| 1 |
#define NI __attribute__((noipa)) |
| 2 |
|
| 3 |
NI |
| 4 |
T shiftN (T x, int n) |
| 5 |
{ |
| 6 |
return x OP n; |
| 7 |
} |
| 8 |
|
| 9 |
#define MK_FUN(N) \ |
| 10 |
NI \ |
| 11 |
T shift_##N##_r22 (T x) \ |
| 12 |
{ \ |
| 13 |
return x OP N; \ |
| 14 |
} \ |
| 15 |
\ |
| 16 |
NI \ |
| 17 |
T shift_##N##_r20 (T x) \ |
| 18 |
{ \ |
| 19 |
register T r20 __asm("20") = x OP N; \ |
| 20 |
__asm ("nop ; %0" : "+r" (r20)); \ |
| 21 |
return r20; \ |
| 22 |
} \ |
| 23 |
\ |
| 24 |
NI \ |
| 25 |
T shift_##N##_r24 (T x) \ |
| 26 |
{ \ |
| 27 |
register T r24 __asm("24") = x OP N; \ |
| 28 |
__asm ("nop ; %0" : "+r" (r24)); \ |
| 29 |
return r24; \ |
| 30 |
} \ |
| 31 |
|
| 32 |
MK_FUN (1) |
| 33 |
MK_FUN (2) |
| 34 |
MK_FUN (3) |
| 35 |
MK_FUN (4) |
| 36 |
MK_FUN (5) |
| 37 |
MK_FUN (6) |
| 38 |
MK_FUN (7) |
| 39 |
|
| 40 |
#if BITS > 8 |
| 41 |
MK_FUN (8) |
| 42 |
MK_FUN (9) |
| 43 |
MK_FUN (10) |
| 44 |
MK_FUN (11) |
| 45 |
MK_FUN (12) |
| 46 |
MK_FUN (13) |
| 47 |
MK_FUN (14) |
| 48 |
MK_FUN (15) |
| 49 |
#endif |
| 50 |
|
| 51 |
#if BITS > 16 |
| 52 |
MK_FUN (16) |
| 53 |
MK_FUN (17) |
| 54 |
MK_FUN (18) |
| 55 |
MK_FUN (19) |
| 56 |
MK_FUN (20) |
| 57 |
MK_FUN (21) |
| 58 |
MK_FUN (22) |
| 59 |
MK_FUN (23) |
| 60 |
#endif |
| 61 |
|
| 62 |
#if BITS > 24 |
| 63 |
MK_FUN (24) |
| 64 |
MK_FUN (25) |
| 65 |
MK_FUN (26) |
| 66 |
MK_FUN (27) |
| 67 |
MK_FUN (28) |
| 68 |
MK_FUN (29) |
| 69 |
MK_FUN (30) |
| 70 |
MK_FUN (31) |
| 71 |
#endif |
| 72 |
|
| 73 |
#define ARRAY_SIZE(X) ((int) (sizeof (X) / sizeof (*X))) |
| 74 |
|
| 75 |
#ifdef __FLASH |
| 76 |
#define AS __flash |
| 77 |
#else |
| 78 |
#define AS /* empty */ |
| 79 |
#endif |
| 80 |
|
| 81 |
typedef T (*fun_t) (T); |
| 82 |
|
| 83 |
typedef struct |
| 84 |
{ |
| 85 |
fun_t f[3]; |
| 86 |
} fun3_t; |
| 87 |
|
| 88 |
#define FN(N) { { shift_##N##_r20, shift_##N##_r22, shift_##N##_r24 } } |
| 89 |
|
| 90 |
const AS fun3_t funcs[] = |
| 91 |
{ |
| 92 |
FN (1), FN (2), FN (3), FN (4), FN (5), FN (6), FN (7), |
| 93 |
#if BITS > 8 |
| 94 |
FN (8), FN (9), FN (10), FN (11), FN (12), FN (13), FN (14), FN (15), |
| 95 |
#endif |
| 96 |
#if BITS > 16 |
| 97 |
FN (16), FN (17), FN (18), FN (19), FN (20), FN (21), FN (22), FN (23), |
| 98 |
#endif |
| 99 |
#if BITS > 24 |
| 100 |
FN (24), FN (25), FN (26), FN (27), FN (28), FN (29), FN (30), FN (31), |
| 101 |
#endif |
| 102 |
}; |
| 103 |
|
| 104 |
void test1 (fun_t fun, T x, int n) |
| 105 |
{ |
| 106 |
T res = shiftN (x, n); |
| 107 |
if (res != fun (x)) |
| 108 |
__builtin_abort (); |
| 109 |
} |
| 110 |
|
| 111 |
void testx (T x) |
| 112 |
{ |
| 113 |
for (int i = 0; i < ARRAY_SIZE (funcs); ++i) |
| 114 |
{ |
| 115 |
const int n = 1 + i; |
| 116 |
const T res = shiftN (x, n); |
| 117 |
|
| 118 |
for (int j = 0; j < ARRAY_SIZE (funcs[i].f); ++j) |
| 119 |
{ |
| 120 |
fun_t f = funcs[i].f[j]; |
| 121 |
if (f (x) != res) |
| 122 |
__builtin_abort (); |
| 123 |
} |
| 124 |
} |
| 125 |
} |