Update concepts branch to revision 131834
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / sse2-mmx.c
blobca375cb90d977f09a99a37b93438c320eb1d0b7f
1 /* { dg-do run } */
2 /* { dg-options "-O2 -msse2" } */
4 #include "sse2-check.h"
6 #include <mmintrin.h>
8 #define N 4
10 unsigned long long a[N], b[N], result[N];
12 unsigned long long check[N] =
13 { 0x101010101010100full,
14 0x1010101010101010ull,
15 0x1010101010101010ull,
16 0x1010101010101010ull };
18 __m64
19 unsigned_add3 (const __m64 * a, const __m64 * b,
20 __m64 * result, unsigned int count)
22 __m64 _a, _b, one, sum, carry, onesCarry;
24 unsigned int i;
26 carry = _mm_setzero_si64 ();
28 one = _mm_cmpeq_pi8 (carry, carry);
29 one = _mm_sub_si64 (carry, one);
31 for (i = 0; i < count; i++)
33 _a = a[i];
34 _b = b[i];
36 sum = _mm_add_si64 (_a, _b);
37 sum = _mm_add_si64 (sum, carry);
39 result[i] = sum;
41 onesCarry = _mm_and_si64 (_mm_xor_si64 (_a, _b), carry);
42 onesCarry = _mm_or_si64 (_mm_and_si64 (_a, _b), onesCarry);
43 onesCarry = _mm_and_si64 (onesCarry, one);
45 _a = _mm_srli_si64 (_a, 1);
46 _b = _mm_srli_si64 (_b, 1);
48 carry = _mm_add_si64 (_mm_add_si64 (_a, _b), onesCarry);
49 carry = _mm_srli_si64 (carry, 63);
52 return carry;
55 void __attribute__((noinline))
56 sse2_test (void)
58 unsigned long long carry;
59 int i;
61 /* Really long numbers. */
62 a[3] = a[2] = a[1] = a[0] = 0xd3d3d3d3d3d3d3d3ull;
63 b[3] = b[2] = b[1] = b[0] = 0x3c3c3c3c3c3c3c3cull;
65 carry = (unsigned long long) unsigned_add3
66 ((__m64 *)a, (__m64 *)b, (__m64 *)result, N);
68 _mm_empty ();
70 if (carry != 1)
71 abort ();
73 for (i = 0; i < N; i++)
74 if (result [i] != check[i])
75 abort ();