diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-04-07 00:26:55 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-04-07 01:52:27 +0900 |
| commit | 28b496687c0eb36a035a8686794fa45434957e28 (patch) | |
| tree | f660f257eb72a040f693882a502adb1416e42257 /src/WebAssembly | |
| parent | 7bc9e73c59e6ec7e4f9feef785e08dc56fbb09eb (diff) | |
| download | php-waddiwasi-28b496687c0eb36a035a8686794fa45434957e28.tar.gz php-waddiwasi-28b496687c0eb36a035a8686794fa45434957e28.tar.zst php-waddiwasi-28b496687c0eb36a035a8686794fa45434957e28.zip | |
feat: do not use FFI to cast integers to f32
Diffstat (limited to 'src/WebAssembly')
| -rw-r--r-- | src/WebAssembly/Execution/NumericOps.php | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/src/WebAssembly/Execution/NumericOps.php b/src/WebAssembly/Execution/NumericOps.php index f7a1e89..7d5e57c 100644 --- a/src/WebAssembly/Execution/NumericOps.php +++ b/src/WebAssembly/Execution/NumericOps.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Nsfisis\Waddiwasi\WebAssembly\Execution; -use FFI; use Nsfisis\Waddiwasi\BitOps\BinaryConversion; use Nsfisis\Waddiwasi\BitOps\FloatOps; use RoundingMode; @@ -70,13 +69,13 @@ final readonly class NumericOps public static function f32ConvertI64S(int $x): float { - return self::castBigIntToF32((string)$x); + return BinaryConversion::convertBigIntToF32((string)$x); } public static function f32ConvertI64U(int $x): float { $x = self::convertS64ToBigUInt($x); - return self::castBigIntToF32($x); + return BinaryConversion::convertBigIntToF32($x); } public static function f32CopySign(float $x, float $y): float @@ -1165,6 +1164,9 @@ final readonly class NumericOps } } + /** + * @return numeric-string + */ public static function convertS64ToBigUInt(int $x): string { if ($x < 0) { @@ -1190,22 +1192,4 @@ final readonly class NumericOps } return (int)$result; } - - - private static function castBigIntToF32(string $x): float - { - // @phpstan-ignore-next-line - return self::ffi()->strtof($x, null); - } - - private static function ffi(): FFI - { - static $ffi; - if (!$ffi) { - $ffi = FFI::cdef( - 'float strtof(const char *restrict nptr, char **restrict endptr);', - ); - } - return $ffi; - } } |
