OSDN Git Service

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