| 1 |
/* { dg-do run { target powerpc_fprs } } */ |
| 2 |
/* { dg-options "-O2" } */ |
| 3 |
|
| 4 |
/* Originally __builtin_set_fpscr_rn was defined to return void. It was |
| 5 |
later extended to return a double with the various FPSCR bits. The |
| 6 |
extended built-in is intended to be a drop in replacement for the original |
| 7 |
version. This test is for the original version of the built-in and should |
| 8 |
work exactly as before. */ |
| 9 |
|
| 10 |
#ifdef DEBUG |
| 11 |
#include <stdio.h> |
| 12 |
#endif |
| 13 |
|
| 14 |
#define RN_MASK 0x3LL /* RN field mask */ |
| 15 |
|
| 16 |
void abort (void); |
| 17 |
void __attribute__ ((noipa)) wrap_set_fpscr_rn (int val) |
| 18 |
{ |
| 19 |
__builtin_set_fpscr_rn (val); |
| 20 |
} |
| 21 |
|
| 22 |
int main () |
| 23 |
{ |
| 24 |
int i; |
| 25 |
int val, bit; |
| 26 |
double fpscr_val; |
| 27 |
union blah { |
| 28 |
double d; |
| 29 |
unsigned long long ll; |
| 30 |
} conv_val; |
| 31 |
|
| 32 |
unsigned long long ll_value; |
| 33 |
register double f14; |
| 34 |
|
| 35 |
/* __builtin_set_fpscr_rn() built-in can take a const or a variable |
| 36 |
value between 0 and 3 as the argument. |
| 37 |
__builtin_mtfsb0 and __builtin_mtfsb1 argument must be a constant |
| 38 |
30 or 31. |
| 39 |
*/ |
| 40 |
|
| 41 |
/* Test reading the FPSCR register */ |
| 42 |
__asm __volatile ("mffs %0" : "=f"(f14)); |
| 43 |
conv_val.d = f14; |
| 44 |
|
| 45 |
if (conv_val.d != __builtin_mffs()) |
| 46 |
{ |
| 47 |
#ifdef DEBUG |
| 48 |
printf("ERROR, __builtin_mffs() returned 0x%llx, not the expecected value 0x%llx\n", |
| 49 |
__builtin_mffs(), conv_val.d); |
| 50 |
#else |
| 51 |
abort(); |
| 52 |
#endif |
| 53 |
} |
| 54 |
|
| 55 |
/* Test float rounding mode builtin with const value argument. */ |
| 56 |
val = 3; |
| 57 |
__builtin_set_fpscr_rn (val); |
| 58 |
conv_val.d = __builtin_mffs(); |
| 59 |
ll_value = conv_val.ll & RN_MASK; |
| 60 |
|
| 61 |
if (ll_value != 3) |
| 62 |
{ |
| 63 |
#ifdef DEBUG |
| 64 |
printf("ERROR, __builtin_set_fpscr_rn(3) returned 0x%llx, not the expecected value 0x%x\n", |
| 65 |
ll_value, 3); |
| 66 |
#else |
| 67 |
abort(); |
| 68 |
#endif |
| 69 |
} |
| 70 |
|
| 71 |
val = 2; |
| 72 |
__builtin_set_fpscr_rn (val); |
| 73 |
conv_val.d = __builtin_mffs(); |
| 74 |
ll_value = conv_val.ll & RN_MASK; |
| 75 |
|
| 76 |
if (ll_value != val) |
| 77 |
{ |
| 78 |
#ifdef DEBUG |
| 79 |
printf("ERROR, __builtin_set_fpscr_rn(val=%d) returned 0x%llx, not the expecected value 0x%x\n", |
| 80 |
val, ll_value, val); |
| 81 |
#else |
| 82 |
abort(); |
| 83 |
#endif |
| 84 |
} |
| 85 |
|
| 86 |
/* Reset to 0 for testing */ |
| 87 |
val = 0; |
| 88 |
__builtin_set_fpscr_rn (val); |
| 89 |
|
| 90 |
__builtin_mtfsb1(31); |
| 91 |
conv_val.d = __builtin_mffs(); |
| 92 |
ll_value = conv_val.ll & 0x1LL; |
| 93 |
|
| 94 |
if (ll_value != 1) |
| 95 |
{ |
| 96 |
#ifdef DEBUG |
| 97 |
printf("ERROR, __builtin_mtfsb1(31) did not set the bit to a 1.\n"); |
| 98 |
#else |
| 99 |
abort(); |
| 100 |
#endif |
| 101 |
} |
| 102 |
|
| 103 |
__builtin_mtfsb0(31); |
| 104 |
conv_val.d = __builtin_mffs(); |
| 105 |
ll_value = conv_val.ll & 0x1LL; |
| 106 |
|
| 107 |
if (ll_value != 0) |
| 108 |
{ |
| 109 |
#ifdef DEBUG |
| 110 |
printf("ERROR, __builtin_mtfsb0(31) did not set the bit to a 0.\n"); |
| 111 |
#else |
| 112 |
abort(); |
| 113 |
#endif |
| 114 |
} |
| 115 |
|
| 116 |
__builtin_mtfsb1(30); |
| 117 |
conv_val.d = __builtin_mffs(); |
| 118 |
ll_value = conv_val.ll & 0x2LL; |
| 119 |
|
| 120 |
if (ll_value != 2) |
| 121 |
{ |
| 122 |
#ifdef DEBUG |
| 123 |
printf("ERROR, __builtin_mtfsb1(31) did not set the bit to a 1.\n"); |
| 124 |
#else |
| 125 |
abort(); |
| 126 |
#endif |
| 127 |
} |
| 128 |
|
| 129 |
__builtin_mtfsb0(30); |
| 130 |
conv_val.d = __builtin_mffs(); |
| 131 |
ll_value = conv_val.ll & 0x2LL; |
| 132 |
|
| 133 |
if (ll_value != 0) |
| 134 |
{ |
| 135 |
#ifdef DEBUG |
| 136 |
printf("ERROR, __builtin_mtfsb1(31) did not set the bit to a 0.\n"); |
| 137 |
#else |
| 138 |
abort(); |
| 139 |
#endif |
| 140 |
} |
| 141 |
|
| 142 |
__builtin_mtfsb1(0); |
| 143 |
conv_val.d = __builtin_mffs(); |
| 144 |
ll_value = conv_val.ll & (0x1LL << (31-0)); |
| 145 |
|
| 146 |
if (ll_value != (0x1LL << (31-0))) |
| 147 |
{ |
| 148 |
#ifdef DEBUG |
| 149 |
printf("ERROR, __builtin_mtfsb1(0) did not set the bit to a 1.\n"); |
| 150 |
#else |
| 151 |
abort(); |
| 152 |
#endif |
| 153 |
} |
| 154 |
|
| 155 |
__builtin_mtfsb0(0); |
| 156 |
conv_val.d = __builtin_mffs(); |
| 157 |
ll_value = conv_val.ll & (0x1LL << (31-0)); |
| 158 |
|
| 159 |
if (ll_value != 0) |
| 160 |
{ |
| 161 |
#ifdef DEBUG |
| 162 |
printf("ERROR, __builtin_mtfsb0(0) did not set the bit to a 0.\n"); |
| 163 |
#else |
| 164 |
abort(); |
| 165 |
#endif |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
/* Test builtin float rounding mode with variable as argument. */ |
| 170 |
val = 0; |
| 171 |
wrap_set_fpscr_rn (val); |
| 172 |
conv_val.d = __builtin_mffs(); |
| 173 |
ll_value = conv_val.ll & RN_MASK; |
| 174 |
|
| 175 |
if (ll_value != val) |
| 176 |
{ |
| 177 |
#ifdef DEBUG |
| 178 |
printf("ERROR, __builtin_set_fpscr_rn(val=%d) did not set rounding mode to %x.\n", |
| 179 |
val, val); |
| 180 |
#else |
| 181 |
abort(); |
| 182 |
#endif |
| 183 |
} |
| 184 |
|
| 185 |
val = 3; |
| 186 |
wrap_set_fpscr_rn (val); |
| 187 |
conv_val.d = __builtin_mffs(); |
| 188 |
ll_value = conv_val.ll & RN_MASK; |
| 189 |
|
| 190 |
if (ll_value != val) |
| 191 |
{ |
| 192 |
#ifdef DEBUG |
| 193 |
printf("ERROR, __builtin_set_fpscr_rn(val=%d) did not set rounding mode to %x.\n", |
| 194 |
val, val); |
| 195 |
#else |
| 196 |
abort(); |
| 197 |
#endif |
| 198 |
} |
| 199 |
} |