Commit a0476fd
authored
Micro-optimize double comparison (#11061)
When using ZEND_NORMALIZE_BOOL(a - b) where a and b are doubles, this
generates the following instruction sequence on x64:
subsd xmm0, xmm1
pxor xmm1, xmm1
comisd xmm0, xmm1
...
whereas if we use ZEND_THREEWAY_COMPARE we get two instructions less:
ucomisd xmm0, xmm1
The only difference is that the threeway compare uses *u*comisd instead
of comisd. The difference is that it will cause a FP signal if a
signaling NAN is used, but as far as I'm aware this doesn't matter for
our use case.
Similarly, the amount of instructions on AArch64 is also quite a bit
lower for this code compared to the old code.
** Results **
Using the benchmark https://gist.github.com/nielsdos/b36517d81a1af74d96baa3576c2b70df
I used hyperfine: hyperfine --runs 25 --warmup 3 './sapi/cli/php sort_double.php'
No extensions such as opcache used during benchmarking.
BEFORE THIS PATCH
-----------------
Time (mean ± σ): 255.5 ms ± 2.2 ms [User: 251.0 ms, System: 2.5 ms]
Range (min … max): 251.5 ms … 260.7 ms 25 runs
AFTER THIS PATCH
----------------
Time (mean ± σ): 236.2 ms ± 2.8 ms [User: 228.9 ms, System: 5.0 ms]
Range (min … max): 231.5 ms … 242.7 ms 25 runs1 parent 8d5e06d commit a0476fd
3 files changed
+9
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2109 | 2109 | | |
2110 | 2110 | | |
2111 | 2111 | | |
2112 | | - | |
| 2112 | + | |
2113 | 2113 | | |
2114 | 2114 | | |
2115 | 2115 | | |
| |||
2131 | 2131 | | |
2132 | 2132 | | |
2133 | 2133 | | |
2134 | | - | |
2135 | | - | |
| 2134 | + | |
2136 | 2135 | | |
2137 | 2136 | | |
2138 | 2137 | | |
| |||
2150 | 2149 | | |
2151 | 2150 | | |
2152 | 2151 | | |
2153 | | - | |
2154 | | - | |
| 2152 | + | |
2155 | 2153 | | |
2156 | 2154 | | |
2157 | 2155 | | |
2158 | | - | |
2159 | | - | |
2160 | | - | |
2161 | | - | |
| 2156 | + | |
2162 | 2157 | | |
2163 | 2158 | | |
2164 | 2159 | | |
| |||
2180 | 2175 | | |
2181 | 2176 | | |
2182 | 2177 | | |
2183 | | - | |
| 2178 | + | |
2184 | 2179 | | |
2185 | 2180 | | |
2186 | | - | |
| 2181 | + | |
2187 | 2182 | | |
2188 | 2183 | | |
2189 | | - | |
2190 | | - | |
2191 | | - | |
2192 | | - | |
2193 | | - | |
| 2184 | + | |
2194 | 2185 | | |
2195 | 2186 | | |
2196 | 2187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
| 250 | + | |
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
0 commit comments