You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JIT: Accelerate floating->long casts on x86 (#125180)
This adds floating->long/ulong cast codegen for AVX-512 and AVX10.2 on
x86. With this, all non-overflow casts are now hardware accelerated.
This is the last bit pulled from #116805.
Typical Diff (double->long AVX-512):
```diff
- sub esp, 8
- vzeroupper
- vmovsd xmm0, qword ptr [esp+0x0C]
- sub esp, 8
- ; npt arg push 0
- ; npt arg push 1
- vmovsd qword ptr [esp], xmm0
- call CORINFO_HELP_DBL2LNG
- ; gcr arg pop 2
+ vmovsd xmm0, qword ptr [esp+0x04]
+ vcmpordsd k1, xmm0, xmm0
+ vcmpge_oqsd k2, xmm0, qword ptr [@rwd00]
+ vcvttpd2qq xmm0 {k1}{z}, xmm0
+ vpblendmq xmm0 {k2}, xmm0, qword ptr [@RWD08] {1to2}
+ vmovd eax, xmm0
+ vpextrd edx, xmm0, 1
- add esp, 8
ret 8
+RWD00 dq 43E0000000000000h
+RWD08 dq 7FFFFFFFFFFFFFFFh
-; Total bytes of code 31
+; Total bytes of code 53
```
Full
[Diffs](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1391699&view=ms.vss-build-web.run-extensions-tab)
Breakdown of the double->long asm:
```asm
; load the scalar double
vmovsd xmm0, qword ptr [esp+0x04]
; set the low bit of k1 if the scalar value is not NaN
vcmpordsd k1, xmm0, xmm0
; set the low bit of k2 if the input was greater than or equal to 2^63 (nearest double greater than long.MaxValue)
vcmpge_oqsd k2, xmm0, qword ptr [@rwd00]
; convert, using k1 mask bit. if the mask bit is not set (meaning we have a NaN), set the value to zero
vcvttpd2qq xmm0 {k1}{z}, xmm0
; if the low bit of k2 is set (meaning overflow), set the value to long.MaxValue, otherwise take the conversion result
vpblendmq xmm0 {k2}, xmm0, qword ptr [@RWD08] {1to2}
; extract the two 32-bit halves of the long result
vmovd eax, xmm0
vpextrd edx, xmm0, 1
```
---------
Co-authored-by: Tanner Gooding <tagoo@microsoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
0 commit comments