diff options
| author | gingerBill <bill@gingerbill.org> | 2020-04-11 19:26:16 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-04-11 19:26:16 +0100 |
| commit | baf5b9edc31eda5fe79dd1fee4b9a4378b10bd8b (patch) | |
| tree | c00c5983929ae72a2a34919be1831b165d3c2fde /core/runtime | |
| parent | 62dc99dbefa4dece8948672c295745f572d2978a (diff) | |
Add `runtime.bswap_*` required for -llvm-api
Diffstat (limited to 'core/runtime')
| -rw-r--r-- | core/runtime/internal.odin | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index 2d4388bb2..4b3039802 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -2,6 +2,22 @@ package runtime import "core:os" +bswap_16 :: proc "none" (x: u16) -> u16 { + return x>>8 | x<<16; +} + +bswap_32 :: proc "none" (x: u32) -> u32 { + return x>>24 | (x>>8)&0xff00 | (x<<8)&0xff0000 | x<<24; +} + +bswap_64 :: proc "none" (x: u64) -> u64 { + return u64(bswap_32(u32(x))) | u64(bswap_32(u32(x>>32))); +} + +bswap_128 :: proc "none" (x: u128) -> u128 { + return u128(bswap_64(u64(x))) | u128(bswap_64(u64(x>>64))); +} + ptr_offset :: inline proc "contextless" (ptr: $P/^$T, n: int) -> P { new := int(uintptr(ptr)) + size_of(T)*n; return P(uintptr(new)); |