VirtualBox

Ignore:
Timestamp:
Aug 17, 2022 1:59:06 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
153054
Message:

IPRT/nocrt: Adapted the reworked sin and cos code for sinf and cosf; fixed a few cos bugs and added tests for cos. bugref:10261

Location:
trunk/src/VBox/Runtime/common/math
Files:
2 edited
2 copied

Legend:

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

    r96240 r96242  
    110110        fld     qword [.s_r64TinyCosTo1 xWrtRIP]
    111111        fcomip  st1
    112         jbe      .zero_extra_pop
     112        ja      .zero_extra_pop
    113113
    114114.not_that_tiny_input:
  • trunk/src/VBox/Runtime/common/math/cosf.asm

    r96240 r96242  
    11; $Id$
    22;; @file
    3 ; IPRT - No-CRT cos - AMD64 & X86.
     3; IPRT - No-CRT cosf - AMD64 & X86.
    44;
    55
     
    3434
    3535;;
    36 ; Compute the cosine of rd, measured in radians.
     36; Compute the cosine of rf, measured in radians.
    3737;
    3838; @returns  st(0) / xmm0
    39 ; @param    rd      [rbp + xCB*2] / xmm0
    40 ;
    41 RT_NOCRT_BEGINPROC cos
     39; @param    rf      [rbp + xCB*2] / xmm0
     40;
     41RT_NOCRT_BEGINPROC cosf
    4242        push    xBP
    4343        SEH64_PUSH_xBP
     
    6464        ;
    6565%ifdef RT_ARCH_AMD64
    66         movsd   [xBP - 10h], xmm0
    67         fld     qword [xBP - 10h]
     66        movss   [xBP - 10h], xmm0
     67        fld     dword [xBP - 10h]
    6868%else
    69         fld     qword [xBP + xCB*2]
     69        fld     dword [xBP + xCB*2]
    7070%endif
    7171
     
    7474        ; works reliably, so outside that we'll use the FSIN instruction instead
    7575        ; as it has a larger good range (-5pi/4 to 1pi/4 for cosine).
    76         ; Input conversion follows: cos(x) = sin(x + pi/2)
     76        ; Input conversion follows: cosf(x) = sinf(x + pi/2)
    7777        ;
    7878        ; We examin the input and weed out non-finit numbers first.
     
    110110        fld     qword [.s_r64TinyCosTo1 xWrtRIP]
    111111        fcomip  st1
    112         jbe      .zero_extra_pop
     112        ja      .zero_extra_pop
    113113
    114114.not_that_tiny_input:
     
    147147        ;
    148148.do_sine:
    149         mov     ecx, 1                      ; double
     149        mov     ecx, 0                      ; double
    150150        extern  NAME(rtNoCrtMathSinCore)
    151151        call    NAME(rtNoCrtMathSinCore)
     
    156156.return_val:
    157157%ifdef RT_ARCH_AMD64
    158         fstp    qword [xBP - 10h]
    159         movsd   xmm0, [xBP - 10h]
     158        fstp    dword [xBP - 10h]
     159        movss   xmm0, [xBP - 10h]
    160160%endif
    161161%ifdef RT_OS_WINDOWS
     
    167167
    168168        ;
    169         ; cos(+/-0) = +1.0
     169        ; cosf(+/-0) = +1.0
    170170        ;
    171171.zero_extra_pop:
     
    190190        ;
    191191ALIGNCODE(8)
    192         ; About 2**-27. When fabs(input) is below this limit we can consider cos(input) ~= 1.0.
     192        ; About 2**-18. When fabs(input) is below this limit we can consider cosf(input) ~= 1.0.
    193193.s_r64TinyCosTo1:
    194         dq  7.4505806e-9
     194        dq  0.000244140625
    195195
    196196        ; The absolute limit for the range which FCOS is expected to produce reasonable results.
     
    200200.s_r64Two:
    201201        dq  2.0
    202 ENDPROC   RT_NOCRT(cos)
    203 
     202ENDPROC   RT_NOCRT(cosf)
     203
  • trunk/src/VBox/Runtime/common/math/sin.asm

    r96241 r96242  
    3535
    3636;;
    37 ; Compute the sine of rd, measured in radians.
     37; Compute the sine of rf, measured in radians.
    3838;
    3939; @returns  st(0) / xmm0
    40 ; @param    rd      [rbp + xCB*2] / xmm0
     40; @param    rf      [rbp + xCB*2] / xmm0
    4141;
    4242RT_NOCRT_BEGINPROC sin
     
    160160
    161161ALIGNCODE(8)
    162         ; Ca. 2**-26, absolute value. Inputs closer to zero than this can be
     162        ; Ca. 2**-17, absolute value. Inputs closer to zero than this can be
    163163        ; returns directly as the sin(input) value should be basically the same
    164164        ; given the precision we're working with and FSIN probably won't even
     
    166166        ;; @todo experiment when FSIN gets better than this.
    167167.s_r64Tiny:
    168         dq      1.49011612e-8
     168        dq      0.00000762939453125
    169169        ; The absolute limit of FSIN "good" range.
    170170.s_r64FSinOkay:
  • trunk/src/VBox/Runtime/common/math/sinf.asm

    r96241 r96242  
    11; $Id$
    22;; @file
    3 ; IPRT - No-CRT sin - AMD64 & X86.
     3; IPRT - No-CRT sinf - AMD64 & X86.
    44;
    55
     
    4040; @param    rd      [rbp + xCB*2] / xmm0
    4141;
    42 RT_NOCRT_BEGINPROC sin
     42RT_NOCRT_BEGINPROC sinf
    4343        push    xBP
    4444        SEH64_PUSH_xBP
     
    6464        ;
    6565%ifdef RT_ARCH_AMD64
    66         movsd   [xBP - 10h], xmm0
    67         fld     qword [xBP - 10h]
     66        movss   [xBP - 10h], xmm0
     67        fld     dword [xBP - 10h]
    6868%else
    69         fld     qword [xBP + xCB*2]
     69        fld     dword [xBP + xCB*2]
    7070%endif
    7171
     
    115115        ; Call common sine/cos worker.
    116116        ;
    117         mov     ecx, 1                      ; double
     117        mov     ecx, 0                      ; float
    118118        extern  NAME(rtNoCrtMathSinCore)
    119119        call    NAME(rtNoCrtMathSinCore)
     
    124124.return_val:
    125125%ifdef RT_ARCH_AMD64
    126         fstp    qword [xBP - 10h]
    127         movsd   xmm0, [xBP - 10h]
     126        fstp    dword [xBP - 10h]
     127        movss   xmm0, [xBP - 10h]
    128128%endif
    129129%ifdef RT_OS_WINDOWS
     
    136136        ;
    137137        ; As explained already, we can return tiny numbers directly too as the
    138         ; output from sin(input) = input given our precision.
     138        ; output from sinf(input) = input given our precision.
    139139        ; We can skip the st0 -> xmm0 translation here, so follow the same path
    140140        ; as .zero & .nan, after we've removed the fabs(input) value.
     
    144144
    145145        ;
    146         ; sin(+/-0.0) = +/-0.0 (preserve the sign)
     146        ; sinf(+/-0.0) = +/-0.0 (preserve the sign)
    147147        ; We can skip the st0 -> xmm0 translation here, so follow the .nan code path.
    148148        ;
     
    161161ALIGNCODE(8)
    162162        ; Ca. 2**-26, absolute value. Inputs closer to zero than this can be
    163         ; returns directly as the sin(input) value should be basically the same
     163        ; returns directly as the sinf(input) value should be basically the same
    164164        ; given the precision we're working with and FSIN probably won't even
    165165        ; manage that.
     
    172172        ;dq      1.57079632679489661923  ; pi/2 - alternative.
    173173
    174 ENDPROC   RT_NOCRT(sin)
     174ENDPROC   RT_NOCRT(sinf)
    175175
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