/* This C language subroutine computes the greatest integer less then or equal to the input. The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 4/28/90 Updated on 5/94 by AS #include
double floor(double x); */ #include "lib_glob.h" #include "mth_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL _floor; _floor: put(R6); put(R7); reads(R4,1); reads(R8,2); R0=PASS R4, R12=R8; R4=FEXT R0 BY 20:11; /*Extract biased exponent*/ R3=D_EXP_BIAS; R4=R4-R3, R1=R12; /*Compute unbiased exponent*/ R3=52; COMP(R4,R3); /*Test for zero fraction*/ IF GT JUMP (PC, restore_state); /*Return already set to zero*/ R8=0xFFFFFFFF; R2=52; R2=R2-R4; R7=ASHIFT R8 BY R2; /*Determine mask*/ R7=R12 AND R7; /*R7 holds LSW integer part only*/ R2=20; R2=R2-R4, R1=R7; R8=ASHIFT R8 BY R2; R6=R0 AND R8; /*R6 holds MSW integer part only*/ F2=PASS F0, R0=R6; /* If the original input is pos.*/ IF GE JUMP (PC, restore_state); /* just remove the fraction */ /* Otherwise, for a neg value we*/ put(R12); /* need to subtract integer val */ put(R2); /* from the original value to */ put(R1); /* determine if there is a */ put(R0); /* fractional part remaining. */ CALLER_HOLD(R2) CALLER_SWAP RTLCALL (PC, ___dsub) (DB); SAVE_OLD_FRAME(R2) label_1: SAVE_RET_ADDR alter(4); /* Clean parameters from stack */ R4=R0 OR R1; /* Test for zero fraction, if it*/ IF EQ JUMP (PC, restore_state) (DB); /* is, return with result, else */ R0=PASS R6, R1=R7; /* subtract one from result */ R8=D_ONE_LSW; R4=D_ONE_MSW; put(R8); put(R4); put(R1); /*Store LSW of integer*/ put(R0); CALLER_HOLD(R2) CALLER_SWAP RTLCALL (PC, ___dsub) (DB); SAVE_OLD_FRAME(R2) label_2:SAVE_RET_ADDR alter(4); restore_state: FETCH_RETURN get(R7,2); get(R6,3); RETURN (DB); RESTORE_STACK RESTORE_FRAME .ENDSEG;