Annotation of 43BSDReno/lib/libm/tahoe/support.s, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1987 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  *
                     19:  * All recipients should regard themselves as participants in an ongoing
                     20:  * research project and hence should feel obligated to report their
                     21:  * experiences (good or bad) with these elementary function codes, using
                     22:  * the sendbug(8) program, to the authors.
                     23:  */
                     24:        .data
                     25:        .align  2
                     26: _sccsid:
                     27:        .asciz  "@(#)support.s  5.5     (ucb.elefunt)   6/1/90"
                     28: /*
                     29:  * copysign(x,y),
                     30:  * logb(x),
                     31:  * scalb(x,N),
                     32:  * finite(x),
                     33:  * drem(x,y),
                     34:  * Coded in vax assembly language by K. C. Ng 4/9/85.
                     35:  * Re-coded in tahoe assembly language by Z. Alex Liu 7/13/87.
                     36:  */
                     37: /*
                     38:  * double copysign(x,y)
                     39:  * double x,y;
                     40:  */
                     41:        .globl  _copysign
                     42:        .text
                     43:        .align  2
                     44: _copysign:
                     45:        .word   0x0004                  # save r2
                     46:        movl    8(fp),r1
                     47:        movl    4(fp),r0                # r0:r1 = x
                     48:        andl3   $0x7f800000,r0,r2       # r2 = biased exponent of x
                     49:        beql    1f                      # if 0 or reserved op then return x
                     50:        andl3   $0x80000000,12(fp),r2   # r2 = sign bit of y at bit-31
                     51:        andl2   $0x7fffffff,r0          # replace x by |x|
                     52:        orl2    r2,r0                   # copy the sign bit of y to x
                     53: 1:     ret
                     54: /*
                     55:  * double logb(x)
                     56:  * double x;
                     57:  */
                     58:        .globl  _logb
                     59:        .text
                     60:        .align  2
                     61: _logb:
                     62:        .word   0x0000                  # save nothing
                     63:        andl3   $0x7f800000,4(fp),r0    # r0[b23:b30] = biased exponent of x
                     64:        beql    1f
                     65:        shrl    $23,r0,r0               # r0[b0:b7] = biased exponent of x
                     66:        subl2   $129,r0                 # r0 = unbiased exponent of x
                     67:        cvld    r0                      # acc = unbiased exponent of x (double)
                     68:        std     r0                      # r0 =  unbiased exponent of x (double)
                     69:        ret
                     70: 1:     movl    8(fp),r1                # 8(fp) must be moved first
                     71:        movl    4(fp),r0                # r0:r1 = x (zero or reserved op)
                     72:        blss    2f                      # simply return if reserved op
                     73:        movl    $0xfe000000,r1
                     74:        movl    $0xcfffffff,r0          # -2147483647.0
                     75: 2:     ret
                     76: /*
                     77:  * long finite(x)
                     78:  * double x;
                     79:  */
                     80:        .globl  _finite
                     81:        .text
                     82:        .align  2
                     83: _finite:
                     84:        .word   0x0000                  # save nothing
                     85:        andl3   $0xff800000,4(fp),r0    # r0 = sign of x & its biased exponent
                     86:        cmpl    r0,$0x80000000          # is x a reserved op?
                     87:        beql    1f                      # if so, return FALSE (0)
                     88:        movl    $1,r0                   # else return TRUE (1)
                     89:        ret
                     90: 1:     clrl    r0
                     91:        ret
                     92: /*
                     93:  * double scalb(x,N)
                     94:  * double x; int N;
                     95:  */
                     96:        .globl  _scalb
                     97:        .set    ERANGE,34
                     98:        .text
                     99:        .align  2
                    100: _scalb:
                    101:        .word   0x000c                  # save r2-r3
                    102:        movl    8(fp),r1
                    103:        movl    4(fp),r0                # r0:r1 = x (-128 <= Ex <= 126)
                    104:        andl3   $0x7f800000,r0,r3       # r3[b23:b30] = biased exponent of x
                    105:        beql    1f                      # is x a 0 or a reserved operand?
                    106:        movl    12(fp),r2               # r2 = N
                    107:        cmpl    r2,$0xff                # if N >= 255
                    108:        bgeq    2f                      # then the result must overflow
                    109:        cmpl    r2,$-0xff               # if N <= -255
                    110:        bleq    3f                      # then the result must underflow
                    111:        shrl    $23,r3,r3               # r3[b0:b7] = biased exponent of x
                    112:        addl2   r2,r3                   # r3 = biased exponent of the result
                    113:        bleq    3f                      # if <= 0 then the result underflows
                    114:        cmpl    r3,$0x100               # if >= 256 then the result overflows
                    115:        bgeq    2f
                    116:        shll    $23,r3,r3               # r3[b23:b30] = biased exponent of res.
                    117:        andl2   $0x807fffff,r0
                    118:        orl2    r3,r0                   # r0:r1 = x*2^N
                    119: 1:     ret
                    120: 2:     pushl   $ERANGE                 # if the result would overflow
                    121:        callf   $8,_infnan              # and _infnan returns
                    122:        andl3   $0x80000000,4(fp),r2    # get the sign of input arg
                    123:        orl2    r2,r0                   # re-attach the sign to r0:r1
                    124:        ret
                    125: 3:     clrl    r1                      # if the result would underflow
                    126:        clrl    r0                      # then return 0
                    127:        ret
                    128: /*
                    129:  * double drem(x,y)
                    130:  * double x,y;
                    131:  * Returns x-n*y where n=[x/y] rounded (to even in the half way case).
                    132:  */
                    133:        .globl  _drem
                    134:        .set    EDOM,33
                    135:        .text
                    136:        .align  2
                    137: _drem:
                    138:        .word   0x1ffc                  # save r2-r12
                    139:        movl    16(fp),r3
                    140:        movl    12(fp),r2               # r2:r3 = y
                    141:        movl    8(fp),r1
                    142:        movl    4(fp),r0                # r0:r1 = x
                    143:        andl3   $0xff800000,r0,r4
                    144:        cmpl    r4,$0x80000000          # is x a reserved operand?
                    145:        beql    1f                      # if yes then propagate x and return
                    146:        andl3   $0xff800000,r2,r4
                    147:        cmpl    r4,$0x80000000          # is y a reserved operand?
                    148:        bneq    2f
                    149:        movl    r3,r1
                    150:        movl    r2,r0                   # if yes then propagate y and return
                    151: 1:     ret
                    152: 
                    153: 2:     tstl    r4                      # is y a 0?
                    154:        bneq    3f
                    155:        pushl   $EDOM                   # if so then generate reserved op fault
                    156:        callf   $8,_infnan
                    157:        ret
                    158: 
                    159: 3:     andl2   $0x7fffffff,r2          # r2:r3 = y <- |y|
                    160:        clrl    r12                     # r12 = nx := 0
                    161:        cmpl    r2,$0x1c800000          # Ey ? 57 
                    162:        bgtr    4f                      # if Ey > 57 goto 4
                    163:        addl2   $0x1c800000,r2          # scale up y by 2**57
                    164:        movl    $0x1c800000,r12         # r12[b23:b30] = nx = 57
                    165: 4:     pushl   r12                     # pushed onto stack: nf := nx
                    166:        andl3   $0x80000000,r0,-(sp)    # pushed onto stack: sign of x
                    167:        andl2   $0x7fffffff,r0          # r0:r1 = x <- |x|
                    168:        movl    r3,r11                  # r10:r11 = y1 = y w/ last 27 bits 0
                    169:        andl3   $0xf8000000,r10,r11     # clear last 27 bits of y1
                    170: 
                    171: Loop:  cmpd2   r0,r2                   # x ? y
                    172:        bleq    6f                      # if x <= y goto 6
                    173:  /*                                    # begin argument reduction */
                    174:        movl    r3,r5
                    175:        movl    r2,r4                   # r4:r5 = t = y
                    176:        movl    r11,r7
                    177:        movl    r10,r6                  # r6:r7 = t1 = y1
                    178:        andl3   $0x7f800000,r0,r8       # r8[b23:b30] = Ex:biased exponent of x
                    179:        andl3   $0x7f800000,r2,r9       # r9[b23:b30] = Ey:biased exponent of y
                    180:        subl2   r9,r8                   # r8[b23:b30] = Ex-Ey
                    181:        subl2   $0x0c800000,r8          # r8[b23:b30] = k = Ex-Ey-25
                    182:        blss    5f                      # if k < 0 goto 5
                    183:        addl2   r8,r4                   # t += k        
                    184:        addl2   r8,r6                   # t1 += k, scale up t and t1
                    185: 5:     ldd     r0                      # acc = x
                    186:        divd    r4                      # acc = x/t
                    187:        cvdl    r8                      # r8 = n = [x/t] truncated
                    188:        cvld    r8                      # acc = dble(n)
                    189:        std     r8                      # r8:r9 = dble(n)
                    190:        ldd     r4                      # acc = t
                    191:        subd    r6                      # acc = t-t1
                    192:        muld    r8                      # acc = n*(t-t1)
                    193:        std     r4                      # r4:r5 = n*(t-t1)
                    194:        ldd     r6                      # acc = t1
                    195:        muld    r8                      # acc = n*t1
                    196:        subd    r0                      # acc = n*t1-x
                    197:        negd                            # acc = x-n*t1
                    198:        subd    r4                      # acc = (x-n*t1)-n*(t-t1)
                    199:        std     r0                      # r0:r1 = (x-n*t1)-n*(t-t1)
                    200:        brb     Loop
                    201: 
                    202: 6:     movl    r12,r6                  # r6 = nx
                    203:        beql    7f                      # if nx == 0 goto 7
                    204:        addl2   r6,r0                   # x <- x*2**57:scale x up by nx
                    205:        clrl    r12                     # clear nx
                    206:        brb     Loop
                    207: 
                    208: 7:     movl    r3,r5
                    209:        movl    r2,r4                   # r4:r5 = y
                    210:        subl2   $0x800000,r4            # r4:r5 = y/2
                    211:        cmpd2   r0,r4                   # x ? y/2
                    212:        blss    9f                      # if x < y/2 goto 9
                    213:        bgtr    8f                      # if x > y/2 goto 8
                    214:        ldd     r8                      # acc = dble(n)
                    215:        cvdl    r8                      # r8 = ifix(dble(n))
                    216:        bbc     $0,r8,9f                # if the last bit is zero, goto 9
                    217: 8:     ldd     r0                      # acc = x
                    218:        subd    r2                      # acc = x-y
                    219:        std     r0                      # r0:r1 = x-y
                    220: 9:     xorl2   (sp)+,r0                # x^sign (exclusive or)
                    221:        movl    (sp)+,r6                # r6 = nf
                    222:        andl3   $0x7f800000,r0,r8       # r8 = biased exponent of x
                    223:        andl2   $0x807fffff,r0          # r0 = x w/ exponent zapped
                    224:        subl2   r6,r8                   # r8 = Ex-nf
                    225:        bgtr    0f                      # if Ex-nf > 0 goto 0
                    226:        clrl    r8                      # clear r8
                    227:        clrl    r0
                    228:        clrl    r1                      # x underflows to zero
                    229: 0:     orl2    r8,r0                   # put r8 into x's exponent field
                    230:        ret

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.