1 ; Adapteva EPIPHANY CPU description. -*- Scheme -*-
2 ; Copyright 1998, 1999, 2000, 2001, 2003, 2006, 2007, 2008, 2009, 2010, 2011
3 ; Free Software Foundation, Inc.
5 ; Contributed by Embecosm on behalf of Adapteva, Inc.
6 ; This file is part of the GNU Binutils and of GDB.
8 ; This program is free software; you can redistribute it and/or modify
9 ; it under the terms of the GNU General Public License as published by
10 ; the Free Software Foundation; either version 3 of the License, or
11 ; (at your option) any later version.
13 ; This program is distributed in the hope that it will be useful,
14 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ; GNU General Public License for more details.
18 ; You should have received a copy of the GNU General Public License
19 ; along with this program; if not, write to the Free Software
20 ; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 (include "simplify.inc")
24 ; define-arch must appear first
27 (name epiphany) ; name of cpu family
28 (comment "Adapteva, Inc. EPIPHANY family")
29 (default-alignment aligned)
32 ; - a 16/32 bit instruction machine (the default)
44 (comment "instruction is a 16 bit form")
47 ;; 3 bit add/sub immediate forms - useful for relaxing into 11 bit form
52 (comment "instruction has a 3 bit immediate form")
55 ;; 8 bit mov immediate forms - useful for relaxing into 16 bit form
60 (comment "instruction has a 8 bit immediate form")
63 ; Instruction set parameters.
67 (comment "Adapteva, Inc. EPIPHANY32 ISA")
69 (default-insn-word-bitsize 32)
70 (default-insn-bitsize 32)
71 (base-insn-bitsize 32)
72 (decode-assist (3 2 1 0)) ; CGEN can figure this out
73 (liw-insns 1) ; # instructions fetched at once
76 ; Cpu family definitions.
80 ; cpu names must be distinct from the architecture name and machine names.
82 (comment "Adapteva, Inc. EPIPHANY Family")
89 (comment "Adapteva, Inc. EPIPHANY Family")
97 (comment "Adapteva EPIPHANY")
102 ; Model descriptions.
105 (name epiphany32) (comment "Adapteva EPIPHANY 32/16") (attrs)
108 (unit u-exec "Execution Unit" ()
113 () ; profile action (default)
119 ; Instruction fields.
122 ; XXX: what EPIPHANY attrs
123 ; PCREL-ADDR: pc relative value (for reloc and disassembly purposes)
124 ; ABS-ADDR: absolute address (for reloc and disassembly purposes?)
125 ; RESERVED: bits are not used to decode insn, must be all 0
126 ; RELOC: there is a relocation associated with this field
132 (comment "there is a reloc associated with this field (experiment)")
135 ;; define the fields of the instruction.
136 ;; name description ATTR MSB LEN
137 (dnf f-opc "primary opcode" () 3 4)
138 (dnf f-opc-4-1 "secondary opcode" () 4 1)
139 (dnf f-opc-6-3 "secondary opcode" () 6 3) ;;
140 (dnf f-opc-8-5 "tertiary opcode" () 8 5) ;;
141 (dnf f-opc-19-4 "additional opcode bits" () 19 4)
142 (dnf f-condcode "condition codes" () 7 4)
143 (dnf f-secondary-ccs "flag for secondary ccs" () 7 1)
144 (dnf f-shift "shift amount" () 9 5)
145 (dnf f-wordsize "load/store size" () 6 2)
146 (dnf f-store "load/store flag" () 4 1) ;; 0==load,1==store
147 (dnf f-opc-8-1 "opcode bits" () 8 1)
148 (dnf f-opc-31-32 "all opcode set" () 31 32)
150 (df f-simm8 "branch displacement" (PCREL-ADDR RELOC) 15 8 INT
151 ((value pc) (sra SI (sub SI value pc) 1))
152 ((value pc) (add SI (sll SI value 1) pc)))
154 (df f-simm24 "branch displacement" (PCREL-ADDR RELOC) 31 24 INT
155 ((value pc) (sra SI (sub SI value pc) 1))
156 ((value pc) (add SI (sll SI value 1) pc)))
158 (df f-sdisp3 "signed immediate 3 bit" () 9 3 INT #f #f)
160 (dnf f-disp3 "address offset" () 9 3)
161 (dnf f-disp8 "address offset" () 23 8)
163 (dnf f-imm8 "move/add/sub imm8" () 12 8)
164 (dnf f-imm-27-8 "move/add/sub imm16" () 27 8)
165 (dnf f-addsubx "+/- index address" () 20 1)
166 (dnf f-subd "+/- displ address" () 24 1)
167 (dnf f-pm "post-modify immediate" () 25 1)
169 (dnf f-rm "short rm" () 9 3) ;; RM
170 (dnf f-rn "short rn" () 12 3) ;; RN
171 (dnf f-rd "short rd" () 15 3) ;; RD
173 (dnf f-rm-x "extension rm" () 25 3) ;; RM
174 (dnf f-rn-x "extension rn" () 28 3) ;; RN
175 (dnf f-rd-x "extension rd" () 31 3) ;; RD
177 (dnf f-dc-9-1 "DC" (RESERVED) 9 1)
179 (dnf f-sn "short sn" () 12 3) ;; SN
180 (dnf f-sd "short sd" () 15 3) ;; SD
182 (dnf f-sn-x "extension sn" () 28 3) ;; SN
183 (dnf f-sd-x "extension sd" () 31 3) ;; SD
187 (dnf f-dc-7-4 "movts zeros" () 7 4)
188 (dnf f-trap-swi-9-1 "trap or swi" () 9 1)
189 (dnf f-gien-gidis-9-1 "gien or gidis" () 9 1)
192 (dnf f-dc-15-3 "DC" (RESERVED) 15 3)
193 (dnf f-dc-15-7 "DC" (RESERVED) 15 7)
194 (dnf f-dc-15-6 "DC" () 15 6)
195 (dnf f-trap-num "trap number" () 15 6)
197 (dnf f-dc-20-1 "DC" (RESERVED) 20 1)
199 (dnf f-dc-21-1 "DC" (RESERVED) 21 1)
200 (dnf f-dc-21-2 "DC" (RESERVED) 21 2)
202 (dnf f-dc-22-3 "DC" (RESERVED) 22 3)
203 (dnf f-dc-22-2 "DC" (RESERVED) 22 2)
204 (dnf f-dc-22-1 "DC" (RESERVED) 22 1)
206 (dnf f-dc-25-6 "DC" (RESERVED) 25 6)
207 (dnf f-dc-25-4 "DC" (RESERVED) 25 4)
208 (dnf f-dc-25-2 "DC" (RESERVED) 25 2)
209 (dnf f-dc-25-1 "DC" (RESERVED) 25 1)
211 (dnf f-dc-28-1 "DC" (RESERVED) 28 1)
212 (dnf f-dc-31-3 "DC" (RESERVED) 31 3)
214 (dnmf f-disp11 "Unsigned offset for load/store" () UINT (f-disp3 f-disp8)
216 (set (ifield f-disp8) (and (srl (ifield f-disp11) 3) (const 255)))
217 (set (ifield f-disp3) (and (ifield f-disp11) 7)))
219 (set (ifield f-disp11) (or (sll (ifield f-disp8) 3)
225 (dnmf f-sdisp11 "Signed offset for load/store" () INT (f-disp3 f-disp8)
227 (set (ifield f-disp8) (and #xff (srl SI (ifield f-sdisp11) 3)))
228 (set (ifield f-disp3) (and SI (ifield f-sdisp11) 7)))
230 (set (ifield f-sdisp11)
231 (sra SI (sll SI (or SI (sll (ifield f-disp8) 3)
237 (dnmf f-imm16 "Short immediate for move/add/sub" () UINT (f-imm8 f-imm-27-8)
239 (set (ifield f-imm8) (and (ifield f-imm16) #xff))
240 (set (ifield f-imm-27-8) (srl (ifield f-imm16) 8)))
242 (set (ifield f-imm16) (or (sll (ifield f-imm-27-8) 8)
247 ;; 32 bit instructions have the register number broken into two non-contiguous fields
249 (define-pmacro (x-reg-field reg)
251 (name (.sym "f-" reg "6"))
253 (subfields (.sym "f-" reg "-x") (.sym "f-" reg))
255 (set (ifield (.sym "f-" reg)) (and (ifield (.sym "f-" reg "6"))
257 (set (ifield (.sym "f-" reg "-x")) (srl (ifield (.sym "f-" reg "6"))
260 (extract (sequence ()
261 (set (ifield (.sym "f-" reg "6")) (or (sll (ifield (.sym "f-" reg "-x"))
263 (ifield (.sym "f-" reg))))
268 (x-reg-field rd) ; f-rd6
269 (x-reg-field rn) ; f-rn6
270 (x-reg-field rm) ; f-rm6
271 (x-reg-field sd) ; f-sd6
272 (x-reg-field sn) ; f-sn6
279 ; insn-opc: bits 3..0 - major family selector
280 (define-normal-insn-enum insn-opc "opc enums" () OP4_ f-opc
288 LSHIFT16 ;; 0110 - logical shift
289 DSP16 ;; 0111 - 3 reg DSP 16 bit insns
292 ALU16 ;; 1010 - 3 reg 16 bit
296 ASHIFT16 ;; 1110 ASR, BITR
297 MISC ;; 1111 - 32 bit shifts, 3 reg ALU, 3 reg DSP, FLOW, BITR
301 (define-normal-insn-enum insn-wordsize "memory access width" () OPW_ f-wordsize
302 ; specifies the size of a memory load/store operation
303 (BYTE SHORT WORD DOUBLE)
306 (define-normal-insn-enum insn-memory-access "memory access direction" () OP_ f-store
311 ; enum for trap codes used by simulator
312 (define-normal-insn-enum trap-codes "trap instruction dispatch code" () TRAP_ f-trap-num
313 (write read open exit pass fail close other)
316 ; cond branch: bits 7..4
318 (define-normal-insn-enum insn-cond "branch conditions" () OPC_ f-condcode
319 (EQ NE GTU GTEU LTEU LTU GT GTE LT LTE BEQ BNE BLT BLTE B BL))
321 ; dsp 3 operand opcodes
322 (define-normal-insn-enum insn-bop "binary operator subcodes" () OPB_ f-opc-6-3
323 (EOR ADD LSL SUB LSR AND ASR ORR))
325 ; dsp 3 operand opcodes
326 (define-normal-insn-enum insn-bopext "binary operator subcodes" () OPBE_ f-opc-6-3
327 (FEXT FDEP LFSR - - - - -))
330 (define-normal-insn-enum insn-fop "floating operators" () OPF_ f-opc-6-3
331 (ADD SUB MUL MADD MSUB FLOAT FIX FABS))
333 (define-normal-insn-enum insn-fopexn "extended floating operators" () OPF_ f-opc-6-3
334 (FRECIP FSQRT - - - - - -))
339 ; Immediate operation secondary opcodes
340 (define-normal-insn-enum insn-immop "immediate operators" () OPI_ f-opc-6-3
341 (- ADD - SUB - - - TRAP) ; TRAP is special extension for simulator
345 (define-normal-insn-enum insn-dc-25-2 "don't cares" () OPI_25_2_ f-dc-25-2
348 ; General Register keyword names.
351 (print-name h-registers)
354 ; some preferred aliases
355 (sb 9) (sl 10) (fp 11) (ip 12) (sp 13) (lr 14)
356 ; the default register names
357 (r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
358 (r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15)
359 (r16 16) (r17 17) (r18 18) (r19 19) (r20 20) (r21 21) (r22 22) (r23 23)
360 (r24 24) (r25 25) (r26 26) (r27 27) (r28 28) (r29 29) (r30 30) (r31 31)
361 (r32 32) (r33 33) (r34 34) (r35 35) (r36 36) (r37 37) (r38 38) (r39 39)
362 (r40 40) (r41 41) (r42 42) (r43 43) (r44 44) (r45 45) (r46 46) (r47 47)
363 (r48 48) (r49 49) (r50 50) (r51 51) (r52 52) (r53 53) (r54 54) (r55 55)
364 (r56 56) (r57 57) (r58 58) (r59 59) (r60 60) (r61 61) (r62 62) (r63 63)
365 ; some less popular aliases
366 (a1 0) (a2 1) (a3 2) (a4 3) (v1 4) (v2 5) (v3 6) (v4 7)
367 (v5 8) (v6 9) (v7 10) (v8 11)
371 (define-normal-insn-enum post-index "+/- index register" () DIR_ f-addsubx (POSTINC POSTDEC))
373 (define-normal-insn-enum disp-post-modify "postmodify displacement" () PMOD_ f-pm (DISP POST))
375 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
379 ;; 64 general-purpose registers
382 (comment "all addressable registers")
383 (type register SI (64))
384 (attrs PROFILE CACHE-ADDR)
385 (indices extern-keyword gr-names)
390 ;; Same 64 registers as floating point registers
393 (comment "all GPRs as float values")
394 (type register SF (64))
395 (attrs PROFILE VIRTUAL)
396 (indices extern-keyword gr-names)
397 (get (index) (subword SF (reg h-registers index) 0))
398 (set (index newval) (set (reg h-registers index) (subword SI newval 0)))
401 ;; define processor status bits as physical hardware
403 (define-pmacro (psw-h-bit name cmt)
404 (dsh name cmt () (register BI)))
406 (psw-h-bit h-zbit "integer zero bit")
407 (psw-h-bit h-nbit "integer neg bit")
408 (psw-h-bit h-cbit "integer carry bit")
409 (psw-h-bit h-vbit "integer overflow bit")
410 (psw-h-bit h-vsbit "integer overflow sticky")
413 (psw-h-bit h-bzbit "floating point zero bit")
414 (psw-h-bit h-bnbit "floating point neg bit")
415 (psw-h-bit h-bvbit "floating point ovfl bit")
416 (psw-h-bit h-bubit "floating point underfl bit")
417 (psw-h-bit h-bibit "floating point invalid bit")
418 (psw-h-bit h-bcbit "floating point carry bit")
420 (psw-h-bit h-bvsbit "floating point overflow sticky")
421 (psw-h-bit h-bisbit "floating point invalid sticky")
422 (psw-h-bit h-busbit "floating point underflow sticky")
424 (psw-h-bit h-expcause0bit "exceprion cause bit0")
425 (psw-h-bit h-expcause1bit "exceprion cause bit1")
426 (psw-h-bit h-expcause2bit "external load stalled bit")
427 (psw-h-bit h-extFstallbit "external fetch stalled bit")
429 (psw-h-bit h-trmbit "0=round to nearest, 1=trunacte select bit")
430 (psw-h-bit h-invExcEnbit "invalid exception enable bit")
431 (psw-h-bit h-ovfExcEnbit "overflow exception enable bit")
432 (psw-h-bit h-unExcEnbit "underflow exception enablebit ")
434 (psw-h-bit h-timer0bit0 "timer 0 mode selection 0")
435 (psw-h-bit h-timer0bit1 "timer 0 mode selection 1")
436 (psw-h-bit h-timer0bit2 "timer 0 mode selection 2")
437 (psw-h-bit h-timer0bit3 "timer 0 mode selection 3")
438 (psw-h-bit h-timer1bit0 "timer 1 mode selection 0")
439 (psw-h-bit h-timer1bit1 "timer 1 mode selection 1")
440 (psw-h-bit h-timer1bit2 "timer 1 mode selection 2")
441 (psw-h-bit h-timer1bit3 "timer 1 mode selection 3")
443 (psw-h-bit h-mbkptEnbit "multicore bkpt enable")
444 (psw-h-bit h-clockGateEnbit "clock gating enable bkpt enable")
447 (psw-h-bit h-coreCfgResBit12 "core config bit 12")
448 (psw-h-bit h-coreCfgResBit13 "core config bit 13")
449 (psw-h-bit h-coreCfgResBit14 "core config bit 14")
450 (psw-h-bit h-coreCfgResBit15 "core config bit 15")
451 (psw-h-bit h-coreCfgResBit16 "core config bit 16")
454 (psw-h-bit h-coreCfgResBit20 "core config bit 20")
455 (psw-h-bit h-coreCfgResBit21 "core config bit 21")
457 (psw-h-bit h-coreCfgResBit24 "core config bit 24")
458 (psw-h-bit h-coreCfgResBit25 "core config bit 25")
459 (psw-h-bit h-coreCfgResBit26 "core config bit 26")
460 (psw-h-bit h-coreCfgResBit27 "core config bit 27")
461 (psw-h-bit h-coreCfgResBit28 "core config bit 28")
462 (psw-h-bit h-coreCfgResBit29 "core config bit 29")
463 (psw-h-bit h-coreCfgResBit30 "core config bit 30")
464 (psw-h-bit h-coreCfgResBit31 "core config bit 31")
467 (psw-h-bit h-arithmetic-modebit0 "arithmetic mode bit0")
468 (psw-h-bit h-arithmetic-modebit1 "arithmetic mode bit1")
469 (psw-h-bit h-arithmetic-modebit2 "arithmetic mode bit2")
472 (psw-h-bit h-gidisablebit "global interrupt disable bit")
473 (psw-h-bit h-kmbit "kernel mode bit")
474 (psw-h-bit h-caibit "core active indicator mode bit")
475 (psw-h-bit h-sflagbit "sflag bit")
478 ; Define operands for each of the physical bits
479 (define-pmacro (psw-bit name hname cmt)
480 (dnop name cmt (SEM-ONLY) hname f-nil)
483 (psw-bit zbit h-zbit "integer zero bit")
484 (psw-bit nbit h-nbit "integer neg bit")
485 (psw-bit cbit h-cbit "integer carry bit")
486 (psw-bit vbit h-vbit "integer overflow bit")
488 (psw-bit bzbit h-bzbit "floating point zero bit")
489 (psw-bit bnbit h-bnbit "floating point neg bit")
490 (psw-bit bvbit h-bvbit "floating point ovfl bit")
491 (psw-bit bcbit h-bcbit "floating point carry bit")
493 (psw-bit bubit h-bubit "floating point underfl bit")
494 (psw-bit bibit h-bibit "floating point invalid bit")
497 (psw-bit vsbit h-vsbit "integer overflow sticky")
498 (psw-bit bvsbit h-bvsbit "floating point overflow sticky")
499 (psw-bit bisbit h-bisbit "floating point invalid sticky")
500 (psw-bit busbit h-busbit "floating point underflow sticky")
501 (psw-bit expcause0bit h-expcause0bit "exceprion cause bit0")
502 (psw-bit expcause1bit h-expcause1bit "exceprion cause bit1")
505 (psw-bit expcause2bit h-expcause2bit "external load stalled bit")
506 (psw-bit extFstallbit h-extFstallbit "external fetch stalled bit")
508 (psw-bit trmbit h-trmbit "0=round to nearest, 1=trunacte selct bit")
509 (psw-bit invExcEnbit h-invExcEnbit "invalid exception enable bit")
510 (psw-bit ovfExcEnbit h-ovfExcEnbit "overflow exception enable bit")
511 (psw-bit unExcEnbit h-unExcEnbit "underflow exception enable bit")
513 (psw-bit timer0bit0 h-timer0bit0 "timer 0 mode selection 0")
514 (psw-bit timer0bit1 h-timer0bit1 "timer 0 mode selection 1")
515 (psw-bit timer0bit2 h-timer0bit2 "timer 0 mode selection 2")
516 (psw-bit timer0bit3 h-timer0bit3 "timer 0 mode selection 3")
518 (psw-bit timer1bit0 h-timer1bit0 "timer 1 mode selection 0")
519 (psw-bit timer1bit1 h-timer1bit1 "timer 1 mode selection 1")
520 (psw-bit timer1bit2 h-timer1bit2 "timer 1 mode selection 2")
521 (psw-bit timer1bit3 h-timer1bit3 "timer 1 mode selection 3")
523 (psw-bit mbkptEnbit h-mbkptEnbit "multicore bkpt enable")
524 (psw-bit clockGateEnbit h-clockGateEnbit "clock gate enable enable")
526 (psw-bit arithmetic-modebit0 h-arithmetic-modebit0 "arithmetic mode bit0")
527 (psw-bit arithmetic-modebit1 h-arithmetic-modebit1 "arithmetic mode bit1")
528 (psw-bit arithmetic-modebit2 h-arithmetic-modebit2 "arithmetic mode bit2")
530 (psw-bit coreCfgResBit12 h-coreCfgResBit12 "core config bit 12")
531 (psw-bit coreCfgResBit13 h-coreCfgResBit13 "core config bit 13")
532 (psw-bit coreCfgResBit14 h-coreCfgResBit14 "core config bit 14")
533 (psw-bit coreCfgResBit15 h-coreCfgResBit15 "core config bit 15")
534 (psw-bit coreCfgResBit16 h-coreCfgResBit16 "core config bit 16")
536 (psw-bit coreCfgResBit20 h-coreCfgResBit20 "core config bit 20")
537 (psw-bit coreCfgResBit21 h-coreCfgResBit21 "core config bit 21")
539 (psw-bit coreCfgResBit24 h-coreCfgResBit24 "core config bit 24")
540 (psw-bit coreCfgResBit25 h-coreCfgResBit25 "core config bit 25")
541 (psw-bit coreCfgResBit26 h-coreCfgResBit26 "core config bit 26")
542 (psw-bit coreCfgResBit27 h-coreCfgResBit27 "core config bit 27")
543 (psw-bit coreCfgResBit28 h-coreCfgResBit28 "core config bit 28")
544 (psw-bit coreCfgResBit29 h-coreCfgResBit29 "core config bit 29")
545 (psw-bit coreCfgResBit30 h-coreCfgResBit30 "core config bit 30")
546 (psw-bit coreCfgResBit31 h-coreCfgResBit31 "core config bit 31")
549 (psw-bit gidisablebit h-gidisablebit "global interrupt disable bit")
550 (psw-bit kmbit h-kmbit "kernel mode bit")
551 (psw-bit caibit h-caibit "core actibe indicator bit")
552 (psw-bit sflagbit h-sflagbit "sflag bit")
557 ;; Special registers - accessed via MOVTS and MOVFS.
559 ;; "Core control and status" in group MR0=0, MR1=0
563 (print-name h-core-registers)
566 (status 1) ; unified condition codes
567 (pc 2) ; virtualized PC
570 (lc 5);loop counter Not impemented
571 (ls 6);loop start address Not impemented
572 (le 7);loop end address Not impemented
584 ;; DMA registers in group MR0=1, MR1=0
588 (print-name h-coredma-registers)
619 ;; mem configuration registers in group MR0=0, MR1=1
623 (print-name h-coremem-registers)
633 ;; mesh configuration registers in group MR0=1, MR1=1
637 (print-name h-coremesh-registers)
653 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
654 ; PC is a byte-addressed register
655 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
657 (dnh h-pc "program counter" (PC PROFILE) (pc) () () ())
659 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
660 ; Memory Effective Address wants to be visible
661 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663 (dnh h-memaddr "memory effective address" (PROFILE) (register SI) () () ())
664 (dnop memaddr "memory effective address" (SEM-ONLY) h-memaddr f-nil)
666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
667 ; Special Core Registers
668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
670 ;; [0]=core active indicator
671 ;; [1]=global interrupt disable
672 ;; [2]=processor mode(1=user mode, 0=kernel mode)
673 ;; [3]=wired AND global flag
675 ;; [4]=integer zero zbit
676 ;; [5]=integer negative nbit
677 ;; [6]=integer carry cbit
678 ;; [7]=integer overflow vbit
680 ;; [8]=fpu zero flag bzbit
681 ;; [9]=fpu negative flag bnbit
682 ;; [10]=fpu overflow flag bvbit
683 ;; [11]=fpu carry flag(not used) bcbit
685 ;; [12]=ialu overflow flag(sticky) vsbit
686 ;; [13]=fpu invalid flag(sticky) bisbit
687 ;; [14]=fpu overflow flag(sticky) bvsbit
688 ;; [15]=fpu underflow flag(sticky) busbit
690 ;; [17:16]=exception cause 00=no exception 01=load-store exception 10=fpu exception 11=unimplemented instruction
694 ;; [18]=external load stalled expcause2bit
695 ;; [19]=external fetch stalled extFstallbit
704 (name h-core-registers)
705 (comment "Special Core Registers")
706 (type register USI (17))
708 (indices extern-keyword cr-names)
711 ((eq index (const 1)) ; STATUS reg ?
712 (or (or (or (or (sll USI kmbit (const 2))
713 (sll USI gidisablebit (const 1)))
714 (or (or (sll USI expcause1bit (const 17))
715 (sll USI expcause0bit (const 16)))
716 (or (sll USI expcause2bit (const 18))
717 (sll USI extFstallbit (const 19)))))
718 (or (or (or (sll USI busbit (const 15))
719 (sll USI bisbit (const 13)))
720 (or (sll USI bvsbit (const 14))
721 (sll USI vsbit (const 12))))
722 (or (or (sll USI bvbit (const 10))
723 (sll USI bcbit (const 11)))
724 (or (sll USI bnbit (const 9))
725 (sll USI bzbit (const 8))))))
726 (or (or (or (sll USI vbit (const 7))
727 (sll USI cbit (const 6)))
728 (or (sll USI nbit (const 5))
729 (sll USI zbit (const 4))))
730 (or (sll USI sflagbit (const 3))
731 (sll USI (const 1) (const 0)))))) ;caibit
732 ((eq index (const 0)) ; Config reg ?
733 (or (or (or (or (or (or (sll USI timer0bit2 (const 6))
734 (sll USI timer0bit3 (const 7)))
735 (or (or (sll USI coreCfgResBit28 (const 28))
736 (sll USI coreCfgResBit29 (const 29)))
737 (or (sll USI coreCfgResBit30 (const 30))
738 (sll USI coreCfgResBit31 (const 31)))))
739 (or (or (sll USI coreCfgResBit24 (const 24))
740 (sll USI coreCfgResBit25 (const 25)))
741 (or (sll USI coreCfgResBit26 (const 26))
742 (sll USI coreCfgResBit27 (const 27)))))
743 (or (or (sll USI timer0bit0 (const 4))
744 (sll USI timer0bit1 (const 5)))
745 (or (sll USI coreCfgResBit14 (const 14))
746 (sll USI coreCfgResBit15 (const 15)))))
747 (or (or (or (or (sll USI timer1bit2 (const 10))
748 (sll USI timer1bit3 (const 11)))
749 (or (sll USI coreCfgResBit12 (const 12))
750 (sll USI coreCfgResBit13 (const 13))))
751 (or (sll USI clockGateEnbit (const 22))
752 (sll USI mbkptEnbit (const 23))))
753 (or (or (sll USI timer1bit0 (const 8))
754 (sll USI timer1bit1 (const 9)))
755 (or (sll USI coreCfgResBit20 (const 20))
756 (sll USI coreCfgResBit21 (const 21))))))
757 (or (or (sll USI invExcEnbit (const 1))
758 (sll USI ovfExcEnbit (const 2)))
759 (or (or (sll USI trmbit (const 0))
760 (sll USI unExcEnbit (const 3)))
761 (or (or (sll USI arithmetic-modebit0 (const 17))
762 (sll USI arithmetic-modebit1 (const 18)))
763 (or (sll USI arithmetic-modebit2 (const 19))
764 (sll USI coreCfgResBit16 (const 16)))))))) ;config reg
766 ((eq index (const 2)) (raw-reg USI h-pc)) ;PC reg
768 (else (raw-reg USI h-core-registers index))))
772 ((eq index (const 0)) ; CONFIG reg
774 (set trmbit (and (const 1) (srl val (const 0))))
775 (set invExcEnbit (and (const 1) (srl val (const 1))))
776 (set ovfExcEnbit (and (const 1) (srl val (const 2))))
777 (set unExcEnbit (and (const 1) (srl val (const 3))))
778 (set timer0bit0 (and (const 1) (srl val (const 4))))
779 (set timer0bit1 (and (const 1) (srl val (const 5))))
780 (set timer0bit2 (and (const 1) (srl val (const 6))))
781 (set timer0bit3 (and (const 1) (srl val (const 7))))
782 (set timer1bit0 (and (const 1) (srl val (const 8))))
783 (set timer1bit1 (and (const 1) (srl val (const 9))))
784 (set timer1bit2 (and (const 1) (srl val (const 10))))
785 (set timer1bit3 (and (const 1) (srl val (const 11))))
787 (set coreCfgResBit12 (and (const 1) (srl val (const 12))))
788 (set coreCfgResBit13 (and (const 1) (srl val (const 13))))
789 (set coreCfgResBit14 (and (const 1) (srl val (const 14))))
790 (set coreCfgResBit15 (and (const 1) (srl val (const 15))))
791 (set coreCfgResBit16 (and (const 1) (srl val (const 16))))
793 (set arithmetic-modebit0 (and (const 1) (srl val (const 17))))
794 (set arithmetic-modebit1 (and (const 1) (srl val (const 18))))
795 (set arithmetic-modebit2 (and (const 1) (srl val (const 19))))
797 (set coreCfgResBit20 (and (const 1) (srl val (const 20))))
798 (set coreCfgResBit21 (and (const 1) (srl val (const 21))))
800 (set clockGateEnbit (and (const 1) (srl val (const 22))))
801 (set mbkptEnbit (and (const 1) (srl val (const 23))))
803 (set coreCfgResBit24 (and (const 1) (srl val (const 24))))
804 (set coreCfgResBit25 (and (const 1) (srl val (const 25))))
805 (set coreCfgResBit26 (and (const 1) (srl val (const 26))))
806 (set coreCfgResBit27 (and (const 1) (srl val (const 27))))
807 (set coreCfgResBit28 (and (const 1) (srl val (const 28))))
808 (set coreCfgResBit29 (and (const 1) (srl val (const 29))))
809 (set coreCfgResBit30 (and (const 1) (srl val (const 30))))
810 (set coreCfgResBit31 (and (const 1) (srl val (const 31))))
812 (set (raw-reg USI h-core-registers index) val)
813 ;; check LSB of CONFIG for rounding mode
814 (c-call "epiphany_set_rounding_mode" val)
817 ((eq index (const 1)) ;STATUS reg ; TODO check which bits can be set or clear
818 (sequence ((USI newval))
819 (set newval (and val (const #xfff2)))
820 (set extFstallbit (and (const 1) (srl newval (const 19))))
821 (set expcause2bit (and (const 1) (srl newval (const 18))))
822 (set expcause1bit (and (const 1) (srl newval (const 17))))
823 (set expcause0bit (and (const 1) (srl newval (const 16))))
824 (set busbit (and (const 1) (srl newval (const 15))))
825 (set bisbit (and (const 1) (srl newval (const 13))))
826 (set bvsbit (and (const 1) (srl newval (const 14))))
827 (set vsbit (and (const 1) (srl newval (const 12))))
828 (set bvbit (and (const 1) (srl newval (const 10))))
829 (set bcbit (and (const 1) (srl newval (const 11))))
830 (set bnbit (and (const 1) (srl newval (const 9))))
831 (set bzbit (and (const 1) (srl newval (const 8))))
832 (set vbit (and (const 1) (srl newval (const 7))))
833 (set cbit (and (const 1) (srl newval (const 6))))
834 (set nbit (and (const 1) (srl newval (const 5))))
835 (set zbit (and (const 1) (srl newval (const 4))))
836 (set sflagbit (and (const 1) (srl newval (const 3))))
837 (set kmbit (and (const 1) (srl newval (const 2))))
838 ;;(set gie (and (const 1) (srl newval (const 1))))
839 (set (raw-reg SI h-core-registers (const 1)) newval)
841 ;; causes simulator errors
842 ;; ((eq index (const 2)) ;PC reg
845 (else (set (raw-reg USI h-core-registers index) val))
848 ; (define-pmacro (hcr-config) (reg h-core-registers 0)) etc.
849 (.splice begin (.unsplice (.map
850 (.pmacro (xname xnum)
851 (define-pmacro ((.sym hcr- xname)) (reg h-core-registers xnum)))
876 (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
882 ;; DMA registers in MMR space
884 (name h-coredma-registers)
885 (comment "DMA registers in MMR space")
886 (type register USI (16))
888 (indices extern-keyword crdma-names)
891 ;; MEM registers in MMR space
893 (name h-coremem-registers)
894 (comment "MEM registers in MMR space")
895 (type register USI (4))
897 (indices extern-keyword crmem-names)
900 ;; MEM registers in MMR space
902 (name h-coremesh-registers)
903 (comment "MESH registers in MMR space")
904 (type register USI (4))
906 (indices extern-keyword crmesh-names)
913 ; Branch displacements
916 (comment "branch address pc-relative")
920 (handlers (parse "branch_addr")))
924 (comment "branch address pc-relative")
928 (handlers (parse "branch_addr")))
931 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
933 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
935 (define-pmacro (short-regs nm group hw cmt)
941 (index (.sym "f-r" group))
942 (handlers (parse "shortregs") (print "keyword"))
946 (define-pmacro (short-regs-core nm group hw cmt)
952 (index (.sym "f-s" group))
953 (handlers (parse "shortregs") (print "keyword"))
959 (short-regs rd d h-registers "destination register")
960 (short-regs rn n h-registers "source register")
961 (short-regs rm m h-registers "source register")
963 (short-regs frd d h-fpregisters "fp destination register")
964 (short-regs frn n h-fpregisters "fp source register")
965 (short-regs frm m h-fpregisters "fp source register")
968 (dnop rd6 "destination register" () h-registers f-rd6)
969 (dnop rn6 "source register" () h-registers f-rn6)
970 (dnop rm6 "source register" () h-registers f-rm6)
972 (dnop frd6 "fp destination register" () h-fpregisters f-rd6)
973 (dnop frn6 "fp source register" () h-fpregisters f-rn6)
974 (dnop frm6 "fp source register" () h-fpregisters f-rm6)
977 (short-regs-core sd d h-core-registers "special destination")
978 (short-regs-core sn n h-core-registers "special source")
980 ; special regs (long form)
981 (dnop sd6 "special destination register" () h-core-registers f-sd6)
982 (dnop sn6 "special source register" () h-core-registers f-sn6)
984 (dnop sddma "dma register" () h-coredma-registers f-sd6)
985 (dnop sndma "dma register" () h-coredma-registers f-sn6)
986 (dnop sdmem "mem register" () h-coremem-registers f-sd6)
987 (dnop snmem "mem register" () h-coremem-registers f-sn6)
988 (dnop sdmesh "mesh register" () h-coremesh-registers f-sd6)
989 (dnop snmesh "mesh register" () h-coremesh-registers f-sn6)
991 ; Immediate literals - but don't allow register names!
992 (define-pmacro (dimmop nm cmt hwtype idx)
993 (define-operand (name nm) (comment cmt) (type hwtype) (index idx)
995 (handlers (parse "simm_not_reg")
996 (print "simm_not_reg")))
999 (dimmop simm3 "signed 3-bit literal" h-sint f-sdisp3)
1000 (dimmop simm11 "signed 11-bit literal" h-sint f-sdisp11)
1001 (dnop disp3 "short data displacement" () h-uint f-disp3)
1002 (dnop trapnum6 "parameter for swi or trap" () h-uint f-trap-num)
1004 (define-pmacro (duimmop nm cmt hwtype idx)
1005 (define-operand (name nm) (comment cmt) (type hwtype) (index idx)
1007 (handlers (parse "uimm_not_reg")
1008 (print "uimm_not_reg")))
1011 (duimmop swi_num "unsigned 6-bit swi#" h-uint f-trap-num)
1012 (duimmop disp11 "sign-magnitude data displacement" h-uint f-disp11)
1014 (dnop shift "immediate shift amount" () h-uint f-shift)
1016 (define-operand (name imm16) (comment "16-bit unsigned literal") (attrs RELAX)
1017 (type h-addr) (index f-imm16) (handlers (parse "imm16")))
1018 (define-operand (name imm8) (comment "8-bit unsigned literal") (attrs RELAX)
1019 (type h-addr) (index f-imm8) (handlers (parse "imm8")))
1023 (comment "+/- indexing")
1027 (handlers (parse "postindex")
1028 (print "postindex")))
1032 (comment "+/- magnitude immediate displacement")
1036 (handlers (parse "postindex")
1037 (print "postindex")))
1041 ;; call exception macro - no check for imask
1042 (define-pmacro (call-exception vaddr bit-in-ilat)
1043 (if (eq gidisablebit 0)
1044 (if (eq (and (hcr-imask) bit-in-ilat) 0)
1047 (set gidisablebit 1)
1048 (set (hcr-iret) (add pc (const 2)))
1049 (set (hcr-ipend) (or (hcr-ipend) (const bit-in-ilat)))
1050 (set pc (const vaddr))
1053 ;; schedule interrupt
1054 (set (hcr-ilat) (or (hcr-ilat) (const bit-in-ilat)))
1060 ;; (lc 5);loop counter Not impemented
1061 ;; (ls 6);loop start address Not impemented
1062 ;; (le 7);loop end address Not impemented
1064 ;;have callback to adjust pc in case od events ( HW loops ... )
1065 (define-pmacro (dni_wrapper isnid stdrdesc attr_ strassembl iopcode proceed null_b)
1067 (dni isnid stdrdesc attr_ strassembl iopcode
1068 (sequence () proceed
1069 (sequence ((USI tmpPC))
1070 ;;(set tmpPC (c-call USI "epiphany_post_isn_callback" pc))
1072 (if (eq pc (hcr-le))
1073 (set (hcr-lc) (sub (hcr-lc) #x1)))
1076 (not (eq (hcr-lc) #x0)))
1088 ;; Some handy macros
1091 ;; define instructions
1092 ;; Short (16 bit forms) must appear first so that instruction
1093 ;; selection can reject them and match long forms when registers
1094 ;; or immediates exceed the values in the 16 bit instructions
1100 (define-pmacro (br-insn name cond g-op)
1102 ; the 16-bit versions of branch
1103 (dni (.sym "b" name "16")
1104 (.str "Conditional Branch - 16 bit" name)
1105 (COND-CTI SHORT-INSN)
1106 (.str "b" name ".s $simm8")
1107 (+ OP4_BRANCH16 (.sym "OPC_" cond) simm8)
1114 (dnmi (.sym "b" name "16r") "relaxable conditional branch"
1115 (COND-CTI RELAXABLE)
1116 (.str "b" name " $simm8")
1117 (emit (.sym "b" name "16") simm8)
1120 (dni (.sym "b" name)
1121 (.str "Conditional Branch " name)
1123 (.str "b" name ".l $simm24")
1124 (+ OP4_BRANCH (.sym "OPC_" cond) simm24)
1131 (dnmi (.sym "b" name "32r") "relaxable conditional branch"
1133 (.str "b" name " $simm24")
1134 (emit (.sym "b" name) simm24)
1140 ; basic conditional branches for integer arithmetic
1141 (br-insn "eq" EQ (.pmacro () (eq zbit #x1)))
1142 (br-insn "ne" NE (.pmacro () (eq zbit #x0)))
1143 (br-insn "gtu" GTU (.pmacro () (and BI cbit (not BI zbit))))
1144 (br-insn "gteu" GTEU (.pmacro () (eq cbit #x1)))
1145 (br-insn "lteu" LTEU (.pmacro () (or BI (not BI cbit) zbit)))
1146 (br-insn "ltu" LTU (.pmacro () (eq cbit #x0)))
1147 (br-insn "gt" GT (.pmacro () (and BI (not BI zbit) (eq vbit nbit))))
1148 (br-insn "gte" GTE (.pmacro () (eq vbit nbit)))
1149 (br-insn "lt" LT (.pmacro () (xor BI vbit nbit)))
1150 (br-insn "lte" LTE (.pmacro () (or BI zbit (xor vbit nbit))))
1153 ; floating point condition codes (floating point instructions)
1154 (br-insn "beq" BEQ (.pmacro () (or BI bzbit bzbit)))
1155 (br-insn "bne" BNE (.pmacro () (not BI bzbit)))
1156 (br-insn "blt" BLT (.pmacro () (and BI bnbit (not bzbit))))
1157 (br-insn "blte" BLTE (.pmacro () (or BI bnbit bzbit)))
1159 ; unconditional branches
1160 (dni b16 "short unconditional branch" (UNCOND-CTI SHORT-INSN)
1162 (+ OP4_BRANCH16 OPC_B simm8)
1167 (dnmi b16r "relaxable b16"
1168 (UNCOND-CTI RELAXABLE)
1173 (dni b "long unconditional branch" (UNCOND-CTI)
1175 (+ OP4_BRANCH OPC_B simm24)
1180 (dnmi b32r "relaxable b"
1181 (UNCOND-CTI RELAXED)
1187 (dni bl16 "branch and link"
1188 (UNCOND-CTI SHORT-INSN)
1190 (+ OP4_BRANCH16 OPC_BL simm8)
1192 (set (reg h-registers 14) (add pc (const 2)))
1197 (dnmi bl16r "bl16 relaxable"
1198 (UNCOND-CTI RELAXABLE)
1202 (dni bl "branch and link"
1205 (+ OP4_BRANCH OPC_BL simm24)
1207 (set (reg h-registers 14) (add pc (const 4)))
1212 (dnmi blr "bl relaxable"
1213 (UNCOND-CTI RELAXED)
1218 (dni jr16 "unconditional jump 16"
1219 (UNCOND-CTI SHORT-INSN)
1221 (+ OP4_FLOW16 (f-opc-8-5 #x14) (f-dc-15-3 #x0) (f-dc-9-1 #x0) rn)
1227 ;; ??? Putting a constant into a multi-ifield does not work -
1228 ;; the constant gets inserted in full into each part.
1229 ;(dnmi rts "return from subroutine"
1232 ; (emit jr (rn6 14)) ; jr lr / jr r14
1235 (dni rts "return from subroutine"
1238 (+ OP4_MISC (f-opc-8-5 #x14) (f-opc-19-4 #x2) (f-rn 6) (f-rn-x 1)
1244 (set pc (reg h-registers 14))
1248 (dni jr "unconditional jump"
1251 (+ OP4_MISC (f-opc-8-5 #x14) (f-opc-19-4 #x2) rn6
1263 (dni jalr16 "jump and link register"
1264 (UNCOND-CTI SHORT-INSN)
1266 (+ OP4_FLOW16 (f-opc-8-5 #x15) (f-dc-15-3 #x0) (f-dc-9-1 #x0) rn)
1268 (set (reg h-registers 14) (add pc (const 2)))
1274 (dni jalr "jump and link register"
1288 (set (reg h-registers 14) (add pc (const 4)))
1294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1295 ; Load/Store Memory Instructions
1296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1299 (define-pmacro (callMisaligmentExceptionIfNeeded sel addr isAligmentAccess)
1300 (sequence ((BI scale))
1301 (set isAligmentAccess
1303 ((OPW_BYTE) (eq (and addr #x0) #x0))
1304 ((OPW_SHORT) (eq (and addr #x1) #x0))
1305 ((OPW_WORD) (eq (and addr #x3) #x0))
1306 (else (eq (and addr #x7) #x0))))
1307 (if (not BI isAligmentAccess)
1308 (call-exception #x4 #x2))
1314 ;; helper to convert size selector OPW_<mode> into a literal scale factor
1315 (define-pmacro (ConvertSelectorToShift sel scale)
1318 ((OPW_BYTE) (const 0))
1319 ((OPW_SHORT) (const 1))
1320 ((OPW_WORD) (const 2))
1324 ;; common load macros from effective address, handling 8/16/32/64 bits
1325 (define-pmacro (load-double-from-ea regnum eff-addr mode sel)
1326 (sequence ((SI loadaddr) (BI isAligmentAccess))
1327 (set loadaddr eff-addr)
1328 (callMisaligmentExceptionIfNeeded sel loadaddr isAligmentAccess)
1330 (if (not (not BI isAligmentAccess))
1332 (set memaddr loadaddr)
1333 (set regnum (mem SI loadaddr))
1334 (set loadaddr (add loadaddr (const 4)))
1335 (set memaddr loadaddr)
1336 (set (reg h-registers
1337 (add (index-of regnum)
1346 (define-pmacro (load-from-ea regnum eff-addr mode sel)
1347 (sequence ((BI isAligmentAccess))
1349 (callMisaligmentExceptionIfNeeded sel eff-addr isAligmentAccess)
1350 (if (not (not BI isAligmentAccess))
1352 (set memaddr eff-addr)
1353 (set regnum (zext SI (mem mode eff-addr)))
1357 ) ;; 8/16/32 bit cases
1360 ;; common store to effective address, handling 8/16/32/64 bit data
1361 (define-pmacro (store-double-to-ea eff-addr regnum mode sel)
1362 (sequence ((SI storeaddr) (BI isAligmentAccess))
1363 (set storeaddr eff-addr)
1364 (callMisaligmentExceptionIfNeeded sel storeaddr isAligmentAccess)
1365 (if (not (not BI isAligmentAccess))
1367 (set memaddr storeaddr)
1368 (set (mem SI storeaddr) regnum)
1369 (set storeaddr (add storeaddr (const 4)))
1370 (set memaddr storeaddr)
1371 (set (mem SI storeaddr)
1372 (reg h-registers (add (index-of regnum) (const 1))))
1378 (define-pmacro (store-to-ea eff-addr regnum mode sel)
1379 (sequence ((BI isAligmentAccess))
1380 (callMisaligmentExceptionIfNeeded sel eff-addr isAligmentAccess)
1381 (if (not (not BI isAligmentAccess))
1383 (set memaddr eff-addr)
1384 (set (mem mode eff-addr) regnum)
1388 ) ;8/16/32 bit cases
1391 (define-pmacro (load-insn name mode sel sem-op)
1393 (dni_wrapper (.sym name "x16.s")
1394 (.str "load " mode " indexed")
1396 (.str name " $rd,[$rn,$rm]")
1397 (+ OP4_LDSTR16X sel OP_LOAD rd rn rm)
1399 (sem-op rd (add rn rm) mode sel))
1404 (dni_wrapper (.sym name "p16.s")
1405 (.str "load " mode " postmodify")
1407 (.str name " $rd,[$rn],$rm")
1408 (+ OP4_LDSTR16P sel OP_LOAD rd rn rm)
1409 (sequence ((SI tmprm))
1411 (sem-op rd rn mode sel)
1412 (set rn (add rn tmprm)))
1417 (dni_wrapper (.sym name "x.l")
1418 (.str "load " mode " indexed")
1420 (.str name " $rd6,[$rn6,$direction$rm6]")
1421 (+ OP4_LDSTRX sel OP_LOAD (f-opc-19-4 #x0) (f-dc-22-1 #x0) (f-dc-21-1 #x0) rd6 rn6 direction rm6)
1423 (if (ifield f-addsubx)
1424 (sem-op rd6 (sub rn6 rm6) mode sel)
1425 (sem-op rd6 (add rn6 rm6) mode sel)))
1429 (dnmi (.sym name "x")
1430 (.str "load " mode " indexed")
1432 (.str name ".l $rd6,[$rn6,$direction$rm6]")
1433 (emit (.sym name "x.l") rd6 rn6 direction rm6)
1438 (dni_wrapper (.sym name "p.l")
1439 (.str "load " mode " postmodify")
1441 (.str name " $rd6,[$rn6],$direction$rm6")
1442 (+ OP4_LDSTRP sel OP_LOAD (f-opc-19-4 #x0) (f-dc-22-2 #x0) rd6 rn6 direction rm6)
1443 (sequence ((SI tmprm))
1445 (sem-op rd6 rn6 mode sel)
1446 (if (ifield f-addsubx)
1447 (set rn6 (sub rn6 tmprm))
1448 (set rn6 (add rn6 tmprm)))
1454 (dnmi (.sym name "p")
1455 (.str "load " mode " postmodify")
1457 (.str name ".l $rd6,[$rn6],$direction$rm6")
1458 (emit (.sym name "p.l") rd6 rn6 direction rm6)
1462 ;;immediate modes last so reg forms found first.
1463 (dni_wrapper (.sym name "d16.s")
1464 (.str "load " mode " displacement")
1466 (.str name " $rd,[$rn,$disp3]")
1467 (+ OP4_LDSTR16D sel OP_LOAD rd rn disp3) ;; convert size to 'B'
1468 (sequence ((SI effa)
1470 (ConvertSelectorToShift sel scale)
1471 (set effa (add rn (sll disp3 scale)))
1472 (sem-op rd effa mode sel)
1478 (dni_wrapper (.sym name "d.l")
1479 (.str "load " mode " displacement")
1481 (.str name " $rd6,[$rn6,$dpmi$disp11]")
1482 (+ OP4_LDSTRD sel OP_LOAD PMOD_DISP rd6 rn6 dpmi disp11)
1483 (sequence ((SI effa)
1485 (ConvertSelectorToShift sel scale)
1487 (set effa (sub rn6 (sll disp11 scale)))
1488 (set effa (add rn6 (sll disp11 scale)))
1490 (sem-op rd6 effa mode sel)
1495 (dnmi (.sym name "d")
1496 (.str "load " mode " displacement")
1498 (.str name ".l $rd6,[$rn6,$dpmi$disp11]")
1499 (emit (.sym name "d.l") rd6 rn6 dpmi disp11)
1504 (dni_wrapper (.sym name "dpm.l")
1505 (.str "load " mode " displacement post-modify")
1507 (.str name " $rd6,[$rn6],$dpmi$disp11")
1508 (+ OP4_LDSTRD sel OP_LOAD PMOD_POST rd6 rn6 dpmi disp11)
1509 (sequence ((SI scale))
1510 (ConvertSelectorToShift sel scale)
1511 (sem-op rd6 rn6 mode sel)
1513 (set rn6 (sub rn6 (sll disp11 scale)))
1514 (set rn6 (add rn6 (sll disp11 scale)))
1520 (dnmi (.sym name "dpm")
1521 (.str "load " mode " displacement post-modify")
1523 (.str name ".l $rd6,[$rn6],$dpmi$disp11")
1524 (emit (.sym name "dpm.l") rd6 rn6 dpmi disp11)
1528 ;; ;; macro form with a zero displacement
1529 (dnmi (.sym name "ds0") "load with 0 disp"
1531 (.str name " $rd,[$rn]")
1532 (emit (.sym name "d16.s") rd rn (disp3 0))
1534 (dnmi (.sym name "dl0") "load with 0 disp"
1536 (.str name " $rd6,[$rn6]")
1537 (emit (.sym name "d.l") rd6 rn6 (dpmi 0) (disp11 0))
1539 (dnmi (.sym name "dl0.l") "load with 0 disp"
1541 (.str name ".l $rd6,[$rn6]")
1542 (emit (.sym name "d.l") rd6 rn6 (dpmi 0) (disp11 0))
1549 (load-insn ldrb QI OPW_BYTE load-from-ea)
1550 (load-insn ldrh HI OPW_SHORT load-from-ea)
1551 (load-insn ldr SI OPW_WORD load-from-ea)
1552 (load-insn ldrd DI OPW_DOUBLE load-double-from-ea)
1557 ;; TMP = MEM[RD+RM]; /* Copy content of memory to tmp. */
1558 ;; if (~TMP) /* Check if memory location is zero. */
1559 ;; MEM[RD+RM] = RD; /* If zero, write RD to memory. */
1560 ;; RD = TMP; /* Always write tmp into RD (NOTE it's destructive). */
1563 (define-pmacro (testset-insn name mode sel)
1567 (dni_wrapper (.sym name "t")
1568 (.str "testset " mode " indexed")
1570 (.str name " $rd6,[$rn6,$direction$rm6]")
1571 (+ OP4_LDSTRX sel OP_LOAD (f-opc-19-4 #x0) (f-dc-22-1 #x0) (f-dc-21-1 #x1)
1572 rd6 rn6 direction rm6)
1573 (sequence ((SI tmemaddr) (SI tmpValReg))
1578 (if (ifield f-addsubx)
1579 (set tmemaddr (sub rn6 rm6))
1580 (set tmemaddr (add rn6 rm6))
1583 (load-from-ea rd6 tmemaddr mode sel)
1587 (set (mem mode tmemaddr) tmpValReg)
1595 (dnmi (.sym name "t.l")
1596 (.str "testset " mode ".l indexed")
1598 (.str name ".l $rd6,[$rn6,$direction$rm6]")
1599 (emit (.sym name "t") rd6 rn6 direction rm6)
1606 (testset-insn testsetb QI OPW_BYTE)
1607 (testset-insn testseth HI OPW_SHORT)
1608 (testset-insn testset SI OPW_WORD)
1609 ;;no double mode support, since we have to send the src address, data
1610 ;;(testset-insn testsetd DI OPW_DOUBLE load-double-from-ea)
1614 ;; need 16 bit forms too
1615 (define-pmacro (store-insn name mode sel sem-op)
1617 (dni_wrapper (.sym name "x16")
1618 (.str "store" mode " indexed")
1620 (.str name " $rd,[$rn,$rm]")
1621 (+ OP4_LDSTR16X sel OP_STORE rd rn rm)
1623 (sem-op (add rn rm) rd mode sel)
1628 (dni_wrapper (.sym name "x")
1629 (.str "store" mode " indexed")
1631 (.str name " $rd6,[$rn6,$direction$rm6]")
1632 (+ OP4_LDSTRX sel OP_STORE (f-opc-19-4 #x0) (f-dc-22-1 #x0) (f-dc-21-1 #x0) rd6 rn6 direction rm6)
1634 (if (ifield f-addsubx)
1635 (sem-op (sub rn6 rm6) rd6 mode sel)
1636 (sem-op (add rn6 rm6) rd6 mode sel)
1641 (dnmi (.sym name "x.l")
1642 (.str "store" mode " indexed")
1644 (.str name ".l $rd6,[$rn6,$direction$rm6]")
1645 (emit (.sym name "x") rd6 rn6 direction rm6)
1652 (dni_wrapper (.sym name "p16")
1653 (.str "store " mode " postmodify")
1655 (.str name " $rd,[$rn],$rm")
1656 (+ OP4_LDSTR16P sel OP_STORE rd rn rm)
1658 (sem-op rn rd mode sel)
1659 (set rn (add rn rm))
1664 (dni_wrapper (.sym name "p")
1665 (.str "store " mode " postmodify")
1667 (.str name " $rd6,[$rn6],$direction$rm6")
1668 (+ OP4_LDSTRP sel OP_STORE (f-opc-19-4 #x0) (f-dc-22-2 #x0) rd6 rn6 direction rm6)
1670 (sem-op rn6 rd6 mode sel)
1671 (if (ifield f-addsubx)
1672 (set rn6 (sub rn6 rm6))
1673 (set rn6 (add rn6 rm6)))
1677 (dnmi (.sym name "p.l")
1678 (.str "store " mode " postmodify")
1680 (.str name ".l $rd6,[$rn6],$direction$rm6")
1681 (emit (.sym name "p") rd6 rn6 direction rm6)
1684 (dni_wrapper (.sym name "d16")
1685 (.str "store " mode " displacement")
1687 (.str name " $rd,[$rn,$disp3]")
1688 (+ OP4_LDSTR16D sel OP_STORE rd rn disp3) ;; convert size to 'B'
1689 (sequence ((SI effa)
1691 (ConvertSelectorToShift sel scale)
1692 (set effa (add rn (sll disp3 scale)))
1693 (sem-op effa rd mode sel)
1698 (dni_wrapper (.sym name "d")
1699 (.str "store " mode " displacement")
1701 (.str name " $rd6,[$rn6,$dpmi$disp11]")
1702 (+ OP4_LDSTRD sel OP_STORE PMOD_DISP rd6 rn6 dpmi disp11)
1703 (sequence ((SI effa)
1705 (ConvertSelectorToShift sel scale)
1707 (set effa (sub rn6 (sll disp11 scale)))
1708 (set effa (add rn6 (sll disp11 scale)))
1710 (sem-op effa rd6 mode sel)
1715 (dnmi (.sym name "d.l")
1716 (.str "store " mode " displacement")
1718 (.str name ".l $rd6,[$rn6,$dpmi$disp11]")
1719 (emit (.sym name "d") rd6 rn6 dpmi disp11)
1723 (dni_wrapper (.sym name "dpm")
1724 (.str "store " mode " displacement post-modify")
1726 (.str name " $rd6,[$rn6],$dpmi$disp11")
1727 (+ OP4_LDSTRD sel OP_STORE PMOD_POST rd6 rn6 dpmi disp11) ;; convert size to 'B'
1728 (sequence ((SI scale))
1729 (ConvertSelectorToShift sel scale)
1730 (sem-op rn6 rd6 mode sel)
1732 (set rn6 (sub rn6 (sll disp11 scale)))
1733 (set rn6 (add rn6 (sll disp11 scale)))
1738 (dnmi (.sym name "dpm.l")
1739 (.str "store " mode " displacement post-modify")
1741 (.str name ".l $rd6,[$rn6],$dpmi$disp11")
1742 (emit (.sym name "dpm") rd6 rn6 dpmi disp11)
1745 ;; macro form with a zero displacement
1746 (dnmi (.sym name "ds0") "store w 0 disp"
1748 (.str name " $rd,[$rn]")
1749 (emit (.sym name "d16") rd rn (disp3 0))
1752 (dnmi (.sym name "dl0") "store w 0 disp"
1754 (.str name " $rd6,[$rn6]")
1755 (emit (.sym name "d") rd6 rn6 (dpmi 0) (disp11 0))
1758 (dnmi (.sym name "dl0.l") "store w 0 disp"
1760 (.str name ".l $rd6,[$rn6]")
1761 (emit (.sym name "d") rd6 rn6 (dpmi 0) (disp11 0))
1769 (store-insn strb QI OPW_BYTE store-to-ea)
1770 (store-insn strh HI OPW_SHORT store-to-ea)
1771 (store-insn str SI OPW_WORD store-to-ea)
1772 (store-insn strd DI OPW_DOUBLE store-double-to-ea)
1774 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1776 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1778 (define-pmacro (move-insns name cond g-op)
1780 (dni_wrapper (.sym "cmov16" cond)
1781 (.str "move register " cond)
1783 (.str "mov" name " $rd,$rn")
1784 (+ OP4_FLOW16 (.sym "OPC_" cond) (f-opc-8-1 #x0) (f-dc-9-1 #x0) rd rn)
1790 (dni_wrapper (.sym "cmov" cond)
1791 (.str "move register " cond)
1793 (.str "mov" name " $rd6,$rn6")
1794 (+ 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)
1799 (dnmi (.sym "cmov.l" cond)
1800 (.str "move register " cond)
1802 (.str "mov" name ".l $rd6,$rn6")
1803 (emit (.sym "cmov" cond) rd6 rn6)
1811 ; basic conditional moves
1812 (move-insns "eq" EQ (.pmacro () (eq zbit #x1)))
1813 (move-insns "ne" NE (.pmacro () (eq zbit #x0)))
1814 (move-insns "gtu" GTU (.pmacro () (and BI cbit (not BI zbit))))
1815 (move-insns "gteu" GTEU (.pmacro () (eq cbit #x1)))
1816 (move-insns "lteu" LTEU (.pmacro () (or BI (not BI cbit) zbit)))
1817 (move-insns "ltu" LTU (.pmacro () (eq cbit #x0)))
1818 (move-insns "gt" GT (.pmacro () (and BI (not BI zbit) (eq vbit nbit))))
1819 (move-insns "gte" GTE (.pmacro () (eq vbit nbit)))
1820 (move-insns "lt" LT (.pmacro () (xor BI vbit nbit)))
1821 (move-insns "lte" LTE (.pmacro () (or BI zbit (xor vbit nbit))))
1823 ; unconditional move
1824 (move-insns "" B (.pmacro () #x1))
1827 ; floating point condition codes (floating point instructions)
1828 (move-insns "beq" BEQ (.pmacro () (or BI bzbit bzbit)))
1829 (move-insns "bne" BNE (.pmacro () (not BI bzbit)))
1830 (move-insns "blt" BLT (.pmacro () (and BI bnbit (not bzbit))))
1831 (move-insns "blte" BLTE (.pmacro () (or BI bnbit bzbit)))
1833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1835 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1837 ;; 16 bits form exists for group zero ( M1 and M0 equals to zero ) only
1839 (dni_wrapper movts16
1840 "move to special reg"
1843 (+ OP4_FLOW16 (f-opc-8-5 #x10) (f-dc-9-1 #x0) rd sn) ;; rd is source for movts
1848 (define-pmacro (op-mmr-movts name sdreg code)
1851 (dni_wrapper (.sym "movts" name)
1852 (.str "move to " name)
1854 (.str "movts $" sdreg ",$rd6")
1855 (+ 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
1860 (dnmi (.sym "movts.l" name)
1861 (.str "move to " name)
1863 (.str "movts.l $" sdreg ",$rd6")
1864 (emit (.sym "movts" name) sdreg rd6)
1873 (op-mmr-movts 6 sn6 #x0)
1874 (op-mmr-movts dma sndma #x1)
1875 (op-mmr-movts mem snmem #x2)
1876 (op-mmr-movts mesh snmesh #x3)
1878 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1880 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1881 (dni_wrapper movfs16
1882 "move from special register"
1885 (+ OP4_FLOW16 (f-opc-8-5 #x11) (f-dc-9-1 #x0) rd sn)
1892 (define-pmacro (op-mmr-movfs name snreg code)
1895 (dni_wrapper (.sym "movfs" name)
1896 (.str "move from " name)
1898 (.str "movfs $rd6,$" snreg)
1899 (+ 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)
1904 (dnmi (.sym "movfs.l" name)
1905 (.str "move from " name)
1907 (.str "movfs.l $rd6,$" snreg)
1908 (emit (.sym "movfs" name) rd6 snreg)
1916 (op-mmr-movfs 6 sn6 #x0)
1917 (op-mmr-movfs dma sndma #x1)
1918 (op-mmr-movfs mem snmem #x2)
1919 (op-mmr-movfs mesh snmesh #x3)
1925 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1927 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1932 (+ OP4_FLOW16 (f-opc-8-5 #x1a) (f-dc-15-7 #x0))
1938 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1940 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1945 (+ OP4_FLOW16 (f-opc-8-5 #x3a) (f-dc-15-7 #x0))
1951 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1958 (+ (f-opc-31-32 #x000F000F))
1963 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1965 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1967 (dni idle "idle until interrupt" () "idle"
1968 (+ OP4_FLOW16 (f-opc-8-5 #x1b) (f-dc-15-7 #x0))
1969 ;; (set pc pc) ;; should branch to self until interrupt, but not modeling interrupts
1972 (c-code "sim_engine_halt (CPU_STATE (current_cpu), current_cpu, NULL, \
1973 pc, sim_exited, 0);"))
1977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1979 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1985 (+ OP4_FLOW16 (f-opc-8-5 #x1c) (f-dc-15-7 #x0))
1987 (c-call "epiphany_break" pc)
1993 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1995 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1998 "multicorebreakpoint"
2001 (+ OP4_FLOW16 (f-opc-8-5 #x1c) (f-dc-15-7 #x1))
2002 ;;;(c-call "epiphany_break" pc)
2003 (nop) ;; ignore the multi core break point in the simulator
2011 (dni rti "return from interrupt" (SHORT-INSN UNCOND-CTI)
2013 (+ OP4_FLOW16 (f-opc-8-5 #x1d) (f-dc-15-7 #x0))
2018 ;; (sub (c-raw-call SI "ffs" (and (hcr-ipend) (not (hcr-imask))))
2022 (c-call SI "epiphany_rti" (hcr-ipend) (hcr-imask)))
2023 (set gidisablebit 0)
2026 (set pc (hcr-iret)))
2029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2030 ;; WAND is a wired flag that runs around the chip
2031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2032 (dni_wrapper wand "wand"
2035 (+ OP4_FLOW16 (f-opc-8-5 #x18) (f-dc-15-7 #x0))
2040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2041 ;; Sync likes wand, but wired OR
2042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2043 (dni_wrapper sync "sync"
2046 (+ OP4_FLOW16 (f-opc-8-5 #x1f) (f-dc-15-7 #x0))
2051 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2053 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2054 (dni_wrapper gien "global interrupt enable"
2057 (+ OP4_FLOW16 (f-gien-gidis-9-1 #x0) (f-opc-8-5 #x19) (f-dc-15-6 #x0))
2058 (set gidisablebit 0)
2062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2064 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2065 (dni_wrapper gidis "global interrupt disable"
2068 (+ OP4_FLOW16 (f-gien-gidis-9-1 #x1) (f-opc-8-5 #x19) (f-dc-15-6 #x0))
2069 (set gidisablebit 1)
2079 ;; Model only immediate 'fire' exception, if gien cleared or masked don't fire and don't check later - no ilat like behavior
2080 (dni swi_num "software interrupt" (SHORT-INSN UNCOND-CTI)
2082 (+ OP4_FLOW16 (f-opc-8-5 #x1e) (f-trap-swi-9-1 #x0) swi_num)
2083 (sequence () (call-exception #x24 #x80))
2088 ;; (set (hcr-iret) (add pc (const 2)))
2089 ;; (set (hcr-ipend) (or (hcr-ipend) (const #x80)))
2090 ;; (set pc (const #x1c))
2093 ;; ;; schedule interrupt
2094 ;; (set (hcr-ilat) (or (hcr-ilat) (const #x80)))
2098 (dni swi "software interrupt" (ALIAS SHORT-INSN UNCOND-CTI)
2100 (+ OP4_FLOW16 (f-opc-8-5 #x1e) (f-trap-swi-9-1 #x0) (f-dc-15-6 #x0))
2101 (sequence () (call-exception #x24 #x80))
2106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2107 ;; TRAP #disp3 - simulator only and chip as well - make the same grouop as swi
2108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2110 ;; Only defining 16-bit form of this instruction. It exists to support the
2111 ;; simulator, by giving us a simple input/output mechanism beyond returning values
2112 ;; in registers or memory.
2113 ;; TRAP #N - special sw trap for simulator support; allows simple i/o using fixed arguments
2114 ;; TRAP #0 - write (r0=i/o channel, r1=addr, r2=len) returns status in r0
2115 ;; TRAP #1 - read (r0=i/o channel, r1=addr, r2=len) returns length or -<code> on error
2116 ;; TRAP #2 - open (r0=string path, r1=mode) returns channel# or -<code> on error
2117 ;; TRAP #3 - exit (r0=status code) never returns.
2118 ;; TRAP #4 - print "pass\n" and exit
2119 ;; TRAP #5 - print "fail\n" and exit
2120 ;; TRAP #6 - close (r0=i/o channel)
2122 (dni trap16 "trap to simulator"
2123 (SHORT-INSN UNCOND-CTI)
2125 (+ 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)
2126 (set (reg SI h-registers 0) (c-call SI "epiphany_trap" pc trapnum6))
2131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2132 ;; Integer arithmetic instructions 3 address forms
2133 ;; both 16 and 32 bit forms
2134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2136 (define-pmacro (op-rrr name sem-op cond-op)
2138 (dni_wrapper (.sym name "16")
2141 (.str name " $rd,$rn,$rm")
2142 (+ OP4_ALU16 (.sym "OPB_" (.upcase (.str name))) rd rn rm)
2145 (set rd (sem-op SI rn rm))
2146 (set zbit (zflag rd))
2147 (set nbit (nflag rd))
2152 (dni_wrapper (.sym name)
2155 (.str name " $rd6,$rn6,$rm6")
2156 (+ OP4_MISC (.sym "OPB_" (.upcase (.str name))) (f-opc-19-4 #xa) (f-dc-22-3 #x0) rd6 rn6 rm6)
2159 (set rd6 (sem-op SI rn6 rm6))
2160 (set zbit (zflag rd6))
2161 (set nbit (nflag rd6))
2166 (dnmi (.sym name ".l")
2169 (.str name ".l $rd6,$rn6,$rm6")
2170 (emit (.sym name) rd6 rn6 rm6)
2178 ;; submacros to set condition codes
2179 ;; NZ are always set to reflect the sign and value of the result
2180 ;; CV are a function of the operator
2181 (define-pmacro (add-vc a b) (sequence ()
2182 (set cbit (add-cflag SI a b 0))
2183 (set vbit (add-oflag SI a b 0))
2184 (set vsbit (or BI vsbit vbit))
2187 (define-pmacro (sub-vc a b) (sequence ()
2188 (set cbit (not (sub-cflag SI a b 0)))
2189 (set vbit (sub-oflag SI a b 0))
2190 (set vsbit (or vsbit vbit))
2193 (define-pmacro (logic-vc a b) (sequence ()
2198 (op-rrr add add add-vc)
2199 (op-rrr sub sub sub-vc)
2200 (op-rrr and and logic-vc)
2201 (op-rrr orr or logic-vc)
2202 (op-rrr eor xor logic-vc)
2204 ;; Integer arithmetic immediate forms
2206 (define-pmacro (op-rri name code cond-op)
2208 (dni_wrapper (.sym name "i16")
2211 (.str name ".s $rd,$rn,$simm3")
2212 (+ OP4_IMM16 code rd rn simm3)
2215 (set rd (name SI rn simm3))
2216 (set zbit (zflag rd))
2217 (set nbit (nflag rd))
2223 (dni_wrapper (.sym name "i")
2226 (.str name ".l $rd6,$rn6,$simm11")
2227 (+ OP4_IMM32 code OPI_25_2_MBZ rd6 rn6 simm11)
2229 (cond-op rn6 simm11)
2230 (set rd6 (name SI rn6 simm11))
2231 (set zbit (zflag rd6))
2232 (set nbit (nflag rd6))
2237 ;; (dnmi (.sym name "ri") "relaxed arithmetic immediate" (RELAXED)
2238 ;; (.str name " $rd6,$rn6,$simm11")
2239 ;; (emit (.sym name "i") rd6 rn6 simm11))
2243 (op-rri add OPI_ADD add-vc)
2244 (op-rri sub OPI_SUB sub-vc)
2246 (dnmi addir "relaxable short immediate add" (RELAXABLE IMM3)
2247 "add $rd,$rn,$simm3"
2248 (emit addi16 rd rn simm3))
2250 (dnmi addi32r "relaxed long immediate add" (RELAXED)
2251 "add $rd6,$rn6,$simm11"
2252 (emit addi rd6 rn6 simm11))
2254 ;; Again, but not relaxable so that full sized registers are handled
2255 (dnmi addi32m "relaxed long immediate add" ()
2256 "add $rd6,$rn6,$simm11"
2257 (emit addi rd6 rn6 simm11))
2260 (dnmi subir "relaxable short immediate sub" (RELAXABLE IMM3)
2261 "sub $rd,$rn,$simm3"
2262 (emit subi16 rd rn simm3))
2264 (dnmi subi32r "relaxed long immediate sub" (RELAXED)
2265 "sub $rd6,$rn6,$simm11"
2266 (emit subi rd6 rn6 simm11))
2268 (dnmi subi32m "relaxed long immediate sub" ()
2269 "sub $rd6,$rn6,$simm11"
2270 (emit subi rd6 rn6 simm11))
2273 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2274 ;; Shift instructions 3 address forms
2275 ;; both 16 and 32 bit forms
2276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2278 (define-pmacro (shift-rrr name sem-op)
2280 (dni_wrapper (.sym name "16")
2283 (.str name " $rd,$rn,$rm")
2284 (+ OP4_ALU16 (.sym "OPB_" (.upcase (.str name))) rd rn rm)
2287 (set rd (sem-op SI rn (and rm (const 31))))
2288 (set zbit (zflag rd))
2289 (set nbit (nflag rd))
2294 (dni_wrapper (.sym name)
2297 (.str name " $rd6,$rn6,$rm6")
2298 (+ OP4_MISC (.sym "OPB_" (.upcase (.str name))) (f-opc-19-4 #xa) (f-dc-22-3 #x0) rd6 rn6 rm6)
2301 (set rd6 (sem-op SI rn6 (and rm6 (const 31))))
2302 (set zbit (zflag rd6))
2303 (set nbit (nflag rd6))
2308 (dnmi (.sym name ".l")
2311 (.str name ".l $rd6,$rn6,$rm6")
2312 (emit (.sym name) rd6 rn6 rm6)
2321 (define-pmacro (op-shift-rri name shortcode f5 longcode sem-op)
2323 (dni_wrapper (.sym name "i16")
2326 (.str name " $rd,$rn,$shift")
2327 (+ shortcode (f-opc-4-1 f5) rd rn shift)
2330 (set rd (sem-op SI rn shift))
2331 (set zbit (zflag rd))
2332 (set nbit (nflag rd))
2336 (dni_wrapper (.sym name "i32")
2339 (.str name " $rd6,$rn6,$shift")
2340 (+ OP4_MISC (f-opc-4-1 f5) (f-opc-19-4 longcode) (f-dc-25-6 0) rd6 rn6 shift)
2342 (logic-vc rn6 shift)
2343 (set rd6 (sem-op SI rn6 shift))
2344 (set zbit (zflag rd6))
2345 (set nbit (nflag rd6))
2350 (dnmi (.sym name "i32.l")
2353 (.str name ".l $rd6,$rn6,$shift")
2354 (emit (.sym name "i32") rd6 rn6 shift)
2361 (op-shift-rri lsr OP4_LSHIFT16 0 #x6 srl)
2362 (op-shift-rri lsl OP4_LSHIFT16 1 #x6 sll)
2363 (op-shift-rri asr OP4_ASHIFT16 0 #xe sra)
2365 ;; BITR - bitreversal (FFT)
2367 ;; From Dr Dobbs et al.
2370 ;; v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1); ;; swap odd-even bits
2371 ;; v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2); ;; swap pairs
2372 ;; v = ((v >> 4) & 0x0f0f0f0f) | ((v & 0x0f0f0f0f) << 4); ;; swap nibbles
2373 ;; v = ((v >> 8) & 0x00ff00ff) | ((v & 0x00ff00ff) << 8); ;; swap bytes
2374 ;; v = (v >> 16) | (v << 16); ;; swap halves
2375 (define-pmacro (bit-reversal dest src)
2378 (set v (or (and (srl v 1) #x55555555) (sll (and v #x55555555) 1)))
2379 (set v (or (and (srl v 2) #x33333333) (sll (and v #x33333333) 2)))
2380 (set v (or (and (srl v 4) #x0f0f0f0f) (sll (and v #x0f0f0f0f) 4)))
2381 (set v (or (and (srl v 8) #x00ff00ff) (sll (and v #x00ff00ff) 8)))
2382 (set v (or (srl v 16) (sll v 16)))
2386 (dni_wrapper bitr16 "bit reverse short"
2389 (+ OP4_ASHIFT16 (f-opc-4-1 1) rd rn (f-shift 0))
2391 (bit-reversal rd rn)
2392 (set zbit (zflag rd))
2393 (set nbit (nflag rd))
2400 (dni_wrapper bitr "bit reverse"
2403 (+ OP4_MISC (f-opc-4-1 1) (f-opc-19-4 #xe) (f-dc-25-6 0) rd6 rn6 (f-shift 0))
2405 (bit-reversal rd6 rn6)
2406 (set zbit (zflag rd6))
2407 (set nbit (nflag rd6))
2413 (dnmi bitrl "bit reverse l"
2415 ("bitr.l $rd6,$rn6")
2419 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2420 ;; Integer arithmetic instructions
2421 ;; Extended operation
2422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2424 (define-pmacro (op-iextrrr name cond-op)
2427 (dni_wrapper (.sym name)
2430 (.str name " $rd6,$rn6,$rm6")
2431 (+ OP4_MISC (.sym "OPBE_" (.upcase (.str name))) (f-opc-19-4 #xa) (f-dc-22-2 #x0) (f-dc-20-1 #x1)
2434 ;; TODO cond operation (cond-op rn6 rm6)
2435 ;;(set rd6 (sem-op SI rn6 rm6))
2436 (set zbit (zflag rd6))
2437 (set nbit (nflag rd6))
2442 (dnmi (.sym name ".l")
2445 (.str name ".l $rd6,$rn6,$rm6")
2446 (emit (.sym name) rd6 rn6 rm6)
2451 (op-iextrrr fext sub-vc)
2452 (op-iextrrr fdep sub-vc)
2453 (op-iextrrr lfsr sub-vc)
2457 ;; Immediate moves. The 8 bit form is relaxed if it doesn't fit or is external
2463 (+ OP4_IMM16 (f-opc-4-1 #x0) rd imm8)
2464 (set rd (zext SI imm8))
2468 (dnmi mov8r "mov imm8 relaxable"
2471 (emit mov8 rd imm8))
2477 (+ OP4_IMM32 (f-opc-4-1 #x0) (f-opc-19-4 #x2) (f-dc-28-1 #x0) rd6 imm16)
2478 (set rd6 (zext SI imm16))
2482 (dnmi mov16r "mov imm16 relaxable"
2485 (emit mov16 rd6 imm16))
2487 ;; MOVE TO HIGH WORD
2492 (+ OP4_IMM32 (f-opc-4-1 #x0) (f-opc-19-4 #x2) (f-dc-28-1 #x1) rd6 imm16)
2493 (set rd6 (or (and SI rd6 (const #xffff)) ; keep low bits of rd
2494 (sll SI imm16 (const 16)))) ; replacing just high bits
2500 "movt.l $rd6,$imm16"
2501 (emit movt rd6 imm16)
2506 ;; FLOATING POINT OPERATIONS
2508 (define-pmacro (op-two_operands-float name code)
2511 (.sym "f_" name "f16")
2514 (.str "f" name " $rd,$rn,$rm")
2515 (+ OP4_DSP16 code rd rn rm)
2518 (eq arithmetic-modebit2 0)
2519 (sequence ((SF fptemp) (SI sdtmp))
2520 (set sdtmp (c-call SI (.str "epiphany_f" name) rd rn rm))
2522 ;;All bits are calculated in C
2523 (set bzbit (c-call BI "get_epiphany_fzeroflag" sdtmp))
2524 (set bnbit (c-call BI "get_epiphany_fnegativeflag" sdtmp))
2525 (set bvbit (c-call BI "get_epiphany_foverflowflag" sdtmp))
2526 (set bubit (c-call BI "get_epiphany_funderflowflag" sdtmp))
2527 (set bibit (c-call BI "get_epiphany_finvalidflag" sdtmp))
2528 (set bvsbit (or bvsbit bvbit))
2529 (set busbit (or busbit bubit))
2530 (set bisbit (or bisbit bibit))
2532 (if (or (and invExcEnbit bisbit)
2533 (or (and ovfExcEnbit bvsbit) (and unExcEnbit busbit)))
2535 (set expcause0bit (const 1))
2536 (set expcause1bit (const 1))
2537 (call-exception #x4 #x2)))
2539 (if (eq arithmetic-modebit2 1)
2540 (sequence ((SI sdtmp))
2541 (set sdtmp (c-call SI (.str "epiphany_i" name) rd rn rm))
2542 ;; carry is not connected inb the design (set bcbit bcbit)
2543 (set bzbit (zflag sdtmp))
2544 (set bnbit (nflag sdtmp))
2550 (dnmi (.sym "i_" name "f16")
2553 (.str "i" name " $rd,$rn,$rm")
2554 (emit (.sym "f_" name "f16") rd rn rm)
2559 (.sym "f_" name "f32")
2562 (.str "f" name " $rd6,$rn6,$rm6")
2563 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rm6)
2566 (eq arithmetic-modebit2 0)
2567 (sequence ((SF fptemp) (SI sdtmp))
2568 (set sdtmp (c-call SI (.str "epiphany_f" name) rd6 rn6 rm6))
2570 ;;All bits are calculated in C
2571 (set bzbit (c-call BI "get_epiphany_fzeroflag" sdtmp))
2572 (set bnbit (c-call BI "get_epiphany_fnegativeflag" sdtmp))
2573 (set bvbit (c-call BI "get_epiphany_foverflowflag" sdtmp))
2574 (set bubit (c-call BI "get_epiphany_funderflowflag" sdtmp))
2575 (set bibit (c-call BI "get_epiphany_finvalidflag" sdtmp))
2576 (set bvsbit (or bvsbit bvbit))
2577 (set busbit (or busbit bubit))
2578 (set bisbit (or bisbit bibit))
2582 (if (or (and invExcEnbit bisbit)
2583 (or (and ovfExcEnbit bvsbit) (and unExcEnbit busbit)))
2585 (set expcause0bit (const 1))
2586 (set expcause1bit (const 1))
2587 (call-exception #x4 #x2)))
2590 (if (eq arithmetic-modebit2 1)
2591 (sequence ((SI sdtmp))
2592 (set sdtmp (c-call SI (.str "epiphany_i" name) rd6 rn6 rm6))
2593 ;; carry is not connected inb the design (set bcbit bcbit)
2594 (set bzbit (zflag sdtmp))
2595 (set bnbit (nflag sdtmp))
2603 (dnmi (.sym "f_" name "f32.l")
2606 (.str "f" name ".l $rd6,$rn6,$rm6")
2607 (emit (.sym "f_" name "f32") rd6 rn6 rm6)
2609 (dnmi (.sym "i_" name "f32")
2612 (.str "i" name " $rd6,$rn6,$rm6")
2613 (emit (.sym "f_" name "f32") rd6 rn6 rm6)
2615 (dnmi (.sym "i_" name "f32.l")
2618 (.str "i" name ".l $rd6,$rn6,$rm6")
2619 (emit (.sym "f_" name "f32") rd6 rn6 rm6)
2627 (op-two_operands-float add OPF_ADD)
2628 (op-two_operands-float sub OPF_SUB)
2629 (op-two_operands-float mul OPF_MUL)
2630 (op-two_operands-float madd OPF_MADD)
2631 (op-two_operands-float msub OPF_MSUB)
2635 (define-pmacro (op-fabs-float name code)
2637 (dni_wrapper (.sym "f_" name "f16")
2640 (.str "f" name " rd,rn")
2641 (+ OP4_DSP16 code rd rn rn)
2642 (sequence ((SF fptemp) (SI sdtmp))
2644 ;(set sdtmp (and rn #x7fffffff))
2645 (set sdtmp (c-call SI (.str "epiphany_fabs") rd rn rn))
2648 (set bnbit (const SI 0))
2649 (set bzbit (eq SI sdtmp (const SI 0)))
2652 (set bvsbit (or bvsbit bvbit))
2653 (set busbit (or busbit bubit))
2654 (set bisbit (or bisbit bibit))
2661 (dni_wrapper (.sym "f_" name "f32")
2664 (.str "f" name " $rd6,$rn6")
2665 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rn6)
2666 (sequence ((SF fptemp) (SI sdtmp))
2669 ;(set sdtmp (and rn6 #x7fffffff))
2671 (set sdtmp (c-call SI (.str "epiphany_fabs") rd6 rn6 rn6))
2674 (set bnbit (const SI 0))
2675 (set bzbit (eq SI sdtmp (const SI 0)))
2677 (set bvsbit (or bvsbit bvbit))
2678 (set busbit (or busbit bubit))
2679 (set bisbit (or bisbit bibit))
2687 (dnmi (.sym "f_" name "f32.l")
2690 (.str "f" name ".l $rd6,$rn6")
2691 (emit (.sym "f_" name "f32") rd6 rn6)
2698 (op-fabs-float abs OPF_FABS)
2701 (define-pmacro (op-fix2float-float name code)
2703 (dni_wrapper (.sym "f_" name "f16")
2706 (.str "f" name " $rd,$rn")
2707 (+ OP4_DSP16 code frd frn frn)
2708 (sequence ((SF fptemp) (SI sdtmp))
2710 (set sdtmp (c-call SI (.str "epiphany_f" name) rd rn rn))
2712 (set bnbit (lt SI sdtmp (const SI 0)))
2713 (set bzbit (eq SI sdtmp (const SI 0)))
2715 (set bvsbit (or bvsbit bvbit))
2716 (set busbit (or busbit bubit))
2717 (set bisbit (or bisbit bibit))
2725 (dni_wrapper (.sym "f_" name "f32")
2728 (.str "f" name " $rd6,$rn6")
2729 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rn6)
2730 (sequence ((SF fptemp) (SI sdtmp))
2732 (set sdtmp (c-call SI (.str "epiphany_f" name) rd6 rn6 rn6))
2734 (set bnbit (lt SI sdtmp (const SI 0)))
2735 (set bzbit (eq SI sdtmp (const SI 0)))
2737 (set bvsbit (or bvsbit bvbit))
2738 (set busbit (or busbit bubit))
2739 (set bisbit (or bisbit bibit))
2747 (dnmi (.sym "f_" name "f32.l")
2750 (.str "f" name ".l $rd6,$rn6")
2751 (emit (.sym "f_" name "f32") rd6 rn6)
2756 (op-fix2float-float loat OPF_FLOAT)
2758 (define-pmacro (op-float2fix-float name code)
2760 (dni_wrapper (.sym "f_" name "f16")
2763 (.str "f" name " $rd,$rn")
2764 (+ OP4_DSP16 code rd rn rn)
2765 (sequence ((SF fptemp) (SI sdtmp))
2767 (set sdtmp (c-call SI (.str "epiphany_f" name) rd rn rn))
2769 (set bzbit (zflag sdtmp))
2770 (set bnbit (nflag sdtmp))
2772 (set bvbit (c-call BI "get_epiphany_foverflowflag" sdtmp))
2773 (set bubit (c-call BI "get_epiphany_funderflowflag" sdtmp))
2774 (set bibit (c-call BI "get_epiphany_finvalidflag" sdtmp))
2776 (set bvsbit (or bvsbit bvbit))
2777 (set busbit (or busbit bubit))
2778 (set bisbit (or bisbit bibit))
2782 (if (or (and invExcEnbit bisbit)
2783 (or (and ovfExcEnbit busbit)
2784 (and unExcEnbit bvsbit)))
2786 (set expcause0bit (const 1))
2787 (set expcause1bit (const 1))
2788 (call-exception #x4 #x2)))
2796 (dni_wrapper (.sym "f_" name "f32")
2799 (.str "f" name " $rd6,$rn6")
2800 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) rd6 rn6 rn6)
2801 (sequence ((SF fptemp) (SI sdtmp))
2803 (set sdtmp (c-call SI (.str "epiphany_f" name) rd6 rn6 rm6))
2805 (set bzbit (zflag sdtmp))
2806 (set bnbit (nflag sdtmp))
2808 (set bvbit (c-call BI "get_epiphany_foverflowflag" sdtmp))
2809 (set bubit (c-call BI "get_epiphany_funderflowflag" sdtmp))
2810 (set bibit (c-call BI "get_epiphany_finvalidflag" sdtmp))
2812 (set bvsbit (or bvsbit bvbit))
2813 (set busbit (or busbit bubit))
2814 (set bisbit (or bisbit bibit))
2818 (if (or (and invExcEnbit bisbit)
2819 (or (and ovfExcEnbit busbit)
2820 (and unExcEnbit bvsbit)))
2822 (set expcause0bit (const 1))
2823 (set expcause1bit (const 1))
2824 (call-exception #x4 #x2))
2831 (dnmi (.sym "f_" name "f32.l")
2834 (.str "f" name ".l $rd6,$rn6")
2835 (emit (.sym "f_" name "f32") rd6 rn6)
2846 (op-float2fix-float ix OPF_FIX)
2848 ;; MAC (Multiply and Accumulate Instructions
2849 ;; (define-pmacro (op-mac-float name code)
2851 ;; (dni_wrapper (.sym "fm" name "f16")
2854 ;; (.str "fm" name " $frd,$frn,$frm")
2855 ;; (+ OP4_DSP16 code frd frn frm)
2856 ;; (sequence ((SF fptemp))
2859 ;; (set fptemp (c-call SF (.str "epiphany_fm" name) frd frm frn))
2860 ;; (set bnbit (lt SF fptemp (const SF 0)))
2861 ;; (set bzbit (eq SF fptemp (const SF 0)))
2862 ;; (set bvsbit (or bvsbit bvbit))
2864 ;; ; (set rd (subword SI frd 0))
2869 ;; (dni_wrapper (.sym "fm" name "f32")
2872 ;; (.str "fm" name " $frd6,$frn6,$frm6")
2873 ;; (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-3 #x0) frd6 frn6 frm6)
2874 ;; (sequence ((SF fptemp))
2877 ;; (set fptemp (c-call SF (.str "epiphany_fm" name) frd6 frm6 frn6))
2878 ;; (set bnbit (lt SF fptemp (const SF 0)))
2879 ;; (set bzbit (eq SF fptemp (const SF 0)))
2880 ;; (set bvsbit (or bvsbit bvbit))
2881 ;; (set frd6 fptemp)
2882 ;; ; (set rd6 (subword SI frd6 0))
2895 ; extended floating point operation
2898 (define-pmacro (op-fextop-float name code)
2901 (dni_wrapper (.sym "f_" name "f32")
2904 (.str "f" name " $frd6,$frn6")
2905 (+ OP4_MISC code (f-opc-19-4 #x7) (f-dc-22-2 #x0) (f-dc-20-1 #x1) frd6 frn6 frn6)
2906 (sequence ((SF fptemp))
2909 (set fptemp (c-call SF (.str "epiphany_f" name) frn6))
2910 (set bnbit (lt SF fptemp (const SF 0)))
2911 (set bzbit (eq SF fptemp (const SF 0)))
2912 (set bvsbit (or bvsbit bvbit))
2920 (dnmi (.sym "f_" name "f32.l")
2923 (.str "f" name ".l $frd6,$frn6")
2924 (emit (.sym "f_" name "f32") frd6 frn6)
2929 (op-fextop-float recip OPF_FRECIP)
2930 (op-fextop-float sqrt OPF_FSQRT)