1 | ; $Id: truncf.asm 96203 2022-08-14 03:27:49Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT truncf - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2022 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 | ; The contents of this file may alternatively be used under the terms
|
---|
18 | ; of the Common Development and Distribution License Version 1.0
|
---|
19 | ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | ; VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | ; CDDL are applicable instead of those of the GPL.
|
---|
22 | ;
|
---|
23 | ; You may elect to license modified versions of this file under the
|
---|
24 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | ;
|
---|
26 |
|
---|
27 |
|
---|
28 | %define RT_ASM_WITH_SEH64
|
---|
29 | %include "iprt/asmdefs.mac"
|
---|
30 | %include "iprt/x86.mac"
|
---|
31 |
|
---|
32 |
|
---|
33 | BEGINCODE
|
---|
34 |
|
---|
35 | ;;
|
---|
36 | ; Round to truncated integer value.
|
---|
37 | ; @returns 32-bit: st(0) 64-bit: xmm0
|
---|
38 | ; @param rf 32-bit: [ebp + 8] 64-bit: xmm0
|
---|
39 | RT_NOCRT_BEGINPROC truncf
|
---|
40 | push xBP
|
---|
41 | SEH64_PUSH_xBP
|
---|
42 | mov xBP, xSP
|
---|
43 | SEH64_SET_FRAME_xBP 0
|
---|
44 | sub xSP, 10h
|
---|
45 | SEH64_ALLOCATE_STACK 10h
|
---|
46 | SEH64_END_PROLOGUE
|
---|
47 |
|
---|
48 | ;
|
---|
49 | ; Load the value into st(0). This messes up SNaN values.
|
---|
50 | ;
|
---|
51 | %ifdef RT_ARCH_AMD64
|
---|
52 | movss [xSP], xmm0
|
---|
53 | fld dword [xSP]
|
---|
54 | %else
|
---|
55 | fld dword [xBP + xCB*2]
|
---|
56 | %endif
|
---|
57 |
|
---|
58 | ;
|
---|
59 | ; Return immediately if NaN or infinity.
|
---|
60 | ;
|
---|
61 | fxam
|
---|
62 | fstsw ax
|
---|
63 | test ax, X86_FSW_C0 ; C0 is set for NaN, Infinity and Empty register. The latter is not the case.
|
---|
64 | jz .input_ok
|
---|
65 | %ifdef RT_ARCH_AMD64
|
---|
66 | ffreep st0 ; return the xmm0 register value unchanged, as FLD changes SNaN to QNaN.
|
---|
67 | %endif
|
---|
68 | jmp .return_val
|
---|
69 | .input_ok:
|
---|
70 |
|
---|
71 | ;
|
---|
72 | ; Make it truncate up by modifying the fpu control word.
|
---|
73 | ;
|
---|
74 | fstcw [xBP - 10h]
|
---|
75 | mov eax, [xBP - 10h]
|
---|
76 | or eax, X86_FCW_RC_ZERO ; both bits set, so no need to clear anything first.
|
---|
77 | mov [xBP - 08h], eax
|
---|
78 | fldcw [xBP - 08h]
|
---|
79 |
|
---|
80 | ;
|
---|
81 | ; Round ST(0) to integer.
|
---|
82 | ;
|
---|
83 | frndint
|
---|
84 |
|
---|
85 | ;
|
---|
86 | ; Restore the fpu control word and return.
|
---|
87 | ;
|
---|
88 | fldcw [xBP - 10h]
|
---|
89 |
|
---|
90 | %ifdef RT_ARCH_AMD64
|
---|
91 | fstp dword [xSP]
|
---|
92 | movss xmm0, [xSP]
|
---|
93 | %endif
|
---|
94 | .return_val:
|
---|
95 | leave
|
---|
96 | ret
|
---|
97 | ENDPROC RT_NOCRT(truncf)
|
---|
98 |
|
---|