/* This C language subroutine computes the floating point modulo of its two floating point inputs. The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 4/28/90 #include
float fmodf(float x, float y); */ #include "lib_glob.h" #include "mth_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL _fmodf; _fmodf: R0=PASS R4, put(R7); /*Save sign of x */ R1=R1-R1, put(R11); /*R1=0 for scale subtract*/ R2=MODE1; /*ABS of denominator, Save old mode*/ BIT SET MODE1 32768; /*Set TRUNCATE mode*/ BIT CLR MODE1 65536; /*Set to 40-bit mode*/ F11=2.0; /*Used in divide*/ CALL (PC, ___float_divide) (DB); R12=ABS R8, dm_ptr=R0; F7=ABS F4, dm_mdf=R12; F7=ABS F4, F4=F7; /*F15=Q, F7=N*/ R8=LOGB F4, R11=dm_ptr; /*Extract exponent of input*/ IF AV R8=R8-R8; /*Handle Q=0 correctly*/ R0=31; /*Used for exponent test*/ COMP(R8,R0), R12=dm_mdf; /*If greater then 31, return*/ IF GT JUMP (PC, compute_modulo); /*Input contains all integer part*/ F0=1.0; IF EQ F1=SCALB F0 BY R8; /*Must remove MSB Q if big exp*/ F8=F4-F1; /*Subtract scale (sometimes 0)*/ R0=FIX F8; /*Convert to fixed point*/ F8=FLOAT R0; /*Refloat R0*/ F4=F8+F1; /*Add back scale if necessary*/ compute_modulo: F4=F4*F12, FETCH_RETURN /*Compute i*y*/ F1=F7-F4, MODE1=R2; /*Compute x - i * y */ F0=F1 COPYSIGN F11, get(R11,1); /*Get sign of input into F1 */ COMP (R1,R12), get(R7,2); IF EQ R0=R0-R0; /*divisor is a factor of dividend */ restore_state: RETURN (DB); RESTORE_STACK RESTORE_FRAME .ENDSEG;