! ! Code for Sun 4 ! ! NOTE: for the Sun 4 base and number of bits are hardwired in the code. base = 1073741824 bits = 30 mask = base-1 .text ! ! routine to compute (a + b*c) mod base (d) ! (a + b*c) / base (e) ! Note: a, b and c are all < base, a and c may be negative. ! If (a + b*c) < 0 the remainder is positive ! ! C call sequence: ! mxmul(a,b,c,d,e) int a,b,c,*d,*e; ! .globl mxmul mxmul: orcc %o2,%g0,%g1 ! if c positive bge mxmul1 ! goto common code mov %o1,%y ! and multiplier to y register sub %g0,%o2,%o2 ! negate multiplicand sub %g0,%o0,%o0 ! and previous carry mxmul1: addcc %o0,%o0,%o0 ! put sign bit in carry bit nop ! delay for carry bit to settle mulscc %o0,%o2,%o0 ! step 1 mulscc %o0,%o2,%o0 ! step 2 mulscc %o0,%o2,%o0 ! step 3 mulscc %o0,%o2,%o0 ! step 4 mulscc %o0,%o2,%o0 ! step 5 mulscc %o0,%o2,%o0 ! step 6 mulscc %o0,%o2,%o0 ! step 7 mulscc %o0,%o2,%o0 ! step 8 mulscc %o0,%o2,%o0 ! step 9 mulscc %o0,%o2,%o0 ! step 10 mulscc %o0,%o2,%o0 ! step 11 mulscc %o0,%o2,%o0 ! step 12 mulscc %o0,%o2,%o0 ! step 13 mulscc %o0,%o2,%o0 ! step 14 mulscc %o0,%o2,%o0 ! step 15 mulscc %o0,%o2,%o0 ! step 16 mulscc %o0,%o2,%o0 ! step 17 mulscc %o0,%o2,%o0 ! step 18 mulscc %o0,%o2,%o0 ! step 19 mulscc %o0,%o2,%o0 ! step 20 mulscc %o0,%o2,%o0 ! step 21 mulscc %o0,%o2,%o0 ! step 22 mulscc %o0,%o2,%o0 ! step 23 mulscc %o0,%o2,%o0 ! step 24 mulscc %o0,%o2,%o0 ! step 25 mulscc %o0,%o2,%o0 ! step 26 mulscc %o0,%o2,%o0 ! step 27 mulscc %o0,%o2,%o0 ! step 28 mulscc %o0,%o2,%o0 ! step 29 mulscc %o0,%o2,%o0 ! step 30 mulscc %o0,%g0,%o0 ! align results addcc %g1,%g0,%g0 ! test sign bge mxmul22 ! branch if positive rd %y,%o1 ! and get low order part subcc %g0,%o1,%o1 ! negate low order part bcs mxmul22 ! jump if no borrow xnor %o0,%g0,%o0 ! and complement high order part add %o0,1,%o0 ! add one for borrow mxmul22: st %o0,[%o4] ! store high order part in e srl %o1,32-bits,%o1 ! position low order part retl st %o1,[%o3] ! store in d ! ! routine to compute (a*base + b) mod c (d) ! (a*base + b) / c (e) ! Note: a < c, 0 <= a,b,c < base ! ! C call sequence: ! mxdiv(a,b,c,d,e) int a,b,c,*d,*e; ! .globl mxdiv mxdiv: sll %o1,32-bits,%o1 ! position b mov %g0,%g1 ! clear quotient ! step 1 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv1 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv1: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv2 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv2: ! step 2 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv3 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv3: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv4 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv4: ! step 3 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv5 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv5: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv6 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv6: ! step 4 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv7 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv7: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv8 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv8: ! step 5 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv9 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv9: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv10 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv10:! step 6 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv11 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv11: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv12 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv12:! step 7 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv13 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv13: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv14 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv14:! step 8 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv15 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv15: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv16 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv16:! step 9 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv17 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv17: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv18 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv18:! step 10 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv19 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv19: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv20 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv20:! step 11 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv21 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv21: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv22 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv22:! step 12 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv23 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv23: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv24 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv24:! step 13 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv25 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv25: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv26 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv26:! step 14 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv27 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv27: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv28 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv28:! step 15 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv29 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv29: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv30 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv30:! step 16 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv31 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv31: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv32 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv32:! step 17 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv33 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv33: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv34 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv34:! step 18 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv35 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv35: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv36 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv36:! step 19 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv37 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv37: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv38 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv38:! step 20 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv39 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv39: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv40 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv40:! step 21 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv41 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv41: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv42 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv42:! step 22 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv43 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv43: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv44 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv44:! step 23 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv45 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv45: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv46 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv46:! step 24 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv47 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv47: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv48 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv48:! step 25 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv49 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv49: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv50 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv50:! step 26 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv51 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv51: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv52 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv52:! step 27 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv53 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv53: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv54 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv54:! step 28 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv55 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv55: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv56 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv56:! step 29 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv57 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv57: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv58 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv58:! step 30 addcc %o1,%o1,%o1 ! shift and get sign bit bcc mxdiv59 ! if no bit jump sll %o0,1,%o0 ! and position high order add %o0,1,%o0 ! add one to high order mxdiv59: cmp %o0,%o2 ! compare dividend and divisor blt mxdiv60 ! if less, skip sll %g1,1,%g1 ! and position quotient sub %o0,%o2,%o0 ! subtract divisor add %g1,1,%g1 ! and add one to quotient mxdiv60: st %o0,[%o3] ! store remainder in d retl st %g1,[%o4] ! and quotient in e