aboutsummaryrefslogtreecommitdiff
path: root/base/runtime
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2024-03-22 17:04:15 +0100
committerLaytan Laats <laytanlaats@hotmail.com>2024-03-22 17:04:15 +0100
commitbb5dab342a8e0f3edbbad2c2f03ba5967e3b7fca (patch)
treeddf1e5dc797d84df7e79e0e72f7c6befaf5acada /base/runtime
parent7d6e9ef39cc46e957a5f8c67c01eb5f5b232597e (diff)
fix wasm with `-target-features:"simd128"`
the required procs within wasm would compile to take native v128 arguments in, but the procs are supposed to take in i64's causing bad wasm modules. Fixes #3263
Diffstat (limited to 'base/runtime')
-rw-r--r--base/runtime/internal.odin8
-rw-r--r--base/runtime/procs_wasm.odin30
2 files changed, 27 insertions, 11 deletions
diff --git a/base/runtime/internal.odin b/base/runtime/internal.odin
index 62bee8620..6ca61c721 100644
--- a/base/runtime/internal.odin
+++ b/base/runtime/internal.odin
@@ -962,9 +962,11 @@ udivmodti4 :: proc "c" (a, b: u128, rem: ^u128) -> u128 {
return udivmod128(a, b, rem)
}
-@(link_name="__udivti3", linkage=RUNTIME_LINKAGE, require=RUNTIME_REQUIRE)
-udivti3 :: proc "c" (a, b: u128) -> u128 {
- return udivmodti4(a, b, nil)
+when !IS_WASM {
+ @(link_name="__udivti3", linkage=RUNTIME_LINKAGE, require=RUNTIME_REQUIRE)
+ udivti3 :: proc "c" (a, b: u128) -> u128 {
+ return udivmodti4(a, b, nil)
+ }
}
diff --git a/base/runtime/procs_wasm.odin b/base/runtime/procs_wasm.odin
index 26dcfef77..7501df460 100644
--- a/base/runtime/procs_wasm.odin
+++ b/base/runtime/procs_wasm.odin
@@ -7,19 +7,25 @@ ti_int :: struct #raw_union {
all: i128,
}
+@(private="file")
+ti_uint :: struct #raw_union {
+ using s: struct { lo, hi: u64 },
+ all: u128,
+}
+
@(link_name="__ashlti3", linkage="strong")
-__ashlti3 :: proc "contextless" (a: i128, b_: u32) -> i128 {
+__ashlti3 :: proc "contextless" (la, ha: u64, b_: u32) -> i128 {
bits_in_dword :: size_of(u32)*8
b := u32(b_)
input, result: ti_int
- input.all = a
+ input.lo, input.hi = la, ha
if b & bits_in_dword != 0 {
result.lo = 0
result.hi = input.lo << (b-bits_in_dword)
} else {
if b == 0 {
- return a
+ return input.all
}
result.lo = input.lo<<b
result.hi = (input.hi<<b) | (input.lo>>(bits_in_dword-b))
@@ -29,12 +35,20 @@ __ashlti3 :: proc "contextless" (a: i128, b_: u32) -> i128 {
@(link_name="__multi3", linkage="strong")
-__multi3 :: proc "contextless" (a, b: i128) -> i128 {
+__multi3 :: proc "contextless" (la, ha, lb, hb: u64) -> i128 {
x, y, r: ti_int
-
- x.all = a
- y.all = b
+
+ x.lo, x.hi = la, ha
+ y.lo, y.hi = lb, hb
r.all = i128(x.lo * y.lo) // TODO this is incorrect
r.hi += x.hi*y.lo + x.lo*y.hi
return r.all
-} \ No newline at end of file
+}
+
+@(link_name="__udivti3", linkage="strong")
+udivti3 :: proc "c" (la, ha, lb, hb: u64) -> u128 {
+ a, b: ti_uint
+ a.lo, a.hi = la, ha
+ b.lo, b.hi = lb, hb
+ return udivmodti4(a.all, b.all, nil)
+}