Subject: Re: [PATCH V8 06/10] powerpc, lib: Add new branch analysis support functions

From: Daniel Axtens <[email-masked]>
Date: Wed, 10 Jun 2015 15:33:11 +1000

> +static int instr_is_branch_xlform(unsigned int instr)
> +{
> +	return branch_opcode(instr) == 19;
> +}
Why do these not return bool? The functions below do.
> +
> +static int is_xlform_lr(unsigned int instr)
> +{
> +	return (instr & XL_FORM_LR) == XL_FORM_LR;
> +}
> +
> +static int is_bo_always(unsigned int instr)
> +{
> +	return (instr & BO_ALWAYS) == BO_ALWAYS;
> +}
> +
> +static int is_branch_link_set(unsigned int instr)
> +{
> +	return (instr & BRANCH_SET_LINK) == BRANCH_SET_LINK;
> +}
> +
> +bool instr_is_return_branch(unsigned int instr)
> +{
> +	/*
> +	 * Conditional and unconditional branch to LR register
> +	 * without seting the link register.
setting
> +	 */
> +	if (is_xlform_lr(instr) && !is_branch_link_set(instr))
> +		return true;
> +
> +	return false;
> +}
> +

> +bool instr_is_func_call(unsigned int instr)
> +{
> +	/* LR should be set */
> +	if (is_branch_link_set(instr))
> +		return true;
> +
> +	return false;
> +}
> +
> +bool instr_is_indirect_func_call(unsigned int instr)
> +{
> +	/* XL-form instruction with LR set */
> +	if (instr_is_branch_xlform(instr) && is_branch_link_set(instr))
> +		return true;
> +
> +	return false;
> +}
Both of these functions could be made into a single 'return' statement,
right?
> +
>  int instr_is_relative_branch(unsigned int instr)
>  {
>  	if (instr & BRANCH_ABSOLUTE)