Endian specific floating point types (e.g. f32be)

This commit is contained in:
gingerBill
2020-04-11 21:34:55 +01:00
parent 16b4178b8a
commit 90593fe6ae
9 changed files with 178 additions and 7 deletions
+1 -1
View File
@@ -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};
+16
View File
@@ -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));