1 /* { dg-do run { target { powerpc*-*-* &&  lp64 } } } */
2 /* { dg-require-effective-target hard_dfp } */
3 /* { dg-options "-O2 -std=c99" } */
4 
5 #ifdef DEBUG
6 #include <stdio.h>
7 #endif
8 
9 #define DRN_MASK 0x700000000LL     /* DRN field mask */
10 
11 void abort (void);
12 
main()13 int main ()
14 {
15   int i;
16   int val, bit;
17   double fpscr_val;
18   union blah {
19     double d;
20     unsigned long long ll;
21   } conv_val;
22 
23   unsigned long long ll_value;
24   register double  f14;
25 
26   /* __builtin_set_fpscr_drn() builtin can take a const or a variable
27      value between 0 and 7 as the argument.
28   */
29 
30   /* Test builtin decimal float rounding mode with const argument.  */
31   __builtin_set_fpscr_drn(7);
32   conv_val.d = __builtin_mffs();
33   ll_value = conv_val.ll & DRN_MASK;
34 
35   if (ll_value != 0x700000000)
36     {
37 #ifdef DEBUG
38        printf("ERROR, __builtin_set_fpscr_drn(7) did not set rounding mode to 7.\n");
39 #else
40        abort();
41 #endif
42     }
43 
44   __builtin_set_fpscr_drn(2);
45   conv_val.d = __builtin_mffs();
46   ll_value = conv_val.ll & DRN_MASK;
47 
48   if (ll_value != 0x200000000)
49     {
50 #ifdef DEBUG
51        printf("ERROR, __builtin_set_fpscr_drn(2) did not set rounding mode to 2.\n");
52 #else
53        abort();
54 #endif
55     }
56 
57   __builtin_set_fpscr_drn(5);
58   conv_val.d = __builtin_mffs();
59   ll_value = conv_val.ll & DRN_MASK;
60 
61   if (ll_value != 0x500000000)
62     {
63 #ifdef DEBUG
64        printf("ERROR, __builtin_set_fpscr_drn(5) did not set rounding mode to 5.\n");
65 #else
66        abort();
67 #endif
68     }
69 
70   /* Test builtin decimal float rounding mode with variable as argument.  */
71   val = 7;
72   __builtin_set_fpscr_drn(val);
73   conv_val.d = __builtin_mffs();
74   ll_value = conv_val.ll & DRN_MASK;
75 
76   if (ll_value != ((unsigned long long)val << 32))
77     {
78 #ifdef DEBUG
79        printf("ERROR, __builtin_set_fpscr_drn(val=%d) did not set rounding mode to %d.\n",
80 	      val, val);
81 #else
82        abort();
83 #endif
84     }
85 
86   val = 0;
87   __builtin_set_fpscr_drn(val);
88   conv_val.d = __builtin_mffs();
89   ll_value = conv_val.ll & DRN_MASK;
90 
91   if (ll_value != ((unsigned long long)val << 32))
92     {
93 #ifdef DEBUG
94        printf("ERROR, __builtin_set_fpscr_drn(val=%d) did not set rounding mode to %d.\n",
95 	      val, val);
96 #else
97        abort();
98 #endif
99     }
100 
101   val = 2;
102   __builtin_set_fpscr_drn(val);
103   conv_val.d = __builtin_mffs();
104   ll_value = conv_val.ll & DRN_MASK;
105 
106   if (ll_value != ((unsigned long long)val << 32))
107     {
108 #ifdef DEBUG
109        printf("ERROR, __builtin_set_fpscr_drn(val=%d) did not set rounding mode to %d.\n",
110 	      val, val);
111 #else
112        abort();
113 #endif
114     }
115 }
116