xref: /original-bsd/sys/tahoe/math/Ksqrtf.s (revision c8089215)
1/*-
2 * Copyright (c) 1985 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Computer Consoles Inc.
7 *
8 * %sccs.include.redist.c%
9 *
10 *	@(#)Ksqrtf.s	7.1 (Berkeley) 12/06/90
11 */
12
13#include "../tahoe/SYS.h"
14
15	.text
16ENTRY(Ksqrtf, 0)
17	subl3	$76,fp,sp
18	tstl	4(fp)			# if (arg <= 0.) {
19	jgtr	L18
20	jgeq	L19			# if (arg < 0.)
21L19:	clrl	r1
22	clrl	r0
23	ret				# return(0.);}
24L18:
25	pushl	20(fp)			# hfs
26	subl3	$72,fp,-(sp)
27	pushl	8(fp)
28	pushl	4(fp)
29	callf	$20,_Kfrexpf
30	clrl	-60+4(fp)
31	movl	r0,-60(fp)		# x = frexp(arg,&exp);
32	jbr	L20
33L2000001:
34	pushl	20(fp)			# hfs
35	ldd	two
36	pushd
37	ldd	-60(fp)
38	pushd
39	callf	$24,_Kmuld		# x * 2
40	ldd	r0
41	std	-60(fp)			# x *= 2;
42	decl	-72(fp)			# exp--;}
43L20:	cmpd2	-60(fp),half		# while(x < 0.5){
44	jlss	L2000001
45	bitl	$1,-72(fp)		# if(exp & 1) {
46	jeql	L24
47	pushl	20(fp)			# hfs
48	ldd	two
49	pushd
50	ldd	-60(fp)
51	pushd
52	callf	$24,_Kmuld		# x * 2
53	ldd	r0
54	std	-60(fp)			# x *= 2;
55	decl	-72(fp)			# exp--;}
56L24:	pushl	20(fp)			# hfs
57	ldd	-60(fp)
58	pushd
59	ldd	one
60	pushd
61	callf	$24,_Kaddd		# (1.0+x)
62	pushl	20(fp)			# hfs
63	ldd	r0
64	pushd
65	ldd	half
66	pushd
67	callf	$24,_Kmuld
68	ldd	r0
69	std	-68(fp)			 # temp=0.5*(1.0+x);
70	jbr	L28
71L2000003:
72	pushl	20(fp)			# hfs
73	ldd	big
74	pushd
75	ldd	-68(fp)
76	pushd
77	callf	$24,_Kmuld		# temp*(1L<<30)
78	ldd	r0
79	std	-68(fp)			# temp *=(1L<<30);
80	subl2	$60,-72(fp)		# exp -= 60;}
81L28:	cmpl	-72(fp),$60		# while(exp > 60){
82	jleq	L31
83	jbr	L2000003
84L2000005:
85	pushl	20(fp)			# hfs
86	ldd	big
87	pushd
88	ldd	-68(fp)
89	pushd
90	callf	$24,_Kdivd
91	ldd	r0
92	std	-68(fp)			# temp /= (1L<<30);
93	addl2	$60,-72(fp)		# exp +=60;}
94L31:	cmpl	-72(fp),$-60		# while(exp < -60) {
95	jlss	L2000005
96	tstl	-72(fp)			# if(exp >=0)
97	jlss	L34
98	divl3	$2,-72(fp),r0
99	shll	r0,$1,r0
100	pushl	20(fp)			# hfs
101	pushl	$0
102	pushl	r0
103	pushl	$0
104	pushl	$0
105	callf	$24,_Kcvtld
106	pushl	20(fp)			# hfs
107	ldd	r0
108	pushd
109	ldd	-68(fp)
110	pushd
111	callf	$24,_Kmuld		# temp * (1L <<(exp/2))
112	jbr	L2000006		# temp *= 1L << (exp/2));
113L34:	mnegl	-72(fp),r0		# -exp
114	divl2	$2,r0			# -exp/2
115	shll	r0,$1,r0
116	pushl	20(fp)			# hfs
117	pushl	$0
118	pushl	r0
119	pushl	$0
120	pushl	$0
121	callf	$24,_Kcvtld
122	pushl	20(fp)			# hfs
123	ldd	r0
124	pushd
125	ldd	-68(fp)
126	pushd
127	callf	$24,_Kdivd		# temp / (1L <<(-exp/2))
128L2000006:
129	ldd	r0
130	std	-68(fp)			# temp (*/)= 1L << (exp/2));
131	clrl	-76(fp)
132L2000008:
133	pushl	20(fp)			# hfs
134	ldd	-68(fp)
135	pushd
136	ldd	4(fp)
137	pushd
138	callf	$24,_Kdivd
139	pushl	20(fp)			# hfs
140	ldd	r0
141	pushd
142	ldd	-68(fp)
143	pushd
144	callf	$24,_Kaddd
145	pushl	20(fp)			# hfs
146	ldd	r0
147	pushd
148	ldd	half
149	pushd
150	callf	$24,_Kmuld
151	ldd	r0
152	std	-68(fp)			# temp=0.5*(temp+arg/temp);
153	aobleq	$3,-76(fp),L2000008
154	ldd	-68(fp)
155	cvdf
156	stf	r0
157	ret
158
159	.data
160	.align	2
161half:	.long	0x40000000, 0x00000000 # .double .5
162two:	.long	0x41000000, 0x00000000 # .double 2
163one:	.long	0x40800000, 0x00000000 # .double 1
164big:	.long	0x4F800000, 0x00000000 # .double (1<<30)
165