* Copyright (c) 1985, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* @(#)support.s 8.1 (Berkeley) 6/4/93
.asciz "@(#)support.s 1.3 (Berkeley) 8/21/85; 8.1 (ucb.elefunt) 6/4/93"
* Coded in vax assembly language by K.C. Ng, 3/14/85.
* Revised by K.C. Ng on 4/9/85.
movq 4(ap),r0 # load x into r0
bicw3 $0x807f,r0,r2 # mask off the exponent of x
beql Lz # if zero or reserved op then return x
bicw3 $0x7fff,12(ap),r2 # copy the sign bit of y into r2
bicw2 $0x8000,r0 # replace x by |x|
bisw2 r2,r0 # copy the sign bit of y to x
bicl3 $0xffff807f,4(ap),r0 # mask off the exponent of x
ashl $-7,r0,r0 # get the bias exponent
subl2 $129,r0 # get the unbias exponent
cvtld r0,r0 # return the answer in double
Ln: movq 4(ap),r0 # r0:1 = x (zero or reserved op)
bneq 1f # simply return if reserved op
movq $0x0000fe00ffffcfff,r0 # -2147483647.0
bicw3 $0x7f,4(ap),r0 # mask off the mantissa
cmpw r0,$0x8000 # to see if x is the reserved op
beql 1f # if so, return FALSE (0)
movl $1,r0 # else return TRUE (1)
beql ret1 # 0 or reserved operand
calls $1,_infnan # if it returns
bicw3 $0x7fff,4(ap),r2 # get the sign of input arg
bisw2 r2,r0 # re-attach the sign to r0/1
* RETURN X REM Y =X-N*Y, N=[X/Y] ROUNDED (ROUNDED TO EVEN IN THE HALF WAY CASE)
* DOUBLE PRECISION (VAX D format 56 bits)
* CODED IN VAX ASSEMBLY LANGUAGE BY K.C. NG, 4/8/85.
jeql Rop #if y=0 then generate reserved op fault
bicw3 $0x007f,r0,r4 #check if x is Rop
jeql Ret #if x is Rop then return Rop
bicl3 $0x007f,r2,r4 #check if y is Rop
jeql Ret #if y is Rop then return Rop
bicw2 $0x8000,r2 #y := |y|
movw $0,-4(fp) #-4(fp) = nx := 0
cmpw r2,$0x1c80 #yexp ? 57
bgtr C1 #if yexp > 57 goto C1
addw2 $0x1c80,r2 #scale up y by 2**57
movw $0x1c80,-4(fp) #nx := 57 (exponent field)
movw -4(fp),-8(fp) #-8(fp) = nf := nx
bicw3 $0x7fff,r0,-12(fp) #-12(fp) = sign of x
bicw2 $0x8000,r0 #x := |x|
bicl2 $0xffff07ff,r11 #clear the last 27 bits of y1
bleq E1 #if x <= y goto E1
/* begin argument reduction */
bicw3 $0x807f,r0,r8 #xexp= exponent of x
bicw3 $0x807f,r2,r9 #yexp= exponent fo y
subw2 $0x0c80,r8 #k=xexp-yexp-25(exponent bit field)
addw2 r8,r6 #t1+=k, scale up t and t1
cvtdl r8,r8 #n=[x/t] truncated
subd2 r4,r0 #(x-n*t1)-n*(t-t1)
addw2 r6,r0 #x:=x*2**57 scale up x by nx
blss E2 #if x < y/2 goto E2
bgtr C4 #if x > y/2 goto C4
cvtdl r8,r8 #ifix(float(n))
blbc r8,E2 #if the last bit is zero, goto E2
xorw2 -12(fp),r0 #x^sign (exclusive or)
bicw3 $0x807f,r0,r8 #r8=exponent of x
bicw2 $0x7f80,r0 #clear the exponent of x
bgtr C5 #if xexp-nf is positive goto C5
movq $0,r0 #x underflow to zero
bisw2 r8,r0 #put r8 into x's exponent field
calls $1,_infnan #generate reserved op fault
movq $0x8000,r0 #propagate reserved op