/* 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
float tanhf(float x); */ #include "lib_glob.h" #include "mth_glob.h" #include "tanh.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL _tanhf; .EXTERN _expf; _tanhf: F8=PASS F4, put(R7); F4=ABS F4, put(R11); 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: get(R11,1); get(R7,2); 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;