Debian Codegraph @

gcc/testsuite/gcc.target/powerpc/test_fpscr_rn_builtin_2.c

raw
1 /* { dg-do run { target powerpc_fprs } } */
2 /* { dg-options "-O2" } */
3
4 /* The __builtin_set_fpscr_rn built-in was originally defined to return
5 void. The built-in now returns a double containing the various FPSCR bits.
6 This test verifies the new return value. */
7
8 #ifdef DEBUG
9 #include <stdio.h>
10 #endif
11
12 #define RN_MASK 0x3LL /* RN field mask */
13 #define FIELD_MASK 0x00000007000000FFULL
14
15 union blah {
16 double d;
17 unsigned long long ll;
18 } conv_val;
19
20 void abort (void);
21
22 double __attribute__ ((noipa)) wrap_set_fpscr_rn (int val)
23 {
24 return __builtin_set_fpscr_rn (val);
25 }
26
27 double __attribute__ ((noipa)) wrap_const_fpscr_rn (int val)
28 {
29 switch (val)
30 {
31 case 0: return __builtin_set_fpscr_rn (0x0);
32 case 1: return __builtin_set_fpscr_rn (0x1);
33 case 2: return __builtin_set_fpscr_rn (0x2);
34 case 3: return __builtin_set_fpscr_rn (0x3);
35 }
36 }
37
38 void check_builtin_set_fpscr_rn (unsigned long long initial_fpscr,
39 int new_RN, double result)
40 {
41 register double f14;
42 unsigned long long masked_fpscr = initial_fpscr & FIELD_MASK;
43
44 conv_val.d = result;
45
46 /* Check the result. */
47 if (conv_val.ll != masked_fpscr)
48 {
49 #ifdef DEBUG
50 printf("ERROR, __builtin_set_fpscr_rn(%d) did not return expected value %llx.\n",
51 new_RN, masked_fpscr);
52 printf("fpscr_val_initial = 0x%llx\n", initial_fpscr);
53 printf("result = 0x%llx\n", conv_val.ll);
54 #else
55 abort();
56 #endif
57 }
58
59 /* Check to see if the RN field was updated. */
60 __asm __volatile ("mffs %0" : "=f"(f14));
61 conv_val.d = f14;
62
63 if ((conv_val.ll & RN_MASK) != new_RN)
64 #ifdef DEBUG
65 {
66 printf("ERROR, __builtin_set_fpscr_rn(%d) did not update RN to %llx.\n",
67 new_RN, new_RN);
68 printf(" conv_val.ll = 0x%llx\n", conv_val.ll);
69 }
70 #else
71 abort();
72 #endif
73 }
74
75 int
76 main ()
77 {
78 int i;
79 int val, bit;
80 double fpscr_val;
81 unsigned long long fpscr_val_initial;
82
83 unsigned long long ll_value;
84 union blah src_double;
85 register double f14;
86
87 /* If __SET_FPSCR_RN_RETURNS_FPSCR__ is defined, the __builtin_set_fpscr_rn()
88 builtin returns the FPSCR fields.*/
89
90 /* __builtin_set_fpscr_rn() builtin can take a constant or a variable
91 value between 0 and 3 as the argument.
92 __builtin_mtfsb0 and __builtin_mtfsb1 argument must be a constant
93 30 or 31.
94 */
95
96 /* Test reading the FPSCR register */
97 __asm __volatile ("mffs %0" : "=f"(f14));
98 conv_val.d = f14;
99
100 if (conv_val.d != __builtin_mffs())
101 {
102 #ifdef DEBUG
103 printf("ERROR, __builtin_mffs() returned 0x%llx, not the expected value 0x%llx\n",
104 __builtin_mffs(), conv_val.d);
105 #else
106 abort();
107 #endif
108 }
109
110 /* Test return value from __builtin_set_fpscr_rn. The FPSCR fields (DRN, VE,
111 OE, UE, ZE, XE, NI, RN) are returned and the RN field of FPSCR is updated
112 with the specified argument for the built-in. */
113
114 /* Check immediate argument cases */
115 __asm __volatile ("mffs %0" : "=f"(f14));
116 conv_val.d = f14;
117 fpscr_val_initial = conv_val.ll;
118
119 val = 0x0;
120 fpscr_val = wrap_const_fpscr_rn (val);
121 check_builtin_set_fpscr_rn (fpscr_val_initial, val, fpscr_val);
122
123 __asm __volatile ("mffs %0" : "=f"(f14));
124 conv_val.d = f14;
125 fpscr_val_initial = conv_val.ll;
126
127 val = 0x3;
128 fpscr_val = wrap_const_fpscr_rn (val);
129 check_builtin_set_fpscr_rn (fpscr_val_initial, val, fpscr_val);
130
131 /* Check int argument cases */
132 __asm __volatile ("mffs %0" : "=f"(f14));
133 conv_val.d = f14;
134 fpscr_val_initial = conv_val.ll;
135
136 val = 0x1;
137 fpscr_val = wrap_set_fpscr_rn (val);
138 check_builtin_set_fpscr_rn (fpscr_val_initial, val, fpscr_val);
139
140 __asm __volatile ("mffs %0" : "=f"(f14));
141 conv_val.d = f14;
142 fpscr_val_initial = conv_val.ll;
143
144 val = 0x2;
145 fpscr_val = wrap_set_fpscr_rn (val);
146 check_builtin_set_fpscr_rn (fpscr_val_initial, val, fpscr_val);
147 return 0;
148 }