PR target/84226
[official-gcc.git] / gcc / testsuite / gcc.target / rx / builtins.c
blob45071bb26df1f6159625e60e6af86333af18fb5f
1 /* { dg-do run } */
3 /* Verify that the RX specific builtin functions work. */
5 #include <stdlib.h>
6 #include <stdio.h>
8 /* We need to prevent these functions from being inlined
9 as otherwise gcc will attempt to optimize away their
10 arguments and we need the operations on them in order
11 to correctly set the psw flags. */
13 int saturate_add (int, int) __attribute__((__noinline__));
14 int exchange (int, int) __attribute__((__noinline__));
16 int
17 half_word_swap (int arg)
19 return __builtin_rx_revw (arg);
22 long
23 multiply_and_accumulate (long arg1, long arg2, long arg3)
25 __builtin_rx_mvtaclo (0);
26 __builtin_rx_mvtachi (0);
28 __builtin_rx_mullo (arg1, arg2);
29 __builtin_rx_mulhi (arg1, arg2);
30 __builtin_rx_maclo (arg1, arg3);
31 __builtin_rx_machi (arg1, arg3);
33 __builtin_rx_racw (1);
35 arg1 = __builtin_rx_mvfachi ();
36 arg1 += __builtin_rx_mvfacmi ();
38 return arg1;
41 int
42 rxround (float arg)
44 return __builtin_rx_round (arg);
47 /* #define DEBUG 1 */
49 #ifdef DEBUG
50 #define CHECK_0ARG(func, result) \
51 if (func () != result) \
52 { \
53 printf (#func " () fails: %x not %x\n", func (), result); \
54 abort (); \
57 #define CHECK_1ARG(func, arg, result) \
58 if (func (arg) != result) \
59 { \
60 printf (#func " (" #arg ") fails: %x not %x\n", func (arg), result); \
61 abort (); \
64 #define CHECK_2ARG(func, arg1, arg2, result) \
65 if (func (arg1, arg2) != result) \
66 { \
67 printf (#func " (" #arg1 "," #arg2 ") fails: %x not %x\n", \
68 func (arg1, arg2), result); \
69 abort (); \
72 #define CHECK_3ARG(func, arg1, arg2, arg3, result) \
73 if (func (arg1, arg2, arg3) != result) \
74 { \
75 printf (#func " (" #arg1 "," #arg2 "," #arg3 ") fails: %x not %x\n", \
76 func (arg1, arg2, arg3), result); \
77 abort (); \
79 #else
80 #define CHECK_0ARG(func, result) \
81 if (func () != result) \
82 abort ();
84 #define CHECK_1ARG(func, arg, result) \
85 if (func (arg) != result) \
86 abort ();
88 #define CHECK_2ARG(func, arg1, arg2, result) \
89 if (func (arg1, arg2) != result) \
90 abort ();
92 #define CHECK_3ARG(func, arg1, arg2, arg3, result) \
93 if (func (arg1, arg2, arg3) != result) \
94 abort ();
95 #endif
97 int
98 main (void)
100 CHECK_1ARG (half_word_swap, 0x12345678, 0x34127856);
101 CHECK_3ARG (multiply_and_accumulate, 0x111, 0x222, 0x333, 0x70007);
102 CHECK_1ARG (rxround, 0.5, 1);
103 return 0;
106 /* The following builtins are compiled but
107 not executed because they need OS support. */
109 void
110 rxbreak (void)
112 __builtin_rx_brk ();
115 void
116 interrupt (void)
118 __builtin_rx_int (0x12);
122 get_stack_pointer (void)
124 return __builtin_rx_mvfc (2);
127 void
128 set_stack_pointer (int value)
130 __builtin_rx_mvtc (2, value);
131 __builtin_rx_mvtc (2, 0x1234);
134 void
135 wait (void)
137 __builtin_rx_wait ();
140 #ifndef __RX_DISALLOW_STRING_INSNS__
141 void
142 rmpa (int * multiplicand, int * multiplier, int num)
144 __builtin_rx_rmpa ();
146 #endif