386trig.inc
来自「开放源码的编译器open watcom 1.6.0版的源代码」· INC 代码 · 共 426 行 · 第 1/2 页
INC
426 行
or CX,CX ; - if index > 0
_if ns ; - then
mov CX,0 ; - - set to 0
_endif ; - endif
neg CX ; - make positive
cmp CX,8 ; - if index > 8
_if g ; - then
mov CX,8 ; - - set to 8
_endif ; - endif
mov CX,Degree[ECX*2] ; - get degree
push ECX ; - save degree
;; /* only calculate the necessary polynomials */
;; if( ((i+1) & 2) || flag == 1 ) {
_guess ; - guess
mov EAX,iflag[EBP] ; - - get i and flag
inc AL ; - - + 1
and AL,2 ; - - & 2
_quif ne ; - - quit if ON
cmp AH,1 ; - - or flag == 1
_quif e ; - - ...
_admit ; - admit
;; cosy = _EvalPoly( y*y, &_cospoly[index], 8 - index );
push EAX ; - - save (i+1) & 2
mov EAX,[EDI] ; - - load y
mov EDX,4[EDI] ; - - ...
mov SI,8[EDI] ; - - ...
shl ESI,16 ; - - again
mov SI,8[EDI] ; - - ...
mov EBX,EAX ; - - ...
mov ECX,EDX ; - - ...
call ___LDM ; - - calc. y*y
mov ECX,index[EBP] ; - - get index
mov EBX,8 ; - - calc. 8 - index
sub EBX,ECX ; - - ...
lea ECX,[ECX+ECX*4] ; - - index * 5
lea ECX,__cospoly[ECX*2] ; - - index * 2, point to start of polynomial
call __poly ; - - evaluate polynomial
mov cosy[EBP],EAX ; - - save cosy
mov cosy+4[EBP],EDX ; - - ...
mov cosy+8[EBP],SI ; - - ...
;; }
pop EAX ; - - restore (i+1) & 2
_endguess ; - endguess
;; if( (((i+1) & 2) == 0) || flag == 1 ) {
_guess ; - guess
cmp AL,0 ; - - quit if (1+1) & 2 == 0
_quif e ; - - ...
cmp AH,1 ; - - or flag == 1
_quif e ; - - ...
_admit ; - admit
;; siny = _OddPoly( y, &_sinpoly[index], 8 - index );
mov EAX,EDI ; - - point to y
mov ECX,index[EBP] ; - - get index
mov EBX,8 ; - - calc. 8 - index
sub EBX,ECX ; - - ...
lea ECX,[ECX+ECX*4] ; - - index * 5
lea EDX,__sinpoly[ECX*2] ; - - index * 2, point to start of poly.
call __OddPoly ; - - evaluate polynomial
;; }
_endguess ; - endguess
;; }
__endif1:; _endif ; endif
;;#if 0
;; switch( i ) {
;; case 0: sinx = siny; cosx = cosy; break;
;; case 1: sinx = cosy; cosx = siny; break;
;; case 2: sinx = cosy; cosx = - siny; break;
;; case 3: sinx = siny; cosx = - cosy; break;
;; case 4: sinx = - siny; cosx = - cosy; break;
;; case 5: sinx = - cosy; cosx = - siny; break;
;; case 6: sinx = - cosy; cosx = siny; break;
;; case 7: sinx = - siny; cosx = cosy; break;
;; }
;;#endif
;; if( (i+1) & 2 ) { /* if octants 1,2,5,6 */
;; sinx = cosy;
;; } else { /* octants 0,3,4,7 */
;; sinx = siny;
;; }
mov EAX,iflag[EBP] ; get i and flag
inc AL ; + 1
and AL,2 ; & 2
_if ne ; if octants 1,2,5,6
mov EAX,cosy[EBP] ; - load cosy
mov EDX,cosy+4[EBP] ; - ...
mov SI,cosy+8[EBP] ; - ...
_else ; else octants 0,3,4,7
mov EAX,[EDI] ; - load siny
mov EDX,4[EDI] ; - ...
mov SI,8[EDI] ; - ...
_endif ; endif
;; if( i & 4 ) sinx = - sinx; /* octants 4,5,6,7 */
mov ECX,iflag[EBP] ; get i and flag
test CL,4 ; if octants 4,5,6,7
_if ne ; then
xor SI,8000h ; - flip the sign
_endif ; endif
;; if( flag == 1 ) { /* if "tan" */
cmp CH,1 ; if "tan"
_if e ; then
;;
;; /* cos is out of phase with sin by 2 octants */
;;
;; i += 2;
;; if( (i+1) & 2 ) { /* if octants 1,2,5,6 */
;; cosx = cosy;
;; } else { /* octants 0,3,4,7 */
;; cosx = siny;
;; }
rol ESI,16 ; - shift exponent to top
add CL,2 ; - i += 2;
mov BL,CL ; - calc. (i+1) & 2
inc BL ; - ...
and BL,2 ; - ...
_if ne ; - if octants 1,2,5,6
and CL,4 ; - - if octants 4,5,6,7
mov EBX,cosy[EBP] ; - - load cosy
mov ECX,cosy+4[EBP] ; - - ...
mov SI,cosy+8[EBP] ; - - ...
_else ; - else
and CL,4 ; - - if octants 4,5,6,7
mov EBX,[EDI] ; - - load siny
mov ECX,4[EDI] ; - - ...
mov SI,8[EDI] ; - - ...
_endif ; - endif
;; if( i & 4 ) cosx = - cosx; /* octants 4,5,6,7 */
_if ne ; - if octants 4,5,6,7
xor ESI,00008000h ; - - flip the sign
_endif ; - endif
rol ESI,16 ; - shift exponent back to bottom
;; if( cosx == 0.0 ) {
;; errno = ERANGE;
;; if( sinx > 0.0 ) return( HUGE_VAL );
;; return( - HUGE_VAL );
;; }
_guess ; - guess
or EBX,EBX ; - - quit if cosx != 0
_quif ne ; - - ...
or ECX,ECX ; - - ...
_quif ne ; - - ...
test ESI,7FFF0000h ; - - ...
_quif ne ; - - ...
sub EAX,EAX ; - - set result to infinity
mov EDX,80000000h ; - - ...
or SI,7FFFh ; - - ...
_admit ; - admit
;; sinx = sinx/cosx; /* calculate value of tan function */
call ___LDD ; - - tan(x) = sin(x) / cos(x)
_endguess ; - endguess
;; }
_endif ; endif
;; if( exponent >= 28 ) {
;; return( _matherr( PLOSS, func_name[flag], &x, &x, sinx ) );
;; }
;; return( sinx );
mov [EDI],EAX ; store result
mov 4[EDI],EDX ; ...
mov 8[EDI],SI ; ...
mov ESP,EBP ; clean up stack
pop EBX ; restore registers
pop ECX ; ...
pop EDX ; ...
pop EDI ; ...
pop EBP ; restore EBP
ret ; return
__sincos endp
;; }
;;
;;
;;void sin( long double *x )
;; {
;; return _sincos( x, 0 );
defp __sin
push ESI ; save registers
sub ESI,ESI ; indicate sin
call __sincos ; evaluate sin
pop ESI ; restore ESI
ret ; return
__sin endp
;; }
;;
;;
;;void cos( long double *x )
;; {
;; return _sincos( x, 2 );
defp __cos
push ESI ; save registers
mov ESI,2 ; indicate cos
call __sincos ; evaluate cos
pop ESI ; restore ESI
ret ; return
__cos endp
;; }
;;
;;
;;void tan( long double *x )
;; {
;; return _sincos( x, 1 );
defp __tan
push ESI ; save registers
mov ESI,1 ; indicate tan
call __sincos ; evaluate tan
pop ESI ; restore ESI
ret ; return
__tan endp
;; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?