round64.asm 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. %include "defs.asm"
  2. ; ROUND64.ASM
  3. ; Author: Agner Fog
  4. ; Date created: 2007-06-15
  5. ; Last modified: 2008-10-16
  6. ; Description:
  7. ; Round function
  8. ; Copyright (c) 2009 GNU General Public License www.gnu.org/licenses
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10. default rel
  11. global RoundD: function
  12. global RoundF: function
  13. SECTION .text align=16
  14. ; ********** round function **********
  15. ; C++ prototype:
  16. ; extern "C" int RoundD (double x);
  17. ; extern "C" int RoundF (float x);
  18. ; This function converts a single or double precision floating point number
  19. ; to an integer, rounding to nearest or even. Does not check for overflow.
  20. ; This function is much faster than the default conversion method in C++
  21. ; which uses truncation.
  22. RoundD:
  23. cvtsd2si eax, xmm0 ; Round xmm0 to eax
  24. ret
  25. ;RoundD ENDP
  26. RoundF:
  27. cvtss2si eax, xmm0 ; Round xmm0 to eax
  28. ret
  29. ;RoundF ENDP