From: Brendan Hansen Date: Sat, 8 Apr 2023 18:06:25 +0000 (-0500) Subject: added: reinterpret intrinsics X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=6f05aa63f01d1b676f922b62d56c5ab147392440;p=onyx.git added: reinterpret intrinsics --- diff --git a/compiler/include/astnodes.h b/compiler/include/astnodes.h index 7bf74752..db91ff4e 100644 --- a/compiler/include/astnodes.h +++ b/compiler/include/astnodes.h @@ -391,6 +391,10 @@ typedef enum OnyxIntrinsic { ONYX_INTRINSIC_F64_MIN, ONYX_INTRINSIC_F64_MAX, ONYX_INTRINSIC_F64_COPYSIGN, + ONYX_INTRINSIC_I32_REINTERPRET_F32, + ONYX_INTRINSIC_I64_REINTERPRET_F64, + ONYX_INTRINSIC_F32_REINTERPRET_I32, + ONYX_INTRINSIC_F64_REINTERPRET_I64, ONYX_INTRINSIC_V128_CONST, diff --git a/compiler/src/builtins.c b/compiler/src/builtins.c index 41724010..6491f385 100644 --- a/compiler/src/builtins.c +++ b/compiler/src/builtins.c @@ -160,6 +160,11 @@ static IntrinsicMap builtin_intrinsics[] = { { "max_f64", ONYX_INTRINSIC_F64_MAX }, { "copysign_f64", ONYX_INTRINSIC_F64_COPYSIGN }, + { "reinterpret_f32", ONYX_INTRINSIC_I32_REINTERPRET_F32 }, + { "reinterpret_f64", ONYX_INTRINSIC_I64_REINTERPRET_F64 }, + { "reinterpret_i32", ONYX_INTRINSIC_F32_REINTERPRET_I32 }, + { "reinterpret_i64", ONYX_INTRINSIC_F64_REINTERPRET_I64 }, + // SIMD Intrinsics { "v128_const", ONYX_INTRINSIC_V128_CONST }, diff --git a/compiler/src/wasm_emit.c b/compiler/src/wasm_emit.c index f94c0f92..463e7b7e 100644 --- a/compiler/src/wasm_emit.c +++ b/compiler/src/wasm_emit.c @@ -2337,6 +2337,11 @@ EMIT_FUNC(intrinsic_call, AstCall* call) { case ONYX_INTRINSIC_F64_MAX: WI(call->token, WI_F64_MAX); break; case ONYX_INTRINSIC_F64_COPYSIGN: WI(call->token, WI_F64_COPYSIGN); break; + case ONYX_INTRINSIC_I32_REINTERPRET_F32: WI(call->token, WI_I32_REINTERPRET_F32); break; + case ONYX_INTRINSIC_I64_REINTERPRET_F64: WI(call->token, WI_I64_REINTERPRET_F64); break; + case ONYX_INTRINSIC_F32_REINTERPRET_I32: WI(call->token, WI_F32_REINTERPRET_I32); break; + case ONYX_INTRINSIC_F64_REINTERPRET_I64: WI(call->token, WI_F64_REINTERPRET_I64); break; + case ONYX_INTRINSIC_I8X16_CONST: case ONYX_INTRINSIC_V128_CONST: SIMD_INT_CONST_INTRINSIC(u8, 16); break; case ONYX_INTRINSIC_I16X8_CONST: SIMD_INT_CONST_INTRINSIC(u16, 8); break; diff --git a/core/intrinsics/wasm.onyx b/core/intrinsics/wasm.onyx index cab1716d..59608309 100644 --- a/core/intrinsics/wasm.onyx +++ b/core/intrinsics/wasm.onyx @@ -51,3 +51,8 @@ sqrt_f64 :: (val: f64) -> f64 #intrinsic --- min_f64 :: (lhs: f64, rhs: f64) -> f64 #intrinsic --- max_f64 :: (lhs: f64, rhs: f64) -> f64 #intrinsic --- copysign_f64 :: (lhs: f64, rhs: f64) -> f64 #intrinsic --- + +reinterpret_f32 :: (val: f32) -> i32 #intrinsic --- +reinterpret_f64 :: (val: f64) -> i64 #intrinsic --- +reinterpret_i32 :: (val: i32) -> f32 #intrinsic --- +reinterpret_i64 :: (val: i64) -> f64 #intrinsic --- diff --git a/core/random/random.onyx b/core/random/random.onyx index 07092cfe..400df811 100644 --- a/core/random/random.onyx +++ b/core/random/random.onyx @@ -37,7 +37,7 @@ Random :: struct { #doc "Generates a random floating point number between `lo` and `hi`." float :: (self: &Random, lo := 0.0f, hi := 1.0f) -> f32 { - return (cast(f32) (self->int() % (1 << 20)) / cast(f32) (1 << 20)) * (hi - lo) + lo; + return (cast(f32) (self->int() % (1 << 23)) / cast(f32) (1 << 23)) * (hi - lo) + lo; } #doc "Returns a random element from a slice."