1: #ifdef LIBC_SCCS
   2:         .asciz  "@(#)udiv.s	5.2 (Berkeley) 3/9/86"
   3: #endif LIBC_SCCS
   4: 
   5: /*
   6:  * udiv - unsigned division for vax-11
   7:  *
   8:  * arguments: dividend, divisor.
   9:  * result: quotient.
  10:  * uses r0-r2
  11:  *
  12:  * If 1 < divisor <= 2147483647, zero-extend the dividend
  13:  * to 64 bits and let ediv do the work.  If the divisor is 1,
  14:  * ediv will overflow if bit 31 of the dividend is on, so
  15:  * just return the dividend unchanged.  If the divisor is 0,
  16:  * do the ediv also, so it will generate the proper exception.
  17:  * All other values of the divisor have bit 31 on: in this case
  18:  * the quotient must be 0 if divisor > dividend, and 1 otherwise,
  19:  * provided that the comparison is made as unsigned.
  20:  */
  21: 
  22: #include "DEFS.h"
  23: 
  24: ASENTRY(udiv, 0)
  25:         movl    4(ap),r0        /* dividend */
  26:         movl    8(ap),r2        /* divisor */
  27:         jeql    1f              /* if divisor=0, force exception */
  28:         cmpl    r2,$1           /* if divisor <= 1 (signed), */
  29:         jleq    2f              /*  no division is necessary */
  30: 1:
  31:         clrl    r1              /* zero-extend the dividend */
  32:         ediv    r2,r0,r0,r2     /* divide.  q->r0, r->r2 (discarded) */
  33:         ret
  34: 2:
  35:         jeql    1f              /* if divisor=1, return dividend */
  36:         cmpl    r0,r2           /* unsigned comparison between */
  37:         jgequ   2f              /*  dividend and divisor */
  38:         clrl    r0              /* dividend < divisor, return 0 */
  39:         ret
  40: 2:
  41:         movl    $1,r0           /* dividend >= divisor, return 1 */
  42: 1:
  43:         ret
  44: 
  45: /*
  46:  * audiv - unsigned division for vax-11
  47:  *
  48:  * arguments: *dividend, divisor.
  49:  * result: quotient in r0 and *dividend.
  50:  * uses r0-r2
  51:  */
  52: 
  53: #include "DEFS.h"
  54: 
  55: ASENTRY(audiv, 0)
  56:         movl    *4(ap),r0       /* dividend */
  57:         movl    8(ap),r2        /* divisor */
  58:         jeql    1f              /* if divisor=0, force exception */
  59:         cmpl    r2,$1           /* if divisor <= 1 (signed), */
  60:         jleq    2f              /*  no division is necessary */
  61: 1:
  62:         clrl    r1              /* zero-extend the dividend */
  63:         ediv    r2,r0,r0,r2     /* divide.  q->r0, r->r2 (discarded) */
  64:         movl    r0,*4(ap)       /* save result */
  65:         ret
  66: 2:
  67:         jeql    1f              /* if divisor=1, return dividend */
  68:         cmpl    r0,r2           /* unsigned comparison between */
  69:         jgequ   2f              /*  dividend and divisor */
  70:         clrl    r0              /* dividend < divisor, return 0 */
  71:         clrl    *4(ap)          /* save result */
  72:         ret
  73: 2:
  74:         movl    $1,r0           /* dividend >= divisor, return 1 */
  75: 1:
  76:         movl    r0,*4(ap)       /* save result */
  77:         ret

Defined functions

audiv defined in line 55; never used
udiv defined in line 24; never used
Last modified: 1986-03-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 731
Valid CSS Valid XHTML 1.0 Strict