home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / div.cpp < prev    next >
C/C++ Source or Header  |  1992-06-01  |  835b  |  41 lines

  1. /*
  2.  * semi efficient div and ldiv using gcc struct return conventions
  3.  *    this efficiency is desirable.
  4.  *
  5.  *  NOTE: *not* suitable for use with -fpcc-struct-return option
  6.  *      for the (slightly) more portable coding, see div.c
  7.  *
  8.  *    ++jrb    bammi@dsrgsun.ces.cwru.edu
  9.  */
  10.  
  11. #ifdef __MSHORT__
  12. /*
  13.  * div_t div(int num, int denom)
  14.  */
  15.     .text
  16.     .even
  17.     .globl    _div
  18. _div:
  19.     movw    sp@(4),d0   | num
  20.     movw    sp@(6),d1   | denom
  21.     extl    d0
  22.     divs    d1,d0
  23.     swap    d0        
  24.     rts            | d0<31:16> = result.quot  d0<15:0> = result.rem
  25.  
  26. #else /* !__MSHORT__ */
  27.     .globl _div
  28. _div:            | div is same as ldiv when !__MSHORT__
  29. #endif
  30.  
  31. /*
  32.  * ldiv_t ldiv(long num, long denom)
  33.  */
  34.     .globl    _ldiv
  35. _ldiv:
  36.     movl    sp@(8),sp@-    | push denom
  37.     movl    sp@(8),sp@-    | push num
  38.     jbsr    ___divsi3    | returns quo in d0.l and rem in d1.l
  39.     addqw    #8,sp        | which is how we want it (see fixnum.s)
  40.     rts
  41.