| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O3 -mvsx" } */ |
| 3 |
/* { dg-additional-options "-mdejagnu-cpu=power8" { target { ! has_arch_pwr8 } } } */ |
| 4 |
/* { dg-require-effective-target p8vector_hw } */ |
| 5 |
|
| 6 |
#include "sse2-check.h" |
| 7 |
|
| 8 |
#ifndef TEST |
| 9 |
#define TEST sse2_test_mmx_1 |
| 10 |
#endif |
| 11 |
|
| 12 |
#include <mmintrin.h> |
| 13 |
|
| 14 |
#define N 4 |
| 15 |
|
| 16 |
unsigned long long a[N], b[N], result[N]; |
| 17 |
|
| 18 |
unsigned long long check_data[N] = |
| 19 |
{ 0x101010101010100full, |
| 20 |
0x1010101010101010ull, |
| 21 |
0x1010101010101010ull, |
| 22 |
0x1010101010101010ull }; |
| 23 |
|
| 24 |
__m64 |
| 25 |
unsigned_add3 (const __m64 * a, const __m64 * b, |
| 26 |
__m64 * result, unsigned int count) |
| 27 |
{ |
| 28 |
__m64 _a, _b, one, sum, carry, onesCarry; |
| 29 |
|
| 30 |
unsigned int i; |
| 31 |
|
| 32 |
carry = _mm_setzero_si64 (); |
| 33 |
|
| 34 |
one = _mm_cmpeq_pi8 (carry, carry); |
| 35 |
one = _mm_sub_si64 (carry, one); |
| 36 |
|
| 37 |
for (i = 0; i < count; i++) |
| 38 |
{ |
| 39 |
_a = a[i]; |
| 40 |
_b = b[i]; |
| 41 |
|
| 42 |
sum = _mm_add_si64 (_a, _b); |
| 43 |
sum = _mm_add_si64 (sum, carry); |
| 44 |
|
| 45 |
result[i] = sum; |
| 46 |
|
| 47 |
onesCarry = _mm_and_si64 (_mm_xor_si64 (_a, _b), carry); |
| 48 |
onesCarry = _mm_or_si64 (_mm_and_si64 (_a, _b), onesCarry); |
| 49 |
onesCarry = _mm_and_si64 (onesCarry, one); |
| 50 |
|
| 51 |
_a = _mm_srli_si64 (_a, 1); |
| 52 |
_b = _mm_srli_si64 (_b, 1); |
| 53 |
|
| 54 |
carry = _mm_add_si64 (_mm_add_si64 (_a, _b), onesCarry); |
| 55 |
carry = _mm_srli_si64 (carry, 63); |
| 56 |
} |
| 57 |
|
| 58 |
return carry; |
| 59 |
} |
| 60 |
|
| 61 |
void __attribute__((noinline)) |
| 62 |
TEST (void) |
| 63 |
{ |
| 64 |
unsigned long long carry; |
| 65 |
int i; |
| 66 |
|
| 67 |
/* Really long numbers. */ |
| 68 |
a[3] = a[2] = a[1] = a[0] = 0xd3d3d3d3d3d3d3d3ull; |
| 69 |
b[3] = b[2] = b[1] = b[0] = 0x3c3c3c3c3c3c3c3cull; |
| 70 |
|
| 71 |
carry = (unsigned long long) unsigned_add3 |
| 72 |
((__m64 *)a, (__m64 *)b, (__m64 *)result, N); |
| 73 |
|
| 74 |
_mm_empty (); |
| 75 |
|
| 76 |
if (carry != 1) |
| 77 |
abort (); |
| 78 |
|
| 79 |
for (i = 0; i < N; i++) |
| 80 |
if (result [i] != check_data[i]) |
| 81 |
abort (); |
| 82 |
} |