2005-04-16 15:20:36 -07:00
/ *
* Copyright ( C ) 2 0 0 0 H e w l e t t - P a c k a r d C o
* Copyright ( C ) 2 0 0 0 D a v i d M o s b e r g e r - T a n g < d a v i d m @hpl.hp.com>
*
* 3 2 - bit i n t e g e r d i v i s i o n .
*
* This c o d e i s b a s e d o n t h e a p p l i c a t i o n n o t e e n t i t l e d " D i v i d e , S q u a r e R o o t
* and R e m a i n d e r A l g o r i t h m s f o r t h e I A - 6 4 A r c h i t e c t u r e " . T h i s d o c u m e n t
* is a v a i l a b l e a s I n t e l d o c u m e n t n u m b e r 2 4 8 7 2 5 - 0 0 2 o r v i a t h e w e b a t
* http : / / developer. i n t e l . c o m / s o f t w a r e / o p e n s o u r c e / n u m e r i c s /
*
* For m o r e d e t a i l s o n t h e t h e o r y b e h i n d t h e s e a l g o r i t h m s , s e e " I A - 6 4
* and E l e m e n t a r y F u n c t i o n s " b y P e t e r M a r k s t e i n ; HP Professional Books
2016-01-30 22:07:31 -08:00
* ( http : / / www. g o o d r e a d s . c o m / b o o k / s h o w / 2 0 1 9 8 8 7 . I a _ 6 4 _ a n d _ E l e m e n t a r y _ F u n c t i o n s )
2005-04-16 15:20:36 -07:00
* /
# include < a s m / a s m m a c r o . h >
2016-01-17 01:13:41 -05:00
# include < a s m / e x p o r t . h >
2005-04-16 15:20:36 -07:00
# ifdef M O D U L O
# define O P m o d
# else
# define O P d i v
# endif
# ifdef U N S I G N E D
# define S G N u
# define E X T E N D z x t 4
# define I N T _ T O _ F P ( a ,b ) f c v t . x u f . s1 a =b
# define F P _ T O _ I N T ( a ,b ) f c v t . f x u . t r u n c . s1 a =b
# else
# define S G N
# define E X T E N D s x t 4
# define I N T _ T O _ F P ( a ,b ) f c v t . x f a =b
# define F P _ T O _ I N T ( a ,b ) f c v t . f x . t r u n c . s1 a =b
# endif
# define P A S T E 1 ( a ,b ) a ## b
# define P A S T E ( a ,b ) P A S T E 1 ( a ,b )
# define N A M E P A S T E ( P A S T E ( _ _ ,S G N ) ,P A S T E ( O P ,s i 3 ) )
GLOBAL_ E N T R Y ( N A M E )
.regstk 2 , 0 , 0 , 0
/ / Transfer i n p u t s t o F P r e g i s t e r s .
mov r2 = 0 x f f d d / / r2 = - 3 4 + 6 5 5 3 5 ( f p r e g f o r m a t b i a s )
EXTEND i n 0 = i n 0 / / i n 0 = a
EXTEND i n 1 = i n 1 / / i n 1 = b
;;
setf. s i g f8 = i n 0
setf. s i g f9 = i n 1
# ifdef M O D U L O
sub i n 1 = r0 , i n 1 / / i n 1 = - b
# endif
;;
/ / Convert t h e i n p u t s t o F P , t o a v o i d F P s o f t w a r e - a s s i s t f a u l t s .
INT_ T O _ F P ( f8 , f8 )
INT_ T O _ F P ( f9 , f9 )
;;
setf. e x p f7 = r2 / / f7 = 2 ^ - 3 4
frcpa. s1 f6 , p6 = f8 , f9 / / y 0 = f r c p a ( b )
;;
( p6 ) f m p y . s1 f8 = f8 , f6 / / q0 = a * y 0
( p6 ) f n m a . s1 f6 = f9 , f6 , f1 / / e 0 = - b * y 0 + 1
;;
# ifdef M O D U L O
setf. s i g f9 = i n 1 / / f9 = - b
# endif
( p6 ) f m a . s1 f8 = f6 , f8 , f8 / / q1 = e 0 * q0 + q0
( p6 ) f m a . s1 f6 = f6 , f6 , f7 / / e 1 = e 0 * e 0 + 2 ^ - 3 4
;;
# ifdef M O D U L O
setf. s i g f7 = i n 0
# endif
( p6 ) f m a . s1 f6 = f6 , f8 , f8 / / q2 = e 1 * q1 + q1
;;
FP_ T O _ I N T ( f6 , f6 ) / / q = t r u n c ( q2 )
;;
# ifdef M O D U L O
xma. l f6 = f6 , f9 , f7 / / r = q * ( - b ) + a
;;
# endif
getf. s i g r8 = f6 / / t r a n s f e r r e s u l t t o r e s u l t r e g i s t e r
br. r e t . s p t k . m a n y r p
END( N A M E )
2016-01-17 01:13:41 -05:00
EXPORT_ S Y M B O L ( N A M E )