public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-781] xtensa: Simplify EXTUI instruction maskimm validations
@ 2022-05-26 16:41 Max Filippov
  0 siblings, 0 replies; only message in thread
From: Max Filippov @ 2022-05-26 16:41 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b753405a5f0d45eea97f4cc7df2c2089401b08bf

commit r13-781-gb753405a5f0d45eea97f4cc7df2c2089401b08bf
Author: Takayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
Date:   Fri May 13 22:26:30 2022 +0900

    xtensa: Simplify EXTUI instruction maskimm validations
    
    No functional changes.
    
    gcc/ChangeLog:
    
            * config/xtensa/predicates.md (extui_fldsz_operand): Simplify.
            * config/xtensa/xtensa.cc (xtensa_mask_immediate, print_operand):
            Ditto.

Diff:
---
 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");


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-26 16:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-26 16:41 [gcc r13-781] xtensa: Simplify EXTUI instruction maskimm validations 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).