; RCS Header $Id: fp24.a16 2.7 1996/10/07 13:50:29 F.J.Testa Exp $ ; $Revision: 2.7 $ ; PIC16 24 BIT FLOATING POINT LIBRARY ; ; Unary operations: both input and output are in AEXP,AARG ; ; Binary operations: input in AEXP,AARG and BEXP,BARG with output in AEXP,AARG ; ; All routines return WREG = 0x00 for successful completion, and WREG = 0xFF ; for an error condition specified in FPFLAGS. ; ; All timings are worst case cycle counts ; ; Routine Function ; ; FLO1624 16 bit integer to 24 bit floating point conversion ; FLO24 ; ; Timing: RND ; 0 1 ; ; 0 83 83 ; SAT ; 1 88 88 ; ; NRM2424 24 bit normalization of unnormalized 24 bit floating point numbers ; NRM24 ; ; Timing: RND ; 0 1 ; ; 0 72 72 ; SAT ; 1 77 77 ; ; INT2416 24 bit floating point to 16 bit integer conversion ; INT24 ; ; Timing: RND ; 0 1 ; ; 0 83 89 ; SAT ; 1 83 92 ; ; FLO2424 24 bit integer to 24 bit floating point conversion ; ; Timing: RND ; 0 1 ; ; 0 108 117 ; SAT ; 1 108 123 ; ; NRM3224 32 bit normalization of unnormalized 24 bit floating point numbers ; ; Timing: RND ; 0 1 ; ; 0 94 103 ; SAT ; 1 94 109 ; ; INT2424 24 bit floating point to 24 bit integer conversion ; ; Timing: RND ; 0 1 ; ; 0 105 113 ; SAT ; 1 105 115 ; ; FPA24 24 bit floating point add ; ; Timing: RND ; 0 1 ; ; 0 197 208 ; SAT ; 1 197 213 ; ; FPS24 24 bit floating point subtract ; ; Timing: RND ; 0 1 ; ; 0 199 240 ; SAT ; 1 199 215 ; ; FPM24 24 bit floating point multiply ; ; Timing: RND ; 0 1 ; ; 0 298 309 ; SAT ; 1 298 313 ; ; FPD24 24 bit floating point divide ; ; Timing: RND ; 0 1 ; ; 0 472 494 ; SAT ; 1 472 498 ; ;********************************************************************************************** ;********************************************************************************************** ; ; 24 bit floating point representation ; ; EXPONENT 8 bit biased exponent ; It is important to note that the use of biased exponents produces ; a unique representation of a floating point 0, given by ; EXP = HIGHBYTE = LOWBYTE = 0x00, with 0 being the only ; number with EXP = 0. ; ; HIGHBYTE 8 bit most significant byte of fraction in sign-magnitude representation, ; with SIGN = MSB, implicit MSB = 1 and radix point to the right of MSB ; ; LOWBYTE 8 bit least significant byte of sign-magnitude fraction ; ; EXPONENT HIGHBYTE LOWBYTE ; ; xxxxxxxx S.xxxxxxx xxxxxxxx ; ; | ; RADIX ; POINT ; ;********************************************************************************************** ;********************************************************************************************** ; Normalization routine ; Input: 24 bit unnormalized floating point number in AEXP, AARGB0, AARGB1, ; with sign in SIGN,MSB and other bits zero. ; Use: CALL NRM2424 or CALL NRM24 ; Output: 24 bit normalized floating point number in AEXP, AARGB0, AARGB1 ; Result: AARG <-- NORMALIZE( AARG ) ; Max Timing: 10+6+7*7+7 = 72 clks SAT = 0 ; 10+6+7*7+1+11 = 77 clks SAT = 1 ; Min Timing: 14 clks AARG = 0 ; 5+9+4 = 18 clks ; PM: 26 DM: 6 ;---------------------------------------------------------------------------------------------- NRM2424 NRM24 CLRF TEMP ; clear exponent decrement MOVF AARGB0,W ; test if highbyte=0 BTFSS _Z GOTO NORM2424 MOVF AARGB1,W ; if so, shift 8 bits by move MOVWF AARGB0 BTFSC _Z ; if highbyte=0, result=0 GOTO RES024 CLRF AARGB1 BSF TEMP,3 NORM2424 MOVF TEMP,W SUBWF EXP,F BTFSS _Z BTFSS _C GOTO SETFUN24 BCF _C ; clear carry bit NORM2424A BTFSC AARGB0,MSB ; if MSB=1, normalization done GOTO FIXSIGN24 RLF AARGB1,F ; otherwise, shift left and RLF AARGB0,F ; decrement EXP DECFSZ EXP,F GOTO NORM2424A GOTO SETFUN24 ; underflow if EXP=0 FIXSIGN24 BTFSS SIGN,MSB BCF AARGB0,MSB ; clear explicit MSB if positive RETLW 0 RES024 CLRF AARGB0 ; result equals zero CLRF AARGB1 CLRF AARGB2 ; clear extended byte CLRF EXP RETLW 0 ;********************************************************************************************** ;********************************************************************************************** ; Integer to float conversion ; Input: 24 bit 2's complement integer right justified in AARGB0, AARGB1, AARGB2 ; Use: CALL FLO2424 ; Output: 24 bit floating point number in AEXP, AARGB0, AARGB1 ; Result: AARG <-- FLOAT( AARG ) ; Max Timing: 14+94 = 108 clks RND = 0 ; 14+103 = 117 clks RND = 1, SAT = 0 ; 14+109 = 123 clks RND = 1, SAT = 1 ; Min Timing: 6+28 = 34 clks AARG = 0 ; 6+22 = 28 clks ; PM: 14+51 = 65 DM: 7 ;---------------------------------------------------------------------------------------------- FLO2424 MOVLW D'23'+EXPBIAS ; initialize exponent and add bias MOVWF EXP CLRF SIGN BTFSS AARGB0,MSB ; test sign GOTO NRM3224 COMF AARGB2,F ; if < 0, negate and set MSB in SIGN COMF AARGB1,F COMF AARGB0,F INCF AARGB2,F BTFSC _Z INCF AARGB1,F BTFSC _Z INCF AARGB0,F BSF SIGN,MSB ;********************************************************************************************** ; Normalization routine ; Input: 32 bit unnormalized floating point number in AEXP, AARGB0, AARGB1, ; AARGB2, with sign in SIGN,MSB ; Use: CALL NRM3224 ; Output: 24 bit normalized floating point number in AEXP, AARGB0, AARGB1 ; Result: AARG <-- NORMALIZE( AARG ) ; Max Timing: 21+6+7*8+7+4 = 94 clks RND = 0 ; 21+6+7*8+20+4 = 103 clks RND = 1, SAT = 0 ; 21+6+7*8+19+11 = 109 clks RND = 1, SAT = 1 ; Min Timing: 22+6 = 28 clks AARG = 0 ; 5+9+4+4 = 22 clks ; PM: 51 DM: 7 ;---------------------------------------------------------------------------------------------- NRM3224 CLRF TEMP ; clear exponent decrement MOVF AARGB0,W ; test if highbyte=0 BTFSS _Z GOTO NORM3224 MOVF AARGB1,W ; if so, shift 8 bits by move MOVWF AARGB0 MOVF AARG...
fred1144