diff options
| author | gingerBill <bill@gingerbill.org> | 2020-04-11 21:34:55 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-04-11 21:34:55 +0100 |
| commit | 90593fe6ae1a66ea5037140d14c7666fd073894c (patch) | |
| tree | 9afa3504eed1addf0e1ef5f8e76dbd7a25dfacdc /core/runtime | |
| parent | 16b4178b8a9bb132e4b2361b95b53f791162a445 (diff) | |
Endian specific floating point types (e.g. f32be)
Diffstat (limited to 'core/runtime')
| -rw-r--r-- | core/runtime/core.odin | 2 | ||||
| -rw-r--r-- | core/runtime/internal.odin | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 3ef992e8e..d906c28b7 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -57,7 +57,7 @@ Type_Info_Struct_Soa_Kind :: enum u8 { Type_Info_Named :: struct {name: string, base: ^Type_Info}; Type_Info_Integer :: struct {signed: bool, endianness: Platform_Endianness}; Type_Info_Rune :: struct {}; -Type_Info_Float :: struct {}; +Type_Info_Float :: struct {endianness: Platform_Endianness}; Type_Info_Complex :: struct {}; Type_Info_Quaternion :: struct {}; Type_Info_String :: struct {is_cstring: bool}; diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index 4b3039802..9dd166d8e 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -18,6 +18,22 @@ bswap_128 :: proc "none" (x: u128) -> u128 { return u128(bswap_64(u64(x))) | u128(bswap_64(u64(x>>64))); } + +bswap_f32 :: proc "none" (f: f32) -> f32 { + x := transmute(u32)f; + z := x>>24 | (x>>8)&0xff00 | (x<<8)&0xff0000 | x<<24; + return transmute(f32)z; + +} + +bswap_f64 :: proc "none" (f: f64) -> f64 { + x := transmute(u64)f; + z := u64(bswap_32(u32(x))) | u64(bswap_32(u32(x>>32))); + return transmute(f64)z; +} + + + ptr_offset :: inline proc "contextless" (ptr: $P/^$T, n: int) -> P { new := int(uintptr(ptr)) + size_of(T)*n; return P(uintptr(new)); |