From c3347d6815a4a51298d5d697e22e088b5aa02962 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 21 Apr 2023 16:02:13 +0300 Subject: [PATCH] move f32 to h.h, add reinterpreting helper methods --- src/builtins/arithd.c | 3 --- src/h.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/builtins/arithd.c b/src/builtins/arithd.c index 955faf59..b88c4c00 100644 --- a/src/builtins/arithd.c +++ b/src/builtins/arithd.c @@ -41,9 +41,6 @@ B sub_c1(B t, B x); B fne_c1(B t, B x); B shape_c2(B t, B w, B x); -// TODO move to h.h -typedef float f32; - // all divint/floordiv/modint assume integer arguments // floordiv will return float result only on ¯2147483648÷¯1 or n÷0, but may not otherwise squeeze integer types; integer argument requirement may be relaxed in the future // divint will return float result if there's a fractional result, or in overflow cases same as floordiv diff --git a/src/h.h b/src/h.h index cfd7768f..42bb7b57 100644 --- a/src/h.h +++ b/src/h.h @@ -113,6 +113,7 @@ typedef uint32_t u32; typedef int64_t i64; typedef uint64_t u64; typedef double f64; +typedef float f32; typedef size_t ux; #if defined(__SIZEOF_INT128__) #define HAS_U128 1 @@ -232,6 +233,16 @@ typedef union B { } B; #define b(x) ((B)(x)) +typedef union { u32 u; f32 f; } F32R; +FORCE_INLINE u64 r_f64u(f64 x) { return ((B) x).u; } +FORCE_INLINE f64 r_u64f(u64 x) { return ((B) x).f; } +FORCE_INLINE u32 r_f32u(f32 x) { return ((F32R) x).u; } +FORCE_INLINE f32 r_u32f(u32 x) { return ((F32R) x).f; } +FORCE_INLINE u64 r_Bu(B x) { return x.u; } +FORCE_INLINE f64 r_Bf(B x) { return x.f; } +FORCE_INLINE B r_uB(u64 x) { return b(x); } +FORCE_INLINE B r_fB(f64 x) { return b(x); } + #if defined(RT_WRAP) || defined(WRAP_NNBI) #define IF_WRAP(X) X #else