Repository navigation
Conversation
marc-mabe
force-pushed
the
fpmath_sse
branch
from
November 11, 2026 08:01
940af07 to
5f03040
Compare
SSE2 is part of the x86-64 baseline, but optional on 32-bit x86, where
GCC targets i686 by default. Such builds miss the __SSE2__ code paths and
compute doubles on the x87 unit.
x87 registers have a 15-bit exponent that zend_init_fpu() cannot clamp,
so subnormal results are rounded twice and can be one ULP off:
$a = 5.678650331314532e-158;
$b = 2.3715405351663569e-153;
var_dump($a * $b);
// x87: 1.34671494457485E-310
// SSE2 and 64-bit: 1.3467149445748E-310 (correctly rounded)
The new PHP_CHECK_SSE2 macro in build/php.m4, called from the
platform-specific compile settings in configure.ac, prepends to CFLAGS
and CXXFLAGS on x86 targets:
- -msse2 if supported and not enabled by default;
- -mfpmath=sse if SSE2 is enabled and doubles do not use it by default.
Clang does this by itself; GCC needs the flag.
Configure warns but builds without SSE2 if the build machine cannot run
SSE2 code. When cross compiling, -msse2 is added without that check.
The resulting build requires SSE2. Pass CFLAGS=-mno-sse2 to build without
SSE2.
phpize builds do not call the macro, but an extension can call
PHP_CHECK_SSE2 from its config.m4.
marc-mabe
force-pushed
the
fpmath_sse
branch
from
November 11, 2026 08:05
5f03040 to
186309e
Compare
Sjord
reviewed
Nov 11, 2026
Sjord
left a comment
Contributor
There was a problem hiding this comment.
Mailing list post: https://news-web.php.net/php.internals/133038
Perhaps this also needs a NEWS entry.
| @@ -0,0 +1,25 @@ | |||
| --TEST-- | |||
| Float multiplication and division with subnormal results are correctly rounded | |||
| --DESCRIPTION-- | |||
Contributor
There was a problem hiding this comment.
Does this test needs a skip guard if someone builds with CFLAGS=-mno-sse2?
Contributor
Author
There was a problem hiding this comment.
The test is designed like others ( e.g. gh14140.phpt does for -ffp-contract=off). If you build with -mno-sse2, failing this test is the expected result, and there’s no way to detect it from a phpt without adding test-only API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SSE2 is part of the x86-64 baseline, but optional on 32-bit x86, where GCC targets i686 by default. Such builds miss the SSE2 code paths and compute doubles on the x87 unit.
x87 registers have a 15-bit exponent that zend_init_fpu() cannot clamp, so subnormal results are rounded twice and can be one ULP off:
The new PHP_CHECK_SSE2 macro in build/php.m4, called from the platform-specific compile settings in configure.ac, prepends to CFLAGS and CXXFLAGS on x86 targets:
Configure warns but builds without SSE2 if the build machine cannot run SSE2 code. When cross compiling, -msse2 is added without that check.
The resulting build requires SSE2. Pass CFLAGS=-mno-sse2 to build without SSE2.
phpize builds do not call the macro, but an extension can call PHP_CHECK_SSE2 from its config.m4.