public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/5] xtensa: Simplify EXTUI instruction maskimm validations
@ 2022-05-13 13:26 Takayuki 'January June' Suwa
  2022-05-26 16:42 ` Max Filippov
  0 siblings, 1 reply; 2+ messages in thread
From: Takayuki 'January June' Suwa @ 2022-05-13 13:26 UTC (permalink / raw)
  To: gcc-patches

No functional changes.

gcc/ChangeLog:

	* gcc/config/xtensa/predicates.md (extui_fldsz_operand): Simplify.
	* gcc/config/xtensa/xtensa.cc (xtensa_mask_immediate, print_operand):
	Ditto.
---
  gcc/config/xtensa/predicates.md |  2 +-
  gcc/config/xtensa/xtensa.cc     | 24 +++---------------------
  2 files changed, 4 insertions(+), 22 deletions(-)

diff --git a/gcc/config/xtensa/predicates.md 
b/gcc/config/xtensa/predicates.md
index 01226a2b3c7..daea63b182c 100644
--- a/gcc/config/xtensa/predicates.md
+++ b/gcc/config/xtensa/predicates.md
@@ -55,7 +55,7 @@

  (define_predicate "extui_fldsz_operand"
    (and (match_code "const_int")
-       (match_test "xtensa_mask_immediate ((1 << INTVAL (op)) - 1)")))
+       (match_test "IN_RANGE (INTVAL (op), 1, 16)")))

  (define_predicate "sext_operand"
    (if_then_else (match_test "TARGET_SEXT")
diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index 7023badf0e2..a1f77b2bd35 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -456,19 +456,7 @@ xtensa_b4constu (HOST_WIDE_INT v)
  bool
  xtensa_mask_immediate (HOST_WIDE_INT v)
  {
-#define MAX_MASK_SIZE 16
-  int mask_size;
-
-  for (mask_size = 1; mask_size <= MAX_MASK_SIZE; mask_size++)
-    {
-      if ((v & 1) == 0)
-	return false;
-      v = v >> 1;
-      if (v == 0)
-	return true;
-    }
-
-  return false;
+  return IN_RANGE (exact_log2 (v + 1), 1, 16);
  }


@@ -2430,17 +2418,11 @@ print_operand (FILE *file, rtx x, int letter)
      case 'K':
        if (GET_CODE (x) == CONST_INT)
  	{
-	  int num_bits = 0;
  	  unsigned val = INTVAL (x);
-	  while (val & 1)
-	    {
-	      num_bits += 1;
-	      val = val >> 1;
-	    }
-	  if ((val != 0) || (num_bits == 0) || (num_bits > 16))
+	  if (!xtensa_mask_immediate (val))
  	    fatal_insn ("invalid mask", x);

-	  fprintf (file, "%d", num_bits);
+	  fprintf (file, "%d", floor_log2 (val + 1));
  	}
        else
  	output_operand_lossage ("invalid %%K value");
-- 
2.20.1

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

* Re: [PATCH 1/5] xtensa: Simplify EXTUI instruction maskimm validations
  2022-05-13 13:26 [PATCH 1/5] xtensa: Simplify EXTUI instruction maskimm validations Takayuki 'January June' Suwa
@ 2022-05-26 16:42 ` Max Filippov
  0 siblings, 0 replies; 2+ messages in thread
From: Max Filippov @ 2022-05-26 16:42 UTC (permalink / raw)
  To: Takayuki 'January June' Suwa; +Cc: GCC Patches

On Fri, May 13, 2022 at 6:35 AM Takayuki 'January June' Suwa
<jjsuwa_sys3175@yahoo.co.jp> wrote:
>
> No functional changes.
>
> gcc/ChangeLog:
>
>         * gcc/config/xtensa/predicates.md (extui_fldsz_operand): Simplify.
>         * gcc/config/xtensa/xtensa.cc (xtensa_mask_immediate, print_operand):
>         Ditto.
> ---
>   gcc/config/xtensa/predicates.md |  2 +-
>   gcc/config/xtensa/xtensa.cc     | 24 +++---------------------
>   2 files changed, 4 insertions(+), 22 deletions(-)

Regtested for target=xtensa-linux-uclibc, no new regressions.
Changelog has extra 'gcc/' in paths, so I've dropped this part.
Committed to master.

-- 
Thanks.
-- Max

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

end of thread, other threads:[~2022-05-26 16:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 13:26 [PATCH 1/5] xtensa: Simplify EXTUI instruction maskimm validations Takayuki 'January June' Suwa
2022-05-26 16:42 ` Max Filippov

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).