VirtualBox

Ignore:
Timestamp:
Aug 14, 2022 3:27:49 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
153011
Message:

IPRT/nocrt: More test and fixes to rint, rintf, trunc, truncf and truncl. bugref:10261

Location:
trunk/src/VBox/Runtime/common/math
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/math/rint.asm

    r96117 r96203  
    2525;
    2626
     27
    2728%define RT_ASM_WITH_SEH64
    2829%include "iprt/asmdefs.mac"
     30%include "iprt/x86.mac"
     31
    2932
    3033BEGINCODE
     
    4851        SEH64_END_PROLOGUE
    4952
     53        ;
     54        ; Load the value into st(0).  This messes up SNaN values.
     55        ;
    5056%ifdef RT_ARCH_AMD64
    5157        movsd   qword [xSP], xmm0
    5258        fld     qword [xSP]
     59%else
     60        fld     qword [xBP + xCB*2]
     61%endif
     62
     63        ;
     64        ; Return immediately if NaN or infinity.
     65        ;
     66        fxam
     67        fstsw   ax
     68        test    ax, X86_FSW_C0          ; C0 is set for NaN, Infinity and Empty register. The latter is not the case.
     69        jz      .input_ok
     70%ifdef RT_ARCH_AMD64
     71        ffreep  st0                     ; return the xmm0 register value unchanged, as FLD changes SNaN to QNaN.
     72%endif
     73        jmp     .return
     74.input_ok:
     75
     76        ;
     77        ; Do the job and return.
     78        ;
    5379        frndint
     80
     81%ifdef RT_ARCH_AMD64
    5482        fstp    qword [xSP]
    5583        movsd   xmm0, qword [xSP]
    56 %else
    57         fld     qword [xBP + xCB*2]
    58         frndint
    5984%endif
    60 
     85.return:
    6186        leave
    6287        ret
  • trunk/src/VBox/Runtime/common/math/rintf.asm

    r96121 r96203  
    2525;
    2626
     27
    2728%define RT_ASM_WITH_SEH64
    2829%include "iprt/asmdefs.mac"
     30%include "iprt/x86.mac"
     31
    2932
    3033BEGINCODE
     
    4851        SEH64_END_PROLOGUE
    4952
     53        ;
     54        ; Load the value into st(0).  This messes up SNaN values.
     55        ;
    5056%ifdef RT_ARCH_AMD64
    5157        movss   dword [xSP], xmm0
    5258        fld     dword [xSP]
     59%else
     60        fld     dword [xBP + xCB*2]
     61%endif
     62
     63        ;
     64        ; Return immediately if NaN or infinity.
     65        ;
     66        fxam
     67        fstsw   ax
     68        test    ax, X86_FSW_C0          ; C0 is set for NaN, Infinity and Empty register. The latter is not the case.
     69        jz      .input_ok
     70%ifdef RT_ARCH_AMD64
     71        ffreep  st0                     ; return the xmm0 register value unchanged, as FLD changes SNaN to QNaN.
     72%endif
     73        jmp     .return
     74.input_ok:
     75
     76        ;
     77        ; Do the job and return.
     78        ;
    5379        frndint
     80
     81%ifdef RT_ARCH_AMD64
    5482        fstp    dword [xSP]
    5583        movss   xmm0, dword [xSP]
    56 %else
    57         fld     dword [xBP + xCB*2]
    58         frndint
    5984%endif
    60 
     85.return:
    6186        leave
    6287        ret
  • trunk/src/VBox/Runtime/common/math/trunc.asm

    r96014 r96203  
    2626
    2727
     28%define RT_ASM_WITH_SEH64
    2829%include "iprt/asmdefs.mac"
     30%include "iprt/x86.mac"
     31
    2932
    3033BEGINCODE
     
    3538; @param    rd      32-bit: [ebp + 8]   64-bit: xmm0
    3639RT_NOCRT_BEGINPROC trunc
    37     push    xBP
    38     mov     xBP, xSP
    39     sub     xSP, 10h
     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        movsd   [xSP], xmm0
     53        fld     qword [xSP]
     54%else
     55        fld     qword [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]
    4089
    4190%ifdef RT_ARCH_AMD64
    42     movsd   [xSP], xmm0
    43     fld     qword [xSP]
    44 %else
    45     fld     qword [xBP + xCB*2]
     91        fstp    qword [xSP]
     92        movsd   xmm0, [xSP]
    4693%endif
    47 
    48     ; Make it truncate up by modifying the fpu control word.
    49     fstcw   [xBP - 10h]
    50     mov     eax, [xBP - 10h]
    51     or      eax, 00c00h
    52     mov     [xBP - 08h], eax
    53     fldcw   [xBP - 08h]
    54 
    55     ; Round ST(0) to integer.
    56     frndint
    57 
    58     ; Restore the fpu control word.
    59     fldcw   [xBP - 10h]
    60 
    61 %ifdef RT_ARCH_AMD64
    62     fstp    qword [xSP]
    63     movsd   xmm0, [xSP]
    64 %endif
    65     leave
    66     ret
     94.return_val:
     95        leave
     96        ret
    6797ENDPROC   RT_NOCRT(trunc)
    6898
  • trunk/src/VBox/Runtime/common/math/truncf.asm

    r96014 r96203  
    2626
    2727
     28%define RT_ASM_WITH_SEH64
    2829%include "iprt/asmdefs.mac"
     30%include "iprt/x86.mac"
     31
    2932
    3033BEGINCODE
     
    3538; @param    rf      32-bit: [ebp + 8]   64-bit: xmm0
    3639RT_NOCRT_BEGINPROC truncf
    37     push    xBP
    38     mov     xBP, xSP
    39     sub     xSP, 10h
     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]
    4089
    4190%ifdef RT_ARCH_AMD64
    42     movss   [xSP], xmm0
    43     fld     dword [xSP]
    44 %else
    45     fld     dword [xBP + xCB*2]
     91        fstp    dword [xSP]
     92        movss   xmm0, [xSP]
    4693%endif
    47 
    48     ; Make it truncate up by modifying the fpu control word.
    49     fstcw   [xBP - 10h]
    50     mov     eax, [xBP - 10h]
    51     or      eax, 00c00h
    52     mov     [xBP - 08h], eax
    53     fldcw   [xBP - 08h]
    54 
    55     ; Round ST(0) to integer.
    56     frndint
    57 
    58     ; Restore the fpu control word.
    59     fldcw   [xBP - 10h]
    60 
    61 %ifdef RT_ARCH_AMD64
    62     fstp    dword [xSP]
    63     movss   xmm0, [xSP]
    64 %endif
    65     leave
    66     ret
     94.return_val:
     95        leave
     96        ret
    6797ENDPROC   RT_NOCRT(truncf)
    6898
  • trunk/src/VBox/Runtime/common/math/truncl.asm

    r96014 r96203  
    2626
    2727
     28%define RT_ASM_WITH_SEH64
    2829%include "iprt/asmdefs.mac"
     30%include "iprt/x86.mac"
     31
    2932
    3033BEGINCODE
     
    3336; Round to truncated integer value.
    3437; @returns st(0)
    35 ; @param    rd      [rbp + 8]
     38; @param    lrd     [rbp + 8]
    3639RT_NOCRT_BEGINPROC truncl
    37     push    xBP
    38     mov     xBP, xSP
    39     sub     xSP, 10h
     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
    4047
    41     fld     tword [xBP + xCB*2]
     48        fld     tword [xBP + xCB*2]
    4249
    43     ; Make it truncate up by modifying the fpu control word.
    44     fstcw   [xBP - 10h]
    45     mov     eax, [xBP - 10h]
    46     or      eax, 00c00h
    47     mov     [xBP - 08h], eax
    48     fldcw   [xBP - 08h]
     50        ; Make it truncate up by modifying the fpu control word.
     51        fstcw   [xBP - 10h]
     52        mov     eax, [xBP - 10h]
     53        or      eax, X86_FCW_RC_ZERO    ; both bits set, so no need to clear anything first.
     54        mov     [xBP - 08h], eax
     55        fldcw   [xBP - 08h]
    4956
    50     ; Round ST(0) to integer.
    51     frndint
     57        ; Round ST(0) to integer.
     58        frndint
    5259
    53     ; Restore the fpu control word.
    54     fldcw   [xBP - 10h]
     60        ; Restore the fpu control word.
     61        fldcw   [xBP - 10h]
    5562
    56     leave
    57     ret
     63        leave
     64        ret
    5865ENDPROC   RT_NOCRT(truncl)
    5966
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette