1# 2# Copyright (c) 1987 Regents of the University of California. 3# 4# Use and reproduction of this software are granted in accordance with 5# the terms and conditions specified in the Berkeley Software License 6# Agreement (in particular, this entails acknowledgement of the programs' 7# source, and inclusion of this notice) with the additional understanding 8# that all recipients should regard themselves as participants in an 9# ongoing research project and hence should feel obligated to report 10# their experiences (good or bad) with these elementary function codes, 11# using "sendbug 4bsd-bugs@BERKELEY", to the authors. 12# 13 .data 14 .align 2 15_sccsid: 16.asciz "@(#)cabs.s 1.1 1.1 (ucb.elefunt) 08/04/87" 17 18# double precision complex absolute value 19# CABS by W. Kahan, 9/7/80. 20# Revised for reserved operands by E. LeBlanc, 8/18/82 21# argument for complex absolute value by reference, *4(fp) 22# argument for cabs and hypot (C fcns) by value, 4(fp) 23# output is in r0:r1 24 25 .text 26 .align 2 27 .globl _cabs 28 .globl _hypot 29 .globl _z_abs 30 31# entry for c functions cabs and hypot 32_cabs: 33_hypot: 34 .word 0x807c # save r2-r6, enable floating overflow 35 movl 16(fp),r3 36 movl 12(fp),r2 # r2:3 = y 37 movl 8(fp),r1 38 movl 4(fp),r0 # r0:1 = x 39 brb 1f 40# entry for Fortran use, call by: d = abs(z) 41_z_abs: 42 .word 0x807c # save r2-r6, enable floating overflow 43 movl 4(fp),r4 # indirect addressing is necessary here 44 movl 12(r4),r3 # 45 movl 8(r4),r2 # r2:3 = y 46 movl 4(r4),r1 # 47 movl (r4),r0 # r0:1 = x 481: andl3 $0xff800000,r0,r4 # r4 has signed biased exp of x 49 cmpl $0x80000000,r4 50 beql 2f # x is a reserved operand, so return it 51 andl3 $0xff800000,r2,r5 # r5 has signed biased exp of y 52 cmpl $0x80000000,r5 53 bneq 3f # y isn't a reserved operand 54 movl r3,r1 55 movl r2,r0 # return y if it's reserved 562: ret 57 583: callf $4,regs_set # r0:1 = dsqrt(x^2+y^2)/2^r6 59 addl2 r6,r0 # unscaled cdabs in r0:1 60 jvc 2b # unless it overflows 61 subl2 $0x800000,r0 # halve r0 to get meaningful overflow 62 ldd r0 63 addd r0 # overflow; r0 is half of true abs value 64 ret 65 66regs_set: 67 .word 0x0000 68 andl2 $0x7fffffff,r0 # r0:r1 = dabs(x) 69 andl2 $0x7fffffff,r2 # r2:r3 = dabs(y) 70 cmpl r0,r2 71 bgeq 4f 72 movl r1,r5 73 movl r0,r4 74 movl r3,r1 75 movl r2,r0 76 movl r5,r3 77 movl r4,r2 # force y's exp <= x's exp 784: andl3 $0xff800000,r0,r6 # r6 = exponent(x) + bias(129) 79 beql 5f # if x = y = 0 then cdabs(x,y) = 0 80 subl2 $0x47800000,r6 # r6 = exponent(x) - 14 81 subl2 r6,r0 # 2^14 <= scaled x < 2^15 82 bitl $0xff800000,r2 83 beql 5f # if y = 0 return dabs(x) 84 subl2 r6,r2 85 cmpl $0x37800000,r2 # if scaled y < 2^-18 86 bgtr 5f # return dabs(x) 87 ldd r0 88 muld r0 89 std r0 # r0:1 = scaled x^2 90 ldd r2 91 muld r2 # acc = scaled y^2 92 addd r0 93 std r0 94 pushl r1 95 pushl r0 96 callf $12,_sqrt # r0:1 = dsqrt(x^2+y^2)/2^r6 975: ret 98