OSDN Git Service

72097909fa2398126423d9e8ccd066e900397a9a
[pf3gnuchains/pf3gnuchains4x.git] / cgen / cpu / frv.cpu
1 ; Fujitsu FRV CPU description.  -*- Scheme -*-
2 ; Copyright (C) 2000, 2001 Red Hat, Inc.
3 ; This file is part of CGEN.
4 ; See file COPYING.CGEN for details.
5
6 (include "simplify.inc")
7
8 ; define-arch must appear first
9
10 (define-arch
11   (name frv) ; name of cpu architecture
12   (comment "Fujitsu FRV")
13   (insn-lsb0? #t)
14   (machs frv fr500 fr400 tomcat simple)
15   (isas frv)
16 )
17
18 (define-isa
19   (name frv)
20   (base-insn-bitsize 32)
21   ; Initial bitnumbers to decode insns by.
22   (decode-assist (24 23 22 21 20 19 18))
23   (liw-insns 1)       ; The frv fetches  up to 1 insns at a time.
24   (parallel-insns 4)  ; The frv executes up to 4 insns at a time.
25 )
26
27 ; Cpu family definitions.
28 ;
29 (define-cpu
30   ; cpu names must be distinct from the architecture name and machine names.
31   ; The "b" suffix stands for "base" and is the convention.
32   ; The "f" suffix stands for "family" and is the convention.
33   (name frvbf)
34   (comment "Fujitsu FRV base family")
35   (endian big)
36   (word-bitsize 32)
37 )
38 \f
39 ; Generic FR-V machine. Supports the entire architecture
40 (define-mach
41   (name frv)
42   (comment "Generic FRV cpu")
43   (cpu frvbf)
44 )
45 (define-model
46   (name frv) (comment "Generic FRV model") (attrs)
47   (mach frv)
48
49   (pipeline all "" () ((fetch) (decode) (execute) (writeback)))
50
51   ; `state' is a list of variables for recording model state
52   ; (state)
53
54   (unit u-exec "Execution Unit" ()
55         1 1 ; issue done
56         () ; state
57         () ; inputs
58         () ; outputs
59         () ; profile action (default)
60         )
61 )
62 \f
63 ; FR500 machine.
64 (define-mach
65   (name fr500)
66   (comment "FR500 cpu")
67   (cpu frvbf)
68 )
69 (define-model
70   (name fr500) (comment "FR500 model") (attrs)
71   (mach fr500)
72
73   (pipeline all "" () ((fetch) (decode) (execute) (writeback)))
74
75   ; `state' is a list of variables for recording model state
76   (state
77    ; State items
78    ; These are all masks with each bit representing one register.
79    (prev-fpop       DI) ; Previous use of FR register was floating point insn
80    (prev-media      DI) ; Previous use of FR register was a media insn
81    (prev-cc-complex DI) ; Previous use of ICC register was not simple
82    (cur-fpop        DI) ; Current use of FR register was floating point insn
83    (cur-media       DI) ; Current use of FR register was a media insn
84    (cur-cc-complex  DI) ; Current use of ICC register was not simple
85   )
86   ; Basic unit for instructions with no latency penalties
87   (unit u-exec "Execution Unit" ()
88         1 1 ; issue done
89         () ; state
90         () ; inputs
91         () ; outputs
92         () ; profile action (default)
93         )
94   ; Basic integer insn unit
95   (unit u-integer "Integer Unit" ()
96         1 1 ; issue done
97         () ; state
98         ((GRi INT -1) (GRj INT -1)) ; inputs
99         ((GRk INT -1) (ICCi_1 INT -1)) ; outputs
100         () ; profile action (default)
101         )
102   ; Integer multiplication unit
103   (unit u-imul "Integer Multiplication Unit" ()
104         1 1 ; issue done
105         () ; state
106         ((GRi INT -1) (GRj INT -1)) ; inputs
107         ((GRdoublek INT -1) (ICCi_1 INT -1)) ; outputs
108         () ; profile action (default)
109         )
110   ; Integer division unit
111   (unit u-idiv "Integer Division Unit" ()
112         1 1 ; issue done
113         () ; state
114         ((GRi INT -1) (GRj INT -1)) ; inputs
115         ((GRk INT -1) (ICCi_1 INT -1)) ; outputs
116         () ; profile action (default)
117         )
118   ; Branch unit
119   (unit u-branch "Branch Unit" ()
120         1 1 ; issue done
121         () ; state
122         ((GRi INT -1) (GRj INT -1)
123          (ICCi_2 INT -1) (FCCi_2 INT -1)) ; inputs
124         ((pc)) ; outputs
125         () ; profile action (default)
126         )
127   ; Trap unit
128   (unit u-trap "Trap Unit" ()
129         1 1 ; issue done
130         () ; state
131         ((GRi INT -1) (GRj INT -1)
132          (ICCi_2 INT -1) (FCCi_2 INT -1)) ; inputs
133         () ; outputs
134         () ; profile action (default)
135         )
136   ; Condition code check unit
137   (unit u-check "Check Unit" ()
138         1 1 ; issue done
139         () ; state
140         ((ICCi_3 INT -1) (FCCi_3 INT -1)) ; inputs
141         () ; outputs
142         () ; profile action (default)
143         )
144   ; GR set half unit
145   (unit u-set-hilo "GR Set Half" ()
146         1 1 ; issue done
147         () ; state
148         () ; inputs
149         ((GRkhi INT -1) (GRklo INT -1)) ; outputs
150         () ; profile action (default)
151         )
152   ; GR load unit -- TODO doesn't handle quad
153   (unit u-gr-load "GR Load Unit" ()
154         1 1 ; issue done
155         () ; state
156         ((GRi INT -1) (GRj INT -1)) ; inputs
157         ((GRk INT -1) (GRdoublek INT -1)) ; outputs
158         () ; profile action (default)
159         )
160   ; GR store unit -- TODO doesn't handle quad
161   (unit u-gr-store "GR Store Unit" ()
162         1 1 ; issue done
163         () ; state
164         ((GRi INT -1) (GRj INT -1) (GRk INT -1) (GRdoublek INT -1)) ; inputs
165         () ; outputs
166         () ; profile action (default)
167         )
168   ; GR recovering store unit -- TODO doesn't handle quad
169   (unit u-gr-r-store "GR Recovering Store Unit" ()
170         1 1 ; issue done
171         () ; state
172         ((GRi INT -1) (GRj INT -1) (GRk INT -1) (GRdoublek INT -1)) ; inputs
173         () ; outputs
174         () ; profile action (default)
175         )
176   ; FR load unit -- TODO doesn't handle quad
177   (unit u-fr-load "FR Load Unit" ()
178         1 1 ; issue done
179         () ; state
180         ((GRi INT -1) (GRj INT -1)) ; inputs
181         ((FRintk INT -1) (FRdoublek INT -1)) ; outputs
182         () ; profile action (default)
183         )
184   ; FR store unit -- TODO doesn't handle quad
185   (unit u-fr-store "FR Store Unit" ()
186         1 1 ; issue done
187         () ; state
188         ((GRi INT -1) (GRj INT -1) (FRintk INT -1) (FRdoublek INT -1)) ; inputs
189         () ; outputs
190         () ; profile action (default)
191         )
192   ; FR recovering store unit -- TODO doesn't handle quad
193   (unit u-fr-r-store "FR Recovering Store Unit" ()
194         1 1 ; issue done
195         () ; state
196         ((GRi INT -1) (GRj INT -1) (FRintk INT -1) (FRdoublek INT -1)) ; inputs
197         () ; outputs
198         () ; profile action (default)
199         )
200   ; Swap unit
201   (unit u-swap "Swap Unit" ()
202         1 1 ; issue done
203         () ; state
204         ((GRi INT -1) (GRj INT -1)) ; inputs
205         ((GRk INT -1)) ; outputs
206         () ; profile action (default)
207         )
208   ; FR Move to FR unit
209   (unit u-fr2fr "FR Move to FR Unit" ()
210         1 1 ; issue done
211         () ; state
212         ((FRi INT -1)) ; inputs
213         ((FRk INT -1)) ; outputs
214         () ; profile action (default)
215         )
216   ; FR Move to GR unit
217   (unit u-fr2gr "FR Move to GR Unit" ()
218         1 1 ; issue done
219         () ; state
220         ((FRintk INT -1)) ; inputs
221         ((GRj INT -1)) ; outputs
222         () ; profile action (default)
223         )
224   ; SPR Move to GR unit
225   (unit u-spr2gr "SPR Move to GR Unit" ()
226         1 1 ; issue done
227         () ; state
228         ((spr INT -1)) ; inputs
229         ((GRj INT -1)) ; outputs
230         () ; profile action (default)
231         )
232   ; GR Move to FR unit
233   (unit u-gr2fr "GR Move to FR Unit" ()
234         1 1 ; issue done
235         () ; state
236         ((GRj INT -1)) ; inputs
237         ((FRintk INT -1)) ; outputs
238         () ; profile action (default)
239         )
240   ; GR Move to SPR unit
241   (unit u-gr2spr "GR Move to SPR Unit" ()
242         1 1 ; issue done
243         () ; state
244         ((GRj INT -1)) ; inputs
245         ((spr INT -1)) ; outputs
246         () ; profile action (default)
247         )
248   ; Float Arithmetic unit
249   (unit u-float-arith "Float Arithmetic unit" ()
250         1 1 ; issue done
251         () ; state
252         ((FRi INT -1) (FRj INT -1) ; inputs
253          (FRdoublei INT -1) (FRdoublej INT -1)) ; inputs
254         ((FRk INT -1) (FRdoublek INT -1)) ; outputs
255         () ; profile action (default)
256         )
257   ; Float Dual Arithmetic unit
258   (unit u-float-dual-arith "Float Arithmetic unit" ()
259         1 1 ; issue done
260         () ; state
261         ((FRi INT -1) (FRj INT -1) ; inputs
262          (FRdoublei INT -1) (FRdoublej INT -1)) ; inputs
263         ((FRk INT -1) (FRdoublek INT -1)) ; outputs
264         () ; profile action (default)
265         )
266   ; Float Div unit
267   (unit u-float-div "Float Div unit" ()
268         1 1 ; issue done
269         () ; state
270         ((FRi INT -1) (FRj INT -1)) ; inputs
271         ((FRk INT -1)) ; outputs
272         () ; profile action (default)
273         )
274   ; Float Square Root unit
275   (unit u-float-sqrt "Float Square Root unit" ()
276         1 1 ; issue done
277         () ; state
278         ((FRj INT -1) (FRdoublej INT -1)) ; inputs
279         ((FRk INT -1) (FRdoublek INT -1)) ; outputs
280         () ; profile action (default)
281         )
282   ; Float Dual Square Root unit
283   (unit u-float-dual-sqrt "Float Dual Square Root unit" ()
284         1 1 ; issue done
285         () ; state
286         ((FRj INT -1)) ; inputs
287         ((FRk INT -1)) ; outputs
288         () ; profile action (default)
289         )
290   ; Float Compare unit
291   (unit u-float-compare "Float Compare unit" ()
292         1 1 ; issue done
293         () ; state
294         ((FRi INT -1) (FRj INT -1)
295          (FRdoublei INT -1) (FRdoublej INT -1)) ; inputs
296         ((FCCi_2 INT -1)) ; outputs
297         () ; profile action (default)
298         )
299   ; Dual Float Compare unit
300   (unit u-float-dual-compare "Float Dual Compare unit" ()
301         1 1 ; issue done
302         () ; state
303         ((FRi INT -1) (FRj INT -1)) ; inputs
304         ((FCCi_2 INT -1)) ; outputs
305         () ; profile action (default)
306         )
307   ; Float Conversion unit
308   (unit u-float-convert "Float Conversion unit" ()
309         1 1 ; issue done
310         () ; state
311         ((FRj INT -1) (FRintj INT -1) (FRdoublej INT -1)) ; inputs
312         ((FRk INT -1) (FRintk INT -1) (FRdoublek INT -1)) ; outputs
313         () ; profile action (default)
314         )
315   ; Dual Float Conversion unit
316   (unit u-float-dual-convert "Float Dual Conversion unit" ()
317         1 1 ; issue done
318         () ; state
319         ((FRj INT -1) (FRintj INT -1)) ; inputs
320         ((FRk INT -1) (FRintk INT -1)) ; outputs
321         () ; profile action (default)
322         )
323   ; Media unit
324   (unit u-media "Media unit" ()
325         1 1 ; issue done
326         () ; state
327         ((FRinti INT -1) (FRintj INT -1) (ACC40Si INT -1) (ACCGi INT -1)) ; inputs
328         ((FRintk INT -1) (ACC40Sk INT -1) (ACC40Uk INT -1) (ACCGk INT -1)) ; outputs
329         () ; profile action (default)
330         )
331   ; Media Quad Arithmetic unit
332   (unit u-media-quad-arith "Media Quad Arithmetic unit" ()
333         1 1 ; issue done
334         () ; state
335         ((FRinti INT -1) (FRintj INT -1)) ; inputs
336         ((FRintk INT -1)) ; outputs
337         () ; profile action (default)
338         )
339   ; Media Dual Multiplication unit
340   (unit u-media-dual-mul "Media Dual Multiplication unit" ()
341         1 1 ; issue done
342         () ; state
343         ((FRinti INT -1) (FRintj INT -1)) ; inputs
344         ((ACC40Sk INT -1) (ACC40Uk INT -1)) ; outputs
345         () ; profile action (default)
346         )
347   ; Media Quad Multiplication unit
348   (unit u-media-quad-mul "Media Quad Multiplication unit" ()
349         1 1 ; issue done
350         () ; state
351         ((FRinti INT -1) (FRintj INT -1)) ; inputs
352         ((ACC40Sk INT -1) (ACC40Uk INT -1)) ; outputs
353         () ; profile action (default)
354         )
355   ; Media Quad Complex unit
356   (unit u-media-quad-complex "Media Quad Complex unit" ()
357         1 1 ; issue done
358         () ; state
359         ((FRinti INT -1) (FRintj INT -1)) ; inputs
360         ((ACC40Sk INT -1)) ; outputs
361         () ; profile action (default)
362         )
363   ; Media Dual Expand unit
364   (unit u-media-dual-expand "Media Dual Expand unit" ()
365         1 1 ; issue done
366         () ; state
367         ((FRinti INT -1)) ; inputs
368         ((FRintk INT -1)) ; outputs
369         () ; profile action (default)
370         )
371   ; Media Dual Unpack unit
372   (unit u-media-dual-unpack "Media Dual Unpack unit" ()
373         1 1 ; issue done
374         () ; state
375         ((FRinti INT -1)) ; inputs
376         ((FRintk INT -1)) ; outputs
377         () ; profile action (default)
378         )
379   ; Media Dual byte to half unit
380   (unit u-media-dual-btoh "Media Byte to byte" ()
381         1 1 ; issue done
382         () ; state
383         ((FRintj INT -1)) ; inputs
384         ((FRintk INT -1)) ; outputs
385         () ; profile action (default)
386         )
387   ; Media Dual half to byte unit
388   (unit u-media-dual-htob "Media Half to byte" ()
389         1 1 ; issue done
390         () ; state
391         ((FRintj INT -1)) ; inputs
392         ((FRintk INT -1)) ; outputs
393         () ; profile action (default)
394         )
395   ; Media Dual byte to half unit extended
396   (unit u-media-dual-btohe "Media Byte to byte extended" ()
397         1 1 ; issue done
398         () ; state
399         ((FRintj INT -1)) ; inputs
400         ((FRintk INT -1)) ; outputs
401         () ; profile action (default)
402         )
403   ; Barrier unit
404   (unit u-barrier "Barrier unit" ()
405         1 1 ; issue done
406         () ; state
407         () ; inputs
408         () ; outputs
409         () ; profile action (default)
410         )
411   ; Memory Barrier unit
412   (unit u-membar "Memory Barrier unit" ()
413         1 1 ; issue done
414         () ; state
415         () ; inputs
416         () ; outputs
417         () ; profile action (default)
418         )
419   ; Insn cache invalidate unit
420   (unit u-ici "Insn cache invalidate unit" ()
421         1 1 ; issue done
422         () ; state
423         ((GRi INT -1) (GRj INT -1)) ; inputs
424         () ; outputs
425         () ; profile action (default)
426         )
427   ; Data cache invalidate unit
428   (unit u-dci "Data cache invalidate unit" ()
429         1 1 ; issue done
430         () ; state
431         ((GRi INT -1) (GRj INT -1)) ; inputs
432         () ; outputs
433         () ; profile action (default)
434         )
435   ; Data cache flush unit
436   (unit u-dcf "Data cache flush unit" ()
437         1 1 ; issue done
438         () ; state
439         ((GRi INT -1) (GRj INT -1)) ; inputs
440         () ; outputs
441         () ; profile action (default)
442         )
443   ; Insn cache preload unit
444   (unit u-icpl "Insn cache preload unit" ()
445         1 1 ; issue done
446         () ; state
447         ((GRi INT -1) (GRj INT -1)) ; inputs
448         () ; outputs
449         () ; profile action (default)
450         )
451   ; Data cache preload unit
452   (unit u-dcpl "Data cache preload unit" ()
453         1 1 ; issue done
454         () ; state
455         ((GRi INT -1) (GRj INT -1)) ; inputs
456         () ; outputs
457         () ; profile action (default)
458         )
459   ; Insn cache unlock unit
460   (unit u-icul "Insn cache unlock unit" ()
461         1 1 ; issue done
462         () ; state
463         ((GRi INT -1) (GRj INT -1)) ; inputs
464         () ; outputs
465         () ; profile action (default)
466         )
467   ; Data cache unlock unit
468   (unit u-dcul "Data cache unlock unit" ()
469         1 1 ; issue done
470         () ; state
471         ((GRi INT -1) (GRj INT -1)) ; inputs
472         () ; outputs
473         () ; profile action (default)
474         )
475 )
476 \f
477 ; Tomcat machine. Early version of fr500 machine
478 (define-mach
479   (name tomcat)
480   (comment "Tomcat -- early version of fr500")
481   (cpu frvbf)
482 )
483 (define-model
484   (name tomcat) (comment "Tomcat model") (attrs)
485   (mach tomcat)
486
487   (pipeline all "" () ((fetch) (decode) (execute) (writeback)))
488
489   ; `state' is a list of variables for recording model state
490   ; (state)
491
492   (unit u-exec "Execution Unit" ()
493         1 1 ; issue done
494         () ; state
495         () ; inputs
496         () ; outputs
497         () ; profile action (default)
498         )
499 )
500 \f
501 ; FR400 machine
502 (define-mach
503   (name fr400)
504   (comment "FR400 cpu")
505   (cpu frvbf)
506 )
507 (define-model
508   (name fr400) (comment "FR400 model") (attrs)
509   (mach fr400)
510   (pipeline all "" () ((fetch) (decode) (execute) (writeback)))
511   ; `state' is a list of variables for recording model state
512   (state
513    ; State items
514    ; These are all masks with each bit representing one register.
515    (prev-fp-load    DI) ; Previous use of FR  register was floating point load
516    (prev-fr-p4      DI) ; Previous use of FR  register was media unit 4
517    (prev-fr-p6      DI) ; Previous use of FR  register was media unit 6
518    (prev-acc-p2     DI) ; Previous use of ACC register was media unit 2
519    (prev-acc-p4     DI) ; Previous use of ACC register was media unit 4
520    (cur-fp-load     DI) ; Current  use of FR  register is  floating point load
521    (cur-fr-p4       DI) ; Current  use of FR  register is  media unit 4
522    (cur-fr-p6       DI) ; Current  use of FR  register is  media unit 6
523    (cur-acc-p2      DI) ; Current  use of ACC register is  media unit 2
524    (cur-acc-p4      DI) ; Current  use of ACC register is  media unit 4
525   )
526   (unit u-exec "Execution Unit" ()
527         1 1 ; issue done
528         () ; state
529         () ; inputs
530         () ; outputs
531         () ; profile action (default)
532         )
533   ; Basic integer insn unit
534   (unit u-integer "Integer Unit" ()
535         1 1 ; issue done
536         () ; state
537         ((GRi INT -1) (GRj INT -1)) ; inputs
538         ((GRk INT -1) (ICCi_1 INT -1)) ; outputs
539         () ; profile action (default)
540         )
541   ; Integer multiplication unit
542   (unit u-imul "Integer Multiplication Unit" ()
543         1 1 ; issue done
544         () ; state
545         ((GRi INT -1) (GRj INT -1)) ; inputs
546         ((GRdoublek INT -1) (ICCi_1 INT -1)) ; outputs
547         () ; profile action (default)
548         )
549   ; Integer division unit
550   (unit u-idiv "Integer Division Unit" ()
551         1 1 ; issue done
552         () ; state
553         ((GRi INT -1) (GRj INT -1)) ; inputs
554         ((GRk INT -1) (ICCi_1 INT -1)) ; outputs
555         () ; profile action (default)
556         )
557   ; Branch unit
558   (unit u-branch "Branch Unit" ()
559         1 1 ; issue done
560         () ; state
561         ((GRi INT -1) (GRj INT -1)
562          (ICCi_2 INT -1) (FCCi_2 INT -1)) ; inputs
563         ((pc)) ; outputs
564         () ; profile action (default)
565         )
566   ; Trap unit
567   (unit u-trap "Trap Unit" ()
568         1 1 ; issue done
569         () ; state
570         ((GRi INT -1) (GRj INT -1)
571          (ICCi_2 INT -1) (FCCi_2 INT -1)) ; inputs
572         () ; outputs
573         () ; profile action (default)
574         )
575   ; Condition code check unit
576   (unit u-check "Check Unit" ()
577         1 1 ; issue done
578         () ; state
579         ((ICCi_3 INT -1) (FCCi_3 INT -1)) ; inputs
580         () ; outputs
581         () ; profile action (default)
582         )
583   ; GR set half unit
584   (unit u-set-hilo "GR Set Half" ()
585         1 1 ; issue done
586         () ; state
587         () ; inputs
588         ((GRkhi INT -1) (GRklo INT -1)) ; outputs
589         () ; profile action (default)
590         )
591   ; GR load unit -- TODO doesn't handle quad
592   (unit u-gr-load "GR Load Unit" ()
593         1 1 ; issue done
594         () ; state
595         ((GRi INT -1) (GRj INT -1)) ; inputs
596         ((GRk INT -1) (GRdoublek INT -1)) ; outputs
597         () ; profile action (default)
598         )
599   ; GR store unit -- TODO doesn't handle quad
600   (unit u-gr-store "GR Store Unit" ()
601         1 1 ; issue done
602         () ; state
603         ((GRi INT -1) (GRj INT -1) (GRk INT -1) (GRdoublek INT -1)) ; inputs
604         () ; outputs
605         () ; profile action (default)
606         )
607   ; FR load unit -- TODO doesn't handle quad
608   (unit u-fr-load "FR Load Unit" ()
609         1 1 ; issue done
610         () ; state
611         ((GRi INT -1) (GRj INT -1)) ; inputs
612         ((FRintk INT -1) (FRdoublek INT -1)) ; outputs
613         () ; profile action (default)
614         )
615   ; FR store unit -- TODO doesn't handle quad
616   (unit u-fr-store "FR Store Unit" ()
617         1 1 ; issue done
618         () ; state
619         ((GRi INT -1) (GRj INT -1) (FRintk INT -1) (FRdoublek INT -1)) ; inputs
620         () ; outputs
621         () ; profile action (default)
622         )
623   ; Swap unit
624   (unit u-swap "Swap Unit" ()
625         1 1 ; issue done
626         () ; state
627         ((GRi INT -1) (GRj INT -1)) ; inputs
628         ((GRk INT -1)) ; outputs
629         () ; profile action (default)
630         )
631   ; FR Move to GR unit
632   (unit u-fr2gr "FR Move to GR Unit" ()
633         1 1 ; issue done
634         () ; state
635         ((FRintk INT -1)) ; inputs
636         ((GRj INT -1)) ; outputs
637         () ; profile action (default)
638         )
639   ; SPR Move to GR unit
640   (unit u-spr2gr "SPR Move to GR Unit" ()
641         1 1 ; issue done
642         () ; state
643         ((spr INT -1)) ; inputs
644         ((GRj INT -1)) ; outputs
645         () ; profile action (default)
646         )
647   ; GR Move to FR unit
648   (unit u-gr2fr "GR Move to FR Unit" ()
649         1 1 ; issue done
650         () ; state
651         ((GRj INT -1)) ; inputs
652         ((FRintk INT -1)) ; outputs
653         () ; profile action (default)
654         )
655   ; GR Move to SPR unit
656   (unit u-gr2spr "GR Move to SPR Unit" ()
657         1 1 ; issue done
658         () ; state
659         ((GRj INT -1)) ; inputs
660         ((spr INT -1)) ; outputs
661         () ; profile action (default)
662         )
663   ; Media unit M1 -- see table 13-8 in the fr400 LSI
664   (unit u-media-1 "Media-1 unit" ()
665         1 1 ; issue done
666         () ; state
667         ((FRinti INT -1) (FRintj INT -1)) ; inputs
668         ((FRintk INT -1)) ; outputs
669         () ; profile action (default)
670         )
671   (unit u-media-1-quad "Media-1-quad unit" ()
672         1 1 ; issue done
673         () ; state
674         ((FRinti INT -1) (FRintj INT -1)) ; inputs
675         ((FRintk INT -1)) ; outputs
676         () ; profile action (default)
677         )
678   (unit u-media-hilo "Media-hilo unit -- a variation of the Media-1 unit" ()
679         1 1 ; issue done
680         () ; state
681         () ; inputs
682         ((FRkhi INT -1) (FRklo INT -1)) ; outputs
683         () ; profile action (default)
684         )
685   ; Media unit M2 -- see table 13-8 in the fr400 LSI
686   (unit u-media-2 "Media-2 unit" ()
687         1 1 ; issue done
688         () ; state
689         ((FRinti INT -1) (FRintj INT -1)) ; inputs
690         ((ACC40Sk INT -1) (ACC40Uk INT -1)) ; outputs
691         () ; profile action (default)
692         )
693   (unit u-media-2-quad "Media-2-quad unit" ()
694         1 1 ; issue done
695         () ; state
696         ((FRinti INT -1) (FRintj INT -1)) ; inputs
697         ((ACC40Sk INT -1) (ACC40Uk INT -1)) ; outputs
698         () ; profile action (default)
699         )
700   (unit u-media-2-acc "Media-2-acc unit" ()
701         1 1 ; issue done
702         () ; state
703         ((ACC40Si INT -1)) ; inputs
704         ((ACC40Sk INT -1)) ; outputs
705         () ; profile action (default)
706         )
707   (unit u-media-2-acc-dual "Media-2-acc-dual unit" ()
708         1 1 ; issue done
709         () ; state
710         ((ACC40Si INT -1)) ; inputs
711         ((ACC40Sk INT -1)) ; outputs
712         () ; profile action (default)
713         )
714   (unit u-media-2-add-sub "Media-2-add-sub unit" ()
715         1 1 ; issue done
716         () ; state
717         ((ACC40Si INT -1)) ; inputs
718         ((ACC40Sk INT -1)) ; outputs
719         () ; profile action (default)
720         )
721   (unit u-media-2-add-sub-dual "Media-2-add-sub-dual unit" ()
722         1 1 ; issue done
723         () ; state
724         ((ACC40Si INT -1)) ; inputs
725         ((ACC40Sk INT -1)) ; outputs
726         () ; profile action (default)
727         )
728   ; Media unit M3 -- see table 13-8 in the fr400 LSI
729   (unit u-media-3 "Media-3 unit" ()
730         1 1 ; issue done
731         () ; state
732         ((FRinti INT -1) (FRintj INT -1)) ; inputs
733         ((FRintk INT -1)) ; outputs
734         () ; profile action (default)
735         )
736   (unit u-media-3-dual "Media-3-dual unit" ()
737         1 1 ; issue done
738         () ; state
739         ((FRinti INT -1)) ; inputs
740         ((FRintk INT -1)) ; outputs
741         () ; profile action (default)
742         )
743   (unit u-media-3-quad "Media-3-quad unit" ()
744         1 1 ; issue done
745         () ; state
746         ((FRinti INT -1) (FRintj INT -1)) ; inputs
747         ((FRintk INT -1)) ; outputs
748         () ; profile action (default)
749         )
750   ; Media unit M4 -- see table 13-8 in the fr400 LSI
751   (unit u-media-4 "Media-4 unit" ()
752         1 1 ; issue done
753         () ; state
754         ((ACC40Si INT -1) (FRintj INT -1)) ; inputs
755         ((ACC40Sk INT -1) (FRintk INT -1)) ; outputs
756         () ; profile action (default)
757         )
758   (unit u-media-4-accg "Media-4-accg unit" ()
759         1 1 ; issue done
760         () ; state
761         ((ACCGi INT -1) (FRinti INT -1)) ; inputs
762         ((ACCGk INT -1) (FRintk INT -1)) ; outputs
763         () ; profile action (default)
764         )
765   (unit u-media-4-acc-dual "Media-4-acc-dual unit" ()
766         1 1 ; issue done
767         () ; state
768         ((ACC40Si INT -1)) ; inputs
769         ((FRintk INT -1)) ; outputs
770         () ; profile action (default)
771         )
772   ; Media unit M6 -- see table 13-8 in the fr400 LSI
773   (unit u-media-6 "Media-6 unit" ()
774         1 1 ; issue done
775         () ; state
776         ((FRinti INT -1)) ; inputs
777         ((FRintk INT -1)) ; outputs
778         () ; profile action (default)
779         )
780   ; Media unit M7 -- see table 13-8 in the fr400 LSI
781   (unit u-media-7 "Media-1 unit" ()
782         1 1 ; issue done
783         () ; state
784         ((FRinti INT -1) (FRintj INT -1)) ; inputs
785         ((FCCk INT -1)) ; outputs
786         () ; profile action (default)
787         )
788   ; Media Dual Expand unit
789   (unit u-media-dual-expand "Media Dual Expand unit" ()
790         1 1 ; issue done
791         () ; state
792         ((FRinti INT -1)) ; inputs
793         ((FRintk INT -1)) ; outputs
794         () ; profile action (default)
795         )
796   ; Media Dual half to byte unit
797   (unit u-media-dual-htob "Media Half to byte" ()
798         1 1 ; issue done
799         () ; state
800         ((FRintj INT -1)) ; inputs
801         ((FRintk INT -1)) ; outputs
802         () ; profile action (default)
803         )
804   ; Barrier unit
805   (unit u-barrier "Barrier unit" ()
806         1 1 ; issue done
807         () ; state
808         () ; inputs
809         () ; outputs
810         () ; profile action (default)
811         )
812   ; Memory Barrier unit
813   (unit u-membar "Memory Barrier unit" ()
814         1 1 ; issue done
815         () ; state
816         () ; inputs
817         () ; outputs
818         () ; profile action (default)
819         )
820   ; Insn cache invalidate unit
821   (unit u-ici "Insn cache invalidate unit" ()
822         1 1 ; issue done
823         () ; state
824         ((GRi INT -1) (GRj INT -1)) ; inputs
825         () ; outputs
826         () ; profile action (default)
827         )
828   ; Data cache invalidate unit
829   (unit u-dci "Data cache invalidate unit" ()
830         1 1 ; issue done
831         () ; state
832         ((GRi INT -1) (GRj INT -1)) ; inputs
833         () ; outputs
834         () ; profile action (default)
835         )
836   ; Data cache flush unit
837   (unit u-dcf "Data cache flush unit" ()
838         1 1 ; issue done
839         () ; state
840         ((GRi INT -1) (GRj INT -1)) ; inputs
841         () ; outputs
842         () ; profile action (default)
843         )
844   ; Insn cache preload unit
845   (unit u-icpl "Insn cache preload unit" ()
846         1 1 ; issue done
847         () ; state
848         ((GRi INT -1) (GRj INT -1)) ; inputs
849         () ; outputs
850         () ; profile action (default)
851         )
852   ; Data cache preload unit
853   (unit u-dcpl "Data cache preload unit" ()
854         1 1 ; issue done
855         () ; state
856         ((GRi INT -1) (GRj INT -1)) ; inputs
857         () ; outputs
858         () ; profile action (default)
859         )
860   ; Insn cache unlock unit
861   (unit u-icul "Insn cache unlock unit" ()
862         1 1 ; issue done
863         () ; state
864         ((GRi INT -1) (GRj INT -1)) ; inputs
865         () ; outputs
866         () ; profile action (default)
867         )
868   ; Data cache unlock unit
869   (unit u-dcul "Data cache unlock unit" ()
870         1 1 ; issue done
871         () ; state
872         ((GRi INT -1) (GRj INT -1)) ; inputs
873         () ; outputs
874         () ; profile action (default)
875         )
876 )
877 \f
878 ; Simple machine - single issue integer machine
879 (define-mach
880   (name simple)
881   (comment "Simple single issue integer cpu")
882   (cpu frvbf)
883 )
884 (define-model
885   (name simple) (comment "Simple model") (attrs)
886   (mach simple)
887   (pipeline all "" () ((fetch) (decode) (execute) (writeback)))
888   ; `state' is a list of variables for recording model state
889   (state)
890   (unit u-exec "Execution Unit" ()
891         1 1 ; issue done
892         () ; state
893         () ; inputs
894         () ; outputs
895         () ; profile action (default)
896         )
897 )
898 \f
899 ; The instruction fetch/execute cycle.
900 ;
901 ; This is how to fetch and decode an instruction.
902 ; Leave it out for now
903
904 ; (define-extract (const SI 0))
905
906 ; This is how to execute a decoded instruction.
907 ; Leave it out for now
908
909 ; (define-execute (const SI 0))
910 \f
911 ; An attribute to describe which unit an insn runs in.
912 (define-attr
913   (for insn)
914   (type enum)
915   (name UNIT)
916   (comment "parallel execution pipeline selection")
917   ; The order of declaration is significant. Keep variations on the same unit
918   ; together and keep the '01' variation last within each unit.
919   (values NIL
920           I0 I1 I01
921           FM0 FM1 FM01
922           B0 B1 B01
923           C
924           MULT-DIV ; multiply/division slotted differently on different machines
925           LOAD     ; loads             slotted differently on different machines
926           NUM_UNITS
927   )
928 )
929 ; Attributes to describe major categories of insns
930 (define-attr
931   (for insn)
932   (type enum)
933   (name FR400-MAJOR)
934   (comment "fr400 major insn categories")
935   ; The order of declaration is significant. Keep variations on the same major
936   ; together.
937   (values NONE
938           I-1 I-2 I-3 I-4 I-5
939           B-1 B-2 B-3 B-4 B-5 B-6
940           C-1 C-2
941           M-1 M-2
942   )
943 )
944 (define-attr
945   (for insn)
946   (type enum)
947   (name FR500-MAJOR)
948   (comment "fr500 major insn categories")
949   ; The order of declaration is significant. Keep variations on the same major
950   ; together.
951   (values NONE
952           I-1 I-2 I-3 I-4 I-5 I-6
953           B-1 B-2 B-3 B-4 B-5 B-6
954           C-1 C-2
955           F-1 F-2 F-3 F-4 F-5 F-6 F-7 F-8
956           M-1 M-2 M-3 M-4 M-5 M-6 M-7 M-8
957   )
958 )
959 ; Privileged insn
960 (define-attr
961   (for insn)
962   (type boolean)
963   (name PRIVILEGED)
964   (comment "insn only allowed in supervisor mode")
965 )
966 ; Non-Excepting insn
967 (define-attr
968   (for insn)
969   (type boolean)
970   (name NON-EXCEPTING)
971   (comment "non-excepting insn")
972 )
973 ; Conditional insn
974 (define-attr
975   (for insn)
976   (type boolean)
977   (name CONDITIONAL)
978   (comment "conditional insn")
979 )
980 ; insn accesses FR registers
981 (define-attr
982   (for insn)
983   (type boolean)
984   (name FR-ACCESS)
985   (comment "insn accesses FR registers")
986 )
987 ; insn preserves MSR.OVF
988 (define-attr
989   (for insn)
990   (type boolean)
991   (name PRESERVE-OVF)
992   (comment "Preserve value of MSR.OVF")
993 )
994 ; null attribute -- used as a place holder for where an attribue it required.
995 (define-attr
996   (for insn)
997   (type boolean)
998   (name NA)
999   (comment "placeholder attribute")
1000   (attrs META) ; do not define in any generated file for now
1001 )
1002 \f
1003 ; Instruction fields.
1004 ;
1005 ; Attributes:
1006 ; PCREL-ADDR: pc relative value (for reloc and disassembly purposes)
1007 ; ABS-ADDR: absolute address (for reloc and disassembly purposes?)
1008 ; RESERVED: bits are not used to decode insn, must be all 0
1009 (dnf f-pack      "packing bit"                  () 31  1)
1010 (dnf f-op        "primary opcode"               () 24  7)
1011 (dnf f-ope1      "extended opcode"              () 11  6)
1012 (dnf f-ope2      "extended opcode"              ()  9  4)
1013 (dnf f-ope3      "extended opcode"              () 15  3)
1014 (dnf f-ope4      "extended opcode"              ()  7  2)
1015
1016 (dnf f-GRi       "source register 1"            () 17  6)
1017 (dnf f-GRj       "source register 2"            ()  5  6)
1018 (dnf f-GRk       "destination register"         () 30  6)
1019
1020 (dnf f-FRi       "source register 1"            () 17  6)
1021 (dnf f-FRj       "source register 2"            ()  5  6)
1022 (dnf f-FRk       "destination register"         () 30  6)
1023
1024 (dnf f-CPRi      "source register 1"            () 17  6)
1025 (dnf f-CPRj      "source register 2"            ()  5  6)
1026 (dnf f-CPRk      "destination register"         () 30  6)
1027
1028 (dnf f-ACCGi     "source register"              () 17  6)
1029 (dnf f-ACCGk     "destination register"         () 30  6)
1030
1031 (dnf f-ACC40Si   "40 bit signed accumulator"    () 17  6)
1032 (dnf f-ACC40Ui   "40 bit unsigned accumulator"  () 17  6)
1033 (dnf f-ACC40Sk   "40 bit accumulator"           () 30  6)
1034 (dnf f-ACC40Uk   "40 bit accumulator"           () 30  6)
1035
1036 (dnf f-CRi       "source      register"         () 14  3)
1037 (dnf f-CRj       "source      register"         ()  2  3)
1038 (dnf f-CRk       "destination register"         () 27  3)
1039 (dnf f-CCi       "condition   register"         () 11  3)
1040
1041 (df  f-CRj_int   "target cr for ck insns"       () 26  2 UINT
1042      ((value pc) (sub WI value 4))
1043      ((value pc) (add WI value 4))
1044 )
1045 (dnf f-CRj_float "target cr for fck insns"      () 26  2)
1046
1047 (dnf f-ICCi_1    "condition register"           () 11  2)
1048 (dnf f-ICCi_2    "condition register"           () 26  2)
1049 (dnf f-ICCi_3    "condition register"           ()  1  2)
1050 (dnf f-FCCi_1    "condition register"           () 11  2)
1051 (dnf f-FCCi_2    "condition register"           () 26  2)
1052 (dnf f-FCCi_3    "condition register"           ()  1  2)
1053 (dnf f-FCCk      "condition register"           () 26  2)
1054 (dnf f-eir       "exception insn register"      () 17  6)
1055
1056 (df  f-s10       "10 bit sign extended"         ()  9 10  INT #f #f)
1057 (df  f-s12       "12 bit sign extended"         () 11 12  INT #f #f)
1058 (df  f-d12       "12 bit sign extended"         () 11 12  INT #f #f)
1059 (df  f-u16       "16 bit unsigned"              () 15 16 UINT #f #f)
1060 (df  f-s16       "16 bit sign extended"         () 15 16  INT #f #f)
1061 (df  f-s6        "6  bit   signed"              ()  5  6  INT #f #f)
1062 (df  f-s6_1      "6  bit   signed"              () 11  6  INT #f #f)
1063 (df  f-u6        "6  bit unsigned"              ()  5  6 UINT #f #f)
1064 (df  f-s5        "5  bit   signed"              ()  4  5  INT #f #f)
1065
1066 (df  f-u12-h "upper 6 bits of u12"  () 17 6  INT #f #f)
1067 (df  f-u12-l "lower 6 bits of u12"  ()  5 6 UINT #f #f)
1068 (dnmf f-u12   "12 bit signed immediate" () INT
1069       (f-u12-h f-u12-l)
1070       (sequence () ; insert
1071                 (set (ifield f-u12-h) (sra SI (ifield f-u12) 6))
1072                 (set (ifield f-u12-l) (and (ifield f-u12) #x3f))
1073                 )
1074       (sequence () ; extract
1075                 (set (ifield f-u12) (or (sll (ifield f-u12-h) 6)
1076                                         (ifield f-u12-l)))
1077                 )
1078 )
1079
1080 (dnf f-int-cc    "integer  branch conditions"   () 30  4)
1081 (dnf f-flt-cc    "floating branch conditions"   () 30  4)
1082 (df  f-cond      "conditional arithmetic"       ()  8  1 UINT #f #f)
1083 (df  f-ccond     "lr branch condition"          () 12  1 UINT #f #f)
1084 (df  f-hint      "2 bit branch prediction hint" () 17  2 UINT #f #f)
1085 (df  f-LI        "link indicator"               () 25  1 UINT #f #f)
1086 (df  f-lock      "cache lock indicator"         () 25  1 UINT #f #f)
1087 (df  f-debug     "debug mode indicator"         () 25  1 UINT #f #f)
1088 (df  f-A         "all accumulator bit"          () 17  1 UINT #f #f)
1089 (df  f-ae        "cache all entries indicator"  () 25  1 UINT #f #f)
1090
1091 (dnf  f-spr-h "upper 6 bits of spr"  () 30  6)
1092 (dnf  f-spr-l "lower 6 bits of spr"  () 17  6)
1093 (dnmf f-spr   "special purpose register" () UINT
1094       (f-spr-h f-spr-l)
1095       (sequence () ; insert
1096                 (set (ifield f-spr-h) (srl (ifield f-spr) (const 6)))
1097                 (set (ifield f-spr-l) (and (ifield f-spr) (const #x3f)))
1098                 )
1099       (sequence () ; extract
1100                 (set (ifield f-spr) (or (sll (ifield f-spr-h) (const 6))
1101                                         (ifield f-spr-l)))
1102                 )
1103 )
1104
1105 (df  f-label16    "18 bit pc relative signed offset" (PCREL-ADDR) 15 16 INT
1106      ((value pc) (sra WI (sub WI value pc) (const 2)))
1107      ((value pc) (add WI (sll WI value (const 2)) pc))
1108 )
1109
1110 (df   f-labelH6   "upper 6  bits of label24"  () 30  6 INT #f #f)
1111 (dnf  f-labelL18  "lower 18 bits of label24"  () 17 18)
1112 (dnmf f-label24   "26 bit signed offset"     (PCREL-ADDR) INT
1113       (f-labelH6 f-labelL18)
1114       ; insert
1115       (sequence ()
1116                 (set (ifield f-labelH6)
1117                      (sra WI (sub (ifield f-label24) pc) (const 20)))
1118                 (set (ifield f-labelL18)
1119                      (and (srl (sub (ifield f-label24) pc) (const 2))
1120                           (const #x3ffff)))
1121                 )
1122       ; extract
1123       (sequence ()
1124                 (set (ifield f-label24)
1125                      (add (sll (or (sll (ifield f-labelH6) (const 18))
1126                                    (ifield f-labelL18))
1127                                (const 2))
1128                           pc)))
1129 )
1130
1131 (dnf f-ICCi_1-null  "null field" (RESERVED) 11  2)
1132 (dnf f-ICCi_2-null  "null field" (RESERVED) 26  2)
1133 (dnf f-ICCi_3-null  "null field" (RESERVED)  1  2)
1134 (dnf f-FCCi_1-null  "null field" (RESERVED) 11  2)
1135 (dnf f-FCCi_2-null  "null field" (RESERVED) 26  2)
1136 (dnf f-FCCi_3-null  "null field" (RESERVED)  1  2)
1137 (dnf f-rs-null      "null field" (RESERVED) 17  6)
1138 (dnf f-GRi-null     "null field" (RESERVED) 17  6)
1139 (dnf f-GRj-null     "null field" (RESERVED)  5  6)
1140 (dnf f-GRk-null     "null field" (RESERVED) 30  6)
1141 (dnf f-FRi-null     "null field" (RESERVED) 17  6)
1142 (dnf f-FRj-null     "null field" (RESERVED)  5  6)
1143 (dnf f-ACCj-null    "null field" (RESERVED)  5  6)
1144 (dnf f-rd-null      "null field" (RESERVED) 30  6)
1145 (dnf f-cond-null    "null field" (RESERVED) 30  4)
1146 (dnf f-ccond-null   "null field" (RESERVED) 12  1)
1147 (dnf f-s12-null     "null field" (RESERVED) 11 12)
1148 (dnf f-label16-null "null field" (RESERVED) 15 16)
1149 (dnf f-misc-null-1  "null field" (RESERVED) 30  5)
1150 (dnf f-misc-null-2  "null field" (RESERVED) 11  6)
1151 (dnf f-misc-null-3  "null field" (RESERVED) 11  4)
1152 (dnf f-misc-null-4  "null field" (RESERVED) 17  2)
1153 (dnf f-misc-null-5  "null field" (RESERVED) 17 16)
1154 (dnf f-misc-null-6  "null field" (RESERVED) 30  3)
1155 (dnf f-misc-null-7  "null field" (RESERVED) 17  3)
1156 (dnf f-misc-null-8  "null field" (RESERVED)  5  3)
1157 (dnf f-misc-null-9  "null field" (RESERVED)  5  4)
1158 (dnf f-misc-null-10 "null field" (RESERVED) 16  5)
1159 (dnf f-misc-null-11 "null field" (RESERVED)  5  1)
1160
1161 (dnf f-LI-off      "null field" (RESERVED) 25  1)
1162 (dnf f-LI-on       "null field" (RESERVED) 25  1)
1163 \f
1164 ; Enums.
1165
1166 ; insn-op:
1167 ; FIXME: should use die macro or some such
1168 (define-normal-insn-enum insn-op "insn op enums" () OP_ f-op
1169  (
1170  "00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F"
1171  "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B" "1C" "1D" "1E" "1F"
1172  "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "2A" "2B" "2C" "2D" "2E" "2F"
1173  "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "3A" "3B" "3C" "3D" "3E" "3F"
1174  "40" "41" "42" "43" "44" "45" "46" "47" "48" "49" "4A" "4B" "4C" "4D" "4E" "4F"
1175  "50" "51" "52" "53" "54" "55" "56" "57" "58" "59" "5A" "5B" "5C" "5D" "5E" "5F"
1176  "60" "61" "62" "63" "64" "65" "66" "67" "68" "69" "6A" "6B" "6C" "6D" "6E" "6F"
1177  "70" "71" "72" "73" "74" "75" "76" "77" "78" "79" "7A" "7B" "7C" "7D" "7E" "7F"
1178  )
1179 )
1180
1181 (define-normal-insn-enum insn-ope1 "insn ope enums" () OPE1_ f-ope1
1182  (
1183  "00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F"
1184  "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B" "1C" "1D" "1E" "1F"
1185  "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "2A" "2B" "2C" "2D" "2E" "2F"
1186  "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "3A" "3B" "3C" "3D" "3E" "3F"
1187  )
1188 )
1189
1190 (define-normal-insn-enum insn-ope2 "insn ope enums" () OPE2_ f-ope2
1191  (
1192  "00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F"
1193  )
1194 )
1195
1196 (define-normal-insn-enum insn-ope3 "insn ope enums" () OPE3_ f-ope3
1197  (
1198  "00" "01" "02" "03" "04" "05" "06" "07"
1199  )
1200 )
1201
1202 (define-normal-insn-enum insn-ope4 "insn ope enums" () OPE4_ f-ope4
1203  (
1204  "0" "1" "2" "3"
1205  )
1206 )
1207
1208 ; int-cc: integer branch conditions
1209 ; FIXME: should use die macro or some such
1210 (define-normal-insn-enum int-cc "integer branch cond enums" () ICC_ f-int-cc
1211   (
1212    "nev" "c"  "v"  "lt" "eq" "ls" "n" "le"
1213    "ra"  "nc" "nv" "ge" "ne" "hi" "p" "gt"
1214   )
1215 )
1216
1217 ; flt-cc: floating-point/media branch conditions
1218 ; FIXME: should use die macro or some such
1219 (define-normal-insn-enum flt-cc "float branch cond enums" () FCC_ f-flt-cc
1220   ("nev" "u" "gt" "ug" "lt" "ul" "lg" "ne"
1221    "eq" "ue" "ge" "uge" "le" "ule" "o" "ra")
1222 )
1223 \f
1224 ; Hardware pieces.
1225 ; These entries list the elements of the raw hardware.
1226 ; They're also used to provide tables and other elements of the assembly
1227 ; language.
1228 (dnh h-pc "program counter" (PC PROFILE) (pc) () () ())
1229
1230 ; The PSR. The individual fields are referenced more than the entire
1231 ; register, so reference them directly. We can assemble the
1232 ; entire register contents when necessary.
1233 ;
1234 (dsh h-psr_imple "PSR.IMPLE"   () (register UQI))
1235 (dsh h-psr_ver   "PSR.VER"     () (register UQI))
1236 (dsh h-psr_ice   "PSR.ICE bit" () (register BI))
1237 (dsh h-psr_nem   "PSR.NEM bit" () (register BI))
1238 (dsh h-psr_cm    "PSR.CM  bit" () (register BI))
1239 (dsh h-psr_be    "PSR.BE  bit" () (register BI))
1240 (dsh h-psr_esr   "PSR.ESR bit" () (register BI))
1241 (dsh h-psr_ef    "PSR.EF  bit" () (register BI))
1242 (dsh h-psr_em    "PSR.EM  bit" () (register BI))
1243 (dsh h-psr_pil   "PSR.PIL    " () (register UQI))
1244 (dsh h-psr_ps    "PSR.PS  bit" () (register BI))
1245 (dsh h-psr_et    "PSR.ET  bit" () (register BI))
1246
1247 ; PSR.S requires special handling because the shadow registers (SR0-SR4) must
1248 ; be switched with GR4-GR7 when changing from user to supervisor mode or
1249 ; vice-versa.
1250 (define-hardware
1251   (name h-psr_s)
1252   (comment "PSR.S bit")
1253   (attrs)
1254   (type register BI)
1255   (get)
1256   (set (newval) (c-call VOID "@cpu@_h_psr_s_set_handler" newval))
1257 )
1258
1259 ; The TBR. The individual bits are referenced more than the entire
1260 ; register, so reference them directly. We can assemble the
1261 ; entire register contents when necessary.
1262 ;
1263 (dsh h-tbr_tba "TBR.TBA" () (register UWI))
1264 (dsh h-tbr_tt  "TBR.TT"  () (register UQI))
1265
1266 ; The BPSR. The individual bits are referenced more than the entire
1267 ; register, so reference them directly. We can assemble the
1268 ; entire register contents when necessary.
1269 ;
1270 (dsh h-bpsr_bs   "PSR.S   bit" () (register BI))
1271 (dsh h-bpsr_bet  "PSR.ET  bit" () (register BI))
1272
1273 ; General registers
1274 ;
1275 (define-keyword
1276   (name gr-names)
1277   (print-name h-gr)
1278   (prefix "")
1279   (values
1280    (sp 1) (fp 2)
1281    (gr0   0)(gr1   1)(gr2   2)(gr3   3)(gr4   4)(gr5   5)(gr6   6)(gr7   7)
1282    (gr8   8)(gr9   9)(gr10 10)(gr11 11)(gr12 12)(gr13 13)(gr14 14)(gr15 15)
1283    (gr16 16)(gr17 17)(gr18 18)(gr19 19)(gr20 20)(gr21 21)(gr22 22)(gr23 23)
1284    (gr24 24)(gr25 25)(gr26 26)(gr27 27)(gr28 28)(gr29 29)(gr30 30)(gr31 31)
1285    (gr32 32)(gr33 33)(gr34 34)(gr35 35)(gr36 36)(gr37 37)(gr38 38)(gr39 39)
1286    (gr40 40)(gr41 41)(gr42 42)(gr43 43)(gr44 44)(gr45 45)(gr46 46)(gr47 47)
1287    (gr48 48)(gr49 49)(gr50 50)(gr51 51)(gr52 52)(gr53 53)(gr54 54)(gr55 55)
1288    (gr56 56)(gr57 57)(gr58 58)(gr59 59)(gr60 60)(gr61 61)(gr62 62)(gr63 63)
1289   )
1290 )
1291
1292 (define-hardware
1293   (name h-gr)
1294   (comment "general registers")
1295   (attrs PROFILE)
1296   (type register USI (64))
1297   (indices extern-keyword gr-names)
1298   (get (index) (c-call WI "@cpu@_h_gr_get_handler" index))
1299   (set (index newval) (c-call VOID "@cpu@_h_gr_set_handler" index newval))
1300 )
1301
1302 ; General Registers as double words
1303 ; These registers are shadowed onto h-gr
1304 (define-hardware
1305   (name h-gr_double)
1306   (comment "general registers as double words")
1307   (attrs PROFILE VIRTUAL)
1308   (type register DI (32))
1309   ; FIXME: Need constraint to prohibit odd numbers.
1310   (indices extern-keyword gr-names)
1311   (get (index)
1312        (c-call DI "@cpu@_h_gr_double_get_handler" index))
1313   (set (index newval)
1314        (c-call VOID "@cpu@_h_gr_double_set_handler" index newval))
1315 )
1316
1317 ; General Registers as high and low half words
1318 ; These registers are shadowed onto h-gr
1319 (define-hardware
1320   (name h-gr_hi)
1321   (comment "general registers as high half word")
1322   (attrs PROFILE VIRTUAL)
1323   (type register UHI (64))
1324   (indices extern-keyword gr-names)
1325   (get (index) (c-call UHI "@cpu@_h_gr_hi_get_handler" index))
1326   (set (index newval) (c-call VOID "@cpu@_h_gr_hi_set_handler" index newval))
1327 )
1328 (define-hardware
1329   (name h-gr_lo)
1330   (comment "general registers as low half word")
1331   (attrs PROFILE VIRTUAL)
1332   (type register UHI (64))
1333   (indices extern-keyword gr-names)
1334   (get (index) (c-call UHI "@cpu@_h_gr_lo_get_handler" index))
1335   (set (index newval) (c-call VOID "@cpu@_h_gr_lo_set_handler" index newval))
1336 )
1337
1338 ; Floating Point Registers
1339 (define-keyword
1340   (name fr-names)
1341   (print-name h-fr)
1342   (prefix "")
1343   (values
1344    (fr0   0)(fr1   1)(fr2   2)(fr3   3)(fr4   4)(fr5   5)(fr6   6)(fr7   7)
1345    (fr8   8)(fr9   9)(fr10 10)(fr11 11)(fr12 12)(fr13 13)(fr14 14)(fr15 15)
1346    (fr16 16)(fr17 17)(fr18 18)(fr19 19)(fr20 20)(fr21 21)(fr22 22)(fr23 23)
1347    (fr24 24)(fr25 25)(fr26 26)(fr27 27)(fr28 28)(fr29 29)(fr30 30)(fr31 31)
1348    (fr32 32)(fr33 33)(fr34 34)(fr35 35)(fr36 36)(fr37 37)(fr38 38)(fr39 39)
1349    (fr40 40)(fr41 41)(fr42 42)(fr43 43)(fr44 44)(fr45 45)(fr46 46)(fr47 47)
1350    (fr48 48)(fr49 49)(fr50 50)(fr51 51)(fr52 52)(fr53 53)(fr54 54)(fr55 55)
1351    (fr56 56)(fr57 57)(fr58 58)(fr59 59)(fr60 60)(fr61 61)(fr62 62)(fr63 63)
1352   )
1353 )
1354
1355 (define-hardware
1356   (name h-fr)
1357   (comment "floating point registers")
1358   (attrs PROFILE)
1359   (type register SF (64))
1360   (indices extern-keyword fr-names)
1361   (get (index) (c-call SF "@cpu@_h_fr_get_handler" index))
1362   (set (index newval) (c-call VOID "@cpu@_h_fr_set_handler" index newval))
1363 )
1364
1365 ; Floating Point Registers as double precision
1366 ; These registers are shadowed onto h-fr
1367
1368 (define-hardware
1369   (name h-fr_double)
1370   (comment "floating point registers as double precision")
1371   (attrs PROFILE VIRTUAL)
1372   (type register DF (32))
1373   ; FIXME: Need constraint to prohibit odd numbers.
1374   (indices extern-keyword fr-names)
1375   (get (index)
1376        (c-call DF "@cpu@_h_fr_double_get_handler" index))
1377   (set (index newval)
1378        (c-call VOID "@cpu@_h_fr_double_set_handler" index newval))
1379 )
1380
1381 ; Floating Point Registers as integer words.
1382 ; These registers are shadowed onto h-fr
1383
1384 (define-hardware
1385   (name h-fr_int)
1386   (comment "floating point registers as integers")
1387   (attrs PROFILE VIRTUAL)
1388   (type register USI (64))
1389   (indices extern-keyword fr-names)
1390   (get (index)
1391        (c-call USI "@cpu@_h_fr_int_get_handler" index))
1392   (set (index newval)
1393        (c-call VOID "@cpu@_h_fr_int_set_handler" index newval))
1394 )
1395
1396 ; Floating Point Registers as high and low half words
1397 ; These registers are shadowed onto h-fr
1398 (define-hardware
1399   (name h-fr_hi)
1400   (comment "floating point registers as unsigned high half word")
1401   (attrs PROFILE VIRTUAL)
1402   (type register UHI (64))
1403   (indices extern-keyword fr-names)
1404   (get (regno) (srl (reg h-fr_int regno) 16))
1405   (set (regno newval) (set (reg h-fr_int regno)
1406                            (or (and (reg h-fr_int regno) #xffff)
1407                                (sll newval 16))))
1408 )
1409 (define-hardware
1410   (name h-fr_lo)
1411   (comment "floating point registers as unsigned low half word")
1412   (attrs PROFILE VIRTUAL)
1413   (type register UHI (64))
1414   (indices extern-keyword fr-names)
1415   (get (regno) (and (reg h-fr_int regno) #xffff))
1416   (set (regno newval) (set (reg h-fr_int regno)
1417                            (or (and (reg h-fr_int regno) #xffff0000)
1418                                (and newval #xffff))))
1419 )
1420
1421 ; Floating Point Registers as unsigned bytes
1422 ; These registers are shadowed onto h-fr
1423 (define-hardware
1424   (name h-fr_0)
1425   (comment "floating point registers as unsigned byte 0")
1426   (attrs PROFILE VIRTUAL)
1427   (type register UHI (64))
1428   (indices extern-keyword fr-names)
1429   (get (regno) (and (reg h-fr_int regno) #xff))
1430   (set (regno newval)
1431        (sequence ()
1432                  (if (gt USI newval #xff)
1433                      (set newval #xff))
1434                  (set (reg h-fr_int regno) (or (and (reg h-fr_int regno) #xffffff00)
1435                                            newval))))
1436 )
1437 (define-hardware
1438   (name h-fr_1)
1439   (comment "floating point registers as unsigned byte 1")
1440   (attrs PROFILE VIRTUAL)
1441   (type register UHI (64))
1442   (indices extern-keyword fr-names)
1443   (get (regno) (and (srl (reg h-fr_int regno) 8) #xff))
1444   (set (regno newval)
1445        (sequence ()
1446                  (if (gt USI newval #xff)
1447                      (set newval #xff))
1448                  (set (reg h-fr_int regno) (or (and (reg h-fr_int regno) #xffff00ff) 
1449                                            (sll newval 8)))))
1450 )
1451 (define-hardware
1452   (name h-fr_2)
1453   (comment "floating point registers as unsigned byte 2")
1454   (attrs PROFILE VIRTUAL)
1455   (type register UHI (64))
1456   (indices extern-keyword fr-names)
1457   (get (regno) (and (srl (reg h-fr_int regno) 16) #xff))
1458   (set (regno newval)
1459        (sequence ()
1460                  (if (gt USI newval #xff)
1461                      (set newval #xff))
1462                  (set (reg h-fr_int regno) (or (and (reg h-fr_int regno) #xff00ffff) 
1463                                            (sll newval 16)))))
1464 )
1465 (define-hardware
1466   (name h-fr_3)
1467   (comment "floating point registers as unsigned byte 3")
1468   (attrs PROFILE VIRTUAL)
1469   (type register UHI (64))
1470   (indices extern-keyword fr-names)
1471   (get (regno) (and (srl (reg h-fr_int regno) 24) #xff))
1472   (set (regno newval)
1473        (sequence ()
1474                  (if (gt USI newval #xff)
1475                      (set newval #xff))
1476                  (set (reg h-fr_int regno) (or (and (reg h-fr_int regno) #x00ffffff) 
1477                                            (sll newval 24)))))
1478 )
1479 ; Coprocessor Registers
1480 ;
1481 (define-keyword
1482   (name cpr-names)
1483   (print-name h-cpr)
1484   (prefix "")
1485   (values
1486 (cpr0   0)(cpr1   1)(cpr2   2)(cpr3   3)(cpr4   4)(cpr5   5)(cpr6   6)(cpr7   7)
1487 (cpr8   8)(cpr9   9)(cpr10 10)(cpr11 11)(cpr12 12)(cpr13 13)(cpr14 14)(cpr15 15)
1488 (cpr16 16)(cpr17 17)(cpr18 18)(cpr19 19)(cpr20 20)(cpr21 21)(cpr22 22)(cpr23 23)
1489 (cpr24 24)(cpr25 25)(cpr26 26)(cpr27 27)(cpr28 28)(cpr29 29)(cpr30 30)(cpr31 31)
1490 (cpr32 32)(cpr33 33)(cpr34 34)(cpr35 35)(cpr36 36)(cpr37 37)(cpr38 38)(cpr39 39)
1491 (cpr40 40)(cpr41 41)(cpr42 42)(cpr43 43)(cpr44 44)(cpr45 45)(cpr46 46)(cpr47 47)
1492 (cpr48 48)(cpr49 49)(cpr50 50)(cpr51 51)(cpr52 52)(cpr53 53)(cpr54 54)(cpr55 55)
1493 (cpr56 56)(cpr57 57)(cpr58 58)(cpr59 59)(cpr60 60)(cpr61 61)(cpr62 62)(cpr63 63)
1494   )
1495 )
1496
1497 (define-hardware
1498   (name h-cpr)
1499   (comment "coprocessor registers")
1500   (attrs PROFILE (MACH frv))
1501   (type register WI (64))
1502   (indices extern-keyword cpr-names)
1503 )
1504
1505 ; Coprocessor Registers as double words
1506 ; These registers are shadowed onto h-cpr
1507 (define-hardware
1508   (name h-cpr_double)
1509   (comment "coprocessor registers as double words")
1510   (attrs PROFILE VIRTUAL (MACH frv))
1511   (type register DI (32))
1512   ; FIXME: Need constraint to prohibit odd numbers.
1513   (indices extern-keyword cpr-names)
1514   (get (index)
1515        (c-call DI "@cpu@_h_cpr_double_get_handler" index))
1516   (set (index newval)
1517        (c-call VOID "@cpu@_h_cpr_double_set_handler" index newval))
1518 )
1519
1520 ; Special Purpose Registers
1521 ;
1522 (define-keyword
1523   (name spr-names)
1524   (print-name h-spr)
1525   (prefix "")
1526   (values
1527    (psr        0) (pcsr       1) (bpcsr      2) (tbr        3) (bpsr       4)
1528
1529    (hsr0      16) (hsr1      17) (hsr2      18) (hsr3      19)
1530    (hsr4      20) (hsr5      21) (hsr6      22) (hsr7      23)
1531    (hsr8      24) (hsr9      25) (hsr10     26) (hsr11     27)
1532    (hsr12     28) (hsr13     29) (hsr14     30) (hsr15     31)
1533    (hsr16     32) (hsr17     33) (hsr18     34) (hsr19     35)
1534    (hsr20     36) (hsr21     37) (hsr22     38) (hsr23     39)
1535    (hsr24     40) (hsr25     41) (hsr26     42) (hsr27     43)
1536    (hsr28     44) (hsr29     45) (hsr30     46) (hsr31     47)
1537    (hsr32     48) (hsr33     49) (hsr34     50) (hsr35     51)
1538    (hsr36     52) (hsr37     53) (hsr38     54) (hsr39     55)
1539    (hsr40     56) (hsr41     57) (hsr42     58) (hsr43     59)
1540    (hsr44     60) (hsr45     61) (hsr46     62) (hsr47     63)
1541    (hsr48     64) (hsr49     65) (hsr50     66) (hsr51     67)
1542    (hsr52     68) (hsr53     69) (hsr54     70) (hsr55     71)
1543    (hsr56     72) (hsr57     73) (hsr58     74) (hsr59     75)
1544    (hsr60     76) (hsr61     77) (hsr62     78) (hsr63     79)
1545
1546    (ccr      256) (cccr     263) (lr       272) (lcr      273) (isr      288)
1547
1548    (neear0   352) (neear1   353) (neear2   354) (neear3   355)
1549    (neear4   356) (neear5   357) (neear6   358) (neear7   359)
1550    (neear8   360) (neear9   361) (neear10  362) (neear11  363)
1551    (neear12  364) (neear13  365) (neear14  366) (neear15  367)
1552    (neear16  368) (neear17  369) (neear18  370) (neear19  371)
1553    (neear20  372) (neear21  373) (neear22  374) (neear23  375)
1554    (neear24  376) (neear25  377) (neear26  378) (neear27  379)
1555    (neear28  380) (neear29  381) (neear30  382) (neear31  383)
1556
1557    (nesr0    384) (nesr1    385) (nesr2    386) (nesr3    387)
1558    (nesr4    388) (nesr5    389) (nesr6    390) (nesr7    391)
1559    (nesr8    392) (nesr9    393) (nesr10   394) (nesr11   395)
1560    (nesr12   396) (nesr13   397) (nesr14   398) (nesr15   399)
1561    (nesr16   400) (nesr17   401) (nesr18   402) (nesr19   403)
1562    (nesr20   404) (nesr21   405) (nesr22   406) (nesr23   407)
1563    (nesr24   408) (nesr25   409) (nesr26   410) (nesr27   411)
1564    (nesr28   412) (nesr29   413) (nesr30   414) (nesr31   415)
1565
1566    (necr     416)
1567
1568    (gner0    432) (gner1    433)
1569
1570    (fner0    434) (fner1    435)
1571
1572    (epcr0    512) (epcr1    513) (epcr2    514) (epcr3    515)
1573    (epcr4    516) (epcr5    517) (epcr6    518) (epcr7    519)
1574    (epcr8    520) (epcr9    521) (epcr10   522) (epcr11   523)
1575    (epcr12   524) (epcr13   525) (epcr14   526) (epcr15   527)
1576    (epcr16   528) (epcr17   529) (epcr18   530) (epcr19   531)
1577    (epcr20   532) (epcr21   533) (epcr22   534) (epcr23   535)
1578    (epcr24   536) (epcr25   537) (epcr26   538) (epcr27   539)
1579    (epcr28   540) (epcr29   541) (epcr30   542) (epcr31   543)
1580    (epcr32   544) (epcr33   545) (epcr34   546) (epcr35   547)
1581    (epcr36   548) (epcr37   549) (epcr38   550) (epcr39   551)
1582    (epcr40   552) (epcr41   553) (epcr42   554) (epcr43   555)
1583    (epcr44   556) (epcr45   557) (epcr46   558) (epcr47   559)
1584    (epcr48   560) (epcr49   561) (epcr50   562) (epcr51   563)
1585    (epcr52   564) (epcr53   565) (epcr54   566) (epcr55   567)
1586    (epcr56   568) (epcr57   569) (epcr58   570) (epcr59   571)
1587    (epcr60   572) (epcr61   573) (epcr62   574) (epcr63   575)
1588
1589    (esr0     576) (esr1     577) (esr2     578) (esr3     579)
1590    (esr4     580) (esr5     581) (esr6     582) (esr7     583)
1591    (esr8     584) (esr9     585) (esr10    586) (esr11    587)
1592    (esr12    588) (esr13    589) (esr14    590) (esr15    591)
1593    (esr16    592) (esr17    593) (esr18    594) (esr19    595)
1594    (esr20    596) (esr21    597) (esr22    598) (esr23    599)
1595    (esr24    600) (esr25    601) (esr26    602) (esr27    603)
1596    (esr28    604) (esr29    605) (esr30    606) (esr31    607)
1597    (esr32    608) (esr33    609) (esr34    610) (esr35    611)
1598    (esr36    612) (esr37    613) (esr38    614) (esr39    615)
1599    (esr40    616) (esr41    617) (esr42    618) (esr43    619)
1600    (esr44    620) (esr45    621) (esr46    622) (esr47    623)
1601    (esr48    624) (esr49    625) (esr50    626) (esr51    627)
1602    (esr52    628) (esr53    629) (esr54    630) (esr55    631)
1603    (esr56    632) (esr57    633) (esr58    634) (esr59    635)
1604    (esr60    636) (esr61    637) (esr62    638) (esr63    639)
1605
1606    (eir0     640) (eir1     641) (eir2     642) (eir3     643)
1607    (eir4     644) (eir5     645) (eir6     646) (eir7     647)
1608    (eir8     648) (eir9     649) (eir10    650) (eir11    651)
1609    (eir12    652) (eir13    653) (eir14    654) (eir15    655)
1610    (eir16    656) (eir17    657) (eir18    658) (eir19    659)
1611    (eir20    660) (eir21    661) (eir22    662) (eir23    663)
1612    (eir24    664) (eir25    665) (eir26    666) (eir27    667)
1613    (eir28    668) (eir29    669) (eir30    670) (eir31    671)
1614
1615    (esfr0    672) (esfr1    673)
1616
1617    (sr0      768) (sr1      769) (sr2      770) (sr3      771) 
1618
1619    (fsr0    1024) (fsr1    1025) (fsr2    1026) (fsr3    1027)
1620    (fsr4    1028) (fsr5    1029) (fsr6    1030) (fsr7    1031)
1621    (fsr8    1032) (fsr9    1033) (fsr10   1034) (fsr11   1035)
1622    (fsr12   1036) (fsr13   1037) (fsr14   1038) (fsr15   1039)
1623    (fsr16   1040) (fsr17   1041) (fsr18   1042) (fsr19   1043)
1624    (fsr20   1044) (fsr21   1045) (fsr22   1046) (fsr23   1047)
1625    (fsr24   1048) (fsr25   1049) (fsr26   1050) (fsr27   1051)
1626    (fsr28   1052) (fsr29   1053) (fsr30   1054) (fsr31   1055)
1627    (fsr32   1056) (fsr33   1057) (fsr34   1058) (fsr35   1059)
1628    (fsr36   1060) (fsr37   1061) (fsr38   1062) (fsr39   1063)
1629    (fsr40   1064) (fsr41   1065) (fsr42   1066) (fsr43   1067)
1630    (fsr44   1068) (fsr45   1069) (fsr46   1070) (fsr47   1071)
1631    (fsr48   1072) (fsr49   1073) (fsr50   1074) (fsr51   1075)
1632    (fsr52   1076) (fsr53   1077) (fsr54   1078) (fsr55   1079)
1633    (fsr56   1080) (fsr57   1081) (fsr58   1082) (fsr59   1083)
1634    (fsr60   1084) (fsr61   1085) (fsr62   1086) (fsr63   1087)
1635
1636    ; FQ0-FQ31 are 64 bit registers.
1637    ; These names allow access to the upper 32 bits of the FQ registers.
1638    (fqop0   1088) (fqop1   1090) (fqop2   1092) (fqop3   1094) 
1639    (fqop4   1096) (fqop5   1098) (fqop6   1100) (fqop7   1102) 
1640    (fqop8   1104) (fqop9   1106) (fqop10  1108) (fqop11  1110) 
1641    (fqop12  1112) (fqop13  1114) (fqop14  1116) (fqop15  1118) 
1642    (fqop16  1120) (fqop17  1122) (fqop18  1124) (fqop19  1126) 
1643    (fqop20  1128) (fqop21  1130) (fqop22  1132) (fqop23  1134) 
1644    (fqop24  1136) (fqop25  1138) (fqop26  1140) (fqop27  1142) 
1645    (fqop28  1144) (fqop29  1146) (fqop30  1148) (fqop31  1150) 
1646    ; These names allow access to the lower 32 bits of the FQ registers.
1647    (fqst0   1089) (fqst1   1091) (fqst2   1093) (fqst3   1095) 
1648    (fqst4   1097) (fqst5   1099) (fqst6   1101) (fqst7   1103) 
1649    (fqst8   1105) (fqst9   1107) (fqst10  1109) (fqst11  1111) 
1650    (fqst12  1113) (fqst13  1115) (fqst14  1117) (fqst15  1119) 
1651    (fqst16  1121) (fqst17  1123) (fqst18  1125) (fqst19  1127) 
1652    (fqst20  1129) (fqst21  1131) (fqst22  1133) (fqst23  1135) 
1653    (fqst24  1137) (fqst25  1139) (fqst26  1141) (fqst27  1143) 
1654    (fqst28  1145) (fqst29  1147) (fqst30  1149) (fqst31  1151) 
1655    ; These also access the lower 32 bits of the FQ registers.
1656    ; These are not accessible as spr registers (see LSI appendix - section 13.4)
1657 ;  (fq0     1089) (fq1     1091) (fq2     1093) (fq3     1095) 
1658 ;  (fq4     1097) (fq5     1099) (fq6     1101) (fq7     1103) 
1659 ;  (fq8     1105) (fq9     1107) (fq10    1109) (fq11    1111) 
1660 ;  (fq12    1113) (fq13    1115) (fq14    1117) (fq15    1119) 
1661 ;  (fq16    1121) (fq17    1123) (fq18    1125) (fq19    1127) 
1662 ;  (fq20    1129) (fq21    1131) (fq22    1133) (fq23    1135) 
1663 ;  (fq24    1137) (fq25    1139) (fq26    1141) (fq27    1143) 
1664 ;  (fq28    1145) (fq29    1147) (fq30    1149) (fq31    1151) 
1665
1666    (mcilr0  1272) (mcilr1  1273)
1667
1668    (msr0    1280) (msr1    1281) (msr2    1282) (msr3    1283)
1669    (msr4    1284) (msr5    1285) (msr6    1286) (msr7    1287)
1670    (msr8    1288) (msr9    1289) (msr10   1290) (msr11   1291)
1671    (msr12   1292) (msr13   1293) (msr14   1294) (msr15   1295)
1672    (msr16   1296) (msr17   1297) (msr18   1298) (msr19   1299)
1673    (msr20   1300) (msr21   1301) (msr22   1302) (msr23   1303)
1674    (msr24   1304) (msr25   1305) (msr26   1306) (msr27   1307)
1675    (msr28   1308) (msr29   1309) (msr30   1310) (msr31   1311)
1676    (msr32   1312) (msr33   1313) (msr34   1314) (msr35   1315)
1677    (msr36   1316) (msr37   1317) (msr38   1318) (msr39   1319)
1678    (msr40   1320) (msr41   1321) (msr42   1322) (msr43   1323)
1679    (msr44   1324) (msr45   1325) (msr46   1326) (msr47   1327)
1680    (msr48   1328) (msr49   1329) (msr50   1330) (msr51   1331)
1681    (msr52   1332) (msr53   1333) (msr54   1334) (msr55   1335)
1682    (msr56   1336) (msr57   1337) (msr58   1338) (msr59   1339)
1683    (msr60   1340) (msr61   1341) (msr62   1342) (msr63   1343)
1684
1685    ; MQ0-MQ31 are 64 bit registers.
1686    ; These names allow access to the upper 32 bits of the MQ registers.
1687    (mqop0   1344) (mqop1   1346) (mqop2   1348) (mqop3   1350) 
1688    (mqop4   1352) (mqop5   1354) (mqop6   1356) (mqop7   1358) 
1689    (mqop8   1360) (mqop9   1362) (mqop10  1364) (mqop11  1366) 
1690    (mqop12  1368) (mqop13  1370) (mqop14  1372) (mqop15  1374) 
1691    (mqop16  1376) (mqop17  1378) (mqop18  1380) (mqop19  1382) 
1692    (mqop20  1384) (mqop21  1386) (mqop22  1388) (mqop23  1390) 
1693    (mqop24  1392) (mqop25  1394) (mqop26  1396) (mqop27  1398) 
1694    (mqop28  1400) (mqop29  1402) (mqop30  1404) (mqop31  1406) 
1695    ; These names allow access to the lower 32 bits of the MQ registers.
1696    (mqst0   1345) (mqst1   1347) (mqst2   1349) (mqst3   1351) 
1697    (mqst4   1353) (mqst5   1355) (mqst6   1357) (mqst7   1359) 
1698    (mqst8   1361) (mqst9   1363) (mqst10  1365) (mqst11  1367) 
1699    (mqst12  1369) (mqst13  1371) (mqst14  1373) (mqst15  1375) 
1700    (mqst16  1377) (mqst17  1379) (mqst18  1381) (mqst19  1383) 
1701    (mqst20  1385) (mqst21  1387) (mqst22  1389) (mqst23  1391) 
1702    (mqst24  1393) (mqst25  1395) (mqst26  1397) (mqst27  1399) 
1703    (mqst28  1401) (mqst29  1403) (mqst30  1405) (mqst31  1407) 
1704    ; These also access the lower 32 bits of the MQ registers.
1705    ; These are not accessible as spr registers (see LSI appendix - section 13.4)
1706 ;  (mq0     1345) (mq1     1347) (mq2     1349) (mq3     1351) 
1707 ;  (mq4     1353) (mq5     1355) (mq6     1357) (mq7     1359) 
1708 ;  (mq8     1361) (mq9     1363) (mq10    1365) (mq11    1367) 
1709 ;  (mq12    1369) (mq13    1371) (mq14    1373) (mq15    1375) 
1710 ;  (mq16    1377) (mq17    1379) (mq18    1381) (mq19    1383) 
1711 ;  (mq20    1385) (mq21    1387) (mq22    1389) (mq23    1391) 
1712 ;  (mq24    1393) (mq25    1395) (mq26    1397) (mq27    1399) 
1713 ;  (mq28    1401) (mq29    1403) (mq30    1405) (mq31    1407) 
1714
1715    ; These are not accessible as spr registers (see LSI appendix - section 13.4)
1716 ;  (acc0    1408) (acc1    1409) (acc2    1410) (acc3    1411)
1717 ;  (acc4    1412) (acc5    1413) (acc6    1414) (acc7    1415)
1718 ;  (acc8    1416) (acc9    1417) (acc10   1418) (acc11   1419)
1719 ;  (acc12   1420) (acc13   1421) (acc14   1422) (acc15   1423)
1720 ;  (acc16   1424) (acc17   1425) (acc18   1426) (acc19   1427)
1721 ;  (acc20   1428) (acc21   1429) (acc22   1430) (acc23   1431)
1722 ;  (acc24   1432) (acc25   1433) (acc26   1434) (acc27   1435)
1723 ;  (acc28   1436) (acc29   1437) (acc30   1438) (acc31   1439)
1724 ;  (acc32   1440) (acc33   1441) (acc34   1442) (acc35   1443)
1725 ;  (acc36   1444) (acc37   1445) (acc38   1446) (acc39   1447)
1726 ;  (acc40   1448) (acc41   1449) (acc42   1450) (acc43   1451)
1727 ;  (acc44   1452) (acc45   1453) (acc46   1454) (acc47   1455)
1728 ;  (acc48   1456) (acc49   1457) (acc50   1458) (acc51   1459)
1729 ;  (acc52   1460) (acc53   1461) (acc54   1462) (acc55   1463)
1730 ;  (acc56   1464) (acc57   1465) (acc58   1466) (acc59   1467)
1731 ;  (acc60   1468) (acc61   1469) (acc62   1470) (acc63   1471)
1732
1733 ;  (accg0   1472) (accg1   1473) (accg2   1474) (accg3   1475)
1734 ;  (accg4   1476) (accg5   1477) (accg6   1478) (accg7   1479)
1735 ;  (accg8   1480) (accg9   1481) (accg10  1482) (accg11  1483)
1736 ;  (accg12  1484) (accg13  1485) (accg14  1486) (accg15  1487)
1737 ;  (accg16  1488) (accg17  1489) (accg18  1490) (accg19  1491)
1738 ;  (accg20  1492) (accg21  1493) (accg22  1494) (accg23  1495)
1739 ;  (accg24  1496) (accg25  1497) (accg26  1498) (accg27  1499)
1740 ;  (accg28  1500) (accg29  1501) (accg30  1502) (accg31  1503)
1741 ;  (accg32  1504) (accg33  1505) (accg34  1506) (accg35  1507)
1742 ;  (accg36  1508) (accg37  1509) (accg38  1510) (accg39  1511)
1743 ;  (accg40  1512) (accg41  1513) (accg42  1514) (accg43  1515)
1744 ;  (accg44  1516) (accg45  1517) (accg46  1518) (accg47  1519)
1745 ;  (accg48  1520) (accg49  1521) (accg50  1522) (accg51  1523)
1746 ;  (accg52  1524) (accg53  1525) (accg54  1526) (accg55  1527)
1747 ;  (accg56  1528) (accg57  1529) (accg58  1530) (accg59  1531)
1748 ;  (accg60  1532) (accg61  1533) (accg62  1534) (accg63  1535)
1749
1750    (ear0    1536) (ear1    1537) (ear2    1538) (ear3    1539)
1751    (ear4    1540) (ear5    1541) (ear6    1542) (ear7    1543)
1752    (ear8    1544) (ear9    1545) (ear10   1546) (ear11   1547)
1753    (ear12   1548) (ear13   1549) (ear14   1550) (ear15   1551)
1754    (ear16   1552) (ear17   1553) (ear18   1554) (ear19   1555)
1755    (ear20   1556) (ear21   1557) (ear22   1558) (ear23   1559)
1756    (ear24   1560) (ear25   1561) (ear26   1562) (ear27   1563)
1757    (ear28   1564) (ear29   1565) (ear30   1566) (ear31   1567)
1758    (ear32   1568) (ear33   1569) (ear34   1570) (ear35   1571)
1759    (ear36   1572) (ear37   1573) (ear38   1574) (ear39   1575)
1760    (ear40   1576) (ear41   1577) (ear42   1578) (ear43   1579)
1761    (ear44   1580) (ear45   1581) (ear46   1582) (ear47   1583)
1762    (ear48   1584) (ear49   1585) (ear50   1586) (ear51   1587)
1763    (ear52   1588) (ear53   1589) (ear54   1590) (ear55   1591)
1764    (ear56   1592) (ear57   1593) (ear58   1594) (ear59   1595)
1765    (ear60   1596) (ear61   1597) (ear62   1598) (ear63   1599)
1766
1767    (edr0    1600) (edr1    1601) (edr2    1602) (edr3    1603)
1768    (edr4    1604) (edr5    1605) (edr6    1606) (edr7    1607)
1769    (edr8    1608) (edr9    1609) (edr10   1610) (edr11   1611)
1770    (edr12   1612) (edr13   1613) (edr14   1614) (edr15   1615)
1771    (edr16   1616) (edr17   1617) (edr18   1618) (edr19   1619)
1772    (edr20   1620) (edr21   1621) (edr22   1622) (edr23   1623)
1773    (edr24   1624) (edr25   1625) (edr26   1626) (edr27   1627)
1774    (edr28   1628) (edr29   1629) (edr30   1630) (edr31   1631)
1775    (edr32   1632) (edr33   1636) (edr34   1634) (edr35   1635)
1776    (edr36   1636) (edr37   1637) (edr38   1638) (edr39   1639)
1777    (edr40   1640) (edr41   1641) (edr42   1642) (edr43   1643)
1778    (edr44   1644) (edr45   1645) (edr46   1646) (edr47   1647)
1779    (edr48   1648) (edr49   1649) (edr50   1650) (edr51   1651)
1780    (edr52   1652) (edr53   1653) (edr54   1654) (edr55   1655)
1781    (edr56   1656) (edr57   1657) (edr58   1658) (edr59   1659)
1782    (edr60   1660) (edr61   1661) (edr62   1662) (edr63   1663)
1783
1784    (iamlr0  1664) (iamlr1  1665) (iamlr2  1666) (iamlr3  1667)
1785    (iamlr4  1668) (iamlr5  1669) (iamlr6  1670) (iamlr7  1671)
1786    (iamlr8  1672) (iamlr9  1673) (iamlr10 1674) (iamlr11 1675)
1787    (iamlr12 1676) (iamlr13 1677) (iamlr14 1678) (iamlr15 1679)
1788    (iamlr16 1680) (iamlr17 1681) (iamlr18 1682) (iamlr19 1683)
1789    (iamlr20 1684) (iamlr21 1685) (iamlr22 1686) (iamlr23 1687)
1790    (iamlr24 1688) (iamlr25 1689) (iamlr26 1690) (iamlr27 1691)
1791    (iamlr28 1692) (iamlr29 1693) (iamlr30 1694) (iamlr31 1695)
1792    (iamlr32 1696) (iamlr33 1697) (iamlr34 1698) (iamlr35 1699)
1793    (iamlr36 1700) (iamlr37 1701) (iamlr38 1702) (iamlr39 1703)
1794    (iamlr40 1704) (iamlr41 1705) (iamlr42 1706) (iamlr43 1707)
1795    (iamlr44 1708) (iamlr45 1709) (iamlr46 1710) (iamlr47 1711)
1796    (iamlr48 1712) (iamlr49 1713) (iamlr50 1714) (iamlr51 1715)
1797    (iamlr52 1716) (iamlr53 1717) (iamlr54 1718) (iamlr55 1719)
1798    (iamlr56 1720) (iamlr57 1721) (iamlr58 1722) (iamlr59 1723)
1799    (iamlr60 1724) (iamlr61 1725) (iamlr62 1726) (iamlr63 1727)
1800
1801    (iampr0  1728) (iampr1  1729) (iampr2  1730) (iampr3  1731)
1802    (iampr4  1732) (iampr5  1733) (iampr6  1734) (iampr7  1735)
1803    (iampr8  1736) (iampr9  1737) (iampr10 1738) (iampr11 1739)
1804    (iampr12 1740) (iampr13 1741) (iampr14 1742) (iampr15 1743)
1805    (iampr16 1744) (iampr17 1745) (iampr18 1746) (iampr19 1747)
1806    (iampr20 1748) (iampr21 1749) (iampr22 1750) (iampr23 1751)
1807    (iampr24 1752) (iampr25 1753) (iampr26 1754) (iampr27 1755)
1808    (iampr28 1756) (iampr29 1757) (iampr30 1758) (iampr31 1759)
1809    (iampr32 1760) (iampr33 1761) (iampr34 1762) (iampr35 1763)
1810    (iampr36 1764) (iampr37 1765) (iampr38 1766) (iampr39 1767)
1811    (iampr40 1768) (iampr41 1769) (iampr42 1770) (iampr43 1771)
1812    (iampr44 1772) (iampr45 1773) (iampr46 1774) (iampr47 1775)
1813    (iampr48 1776) (iampr49 1777) (iampr50 1778) (iampr51 1779)
1814    (iampr52 1780) (iampr53 1781) (iampr54 1782) (iampr55 1783)
1815    (iampr56 1784) (iampr57 1785) (iampr58 1786) (iampr59 1787)
1816    (iampr60 1788) (iampr61 1789) (iampr62 1790) (iampr63 1791)
1817
1818    (damlr0  1792) (damlr1  1793) (damlr2  1794) (damlr3  1795)
1819    (damlr4  1796) (damlr5  1797) (damlr6  1798) (damlr7  1799)
1820    (damlr8  1800) (damlr9  1801) (damlr10 1802) (damlr11 1803)
1821    (damlr12 1804) (damlr13 1805) (damlr14 1806) (damlr15 1807)
1822    (damlr16 1808) (damlr17 1809) (damlr18 1810) (damlr19 1811)
1823    (damlr20 1812) (damlr21 1813) (damlr22 1814) (damlr23 1815)
1824    (damlr24 1816) (damlr25 1817) (damlr26 1818) (damlr27 1819)
1825    (damlr28 1820) (damlr29 1821) (damlr30 1822) (damlr31 1823)
1826    (damlr32 1824) (damlr33 1825) (damlr34 1826) (damlr35 1827)
1827    (damlr36 1828) (damlr37 1829) (damlr38 1830) (damlr39 1831)
1828    (damlr40 1832) (damlr41 1833) (damlr42 1834) (damlr43 1835)
1829    (damlr44 1836) (damlr45 1837) (damlr46 1838) (damlr47 1839)
1830    (damlr48 1840) (damlr49 1841) (damlr50 1842) (damlr51 1843)
1831    (damlr52 1844) (damlr53 1845) (damlr54 1846) (damlr55 1847)
1832    (damlr56 1848) (damlr57 1849) (damlr58 1850) (damlr59 1851)
1833    (damlr60 1852) (damlr61 1853) (damlr62 1854) (damlr63 1855)
1834
1835    (dampr0  1856) (dampr1  1857) (dampr2  1858) (dampr3  1859)
1836    (dampr4  1860) (dampr5  1861) (dampr6  1862) (dampr7  1863)
1837    (dampr8  1864) (dampr9  1865) (dampr10 1866) (dampr11 1867)
1838    (dampr12 1868) (dampr13 1869) (dampr14 1870) (dampr15 1871)
1839    (dampr16 1872) (dampr17 1873) (dampr18 1874) (dampr19 1875)
1840    (dampr20 1876) (dampr21 1877) (dampr22 1878) (dampr23 1879)
1841    (dampr24 1880) (dampr25 1881) (dampr26 1882) (dampr27 1883)
1842    (dampr28 1884) (dampr29 1885) (dampr30 1886) (dampr31 1887)
1843    (dampr32 1888) (dampr33 1889) (dampr34 1890) (dampr35 1891)
1844    (dampr36 1892) (dampr37 1893) (dampr38 1894) (dampr39 1895)
1845    (dampr40 1896) (dampr41 1897) (dampr42 1898) (dampr43 1899)
1846    (dampr44 1900) (dampr45 1901) (dampr46 1902) (dampr47 1903)
1847    (dampr48 1904) (dampr49 1905) (dampr50 1906) (dampr51 1907)
1848    (dampr52 1908) (dampr53 1909) (dampr54 1910) (dampr55 1911)
1849    (dampr56 1912) (dampr57 1913) (dampr58 1914) (dampr59 1915)
1850    (dampr60 1916) (dampr61 1917) (dampr62 1918) (dampr63 1919)
1851
1852    (amcr    1920) (stbar   1921) (mmcr    1922)
1853    (dcr     2048) (brr     2049) (nmar    2050)
1854
1855    (ibar0   2052) (ibar1   2053) (ibar2   2054) (ibar3   2055)
1856    (dbar0   2056) (dbar1   2057) (dbar2   2058) (dbar3   2059)
1857
1858    (dbdr00  2060) (dbdr01  2061) (dbdr02  2062) (dbdr03  2063)
1859    (dbdr10  2064) (dbdr11  2065) (dbdr12  2066) (dbdr13  2067)
1860    (dbdr20  2068) (dbdr21  2069) (dbdr22  2070) (dbdr23  2071)
1861    (dbdr30  2072) (dbdr31  2073) (dbdr32  2074) (dbdr33  2075)
1862
1863    (dbmr00  2076) (dbmr01  2077) (dbmr02  2078) (dbmr03  2079)
1864    (dbmr10  2080) (dbmr11  2081) (dbmr12  2082) (dbmr13  2083)
1865    (dbmr20  2084) (dbmr21  2085) (dbmr22  2086) (dbmr23  2087)
1866    (dbmr30  2088) (dbmr31  2089) (dbmr32  2090) (dbmr33  2091)
1867
1868    (cpcfr   2092) (cpcr    2093) (cpsr    2094)
1869
1870    (cpesr0  2096) (cpesr1  2097)
1871    (cpemr0  2098) (cpemr1  2099)
1872
1873    (ihsr8   3848)
1874   )
1875 )
1876
1877 (define-hardware
1878   (name h-spr)
1879   (comment "special purpose registers")
1880   (attrs PROFILE)
1881   (type register UWI (4096))
1882   (indices extern-keyword spr-names)
1883   (get (index) (c-call UWI "@cpu@_h_spr_get_handler" index))
1884   (set (index newval) (c-call VOID "@cpu@_h_spr_set_handler" index newval))
1885 )
1886
1887 (define-pmacro (spr-pcsr)  (reg h-spr   1))
1888 (define-pmacro (spr-bpcsr) (reg h-spr   2))
1889 (define-pmacro (spr-lr)    (reg h-spr 272))
1890 (define-pmacro (spr-lcr)   (reg h-spr 273))
1891 (define-pmacro (spr-sr0)   (reg h-spr 768))
1892 (define-pmacro (spr-sr1)   (reg h-spr 769))
1893 (define-pmacro (spr-sr2)   (reg h-spr 770))
1894 (define-pmacro (spr-sr3)   (reg h-spr 771))
1895
1896 ; Accumulator guard. Actually a subset of the SPR registers, but those SPRs
1897 ; are read-only in most insns. This hardware element is used by those insns
1898 ; which have direct access (mwtaccg, mrdaccg).
1899 (define-keyword
1900   (name accg-names)
1901   (print-name h-accg)
1902   (prefix "")
1903   (values
1904    (accg0   0)(accg1   1)(accg2   2)(accg3   3)
1905    (accg4   4)(accg5   5)(accg6   6)(accg7   7)
1906    (accg8   8)(accg9   9)(accg10 10)(accg11 11)
1907    (accg12 12)(accg13 13)(accg14 14)(accg15 15)
1908    (accg16 16)(accg17 17)(accg18 18)(accg19 19)
1909    (accg20 20)(accg21 21)(accg22 22)(accg23 23)
1910    (accg24 24)(accg25 25)(accg26 26)(accg27 27)
1911    (accg28 28)(accg29 29)(accg30 30)(accg31 31)
1912    (accg32 32)(accg33 33)(accg34 34)(accg35 35)
1913    (accg36 36)(accg37 37)(accg38 38)(accg39 39)
1914    (accg40 40)(accg41 41)(accg42 42)(accg43 43)
1915    (accg44 44)(accg45 45)(accg46 46)(accg47 47)
1916    (accg48 48)(accg49 49)(accg50 50)(accg51 51)
1917    (accg52 52)(accg53 53)(accg54 54)(accg55 55)
1918    (accg56 56)(accg57 57)(accg58 58)(accg59 59)
1919    (accg60 60)(accg61 61)(accg62 62)(accg63 63)
1920   )
1921 )
1922
1923 (define-hardware
1924   (name h-accg)
1925   (comment "accumulator guard")
1926   (attrs PROFILE VIRTUAL)
1927   (type register UWI (64))
1928   (indices extern-keyword accg-names)
1929   (get (index)
1930        (and (reg h-spr (add index 1472)) #xff))
1931   (set (index newval)
1932        (set (raw-reg UWI h-spr (add index 1472)) (and newval #xff)))
1933 )
1934
1935 ; 40 bit accumulator. Composed of ACCG and ACC registers concatenated, but
1936 ; referenced more often as the composed 40 bits.
1937 (define-keyword
1938   (name acc-names)
1939   (print-name h-acc40)
1940   (prefix "")
1941   (values
1942 (acc0   0)(acc1   1)(acc2   2)(acc3   3)(acc4   4)(acc5   5)(acc6   6)(acc7   7)
1943 (acc8   8)(acc9   9)(acc10 10)(acc11 11)(acc12 12)(acc13 13)(acc14 14)(acc15 15)
1944 (acc16 16)(acc17 17)(acc18 18)(acc19 19)(acc20 20)(acc21 21)(acc22 22)(acc23 23)
1945 (acc24 24)(acc25 25)(acc26 26)(acc27 27)(acc28 28)(acc29 29)(acc30 30)(acc31 31)
1946 (acc32 32)(acc33 33)(acc34 34)(acc35 35)(acc36 36)(acc37 37)(acc38 38)(acc39 39)
1947 (acc40 40)(acc41 41)(acc42 42)(acc43 43)(acc44 44)(acc45 45)(acc46 46)(acc47 47)
1948 (acc48 48)(acc49 49)(acc50 50)(acc51 51)(acc52 52)(acc53 53)(acc54 54)(acc55 55)
1949 (acc56 56)(acc57 57)(acc58 58)(acc59 59)(acc60 60)(acc61 61)(acc62 62)(acc63 63)
1950   )
1951 )
1952
1953 (define-hardware
1954   (name h-acc40S)
1955   (comment "40 bit signed accumulator")
1956   (attrs PROFILE VIRTUAL)
1957   (type register DI (64))
1958   (indices extern-keyword acc-names)
1959   ; The accumlator is made up of two 32 bit registers, accgi/acci.
1960   ; We want to extract this as a combined 40 signed bits
1961   (get (index)
1962        (or DI
1963            (sll  DI (ext DI (trunc QI (reg h-spr (add index 1472))))
1964                  32)
1965            (zext DI (reg h-spr (add index 1408)))))
1966   ; Bits 40-63 are not written. raw-reg is used to bypass read-only restrictions
1967   ; on ACC and ACCG registers
1968   (set (index newval)
1969        (sequence ()
1970                  (c-call VOID "frv_check_spr_write_access" (add index 1408))
1971                  (set (raw-reg UWI h-spr
1972                                (add index 1472)) (and (srl newval 32) #xff))
1973                  (set (raw-reg UWI h-spr
1974                                (add index 1408)) (trunc USI newval))))
1975 )
1976
1977 (define-hardware
1978   (name h-acc40U)
1979   (comment "40 bit unsigned accumulator")
1980   (attrs PROFILE VIRTUAL)
1981   (type register UDI (64))
1982   (indices extern-keyword acc-names)
1983   ; The accumlator is made up of two 32 bit registers, accgi/acci.
1984   ; We want to extract this as a combined 40 unsigned bits
1985   (get (index)
1986        (or DI
1987            (sll  DI (zext DI (reg h-spr (add index 1472))) 32)
1988            (zext DI (reg h-spr (add index 1408)))))
1989   ; Bits 40-63 are not written. raw-reg is used to bypass read-only restrictions
1990   ; on ACC and ACCG registers
1991   (set (index newval)
1992        (sequence ()
1993                  (c-call VOID "frv_check_spr_write_access" (add index 1408))
1994                  (set (raw-reg UWI h-spr
1995                                (add index 1472)) (and (srl newval 32) #xff))
1996                  (set (raw-reg UWI h-spr
1997                                (add index 1408)) (trunc USI newval))))
1998 )
1999
2000 ; Integer condition code registers (CCR)
2001 ;
2002 ; The individual sub registers bits of the CCR are referenced more often than
2003 ; the entire register so set them directly. We can assemble the
2004 ; entire register when necessary.
2005 ;
2006 (define-keyword
2007   (name iccr-names)
2008   (print-name h-iccr)
2009   (prefix "")
2010   (values (icc0 0) (icc1 1) (icc2 2) (icc3 3))
2011 )
2012
2013 (define-hardware
2014   (name h-iccr)
2015   (comment "Integer condition code registers")
2016   (attrs PROFILE)
2017   (type register UQI (4))
2018   (indices extern-keyword iccr-names)
2019 )
2020
2021 ; Floating point condition code registers (CCR)
2022 ;
2023 ; The individual sub registers bits of the CCR are referenced more often than
2024 ; the entire register so set them directly. We can assemble the
2025 ; entire register when necessary.
2026 ;
2027 (define-keyword
2028   (name fccr-names)
2029   (print-name h-fccr)
2030   (prefix "")
2031   (values (fcc0 0) (fcc1 1) (fcc2 2) (fcc3 3))
2032 )
2033
2034 (define-hardware
2035   (name h-fccr)
2036   (comment "Integer condition code registers")
2037   (attrs PROFILE)
2038   (type register UQI (4))
2039   (indices extern-keyword fccr-names)
2040 )
2041
2042 ; C condition code registers (CCCR)
2043 ;
2044 (define-keyword
2045   (name cccr-names)
2046   (print-name h-cccr)
2047   (prefix "")
2048   (values (cc0 0) (cc1 1) (cc2 2) (cc3 3) (cc4 4) (cc5 5) (cc6 6) (cc7 7))
2049 )
2050
2051 (define-hardware
2052   (name h-cccr)
2053   (comment "Condition code registers")
2054   (attrs PROFILE)
2055   (type register UQI (8))
2056   (indices extern-keyword cccr-names)
2057 )
2058 \f
2059 ; Dummy hardware used to define packing bit on insns
2060 ;
2061 (define-hardware
2062   (name h-pack)
2063   (comment "Packing bit dummy hardware")
2064   (type immediate (UINT 1))
2065   (values keyword "" (("" 1) (".p" 0) (".P" 0)))
2066 )
2067 ; Dummy hardware used to define hint field for branches always taken
2068 ;
2069 (define-hardware
2070   (name h-hint-taken)
2071   (comment "Branch taken hint dummy hardware")
2072   (type immediate (UINT 1))
2073   ; The order of these is important. We want '2' to get written by default,
2074   ; but we also want the docoder/disassembler to allow the values '0', '1' and
2075   ; '3'.
2076   (values keyword "" (("" 2) ("" 0) ("" 1) ("" 3)))
2077 )
2078 ; Dummy hardware used to define hint field for branches never taken
2079 ;
2080 (define-hardware
2081   (name h-hint-not-taken)
2082   (comment "Branch not taken hint dummy hardware")
2083   (type immediate (UINT 1))
2084   ; The order of these is important. We want '0' to get written by default,
2085   ; but we also want the docoder/disassembler to allow the values '1', '2' and
2086   ; '3'.
2087   (values keyword "" (("" 0) ("" 1) ("" 2) ("" 3)))
2088 )
2089 \f
2090 ; Instruction Operands.
2091 ; These entries provide a layer between the assembler and the raw hardware
2092 ; description, and are used to refer to hardware elements in the semantic
2093 ; code.  Usually there's a bit of over-specification, but in more complicated
2094 ; instruction sets there isn't.
2095
2096 ; FRV specific operand attributes:
2097
2098 (define-attr
2099   (for operand)
2100   (type boolean)
2101   (name HASH-PREFIX)
2102   (comment "immediates have an optional '#' prefix")
2103 )
2104
2105 ; ??? Convention says this should be o-sr, but then the insn definitions
2106 ; should refer to o-sr which is clumsy.  The "o-" could be implicit, but
2107 ; then it should be implicit for all the symbols here, but then there would
2108 ; be confusion between (f-)simm8 and (h-)simm8.
2109 ; So for now the rule is exactly as it appears here.
2110
2111 ; dnmop: define-normal-mode-operand: temporary, pending potential removal
2112 ; of modes from h/w.
2113 (define-pmacro (dnmop xname xcomment xattrs xtype xindex xmode)
2114   (define-operand
2115     (name xname)
2116     (comment xcomment)
2117     (.splice attrs (.unsplice xattrs))
2118     (type xtype)
2119     (index xindex)
2120     (mode xmode)
2121     )
2122 )
2123
2124 (dnop  pack "packing bit" () h-pack f-pack)
2125
2126 (dnmop GRi        "source register 1"      () h-gr        f-GRi  SI)
2127 (dnmop GRj        "source register 2"      () h-gr        f-GRj  SI)
2128 (dnmop GRk        "destination register"   () h-gr        f-GRk  SI)
2129 (dnmop GRkhi      "destination register"   () h-gr_hi     f-GRk  UHI)
2130 (dnmop GRklo      "destination register"   () h-gr_lo     f-GRk  UHI)
2131 (dnmop GRdoublek  "destination register"   () h-gr_double f-GRk  DI)
2132 (dnmop ACC40Si    "signed accumulator"     () h-acc40S    f-ACC40Si DI)
2133 (dnmop ACC40Ui    "unsigned accumulator"   () h-acc40U    f-ACC40Ui UDI)
2134 (dnmop ACC40Sk    "target accumulator"     () h-acc40S    f-ACC40Sk DI)
2135 (dnmop ACC40Uk    "target accumulator"     () h-acc40U    f-ACC40Uk UDI)
2136 (dnmop ACCGi      "source register"        () h-accg      f-ACCGi   UWI)
2137 (dnmop ACCGk      "target register"        () h-accg      f-ACCGk   UWI)
2138
2139 (dnmop CPRi       "source register"        ((MACH frv)) h-cpr        f-CPRi SI)
2140 (dnmop CPRj       "source register"        ((MACH frv)) h-cpr        f-CPRj SI)
2141 (dnmop CPRk       "destination register"   ((MACH frv)) h-cpr        f-CPRk SI)
2142 (dnmop CPRdoublek "destination register"   ((MACH frv)) h-cpr_double f-CPRk DI)
2143
2144 ; floating point operands
2145 (dnmop FRinti    "source register 1"      () h-fr_int        f-FRi SI)
2146 (dnmop FRintj    "source register 2"      () h-fr_int        f-FRj SI)
2147 (dnmop FRintk    "target register"        () h-fr_int        f-FRk SI)
2148 (dnmop FRi       "source register 1"      () h-fr        f-FRi SF)
2149 (dnmop FRj       "source register 2"      () h-fr        f-FRj SF)
2150 (dnmop FRk       "destination register"   () h-fr        f-FRk SF)
2151 (dnmop FRkhi     "destination register"   () h-fr_hi     f-FRk UHI)
2152 (dnmop FRklo     "destination register"   () h-fr_lo     f-FRk UHI)
2153 (dnmop FRdoublei "source register 1"      () h-fr_double f-FRi DF)
2154 (dnmop FRdoublej "source register 2"      () h-fr_double f-FRj DF)
2155 (dnmop FRdoublek "target register"        () h-fr_double f-FRk DF)
2156
2157 (dnop CRi       "source register 1"       () h-cccr f-CRi)
2158 (dnop CRj       "source register 2"       () h-cccr f-CRj)
2159 (dnop CRj_int   "destination register"    () h-cccr f-CRj_int)
2160 (dnop CRj_float "destination register"    () h-cccr f-CRj_float)
2161 (dnop CRk       "destination register"    () h-cccr f-CRk)
2162 (dnop CCi       "condition   register"    () h-cccr f-CCi)
2163
2164 (dnop ICCi_1  "condition   register"      () h-iccr f-ICCi_1)
2165 (dnop ICCi_2  "condition   register"      () h-iccr f-ICCi_2)
2166 (dnop ICCi_3  "condition   register"      () h-iccr f-ICCi_3)
2167 (dnop FCCi_1  "condition   register"      () h-fccr f-FCCi_1)
2168 (dnop FCCi_2  "condition   register"      () h-fccr f-FCCi_2)
2169 (dnop FCCi_3  "condition   register"      () h-fccr f-FCCi_3)
2170 (dnop FCCk    "condition   register"      () h-fccr f-FCCk)
2171
2172 (dnop eir     "exception insn reg"        () h-uint f-eir)
2173 (dnop s10     "10 bit signed immediate"   (HASH-PREFIX) h-sint f-s10)
2174 (dnop u16     "16 bit unsigned immediate" (HASH-PREFIX) h-uint f-u16)
2175 (dnop s16     "16 bit signed   immediate" (HASH-PREFIX) h-sint f-s16)
2176 (dnop s6      "6  bit signed   immediate" (HASH-PREFIX) h-sint f-s6)
2177 (dnop s6_1    "6  bit signed   immediate" (HASH-PREFIX) h-sint f-s6_1)
2178 (dnop u6      "6  bit unsigned immediate" (HASH-PREFIX) h-uint f-u6)
2179 (dnop s5      "5  bit signed   immediate" (HASH-PREFIX) h-sint f-s5)
2180 (dnop cond    "conditional arithmetic"    (HASH-PREFIX) h-uint f-cond)
2181 (dnop ccond   "lr branch condition"       (HASH-PREFIX) h-uint f-ccond)
2182 (dnop hint    "2 bit branch predictor"    (HASH-PREFIX) h-uint f-hint)
2183 (dnop hint_taken "2 bit branch predictor"     () h-hint-taken     f-hint)
2184 (dnop hint_not_taken "2 bit branch predictor" () h-hint-not-taken f-hint)
2185
2186 (dnop LI      "link indicator"            () h-uint f-LI)
2187 (dnop lock    "cache lock indicator"      (HASH-PREFIX) h-uint f-lock)
2188 (dnop debug   "debug mode indicator"      (HASH-PREFIX) h-uint f-debug)
2189 (dnop A       "all accumulator indicator" (HASH-PREFIX) h-uint f-A)
2190 (dnop ae      "all entries indicator"     (HASH-PREFIX) h-uint f-ae)
2191
2192 (dnop label16  "18 bit pc relative address" () h-iaddr f-label16)
2193 (dnop label24  "26 bit pc relative address" () h-iaddr f-label24)
2194
2195 (define-operand
2196   (name d12)
2197   (comment "12 bit signed immediate")
2198   (attrs)
2199   (type h-sint)
2200   (index f-d12)
2201   (handlers (parse "d12"))
2202 )
2203
2204 (define-operand
2205   (name s12)
2206   (comment "12 bit signed immediate")
2207   (attrs HASH-PREFIX)
2208   (type h-sint)
2209   (index f-d12)
2210   (handlers (parse "s12"))
2211 )
2212
2213 (define-operand
2214   (name u12)
2215   (comment "12 bit signed immediate")
2216   (attrs HASH-PREFIX)
2217   (type h-sint)
2218   (index f-u12)
2219   (handlers (parse "u12"))
2220 )
2221
2222 (define-operand 
2223   (name spr)
2224   (comment "special purpose register")
2225   (attrs)
2226   (type  h-spr)
2227   (index f-spr)
2228   (handlers (parse "spr") (print "spr"))
2229 )
2230
2231 (define-operand
2232   (name ulo16)
2233   (comment "16 bit unsigned immediate, for #lo()")
2234   (attrs)
2235   (type h-uint)
2236   (index f-u16)
2237   (handlers (parse "ulo16") (print "lo"))
2238 )
2239
2240 (define-operand
2241   (name slo16)
2242   (comment "16 bit unsigned immediate, for #lo()")
2243   (attrs)
2244   (type h-sint)
2245   (index f-s16)
2246   (handlers (parse "uslo16") (print "lo"))
2247 )
2248
2249 (define-operand
2250   (name uhi16)
2251   (comment "16 bit unsigned immediate, for #hi()")
2252   (attrs)
2253   (type h-uint)
2254   (index f-u16)
2255   (handlers (parse "uhi16") (print "hi"))
2256 )
2257
2258 ; operands representing hardware
2259 ;
2260 (dnop psr_esr "PSR.ESR bit" (SEM-ONLY) h-psr_esr f-nil)
2261 (dnop psr_s   "PSR.S   bit" (SEM-ONLY) h-psr_s   f-nil)
2262 (dnop psr_ps  "PSR.PS  bit" (SEM-ONLY) h-psr_ps  f-nil)
2263 (dnop psr_et  "PSR.ET  bit" (SEM-ONLY) h-psr_et  f-nil)
2264
2265 (dnop bpsr_bs  "BPSR.BS  bit" (SEM-ONLY) h-bpsr_bs  f-nil)
2266 (dnop bpsr_bet "BPSR.BET bit" (SEM-ONLY) h-bpsr_bet f-nil)
2267
2268 (dnop tbr_tba "TBR.TBA" (SEM-ONLY) h-tbr_tba f-nil)
2269 (dnop tbr_tt  "TBR.TT"  (SEM-ONLY) h-tbr_tt  f-nil)
2270
2271 ; Null operands
2272 ;
2273 (define-pmacro (ICCi_1-null)  (f-ICCi_1-null 0))
2274 (define-pmacro (ICCi_2-null)  (f-ICCi_2-null 0))
2275 (define-pmacro (ICCi_3-null)  (f-ICCi_3-null 0))
2276 (define-pmacro (FCCi_1-null)  (f-FCCi_1-null 0))
2277 (define-pmacro (FCCi_2-null)  (f-FCCi_2-null 0))
2278 (define-pmacro (FCCi_3-null)  (f-FCCi_3-null 0))
2279 (define-pmacro (rs-null)      (f-rs-null     0))
2280 (define-pmacro (GRi-null)     (f-GRi-null    0))
2281 (define-pmacro (GRj-null)     (f-GRj-null    0))
2282 (define-pmacro (GRk-null)     (f-GRk-null    0))
2283 (define-pmacro (FRi-null)     (f-FRi-null    0))
2284 (define-pmacro (FRj-null)     (f-FRj-null    0))
2285 (define-pmacro (ACCj-null)    (f-ACCj-null   0))
2286 (define-pmacro (rd-null)      (f-rd-null     0))
2287 (define-pmacro (cond-null)    (f-cond-null   0))
2288 (define-pmacro (ccond-null)   (f-ccond-null  0))
2289 (define-pmacro (s12-null)     (f-s12-null    0))
2290 (define-pmacro (label16-null) (f-label16-null 0))
2291 (define-pmacro (misc-null-1)  (f-misc-null-1 0))
2292 (define-pmacro (misc-null-2)  (f-misc-null-2 0))
2293 (define-pmacro (misc-null-3)  (f-misc-null-3 0))
2294 (define-pmacro (misc-null-4)  (f-misc-null-4 0))
2295 (define-pmacro (misc-null-5)  (f-misc-null-5 0))
2296 (define-pmacro (misc-null-6)  (f-misc-null-6 0))
2297 (define-pmacro (misc-null-7)  (f-misc-null-7 0))
2298 (define-pmacro (misc-null-8)  (f-misc-null-8 0))
2299 (define-pmacro (misc-null-9)  (f-misc-null-9 0))
2300 (define-pmacro (misc-null-10) (f-misc-null-10 0))
2301 (define-pmacro (misc-null-11) (f-misc-null-11 0))
2302
2303 (define-pmacro (LI-on)       (f-LI-on  1))
2304 (define-pmacro (LI-off)      (f-LI-off 0))
2305 \f
2306 ; Instruction definitions.
2307 ;
2308 ; Notes:
2309 ; - dni is short for "define-normal-instruction"
2310 ; - Macros are used to represent each insn format. These should be used as much
2311 ;   as possible unless an insn has exceptional behaviour
2312 ;
2313
2314 ; Commonly used Macros
2315 ;
2316 ; Specific registers
2317 ;
2318
2319 ; Integer condition code manipulation
2320 ;
2321 (define-pmacro (set-z-and-n icc x)
2322   (if (eq x 0)
2323       (set icc (or (and icc #x7) #x4))
2324       (if (lt x 0)
2325           (set icc (or (and icc #xb) #x8))
2326           (set icc (and icc #x3))))
2327 )
2328
2329 (define-pmacro (set-n icc val)
2330   (if (eq val 0)
2331       (set icc (and icc #x7))
2332       (set icc (or  icc #x8)))
2333 )
2334
2335 (define-pmacro (set-z icc val)
2336   (if (eq val 0)
2337       (set icc (and icc #xb))
2338       (set icc (or  icc #x4)))
2339 )
2340
2341 (define-pmacro (set-v icc val)
2342   (if (eq val 0)
2343       (set icc (and icc #xd))
2344       (set icc (or  icc #x2)))
2345 )
2346
2347 (define-pmacro (set-c icc val)
2348   (if (eq val 0)
2349       (set icc (and icc #xe))
2350       (set icc (or  icc #x1)))
2351 )
2352
2353 (define-pmacro (nbit icc)
2354   (trunc BI (srl (and icc #x8) 3))
2355 )
2356
2357 (define-pmacro (zbit icc)
2358   (trunc BI (srl (and icc #x4) 2))
2359 )
2360
2361 (define-pmacro (vbit icc)
2362   (trunc BI (srl (and icc #x2) 1))
2363 )
2364
2365 (define-pmacro (cbit icc)
2366   (trunc BI (and icc #x1))
2367 )
2368
2369 (define-pmacro (ebit icc)
2370   (trunc BI (srl (and icc #x8) 3))
2371 )
2372
2373 (define-pmacro (lbit icc)
2374   (trunc BI (srl (and icc #x4) 2))
2375 )
2376
2377 (define-pmacro (gbit icc)
2378   (trunc BI (srl (and icc #x2) 1))
2379 )
2380
2381 (define-pmacro (ubit icc)
2382   (trunc BI (and icc #x1))
2383 )
2384
2385 ; FRV specific insn attributes:
2386 ;
2387
2388 ; Format: INT, Logic, Shift r-r
2389 ;
2390 (define-pmacro (int-logic-r-r name operation op ope comment)
2391   (dni name
2392        (comment)
2393        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2394        (.str name "$pack $GRi,$GRj,$GRk")
2395        (+ pack GRk op GRi (ICCi_1-null) ope GRj)
2396        (set GRk (operation GRi GRj))
2397        ((fr400 (unit u-integer))
2398         (fr500 (unit u-integer)))
2399   )
2400 )
2401
2402 (int-logic-r-r add  add   OP_00 OPE2_00 "add reg/reg")
2403 (int-logic-r-r sub  sub   OP_00 OPE2_04 "sub reg/reg")
2404 (int-logic-r-r and  and   OP_01 OPE2_00 "and reg/reg")
2405 (int-logic-r-r or   or    OP_01 OPE2_02 "or  reg/reg")
2406 (int-logic-r-r xor  xor   OP_01 OPE2_04 "xor reg/reg")
2407
2408 (dni not
2409      ("not")
2410      ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2411      ("not$pack $GRj,$GRk")
2412      (+ pack GRk OP_01 (rs-null) (ICCi_1-null) OPE2_06 GRj)
2413      (set GRk (inv GRj))
2414      ((fr400 (unit u-integer))
2415       (fr500 (unit u-integer)))
2416 )
2417
2418 (dni sdiv
2419      "signed division"
2420      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2421      "sdiv$pack $GRi,$GRj,$GRk"
2422      (+ pack GRk OP_00 GRi (ICCi_1-null) OPE2_0E GRj)
2423      (sequence ()
2424                (c-call VOID "@cpu@_signed_integer_divide"
2425                        GRi GRj (index-of GRk) 0)
2426                (clobber GRk))
2427      ((fr400 (unit u-idiv))
2428       (fr500 (unit u-idiv)))
2429 )
2430
2431 (dni nsdiv
2432      "non excepting signed division"
2433      ((UNIT MULT-DIV) (FR500-MAJOR I-1) NON-EXCEPTING
2434       (MACH simple,tomcat,fr500,frv))
2435      "nsdiv$pack $GRi,$GRj,$GRk"
2436      (+ pack GRk OP_01 GRi (ICCi_1-null) OPE2_0E GRj)
2437      (sequence ()
2438                (c-call VOID "@cpu@_signed_integer_divide"
2439                        GRi GRj (index-of GRk) 1)
2440                (clobber GRk))
2441      ((fr400 (unit u-idiv))
2442       (fr500 (unit u-idiv)))
2443 )
2444
2445 (dni udiv
2446      "unsigned division reg/reg"
2447      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2448      "udiv$pack $GRi,$GRj,$GRk"
2449      (+ pack GRk OP_00 GRi (ICCi_1-null) OPE2_0F GRj)
2450      (sequence ()
2451                (c-call VOID "@cpu@_unsigned_integer_divide"
2452                        GRi GRj (index-of GRk) 0)
2453                (clobber GRk))
2454      ((fr400 (unit u-idiv))
2455       (fr500 (unit u-idiv)))
2456 )
2457
2458 (dni nudiv
2459      "non excepting unsigned division"
2460      ((UNIT MULT-DIV) (FR500-MAJOR I-1) NON-EXCEPTING
2461       (MACH simple,tomcat,fr500,frv))
2462      "nudiv$pack $GRi,$GRj,$GRk"
2463      (+ pack GRk OP_01 GRi (ICCi_1-null) OPE2_0F GRj)
2464      (sequence ()
2465                (c-call VOID "@cpu@_unsigned_integer_divide"
2466                        GRi GRj (index-of GRk) 1)
2467                (clobber GRk))
2468      ((fr400 (unit u-idiv))
2469       (fr500 (unit u-idiv)))
2470 )
2471
2472 ; Multiplication
2473 ;
2474 (define-pmacro (multiply-r-r name signop op ope comment)
2475   (dni name
2476        (comment)
2477        ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2478        (.str name "$pack $GRi,$GRj,$GRdoublek")
2479        (+ pack GRdoublek op GRi (ICCi_1-null) ope GRj) 
2480        (set GRdoublek (mul DI (signop DI GRi) (signop DI GRj)))
2481        ((fr400 (unit u-imul))
2482         (fr500 (unit u-imul)))
2483   )
2484 )
2485
2486 (multiply-r-r smul ext  OP_00 OPE2_08 "signed   multiply reg/reg")
2487 (multiply-r-r umul zext OP_00 OPE2_0A "unsigned multiply reg/reg")
2488
2489 (define-pmacro (int-shift-r-r name op ope comment)
2490   (dni name
2491        (comment)
2492        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2493        (.str name "$pack $GRi,$GRj,$GRk")
2494        (+ pack GRk op GRi (ICCi_1-null) ope GRj)
2495        (set GRk (name GRi (and GRj #x1f)))
2496        ((fr400 (unit u-integer))
2497         (fr500 (unit u-integer)))
2498   )
2499 )
2500
2501 (int-shift-r-r sll OP_01 OPE2_08 "shift left  logical reg/reg")
2502 (int-shift-r-r srl OP_01 OPE2_0A "shift right logical reg/reg")
2503 (int-shift-r-r sra OP_01 OPE2_0C "shift right arith   reg/reg")
2504
2505 (define-pmacro (scan-semantics arg1 arg2 targ)
2506   (sequence ((WI tmp1) (WI tmp2))
2507             (set tmp1 arg1)
2508             (set tmp2 (sra arg2 1))
2509             (set targ (c-call WI "@cpu@_scan_result" (xor tmp1 tmp2))))
2510 )
2511
2512 (dni scan
2513      "scan"
2514      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2515      "scan$pack $GRi,$GRj,$GRk"
2516      (+ pack GRk OP_0B GRi (ICCi_1-null) OPE2_00 GRj)
2517      (scan-semantics GRi GRj GRk)
2518      ((fr400 (unit u-integer))
2519       (fr500 (unit u-integer)))
2520 )
2521
2522 ; Format: conditional INT, Logic, Shift r-r
2523 ;
2524 (define-pmacro (conditional-int-logic name operation op ope comment)
2525   (dni name
2526        (comment)
2527        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2528        (.str name "$pack $GRi,$GRj,$GRk,$CCi,$cond")
2529        (+ pack GRk op GRi CCi cond ope GRj)
2530        (if (eq CCi (or cond 2))
2531            (set GRk (operation GRi GRj)))
2532        ((fr400 (unit u-integer))
2533         (fr500 (unit u-integer)))
2534   )
2535 )
2536
2537 (conditional-int-logic cadd  add  OP_58 OPE4_0 "conditional add")
2538 (conditional-int-logic csub  sub  OP_58 OPE4_1 "conditional sub")
2539 (conditional-int-logic cand  and  OP_5A OPE4_0 "conditional and")
2540 (conditional-int-logic cor   or   OP_5A OPE4_1 "conditional or")
2541 (conditional-int-logic cxor  xor  OP_5A OPE4_2 "conditional xor")
2542
2543 (dni cnot
2544      "conditional not"
2545      ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2546      "cnot$pack $GRj,$GRk,$CCi,$cond"
2547      (+ pack GRk OP_5A (rs-null) CCi cond OPE4_3 GRj)
2548      (if (eq CCi (or cond 2))
2549          (set GRk (inv GRj)))
2550      ((fr400 (unit u-integer))
2551       (fr500 (unit u-integer)))
2552 )
2553
2554 (dni csmul
2555      "conditional signed multiply"
2556      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2557      "csmul$pack $GRi,$GRj,$GRdoublek,$CCi,$cond"
2558      (+ pack GRdoublek OP_58 GRi CCi cond OPE4_2 GRj)
2559      (if (eq CCi (or cond 2))
2560          (set GRdoublek (mul DI (ext DI GRi) (ext DI GRj))))
2561      ((fr400 (unit u-imul))
2562       (fr500 (unit u-imul)))
2563 )
2564
2565 (dni csdiv
2566      "conditional signed division"
2567      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2568      "csdiv$pack $GRi,$GRj,$GRk,$CCi,$cond"
2569      (+ pack GRk OP_58 GRi CCi cond OPE4_3 GRj)
2570      (if (eq CCi (or cond 2))
2571          (sequence ()
2572                    (c-call VOID "@cpu@_signed_integer_divide"
2573                            GRi GRj (index-of GRk) 0)
2574                    (clobber GRk)))
2575      ((fr400 (unit u-idiv))
2576       (fr500 (unit u-idiv)))
2577 )
2578
2579 (dni cudiv
2580      "conditional unsigned division"
2581      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2582      "cudiv$pack $GRi,$GRj,$GRk,$CCi,$cond"
2583      (+ pack GRk OP_59 GRi CCi cond OPE4_3 GRj)
2584      (if (eq CCi (or cond 2))
2585          (sequence ()
2586                    (c-call VOID "@cpu@_unsigned_integer_divide"
2587                            GRi GRj (index-of GRk) 0)
2588                    (clobber GRk)))
2589      ((fr400 (unit u-idiv))
2590       (fr500 (unit u-idiv)))
2591 )
2592
2593 (define-pmacro (conditional-shift name operation op ope comment)
2594   (dni name
2595        (comment)
2596        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2597        (.str name "$pack $GRi,$GRj,$GRk,$CCi,$cond")
2598        (+ pack GRk op GRi CCi cond ope GRj)
2599        (if (eq CCi (or cond 2))
2600            (set GRk (operation GRi (and GRj #x1f))))
2601        ((fr400 (unit u-integer))
2602         (fr500 (unit u-integer)))
2603   )
2604 )
2605
2606 (conditional-shift csll sll OP_5C OPE4_0 "conditional shift left  logical")
2607 (conditional-shift csrl srl OP_5C OPE4_1 "conditional shift right logical")
2608 (conditional-shift csra sra OP_5C OPE4_2 "conditional shift right arith")
2609
2610 (dni cscan
2611      "conditional scan"
2612      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2613      "cscan$pack $GRi,$GRj,$GRk,$CCi,$cond"
2614      (+ pack GRk OP_65 GRi CCi cond OPE4_3 GRj)
2615      (if (eq CCi (or cond 2))
2616          (scan-semantics GRi GRj GRk))
2617      ((fr400 (unit u-integer))
2618       (fr500 (unit u-integer)))
2619 )
2620
2621 ; Format: INT, Logic, Shift, cc r-r
2622 ;
2623 (define-pmacro (int-arith-cc-semantics operation icc)
2624   (sequence ((BI tmp) (QI cc) (SI result))
2625             (set cc icc)
2626             (set tmp ((.sym operation -oflag) GRi GRj (const 0)))
2627             (set-v cc tmp)
2628             (set tmp ((.sym operation -cflag) GRi GRj (const 0)))
2629             (set-c cc tmp)
2630             (set result (operation GRi GRj))
2631             (set-z-and-n cc result)
2632             (set GRk result)
2633             (set icc cc))
2634 )
2635
2636 (define-pmacro (int-arith-cc-r-r name operation op ope comment)
2637   (dni name
2638        (comment)
2639        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2640        (.str name "$pack $GRi,$GRj,$GRk,$ICCi_1")
2641        (+ pack GRk op GRi ICCi_1 ope GRj)
2642        (int-arith-cc-semantics operation ICCi_1)
2643        ((fr400 (unit u-integer))
2644         (fr500 (unit u-integer)))
2645   )
2646 )
2647
2648 (int-arith-cc-r-r addcc add OP_00 OPE2_01 "add reg/reg, set icc")
2649 (int-arith-cc-r-r subcc sub OP_00 OPE2_05 "sub reg/reg, set icc")
2650
2651 (define-pmacro (int-logic-cc-semantics op icc)
2652   (sequence ((SI tmp))
2653             (set tmp (op GRi GRj))
2654             (set GRk tmp)
2655             (set-z-and-n icc tmp))
2656 )
2657
2658 (define-pmacro (int-logic-cc-r-r name op ope comment)
2659   (dni (.sym name cc)
2660        (comment)
2661        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2662        (.str (.sym name cc) "$pack $GRi,$GRj,$GRk,$ICCi_1")
2663        (+ pack GRk op GRi ICCi_1 ope GRj)
2664        (int-logic-cc-semantics name ICCi_1)
2665        ((fr400 (unit u-integer))
2666         (fr500 (unit u-integer)))
2667   )
2668 )
2669
2670 (int-logic-cc-r-r and OP_01 OPE2_01 "and reg/reg, set icc")
2671 (int-logic-cc-r-r or  OP_01 OPE2_03 "or  reg/reg, set icc")
2672 (int-logic-cc-r-r xor OP_01 OPE2_05 "xor reg/reg, set icc")
2673
2674 (define-pmacro (int-shift-cc-semantics op l-r icc)
2675   (sequence ((WI shift) (SI tmp) (QI cc))
2676             (set shift (and GRj #x1f))
2677             (set cc (c-call QI (.str "@cpu@_set_icc_for_shift_" l-r)
2678                             GRi shift icc))
2679             (set tmp (op GRi shift))
2680             (set GRk tmp)
2681             (set-z-and-n cc tmp)
2682             (set icc cc))
2683 )
2684
2685 (define-pmacro (int-shift-cc-r-r name l-r op ope comment)
2686   (dni (.sym name cc)
2687        (comment)
2688        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2689        (.str (.sym name cc) "$pack $GRi,$GRj,$GRk,$ICCi_1")
2690        (+ pack GRk op GRi ICCi_1 ope GRj)
2691        (int-shift-cc-semantics name l-r ICCi_1)
2692        ((fr400 (unit u-integer))
2693         (fr500 (unit u-integer)))
2694   )
2695 )
2696
2697 (int-shift-cc-r-r sll left  OP_01 OPE2_09 "shift left  logical reg/reg,set icc")
2698 (int-shift-cc-r-r srl right OP_01 OPE2_0B "shift right logical reg/reg,set icc")
2699 (int-shift-cc-r-r sra right OP_01 OPE2_0D "shift right arith   reg/reg,set icc")
2700
2701 (define-pmacro (multiply-cc-semantics signop arg1 arg2 targ icc)
2702   (sequence ((DI tmp) (QI cc))
2703             (set cc icc)
2704             (set tmp (mul DI (signop DI arg1) (signop DI arg2)))
2705             (set-n cc (srl DI tmp 63))
2706             (set-z cc (eq tmp 0))
2707             (set targ tmp)
2708             (set icc cc))
2709 )
2710
2711 (define-pmacro (multiply-cc-r-r name signop op ope comment)
2712   (dni name
2713        (comment)
2714        ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2715        (.str name "$pack $GRi,$GRj,$GRdoublek,$ICCi_1")
2716        (+ pack GRdoublek op GRi ICCi_1 ope GRj)
2717        (multiply-cc-semantics signop GRi GRj GRdoublek ICCi_1)
2718        ((fr400 (unit u-imul))
2719         (fr500 (unit u-imul)))
2720   )
2721 )
2722
2723 (multiply-cc-r-r smulcc ext  OP_00 OPE2_09 "signed   multiply reg/reg")
2724 (multiply-cc-r-r umulcc zext OP_00 OPE2_0B "unsigned multiply reg/reg")
2725
2726
2727 ; Format: conditional INT, Logic, Shift, cc r-r
2728 ;
2729 (define-pmacro (conditional-int-arith-cc name operation op ope comment)
2730   (dni name
2731        (comment)
2732        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2733        (.str name "$pack $GRi,$GRj,$GRk,$CCi,$cond")
2734        (+ pack GRk op GRi CCi cond ope GRj)
2735        (if (eq CCi (or cond 2))
2736            (int-arith-cc-semantics operation
2737                                    (reg h-iccr (and (index-of CCi) 3))))
2738        ((fr400 (unit u-integer))
2739         (fr500 (unit u-integer)))
2740   )
2741 )
2742
2743 (conditional-int-arith-cc caddcc add OP_59 OPE4_0 "add, set icc")
2744 (conditional-int-arith-cc csubcc sub OP_59 OPE4_1 "sub, set icc")
2745
2746 (dni csmulcc
2747      "conditional signed multiply and set condition code"
2748      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2749      "csmulcc$pack $GRi,$GRj,$GRdoublek,$CCi,$cond"
2750      (+ pack GRdoublek OP_59 GRi CCi cond OPE4_2 GRj)
2751      (if (eq CCi (or cond 2))
2752          (multiply-cc-semantics ext GRi GRj GRdoublek
2753                                 (reg h-iccr (and (index-of CCi) 3))))
2754      ((fr400 (unit u-imul))
2755       (fr500 (unit u-imul)))
2756 )
2757
2758 (define-pmacro (conditional-int-logic-cc name operation op ope comment)
2759   (dni name
2760        (comment)
2761        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2762        (.str name "$pack $GRi,$GRj,$GRk,$CCi,$cond")
2763        (+ pack GRk op GRi CCi cond ope GRj)
2764        (if (eq CCi (or cond 2))
2765            (int-logic-cc-semantics operation
2766                                    (reg h-iccr (and (index-of CCi) 3))))
2767        ((fr400 (unit u-integer))
2768         (fr500 (unit u-integer)))
2769   )
2770 )
2771
2772 (conditional-int-logic-cc candcc and OP_5B OPE4_0 "conditional and, set icc")
2773 (conditional-int-logic-cc corcc  or  OP_5B OPE4_1 "conditional or , set icc")
2774 (conditional-int-logic-cc cxorcc xor OP_5B OPE4_2 "conditional xor, set icc")
2775
2776 (define-pmacro (conditional-int-shift-cc name l-r op ope comment)
2777   (dni (.sym c name cc)
2778        (comment)
2779        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
2780        (.str (.sym c name cc) "$pack $GRi,$GRj,$GRk,$CCi,$cond")
2781        (+ pack GRk op GRi CCi cond ope GRj)
2782        (if (eq CCi (or cond 2))
2783            (int-shift-cc-semantics name l-r
2784                                    (reg h-iccr (and (index-of CCi) 3))))
2785        ((fr400 (unit u-integer))
2786         (fr500 (unit u-integer)))
2787   )
2788 )
2789
2790 (conditional-int-shift-cc sll left  OP_5D OPE4_0 "shift left  logical, set icc")
2791 (conditional-int-shift-cc srl right OP_5D OPE4_1 "shift right logical, set icc")
2792 (conditional-int-shift-cc sra right OP_5D OPE4_2 "shift right arith  , set icc")
2793
2794 ; Add and subtract with carry
2795 ;
2796 (define-pmacro (int-arith-x-r-r name operation op ope comment)
2797   (dni name
2798        (comment)
2799        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2800        (.str name "$pack $GRi,$GRj,$GRk,$ICCi_1")
2801        (+ pack GRk op GRi ICCi_1 ope GRj)
2802        (set GRk ((.sym operation c) GRi GRj (cbit ICCi_1)))
2803        ((fr400 (unit u-integer))
2804         (fr500 (unit u-integer)))
2805   )
2806 )
2807
2808 (int-arith-x-r-r addx add OP_00 OPE2_02 "Add reg/reg, with carry")
2809 (int-arith-x-r-r subx sub OP_00 OPE2_06 "Sub reg/reg, with carry")
2810
2811 (define-pmacro (int-arith-x-cc-r-r name operation op ope comment)
2812   (dni name
2813        (comment)
2814        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2815        (.str name "$pack $GRi,$GRj,$GRk,$ICCi_1")
2816        (+ pack GRk op GRi ICCi_1 ope GRj)
2817        (sequence ((WI tmp) (QI cc))
2818                  (set cc ICCi_1)
2819                  (set tmp ((.sym operation c) GRi GRj (cbit cc)))
2820                  (set-v cc ((.sym operation -oflag) GRi GRj (cbit cc)))
2821                  (set-c cc ((.sym operation -cflag) GRi GRj (cbit cc)))
2822                  (set-z-and-n cc tmp)
2823                  (set GRk tmp)
2824                  (set ICCi_1 cc))
2825        ((fr400 (unit u-integer))
2826         (fr500 (unit u-integer)))
2827   )
2828 )
2829
2830 (int-arith-x-cc-r-r addxcc add OP_00 OPE2_03 "Add reg/reg, use/set carry")
2831 (int-arith-x-cc-r-r subxcc sub OP_00 OPE2_07 "Sub reg/reg, use/set carry")
2832
2833 ; Format: INT, Logic, Shift r-simm
2834 ;
2835 (define-pmacro (int-logic-r-simm name operation op comment)
2836   (dni name
2837        (comment)
2838        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2839        (.str name "$pack $GRi,$s12,$GRk")
2840        (+ pack GRk op GRi s12)
2841        (set GRk (operation GRi s12))
2842        ((fr400 (unit u-integer))
2843         (fr500 (unit u-integer)))
2844   )
2845 )
2846
2847 (int-logic-r-simm addi  add   OP_10 "add reg/immed")
2848 (int-logic-r-simm subi  sub   OP_14 "sub reg/immed")
2849 (int-logic-r-simm andi  and   OP_20 "and reg/immed")
2850 (int-logic-r-simm ori   or    OP_22 "or  reg/immed")
2851 (int-logic-r-simm xori  xor   OP_24 "xor reg/immed")
2852
2853 (dni sdivi
2854      "signed division reg/immed"
2855      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2856      "sdivi$pack $GRi,$s12,$GRk"
2857      (+ pack GRk OP_1E GRi s12)
2858      (sequence ()
2859                (c-call VOID "@cpu@_signed_integer_divide"
2860                        GRi s12 (index-of GRk) 0)
2861                (clobber GRk))
2862      ((fr400 (unit u-idiv))
2863       (fr500 (unit u-idiv)))
2864 )
2865
2866 (dni nsdivi
2867      "non excepting signed division reg/immed"
2868      ((UNIT MULT-DIV) (FR500-MAJOR I-1) NON-EXCEPTING
2869       (MACH simple,tomcat,fr500,frv))
2870      "nsdivi$pack $GRi,$s12,$GRk"
2871      (+ pack GRk OP_2E GRi s12)
2872      (sequence ()
2873                (c-call VOID "@cpu@_signed_integer_divide"
2874                        GRi s12 (index-of GRk) 1)
2875                (clobber GRk))
2876      ((fr400 (unit u-idiv))
2877       (fr500 (unit u-idiv)))
2878 )
2879
2880 (dni udivi
2881      "unsigned division reg/immed"
2882      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2883      "udivi$pack $GRi,$s12,$GRk"
2884      (+ pack GRk OP_1F GRi s12)
2885      (sequence ()
2886                (c-call VOID "@cpu@_unsigned_integer_divide"
2887                        GRi s12 (index-of GRk) 0)
2888                (clobber GRk))
2889      ((fr400 (unit u-idiv))
2890       (fr500 (unit u-idiv)))
2891 )
2892
2893 (dni nudivi
2894      "non excepting unsigned division reg/immed"
2895      ((UNIT MULT-DIV) (FR500-MAJOR I-1) NON-EXCEPTING
2896       (MACH simple,tomcat,fr500,frv))
2897      "nudivi$pack $GRi,$s12,$GRk"
2898      (+ pack GRk OP_2F GRi s12)
2899      (sequence ()
2900                (c-call VOID "@cpu@_unsigned_integer_divide"
2901                        GRi s12 (index-of GRk) 1)
2902                (clobber GRk))
2903      ((fr400 (unit u-idiv))
2904       (fr500 (unit u-idiv)))
2905 )
2906
2907 (define-pmacro (multiply-r-simm name signop op comment)
2908   (dni name
2909        (comment)
2910        ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2911        (.str name "$pack $GRi,$s12,$GRdoublek")
2912        (+ pack GRdoublek op GRi s12)
2913        (set GRdoublek (mul DI (signop DI GRi) (signop DI s12)))
2914        ((fr400 (unit u-imul))
2915         (fr500 (unit u-imul)))
2916   )
2917 )
2918
2919 (multiply-r-simm smuli ext  OP_18 "signed   multiply reg/immed")
2920 (multiply-r-simm umuli zext OP_1A "unsigned multiply reg/immed")
2921
2922 (define-pmacro (int-shift-r-simm name op comment)
2923   (dni (.sym name i)
2924        (comment)
2925        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2926        (.str (.sym name i) "$pack $GRi,$s12,$GRk")
2927        (+ pack GRk op GRi s12)
2928        (set GRk (name GRi (and s12 #x1f)))
2929        ((fr400 (unit u-integer))
2930         (fr500 (unit u-integer)))
2931   )
2932 )
2933
2934 (int-shift-r-simm sll OP_28 "shift left  logical reg/immed")
2935 (int-shift-r-simm srl OP_2A "shift right logical reg/immed")
2936 (int-shift-r-simm sra OP_2C "shift right arith   reg/immed")
2937
2938 (dni scani
2939      "scan immediate"
2940      ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2941      "scani$pack $GRi,$s12,$GRk"
2942      (+ pack GRk OP_47 GRi s12)
2943      (scan-semantics GRi s12 GRk)
2944      ((fr400 (unit u-integer))
2945       (fr500 (unit u-integer)))
2946 )
2947
2948 ; Format: INT, Logic, Shift cc r-simm
2949 ;
2950 (define-pmacro (int-arith-cc-r-simm name operation op comment)
2951   (dni name
2952        (comment)
2953        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2954        (.str name "$pack $GRi,$s10,$GRk,$ICCi_1")
2955        (+ pack GRk op GRi ICCi_1 s10)
2956        (sequence ((BI tmp) (QI cc) (SI result))
2957                  (set cc ICCi_1)
2958                  (set tmp ((.sym operation -oflag) GRi s10 (const 0)))
2959                  (set-v cc tmp)
2960                  (set tmp ((.sym operation -cflag) GRi s10 (const 0)))
2961                  (set-c cc tmp)
2962                  (set result (operation GRi s10))
2963                  (set-z-and-n cc result)
2964                  (set GRk result)
2965                  (set ICCi_1 cc))
2966        ((fr400 (unit u-integer))
2967         (fr500 (unit u-integer)))
2968   )
2969 )
2970
2971 (int-arith-cc-r-simm addicc add OP_11 "add reg/immed, set icc")
2972 (int-arith-cc-r-simm subicc sub OP_15 "sub reg/immed, set icc")
2973
2974 (define-pmacro (int-logic-cc-r-simm name op comment)
2975   (dni (.sym name icc)
2976        (comment)
2977        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2978        (.str (.sym name icc) "$pack $GRi,$s10,$GRk,$ICCi_1")
2979        (+ pack GRk op GRi ICCi_1 s10)
2980        (sequence ((SI tmp))
2981                  (set tmp (name GRi s10))
2982                  (set GRk tmp)
2983                  (set-z-and-n ICCi_1 tmp))
2984        ((fr400 (unit u-integer))
2985         (fr500 (unit u-integer)))
2986   )
2987 )
2988
2989 (int-logic-cc-r-simm and  OP_21 "and reg/immed, set icc")
2990 (int-logic-cc-r-simm or   OP_23 "or  reg/immed, set icc")
2991 (int-logic-cc-r-simm xor  OP_25 "xor reg/immed, set icc")
2992
2993 (define-pmacro (multiply-cc-r-simm name signop op comment)
2994   (dni name
2995        (comment)
2996        ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
2997        (.str name "$pack $GRi,$s10,$GRdoublek,$ICCi_1")
2998        (+ pack GRdoublek op GRi ICCi_1 s10)
2999        (multiply-cc-semantics signop GRi s10 GRdoublek ICCi_1)
3000        ((fr400 (unit u-imul))
3001         (fr500 (unit u-imul)))
3002   )
3003 )
3004
3005 (multiply-cc-r-simm smulicc ext  OP_19 "signed   multiply reg/immed")
3006 (multiply-cc-r-simm umulicc zext OP_1B "unsigned multiply reg/immed")
3007
3008 (define-pmacro (int-shift-cc-r-simm name l-r op comment)
3009   (dni (.sym name icc)
3010        (comment)
3011        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
3012        (.str (.sym name icc) "$pack $GRi,$s10,$GRk,$ICCi_1")
3013        (+ pack GRk op GRi ICCi_1 s10)
3014        (sequence ((WI shift) (SI tmp) (QI cc))
3015                  (set shift (and s10 #x1f))
3016                  (set cc (c-call QI (.str "@cpu@_set_icc_for_shift_" l-r)
3017                                  GRi shift ICCi_1))
3018                  (set tmp (name GRi shift))
3019                  (set GRk tmp)
3020                  (set-z-and-n cc tmp)
3021                  (set ICCi_1 cc))
3022        ((fr400 (unit u-integer))
3023         (fr500 (unit u-integer)))
3024   )
3025 )
3026
3027 (int-shift-cc-r-simm sll left  OP_29 "shift left  logical reg/immed, set icc")
3028 (int-shift-cc-r-simm srl right OP_2B "shift right logical reg/immed, set icc")
3029 (int-shift-cc-r-simm sra right OP_2D "shift right arith   reg/immed, set icc")
3030
3031 (define-pmacro (int-arith-x-r-simm name operation op comment)
3032   (dni name
3033        (comment)
3034        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
3035        (.str name "$pack $GRi,$s10,$GRk,$ICCi_1")
3036        (+ pack GRk op GRi ICCi_1 s10)
3037        (set GRk ((.sym operation c) GRi s10 (cbit ICCi_1)))
3038        ((fr400 (unit u-integer))
3039         (fr500 (unit u-integer)))
3040   )
3041 )
3042
3043 (int-arith-x-r-simm addxi add OP_12 "Add reg/immed, with carry")
3044 (int-arith-x-r-simm subxi sub OP_16 "Sub reg/immed, with carry")
3045
3046 (define-pmacro (int-arith-x-cc-r-simm name operation op comment)
3047   (dni name
3048        (comment)
3049        ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
3050        (.str name "$pack $GRi,$s10,$GRk,$ICCi_1")
3051        (+ pack GRk op GRi ICCi_1 s10)
3052        (sequence ((WI tmp) (QI cc))
3053                  (set cc ICCi_1)
3054                  (set tmp ((.sym operation c) GRi s10 (cbit cc)))
3055                  (set-v cc ((.sym operation -oflag) GRi s10 (cbit cc)))
3056                  (set-c cc ((.sym operation -cflag) GRi s10 (cbit cc)))
3057                  (set-z-and-n cc tmp)
3058                  (set GRk tmp)
3059                  (set ICCi_1 cc))
3060        ((fr400 (unit u-integer))
3061         (fr500 (unit u-integer)))
3062   )
3063 )
3064
3065 (int-arith-x-cc-r-simm addxicc add OP_13 "Add reg/immed, with carry")
3066 (int-arith-x-cc-r-simm subxicc sub OP_17 "Sub reg/immed, with carry")
3067
3068 ; Byte compare insns
3069
3070 (dni cmpb
3071      "Compare bytes"
3072      ((UNIT I01) (FR400-MAJOR I-1) (MACH fr400))
3073      "cmpb$pack $GRi,$GRj,$ICCi_1"
3074      (+ pack (GRk-null) OP_00 GRi ICCi_1 OPE2_0C GRj)
3075      (sequence ((QI cc))
3076                (set-n cc (eq (and GRi #xff000000) (and GRj #xff000000)))
3077                (set-z cc (eq (and GRi #x00ff0000) (and GRj #x00ff0000)))
3078                (set-v cc (eq (and GRi #x0000ff00) (and GRj #x0000ff00)))
3079                (set-c cc (eq (and GRi #x000000ff) (and GRj #x000000ff)))
3080                (set ICCi_1 cc))
3081      ((fr400 (unit u-integer)))
3082 )
3083
3084 (dni cmpba
3085      "OR of Compare bytes"
3086      ((UNIT I01) (FR400-MAJOR I-1) (MACH fr400))
3087      "cmpba$pack $GRi,$GRj,$ICCi_1"
3088      (+ pack (GRk-null) OP_00 GRi ICCi_1 OPE2_0D GRj)
3089      (sequence ((QI cc))
3090                (set cc 0)
3091                (set-c cc
3092                       (orif (eq (and GRi #xff000000) (and GRj #xff000000))
3093                             (orif (eq (and GRi #x00ff0000) (and GRj #x00ff0000))
3094                                   (orif (eq (and GRi #x0000ff00)
3095                                             (and GRj #x0000ff00))
3096                                          (eq (and GRi #x000000ff)
3097                                             (and GRj #x000000ff))))))
3098                (set ICCi_1 cc))
3099      ((fr400 (unit u-integer)))
3100 )
3101
3102 ; Format: Load immediate
3103 ;
3104 (dni setlo
3105      "set low order bits"
3106      ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
3107      "setlo$pack $ulo16,$GRklo"
3108      (+ pack GRk OP_3D (misc-null-4) u16)
3109      (set GRklo u16)
3110      ((fr400 (unit u-set-hilo))
3111       (fr500 (unit u-set-hilo)))
3112 )
3113
3114 (dni sethi
3115      "set high order bits"
3116      ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
3117      "sethi$pack $uhi16,$GRkhi"
3118      (+ pack GRkhi OP_3E (misc-null-4) u16)
3119      (set GRkhi u16)
3120      ((fr400 (unit u-set-hilo))
3121       (fr500 (unit u-set-hilo)))
3122 )
3123
3124 (dni setlos
3125      "set low order bits and extend sign"
3126      ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
3127      "setlos$pack $slo16,$GRk"
3128      (+ pack GRk OP_3F (misc-null-4) s16)
3129      (set GRk s16)
3130      ((fr400 (unit u-integer))
3131       (fr500 (unit u-integer)))
3132 )
3133
3134 (define-pmacro (load-gr-r name mode op ope comment)
3135   (dni name
3136        (comment)
3137        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2))
3138        (.str name "$pack @($GRi,$GRj),$GRk")
3139        (+ pack GRk op GRi ope GRj)
3140        (set GRk (c-call mode (.str "@cpu@_read_mem_" mode) pc (add GRi GRj)))
3141        ((fr400 (unit u-gr-load))
3142         (fr500 (unit u-gr-load)))
3143   )
3144 )
3145
3146 (load-gr-r ldsb   QI OP_02 OPE1_00 "Load   signed byte")
3147 (load-gr-r ldub  UQI OP_02 OPE1_01 "Load unsigned byte")
3148 (load-gr-r ldsh   HI OP_02 OPE1_02 "Load   signed half")
3149 (load-gr-r lduh  UHI OP_02 OPE1_03 "Load unsigned half")
3150 (load-gr-r ld     SI OP_02 OPE1_04 "Load          word")
3151
3152 (define-pmacro (load-fr-r name mode op ope comment)
3153   (dni name
3154        (comment)
3155        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) FR-ACCESS)
3156        (.str name "$pack @($GRi,$GRj),$FRintk")
3157        (+ pack FRintk op GRi ope GRj)
3158        (set FRintk (c-call mode (.str "@cpu@_read_mem_" mode) pc (add GRi GRj)))
3159        ((fr400 (unit u-fr-load))
3160         (fr500 (unit u-fr-load)))
3161   )
3162 )
3163
3164 (load-fr-r ldbf UQI OP_02 OPE1_08 "Load byte   float")
3165 (load-fr-r ldhf UHI OP_02 OPE1_09 "Load half   float")
3166 (load-fr-r ldf   SI OP_02 OPE1_0A "Load word   float")
3167
3168 (define-pmacro (load-cpr-r name mode op ope reg attr comment)
3169   (dni name
3170        (comment)
3171        ((UNIT LOAD) (FR500-MAJOR I-2) attr)
3172        (.str name "$pack @($GRi,$GRj),$" reg "k")
3173        (+ pack (.sym reg k) op GRi ope GRj)
3174        (set (.sym reg k)
3175             (c-call mode (.str "@cpu@_read_mem_" mode) pc (add GRi GRj)))
3176        ()
3177   )
3178 )
3179
3180 (load-cpr-r ldc SI OP_02 OPE1_0D CPR (MACH frv) "Load coprocessor word")
3181
3182 ; These correspond to enumerators in frv-sim.h
3183 (define-pmacro (ne-UQI-size) 0)
3184 (define-pmacro (ne-QI-size)  1)
3185 (define-pmacro (ne-UHI-size) 2)
3186 (define-pmacro (ne-HI-size)  3)
3187 (define-pmacro (ne-SI-size)  4)
3188 (define-pmacro (ne-DI-size)  5)
3189 (define-pmacro (ne-XI-size)  6)
3190
3191 (define-pmacro (ne-load-semantics base dispix targ idisp size is_float action)
3192   (sequence ((BI do_op))
3193             (set do_op
3194                  (c-call BI "@cpu@_check_non_excepting_load"
3195                           (index-of base) dispix (index-of targ)
3196                           idisp size is_float))
3197             (if do_op action))
3198 )
3199
3200 (define-pmacro (ne-load-gr-r name mode op ope size comment)
3201   (dni name
3202        (comment)
3203        ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING
3204         (MACH simple,tomcat,fr500,frv))
3205        (.str name "$pack @($GRi,$GRj),$GRk")
3206        (+ pack GRk op GRi ope GRj)
3207        (ne-load-semantics GRi (index-of GRj) GRk 0 size 0
3208                           (set GRk
3209                                (c-call mode (.str "@cpu@_read_mem_" mode)
3210                                        pc (add GRi GRj))))
3211        ((fr500 (unit u-gr-load)))
3212   )
3213 )
3214
3215 (ne-load-gr-r nldsb  QI OP_02 OPE1_20 (ne-QI-size)  "Load   signed byte")
3216 (ne-load-gr-r nldub UQI OP_02 OPE1_21 (ne-UQI-size) "Load unsigned byte")
3217 (ne-load-gr-r nldsh  HI OP_02 OPE1_22 (ne-HI-size)  "Load   signed half")
3218 (ne-load-gr-r nlduh UHI OP_02 OPE1_23 (ne-UHI-size) "Load unsigned half")
3219 (ne-load-gr-r nld    SI OP_02 OPE1_24 (ne-SI-size)  "Load          word")
3220
3221 (define-pmacro (ne-load-fr-r name mode op ope size comment)
3222   (dni name
3223        (comment)
3224        ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING FR-ACCESS
3225         (MACH simple,tomcat,fr500,frv))
3226        (.str name "$pack @($GRi,$GRj),$FRintk")
3227        (+ pack FRintk op GRi ope GRj)
3228        (ne-load-semantics GRi (index-of GRj) FRintk 0 size 1
3229                           (set FRintk
3230                                (c-call mode (.str "@cpu@_read_mem_" mode)
3231                                        pc (add GRi GRj))))
3232        ((fr500 (unit u-fr-load)))
3233   )
3234 )
3235
3236 (ne-load-fr-r nldbf UQI OP_02 OPE1_28 (ne-UQI-size) "Load byte float")
3237 (ne-load-fr-r nldhf UHI OP_02 OPE1_29 (ne-UHI-size) "Load half float")
3238 (ne-load-fr-r nldf   SI OP_02 OPE1_2A (ne-SI-size)  "Load word float")
3239
3240 ; Semantics for a load-double insn
3241 ;
3242 (define-pmacro (load-double-semantics not_gr mode regtype address arg)
3243   (if (orif not_gr (ne (index-of (.sym regtype doublek)) 0))
3244       (sequence ()
3245                 (set address (add GRi arg))
3246                 (set (.sym regtype doublek)
3247                      (c-call mode (.str "@cpu@_read_mem_" mode) pc address))))
3248 )
3249
3250 (define-pmacro (load-double-r-r
3251                 name not_gr mode op ope regtype attr profile comment)
3252   (dni name
3253        (comment)
3254        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) attr)
3255        (.str name "$pack @($GRi,$GRj),$" regtype "doublek")
3256        (+ pack (.sym regtype doublek) op GRi ope GRj)
3257        (sequence ((WI address))
3258                  (load-double-semantics not_gr mode regtype address GRj))
3259        profile
3260   )
3261 )
3262
3263 (load-double-r-r ldd  0 DI OP_02 OPE1_05 GR  NA
3264                  ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
3265                  "Load double word")
3266 (load-double-r-r lddf 1 DF OP_02 OPE1_0B FR  FR-ACCESS
3267                  ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
3268                  "Load double float")
3269 (load-double-r-r lddc 1 DI OP_02 OPE1_0E CPR (MACH frv) ()
3270                  "Load coprocessor double")
3271
3272 (define-pmacro (ne-load-double-r-r
3273                 name not_gr mode op ope regtype size is_float attr profile
3274                 comment)
3275   (dni name
3276        (comment)
3277        ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING attr
3278         (MACH simple,tomcat,fr500,frv))
3279        (.str name "$pack @($GRi,$GRj),$" regtype "doublek")
3280        (+ pack (.sym regtype doublek) op GRi ope GRj)
3281        (sequence ((WI address))
3282                  (ne-load-semantics GRi (index-of GRj) (.sym regtype doublek)
3283                                     0 size is_float
3284                                     (load-double-semantics not_gr mode
3285                                                            regtype
3286                                                            address GRj)))
3287        profile
3288   )
3289 )
3290
3291 (ne-load-double-r-r nldd  0 DI OP_02 OPE1_25 GR (ne-DI-size) 0 NA
3292                     ((fr500 (unit u-gr-load))) "Load double   word")
3293 (ne-load-double-r-r nlddf 1 DF OP_02 OPE1_2B FR (ne-DI-size) 1 FR-ACCESS
3294                     ((fr500 (unit u-fr-load))) "Load double float")
3295
3296 ; Semantics for a load-quad insn
3297 ;
3298 (define-pmacro (load-quad-semantics regtype address arg)
3299   (sequence ()
3300             (set address (add GRi arg))
3301             (c-call VOID (.str "@cpu@_load_quad_" regtype)
3302                     pc address (index-of (.sym regtype k))))
3303 )
3304
3305 (define-pmacro (load-quad-r-r name op ope regtype attr profile comment)
3306   (dni name
3307        (comment)
3308        ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) attr)
3309        (.str name "$pack @($GRi,$GRj),$" regtype "k")
3310        (+ pack (.sym regtype k) op GRi ope GRj)
3311        (sequence ((WI address))
3312                  (load-quad-semantics regtype address GRj))
3313        ; TODO regtype-k not referenced for profiling
3314        profile
3315   )
3316 )
3317
3318 (load-quad-r-r ldq  OP_02 OPE1_06 GR    NA        ((fr500 (unit u-gr-load)))
3319                "Load quad word")
3320 (load-quad-r-r ldqf OP_02 OPE1_0C FRint FR-ACCESS ((fr500 (unit u-fr-load)))
3321                "Load quad float")
3322 (load-quad-r-r ldqc OP_02 OPE1_0F CPR   NA        () "Load coprocessor quad")
3323
3324 (define-pmacro (ne-load-quad-r-r
3325                 name op ope regtype size is_float attr profile comment)
3326   (dni name
3327        (comment)
3328        ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) NON-EXCEPTING attr)
3329        (.str name "$pack @($GRi,$GRj),$" regtype "k")
3330        (+ pack (.sym regtype k) op GRi ope GRj)
3331        (sequence ((WI address))
3332                  (ne-load-semantics GRi (index-of GRj) (.sym regtype k)
3333                                     0 size is_float
3334                                     (load-quad-semantics regtype address GRj)))
3335        ; TODO regtype-k not referenced for profiling
3336        profile
3337   )
3338 )
3339
3340 (ne-load-quad-r-r nldq  OP_02 OPE1_26 GR    (ne-XI-size) 0 NA
3341                   ((fr500 (unit u-gr-load))) "Load quad word")
3342 (ne-load-quad-r-r nldqf OP_02 OPE1_2C FRint (ne-XI-size) 1 FR-ACCESS
3343                   ((fr500 (unit u-fr-load))) "Load quad float")
3344
3345 (define-pmacro (load-gr-u-semantics mode)
3346   (sequence ((UWI address))
3347             (set address (add GRi GRj))
3348             (set GRk (c-call mode (.str "@cpu@_read_mem_" mode) pc address))
3349             (if (ne (index-of GRi) (index-of GRk))
3350                 (sequence ()
3351                           (set GRi address)
3352                           (c-call VOID "@cpu@_force_update"))))
3353 )
3354
3355 (define-pmacro (load-gr-u name mode op ope comment)
3356   (dni name
3357        (comment)
3358        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2))
3359        (.str name "$pack @($GRi,$GRj),$GRk")
3360        (+ pack GRk op GRi ope GRj)
3361        (load-gr-u-semantics mode)
3362        ((fr400 (unit u-gr-load))
3363         (fr500 (unit u-gr-load)))
3364   )
3365 )
3366
3367 (load-gr-u ldsbu   QI OP_02 OPE1_10 "Load   signed byte, update index")
3368 (load-gr-u ldubu  UQI OP_02 OPE1_11 "Load unsigned byte, update index")
3369 (load-gr-u ldshu   HI OP_02 OPE1_12 "Load   signed half, update index")
3370 (load-gr-u lduhu  UHI OP_02 OPE1_13 "Load unsigned half, update index")
3371 (load-gr-u ldu     SI OP_02 OPE1_14 "Load          word, update index")
3372
3373 (define-pmacro (ne-load-gr-u name mode op ope size comment)
3374   (dni name
3375        (comment)
3376        ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING
3377         (MACH simple,tomcat,fr500,frv))
3378        (.str name "$pack @($GRi,$GRj),$GRk")
3379        (+ pack GRk op GRi ope GRj)
3380        (ne-load-semantics GRi (index-of GRj) GRk 0 size 0 (load-gr-u-semantics mode))
3381        ((fr500 (unit u-gr-load)))
3382   )
3383 )
3384
3385 (ne-load-gr-u nldsbu  QI OP_02 OPE1_30 (ne-QI-size)  "Load   signed byte, update index")
3386 (ne-load-gr-u nldubu UQI OP_02 OPE1_31 (ne-UQI-size) "Load unsigned byte, update index")
3387 (ne-load-gr-u nldshu  HI OP_02 OPE1_32 (ne-HI-size)  "Load   signed half, update index")
3388 (ne-load-gr-u nlduhu UHI OP_02 OPE1_33 (ne-UHI-size) "Load unsigned half, update index")
3389 (ne-load-gr-u nldu    SI OP_02 OPE1_34 (ne-SI-size)  "Load          word, update index")
3390
3391 (define-pmacro (load-non-gr-u-semantics mode regtype)
3392   (sequence ((UWI address))
3393             (set address (add GRi GRj))
3394             (set (.sym regtype k)
3395                  (c-call mode (.str "@cpu@_read_mem_" mode) pc address))
3396             (set GRi address)
3397             (c-call VOID "@cpu@_force_update"))
3398 )
3399
3400 (define-pmacro (load-fr-u name mode op ope comment)
3401   (dni name
3402        (comment)
3403        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) FR-ACCESS)
3404        (.str name "$pack @($GRi,$GRj),$FRintk")
3405        (+ pack FRintk op GRi ope GRj)
3406        (load-non-gr-u-semantics mode FRint)
3407        ((fr400 (unit u-fr-load))
3408         (fr500 (unit u-fr-load)))
3409   )
3410 )
3411
3412 (load-fr-u ldbfu  UQI OP_02 OPE1_18 "Load byte float, update index")
3413 (load-fr-u ldhfu  UHI OP_02 OPE1_19 "Load half float, update index")
3414 (load-fr-u ldfu    SI OP_02 OPE1_1A "Load word float, update index")
3415
3416 (define-pmacro (load-cpr-u name mode op ope comment)
3417   (dni name
3418        (comment)
3419        ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv))
3420        (.str name "$pack @($GRi,$GRj),$CPRk")
3421        (+ pack CPRk op GRi ope GRj)
3422        (load-non-gr-u-semantics mode CPR)
3423        ()
3424   )
3425 )
3426
3427 (load-cpr-u ldcu SI OP_02 OPE1_1D "Load coprocessor word float,update index")
3428
3429 (define-pmacro (ne-load-non-gr-u name mode op ope regtype size comment)
3430   (dni name
3431        (comment)
3432        ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING FR-ACCESS
3433         (MACH simple,tomcat,fr500,frv))
3434        (.str name "$pack @($GRi,$GRj),$" regtype "k")
3435        (+ pack (.sym regtype k) op GRi ope GRj)
3436        (ne-load-semantics GRi (index-of GRj) (.sym regtype k) 0 size 1
3437                           (load-non-gr-u-semantics mode regtype))
3438        ((fr500 (unit u-fr-load)))
3439   )
3440 )
3441
3442 (ne-load-non-gr-u nldbfu UQI OP_02 OPE1_38 FRint (ne-UQI-size) "Load byte float, update index")
3443 (ne-load-non-gr-u nldhfu UHI OP_02 OPE1_39 FRint (ne-UHI-size) "Load half float, update index")
3444 (ne-load-non-gr-u nldfu   SI OP_02 OPE1_3A FRint (ne-SI-size)  "Load word float, update index")
3445
3446 (define-pmacro (load-double-gr-u-semantics)
3447   (sequence ((WI address))
3448             (load-double-semantics 0 DI GR address GRj)
3449             (if (ne (index-of GRi) (index-of GRdoublek))
3450                 (sequence ()
3451                           (set GRi address)
3452                           (c-call VOID "@cpu@_force_update"))))
3453 )
3454
3455 (define-pmacro (load-double-gr-u name op ope comment)
3456   (dni name
3457        (comment)
3458        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2))
3459        (.str name "$pack @($GRi,$GRj),$GRdoublek")
3460        (+ pack GRdoublek op GRi ope GRj)
3461        (load-double-gr-u-semantics)
3462        ((fr400 (unit u-gr-load))
3463         (fr500 (unit u-gr-load)))
3464   )
3465 )
3466
3467 (load-double-gr-u lddu  OP_02 OPE1_15 "Load double word, update index")
3468
3469 (define-pmacro (ne-load-double-gr-u name op ope size comment)
3470   (dni name
3471        (comment)
3472        ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING
3473         (MACH simple,tomcat,fr500,frv))
3474        (.str name "$pack @($GRi,$GRj),$GRdoublek")
3475        (+ pack GRdoublek op GRi ope GRj)
3476        (ne-load-semantics GRi (index-of GRj) GRdoublek 0 size 0
3477                           (load-double-gr-u-semantics))
3478        ((fr500 (unit u-gr-load)))
3479
3480   )
3481 )
3482
3483 (ne-load-double-gr-u nlddu OP_02 OPE1_35 (ne-DI-size) "Load double word, update index")
3484
3485 (define-pmacro (load-double-non-gr-u-semantics mode regtype)
3486   (sequence ((WI address))
3487             (load-double-semantics 1 mode regtype address GRj)
3488             (set GRi address)
3489             (c-call VOID "@cpu@_force_update"))
3490 )
3491
3492 (define-pmacro (load-double-non-gr-u
3493                 name mode op ope regtype attr profile comment)
3494   (dni name
3495        (comment)
3496        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) attr)
3497        (.str name "$pack @($GRi,$GRj),$" regtype "doublek")
3498        (+ pack (.sym regtype doublek) op GRi ope GRj)
3499        (load-double-non-gr-u-semantics mode regtype)
3500        profile
3501   )
3502 )
3503
3504 (load-double-non-gr-u lddfu DF OP_02 OPE1_1B FR  FR-ACCESS
3505                       ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
3506                       "Load double float, update index")
3507 (load-double-non-gr-u lddcu DI OP_02 OPE1_1E CPR (MACH frv)
3508                       () "Load coprocessor double float, update index")
3509
3510 (define-pmacro (ne-load-double-non-gr-u name mode op ope regtype size comment)
3511   (dni name
3512        (comment)
3513        ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING FR-ACCESS
3514         (MACH simple,tomcat,fr500,frv))
3515        (.str name "$pack @($GRi,$GRj),$" regtype "doublek")
3516        (+ pack (.sym regtype doublek) op GRi ope GRj)
3517        (ne-load-semantics GRi (index-of GRj) (.sym regtype doublek) 0 size 1
3518                           (load-double-non-gr-u-semantics mode regtype))
3519        ((fr500 (unit u-fr-load)))
3520   )
3521 )
3522
3523 (ne-load-double-non-gr-u nlddfu DF OP_02 OPE1_3B FR (ne-DI-size) "Load double float, update index")
3524
3525 (define-pmacro (load-quad-gr-u-semantics)
3526   (sequence ((WI address))
3527             (load-quad-semantics GR address GRj)
3528             (if (ne (index-of GRi) (index-of GRk))
3529                 (sequence ()
3530                           (set GRi address)
3531                           (c-call VOID "@cpu@_force_update"))))
3532 )
3533
3534 (define-pmacro (load-quad-gr-u name op ope comment)
3535   (dni name
3536        (comment)
3537        ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv))
3538        (.str name "$pack @($GRi,$GRj),$GRk")
3539        (+ pack GRk op GRi ope GRj)
3540        (load-quad-gr-u-semantics)
3541        ; TODO - GRk not referenced here for profiling
3542        ((fr500 (unit u-gr-load)))
3543   )
3544 )
3545
3546 (load-quad-gr-u ldqu  OP_02 OPE1_16 "Load quad word, update index")
3547
3548 (define-pmacro (ne-load-quad-gr-u name op ope size comment)
3549   (dni name
3550        (comment)
3551        ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) NON-EXCEPTING)
3552        (.str name "$pack @($GRi,$GRj),$GRk")
3553        (+ pack GRk op GRi ope GRj)
3554        (ne-load-semantics GRi (index-of GRj) GRk 0 size 0
3555                           (load-quad-gr-u-semantics))
3556        ; TODO - GRk not referenced here for profiling
3557        ((fr500 (unit u-gr-load)))
3558   )
3559 )
3560
3561 (ne-load-quad-gr-u nldqu OP_02 OPE1_36 (ne-XI-size) "Load quad word, update index")
3562
3563 (define-pmacro (load-quad-non-gr-u-semantics regtype)
3564   (sequence ((WI address))
3565             (load-quad-semantics regtype address GRj)
3566             (set GRi address)
3567             (c-call VOID "@cpu@_force_update"))
3568 )
3569
3570 (define-pmacro (load-quad-non-gr-u name op ope regtype attr profile comment)
3571   (dni name
3572        (comment)
3573        ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) attr)
3574        (.str name "$pack @($GRi,$GRj),$" regtype "k")
3575        (+ pack (.sym regtype k) op GRi ope GRj)
3576        (load-quad-non-gr-u-semantics regtype)
3577        profile
3578   )
3579 )
3580
3581 (load-quad-non-gr-u ldqfu OP_02 OPE1_1C FRint FR-ACCESS
3582                     ((fr500 (unit u-fr-load))) "Load quad float, update index")
3583 (load-quad-non-gr-u ldqcu OP_02 OPE1_1F CPR   NA
3584                     () "Load coprocessor quad word, update index")
3585
3586 (define-pmacro (ne-load-quad-non-gr-u name op ope regtype size comment)
3587   (dni name
3588        (comment)
3589        ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) NON-EXCEPTING FR-ACCESS)
3590        (.str name "$pack @($GRi,$GRj),$" regtype "k")
3591        (+ pack (.sym regtype k) op GRi ope GRj)
3592        (ne-load-semantics GRi (index-of GRj) (.sym regtype k) 0 size 1
3593                           (load-quad-non-gr-u-semantics regtype))
3594        ((fr500 (unit u-fr-load)))
3595   )
3596 )
3597
3598 (ne-load-quad-non-gr-u nldqfu OP_02 OPE1_3C FRint (ne-XI-size) "Load quad float,update index")
3599
3600 (define-pmacro (load-r-simm name mode op regtype attr profile comment)
3601   (dni name
3602        (comment)
3603        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) attr)
3604        (.str name "$pack @($GRi,$d12),$" regtype "k")
3605        (+ pack (.sym regtype k) op GRi d12)
3606        (set (.sym regtype k)
3607             (c-call mode (.str "@cpu@_read_mem_" mode) pc (add GRi d12)))
3608        profile
3609   )
3610 )
3611
3612 (load-r-simm ldsbi  QI OP_30 GR NA
3613              ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
3614              "Load   signed byte")
3615 (load-r-simm ldshi  HI OP_31 GR NA
3616              ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
3617              "Load   signed half")
3618 (load-r-simm ldi    SI OP_32 GR NA
3619              ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
3620              "Load          word")
3621 (load-r-simm ldubi UQI OP_35 GR NA
3622              ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
3623              "Load unsigned byte")
3624 (load-r-simm lduhi UHI OP_36 GR NA
3625              ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
3626              "Load unsigned half")
3627
3628 (load-r-simm ldbfi UQI OP_38 FRint FR-ACCESS
3629              ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
3630              "Load byte float")
3631 (load-r-simm ldhfi UHI OP_39 FRint FR-ACCESS
3632              ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
3633              "Load half float")
3634 (load-r-simm ldfi   SI OP_3A FRint FR-ACCESS
3635              ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
3636              "Load word float")
3637
3638 (define-pmacro (ne-load-r-simm
3639                 name mode op regtype size is_float attr profile comment)
3640   (dni name
3641        (comment)
3642        ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING attr
3643         (MACH simple,tomcat,fr500,frv))
3644        (.str name "$pack @($GRi,$d12),$" regtype "k")
3645        (+ pack (.sym regtype k) op GRi d12)
3646        (ne-load-semantics GRi -1 (.sym regtype k) d12 size is_float
3647                           (set (.sym regtype k)
3648                                (c-call mode (.str "@cpu@_read_mem_" mode)
3649                                        pc (add GRi d12))))
3650        profile
3651   )
3652 )
3653
3654 (ne-load-r-simm nldsbi  QI OP_40 GR (ne-QI-size)  0 NA
3655                 ((fr500 (unit u-gr-load))) "Load   signed byte")
3656 (ne-load-r-simm nldubi UQI OP_41 GR (ne-UQI-size) 0 NA
3657                 ((fr500 (unit u-gr-load))) "Load unsigned byte")
3658 (ne-load-r-simm nldshi  HI OP_42 GR (ne-HI-size)  0 NA
3659                 ((fr500 (unit u-gr-load))) "Load   signed half")
3660 (ne-load-r-simm nlduhi UHI OP_43 GR (ne-UHI-size) 0 NA
3661                 ((fr500 (unit u-gr-load))) "Load unsigned half")
3662 (ne-load-r-simm nldi    SI OP_44 GR (ne-SI-size)  0 NA
3663                 ((fr500 (unit u-gr-load))) "Load          word")
3664
3665 (ne-load-r-simm nldbfi UQI OP_48 FRint (ne-UQI-size) 1 FR-ACCESS
3666                 ((fr500 (unit u-fr-load))) "Load byte float")
3667 (ne-load-r-simm nldhfi UHI OP_49 FRint (ne-UHI-size) 1 FR-ACCESS
3668                 ((fr500 (unit u-fr-load))) "Load half float")
3669 (ne-load-r-simm nldfi   SI OP_4A FRint (ne-SI-size)  1 FR-ACCESS
3670                 ((fr500 (unit u-fr-load))) "Load word float")
3671
3672 (define-pmacro (load-double-r-simm
3673                 name not_gr mode op regtype attr profile comment)
3674   (dni name
3675        (comment)
3676        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) attr)
3677        (.str name "$pack @($GRi,$d12),$" regtype "doublek")
3678        (+ pack (.sym regtype doublek) op GRi d12)
3679        (sequence ((WI address))
3680                  (load-double-semantics not_gr mode regtype address d12))
3681        profile
3682   )
3683 )
3684
3685 (load-double-r-simm lddi  0 DI OP_33 GR NA
3686                     ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
3687                     "Load double word")
3688 (load-double-r-simm lddfi 1 DF OP_3B FR FR-ACCESS
3689                     ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
3690                     "Load double float")
3691
3692 (define-pmacro (ne-load-double-r-simm
3693                 name not_gr mode op regtype size is_float attr profile comment)
3694   (dni name
3695        (comment)
3696        ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING attr
3697         (MACH simple,tomcat,fr500,frv))
3698        (.str name "$pack @($GRi,$d12),$" regtype "doublek")
3699        (+ pack (.sym regtype doublek) op GRi d12)
3700        (sequence ((WI address))
3701                  (ne-load-semantics GRi -1 (.sym regtype doublek)
3702                                     d12 size is_float
3703                                     (load-double-semantics not_gr mode
3704                                                            regtype
3705                                                            address d12)))
3706        profile
3707   )
3708 )
3709
3710 (ne-load-double-r-simm nlddi  0 DI OP_45 GR (ne-DI-size) 0 NA
3711                        ((fr500 (unit u-gr-load))) "Load double word")
3712 (ne-load-double-r-simm nlddfi 1 DF OP_4B FR (ne-DI-size) 1 FR-ACCESS
3713                        ((fr500 (unit u-fr-load))) "Load double float")
3714
3715 (define-pmacro (load-quad-r-simm name op regtype attr profile comment)
3716   (dni name
3717        (comment)
3718        ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) attr)
3719        (.str name "$pack @($GRi,$d12),$" regtype "k")
3720        (+ pack (.sym regtype k) op GRi d12)
3721        (sequence ((WI address))
3722                  (load-quad-semantics regtype address d12))
3723        profile
3724   )
3725 )
3726
3727 (load-quad-r-simm ldqi  OP_34 GR    NA
3728                   ((fr500 (unit u-gr-load))) "Load quad word")
3729 (load-quad-r-simm ldqfi OP_3C FRint FR-ACCESS
3730                   ((fr500 (unit u-fr-load))) "Load quad float")
3731
3732 (define-pmacro (ne-load-quad-r-simm
3733                 name op regtype size is_float attr profile comment)
3734   (dni name
3735        (comment)
3736        ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) NON-EXCEPTING attr)
3737        (.str name "$pack @($GRi,$d12),$" regtype "k")
3738        (+ pack (.sym regtype k) op GRi d12)
3739        (sequence ((WI address))
3740                  (ne-load-semantics GRi -1 (.sym regtype k) d12 size is_float
3741                                     (load-quad-semantics regtype address d12)))
3742        profile
3743   )
3744 )
3745
3746 (ne-load-quad-r-simm nldqi  OP_46 GR    (ne-XI-size) 0 NA
3747                      ((fr500 (unit u-gr-load))) "Load quad word")
3748 (ne-load-quad-r-simm nldqfi OP_4C FRint (ne-XI-size) 1 FR-ACCESS
3749                      ((fr500 (unit u-fr-load))) "Load quad float")
3750
3751 (define-pmacro (store-r-r name mode op ope reg attr profile comment)
3752   (dni name
3753        (comment)
3754        ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
3755        (.str name "$pack $" reg "k,@($GRi,$GRj)")
3756        (+ pack (.sym reg k) op GRi ope GRj)
3757        (c-call VOID (.str "@cpu@_write_mem_" mode)
3758                pc (add GRi GRj) (.sym reg k))
3759        profile
3760   )
3761 )
3762
3763 (store-r-r stb   QI OP_03 OPE1_00 GR NA
3764            ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
3765            "Store unsigned byte")
3766 (store-r-r sth   HI OP_03 OPE1_01 GR NA
3767            ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
3768            "Store unsigned half")
3769 (store-r-r st    SI OP_03 OPE1_02 GR NA
3770            ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
3771            "Store          word")
3772
3773 (store-r-r stbf  QI OP_03 OPE1_08 FRint FR-ACCESS
3774            ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
3775            "Store byte float")
3776 (store-r-r sthf  HI OP_03 OPE1_09 FRint FR-ACCESS
3777            ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
3778            "Store half float")
3779 (store-r-r stf   SI OP_03 OPE1_0A FRint FR-ACCESS
3780            ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
3781            "Store word float")
3782
3783 (store-r-r stc   SI OP_03 OPE1_25 CPR (MACH frv) () "Store coprocessor word")
3784
3785 (define-pmacro (r-store name mode op ope reg size is_float profile comment)
3786   (dni name
3787        (comment)
3788        ((UNIT I0) (FR500-MAJOR I-3) (MACH frv))
3789        (.str name "$pack $" reg "k,@($GRi,$GRj)")
3790        (+ pack (.sym reg k) op GRi ope GRj)
3791        (sequence ((WI address))
3792                  (set address (add GRi GRj))
3793                  (c-call VOID (.str "@cpu@_write_mem_" mode)
3794                          pc address (.sym reg k))
3795                  (c-call VOID "@cpu@_check_recovering_store"
3796                          address (index-of (.sym reg k)) size is_float))
3797        profile
3798   )
3799 )
3800
3801 (r-store rstb  QI OP_03 OPE1_20 GR 1 0
3802          ((fr500 (unit u-gr-r-store))) "Store unsigned byte")
3803 (r-store rsth  HI OP_03 OPE1_21 GR 2 0
3804          ((fr500 (unit u-gr-r-store))) "Store unsigned half")
3805 (r-store rst   SI OP_03 OPE1_22 GR 4 0
3806          ((fr500 (unit u-gr-r-store))) "Store          word")
3807
3808 (r-store rstbf QI OP_03 OPE1_28 FRint 1 1
3809          ((fr500 (unit u-fr-r-store))) "Store byte float")
3810 (r-store rsthf HI OP_03 OPE1_29 FRint 2 1
3811          ((fr500 (unit u-fr-r-store))) "Store half float")
3812 (r-store rstf  SI OP_03 OPE1_2A FRint 4 1
3813          ((fr500 (unit u-fr-r-store))) "Store word float")
3814
3815 ; Semantics for a store-double insn
3816 ;
3817 (define-pmacro (store-double-semantics mode regtype address arg)
3818   (sequence ()
3819             (set address (add GRi arg))
3820             (c-call VOID (.str "@cpu@_write_mem_" mode)
3821                     pc address (.sym regtype doublek)))
3822 )
3823
3824 (define-pmacro (store-double-r-r name mode op ope regtype attr profile comment)
3825   (dni name
3826        (comment)
3827        ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
3828        (.str name "$pack $" regtype "k,@($GRi,$GRj)")
3829        (+ pack (.sym regtype k) op GRi ope GRj)
3830        (sequence ((WI address))
3831                  (store-double-semantics mode regtype address GRj))
3832        profile
3833   )
3834 )
3835
3836 (store-double-r-r std  DI OP_03 OPE1_03 GR  NA
3837                   ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
3838                   "Store double word")
3839 (store-double-r-r stdf DF OP_03 OPE1_0B FR  FR-ACCESS
3840                   ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
3841                   "Store double float")
3842
3843 (store-double-r-r stdc DI OP_03 OPE1_26 CPR (MACH frv)
3844                   () "Store coprocessor double word")
3845
3846 (define-pmacro (r-store-double
3847                 name mode op ope regtype is_float attr profile comment)
3848   (dni name
3849        (comment)
3850        ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) attr)
3851        (.str name "$pack $" regtype "k,@($GRi,$GRj)")
3852        (+ pack (.sym regtype k) op GRi ope GRj)
3853        (sequence ((WI address))
3854                  (store-double-semantics mode regtype address GRj)
3855                  (c-call VOID "@cpu@_check_recovering_store"
3856                          address (index-of (.sym regtype k)) 8 is_float))
3857        profile
3858   )
3859 )
3860
3861 (r-store-double rstd  DI OP_03 OPE1_23 GR 0 NA
3862                 ((fr500 (unit u-gr-r-store))) "Store double word")
3863 (r-store-double rstdf DF OP_03 OPE1_2B FR 1 FR-ACCESS
3864                 ((fr500 (unit u-fr-r-store))) "Store double float")
3865
3866 ; Semantics for a store-quad insn
3867 ;
3868 (define-pmacro (store-quad-semantics regtype address arg)
3869   (sequence ()
3870             (set address (add GRi arg))
3871             (c-call VOID (.str "@cpu@_store_quad_" regtype)
3872                      pc address (index-of (.sym regtype k))))
3873 )
3874
3875 (define-pmacro (store-quad-r-r name op ope regtype attr profile comment)
3876   (dni name
3877        (comment)
3878        ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) attr)
3879        (.str name "$pack $" regtype "k,@($GRi,$GRj)")
3880        (+ pack (.sym regtype k) op GRi ope GRj)
3881        (sequence ((WI address))
3882                  (store-quad-semantics regtype address GRj))
3883        profile
3884   )
3885 )
3886
3887 (store-quad-r-r stq   OP_03 OPE1_04 GR    NA
3888                 ((fr500 (unit u-gr-store))) "Store quad word")
3889 (store-quad-r-r stqf  OP_03 OPE1_0C FRint FR-ACCESS
3890                 ((fr500 (unit u-fr-store)))
3891                 "Store quad float")
3892 (store-quad-r-r stqc  OP_03 OPE1_27 CPR   NA
3893                 () "Store coprocessor quad word")
3894
3895 (define-pmacro (r-store-quad name op ope regtype is_float attr profile comment)
3896   (dni name
3897        (comment)
3898        ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) attr)
3899        (.str name "$pack $" regtype "k,@($GRi,$GRj)")
3900        (+ pack (.sym regtype k) op GRi ope GRj)
3901        (sequence ((WI address))
3902                  (store-quad-semantics regtype address GRj)
3903                  (c-call VOID "@cpu@_check_recovering_store"
3904                          address (index-of (.sym regtype k)) 16 is_float))
3905        profile
3906   )
3907 )
3908
3909 (r-store-quad rstq  OP_03 OPE1_24 GR    0 NA
3910               ((fr500 (unit u-gr-r-store))) "Store quad word")
3911 (r-store-quad rstqf OP_03 OPE1_2C FRint 1 FR-ACCESS
3912               ((fr500 (unit u-fr-r-store))) "Store quad float")
3913
3914 (define-pmacro (store-r-r-u name mode op ope regtype attr profile comment)
3915   (dni name
3916        (comment)
3917        ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
3918        (.str name "$pack $" regtype "k,@($GRi,$GRj)")
3919        (+ pack (.sym regtype k) op GRi ope GRj)
3920        (sequence ((UWI address))
3921                  (set address (add GRi GRj))
3922                  (c-call VOID (.str "@cpu@_write_mem_" mode)
3923                          pc address (.sym regtype k))
3924                  (set GRi address))
3925        profile
3926   )
3927 )
3928
3929 (store-r-r-u stbu  QI OP_03 OPE1_10 GR NA
3930              ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
3931              "Store unsigned byte, update index")
3932 (store-r-r-u sthu  HI OP_03 OPE1_11 GR NA
3933              ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
3934              "Store unsigned half, update index")
3935 (store-r-r-u stu   WI OP_03 OPE1_12 GR NA
3936              ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
3937              "Store          word, update index")
3938
3939 (store-r-r-u stbfu QI OP_03 OPE1_18 FRint FR-ACCESS
3940              ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
3941              "Store byte float, update index")
3942 (store-r-r-u sthfu HI OP_03 OPE1_19 FRint FR-ACCESS
3943              ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
3944              "Store half float, update index")
3945 (store-r-r-u stfu  SI OP_03 OPE1_1A FRint FR-ACCESS
3946              ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
3947              "Store word float, update index")
3948
3949 (store-r-r-u stcu  SI OP_03 OPE1_2D CPR (MACH frv) ()
3950              "Store coprocessor word, update index")
3951
3952 (define-pmacro (store-double-r-r-u
3953                 name mode op ope regtype attr profile comment)
3954   (dni name
3955        (comment)
3956        ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
3957        (.str name "$pack $" regtype "k,@($GRi,$GRj)")
3958        (+ pack (.sym regtype k) op GRi ope GRj)
3959        (sequence ((WI address))
3960                  (store-double-semantics mode regtype address GRj)
3961                  (set GRi address))
3962        profile
3963   )
3964 )
3965
3966 (store-double-r-r-u stdu  DI OP_03 OPE1_13 GR  NA
3967                     ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
3968                     "Store double word, update index")
3969 (store-double-r-r-u stdfu DF OP_03 OPE1_1B FR  FR-ACCESS
3970                     ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
3971                     "Store double float,update index")
3972 (store-double-r-r-u stdcu DI OP_03 OPE1_2E CPR (MACH frv) ()
3973                     "Store coprocessor double word, update index")
3974
3975 (define-pmacro (store-quad-r-r-u name op ope regtype attr profile comment)
3976   (dni name
3977        (comment)
3978        ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) attr)
3979        (.str name "$pack $" regtype "k,@($GRi,$GRj)")
3980        (+ pack (.sym regtype k) op GRi ope GRj)
3981        (sequence ((WI address))
3982                  (store-quad-semantics regtype address GRj)
3983                  (set GRi address))
3984        profile
3985   )
3986 )
3987
3988 (store-quad-r-r-u stqu  OP_03 OPE1_14 GR    NA
3989                   ((fr500 (unit u-gr-store)))
3990                   "Store quad word, update index")
3991 (store-quad-r-r-u stqfu OP_03 OPE1_1C FRint FR-ACCESS
3992                   ((fr500 (unit u-fr-store)))
3993                   "Store quad float, update index")
3994 (store-quad-r-r-u stqcu OP_03 OPE1_2F CPR   NA ()
3995                   "Store coprocessor quad   word, update index")
3996
3997 (define-pmacro (conditional-load name mode op ope regtype profile comment)
3998   (dni name
3999        (comment)
4000        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL)
4001        (.str name "$pack @($GRi,$GRj),$" regtype "k,$CCi,$cond")
4002        (+ pack (.sym regtype k) op GRi CCi  cond ope GRj)
4003        (if (eq CCi (or cond 2))
4004            (set (.sym regtype k)
4005                 (c-call mode (.str "@cpu@_read_mem_" mode) pc (add GRi GRj))))
4006        profile
4007   )
4008 )
4009
4010 (conditional-load cldsb  QI OP_5E OPE4_0 GR
4011                   ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
4012                   "Load   signed byte")
4013 (conditional-load cldub UQI OP_5E OPE4_1 GR
4014                   ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
4015                   "Load unsigned byte")
4016 (conditional-load cldsh  HI OP_5E OPE4_2 GR
4017                   ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
4018                   "Load   signed half")
4019 (conditional-load clduh UHI OP_5E OPE4_3 GR
4020                   ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
4021                   "Load unsigned half")
4022 (conditional-load cld    SI OP_5F OPE4_0 GR
4023                   ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
4024                   "Load          word")
4025
4026 (conditional-load cldbf UQI OP_60 OPE4_0 FRint
4027                   ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
4028                   "Load byte float")
4029 (conditional-load cldhf UHI OP_60 OPE4_1 FRint
4030                   ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
4031                   "Load half float")
4032 (conditional-load cldf   SI OP_60 OPE4_2 FRint
4033                   ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
4034                   "Load word float")
4035
4036 (define-pmacro (conditional-load-double
4037                 name not_gr mode op ope regtype attr profile comment)
4038   (dni name
4039        (comment)
4040        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL attr)
4041        (.str name "$pack @($GRi,$GRj),$" regtype "doublek,$CCi,$cond")
4042        (+ pack (.sym regtype doublek) op GRi CCi  cond ope GRj)
4043        (if (eq CCi (or cond 2))
4044            (sequence ((WI address))
4045                      (load-double-semantics not_gr mode regtype address GRj)))
4046        profile
4047   )
4048 )
4049
4050 (conditional-load-double cldd  0 DI OP_5F OPE4_1 GR NA
4051                          ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
4052                          "Load double word")
4053 (conditional-load-double clddf 1 DF OP_60 OPE4_3 FR FR-ACCESS
4054                          ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
4055                          "Load double float")
4056
4057 (dni cldq
4058      "conditional load quad integer"
4059      ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) CONDITIONAL)
4060      "cldq$pack @($GRi,$GRj),$GRk,$CCi,$cond"
4061      (+ pack GRk OP_5F GRi CCi cond OPE4_2 GRj)
4062      (if (eq CCi (or cond 2))
4063          (sequence ((WI address))
4064                    (load-quad-semantics GR address GRj)))
4065      ((fr500 (unit u-gr-load)))
4066 )
4067
4068 (define-pmacro (conditional-load-gr-u name mode op ope comment)
4069   (dni name
4070        (comment)
4071        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL)
4072        (.str name "$pack @($GRi,$GRj),$GRk,$CCi,$cond")
4073        (+ pack GRk op GRi CCi  cond ope GRj)
4074        (if (eq CCi (or cond 2))
4075            (sequence ((WI address))
4076                      (set address (add GRi GRj))
4077                      (set GRk
4078                           (c-call mode (.str "@cpu@_read_mem_" mode)
4079                                   pc address))
4080                      (if (ne (index-of GRi) (index-of GRk))
4081                          (set GRi address))))
4082        ((fr400 (unit u-gr-load))
4083         (fr500 (unit u-gr-load)))
4084   )
4085 )
4086
4087 (conditional-load-gr-u cldsbu  QI OP_61 OPE4_0 "Load   signed byte, update")
4088 (conditional-load-gr-u cldubu UQI OP_61 OPE4_1 "Load unsigned byte, update")
4089 (conditional-load-gr-u cldshu  HI OP_61 OPE4_2 "Load   signed half, update")
4090 (conditional-load-gr-u clduhu UHI OP_61 OPE4_3 "Load unsigned half, update")
4091 (conditional-load-gr-u cldu    SI OP_62 OPE4_0 "Load          word, update")
4092
4093 (define-pmacro (conditional-load-non-gr-u name mode op ope regtype comment)
4094   (dni name
4095        (comment)
4096        ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL FR-ACCESS)
4097        (.str name "$pack @($GRi,$GRj),$" regtype "k,$CCi,$cond")
4098        (+ pack (.sym regtype k) op GRi CCi  cond ope GRj)
4099        (if (eq CCi (or cond 2))
4100            (sequence ((WI address))
4101                      (set address (add GRi GRj))
4102                      (set (.sym regtype k)
4103                           (c-call mode (.str "@cpu@_read_mem_" mode)
4104                                   pc address))
4105                      (set GRi address)))
4106        ((fr400 (unit u-fr-load))
4107         (fr500 (unit u-fr-load)))
4108   )
4109 )
4110
4111 (conditional-load-non-gr-u cldbfu UQI OP_63 OPE4_0 FRint "Load byte float, update")
4112 (conditional-load-non-gr-u cldhfu UHI OP_63 OPE4_1 FRint "Load half float, update")
4113 (conditional-load-non-gr-u cldfu   SI OP_63 OPE4_2 FRint "Load word float, update")
4114
4115
4116 (dni clddu
4117      "Load double word,  update"
4118      ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL)
4119      "clddu$pack @($GRi,$GRj),$GRdoublek,$CCi,$cond"
4120      (+ pack GRdoublek OP_62 GRi CCi cond OPE4_1 GRj)
4121      (if (eq CCi (or cond 2))
4122          (sequence ((WI address))
4123                    (load-double-semantics 0 DI GR address GRj)
4124                    (if (ne (index-of GRi) (index-of GRdoublek))
4125                        (set GRi address))))
4126      ((fr400 (unit u-gr-load))
4127       (fr500 (unit u-gr-load)))
4128 )
4129
4130 (dni clddfu
4131      "Load double float, update"
4132      ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL FR-ACCESS)
4133      "clddfu$pack @($GRi,$GRj),$FRdoublek,$CCi,$cond"
4134      (+ pack FRdoublek OP_63 GRi CCi cond OPE4_3 GRj)
4135      (if (eq CCi (or cond 2))
4136          (sequence ((WI address))
4137                    (load-double-semantics 1 DF FR address GRj)
4138                    (set GRi address)))
4139      ((fr400 (unit u-fr-load))
4140       (fr500 (unit u-fr-load)))
4141 )
4142
4143 (dni cldqu
4144      "conditional load quad integer and update index"
4145      ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) CONDITIONAL)
4146      "cldqu$pack @($GRi,$GRj),$GRk,$CCi,$cond"
4147      (+ pack GRk OP_62 GRi CCi cond OPE4_2 GRj)
4148      (if (eq CCi (or cond 2))
4149          (sequence ((WI address))
4150                    (load-quad-semantics GR address GRj)
4151                    (if (ne (index-of GRi) (index-of GRk))
4152                        (set GRi address))))
4153      ((fr500 (unit u-gr-load)))
4154 )
4155
4156 (define-pmacro (conditional-store name mode op ope regtype profile comment)
4157   (dni name
4158        (comment)
4159        ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) CONDITIONAL)
4160        (.str name "$pack $" regtype "k,@($GRi,$GRj),$CCi,$cond")
4161        (+ pack (.sym regtype k) op GRi CCi cond ope GRj)
4162        (if (eq CCi (or cond 2))
4163            (c-call VOID (.str "@cpu@_write_mem_" mode)
4164                    pc (add GRi GRj) (.sym regtype k)))
4165        profile
4166   )
4167 )
4168
4169 (conditional-store cstb  QI OP_64 OPE4_0 GR
4170                    ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4171                    "Store unsigned byte")
4172 (conditional-store csth  HI OP_64 OPE4_1 GR
4173                    ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4174                    "Store unsigned half")
4175 (conditional-store cst   SI OP_64 OPE4_2 GR
4176                    ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4177                    "Store          word")
4178
4179 (conditional-store cstbf QI OP_66 OPE4_0 FRint
4180                    ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4181                    "Store byte float")
4182 (conditional-store csthf HI OP_66 OPE4_1 FRint
4183                    ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4184                    "Store half float")
4185 (conditional-store cstf  SI OP_66 OPE4_2 FRint
4186                    ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4187                    "Store word float")
4188
4189 (define-pmacro (conditional-store-double
4190                 name mode op ope regtype attr profile comment)
4191   (dni name
4192        (comment)
4193        ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) CONDITIONAL attr)
4194        (.str name "$pack $" regtype "k,@($GRi,$GRj),$CCi,$cond")
4195        (+ pack (.sym regtype k) op GRi CCi  cond ope GRj)
4196        (if (eq CCi (or cond 2))
4197            (sequence ((WI address))
4198                      (store-double-semantics mode regtype address GRj)))
4199        profile
4200   )
4201 )
4202
4203 (conditional-store-double cstd  DI OP_64 OPE4_3 GR NA
4204                           ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4205                           "Store double word")
4206 (conditional-store-double cstdf DF OP_66 OPE4_3 FR FR-ACCESS
4207                           ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4208                           "Store double float")
4209
4210 (dni cstq
4211      "conditionally store quad word"
4212      ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) CONDITIONAL)
4213      "cstq$pack $GRk,@($GRi,$GRj),$CCi,$cond"
4214      (+ pack GRk OP_65 GRi CCi cond OPE4_0 GRj)
4215      (if (eq CCi (or cond 2))
4216          (sequence ((WI address))
4217                    (store-quad-semantics GR address GRj)))
4218      ((fr500 (unit u-gr-store)))
4219 )
4220
4221 (define-pmacro (conditional-store-u
4222                 name mode op ope regtype attr profile comment)
4223   (dni name
4224        (comment)
4225        ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) CONDITIONAL attr)
4226        (.str name "$pack $" regtype "k,@($GRi,$GRj),$CCi,$cond")
4227        (+ pack (.sym regtype k) op GRi CCi  cond ope GRj)
4228        (if (eq CCi (or cond 2))
4229            (sequence ((WI address))
4230                      (set address (add GRi GRj))
4231                      (c-call VOID (.str "@cpu@_write_mem_" mode)
4232                              pc address (.sym regtype k))
4233                      (set GRi address)))
4234        profile
4235   )
4236 )
4237
4238 (conditional-store-u cstbu QI OP_67 OPE4_0 GR NA
4239                      ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4240                      "Store unsigned byte, update index")
4241 (conditional-store-u csthu HI OP_67 OPE4_1 GR NA
4242                      ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4243                      "Store unsigned half, update index")
4244 (conditional-store-u cstu  SI OP_67 OPE4_2 GR NA
4245                      ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4246                      "Store          word, update index")
4247
4248 (conditional-store-u cstbfu QI OP_68 OPE4_0 FRint FR-ACCESS
4249                      ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4250                      "Store byte float, update index")
4251 (conditional-store-u csthfu HI OP_68 OPE4_1 FRint FR-ACCESS
4252                      ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4253                      "Store half float, update index")
4254 (conditional-store-u cstfu  SI OP_68 OPE4_2 FRint FR-ACCESS
4255                      ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4256                      "Store word float, update index")
4257
4258 (define-pmacro (conditional-store-double-u
4259                 name mode op ope regtype attr profile comment)
4260   (dni name
4261        (comment)
4262        ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) CONDITIONAL attr)
4263        (.str name "$pack $" regtype "k,@($GRi,$GRj),$CCi,$cond")
4264        (+ pack (.sym regtype k) op GRi CCi  cond ope GRj)
4265        (if (eq CCi (or cond 2))
4266            (sequence ((WI address))
4267                      (store-double-semantics mode regtype address GRj)
4268                      (set GRi address)))
4269        profile
4270   )
4271 )
4272
4273 (conditional-store-double-u cstdu  DI OP_67 OPE4_3 GR NA
4274                             ((fr400 (unit u-gr-store))
4275                              (fr500 (unit u-gr-store)))
4276                             "Store double word, update index")
4277 (conditional-store-double-u cstdfu DF OP_68 OPE4_3 FR FR-ACCESS
4278                             ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4279                             "Store double float, update index")
4280
4281 (define-pmacro (store-r-simm name mode op regtype attr profile comment)
4282   (dni name
4283        (comment)
4284        ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
4285        (.str name "$pack $" regtype "k,@($GRi,$d12)")
4286        (+ pack (.sym regtype k) op GRi d12)
4287        (c-call VOID (.str "@cpu@_write_mem_" mode)
4288                pc (add GRi d12) (.sym regtype k))
4289        profile
4290   )
4291 )
4292
4293 (store-r-simm stbi QI OP_50 GR NA
4294               ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4295               "Store unsigned byte")
4296 (store-r-simm sthi HI OP_51 GR NA
4297               ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4298               "Store unsigned half")
4299 (store-r-simm sti  SI OP_52 GR NA
4300               ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4301               "Store          word")
4302
4303 (store-r-simm stbfi QI OP_4E FRint FR-ACCESS
4304               ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4305               "Store byte float")
4306 (store-r-simm sthfi HI OP_4F FRint FR-ACCESS
4307               ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4308               "Store half float")
4309 (store-r-simm stfi  SI OP_55 FRint FR-ACCESS
4310               ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4311               "Store word float")
4312
4313 (define-pmacro (store-double-r-simm name mode op regtype attr profile comment)
4314   (dni name
4315        (comment)
4316        ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
4317        (.str name "$pack $" regtype "k,@($GRi,$d12)")
4318        (+ pack (.sym regtype k) op GRi d12)
4319        (sequence ((WI address))
4320                  (store-double-semantics mode regtype address d12))
4321        profile
4322   )
4323 )
4324
4325 (store-double-r-simm stdi  DI OP_53 GR NA
4326                      ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
4327                      "Store double word")
4328 (store-double-r-simm stdfi DF OP_56 FR FR-ACCESS
4329                      ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
4330                      "Store double float")
4331
4332 (define-pmacro (store-quad-r-simm name op regtype attr profile comment)
4333   (dni name
4334        (comment)
4335        ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) attr)
4336        (.str name "$pack $" regtype "k,@($GRi,$d12)")
4337        (+ pack (.sym regtype k) op GRi d12)
4338        (sequence ((WI address))
4339                  (store-quad-semantics regtype address d12))
4340        profile
4341   )
4342 )
4343
4344 (store-quad-r-simm stqi  OP_54 GR    NA ((fr500 (unit u-gr-store)))
4345                    "Store quad word")
4346 (store-quad-r-simm stqfi OP_57 FRint FR-ACCESS ()
4347                    "Store quad float")
4348
4349 (define-pmacro (swap-semantics base offset arg)
4350   (sequence ((WI tmp) (WI address))
4351             (set tmp arg)
4352             (set address (add base offset))
4353             (set arg (c-call WI "@cpu@_read_mem_WI" pc address))
4354             (c-call VOID "@cpu@_write_mem_WI" pc address tmp))
4355 )
4356
4357 (dni swap
4358      "Swap contents of memory with GR"
4359      ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
4360      "swap$pack @($GRi,$GRj),$GRk"
4361      (+ pack GRk OP_03 GRi OPE1_05 GRj)
4362      (swap-semantics GRi GRj GRk)
4363      ((fr400 (unit u-swap))
4364       (fr500 (unit u-swap)))
4365 )
4366
4367 (dni "swapi"
4368      "Swap contents of memory with GR"
4369      ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
4370      ("swapi$pack @($GRi,$d12),$GRk")
4371      (+ pack GRk OP_4D GRi d12)
4372      (swap-semantics GRi d12 GRk)
4373      ((fr400 (unit u-swap))
4374       (fr500 (unit u-swap)))
4375 )
4376
4377 (dni cswap
4378      "Conditionally swap contents of memory with GR"
4379      ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2) CONDITIONAL)
4380      "cswap$pack @($GRi,$GRj),$GRk,$CCi,$cond"
4381      (+ pack GRk OP_65 GRi CCi cond OPE4_2 GRj)
4382      (if (eq CCi (or cond 2))
4383          (swap-semantics GRi GRj GRk))
4384      ((fr400 (unit u-swap))
4385       (fr500 (unit u-swap)))
4386 )
4387
4388 (define-pmacro (register-transfer
4389                 name op ope reg_src reg_targ pipe major1 major2 attr1 attr2
4390                 profile comment)
4391   (dni name
4392        (comment)
4393        ((UNIT pipe) major1 major2 attr1 attr2)
4394        (.str name "$pack $" reg_src ",$" reg_targ)
4395        (+ pack reg_targ op (rs-null) ope reg_src)
4396        (set reg_targ reg_src)
4397        profile
4398   )
4399 )
4400
4401 (register-transfer movgf OP_03 OPE1_15
4402                    GRj FRintk I0 (FR500-MAJOR I-4) (FR400-MAJOR I-4)
4403                    FR-ACCESS NA
4404                    ((fr400 (unit u-gr2fr)) (fr500 (unit u-gr2fr)))
4405                    "transfer gr to fr")
4406 (register-transfer movfg OP_03 OPE1_0D
4407                    FRintk GRj I0 (FR500-MAJOR I-4) (FR400-MAJOR I-4)
4408                    FR-ACCESS NA
4409                    ((fr400 (unit u-fr2gr)) (fr500 (unit u-fr2gr)))
4410                    "transfer fr to gr")
4411
4412 (define-pmacro (nextreg hw r offset) (reg hw (add (index-of r) offset)))
4413
4414 (define-pmacro (register-transfer-double-from-gr-semantics cond)
4415   (if cond
4416       (if (eq (index-of GRj) 0)
4417           (sequence ()
4418                     (set FRintk 0)
4419                     (set (nextreg h-fr_int FRintk 1) 0))
4420           (sequence ()
4421                     (set FRintk GRj)
4422                     (set (nextreg h-fr_int FRintk 1) (nextreg h-gr GRj 1)))))
4423 )
4424
4425 (dni movgfd
4426      "move GR for FR double"
4427      ((UNIT I0) (FR500-MAJOR I-4) (FR400-MAJOR I-4) FR-ACCESS)
4428      "movgfd$pack $GRj,$FRintk"
4429      (+ pack FRintk OP_03 (rs-null) OPE1_16 GRj)
4430      (register-transfer-double-from-gr-semantics 1)
4431      ; TODO -- doesn't handle second register in the pair
4432      ((fr400 (unit u-gr2fr))
4433       (fr500 (unit u-gr2fr)))
4434 )
4435
4436 (define-pmacro (register-transfer-double-to-gr-semantics cond)
4437   (if (andif (ne (index-of GRj) 0) cond)
4438       (sequence ()
4439                 (set GRj FRintk)
4440                 (set (nextreg h-gr GRj 1) (nextreg h-fr_int FRintk 1))))
4441 )
4442
4443 (dni movfgd
4444      "move FR for GR double"
4445      ((UNIT I0) (FR500-MAJOR I-4) (FR400-MAJOR I-4) FR-ACCESS)
4446      "movfgd$pack $FRintk,$GRj"
4447      (+ pack FRintk OP_03 (rs-null) OPE1_0E GRj)
4448      (register-transfer-double-to-gr-semantics 1)
4449      ; TODO -- doesn't handle second register in the pair
4450      ((fr400 (unit u-fr2gr))
4451       (fr500 (unit u-fr2gr)))
4452 )
4453
4454 (dni movgfq
4455      "move GR for FR quad"
4456      ((UNIT I0) (FR500-MAJOR I-4) (MACH frv) FR-ACCESS)
4457      "movgfq$pack $GRj,$FRintk"
4458      (+ pack FRintk OP_03 (rs-null) OPE1_17 GRj)
4459      (if (eq (index-of GRj) 0)
4460          (sequence ()
4461                    (set FRintk 0)
4462                    (set (reg h-fr_int (add (index-of FRintk) 1)) 0)
4463                    (set (reg h-fr_int (add (index-of FRintk) 2)) 0)
4464                    (set (reg h-fr_int (add (index-of FRintk) 3)) 0))
4465          (sequence ()
4466                    (set FRintk GRj)
4467                    (set (reg h-fr_int (add (index-of FRintk) 1))
4468                         (reg h-gr (add (index-of GRj)    1)))
4469                    (set (reg h-fr_int (add (index-of FRintk) 2))
4470                         (reg h-gr (add (index-of GRj)    2)))
4471                    (set (reg h-fr_int (add (index-of FRintk) 3))
4472                         (reg h-gr (add (index-of GRj)    3)))))
4473      ()
4474 )
4475
4476 (dni movfgq
4477      "move FR for GR quad"
4478      ((UNIT I0) (FR500-MAJOR I-4) (MACH frv) FR-ACCESS)
4479      "movfgq$pack $FRintk,$GRj"
4480      (+ pack FRintk OP_03 (rs-null) OPE1_0F GRj)
4481      (if (ne (index-of GRj) 0)
4482          (sequence ()
4483                    (set GRj FRintk)
4484                    (set (reg h-gr (add (index-of GRj)    1))
4485                         (reg h-fr_int (add (index-of FRintk) 1)))
4486                    (set (reg h-gr (add (index-of GRj)    2))
4487                         (reg h-fr_int (add (index-of FRintk) 2)))
4488                    (set (reg h-gr (add (index-of GRj)    3))
4489                         (reg h-fr_int (add (index-of FRintk) 3)))))
4490      ()
4491 )
4492
4493 (define-pmacro (conditional-register-transfer
4494                 name op ope reg_src reg_targ pipe major1 major2 mach
4495                 profile comment)
4496   (dni name
4497        (comment)
4498        ((UNIT pipe) major1 major2 CONDITIONAL FR-ACCESS mach)
4499        (.str name "$pack $" reg_src ",$" reg_targ ",$CCi,$cond")
4500        (+ pack reg_targ op (rs-null) CCi cond ope reg_src)
4501        (if (eq CCi (or cond 2))
4502            (set reg_targ reg_src))
4503        profile
4504   )
4505 )
4506
4507 (conditional-register-transfer cmovgf OP_69 OPE4_0 GRj FRintk I0
4508                                (FR500-MAJOR I-4) (FR400-MAJOR I-4)
4509                                NA
4510                                ((fr400 (unit u-gr2fr)) (fr500 (unit u-gr2fr)))
4511                                "transfer gr to fr")
4512 (conditional-register-transfer cmovfg OP_69 OPE4_2 FRintk GRj I0
4513                                (FR500-MAJOR I-4) (FR400-MAJOR I-4)
4514                                NA
4515                                ((fr400 (unit u-fr2gr)) (fr500 (unit u-fr2gr)))
4516                                "transfer fr to gr")
4517
4518
4519 (dni cmovgfd
4520      "Conditional move GR to FR double"
4521      ((UNIT I0) (FR500-MAJOR I-4) (FR400-MAJOR I-4) CONDITIONAL FR-ACCESS)
4522      "cmovgfd$pack $GRj,$FRintk,$CCi,$cond"
4523      (+ pack FRintk OP_69 (rs-null) CCi cond OPE4_1 GRj)
4524      (register-transfer-double-from-gr-semantics (eq CCi (or cond 2)))
4525      ; TODO -- doesn't handle extra registers in double
4526      ((fr400 (unit u-gr2fr))
4527       (fr500 (unit u-gr2fr)))
4528 )
4529
4530 (dni cmovfgd
4531      "Conditional move FR to GR double"
4532      ((UNIT I0) (FR500-MAJOR I-4) (FR400-MAJOR I-4) CONDITIONAL FR-ACCESS)
4533      "cmovfgd$pack $FRintk,$GRj,$CCi,$cond"
4534      (+ pack FRintk OP_69 (rs-null) CCi cond OPE4_3 GRj)
4535      (register-transfer-double-to-gr-semantics (eq CCi (or cond 2)))
4536      ; TODO -- doesn't handle second register in the pair
4537      ((fr400 (unit u-fr2gr))
4538       (fr500 (unit u-fr2gr)))
4539 )
4540
4541 (define-pmacro (register-transfer-spr
4542                 name op ope reg_src reg_targ unitname comment)
4543   (dni name
4544        (comment)
4545        ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
4546        (.str name "$pack $" reg_src ",$" reg_targ)
4547        (+ pack reg_targ op ope reg_src)
4548        (set reg_targ reg_src)
4549        ((fr400 (unit unitname))
4550         (fr500 (unit unitname)))
4551   )
4552 )
4553
4554 (register-transfer-spr movgs OP_03 OPE1_06 GRj spr u-gr2spr "transfer gr->spr")
4555 (register-transfer-spr movsg OP_03 OPE1_07 spr GRj u-spr2gr "transfer spr->gr")
4556
4557 ; Integer Branch Conditions
4558 (define-pmacro (Inev cc) (const BI 0))
4559 (define-pmacro (Ira  cc) (const BI 1))
4560 (define-pmacro (Ieq  cc) (     zbit cc))
4561 (define-pmacro (Ine  cc) (not (zbit cc)))
4562 (define-pmacro (Ile  cc) (     orif (zbit cc) (xor (nbit cc) (vbit cc))))
4563 (define-pmacro (Igt  cc) (not (orif (zbit cc) (xor (nbit cc) (vbit cc)))))
4564 (define-pmacro (Ilt  cc) (     xor  (nbit cc) (vbit cc)))
4565 (define-pmacro (Ige  cc) (not (xor  (nbit cc) (vbit cc))))
4566 (define-pmacro (Ils  cc) (     orif (cbit cc) (zbit cc)))
4567 (define-pmacro (Ihi  cc) (not (orif (cbit cc) (zbit cc))))
4568 (define-pmacro (Ic   cc) (     cbit cc))
4569 (define-pmacro (Inc  cc) (not (cbit cc)))
4570 (define-pmacro (In   cc) (     nbit cc))
4571 (define-pmacro (Ip   cc) (not (nbit cc)))
4572 (define-pmacro (Iv   cc) (     vbit cc))
4573 (define-pmacro (Inv  cc) (not (vbit cc)))
4574
4575 ; Float Branch Conditions
4576 (define-pmacro (Fnev cc) (const BI 0))
4577 (define-pmacro (Fra  cc) (const BI 1))
4578 (define-pmacro (Fne  cc) (orif (lbit cc) (orif (gbit cc) (ubit cc))))
4579 (define-pmacro (Feq  cc) (ebit cc))
4580 (define-pmacro (Flg  cc) (orif (lbit cc) (gbit cc)))
4581 (define-pmacro (Fue  cc) (orif (ebit cc) (ubit cc)))
4582 (define-pmacro (Ful  cc) (orif (lbit cc) (ubit cc)))
4583 (define-pmacro (Fge  cc) (orif (ebit cc) (gbit cc)))
4584 (define-pmacro (Flt  cc) (lbit cc))
4585 (define-pmacro (Fuge cc) (orif (ebit cc) (orif (gbit cc) (ubit cc))))
4586 (define-pmacro (Fug  cc) (orif (gbit cc) (ubit cc)))
4587 (define-pmacro (Fle  cc) (orif (ebit cc) (lbit cc)))
4588 (define-pmacro (Fgt  cc) (gbit cc))
4589 (define-pmacro (Fule cc) (orif (ebit cc) (orif (lbit cc) (ubit cc))))
4590 (define-pmacro (Fu   cc) (ubit cc))
4591 (define-pmacro (Fo   cc) (orif (ebit cc) (orif (lbit cc) (gbit cc))))
4592
4593 (define-pmacro (conditional-branch-i prefix cc op cond comment)
4594   (dni (.sym prefix cc)
4595        (comment)
4596        ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1))
4597        (.str (.sym prefix cc) "$pack $ICCi_2,$hint,$label16")
4598        (+ pack (.sym ICC_ cc) ICCi_2 op hint label16)
4599        (sequence ()
4600                  (c-call VOID "@cpu@_model_branch" label16 hint)
4601                  (if (cond ICCi_2)
4602                      (set pc label16)))
4603        ((fr400 (unit u-branch))
4604         (fr500 (unit u-branch)))
4605   )
4606 )
4607
4608 (dni bra
4609      "integer branch equal"
4610       ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1))
4611       "bra$pack $hint_taken$label16"
4612       (+ pack ICC_ra (ICCi_2-null) OP_06 hint_taken label16)
4613       (sequence ()
4614                 (c-call VOID "@cpu@_model_branch" label16 hint_taken)
4615                 (set pc label16))
4616       ((fr400 (unit u-branch))
4617        (fr500 (unit u-branch)))
4618 )
4619
4620 (dni bno
4621      "integer branch never"
4622       ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1))
4623       "bno$pack$hint_not_taken"
4624       (+ pack ICC_nev (ICCi_2-null) OP_06 hint_not_taken (label16-null))
4625       (c-call VOID "@cpu@_model_branch" label16 hint_not_taken)
4626       ((fr400 (unit u-branch))
4627        (fr500 (unit u-branch)))
4628 )
4629
4630 (conditional-branch-i b eq  OP_06 Ieq  "integer branch equal")
4631 (conditional-branch-i b ne  OP_06 Ine  "integer branch not equal")
4632 (conditional-branch-i b le  OP_06 Ile  "integer branch less or equal")
4633 (conditional-branch-i b gt  OP_06 Igt  "integer branch greater")
4634 (conditional-branch-i b lt  OP_06 Ilt  "integer branch less")
4635 (conditional-branch-i b ge  OP_06 Ige  "integer branch greater or equal")
4636 (conditional-branch-i b ls  OP_06 Ils  "integer branch less or equal unsigned")
4637 (conditional-branch-i b hi  OP_06 Ihi  "integer branch greater unsigned")
4638 (conditional-branch-i b c   OP_06 Ic   "integer branch carry set")
4639 (conditional-branch-i b nc  OP_06 Inc  "integer branch carry clear")
4640 (conditional-branch-i b n   OP_06 In   "integer branch negative")
4641 (conditional-branch-i b p   OP_06 Ip   "integer branch positive")
4642 (conditional-branch-i b v   OP_06 Iv   "integer branch overflow set")
4643 (conditional-branch-i b nv  OP_06 Inv  "integer branch overflow clear")
4644
4645 (define-pmacro (conditional-branch-f prefix cc op cond comment)
4646   (dni (.sym prefix cc)
4647        (comment)
4648        ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1) FR-ACCESS)
4649        (.str (.sym prefix cc) "$pack $FCCi_2,$hint,$label16")
4650        (+ pack (.sym FCC_ cc) FCCi_2 op hint label16)
4651        (sequence ()
4652                  (c-call VOID "@cpu@_model_branch" label16 hint)
4653                  (if (cond FCCi_2) (set pc label16)))
4654        ((fr400 (unit u-branch))
4655         (fr500 (unit u-branch)))
4656   )
4657 )
4658
4659 (dni fbra
4660      "float branch equal"
4661       ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1) FR-ACCESS)
4662       "fbra$pack $hint_taken$label16"
4663       (+ pack FCC_ra (FCCi_2-null) OP_07 hint_taken label16)
4664       (sequence ()
4665                 (c-call VOID "@cpu@_model_branch" label16 hint_taken)
4666                 (set pc label16))
4667       ((fr400 (unit u-branch))
4668        (fr500 (unit u-branch)))
4669 )
4670
4671 (dni fbno
4672      "float branch never"
4673       ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1) FR-ACCESS)
4674       "fbno$pack$hint_not_taken"
4675       (+ pack FCC_nev (FCCi_2-null) OP_07 hint_not_taken (label16-null))
4676       (c-call VOID "@cpu@_model_branch" label16 hint_not_taken)
4677       ((fr400 (unit u-branch))
4678        (fr500 (unit u-branch)))
4679 )
4680
4681 (conditional-branch-f fb ne  OP_07 Fne  "float branch not equal")
4682 (conditional-branch-f fb eq  OP_07 Feq  "float branch equal")
4683 (conditional-branch-f fb lg  OP_07 Flg  "float branch less or greater")
4684 (conditional-branch-f fb ue  OP_07 Fue  "float branch unordered or equal")
4685 (conditional-branch-f fb ul  OP_07 Ful  "float branch unordered or less")
4686 (conditional-branch-f fb ge  OP_07 Fge  "float branch greater or equal")
4687 (conditional-branch-f fb lt  OP_07 Flt  "float branch less")
4688 (conditional-branch-f fb uge OP_07 Fuge "float branch unordered, greater,equal")
4689 (conditional-branch-f fb ug  OP_07 Fug  "float branch unordered or greater")
4690 (conditional-branch-f fb le  OP_07 Fle  "float branch less or equal")
4691 (conditional-branch-f fb gt  OP_07 Fgt  "float branch greater")
4692 (conditional-branch-f fb ule OP_07 Fule "float branch unordered, less or equal")
4693 (conditional-branch-f fb u   OP_07 Fu   "float branch unordered")
4694 (conditional-branch-f fb o   OP_07 Fo   "float branch ordered")
4695
4696 (define-pmacro (ctrlr-branch-semantics cond ccond)
4697   (sequence ((SI tmp))
4698             (set tmp (sub (spr-lcr) 1))
4699             (set (spr-lcr) tmp)
4700             (if cond
4701                 (if (eq ccond 0)
4702                     (if (ne tmp 0)
4703                         (set pc (spr-lr)))
4704                     (if (eq tmp 0)
4705                         (set pc (spr-lr))))))
4706 )
4707
4708 (dni bctrlr
4709      "LCR conditional branch to lr"
4710      ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2))
4711      ("bctrlr$pack $ccond,$hint")
4712      (+ pack (cond-null) (ICCi_2-null) OP_0E hint OPE3_01 ccond (s12-null))
4713      (sequence ()
4714                (c-call VOID "@cpu@_model_branch" (spr-lr) hint)
4715                (ctrlr-branch-semantics (const BI 1) ccond))
4716      ((fr400 (unit u-branch))
4717       (fr500 (unit u-branch)))
4718 )
4719
4720 (define-pmacro (conditional-branch-cclr prefix cc i-f op ope cond attr comment)
4721   (dni (.sym prefix cc lr)
4722        (comment)
4723        ((UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3) attr)
4724        (.str (.sym prefix cc lr) "$pack $" i-f "CCi_2,$hint")
4725        (+ pack (.sym i-f CC_ cc) (.sym i-f CCi_2) op hint ope
4726           (ccond-null) (s12-null))
4727        (sequence ()
4728                  (c-call VOID "@cpu@_model_branch" (spr-lr) hint)
4729                  (if (cond (.sym i-f CCi_2)) (set pc (spr-lr))))
4730        ((fr400 (unit u-branch))
4731         (fr500 (unit u-branch)))
4732   )
4733 )
4734
4735 (dni bralr
4736      "integer cclr branch always"
4737      ((UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3))
4738      "bralr$pack$hint_taken"
4739      (+ pack ICC_ra (ICCi_2-null) OP_0E hint_taken OPE3_02 (ccond-null) (s12-null))
4740      (sequence ()
4741                (c-call VOID "@cpu@_model_branch" (spr-lr) hint_taken)
4742                (set pc (spr-lr)))
4743      ((fr400 (unit u-branch))
4744       (fr500 (unit u-branch)))
4745 )
4746
4747 (dni bnolr
4748      "integer cclr branch never"
4749      ((UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3))
4750      "bnolr$pack$hint_not_taken"
4751      (+ pack ICC_nev (ICCi_2-null) OP_0E hint_not_taken OPE3_02 (ccond-null) (s12-null))
4752      (c-call VOID "@cpu@_model_branch" (spr-lr) hint_not_taken)
4753      ((fr400 (unit u-branch))
4754       (fr500 (unit u-branch)))
4755 )
4756
4757 (conditional-branch-cclr b eq  I OP_0E OPE3_02 Ieq  NA "integer cclr branch equal")
4758 (conditional-branch-cclr b ne  I OP_0E OPE3_02 Ine  NA "integer cclr branch not equal")
4759 (conditional-branch-cclr b le  I OP_0E OPE3_02 Ile  NA "integer cclr branch less or equal")
4760 (conditional-branch-cclr b gt  I OP_0E OPE3_02 Igt  NA "integer cclr branch greater")
4761 (conditional-branch-cclr b lt  I OP_0E OPE3_02 Ilt  NA "integer cclr branch less")
4762 (conditional-branch-cclr b ge  I OP_0E OPE3_02 Ige  NA "integer cclr branch greater or equal")
4763 (conditional-branch-cclr b ls  I OP_0E OPE3_02 Ils  NA "integer cclr branch less or equal unsigned")
4764 (conditional-branch-cclr b hi  I OP_0E OPE3_02 Ihi  NA "integer cclr branch greater unsigned")
4765 (conditional-branch-cclr b c   I OP_0E OPE3_02 Ic   NA "integer cclr branch carry set")
4766 (conditional-branch-cclr b nc  I OP_0E OPE3_02 Inc  NA "integer cclr branch carry clear")
4767 (conditional-branch-cclr b n   I OP_0E OPE3_02 In   NA "integer cclr branch negative")
4768 (conditional-branch-cclr b p   I OP_0E OPE3_02 Ip   NA "integer cclr branch positive")
4769 (conditional-branch-cclr b v   I OP_0E OPE3_02 Iv   NA "integer cclr branch overflow set")
4770 (conditional-branch-cclr b nv  I OP_0E OPE3_02 Inv  NA "integer cclr branch overflow clear")
4771
4772 (dni fbralr
4773      "float cclr branch always"
4774      ((UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3) FR-ACCESS)
4775      "fbralr$pack$hint_taken"
4776      (+ pack FCC_ra (FCCi_2-null) OP_0E hint_taken OPE3_06 (ccond-null) (s12-null))
4777      (sequence ()
4778                (c-call VOID "@cpu@_model_branch" (spr-lr) hint_taken)
4779                (set pc (spr-lr)))
4780      ((fr400 (unit u-branch))
4781       (fr500 (unit u-branch)))
4782 )
4783
4784 (dni fbnolr
4785      "float cclr branch never"
4786      ((UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3) FR-ACCESS)
4787      "fbnolr$pack$hint_not_taken"
4788      (+ pack FCC_nev (FCCi_2-null) OP_0E hint_not_taken OPE3_06 (ccond-null) (s12-null))
4789      (c-call VOID "@cpu@_model_branch" (spr-lr) hint_not_taken)
4790      ((fr400 (unit u-branch))
4791       (fr500 (unit u-branch)))
4792 )
4793
4794 (conditional-branch-cclr fb eq  F OP_0E OPE3_06 Feq  FR-ACCESS "float cclr branch equal")
4795 (conditional-branch-cclr fb ne  F OP_0E OPE3_06 Fne  FR-ACCESS "float cclr branch not equal")
4796 (conditional-branch-cclr fb lg  F OP_0E OPE3_06 Flg  FR-ACCESS "float branch less or greater")
4797 (conditional-branch-cclr fb ue  F OP_0E OPE3_06 Fue  FR-ACCESS "float branch unordered or equal")
4798 (conditional-branch-cclr fb ul  F OP_0E OPE3_06 Ful  FR-ACCESS "float branch unordered or less")
4799 (conditional-branch-cclr fb ge  F OP_0E OPE3_06 Fge  FR-ACCESS "float branch greater or equal")
4800 (conditional-branch-cclr fb lt  F OP_0E OPE3_06 Flt  FR-ACCESS "float branch less")
4801 (conditional-branch-cclr fb uge F OP_0E OPE3_06 Fuge FR-ACCESS "float branch unordered, greater, equal")
4802 (conditional-branch-cclr fb ug  F OP_0E OPE3_06 Fug  FR-ACCESS "float branch unordered or greater")
4803 (conditional-branch-cclr fb le  F OP_0E OPE3_06 Fle  FR-ACCESS "float branch less or equal")
4804 (conditional-branch-cclr fb gt  F OP_0E OPE3_06 Fgt  FR-ACCESS "float branch greater")
4805 (conditional-branch-cclr fb ule F OP_0E OPE3_06 Fule FR-ACCESS "float branch unordered, less or equal")
4806 (conditional-branch-cclr fb u   F OP_0E OPE3_06 Fu   FR-ACCESS "float branch unordered")
4807 (conditional-branch-cclr fb o   F OP_0E OPE3_06 Fo   FR-ACCESS "float branch ordered")
4808
4809 (define-pmacro (conditional-branch-ctrlr prefix cc i-f op ope cond attr comment)
4810   (dni (.sym prefix cc lr)
4811        (comment)
4812        ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2) attr)
4813        (.str (.sym prefix cc lr) "$pack $" i-f "CCi_2,$ccond,$hint")
4814        (+ pack (.sym i-f CC_ cc) (.sym i-f CCi_2) op hint ope ccond (s12-null))
4815        (sequence ()
4816                  (c-call VOID "@cpu@_model_branch" (spr-lr) hint)
4817                  (ctrlr-branch-semantics (cond (.sym i-f CCi_2)) ccond))
4818        ((fr400 (unit u-branch))
4819         (fr500 (unit u-branch)))
4820   )
4821 )
4822
4823 (dni bcralr
4824      "integer ctrlr branch always"
4825      ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2))
4826      "bcralr$pack $ccond$hint_taken"
4827      (+ pack ICC_ra (ICCi_2-null) OP_0E hint_taken OPE3_03 ccond (s12-null))
4828      (sequence ()
4829                (c-call VOID "@cpu@_model_branch" (spr-lr) hint_taken)
4830                (ctrlr-branch-semantics (const BI 1) ccond))
4831      ((fr400 (unit u-branch))
4832       (fr500 (unit u-branch)))
4833 )
4834
4835 (dni bcnolr
4836      "integer ctrlr branch never"
4837      ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2))
4838      "bcnolr$pack$hint_not_taken"
4839      (+ pack ICC_nev (ICCi_2-null) OP_0E hint_not_taken OPE3_03 (ccond-null) (s12-null))
4840      (sequence ()
4841                (c-call VOID "@cpu@_model_branch" (spr-lr) hint_not_taken)
4842                (ctrlr-branch-semantics (const BI 0) ccond))
4843      ((fr400 (unit u-branch))
4844       (fr500 (unit u-branch)))
4845 )
4846
4847 (conditional-branch-ctrlr bc eq  I OP_0E OPE3_03 Ieq  NA "integer ctrlr branch equal")
4848 (conditional-branch-ctrlr bc ne  I OP_0E OPE3_03 Ine  NA "integer ctrlr branch not equal")
4849 (conditional-branch-ctrlr bc le  I OP_0E OPE3_03 Ile  NA "integer ctrlr branch less equal")
4850 (conditional-branch-ctrlr bc gt  I OP_0E OPE3_03 Igt  NA "integer ctrlr branch greater")
4851 (conditional-branch-ctrlr bc lt  I OP_0E OPE3_03 Ilt  NA "integer ctrlr branch less")
4852 (conditional-branch-ctrlr bc ge  I OP_0E OPE3_03 Ige  NA "integer ctrlr branch greater equal")
4853 (conditional-branch-ctrlr bc ls  I OP_0E OPE3_03 Ils  NA "integer ctrlr branch less equal unsigned")
4854 (conditional-branch-ctrlr bc hi  I OP_0E OPE3_03 Ihi  NA "integer ctrlr branch greater unsigned")
4855 (conditional-branch-ctrlr bc c   I OP_0E OPE3_03 Ic   NA "integer ctrlr branch carry set")
4856 (conditional-branch-ctrlr bc nc  I OP_0E OPE3_03 Inc  NA "integer ctrlr branch carry clear")
4857 (conditional-branch-ctrlr bc n   I OP_0E OPE3_03 In   NA "integer ctrlr branch negative")
4858 (conditional-branch-ctrlr bc p   I OP_0E OPE3_03 Ip   NA "integer ctrlr branch positive")
4859 (conditional-branch-ctrlr bc v   I OP_0E OPE3_03 Iv   NA "integer ctrlr branch overflow set")
4860 (conditional-branch-ctrlr bc nv  I OP_0E OPE3_03 Inv  NA "integer ctrlr branch overflow clear")
4861
4862 (dni fcbralr
4863      "float ctrlr branch always"
4864      ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2) FR-ACCESS)
4865      "fcbralr$pack $ccond$hint_taken"
4866      (+ pack FCC_ra (FCCi_2-null) OP_0E hint_taken OPE3_07 ccond (s12-null))
4867      (sequence ()
4868                (c-call VOID "@cpu@_model_branch" (spr-lr) hint_taken)
4869                (ctrlr-branch-semantics (const BI 1) ccond))
4870      ((fr400 (unit u-branch))
4871       (fr500 (unit u-branch)))
4872 )
4873
4874 (dni fcbnolr
4875      "float ctrlr branch never"
4876      ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2) FR-ACCESS)
4877      "fcbnolr$pack$hint_not_taken"
4878      (+ pack FCC_nev (FCCi_2-null) OP_0E hint_not_taken OPE3_07 (ccond-null) (s12-null))
4879      (sequence ()
4880                (c-call VOID "@cpu@_model_branch" (spr-lr) hint_not_taken)
4881                (ctrlr-branch-semantics (const BI 0) ccond))
4882      ((fr400 (unit u-branch))
4883       (fr500 (unit u-branch)))
4884 )
4885
4886 (conditional-branch-ctrlr fcb eq  F OP_0E OPE3_07 Feq  FR-ACCESS "float cclr branch equal")
4887 (conditional-branch-ctrlr fcb ne  F OP_0E OPE3_07 Fne  FR-ACCESS "float cclr branch not equal")
4888 (conditional-branch-ctrlr fcb lg  F OP_0E OPE3_07 Flg  FR-ACCESS "float branch less or greater")
4889 (conditional-branch-ctrlr fcb ue  F OP_0E OPE3_07 Fue  FR-ACCESS "float branch unordered or equal")
4890 (conditional-branch-ctrlr fcb ul  F OP_0E OPE3_07 Ful  FR-ACCESS "float branch unordered or less")
4891 (conditional-branch-ctrlr fcb ge  F OP_0E OPE3_07 Fge  FR-ACCESS "float branch greater or equal")
4892 (conditional-branch-ctrlr fcb lt  F OP_0E OPE3_07 Flt  FR-ACCESS "float branch less")
4893 (conditional-branch-ctrlr fcb uge F OP_0E OPE3_07 Fuge FR-ACCESS "float branch unordered, greater, equal")
4894 (conditional-branch-ctrlr fcb ug  F OP_0E OPE3_07 Fug  FR-ACCESS "float branch unordered or greater")
4895 (conditional-branch-ctrlr fcb le  F OP_0E OPE3_07 Fle  FR-ACCESS "float branch less or equal")
4896 (conditional-branch-ctrlr fcb gt  F OP_0E OPE3_07 Fgt  FR-ACCESS "float branch greater")
4897 (conditional-branch-ctrlr fcb ule F OP_0E OPE3_07 Fule FR-ACCESS "float branch unordered, less or equal")
4898 (conditional-branch-ctrlr fcb u   F OP_0E OPE3_07 Fu   FR-ACCESS "float branch unordered")
4899 (conditional-branch-ctrlr fcb o   F OP_0E OPE3_07 Fo   FR-ACCESS "float branch ordered")
4900
4901 (define-pmacro (jump-and-link-semantics base offset LI)
4902   (sequence ()
4903             (if (eq LI 1)
4904                 (c-call VOID "@cpu@_set_write_next_vliw_addr_to_LR" 1))
4905             ; Target address gets aligned here
4906             (set pc (and (add base offset) #xfffffffc))
4907             (c-call VOID "@cpu@_model_branch" pc #x2)) ; hint branch taken
4908 )
4909
4910 (dni jmpl
4911      "jump and link"
4912      ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5))
4913      "jmpl$pack @($GRi,$GRj)"
4914      (+ pack (misc-null-1) (LI-off) OP_0C GRi (misc-null-2) GRj)
4915      (jump-and-link-semantics GRi GRj LI)
4916      ((fr400 (unit u-branch))
4917       (fr500 (unit u-branch)))
4918 )
4919
4920 (dni calll
4921      "call and link"
4922      ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5))
4923      "calll$pack @($GRi,$GRj)"
4924      (+ pack (misc-null-1) (LI-on) OP_0C GRi (misc-null-2) GRj)
4925      (jump-and-link-semantics GRi GRj LI)
4926      ((fr400 (unit u-branch))
4927       (fr500 (unit u-branch)))
4928 )
4929
4930 (dni jmpil
4931      "jump immediate and link"
4932      ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5))
4933      "jmpil$pack @($GRi,$s12)"
4934      (+ pack (misc-null-1) (LI-off) OP_0D GRi s12)
4935      (jump-and-link-semantics GRi s12 LI)
4936      ((fr400 (unit u-branch))
4937       (fr500 (unit u-branch)))
4938 )
4939
4940 (dni callil
4941      "call immediate and link"
4942      ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5))
4943      "callil$pack @($GRi,$s12)"
4944      (+ pack (misc-null-1) (LI-on) OP_0D GRi s12)
4945      (jump-and-link-semantics GRi s12 LI)
4946      ((fr400 (unit u-branch))
4947       (fr500 (unit u-branch)))
4948 )
4949
4950 (dni call
4951      "call and link"
4952      ((UNIT B0) (FR500-MAJOR B-4) (FR400-MAJOR B-4))
4953      "call$pack $label24"
4954      (+ pack OP_0F label24)
4955      (sequence ()
4956                (c-call VOID "@cpu@_set_write_next_vliw_addr_to_LR" 1)
4957                (set pc label24)
4958                (c-call VOID "@cpu@_model_branch" pc #x2)) ; hint branch taken
4959      ((fr400 (unit u-branch))
4960       (fr500 (unit u-branch)))
4961 )
4962
4963 (dni rett
4964     "return from trap"
4965     ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2) PRIVILEGED)
4966     "rett$pack $debug"
4967     (+ pack (misc-null-1) debug OP_05 (rs-null) (s12-null))
4968     ; frv_rett handles operating vs user mode
4969     (sequence ()
4970               (set pc (c-call UWI "frv_rett" pc debug))
4971               (c-call VOID "@cpu@_model_branch" pc #x2)) ; hint branch taken
4972     ()
4973 )
4974
4975 (dni rei
4976      "run exception instruction"
4977      ((UNIT C) (FR500-MAJOR C-1) (MACH frv) PRIVILEGED)
4978      "rei$pack $eir"
4979      (+ pack (rd-null) OP_37 eir (s12-null))
4980      (nop) ; for now
4981      ()
4982 )
4983
4984 (define-pmacro (trap-semantics cond base offset)
4985   (if cond
4986       (sequence ()
4987                 ; This is defered to frv_itrap because for the breakpoint
4988                 ; case we want to change as little of the machine state as
4989                 ; possible.
4990                 ;
4991                 ; PCSR=PC
4992                 ; PSR.PS=PSR.S
4993                 ; PSR.ET=0
4994                 ; if PSR.ESR==1
4995                 ;   SR0 through SR3=GR4 through GR7
4996                 ; TBR.TT=0x80 + ((GRi + s12) & 0x7f)
4997                 ; PC=TBR
4998                 ; We still should indicate what is modified by this insn.
4999                 (clobber (spr-pcsr))
5000                 (clobber psr_ps)
5001                 (clobber psr_et)
5002                 (clobber tbr_tt)
5003                 (if (ne psr_esr (const 0))
5004                     (sequence ()
5005                               (clobber (spr-sr0))
5006                               (clobber (spr-sr1))
5007                               (clobber (spr-sr2))
5008                               (clobber (spr-sr3))))
5009                 ; frv_itrap handles operating vs user mode
5010                 (c-call VOID "frv_itrap" pc base offset)))
5011 )
5012
5013 (define-pmacro (trap-r prefix cc i-f op ope cond attr comment)
5014   (dni (.sym prefix cc)
5015        (comment)
5016        ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) attr)
5017        (.str (.sym prefix cc) "$pack $" i-f "CCi_2,$GRi,$GRj")
5018        (+ pack (.sym i-f CC_ cc) (.sym i-f CCi_2) op GRi (misc-null-3) ope GRj)
5019        (trap-semantics (cond (.sym i-f CCi_2)) GRi GRj)
5020        ((fr400 (unit u-trap))
5021         (fr500 (unit u-trap)))
5022   )
5023 )
5024
5025 (dni tra
5026      "integer trap always"
5027      ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1))
5028      "tra$pack $GRi,$GRj"
5029      (+ pack ICC_ra (ICCi_2-null) OP_04 GRi (misc-null-3) OPE4_0 GRj)
5030      (trap-semantics (const BI 1) GRi GRj)
5031      ((fr400 (unit u-trap))
5032       (fr500 (unit u-trap)))
5033 )
5034
5035 (dni tno
5036      "integer trap never"
5037      ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1))
5038      "tno$pack"
5039      (+ pack ICC_nev (ICCi_2-null) OP_04 (GRi-null) (misc-null-3) OPE4_0 (GRj-null))
5040      (trap-semantics (const BI 0) GRi GRj)
5041      ((fr400 (unit u-trap))
5042       (fr500 (unit u-trap)))
5043 )
5044
5045 (trap-r t eq  I OP_04 OPE4_0 Ieq  NA "integer trap equal")
5046 (trap-r t ne  I OP_04 OPE4_0 Ine  NA "integer trap not equal")
5047 (trap-r t le  I OP_04 OPE4_0 Ile  NA "integer trap less or equal")
5048 (trap-r t gt  I OP_04 OPE4_0 Igt  NA "integer trap greater")
5049 (trap-r t lt  I OP_04 OPE4_0 Ilt  NA "integer trap less")
5050 (trap-r t ge  I OP_04 OPE4_0 Ige  NA "integer trap greater or equal")
5051 (trap-r t ls  I OP_04 OPE4_0 Ils  NA "integer trap less or equal unsigned")
5052 (trap-r t hi  I OP_04 OPE4_0 Ihi  NA "integer trap greater unsigned")
5053 (trap-r t c   I OP_04 OPE4_0 Ic   NA "integer trap carry set")
5054 (trap-r t nc  I OP_04 OPE4_0 Inc  NA "integer trap carry clear")
5055 (trap-r t n   I OP_04 OPE4_0 In   NA "integer trap negative")
5056 (trap-r t p   I OP_04 OPE4_0 Ip   NA "integer trap positive")
5057 (trap-r t v   I OP_04 OPE4_0 Iv   NA "integer trap overflow set")
5058 (trap-r t nv  I OP_04 OPE4_0 Inv  NA "integer trap overflow clear")
5059
5060 (dni ftra
5061      "float trap always"
5062      ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) FR-ACCESS)
5063      "ftra$pack $GRi,$GRj"
5064      (+ pack FCC_ra (FCCi_2-null) OP_04 GRi (misc-null-3) OPE4_1 GRj)
5065      (trap-semantics (const BI 1) GRi GRj)
5066      ((fr400 (unit u-trap))
5067       (fr500 (unit u-trap)))
5068 )
5069
5070 (dni ftno
5071      "flost trap never"
5072      ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) FR-ACCESS)
5073      "ftno$pack"
5074      (+ pack FCC_nev (FCCi_2-null) OP_04 (GRi-null) (misc-null-3) OPE4_1 (GRj-null))
5075      (trap-semantics (const BI 0) GRi GRj)
5076      ((fr400 (unit u-trap))
5077       (fr500 (unit u-trap)))
5078 )
5079
5080 (trap-r ft ne  F OP_04 OPE4_1 Fne  FR-ACCESS "float trap not equal")
5081 (trap-r ft eq  F OP_04 OPE4_1 Feq  FR-ACCESS "float trap equal")
5082 (trap-r ft lg  F OP_04 OPE4_1 Flg  FR-ACCESS "float trap greater or less")
5083 (trap-r ft ue  F OP_04 OPE4_1 Fue  FR-ACCESS "float trap unordered or equal")
5084 (trap-r ft ul  F OP_04 OPE4_1 Ful  FR-ACCESS "float trap unordered or less")
5085 (trap-r ft ge  F OP_04 OPE4_1 Fge  FR-ACCESS "float trap greater or equal")
5086 (trap-r ft lt  F OP_04 OPE4_1 Flt  FR-ACCESS "float trap less")
5087 (trap-r ft uge F OP_04 OPE4_1 Fuge FR-ACCESS "float trap unordered greater or equal")
5088 (trap-r ft ug  F OP_04 OPE4_1 Fug  FR-ACCESS "float trap unordered or greater")
5089 (trap-r ft le  F OP_04 OPE4_1 Fle  FR-ACCESS "float trap less or equal")
5090 (trap-r ft gt  F OP_04 OPE4_1 Fgt  FR-ACCESS "float trap greater")
5091 (trap-r ft ule F OP_04 OPE4_1 Fule FR-ACCESS "float trap unordered less or equal")
5092 (trap-r ft u   F OP_04 OPE4_1 Fu   FR-ACCESS "float trap unordered")
5093 (trap-r ft o   F OP_04 OPE4_1 Fo   FR-ACCESS "float trap ordered")
5094
5095 (define-pmacro (trap-immed prefix cc i-f op cond attr comment)
5096   (dni (.sym prefix cc)
5097        (comment)
5098        ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) attr)
5099        (.str (.sym prefix cc) "$pack $" i-f "CCi_2,$GRi,$s12")
5100        (+ pack (.sym i-f CC_ cc) (.sym i-f CCi_2) op GRi s12)
5101        (trap-semantics (cond (.sym i-f CCi_2)) GRi s12)
5102        ((fr400 (unit u-trap))
5103         (fr500 (unit u-trap)))
5104   )
5105 )
5106
5107 (dni tira
5108      "integer trap always"
5109      ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1))
5110      "tira$pack $GRi,$s12"
5111      (+ pack ICC_ra (ICCi_2-null) OP_1C GRi s12)
5112      (trap-semantics (const BI 1) GRi s12)
5113      ((fr400 (unit u-trap))
5114       (fr500 (unit u-trap)))
5115 )
5116
5117 (dni tino
5118      "integer trap never"
5119      ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1))
5120      "tino$pack"
5121      (+ pack ICC_nev (ICCi_2-null) OP_1C (GRi-null) (s12-null))
5122      (trap-semantics (const BI 0) GRi s12)
5123      ((fr400 (unit u-trap))
5124       (fr500 (unit u-trap)))
5125 )
5126
5127 (trap-immed ti eq  I OP_1C Ieq  NA "integer trap equal")
5128 (trap-immed ti ne  I OP_1C Ine  NA "integer trap not equal")
5129 (trap-immed ti le  I OP_1C Ile  NA "integer trap less or equal")
5130 (trap-immed ti gt  I OP_1C Igt  NA "integer trap greater")
5131 (trap-immed ti lt  I OP_1C Ilt  NA "integer trap less")
5132 (trap-immed ti ge  I OP_1C Ige  NA "integer trap greater or equal")
5133 (trap-immed ti ls  I OP_1C Ils  NA "integer trap less or equal unsigned")
5134 (trap-immed ti hi  I OP_1C Ihi  NA "integer trap greater unsigned")
5135 (trap-immed ti c   I OP_1C Ic   NA "integer trap carry set")
5136 (trap-immed ti nc  I OP_1C Inc  NA "integer trap carry clear")
5137 (trap-immed ti n   I OP_1C In   NA "integer trap negative")
5138 (trap-immed ti p   I OP_1C Ip   NA "integer trap positive")
5139 (trap-immed ti v   I OP_1C Iv   NA "integer trap overflow set")
5140 (trap-immed ti nv  I OP_1C Inv  NA "integer trap overflow clear")
5141
5142 (dni ftira
5143      "float trap always"
5144      ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) FR-ACCESS)
5145      "ftira$pack $GRi,$s12"
5146      (+ pack FCC_ra (ICCi_2-null) OP_1D GRi s12)
5147      (trap-semantics (const BI 1) GRi s12)
5148      ((fr400 (unit u-trap))
5149       (fr500 (unit u-trap)))
5150 )
5151
5152 (dni ftino
5153      "float trap never"
5154      ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) FR-ACCESS)
5155      "ftino$pack"
5156      (+ pack FCC_nev (FCCi_2-null) OP_1D (GRi-null) (s12-null))
5157      (trap-semantics (const BI 0) GRi s12)
5158      ((fr400 (unit u-trap))
5159       (fr500 (unit u-trap)))
5160 )
5161
5162 (trap-immed fti ne  F OP_1D Fne  FR-ACCESS "float trap not equal")
5163 (trap-immed fti eq  F OP_1D Feq  FR-ACCESS "float trap equal")
5164 (trap-immed fti lg  F OP_1D Flg  FR-ACCESS "float trap greater or less")
5165 (trap-immed fti ue  F OP_1D Fue  FR-ACCESS "float trap unordered or equal")
5166 (trap-immed fti ul  F OP_1D Ful  FR-ACCESS "float trap unordered or less")
5167 (trap-immed fti ge  F OP_1D Fge  FR-ACCESS "float trap greater or equal")
5168 (trap-immed fti lt  F OP_1D Flt  FR-ACCESS "float trap less")
5169 (trap-immed fti uge F OP_1D Fuge FR-ACCESS "float trap unordered greater or equal")
5170 (trap-immed fti ug  F OP_1D Fug  FR-ACCESS "float trap unordered or greater")
5171 (trap-immed fti le  F OP_1D Fle  FR-ACCESS "float trap less or equal")
5172 (trap-immed fti gt  F OP_1D Fgt  FR-ACCESS "float trap greater")
5173 (trap-immed fti ule F OP_1D Fule FR-ACCESS "float trap unordered less or equal")
5174 (trap-immed fti u   F OP_1D Fu   FR-ACCESS "float trap unordered")
5175 (trap-immed fti o   F OP_1D Fo   FR-ACCESS "float trap ordered")
5176
5177 (dni break
5178      "break trap"
5179      ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1))
5180      "break$pack"
5181      (+ pack (rd-null) OP_04 (rs-null) (misc-null-3) OPE4_3 (GRj-null))
5182      (sequence ()
5183                ; This is defered to frv_break because for the breakpoint
5184                ; case we want to change as little of the machine state as
5185                ; possible.
5186                ;
5187                ; BPCSR=PC
5188                ; BPSR.BS=PSR.S
5189                ; BPSR.BET=PSR.ET
5190                ; PSR.S=1
5191                ; PSR.ET=0
5192                ; TBR.TT=0xff
5193                ; PC=TBR
5194                ; We still should indicate what is modified by this insn.
5195                (clobber (spr-bpcsr))
5196                (clobber bpsr_bs)
5197                (clobber bpsr_bet)
5198                (clobber psr_s)
5199                (clobber psr_et)
5200                (clobber tbr_tt)
5201                (c-call VOID "frv_break"))
5202      ()
5203 )
5204
5205 (dni mtrap
5206      "media trap"
5207      ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) FR-ACCESS)
5208      "mtrap$pack"
5209      (+ pack (rd-null) OP_04 (rs-null) (misc-null-3) OPE4_2 (GRj-null))
5210      (c-call VOID "frv_mtrap")
5211      ()
5212 )
5213
5214 (define-pmacro (condition-code-logic name operation ope comment)
5215   (dni name
5216        (comment)
5217        ((UNIT B01) (FR500-MAJOR B-6) (FR400-MAJOR B-6))
5218        (.str name "$pack $CRi,$CRj,$CRk")
5219        (+ pack (misc-null-6) CRk OP_0A (misc-null-7) CRi ope (misc-null-8) CRj)
5220        (set CRk (c-call UQI "@cpu@_cr_logic" operation CRi CRj))
5221        ()
5222   )
5223 )
5224 (define-pmacro (op-andcr)   0)
5225 (define-pmacro (op-orcr)    1)
5226 (define-pmacro (op-xorcr)   2)
5227 (define-pmacro (op-nandcr)  3)
5228 (define-pmacro (op-norcr)   4)
5229 (define-pmacro (op-andncr)  5)
5230 (define-pmacro (op-orncr)   6)
5231 (define-pmacro (op-nandncr) 7)
5232 (define-pmacro (op-norncr)  8)
5233
5234 (define-pmacro (cr-true)  3)
5235 (define-pmacro (cr-false) 2)
5236 (define-pmacro (cr-undefined) 0)
5237
5238 (condition-code-logic andcr   (op-andcr)   OPE1_08 "and   condition code regs")
5239 (condition-code-logic orcr    (op-orcr)    OPE1_09 "or    condition code regs")
5240 (condition-code-logic xorcr   (op-xorcr)   OPE1_0A "xor   condition code regs")
5241 (condition-code-logic nandcr  (op-nandcr)  OPE1_0C "nand  condition code regs")
5242 (condition-code-logic norcr   (op-norcr)   OPE1_0D "nor   condition code regs")
5243 (condition-code-logic andncr  (op-andncr)  OPE1_10 "andn  condition code regs")
5244 (condition-code-logic orncr   (op-orncr)   OPE1_11 "orn   condition code regs")
5245 (condition-code-logic nandncr (op-nandncr) OPE1_14 "nandn condition code regs")
5246 (condition-code-logic norncr  (op-norncr)  OPE1_15 "norn  condition code regs")
5247
5248 (dni notcr
5249      ("not cccr register")
5250      ((UNIT B01) (FR500-MAJOR B-6) (FR400-MAJOR B-6))
5251      (.str notcr "$pack $CRj,$CRk")
5252      (+ pack (misc-null-6) CRk OP_0A (rs-null) OPE1_0B (misc-null-8) CRj)
5253      (set CRk (xor CRj 1))
5254      ()
5255 )
5256
5257 (define-pmacro (check-semantics cond cr)
5258   (if cond (set cr (cr-true)) (set cr (cr-false)))
5259 )
5260
5261 (define-pmacro (check-int-condition-code prefix cc op cond comment)
5262   (dni (.sym prefix cc)
5263        (comment)
5264        ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5))
5265        (.str (.sym prefix cc) "$pack $ICCi_3,$CRj_int")
5266        (+ pack (.sym ICC_ cc) CRj_int op (misc-null-5) ICCi_3)
5267        (check-semantics (cond ICCi_3) CRj_int)
5268        ((fr400 (unit u-check))
5269         (fr500 (unit u-check)))
5270   )
5271 )
5272
5273 (dni ckra
5274      "check integer cc always"
5275      ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5))
5276      "ckra$pack $CRj_int"
5277      (+ pack ICC_ra CRj_int OP_08 (misc-null-5) (ICCi_3-null))
5278      (check-semantics (const BI 1) CRj_int)
5279      ((fr400 (unit u-check))
5280       (fr500 (unit u-check)))
5281 )
5282
5283 (dni ckno
5284      "check integer cc never"
5285      ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5))
5286      "ckno$pack $CRj_int"
5287      (+ pack ICC_nev CRj_int OP_08 (misc-null-5) (ICCi_3-null))
5288      (check-semantics (const BI 0) CRj_int)
5289      ((fr400 (unit u-check))
5290       (fr500 (unit u-check)))
5291 )
5292
5293 (check-int-condition-code ck eq  OP_08 Ieq  "check integer cc equal")
5294 (check-int-condition-code ck ne  OP_08 Ine  "check integer cc not equal")
5295 (check-int-condition-code ck le  OP_08 Ile  "check integer cc less or equal")
5296 (check-int-condition-code ck gt  OP_08 Igt  "check integer cc greater")
5297 (check-int-condition-code ck lt  OP_08 Ilt  "check integer cc less")
5298 (check-int-condition-code ck ge  OP_08 Ige  "check integer cc greater or equal")
5299 (check-int-condition-code ck ls  OP_08 Ils  "check integer cc less or equal unsigned")
5300 (check-int-condition-code ck hi  OP_08 Ihi  "check integer cc greater unsigned")
5301 (check-int-condition-code ck c   OP_08 Ic   "check integer cc carry set")
5302 (check-int-condition-code ck nc  OP_08 Inc  "check integer cc carry clear")
5303 (check-int-condition-code ck n   OP_08 In   "check integer cc negative")
5304 (check-int-condition-code ck p   OP_08 Ip   "check integer cc positive")
5305 (check-int-condition-code ck v   OP_08 Iv   "check integer cc overflow set")
5306 (check-int-condition-code ck nv  OP_08 Inv  "check integer cc overflow clear")
5307
5308 (define-pmacro (check-float-condition-code prefix cc op cond comment)
5309   (dni (.sym prefix cc)
5310        (comment)
5311        ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) FR-ACCESS)
5312        (.str (.sym prefix cc) "$pack $FCCi_3,$CRj_float")
5313        (+ pack (.sym FCC_ cc) CRj_float op (misc-null-5) FCCi_3)
5314        (check-semantics (cond FCCi_3) CRj_float)
5315        ((fr400 (unit u-check))
5316         (fr500 (unit u-check)))
5317   )
5318 )
5319
5320 (dni fckra
5321      "check float cc always"
5322      ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) FR-ACCESS)
5323      "fckra$pack $CRj_float"
5324      (+ pack FCC_ra CRj_float OP_09 (misc-null-5) FCCi_3)
5325      (check-semantics (const BI 1) CRj_float)
5326      ((fr400 (unit u-check))
5327       (fr500 (unit u-check)))
5328 )
5329
5330 (dni fckno
5331      "check float cc never"
5332      ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) FR-ACCESS)
5333      "fckno$pack $CRj_float"
5334      (+ pack FCC_nev CRj_float OP_09 (misc-null-5) FCCi_3)
5335      (check-semantics (const BI 0) CRj_float)
5336      ((fr400 (unit u-check))
5337       (fr500 (unit u-check)))
5338 )
5339
5340 (check-float-condition-code fck ne  OP_09 Fne  "check float cc not equal")
5341 (check-float-condition-code fck eq  OP_09 Feq  "check float cc equal")
5342 (check-float-condition-code fck lg  OP_09 Flg  "check float cc greater or less")
5343 (check-float-condition-code fck ue  OP_09 Fue  "check float cc unordered or equal")
5344 (check-float-condition-code fck ul  OP_09 Ful  "check float cc unordered or less")
5345 (check-float-condition-code fck ge  OP_09 Fge  "check float cc greater or equal")
5346 (check-float-condition-code fck lt  OP_09 Flt  "check float cc less")
5347 (check-float-condition-code fck uge OP_09 Fuge "check float cc unordered greater or equal")
5348 (check-float-condition-code fck ug  OP_09 Fug  "check float cc unordered or greater")
5349 (check-float-condition-code fck le  OP_09 Fle  "check float cc less or equal")
5350 (check-float-condition-code fck gt  OP_09 Fgt  "check float cc greater")
5351 (check-float-condition-code fck ule OP_09 Fule "check float cc unordered less or equal")
5352 (check-float-condition-code fck u   OP_09 Fu   "check float cc unordered")
5353 (check-float-condition-code fck o   OP_09 Fo   "check float cc ordered")
5354
5355 (define-pmacro (conditional-check-int-condition-code prefix cc op ope test comment)
5356   (dni (.sym prefix cc)
5357        (comment)
5358        ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL)
5359        (.str (.sym prefix cc) "$pack $ICCi_3,$CRj_int,$CCi,$cond")
5360        (+ pack (.sym ICC_ cc) CRj_int op (rs-null) CCi cond ope
5361           (misc-null-9) ICCi_3)
5362        (if (eq CCi (or cond 2))
5363            (check-semantics (test ICCi_3) CRj_int)
5364            (set CRj_int (cr-undefined)))
5365        ((fr400 (unit u-check))
5366         (fr500 (unit u-check)))
5367   )
5368 )
5369
5370 (dni cckra
5371      "conditional check integer cc always"
5372      ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL)
5373      "cckra$pack $CRj_int,$CCi,$cond"
5374      (+ pack ICC_ra CRj_int OP_6A (rs-null) CCi cond OPE4_0
5375         (misc-null-9) (ICCi_3-null))
5376      (if (eq CCi (or cond 2))
5377          (check-semantics (const BI 1) CRj_int)
5378          (set CRj_int (cr-undefined)))
5379      ((fr400 (unit u-check))
5380       (fr500 (unit u-check)))
5381 )
5382
5383 (dni cckno
5384      "conditional check integer cc never"
5385      ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL)
5386      "cckno$pack $CRj_int,$CCi,$cond"
5387      (+ pack ICC_nev CRj_int OP_6A (rs-null) CCi cond OPE4_0
5388         (misc-null-9) (ICCi_3-null))
5389      (if (eq CCi (or cond 2))
5390          (check-semantics (const BI 0) CRj_int)
5391          (set CRj_int (cr-undefined)))
5392      ((fr400 (unit u-check))
5393       (fr500 (unit u-check)))
5394 )
5395
5396 (conditional-check-int-condition-code cck eq  OP_6A OPE4_0 Ieq  "check integer cc equal")
5397 (conditional-check-int-condition-code cck ne  OP_6A OPE4_0 Ine  "check integer cc not equal")
5398 (conditional-check-int-condition-code cck le  OP_6A OPE4_0 Ile  "check integer cc less or equal")
5399 (conditional-check-int-condition-code cck gt  OP_6A OPE4_0 Igt  "check integer cc greater")
5400 (conditional-check-int-condition-code cck lt  OP_6A OPE4_0 Ilt  "check integer cc less")
5401 (conditional-check-int-condition-code cck ge  OP_6A OPE4_0 Ige  "check integer cc greater or equal")
5402 (conditional-check-int-condition-code cck ls  OP_6A OPE4_0 Ils  "check integer cc less or equal unsigned")
5403 (conditional-check-int-condition-code cck hi  OP_6A OPE4_0 Ihi  "check integer cc greater unsigned")
5404 (conditional-check-int-condition-code cck c   OP_6A OPE4_0 Ic   "check integer cc carry set")
5405 (conditional-check-int-condition-code cck nc  OP_6A OPE4_0 Inc  "check integer cc carry clear")
5406 (conditional-check-int-condition-code cck n   OP_6A OPE4_0 In   "check integer cc negative")
5407 (conditional-check-int-condition-code cck p   OP_6A OPE4_0 Ip   "check integer cc positive")
5408 (conditional-check-int-condition-code cck v   OP_6A OPE4_0 Iv   "check integer cc overflow set")
5409 (conditional-check-int-condition-code cck nv  OP_6A OPE4_0 Inv  "check integer cc overflow clear")
5410
5411 (define-pmacro (conditional-check-float-condition-code prefix cc op ope test comment)
5412   (dni (.sym prefix cc)
5413        (comment)
5414        ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL FR-ACCESS)
5415        (.str (.sym prefix cc) "$pack $FCCi_3,$CRj_float,$CCi,$cond")
5416        (+ pack (.sym FCC_ cc) CRj_float op (rs-null) CCi cond ope
5417           (misc-null-9) FCCi_3)
5418        (if (eq CCi (or cond 2))
5419            (check-semantics (test FCCi_3) CRj_float)
5420            (set CRj_float (cr-undefined)))
5421        ((fr400 (unit u-check))
5422         (fr500 (unit u-check)))
5423   )
5424 )
5425
5426 (dni cfckra
5427      "conditional check float cc always"
5428      ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL FR-ACCESS)
5429      "cfckra$pack $CRj_float,$CCi,$cond"
5430      (+ pack FCC_ra CRj_float OP_6A (rs-null) CCi cond OPE4_1
5431         (misc-null-9) (FCCi_3-null))
5432      (if (eq CCi (or cond 2))
5433          (check-semantics (const BI 1) CRj_float)
5434          (set CRj_float (cr-undefined)))
5435      ((fr400 (unit u-check))
5436       (fr500 (unit u-check)))
5437 )
5438
5439 (dni cfckno
5440      "conditional check float cc never"
5441      ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL FR-ACCESS)
5442      "cfckno$pack $CRj_float,$CCi,$cond"
5443      (+ pack FCC_nev CRj_float OP_6A (rs-null) CCi cond OPE4_1
5444         (misc-null-9) (FCCi_3-null))
5445      (if (eq CCi (or cond 2))
5446          (check-semantics (const BI 0) CRj_float)
5447          (set CRj_float (cr-undefined)))
5448      ((fr400 (unit u-check))
5449       (fr500 (unit u-check)))
5450 )
5451
5452 (conditional-check-float-condition-code cfck ne  OP_6A OPE4_1 Fne  "check float cc not equal")
5453 (conditional-check-float-condition-code cfck eq  OP_6A OPE4_1 Feq  "check float cc equal")
5454 (conditional-check-float-condition-code cfck lg  OP_6A OPE4_1 Flg  "check float cc greater or less")
5455 (conditional-check-float-condition-code cfck ue  OP_6A OPE4_1 Fue  "check float cc unordered or equal")
5456 (conditional-check-float-condition-code cfck ul  OP_6A OPE4_1 Ful  "check float cc unordered or less")
5457 (conditional-check-float-condition-code cfck ge  OP_6A OPE4_1 Fge  "check float cc greater or equal")
5458 (conditional-check-float-condition-code cfck lt  OP_6A OPE4_1 Flt  "check float cc less")
5459 (conditional-check-float-condition-code cfck uge OP_6A OPE4_1 Fuge "check float cc unordered greater or equal")
5460 (conditional-check-float-condition-code cfck ug  OP_6A OPE4_1 Fug  "check float cc unordered or greater")
5461 (conditional-check-float-condition-code cfck le  OP_6A OPE4_1 Fle  "check float cc less or equal")
5462 (conditional-check-float-condition-code cfck gt  OP_6A OPE4_1 Fgt  "check float cc greater")
5463 (conditional-check-float-condition-code cfck ule OP_6A OPE4_1 Fule "check float cc unordered less or equal")
5464 (conditional-check-float-condition-code cfck u   OP_6A OPE4_1 Fu   "check float cc unordered")
5465 (conditional-check-float-condition-code cfck o   OP_6A OPE4_1 Fo   "check float cc ordered")
5466
5467 (dni cjmpl
5468      "conditional jump and link"
5469      ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5) CONDITIONAL)
5470      "cjmpl$pack @($GRi,$GRj),$CCi,$cond"
5471      (+ pack (misc-null-1) (LI-off) OP_6A GRi CCi cond OPE4_2 GRj)
5472      (if (eq CCi (or cond 2))
5473          (jump-and-link-semantics GRi GRj LI))
5474      ((fr400 (unit u-branch))
5475       (fr500 (unit u-branch)))
5476 )
5477
5478 (dni ccalll
5479      "conditional call and link"
5480      ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5) CONDITIONAL)
5481      "ccalll$pack @($GRi,$GRj),$CCi,$cond"
5482      (+ pack (misc-null-1) (LI-on) OP_6A GRi CCi cond OPE4_2 GRj)
5483      (if (eq CCi (or cond 2))
5484          (jump-and-link-semantics GRi GRj LI))
5485      ((fr400 (unit u-branch))
5486       (fr500 (unit u-branch)))
5487 )
5488
5489 (define-pmacro (cache-invalidate name cache all op ope profile comment)
5490   (dni name
5491        (comment)
5492        ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
5493        (.str name "$pack @($GRi,$GRj)")
5494        (+ pack (rd-null) op GRi ope GRj)
5495        (c-call VOID (.str "@cpu@_" cache "_cache_invalidate") (add GRi GRj) all)
5496        profile
5497   )
5498 )
5499
5500 (cache-invalidate ici insn 0 OP_03 OPE1_38
5501                   ((fr400 (unit u-ici)) (fr500 (unit u-ici)))
5502                   "invalidate insn cache")
5503 (cache-invalidate dci data 0 OP_03 OPE1_3C
5504                   ((fr400 (unit u-dci)) (fr500 (unit u-dci)))
5505                   "invalidate data cache")
5506
5507 (define-pmacro (cache-invalidate-entry name cache op ope profile comment)
5508   (dni name
5509        (comment)
5510        ((UNIT C) (FR400-MAJOR C-2) (MACH fr400))
5511        (.str name "$pack @($GRi,$GRj),$ae")
5512        (+ pack (misc-null-1) ae op GRi ope GRj)
5513        (if (eq ae 0)
5514            (c-call VOID (.str "@cpu@_" cache "_cache_invalidate") (add GRi GRj) -1) ; Invalid ae setting for this insn
5515            (c-call VOID (.str "@cpu@_" cache "_cache_invalidate") (add GRi GRj) ae))
5516        profile
5517   )
5518 )
5519
5520 (cache-invalidate-entry icei insn OP_03 OPE1_39
5521                         ((fr400 (unit u-ici)))
5522                         "invalidate insn cache entry")
5523 (cache-invalidate-entry dcei data OP_03 OPE1_3A
5524                         ((fr400 (unit u-dci)))
5525                         "invalidate data cache entry")
5526
5527 (dni dcf
5528      "Data cache flush"
5529      ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
5530      "dcf$pack @($GRi,$GRj)"
5531      (+ pack (rd-null) OP_03 GRi OPE1_3D GRj)
5532      (c-call VOID "@cpu@_data_cache_flush" (add GRi GRj) 0)
5533      ((fr400 (unit u-dcf))
5534       (fr500 (unit u-dcf)))
5535 )
5536
5537 (dni dcef
5538      "Data cache entry flush"
5539      ((UNIT C) (FR400-MAJOR C-2) (MACH fr400))
5540      "dcef$pack @($GRi,$GRj),$ae"
5541      (+ pack (misc-null-1) ae OP_03 GRi OPE1_3B GRj)
5542      (if (eq ae 0)
5543          (c-call VOID "@cpu@_data_cache_flush" (add GRi GRj) -1)
5544          (c-call VOID "@cpu@_data_cache_flush" (add GRi GRj) ae))
5545      ((fr400 (unit u-dcf)))
5546 )
5547
5548 (define-pmacro (write-TLB name insn op ope comment)
5549   (dni name
5550        (comment)
5551        ((UNIT C) (FR500-MAJOR C-2) (MACH frv) PRIVILEGED)
5552        (.str insn "$pack $GRk,@($GRi,$GRj)")
5553        (+ pack GRk op GRi ope GRj)
5554        (nop) ; for now
5555        ()
5556   )
5557 )
5558
5559 (write-TLB witlb witlb OP_03 OPE1_32 "write for insn TLB")
5560 (write-TLB wdtlb wdtlb OP_03 OPE1_36 "write for data TLB")
5561
5562 (define-pmacro (invalidate-TLB name insn op ope comment)
5563   (dni name
5564        (comment)
5565        ((UNIT C) (FR500-MAJOR C-2) (MACH frv) PRIVILEGED)
5566        (.str insn "$pack @($GRi,$GRj)")
5567        (+ pack (rd-null) op GRi ope GRj)
5568        (nop) ; for now
5569        ()
5570   )
5571 )
5572
5573 (invalidate-TLB itlbi itlbi OP_03 OPE1_33 "invalidate insn TLB")
5574 (invalidate-TLB dtlbi dtlbi OP_03 OPE1_37 "invalidate data TLB")
5575
5576 (define-pmacro (cache-preload name cache op ope profile comment)
5577   (dni name
5578        (comment)
5579        ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
5580        (.str name "$pack $GRi,$GRj,$lock")
5581        (+ pack (misc-null-1) lock op GRi ope GRj)
5582        (c-call VOID (.str "@cpu@_" cache "_cache_preload") GRi GRj lock)
5583        profile
5584   )
5585 )
5586
5587 (cache-preload icpl insn OP_03 OPE1_30
5588                ((fr400 (unit u-icpl)) (fr500 (unit u-icpl)))
5589                "preload insn cache")
5590 (cache-preload dcpl data OP_03 OPE1_34
5591                ((fr400 (unit u-dcpl)) (fr500 (unit u-dcpl)))
5592                "preload data cache")
5593
5594 (define-pmacro (cache-unlock name cache op ope profile comment)
5595   (dni name
5596        (comment)
5597        ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
5598        (.str name "$pack $GRi")
5599        (+ pack (rd-null) op GRi ope (GRj-null))
5600        (c-call VOID (.str "@cpu@_" cache "_cache_unlock") GRi)
5601        profile
5602   )
5603 )
5604
5605 (cache-unlock icul insn OP_03 OPE1_31
5606               ((fr400 (unit u-icul)) (fr500 (unit u-icul)))
5607               "unlock insn cache")
5608 (cache-unlock dcul data OP_03 OPE1_35
5609               ((fr400 (unit u-dcul)) (fr500 (unit u-dcul)))
5610               "unlock data cache")
5611
5612 (define-pmacro (barrier name insn op ope profile comment)
5613   (dni name
5614        (comment)
5615        ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
5616        (.str insn "$pack")
5617        (+ pack (rd-null) op (rs-null) ope (GRj-null))
5618        (nop) ; sufficient implementation
5619        profile
5620   )
5621 )
5622
5623 (barrier bar    bar    OP_03 OPE1_3E
5624          ((fr400 (unit u-barrier)) (fr500 (unit u-barrier)))
5625          "barrier")
5626 (barrier membar membar OP_03 OPE1_3F
5627          ((fr400 (unit u-membar)) (fr500 (unit u-membar)))
5628          "memory barrier")
5629
5630 ; Coprocessor operations
5631 (define-pmacro (cop-op num op)
5632   (dni (.sym cop num)
5633        "Coprocessor operation"
5634        ((UNIT C) (FR500-MAJOR C-2) (MACH frv))
5635        (.str "cop" num "$pack $s6_1,$CPRi,$CPRj,$CPRk")
5636        (+ pack CPRk op CPRi s6_1 CPRj)
5637        (nop) ; sufficient implementation
5638        ()
5639   )
5640 )
5641
5642 (cop-op 1 OP_7E)
5643 (cop-op 2 OP_7F)
5644
5645 (define-pmacro (clear-ne-flag-semantics target_index is_float)
5646   (c-call VOID "@cpu@_clear_ne_flags" target_index is_float)
5647 )
5648
5649 (define-pmacro (clear-ne-flag-r name op ope reg is_float attr comment)
5650   (dni name
5651        (comment)
5652        ((UNIT I01) (FR500-MAJOR I-6) (MACH simple,tomcat,fr500,frv) attr)
5653        (.str name "$pack $" reg "k")
5654        (+ pack (.sym reg k) op (rs-null) ope (GRj-null))
5655        (clear-ne-flag-semantics (index-of (.sym reg k)) is_float)
5656        ()
5657   )
5658 )
5659
5660 (clear-ne-flag-r clrgr OP_0A OPE1_00 GR 0 NA        "Clear GR NE flag")
5661 (clear-ne-flag-r clrfr OP_0A OPE1_02 FR 1 FR-ACCESS "Clear FR NE flag")
5662
5663 (define-pmacro (clear-ne-flag-all name op ope is_float attr comment)
5664   (dni name
5665        (comment)
5666        ((UNIT I01) (FR500-MAJOR I-6) (MACH simple,tomcat,fr500,frv) attr)
5667        (.str name "$pack")
5668        (+ pack (rd-null) op (rs-null) ope (GRj-null))
5669        (clear-ne-flag-semantics -1 is_float)
5670        ()
5671   )
5672 )
5673
5674 (clear-ne-flag-all clrga OP_0A OPE1_01 0 NA        "Clear GR NE flag ALL")
5675 (clear-ne-flag-all clrfa OP_0A OPE1_03 1 FR-ACCESS "Clear FR NE flag ALL")
5676
5677 (define-pmacro (commit-semantics target_index is_float)
5678   (c-call VOID "@cpu@_commit" target_index is_float)
5679 )
5680
5681 (define-pmacro (commit-r name op ope reg is_float attr comment)
5682   (dni name
5683        (comment)
5684        ((UNIT I01) (FR500-MAJOR I-6) (MACH frv,fr500) attr)
5685        (.str name "$pack $" reg "k")
5686        (+ pack (.sym reg k) op (rs-null) ope (GRj-null))
5687        (commit-semantics (index-of (.sym reg k)) is_float)
5688        ()
5689   )
5690 )
5691
5692 (commit-r commitgr OP_0A OPE1_04 GR 0 NA        "commit exceptions, specific GR")
5693 (commit-r commitfr OP_0A OPE1_06 FR 1 FR-ACCESS "commit exceptions, specific FR")
5694
5695 (define-pmacro (commit name op ope is_float attr comment)
5696   (dni name
5697        (comment)
5698        ((UNIT I01) (FR500-MAJOR I-6) (MACH frv,fr500) attr)
5699        (.str name "$pack")
5700        (+ pack (rd-null) op (rs-null) ope (GRj-null))
5701        (commit-semantics -1 is_float)
5702        ()
5703   )
5704 )
5705
5706 (commit commitga OP_0A OPE1_05 0 NA        "commit exceptions, any GR")
5707 (commit commitfa OP_0A OPE1_07 1 FR-ACCESS "commit exceptions, any FR")
5708
5709 (define-pmacro (floating-point-conversion
5710                 name op ope conv mode src targ attr comment)
5711   (dni name
5712        (comment)
5713        ((UNIT FM01) (FR500-MAJOR F-1) (MACH simple,tomcat,fr500,frv) attr)
5714        (.str name "$pack $" src ",$" targ)
5715        (+ pack targ op (rs-null) ope src)
5716        (set targ (conv mode src))
5717        ((fr500 (unit u-float-convert)))
5718   )
5719 )
5720
5721 (floating-point-conversion fitos OP_79 OPE1_00 float SF FRintj FRk NA "Convert Integer to Single")
5722 (floating-point-conversion fstoi OP_79 OPE1_01 fix   SI FRj FRintk NA "Convert Single  to Integer")
5723 (floating-point-conversion fitod OP_7A OPE1_00 float DF FRintj FRdoublek (MACH frv) "Convert Integer to Double")
5724 (floating-point-conversion fdtoi OP_7A OPE1_01 fix   SI FRdoublej FRintk (MACH frv) "Convert Double to Integer")
5725
5726 (define-pmacro (floating-point-dual-conversion
5727                 name op ope conv mode src src_hw targ targ_hw attr comment)
5728   (dni name
5729        (comment)
5730        ((MACH frv) (UNIT FM01) (FR500-MAJOR F-1) attr)
5731        (.str name "$pack $" src ",$" targ)
5732        (+ pack targ op (rs-null) ope src)
5733        (sequence ()
5734                  (set targ (conv mode src))
5735                  (set (nextreg targ_hw targ 1)
5736                       (conv mode (nextreg src_hw src 1))))
5737        ((fr500 (unit u-float-dual-convert)))
5738   )
5739 )
5740
5741 (floating-point-dual-conversion fditos OP_79 OPE1_10 float SF FRintj h-fr_int FRk h-fr NA "Dual Convert Integer to Single")
5742 (floating-point-dual-conversion fdstoi OP_79 OPE1_11 fix   SI FRj h-fr FRintk h-fr_int NA "Dual Convert Single  to Integer")
5743
5744 (define-pmacro (ne-floating-point-dual-conversion
5745                 name op ope conv mode src src_hw targ targ_hw attr comment)
5746   (dni name
5747        (comment)
5748        ((MACH frv) (UNIT FM01) (FR500-MAJOR F-1) NON-EXCEPTING attr)
5749        (.str name "$pack $" src ",$" targ)
5750        (+ pack targ op (rs-null) ope src)
5751        (sequence ()
5752                  (c-call VOID "@cpu@_set_ne_index" (index-of targ))
5753                  (set targ (conv mode src))
5754                  (c-call VOID "@cpu@_set_ne_index" (add (index-of targ) 1))
5755                  (set (nextreg targ_hw targ 1)
5756                       (conv mode (nextreg src_hw src 1))))
5757        ((fr500 (unit u-float-dual-convert)))
5758   )
5759 )
5760
5761 (ne-floating-point-dual-conversion nfditos OP_79 OPE1_30 float SF FRintj h-fr_int FRk h-fr NA "Non excepting dual Convert Integer to Single")
5762 (ne-floating-point-dual-conversion nfdstoi OP_79 OPE1_31 fix   SI FRj h-fr FRintk h-fr_int NA "Non excepting dual Convert Single  to Integer")
5763
5764 (define-pmacro (conditional-floating-point-conversion
5765                 name op ope conv mode src targ comment)
5766   (dni name
5767        (comment)
5768        ((UNIT FM01) (FR500-MAJOR F-1) (MACH simple,tomcat,fr500,frv))
5769        (.str name "$pack $" src ",$" targ ",$CCi,$cond")
5770        (+ pack targ op (rs-null) CCi cond ope src)
5771        (if (eq CCi (or cond 2))
5772            (set targ (conv mode src)))
5773        ((fr500 (unit u-float-convert)))
5774   )
5775 )
5776
5777 (conditional-floating-point-conversion cfitos OP_6B OPE4_0 float SF FRintj FRk "Conditional convert Integer to Single")
5778 (conditional-floating-point-conversion cfstoi OP_6B OPE4_1 fix   SI FRj FRintk "Conditional convert Single to Integer")
5779
5780 (define-pmacro (ne-floating-point-conversion 
5781                 name op ope conv mode src targ comment)
5782   (dni name
5783        (comment)
5784        ((UNIT FM01) (FR500-MAJOR F-1) (MACH simple,tomcat,fr500,frv))
5785        (.str name "$pack $" src ",$" targ)
5786        (+ pack targ op (rs-null) ope src)
5787        (sequence ()
5788                  (c-call VOID "@cpu@_set_ne_index" (index-of targ))
5789                  (set targ (conv mode src)))
5790        ((fr500 (unit u-float-convert)))
5791   )
5792 )
5793
5794 (ne-floating-point-conversion nfitos OP_79 OPE1_20 float SF FRintj FRk "NE convert Integer to Single")
5795 (ne-floating-point-conversion nfstoi OP_79 OPE1_21 fix   SI FRj FRintk "NE convert Single to Integer")
5796
5797 (register-transfer fmovs OP_79 OPE1_02
5798                    FRj FRk FM01 (FR500-MAJOR F-1) NA
5799                    (MACH simple,tomcat,fr500,frv) NA
5800                    ((fr500 (unit u-fr2fr)))
5801                    "Move Single Float")
5802 (register-transfer fmovd OP_7A OPE1_02
5803                    ; TODO -- unit doesn't handle extra register
5804                    FRdoublej FRdoublek FM01 (FR500-MAJOR F-1) NA
5805                    (MACH frv) NA
5806                    ((fr500 (unit u-fr2fr)))
5807                    "Move Double Float")
5808
5809 (dni fdmovs
5810      "Dual move single float"
5811      ((MACH frv) (UNIT FM01) (FR500-MAJOR F-1))
5812      "fdmovs$pack $FRj,$FRk"
5813      (+ pack FRk OP_79 (rs-null) OPE1_12 FRj)
5814      (sequence ()
5815                (set FRk FRj)
5816                (set (nextreg h-fr FRk 1) (nextreg h-fr FRj 1)))
5817      ; TODO -- unit doesn't handle extra register
5818      ((fr500 (unit u-fr2fr)))
5819 )
5820
5821 (conditional-register-transfer cfmovs OP_6C OPE4_0 FRj FRk FM01
5822                                (FR500-MAJOR F-1) NA
5823                                (MACH simple,tomcat,fr500,frv)
5824                                ((fr500 (unit u-fr2fr)))
5825                                "Conditional move Single Float")
5826
5827 (define-pmacro (floating-point-neg name src targ op ope attr comment)
5828   (dni name
5829        (comment)
5830        ((UNIT FM01) (FR500-MAJOR F-1) attr)
5831        (.str name "$pack $" src ",$" targ)
5832        (+ pack src op (rs-null) ope targ)
5833        (set targ (neg src))
5834        ((fr500 (unit u-float-arith)))
5835   )
5836 )
5837
5838 (floating-point-neg fnegs FRj FRk OP_79 OPE1_03 (MACH simple,tomcat,fr500,frv) "Floating point negate, single")
5839 (floating-point-neg fnegd FRdoublej FRdoublek OP_7A OPE1_03 (MACH frv) "Floating point negate, double")
5840
5841 (dni fdnegs
5842      "Floating point dual negate, single"
5843      ((MACH frv) (UNIT FM01) (FR500-MAJOR F-1))
5844      "fdnegs$pack $FRj,$FRk"
5845      (+ pack FRk OP_79 (rs-null) OPE1_13 FRj)
5846      (sequence ()
5847                (set FRk (neg FRj))
5848                (set (nextreg h-fr FRk 1) (neg (nextreg h-fr FRj 1))))
5849      ((fr500 (unit u-float-dual-arith)))
5850 )
5851
5852 (dni cfnegs
5853      "Conditional floating point negate, single"
5854      ((UNIT FM01) (FR500-MAJOR F-1) (MACH simple,tomcat,fr500,frv))
5855      "cfnegs$pack $FRj,$FRk,$CCi,$cond"
5856      (+ pack FRj OP_6C (rs-null) CCi cond OPE4_1 FRk)
5857      (if (eq CCi (or cond 2))
5858          (set FRk (neg FRj)))
5859      ((fr500 (unit u-float-arith)))
5860 )
5861
5862 (define-pmacro (float-abs name src targ op ope attr comment)
5863   (dni name
5864        (comment)
5865        ((UNIT FM01) (FR500-MAJOR F-1) attr)
5866        (.str name "$pack $" src ",$" targ )
5867        (+ pack targ op (rs-null) ope src)
5868        (set targ (abs src))
5869        ((fr500 (unit u-float-arith)))
5870   )
5871 )
5872
5873 (float-abs fabss FRj FRk OP_79 OPE1_04 (MACH simple,tomcat,fr500,frv) "Float absolute value, single")
5874 (float-abs fabsd FRdoublej FRdoublek OP_7A OPE1_04 (MACH frv) "Float absolute value, double")
5875
5876 (dni fdabss
5877      "Floating point dual absolute value, single"
5878      ((MACH frv) (UNIT FM01) (FR500-MAJOR F-1))
5879      "fdabss$pack $FRj,$FRk"
5880      (+ pack FRk OP_79 (rs-null) OPE1_14 FRj)
5881      (sequence ()
5882                (set FRk (abs FRj))
5883                (set (nextreg h-fr FRk 1) (abs (nextreg h-fr FRj 1))))
5884      ((fr500 (unit u-float-dual-arith)))
5885 )
5886
5887 (dni cfabss
5888      "Conditional floating point absolute value, single"
5889      ((UNIT FM01) (FR500-MAJOR F-1) (MACH simple,tomcat,fr500,frv))
5890      "cfabss$pack $FRj,$FRk,$CCi,$cond"
5891      (+ pack FRj OP_6C (rs-null) CCi cond OPE4_2 FRk)
5892      (if (eq CCi (or cond 2))
5893          (set FRk (abs FRj)))
5894      ((fr500 (unit u-float-arith)))
5895 )
5896
5897 (dni fsqrts
5898      "Square root single"
5899      ((UNIT FM01) (FR500-MAJOR F-4) (MACH simple,tomcat,fr500,frv))
5900      "fsqrts$pack $FRj,$FRk"
5901      (+ pack FRk OP_79 (rs-null) OPE1_05 FRj)
5902      (set FRk (sqrt SF FRj))
5903      ((fr500 (unit u-float-sqrt)))
5904 )
5905
5906 (dni fdsqrts
5907      "Dual square root single"
5908      ((MACH frv) (UNIT FM01) (FR500-MAJOR F-4))
5909      "fdsqrts$pack $FRj,$FRk"
5910      (+ pack FRk OP_79 (rs-null) OPE1_15 FRj)
5911      (sequence ()
5912                (set FRk (sqrt SF FRj))
5913                (set (nextreg h-fr FRk 1) (sqrt (nextreg h-fr FRj 1))))
5914      ((fr500 (unit u-float-dual-sqrt)))
5915 )
5916
5917 (dni nfdsqrts
5918      "Non excepting Dual square root single"
5919      ((MACH frv) (UNIT FM01) (FR500-MAJOR F-4) NON-EXCEPTING)
5920      "nfdsqrts$pack $FRj,$FRk"
5921      (+ pack FRk OP_79 (rs-null) OPE1_35 FRj)
5922      (sequence ()
5923                (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
5924                (set FRk (sqrt SF FRj))
5925                (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
5926                (set (nextreg h-fr FRk 1) (sqrt (nextreg h-fr FRj 1))))
5927      ((fr500 (unit u-float-dual-sqrt)))
5928 )
5929
5930 (dni fsqrtd
5931      "Square root double"
5932      ((UNIT FM01) (FR500-MAJOR F-4) (MACH frv))
5933      "fsqrtd$pack $FRdoublej,$FRdoublek"
5934      (+ pack FRdoublek OP_7A (rs-null) OPE1_05 FRdoublej)
5935      (set FRdoublek (sqrt DF FRdoublej))
5936      ((fr500 (unit u-float-sqrt)))
5937 )
5938
5939 (dni cfsqrts
5940      "Conditional square root single"
5941      ((UNIT FM01) (FR500-MAJOR F-4) (MACH simple,tomcat,fr500,frv))
5942      "cfsqrts$pack $FRj,$FRk,$CCi,$cond"
5943      (+ pack FRk OP_6E (rs-null) CCi cond OPE4_2 FRj)
5944      (if (eq CCi (or cond 2))
5945          (set FRk (sqrt SF FRj)))
5946      ((fr500 (unit u-float-sqrt)))
5947 )
5948
5949 (dni nfsqrts
5950      "Non exception square root, single"
5951      ((UNIT FM01) (FR500-MAJOR F-4) (MACH simple,tomcat,fr500,frv))
5952      "nfsqrts$pack $FRj,$FRk"
5953      (+ pack FRk OP_79 (rs-null) OPE1_25 FRj)
5954      (sequence ()
5955                (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
5956                (set FRk (sqrt SF FRj)))
5957      ((fr500 (unit u-float-sqrt)))
5958 )
5959
5960 (define-pmacro (float-binary-op-s name operation op ope major comment)
5961   (dni name
5962        (comment)
5963        ((UNIT FM01) (FR500-MAJOR major) (MACH simple,tomcat,fr500,frv))
5964        (.str name "$pack $FRi,$FRj,$FRk")
5965        (+ pack FRk op FRi ope FRj)
5966        (set FRk (operation FRi FRj))
5967        ((fr500 (unit u-float-arith)))
5968   )
5969 )
5970
5971 (float-binary-op-s fadds add OP_79 OPE1_06 F-2 "add single float")
5972 (float-binary-op-s fsubs sub OP_79 OPE1_07 F-2 "sub single float")
5973 (float-binary-op-s fmuls mul OP_79 OPE1_08 F-3 "mul single float")
5974
5975 (dni fdivs
5976      "div single float"
5977      ((UNIT FM01) (FR500-MAJOR F-4) (MACH simple,tomcat,fr500,frv))
5978      "fdivs$pack $FRi,$FRj,$FRk"
5979      (+ pack FRk OP_79 FRi OPE1_09 FRj)
5980      (set FRk (div FRi FRj))
5981      ((fr500 (unit u-float-div)))
5982 )
5983
5984 (define-pmacro (float-binary-op-d name operation op ope major comment)
5985   (dni name
5986        (comment)
5987        ((UNIT FM01) (FR500-MAJOR major) (MACH frv))
5988        (.str name "$pack $FRdoublei,$FRdoublej,$FRdoublek")
5989        (+ pack FRdoublek op FRdoublei ope FRdoublej)
5990        (set FRdoublek (operation FRdoublei FRdoublej))
5991        ((fr500 (unit u-float-arith)))
5992   )
5993 )
5994
5995 (float-binary-op-d faddd add OP_7A OPE1_06 F-2 "add double float")
5996 (float-binary-op-d fsubd sub OP_7A OPE1_07 F-2 "sub double float")
5997 (float-binary-op-d fmuld mul OP_7A OPE1_08 F-3 "mul double float")
5998 (float-binary-op-d fdivd div OP_7A OPE1_09 F-4 "div double float")
5999
6000 (define-pmacro (conditional-float-binary-op name operation op ope major comment)
6001   (dni name
6002        (comment)
6003        ((UNIT FM01) (FR500-MAJOR major) (MACH simple,tomcat,fr500,frv))
6004        (.str name "$pack $FRi,$FRj,$FRk,$CCi,$cond")
6005        (+ pack FRk op FRi CCi cond ope FRj)
6006        (if (eq CCi (or cond 2))
6007            (set FRk (operation FRi FRj)))
6008        ((fr500 (unit u-float-arith)))
6009   )
6010 )
6011
6012 (conditional-float-binary-op cfadds add OP_6D OPE4_0 F-2 "cond add single")
6013 (conditional-float-binary-op cfsubs sub OP_6D OPE4_1 F-2 "cond sub single")
6014 (conditional-float-binary-op cfmuls mul OP_6E OPE4_0 F-3 "cond mul single")
6015 (conditional-float-binary-op cfdivs div OP_6E OPE4_1 F-4 "cond div single")
6016
6017 (define-pmacro (ne-float-binary-op name operation op ope major comment)
6018   (dni name
6019        (comment)
6020        ((UNIT FM01) (FR500-MAJOR major) (MACH simple,tomcat,fr500,frv))
6021        (.str name "$pack $FRi,$FRj,$FRk")
6022        (+ pack FRk op FRi ope FRj)
6023        (sequence ()
6024                  (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
6025                  (set FRk (operation FRi FRj)))
6026        ((fr500 (unit u-float-arith)))
6027   )
6028 )
6029
6030 (ne-float-binary-op nfadds add OP_79 OPE1_26 F-2 "ne add single")
6031 (ne-float-binary-op nfsubs sub OP_79 OPE1_27 F-2 "ne sub single")
6032 (ne-float-binary-op nfmuls mul OP_79 OPE1_28 F-3 "ne mul single")
6033 (ne-float-binary-op nfdivs div OP_79 OPE1_29 F-4 "ne div single")
6034
6035 (define-pmacro (fcc-eq) 8)
6036 (define-pmacro (fcc-lt) 4)
6037 (define-pmacro (fcc-gt) 2)
6038 (define-pmacro (fcc-uo) 1)
6039
6040 (define-pmacro (compare-and-set-fcc arg1 arg2 fcc)
6041   (if (gt arg1 arg2)
6042       (set fcc (fcc-gt))
6043       (if (eq arg1 arg2)
6044           (set fcc (fcc-eq))
6045           (if (lt arg1 arg2)
6046               (set fcc (fcc-lt))
6047               (set fcc (fcc-uo)))))
6048 )
6049
6050 (dni fcmps
6051      "compare single float"
6052      ((UNIT FM01) (FR500-MAJOR F-2) (MACH simple,tomcat,fr500,frv))
6053      "fcmps$pack $FRi,$FRj,$FCCi_2"
6054      (+ pack (cond-null) FCCi_2 OP_79 FRi OPE1_0A FRj)
6055      (compare-and-set-fcc FRi FRj FCCi_2)
6056      ((fr500 (unit u-float-compare)))
6057 )
6058
6059 (dni fcmpd
6060      "compare double float"
6061      ((UNIT FM01) (FR500-MAJOR F-2) (MACH frv))
6062      "fcmpd$pack $FRdoublei,$FRdoublej,$FCCi_2"
6063      (+ pack (cond-null) FCCi_2 OP_7A FRdoublei OPE1_0A FRdoublej)
6064      (compare-and-set-fcc FRdoublei FRdoublej FCCi_2)
6065      ((fr500 (unit u-float-compare)))
6066 )
6067
6068 (dni cfcmps
6069      "Conditional compare single, float"
6070      ((UNIT FM01) (FR500-MAJOR F-2) (MACH simple,tomcat,fr500,frv))
6071      "cfcmps$pack $FRi,$FRj,$FCCi_2,$CCi,$cond"
6072      (+ pack (cond-null) FCCi_2 OP_6D FRi CCi cond OPE4_2 FRj)
6073      (if (eq CCi (or cond 2))
6074          (compare-and-set-fcc FRi FRj FCCi_2))
6075      ((fr500 (unit u-float-compare)))
6076 )
6077
6078 (dni fdcmps
6079      "float dual compare single"
6080      ((UNIT FM01) (FR500-MAJOR F-6) (MACH simple,tomcat,fr500,frv))
6081      "fdcmps$pack $FRi,$FRj,$FCCi_2"
6082      (+ pack (cond-null) FCCi_2 OP_79 FRi OPE1_1A FRj)
6083      (sequence ()
6084                (compare-and-set-fcc FRi FRj FCCi_2)
6085                (compare-and-set-fcc (nextreg h-fr FRi 1) (nextreg h-fr FRj 1)
6086                                     (nextreg h-fccr FCCi_2 1)))
6087      ((fr500 (unit u-float-dual-compare)))
6088 )
6089
6090 (define-pmacro (float-mul-with-add name add_sub arg1 arg2 targ op ope comment)
6091   (dni name
6092        (comment)
6093        ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
6094        (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
6095        (+ pack targ op arg1 ope arg2)
6096        (set targ (add_sub (mul arg1 arg2) targ))
6097        ((fr500 (unit u-float-dual-arith)))
6098   )
6099 )
6100
6101 (float-mul-with-add fmadds add FRi FRj FRk OP_79 OPE1_0B "mul with add, single")
6102 (float-mul-with-add fmsubs sub FRi FRj FRk OP_79 OPE1_0C "mul with sub, single")
6103
6104 (float-mul-with-add fmaddd add FRdoublei FRdoublej FRdoublek OP_7A OPE1_0B "mul with add, double")
6105 (float-mul-with-add fmsubd sub FRdoublei FRdoublej FRdoublek OP_7A OPE1_0C "mul with sub, double")
6106
6107 (dni fdmadds
6108      "Float dual multiply with add"
6109      ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
6110      "fdmadds$pack $FRi,$FRj,$FRk"
6111      (+ pack FRk OP_79 FRi OPE1_1B FRj)
6112      (sequence ()
6113                (set FRk (add (mul FRi FRj) FRk))
6114                (set (nextreg h-fr FRk 1)
6115                     (add (mul (nextreg h-fr FRi 1) (nextreg h-fr FRj 1))
6116                          (nextreg h-fr FRk 1))))
6117      ; TODO dual registers not referenced for profiling
6118      ((fr500 (unit u-float-dual-arith)))
6119 )
6120
6121 (dni nfdmadds
6122      "Non excepting float dual multiply with add"
6123      ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
6124      "nfdmadds$pack $FRi,$FRj,$FRk"
6125      (+ pack FRk OP_79 FRi OPE1_3B FRj)
6126      (sequence ()
6127                (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
6128                (set FRk (add (mul FRi FRj) FRk))
6129                (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
6130                (set (nextreg h-fr FRk 1)
6131                     (add (mul (nextreg h-fr FRi 1) (nextreg h-fr FRj 1))
6132                          (nextreg h-fr FRk 1))))
6133      ; TODO dual registers not referenced for profiling
6134      ((fr500 (unit u-float-dual-arith)))
6135 )
6136
6137 (define-pmacro (conditional-float-mul-with-add
6138                 name add_sub arg1 arg2 targ op ope comment)
6139   (dni name
6140        (comment)
6141        ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv) CONDITIONAL)
6142        (.str name "$pack $FRi,$FRj,$FRk,$CCi,$cond")
6143        (+ pack FRk op FRi CCi cond ope FRj)
6144        (if (eq CCi (or cond 2))
6145            (set targ (add_sub (mul arg1 arg2) targ)))
6146        ((fr500 (unit u-float-dual-arith)))
6147   )
6148 )
6149
6150 (conditional-float-mul-with-add cfmadds add FRi FRj FRk OP_6F OPE4_0 "conditional mul with add, single")
6151 (conditional-float-mul-with-add cfmsubs sub FRi FRj FRk OP_6F OPE4_1 "conditional mul with sub, single")
6152
6153 (define-pmacro (ne-float-mul-with-add name add_sub arg1 arg2 targ op ope comment)
6154   (dni name
6155        (comment)
6156        ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv) NON-EXCEPTING)
6157        (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
6158        (+ pack targ op arg1 ope arg2)
6159        (sequence ()
6160                  (c-call VOID "@cpu@_set_ne_index" (index-of targ))
6161                  (set targ (add_sub (mul arg1 arg2) targ)))
6162        ((fr500 (unit u-float-dual-arith)))
6163   )
6164 )
6165
6166 (ne-float-mul-with-add nfmadds add FRi FRj FRk OP_79 OPE1_2B "non excepting mul with add, single")
6167 (ne-float-mul-with-add nfmsubs sub FRi FRj FRk OP_79 OPE1_2C "non excepting mul with sub, single")
6168
6169 (define-pmacro (float-parallel-mul-add-semantics cond add_sub arg1 arg2 targ)
6170   (if cond
6171       (sequence ()
6172                 (set targ (mul arg1 arg2))
6173                 (set (nextreg h-fr targ 1)
6174                      (add_sub (nextreg h-fr arg1 1) (nextreg h-fr arg2 1)))))
6175 )
6176
6177 (define-pmacro (float-parallel-mul-add
6178                 name add_sub arg1 arg2 targ op ope comment)
6179   (dni name
6180        (comment)
6181        ((UNIT FM01) (FR500-MAJOR F-5) (MACH simple,tomcat,fr500,frv))
6182        (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
6183        (+ pack targ op arg1 ope arg2)
6184        (float-parallel-mul-add-semantics 1 add_sub arg1 arg2 targ)
6185        ((fr500 (unit u-float-dual-arith)))
6186   )
6187 )
6188
6189 (float-parallel-mul-add fmas add FRi FRj FRk OP_79 OPE1_0E "parallel mul/add, single")
6190 (float-parallel-mul-add fmss sub FRi FRj FRk OP_79 OPE1_0F "parallel mul/sub, single")
6191
6192 (define-pmacro (float-dual-parallel-mul-add-semantics add_sub arg1 arg2 targ)
6193   (sequence ()
6194             (set targ (mul arg1 arg2))
6195             (set (nextreg h-fr targ 1)
6196                  (add_sub (nextreg h-fr arg1 1) (nextreg h-fr arg2 1)))
6197             (set (nextreg h-fr targ 2)
6198                  (mul (nextreg h-fr arg1 2)     (nextreg h-fr arg2 2)))
6199             (set (nextreg h-fr targ 3)
6200                  (add_sub (nextreg h-fr arg1 3) (nextreg h-fr arg2 3))))
6201 )
6202
6203 (define-pmacro (float-dual-parallel-mul-add
6204                 name add_sub arg1 arg2 targ op ope comment)
6205   (dni name
6206        (comment)
6207        ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
6208        (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
6209        (+ pack targ op arg1 ope arg2)
6210        (float-dual-parallel-mul-add-semantics add_sub arg1 arg2 targ)
6211        ()
6212   )
6213 )
6214
6215 (float-dual-parallel-mul-add fdmas add FRi FRj FRk OP_79 OPE1_1C "dual parallel mul/add, single")
6216 (float-dual-parallel-mul-add fdmss sub FRi FRj FRk OP_79 OPE1_1D "dual parallel mul/sub, single")
6217
6218 (define-pmacro (ne-float-dual-parallel-mul-add-semantics add_sub arg1 arg2 targ)
6219   (sequence ()
6220             (c-call VOID "@cpu@_set_ne_index" (index-of targ))
6221             (c-call VOID "@cpu@_set_ne_index" (add (index-of targ) 1))
6222             (c-call VOID "@cpu@_set_ne_index" (add (index-of targ) 2))
6223             (c-call VOID "@cpu@_set_ne_index" (add (index-of targ) 3))
6224             (set targ (mul arg1 arg2))
6225             (set (nextreg h-fr targ 1)
6226                  (add_sub (nextreg h-fr arg1 1) (nextreg h-fr arg2 1)))
6227             (set (nextreg h-fr targ 2)
6228                  (mul (nextreg h-fr arg1 2)     (nextreg h-fr arg2 2)))
6229             (set (nextreg h-fr targ 3)
6230                  (add_sub (nextreg h-fr arg1 3) (nextreg h-fr arg2 3))))
6231 )
6232
6233 (define-pmacro (ne-float-dual-parallel-mul-add
6234                 name add_sub arg1 arg2 targ op ope comment)
6235   (dni name
6236        (comment)
6237        ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
6238        (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
6239        (+ pack targ op arg1 ope arg2)
6240        (ne-float-dual-parallel-mul-add-semantics add_sub arg1 arg2 targ)
6241        ()
6242   )
6243 )
6244
6245 (ne-float-dual-parallel-mul-add nfdmas add FRi FRj FRk OP_79 OPE1_3C "non excepting dual parallel mul/add, single")
6246 (ne-float-dual-parallel-mul-add nfdmss sub FRi FRj FRk OP_79 OPE1_3D "non excepting dual parallel mul/sub, single")
6247
6248 (define-pmacro (conditional-float-parallel-mul-add name add_sub op ope comment)
6249   (dni name
6250        (comment)
6251        ((UNIT FM01) (FR500-MAJOR F-5) CONDITIONAL (MACH simple,tomcat,fr500,frv))
6252        (.str name "$pack $FRi,$FRj,$FRk,$CCi,$cond")
6253        (+ pack FRk op FRi CCi cond ope FRj)
6254        (float-parallel-mul-add-semantics (eq CCi (or cond 2))
6255                                          add_sub FRi FRj FRk)
6256        ((fr500 (unit u-float-dual-arith)))
6257   )
6258 )
6259
6260 (conditional-float-parallel-mul-add cfmas add OP_6F OPE4_2 "conditional parallel mul/add, single")
6261 (conditional-float-parallel-mul-add cfmss sub OP_6F OPE4_3 "conditional parallel mul/sub, single")
6262
6263 (define-pmacro (float-parallel-mul-add-double-semantics add_sub arg1 arg2 targ)
6264   (sequence ()
6265             (set targ (ftrunc SF (mul DF (fext DF arg1) (fext DF arg2))))
6266             (set (nextreg h-fr targ 1)
6267                  (ftrunc SF (add_sub DF
6268                                      (fext DF (nextreg h-fr arg1 1))
6269                                      (fext DF (nextreg h-fr arg2 1))))))
6270 )
6271
6272 (define-pmacro (float-parallel-mul-add-double
6273                 name add_sub arg1 arg2 targ op ope comment)
6274   (dni name
6275        (comment)
6276        ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
6277        (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
6278        (+ pack targ op arg1 ope arg2)
6279        (float-parallel-mul-add-double-semantics add_sub arg1 arg2 targ)
6280        ()
6281   )
6282 )
6283
6284 (float-parallel-mul-add-double fmad add FRi FRj FRk OP_7A OPE1_0E "parallel mul/add, double")
6285 (float-parallel-mul-add-double fmsd sub FRi FRj FRk OP_7A OPE1_0F "parallel mul/sub, double")
6286
6287 (define-pmacro (ne-float-parallel-mul-add name add_sub op ope comment)
6288   (dni name
6289        (comment)
6290        ((UNIT FM01) (FR500-MAJOR F-5) (MACH simple,tomcat,fr500,frv))
6291        (.str name "$pack $FRi,$FRj,$FRk")
6292        (+ pack FRk op FRi ope FRj)
6293        (sequence ()
6294                  (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
6295                  (set FRk (mul FRi FRj))
6296                  (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
6297                  (set (nextreg h-fr FRk 1)
6298                       (add_sub (nextreg h-fr FRi 1) (nextreg h-fr FRj 1))))
6299        ((fr500 (unit u-float-dual-arith)))
6300   )
6301 )
6302
6303 (ne-float-parallel-mul-add nfmas add OP_79 OPE1_2E "ne parallel mul/add,single")
6304 (ne-float-parallel-mul-add nfmss sub OP_79 OPE1_2F "ne parallel mul/sub,single")
6305
6306 (define-pmacro (float-dual-arith name major oper1 oper2 op ope attr comment)
6307   (dni name
6308        (comment)
6309        ((UNIT FM01) (FR500-MAJOR major) attr)
6310        (.str name "$pack $FRi,$FRj,$FRk")
6311        (+ pack FRk op FRi ope FRj)
6312        (sequence ()
6313                  (set FRk (oper1 FRi FRj))
6314                  (set (nextreg h-fr FRk 1)
6315                       (oper2 (nextreg h-fr FRi 1) (nextreg h-fr FRj 1))))
6316        ((fr500 (unit u-float-dual-arith)))
6317   )
6318 )
6319
6320 (float-dual-arith fdadds F-6 add add OP_79 OPE1_16 (MACH simple,tomcat,fr500,frv) "dual add, single")
6321 (float-dual-arith fdsubs F-6 sub sub OP_79 OPE1_17 (MACH simple,tomcat,fr500,frv) "dual sub, single")
6322 (float-dual-arith fdmuls F-7 mul mul OP_79 OPE1_18 (MACH simple,tomcat,fr500,frv) "dual mul, single")
6323 (float-dual-arith fddivs F-7 div div OP_79 OPE1_19 (MACH frv) "dual div,single")
6324 (float-dual-arith fdsads F-6 add sub OP_79 OPE1_1E (MACH simple,tomcat,fr500,frv) "dual add/sub, single")
6325
6326 (dni fdmulcs
6327      "Float dual cross multiply single"
6328      ((UNIT FM01) (FR500-MAJOR F-7) (MACH simple,tomcat,fr500,frv))
6329      "fdmulcs$pack $FRi,$FRj,$FRk"
6330      (+ pack FRk OP_79 FRi OPE1_1F FRj)
6331      (sequence ()
6332                (set FRk (mul FRi (nextreg h-fr FRj 1)))
6333                (set (nextreg h-fr FRk 1) (mul (nextreg h-fr FRi 1) FRj)))
6334      ((fr500 (unit u-float-dual-arith)))
6335 )
6336
6337 (dni nfdmulcs
6338      "NE float dual cross multiply single"
6339      ((UNIT FM01) (FR500-MAJOR F-7) (MACH simple,tomcat,fr500,frv))
6340      "nfdmulcs$pack $FRi,$FRj,$FRk"
6341      (+ pack FRk OP_79 FRi OPE1_3F FRj)
6342      (sequence ()
6343                (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
6344                (set FRk (mul FRi (nextreg h-fr FRj 1)))
6345                (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
6346                (set (nextreg h-fr FRk 1) (mul (nextreg h-fr FRi 1) FRj)))
6347      ((fr500 (unit u-float-dual-arith)))
6348 )
6349
6350 (define-pmacro (ne-float-dual-arith name major oper1 oper2 op ope attr comment)
6351   (dni name
6352        (comment)
6353        ((UNIT FM01) (FR500-MAJOR major) attr)
6354        (.str name "$pack $FRi,$FRj,$FRk")
6355        (+ pack FRk op FRi ope FRj)
6356        (sequence ()
6357                  (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
6358                  (set FRk (oper1 FRi FRj))
6359                  (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
6360                  (set (nextreg h-fr FRk 1)
6361                       (oper2 (nextreg h-fr FRi 1) (nextreg h-fr FRj 1))))
6362        ((fr500 (unit u-float-dual-arith)))
6363   )
6364 )
6365
6366 (ne-float-dual-arith nfdadds F-6 add add OP_79 OPE1_36 (MACH simple,tomcat,fr500,frv) "ne dual add, single")
6367 (ne-float-dual-arith nfdsubs F-6 sub sub OP_79 OPE1_37 (MACH simple,tomcat,fr500,frv) "ne dual sub, single")
6368 (ne-float-dual-arith nfdmuls F-7 mul mul OP_79 OPE1_38 (MACH simple,tomcat,fr500,frv) "ne dual mul, single")
6369 (ne-float-dual-arith nfddivs F-7 div div OP_79 OPE1_39 (MACH frv) "ne dual div,single")
6370 (ne-float-dual-arith nfdsads F-6 add sub OP_79 OPE1_3E (MACH simple,tomcat,fr500,frv) "ne dual add/sub, single")
6371
6372 (dni nfdcmps
6373      "non-excepting dual float compare"
6374      ((UNIT FM01) (FR500-MAJOR F-6) (MACH simple,tomcat,frv))
6375      "nfdcmps$pack $FRi,$FRj,$FCCi_2"
6376      (+ pack (cond-null) FCCi_2 OP_79 FRi OPE1_3A FRj)
6377      (sequence ()
6378                (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
6379                (compare-and-set-fcc FRi FRj FCCi_2)
6380                (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
6381                (compare-and-set-fcc (nextreg h-fr FRi 1) (nextreg h-fr FRj 1)
6382                                     (nextreg h-fccr FCCi_2 1)))
6383      ((fr500 (unit u-float-dual-compare)))
6384 )
6385
6386 ; Media Instructions
6387 ;
6388 (define-pmacro (halfword hilo arg offset)
6389   (reg (.sym h-fr_ hilo) (add (index-of arg) offset)))
6390
6391 (dni mhsetlos
6392      "Media set lower signed 12 bits"
6393      ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
6394      "mhsetlos$pack $u12,$FRklo"
6395      (+ pack FRklo OP_78 OPE1_20 u12)
6396      (set FRklo u12)
6397      ((fr400 (unit u-media-hilo)))
6398 )
6399
6400 (dni mhsethis
6401      "Media set upper signed 12 bits"
6402      ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
6403      "mhsethis$pack $u12,$FRkhi"
6404      (+ pack FRkhi OP_78 OPE1_22 u12)
6405      (set FRkhi u12)
6406      ((fr400 (unit u-media-hilo)))
6407 )
6408
6409 (dni mhdsets
6410      "Media dual set halfword signed 12 bits"
6411      ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
6412      "mhdsets$pack $u12,$FRintk"
6413      (+ pack FRintk OP_78 OPE1_24 u12)
6414      (sequence ()
6415                ; hack to get FRintk passed to modelling functions
6416                (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
6417                (set (halfword hi FRintk 0) u12)
6418                (set (halfword lo FRintk 0) u12))
6419      ((fr400 (unit u-media-1)))
6420 )
6421
6422 (define-pmacro (set-5-semantics target value)
6423   (sequence ((HI tmp))
6424             (set tmp target)
6425             (set tmp (and tmp #x07ff))
6426             (set tmp (or tmp (sll (and s5 #x1f) 11)))
6427             (set target tmp))
6428 )
6429
6430 (define-pmacro (media-set-5 name hilo op ope comment)
6431   (dni name
6432        (comment)
6433        ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
6434        (.str name "$pack $s5,$FRk" hilo)
6435        (+ pack (.sym FRk hilo) op (FRi-null) ope (misc-null-11) s5)
6436        (set-5-semantics (.sym FRk hilo) s5)
6437        ((fr400 (unit u-media-hilo)))
6438   )
6439 )
6440
6441 (media-set-5 mhsetloh lo OP_78 OPE1_21 "Media set upper 5 bits lo")
6442 (media-set-5 mhsethih hi OP_78 OPE1_23 "Media set upper 5 bits hi")
6443
6444 (dni mhdseth
6445      "Media dual set halfword upper 5 bits"
6446      ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
6447      "mhdseth$pack $s5,$FRintk"
6448      (+ pack FRintk OP_78 (FRi-null) OPE1_25 (misc-null-11) s5)
6449      (sequence ()
6450                ; hack to get FRintk passed to modelling functions
6451                (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
6452                (set-5-semantics (halfword hi FRintk 0) s5)
6453                (set-5-semantics (halfword lo FRintk 0) s5))
6454      ((fr400 (unit u-media-1)))
6455 )
6456
6457 (define-pmacro (media-logic-r-r name operation op ope comment)
6458   (dni name
6459        (comment)
6460        ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
6461        (.str name "$pack $FRinti,$FRintj,$FRintk")
6462        (+ pack FRintk op FRinti ope FRintj)
6463        (set FRintk (operation FRinti FRintj))
6464        ((fr400 (unit u-media-1))
6465         (fr500 (unit u-media)))
6466   )
6467 )
6468
6469 (media-logic-r-r mand and OP_7B OPE1_00 "and reg/reg")
6470 (media-logic-r-r mor  or  OP_7B OPE1_01 "or  reg/reg")
6471 (media-logic-r-r mxor xor OP_7B OPE1_02 "xor reg/reg")
6472
6473 (define-pmacro (conditional-media-logic name operation op ope comment)
6474   (dni name
6475        (comment)
6476        ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1) CONDITIONAL)
6477        (.str name "$pack $FRinti,$FRintj,$FRintk,$CCi,$cond")
6478        (+ pack FRintk op FRinti CCi cond ope FRintj)
6479        (if (eq CCi (or cond 2))
6480            (set FRintk (operation FRinti FRintj)))
6481        ((fr400 (unit u-media-1))
6482         (fr500 (unit u-media)))
6483   )
6484 )
6485
6486 (conditional-media-logic cmand and OP_70 OPE4_0 "conditional and reg/reg")
6487 (conditional-media-logic cmor  or  OP_70 OPE4_1 "conditional or  reg/reg")
6488 (conditional-media-logic cmxor xor OP_70 OPE4_2 "conditional xor reg/reg")
6489
6490 (dni mnot
6491      ("mnot")
6492      ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
6493      ("mnot$pack $FRintj,$FRintk")
6494      (+ pack FRintk OP_7B (rs-null) OPE1_03 FRintj)
6495      (set FRintk (inv FRintj))
6496      ((fr400 (unit u-media-1))
6497       (fr500 (unit u-media)))
6498 )
6499
6500 (dni cmnot
6501      ("cmnot")
6502      ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1) CONDITIONAL)
6503      ("cmnot$pack $FRintj,$FRintk,$CCi,$cond")
6504      (+ pack FRintk OP_70 (rs-null) CCi cond OPE4_3 FRintj)
6505      (if (eq CCi (or cond 2))
6506          (set FRintk (inv FRintj)))
6507      ((fr400 (unit u-media-1))
6508       (fr500 (unit u-media)))
6509 )
6510
6511 (define-pmacro (media-rotate-r-r name operation op ope comment)
6512   (dni name
6513        (comment)
6514        ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
6515        (.str name "$pack $FRinti,$u6,$FRintk")
6516        (+ pack FRintk op FRinti ope u6)
6517        (set FRintk (operation FRinti (and u6 #x1f)))
6518        ((fr400 (unit u-media-3))
6519         (fr500 (unit u-media)))
6520   )
6521 )
6522
6523 (media-rotate-r-r mrotli rol OP_7B OPE1_04 "rotate left reg/reg")
6524 (media-rotate-r-r mrotri ror OP_7B OPE1_05 "rotate right reg/reg")
6525
6526 (define-pmacro (media-cut-r-r name arg op ope comment)
6527   (dni name
6528        (comment)
6529        ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2))
6530        (.str name "$pack $FRinti,$" arg ",$FRintk")
6531        (+ pack FRintk op FRinti ope arg)
6532        (set FRintk (c-call SI "@cpu@_cut" FRinti (nextreg h-fr_int FRinti 1) arg))
6533        ((fr400 (unit u-media-3))
6534         (fr500 (unit u-media)))
6535   )
6536 )
6537
6538 (media-cut-r-r mwcut  FRintj OP_7B OPE1_06 "media cut")
6539 (media-cut-r-r mwcuti u6     OP_7B OPE1_07 "media cut")
6540
6541 (define-pmacro (media-cut-acc name arg op ope comment)
6542   (dni name
6543        (comment)
6544        ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
6545        (.str name "$pack $ACC40Si,$" arg ",$FRintk")
6546        (+ pack FRintk op ACC40Si ope arg)
6547        (set FRintk (c-call SI "@cpu@_media_cut" ACC40Si arg))
6548        ((fr400 (unit u-media-4))
6549         (fr500 (unit u-media)))
6550   )
6551 )
6552
6553 (media-cut-acc mcut  FRintj OP_7B OPE1_2C "media accumulator cut reg")
6554 (media-cut-acc mcuti s6     OP_7B OPE1_2E "media accumulator cut immed")
6555
6556 (define-pmacro (media-cut-acc-ss name arg op ope comment)
6557   (dni name
6558        (comment)
6559        ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
6560        (.str name "$pack $ACC40Si,$" arg ",$FRintk")
6561        (+ pack FRintk op ACC40Si ope arg)
6562        (set FRintk (c-call SI "@cpu@_media_cut_ss" ACC40Si arg))
6563        ((fr400 (unit u-media-4))
6564         (fr500 (unit u-media)))
6565   )
6566 )
6567
6568 (media-cut-acc-ss mcutss  FRintj OP_7B OPE1_2D "media accumulator cut reg with saturation")
6569 (media-cut-acc-ss mcutssi s6     OP_7B OPE1_2F "media accumulator cut immed with saturation")
6570
6571 ; Dual Media Instructions
6572 ;
6573 (define-pmacro (register-unaligned register alignment)
6574   (and (index-of register) (sub alignment 1))
6575 )
6576
6577 (dni mdcutssi
6578      "Media dual cut with signed saturation"
6579      ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
6580      "mdcutssi$pack $ACC40Si,$s6,$FRintk"
6581      (+ pack FRintk OP_78 ACC40Si OPE1_0E s6)
6582      (if (register-unaligned ACC40Si 2)
6583          (c-call VOID "@cpu@_media_acc_not_aligned")
6584          (if (register-unaligned FRintk 2)
6585              (c-call VOID "@cpu@_media_register_not_aligned")
6586              (sequence ()
6587                        (set FRintk (c-call SI "@cpu@_media_cut_ss" ACC40Si s6))
6588                        (set (nextreg h-fr_int FRintk 1)
6589                             (c-call SI "@cpu@_media_cut_ss"
6590                                     (nextreg h-acc40S ACC40Si 1) s6)))))
6591      ((fr400 (unit u-media-4-acc-dual)))
6592 )
6593
6594 ; The (add (xxxx) (mul arg 0)) is a hack to get a reference to arg generated
6595 ; so it will be passed to the unit modelers.   YUCK!!!!!
6596 (define-pmacro (extract-hilo reg1 off1 reg2 off2 arg1hi arg1lo arg2hi arg2lo)
6597   (sequence ()
6598             (set arg1hi (add (halfword hi reg1 off1) (mul reg1 0)))
6599             (set arg1lo (add (halfword lo reg1 off1) (mul reg1 0)))
6600             (set arg2hi (add (halfword hi reg2 off2) (mul reg2 0)))
6601             (set arg2lo (add (halfword lo reg2 off2) (mul reg2 0))))
6602 )
6603
6604 (dni maveh
6605      "Media dual average"
6606      ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
6607      "maveh$pack $FRinti,$FRintj,$FRintk"
6608      (+ pack FRintk OP_7B FRinti OPE1_08 FRintj)
6609      (set FRintk (c-call SI "@cpu@_media_average" FRinti FRintj))
6610      ((fr400 (unit u-media-1))
6611       (fr500 (unit u-media)))
6612 )
6613
6614 (define-pmacro (media-dual-shift name operation op ope profile comment)
6615   (dni name
6616        (comment)
6617        ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
6618        (.str name "$pack $FRinti,$u6,$FRintk")
6619        (+ pack FRintk op FRinti ope u6)
6620        (sequence ()
6621                  ; hack to get these referenced for profiling
6622                  (set FRinti (c-raw-call SI "frv_ref_SI" FRinti))
6623                  (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
6624                  (set (halfword hi FRintk 0)
6625                       (operation (halfword hi FRinti 0) (and u6 #xf)))
6626                  (set (halfword lo FRintk 0)
6627                       (operation (halfword lo FRinti 0) (and u6 #xf))))
6628        profile
6629   )
6630 )
6631
6632 (media-dual-shift msllhi sll OP_7B OPE1_09
6633                   ((fr400 (unit u-media-3)) (fr500 (unit u-media)))
6634                   "Media dual shift left  logical")
6635 (media-dual-shift msrlhi srl OP_7B OPE1_0A
6636                   ((fr400 (unit u-media-3)) (fr500 (unit u-media)))
6637                   "Media dual shift right logical")
6638 (media-dual-shift msrahi sra OP_7B OPE1_0B
6639                   ((fr400 (unit u-media-6)) (fr500 (unit u-media)))
6640                   "Media dual shift right arithmetic")
6641
6642 (define-pmacro (media-dual-word-rotate-r-r name operation op ope comment)
6643   (dni name
6644        (comment)
6645        ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
6646        (.str name "$pack $FRinti,$s6,$FRintk")
6647        (+ pack FRintk op FRinti ope s6)
6648        (if (orif (register-unaligned FRinti 2)
6649                  (register-unaligned FRintk 2))
6650            (c-call VOID "@cpu@_media_register_not_aligned")
6651            (sequence ()
6652                      (set FRintk (operation FRinti (and s6 #x1f)))
6653                      (set (nextreg h-fr_int FRintk 1)
6654                           (operation (nextreg h-fr_int FRinti 1)
6655                                      (and s6 #x1f)))))
6656        ((fr400 (unit u-media-3-quad)))
6657   )
6658 )
6659
6660 (media-dual-word-rotate-r-r mdrotli rol OP_78 OPE1_0B "rotate left reg/reg")
6661
6662 (dni mcplhi
6663      "Media dual couple, halfword"
6664      ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
6665      "mcplhi$pack $FRinti,$u6,$FRintk"
6666      (+ pack FRintk OP_78 FRinti OPE1_0C u6)
6667      (sequence ((HI arg1) (HI arg2) (HI shift))
6668                (set FRinti (c-raw-call SI "frv_ref_SI" FRinti))
6669                (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
6670                (set shift (and u6 #xf))
6671                (set arg1 (sll (halfword hi FRinti 0) shift))
6672                (if (ne shift 0)
6673                    (sequence ()
6674                              (set arg2 (halfword hi FRinti 1))
6675                              (set arg2 (srl HI (sll HI arg2 (sub 15 shift))
6676                                             (sub 15 shift)))
6677                              (set arg1 (or HI arg1 arg2))))
6678                (set (halfword hi FRintk 0) arg1))
6679      ((fr400 (unit u-media-3-dual)))
6680 )
6681
6682 (dni mcpli
6683      "Media dual couple, word"
6684      ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
6685      "mcpli$pack $FRinti,$u6,$FRintk"
6686      (+ pack FRintk OP_78 FRinti OPE1_0D u6)
6687      (sequence ((SI tmp) (SI shift))
6688                (set shift (and u6 #x1f))
6689                (set tmp (sll FRinti shift))
6690                (if (ne shift 0)
6691                    (sequence ((SI tmp1))
6692                              (set tmp1 (srl (sll (nextreg h-fr_int FRinti 1)
6693                                                  (sub 31 shift))
6694                                             (sub 31 shift)))
6695                              (set tmp (or tmp tmp1))))
6696                (set FRintk tmp))
6697      ((fr400 (unit u-media-3-dual)))
6698 )
6699
6700 (define-pmacro (saturate arg max min result)
6701   (if (gt arg max)
6702       (set result max)
6703       (if (lt arg min)
6704           (set result min)
6705           (set result arg)))
6706 )
6707
6708 (dni msaths
6709      "Media dual saturation signed"
6710      ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
6711      "msaths$pack $FRinti,$FRintj,$FRintk"
6712      (+ pack FRintk OP_7B FRinti OPE1_0C FRintj)
6713      (sequence ((HI argihi) (HI argilo) (HI argjhi) (HI argjlo))
6714                (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
6715                (saturate argihi argjhi (inv argjhi) (halfword hi FRintk 0))
6716                (saturate argilo argjlo (inv argjlo) (halfword lo FRintk 0)))
6717      ((fr400 (unit u-media-1))
6718       (fr500 (unit u-media)))
6719 )
6720
6721 (dni mqsaths
6722      "Media quad saturation signed"
6723      ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
6724      "mqsaths$pack $FRinti,$FRintj,$FRintk"
6725      (+ pack FRintk OP_78 FRinti OPE1_0F FRintj)
6726      (if (orif (register-unaligned FRinti 2)
6727                (orif (register-unaligned FRintj 2)
6728                      (register-unaligned FRintk 2)))
6729          (c-call VOID "@cpu@_media_register_not_aligned")
6730          (sequence ((HI argihi) (HI argilo) (HI argjhi) (HI argjlo))
6731                    ; hack to get FRintk referenced as a target for profiling
6732                    (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
6733                    (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
6734                    (saturate argihi argjhi (inv argjhi) (halfword hi FRintk 0))
6735                    (saturate argilo argjlo (inv argjlo) (halfword lo FRintk 0))
6736                    (extract-hilo FRinti 1 FRintj 1 argihi argilo argjhi argjlo)
6737                    (saturate argihi argjhi (inv argjhi) (halfword hi FRintk 1))
6738                    (saturate argilo argjlo (inv argjlo) (halfword lo FRintk 1))))
6739      ((fr400 (unit u-media-1-quad)))
6740 )
6741
6742 (define-pmacro (saturate-unsigned arg max result)
6743   (if (gt arg max)
6744       (set result max)
6745       (set result arg))
6746 )
6747
6748 (dni msathu
6749      "Media dual saturation unsigned"
6750      ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
6751      "msathu$pack $FRinti,$FRintj,$FRintk"
6752      (+ pack FRintk OP_7B FRinti OPE1_0D FRintj)
6753      (sequence ((UHI argihi) (UHI argilo) (UHI argjhi) (UHI argjlo))
6754                (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
6755                (saturate-unsigned argihi argjhi (halfword hi FRintk 0))
6756                (saturate-unsigned argilo argjlo (halfword lo FRintk 0)))
6757      ((fr400 (unit u-media-1))
6758       (fr500 (unit u-media)))
6759 )
6760
6761 (define-pmacro (media-dual-compare name mode op ope comment)
6762   (dni name
6763        (comment)
6764        ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
6765        (.str name "$pack $FRinti,$FRintj,$FCCk")
6766        (+ pack (cond-null) FCCk op FRinti ope FRintj)
6767        (if (register-unaligned FCCk 2)
6768            (c-call VOID "@cpu@_media_cr_not_aligned")
6769            (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
6770                      (extract-hilo FRinti 0 FRintj 0
6771                                    argihi argilo argjhi argjlo)
6772                      (compare-and-set-fcc argihi argjhi FCCk)
6773                      (compare-and-set-fcc argilo argjlo (nextreg h-fccr FCCk 1))))
6774        ; TODO - doesn't handle second FCC
6775        ((fr400 (unit u-media-7))
6776         (fr500 (unit u-media)))
6777   )
6778 )
6779
6780 (media-dual-compare mcmpsh HI  OP_7B OPE1_0E "Media dual compare signed")
6781 (media-dual-compare mcmpuh UHI OP_7B OPE1_0F "Media dual compare unsigned")
6782
6783 ; Bits for the MSR.SIE field
6784 (define-pmacro (msr-sie-nil)      0)
6785 (define-pmacro (msr-sie-fri-hi)   8)
6786 (define-pmacro (msr-sie-fri-lo)   4)
6787 (define-pmacro (msr-sie-fri-1-hi) 2)
6788 (define-pmacro (msr-sie-fri-1-lo) 1)
6789 (define-pmacro (msr-sie-acci)     8)
6790 (define-pmacro (msr-sie-acci-1)   4)
6791 (define-pmacro (msr-sie-acci-2)   2)
6792 (define-pmacro (msr-sie-acci-3)   1)
6793
6794 (define-pmacro (saturate-v arg max min sie result)
6795   (if (gt DI arg max)
6796       (sequence ()
6797                 (set result max)
6798                 (c-call VOID "@cpu@_media_overflow" sie))
6799       (if (lt DI arg min)
6800           (sequence ()
6801                     (set result min)
6802                     (c-call VOID "@cpu@_media_overflow" sie))
6803           (set result arg)))
6804 )
6805
6806 (dni mabshs
6807      "Media dual absolute value, halfword"
6808      ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
6809      "mabshs$pack $FRintj,$FRintk"
6810      (+ pack FRintk OP_78 (FRi-null) OPE1_0A FRintj)
6811      (sequence ((HI arghi) (HI arglo))
6812                (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
6813                (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
6814                (set arghi (halfword hi FRintj 0))
6815                (set arglo (halfword lo FRintj 0))
6816                (saturate-v (abs arghi) 32767 -32768 (msr-sie-fri-hi)
6817                            (halfword hi FRintk 0))
6818                (saturate-v (abs arglo) 32767 -32768 (msr-sie-fri-lo)
6819                            (halfword lo FRintk 0)))
6820      ((fr400 (unit u-media-1)))
6821 )
6822
6823 (define-pmacro (media-arith-sat-semantics
6824                 operation arg1 arg2 res mode max min sie)
6825   (sequence ((DI tmp))
6826             (set tmp (operation arg1 arg2))
6827             (saturate-v tmp max min sie res))
6828 )
6829
6830 (define-pmacro (media-dual-arith-sat-semantics operation mode max min)
6831   (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
6832             (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
6833             (media-arith-sat-semantics operation argihi argjhi
6834                                        (halfword hi FRintk 0) mode max min
6835                                        (msr-sie-fri-hi))
6836             (media-arith-sat-semantics operation argilo argjlo
6837                                        (halfword lo FRintk 0) mode max min
6838                                        (msr-sie-fri-lo)))
6839 )
6840
6841 (define-pmacro (media-dual-arith-sat name operation mode max min op ope comment)
6842   (dni name
6843        (comment)
6844        ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
6845        (.str name "$pack $FRinti,$FRintj,$FRintk")
6846        (+ pack FRintk op FRinti ope FRintj)
6847        (media-dual-arith-sat-semantics operation mode max min)
6848        ((fr400 (unit u-media-1))
6849         (fr500 (unit u-media)))
6850   )
6851 )
6852
6853 (media-dual-arith-sat maddhss add  HI 32767 -32768 OP_7B OPE1_10 "Media dual add signed with saturation")
6854 (media-dual-arith-sat maddhus add UHI 65535      0 OP_7B OPE1_11 "Media dual add unsigned with saturation")
6855
6856 (media-dual-arith-sat msubhss sub  HI 32767 -32768 OP_7B OPE1_12 "Media dual sub signed with saturation")
6857 (media-dual-arith-sat msubhus sub UHI 65535      0 OP_7B OPE1_13 "Media dual sub unsigned with saturation")
6858
6859 (define-pmacro (conditional-media-dual-arith-sat
6860                 name operation mode max min op ope comment)
6861   (dni name
6862        (comment)
6863        ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1) CONDITIONAL)
6864        (.str name "$pack $FRinti,$FRintj,$FRintk,$CCi,$cond")
6865        (+ pack FRintk op FRinti CCi cond ope FRintj)
6866        (if (eq CCi (or cond 2))
6867            (media-dual-arith-sat-semantics operation mode max min))
6868        ((fr400 (unit u-media-1))
6869         (fr500 (unit u-media)))
6870   )
6871 )
6872
6873 (conditional-media-dual-arith-sat cmaddhss add  HI 32767 -32768 OP_71 OPE4_0 "Conditional Media dual add signed with saturation")
6874 (conditional-media-dual-arith-sat cmaddhus add UHI 65535      0 OP_71 OPE4_1 "Conditional Media dual add unsigned with saturation")
6875
6876 (conditional-media-dual-arith-sat cmsubhss sub  HI 32767 -32768 OP_71 OPE4_2 "Conditional Media dual sub signed with saturation")
6877 (conditional-media-dual-arith-sat cmsubhus sub UHI 65535      0 OP_71 OPE4_3 "Conditional Media dual sub unsigned with saturation")
6878
6879 (define-pmacro (media-quad-arith-sat-semantics cond operation mode max min)
6880   (if (orif (register-unaligned FRinti 2)
6881             (orif (register-unaligned FRintj 2)
6882                   (register-unaligned FRintk 2)))
6883       (c-call VOID "@cpu@_media_register_not_aligned")
6884       (if cond
6885           (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
6886                     ; hack to get FRintk referenced as a target for profiling
6887                     (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
6888                     (extract-hilo FRinti 0 FRintj 0
6889                                   argihi argilo argjhi argjlo)
6890                     (media-arith-sat-semantics operation argihi argjhi
6891                                                (halfword hi FRintk 0) mode
6892                                                max min (msr-sie-fri-hi))
6893                     (media-arith-sat-semantics operation argilo argjlo
6894                                                (halfword lo FRintk 0) mode
6895                                                max min (msr-sie-fri-lo))
6896                     (extract-hilo FRinti 1 FRintj 1
6897                                   argihi argilo argjhi argjlo)
6898                     (media-arith-sat-semantics operation argihi argjhi
6899                                                (halfword hi FRintk 1) mode
6900                                                max min  (msr-sie-fri-1-hi))
6901                     (media-arith-sat-semantics operation argilo argjlo
6902                                                (halfword lo FRintk 1) mode
6903                                                max min (msr-sie-fri-1-lo)))))
6904 )
6905
6906 (define-pmacro (media-quad-arith-sat name operation mode max min op ope comment)
6907   (dni name
6908        (comment)
6909        ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-2))
6910        (.str name "$pack $FRinti,$FRintj,$FRintk")
6911        (+ pack FRintk op FRinti ope FRintj)
6912        (media-quad-arith-sat-semantics 1 operation mode max min)
6913        ((fr400 (unit u-media-1-quad))
6914         (fr500 (unit u-media-quad-arith)))
6915   )
6916 )
6917
6918 (media-quad-arith-sat mqaddhss add  HI 32767 -32768 OP_7B OPE1_18 "Media quad add signed with saturation")
6919 (media-quad-arith-sat mqaddhus add UHI 65535      0 OP_7B OPE1_19 "Media quad add unsigned with saturation")
6920
6921 (media-quad-arith-sat mqsubhss sub  HI 32767 -32768 OP_7B OPE1_1A "Media quad sub signed with saturation")
6922 (media-quad-arith-sat mqsubhus sub UHI 65535      0 OP_7B OPE1_1B "Media quad sub unsigned with saturation")
6923
6924 (define-pmacro (conditional-media-quad-arith-sat
6925                 name operation mode max min op ope comment)
6926   (dni name
6927        (comment)
6928        ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-2) CONDITIONAL)
6929        (.str name "$pack $FRinti,$FRintj,$FRintk,$CCi,$cond")
6930        (+ pack FRintk op FRinti CCi cond ope FRintj)
6931        (media-quad-arith-sat-semantics (eq CCi (or cond 2))
6932                                        operation mode max min)
6933        ((fr400 (unit u-media-1-quad))
6934         (fr500 (unit u-media-quad-arith)))
6935   )
6936 )
6937
6938 (conditional-media-quad-arith-sat cmqaddhss add  HI 32767 -32768 OP_73 OPE4_0 "Conditional Media quad add signed with saturation")
6939 (conditional-media-quad-arith-sat cmqaddhus add UHI 65535      0 OP_73 OPE4_1 "Conditional Media quad add unsigned with saturation")
6940
6941 (conditional-media-quad-arith-sat cmqsubhss sub  HI 32767 -32768 OP_73 OPE4_2 "Conditional Media quad sub signed with saturation")
6942 (conditional-media-quad-arith-sat cmqsubhus sub UHI 65535      0 OP_73 OPE4_3 "Conditional Media quad sub unsigned with saturation")
6943
6944 (define-pmacro (media-acc-arith-sat name operation mode max min op ope comment)
6945   (dni name
6946        (comment)
6947        ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
6948        (.str name "$pack $ACC40Si,$ACC40Sk")
6949        (+ pack ACC40Sk op ACC40Si ope (ACCj-null))
6950        (if (register-unaligned ACC40Si 2)
6951            (c-call VOID "@cpu@_media_acc_not_aligned")
6952            (media-arith-sat-semantics operation ACC40Si
6953                                       (nextreg h-acc40S ACC40Si 1)
6954                                       ACC40Sk mode max min (msr-sie-acci)))
6955        ((fr400 (unit u-media-2-acc)))
6956   )
6957 )
6958
6959 (media-acc-arith-sat maddaccs add DI #x7fffffffff (inv DI #x7fffffffff)
6960                      OP_78 OPE1_04 "Media accumulator addition")
6961 (media-acc-arith-sat msubaccs sub DI #x7fffffffff (inv DI #x7fffffffff)
6962                      OP_78 OPE1_05 "Media accumulator subtraction")
6963
6964 (define-pmacro (media-dual-acc-arith-sat name operation mode max min op ope
6965                                          comment)
6966   (dni name
6967        (comment)
6968        ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
6969        (.str name "$pack $ACC40Si,$ACC40Sk")
6970        (+ pack ACC40Sk op ACC40Si ope (ACCj-null))
6971        (if (register-unaligned ACC40Si 4)
6972            (c-call VOID "@cpu@_media_acc_not_aligned")
6973            (if (register-unaligned ACC40Sk 2)
6974                (c-call VOID "@cpu@_media_acc_not_aligned")
6975                (sequence ()
6976                          (media-arith-sat-semantics operation ACC40Si
6977                                                     (nextreg h-acc40S ACC40Si 1)
6978                                                     ACC40Sk mode max min
6979                                                     (msr-sie-acci))
6980                          (media-arith-sat-semantics operation
6981                                                     (nextreg h-acc40S ACC40Si 2)
6982                                                     (nextreg h-acc40S ACC40Si 3)
6983                                                     (nextreg h-acc40S ACC40Sk 1)
6984                                                     mode max min
6985                                                     (msr-sie-acci-1)))))
6986        ((fr400 (unit u-media-2-acc-dual)))
6987   )
6988 )
6989
6990 (media-dual-acc-arith-sat mdaddaccs add DI #x7fffffffff (inv DI #x7fffffffff)
6991                           OP_78 OPE1_06 "Media accumulator addition")
6992 (media-dual-acc-arith-sat mdsubaccs sub DI #x7fffffffff (inv DI #x7fffffffff)
6993                           OP_78 OPE1_07 "Media accumulator subtraction")
6994
6995 (dni masaccs
6996      "Media add and subtract signed accumulator with saturation"
6997        ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
6998        "masaccs$pack $ACC40Si,$ACC40Sk"
6999        (+ pack ACC40Sk OP_78 ACC40Si OPE1_08 (ACCj-null))
7000        (if (register-unaligned ACC40Si 2)
7001            (c-call VOID "@cpu@_media_acc_not_aligned")
7002            (if (register-unaligned ACC40Sk 2)
7003                (c-call VOID "@cpu@_media_acc_not_aligned")
7004                (sequence ()
7005                          (media-arith-sat-semantics add ACC40Si
7006                                                     (nextreg h-acc40S ACC40Si 1)
7007                                                     ACC40Sk DI
7008                                                     #x7fffffffff
7009                                                     (inv DI #x7fffffffff)
7010                                                     (msr-sie-acci))
7011                          (media-arith-sat-semantics sub ACC40Si
7012                                                     (nextreg h-acc40S ACC40Si 1)
7013                                                     (nextreg h-acc40S ACC40Sk 1)
7014                                                     DI
7015                                                     #x7fffffffff
7016                                                     (inv DI #x7fffffffff)
7017                                                     (msr-sie-acci-1)))))
7018        ((fr400 (unit u-media-2-add-sub)))
7019   )
7020
7021 (dni mdasaccs
7022      "Media add and subtract signed accumulator with saturation"
7023        ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
7024        "mdasaccs$pack $ACC40Si,$ACC40Sk"
7025        (+ pack ACC40Sk OP_78 ACC40Si OPE1_09 (ACCj-null))
7026        (if (register-unaligned ACC40Si 4)
7027            (c-call VOID "@cpu@_media_acc_not_aligned")
7028            (if (register-unaligned ACC40Sk 4)
7029                (c-call VOID "@cpu@_media_acc_not_aligned")
7030                (sequence ()
7031                          (media-arith-sat-semantics add ACC40Si
7032                                                     (nextreg h-acc40S ACC40Si 1)
7033                                                     ACC40Sk DI
7034                                                     #x7fffffffff
7035                                                     (inv DI #x7fffffffff)
7036                                                     (msr-sie-acci))
7037                          (media-arith-sat-semantics sub ACC40Si
7038                                                     (nextreg h-acc40S ACC40Si 1)
7039                                                     (nextreg h-acc40S ACC40Sk 1)
7040                                                     DI
7041                                                     #x7fffffffff
7042                                                     (inv DI #x7fffffffff)
7043                                                     (msr-sie-acci-1))
7044                          (media-arith-sat-semantics add
7045                                                     (nextreg h-acc40S ACC40Si 2)
7046                                                     (nextreg h-acc40S ACC40Si 3)
7047                                                     (nextreg h-acc40S ACC40Sk 2)
7048                                                     DI
7049                                                     #x7fffffffff
7050                                                     (inv DI #x7fffffffff)
7051                                                     (msr-sie-acci-2))
7052                          (media-arith-sat-semantics sub
7053                                                     (nextreg h-acc40S ACC40Si 2)
7054                                                     (nextreg h-acc40S ACC40Si 3)
7055                                                     (nextreg h-acc40S ACC40Sk 3)
7056                                                     DI
7057                                                     #x7fffffffff
7058                                                     (inv DI #x7fffffffff)
7059                                                     (msr-sie-acci-3)))))
7060        ((fr400 (unit u-media-2-add-sub-dual)))
7061   )
7062
7063 (define-pmacro (media-multiply-semantics conv arg1 arg2 res)
7064   (set res (mul DI (conv DI arg1) (conv DI arg2)))
7065 )
7066
7067 (define-pmacro (media-dual-multiply-semantics cond mode conv rhs1 rhs2)
7068   (if (register-unaligned ACC40Sk 2)
7069       (c-call VOID "@cpu@_media_acc_not_aligned")
7070       (if cond
7071           (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
7072                     (extract-hilo FRinti 0 FRintj 0
7073                                   argihi argilo argjhi argjlo)
7074                     (media-multiply-semantics conv argihi rhs1 ACC40Sk)
7075                     (media-multiply-semantics conv argilo rhs2
7076                                               (nextreg h-acc40S ACC40Sk 1)))))
7077 )
7078
7079 (define-pmacro (media-dual-multiply name mode conv rhs1 rhs2 op ope comment)
7080   (dni name
7081        (comment)
7082        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1) PRESERVE-OVF)
7083        (.str name "$pack $FRinti,$FRintj,$ACC40Sk")
7084        (+ pack ACC40Sk op FRinti ope FRintj)
7085        (media-dual-multiply-semantics 1 mode conv rhs1 rhs2)
7086        ((fr400 (unit u-media-2))
7087         (fr500 (unit u-media-dual-mul)))
7088   )
7089 )
7090
7091 (media-dual-multiply mmulhs  HI ext  argjhi argjlo OP_7B OPE1_14 "Media dual multiply signed")
7092 (media-dual-multiply mmulhu UHI zext argjhi argjlo OP_7B OPE1_15 "Media dual multiply unsigned")
7093
7094 (media-dual-multiply mmulxhs  HI ext  argjlo argjhi OP_7B OPE1_28 "Media dual cross multiply signed")
7095 (media-dual-multiply mmulxhu UHI zext argjlo argjhi OP_7B OPE1_29 "Media dual cross multiply unsigned")
7096
7097 (define-pmacro (conditional-media-dual-multiply
7098                 name mode conv rhs1 rhs2 op ope comment)
7099   (dni name
7100        (comment)
7101        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1)
7102         PRESERVE-OVF CONDITIONAL)
7103        (.str name "$pack $FRinti,$FRintj,$ACC40Sk,$CCi,$cond")
7104        (+ pack ACC40Sk op FRinti CCi cond ope FRintj)
7105        (media-dual-multiply-semantics (eq CCi (or cond 2)) mode conv rhs1 rhs2)
7106        ((fr400 (unit u-media-2))
7107         (fr500 (unit u-media-dual-mul)))
7108   )
7109 )
7110
7111 (conditional-media-dual-multiply cmmulhs  HI ext  argjhi argjlo OP_72 OPE4_0 "Conditional Media dual multiply signed")
7112 (conditional-media-dual-multiply cmmulhu UHI zext argjhi argjlo OP_72 OPE4_1 "Conditional Media dual multiply unsigned")
7113
7114 (define-pmacro (media-quad-multiply-semantics cond mode conv rhs1 rhs2)
7115   (if (register-unaligned ACC40Sk 4)
7116       (c-call VOID "@cpu@_media_acc_not_aligned")
7117       (if (orif (register-unaligned FRinti 2)
7118                 (register-unaligned FRintj 2))
7119           (c-call VOID "@cpu@_media_register_not_aligned")
7120           (if cond
7121               (sequence ((mode argihi) (mode argilo)
7122                          (mode argjhi) (mode argjlo))
7123                         (extract-hilo FRinti 0 FRintj 0
7124                                       argihi argilo argjhi argjlo)
7125                         (media-multiply-semantics conv argihi rhs1 ACC40Sk)
7126                         (media-multiply-semantics conv argilo rhs2
7127                                                   (nextreg h-acc40S ACC40Sk 1))
7128                         (extract-hilo FRinti 1 FRintj 1
7129                                       argihi argilo argjhi argjlo)
7130                         (media-multiply-semantics conv argihi rhs1
7131                                                   (nextreg h-acc40S ACC40Sk 2))
7132                         (media-multiply-semantics conv argilo rhs2
7133                                                   (nextreg h-acc40S ACC40Sk 3))))))
7134 )
7135
7136 (define-pmacro (media-quad-multiply name mode conv rhs1 rhs2 op ope comment)
7137   (dni name
7138        (comment)
7139        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2) PRESERVE-OVF)
7140        (.str name "$pack $FRinti,$FRintj,$ACC40Sk")
7141        (+ pack ACC40Sk op FRinti ope FRintj)
7142        (media-quad-multiply-semantics 1 mode conv rhs1 rhs2) 
7143        ((fr400 (unit u-media-2-quad))
7144         (fr500 (unit u-media-quad-mul)))
7145   )
7146 )
7147
7148 (media-quad-multiply mqmulhs  HI ext  argjhi argjlo OP_7B OPE1_1C "Media quad multiply signed")
7149 (media-quad-multiply mqmulhu UHI zext argjhi argjlo OP_7B OPE1_1D "Media quad multiply unsigned")
7150
7151 (media-quad-multiply mqmulxhs  HI ext  argjlo argjhi OP_7B OPE1_2A "Media quad cross multiply signed")
7152 (media-quad-multiply mqmulxhu UHI zext argjlo argjhi OP_7B OPE1_2B "Media quad cross multiply unsigned")
7153
7154 (define-pmacro (conditional-media-quad-multiply
7155                 name mode conv rhs1 rhs2 op ope comment)
7156   (dni name
7157        (comment)
7158        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2)
7159         PRESERVE-OVF CONDITIONAL)
7160        (.str name "$pack $FRinti,$FRintj,$ACC40Sk,$CCi,$cond")
7161        (+ pack ACC40Sk op FRinti CCi cond ope FRintj)
7162        (media-quad-multiply-semantics (eq CCi (or cond 2)) mode conv rhs1 rhs2)
7163        ((fr400 (unit u-media-2-quad))
7164         (fr500 (unit u-media-quad-mul)))
7165   )
7166 )
7167
7168 (conditional-media-quad-multiply cmqmulhs  HI ext  argjhi argjlo OP_74 OPE4_0 "Conditional Media quad multiply signed")
7169 (conditional-media-quad-multiply cmqmulhu UHI zext argjhi argjlo OP_74 OPE4_1 "Conditional Media quad multiply unsigned")
7170
7171 (define-pmacro (media-multiply-acc-semantics 
7172                 conv arg1 addop arg2 res max min sie)
7173   (sequence ((DI tmp))
7174             (set tmp (addop res (mul DI (conv DI arg1) (conv DI arg2))))
7175             (saturate-v tmp max min sie res))
7176 )
7177
7178 (define-pmacro (media-dual-multiply-acc-semantics
7179                 cond mode conv addop rhw res max min)
7180   (if (register-unaligned res 2)
7181       (c-call VOID "@cpu@_media_acc_not_aligned")
7182       (if cond
7183           (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
7184                     (extract-hilo FRinti 0 FRintj 0
7185                                   argihi argilo argjhi argjlo)
7186                     (media-multiply-acc-semantics conv argihi addop argjhi
7187                                                   res
7188                                                   max min (msr-sie-acci))
7189                     (media-multiply-acc-semantics conv argilo addop argjlo
7190                                                   (nextreg rhw res 1)
7191                                                   max min (msr-sie-acci-1)))))
7192 )
7193
7194 (define-pmacro (media-dual-multiply-acc
7195                 name mode conv addop rhw res max min op ope comment)
7196   (dni name
7197        (comment)
7198        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1))
7199        (.str name "$pack $FRinti,$FRintj,$" res)
7200        (+ pack res op FRinti ope FRintj)
7201        (media-dual-multiply-acc-semantics 1 mode conv addop rhw res max min)
7202        ((fr400 (unit u-media-2))
7203         (fr500 (unit u-media-dual-mul)))
7204   )
7205 )
7206
7207 (media-dual-multiply-acc mmachs HI ext add h-acc40S ACC40Sk
7208                          (const DI #x7fffffffff) (const DI #xffffff8000000000)
7209                          OP_7B OPE1_16
7210                          "Media dual multiply and accumulate signed")
7211
7212 (media-dual-multiply-acc mmachu UHI zext add h-acc40U ACC40Uk
7213                          (const DI #xffffffffff) (const DI 0)
7214                          OP_7B OPE1_17
7215                          "Media dual multiply and accumulate unsigned")
7216
7217 (media-dual-multiply-acc mmrdhs HI ext sub h-acc40S ACC40Sk
7218                          (const DI #x7fffffffff) (const DI #xffffff8000000000)
7219                          OP_7B OPE1_30
7220                          "Media dual multiply and reduce signed")
7221
7222 (media-dual-multiply-acc mmrdhu UHI zext sub h-acc40U ACC40Uk
7223                          (const DI #xffffffffff) (const DI 0)
7224                          OP_7B OPE1_31
7225                          "Media dual multiply and reduce unsigned")
7226
7227 (define-pmacro (conditional-media-dual-multiply-acc
7228                 name mode conv addop rhw res max min op ope comment)
7229   (dni name
7230        (comment)
7231        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1) CONDITIONAL)
7232        (.str name "$pack $FRinti,$FRintj,$" res ",$CCi,$cond")
7233        (+ pack res op FRinti CCi cond ope FRintj)
7234        (media-dual-multiply-acc-semantics (eq CCi (or cond 2))
7235                                           mode conv addop rhw res max min)
7236        ((fr400 (unit u-media-2))
7237         (fr500 (unit u-media-dual-mul)))
7238   )
7239 )
7240
7241 (conditional-media-dual-multiply-acc cmmachs HI ext add h-acc40S ACC40Sk
7242                          (const DI #x7fffffffff) (const DI #xffffff8000000000)
7243                          OP_72 OPE4_2
7244                          "Conditional Media dual multiply and accumulate signed")
7245
7246 (conditional-media-dual-multiply-acc cmmachu UHI zext add  h-acc40U ACC40Uk
7247                          (const DI #xffffffffff) (const DI 0)
7248                          OP_72 OPE4_3
7249                          "Conditional Media dual multiply and accumulate unsigned")
7250
7251 (define-pmacro (media-quad-multiply-acc-semantics
7252                 cond mode conv addop rhw res max min)
7253   (if (register-unaligned res 4)
7254       (c-call VOID "@cpu@_media_acc_not_aligned")
7255       (if (orif (register-unaligned FRinti 2)
7256                 (register-unaligned FRintj 2))
7257           (c-call VOID "@cpu@_media_register_not_aligned")
7258           (if cond
7259               (sequence ((mode argihi) (mode argilo)
7260                          (mode argjhi) (mode argjlo))
7261                         (extract-hilo FRinti 0 FRintj 0
7262                                       argihi argilo argjhi argjlo)
7263                         (media-multiply-acc-semantics conv argihi addop argjhi
7264                                                       res
7265                                                       max min (msr-sie-acci))
7266                         (media-multiply-acc-semantics conv argilo addop argjlo
7267                                                       (nextreg rhw res 1)
7268                                                       max min (msr-sie-acci-1))
7269                         (extract-hilo FRinti 1 FRintj 1
7270                                       argihi argilo argjhi argjlo)
7271                         (media-multiply-acc-semantics conv argihi addop argjhi
7272                                                       (nextreg rhw res 2)
7273                                                       max min (msr-sie-acci-2))
7274                         (media-multiply-acc-semantics conv argilo addop argjlo
7275                                                       (nextreg rhw res 3)
7276                                                       max min
7277                                                       (msr-sie-acci-3))))))
7278 )
7279
7280 (define-pmacro (media-quad-multiply-acc
7281                 name mode conv addop rhw res max min op ope comment)
7282   (dni name
7283        (comment)
7284        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2))
7285        (.str name "$pack $FRinti,$FRintj,$" res)
7286        (+ pack res op FRinti ope FRintj)
7287        (media-quad-multiply-acc-semantics 1 mode conv addop rhw res max min)
7288        ((fr400 (unit u-media-2-quad))
7289         (fr500 (unit u-media-quad-mul)))
7290   )
7291 )
7292
7293 (media-quad-multiply-acc mqmachs HI ext add h-acc40S ACC40Sk
7294                          (const DI #x7fffffffff) (const DI #xffffff8000000000)
7295                          OP_7B OPE1_1E
7296                          "Media quad multiply and accumulate signed")
7297
7298 (media-quad-multiply-acc mqmachu UHI zext add h-acc40U ACC40Uk
7299                          (const DI #xffffffffff) (const DI 0)
7300                          OP_7B OPE1_1F
7301                          "Media quad multiply and accumulate unsigned")
7302
7303 (define-pmacro (conditional-media-quad-multiply-acc
7304                 name mode conv addop rhw res max min op ope comment)
7305   (dni name
7306        (comment)
7307        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2) CONDITIONAL)
7308        (.str name "$pack $FRinti,$FRintj,$" res ",$CCi,$cond")
7309        (+ pack res op FRinti CCi cond ope FRintj)
7310        (media-quad-multiply-acc-semantics (eq CCi (or cond 2))
7311                                           mode conv addop rhw res max min)
7312        ((fr400 (unit u-media-2-quad))
7313         (fr500 (unit u-media-quad-mul)))
7314   )
7315 )
7316
7317 (conditional-media-quad-multiply-acc cmqmachs HI ext add h-acc40S ACC40Sk
7318                          (const DI #x7fffffffff) (const DI #xffffff8000000000)
7319                          OP_74 OPE4_2
7320                          "Conditional Media quad multiply and accumulate signed")
7321
7322 (conditional-media-quad-multiply-acc cmqmachu UHI zext add h-acc40U ACC40Uk
7323                          (const DI #xffffffffff) (const DI 0)
7324                          OP_74 OPE4_3
7325                          "Conditional media quad multiply and accumulate unsigned")
7326
7327 (define-pmacro (media-quad-multiply-cross-acc-semantics
7328                 cond mode conv addop rhw res max min)
7329   (if (register-unaligned res 4)
7330       (c-call VOID "@cpu@_media_acc_not_aligned")
7331       (if (orif (register-unaligned FRinti 2)
7332                 (register-unaligned FRintj 2))
7333           (c-call VOID "@cpu@_media_register_not_aligned")
7334           (if cond
7335               (sequence ((mode argihi) (mode argilo)
7336                          (mode argjhi) (mode argjlo))
7337                         (extract-hilo FRinti 0 FRintj 0
7338                                       argihi argilo argjhi argjlo)
7339                         (media-multiply-acc-semantics conv argihi addop argjhi
7340                                                       (nextreg rhw res 2)
7341                                                       max min (msr-sie-acci-2))
7342                         (media-multiply-acc-semantics conv argilo addop argjlo
7343                                                       (nextreg rhw res 3)
7344                                                       max min (msr-sie-acci-3))
7345                         (extract-hilo FRinti 1 FRintj 1
7346                                       argihi argilo argjhi argjlo)
7347                         (media-multiply-acc-semantics conv argihi addop argjhi
7348                                                       res
7349                                                       max min (msr-sie-acci))
7350                         (media-multiply-acc-semantics conv argilo addop argjlo
7351                                                       (nextreg rhw res 1)
7352                                                       max min
7353                                                       (msr-sie-acci-1))))))
7354 )
7355
7356 (define-pmacro (media-quad-multiply-cross-acc
7357                 name mode conv addop rhw res max min op ope comment)
7358   (dni name
7359        (comment)
7360        ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
7361        (.str name "$pack $FRinti,$FRintj,$" res)
7362        (+ pack res op FRinti ope FRintj)
7363        (media-quad-multiply-cross-acc-semantics 1 mode conv addop rhw res
7364                                                 max min)
7365        ((fr400 (unit u-media-2-quad)))
7366   )
7367 )
7368
7369 (media-quad-multiply-cross-acc mqxmachs HI ext add h-acc40S ACC40Sk
7370                          (const DI #x7fffffffff) (const DI #xffffff8000000000)
7371                          OP_78 OPE1_00
7372                          "Media quad multiply and cross accumulate signed")
7373
7374 (define-pmacro (media-quad-cross-multiply-cross-acc-semantics
7375                 cond mode conv addop rhw res max min)
7376   (if (register-unaligned res 4)
7377       (c-call VOID "@cpu@_media_acc_not_aligned")
7378       (if (orif (register-unaligned FRinti 2)
7379                 (register-unaligned FRintj 2))
7380           (c-call VOID "@cpu@_media_register_not_aligned")
7381           (if cond
7382               (sequence ((mode argihi) (mode argilo)
7383                          (mode argjhi) (mode argjlo))
7384                         (extract-hilo FRinti 0 FRintj 0
7385                                       argihi argilo argjhi argjlo)
7386                         (media-multiply-acc-semantics conv argihi addop argjlo
7387                                                       (nextreg rhw res 2)
7388                                                       max min (msr-sie-acci-2))
7389                         (media-multiply-acc-semantics conv argilo addop argjhi
7390                                                       (nextreg rhw res 3)
7391                                                       max min (msr-sie-acci-3))
7392                         (extract-hilo FRinti 1 FRintj 1
7393                                       argihi argilo argjhi argjlo)
7394                         (media-multiply-acc-semantics conv argihi addop argjlo
7395                                                       res
7396                                                       max min (msr-sie-acci))
7397                         (media-multiply-acc-semantics conv argilo addop argjhi
7398                                                       (nextreg rhw res 1)
7399                                                       max min
7400                                                       (msr-sie-acci-1))))))
7401 )
7402
7403 (define-pmacro (media-quad-cross-multiply-cross-acc
7404                 name mode conv addop rhw res max min op ope comment)
7405   (dni name
7406        (comment)
7407        ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
7408        (.str name "$pack $FRinti,$FRintj,$" res)
7409        (+ pack res op FRinti ope FRintj)
7410        (media-quad-cross-multiply-cross-acc-semantics 1 mode conv addop rhw res
7411                                                       max min)
7412        ((fr400 (unit u-media-2-quad)))
7413   )
7414 )
7415
7416 (media-quad-cross-multiply-cross-acc mqxmacxhs HI ext add h-acc40S ACC40Sk
7417                         (const DI #x7fffffffff) (const DI #xffffff8000000000)
7418                         OP_78 OPE1_01
7419                         "Media quad cross multiply and cross accumulate signed")
7420
7421 (define-pmacro (media-quad-cross-multiply-acc-semantics
7422                 cond mode conv addop rhw res max min)
7423   (if (register-unaligned res 4)
7424       (c-call VOID "@cpu@_media_acc_not_aligned")
7425       (if (orif (register-unaligned FRinti 2)
7426                 (register-unaligned FRintj 2))
7427           (c-call VOID "@cpu@_media_register_not_aligned")
7428           (if cond
7429               (sequence ((mode argihi) (mode argilo)
7430                          (mode argjhi) (mode argjlo))
7431                         (extract-hilo FRinti 0 FRintj 0
7432                                       argihi argilo argjhi argjlo)
7433                         (media-multiply-acc-semantics conv argihi addop argjlo
7434                                                       res
7435                                                       max min (msr-sie-acci))
7436                         (media-multiply-acc-semantics conv argilo addop argjhi
7437                                                       (nextreg rhw res 1)
7438                                                       max min (msr-sie-acci-1))
7439                         (extract-hilo FRinti 1 FRintj 1
7440                                       argihi argilo argjhi argjlo)
7441                         (media-multiply-acc-semantics conv argihi addop argjlo
7442                                                       (nextreg rhw res 2)
7443                                                       max min (msr-sie-acci-2))
7444                         (media-multiply-acc-semantics conv argilo addop argjhi
7445                                                       (nextreg rhw res 3)
7446                                                       max min
7447                                                       (msr-sie-acci-3))))))
7448 )
7449
7450 (define-pmacro (media-quad-cross-multiply-acc
7451                 name mode conv addop rhw res max min op ope comment)
7452   (dni name
7453        (comment)
7454        ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
7455        (.str name "$pack $FRinti,$FRintj,$" res)
7456        (+ pack res op FRinti ope FRintj)
7457        (media-quad-cross-multiply-acc-semantics 1 mode conv addop rhw res
7458                                                 max min)
7459        ((fr400 (unit u-media-2-quad)))
7460   )
7461 )
7462
7463 (media-quad-cross-multiply-acc mqmacxhs HI ext add h-acc40S ACC40Sk
7464                         (const DI #x7fffffffff) (const DI #xffffff8000000000)
7465                         OP_78 OPE1_02
7466                         "Media quad cross multiply and accumulate signed")
7467
7468 (define-pmacro (media-complex-semantics
7469                 conv lhs1 rhs1 lhs2 rhs2 res max min sie)
7470   (sequence ((DI tmp1) (DI tmp2))
7471             (media-multiply-semantics conv lhs1 rhs1 tmp1)
7472             (media-multiply-semantics conv lhs2 rhs2 tmp2)
7473             (set tmp1 (sub tmp1 tmp2))
7474             (saturate-v tmp1 max min sie res))
7475 )
7476
7477 (define-pmacro (media-complex-semantics-i
7478                 conv lhs1 rhs1 lhs2 rhs2 res max min sie)
7479   (sequence ((DI tmp1) (DI tmp2))
7480             (media-multiply-semantics conv lhs1 rhs1 tmp1)
7481             (media-multiply-semantics conv lhs2 rhs2 tmp2)
7482             (set tmp1 (add tmp1 tmp2))
7483             (saturate-v tmp1 max min sie res))
7484 )
7485
7486 (define-pmacro (media-dual-complex-semantics mode conv rhs1 rhs2 max min)
7487   (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
7488             (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
7489             (media-complex-semantics conv argihi rhs1 argilo rhs2 ACC40Sk
7490                                      max min (msr-sie-acci)))
7491 )
7492
7493 (define-pmacro (media-dual-complex-semantics-i mode conv rhs1 rhs2 max min)
7494   (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
7495             (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
7496             (media-complex-semantics-i conv argihi rhs1 argilo rhs2 ACC40Sk
7497                                      max min (msr-sie-acci)))
7498 )
7499
7500 (define-pmacro (media-dual-complex
7501                 name mode conv rhs1 rhs2 max min op ope comment)
7502   (dni name
7503        (comment)
7504        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1))
7505        (.str name "$pack $FRinti,$FRintj,$ACC40Sk")
7506        (+ pack ACC40Sk op FRinti ope FRintj)
7507        (media-dual-complex-semantics mode conv rhs1 rhs2 max min)
7508        ((fr400 (unit u-media-2))
7509         (fr500 (unit u-media)))
7510   )
7511 )
7512
7513 (define-pmacro (media-dual-complex-i
7514                 name mode conv rhs1 rhs2 max min op ope comment)
7515   (dni name
7516        (comment)
7517        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1))
7518        (.str name "$pack $FRinti,$FRintj,$ACC40Sk")
7519        (+ pack ACC40Sk op FRinti ope FRintj)
7520        (media-dual-complex-semantics-i mode conv rhs1 rhs2 max min)
7521        ((fr400 (unit u-media-2))
7522         (fr500 (unit u-media-dual-mul)))
7523   )
7524 )
7525
7526 (media-dual-complex mcpxrs HI ext argjhi argjlo
7527                     (const DI #x7fffffffff) (const DI #xffffff8000000000)
7528                     OP_7B OPE1_20
7529                     "Media dual complex real signed with saturation")
7530
7531 (media-dual-complex mcpxru UHI zext argjhi argjlo
7532                     (const DI #xffffffffff) (const DI 0)
7533                     OP_7B OPE1_21
7534                     "Media dual complex real unsigned with saturation")
7535
7536 (media-dual-complex-i mcpxis HI ext argjlo argjhi
7537                     (const DI #x7fffffffff) (const DI #xffffff8000000000)
7538                     OP_7B OPE1_22
7539                     "Media dual complex imaginary signed with saturation")
7540
7541 (media-dual-complex-i mcpxiu UHI zext argjlo argjhi
7542                     (const DI #xffffffffff) (const DI 0)
7543                     OP_7B OPE1_23
7544                     "Media dual complex imaginary unsigned with saturation")
7545
7546 (define-pmacro (conditional-media-dual-complex
7547                 name mode conv rhs1 rhs2 max min op ope comment)
7548   (dni name
7549        (comment)
7550        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1) CONDITIONAL)
7551        (.str name "$pack $FRinti,$FRintj,$ACC40Sk,$CCi,$cond")
7552        (+ pack ACC40Sk op FRinti CCi cond ope FRintj)
7553        (if (eq CCi (or cond 2))
7554            (media-dual-complex-semantics mode conv rhs1 rhs2 max min))
7555        ((fr400 (unit u-media-2))
7556         (fr500 (unit u-media)))
7557   )
7558 )
7559
7560 (define-pmacro (conditional-media-dual-complex-i
7561                 name mode conv rhs1 rhs2 max min op ope comment)
7562   (dni name
7563        (comment)
7564        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1) CONDITIONAL)
7565        (.str name "$pack $FRinti,$FRintj,$ACC40Sk,$CCi,$cond")
7566        (+ pack ACC40Sk op FRinti CCi cond ope FRintj)
7567        (if (eq CCi (or cond 2))
7568            (media-dual-complex-semantics-i mode conv rhs1 rhs2 max min))
7569        ((fr400 (unit u-media-2))
7570         (fr500 (unit u-media-dual-mul)))
7571   )
7572 )
7573
7574 (conditional-media-dual-complex cmcpxrs HI ext argjhi argjlo
7575                     (const DI #x7fffffffff) (const DI #xffffff8000000000)
7576                     OP_75 OPE4_0
7577                     "Conditional Media dual complex real signed with saturation")
7578
7579 (conditional-media-dual-complex cmcpxru UHI zext argjhi argjlo
7580                     (const DI #xffffffffff) (const DI 0)
7581                     OP_75 OPE4_1
7582                     "Conditional Media dual complex real unsigned with saturation")
7583
7584 (conditional-media-dual-complex-i cmcpxis HI ext argjlo argjhi
7585                     (const DI #x7fffffffff) (const DI #xffffff8000000000)
7586                     OP_75 OPE4_2
7587                     "Conditional Media dual complex imaginary signed with saturation")
7588
7589 (conditional-media-dual-complex-i cmcpxiu UHI zext argjlo argjhi
7590                     (const DI #xffffffffff) (const DI 0)
7591                     OP_75 OPE4_3
7592                     "Conditional Media dual complex imaginary unsigned with saturation")
7593
7594 (define-pmacro (media-quad-complex
7595                 name mode conv rhs1 rhs2 max min op ope comment)
7596   (dni name
7597        (comment)
7598        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2))
7599        (.str name "$pack $FRinti,$FRintj,$ACC40Sk")
7600        (+ pack ACC40Sk op FRinti ope FRintj)
7601        (if (register-unaligned ACC40Sk 2)
7602            (c-call VOID "@cpu@_media_acc_not_aligned")
7603            (if (orif (register-unaligned FRinti 2)
7604                      (register-unaligned FRintj 2))
7605                (c-call VOID "@cpu@_media_register_not_aligned")
7606                (sequence ((mode argihi) (mode argilo)
7607                           (mode argjhi) (mode argjlo))
7608                          (extract-hilo FRinti 0 FRintj 0
7609                                        argihi argilo argjhi argjlo)
7610                          (media-complex-semantics conv argihi rhs1 argilo rhs2
7611                                                   ACC40Sk
7612                                                   max min (msr-sie-acci))
7613                          (extract-hilo FRinti 1 FRintj 1
7614                                        argihi argilo argjhi argjlo)
7615                          (media-complex-semantics conv argihi rhs1 argilo rhs2
7616                                                   (nextreg h-acc40S ACC40Sk 1)
7617                                                   max min (msr-sie-acci-1)))))
7618        ((fr400 (unit u-media-2-quad))
7619         (fr500 (unit u-media-quad-complex)))
7620   )
7621 )
7622
7623 (define-pmacro (media-quad-complex-i
7624                 name mode conv rhs1 rhs2 max min op ope comment)
7625   (dni name
7626        (comment)
7627        ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2))
7628        (.str name "$pack $FRinti,$FRintj,$ACC40Sk")
7629        (+ pack ACC40Sk op FRinti ope FRintj)
7630        (if (register-unaligned ACC40Sk 2)
7631            (c-call VOID "@cpu@_media_acc_not_aligned")
7632            (if (orif (register-unaligned FRinti 2)
7633                      (register-unaligned FRintj 2))
7634                (c-call VOID "@cpu@_media_register_not_aligned")
7635                (sequence ((mode argihi) (mode argilo)
7636                           (mode argjhi) (mode argjlo))
7637                          (extract-hilo FRinti 0 FRintj 0
7638                                        argihi argilo argjhi argjlo)
7639                          (media-complex-semantics-i conv argihi rhs1 argilo rhs2
7640                                                   ACC40Sk
7641                                                   max min (msr-sie-acci))
7642                          (extract-hilo FRinti 1 FRintj 1
7643                                        argihi argilo argjhi argjlo)
7644                          (media-complex-semantics-i conv argihi rhs1 argilo rhs2
7645                                                   (nextreg h-acc40S ACC40Sk 1)
7646                                                   max min (msr-sie-acci-1)))))
7647        ((fr400 (unit u-media-2-quad))
7648         (fr500 (unit u-media-quad-complex)))
7649   )
7650 )
7651
7652 (media-quad-complex mqcpxrs HI ext argjhi argjlo
7653                     (const DI #x7fffffffff) (const DI #xffffff8000000000)
7654                     OP_7B OPE1_24
7655                     "Media quad complex real signed with saturation")
7656
7657 (media-quad-complex mqcpxru UHI zext argjhi argjlo
7658                     (const DI #xffffffffff) (const DI 0)
7659                     OP_7B OPE1_25
7660                     "Media quad complex real unsigned with saturation")
7661
7662 (media-quad-complex-i mqcpxis HI ext argjlo argjhi
7663                     (const DI #x7fffffffff) (const DI #xffffff8000000000)
7664                     OP_7B OPE1_26
7665                     "Media quad complex imaginary signed with saturation")
7666
7667 (media-quad-complex-i mqcpxiu UHI zext argjlo argjhi
7668                     (const DI #xffffffffff) (const DI 0)
7669                     OP_7B OPE1_27
7670                     "Media quad complex imaginary unsigned with saturation")
7671
7672 (define-pmacro (media-pack src1 src2 targ offset)
7673   (sequence ()
7674             (set (halfword hi targ offset) (halfword lo src1 offset))
7675             (set (halfword lo targ offset) (halfword lo src2 offset)))
7676 )
7677
7678 (define-pmacro (media-expand-halfword-to-word-semantics cond)
7679   (if cond
7680       (sequence ((UHI tmp))
7681                 (if (and u6 1)
7682                     (set tmp (halfword lo FRinti 0))
7683                     (set tmp (halfword hi FRinti 0)))
7684                 (set (halfword hi FRintk 0) tmp)
7685                 (set (halfword lo FRintk 0) tmp)))
7686 )
7687
7688 (dni mexpdhw
7689      "Media expand halfword to word"
7690      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
7691      "mexpdhw$pack $FRinti,$u6,$FRintk"
7692      (+ pack FRintk OP_7B FRinti OPE1_32 u6)
7693      (media-expand-halfword-to-word-semantics 1)
7694      ((fr400 (unit u-media-3))
7695       (fr500 (unit u-media)))
7696 )
7697
7698 (dni cmexpdhw
7699      "Conditional media expand halfword to word"
7700      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1) CONDITIONAL)
7701      "cmexpdhw$pack $FRinti,$u6,$FRintk,$CCi,$cond"
7702      (+ pack FRintk OP_76 FRinti CCi cond OPE4_2 u6)
7703      (media-expand-halfword-to-word-semantics (eq CCi (or cond 2)))
7704      ((fr400 (unit u-media-3))
7705       (fr500 (unit u-media)))
7706 )
7707
7708 (define-pmacro (media-expand-halfword-to-double-semantics cond)
7709   (if (register-unaligned FRintk 2)
7710       (c-call VOID "@cpu@_media_register_not_aligned")
7711       (if cond
7712           (sequence ((UHI tmp))
7713                     ; a hack to get FRintk referenced for profiling
7714                     (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
7715                     (if (and u6 1)
7716                         (set tmp (halfword lo FRinti 0))
7717                         (set tmp (halfword hi FRinti 0)))
7718                     (set (halfword hi FRintk 0) tmp)
7719                     (set (halfword lo FRintk 0) tmp)
7720                     (set (halfword hi FRintk 1) tmp)
7721                     (set (halfword lo FRintk 1) tmp))))
7722 )
7723
7724 (dni mexpdhd
7725      "Media expand halfword to double"
7726      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2))
7727      "mexpdhd$pack $FRinti,$u6,$FRintk"
7728      (+ pack FRintk OP_7B FRinti OPE1_33 u6)
7729      (media-expand-halfword-to-double-semantics 1)
7730      ((fr400 (unit u-media-dual-expand))
7731       (fr500 (unit u-media-dual-expand)))
7732 )
7733
7734 (dni cmexpdhd
7735      "Conditional media expand halfword to double"
7736      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2) CONDITIONAL)
7737      "cmexpdhd$pack $FRinti,$u6,$FRintk,$CCi,$cond"
7738      (+ pack FRintk OP_76 FRinti CCi cond OPE4_3 u6)
7739      (media-expand-halfword-to-double-semantics (eq CCi (or cond 2)))
7740      ((fr400 (unit u-media-dual-expand))
7741       (fr500 (unit u-media-dual-expand)))
7742 )
7743
7744 (dni mpackh
7745      "Media halfword pack"
7746      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
7747      "mpackh$pack $FRinti,$FRintj,$FRintk"
7748      (+ pack FRintk OP_7B FRinti OPE1_34 FRintj)
7749      (media-pack FRinti FRintj FRintk 0)
7750      ((fr400 (unit u-media-3))
7751       (fr500 (unit u-media)))
7752 )
7753
7754 (dni mdpackh
7755      "Media dual pack"
7756      ((UNIT FM01) (FR500-MAJOR M-5) (FR400-MAJOR M-2))
7757      "mdpackh$pack $FRinti,$FRintj,$FRintk"
7758      (+ pack FRintk OP_7B FRinti OPE1_36 FRintj)
7759      (if (orif (register-unaligned FRinti 2)
7760                (orif (register-unaligned FRintj 2)
7761                      (register-unaligned FRintk 2)))
7762          (c-call VOID "@cpu@_media_register_not_aligned")
7763          (sequence ()
7764                    ; hack to get these referenced for profiling
7765                    (set FRinti (c-raw-call SI "frv_ref_SI" FRinti))
7766                    (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
7767                    (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
7768                    (media-pack FRinti FRintj FRintk 0)
7769                    (media-pack FRinti FRintj FRintk 1)))
7770      ((fr400 (unit u-media-3-quad))
7771       (fr500 (unit u-media-quad-arith)))
7772 )
7773
7774 (define-pmacro (media-unpack src soff targ toff)
7775   (sequence ()
7776             (set (halfword hi targ toff) (halfword hi src soff))
7777             (set (halfword lo targ toff) (halfword hi src soff))
7778             (set (halfword hi targ (add toff 1)) (halfword lo src soff))
7779             (set (halfword lo targ (add toff 1)) (halfword lo src soff)))
7780 )
7781
7782 (dni munpackh
7783      "Media halfword unpack"
7784      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2))
7785      "munpackh$pack $FRinti,$FRintk"
7786      (+ pack FRintk OP_7B FRinti OPE1_35 (FRj-null))
7787      (if (register-unaligned FRintk 2)
7788          (c-call VOID "@cpu@_media_register_not_aligned")
7789          (sequence ()
7790                    ; hack to get these referenced for profiling
7791                    (set FRinti (c-raw-call SI "frv_ref_SI" FRinti))
7792                    (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
7793                    (media-unpack FRinti 0 FRintk 0)))
7794      ((fr400 (unit u-media-dual-expand))
7795       (fr500 (unit u-media-dual-expand)))
7796 )
7797
7798 (dni mdunpackh
7799      "Media dual unpack"
7800      ((UNIT FM01) (FR500-MAJOR M-7) (MACH simple,tomcat,frv))
7801      "mdunpackh$pack $FRinti,$FRintk"
7802      (+ pack FRintk OP_7B FRinti OPE1_37 (FRj-null))
7803      (if (orif (register-unaligned FRinti 2) (register-unaligned FRintk 4))
7804          (c-call VOID "@cpu@_media_register_not_aligned")
7805          (sequence ()
7806                    ; hack to get these referenced for profiling
7807                    (set FRinti (c-raw-call SI "frv_ref_SI" FRinti))
7808                    (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
7809                    (media-unpack FRinti 0 FRintk 0)
7810                    (media-unpack FRinti 1 FRintk 2)))
7811      ((fr500 (unit u-media-dual-unpack)))
7812 )
7813
7814 (define-pmacro (ubyte num arg offset)
7815   (reg (.sym h-fr_ num) (add (index-of arg) offset)))
7816
7817 (define-pmacro (mbtoh-semantics cond)
7818   (if (register-unaligned FRintk 2)
7819       (c-call VOID "@cpu@_media_register_not_aligned")
7820       (if cond
7821           (sequence ()
7822                     (set (halfword hi FRintk 0) (ubyte 3 FRintj 0))
7823                     (set (halfword lo FRintk 0) (ubyte 2 FRintj 0))
7824                     (set (halfword hi FRintk 1) (ubyte 1 FRintj 0))
7825                     (set (halfword lo FRintk 1) (ubyte 0 FRintj 0)))))
7826 )
7827
7828 (dni mbtoh
7829      "Media convert byte to halfword"
7830      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2))
7831      "mbtoh$pack $FRintj,$FRintk"
7832      (+ pack FRintk OP_7B (FRi-null) OPE1_38 FRintj)
7833      (sequence ()
7834                ; hack to get these referenced for profiling
7835                (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
7836                (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
7837                (mbtoh-semantics 1))
7838      ((fr400 (unit u-media-dual-expand))
7839       (fr500 (unit u-media-dual-btoh)))
7840 )
7841
7842 (dni cmbtoh
7843      "Conditional media convert byte to halfword"
7844      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2) CONDITIONAL)
7845      "cmbtoh$pack $FRintj,$FRintk,$CCi,$cond"
7846      (+ pack FRintk OP_77 (FRi-null) CCi cond OPE4_0 FRintj)
7847      (mbtoh-semantics (eq CCi (or cond 2)))
7848      ((fr400 (unit u-media-dual-expand))
7849       (fr500 (unit u-media-dual-btoh)))
7850 )
7851
7852 (define-pmacro (mhtob-semantics cond)
7853   (if (register-unaligned FRintj 2)
7854       (c-call VOID "@cpu@_media_register_not_aligned")
7855       (if cond
7856           (sequence ()
7857                     (set (ubyte 3 FRintk 0) (halfword hi FRintj 0))
7858                     (set (ubyte 2 FRintk 0) (halfword lo FRintj 0))
7859                     (set (ubyte 1 FRintk 0) (halfword hi FRintj 1))
7860                     (set (ubyte 0 FRintk 0) (halfword lo FRintj 1)))))
7861 )
7862
7863 (dni mhtob
7864      "Media convert halfword to byte"
7865      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2))
7866      "mhtob$pack $FRintj,$FRintk"
7867      (+ pack FRintk OP_7B (FRi-null) OPE1_39 FRintj)
7868      (sequence ()
7869                ; hack to get these referenced for profiling
7870                (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
7871                (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
7872                (mhtob-semantics 1))
7873      ((fr400 (unit u-media-dual-htob))
7874       (fr500 (unit u-media-dual-htob)))
7875 )
7876
7877 (dni cmhtob
7878      "Conditional media convert halfword to byte"
7879      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2) CONDITIONAL)
7880      "cmhtob$pack $FRintj,$FRintk,$CCi,$cond"
7881      (+ pack FRintk OP_77 (FRi-null) CCi cond OPE4_1 FRintj)
7882      (sequence ()
7883                ; hack to get these referenced for profiling
7884                (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
7885                (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
7886                (mhtob-semantics (eq CCi (or cond 2))))
7887      ((fr400 (unit u-media-dual-htob))
7888       (fr500 (unit u-media-dual-htob)))
7889 )
7890
7891 (define-pmacro (mbtohe-semantics cond)
7892   (if (register-unaligned FRintk 4)
7893       (c-call VOID "@cpu@_media_register_not_aligned")
7894       (if cond
7895           (sequence ()
7896                     (set (halfword hi FRintk 0) (ubyte 3 FRintj 0))
7897                     (set (halfword lo FRintk 0) (ubyte 3 FRintj 0))
7898                     (set (halfword hi FRintk 1) (ubyte 2 FRintj 0))
7899                     (set (halfword lo FRintk 1) (ubyte 2 FRintj 0))
7900                     (set (halfword hi FRintk 2) (ubyte 1 FRintj 0))
7901                     (set (halfword lo FRintk 2) (ubyte 1 FRintj 0))
7902                     (set (halfword hi FRintk 3) (ubyte 0 FRintj 0))
7903                     (set (halfword lo FRintk 3) (ubyte 0 FRintj 0)))))
7904 )
7905
7906 (dni mbtohe
7907      "Media convert byte to halfword extended"
7908      ((UNIT FM01) (FR500-MAJOR M-7) (MACH simple,tomcat,frv))
7909      "mbtohe$pack $FRintj,$FRintk"
7910      (+ pack FRintk OP_7B (FRi-null) OPE1_3A FRintj)
7911      (sequence ()
7912                ; hack to get these referenced for profiling
7913                (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
7914                (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
7915                (mbtohe-semantics 1))
7916      ((fr500 (unit u-media-dual-btohe)))
7917 )
7918
7919 (dni cmbtohe
7920      "Conditional media convert byte to halfword extended"
7921      ((UNIT FM01) (FR500-MAJOR M-7) CONDITIONAL (MACH simple,tomcat,frv))
7922      "cmbtohe$pack $FRintj,$FRintk,$CCi,$cond"
7923      (+ pack FRintk OP_77 (FRi-null) CCi cond OPE4_2 FRintj)
7924      (sequence ()
7925                ; hack to get these referenced for profiling
7926                (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
7927                (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
7928                (mbtohe-semantics (eq CCi (or cond 2))))
7929      ((fr500 (unit u-media-dual-btohe)))
7930 )
7931
7932 (dni mclracc
7933      "Media clear accumulator(s)"
7934      ((UNIT FM01) (FR500-MAJOR M-3))
7935      "mclracc$pack $ACC40Sk,$A"
7936      (+ pack ACC40Sk OP_7B A (misc-null-10) OPE1_3B (FRj-null))
7937      (c-call VOID "@cpu@_clear_accumulators" (index-of ACC40Sk) A)
7938      ((fr400 (unit u-media-4))
7939       (fr500 (unit u-media)))
7940 )
7941
7942 (dni mrdacc
7943      "Media read accumulator"
7944      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
7945      "mrdacc$pack $ACC40Si,$FRintk"
7946      (+ pack FRintk OP_7B ACC40Si OPE1_3C (FRj-null))
7947      (set FRintk ACC40Si)
7948      ((fr400 (unit u-media-4))
7949       (fr500 (unit u-media)))
7950 )
7951
7952 (dni mrdaccg
7953      "Media read accumulator guard"
7954      ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
7955      "mrdaccg$pack $ACCGi,$FRintk"
7956      (+ pack FRintk OP_7B ACCGi OPE1_3E (FRj-null))
7957      (set FRintk ACCGi)
7958      ((fr400 (unit u-media-4-accg))
7959       (fr500 (unit u-media)))
7960 )
7961
7962 (dni mwtacc
7963      "Media write accumulator"
7964      ((UNIT FM01) (FR500-MAJOR M-3) (FR400-MAJOR M-1))
7965      "mwtacc$pack $FRinti,$ACC40Sk"
7966      (+ pack ACC40Sk OP_7B FRinti OPE1_3D (FRj-null))
7967      (set ACC40Sk (or (and ACC40Sk (const DI #xffffffff00000000))
7968                      FRinti))
7969      ((fr400 (unit u-media-4))
7970       (fr500 (unit u-media)))
7971 )
7972
7973 (dni mwtaccg
7974      "Media write accumulator guard"
7975      ((UNIT FM01) (FR500-MAJOR M-3) (FR400-MAJOR M-1))
7976      "mwtaccg$pack $FRinti,$ACCGk"
7977      (+ pack ACCGk OP_7B FRinti OPE1_3F (FRj-null))
7978      (set ACCGk FRinti)
7979      ((fr400 (unit u-media-4-accg))
7980       (fr500 (unit u-media)))
7981 )
7982
7983 (define-pmacro (media-cop num op)
7984   (dni (.sym mcop num)
7985        "Media custom instruction"
7986        ((UNIT FM01) (FR500-MAJOR M-1) (MACH frv))
7987        (.str "mcop" num "$pack $FRi,$FRj,$FRk")
7988        (+ pack FRk op FRi OPE1_00 FRj)
7989        (c-call VOID "@cpu@_media_cop" num)
7990        ()
7991   )
7992 )
7993
7994 (media-cop 1 OP_7C)
7995 (media-cop 2 OP_7D)
7996
7997 ; nop
7998 ; A nop is defined to be a "ori gr0,0,gr0"
7999 ; This needn't be a macro-insn, but making it one greatly simplifies decode.c
8000 ; On the other hand spending a little time in the decoder is often worth it.
8001 ;
8002 (dnmi nop "nop"
8003      ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
8004      "nop$pack"
8005      (emit ori pack (GRi 0) (s12 0) (GRk 0))
8006 )
8007
8008 ; Floating point NOP
8009 (dni fnop
8010      "Floating point nop"
8011      ((UNIT FM01) (FR500-MAJOR F-8) (MACH simple,tomcat,fr500,frv))
8012      "fnop$pack"
8013      (+ pack (rd-null) OP_79 (FRi-null) OPE1_0D (FRj-null))
8014      (nop)
8015      ()
8016 )
8017
8018 ; Media NOP
8019 ; A special case of mclracc
8020 (dnmi mnop "Media nop"
8021       (NO-DIS (UNIT FM01) (FR500-MAJOR M-3))
8022      "mnop$pack"
8023      (emit mclracc pack (ACC40Sk 63) (A 1))
8024 )
8025
8026 ; A return instruction
8027 (dnmi ret "return"
8028       (NO-DIS (UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3))
8029       "ret$pack"
8030       (emit bralr pack (hint_taken 2))
8031 )
8032
8033 (dnmi cmp "compare"
8034       (NO-DIS (UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
8035       "cmp$pack $GRi,$GRj,$ICCi_1"
8036       (emit subcc pack GRi GRj (GRk 0) ICCi_1)
8037 )
8038
8039 (dnmi cmpi "compare immediate"
8040       (NO-DIS (UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
8041       "cmpi$pack $GRi,$s10,$ICCi_1"
8042       (emit subicc pack GRi s10 (GRk 0) ICCi_1)
8043 )
8044
8045 (dnmi ccmp "conditional compare"
8046       (NO-DIS (UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
8047       "ccmp$pack $GRi,$GRj,$CCi,$cond"
8048       (emit csubcc pack GRi GRj (GRk 0) CCi cond)
8049 )
8050
8051 (dnmi mov "move"
8052       (NO-DIS (UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
8053       "mov$pack $GRi,$GRk"
8054       (emit ori pack GRi (s12 0) GRk)
8055 )   
8056
8057 (dnmi cmov "conditional move"
8058       (NO-DIS (UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
8059       "cmov$pack $GRi,$GRk,$CCi,$cond"
8060       (emit cor pack GRi (GRj 0) GRk CCi cond)
8061 )