[DTrace-devel] [PATCH 2/4] clean up dt_cg_typecast(): suppress shifts if shift amount is 0

Kris Van Hees kris.van.hees at oracle.com
Mon Aug 24 06:57:13 PDT 2020


I somehow missed to reply to this patch, even though I replied to the other 3
in the series.  Weird.  Sorry about that.

On Tue, Aug 11, 2020 at 06:11:10PM -0400, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> The typecast consists of shifting left and then right.  It is possible
> that the shift amount is 0:  the src and dst values can both be 64 bits
> while one or else the other is signed.  It is easy to add the test
> n!=0 to the condition for performing the typecast.  This is a small
> but easy optimization.
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>

Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>

> ---
>  libdtrace/dt_cg.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
> index 4f657967..6ba779d1 100644
> --- a/libdtrace/dt_cg.c
> +++ b/libdtrace/dt_cg.c
> @@ -1132,16 +1132,16 @@ dt_cg_typecast(const dt_node_t *src, const dt_node_t *dst,
>  	srcsize = dt_node_type_size(src);
>  	dstsize = dt_node_type_size(dst);
>  
> -	if (dt_node_is_scalar(dst) && (dstsize < srcsize ||
> +	if (dstsize < srcsize)
> +		n = sizeof (uint64_t) * NBBY - dstsize * NBBY;
> +	else
> +		n = sizeof (uint64_t) * NBBY - srcsize * NBBY;
> +
> +	if (dt_node_is_scalar(dst) && n != 0 && (dstsize < srcsize ||
>  	    (src->dn_flags & DT_NF_SIGNED) ^ (dst->dn_flags & DT_NF_SIGNED))) {
>  		if ((reg = dt_regset_alloc(drp)) == -1)
>  			longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
>  
> -		if (dstsize < srcsize)
> -			n = sizeof (uint64_t) * NBBY - dstsize * NBBY;
> -		else
> -			n = sizeof (uint64_t) * NBBY - srcsize * NBBY;
> -
>  		dt_cg_setx(dlp, reg, n);
>  
>  		instr = BPF_ALU64_REG(BPF_LSH, dst->dn_reg, reg);
> -- 
> 2.18.4
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list