;***********************************************************************; *;
;* Description : This file contain source code for fixed point SQRT *;
;* function implemented using Tylor series *;
;* *;
;***********************************************************************;
;* Tylor Series Approximation of SQRT: *;
;* Algorithm : *;
;* The following equation approximates the sqrt(x), where 0.5<= x <=1.0*;
;* 0.5*sqrt(x)= 0.7274475*x-0.672455*x^2+0.553406*x^3-0.2682495*x^4 *;
;* +0.0560605*x^5+0.1037903 *;
;* *;
;* To determine the sqrt of an input value outside the range [0.5, 1.0]*;
;* the input should be scaled to a number within the range. *;
;***********************************************************************;
.global _Int16Sqrt
a0 .set 06a48h ; 0.1037903 scaled by 2^18
a1 .set 05d1dh ; 0.7274475 scaled by 2^15
a2 .set 0a9edh ; -0.672455 scaled by 2^15
a3 .set 046d6h ; 0.553406 scaled by 2^15
a4 .set 0bb54h ; -0.2682495 scaled by 2^16
a5 .set 00e5ah ; 0.0560605 scaled by 2^16
SQRT2 .set 05a82h ;(1/sqrt(2)) in Q15 format
; Also sqrt(2) in Q14 format
.text
_Int16Sqrt
; ACC=X in Q16 format to AH
SETC SXM ; Set the sign ext. mode
MPY P,T,#0 ; P=0
LSR64 ACC,#1 ; X=X/2
CSB ACC ; Count sign bits, T=E
LSL64 ACC,T ; ACC=x=X/(2^(E-15) in Q31 format