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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
|
/* Assembly support functions for libgcc1.
*
* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
* Contributed by Cygnus Support
*
* This file is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* In addition to the permissions in the GNU General Public License, the
* Free Software Foundation gives you unlimited permission to link the
* compiled version of this file with other programs, and to distribute
* those programs without any restriction coming from the use of this
* file. (The General Public License restrictions do apply in other
* respects; for example, they cover modification of the file, and
* distribution when not linked into another program.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* As a special exception, if you link this library with files
* compiled with GCC to produce an executable, this does not cause
* the resulting executable to be covered by the GNU General Public License.
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*/
#ifdef L_ashlsi3
/* Shift of 32 bit int left, r0-r1 == value to be shifted, r2 = shift amount */
.file "_ashlsi3.s"
.text
.globl __ashlsi3
.type __ashlsi3,@function
__ashlsi3:
mv2wfac r4,a0 /* preserve accumulator & guard digits */
mvfacg r12,a0
mv2wtac r0,a0
cmpui r2,16
and3 r0,r2,15
exef0f || slli a0,16
sll a0,r0
mv2wfac r0,a0
mv2wtac r4,a0
mvtacg r12,a0
jmp r13
.size __ashlsi3,.-__ashlsi3
#endif
#ifdef L_ashrsi3
/* Shift of 32 bit signed int right, r0-r1 == value to be shifted, r2 = shift amount */
.file "_ashrsi3.s"
.text
.globl __ashrsi3
.type __ashrsi3,@function
__ashrsi3:
mv2wfac r4,a0 /* preserve accumulator & guard digits */
mvfacg r12,a0
mv2wtac r0,a0
cmpui r2,16
and3 r0,r2,15
exef0f || srai a0,16
sra a0,r0
mv2wfac r0,a0
mv2wtac r4,a0
mvtacg r12,a0
jmp r13
.size __ashrsi3,.-__ashrsi3
#endif
#ifdef L_lshrsi3
/* Shift of 32 bit unsigned int right, r0-r1 == value to be shifted, r2 = shift amount */
.file "_lshrsi3.s"
.text
.globl __lshrsi3
.type __lshrsi3,@function
__lshrsi3:
mv2wfac r4,a0 /* preserve accumulator & guard digits */
mvfacg r12,a0
mv2wtac r0,a0
mvtacg r14,a0 /* zero guard digits */
cmpui r2,16
and3 r0,r2,15
exef0f || srli a0,16
srl a0,r0
mv2wfac r0,a0
mv2wtac r4,a0
mvtacg r12,a0
jmp r13
.size __lshrsi3,.-__lshrsi3
#endif
#ifdef L_mulsi3
/* Multiply 2 32-bit signed integers with a 32-bit result, r0-r1 = first number,
r2-r3 = second number. */
.file "_mulsi3.s"
.text
.globl __mulsi3
.type __mulsi3,@function
__mulsi3:
mv2wfac r4,a0 /* preserve accumulator & guard digits */
mvfacg r12,a0
mulxu a0,r0,r3
macu a0,r1,r2
slli a0,16
macu a0,r1,r3
mv2wfac r0,a0
mv2wtac r4,a0
mvtacg r12,a0
jmp r13
.size __mulsi3,.-__mulsi3
#endif
#ifdef L_udivmodhi4
/* Unsigned divide 2 16-bit numbers, leaving the remainder in r0, and quotient
in r1. */
.file "_udivmodhi4.s"
.text
.globl __udivmodhi4
.type __udivmodhi4,@function
.globl __umodhi3
.type __umodhi3,@function
__udivmodhi4:
__umodhi3:
mv r2,r1 -> mv r1,r0 /* move divisor to safe register & create 32-bit value for dividend */
ldi r0,0 /* high part of dividend */
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
jmp r13
.size __udivmodhi4,.-__udivmodhi4
.size __umodhi3,.-__umodhi3
.globl __udivhi3
.type __udivhi3,@function
__udivhi3:
st r13,@-sp
bl __udivmodhi4
mv r0,r1
ld r13,@sp+
jmp r13
.size __udivhi3,.-__udivhi3
#endif
#ifdef L_divmodhi4
/* Signed divide 2 16-bit numbers, leaving the remainder in r0, and quotient
in r1. */
.file "_divmodhi4.s"
.text
.globl __divmodhi4
.type __divmodhi4,@function
.globl __modhi3
.type __modhi3,@function
__divmodhi4:
__modhi3:
mv r2,r1 -> mv r1,r0 /* move divisor to safe register & create 32-bit value for dividend */
ldi r0,0 || abs r1 /* high part of dividend */
abs r2 || nop /* make sure divisor & dividend are positive (F0/F1 indicate if args were negative) */
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
divs r0,r2
exef1t || neg r0
exef0t || neg r1
exef1t || neg r1
jmp r13
.size __divmodhi4,.-__divmodhi4
.size __modhi3,.-__modhi3
.globl __divhi3
.type __divhi3,@function
__divhi3:
st r13,@-sp
bl __divmodhi4
mv r0,r1
ld r13,@sp+
jmp r13
.size __divhi3,.-__divhi3
#endif
#ifdef L_udivmodsi4
/* Unsigned divide 2 32-bit numbers, leaving the remainder in r0-r1, and quotient
in r2-r3. */
.file "_udivmodsi4.s"
.text
.globl __udivmodsi4
.type __udivmodsi4,@function
.globl __udivsi3
.type __udivsi3,@function
/* input: r0-r1 = dividend, r2-r3 = divisor */
/* output: r0-r1 = quotient, r2-r3 = remainder */
__udivmodsi4:
__udivsi3:
cmpeqi r0,0 -> brf0f.s .Llong /* if we are doing short/short do it with divs */
cmpeqi r2,0 -> brf0f.s .Llong
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
divs r0,r3
mv r3,r0
ldi r0,0
jmp r13
.Llong:
st2w r6,@-sp
st2w r8,@-sp
mv2w r4,r2 /* divisor (b) */
ldi r2,0 /* high part of dividend (ah) */
ldi r3,0
ldi r12,32 /* number of iterations */
.Lloop:
mv2w r6,r2 /* tmp1 = (ah << 1) | (al >> 31) */
add2w r6,r6
cmpi r0,0
exef0t || addi r7,1
mv2w r8,r6 /* tmp2 = tmp1 - b */
sub2w r8,r4
cmpeq r6,r4 /* tmpf = (tmp1 >= b), ie f0 = !(tmp1 < b) */
cmpu r6,r4
exef1t || cmpu r7,r5
mv2w r2,r6 /* ah = (tmpf) ? tmp1 : tmp2 */
exef0f || mv2w r2,r8
add2w r0,r0 /* al = (al << 1) | tmpf */
exef0f || addi r1,1
subi r12,1 /* decrement and loop */
cmpeqi r12,0
brf0f.s .Lloop /* work around simulator bug with .s version of brf0f */
ld2w r8,@sp+
ld2w r6,@sp+
jmp r13
.size __udivmodsi4,.-__udivmodsi4
.size __udivsi3,.-__udivsi3
.globl __umodsi3
.type __umodsi3,@function
__umodsi3:
st r13,@-sp
bl __udivmodsi4
mv2w r0,r2
ld r13,@sp+
jmp r13
.size __modvsi3,.-__modvsi3
#endif
#ifdef L_divmodsi4
/* Signed divide 2 32-bit numbers, leaving the remainder in r0-r1, and quotient
in r2-r3. */
.file "_divmodsi4.s"
.text
.globl __divmodsi4
.type __divmodsi4,@function
.globl __divsi3
.type __divsi3,@function
__divmodsi4:
__divsi3:
cmpi r0,0 /* divisor negative? */
brf0t.s .Lneg1
cmpi r2,0 /* dividend negative? */
brf0t.s .Lneg3
bra __udivmodsi4 /* both positive, just do division, __udivmodsi4 will return to caller */
.Lneg1: /* divisor negative, dividend sign not yet checked */
st r13,@-sp
not r0 /* negate divisor */
neg r1
cmpeqi r1,0
exef0t || addi r0,1
cmpi r2,0 /* dividend negative? */
brf0t.s .Lneg2
bl __udivmodsi4 /* do division */
not r0 /* negate quotient */
neg r1
cmpeqi r1,0
exef0t || addi r0,1
not r2 /* negate remainder */
neg r3
cmpeqi r3,0
exef0t || addi r2,1
ld r13,@sp+
jmp r13
.Lneg2: /* divisor & dividend negative */
not r2 /* negate dividend */
neg r3
cmpeqi r3,0
exef0t || addi r2,1
bl __udivmodsi4 /* do division */
not r2 /* negate remainder */
neg r3
cmpeqi r3,0
exef0t || addi r2,1
ld r13,@sp+
jmp r13
.Lneg3: /* divisor positive, dividend negative */
st r13,@-sp
not r2 /* negate dividend */
neg r3
cmpeqi r3,0
exef0t || addi r2,1
bl __udivmodsi4 /* do division */
not r0 /* negate quotient */
neg r1
cmpeqi r1,0
exef0t || addi r0,1
ld r13,@sp+
jmp r13
.size __divmodsi4,.-__divmodsi4
.size __divsi3,.-__divsi3
.globl __modsi3
.type __modsi3,@function
__modsi3:
st r13,@-sp
bl __divmodsi4
mv2w r0,r2
ld r13,@sp+
jmp r13
.size __modsi3,.-__modsi3
#endif
#ifdef L_cmpdi
/* Signed compare 2 64-bit ints */
.file "__cmpdi.s"
.text
.globl __cmpdi
.type __cmpdi,@function
/* input: r0-r3 is first value to compare, second value to compare on stack */
/* output: r0 is 0 if op0 < op1, 1 if op0 == op1, 2 if op0 > op1 */
__cmpdi:
ld2w r4,@sp /* compare first word */
cmp r0,r4
brf0t.s .Lneg
cmp r4,r0
brf0t.s .Lpos
cmpu r1,r5 /* compare second word */
brf0t.s .Lneg
cmpu r5,r1
brf0t.s .Lpos
ld2w r4,@(4,sp) /* compare third word */
cmpu r2,r4
brf0t.s .Lneg
cmpu r4,r2
brf0t.s .Lpos
cmpu r3,r5 /* compare fourth word */
brf0t.s .Lneg
cmpu r5,r3
brf0t.s .Lpos
ldi r0,1 /* op1 == op2 */
jmp r13
.Lneg:
ldi r0,0 /* op1 < op2 */
jmp r13
.Lpos:
ldi r0,2 /* op1 > op2 */
jmp r13
.size __cmpdi,.-__cmpdi
#endif
#ifdef L_cmpdi0
/* Signed compare 64-bit int against 0 */
.file "__cmpdi0.s"
.text
.globl __cmpdi0
.type __cmpdi0,@function
/* input: r0-r3 is value to compare */
/* output: r0 is -1 if op0 < 0, 0 if op0 == 0, 1 if op0 > 0 */
__cmpdi0:
cmpi r0,0 /* compare first word */
brf0t.s .Lneg
cmpeqi r0,0
brf0f.s .Lpos
cmpeqi r1,0 /* compare second word */
brf0f.s .Lpos
cmpeqi r2,0 /* compare third word */
brf0f.s .Lpos
cmpeqi r3,0 /* compare fourth word */
brf0f.s .Lpos
ldi r0,1 /* op1 == 0 */
jmp r13
.Lneg:
ldi r0,0 /* op1 < 0 */
jmp r13
.Lpos:
ldi r0,2 /* op1 > 0 */
jmp r13
.size __cmpdi0,.-__cmpdi0
#endif
#ifdef L_ucmpdi
/* Unsigned compare 2 64-bit ints */
.file "__ucmpdi.s"
.text
.globl __ucmpdi
.type __ucmpdi,@function
/* input: r0-r3 is first value to compare, second value to compare on stack */
/* output: r0 is -1 if (unsigned)op0 < (unsigned)op1, 0 if op0 == op1, 1 if (unsigned)op0 > (unsigned)op1 */
__ucmpdi:
ld2w r4,@sp /* compare first word */
cmpu r0,r4
brf0t.s .Lneg
cmpu r4,r0
brf0t.s .Lpos
cmpu r1,r5 /* compare second word */
brf0t.s .Lneg
cmpu r5,r1
brf0t.s .Lpos
ld2w r4,@(4,sp) /* compare third word */
cmpu r2,r4
brf0t.s .Lneg
cmpu r4,r2
brf0t.s .Lpos
cmpu r3,r5 /* compare fourth word */
brf0t.s .Lneg
cmpu r5,r3
brf0t.s .Lpos
ldi r0,1 /* op1 == op2 */
jmp r13
.Lneg:
ldi r0,0 /* op1 < op2 */
jmp r13
.Lpos:
ldi r0,2 /* op1 > op2 */
jmp r13
.size __ucmpdi,.-__ucmpdi
#endif
#ifdef L_ucmpdi0
/* Unsigned compare 64-bit int against 0 */
.file "__ucmpdi0.s"
.text
.globl __ucmpdi0
.type __ucmpdi0,@function
/* input: r0-r3 is value to compare */
/* output: r0 is 0 if op0 == 0, 1 if op0 > 0 */
__ucmpdi0:
cmpeqi r0,0 /* compare first word */
brf0f.s .Lpos
cmpeqi r1,0 /* compare second word */
brf0f.s .Lpos
cmpeqi r2,0 /* compare third word */
brf0f.s .Lpos
cmpeqi r3,0 /* compare fourth word */
brf0f.s .Lpos
ldi r0,1 /* op1 == 0 */
jmp r13
.Lpos:
ldi r0,2 /* op1 > 0 */
jmp r13
.size __ucmpdi0,.-__ucmpdi0
#endif
|