OSDN Git Service

gcc/ChangeLog:
[pf3gnuchains/gcc-fork.git] / gcc / config / sh / lib1funcs.asm
1 /* Copyright (C) 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003
2    Free Software Foundation, Inc.
3
4 This file is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
7 later version.
8
9 In addition to the permissions in the GNU General Public License, the
10 Free Software Foundation gives you unlimited permission to link the
11 compiled version of this file into combinations with other programs,
12 and to distribute those combinations without any restriction coming
13 from the use of this file.  (The General Public License restrictions
14 do apply in other respects; for example, they cover modification of
15 the file, and distribution when not linked into a combine
16 executable.)
17
18 This file is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; see the file COPYING.  If not, write to
25 the Free Software Foundation, 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.  */
27
28 !! libgcc routines for the Renesas / SuperH SH CPUs.
29 !! Contributed by Steve Chamberlain.
30 !! sac@cygnus.com
31
32 !! ashiftrt_r4_x, ___ashrsi3, ___ashlsi3, ___lshrsi3 routines
33 !! recoded in assembly by Toshiyasu Morita
34 !! tm@netcom.com
35
36 /* SH2 optimizations for ___ashrsi3, ___ashlsi3, ___lshrsi3 and
37    ELF local label prefixes by J"orn Rennecke
38    amylaar@cygnus.com  */
39
40 #ifdef __ELF__
41 #define LOCAL(X)        .L_##X
42 #define FUNC(X)         .type X,@function
43 #define ENDFUNC0(X)     .Lfe_##X: .size X,.Lfe_##X-X
44 #define ENDFUNC(X)      ENDFUNC0(X)
45 #else
46 #define LOCAL(X)        L_##X
47 #define FUNC(X)
48 #define ENDFUNC(X)
49 #endif
50
51 #define CONCAT(A,B)     A##B
52 #define GLOBAL0(U,X)    CONCAT(U,__##X)
53 #define GLOBAL(X)       GLOBAL0(__USER_LABEL_PREFIX__,X)
54
55 #if defined __SH5__ && ! defined __SH4_NOFPU__ && ! defined (__LITTLE_ENDIAN__)
56 #define FMOVD_WORKS
57 #endif
58
59 #if ! __SH5__
60 #ifdef L_ashiftrt
61         .global GLOBAL(ashiftrt_r4_0)
62         .global GLOBAL(ashiftrt_r4_1)
63         .global GLOBAL(ashiftrt_r4_2)
64         .global GLOBAL(ashiftrt_r4_3)
65         .global GLOBAL(ashiftrt_r4_4)
66         .global GLOBAL(ashiftrt_r4_5)
67         .global GLOBAL(ashiftrt_r4_6)
68         .global GLOBAL(ashiftrt_r4_7)
69         .global GLOBAL(ashiftrt_r4_8)
70         .global GLOBAL(ashiftrt_r4_9)
71         .global GLOBAL(ashiftrt_r4_10)
72         .global GLOBAL(ashiftrt_r4_11)
73         .global GLOBAL(ashiftrt_r4_12)
74         .global GLOBAL(ashiftrt_r4_13)
75         .global GLOBAL(ashiftrt_r4_14)
76         .global GLOBAL(ashiftrt_r4_15)
77         .global GLOBAL(ashiftrt_r4_16)
78         .global GLOBAL(ashiftrt_r4_17)
79         .global GLOBAL(ashiftrt_r4_18)
80         .global GLOBAL(ashiftrt_r4_19)
81         .global GLOBAL(ashiftrt_r4_20)
82         .global GLOBAL(ashiftrt_r4_21)
83         .global GLOBAL(ashiftrt_r4_22)
84         .global GLOBAL(ashiftrt_r4_23)
85         .global GLOBAL(ashiftrt_r4_24)
86         .global GLOBAL(ashiftrt_r4_25)
87         .global GLOBAL(ashiftrt_r4_26)
88         .global GLOBAL(ashiftrt_r4_27)
89         .global GLOBAL(ashiftrt_r4_28)
90         .global GLOBAL(ashiftrt_r4_29)
91         .global GLOBAL(ashiftrt_r4_30)
92         .global GLOBAL(ashiftrt_r4_31)
93         .global GLOBAL(ashiftrt_r4_32)
94
95         FUNC(GLOBAL(ashiftrt_r4_0))
96         FUNC(GLOBAL(ashiftrt_r4_1))
97         FUNC(GLOBAL(ashiftrt_r4_2))
98         FUNC(GLOBAL(ashiftrt_r4_3))
99         FUNC(GLOBAL(ashiftrt_r4_4))
100         FUNC(GLOBAL(ashiftrt_r4_5))
101         FUNC(GLOBAL(ashiftrt_r4_6))
102         FUNC(GLOBAL(ashiftrt_r4_7))
103         FUNC(GLOBAL(ashiftrt_r4_8))
104         FUNC(GLOBAL(ashiftrt_r4_9))
105         FUNC(GLOBAL(ashiftrt_r4_10))
106         FUNC(GLOBAL(ashiftrt_r4_11))
107         FUNC(GLOBAL(ashiftrt_r4_12))
108         FUNC(GLOBAL(ashiftrt_r4_13))
109         FUNC(GLOBAL(ashiftrt_r4_14))
110         FUNC(GLOBAL(ashiftrt_r4_15))
111         FUNC(GLOBAL(ashiftrt_r4_16))
112         FUNC(GLOBAL(ashiftrt_r4_17))
113         FUNC(GLOBAL(ashiftrt_r4_18))
114         FUNC(GLOBAL(ashiftrt_r4_19))
115         FUNC(GLOBAL(ashiftrt_r4_20))
116         FUNC(GLOBAL(ashiftrt_r4_21))
117         FUNC(GLOBAL(ashiftrt_r4_22))
118         FUNC(GLOBAL(ashiftrt_r4_23))
119         FUNC(GLOBAL(ashiftrt_r4_24))
120         FUNC(GLOBAL(ashiftrt_r4_25))
121         FUNC(GLOBAL(ashiftrt_r4_26))
122         FUNC(GLOBAL(ashiftrt_r4_27))
123         FUNC(GLOBAL(ashiftrt_r4_28))
124         FUNC(GLOBAL(ashiftrt_r4_29))
125         FUNC(GLOBAL(ashiftrt_r4_30))
126         FUNC(GLOBAL(ashiftrt_r4_31))
127         FUNC(GLOBAL(ashiftrt_r4_32))
128
129         .align  1
130 GLOBAL(ashiftrt_r4_32):
131 GLOBAL(ashiftrt_r4_31):
132         rotcl   r4
133         rts
134         subc    r4,r4
135
136 GLOBAL(ashiftrt_r4_30):
137         shar    r4
138 GLOBAL(ashiftrt_r4_29):
139         shar    r4
140 GLOBAL(ashiftrt_r4_28):
141         shar    r4
142 GLOBAL(ashiftrt_r4_27):
143         shar    r4
144 GLOBAL(ashiftrt_r4_26):
145         shar    r4
146 GLOBAL(ashiftrt_r4_25):
147         shar    r4
148 GLOBAL(ashiftrt_r4_24):
149         shlr16  r4
150         shlr8   r4
151         rts
152         exts.b  r4,r4
153
154 GLOBAL(ashiftrt_r4_23):
155         shar    r4
156 GLOBAL(ashiftrt_r4_22):
157         shar    r4
158 GLOBAL(ashiftrt_r4_21):
159         shar    r4
160 GLOBAL(ashiftrt_r4_20):
161         shar    r4
162 GLOBAL(ashiftrt_r4_19):
163         shar    r4
164 GLOBAL(ashiftrt_r4_18):
165         shar    r4
166 GLOBAL(ashiftrt_r4_17):
167         shar    r4
168 GLOBAL(ashiftrt_r4_16):
169         shlr16  r4
170         rts
171         exts.w  r4,r4
172
173 GLOBAL(ashiftrt_r4_15):
174         shar    r4
175 GLOBAL(ashiftrt_r4_14):
176         shar    r4
177 GLOBAL(ashiftrt_r4_13):
178         shar    r4
179 GLOBAL(ashiftrt_r4_12):
180         shar    r4
181 GLOBAL(ashiftrt_r4_11):
182         shar    r4
183 GLOBAL(ashiftrt_r4_10):
184         shar    r4
185 GLOBAL(ashiftrt_r4_9):
186         shar    r4
187 GLOBAL(ashiftrt_r4_8):
188         shar    r4
189 GLOBAL(ashiftrt_r4_7):
190         shar    r4
191 GLOBAL(ashiftrt_r4_6):
192         shar    r4
193 GLOBAL(ashiftrt_r4_5):
194         shar    r4
195 GLOBAL(ashiftrt_r4_4):
196         shar    r4
197 GLOBAL(ashiftrt_r4_3):
198         shar    r4
199 GLOBAL(ashiftrt_r4_2):
200         shar    r4
201 GLOBAL(ashiftrt_r4_1):
202         rts
203         shar    r4
204
205 GLOBAL(ashiftrt_r4_0):
206         rts
207         nop
208
209         ENDFUNC(GLOBAL(ashiftrt_r4_0))
210         ENDFUNC(GLOBAL(ashiftrt_r4_1))
211         ENDFUNC(GLOBAL(ashiftrt_r4_2))
212         ENDFUNC(GLOBAL(ashiftrt_r4_3))
213         ENDFUNC(GLOBAL(ashiftrt_r4_4))
214         ENDFUNC(GLOBAL(ashiftrt_r4_5))
215         ENDFUNC(GLOBAL(ashiftrt_r4_6))
216         ENDFUNC(GLOBAL(ashiftrt_r4_7))
217         ENDFUNC(GLOBAL(ashiftrt_r4_8))
218         ENDFUNC(GLOBAL(ashiftrt_r4_9))
219         ENDFUNC(GLOBAL(ashiftrt_r4_10))
220         ENDFUNC(GLOBAL(ashiftrt_r4_11))
221         ENDFUNC(GLOBAL(ashiftrt_r4_12))
222         ENDFUNC(GLOBAL(ashiftrt_r4_13))
223         ENDFUNC(GLOBAL(ashiftrt_r4_14))
224         ENDFUNC(GLOBAL(ashiftrt_r4_15))
225         ENDFUNC(GLOBAL(ashiftrt_r4_16))
226         ENDFUNC(GLOBAL(ashiftrt_r4_17))
227         ENDFUNC(GLOBAL(ashiftrt_r4_18))
228         ENDFUNC(GLOBAL(ashiftrt_r4_19))
229         ENDFUNC(GLOBAL(ashiftrt_r4_20))
230         ENDFUNC(GLOBAL(ashiftrt_r4_21))
231         ENDFUNC(GLOBAL(ashiftrt_r4_22))
232         ENDFUNC(GLOBAL(ashiftrt_r4_23))
233         ENDFUNC(GLOBAL(ashiftrt_r4_24))
234         ENDFUNC(GLOBAL(ashiftrt_r4_25))
235         ENDFUNC(GLOBAL(ashiftrt_r4_26))
236         ENDFUNC(GLOBAL(ashiftrt_r4_27))
237         ENDFUNC(GLOBAL(ashiftrt_r4_28))
238         ENDFUNC(GLOBAL(ashiftrt_r4_29))
239         ENDFUNC(GLOBAL(ashiftrt_r4_30))
240         ENDFUNC(GLOBAL(ashiftrt_r4_31))
241         ENDFUNC(GLOBAL(ashiftrt_r4_32))
242 #endif
243
244 #ifdef L_ashiftrt_n
245
246 !
247 ! GLOBAL(ashrsi3)
248 !
249 ! Entry:
250 !
251 ! r4: Value to shift
252 ! r5: Shifts
253 !
254 ! Exit:
255 !
256 ! r0: Result
257 !
258 ! Destroys:
259 !
260 ! (none)
261 !
262
263         .global GLOBAL(ashrsi3)
264         FUNC(GLOBAL(ashrsi3))
265         .align  2
266 GLOBAL(ashrsi3):
267         mov     #31,r0
268         and     r0,r5
269         mova    LOCAL(ashrsi3_table),r0
270         mov.b   @(r0,r5),r5
271 #ifdef __sh1__
272         add     r5,r0
273         jmp     @r0
274 #else
275         braf    r5
276 #endif
277         mov     r4,r0
278
279         .align  2
280 LOCAL(ashrsi3_table):
281         .byte           LOCAL(ashrsi3_0)-LOCAL(ashrsi3_table)
282         .byte           LOCAL(ashrsi3_1)-LOCAL(ashrsi3_table)
283         .byte           LOCAL(ashrsi3_2)-LOCAL(ashrsi3_table)
284         .byte           LOCAL(ashrsi3_3)-LOCAL(ashrsi3_table)
285         .byte           LOCAL(ashrsi3_4)-LOCAL(ashrsi3_table)
286         .byte           LOCAL(ashrsi3_5)-LOCAL(ashrsi3_table)
287         .byte           LOCAL(ashrsi3_6)-LOCAL(ashrsi3_table)
288         .byte           LOCAL(ashrsi3_7)-LOCAL(ashrsi3_table)
289         .byte           LOCAL(ashrsi3_8)-LOCAL(ashrsi3_table)
290         .byte           LOCAL(ashrsi3_9)-LOCAL(ashrsi3_table)
291         .byte           LOCAL(ashrsi3_10)-LOCAL(ashrsi3_table)
292         .byte           LOCAL(ashrsi3_11)-LOCAL(ashrsi3_table)
293         .byte           LOCAL(ashrsi3_12)-LOCAL(ashrsi3_table)
294         .byte           LOCAL(ashrsi3_13)-LOCAL(ashrsi3_table)
295         .byte           LOCAL(ashrsi3_14)-LOCAL(ashrsi3_table)
296         .byte           LOCAL(ashrsi3_15)-LOCAL(ashrsi3_table)
297         .byte           LOCAL(ashrsi3_16)-LOCAL(ashrsi3_table)
298         .byte           LOCAL(ashrsi3_17)-LOCAL(ashrsi3_table)
299         .byte           LOCAL(ashrsi3_18)-LOCAL(ashrsi3_table)
300         .byte           LOCAL(ashrsi3_19)-LOCAL(ashrsi3_table)
301         .byte           LOCAL(ashrsi3_20)-LOCAL(ashrsi3_table)
302         .byte           LOCAL(ashrsi3_21)-LOCAL(ashrsi3_table)
303         .byte           LOCAL(ashrsi3_22)-LOCAL(ashrsi3_table)
304         .byte           LOCAL(ashrsi3_23)-LOCAL(ashrsi3_table)
305         .byte           LOCAL(ashrsi3_24)-LOCAL(ashrsi3_table)
306         .byte           LOCAL(ashrsi3_25)-LOCAL(ashrsi3_table)
307         .byte           LOCAL(ashrsi3_26)-LOCAL(ashrsi3_table)
308         .byte           LOCAL(ashrsi3_27)-LOCAL(ashrsi3_table)
309         .byte           LOCAL(ashrsi3_28)-LOCAL(ashrsi3_table)
310         .byte           LOCAL(ashrsi3_29)-LOCAL(ashrsi3_table)
311         .byte           LOCAL(ashrsi3_30)-LOCAL(ashrsi3_table)
312         .byte           LOCAL(ashrsi3_31)-LOCAL(ashrsi3_table)
313
314 LOCAL(ashrsi3_31):
315         rotcl   r0
316         rts
317         subc    r0,r0
318
319 LOCAL(ashrsi3_30):
320         shar    r0
321 LOCAL(ashrsi3_29):
322         shar    r0
323 LOCAL(ashrsi3_28):
324         shar    r0
325 LOCAL(ashrsi3_27):
326         shar    r0
327 LOCAL(ashrsi3_26):
328         shar    r0
329 LOCAL(ashrsi3_25):
330         shar    r0
331 LOCAL(ashrsi3_24):
332         shlr16  r0
333         shlr8   r0
334         rts
335         exts.b  r0,r0
336
337 LOCAL(ashrsi3_23):
338         shar    r0
339 LOCAL(ashrsi3_22):
340         shar    r0
341 LOCAL(ashrsi3_21):
342         shar    r0
343 LOCAL(ashrsi3_20):
344         shar    r0
345 LOCAL(ashrsi3_19):
346         shar    r0
347 LOCAL(ashrsi3_18):
348         shar    r0
349 LOCAL(ashrsi3_17):
350         shar    r0
351 LOCAL(ashrsi3_16):
352         shlr16  r0
353         rts
354         exts.w  r0,r0
355
356 LOCAL(ashrsi3_15):
357         shar    r0
358 LOCAL(ashrsi3_14):
359         shar    r0
360 LOCAL(ashrsi3_13):
361         shar    r0
362 LOCAL(ashrsi3_12):
363         shar    r0
364 LOCAL(ashrsi3_11):
365         shar    r0
366 LOCAL(ashrsi3_10):
367         shar    r0
368 LOCAL(ashrsi3_9):
369         shar    r0
370 LOCAL(ashrsi3_8):
371         shar    r0
372 LOCAL(ashrsi3_7):
373         shar    r0
374 LOCAL(ashrsi3_6):
375         shar    r0
376 LOCAL(ashrsi3_5):
377         shar    r0
378 LOCAL(ashrsi3_4):
379         shar    r0
380 LOCAL(ashrsi3_3):
381         shar    r0
382 LOCAL(ashrsi3_2):
383         shar    r0
384 LOCAL(ashrsi3_1):
385         rts
386         shar    r0
387
388 LOCAL(ashrsi3_0):
389         rts
390         nop
391
392         ENDFUNC(GLOBAL(ashrsi3))
393 #endif
394
395 #ifdef L_ashiftlt
396
397 !
398 ! GLOBAL(ashlsi3)
399 !
400 ! Entry:
401 !
402 ! r4: Value to shift
403 ! r5: Shifts
404 !
405 ! Exit:
406 !
407 ! r0: Result
408 !
409 ! Destroys:
410 !
411 ! (none)
412 !
413         .global GLOBAL(ashlsi3)
414         FUNC(GLOBAL(ashlsi3))
415         .align  2
416 GLOBAL(ashlsi3):
417         mov     #31,r0
418         and     r0,r5
419         mova    LOCAL(ashlsi3_table),r0
420         mov.b   @(r0,r5),r5
421 #ifdef __sh1__
422         add     r5,r0
423         jmp     @r0
424 #else
425         braf    r5
426 #endif
427         mov     r4,r0
428
429         .align  2
430 LOCAL(ashlsi3_table):
431         .byte           LOCAL(ashlsi3_0)-LOCAL(ashlsi3_table)
432         .byte           LOCAL(ashlsi3_1)-LOCAL(ashlsi3_table)
433         .byte           LOCAL(ashlsi3_2)-LOCAL(ashlsi3_table)
434         .byte           LOCAL(ashlsi3_3)-LOCAL(ashlsi3_table)
435         .byte           LOCAL(ashlsi3_4)-LOCAL(ashlsi3_table)
436         .byte           LOCAL(ashlsi3_5)-LOCAL(ashlsi3_table)
437         .byte           LOCAL(ashlsi3_6)-LOCAL(ashlsi3_table)
438         .byte           LOCAL(ashlsi3_7)-LOCAL(ashlsi3_table)
439         .byte           LOCAL(ashlsi3_8)-LOCAL(ashlsi3_table)
440         .byte           LOCAL(ashlsi3_9)-LOCAL(ashlsi3_table)
441         .byte           LOCAL(ashlsi3_10)-LOCAL(ashlsi3_table)
442         .byte           LOCAL(ashlsi3_11)-LOCAL(ashlsi3_table)
443         .byte           LOCAL(ashlsi3_12)-LOCAL(ashlsi3_table)
444         .byte           LOCAL(ashlsi3_13)-LOCAL(ashlsi3_table)
445         .byte           LOCAL(ashlsi3_14)-LOCAL(ashlsi3_table)
446         .byte           LOCAL(ashlsi3_15)-LOCAL(ashlsi3_table)
447         .byte           LOCAL(ashlsi3_16)-LOCAL(ashlsi3_table)
448         .byte           LOCAL(ashlsi3_17)-LOCAL(ashlsi3_table)
449         .byte           LOCAL(ashlsi3_18)-LOCAL(ashlsi3_table)
450         .byte           LOCAL(ashlsi3_19)-LOCAL(ashlsi3_table)
451         .byte           LOCAL(ashlsi3_20)-LOCAL(ashlsi3_table)
452         .byte           LOCAL(ashlsi3_21)-LOCAL(ashlsi3_table)
453         .byte           LOCAL(ashlsi3_22)-LOCAL(ashlsi3_table)
454         .byte           LOCAL(ashlsi3_23)-LOCAL(ashlsi3_table)
455         .byte           LOCAL(ashlsi3_24)-LOCAL(ashlsi3_table)
456         .byte           LOCAL(ashlsi3_25)-LOCAL(ashlsi3_table)
457         .byte           LOCAL(ashlsi3_26)-LOCAL(ashlsi3_table)
458         .byte           LOCAL(ashlsi3_27)-LOCAL(ashlsi3_table)
459         .byte           LOCAL(ashlsi3_28)-LOCAL(ashlsi3_table)
460         .byte           LOCAL(ashlsi3_29)-LOCAL(ashlsi3_table)
461         .byte           LOCAL(ashlsi3_30)-LOCAL(ashlsi3_table)
462         .byte           LOCAL(ashlsi3_31)-LOCAL(ashlsi3_table)
463
464 LOCAL(ashlsi3_6):
465         shll2   r0
466 LOCAL(ashlsi3_4):
467         shll2   r0
468 LOCAL(ashlsi3_2):
469         rts
470         shll2   r0
471
472 LOCAL(ashlsi3_7):
473         shll2   r0
474 LOCAL(ashlsi3_5):
475         shll2   r0
476 LOCAL(ashlsi3_3):
477         shll2   r0
478 LOCAL(ashlsi3_1):
479         rts
480         shll    r0
481
482 LOCAL(ashlsi3_14):
483         shll2   r0
484 LOCAL(ashlsi3_12):
485         shll2   r0
486 LOCAL(ashlsi3_10):
487         shll2   r0
488 LOCAL(ashlsi3_8):
489         rts
490         shll8   r0
491
492 LOCAL(ashlsi3_15):
493         shll2   r0
494 LOCAL(ashlsi3_13):
495         shll2   r0
496 LOCAL(ashlsi3_11):
497         shll2   r0
498 LOCAL(ashlsi3_9):
499         shll8   r0
500         rts
501         shll    r0
502
503 LOCAL(ashlsi3_22):
504         shll2   r0
505 LOCAL(ashlsi3_20):
506         shll2   r0
507 LOCAL(ashlsi3_18):
508         shll2   r0
509 LOCAL(ashlsi3_16):
510         rts
511         shll16  r0
512
513 LOCAL(ashlsi3_23):
514         shll2   r0
515 LOCAL(ashlsi3_21):
516         shll2   r0
517 LOCAL(ashlsi3_19):
518         shll2   r0
519 LOCAL(ashlsi3_17):
520         shll16  r0
521         rts
522         shll    r0
523
524 LOCAL(ashlsi3_30):
525         shll2   r0
526 LOCAL(ashlsi3_28):
527         shll2   r0
528 LOCAL(ashlsi3_26):
529         shll2   r0
530 LOCAL(ashlsi3_24):
531         shll16  r0
532         rts
533         shll8   r0
534
535 LOCAL(ashlsi3_31):
536         shll2   r0
537 LOCAL(ashlsi3_29):
538         shll2   r0
539 LOCAL(ashlsi3_27):
540         shll2   r0
541 LOCAL(ashlsi3_25):
542         shll16  r0
543         shll8   r0
544         rts
545         shll    r0
546
547 LOCAL(ashlsi3_0):
548         rts
549         nop
550
551         ENDFUNC(GLOBAL(ashlsi3))
552 #endif
553
554 #ifdef L_lshiftrt
555
556 !
557 ! GLOBAL(lshrsi3)
558 !
559 ! Entry:
560 !
561 ! r4: Value to shift
562 ! r5: Shifts
563 !
564 ! Exit:
565 !
566 ! r0: Result
567 !
568 ! Destroys:
569 !
570 ! (none)
571 !
572         .global GLOBAL(lshrsi3)
573         FUNC(GLOBAL(lshrsi3))
574         .align  2
575 GLOBAL(lshrsi3):
576         mov     #31,r0
577         and     r0,r5
578         mova    LOCAL(lshrsi3_table),r0
579         mov.b   @(r0,r5),r5
580 #ifdef __sh1__
581         add     r5,r0
582         jmp     @r0
583 #else
584         braf    r5
585 #endif
586         mov     r4,r0
587
588         .align  2
589 LOCAL(lshrsi3_table):
590         .byte           LOCAL(lshrsi3_0)-LOCAL(lshrsi3_table)
591         .byte           LOCAL(lshrsi3_1)-LOCAL(lshrsi3_table)
592         .byte           LOCAL(lshrsi3_2)-LOCAL(lshrsi3_table)
593         .byte           LOCAL(lshrsi3_3)-LOCAL(lshrsi3_table)
594         .byte           LOCAL(lshrsi3_4)-LOCAL(lshrsi3_table)
595         .byte           LOCAL(lshrsi3_5)-LOCAL(lshrsi3_table)
596         .byte           LOCAL(lshrsi3_6)-LOCAL(lshrsi3_table)
597         .byte           LOCAL(lshrsi3_7)-LOCAL(lshrsi3_table)
598         .byte           LOCAL(lshrsi3_8)-LOCAL(lshrsi3_table)
599         .byte           LOCAL(lshrsi3_9)-LOCAL(lshrsi3_table)
600         .byte           LOCAL(lshrsi3_10)-LOCAL(lshrsi3_table)
601         .byte           LOCAL(lshrsi3_11)-LOCAL(lshrsi3_table)
602         .byte           LOCAL(lshrsi3_12)-LOCAL(lshrsi3_table)
603         .byte           LOCAL(lshrsi3_13)-LOCAL(lshrsi3_table)
604         .byte           LOCAL(lshrsi3_14)-LOCAL(lshrsi3_table)
605         .byte           LOCAL(lshrsi3_15)-LOCAL(lshrsi3_table)
606         .byte           LOCAL(lshrsi3_16)-LOCAL(lshrsi3_table)
607         .byte           LOCAL(lshrsi3_17)-LOCAL(lshrsi3_table)
608         .byte           LOCAL(lshrsi3_18)-LOCAL(lshrsi3_table)
609         .byte           LOCAL(lshrsi3_19)-LOCAL(lshrsi3_table)
610         .byte           LOCAL(lshrsi3_20)-LOCAL(lshrsi3_table)
611         .byte           LOCAL(lshrsi3_21)-LOCAL(lshrsi3_table)
612         .byte           LOCAL(lshrsi3_22)-LOCAL(lshrsi3_table)
613         .byte           LOCAL(lshrsi3_23)-LOCAL(lshrsi3_table)
614         .byte           LOCAL(lshrsi3_24)-LOCAL(lshrsi3_table)
615         .byte           LOCAL(lshrsi3_25)-LOCAL(lshrsi3_table)
616         .byte           LOCAL(lshrsi3_26)-LOCAL(lshrsi3_table)
617         .byte           LOCAL(lshrsi3_27)-LOCAL(lshrsi3_table)
618         .byte           LOCAL(lshrsi3_28)-LOCAL(lshrsi3_table)
619         .byte           LOCAL(lshrsi3_29)-LOCAL(lshrsi3_table)
620         .byte           LOCAL(lshrsi3_30)-LOCAL(lshrsi3_table)
621         .byte           LOCAL(lshrsi3_31)-LOCAL(lshrsi3_table)
622
623 LOCAL(lshrsi3_6):
624         shlr2   r0
625 LOCAL(lshrsi3_4):
626         shlr2   r0
627 LOCAL(lshrsi3_2):
628         rts
629         shlr2   r0
630
631 LOCAL(lshrsi3_7):
632         shlr2   r0
633 LOCAL(lshrsi3_5):
634         shlr2   r0
635 LOCAL(lshrsi3_3):
636         shlr2   r0
637 LOCAL(lshrsi3_1):
638         rts
639         shlr    r0
640
641 LOCAL(lshrsi3_14):
642         shlr2   r0
643 LOCAL(lshrsi3_12):
644         shlr2   r0
645 LOCAL(lshrsi3_10):
646         shlr2   r0
647 LOCAL(lshrsi3_8):
648         rts
649         shlr8   r0
650
651 LOCAL(lshrsi3_15):
652         shlr2   r0
653 LOCAL(lshrsi3_13):
654         shlr2   r0
655 LOCAL(lshrsi3_11):
656         shlr2   r0
657 LOCAL(lshrsi3_9):
658         shlr8   r0
659         rts
660         shlr    r0
661
662 LOCAL(lshrsi3_22):
663         shlr2   r0
664 LOCAL(lshrsi3_20):
665         shlr2   r0
666 LOCAL(lshrsi3_18):
667         shlr2   r0
668 LOCAL(lshrsi3_16):
669         rts
670         shlr16  r0
671
672 LOCAL(lshrsi3_23):
673         shlr2   r0
674 LOCAL(lshrsi3_21):
675         shlr2   r0
676 LOCAL(lshrsi3_19):
677         shlr2   r0
678 LOCAL(lshrsi3_17):
679         shlr16  r0
680         rts
681         shlr    r0
682
683 LOCAL(lshrsi3_30):
684         shlr2   r0
685 LOCAL(lshrsi3_28):
686         shlr2   r0
687 LOCAL(lshrsi3_26):
688         shlr2   r0
689 LOCAL(lshrsi3_24):
690         shlr16  r0
691         rts
692         shlr8   r0
693
694 LOCAL(lshrsi3_31):
695         shlr2   r0
696 LOCAL(lshrsi3_29):
697         shlr2   r0
698 LOCAL(lshrsi3_27):
699         shlr2   r0
700 LOCAL(lshrsi3_25):
701         shlr16  r0
702         shlr8   r0
703         rts
704         shlr    r0
705
706 LOCAL(lshrsi3_0):
707         rts
708         nop
709
710         ENDFUNC(GLOBAL(lshrsi3))
711 #endif
712
713 #ifdef L_movmem
714         .text
715 ! done all the large groups, do the remainder
716
717 ! jump to movmem+
718 done:
719         add     #64,r5
720         mova    GLOBAL(movmemSI0),r0
721         shll2   r6
722         add     r6,r0
723         jmp     @r0
724         add     #64,r4
725         .align  4
726         .global GLOBAL(movmemSI64)
727         FUNC(GLOBAL(movmemSI64))
728 GLOBAL(movmemSI64):
729         mov.l   @(60,r5),r0
730         mov.l   r0,@(60,r4)
731         .global GLOBAL(movmemSI60)
732         FUNC(GLOBAL(movmemSI60))
733 GLOBAL(movmemSI60):
734         mov.l   @(56,r5),r0
735         mov.l   r0,@(56,r4)
736         .global GLOBAL(movmemSI56)
737         FUNC(GLOBAL(movmemSI56))
738 GLOBAL(movmemSI56):
739         mov.l   @(52,r5),r0
740         mov.l   r0,@(52,r4)
741         .global GLOBAL(movmemSI52)
742         FUNC(GLOBAL(movmemSI52))
743 GLOBAL(movmemSI52):
744         mov.l   @(48,r5),r0
745         mov.l   r0,@(48,r4)
746         .global GLOBAL(movmemSI48)
747         FUNC(GLOBAL(movmemSI48))
748 GLOBAL(movmemSI48):
749         mov.l   @(44,r5),r0
750         mov.l   r0,@(44,r4)
751         .global GLOBAL(movmemSI44)
752         FUNC(GLOBAL(movmemSI44))
753 GLOBAL(movmemSI44):
754         mov.l   @(40,r5),r0
755         mov.l   r0,@(40,r4)
756         .global GLOBAL(movmemSI40)
757         FUNC(GLOBAL(movmemSI40))
758 GLOBAL(movmemSI40):
759         mov.l   @(36,r5),r0
760         mov.l   r0,@(36,r4)
761         .global GLOBAL(movmemSI36)
762         FUNC(GLOBAL(movmemSI36))
763 GLOBAL(movmemSI36):
764         mov.l   @(32,r5),r0
765         mov.l   r0,@(32,r4)
766         .global GLOBAL(movmemSI32)
767         FUNC(GLOBAL(movmemSI32))
768 GLOBAL(movmemSI32):
769         mov.l   @(28,r5),r0
770         mov.l   r0,@(28,r4)
771         .global GLOBAL(movmemSI28)
772         FUNC(GLOBAL(movmemSI28))
773 GLOBAL(movmemSI28):
774         mov.l   @(24,r5),r0
775         mov.l   r0,@(24,r4)
776         .global GLOBAL(movmemSI24)
777         FUNC(GLOBAL(movmemSI24))
778 GLOBAL(movmemSI24):
779         mov.l   @(20,r5),r0
780         mov.l   r0,@(20,r4)
781         .global GLOBAL(movmemSI20)
782         FUNC(GLOBAL(movmemSI20))
783 GLOBAL(movmemSI20):
784         mov.l   @(16,r5),r0
785         mov.l   r0,@(16,r4)
786         .global GLOBAL(movmemSI16)
787         FUNC(GLOBAL(movmemSI16))
788 GLOBAL(movmemSI16):
789         mov.l   @(12,r5),r0
790         mov.l   r0,@(12,r4)
791         .global GLOBAL(movmemSI12)
792         FUNC(GLOBAL(movmemSI12))
793 GLOBAL(movmemSI12):
794         mov.l   @(8,r5),r0
795         mov.l   r0,@(8,r4)
796         .global GLOBAL(movmemSI8)
797         FUNC(GLOBAL(movmemSI8))
798 GLOBAL(movmemSI8):
799         mov.l   @(4,r5),r0
800         mov.l   r0,@(4,r4)
801         .global GLOBAL(movmemSI4)
802         FUNC(GLOBAL(movmemSI4))
803 GLOBAL(movmemSI4):
804         mov.l   @(0,r5),r0
805         mov.l   r0,@(0,r4)
806         .global GLOBAL(movmemSI0)
807         FUNC(GLOBAL(movmemSI0))
808 GLOBAL(movmemSI0):
809         rts
810         nop
811
812         ENDFUNC(GLOBAL(movmemSI64))
813         ENDFUNC(GLOBAL(movmemSI60))
814         ENDFUNC(GLOBAL(movmemSI56))
815         ENDFUNC(GLOBAL(movmemSI52))
816         ENDFUNC(GLOBAL(movmemSI48))
817         ENDFUNC(GLOBAL(movmemSI44))
818         ENDFUNC(GLOBAL(movmemSI40))
819         ENDFUNC(GLOBAL(movmemSI36))
820         ENDFUNC(GLOBAL(movmemSI32))
821         ENDFUNC(GLOBAL(movmemSI28))
822         ENDFUNC(GLOBAL(movmemSI24))
823         ENDFUNC(GLOBAL(movmemSI20))
824         ENDFUNC(GLOBAL(movmemSI16))
825         ENDFUNC(GLOBAL(movmemSI12))
826         ENDFUNC(GLOBAL(movmemSI8))
827         ENDFUNC(GLOBAL(movmemSI4))
828         ENDFUNC(GLOBAL(movmemSI0))
829
830         .align  4
831
832         .global GLOBAL(movmem)
833         FUNC(GLOBAL(movmem))
834 GLOBAL(movmem):
835         mov.l   @(60,r5),r0
836         mov.l   r0,@(60,r4)
837
838         mov.l   @(56,r5),r0
839         mov.l   r0,@(56,r4)
840
841         mov.l   @(52,r5),r0
842         mov.l   r0,@(52,r4)
843
844         mov.l   @(48,r5),r0
845         mov.l   r0,@(48,r4)
846
847         mov.l   @(44,r5),r0
848         mov.l   r0,@(44,r4)
849
850         mov.l   @(40,r5),r0
851         mov.l   r0,@(40,r4)
852
853         mov.l   @(36,r5),r0
854         mov.l   r0,@(36,r4)
855
856         mov.l   @(32,r5),r0
857         mov.l   r0,@(32,r4)
858
859         mov.l   @(28,r5),r0
860         mov.l   r0,@(28,r4)
861
862         mov.l   @(24,r5),r0
863         mov.l   r0,@(24,r4)
864
865         mov.l   @(20,r5),r0
866         mov.l   r0,@(20,r4)
867
868         mov.l   @(16,r5),r0
869         mov.l   r0,@(16,r4)
870
871         mov.l   @(12,r5),r0
872         mov.l   r0,@(12,r4)
873
874         mov.l   @(8,r5),r0
875         mov.l   r0,@(8,r4)
876
877         mov.l   @(4,r5),r0
878         mov.l   r0,@(4,r4)
879
880         mov.l   @(0,r5),r0
881         mov.l   r0,@(0,r4)
882
883         add     #-16,r6
884         cmp/pl  r6
885         bf      done
886
887         add     #64,r5
888         bra     GLOBAL(movmem)
889         add     #64,r4
890
891         FUNC(GLOBAL(movmem))
892 #endif
893
894 #ifdef L_movmem_i4
895         .text
896         .global GLOBAL(movmem_i4_even)
897         .global GLOBAL(movmem_i4_odd)
898         .global GLOBAL(movmemSI12_i4)
899
900         FUNC(GLOBAL(movmem_i4_even))
901         FUNC(GLOBAL(movmem_i4_odd))
902         FUNC(GLOBAL(movmemSI12_i4))
903
904         .p2align        5
905 L_movmem_2mod4_end:
906         mov.l   r0,@(16,r4)
907         rts
908         mov.l   r1,@(20,r4)
909
910         .p2align        2
911
912 GLOBAL(movmem_i4_even):
913         mov.l   @r5+,r0
914         bra     L_movmem_start_even
915         mov.l   @r5+,r1
916
917 GLOBAL(movmem_i4_odd):
918         mov.l   @r5+,r1
919         add     #-4,r4
920         mov.l   @r5+,r2
921         mov.l   @r5+,r3
922         mov.l   r1,@(4,r4)
923         mov.l   r2,@(8,r4)
924
925 L_movmem_loop:
926         mov.l   r3,@(12,r4)
927         dt      r6
928         mov.l   @r5+,r0
929         bt/s    L_movmem_2mod4_end
930         mov.l   @r5+,r1
931         add     #16,r4
932 L_movmem_start_even:
933         mov.l   @r5+,r2
934         mov.l   @r5+,r3
935         mov.l   r0,@r4
936         dt      r6
937         mov.l   r1,@(4,r4)
938         bf/s    L_movmem_loop
939         mov.l   r2,@(8,r4)
940         rts
941         mov.l   r3,@(12,r4)
942
943         ENDFUNC(GLOBAL(movmem_i4_even))
944         ENDFUNC(GLOBAL(movmem_i4_odd))
945
946         .p2align        4
947 GLOBAL(movmemSI12_i4):
948         mov.l   @r5,r0
949         mov.l   @(4,r5),r1
950         mov.l   @(8,r5),r2
951         mov.l   r0,@r4
952         mov.l   r1,@(4,r4)
953         rts
954         mov.l   r2,@(8,r4)
955
956         ENDFUNC(GLOBAL(movmemSI12_i4))
957 #endif
958
959 #ifdef L_mulsi3
960
961
962         .global GLOBAL(mulsi3)
963         FUNC(GLOBAL(mulsi3))
964
965 ! r4 =       aabb
966 ! r5 =       ccdd
967 ! r0 = aabb*ccdd  via partial products
968 !
969 ! if aa == 0 and cc = 0
970 ! r0 = bb*dd
971 !
972 ! else
973 ! aa = bb*dd + (aa*dd*65536) + (cc*bb*65536)
974 !
975
976 GLOBAL(mulsi3):
977         mulu.w  r4,r5           ! multiply the lsws  macl=bb*dd
978         mov     r5,r3           ! r3 = ccdd
979         swap.w  r4,r2           ! r2 = bbaa
980         xtrct   r2,r3           ! r3 = aacc
981         tst     r3,r3           ! msws zero ?
982         bf      hiset
983         rts                     ! yes - then we have the answer
984         sts     macl,r0
985
986 hiset:  sts     macl,r0         ! r0 = bb*dd
987         mulu.w  r2,r5           ! brewing macl = aa*dd
988         sts     macl,r1
989         mulu.w  r3,r4           ! brewing macl = cc*bb
990         sts     macl,r2
991         add     r1,r2
992         shll16  r2
993         rts
994         add     r2,r0
995
996         FUNC(GLOBAL(mulsi3))
997 #endif
998 #endif /* ! __SH5__ */
999 #ifdef L_sdivsi3_i4
1000         .title "SH DIVIDE"
1001 !! 4 byte integer Divide code for the Renesas SH
1002 #ifdef __SH4__
1003 !! args in r4 and r5, result in fpul, clobber dr0, dr2
1004
1005         .global GLOBAL(sdivsi3_i4)
1006         FUNC(GLOBAL(sdivsi3_i4))
1007 GLOBAL(sdivsi3_i4):
1008         lds r4,fpul
1009         float fpul,dr0
1010         lds r5,fpul
1011         float fpul,dr2
1012         fdiv dr2,dr0
1013         rts
1014         ftrc dr0,fpul
1015
1016         ENDFUNC(GLOBAL(sdivsi3_i4))
1017 #elif defined(__SH4_SINGLE__) || defined(__SH4_SINGLE_ONLY__) || (defined (__SH5__) && ! defined __SH4_NOFPU__)
1018 !! args in r4 and r5, result in fpul, clobber r2, dr0, dr2
1019
1020 #if ! __SH5__ || __SH5__ == 32
1021 #if __SH5__
1022         .mode   SHcompact
1023 #endif
1024         .global GLOBAL(sdivsi3_i4)
1025         FUNC(GLOBAL(sdivsi3_i4))
1026 GLOBAL(sdivsi3_i4):
1027         sts.l fpscr,@-r15
1028         mov #8,r2
1029         swap.w r2,r2
1030         lds r2,fpscr
1031         lds r4,fpul
1032         float fpul,dr0
1033         lds r5,fpul
1034         float fpul,dr2
1035         fdiv dr2,dr0
1036         ftrc dr0,fpul
1037         rts
1038         lds.l @r15+,fpscr
1039
1040         ENDFUNC(GLOBAL(sdivsi3_i4))
1041 #endif /* ! __SH5__ || __SH5__ == 32 */
1042 #endif /* ! __SH4__ */
1043 #endif
1044
1045 #ifdef L_sdivsi3
1046 /* __SH4_SINGLE_ONLY__ keeps this part for link compatibility with
1047    sh2e/sh3e code.  */
1048 #if (! defined(__SH4__) && ! defined (__SH4_SINGLE__)) || defined (__linux__)
1049 !!
1050 !! Steve Chamberlain
1051 !! sac@cygnus.com
1052 !!
1053 !!
1054
1055 !! args in r4 and r5, result in r0 clobber r1, r2, r3, and t bit
1056
1057         .global GLOBAL(sdivsi3)
1058         FUNC(GLOBAL(sdivsi3))
1059 #if __SHMEDIA__
1060 #if __SH5__ == 32
1061         .section        .text..SHmedia32,"ax"
1062 #else
1063         .text
1064 #endif
1065         .align  2
1066 #if 0
1067 /* The assembly code that follows is a hand-optimized version of the C
1068    code that follows.  Note that the registers that are modified are
1069    exactly those listed as clobbered in the patterns divsi3_i1 and
1070    divsi3_i1_media.
1071         
1072 int __sdivsi3 (i, j)
1073      int i, j;
1074 {
1075   register unsigned long long r18 asm ("r18");
1076   register unsigned long long r19 asm ("r19");
1077   register unsigned long long r0 asm ("r0") = 0;
1078   register unsigned long long r1 asm ("r1") = 1;
1079   register int r2 asm ("r2") = i >> 31;
1080   register int r3 asm ("r3") = j >> 31;
1081
1082   r2 = r2 ? r2 : r1;
1083   r3 = r3 ? r3 : r1;
1084   r18 = i * r2;
1085   r19 = j * r3;
1086   r2 *= r3;
1087   
1088   r19 <<= 31;
1089   r1 <<= 31;
1090   do
1091     if (r18 >= r19)
1092       r0 |= r1, r18 -= r19;
1093   while (r19 >>= 1, r1 >>= 1);
1094
1095   return r2 * (int)r0;
1096 }
1097 */
1098 GLOBAL(sdivsi3):
1099         pt/l    LOCAL(sdivsi3_dontadd), tr2
1100         pt/l    LOCAL(sdivsi3_loop), tr1
1101         ptabs/l r18, tr0
1102         movi    0, r0
1103         movi    1, r1
1104         shari.l r4, 31, r2
1105         shari.l r5, 31, r3
1106         cmveq   r2, r1, r2
1107         cmveq   r3, r1, r3
1108         muls.l  r4, r2, r18
1109         muls.l  r5, r3, r19
1110         muls.l  r2, r3, r2
1111         shlli   r19, 31, r19
1112         shlli   r1, 31, r1
1113 LOCAL(sdivsi3_loop):
1114         bgtu    r19, r18, tr2
1115         or      r0, r1, r0
1116         sub     r18, r19, r18
1117 LOCAL(sdivsi3_dontadd):
1118         shlri   r1, 1, r1
1119         shlri   r19, 1, r19
1120         bnei    r1, 0, tr1
1121         muls.l  r0, r2, r0
1122         add.l   r0, r63, r0
1123         blink   tr0, r63
1124 #else /* ! 0 */
1125  // inputs: r4,r5
1126  // clobbered: r1,r2,r3,r18,r19,r20,r21,r25,tr0
1127  // result in r0
1128 GLOBAL(sdivsi3):
1129  // can create absolute value without extra latency,
1130  // but dependent on proper sign extension of inputs:
1131  // shari.l r5,31,r2
1132  // xor r5,r2,r20
1133  // sub r20,r2,r20 // r20 is now absolute value of r5, zero-extended.
1134  shari.l r5,31,r2
1135  ori r2,1,r2
1136  muls.l r5,r2,r20 // r20 is now absolute value of r5, zero-extended.
1137  movi 0xffffffffffffbb0c,r19 // shift count eqiv 76
1138  shari.l r4,31,r3
1139  nsb r20,r0
1140  shlld r20,r0,r25
1141  shlri r25,48,r25
1142  sub r19,r25,r1
1143  mmulfx.w r1,r1,r2
1144  mshflo.w r1,r63,r1
1145  // If r4 was to be used in-place instead of r21, could use this sequence
1146  // to compute absolute:
1147  // sub r63,r4,r19 // compute absolute value of r4
1148  // shlri r4,32,r3 // into lower 32 bit of r4, keeping
1149  // mcmv r19,r3,r4 // the sign in the upper 32 bits intact.
1150  ori r3,1,r3
1151  mmulfx.w r25,r2,r2
1152  sub r19,r0,r0
1153  muls.l r4,r3,r21
1154  msub.w r1,r2,r2
1155  addi r2,-2,r1
1156  mulu.l r21,r1,r19
1157  mmulfx.w r2,r2,r2
1158  shlli r1,15,r1
1159  shlrd r19,r0,r19
1160  mulu.l r19,r20,r3
1161  mmacnfx.wl r25,r2,r1
1162  ptabs r18,tr0
1163  sub r21,r3,r25
1164
1165  mulu.l r25,r1,r2
1166  addi r0,14,r0
1167  xor r4,r5,r18
1168  shlrd r2,r0,r2
1169  mulu.l r2,r20,r3
1170  add r19,r2,r19
1171  shari.l r18,31,r18
1172  sub r25,r3,r25
1173
1174  mulu.l r25,r1,r2
1175  sub r25,r20,r25
1176  add r19,r18,r19
1177  shlrd r2,r0,r2
1178  mulu.l r2,r20,r3
1179  addi r25,1,r25
1180  add r19,r2,r19
1181
1182  cmpgt r25,r3,r25
1183  add.l r19,r25,r0
1184  xor r0,r18,r0
1185  blink tr0,r63
1186 #endif
1187 #elif defined __SHMEDIA__
1188 /* m5compact-nofpu */
1189  // clobbered: r18,r19,r20,r21,r25,tr0,tr1,tr2
1190         .mode   SHmedia
1191         .section        .text..SHmedia32,"ax"
1192         .align  2
1193 GLOBAL(sdivsi3):
1194         pt/l LOCAL(sdivsi3_dontsub), tr0
1195         pt/l LOCAL(sdivsi3_loop), tr1
1196         ptabs/l r18,tr2
1197         shari.l r4,31,r18
1198         shari.l r5,31,r19
1199         xor r4,r18,r20
1200         xor r5,r19,r21
1201         sub.l r20,r18,r20
1202         sub.l r21,r19,r21
1203         xor r18,r19,r19
1204         shlli r21,32,r25
1205         addi r25,-1,r21
1206         addz.l r20,r63,r20
1207 LOCAL(sdivsi3_loop):
1208         shlli r20,1,r20
1209         bgeu/u r21,r20,tr0
1210         sub r20,r21,r20
1211 LOCAL(sdivsi3_dontsub):
1212         addi.l r25,-1,r25
1213         bnei r25,-32,tr1
1214         xor r20,r19,r20
1215         sub.l r20,r19,r0
1216         blink tr2,r63
1217 #else /* ! __SHMEDIA__ */
1218 GLOBAL(sdivsi3):
1219         mov     r4,r1
1220         mov     r5,r0
1221
1222         tst     r0,r0
1223         bt      div0
1224         mov     #0,r2
1225         div0s   r2,r1
1226         subc    r3,r3
1227         subc    r2,r1
1228         div0s   r0,r3
1229         rotcl   r1
1230         div1    r0,r3
1231         rotcl   r1
1232         div1    r0,r3
1233         rotcl   r1
1234         div1    r0,r3
1235         rotcl   r1
1236         div1    r0,r3
1237         rotcl   r1
1238         div1    r0,r3
1239         rotcl   r1
1240         div1    r0,r3
1241         rotcl   r1
1242         div1    r0,r3
1243         rotcl   r1
1244         div1    r0,r3
1245         rotcl   r1
1246         div1    r0,r3
1247         rotcl   r1
1248         div1    r0,r3
1249         rotcl   r1
1250         div1    r0,r3
1251         rotcl   r1
1252         div1    r0,r3
1253         rotcl   r1
1254         div1    r0,r3
1255         rotcl   r1
1256         div1    r0,r3
1257         rotcl   r1
1258         div1    r0,r3
1259         rotcl   r1
1260         div1    r0,r3
1261         rotcl   r1
1262         div1    r0,r3
1263         rotcl   r1
1264         div1    r0,r3
1265         rotcl   r1
1266         div1    r0,r3
1267         rotcl   r1
1268         div1    r0,r3
1269         rotcl   r1
1270         div1    r0,r3
1271         rotcl   r1
1272         div1    r0,r3
1273         rotcl   r1
1274         div1    r0,r3
1275         rotcl   r1
1276         div1    r0,r3
1277         rotcl   r1
1278         div1    r0,r3
1279         rotcl   r1
1280         div1    r0,r3
1281         rotcl   r1
1282         div1    r0,r3
1283         rotcl   r1
1284         div1    r0,r3
1285         rotcl   r1
1286         div1    r0,r3
1287         rotcl   r1
1288         div1    r0,r3
1289         rotcl   r1
1290         div1    r0,r3
1291         rotcl   r1
1292         div1    r0,r3
1293         rotcl   r1
1294         addc    r2,r1
1295         rts
1296         mov     r1,r0
1297
1298
1299 div0:   rts
1300         mov     #0,r0
1301
1302         ENDFUNC(GLOBAL(sdivsi3))
1303 #endif /* ! __SHMEDIA__ */
1304 #endif /* ! __SH4__ */
1305 #endif
1306 #ifdef L_udivsi3_i4
1307
1308         .title "SH DIVIDE"
1309 !! 4 byte integer Divide code for the Renesas SH
1310 #ifdef __SH4__
1311 !! args in r4 and r5, result in fpul, clobber r0, r1, r4, r5, dr0, dr2, dr4,
1312 !! and t bit
1313
1314         .global GLOBAL(udivsi3_i4)
1315         FUNC(GLOBAL(udivsi3_i4))
1316 GLOBAL(udivsi3_i4):
1317         mov #1,r1
1318         cmp/hi r1,r5
1319         bf trivial
1320         rotr r1
1321         xor r1,r4
1322         lds r4,fpul
1323         mova L1,r0
1324 #ifdef FMOVD_WORKS
1325         fmov.d @r0+,dr4
1326 #else
1327 #ifdef __LITTLE_ENDIAN__
1328         fmov.s @r0+,fr5
1329         fmov.s @r0,fr4
1330 #else
1331         fmov.s @r0+,fr4
1332         fmov.s @r0,fr5
1333 #endif
1334 #endif
1335         float fpul,dr0
1336         xor r1,r5
1337         lds r5,fpul
1338         float fpul,dr2
1339         fadd dr4,dr0
1340         fadd dr4,dr2
1341         fdiv dr2,dr0
1342         rts
1343         ftrc dr0,fpul
1344
1345 trivial:
1346         rts
1347         lds r4,fpul
1348
1349         .align 2
1350 #ifdef FMOVD_WORKS
1351         .align 3        ! make double below 8 byte aligned.
1352 #endif
1353 L1:
1354         .double 2147483648
1355
1356         ENDFUNC(GLOBAL(udivsi3_i4))
1357 #elif defined (__SH5__) && ! defined (__SH4_NOFPU__)
1358 #if ! __SH5__ || __SH5__ == 32
1359 !! args in r4 and r5, result in fpul, clobber r20, r21, dr0, fr33
1360         .mode   SHmedia
1361         .global GLOBAL(udivsi3_i4)
1362         FUNC(GLOBAL(udivsi3_i4))
1363 GLOBAL(udivsi3_i4):
1364         addz.l  r4,r63,r20
1365         addz.l  r5,r63,r21
1366         fmov.qd r20,dr0
1367         fmov.qd r21,dr32
1368         ptabs   r18,tr0
1369         float.qd dr0,dr0
1370         float.qd dr32,dr32
1371         fdiv.d  dr0,dr32,dr0
1372         ftrc.dq dr0,dr32
1373         fmov.s fr33,fr32
1374         blink tr0,r63
1375
1376         ENDFUNC(GLOBAL(udivsi3_i4))
1377 #endif /* ! __SH5__ || __SH5__ == 32 */
1378 #elif defined(__SH4_SINGLE__) || defined(__SH4_SINGLE_ONLY__)
1379 !! args in r4 and r5, result in fpul, clobber r0, r1, r4, r5, dr0, dr2, dr4
1380
1381         .global GLOBAL(udivsi3_i4)
1382 GLOBAL(udivsi3_i4):
1383         mov #1,r1
1384         cmp/hi r1,r5
1385         bf trivial
1386         sts.l fpscr,@-r15
1387         mova L1,r0
1388         lds.l @r0+,fpscr
1389         rotr r1
1390         xor r1,r4
1391         lds r4,fpul
1392 #ifdef FMOVD_WORKS
1393         fmov.d @r0+,dr4
1394 #else
1395 #ifdef __LITTLE_ENDIAN__
1396         fmov.s @r0+,fr5
1397         fmov.s @r0,fr4
1398 #else
1399         fmov.s @r0+,fr4
1400         fmov.s @r0,fr5
1401 #endif
1402 #endif
1403         float fpul,dr0
1404         xor r1,r5
1405         lds r5,fpul
1406         float fpul,dr2
1407         fadd dr4,dr0
1408         fadd dr4,dr2
1409         fdiv dr2,dr0
1410         ftrc dr0,fpul
1411         rts
1412         lds.l @r15+,fpscr
1413
1414 #ifdef FMOVD_WORKS
1415         .align 3        ! make double below 8 byte aligned.
1416 #endif
1417 trivial:
1418         rts
1419         lds r4,fpul
1420
1421         .align 2
1422 L1:
1423 #ifndef FMOVD_WORKS
1424         .long 0x80000
1425 #else
1426         .long 0x180000
1427 #endif
1428         .double 2147483648
1429
1430         ENDFUNC(GLOBAL(udivsi3_i4))
1431 #endif /* ! __SH4__ */
1432 #endif
1433
1434 #ifdef L_udivsi3
1435 /* __SH4_SINGLE_ONLY__ keeps this part for link compatibility with
1436    sh2e/sh3e code.  */
1437 #if (! defined(__SH4__) && ! defined (__SH4_SINGLE__)) || defined (__linux__)
1438
1439 !! args in r4 and r5, result in r0, clobbers r4, pr, and t bit
1440         .global GLOBAL(udivsi3)
1441         FUNC(GLOBAL(udivsi3))
1442
1443 #if __SHMEDIA__
1444 #if __SH5__ == 32
1445         .section        .text..SHmedia32,"ax"
1446 #else
1447         .text
1448 #endif
1449         .align  2
1450 #if 0
1451 /* The assembly code that follows is a hand-optimized version of the C
1452    code that follows.  Note that the registers that are modified are
1453    exactly those listed as clobbered in the patterns udivsi3_i1 and
1454    udivsi3_i1_media.
1455         
1456 unsigned 
1457 __udivsi3 (i, j)
1458     unsigned i, j; 
1459 {
1460   register unsigned long long r0 asm ("r0") = 0;
1461   register unsigned long long r18 asm ("r18") = 1;
1462   register unsigned long long r4 asm ("r4") = i;
1463   register unsigned long long r19 asm ("r19") = j;
1464
1465   r19 <<= 31;
1466   r18 <<= 31;
1467   do
1468     if (r4 >= r19)
1469       r0 |= r18, r4 -= r19;
1470   while (r19 >>= 1, r18 >>= 1);
1471
1472   return r0;
1473 }
1474 */
1475 GLOBAL(udivsi3):
1476         pt/l    LOCAL(udivsi3_dontadd), tr2
1477         pt/l    LOCAL(udivsi3_loop), tr1
1478         ptabs/l r18, tr0
1479         movi    0, r0
1480         movi    1, r18
1481         addz.l  r5, r63, r19
1482         addz.l  r4, r63, r4
1483         shlli   r19, 31, r19
1484         shlli   r18, 31, r18
1485 LOCAL(udivsi3_loop):
1486         bgtu    r19, r4, tr2
1487         or      r0, r18, r0
1488         sub     r4, r19, r4
1489 LOCAL(udivsi3_dontadd):
1490         shlri   r18, 1, r18
1491         shlri   r19, 1, r19
1492         bnei    r18, 0, tr1
1493         blink   tr0, r63
1494 #else
1495 GLOBAL(udivsi3):
1496  // inputs: r4,r5
1497  // clobbered: r18,r19,r20,r21,r22,r25,tr0
1498  // result in r0.
1499  addz.l r5,r63,r22
1500  nsb r22,r0
1501  shlld r22,r0,r25
1502  shlri r25,48,r25
1503  movi 0xffffffffffffbb0c,r20 // shift count eqiv 76
1504  sub r20,r25,r21
1505  mmulfx.w r21,r21,r19
1506  mshflo.w r21,r63,r21
1507  ptabs r18,tr0
1508  mmulfx.w r25,r19,r19
1509  sub r20,r0,r0
1510  /* bubble */
1511  msub.w r21,r19,r19
1512  addi r19,-2,r21 /* It would be nice for scheduling to do this add to r21
1513                     before the msub.w, but we need a different value for
1514                     r19 to keep errors under control.  */
1515  mulu.l r4,r21,r18
1516  mmulfx.w r19,r19,r19
1517  shlli r21,15,r21
1518  shlrd r18,r0,r18
1519  mulu.l r18,r22,r20
1520  mmacnfx.wl r25,r19,r21
1521  /* bubble */
1522  sub r4,r20,r25
1523
1524  mulu.l r25,r21,r19
1525  addi r0,14,r0
1526  /* bubble */
1527  shlrd r19,r0,r19
1528  mulu.l r19,r22,r20
1529  add r18,r19,r18
1530  /* bubble */
1531  sub.l r25,r20,r25
1532
1533  mulu.l r25,r21,r19
1534  addz.l r25,r63,r25
1535  sub r25,r22,r25
1536  shlrd r19,r0,r19
1537  mulu.l r19,r22,r20
1538  addi r25,1,r25
1539  add r18,r19,r18
1540
1541  cmpgt r25,r20,r25
1542  add.l r18,r25,r0
1543  blink tr0,r63
1544 #endif
1545 #elif defined (__SHMEDIA__)
1546 /* m5compact-nofpu - more emphasis on code size than on speed, but don't
1547    ignore speed altogether - div1 needs 9 cycles, subc 7 and rotcl 4.
1548    So use a short shmedia loop.  */
1549  // clobbered: r20,r21,r25,tr0,tr1,tr2
1550         .mode   SHmedia
1551         .section        .text..SHmedia32,"ax"
1552         .align  2
1553 GLOBAL(udivsi3):
1554  pt/l LOCAL(udivsi3_dontsub), tr0
1555  pt/l LOCAL(udivsi3_loop), tr1
1556  ptabs/l r18,tr2
1557  shlli r5,32,r25
1558  addi r25,-1,r21
1559  addz.l r4,r63,r20
1560 LOCAL(udivsi3_loop):
1561  shlli r20,1,r20
1562  bgeu/u r21,r20,tr0
1563  sub r20,r21,r20
1564 LOCAL(udivsi3_dontsub):
1565  addi.l r25,-1,r25
1566  bnei r25,-32,tr1
1567  add.l r20,r63,r0
1568  blink tr2,r63
1569 #else /* ! defined (__SHMEDIA__) */
1570 LOCAL(div8):
1571  div1 r5,r4
1572 LOCAL(div7):
1573  div1 r5,r4; div1 r5,r4; div1 r5,r4
1574  div1 r5,r4; div1 r5,r4; div1 r5,r4; rts; div1 r5,r4
1575
1576 LOCAL(divx4):
1577  div1 r5,r4; rotcl r0
1578  div1 r5,r4; rotcl r0
1579  div1 r5,r4; rotcl r0
1580  rts; div1 r5,r4
1581
1582 GLOBAL(udivsi3):
1583  sts.l pr,@-r15
1584  extu.w r5,r0
1585  cmp/eq r5,r0
1586 #ifdef __sh1__
1587  bf LOCAL(large_divisor)
1588 #else
1589  bf/s LOCAL(large_divisor)
1590 #endif
1591  div0u
1592  swap.w r4,r0
1593  shlr16 r4
1594  bsr LOCAL(div8)
1595  shll16 r5
1596  bsr LOCAL(div7)
1597  div1 r5,r4
1598  xtrct r4,r0
1599  xtrct r0,r4
1600  bsr LOCAL(div8)
1601  swap.w r4,r4
1602  bsr LOCAL(div7)
1603  div1 r5,r4
1604  lds.l @r15+,pr
1605  xtrct r4,r0
1606  swap.w r0,r0
1607  rotcl r0
1608  rts
1609  shlr16 r5
1610
1611 LOCAL(large_divisor):
1612 #ifdef __sh1__
1613  div0u
1614 #endif
1615  mov #0,r0
1616  xtrct r4,r0
1617  xtrct r0,r4
1618  bsr LOCAL(divx4)
1619  rotcl r0
1620  bsr LOCAL(divx4)
1621  rotcl r0
1622  bsr LOCAL(divx4)
1623  rotcl r0
1624  bsr LOCAL(divx4)
1625  rotcl r0
1626  lds.l @r15+,pr
1627  rts
1628  rotcl r0
1629
1630         ENDFUNC(GLOBAL(udivsi3))
1631 #endif /* ! __SHMEDIA__ */
1632 #endif /* __SH4__ */
1633 #endif /* L_udivsi3 */
1634
1635 #ifdef L_udivdi3
1636 #ifdef __SHMEDIA__
1637         .mode   SHmedia
1638         .section        .text..SHmedia32,"ax"
1639         .align  2
1640         .global GLOBAL(udivdi3)
1641         FUNC(GLOBAL(udivdi3))
1642 GLOBAL(udivdi3):
1643         shlri r3,1,r4
1644         nsb r4,r22
1645         shlld r3,r22,r6
1646         shlri r6,49,r5
1647         movi 0xffffffffffffbaf1,r21 /* .l shift count 17.  */
1648         sub r21,r5,r1
1649         mmulfx.w r1,r1,r4
1650         mshflo.w r1,r63,r1
1651         sub r63,r22,r20 // r63 == 64 % 64
1652         mmulfx.w r5,r4,r4
1653         pta LOCAL(large_divisor),tr0
1654         addi r20,32,r9
1655         msub.w r1,r4,r1
1656         madd.w r1,r1,r1
1657         mmulfx.w r1,r1,r4
1658         shlri r6,32,r7
1659         bgt/u r9,r63,tr0 // large_divisor
1660         mmulfx.w r5,r4,r4
1661         shlri r2,32+14,r19
1662         addi r22,-31,r0
1663         msub.w r1,r4,r1
1664
1665         mulu.l r1,r7,r4
1666         addi r1,-3,r5
1667         mulu.l r5,r19,r5
1668         sub r63,r4,r4 // Negate to make sure r1 ends up <= 1/r2
1669         shlri r4,2,r4 /* chop off leading %0000000000000000 001.00000000000 - or, as
1670                          the case may be, %0000000000000000 000.11111111111, still */
1671         muls.l r1,r4,r4 /* leaving at least one sign bit.  */
1672         mulu.l r5,r3,r8
1673         mshalds.l r1,r21,r1
1674         shari r4,26,r4
1675         shlld r8,r0,r8
1676         add r1,r4,r1 // 31 bit unsigned reciprocal now in r1 (msb equiv. 0.5)
1677         sub r2,r8,r2
1678         /* Can do second step of 64 : 32 div now, using r1 and the rest in r2.  */
1679
1680         shlri r2,22,r21
1681         mulu.l r21,r1,r21
1682         shlld r5,r0,r8
1683         addi r20,30-22,r0
1684         shlrd r21,r0,r21
1685         mulu.l r21,r3,r5
1686         add r8,r21,r8
1687         mcmpgt.l r21,r63,r21 // See Note 1
1688         addi r20,30,r0
1689         mshfhi.l r63,r21,r21
1690         sub r2,r5,r2
1691         andc r2,r21,r2
1692
1693         /* small divisor: need a third divide step */
1694         mulu.l r2,r1,r7
1695         ptabs r18,tr0
1696         addi r2,1,r2
1697         shlrd r7,r0,r7
1698         mulu.l r7,r3,r5
1699         add r8,r7,r8
1700         sub r2,r3,r2
1701         cmpgt r2,r5,r5
1702         add r8,r5,r2
1703         /* could test r3 here to check for divide by zero.  */
1704         blink tr0,r63
1705
1706 LOCAL(large_divisor):
1707         mmulfx.w r5,r4,r4
1708         shlrd r2,r9,r25
1709         shlri r25,32,r8
1710         msub.w r1,r4,r1
1711
1712         mulu.l r1,r7,r4
1713         addi r1,-3,r5
1714         mulu.l r5,r8,r5
1715         sub r63,r4,r4 // Negate to make sure r1 ends up <= 1/r2
1716         shlri r4,2,r4 /* chop off leading %0000000000000000 001.00000000000 - or, as
1717                          the case may be, %0000000000000000 000.11111111111, still */
1718         muls.l r1,r4,r4 /* leaving at least one sign bit.  */
1719         shlri r5,14-1,r8
1720         mulu.l r8,r7,r5
1721         mshalds.l r1,r21,r1
1722         shari r4,26,r4
1723         add r1,r4,r1 // 31 bit unsigned reciprocal now in r1 (msb equiv. 0.5)
1724         sub r25,r5,r25
1725         /* Can do second step of 64 : 32 div now, using r1 and the rest in r25.  */
1726
1727         shlri r25,22,r21
1728         mulu.l r21,r1,r21
1729         pta LOCAL(no_lo_adj),tr0
1730         addi r22,32,r0
1731         shlri r21,40,r21
1732         mulu.l r21,r7,r5
1733         add r8,r21,r8
1734         shlld r2,r0,r2
1735         sub r25,r5,r25
1736         bgtu/u r7,r25,tr0 // no_lo_adj
1737         addi r8,1,r8
1738         sub r25,r7,r25
1739 LOCAL(no_lo_adj):
1740         mextr4 r2,r25,r2
1741
1742         /* large_divisor: only needs a few adjustments.  */
1743         mulu.l r8,r6,r5
1744         ptabs r18,tr0
1745         /* bubble */
1746         cmpgtu r5,r2,r5
1747         sub r8,r5,r2
1748         blink tr0,r63
1749         ENDFUNC(GLOBAL(udivdi3))
1750 /* Note 1: To shift the result of the second divide stage so that the result
1751    always fits into 32 bits, yet we still reduce the rest sufficiently
1752    would require a lot of instructions to do the shifts just right.  Using
1753    the full 64 bit shift result to multiply with the divisor would require
1754    four extra instructions for the upper 32 bits (shift / mulu / shift / sub).
1755    Fortunately, if the upper 32 bits of the shift result are nonzero, we
1756    know that the rest after taking this partial result into account will
1757    fit into 32 bits.  So we just clear the upper 32 bits of the rest if the
1758    upper 32 bits of the partial result are nonzero.  */
1759 #endif /* __SHMEDIA__ */
1760 #endif /* L_udivdi3 */
1761
1762 #ifdef L_divdi3
1763 #ifdef __SHMEDIA__
1764         .mode   SHmedia
1765         .section        .text..SHmedia32,"ax"
1766         .align  2
1767         .global GLOBAL(divdi3)
1768         FUNC(GLOBAL(divdi3))
1769 GLOBAL(divdi3):
1770         pta GLOBAL(udivdi3),tr0
1771         shari r2,63,r22
1772         shari r3,63,r23
1773         xor r2,r22,r2
1774         xor r3,r23,r3
1775         sub r2,r22,r2
1776         sub r3,r23,r3
1777         beq/u r22,r23,tr0
1778         ptabs r18,tr1
1779         blink tr0,r18
1780         sub r63,r2,r2
1781         blink tr1,r63
1782         ENDFUNC(GLOBAL(divdi3))
1783 #endif /* __SHMEDIA__ */
1784 #endif /* L_divdi3 */
1785
1786 #ifdef L_umoddi3
1787 #ifdef __SHMEDIA__
1788         .mode   SHmedia
1789         .section        .text..SHmedia32,"ax"
1790         .align  2
1791         .global GLOBAL(umoddi3)
1792         FUNC(GLOBAL(umoddi3))
1793 GLOBAL(umoddi3):
1794         shlri r3,1,r4
1795         nsb r4,r22
1796         shlld r3,r22,r6
1797         shlri r6,49,r5
1798         movi 0xffffffffffffbaf1,r21 /* .l shift count 17.  */
1799         sub r21,r5,r1
1800         mmulfx.w r1,r1,r4
1801         mshflo.w r1,r63,r1
1802         sub r63,r22,r20 // r63 == 64 % 64
1803         mmulfx.w r5,r4,r4
1804         pta LOCAL(large_divisor),tr0
1805         addi r20,32,r9
1806         msub.w r1,r4,r1
1807         madd.w r1,r1,r1
1808         mmulfx.w r1,r1,r4
1809         shlri r6,32,r7
1810         bgt/u r9,r63,tr0 // large_divisor
1811         mmulfx.w r5,r4,r4
1812         shlri r2,32+14,r19
1813         addi r22,-31,r0
1814         msub.w r1,r4,r1
1815
1816         mulu.l r1,r7,r4
1817         addi r1,-3,r5
1818         mulu.l r5,r19,r5
1819         sub r63,r4,r4 // Negate to make sure r1 ends up <= 1/r2
1820         shlri r4,2,r4 /* chop off leading %0000000000000000 001.00000000000 - or, as
1821                          the case may be, %0000000000000000 000.11111111111, still */
1822         muls.l r1,r4,r4 /* leaving at least one sign bit.  */
1823         mulu.l r5,r3,r5
1824         mshalds.l r1,r21,r1
1825         shari r4,26,r4
1826         shlld r5,r0,r5
1827         add r1,r4,r1 // 31 bit unsigned reciprocal now in r1 (msb equiv. 0.5)
1828         sub r2,r5,r2
1829         /* Can do second step of 64 : 32 div now, using r1 and the rest in r2.  */
1830
1831         shlri r2,22,r21
1832         mulu.l r21,r1,r21
1833         addi r20,30-22,r0
1834         /* bubble */ /* could test r3 here to check for divide by zero.  */
1835         shlrd r21,r0,r21
1836         mulu.l r21,r3,r5
1837         mcmpgt.l r21,r63,r21 // See Note 1
1838         addi r20,30,r0
1839         mshfhi.l r63,r21,r21
1840         sub r2,r5,r2
1841         andc r2,r21,r2
1842
1843         /* small divisor: need a third divide step */
1844         mulu.l r2,r1,r7
1845         ptabs r18,tr0
1846         sub r2,r3,r8 /* re-use r8 here for rest - r3 */
1847         shlrd r7,r0,r7
1848         mulu.l r7,r3,r5
1849         /* bubble */
1850         addi r8,1,r7
1851         cmpgt r7,r5,r7
1852         cmvne r7,r8,r2
1853         sub r2,r5,r2
1854         blink tr0,r63
1855
1856 LOCAL(large_divisor):
1857         mmulfx.w r5,r4,r4
1858         shlrd r2,r9,r25
1859         shlri r25,32,r8
1860         msub.w r1,r4,r1
1861
1862         mulu.l r1,r7,r4
1863         addi r1,-3,r5
1864         mulu.l r5,r8,r5
1865         sub r63,r4,r4 // Negate to make sure r1 ends up <= 1/r2
1866         shlri r4,2,r4 /* chop off leading %0000000000000000 001.00000000000 - or, as
1867                          the case may be, %0000000000000000 000.11111111111, still */
1868         muls.l r1,r4,r4 /* leaving at least one sign bit.  */
1869         shlri r5,14-1,r8
1870         mulu.l r8,r7,r5
1871         mshalds.l r1,r21,r1
1872         shari r4,26,r4
1873         add r1,r4,r1 // 31 bit unsigned reciprocal now in r1 (msb equiv. 0.5)
1874         sub r25,r5,r25
1875         /* Can do second step of 64 : 32 div now, using r1 and the rest in r25.  */
1876
1877         shlri r25,22,r21
1878         mulu.l r21,r1,r21
1879         pta LOCAL(no_lo_adj),tr0
1880         addi r22,32,r0
1881         shlri r21,40,r21
1882         mulu.l r21,r7,r5
1883         add r8,r21,r8
1884         shlld r2,r0,r2
1885         sub r25,r5,r25
1886         bgtu/u r7,r25,tr0 // no_lo_adj
1887         addi r8,1,r8
1888         sub r25,r7,r25
1889 LOCAL(no_lo_adj):
1890         mextr4 r2,r25,r2
1891
1892         /* large_divisor: only needs a few adjustments.  */
1893         mulu.l r8,r6,r5
1894         ptabs r18,tr0
1895         add r2,r6,r7
1896         cmpgtu r5,r2,r8
1897         cmvne r8,r7,r2
1898         sub r2,r5,r2
1899         shlrd r2,r22,r2
1900         blink tr0,r63
1901         ENDFUNC(GLOBAL(umoddi3))
1902 /* Note 1: To shift the result of the second divide stage so that the result
1903    always fits into 32 bits, yet we still reduce the rest sufficiently
1904    would require a lot of instructions to do the shifts just right.  Using
1905    the full 64 bit shift result to multiply with the divisor would require
1906    four extra instructions for the upper 32 bits (shift / mulu / shift / sub).
1907    Fortunately, if the upper 32 bits of the shift result are nonzero, we
1908    know that the rest after taking this partial result into account will
1909    fit into 32 bits.  So we just clear the upper 32 bits of the rest if the
1910    upper 32 bits of the partial result are nonzero.  */
1911 #endif /* __SHMEDIA__ */
1912 #endif /* L_umoddi3 */
1913
1914 #ifdef L_moddi3
1915 #ifdef __SHMEDIA__
1916         .mode   SHmedia
1917         .section        .text..SHmedia32,"ax"
1918         .align  2
1919         .global GLOBAL(moddi3)
1920         FUNC(GLOBAL(moddi3))
1921 GLOBAL(moddi3):
1922         pta GLOBAL(umoddi3),tr0
1923         shari r2,63,r22
1924         shari r3,63,r23
1925         xor r2,r22,r2
1926         xor r3,r23,r3
1927         sub r2,r22,r2
1928         sub r3,r23,r3
1929         beq/u r22,r63,tr0
1930         ptabs r18,tr1
1931         blink tr0,r18
1932         sub r63,r2,r2
1933         blink tr1,r63
1934         ENDFUNC(GLOBAL(moddi3))
1935 #endif /* __SHMEDIA__ */
1936 #endif /* L_moddi3 */
1937
1938 #ifdef L_set_fpscr
1939 #if defined (__SH2E__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) || __SH5__ == 32
1940 #ifdef __SH5__
1941         .mode   SHcompact
1942 #endif
1943         .global GLOBAL(set_fpscr)
1944         FUNC(GLOBAL(set_fpscr))
1945 GLOBAL(set_fpscr):
1946         lds r4,fpscr
1947 #ifdef __PIC__
1948         mov.l   r12,@-r15
1949         mova    LOCAL(set_fpscr_L0),r0
1950         mov.l   LOCAL(set_fpscr_L0),r12
1951         add     r0,r12
1952         mov.l   LOCAL(set_fpscr_L1),r0
1953         mov.l   @(r0,r12),r1
1954         mov.l   @r15+,r12
1955 #else
1956         mov.l LOCAL(set_fpscr_L1),r1
1957 #endif
1958         swap.w r4,r0
1959         or #24,r0
1960 #ifndef FMOVD_WORKS
1961         xor #16,r0
1962 #endif
1963 #if defined(__SH4__)
1964         swap.w r0,r3
1965         mov.l r3,@(4,r1)
1966 #else /* defined (__SH2E__) || defined(__SH3E__) || defined(__SH4_SINGLE*__) */
1967         swap.w r0,r2
1968         mov.l r2,@r1
1969 #endif
1970 #ifndef FMOVD_WORKS
1971         xor #8,r0
1972 #else
1973         xor #24,r0
1974 #endif
1975 #if defined(__SH4__)
1976         swap.w r0,r2
1977         rts
1978         mov.l r2,@r1
1979 #else /* defined(__SH2E__) || defined(__SH3E__) || defined(__SH4_SINGLE*__) */
1980         swap.w r0,r3
1981         rts
1982         mov.l r3,@(4,r1)
1983 #endif
1984         .align 2
1985 #ifdef __PIC__
1986 LOCAL(set_fpscr_L0):
1987         .long _GLOBAL_OFFSET_TABLE_
1988 LOCAL(set_fpscr_L1):
1989         .long GLOBAL(fpscr_values@GOT)
1990 #else
1991 LOCAL(set_fpscr_L1):
1992         .long GLOBAL(fpscr_values)
1993 #endif
1994
1995         ENDFUNC(GLOBAL(set_fpscr))
1996 #ifndef NO_FPSCR_VALUES
1997 #ifdef __ELF__
1998         .comm   GLOBAL(fpscr_values),8,4
1999 #else
2000         .comm   GLOBAL(fpscr_values),8
2001 #endif /* ELF */
2002 #endif /* NO_FPSCR_VALUES */
2003 #endif /* SH2E / SH3E / SH4 */
2004 #endif /* L_set_fpscr */
2005 #ifdef L_ic_invalidate
2006 #if __SH5__ == 32
2007         .mode   SHmedia
2008         .section        .text..SHmedia32,"ax"
2009         .align  2
2010         .global GLOBAL(init_trampoline)
2011         FUNC(GLOBAL(init_trampoline))
2012 GLOBAL(init_trampoline):
2013         st.l    r0,8,r2
2014 #ifdef __LITTLE_ENDIAN__
2015         movi    9,r20
2016         shori   0x402b,r20
2017         shori   0xd101,r20
2018         shori   0xd002,r20
2019 #else
2020         movi    0xffffffffffffd002,r20
2021         shori   0xd101,r20
2022         shori   0x402b,r20
2023         shori   9,r20
2024 #endif
2025         st.q    r0,0,r20
2026         st.l    r0,12,r3
2027         .global GLOBAL(ic_invalidate)
2028         FUNC(GLOBAL(ic_invalidate))
2029 GLOBAL(ic_invalidate):
2030         ocbwb   r0,0
2031         synco
2032         icbi    r0, 0
2033         ptabs   r18, tr0
2034         synci
2035         blink   tr0, r63
2036
2037         ENDFUNC(GLOBAL(ic_invalidate))
2038         ENDFUNC(GLOBAL(init_trampoline))
2039 #elif defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__)
2040         .global GLOBAL(ic_invalidate)
2041         FUNC(GLOBAL(ic_invalidate))
2042 GLOBAL(ic_invalidate):
2043         ocbwb   @r4
2044         mova    0f,r0
2045         mov.w   1f,r1
2046 /* Compute how many cache lines 0f is away from r4.  */
2047         sub     r0,r4
2048         and     r1,r4
2049 /* Prepare to branch to 0f plus the cache-line offset.  */
2050         add     # 0f - 1f,r4
2051         braf    r4
2052         nop
2053 1:
2054         .short  0x1fe0
2055         .p2align 5
2056 /* This must be aligned to the beginning of a cache line.  */
2057 0:
2058         .rept   256 /* There are 256 cache lines of 32 bytes.  */
2059         rts
2060         .rept   15
2061         nop
2062         .endr
2063         .endr
2064
2065         ENDFUNC(GLOBAL(ic_invalidate))
2066 #endif /* SH4 */
2067 #endif /* L_ic_invalidate */
2068
2069 #if defined (__SH5__) && __SH5__ == 32
2070 #ifdef L_shcompact_call_trampoline
2071         .section        .rodata
2072         .align  1
2073 LOCAL(ct_main_table):
2074 .word   LOCAL(ct_r2_fp) - datalabel LOCAL(ct_main_label)
2075 .word   LOCAL(ct_r2_ld) - datalabel LOCAL(ct_main_label)
2076 .word   LOCAL(ct_r2_pop) - datalabel LOCAL(ct_main_label)
2077 .word   LOCAL(ct_r3_fp) - datalabel LOCAL(ct_main_label)
2078 .word   LOCAL(ct_r3_ld) - datalabel LOCAL(ct_main_label)
2079 .word   LOCAL(ct_r3_pop) - datalabel LOCAL(ct_main_label)
2080 .word   LOCAL(ct_r4_fp) - datalabel LOCAL(ct_main_label)
2081 .word   LOCAL(ct_r4_ld) - datalabel LOCAL(ct_main_label)
2082 .word   LOCAL(ct_r4_pop) - datalabel LOCAL(ct_main_label)
2083 .word   LOCAL(ct_r5_fp) - datalabel LOCAL(ct_main_label)
2084 .word   LOCAL(ct_r5_ld) - datalabel LOCAL(ct_main_label)
2085 .word   LOCAL(ct_r5_pop) - datalabel LOCAL(ct_main_label)
2086 .word   LOCAL(ct_r6_fph) - datalabel LOCAL(ct_main_label)
2087 .word   LOCAL(ct_r6_fpl) - datalabel LOCAL(ct_main_label)
2088 .word   LOCAL(ct_r6_ld) - datalabel LOCAL(ct_main_label)
2089 .word   LOCAL(ct_r6_pop) - datalabel LOCAL(ct_main_label)
2090 .word   LOCAL(ct_r7_fph) - datalabel LOCAL(ct_main_label)
2091 .word   LOCAL(ct_r7_fpl) - datalabel LOCAL(ct_main_label)
2092 .word   LOCAL(ct_r7_ld) - datalabel LOCAL(ct_main_label)
2093 .word   LOCAL(ct_r7_pop) - datalabel LOCAL(ct_main_label)
2094 .word   LOCAL(ct_r8_fph) - datalabel LOCAL(ct_main_label)
2095 .word   LOCAL(ct_r8_fpl) - datalabel LOCAL(ct_main_label)
2096 .word   LOCAL(ct_r8_ld) - datalabel LOCAL(ct_main_label)
2097 .word   LOCAL(ct_r8_pop) - datalabel LOCAL(ct_main_label)
2098 .word   LOCAL(ct_r9_fph) - datalabel LOCAL(ct_main_label)
2099 .word   LOCAL(ct_r9_fpl) - datalabel LOCAL(ct_main_label)
2100 .word   LOCAL(ct_r9_ld) - datalabel LOCAL(ct_main_label)
2101 .word   LOCAL(ct_r9_pop) - datalabel LOCAL(ct_main_label)
2102 .word   LOCAL(ct_pop_seq) - datalabel LOCAL(ct_main_label)
2103 .word   LOCAL(ct_pop_seq) - datalabel LOCAL(ct_main_label)
2104 .word   LOCAL(ct_r9_pop) - datalabel LOCAL(ct_main_label)
2105 .word   LOCAL(ct_ret_wide) - datalabel LOCAL(ct_main_label)
2106 .word   LOCAL(ct_call_func) - datalabel LOCAL(ct_main_label)
2107         .mode   SHmedia
2108         .section        .text..SHmedia32, "ax"
2109         .align  2
2110         
2111      /* This function loads 64-bit general-purpose registers from the
2112         stack, from a memory address contained in them or from an FP
2113         register, according to a cookie passed in r1.  Its execution
2114         time is linear on the number of registers that actually have
2115         to be copied.  See sh.h for details on the actual bit pattern.
2116
2117         The function to be called is passed in r0.  If a 32-bit return
2118         value is expected, the actual function will be tail-called,
2119         otherwise the return address will be stored in r10 (that the
2120         caller should expect to be clobbered) and the return value
2121         will be expanded into r2/r3 upon return.  */
2122         
2123         .global GLOBAL(GCC_shcompact_call_trampoline)
2124         FUNC(GLOBAL(GCC_shcompact_call_trampoline))
2125 GLOBAL(GCC_shcompact_call_trampoline):
2126         ptabs/l r0, tr0 /* Prepare to call the actual function.  */
2127         movi    ((datalabel LOCAL(ct_main_table) - 31 * 2) >> 16) & 65535, r0
2128         pt/l    LOCAL(ct_loop), tr1
2129         addz.l  r1, r63, r1
2130         shori   ((datalabel LOCAL(ct_main_table) - 31 * 2)) & 65535, r0
2131 LOCAL(ct_loop):
2132         nsb     r1, r28
2133         shlli   r28, 1, r29
2134         ldx.w   r0, r29, r30
2135 LOCAL(ct_main_label):
2136         ptrel/l r30, tr2
2137         blink   tr2, r63
2138 LOCAL(ct_r2_fp):        /* Copy r2 from an FP register.  */
2139         /* It must be dr0, so just do it.  */
2140         fmov.dq dr0, r2
2141         movi    7, r30
2142         shlli   r30, 29, r31
2143         andc    r1, r31, r1
2144         blink   tr1, r63
2145 LOCAL(ct_r3_fp):        /* Copy r3 from an FP register.  */
2146         /* It is either dr0 or dr2.  */
2147         movi    7, r30
2148         shlri   r1, 26, r32
2149         shlli   r30, 26, r31
2150         andc    r1, r31, r1
2151         fmov.dq dr0, r3
2152         beqi/l  r32, 4, tr1
2153         fmov.dq dr2, r3
2154         blink   tr1, r63
2155 LOCAL(ct_r4_fp):        /* Copy r4 from an FP register.  */
2156         shlri   r1, 23 - 3, r34
2157         andi    r34, 3 << 3, r33
2158         addi    r33, LOCAL(ct_r4_fp_copy) - datalabel LOCAL(ct_r4_fp_base), r32
2159 LOCAL(ct_r4_fp_base):
2160         ptrel/l r32, tr2
2161         movi    7, r30
2162         shlli   r30, 23, r31
2163         andc    r1, r31, r1
2164         blink   tr2, r63
2165 LOCAL(ct_r4_fp_copy):
2166         fmov.dq dr0, r4
2167         blink   tr1, r63
2168         fmov.dq dr2, r4
2169         blink   tr1, r63
2170         fmov.dq dr4, r4
2171         blink   tr1, r63
2172 LOCAL(ct_r5_fp):        /* Copy r5 from an FP register.  */
2173         shlri   r1, 20 - 3, r34
2174         andi    r34, 3 << 3, r33
2175         addi    r33, LOCAL(ct_r5_fp_copy) - datalabel LOCAL(ct_r5_fp_base), r32
2176 LOCAL(ct_r5_fp_base):
2177         ptrel/l r32, tr2
2178         movi    7, r30
2179         shlli   r30, 20, r31
2180         andc    r1, r31, r1
2181         blink   tr2, r63
2182 LOCAL(ct_r5_fp_copy):
2183         fmov.dq dr0, r5
2184         blink   tr1, r63
2185         fmov.dq dr2, r5
2186         blink   tr1, r63
2187         fmov.dq dr4, r5
2188         blink   tr1, r63
2189         fmov.dq dr6, r5
2190         blink   tr1, r63
2191 LOCAL(ct_r6_fph):       /* Copy r6 from a high FP register.  */
2192         /* It must be dr8.  */
2193         fmov.dq dr8, r6
2194         movi    15, r30
2195         shlli   r30, 16, r31
2196         andc    r1, r31, r1
2197         blink   tr1, r63
2198 LOCAL(ct_r6_fpl):       /* Copy r6 from a low FP register.  */
2199         shlri   r1, 16 - 3, r34
2200         andi    r34, 3 << 3, r33
2201         addi    r33, LOCAL(ct_r6_fp_copy) - datalabel LOCAL(ct_r6_fp_base), r32
2202 LOCAL(ct_r6_fp_base):
2203         ptrel/l r32, tr2
2204         movi    7, r30
2205         shlli   r30, 16, r31
2206         andc    r1, r31, r1
2207         blink   tr2, r63
2208 LOCAL(ct_r6_fp_copy):
2209         fmov.dq dr0, r6
2210         blink   tr1, r63
2211         fmov.dq dr2, r6
2212         blink   tr1, r63
2213         fmov.dq dr4, r6
2214         blink   tr1, r63
2215         fmov.dq dr6, r6
2216         blink   tr1, r63
2217 LOCAL(ct_r7_fph):       /* Copy r7 from a high FP register.  */
2218         /* It is either dr8 or dr10.  */
2219         movi    15 << 12, r31
2220         shlri   r1, 12, r32
2221         andc    r1, r31, r1
2222         fmov.dq dr8, r7
2223         beqi/l  r32, 8, tr1
2224         fmov.dq dr10, r7
2225         blink   tr1, r63
2226 LOCAL(ct_r7_fpl):       /* Copy r7 from a low FP register.  */
2227         shlri   r1, 12 - 3, r34
2228         andi    r34, 3 << 3, r33
2229         addi    r33, LOCAL(ct_r7_fp_copy) - datalabel LOCAL(ct_r7_fp_base), r32
2230 LOCAL(ct_r7_fp_base):
2231         ptrel/l r32, tr2
2232         movi    7 << 12, r31
2233         andc    r1, r31, r1
2234         blink   tr2, r63
2235 LOCAL(ct_r7_fp_copy):
2236         fmov.dq dr0, r7
2237         blink   tr1, r63
2238         fmov.dq dr2, r7
2239         blink   tr1, r63
2240         fmov.dq dr4, r7
2241         blink   tr1, r63
2242         fmov.dq dr6, r7
2243         blink   tr1, r63
2244 LOCAL(ct_r8_fph):       /* Copy r8 from a high FP register.  */
2245         /* It is either dr8 or dr10.  */
2246         movi    15 << 8, r31
2247         andi    r1, 1 << 8, r32
2248         andc    r1, r31, r1
2249         fmov.dq dr8, r8
2250         beq/l   r32, r63, tr1
2251         fmov.dq dr10, r8
2252         blink   tr1, r63
2253 LOCAL(ct_r8_fpl):       /* Copy r8 from a low FP register.  */
2254         shlri   r1, 8 - 3, r34
2255         andi    r34, 3 << 3, r33
2256         addi    r33, LOCAL(ct_r8_fp_copy) - datalabel LOCAL(ct_r8_fp_base), r32
2257 LOCAL(ct_r8_fp_base):
2258         ptrel/l r32, tr2
2259         movi    7 << 8, r31
2260         andc    r1, r31, r1
2261         blink   tr2, r63
2262 LOCAL(ct_r8_fp_copy):
2263         fmov.dq dr0, r8
2264         blink   tr1, r63
2265         fmov.dq dr2, r8
2266         blink   tr1, r63
2267         fmov.dq dr4, r8
2268         blink   tr1, r63
2269         fmov.dq dr6, r8
2270         blink   tr1, r63
2271 LOCAL(ct_r9_fph):       /* Copy r9 from a high FP register.  */
2272         /* It is either dr8 or dr10.  */
2273         movi    15 << 4, r31
2274         andi    r1, 1 << 4, r32
2275         andc    r1, r31, r1
2276         fmov.dq dr8, r9
2277         beq/l   r32, r63, tr1
2278         fmov.dq dr10, r9
2279         blink   tr1, r63
2280 LOCAL(ct_r9_fpl):       /* Copy r9 from a low FP register.  */
2281         shlri   r1, 4 - 3, r34
2282         andi    r34, 3 << 3, r33
2283         addi    r33, LOCAL(ct_r9_fp_copy) - datalabel LOCAL(ct_r9_fp_base), r32
2284 LOCAL(ct_r9_fp_base):
2285         ptrel/l r32, tr2
2286         movi    7 << 4, r31
2287         andc    r1, r31, r1
2288         blink   tr2, r63
2289 LOCAL(ct_r9_fp_copy):
2290         fmov.dq dr0, r9
2291         blink   tr1, r63
2292         fmov.dq dr2, r9
2293         blink   tr1, r63
2294         fmov.dq dr4, r9
2295         blink   tr1, r63
2296         fmov.dq dr6, r9
2297         blink   tr1, r63
2298 LOCAL(ct_r2_ld):        /* Copy r2 from a memory address.  */
2299         pt/l    LOCAL(ct_r2_load), tr2
2300         movi    3, r30
2301         shlli   r30, 29, r31
2302         and     r1, r31, r32
2303         andc    r1, r31, r1
2304         beq/l   r31, r32, tr2
2305         addi.l  r2, 8, r3
2306         ldx.q   r2, r63, r2
2307         /* Fall through.  */
2308 LOCAL(ct_r3_ld):        /* Copy r3 from a memory address.  */
2309         pt/l    LOCAL(ct_r3_load), tr2
2310         movi    3, r30
2311         shlli   r30, 26, r31
2312         and     r1, r31, r32
2313         andc    r1, r31, r1
2314         beq/l   r31, r32, tr2
2315         addi.l  r3, 8, r4
2316         ldx.q   r3, r63, r3
2317 LOCAL(ct_r4_ld):        /* Copy r4 from a memory address.  */
2318         pt/l    LOCAL(ct_r4_load), tr2
2319         movi    3, r30
2320         shlli   r30, 23, r31
2321         and     r1, r31, r32
2322         andc    r1, r31, r1
2323         beq/l   r31, r32, tr2
2324         addi.l  r4, 8, r5
2325         ldx.q   r4, r63, r4
2326 LOCAL(ct_r5_ld):        /* Copy r5 from a memory address.  */
2327         pt/l    LOCAL(ct_r5_load), tr2
2328         movi    3, r30
2329         shlli   r30, 20, r31
2330         and     r1, r31, r32
2331         andc    r1, r31, r1
2332         beq/l   r31, r32, tr2
2333         addi.l  r5, 8, r6
2334         ldx.q   r5, r63, r5
2335 LOCAL(ct_r6_ld):        /* Copy r6 from a memory address.  */
2336         pt/l    LOCAL(ct_r6_load), tr2
2337         movi    3 << 16, r31
2338         and     r1, r31, r32
2339         andc    r1, r31, r1
2340         beq/l   r31, r32, tr2
2341         addi.l  r6, 8, r7
2342         ldx.q   r6, r63, r6
2343 LOCAL(ct_r7_ld):        /* Copy r7 from a memory address.  */
2344         pt/l    LOCAL(ct_r7_load), tr2
2345         movi    3 << 12, r31
2346         and     r1, r31, r32
2347         andc    r1, r31, r1
2348         beq/l   r31, r32, tr2
2349         addi.l  r7, 8, r8
2350         ldx.q   r7, r63, r7
2351 LOCAL(ct_r8_ld):        /* Copy r8 from a memory address.  */
2352         pt/l    LOCAL(ct_r8_load), tr2
2353         movi    3 << 8, r31
2354         and     r1, r31, r32
2355         andc    r1, r31, r1
2356         beq/l   r31, r32, tr2
2357         addi.l  r8, 8, r9
2358         ldx.q   r8, r63, r8
2359 LOCAL(ct_r9_ld):        /* Copy r9 from a memory address.  */
2360         pt/l    LOCAL(ct_check_tramp), tr2
2361         ldx.q   r9, r63, r9
2362         blink   tr2, r63
2363 LOCAL(ct_r2_load):
2364         ldx.q   r2, r63, r2
2365         blink   tr1, r63
2366 LOCAL(ct_r3_load):
2367         ldx.q   r3, r63, r3
2368         blink   tr1, r63
2369 LOCAL(ct_r4_load):
2370         ldx.q   r4, r63, r4
2371         blink   tr1, r63
2372 LOCAL(ct_r5_load):
2373         ldx.q   r5, r63, r5
2374         blink   tr1, r63
2375 LOCAL(ct_r6_load):
2376         ldx.q   r6, r63, r6
2377         blink   tr1, r63
2378 LOCAL(ct_r7_load):
2379         ldx.q   r7, r63, r7
2380         blink   tr1, r63
2381 LOCAL(ct_r8_load):
2382         ldx.q   r8, r63, r8
2383         blink   tr1, r63
2384 LOCAL(ct_r2_pop):       /* Pop r2 from the stack.  */
2385         movi    1, r30
2386         ldx.q   r15, r63, r2
2387         shlli   r30, 29, r31
2388         addi.l  r15, 8, r15
2389         andc    r1, r31, r1
2390         blink   tr1, r63
2391 LOCAL(ct_r3_pop):       /* Pop r3 from the stack.  */
2392         movi    1, r30
2393         ldx.q   r15, r63, r3
2394         shlli   r30, 26, r31
2395         addi.l  r15, 8, r15
2396         andc    r1, r31, r1
2397         blink   tr1, r63
2398 LOCAL(ct_r4_pop):       /* Pop r4 from the stack.  */
2399         movi    1, r30
2400         ldx.q   r15, r63, r4
2401         shlli   r30, 23, r31
2402         addi.l  r15, 8, r15
2403         andc    r1, r31, r1
2404         blink   tr1, r63
2405 LOCAL(ct_r5_pop):       /* Pop r5 from the stack.  */
2406         movi    1, r30
2407         ldx.q   r15, r63, r5
2408         shlli   r30, 20, r31
2409         addi.l  r15, 8, r15
2410         andc    r1, r31, r1
2411         blink   tr1, r63
2412 LOCAL(ct_r6_pop):       /* Pop r6 from the stack.  */
2413         movi    1, r30
2414         ldx.q   r15, r63, r6
2415         shlli   r30, 16, r31
2416         addi.l  r15, 8, r15
2417         andc    r1, r31, r1
2418         blink   tr1, r63
2419 LOCAL(ct_r7_pop):       /* Pop r7 from the stack.  */
2420         ldx.q   r15, r63, r7
2421         movi    1 << 12, r31
2422         addi.l  r15, 8, r15
2423         andc    r1, r31, r1
2424         blink   tr1, r63
2425 LOCAL(ct_r8_pop):       /* Pop r8 from the stack.  */
2426         ldx.q   r15, r63, r8
2427         movi    1 << 8, r31
2428         addi.l  r15, 8, r15
2429         andc    r1, r31, r1
2430         blink   tr1, r63
2431 LOCAL(ct_pop_seq):      /* Pop a sequence of registers off the stack.  */
2432         andi    r1, 7 << 1, r30
2433         movi    (LOCAL(ct_end_of_pop_seq) >> 16) & 65535, r32
2434         shlli   r30, 2, r31
2435         shori   LOCAL(ct_end_of_pop_seq) & 65535, r32
2436         sub.l   r32, r31, r33
2437         ptabs/l r33, tr2
2438         blink   tr2, r63
2439 LOCAL(ct_start_of_pop_seq):     /* Beginning of pop sequence.  */
2440         ldx.q   r15, r63, r3
2441         addi.l  r15, 8, r15
2442         ldx.q   r15, r63, r4
2443         addi.l  r15, 8, r15
2444         ldx.q   r15, r63, r5
2445         addi.l  r15, 8, r15
2446         ldx.q   r15, r63, r6
2447         addi.l  r15, 8, r15
2448         ldx.q   r15, r63, r7
2449         addi.l  r15, 8, r15
2450         ldx.q   r15, r63, r8
2451         addi.l  r15, 8, r15
2452 LOCAL(ct_r9_pop):       /* Pop r9 from the stack.  */
2453         ldx.q   r15, r63, r9
2454         addi.l  r15, 8, r15
2455 LOCAL(ct_end_of_pop_seq): /* Label used to compute first pop instruction.  */
2456 LOCAL(ct_check_tramp):  /* Check whether we need a trampoline.  */
2457         pt/u    LOCAL(ct_ret_wide), tr2
2458         andi    r1, 1, r1
2459         bne/u   r1, r63, tr2
2460 LOCAL(ct_call_func):    /* Just branch to the function.  */
2461         blink   tr0, r63
2462 LOCAL(ct_ret_wide):     /* Call the function, so that we can unpack its 
2463                            64-bit return value.  */
2464         add.l   r18, r63, r10
2465         blink   tr0, r18
2466         ptabs   r10, tr0
2467 #if __LITTLE_ENDIAN__
2468         shari   r2, 32, r3
2469         add.l   r2, r63, r2
2470 #else
2471         add.l   r2, r63, r3
2472         shari   r2, 32, r2
2473 #endif
2474         blink   tr0, r63
2475
2476         ENDFUNC(GLOBAL(GCC_shcompact_call_trampoline))
2477 #endif /* L_shcompact_call_trampoline */
2478
2479 #ifdef L_shcompact_return_trampoline
2480      /* This function does the converse of the code in `ret_wide'
2481         above.  It is tail-called by SHcompact functions returning
2482         64-bit non-floating-point values, to pack the 32-bit values in
2483         r2 and r3 into r2.  */
2484
2485         .mode   SHmedia
2486         .section        .text..SHmedia32, "ax"
2487         .align  2
2488         .global GLOBAL(GCC_shcompact_return_trampoline)
2489         FUNC(GLOBAL(GCC_shcompact_return_trampoline))
2490 GLOBAL(GCC_shcompact_return_trampoline):
2491         ptabs/l r18, tr0
2492 #if __LITTLE_ENDIAN__
2493         addz.l  r2, r63, r2
2494         shlli   r3, 32, r3
2495 #else
2496         addz.l  r3, r63, r3
2497         shlli   r2, 32, r2
2498 #endif
2499         or      r3, r2, r2
2500         blink   tr0, r63
2501
2502         ENDFUNC(GLOBAL(GCC_shcompact_return_trampoline))
2503 #endif /* L_shcompact_return_trampoline */
2504
2505 #ifdef L_shcompact_incoming_args
2506         .section        .rodata
2507         .align  1
2508 LOCAL(ia_main_table):
2509 .word   1 /* Invalid, just loop */
2510 .word   LOCAL(ia_r2_ld) - datalabel LOCAL(ia_main_label)
2511 .word   LOCAL(ia_r2_push) - datalabel LOCAL(ia_main_label)
2512 .word   1 /* Invalid, just loop */
2513 .word   LOCAL(ia_r3_ld) - datalabel LOCAL(ia_main_label)
2514 .word   LOCAL(ia_r3_push) - datalabel LOCAL(ia_main_label)
2515 .word   1 /* Invalid, just loop */
2516 .word   LOCAL(ia_r4_ld) - datalabel LOCAL(ia_main_label)
2517 .word   LOCAL(ia_r4_push) - datalabel LOCAL(ia_main_label)
2518 .word   1 /* Invalid, just loop */
2519 .word   LOCAL(ia_r5_ld) - datalabel LOCAL(ia_main_label)
2520 .word   LOCAL(ia_r5_push) - datalabel LOCAL(ia_main_label)
2521 .word   1 /* Invalid, just loop */
2522 .word   1 /* Invalid, just loop */
2523 .word   LOCAL(ia_r6_ld) - datalabel LOCAL(ia_main_label)
2524 .word   LOCAL(ia_r6_push) - datalabel LOCAL(ia_main_label)
2525 .word   1 /* Invalid, just loop */
2526 .word   1 /* Invalid, just loop */
2527 .word   LOCAL(ia_r7_ld) - datalabel LOCAL(ia_main_label)
2528 .word   LOCAL(ia_r7_push) - datalabel LOCAL(ia_main_label)
2529 .word   1 /* Invalid, just loop */
2530 .word   1 /* Invalid, just loop */
2531 .word   LOCAL(ia_r8_ld) - datalabel LOCAL(ia_main_label)
2532 .word   LOCAL(ia_r8_push) - datalabel LOCAL(ia_main_label)
2533 .word   1 /* Invalid, just loop */
2534 .word   1 /* Invalid, just loop */
2535 .word   LOCAL(ia_r9_ld) - datalabel LOCAL(ia_main_label)
2536 .word   LOCAL(ia_r9_push) - datalabel LOCAL(ia_main_label)
2537 .word   LOCAL(ia_push_seq) - datalabel LOCAL(ia_main_label)
2538 .word   LOCAL(ia_push_seq) - datalabel LOCAL(ia_main_label)
2539 .word   LOCAL(ia_r9_push) - datalabel LOCAL(ia_main_label)
2540 .word   LOCAL(ia_return) - datalabel LOCAL(ia_main_label)
2541 .word   LOCAL(ia_return) - datalabel LOCAL(ia_main_label)
2542         .mode   SHmedia
2543         .section        .text..SHmedia32, "ax"
2544         .align  2
2545         
2546      /* This function stores 64-bit general-purpose registers back in
2547         the stack, and loads the address in which each register
2548         was stored into itself.  The lower 32 bits of r17 hold the address
2549         to begin storing, and the upper 32 bits of r17 hold the cookie.
2550         Its execution time is linear on the
2551         number of registers that actually have to be copied, and it is
2552         optimized for structures larger than 64 bits, as opposed to
2553         individual `long long' arguments.  See sh.h for details on the
2554         actual bit pattern.  */
2555         
2556         .global GLOBAL(GCC_shcompact_incoming_args)
2557         FUNC(GLOBAL(GCC_shcompact_incoming_args))
2558 GLOBAL(GCC_shcompact_incoming_args):
2559         ptabs/l r18, tr0        /* Prepare to return.  */
2560         shlri   r17, 32, r0     /* Load the cookie.  */
2561         movi    ((datalabel LOCAL(ia_main_table) - 31 * 2) >> 16) & 65535, r43
2562         pt/l    LOCAL(ia_loop), tr1
2563         add.l   r17, r63, r17
2564         shori   ((datalabel LOCAL(ia_main_table) - 31 * 2)) & 65535, r43
2565 LOCAL(ia_loop):
2566         nsb     r0, r36
2567         shlli   r36, 1, r37
2568         ldx.w   r43, r37, r38
2569 LOCAL(ia_main_label):
2570         ptrel/l r38, tr2
2571         blink   tr2, r63
2572 LOCAL(ia_r2_ld):        /* Store r2 and load its address.  */
2573         movi    3, r38
2574         shlli   r38, 29, r39
2575         and     r0, r39, r40
2576         andc    r0, r39, r0
2577         stx.q   r17, r63, r2
2578         add.l   r17, r63, r2
2579         addi.l  r17, 8, r17
2580         beq/u   r39, r40, tr1
2581 LOCAL(ia_r3_ld):        /* Store r3 and load its address.  */
2582         movi    3, r38
2583         shlli   r38, 26, r39
2584         and     r0, r39, r40
2585         andc    r0, r39, r0
2586         stx.q   r17, r63, r3
2587         add.l   r17, r63, r3
2588         addi.l  r17, 8, r17
2589         beq/u   r39, r40, tr1
2590 LOCAL(ia_r4_ld):        /* Store r4 and load its address.  */
2591         movi    3, r38
2592         shlli   r38, 23, r39
2593         and     r0, r39, r40
2594         andc    r0, r39, r0
2595         stx.q   r17, r63, r4
2596         add.l   r17, r63, r4
2597         addi.l  r17, 8, r17
2598         beq/u   r39, r40, tr1
2599 LOCAL(ia_r5_ld):        /* Store r5 and load its address.  */
2600         movi    3, r38
2601         shlli   r38, 20, r39
2602         and     r0, r39, r40
2603         andc    r0, r39, r0
2604         stx.q   r17, r63, r5
2605         add.l   r17, r63, r5
2606         addi.l  r17, 8, r17
2607         beq/u   r39, r40, tr1
2608 LOCAL(ia_r6_ld):        /* Store r6 and load its address.  */
2609         movi    3, r38
2610         shlli   r38, 16, r39
2611         and     r0, r39, r40
2612         andc    r0, r39, r0
2613         stx.q   r17, r63, r6
2614         add.l   r17, r63, r6
2615         addi.l  r17, 8, r17
2616         beq/u   r39, r40, tr1
2617 LOCAL(ia_r7_ld):        /* Store r7 and load its address.  */
2618         movi    3 << 12, r39
2619         and     r0, r39, r40
2620         andc    r0, r39, r0
2621         stx.q   r17, r63, r7
2622         add.l   r17, r63, r7
2623         addi.l  r17, 8, r17
2624         beq/u   r39, r40, tr1
2625 LOCAL(ia_r8_ld):        /* Store r8 and load its address.  */
2626         movi    3 << 8, r39
2627         and     r0, r39, r40
2628         andc    r0, r39, r0
2629         stx.q   r17, r63, r8
2630         add.l   r17, r63, r8
2631         addi.l  r17, 8, r17
2632         beq/u   r39, r40, tr1
2633 LOCAL(ia_r9_ld):        /* Store r9 and load its address.  */
2634         stx.q   r17, r63, r9
2635         add.l   r17, r63, r9
2636         blink   tr0, r63
2637 LOCAL(ia_r2_push):      /* Push r2 onto the stack.  */
2638         movi    1, r38
2639         shlli   r38, 29, r39
2640         andc    r0, r39, r0
2641         stx.q   r17, r63, r2
2642         addi.l  r17, 8, r17
2643         blink   tr1, r63
2644 LOCAL(ia_r3_push):      /* Push r3 onto the stack.  */
2645         movi    1, r38
2646         shlli   r38, 26, r39
2647         andc    r0, r39, r0
2648         stx.q   r17, r63, r3
2649         addi.l  r17, 8, r17
2650         blink   tr1, r63
2651 LOCAL(ia_r4_push):      /* Push r4 onto the stack.  */
2652         movi    1, r38
2653         shlli   r38, 23, r39
2654         andc    r0, r39, r0
2655         stx.q   r17, r63, r4
2656         addi.l  r17, 8, r17
2657         blink   tr1, r63
2658 LOCAL(ia_r5_push):      /* Push r5 onto the stack.  */
2659         movi    1, r38
2660         shlli   r38, 20, r39
2661         andc    r0, r39, r0
2662         stx.q   r17, r63, r5
2663         addi.l  r17, 8, r17
2664         blink   tr1, r63
2665 LOCAL(ia_r6_push):      /* Push r6 onto the stack.  */
2666         movi    1, r38
2667         shlli   r38, 16, r39
2668         andc    r0, r39, r0
2669         stx.q   r17, r63, r6
2670         addi.l  r17, 8, r17
2671         blink   tr1, r63
2672 LOCAL(ia_r7_push):      /* Push r7 onto the stack.  */
2673         movi    1 << 12, r39
2674         andc    r0, r39, r0
2675         stx.q   r17, r63, r7
2676         addi.l  r17, 8, r17
2677         blink   tr1, r63
2678 LOCAL(ia_r8_push):      /* Push r8 onto the stack.  */
2679         movi    1 << 8, r39
2680         andc    r0, r39, r0
2681         stx.q   r17, r63, r8
2682         addi.l  r17, 8, r17
2683         blink   tr1, r63
2684 LOCAL(ia_push_seq):     /* Push a sequence of registers onto the stack.  */
2685         andi    r0, 7 << 1, r38
2686         movi    (LOCAL(ia_end_of_push_seq) >> 16) & 65535, r40
2687         shlli   r38, 2, r39
2688         shori   LOCAL(ia_end_of_push_seq) & 65535, r40
2689         sub.l   r40, r39, r41
2690         ptabs/l r41, tr2
2691         blink   tr2, r63
2692 LOCAL(ia_stack_of_push_seq):     /* Beginning of push sequence.  */
2693         stx.q   r17, r63, r3
2694         addi.l  r17, 8, r17
2695         stx.q   r17, r63, r4
2696         addi.l  r17, 8, r17
2697         stx.q   r17, r63, r5
2698         addi.l  r17, 8, r17
2699         stx.q   r17, r63, r6
2700         addi.l  r17, 8, r17
2701         stx.q   r17, r63, r7
2702         addi.l  r17, 8, r17
2703         stx.q   r17, r63, r8
2704         addi.l  r17, 8, r17
2705 LOCAL(ia_r9_push):      /* Push r9 onto the stack.  */
2706         stx.q   r17, r63, r9
2707 LOCAL(ia_return):       /* Return.  */
2708         blink   tr0, r63
2709 LOCAL(ia_end_of_push_seq): /* Label used to compute the first push instruction.  */
2710         ENDFUNC(GLOBAL(GCC_shcompact_incoming_args))
2711 #endif /* L_shcompact_incoming_args */
2712 #endif
2713 #if __SH5__
2714 #ifdef L_nested_trampoline
2715 #if __SH5__ == 32
2716         .section        .text..SHmedia32,"ax"
2717 #else
2718         .text
2719 #endif
2720         .align  3 /* It is copied in units of 8 bytes in SHmedia mode.  */
2721         .global GLOBAL(GCC_nested_trampoline)
2722         FUNC(GLOBAL(GCC_nested_trampoline))
2723 GLOBAL(GCC_nested_trampoline):
2724         .mode   SHmedia
2725         ptrel/u r63, tr0
2726         gettr   tr0, r0
2727 #if __SH5__ == 64
2728         ld.q    r0, 24, r1
2729 #else
2730         ld.l    r0, 24, r1
2731 #endif
2732         ptabs/l r1, tr1
2733 #if __SH5__ == 64
2734         ld.q    r0, 32, r1
2735 #else
2736         ld.l    r0, 28, r1
2737 #endif
2738         blink   tr1, r63
2739
2740         ENDFUNC(GLOBAL(GCC_nested_trampoline))
2741 #endif /* L_nested_trampoline */
2742 #endif /* __SH5__ */
2743 #if __SH5__ == 32
2744 #ifdef L_push_pop_shmedia_regs
2745         .section        .text..SHmedia32,"ax"
2746         .mode   SHmedia
2747         .align  2
2748 #ifndef __SH4_NOFPU__   
2749         .global GLOBAL(GCC_push_shmedia_regs)
2750         FUNC(GLOBAL(GCC_push_shmedia_regs))
2751 GLOBAL(GCC_push_shmedia_regs):
2752         addi.l  r15, -14*8, r15
2753         fst.d   r15, 13*8, dr62
2754         fst.d   r15, 12*8, dr60
2755         fst.d   r15, 11*8, dr58
2756         fst.d   r15, 10*8, dr56
2757         fst.d   r15,  9*8, dr54
2758         fst.d   r15,  8*8, dr52
2759         fst.d   r15,  7*8, dr50
2760         fst.d   r15,  6*8, dr48
2761         fst.d   r15,  5*8, dr46
2762         fst.d   r15,  4*8, dr44
2763         fst.d   r15,  3*8, dr42
2764         fst.d   r15,  2*8, dr40
2765         fst.d   r15,  1*8, dr38
2766         fst.d   r15,  0*8, dr36
2767 #endif
2768         .global GLOBAL(GCC_push_shmedia_regs_nofpu)
2769         FUNC(GLOBAL(GCC_push_shmedia_regs_nofpu))
2770 GLOBAL(GCC_push_shmedia_regs_nofpu):
2771         ptabs/l r18, tr0
2772         addi.l  r15, -27*8, r15
2773         gettr   tr7, r62
2774         gettr   tr6, r61
2775         gettr   tr5, r60
2776         st.q    r15, 26*8, r62
2777         st.q    r15, 25*8, r61
2778         st.q    r15, 24*8, r60
2779         st.q    r15, 23*8, r59
2780         st.q    r15, 22*8, r58
2781         st.q    r15, 21*8, r57
2782         st.q    r15, 20*8, r56
2783         st.q    r15, 19*8, r55
2784         st.q    r15, 18*8, r54
2785         st.q    r15, 17*8, r53
2786         st.q    r15, 16*8, r52
2787         st.q    r15, 15*8, r51
2788         st.q    r15, 14*8, r50
2789         st.q    r15, 13*8, r49
2790         st.q    r15, 12*8, r48
2791         st.q    r15, 11*8, r47
2792         st.q    r15, 10*8, r46
2793         st.q    r15,  9*8, r45
2794         st.q    r15,  8*8, r44
2795         st.q    r15,  7*8, r35
2796         st.q    r15,  6*8, r34
2797         st.q    r15,  5*8, r33
2798         st.q    r15,  4*8, r32
2799         st.q    r15,  3*8, r31
2800         st.q    r15,  2*8, r30
2801         st.q    r15,  1*8, r29
2802         st.q    r15,  0*8, r28
2803         blink   tr0, r63
2804
2805 #ifndef __SH4_NOFPU__   
2806         ENDFUNC(GLOBAL(GCC_push_shmedia_regs))
2807 #endif
2808         ENDFUNC(GLOBAL(GCC_push_shmedia_regs_nofpu))
2809 #ifndef __SH4_NOFPU__
2810         .global GLOBAL(GCC_pop_shmedia_regs)
2811         FUNC(GLOBAL(GCC_pop_shmedia_regs))
2812 GLOBAL(GCC_pop_shmedia_regs):
2813         pt      .L0, tr1
2814         movi    41*8, r0
2815         fld.d   r15, 40*8, dr62
2816         fld.d   r15, 39*8, dr60
2817         fld.d   r15, 38*8, dr58
2818         fld.d   r15, 37*8, dr56
2819         fld.d   r15, 36*8, dr54
2820         fld.d   r15, 35*8, dr52
2821         fld.d   r15, 34*8, dr50
2822         fld.d   r15, 33*8, dr48
2823         fld.d   r15, 32*8, dr46
2824         fld.d   r15, 31*8, dr44
2825         fld.d   r15, 30*8, dr42
2826         fld.d   r15, 29*8, dr40
2827         fld.d   r15, 28*8, dr38
2828         fld.d   r15, 27*8, dr36
2829         blink   tr1, r63
2830 #endif
2831         .global GLOBAL(GCC_pop_shmedia_regs_nofpu)
2832         FUNC(GLOBAL(GCC_pop_shmedia_regs_nofpu))
2833 GLOBAL(GCC_pop_shmedia_regs_nofpu):
2834         movi    27*8, r0
2835 .L0:
2836         ptabs   r18, tr0
2837         ld.q    r15, 26*8, r62
2838         ld.q    r15, 25*8, r61
2839         ld.q    r15, 24*8, r60
2840         ptabs   r62, tr7
2841         ptabs   r61, tr6
2842         ptabs   r60, tr5
2843         ld.q    r15, 23*8, r59
2844         ld.q    r15, 22*8, r58
2845         ld.q    r15, 21*8, r57
2846         ld.q    r15, 20*8, r56
2847         ld.q    r15, 19*8, r55
2848         ld.q    r15, 18*8, r54
2849         ld.q    r15, 17*8, r53
2850         ld.q    r15, 16*8, r52
2851         ld.q    r15, 15*8, r51
2852         ld.q    r15, 14*8, r50
2853         ld.q    r15, 13*8, r49
2854         ld.q    r15, 12*8, r48
2855         ld.q    r15, 11*8, r47
2856         ld.q    r15, 10*8, r46
2857         ld.q    r15,  9*8, r45
2858         ld.q    r15,  8*8, r44
2859         ld.q    r15,  7*8, r35
2860         ld.q    r15,  6*8, r34
2861         ld.q    r15,  5*8, r33
2862         ld.q    r15,  4*8, r32
2863         ld.q    r15,  3*8, r31
2864         ld.q    r15,  2*8, r30
2865         ld.q    r15,  1*8, r29
2866         ld.q    r15,  0*8, r28
2867         add.l   r15, r0, r15
2868         blink   tr0, r63
2869
2870 #ifndef __SH4_NOFPU__
2871         ENDFUNC(GLOBAL(GCC_pop_shmedia_regs))
2872 #endif
2873         ENDFUNC(GLOBAL(GCC_pop_shmedia_regs_nofpu))
2874 #endif /* __SH5__ == 32 */
2875 #endif /* L_push_pop_shmedia_regs */