2015-12-10 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / sse2-mmx.c
blobfb226a8e8f376623a8628496d9fcc7fa07a7f321
1 /* { dg-do run } */
2 /* { dg-options "-O2 -msse2" } */
3 /* { dg-require-effective-target sse2 } */
5 #include "sse2-check.h"
7 #include <mmintrin.h>
9 #define N 4
11 unsigned long long a[N], b[N], result[N];
13 unsigned long long check[N] =
14 { 0x101010101010100full,
15 0x1010101010101010ull,
16 0x1010101010101010ull,
17 0x1010101010101010ull };
19 __m64
20 unsigned_add3 (const __m64 * a, const __m64 * b,
21 __m64 * result, unsigned int count)
23 __m64 _a, _b, one, sum, carry, onesCarry;
25 unsigned int i;
27 carry = _mm_setzero_si64 ();
29 one = _mm_cmpeq_pi8 (carry, carry);
30 one = _mm_sub_si64 (carry, one);
32 for (i = 0; i < count; i++)
34 _a = a[i];
35 _b = b[i];
37 sum = _mm_add_si64 (_a, _b);
38 sum = _mm_add_si64 (sum, carry);
40 result[i] = sum;
42 onesCarry = _mm_and_si64 (_mm_xor_si64 (_a, _b), carry);
43 onesCarry = _mm_or_si64 (_mm_and_si64 (_a, _b), onesCarry);
44 onesCarry = _mm_and_si64 (onesCarry, one);
46 _a = _mm_srli_si64 (_a, 1);
47 _b = _mm_srli_si64 (_b, 1);
49 carry = _mm_add_si64 (_mm_add_si64 (_a, _b), onesCarry);
50 carry = _mm_srli_si64 (carry, 63);
53 return carry;
56 void __attribute__((noinline))
57 sse2_test (void)
59 unsigned long long carry;
60 int i;
62 /* Really long numbers. */
63 a[3] = a[2] = a[1] = a[0] = 0xd3d3d3d3d3d3d3d3ull;
64 b[3] = b[2] = b[1] = b[0] = 0x3c3c3c3c3c3c3c3cull;
66 carry = (unsigned long long) unsigned_add3
67 ((__m64 *)a, (__m64 *)b, (__m64 *)result, N);
69 _mm_empty ();
71 if (carry != 1)
72 abort ();
74 for (i = 0; i < N; i++)
75 if (result [i] != check[i])
76 abort ();