From de116dceae7ea654df28caab3fd2f3aefdffe188 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 6 Apr 2025 02:19:44 +0900 Subject: fix: pass FloatMemoryTest --- BUGS | 4 ---- TODO | 1 - phpunit.xml | 1 + src/WebAssembly/Execution/MemInst.php | 29 +++++++---------------------- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/BUGS b/BUGS index 042151c..3e88d14 100644 --- a/BUGS +++ b/BUGS @@ -1,9 +1,5 @@ # Failed spec tests -## Numeric - -* FloatMemoryTest - ## Validation * ImportsTest diff --git a/TODO b/TODO index a361e26..171eb28 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ * Support text format (.wat) * Implement validation * Fix known bugs (BUGS) -* Implement NaN propagation * Provide sane bindings to PHP * Write PHPDoc for public APIs * Provide high-level APIs diff --git a/phpunit.xml b/phpunit.xml index 02e668c..a6c6ac1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -42,6 +42,7 @@ tests/src/SpecTestsuites/Core/FacTest.php tests/src/SpecTestsuites/Core/FloatExprsTest.php tests/src/SpecTestsuites/Core/FloatLiteralsTest.php + tests/src/SpecTestsuites/Core/FloatMemoryTest.php tests/src/SpecTestsuites/Core/FloatMiscTest.php tests/src/SpecTestsuites/Core/ForwardTest.php tests/src/SpecTestsuites/Core/FuncPtrsTest.php diff --git a/src/WebAssembly/Execution/MemInst.php b/src/WebAssembly/Execution/MemInst.php index 94d57cf..9ced0a3 100644 --- a/src/WebAssembly/Execution/MemInst.php +++ b/src/WebAssembly/Execution/MemInst.php @@ -44,11 +44,6 @@ final class MemInst private CData $dataS64_6; private CData $dataS64_7; - private CData $dataF32_0; - private CData $dataF32_1; - private CData $dataF32_2; - private CData $dataF32_3; - private CData $dataF64_0; private CData $dataF64_1; private CData $dataF64_2; @@ -155,11 +150,6 @@ final class MemInst $this->dataS64_6 = $castInt(64, true, 6); $this->dataS64_7 = $castInt(64, true, 7); - $this->dataF32_0 = $castFloat(32, 0); - $this->dataF32_1 = $castFloat(32, 1); - $this->dataF32_2 = $castFloat(32, 2); - $this->dataF32_3 = $castFloat(32, 3); - $this->dataF64_0 = $castFloat(64, 0); $this->dataF64_1 = $castFloat(64, 1); $this->dataF64_2 = $castFloat(64, 2); @@ -380,7 +370,10 @@ final class MemInst if ($this->size() < $ptr + 4) { return null; } - return $this->dataF32($ptr)[$ptr >> 2]; + // f32 cannot be loaded directly from memory because PHP handles NaN + // differently than WebAssembly spec defines. + $i = $this->dataU32($ptr)[$ptr >> 2]; + return NumericOps::f32ReinterpretI32($i); } /** @@ -517,7 +510,9 @@ final class MemInst if ($this->size() < $ptr + 4) { return false; } - $this->dataF32($ptr)[$ptr >> 2] = $c; + // f32 cannot be stored directly in memory because PHP handles NaN + // differently than WebAssembly spec defines. + $this->dataU32($ptr)[$ptr >> 2] = NumericOps::i32ReinterpretF32($c); return true; } @@ -578,16 +573,6 @@ final class MemInst }; } - private function dataF32(int $ptr): CData - { - return match ($ptr & 3) { - 0 => $this->dataF32_0, - 1 => $this->dataF32_1, - 2 => $this->dataF32_2, - 3 => $this->dataF32_3, - }; - } - private function dataF64(int $ptr): CData { return match ($ptr & 7) { -- cgit v1.2.3-70-g09d2