summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/torture/fp-int-convert.h
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/torture/fp-int-convert.h
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/torture/fp-int-convert.h')
-rw-r--r--gcc/testsuite/gcc.dg/torture/fp-int-convert.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert.h b/gcc/testsuite/gcc.dg/torture/fp-int-convert.h
new file mode 100644
index 000000000..61d2c0199
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert.h
@@ -0,0 +1,89 @@
+/* Test floating-point conversions. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+
+#include <limits.h>
+extern void abort (void);
+extern void exit (int);
+
+/* Not all platforms support TImode integers; logic as in
+ gcc.dg/titype-1.c. */
+#if (defined(__LP64__) && !defined(__hppa__)) || defined(_WIN64) || defined(__SPU__)
+typedef int TItype __attribute__ ((mode (TI)));
+typedef unsigned int UTItype __attribute__ ((mode (TI)));
+#else
+typedef long TItype;
+typedef unsigned long UTItype;
+#endif
+
+/* TEST_I_F(I, U, F, P) tests conversions between the pair of signed
+ and unsigned integer types I and U and the floating-point type F,
+ where P is the binary precision of the floating point type. We
+ test conversions of the values 0, 1, 0x7...f, 0x8...0, 0xf...f. We
+ also test conversions of values half way inbetween two
+ representable values (rounding both ways), just above half way, and
+ just below half way. */
+#define TEST_I_F(I, U, F, P) \
+do { \
+ TEST_I_F_VAL (I, F, (I)0, 1); \
+ TEST_I_F_VAL (I, F, (I)1, 1); \
+ TEST_I_F_VAL (I, F, (I)(((U)~(U)0) >> 1), P_OK1 (P, I)); \
+ TEST_I_F_VAL (I, F, (I)(U)~(((U)~(U)0) >> 1), 1); \
+ TEST_I_F_VAL (I, F, (I)(U)~(U)0, P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, HVAL0S (P, I), P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, HVAL0S (P, I) + 1, P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, HVAL0S (P, I) - 1, P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, HVAL1S (P, I), P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, HVAL1S (P, I) + 1, P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, HVAL1S (P, I) - 1, P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, -HVAL0S (P, I), P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, -HVAL0S (P, I) + 1, P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, -HVAL0S (P, I) - 1, P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, -HVAL1S (P, I), P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, -HVAL1S (P, I) + 1, P_OK (P, I)); \
+ TEST_I_F_VAL (I, F, -HVAL1S (P, I) - 1, P_OK (P, I)); \
+ TEST_I_F_VAL (U, F, (U)0, 1); \
+ TEST_I_F_VAL (U, F, (U)1, 1); \
+ TEST_I_F_VAL (U, F, (U)(((U)~(U)0) >> 1), P_OK1 (P, U)); \
+ TEST_I_F_VAL (U, F, (U)~(((U)~(U)0) >> 1), 1); \
+ TEST_I_F_VAL (U, F, (U)~(U)0, P_OK (P, U)); \
+ TEST_I_F_VAL (U, F, HVAL0U (P, U), P_OK (P, U)); \
+ TEST_I_F_VAL (U, F, HVAL0U (P, U) + 1, P_OK (P, U)); \
+ TEST_I_F_VAL (U, F, HVAL0U (P, U) - 1, P_OK (P, U)); \
+ TEST_I_F_VAL (U, F, HVAL1U (P, U), P_OK (P, U)); \
+ TEST_I_F_VAL (U, F, HVAL1U (P, U) + 1, P_OK (P, U)); \
+ TEST_I_F_VAL (U, F, HVAL1U (P, U) - 1, P_OK (P, U)); \
+} while (0)
+
+#define P_OK(P, T) ((P) >= sizeof(T) * CHAR_BIT)
+#define P_OK1(P, T) ((P) >= sizeof(T) * CHAR_BIT - 1)
+#define HVAL0U(P, U) (U)(P_OK (P, U) \
+ ? (U)1 \
+ : (((U)1 << (sizeof(U) * CHAR_BIT - 1)) \
+ + ((U)1 << (sizeof(U) * CHAR_BIT - 1 - P))))
+#define HVAL1U(P, U) (U)(P_OK (P, U) \
+ ? (U)1 \
+ : (((U)1 << (sizeof(U) * CHAR_BIT - 1)) \
+ + ((U)3 << (sizeof(U) * CHAR_BIT - 1 - P))))
+#define HVAL0S(P, S) (S)(P_OK1 (P, S) \
+ ? (S)1 \
+ : (((S)1 << (sizeof(S) * CHAR_BIT - 2)) \
+ + ((S)1 << (sizeof(S) * CHAR_BIT - 2 - P))))
+#define HVAL1S(P, S) (S)(P_OK1 (P, S) \
+ ? (S)1 \
+ : (((S)1 << (sizeof(S) * CHAR_BIT - 2)) \
+ + ((S)3 << (sizeof(S) * CHAR_BIT - 2 - P))))
+
+#define TEST_I_F_VAL(IT, FT, VAL, PREC_OK) \
+do { \
+ static volatile IT ivin, ivout; \
+ static volatile FT fv1, fv2; \
+ ivin = (VAL); \
+ fv1 = (VAL); \
+ fv2 = ivin; \
+ ivout = fv2; \
+ if (ivin != (VAL) \
+ || ((PREC_OK) && ivout != ivin) \
+ || ((PREC_OK) && ivout != (VAL)) \
+ || fv1 != (VAL) || fv2 != (VAL) || fv1 != fv2) \
+ abort (); \
+} while (0)