1 /* bfin-parse.y ADI Blackfin parser
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010
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)
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
26 #include "bfin-aux.h" /* Opcode generating auxiliaries. */
28 #include "elf/common.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, \
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, \
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);
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;
167 int yyerror (char *);
169 void error (char *format, ...)
172 static char buffer[2000];
174 va_start (ap, format);
175 vsprintf (buffer, format, ap);
178 as_bad ("%s", buffer);
187 else if (yytext[0] != ';')
188 error ("%s. Input text was %s.", msg, yytext);
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)
201 if (val < from || val > to)
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. */
227 valid_dreg_pair (Register *reg1, Expr_Node *reg2)
229 if (!IS_DREG (*reg1))
231 yyerror ("Dregs expected");
235 if (reg1->regno != 1 && reg1->regno != 3)
237 yyerror ("Bad register pair");
241 if (imm7 (reg2) != reg1->regno - 1)
243 yyerror ("Bad register pair");
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");
262 /* Check mac option. */
265 check_macfunc_option (Macfunc *a, Opt_mode *opt)
267 /* Default option is always valid. */
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))
285 /* Check (vector) mac funcs and ops. */
288 check_macfuncs (Macfunc *aa, Opt_mode *opa,
289 Macfunc *ab, Opt_mode *opb)
291 /* Variables for swapping. */
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. */
298 return yyerror ("Bad opt mode");
300 /* If a0macfunc comes before a1macfunc, swap them. */
304 /* (M) is not allowed here. */
306 return yyerror ("(M) not allowed with A0MAC");
308 return yyerror ("Vector AxMACs can't be same");
310 mtmp = *aa; *aa = *ab; *ab = mtmp;
311 otmp = *opa; *opa = *opb; *opb = otmp;
316 return yyerror ("(M) not allowed with A0MAC");
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)
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)
341 return yyerror ("macfuncs must differ");
342 if (aa->w && (aa->dst.regno - ab->dst.regno != 1))
343 return yyerror ("Destination Dregs must differ by one");
346 /* Make sure mod flags get ORed, too. */
347 opb->mod |= opa->mod;
350 if (check_macfunc_option (aa, opb) < 0
351 && check_macfunc_option (ab, opb) < 0)
352 return yyerror ("bad option");
354 /* Make sure first macfunc has got both P flags ORed. */
362 is_group1 (INSTR_T x)
364 /* Group1 is dpsLDST, LDSTpmod, LDST, LDSTiiFP, LDSTii. */
365 if ((x->value & 0xc000) == 0x8000 || (x->value == 0x0000))
372 is_group2 (INSTR_T x)
374 if ((((x->value & 0xfc00) == 0x9c00) /* dspLDST. */
375 && !((x->value & 0xfde0) == 0x9c60) /* dagMODim. */
376 && !((x->value & 0xfde0) == 0x9ce0) /* dagMODim with bit rev. */
377 && !((x->value & 0xfde0) == 0x9d60)) /* pick dagMODik. */
378 || (x->value == 0x0000))
384 gen_multi_instr_1 (INSTR_T dsp32, INSTR_T dsp16_grp1, INSTR_T dsp16_grp2)
386 int mask1 = dsp32 ? insn_regmask (dsp32->value, dsp32->next->value) : 0;
387 int mask2 = dsp16_grp1 ? insn_regmask (dsp16_grp1->value, 0) : 0;
388 int mask3 = dsp16_grp2 ? insn_regmask (dsp16_grp2->value, 0) : 0;
390 if ((mask1 & mask2) || (mask1 & mask3) || (mask2 & mask3))
391 yyerror ("resource conflict in multi-issue instruction");
393 /* Anomaly 05000074 */
394 if (ENABLE_AC_05000074
395 && dsp32 != NULL && dsp16_grp1 != NULL
396 && (dsp32->value & 0xf780) == 0xc680
397 && ((dsp16_grp1->value & 0xfe40) == 0x9240
398 || (dsp16_grp1->value & 0xfe08) == 0xba08
399 || (dsp16_grp1->value & 0xfc00) == 0xbc00))
400 yyerror ("anomaly 05000074 - Multi-Issue Instruction with \
401 dsp32shiftimm in slot1 and P-reg Store in slot2 Not Supported");
403 return bfin_gen_multi_instr (dsp32, dsp16_grp1, dsp16_grp2);
415 struct { int r0; int s0; int x0; int aop; } modcodes;
416 struct { int r0; } r0;
423 /* Vector Specific. */
424 %token BYTEOP16P BYTEOP16M
425 %token BYTEOP1P BYTEOP2P BYTEOP2M BYTEOP3P
426 %token BYTEUNPACK BYTEPACK
429 %token ALIGN8 ALIGN16 ALIGN24
431 %token EXTRACT DEPOSIT EXPADJ SEARCH
432 %token ONES SIGN SIGNBITS
440 %token CCREG BYTE_DREG
441 %token REG_A_DOUBLE_ZERO REG_A_DOUBLE_ONE
442 %token A_ZERO_DOT_L A_ZERO_DOT_H A_ONE_DOT_L A_ONE_DOT_H
447 %token RTI RTS RTX RTN RTE
458 %token JUMP JUMP_DOT_S JUMP_DOT_L
465 %token NOT TILDA BANG
471 %token MINUS PLUS STAR SLASH
475 %token _PLUS_BAR_PLUS _PLUS_BAR_MINUS _MINUS_BAR_PLUS _MINUS_BAR_MINUS
476 %token _MINUS_MINUS _PLUS_PLUS
478 /* Shift/rotate ops. */
479 %token SHIFT LSHIFT ASHIFT BXORSHIFT
480 %token _GREATER_GREATER_GREATER_THAN_ASSIGN
482 %token LESS_LESS GREATER_GREATER
483 %token _GREATER_GREATER_GREATER
484 %token _LESS_LESS_ASSIGN _GREATER_GREATER_ASSIGN
487 /* In place operators. */
488 %token ASSIGN _STAR_ASSIGN
489 %token _BAR_ASSIGN _CARET_ASSIGN _AMPERSAND_ASSIGN
490 %token _MINUS_ASSIGN _PLUS_ASSIGN
492 /* Assignments, comparisons. */
493 %token _ASSIGN_BANG _LESS_THAN_ASSIGN _ASSIGN_ASSIGN
498 %token FLUSHINV FLUSH
499 %token IFLUSH PREFETCH
516 %token R RND RNDL RNDH RND12 RND20
521 %token BITTGL BITCLR BITSET BITTST BITMUX
524 %token DBGAL DBGAH DBGHALT DBG DBGA DBGCMPLX
526 /* Semantic auxiliaries. */
529 %token COLON SEMICOLON
530 %token RPAREN LPAREN LBRACK RBRACK
534 %token GOT GOT17M4 FUNCDESC_GOT17M4
544 %type <modcodes> byteop_mod
546 %type <reg> a_plusassign
547 %type <reg> a_minusassign
548 %type <macfunc> multiply_halfregs
549 %type <macfunc> assign_macfunc
550 %type <macfunc> a_macfunc
554 %type <modcodes> vsmod
555 %type <modcodes> ccstat
558 %type <reg> reg_with_postinc
559 %type <reg> reg_with_predec
563 %type <symbol> SYMBOL
566 %type <reg> BYTE_DREG
567 %type <reg> REG_A_DOUBLE_ZERO
568 %type <reg> REG_A_DOUBLE_ONE
570 %type <reg> STATUS_REG
574 %type <modcodes> smod
575 %type <modcodes> b3_op
576 %type <modcodes> rnd_op
577 %type <modcodes> post_op
579 %type <r0> iu_or_nothing
580 %type <r0> plus_minus
584 %type <modcodes> amod0
585 %type <modcodes> amod1
586 %type <modcodes> amod2
588 %type <r0> w32_or_nothing
592 %type <expr> got_or_expr
594 %type <value> any_gotrel GOT GOT17M4 FUNCDESC_GOT17M4
596 /* Precedence rules. */
600 %left LESS_LESS GREATER_GREATER
602 %left STAR SLASH PERCENT
613 if (insn == (INSTR_T) 0)
614 return NO_INSN_GENERATED;
615 else if (insn == (INSTR_T) - 1)
616 return SEMANTIC_ERROR;
618 return INSN_GENERATED;
623 /* Parallel instructions. */
624 | asm_1 DOUBLE_BAR asm_1 DOUBLE_BAR asm_1 SEMICOLON
626 if (($1->value & 0xf800) == 0xc000)
628 if (is_group1 ($3) && is_group2 ($5))
629 $$ = gen_multi_instr_1 ($1, $3, $5);
630 else if (is_group2 ($3) && is_group1 ($5))
631 $$ = gen_multi_instr_1 ($1, $5, $3);
633 return yyerror ("Wrong 16 bit instructions groups, slot 2 and slot 3 must be 16-bit instrution group");
635 else if (($3->value & 0xf800) == 0xc000)
637 if (is_group1 ($1) && is_group2 ($5))
638 $$ = gen_multi_instr_1 ($3, $1, $5);
639 else if (is_group2 ($1) && is_group1 ($5))
640 $$ = gen_multi_instr_1 ($3, $5, $1);
642 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 3 must be 16-bit instrution group");
644 else if (($5->value & 0xf800) == 0xc000)
646 if (is_group1 ($1) && is_group2 ($3))
647 $$ = gen_multi_instr_1 ($5, $1, $3);
648 else if (is_group2 ($1) && is_group1 ($3))
649 $$ = gen_multi_instr_1 ($5, $3, $1);
651 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be 16-bit instrution group");
654 error ("\nIllegal Multi Issue Construct, at least any one of the slot must be DSP32 instruction group\n");
657 | asm_1 DOUBLE_BAR asm_1 SEMICOLON
659 if (($1->value & 0xf800) == 0xc000)
662 $$ = gen_multi_instr_1 ($1, $3, 0);
663 else if (is_group2 ($3))
664 $$ = gen_multi_instr_1 ($1, 0, $3);
666 return yyerror ("Wrong 16 bit instructions groups, slot 2 must be the 16-bit instruction group");
668 else if (($3->value & 0xf800) == 0xc000)
671 $$ = gen_multi_instr_1 ($3, $1, 0);
672 else if (is_group2 ($1))
673 $$ = gen_multi_instr_1 ($3, 0, $1);
675 return yyerror ("Wrong 16 bit instructions groups, slot 1 must be the 16-bit instruction group");
677 else if (is_group1 ($1) && is_group2 ($3))
678 $$ = gen_multi_instr_1 (0, $1, $3);
679 else if (is_group2 ($1) && is_group1 ($3))
680 $$ = gen_multi_instr_1 (0, $3, $1);
682 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be the 16-bit instruction group");
697 $$ = DSP32MAC (3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
699 | assign_macfunc opt_mode
703 int h00, h10, h01, h11;
705 if (check_macfunc_option (&$1, &$2) < 0)
706 return yyerror ("bad option");
711 return yyerror ("(m) not allowed with a0 unit");
730 $$ = DSP32MAC (op1, $2.MM, $2.mod, w1, $1.P, h01, h11, h00, h10,
731 &$1.dst, op0, &$1.s0, &$1.s1, w0);
737 | assign_macfunc opt_mode COMMA assign_macfunc opt_mode
741 if (check_macfuncs (&$1, &$2, &$4, &$5) < 0)
743 notethat ("assign_macfunc (.), assign_macfunc (.)\n");
750 $$ = DSP32MAC ($1.op, $2.MM, $5.mod, $1.w, $1.P,
751 IS_H ($1.s0), IS_H ($1.s1), IS_H ($4.s0), IS_H ($4.s1),
752 dst, $4.op, &$1.s0, &$1.s1, $4.w);
759 notethat ("dsp32alu: DISALGNEXCPT\n");
760 $$ = DSP32ALU (18, 0, 0, 0, 0, 0, 0, 0, 3);
762 | REG ASSIGN LPAREN a_plusassign REG_A RPAREN
764 if (IS_DREG ($1) && !IS_A1 ($4) && IS_A1 ($5))
766 notethat ("dsp32alu: dregs = ( A0 += A1 )\n");
767 $$ = DSP32ALU (11, 0, 0, &$1, 0, 0, 0, 0, 0);
770 return yyerror ("Register mismatch");
772 | HALF_REG ASSIGN LPAREN a_plusassign REG_A RPAREN
774 if (!IS_A1 ($4) && IS_A1 ($5))
776 notethat ("dsp32alu: dregs_half = ( A0 += A1 )\n");
777 $$ = DSP32ALU (11, IS_H ($1), 0, &$1, 0, 0, 0, 0, 1);
780 return yyerror ("Register mismatch");
782 | A_ZERO_DOT_H ASSIGN HALF_REG
784 notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
785 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
787 | A_ONE_DOT_H ASSIGN HALF_REG
789 notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
790 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
792 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16P LPAREN REG
793 COLON expr COMMA REG COLON expr RPAREN aligndir
795 if (!IS_DREG ($2) || !IS_DREG ($4))
796 return yyerror ("Dregs expected");
797 else if (!valid_dreg_pair (&$9, $11))
798 return yyerror ("Bad dreg pair");
799 else if (!valid_dreg_pair (&$13, $15))
800 return yyerror ("Bad dreg pair");
803 notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16P (dregs_pair , dregs_pair ) (half)\n");
804 $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 0);
808 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16M LPAREN REG COLON expr COMMA
809 REG COLON expr RPAREN aligndir
811 if (!IS_DREG ($2) || !IS_DREG ($4))
812 return yyerror ("Dregs expected");
813 else if (!valid_dreg_pair (&$9, $11))
814 return yyerror ("Bad dreg pair");
815 else if (!valid_dreg_pair (&$13, $15))
816 return yyerror ("Bad dreg pair");
819 notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16M (dregs_pair , dregs_pair ) (aligndir)\n");
820 $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 1);
824 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEUNPACK REG COLON expr aligndir
826 if (!IS_DREG ($2) || !IS_DREG ($4))
827 return yyerror ("Dregs expected");
828 else if (!valid_dreg_pair (&$8, $10))
829 return yyerror ("Bad dreg pair");
832 notethat ("dsp32alu: (dregs , dregs ) = BYTEUNPACK dregs_pair (aligndir)\n");
833 $$ = DSP32ALU (24, 0, &$2, &$4, &$8, 0, $11.r0, 0, 1);
836 | LPAREN REG COMMA REG RPAREN ASSIGN SEARCH REG LPAREN searchmod RPAREN
838 if (IS_DREG ($2) && IS_DREG ($4) && IS_DREG ($8))
840 notethat ("dsp32alu: (dregs , dregs ) = SEARCH dregs (searchmod)\n");
841 $$ = DSP32ALU (13, 0, &$2, &$4, &$8, 0, 0, 0, $10.r0);
844 return yyerror ("Register mismatch");
846 | REG ASSIGN A_ONE_DOT_L PLUS A_ONE_DOT_H COMMA
847 REG ASSIGN A_ZERO_DOT_L PLUS A_ZERO_DOT_H
849 if (IS_DREG ($1) && IS_DREG ($7))
851 notethat ("dsp32alu: dregs = A1.l + A1.h, dregs = A0.l + A0.h \n");
852 $$ = DSP32ALU (12, 0, &$1, &$7, 0, 0, 0, 0, 1);
855 return yyerror ("Register mismatch");
859 | REG ASSIGN REG_A PLUS REG_A COMMA REG ASSIGN REG_A MINUS REG_A amod1
861 if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
862 && IS_A1 ($9) && !IS_A1 ($11))
864 notethat ("dsp32alu: dregs = A1 + A0 , dregs = A1 - A0 (amod1)\n");
865 $$ = DSP32ALU (17, 0, &$1, &$7, 0, 0, $12.s0, $12.x0, 0);
868 else if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
869 && !IS_A1 ($9) && IS_A1 ($11))
871 notethat ("dsp32alu: dregs = A0 + A1 , dregs = A0 - A1 (amod1)\n");
872 $$ = DSP32ALU (17, 0, &$1, &$7, 0, 0, $12.s0, $12.x0, 1);
875 return yyerror ("Register mismatch");
878 | REG ASSIGN REG plus_minus REG COMMA REG ASSIGN REG plus_minus REG amod1
881 return yyerror ("Operators must differ");
883 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5)
884 && REG_SAME ($3, $9) && REG_SAME ($5, $11))
886 notethat ("dsp32alu: dregs = dregs + dregs,"
887 "dregs = dregs - dregs (amod1)\n");
888 $$ = DSP32ALU (4, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, 2);
891 return yyerror ("Register mismatch");
894 /* Bar Operations. */
896 | REG ASSIGN REG op_bar_op REG COMMA REG ASSIGN REG op_bar_op REG amod2
898 if (!REG_SAME ($3, $9) || !REG_SAME ($5, $11))
899 return yyerror ("Differing source registers");
901 if (!IS_DREG ($1) || !IS_DREG ($3) || !IS_DREG ($5) || !IS_DREG ($7))
902 return yyerror ("Dregs expected");
905 if ($4.r0 == 1 && $10.r0 == 2)
907 notethat ("dsp32alu: dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
908 $$ = DSP32ALU (1, 1, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
910 else if ($4.r0 == 0 && $10.r0 == 3)
912 notethat ("dsp32alu: dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
913 $$ = DSP32ALU (1, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
916 return yyerror ("Bar operand mismatch");
919 | REG ASSIGN ABS REG vmod
923 if (IS_DREG ($1) && IS_DREG ($4))
927 notethat ("dsp32alu: dregs = ABS dregs (v)\n");
932 /* Vector version of ABS. */
933 notethat ("dsp32alu: dregs = ABS dregs\n");
936 $$ = DSP32ALU (op, 0, 0, &$1, &$4, 0, 0, 0, 2);
939 return yyerror ("Dregs expected");
943 notethat ("dsp32alu: Ax = ABS Ax\n");
944 $$ = DSP32ALU (16, IS_A1 ($1), 0, 0, 0, 0, 0, 0, IS_A1 ($3));
946 | A_ZERO_DOT_L ASSIGN HALF_REG
950 notethat ("dsp32alu: A0.l = reg_half\n");
951 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
954 return yyerror ("A0.l = Rx.l expected");
956 | A_ONE_DOT_L ASSIGN HALF_REG
960 notethat ("dsp32alu: A1.l = reg_half\n");
961 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
964 return yyerror ("A1.l = Rx.l expected");
967 | REG ASSIGN c_align LPAREN REG COMMA REG RPAREN
969 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
971 notethat ("dsp32shift: dregs = ALIGN8 (dregs , dregs )\n");
972 $$ = DSP32SHIFT (13, &$1, &$7, &$5, $3.r0, 0);
975 return yyerror ("Dregs expected");
978 | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN byteop_mod
981 return yyerror ("Dregs expected");
982 else if (!valid_dreg_pair (&$5, $7))
983 return yyerror ("Bad dreg pair");
984 else if (!valid_dreg_pair (&$9, $11))
985 return yyerror ("Bad dreg pair");
988 notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
989 $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, $13.s0, 0, $13.r0);
992 | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
995 return yyerror ("Dregs expected");
996 else if (!valid_dreg_pair (&$5, $7))
997 return yyerror ("Bad dreg pair");
998 else if (!valid_dreg_pair (&$9, $11))
999 return yyerror ("Bad dreg pair");
1002 notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
1003 $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, 0, 0, 0);
1007 | REG ASSIGN BYTEOP2P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1011 return yyerror ("Dregs expected");
1012 else if (!valid_dreg_pair (&$5, $7))
1013 return yyerror ("Bad dreg pair");
1014 else if (!valid_dreg_pair (&$9, $11))
1015 return yyerror ("Bad dreg pair");
1018 notethat ("dsp32alu: dregs = BYTEOP2P (dregs_pair , dregs_pair ) (rnd_op)\n");
1019 $$ = DSP32ALU (22, $13.r0, 0, &$1, &$5, &$9, $13.s0, $13.x0, $13.aop);
1023 | REG ASSIGN BYTEOP2M LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1027 return yyerror ("Dregs expected");
1028 else if (!valid_dreg_pair (&$5, $7))
1029 return yyerror ("Bad dreg pair");
1030 else if (!valid_dreg_pair (&$9, $11))
1031 return yyerror ("Bad dreg pair");
1034 notethat ("dsp32alu: dregs = BYTEOP2P (dregs_pair , dregs_pair ) (rnd_op)\n");
1035 $$ = DSP32ALU (22, $13.r0, 0, &$1, &$5, &$9, $13.s0, 0, $13.x0);
1039 | REG ASSIGN BYTEOP3P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1043 return yyerror ("Dregs expected");
1044 else if (!valid_dreg_pair (&$5, $7))
1045 return yyerror ("Bad dreg pair");
1046 else if (!valid_dreg_pair (&$9, $11))
1047 return yyerror ("Bad dreg pair");
1050 notethat ("dsp32alu: dregs = BYTEOP3P (dregs_pair , dregs_pair ) (b3_op)\n");
1051 $$ = DSP32ALU (23, $13.x0, 0, &$1, &$5, &$9, $13.s0, 0, 0);
1055 | REG ASSIGN BYTEPACK LPAREN REG COMMA REG RPAREN
1057 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1059 notethat ("dsp32alu: dregs = BYTEPACK (dregs , dregs )\n");
1060 $$ = DSP32ALU (24, 0, 0, &$1, &$5, &$7, 0, 0, 0);
1063 return yyerror ("Dregs expected");
1066 | HALF_REG ASSIGN HALF_REG ASSIGN SIGN LPAREN HALF_REG RPAREN STAR
1067 HALF_REG PLUS SIGN LPAREN HALF_REG RPAREN STAR HALF_REG
1069 if (IS_HCOMPL ($1, $3) && IS_HCOMPL ($7, $14) && IS_HCOMPL ($10, $17))
1071 notethat ("dsp32alu: dregs_hi = dregs_lo ="
1072 "SIGN (dregs_hi) * dregs_hi + "
1073 "SIGN (dregs_lo) * dregs_lo \n");
1075 $$ = DSP32ALU (12, 0, 0, &$1, &$7, &$10, 0, 0, 0);
1078 return yyerror ("Dregs expected");
1080 | REG ASSIGN REG plus_minus REG amod1
1082 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1086 /* No saturation flag specified, generate the 16 bit variant. */
1087 notethat ("COMP3op: dregs = dregs +- dregs\n");
1088 $$ = COMP3OP (&$1, &$3, &$5, $4.r0);
1092 /* Saturation flag specified, generate the 32 bit variant. */
1093 notethat ("dsp32alu: dregs = dregs +- dregs (amod1)\n");
1094 $$ = DSP32ALU (4, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
1098 if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($5) && $4.r0 == 0)
1100 notethat ("COMP3op: pregs = pregs + pregs\n");
1101 $$ = COMP3OP (&$1, &$3, &$5, 5);
1104 return yyerror ("Dregs expected");
1106 | REG ASSIGN min_max LPAREN REG COMMA REG RPAREN vmod
1110 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1117 notethat ("dsp32alu: dregs = {MIN|MAX} (dregs, dregs)\n");
1118 $$ = DSP32ALU (op, 0, 0, &$1, &$5, &$7, 0, 0, $3.r0);
1121 return yyerror ("Dregs expected");
1124 | a_assign MINUS REG_A
1126 notethat ("dsp32alu: Ax = - Ax\n");
1127 $$ = DSP32ALU (14, IS_A1 ($1), 0, 0, 0, 0, 0, 0, IS_A1 ($3));
1129 | HALF_REG ASSIGN HALF_REG plus_minus HALF_REG amod1
1131 notethat ("dsp32alu: dregs_lo = dregs_lo +- dregs_lo (amod1)\n");
1132 $$ = DSP32ALU (2 | $4.r0, IS_H ($1), 0, &$1, &$3, &$5,
1133 $6.s0, $6.x0, HL2 ($3, $5));
1135 | a_assign a_assign expr
1137 if (EXPR_VALUE ($3) == 0 && !REG_SAME ($1, $2))
1139 notethat ("dsp32alu: A1 = A0 = 0\n");
1140 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, 2);
1143 return yyerror ("Bad value, 0 expected");
1147 | a_assign REG_A LPAREN S RPAREN
1149 if (REG_SAME ($1, $2))
1151 notethat ("dsp32alu: Ax = Ax (S)\n");
1152 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 1, 0, IS_A1 ($1));
1155 return yyerror ("Registers must be equal");
1158 | HALF_REG ASSIGN REG LPAREN RND RPAREN
1162 notethat ("dsp32alu: dregs_half = dregs (RND)\n");
1163 $$ = DSP32ALU (12, IS_H ($1), 0, &$1, &$3, 0, 0, 0, 3);
1166 return yyerror ("Dregs expected");
1169 | HALF_REG ASSIGN REG plus_minus REG LPAREN RND12 RPAREN
1171 if (IS_DREG ($3) && IS_DREG ($5))
1173 notethat ("dsp32alu: dregs_half = dregs (+-) dregs (RND12)\n");
1174 $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 0, $4.r0);
1177 return yyerror ("Dregs expected");
1180 | HALF_REG ASSIGN REG plus_minus REG LPAREN RND20 RPAREN
1182 if (IS_DREG ($3) && IS_DREG ($5))
1184 notethat ("dsp32alu: dregs_half = dregs -+ dregs (RND20)\n");
1185 $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 1, $4.r0 | 2);
1188 return yyerror ("Dregs expected");
1193 if (!REG_SAME ($1, $2))
1195 notethat ("dsp32alu: An = Am\n");
1196 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, IS_A1 ($1), 0, 3);
1199 return yyerror ("Accu reg arguments must differ");
1206 notethat ("dsp32alu: An = dregs\n");
1207 $$ = DSP32ALU (9, 0, 0, 0, &$2, 0, 1, 0, IS_A1 ($1) << 1);
1210 return yyerror ("Dregs expected");
1213 | REG ASSIGN HALF_REG xpmod
1217 if ($1.regno == REG_A0x && IS_DREG ($3))
1219 notethat ("dsp32alu: A0.x = dregs_lo\n");
1220 $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 1);
1222 else if ($1.regno == REG_A1x && IS_DREG ($3))
1224 notethat ("dsp32alu: A1.x = dregs_lo\n");
1225 $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 3);
1227 else if (IS_DREG ($1) && IS_DREG ($3))
1229 notethat ("ALU2op: dregs = dregs_lo\n");
1230 $$ = ALU2OP (&$1, &$3, 10 | ($4.r0 ? 0: 1));
1233 return yyerror ("Register mismatch");
1236 return yyerror ("Low reg expected");
1239 | HALF_REG ASSIGN expr
1241 notethat ("LDIMMhalf: pregs_half = imm16\n");
1243 if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
1244 && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
1245 return yyerror ("Wrong register for load immediate");
1247 if (!IS_IMM ($3, 16) && !IS_UIMM ($3, 16))
1248 return yyerror ("Constant out of range");
1250 $$ = LDIMMHALF_R (&$1, IS_H ($1), 0, 0, $3);
1255 notethat ("dsp32alu: An = 0\n");
1258 return yyerror ("0 expected");
1260 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, IS_A1 ($1));
1263 | REG ASSIGN expr xpmod1
1265 if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
1266 && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
1267 return yyerror ("Wrong register for load immediate");
1271 /* 7 bit immediate value if possible.
1272 We will check for that constant value for efficiency
1273 If it goes to reloc, it will be 16 bit. */
1274 if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_DREG ($1))
1276 notethat ("COMPI2opD: dregs = imm7 (x) \n");
1277 $$ = COMPI2OPD (&$1, imm7 ($3), 0);
1279 else if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_PREG ($1))
1281 notethat ("COMPI2opP: pregs = imm7 (x)\n");
1282 $$ = COMPI2OPP (&$1, imm7 ($3), 0);
1286 if (IS_CONST ($3) && !IS_IMM ($3, 16))
1287 return yyerror ("Immediate value out of range");
1289 notethat ("LDIMMhalf: regs = luimm16 (x)\n");
1291 $$ = LDIMMHALF_R5 (&$1, 0, 1, 0, $3);
1296 /* (z) There is no 7 bit zero extended instruction.
1297 If the expr is a relocation, generate it. */
1299 if (IS_CONST ($3) && !IS_UIMM ($3, 16))
1300 return yyerror ("Immediate value out of range");
1302 notethat ("LDIMMhalf: regs = luimm16 (x)\n");
1304 $$ = LDIMMHALF_R5 (&$1, 0, 0, 1, $3);
1308 | HALF_REG ASSIGN REG
1311 return yyerror ("Low reg expected");
1313 if (IS_DREG ($1) && $3.regno == REG_A0x)
1315 notethat ("dsp32alu: dregs_lo = A0.x\n");
1316 $$ = DSP32ALU (10, 0, 0, &$1, 0, 0, 0, 0, 0);
1318 else if (IS_DREG ($1) && $3.regno == REG_A1x)
1320 notethat ("dsp32alu: dregs_lo = A1.x\n");
1321 $$ = DSP32ALU (10, 0, 0, &$1, 0, 0, 0, 0, 1);
1324 return yyerror ("Register mismatch");
1327 | REG ASSIGN REG op_bar_op REG amod0
1329 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1331 notethat ("dsp32alu: dregs = dregs .|. dregs (amod0)\n");
1332 $$ = DSP32ALU (0, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
1335 return yyerror ("Register mismatch");
1338 | REG ASSIGN BYTE_DREG xpmod
1340 if (IS_DREG ($1) && IS_DREG ($3))
1342 notethat ("ALU2op: dregs = dregs_byte\n");
1343 $$ = ALU2OP (&$1, &$3, 12 | ($4.r0 ? 0: 1));
1346 return yyerror ("Register mismatch");
1349 | a_assign ABS REG_A COMMA a_assign ABS REG_A
1351 if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
1353 notethat ("dsp32alu: A1 = ABS A1 , A0 = ABS A0\n");
1354 $$ = DSP32ALU (16, 0, 0, 0, 0, 0, 0, 0, 3);
1357 return yyerror ("Register mismatch");
1360 | a_assign MINUS REG_A COMMA a_assign MINUS REG_A
1362 if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
1364 notethat ("dsp32alu: A1 = - A1 , A0 = - A0\n");
1365 $$ = DSP32ALU (14, 0, 0, 0, 0, 0, 0, 0, 3);
1368 return yyerror ("Register mismatch");
1371 | a_minusassign REG_A w32_or_nothing
1373 if (!IS_A1 ($1) && IS_A1 ($2))
1375 notethat ("dsp32alu: A0 -= A1\n");
1376 $$ = DSP32ALU (11, 0, 0, 0, 0, 0, $3.r0, 0, 3);
1379 return yyerror ("Register mismatch");
1382 | REG _MINUS_ASSIGN expr
1384 if (IS_IREG ($1) && EXPR_VALUE ($3) == 4)
1386 notethat ("dagMODik: iregs -= 4\n");
1387 $$ = DAGMODIK (&$1, 3);
1389 else if (IS_IREG ($1) && EXPR_VALUE ($3) == 2)
1391 notethat ("dagMODik: iregs -= 2\n");
1392 $$ = DAGMODIK (&$1, 1);
1395 return yyerror ("Register or value mismatch");
1398 | REG _PLUS_ASSIGN REG LPAREN BREV RPAREN
1400 if (IS_IREG ($1) && IS_MREG ($3))
1402 notethat ("dagMODim: iregs += mregs (opt_brev)\n");
1404 $$ = DAGMODIM (&$1, &$3, 0, 1);
1406 else if (IS_PREG ($1) && IS_PREG ($3))
1408 notethat ("PTR2op: pregs += pregs (BREV )\n");
1409 $$ = PTR2OP (&$1, &$3, 5);
1412 return yyerror ("Register mismatch");
1415 | REG _MINUS_ASSIGN REG
1417 if (IS_IREG ($1) && IS_MREG ($3))
1419 notethat ("dagMODim: iregs -= mregs\n");
1420 $$ = DAGMODIM (&$1, &$3, 1, 0);
1422 else if (IS_PREG ($1) && IS_PREG ($3))
1424 notethat ("PTR2op: pregs -= pregs\n");
1425 $$ = PTR2OP (&$1, &$3, 0);
1428 return yyerror ("Register mismatch");
1431 | REG_A _PLUS_ASSIGN REG_A w32_or_nothing
1433 if (!IS_A1 ($1) && IS_A1 ($3))
1435 notethat ("dsp32alu: A0 += A1 (W32)\n");
1436 $$ = DSP32ALU (11, 0, 0, 0, 0, 0, $4.r0, 0, 2);
1439 return yyerror ("Register mismatch");
1442 | REG _PLUS_ASSIGN REG
1444 if (IS_IREG ($1) && IS_MREG ($3))
1446 notethat ("dagMODim: iregs += mregs\n");
1447 $$ = DAGMODIM (&$1, &$3, 0, 0);
1450 return yyerror ("iregs += mregs expected");
1453 | REG _PLUS_ASSIGN expr
1457 if (EXPR_VALUE ($3) == 4)
1459 notethat ("dagMODik: iregs += 4\n");
1460 $$ = DAGMODIK (&$1, 2);
1462 else if (EXPR_VALUE ($3) == 2)
1464 notethat ("dagMODik: iregs += 2\n");
1465 $$ = DAGMODIK (&$1, 0);
1468 return yyerror ("iregs += [ 2 | 4 ");
1470 else if (IS_PREG ($1) && IS_IMM ($3, 7))
1472 notethat ("COMPI2opP: pregs += imm7\n");
1473 $$ = COMPI2OPP (&$1, imm7 ($3), 1);
1475 else if (IS_DREG ($1) && IS_IMM ($3, 7))
1477 notethat ("COMPI2opD: dregs += imm7\n");
1478 $$ = COMPI2OPD (&$1, imm7 ($3), 1);
1480 else if ((IS_DREG ($1) || IS_PREG ($1)) && IS_CONST ($3))
1481 return yyerror ("Immediate value out of range");
1483 return yyerror ("Register mismatch");
1486 | REG _STAR_ASSIGN REG
1488 if (IS_DREG ($1) && IS_DREG ($3))
1490 notethat ("ALU2op: dregs *= dregs\n");
1491 $$ = ALU2OP (&$1, &$3, 3);
1494 return yyerror ("Register mismatch");
1497 | SAA LPAREN REG COLON expr COMMA REG COLON expr RPAREN aligndir
1499 if (!valid_dreg_pair (&$3, $5))
1500 return yyerror ("Bad dreg pair");
1501 else if (!valid_dreg_pair (&$7, $9))
1502 return yyerror ("Bad dreg pair");
1505 notethat ("dsp32alu: SAA (dregs_pair , dregs_pair ) (aligndir)\n");
1506 $$ = DSP32ALU (18, 0, 0, 0, &$3, &$7, $11.r0, 0, 0);
1510 | a_assign REG_A LPAREN S RPAREN COMMA a_assign REG_A LPAREN S RPAREN
1512 if (REG_SAME ($1, $2) && REG_SAME ($7, $8) && !REG_SAME ($1, $7))
1514 notethat ("dsp32alu: A1 = A1 (S) , A0 = A0 (S)\n");
1515 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 1, 0, 2);
1518 return yyerror ("Register mismatch");
1521 | REG ASSIGN LPAREN REG PLUS REG RPAREN LESS_LESS expr
1523 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6)
1524 && REG_SAME ($1, $4))
1526 if (EXPR_VALUE ($9) == 1)
1528 notethat ("ALU2op: dregs = (dregs + dregs) << 1\n");
1529 $$ = ALU2OP (&$1, &$6, 4);
1531 else if (EXPR_VALUE ($9) == 2)
1533 notethat ("ALU2op: dregs = (dregs + dregs) << 2\n");
1534 $$ = ALU2OP (&$1, &$6, 5);
1537 return yyerror ("Bad shift value");
1539 else if (IS_PREG ($1) && IS_PREG ($4) && IS_PREG ($6)
1540 && REG_SAME ($1, $4))
1542 if (EXPR_VALUE ($9) == 1)
1544 notethat ("PTR2op: pregs = (pregs + pregs) << 1\n");
1545 $$ = PTR2OP (&$1, &$6, 6);
1547 else if (EXPR_VALUE ($9) == 2)
1549 notethat ("PTR2op: pregs = (pregs + pregs) << 2\n");
1550 $$ = PTR2OP (&$1, &$6, 7);
1553 return yyerror ("Bad shift value");
1556 return yyerror ("Register mismatch");
1560 | REG ASSIGN REG BAR REG
1562 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1564 notethat ("COMP3op: dregs = dregs | dregs\n");
1565 $$ = COMP3OP (&$1, &$3, &$5, 3);
1568 return yyerror ("Dregs expected");
1570 | REG ASSIGN REG CARET REG
1572 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1574 notethat ("COMP3op: dregs = dregs ^ dregs\n");
1575 $$ = COMP3OP (&$1, &$3, &$5, 4);
1578 return yyerror ("Dregs expected");
1580 | REG ASSIGN REG PLUS LPAREN REG LESS_LESS expr RPAREN
1582 if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($6))
1584 if (EXPR_VALUE ($8) == 1)
1586 notethat ("COMP3op: pregs = pregs + (pregs << 1)\n");
1587 $$ = COMP3OP (&$1, &$3, &$6, 6);
1589 else if (EXPR_VALUE ($8) == 2)
1591 notethat ("COMP3op: pregs = pregs + (pregs << 2)\n");
1592 $$ = COMP3OP (&$1, &$3, &$6, 7);
1595 return yyerror ("Bad shift value");
1598 return yyerror ("Dregs expected");
1600 | CCREG ASSIGN REG_A _ASSIGN_ASSIGN REG_A
1602 if ($3.regno == REG_A0 && $5.regno == REG_A1)
1604 notethat ("CCflag: CC = A0 == A1\n");
1605 $$ = CCFLAG (0, 0, 5, 0, 0);
1608 return yyerror ("AREGs are in bad order or same");
1610 | CCREG ASSIGN REG_A LESS_THAN REG_A
1612 if ($3.regno == REG_A0 && $5.regno == REG_A1)
1614 notethat ("CCflag: CC = A0 < A1\n");
1615 $$ = CCFLAG (0, 0, 6, 0, 0);
1618 return yyerror ("AREGs are in bad order or same");
1620 | CCREG ASSIGN REG LESS_THAN REG iu_or_nothing
1622 if ((IS_DREG ($3) && IS_DREG ($5))
1623 || (IS_PREG ($3) && IS_PREG ($5)))
1625 notethat ("CCflag: CC = dpregs < dpregs\n");
1626 $$ = CCFLAG (&$3, $5.regno & CODE_MASK, $6.r0, 0, IS_PREG ($3) ? 1 : 0);
1629 return yyerror ("Bad register in comparison");
1631 | CCREG ASSIGN REG LESS_THAN expr iu_or_nothing
1633 if (!IS_DREG ($3) && !IS_PREG ($3))
1634 return yyerror ("Bad register in comparison");
1636 if (($6.r0 == 1 && IS_IMM ($5, 3))
1637 || ($6.r0 == 3 && IS_UIMM ($5, 3)))
1639 notethat ("CCflag: CC = dpregs < (u)imm3\n");
1640 $$ = CCFLAG (&$3, imm3 ($5), $6.r0, 1, IS_PREG ($3) ? 1 : 0);
1643 return yyerror ("Bad constant value");
1645 | CCREG ASSIGN REG _ASSIGN_ASSIGN REG
1647 if ((IS_DREG ($3) && IS_DREG ($5))
1648 || (IS_PREG ($3) && IS_PREG ($5)))
1650 notethat ("CCflag: CC = dpregs == dpregs\n");
1651 $$ = CCFLAG (&$3, $5.regno & CODE_MASK, 0, 0, IS_PREG ($3) ? 1 : 0);
1654 return yyerror ("Bad register in comparison");
1656 | CCREG ASSIGN REG _ASSIGN_ASSIGN expr
1658 if (!IS_DREG ($3) && !IS_PREG ($3))
1659 return yyerror ("Bad register in comparison");
1663 notethat ("CCflag: CC = dpregs == imm3\n");
1664 $$ = CCFLAG (&$3, imm3 ($5), 0, 1, IS_PREG ($3) ? 1 : 0);
1667 return yyerror ("Bad constant range");
1669 | CCREG ASSIGN REG_A _LESS_THAN_ASSIGN REG_A
1671 if ($3.regno == REG_A0 && $5.regno == REG_A1)
1673 notethat ("CCflag: CC = A0 <= A1\n");
1674 $$ = CCFLAG (0, 0, 7, 0, 0);
1677 return yyerror ("AREGs are in bad order or same");
1679 | CCREG ASSIGN REG _LESS_THAN_ASSIGN REG iu_or_nothing
1681 if ((IS_DREG ($3) && IS_DREG ($5))
1682 || (IS_PREG ($3) && IS_PREG ($5)))
1684 notethat ("CCflag: CC = dpregs <= dpregs (..)\n");
1685 $$ = CCFLAG (&$3, $5.regno & CODE_MASK,
1686 1 + $6.r0, 0, IS_PREG ($3) ? 1 : 0);
1689 return yyerror ("Bad register in comparison");
1691 | CCREG ASSIGN REG _LESS_THAN_ASSIGN expr iu_or_nothing
1693 if (!IS_DREG ($3) && !IS_PREG ($3))
1694 return yyerror ("Bad register in comparison");
1696 if (($6.r0 == 1 && IS_IMM ($5, 3))
1697 || ($6.r0 == 3 && IS_UIMM ($5, 3)))
1699 notethat ("CCflag: CC = dpregs <= (u)imm3\n");
1700 $$ = CCFLAG (&$3, imm3 ($5), 1 + $6.r0, 1, IS_PREG ($3) ? 1 : 0);
1703 return yyerror ("Bad constant value");
1706 | REG ASSIGN REG AMPERSAND REG
1708 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1710 notethat ("COMP3op: dregs = dregs & dregs\n");
1711 $$ = COMP3OP (&$1, &$3, &$5, 2);
1714 return yyerror ("Dregs expected");
1719 notethat ("CC2stat operation\n");
1720 $$ = bfin_gen_cc2stat ($1.r0, $1.x0, $1.s0);
1725 if ((IS_GENREG ($1) && IS_GENREG ($3))
1726 || (IS_GENREG ($1) && IS_DAGREG ($3))
1727 || (IS_DAGREG ($1) && IS_GENREG ($3))
1728 || (IS_DAGREG ($1) && IS_DAGREG ($3))
1729 || (IS_GENREG ($1) && $3.regno == REG_USP)
1730 || ($1.regno == REG_USP && IS_GENREG ($3))
1731 || ($1.regno == REG_USP && $3.regno == REG_USP)
1732 || (IS_DREG ($1) && IS_SYSREG ($3))
1733 || (IS_PREG ($1) && IS_SYSREG ($3))
1734 || (IS_SYSREG ($1) && IS_GENREG ($3))
1735 || (IS_ALLREG ($1) && IS_EMUDAT ($3))
1736 || (IS_EMUDAT ($1) && IS_ALLREG ($3))
1737 || (IS_SYSREG ($1) && $3.regno == REG_USP))
1739 $$ = bfin_gen_regmv (&$3, &$1);
1742 return yyerror ("Unsupported register move");
1749 notethat ("CC2dreg: CC = dregs\n");
1750 $$ = bfin_gen_cc2dreg (1, &$3);
1753 return yyerror ("Only 'CC = Dreg' supported");
1760 notethat ("CC2dreg: dregs = CC\n");
1761 $$ = bfin_gen_cc2dreg (0, &$1);
1764 return yyerror ("Only 'Dreg = CC' supported");
1767 | CCREG _ASSIGN_BANG CCREG
1769 notethat ("CC2dreg: CC =! CC\n");
1770 $$ = bfin_gen_cc2dreg (3, 0);
1775 | HALF_REG ASSIGN multiply_halfregs opt_mode
1777 notethat ("dsp32mult: dregs_half = multiply_halfregs (opt_mode)\n");
1779 if (!IS_H ($1) && $4.MM)
1780 return yyerror ("(M) not allowed with MAC0");
1782 if ($4.mod != 0 && $4.mod != M_FU && $4.mod != M_IS
1783 && $4.mod != M_IU && $4.mod != M_T && $4.mod != M_TFU
1784 && $4.mod != M_S2RND && $4.mod != M_ISS2 && $4.mod != M_IH)
1785 return yyerror ("bad option.");
1789 $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 0,
1790 IS_H ($3.s0), IS_H ($3.s1), 0, 0,
1791 &$1, 0, &$3.s0, &$3.s1, 0);
1795 $$ = DSP32MULT (0, 0, $4.mod, 0, 0,
1796 0, 0, IS_H ($3.s0), IS_H ($3.s1),
1797 &$1, 0, &$3.s0, &$3.s1, 1);
1801 | REG ASSIGN multiply_halfregs opt_mode
1803 /* Odd registers can use (M). */
1805 return yyerror ("Dreg expected");
1807 if (IS_EVEN ($1) && $4.MM)
1808 return yyerror ("(M) not allowed with MAC0");
1810 if ($4.mod != 0 && $4.mod != M_FU && $4.mod != M_IS
1811 && $4.mod != M_S2RND && $4.mod != M_ISS2)
1812 return yyerror ("bad option");
1816 notethat ("dsp32mult: dregs = multiply_halfregs (opt_mode)\n");
1818 $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 1,
1819 IS_H ($3.s0), IS_H ($3.s1), 0, 0,
1820 &$1, 0, &$3.s0, &$3.s1, 0);
1824 notethat ("dsp32mult: dregs = multiply_halfregs opt_mode\n");
1825 $$ = DSP32MULT (0, 0, $4.mod, 0, 1,
1826 0, 0, IS_H ($3.s0), IS_H ($3.s1),
1827 &$1, 0, &$3.s0, &$3.s1, 1);
1831 | HALF_REG ASSIGN multiply_halfregs opt_mode COMMA
1832 HALF_REG ASSIGN multiply_halfregs opt_mode
1834 if (!IS_DREG ($1) || !IS_DREG ($6))
1835 return yyerror ("Dregs expected");
1837 if (!IS_HCOMPL($1, $6))
1838 return yyerror ("Dest registers mismatch");
1840 if (check_multiply_halfregs (&$3, &$8) < 0)
1843 if ((!IS_H ($1) && $4.MM)
1844 || (!IS_H ($6) && $9.MM))
1845 return yyerror ("(M) not allowed with MAC0");
1847 notethat ("dsp32mult: dregs_hi = multiply_halfregs mxd_mod, "
1848 "dregs_lo = multiply_halfregs opt_mode\n");
1851 $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 0,
1852 IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
1853 &$1, 0, &$3.s0, &$3.s1, 1);
1855 $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 0,
1856 IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
1857 &$1, 0, &$3.s0, &$3.s1, 1);
1860 | REG ASSIGN multiply_halfregs opt_mode COMMA REG ASSIGN multiply_halfregs opt_mode
1862 if (!IS_DREG ($1) || !IS_DREG ($6))
1863 return yyerror ("Dregs expected");
1865 if ((IS_EVEN ($1) && $6.regno - $1.regno != 1)
1866 || (IS_EVEN ($6) && $1.regno - $6.regno != 1))
1867 return yyerror ("Dest registers mismatch");
1869 if (check_multiply_halfregs (&$3, &$8) < 0)
1872 if ((IS_EVEN ($1) && $4.MM)
1873 || (IS_EVEN ($6) && $9.MM))
1874 return yyerror ("(M) not allowed with MAC0");
1876 notethat ("dsp32mult: dregs = multiply_halfregs mxd_mod, "
1877 "dregs = multiply_halfregs opt_mode\n");
1880 $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 1,
1881 IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
1882 &$1, 0, &$3.s0, &$3.s1, 1);
1884 $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 1,
1885 IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
1886 &$1, 0, &$3.s0, &$3.s1, 1);
1891 | a_assign ASHIFT REG_A BY HALF_REG
1893 if (!REG_SAME ($1, $3))
1894 return yyerror ("Aregs must be same");
1896 if (IS_DREG ($5) && !IS_H ($5))
1898 notethat ("dsp32shift: A0 = ASHIFT A0 BY dregs_lo\n");
1899 $$ = DSP32SHIFT (3, 0, &$5, 0, 0, IS_A1 ($1));
1902 return yyerror ("Dregs expected");
1905 | HALF_REG ASSIGN ASHIFT HALF_REG BY HALF_REG smod
1907 if (IS_DREG ($6) && !IS_H ($6))
1909 notethat ("dsp32shift: dregs_half = ASHIFT dregs_half BY dregs_lo\n");
1910 $$ = DSP32SHIFT (0, &$1, &$6, &$4, $7.s0, HL2 ($1, $4));
1913 return yyerror ("Dregs expected");
1916 | a_assign REG_A LESS_LESS expr
1918 if (!REG_SAME ($1, $2))
1919 return yyerror ("Aregs must be same");
1921 if (IS_UIMM ($4, 5))
1923 notethat ("dsp32shiftimm: A0 = A0 << uimm5\n");
1924 $$ = DSP32SHIFTIMM (3, 0, imm5 ($4), 0, 0, IS_A1 ($1));
1927 return yyerror ("Bad shift value");
1930 | REG ASSIGN REG LESS_LESS expr vsmod
1932 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
1937 notethat ("dsp32shiftimm: dregs = dregs << expr (V, .)\n");
1938 $$ = DSP32SHIFTIMM (1, &$1, imm4 ($5), &$3, $6.s0 ? 1 : 2, 0);
1942 notethat ("dsp32shiftimm: dregs = dregs << uimm5 (.)\n");
1943 $$ = DSP32SHIFTIMM (2, &$1, imm6 ($5), &$3, $6.s0 ? 1 : 2, 0);
1946 else if ($6.s0 == 0 && IS_PREG ($1) && IS_PREG ($3))
1948 if (EXPR_VALUE ($5) == 2)
1950 notethat ("PTR2op: pregs = pregs << 2\n");
1951 $$ = PTR2OP (&$1, &$3, 1);
1953 else if (EXPR_VALUE ($5) == 1)
1955 notethat ("COMP3op: pregs = pregs << 1\n");
1956 $$ = COMP3OP (&$1, &$3, &$3, 5);
1959 return yyerror ("Bad shift value");
1962 return yyerror ("Bad shift value or register");
1964 | HALF_REG ASSIGN HALF_REG LESS_LESS expr smod
1966 if (IS_UIMM ($5, 4))
1970 notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4 (S)\n");
1971 $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, $6.s0, HL2 ($1, $3));
1975 notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4\n");
1976 $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, 2, HL2 ($1, $3));
1980 return yyerror ("Bad shift value");
1982 | REG ASSIGN ASHIFT REG BY HALF_REG vsmod
1986 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6) && !IS_H ($6))
1991 notethat ("dsp32shift: dregs = ASHIFT dregs BY "
1992 "dregs_lo (V, .)\n");
1998 notethat ("dsp32shift: dregs = ASHIFT dregs BY dregs_lo (.)\n");
2000 $$ = DSP32SHIFT (op, &$1, &$6, &$4, $7.s0, 0);
2003 return yyerror ("Dregs expected");
2007 | HALF_REG ASSIGN EXPADJ LPAREN REG COMMA HALF_REG RPAREN vmod
2009 if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
2011 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs , dregs_lo )\n");
2012 $$ = DSP32SHIFT (7, &$1, &$7, &$5, $9.r0, 0);
2015 return yyerror ("Bad shift value or register");
2019 | HALF_REG ASSIGN EXPADJ LPAREN HALF_REG COMMA HALF_REG RPAREN
2021 if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
2023 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_lo, dregs_lo)\n");
2024 $$ = DSP32SHIFT (7, &$1, &$7, &$5, 2, 0);
2026 else if (IS_DREG_L ($1) && IS_DREG_H ($5) && IS_DREG_L ($7))
2028 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_hi, dregs_lo)\n");
2029 $$ = DSP32SHIFT (7, &$1, &$7, &$5, 3, 0);
2032 return yyerror ("Bad shift value or register");
2037 | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN
2039 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2041 notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs )\n");
2042 $$ = DSP32SHIFT (10, &$1, &$7, &$5, 2, 0);
2045 return yyerror ("Register mismatch");
2048 | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN LPAREN X RPAREN
2050 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2052 notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs ) (X)\n");
2053 $$ = DSP32SHIFT (10, &$1, &$7, &$5, 3, 0);
2056 return yyerror ("Register mismatch");
2059 | REG ASSIGN EXTRACT LPAREN REG COMMA HALF_REG RPAREN xpmod
2061 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG_L ($7))
2063 notethat ("dsp32shift: dregs = EXTRACT (dregs, dregs_lo ) (.)\n");
2064 $$ = DSP32SHIFT (10, &$1, &$7, &$5, $9.r0, 0);
2067 return yyerror ("Register mismatch");
2070 | a_assign REG_A _GREATER_GREATER_GREATER expr
2072 if (!REG_SAME ($1, $2))
2073 return yyerror ("Aregs must be same");
2075 if (IS_UIMM ($4, 5))
2077 notethat ("dsp32shiftimm: Ax = Ax >>> uimm5\n");
2078 $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 0, IS_A1 ($1));
2081 return yyerror ("Shift value range error");
2083 | a_assign LSHIFT REG_A BY HALF_REG
2085 if (REG_SAME ($1, $3) && IS_DREG_L ($5))
2087 notethat ("dsp32shift: Ax = LSHIFT Ax BY dregs_lo\n");
2088 $$ = DSP32SHIFT (3, 0, &$5, 0, 1, IS_A1 ($1));
2091 return yyerror ("Register mismatch");
2094 | HALF_REG ASSIGN LSHIFT HALF_REG BY HALF_REG
2096 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2098 notethat ("dsp32shift: dregs_lo = LSHIFT dregs_hi BY dregs_lo\n");
2099 $$ = DSP32SHIFT (0, &$1, &$6, &$4, 2, HL2 ($1, $4));
2102 return yyerror ("Register mismatch");
2105 | REG ASSIGN LSHIFT REG BY HALF_REG vmod
2107 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2109 notethat ("dsp32shift: dregs = LSHIFT dregs BY dregs_lo (V )\n");
2110 $$ = DSP32SHIFT ($7.r0 ? 1: 2, &$1, &$6, &$4, 2, 0);
2113 return yyerror ("Register mismatch");
2116 | REG ASSIGN SHIFT REG BY HALF_REG
2118 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2120 notethat ("dsp32shift: dregs = SHIFT dregs BY dregs_lo\n");
2121 $$ = DSP32SHIFT (2, &$1, &$6, &$4, 2, 0);
2124 return yyerror ("Register mismatch");
2127 | a_assign REG_A GREATER_GREATER expr
2129 if (REG_SAME ($1, $2) && IS_IMM ($4, 6) >= 0)
2131 notethat ("dsp32shiftimm: Ax = Ax >> imm6\n");
2132 $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 1, IS_A1 ($1));
2135 return yyerror ("Accu register expected");
2138 | REG ASSIGN REG GREATER_GREATER expr vmod
2142 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2144 notethat ("dsp32shiftimm: dregs = dregs >> uimm5 (V)\n");
2145 $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, 2, 0);
2148 return yyerror ("Register mismatch");
2152 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2154 notethat ("dsp32shiftimm: dregs = dregs >> uimm5\n");
2155 $$ = DSP32SHIFTIMM (2, &$1, -imm6 ($5), &$3, 2, 0);
2157 else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 2)
2159 notethat ("PTR2op: pregs = pregs >> 2\n");
2160 $$ = PTR2OP (&$1, &$3, 3);
2162 else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 1)
2164 notethat ("PTR2op: pregs = pregs >> 1\n");
2165 $$ = PTR2OP (&$1, &$3, 4);
2168 return yyerror ("Register mismatch");
2171 | HALF_REG ASSIGN HALF_REG GREATER_GREATER expr
2173 if (IS_UIMM ($5, 5))
2175 notethat ("dsp32shiftimm: dregs_half = dregs_half >> uimm5\n");
2176 $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3, 2, HL2 ($1, $3));
2179 return yyerror ("Register mismatch");
2181 | HALF_REG ASSIGN HALF_REG _GREATER_GREATER_GREATER expr smod
2183 if (IS_UIMM ($5, 5))
2185 notethat ("dsp32shiftimm: dregs_half = dregs_half >>> uimm5\n");
2186 $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3,
2187 $6.s0, HL2 ($1, $3));
2190 return yyerror ("Register or modifier mismatch");
2194 | REG ASSIGN REG _GREATER_GREATER_GREATER expr vsmod
2196 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2201 notethat ("dsp32shiftimm: dregs = dregs >>> uimm5 (V, .)\n");
2202 $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, $6.s0, 0);
2206 notethat ("dsp32shiftimm: dregs = dregs >>> uimm5 (.)\n");
2207 $$ = DSP32SHIFTIMM (2, &$1, -uimm5 ($5), &$3, $6.s0, 0);
2211 return yyerror ("Register mismatch");
2214 | HALF_REG ASSIGN ONES REG
2216 if (IS_DREG_L ($1) && IS_DREG ($4))
2218 notethat ("dsp32shift: dregs_lo = ONES dregs\n");
2219 $$ = DSP32SHIFT (6, &$1, 0, &$4, 3, 0);
2222 return yyerror ("Register mismatch");
2225 | REG ASSIGN PACK LPAREN HALF_REG COMMA HALF_REG RPAREN
2227 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2229 notethat ("dsp32shift: dregs = PACK (dregs_hi , dregs_hi )\n");
2230 $$ = DSP32SHIFT (4, &$1, &$7, &$5, HL2 ($5, $7), 0);
2233 return yyerror ("Register mismatch");
2236 | HALF_REG ASSIGN CCREG ASSIGN BXORSHIFT LPAREN REG_A COMMA REG RPAREN
2239 && $7.regno == REG_A0
2240 && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
2242 notethat ("dsp32shift: dregs_lo = CC = BXORSHIFT (A0 , dregs )\n");
2243 $$ = DSP32SHIFT (11, &$1, &$9, 0, 0, 0);
2246 return yyerror ("Register mismatch");
2249 | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG RPAREN
2252 && $7.regno == REG_A0
2253 && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
2255 notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , dregs)\n");
2256 $$ = DSP32SHIFT (11, &$1, &$9, 0, 1, 0);
2259 return yyerror ("Register mismatch");
2262 | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
2264 if (IS_DREG ($1) && !IS_H ($1) && !REG_SAME ($7, $9))
2266 notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , A1 , CC)\n");
2267 $$ = DSP32SHIFT (12, &$1, 0, 0, 1, 0);
2270 return yyerror ("Register mismatch");
2273 | a_assign ROT REG_A BY HALF_REG
2275 if (REG_SAME ($1, $3) && IS_DREG_L ($5))
2277 notethat ("dsp32shift: Ax = ROT Ax BY dregs_lo\n");
2278 $$ = DSP32SHIFT (3, 0, &$5, 0, 2, IS_A1 ($1));
2281 return yyerror ("Register mismatch");
2284 | REG ASSIGN ROT REG BY HALF_REG
2286 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2288 notethat ("dsp32shift: dregs = ROT dregs BY dregs_lo\n");
2289 $$ = DSP32SHIFT (2, &$1, &$6, &$4, 3, 0);
2292 return yyerror ("Register mismatch");
2295 | a_assign ROT REG_A BY expr
2299 notethat ("dsp32shiftimm: An = ROT An BY imm6\n");
2300 $$ = DSP32SHIFTIMM (3, 0, imm6 ($5), 0, 2, IS_A1 ($1));
2303 return yyerror ("Register mismatch");
2306 | REG ASSIGN ROT REG BY expr
2308 if (IS_DREG ($1) && IS_DREG ($4) && IS_IMM ($6, 6))
2310 $$ = DSP32SHIFTIMM (2, &$1, imm6 ($6), &$4, 3, IS_A1 ($1));
2313 return yyerror ("Register mismatch");
2316 | HALF_REG ASSIGN SIGNBITS REG_A
2320 notethat ("dsp32shift: dregs_lo = SIGNBITS An\n");
2321 $$ = DSP32SHIFT (6, &$1, 0, 0, IS_A1 ($4), 0);
2324 return yyerror ("Register mismatch");
2327 | HALF_REG ASSIGN SIGNBITS REG
2329 if (IS_DREG_L ($1) && IS_DREG ($4))
2331 notethat ("dsp32shift: dregs_lo = SIGNBITS dregs\n");
2332 $$ = DSP32SHIFT (5, &$1, 0, &$4, 0, 0);
2335 return yyerror ("Register mismatch");
2338 | HALF_REG ASSIGN SIGNBITS HALF_REG
2342 notethat ("dsp32shift: dregs_lo = SIGNBITS dregs_lo\n");
2343 $$ = DSP32SHIFT (5, &$1, 0, &$4, 1 + IS_H ($4), 0);
2346 return yyerror ("Register mismatch");
2349 /* The ASR bit is just inverted here. */
2350 | HALF_REG ASSIGN VIT_MAX LPAREN REG RPAREN asr_asl
2352 if (IS_DREG_L ($1) && IS_DREG ($5))
2354 notethat ("dsp32shift: dregs_lo = VIT_MAX (dregs) (..)\n");
2355 $$ = DSP32SHIFT (9, &$1, 0, &$5, ($7.r0 ? 0 : 1), 0);
2358 return yyerror ("Register mismatch");
2361 | REG ASSIGN VIT_MAX LPAREN REG COMMA REG RPAREN asr_asl
2363 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2365 notethat ("dsp32shift: dregs = VIT_MAX (dregs, dregs) (ASR)\n");
2366 $$ = DSP32SHIFT (9, &$1, &$7, &$5, 2 | ($9.r0 ? 0 : 1), 0);
2369 return yyerror ("Register mismatch");
2372 | BITMUX LPAREN REG COMMA REG COMMA REG_A RPAREN asr_asl
2374 if (IS_DREG ($3) && IS_DREG ($5) && !IS_A1 ($7))
2376 notethat ("dsp32shift: BITMUX (dregs , dregs , A0) (ASR)\n");
2377 $$ = DSP32SHIFT (8, 0, &$3, &$5, $9.r0, 0);
2380 return yyerror ("Register mismatch");
2383 | a_assign BXORSHIFT LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
2385 if (!IS_A1 ($1) && !IS_A1 ($4) && IS_A1 ($6))
2387 notethat ("dsp32shift: A0 = BXORSHIFT (A0 , A1 , CC )\n");
2388 $$ = DSP32SHIFT (12, 0, 0, 0, 0, 0);
2391 return yyerror ("Dregs expected");
2395 /* LOGI2op: BITCLR (dregs, uimm5). */
2396 | BITCLR LPAREN REG COMMA expr RPAREN
2398 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2400 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2401 $$ = LOGI2OP ($3, uimm5 ($5), 4);
2404 return yyerror ("Register mismatch");
2407 /* LOGI2op: BITSET (dregs, uimm5). */
2408 | BITSET LPAREN REG COMMA expr RPAREN
2410 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2412 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2413 $$ = LOGI2OP ($3, uimm5 ($5), 2);
2416 return yyerror ("Register mismatch");
2419 /* LOGI2op: BITTGL (dregs, uimm5). */
2420 | BITTGL LPAREN REG COMMA expr RPAREN
2422 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2424 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2425 $$ = LOGI2OP ($3, uimm5 ($5), 3);
2428 return yyerror ("Register mismatch");
2431 | CCREG _ASSIGN_BANG BITTST LPAREN REG COMMA expr RPAREN
2433 if (IS_DREG ($5) && IS_UIMM ($7, 5))
2435 notethat ("LOGI2op: CC =! BITTST (dregs , uimm5 )\n");
2436 $$ = LOGI2OP ($5, uimm5 ($7), 0);
2439 return yyerror ("Register mismatch or value error");
2442 | CCREG ASSIGN BITTST LPAREN REG COMMA expr RPAREN
2444 if (IS_DREG ($5) && IS_UIMM ($7, 5))
2446 notethat ("LOGI2op: CC = BITTST (dregs , uimm5 )\n");
2447 $$ = LOGI2OP ($5, uimm5 ($7), 1);
2450 return yyerror ("Register mismatch or value error");
2453 | IF BANG CCREG REG ASSIGN REG
2455 if ((IS_DREG ($4) || IS_PREG ($4))
2456 && (IS_DREG ($6) || IS_PREG ($6)))
2458 notethat ("ccMV: IF ! CC gregs = gregs\n");
2459 $$ = CCMV (&$6, &$4, 0);
2462 return yyerror ("Register mismatch");
2465 | IF CCREG REG ASSIGN REG
2467 if ((IS_DREG ($5) || IS_PREG ($5))
2468 && (IS_DREG ($3) || IS_PREG ($3)))
2470 notethat ("ccMV: IF CC gregs = gregs\n");
2471 $$ = CCMV (&$5, &$3, 1);
2474 return yyerror ("Register mismatch");
2477 | IF BANG CCREG JUMP expr
2479 if (IS_PCREL10 ($5))
2481 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2482 $$ = BRCC (0, 0, $5);
2485 return yyerror ("Bad jump offset");
2488 | IF BANG CCREG JUMP expr LPAREN BP RPAREN
2490 if (IS_PCREL10 ($5))
2492 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2493 $$ = BRCC (0, 1, $5);
2496 return yyerror ("Bad jump offset");
2499 | IF CCREG JUMP expr
2501 if (IS_PCREL10 ($4))
2503 notethat ("BRCC: IF CC JUMP pcrel11m2\n");
2504 $$ = BRCC (1, 0, $4);
2507 return yyerror ("Bad jump offset");
2510 | IF CCREG JUMP expr LPAREN BP RPAREN
2512 if (IS_PCREL10 ($4))
2514 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2515 $$ = BRCC (1, 1, $4);
2518 return yyerror ("Bad jump offset");
2522 notethat ("ProgCtrl: NOP\n");
2523 $$ = PROGCTRL (0, 0);
2528 notethat ("ProgCtrl: RTS\n");
2529 $$ = PROGCTRL (1, 0);
2534 notethat ("ProgCtrl: RTI\n");
2535 $$ = PROGCTRL (1, 1);
2540 notethat ("ProgCtrl: RTX\n");
2541 $$ = PROGCTRL (1, 2);
2546 notethat ("ProgCtrl: RTN\n");
2547 $$ = PROGCTRL (1, 3);
2552 notethat ("ProgCtrl: RTE\n");
2553 $$ = PROGCTRL (1, 4);
2558 notethat ("ProgCtrl: IDLE\n");
2559 $$ = PROGCTRL (2, 0);
2564 notethat ("ProgCtrl: CSYNC\n");
2565 $$ = PROGCTRL (2, 3);
2570 notethat ("ProgCtrl: SSYNC\n");
2571 $$ = PROGCTRL (2, 4);
2576 notethat ("ProgCtrl: EMUEXCPT\n");
2577 $$ = PROGCTRL (2, 5);
2584 notethat ("ProgCtrl: CLI dregs\n");
2585 $$ = PROGCTRL (3, $2.regno & CODE_MASK);
2588 return yyerror ("Dreg expected for CLI");
2595 notethat ("ProgCtrl: STI dregs\n");
2596 $$ = PROGCTRL (4, $2.regno & CODE_MASK);
2599 return yyerror ("Dreg expected for STI");
2602 | JUMP LPAREN REG RPAREN
2606 notethat ("ProgCtrl: JUMP (pregs )\n");
2607 $$ = PROGCTRL (5, $3.regno & CODE_MASK);
2610 return yyerror ("Bad register for indirect jump");
2613 | CALL LPAREN REG RPAREN
2617 notethat ("ProgCtrl: CALL (pregs )\n");
2618 $$ = PROGCTRL (6, $3.regno & CODE_MASK);
2621 return yyerror ("Bad register for indirect call");
2624 | CALL LPAREN PC PLUS REG RPAREN
2628 notethat ("ProgCtrl: CALL (PC + pregs )\n");
2629 $$ = PROGCTRL (7, $5.regno & CODE_MASK);
2632 return yyerror ("Bad register for indirect call");
2635 | JUMP LPAREN PC PLUS REG RPAREN
2639 notethat ("ProgCtrl: JUMP (PC + pregs )\n");
2640 $$ = PROGCTRL (8, $5.regno & CODE_MASK);
2643 return yyerror ("Bad register for indirect jump");
2648 if (IS_UIMM ($2, 4))
2650 notethat ("ProgCtrl: RAISE uimm4\n");
2651 $$ = PROGCTRL (9, uimm4 ($2));
2654 return yyerror ("Bad value for RAISE");
2659 notethat ("ProgCtrl: EMUEXCPT\n");
2660 $$ = PROGCTRL (10, uimm4 ($2));
2663 | TESTSET LPAREN REG RPAREN
2667 notethat ("ProgCtrl: TESTSET (pregs )\n");
2668 $$ = PROGCTRL (11, $3.regno & CODE_MASK);
2671 return yyerror ("Preg expected");
2676 if (IS_PCREL12 ($2))
2678 notethat ("UJUMP: JUMP pcrel12\n");
2682 return yyerror ("Bad value for relative jump");
2687 if (IS_PCREL12 ($2))
2689 notethat ("UJUMP: JUMP_DOT_S pcrel12\n");
2693 return yyerror ("Bad value for relative jump");
2698 if (IS_PCREL24 ($2))
2700 notethat ("CALLa: jump.l pcrel24\n");
2704 return yyerror ("Bad value for long jump");
2709 if (IS_PCREL24 ($2))
2711 notethat ("CALLa: jump.l pcrel24\n");
2715 return yyerror ("Bad value for long jump");
2720 if (IS_PCREL24 ($2))
2722 notethat ("CALLa: CALL pcrel25m2\n");
2726 return yyerror ("Bad call address");
2730 if (IS_PCREL24 ($2))
2732 notethat ("CALLa: CALL pcrel25m2\n");
2736 return yyerror ("Bad call address");
2740 /* ALU2op: DIVQ (dregs, dregs). */
2741 | DIVQ LPAREN REG COMMA REG RPAREN
2743 if (IS_DREG ($3) && IS_DREG ($5))
2744 $$ = ALU2OP (&$3, &$5, 8);
2746 return yyerror ("Bad registers for DIVQ");
2749 | DIVS LPAREN REG COMMA REG RPAREN
2751 if (IS_DREG ($3) && IS_DREG ($5))
2752 $$ = ALU2OP (&$3, &$5, 9);
2754 return yyerror ("Bad registers for DIVS");
2757 | REG ASSIGN MINUS REG vsmod
2759 if (IS_DREG ($1) && IS_DREG ($4))
2761 if ($5.r0 == 0 && $5.s0 == 0 && $5.aop == 0)
2763 notethat ("ALU2op: dregs = - dregs\n");
2764 $$ = ALU2OP (&$1, &$4, 14);
2766 else if ($5.r0 == 1 && $5.s0 == 0 && $5.aop == 3)
2768 notethat ("dsp32alu: dregs = - dregs (.)\n");
2769 $$ = DSP32ALU (15, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
2773 notethat ("dsp32alu: dregs = - dregs (.)\n");
2774 $$ = DSP32ALU (7, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
2778 return yyerror ("Dregs expected");
2781 | REG ASSIGN TILDA REG
2783 if (IS_DREG ($1) && IS_DREG ($4))
2785 notethat ("ALU2op: dregs = ~dregs\n");
2786 $$ = ALU2OP (&$1, &$4, 15);
2789 return yyerror ("Dregs expected");
2792 | REG _GREATER_GREATER_ASSIGN REG
2794 if (IS_DREG ($1) && IS_DREG ($3))
2796 notethat ("ALU2op: dregs >>= dregs\n");
2797 $$ = ALU2OP (&$1, &$3, 1);
2800 return yyerror ("Dregs expected");
2803 | REG _GREATER_GREATER_ASSIGN expr
2805 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2807 notethat ("LOGI2op: dregs >>= uimm5\n");
2808 $$ = LOGI2OP ($1, uimm5 ($3), 6);
2811 return yyerror ("Dregs expected or value error");
2814 | REG _GREATER_GREATER_GREATER_THAN_ASSIGN REG
2816 if (IS_DREG ($1) && IS_DREG ($3))
2818 notethat ("ALU2op: dregs >>>= dregs\n");
2819 $$ = ALU2OP (&$1, &$3, 0);
2822 return yyerror ("Dregs expected");
2825 | REG _LESS_LESS_ASSIGN REG
2827 if (IS_DREG ($1) && IS_DREG ($3))
2829 notethat ("ALU2op: dregs <<= dregs\n");
2830 $$ = ALU2OP (&$1, &$3, 2);
2833 return yyerror ("Dregs expected");
2836 | REG _LESS_LESS_ASSIGN expr
2838 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2840 notethat ("LOGI2op: dregs <<= uimm5\n");
2841 $$ = LOGI2OP ($1, uimm5 ($3), 7);
2844 return yyerror ("Dregs expected or const value error");
2848 | REG _GREATER_GREATER_GREATER_THAN_ASSIGN expr
2850 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2852 notethat ("LOGI2op: dregs >>>= uimm5\n");
2853 $$ = LOGI2OP ($1, uimm5 ($3), 5);
2856 return yyerror ("Dregs expected");
2859 /* Cache Control. */
2861 | FLUSH LBRACK REG RBRACK
2863 notethat ("CaCTRL: FLUSH [ pregs ]\n");
2865 $$ = CACTRL (&$3, 0, 2);
2867 return yyerror ("Bad register(s) for FLUSH");
2870 | FLUSH reg_with_postinc
2874 notethat ("CaCTRL: FLUSH [ pregs ++ ]\n");
2875 $$ = CACTRL (&$2, 1, 2);
2878 return yyerror ("Bad register(s) for FLUSH");
2881 | FLUSHINV LBRACK REG RBRACK
2885 notethat ("CaCTRL: FLUSHINV [ pregs ]\n");
2886 $$ = CACTRL (&$3, 0, 1);
2889 return yyerror ("Bad register(s) for FLUSH");
2892 | FLUSHINV reg_with_postinc
2896 notethat ("CaCTRL: FLUSHINV [ pregs ++ ]\n");
2897 $$ = CACTRL (&$2, 1, 1);
2900 return yyerror ("Bad register(s) for FLUSH");
2903 /* CaCTRL: IFLUSH [pregs]. */
2904 | IFLUSH LBRACK REG RBRACK
2908 notethat ("CaCTRL: IFLUSH [ pregs ]\n");
2909 $$ = CACTRL (&$3, 0, 3);
2912 return yyerror ("Bad register(s) for FLUSH");
2915 | IFLUSH reg_with_postinc
2919 notethat ("CaCTRL: IFLUSH [ pregs ++ ]\n");
2920 $$ = CACTRL (&$2, 1, 3);
2923 return yyerror ("Bad register(s) for FLUSH");
2926 | PREFETCH LBRACK REG RBRACK
2930 notethat ("CaCTRL: PREFETCH [ pregs ]\n");
2931 $$ = CACTRL (&$3, 0, 0);
2934 return yyerror ("Bad register(s) for PREFETCH");
2937 | PREFETCH reg_with_postinc
2941 notethat ("CaCTRL: PREFETCH [ pregs ++ ]\n");
2942 $$ = CACTRL (&$2, 1, 0);
2945 return yyerror ("Bad register(s) for PREFETCH");
2949 /* LDST: B [ pregs <post_op> ] = dregs. */
2951 | B LBRACK REG post_op RBRACK ASSIGN REG
2954 return yyerror ("Dreg expected for source operand");
2956 return yyerror ("Preg expected in address");
2958 notethat ("LDST: B [ pregs <post_op> ] = dregs\n");
2959 $$ = LDST (&$3, &$7, $4.x0, 2, 0, 1);
2962 /* LDSTidxI: B [ pregs + imm16 ] = dregs. */
2963 | B LBRACK REG plus_minus expr RBRACK ASSIGN REG
2965 Expr_Node *tmp = $5;
2968 return yyerror ("Dreg expected for source operand");
2970 return yyerror ("Preg expected in address");
2973 return yyerror ("Plain symbol used as offset");
2976 tmp = unary (Expr_Op_Type_NEG, tmp);
2978 if (in_range_p (tmp, -32768, 32767, 0))
2980 notethat ("LDST: B [ pregs + imm16 ] = dregs\n");
2981 $$ = LDSTIDXI (&$3, &$8, 1, 2, 0, $5);
2984 return yyerror ("Displacement out of range");
2988 /* LDSTii: W [ pregs + uimm4s2 ] = dregs. */
2989 | W LBRACK REG plus_minus expr RBRACK ASSIGN REG
2991 Expr_Node *tmp = $5;
2994 return yyerror ("Dreg expected for source operand");
2996 return yyerror ("Preg expected in address");
2999 tmp = unary (Expr_Op_Type_NEG, tmp);
3002 return yyerror ("Plain symbol used as offset");
3004 if (in_range_p (tmp, 0, 30, 1))
3006 notethat ("LDSTii: W [ pregs +- uimm5m2 ] = dregs\n");
3007 $$ = LDSTII (&$3, &$8, tmp, 1, 1);
3009 else if (in_range_p (tmp, -65536, 65535, 1))
3011 notethat ("LDSTidxI: W [ pregs + imm17m2 ] = dregs\n");
3012 $$ = LDSTIDXI (&$3, &$8, 1, 1, 0, tmp);
3015 return yyerror ("Displacement out of range");
3018 /* LDST: W [ pregs <post_op> ] = dregs. */
3019 | W LBRACK REG post_op RBRACK ASSIGN REG
3022 return yyerror ("Dreg expected for source operand");
3024 return yyerror ("Preg expected in address");
3026 notethat ("LDST: W [ pregs <post_op> ] = dregs\n");
3027 $$ = LDST (&$3, &$7, $4.x0, 1, 0, 1);
3030 | W LBRACK REG post_op RBRACK ASSIGN HALF_REG
3033 return yyerror ("Dreg expected for source operand");
3036 if (!IS_IREG ($3) && !IS_PREG ($3))
3037 return yyerror ("Ireg or Preg expected in address");
3039 else if (!IS_IREG ($3))
3040 return yyerror ("Ireg expected in address");
3044 notethat ("dspLDST: W [ iregs <post_op> ] = dregs_half\n");
3045 $$ = DSPLDST (&$3, 1 + IS_H ($7), &$7, $4.x0, 1);
3049 notethat ("LDSTpmod: W [ pregs ] = dregs_half\n");
3050 $$ = LDSTPMOD (&$3, &$7, &$3, 1 + IS_H ($7), 1);
3054 /* LDSTiiFP: [ FP - const ] = dpregs. */
3055 | LBRACK REG plus_minus expr RBRACK ASSIGN REG
3057 Expr_Node *tmp = $4;
3058 int ispreg = IS_PREG ($7);
3061 return yyerror ("Preg expected in address");
3063 if (!IS_DREG ($7) && !ispreg)
3064 return yyerror ("Preg expected for source operand");
3067 tmp = unary (Expr_Op_Type_NEG, tmp);
3070 return yyerror ("Plain symbol used as offset");
3072 if (in_range_p (tmp, 0, 63, 3))
3074 notethat ("LDSTii: dpregs = [ pregs + uimm6m4 ]\n");
3075 $$ = LDSTII (&$2, &$7, tmp, 1, ispreg ? 3 : 0);
3077 else if ($2.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
3079 notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
3080 tmp = unary (Expr_Op_Type_NEG, tmp);
3081 $$ = LDSTIIFP (tmp, &$7, 1);
3083 else if (in_range_p (tmp, -131072, 131071, 3))
3085 notethat ("LDSTidxI: [ pregs + imm18m4 ] = dpregs\n");
3086 $$ = LDSTIDXI (&$2, &$7, 1, 0, ispreg ? 1 : 0, tmp);
3089 return yyerror ("Displacement out of range");
3092 | REG ASSIGN W LBRACK REG plus_minus expr RBRACK xpmod
3094 Expr_Node *tmp = $7;
3096 return yyerror ("Dreg expected for destination operand");
3098 return yyerror ("Preg expected in address");
3101 tmp = unary (Expr_Op_Type_NEG, tmp);
3104 return yyerror ("Plain symbol used as offset");
3106 if (in_range_p (tmp, 0, 30, 1))
3108 notethat ("LDSTii: dregs = W [ pregs + uimm5m2 ] (.)\n");
3109 $$ = LDSTII (&$5, &$1, tmp, 0, 1 << $9.r0);
3111 else if (in_range_p (tmp, -65536, 65535, 1))
3113 notethat ("LDSTidxI: dregs = W [ pregs + imm17m2 ] (.)\n");
3114 $$ = LDSTIDXI (&$5, &$1, 0, 1, $9.r0, tmp);
3117 return yyerror ("Displacement out of range");
3120 | HALF_REG ASSIGN W LBRACK REG post_op RBRACK
3123 return yyerror ("Dreg expected for source operand");
3126 if (!IS_IREG ($5) && !IS_PREG ($5))
3127 return yyerror ("Ireg or Preg expected in address");
3129 else if (!IS_IREG ($5))
3130 return yyerror ("Ireg expected in address");
3134 notethat ("dspLDST: dregs_half = W [ iregs <post_op> ]\n");
3135 $$ = DSPLDST(&$5, 1 + IS_H ($1), &$1, $6.x0, 0);
3139 notethat ("LDSTpmod: dregs_half = W [ pregs <post_op> ]\n");
3140 $$ = LDSTPMOD (&$5, &$1, &$5, 1 + IS_H ($1), 0);
3145 | REG ASSIGN W LBRACK REG post_op RBRACK xpmod
3148 return yyerror ("Dreg expected for destination operand");
3150 return yyerror ("Preg expected in address");
3152 notethat ("LDST: dregs = W [ pregs <post_op> ] (.)\n");
3153 $$ = LDST (&$5, &$1, $6.x0, 1, $8.r0, 0);
3156 | REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK xpmod
3159 return yyerror ("Dreg expected for destination operand");
3160 if (!IS_PREG ($5) || !IS_PREG ($7))
3161 return yyerror ("Preg expected in address");
3163 notethat ("LDSTpmod: dregs = W [ pregs ++ pregs ] (.)\n");
3164 $$ = LDSTPMOD (&$5, &$1, &$7, 3, $9.r0);
3167 | HALF_REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK
3170 return yyerror ("Dreg expected for destination operand");
3171 if (!IS_PREG ($5) || !IS_PREG ($7))
3172 return yyerror ("Preg expected in address");
3174 notethat ("LDSTpmod: dregs_half = W [ pregs ++ pregs ]\n");
3175 $$ = LDSTPMOD (&$5, &$1, &$7, 1 + IS_H ($1), 0);
3178 | LBRACK REG post_op RBRACK ASSIGN REG
3180 if (!IS_IREG ($2) && !IS_PREG ($2))
3181 return yyerror ("Ireg or Preg expected in address");
3182 else if (IS_IREG ($2) && !IS_DREG ($6))
3183 return yyerror ("Dreg expected for source operand");
3184 else if (IS_PREG ($2) && !IS_DREG ($6) && !IS_PREG ($6))
3185 return yyerror ("Dreg or Preg expected for source operand");
3189 notethat ("dspLDST: [ iregs <post_op> ] = dregs\n");
3190 $$ = DSPLDST(&$2, 0, &$6, $3.x0, 1);
3192 else if (IS_DREG ($6))
3194 notethat ("LDST: [ pregs <post_op> ] = dregs\n");
3195 $$ = LDST (&$2, &$6, $3.x0, 0, 0, 1);
3199 notethat ("LDST: [ pregs <post_op> ] = pregs\n");
3200 $$ = LDST (&$2, &$6, $3.x0, 0, 1, 1);
3204 | LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN REG
3207 return yyerror ("Dreg expected for source operand");
3209 if (IS_IREG ($2) && IS_MREG ($4))
3211 notethat ("dspLDST: [ iregs ++ mregs ] = dregs\n");
3212 $$ = DSPLDST(&$2, $4.regno & CODE_MASK, &$7, 3, 1);
3214 else if (IS_PREG ($2) && IS_PREG ($4))
3216 notethat ("LDSTpmod: [ pregs ++ pregs ] = dregs\n");
3217 $$ = LDSTPMOD (&$2, &$7, &$4, 0, 1);
3220 return yyerror ("Preg ++ Preg or Ireg ++ Mreg expected in address");
3223 | W LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN HALF_REG
3226 return yyerror ("Dreg expected for source operand");
3228 if (IS_PREG ($3) && IS_PREG ($5))
3230 notethat ("LDSTpmod: W [ pregs ++ pregs ] = dregs_half\n");
3231 $$ = LDSTPMOD (&$3, &$8, &$5, 1 + IS_H ($8), 1);
3234 return yyerror ("Preg ++ Preg expected in address");
3237 | REG ASSIGN B LBRACK REG plus_minus expr RBRACK xpmod
3239 Expr_Node *tmp = $7;
3241 return yyerror ("Dreg expected for destination operand");
3243 return yyerror ("Preg expected in address");
3246 tmp = unary (Expr_Op_Type_NEG, tmp);
3249 return yyerror ("Plain symbol used as offset");
3251 if (in_range_p (tmp, -32768, 32767, 0))
3253 notethat ("LDSTidxI: dregs = B [ pregs + imm16 ] (%c)\n",
3255 $$ = LDSTIDXI (&$5, &$1, 0, 2, $9.r0, tmp);
3258 return yyerror ("Displacement out of range");
3261 | REG ASSIGN B LBRACK REG post_op RBRACK xpmod
3264 return yyerror ("Dreg expected for destination operand");
3266 return yyerror ("Preg expected in address");
3268 notethat ("LDST: dregs = B [ pregs <post_op> ] (%c)\n",
3270 $$ = LDST (&$5, &$1, $6.x0, 2, $8.r0, 0);
3273 | REG ASSIGN LBRACK REG _PLUS_PLUS REG RBRACK
3276 return yyerror ("Dreg expected for destination operand");
3278 if (IS_IREG ($4) && IS_MREG ($6))
3280 notethat ("dspLDST: dregs = [ iregs ++ mregs ]\n");
3281 $$ = DSPLDST(&$4, $6.regno & CODE_MASK, &$1, 3, 0);
3283 else if (IS_PREG ($4) && IS_PREG ($6))
3285 notethat ("LDSTpmod: dregs = [ pregs ++ pregs ]\n");
3286 $$ = LDSTPMOD (&$4, &$1, &$6, 0, 0);
3289 return yyerror ("Preg ++ Preg or Ireg ++ Mreg expected in address");
3292 | REG ASSIGN LBRACK REG plus_minus got_or_expr RBRACK
3294 Expr_Node *tmp = $6;
3295 int ispreg = IS_PREG ($1);
3296 int isgot = IS_RELOC($6);
3299 return yyerror ("Preg expected in address");
3301 if (!IS_DREG ($1) && !ispreg)
3302 return yyerror ("Dreg or Preg expected for destination operand");
3304 if (tmp->type == Expr_Node_Reloc
3305 && strcmp (tmp->value.s_value,
3306 "_current_shared_library_p5_offset_") != 0)
3307 return yyerror ("Plain symbol used as offset");
3310 tmp = unary (Expr_Op_Type_NEG, tmp);
3314 notethat ("LDSTidxI: dpregs = [ pregs + sym@got ]\n");
3315 $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1 : 0, tmp);
3317 else if (in_range_p (tmp, 0, 63, 3))
3319 notethat ("LDSTii: dpregs = [ pregs + uimm7m4 ]\n");
3320 $$ = LDSTII (&$4, &$1, tmp, 0, ispreg ? 3 : 0);
3322 else if ($4.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
3324 notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
3325 tmp = unary (Expr_Op_Type_NEG, tmp);
3326 $$ = LDSTIIFP (tmp, &$1, 0);
3328 else if (in_range_p (tmp, -131072, 131071, 3))
3330 notethat ("LDSTidxI: dpregs = [ pregs + imm18m4 ]\n");
3331 $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1 : 0, tmp);
3335 return yyerror ("Displacement out of range");
3338 | REG ASSIGN LBRACK REG post_op RBRACK
3340 if (!IS_IREG ($4) && !IS_PREG ($4))
3341 return yyerror ("Ireg or Preg expected in address");
3342 else if (IS_IREG ($4) && !IS_DREG ($1))
3343 return yyerror ("Dreg expected in destination operand");
3344 else if (IS_PREG ($4) && !IS_DREG ($1) && !IS_PREG ($1)
3345 && ($4.regno != REG_SP || !IS_ALLREG ($1) || $5.x0 != 0))
3346 return yyerror ("Dreg or Preg expected in destination operand");
3350 notethat ("dspLDST: dregs = [ iregs <post_op> ]\n");
3351 $$ = DSPLDST (&$4, 0, &$1, $5.x0, 0);
3353 else if (IS_DREG ($1))
3355 notethat ("LDST: dregs = [ pregs <post_op> ]\n");
3356 $$ = LDST (&$4, &$1, $5.x0, 0, 0, 0);
3358 else if (IS_PREG ($1))
3360 if (REG_SAME ($1, $4) && $5.x0 != 2)
3361 return yyerror ("Pregs can't be same");
3363 notethat ("LDST: pregs = [ pregs <post_op> ]\n");
3364 $$ = LDST (&$4, &$1, $5.x0, 0, 1, 0);
3368 notethat ("PushPopReg: allregs = [ SP ++ ]\n");
3369 $$ = PUSHPOPREG (&$1, 0);
3374 /* PushPopMultiple. */
3375 | reg_with_predec ASSIGN LPAREN REG COLON expr COMMA REG COLON expr RPAREN
3377 if ($1.regno != REG_SP)
3378 yyerror ("Stack Pointer expected");
3379 if ($4.regno == REG_R7
3380 && IN_RANGE ($6, 0, 7)
3381 && $8.regno == REG_P5
3382 && IN_RANGE ($10, 0, 5))
3384 notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim , P5 : reglim )\n");
3385 $$ = PUSHPOPMULTIPLE (imm5 ($6), imm5 ($10), 1, 1, 1);
3388 return yyerror ("Bad register for PushPopMultiple");
3391 | reg_with_predec ASSIGN LPAREN REG COLON expr RPAREN
3393 if ($1.regno != REG_SP)
3394 yyerror ("Stack Pointer expected");
3396 if ($4.regno == REG_R7 && IN_RANGE ($6, 0, 7))
3398 notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim )\n");
3399 $$ = PUSHPOPMULTIPLE (imm5 ($6), 0, 1, 0, 1);
3401 else if ($4.regno == REG_P5 && IN_RANGE ($6, 0, 6))
3403 notethat ("PushPopMultiple: [ -- SP ] = (P5 : reglim )\n");
3404 $$ = PUSHPOPMULTIPLE (0, imm5 ($6), 0, 1, 1);
3407 return yyerror ("Bad register for PushPopMultiple");
3410 | LPAREN REG COLON expr COMMA REG COLON expr RPAREN ASSIGN reg_with_postinc
3412 if ($11.regno != REG_SP)
3413 yyerror ("Stack Pointer expected");
3414 if ($2.regno == REG_R7 && (IN_RANGE ($4, 0, 7))
3415 && $6.regno == REG_P5 && (IN_RANGE ($8, 0, 6)))
3417 notethat ("PushPopMultiple: (R7 : reglim , P5 : reglim ) = [ SP ++ ]\n");
3418 $$ = PUSHPOPMULTIPLE (imm5 ($4), imm5 ($8), 1, 1, 0);
3421 return yyerror ("Bad register range for PushPopMultiple");
3424 | LPAREN REG COLON expr RPAREN ASSIGN reg_with_postinc
3426 if ($7.regno != REG_SP)
3427 yyerror ("Stack Pointer expected");
3429 if ($2.regno == REG_R7 && IN_RANGE ($4, 0, 7))
3431 notethat ("PushPopMultiple: (R7 : reglim ) = [ SP ++ ]\n");
3432 $$ = PUSHPOPMULTIPLE (imm5 ($4), 0, 1, 0, 0);
3434 else if ($2.regno == REG_P5 && IN_RANGE ($4, 0, 6))
3436 notethat ("PushPopMultiple: (P5 : reglim ) = [ SP ++ ]\n");
3437 $$ = PUSHPOPMULTIPLE (0, imm5 ($4), 0, 1, 0);
3440 return yyerror ("Bad register range for PushPopMultiple");
3443 | reg_with_predec ASSIGN REG
3445 if ($1.regno != REG_SP)
3446 yyerror ("Stack Pointer expected");
3450 notethat ("PushPopReg: [ -- SP ] = allregs\n");
3451 $$ = PUSHPOPREG (&$3, 1);
3454 return yyerror ("Bad register for PushPopReg");
3461 if (IS_URANGE (16, $2, 0, 4))
3462 $$ = LINKAGE (0, uimm16s4 ($2));
3464 return yyerror ("Bad constant for LINK");
3469 notethat ("linkage: UNLINK\n");
3470 $$ = LINKAGE (1, 0);
3476 | LSETUP LPAREN expr COMMA expr RPAREN REG
3478 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5) && IS_CREG ($7))
3480 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters\n");
3481 $$ = LOOPSETUP ($3, &$7, 0, $5, 0);
3484 return yyerror ("Bad register or values for LSETUP");
3487 | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG
3489 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
3490 && IS_PREG ($9) && IS_CREG ($7))
3492 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs\n");
3493 $$ = LOOPSETUP ($3, &$7, 1, $5, &$9);
3496 return yyerror ("Bad register or values for LSETUP");
3499 | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG GREATER_GREATER expr
3501 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
3502 && IS_PREG ($9) && IS_CREG ($7)
3503 && EXPR_VALUE ($11) == 1)
3505 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs >> 1\n");
3506 $$ = LOOPSETUP ($3, &$7, 3, $5, &$9);
3509 return yyerror ("Bad register or values for LSETUP");
3516 return yyerror ("Invalid expression in loop statement");
3518 return yyerror ("Invalid loop counter register");
3519 $$ = bfin_gen_loop ($2, &$3, 0, 0);
3521 | LOOP expr REG ASSIGN REG
3523 if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3))
3525 notethat ("Loop: LOOP expr counters = pregs\n");
3526 $$ = bfin_gen_loop ($2, &$3, 1, &$5);
3529 return yyerror ("Bad register or values for LOOP");
3531 | LOOP expr REG ASSIGN REG GREATER_GREATER expr
3533 if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3) && EXPR_VALUE ($7) == 1)
3535 notethat ("Loop: LOOP expr counters = pregs >> 1\n");
3536 $$ = bfin_gen_loop ($2, &$3, 3, &$5);
3539 return yyerror ("Bad register or values for LOOP");
3546 return yyerror ("Invalid expression in LOOP_BEGIN statement");
3548 bfin_loop_beginend ($2, 1);
3556 return yyerror ("Invalid expression in LOOP_END statement");
3558 bfin_loop_beginend ($2, 0);
3566 notethat ("psedoDEBUG: ABORT\n");
3567 $$ = bfin_gen_pseudodbg (3, 3, 0);
3572 notethat ("pseudoDEBUG: DBG\n");
3573 $$ = bfin_gen_pseudodbg (3, 7, 0);
3577 notethat ("pseudoDEBUG: DBG REG_A\n");
3578 $$ = bfin_gen_pseudodbg (3, IS_A1 ($2), 0);
3582 notethat ("pseudoDEBUG: DBG allregs\n");
3583 $$ = bfin_gen_pseudodbg (0, $2.regno & CODE_MASK, ($2.regno & CLASS_MASK) >> 4);
3586 | DBGCMPLX LPAREN REG RPAREN
3589 return yyerror ("Dregs expected");
3590 notethat ("pseudoDEBUG: DBGCMPLX (dregs )\n");
3591 $$ = bfin_gen_pseudodbg (3, 6, ($3.regno & CODE_MASK) >> 4);
3596 notethat ("psedoDEBUG: DBGHALT\n");
3597 $$ = bfin_gen_pseudodbg (3, 5, 0);
3602 notethat ("psedoDEBUG: HLT\n");
3603 $$ = bfin_gen_pseudodbg (3, 4, 0);
3606 | DBGA LPAREN HALF_REG COMMA expr RPAREN
3608 notethat ("pseudodbg_assert: DBGA (regs_lo/hi , uimm16 )\n");
3609 $$ = bfin_gen_pseudodbg_assert (IS_H ($3), &$3, uimm16 ($5));
3612 | DBGAH LPAREN REG COMMA expr RPAREN
3614 notethat ("pseudodbg_assert: DBGAH (regs , uimm16 )\n");
3615 $$ = bfin_gen_pseudodbg_assert (3, &$3, uimm16 ($5));
3618 | DBGAL LPAREN REG COMMA expr RPAREN
3620 notethat ("psedodbg_assert: DBGAL (regs , uimm16 )\n");
3621 $$ = bfin_gen_pseudodbg_assert (2, &$3, uimm16 ($5));
3626 if (!IS_UIMM ($2, 8))
3627 return yyerror ("Constant out of range");
3628 notethat ("psedodbg_assert: OUTC uimm8\n");
3629 $$ = bfin_gen_pseudochr (uimm8 ($2));
3635 return yyerror ("Dregs expected");
3636 notethat ("psedodbg_assert: OUTC dreg\n");
3637 $$ = bfin_gen_pseudodbg (2, $2.regno & CODE_MASK, 0);
3644 /* Register rules. */
3646 REG_A: REG_A_DOUBLE_ZERO
3664 | LPAREN M COMMA MMOD RPAREN
3669 | LPAREN MMOD COMMA M RPAREN
3674 | LPAREN MMOD RPAREN
3686 asr_asl: LPAREN ASL RPAREN
3767 | LPAREN asr_asl_0 RPAREN
3779 | LPAREN asr_asl_0 COMMA sco RPAREN
3785 | LPAREN sco COMMA asr_asl_0 RPAREN
3845 | LPAREN V COMMA S RPAREN
3850 | LPAREN S COMMA V RPAREN
3912 | LPAREN MMOD RPAREN
3915 return yyerror ("Bad modifier");
3919 | LPAREN MMOD COMMA R RPAREN
3922 return yyerror ("Bad modifier");
3926 | LPAREN R COMMA MMOD RPAREN
3929 return yyerror ("Bad modifier");
3956 | LPAREN MMOD RPAREN
3961 return yyerror ("Only (W32) allowed");
3969 | LPAREN MMOD RPAREN
3974 return yyerror ("(IU) expected");
3978 reg_with_predec: LBRACK _MINUS_MINUS REG RBRACK
3984 reg_with_postinc: LBRACK REG _PLUS_PLUS RBRACK
4036 $$.r0 = 1; /* HL. */
4039 $$.aop = 0; /* aop. */
4044 $$.r0 = 1; /* HL. */
4047 $$.aop = 1; /* aop. */
4050 | LPAREN RNDL RPAREN
4052 $$.r0 = 0; /* HL. */
4055 $$.aop = 0; /* aop. */
4060 $$.r0 = 0; /* HL. */
4066 | LPAREN RNDH COMMA R RPAREN
4068 $$.r0 = 1; /* HL. */
4071 $$.aop = 0; /* aop. */
4073 | LPAREN TH COMMA R RPAREN
4075 $$.r0 = 1; /* HL. */
4078 $$.aop = 1; /* aop. */
4080 | LPAREN RNDL COMMA R RPAREN
4082 $$.r0 = 0; /* HL. */
4085 $$.aop = 0; /* aop. */
4088 | LPAREN TL COMMA R RPAREN
4090 $$.r0 = 0; /* HL. */
4093 $$.aop = 1; /* aop. */
4101 $$.x0 = 0; /* HL. */
4106 $$.x0 = 1; /* HL. */
4108 | LPAREN LO COMMA R RPAREN
4111 $$.x0 = 0; /* HL. */
4113 | LPAREN HI COMMA R RPAREN
4116 $$.x0 = 1; /* HL. */
4134 /* Assignments, Macfuncs. */
4160 if (IS_A1 ($3) && IS_EVEN ($1))
4161 return yyerror ("Cannot move A1 to even register");
4162 else if (!IS_A1 ($3) && !IS_EVEN ($1))
4163 return yyerror ("Cannot move A0 to odd register");
4179 | REG ASSIGN LPAREN a_macfunc RPAREN
4181 if ($4.n && IS_EVEN ($1))
4182 return yyerror ("Cannot move A1 to even register");
4183 else if (!$4.n && !IS_EVEN ($1))
4184 return yyerror ("Cannot move A0 to odd register");
4192 | HALF_REG ASSIGN LPAREN a_macfunc RPAREN
4194 if ($4.n && !IS_H ($1))
4195 return yyerror ("Cannot move A1 to low half of register");
4196 else if (!$4.n && IS_H ($1))
4197 return yyerror ("Cannot move A0 to high half of register");
4205 | HALF_REG ASSIGN REG_A
4207 if (IS_A1 ($3) && !IS_H ($1))
4208 return yyerror ("Cannot move A1 to low half of register");
4209 else if (!IS_A1 ($3) && IS_H ($1))
4210 return yyerror ("Cannot move A0 to high half of register");
4223 a_assign multiply_halfregs
4230 | a_plusassign multiply_halfregs
4237 | a_minusassign multiply_halfregs
4247 HALF_REG STAR HALF_REG
4249 if (IS_DREG ($1) && IS_DREG ($3))
4255 return yyerror ("Dregs expected");
4279 CCREG cc_op STATUS_REG
4291 | STATUS_REG cc_op CCREG
4305 /* Expressions and Symbols. */
4309 Expr_Node_Value val;
4310 val.s_value = S_GET_NAME($1);
4311 $$ = Expr_Node_Create (Expr_Node_Reloc, val, NULL, NULL);
4317 { $$ = BFD_RELOC_BFIN_GOT; }
4319 { $$ = BFD_RELOC_BFIN_GOT17M4; }
4321 { $$ = BFD_RELOC_BFIN_FUNCDESC_GOT17M4; }
4324 got: symbol AT any_gotrel
4326 Expr_Node_Value val;
4328 $$ = Expr_Node_Create (Expr_Node_GOT_Reloc, val, $1, NULL);
4351 Expr_Node_Value val;
4353 $$ = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
4359 | LPAREN expr_1 RPAREN
4365 $$ = unary (Expr_Op_Type_COMP, $2);
4367 | MINUS expr_1 %prec TILDA
4369 $$ = unary (Expr_Op_Type_NEG, $2);
4379 expr_1: expr_1 STAR expr_1
4381 $$ = binary (Expr_Op_Type_Mult, $1, $3);
4383 | expr_1 SLASH expr_1
4385 $$ = binary (Expr_Op_Type_Div, $1, $3);
4387 | expr_1 PERCENT expr_1
4389 $$ = binary (Expr_Op_Type_Mod, $1, $3);
4391 | expr_1 PLUS expr_1
4393 $$ = binary (Expr_Op_Type_Add, $1, $3);
4395 | expr_1 MINUS expr_1
4397 $$ = binary (Expr_Op_Type_Sub, $1, $3);
4399 | expr_1 LESS_LESS expr_1
4401 $$ = binary (Expr_Op_Type_Lshift, $1, $3);
4403 | expr_1 GREATER_GREATER expr_1
4405 $$ = binary (Expr_Op_Type_Rshift, $1, $3);
4407 | expr_1 AMPERSAND expr_1
4409 $$ = binary (Expr_Op_Type_BAND, $1, $3);
4411 | expr_1 CARET expr_1
4413 $$ = binary (Expr_Op_Type_LOR, $1, $3);
4417 $$ = binary (Expr_Op_Type_BOR, $1, $3);
4429 mkexpr (int x, SYMBOL_T s)
4431 EXPR_T e = (EXPR_T) ALLOCATE (sizeof (struct expression_cell));
4438 value_match (Expr_Node *exp, int sz, int sign, int mul, int issigned)
4440 int umax = (1 << sz) - 1;
4441 int min = -1 << (sz - 1);
4442 int max = (1 << (sz - 1)) - 1;
4444 int v = (EXPR_VALUE (exp)) & 0xffffffff;
4448 error ("%s:%d: Value Error -- Must align to %d\n", __FILE__, __LINE__, mul);
4459 if (v >= min && v <= max) return 1;
4462 fprintf(stderr, "signed value %lx out of range\n", v * mul);
4466 if (v <= umax && v >= 0)
4469 fprintf(stderr, "unsigned value %lx out of range\n", v * mul);
4474 /* Return the expression structure that allows symbol operations.
4475 If the left and right children are constants, do the operation. */
4477 binary (Expr_Op_Type op, Expr_Node *x, Expr_Node *y)
4479 Expr_Node_Value val;
4481 if (x->type == Expr_Node_Constant && y->type == Expr_Node_Constant)
4485 case Expr_Op_Type_Add:
4486 x->value.i_value += y->value.i_value;
4488 case Expr_Op_Type_Sub:
4489 x->value.i_value -= y->value.i_value;
4491 case Expr_Op_Type_Mult:
4492 x->value.i_value *= y->value.i_value;
4494 case Expr_Op_Type_Div:
4495 if (y->value.i_value == 0)
4496 error ("Illegal Expression: Division by zero.");
4498 x->value.i_value /= y->value.i_value;
4500 case Expr_Op_Type_Mod:
4501 x->value.i_value %= y->value.i_value;
4503 case Expr_Op_Type_Lshift:
4504 x->value.i_value <<= y->value.i_value;
4506 case Expr_Op_Type_Rshift:
4507 x->value.i_value >>= y->value.i_value;
4509 case Expr_Op_Type_BAND:
4510 x->value.i_value &= y->value.i_value;
4512 case Expr_Op_Type_BOR:
4513 x->value.i_value |= y->value.i_value;
4515 case Expr_Op_Type_BXOR:
4516 x->value.i_value ^= y->value.i_value;
4518 case Expr_Op_Type_LAND:
4519 x->value.i_value = x->value.i_value && y->value.i_value;
4521 case Expr_Op_Type_LOR:
4522 x->value.i_value = x->value.i_value || y->value.i_value;
4526 error ("%s:%d: Internal assembler error\n", __FILE__, __LINE__);
4530 /* Canonicalize order to EXPR OP CONSTANT. */
4531 if (x->type == Expr_Node_Constant)
4537 /* Canonicalize subtraction of const to addition of negated const. */
4538 if (op == Expr_Op_Type_Sub && y->type == Expr_Node_Constant)
4540 op = Expr_Op_Type_Add;
4541 y->value.i_value = -y->value.i_value;
4543 if (y->type == Expr_Node_Constant && x->type == Expr_Node_Binop
4544 && x->Right_Child->type == Expr_Node_Constant)
4546 if (op == x->value.op_value && x->value.op_value == Expr_Op_Type_Add)
4548 x->Right_Child->value.i_value += y->value.i_value;
4553 /* Create a new expression structure. */
4555 return Expr_Node_Create (Expr_Node_Binop, val, x, y);
4559 unary (Expr_Op_Type op, Expr_Node *x)
4561 if (x->type == Expr_Node_Constant)
4565 case Expr_Op_Type_NEG:
4566 x->value.i_value = -x->value.i_value;
4568 case Expr_Op_Type_COMP:
4569 x->value.i_value = ~x->value.i_value;
4572 error ("%s:%d: Internal assembler error\n", __FILE__, __LINE__);
4578 /* Create a new expression structure. */
4579 Expr_Node_Value val;
4581 return Expr_Node_Create (Expr_Node_Unop, val, x, NULL);
4585 int debug_codeselection = 0;
4587 notethat (char *format, ...)
4590 va_start (ap, format);
4591 if (debug_codeselection)
4593 vfprintf (errorf, format, ap);
4599 main (int argc, char **argv)