| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-O2 -ftree-vectorize" } */ |
| 3 |
|
| 4 |
typedef unsigned char uint8_t; |
| 5 |
typedef unsigned short uint16_t; |
| 6 |
typedef unsigned int uint32_t; |
| 7 |
|
| 8 |
/* 8-bit SWAR tests. */ |
| 9 |
|
| 10 |
static uint8_t packed_cmp_8_8(uint8_t a) |
| 11 |
{ |
| 12 |
return ((a >> 7) & 0x1U) * 0xffU; |
| 13 |
} |
| 14 |
|
| 15 |
/* 16-bit SWAR tests. */ |
| 16 |
|
| 17 |
static uint16_t packed_cmp_8_16(uint16_t a) |
| 18 |
{ |
| 19 |
return ((a >> 7) & 0x101U) * 0xffU; |
| 20 |
} |
| 21 |
|
| 22 |
static uint16_t packed_cmp_16_16(uint16_t a) |
| 23 |
{ |
| 24 |
return ((a >> 15) & 0x1U) * 0xffffU; |
| 25 |
} |
| 26 |
|
| 27 |
/* 32-bit SWAR tests. */ |
| 28 |
|
| 29 |
static uint32_t packed_cmp_8_32(uint32_t a) |
| 30 |
{ |
| 31 |
return ((a >> 7) & 0x1010101U) * 0xffU; |
| 32 |
} |
| 33 |
|
| 34 |
static uint32_t packed_cmp_16_32(uint32_t a) |
| 35 |
{ |
| 36 |
return ((a >> 15) & 0x10001U) * 0xffffU; |
| 37 |
} |
| 38 |
|
| 39 |
static uint32_t packed_cmp_32_32(uint32_t a) |
| 40 |
{ |
| 41 |
return ((a >> 31) & 0x1U) * 0xffffffffU; |
| 42 |
} |
| 43 |
|
| 44 |
/* Driver function to test the vectorized code generated for the different |
| 45 |
packed_cmp variants. */ |
| 46 |
|
| 47 |
#define VECTORIZED_PACKED_CMP(T, FUNC) \ |
| 48 |
void vectorized_cmp_##FUNC(T* a, int n) \ |
| 49 |
{ \ |
| 50 |
n = (n / 32) * 32; \ |
| 51 |
for(int i = 0; i < n; i += 4) \ |
| 52 |
{ \ |
| 53 |
a[i + 0] = FUNC(a[i + 0]); \ |
| 54 |
a[i + 1] = FUNC(a[i + 1]); \ |
| 55 |
a[i + 2] = FUNC(a[i + 2]); \ |
| 56 |
a[i + 3] = FUNC(a[i + 3]); \ |
| 57 |
} \ |
| 58 |
} |
| 59 |
|
| 60 |
VECTORIZED_PACKED_CMP(uint8_t, packed_cmp_8_8); |
| 61 |
|
| 62 |
VECTORIZED_PACKED_CMP(uint16_t, packed_cmp_8_16); |
| 63 |
VECTORIZED_PACKED_CMP(uint16_t, packed_cmp_16_16); |
| 64 |
|
| 65 |
VECTORIZED_PACKED_CMP(uint32_t, packed_cmp_8_32); |
| 66 |
VECTORIZED_PACKED_CMP(uint32_t, packed_cmp_16_32); |
| 67 |
VECTORIZED_PACKED_CMP(uint32_t, packed_cmp_32_32); |
| 68 |
|
| 69 |
/* { dg-final { scan-assembler {\tcmlt\t} } } */ |
| 70 |
/* { dg-final { scan-assembler-not {\tushr\t} } } */ |
| 71 |
/* { dg-final { scan-assembler-not {\tshl\t} } } */ |
| 72 |
/* { dg-final { scan-assembler-not {\tmul\t} } } */ |