1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 #define halt .long 0
49
50
51
52
53 #define mask $0
54 #define divisor $1
55 #define compare $28
56
57 #ifdef DIV
58 #define func(x) __div##x
59 #define modulus $2
60 #define quotient $27
61 #else
62 #define func(x) __rem##x
63 #define modulus $27
64 #define quotient $2
65 #endif
66
67
68
69
70 #ifdef INTSIZE
71 #define ufunction func(lu)
72 #define sfunction func(l)
73 #define LONGIFY(x) zapnot x,15,x
74 #define SLONGIFY(x) addl x,0,x
75 #else
76 #define ufunction func(qu)
77 #define sfunction func(q)
78 #define LONGIFY(x)
79 #define SLONGIFY(x)
80 #endif
81
82 .set noat
83 .globl ufunction
84 .ent ufunction
85 ufunction:
86 subq $30,32,$30
87 stq $0, 0($30)
88 stq $1, 8($30)
89 stq $2,16($30)
90
91 bis $25,$25,divisor
92 bis $24,$24,modulus
93 bis $31,$31,quotient
94 LONGIFY(divisor)
95 LONGIFY(modulus)
96 beq divisor, 9f
97 bis $31,1,mask
98
99
100 1: cmpult divisor,modulus,compare
101 blt divisor, 3f
102 addq divisor,divisor,divisor
103 addq mask,mask,mask
104 bne compare,1b
105
106
107 2: srl divisor,1,divisor
108 beq mask,9f
109 srl mask,1,mask
110 3: cmpule divisor,modulus,compare
111 beq compare,2b
112 addq quotient,mask,quotient
113 beq mask,9f
114 subq modulus,divisor,modulus
115 br 2b
116
117 9: ldq $0, 0($30)
118 ldq $1, 8($30)
119 ldq $2, 16($30)
120 addq $30,32,$30
121 ret $31,($23),1
122 .end ufunction
123
124
125
126
127
128
129 .globl sfunction
130 .ent sfunction
131 sfunction:
132 bis $24,$25,$28
133 SLONGIFY($28)
134 bge $28,ufunction
135 halt
136 .end sfunction