xref: /netbsd-src/external/gpl3/gdb/dist/cpu/epiphany.cpu (revision 8dffb485a119f39f727115fa0bcb569045caf7cb)
1a2e2270fSchristos; Adapteva EPIPHANY CPU description. -*- Scheme -*-
2a2e2270fSchristos; Copyright 1998, 1999, 2000, 2001, 2003, 2006, 2007, 2008, 2009, 2010, 2011
3a2e2270fSchristos; Free Software Foundation, Inc.
4a2e2270fSchristos;
5a2e2270fSchristos; Contributed by Embecosm on behalf of Adapteva, Inc.
6a2e2270fSchristos; This file is part of the GNU Binutils and of GDB.
7a2e2270fSchristos;
8a2e2270fSchristos; This program is free software; you can redistribute it and/or modify
9a2e2270fSchristos; it under the terms of the GNU General Public License as published by
10a2e2270fSchristos; the Free Software Foundation; either version 3 of the License, or
11a2e2270fSchristos; (at your option) any later version.
12a2e2270fSchristos;
13a2e2270fSchristos; This program is distributed in the hope that it will be useful,
14a2e2270fSchristos; but WITHOUT ANY WARRANTY; without even the implied warranty of
15a2e2270fSchristos; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16a2e2270fSchristos; GNU General Public License for more details.
17a2e2270fSchristos;
18a2e2270fSchristos; You should have received a copy of the GNU General Public License
19a2e2270fSchristos; along with this program; if not, write to the Free Software
20a2e2270fSchristos; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21a2e2270fSchristos; MA 02110-1301, USA.
22a2e2270fSchristos
23a2e2270fSchristos(include "simplify.inc")
24a2e2270fSchristos					; define-arch must appear first
25a2e2270fSchristos
26a2e2270fSchristos(define-arch
27a2e2270fSchristos  (name epiphany) ; name of cpu family
28a2e2270fSchristos  (comment "Adapteva, Inc. EPIPHANY family")
29a2e2270fSchristos  (default-alignment aligned)
30a2e2270fSchristos  (insn-lsb0? #t)
31a2e2270fSchristos
32a2e2270fSchristos					; - a 16/32 bit instruction machine (the default)
33a2e2270fSchristos
34a2e2270fSchristos  (machs epiphany32)
35a2e2270fSchristos  (isas epiphany)
36a2e2270fSchristos  )
37a2e2270fSchristos
38a2e2270fSchristos					; Attributes.
39a2e2270fSchristos
40a2e2270fSchristos(define-attr
41a2e2270fSchristos  (for insn)
42a2e2270fSchristos  (type boolean)
43a2e2270fSchristos  (name SHORT-INSN)
44a2e2270fSchristos  (comment "instruction is a 16 bit form")
45a2e2270fSchristos  )
46a2e2270fSchristos
47a2e2270fSchristos;; 3 bit add/sub immediate forms - useful for relaxing into 11 bit form
48a2e2270fSchristos(define-attr
49a2e2270fSchristos  (for insn)
50a2e2270fSchristos  (type boolean)
51a2e2270fSchristos  (name IMM3)
52a2e2270fSchristos  (comment "instruction has a 3 bit immediate form")
53a2e2270fSchristos  )
54a2e2270fSchristos
55a2e2270fSchristos;; 8 bit mov immediate forms - useful for relaxing into 16 bit form
56a2e2270fSchristos(define-attr
57a2e2270fSchristos  (for insn)
58a2e2270fSchristos  (type boolean)
59a2e2270fSchristos  (name IMM8)
60a2e2270fSchristos  (comment "instruction has a 8 bit immediate form")
61a2e2270fSchristos  )
62a2e2270fSchristos
63a2e2270fSchristos					; Instruction set parameters.
64a2e2270fSchristos
65a2e2270fSchristos(define-isa
66a2e2270fSchristos  (name epiphany)
67a2e2270fSchristos  (comment "Adapteva, Inc. EPIPHANY32 ISA")
68a2e2270fSchristos
69a2e2270fSchristos  (default-insn-word-bitsize 32)
70a2e2270fSchristos  (default-insn-bitsize 32)
71a2e2270fSchristos  (base-insn-bitsize 32)
72a2e2270fSchristos  (decode-assist (3 2 1 0))  ; CGEN can figure this out
73a2e2270fSchristos  (liw-insns 1)				; # instructions fetched at once
74a2e2270fSchristos  )
75a2e2270fSchristos
76a2e2270fSchristos					; Cpu family definitions.
77a2e2270fSchristos
78a2e2270fSchristos
79a2e2270fSchristos(define-cpu
80a2e2270fSchristos					; cpu names must be distinct from the architecture name and machine names.
81a2e2270fSchristos  (name epiphanybf)
82a2e2270fSchristos  (comment "Adapteva, Inc. EPIPHANY Family")
83a2e2270fSchristos  (endian little)
84a2e2270fSchristos  (word-bitsize 32)
85a2e2270fSchristos  )
86a2e2270fSchristos
87a2e2270fSchristos(define-cpu
88a2e2270fSchristos  (name epiphanymf)
89a2e2270fSchristos  (comment "Adapteva, Inc. EPIPHANY Family")
90a2e2270fSchristos  (endian little)
91a2e2270fSchristos  (word-bitsize 32)
92a2e2270fSchristos  )
93a2e2270fSchristos
94a2e2270fSchristos
95a2e2270fSchristos(define-mach
96a2e2270fSchristos  (name epiphany32)
97a2e2270fSchristos  (comment "Adapteva EPIPHANY")
98a2e2270fSchristos  (cpu epiphanybf)
99a2e2270fSchristos  )
100a2e2270fSchristos
101a2e2270fSchristos
102a2e2270fSchristos					; Model descriptions.
103a2e2270fSchristos
104a2e2270fSchristos(define-model
105a2e2270fSchristos  (name epiphany32) (comment "Adapteva EPIPHANY 32/16") (attrs)
106a2e2270fSchristos  (mach epiphany32)
107a2e2270fSchristos
108a2e2270fSchristos  (unit u-exec "Execution Unit" ()
109a2e2270fSchristos	1 1 ; issue done
110a2e2270fSchristos	() ; state
111a2e2270fSchristos	() ; inputs
112a2e2270fSchristos	() ; outputs
113a2e2270fSchristos	() ; profile action (default)
114a2e2270fSchristos	)
115a2e2270fSchristos  )
116a2e2270fSchristos
117a2e2270fSchristos
118a2e2270fSchristos
119a2e2270fSchristos					; Instruction fields.
120a2e2270fSchristos					;
121a2e2270fSchristos					; Attributes:
122a2e2270fSchristos					; XXX: what EPIPHANY attrs
123a2e2270fSchristos					; PCREL-ADDR: pc relative value (for reloc and disassembly purposes)
124a2e2270fSchristos					; ABS-ADDR: absolute address (for reloc and disassembly purposes?)
125a2e2270fSchristos					; RESERVED: bits are not used to decode insn, must be all 0
126a2e2270fSchristos					; RELOC: there is a relocation associated with this field
127a2e2270fSchristos
128a2e2270fSchristos(define-attr
129a2e2270fSchristos  (for ifield operand)
130a2e2270fSchristos  (type boolean)
131a2e2270fSchristos  (name RELOC)
132a2e2270fSchristos  (comment "there is a reloc associated with this field (experiment)")
133a2e2270fSchristos  )
134a2e2270fSchristos
135a2e2270fSchristos;; define the fields of the instruction.
136a2e2270fSchristos;;   name            description              ATTR  MSB LEN
137a2e2270fSchristos(dnf f-opc	  "primary opcode"	       ()     3 4)
138a2e2270fSchristos(dnf f-opc-4-1    "secondary opcode"           ()     4 1)
139a2e2270fSchristos(dnf f-opc-6-3    "secondary opcode"           ()     6 3) ;;
140a2e2270fSchristos(dnf f-opc-8-5    "tertiary opcode"            ()     8 5) ;;
141a2e2270fSchristos(dnf f-opc-19-4   "additional opcode bits"     ()    19 4)
142a2e2270fSchristos(dnf f-condcode   "condition codes" 	       ()     7 4)
143a2e2270fSchristos(dnf f-secondary-ccs "flag for secondary ccs"  ()     7 1)
144a2e2270fSchristos(dnf f-shift      "shift amount"               ()     9 5)
145a2e2270fSchristos(dnf f-wordsize   "load/store size"            ()     6 2)
146a2e2270fSchristos(dnf f-store      "load/store flag"            ()     4 1) ;; 0==load,1==store
147a2e2270fSchristos(dnf f-opc-8-1    "opcode bits"                ()     8 1)
148a2e2270fSchristos(dnf f-opc-31-32  "all opcode set"             ()     31 32)
149a2e2270fSchristos
150a2e2270fSchristos(df f-simm8	  "branch displacement"   (PCREL-ADDR RELOC) 15 8 INT
151a2e2270fSchristos    ((value pc) (sra SI (sub SI value pc) 1))
152*8dffb485Schristos    ((value pc) (add SI (mul SI value 2) pc)))
153a2e2270fSchristos
154a2e2270fSchristos(df f-simm24     "branch displacement"	  (PCREL-ADDR RELOC) 31 24 INT
155a2e2270fSchristos    ((value pc) (sra SI (sub SI value pc) 1))
156*8dffb485Schristos    ((value pc) (add SI (mul SI value 2) pc)))
157a2e2270fSchristos
158a2e2270fSchristos(df f-sdisp3     "signed immediate 3 bit"      ()     9 3  INT #f #f)
159a2e2270fSchristos
160a2e2270fSchristos(dnf f-disp3      "address offset"             ()     9 3)
161a2e2270fSchristos(dnf f-disp8      "address offset"             ()    23 8)
162a2e2270fSchristos
163a2e2270fSchristos(dnf f-imm8      "move/add/sub imm8"           ()    12 8)
164a2e2270fSchristos(dnf f-imm-27-8  "move/add/sub imm16"          ()    27 8)
165a2e2270fSchristos(dnf f-addsubx   "+/- index address"           ()    20 1)
166a2e2270fSchristos(dnf f-subd      "+/- displ address"           ()    24 1)
167a2e2270fSchristos(dnf f-pm        "post-modify immediate"       ()    25 1)
168a2e2270fSchristos
169a2e2270fSchristos(dnf f-rm        "short rm"                    ()     9 3)   ;; RM
170a2e2270fSchristos(dnf f-rn        "short rn"                    ()    12 3)   ;; RN
171a2e2270fSchristos(dnf f-rd        "short rd"                    ()    15 3)   ;; RD
172a2e2270fSchristos
173a2e2270fSchristos(dnf f-rm-x       "extension rm"               ()    25 3)   ;; RM
174a2e2270fSchristos(dnf f-rn-x       "extension rn"               ()    28 3)   ;; RN
175a2e2270fSchristos(dnf f-rd-x       "extension rd"               ()    31 3)   ;; RD
176a2e2270fSchristos
177a2e2270fSchristos(dnf f-dc-9-1     "DC"                 (RESERVED)     9 1)
178a2e2270fSchristos
179a2e2270fSchristos(dnf f-sn        "short sn"                    ()    12 3)   ;; SN
180a2e2270fSchristos(dnf f-sd        "short sd"                    ()    15 3)   ;; SD
181a2e2270fSchristos
182a2e2270fSchristos(dnf f-sn-x       "extension sn"               ()    28 3)   ;; SN
183a2e2270fSchristos(dnf f-sd-x       "extension sd"               ()    31 3)   ;; SD
184a2e2270fSchristos
185a2e2270fSchristos
186a2e2270fSchristos
187a2e2270fSchristos(dnf f-dc-7-4     "movts zeros"                 ()     7 4)
188a2e2270fSchristos(dnf f-trap-swi-9-1     "trap or swi"                 ()     9 1)
189a2e2270fSchristos(dnf f-gien-gidis-9-1     "gien or gidis"                 ()     9 1)
190a2e2270fSchristos
191a2e2270fSchristos
192a2e2270fSchristos(dnf f-dc-15-3    "DC"                 (RESERVED)    15 3)
193a2e2270fSchristos(dnf f-dc-15-7    "DC"                 (RESERVED)    15 7)
194a2e2270fSchristos(dnf f-dc-15-6    "DC"                 ()            15 6)
195a2e2270fSchristos(dnf f-trap-num   "trap number"                ()    15 6)
196a2e2270fSchristos
197a2e2270fSchristos(dnf f-dc-20-1    "DC"                 (RESERVED)    20 1)
198a2e2270fSchristos
199a2e2270fSchristos(dnf f-dc-21-1    "DC"                 (RESERVED)    21 1)
200a2e2270fSchristos(dnf f-dc-21-2    "DC"                 (RESERVED)    21 2)
201a2e2270fSchristos
202a2e2270fSchristos(dnf f-dc-22-3    "DC"                 (RESERVED)    22 3)
203a2e2270fSchristos(dnf f-dc-22-2    "DC"                 (RESERVED)    22 2)
204a2e2270fSchristos(dnf f-dc-22-1    "DC"                 (RESERVED)    22 1)
205a2e2270fSchristos
206a2e2270fSchristos(dnf f-dc-25-6    "DC"                 (RESERVED)    25 6)
207a2e2270fSchristos(dnf f-dc-25-4    "DC"                 (RESERVED)    25 4)
208a2e2270fSchristos(dnf f-dc-25-2    "DC"                 (RESERVED)    25 2)
209a2e2270fSchristos(dnf f-dc-25-1    "DC"                 (RESERVED)    25 1)
210a2e2270fSchristos
211a2e2270fSchristos(dnf f-dc-28-1    "DC"                 (RESERVED)    28 1)
212a2e2270fSchristos(dnf f-dc-31-3    "DC"                 (RESERVED)    31 3)
213a2e2270fSchristos
214a2e2270fSchristos(dnmf f-disp11 "Unsigned offset for load/store" () UINT (f-disp3 f-disp8)
215a2e2270fSchristos      (sequence ()
216a2e2270fSchristos		(set (ifield f-disp8) (and (srl (ifield f-disp11) 3) (const 255)))
217a2e2270fSchristos		(set (ifield f-disp3) (and (ifield f-disp11) 7)))
218a2e2270fSchristos      (sequence ()
219a2e2270fSchristos		(set (ifield f-disp11) (or (sll (ifield f-disp8) 3)
220a2e2270fSchristos					   (ifield f-disp3)))
221a2e2270fSchristos		)
222a2e2270fSchristos      )
223a2e2270fSchristos
224a2e2270fSchristos
225a2e2270fSchristos(dnmf f-sdisp11 "Signed offset for load/store" () INT (f-disp3 f-disp8)
226a2e2270fSchristos      (sequence ()			;encode
227a2e2270fSchristos		(set (ifield f-disp8) (and #xff (srl SI (ifield f-sdisp11) 3)))
228a2e2270fSchristos		(set (ifield f-disp3)  (and SI (ifield f-sdisp11) 7)))
229a2e2270fSchristos      (sequence ()			;decode
230a2e2270fSchristos		(set (ifield f-sdisp11)
231*8dffb485Schristos		     (sub SI (xor (and (or (sll (ifield f-disp8) 3)
232a2e2270fSchristos					   (ifield f-disp3))
233*8dffb485Schristos				       #x7ff)
234*8dffb485Schristos				  #x400)
235*8dffb485Schristos			  #x400)))
236a2e2270fSchristos      )
237a2e2270fSchristos
238a2e2270fSchristos(dnmf f-imm16 "Short immediate for move/add/sub" () UINT (f-imm8 f-imm-27-8)
239a2e2270fSchristos      (sequence ()
240a2e2270fSchristos		(set (ifield f-imm8) (and (ifield f-imm16) #xff))
241a2e2270fSchristos		(set (ifield f-imm-27-8) (srl (ifield f-imm16) 8)))
242a2e2270fSchristos      (sequence ()
243a2e2270fSchristos		(set (ifield f-imm16) (or (sll (ifield f-imm-27-8) 8)
244a2e2270fSchristos					  (ifield f-imm8))))
245a2e2270fSchristos      )
246a2e2270fSchristos
247a2e2270fSchristos
248a2e2270fSchristos;; 32 bit instructions have the register number broken into two non-contiguous fields
249a2e2270fSchristos
250a2e2270fSchristos(define-pmacro (x-reg-field reg)
251a2e2270fSchristos  (define-multi-ifield
252a2e2270fSchristos    (name (.sym "f-" reg "6"))
253a2e2270fSchristos    (mode UINT)
254a2e2270fSchristos    (subfields (.sym "f-" reg "-x") (.sym "f-" reg))
255a2e2270fSchristos    (insert (sequence ()
256a2e2270fSchristos		      (set (ifield (.sym "f-" reg))   (and (ifield (.sym "f-" reg "6"))
257a2e2270fSchristos							   (const 7)))
258a2e2270fSchristos		      (set (ifield (.sym "f-" reg "-x"))  (srl (ifield (.sym "f-" reg "6"))
259a2e2270fSchristos							       (const 3)))
260a2e2270fSchristos		      ))
261a2e2270fSchristos    (extract (sequence ()
262a2e2270fSchristos		       (set (ifield (.sym "f-" reg "6")) (or (sll (ifield (.sym "f-" reg "-x"))
263a2e2270fSchristos								  (const 3))
264a2e2270fSchristos							     (ifield (.sym "f-" reg))))
265a2e2270fSchristos		       ))
266a2e2270fSchristos    )
267a2e2270fSchristos  )
268a2e2270fSchristos
269a2e2270fSchristos(x-reg-field rd)			; f-rd6
270a2e2270fSchristos(x-reg-field rn)			; f-rn6
271a2e2270fSchristos(x-reg-field rm)			; f-rm6
272a2e2270fSchristos(x-reg-field sd)			; f-sd6
273a2e2270fSchristos(x-reg-field sn)			; f-sn6
274a2e2270fSchristos
275a2e2270fSchristos
276a2e2270fSchristos;;;;;;;;;;
277a2e2270fSchristos					; Enums. ;
278a2e2270fSchristos;;;;;;;;;;
279a2e2270fSchristos
280a2e2270fSchristos					; insn-opc: bits 3..0 - major family selector
281a2e2270fSchristos(define-normal-insn-enum insn-opc "opc enums" () OP4_ f-opc
282a2e2270fSchristos  (
283a2e2270fSchristos   BRANCH16  ;; 0000
284a2e2270fSchristos   LDSTR16X  ;; 0001
285a2e2270fSchristos   FLOW16    ;; 0010
286a2e2270fSchristos   IMM16     ;; 0011
287a2e2270fSchristos   LDSTR16D  ;; 0100
288a2e2270fSchristos   LDSTR16P  ;; 0101
289a2e2270fSchristos   LSHIFT16  ;; 0110 - logical shift
290a2e2270fSchristos   DSP16     ;; 0111 - 3 reg DSP 16 bit insns
291a2e2270fSchristos   BRANCH    ;; 1000
292a2e2270fSchristos   LDSTRX    ;; 1001
293a2e2270fSchristos   ALU16     ;; 1010 - 3 reg 16 bit
294a2e2270fSchristos   IMM32     ;; 1011
295a2e2270fSchristos   LDSTRD    ;; 1100
296a2e2270fSchristos   LDSTRP    ;; 1101
297a2e2270fSchristos   ASHIFT16  ;; 1110   ASR, BITR
298a2e2270fSchristos   MISC      ;; 1111 - 32 bit shifts, 3 reg ALU, 3 reg DSP, FLOW, BITR
299a2e2270fSchristos   )
300a2e2270fSchristos  )
301a2e2270fSchristos
302a2e2270fSchristos(define-normal-insn-enum insn-wordsize "memory access width" () OPW_ f-wordsize
303a2e2270fSchristos					; specifies the size of a memory load/store operation
304a2e2270fSchristos  (BYTE SHORT WORD DOUBLE)
305a2e2270fSchristos  )
306a2e2270fSchristos
307a2e2270fSchristos(define-normal-insn-enum insn-memory-access "memory access direction" () OP_ f-store
308a2e2270fSchristos					; load=0, store=1
309a2e2270fSchristos  (LOAD STORE)
310a2e2270fSchristos  )
311a2e2270fSchristos
312a2e2270fSchristos					; enum for trap codes used by simulator
313a2e2270fSchristos(define-normal-insn-enum trap-codes "trap instruction dispatch code" () TRAP_ f-trap-num
314a2e2270fSchristos  (write read open exit pass fail close other)
315a2e2270fSchristos  )
316a2e2270fSchristos
317a2e2270fSchristos					; cond branch: bits 7..4
318a2e2270fSchristos					;
319a2e2270fSchristos(define-normal-insn-enum insn-cond "branch conditions" () OPC_ f-condcode
320a2e2270fSchristos  (EQ NE GTU GTEU LTEU LTU GT GTE LT LTE BEQ BNE BLT BLTE B BL))
321a2e2270fSchristos
322a2e2270fSchristos					; dsp 3 operand opcodes
323a2e2270fSchristos(define-normal-insn-enum insn-bop "binary operator subcodes" () OPB_ f-opc-6-3
324a2e2270fSchristos  (EOR ADD LSL SUB LSR AND ASR ORR))
325a2e2270fSchristos
326a2e2270fSchristos					; dsp 3 operand opcodes
327a2e2270fSchristos(define-normal-insn-enum insn-bopext "binary operator subcodes" () OPBE_ f-opc-6-3
328a2e2270fSchristos  (FEXT FDEP LFSR - - - - -))
329a2e2270fSchristos
330a2e2270fSchristos
331a2e2270fSchristos(define-normal-insn-enum insn-fop "floating operators" () OPF_ f-opc-6-3
332a2e2270fSchristos  (ADD SUB MUL MADD MSUB FLOAT FIX FABS))
333a2e2270fSchristos
334a2e2270fSchristos(define-normal-insn-enum insn-fopexn "extended floating operators" () OPF_ f-opc-6-3
335a2e2270fSchristos  (FRECIP FSQRT - - - - - -))
336a2e2270fSchristos
337a2e2270fSchristos
338a2e2270fSchristos
339a2e2270fSchristos
340a2e2270fSchristos; Immediate operation secondary opcodes
341a2e2270fSchristos(define-normal-insn-enum insn-immop "immediate operators" () OPI_ f-opc-6-3
342a2e2270fSchristos  (- ADD - SUB - - - TRAP) ; TRAP is special extension for simulator
343a2e2270fSchristos  )
344a2e2270fSchristos
345a2e2270fSchristos					; don't care fields
346a2e2270fSchristos(define-normal-insn-enum insn-dc-25-2 "don't cares" () OPI_25_2_ f-dc-25-2
347a2e2270fSchristos  (MBZ))
348a2e2270fSchristos
349a2e2270fSchristos; General Register keyword names.
350a2e2270fSchristos(define-keyword
351a2e2270fSchristos  (name gr-names)
352a2e2270fSchristos  (print-name h-registers)
353a2e2270fSchristos  (prefix "")
354a2e2270fSchristos  (values
355a2e2270fSchristos; some preferred aliases
356a2e2270fSchristos   (fp 11) (sp 13) (lr 14)
357a2e2270fSchristos; the default register names
358a2e2270fSchristos   (r0  0)  (r1  1)  (r2  2)  (r3  3)  (r4  4)  (r5  5)  (r6  6)  (r7  7)
359a2e2270fSchristos   (r8  8)  (r9  9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15)
360a2e2270fSchristos   (r16 16) (r17 17) (r18 18) (r19 19) (r20 20) (r21 21) (r22 22) (r23 23)
361a2e2270fSchristos   (r24 24) (r25 25) (r26 26) (r27 27) (r28 28) (r29 29) (r30 30) (r31 31)
362a2e2270fSchristos   (r32 32) (r33 33) (r34 34) (r35 35) (r36 36) (r37 37) (r38 38) (r39 39)
363a2e2270fSchristos   (r40 40) (r41 41) (r42 42) (r43 43) (r44 44) (r45 45) (r46 46) (r47 47)
364a2e2270fSchristos   (r48 48) (r49 49) (r50 50) (r51 51) (r52 52) (r53 53) (r54 54) (r55 55)
365a2e2270fSchristos   (r56 56) (r57 57) (r58 58) (r59 59) (r60 60) (r61 61) (r62 62) (r63 63)
366a2e2270fSchristos; some less popular aliases
367a2e2270fSchristos   (a1  0) (a2  1) (a3  2) (a4  3) (v1  4) (v2  5) (v3  6) (v4  7)
368a2e2270fSchristos   (v5  8) (v6  9) (v7 10) (v8 11)
369a2e2270fSchristos   (sb 9) (sl 10) (ip 12)
370a2e2270fSchristos   )
371a2e2270fSchristos  )
372a2e2270fSchristos
373a2e2270fSchristos(define-normal-insn-enum post-index "+/- index register" () DIR_ f-addsubx (POSTINC POSTDEC))
374a2e2270fSchristos
375a2e2270fSchristos(define-normal-insn-enum disp-post-modify "postmodify displacement" () PMOD_ f-pm (DISP POST))
376a2e2270fSchristos
377a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
378a2e2270fSchristos					; Hardware pieces.
379a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
380a2e2270fSchristos
381a2e2270fSchristos;; 64 general-purpose registers
382a2e2270fSchristos(define-hardware
383a2e2270fSchristos  (name h-registers)
384a2e2270fSchristos  (comment "all addressable registers")
385a2e2270fSchristos  (type register SI (64))
386a2e2270fSchristos  (attrs PROFILE CACHE-ADDR)
387a2e2270fSchristos  (indices extern-keyword gr-names)
388a2e2270fSchristos  )
389a2e2270fSchristos
390a2e2270fSchristos
391a2e2270fSchristos
392a2e2270fSchristos;; Same 64 registers as floating point registers
393a2e2270fSchristos(define-hardware
394a2e2270fSchristos  (name h-fpregisters)
395a2e2270fSchristos  (comment "all GPRs as float values")
396a2e2270fSchristos  (type register SF (64))
397a2e2270fSchristos  (attrs PROFILE VIRTUAL)
398a2e2270fSchristos  (indices extern-keyword gr-names)
399a2e2270fSchristos  (get (index) (subword SF (reg h-registers index) 0))
400a2e2270fSchristos  (set (index newval) (set (reg h-registers index) (subword SI newval 0)))
401a2e2270fSchristos  )
402a2e2270fSchristos
403a2e2270fSchristos;; define processor status bits as physical hardware
404a2e2270fSchristos
405a2e2270fSchristos(define-pmacro (psw-h-bit name cmt)
406a2e2270fSchristos  (dsh name cmt () (register BI)))
407a2e2270fSchristos
408a2e2270fSchristos(psw-h-bit h-zbit "integer zero bit")
409a2e2270fSchristos(psw-h-bit h-nbit "integer neg bit")
410a2e2270fSchristos(psw-h-bit h-cbit "integer carry bit")
411a2e2270fSchristos(psw-h-bit h-vbit "integer overflow bit")
412a2e2270fSchristos(psw-h-bit h-vsbit "integer overflow sticky")
413a2e2270fSchristos
414a2e2270fSchristos
415a2e2270fSchristos(psw-h-bit h-bzbit "floating point zero bit")
416a2e2270fSchristos(psw-h-bit h-bnbit "floating point neg bit")
417a2e2270fSchristos(psw-h-bit h-bvbit "floating point ovfl bit")
418a2e2270fSchristos(psw-h-bit h-bubit "floating point underfl bit")
419a2e2270fSchristos(psw-h-bit h-bibit "floating point invalid bit")
420a2e2270fSchristos(psw-h-bit h-bcbit "floating point carry bit")
421a2e2270fSchristos
422a2e2270fSchristos(psw-h-bit h-bvsbit "floating point overflow sticky")
423a2e2270fSchristos(psw-h-bit h-bisbit  "floating point invalid sticky")
424a2e2270fSchristos(psw-h-bit h-busbit  "floating point underflow sticky")
425a2e2270fSchristos
426a2e2270fSchristos(psw-h-bit h-expcause0bit  "exceprion cause bit0")
427a2e2270fSchristos(psw-h-bit h-expcause1bit  "exceprion cause bit1")
428a2e2270fSchristos(psw-h-bit h-expcause2bit  "external load stalled bit")
429a2e2270fSchristos(psw-h-bit h-extFstallbit  "external fetch stalled bit")
430a2e2270fSchristos
431a2e2270fSchristos(psw-h-bit h-trmbit  "0=round to nearest, 1=trunacte select bit")
432a2e2270fSchristos(psw-h-bit h-invExcEnbit  "invalid exception enable bit")
433a2e2270fSchristos(psw-h-bit h-ovfExcEnbit  "overflow exception enable bit")
434a2e2270fSchristos(psw-h-bit h-unExcEnbit  "underflow exception enablebit ")
435a2e2270fSchristos
436a2e2270fSchristos(psw-h-bit h-timer0bit0  "timer 0 mode selection 0")
437a2e2270fSchristos(psw-h-bit h-timer0bit1  "timer 0 mode selection 1")
438a2e2270fSchristos(psw-h-bit h-timer0bit2  "timer 0 mode selection 2")
439a2e2270fSchristos(psw-h-bit h-timer0bit3  "timer 0 mode selection 3")
440a2e2270fSchristos(psw-h-bit h-timer1bit0  "timer 1 mode selection 0")
441a2e2270fSchristos(psw-h-bit h-timer1bit1  "timer 1 mode selection 1")
442a2e2270fSchristos(psw-h-bit h-timer1bit2  "timer 1 mode selection 2")
443a2e2270fSchristos(psw-h-bit h-timer1bit3  "timer 1 mode selection 3")
444a2e2270fSchristos
445a2e2270fSchristos(psw-h-bit h-mbkptEnbit  "multicore bkpt enable")
446a2e2270fSchristos(psw-h-bit h-clockGateEnbit  "clock gating enable bkpt enable")
447a2e2270fSchristos
448a2e2270fSchristos
449a2e2270fSchristos(psw-h-bit h-coreCfgResBit12 "core config bit 12")
450a2e2270fSchristos(psw-h-bit h-coreCfgResBit13 "core config bit 13")
451a2e2270fSchristos(psw-h-bit h-coreCfgResBit14 "core config bit 14")
452a2e2270fSchristos(psw-h-bit h-coreCfgResBit15 "core config bit 15")
453a2e2270fSchristos(psw-h-bit h-coreCfgResBit16 "core config bit 16")
454a2e2270fSchristos
455a2e2270fSchristos
456a2e2270fSchristos(psw-h-bit h-coreCfgResBit20 "core config bit 20")
457a2e2270fSchristos(psw-h-bit h-coreCfgResBit21 "core config bit 21")
458a2e2270fSchristos
459a2e2270fSchristos(psw-h-bit h-coreCfgResBit24 "core config bit 24")
460a2e2270fSchristos(psw-h-bit h-coreCfgResBit25 "core config bit 25")
461a2e2270fSchristos(psw-h-bit h-coreCfgResBit26 "core config bit 26")
462a2e2270fSchristos(psw-h-bit h-coreCfgResBit27 "core config bit 27")
463a2e2270fSchristos(psw-h-bit h-coreCfgResBit28 "core config bit 28")
464a2e2270fSchristos(psw-h-bit h-coreCfgResBit29 "core config bit 29")
465a2e2270fSchristos(psw-h-bit h-coreCfgResBit30 "core config bit 30")
466a2e2270fSchristos(psw-h-bit h-coreCfgResBit31 "core config bit 31")
467a2e2270fSchristos
468a2e2270fSchristos
469a2e2270fSchristos(psw-h-bit h-arithmetic-modebit0  "arithmetic mode bit0")
470a2e2270fSchristos(psw-h-bit h-arithmetic-modebit1  "arithmetic mode bit1")
471a2e2270fSchristos(psw-h-bit h-arithmetic-modebit2  "arithmetic mode bit2")
472a2e2270fSchristos
473a2e2270fSchristos
474a2e2270fSchristos(psw-h-bit h-gidisablebit "global interrupt disable bit")
475a2e2270fSchristos(psw-h-bit h-kmbit "kernel mode bit")
476a2e2270fSchristos(psw-h-bit h-caibit "core active indicator mode bit")
477a2e2270fSchristos(psw-h-bit h-sflagbit "sflag bit")
478a2e2270fSchristos
479a2e2270fSchristos
480a2e2270fSchristos					; Define operands for each of the physical bits
481a2e2270fSchristos(define-pmacro (psw-bit name hname cmt)
482a2e2270fSchristos  (dnop name cmt (SEM-ONLY) hname f-nil)
483a2e2270fSchristos  )
484a2e2270fSchristos
485a2e2270fSchristos(psw-bit zbit h-zbit "integer zero bit")
486a2e2270fSchristos(psw-bit nbit h-nbit "integer neg bit")
487a2e2270fSchristos(psw-bit cbit h-cbit "integer carry bit")
488a2e2270fSchristos(psw-bit vbit h-vbit "integer overflow bit")
489a2e2270fSchristos
490a2e2270fSchristos(psw-bit bzbit  h-bzbit "floating point zero bit")
491a2e2270fSchristos(psw-bit bnbit  h-bnbit "floating point neg bit")
492a2e2270fSchristos(psw-bit bvbit  h-bvbit "floating point ovfl bit")
493a2e2270fSchristos(psw-bit bcbit  h-bcbit "floating point carry bit")
494a2e2270fSchristos
495a2e2270fSchristos(psw-bit bubit h-bubit "floating point underfl bit")
496a2e2270fSchristos(psw-bit bibit h-bibit "floating point invalid bit")
497a2e2270fSchristos
498a2e2270fSchristos
499a2e2270fSchristos(psw-bit vsbit  h-vsbit  "integer overflow sticky")
500a2e2270fSchristos(psw-bit bvsbit h-bvsbit "floating point overflow sticky")
501a2e2270fSchristos(psw-bit bisbit  h-bisbit  "floating point invalid sticky")
502a2e2270fSchristos(psw-bit busbit  h-busbit  "floating point underflow sticky")
503a2e2270fSchristos(psw-bit expcause0bit h-expcause0bit  "exceprion cause bit0")
504a2e2270fSchristos(psw-bit expcause1bit h-expcause1bit  "exceprion cause bit1")
505a2e2270fSchristos
506a2e2270fSchristos
507a2e2270fSchristos(psw-bit expcause2bit  h-expcause2bit  "external load stalled bit")
508a2e2270fSchristos(psw-bit extFstallbit  h-extFstallbit  "external fetch stalled bit")
509a2e2270fSchristos
510a2e2270fSchristos(psw-bit trmbit  h-trmbit  "0=round to nearest, 1=trunacte selct bit")
511a2e2270fSchristos(psw-bit invExcEnbit  h-invExcEnbit  "invalid exception enable bit")
512a2e2270fSchristos(psw-bit ovfExcEnbit  h-ovfExcEnbit  "overflow exception enable bit")
513a2e2270fSchristos(psw-bit unExcEnbit  h-unExcEnbit  "underflow exception enable bit")
514a2e2270fSchristos
515a2e2270fSchristos(psw-bit timer0bit0  h-timer0bit0  "timer 0 mode selection 0")
516a2e2270fSchristos(psw-bit timer0bit1  h-timer0bit1  "timer 0 mode selection 1")
517a2e2270fSchristos(psw-bit timer0bit2  h-timer0bit2  "timer 0 mode selection 2")
518a2e2270fSchristos(psw-bit timer0bit3  h-timer0bit3  "timer 0 mode selection 3")
519a2e2270fSchristos
520a2e2270fSchristos(psw-bit timer1bit0  h-timer1bit0  "timer 1 mode selection 0")
521a2e2270fSchristos(psw-bit timer1bit1  h-timer1bit1  "timer 1 mode selection 1")
522a2e2270fSchristos(psw-bit timer1bit2  h-timer1bit2  "timer 1 mode selection 2")
523a2e2270fSchristos(psw-bit timer1bit3  h-timer1bit3  "timer 1 mode selection 3")
524a2e2270fSchristos
525a2e2270fSchristos(psw-bit mbkptEnbit  h-mbkptEnbit "multicore bkpt enable")
526a2e2270fSchristos(psw-bit clockGateEnbit  h-clockGateEnbit "clock gate enable enable")
527a2e2270fSchristos
528a2e2270fSchristos(psw-bit arithmetic-modebit0  h-arithmetic-modebit0  "arithmetic mode bit0")
529a2e2270fSchristos(psw-bit arithmetic-modebit1  h-arithmetic-modebit1  "arithmetic mode bit1")
530a2e2270fSchristos(psw-bit arithmetic-modebit2  h-arithmetic-modebit2  "arithmetic mode bit2")
531a2e2270fSchristos
532a2e2270fSchristos(psw-bit coreCfgResBit12  h-coreCfgResBit12 "core config bit 12")
533a2e2270fSchristos(psw-bit coreCfgResBit13  h-coreCfgResBit13 "core config bit 13")
534a2e2270fSchristos(psw-bit coreCfgResBit14  h-coreCfgResBit14 "core config bit 14")
535a2e2270fSchristos(psw-bit coreCfgResBit15  h-coreCfgResBit15 "core config bit 15")
536a2e2270fSchristos(psw-bit coreCfgResBit16  h-coreCfgResBit16 "core config bit 16")
537a2e2270fSchristos
538a2e2270fSchristos(psw-bit coreCfgResBit20  h-coreCfgResBit20 "core config bit 20")
539a2e2270fSchristos(psw-bit coreCfgResBit21  h-coreCfgResBit21 "core config bit 21")
540a2e2270fSchristos
541a2e2270fSchristos(psw-bit coreCfgResBit24  h-coreCfgResBit24 "core config bit 24")
542a2e2270fSchristos(psw-bit coreCfgResBit25  h-coreCfgResBit25 "core config bit 25")
543a2e2270fSchristos(psw-bit coreCfgResBit26  h-coreCfgResBit26 "core config bit 26")
544a2e2270fSchristos(psw-bit coreCfgResBit27  h-coreCfgResBit27 "core config bit 27")
545a2e2270fSchristos(psw-bit coreCfgResBit28  h-coreCfgResBit28 "core config bit 28")
546a2e2270fSchristos(psw-bit coreCfgResBit29  h-coreCfgResBit29 "core config bit 29")
547a2e2270fSchristos(psw-bit coreCfgResBit30  h-coreCfgResBit30 "core config bit 30")
548a2e2270fSchristos(psw-bit coreCfgResBit31  h-coreCfgResBit31 "core config bit 31")
549a2e2270fSchristos
550a2e2270fSchristos
551a2e2270fSchristos(psw-bit gidisablebit h-gidisablebit "global interrupt disable bit")
552a2e2270fSchristos(psw-bit kmbit h-kmbit "kernel mode bit")
553a2e2270fSchristos(psw-bit caibit h-caibit "core actibe indicator bit")
554a2e2270fSchristos(psw-bit sflagbit h-sflagbit "sflag bit")
555a2e2270fSchristos
556a2e2270fSchristos
557a2e2270fSchristos
558a2e2270fSchristos
559a2e2270fSchristos;; Special registers - accessed via MOVTS and MOVFS.
560a2e2270fSchristos;;
561a2e2270fSchristos;;  "Core control and status" in group MR0=0, MR1=0
562a2e2270fSchristos
563a2e2270fSchristos(define-keyword
564a2e2270fSchristos  (name cr-names)
565a2e2270fSchristos  (print-name h-core-registers)
566a2e2270fSchristos  (prefix "")
567a2e2270fSchristos  (values  (config         0)
568a2e2270fSchristos	   (status         1) ; unified condition codes
569a2e2270fSchristos	   (pc             2) ; virtualized PC
570a2e2270fSchristos	   (debug          3);
571a2e2270fSchristos	   (iab            4)
572a2e2270fSchristos	   (lc             5);loop counter            Not impemented
573a2e2270fSchristos	   (ls             6);loop start address      Not impemented
574a2e2270fSchristos	   (le             7);loop end address        Not impemented
575a2e2270fSchristos	   (iret           8)
576a2e2270fSchristos	   (imask          9)
577a2e2270fSchristos	   (ilat           10)
578a2e2270fSchristos	   (ilatst         11)
579a2e2270fSchristos	   (ilatcl         12)
580a2e2270fSchristos	   (ipend          13)
581a2e2270fSchristos	   (ctimer0        14)
582a2e2270fSchristos	   (ctimer1        15)
583a2e2270fSchristos	   (hstatus        16)
584a2e2270fSchristos	   )
585a2e2270fSchristos  )
586a2e2270fSchristos;; DMA registers in group MR0=1, MR1=0
587a2e2270fSchristos
588a2e2270fSchristos(define-keyword
589a2e2270fSchristos  (name crdma-names)
590a2e2270fSchristos  (print-name h-coredma-registers)
591a2e2270fSchristos  (prefix "")
592a2e2270fSchristos  (values
593a2e2270fSchristos
594a2e2270fSchristos
595a2e2270fSchristos   (dma0config     0)
596a2e2270fSchristos   (dma0stride     1)
597a2e2270fSchristos   (dma0count      2)
598a2e2270fSchristos
599a2e2270fSchristos   (dma0srcaddr    3)
600a2e2270fSchristos   (dma0dstaddr    4)
601a2e2270fSchristos
602a2e2270fSchristos   (dma0auto0      5)
603a2e2270fSchristos   (dma0auto1      6)
604a2e2270fSchristos
605a2e2270fSchristos   (dma0status     7)
606a2e2270fSchristos
607a2e2270fSchristos   (dma1config     8)
608a2e2270fSchristos   (dma1stride     9)
609a2e2270fSchristos   (dma1count      10)
610a2e2270fSchristos
611a2e2270fSchristos   (dma1srcaddr    11)
612a2e2270fSchristos   (dma1dstaddr    12)
613a2e2270fSchristos
614a2e2270fSchristos   (dma1auto0      13)
615a2e2270fSchristos   (dma1auto1      14)
616a2e2270fSchristos
617a2e2270fSchristos   (dma1status     15)
618a2e2270fSchristos
619a2e2270fSchristos   )
620a2e2270fSchristos  )
621a2e2270fSchristos;; mem configuration registers in group MR0=0, MR1=1
622a2e2270fSchristos
623a2e2270fSchristos(define-keyword
624a2e2270fSchristos  (name crmem-names)
625a2e2270fSchristos  (print-name h-coremem-registers)
626a2e2270fSchristos  (prefix "")
627a2e2270fSchristos  (values
628a2e2270fSchristos   (memconfig     0)
629a2e2270fSchristos   (memstatus     1)
630a2e2270fSchristos   (memprotect    2)
631a2e2270fSchristos   (memreserve    3)
632a2e2270fSchristos   )
633a2e2270fSchristos  )
634a2e2270fSchristos
635a2e2270fSchristos;; mesh configuration registers in group MR0=1, MR1=1
636a2e2270fSchristos
637a2e2270fSchristos(define-keyword
638a2e2270fSchristos  (name crmesh-names)
639a2e2270fSchristos  (print-name h-coremesh-registers)
640a2e2270fSchristos  (prefix "")
641a2e2270fSchristos
642a2e2270fSchristos  (values
643a2e2270fSchristos
644a2e2270fSchristos
645a2e2270fSchristos   (meshconfig    0)
646a2e2270fSchristos   (coreid    1)
647a2e2270fSchristos   (meshmulticast 2)
648a2e2270fSchristos   (swreset   3)
649a2e2270fSchristos   )
650a2e2270fSchristos  )
651a2e2270fSchristos
652a2e2270fSchristos
653a2e2270fSchristos
654a2e2270fSchristos
655a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
656a2e2270fSchristos					; PC is a byte-addressed register
657a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
658a2e2270fSchristos
659a2e2270fSchristos(dnh h-pc "program counter" (PC PROFILE) (pc) () () ())
660a2e2270fSchristos
661a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
662a2e2270fSchristos					; Memory Effective Address wants to be visible
663a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
664a2e2270fSchristos
665a2e2270fSchristos(dnh h-memaddr "memory effective address" (PROFILE) (register SI) () () ())
666a2e2270fSchristos(dnop memaddr "memory effective address" (SEM-ONLY) h-memaddr f-nil)
667a2e2270fSchristos
668a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
669a2e2270fSchristos					; Special Core Registers
670a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
671a2e2270fSchristos;; STATUS
672a2e2270fSchristos;; [0]=core active indicator
673a2e2270fSchristos;; [1]=global interrupt disable
674a2e2270fSchristos;; [2]=processor mode(1=user mode, 0=kernel mode)
675a2e2270fSchristos;; [3]=wired AND global flag
676a2e2270fSchristos
677a2e2270fSchristos;; [4]=integer zero                        zbit
678a2e2270fSchristos;; [5]=integer negative                    nbit
679a2e2270fSchristos;; [6]=integer carry                       cbit
680a2e2270fSchristos;; [7]=integer overflow                    vbit
681a2e2270fSchristos
682a2e2270fSchristos;; [8]=fpu zero flag                       bzbit
683a2e2270fSchristos;; [9]=fpu negative flag                   bnbit
684a2e2270fSchristos;; [10]=fpu overflow flag                  bvbit
685a2e2270fSchristos;; [11]=fpu carry flag(not used)           bcbit
686a2e2270fSchristos
687a2e2270fSchristos;; [12]=ialu overflow flag(sticky)         vsbit
688a2e2270fSchristos;; [13]=fpu invalid flag(sticky)           bisbit
689a2e2270fSchristos;; [14]=fpu overflow flag(sticky)          bvsbit
690a2e2270fSchristos;; [15]=fpu underflow flag(sticky)         busbit
691a2e2270fSchristos
692a2e2270fSchristos;; [17:16]=exception cause 00=no exception 01=load-store exception 10=fpu exception 11=unimplemented instruction
693a2e2270fSchristos;;                                         expcause1bit
694a2e2270fSchristos;;                                         expcause0bit
695a2e2270fSchristos
696a2e2270fSchristos;; [18]=external load stalled              expcause2bit
697a2e2270fSchristos;; [19]=external fetch stalled             extFstallbit
698a2e2270fSchristos
699a2e2270fSchristos;; [31:20]=RESERVED
700a2e2270fSchristos
701a2e2270fSchristos
702a2e2270fSchristos
703a2e2270fSchristos
704a2e2270fSchristos
705a2e2270fSchristos(define-hardware
706a2e2270fSchristos  (name h-core-registers)
707a2e2270fSchristos  (comment "Special Core Registers")
708a2e2270fSchristos  (type register USI (17))
709a2e2270fSchristos  (attrs)
710a2e2270fSchristos  (indices extern-keyword cr-names)
711a2e2270fSchristos  (get (index)
712a2e2270fSchristos       (cond USI
713a2e2270fSchristos	 ((eq index (const 1)) ; STATUS reg ?
714a2e2270fSchristos	  (or (or (or (or (sll USI kmbit (const 2))
715a2e2270fSchristos			  (sll USI gidisablebit (const 1)))
716a2e2270fSchristos		      (or (or (sll USI expcause1bit (const 17))
717a2e2270fSchristos			      (sll USI expcause0bit (const 16)))
718a2e2270fSchristos			  (or (sll USI expcause2bit (const 18))
719a2e2270fSchristos			      (sll USI extFstallbit (const 19)))))
720a2e2270fSchristos		  (or (or (or (sll USI busbit (const 15))
721a2e2270fSchristos			      (sll USI bisbit (const 13)))
722a2e2270fSchristos			  (or (sll USI bvsbit (const 14))
723a2e2270fSchristos			      (sll USI vsbit (const 12))))
724a2e2270fSchristos		      (or (or (sll USI bvbit (const 10))
725a2e2270fSchristos			      (sll USI bcbit (const 11)))
726a2e2270fSchristos			  (or (sll USI bnbit (const 9))
727a2e2270fSchristos			      (sll USI bzbit (const 8))))))
728a2e2270fSchristos	      (or (or (or (sll USI vbit (const 7))
729a2e2270fSchristos			  (sll USI cbit (const 6)))
730a2e2270fSchristos		      (or (sll USI nbit (const 5))
731a2e2270fSchristos			  (sll USI zbit (const 4))))
732a2e2270fSchristos		  (or (sll USI sflagbit (const 3))
733a2e2270fSchristos		      (sll USI (const 1) (const 0)))))) ;caibit
734a2e2270fSchristos	 ((eq index (const 0)) ; Config reg ?
735a2e2270fSchristos	  (or (or (or (or (or (or (sll USI timer0bit2 (const 6))
736a2e2270fSchristos				  (sll USI timer0bit3 (const 7)))
737a2e2270fSchristos			      (or (or (sll USI coreCfgResBit28 (const 28))
738a2e2270fSchristos				      (sll USI coreCfgResBit29 (const 29)))
739a2e2270fSchristos				  (or (sll USI coreCfgResBit30 (const 30))
740a2e2270fSchristos				      (sll USI coreCfgResBit31 (const 31)))))
741a2e2270fSchristos			  (or (or (sll USI coreCfgResBit24 (const 24))
742a2e2270fSchristos				  (sll USI coreCfgResBit25 (const 25)))
743a2e2270fSchristos			      (or (sll USI coreCfgResBit26 (const 26))
744a2e2270fSchristos				  (sll USI coreCfgResBit27 (const 27)))))
745a2e2270fSchristos		      (or (or (sll USI timer0bit0 (const 4))
746a2e2270fSchristos			      (sll USI timer0bit1 (const 5)))
747a2e2270fSchristos			  (or (sll USI coreCfgResBit14 (const 14))
748a2e2270fSchristos			      (sll USI coreCfgResBit15 (const 15)))))
749a2e2270fSchristos		  (or (or (or (or (sll USI timer1bit2 (const 10))
750a2e2270fSchristos				  (sll USI timer1bit3 (const 11)))
751a2e2270fSchristos			      (or (sll USI coreCfgResBit12 (const 12))
752a2e2270fSchristos				  (sll USI coreCfgResBit13 (const 13))))
753a2e2270fSchristos			  (or (sll USI clockGateEnbit (const 22))
754a2e2270fSchristos			      (sll USI mbkptEnbit (const 23))))
755a2e2270fSchristos		      (or (or (sll USI timer1bit0 (const 8))
756a2e2270fSchristos			      (sll USI timer1bit1 (const 9)))
757a2e2270fSchristos			  (or (sll USI coreCfgResBit20 (const 20))
758a2e2270fSchristos			      (sll USI coreCfgResBit21 (const 21))))))
759a2e2270fSchristos	      (or (or (sll USI invExcEnbit (const 1))
760a2e2270fSchristos		      (sll USI ovfExcEnbit (const 2)))
761a2e2270fSchristos		  (or (or (sll USI trmbit (const 0))
762a2e2270fSchristos			  (sll USI unExcEnbit (const 3)))
763a2e2270fSchristos		      (or (or (sll USI arithmetic-modebit0 (const 17))
764a2e2270fSchristos			      (sll USI arithmetic-modebit1 (const 18)))
765a2e2270fSchristos			  (or (sll USI arithmetic-modebit2 (const 19))
766a2e2270fSchristos			      (sll USI coreCfgResBit16 (const 16)))))))) ;config reg
767a2e2270fSchristos
768a2e2270fSchristos	 ((eq index (const 2)) (raw-reg USI h-pc)) ;PC reg
769a2e2270fSchristos
770a2e2270fSchristos	 (else (raw-reg USI h-core-registers index))))
771a2e2270fSchristos
772a2e2270fSchristos  (set (index val)
773a2e2270fSchristos       (cond VOID
774a2e2270fSchristos	 ((eq index (const 0)) ; CONFIG reg
775a2e2270fSchristos	  (sequence ()
776a2e2270fSchristos	    (set trmbit      (and (const 1) (srl val (const 0))))
777a2e2270fSchristos	    (set invExcEnbit (and (const 1) (srl val (const 1))))
778a2e2270fSchristos	    (set ovfExcEnbit (and (const 1) (srl val (const 2))))
779a2e2270fSchristos	    (set unExcEnbit  (and (const 1) (srl val (const 3))))
780a2e2270fSchristos	    (set timer0bit0  (and (const 1) (srl val (const 4))))
781a2e2270fSchristos	    (set timer0bit1  (and (const 1) (srl val (const 5))))
782a2e2270fSchristos	    (set timer0bit2  (and (const 1) (srl val (const 6))))
783a2e2270fSchristos	    (set timer0bit3  (and (const 1) (srl val (const 7))))
784a2e2270fSchristos	    (set timer1bit0  (and (const 1) (srl val (const 8))))
785a2e2270fSchristos	    (set timer1bit1  (and (const 1) (srl val (const 9))))
786a2e2270fSchristos	    (set timer1bit2  (and (const 1) (srl val (const 10))))
787a2e2270fSchristos	    (set timer1bit3  (and (const 1) (srl val (const 11))))
788a2e2270fSchristos
789a2e2270fSchristos	    (set coreCfgResBit12 (and (const 1) (srl val (const 12))))
790a2e2270fSchristos	    (set coreCfgResBit13 (and (const 1) (srl val (const 13))))
791a2e2270fSchristos	    (set coreCfgResBit14 (and (const 1) (srl val (const 14))))
792a2e2270fSchristos	    (set coreCfgResBit15 (and (const 1) (srl val (const 15))))
793a2e2270fSchristos	    (set coreCfgResBit16 (and (const 1) (srl val (const 16))))
794a2e2270fSchristos
795a2e2270fSchristos	    (set arithmetic-modebit0 (and (const 1) (srl val (const 17))))
796a2e2270fSchristos	    (set arithmetic-modebit1 (and (const 1) (srl val (const 18))))
797a2e2270fSchristos	    (set arithmetic-modebit2 (and (const 1) (srl val (const 19))))
798a2e2270fSchristos
799a2e2270fSchristos	    (set coreCfgResBit20 (and (const 1) (srl val (const 20))))
800a2e2270fSchristos	    (set coreCfgResBit21 (and (const 1) (srl val (const 21))))
801a2e2270fSchristos
802a2e2270fSchristos	    (set clockGateEnbit  (and (const 1) (srl val (const 22))))
803a2e2270fSchristos	    (set mbkptEnbit      (and (const 1) (srl val (const 23))))
804a2e2270fSchristos
805a2e2270fSchristos	    (set coreCfgResBit24 (and (const 1) (srl val (const 24))))
806a2e2270fSchristos	    (set coreCfgResBit25 (and (const 1) (srl val (const 25))))
807a2e2270fSchristos	    (set coreCfgResBit26 (and (const 1) (srl val (const 26))))
808a2e2270fSchristos	    (set coreCfgResBit27 (and (const 1) (srl val (const 27))))
809a2e2270fSchristos	    (set coreCfgResBit28 (and (const 1) (srl val (const 28))))
810a2e2270fSchristos	    (set coreCfgResBit29 (and (const 1) (srl val (const 29))))
811a2e2270fSchristos	    (set coreCfgResBit30 (and (const 1) (srl val (const 30))))
812a2e2270fSchristos	    (set coreCfgResBit31 (and (const 1) (srl val (const 31))))
813a2e2270fSchristos
814a2e2270fSchristos	    (set (raw-reg USI h-core-registers index) val)
815a2e2270fSchristos	    ;; check LSB of CONFIG for rounding mode
816a2e2270fSchristos	    (c-call "epiphany_set_rounding_mode" val)
817a2e2270fSchristos	  )
818a2e2270fSchristos	 )
819a2e2270fSchristos	 ((eq index (const 1))	;STATUS reg ; TODO check which bits can be set or clear
820a2e2270fSchristos	  (sequence ((USI newval))
821a2e2270fSchristos	    (set newval (and val (const #xfff2)))
822a2e2270fSchristos	    (set extFstallbit  (and (const 1) (srl newval (const 19))))
823a2e2270fSchristos	    (set expcause2bit  (and (const 1) (srl newval (const 18))))
824a2e2270fSchristos	    (set expcause1bit  (and (const 1) (srl newval (const 17))))
825a2e2270fSchristos	    (set expcause0bit  (and (const 1) (srl newval (const 16))))
826a2e2270fSchristos	    (set busbit (and (const 1) (srl newval (const 15))))
827a2e2270fSchristos	    (set bisbit (and (const 1) (srl newval (const 13))))
828a2e2270fSchristos	    (set bvsbit (and (const 1) (srl newval (const 14))))
829a2e2270fSchristos	    (set vsbit  (and (const 1) (srl newval (const 12))))
830a2e2270fSchristos	    (set bvbit  (and (const 1) (srl newval (const 10))))
831a2e2270fSchristos	    (set bcbit  (and (const 1) (srl newval (const 11))))
832a2e2270fSchristos	    (set bnbit  (and (const 1) (srl newval (const 9))))
833a2e2270fSchristos	    (set bzbit  (and (const 1) (srl newval (const 8))))
834a2e2270fSchristos	    (set vbit   (and (const 1) (srl newval (const 7))))
835a2e2270fSchristos	    (set cbit   (and (const 1) (srl newval (const 6))))
836a2e2270fSchristos	    (set nbit   (and (const 1) (srl newval (const 5))))
837a2e2270fSchristos	    (set zbit   (and (const 1) (srl newval (const 4))))
838a2e2270fSchristos	    (set sflagbit (and (const 1) (srl newval (const 3))))
839a2e2270fSchristos	    (set kmbit  (and (const 1) (srl newval (const 2))))
840a2e2270fSchristos	    ;;(set gie    (and (const 1) (srl newval (const 1))))
841a2e2270fSchristos	    (set (raw-reg SI h-core-registers (const 1)) newval)
842a2e2270fSchristos	   ))
843a2e2270fSchristos	 ;; causes simulator errors
844a2e2270fSchristos	 ;;	     ((eq index (const 2))	;PC reg
845a2e2270fSchristos	 ;;	      (set pc val))
846a2e2270fSchristos
847a2e2270fSchristos	 (else (set (raw-reg USI h-core-registers index) val))
848a2e2270fSchristos       ))
849a2e2270fSchristos)
850a2e2270fSchristos					; (define-pmacro (hcr-config) (reg h-core-registers 0)) etc.
851a2e2270fSchristos(.splice begin (.unsplice (.map
852a2e2270fSchristos			   (.pmacro (xname xnum)
853a2e2270fSchristos				    (define-pmacro ((.sym hcr- xname)) (reg h-core-registers xnum)))
854a2e2270fSchristos
855a2e2270fSchristos			   (
856a2e2270fSchristos			    config
857a2e2270fSchristos			    status
858a2e2270fSchristos			    pc
859a2e2270fSchristos			    debug
860a2e2270fSchristos			    iab
861a2e2270fSchristos			    lc
862a2e2270fSchristos			    ls
863a2e2270fSchristos			    le
864a2e2270fSchristos			    iret
865a2e2270fSchristos			    imask
866a2e2270fSchristos			    ilat
867a2e2270fSchristos			    ilatst
868a2e2270fSchristos			    ilatcl
869a2e2270fSchristos			    ipend
870a2e2270fSchristos			    ctimer0
871a2e2270fSchristos			    ctimer1
872a2e2270fSchristos			    hstatus
873a2e2270fSchristos
874a2e2270fSchristos
875a2e2270fSchristos
876a2e2270fSchristos			    )
877a2e2270fSchristos
878a2e2270fSchristos			   (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
879a2e2270fSchristos			      )
880a2e2270fSchristos			   )))
881a2e2270fSchristos
882a2e2270fSchristos
883a2e2270fSchristos
884a2e2270fSchristos;; DMA registers in MMR space
885a2e2270fSchristos(define-hardware
886a2e2270fSchristos  (name h-coredma-registers)
887a2e2270fSchristos  (comment "DMA registers in MMR space")
888a2e2270fSchristos  (type register USI (16))
889a2e2270fSchristos  (attrs)
890a2e2270fSchristos  (indices extern-keyword crdma-names)
891a2e2270fSchristos  )
892a2e2270fSchristos
893a2e2270fSchristos;; MEM registers in MMR space
894a2e2270fSchristos(define-hardware
895a2e2270fSchristos  (name h-coremem-registers)
896a2e2270fSchristos  (comment "MEM registers in MMR space")
897a2e2270fSchristos  (type register USI (4))
898a2e2270fSchristos  (attrs)
899a2e2270fSchristos  (indices extern-keyword crmem-names)
900a2e2270fSchristos  )
901a2e2270fSchristos
902a2e2270fSchristos;; MEM registers in MMR space
903a2e2270fSchristos(define-hardware
904a2e2270fSchristos  (name h-coremesh-registers)
905a2e2270fSchristos  (comment "MESH registers in MMR space")
906a2e2270fSchristos  (type register USI (4))
907a2e2270fSchristos  (attrs)
908a2e2270fSchristos  (indices extern-keyword crmesh-names)
909a2e2270fSchristos  )
910a2e2270fSchristos
911a2e2270fSchristos
912a2e2270fSchristos
913a2e2270fSchristos					; Operands
914a2e2270fSchristos
915a2e2270fSchristos					; Branch displacements
916a2e2270fSchristos(define-operand
917a2e2270fSchristos  (name simm24)
918a2e2270fSchristos  (comment "branch address pc-relative")
919a2e2270fSchristos  (attrs RELAX)
920a2e2270fSchristos  (type h-iaddr)
921a2e2270fSchristos  (index f-simm24)
922a2e2270fSchristos  (handlers (parse "branch_addr")))
923a2e2270fSchristos
924a2e2270fSchristos(define-operand
925a2e2270fSchristos  (name simm8)
926a2e2270fSchristos  (comment "branch address pc-relative")
927a2e2270fSchristos  (attrs RELAX)
928a2e2270fSchristos  (type h-iaddr)
929a2e2270fSchristos  (index f-simm8)
930a2e2270fSchristos  (handlers (parse "branch_addr")))
931a2e2270fSchristos
932a2e2270fSchristos
933a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
934a2e2270fSchristos					; Register operands
935a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
936a2e2270fSchristos
937a2e2270fSchristos(define-pmacro (short-regs nm group hw cmt)
938a2e2270fSchristos  (define-operand
939a2e2270fSchristos    (name nm)
940a2e2270fSchristos    (comment cmt)
941a2e2270fSchristos    (attrs)
942a2e2270fSchristos    (type hw)
943a2e2270fSchristos    (index (.sym "f-r" group))
944a2e2270fSchristos    (handlers (parse "shortregs") (print "keyword"))
945a2e2270fSchristos    )
946a2e2270fSchristos  )
947a2e2270fSchristos
948a2e2270fSchristos(define-pmacro (short-regs-core nm group hw cmt)
949a2e2270fSchristos  (define-operand
950a2e2270fSchristos    (name nm)
951a2e2270fSchristos    (comment cmt)
952a2e2270fSchristos    (attrs)
953a2e2270fSchristos    (type hw)
954a2e2270fSchristos    (index (.sym "f-s" group))
955a2e2270fSchristos    (handlers (parse "shortregs") (print "keyword"))
956a2e2270fSchristos    )
957a2e2270fSchristos  )
958a2e2270fSchristos
959a2e2270fSchristos
960a2e2270fSchristos					; short regs (0-7)
961a2e2270fSchristos(short-regs rd d h-registers "destination register")
962a2e2270fSchristos(short-regs rn n h-registers "source register")
963a2e2270fSchristos(short-regs rm m h-registers "source register")
964a2e2270fSchristos
965a2e2270fSchristos(short-regs frd d h-fpregisters "fp destination register")
966a2e2270fSchristos(short-regs frn n h-fpregisters "fp source register")
967a2e2270fSchristos(short-regs frm m h-fpregisters "fp source register")
968a2e2270fSchristos
969a2e2270fSchristos					; long regs (0-63)
970a2e2270fSchristos(dnop rd6 "destination register" () h-registers f-rd6)
971a2e2270fSchristos(dnop rn6 "source register"      () h-registers f-rn6)
972a2e2270fSchristos(dnop rm6 "source register"      () h-registers f-rm6)
973a2e2270fSchristos
974a2e2270fSchristos(dnop frd6 "fp destination register" () h-fpregisters f-rd6)
975a2e2270fSchristos(dnop frn6 "fp source register"      () h-fpregisters f-rn6)
976a2e2270fSchristos(dnop frm6 "fp source register"      () h-fpregisters f-rm6)
977a2e2270fSchristos
978a2e2270fSchristos					; special regs (0-7)
979a2e2270fSchristos(short-regs-core sd d h-core-registers "special destination")
980a2e2270fSchristos(short-regs-core sn n h-core-registers "special source")
981a2e2270fSchristos
982a2e2270fSchristos					; special regs (long form)
983a2e2270fSchristos(dnop sd6 "special destination register" () h-core-registers f-sd6)
984a2e2270fSchristos(dnop sn6 "special source register"      () h-core-registers f-sn6)
985a2e2270fSchristos
986a2e2270fSchristos(dnop sddma "dma register" () h-coredma-registers f-sd6)
987a2e2270fSchristos(dnop sndma "dma register"      () h-coredma-registers f-sn6)
988a2e2270fSchristos(dnop sdmem "mem register" () h-coremem-registers f-sd6)
989a2e2270fSchristos(dnop snmem "mem register"      () h-coremem-registers f-sn6)
990a2e2270fSchristos(dnop sdmesh "mesh register" () h-coremesh-registers f-sd6)
991a2e2270fSchristos(dnop snmesh "mesh register"      () h-coremesh-registers f-sn6)
992a2e2270fSchristos
993a2e2270fSchristos					; Immediate literals - but don't allow register names!
994a2e2270fSchristos(define-pmacro (dimmop nm cmt hwtype idx)
995a2e2270fSchristos  (define-operand (name nm) (comment cmt) (type hwtype) (index idx)
996a2e2270fSchristos    (attrs RELAX)
997a2e2270fSchristos    (handlers (parse "simm_not_reg")
998a2e2270fSchristos	      (print "simm_not_reg")))
999a2e2270fSchristos  )
1000a2e2270fSchristos
1001a2e2270fSchristos(dimmop simm3   "signed 3-bit literal"    h-sint f-sdisp3)
1002a2e2270fSchristos(dimmop simm11  "signed 11-bit literal"   h-sint f-sdisp11)
1003a2e2270fSchristos(dnop disp3  "short data displacement"   () h-uint f-disp3)
1004a2e2270fSchristos(dnop trapnum6 "parameter for swi or trap" () h-uint f-trap-num)
1005a2e2270fSchristos
1006a2e2270fSchristos(define-pmacro (duimmop nm cmt hwtype idx)
1007a2e2270fSchristos  (define-operand (name nm) (comment cmt) (type hwtype) (index idx)
1008a2e2270fSchristos    (attrs)
1009a2e2270fSchristos    (handlers (parse "uimm_not_reg")
1010a2e2270fSchristos	      (print "uimm_not_reg")))
1011a2e2270fSchristos  )
1012a2e2270fSchristos
1013a2e2270fSchristos(duimmop swi_num "unsigned 6-bit swi#" h-uint f-trap-num)
1014a2e2270fSchristos(duimmop disp11 "sign-magnitude data displacement" h-uint f-disp11)
1015a2e2270fSchristos
1016a2e2270fSchristos(dnop shift   "immediate shift amount"   () h-uint f-shift)
1017a2e2270fSchristos
1018a2e2270fSchristos(define-operand (name imm16) (comment "16-bit unsigned literal") (attrs RELAX)
1019a2e2270fSchristos  (type h-addr) (index f-imm16) (handlers (parse "imm16")))
1020a2e2270fSchristos(define-operand (name imm8) (comment "8-bit unsigned literal") (attrs RELAX)
1021a2e2270fSchristos  (type h-addr) (index f-imm8) (handlers (parse "imm8")))
1022a2e2270fSchristos
1023a2e2270fSchristos(define-operand
1024a2e2270fSchristos  (name direction)
1025a2e2270fSchristos  (comment "+/- indexing")
1026a2e2270fSchristos  (attrs)
1027a2e2270fSchristos  (type h-uint)
1028a2e2270fSchristos  (index f-addsubx)
1029a2e2270fSchristos  (handlers (parse "postindex")
1030a2e2270fSchristos	    (print "postindex")))
1031a2e2270fSchristos
1032a2e2270fSchristos(define-operand
1033a2e2270fSchristos  (name dpmi)
1034a2e2270fSchristos  (comment "+/- magnitude immediate displacement")
1035a2e2270fSchristos  (attrs)
1036a2e2270fSchristos  (type h-uint)
1037a2e2270fSchristos  (index f-subd)
1038a2e2270fSchristos  (handlers (parse "postindex")
1039a2e2270fSchristos	    (print "postindex")))
1040a2e2270fSchristos
1041a2e2270fSchristos
1042a2e2270fSchristos
1043a2e2270fSchristos;; call exception macro - no check for imask
1044a2e2270fSchristos(define-pmacro (call-exception vaddr bit-in-ilat)
1045a2e2270fSchristos  (if (eq gidisablebit 0)
1046a2e2270fSchristos      (if (eq (and (hcr-imask) bit-in-ilat) 0)
1047a2e2270fSchristos	  (sequence ()
1048a2e2270fSchristos		    (set kmbit 1)
1049a2e2270fSchristos		    (set gidisablebit 1)
1050a2e2270fSchristos		    (set (hcr-iret) (add pc (const 2)))
1051a2e2270fSchristos		    (set (hcr-ipend) (or (hcr-ipend) (const bit-in-ilat)))
1052a2e2270fSchristos		    (set pc (const vaddr))
1053a2e2270fSchristos
1054a2e2270fSchristos		    )
1055a2e2270fSchristos	  ;; schedule interrupt
1056a2e2270fSchristos	  (set (hcr-ilat) (or (hcr-ilat) (const  bit-in-ilat)))
1057a2e2270fSchristos	  )
1058a2e2270fSchristos      )
1059a2e2270fSchristos  )
1060a2e2270fSchristos
1061a2e2270fSchristos
1062a2e2270fSchristos;;      (lc             5);loop counter            Not impemented
1063a2e2270fSchristos;;       (ls             6);loop start address      Not impemented
1064a2e2270fSchristos;;       (le             7);loop end address        Not impemented
1065a2e2270fSchristos
1066a2e2270fSchristos;;have callback to adjust pc in case od events ( HW loops ... )
1067a2e2270fSchristos(define-pmacro (dni_wrapper isnid stdrdesc attr_ strassembl iopcode proceed null_b)
1068a2e2270fSchristos  (begin
1069a2e2270fSchristos    (dni isnid stdrdesc attr_ strassembl iopcode
1070a2e2270fSchristos	 (sequence () proceed
1071a2e2270fSchristos		   (sequence ((USI tmpPC))
1072a2e2270fSchristos			     ;;(set tmpPC  (c-call  USI "epiphany_post_isn_callback" pc))
1073a2e2270fSchristos
1074a2e2270fSchristos			     (if (eq pc (hcr-le))
1075a2e2270fSchristos				 (set (hcr-lc) (sub (hcr-lc) #x1)))
1076a2e2270fSchristos			     (if (and
1077a2e2270fSchristos				   (eq pc (hcr-le))
1078a2e2270fSchristos				   (not (eq (hcr-lc) #x0)))
1079a2e2270fSchristos				 (set pc (hcr-ls)))
1080a2e2270fSchristos			     )
1081a2e2270fSchristos		   )
1082a2e2270fSchristos	 null_b)
1083a2e2270fSchristos    )
1084a2e2270fSchristos  )
1085a2e2270fSchristos
1086a2e2270fSchristos
1087a2e2270fSchristos
1088a2e2270fSchristos
1089a2e2270fSchristos
1090a2e2270fSchristos;; Some handy macros
1091a2e2270fSchristos;;
1092a2e2270fSchristos
1093a2e2270fSchristos;; define instructions
1094a2e2270fSchristos;;   Short (16 bit forms) must appear first so that instruction
1095a2e2270fSchristos;;   selection can reject them and match long forms when registers
1096a2e2270fSchristos;;   or immediates exceed the values in the 16 bit instructions
1097a2e2270fSchristos
1098a2e2270fSchristos
1099a2e2270fSchristos;; B<COND> SIMM8
1100a2e2270fSchristos;; B<COND> SIMM24
1101a2e2270fSchristos
1102a2e2270fSchristos(define-pmacro (br-insn name cond g-op)
1103a2e2270fSchristos  (begin
1104a2e2270fSchristos					; the 16-bit versions of branch
1105a2e2270fSchristos    (dni (.sym "b" name "16")
1106a2e2270fSchristos	 (.str "Conditional Branch - 16 bit" name)
1107a2e2270fSchristos	 (COND-CTI SHORT-INSN)
1108a2e2270fSchristos	 (.str "b" name ".s $simm8")
1109a2e2270fSchristos	 (+ OP4_BRANCH16 (.sym "OPC_" cond) simm8)
1110a2e2270fSchristos	 (if (g-op)
1111a2e2270fSchristos	     (set pc simm8)
1112a2e2270fSchristos	     )
1113a2e2270fSchristos	 ()
1114a2e2270fSchristos	 )
1115a2e2270fSchristos
1116a2e2270fSchristos    (dnmi (.sym "b" name "16r") "relaxable conditional branch"
1117a2e2270fSchristos	  (COND-CTI RELAXABLE)
1118a2e2270fSchristos	  (.str "b" name " $simm8")
1119a2e2270fSchristos	  (emit (.sym "b" name "16") simm8)
1120a2e2270fSchristos	  )
1121a2e2270fSchristos
1122a2e2270fSchristos    (dni (.sym "b" name)
1123a2e2270fSchristos	 (.str "Conditional Branch " name)
1124a2e2270fSchristos	 (COND-CTI)
1125a2e2270fSchristos	 (.str "b" name ".l $simm24")
1126a2e2270fSchristos	 (+ OP4_BRANCH (.sym "OPC_" cond) simm24)
1127a2e2270fSchristos	 (if (g-op)
1128a2e2270fSchristos	     (set pc simm24)
1129a2e2270fSchristos	     )
1130a2e2270fSchristos	 ()
1131a2e2270fSchristos	 )
1132a2e2270fSchristos
1133a2e2270fSchristos    (dnmi (.sym "b" name "32r") "relaxable conditional branch"
1134a2e2270fSchristos	  (COND-CTI RELAXED)
1135a2e2270fSchristos	  (.str "b" name " $simm24")
1136a2e2270fSchristos	  (emit (.sym "b" name) simm24)
1137a2e2270fSchristos	  )
1138a2e2270fSchristos    )
1139a2e2270fSchristos  )
1140a2e2270fSchristos
1141a2e2270fSchristos
1142a2e2270fSchristos					; basic conditional branches for integer arithmetic
1143a2e2270fSchristos(br-insn "eq"	 EQ	(.pmacro () (eq zbit #x1)))
1144a2e2270fSchristos(br-insn "ne"	 NE	(.pmacro () (eq zbit #x0)))
1145a2e2270fSchristos(br-insn "gtu"   GTU	(.pmacro () (and BI cbit (not BI zbit))))
1146a2e2270fSchristos(br-insn "gteu"  GTEU	(.pmacro () (eq cbit #x1)))
1147a2e2270fSchristos(br-insn "lteu"  LTEU	(.pmacro () (or BI (not BI cbit) zbit)))
1148a2e2270fSchristos(br-insn "ltu"   LTU	(.pmacro () (eq cbit #x0)))
1149a2e2270fSchristos(br-insn "gt"	 GT	(.pmacro () (and BI (not BI zbit) (eq vbit nbit))))
1150a2e2270fSchristos(br-insn "gte"   GTE	(.pmacro () (eq vbit nbit)))
1151a2e2270fSchristos(br-insn "lt"	 LT	(.pmacro () (xor BI vbit nbit)))
1152a2e2270fSchristos(br-insn "lte"   LTE	(.pmacro () (or BI zbit (xor vbit nbit))))
1153a2e2270fSchristos
1154a2e2270fSchristos
1155a2e2270fSchristos					; floating point condition codes (floating point instructions)
1156a2e2270fSchristos(br-insn "beq"   BEQ    (.pmacro () (or BI bzbit bzbit)))
1157a2e2270fSchristos(br-insn "bne"   BNE    (.pmacro () (not BI bzbit)))
1158a2e2270fSchristos(br-insn "blt"   BLT    (.pmacro () (and BI bnbit (not bzbit))))
1159a2e2270fSchristos(br-insn "blte"  BLTE   (.pmacro () (or BI bnbit bzbit)))
1160a2e2270fSchristos
1161a2e2270fSchristos					; unconditional branches
1162a2e2270fSchristos(dni b16 "short unconditional branch" (UNCOND-CTI SHORT-INSN)
1163a2e2270fSchristos     "b.s $simm8"
1164a2e2270fSchristos     (+ OP4_BRANCH16 OPC_B simm8)
1165a2e2270fSchristos     (set pc simm8)
1166a2e2270fSchristos     ()
1167a2e2270fSchristos     )
1168a2e2270fSchristos
1169a2e2270fSchristos(dnmi b16r "relaxable b16"
1170a2e2270fSchristos      (UNCOND-CTI RELAXABLE)
1171a2e2270fSchristos      "b $simm8"
1172a2e2270fSchristos      (emit b16 simm8)
1173a2e2270fSchristos      )
1174a2e2270fSchristos
1175a2e2270fSchristos(dni b "long unconditional branch" (UNCOND-CTI)
1176a2e2270fSchristos     "b.l $simm24"
1177a2e2270fSchristos     (+ OP4_BRANCH OPC_B simm24)
1178a2e2270fSchristos     (set pc simm24)
1179a2e2270fSchristos     ()
1180a2e2270fSchristos     )
1181a2e2270fSchristos
1182a2e2270fSchristos(dnmi b32r "relaxable b"
1183a2e2270fSchristos      (UNCOND-CTI RELAXED)
1184a2e2270fSchristos      "b $simm24"
1185a2e2270fSchristos      (emit b simm24))
1186a2e2270fSchristos
1187a2e2270fSchristos;; BL R,ADDR
1188a2e2270fSchristos
1189a2e2270fSchristos(dni bl16 "branch and link"
1190a2e2270fSchristos     (UNCOND-CTI SHORT-INSN)
1191a2e2270fSchristos     ("bl.s $simm8")
1192a2e2270fSchristos     (+ OP4_BRANCH16 OPC_BL simm8)
1193a2e2270fSchristos     (sequence ()
1194a2e2270fSchristos	       (set (reg h-registers 14) (add pc (const 2)))
1195a2e2270fSchristos	       (set pc simm8))
1196a2e2270fSchristos     ()
1197a2e2270fSchristos     )
1198a2e2270fSchristos
1199a2e2270fSchristos(dnmi bl16r "bl16 relaxable"
1200a2e2270fSchristos      (UNCOND-CTI RELAXABLE)
1201a2e2270fSchristos      "bl $simm8"
1202a2e2270fSchristos      (emit bl16 simm8))
1203a2e2270fSchristos
1204a2e2270fSchristos(dni bl "branch and link"
1205a2e2270fSchristos     (UNCOND-CTI)
1206a2e2270fSchristos     ("bl.l $simm24")
1207a2e2270fSchristos     (+ OP4_BRANCH OPC_BL simm24)
1208a2e2270fSchristos     (sequence ()
1209a2e2270fSchristos	       (set (reg h-registers 14) (add pc (const 4)))
1210a2e2270fSchristos	       (set pc simm24))
1211a2e2270fSchristos     ()
1212a2e2270fSchristos     )
1213a2e2270fSchristos
1214a2e2270fSchristos(dnmi blr "bl relaxable"
1215a2e2270fSchristos      (UNCOND-CTI RELAXED)
1216a2e2270fSchristos      "bl $simm24"
1217a2e2270fSchristos      (emit bl simm24))
1218a2e2270fSchristos
1219a2e2270fSchristos;; JUMP <RN>
1220a2e2270fSchristos(dni jr16 "unconditional jump 16"
1221a2e2270fSchristos     (UNCOND-CTI SHORT-INSN)
1222a2e2270fSchristos     ("jr $rn")
1223a2e2270fSchristos     (+ OP4_FLOW16 (f-opc-8-5 #x14) (f-dc-15-3 #x0) (f-dc-9-1 #x0) rn)
1224a2e2270fSchristos     (set pc rn)
1225a2e2270fSchristos     ()
1226a2e2270fSchristos     )
1227a2e2270fSchristos
1228a2e2270fSchristos;; RTS / JR
1229a2e2270fSchristos;; ??? Putting a constant into a multi-ifield does not work -
1230a2e2270fSchristos;; the constant gets inserted in full into each part.
1231a2e2270fSchristos					;(dnmi rts "return from subroutine"
1232a2e2270fSchristos					;     (UNCOND-CTI)
1233a2e2270fSchristos					;     ("rts")
1234a2e2270fSchristos					;     (emit jr (rn6 14)) ; jr lr  / jr r14
1235a2e2270fSchristos					;)
1236a2e2270fSchristos;; RTS / JR
1237a2e2270fSchristos(dni rts "return from subroutine"
1238a2e2270fSchristos     (ALIAS UNCOND-CTI)
1239a2e2270fSchristos     ("rts")
1240a2e2270fSchristos     (+ OP4_MISC (f-opc-8-5 #x14) (f-opc-19-4 #x2) (f-rn 6) (f-rn-x 1)
1241a2e2270fSchristos	(f-dc-9-1 #x0)
1242a2e2270fSchristos	(f-dc-15-3 #x0)
1243a2e2270fSchristos	(f-dc-25-6 #x0)
1244a2e2270fSchristos	(f-dc-31-3 #x0)
1245a2e2270fSchristos	)
1246a2e2270fSchristos     (set pc (reg h-registers 14))
1247a2e2270fSchristos     ()
1248a2e2270fSchristos     )
1249a2e2270fSchristos
1250a2e2270fSchristos(dni jr "unconditional jump"
1251a2e2270fSchristos     (UNCOND-CTI)
1252a2e2270fSchristos     ("jr $rn6")
1253a2e2270fSchristos     (+ OP4_MISC (f-opc-8-5 #x14) (f-opc-19-4 #x2) rn6
1254a2e2270fSchristos	(f-dc-9-1 #x0)
1255a2e2270fSchristos	(f-dc-15-3 #x0)
1256a2e2270fSchristos	(f-dc-25-6 #x0)
1257a2e2270fSchristos	(f-dc-31-3 #x0)
1258a2e2270fSchristos	)
1259a2e2270fSchristos     (set pc rn6)
1260a2e2270fSchristos     ()
1261a2e2270fSchristos     )
1262a2e2270fSchristos
1263a2e2270fSchristos
1264a2e2270fSchristos;; JALR <RN>
1265a2e2270fSchristos(dni jalr16 "jump and link register"
1266a2e2270fSchristos     (UNCOND-CTI SHORT-INSN)
1267a2e2270fSchristos     ("jalr $rn")
1268a2e2270fSchristos     (+ OP4_FLOW16  (f-opc-8-5 #x15) (f-dc-15-3 #x0) (f-dc-9-1 #x0)  rn)
1269a2e2270fSchristos     (sequence ()
1270a2e2270fSchristos	       (set (reg h-registers 14) (add pc (const 2)))
1271a2e2270fSchristos	       (set pc rn)
1272a2e2270fSchristos	       )
1273a2e2270fSchristos     ()
1274a2e2270fSchristos     )
1275a2e2270fSchristos
1276a2e2270fSchristos(dni jalr "jump and link register"
1277a2e2270fSchristos     (UNCOND-CTI)
1278a2e2270fSchristos     ("jalr $rn6")
1279a2e2270fSchristos     (+ OP4_MISC
1280a2e2270fSchristos	(f-opc-8-5 #x15)
1281a2e2270fSchristos	(f-opc-19-4 #x2)
1282a2e2270fSchristos	rn6
1283a2e2270fSchristos	(f-dc-9-1 #x0)
1284a2e2270fSchristos	(f-dc-15-3 #x0)
1285a2e2270fSchristos	(f-dc-25-6 #x0)
1286a2e2270fSchristos	(f-dc-31-3 #x0)
1287a2e2270fSchristos
1288a2e2270fSchristos	)
1289a2e2270fSchristos     (sequence ()
1290a2e2270fSchristos	       (set (reg h-registers 14) (add pc (const 4)))
1291a2e2270fSchristos	       (set pc rn6))
1292a2e2270fSchristos     ()
1293a2e2270fSchristos     )
1294a2e2270fSchristos
1295a2e2270fSchristos
1296a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1297a2e2270fSchristos					;  Load/Store Memory Instructions
1298a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1299a2e2270fSchristos
1300a2e2270fSchristos
1301a2e2270fSchristos(define-pmacro (callMisaligmentExceptionIfNeeded sel  addr isAligmentAccess)
1302a2e2270fSchristos  (sequence ((BI scale))
1303a2e2270fSchristos    (set isAligmentAccess
1304a2e2270fSchristos	 (case BI sel
1305a2e2270fSchristos	   ((OPW_BYTE)	(eq (and addr #x0) #x0))
1306a2e2270fSchristos	   ((OPW_SHORT)	(eq (and addr #x1) #x0))
1307a2e2270fSchristos	   ((OPW_WORD)	(eq (and addr #x3) #x0))
1308a2e2270fSchristos	   (else	(eq (and addr #x7) #x0))))
1309a2e2270fSchristos    (if (not BI isAligmentAccess)
1310a2e2270fSchristos	(call-exception #x4 #x2))
1311a2e2270fSchristos  )
1312a2e2270fSchristos)
1313a2e2270fSchristos
1314a2e2270fSchristos
1315a2e2270fSchristos
1316a2e2270fSchristos;; helper to convert size selector OPW_<mode> into a literal scale factor
1317a2e2270fSchristos(define-pmacro (ConvertSelectorToShift sel scale)
1318a2e2270fSchristos  (set scale
1319a2e2270fSchristos       (case SI sel
1320a2e2270fSchristos	 ((OPW_BYTE)	(const 0))
1321a2e2270fSchristos	 ((OPW_SHORT)	(const 1))
1322a2e2270fSchristos	 ((OPW_WORD)	(const 2))
1323a2e2270fSchristos	 (else	(const 3))))
1324a2e2270fSchristos)
1325a2e2270fSchristos
1326a2e2270fSchristos;; common load macros from effective address, handling 8/16/32/64 bits
1327a2e2270fSchristos(define-pmacro (load-double-from-ea regnum eff-addr mode sel)
1328a2e2270fSchristos  (sequence ((SI loadaddr) (BI isAligmentAccess))
1329a2e2270fSchristos	    (set loadaddr eff-addr)
1330a2e2270fSchristos	    (callMisaligmentExceptionIfNeeded sel  loadaddr isAligmentAccess)
1331a2e2270fSchristos
1332a2e2270fSchristos	    (if (not (not BI isAligmentAccess))
1333a2e2270fSchristos		(sequence ()
1334a2e2270fSchristos			  (set memaddr loadaddr)
1335a2e2270fSchristos			  (set regnum (mem SI loadaddr))
1336a2e2270fSchristos			  (set loadaddr (add loadaddr (const 4)))
1337a2e2270fSchristos			  (set memaddr loadaddr)
1338a2e2270fSchristos			  (set (reg h-registers
1339a2e2270fSchristos				    (add (index-of regnum)
1340a2e2270fSchristos					 (const 1)))
1341a2e2270fSchristos			       (mem SI loadaddr))
1342a2e2270fSchristos
1343a2e2270fSchristos			  )
1344a2e2270fSchristos		)
1345a2e2270fSchristos	    )
1346a2e2270fSchristos  )
1347a2e2270fSchristos
1348a2e2270fSchristos(define-pmacro (load-from-ea regnum eff-addr mode sel)
1349a2e2270fSchristos  (sequence ((BI isAligmentAccess))
1350a2e2270fSchristos
1351a2e2270fSchristos	    (callMisaligmentExceptionIfNeeded sel eff-addr   isAligmentAccess)
1352a2e2270fSchristos	    (if (not (not BI isAligmentAccess))
1353a2e2270fSchristos		(sequence ()
1354a2e2270fSchristos			  (set memaddr eff-addr)
1355a2e2270fSchristos			  (set regnum (zext SI (mem mode eff-addr)))
1356a2e2270fSchristos			  )
1357a2e2270fSchristos		)
1358a2e2270fSchristos	    )
1359a2e2270fSchristos  ) ;; 8/16/32 bit cases
1360a2e2270fSchristos
1361a2e2270fSchristos
1362a2e2270fSchristos;; common store to effective address, handling 8/16/32/64 bit data
1363a2e2270fSchristos(define-pmacro (store-double-to-ea eff-addr regnum mode sel)
1364a2e2270fSchristos  (sequence ((SI storeaddr) (BI isAligmentAccess))
1365a2e2270fSchristos	    (set storeaddr eff-addr)
1366a2e2270fSchristos	    (callMisaligmentExceptionIfNeeded sel storeaddr isAligmentAccess)
1367a2e2270fSchristos	    (if (not (not BI isAligmentAccess))
1368a2e2270fSchristos		(sequence ()
1369a2e2270fSchristos			  (set memaddr storeaddr)
1370a2e2270fSchristos			  (set (mem SI storeaddr) regnum)
1371a2e2270fSchristos			  (set storeaddr (add storeaddr (const 4)))
1372a2e2270fSchristos			  (set memaddr storeaddr)
1373a2e2270fSchristos			  (set (mem SI storeaddr)
1374a2e2270fSchristos			       (reg h-registers (add (index-of regnum) (const 1))))
1375a2e2270fSchristos			  )
1376a2e2270fSchristos		)
1377a2e2270fSchristos	    )
1378a2e2270fSchristos  )
1379a2e2270fSchristos
1380a2e2270fSchristos(define-pmacro (store-to-ea eff-addr regnum mode sel)
1381a2e2270fSchristos  (sequence ((BI isAligmentAccess))
1382a2e2270fSchristos	    (callMisaligmentExceptionIfNeeded sel eff-addr   isAligmentAccess)
1383a2e2270fSchristos	    (if (not (not BI isAligmentAccess))
1384a2e2270fSchristos		(sequence ()
1385a2e2270fSchristos			  (set memaddr eff-addr)
1386a2e2270fSchristos			  (set (mem mode eff-addr) regnum)
1387a2e2270fSchristos			  )
1388a2e2270fSchristos		)
1389a2e2270fSchristos	    )
1390a2e2270fSchristos  )	;8/16/32 bit cases
1391a2e2270fSchristos
1392a2e2270fSchristos
1393a2e2270fSchristos(define-pmacro (load-insn name mode sel sem-op)
1394a2e2270fSchristos  (begin
1395a2e2270fSchristos    (dni_wrapper (.sym name "x16.s")
1396a2e2270fSchristos		 (.str "load " mode " indexed")
1397a2e2270fSchristos		 (SHORT-INSN)
1398a2e2270fSchristos		 (.str name " $rd,[$rn,$rm]")
1399a2e2270fSchristos		 (+ OP4_LDSTR16X sel OP_LOAD rd rn rm)
1400a2e2270fSchristos		 (sequence ()
1401a2e2270fSchristos			   (sem-op rd (add rn rm) mode sel))
1402a2e2270fSchristos		 ()
1403a2e2270fSchristos		 )
1404a2e2270fSchristos
1405a2e2270fSchristos
1406a2e2270fSchristos    (dni_wrapper (.sym name "p16.s")
1407a2e2270fSchristos		 (.str "load " mode " postmodify")
1408a2e2270fSchristos		 (SHORT-INSN)
1409a2e2270fSchristos		 (.str name " $rd,[$rn],$rm")
1410a2e2270fSchristos		 (+ OP4_LDSTR16P sel OP_LOAD rd rn rm)
1411a2e2270fSchristos		 (sequence ((SI tmprm))
1412a2e2270fSchristos			   (set tmprm rm)
1413a2e2270fSchristos			   (sem-op rd rn mode sel)
1414a2e2270fSchristos			   (set rn (add rn tmprm)))
1415a2e2270fSchristos		 ()
1416a2e2270fSchristos		 )
1417a2e2270fSchristos
1418a2e2270fSchristos
1419a2e2270fSchristos    (dni_wrapper (.sym name "x.l")
1420a2e2270fSchristos		 (.str "load " mode " indexed")
1421a2e2270fSchristos		 ()
1422a2e2270fSchristos		 (.str name " $rd6,[$rn6,$direction$rm6]")
1423a2e2270fSchristos		 (+ OP4_LDSTRX sel OP_LOAD (f-opc-19-4 #x0) (f-dc-22-1 #x0) (f-dc-21-1 #x0) rd6 rn6 direction rm6)
1424a2e2270fSchristos		 (sequence ()
1425a2e2270fSchristos			   (if (ifield f-addsubx)
1426a2e2270fSchristos			       (sem-op rd6 (sub rn6 rm6) mode sel)
1427a2e2270fSchristos			       (sem-op rd6 (add rn6 rm6) mode sel)))
1428a2e2270fSchristos		 ()
1429a2e2270fSchristos		 )
1430a2e2270fSchristos
1431a2e2270fSchristos    (dnmi (.sym name "x")
1432a2e2270fSchristos	  (.str "load " mode " indexed")
1433a2e2270fSchristos	  (NO-DIS)
1434a2e2270fSchristos	  (.str name ".l $rd6,[$rn6,$direction$rm6]")
1435a2e2270fSchristos	  (emit  (.sym name "x.l") rd6 rn6 direction rm6)
1436a2e2270fSchristos	  )
1437a2e2270fSchristos
1438a2e2270fSchristos
1439a2e2270fSchristos
1440a2e2270fSchristos    (dni_wrapper (.sym name "p.l")
1441a2e2270fSchristos		 (.str "load " mode " postmodify")
1442a2e2270fSchristos		 ()
1443a2e2270fSchristos		 (.str name " $rd6,[$rn6],$direction$rm6")
1444a2e2270fSchristos		 (+ OP4_LDSTRP sel OP_LOAD (f-opc-19-4 #x0) (f-dc-22-2 #x0) rd6 rn6 direction rm6)
1445a2e2270fSchristos		 (sequence ((SI tmprm))
1446a2e2270fSchristos			   (set tmprm rm6)
1447a2e2270fSchristos			   (sem-op rd6 rn6 mode sel)
1448a2e2270fSchristos			   (if (ifield f-addsubx)
1449a2e2270fSchristos			       (set rn6 (sub rn6 tmprm))
1450a2e2270fSchristos			       (set rn6 (add rn6 tmprm)))
1451a2e2270fSchristos			   )
1452a2e2270fSchristos		 ()
1453a2e2270fSchristos		 )
1454a2e2270fSchristos
1455a2e2270fSchristos
1456a2e2270fSchristos    (dnmi (.sym name "p")
1457a2e2270fSchristos	  (.str "load " mode " postmodify")
1458a2e2270fSchristos	  (NO-DIS)
1459a2e2270fSchristos	  (.str name ".l $rd6,[$rn6],$direction$rm6")
1460a2e2270fSchristos	  (emit  (.sym name "p.l") rd6 rn6 direction rm6)
1461a2e2270fSchristos	  )
1462a2e2270fSchristos
1463a2e2270fSchristos
1464a2e2270fSchristos    ;;immediate modes last so reg forms found first.
1465a2e2270fSchristos    (dni_wrapper (.sym name "d16.s")
1466a2e2270fSchristos		 (.str "load " mode " displacement")
1467a2e2270fSchristos		 (SHORT-INSN IMM3)
1468a2e2270fSchristos		 (.str name " $rd,[$rn,$disp3]")
1469a2e2270fSchristos		 (+ OP4_LDSTR16D sel OP_LOAD rd rn disp3) ;; convert size to 'B'
1470a2e2270fSchristos		 (sequence ((SI effa)
1471a2e2270fSchristos			    (SI scale))
1472a2e2270fSchristos			   (ConvertSelectorToShift sel scale)
1473a2e2270fSchristos			   (set effa (add rn (sll disp3 scale)))
1474a2e2270fSchristos			   (sem-op rd effa mode sel)
1475a2e2270fSchristos			   )
1476a2e2270fSchristos		 ()
1477a2e2270fSchristos		 )
1478a2e2270fSchristos
1479a2e2270fSchristos
1480a2e2270fSchristos    (dni_wrapper (.sym name "d.l")
1481a2e2270fSchristos		 (.str "load " mode " displacement")
1482a2e2270fSchristos		 ()
1483a2e2270fSchristos		 (.str name " $rd6,[$rn6,$dpmi$disp11]")
1484a2e2270fSchristos		 (+ OP4_LDSTRD sel OP_LOAD PMOD_DISP rd6 rn6 dpmi disp11)
1485a2e2270fSchristos		 (sequence ((SI effa)
1486a2e2270fSchristos			    (SI scale))
1487a2e2270fSchristos			   (ConvertSelectorToShift sel scale)
1488a2e2270fSchristos			   (if dpmi
1489a2e2270fSchristos			       (set effa (sub rn6 (sll disp11 scale)))
1490a2e2270fSchristos			       (set effa (add rn6 (sll disp11 scale)))
1491a2e2270fSchristos			       )
1492a2e2270fSchristos			   (sem-op rd6 effa mode sel)
1493a2e2270fSchristos			   )
1494a2e2270fSchristos		 ()
1495a2e2270fSchristos		 )
1496a2e2270fSchristos
1497a2e2270fSchristos    (dnmi (.sym name "d")
1498a2e2270fSchristos	  (.str "load " mode " displacement")
1499a2e2270fSchristos	  (NO-DIS)
1500a2e2270fSchristos	  (.str name ".l $rd6,[$rn6,$dpmi$disp11]")
1501a2e2270fSchristos	  (emit  (.sym name "d.l") rd6 rn6  dpmi disp11)
1502a2e2270fSchristos	  )
1503a2e2270fSchristos
1504a2e2270fSchristos
1505a2e2270fSchristos
1506a2e2270fSchristos    (dni_wrapper (.sym name "dpm.l")
1507a2e2270fSchristos		 (.str "load " mode " displacement post-modify")
1508a2e2270fSchristos		 ()
1509a2e2270fSchristos		 (.str name " $rd6,[$rn6],$dpmi$disp11")
1510a2e2270fSchristos		 (+ OP4_LDSTRD sel OP_LOAD PMOD_POST rd6 rn6 dpmi disp11)
1511a2e2270fSchristos		 (sequence ((SI scale))
1512a2e2270fSchristos			   (ConvertSelectorToShift sel scale)
1513a2e2270fSchristos			   (sem-op rd6 rn6 mode sel)
1514a2e2270fSchristos			   (if dpmi
1515a2e2270fSchristos			       (set rn6 (sub rn6 (sll disp11 scale)))
1516a2e2270fSchristos			       (set rn6 (add rn6 (sll disp11 scale)))
1517a2e2270fSchristos			       )
1518a2e2270fSchristos			   )
1519a2e2270fSchristos		 ()
1520a2e2270fSchristos		 )
1521a2e2270fSchristos
1522a2e2270fSchristos    (dnmi (.sym name "dpm")
1523a2e2270fSchristos	  (.str "load " mode " displacement post-modify")
1524a2e2270fSchristos	  (NO-DIS)
1525a2e2270fSchristos	  (.str name ".l $rd6,[$rn6],$dpmi$disp11")
1526a2e2270fSchristos	  (emit  (.sym name "dpm.l") rd6 rn6  dpmi disp11)
1527a2e2270fSchristos	  )
1528a2e2270fSchristos
1529a2e2270fSchristos
1530a2e2270fSchristos    ;; ;; macro form with a zero displacement
1531a2e2270fSchristos    (dnmi (.sym name "ds0") "load with 0 disp"
1532a2e2270fSchristos	  (SHORT-INSN IMM3)
1533a2e2270fSchristos	  (.str name " $rd,[$rn]")
1534a2e2270fSchristos	  (emit (.sym name "d16.s") rd rn (disp3 0))
1535a2e2270fSchristos	  )
1536a2e2270fSchristos    (dnmi (.sym name "dl0") "load with 0 disp"
1537a2e2270fSchristos    	  (NO-DIS)
1538a2e2270fSchristos	  (.str name " $rd6,[$rn6]")
1539a2e2270fSchristos	  (emit (.sym name "d.l") rd6 rn6 (dpmi 0) (disp11 0))
1540a2e2270fSchristos	  )
1541a2e2270fSchristos    (dnmi (.sym name "dl0.l") "load with 0 disp"
1542a2e2270fSchristos    	  (NO-DIS)
1543a2e2270fSchristos	  (.str name ".l $rd6,[$rn6]")
1544a2e2270fSchristos	  (emit (.sym name "d.l") rd6 rn6 (dpmi 0) (disp11 0))
1545a2e2270fSchristos	  )
1546a2e2270fSchristos
1547a2e2270fSchristos
1548a2e2270fSchristos    )
1549a2e2270fSchristos  )
1550a2e2270fSchristos
1551a2e2270fSchristos(load-insn ldrb QI OPW_BYTE load-from-ea)
1552a2e2270fSchristos(load-insn ldrh HI OPW_SHORT load-from-ea)
1553a2e2270fSchristos(load-insn ldr  SI OPW_WORD  load-from-ea)
1554a2e2270fSchristos(load-insn ldrd DI OPW_DOUBLE load-double-from-ea)
1555a2e2270fSchristos
1556a2e2270fSchristos
1557a2e2270fSchristos
1558a2e2270fSchristos
1559a2e2270fSchristos;; TMP = MEM[RD+RM];    /* Copy content of memory to tmp.  */
1560a2e2270fSchristos;; if (~TMP)            /* Check if memory location is zero.  */
1561a2e2270fSchristos;;   MEM[RD+RM] = RD;   /* If zero, write RD to memory.  */
1562a2e2270fSchristos;; RD = TMP;            /* Always write tmp into RD (NOTE it's destructive).  */
1563a2e2270fSchristos
1564a2e2270fSchristos
1565a2e2270fSchristos(define-pmacro (testset-insn name mode sel)
1566a2e2270fSchristos  (begin
1567a2e2270fSchristos
1568a2e2270fSchristos
1569a2e2270fSchristos    (dni_wrapper (.sym name "t")
1570a2e2270fSchristos		 (.str "testset " mode " indexed")
1571a2e2270fSchristos		 ()
1572a2e2270fSchristos		 (.str name " $rd6,[$rn6,$direction$rm6]")
1573a2e2270fSchristos		 (+ OP4_LDSTRX sel OP_LOAD (f-opc-19-4 #x0) (f-dc-22-1 #x0) (f-dc-21-1 #x1)
1574a2e2270fSchristos		    rd6 rn6 direction rm6)
1575a2e2270fSchristos		 (sequence ((SI tmemaddr) (SI tmpValReg))
1576a2e2270fSchristos
1577a2e2270fSchristos			   ;;back up register
1578a2e2270fSchristos			   (set tmpValReg rd6)
1579a2e2270fSchristos
1580a2e2270fSchristos			   (if (ifield f-addsubx)
1581a2e2270fSchristos			       (set  tmemaddr  (sub rn6 rm6))
1582a2e2270fSchristos			       (set  tmemaddr  (add rn6 rm6))
1583a2e2270fSchristos			       )
1584a2e2270fSchristos			   ;;always update rd
1585a2e2270fSchristos			   (load-from-ea rd6 tmemaddr  mode sel)
1586a2e2270fSchristos			   ;;if zero
1587a2e2270fSchristos			   (if  rd6
1588a2e2270fSchristos				(nop)
1589a2e2270fSchristos				(set (mem mode tmemaddr) tmpValReg)
1590a2e2270fSchristos				)
1591a2e2270fSchristos
1592a2e2270fSchristos			   )
1593a2e2270fSchristos		 ()
1594a2e2270fSchristos		 )
1595a2e2270fSchristos
1596a2e2270fSchristos
1597a2e2270fSchristos    (dnmi  (.sym name "t.l")
1598a2e2270fSchristos	   (.str "testset " mode ".l indexed")
1599a2e2270fSchristos	   (NO-DIS)
1600a2e2270fSchristos	   (.str name ".l $rd6,[$rn6,$direction$rm6]")
1601a2e2270fSchristos	   (emit (.sym name "t") rd6 rn6 direction rm6)
1602a2e2270fSchristos	   )
1603a2e2270fSchristos
1604a2e2270fSchristos
1605a2e2270fSchristos    )
1606a2e2270fSchristos  )
1607a2e2270fSchristos
1608a2e2270fSchristos(testset-insn testsetb QI OPW_BYTE)
1609a2e2270fSchristos(testset-insn testseth HI OPW_SHORT)
1610a2e2270fSchristos(testset-insn testset  SI OPW_WORD)
1611a2e2270fSchristos;;no double mode support, since we have to send the src address, data
1612a2e2270fSchristos;;(testset-insn testsetd DI OPW_DOUBLE load-double-from-ea)
1613a2e2270fSchristos
1614a2e2270fSchristos
1615a2e2270fSchristos
1616a2e2270fSchristos;; need 16 bit forms too
1617a2e2270fSchristos(define-pmacro (store-insn name mode sel sem-op)
1618a2e2270fSchristos  (begin
1619a2e2270fSchristos    (dni_wrapper (.sym name "x16")
1620a2e2270fSchristos		 (.str "store" mode " indexed")
1621a2e2270fSchristos		 (SHORT-INSN)
1622a2e2270fSchristos		 (.str name " $rd,[$rn,$rm]")
1623a2e2270fSchristos		 (+ OP4_LDSTR16X sel OP_STORE rd rn rm)
1624a2e2270fSchristos		 (sequence ()
1625a2e2270fSchristos			   (sem-op (add rn rm) rd mode sel)
1626a2e2270fSchristos			   )
1627a2e2270fSchristos		 ()
1628a2e2270fSchristos		 )
1629a2e2270fSchristos
1630a2e2270fSchristos    (dni_wrapper (.sym name "x")
1631a2e2270fSchristos		 (.str "store" mode " indexed")
1632a2e2270fSchristos		 ()
1633a2e2270fSchristos		 (.str name " $rd6,[$rn6,$direction$rm6]")
1634a2e2270fSchristos		 (+ OP4_LDSTRX sel OP_STORE (f-opc-19-4 #x0)  (f-dc-22-1 #x0) (f-dc-21-1 #x0) rd6 rn6 direction rm6)
1635a2e2270fSchristos		 (sequence ()
1636a2e2270fSchristos			   (if (ifield f-addsubx)
1637a2e2270fSchristos			       (sem-op (sub rn6 rm6) rd6 mode sel)
1638a2e2270fSchristos			       (sem-op (add rn6 rm6) rd6 mode sel)
1639a2e2270fSchristos			       ))
1640a2e2270fSchristos		 ()
1641a2e2270fSchristos		 )
1642a2e2270fSchristos
1643a2e2270fSchristos    (dnmi (.sym name "x.l")
1644a2e2270fSchristos	  (.str "store" mode " indexed")
1645a2e2270fSchristos	  (NO-DIS)
1646a2e2270fSchristos	  (.str name ".l $rd6,[$rn6,$direction$rm6]")
1647a2e2270fSchristos	  (emit  (.sym name "x")  rd6 rn6 direction rm6)
1648a2e2270fSchristos	  )
1649a2e2270fSchristos
1650a2e2270fSchristos
1651a2e2270fSchristos
1652a2e2270fSchristos
1653a2e2270fSchristos
1654a2e2270fSchristos    (dni_wrapper (.sym name "p16")
1655a2e2270fSchristos		 (.str "store " mode " postmodify")
1656a2e2270fSchristos		 (SHORT-INSN)
1657a2e2270fSchristos		 (.str name " $rd,[$rn],$rm")
1658a2e2270fSchristos		 (+ OP4_LDSTR16P sel OP_STORE rd rn rm)
1659a2e2270fSchristos		 (sequence ()
1660a2e2270fSchristos			   (sem-op rn rd mode sel)
1661a2e2270fSchristos			   (set rn (add rn rm))
1662a2e2270fSchristos			   )
1663a2e2270fSchristos		 ()
1664a2e2270fSchristos		 )
1665a2e2270fSchristos
1666a2e2270fSchristos    (dni_wrapper (.sym name "p")
1667a2e2270fSchristos		 (.str "store " mode " postmodify")
1668a2e2270fSchristos		 ()
1669a2e2270fSchristos		 (.str name " $rd6,[$rn6],$direction$rm6")
1670a2e2270fSchristos		 (+ OP4_LDSTRP sel OP_STORE (f-opc-19-4 #x0) (f-dc-22-2 #x0) rd6 rn6 direction rm6)
1671a2e2270fSchristos		 (sequence ()
1672a2e2270fSchristos			   (sem-op rn6 rd6 mode sel)
1673a2e2270fSchristos			   (if (ifield f-addsubx)
1674a2e2270fSchristos			       (set rn6	(sub rn6 rm6))
1675a2e2270fSchristos			       (set rn6 (add rn6 rm6)))
1676a2e2270fSchristos			   )
1677a2e2270fSchristos		 ()
1678a2e2270fSchristos		 )
1679a2e2270fSchristos    (dnmi (.sym name "p.l")
1680a2e2270fSchristos	  (.str "store " mode " postmodify")
1681a2e2270fSchristos	  (NO-DIS)
1682a2e2270fSchristos	  (.str name ".l $rd6,[$rn6],$direction$rm6")
1683a2e2270fSchristos	  (emit (.sym name "p") rd6 rn6 direction rm6)
1684a2e2270fSchristos	  )
1685a2e2270fSchristos
1686a2e2270fSchristos    (dni_wrapper (.sym name "d16")
1687a2e2270fSchristos		 (.str "store " mode " displacement")
1688a2e2270fSchristos		 (SHORT-INSN IMM3)
1689a2e2270fSchristos		 (.str name " $rd,[$rn,$disp3]")
1690a2e2270fSchristos		 (+ OP4_LDSTR16D sel OP_STORE rd rn disp3) ;; convert size to 'B'
1691a2e2270fSchristos		 (sequence ((SI effa)
1692a2e2270fSchristos			    (SI scale))
1693a2e2270fSchristos			   (ConvertSelectorToShift sel scale)
1694a2e2270fSchristos			   (set effa (add rn (sll disp3 scale)))
1695a2e2270fSchristos			   (sem-op effa rd mode sel)
1696a2e2270fSchristos			   )
1697a2e2270fSchristos		 ()
1698a2e2270fSchristos		 )
1699a2e2270fSchristos
1700a2e2270fSchristos    (dni_wrapper (.sym name "d")
1701a2e2270fSchristos		 (.str "store " mode " displacement")
1702a2e2270fSchristos		 ()
1703a2e2270fSchristos		 (.str name " $rd6,[$rn6,$dpmi$disp11]")
1704a2e2270fSchristos		 (+ OP4_LDSTRD sel OP_STORE PMOD_DISP rd6 rn6 dpmi disp11)
1705a2e2270fSchristos		 (sequence ((SI effa)
1706a2e2270fSchristos			    (SI scale))
1707a2e2270fSchristos			   (ConvertSelectorToShift sel scale)
1708a2e2270fSchristos			   (if dpmi
1709a2e2270fSchristos			       (set effa (sub rn6 (sll disp11 scale)))
1710a2e2270fSchristos			       (set effa (add rn6 (sll disp11 scale)))
1711a2e2270fSchristos			       )
1712a2e2270fSchristos			   (sem-op effa rd6 mode sel)
1713a2e2270fSchristos			   )
1714a2e2270fSchristos		 ()
1715a2e2270fSchristos		 )
1716a2e2270fSchristos
1717a2e2270fSchristos    (dnmi (.sym name "d.l")
1718a2e2270fSchristos	  (.str "store " mode " displacement")
1719a2e2270fSchristos	  (NO-DIS)
1720a2e2270fSchristos	  (.str name ".l $rd6,[$rn6,$dpmi$disp11]")
1721a2e2270fSchristos	  (emit (.sym name "d") rd6 rn6 dpmi disp11)
1722a2e2270fSchristos	  )
1723a2e2270fSchristos
1724a2e2270fSchristos
1725a2e2270fSchristos    (dni_wrapper (.sym name "dpm")
1726a2e2270fSchristos		 (.str "store " mode " displacement post-modify")
1727a2e2270fSchristos		 ()
1728a2e2270fSchristos		 (.str name " $rd6,[$rn6],$dpmi$disp11")
1729a2e2270fSchristos		 (+ OP4_LDSTRD sel OP_STORE PMOD_POST rd6 rn6 dpmi disp11) ;; convert size to 'B'
1730a2e2270fSchristos		 (sequence ((SI scale))
1731a2e2270fSchristos			   (ConvertSelectorToShift sel scale)
1732a2e2270fSchristos			   (sem-op rn6 rd6 mode sel)
1733a2e2270fSchristos			   (if dpmi
1734a2e2270fSchristos			       (set rn6 (sub rn6 (sll disp11 scale)))
1735a2e2270fSchristos			       (set rn6 (add rn6 (sll disp11 scale)))
1736a2e2270fSchristos			       )
1737a2e2270fSchristos			   )
1738a2e2270fSchristos		 ()
1739a2e2270fSchristos		 )
1740a2e2270fSchristos    (dnmi (.sym name "dpm.l")
1741a2e2270fSchristos	  (.str "store " mode " displacement post-modify")
1742a2e2270fSchristos	  (NO-DIS)
1743a2e2270fSchristos	  (.str name ".l $rd6,[$rn6],$dpmi$disp11")
1744a2e2270fSchristos	  (emit (.sym name "dpm") rd6 rn6 dpmi disp11)
1745a2e2270fSchristos	  )
1746a2e2270fSchristos
1747a2e2270fSchristos    ;; macro form with a zero displacement
1748a2e2270fSchristos    (dnmi (.sym name "ds0") "store w 0 disp"
1749a2e2270fSchristos	  (SHORT-INSN IMM3)
1750a2e2270fSchristos	  (.str name " $rd,[$rn]")
1751a2e2270fSchristos	  (emit (.sym name "d16") rd rn (disp3 0))
1752a2e2270fSchristos	  )
1753a2e2270fSchristos
1754a2e2270fSchristos    (dnmi (.sym name "dl0")  "store w 0 disp"
1755a2e2270fSchristos	  ()
1756a2e2270fSchristos	  (.str name " $rd6,[$rn6]")
1757a2e2270fSchristos	  (emit (.sym name "d") rd6 rn6 (dpmi 0) (disp11 0))
1758a2e2270fSchristos	  )
1759a2e2270fSchristos
1760a2e2270fSchristos    (dnmi (.sym name "dl0.l")  "store w 0 disp"
1761a2e2270fSchristos	  (NO-DIS)
1762a2e2270fSchristos	  (.str name ".l $rd6,[$rn6]")
1763a2e2270fSchristos	  (emit (.sym name "d") rd6 rn6 (dpmi 0) (disp11 0))
1764a2e2270fSchristos	  )
1765a2e2270fSchristos
1766a2e2270fSchristos
1767a2e2270fSchristos
1768a2e2270fSchristos    )
1769a2e2270fSchristos  )
1770a2e2270fSchristos
1771a2e2270fSchristos(store-insn strb QI OPW_BYTE store-to-ea)
1772a2e2270fSchristos(store-insn strh HI OPW_SHORT store-to-ea)
1773a2e2270fSchristos(store-insn str  SI OPW_WORD store-to-ea)
1774a2e2270fSchristos(store-insn strd DI OPW_DOUBLE store-double-to-ea)
1775a2e2270fSchristos
1776a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1777a2e2270fSchristos;; MOV<COND> RD,RN
1778a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1779a2e2270fSchristos
1780a2e2270fSchristos(define-pmacro (move-insns name cond g-op)
1781a2e2270fSchristos  (begin
1782a2e2270fSchristos    (dni_wrapper (.sym "cmov16" cond)
1783a2e2270fSchristos		 (.str "move register " cond)
1784a2e2270fSchristos		 (SHORT-INSN)
1785a2e2270fSchristos		 (.str "mov" name " $rd,$rn")
1786a2e2270fSchristos		 (+ OP4_FLOW16 (.sym "OPC_" cond) (f-opc-8-1 #x0) (f-dc-9-1 #x0) rd rn)
1787a2e2270fSchristos		 (if (g-op)
1788a2e2270fSchristos		     (set rd rn))
1789a2e2270fSchristos		 ()
1790a2e2270fSchristos		 )
1791a2e2270fSchristos
1792a2e2270fSchristos    (dni_wrapper (.sym "cmov" cond)
1793a2e2270fSchristos		 (.str "move register " cond)
1794a2e2270fSchristos		 ()
1795a2e2270fSchristos		 (.str "mov" name " $rd6,$rn6")
1796a2e2270fSchristos		 (+ OP4_MISC (.sym "OPC_" cond) (f-opc-8-1 #x0) (f-dc-9-1 #x0) (f-opc-19-4 #x2) (f-dc-25-6 #x0) rd6 rn6)
1797a2e2270fSchristos		 (if (g-op)
1798a2e2270fSchristos		     (set rd6 rn6))
1799a2e2270fSchristos		 ()
1800a2e2270fSchristos		 )
1801a2e2270fSchristos    (dnmi (.sym "cmov.l" cond)
1802a2e2270fSchristos	  (.str "move register " cond)
1803a2e2270fSchristos	  (NO-DIS)
1804a2e2270fSchristos	  (.str "mov" name ".l $rd6,$rn6")
1805a2e2270fSchristos	  (emit (.sym "cmov" cond) rd6 rn6)
1806a2e2270fSchristos	  )
1807a2e2270fSchristos
1808a2e2270fSchristos
1809a2e2270fSchristos
1810a2e2270fSchristos    )
1811a2e2270fSchristos  )
1812a2e2270fSchristos
1813a2e2270fSchristos					; basic conditional moves
1814a2e2270fSchristos(move-insns "eq"    EQ	   (.pmacro () (eq zbit #x1)))
1815a2e2270fSchristos(move-insns "ne"    NE	   (.pmacro () (eq zbit #x0)))
1816a2e2270fSchristos(move-insns "gtu"   GTU	   (.pmacro () (and BI cbit (not BI zbit))))
1817a2e2270fSchristos(move-insns "gteu"  GTEU   (.pmacro () (eq cbit #x1)))
1818a2e2270fSchristos(move-insns "lteu"  LTEU   (.pmacro () (or BI (not BI cbit) zbit)))
1819a2e2270fSchristos(move-insns "ltu"   LTU	   (.pmacro () (eq cbit #x0)))
1820a2e2270fSchristos(move-insns "gt"    GT	   (.pmacro () (and BI (not BI zbit) (eq vbit nbit))))
1821a2e2270fSchristos(move-insns "gte"   GTE	   (.pmacro () (eq vbit nbit)))
1822a2e2270fSchristos(move-insns "lt"    LT	   (.pmacro () (xor BI vbit nbit)))
1823a2e2270fSchristos(move-insns "lte"   LTE	   (.pmacro () (or BI zbit (xor vbit nbit))))
1824a2e2270fSchristos
1825a2e2270fSchristos					; unconditional move
1826a2e2270fSchristos(move-insns ""      B      (.pmacro () #x1))
1827a2e2270fSchristos
1828a2e2270fSchristos
1829a2e2270fSchristos					; floating point condition codes (floating point instructions)
1830a2e2270fSchristos(move-insns "beq"   BEQ    (.pmacro () (or BI bzbit bzbit)))
1831a2e2270fSchristos(move-insns "bne"   BNE    (.pmacro () (not BI bzbit)))
1832a2e2270fSchristos(move-insns "blt"   BLT    (.pmacro () (and BI bnbit (not bzbit))))
1833a2e2270fSchristos(move-insns "blte"  BLTE   (.pmacro () (or BI bnbit bzbit)))
1834a2e2270fSchristos
1835a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1836a2e2270fSchristos;; MOVTS RD,RN
1837a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1838a2e2270fSchristos
1839a2e2270fSchristos;; 16 bits form exists for group zero ( M1 and M0 equals to zero ) only
1840a2e2270fSchristos
1841a2e2270fSchristos(dni_wrapper movts16
1842a2e2270fSchristos	     "move to special reg"
1843a2e2270fSchristos	     (SHORT-INSN)
1844a2e2270fSchristos	     "movts $sn,$rd"
1845a2e2270fSchristos	     (+ OP4_FLOW16 (f-opc-8-5 #x10) (f-dc-9-1 #x0) rd sn) ;; rd is source for movts
1846a2e2270fSchristos	     (set sn rd)
1847a2e2270fSchristos	     ()
1848a2e2270fSchristos	     )
1849a2e2270fSchristos
1850a2e2270fSchristos(define-pmacro (op-mmr-movts name sdreg code)
1851a2e2270fSchristos  (begin
1852a2e2270fSchristos
1853a2e2270fSchristos    (dni_wrapper (.sym "movts" name)
1854a2e2270fSchristos		 (.str "move to " name)
1855a2e2270fSchristos		 ()
1856a2e2270fSchristos		 (.str "movts $" sdreg ",$rd6")
1857a2e2270fSchristos		 (+ OP4_MISC (f-dc-7-4 #x0) (f-opc-8-1 #x1) (f-dc-9-1 #x0) (f-opc-19-4 #x2) (f-dc-25-4 #x0) (f-dc-21-2 code) sdreg rd6);; rd is source for movts
1858a2e2270fSchristos		 (set sdreg rd6)
1859a2e2270fSchristos		 ()
1860a2e2270fSchristos		 )
1861a2e2270fSchristos
1862a2e2270fSchristos    (dnmi (.sym "movts.l" name)
1863a2e2270fSchristos	  (.str "move to " name)
1864a2e2270fSchristos	  (NO-DIS)
1865a2e2270fSchristos	  (.str "movts.l $" sdreg ",$rd6")
1866a2e2270fSchristos	  (emit (.sym "movts" name) sdreg rd6)
1867a2e2270fSchristos	  )
1868a2e2270fSchristos
1869a2e2270fSchristos
1870a2e2270fSchristos
1871a2e2270fSchristos
1872a2e2270fSchristos    )
1873a2e2270fSchristos  )
1874a2e2270fSchristos
1875a2e2270fSchristos(op-mmr-movts  6    sn6    #x0)
1876a2e2270fSchristos(op-mmr-movts  dma  sndma  #x1)
1877a2e2270fSchristos(op-mmr-movts  mem  snmem  #x2)
1878a2e2270fSchristos(op-mmr-movts  mesh snmesh #x3)
1879a2e2270fSchristos
1880a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1881a2e2270fSchristos;; MOVFS
1882a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1883a2e2270fSchristos(dni_wrapper movfs16
1884a2e2270fSchristos	     "move from special register"
1885a2e2270fSchristos	     (SHORT-INSN)
1886a2e2270fSchristos	     "movfs $rd,$sn"
1887a2e2270fSchristos	     (+ OP4_FLOW16 (f-opc-8-5 #x11) (f-dc-9-1 #x0) rd sn)
1888a2e2270fSchristos	     (set rd sn)
1889a2e2270fSchristos	     ()
1890a2e2270fSchristos	     )
1891a2e2270fSchristos
1892a2e2270fSchristos
1893a2e2270fSchristos
1894a2e2270fSchristos(define-pmacro (op-mmr-movfs name snreg code)
1895a2e2270fSchristos  (begin
1896a2e2270fSchristos
1897a2e2270fSchristos    (dni_wrapper (.sym "movfs" name)
1898a2e2270fSchristos		 (.str "move from " name)
1899a2e2270fSchristos		 ()
1900a2e2270fSchristos		 (.str "movfs $rd6,$" snreg)
1901a2e2270fSchristos		 (+ OP4_MISC (f-dc-7-4 #x1) (f-opc-8-1 #x1) (f-dc-9-1 #x0) (f-opc-19-4 #x2) (f-dc-25-4 #x0) (f-dc-21-2 code) rd6 snreg)
1902a2e2270fSchristos		 (set rd6 snreg)
1903a2e2270fSchristos		 ()
1904a2e2270fSchristos		 )
1905a2e2270fSchristos
1906a2e2270fSchristos    (dnmi (.sym "movfs.l" name)
1907a2e2270fSchristos	  (.str "move from " name)
1908a2e2270fSchristos	  (NO-DIS)
1909a2e2270fSchristos	  (.str "movfs.l $rd6,$" snreg)
1910a2e2270fSchristos	  (emit (.sym "movfs" name) rd6 snreg)
1911a2e2270fSchristos	  )
1912a2e2270fSchristos
1913a2e2270fSchristos
1914a2e2270fSchristos
1915a2e2270fSchristos    )
1916a2e2270fSchristos  )
1917a2e2270fSchristos
1918a2e2270fSchristos(op-mmr-movfs  6    sn6    #x0)
1919a2e2270fSchristos(op-mmr-movfs  dma  sndma  #x1)
1920a2e2270fSchristos(op-mmr-movfs  mem  snmem  #x2)
1921a2e2270fSchristos(op-mmr-movfs  mesh snmesh #x3)
1922a2e2270fSchristos
1923a2e2270fSchristos
1924a2e2270fSchristos
1925a2e2270fSchristos
1926a2e2270fSchristos
1927a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1928a2e2270fSchristos;; NOP 0x1a2
1929a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1930a2e2270fSchristos(dni_wrapper nop
1931a2e2270fSchristos	     "no-operation"
1932a2e2270fSchristos	     (SHORT-INSN)
1933a2e2270fSchristos	     "nop"
1934a2e2270fSchristos	     (+ OP4_FLOW16 (f-opc-8-5 #x1a) (f-dc-15-7 #x0))
1935a2e2270fSchristos	     (nop)
1936a2e2270fSchristos	     ()
1937a2e2270fSchristos	     )
1938a2e2270fSchristos
1939a2e2270fSchristos
1940a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1941a2e2270fSchristos;; SNOP 0x3a2
1942a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1943a2e2270fSchristos(dni_wrapper snop
1944a2e2270fSchristos	     "no-operation"
1945a2e2270fSchristos	     (SHORT-INSN)
1946a2e2270fSchristos	     "snop"
1947a2e2270fSchristos	     (+ OP4_FLOW16 (f-opc-8-5 #x3a) (f-dc-15-7 #x0))
1948a2e2270fSchristos	     (nop)
1949a2e2270fSchristos	     ()
1950a2e2270fSchristos	     )
1951a2e2270fSchristos
1952a2e2270fSchristos
1953a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1954a2e2270fSchristos;; UNIMPL
1955a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1956a2e2270fSchristos(dni_wrapper unimpl
1957a2e2270fSchristos	     "not-implemented"
1958a2e2270fSchristos	     ()
1959a2e2270fSchristos	     "unimpl"
1960a2e2270fSchristos	     (+ (f-opc-31-32  #x000F000F))
1961a2e2270fSchristos	     (nop)
1962a2e2270fSchristos	     ()
1963a2e2270fSchristos	     )
1964a2e2270fSchristos
1965a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1966a2e2270fSchristos;; IDLE
1967a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1968a2e2270fSchristos
1969a2e2270fSchristos(dni idle "idle until interrupt" () "idle"
1970a2e2270fSchristos     (+ OP4_FLOW16 (f-opc-8-5 #x1b) (f-dc-15-7 #x0))
1971a2e2270fSchristos     ;;     (set pc pc)	;; should branch to self until interrupt, but not modeling interrupts
1972a2e2270fSchristos     (sequence ()
1973a2e2270fSchristos       (set caibit 0)
1974a2e2270fSchristos       (c-code "sim_engine_halt (CPU_STATE (current_cpu), current_cpu, NULL, \
1975a2e2270fSchristos		pc, sim_exited, 0);"))
1976a2e2270fSchristos     ()
1977a2e2270fSchristos     )
1978a2e2270fSchristos
1979a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1980a2e2270fSchristos;; BKPT
1981a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1982a2e2270fSchristos
1983a2e2270fSchristos(dni bkpt
1984a2e2270fSchristos     "breakpoint"
1985a2e2270fSchristos     (SHORT-INSN)
1986a2e2270fSchristos     "bkpt"
1987a2e2270fSchristos     (+ OP4_FLOW16 (f-opc-8-5 #x1c) (f-dc-15-7 #x0))
1988a2e2270fSchristos     (sequence ()
1989a2e2270fSchristos     	 (c-call  "epiphany_break" pc)
1990a2e2270fSchristos     	(set pc pc)
1991a2e2270fSchristos     	)
1992a2e2270fSchristos     ()
1993a2e2270fSchristos     )
1994a2e2270fSchristos
1995a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1996a2e2270fSchristos;; MBKPT
1997a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1998a2e2270fSchristos
1999a2e2270fSchristos(dni mbkpt
2000a2e2270fSchristos     "multicorebreakpoint"
2001a2e2270fSchristos     (SHORT-INSN)
2002a2e2270fSchristos     "mbkpt"
2003a2e2270fSchristos     (+ OP4_FLOW16 (f-opc-8-5 #x1c) (f-dc-15-7 #x1))
2004a2e2270fSchristos     ;;;(c-call "epiphany_break" pc)
2005a2e2270fSchristos     (nop) ;; ignore the multi core break point in the simulator
2006a2e2270fSchristos     ()
2007a2e2270fSchristos     )
2008a2e2270fSchristos
2009a2e2270fSchristos;;;;;;;;;;;;;;;;
2010a2e2270fSchristos;; RTI
2011a2e2270fSchristos;;;;;;;;;;;;;;;;
2012a2e2270fSchristos
2013a2e2270fSchristos(dni rti "return from interrupt" (SHORT-INSN UNCOND-CTI)
2014a2e2270fSchristos     "rti"
2015a2e2270fSchristos     (+ OP4_FLOW16 (f-opc-8-5 #x1d) (f-dc-15-7 #x0))
2016a2e2270fSchristos     (sequence ()
2017a2e2270fSchristos	       ;; 	(set (hcr-ipend)
2018a2e2270fSchristos	       ;; 	     (xor (hcr-ipend)
2019a2e2270fSchristos	       ;; 		  (sll (const 1)
2020a2e2270fSchristos	       ;; 		       (sub (c-raw-call SI "ffs" (and (hcr-ipend) (not (hcr-imask))))
2021a2e2270fSchristos	       ;; 			    (const 1)))))
2022a2e2270fSchristos
2023a2e2270fSchristos	       (set (hcr-ipend)
2024a2e2270fSchristos		    (c-call SI "epiphany_rti" (hcr-ipend) (hcr-imask)))
2025a2e2270fSchristos	       (set gidisablebit 0)
2026a2e2270fSchristos	       (set kmbit 0)
2027a2e2270fSchristos					;(set caibit 1)
2028a2e2270fSchristos	       (set pc (hcr-iret)))
2029a2e2270fSchristos     ()
2030a2e2270fSchristos     )
2031a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2032a2e2270fSchristos;; WAND is a wired flag that runs around the chip
2033a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2034a2e2270fSchristos(dni_wrapper wand     "wand"
2035a2e2270fSchristos	     (SHORT-INSN)
2036a2e2270fSchristos	     "wand"
2037a2e2270fSchristos	     (+ OP4_FLOW16 (f-opc-8-5 #x18) (f-dc-15-7 #x0))
2038a2e2270fSchristos	     (set sflagbit 1)
2039a2e2270fSchristos	     ()
2040a2e2270fSchristos	     )
2041a2e2270fSchristos
2042a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2043a2e2270fSchristos;; Sync likes wand, but wired OR
2044a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2045a2e2270fSchristos(dni_wrapper sync     "sync"
2046a2e2270fSchristos	     (SHORT-INSN)
2047a2e2270fSchristos	     "sync"
2048a2e2270fSchristos	     (+ OP4_FLOW16 (f-opc-8-5 #x1f) (f-dc-15-7 #x0))
2049a2e2270fSchristos	     (nop);;TODO
2050a2e2270fSchristos	     ()
2051a2e2270fSchristos	     )
2052a2e2270fSchristos
2053a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2054a2e2270fSchristos;; GIE
2055a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2056a2e2270fSchristos(dni_wrapper gien     "global interrupt enable"
2057a2e2270fSchristos	     (SHORT-INSN)
2058a2e2270fSchristos	     "gie"
2059a2e2270fSchristos	     (+ OP4_FLOW16 (f-gien-gidis-9-1 #x0) (f-opc-8-5 #x19) (f-dc-15-6 #x0))
2060a2e2270fSchristos	     (set gidisablebit 0)
2061a2e2270fSchristos	     ()
2062a2e2270fSchristos	     )
2063a2e2270fSchristos
2064a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2065a2e2270fSchristos;; GIDIS
2066a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2067a2e2270fSchristos(dni_wrapper gidis     "global interrupt disable"
2068a2e2270fSchristos	     (SHORT-INSN)
2069a2e2270fSchristos	     "gid"
2070a2e2270fSchristos	     (+ OP4_FLOW16 (f-gien-gidis-9-1 #x1) (f-opc-8-5 #x19) (f-dc-15-6 #x0))
2071a2e2270fSchristos	     (set gidisablebit 1)
2072a2e2270fSchristos	     ()
2073a2e2270fSchristos	     )
2074a2e2270fSchristos
2075a2e2270fSchristos
2076a2e2270fSchristos
2077a2e2270fSchristos;;;;;;;;;;;;;;;;
2078a2e2270fSchristos;; SWI
2079a2e2270fSchristos;;;;;;;;;;;;;;;;
2080a2e2270fSchristos
2081a2e2270fSchristos;; Model only immediate 'fire' exception, if gien cleared or masked don't fire and don't check later - no ilat like behavior
2082a2e2270fSchristos(dni swi_num "software interrupt" (SHORT-INSN UNCOND-CTI)
2083a2e2270fSchristos     "swi $swi_num"
2084a2e2270fSchristos     (+ OP4_FLOW16 (f-opc-8-5 #x1e) (f-trap-swi-9-1 #x0)  swi_num)
2085a2e2270fSchristos     (sequence ()  (call-exception #x24  #x80))
2086a2e2270fSchristos     ;;      (if (eq gie 1)
2087a2e2270fSchristos     ;; 	 (sequence ()
2088a2e2270fSchristos     ;; 		   (set kmbit 1)
2089a2e2270fSchristos     ;; 		   (set gie 0)
2090a2e2270fSchristos     ;; 		   (set (hcr-iret) (add pc (const 2)))
2091a2e2270fSchristos     ;; 		   (set (hcr-ipend) (or (hcr-ipend) (const #x80)))
2092a2e2270fSchristos     ;; 		   (set pc (const #x1c))
2093a2e2270fSchristos
2094a2e2270fSchristos     ;; 			   )
2095a2e2270fSchristos     ;; 	 ;; schedule interrupt
2096a2e2270fSchristos     ;; 	 (set (hcr-ilat) (or (hcr-ilat) (const #x80)))
2097a2e2270fSchristos     ;; 	 )
2098a2e2270fSchristos     ()
2099a2e2270fSchristos     )
2100a2e2270fSchristos(dni swi "software interrupt" (ALIAS SHORT-INSN UNCOND-CTI)
2101a2e2270fSchristos     "swi"
2102a2e2270fSchristos     (+ OP4_FLOW16 (f-opc-8-5 #x1e) (f-trap-swi-9-1 #x0) (f-dc-15-6 #x0))
2103a2e2270fSchristos     (sequence ()  (call-exception #x24  #x80))
2104a2e2270fSchristos     ()
2105a2e2270fSchristos     )
2106a2e2270fSchristos
2107a2e2270fSchristos
2108a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2109a2e2270fSchristos;; TRAP #disp3 - simulator only and chip as well - make the same grouop as swi
2110a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2111a2e2270fSchristos
2112a2e2270fSchristos;; Only defining 16-bit form of this instruction.  It exists to support the
2113a2e2270fSchristos;; simulator, by giving us a simple input/output mechanism beyond returning values
2114a2e2270fSchristos;; in registers or memory.
2115a2e2270fSchristos;; TRAP #N  - special sw trap for simulator support;  allows simple i/o using fixed arguments
2116a2e2270fSchristos;; TRAP #0  - write (r0=i/o channel, r1=addr, r2=len) returns status in r0
2117a2e2270fSchristos;; TRAP #1  - read  (r0=i/o channel, r1=addr, r2=len) returns length or -<code> on error
2118a2e2270fSchristos;; TRAP #2  - open  (r0=string path, r1=mode) returns channel# or -<code> on error
2119a2e2270fSchristos;; TRAP #3  - exit  (r0=status code) never returns.
2120a2e2270fSchristos;; TRAP #4  - print "pass\n" and exit
2121a2e2270fSchristos;; TRAP #5  - print "fail\n" and exit
2122a2e2270fSchristos;; TRAP #6  - close  (r0=i/o channel)
2123a2e2270fSchristos
2124a2e2270fSchristos(dni trap16 "trap to simulator"
2125a2e2270fSchristos     (SHORT-INSN UNCOND-CTI)
2126a2e2270fSchristos     "trap $trapnum6"
2127a2e2270fSchristos     (+ OP4_FLOW16 (f-opc-8-5 #x1e) (f-trap-swi-9-1 #x1)  trapnum6) ;;  (+ OP4_IMM16 OPI_TRAP (f-rd 0) (f-rn 0) disp3)
2128a2e2270fSchristos     (set (reg SI h-registers 0) (c-call SI "epiphany_trap" pc trapnum6))
2129a2e2270fSchristos     ()
2130a2e2270fSchristos     )
2131a2e2270fSchristos
2132a2e2270fSchristos
2133a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2134a2e2270fSchristos;; Integer arithmetic instructions 3 address forms
2135a2e2270fSchristos;;   both 16 and 32 bit forms
2136a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2137a2e2270fSchristos
2138a2e2270fSchristos(define-pmacro (op-rrr name sem-op cond-op)
2139a2e2270fSchristos  (begin
2140a2e2270fSchristos    (dni_wrapper (.sym name "16")
2141a2e2270fSchristos		 (.str name)
2142a2e2270fSchristos		 (SHORT-INSN)
2143a2e2270fSchristos		 (.str name " $rd,$rn,$rm")
2144a2e2270fSchristos		 (+ OP4_ALU16 (.sym "OPB_" (.upcase (.str name))) rd rn rm)
2145a2e2270fSchristos		 (sequence ()
2146a2e2270fSchristos			   (cond-op rn rm)
2147a2e2270fSchristos			   (set rd (sem-op SI rn rm))
2148a2e2270fSchristos			   (set zbit (zflag rd))
2149a2e2270fSchristos			   (set nbit (nflag rd))
2150a2e2270fSchristos			   )
2151a2e2270fSchristos		 ()
2152a2e2270fSchristos		 )
2153a2e2270fSchristos
2154a2e2270fSchristos    (dni_wrapper (.sym name)
2155a2e2270fSchristos		 (.str name)
2156a2e2270fSchristos		 ()
2157a2e2270fSchristos		 (.str name " $rd6,$rn6,$rm6")
2158a2e2270fSchristos		 (+ OP4_MISC (.sym "OPB_" (.upcase (.str name))) (f-opc-19-4 #xa) (f-dc-22-3 #x0) rd6 rn6 rm6)
2159a2e2270fSchristos		 (sequence ()
2160a2e2270fSchristos			   (cond-op rn6 rm6)
2161a2e2270fSchristos			   (set rd6 (sem-op SI rn6 rm6))
2162a2e2270fSchristos			   (set zbit (zflag rd6))
2163a2e2270fSchristos			   (set nbit (nflag rd6))
2164a2e2270fSchristos			   )
2165a2e2270fSchristos		 ()
2166a2e2270fSchristos		 )
2167a2e2270fSchristos
2168a2e2270fSchristos    (dnmi (.sym name ".l")
2169a2e2270fSchristos	  (.str name)
2170a2e2270fSchristos	  (NO-DIS)
2171a2e2270fSchristos	  (.str name ".l $rd6,$rn6,$rm6")
2172a2e2270fSchristos	  (emit (.sym name) rd6 rn6 rm6)
2173a2e2270fSchristos	  )
2174a2e2270fSchristos
2175a2e2270fSchristos
2176a2e2270fSchristos
2177a2e2270fSchristos    )
2178a2e2270fSchristos  )
2179a2e2270fSchristos
2180a2e2270fSchristos;; submacros to set condition codes
2181a2e2270fSchristos;;  NZ are always set to reflect the sign and value of the result
2182a2e2270fSchristos;;  CV are a function of the operator
2183a2e2270fSchristos(define-pmacro (add-vc a b) (sequence ()
2184a2e2270fSchristos				      (set cbit (add-cflag SI a b 0))
2185a2e2270fSchristos				      (set vbit (add-oflag SI a b 0))
2186a2e2270fSchristos				      (set vsbit (or BI vsbit vbit))
2187a2e2270fSchristos				      ))
2188a2e2270fSchristos
2189a2e2270fSchristos(define-pmacro (sub-vc a b) (sequence ()
2190a2e2270fSchristos				      (set cbit (not (sub-cflag SI a b 0)))
2191a2e2270fSchristos				      (set vbit (sub-oflag SI a b 0))
2192a2e2270fSchristos				      (set vsbit (or vsbit vbit))
2193a2e2270fSchristos				      ))
2194a2e2270fSchristos
2195a2e2270fSchristos(define-pmacro (logic-vc a b) (sequence ()
2196a2e2270fSchristos					(set cbit 0)
2197a2e2270fSchristos					(set vbit 0)
2198a2e2270fSchristos					))
2199a2e2270fSchristos
2200a2e2270fSchristos(op-rrr add add add-vc)
2201a2e2270fSchristos(op-rrr sub sub sub-vc)
2202a2e2270fSchristos(op-rrr and and logic-vc)
2203a2e2270fSchristos(op-rrr orr  or  logic-vc)
2204a2e2270fSchristos(op-rrr eor xor logic-vc)
2205a2e2270fSchristos
2206a2e2270fSchristos;; Integer arithmetic immediate forms
2207a2e2270fSchristos
2208a2e2270fSchristos(define-pmacro (op-rri name code cond-op)
2209a2e2270fSchristos  (begin
2210a2e2270fSchristos    (dni_wrapper (.sym name "i16")
2211a2e2270fSchristos		 (.str name)
2212a2e2270fSchristos		 (SHORT-INSN IMM3)
2213a2e2270fSchristos		 (.str name ".s $rd,$rn,$simm3")
2214a2e2270fSchristos		 (+ OP4_IMM16 code rd rn simm3)
2215a2e2270fSchristos		 (sequence ()
2216a2e2270fSchristos			   (cond-op rn simm3)
2217a2e2270fSchristos			   (set rd (name SI rn simm3))
2218a2e2270fSchristos			   (set zbit (zflag rd))
2219a2e2270fSchristos			   (set nbit (nflag rd))
2220a2e2270fSchristos			   )
2221a2e2270fSchristos		 ()
2222a2e2270fSchristos		 )
2223a2e2270fSchristos
2224a2e2270fSchristos
2225a2e2270fSchristos    (dni_wrapper (.sym name "i")
2226a2e2270fSchristos		 (.str name)
2227a2e2270fSchristos		 ()
2228a2e2270fSchristos		 (.str name ".l $rd6,$rn6,$simm11")
2229a2e2270fSchristos		 (+ OP4_IMM32 code OPI_25_2_MBZ rd6 rn6 simm11)
2230a2e2270fSchristos		 (sequence ()
2231a2e2270fSchristos			   (cond-op rn6 simm11)
2232a2e2270fSchristos			   (set rd6 (name SI rn6 simm11))
2233a2e2270fSchristos			   (set zbit (zflag rd6))
2234a2e2270fSchristos			   (set nbit (nflag rd6))
2235a2e2270fSchristos			   )
2236a2e2270fSchristos		 ()
2237a2e2270fSchristos		 )
2238a2e2270fSchristos
2239a2e2270fSchristos    ;;    (dnmi (.sym name "ri") "relaxed arithmetic immediate" (RELAXED)
2240a2e2270fSchristos    ;;	  (.str name " $rd6,$rn6,$simm11")
2241a2e2270fSchristos    ;;	  (emit (.sym name "i") rd6 rn6 simm11))
2242a2e2270fSchristos    )
2243a2e2270fSchristos  )
2244a2e2270fSchristos
2245a2e2270fSchristos(op-rri add OPI_ADD add-vc)
2246a2e2270fSchristos(op-rri sub OPI_SUB sub-vc)
2247a2e2270fSchristos
2248a2e2270fSchristos(dnmi addir "relaxable short immediate add" (RELAXABLE IMM3)
2249a2e2270fSchristos      "add $rd,$rn,$simm3"
2250a2e2270fSchristos      (emit addi16 rd rn simm3))
2251a2e2270fSchristos
2252a2e2270fSchristos(dnmi addi32r "relaxed long immediate add" (RELAXED)
2253a2e2270fSchristos      "add $rd6,$rn6,$simm11"
2254a2e2270fSchristos      (emit addi rd6 rn6 simm11))
2255a2e2270fSchristos
2256a2e2270fSchristos;; Again, but not relaxable so that full sized registers are handled
2257a2e2270fSchristos(dnmi addi32m "relaxed long immediate add" ()
2258a2e2270fSchristos      "add $rd6,$rn6,$simm11"
2259a2e2270fSchristos      (emit addi rd6 rn6 simm11))
2260a2e2270fSchristos
2261a2e2270fSchristos
2262a2e2270fSchristos(dnmi subir "relaxable short immediate sub" (RELAXABLE IMM3)
2263a2e2270fSchristos      "sub $rd,$rn,$simm3"
2264a2e2270fSchristos      (emit subi16 rd rn simm3))
2265a2e2270fSchristos
2266a2e2270fSchristos(dnmi subi32r "relaxed long immediate sub" (RELAXED)
2267a2e2270fSchristos      "sub $rd6,$rn6,$simm11"
2268a2e2270fSchristos      (emit subi rd6 rn6 simm11))
2269a2e2270fSchristos
2270a2e2270fSchristos(dnmi subi32m "relaxed long immediate sub" ()
2271a2e2270fSchristos      "sub $rd6,$rn6,$simm11"
2272a2e2270fSchristos      (emit subi rd6 rn6 simm11))
2273a2e2270fSchristos
2274a2e2270fSchristos
2275a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2276a2e2270fSchristos;; Shift instructions 3 address forms
2277a2e2270fSchristos;;   both 16 and 32 bit forms
2278a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2279a2e2270fSchristos
2280a2e2270fSchristos(define-pmacro (shift-rrr name sem-op)
2281a2e2270fSchristos  (begin
2282a2e2270fSchristos    (dni_wrapper (.sym name "16")
2283a2e2270fSchristos		 (.str name)
2284a2e2270fSchristos		 (SHORT-INSN)
2285a2e2270fSchristos		 (.str name " $rd,$rn,$rm")
2286a2e2270fSchristos		 (+ OP4_ALU16 (.sym "OPB_" (.upcase (.str name))) rd rn rm)
2287a2e2270fSchristos		 (sequence ()
2288a2e2270fSchristos			   (logic-vc rn rm)
2289a2e2270fSchristos			   (set rd (sem-op SI rn (and rm (const 31))))
2290a2e2270fSchristos			   (set zbit (zflag rd))
2291a2e2270fSchristos			   (set nbit (nflag rd))
2292a2e2270fSchristos			   )
2293a2e2270fSchristos		 ()
2294a2e2270fSchristos		 )
2295a2e2270fSchristos
2296a2e2270fSchristos    (dni_wrapper (.sym name)
2297a2e2270fSchristos		 (.str name)
2298a2e2270fSchristos		 ()
2299a2e2270fSchristos		 (.str name " $rd6,$rn6,$rm6")
2300a2e2270fSchristos		 (+ OP4_MISC (.sym "OPB_" (.upcase (.str name))) (f-opc-19-4 #xa) (f-dc-22-3 #x0) rd6 rn6 rm6)
2301a2e2270fSchristos		 (sequence ()
2302a2e2270fSchristos			   (logic-vc rn6 rm6)
2303a2e2270fSchristos			   (set rd6 (sem-op SI rn6 (and rm6 (const 31))))
2304a2e2270fSchristos			   (set zbit (zflag rd6))
2305a2e2270fSchristos			   (set nbit (nflag rd6))
2306a2e2270fSchristos			   )
2307a2e2270fSchristos		 ()
2308a2e2270fSchristos		 )
2309a2e2270fSchristos
2310a2e2270fSchristos    (dnmi (.sym name ".l")
2311a2e2270fSchristos	  (.str name)
2312a2e2270fSchristos	  (NO-DIS)
2313a2e2270fSchristos	  (.str name ".l $rd6,$rn6,$rm6")
2314a2e2270fSchristos	  (emit (.sym name) rd6 rn6 rm6)
2315a2e2270fSchristos	  )
2316a2e2270fSchristos    )
2317a2e2270fSchristos  )
2318a2e2270fSchristos
2319a2e2270fSchristos(shift-rrr asr sra)
2320a2e2270fSchristos(shift-rrr lsr srl)
2321a2e2270fSchristos(shift-rrr lsl sll)
2322a2e2270fSchristos
2323a2e2270fSchristos(define-pmacro (op-shift-rri name shortcode f5 longcode sem-op)
2324a2e2270fSchristos  (begin
2325a2e2270fSchristos    (dni_wrapper (.sym name "i16")
2326a2e2270fSchristos		 (.str name)
2327a2e2270fSchristos		 (SHORT-INSN)
2328a2e2270fSchristos		 (.str name " $rd,$rn,$shift")
2329a2e2270fSchristos		 (+ shortcode (f-opc-4-1 f5) rd rn shift)
2330a2e2270fSchristos		 (sequence ()
2331a2e2270fSchristos			   (logic-vc rn shift)
2332a2e2270fSchristos			   (set rd (sem-op SI rn shift))
2333a2e2270fSchristos			   (set zbit (zflag rd))
2334a2e2270fSchristos			   (set nbit (nflag rd))
2335a2e2270fSchristos			   )
2336a2e2270fSchristos		 ()
2337a2e2270fSchristos		 )
2338a2e2270fSchristos    (dni_wrapper (.sym name "i32")
2339a2e2270fSchristos		 (.str name)
2340a2e2270fSchristos		 ()
2341a2e2270fSchristos		 (.str name " $rd6,$rn6,$shift")
2342a2e2270fSchristos		 (+ OP4_MISC (f-opc-4-1 f5) (f-opc-19-4 longcode) (f-dc-25-6 0) rd6 rn6 shift)
2343a2e2270fSchristos		 (sequence ()
2344a2e2270fSchristos			   (logic-vc rn6 shift)
2345a2e2270fSchristos			   (set rd6 (sem-op SI rn6 shift))
2346a2e2270fSchristos			   (set zbit (zflag rd6))
2347a2e2270fSchristos			   (set nbit (nflag rd6))
2348a2e2270fSchristos			   )
2349a2e2270fSchristos		 ()
2350a2e2270fSchristos		 )
2351a2e2270fSchristos
2352a2e2270fSchristos    (dnmi (.sym name "i32.l")
2353a2e2270fSchristos	  (.str name)
2354a2e2270fSchristos	  (NO-DIS)
2355a2e2270fSchristos	  (.str name ".l $rd6,$rn6,$shift")
2356a2e2270fSchristos	  (emit (.sym name "i32") rd6  rn6 shift)
2357a2e2270fSchristos	  )
2358a2e2270fSchristos
2359a2e2270fSchristos
2360a2e2270fSchristos    )
2361a2e2270fSchristos  )
2362a2e2270fSchristos
2363a2e2270fSchristos(op-shift-rri lsr OP4_LSHIFT16 0 #x6 srl)
2364a2e2270fSchristos(op-shift-rri lsl OP4_LSHIFT16 1 #x6 sll)
2365a2e2270fSchristos(op-shift-rri asr OP4_ASHIFT16 0 #xe sra)
2366a2e2270fSchristos
2367a2e2270fSchristos;; BITR - bitreversal (FFT)
2368a2e2270fSchristos;;
2369a2e2270fSchristos;; From Dr Dobbs et al.
2370a2e2270fSchristos;;
2371a2e2270fSchristos;; unsigned int v;
2372a2e2270fSchristos;; v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1);  ;; swap odd-even bits
2373a2e2270fSchristos;; v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2);  ;; swap pairs
2374a2e2270fSchristos;; v = ((v >> 4) & 0x0f0f0f0f) | ((v & 0x0f0f0f0f) << 4);  ;; swap nibbles
2375a2e2270fSchristos;; v = ((v >> 8) & 0x00ff00ff) | ((v & 0x00ff00ff) << 8);  ;; swap bytes
2376a2e2270fSchristos;; v =  (v >> 16)              |  (v               << 16); ;; swap halves
2377a2e2270fSchristos(define-pmacro (bit-reversal dest src)
2378a2e2270fSchristos  (sequence ((SI v))
2379a2e2270fSchristos	    (set v src)
2380a2e2270fSchristos	    (set v (or (and (srl v 1) #x55555555) (sll (and v #x55555555) 1)))
2381a2e2270fSchristos	    (set v (or (and (srl v 2) #x33333333) (sll (and v #x33333333) 2)))
2382a2e2270fSchristos	    (set v (or (and (srl v 4) #x0f0f0f0f) (sll (and v #x0f0f0f0f) 4)))
2383a2e2270fSchristos	    (set v (or (and (srl v 8) #x00ff00ff) (sll (and v #x00ff00ff) 8)))
2384a2e2270fSchristos	    (set v (or      (srl v 16)            (sll      v            16)))
2385a2e2270fSchristos	    (set dest v)
2386a2e2270fSchristos	    ))
2387a2e2270fSchristos
2388a2e2270fSchristos(dni_wrapper bitr16 "bit reverse short"
2389a2e2270fSchristos	     (SHORT-INSN)
2390a2e2270fSchristos	     ("bitr $rd,$rn")
2391a2e2270fSchristos	     (+ OP4_ASHIFT16 (f-opc-4-1 1) rd rn (f-shift 0))
2392a2e2270fSchristos	     (sequence ()
2393a2e2270fSchristos		       (bit-reversal rd rn)
2394a2e2270fSchristos		       (set zbit (zflag rd))
2395a2e2270fSchristos		       (set nbit (nflag rd))
2396a2e2270fSchristos		       (set cbit 0)
2397a2e2270fSchristos		       (set vbit 0)
2398a2e2270fSchristos		       )
2399a2e2270fSchristos	     ()
2400a2e2270fSchristos	     )
2401a2e2270fSchristos
2402a2e2270fSchristos(dni_wrapper bitr "bit reverse"
2403a2e2270fSchristos	     ()
2404a2e2270fSchristos	     ("bitr $rd6,$rn6")
2405a2e2270fSchristos	     (+ OP4_MISC (f-opc-4-1 1) (f-opc-19-4 #xe) (f-dc-25-6 0) rd6 rn6 (f-shift 0))
2406a2e2270fSchristos	     (sequence ()
2407a2e2270fSchristos		       (bit-reversal rd6 rn6)
2408a2e2270fSchristos		       (set zbit (zflag rd6))
2409a2e2270fSchristos		       (set nbit (nflag rd6))
2410a2e2270fSchristos		       (set cbit 0)
2411a2e2270fSchristos		       (set vbit 0)
2412a2e2270fSchristos		       )
2413a2e2270fSchristos	     ()
2414a2e2270fSchristos	     )
2415a2e2270fSchristos(dnmi bitrl "bit reverse l"
2416a2e2270fSchristos      (NO-DIS)
2417a2e2270fSchristos      ("bitr.l $rd6,$rn6")
2418a2e2270fSchristos      (emit bitr rd6 rn6)
2419a2e2270fSchristos      )
2420a2e2270fSchristos
2421a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2422a2e2270fSchristos;; Integer arithmetic instructions
2423a2e2270fSchristos;; Extended operation
2424a2e2270fSchristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2425a2e2270fSchristos
2426a2e2270fSchristos(define-pmacro (op-iextrrr  name  cond-op)
2427a2e2270fSchristos  (begin
2428a2e2270fSchristos
2429a2e2270fSchristos    (dni_wrapper (.sym name)
2430a2e2270fSchristos		 (.str name)
2431a2e2270fSchristos		 ()
2432a2e2270fSchristos		 (.str name " $rd6,$rn6,$rm6")
2433a2e2270fSchristos		 (+ OP4_MISC (.sym "OPBE_" (.upcase (.str name))) (f-opc-19-4 #xa) (f-dc-22-2 #x0)  (f-dc-20-1 #x1)
2434a2e2270fSchristos		    rd6 rn6 rm6)
2435a2e2270fSchristos		 (sequence ()
2436a2e2270fSchristos			   ;;  TODO cond operation (cond-op rn6 rm6)
2437a2e2270fSchristos			   ;;(set rd6 (sem-op SI rn6 rm6))
2438a2e2270fSchristos			   (set zbit (zflag rd6))
2439a2e2270fSchristos			   (set nbit (nflag rd6))
2440a2e2270fSchristos			   )
2441a2e2270fSchristos		 ()
2442a2e2270fSchristos		 )
2443a2e2270fSchristos
2444a2e2270fSchristos    (dnmi (.sym name ".l")
2445a2e2270fSchristos	  (.str name)
2446a2e2270fSchristos	  (NO-DIS)
2447a2e2270fSchristos	  (.str name ".l $rd6,$rn6,$rm6")
2448a2e2270fSchristos	  (emit (.sym name) rd6  rn6 rm6)
2449a2e2270fSchristos	  )
2450a2e2270fSchristos    )
2451a2e2270fSchristos  )
2452a2e2270fSchristos
2453a2e2270fSchristos(op-iextrrr fext  sub-vc)
2454a2e2270fSchristos(op-iextrrr fdep  sub-vc)
2455a2e2270fSchristos(op-iextrrr lfsr  sub-vc)
2456a2e2270fSchristos
2457a2e2270fSchristos
2458a2e2270fSchristos
2459a2e2270fSchristos;; Immediate moves.  The 8 bit form is relaxed if it doesn't fit or is external
2460a2e2270fSchristos;; Move RD,#IMM
2461a2e2270fSchristos(dni_wrapper mov8
2462a2e2270fSchristos	     "mov imm8"
2463a2e2270fSchristos	     (SHORT-INSN)
2464a2e2270fSchristos	     "mov.b $rd,$imm8"
2465a2e2270fSchristos	     (+ OP4_IMM16 (f-opc-4-1 #x0) rd imm8)
2466a2e2270fSchristos	     (set rd (zext SI imm8))
2467a2e2270fSchristos	     ()
2468a2e2270fSchristos	     )
2469a2e2270fSchristos
2470a2e2270fSchristos(dnmi mov8r "mov imm8 relaxable"
2471a2e2270fSchristos      (RELAXABLE)
2472a2e2270fSchristos      "mov $rd,$imm8"
2473a2e2270fSchristos      (emit mov8 rd imm8))
2474a2e2270fSchristos
2475a2e2270fSchristos(dni_wrapper mov16
2476a2e2270fSchristos	     "mov imm16"
2477a2e2270fSchristos	     ()
2478a2e2270fSchristos	     "mov.l $rd6,$imm16"
2479a2e2270fSchristos	     (+ OP4_IMM32 (f-opc-4-1 #x0) (f-opc-19-4 #x2) (f-dc-28-1 #x0) rd6 imm16)
2480a2e2270fSchristos	     (set rd6 (zext SI imm16))
2481a2e2270fSchristos	     ()
2482a2e2270fSchristos	     )
2483a2e2270fSchristos
2484a2e2270fSchristos(dnmi mov16r "mov imm16 relaxable"
2485a2e2270fSchristos      ()
2486a2e2270fSchristos      "mov $rd6,$imm16"
2487a2e2270fSchristos      (emit mov16 rd6 imm16))
2488a2e2270fSchristos
2489a2e2270fSchristos;; MOVE TO HIGH WORD
2490a2e2270fSchristos(dni_wrapper movt
2491a2e2270fSchristos	     "movt imm16"
2492a2e2270fSchristos	     ()
2493a2e2270fSchristos	     "movt $rd6,$imm16"
2494a2e2270fSchristos	     (+ OP4_IMM32 (f-opc-4-1 #x0) (f-opc-19-4 #x2) (f-dc-28-1 #x1) rd6 imm16)
2495a2e2270fSchristos	     (set rd6 (or (and SI rd6 (const #xffff)) ; keep low bits of rd
2496a2e2270fSchristos			  (sll SI imm16 (const 16)))) ; replacing just high bits
2497a2e2270fSchristos	     ()
2498a2e2270fSchristos	     )
2499a2e2270fSchristos(dnmi movtl
2500a2e2270fSchristos      "movt imm16"
2501a2e2270fSchristos      (NO-DIS)
2502a2e2270fSchristos      "movt.l $rd6,$imm16"
2503a2e2270fSchristos      (emit movt rd6 imm16)
2504a2e2270fSchristos      )
2505a2e2270fSchristos
2506a2e2270fSchristos
2507a2e2270fSchristos
2508a2e2270fSchristos;; FLOATING POINT OPERATIONS
2509a2e2270fSchristos;; TWO operands
2510a2e2270fSchristos(define-pmacro (op-two_operands-float name code)
2511a2e2270fSchristos  (begin
2512a2e2270fSchristos    (dni_wrapper
2513a2e2270fSchristos      (.sym "f_" name "f16")
2514a2e2270fSchristos      (.str "f_" name)
2515a2e2270fSchristos      (SHORT-INSN)
2516a2e2270fSchristos      (.str "f" name " $rd,$rn,$rm")
2517a2e2270fSchristos      (+ OP4_DSP16 code rd rn rm)
2518a2e2270fSchristos      (sequence ()
2519a2e2270fSchristos	(if
2520a2e2270fSchristos	  (eq  arithmetic-modebit2 0)
2521a2e2270fSchristos	  (sequence ((SF fptemp) (SI sdtmp))
2522a2e2270fSchristos	    (set sdtmp  (c-call SI (.str "epiphany_f" name) rd rn rm))
2523a2e2270fSchristos
2524a2e2270fSchristos	    ;;All bits are calculated in C
2525a2e2270fSchristos	    (set bzbit  (c-call BI "get_epiphany_fzeroflag" sdtmp))
2526a2e2270fSchristos	    (set bnbit  (c-call BI "get_epiphany_fnegativeflag" sdtmp))
2527a2e2270fSchristos	    (set bvbit  (c-call BI "get_epiphany_foverflowflag" sdtmp))
2528a2e2270fSchristos	    (set bubit  (c-call BI "get_epiphany_funderflowflag" sdtmp))
2529a2e2270fSchristos	    (set bibit  (c-call BI "get_epiphany_finvalidflag" sdtmp))
2530a2e2270fSchristos	    (set bvsbit (or bvsbit bvbit))
2531a2e2270fSchristos	    (set busbit (or busbit bubit))
2532a2e2270fSchristos	    (set bisbit (or bisbit bibit))
2533a2e2270fSchristos	    (set rd sdtmp)
2534a2e2270fSchristos	    (if (or (and invExcEnbit bisbit)
2535a2e2270fSchristos		    (or (and ovfExcEnbit bvsbit) (and unExcEnbit busbit)))
2536a2e2270fSchristos		(sequence ()
2537a2e2270fSchristos		  (set expcause0bit (const 1))
2538a2e2270fSchristos		  (set expcause1bit (const 1))
2539a2e2270fSchristos		  (call-exception #x4 #x2)))
2540a2e2270fSchristos	    ))
2541a2e2270fSchristos	(if (eq arithmetic-modebit2 1)
2542a2e2270fSchristos	    (sequence ((SI sdtmp))
2543a2e2270fSchristos	      (set sdtmp  (c-call SI (.str "epiphany_i" name) rd rn rm))
2544a2e2270fSchristos	      ;; carry is not connected inb the design (set bcbit bcbit)
2545a2e2270fSchristos	      (set bzbit (zflag sdtmp))
2546a2e2270fSchristos	      (set bnbit (nflag sdtmp))
2547a2e2270fSchristos	      (set rd sdtmp)))
2548a2e2270fSchristos	)
2549a2e2270fSchristos
2550a2e2270fSchristos      ()
2551a2e2270fSchristos      )
2552a2e2270fSchristos    (dnmi (.sym "i_" name "f16")
2553a2e2270fSchristos	  (.str "i_" name)
2554a2e2270fSchristos	  (SHORT-INSN NO-DIS)
2555a2e2270fSchristos	  (.str "i" name " $rd,$rn,$rm")
2556a2e2270fSchristos	  (emit (.sym "f_" name "f16") rd rn rm)
2557a2e2270fSchristos    )
2558a2e2270fSchristos
2559a2e2270fSchristos
2560a2e2270fSchristos    (dni_wrapper
2561a2e2270fSchristos      (.sym "f_" name "f32")
2562a2e2270fSchristos      (.str "f_" name)
2563a2e2270fSchristos      ()
2564a2e2270fSchristos      (.str "f" name " $rd6,$rn6,$rm6")
2565a2e2270fSchristos      (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rm6)
2566a2e2270fSchristos      (sequence ()
2567a2e2270fSchristos	(if
2568a2e2270fSchristos	  (eq arithmetic-modebit2 0)
2569a2e2270fSchristos	  (sequence ((SF fptemp) (SI sdtmp))
2570a2e2270fSchristos	    (set sdtmp  (c-call SI (.str "epiphany_f" name) rd6 rn6 rm6))
2571a2e2270fSchristos
2572a2e2270fSchristos	    ;;All bits are calculated in C
2573a2e2270fSchristos	    (set bzbit  (c-call BI "get_epiphany_fzeroflag" sdtmp))
2574a2e2270fSchristos	    (set bnbit  (c-call BI "get_epiphany_fnegativeflag" sdtmp))
2575a2e2270fSchristos	    (set bvbit  (c-call BI "get_epiphany_foverflowflag" sdtmp))
2576a2e2270fSchristos	    (set bubit  (c-call BI "get_epiphany_funderflowflag" sdtmp))
2577a2e2270fSchristos	    (set bibit  (c-call BI "get_epiphany_finvalidflag" sdtmp))
2578a2e2270fSchristos	    (set bvsbit (or bvsbit bvbit))
2579a2e2270fSchristos	    (set busbit (or busbit bubit))
2580a2e2270fSchristos	    (set bisbit (or bisbit bibit))
2581a2e2270fSchristos
2582a2e2270fSchristos	    (set rd6 sdtmp)
2583a2e2270fSchristos
2584a2e2270fSchristos	    (if (or (and invExcEnbit bisbit)
2585a2e2270fSchristos		    (or (and ovfExcEnbit bvsbit) (and unExcEnbit busbit)))
2586a2e2270fSchristos		(sequence ()
2587a2e2270fSchristos		  (set expcause0bit (const 1))
2588a2e2270fSchristos		  (set expcause1bit (const 1))
2589a2e2270fSchristos		  (call-exception #x4 #x2)))
2590a2e2270fSchristos	    )
2591a2e2270fSchristos	  )
2592a2e2270fSchristos	(if (eq arithmetic-modebit2 1)
2593a2e2270fSchristos	    (sequence ((SI sdtmp))
2594a2e2270fSchristos	      (set sdtmp (c-call SI (.str "epiphany_i" name) rd6 rn6 rm6))
2595a2e2270fSchristos	      ;; carry is not connected inb the design (set bcbit bcbit)
2596a2e2270fSchristos	      (set bzbit (zflag sdtmp))
2597a2e2270fSchristos	      (set bnbit (nflag sdtmp))
2598a2e2270fSchristos	      (set rd6 sdtmp)
2599a2e2270fSchristos	      )
2600a2e2270fSchristos	    )
2601a2e2270fSchristos	)
2602a2e2270fSchristos      ()
2603a2e2270fSchristos      )
2604a2e2270fSchristos
2605a2e2270fSchristos    (dnmi (.sym "f_" name "f32.l")
2606a2e2270fSchristos	  (.str "f_" name)
2607a2e2270fSchristos	  (NO-DIS)
2608a2e2270fSchristos	  (.str "f" name ".l $rd6,$rn6,$rm6")
2609a2e2270fSchristos	  (emit  (.sym "f_" name "f32") rd6  rn6 rm6)
2610a2e2270fSchristos	  )
2611a2e2270fSchristos    (dnmi (.sym "i_" name "f32")
2612a2e2270fSchristos	  (.str "i_" name)
2613a2e2270fSchristos	  (NO-DIS)
2614a2e2270fSchristos	  (.str "i" name " $rd6,$rn6,$rm6")
2615a2e2270fSchristos	  (emit  (.sym "f_" name "f32") rd6  rn6 rm6)
2616a2e2270fSchristos	  )
2617a2e2270fSchristos    (dnmi (.sym "i_" name "f32.l")
2618a2e2270fSchristos	  (.str "i_" name)
2619a2e2270fSchristos	  (NO-DIS)
2620a2e2270fSchristos	  (.str "i" name ".l $rd6,$rn6,$rm6")
2621a2e2270fSchristos	  (emit  (.sym "f_" name "f32") rd6  rn6 rm6)
2622a2e2270fSchristos	  )
2623a2e2270fSchristos
2624a2e2270fSchristos
2625a2e2270fSchristos
2626a2e2270fSchristos    )
2627a2e2270fSchristos  )
2628a2e2270fSchristos
2629a2e2270fSchristos(op-two_operands-float add OPF_ADD)
2630a2e2270fSchristos(op-two_operands-float sub OPF_SUB)
2631a2e2270fSchristos(op-two_operands-float mul OPF_MUL)
2632a2e2270fSchristos(op-two_operands-float madd OPF_MADD)
2633a2e2270fSchristos(op-two_operands-float msub OPF_MSUB)
2634a2e2270fSchristos
2635a2e2270fSchristos;; ONE operands
2636a2e2270fSchristos;; FABS
2637a2e2270fSchristos(define-pmacro (op-fabs-float name code)
2638a2e2270fSchristos  (begin
2639a2e2270fSchristos    (dni_wrapper (.sym "f_" name "f16")
2640a2e2270fSchristos		 (.str "f_" name)
2641a2e2270fSchristos		 (SHORT-INSN)
2642a2e2270fSchristos		 (.str "f" name " rd,rn")
2643a2e2270fSchristos		 (+ OP4_DSP16 code rd rn rn)
2644a2e2270fSchristos		 (sequence ((SF fptemp) (SI sdtmp))
2645a2e2270fSchristos
2646a2e2270fSchristos		   ;(set sdtmp  (and rn  #x7fffffff))
2647a2e2270fSchristos		   (set sdtmp  (c-call SI (.str "epiphany_fabs") rd rn rn))
2648a2e2270fSchristos
2649a2e2270fSchristos
2650a2e2270fSchristos		   (set bnbit  (const SI 0))
2651a2e2270fSchristos		   (set bzbit (eq SI sdtmp  (const SI 0)))
2652a2e2270fSchristos
2653a2e2270fSchristos		   ;;TODO subnormal ??
2654a2e2270fSchristos		   (set bvsbit (or bvsbit bvbit))
2655a2e2270fSchristos		   (set busbit (or busbit bubit))
2656a2e2270fSchristos		   (set bisbit (or bisbit bibit))
2657a2e2270fSchristos
2658a2e2270fSchristos		   (set rd sdtmp)
2659a2e2270fSchristos		   )
2660a2e2270fSchristos		 ()
2661a2e2270fSchristos		 )
2662a2e2270fSchristos
2663a2e2270fSchristos    (dni_wrapper (.sym "f_" name "f32")
2664a2e2270fSchristos		 (.str "f_" name)
2665a2e2270fSchristos		 ()
2666a2e2270fSchristos		 (.str "f" name " $rd6,$rn6")
2667a2e2270fSchristos		 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rn6)
2668a2e2270fSchristos		 (sequence ((SF fptemp) (SI sdtmp))
2669a2e2270fSchristos
2670a2e2270fSchristos
2671a2e2270fSchristos		   ;(set sdtmp   (and rn6  #x7fffffff))
2672a2e2270fSchristos
2673a2e2270fSchristos		   (set sdtmp  (c-call SI (.str "epiphany_fabs") rd6 rn6 rn6))
2674a2e2270fSchristos
2675a2e2270fSchristos
2676a2e2270fSchristos		   (set bnbit   (const SI 0))
2677a2e2270fSchristos		   (set bzbit (eq SI sdtmp  (const SI 0)))
2678a2e2270fSchristos
2679a2e2270fSchristos		   (set bvsbit (or bvsbit bvbit))
2680a2e2270fSchristos		   (set busbit (or busbit bubit))
2681a2e2270fSchristos		   (set bisbit (or bisbit bibit))
2682a2e2270fSchristos
2683a2e2270fSchristos		   (set rd6 sdtmp)
2684a2e2270fSchristos
2685a2e2270fSchristos		   )
2686a2e2270fSchristos		 ()
2687a2e2270fSchristos		 )
2688a2e2270fSchristos
2689a2e2270fSchristos    (dnmi  (.sym "f_" name "f32.l")
2690a2e2270fSchristos	   (.str "f_" name)
2691a2e2270fSchristos	   (NO-DIS)
2692a2e2270fSchristos	   (.str "f" name ".l $rd6,$rn6")
2693a2e2270fSchristos	   (emit (.sym "f_" name "f32") rd6  rn6)
2694a2e2270fSchristos	   )
2695a2e2270fSchristos
2696a2e2270fSchristos
2697a2e2270fSchristos    )
2698a2e2270fSchristos  )
2699a2e2270fSchristos
2700a2e2270fSchristos(op-fabs-float abs OPF_FABS)
2701a2e2270fSchristos
2702a2e2270fSchristos
2703a2e2270fSchristos(define-pmacro (op-fix2float-float name code)
2704a2e2270fSchristos  (begin
2705a2e2270fSchristos    (dni_wrapper (.sym "f_" name "f16")
2706a2e2270fSchristos		 (.str "f_" name)
2707a2e2270fSchristos		 (SHORT-INSN)
2708a2e2270fSchristos		 (.str "f" name " $rd,$rn")
2709a2e2270fSchristos		 (+ OP4_DSP16 code frd frn frn)
2710a2e2270fSchristos		 (sequence ((SF fptemp) (SI sdtmp))
2711a2e2270fSchristos
2712a2e2270fSchristos		   (set sdtmp  (c-call SI (.str "epiphany_f" name) rd rn rn))
2713a2e2270fSchristos
2714a2e2270fSchristos		   (set bnbit (lt SI sdtmp  (const SI 0)))
2715a2e2270fSchristos		   (set bzbit (eq SI sdtmp  (const SI 0)))
2716a2e2270fSchristos
2717a2e2270fSchristos		   (set bvsbit (or bvsbit bvbit))
2718a2e2270fSchristos		   (set busbit (or busbit bubit))
2719a2e2270fSchristos		   (set bisbit (or bisbit bibit))
2720a2e2270fSchristos
2721a2e2270fSchristos		   (set rd sdtmp)
2722a2e2270fSchristos		   )
2723a2e2270fSchristos		 ()
2724a2e2270fSchristos		 )
2725a2e2270fSchristos
2726a2e2270fSchristos
2727a2e2270fSchristos    (dni_wrapper (.sym "f_" name "f32")
2728a2e2270fSchristos		 (.str "f_" name)
2729a2e2270fSchristos		 ()
2730a2e2270fSchristos		 (.str "f" name " $rd6,$rn6")
2731a2e2270fSchristos		 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rn6)
2732a2e2270fSchristos		 (sequence ((SF fptemp) (SI sdtmp))
2733a2e2270fSchristos
2734a2e2270fSchristos		   (set sdtmp  (c-call SI (.str "epiphany_f" name) rd6 rn6 rn6))
2735a2e2270fSchristos
2736a2e2270fSchristos		   (set bnbit (lt SI sdtmp  (const SI 0)))
2737a2e2270fSchristos		   (set bzbit (eq SI sdtmp  (const SI 0)))
2738a2e2270fSchristos
2739a2e2270fSchristos		   (set bvsbit (or bvsbit bvbit))
2740a2e2270fSchristos		   (set busbit (or busbit bubit))
2741a2e2270fSchristos		   (set bisbit (or bisbit bibit))
2742a2e2270fSchristos
2743a2e2270fSchristos		   (set rd6 sdtmp)
2744a2e2270fSchristos
2745a2e2270fSchristos		   )
2746a2e2270fSchristos		 ()
2747a2e2270fSchristos		 )
2748a2e2270fSchristos
2749a2e2270fSchristos    (dnmi (.sym "f_" name "f32.l")
2750a2e2270fSchristos	  (.str "f_" name)
2751a2e2270fSchristos	  (NO-DIS)
2752a2e2270fSchristos	  (.str "f" name ".l $rd6,$rn6")
2753a2e2270fSchristos	  (emit (.sym "f_" name "f32")  rd6 rn6)
2754a2e2270fSchristos	  )
2755a2e2270fSchristos    )
2756a2e2270fSchristos  )
2757a2e2270fSchristos
2758a2e2270fSchristos(op-fix2float-float loat OPF_FLOAT)
2759a2e2270fSchristos
2760a2e2270fSchristos(define-pmacro (op-float2fix-float name code)
2761a2e2270fSchristos  (begin
2762a2e2270fSchristos    (dni_wrapper (.sym "f_" name "f16")
2763a2e2270fSchristos		 (.str "f_" name)
2764a2e2270fSchristos		 (SHORT-INSN)
2765a2e2270fSchristos		 (.str "f" name " $rd,$rn")
2766a2e2270fSchristos		 (+ OP4_DSP16 code rd rn rn)
2767a2e2270fSchristos		 (sequence ((SF fptemp) (SI sdtmp))
2768a2e2270fSchristos
2769a2e2270fSchristos		   (set sdtmp  (c-call SI (.str "epiphany_f" name) rd rn rn))
2770a2e2270fSchristos
2771a2e2270fSchristos		   (set bzbit (zflag sdtmp))
2772a2e2270fSchristos		   (set bnbit (nflag sdtmp))
2773a2e2270fSchristos
2774a2e2270fSchristos		   (set bvbit  (c-call BI "get_epiphany_foverflowflag" sdtmp))
2775a2e2270fSchristos		   (set bubit  (c-call BI "get_epiphany_funderflowflag" sdtmp))
2776a2e2270fSchristos		   (set bibit  (c-call BI "get_epiphany_finvalidflag" sdtmp))
2777a2e2270fSchristos
2778a2e2270fSchristos		   (set bvsbit (or bvsbit bvbit))
2779a2e2270fSchristos		   (set busbit (or busbit bubit))
2780a2e2270fSchristos		   (set bisbit (or bisbit bibit))
2781a2e2270fSchristos
2782a2e2270fSchristos		   (set rd6 sdtmp)
2783a2e2270fSchristos
2784a2e2270fSchristos		   (if (or (and invExcEnbit bisbit)
2785a2e2270fSchristos			   (or (and ovfExcEnbit busbit)
2786a2e2270fSchristos			       (and unExcEnbit bvsbit)))
2787a2e2270fSchristos		       (sequence ()
2788a2e2270fSchristos			 (set expcause0bit (const 1))
2789a2e2270fSchristos			 (set expcause1bit (const 1))
2790a2e2270fSchristos			 (call-exception #x4 #x2)))
2791a2e2270fSchristos		   (set rd sdtmp)
2792a2e2270fSchristos		   )
2793a2e2270fSchristos		 ()
2794a2e2270fSchristos		 )
2795a2e2270fSchristos
2796a2e2270fSchristos
2797a2e2270fSchristos
2798a2e2270fSchristos    (dni_wrapper (.sym "f_" name "f32")
2799a2e2270fSchristos		 (.str "f_" name)
2800a2e2270fSchristos		 ()
2801a2e2270fSchristos		 (.str "f" name " $rd6,$rn6")
2802a2e2270fSchristos		 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rn6)
2803a2e2270fSchristos		 (sequence ((SF fptemp) (SI sdtmp))
2804a2e2270fSchristos
2805a2e2270fSchristos		   (set sdtmp  (c-call SI (.str "epiphany_f" name) rd6 rn6 rm6))
2806a2e2270fSchristos
2807a2e2270fSchristos		   (set bzbit (zflag sdtmp))
2808a2e2270fSchristos		   (set bnbit (nflag sdtmp))
2809a2e2270fSchristos
2810a2e2270fSchristos		   (set bvbit  (c-call BI "get_epiphany_foverflowflag" sdtmp))
2811a2e2270fSchristos		   (set bubit  (c-call BI "get_epiphany_funderflowflag" sdtmp))
2812a2e2270fSchristos		   (set bibit  (c-call BI "get_epiphany_finvalidflag" sdtmp))
2813a2e2270fSchristos
2814a2e2270fSchristos		   (set bvsbit (or bvsbit bvbit))
2815a2e2270fSchristos		   (set busbit (or busbit bubit))
2816a2e2270fSchristos		   (set bisbit (or bisbit bibit))
2817a2e2270fSchristos
2818a2e2270fSchristos		   (set rd6 sdtmp)
2819a2e2270fSchristos
2820a2e2270fSchristos		   (if (or (and invExcEnbit bisbit)
2821a2e2270fSchristos			   (or (and ovfExcEnbit busbit)
2822a2e2270fSchristos			       (and unExcEnbit bvsbit)))
2823a2e2270fSchristos		       (sequence ()
2824a2e2270fSchristos			 (set expcause0bit (const 1))
2825a2e2270fSchristos			 (set expcause1bit (const 1))
2826a2e2270fSchristos			 (call-exception #x4 #x2))
2827a2e2270fSchristos		       )
2828a2e2270fSchristos
2829a2e2270fSchristos		   )
2830a2e2270fSchristos		 ()
2831a2e2270fSchristos		 )
2832a2e2270fSchristos
2833a2e2270fSchristos    (dnmi (.sym "f_" name "f32.l")
2834a2e2270fSchristos	  (.str "f_" name)
2835a2e2270fSchristos	  (NO-DIS)
2836a2e2270fSchristos	  (.str "f" name ".l $rd6,$rn6")
2837a2e2270fSchristos	  (emit (.sym "f_" name "f32") rd6  rn6)
2838a2e2270fSchristos	  )
2839a2e2270fSchristos
2840a2e2270fSchristos
2841a2e2270fSchristos    )
2842a2e2270fSchristos  )
2843a2e2270fSchristos
2844a2e2270fSchristos
2845a2e2270fSchristos
2846a2e2270fSchristos
2847a2e2270fSchristos
2848a2e2270fSchristos(op-float2fix-float ix OPF_FIX)
2849a2e2270fSchristos
2850a2e2270fSchristos;; MAC (Multiply and Accumulate Instructions
2851a2e2270fSchristos;; (define-pmacro (op-mac-float name code)
2852a2e2270fSchristos;;   (begin
2853a2e2270fSchristos;;     (dni_wrapper (.sym "fm" name "f16")
2854a2e2270fSchristos;; 	 (.str "fm" name)
2855a2e2270fSchristos;; 	 (SHORT-INSN)
2856a2e2270fSchristos;; 	 (.str "fm" name " $frd,$frn,$frm")
2857a2e2270fSchristos;; 	 (+ OP4_DSP16 code frd frn frm)
2858a2e2270fSchristos;; 	 (sequence ((SF fptemp))
2859a2e2270fSchristos;; 		   (set bvbit 0)
2860a2e2270fSchristos;; 		   (set busbit 0)
2861a2e2270fSchristos;;                    (set fptemp (c-call SF (.str "epiphany_fm" name) frd frm frn))
2862a2e2270fSchristos;; 		   (set bnbit (lt SF fptemp (const SF 0)))
2863a2e2270fSchristos;; 		   (set bzbit (eq SF fptemp (const SF 0)))
2864a2e2270fSchristos;; 		   (set bvsbit (or bvsbit bvbit))
2865a2e2270fSchristos;;                    (set frd fptemp)
2866a2e2270fSchristos;; ;		   (set rd (subword SI frd 0))
2867a2e2270fSchristos;; 		   )
2868a2e2270fSchristos;; 	 ()
2869a2e2270fSchristos;; 	 )
2870a2e2270fSchristos
2871a2e2270fSchristos;;     (dni_wrapper (.sym "fm" name "f32")
2872a2e2270fSchristos;; 	 (.str "fm" name)
2873a2e2270fSchristos;; 	 ()
2874a2e2270fSchristos;; 	 (.str "fm" name " $frd6,$frn6,$frm6")
2875a2e2270fSchristos;; 	 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) frd6 frn6 frm6)
2876a2e2270fSchristos;; 	 (sequence ((SF fptemp))
2877a2e2270fSchristos;; 		   (set bvbit 0)
2878a2e2270fSchristos;; 		   (set busbit 0)
2879a2e2270fSchristos;;                    (set fptemp (c-call SF (.str "epiphany_fm" name) frd6 frm6 frn6))
2880a2e2270fSchristos;; 		   (set bnbit (lt SF fptemp (const SF 0)))
2881a2e2270fSchristos;; 		   (set bzbit (eq SF fptemp (const SF 0)))
2882a2e2270fSchristos;; 		   (set bvsbit (or bvsbit bvbit))
2883a2e2270fSchristos;;                    (set frd6 fptemp)
2884a2e2270fSchristos;; ;		   (set rd6 (subword SI frd6 0))
2885a2e2270fSchristos;; 		   )
2886a2e2270fSchristos;; 	 ()
2887a2e2270fSchristos;; 	 )
2888a2e2270fSchristos;;     )
2889a2e2270fSchristos;; )
2890a2e2270fSchristos
2891a2e2270fSchristos
2892a2e2270fSchristos
2893a2e2270fSchristos
2894a2e2270fSchristos
2895a2e2270fSchristos
2896a2e2270fSchristos
2897a2e2270fSchristos					; extended floating point operation
2898a2e2270fSchristos
2899a2e2270fSchristos
2900a2e2270fSchristos(define-pmacro (op-fextop-float name code)
2901a2e2270fSchristos  (begin
2902a2e2270fSchristos
2903a2e2270fSchristos    (dni_wrapper (.sym "f_" name "f32")
2904a2e2270fSchristos		 (.str "f_" name)
2905a2e2270fSchristos		 ()
2906a2e2270fSchristos		 (.str "f" name " $frd6,$frn6")
2907a2e2270fSchristos		 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-2 #x0) (f-dc-20-1 #x1) frd6 frn6 frn6)
2908a2e2270fSchristos		 (sequence ((SF fptemp))
2909a2e2270fSchristos			   (set bvbit 0)
2910a2e2270fSchristos			   (set busbit 0)
2911a2e2270fSchristos			   (set fptemp (c-call SF (.str "epiphany_f" name) frn6))
2912a2e2270fSchristos			   (set bnbit (lt SF fptemp (const SF 0)))
2913a2e2270fSchristos			   (set bzbit (eq SF fptemp (const SF 0)))
2914a2e2270fSchristos			   (set bvsbit (or bvsbit bvbit))
2915a2e2270fSchristos			   (set frd6 fptemp)
2916a2e2270fSchristos
2917a2e2270fSchristos			   )
2918a2e2270fSchristos		 ()
2919a2e2270fSchristos		 )
2920a2e2270fSchristos
2921a2e2270fSchristos
2922a2e2270fSchristos    (dnmi (.sym "f_" name "f32.l")
2923a2e2270fSchristos	  (.str "f_" name)
2924a2e2270fSchristos	  (NO-DIS)
2925a2e2270fSchristos	  (.str "f" name ".l $frd6,$frn6")
2926a2e2270fSchristos	  (emit (.sym "f_" name "f32") frd6 frn6)
2927a2e2270fSchristos	  )
2928a2e2270fSchristos    )
2929a2e2270fSchristos  )
2930a2e2270fSchristos
2931a2e2270fSchristos(op-fextop-float recip OPF_FRECIP)
2932a2e2270fSchristos(op-fextop-float sqrt  OPF_FSQRT)
2933a2e2270fSchristos
2934a2e2270fSchristos
2935a2e2270fSchristos
2936a2e2270fSchristos
2937a2e2270fSchristos
2938