| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target fma4 } */ |
| 3 |
/* { dg-options "-std=gnu17 -O0 -mfma4" } */ |
| 4 |
|
| 5 |
#include "fma4-check.h" |
| 6 |
|
| 7 |
#include <x86intrin.h> |
| 8 |
#include <string.h> |
| 9 |
|
| 10 |
#define NUM 20 |
| 11 |
|
| 12 |
union |
| 13 |
{ |
| 14 |
__m128 x[NUM]; |
| 15 |
float f[NUM * 4]; |
| 16 |
__m128d y[NUM]; |
| 17 |
double d[NUM * 2]; |
| 18 |
} dst, res, src1, src2, src3; |
| 19 |
|
| 20 |
/* Note that in macc*,msub*,mnmacc* and mnsub* instructions, the intermdediate |
| 21 |
product is not rounded, only the addition is rounded. */ |
| 22 |
|
| 23 |
static void |
| 24 |
init_nmsubps () |
| 25 |
{ |
| 26 |
int i; |
| 27 |
for (i = 0; i < NUM * 4; i++) |
| 28 |
{ |
| 29 |
src1.f[i] = i; |
| 30 |
src2.f[i] = i + 10; |
| 31 |
src3.f[i] = i + 20; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
static void |
| 36 |
init_nmsubpd () |
| 37 |
{ |
| 38 |
int i; |
| 39 |
for (i = 0; i < NUM * 4; i++) |
| 40 |
{ |
| 41 |
src1.d[i] = i; |
| 42 |
src2.d[i] = i + 10; |
| 43 |
src3.d[i] = i + 20; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
static int |
| 48 |
check_nmsubps () |
| 49 |
{ |
| 50 |
int i, j, check_fails = 0; |
| 51 |
for (i = 0; i < NUM * 4; i = i + 4) |
| 52 |
for (j = 0; j < 4; j++) |
| 53 |
{ |
| 54 |
res.f[i + j] = - (src1.f[i + j] * src2.f[i + j]) - src3.f[i + j]; |
| 55 |
if (dst.f[i + j] != res.f[i + j]) |
| 56 |
check_fails++; |
| 57 |
} |
| 58 |
return check_fails; |
| 59 |
} |
| 60 |
|
| 61 |
static int |
| 62 |
check_nmsubpd () |
| 63 |
{ |
| 64 |
int i, j, check_fails = 0; |
| 65 |
for (i = 0; i < NUM * 2; i = i + 2) |
| 66 |
for (j = 0; j < 2; j++) |
| 67 |
{ |
| 68 |
res.d[i + j] = - (src1.d[i + j] * src2.d[i + j]) - src3.d[i + j]; |
| 69 |
if (dst.d[i + j] != res.d[i + j]) |
| 70 |
check_fails++; |
| 71 |
} |
| 72 |
return check_fails; |
| 73 |
} |
| 74 |
|
| 75 |
static int |
| 76 |
check_nmsubss () |
| 77 |
{ |
| 78 |
int i, j, check_fails = 0; |
| 79 |
for (i = 0; i < NUM * 4; i = i + 4) |
| 80 |
{ |
| 81 |
res.f[i] = - (src1.f[i] * src2.f[i]) - src3.f[i]; |
| 82 |
if (dst.f[i] != res.f[i]) |
| 83 |
check_fails++; |
| 84 |
} |
| 85 |
return check_fails; |
| 86 |
} |
| 87 |
|
| 88 |
static int |
| 89 |
check_nmsubsd () |
| 90 |
{ |
| 91 |
int i, j, check_fails = 0; |
| 92 |
for (i = 0; i < NUM * 2; i = i + 2) |
| 93 |
{ |
| 94 |
res.d[i] = - (src1.d[i] * src2.d[i]) - src3.d[i]; |
| 95 |
if (dst.d[i] != res.d[i]) |
| 96 |
check_fails++; |
| 97 |
} |
| 98 |
return check_fails; |
| 99 |
} |
| 100 |
|
| 101 |
static void |
| 102 |
fma4_test (void) |
| 103 |
{ |
| 104 |
int i; |
| 105 |
|
| 106 |
init_nmsubps (); |
| 107 |
|
| 108 |
for (i = 0; i < NUM; i++) |
| 109 |
dst.x[i] = _mm_nmsub_ps (src1.x[i], src2.x[i], src3.x[i]); |
| 110 |
|
| 111 |
if (check_nmsubps (&dst.x[i], &src1.f[i * 4], &src2.f[i * 4], &src3.f[i * 4])) |
| 112 |
abort (); |
| 113 |
|
| 114 |
for (i = 0; i < NUM; i++) |
| 115 |
dst.x[i] = _mm_nmsub_ss (src1.x[i], src2.x[i], src3.x[i]); |
| 116 |
|
| 117 |
if (check_nmsubss (&dst.x[i], &src1.f[i * 4], &src2.f[i * 4], &src3.f[i * 4])) |
| 118 |
abort (); |
| 119 |
|
| 120 |
init_nmsubpd (); |
| 121 |
|
| 122 |
for (i = 0; i < NUM; i++) |
| 123 |
dst.y[i] = _mm_nmsub_pd (src1.y[i], src2.y[i], src3.y[i]); |
| 124 |
|
| 125 |
if (check_nmsubpd (&dst.y[i], &src1.d[i * 2], &src2.d[i * 2], &src3.d[i * 2])) |
| 126 |
abort (); |
| 127 |
|
| 128 |
for (i = 0; i < NUM; i++) |
| 129 |
dst.y[i] = _mm_nmsub_sd (src1.y[i], src2.y[i], src3.y[i]); |
| 130 |
|
| 131 |
if (check_nmsubsd (&dst.y[i], &src1.d[i * 2], &src2.d[i * 2], &src3.d[i * 2])) |
| 132 |
abort (); |
| 133 |
} |