aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/mn10200/lib1funcs.asm
blob: 90ae1beba8094c5300e58a0e85712186b94ba773 (plain)
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
/* libgcc routines for Matsushita mn10200.
   Copyright (C) 1997 Free Software Foundation, Inc.

This file is part of GNU CC.

GNU CC 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 into combinations with other programs,
and to distribute those combinations 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 a combine
executable.)

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.  */

#ifdef L_divhi3
	/* Derive signed division/modulo from unsigned "divu" instruction.  */
	.text
	.globl ___divhi3
	.type ___divhi3,@function
___divhi3:

	/* We're going to need some scratch registers, so save d2/d3
	   into the stack.  */
	add -8,a3
	movx d2,(0,a3)
	movx d3,(4,a3)

	/* Loading zeros into registers now allows us to use them
	   in the compare instructions, which saves a total of
	   two bytes (egad).  */
	sub d3,d3
	sub d2,d2
	sub a0,a0

	/* If first operand is negative, then make it positive.
	   It will be contained in d2 just before .L1. 

	   a0 tells us if the first operand was negated.  */
	cmp d2,d0
	bge .L0
	sub d0,d2
	mov 1,a0
	bra .L1
.L0:
	mov d0,d2
.L1:
	/* If the second operand is negative, then make it positive.
	   It will be contained in d3 just before .L3. 

	   d0 tells us if the second operand was negated.  */
	cmp d3,d1
	bge .L2
	sub d1,d3
	mov 1,d0
	bra .L3
.L2:
	sub d0,d0
	mov d1,d3
.L3:
	/* Loading d1 with zero here allows us to save one byte
	   in the comparison below.  */

	sub d1,d1

	/* Make sure to clear the mdr register, then do the unsigned
	   division.  Result will be in d2/mdr.  */
	mov d1,mdr
	divu d3,d2

	/* Negate the remainder based on the first argument negation
	   flag only.  */
	cmp d1,a0
	beq .L4
	mov mdr,d3
	sub d3,d1
	bra .L5
.L4:
	mov mdr,d1

.L5:
	/* Negate the result if either, but not both of the inputs
	   were negated.  */
	mov a0,d3
	xor d3,d0
	beq .L6
	sub d0,d0
	sub d2,d0
	bra .L7
.L6:
	mov d2,d0
.L7:
	
	/* Restore our scratch registers, deallocate our stack and return.  */
	movx (0,a3),d2
	movx (4,a3),d3
	add 8,a3
	rts
	.size ___divhi3,.-___divhi3
#endif

#ifdef L_modhi3
	.text
	.globl ___modhi3
	.type ___modhi3,@function
___modhi3:
	jsr ___divhi3
	mov d1,d0
	rts
	.size ___modhi3,.-___modhi3
#endif

#ifdef L_addsi3
	.text
	.globl ___addsi3
	.type  ___addsi3,@function
___addsi3:
	add -4,a3
	movx d2,(0,a3)
	mov (8,a3),d2
	add d2,d0
	mov (10,a3),d2
	addc d2,d1
	movx (0,a3),d2
	add 4,a3
	rts

	.size ___addsi3,.-___addsi3
#endif

#ifdef L_subsi3
	.text
	.globl ___subsi3
	.type  ___subsi3,@function
___subsi3:
	add -4,a3
	movx d2,(0,a3)
	mov (8,a3),d2
	sub d2,d0
	mov (10,a3),d2
	subc d2,d1
	movx (0,a3),d2
	add 4,a3
	rts

	.size ___subsi3,.-___subsi3
#endif

#ifdef L_mulsi3
	.text
	.globl ___mulsi3
	.type  ___mulsi3,@function
___mulsi3:
	add -4,a3
	mov a1,(0,a3)
	mov d0,a0
	/* Multiply arg0 msb with arg1 lsb.
	   arg0 msb is in register d1,
	   arg1 lsb is in memory.  */
	mov (8,a3),d0
	mulu d0,d1
	mov d1,a1

	/* Multiply arg0 lsb with arg1 msb.
	   arg0 msb is in register a0,
	   arg1 lsb is in memory.  */
	mov a0,d0
	mov (10,a3),d1
	mulu d0,d1

	/* Add the cross products.  */
	add d1,a1

	/* Now multiply arg0 lsb with arg1 lsb.  */
	mov (8,a3),d1
	mulu d1,d0

	/* Add in the upper 16 bits to the cross product sum.  */
	mov mdr,d1
	add a1,d1
	mov (0,a3),a1
	add 4,a3
	rts

	.size ___mulsi3,.-___mulsi3
#endif

#ifdef  L_ashlsi3
	.text
	.globl ___ashlsi3
	.type  ___ashlsi3,@function
___ashlsi3:
	mov (4,a3),a0
	cmp 0,a0
	beq .L0
.L1:
	add d0,d0
	addc d1,d1
	add -1,a0
	bne .L1
.L0:
	rts

	.size ___ashlsi3,.-___ashlsi3
#endif

#ifdef  L_lshrsi3
	.text
	.globl ___lshrsi3
	.type  ___lshrsi3,@function
___lshrsi3:
	mov (4,a3),a0
	cmp 0,a0
	beq .L0
.L1:
	lsr d1
	ror d0
	add -1,a0
	bne .L1
.L0:
	rts

	.size ___lshrsi3,.-___lshrsi3
#endif

#ifdef  L_ashrsi3
	.text
	.globl ___ashrsi3
	.type  ___ashrsi3,@function
___ashrsi3:
	mov (4,a3),a0
	cmp 0,a0
	beq .L0
.L1:
	asr d1
	ror d0
	add -1,a0
	bne .L1
.L0:
	rts

	.size ___ashrsi3,.-___ashrsi3
#endif

/* All functions beyond this point pass their arguments in registers! */
#ifdef  L_negsi2_d0
	.text
	.globl ___negsi2_d0
	.type  ___negsi2_d0,@function
___negsi2_d0:
	add -8,a3
	movx d3,(0,a3)
	movx d2,(4,a3)
	mov d0,d2
	mov d1,d3
	sub d0,d0
	sub d1,d1
	sub d2,d0
	subc d3,d1
	movx (0,a3),d3
	movx (4,a3),d2
	add 8,a3
	rts

	.size ___negsi2_d0,.-___negsi2_d0
#endif

#ifdef  L_negsi2_d2
	.text
	.globl ___negsi2_d2
	.type  ___negsi2_d2,@function
___negsi2_d2:
	add -8,a3
	movx d1,(0,a3)
	movx d0,(4,a3)
	mov d2,d0
	mov d3,d1
	sub d2,d2
	sub d3,d3
	sub d0,d2
	subc d1,d3
	movx (0,a3),d1
	movx (4,a3),d0
	add 8,a3
	rts

	.size ___negsi2_d2,.-___negsi2_d2
#endif

#ifdef  L_zero_extendpsisi2_d0
	.text
	.globl ___zero_extendpsisi2_d0
	.type  ___zero_extendpsisi2_d0,@function
___zero_extendpsisi2_d0:
	add -4,a3
	movx d0,(0,a3)
	movbu (2,a3),d1
	add 4,a3
	rts

	.size ___zero_extendpsisi2_d0,.-___zero_extendpsisi2_d0
#endif

#ifdef  L_zero_extendpsisi2_d2
	.text
	.globl ___zero_extendpsisi2_d2
	.type  ___zero_extendpsisi2_d2,@function
___zero_extendpsisi2_d2:
	add -4,a3
	movx d2,(0,a3)
	movbu (2,a3),d3
	add 4,a3
	rts

	.size ___zero_extendpsisi2_d2,.-___zero_extendpsisi2_d2
#endif

#ifdef  L_sign_extendpsisi2_d0
	.text
	.globl ___sign_extendpsisi2_d0
	.type  ___sign_extendpsisi2_d0,@function
___sign_extendpsisi2_d0:
	add -4,a3
	movx d0,(0,a3)
	movb (2,a3),d1
	add 4,a3
	rts

	.size ___sign_extendpsisi2_d0,.-___sign_extendpsisi2_d0
#endif

#ifdef  L_sign_extendpsisi2_d2
	.text
	.globl ___sign_extendpsisi2_d2
	.type  ___sign_extendpsisi2_d2,@function
___sign_extendpsisi2_d2:
	add -4,a3
	movx d2,(0,a3)
	movb (2,a3),d3
	add 4,a3
	rts

	.size ___sign_extendpsisi2_d2,.-___sign_extendpsisi2_d2
#endif

#ifdef  L_truncsipsi2_d0_d0
	.text
	.globl ___truncsipsi2_d0_d0
	.type  ___truncsipsi2_d0_d0,@function
___truncsipsi2_d0_d0:
	add -4,a3
	mov d0,(a3)
	mov d1,(2,a3)
	movx (0,a3),d0
	add 4,a3
	rts

	.size ___truncsipsi2_d0_d0,.-___truncsipsi2_d0_d0
#endif

#ifdef  L_truncsipsi2_d0_d1
	.text
	.globl ___truncsipsi2_d0_d1
	.type  ___truncsipsi2_d0_d1,@function
___truncsipsi2_d0_d1:
	add -4,a3
	mov d0,(a3)
	mov d1,(2,a3)
	movx (0,a3),d1
	add 4,a3
	rts

	.size ___truncsipsi2_d0_d1,.-___truncsipsi2_d0_d1
#endif

#ifdef  L_truncsipsi2_d0_d2
	.text
	.globl ___truncsipsi2_d0_d2
	.type  ___truncsipsi2_d0_d2,@function
___truncsipsi2_d0_d2:
	add -4,a3
	mov d0,(a3)
	mov d1,(2,a3)
	movx (0,a3),d2
	add 4,a3
	rts

	.size ___truncsipsi2_d0_d2,.-___truncsipsi2_d0_d2
#endif

#ifdef  L_truncsipsi2_d0_d3
	.text
	.globl ___truncsipsi2_d0_d3
	.type  ___truncsipsi2_d0_d3,@function
___truncsipsi2_d0_d3:
	add -4,a3
	mov d0,(a3)
	mov d1,(2,a3)
	movx (0,a3),d3
	add 4,a3
	rts

	.size ___truncsipsi2_d0_d3,.-___truncsipsi2_d0_d3
#endif

#ifdef  L_truncsipsi2_d2_d0
	.text
	.globl ___truncsipsi2_d2_d0
	.type  ___truncsipsi2_d2_d0,@function
___truncsipsi2_d2_d0:
	add -4,a3
	mov d2,(a3)
	mov d3,(2,a3)
	movx (0,a3),d0
	add 4,a3
	rts

	.size ___truncsipsi2_d2_d0,.-___truncsipsi2_d2_d0
#endif

#ifdef  L_truncsipsi2_d2_d1
	.text
	.globl ___truncsipsi2_d2_d1
	.type  ___truncsipsi2_d2_d1,@function
___truncsipsi2_d2_d1:
	add -4,a3
	mov d2,(a3)
	mov d3,(2,a3)
	movx (0,a3),d1
	add 4,a3
	rts

	.size ___truncsipsi2_d2_d1,.-___truncsipsi2_d2_d1
#endif

#ifdef  L_truncsipsi2_d2_d2
	.text
	.globl ___truncsipsi2_d2_d2
	.type  ___truncsipsi2_d2_d2,@function
___truncsipsi2_d2_d2:
	add -4,a3
	mov d2,(a3)
	mov d3,(2,a3)
	movx (0,a3),d2
	add 4,a3
	rts

	.size ___truncsipsi2_d2_d2,.-___truncsipsi2_d2_d2
#endif

#ifdef  L_truncsipsi2_d2_d3
	.text
	.globl ___truncsipsi2_d2_d3
	.type  ___truncsipsi2_d2_d3,@function
___truncsipsi2_d2_d3:
	add -4,a3
	mov d2,(a3)
	mov d3,(2,a3)
	movx (0,a3),d3
	add 4,a3
	rts

	.size ___truncsipsi2_d2_d3,.-___truncsipsi2_d2_d3
#endif


#ifdef  L_cmpsi2
	.text
	.globl ___cmpsi2
	.type  ___cmpsi2,@function
___cmpsi2:
	add -4,a3
	mov a1,(0,a3)
        mov (10,a3),a1
        mov (8,a3),a0
        cmp a1,d1
        blt .L9
        bgt .L6
        cmp a0,d0
        bcc .L5
.L9:
        sub d0,d0
        jmp .L8
.L5:
        cmp a0,d0
        bhi .L6
        mov 1,d0
        jmp .L8
.L6:
        mov 2,d0
.L8:
	mov (0,a3),a1
	add 4,a3
        rts
	.size ___cmpsi2,.-___cmpsi2
#endif

#ifdef  L_ucmpsi2
	.text
	.globl ___ucmpsi2
	.type  ___ucmpsi2,@function
___ucmpsi2:
	add -4,a3
	mov a1,(0,a3)
        mov (10,a3),a1
        mov (8,a3),a0
        cmp a1,d1
        bcs .L9
        bhi .L6
        cmp a0,d0
        bcc .L5
.L9:
        sub d0,d0
        jmp .L8
.L5:
        cmp a0,d0
        bhi .L6
        mov 1,d0
        jmp .L8
.L6:
        mov 2,d0
.L8:
	mov (0,a3),a1
	add 4,a3
        rts
	.size ___ucmpsi2,.-___ucmpsi2
#endif


#ifdef L_prologue
	.text
	.globl ___prologue
	.type ___prologue,@function
___prologue:
	mov (0,a3),a0
	add -16,a3
	movx d2,(4,a3)
	movx d3,(8,a3)
	mov a1,(12,a3)
	mov a2,(16,a3)
	mov a0,(0,a3)
	rts
	.size ___prologue,.-___prologue
#endif

#ifdef L_epilogue_a0
	.text
	.globl ___epilogue_a0
	.type ___epilogue_a0,@function
___epilogue_a0:
	mov (0,a3),a0
	movx (4,a3),d2
	movx (8,a3),d3
	mov (12,a3),a1
	mov (16,a3),a2
	add 16,a3
	mov a0,(0,a3)
	rts
	.size ___epilogue_a0,.-___epilogue_a0
#endif

#ifdef L_epilogue_d0
	.text
	.globl ___epilogue_d0
	.type ___epilogue_d0,@function
___epilogue_d0:
	movx (0,a3),d0
	movx (4,a3),d2
	movx (8,a3),d3
	mov (12,a3),a1
	mov (16,a3),a2
	add 16,a3
	movx d0,(0,a3)
	rts
	.size ___epilogue_d0,.-___epilogue_d0
#endif

#ifdef L_epilogue_noreturn
	.text
	.globl ___epilogue_noreturn
	.type ___epilogue_noreturn,@function
___epilogue_noreturn:
	movx (0,a3),d2
	movx (4,a3),d3
	mov (8,a3),a1
	mov (12,a3),a2
	add 16,a3
	rts
	.size ___epilogue_noreturn,.-___epilogue_noreturn
#endif