| 1 |
/* { dg-do run } */ |
| 2 |
|
| 3 |
/* Verify that the RX specific builtin functions work. */ |
| 4 |
|
| 5 |
#include <stdlib.h> |
| 6 |
#include <stdio.h> |
| 7 |
|
| 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. */ |
| 12 |
|
| 13 |
int saturate_add (int, int) __attribute__((__noinline__)); |
| 14 |
int exchange (int, int) __attribute__((__noinline__)); |
| 15 |
|
| 16 |
int |
| 17 |
half_word_swap (int arg) |
| 18 |
{ |
| 19 |
return __builtin_rx_revw (arg); |
| 20 |
} |
| 21 |
|
| 22 |
long |
| 23 |
multiply_and_accumulate (long arg1, long arg2, long arg3) |
| 24 |
{ |
| 25 |
__builtin_rx_mvtaclo (0); |
| 26 |
__builtin_rx_mvtachi (0); |
| 27 |
|
| 28 |
__builtin_rx_mullo (arg1, arg2); |
| 29 |
__builtin_rx_mulhi (arg1, arg2); |
| 30 |
__builtin_rx_maclo (arg1, arg3); |
| 31 |
__builtin_rx_machi (arg1, arg3); |
| 32 |
|
| 33 |
__builtin_rx_racw (1); |
| 34 |
|
| 35 |
arg1 = __builtin_rx_mvfachi (); |
| 36 |
arg1 += __builtin_rx_mvfacmi (); |
| 37 |
|
| 38 |
return arg1; |
| 39 |
} |
| 40 |
|
| 41 |
int |
| 42 |
rxround (float arg) |
| 43 |
{ |
| 44 |
return __builtin_rx_round (arg); |
| 45 |
} |
| 46 |
|
| 47 |
/* #define DEBUG 1 */ |
| 48 |
|
| 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 (); \ |
| 55 |
} |
| 56 |
|
| 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 (); \ |
| 62 |
} |
| 63 |
|
| 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 (); \ |
| 70 |
} |
| 71 |
|
| 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 (); \ |
| 78 |
} |
| 79 |
#else |
| 80 |
#define CHECK_0ARG(func, result) \ |
| 81 |
if (func () != result) \ |
| 82 |
abort (); |
| 83 |
|
| 84 |
#define CHECK_1ARG(func, arg, result) \ |
| 85 |
if (func (arg) != result) \ |
| 86 |
abort (); |
| 87 |
|
| 88 |
#define CHECK_2ARG(func, arg1, arg2, result) \ |
| 89 |
if (func (arg1, arg2) != result) \ |
| 90 |
abort (); |
| 91 |
|
| 92 |
#define CHECK_3ARG(func, arg1, arg2, arg3, result) \ |
| 93 |
if (func (arg1, arg2, arg3) != result) \ |
| 94 |
abort (); |
| 95 |
#endif |
| 96 |
|
| 97 |
int |
| 98 |
main (void) |
| 99 |
{ |
| 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; |
| 104 |
} |
| 105 |
|
| 106 |
/* The following builtins are compiled but |
| 107 |
not executed because they need OS support. */ |
| 108 |
|
| 109 |
void |
| 110 |
rxbreak (void) |
| 111 |
{ |
| 112 |
__builtin_rx_brk (); |
| 113 |
} |
| 114 |
|
| 115 |
void |
| 116 |
interrupt (void) |
| 117 |
{ |
| 118 |
__builtin_rx_int (0x12); |
| 119 |
} |
| 120 |
|
| 121 |
int |
| 122 |
get_stack_pointer (void) |
| 123 |
{ |
| 124 |
return __builtin_rx_mvfc (2); |
| 125 |
} |
| 126 |
|
| 127 |
void |
| 128 |
set_stack_pointer (int value) |
| 129 |
{ |
| 130 |
__builtin_rx_mvtc (2, value); |
| 131 |
__builtin_rx_mvtc (2, 0x1234); |
| 132 |
} |
| 133 |
|
| 134 |
void |
| 135 |
wait (void) |
| 136 |
{ |
| 137 |
__builtin_rx_wait (); |
| 138 |
} |
| 139 |
|
| 140 |
#ifndef __RX_DISALLOW_STRING_INSNS__ |
| 141 |
void |
| 142 |
rmpa (int * multiplicand, int * multiplier, int num) |
| 143 |
{ |
| 144 |
__builtin_rx_rmpa (); |
| 145 |
} |
| 146 |
#endif |