| 1 |
/* { dg-do run { target { powerpc*-*-linux* && { lp64 && p9vector_hw } } } } */ |
| 2 |
/* { dg-options "-mdejagnu-cpu=power9 -O2" } */ |
| 3 |
/* { dg-require-effective-target powerpc_vsx } */ |
| 4 |
|
| 5 |
#include <amo.h> |
| 6 |
#include <stdint.h> |
| 7 |
#include <stdlib.h> |
| 8 |
|
| 9 |
/* Test whether the ISA 3.0 amo (atomic memory operations) functions perform as |
| 10 |
expected. */ |
| 11 |
|
| 12 |
/* 32-bit tests. */ |
| 13 |
static uint32_t u32_ld[4] = { |
| 14 |
9, /* add */ |
| 15 |
7, /* xor */ |
| 16 |
6, /* ior */ |
| 17 |
7, /* and */ |
| 18 |
}; |
| 19 |
|
| 20 |
static uint32_t u32_st[4] = { |
| 21 |
9, /* add */ |
| 22 |
7, /* xor */ |
| 23 |
6, /* ior */ |
| 24 |
7, /* and */ |
| 25 |
}; |
| 26 |
|
| 27 |
static uint32_t u32_result[4]; |
| 28 |
|
| 29 |
static uint32_t u32_update[4] = { |
| 30 |
9 + 1, /* add */ |
| 31 |
7 ^ 1, /* xor */ |
| 32 |
6 | 1, /* ior */ |
| 33 |
7 & 1, /* and */ |
| 34 |
}; |
| 35 |
|
| 36 |
static uint32_t u32_prev[4] = { |
| 37 |
9, /* add */ |
| 38 |
7, /* xor */ |
| 39 |
6, /* ior */ |
| 40 |
7, /* and */ |
| 41 |
}; |
| 42 |
|
| 43 |
/* 64-bit tests. */ |
| 44 |
static uint64_t u64_ld[4] = { |
| 45 |
9, /* add */ |
| 46 |
7, /* xor */ |
| 47 |
6, /* ior */ |
| 48 |
7, /* and */ |
| 49 |
}; |
| 50 |
|
| 51 |
static uint64_t u64_st[4] = { |
| 52 |
9, /* add */ |
| 53 |
7, /* xor */ |
| 54 |
6, /* ior */ |
| 55 |
7, /* and */ |
| 56 |
}; |
| 57 |
|
| 58 |
static uint64_t u64_result[4]; |
| 59 |
|
| 60 |
static uint64_t u64_update[4] = { |
| 61 |
9 + 1, /* add */ |
| 62 |
7 ^ 1, /* xor */ |
| 63 |
6 | 1, /* ior */ |
| 64 |
7 & 1, /* and */ |
| 65 |
}; |
| 66 |
|
| 67 |
static uint64_t u64_prev[4] = { |
| 68 |
9, /* add */ |
| 69 |
7, /* xor */ |
| 70 |
6, /* ior */ |
| 71 |
7, /* and */ |
| 72 |
}; |
| 73 |
|
| 74 |
int |
| 75 |
main (void) |
| 76 |
{ |
| 77 |
size_t i; |
| 78 |
|
| 79 |
u32_result[0] = amo_lwat_add (&u32_ld[0], 1); |
| 80 |
u32_result[1] = amo_lwat_xor (&u32_ld[1], 1); |
| 81 |
u32_result[2] = amo_lwat_ior (&u32_ld[2], 1); |
| 82 |
u32_result[3] = amo_lwat_and (&u32_ld[3], 1); |
| 83 |
|
| 84 |
u64_result[0] = amo_ldat_add (&u64_ld[0], 1); |
| 85 |
u64_result[1] = amo_ldat_xor (&u64_ld[1], 1); |
| 86 |
u64_result[2] = amo_ldat_ior (&u64_ld[2], 1); |
| 87 |
u64_result[3] = amo_ldat_and (&u64_ld[3], 1); |
| 88 |
|
| 89 |
amo_stwat_add (&u32_st[0], 1); |
| 90 |
amo_stwat_xor (&u32_st[1], 1); |
| 91 |
amo_stwat_ior (&u32_st[2], 1); |
| 92 |
amo_stwat_and (&u32_st[3], 1); |
| 93 |
|
| 94 |
amo_stdat_add (&u64_st[0], 1); |
| 95 |
amo_stdat_xor (&u64_st[1], 1); |
| 96 |
amo_stdat_ior (&u64_st[2], 1); |
| 97 |
amo_stdat_and (&u64_st[3], 1); |
| 98 |
|
| 99 |
for (i = 0; i < 4; i++) |
| 100 |
{ |
| 101 |
if (u32_result[i] != u32_prev[i]) |
| 102 |
abort (); |
| 103 |
|
| 104 |
if (u32_ld[i] != u32_update[i]) |
| 105 |
abort (); |
| 106 |
|
| 107 |
if (u32_st[i] != u32_update[i]) |
| 108 |
abort (); |
| 109 |
|
| 110 |
if (u64_result[i] != u64_prev[i]) |
| 111 |
abort (); |
| 112 |
|
| 113 |
if (u64_ld[i] != u64_update[i]) |
| 114 |
abort (); |
| 115 |
|
| 116 |
if (u64_st[i] != u64_update[i]) |
| 117 |
abort (); |
| 118 |
} |
| 119 |
|
| 120 |
return 0; |
| 121 |
} |