xref: /netbsd-src/external/gpl3/binutils/dist/cpu/epiphany.cpu (revision 6f4ced0b3153adc81d1209a382d97f210becf0ec)
1883529b6Schristos; Adapteva EPIPHANY CPU description. -*- Scheme -*-
2883529b6Schristos; Copyright 1998, 1999, 2000, 2001, 2003, 2006, 2007, 2008, 2009, 2010, 2011
3883529b6Schristos; Free Software Foundation, Inc.
4883529b6Schristos;
5883529b6Schristos; Contributed by Embecosm on behalf of Adapteva, Inc.
6883529b6Schristos; This file is part of the GNU Binutils and of GDB.
7883529b6Schristos;
8883529b6Schristos; This program is free software; you can redistribute it and/or modify
9883529b6Schristos; it under the terms of the GNU General Public License as published by
10883529b6Schristos; the Free Software Foundation; either version 3 of the License, or
11883529b6Schristos; (at your option) any later version.
12883529b6Schristos;
13883529b6Schristos; This program is distributed in the hope that it will be useful,
14883529b6Schristos; but WITHOUT ANY WARRANTY; without even the implied warranty of
15883529b6Schristos; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16883529b6Schristos; GNU General Public License for more details.
17883529b6Schristos;
18883529b6Schristos; You should have received a copy of the GNU General Public License
19883529b6Schristos; along with this program; if not, write to the Free Software
20883529b6Schristos; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21883529b6Schristos; MA 02110-1301, USA.
22883529b6Schristos
23883529b6Schristos(include "simplify.inc")
24883529b6Schristos					; define-arch must appear first
25883529b6Schristos
26883529b6Schristos(define-arch
27883529b6Schristos  (name epiphany) ; name of cpu family
28883529b6Schristos  (comment "Adapteva, Inc. EPIPHANY family")
29883529b6Schristos  (default-alignment aligned)
30883529b6Schristos  (insn-lsb0? #t)
31883529b6Schristos
32883529b6Schristos					; - a 16/32 bit instruction machine (the default)
33883529b6Schristos
34883529b6Schristos  (machs epiphany32)
35883529b6Schristos  (isas epiphany)
36883529b6Schristos  )
37883529b6Schristos
38883529b6Schristos					; Attributes.
39883529b6Schristos
40883529b6Schristos(define-attr
41883529b6Schristos  (for insn)
42883529b6Schristos  (type boolean)
43883529b6Schristos  (name SHORT-INSN)
44883529b6Schristos  (comment "instruction is a 16 bit form")
45883529b6Schristos  )
46883529b6Schristos
47883529b6Schristos;; 3 bit add/sub immediate forms - useful for relaxing into 11 bit form
48883529b6Schristos(define-attr
49883529b6Schristos  (for insn)
50883529b6Schristos  (type boolean)
51883529b6Schristos  (name IMM3)
52883529b6Schristos  (comment "instruction has a 3 bit immediate form")
53883529b6Schristos  )
54883529b6Schristos
55883529b6Schristos;; 8 bit mov immediate forms - useful for relaxing into 16 bit form
56883529b6Schristos(define-attr
57883529b6Schristos  (for insn)
58883529b6Schristos  (type boolean)
59883529b6Schristos  (name IMM8)
60883529b6Schristos  (comment "instruction has a 8 bit immediate form")
61883529b6Schristos  )
62883529b6Schristos
63883529b6Schristos					; Instruction set parameters.
64883529b6Schristos
65883529b6Schristos(define-isa
66883529b6Schristos  (name epiphany)
67883529b6Schristos  (comment "Adapteva, Inc. EPIPHANY32 ISA")
68883529b6Schristos
69883529b6Schristos  (default-insn-word-bitsize 32)
70883529b6Schristos  (default-insn-bitsize 32)
71883529b6Schristos  (base-insn-bitsize 32)
72883529b6Schristos  (decode-assist (3 2 1 0))  ; CGEN can figure this out
73883529b6Schristos  (liw-insns 1)				; # instructions fetched at once
74883529b6Schristos  )
75883529b6Schristos
76883529b6Schristos					; Cpu family definitions.
77883529b6Schristos
78883529b6Schristos
79883529b6Schristos(define-cpu
80883529b6Schristos					; cpu names must be distinct from the architecture name and machine names.
81883529b6Schristos  (name epiphanybf)
82883529b6Schristos  (comment "Adapteva, Inc. EPIPHANY Family")
83883529b6Schristos  (endian little)
84883529b6Schristos  (word-bitsize 32)
85883529b6Schristos  )
86883529b6Schristos
87883529b6Schristos(define-cpu
88883529b6Schristos  (name epiphanymf)
89883529b6Schristos  (comment "Adapteva, Inc. EPIPHANY Family")
90883529b6Schristos  (endian little)
91883529b6Schristos  (word-bitsize 32)
92883529b6Schristos  )
93883529b6Schristos
94883529b6Schristos
95883529b6Schristos(define-mach
96883529b6Schristos  (name epiphany32)
97883529b6Schristos  (comment "Adapteva EPIPHANY")
98883529b6Schristos  (cpu epiphanybf)
99883529b6Schristos  )
100883529b6Schristos
101883529b6Schristos
102883529b6Schristos					; Model descriptions.
103883529b6Schristos
104883529b6Schristos(define-model
105883529b6Schristos  (name epiphany32) (comment "Adapteva EPIPHANY 32/16") (attrs)
106883529b6Schristos  (mach epiphany32)
107883529b6Schristos
108883529b6Schristos  (unit u-exec "Execution Unit" ()
109883529b6Schristos	1 1 ; issue done
110883529b6Schristos	() ; state
111883529b6Schristos	() ; inputs
112883529b6Schristos	() ; outputs
113883529b6Schristos	() ; profile action (default)
114883529b6Schristos	)
115883529b6Schristos  )
116883529b6Schristos
117883529b6Schristos
118883529b6Schristos
119883529b6Schristos					; Instruction fields.
120883529b6Schristos					;
121883529b6Schristos					; Attributes:
122883529b6Schristos					; XXX: what EPIPHANY attrs
123883529b6Schristos					; PCREL-ADDR: pc relative value (for reloc and disassembly purposes)
124883529b6Schristos					; ABS-ADDR: absolute address (for reloc and disassembly purposes?)
125883529b6Schristos					; RESERVED: bits are not used to decode insn, must be all 0
126883529b6Schristos					; RELOC: there is a relocation associated with this field
127883529b6Schristos
128883529b6Schristos(define-attr
129883529b6Schristos  (for ifield operand)
130883529b6Schristos  (type boolean)
131883529b6Schristos  (name RELOC)
132883529b6Schristos  (comment "there is a reloc associated with this field (experiment)")
133883529b6Schristos  )
134883529b6Schristos
135883529b6Schristos;; define the fields of the instruction.
136883529b6Schristos;;   name            description              ATTR  MSB LEN
137883529b6Schristos(dnf f-opc	  "primary opcode"	       ()     3 4)
138883529b6Schristos(dnf f-opc-4-1    "secondary opcode"           ()     4 1)
139883529b6Schristos(dnf f-opc-6-3    "secondary opcode"           ()     6 3) ;;
140883529b6Schristos(dnf f-opc-8-5    "tertiary opcode"            ()     8 5) ;;
141883529b6Schristos(dnf f-opc-19-4   "additional opcode bits"     ()    19 4)
142883529b6Schristos(dnf f-condcode   "condition codes" 	       ()     7 4)
143883529b6Schristos(dnf f-secondary-ccs "flag for secondary ccs"  ()     7 1)
144883529b6Schristos(dnf f-shift      "shift amount"               ()     9 5)
145883529b6Schristos(dnf f-wordsize   "load/store size"            ()     6 2)
146883529b6Schristos(dnf f-store      "load/store flag"            ()     4 1) ;; 0==load,1==store
147883529b6Schristos(dnf f-opc-8-1    "opcode bits"                ()     8 1)
148883529b6Schristos(dnf f-opc-31-32  "all opcode set"             ()     31 32)
149883529b6Schristos
150883529b6Schristos(df f-simm8	  "branch displacement"   (PCREL-ADDR RELOC) 15 8 INT
151883529b6Schristos    ((value pc) (sra SI (sub SI value pc) 1))
152*6f4ced0bSchristos    ((value pc) (add SI (mul SI value 2) pc)))
153883529b6Schristos
154883529b6Schristos(df f-simm24     "branch displacement"	  (PCREL-ADDR RELOC) 31 24 INT
155883529b6Schristos    ((value pc) (sra SI (sub SI value pc) 1))
156*6f4ced0bSchristos    ((value pc) (add SI (mul SI value 2) pc)))
157883529b6Schristos
158883529b6Schristos(df f-sdisp3     "signed immediate 3 bit"      ()     9 3  INT #f #f)
159883529b6Schristos
160883529b6Schristos(dnf f-disp3      "address offset"             ()     9 3)
161883529b6Schristos(dnf f-disp8      "address offset"             ()    23 8)
162883529b6Schristos
163883529b6Schristos(dnf f-imm8      "move/add/sub imm8"           ()    12 8)
164883529b6Schristos(dnf f-imm-27-8  "move/add/sub imm16"          ()    27 8)
165883529b6Schristos(dnf f-addsubx   "+/- index address"           ()    20 1)
166883529b6Schristos(dnf f-subd      "+/- displ address"           ()    24 1)
167883529b6Schristos(dnf f-pm        "post-modify immediate"       ()    25 1)
168883529b6Schristos
169883529b6Schristos(dnf f-rm        "short rm"                    ()     9 3)   ;; RM
170883529b6Schristos(dnf f-rn        "short rn"                    ()    12 3)   ;; RN
171883529b6Schristos(dnf f-rd        "short rd"                    ()    15 3)   ;; RD
172883529b6Schristos
173883529b6Schristos(dnf f-rm-x       "extension rm"               ()    25 3)   ;; RM
174883529b6Schristos(dnf f-rn-x       "extension rn"               ()    28 3)   ;; RN
175883529b6Schristos(dnf f-rd-x       "extension rd"               ()    31 3)   ;; RD
176883529b6Schristos
177883529b6Schristos(dnf f-dc-9-1     "DC"                 (RESERVED)     9 1)
178883529b6Schristos
179883529b6Schristos(dnf f-sn        "short sn"                    ()    12 3)   ;; SN
180883529b6Schristos(dnf f-sd        "short sd"                    ()    15 3)   ;; SD
181883529b6Schristos
182883529b6Schristos(dnf f-sn-x       "extension sn"               ()    28 3)   ;; SN
183883529b6Schristos(dnf f-sd-x       "extension sd"               ()    31 3)   ;; SD
184883529b6Schristos
185883529b6Schristos
186883529b6Schristos
187883529b6Schristos(dnf f-dc-7-4     "movts zeros"                 ()     7 4)
188883529b6Schristos(dnf f-trap-swi-9-1     "trap or swi"                 ()     9 1)
189883529b6Schristos(dnf f-gien-gidis-9-1     "gien or gidis"                 ()     9 1)
190883529b6Schristos
191883529b6Schristos
192883529b6Schristos(dnf f-dc-15-3    "DC"                 (RESERVED)    15 3)
193883529b6Schristos(dnf f-dc-15-7    "DC"                 (RESERVED)    15 7)
194883529b6Schristos(dnf f-dc-15-6    "DC"                 ()            15 6)
195883529b6Schristos(dnf f-trap-num   "trap number"                ()    15 6)
196883529b6Schristos
197883529b6Schristos(dnf f-dc-20-1    "DC"                 (RESERVED)    20 1)
198883529b6Schristos
199883529b6Schristos(dnf f-dc-21-1    "DC"                 (RESERVED)    21 1)
200883529b6Schristos(dnf f-dc-21-2    "DC"                 (RESERVED)    21 2)
201883529b6Schristos
202883529b6Schristos(dnf f-dc-22-3    "DC"                 (RESERVED)    22 3)
203883529b6Schristos(dnf f-dc-22-2    "DC"                 (RESERVED)    22 2)
204883529b6Schristos(dnf f-dc-22-1    "DC"                 (RESERVED)    22 1)
205883529b6Schristos
206883529b6Schristos(dnf f-dc-25-6    "DC"                 (RESERVED)    25 6)
207883529b6Schristos(dnf f-dc-25-4    "DC"                 (RESERVED)    25 4)
208883529b6Schristos(dnf f-dc-25-2    "DC"                 (RESERVED)    25 2)
209883529b6Schristos(dnf f-dc-25-1    "DC"                 (RESERVED)    25 1)
210883529b6Schristos
211883529b6Schristos(dnf f-dc-28-1    "DC"                 (RESERVED)    28 1)
212883529b6Schristos(dnf f-dc-31-3    "DC"                 (RESERVED)    31 3)
213883529b6Schristos
214883529b6Schristos(dnmf f-disp11 "Unsigned offset for load/store" () UINT (f-disp3 f-disp8)
215883529b6Schristos      (sequence ()
216883529b6Schristos		(set (ifield f-disp8) (and (srl (ifield f-disp11) 3) (const 255)))
217883529b6Schristos		(set (ifield f-disp3) (and (ifield f-disp11) 7)))
218883529b6Schristos      (sequence ()
219883529b6Schristos		(set (ifield f-disp11) (or (sll (ifield f-disp8) 3)
220883529b6Schristos					   (ifield f-disp3)))
221883529b6Schristos		)
222883529b6Schristos      )
223883529b6Schristos
224883529b6Schristos
225883529b6Schristos(dnmf f-sdisp11 "Signed offset for load/store" () INT (f-disp3 f-disp8)
226883529b6Schristos      (sequence ()			;encode
227883529b6Schristos		(set (ifield f-disp8) (and #xff (srl SI (ifield f-sdisp11) 3)))
228883529b6Schristos		(set (ifield f-disp3)  (and SI (ifield f-sdisp11) 7)))
229883529b6Schristos      (sequence ()			;decode
230883529b6Schristos		(set (ifield f-sdisp11)
231*6f4ced0bSchristos		     (sub SI (xor (and (or (sll (ifield f-disp8) 3)
232883529b6Schristos					   (ifield f-disp3))
233*6f4ced0bSchristos				       #x7ff)
234*6f4ced0bSchristos				  #x400)
235*6f4ced0bSchristos			  #x400)))
236883529b6Schristos      )
237883529b6Schristos
238883529b6Schristos(dnmf f-imm16 "Short immediate for move/add/sub" () UINT (f-imm8 f-imm-27-8)
239883529b6Schristos      (sequence ()
240883529b6Schristos		(set (ifield f-imm8) (and (ifield f-imm16) #xff))
241883529b6Schristos		(set (ifield f-imm-27-8) (srl (ifield f-imm16) 8)))
242883529b6Schristos      (sequence ()
243883529b6Schristos		(set (ifield f-imm16) (or (sll (ifield f-imm-27-8) 8)
244883529b6Schristos					  (ifield f-imm8))))
245883529b6Schristos      )
246883529b6Schristos
247883529b6Schristos
248883529b6Schristos;; 32 bit instructions have the register number broken into two non-contiguous fields
249883529b6Schristos
250883529b6Schristos(define-pmacro (x-reg-field reg)
251883529b6Schristos  (define-multi-ifield
252883529b6Schristos    (name (.sym "f-" reg "6"))
253883529b6Schristos    (mode UINT)
254883529b6Schristos    (subfields (.sym "f-" reg "-x") (.sym "f-" reg))
255883529b6Schristos    (insert (sequence ()
256883529b6Schristos		      (set (ifield (.sym "f-" reg))   (and (ifield (.sym "f-" reg "6"))
257883529b6Schristos							   (const 7)))
258883529b6Schristos		      (set (ifield (.sym "f-" reg "-x"))  (srl (ifield (.sym "f-" reg "6"))
259883529b6Schristos							       (const 3)))
260883529b6Schristos		      ))
261883529b6Schristos    (extract (sequence ()
262883529b6Schristos		       (set (ifield (.sym "f-" reg "6")) (or (sll (ifield (.sym "f-" reg "-x"))
263883529b6Schristos								  (const 3))
264883529b6Schristos							     (ifield (.sym "f-" reg))))
265883529b6Schristos		       ))
266883529b6Schristos    )
267883529b6Schristos  )
268883529b6Schristos
269883529b6Schristos(x-reg-field rd)			; f-rd6
270883529b6Schristos(x-reg-field rn)			; f-rn6
271883529b6Schristos(x-reg-field rm)			; f-rm6
272883529b6Schristos(x-reg-field sd)			; f-sd6
273883529b6Schristos(x-reg-field sn)			; f-sn6
274883529b6Schristos
275883529b6Schristos
276883529b6Schristos;;;;;;;;;;
277883529b6Schristos					; Enums. ;
278883529b6Schristos;;;;;;;;;;
279883529b6Schristos
280883529b6Schristos					; insn-opc: bits 3..0 - major family selector
281883529b6Schristos(define-normal-insn-enum insn-opc "opc enums" () OP4_ f-opc
282883529b6Schristos  (
283883529b6Schristos   BRANCH16  ;; 0000
284883529b6Schristos   LDSTR16X  ;; 0001
285883529b6Schristos   FLOW16    ;; 0010
286883529b6Schristos   IMM16     ;; 0011
287883529b6Schristos   LDSTR16D  ;; 0100
288883529b6Schristos   LDSTR16P  ;; 0101
289883529b6Schristos   LSHIFT16  ;; 0110 - logical shift
290883529b6Schristos   DSP16     ;; 0111 - 3 reg DSP 16 bit insns
291883529b6Schristos   BRANCH    ;; 1000
292883529b6Schristos   LDSTRX    ;; 1001
293883529b6Schristos   ALU16     ;; 1010 - 3 reg 16 bit
294883529b6Schristos   IMM32     ;; 1011
295883529b6Schristos   LDSTRD    ;; 1100
296883529b6Schristos   LDSTRP    ;; 1101
297883529b6Schristos   ASHIFT16  ;; 1110   ASR, BITR
298883529b6Schristos   MISC      ;; 1111 - 32 bit shifts, 3 reg ALU, 3 reg DSP, FLOW, BITR
299883529b6Schristos   )
300883529b6Schristos  )
301883529b6Schristos
302883529b6Schristos(define-normal-insn-enum insn-wordsize "memory access width" () OPW_ f-wordsize
303883529b6Schristos					; specifies the size of a memory load/store operation
304883529b6Schristos  (BYTE SHORT WORD DOUBLE)
305883529b6Schristos  )
306883529b6Schristos
307883529b6Schristos(define-normal-insn-enum insn-memory-access "memory access direction" () OP_ f-store
308883529b6Schristos					; load=0, store=1
309883529b6Schristos  (LOAD STORE)
310883529b6Schristos  )
311883529b6Schristos
312883529b6Schristos					; enum for trap codes used by simulator
313883529b6Schristos(define-normal-insn-enum trap-codes "trap instruction dispatch code" () TRAP_ f-trap-num
314883529b6Schristos  (write read open exit pass fail close other)
315883529b6Schristos  )
316883529b6Schristos
317883529b6Schristos					; cond branch: bits 7..4
318883529b6Schristos					;
319883529b6Schristos(define-normal-insn-enum insn-cond "branch conditions" () OPC_ f-condcode
320883529b6Schristos  (EQ NE GTU GTEU LTEU LTU GT GTE LT LTE BEQ BNE BLT BLTE B BL))
321883529b6Schristos
322883529b6Schristos					; dsp 3 operand opcodes
323883529b6Schristos(define-normal-insn-enum insn-bop "binary operator subcodes" () OPB_ f-opc-6-3
324883529b6Schristos  (EOR ADD LSL SUB LSR AND ASR ORR))
325883529b6Schristos
326883529b6Schristos					; dsp 3 operand opcodes
327883529b6Schristos(define-normal-insn-enum insn-bopext "binary operator subcodes" () OPBE_ f-opc-6-3
328883529b6Schristos  (FEXT FDEP LFSR - - - - -))
329883529b6Schristos
330883529b6Schristos
331883529b6Schristos(define-normal-insn-enum insn-fop "floating operators" () OPF_ f-opc-6-3
332883529b6Schristos  (ADD SUB MUL MADD MSUB FLOAT FIX FABS))
333883529b6Schristos
334883529b6Schristos(define-normal-insn-enum insn-fopexn "extended floating operators" () OPF_ f-opc-6-3
335883529b6Schristos  (FRECIP FSQRT - - - - - -))
336883529b6Schristos
337883529b6Schristos
338883529b6Schristos
339883529b6Schristos
340883529b6Schristos; Immediate operation secondary opcodes
341883529b6Schristos(define-normal-insn-enum insn-immop "immediate operators" () OPI_ f-opc-6-3
342883529b6Schristos  (- ADD - SUB - - - TRAP) ; TRAP is special extension for simulator
343883529b6Schristos  )
344883529b6Schristos
345883529b6Schristos					; don't care fields
346883529b6Schristos(define-normal-insn-enum insn-dc-25-2 "don't cares" () OPI_25_2_ f-dc-25-2
347883529b6Schristos  (MBZ))
348883529b6Schristos
349883529b6Schristos; General Register keyword names.
350883529b6Schristos(define-keyword
351883529b6Schristos  (name gr-names)
352883529b6Schristos  (print-name h-registers)
353883529b6Schristos  (prefix "")
354883529b6Schristos  (values
355883529b6Schristos; some preferred aliases
3569573673dSchristos   (fp 11) (sp 13) (lr 14)
357883529b6Schristos; the default register names
358883529b6Schristos   (r0  0)  (r1  1)  (r2  2)  (r3  3)  (r4  4)  (r5  5)  (r6  6)  (r7  7)
359883529b6Schristos   (r8  8)  (r9  9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15)
360883529b6Schristos   (r16 16) (r17 17) (r18 18) (r19 19) (r20 20) (r21 21) (r22 22) (r23 23)
361883529b6Schristos   (r24 24) (r25 25) (r26 26) (r27 27) (r28 28) (r29 29) (r30 30) (r31 31)
362883529b6Schristos   (r32 32) (r33 33) (r34 34) (r35 35) (r36 36) (r37 37) (r38 38) (r39 39)
363883529b6Schristos   (r40 40) (r41 41) (r42 42) (r43 43) (r44 44) (r45 45) (r46 46) (r47 47)
364883529b6Schristos   (r48 48) (r49 49) (r50 50) (r51 51) (r52 52) (r53 53) (r54 54) (r55 55)
365883529b6Schristos   (r56 56) (r57 57) (r58 58) (r59 59) (r60 60) (r61 61) (r62 62) (r63 63)
366883529b6Schristos; some less popular aliases
367883529b6Schristos   (a1  0) (a2  1) (a3  2) (a4  3) (v1  4) (v2  5) (v3  6) (v4  7)
368883529b6Schristos   (v5  8) (v6  9) (v7 10) (v8 11)
3699573673dSchristos   (sb 9) (sl 10) (ip 12)
370883529b6Schristos   )
371883529b6Schristos  )
372883529b6Schristos
373883529b6Schristos(define-normal-insn-enum post-index "+/- index register" () DIR_ f-addsubx (POSTINC POSTDEC))
374883529b6Schristos
375883529b6Schristos(define-normal-insn-enum disp-post-modify "postmodify displacement" () PMOD_ f-pm (DISP POST))
376883529b6Schristos
377883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
378883529b6Schristos					; Hardware pieces.
379883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
380883529b6Schristos
381883529b6Schristos;; 64 general-purpose registers
382883529b6Schristos(define-hardware
383883529b6Schristos  (name h-registers)
384883529b6Schristos  (comment "all addressable registers")
385883529b6Schristos  (type register SI (64))
386883529b6Schristos  (attrs PROFILE CACHE-ADDR)
387883529b6Schristos  (indices extern-keyword gr-names)
388883529b6Schristos  )
389883529b6Schristos
390883529b6Schristos
391883529b6Schristos
392883529b6Schristos;; Same 64 registers as floating point registers
393883529b6Schristos(define-hardware
394883529b6Schristos  (name h-fpregisters)
395883529b6Schristos  (comment "all GPRs as float values")
396883529b6Schristos  (type register SF (64))
397883529b6Schristos  (attrs PROFILE VIRTUAL)
398883529b6Schristos  (indices extern-keyword gr-names)
399883529b6Schristos  (get (index) (subword SF (reg h-registers index) 0))
400883529b6Schristos  (set (index newval) (set (reg h-registers index) (subword SI newval 0)))
401883529b6Schristos  )
402883529b6Schristos
403883529b6Schristos;; define processor status bits as physical hardware
404883529b6Schristos
405883529b6Schristos(define-pmacro (psw-h-bit name cmt)
406883529b6Schristos  (dsh name cmt () (register BI)))
407883529b6Schristos
408883529b6Schristos(psw-h-bit h-zbit "integer zero bit")
409883529b6Schristos(psw-h-bit h-nbit "integer neg bit")
410883529b6Schristos(psw-h-bit h-cbit "integer carry bit")
411883529b6Schristos(psw-h-bit h-vbit "integer overflow bit")
412883529b6Schristos(psw-h-bit h-vsbit "integer overflow sticky")
413883529b6Schristos
414883529b6Schristos
415883529b6Schristos(psw-h-bit h-bzbit "floating point zero bit")
416883529b6Schristos(psw-h-bit h-bnbit "floating point neg bit")
417883529b6Schristos(psw-h-bit h-bvbit "floating point ovfl bit")
418883529b6Schristos(psw-h-bit h-bubit "floating point underfl bit")
419883529b6Schristos(psw-h-bit h-bibit "floating point invalid bit")
420883529b6Schristos(psw-h-bit h-bcbit "floating point carry bit")
421883529b6Schristos
422883529b6Schristos(psw-h-bit h-bvsbit "floating point overflow sticky")
423883529b6Schristos(psw-h-bit h-bisbit  "floating point invalid sticky")
424883529b6Schristos(psw-h-bit h-busbit  "floating point underflow sticky")
425883529b6Schristos
426883529b6Schristos(psw-h-bit h-expcause0bit  "exceprion cause bit0")
427883529b6Schristos(psw-h-bit h-expcause1bit  "exceprion cause bit1")
428883529b6Schristos(psw-h-bit h-expcause2bit  "external load stalled bit")
429883529b6Schristos(psw-h-bit h-extFstallbit  "external fetch stalled bit")
430883529b6Schristos
431883529b6Schristos(psw-h-bit h-trmbit  "0=round to nearest, 1=trunacte select bit")
432883529b6Schristos(psw-h-bit h-invExcEnbit  "invalid exception enable bit")
433883529b6Schristos(psw-h-bit h-ovfExcEnbit  "overflow exception enable bit")
434883529b6Schristos(psw-h-bit h-unExcEnbit  "underflow exception enablebit ")
435883529b6Schristos
436883529b6Schristos(psw-h-bit h-timer0bit0  "timer 0 mode selection 0")
437883529b6Schristos(psw-h-bit h-timer0bit1  "timer 0 mode selection 1")
438883529b6Schristos(psw-h-bit h-timer0bit2  "timer 0 mode selection 2")
439883529b6Schristos(psw-h-bit h-timer0bit3  "timer 0 mode selection 3")
440883529b6Schristos(psw-h-bit h-timer1bit0  "timer 1 mode selection 0")
441883529b6Schristos(psw-h-bit h-timer1bit1  "timer 1 mode selection 1")
442883529b6Schristos(psw-h-bit h-timer1bit2  "timer 1 mode selection 2")
443883529b6Schristos(psw-h-bit h-timer1bit3  "timer 1 mode selection 3")
444883529b6Schristos
445883529b6Schristos(psw-h-bit h-mbkptEnbit  "multicore bkpt enable")
446883529b6Schristos(psw-h-bit h-clockGateEnbit  "clock gating enable bkpt enable")
447883529b6Schristos
448883529b6Schristos
449883529b6Schristos(psw-h-bit h-coreCfgResBit12 "core config bit 12")
450883529b6Schristos(psw-h-bit h-coreCfgResBit13 "core config bit 13")
451883529b6Schristos(psw-h-bit h-coreCfgResBit14 "core config bit 14")
452883529b6Schristos(psw-h-bit h-coreCfgResBit15 "core config bit 15")
453883529b6Schristos(psw-h-bit h-coreCfgResBit16 "core config bit 16")
454883529b6Schristos
455883529b6Schristos
456883529b6Schristos(psw-h-bit h-coreCfgResBit20 "core config bit 20")
457883529b6Schristos(psw-h-bit h-coreCfgResBit21 "core config bit 21")
458883529b6Schristos
459883529b6Schristos(psw-h-bit h-coreCfgResBit24 "core config bit 24")
460883529b6Schristos(psw-h-bit h-coreCfgResBit25 "core config bit 25")
461883529b6Schristos(psw-h-bit h-coreCfgResBit26 "core config bit 26")
462883529b6Schristos(psw-h-bit h-coreCfgResBit27 "core config bit 27")
463883529b6Schristos(psw-h-bit h-coreCfgResBit28 "core config bit 28")
464883529b6Schristos(psw-h-bit h-coreCfgResBit29 "core config bit 29")
465883529b6Schristos(psw-h-bit h-coreCfgResBit30 "core config bit 30")
466883529b6Schristos(psw-h-bit h-coreCfgResBit31 "core config bit 31")
467883529b6Schristos
468883529b6Schristos
469883529b6Schristos(psw-h-bit h-arithmetic-modebit0  "arithmetic mode bit0")
470883529b6Schristos(psw-h-bit h-arithmetic-modebit1  "arithmetic mode bit1")
471883529b6Schristos(psw-h-bit h-arithmetic-modebit2  "arithmetic mode bit2")
472883529b6Schristos
473883529b6Schristos
474883529b6Schristos(psw-h-bit h-gidisablebit "global interrupt disable bit")
475883529b6Schristos(psw-h-bit h-kmbit "kernel mode bit")
476883529b6Schristos(psw-h-bit h-caibit "core active indicator mode bit")
477883529b6Schristos(psw-h-bit h-sflagbit "sflag bit")
478883529b6Schristos
479883529b6Schristos
480883529b6Schristos					; Define operands for each of the physical bits
481883529b6Schristos(define-pmacro (psw-bit name hname cmt)
482883529b6Schristos  (dnop name cmt (SEM-ONLY) hname f-nil)
483883529b6Schristos  )
484883529b6Schristos
485883529b6Schristos(psw-bit zbit h-zbit "integer zero bit")
486883529b6Schristos(psw-bit nbit h-nbit "integer neg bit")
487883529b6Schristos(psw-bit cbit h-cbit "integer carry bit")
488883529b6Schristos(psw-bit vbit h-vbit "integer overflow bit")
489883529b6Schristos
490883529b6Schristos(psw-bit bzbit  h-bzbit "floating point zero bit")
491883529b6Schristos(psw-bit bnbit  h-bnbit "floating point neg bit")
492883529b6Schristos(psw-bit bvbit  h-bvbit "floating point ovfl bit")
493883529b6Schristos(psw-bit bcbit  h-bcbit "floating point carry bit")
494883529b6Schristos
495883529b6Schristos(psw-bit bubit h-bubit "floating point underfl bit")
496883529b6Schristos(psw-bit bibit h-bibit "floating point invalid bit")
497883529b6Schristos
498883529b6Schristos
499883529b6Schristos(psw-bit vsbit  h-vsbit  "integer overflow sticky")
500883529b6Schristos(psw-bit bvsbit h-bvsbit "floating point overflow sticky")
501883529b6Schristos(psw-bit bisbit  h-bisbit  "floating point invalid sticky")
502883529b6Schristos(psw-bit busbit  h-busbit  "floating point underflow sticky")
503883529b6Schristos(psw-bit expcause0bit h-expcause0bit  "exceprion cause bit0")
504883529b6Schristos(psw-bit expcause1bit h-expcause1bit  "exceprion cause bit1")
505883529b6Schristos
506883529b6Schristos
507883529b6Schristos(psw-bit expcause2bit  h-expcause2bit  "external load stalled bit")
508883529b6Schristos(psw-bit extFstallbit  h-extFstallbit  "external fetch stalled bit")
509883529b6Schristos
510883529b6Schristos(psw-bit trmbit  h-trmbit  "0=round to nearest, 1=trunacte selct bit")
511883529b6Schristos(psw-bit invExcEnbit  h-invExcEnbit  "invalid exception enable bit")
512883529b6Schristos(psw-bit ovfExcEnbit  h-ovfExcEnbit  "overflow exception enable bit")
513883529b6Schristos(psw-bit unExcEnbit  h-unExcEnbit  "underflow exception enable bit")
514883529b6Schristos
515883529b6Schristos(psw-bit timer0bit0  h-timer0bit0  "timer 0 mode selection 0")
516883529b6Schristos(psw-bit timer0bit1  h-timer0bit1  "timer 0 mode selection 1")
517883529b6Schristos(psw-bit timer0bit2  h-timer0bit2  "timer 0 mode selection 2")
518883529b6Schristos(psw-bit timer0bit3  h-timer0bit3  "timer 0 mode selection 3")
519883529b6Schristos
520883529b6Schristos(psw-bit timer1bit0  h-timer1bit0  "timer 1 mode selection 0")
521883529b6Schristos(psw-bit timer1bit1  h-timer1bit1  "timer 1 mode selection 1")
522883529b6Schristos(psw-bit timer1bit2  h-timer1bit2  "timer 1 mode selection 2")
523883529b6Schristos(psw-bit timer1bit3  h-timer1bit3  "timer 1 mode selection 3")
524883529b6Schristos
525883529b6Schristos(psw-bit mbkptEnbit  h-mbkptEnbit "multicore bkpt enable")
526883529b6Schristos(psw-bit clockGateEnbit  h-clockGateEnbit "clock gate enable enable")
527883529b6Schristos
528883529b6Schristos(psw-bit arithmetic-modebit0  h-arithmetic-modebit0  "arithmetic mode bit0")
529883529b6Schristos(psw-bit arithmetic-modebit1  h-arithmetic-modebit1  "arithmetic mode bit1")
530883529b6Schristos(psw-bit arithmetic-modebit2  h-arithmetic-modebit2  "arithmetic mode bit2")
531883529b6Schristos
532883529b6Schristos(psw-bit coreCfgResBit12  h-coreCfgResBit12 "core config bit 12")
533883529b6Schristos(psw-bit coreCfgResBit13  h-coreCfgResBit13 "core config bit 13")
534883529b6Schristos(psw-bit coreCfgResBit14  h-coreCfgResBit14 "core config bit 14")
535883529b6Schristos(psw-bit coreCfgResBit15  h-coreCfgResBit15 "core config bit 15")
536883529b6Schristos(psw-bit coreCfgResBit16  h-coreCfgResBit16 "core config bit 16")
537883529b6Schristos
538883529b6Schristos(psw-bit coreCfgResBit20  h-coreCfgResBit20 "core config bit 20")
539883529b6Schristos(psw-bit coreCfgResBit21  h-coreCfgResBit21 "core config bit 21")
540883529b6Schristos
541883529b6Schristos(psw-bit coreCfgResBit24  h-coreCfgResBit24 "core config bit 24")
542883529b6Schristos(psw-bit coreCfgResBit25  h-coreCfgResBit25 "core config bit 25")
543883529b6Schristos(psw-bit coreCfgResBit26  h-coreCfgResBit26 "core config bit 26")
544883529b6Schristos(psw-bit coreCfgResBit27  h-coreCfgResBit27 "core config bit 27")
545883529b6Schristos(psw-bit coreCfgResBit28  h-coreCfgResBit28 "core config bit 28")
546883529b6Schristos(psw-bit coreCfgResBit29  h-coreCfgResBit29 "core config bit 29")
547883529b6Schristos(psw-bit coreCfgResBit30  h-coreCfgResBit30 "core config bit 30")
548883529b6Schristos(psw-bit coreCfgResBit31  h-coreCfgResBit31 "core config bit 31")
549883529b6Schristos
550883529b6Schristos
551883529b6Schristos(psw-bit gidisablebit h-gidisablebit "global interrupt disable bit")
552883529b6Schristos(psw-bit kmbit h-kmbit "kernel mode bit")
553883529b6Schristos(psw-bit caibit h-caibit "core actibe indicator bit")
554883529b6Schristos(psw-bit sflagbit h-sflagbit "sflag bit")
555883529b6Schristos
556883529b6Schristos
557883529b6Schristos
558883529b6Schristos
559883529b6Schristos;; Special registers - accessed via MOVTS and MOVFS.
560883529b6Schristos;;
561883529b6Schristos;;  "Core control and status" in group MR0=0, MR1=0
562883529b6Schristos
563883529b6Schristos(define-keyword
564883529b6Schristos  (name cr-names)
565883529b6Schristos  (print-name h-core-registers)
566883529b6Schristos  (prefix "")
567883529b6Schristos  (values  (config         0)
568883529b6Schristos	   (status         1) ; unified condition codes
569883529b6Schristos	   (pc             2) ; virtualized PC
570883529b6Schristos	   (debug          3);
571883529b6Schristos	   (iab            4)
572883529b6Schristos	   (lc             5);loop counter            Not impemented
573883529b6Schristos	   (ls             6);loop start address      Not impemented
574883529b6Schristos	   (le             7);loop end address        Not impemented
575883529b6Schristos	   (iret           8)
576883529b6Schristos	   (imask          9)
577883529b6Schristos	   (ilat           10)
578883529b6Schristos	   (ilatst         11)
579883529b6Schristos	   (ilatcl         12)
580883529b6Schristos	   (ipend          13)
581883529b6Schristos	   (ctimer0        14)
582883529b6Schristos	   (ctimer1        15)
583883529b6Schristos	   (hstatus        16)
584883529b6Schristos	   )
585883529b6Schristos  )
586883529b6Schristos;; DMA registers in group MR0=1, MR1=0
587883529b6Schristos
588883529b6Schristos(define-keyword
589883529b6Schristos  (name crdma-names)
590883529b6Schristos  (print-name h-coredma-registers)
591883529b6Schristos  (prefix "")
592883529b6Schristos  (values
593883529b6Schristos
594883529b6Schristos
595883529b6Schristos   (dma0config     0)
596883529b6Schristos   (dma0stride     1)
597883529b6Schristos   (dma0count      2)
598883529b6Schristos
599883529b6Schristos   (dma0srcaddr    3)
600883529b6Schristos   (dma0dstaddr    4)
601883529b6Schristos
602883529b6Schristos   (dma0auto0      5)
603883529b6Schristos   (dma0auto1      6)
604883529b6Schristos
605883529b6Schristos   (dma0status     7)
606883529b6Schristos
607883529b6Schristos   (dma1config     8)
608883529b6Schristos   (dma1stride     9)
609883529b6Schristos   (dma1count      10)
610883529b6Schristos
611883529b6Schristos   (dma1srcaddr    11)
612883529b6Schristos   (dma1dstaddr    12)
613883529b6Schristos
614883529b6Schristos   (dma1auto0      13)
615883529b6Schristos   (dma1auto1      14)
616883529b6Schristos
617883529b6Schristos   (dma1status     15)
618883529b6Schristos
619883529b6Schristos   )
620883529b6Schristos  )
621883529b6Schristos;; mem configuration registers in group MR0=0, MR1=1
622883529b6Schristos
623883529b6Schristos(define-keyword
624883529b6Schristos  (name crmem-names)
625883529b6Schristos  (print-name h-coremem-registers)
626883529b6Schristos  (prefix "")
627883529b6Schristos  (values
628883529b6Schristos   (memconfig     0)
629883529b6Schristos   (memstatus     1)
630883529b6Schristos   (memprotect    2)
631883529b6Schristos   (memreserve    3)
632883529b6Schristos   )
633883529b6Schristos  )
634883529b6Schristos
635883529b6Schristos;; mesh configuration registers in group MR0=1, MR1=1
636883529b6Schristos
637883529b6Schristos(define-keyword
638883529b6Schristos  (name crmesh-names)
639883529b6Schristos  (print-name h-coremesh-registers)
640883529b6Schristos  (prefix "")
641883529b6Schristos
642883529b6Schristos  (values
643883529b6Schristos
644883529b6Schristos
645883529b6Schristos   (meshconfig    0)
646883529b6Schristos   (coreid    1)
647883529b6Schristos   (meshmulticast 2)
648883529b6Schristos   (swreset   3)
649883529b6Schristos   )
650883529b6Schristos  )
651883529b6Schristos
652883529b6Schristos
653883529b6Schristos
654883529b6Schristos
655883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
656883529b6Schristos					; PC is a byte-addressed register
657883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
658883529b6Schristos
659883529b6Schristos(dnh h-pc "program counter" (PC PROFILE) (pc) () () ())
660883529b6Schristos
661883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
662883529b6Schristos					; Memory Effective Address wants to be visible
663883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
664883529b6Schristos
665883529b6Schristos(dnh h-memaddr "memory effective address" (PROFILE) (register SI) () () ())
666883529b6Schristos(dnop memaddr "memory effective address" (SEM-ONLY) h-memaddr f-nil)
667883529b6Schristos
668883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
669883529b6Schristos					; Special Core Registers
670883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
671883529b6Schristos;; STATUS
672883529b6Schristos;; [0]=core active indicator
673883529b6Schristos;; [1]=global interrupt disable
674883529b6Schristos;; [2]=processor mode(1=user mode, 0=kernel mode)
675883529b6Schristos;; [3]=wired AND global flag
676883529b6Schristos
677883529b6Schristos;; [4]=integer zero                        zbit
678883529b6Schristos;; [5]=integer negative                    nbit
679883529b6Schristos;; [6]=integer carry                       cbit
680883529b6Schristos;; [7]=integer overflow                    vbit
681883529b6Schristos
682883529b6Schristos;; [8]=fpu zero flag                       bzbit
683883529b6Schristos;; [9]=fpu negative flag                   bnbit
684883529b6Schristos;; [10]=fpu overflow flag                  bvbit
685883529b6Schristos;; [11]=fpu carry flag(not used)           bcbit
686883529b6Schristos
687883529b6Schristos;; [12]=ialu overflow flag(sticky)         vsbit
688883529b6Schristos;; [13]=fpu invalid flag(sticky)           bisbit
689883529b6Schristos;; [14]=fpu overflow flag(sticky)          bvsbit
690883529b6Schristos;; [15]=fpu underflow flag(sticky)         busbit
691883529b6Schristos
692883529b6Schristos;; [17:16]=exception cause 00=no exception 01=load-store exception 10=fpu exception 11=unimplemented instruction
693883529b6Schristos;;                                         expcause1bit
694883529b6Schristos;;                                         expcause0bit
695883529b6Schristos
696883529b6Schristos;; [18]=external load stalled              expcause2bit
697883529b6Schristos;; [19]=external fetch stalled             extFstallbit
698883529b6Schristos
699883529b6Schristos;; [31:20]=RESERVED
700883529b6Schristos
701883529b6Schristos
702883529b6Schristos
703883529b6Schristos
704883529b6Schristos
705883529b6Schristos(define-hardware
706883529b6Schristos  (name h-core-registers)
707883529b6Schristos  (comment "Special Core Registers")
708883529b6Schristos  (type register USI (17))
709883529b6Schristos  (attrs)
710883529b6Schristos  (indices extern-keyword cr-names)
711883529b6Schristos  (get (index)
712883529b6Schristos       (cond USI
713883529b6Schristos	 ((eq index (const 1)) ; STATUS reg ?
714883529b6Schristos	  (or (or (or (or (sll USI kmbit (const 2))
715883529b6Schristos			  (sll USI gidisablebit (const 1)))
716883529b6Schristos		      (or (or (sll USI expcause1bit (const 17))
717883529b6Schristos			      (sll USI expcause0bit (const 16)))
718883529b6Schristos			  (or (sll USI expcause2bit (const 18))
719883529b6Schristos			      (sll USI extFstallbit (const 19)))))
720883529b6Schristos		  (or (or (or (sll USI busbit (const 15))
721883529b6Schristos			      (sll USI bisbit (const 13)))
722883529b6Schristos			  (or (sll USI bvsbit (const 14))
723883529b6Schristos			      (sll USI vsbit (const 12))))
724883529b6Schristos		      (or (or (sll USI bvbit (const 10))
725883529b6Schristos			      (sll USI bcbit (const 11)))
726883529b6Schristos			  (or (sll USI bnbit (const 9))
727883529b6Schristos			      (sll USI bzbit (const 8))))))
728883529b6Schristos	      (or (or (or (sll USI vbit (const 7))
729883529b6Schristos			  (sll USI cbit (const 6)))
730883529b6Schristos		      (or (sll USI nbit (const 5))
731883529b6Schristos			  (sll USI zbit (const 4))))
732883529b6Schristos		  (or (sll USI sflagbit (const 3))
733883529b6Schristos		      (sll USI (const 1) (const 0)))))) ;caibit
734883529b6Schristos	 ((eq index (const 0)) ; Config reg ?
735883529b6Schristos	  (or (or (or (or (or (or (sll USI timer0bit2 (const 6))
736883529b6Schristos				  (sll USI timer0bit3 (const 7)))
737883529b6Schristos			      (or (or (sll USI coreCfgResBit28 (const 28))
738883529b6Schristos				      (sll USI coreCfgResBit29 (const 29)))
739883529b6Schristos				  (or (sll USI coreCfgResBit30 (const 30))
740883529b6Schristos				      (sll USI coreCfgResBit31 (const 31)))))
741883529b6Schristos			  (or (or (sll USI coreCfgResBit24 (const 24))
742883529b6Schristos				  (sll USI coreCfgResBit25 (const 25)))
743883529b6Schristos			      (or (sll USI coreCfgResBit26 (const 26))
744883529b6Schristos				  (sll USI coreCfgResBit27 (const 27)))))
745883529b6Schristos		      (or (or (sll USI timer0bit0 (const 4))
746883529b6Schristos			      (sll USI timer0bit1 (const 5)))
747883529b6Schristos			  (or (sll USI coreCfgResBit14 (const 14))
748883529b6Schristos			      (sll USI coreCfgResBit15 (const 15)))))
749883529b6Schristos		  (or (or (or (or (sll USI timer1bit2 (const 10))
750883529b6Schristos				  (sll USI timer1bit3 (const 11)))
751883529b6Schristos			      (or (sll USI coreCfgResBit12 (const 12))
752883529b6Schristos				  (sll USI coreCfgResBit13 (const 13))))
753883529b6Schristos			  (or (sll USI clockGateEnbit (const 22))
754883529b6Schristos			      (sll USI mbkptEnbit (const 23))))
755883529b6Schristos		      (or (or (sll USI timer1bit0 (const 8))
756883529b6Schristos			      (sll USI timer1bit1 (const 9)))
757883529b6Schristos			  (or (sll USI coreCfgResBit20 (const 20))
758883529b6Schristos			      (sll USI coreCfgResBit21 (const 21))))))
759883529b6Schristos	      (or (or (sll USI invExcEnbit (const 1))
760883529b6Schristos		      (sll USI ovfExcEnbit (const 2)))
761883529b6Schristos		  (or (or (sll USI trmbit (const 0))
762883529b6Schristos			  (sll USI unExcEnbit (const 3)))
763883529b6Schristos		      (or (or (sll USI arithmetic-modebit0 (const 17))
764883529b6Schristos			      (sll USI arithmetic-modebit1 (const 18)))
765883529b6Schristos			  (or (sll USI arithmetic-modebit2 (const 19))
766883529b6Schristos			      (sll USI coreCfgResBit16 (const 16)))))))) ;config reg
767883529b6Schristos
768883529b6Schristos	 ((eq index (const 2)) (raw-reg USI h-pc)) ;PC reg
769883529b6Schristos
770883529b6Schristos	 (else (raw-reg USI h-core-registers index))))
771883529b6Schristos
772883529b6Schristos  (set (index val)
773883529b6Schristos       (cond VOID
774883529b6Schristos	 ((eq index (const 0)) ; CONFIG reg
775883529b6Schristos	  (sequence ()
776883529b6Schristos	    (set trmbit      (and (const 1) (srl val (const 0))))
777883529b6Schristos	    (set invExcEnbit (and (const 1) (srl val (const 1))))
778883529b6Schristos	    (set ovfExcEnbit (and (const 1) (srl val (const 2))))
779883529b6Schristos	    (set unExcEnbit  (and (const 1) (srl val (const 3))))
780883529b6Schristos	    (set timer0bit0  (and (const 1) (srl val (const 4))))
781883529b6Schristos	    (set timer0bit1  (and (const 1) (srl val (const 5))))
782883529b6Schristos	    (set timer0bit2  (and (const 1) (srl val (const 6))))
783883529b6Schristos	    (set timer0bit3  (and (const 1) (srl val (const 7))))
784883529b6Schristos	    (set timer1bit0  (and (const 1) (srl val (const 8))))
785883529b6Schristos	    (set timer1bit1  (and (const 1) (srl val (const 9))))
786883529b6Schristos	    (set timer1bit2  (and (const 1) (srl val (const 10))))
787883529b6Schristos	    (set timer1bit3  (and (const 1) (srl val (const 11))))
788883529b6Schristos
789883529b6Schristos	    (set coreCfgResBit12 (and (const 1) (srl val (const 12))))
790883529b6Schristos	    (set coreCfgResBit13 (and (const 1) (srl val (const 13))))
791883529b6Schristos	    (set coreCfgResBit14 (and (const 1) (srl val (const 14))))
792883529b6Schristos	    (set coreCfgResBit15 (and (const 1) (srl val (const 15))))
793883529b6Schristos	    (set coreCfgResBit16 (and (const 1) (srl val (const 16))))
794883529b6Schristos
795883529b6Schristos	    (set arithmetic-modebit0 (and (const 1) (srl val (const 17))))
796883529b6Schristos	    (set arithmetic-modebit1 (and (const 1) (srl val (const 18))))
797883529b6Schristos	    (set arithmetic-modebit2 (and (const 1) (srl val (const 19))))
798883529b6Schristos
799883529b6Schristos	    (set coreCfgResBit20 (and (const 1) (srl val (const 20))))
800883529b6Schristos	    (set coreCfgResBit21 (and (const 1) (srl val (const 21))))
801883529b6Schristos
802883529b6Schristos	    (set clockGateEnbit  (and (const 1) (srl val (const 22))))
803883529b6Schristos	    (set mbkptEnbit      (and (const 1) (srl val (const 23))))
804883529b6Schristos
805883529b6Schristos	    (set coreCfgResBit24 (and (const 1) (srl val (const 24))))
806883529b6Schristos	    (set coreCfgResBit25 (and (const 1) (srl val (const 25))))
807883529b6Schristos	    (set coreCfgResBit26 (and (const 1) (srl val (const 26))))
808883529b6Schristos	    (set coreCfgResBit27 (and (const 1) (srl val (const 27))))
809883529b6Schristos	    (set coreCfgResBit28 (and (const 1) (srl val (const 28))))
810883529b6Schristos	    (set coreCfgResBit29 (and (const 1) (srl val (const 29))))
811883529b6Schristos	    (set coreCfgResBit30 (and (const 1) (srl val (const 30))))
812883529b6Schristos	    (set coreCfgResBit31 (and (const 1) (srl val (const 31))))
813883529b6Schristos
814883529b6Schristos	    (set (raw-reg USI h-core-registers index) val)
815883529b6Schristos	    ;; check LSB of CONFIG for rounding mode
816883529b6Schristos	    (c-call "epiphany_set_rounding_mode" val)
817883529b6Schristos	  )
818883529b6Schristos	 )
819883529b6Schristos	 ((eq index (const 1))	;STATUS reg ; TODO check which bits can be set or clear
820883529b6Schristos	  (sequence ((USI newval))
821883529b6Schristos	    (set newval (and val (const #xfff2)))
822883529b6Schristos	    (set extFstallbit  (and (const 1) (srl newval (const 19))))
823883529b6Schristos	    (set expcause2bit  (and (const 1) (srl newval (const 18))))
824883529b6Schristos	    (set expcause1bit  (and (const 1) (srl newval (const 17))))
825883529b6Schristos	    (set expcause0bit  (and (const 1) (srl newval (const 16))))
826883529b6Schristos	    (set busbit (and (const 1) (srl newval (const 15))))
827883529b6Schristos	    (set bisbit (and (const 1) (srl newval (const 13))))
828883529b6Schristos	    (set bvsbit (and (const 1) (srl newval (const 14))))
829883529b6Schristos	    (set vsbit  (and (const 1) (srl newval (const 12))))
830883529b6Schristos	    (set bvbit  (and (const 1) (srl newval (const 10))))
831883529b6Schristos	    (set bcbit  (and (const 1) (srl newval (const 11))))
832883529b6Schristos	    (set bnbit  (and (const 1) (srl newval (const 9))))
833883529b6Schristos	    (set bzbit  (and (const 1) (srl newval (const 8))))
834883529b6Schristos	    (set vbit   (and (const 1) (srl newval (const 7))))
835883529b6Schristos	    (set cbit   (and (const 1) (srl newval (const 6))))
836883529b6Schristos	    (set nbit   (and (const 1) (srl newval (const 5))))
837883529b6Schristos	    (set zbit   (and (const 1) (srl newval (const 4))))
838883529b6Schristos	    (set sflagbit (and (const 1) (srl newval (const 3))))
839883529b6Schristos	    (set kmbit  (and (const 1) (srl newval (const 2))))
840883529b6Schristos	    ;;(set gie    (and (const 1) (srl newval (const 1))))
841883529b6Schristos	    (set (raw-reg SI h-core-registers (const 1)) newval)
842883529b6Schristos	   ))
843883529b6Schristos	 ;; causes simulator errors
844883529b6Schristos	 ;;	     ((eq index (const 2))	;PC reg
845883529b6Schristos	 ;;	      (set pc val))
846883529b6Schristos
847883529b6Schristos	 (else (set (raw-reg USI h-core-registers index) val))
848883529b6Schristos       ))
849883529b6Schristos)
850883529b6Schristos					; (define-pmacro (hcr-config) (reg h-core-registers 0)) etc.
851883529b6Schristos(.splice begin (.unsplice (.map
852883529b6Schristos			   (.pmacro (xname xnum)
853883529b6Schristos				    (define-pmacro ((.sym hcr- xname)) (reg h-core-registers xnum)))
854883529b6Schristos
855883529b6Schristos			   (
856883529b6Schristos			    config
857883529b6Schristos			    status
858883529b6Schristos			    pc
859883529b6Schristos			    debug
860883529b6Schristos			    iab
861883529b6Schristos			    lc
862883529b6Schristos			    ls
863883529b6Schristos			    le
864883529b6Schristos			    iret
865883529b6Schristos			    imask
866883529b6Schristos			    ilat
867883529b6Schristos			    ilatst
868883529b6Schristos			    ilatcl
869883529b6Schristos			    ipend
870883529b6Schristos			    ctimer0
871883529b6Schristos			    ctimer1
872883529b6Schristos			    hstatus
873883529b6Schristos
874883529b6Schristos
875883529b6Schristos
876883529b6Schristos			    )
877883529b6Schristos
878883529b6Schristos			   (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
879883529b6Schristos			      )
880883529b6Schristos			   )))
881883529b6Schristos
882883529b6Schristos
883883529b6Schristos
884883529b6Schristos;; DMA registers in MMR space
885883529b6Schristos(define-hardware
886883529b6Schristos  (name h-coredma-registers)
887883529b6Schristos  (comment "DMA registers in MMR space")
888883529b6Schristos  (type register USI (16))
889883529b6Schristos  (attrs)
890883529b6Schristos  (indices extern-keyword crdma-names)
891883529b6Schristos  )
892883529b6Schristos
893883529b6Schristos;; MEM registers in MMR space
894883529b6Schristos(define-hardware
895883529b6Schristos  (name h-coremem-registers)
896883529b6Schristos  (comment "MEM registers in MMR space")
897883529b6Schristos  (type register USI (4))
898883529b6Schristos  (attrs)
899883529b6Schristos  (indices extern-keyword crmem-names)
900883529b6Schristos  )
901883529b6Schristos
902883529b6Schristos;; MEM registers in MMR space
903883529b6Schristos(define-hardware
904883529b6Schristos  (name h-coremesh-registers)
905883529b6Schristos  (comment "MESH registers in MMR space")
906883529b6Schristos  (type register USI (4))
907883529b6Schristos  (attrs)
908883529b6Schristos  (indices extern-keyword crmesh-names)
909883529b6Schristos  )
910883529b6Schristos
911883529b6Schristos
912883529b6Schristos
913883529b6Schristos					; Operands
914883529b6Schristos
915883529b6Schristos					; Branch displacements
916883529b6Schristos(define-operand
917883529b6Schristos  (name simm24)
918883529b6Schristos  (comment "branch address pc-relative")
919883529b6Schristos  (attrs RELAX)
920883529b6Schristos  (type h-iaddr)
921883529b6Schristos  (index f-simm24)
922883529b6Schristos  (handlers (parse "branch_addr")))
923883529b6Schristos
924883529b6Schristos(define-operand
925883529b6Schristos  (name simm8)
926883529b6Schristos  (comment "branch address pc-relative")
927883529b6Schristos  (attrs RELAX)
928883529b6Schristos  (type h-iaddr)
929883529b6Schristos  (index f-simm8)
930883529b6Schristos  (handlers (parse "branch_addr")))
931883529b6Schristos
932883529b6Schristos
933883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
934883529b6Schristos					; Register operands
935883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
936883529b6Schristos
937883529b6Schristos(define-pmacro (short-regs nm group hw cmt)
938883529b6Schristos  (define-operand
939883529b6Schristos    (name nm)
940883529b6Schristos    (comment cmt)
941883529b6Schristos    (attrs)
942883529b6Schristos    (type hw)
943883529b6Schristos    (index (.sym "f-r" group))
944883529b6Schristos    (handlers (parse "shortregs") (print "keyword"))
945883529b6Schristos    )
946883529b6Schristos  )
947883529b6Schristos
948883529b6Schristos(define-pmacro (short-regs-core nm group hw cmt)
949883529b6Schristos  (define-operand
950883529b6Schristos    (name nm)
951883529b6Schristos    (comment cmt)
952883529b6Schristos    (attrs)
953883529b6Schristos    (type hw)
954883529b6Schristos    (index (.sym "f-s" group))
955883529b6Schristos    (handlers (parse "shortregs") (print "keyword"))
956883529b6Schristos    )
957883529b6Schristos  )
958883529b6Schristos
959883529b6Schristos
960883529b6Schristos					; short regs (0-7)
961883529b6Schristos(short-regs rd d h-registers "destination register")
962883529b6Schristos(short-regs rn n h-registers "source register")
963883529b6Schristos(short-regs rm m h-registers "source register")
964883529b6Schristos
965883529b6Schristos(short-regs frd d h-fpregisters "fp destination register")
966883529b6Schristos(short-regs frn n h-fpregisters "fp source register")
967883529b6Schristos(short-regs frm m h-fpregisters "fp source register")
968883529b6Schristos
969883529b6Schristos					; long regs (0-63)
970883529b6Schristos(dnop rd6 "destination register" () h-registers f-rd6)
971883529b6Schristos(dnop rn6 "source register"      () h-registers f-rn6)
972883529b6Schristos(dnop rm6 "source register"      () h-registers f-rm6)
973883529b6Schristos
974883529b6Schristos(dnop frd6 "fp destination register" () h-fpregisters f-rd6)
975883529b6Schristos(dnop frn6 "fp source register"      () h-fpregisters f-rn6)
976883529b6Schristos(dnop frm6 "fp source register"      () h-fpregisters f-rm6)
977883529b6Schristos
978883529b6Schristos					; special regs (0-7)
979883529b6Schristos(short-regs-core sd d h-core-registers "special destination")
980883529b6Schristos(short-regs-core sn n h-core-registers "special source")
981883529b6Schristos
982883529b6Schristos					; special regs (long form)
983883529b6Schristos(dnop sd6 "special destination register" () h-core-registers f-sd6)
984883529b6Schristos(dnop sn6 "special source register"      () h-core-registers f-sn6)
985883529b6Schristos
986883529b6Schristos(dnop sddma "dma register" () h-coredma-registers f-sd6)
987883529b6Schristos(dnop sndma "dma register"      () h-coredma-registers f-sn6)
988883529b6Schristos(dnop sdmem "mem register" () h-coremem-registers f-sd6)
989883529b6Schristos(dnop snmem "mem register"      () h-coremem-registers f-sn6)
990883529b6Schristos(dnop sdmesh "mesh register" () h-coremesh-registers f-sd6)
991883529b6Schristos(dnop snmesh "mesh register"      () h-coremesh-registers f-sn6)
992883529b6Schristos
993883529b6Schristos					; Immediate literals - but don't allow register names!
994883529b6Schristos(define-pmacro (dimmop nm cmt hwtype idx)
995883529b6Schristos  (define-operand (name nm) (comment cmt) (type hwtype) (index idx)
996883529b6Schristos    (attrs RELAX)
997883529b6Schristos    (handlers (parse "simm_not_reg")
998883529b6Schristos	      (print "simm_not_reg")))
999883529b6Schristos  )
1000883529b6Schristos
1001883529b6Schristos(dimmop simm3   "signed 3-bit literal"    h-sint f-sdisp3)
1002883529b6Schristos(dimmop simm11  "signed 11-bit literal"   h-sint f-sdisp11)
1003883529b6Schristos(dnop disp3  "short data displacement"   () h-uint f-disp3)
1004883529b6Schristos(dnop trapnum6 "parameter for swi or trap" () h-uint f-trap-num)
1005883529b6Schristos
1006883529b6Schristos(define-pmacro (duimmop nm cmt hwtype idx)
1007883529b6Schristos  (define-operand (name nm) (comment cmt) (type hwtype) (index idx)
1008883529b6Schristos    (attrs)
1009883529b6Schristos    (handlers (parse "uimm_not_reg")
1010883529b6Schristos	      (print "uimm_not_reg")))
1011883529b6Schristos  )
1012883529b6Schristos
1013883529b6Schristos(duimmop swi_num "unsigned 6-bit swi#" h-uint f-trap-num)
1014883529b6Schristos(duimmop disp11 "sign-magnitude data displacement" h-uint f-disp11)
1015883529b6Schristos
1016883529b6Schristos(dnop shift   "immediate shift amount"   () h-uint f-shift)
1017883529b6Schristos
1018883529b6Schristos(define-operand (name imm16) (comment "16-bit unsigned literal") (attrs RELAX)
1019883529b6Schristos  (type h-addr) (index f-imm16) (handlers (parse "imm16")))
1020883529b6Schristos(define-operand (name imm8) (comment "8-bit unsigned literal") (attrs RELAX)
1021883529b6Schristos  (type h-addr) (index f-imm8) (handlers (parse "imm8")))
1022883529b6Schristos
1023883529b6Schristos(define-operand
1024883529b6Schristos  (name direction)
1025883529b6Schristos  (comment "+/- indexing")
1026883529b6Schristos  (attrs)
1027883529b6Schristos  (type h-uint)
1028883529b6Schristos  (index f-addsubx)
1029883529b6Schristos  (handlers (parse "postindex")
1030883529b6Schristos	    (print "postindex")))
1031883529b6Schristos
1032883529b6Schristos(define-operand
1033883529b6Schristos  (name dpmi)
1034883529b6Schristos  (comment "+/- magnitude immediate displacement")
1035883529b6Schristos  (attrs)
1036883529b6Schristos  (type h-uint)
1037883529b6Schristos  (index f-subd)
1038883529b6Schristos  (handlers (parse "postindex")
1039883529b6Schristos	    (print "postindex")))
1040883529b6Schristos
1041883529b6Schristos
1042883529b6Schristos
1043883529b6Schristos;; call exception macro - no check for imask
1044883529b6Schristos(define-pmacro (call-exception vaddr bit-in-ilat)
1045883529b6Schristos  (if (eq gidisablebit 0)
1046883529b6Schristos      (if (eq (and (hcr-imask) bit-in-ilat) 0)
1047883529b6Schristos	  (sequence ()
1048883529b6Schristos		    (set kmbit 1)
1049883529b6Schristos		    (set gidisablebit 1)
1050883529b6Schristos		    (set (hcr-iret) (add pc (const 2)))
1051883529b6Schristos		    (set (hcr-ipend) (or (hcr-ipend) (const bit-in-ilat)))
1052883529b6Schristos		    (set pc (const vaddr))
1053883529b6Schristos
1054883529b6Schristos		    )
1055883529b6Schristos	  ;; schedule interrupt
1056883529b6Schristos	  (set (hcr-ilat) (or (hcr-ilat) (const  bit-in-ilat)))
1057883529b6Schristos	  )
1058883529b6Schristos      )
1059883529b6Schristos  )
1060883529b6Schristos
1061883529b6Schristos
1062883529b6Schristos;;      (lc             5);loop counter            Not impemented
1063883529b6Schristos;;       (ls             6);loop start address      Not impemented
1064883529b6Schristos;;       (le             7);loop end address        Not impemented
1065883529b6Schristos
1066883529b6Schristos;;have callback to adjust pc in case od events ( HW loops ... )
1067883529b6Schristos(define-pmacro (dni_wrapper isnid stdrdesc attr_ strassembl iopcode proceed null_b)
1068883529b6Schristos  (begin
1069883529b6Schristos    (dni isnid stdrdesc attr_ strassembl iopcode
1070883529b6Schristos	 (sequence () proceed
1071883529b6Schristos		   (sequence ((USI tmpPC))
1072883529b6Schristos			     ;;(set tmpPC  (c-call  USI "epiphany_post_isn_callback" pc))
1073883529b6Schristos
1074883529b6Schristos			     (if (eq pc (hcr-le))
1075883529b6Schristos				 (set (hcr-lc) (sub (hcr-lc) #x1)))
1076883529b6Schristos			     (if (and
1077883529b6Schristos				   (eq pc (hcr-le))
1078883529b6Schristos				   (not (eq (hcr-lc) #x0)))
1079883529b6Schristos				 (set pc (hcr-ls)))
1080883529b6Schristos			     )
1081883529b6Schristos		   )
1082883529b6Schristos	 null_b)
1083883529b6Schristos    )
1084883529b6Schristos  )
1085883529b6Schristos
1086883529b6Schristos
1087883529b6Schristos
1088883529b6Schristos
1089883529b6Schristos
1090883529b6Schristos;; Some handy macros
1091883529b6Schristos;;
1092883529b6Schristos
1093883529b6Schristos;; define instructions
1094883529b6Schristos;;   Short (16 bit forms) must appear first so that instruction
1095883529b6Schristos;;   selection can reject them and match long forms when registers
1096883529b6Schristos;;   or immediates exceed the values in the 16 bit instructions
1097883529b6Schristos
1098883529b6Schristos
1099883529b6Schristos;; B<COND> SIMM8
1100883529b6Schristos;; B<COND> SIMM24
1101883529b6Schristos
1102883529b6Schristos(define-pmacro (br-insn name cond g-op)
1103883529b6Schristos  (begin
1104883529b6Schristos					; the 16-bit versions of branch
1105883529b6Schristos    (dni (.sym "b" name "16")
1106883529b6Schristos	 (.str "Conditional Branch - 16 bit" name)
1107883529b6Schristos	 (COND-CTI SHORT-INSN)
1108883529b6Schristos	 (.str "b" name ".s $simm8")
1109883529b6Schristos	 (+ OP4_BRANCH16 (.sym "OPC_" cond) simm8)
1110883529b6Schristos	 (if (g-op)
1111883529b6Schristos	     (set pc simm8)
1112883529b6Schristos	     )
1113883529b6Schristos	 ()
1114883529b6Schristos	 )
1115883529b6Schristos
1116883529b6Schristos    (dnmi (.sym "b" name "16r") "relaxable conditional branch"
1117883529b6Schristos	  (COND-CTI RELAXABLE)
1118883529b6Schristos	  (.str "b" name " $simm8")
1119883529b6Schristos	  (emit (.sym "b" name "16") simm8)
1120883529b6Schristos	  )
1121883529b6Schristos
1122883529b6Schristos    (dni (.sym "b" name)
1123883529b6Schristos	 (.str "Conditional Branch " name)
1124883529b6Schristos	 (COND-CTI)
1125883529b6Schristos	 (.str "b" name ".l $simm24")
1126883529b6Schristos	 (+ OP4_BRANCH (.sym "OPC_" cond) simm24)
1127883529b6Schristos	 (if (g-op)
1128883529b6Schristos	     (set pc simm24)
1129883529b6Schristos	     )
1130883529b6Schristos	 ()
1131883529b6Schristos	 )
1132883529b6Schristos
1133883529b6Schristos    (dnmi (.sym "b" name "32r") "relaxable conditional branch"
1134883529b6Schristos	  (COND-CTI RELAXED)
1135883529b6Schristos	  (.str "b" name " $simm24")
1136883529b6Schristos	  (emit (.sym "b" name) simm24)
1137883529b6Schristos	  )
1138883529b6Schristos    )
1139883529b6Schristos  )
1140883529b6Schristos
1141883529b6Schristos
1142883529b6Schristos					; basic conditional branches for integer arithmetic
1143883529b6Schristos(br-insn "eq"	 EQ	(.pmacro () (eq zbit #x1)))
1144883529b6Schristos(br-insn "ne"	 NE	(.pmacro () (eq zbit #x0)))
1145883529b6Schristos(br-insn "gtu"   GTU	(.pmacro () (and BI cbit (not BI zbit))))
1146883529b6Schristos(br-insn "gteu"  GTEU	(.pmacro () (eq cbit #x1)))
1147883529b6Schristos(br-insn "lteu"  LTEU	(.pmacro () (or BI (not BI cbit) zbit)))
1148883529b6Schristos(br-insn "ltu"   LTU	(.pmacro () (eq cbit #x0)))
1149883529b6Schristos(br-insn "gt"	 GT	(.pmacro () (and BI (not BI zbit) (eq vbit nbit))))
1150883529b6Schristos(br-insn "gte"   GTE	(.pmacro () (eq vbit nbit)))
1151883529b6Schristos(br-insn "lt"	 LT	(.pmacro () (xor BI vbit nbit)))
1152883529b6Schristos(br-insn "lte"   LTE	(.pmacro () (or BI zbit (xor vbit nbit))))
1153883529b6Schristos
1154883529b6Schristos
1155883529b6Schristos					; floating point condition codes (floating point instructions)
1156883529b6Schristos(br-insn "beq"   BEQ    (.pmacro () (or BI bzbit bzbit)))
1157883529b6Schristos(br-insn "bne"   BNE    (.pmacro () (not BI bzbit)))
1158883529b6Schristos(br-insn "blt"   BLT    (.pmacro () (and BI bnbit (not bzbit))))
1159883529b6Schristos(br-insn "blte"  BLTE   (.pmacro () (or BI bnbit bzbit)))
1160883529b6Schristos
1161883529b6Schristos					; unconditional branches
1162883529b6Schristos(dni b16 "short unconditional branch" (UNCOND-CTI SHORT-INSN)
1163883529b6Schristos     "b.s $simm8"
1164883529b6Schristos     (+ OP4_BRANCH16 OPC_B simm8)
1165883529b6Schristos     (set pc simm8)
1166883529b6Schristos     ()
1167883529b6Schristos     )
1168883529b6Schristos
1169883529b6Schristos(dnmi b16r "relaxable b16"
1170883529b6Schristos      (UNCOND-CTI RELAXABLE)
1171883529b6Schristos      "b $simm8"
1172883529b6Schristos      (emit b16 simm8)
1173883529b6Schristos      )
1174883529b6Schristos
1175883529b6Schristos(dni b "long unconditional branch" (UNCOND-CTI)
1176883529b6Schristos     "b.l $simm24"
1177883529b6Schristos     (+ OP4_BRANCH OPC_B simm24)
1178883529b6Schristos     (set pc simm24)
1179883529b6Schristos     ()
1180883529b6Schristos     )
1181883529b6Schristos
1182883529b6Schristos(dnmi b32r "relaxable b"
1183883529b6Schristos      (UNCOND-CTI RELAXED)
1184883529b6Schristos      "b $simm24"
1185883529b6Schristos      (emit b simm24))
1186883529b6Schristos
1187883529b6Schristos;; BL R,ADDR
1188883529b6Schristos
1189883529b6Schristos(dni bl16 "branch and link"
1190883529b6Schristos     (UNCOND-CTI SHORT-INSN)
1191883529b6Schristos     ("bl.s $simm8")
1192883529b6Schristos     (+ OP4_BRANCH16 OPC_BL simm8)
1193883529b6Schristos     (sequence ()
1194883529b6Schristos	       (set (reg h-registers 14) (add pc (const 2)))
1195883529b6Schristos	       (set pc simm8))
1196883529b6Schristos     ()
1197883529b6Schristos     )
1198883529b6Schristos
1199883529b6Schristos(dnmi bl16r "bl16 relaxable"
1200883529b6Schristos      (UNCOND-CTI RELAXABLE)
1201883529b6Schristos      "bl $simm8"
1202883529b6Schristos      (emit bl16 simm8))
1203883529b6Schristos
1204883529b6Schristos(dni bl "branch and link"
1205883529b6Schristos     (UNCOND-CTI)
1206883529b6Schristos     ("bl.l $simm24")
1207883529b6Schristos     (+ OP4_BRANCH OPC_BL simm24)
1208883529b6Schristos     (sequence ()
1209883529b6Schristos	       (set (reg h-registers 14) (add pc (const 4)))
1210883529b6Schristos	       (set pc simm24))
1211883529b6Schristos     ()
1212883529b6Schristos     )
1213883529b6Schristos
1214883529b6Schristos(dnmi blr "bl relaxable"
1215883529b6Schristos      (UNCOND-CTI RELAXED)
1216883529b6Schristos      "bl $simm24"
1217883529b6Schristos      (emit bl simm24))
1218883529b6Schristos
1219883529b6Schristos;; JUMP <RN>
1220883529b6Schristos(dni jr16 "unconditional jump 16"
1221883529b6Schristos     (UNCOND-CTI SHORT-INSN)
1222883529b6Schristos     ("jr $rn")
1223883529b6Schristos     (+ OP4_FLOW16 (f-opc-8-5 #x14) (f-dc-15-3 #x0) (f-dc-9-1 #x0) rn)
1224883529b6Schristos     (set pc rn)
1225883529b6Schristos     ()
1226883529b6Schristos     )
1227883529b6Schristos
1228883529b6Schristos;; RTS / JR
1229883529b6Schristos;; ??? Putting a constant into a multi-ifield does not work -
1230883529b6Schristos;; the constant gets inserted in full into each part.
1231883529b6Schristos					;(dnmi rts "return from subroutine"
1232883529b6Schristos					;     (UNCOND-CTI)
1233883529b6Schristos					;     ("rts")
1234883529b6Schristos					;     (emit jr (rn6 14)) ; jr lr  / jr r14
1235883529b6Schristos					;)
1236883529b6Schristos;; RTS / JR
1237883529b6Schristos(dni rts "return from subroutine"
1238883529b6Schristos     (ALIAS UNCOND-CTI)
1239883529b6Schristos     ("rts")
1240883529b6Schristos     (+ OP4_MISC (f-opc-8-5 #x14) (f-opc-19-4 #x2) (f-rn 6) (f-rn-x 1)
1241883529b6Schristos	(f-dc-9-1 #x0)
1242883529b6Schristos	(f-dc-15-3 #x0)
1243883529b6Schristos	(f-dc-25-6 #x0)
1244883529b6Schristos	(f-dc-31-3 #x0)
1245883529b6Schristos	)
1246883529b6Schristos     (set pc (reg h-registers 14))
1247883529b6Schristos     ()
1248883529b6Schristos     )
1249883529b6Schristos
1250883529b6Schristos(dni jr "unconditional jump"
1251883529b6Schristos     (UNCOND-CTI)
1252883529b6Schristos     ("jr $rn6")
1253883529b6Schristos     (+ OP4_MISC (f-opc-8-5 #x14) (f-opc-19-4 #x2) rn6
1254883529b6Schristos	(f-dc-9-1 #x0)
1255883529b6Schristos	(f-dc-15-3 #x0)
1256883529b6Schristos	(f-dc-25-6 #x0)
1257883529b6Schristos	(f-dc-31-3 #x0)
1258883529b6Schristos	)
1259883529b6Schristos     (set pc rn6)
1260883529b6Schristos     ()
1261883529b6Schristos     )
1262883529b6Schristos
1263883529b6Schristos
1264883529b6Schristos;; JALR <RN>
1265883529b6Schristos(dni jalr16 "jump and link register"
1266883529b6Schristos     (UNCOND-CTI SHORT-INSN)
1267883529b6Schristos     ("jalr $rn")
1268883529b6Schristos     (+ OP4_FLOW16  (f-opc-8-5 #x15) (f-dc-15-3 #x0) (f-dc-9-1 #x0)  rn)
1269883529b6Schristos     (sequence ()
1270883529b6Schristos	       (set (reg h-registers 14) (add pc (const 2)))
1271883529b6Schristos	       (set pc rn)
1272883529b6Schristos	       )
1273883529b6Schristos     ()
1274883529b6Schristos     )
1275883529b6Schristos
1276883529b6Schristos(dni jalr "jump and link register"
1277883529b6Schristos     (UNCOND-CTI)
1278883529b6Schristos     ("jalr $rn6")
1279883529b6Schristos     (+ OP4_MISC
1280883529b6Schristos	(f-opc-8-5 #x15)
1281883529b6Schristos	(f-opc-19-4 #x2)
1282883529b6Schristos	rn6
1283883529b6Schristos	(f-dc-9-1 #x0)
1284883529b6Schristos	(f-dc-15-3 #x0)
1285883529b6Schristos	(f-dc-25-6 #x0)
1286883529b6Schristos	(f-dc-31-3 #x0)
1287883529b6Schristos
1288883529b6Schristos	)
1289883529b6Schristos     (sequence ()
1290883529b6Schristos	       (set (reg h-registers 14) (add pc (const 4)))
1291883529b6Schristos	       (set pc rn6))
1292883529b6Schristos     ()
1293883529b6Schristos     )
1294883529b6Schristos
1295883529b6Schristos
1296883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1297883529b6Schristos					;  Load/Store Memory Instructions
1298883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1299883529b6Schristos
1300883529b6Schristos
1301883529b6Schristos(define-pmacro (callMisaligmentExceptionIfNeeded sel  addr isAligmentAccess)
1302883529b6Schristos  (sequence ((BI scale))
1303883529b6Schristos    (set isAligmentAccess
1304883529b6Schristos	 (case BI sel
1305883529b6Schristos	   ((OPW_BYTE)	(eq (and addr #x0) #x0))
1306883529b6Schristos	   ((OPW_SHORT)	(eq (and addr #x1) #x0))
1307883529b6Schristos	   ((OPW_WORD)	(eq (and addr #x3) #x0))
1308883529b6Schristos	   (else	(eq (and addr #x7) #x0))))
1309883529b6Schristos    (if (not BI isAligmentAccess)
1310883529b6Schristos	(call-exception #x4 #x2))
1311883529b6Schristos  )
1312883529b6Schristos)
1313883529b6Schristos
1314883529b6Schristos
1315883529b6Schristos
1316883529b6Schristos;; helper to convert size selector OPW_<mode> into a literal scale factor
1317883529b6Schristos(define-pmacro (ConvertSelectorToShift sel scale)
1318883529b6Schristos  (set scale
1319883529b6Schristos       (case SI sel
1320883529b6Schristos	 ((OPW_BYTE)	(const 0))
1321883529b6Schristos	 ((OPW_SHORT)	(const 1))
1322883529b6Schristos	 ((OPW_WORD)	(const 2))
1323883529b6Schristos	 (else	(const 3))))
1324883529b6Schristos)
1325883529b6Schristos
1326883529b6Schristos;; common load macros from effective address, handling 8/16/32/64 bits
1327883529b6Schristos(define-pmacro (load-double-from-ea regnum eff-addr mode sel)
1328883529b6Schristos  (sequence ((SI loadaddr) (BI isAligmentAccess))
1329883529b6Schristos	    (set loadaddr eff-addr)
1330883529b6Schristos	    (callMisaligmentExceptionIfNeeded sel  loadaddr isAligmentAccess)
1331883529b6Schristos
1332883529b6Schristos	    (if (not (not BI isAligmentAccess))
1333883529b6Schristos		(sequence ()
1334883529b6Schristos			  (set memaddr loadaddr)
1335883529b6Schristos			  (set regnum (mem SI loadaddr))
1336883529b6Schristos			  (set loadaddr (add loadaddr (const 4)))
1337883529b6Schristos			  (set memaddr loadaddr)
1338883529b6Schristos			  (set (reg h-registers
1339883529b6Schristos				    (add (index-of regnum)
1340883529b6Schristos					 (const 1)))
1341883529b6Schristos			       (mem SI loadaddr))
1342883529b6Schristos
1343883529b6Schristos			  )
1344883529b6Schristos		)
1345883529b6Schristos	    )
1346883529b6Schristos  )
1347883529b6Schristos
1348883529b6Schristos(define-pmacro (load-from-ea regnum eff-addr mode sel)
1349883529b6Schristos  (sequence ((BI isAligmentAccess))
1350883529b6Schristos
1351883529b6Schristos	    (callMisaligmentExceptionIfNeeded sel eff-addr   isAligmentAccess)
1352883529b6Schristos	    (if (not (not BI isAligmentAccess))
1353883529b6Schristos		(sequence ()
1354883529b6Schristos			  (set memaddr eff-addr)
1355883529b6Schristos			  (set regnum (zext SI (mem mode eff-addr)))
1356883529b6Schristos			  )
1357883529b6Schristos		)
1358883529b6Schristos	    )
1359883529b6Schristos  ) ;; 8/16/32 bit cases
1360883529b6Schristos
1361883529b6Schristos
1362883529b6Schristos;; common store to effective address, handling 8/16/32/64 bit data
1363883529b6Schristos(define-pmacro (store-double-to-ea eff-addr regnum mode sel)
1364883529b6Schristos  (sequence ((SI storeaddr) (BI isAligmentAccess))
1365883529b6Schristos	    (set storeaddr eff-addr)
1366883529b6Schristos	    (callMisaligmentExceptionIfNeeded sel storeaddr isAligmentAccess)
1367883529b6Schristos	    (if (not (not BI isAligmentAccess))
1368883529b6Schristos		(sequence ()
1369883529b6Schristos			  (set memaddr storeaddr)
1370883529b6Schristos			  (set (mem SI storeaddr) regnum)
1371883529b6Schristos			  (set storeaddr (add storeaddr (const 4)))
1372883529b6Schristos			  (set memaddr storeaddr)
1373883529b6Schristos			  (set (mem SI storeaddr)
1374883529b6Schristos			       (reg h-registers (add (index-of regnum) (const 1))))
1375883529b6Schristos			  )
1376883529b6Schristos		)
1377883529b6Schristos	    )
1378883529b6Schristos  )
1379883529b6Schristos
1380883529b6Schristos(define-pmacro (store-to-ea eff-addr regnum mode sel)
1381883529b6Schristos  (sequence ((BI isAligmentAccess))
1382883529b6Schristos	    (callMisaligmentExceptionIfNeeded sel eff-addr   isAligmentAccess)
1383883529b6Schristos	    (if (not (not BI isAligmentAccess))
1384883529b6Schristos		(sequence ()
1385883529b6Schristos			  (set memaddr eff-addr)
1386883529b6Schristos			  (set (mem mode eff-addr) regnum)
1387883529b6Schristos			  )
1388883529b6Schristos		)
1389883529b6Schristos	    )
1390883529b6Schristos  )	;8/16/32 bit cases
1391883529b6Schristos
1392883529b6Schristos
1393883529b6Schristos(define-pmacro (load-insn name mode sel sem-op)
1394883529b6Schristos  (begin
1395883529b6Schristos    (dni_wrapper (.sym name "x16.s")
1396883529b6Schristos		 (.str "load " mode " indexed")
1397883529b6Schristos		 (SHORT-INSN)
1398883529b6Schristos		 (.str name " $rd,[$rn,$rm]")
1399883529b6Schristos		 (+ OP4_LDSTR16X sel OP_LOAD rd rn rm)
1400883529b6Schristos		 (sequence ()
1401883529b6Schristos			   (sem-op rd (add rn rm) mode sel))
1402883529b6Schristos		 ()
1403883529b6Schristos		 )
1404883529b6Schristos
1405883529b6Schristos
1406883529b6Schristos    (dni_wrapper (.sym name "p16.s")
1407883529b6Schristos		 (.str "load " mode " postmodify")
1408883529b6Schristos		 (SHORT-INSN)
1409883529b6Schristos		 (.str name " $rd,[$rn],$rm")
1410883529b6Schristos		 (+ OP4_LDSTR16P sel OP_LOAD rd rn rm)
1411883529b6Schristos		 (sequence ((SI tmprm))
1412883529b6Schristos			   (set tmprm rm)
1413883529b6Schristos			   (sem-op rd rn mode sel)
1414883529b6Schristos			   (set rn (add rn tmprm)))
1415883529b6Schristos		 ()
1416883529b6Schristos		 )
1417883529b6Schristos
1418883529b6Schristos
1419883529b6Schristos    (dni_wrapper (.sym name "x.l")
1420883529b6Schristos		 (.str "load " mode " indexed")
1421883529b6Schristos		 ()
1422883529b6Schristos		 (.str name " $rd6,[$rn6,$direction$rm6]")
1423883529b6Schristos		 (+ OP4_LDSTRX sel OP_LOAD (f-opc-19-4 #x0) (f-dc-22-1 #x0) (f-dc-21-1 #x0) rd6 rn6 direction rm6)
1424883529b6Schristos		 (sequence ()
1425883529b6Schristos			   (if (ifield f-addsubx)
1426883529b6Schristos			       (sem-op rd6 (sub rn6 rm6) mode sel)
1427883529b6Schristos			       (sem-op rd6 (add rn6 rm6) mode sel)))
1428883529b6Schristos		 ()
1429883529b6Schristos		 )
1430883529b6Schristos
1431883529b6Schristos    (dnmi (.sym name "x")
1432883529b6Schristos	  (.str "load " mode " indexed")
14339573673dSchristos	  (NO-DIS)
1434883529b6Schristos	  (.str name ".l $rd6,[$rn6,$direction$rm6]")
1435883529b6Schristos	  (emit  (.sym name "x.l") rd6 rn6 direction rm6)
1436883529b6Schristos	  )
1437883529b6Schristos
1438883529b6Schristos
1439883529b6Schristos
1440883529b6Schristos    (dni_wrapper (.sym name "p.l")
1441883529b6Schristos		 (.str "load " mode " postmodify")
1442883529b6Schristos		 ()
1443883529b6Schristos		 (.str name " $rd6,[$rn6],$direction$rm6")
1444883529b6Schristos		 (+ OP4_LDSTRP sel OP_LOAD (f-opc-19-4 #x0) (f-dc-22-2 #x0) rd6 rn6 direction rm6)
1445883529b6Schristos		 (sequence ((SI tmprm))
1446883529b6Schristos			   (set tmprm rm6)
1447883529b6Schristos			   (sem-op rd6 rn6 mode sel)
1448883529b6Schristos			   (if (ifield f-addsubx)
1449883529b6Schristos			       (set rn6 (sub rn6 tmprm))
1450883529b6Schristos			       (set rn6 (add rn6 tmprm)))
1451883529b6Schristos			   )
1452883529b6Schristos		 ()
1453883529b6Schristos		 )
1454883529b6Schristos
1455883529b6Schristos
1456883529b6Schristos    (dnmi (.sym name "p")
1457883529b6Schristos	  (.str "load " mode " postmodify")
14589573673dSchristos	  (NO-DIS)
1459883529b6Schristos	  (.str name ".l $rd6,[$rn6],$direction$rm6")
1460883529b6Schristos	  (emit  (.sym name "p.l") rd6 rn6 direction rm6)
1461883529b6Schristos	  )
1462883529b6Schristos
1463883529b6Schristos
1464883529b6Schristos    ;;immediate modes last so reg forms found first.
1465883529b6Schristos    (dni_wrapper (.sym name "d16.s")
1466883529b6Schristos		 (.str "load " mode " displacement")
1467883529b6Schristos		 (SHORT-INSN IMM3)
1468883529b6Schristos		 (.str name " $rd,[$rn,$disp3]")
1469883529b6Schristos		 (+ OP4_LDSTR16D sel OP_LOAD rd rn disp3) ;; convert size to 'B'
1470883529b6Schristos		 (sequence ((SI effa)
1471883529b6Schristos			    (SI scale))
1472883529b6Schristos			   (ConvertSelectorToShift sel scale)
1473883529b6Schristos			   (set effa (add rn (sll disp3 scale)))
1474883529b6Schristos			   (sem-op rd effa mode sel)
1475883529b6Schristos			   )
1476883529b6Schristos		 ()
1477883529b6Schristos		 )
1478883529b6Schristos
1479883529b6Schristos
1480883529b6Schristos    (dni_wrapper (.sym name "d.l")
1481883529b6Schristos		 (.str "load " mode " displacement")
1482883529b6Schristos		 ()
1483883529b6Schristos		 (.str name " $rd6,[$rn6,$dpmi$disp11]")
1484883529b6Schristos		 (+ OP4_LDSTRD sel OP_LOAD PMOD_DISP rd6 rn6 dpmi disp11)
1485883529b6Schristos		 (sequence ((SI effa)
1486883529b6Schristos			    (SI scale))
1487883529b6Schristos			   (ConvertSelectorToShift sel scale)
1488883529b6Schristos			   (if dpmi
1489883529b6Schristos			       (set effa (sub rn6 (sll disp11 scale)))
1490883529b6Schristos			       (set effa (add rn6 (sll disp11 scale)))
1491883529b6Schristos			       )
1492883529b6Schristos			   (sem-op rd6 effa mode sel)
1493883529b6Schristos			   )
1494883529b6Schristos		 ()
1495883529b6Schristos		 )
1496883529b6Schristos
1497883529b6Schristos    (dnmi (.sym name "d")
1498883529b6Schristos	  (.str "load " mode " displacement")
14999573673dSchristos	  (NO-DIS)
1500883529b6Schristos	  (.str name ".l $rd6,[$rn6,$dpmi$disp11]")
1501883529b6Schristos	  (emit  (.sym name "d.l") rd6 rn6  dpmi disp11)
1502883529b6Schristos	  )
1503883529b6Schristos
1504883529b6Schristos
1505883529b6Schristos
1506883529b6Schristos    (dni_wrapper (.sym name "dpm.l")
1507883529b6Schristos		 (.str "load " mode " displacement post-modify")
1508883529b6Schristos		 ()
1509883529b6Schristos		 (.str name " $rd6,[$rn6],$dpmi$disp11")
1510883529b6Schristos		 (+ OP4_LDSTRD sel OP_LOAD PMOD_POST rd6 rn6 dpmi disp11)
1511883529b6Schristos		 (sequence ((SI scale))
1512883529b6Schristos			   (ConvertSelectorToShift sel scale)
1513883529b6Schristos			   (sem-op rd6 rn6 mode sel)
1514883529b6Schristos			   (if dpmi
1515883529b6Schristos			       (set rn6 (sub rn6 (sll disp11 scale)))
1516883529b6Schristos			       (set rn6 (add rn6 (sll disp11 scale)))
1517883529b6Schristos			       )
1518883529b6Schristos			   )
1519883529b6Schristos		 ()
1520883529b6Schristos		 )
1521883529b6Schristos
1522883529b6Schristos    (dnmi (.sym name "dpm")
1523883529b6Schristos	  (.str "load " mode " displacement post-modify")
15249573673dSchristos	  (NO-DIS)
1525883529b6Schristos	  (.str name ".l $rd6,[$rn6],$dpmi$disp11")
1526883529b6Schristos	  (emit  (.sym name "dpm.l") rd6 rn6  dpmi disp11)
1527883529b6Schristos	  )
1528883529b6Schristos
1529883529b6Schristos
1530883529b6Schristos    ;; ;; macro form with a zero displacement
1531883529b6Schristos    (dnmi (.sym name "ds0") "load with 0 disp"
1532883529b6Schristos	  (SHORT-INSN IMM3)
1533883529b6Schristos	  (.str name " $rd,[$rn]")
1534883529b6Schristos	  (emit (.sym name "d16.s") rd rn (disp3 0))
1535883529b6Schristos	  )
1536883529b6Schristos    (dnmi (.sym name "dl0") "load with 0 disp"
15379573673dSchristos    	  (NO-DIS)
1538883529b6Schristos	  (.str name " $rd6,[$rn6]")
1539883529b6Schristos	  (emit (.sym name "d.l") rd6 rn6 (dpmi 0) (disp11 0))
1540883529b6Schristos	  )
1541883529b6Schristos    (dnmi (.sym name "dl0.l") "load with 0 disp"
15429573673dSchristos    	  (NO-DIS)
1543883529b6Schristos	  (.str name ".l $rd6,[$rn6]")
1544883529b6Schristos	  (emit (.sym name "d.l") rd6 rn6 (dpmi 0) (disp11 0))
1545883529b6Schristos	  )
1546883529b6Schristos
1547883529b6Schristos
1548883529b6Schristos    )
1549883529b6Schristos  )
1550883529b6Schristos
1551883529b6Schristos(load-insn ldrb QI OPW_BYTE load-from-ea)
1552883529b6Schristos(load-insn ldrh HI OPW_SHORT load-from-ea)
1553883529b6Schristos(load-insn ldr  SI OPW_WORD  load-from-ea)
1554883529b6Schristos(load-insn ldrd DI OPW_DOUBLE load-double-from-ea)
1555883529b6Schristos
1556883529b6Schristos
1557883529b6Schristos
1558883529b6Schristos
1559883529b6Schristos;; TMP = MEM[RD+RM];    /* Copy content of memory to tmp.  */
1560883529b6Schristos;; if (~TMP)            /* Check if memory location is zero.  */
1561883529b6Schristos;;   MEM[RD+RM] = RD;   /* If zero, write RD to memory.  */
1562883529b6Schristos;; RD = TMP;            /* Always write tmp into RD (NOTE it's destructive).  */
1563883529b6Schristos
1564883529b6Schristos
1565883529b6Schristos(define-pmacro (testset-insn name mode sel)
1566883529b6Schristos  (begin
1567883529b6Schristos
1568883529b6Schristos
1569883529b6Schristos    (dni_wrapper (.sym name "t")
1570883529b6Schristos		 (.str "testset " mode " indexed")
1571883529b6Schristos		 ()
1572883529b6Schristos		 (.str name " $rd6,[$rn6,$direction$rm6]")
1573883529b6Schristos		 (+ OP4_LDSTRX sel OP_LOAD (f-opc-19-4 #x0) (f-dc-22-1 #x0) (f-dc-21-1 #x1)
1574883529b6Schristos		    rd6 rn6 direction rm6)
1575883529b6Schristos		 (sequence ((SI tmemaddr) (SI tmpValReg))
1576883529b6Schristos
1577883529b6Schristos			   ;;back up register
1578883529b6Schristos			   (set tmpValReg rd6)
1579883529b6Schristos
1580883529b6Schristos			   (if (ifield f-addsubx)
1581883529b6Schristos			       (set  tmemaddr  (sub rn6 rm6))
1582883529b6Schristos			       (set  tmemaddr  (add rn6 rm6))
1583883529b6Schristos			       )
1584883529b6Schristos			   ;;always update rd
1585883529b6Schristos			   (load-from-ea rd6 tmemaddr  mode sel)
1586883529b6Schristos			   ;;if zero
1587883529b6Schristos			   (if  rd6
1588883529b6Schristos				(nop)
1589883529b6Schristos				(set (mem mode tmemaddr) tmpValReg)
1590883529b6Schristos				)
1591883529b6Schristos
1592883529b6Schristos			   )
1593883529b6Schristos		 ()
1594883529b6Schristos		 )
1595883529b6Schristos
1596883529b6Schristos
1597883529b6Schristos    (dnmi  (.sym name "t.l")
1598883529b6Schristos	   (.str "testset " mode ".l indexed")
15999573673dSchristos	   (NO-DIS)
1600883529b6Schristos	   (.str name ".l $rd6,[$rn6,$direction$rm6]")
1601883529b6Schristos	   (emit (.sym name "t") rd6 rn6 direction rm6)
1602883529b6Schristos	   )
1603883529b6Schristos
1604883529b6Schristos
1605883529b6Schristos    )
1606883529b6Schristos  )
1607883529b6Schristos
1608883529b6Schristos(testset-insn testsetb QI OPW_BYTE)
1609883529b6Schristos(testset-insn testseth HI OPW_SHORT)
1610883529b6Schristos(testset-insn testset  SI OPW_WORD)
1611883529b6Schristos;;no double mode support, since we have to send the src address, data
1612883529b6Schristos;;(testset-insn testsetd DI OPW_DOUBLE load-double-from-ea)
1613883529b6Schristos
1614883529b6Schristos
1615883529b6Schristos
1616883529b6Schristos;; need 16 bit forms too
1617883529b6Schristos(define-pmacro (store-insn name mode sel sem-op)
1618883529b6Schristos  (begin
1619883529b6Schristos    (dni_wrapper (.sym name "x16")
1620883529b6Schristos		 (.str "store" mode " indexed")
1621883529b6Schristos		 (SHORT-INSN)
1622883529b6Schristos		 (.str name " $rd,[$rn,$rm]")
1623883529b6Schristos		 (+ OP4_LDSTR16X sel OP_STORE rd rn rm)
1624883529b6Schristos		 (sequence ()
1625883529b6Schristos			   (sem-op (add rn rm) rd mode sel)
1626883529b6Schristos			   )
1627883529b6Schristos		 ()
1628883529b6Schristos		 )
1629883529b6Schristos
1630883529b6Schristos    (dni_wrapper (.sym name "x")
1631883529b6Schristos		 (.str "store" mode " indexed")
1632883529b6Schristos		 ()
1633883529b6Schristos		 (.str name " $rd6,[$rn6,$direction$rm6]")
1634883529b6Schristos		 (+ OP4_LDSTRX sel OP_STORE (f-opc-19-4 #x0)  (f-dc-22-1 #x0) (f-dc-21-1 #x0) rd6 rn6 direction rm6)
1635883529b6Schristos		 (sequence ()
1636883529b6Schristos			   (if (ifield f-addsubx)
1637883529b6Schristos			       (sem-op (sub rn6 rm6) rd6 mode sel)
1638883529b6Schristos			       (sem-op (add rn6 rm6) rd6 mode sel)
1639883529b6Schristos			       ))
1640883529b6Schristos		 ()
1641883529b6Schristos		 )
1642883529b6Schristos
1643883529b6Schristos    (dnmi (.sym name "x.l")
1644883529b6Schristos	  (.str "store" mode " indexed")
16459573673dSchristos	  (NO-DIS)
1646883529b6Schristos	  (.str name ".l $rd6,[$rn6,$direction$rm6]")
1647883529b6Schristos	  (emit  (.sym name "x")  rd6 rn6 direction rm6)
1648883529b6Schristos	  )
1649883529b6Schristos
1650883529b6Schristos
1651883529b6Schristos
1652883529b6Schristos
1653883529b6Schristos
1654883529b6Schristos    (dni_wrapper (.sym name "p16")
1655883529b6Schristos		 (.str "store " mode " postmodify")
1656883529b6Schristos		 (SHORT-INSN)
1657883529b6Schristos		 (.str name " $rd,[$rn],$rm")
1658883529b6Schristos		 (+ OP4_LDSTR16P sel OP_STORE rd rn rm)
1659883529b6Schristos		 (sequence ()
1660883529b6Schristos			   (sem-op rn rd mode sel)
1661883529b6Schristos			   (set rn (add rn rm))
1662883529b6Schristos			   )
1663883529b6Schristos		 ()
1664883529b6Schristos		 )
1665883529b6Schristos
1666883529b6Schristos    (dni_wrapper (.sym name "p")
1667883529b6Schristos		 (.str "store " mode " postmodify")
1668883529b6Schristos		 ()
1669883529b6Schristos		 (.str name " $rd6,[$rn6],$direction$rm6")
1670883529b6Schristos		 (+ OP4_LDSTRP sel OP_STORE (f-opc-19-4 #x0) (f-dc-22-2 #x0) rd6 rn6 direction rm6)
1671883529b6Schristos		 (sequence ()
1672883529b6Schristos			   (sem-op rn6 rd6 mode sel)
1673883529b6Schristos			   (if (ifield f-addsubx)
1674883529b6Schristos			       (set rn6	(sub rn6 rm6))
1675883529b6Schristos			       (set rn6 (add rn6 rm6)))
1676883529b6Schristos			   )
1677883529b6Schristos		 ()
1678883529b6Schristos		 )
1679883529b6Schristos    (dnmi (.sym name "p.l")
1680883529b6Schristos	  (.str "store " mode " postmodify")
16819573673dSchristos	  (NO-DIS)
1682883529b6Schristos	  (.str name ".l $rd6,[$rn6],$direction$rm6")
1683883529b6Schristos	  (emit (.sym name "p") rd6 rn6 direction rm6)
1684883529b6Schristos	  )
1685883529b6Schristos
1686883529b6Schristos    (dni_wrapper (.sym name "d16")
1687883529b6Schristos		 (.str "store " mode " displacement")
1688883529b6Schristos		 (SHORT-INSN IMM3)
1689883529b6Schristos		 (.str name " $rd,[$rn,$disp3]")
1690883529b6Schristos		 (+ OP4_LDSTR16D sel OP_STORE rd rn disp3) ;; convert size to 'B'
1691883529b6Schristos		 (sequence ((SI effa)
1692883529b6Schristos			    (SI scale))
1693883529b6Schristos			   (ConvertSelectorToShift sel scale)
1694883529b6Schristos			   (set effa (add rn (sll disp3 scale)))
1695883529b6Schristos			   (sem-op effa rd mode sel)
1696883529b6Schristos			   )
1697883529b6Schristos		 ()
1698883529b6Schristos		 )
1699883529b6Schristos
1700883529b6Schristos    (dni_wrapper (.sym name "d")
1701883529b6Schristos		 (.str "store " mode " displacement")
1702883529b6Schristos		 ()
1703883529b6Schristos		 (.str name " $rd6,[$rn6,$dpmi$disp11]")
1704883529b6Schristos		 (+ OP4_LDSTRD sel OP_STORE PMOD_DISP rd6 rn6 dpmi disp11)
1705883529b6Schristos		 (sequence ((SI effa)
1706883529b6Schristos			    (SI scale))
1707883529b6Schristos			   (ConvertSelectorToShift sel scale)
1708883529b6Schristos			   (if dpmi
1709883529b6Schristos			       (set effa (sub rn6 (sll disp11 scale)))
1710883529b6Schristos			       (set effa (add rn6 (sll disp11 scale)))
1711883529b6Schristos			       )
1712883529b6Schristos			   (sem-op effa rd6 mode sel)
1713883529b6Schristos			   )
1714883529b6Schristos		 ()
1715883529b6Schristos		 )
1716883529b6Schristos
1717883529b6Schristos    (dnmi (.sym name "d.l")
1718883529b6Schristos	  (.str "store " mode " displacement")
17199573673dSchristos	  (NO-DIS)
1720883529b6Schristos	  (.str name ".l $rd6,[$rn6,$dpmi$disp11]")
1721883529b6Schristos	  (emit (.sym name "d") rd6 rn6 dpmi disp11)
1722883529b6Schristos	  )
1723883529b6Schristos
1724883529b6Schristos
1725883529b6Schristos    (dni_wrapper (.sym name "dpm")
1726883529b6Schristos		 (.str "store " mode " displacement post-modify")
1727883529b6Schristos		 ()
1728883529b6Schristos		 (.str name " $rd6,[$rn6],$dpmi$disp11")
1729883529b6Schristos		 (+ OP4_LDSTRD sel OP_STORE PMOD_POST rd6 rn6 dpmi disp11) ;; convert size to 'B'
1730883529b6Schristos		 (sequence ((SI scale))
1731883529b6Schristos			   (ConvertSelectorToShift sel scale)
1732883529b6Schristos			   (sem-op rn6 rd6 mode sel)
1733883529b6Schristos			   (if dpmi
1734883529b6Schristos			       (set rn6 (sub rn6 (sll disp11 scale)))
1735883529b6Schristos			       (set rn6 (add rn6 (sll disp11 scale)))
1736883529b6Schristos			       )
1737883529b6Schristos			   )
1738883529b6Schristos		 ()
1739883529b6Schristos		 )
1740883529b6Schristos    (dnmi (.sym name "dpm.l")
1741883529b6Schristos	  (.str "store " mode " displacement post-modify")
17429573673dSchristos	  (NO-DIS)
1743883529b6Schristos	  (.str name ".l $rd6,[$rn6],$dpmi$disp11")
1744883529b6Schristos	  (emit (.sym name "dpm") rd6 rn6 dpmi disp11)
1745883529b6Schristos	  )
1746883529b6Schristos
1747883529b6Schristos    ;; macro form with a zero displacement
1748883529b6Schristos    (dnmi (.sym name "ds0") "store w 0 disp"
1749883529b6Schristos	  (SHORT-INSN IMM3)
1750883529b6Schristos	  (.str name " $rd,[$rn]")
1751883529b6Schristos	  (emit (.sym name "d16") rd rn (disp3 0))
1752883529b6Schristos	  )
1753883529b6Schristos
1754883529b6Schristos    (dnmi (.sym name "dl0")  "store w 0 disp"
1755883529b6Schristos	  ()
1756883529b6Schristos	  (.str name " $rd6,[$rn6]")
1757883529b6Schristos	  (emit (.sym name "d") rd6 rn6 (dpmi 0) (disp11 0))
1758883529b6Schristos	  )
1759883529b6Schristos
1760883529b6Schristos    (dnmi (.sym name "dl0.l")  "store w 0 disp"
17619573673dSchristos	  (NO-DIS)
1762883529b6Schristos	  (.str name ".l $rd6,[$rn6]")
1763883529b6Schristos	  (emit (.sym name "d") rd6 rn6 (dpmi 0) (disp11 0))
1764883529b6Schristos	  )
1765883529b6Schristos
1766883529b6Schristos
1767883529b6Schristos
1768883529b6Schristos    )
1769883529b6Schristos  )
1770883529b6Schristos
1771883529b6Schristos(store-insn strb QI OPW_BYTE store-to-ea)
1772883529b6Schristos(store-insn strh HI OPW_SHORT store-to-ea)
1773883529b6Schristos(store-insn str  SI OPW_WORD store-to-ea)
1774883529b6Schristos(store-insn strd DI OPW_DOUBLE store-double-to-ea)
1775883529b6Schristos
1776883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1777883529b6Schristos;; MOV<COND> RD,RN
1778883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1779883529b6Schristos
1780883529b6Schristos(define-pmacro (move-insns name cond g-op)
1781883529b6Schristos  (begin
1782883529b6Schristos    (dni_wrapper (.sym "cmov16" cond)
1783883529b6Schristos		 (.str "move register " cond)
1784883529b6Schristos		 (SHORT-INSN)
1785883529b6Schristos		 (.str "mov" name " $rd,$rn")
1786883529b6Schristos		 (+ OP4_FLOW16 (.sym "OPC_" cond) (f-opc-8-1 #x0) (f-dc-9-1 #x0) rd rn)
1787883529b6Schristos		 (if (g-op)
1788883529b6Schristos		     (set rd rn))
1789883529b6Schristos		 ()
1790883529b6Schristos		 )
1791883529b6Schristos
1792883529b6Schristos    (dni_wrapper (.sym "cmov" cond)
1793883529b6Schristos		 (.str "move register " cond)
1794883529b6Schristos		 ()
1795883529b6Schristos		 (.str "mov" name " $rd6,$rn6")
1796883529b6Schristos		 (+ 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)
1797883529b6Schristos		 (if (g-op)
1798883529b6Schristos		     (set rd6 rn6))
1799883529b6Schristos		 ()
1800883529b6Schristos		 )
1801883529b6Schristos    (dnmi (.sym "cmov.l" cond)
1802883529b6Schristos	  (.str "move register " cond)
18039573673dSchristos	  (NO-DIS)
1804883529b6Schristos	  (.str "mov" name ".l $rd6,$rn6")
1805883529b6Schristos	  (emit (.sym "cmov" cond) rd6 rn6)
1806883529b6Schristos	  )
1807883529b6Schristos
1808883529b6Schristos
1809883529b6Schristos
1810883529b6Schristos    )
1811883529b6Schristos  )
1812883529b6Schristos
1813883529b6Schristos					; basic conditional moves
1814883529b6Schristos(move-insns "eq"    EQ	   (.pmacro () (eq zbit #x1)))
1815883529b6Schristos(move-insns "ne"    NE	   (.pmacro () (eq zbit #x0)))
1816883529b6Schristos(move-insns "gtu"   GTU	   (.pmacro () (and BI cbit (not BI zbit))))
1817883529b6Schristos(move-insns "gteu"  GTEU   (.pmacro () (eq cbit #x1)))
1818883529b6Schristos(move-insns "lteu"  LTEU   (.pmacro () (or BI (not BI cbit) zbit)))
1819883529b6Schristos(move-insns "ltu"   LTU	   (.pmacro () (eq cbit #x0)))
1820883529b6Schristos(move-insns "gt"    GT	   (.pmacro () (and BI (not BI zbit) (eq vbit nbit))))
1821883529b6Schristos(move-insns "gte"   GTE	   (.pmacro () (eq vbit nbit)))
1822883529b6Schristos(move-insns "lt"    LT	   (.pmacro () (xor BI vbit nbit)))
1823883529b6Schristos(move-insns "lte"   LTE	   (.pmacro () (or BI zbit (xor vbit nbit))))
1824883529b6Schristos
1825883529b6Schristos					; unconditional move
1826883529b6Schristos(move-insns ""      B      (.pmacro () #x1))
1827883529b6Schristos
1828883529b6Schristos
1829883529b6Schristos					; floating point condition codes (floating point instructions)
1830883529b6Schristos(move-insns "beq"   BEQ    (.pmacro () (or BI bzbit bzbit)))
1831883529b6Schristos(move-insns "bne"   BNE    (.pmacro () (not BI bzbit)))
1832883529b6Schristos(move-insns "blt"   BLT    (.pmacro () (and BI bnbit (not bzbit))))
1833883529b6Schristos(move-insns "blte"  BLTE   (.pmacro () (or BI bnbit bzbit)))
1834883529b6Schristos
1835883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1836883529b6Schristos;; MOVTS RD,RN
1837883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1838883529b6Schristos
1839883529b6Schristos;; 16 bits form exists for group zero ( M1 and M0 equals to zero ) only
1840883529b6Schristos
1841883529b6Schristos(dni_wrapper movts16
1842883529b6Schristos	     "move to special reg"
1843883529b6Schristos	     (SHORT-INSN)
1844883529b6Schristos	     "movts $sn,$rd"
1845883529b6Schristos	     (+ OP4_FLOW16 (f-opc-8-5 #x10) (f-dc-9-1 #x0) rd sn) ;; rd is source for movts
1846883529b6Schristos	     (set sn rd)
1847883529b6Schristos	     ()
1848883529b6Schristos	     )
1849883529b6Schristos
1850883529b6Schristos(define-pmacro (op-mmr-movts name sdreg code)
1851883529b6Schristos  (begin
1852883529b6Schristos
1853883529b6Schristos    (dni_wrapper (.sym "movts" name)
1854883529b6Schristos		 (.str "move to " name)
1855883529b6Schristos		 ()
1856883529b6Schristos		 (.str "movts $" sdreg ",$rd6")
1857883529b6Schristos		 (+ 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
1858883529b6Schristos		 (set sdreg rd6)
1859883529b6Schristos		 ()
1860883529b6Schristos		 )
1861883529b6Schristos
1862883529b6Schristos    (dnmi (.sym "movts.l" name)
1863883529b6Schristos	  (.str "move to " name)
18649573673dSchristos	  (NO-DIS)
1865883529b6Schristos	  (.str "movts.l $" sdreg ",$rd6")
1866883529b6Schristos	  (emit (.sym "movts" name) sdreg rd6)
1867883529b6Schristos	  )
1868883529b6Schristos
1869883529b6Schristos
1870883529b6Schristos
1871883529b6Schristos
1872883529b6Schristos    )
1873883529b6Schristos  )
1874883529b6Schristos
1875883529b6Schristos(op-mmr-movts  6    sn6    #x0)
1876883529b6Schristos(op-mmr-movts  dma  sndma  #x1)
1877883529b6Schristos(op-mmr-movts  mem  snmem  #x2)
1878883529b6Schristos(op-mmr-movts  mesh snmesh #x3)
1879883529b6Schristos
1880883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1881883529b6Schristos;; MOVFS
1882883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1883883529b6Schristos(dni_wrapper movfs16
1884883529b6Schristos	     "move from special register"
1885883529b6Schristos	     (SHORT-INSN)
1886883529b6Schristos	     "movfs $rd,$sn"
1887883529b6Schristos	     (+ OP4_FLOW16 (f-opc-8-5 #x11) (f-dc-9-1 #x0) rd sn)
1888883529b6Schristos	     (set rd sn)
1889883529b6Schristos	     ()
1890883529b6Schristos	     )
1891883529b6Schristos
1892883529b6Schristos
1893883529b6Schristos
1894883529b6Schristos(define-pmacro (op-mmr-movfs name snreg code)
1895883529b6Schristos  (begin
1896883529b6Schristos
1897883529b6Schristos    (dni_wrapper (.sym "movfs" name)
1898883529b6Schristos		 (.str "move from " name)
1899883529b6Schristos		 ()
1900883529b6Schristos		 (.str "movfs $rd6,$" snreg)
1901883529b6Schristos		 (+ 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)
1902883529b6Schristos		 (set rd6 snreg)
1903883529b6Schristos		 ()
1904883529b6Schristos		 )
1905883529b6Schristos
1906883529b6Schristos    (dnmi (.sym "movfs.l" name)
1907883529b6Schristos	  (.str "move from " name)
19089573673dSchristos	  (NO-DIS)
1909883529b6Schristos	  (.str "movfs.l $rd6,$" snreg)
1910883529b6Schristos	  (emit (.sym "movfs" name) rd6 snreg)
1911883529b6Schristos	  )
1912883529b6Schristos
1913883529b6Schristos
1914883529b6Schristos
1915883529b6Schristos    )
1916883529b6Schristos  )
1917883529b6Schristos
1918883529b6Schristos(op-mmr-movfs  6    sn6    #x0)
1919883529b6Schristos(op-mmr-movfs  dma  sndma  #x1)
1920883529b6Schristos(op-mmr-movfs  mem  snmem  #x2)
1921883529b6Schristos(op-mmr-movfs  mesh snmesh #x3)
1922883529b6Schristos
1923883529b6Schristos
1924883529b6Schristos
1925883529b6Schristos
1926883529b6Schristos
1927883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1928883529b6Schristos;; NOP 0x1a2
1929883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1930883529b6Schristos(dni_wrapper nop
1931883529b6Schristos	     "no-operation"
1932883529b6Schristos	     (SHORT-INSN)
1933883529b6Schristos	     "nop"
1934883529b6Schristos	     (+ OP4_FLOW16 (f-opc-8-5 #x1a) (f-dc-15-7 #x0))
1935883529b6Schristos	     (nop)
1936883529b6Schristos	     ()
1937883529b6Schristos	     )
1938883529b6Schristos
1939883529b6Schristos
1940883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1941883529b6Schristos;; SNOP 0x3a2
1942883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1943883529b6Schristos(dni_wrapper snop
1944883529b6Schristos	     "no-operation"
1945883529b6Schristos	     (SHORT-INSN)
1946883529b6Schristos	     "snop"
1947883529b6Schristos	     (+ OP4_FLOW16 (f-opc-8-5 #x3a) (f-dc-15-7 #x0))
1948883529b6Schristos	     (nop)
1949883529b6Schristos	     ()
1950883529b6Schristos	     )
1951883529b6Schristos
1952883529b6Schristos
1953883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1954883529b6Schristos;; UNIMPL
1955883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1956883529b6Schristos(dni_wrapper unimpl
1957883529b6Schristos	     "not-implemented"
1958883529b6Schristos	     ()
1959883529b6Schristos	     "unimpl"
1960883529b6Schristos	     (+ (f-opc-31-32  #x000F000F))
1961883529b6Schristos	     (nop)
1962883529b6Schristos	     ()
1963883529b6Schristos	     )
1964883529b6Schristos
1965883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1966883529b6Schristos;; IDLE
1967883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1968883529b6Schristos
1969883529b6Schristos(dni idle "idle until interrupt" () "idle"
1970883529b6Schristos     (+ OP4_FLOW16 (f-opc-8-5 #x1b) (f-dc-15-7 #x0))
1971883529b6Schristos     ;;     (set pc pc)	;; should branch to self until interrupt, but not modeling interrupts
1972883529b6Schristos     (sequence ()
1973883529b6Schristos       (set caibit 0)
1974883529b6Schristos       (c-code "sim_engine_halt (CPU_STATE (current_cpu), current_cpu, NULL, \
1975883529b6Schristos		pc, sim_exited, 0);"))
1976883529b6Schristos     ()
1977883529b6Schristos     )
1978883529b6Schristos
1979883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1980883529b6Schristos;; BKPT
1981883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1982883529b6Schristos
1983883529b6Schristos(dni bkpt
1984883529b6Schristos     "breakpoint"
1985883529b6Schristos     (SHORT-INSN)
1986883529b6Schristos     "bkpt"
1987883529b6Schristos     (+ OP4_FLOW16 (f-opc-8-5 #x1c) (f-dc-15-7 #x0))
1988883529b6Schristos     (sequence ()
1989883529b6Schristos     	 (c-call  "epiphany_break" pc)
1990883529b6Schristos     	(set pc pc)
1991883529b6Schristos     	)
1992883529b6Schristos     ()
1993883529b6Schristos     )
1994883529b6Schristos
1995883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1996883529b6Schristos;; MBKPT
1997883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1998883529b6Schristos
1999883529b6Schristos(dni mbkpt
2000883529b6Schristos     "multicorebreakpoint"
2001883529b6Schristos     (SHORT-INSN)
2002883529b6Schristos     "mbkpt"
2003883529b6Schristos     (+ OP4_FLOW16 (f-opc-8-5 #x1c) (f-dc-15-7 #x1))
2004883529b6Schristos     ;;;(c-call "epiphany_break" pc)
2005883529b6Schristos     (nop) ;; ignore the multi core break point in the simulator
2006883529b6Schristos     ()
2007883529b6Schristos     )
2008883529b6Schristos
2009883529b6Schristos;;;;;;;;;;;;;;;;
2010883529b6Schristos;; RTI
2011883529b6Schristos;;;;;;;;;;;;;;;;
2012883529b6Schristos
2013883529b6Schristos(dni rti "return from interrupt" (SHORT-INSN UNCOND-CTI)
2014883529b6Schristos     "rti"
2015883529b6Schristos     (+ OP4_FLOW16 (f-opc-8-5 #x1d) (f-dc-15-7 #x0))
2016883529b6Schristos     (sequence ()
2017883529b6Schristos	       ;; 	(set (hcr-ipend)
2018883529b6Schristos	       ;; 	     (xor (hcr-ipend)
2019883529b6Schristos	       ;; 		  (sll (const 1)
2020883529b6Schristos	       ;; 		       (sub (c-raw-call SI "ffs" (and (hcr-ipend) (not (hcr-imask))))
2021883529b6Schristos	       ;; 			    (const 1)))))
2022883529b6Schristos
2023883529b6Schristos	       (set (hcr-ipend)
2024883529b6Schristos		    (c-call SI "epiphany_rti" (hcr-ipend) (hcr-imask)))
2025883529b6Schristos	       (set gidisablebit 0)
2026883529b6Schristos	       (set kmbit 0)
2027883529b6Schristos					;(set caibit 1)
2028883529b6Schristos	       (set pc (hcr-iret)))
2029883529b6Schristos     ()
2030883529b6Schristos     )
2031883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2032883529b6Schristos;; WAND is a wired flag that runs around the chip
2033883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2034883529b6Schristos(dni_wrapper wand     "wand"
2035883529b6Schristos	     (SHORT-INSN)
2036883529b6Schristos	     "wand"
2037883529b6Schristos	     (+ OP4_FLOW16 (f-opc-8-5 #x18) (f-dc-15-7 #x0))
2038883529b6Schristos	     (set sflagbit 1)
2039883529b6Schristos	     ()
2040883529b6Schristos	     )
2041883529b6Schristos
2042883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2043883529b6Schristos;; Sync likes wand, but wired OR
2044883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2045883529b6Schristos(dni_wrapper sync     "sync"
2046883529b6Schristos	     (SHORT-INSN)
2047883529b6Schristos	     "sync"
2048883529b6Schristos	     (+ OP4_FLOW16 (f-opc-8-5 #x1f) (f-dc-15-7 #x0))
2049883529b6Schristos	     (nop);;TODO
2050883529b6Schristos	     ()
2051883529b6Schristos	     )
2052883529b6Schristos
2053883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2054883529b6Schristos;; GIE
2055883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2056883529b6Schristos(dni_wrapper gien     "global interrupt enable"
2057883529b6Schristos	     (SHORT-INSN)
2058883529b6Schristos	     "gie"
2059883529b6Schristos	     (+ OP4_FLOW16 (f-gien-gidis-9-1 #x0) (f-opc-8-5 #x19) (f-dc-15-6 #x0))
2060883529b6Schristos	     (set gidisablebit 0)
2061883529b6Schristos	     ()
2062883529b6Schristos	     )
2063883529b6Schristos
2064883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2065883529b6Schristos;; GIDIS
2066883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2067883529b6Schristos(dni_wrapper gidis     "global interrupt disable"
2068883529b6Schristos	     (SHORT-INSN)
2069883529b6Schristos	     "gid"
2070883529b6Schristos	     (+ OP4_FLOW16 (f-gien-gidis-9-1 #x1) (f-opc-8-5 #x19) (f-dc-15-6 #x0))
2071883529b6Schristos	     (set gidisablebit 1)
2072883529b6Schristos	     ()
2073883529b6Schristos	     )
2074883529b6Schristos
2075883529b6Schristos
2076883529b6Schristos
2077883529b6Schristos;;;;;;;;;;;;;;;;
2078883529b6Schristos;; SWI
2079883529b6Schristos;;;;;;;;;;;;;;;;
2080883529b6Schristos
2081883529b6Schristos;; Model only immediate 'fire' exception, if gien cleared or masked don't fire and don't check later - no ilat like behavior
2082883529b6Schristos(dni swi_num "software interrupt" (SHORT-INSN UNCOND-CTI)
2083883529b6Schristos     "swi $swi_num"
2084883529b6Schristos     (+ OP4_FLOW16 (f-opc-8-5 #x1e) (f-trap-swi-9-1 #x0)  swi_num)
2085883529b6Schristos     (sequence ()  (call-exception #x24  #x80))
2086883529b6Schristos     ;;      (if (eq gie 1)
2087883529b6Schristos     ;; 	 (sequence ()
2088883529b6Schristos     ;; 		   (set kmbit 1)
2089883529b6Schristos     ;; 		   (set gie 0)
2090883529b6Schristos     ;; 		   (set (hcr-iret) (add pc (const 2)))
2091883529b6Schristos     ;; 		   (set (hcr-ipend) (or (hcr-ipend) (const #x80)))
2092883529b6Schristos     ;; 		   (set pc (const #x1c))
2093883529b6Schristos
2094883529b6Schristos     ;; 			   )
2095883529b6Schristos     ;; 	 ;; schedule interrupt
2096883529b6Schristos     ;; 	 (set (hcr-ilat) (or (hcr-ilat) (const #x80)))
2097883529b6Schristos     ;; 	 )
2098883529b6Schristos     ()
2099883529b6Schristos     )
2100883529b6Schristos(dni swi "software interrupt" (ALIAS SHORT-INSN UNCOND-CTI)
2101883529b6Schristos     "swi"
2102883529b6Schristos     (+ OP4_FLOW16 (f-opc-8-5 #x1e) (f-trap-swi-9-1 #x0) (f-dc-15-6 #x0))
2103883529b6Schristos     (sequence ()  (call-exception #x24  #x80))
2104883529b6Schristos     ()
2105883529b6Schristos     )
2106883529b6Schristos
2107883529b6Schristos
2108883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2109883529b6Schristos;; TRAP #disp3 - simulator only and chip as well - make the same grouop as swi
2110883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2111883529b6Schristos
2112883529b6Schristos;; Only defining 16-bit form of this instruction.  It exists to support the
2113883529b6Schristos;; simulator, by giving us a simple input/output mechanism beyond returning values
2114883529b6Schristos;; in registers or memory.
2115883529b6Schristos;; TRAP #N  - special sw trap for simulator support;  allows simple i/o using fixed arguments
2116883529b6Schristos;; TRAP #0  - write (r0=i/o channel, r1=addr, r2=len) returns status in r0
2117883529b6Schristos;; TRAP #1  - read  (r0=i/o channel, r1=addr, r2=len) returns length or -<code> on error
2118883529b6Schristos;; TRAP #2  - open  (r0=string path, r1=mode) returns channel# or -<code> on error
2119883529b6Schristos;; TRAP #3  - exit  (r0=status code) never returns.
2120883529b6Schristos;; TRAP #4  - print "pass\n" and exit
2121883529b6Schristos;; TRAP #5  - print "fail\n" and exit
2122883529b6Schristos;; TRAP #6  - close  (r0=i/o channel)
2123883529b6Schristos
2124883529b6Schristos(dni trap16 "trap to simulator"
2125883529b6Schristos     (SHORT-INSN UNCOND-CTI)
2126883529b6Schristos     "trap $trapnum6"
2127883529b6Schristos     (+ 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)
2128883529b6Schristos     (set (reg SI h-registers 0) (c-call SI "epiphany_trap" pc trapnum6))
2129883529b6Schristos     ()
2130883529b6Schristos     )
2131883529b6Schristos
2132883529b6Schristos
2133883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2134883529b6Schristos;; Integer arithmetic instructions 3 address forms
2135883529b6Schristos;;   both 16 and 32 bit forms
2136883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2137883529b6Schristos
2138883529b6Schristos(define-pmacro (op-rrr name sem-op cond-op)
2139883529b6Schristos  (begin
2140883529b6Schristos    (dni_wrapper (.sym name "16")
2141883529b6Schristos		 (.str name)
2142883529b6Schristos		 (SHORT-INSN)
2143883529b6Schristos		 (.str name " $rd,$rn,$rm")
2144883529b6Schristos		 (+ OP4_ALU16 (.sym "OPB_" (.upcase (.str name))) rd rn rm)
2145883529b6Schristos		 (sequence ()
2146883529b6Schristos			   (cond-op rn rm)
2147883529b6Schristos			   (set rd (sem-op SI rn rm))
2148883529b6Schristos			   (set zbit (zflag rd))
2149883529b6Schristos			   (set nbit (nflag rd))
2150883529b6Schristos			   )
2151883529b6Schristos		 ()
2152883529b6Schristos		 )
2153883529b6Schristos
2154883529b6Schristos    (dni_wrapper (.sym name)
2155883529b6Schristos		 (.str name)
2156883529b6Schristos		 ()
2157883529b6Schristos		 (.str name " $rd6,$rn6,$rm6")
2158883529b6Schristos		 (+ OP4_MISC (.sym "OPB_" (.upcase (.str name))) (f-opc-19-4 #xa) (f-dc-22-3 #x0) rd6 rn6 rm6)
2159883529b6Schristos		 (sequence ()
2160883529b6Schristos			   (cond-op rn6 rm6)
2161883529b6Schristos			   (set rd6 (sem-op SI rn6 rm6))
2162883529b6Schristos			   (set zbit (zflag rd6))
2163883529b6Schristos			   (set nbit (nflag rd6))
2164883529b6Schristos			   )
2165883529b6Schristos		 ()
2166883529b6Schristos		 )
2167883529b6Schristos
2168883529b6Schristos    (dnmi (.sym name ".l")
2169883529b6Schristos	  (.str name)
21709573673dSchristos	  (NO-DIS)
2171883529b6Schristos	  (.str name ".l $rd6,$rn6,$rm6")
2172883529b6Schristos	  (emit (.sym name) rd6 rn6 rm6)
2173883529b6Schristos	  )
2174883529b6Schristos
2175883529b6Schristos
2176883529b6Schristos
2177883529b6Schristos    )
2178883529b6Schristos  )
2179883529b6Schristos
2180883529b6Schristos;; submacros to set condition codes
2181883529b6Schristos;;  NZ are always set to reflect the sign and value of the result
2182883529b6Schristos;;  CV are a function of the operator
2183883529b6Schristos(define-pmacro (add-vc a b) (sequence ()
2184883529b6Schristos				      (set cbit (add-cflag SI a b 0))
2185883529b6Schristos				      (set vbit (add-oflag SI a b 0))
2186883529b6Schristos				      (set vsbit (or BI vsbit vbit))
2187883529b6Schristos				      ))
2188883529b6Schristos
2189883529b6Schristos(define-pmacro (sub-vc a b) (sequence ()
2190883529b6Schristos				      (set cbit (not (sub-cflag SI a b 0)))
2191883529b6Schristos				      (set vbit (sub-oflag SI a b 0))
2192883529b6Schristos				      (set vsbit (or vsbit vbit))
2193883529b6Schristos				      ))
2194883529b6Schristos
2195883529b6Schristos(define-pmacro (logic-vc a b) (sequence ()
2196883529b6Schristos					(set cbit 0)
2197883529b6Schristos					(set vbit 0)
2198883529b6Schristos					))
2199883529b6Schristos
2200883529b6Schristos(op-rrr add add add-vc)
2201883529b6Schristos(op-rrr sub sub sub-vc)
2202883529b6Schristos(op-rrr and and logic-vc)
2203883529b6Schristos(op-rrr orr  or  logic-vc)
2204883529b6Schristos(op-rrr eor xor logic-vc)
2205883529b6Schristos
2206883529b6Schristos;; Integer arithmetic immediate forms
2207883529b6Schristos
2208883529b6Schristos(define-pmacro (op-rri name code cond-op)
2209883529b6Schristos  (begin
2210883529b6Schristos    (dni_wrapper (.sym name "i16")
2211883529b6Schristos		 (.str name)
2212883529b6Schristos		 (SHORT-INSN IMM3)
2213883529b6Schristos		 (.str name ".s $rd,$rn,$simm3")
2214883529b6Schristos		 (+ OP4_IMM16 code rd rn simm3)
2215883529b6Schristos		 (sequence ()
2216883529b6Schristos			   (cond-op rn simm3)
2217883529b6Schristos			   (set rd (name SI rn simm3))
2218883529b6Schristos			   (set zbit (zflag rd))
2219883529b6Schristos			   (set nbit (nflag rd))
2220883529b6Schristos			   )
2221883529b6Schristos		 ()
2222883529b6Schristos		 )
2223883529b6Schristos
2224883529b6Schristos
2225883529b6Schristos    (dni_wrapper (.sym name "i")
2226883529b6Schristos		 (.str name)
2227883529b6Schristos		 ()
2228883529b6Schristos		 (.str name ".l $rd6,$rn6,$simm11")
2229883529b6Schristos		 (+ OP4_IMM32 code OPI_25_2_MBZ rd6 rn6 simm11)
2230883529b6Schristos		 (sequence ()
2231883529b6Schristos			   (cond-op rn6 simm11)
2232883529b6Schristos			   (set rd6 (name SI rn6 simm11))
2233883529b6Schristos			   (set zbit (zflag rd6))
2234883529b6Schristos			   (set nbit (nflag rd6))
2235883529b6Schristos			   )
2236883529b6Schristos		 ()
2237883529b6Schristos		 )
2238883529b6Schristos
2239883529b6Schristos    ;;    (dnmi (.sym name "ri") "relaxed arithmetic immediate" (RELAXED)
2240883529b6Schristos    ;;	  (.str name " $rd6,$rn6,$simm11")
2241883529b6Schristos    ;;	  (emit (.sym name "i") rd6 rn6 simm11))
2242883529b6Schristos    )
2243883529b6Schristos  )
2244883529b6Schristos
2245883529b6Schristos(op-rri add OPI_ADD add-vc)
2246883529b6Schristos(op-rri sub OPI_SUB sub-vc)
2247883529b6Schristos
2248883529b6Schristos(dnmi addir "relaxable short immediate add" (RELAXABLE IMM3)
2249883529b6Schristos      "add $rd,$rn,$simm3"
2250883529b6Schristos      (emit addi16 rd rn simm3))
2251883529b6Schristos
2252883529b6Schristos(dnmi addi32r "relaxed long immediate add" (RELAXED)
2253883529b6Schristos      "add $rd6,$rn6,$simm11"
2254883529b6Schristos      (emit addi rd6 rn6 simm11))
2255883529b6Schristos
2256883529b6Schristos;; Again, but not relaxable so that full sized registers are handled
2257883529b6Schristos(dnmi addi32m "relaxed long immediate add" ()
2258883529b6Schristos      "add $rd6,$rn6,$simm11"
2259883529b6Schristos      (emit addi rd6 rn6 simm11))
2260883529b6Schristos
2261883529b6Schristos
2262883529b6Schristos(dnmi subir "relaxable short immediate sub" (RELAXABLE IMM3)
2263883529b6Schristos      "sub $rd,$rn,$simm3"
2264883529b6Schristos      (emit subi16 rd rn simm3))
2265883529b6Schristos
2266883529b6Schristos(dnmi subi32r "relaxed long immediate sub" (RELAXED)
2267883529b6Schristos      "sub $rd6,$rn6,$simm11"
2268883529b6Schristos      (emit subi rd6 rn6 simm11))
2269883529b6Schristos
2270883529b6Schristos(dnmi subi32m "relaxed long immediate sub" ()
2271883529b6Schristos      "sub $rd6,$rn6,$simm11"
2272883529b6Schristos      (emit subi rd6 rn6 simm11))
2273883529b6Schristos
2274883529b6Schristos
2275883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2276883529b6Schristos;; Shift instructions 3 address forms
2277883529b6Schristos;;   both 16 and 32 bit forms
2278883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2279883529b6Schristos
2280883529b6Schristos(define-pmacro (shift-rrr name sem-op)
2281883529b6Schristos  (begin
2282883529b6Schristos    (dni_wrapper (.sym name "16")
2283883529b6Schristos		 (.str name)
2284883529b6Schristos		 (SHORT-INSN)
2285883529b6Schristos		 (.str name " $rd,$rn,$rm")
2286883529b6Schristos		 (+ OP4_ALU16 (.sym "OPB_" (.upcase (.str name))) rd rn rm)
2287883529b6Schristos		 (sequence ()
2288883529b6Schristos			   (logic-vc rn rm)
2289883529b6Schristos			   (set rd (sem-op SI rn (and rm (const 31))))
2290883529b6Schristos			   (set zbit (zflag rd))
2291883529b6Schristos			   (set nbit (nflag rd))
2292883529b6Schristos			   )
2293883529b6Schristos		 ()
2294883529b6Schristos		 )
2295883529b6Schristos
2296883529b6Schristos    (dni_wrapper (.sym name)
2297883529b6Schristos		 (.str name)
2298883529b6Schristos		 ()
2299883529b6Schristos		 (.str name " $rd6,$rn6,$rm6")
2300883529b6Schristos		 (+ OP4_MISC (.sym "OPB_" (.upcase (.str name))) (f-opc-19-4 #xa) (f-dc-22-3 #x0) rd6 rn6 rm6)
2301883529b6Schristos		 (sequence ()
2302883529b6Schristos			   (logic-vc rn6 rm6)
2303883529b6Schristos			   (set rd6 (sem-op SI rn6 (and rm6 (const 31))))
2304883529b6Schristos			   (set zbit (zflag rd6))
2305883529b6Schristos			   (set nbit (nflag rd6))
2306883529b6Schristos			   )
2307883529b6Schristos		 ()
2308883529b6Schristos		 )
2309883529b6Schristos
2310883529b6Schristos    (dnmi (.sym name ".l")
2311883529b6Schristos	  (.str name)
23129573673dSchristos	  (NO-DIS)
2313883529b6Schristos	  (.str name ".l $rd6,$rn6,$rm6")
2314883529b6Schristos	  (emit (.sym name) rd6 rn6 rm6)
2315883529b6Schristos	  )
2316883529b6Schristos    )
2317883529b6Schristos  )
2318883529b6Schristos
2319883529b6Schristos(shift-rrr asr sra)
2320883529b6Schristos(shift-rrr lsr srl)
2321883529b6Schristos(shift-rrr lsl sll)
2322883529b6Schristos
2323883529b6Schristos(define-pmacro (op-shift-rri name shortcode f5 longcode sem-op)
2324883529b6Schristos  (begin
2325883529b6Schristos    (dni_wrapper (.sym name "i16")
2326883529b6Schristos		 (.str name)
2327883529b6Schristos		 (SHORT-INSN)
2328883529b6Schristos		 (.str name " $rd,$rn,$shift")
2329883529b6Schristos		 (+ shortcode (f-opc-4-1 f5) rd rn shift)
2330883529b6Schristos		 (sequence ()
2331883529b6Schristos			   (logic-vc rn shift)
2332883529b6Schristos			   (set rd (sem-op SI rn shift))
2333883529b6Schristos			   (set zbit (zflag rd))
2334883529b6Schristos			   (set nbit (nflag rd))
2335883529b6Schristos			   )
2336883529b6Schristos		 ()
2337883529b6Schristos		 )
2338883529b6Schristos    (dni_wrapper (.sym name "i32")
2339883529b6Schristos		 (.str name)
2340883529b6Schristos		 ()
2341883529b6Schristos		 (.str name " $rd6,$rn6,$shift")
2342883529b6Schristos		 (+ OP4_MISC (f-opc-4-1 f5) (f-opc-19-4 longcode) (f-dc-25-6 0) rd6 rn6 shift)
2343883529b6Schristos		 (sequence ()
2344883529b6Schristos			   (logic-vc rn6 shift)
2345883529b6Schristos			   (set rd6 (sem-op SI rn6 shift))
2346883529b6Schristos			   (set zbit (zflag rd6))
2347883529b6Schristos			   (set nbit (nflag rd6))
2348883529b6Schristos			   )
2349883529b6Schristos		 ()
2350883529b6Schristos		 )
2351883529b6Schristos
2352883529b6Schristos    (dnmi (.sym name "i32.l")
2353883529b6Schristos	  (.str name)
23549573673dSchristos	  (NO-DIS)
2355883529b6Schristos	  (.str name ".l $rd6,$rn6,$shift")
2356883529b6Schristos	  (emit (.sym name "i32") rd6  rn6 shift)
2357883529b6Schristos	  )
2358883529b6Schristos
2359883529b6Schristos
2360883529b6Schristos    )
2361883529b6Schristos  )
2362883529b6Schristos
2363883529b6Schristos(op-shift-rri lsr OP4_LSHIFT16 0 #x6 srl)
2364883529b6Schristos(op-shift-rri lsl OP4_LSHIFT16 1 #x6 sll)
2365883529b6Schristos(op-shift-rri asr OP4_ASHIFT16 0 #xe sra)
2366883529b6Schristos
2367883529b6Schristos;; BITR - bitreversal (FFT)
2368883529b6Schristos;;
2369883529b6Schristos;; From Dr Dobbs et al.
2370883529b6Schristos;;
2371883529b6Schristos;; unsigned int v;
2372883529b6Schristos;; v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1);  ;; swap odd-even bits
2373883529b6Schristos;; v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2);  ;; swap pairs
2374883529b6Schristos;; v = ((v >> 4) & 0x0f0f0f0f) | ((v & 0x0f0f0f0f) << 4);  ;; swap nibbles
2375883529b6Schristos;; v = ((v >> 8) & 0x00ff00ff) | ((v & 0x00ff00ff) << 8);  ;; swap bytes
2376883529b6Schristos;; v =  (v >> 16)              |  (v               << 16); ;; swap halves
2377883529b6Schristos(define-pmacro (bit-reversal dest src)
2378883529b6Schristos  (sequence ((SI v))
2379883529b6Schristos	    (set v src)
2380883529b6Schristos	    (set v (or (and (srl v 1) #x55555555) (sll (and v #x55555555) 1)))
2381883529b6Schristos	    (set v (or (and (srl v 2) #x33333333) (sll (and v #x33333333) 2)))
2382883529b6Schristos	    (set v (or (and (srl v 4) #x0f0f0f0f) (sll (and v #x0f0f0f0f) 4)))
2383883529b6Schristos	    (set v (or (and (srl v 8) #x00ff00ff) (sll (and v #x00ff00ff) 8)))
2384883529b6Schristos	    (set v (or      (srl v 16)            (sll      v            16)))
2385883529b6Schristos	    (set dest v)
2386883529b6Schristos	    ))
2387883529b6Schristos
2388883529b6Schristos(dni_wrapper bitr16 "bit reverse short"
2389883529b6Schristos	     (SHORT-INSN)
2390883529b6Schristos	     ("bitr $rd,$rn")
2391883529b6Schristos	     (+ OP4_ASHIFT16 (f-opc-4-1 1) rd rn (f-shift 0))
2392883529b6Schristos	     (sequence ()
2393883529b6Schristos		       (bit-reversal rd rn)
2394883529b6Schristos		       (set zbit (zflag rd))
2395883529b6Schristos		       (set nbit (nflag rd))
2396883529b6Schristos		       (set cbit 0)
2397883529b6Schristos		       (set vbit 0)
2398883529b6Schristos		       )
2399883529b6Schristos	     ()
2400883529b6Schristos	     )
2401883529b6Schristos
2402883529b6Schristos(dni_wrapper bitr "bit reverse"
2403883529b6Schristos	     ()
2404883529b6Schristos	     ("bitr $rd6,$rn6")
2405883529b6Schristos	     (+ OP4_MISC (f-opc-4-1 1) (f-opc-19-4 #xe) (f-dc-25-6 0) rd6 rn6 (f-shift 0))
2406883529b6Schristos	     (sequence ()
2407883529b6Schristos		       (bit-reversal rd6 rn6)
2408883529b6Schristos		       (set zbit (zflag rd6))
2409883529b6Schristos		       (set nbit (nflag rd6))
2410883529b6Schristos		       (set cbit 0)
2411883529b6Schristos		       (set vbit 0)
2412883529b6Schristos		       )
2413883529b6Schristos	     ()
2414883529b6Schristos	     )
2415883529b6Schristos(dnmi bitrl "bit reverse l"
24169573673dSchristos      (NO-DIS)
2417883529b6Schristos      ("bitr.l $rd6,$rn6")
2418883529b6Schristos      (emit bitr rd6 rn6)
2419883529b6Schristos      )
2420883529b6Schristos
2421883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2422883529b6Schristos;; Integer arithmetic instructions
2423883529b6Schristos;; Extended operation
2424883529b6Schristos;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2425883529b6Schristos
2426883529b6Schristos(define-pmacro (op-iextrrr  name  cond-op)
2427883529b6Schristos  (begin
2428883529b6Schristos
2429883529b6Schristos    (dni_wrapper (.sym name)
2430883529b6Schristos		 (.str name)
2431883529b6Schristos		 ()
2432883529b6Schristos		 (.str name " $rd6,$rn6,$rm6")
2433883529b6Schristos		 (+ OP4_MISC (.sym "OPBE_" (.upcase (.str name))) (f-opc-19-4 #xa) (f-dc-22-2 #x0)  (f-dc-20-1 #x1)
2434883529b6Schristos		    rd6 rn6 rm6)
2435883529b6Schristos		 (sequence ()
2436883529b6Schristos			   ;;  TODO cond operation (cond-op rn6 rm6)
2437883529b6Schristos			   ;;(set rd6 (sem-op SI rn6 rm6))
2438883529b6Schristos			   (set zbit (zflag rd6))
2439883529b6Schristos			   (set nbit (nflag rd6))
2440883529b6Schristos			   )
2441883529b6Schristos		 ()
2442883529b6Schristos		 )
2443883529b6Schristos
2444883529b6Schristos    (dnmi (.sym name ".l")
2445883529b6Schristos	  (.str name)
24469573673dSchristos	  (NO-DIS)
2447883529b6Schristos	  (.str name ".l $rd6,$rn6,$rm6")
2448883529b6Schristos	  (emit (.sym name) rd6  rn6 rm6)
2449883529b6Schristos	  )
2450883529b6Schristos    )
2451883529b6Schristos  )
2452883529b6Schristos
2453883529b6Schristos(op-iextrrr fext  sub-vc)
2454883529b6Schristos(op-iextrrr fdep  sub-vc)
2455883529b6Schristos(op-iextrrr lfsr  sub-vc)
2456883529b6Schristos
2457883529b6Schristos
2458883529b6Schristos
2459883529b6Schristos;; Immediate moves.  The 8 bit form is relaxed if it doesn't fit or is external
2460883529b6Schristos;; Move RD,#IMM
2461883529b6Schristos(dni_wrapper mov8
2462883529b6Schristos	     "mov imm8"
2463883529b6Schristos	     (SHORT-INSN)
2464883529b6Schristos	     "mov.b $rd,$imm8"
2465883529b6Schristos	     (+ OP4_IMM16 (f-opc-4-1 #x0) rd imm8)
2466883529b6Schristos	     (set rd (zext SI imm8))
2467883529b6Schristos	     ()
2468883529b6Schristos	     )
2469883529b6Schristos
2470883529b6Schristos(dnmi mov8r "mov imm8 relaxable"
2471883529b6Schristos      (RELAXABLE)
2472883529b6Schristos      "mov $rd,$imm8"
2473883529b6Schristos      (emit mov8 rd imm8))
2474883529b6Schristos
2475883529b6Schristos(dni_wrapper mov16
2476883529b6Schristos	     "mov imm16"
2477883529b6Schristos	     ()
2478883529b6Schristos	     "mov.l $rd6,$imm16"
2479883529b6Schristos	     (+ OP4_IMM32 (f-opc-4-1 #x0) (f-opc-19-4 #x2) (f-dc-28-1 #x0) rd6 imm16)
2480883529b6Schristos	     (set rd6 (zext SI imm16))
2481883529b6Schristos	     ()
2482883529b6Schristos	     )
2483883529b6Schristos
2484883529b6Schristos(dnmi mov16r "mov imm16 relaxable"
2485883529b6Schristos      ()
2486883529b6Schristos      "mov $rd6,$imm16"
2487883529b6Schristos      (emit mov16 rd6 imm16))
2488883529b6Schristos
2489883529b6Schristos;; MOVE TO HIGH WORD
2490883529b6Schristos(dni_wrapper movt
2491883529b6Schristos	     "movt imm16"
2492883529b6Schristos	     ()
2493883529b6Schristos	     "movt $rd6,$imm16"
2494883529b6Schristos	     (+ OP4_IMM32 (f-opc-4-1 #x0) (f-opc-19-4 #x2) (f-dc-28-1 #x1) rd6 imm16)
2495883529b6Schristos	     (set rd6 (or (and SI rd6 (const #xffff)) ; keep low bits of rd
2496883529b6Schristos			  (sll SI imm16 (const 16)))) ; replacing just high bits
2497883529b6Schristos	     ()
2498883529b6Schristos	     )
2499883529b6Schristos(dnmi movtl
2500883529b6Schristos      "movt imm16"
25019573673dSchristos      (NO-DIS)
2502883529b6Schristos      "movt.l $rd6,$imm16"
2503883529b6Schristos      (emit movt rd6 imm16)
2504883529b6Schristos      )
2505883529b6Schristos
2506883529b6Schristos
2507883529b6Schristos
2508883529b6Schristos;; FLOATING POINT OPERATIONS
2509883529b6Schristos;; TWO operands
2510883529b6Schristos(define-pmacro (op-two_operands-float name code)
2511883529b6Schristos  (begin
2512883529b6Schristos    (dni_wrapper
2513883529b6Schristos      (.sym "f_" name "f16")
2514883529b6Schristos      (.str "f_" name)
2515883529b6Schristos      (SHORT-INSN)
2516883529b6Schristos      (.str "f" name " $rd,$rn,$rm")
2517883529b6Schristos      (+ OP4_DSP16 code rd rn rm)
2518883529b6Schristos      (sequence ()
2519883529b6Schristos	(if
2520883529b6Schristos	  (eq  arithmetic-modebit2 0)
2521883529b6Schristos	  (sequence ((SF fptemp) (SI sdtmp))
2522883529b6Schristos	    (set sdtmp  (c-call SI (.str "epiphany_f" name) rd rn rm))
2523883529b6Schristos
2524883529b6Schristos	    ;;All bits are calculated in C
2525883529b6Schristos	    (set bzbit  (c-call BI "get_epiphany_fzeroflag" sdtmp))
2526883529b6Schristos	    (set bnbit  (c-call BI "get_epiphany_fnegativeflag" sdtmp))
2527883529b6Schristos	    (set bvbit  (c-call BI "get_epiphany_foverflowflag" sdtmp))
2528883529b6Schristos	    (set bubit  (c-call BI "get_epiphany_funderflowflag" sdtmp))
2529883529b6Schristos	    (set bibit  (c-call BI "get_epiphany_finvalidflag" sdtmp))
2530883529b6Schristos	    (set bvsbit (or bvsbit bvbit))
2531883529b6Schristos	    (set busbit (or busbit bubit))
2532883529b6Schristos	    (set bisbit (or bisbit bibit))
2533883529b6Schristos	    (set rd sdtmp)
2534883529b6Schristos	    (if (or (and invExcEnbit bisbit)
2535883529b6Schristos		    (or (and ovfExcEnbit bvsbit) (and unExcEnbit busbit)))
2536883529b6Schristos		(sequence ()
2537883529b6Schristos		  (set expcause0bit (const 1))
2538883529b6Schristos		  (set expcause1bit (const 1))
2539883529b6Schristos		  (call-exception #x4 #x2)))
2540883529b6Schristos	    ))
2541883529b6Schristos	(if (eq arithmetic-modebit2 1)
2542883529b6Schristos	    (sequence ((SI sdtmp))
2543883529b6Schristos	      (set sdtmp  (c-call SI (.str "epiphany_i" name) rd rn rm))
2544883529b6Schristos	      ;; carry is not connected inb the design (set bcbit bcbit)
2545883529b6Schristos	      (set bzbit (zflag sdtmp))
2546883529b6Schristos	      (set bnbit (nflag sdtmp))
2547883529b6Schristos	      (set rd sdtmp)))
2548883529b6Schristos	)
2549883529b6Schristos
2550883529b6Schristos      ()
2551883529b6Schristos      )
2552883529b6Schristos    (dnmi (.sym "i_" name "f16")
2553883529b6Schristos	  (.str "i_" name)
2554883529b6Schristos	  (SHORT-INSN NO-DIS)
2555883529b6Schristos	  (.str "i" name " $rd,$rn,$rm")
2556883529b6Schristos	  (emit (.sym "f_" name "f16") rd rn rm)
2557883529b6Schristos    )
2558883529b6Schristos
2559883529b6Schristos
2560883529b6Schristos    (dni_wrapper
2561883529b6Schristos      (.sym "f_" name "f32")
2562883529b6Schristos      (.str "f_" name)
2563883529b6Schristos      ()
2564883529b6Schristos      (.str "f" name " $rd6,$rn6,$rm6")
2565883529b6Schristos      (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rm6)
2566883529b6Schristos      (sequence ()
2567883529b6Schristos	(if
2568883529b6Schristos	  (eq arithmetic-modebit2 0)
2569883529b6Schristos	  (sequence ((SF fptemp) (SI sdtmp))
2570883529b6Schristos	    (set sdtmp  (c-call SI (.str "epiphany_f" name) rd6 rn6 rm6))
2571883529b6Schristos
2572883529b6Schristos	    ;;All bits are calculated in C
2573883529b6Schristos	    (set bzbit  (c-call BI "get_epiphany_fzeroflag" sdtmp))
2574883529b6Schristos	    (set bnbit  (c-call BI "get_epiphany_fnegativeflag" sdtmp))
2575883529b6Schristos	    (set bvbit  (c-call BI "get_epiphany_foverflowflag" sdtmp))
2576883529b6Schristos	    (set bubit  (c-call BI "get_epiphany_funderflowflag" sdtmp))
2577883529b6Schristos	    (set bibit  (c-call BI "get_epiphany_finvalidflag" sdtmp))
2578883529b6Schristos	    (set bvsbit (or bvsbit bvbit))
2579883529b6Schristos	    (set busbit (or busbit bubit))
2580883529b6Schristos	    (set bisbit (or bisbit bibit))
2581883529b6Schristos
2582883529b6Schristos	    (set rd6 sdtmp)
2583883529b6Schristos
2584883529b6Schristos	    (if (or (and invExcEnbit bisbit)
2585883529b6Schristos		    (or (and ovfExcEnbit bvsbit) (and unExcEnbit busbit)))
2586883529b6Schristos		(sequence ()
2587883529b6Schristos		  (set expcause0bit (const 1))
2588883529b6Schristos		  (set expcause1bit (const 1))
2589883529b6Schristos		  (call-exception #x4 #x2)))
2590883529b6Schristos	    )
2591883529b6Schristos	  )
2592883529b6Schristos	(if (eq arithmetic-modebit2 1)
2593883529b6Schristos	    (sequence ((SI sdtmp))
2594883529b6Schristos	      (set sdtmp (c-call SI (.str "epiphany_i" name) rd6 rn6 rm6))
2595883529b6Schristos	      ;; carry is not connected inb the design (set bcbit bcbit)
2596883529b6Schristos	      (set bzbit (zflag sdtmp))
2597883529b6Schristos	      (set bnbit (nflag sdtmp))
2598883529b6Schristos	      (set rd6 sdtmp)
2599883529b6Schristos	      )
2600883529b6Schristos	    )
2601883529b6Schristos	)
2602883529b6Schristos      ()
2603883529b6Schristos      )
2604883529b6Schristos
2605883529b6Schristos    (dnmi (.sym "f_" name "f32.l")
2606883529b6Schristos	  (.str "f_" name)
26079573673dSchristos	  (NO-DIS)
2608883529b6Schristos	  (.str "f" name ".l $rd6,$rn6,$rm6")
2609883529b6Schristos	  (emit  (.sym "f_" name "f32") rd6  rn6 rm6)
2610883529b6Schristos	  )
2611883529b6Schristos    (dnmi (.sym "i_" name "f32")
2612883529b6Schristos	  (.str "i_" name)
2613883529b6Schristos	  (NO-DIS)
2614883529b6Schristos	  (.str "i" name " $rd6,$rn6,$rm6")
2615883529b6Schristos	  (emit  (.sym "f_" name "f32") rd6  rn6 rm6)
2616883529b6Schristos	  )
2617883529b6Schristos    (dnmi (.sym "i_" name "f32.l")
2618883529b6Schristos	  (.str "i_" name)
2619883529b6Schristos	  (NO-DIS)
2620883529b6Schristos	  (.str "i" name ".l $rd6,$rn6,$rm6")
2621883529b6Schristos	  (emit  (.sym "f_" name "f32") rd6  rn6 rm6)
2622883529b6Schristos	  )
2623883529b6Schristos
2624883529b6Schristos
2625883529b6Schristos
2626883529b6Schristos    )
2627883529b6Schristos  )
2628883529b6Schristos
2629883529b6Schristos(op-two_operands-float add OPF_ADD)
2630883529b6Schristos(op-two_operands-float sub OPF_SUB)
2631883529b6Schristos(op-two_operands-float mul OPF_MUL)
2632883529b6Schristos(op-two_operands-float madd OPF_MADD)
2633883529b6Schristos(op-two_operands-float msub OPF_MSUB)
2634883529b6Schristos
2635883529b6Schristos;; ONE operands
2636883529b6Schristos;; FABS
2637883529b6Schristos(define-pmacro (op-fabs-float name code)
2638883529b6Schristos  (begin
2639883529b6Schristos    (dni_wrapper (.sym "f_" name "f16")
2640883529b6Schristos		 (.str "f_" name)
2641883529b6Schristos		 (SHORT-INSN)
2642883529b6Schristos		 (.str "f" name " rd,rn")
2643883529b6Schristos		 (+ OP4_DSP16 code rd rn rn)
2644883529b6Schristos		 (sequence ((SF fptemp) (SI sdtmp))
2645883529b6Schristos
2646883529b6Schristos		   ;(set sdtmp  (and rn  #x7fffffff))
2647883529b6Schristos		   (set sdtmp  (c-call SI (.str "epiphany_fabs") rd rn rn))
2648883529b6Schristos
2649883529b6Schristos
2650883529b6Schristos		   (set bnbit  (const SI 0))
2651883529b6Schristos		   (set bzbit (eq SI sdtmp  (const SI 0)))
2652883529b6Schristos
2653883529b6Schristos		   ;;TODO subnormal ??
2654883529b6Schristos		   (set bvsbit (or bvsbit bvbit))
2655883529b6Schristos		   (set busbit (or busbit bubit))
2656883529b6Schristos		   (set bisbit (or bisbit bibit))
2657883529b6Schristos
2658883529b6Schristos		   (set rd sdtmp)
2659883529b6Schristos		   )
2660883529b6Schristos		 ()
2661883529b6Schristos		 )
2662883529b6Schristos
2663883529b6Schristos    (dni_wrapper (.sym "f_" name "f32")
2664883529b6Schristos		 (.str "f_" name)
2665883529b6Schristos		 ()
2666883529b6Schristos		 (.str "f" name " $rd6,$rn6")
2667883529b6Schristos		 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rn6)
2668883529b6Schristos		 (sequence ((SF fptemp) (SI sdtmp))
2669883529b6Schristos
2670883529b6Schristos
2671883529b6Schristos		   ;(set sdtmp   (and rn6  #x7fffffff))
2672883529b6Schristos
2673883529b6Schristos		   (set sdtmp  (c-call SI (.str "epiphany_fabs") rd6 rn6 rn6))
2674883529b6Schristos
2675883529b6Schristos
2676883529b6Schristos		   (set bnbit   (const SI 0))
2677883529b6Schristos		   (set bzbit (eq SI sdtmp  (const SI 0)))
2678883529b6Schristos
2679883529b6Schristos		   (set bvsbit (or bvsbit bvbit))
2680883529b6Schristos		   (set busbit (or busbit bubit))
2681883529b6Schristos		   (set bisbit (or bisbit bibit))
2682883529b6Schristos
2683883529b6Schristos		   (set rd6 sdtmp)
2684883529b6Schristos
2685883529b6Schristos		   )
2686883529b6Schristos		 ()
2687883529b6Schristos		 )
2688883529b6Schristos
2689883529b6Schristos    (dnmi  (.sym "f_" name "f32.l")
2690883529b6Schristos	   (.str "f_" name)
26919573673dSchristos	   (NO-DIS)
2692883529b6Schristos	   (.str "f" name ".l $rd6,$rn6")
2693883529b6Schristos	   (emit (.sym "f_" name "f32") rd6  rn6)
2694883529b6Schristos	   )
2695883529b6Schristos
2696883529b6Schristos
2697883529b6Schristos    )
2698883529b6Schristos  )
2699883529b6Schristos
2700883529b6Schristos(op-fabs-float abs OPF_FABS)
2701883529b6Schristos
2702883529b6Schristos
2703883529b6Schristos(define-pmacro (op-fix2float-float name code)
2704883529b6Schristos  (begin
2705883529b6Schristos    (dni_wrapper (.sym "f_" name "f16")
2706883529b6Schristos		 (.str "f_" name)
2707883529b6Schristos		 (SHORT-INSN)
2708883529b6Schristos		 (.str "f" name " $rd,$rn")
2709883529b6Schristos		 (+ OP4_DSP16 code frd frn frn)
2710883529b6Schristos		 (sequence ((SF fptemp) (SI sdtmp))
2711883529b6Schristos
2712883529b6Schristos		   (set sdtmp  (c-call SI (.str "epiphany_f" name) rd rn rn))
2713883529b6Schristos
2714883529b6Schristos		   (set bnbit (lt SI sdtmp  (const SI 0)))
2715883529b6Schristos		   (set bzbit (eq SI sdtmp  (const SI 0)))
2716883529b6Schristos
2717883529b6Schristos		   (set bvsbit (or bvsbit bvbit))
2718883529b6Schristos		   (set busbit (or busbit bubit))
2719883529b6Schristos		   (set bisbit (or bisbit bibit))
2720883529b6Schristos
2721883529b6Schristos		   (set rd sdtmp)
2722883529b6Schristos		   )
2723883529b6Schristos		 ()
2724883529b6Schristos		 )
2725883529b6Schristos
2726883529b6Schristos
2727883529b6Schristos    (dni_wrapper (.sym "f_" name "f32")
2728883529b6Schristos		 (.str "f_" name)
2729883529b6Schristos		 ()
2730883529b6Schristos		 (.str "f" name " $rd6,$rn6")
2731883529b6Schristos		 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rn6)
2732883529b6Schristos		 (sequence ((SF fptemp) (SI sdtmp))
2733883529b6Schristos
2734883529b6Schristos		   (set sdtmp  (c-call SI (.str "epiphany_f" name) rd6 rn6 rn6))
2735883529b6Schristos
2736883529b6Schristos		   (set bnbit (lt SI sdtmp  (const SI 0)))
2737883529b6Schristos		   (set bzbit (eq SI sdtmp  (const SI 0)))
2738883529b6Schristos
2739883529b6Schristos		   (set bvsbit (or bvsbit bvbit))
2740883529b6Schristos		   (set busbit (or busbit bubit))
2741883529b6Schristos		   (set bisbit (or bisbit bibit))
2742883529b6Schristos
2743883529b6Schristos		   (set rd6 sdtmp)
2744883529b6Schristos
2745883529b6Schristos		   )
2746883529b6Schristos		 ()
2747883529b6Schristos		 )
2748883529b6Schristos
2749883529b6Schristos    (dnmi (.sym "f_" name "f32.l")
2750883529b6Schristos	  (.str "f_" name)
27519573673dSchristos	  (NO-DIS)
2752883529b6Schristos	  (.str "f" name ".l $rd6,$rn6")
2753883529b6Schristos	  (emit (.sym "f_" name "f32")  rd6 rn6)
2754883529b6Schristos	  )
2755883529b6Schristos    )
2756883529b6Schristos  )
2757883529b6Schristos
2758883529b6Schristos(op-fix2float-float loat OPF_FLOAT)
2759883529b6Schristos
2760883529b6Schristos(define-pmacro (op-float2fix-float name code)
2761883529b6Schristos  (begin
2762883529b6Schristos    (dni_wrapper (.sym "f_" name "f16")
2763883529b6Schristos		 (.str "f_" name)
2764883529b6Schristos		 (SHORT-INSN)
2765883529b6Schristos		 (.str "f" name " $rd,$rn")
2766883529b6Schristos		 (+ OP4_DSP16 code rd rn rn)
2767883529b6Schristos		 (sequence ((SF fptemp) (SI sdtmp))
2768883529b6Schristos
2769883529b6Schristos		   (set sdtmp  (c-call SI (.str "epiphany_f" name) rd rn rn))
2770883529b6Schristos
2771883529b6Schristos		   (set bzbit (zflag sdtmp))
2772883529b6Schristos		   (set bnbit (nflag sdtmp))
2773883529b6Schristos
2774883529b6Schristos		   (set bvbit  (c-call BI "get_epiphany_foverflowflag" sdtmp))
2775883529b6Schristos		   (set bubit  (c-call BI "get_epiphany_funderflowflag" sdtmp))
2776883529b6Schristos		   (set bibit  (c-call BI "get_epiphany_finvalidflag" sdtmp))
2777883529b6Schristos
2778883529b6Schristos		   (set bvsbit (or bvsbit bvbit))
2779883529b6Schristos		   (set busbit (or busbit bubit))
2780883529b6Schristos		   (set bisbit (or bisbit bibit))
2781883529b6Schristos
2782883529b6Schristos		   (set rd6 sdtmp)
2783883529b6Schristos
2784883529b6Schristos		   (if (or (and invExcEnbit bisbit)
2785883529b6Schristos			   (or (and ovfExcEnbit busbit)
2786883529b6Schristos			       (and unExcEnbit bvsbit)))
2787883529b6Schristos		       (sequence ()
2788883529b6Schristos			 (set expcause0bit (const 1))
2789883529b6Schristos			 (set expcause1bit (const 1))
2790883529b6Schristos			 (call-exception #x4 #x2)))
2791883529b6Schristos		   (set rd sdtmp)
2792883529b6Schristos		   )
2793883529b6Schristos		 ()
2794883529b6Schristos		 )
2795883529b6Schristos
2796883529b6Schristos
2797883529b6Schristos
2798883529b6Schristos    (dni_wrapper (.sym "f_" name "f32")
2799883529b6Schristos		 (.str "f_" name)
2800883529b6Schristos		 ()
2801883529b6Schristos		 (.str "f" name " $rd6,$rn6")
2802883529b6Schristos		 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rn6)
2803883529b6Schristos		 (sequence ((SF fptemp) (SI sdtmp))
2804883529b6Schristos
2805883529b6Schristos		   (set sdtmp  (c-call SI (.str "epiphany_f" name) rd6 rn6 rm6))
2806883529b6Schristos
2807883529b6Schristos		   (set bzbit (zflag sdtmp))
2808883529b6Schristos		   (set bnbit (nflag sdtmp))
2809883529b6Schristos
2810883529b6Schristos		   (set bvbit  (c-call BI "get_epiphany_foverflowflag" sdtmp))
2811883529b6Schristos		   (set bubit  (c-call BI "get_epiphany_funderflowflag" sdtmp))
2812883529b6Schristos		   (set bibit  (c-call BI "get_epiphany_finvalidflag" sdtmp))
2813883529b6Schristos
2814883529b6Schristos		   (set bvsbit (or bvsbit bvbit))
2815883529b6Schristos		   (set busbit (or busbit bubit))
2816883529b6Schristos		   (set bisbit (or bisbit bibit))
2817883529b6Schristos
2818883529b6Schristos		   (set rd6 sdtmp)
2819883529b6Schristos
2820883529b6Schristos		   (if (or (and invExcEnbit bisbit)
2821883529b6Schristos			   (or (and ovfExcEnbit busbit)
2822883529b6Schristos			       (and unExcEnbit bvsbit)))
2823883529b6Schristos		       (sequence ()
2824883529b6Schristos			 (set expcause0bit (const 1))
2825883529b6Schristos			 (set expcause1bit (const 1))
2826883529b6Schristos			 (call-exception #x4 #x2))
2827883529b6Schristos		       )
2828883529b6Schristos
2829883529b6Schristos		   )
2830883529b6Schristos		 ()
2831883529b6Schristos		 )
2832883529b6Schristos
2833883529b6Schristos    (dnmi (.sym "f_" name "f32.l")
2834883529b6Schristos	  (.str "f_" name)
28359573673dSchristos	  (NO-DIS)
2836883529b6Schristos	  (.str "f" name ".l $rd6,$rn6")
2837883529b6Schristos	  (emit (.sym "f_" name "f32") rd6  rn6)
2838883529b6Schristos	  )
2839883529b6Schristos
2840883529b6Schristos
2841883529b6Schristos    )
2842883529b6Schristos  )
2843883529b6Schristos
2844883529b6Schristos
2845883529b6Schristos
2846883529b6Schristos
2847883529b6Schristos
2848883529b6Schristos(op-float2fix-float ix OPF_FIX)
2849883529b6Schristos
2850883529b6Schristos;; MAC (Multiply and Accumulate Instructions
2851883529b6Schristos;; (define-pmacro (op-mac-float name code)
2852883529b6Schristos;;   (begin
2853883529b6Schristos;;     (dni_wrapper (.sym "fm" name "f16")
2854883529b6Schristos;; 	 (.str "fm" name)
2855883529b6Schristos;; 	 (SHORT-INSN)
2856883529b6Schristos;; 	 (.str "fm" name " $frd,$frn,$frm")
2857883529b6Schristos;; 	 (+ OP4_DSP16 code frd frn frm)
2858883529b6Schristos;; 	 (sequence ((SF fptemp))
2859883529b6Schristos;; 		   (set bvbit 0)
2860883529b6Schristos;; 		   (set busbit 0)
2861883529b6Schristos;;                    (set fptemp (c-call SF (.str "epiphany_fm" name) frd frm frn))
2862883529b6Schristos;; 		   (set bnbit (lt SF fptemp (const SF 0)))
2863883529b6Schristos;; 		   (set bzbit (eq SF fptemp (const SF 0)))
2864883529b6Schristos;; 		   (set bvsbit (or bvsbit bvbit))
2865883529b6Schristos;;                    (set frd fptemp)
2866883529b6Schristos;; ;		   (set rd (subword SI frd 0))
2867883529b6Schristos;; 		   )
2868883529b6Schristos;; 	 ()
2869883529b6Schristos;; 	 )
2870883529b6Schristos
2871883529b6Schristos;;     (dni_wrapper (.sym "fm" name "f32")
2872883529b6Schristos;; 	 (.str "fm" name)
2873883529b6Schristos;; 	 ()
2874883529b6Schristos;; 	 (.str "fm" name " $frd6,$frn6,$frm6")
2875883529b6Schristos;; 	 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) frd6 frn6 frm6)
2876883529b6Schristos;; 	 (sequence ((SF fptemp))
2877883529b6Schristos;; 		   (set bvbit 0)
2878883529b6Schristos;; 		   (set busbit 0)
2879883529b6Schristos;;                    (set fptemp (c-call SF (.str "epiphany_fm" name) frd6 frm6 frn6))
2880883529b6Schristos;; 		   (set bnbit (lt SF fptemp (const SF 0)))
2881883529b6Schristos;; 		   (set bzbit (eq SF fptemp (const SF 0)))
2882883529b6Schristos;; 		   (set bvsbit (or bvsbit bvbit))
2883883529b6Schristos;;                    (set frd6 fptemp)
2884883529b6Schristos;; ;		   (set rd6 (subword SI frd6 0))
2885883529b6Schristos;; 		   )
2886883529b6Schristos;; 	 ()
2887883529b6Schristos;; 	 )
2888883529b6Schristos;;     )
2889883529b6Schristos;; )
2890883529b6Schristos
2891883529b6Schristos
2892883529b6Schristos
2893883529b6Schristos
2894883529b6Schristos
2895883529b6Schristos
2896883529b6Schristos
2897883529b6Schristos					; extended floating point operation
2898883529b6Schristos
2899883529b6Schristos
2900883529b6Schristos(define-pmacro (op-fextop-float name code)
2901883529b6Schristos  (begin
2902883529b6Schristos
2903883529b6Schristos    (dni_wrapper (.sym "f_" name "f32")
2904883529b6Schristos		 (.str "f_" name)
2905883529b6Schristos		 ()
2906883529b6Schristos		 (.str "f" name " $frd6,$frn6")
2907883529b6Schristos		 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-2 #x0) (f-dc-20-1 #x1) frd6 frn6 frn6)
2908883529b6Schristos		 (sequence ((SF fptemp))
2909883529b6Schristos			   (set bvbit 0)
2910883529b6Schristos			   (set busbit 0)
2911883529b6Schristos			   (set fptemp (c-call SF (.str "epiphany_f" name) frn6))
2912883529b6Schristos			   (set bnbit (lt SF fptemp (const SF 0)))
2913883529b6Schristos			   (set bzbit (eq SF fptemp (const SF 0)))
2914883529b6Schristos			   (set bvsbit (or bvsbit bvbit))
2915883529b6Schristos			   (set frd6 fptemp)
2916883529b6Schristos
2917883529b6Schristos			   )
2918883529b6Schristos		 ()
2919883529b6Schristos		 )
2920883529b6Schristos
2921883529b6Schristos
2922883529b6Schristos    (dnmi (.sym "f_" name "f32.l")
2923883529b6Schristos	  (.str "f_" name)
29249573673dSchristos	  (NO-DIS)
2925883529b6Schristos	  (.str "f" name ".l $frd6,$frn6")
2926883529b6Schristos	  (emit (.sym "f_" name "f32") frd6 frn6)
2927883529b6Schristos	  )
2928883529b6Schristos    )
2929883529b6Schristos  )
2930883529b6Schristos
2931883529b6Schristos(op-fextop-float recip OPF_FRECIP)
2932883529b6Schristos(op-fextop-float sqrt  OPF_FSQRT)
2933883529b6Schristos
2934883529b6Schristos
2935883529b6Schristos
2936883529b6Schristos
2937883529b6Schristos
2938