From 7cec89f22a9a09916f1b9c98fc117ec4a1ea7793 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 19 May 2024 11:53:12 +0900 Subject: fix: iNN.reinterpret_fMM --- src/Execution/Runtime.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php index 9987118..8944ff1 100644 --- a/src/Execution/Runtime.php +++ b/src/Execution/Runtime.php @@ -1093,13 +1093,19 @@ final class Runtime private function execInstrNumericI32ReinterpretF32(Instrs\Numeric\I32ReinterpretF32 $instr): void { $v = $this->stack->popFloat(); - $this->stack->pushValue($v); + $result = unpack('l', pack('f', $v)); + assert($result !== false); + $vAsI32 = $result[1]; + $this->stack->pushValue($vAsI32); } private function execInstrNumericI32ReinterpretF64(Instrs\Numeric\I32ReinterpretF64 $instr): void { $v = $this->stack->popFloat(); - $this->stack->pushValue($v); + $result = unpack('q', pack('d', $v)); + assert($result !== false); + $vAsI64 = $result[1]; + $this->stack->pushValue(self::phpIntToWasmI32($vAsI64 & 0xFFFFFFFF)); } private function execInstrNumericI32RemS(Instrs\Numeric\I32RemS $instr): void @@ -1505,13 +1511,19 @@ final class Runtime private function execInstrNumericI64ReinterpretF32(Instrs\Numeric\I64ReinterpretF32 $instr): void { $v = $this->stack->popFloat(); - $this->stack->pushValue($v); + $result = unpack('q', pack('f', $v)); + assert($result !== false); + $vAsI64 = $result[1]; + $this->stack->pushValue($vAsI64); } private function execInstrNumericI64ReinterpretF64(Instrs\Numeric\I64ReinterpretF64 $instr): void { $v = $this->stack->popFloat(); - $this->stack->pushValue($v); + $result = unpack('q', pack('d', $v)); + assert($result !== false); + $vAsI64 = $result[1]; + $this->stack->pushValue($vAsI64); } private function execInstrNumericI64RemS(Instrs\Numeric\I64RemS $instr): void -- cgit v1.2.3-70-g09d2