Skip to content

Instantly share code, notes, and snippets.

@dfyz
Last active September 11, 2022 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfyz/52c7a0735840576829587aefd63d59ba to your computer and use it in GitHub Desktop.
Save dfyz/52c7a0735840576829587aefd63d59ba to your computer and use it in GitHub Desktop.
We have FJCVTZS at home
.global _d2i
.align 4
_d2i:
fcvtzs x0, d0
ret
.intel_syntax noprefix
.global d2i
d2i:
cvttsd2si rax, xmm0
ret
> gcc -O2 -o ./cvt cvt.c cvt_x86_cheat.s -lm && ./cvt
-1.000000 -1
-133.700000 -133
-17875.690000 -17875
-2389979.753000 -2389979
-319540292.976100 -319540292
-42722537170.904549 227135790
-5712003219749.938477 303283931
-763694830480566.625000 1894355786
1.000000 1
133.700000 133
17875.690000 17875
2389979.753000 2389979
319540292.976100 319540292
42722537170.904549 -227135790
5712003219749.938477 -303283931
763694830480566.625000 -1894355786
> gcc -O2 -o ./cvt cvt.c cvt_aarch64_cheat.s && ./cvt
-1.000000 -1
-133.700000 -133
-17875.690000 -17875
-2389979.753000 -2389979
-319540292.976100 -319540292
-42722537170.904549 227135790
-5712003219749.938477 303283931
-763694830480566.625000 1894355786
1.000000 1
133.700000 133
17875.690000 17875
2389979.753000 2389979
319540292.976100 319540292
42722537170.904549 -227135790
5712003219749.938477 -303283931
763694830480566.625000 -1894355786
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment