| 1 |
/* { dg-options { -std=gnu99 } } */ |
| 2 |
|
| 3 |
void f7_clr (void *cc) |
| 4 |
{ |
| 5 |
__asm ("%~call __f7_clr_asm" :: "z" (cc) : "memory"); |
| 6 |
} |
| 7 |
|
| 8 |
void* f7_copy (void *cc, const void *aa) |
| 9 |
{ |
| 10 |
extern void __f7_copy_asm (void); |
| 11 |
__asm ("%~call __f7_copy_asm" :: "z" (cc), "x" (aa) : "memory"); |
| 12 |
return cc; |
| 13 |
} |
| 14 |
|
| 15 |
typedef _Bool bool; |
| 16 |
typedef unsigned int uint16_t; |
| 17 |
typedef unsigned char uint8_t; |
| 18 |
typedef int int16_t; |
| 19 |
|
| 20 |
typedef struct f7_t |
| 21 |
{ |
| 22 |
union |
| 23 |
{ |
| 24 |
struct |
| 25 |
{ |
| 26 |
uint8_t sign :1; |
| 27 |
uint8_t reserved1 :1; |
| 28 |
uint8_t is_nan :1; |
| 29 |
uint8_t reserved2 :4; |
| 30 |
uint8_t is_inf :1; |
| 31 |
}; |
| 32 |
uint8_t flags; |
| 33 |
}; |
| 34 |
|
| 35 |
uint8_t mant[7]; |
| 36 |
int16_t expo; |
| 37 |
} f7_t; |
| 38 |
|
| 39 |
|
| 40 |
static inline __attribute__((__always_inline__)) |
| 41 |
void __f7_clr (f7_t *cc) |
| 42 |
{ |
| 43 |
extern void __f7_clr_asm (void); |
| 44 |
__asm ("%~call %x[f]" |
| 45 |
: |
| 46 |
: [f] "i" (__f7_clr_asm), "z" (cc) |
| 47 |
: "memory"); |
| 48 |
} |
| 49 |
|
| 50 |
static inline __attribute__((__always_inline__)) |
| 51 |
bool __f7_signbit (const f7_t *aa) |
| 52 |
{ |
| 53 |
return aa->flags & (1 << 0); |
| 54 |
} |
| 55 |
|
| 56 |
static inline __attribute__((__always_inline__)) |
| 57 |
int16_t sub_ssat16 (int16_t a, int16_t b) |
| 58 |
{ |
| 59 |
_Sat _Fract sa = __builtin_avr_rbits (a); |
| 60 |
_Sat _Fract sb = __builtin_avr_rbits (b); |
| 61 |
return __builtin_avr_bitsr (sa - sb); |
| 62 |
} |
| 63 |
|
| 64 |
extern void __f7_Iadd (f7_t*, const f7_t*); |
| 65 |
extern void __f7_addsub (f7_t*, const f7_t*, const f7_t*, bool neg_b); |
| 66 |
extern uint8_t __f7_mulx (f7_t*, const f7_t*, const f7_t*, bool); |
| 67 |
extern f7_t* __f7_normalize_asm (f7_t*); |
| 68 |
|
| 69 |
void __f7_madd_msub (f7_t *cc, const f7_t *aa, const f7_t *bb, const f7_t *dd, |
| 70 |
bool neg_d) |
| 71 |
{ |
| 72 |
f7_t xx7, *xx = &xx7; |
| 73 |
uint8_t x_lsb = __f7_mulx (xx, aa, bb, 1 ); |
| 74 |
uint8_t x_sign = __f7_signbit (xx); |
| 75 |
int16_t x_expo = xx->expo; |
| 76 |
__f7_addsub (xx, xx, dd, neg_d); |
| 77 |
|
| 78 |
|
| 79 |
__f7_clr (cc); |
| 80 |
cc->expo = sub_ssat16 (x_expo, (8 * 7)); |
| 81 |
cc->mant[7 - 1] = x_lsb; |
| 82 |
cc = __f7_normalize_asm (cc); |
| 83 |
cc->flags = x_sign; |
| 84 |
__f7_Iadd (cc, xx); |
| 85 |
} |
| 86 |
|