public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Simplify pad_below implementation
@ 2017-08-21 12:35 Richard Sandiford
  2017-08-21 13:10 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2017-08-21 12:35 UTC (permalink / raw)
  To: gcc-patches

This patch simplifies the alignment calculations in pad_below.
The first arm of the "if" was:

- taking GET_MODE_BITSIZE (always equal to GET_MODE_SIZE * BITS_PER_UNIT),
- rounding up to the next multiple of PARM_BOUNDARY
- converting bits to bytes and
- subtracting the GET_MODE_SIZE

so was in effect calculating the number of bytes needed to round
GET_MODE_SIZE up to (PARM_BOUNDARY / BITS_PER_UNIT).  That can be
done more directly as -size & (align - 1), which is easier to
convert to variable-sized modes.

Tested on aarch64-linux-gnu and x86_64-linux-gnu, and by building
one target per CPU and checking that there were no differences in
assembly for the testsuite.  OK to install?

Richard


2017-08-21  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	* function.c (pad_below): Simplify padding calculation.

Index: gcc/function.c
===================================================================
--- gcc/function.c	2017-08-21 10:42:34.185530464 +0100
+++ gcc/function.c	2017-08-21 11:55:41.018148268 +0100
@@ -4322,21 +4322,16 @@ pad_to_arg_alignment (struct args_size *
 static void
 pad_below (struct args_size *offset_ptr, machine_mode passed_mode, tree sizetree)
 {
+  unsigned int align = PARM_BOUNDARY / BITS_PER_UNIT;
   if (passed_mode != BLKmode)
-    {
-      if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
-	offset_ptr->constant
-	  += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
-	       / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
-	      - GET_MODE_SIZE (passed_mode));
-    }
+    offset_ptr->constant += -GET_MODE_SIZE (passed_mode) & (align - 1);
   else
     {
       if (TREE_CODE (sizetree) != INTEGER_CST
-	  || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
+	  || (TREE_INT_CST_LOW (sizetree) & (align - 1)) != 0)
 	{
 	  /* Round the size up to multiple of PARM_BOUNDARY bits.  */
-	  tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
+	  tree s2 = round_up (sizetree, align);
 	  /* Add it in.  */
 	  ADD_PARM_SIZE (*offset_ptr, s2);
 	  SUB_PARM_SIZE (*offset_ptr, sizetree);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Simplify pad_below implementation
  2017-08-21 12:35 Simplify pad_below implementation Richard Sandiford
@ 2017-08-21 13:10 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-08-21 13:10 UTC (permalink / raw)
  To: GCC Patches, Richard Sandiford

On Mon, Aug 21, 2017 at 1:14 PM, Richard Sandiford
<richard.sandiford@linaro.org> wrote:
> This patch simplifies the alignment calculations in pad_below.
> The first arm of the "if" was:
>
> - taking GET_MODE_BITSIZE (always equal to GET_MODE_SIZE * BITS_PER_UNIT),
> - rounding up to the next multiple of PARM_BOUNDARY
> - converting bits to bytes and
> - subtracting the GET_MODE_SIZE
>
> so was in effect calculating the number of bytes needed to round
> GET_MODE_SIZE up to (PARM_BOUNDARY / BITS_PER_UNIT).  That can be
> done more directly as -size & (align - 1), which is easier to
> convert to variable-sized modes.
>
> Tested on aarch64-linux-gnu and x86_64-linux-gnu, and by building
> one target per CPU and checking that there were no differences in
> assembly for the testsuite.  OK to install?

Ok.

Richard.

> Richard
>
>
> 2017-08-21  Richard Sandiford  <richard.sandiford@linaro.org>
>             Alan Hayward  <alan.hayward@arm.com>
>             David Sherwood  <david.sherwood@arm.com>
>
> gcc/
>         * function.c (pad_below): Simplify padding calculation.
>
> Index: gcc/function.c
> ===================================================================
> --- gcc/function.c      2017-08-21 10:42:34.185530464 +0100
> +++ gcc/function.c      2017-08-21 11:55:41.018148268 +0100
> @@ -4322,21 +4322,16 @@ pad_to_arg_alignment (struct args_size *
>  static void
>  pad_below (struct args_size *offset_ptr, machine_mode passed_mode, tree sizetree)
>  {
> +  unsigned int align = PARM_BOUNDARY / BITS_PER_UNIT;
>    if (passed_mode != BLKmode)
> -    {
> -      if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
> -       offset_ptr->constant
> -         += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
> -              / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
> -             - GET_MODE_SIZE (passed_mode));
> -    }
> +    offset_ptr->constant += -GET_MODE_SIZE (passed_mode) & (align - 1);
>    else
>      {
>        if (TREE_CODE (sizetree) != INTEGER_CST
> -         || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
> +         || (TREE_INT_CST_LOW (sizetree) & (align - 1)) != 0)
>         {
>           /* Round the size up to multiple of PARM_BOUNDARY bits.  */
> -         tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
> +         tree s2 = round_up (sizetree, align);
>           /* Add it in.  */
>           ADD_PARM_SIZE (*offset_ptr, s2);
>           SUB_PARM_SIZE (*offset_ptr, sizetree);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-21 12:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-21 12:35 Simplify pad_below implementation Richard Sandiford
2017-08-21 13:10 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).