/* This C language subroutine computes the hyperbolic tangent of its floating point input. The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 6/9/90 Updated on 5/94 by AS #include
double tanh(double x); */ #include "lib_glob.h" #include "mth_glob.h" #include "tanh.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL _tanh; .EXTERN _expf; _tanh: put(R3); put(R7); put(R11); reads(R4,1); reads(R8,2); CALL (PC, ___lib_dtof) (DB); R0=PASS R4; R1=PASS R8; F4=ABS F0, F8=F0; F2=bigx; COMP(F4,F2); IF GT JUMP (PC, return_one); F2=ln_3_over_2; COMP(F4,F2); IF GT JUMP (PC, return_exp); F2=eps; COMP(F4,F2); IF LE JUMP (PC, check_sign); F2=F4*F4; /* g = f*f */ F1=p1; F7=F1*F2; /* p1*g */ F1=p0; F7=F7+F1; /* P(g) = p1*g + p0 */ F7=F7*F2; /* g*P(g) = (p1*g + p0)*g */ F11=q0; CALL (PC, ___float_divide) (DB); F12=F2+F11; /* Q(g) = g + q0*/ F11=2.0; F7=F7*F4; /* R*f */ F4=F7+F4; /* f+f*R */ check_sign: F8=PASS F8; IF LT F4=-F4; F0=PASS F4, FETCH_RETURN restore_state: CALL (PC, ___lib_ftod) (DB); get(R11,1); get(R7,2); get(R3,3); RETURN (DB); RESTORE_STACK RESTORE_FRAME return_one: JUMP (PC, check_sign) (DB); F4=1.0; NOP; return_exp: F4=F4+F4, CALLER_HOLD(R2) CALLER_SWAP RTLCALL (PC, _expf) (DB); SAVE_OLD_FRAME(R2) SAVE_RET_ADDR F7=1.0; CALL (PC, ___float_divide) (DB); F12=F0+F7; /*Compute 1/(exp(f+f)+1.0) */ F11=2.0; F4=0.5; JUMP (PC, check_sign) (DB); F4=F4-F7; /*Compute 0.5 - 1.0/(exp(f+f)+1.0) */ F4=F4+F4; /*Result=result+result */ .ENDSEG;