File: fp-int-convert.h

package info (click to toggle)
gcc-arm-none-eabi 15%3A8-2019-q3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 571,828 kB
  • sloc: ansic: 2,937,651; cpp: 881,644; ada: 597,189; makefile: 65,528; asm: 56,499; xml: 46,621; exp: 24,747; sh: 19,684; python: 7,256; pascal: 4,370; awk: 3,497; perl: 2,695; yacc: 316; ml: 285; f90: 234; lex: 198; objc: 194; haskell: 119
file content (95 lines) | stat: -rw-r--r-- 4,058 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* 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, M) 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
   and M is the MAX_EXP value for that type (so 2^M overflows, 2^(M-1)
   does not).  We test conversions of the values 0, 1, 0x7...f,
   0x8...0, 0xf...f.  We also test conversions of values half way
   between two representable values (rounding both ways), just above
   half way, and just below half way.  */
#define TEST_I_F(I, U, F, P, M)					\
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), M_OK1 (M, I));	\
  TEST_I_F_VAL (I, F, (I)(U)~(U)0, 1);				\
  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), M_OK1 (M, U));	\
  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));		\
  TEST_I_F_VAL (I, F, WVAL0S (I), M_OK2 (M, U));		\
  TEST_I_F_VAL (I, F, -WVAL0S (I), M_OK2 (M, 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 M_OK1(M, T) ((M) > sizeof(T) * CHAR_BIT - 1)
#define M_OK2(M, T) ((M) > sizeof(T) * CHAR_BIT / 2 - 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 WVAL0S(S) (S)((S)1 << (sizeof(S) * CHAR_BIT / 2 - 1))

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