Add f32/f64 support
Floats live in the existing 8-byte stack slots as raw bits and are computed with scalar SSE ops via xmm0/xmm1. Adds consts, loads/stores, comparisons (NaN-correct), abs/neg/copysign, ceil/floor/trunc/nearest (roundss/sd), sqrt, add/sub/mul/div, wasm-semantics min/max (NaN propagating, -0 < +0), int<->float conversions (incl. unsigned 64-bit), demote/promote, reinterpret, and float globals. Trapping truncation traps on NaN (new 'invalid conversion to integer' message) and on out-of-range values. Adds examples/float.wat (52 self-checks) and examples/fptrap.wat. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4c4fa91dc9
commit
f0d996cee9
7 files changed
+438
-44
No files matched your search
+12
-13
@@ -1,9 +1,9 @@
|
||||
///|
|
||||
fn expect_int(r : Reader) -> Unit raise CompileError {
|
||||
fn expect_num(r : Reader) -> Unit raise CompileError {
|
||||
let t = r.byte()
|
||||
if t != 0x7F && t != 0x7E {
|
||||
if t < 0x7C || t > 0x7F {
|
||||
raise CompileError(
|
||||
"only i32/i64 value types are supported (got 0x\{t.to_string(radix=16)})",
|
||||
"only numeric value types are supported (got 0x\{t.to_string(radix=16)})",
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ const MEM_BASE : Int32 = 0x10001000
|
||||
///|
|
||||
let messages : Array[String] = [
|
||||
"wasm trap: unreachable\n", "wasm trap: integer divide by zero\n", "wasm trap: integer overflow\n",
|
||||
"wasm trap: out of bounds memory access\n",
|
||||
"wasm trap: out of bounds memory access\n", "wasm trap: invalid conversion to integer\n",
|
||||
]
|
||||
|
||||
///|
|
||||
@@ -104,7 +104,7 @@ fn module_exports_prefix(m : Bytes, prefix : String) -> Bool raise CompileError
|
||||
}
|
||||
|
||||
///|
|
||||
/// Compile a WebAssembly core module (i32/i64 subset) or a component whose
|
||||
/// Compile a WebAssembly core module (i32/i64/f32/f64 subset) or a component whose
|
||||
/// core module targets `wasi:cli` to a static x86-64 Linux ELF executable.
|
||||
/// The entry export is called from `_start` and its i32 result becomes the
|
||||
/// process exit code.
|
||||
@@ -166,14 +166,14 @@ fn compile_core(wasm : Bytes, entry : String?) -> Bytes raise CompileError {
|
||||
}
|
||||
let np = r.u32()
|
||||
for _ in 0..<np {
|
||||
expect_int(r)
|
||||
expect_num(r)
|
||||
}
|
||||
let nr = r.u32()
|
||||
if nr > 1 {
|
||||
raise CompileError("multi-value results are not supported")
|
||||
}
|
||||
for _ in 0..<nr {
|
||||
expect_int(r)
|
||||
expect_num(r)
|
||||
}
|
||||
types.push({ nparams: np, nresults: nr, })
|
||||
}
|
||||
@@ -209,15 +209,14 @@ fn compile_core(wasm : Bytes, entry : String?) -> Bytes raise CompileError {
|
||||
}
|
||||
6 =>
|
||||
for _ in 0..<r.u32() {
|
||||
expect_int(r)
|
||||
expect_num(r)
|
||||
ignore(r.byte()) // mutability
|
||||
match r.byte() {
|
||||
0x41 => globals.push(r.s32().to_int64())
|
||||
0x42 => globals.push(r.s64())
|
||||
_ =>
|
||||
raise CompileError(
|
||||
"global initializers must be i32.const or i64.const",
|
||||
)
|
||||
0x43 => globals.push(r.raw32().to_int64() & 0xFFFFFFFFL)
|
||||
0x44 => globals.push(r.raw64())
|
||||
_ => raise CompileError("global initializers must be a numeric const")
|
||||
}
|
||||
if r.byte() != 0x0B {
|
||||
raise CompileError("bad global initializer")
|
||||
@@ -315,7 +314,7 @@ fn compile_core(wasm : Bytes, entry : String?) -> Bytes raise CompileError {
|
||||
let mut nlocals = ft.nparams
|
||||
for _ in 0..<br.u32() {
|
||||
let count = br.u32()
|
||||
expect_int(br)
|
||||
expect_num(br)
|
||||
nlocals += count
|
||||
}
|
||||
fns.push(
|
||||
|
||||
Reference in new issue
Block a user