Home | History | Annotate | Line # | Download | only in vax
n_support.S revision 1.9
      1 /*	$NetBSD: n_support.S,v 1.9 2014/03/15 14:12:56 martin Exp $	*/
      2 /*
      3  * Copyright (c) 1985, 1993
      4  *	The Regents of the University of California.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. Neither the name of the University nor the names of its contributors
     15  *    may be used to endorse or promote products derived from this software
     16  *    without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  *
     30  *	@(#)support.s	8.1 (Berkeley) 6/4/93
     31  */
     32 #include <machine/asm.h>
     33 
     34 WEAK_ALIAS(logbl,logb)
     35 WEAK_ALIAS(copysignl, copysign)
     36 
     37 	.text
     38 _sccsid:
     39 	.asciz "@(#)support.s\t1.3 (Berkeley) 8/21/85; 8.1 (ucb.elefunt) 6/4/93"
     40 
     41 /*
     42  * copysign(x,y),
     43  * logb(x),
     44  * scalb(x,N),
     45  * finite(x),
     46  * drem(x,y),
     47  * Coded in vax assembly language by K.C. Ng,  3/14/85.
     48  * Revised by K.C. Ng on 4/9/85.
     49  */
     50 
     51 /*
     52  * double copysign(double x,double y)
     53  */
     54 
     55 ENTRY(copysign, 0)
     56 	movq	4(%ap),%r0		# load x into %r0
     57 	bicw3	$0x807f,%r0,%r2		# mask off the exponent of x
     58 	beql	Lz			# if zero or reserved op then return x
     59 	bicw3	$0x7fff,12(%ap),%r2	# copy the sign bit of y into %r2
     60 	bicw2	$0x8000,%r0		# replace x by |x|
     61 	bisw2	%r2,%r0			# copy the sign bit of y to x
     62 Lz:	ret
     63 
     64 ENTRY(copysignf, 0)
     65 	movl	4(%ap),%r0		# load x into %r0
     66 	bicw3	$0x807f,%r0,%r2		# mask off the exponent of x
     67 	beql	1f			# if zero or reserved op then return x
     68 	bicw3	$0x7fff,8(%ap),%r2	# copy the sign bit of y into %r2
     69 	bicw2	$0x8000,%r0		# replace x by |x|
     70 	bisw2	%r2,%r0			# copy the sign bit of y to x
     71 1:	ret
     72 
     73 /*
     74  * float logbf(float x);
     75  */
     76 ENTRY(logbf, 0)
     77 	cvtfd   4(%ap),-(%sp)
     78 	calls   $2,_C_LABEL(logb)
     79 	cvtdf   %r0,%r0
     80 	ret
     81 
     82 /*
     83  * double logb(double x);
     84  */
     85 ENTRY(logb, 0)
     86 	bicl3	$0xffff807f,4(%ap),%r0	# mask off the exponent of x
     87 	beql    Ln
     88 	ashl	$-7,%r0,%r0		# get the bias exponent
     89 	subl2	$129,%r0			# get the unbias exponent
     90 	cvtld	%r0,%r0			# return the answer in double
     91 	ret
     92 Ln:	movq	4(%ap),%r0		# %r0:1 = x (zero or reserved op)
     93 	bneq	1f			# simply return if reserved op
     94 	movq 	$0x0000fe00ffffcfff,%r0  # -2147483647.0
     95 1:	ret
     96 
     97 /*
     98  * long finite(double x);
     99  */
    100 #ifndef __GFLOAT__
    101 	.globl finitef
    102 finitef = finite
    103 #endif
    104 ENTRY(finite, 0)
    105 	bicw3	$0x7f,4(%ap),%r0	# mask off the mantissa
    106 	cmpw	%r0,$0x8000		# to see if x is the reserved op
    107 	beql	1f			# if so, return FALSE (0)
    108 	movl	$1,%r0			# else return TRUE (1)
    109 	ret
    110 1:	clrl	%r0
    111 	ret
    112 
    113 /* int isnan(double x);
    114  */
    115 #if 0
    116 ENTRY(isnan, 0)
    117 	clrl	%r0
    118 	ret
    119 #endif
    120 
    121 /* int isnanf(float x);
    122  */
    123 ENTRY(isnanf, 0)
    124 	clrl	%r0
    125 	ret
    126 
    127 /*
    128  * double scalb(x,N)
    129  * double x; double N;
    130  */
    131 	.set	ERANGE,34
    132 
    133 ENTRY(scalb, 0)
    134 	movq	4(%ap),%r0
    135 	bicl3	$0xffff807f,%r0,%r3
    136 	beql	ret1			# 0 or reserved operand
    137 	movq	12(%ap),%r4
    138 	cvtdl	%r4, %r2
    139 	cmpl	%r2,$0x12c
    140 	bgeq	ovfl
    141 	cmpl	%r2,$-0x12c
    142 	bleq	unfl
    143 	ashl	$7,%r2,%r2
    144 	addl2	%r2,%r3
    145 	bleq	unfl
    146 	cmpl	%r3,$0x8000
    147 	bgeq	ovfl
    148 	addl2	%r2,%r0
    149 	ret
    150 ovfl:	pushl	$ERANGE
    151 	calls	$1,_C_LABEL(infnan)	# if it returns
    152 	bicw3	$0x7fff,4(%ap),%r2	# get the sign of input arg
    153 	bisw2	%r2,%r0			# re-attach the sign to %r0/1
    154 	ret
    155 unfl:	movq	$0,%r0
    156 ret1:	ret
    157 
    158 /*
    159  * DREM(X,Y)
    160  * RETURN X REM Y =X-N*Y, N=[X/Y] ROUNDED (ROUNDED TO EVEN IN THE HALF WAY CASE)
    161  * DOUBLE PRECISION (VAX D format 56 bits)
    162  * CODED IN VAX ASSEMBLY LANGUAGE BY K.C. NG, 4/8/85.
    163  */
    164 	.set	EDOM,33
    165 
    166 ENTRY(drem, 0x0fc0)
    167 	subl2	$12,%sp
    168 	movq	4(%ap),%r0		#%r0=x
    169 	movq	12(%ap),%r2		#%r2=y
    170 	jeql	Rop			#if y=0 then generate reserved op fault
    171 	bicw3	$0x007f,%r0,%r4		#check if x is Rop
    172 	cmpw	%r4,$0x8000
    173 	jeql	Ret			#if x is Rop then return Rop
    174 	bicl3	$0x007f,%r2,%r4		#check if y is Rop
    175 	cmpw	%r4,$0x8000
    176 	jeql	Ret			#if y is Rop then return Rop
    177 	bicw2	$0x8000,%r2		#y  := |y|
    178 	movw	$0,-4(%fp)		#-4(%fp) = nx := 0
    179 	cmpw	%r2,$0x1c80		#yexp ? 57
    180 	bgtr	C1			#if yexp > 57 goto C1
    181 	addw2	$0x1c80,%r2		#scale up y by 2**57
    182 	movw	$0x1c80,-4(%fp)		#nx := 57 (exponent field)
    183 C1:
    184 	movw	-4(%fp),-8(%fp)		#-8(%fp) = nf := nx
    185 	bicw3	$0x7fff,%r0,-12(%fp)	#-12(%fp) = sign of x
    186 	bicw2	$0x8000,%r0		#x  := |x|
    187 	movq	%r2,%r10			#y1 := y
    188 	bicl2	$0xffff07ff,%r11		#clear the last 27 bits of y1
    189 loop:
    190 	cmpd	%r0,%r2			#x ? y
    191 	bleq	E1			#if x <= y goto E1
    192  /* begin argument reduction */
    193 	movq	%r2,%r4			#t =y
    194 	movq	%r10,%r6			#t1=y1
    195 	bicw3	$0x807f,%r0,%r8		#xexp= exponent of x
    196 	bicw3	$0x807f,%r2,%r9		#yexp= exponent fo y
    197 	subw2	%r9,%r8			#xexp-yexp
    198 	subw2	$0x0c80,%r8		#k=xexp-yexp-25(exponent bit field)
    199 	blss	C2			#if k<0 goto C2
    200 	addw2	%r8,%r4			#t +=k
    201 	addw2	%r8,%r6			#t1+=k, scale up t and t1
    202 C2:
    203 	divd3	%r4,%r0,%r8		#x/t
    204 	cvtdl	%r8,%r8			#n=[x/t] truncated
    205 	cvtld	%r8,%r8			#float(n)
    206 	subd2	%r6,%r4			#t:=t-t1
    207 	muld2	%r8,%r4			#n*(t-t1)
    208 	muld2	%r8,%r6			#n*t1
    209 	subd2	%r6,%r0			#x-n*t1
    210 	subd2	%r4,%r0			#(x-n*t1)-n*(t-t1)
    211 	jbr	loop
    212 E1:
    213 	movw	-4(%fp),%r6		#%r6=nx
    214 	beql	C3			#if nx=0 goto C3
    215 	addw2	%r6,%r0			#x:=x*2**57 scale up x by nx
    216 	movw	$0,-4(%fp)		#clear nx
    217 	jbr	loop
    218 C3:
    219 	movq	%r2,%r4			#%r4 = y
    220 	subw2	$0x80,%r4		#%r4 = y/2
    221 	cmpd	%r0,%r4			#x:y/2
    222 	blss	E2			#if x < y/2 goto E2
    223 	bgtr	C4			#if x > y/2 goto C4
    224 	cvtdl	%r8,%r8			#ifix(float(n))
    225 	blbc	%r8,E2			#if the last bit is zero, goto E2
    226 C4:
    227 	subd2	%r2,%r0			#x-y
    228 E2:
    229 	xorw2	-12(%fp),%r0		#x^sign (exclusive or)
    230 	movw	-8(%fp),%r6		#%r6=nf
    231 	bicw3	$0x807f,%r0,%r8		#%r8=exponent of x
    232 	bicw2	$0x7f80,%r0		#clear the exponent of x
    233 	subw2	%r6,%r8			#%r8=xexp-nf
    234 	bgtr	C5			#if xexp-nf is positive goto C5
    235 	movw	$0,%r8			#clear %r8
    236 	movq	$0,%r0			#x underflow to zero
    237 C5:
    238 	bisw2	%r8,%r0			/* put %r8 into x's exponent field */
    239 	ret
    240 Rop:					#Reserved operand
    241 	pushl	$EDOM
    242 	calls	$1,_C_LABEL(infnan)	#generate reserved op fault
    243 	ret
    244 Ret:
    245 	movq	$0x8000,%r0		#propagate reserved op
    246 	ret
    247