| 1 |
/*===---- amo.h - PowerPC Atomic Memory Operations ------------------------===*\ |
| 2 |
* |
| 3 |
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
* See https://llvm.org/LICENSE.txt for license information. |
| 5 |
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
* |
| 7 |
\*===----------------------------------------------------------------------===*/ |
| 8 |
|
| 9 |
/* This header provides compatibility for GCC's AMO functions. |
| 10 |
* The functions here call Clang's underlying AMO builtins. |
| 11 |
*/ |
| 12 |
|
| 13 |
#ifndef _AMO_H |
| 14 |
#define _AMO_H |
| 15 |
|
| 16 |
#include <stdint.h> |
| 17 |
|
| 18 |
#ifdef __cplusplus |
| 19 |
extern "C" { |
| 20 |
#endif |
| 21 |
|
| 22 |
/* AMO Load Operation Codes (FC values) */ |
| 23 |
enum { |
| 24 |
_AMO_LD_ADD = 0x00, /* Fetch and Add */ |
| 25 |
_AMO_LD_XOR = 0x01, /* Fetch and XOR */ |
| 26 |
_AMO_LD_IOR = 0x02, /* Fetch and OR */ |
| 27 |
_AMO_LD_AND = 0x03, /* Fetch and AND */ |
| 28 |
_AMO_LD_UMAX = 0x04, /* Fetch and Maximum Unsigned */ |
| 29 |
_AMO_LD_SMAX = 0x05, /* Fetch and Maximum Signed */ |
| 30 |
_AMO_LD_UMIN = 0x06, /* Fetch and Minimum Unsigned */ |
| 31 |
_AMO_LD_SMIN = 0x07, /* Fetch and Minimum Signed */ |
| 32 |
_AMO_LD_SWAP = 0x08 /* Swap */ |
| 33 |
}; |
| 34 |
|
| 35 |
/* 32-bit unsigned AMO load operations */ |
| 36 |
static inline uint32_t amo_lwat_add(uint32_t *ptr, uint32_t val) { |
| 37 |
return __builtin_amo_lwat(ptr, val, _AMO_LD_ADD); |
| 38 |
} |
| 39 |
|
| 40 |
static inline uint32_t amo_lwat_xor(uint32_t *ptr, uint32_t val) { |
| 41 |
return __builtin_amo_lwat(ptr, val, _AMO_LD_XOR); |
| 42 |
} |
| 43 |
|
| 44 |
static inline uint32_t amo_lwat_ior(uint32_t *ptr, uint32_t val) { |
| 45 |
return __builtin_amo_lwat(ptr, val, _AMO_LD_IOR); |
| 46 |
} |
| 47 |
|
| 48 |
static inline uint32_t amo_lwat_and(uint32_t *ptr, uint32_t val) { |
| 49 |
return __builtin_amo_lwat(ptr, val, _AMO_LD_AND); |
| 50 |
} |
| 51 |
|
| 52 |
static inline uint32_t amo_lwat_umax(uint32_t *ptr, uint32_t val) { |
| 53 |
return __builtin_amo_lwat(ptr, val, _AMO_LD_UMAX); |
| 54 |
} |
| 55 |
|
| 56 |
static inline uint32_t amo_lwat_umin(uint32_t *ptr, uint32_t val) { |
| 57 |
return __builtin_amo_lwat(ptr, val, _AMO_LD_UMIN); |
| 58 |
} |
| 59 |
|
| 60 |
static inline uint32_t amo_lwat_swap(uint32_t *ptr, uint32_t val) { |
| 61 |
return __builtin_amo_lwat(ptr, val, _AMO_LD_SWAP); |
| 62 |
} |
| 63 |
|
| 64 |
/* 32-bit signed AMO load operations */ |
| 65 |
static inline int32_t amo_lwat_sadd(int32_t *ptr, int32_t val) { |
| 66 |
return __builtin_amo_lwat_s(ptr, val, _AMO_LD_ADD); |
| 67 |
} |
| 68 |
|
| 69 |
static inline int32_t amo_lwat_smax(int32_t *ptr, int32_t val) { |
| 70 |
return __builtin_amo_lwat_s(ptr, val, _AMO_LD_SMAX); |
| 71 |
} |
| 72 |
|
| 73 |
static inline int32_t amo_lwat_smin(int32_t *ptr, int32_t val) { |
| 74 |
return __builtin_amo_lwat_s(ptr, val, _AMO_LD_SMIN); |
| 75 |
} |
| 76 |
|
| 77 |
static inline int32_t amo_lwat_sswap(int32_t *ptr, int32_t val) { |
| 78 |
return __builtin_amo_lwat_s(ptr, val, _AMO_LD_SWAP); |
| 79 |
} |
| 80 |
|
| 81 |
/* 64-bit unsigned AMO load operations */ |
| 82 |
static inline uint64_t amo_ldat_add(uint64_t *ptr, uint64_t val) { |
| 83 |
return __builtin_amo_ldat(ptr, val, _AMO_LD_ADD); |
| 84 |
} |
| 85 |
|
| 86 |
static inline uint64_t amo_ldat_xor(uint64_t *ptr, uint64_t val) { |
| 87 |
return __builtin_amo_ldat(ptr, val, _AMO_LD_XOR); |
| 88 |
} |
| 89 |
|
| 90 |
static inline uint64_t amo_ldat_ior(uint64_t *ptr, uint64_t val) { |
| 91 |
return __builtin_amo_ldat(ptr, val, _AMO_LD_IOR); |
| 92 |
} |
| 93 |
|
| 94 |
static inline uint64_t amo_ldat_and(uint64_t *ptr, uint64_t val) { |
| 95 |
return __builtin_amo_ldat(ptr, val, _AMO_LD_AND); |
| 96 |
} |
| 97 |
|
| 98 |
static inline uint64_t amo_ldat_umax(uint64_t *ptr, uint64_t val) { |
| 99 |
return __builtin_amo_ldat(ptr, val, _AMO_LD_UMAX); |
| 100 |
} |
| 101 |
|
| 102 |
static inline uint64_t amo_ldat_umin(uint64_t *ptr, uint64_t val) { |
| 103 |
return __builtin_amo_ldat(ptr, val, _AMO_LD_UMIN); |
| 104 |
} |
| 105 |
|
| 106 |
static inline uint64_t amo_ldat_swap(uint64_t *ptr, uint64_t val) { |
| 107 |
return __builtin_amo_ldat(ptr, val, _AMO_LD_SWAP); |
| 108 |
} |
| 109 |
|
| 110 |
/* 64-bit signed AMO load operations */ |
| 111 |
static inline int64_t amo_ldat_sadd(int64_t *ptr, int64_t val) { |
| 112 |
return __builtin_amo_ldat_s(ptr, val, _AMO_LD_ADD); |
| 113 |
} |
| 114 |
|
| 115 |
static inline int64_t amo_ldat_smax(int64_t *ptr, int64_t val) { |
| 116 |
return __builtin_amo_ldat_s(ptr, val, _AMO_LD_SMAX); |
| 117 |
} |
| 118 |
|
| 119 |
static inline int64_t amo_ldat_smin(int64_t *ptr, int64_t val) { |
| 120 |
return __builtin_amo_ldat_s(ptr, val, _AMO_LD_SMIN); |
| 121 |
} |
| 122 |
|
| 123 |
static inline int64_t amo_ldat_sswap(int64_t *ptr, int64_t val) { |
| 124 |
return __builtin_amo_ldat_s(ptr, val, _AMO_LD_SWAP); |
| 125 |
} |
| 126 |
|
| 127 |
#ifdef __cplusplus |
| 128 |
} |
| 129 |
#endif |
| 130 |
|
| 131 |
#endif /* _AMO_H */ |