/* This C language subroutine computes the value of the smallest integer greater 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 6/94 by AS #include
double ceil(double x); */ #include "lib_glob.h" #include "mth_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL _ceil; _ceil: R1=R1-R1, reads(R4,1); R0=R0-R0, reads(R8,2); R12=PASS R8, I4=R4; /*Temp hold of R4 in I12 */ R4=FEXT R4 BY 20:11; /*Extract biased exponent */ R2=D_EXP_BIAS; R4=R4-R2; /*Compute unbiased exponent */ R2=52; COMP(R4,R2); /*Test for zero fraction */ IF GT JUMP (PC, restore_state); /*Return already set to zero*/ R8=0xFFFFFFFF; R2=R2-R4; R1=ASHIFT R8 BY R2; /*Determine mask*/ R1=R12 AND R1; /*R1 holds LSW integer part only*/ R2=20; R2=R2-R4, R4=I4; /*Restore R4 to original */ R8=ASHIFT R8 BY R2; R0=R4 AND R8, I4=R1; /*R0 holds MSW int part, save R1 for later*/ F4=PASS F4, put(R0); /*Tst for neg input, save R0 for later*/ IF LE JUMP (PC, restore_state); /* just remove fract for neg input*/ /* Otherwise, for a pos value we*/ put(R12); /* need to subtract integer val */ put(R4); /* from the original value to */ put(R1); /* determine if there is a */ put(R0); /* fract part remaining */ CALLER_HOLD(R4) CALLER_SWAP RTLCALL (PC, ___dsub) (DB); SAVE_OLD_FRAME(R4) SAVE_RET_ADDR alter(4); /* Clean parameters from stack */ R4=R0 OR R1, R1=I4; /* Test for 0 fraction, restore R1*/ IF EQ JUMP (PC, restore_state) (DB); /* return with result, else*/ get(R0,1); /* add one to result */ R8=D_ONE_LSW; R4=D_ONE_MSW; put(R8); put(R4); put(R1); /*Store LSW of integer*/ put(R0); CALLER_HOLD(R0) CALLER_SWAP RTLCALL (PC, ___dadd) (DB); SAVE_OLD_FRAME(R0) SAVE_RET_ADDR alter(4); restore_state: FETCH_RETURN RETURN (DB); RESTORE_STACK RESTORE_FRAME .ENDSEG;