BSD 4 release
[unix-history] / usr / src / cmd / px / 28fun.s
index 3ff093a..51d64d5 100644 (file)
@@ -1,5 +1,7 @@
 #\f
 #\f
-# 28fun.s
+# Copyright (c) 1979 Regents of the University of California
+#
+# char sccsid[] = "@(#)28fun.s 4.1 10/10/80";
 #
 # BUILT IN FUNCTIONS
 #
 #
 # BUILT IN FUNCTIONS
 #
@@ -19,13 +21,12 @@ _ARGC:
 _ARGV:
        cvtbl   (r10)+,r2
        bneq    l2801
 _ARGV:
        cvtbl   (r10)+,r2
        bneq    l2801
-       cvtwl   (r10)+,r2               #r2 has size of character array
+       movzwl  (r10)+,r2               #r2 has size of character array
 l2801:
        movl    (sp)+,r3                #r3 has addr of character array
 l2801:
        movl    (sp)+,r3                #r3 has addr of character array
-       cvtwl   (sp)+,r4                #r4 has subscript into argv
-       blss    eargv
+       movl    (sp)+,r4                #r4 has subscript into argv
        cmpl    r4,_argc
        cmpl    r4,_argc
-       bgeq    eargv
+       bgequ   eargv
        movl    *_argv[r4],r4           #r4 has pointer to argv string
        locc    $0,r2,(r4)              #find end of string
        subl3   r0,r2,r0                #calculate actual string length
        movl    *_argv[r4],r4           #r4 has pointer to argv string
        locc    $0,r2,(r4)              #find end of string
        subl3   r0,r2,r0                #calculate actual string length
@@ -40,21 +41,19 @@ _WCLCK:
        calls   $1,_time
        jmp     (r8)
 _SCLCK:
        calls   $1,_time
        jmp     (r8)
 _SCLCK:
-       cvtbl   $1,r2
+       cvtbl   $1,r6
        brb     l2805
 _CLCK:
        brb     l2805
 _CLCK:
-       clrl    r2
+       clrl    r6
 l2805:
        incl    r10
        subl2   $16,sp
        pushl   sp
        calls   $1,_times
 l2805:
        incl    r10
        subl2   $16,sp
        pushl   sp
        calls   $1,_times
-       movl    (sp)[r2],r0
+       movl    (sp)[r6],r0
        addl2   $16,sp
        addl2   $16,sp
-       mull2   $1000,r0
-       cvtld   r0,r0
-       divd2   $HZ,r0
-       cvtdl   r0,-(sp)
+       mull2   $50,r0          #(60ths * 1000) / 60
+       divl3   $3,r0,-(sp)     # == (60ths * 50) / 3
        jmp     (r8)
 _DATE:
        incl    r10
        jmp     (r8)
 _DATE:
        incl    r10
@@ -69,11 +68,12 @@ _TIME:
 _STLIM:
        incl    r10
        movl    (sp)+,_stlim
 _STLIM:
        incl    r10
        movl    (sp)+,_stlim
-       aoblss  _stlim,_stcnt,l2812
+       cmpl    _stcnt,_stlim
+       bgeq    l2812
+       jmp     (r8)
+l2812:
        movw    $ESTLIM,_perrno
        jbr     error
        movw    $ESTLIM,_perrno
        jbr     error
-l2812:
-       jmp     (r8)
 _SEED:
        incl    r10
        calls   $0,_srand
 _SEED:
        incl    r10
        calls   $0,_srand
@@ -82,26 +82,27 @@ _RANDOM:
        incl    r10
        calls   $0,_rand
        cvtld   r0,r1
        incl    r10
        calls   $0,_rand
        cvtld   r0,r1
-       divd2   maxint,r1
-       movd    r1,(sp)
+       divd3   $0d2.147483647e+09,r1,(sp)      #div by maxint to get 0..1
        jmp     (r8)
        jmp     (r8)
-maxint:
-       .double 0d2.147483647e+09
 _DISPOSE:
 _DISPOSE:
-       incl    r10
+       movzbl  (r10)+,r0       #r0 has size being disposed
+       bneq    l2813
+       movzwl  (r10)+,r0
+l2813:
        movl    (sp)+,r6        #r6 points to pointer
        pushl   (r6)            #fetch pointer value
        calls   $1,_pfree       #free space
        clrl    (r6)            #set pointer to nil
        jmp     (r8)
 _NEW:
        movl    (sp)+,r6        #r6 points to pointer
        pushl   (r6)            #fetch pointer value
        calls   $1,_pfree       #free space
        clrl    (r6)            #set pointer to nil
        jmp     (r8)
 _NEW:
-       movzbl  (r10)+,r0
+       movzbl  (r10)+,r6
        bneq    l2806
        bneq    l2806
-       movzwl  (r10)+,r0
+       movzwl  (r10)+,r6
 l2806:
 l2806:
-       pushl   r0
+       pushl   r6
        calls   $1,_palloc
        movl    r0,*(sp)+
        calls   $1,_palloc
        movl    r0,*(sp)+
+       movc5   $0,(r1),$0,r6,(r0)
        jmp     (r8)
 _EXPO:
        incl    r10
        jmp     (r8)
 _EXPO:
        incl    r10
@@ -155,54 +156,41 @@ esqrt:
        movw    $ESQRT,_perrno
        jbr     error
 _CHR2:
        movw    $ESQRT,_perrno
        jbr     error
 _CHR2:
+_CHR4:
        incl    r10
        incl    r10
-       movw    (sp),r0
-       blss    echr
-       cmpw    r0,$177
+       movl    (sp)+,r0
+       cmpl    r0,$0x7f
        bgtru   echr
        bgtru   echr
+       movw    r0,-(sp)
        jmp     (r8)
 echr:
        movw    $ECHR,_perrno
        jbr     error
        jmp     (r8)
 echr:
        movw    $ECHR,_perrno
        jbr     error
-_CHR4:
-       incl    r10
-       movl    (sp)+,r0
-       blss    echr
-       cmpl    r0,$177
-       bgtru   echr
-       movw    r0,-(sp)
-       jmp     (r8)
 _ODD4:
 _ODD4:
-       movw    (sp)+,(sp)
 _ODD2:
 _ODD2:
+       movw    (sp)+,(sp)
        incl    r10
        bicw2   $0xfffe,(sp)
        jmp     (r8)
 _PRED2:
        incl    r10
        incl    r10
        bicw2   $0xfffe,(sp)
        jmp     (r8)
 _PRED2:
        incl    r10
+       movw    (sp)+,(sp)
        decw    (sp)
        jmp     (r8)
 _PRED4:
        decw    (sp)
        jmp     (r8)
 _PRED4:
-       incl    r10
-       decl    (sp)
-       jmp     (r8)
 _PRED24:
        incl    r10
 _PRED24:
        incl    r10
-       cvtwl   (sp)+,r0
-       subl3   $1,r0,-(sp)
+       decl    (sp)
        jmp     (r8)
 _SUCC2:
        incl    r10
        jmp     (r8)
 _SUCC2:
        incl    r10
+       movw    (sp)+,(sp)
        incw    (sp)
        jmp     (r8)
 _SUCC4:
        incw    (sp)
        jmp     (r8)
 _SUCC4:
-       incl    r10
-       incl    (sp)
-       jmp     (r8)
 _SUCC24:
        incl    r10
 _SUCC24:
        incl    r10
-       cvtwl   (sp)+,r0
-       addl3   $1,r0,-(sp)
+       incl    (sp)
        jmp     (r8)
 _ROUND:
        incl    r10
        jmp     (r8)
 _ROUND:
        incl    r10
@@ -230,22 +218,27 @@ _UNDEF:
 #      1. i >= m
 #      2. i+(v-u) <= n         (i.e. i-m <= (n-m)-(v-u))
 #
 #      1. i >= m
 #      2. i+(v-u) <= n         (i.e. i-m <= (n-m)-(v-u))
 #
-# on stack:    lv(z), lv(a), rv(i) (len 2)
+# on stack:    lv(z), lv(a), rv(i) (len 4)
 #
 # move w(t)*(v-u+1) bytes from lv(a)+w(t)*(i-m) to lv(z)
 #
 _PACK:
        cvtbl   (r10)+,r0
        bneq    l2809
 #
 # move w(t)*(v-u+1) bytes from lv(a)+w(t)*(i-m) to lv(z)
 #
 _PACK:
        cvtbl   (r10)+,r0
        bneq    l2809
-       cvtwl   (r10)+,r0               #r0 has size of "a" types
+       movzwl  (r10)+,r0               #r0 has size of "a" types
 l2809:
        clrl    r1                      #r1 := subscript - lower_bound
        subw3   (r10)+,8(sp),r1
 l2809:
        clrl    r1                      #r1 := subscript - lower_bound
        subw3   (r10)+,8(sp),r1
-       cvtwl   (r10)+,r3               #r3 := high_bound
-       index   r1,$0,r3,r0,$0,r4       #r4 has index of "a"
-       movc3   (r10)+,*4(sp)[r4],*(sp) #make the move
-       addl2   $10,sp                  #clear the stack
-       jmp     (r8)
+       blss    epack
+       cmpw    r1,(r10)+               #check upper bound
+       bgtru   epack
+       mull2   r0,r1                   #r1 has byte offset
+       movc3   (r10)+,*4(sp)[r1],*(sp) #make the move
+       addl2   $12,sp                  #clear the stack
+       jmp     (r8)
+epack:
+       movw    $EPACK,_perrno
+       jbr     error
 #
 # unpack(z,a,i)
 #
 #
 # unpack(z,a,i)
 #
@@ -257,12 +250,17 @@ l2809:
 _UNPACK:
        cvtbl   (r10)+,r0
        bneq    l2810
 _UNPACK:
        cvtbl   (r10)+,r0
        bneq    l2810
-       cvtwl   (r10)+,r0               #r0 has size of "a" types
+       movzwl  (r10)+,r0               #r0 has size of "a" types
 l2810:
        clrl    r1                      #r1 := subscript - lower_bound
        subw3   (r10)+,8(sp),r1
 l2810:
        clrl    r1                      #r1 := subscript - lower_bound
        subw3   (r10)+,8(sp),r1
-       cvtwl   (r10)+,r3               #r3 := high_bound
-       index   r1,$0,r3,r0,$0,r4       #r4 has index of "a"
-       movc3   (r10)+,*(sp),*4(sp)[r4] #make the move
-       addl2   $10,sp                  #clear the stack
-       jmp     (r8)
+       blss    eunpack
+       cmpw    r1,(r10)+               #check upper bound
+       bgtru   eunpack
+       mull2   r0,r1                   #r1 has byte offset
+       movc3   (r10)+,*(sp),*4(sp)[r1] #make the move
+       addl2   $12,sp                  #clear the stack
+       jmp     (r8)
+eunpack:
+       movw    $EUNPACK,_perrno
+       jbr     error