root/arch/h8300/lib/modsi3.S

/* [<][>][^][v][top][bottom][index][help] */
   1 /* SPDX-License-Identifier: GPL-2.0 */
   2 #include "libgcc.h"
   3 
   4 ; numerator in A0/A1
   5 ; denominator in A2/A3
   6         .global __modsi3
   7 __modsi3:
   8         PUSHP   S2P
   9         bsr     modnorm
  10         bsr     __divsi3
  11         mov.l   er3,er0
  12         bra     exitdiv
  13 
  14         .global __umodsi3
  15 __umodsi3:
  16         bsr     __udivsi3
  17         mov.l   er3,er0
  18         rts
  19 
  20         .global __divsi3
  21 __divsi3:
  22         PUSHP   S2P
  23         jsr     divnorm
  24         bsr     __udivsi3
  25 
  26         ; examine what the sign should be
  27 exitdiv:
  28         btst    #3,S2L
  29         beq     reti
  30 
  31         ; should be -ve
  32         neg.l   A0P
  33 
  34 reti:
  35         POPP    S2P
  36         rts
  37 
  38 divnorm:
  39         mov.l   A0P,A0P         ; is the numerator -ve
  40         stc     ccr,S2L         ; keep the sign in bit 3 of S2L
  41         bge     postive
  42 
  43         neg.l   A0P             ; negate arg
  44 
  45 postive:
  46         mov.l   A1P,A1P         ; is the denominator -ve
  47         bge     postive2
  48 
  49         neg.l   A1P             ; negate arg
  50         xor.b   #0x08,S2L       ; toggle the result sign
  51 
  52 postive2:
  53         rts
  54 
  55 ;; Basically the same, except that the sign of the divisor determines
  56 ;; the sign.
  57 modnorm:
  58         mov.l   A0P,A0P         ; is the numerator -ve
  59         stc     ccr,S2L         ; keep the sign in bit 3 of S2L
  60         bge     mpostive
  61 
  62         neg.l   A0P             ; negate arg
  63 
  64 mpostive:
  65         mov.l   A1P,A1P         ; is the denominator -ve
  66         bge     mpostive2
  67 
  68         neg.l   A1P             ; negate arg
  69 
  70 mpostive2:
  71         rts
  72 
  73         .end

/* [<][>][^][v][top][bottom][index][help] */