| 1 |
/* Test __bf16 complex arithmetic. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "" } */ |
| 4 |
/* { dg-add-options bfloat16 } */ |
| 5 |
/* { dg-require-effective-target bfloat16_runtime } */ |
| 6 |
|
| 7 |
extern void exit (int); |
| 8 |
extern void abort (void); |
| 9 |
|
| 10 |
volatile __bf16 a = 1.0bf16; |
| 11 |
typedef _Complex float __cbf16 __attribute__((__mode__(__BC__))); |
| 12 |
volatile __cbf16 b = __builtin_complex (2.0bf16, 3.0bf16); |
| 13 |
volatile __cbf16 c = __builtin_complex (2.0bf16, 3.0bf16); |
| 14 |
volatile __cbf16 d = __builtin_complex (2.0bf16, 3.0bf16); |
| 15 |
|
| 16 |
__cbf16 |
| 17 |
fn (__cbf16 arg) |
| 18 |
{ |
| 19 |
return arg / 4; |
| 20 |
} |
| 21 |
|
| 22 |
int |
| 23 |
main (void) |
| 24 |
{ |
| 25 |
volatile __cbf16 r; |
| 26 |
if (b != c) |
| 27 |
abort (); |
| 28 |
if (b != d) |
| 29 |
abort (); |
| 30 |
r = a + b; |
| 31 |
if (__real__ r != 3.0bf16 || __imag__ r != 3.0bf16) |
| 32 |
abort (); |
| 33 |
r += d; |
| 34 |
if (__real__ r != 5.0bf16 || __imag__ r != 6.0bf16) |
| 35 |
abort (); |
| 36 |
r -= a; |
| 37 |
if (__real__ r != 4.0bf16 || __imag__ r != 6.0bf16) |
| 38 |
abort (); |
| 39 |
r /= (a + a); |
| 40 |
if (__real__ r != 2.0bf16 || __imag__ r != 3.0bf16) |
| 41 |
abort (); |
| 42 |
r *= (a + a); |
| 43 |
if (__real__ r != 4.0bf16 || __imag__ r != 6.0bf16) |
| 44 |
abort (); |
| 45 |
r -= b; |
| 46 |
if (__real__ r != 2.0bf16 || __imag__ r != 3.0bf16) |
| 47 |
abort (); |
| 48 |
r *= r; |
| 49 |
if (__real__ r != -5.0bf16 || __imag__ r != 12.0bf16) |
| 50 |
abort (); |
| 51 |
/* Division may not be exact, so round result before comparing. */ |
| 52 |
r /= b; |
| 53 |
r += __builtin_complex (100.0bf16, 100.0bf16); |
| 54 |
r -= __builtin_complex (100.0bf16, 100.0bf16); |
| 55 |
if (r != b) |
| 56 |
abort (); |
| 57 |
r = fn (r); |
| 58 |
if (__real__ r != 0.5bf16 || __imag__ r != 0.75bf16) |
| 59 |
abort (); |
| 60 |
exit (0); |
| 61 |
} |