PR gas/12848
[binutils.git] / gas / config / bfin-parse.y
blob797664a5015856ad732d0ea3c48db42a6e9b8e7b
1 /* bfin-parse.y ADI Blackfin parser
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20 02110-1301, USA. */
23 #include "as.h"
24 #include <obstack.h>
26 #include "bfin-aux.h" /* Opcode generating auxiliaries. */
27 #include "libbfd.h"
28 #include "elf/common.h"
29 #include "elf/bfin.h"
31 #define DSP32ALU(aopcde, HL, dst1, dst0, src0, src1, s, x, aop) \
32 bfin_gen_dsp32alu (HL, aopcde, aop, s, x, dst0, dst1, src0, src1)
34 #define DSP32MAC(op1, MM, mmod, w1, P, h01, h11, h00, h10, dst, op0, src0, src1, w0) \
35 bfin_gen_dsp32mac (op1, MM, mmod, w1, P, h01, h11, h00, h10, op0, \
36 dst, src0, src1, w0)
38 #define DSP32MULT(op1, MM, mmod, w1, P, h01, h11, h00, h10, dst, op0, src0, src1, w0) \
39 bfin_gen_dsp32mult (op1, MM, mmod, w1, P, h01, h11, h00, h10, op0, \
40 dst, src0, src1, w0)
42 #define DSP32SHIFT(sopcde, dst0, src0, src1, sop, hls) \
43 bfin_gen_dsp32shift (sopcde, dst0, src0, src1, sop, hls)
45 #define DSP32SHIFTIMM(sopcde, dst0, immag, src1, sop, hls) \
46 bfin_gen_dsp32shiftimm (sopcde, dst0, immag, src1, sop, hls)
48 #define LDIMMHALF_R(reg, h, s, z, hword) \
49 bfin_gen_ldimmhalf (reg, h, s, z, hword, 1)
51 #define LDIMMHALF_R5(reg, h, s, z, hword) \
52 bfin_gen_ldimmhalf (reg, h, s, z, hword, 2)
54 #define LDSTIDXI(ptr, reg, w, sz, z, offset) \
55 bfin_gen_ldstidxi (ptr, reg, w, sz, z, offset)
57 #define LDST(ptr, reg, aop, sz, z, w) \
58 bfin_gen_ldst (ptr, reg, aop, sz, z, w)
60 #define LDSTII(ptr, reg, offset, w, op) \
61 bfin_gen_ldstii (ptr, reg, offset, w, op)
63 #define DSPLDST(i, m, reg, aop, w) \
64 bfin_gen_dspldst (i, reg, aop, w, m)
66 #define LDSTPMOD(ptr, reg, idx, aop, w) \
67 bfin_gen_ldstpmod (ptr, reg, aop, w, idx)
69 #define LDSTIIFP(offset, reg, w) \
70 bfin_gen_ldstiifp (reg, offset, w)
72 #define LOGI2OP(dst, src, opc) \
73 bfin_gen_logi2op (opc, src, dst.regno & CODE_MASK)
75 #define ALU2OP(dst, src, opc) \
76 bfin_gen_alu2op (dst, src, opc)
78 #define BRCC(t, b, offset) \
79 bfin_gen_brcc (t, b, offset)
81 #define UJUMP(offset) \
82 bfin_gen_ujump (offset)
84 #define PROGCTRL(prgfunc, poprnd) \
85 bfin_gen_progctrl (prgfunc, poprnd)
87 #define PUSHPOPMULTIPLE(dr, pr, d, p, w) \
88 bfin_gen_pushpopmultiple (dr, pr, d, p, w)
90 #define PUSHPOPREG(reg, w) \
91 bfin_gen_pushpopreg (reg, w)
93 #define CALLA(addr, s) \
94 bfin_gen_calla (addr, s)
96 #define LINKAGE(r, framesize) \
97 bfin_gen_linkage (r, framesize)
99 #define COMPI2OPD(dst, src, op) \
100 bfin_gen_compi2opd (dst, src, op)
102 #define COMPI2OPP(dst, src, op) \
103 bfin_gen_compi2opp (dst, src, op)
105 #define DAGMODIK(i, op) \
106 bfin_gen_dagmodik (i, op)
108 #define DAGMODIM(i, m, op, br) \
109 bfin_gen_dagmodim (i, m, op, br)
111 #define COMP3OP(dst, src0, src1, opc) \
112 bfin_gen_comp3op (src0, src1, dst, opc)
114 #define PTR2OP(dst, src, opc) \
115 bfin_gen_ptr2op (dst, src, opc)
117 #define CCFLAG(x, y, opc, i, g) \
118 bfin_gen_ccflag (x, y, opc, i, g)
120 #define CCMV(src, dst, t) \
121 bfin_gen_ccmv (src, dst, t)
123 #define CACTRL(reg, a, op) \
124 bfin_gen_cactrl (reg, a, op)
126 #define LOOPSETUP(soffset, c, rop, eoffset, reg) \
127 bfin_gen_loopsetup (soffset, c, rop, eoffset, reg)
129 #define HL2(r1, r0) (IS_H (r1) << 1 | IS_H (r0))
130 #define IS_RANGE(bits, expr, sign, mul) \
131 value_match(expr, bits, sign, mul, 1)
132 #define IS_URANGE(bits, expr, sign, mul) \
133 value_match(expr, bits, sign, mul, 0)
134 #define IS_CONST(expr) (expr->type == Expr_Node_Constant)
135 #define IS_RELOC(expr) (expr->type != Expr_Node_Constant)
136 #define IS_IMM(expr, bits) value_match (expr, bits, 0, 1, 1)
137 #define IS_UIMM(expr, bits) value_match (expr, bits, 0, 1, 0)
139 #define IS_PCREL4(expr) \
140 (value_match (expr, 4, 0, 2, 0))
142 #define IS_LPPCREL10(expr) \
143 (value_match (expr, 10, 0, 2, 0))
145 #define IS_PCREL10(expr) \
146 (value_match (expr, 10, 0, 2, 1))
148 #define IS_PCREL12(expr) \
149 (value_match (expr, 12, 0, 2, 1))
151 #define IS_PCREL24(expr) \
152 (value_match (expr, 24, 0, 2, 1))
155 static int value_match (Expr_Node *, int, int, int, int);
157 extern FILE *errorf;
158 extern INSTR_T insn;
160 static Expr_Node *binary (Expr_Op_Type, Expr_Node *, Expr_Node *);
161 static Expr_Node *unary (Expr_Op_Type, Expr_Node *);
163 static void notethat (char *, ...);
165 char *current_inputline;
166 extern char *yytext;
167 int yyerror (char *);
169 void error (char *format, ...)
171 va_list ap;
172 static char buffer[2000];
174 va_start (ap, format);
175 vsprintf (buffer, format, ap);
176 va_end (ap);
178 as_bad ("%s", buffer);
182 yyerror (char *msg)
184 if (msg[0] == '\0')
185 error ("%s", msg);
187 else if (yytext[0] != ';')
188 error ("%s. Input text was %s.", msg, yytext);
189 else
190 error ("%s.", msg);
192 return -1;
195 static int
196 in_range_p (Expr_Node *exp, int from, int to, unsigned int mask)
198 int val = EXPR_VALUE (exp);
199 if (exp->type != Expr_Node_Constant)
200 return 0;
201 if (val < from || val > to)
202 return 0;
203 return (val & mask) == 0;
206 extern int yylex (void);
208 #define imm3(x) EXPR_VALUE (x)
209 #define imm4(x) EXPR_VALUE (x)
210 #define uimm4(x) EXPR_VALUE (x)
211 #define imm5(x) EXPR_VALUE (x)
212 #define uimm5(x) EXPR_VALUE (x)
213 #define imm6(x) EXPR_VALUE (x)
214 #define imm7(x) EXPR_VALUE (x)
215 #define uimm8(x) EXPR_VALUE (x)
216 #define imm16(x) EXPR_VALUE (x)
217 #define uimm16s4(x) ((EXPR_VALUE (x)) >> 2)
218 #define uimm16(x) EXPR_VALUE (x)
220 /* Return true if a value is inside a range. */
221 #define IN_RANGE(x, low, high) \
222 (((EXPR_VALUE(x)) >= (low)) && (EXPR_VALUE(x)) <= ((high)))
224 /* Auxiliary functions. */
226 static int
227 valid_dreg_pair (Register *reg1, Expr_Node *reg2)
229 if (!IS_DREG (*reg1))
231 yyerror ("Dregs expected");
232 return 0;
235 if (reg1->regno != 1 && reg1->regno != 3)
237 yyerror ("Bad register pair");
238 return 0;
241 if (imm7 (reg2) != reg1->regno - 1)
243 yyerror ("Bad register pair");
244 return 0;
247 reg1->regno--;
248 return 1;
251 static int
252 check_multiply_halfregs (Macfunc *aa, Macfunc *ab)
254 if ((!REG_EQUAL (aa->s0, ab->s0) && !REG_EQUAL (aa->s0, ab->s1))
255 || (!REG_EQUAL (aa->s1, ab->s1) && !REG_EQUAL (aa->s1, ab->s0)))
256 return yyerror ("Source multiplication register mismatch");
258 return 0;
262 /* Check mac option. */
264 static int
265 check_macfunc_option (Macfunc *a, Opt_mode *opt)
267 /* Default option is always valid. */
268 if (opt->mod == 0)
269 return 0;
271 if ((a->w == 1 && a->P == 1
272 && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_IU
273 && opt->mod != M_S2RND && opt->mod != M_ISS2)
274 || (a->w == 1 && a->P == 0
275 && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_IU
276 && opt->mod != M_T && opt->mod != M_TFU && opt->mod != M_S2RND
277 && opt->mod != M_ISS2 && opt->mod != M_IH)
278 || (a->w == 0 && a->P == 0
279 && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_W32))
280 return -1;
282 return 0;
285 /* Check (vector) mac funcs and ops. */
287 static int
288 check_macfuncs (Macfunc *aa, Opt_mode *opa,
289 Macfunc *ab, Opt_mode *opb)
291 /* Variables for swapping. */
292 Macfunc mtmp;
293 Opt_mode otmp;
295 /* The option mode should be put at the end of the second instruction
296 of the vector except M, which should follow MAC1 instruction. */
297 if (opa->mod != 0)
298 return yyerror ("Bad opt mode");
300 /* If a0macfunc comes before a1macfunc, swap them. */
302 if (aa->n == 0)
304 /* (M) is not allowed here. */
305 if (opa->MM != 0)
306 return yyerror ("(M) not allowed with A0MAC");
307 if (ab->n != 1)
308 return yyerror ("Vector AxMACs can't be same");
310 mtmp = *aa; *aa = *ab; *ab = mtmp;
311 otmp = *opa; *opa = *opb; *opb = otmp;
313 else
315 if (opb->MM != 0)
316 return yyerror ("(M) not allowed with A0MAC");
317 if (ab->n != 0)
318 return yyerror ("Vector AxMACs can't be same");
321 /* If both ops are one of 0, 1, or 2, we have multiply_halfregs in both
322 assignment_or_macfuncs. */
323 if ((aa->op == 0 || aa->op == 1 || aa->op == 2)
324 && (ab->op == 0 || ab->op == 1 || ab->op == 2))
326 if (check_multiply_halfregs (aa, ab) < 0)
327 return -1;
329 else
331 /* Only one of the assign_macfuncs has a half reg multiply
332 Evil trick: Just 'OR' their source register codes:
333 We can do that, because we know they were initialized to 0
334 in the rules that don't use multiply_halfregs. */
335 aa->s0.regno |= (ab->s0.regno & CODE_MASK);
336 aa->s1.regno |= (ab->s1.regno & CODE_MASK);
339 if (aa->w == ab->w && aa->P != ab->P)
340 return yyerror ("Destination Dreg sizes (full or half) must match");
342 if (aa->w && ab->w)
344 if (aa->P && (aa->dst.regno - ab->dst.regno) != 1)
345 return yyerror ("Destination Dregs (full) must differ by one");
346 if (!aa->P && aa->dst.regno != ab->dst.regno)
347 return yyerror ("Destination Dregs (half) must match");
350 /* Make sure mod flags get ORed, too. */
351 opb->mod |= opa->mod;
353 /* Check option. */
354 if (check_macfunc_option (aa, opb) < 0
355 && check_macfunc_option (ab, opb) < 0)
356 return yyerror ("bad option");
358 /* Make sure first macfunc has got both P flags ORed. */
359 aa->P |= ab->P;
361 return 0;
365 static int
366 is_group1 (INSTR_T x)
368 /* Group1 is dpsLDST, LDSTpmod, LDST, LDSTiiFP, LDSTii. */
369 if ((x->value & 0xc000) == 0x8000 || (x->value == 0x0000))
370 return 1;
372 return 0;
375 static int
376 is_group2 (INSTR_T x)
378 if ((((x->value & 0xfc00) == 0x9c00) /* dspLDST. */
379 && !((x->value & 0xfde0) == 0x9c60) /* dagMODim. */
380 && !((x->value & 0xfde0) == 0x9ce0) /* dagMODim with bit rev. */
381 && !((x->value & 0xfde0) == 0x9d60)) /* pick dagMODik. */
382 || (x->value == 0x0000))
383 return 1;
384 return 0;
387 static int
388 is_store (INSTR_T x)
390 if (!x)
391 return 0;
393 if ((x->value & 0xf000) == 0x8000)
395 int aop = ((x->value >> 9) & 0x3);
396 int w = ((x->value >> 11) & 0x1);
397 if (!w || aop == 3)
398 return 0;
399 return 1;
402 if (((x->value & 0xFF60) == 0x9E60) || /* dagMODim_0 */
403 ((x->value & 0xFFF0) == 0x9F60)) /* dagMODik_0 */
404 return 0;
406 /* decode_dspLDST_0 */
407 if ((x->value & 0xFC00) == 0x9C00)
409 int w = ((x->value >> 9) & 0x1);
410 if (w)
411 return 1;
414 return 0;
417 static INSTR_T
418 gen_multi_instr_1 (INSTR_T dsp32, INSTR_T dsp16_grp1, INSTR_T dsp16_grp2)
420 int mask1 = dsp32 ? insn_regmask (dsp32->value, dsp32->next->value) : 0;
421 int mask2 = dsp16_grp1 ? insn_regmask (dsp16_grp1->value, 0) : 0;
422 int mask3 = dsp16_grp2 ? insn_regmask (dsp16_grp2->value, 0) : 0;
424 if ((mask1 & mask2) || (mask1 & mask3) || (mask2 & mask3))
425 yyerror ("resource conflict in multi-issue instruction");
427 /* Anomaly 05000074 */
428 if (ENABLE_AC_05000074
429 && dsp32 != NULL && dsp16_grp1 != NULL
430 && (dsp32->value & 0xf780) == 0xc680
431 && ((dsp16_grp1->value & 0xfe40) == 0x9240
432 || (dsp16_grp1->value & 0xfe08) == 0xba08
433 || (dsp16_grp1->value & 0xfc00) == 0xbc00))
434 yyerror ("anomaly 05000074 - Multi-Issue Instruction with \
435 dsp32shiftimm in slot1 and P-reg Store in slot2 Not Supported");
437 if (is_store (dsp16_grp1) && is_store (dsp16_grp2))
438 yyerror ("Only one instruction in multi-issue instruction can be a store");
440 return bfin_gen_multi_instr (dsp32, dsp16_grp1, dsp16_grp2);
445 %union {
446 INSTR_T instr;
447 Expr_Node *expr;
448 SYMBOL_T symbol;
449 long value;
450 Register reg;
451 Macfunc macfunc;
452 struct { int r0; int s0; int x0; int aop; } modcodes;
453 struct { int r0; } r0;
454 Opt_mode mod;
458 /* Tokens. */
460 /* Vector Specific. */
461 %token BYTEOP16P BYTEOP16M
462 %token BYTEOP1P BYTEOP2P BYTEOP3P
463 %token BYTEUNPACK BYTEPACK
464 %token PACK
465 %token SAA
466 %token ALIGN8 ALIGN16 ALIGN24
467 %token VIT_MAX
468 %token EXTRACT DEPOSIT EXPADJ SEARCH
469 %token ONES SIGN SIGNBITS
471 /* Stack. */
472 %token LINK UNLINK
474 /* Registers. */
475 %token REG
476 %token PC
477 %token CCREG BYTE_DREG
478 %token REG_A_DOUBLE_ZERO REG_A_DOUBLE_ONE
479 %token A_ZERO_DOT_L A_ZERO_DOT_H A_ONE_DOT_L A_ONE_DOT_H
480 %token HALF_REG
482 /* Progctrl. */
483 %token NOP
484 %token RTI RTS RTX RTN RTE
485 %token HLT IDLE
486 %token STI CLI
487 %token CSYNC SSYNC
488 %token EMUEXCPT
489 %token RAISE EXCPT
490 %token LSETUP
491 %token LOOP
492 %token LOOP_BEGIN
493 %token LOOP_END
494 %token DISALGNEXCPT
495 %token JUMP JUMP_DOT_S JUMP_DOT_L
496 %token CALL
498 /* Emulator only. */
499 %token ABORT
501 /* Operators. */
502 %token NOT TILDA BANG
503 %token AMPERSAND BAR
504 %token PERCENT
505 %token CARET
506 %token BXOR
508 %token MINUS PLUS STAR SLASH
509 %token NEG
510 %token MIN MAX ABS
511 %token DOUBLE_BAR
512 %token _PLUS_BAR_PLUS _PLUS_BAR_MINUS _MINUS_BAR_PLUS _MINUS_BAR_MINUS
513 %token _MINUS_MINUS _PLUS_PLUS
515 /* Shift/rotate ops. */
516 %token SHIFT LSHIFT ASHIFT BXORSHIFT
517 %token _GREATER_GREATER_GREATER_THAN_ASSIGN
518 %token ROT
519 %token LESS_LESS GREATER_GREATER
520 %token _GREATER_GREATER_GREATER
521 %token _LESS_LESS_ASSIGN _GREATER_GREATER_ASSIGN
522 %token DIVS DIVQ
524 /* In place operators. */
525 %token ASSIGN _STAR_ASSIGN
526 %token _BAR_ASSIGN _CARET_ASSIGN _AMPERSAND_ASSIGN
527 %token _MINUS_ASSIGN _PLUS_ASSIGN
529 /* Assignments, comparisons. */
530 %token _ASSIGN_BANG _LESS_THAN_ASSIGN _ASSIGN_ASSIGN
531 %token GE LT LE GT
532 %token LESS_THAN
534 /* Cache. */
535 %token FLUSHINV FLUSH
536 %token IFLUSH PREFETCH
538 /* Misc. */
539 %token PRNT
540 %token OUTC
541 %token WHATREG
542 %token TESTSET
544 /* Modifiers. */
545 %token ASL ASR
546 %token B W
547 %token NS S CO SCO
548 %token TH TL
549 %token BP
550 %token BREV
551 %token X Z
552 %token M MMOD
553 %token R RND RNDL RNDH RND12 RND20
554 %token V
555 %token LO HI
557 /* Bit ops. */
558 %token BITTGL BITCLR BITSET BITTST BITMUX
560 /* Debug. */
561 %token DBGAL DBGAH DBGHALT DBG DBGA DBGCMPLX
563 /* Semantic auxiliaries. */
565 %token IF COMMA BY
566 %token COLON SEMICOLON
567 %token RPAREN LPAREN LBRACK RBRACK
568 %token STATUS_REG
569 %token MNOP
570 %token SYMBOL NUMBER
571 %token GOT GOT17M4 FUNCDESC_GOT17M4
572 %token AT PLTPC
574 /* Types. */
575 %type <instr> asm
576 %type <value> MMOD
577 %type <mod> opt_mode
579 %type <value> NUMBER
580 %type <r0> aligndir
581 %type <modcodes> byteop_mod
582 %type <reg> a_assign
583 %type <reg> a_plusassign
584 %type <reg> a_minusassign
585 %type <macfunc> multiply_halfregs
586 %type <macfunc> assign_macfunc
587 %type <macfunc> a_macfunc
588 %type <expr> expr_1
589 %type <instr> asm_1
590 %type <r0> vmod
591 %type <modcodes> vsmod
592 %type <modcodes> ccstat
593 %type <r0> cc_op
594 %type <reg> CCREG
595 %type <reg> reg_with_postinc
596 %type <reg> reg_with_predec
598 %type <r0> searchmod
599 %type <expr> symbol
600 %type <symbol> SYMBOL
601 %type <expr> eterm
602 %type <reg> REG
603 %type <reg> BYTE_DREG
604 %type <reg> REG_A_DOUBLE_ZERO
605 %type <reg> REG_A_DOUBLE_ONE
606 %type <reg> REG_A
607 %type <reg> STATUS_REG
608 %type <expr> expr
609 %type <r0> xpmod
610 %type <r0> xpmod1
611 %type <modcodes> smod
612 %type <modcodes> b3_op
613 %type <modcodes> rnd_op
614 %type <modcodes> post_op
615 %type <reg> HALF_REG
616 %type <r0> iu_or_nothing
617 %type <r0> plus_minus
618 %type <r0> asr_asl
619 %type <r0> asr_asl_0
620 %type <modcodes> sco
621 %type <modcodes> amod0
622 %type <modcodes> amod1
623 %type <modcodes> amod2
624 %type <r0> op_bar_op
625 %type <r0> w32_or_nothing
626 %type <r0> c_align
627 %type <r0> min_max
628 %type <expr> got
629 %type <expr> got_or_expr
630 %type <expr> pltpc
631 %type <value> any_gotrel GOT GOT17M4 FUNCDESC_GOT17M4
633 /* Precedence rules. */
634 %left BAR
635 %left CARET
636 %left AMPERSAND
637 %left LESS_LESS GREATER_GREATER
638 %left PLUS MINUS
639 %left STAR SLASH PERCENT
641 %right ASSIGN
643 %right TILDA BANG
644 %start statement
646 statement:
647 | asm
649 insn = $1;
650 if (insn == (INSTR_T) 0)
651 return NO_INSN_GENERATED;
652 else if (insn == (INSTR_T) - 1)
653 return SEMANTIC_ERROR;
654 else
655 return INSN_GENERATED;
659 asm: asm_1 SEMICOLON
660 /* Parallel instructions. */
661 | asm_1 DOUBLE_BAR asm_1 DOUBLE_BAR asm_1 SEMICOLON
663 if (($1->value & 0xf800) == 0xc000)
665 if (is_group1 ($3) && is_group2 ($5))
666 $$ = gen_multi_instr_1 ($1, $3, $5);
667 else if (is_group2 ($3) && is_group1 ($5))
668 $$ = gen_multi_instr_1 ($1, $5, $3);
669 else
670 return yyerror ("Wrong 16 bit instructions groups, slot 2 and slot 3 must be 16-bit instrution group");
672 else if (($3->value & 0xf800) == 0xc000)
674 if (is_group1 ($1) && is_group2 ($5))
675 $$ = gen_multi_instr_1 ($3, $1, $5);
676 else if (is_group2 ($1) && is_group1 ($5))
677 $$ = gen_multi_instr_1 ($3, $5, $1);
678 else
679 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 3 must be 16-bit instrution group");
681 else if (($5->value & 0xf800) == 0xc000)
683 if (is_group1 ($1) && is_group2 ($3))
684 $$ = gen_multi_instr_1 ($5, $1, $3);
685 else if (is_group2 ($1) && is_group1 ($3))
686 $$ = gen_multi_instr_1 ($5, $3, $1);
687 else
688 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be 16-bit instrution group");
690 else
691 error ("\nIllegal Multi Issue Construct, at least any one of the slot must be DSP32 instruction group\n");
694 | asm_1 DOUBLE_BAR asm_1 SEMICOLON
696 if (($1->value & 0xf800) == 0xc000)
698 if (is_group1 ($3))
699 $$ = gen_multi_instr_1 ($1, $3, 0);
700 else if (is_group2 ($3))
701 $$ = gen_multi_instr_1 ($1, 0, $3);
702 else
703 return yyerror ("Wrong 16 bit instructions groups, slot 2 must be the 16-bit instruction group");
705 else if (($3->value & 0xf800) == 0xc000)
707 if (is_group1 ($1))
708 $$ = gen_multi_instr_1 ($3, $1, 0);
709 else if (is_group2 ($1))
710 $$ = gen_multi_instr_1 ($3, 0, $1);
711 else
712 return yyerror ("Wrong 16 bit instructions groups, slot 1 must be the 16-bit instruction group");
714 else if (is_group1 ($1) && is_group2 ($3))
715 $$ = gen_multi_instr_1 (0, $1, $3);
716 else if (is_group2 ($1) && is_group1 ($3))
717 $$ = gen_multi_instr_1 (0, $3, $1);
718 else
719 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be the 16-bit instruction group");
721 | error
723 $$ = 0;
724 yyerror ("");
725 yyerrok;
729 /* DSPMAC. */
731 asm_1:
732 MNOP
734 $$ = DSP32MAC (3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
736 | assign_macfunc opt_mode
738 int op0, op1;
739 int w0 = 0, w1 = 0;
740 int h00, h10, h01, h11;
742 if (check_macfunc_option (&$1, &$2) < 0)
743 return yyerror ("bad option");
745 if ($1.n == 0)
747 if ($2.MM)
748 return yyerror ("(m) not allowed with a0 unit");
749 op1 = 3;
750 op0 = $1.op;
751 w1 = 0;
752 w0 = $1.w;
753 h00 = IS_H ($1.s0);
754 h10 = IS_H ($1.s1);
755 h01 = h11 = 0;
757 else
759 op1 = $1.op;
760 op0 = 3;
761 w1 = $1.w;
762 w0 = 0;
763 h00 = h10 = 0;
764 h01 = IS_H ($1.s0);
765 h11 = IS_H ($1.s1);
767 $$ = DSP32MAC (op1, $2.MM, $2.mod, w1, $1.P, h01, h11, h00, h10,
768 &$1.dst, op0, &$1.s0, &$1.s1, w0);
772 /* VECTOR MACs. */
774 | assign_macfunc opt_mode COMMA assign_macfunc opt_mode
776 Register *dst;
778 if (check_macfuncs (&$1, &$2, &$4, &$5) < 0)
779 return -1;
780 notethat ("assign_macfunc (.), assign_macfunc (.)\n");
782 if ($1.w)
783 dst = &$1.dst;
784 else
785 dst = &$4.dst;
787 $$ = DSP32MAC ($1.op, $2.MM, $5.mod, $1.w, $1.P,
788 IS_H ($1.s0), IS_H ($1.s1), IS_H ($4.s0), IS_H ($4.s1),
789 dst, $4.op, &$1.s0, &$1.s1, $4.w);
792 /* DSPALU. */
794 | DISALGNEXCPT
796 notethat ("dsp32alu: DISALGNEXCPT\n");
797 $$ = DSP32ALU (18, 0, 0, 0, 0, 0, 0, 0, 3);
799 | REG ASSIGN LPAREN a_plusassign REG_A RPAREN
801 if (IS_DREG ($1) && !IS_A1 ($4) && IS_A1 ($5))
803 notethat ("dsp32alu: dregs = ( A0 += A1 )\n");
804 $$ = DSP32ALU (11, 0, 0, &$1, 0, 0, 0, 0, 0);
806 else
807 return yyerror ("Register mismatch");
809 | HALF_REG ASSIGN LPAREN a_plusassign REG_A RPAREN
811 if (!IS_A1 ($4) && IS_A1 ($5))
813 notethat ("dsp32alu: dregs_half = ( A0 += A1 )\n");
814 $$ = DSP32ALU (11, IS_H ($1), 0, &$1, 0, 0, 0, 0, 1);
816 else
817 return yyerror ("Register mismatch");
819 | A_ZERO_DOT_H ASSIGN HALF_REG
821 notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
822 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
824 | A_ONE_DOT_H ASSIGN HALF_REG
826 notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
827 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
829 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16P LPAREN REG
830 COLON expr COMMA REG COLON expr RPAREN aligndir
832 if (!IS_DREG ($2) || !IS_DREG ($4))
833 return yyerror ("Dregs expected");
834 else if (REG_SAME ($2, $4))
835 return yyerror ("Illegal dest register combination");
836 else if (!valid_dreg_pair (&$9, $11))
837 return yyerror ("Bad dreg pair");
838 else if (!valid_dreg_pair (&$13, $15))
839 return yyerror ("Bad dreg pair");
840 else
842 notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16P (dregs_pair , dregs_pair ) (aligndir)\n");
843 $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 0);
847 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16M LPAREN REG COLON expr COMMA
848 REG COLON expr RPAREN aligndir
850 if (!IS_DREG ($2) || !IS_DREG ($4))
851 return yyerror ("Dregs expected");
852 else if (REG_SAME ($2, $4))
853 return yyerror ("Illegal dest register combination");
854 else if (!valid_dreg_pair (&$9, $11))
855 return yyerror ("Bad dreg pair");
856 else if (!valid_dreg_pair (&$13, $15))
857 return yyerror ("Bad dreg pair");
858 else
860 notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16M (dregs_pair , dregs_pair ) (aligndir)\n");
861 $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 1);
865 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEUNPACK REG COLON expr aligndir
867 if (!IS_DREG ($2) || !IS_DREG ($4))
868 return yyerror ("Dregs expected");
869 else if (REG_SAME ($2, $4))
870 return yyerror ("Illegal dest register combination");
871 else if (!valid_dreg_pair (&$8, $10))
872 return yyerror ("Bad dreg pair");
873 else
875 notethat ("dsp32alu: (dregs , dregs ) = BYTEUNPACK dregs_pair (aligndir)\n");
876 $$ = DSP32ALU (24, 0, &$2, &$4, &$8, 0, $11.r0, 0, 1);
879 | LPAREN REG COMMA REG RPAREN ASSIGN SEARCH REG LPAREN searchmod RPAREN
881 if (REG_SAME ($2, $4))
882 return yyerror ("Illegal dest register combination");
884 if (IS_DREG ($2) && IS_DREG ($4) && IS_DREG ($8))
886 notethat ("dsp32alu: (dregs , dregs ) = SEARCH dregs (searchmod)\n");
887 $$ = DSP32ALU (13, 0, &$2, &$4, &$8, 0, 0, 0, $10.r0);
889 else
890 return yyerror ("Register mismatch");
892 | REG ASSIGN A_ONE_DOT_L PLUS A_ONE_DOT_H COMMA
893 REG ASSIGN A_ZERO_DOT_L PLUS A_ZERO_DOT_H
895 if (REG_SAME ($1, $7))
896 return yyerror ("Illegal dest register combination");
898 if (IS_DREG ($1) && IS_DREG ($7))
900 notethat ("dsp32alu: dregs = A1.l + A1.h, dregs = A0.l + A0.h \n");
901 $$ = DSP32ALU (12, 0, &$1, &$7, 0, 0, 0, 0, 1);
903 else
904 return yyerror ("Register mismatch");
908 | REG ASSIGN REG_A PLUS REG_A COMMA REG ASSIGN REG_A MINUS REG_A amod1
910 if (REG_SAME ($1, $7))
911 return yyerror ("Resource conflict in dest reg");
913 if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
914 && IS_A1 ($9) && !IS_A1 ($11))
916 notethat ("dsp32alu: dregs = A1 + A0 , dregs = A1 - A0 (amod1)\n");
917 $$ = DSP32ALU (17, 0, &$1, &$7, 0, 0, $12.s0, $12.x0, 0);
920 else if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
921 && !IS_A1 ($9) && IS_A1 ($11))
923 notethat ("dsp32alu: dregs = A0 + A1 , dregs = A0 - A1 (amod1)\n");
924 $$ = DSP32ALU (17, 0, &$1, &$7, 0, 0, $12.s0, $12.x0, 1);
926 else
927 return yyerror ("Register mismatch");
930 | REG ASSIGN REG plus_minus REG COMMA REG ASSIGN REG plus_minus REG amod1
932 if ($4.r0 == $10.r0)
933 return yyerror ("Operators must differ");
935 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5)
936 && REG_SAME ($3, $9) && REG_SAME ($5, $11))
938 notethat ("dsp32alu: dregs = dregs + dregs,"
939 "dregs = dregs - dregs (amod1)\n");
940 $$ = DSP32ALU (4, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, 2);
942 else
943 return yyerror ("Register mismatch");
946 /* Bar Operations. */
948 | REG ASSIGN REG op_bar_op REG COMMA REG ASSIGN REG op_bar_op REG amod2
950 if (!REG_SAME ($3, $9) || !REG_SAME ($5, $11))
951 return yyerror ("Differing source registers");
953 if (!IS_DREG ($1) || !IS_DREG ($3) || !IS_DREG ($5) || !IS_DREG ($7))
954 return yyerror ("Dregs expected");
956 if (REG_SAME ($1, $7))
957 return yyerror ("Resource conflict in dest reg");
959 if ($4.r0 == 1 && $10.r0 == 2)
961 notethat ("dsp32alu: dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
962 $$ = DSP32ALU (1, 1, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
964 else if ($4.r0 == 0 && $10.r0 == 3)
966 notethat ("dsp32alu: dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
967 $$ = DSP32ALU (1, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
969 else
970 return yyerror ("Bar operand mismatch");
973 | REG ASSIGN ABS REG vmod
975 int op;
977 if (IS_DREG ($1) && IS_DREG ($4))
979 if ($5.r0)
981 notethat ("dsp32alu: dregs = ABS dregs (v)\n");
982 op = 6;
984 else
986 /* Vector version of ABS. */
987 notethat ("dsp32alu: dregs = ABS dregs\n");
988 op = 7;
990 $$ = DSP32ALU (op, 0, 0, &$1, &$4, 0, 0, 0, 2);
992 else
993 return yyerror ("Dregs expected");
995 | a_assign ABS REG_A
997 notethat ("dsp32alu: Ax = ABS Ax\n");
998 $$ = DSP32ALU (16, IS_A1 ($1), 0, 0, 0, 0, 0, 0, IS_A1 ($3));
1000 | A_ZERO_DOT_L ASSIGN HALF_REG
1002 if (IS_DREG_L ($3))
1004 notethat ("dsp32alu: A0.l = reg_half\n");
1005 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
1007 else
1008 return yyerror ("A0.l = Rx.l expected");
1010 | A_ONE_DOT_L ASSIGN HALF_REG
1012 if (IS_DREG_L ($3))
1014 notethat ("dsp32alu: A1.l = reg_half\n");
1015 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
1017 else
1018 return yyerror ("A1.l = Rx.l expected");
1021 | REG ASSIGN c_align LPAREN REG COMMA REG RPAREN
1023 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1025 notethat ("dsp32shift: dregs = ALIGN8 (dregs , dregs )\n");
1026 $$ = DSP32SHIFT (13, &$1, &$7, &$5, $3.r0, 0);
1028 else
1029 return yyerror ("Dregs expected");
1032 | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN byteop_mod
1034 if (!IS_DREG ($1))
1035 return yyerror ("Dregs expected");
1036 else if (!valid_dreg_pair (&$5, $7))
1037 return yyerror ("Bad dreg pair");
1038 else if (!valid_dreg_pair (&$9, $11))
1039 return yyerror ("Bad dreg pair");
1040 else
1042 notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
1043 $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, $13.s0, 0, $13.r0);
1046 | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1048 if (!IS_DREG ($1))
1049 return yyerror ("Dregs expected");
1050 else if (!valid_dreg_pair (&$5, $7))
1051 return yyerror ("Bad dreg pair");
1052 else if (!valid_dreg_pair (&$9, $11))
1053 return yyerror ("Bad dreg pair");
1054 else
1056 notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
1057 $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, 0, 0, 0);
1061 | REG ASSIGN BYTEOP2P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1062 rnd_op
1064 if (!IS_DREG ($1))
1065 return yyerror ("Dregs expected");
1066 else if (!valid_dreg_pair (&$5, $7))
1067 return yyerror ("Bad dreg pair");
1068 else if (!valid_dreg_pair (&$9, $11))
1069 return yyerror ("Bad dreg pair");
1070 else
1072 notethat ("dsp32alu: dregs = BYTEOP2P (dregs_pair , dregs_pair ) (rnd_op)\n");
1073 $$ = DSP32ALU (22, $13.r0, 0, &$1, &$5, &$9, $13.s0, $13.x0, $13.aop);
1077 | REG ASSIGN BYTEOP3P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1078 b3_op
1080 if (!IS_DREG ($1))
1081 return yyerror ("Dregs expected");
1082 else if (!valid_dreg_pair (&$5, $7))
1083 return yyerror ("Bad dreg pair");
1084 else if (!valid_dreg_pair (&$9, $11))
1085 return yyerror ("Bad dreg pair");
1086 else
1088 notethat ("dsp32alu: dregs = BYTEOP3P (dregs_pair , dregs_pair ) (b3_op)\n");
1089 $$ = DSP32ALU (23, $13.x0, 0, &$1, &$5, &$9, $13.s0, 0, 0);
1093 | REG ASSIGN BYTEPACK LPAREN REG COMMA REG RPAREN
1095 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1097 notethat ("dsp32alu: dregs = BYTEPACK (dregs , dregs )\n");
1098 $$ = DSP32ALU (24, 0, 0, &$1, &$5, &$7, 0, 0, 0);
1100 else
1101 return yyerror ("Dregs expected");
1104 | HALF_REG ASSIGN HALF_REG ASSIGN SIGN LPAREN HALF_REG RPAREN STAR
1105 HALF_REG PLUS SIGN LPAREN HALF_REG RPAREN STAR HALF_REG
1107 if (IS_HCOMPL ($1, $3) && IS_HCOMPL ($7, $14) && IS_HCOMPL ($10, $17))
1109 notethat ("dsp32alu: dregs_hi = dregs_lo ="
1110 "SIGN (dregs_hi) * dregs_hi + "
1111 "SIGN (dregs_lo) * dregs_lo \n");
1113 $$ = DSP32ALU (12, 0, 0, &$1, &$7, &$10, 0, 0, 0);
1115 else
1116 return yyerror ("Dregs expected");
1118 | REG ASSIGN REG plus_minus REG amod1
1120 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1122 if ($6.aop == 0)
1124 /* No saturation flag specified, generate the 16 bit variant. */
1125 notethat ("COMP3op: dregs = dregs +- dregs\n");
1126 $$ = COMP3OP (&$1, &$3, &$5, $4.r0);
1128 else
1130 /* Saturation flag specified, generate the 32 bit variant. */
1131 notethat ("dsp32alu: dregs = dregs +- dregs (amod1)\n");
1132 $$ = DSP32ALU (4, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
1135 else
1136 if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($5) && $4.r0 == 0)
1138 notethat ("COMP3op: pregs = pregs + pregs\n");
1139 $$ = COMP3OP (&$1, &$3, &$5, 5);
1141 else
1142 return yyerror ("Dregs expected");
1144 | REG ASSIGN min_max LPAREN REG COMMA REG RPAREN vmod
1146 int op;
1148 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1150 if ($9.r0)
1151 op = 6;
1152 else
1153 op = 7;
1155 notethat ("dsp32alu: dregs = {MIN|MAX} (dregs, dregs)\n");
1156 $$ = DSP32ALU (op, 0, 0, &$1, &$5, &$7, 0, 0, $3.r0);
1158 else
1159 return yyerror ("Dregs expected");
1162 | a_assign MINUS REG_A
1164 notethat ("dsp32alu: Ax = - Ax\n");
1165 $$ = DSP32ALU (14, IS_A1 ($1), 0, 0, 0, 0, 0, 0, IS_A1 ($3));
1167 | HALF_REG ASSIGN HALF_REG plus_minus HALF_REG amod1
1169 notethat ("dsp32alu: dregs_lo = dregs_lo +- dregs_lo (amod1)\n");
1170 $$ = DSP32ALU (2 | $4.r0, IS_H ($1), 0, &$1, &$3, &$5,
1171 $6.s0, $6.x0, HL2 ($3, $5));
1173 | a_assign a_assign expr
1175 if (EXPR_VALUE ($3) == 0 && !REG_SAME ($1, $2))
1177 notethat ("dsp32alu: A1 = A0 = 0\n");
1178 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, 2);
1180 else
1181 return yyerror ("Bad value, 0 expected");
1184 /* Saturating. */
1185 | a_assign REG_A LPAREN S RPAREN
1187 if (REG_SAME ($1, $2))
1189 notethat ("dsp32alu: Ax = Ax (S)\n");
1190 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 1, 0, IS_A1 ($1));
1192 else
1193 return yyerror ("Registers must be equal");
1196 | HALF_REG ASSIGN REG LPAREN RND RPAREN
1198 if (IS_DREG ($3))
1200 notethat ("dsp32alu: dregs_half = dregs (RND)\n");
1201 $$ = DSP32ALU (12, IS_H ($1), 0, &$1, &$3, 0, 0, 0, 3);
1203 else
1204 return yyerror ("Dregs expected");
1207 | HALF_REG ASSIGN REG plus_minus REG LPAREN RND12 RPAREN
1209 if (IS_DREG ($3) && IS_DREG ($5))
1211 notethat ("dsp32alu: dregs_half = dregs (+-) dregs (RND12)\n");
1212 $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 0, $4.r0);
1214 else
1215 return yyerror ("Dregs expected");
1218 | HALF_REG ASSIGN REG plus_minus REG LPAREN RND20 RPAREN
1220 if (IS_DREG ($3) && IS_DREG ($5))
1222 notethat ("dsp32alu: dregs_half = dregs -+ dregs (RND20)\n");
1223 $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 1, $4.r0 | 2);
1225 else
1226 return yyerror ("Dregs expected");
1229 | a_assign REG_A
1231 if (!REG_SAME ($1, $2))
1233 notethat ("dsp32alu: An = Am\n");
1234 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, IS_A1 ($1), 0, 3);
1236 else
1237 return yyerror ("Accu reg arguments must differ");
1240 | a_assign REG
1242 if (IS_DREG ($2))
1244 notethat ("dsp32alu: An = dregs\n");
1245 $$ = DSP32ALU (9, 0, 0, 0, &$2, 0, 1, 0, IS_A1 ($1) << 1);
1247 else
1248 return yyerror ("Dregs expected");
1251 | REG ASSIGN HALF_REG xpmod
1253 if (!IS_H ($3))
1255 if ($1.regno == REG_A0x && IS_DREG ($3))
1257 notethat ("dsp32alu: A0.x = dregs_lo\n");
1258 $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 1);
1260 else if ($1.regno == REG_A1x && IS_DREG ($3))
1262 notethat ("dsp32alu: A1.x = dregs_lo\n");
1263 $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 3);
1265 else if (IS_DREG ($1) && IS_DREG ($3))
1267 notethat ("ALU2op: dregs = dregs_lo\n");
1268 $$ = ALU2OP (&$1, &$3, 10 | ($4.r0 ? 0: 1));
1270 else
1271 return yyerror ("Register mismatch");
1273 else
1274 return yyerror ("Low reg expected");
1277 | HALF_REG ASSIGN expr
1279 notethat ("LDIMMhalf: pregs_half = imm16\n");
1281 if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
1282 && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
1283 return yyerror ("Wrong register for load immediate");
1285 if (!IS_IMM ($3, 16) && !IS_UIMM ($3, 16))
1286 return yyerror ("Constant out of range");
1288 $$ = LDIMMHALF_R (&$1, IS_H ($1), 0, 0, $3);
1291 | a_assign expr
1293 notethat ("dsp32alu: An = 0\n");
1295 if (imm7 ($2) != 0)
1296 return yyerror ("0 expected");
1298 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, IS_A1 ($1));
1301 | REG ASSIGN expr xpmod1
1303 if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
1304 && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
1305 return yyerror ("Wrong register for load immediate");
1307 if ($4.r0 == 0)
1309 /* 7 bit immediate value if possible.
1310 We will check for that constant value for efficiency
1311 If it goes to reloc, it will be 16 bit. */
1312 if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_DREG ($1))
1314 notethat ("COMPI2opD: dregs = imm7 (x) \n");
1315 $$ = COMPI2OPD (&$1, imm7 ($3), 0);
1317 else if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_PREG ($1))
1319 notethat ("COMPI2opP: pregs = imm7 (x)\n");
1320 $$ = COMPI2OPP (&$1, imm7 ($3), 0);
1322 else
1324 if (IS_CONST ($3) && !IS_IMM ($3, 16))
1325 return yyerror ("Immediate value out of range");
1327 notethat ("LDIMMhalf: regs = luimm16 (x)\n");
1328 /* reg, H, S, Z. */
1329 $$ = LDIMMHALF_R5 (&$1, 0, 1, 0, $3);
1332 else
1334 /* (z) There is no 7 bit zero extended instruction.
1335 If the expr is a relocation, generate it. */
1337 if (IS_CONST ($3) && !IS_UIMM ($3, 16))
1338 return yyerror ("Immediate value out of range");
1340 notethat ("LDIMMhalf: regs = luimm16 (x)\n");
1341 /* reg, H, S, Z. */
1342 $$ = LDIMMHALF_R5 (&$1, 0, 0, 1, $3);
1346 | HALF_REG ASSIGN REG
1348 if (IS_H ($1))
1349 return yyerror ("Low reg expected");
1351 if (IS_DREG ($1) && $3.regno == REG_A0x)
1353 notethat ("dsp32alu: dregs_lo = A0.x\n");
1354 $$ = DSP32ALU (10, 0, 0, &$1, 0, 0, 0, 0, 0);
1356 else if (IS_DREG ($1) && $3.regno == REG_A1x)
1358 notethat ("dsp32alu: dregs_lo = A1.x\n");
1359 $$ = DSP32ALU (10, 0, 0, &$1, 0, 0, 0, 0, 1);
1361 else
1362 return yyerror ("Register mismatch");
1365 | REG ASSIGN REG op_bar_op REG amod0
1367 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1369 notethat ("dsp32alu: dregs = dregs .|. dregs (amod0)\n");
1370 $$ = DSP32ALU (0, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
1372 else
1373 return yyerror ("Register mismatch");
1376 | REG ASSIGN BYTE_DREG xpmod
1378 if (IS_DREG ($1) && IS_DREG ($3))
1380 notethat ("ALU2op: dregs = dregs_byte\n");
1381 $$ = ALU2OP (&$1, &$3, 12 | ($4.r0 ? 0: 1));
1383 else
1384 return yyerror ("Register mismatch");
1387 | a_assign ABS REG_A COMMA a_assign ABS REG_A
1389 if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
1391 notethat ("dsp32alu: A1 = ABS A1 , A0 = ABS A0\n");
1392 $$ = DSP32ALU (16, 0, 0, 0, 0, 0, 0, 0, 3);
1394 else
1395 return yyerror ("Register mismatch");
1398 | a_assign MINUS REG_A COMMA a_assign MINUS REG_A
1400 if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
1402 notethat ("dsp32alu: A1 = - A1 , A0 = - A0\n");
1403 $$ = DSP32ALU (14, 0, 0, 0, 0, 0, 0, 0, 3);
1405 else
1406 return yyerror ("Register mismatch");
1409 | a_minusassign REG_A w32_or_nothing
1411 if (!IS_A1 ($1) && IS_A1 ($2))
1413 notethat ("dsp32alu: A0 -= A1\n");
1414 $$ = DSP32ALU (11, 0, 0, 0, 0, 0, $3.r0, 0, 3);
1416 else
1417 return yyerror ("Register mismatch");
1420 | REG _MINUS_ASSIGN expr
1422 if (IS_IREG ($1) && EXPR_VALUE ($3) == 4)
1424 notethat ("dagMODik: iregs -= 4\n");
1425 $$ = DAGMODIK (&$1, 3);
1427 else if (IS_IREG ($1) && EXPR_VALUE ($3) == 2)
1429 notethat ("dagMODik: iregs -= 2\n");
1430 $$ = DAGMODIK (&$1, 1);
1432 else
1433 return yyerror ("Register or value mismatch");
1436 | REG _PLUS_ASSIGN REG LPAREN BREV RPAREN
1438 if (IS_IREG ($1) && IS_MREG ($3))
1440 notethat ("dagMODim: iregs += mregs (opt_brev)\n");
1441 /* i, m, op, br. */
1442 $$ = DAGMODIM (&$1, &$3, 0, 1);
1444 else if (IS_PREG ($1) && IS_PREG ($3))
1446 notethat ("PTR2op: pregs += pregs (BREV )\n");
1447 $$ = PTR2OP (&$1, &$3, 5);
1449 else
1450 return yyerror ("Register mismatch");
1453 | REG _MINUS_ASSIGN REG
1455 if (IS_IREG ($1) && IS_MREG ($3))
1457 notethat ("dagMODim: iregs -= mregs\n");
1458 $$ = DAGMODIM (&$1, &$3, 1, 0);
1460 else if (IS_PREG ($1) && IS_PREG ($3))
1462 notethat ("PTR2op: pregs -= pregs\n");
1463 $$ = PTR2OP (&$1, &$3, 0);
1465 else
1466 return yyerror ("Register mismatch");
1469 | REG_A _PLUS_ASSIGN REG_A w32_or_nothing
1471 if (!IS_A1 ($1) && IS_A1 ($3))
1473 notethat ("dsp32alu: A0 += A1 (W32)\n");
1474 $$ = DSP32ALU (11, 0, 0, 0, 0, 0, $4.r0, 0, 2);
1476 else
1477 return yyerror ("Register mismatch");
1480 | REG _PLUS_ASSIGN REG
1482 if (IS_IREG ($1) && IS_MREG ($3))
1484 notethat ("dagMODim: iregs += mregs\n");
1485 $$ = DAGMODIM (&$1, &$3, 0, 0);
1487 else
1488 return yyerror ("iregs += mregs expected");
1491 | REG _PLUS_ASSIGN expr
1493 if (IS_IREG ($1))
1495 if (EXPR_VALUE ($3) == 4)
1497 notethat ("dagMODik: iregs += 4\n");
1498 $$ = DAGMODIK (&$1, 2);
1500 else if (EXPR_VALUE ($3) == 2)
1502 notethat ("dagMODik: iregs += 2\n");
1503 $$ = DAGMODIK (&$1, 0);
1505 else
1506 return yyerror ("iregs += [ 2 | 4 ");
1508 else if (IS_PREG ($1) && IS_IMM ($3, 7))
1510 notethat ("COMPI2opP: pregs += imm7\n");
1511 $$ = COMPI2OPP (&$1, imm7 ($3), 1);
1513 else if (IS_DREG ($1) && IS_IMM ($3, 7))
1515 notethat ("COMPI2opD: dregs += imm7\n");
1516 $$ = COMPI2OPD (&$1, imm7 ($3), 1);
1518 else if ((IS_DREG ($1) || IS_PREG ($1)) && IS_CONST ($3))
1519 return yyerror ("Immediate value out of range");
1520 else
1521 return yyerror ("Register mismatch");
1524 | REG _STAR_ASSIGN REG
1526 if (IS_DREG ($1) && IS_DREG ($3))
1528 notethat ("ALU2op: dregs *= dregs\n");
1529 $$ = ALU2OP (&$1, &$3, 3);
1531 else
1532 return yyerror ("Register mismatch");
1535 | SAA LPAREN REG COLON expr COMMA REG COLON expr RPAREN aligndir
1537 if (!valid_dreg_pair (&$3, $5))
1538 return yyerror ("Bad dreg pair");
1539 else if (!valid_dreg_pair (&$7, $9))
1540 return yyerror ("Bad dreg pair");
1541 else
1543 notethat ("dsp32alu: SAA (dregs_pair , dregs_pair ) (aligndir)\n");
1544 $$ = DSP32ALU (18, 0, 0, 0, &$3, &$7, $11.r0, 0, 0);
1548 | a_assign REG_A LPAREN S RPAREN COMMA a_assign REG_A LPAREN S RPAREN
1550 if (REG_SAME ($1, $2) && REG_SAME ($7, $8) && !REG_SAME ($1, $7))
1552 notethat ("dsp32alu: A1 = A1 (S) , A0 = A0 (S)\n");
1553 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 1, 0, 2);
1555 else
1556 return yyerror ("Register mismatch");
1559 | REG ASSIGN LPAREN REG PLUS REG RPAREN LESS_LESS expr
1561 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6)
1562 && REG_SAME ($1, $4))
1564 if (EXPR_VALUE ($9) == 1)
1566 notethat ("ALU2op: dregs = (dregs + dregs) << 1\n");
1567 $$ = ALU2OP (&$1, &$6, 4);
1569 else if (EXPR_VALUE ($9) == 2)
1571 notethat ("ALU2op: dregs = (dregs + dregs) << 2\n");
1572 $$ = ALU2OP (&$1, &$6, 5);
1574 else
1575 return yyerror ("Bad shift value");
1577 else if (IS_PREG ($1) && IS_PREG ($4) && IS_PREG ($6)
1578 && REG_SAME ($1, $4))
1580 if (EXPR_VALUE ($9) == 1)
1582 notethat ("PTR2op: pregs = (pregs + pregs) << 1\n");
1583 $$ = PTR2OP (&$1, &$6, 6);
1585 else if (EXPR_VALUE ($9) == 2)
1587 notethat ("PTR2op: pregs = (pregs + pregs) << 2\n");
1588 $$ = PTR2OP (&$1, &$6, 7);
1590 else
1591 return yyerror ("Bad shift value");
1593 else
1594 return yyerror ("Register mismatch");
1597 /* COMP3 CCFLAG. */
1598 | REG ASSIGN REG BAR REG
1600 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1602 notethat ("COMP3op: dregs = dregs | dregs\n");
1603 $$ = COMP3OP (&$1, &$3, &$5, 3);
1605 else
1606 return yyerror ("Dregs expected");
1608 | REG ASSIGN REG CARET REG
1610 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1612 notethat ("COMP3op: dregs = dregs ^ dregs\n");
1613 $$ = COMP3OP (&$1, &$3, &$5, 4);
1615 else
1616 return yyerror ("Dregs expected");
1618 | REG ASSIGN REG PLUS LPAREN REG LESS_LESS expr RPAREN
1620 if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($6))
1622 if (EXPR_VALUE ($8) == 1)
1624 notethat ("COMP3op: pregs = pregs + (pregs << 1)\n");
1625 $$ = COMP3OP (&$1, &$3, &$6, 6);
1627 else if (EXPR_VALUE ($8) == 2)
1629 notethat ("COMP3op: pregs = pregs + (pregs << 2)\n");
1630 $$ = COMP3OP (&$1, &$3, &$6, 7);
1632 else
1633 return yyerror ("Bad shift value");
1635 else
1636 return yyerror ("Dregs expected");
1638 | CCREG ASSIGN REG_A _ASSIGN_ASSIGN REG_A
1640 if ($3.regno == REG_A0 && $5.regno == REG_A1)
1642 notethat ("CCflag: CC = A0 == A1\n");
1643 $$ = CCFLAG (0, 0, 5, 0, 0);
1645 else
1646 return yyerror ("AREGs are in bad order or same");
1648 | CCREG ASSIGN REG_A LESS_THAN REG_A
1650 if ($3.regno == REG_A0 && $5.regno == REG_A1)
1652 notethat ("CCflag: CC = A0 < A1\n");
1653 $$ = CCFLAG (0, 0, 6, 0, 0);
1655 else
1656 return yyerror ("AREGs are in bad order or same");
1658 | CCREG ASSIGN REG LESS_THAN REG iu_or_nothing
1660 if ((IS_DREG ($3) && IS_DREG ($5))
1661 || (IS_PREG ($3) && IS_PREG ($5)))
1663 notethat ("CCflag: CC = dpregs < dpregs\n");
1664 $$ = CCFLAG (&$3, $5.regno & CODE_MASK, $6.r0, 0, IS_PREG ($3) ? 1 : 0);
1666 else
1667 return yyerror ("Bad register in comparison");
1669 | CCREG ASSIGN REG LESS_THAN expr iu_or_nothing
1671 if (!IS_DREG ($3) && !IS_PREG ($3))
1672 return yyerror ("Bad register in comparison");
1674 if (($6.r0 == 1 && IS_IMM ($5, 3))
1675 || ($6.r0 == 3 && IS_UIMM ($5, 3)))
1677 notethat ("CCflag: CC = dpregs < (u)imm3\n");
1678 $$ = CCFLAG (&$3, imm3 ($5), $6.r0, 1, IS_PREG ($3) ? 1 : 0);
1680 else
1681 return yyerror ("Bad constant value");
1683 | CCREG ASSIGN REG _ASSIGN_ASSIGN REG
1685 if ((IS_DREG ($3) && IS_DREG ($5))
1686 || (IS_PREG ($3) && IS_PREG ($5)))
1688 notethat ("CCflag: CC = dpregs == dpregs\n");
1689 $$ = CCFLAG (&$3, $5.regno & CODE_MASK, 0, 0, IS_PREG ($3) ? 1 : 0);
1691 else
1692 return yyerror ("Bad register in comparison");
1694 | CCREG ASSIGN REG _ASSIGN_ASSIGN expr
1696 if (!IS_DREG ($3) && !IS_PREG ($3))
1697 return yyerror ("Bad register in comparison");
1699 if (IS_IMM ($5, 3))
1701 notethat ("CCflag: CC = dpregs == imm3\n");
1702 $$ = CCFLAG (&$3, imm3 ($5), 0, 1, IS_PREG ($3) ? 1 : 0);
1704 else
1705 return yyerror ("Bad constant range");
1707 | CCREG ASSIGN REG_A _LESS_THAN_ASSIGN REG_A
1709 if ($3.regno == REG_A0 && $5.regno == REG_A1)
1711 notethat ("CCflag: CC = A0 <= A1\n");
1712 $$ = CCFLAG (0, 0, 7, 0, 0);
1714 else
1715 return yyerror ("AREGs are in bad order or same");
1717 | CCREG ASSIGN REG _LESS_THAN_ASSIGN REG iu_or_nothing
1719 if ((IS_DREG ($3) && IS_DREG ($5))
1720 || (IS_PREG ($3) && IS_PREG ($5)))
1722 notethat ("CCflag: CC = dpregs <= dpregs (..)\n");
1723 $$ = CCFLAG (&$3, $5.regno & CODE_MASK,
1724 1 + $6.r0, 0, IS_PREG ($3) ? 1 : 0);
1726 else
1727 return yyerror ("Bad register in comparison");
1729 | CCREG ASSIGN REG _LESS_THAN_ASSIGN expr iu_or_nothing
1731 if (!IS_DREG ($3) && !IS_PREG ($3))
1732 return yyerror ("Bad register in comparison");
1734 if (($6.r0 == 1 && IS_IMM ($5, 3))
1735 || ($6.r0 == 3 && IS_UIMM ($5, 3)))
1737 notethat ("CCflag: CC = dpregs <= (u)imm3\n");
1738 $$ = CCFLAG (&$3, imm3 ($5), 1 + $6.r0, 1, IS_PREG ($3) ? 1 : 0);
1740 else
1741 return yyerror ("Bad constant value");
1744 | REG ASSIGN REG AMPERSAND REG
1746 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1748 notethat ("COMP3op: dregs = dregs & dregs\n");
1749 $$ = COMP3OP (&$1, &$3, &$5, 2);
1751 else
1752 return yyerror ("Dregs expected");
1755 | ccstat
1757 notethat ("CC2stat operation\n");
1758 $$ = bfin_gen_cc2stat ($1.r0, $1.x0, $1.s0);
1761 | REG ASSIGN REG
1763 if ((IS_GENREG ($1) && IS_GENREG ($3))
1764 || (IS_GENREG ($1) && IS_DAGREG ($3))
1765 || (IS_DAGREG ($1) && IS_GENREG ($3))
1766 || (IS_DAGREG ($1) && IS_DAGREG ($3))
1767 || (IS_GENREG ($1) && $3.regno == REG_USP)
1768 || ($1.regno == REG_USP && IS_GENREG ($3))
1769 || ($1.regno == REG_USP && $3.regno == REG_USP)
1770 || (IS_DREG ($1) && IS_SYSREG ($3))
1771 || (IS_PREG ($1) && IS_SYSREG ($3))
1772 || (IS_SYSREG ($1) && IS_GENREG ($3))
1773 || (IS_ALLREG ($1) && IS_EMUDAT ($3))
1774 || (IS_EMUDAT ($1) && IS_ALLREG ($3))
1775 || (IS_SYSREG ($1) && $3.regno == REG_USP))
1777 $$ = bfin_gen_regmv (&$3, &$1);
1779 else
1780 return yyerror ("Unsupported register move");
1783 | CCREG ASSIGN REG
1785 if (IS_DREG ($3))
1787 notethat ("CC2dreg: CC = dregs\n");
1788 $$ = bfin_gen_cc2dreg (1, &$3);
1790 else
1791 return yyerror ("Only 'CC = Dreg' supported");
1794 | REG ASSIGN CCREG
1796 if (IS_DREG ($1))
1798 notethat ("CC2dreg: dregs = CC\n");
1799 $$ = bfin_gen_cc2dreg (0, &$1);
1801 else
1802 return yyerror ("Only 'Dreg = CC' supported");
1805 | CCREG _ASSIGN_BANG CCREG
1807 notethat ("CC2dreg: CC =! CC\n");
1808 $$ = bfin_gen_cc2dreg (3, 0);
1811 /* DSPMULT. */
1813 | HALF_REG ASSIGN multiply_halfregs opt_mode
1815 notethat ("dsp32mult: dregs_half = multiply_halfregs (opt_mode)\n");
1817 if (!IS_H ($1) && $4.MM)
1818 return yyerror ("(M) not allowed with MAC0");
1820 if ($4.mod != 0 && $4.mod != M_FU && $4.mod != M_IS
1821 && $4.mod != M_IU && $4.mod != M_T && $4.mod != M_TFU
1822 && $4.mod != M_S2RND && $4.mod != M_ISS2 && $4.mod != M_IH)
1823 return yyerror ("bad option.");
1825 if (IS_H ($1))
1827 $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 0,
1828 IS_H ($3.s0), IS_H ($3.s1), 0, 0,
1829 &$1, 0, &$3.s0, &$3.s1, 0);
1831 else
1833 $$ = DSP32MULT (0, 0, $4.mod, 0, 0,
1834 0, 0, IS_H ($3.s0), IS_H ($3.s1),
1835 &$1, 0, &$3.s0, &$3.s1, 1);
1839 | REG ASSIGN multiply_halfregs opt_mode
1841 /* Odd registers can use (M). */
1842 if (!IS_DREG ($1))
1843 return yyerror ("Dreg expected");
1845 if (IS_EVEN ($1) && $4.MM)
1846 return yyerror ("(M) not allowed with MAC0");
1848 if ($4.mod != 0 && $4.mod != M_FU && $4.mod != M_IS
1849 && $4.mod != M_S2RND && $4.mod != M_ISS2)
1850 return yyerror ("bad option");
1852 if (!IS_EVEN ($1))
1854 notethat ("dsp32mult: dregs = multiply_halfregs (opt_mode)\n");
1856 $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 1,
1857 IS_H ($3.s0), IS_H ($3.s1), 0, 0,
1858 &$1, 0, &$3.s0, &$3.s1, 0);
1860 else
1862 notethat ("dsp32mult: dregs = multiply_halfregs opt_mode\n");
1863 $$ = DSP32MULT (0, 0, $4.mod, 0, 1,
1864 0, 0, IS_H ($3.s0), IS_H ($3.s1),
1865 &$1, 0, &$3.s0, &$3.s1, 1);
1869 | HALF_REG ASSIGN multiply_halfregs opt_mode COMMA
1870 HALF_REG ASSIGN multiply_halfregs opt_mode
1872 if (!IS_DREG ($1) || !IS_DREG ($6))
1873 return yyerror ("Dregs expected");
1875 if (!IS_HCOMPL($1, $6))
1876 return yyerror ("Dest registers mismatch");
1878 if (check_multiply_halfregs (&$3, &$8) < 0)
1879 return -1;
1881 if ((!IS_H ($1) && $4.MM)
1882 || (!IS_H ($6) && $9.MM))
1883 return yyerror ("(M) not allowed with MAC0");
1885 notethat ("dsp32mult: dregs_hi = multiply_halfregs mxd_mod, "
1886 "dregs_lo = multiply_halfregs opt_mode\n");
1888 if (IS_H ($1))
1889 $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 0,
1890 IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
1891 &$1, 0, &$3.s0, &$3.s1, 1);
1892 else
1893 $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 0,
1894 IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
1895 &$1, 0, &$3.s0, &$3.s1, 1);
1898 | REG ASSIGN multiply_halfregs opt_mode COMMA REG ASSIGN multiply_halfregs opt_mode
1900 if (!IS_DREG ($1) || !IS_DREG ($6))
1901 return yyerror ("Dregs expected");
1903 if ((IS_EVEN ($1) && $6.regno - $1.regno != 1)
1904 || (IS_EVEN ($6) && $1.regno - $6.regno != 1))
1905 return yyerror ("Dest registers mismatch");
1907 if (check_multiply_halfregs (&$3, &$8) < 0)
1908 return -1;
1910 if ((IS_EVEN ($1) && $4.MM)
1911 || (IS_EVEN ($6) && $9.MM))
1912 return yyerror ("(M) not allowed with MAC0");
1914 notethat ("dsp32mult: dregs = multiply_halfregs mxd_mod, "
1915 "dregs = multiply_halfregs opt_mode\n");
1917 if (IS_EVEN ($1))
1918 $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 1,
1919 IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
1920 &$1, 0, &$3.s0, &$3.s1, 1);
1921 else
1922 $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 1,
1923 IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
1924 &$1, 0, &$3.s0, &$3.s1, 1);
1928 /* SHIFTs. */
1929 | a_assign ASHIFT REG_A BY HALF_REG
1931 if (!REG_SAME ($1, $3))
1932 return yyerror ("Aregs must be same");
1934 if (IS_DREG ($5) && !IS_H ($5))
1936 notethat ("dsp32shift: A0 = ASHIFT A0 BY dregs_lo\n");
1937 $$ = DSP32SHIFT (3, 0, &$5, 0, 0, IS_A1 ($1));
1939 else
1940 return yyerror ("Dregs expected");
1943 | HALF_REG ASSIGN ASHIFT HALF_REG BY HALF_REG smod
1945 if (IS_DREG ($6) && !IS_H ($6))
1947 notethat ("dsp32shift: dregs_half = ASHIFT dregs_half BY dregs_lo\n");
1948 $$ = DSP32SHIFT (0, &$1, &$6, &$4, $7.s0, HL2 ($1, $4));
1950 else
1951 return yyerror ("Dregs expected");
1954 | a_assign REG_A LESS_LESS expr
1956 if (!REG_SAME ($1, $2))
1957 return yyerror ("Aregs must be same");
1959 if (IS_UIMM ($4, 5))
1961 notethat ("dsp32shiftimm: A0 = A0 << uimm5\n");
1962 $$ = DSP32SHIFTIMM (3, 0, imm5 ($4), 0, 0, IS_A1 ($1));
1964 else
1965 return yyerror ("Bad shift value");
1968 | REG ASSIGN REG LESS_LESS expr vsmod
1970 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
1972 if ($6.r0)
1974 /* Vector? */
1975 notethat ("dsp32shiftimm: dregs = dregs << expr (V, .)\n");
1976 $$ = DSP32SHIFTIMM (1, &$1, imm4 ($5), &$3, $6.s0 ? 1 : 2, 0);
1978 else
1980 notethat ("dsp32shiftimm: dregs = dregs << uimm5 (.)\n");
1981 $$ = DSP32SHIFTIMM (2, &$1, imm6 ($5), &$3, $6.s0 ? 1 : 2, 0);
1984 else if ($6.s0 == 0 && IS_PREG ($1) && IS_PREG ($3))
1986 if (EXPR_VALUE ($5) == 2)
1988 notethat ("PTR2op: pregs = pregs << 2\n");
1989 $$ = PTR2OP (&$1, &$3, 1);
1991 else if (EXPR_VALUE ($5) == 1)
1993 notethat ("COMP3op: pregs = pregs << 1\n");
1994 $$ = COMP3OP (&$1, &$3, &$3, 5);
1996 else
1997 return yyerror ("Bad shift value");
1999 else
2000 return yyerror ("Bad shift value or register");
2002 | HALF_REG ASSIGN HALF_REG LESS_LESS expr smod
2004 if (IS_UIMM ($5, 4))
2006 if ($6.s0)
2008 notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4 (S)\n");
2009 $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, $6.s0, HL2 ($1, $3));
2011 else
2013 notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4\n");
2014 $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, 2, HL2 ($1, $3));
2017 else
2018 return yyerror ("Bad shift value");
2020 | REG ASSIGN ASHIFT REG BY HALF_REG vsmod
2022 int op;
2024 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6) && !IS_H ($6))
2026 if ($7.r0)
2028 op = 1;
2029 notethat ("dsp32shift: dregs = ASHIFT dregs BY "
2030 "dregs_lo (V, .)\n");
2032 else
2035 op = 2;
2036 notethat ("dsp32shift: dregs = ASHIFT dregs BY dregs_lo (.)\n");
2038 $$ = DSP32SHIFT (op, &$1, &$6, &$4, $7.s0, 0);
2040 else
2041 return yyerror ("Dregs expected");
2044 /* EXPADJ. */
2045 | HALF_REG ASSIGN EXPADJ LPAREN REG COMMA HALF_REG RPAREN vmod
2047 if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
2049 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs , dregs_lo )\n");
2050 $$ = DSP32SHIFT (7, &$1, &$7, &$5, $9.r0, 0);
2052 else
2053 return yyerror ("Bad shift value or register");
2057 | HALF_REG ASSIGN EXPADJ LPAREN HALF_REG COMMA HALF_REG RPAREN
2059 if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
2061 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_lo, dregs_lo)\n");
2062 $$ = DSP32SHIFT (7, &$1, &$7, &$5, 2, 0);
2064 else if (IS_DREG_L ($1) && IS_DREG_H ($5) && IS_DREG_L ($7))
2066 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_hi, dregs_lo)\n");
2067 $$ = DSP32SHIFT (7, &$1, &$7, &$5, 3, 0);
2069 else
2070 return yyerror ("Bad shift value or register");
2073 /* DEPOSIT. */
2075 | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN
2077 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2079 notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs )\n");
2080 $$ = DSP32SHIFT (10, &$1, &$7, &$5, 2, 0);
2082 else
2083 return yyerror ("Register mismatch");
2086 | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN LPAREN X RPAREN
2088 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2090 notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs ) (X)\n");
2091 $$ = DSP32SHIFT (10, &$1, &$7, &$5, 3, 0);
2093 else
2094 return yyerror ("Register mismatch");
2097 | REG ASSIGN EXTRACT LPAREN REG COMMA HALF_REG RPAREN xpmod
2099 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG_L ($7))
2101 notethat ("dsp32shift: dregs = EXTRACT (dregs, dregs_lo ) (.)\n");
2102 $$ = DSP32SHIFT (10, &$1, &$7, &$5, $9.r0, 0);
2104 else
2105 return yyerror ("Register mismatch");
2108 | a_assign REG_A _GREATER_GREATER_GREATER expr
2110 if (!REG_SAME ($1, $2))
2111 return yyerror ("Aregs must be same");
2113 if (IS_UIMM ($4, 5))
2115 notethat ("dsp32shiftimm: Ax = Ax >>> uimm5\n");
2116 $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 0, IS_A1 ($1));
2118 else
2119 return yyerror ("Shift value range error");
2121 | a_assign LSHIFT REG_A BY HALF_REG
2123 if (REG_SAME ($1, $3) && IS_DREG_L ($5))
2125 notethat ("dsp32shift: Ax = LSHIFT Ax BY dregs_lo\n");
2126 $$ = DSP32SHIFT (3, 0, &$5, 0, 1, IS_A1 ($1));
2128 else
2129 return yyerror ("Register mismatch");
2132 | HALF_REG ASSIGN LSHIFT HALF_REG BY HALF_REG
2134 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2136 notethat ("dsp32shift: dregs_lo = LSHIFT dregs_hi BY dregs_lo\n");
2137 $$ = DSP32SHIFT (0, &$1, &$6, &$4, 2, HL2 ($1, $4));
2139 else
2140 return yyerror ("Register mismatch");
2143 | REG ASSIGN LSHIFT REG BY HALF_REG vmod
2145 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2147 notethat ("dsp32shift: dregs = LSHIFT dregs BY dregs_lo (V )\n");
2148 $$ = DSP32SHIFT ($7.r0 ? 1: 2, &$1, &$6, &$4, 2, 0);
2150 else
2151 return yyerror ("Register mismatch");
2154 | REG ASSIGN SHIFT REG BY HALF_REG
2156 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2158 notethat ("dsp32shift: dregs = SHIFT dregs BY dregs_lo\n");
2159 $$ = DSP32SHIFT (2, &$1, &$6, &$4, 2, 0);
2161 else
2162 return yyerror ("Register mismatch");
2165 | a_assign REG_A GREATER_GREATER expr
2167 if (REG_SAME ($1, $2) && IS_IMM ($4, 6) >= 0)
2169 notethat ("dsp32shiftimm: Ax = Ax >> imm6\n");
2170 $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 1, IS_A1 ($1));
2172 else
2173 return yyerror ("Accu register expected");
2176 | REG ASSIGN REG GREATER_GREATER expr vmod
2178 if ($6.r0 == 1)
2180 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2182 notethat ("dsp32shiftimm: dregs = dregs >> uimm5 (V)\n");
2183 $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, 2, 0);
2185 else
2186 return yyerror ("Register mismatch");
2188 else
2190 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2192 notethat ("dsp32shiftimm: dregs = dregs >> uimm5\n");
2193 $$ = DSP32SHIFTIMM (2, &$1, -imm6 ($5), &$3, 2, 0);
2195 else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 2)
2197 notethat ("PTR2op: pregs = pregs >> 2\n");
2198 $$ = PTR2OP (&$1, &$3, 3);
2200 else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 1)
2202 notethat ("PTR2op: pregs = pregs >> 1\n");
2203 $$ = PTR2OP (&$1, &$3, 4);
2205 else
2206 return yyerror ("Register mismatch");
2209 | HALF_REG ASSIGN HALF_REG GREATER_GREATER expr
2211 if (IS_UIMM ($5, 5))
2213 notethat ("dsp32shiftimm: dregs_half = dregs_half >> uimm5\n");
2214 $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3, 2, HL2 ($1, $3));
2216 else
2217 return yyerror ("Register mismatch");
2219 | HALF_REG ASSIGN HALF_REG _GREATER_GREATER_GREATER expr smod
2221 if (IS_UIMM ($5, 5))
2223 notethat ("dsp32shiftimm: dregs_half = dregs_half >>> uimm5\n");
2224 $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3,
2225 $6.s0, HL2 ($1, $3));
2227 else
2228 return yyerror ("Register or modifier mismatch");
2232 | REG ASSIGN REG _GREATER_GREATER_GREATER expr vsmod
2234 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2236 if ($6.r0)
2238 /* Vector? */
2239 notethat ("dsp32shiftimm: dregs = dregs >>> uimm5 (V, .)\n");
2240 $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, $6.s0, 0);
2242 else
2244 notethat ("dsp32shiftimm: dregs = dregs >>> uimm5 (.)\n");
2245 $$ = DSP32SHIFTIMM (2, &$1, -uimm5 ($5), &$3, $6.s0, 0);
2248 else
2249 return yyerror ("Register mismatch");
2252 | HALF_REG ASSIGN ONES REG
2254 if (IS_DREG_L ($1) && IS_DREG ($4))
2256 notethat ("dsp32shift: dregs_lo = ONES dregs\n");
2257 $$ = DSP32SHIFT (6, &$1, 0, &$4, 3, 0);
2259 else
2260 return yyerror ("Register mismatch");
2263 | REG ASSIGN PACK LPAREN HALF_REG COMMA HALF_REG RPAREN
2265 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2267 notethat ("dsp32shift: dregs = PACK (dregs_hi , dregs_hi )\n");
2268 $$ = DSP32SHIFT (4, &$1, &$7, &$5, HL2 ($5, $7), 0);
2270 else
2271 return yyerror ("Register mismatch");
2274 | HALF_REG ASSIGN CCREG ASSIGN BXORSHIFT LPAREN REG_A COMMA REG RPAREN
2276 if (IS_DREG ($1)
2277 && $7.regno == REG_A0
2278 && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
2280 notethat ("dsp32shift: dregs_lo = CC = BXORSHIFT (A0 , dregs )\n");
2281 $$ = DSP32SHIFT (11, &$1, &$9, 0, 0, 0);
2283 else
2284 return yyerror ("Register mismatch");
2287 | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG RPAREN
2289 if (IS_DREG ($1)
2290 && $7.regno == REG_A0
2291 && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
2293 notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , dregs)\n");
2294 $$ = DSP32SHIFT (11, &$1, &$9, 0, 1, 0);
2296 else
2297 return yyerror ("Register mismatch");
2300 | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
2302 if (IS_DREG ($1) && !IS_H ($1) && !REG_SAME ($7, $9))
2304 notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , A1 , CC)\n");
2305 $$ = DSP32SHIFT (12, &$1, 0, 0, 1, 0);
2307 else
2308 return yyerror ("Register mismatch");
2311 | a_assign ROT REG_A BY HALF_REG
2313 if (REG_SAME ($1, $3) && IS_DREG_L ($5))
2315 notethat ("dsp32shift: Ax = ROT Ax BY dregs_lo\n");
2316 $$ = DSP32SHIFT (3, 0, &$5, 0, 2, IS_A1 ($1));
2318 else
2319 return yyerror ("Register mismatch");
2322 | REG ASSIGN ROT REG BY HALF_REG
2324 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2326 notethat ("dsp32shift: dregs = ROT dregs BY dregs_lo\n");
2327 $$ = DSP32SHIFT (2, &$1, &$6, &$4, 3, 0);
2329 else
2330 return yyerror ("Register mismatch");
2333 | a_assign ROT REG_A BY expr
2335 if (IS_IMM ($5, 6))
2337 notethat ("dsp32shiftimm: An = ROT An BY imm6\n");
2338 $$ = DSP32SHIFTIMM (3, 0, imm6 ($5), 0, 2, IS_A1 ($1));
2340 else
2341 return yyerror ("Register mismatch");
2344 | REG ASSIGN ROT REG BY expr
2346 if (IS_DREG ($1) && IS_DREG ($4) && IS_IMM ($6, 6))
2348 $$ = DSP32SHIFTIMM (2, &$1, imm6 ($6), &$4, 3, IS_A1 ($1));
2350 else
2351 return yyerror ("Register mismatch");
2354 | HALF_REG ASSIGN SIGNBITS REG_A
2356 if (IS_DREG_L ($1))
2358 notethat ("dsp32shift: dregs_lo = SIGNBITS An\n");
2359 $$ = DSP32SHIFT (6, &$1, 0, 0, IS_A1 ($4), 0);
2361 else
2362 return yyerror ("Register mismatch");
2365 | HALF_REG ASSIGN SIGNBITS REG
2367 if (IS_DREG_L ($1) && IS_DREG ($4))
2369 notethat ("dsp32shift: dregs_lo = SIGNBITS dregs\n");
2370 $$ = DSP32SHIFT (5, &$1, 0, &$4, 0, 0);
2372 else
2373 return yyerror ("Register mismatch");
2376 | HALF_REG ASSIGN SIGNBITS HALF_REG
2378 if (IS_DREG_L ($1))
2380 notethat ("dsp32shift: dregs_lo = SIGNBITS dregs_lo\n");
2381 $$ = DSP32SHIFT (5, &$1, 0, &$4, 1 + IS_H ($4), 0);
2383 else
2384 return yyerror ("Register mismatch");
2387 /* The ASR bit is just inverted here. */
2388 | HALF_REG ASSIGN VIT_MAX LPAREN REG RPAREN asr_asl
2390 if (IS_DREG_L ($1) && IS_DREG ($5))
2392 notethat ("dsp32shift: dregs_lo = VIT_MAX (dregs) (..)\n");
2393 $$ = DSP32SHIFT (9, &$1, 0, &$5, ($7.r0 ? 0 : 1), 0);
2395 else
2396 return yyerror ("Register mismatch");
2399 | REG ASSIGN VIT_MAX LPAREN REG COMMA REG RPAREN asr_asl
2401 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2403 notethat ("dsp32shift: dregs = VIT_MAX (dregs, dregs) (ASR)\n");
2404 $$ = DSP32SHIFT (9, &$1, &$7, &$5, 2 | ($9.r0 ? 0 : 1), 0);
2406 else
2407 return yyerror ("Register mismatch");
2410 | BITMUX LPAREN REG COMMA REG COMMA REG_A RPAREN asr_asl
2412 if (REG_SAME ($3, $5))
2413 return yyerror ("Illegal source register combination");
2415 if (IS_DREG ($3) && IS_DREG ($5) && !IS_A1 ($7))
2417 notethat ("dsp32shift: BITMUX (dregs , dregs , A0) (ASR)\n");
2418 $$ = DSP32SHIFT (8, 0, &$3, &$5, $9.r0, 0);
2420 else
2421 return yyerror ("Register mismatch");
2424 | a_assign BXORSHIFT LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
2426 if (!IS_A1 ($1) && !IS_A1 ($4) && IS_A1 ($6))
2428 notethat ("dsp32shift: A0 = BXORSHIFT (A0 , A1 , CC )\n");
2429 $$ = DSP32SHIFT (12, 0, 0, 0, 0, 0);
2431 else
2432 return yyerror ("Dregs expected");
2436 /* LOGI2op: BITCLR (dregs, uimm5). */
2437 | BITCLR LPAREN REG COMMA expr RPAREN
2439 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2441 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2442 $$ = LOGI2OP ($3, uimm5 ($5), 4);
2444 else
2445 return yyerror ("Register mismatch");
2448 /* LOGI2op: BITSET (dregs, uimm5). */
2449 | BITSET LPAREN REG COMMA expr RPAREN
2451 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2453 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2454 $$ = LOGI2OP ($3, uimm5 ($5), 2);
2456 else
2457 return yyerror ("Register mismatch");
2460 /* LOGI2op: BITTGL (dregs, uimm5). */
2461 | BITTGL LPAREN REG COMMA expr RPAREN
2463 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2465 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2466 $$ = LOGI2OP ($3, uimm5 ($5), 3);
2468 else
2469 return yyerror ("Register mismatch");
2472 | CCREG _ASSIGN_BANG BITTST LPAREN REG COMMA expr RPAREN
2474 if (IS_DREG ($5) && IS_UIMM ($7, 5))
2476 notethat ("LOGI2op: CC =! BITTST (dregs , uimm5 )\n");
2477 $$ = LOGI2OP ($5, uimm5 ($7), 0);
2479 else
2480 return yyerror ("Register mismatch or value error");
2483 | CCREG ASSIGN BITTST LPAREN REG COMMA expr RPAREN
2485 if (IS_DREG ($5) && IS_UIMM ($7, 5))
2487 notethat ("LOGI2op: CC = BITTST (dregs , uimm5 )\n");
2488 $$ = LOGI2OP ($5, uimm5 ($7), 1);
2490 else
2491 return yyerror ("Register mismatch or value error");
2494 | IF BANG CCREG REG ASSIGN REG
2496 if ((IS_DREG ($4) || IS_PREG ($4))
2497 && (IS_DREG ($6) || IS_PREG ($6)))
2499 notethat ("ccMV: IF ! CC gregs = gregs\n");
2500 $$ = CCMV (&$6, &$4, 0);
2502 else
2503 return yyerror ("Register mismatch");
2506 | IF CCREG REG ASSIGN REG
2508 if ((IS_DREG ($5) || IS_PREG ($5))
2509 && (IS_DREG ($3) || IS_PREG ($3)))
2511 notethat ("ccMV: IF CC gregs = gregs\n");
2512 $$ = CCMV (&$5, &$3, 1);
2514 else
2515 return yyerror ("Register mismatch");
2518 | IF BANG CCREG JUMP expr
2520 if (IS_PCREL10 ($5))
2522 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2523 $$ = BRCC (0, 0, $5);
2525 else
2526 return yyerror ("Bad jump offset");
2529 | IF BANG CCREG JUMP expr LPAREN BP RPAREN
2531 if (IS_PCREL10 ($5))
2533 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2534 $$ = BRCC (0, 1, $5);
2536 else
2537 return yyerror ("Bad jump offset");
2540 | IF CCREG JUMP expr
2542 if (IS_PCREL10 ($4))
2544 notethat ("BRCC: IF CC JUMP pcrel11m2\n");
2545 $$ = BRCC (1, 0, $4);
2547 else
2548 return yyerror ("Bad jump offset");
2551 | IF CCREG JUMP expr LPAREN BP RPAREN
2553 if (IS_PCREL10 ($4))
2555 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2556 $$ = BRCC (1, 1, $4);
2558 else
2559 return yyerror ("Bad jump offset");
2561 | NOP
2563 notethat ("ProgCtrl: NOP\n");
2564 $$ = PROGCTRL (0, 0);
2567 | RTS
2569 notethat ("ProgCtrl: RTS\n");
2570 $$ = PROGCTRL (1, 0);
2573 | RTI
2575 notethat ("ProgCtrl: RTI\n");
2576 $$ = PROGCTRL (1, 1);
2579 | RTX
2581 notethat ("ProgCtrl: RTX\n");
2582 $$ = PROGCTRL (1, 2);
2585 | RTN
2587 notethat ("ProgCtrl: RTN\n");
2588 $$ = PROGCTRL (1, 3);
2591 | RTE
2593 notethat ("ProgCtrl: RTE\n");
2594 $$ = PROGCTRL (1, 4);
2597 | IDLE
2599 notethat ("ProgCtrl: IDLE\n");
2600 $$ = PROGCTRL (2, 0);
2603 | CSYNC
2605 notethat ("ProgCtrl: CSYNC\n");
2606 $$ = PROGCTRL (2, 3);
2609 | SSYNC
2611 notethat ("ProgCtrl: SSYNC\n");
2612 $$ = PROGCTRL (2, 4);
2615 | EMUEXCPT
2617 notethat ("ProgCtrl: EMUEXCPT\n");
2618 $$ = PROGCTRL (2, 5);
2621 | CLI REG
2623 if (IS_DREG ($2))
2625 notethat ("ProgCtrl: CLI dregs\n");
2626 $$ = PROGCTRL (3, $2.regno & CODE_MASK);
2628 else
2629 return yyerror ("Dreg expected for CLI");
2632 | STI REG
2634 if (IS_DREG ($2))
2636 notethat ("ProgCtrl: STI dregs\n");
2637 $$ = PROGCTRL (4, $2.regno & CODE_MASK);
2639 else
2640 return yyerror ("Dreg expected for STI");
2643 | JUMP LPAREN REG RPAREN
2645 if (IS_PREG ($3))
2647 notethat ("ProgCtrl: JUMP (pregs )\n");
2648 $$ = PROGCTRL (5, $3.regno & CODE_MASK);
2650 else
2651 return yyerror ("Bad register for indirect jump");
2654 | CALL LPAREN REG RPAREN
2656 if (IS_PREG ($3))
2658 notethat ("ProgCtrl: CALL (pregs )\n");
2659 $$ = PROGCTRL (6, $3.regno & CODE_MASK);
2661 else
2662 return yyerror ("Bad register for indirect call");
2665 | CALL LPAREN PC PLUS REG RPAREN
2667 if (IS_PREG ($5))
2669 notethat ("ProgCtrl: CALL (PC + pregs )\n");
2670 $$ = PROGCTRL (7, $5.regno & CODE_MASK);
2672 else
2673 return yyerror ("Bad register for indirect call");
2676 | JUMP LPAREN PC PLUS REG RPAREN
2678 if (IS_PREG ($5))
2680 notethat ("ProgCtrl: JUMP (PC + pregs )\n");
2681 $$ = PROGCTRL (8, $5.regno & CODE_MASK);
2683 else
2684 return yyerror ("Bad register for indirect jump");
2687 | RAISE expr
2689 if (IS_UIMM ($2, 4))
2691 notethat ("ProgCtrl: RAISE uimm4\n");
2692 $$ = PROGCTRL (9, uimm4 ($2));
2694 else
2695 return yyerror ("Bad value for RAISE");
2698 | EXCPT expr
2700 notethat ("ProgCtrl: EMUEXCPT\n");
2701 $$ = PROGCTRL (10, uimm4 ($2));
2704 | TESTSET LPAREN REG RPAREN
2706 if (IS_PREG ($3))
2708 if ($3.regno == REG_SP || $3.regno == REG_FP)
2709 return yyerror ("Bad register for TESTSET");
2711 notethat ("ProgCtrl: TESTSET (pregs )\n");
2712 $$ = PROGCTRL (11, $3.regno & CODE_MASK);
2714 else
2715 return yyerror ("Preg expected");
2718 | JUMP expr
2720 if (IS_PCREL12 ($2))
2722 notethat ("UJUMP: JUMP pcrel12\n");
2723 $$ = UJUMP ($2);
2725 else
2726 return yyerror ("Bad value for relative jump");
2729 | JUMP_DOT_S expr
2731 if (IS_PCREL12 ($2))
2733 notethat ("UJUMP: JUMP_DOT_S pcrel12\n");
2734 $$ = UJUMP($2);
2736 else
2737 return yyerror ("Bad value for relative jump");
2740 | JUMP_DOT_L expr
2742 if (IS_PCREL24 ($2))
2744 notethat ("CALLa: jump.l pcrel24\n");
2745 $$ = CALLA ($2, 0);
2747 else
2748 return yyerror ("Bad value for long jump");
2751 | JUMP_DOT_L pltpc
2753 if (IS_PCREL24 ($2))
2755 notethat ("CALLa: jump.l pcrel24\n");
2756 $$ = CALLA ($2, 2);
2758 else
2759 return yyerror ("Bad value for long jump");
2762 | CALL expr
2764 if (IS_PCREL24 ($2))
2766 notethat ("CALLa: CALL pcrel25m2\n");
2767 $$ = CALLA ($2, 1);
2769 else
2770 return yyerror ("Bad call address");
2772 | CALL pltpc
2774 if (IS_PCREL24 ($2))
2776 notethat ("CALLa: CALL pcrel25m2\n");
2777 $$ = CALLA ($2, 2);
2779 else
2780 return yyerror ("Bad call address");
2783 /* ALU2ops. */
2784 /* ALU2op: DIVQ (dregs, dregs). */
2785 | DIVQ LPAREN REG COMMA REG RPAREN
2787 if (IS_DREG ($3) && IS_DREG ($5))
2788 $$ = ALU2OP (&$3, &$5, 8);
2789 else
2790 return yyerror ("Bad registers for DIVQ");
2793 | DIVS LPAREN REG COMMA REG RPAREN
2795 if (IS_DREG ($3) && IS_DREG ($5))
2796 $$ = ALU2OP (&$3, &$5, 9);
2797 else
2798 return yyerror ("Bad registers for DIVS");
2801 | REG ASSIGN MINUS REG vsmod
2803 if (IS_DREG ($1) && IS_DREG ($4))
2805 if ($5.r0 == 0 && $5.s0 == 0 && $5.aop == 0)
2807 notethat ("ALU2op: dregs = - dregs\n");
2808 $$ = ALU2OP (&$1, &$4, 14);
2810 else if ($5.r0 == 1 && $5.s0 == 0 && $5.aop == 3)
2812 notethat ("dsp32alu: dregs = - dregs (.)\n");
2813 $$ = DSP32ALU (15, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
2815 else
2817 notethat ("dsp32alu: dregs = - dregs (.)\n");
2818 $$ = DSP32ALU (7, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
2821 else
2822 return yyerror ("Dregs expected");
2825 | REG ASSIGN TILDA REG
2827 if (IS_DREG ($1) && IS_DREG ($4))
2829 notethat ("ALU2op: dregs = ~dregs\n");
2830 $$ = ALU2OP (&$1, &$4, 15);
2832 else
2833 return yyerror ("Dregs expected");
2836 | REG _GREATER_GREATER_ASSIGN REG
2838 if (IS_DREG ($1) && IS_DREG ($3))
2840 notethat ("ALU2op: dregs >>= dregs\n");
2841 $$ = ALU2OP (&$1, &$3, 1);
2843 else
2844 return yyerror ("Dregs expected");
2847 | REG _GREATER_GREATER_ASSIGN expr
2849 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2851 notethat ("LOGI2op: dregs >>= uimm5\n");
2852 $$ = LOGI2OP ($1, uimm5 ($3), 6);
2854 else
2855 return yyerror ("Dregs expected or value error");
2858 | REG _GREATER_GREATER_GREATER_THAN_ASSIGN REG
2860 if (IS_DREG ($1) && IS_DREG ($3))
2862 notethat ("ALU2op: dregs >>>= dregs\n");
2863 $$ = ALU2OP (&$1, &$3, 0);
2865 else
2866 return yyerror ("Dregs expected");
2869 | REG _LESS_LESS_ASSIGN REG
2871 if (IS_DREG ($1) && IS_DREG ($3))
2873 notethat ("ALU2op: dregs <<= dregs\n");
2874 $$ = ALU2OP (&$1, &$3, 2);
2876 else
2877 return yyerror ("Dregs expected");
2880 | REG _LESS_LESS_ASSIGN expr
2882 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2884 notethat ("LOGI2op: dregs <<= uimm5\n");
2885 $$ = LOGI2OP ($1, uimm5 ($3), 7);
2887 else
2888 return yyerror ("Dregs expected or const value error");
2892 | REG _GREATER_GREATER_GREATER_THAN_ASSIGN expr
2894 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2896 notethat ("LOGI2op: dregs >>>= uimm5\n");
2897 $$ = LOGI2OP ($1, uimm5 ($3), 5);
2899 else
2900 return yyerror ("Dregs expected");
2903 /* Cache Control. */
2905 | FLUSH LBRACK REG RBRACK
2907 notethat ("CaCTRL: FLUSH [ pregs ]\n");
2908 if (IS_PREG ($3))
2909 $$ = CACTRL (&$3, 0, 2);
2910 else
2911 return yyerror ("Bad register(s) for FLUSH");
2914 | FLUSH reg_with_postinc
2916 if (IS_PREG ($2))
2918 notethat ("CaCTRL: FLUSH [ pregs ++ ]\n");
2919 $$ = CACTRL (&$2, 1, 2);
2921 else
2922 return yyerror ("Bad register(s) for FLUSH");
2925 | FLUSHINV LBRACK REG RBRACK
2927 if (IS_PREG ($3))
2929 notethat ("CaCTRL: FLUSHINV [ pregs ]\n");
2930 $$ = CACTRL (&$3, 0, 1);
2932 else
2933 return yyerror ("Bad register(s) for FLUSH");
2936 | FLUSHINV reg_with_postinc
2938 if (IS_PREG ($2))
2940 notethat ("CaCTRL: FLUSHINV [ pregs ++ ]\n");
2941 $$ = CACTRL (&$2, 1, 1);
2943 else
2944 return yyerror ("Bad register(s) for FLUSH");
2947 /* CaCTRL: IFLUSH [pregs]. */
2948 | IFLUSH LBRACK REG RBRACK
2950 if (IS_PREG ($3))
2952 notethat ("CaCTRL: IFLUSH [ pregs ]\n");
2953 $$ = CACTRL (&$3, 0, 3);
2955 else
2956 return yyerror ("Bad register(s) for FLUSH");
2959 | IFLUSH reg_with_postinc
2961 if (IS_PREG ($2))
2963 notethat ("CaCTRL: IFLUSH [ pregs ++ ]\n");
2964 $$ = CACTRL (&$2, 1, 3);
2966 else
2967 return yyerror ("Bad register(s) for FLUSH");
2970 | PREFETCH LBRACK REG RBRACK
2972 if (IS_PREG ($3))
2974 notethat ("CaCTRL: PREFETCH [ pregs ]\n");
2975 $$ = CACTRL (&$3, 0, 0);
2977 else
2978 return yyerror ("Bad register(s) for PREFETCH");
2981 | PREFETCH reg_with_postinc
2983 if (IS_PREG ($2))
2985 notethat ("CaCTRL: PREFETCH [ pregs ++ ]\n");
2986 $$ = CACTRL (&$2, 1, 0);
2988 else
2989 return yyerror ("Bad register(s) for PREFETCH");
2992 /* LOAD/STORE. */
2993 /* LDST: B [ pregs <post_op> ] = dregs. */
2995 | B LBRACK REG post_op RBRACK ASSIGN REG
2997 if (!IS_DREG ($7))
2998 return yyerror ("Dreg expected for source operand");
2999 if (!IS_PREG ($3))
3000 return yyerror ("Preg expected in address");
3002 notethat ("LDST: B [ pregs <post_op> ] = dregs\n");
3003 $$ = LDST (&$3, &$7, $4.x0, 2, 0, 1);
3006 /* LDSTidxI: B [ pregs + imm16 ] = dregs. */
3007 | B LBRACK REG plus_minus expr RBRACK ASSIGN REG
3009 Expr_Node *tmp = $5;
3011 if (!IS_DREG ($8))
3012 return yyerror ("Dreg expected for source operand");
3013 if (!IS_PREG ($3))
3014 return yyerror ("Preg expected in address");
3016 if (IS_RELOC ($5))
3017 return yyerror ("Plain symbol used as offset");
3019 if ($4.r0)
3020 tmp = unary (Expr_Op_Type_NEG, tmp);
3022 if (in_range_p (tmp, -32768, 32767, 0))
3024 notethat ("LDST: B [ pregs + imm16 ] = dregs\n");
3025 $$ = LDSTIDXI (&$3, &$8, 1, 2, 0, $5);
3027 else
3028 return yyerror ("Displacement out of range");
3032 /* LDSTii: W [ pregs + uimm4s2 ] = dregs. */
3033 | W LBRACK REG plus_minus expr RBRACK ASSIGN REG
3035 Expr_Node *tmp = $5;
3037 if (!IS_DREG ($8))
3038 return yyerror ("Dreg expected for source operand");
3039 if (!IS_PREG ($3))
3040 return yyerror ("Preg expected in address");
3042 if ($4.r0)
3043 tmp = unary (Expr_Op_Type_NEG, tmp);
3045 if (IS_RELOC ($5))
3046 return yyerror ("Plain symbol used as offset");
3048 if (in_range_p (tmp, 0, 30, 1))
3050 notethat ("LDSTii: W [ pregs +- uimm5m2 ] = dregs\n");
3051 $$ = LDSTII (&$3, &$8, tmp, 1, 1);
3053 else if (in_range_p (tmp, -65536, 65535, 1))
3055 notethat ("LDSTidxI: W [ pregs + imm17m2 ] = dregs\n");
3056 $$ = LDSTIDXI (&$3, &$8, 1, 1, 0, tmp);
3058 else
3059 return yyerror ("Displacement out of range");
3062 /* LDST: W [ pregs <post_op> ] = dregs. */
3063 | W LBRACK REG post_op RBRACK ASSIGN REG
3065 if (!IS_DREG ($7))
3066 return yyerror ("Dreg expected for source operand");
3067 if (!IS_PREG ($3))
3068 return yyerror ("Preg expected in address");
3070 notethat ("LDST: W [ pregs <post_op> ] = dregs\n");
3071 $$ = LDST (&$3, &$7, $4.x0, 1, 0, 1);
3074 | W LBRACK REG post_op RBRACK ASSIGN HALF_REG
3076 if (!IS_DREG ($7))
3077 return yyerror ("Dreg expected for source operand");
3078 if ($4.x0 == 2)
3080 if (!IS_IREG ($3) && !IS_PREG ($3))
3081 return yyerror ("Ireg or Preg expected in address");
3083 else if (!IS_IREG ($3))
3084 return yyerror ("Ireg expected in address");
3086 if (IS_IREG ($3))
3088 notethat ("dspLDST: W [ iregs <post_op> ] = dregs_half\n");
3089 $$ = DSPLDST (&$3, 1 + IS_H ($7), &$7, $4.x0, 1);
3091 else
3093 notethat ("LDSTpmod: W [ pregs ] = dregs_half\n");
3094 $$ = LDSTPMOD (&$3, &$7, &$3, 1 + IS_H ($7), 1);
3098 /* LDSTiiFP: [ FP - const ] = dpregs. */
3099 | LBRACK REG plus_minus expr RBRACK ASSIGN REG
3101 Expr_Node *tmp = $4;
3102 int ispreg = IS_PREG ($7);
3104 if (!IS_PREG ($2))
3105 return yyerror ("Preg expected in address");
3107 if (!IS_DREG ($7) && !ispreg)
3108 return yyerror ("Preg expected for source operand");
3110 if ($3.r0)
3111 tmp = unary (Expr_Op_Type_NEG, tmp);
3113 if (IS_RELOC ($4))
3114 return yyerror ("Plain symbol used as offset");
3116 if (in_range_p (tmp, 0, 63, 3))
3118 notethat ("LDSTii: dpregs = [ pregs + uimm6m4 ]\n");
3119 $$ = LDSTII (&$2, &$7, tmp, 1, ispreg ? 3 : 0);
3121 else if ($2.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
3123 notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
3124 tmp = unary (Expr_Op_Type_NEG, tmp);
3125 $$ = LDSTIIFP (tmp, &$7, 1);
3127 else if (in_range_p (tmp, -131072, 131071, 3))
3129 notethat ("LDSTidxI: [ pregs + imm18m4 ] = dpregs\n");
3130 $$ = LDSTIDXI (&$2, &$7, 1, 0, ispreg ? 1 : 0, tmp);
3132 else
3133 return yyerror ("Displacement out of range");
3136 | REG ASSIGN W LBRACK REG plus_minus expr RBRACK xpmod
3138 Expr_Node *tmp = $7;
3139 if (!IS_DREG ($1))
3140 return yyerror ("Dreg expected for destination operand");
3141 if (!IS_PREG ($5))
3142 return yyerror ("Preg expected in address");
3144 if ($6.r0)
3145 tmp = unary (Expr_Op_Type_NEG, tmp);
3147 if (IS_RELOC ($7))
3148 return yyerror ("Plain symbol used as offset");
3150 if (in_range_p (tmp, 0, 30, 1))
3152 notethat ("LDSTii: dregs = W [ pregs + uimm5m2 ] (.)\n");
3153 $$ = LDSTII (&$5, &$1, tmp, 0, 1 << $9.r0);
3155 else if (in_range_p (tmp, -65536, 65535, 1))
3157 notethat ("LDSTidxI: dregs = W [ pregs + imm17m2 ] (.)\n");
3158 $$ = LDSTIDXI (&$5, &$1, 0, 1, $9.r0, tmp);
3160 else
3161 return yyerror ("Displacement out of range");
3164 | HALF_REG ASSIGN W LBRACK REG post_op RBRACK
3166 if (!IS_DREG ($1))
3167 return yyerror ("Dreg expected for source operand");
3168 if ($6.x0 == 2)
3170 if (!IS_IREG ($5) && !IS_PREG ($5))
3171 return yyerror ("Ireg or Preg expected in address");
3173 else if (!IS_IREG ($5))
3174 return yyerror ("Ireg expected in address");
3176 if (IS_IREG ($5))
3178 notethat ("dspLDST: dregs_half = W [ iregs <post_op> ]\n");
3179 $$ = DSPLDST(&$5, 1 + IS_H ($1), &$1, $6.x0, 0);
3181 else
3183 notethat ("LDSTpmod: dregs_half = W [ pregs <post_op> ]\n");
3184 $$ = LDSTPMOD (&$5, &$1, &$5, 1 + IS_H ($1), 0);
3189 | REG ASSIGN W LBRACK REG post_op RBRACK xpmod
3191 if (!IS_DREG ($1))
3192 return yyerror ("Dreg expected for destination operand");
3193 if (!IS_PREG ($5))
3194 return yyerror ("Preg expected in address");
3196 notethat ("LDST: dregs = W [ pregs <post_op> ] (.)\n");
3197 $$ = LDST (&$5, &$1, $6.x0, 1, $8.r0, 0);
3200 | REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK xpmod
3202 if (!IS_DREG ($1))
3203 return yyerror ("Dreg expected for destination operand");
3204 if (!IS_PREG ($5) || !IS_PREG ($7))
3205 return yyerror ("Preg expected in address");
3207 notethat ("LDSTpmod: dregs = W [ pregs ++ pregs ] (.)\n");
3208 $$ = LDSTPMOD (&$5, &$1, &$7, 3, $9.r0);
3211 | HALF_REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK
3213 if (!IS_DREG ($1))
3214 return yyerror ("Dreg expected for destination operand");
3215 if (!IS_PREG ($5) || !IS_PREG ($7))
3216 return yyerror ("Preg expected in address");
3218 notethat ("LDSTpmod: dregs_half = W [ pregs ++ pregs ]\n");
3219 $$ = LDSTPMOD (&$5, &$1, &$7, 1 + IS_H ($1), 0);
3222 | LBRACK REG post_op RBRACK ASSIGN REG
3224 if (!IS_IREG ($2) && !IS_PREG ($2))
3225 return yyerror ("Ireg or Preg expected in address");
3226 else if (IS_IREG ($2) && !IS_DREG ($6))
3227 return yyerror ("Dreg expected for source operand");
3228 else if (IS_PREG ($2) && !IS_DREG ($6) && !IS_PREG ($6))
3229 return yyerror ("Dreg or Preg expected for source operand");
3231 if (IS_IREG ($2))
3233 notethat ("dspLDST: [ iregs <post_op> ] = dregs\n");
3234 $$ = DSPLDST(&$2, 0, &$6, $3.x0, 1);
3236 else if (IS_DREG ($6))
3238 notethat ("LDST: [ pregs <post_op> ] = dregs\n");
3239 $$ = LDST (&$2, &$6, $3.x0, 0, 0, 1);
3241 else
3243 notethat ("LDST: [ pregs <post_op> ] = pregs\n");
3244 $$ = LDST (&$2, &$6, $3.x0, 0, 1, 1);
3248 | LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN REG
3250 if (!IS_DREG ($7))
3251 return yyerror ("Dreg expected for source operand");
3253 if (IS_IREG ($2) && IS_MREG ($4))
3255 notethat ("dspLDST: [ iregs ++ mregs ] = dregs\n");
3256 $$ = DSPLDST(&$2, $4.regno & CODE_MASK, &$7, 3, 1);
3258 else if (IS_PREG ($2) && IS_PREG ($4))
3260 notethat ("LDSTpmod: [ pregs ++ pregs ] = dregs\n");
3261 $$ = LDSTPMOD (&$2, &$7, &$4, 0, 1);
3263 else
3264 return yyerror ("Preg ++ Preg or Ireg ++ Mreg expected in address");
3267 | W LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN HALF_REG
3269 if (!IS_DREG ($8))
3270 return yyerror ("Dreg expected for source operand");
3272 if (IS_PREG ($3) && IS_PREG ($5))
3274 notethat ("LDSTpmod: W [ pregs ++ pregs ] = dregs_half\n");
3275 $$ = LDSTPMOD (&$3, &$8, &$5, 1 + IS_H ($8), 1);
3277 else
3278 return yyerror ("Preg ++ Preg expected in address");
3281 | REG ASSIGN B LBRACK REG plus_minus expr RBRACK xpmod
3283 Expr_Node *tmp = $7;
3284 if (!IS_DREG ($1))
3285 return yyerror ("Dreg expected for destination operand");
3286 if (!IS_PREG ($5))
3287 return yyerror ("Preg expected in address");
3289 if ($6.r0)
3290 tmp = unary (Expr_Op_Type_NEG, tmp);
3292 if (IS_RELOC ($7))
3293 return yyerror ("Plain symbol used as offset");
3295 if (in_range_p (tmp, -32768, 32767, 0))
3297 notethat ("LDSTidxI: dregs = B [ pregs + imm16 ] (%c)\n",
3298 $9.r0 ? 'X' : 'Z');
3299 $$ = LDSTIDXI (&$5, &$1, 0, 2, $9.r0, tmp);
3301 else
3302 return yyerror ("Displacement out of range");
3305 | REG ASSIGN B LBRACK REG post_op RBRACK xpmod
3307 if (!IS_DREG ($1))
3308 return yyerror ("Dreg expected for destination operand");
3309 if (!IS_PREG ($5))
3310 return yyerror ("Preg expected in address");
3312 notethat ("LDST: dregs = B [ pregs <post_op> ] (%c)\n",
3313 $8.r0 ? 'X' : 'Z');
3314 $$ = LDST (&$5, &$1, $6.x0, 2, $8.r0, 0);
3317 | REG ASSIGN LBRACK REG _PLUS_PLUS REG RBRACK
3319 if (!IS_DREG ($1))
3320 return yyerror ("Dreg expected for destination operand");
3322 if (IS_IREG ($4) && IS_MREG ($6))
3324 notethat ("dspLDST: dregs = [ iregs ++ mregs ]\n");
3325 $$ = DSPLDST(&$4, $6.regno & CODE_MASK, &$1, 3, 0);
3327 else if (IS_PREG ($4) && IS_PREG ($6))
3329 notethat ("LDSTpmod: dregs = [ pregs ++ pregs ]\n");
3330 $$ = LDSTPMOD (&$4, &$1, &$6, 0, 0);
3332 else
3333 return yyerror ("Preg ++ Preg or Ireg ++ Mreg expected in address");
3336 | REG ASSIGN LBRACK REG plus_minus got_or_expr RBRACK
3338 Expr_Node *tmp = $6;
3339 int ispreg = IS_PREG ($1);
3340 int isgot = IS_RELOC($6);
3342 if (!IS_PREG ($4))
3343 return yyerror ("Preg expected in address");
3345 if (!IS_DREG ($1) && !ispreg)
3346 return yyerror ("Dreg or Preg expected for destination operand");
3348 if (tmp->type == Expr_Node_Reloc
3349 && strcmp (tmp->value.s_value,
3350 "_current_shared_library_p5_offset_") != 0)
3351 return yyerror ("Plain symbol used as offset");
3353 if ($5.r0)
3354 tmp = unary (Expr_Op_Type_NEG, tmp);
3356 if (isgot)
3358 notethat ("LDSTidxI: dpregs = [ pregs + sym@got ]\n");
3359 $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1 : 0, tmp);
3361 else if (in_range_p (tmp, 0, 63, 3))
3363 notethat ("LDSTii: dpregs = [ pregs + uimm7m4 ]\n");
3364 $$ = LDSTII (&$4, &$1, tmp, 0, ispreg ? 3 : 0);
3366 else if ($4.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
3368 notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
3369 tmp = unary (Expr_Op_Type_NEG, tmp);
3370 $$ = LDSTIIFP (tmp, &$1, 0);
3372 else if (in_range_p (tmp, -131072, 131071, 3))
3374 notethat ("LDSTidxI: dpregs = [ pregs + imm18m4 ]\n");
3375 $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1 : 0, tmp);
3378 else
3379 return yyerror ("Displacement out of range");
3382 | REG ASSIGN LBRACK REG post_op RBRACK
3384 if (!IS_IREG ($4) && !IS_PREG ($4))
3385 return yyerror ("Ireg or Preg expected in address");
3386 else if (IS_IREG ($4) && !IS_DREG ($1))
3387 return yyerror ("Dreg expected in destination operand");
3388 else if (IS_PREG ($4) && !IS_DREG ($1) && !IS_PREG ($1)
3389 && ($4.regno != REG_SP || !IS_ALLREG ($1) || $5.x0 != 0))
3390 return yyerror ("Dreg or Preg expected in destination operand");
3392 if (IS_IREG ($4))
3394 notethat ("dspLDST: dregs = [ iregs <post_op> ]\n");
3395 $$ = DSPLDST (&$4, 0, &$1, $5.x0, 0);
3397 else if (IS_DREG ($1))
3399 notethat ("LDST: dregs = [ pregs <post_op> ]\n");
3400 $$ = LDST (&$4, &$1, $5.x0, 0, 0, 0);
3402 else if (IS_PREG ($1))
3404 if (REG_SAME ($1, $4) && $5.x0 != 2)
3405 return yyerror ("Pregs can't be same");
3407 notethat ("LDST: pregs = [ pregs <post_op> ]\n");
3408 $$ = LDST (&$4, &$1, $5.x0, 0, 1, 0);
3410 else
3412 notethat ("PushPopReg: allregs = [ SP ++ ]\n");
3413 $$ = PUSHPOPREG (&$1, 0);
3418 /* PushPopMultiple. */
3419 | reg_with_predec ASSIGN LPAREN REG COLON expr COMMA REG COLON expr RPAREN
3421 if ($1.regno != REG_SP)
3422 yyerror ("Stack Pointer expected");
3423 if ($4.regno == REG_R7
3424 && IN_RANGE ($6, 0, 7)
3425 && $8.regno == REG_P5
3426 && IN_RANGE ($10, 0, 5))
3428 notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim , P5 : reglim )\n");
3429 $$ = PUSHPOPMULTIPLE (imm5 ($6), imm5 ($10), 1, 1, 1);
3431 else
3432 return yyerror ("Bad register for PushPopMultiple");
3435 | reg_with_predec ASSIGN LPAREN REG COLON expr RPAREN
3437 if ($1.regno != REG_SP)
3438 yyerror ("Stack Pointer expected");
3440 if ($4.regno == REG_R7 && IN_RANGE ($6, 0, 7))
3442 notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim )\n");
3443 $$ = PUSHPOPMULTIPLE (imm5 ($6), 0, 1, 0, 1);
3445 else if ($4.regno == REG_P5 && IN_RANGE ($6, 0, 6))
3447 notethat ("PushPopMultiple: [ -- SP ] = (P5 : reglim )\n");
3448 $$ = PUSHPOPMULTIPLE (0, imm5 ($6), 0, 1, 1);
3450 else
3451 return yyerror ("Bad register for PushPopMultiple");
3454 | LPAREN REG COLON expr COMMA REG COLON expr RPAREN ASSIGN reg_with_postinc
3456 if ($11.regno != REG_SP)
3457 yyerror ("Stack Pointer expected");
3458 if ($2.regno == REG_R7 && (IN_RANGE ($4, 0, 7))
3459 && $6.regno == REG_P5 && (IN_RANGE ($8, 0, 6)))
3461 notethat ("PushPopMultiple: (R7 : reglim , P5 : reglim ) = [ SP ++ ]\n");
3462 $$ = PUSHPOPMULTIPLE (imm5 ($4), imm5 ($8), 1, 1, 0);
3464 else
3465 return yyerror ("Bad register range for PushPopMultiple");
3468 | LPAREN REG COLON expr RPAREN ASSIGN reg_with_postinc
3470 if ($7.regno != REG_SP)
3471 yyerror ("Stack Pointer expected");
3473 if ($2.regno == REG_R7 && IN_RANGE ($4, 0, 7))
3475 notethat ("PushPopMultiple: (R7 : reglim ) = [ SP ++ ]\n");
3476 $$ = PUSHPOPMULTIPLE (imm5 ($4), 0, 1, 0, 0);
3478 else if ($2.regno == REG_P5 && IN_RANGE ($4, 0, 6))
3480 notethat ("PushPopMultiple: (P5 : reglim ) = [ SP ++ ]\n");
3481 $$ = PUSHPOPMULTIPLE (0, imm5 ($4), 0, 1, 0);
3483 else
3484 return yyerror ("Bad register range for PushPopMultiple");
3487 | reg_with_predec ASSIGN REG
3489 if ($1.regno != REG_SP)
3490 yyerror ("Stack Pointer expected");
3492 if (IS_ALLREG ($3))
3494 notethat ("PushPopReg: [ -- SP ] = allregs\n");
3495 $$ = PUSHPOPREG (&$3, 1);
3497 else
3498 return yyerror ("Bad register for PushPopReg");
3501 /* Linkage. */
3503 | LINK expr
3505 if (IS_URANGE (16, $2, 0, 4))
3506 $$ = LINKAGE (0, uimm16s4 ($2));
3507 else
3508 return yyerror ("Bad constant for LINK");
3511 | UNLINK
3513 notethat ("linkage: UNLINK\n");
3514 $$ = LINKAGE (1, 0);
3518 /* LSETUP. */
3520 | LSETUP LPAREN expr COMMA expr RPAREN REG
3522 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5) && IS_CREG ($7))
3524 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters\n");
3525 $$ = LOOPSETUP ($3, &$7, 0, $5, 0);
3527 else
3528 return yyerror ("Bad register or values for LSETUP");
3531 | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG
3533 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
3534 && IS_PREG ($9) && IS_CREG ($7))
3536 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs\n");
3537 $$ = LOOPSETUP ($3, &$7, 1, $5, &$9);
3539 else
3540 return yyerror ("Bad register or values for LSETUP");
3543 | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG GREATER_GREATER expr
3545 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
3546 && IS_PREG ($9) && IS_CREG ($7)
3547 && EXPR_VALUE ($11) == 1)
3549 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs >> 1\n");
3550 $$ = LOOPSETUP ($3, &$7, 3, $5, &$9);
3552 else
3553 return yyerror ("Bad register or values for LSETUP");
3556 /* LOOP. */
3557 | LOOP expr REG
3559 if (!IS_RELOC ($2))
3560 return yyerror ("Invalid expression in loop statement");
3561 if (!IS_CREG ($3))
3562 return yyerror ("Invalid loop counter register");
3563 $$ = bfin_gen_loop ($2, &$3, 0, 0);
3565 | LOOP expr REG ASSIGN REG
3567 if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3))
3569 notethat ("Loop: LOOP expr counters = pregs\n");
3570 $$ = bfin_gen_loop ($2, &$3, 1, &$5);
3572 else
3573 return yyerror ("Bad register or values for LOOP");
3575 | LOOP expr REG ASSIGN REG GREATER_GREATER expr
3577 if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3) && EXPR_VALUE ($7) == 1)
3579 notethat ("Loop: LOOP expr counters = pregs >> 1\n");
3580 $$ = bfin_gen_loop ($2, &$3, 3, &$5);
3582 else
3583 return yyerror ("Bad register or values for LOOP");
3586 /* LOOP_BEGIN. */
3587 | LOOP_BEGIN NUMBER
3589 Expr_Node_Value val;
3590 val.i_value = $2;
3591 Expr_Node *tmp = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
3592 bfin_loop_attempt_create_label (tmp, 1);
3593 if (!IS_RELOC (tmp))
3594 return yyerror ("Invalid expression in LOOP_BEGIN statement");
3595 bfin_loop_beginend (tmp, 1);
3596 $$ = 0;
3598 | LOOP_BEGIN expr
3600 if (!IS_RELOC ($2))
3601 return yyerror ("Invalid expression in LOOP_BEGIN statement");
3603 bfin_loop_beginend ($2, 1);
3604 $$ = 0;
3607 /* LOOP_END. */
3608 | LOOP_END NUMBER
3610 Expr_Node_Value val;
3611 val.i_value = $2;
3612 Expr_Node *tmp = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
3613 bfin_loop_attempt_create_label (tmp, 1);
3614 if (!IS_RELOC (tmp))
3615 return yyerror ("Invalid expression in LOOP_END statement");
3616 bfin_loop_beginend (tmp, 0);
3617 $$ = 0;
3619 | LOOP_END expr
3621 if (!IS_RELOC ($2))
3622 return yyerror ("Invalid expression in LOOP_END statement");
3624 bfin_loop_beginend ($2, 0);
3625 $$ = 0;
3628 /* pseudoDEBUG. */
3630 | ABORT
3632 notethat ("psedoDEBUG: ABORT\n");
3633 $$ = bfin_gen_pseudodbg (3, 3, 0);
3636 | DBG
3638 notethat ("pseudoDEBUG: DBG\n");
3639 $$ = bfin_gen_pseudodbg (3, 7, 0);
3641 | DBG REG_A
3643 notethat ("pseudoDEBUG: DBG REG_A\n");
3644 $$ = bfin_gen_pseudodbg (3, IS_A1 ($2), 0);
3646 | DBG REG
3648 notethat ("pseudoDEBUG: DBG allregs\n");
3649 $$ = bfin_gen_pseudodbg (0, $2.regno & CODE_MASK, ($2.regno & CLASS_MASK) >> 4);
3652 | DBGCMPLX LPAREN REG RPAREN
3654 if (!IS_DREG ($3))
3655 return yyerror ("Dregs expected");
3656 notethat ("pseudoDEBUG: DBGCMPLX (dregs )\n");
3657 $$ = bfin_gen_pseudodbg (3, 6, ($3.regno & CODE_MASK) >> 4);
3660 | DBGHALT
3662 notethat ("psedoDEBUG: DBGHALT\n");
3663 $$ = bfin_gen_pseudodbg (3, 5, 0);
3666 | HLT
3668 notethat ("psedoDEBUG: HLT\n");
3669 $$ = bfin_gen_pseudodbg (3, 4, 0);
3672 | DBGA LPAREN HALF_REG COMMA expr RPAREN
3674 notethat ("pseudodbg_assert: DBGA (regs_lo/hi , uimm16 )\n");
3675 $$ = bfin_gen_pseudodbg_assert (IS_H ($3), &$3, uimm16 ($5));
3678 | DBGAH LPAREN REG COMMA expr RPAREN
3680 notethat ("pseudodbg_assert: DBGAH (regs , uimm16 )\n");
3681 $$ = bfin_gen_pseudodbg_assert (3, &$3, uimm16 ($5));
3684 | DBGAL LPAREN REG COMMA expr RPAREN
3686 notethat ("psedodbg_assert: DBGAL (regs , uimm16 )\n");
3687 $$ = bfin_gen_pseudodbg_assert (2, &$3, uimm16 ($5));
3690 | OUTC expr
3692 if (!IS_UIMM ($2, 8))
3693 return yyerror ("Constant out of range");
3694 notethat ("psedodbg_assert: OUTC uimm8\n");
3695 $$ = bfin_gen_pseudochr (uimm8 ($2));
3698 | OUTC REG
3700 if (!IS_DREG ($2))
3701 return yyerror ("Dregs expected");
3702 notethat ("psedodbg_assert: OUTC dreg\n");
3703 $$ = bfin_gen_pseudodbg (2, $2.regno & CODE_MASK, 0);
3708 /* AUX RULES. */
3710 /* Register rules. */
3712 REG_A: REG_A_DOUBLE_ZERO
3714 $$ = $1;
3716 | REG_A_DOUBLE_ONE
3718 $$ = $1;
3723 /* Modifiers. */
3725 opt_mode:
3727 $$.MM = 0;
3728 $$.mod = 0;
3730 | LPAREN M COMMA MMOD RPAREN
3732 $$.MM = 1;
3733 $$.mod = $4;
3735 | LPAREN MMOD COMMA M RPAREN
3737 $$.MM = 1;
3738 $$.mod = $2;
3740 | LPAREN MMOD RPAREN
3742 $$.MM = 0;
3743 $$.mod = $2;
3745 | LPAREN M RPAREN
3747 $$.MM = 1;
3748 $$.mod = 0;
3752 asr_asl: LPAREN ASL RPAREN
3754 $$.r0 = 1;
3756 | LPAREN ASR RPAREN
3758 $$.r0 = 0;
3762 sco:
3764 $$.s0 = 0;
3765 $$.x0 = 0;
3769 $$.s0 = 1;
3770 $$.x0 = 0;
3772 | CO
3774 $$.s0 = 0;
3775 $$.x0 = 1;
3777 | SCO
3779 $$.s0 = 1;
3780 $$.x0 = 1;
3784 asr_asl_0:
3787 $$.r0 = 1;
3789 | ASR
3791 $$.r0 = 0;
3795 amod0:
3797 $$.s0 = 0;
3798 $$.x0 = 0;
3800 | LPAREN sco RPAREN
3802 $$.s0 = $2.s0;
3803 $$.x0 = $2.x0;
3807 amod1:
3809 $$.s0 = 0;
3810 $$.x0 = 0;
3811 $$.aop = 0;
3813 | LPAREN NS RPAREN
3815 $$.s0 = 0;
3816 $$.x0 = 0;
3817 $$.aop = 1;
3819 | LPAREN S RPAREN
3821 $$.s0 = 1;
3822 $$.x0 = 0;
3823 $$.aop = 1;
3827 amod2:
3829 $$.r0 = 0;
3830 $$.s0 = 0;
3831 $$.x0 = 0;
3833 | LPAREN asr_asl_0 RPAREN
3835 $$.r0 = 2 + $2.r0;
3836 $$.s0 = 0;
3837 $$.x0 = 0;
3839 | LPAREN sco RPAREN
3841 $$.r0 = 0;
3842 $$.s0 = $2.s0;
3843 $$.x0 = $2.x0;
3845 | LPAREN asr_asl_0 COMMA sco RPAREN
3847 $$.r0 = 2 + $2.r0;
3848 $$.s0 = $4.s0;
3849 $$.x0 = $4.x0;
3851 | LPAREN sco COMMA asr_asl_0 RPAREN
3853 $$.r0 = 2 + $4.r0;
3854 $$.s0 = $2.s0;
3855 $$.x0 = $2.x0;
3859 xpmod:
3861 $$.r0 = 0;
3863 | LPAREN Z RPAREN
3865 $$.r0 = 0;
3867 | LPAREN X RPAREN
3869 $$.r0 = 1;
3873 xpmod1:
3875 $$.r0 = 0;
3877 | LPAREN X RPAREN
3879 $$.r0 = 0;
3881 | LPAREN Z RPAREN
3883 $$.r0 = 1;
3887 vsmod:
3889 $$.r0 = 0;
3890 $$.s0 = 0;
3891 $$.aop = 0;
3893 | LPAREN NS RPAREN
3895 $$.r0 = 0;
3896 $$.s0 = 0;
3897 $$.aop = 3;
3899 | LPAREN S RPAREN
3901 $$.r0 = 0;
3902 $$.s0 = 1;
3903 $$.aop = 3;
3905 | LPAREN V RPAREN
3907 $$.r0 = 1;
3908 $$.s0 = 0;
3909 $$.aop = 3;
3911 | LPAREN V COMMA S RPAREN
3913 $$.r0 = 1;
3914 $$.s0 = 1;
3916 | LPAREN S COMMA V RPAREN
3918 $$.r0 = 1;
3919 $$.s0 = 1;
3923 vmod:
3925 $$.r0 = 0;
3927 | LPAREN V RPAREN
3929 $$.r0 = 1;
3933 smod:
3935 $$.s0 = 0;
3937 | LPAREN S RPAREN
3939 $$.s0 = 1;
3943 searchmod:
3946 $$.r0 = 1;
3948 | GT
3950 $$.r0 = 0;
3952 | LE
3954 $$.r0 = 3;
3956 | LT
3958 $$.r0 = 2;
3962 aligndir:
3964 $$.r0 = 0;
3966 | LPAREN R RPAREN
3968 $$.r0 = 1;
3972 byteop_mod:
3973 LPAREN R RPAREN
3975 $$.r0 = 0;
3976 $$.s0 = 1;
3978 | LPAREN MMOD RPAREN
3980 if ($2 != M_T)
3981 return yyerror ("Bad modifier");
3982 $$.r0 = 1;
3983 $$.s0 = 0;
3985 | LPAREN MMOD COMMA R RPAREN
3987 if ($2 != M_T)
3988 return yyerror ("Bad modifier");
3989 $$.r0 = 1;
3990 $$.s0 = 1;
3992 | LPAREN R COMMA MMOD RPAREN
3994 if ($4 != M_T)
3995 return yyerror ("Bad modifier");
3996 $$.r0 = 1;
3997 $$.s0 = 1;
4003 c_align:
4004 ALIGN8
4006 $$.r0 = 0;
4008 | ALIGN16
4010 $$.r0 = 1;
4012 | ALIGN24
4014 $$.r0 = 2;
4018 w32_or_nothing:
4020 $$.r0 = 0;
4022 | LPAREN MMOD RPAREN
4024 if ($2 == M_W32)
4025 $$.r0 = 1;
4026 else
4027 return yyerror ("Only (W32) allowed");
4031 iu_or_nothing:
4033 $$.r0 = 1;
4035 | LPAREN MMOD RPAREN
4037 if ($2 == M_IU)
4038 $$.r0 = 3;
4039 else
4040 return yyerror ("(IU) expected");
4044 reg_with_predec: LBRACK _MINUS_MINUS REG RBRACK
4046 $$ = $3;
4050 reg_with_postinc: LBRACK REG _PLUS_PLUS RBRACK
4052 $$ = $2;
4056 /* Operators. */
4058 min_max:
4061 $$.r0 = 1;
4063 | MAX
4065 $$.r0 = 0;
4069 op_bar_op:
4070 _PLUS_BAR_PLUS
4072 $$.r0 = 0;
4074 | _PLUS_BAR_MINUS
4076 $$.r0 = 1;
4078 | _MINUS_BAR_PLUS
4080 $$.r0 = 2;
4082 | _MINUS_BAR_MINUS
4084 $$.r0 = 3;
4088 plus_minus:
4089 PLUS
4091 $$.r0 = 0;
4093 | MINUS
4095 $$.r0 = 1;
4099 rnd_op:
4100 LPAREN RNDH RPAREN
4102 $$.r0 = 1; /* HL. */
4103 $$.s0 = 0; /* s. */
4104 $$.x0 = 0; /* x. */
4105 $$.aop = 0; /* aop. */
4108 | LPAREN TH RPAREN
4110 $$.r0 = 1; /* HL. */
4111 $$.s0 = 0; /* s. */
4112 $$.x0 = 0; /* x. */
4113 $$.aop = 1; /* aop. */
4116 | LPAREN RNDL RPAREN
4118 $$.r0 = 0; /* HL. */
4119 $$.s0 = 0; /* s. */
4120 $$.x0 = 0; /* x. */
4121 $$.aop = 0; /* aop. */
4124 | LPAREN TL RPAREN
4126 $$.r0 = 0; /* HL. */
4127 $$.s0 = 0; /* s. */
4128 $$.x0 = 0; /* x. */
4129 $$.aop = 1;
4132 | LPAREN RNDH COMMA R RPAREN
4134 $$.r0 = 1; /* HL. */
4135 $$.s0 = 1; /* s. */
4136 $$.x0 = 0; /* x. */
4137 $$.aop = 0; /* aop. */
4139 | LPAREN TH COMMA R RPAREN
4141 $$.r0 = 1; /* HL. */
4142 $$.s0 = 1; /* s. */
4143 $$.x0 = 0; /* x. */
4144 $$.aop = 1; /* aop. */
4146 | LPAREN RNDL COMMA R RPAREN
4148 $$.r0 = 0; /* HL. */
4149 $$.s0 = 1; /* s. */
4150 $$.x0 = 0; /* x. */
4151 $$.aop = 0; /* aop. */
4154 | LPAREN TL COMMA R RPAREN
4156 $$.r0 = 0; /* HL. */
4157 $$.s0 = 1; /* s. */
4158 $$.x0 = 0; /* x. */
4159 $$.aop = 1; /* aop. */
4163 b3_op:
4164 LPAREN LO RPAREN
4166 $$.s0 = 0; /* s. */
4167 $$.x0 = 0; /* HL. */
4169 | LPAREN HI RPAREN
4171 $$.s0 = 0; /* s. */
4172 $$.x0 = 1; /* HL. */
4174 | LPAREN LO COMMA R RPAREN
4176 $$.s0 = 1; /* s. */
4177 $$.x0 = 0; /* HL. */
4179 | LPAREN HI COMMA R RPAREN
4181 $$.s0 = 1; /* s. */
4182 $$.x0 = 1; /* HL. */
4186 post_op:
4188 $$.x0 = 2;
4190 | _PLUS_PLUS
4192 $$.x0 = 0;
4194 | _MINUS_MINUS
4196 $$.x0 = 1;
4200 /* Assignments, Macfuncs. */
4202 a_assign:
4203 REG_A ASSIGN
4205 $$ = $1;
4209 a_minusassign:
4210 REG_A _MINUS_ASSIGN
4212 $$ = $1;
4216 a_plusassign:
4217 REG_A _PLUS_ASSIGN
4219 $$ = $1;
4223 assign_macfunc:
4224 REG ASSIGN REG_A
4226 if (IS_A1 ($3) && IS_EVEN ($1))
4227 return yyerror ("Cannot move A1 to even register");
4228 else if (!IS_A1 ($3) && !IS_EVEN ($1))
4229 return yyerror ("Cannot move A0 to odd register");
4231 $$.w = 1;
4232 $$.P = 1;
4233 $$.n = IS_A1 ($3);
4234 $$.op = 3;
4235 $$.dst = $1;
4236 $$.s0.regno = 0;
4237 $$.s1.regno = 0;
4239 | a_macfunc
4241 $$ = $1;
4242 $$.w = 0; $$.P = 0;
4243 $$.dst.regno = 0;
4245 | REG ASSIGN LPAREN a_macfunc RPAREN
4247 if ($4.n && IS_EVEN ($1))
4248 return yyerror ("Cannot move A1 to even register");
4249 else if (!$4.n && !IS_EVEN ($1))
4250 return yyerror ("Cannot move A0 to odd register");
4252 $$ = $4;
4253 $$.w = 1;
4254 $$.P = 1;
4255 $$.dst = $1;
4258 | HALF_REG ASSIGN LPAREN a_macfunc RPAREN
4260 if ($4.n && !IS_H ($1))
4261 return yyerror ("Cannot move A1 to low half of register");
4262 else if (!$4.n && IS_H ($1))
4263 return yyerror ("Cannot move A0 to high half of register");
4265 $$ = $4;
4266 $$.w = 1;
4267 $$.P = 0;
4268 $$.dst = $1;
4271 | HALF_REG ASSIGN REG_A
4273 if (IS_A1 ($3) && !IS_H ($1))
4274 return yyerror ("Cannot move A1 to low half of register");
4275 else if (!IS_A1 ($3) && IS_H ($1))
4276 return yyerror ("Cannot move A0 to high half of register");
4278 $$.w = 1;
4279 $$.P = 0;
4280 $$.n = IS_A1 ($3);
4281 $$.op = 3;
4282 $$.dst = $1;
4283 $$.s0.regno = 0;
4284 $$.s1.regno = 0;
4288 a_macfunc:
4289 a_assign multiply_halfregs
4291 $$.n = IS_A1 ($1);
4292 $$.op = 0;
4293 $$.s0 = $2.s0;
4294 $$.s1 = $2.s1;
4296 | a_plusassign multiply_halfregs
4298 $$.n = IS_A1 ($1);
4299 $$.op = 1;
4300 $$.s0 = $2.s0;
4301 $$.s1 = $2.s1;
4303 | a_minusassign multiply_halfregs
4305 $$.n = IS_A1 ($1);
4306 $$.op = 2;
4307 $$.s0 = $2.s0;
4308 $$.s1 = $2.s1;
4312 multiply_halfregs:
4313 HALF_REG STAR HALF_REG
4315 if (IS_DREG ($1) && IS_DREG ($3))
4317 $$.s0 = $1;
4318 $$.s1 = $3;
4320 else
4321 return yyerror ("Dregs expected");
4325 cc_op:
4326 ASSIGN
4328 $$.r0 = 0;
4330 | _BAR_ASSIGN
4332 $$.r0 = 1;
4334 | _AMPERSAND_ASSIGN
4336 $$.r0 = 2;
4338 | _CARET_ASSIGN
4340 $$.r0 = 3;
4344 ccstat:
4345 CCREG cc_op STATUS_REG
4347 $$.r0 = $3.regno;
4348 $$.x0 = $2.r0;
4349 $$.s0 = 0;
4351 | CCREG cc_op V
4353 $$.r0 = 0x18;
4354 $$.x0 = $2.r0;
4355 $$.s0 = 0;
4357 | STATUS_REG cc_op CCREG
4359 $$.r0 = $1.regno;
4360 $$.x0 = $2.r0;
4361 $$.s0 = 1;
4363 | V cc_op CCREG
4365 $$.r0 = 0x18;
4366 $$.x0 = $2.r0;
4367 $$.s0 = 1;
4371 /* Expressions and Symbols. */
4373 symbol: SYMBOL
4375 Expr_Node_Value val;
4376 val.s_value = S_GET_NAME($1);
4377 $$ = Expr_Node_Create (Expr_Node_Reloc, val, NULL, NULL);
4381 any_gotrel:
4383 { $$ = BFD_RELOC_BFIN_GOT; }
4384 | GOT17M4
4385 { $$ = BFD_RELOC_BFIN_GOT17M4; }
4386 | FUNCDESC_GOT17M4
4387 { $$ = BFD_RELOC_BFIN_FUNCDESC_GOT17M4; }
4390 got: symbol AT any_gotrel
4392 Expr_Node_Value val;
4393 val.i_value = $3;
4394 $$ = Expr_Node_Create (Expr_Node_GOT_Reloc, val, $1, NULL);
4398 got_or_expr: got
4400 $$ = $1;
4402 | expr
4404 $$ = $1;
4408 pltpc :
4409 symbol AT PLTPC
4411 $$ = $1;
4415 eterm: NUMBER
4417 Expr_Node_Value val;
4418 val.i_value = $1;
4419 $$ = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
4421 | symbol
4423 $$ = $1;
4425 | LPAREN expr_1 RPAREN
4427 $$ = $2;
4429 | TILDA expr_1
4431 $$ = unary (Expr_Op_Type_COMP, $2);
4433 | MINUS expr_1 %prec TILDA
4435 $$ = unary (Expr_Op_Type_NEG, $2);
4439 expr: expr_1
4441 $$ = $1;
4445 expr_1: expr_1 STAR expr_1
4447 $$ = binary (Expr_Op_Type_Mult, $1, $3);
4449 | expr_1 SLASH expr_1
4451 $$ = binary (Expr_Op_Type_Div, $1, $3);
4453 | expr_1 PERCENT expr_1
4455 $$ = binary (Expr_Op_Type_Mod, $1, $3);
4457 | expr_1 PLUS expr_1
4459 $$ = binary (Expr_Op_Type_Add, $1, $3);
4461 | expr_1 MINUS expr_1
4463 $$ = binary (Expr_Op_Type_Sub, $1, $3);
4465 | expr_1 LESS_LESS expr_1
4467 $$ = binary (Expr_Op_Type_Lshift, $1, $3);
4469 | expr_1 GREATER_GREATER expr_1
4471 $$ = binary (Expr_Op_Type_Rshift, $1, $3);
4473 | expr_1 AMPERSAND expr_1
4475 $$ = binary (Expr_Op_Type_BAND, $1, $3);
4477 | expr_1 CARET expr_1
4479 $$ = binary (Expr_Op_Type_LOR, $1, $3);
4481 | expr_1 BAR expr_1
4483 $$ = binary (Expr_Op_Type_BOR, $1, $3);
4485 | eterm
4487 $$ = $1;
4494 EXPR_T
4495 mkexpr (int x, SYMBOL_T s)
4497 EXPR_T e = (EXPR_T) ALLOCATE (sizeof (struct expression_cell));
4498 e->value = x;
4499 EXPR_SYMBOL(e) = s;
4500 return e;
4503 static int
4504 value_match (Expr_Node *exp, int sz, int sign, int mul, int issigned)
4506 int umax = (1 << sz) - 1;
4507 int min = -1 << (sz - 1);
4508 int max = (1 << (sz - 1)) - 1;
4510 int v = (EXPR_VALUE (exp)) & 0xffffffff;
4512 if ((v % mul) != 0)
4514 error ("%s:%d: Value Error -- Must align to %d\n", __FILE__, __LINE__, mul);
4515 return 0;
4518 v /= mul;
4520 if (sign)
4521 v = -v;
4523 if (issigned)
4525 if (v >= min && v <= max) return 1;
4527 #ifdef DEBUG
4528 fprintf(stderr, "signed value %lx out of range\n", v * mul);
4529 #endif
4530 return 0;
4532 if (v <= umax && v >= 0)
4533 return 1;
4534 #ifdef DEBUG
4535 fprintf(stderr, "unsigned value %lx out of range\n", v * mul);
4536 #endif
4537 return 0;
4540 /* Return the expression structure that allows symbol operations.
4541 If the left and right children are constants, do the operation. */
4542 static Expr_Node *
4543 binary (Expr_Op_Type op, Expr_Node *x, Expr_Node *y)
4545 Expr_Node_Value val;
4547 if (x->type == Expr_Node_Constant && y->type == Expr_Node_Constant)
4549 switch (op)
4551 case Expr_Op_Type_Add:
4552 x->value.i_value += y->value.i_value;
4553 break;
4554 case Expr_Op_Type_Sub:
4555 x->value.i_value -= y->value.i_value;
4556 break;
4557 case Expr_Op_Type_Mult:
4558 x->value.i_value *= y->value.i_value;
4559 break;
4560 case Expr_Op_Type_Div:
4561 if (y->value.i_value == 0)
4562 error ("Illegal Expression: Division by zero.");
4563 else
4564 x->value.i_value /= y->value.i_value;
4565 break;
4566 case Expr_Op_Type_Mod:
4567 x->value.i_value %= y->value.i_value;
4568 break;
4569 case Expr_Op_Type_Lshift:
4570 x->value.i_value <<= y->value.i_value;
4571 break;
4572 case Expr_Op_Type_Rshift:
4573 x->value.i_value >>= y->value.i_value;
4574 break;
4575 case Expr_Op_Type_BAND:
4576 x->value.i_value &= y->value.i_value;
4577 break;
4578 case Expr_Op_Type_BOR:
4579 x->value.i_value |= y->value.i_value;
4580 break;
4581 case Expr_Op_Type_BXOR:
4582 x->value.i_value ^= y->value.i_value;
4583 break;
4584 case Expr_Op_Type_LAND:
4585 x->value.i_value = x->value.i_value && y->value.i_value;
4586 break;
4587 case Expr_Op_Type_LOR:
4588 x->value.i_value = x->value.i_value || y->value.i_value;
4589 break;
4591 default:
4592 error ("%s:%d: Internal assembler error\n", __FILE__, __LINE__);
4594 return x;
4596 /* Canonicalize order to EXPR OP CONSTANT. */
4597 if (x->type == Expr_Node_Constant)
4599 Expr_Node *t = x;
4600 x = y;
4601 y = t;
4603 /* Canonicalize subtraction of const to addition of negated const. */
4604 if (op == Expr_Op_Type_Sub && y->type == Expr_Node_Constant)
4606 op = Expr_Op_Type_Add;
4607 y->value.i_value = -y->value.i_value;
4609 if (y->type == Expr_Node_Constant && x->type == Expr_Node_Binop
4610 && x->Right_Child->type == Expr_Node_Constant)
4612 if (op == x->value.op_value && x->value.op_value == Expr_Op_Type_Add)
4614 x->Right_Child->value.i_value += y->value.i_value;
4615 return x;
4619 /* Create a new expression structure. */
4620 val.op_value = op;
4621 return Expr_Node_Create (Expr_Node_Binop, val, x, y);
4624 static Expr_Node *
4625 unary (Expr_Op_Type op, Expr_Node *x)
4627 if (x->type == Expr_Node_Constant)
4629 switch (op)
4631 case Expr_Op_Type_NEG:
4632 x->value.i_value = -x->value.i_value;
4633 break;
4634 case Expr_Op_Type_COMP:
4635 x->value.i_value = ~x->value.i_value;
4636 break;
4637 default:
4638 error ("%s:%d: Internal assembler error\n", __FILE__, __LINE__);
4640 return x;
4642 else
4644 /* Create a new expression structure. */
4645 Expr_Node_Value val;
4646 val.op_value = op;
4647 return Expr_Node_Create (Expr_Node_Unop, val, x, NULL);
4651 int debug_codeselection = 0;
4652 static void
4653 notethat (char *format, ...)
4655 va_list ap;
4656 va_start (ap, format);
4657 if (debug_codeselection)
4659 vfprintf (errorf, format, ap);
4661 va_end (ap);
4664 #ifdef TEST
4665 main (int argc, char **argv)
4667 yyparse();
4669 #endif