-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathround32.asm
41 lines (33 loc) · 1.2 KB
/
round32.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
; ROUND32.ASM
; Author: Agner Fog
; Date created: 2003
; Last modified: 2008-10-16
; Description:
; Round function
; Copyright (c) 2009 GNU General Public License www.gnu.org/licenses
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
global _RoundD: function
global _RoundF: function
SECTION .text align=16
; ********** round function **********
; C++ prototype:
; extern "C" int RoundD (double x);
; extern "C" int RoundF (float x);
; This function converts a single or double precision floating point number
; to an integer, rounding to nearest or even. Does not check for overflow.
; This function is much faster than the default conversion method in C++
; which uses truncation.
_RoundD:
fld qword [esp+4] ; Load x
push eax ; Make temporary space on stack
fistp dword [esp] ; Round. Store in temporary stack space
pop eax ; Read from temporary stack space
ret
;_RoundD ENDP
_RoundF:
fld dword [esp+4]
push eax
fistp dword [esp]
pop eax
ret
;_RoundF ENDP