[96201] | 1 | ; $Id: fesetround.asm 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
| 2 | ;; @file
|
---|
| 3 | ; IPRT - No-CRT fesetround - AMD64 & X86.
|
---|
| 4 | ;
|
---|
| 5 |
|
---|
| 6 | ;
|
---|
[98103] | 7 | ; Copyright (C) 2022-2023 Oracle and/or its affiliates.
|
---|
[96201] | 8 | ;
|
---|
[96407] | 9 | ; This file is part of VirtualBox base platform packages, as
|
---|
| 10 | ; available from https://www.virtualbox.org.
|
---|
[96201] | 11 | ;
|
---|
[96407] | 12 | ; This program is free software; you can redistribute it and/or
|
---|
| 13 | ; modify it under the terms of the GNU General Public License
|
---|
| 14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | ; License.
|
---|
| 16 | ;
|
---|
| 17 | ; This program is distributed in the hope that it will be useful, but
|
---|
| 18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | ; General Public License for more details.
|
---|
| 21 | ;
|
---|
| 22 | ; You should have received a copy of the GNU General Public License
|
---|
| 23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | ;
|
---|
[96201] | 25 | ; The contents of this file may alternatively be used under the terms
|
---|
| 26 | ; of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
[96201] | 29 | ; CDDL are applicable instead of those of the GPL.
|
---|
| 30 | ;
|
---|
| 31 | ; You may elect to license modified versions of this file under the
|
---|
| 32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
| 33 | ;
|
---|
[96407] | 34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
| 35 | ;
|
---|
[96201] | 36 |
|
---|
| 37 |
|
---|
| 38 | %define RT_ASM_WITH_SEH64
|
---|
| 39 | %include "iprt/asmdefs.mac"
|
---|
| 40 | %include "iprt/x86.mac"
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | BEGINCODE
|
---|
| 44 |
|
---|
| 45 | ;;
|
---|
[96205] | 46 | ; Sets the hardware rounding mode.
|
---|
[96201] | 47 | ;
|
---|
[96205] | 48 | ; @returns eax = 0 on success, non-zero on failure.
|
---|
| 49 | ; @param iRoundingMode 32-bit: [xBP+8] msc64: ecx gcc64: edi
|
---|
| 50 | ;
|
---|
[96201] | 51 | RT_NOCRT_BEGINPROC fesetround
|
---|
| 52 | push xBP
|
---|
| 53 | SEH64_PUSH_xBP
|
---|
| 54 | mov xBP, xSP
|
---|
| 55 | SEH64_SET_FRAME_xBP 0
|
---|
| 56 | sub xSP, 10h
|
---|
| 57 | SEH64_ALLOCATE_STACK 10h
|
---|
| 58 | SEH64_END_PROLOGUE
|
---|
| 59 |
|
---|
| 60 | ;
|
---|
| 61 | ; Load the parameter into ecx.
|
---|
| 62 | ;
|
---|
| 63 | or eax, -1
|
---|
| 64 | %ifdef ASM_CALL64_GCC
|
---|
| 65 | mov ecx, edi
|
---|
| 66 | %elifdef RT_ARCH_X86
|
---|
| 67 | mov ecx, [xBP + xCB*2]
|
---|
| 68 | %endif
|
---|
| 69 | test ecx, ~X86_FCW_RC_MASK
|
---|
| 70 | jnz .return
|
---|
| 71 |
|
---|
| 72 | ;
|
---|
| 73 | ; Make the changes.
|
---|
| 74 | ;
|
---|
| 75 |
|
---|
| 76 | ; Set x87 rounding first (ecx preserved).
|
---|
| 77 | fstcw [xBP - 10h]
|
---|
| 78 | mov ax, word [xBP - 10h]
|
---|
| 79 | and ax, ~X86_FCW_RC_MASK
|
---|
| 80 | or ax, cx
|
---|
| 81 | mov [xBP - 10h], ax
|
---|
| 82 | fldcw [xBP - 10h]
|
---|
| 83 |
|
---|
| 84 | %ifdef RT_ARCH_X86
|
---|
| 85 | ; SSE supported (ecx preserved)?
|
---|
| 86 | extern NAME(rtNoCrtHasSse)
|
---|
| 87 | call NAME(rtNoCrtHasSse)
|
---|
| 88 | test al, al
|
---|
| 89 | jz .return_ok
|
---|
| 90 | %endif
|
---|
| 91 |
|
---|
| 92 | ; Set SSE rounding (modifies ecx).
|
---|
| 93 | stmxcsr [xBP - 10h]
|
---|
| 94 | mov eax, [xBP - 10h]
|
---|
| 95 | and eax, ~X86_MXCSR_RC_MASK
|
---|
| 96 | shl ecx, X86_MXCSR_RC_SHIFT - X86_FCW_RC_SHIFT
|
---|
| 97 | or eax, ecx
|
---|
| 98 | mov [xBP - 10h], eax
|
---|
| 99 | ldmxcsr [xBP - 10h]
|
---|
| 100 |
|
---|
| 101 | .return_ok:
|
---|
| 102 | xor eax, eax
|
---|
| 103 | .return:
|
---|
| 104 | leave
|
---|
| 105 | ret
|
---|
| 106 | ENDPROC RT_NOCRT(fesetround)
|
---|
| 107 |
|
---|