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
+6
View File
@@ -1802,6 +1802,12 @@ fmt_arg :: proc(fi: ^Info, arg: any, verb: rune) {
case f32: fmt_float(fi, f64(a), 32, verb);
case f64: fmt_float(fi, a, 64, verb);
case f32le: fmt_float(fi, f64(a), 32, verb);
case f64le: fmt_float(fi, f64(a), 64, verb);
case f32be: fmt_float(fi, f64(a), 32, verb);
case f64be: fmt_float(fi, f64(a), 64, verb);
case complex64: fmt_complex(fi, complex128(a), 64, verb);
case complex128: fmt_complex(fi, a, 128, verb);
+5
View File
@@ -363,6 +363,11 @@ write_type :: proc(buf: ^strings.Builder, ti: ^Type_Info) {
case Type_Info_Float:
write_byte(buf, 'f');
write_i64(buf, i64(8*ti.size), 10);
switch info.endianness {
case .Platform: // Okay
case .Little: write_string(buf, "le");
case .Big: write_string(buf, "be");
}
case Type_Info_Complex:
write_string(buf, "complex");
write_i64(buf, i64(8*ti.size), 10);
+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));