aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/bitintext.h
diff options
context:
space:
mode:
authorJerry DeLisle <jvdelisle@gcc.gnu.org>2025-09-02 15:58:26 -0700
committerJerry DeLisle <jvdelisle@gcc.gnu.org>2025-09-02 15:58:26 -0700
commit071b4126c613881f4cb25b4e5c39032964827f88 (patch)
tree7ed805786566918630d1d617b1ed8f7310f5fd8e /gcc/testsuite/gcc.dg/bitintext.h
parent845d23f3ea08ba873197c275a8857eee7edad996 (diff)
parentcaa1c2f42691d68af4d894a5c3e700ecd2dba080 (diff)
downloadgcc-devel/gfortran-test.zip
gcc-devel/gfortran-test.tar.gz
gcc-devel/gfortran-test.tar.bz2
Merge branch 'master' into gfortran-testdevel/gfortran-test
Diffstat (limited to 'gcc/testsuite/gcc.dg/bitintext.h')
-rw-r--r--gcc/testsuite/gcc.dg/bitintext.h46
1 files changed, 31 insertions, 15 deletions
diff --git a/gcc/testsuite/gcc.dg/bitintext.h b/gcc/testsuite/gcc.dg/bitintext.h
index 99fedb3..f61cf9a 100644
--- a/gcc/testsuite/gcc.dg/bitintext.h
+++ b/gcc/testsuite/gcc.dg/bitintext.h
@@ -4,25 +4,41 @@ do_copy (void *p, const void *q, __SIZE_TYPE__ r)
__builtin_memcpy (p, q, r);
}
+/* Obtain the value of N from a _BitInt(N)-typed expression X
+ at compile time. */
+#define S(x) \
+ ((typeof (x)) -1 < 0 \
+ ? __builtin_clrsbg (__builtin_choose_expr ((typeof (x)) -1 < 0, \
+ (typeof (x)) -1, -1)) + 1 \
+ : __builtin_popcountg (__builtin_choose_expr ((typeof (x)) -1 < 0, \
+ 0U, (typeof (x)) -1)))
+
+#define CEIL(x,y) (((x) + (y) - 1) / (y))
+
+/* Promote a _BitInt type to include its padding bits. */
+#if defined (__s390x__) || defined(__arm__)
+#define PROMOTED_SIZE(x) sizeof (x)
+#elif defined(__loongarch__)
+#define PROMOTED_SIZE(x) (sizeof (x) > 8 ? CEIL (S (x), 64) * 8 : sizeof (x))
+#endif
+
/* Macro to test whether (on targets where psABI requires it) _BitInt
with padding bits have those filled with sign or zero extension. */
#if defined(__s390x__) || defined(__arm__) || defined(__loongarch__)
+#define BEXTC1(x, uns) \
+ do { \
+ uns _BitInt(PROMOTED_SIZE (x) * __CHAR_BIT__) __x; \
+ do_copy (&__x, &(x), sizeof (__x)); \
+ if (__x != (typeof (x)) __x) \
+ __builtin_abort (); \
+ } while (0)
+
#define BEXTC(x) \
- do { \
- if ((typeof (x)) -1 < 0) \
- { \
- _BitInt(sizeof (x) * __CHAR_BIT__) __x; \
- do_copy (&__x, &(x), sizeof (__x)); \
- if (__x != (x)) \
- __builtin_abort (); \
- } \
- else \
- { \
- unsigned _BitInt(sizeof (x) * __CHAR_BIT__) __x; \
- do_copy (&__x, &(x), sizeof (__x)); \
- if (__x != (x)) \
- __builtin_abort (); \
- } \
+ do { \
+ if ((typeof (x)) -1 < 0) \
+ BEXTC1 ((x), signed); \
+ else \
+ BEXTC1 ((x), unsigned); \
} while (0)
#else
#define BEXTC(x) do { (void) (x); } while (0)