1 /* bfin-parse.y ADI Blackfin parser
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 2, 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
27 #include "bfin-aux.h" // opcode generating auxiliaries
29 #include "elf/common.h"
32 #define DSP32ALU(aopcde, HL, dst1, dst0, src0, src1, s, x, aop) \
33 bfin_gen_dsp32alu (HL, aopcde, aop, s, x, dst0, dst1, src0, src1)
35 #define DSP32MAC(op1, MM, mmod, w1, P, h01, h11, h00, h10, dst, op0, src0, src1, w0) \
36 bfin_gen_dsp32mac (op1, MM, mmod, w1, P, h01, h11, h00, h10, op0, \
39 #define DSP32MULT(op1, MM, mmod, w1, P, h01, h11, h00, h10, dst, op0, src0, src1, w0) \
40 bfin_gen_dsp32mult (op1, MM, mmod, w1, P, h01, h11, h00, h10, op0, \
43 #define DSP32SHIFT(sopcde, dst0, src0, src1, sop, hls) \
44 bfin_gen_dsp32shift (sopcde, dst0, src0, src1, sop, hls)
46 #define DSP32SHIFTIMM(sopcde, dst0, immag, src1, sop, hls) \
47 bfin_gen_dsp32shiftimm (sopcde, dst0, immag, src1, sop, hls)
49 #define LDIMMHALF_R(reg, h, s, z, hword) \
50 bfin_gen_ldimmhalf (reg, h, s, z, hword, 1)
52 #define LDIMMHALF_R5(reg, h, s, z, hword) \
53 bfin_gen_ldimmhalf (reg, h, s, z, hword, 2)
55 #define LDSTIDXI(ptr, reg, w, sz, z, offset) \
56 bfin_gen_ldstidxi (ptr, reg, w, sz, z, offset)
58 #define LDST(ptr, reg, aop, sz, z, w) \
59 bfin_gen_ldst (ptr, reg, aop, sz, z, w)
61 #define LDSTII(ptr, reg, offset, w, op) \
62 bfin_gen_ldstii (ptr, reg, offset, w, op)
64 #define DSPLDST(i, m, reg, aop, w) \
65 bfin_gen_dspldst (i, reg, aop, w, m)
67 #define LDSTPMOD(ptr, reg, idx, aop, w) \
68 bfin_gen_ldstpmod (ptr, reg, aop, w, idx)
70 #define LDSTIIFP(offset, reg, w) \
71 bfin_gen_ldstiifp (reg, offset, w)
73 #define LOGI2OP(dst, src, opc) \
74 bfin_gen_logi2op (opc, src, dst.regno & CODE_MASK)
76 #define ALU2OP(dst, src, opc) \
77 bfin_gen_alu2op (dst, src, opc)
79 #define BRCC(t, b, offset) \
80 bfin_gen_brcc (t, b, offset)
82 #define UJUMP(offset) \
83 bfin_gen_ujump (offset)
85 #define PROGCTRL(prgfunc, poprnd) \
86 bfin_gen_progctrl (prgfunc, poprnd)
88 #define PUSHPOPMULTIPLE(dr, pr, d, p, w) \
89 bfin_gen_pushpopmultiple (dr, pr, d, p, w)
91 #define PUSHPOPREG(reg, w) \
92 bfin_gen_pushpopreg (reg, w)
94 #define CALLA(addr, s) \
95 bfin_gen_calla (addr, s)
97 #define LINKAGE(r, framesize) \
98 bfin_gen_linkage (r, framesize)
100 #define COMPI2OPD(dst, src, op) \
101 bfin_gen_compi2opd (dst, src, op)
103 #define COMPI2OPP(dst, src, op) \
104 bfin_gen_compi2opp (dst, src, op)
106 #define DAGMODIK(i, op) \
107 bfin_gen_dagmodik (i, op)
109 #define DAGMODIM(i, m, op, br) \
110 bfin_gen_dagmodim (i, m, op, br)
112 #define COMP3OP(dst, src0, src1, opc) \
113 bfin_gen_comp3op (src0, src1, dst, opc)
115 #define PTR2OP(dst, src, opc) \
116 bfin_gen_ptr2op (dst, src, opc)
118 #define CCFLAG(x, y, opc, i, g) \
119 bfin_gen_ccflag (x, y, opc, i, g)
121 #define CCMV(src, dst, t) \
122 bfin_gen_ccmv (src, dst, t)
124 #define CACTRL(reg, a, op) \
125 bfin_gen_cactrl (reg, a, op)
127 #define LOOPSETUP(soffset, c, rop, eoffset, reg) \
128 bfin_gen_loopsetup (soffset, c, rop, eoffset, reg)
130 #define HL2(r1, r0) (IS_H (r1) << 1 | IS_H (r0))
131 #define IS_RANGE(bits, expr, sign, mul) \
132 value_match(expr, bits, sign, mul, 1)
133 #define IS_URANGE(bits, expr, sign, mul) \
134 value_match(expr, bits, sign, mul, 0)
135 #define IS_CONST(expr) (expr->type == Expr_Node_Constant)
136 #define IS_RELOC(expr) (expr->type != Expr_Node_Constant)
137 #define IS_IMM(expr, bits) value_match (expr, bits, 0, 1, 1)
138 #define IS_UIMM(expr, bits) value_match (expr, bits, 0, 1, 0)
140 #define IS_PCREL4(expr) \
141 (value_match (expr, 4, 0, 2, 0))
143 #define IS_LPPCREL10(expr) \
144 (value_match (expr, 10, 0, 2, 0))
146 #define IS_PCREL10(expr) \
147 (value_match (expr, 10, 0, 2, 1))
149 #define IS_PCREL12(expr) \
150 (value_match (expr, 12, 0, 2, 1))
152 #define IS_PCREL24(expr) \
153 (value_match (expr, 24, 0, 2, 1))
156 static int value_match (Expr_Node *expr, int sz, int sign, int mul, int issigned);
161 static Expr_Node *binary (Expr_Op_Type, Expr_Node *, Expr_Node *);
162 static Expr_Node *unary (Expr_Op_Type, Expr_Node *);
164 static void notethat (char *format, ...);
166 char *current_inputline;
168 int yyerror (char *msg);
170 void error (char *format, ...)
175 va_start (ap, format);
176 vsprintf (buffer, format, ap);
188 else if (yytext[0] != ';')
189 error ("%s. Input text was %s.", msg, yytext);
197 in_range_p (Expr_Node *expr, int from, int to, unsigned int mask)
199 int val = EXPR_VALUE (expr);
200 if (expr->type != Expr_Node_Constant)
202 if (val < from || val > to)
204 return (val & mask) == 0;
207 extern int yylex (void);
209 #define imm3(x) EXPR_VALUE (x)
210 #define imm4(x) EXPR_VALUE (x)
211 #define uimm4(x) EXPR_VALUE (x)
212 #define imm5(x) EXPR_VALUE (x)
213 #define uimm5(x) EXPR_VALUE (x)
214 #define imm6(x) EXPR_VALUE (x)
215 #define imm7(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 neg_value (Expr_Node *expr)
229 expr->value.i_value = -expr->value.i_value;
233 valid_dreg_pair (Register *reg1, Expr_Node *reg2)
235 if (!IS_DREG (*reg1))
237 yyerror ("Dregs expected");
241 if (reg1->regno != 1 && reg1->regno != 3)
243 yyerror ("Bad register pair");
247 if (imm7 (reg2) != reg1->regno - 1)
249 yyerror ("Bad register pair");
258 check_multiply_halfregs (Macfunc *aa, Macfunc *ab)
260 if ((!REG_EQUAL (aa->s0, ab->s0) && !REG_EQUAL (aa->s0, ab->s1))
261 || (!REG_EQUAL (aa->s1, ab->s1) && !REG_EQUAL (aa->s1, ab->s0)))
262 return yyerror ("Source multiplication register mismatch");
268 /* Check (vector) mac funcs and ops. */
271 check_macfuncs (Macfunc *aa, Opt_mode *opa,
272 Macfunc *ab, Opt_mode *opb)
274 /* Variables for swapping. */
278 /* If a0macfunc comes before a1macfunc, swap them. */
282 /* (M) is not allowed here. */
284 return yyerror ("(M) not allowed with A0MAC");
286 return yyerror ("Vector AxMACs can't be same");
288 mtmp = *aa; *aa = *ab; *ab = mtmp;
289 otmp = *opa; *opa = *opb; *opb = otmp;
294 return yyerror ("(M) not allowed with A0MAC");
296 return yyerror ("Bad opt mode");
298 return yyerror ("Vector AxMACs can't be same");
301 /* If both ops are one of 0, 1, or 2, we have multiply_halfregs in both
302 assignment_or_macfuncs. */
303 if (aa->op < 3 && aa->op >=0
304 && ab->op < 3 && ab->op >= 0)
306 if (check_multiply_halfregs (aa, ab) < 0)
311 /* Only one of the assign_macfuncs has a half reg multiply
312 Evil trick: Just 'OR' their source register codes:
313 We can do that, because we know they were initialized to 0
314 in the rules that don't use multiply_halfregs. */
315 aa->s0.regno |= (ab->s0.regno & CODE_MASK);
316 aa->s1.regno |= (ab->s1.regno & CODE_MASK);
319 if (aa->w == ab->w && aa->P != ab->P)
321 return yyerror ("macfuncs must differ");
322 if (aa->w && (aa->dst.regno - ab->dst.regno != 1))
323 return yyerror ("Destination Dregs must differ by one");
325 /* We assign to full regs, thus obey even/odd rules. */
326 else if ((aa->w && aa->P && IS_EVEN (aa->dst))
327 || (ab->w && ab->P && !IS_EVEN (ab->dst)))
328 return yyerror ("Even/Odd register assignment mismatch");
329 /* We assign to half regs, thus obey hi/low rules. */
330 else if ( (aa->w && !aa->P && !IS_H (aa->dst))
331 || (ab->w && !aa->P && IS_H (ab->dst)))
332 return yyerror ("High/Low register assignment mismatch");
334 /* Make sure first macfunc has got both P flags ORed. */
337 /* Make sure mod flags get ORed, too. */
338 opb->mod |= opa->mod;
344 is_group1 (INSTR_T x)
346 /* Group1 is dpsLDST, LDSTpmod, LDST, LDSTiiFP, LDSTii. */
347 if ((x->value & 0xc000) == 0x8000 || (x->value == 0x0000))
354 is_group2 (INSTR_T x)
356 if ((((x->value & 0xfc00) == 0x9c00) /* dspLDST. */
357 && !((x->value & 0xfde0) == 0x9c60) /* dagMODim. */
358 && !((x->value & 0xfde0) == 0x9ce0) /* dagMODim with bit rev. */
359 && !((x->value & 0xfde0) == 0x9d60)) /* pick dagMODik. */
360 || (x->value == 0x0000))
374 struct { int r0; int s0; int x0; int aop; } modcodes;
375 struct { int r0; } r0;
382 /* Vector Specific. */
383 %token BYTEOP16P BYTEOP16M
384 %token BYTEOP1P BYTEOP2P BYTEOP2M BYTEOP3P
385 %token BYTEUNPACK BYTEPACK
388 %token ALIGN8 ALIGN16 ALIGN24
390 %token EXTRACT DEPOSIT EXPADJ SEARCH
391 %token ONES SIGN SIGNBITS
399 %token CCREG BYTE_DREG
400 %token REG_A_DOUBLE_ZERO REG_A_DOUBLE_ONE
401 %token A_ZERO_DOT_L A_ZERO_DOT_H A_ONE_DOT_L A_ONE_DOT_H
406 %token RTI RTS RTX RTN RTE
417 %token JUMP JUMP_DOT_S JUMP_DOT_L
424 %token NOT TILDA BANG
430 %token MINUS PLUS STAR SLASH
434 %token _PLUS_BAR_PLUS _PLUS_BAR_MINUS _MINUS_BAR_PLUS _MINUS_BAR_MINUS
435 %token _MINUS_MINUS _PLUS_PLUS
437 /* Shift/rotate ops. */
438 %token SHIFT LSHIFT ASHIFT BXORSHIFT
439 %token _GREATER_GREATER_GREATER_THAN_ASSIGN
441 %token LESS_LESS GREATER_GREATER
442 %token _GREATER_GREATER_GREATER
443 %token _LESS_LESS_ASSIGN _GREATER_GREATER_ASSIGN
446 /* In place operators. */
447 %token ASSIGN _STAR_ASSIGN
448 %token _BAR_ASSIGN _CARET_ASSIGN _AMPERSAND_ASSIGN
449 %token _MINUS_ASSIGN _PLUS_ASSIGN
451 /* Assignments, comparisons. */
452 %token _ASSIGN_BANG _LESS_THAN_ASSIGN _ASSIGN_ASSIGN
457 %token FLUSHINV FLUSH
458 %token IFLUSH PREFETCH
475 %token R RND RNDL RNDH RND12 RND20
480 %token BITTGL BITCLR BITSET BITTST BITMUX
483 %token DBGAL DBGAH DBGHALT DBG DBGA DBGCMPLX
485 /* Semantic auxiliaries. */
488 %token COLON SEMICOLON
489 %token RPAREN LPAREN LBRACK RBRACK
493 %token GOT GOT17M4 FUNCDESC_GOT17M4
503 %type <modcodes> byteop_mod
505 %type <reg> a_plusassign
506 %type <reg> a_minusassign
507 %type <macfunc> multiply_halfregs
508 %type <macfunc> assign_macfunc
509 %type <macfunc> a_macfunc
513 %type <modcodes> vsmod
514 %type <modcodes> ccstat
517 %type <reg> reg_with_postinc
518 %type <reg> reg_with_predec
522 %type <symbol> SYMBOL
525 %type <reg> BYTE_DREG
526 %type <reg> REG_A_DOUBLE_ZERO
527 %type <reg> REG_A_DOUBLE_ONE
529 %type <reg> STATUS_REG
533 %type <modcodes> smod
534 %type <modcodes> b3_op
535 %type <modcodes> rnd_op
536 %type <modcodes> post_op
538 %type <r0> iu_or_nothing
539 %type <r0> plus_minus
543 %type <modcodes> amod0
544 %type <modcodes> amod1
545 %type <modcodes> amod2
547 %type <r0> w32_or_nothing
551 %type <expr> got_or_expr
553 %type <value> any_gotrel GOT GOT17M4 FUNCDESC_GOT17M4
555 /* Precedence rules. */
559 %left LESS_LESS GREATER_GREATER
561 %left STAR SLASH PERCENT
572 if (insn == (INSTR_T) 0)
573 return NO_INSN_GENERATED;
574 else if (insn == (INSTR_T) - 1)
575 return SEMANTIC_ERROR;
577 return INSN_GENERATED;
582 /* Parallel instructions. */
583 | asm_1 DOUBLE_BAR asm_1 DOUBLE_BAR asm_1 SEMICOLON
585 if (($1->value & 0xf800) == 0xc000)
587 if (is_group1 ($3) && is_group2 ($5))
588 $$ = bfin_gen_multi_instr ($1, $3, $5);
589 else if (is_group2 ($3) && is_group1 ($5))
590 $$ = bfin_gen_multi_instr ($1, $5, $3);
592 return yyerror ("Wrong 16 bit instructions groups, slot 2 and slot 3 must be 16-bit instrution group");
594 else if (($3->value & 0xf800) == 0xc000)
596 if (is_group1 ($1) && is_group2 ($5))
597 $$ = bfin_gen_multi_instr ($3, $1, $5);
598 else if (is_group2 ($1) && is_group1 ($5))
599 $$ = bfin_gen_multi_instr ($3, $5, $1);
601 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 3 must be 16-bit instrution group");
603 else if (($5->value & 0xf800) == 0xc000)
605 if (is_group1 ($1) && is_group2 ($3))
606 $$ = bfin_gen_multi_instr ($5, $1, $3);
607 else if (is_group2 ($1) && is_group1 ($3))
608 $$ = bfin_gen_multi_instr ($5, $3, $1);
610 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be 16-bit instrution group");
613 error ("\nIllegal Multi Issue Construct, at least any one of the slot must be DSP32 instruction group\n");
616 | asm_1 DOUBLE_BAR asm_1 SEMICOLON
618 if (($1->value & 0xf800) == 0xc000)
621 $$ = bfin_gen_multi_instr ($1, $3, 0);
622 else if (is_group2 ($3))
623 $$ = bfin_gen_multi_instr ($1, 0, $3);
625 return yyerror ("Wrong 16 bit instructions groups, slot 2 must be the 16-bit instruction group");
627 else if (($3->value & 0xf800) == 0xc000)
630 $$ = bfin_gen_multi_instr ($3, $1, 0);
631 else if (is_group2 ($1))
632 $$ = bfin_gen_multi_instr ($3, 0, $1);
634 return yyerror ("Wrong 16 bit instructions groups, slot 1 must be the 16-bit instruction group");
636 else if (is_group1 ($1) && is_group2 ($3))
637 $$ = bfin_gen_multi_instr (0, $1, $3);
638 else if (is_group2 ($1) && is_group1 ($3))
639 $$ = bfin_gen_multi_instr (0, $3, $1);
641 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be the 16-bit instruction group");
656 $$ = DSP32MAC (3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
658 | assign_macfunc opt_mode
662 int h00, h10, h01, h11;
667 return yyerror ("(m) not allowed with a0 unit");
686 $$ = DSP32MAC (op1, $2.MM, $2.mod, w1, $1.P, h01, h11, h00, h10,
687 &$1.dst, op0, &$1.s0, &$1.s1, w0);
693 | assign_macfunc opt_mode COMMA assign_macfunc opt_mode
697 if (check_macfuncs (&$1, &$2, &$4, &$5) < 0)
699 notethat ("assign_macfunc (.), assign_macfunc (.)\n");
706 $$ = DSP32MAC ($1.op, $2.MM, $5.mod, $1.w, $1.P,
707 IS_H ($1.s0), IS_H ($1.s1), IS_H ($4.s0), IS_H ($4.s1),
708 dst, $4.op, &$1.s0, &$1.s1, $4.w);
715 notethat ("dsp32alu: DISALGNEXCPT\n");
716 $$ = DSP32ALU (18, 0, 0, 0, 0, 0, 0, 0, 3);
718 | REG ASSIGN LPAREN a_plusassign REG_A RPAREN
720 if (IS_DREG ($1) && !IS_A1 ($4) && IS_A1 ($5))
722 notethat ("dsp32alu: dregs = ( A0 += A1 )\n");
723 $$ = DSP32ALU (11, 0, 0, &$1, 0, 0, 0, 0, 0);
726 return yyerror ("Register mismatch");
728 | HALF_REG ASSIGN LPAREN a_plusassign REG_A RPAREN
730 if (!IS_A1 ($4) && IS_A1 ($5))
732 notethat ("dsp32alu: dregs_half = ( A0 += A1 )\n");
733 $$ = DSP32ALU (11, IS_H ($1), 0, &$1, 0, 0, 0, 0, 1);
736 return yyerror ("Register mismatch");
738 | A_ZERO_DOT_H ASSIGN HALF_REG
740 notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
741 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
743 | A_ONE_DOT_H ASSIGN HALF_REG
745 notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
746 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
748 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16P LPAREN REG
749 COLON expr COMMA REG COLON expr RPAREN aligndir
751 if (!IS_DREG ($2) || !IS_DREG ($4))
752 return yyerror ("Dregs expected");
753 else if (!valid_dreg_pair (&$9, $11))
754 return yyerror ("Bad dreg pair");
755 else if (!valid_dreg_pair (&$13, $15))
756 return yyerror ("Bad dreg pair");
759 notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16P (dregs_pair , dregs_pair ) (half)\n");
760 $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 0);
764 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16M LPAREN REG COLON expr COMMA
765 REG COLON expr RPAREN aligndir
767 if (!IS_DREG ($2) || !IS_DREG($4))
768 return yyerror ("Dregs expected");
769 else if (!valid_dreg_pair (&$9, $11))
770 return yyerror ("Bad dreg pair");
771 else if (!valid_dreg_pair (&$13, $15))
772 return yyerror ("Bad dreg pair");
775 notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16M (dregs_pair , dregs_pair ) (aligndir)\n");
776 $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 1);
780 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEUNPACK REG COLON expr aligndir
782 if (!IS_DREG ($2) || !IS_DREG ($4))
783 return yyerror ("Dregs expected");
784 else if (!valid_dreg_pair (&$8, $10))
785 return yyerror ("Bad dreg pair");
788 notethat ("dsp32alu: (dregs , dregs ) = BYTEUNPACK dregs_pair (aligndir)\n");
789 $$ = DSP32ALU (24, 0, &$2, &$4, &$8, 0, $11.r0, 0, 1);
792 | LPAREN REG COMMA REG RPAREN ASSIGN SEARCH REG LPAREN searchmod RPAREN
794 if (IS_DREG ($2) && IS_DREG ($4) && IS_DREG ($8))
796 notethat ("dsp32alu: (dregs , dregs ) = SEARCH dregs (searchmod)\n");
797 $$ = DSP32ALU (13, 0, &$2, &$4, &$8, 0, 0, 0, $10.r0);
800 return yyerror ("Register mismatch");
802 | REG ASSIGN A_ONE_DOT_L PLUS A_ONE_DOT_H COMMA
803 REG ASSIGN A_ZERO_DOT_L PLUS A_ZERO_DOT_H
805 if (IS_DREG ($1) && IS_DREG ($7))
807 notethat ("dsp32alu: dregs = A1.l + A1.h, dregs = A0.l + A0.h \n");
808 $$ = DSP32ALU (12, 0, &$1, &$7, 0, 0, 0, 0, 1);
811 return yyerror ("Register mismatch");
815 | REG ASSIGN REG_A PLUS REG_A COMMA REG ASSIGN REG_A MINUS REG_A amod1
817 if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
818 && IS_A1 ($9) && !IS_A1 ($11))
820 notethat ("dsp32alu: dregs = A1 + A0 , dregs = A1 - A0 (amod1)\n");
821 $$ = DSP32ALU (17, 0, &$1, &$7, 0, 0, $12.s0, $12.x0, 0);
824 else if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
825 && !IS_A1 ($9) && IS_A1 ($11))
827 notethat ("dsp32alu: dregs = A0 + A1 , dregs = A0 - A1 (amod1)\n");
828 $$ = DSP32ALU (17, 0, &$1, &$7, 0, 0, $12.s0, $12.x0, 1);
831 return yyerror ("Register mismatch");
834 | REG ASSIGN REG plus_minus REG COMMA REG ASSIGN REG plus_minus REG amod1
837 return yyerror ("Operators must differ");
839 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5)
840 && REG_SAME ($3, $9) && REG_SAME ($5, $11))
842 notethat ("dsp32alu: dregs = dregs + dregs,"
843 "dregs = dregs - dregs (amod1)\n");
844 $$ = DSP32ALU (4, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, 2);
847 return yyerror ("Register mismatch");
850 /* Bar Operations. */
852 | REG ASSIGN REG op_bar_op REG COMMA REG ASSIGN REG op_bar_op REG amod2
854 if (!REG_SAME ($3, $9) || !REG_SAME ($5, $11))
855 return yyerror ("Differing source registers");
857 if (!IS_DREG ($1) || !IS_DREG ($3) || !IS_DREG ($5) || !IS_DREG ($7))
858 return yyerror ("Dregs expected");
861 if ($4.r0 == 1 && $10.r0 == 2)
863 notethat ("dsp32alu: dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
864 $$ = DSP32ALU (1, 1, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
866 else if ($4.r0 == 0 && $10.r0 == 3)
868 notethat ("dsp32alu: dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
869 $$ = DSP32ALU (1, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
872 return yyerror ("Bar operand mismatch");
875 | REG ASSIGN ABS REG vmod
879 if (IS_DREG ($1) && IS_DREG ($4))
883 notethat ("dsp32alu: dregs = ABS dregs (v)\n");
888 /* Vector version of ABS. */
889 notethat ("dsp32alu: dregs = ABS dregs\n");
892 $$ = DSP32ALU (op, 0, 0, &$1, &$4, 0, 0, 0, 2);
895 return yyerror ("Dregs expected");
899 notethat ("dsp32alu: Ax = ABS Ax\n");
900 $$ = DSP32ALU (16, IS_A1 ($1), 0, 0, 0, 0, 0, 0, IS_A1 ($3));
902 | A_ZERO_DOT_L ASSIGN HALF_REG
906 notethat ("dsp32alu: A0.l = reg_half\n");
907 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
910 return yyerror ("A0.l = Rx.l expected");
912 | A_ONE_DOT_L ASSIGN HALF_REG
916 notethat ("dsp32alu: A1.l = reg_half\n");
917 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
920 return yyerror ("A1.l = Rx.l expected");
923 | REG ASSIGN c_align LPAREN REG COMMA REG RPAREN
925 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
927 notethat ("dsp32shift: dregs = ALIGN8 (dregs , dregs )\n");
928 $$ = DSP32SHIFT (13, &$1, &$7, &$5, $3.r0, 0);
931 return yyerror ("Dregs expected");
934 | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN byteop_mod
937 return yyerror ("Dregs expected");
938 else if (!valid_dreg_pair (&$5, $7))
939 return yyerror ("Bad dreg pair");
940 else if (!valid_dreg_pair (&$9, $11))
941 return yyerror ("Bad dreg pair");
944 notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
945 $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, $13.s0, 0, $13.r0);
948 | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
951 return yyerror ("Dregs expected");
952 else if (!valid_dreg_pair (&$5, $7))
953 return yyerror ("Bad dreg pair");
954 else if (!valid_dreg_pair (&$9, $11))
955 return yyerror ("Bad dreg pair");
958 notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
959 $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, 0, 0, 0);
963 | REG ASSIGN BYTEOP2P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
967 return yyerror ("Dregs expected");
968 else if (!valid_dreg_pair (&$5, $7))
969 return yyerror ("Bad dreg pair");
970 else if (!valid_dreg_pair (&$9, $11))
971 return yyerror ("Bad dreg pair");
974 notethat ("dsp32alu: dregs = BYTEOP2P (dregs_pair , dregs_pair ) (rnd_op)\n");
975 $$ = DSP32ALU (22, $13.r0, 0, &$1, &$5, &$9, $13.s0, $13.x0, $13.aop);
979 | REG ASSIGN BYTEOP2M LPAREN REG COLON expr COMMA REG COLON expr RPAREN
983 return yyerror ("Dregs expected");
984 else if (!valid_dreg_pair (&$5, $7))
985 return yyerror ("Bad dreg pair");
986 else if (!valid_dreg_pair (&$9, $11))
987 return yyerror ("Bad dreg pair");
990 notethat ("dsp32alu: dregs = BYTEOP2P (dregs_pair , dregs_pair ) (rnd_op)\n");
991 $$ = DSP32ALU (22, $13.r0, 0, &$1, &$5, &$9, $13.s0, 0, $13.x0);
995 | REG ASSIGN BYTEOP3P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
999 return yyerror ("Dregs expected");
1000 else if (!valid_dreg_pair (&$5, $7))
1001 return yyerror ("Bad dreg pair");
1002 else if (!valid_dreg_pair (&$9, $11))
1003 return yyerror ("Bad dreg pair");
1006 notethat ("dsp32alu: dregs = BYTEOP3P (dregs_pair , dregs_pair ) (b3_op)\n");
1007 $$ = DSP32ALU (23, $13.x0, 0, &$1, &$5, &$9, $13.s0, 0, 0);
1011 | REG ASSIGN BYTEPACK LPAREN REG COMMA REG RPAREN
1013 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1015 notethat ("dsp32alu: dregs = BYTEPACK (dregs , dregs )\n");
1016 $$ = DSP32ALU (24, 0, 0, &$1, &$5, &$7, 0, 0, 0);
1019 return yyerror ("Dregs expected");
1022 | HALF_REG ASSIGN HALF_REG ASSIGN SIGN LPAREN HALF_REG RPAREN STAR
1023 HALF_REG PLUS SIGN LPAREN HALF_REG RPAREN STAR HALF_REG
1025 if (IS_HCOMPL ($1, $3) && IS_HCOMPL ($7, $14) && IS_HCOMPL ($10, $17))
1027 notethat ("dsp32alu: dregs_hi = dregs_lo ="
1028 "SIGN (dregs_hi) * dregs_hi + "
1029 "SIGN (dregs_lo) * dregs_lo \n");
1031 $$ = DSP32ALU (12, 0, 0, &$1, &$7, &$10, 0, 0, 0);
1034 return yyerror ("Dregs expected");
1036 | REG ASSIGN REG plus_minus REG amod1
1038 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1042 /* No saturation flag specified, generate the 16 bit variant. */
1043 notethat ("COMP3op: dregs = dregs +- dregs\n");
1044 $$ = COMP3OP (&$1, &$3, &$5, $4.r0);
1048 /* Saturation flag specified, generate the 32 bit variant. */
1049 notethat ("dsp32alu: dregs = dregs +- dregs (amod1)\n");
1050 $$ = DSP32ALU (4, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
1054 if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($5) && $4.r0 == 0)
1056 notethat ("COMP3op: pregs = pregs + pregs\n");
1057 $$ = COMP3OP (&$1, &$3, &$5, 5);
1060 return yyerror ("Dregs expected");
1062 | REG ASSIGN min_max LPAREN REG COMMA REG RPAREN vmod
1066 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1073 notethat ("dsp32alu: dregs = {MIN|MAX} (dregs, dregs)\n");
1074 $$ = DSP32ALU (op, 0, 0, &$1, &$5, &$7, 0, 0, $3.r0);
1077 return yyerror ("Dregs expected");
1080 | a_assign MINUS REG_A
1082 notethat ("dsp32alu: Ax = - Ax\n");
1083 $$ = DSP32ALU (14, IS_A1 ($1), 0, 0, 0, 0, 0, 0, IS_A1 ($3));
1085 | HALF_REG ASSIGN HALF_REG plus_minus HALF_REG amod1
1087 notethat ("dsp32alu: dregs_lo = dregs_lo +- dregs_lo (amod1)\n");
1088 $$ = DSP32ALU (2 | $4.r0, IS_H ($1), 0, &$1, &$3, &$5,
1089 $6.s0, $6.x0, HL2 ($3, $5));
1091 | a_assign a_assign expr
1093 if (EXPR_VALUE ($3) == 0 && !REG_SAME ($1, $2))
1095 notethat ("dsp32alu: A1 = A0 = 0\n");
1096 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, 2);
1099 return yyerror ("Bad value, 0 expected");
1103 | a_assign REG_A LPAREN S RPAREN
1105 if (REG_SAME ($1, $2))
1107 notethat ("dsp32alu: Ax = Ax (S)\n");
1108 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 1, 0, IS_A1 ($1));
1111 return yyerror ("Registers must be equal");
1114 | HALF_REG ASSIGN REG LPAREN RND RPAREN
1118 notethat ("dsp32alu: dregs_half = dregs (RND)\n");
1119 $$ = DSP32ALU (12, IS_H ($1), 0, &$1, &$3, 0, 0, 0, 3);
1122 return yyerror ("Dregs expected");
1125 | HALF_REG ASSIGN REG plus_minus REG LPAREN RND12 RPAREN
1127 if (IS_DREG ($3) && IS_DREG ($5))
1129 notethat ("dsp32alu: dregs_half = dregs (+-) dregs (RND12)\n");
1130 $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 0, $4.r0);
1133 return yyerror ("Dregs expected");
1136 | HALF_REG ASSIGN REG plus_minus REG LPAREN RND20 RPAREN
1138 if (IS_DREG ($3) && IS_DREG ($5))
1140 notethat ("dsp32alu: dregs_half = dregs -+ dregs (RND20)\n");
1141 $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 1, $4.r0 | 2);
1144 return yyerror ("Dregs expected");
1149 if (!REG_SAME ($1, $2))
1151 notethat ("dsp32alu: An = Am\n");
1152 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, IS_A1 ($1), 0, 3);
1155 return yyerror ("Accu reg arguments must differ");
1162 notethat ("dsp32alu: An = dregs\n");
1163 $$ = DSP32ALU (9, 0, 0, 0, &$2, 0, 1, 0, IS_A1 ($1) << 1);
1166 return yyerror ("Dregs expected");
1169 | REG ASSIGN HALF_REG xpmod
1173 if ($1.regno == REG_A0x && IS_DREG ($3))
1175 notethat ("dsp32alu: A0.x = dregs_lo\n");
1176 $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 1);
1178 else if ($1.regno == REG_A1x && IS_DREG ($3))
1180 notethat ("dsp32alu: A1.x = dregs_lo\n");
1181 $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 3);
1183 else if (IS_DREG ($1) && IS_DREG ($3))
1185 notethat ("ALU2op: dregs = dregs_lo\n");
1186 $$ = ALU2OP (&$1, &$3, 10 | ($4.r0 ? 0: 1));
1189 return yyerror ("Register mismatch");
1192 return yyerror ("Low reg expected");
1195 | HALF_REG ASSIGN expr
1197 notethat ("LDIMMhalf: pregs_half = imm16\n");
1199 if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
1200 && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
1201 return yyerror ("Wrong register for load immediate");
1203 if (!IS_IMM ($3, 16) && !IS_UIMM ($3, 16))
1204 return yyerror ("Constant out of range");
1206 $$ = LDIMMHALF_R (&$1, IS_H ($1), 0, 0, $3);
1211 notethat ("dsp32alu: An = 0\n");
1214 return yyerror ("0 expected");
1216 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, IS_A1 ($1));
1219 | REG ASSIGN expr xpmod1
1221 if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
1222 && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
1223 return yyerror ("Wrong register for load immediate");
1227 /* 7 bit immediate value if possible.
1228 We will check for that constant value for efficiency
1229 If it goes to reloc, it will be 16 bit. */
1230 if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_DREG ($1))
1232 notethat ("COMPI2opD: dregs = imm7 (x) \n");
1233 $$ = COMPI2OPD (&$1, imm7 ($3), 0);
1235 else if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_PREG ($1))
1237 notethat ("COMPI2opP: pregs = imm7 (x)\n");
1238 $$ = COMPI2OPP (&$1, imm7 ($3), 0);
1242 if (IS_CONST ($3) && !IS_IMM ($3, 16))
1243 return yyerror ("Immediate value out of range");
1245 notethat ("LDIMMhalf: regs = luimm16 (x)\n");
1247 $$ = LDIMMHALF_R5 (&$1, 0, 1, 0, $3);
1252 /* (z) There is no 7 bit zero extended instruction.
1253 If the expr is a relocation, generate it. */
1255 if (IS_CONST ($3) && !IS_UIMM ($3, 16))
1256 return yyerror ("Immediate value out of range");
1258 notethat ("LDIMMhalf: regs = luimm16 (x)\n");
1260 $$ = LDIMMHALF_R5 (&$1, 0, 0, 1, $3);
1264 | HALF_REG ASSIGN REG
1267 return yyerror ("Low reg expected");
1269 if (IS_DREG ($1) && $3.regno == REG_A0x)
1271 notethat ("dsp32alu: dregs_lo = A0.x\n");
1272 $$ = DSP32ALU (10, 0, 0, &$1, 0, 0, 0, 0, 0);
1274 else if (IS_DREG ($1) && $3.regno == REG_A1x)
1276 notethat ("dsp32alu: dregs_lo = A1.x\n");
1277 $$ = DSP32ALU (10, 0, 0, &$1, 0, 0, 0, 0, 1);
1280 return yyerror ("Register mismatch");
1283 | REG ASSIGN REG op_bar_op REG amod0
1285 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1287 notethat ("dsp32alu: dregs = dregs .|. dregs (amod0)\n");
1288 $$ = DSP32ALU (0, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
1291 return yyerror ("Register mismatch");
1294 | REG ASSIGN BYTE_DREG xpmod
1296 if (IS_DREG ($1) && IS_DREG ($3))
1298 notethat ("ALU2op: dregs = dregs_byte\n");
1299 $$ = ALU2OP (&$1, &$3, 12 | ($4.r0 ? 0: 1));
1302 return yyerror ("Register mismatch");
1305 | a_assign ABS REG_A COMMA a_assign ABS REG_A
1307 if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
1309 notethat ("dsp32alu: A1 = ABS A1 , A0 = ABS A0\n");
1310 $$ = DSP32ALU (16, 0, 0, 0, 0, 0, 0, 0, 3);
1313 return yyerror ("Register mismatch");
1316 | a_assign MINUS REG_A COMMA a_assign MINUS REG_A
1318 if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
1320 notethat ("dsp32alu: A1 = - A1 , A0 = - A0\n");
1321 $$ = DSP32ALU (14, 0, 0, 0, 0, 0, 0, 0, 3);
1324 return yyerror ("Register mismatch");
1327 | a_minusassign REG_A w32_or_nothing
1329 if (!IS_A1 ($1) && IS_A1 ($2))
1331 notethat ("dsp32alu: A0 -= A1\n");
1332 $$ = DSP32ALU (11, 0, 0, 0, 0, 0, $3.r0, 0, 3);
1335 return yyerror ("Register mismatch");
1338 | REG _MINUS_ASSIGN expr
1340 if (IS_IREG ($1) && EXPR_VALUE ($3) == 4)
1342 notethat ("dagMODik: iregs -= 4\n");
1343 $$ = DAGMODIK (&$1, 3);
1345 else if (IS_IREG ($1) && EXPR_VALUE ($3) == 2)
1347 notethat ("dagMODik: iregs -= 2\n");
1348 $$ = DAGMODIK (&$1, 1);
1351 return yyerror ("Register or value mismatch");
1354 | REG _PLUS_ASSIGN REG LPAREN BREV RPAREN
1356 if (IS_IREG ($1) && IS_MREG ($3))
1358 notethat ("dagMODim: iregs += mregs (opt_brev)\n");
1360 $$ = DAGMODIM (&$1, &$3, 0, 1);
1362 else if (IS_PREG ($1) && IS_PREG ($3))
1364 notethat ("PTR2op: pregs += pregs (BREV )\n");
1365 $$ = PTR2OP (&$1, &$3, 5);
1368 return yyerror ("Register mismatch");
1371 | REG _MINUS_ASSIGN REG
1373 if (IS_IREG ($1) && IS_MREG ($3))
1375 notethat ("dagMODim: iregs -= mregs\n");
1376 $$ = DAGMODIM (&$1, &$3, 1, 0);
1378 else if (IS_PREG ($1) && IS_PREG ($3))
1380 notethat ("PTR2op: pregs -= pregs\n");
1381 $$ = PTR2OP (&$1, &$3, 0);
1384 return yyerror ("Register mismatch");
1387 | REG_A _PLUS_ASSIGN REG_A w32_or_nothing
1389 if (!IS_A1 ($1) && IS_A1 ($3))
1391 notethat ("dsp32alu: A0 += A1 (W32)\n");
1392 $$ = DSP32ALU (11, 0, 0, 0, 0, 0, $4.r0, 0, 2);
1395 return yyerror ("Register mismatch");
1398 | REG _PLUS_ASSIGN REG
1400 if (IS_IREG ($1) && IS_MREG ($3))
1402 notethat ("dagMODim: iregs += mregs\n");
1403 $$ = DAGMODIM (&$1, &$3, 0, 0);
1406 return yyerror ("iregs += mregs expected");
1409 | REG _PLUS_ASSIGN expr
1413 if (EXPR_VALUE ($3) == 4)
1415 notethat ("dagMODik: iregs += 4\n");
1416 $$ = DAGMODIK (&$1, 2);
1418 else if (EXPR_VALUE ($3) == 2)
1420 notethat ("dagMODik: iregs += 2\n");
1421 $$ = DAGMODIK (&$1, 0);
1424 return yyerror ("iregs += [ 2 | 4 ");
1426 else if (IS_PREG ($1) && IS_IMM ($3, 7))
1428 notethat ("COMPI2opP: pregs += imm7\n");
1429 $$ = COMPI2OPP (&$1, imm7 ($3), 1);
1431 else if (IS_DREG ($1) && IS_IMM ($3, 7))
1433 notethat ("COMPI2opD: dregs += imm7\n");
1434 $$ = COMPI2OPD (&$1, imm7 ($3), 1);
1437 return yyerror ("Register mismatch");
1440 | REG _STAR_ASSIGN REG
1442 if (IS_DREG ($1) && IS_DREG ($3))
1444 notethat ("ALU2op: dregs *= dregs\n");
1445 $$ = ALU2OP (&$1, &$3, 3);
1448 return yyerror ("Register mismatch");
1451 | SAA LPAREN REG COLON expr COMMA REG COLON expr RPAREN aligndir
1453 if (!valid_dreg_pair (&$3, $5))
1454 return yyerror ("Bad dreg pair");
1455 else if (!valid_dreg_pair (&$7, $9))
1456 return yyerror ("Bad dreg pair");
1459 notethat ("dsp32alu: SAA (dregs_pair , dregs_pair ) (aligndir)\n");
1460 $$ = DSP32ALU (18, 0, 0, 0, &$3, &$7, $11.r0, 0, 0);
1464 | a_assign REG_A LPAREN S RPAREN COMMA a_assign REG_A LPAREN S RPAREN
1466 if (REG_SAME ($1, $2) && REG_SAME ($7, $8) && !REG_SAME ($1, $7))
1468 notethat ("dsp32alu: A1 = A1 (S) , A0 = A0 (S)\n");
1469 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 1, 0, 2);
1472 return yyerror ("Register mismatch");
1475 | REG ASSIGN LPAREN REG PLUS REG RPAREN LESS_LESS expr
1477 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6)
1478 && REG_SAME ($1, $4))
1480 if (EXPR_VALUE ($9) == 1)
1482 notethat ("ALU2op: dregs = (dregs + dregs) << 1\n");
1483 $$ = ALU2OP (&$1, &$6, 4);
1485 else if (EXPR_VALUE ($9) == 2)
1487 notethat ("ALU2op: dregs = (dregs + dregs) << 2\n");
1488 $$ = ALU2OP (&$1, &$6, 5);
1491 return yyerror ("Bad shift value");
1493 else if (IS_PREG ($1) && IS_PREG ($4) && IS_PREG ($6)
1494 && REG_SAME ($1, $4))
1496 if (EXPR_VALUE ($9) == 1)
1498 notethat ("PTR2op: pregs = (pregs + pregs) << 1\n");
1499 $$ = PTR2OP (&$1, &$6, 6);
1501 else if (EXPR_VALUE ($9) == 2)
1503 notethat ("PTR2op: pregs = (pregs + pregs) << 2\n");
1504 $$ = PTR2OP (&$1, &$6, 7);
1507 return yyerror ("Bad shift value");
1510 return yyerror ("Register mismatch");
1514 | REG ASSIGN REG BAR REG
1516 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1518 notethat ("COMP3op: dregs = dregs | dregs\n");
1519 $$ = COMP3OP (&$1, &$3, &$5, 3);
1522 return yyerror ("Dregs expected");
1524 | REG ASSIGN REG CARET REG
1526 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1528 notethat ("COMP3op: dregs = dregs ^ dregs\n");
1529 $$ = COMP3OP (&$1, &$3, &$5, 4);
1532 return yyerror ("Dregs expected");
1534 | REG ASSIGN REG PLUS LPAREN REG LESS_LESS expr RPAREN
1536 if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($6))
1538 if (EXPR_VALUE ($8) == 1)
1540 notethat ("COMP3op: pregs = pregs + (pregs << 1)\n");
1541 $$ = COMP3OP (&$1, &$3, &$6, 6);
1543 else if (EXPR_VALUE ($8) == 2)
1545 notethat ("COMP3op: pregs = pregs + (pregs << 2)\n");
1546 $$ = COMP3OP (&$1, &$3, &$6, 7);
1549 return yyerror ("Bad shift value");
1552 return yyerror ("Dregs expected");
1554 | CCREG ASSIGN REG_A _ASSIGN_ASSIGN REG_A
1556 if (!REG_SAME ($3, $5))
1558 notethat ("CCflag: CC = A0 == A1\n");
1559 $$ = CCFLAG (0, 0, 5, 0, 0);
1562 return yyerror ("CC register expected");
1564 | CCREG ASSIGN REG_A LESS_THAN REG_A
1566 if (!REG_SAME ($3, $5))
1568 notethat ("CCflag: CC = A0 < A1\n");
1569 $$ = CCFLAG (0, 0, 6, 0, 0);
1572 return yyerror ("Register mismatch");
1574 | CCREG ASSIGN REG LESS_THAN REG iu_or_nothing
1576 if (REG_CLASS($3) == REG_CLASS($5))
1578 notethat ("CCflag: CC = dpregs < dpregs\n");
1579 $$ = CCFLAG (&$3, $5.regno & CODE_MASK, $6.r0, 0, IS_PREG ($3) ? 1 : 0);
1582 return yyerror ("Compare only of same register class");
1584 | CCREG ASSIGN REG LESS_THAN expr iu_or_nothing
1586 if (($6.r0 == 1 && IS_IMM ($5, 3))
1587 || ($6.r0 == 3 && IS_UIMM ($5, 3)))
1589 notethat ("CCflag: CC = dpregs < (u)imm3\n");
1590 $$ = CCFLAG (&$3, imm3 ($5), $6.r0, 1, IS_PREG ($3) ? 1 : 0);
1593 return yyerror ("Bad constant value");
1595 | CCREG ASSIGN REG _ASSIGN_ASSIGN REG
1597 if (REG_CLASS($3) == REG_CLASS($5))
1599 notethat ("CCflag: CC = dpregs == dpregs\n");
1600 $$ = CCFLAG (&$3, $5.regno & CODE_MASK, 0, 0, IS_PREG ($3) ? 1 : 0);
1603 | CCREG ASSIGN REG _ASSIGN_ASSIGN expr
1607 notethat ("CCflag: CC = dpregs == imm3\n");
1608 $$ = CCFLAG (&$3, imm3 ($5), 0, 1, IS_PREG ($3) ? 1 : 0);
1611 return yyerror ("Bad constant range");
1613 | CCREG ASSIGN REG_A _LESS_THAN_ASSIGN REG_A
1615 if (!REG_SAME ($3, $5))
1617 notethat ("CCflag: CC = A0 <= A1\n");
1618 $$ = CCFLAG (0, 0, 7, 0, 0);
1621 return yyerror ("CC register expected");
1623 | CCREG ASSIGN REG _LESS_THAN_ASSIGN REG iu_or_nothing
1625 if (REG_CLASS($3) == REG_CLASS($5))
1627 notethat ("CCflag: CC = pregs <= pregs (..)\n");
1628 $$ = CCFLAG (&$3, $5.regno & CODE_MASK,
1629 1 + $6.r0, 0, IS_PREG ($3) ? 1 : 0);
1632 return yyerror ("Compare only of same register class");
1634 | CCREG ASSIGN REG _LESS_THAN_ASSIGN expr iu_or_nothing
1636 if (($6.r0 == 1 && IS_IMM ($5, 3))
1637 || ($6.r0 == 3 && IS_UIMM ($5, 3)))
1641 notethat ("CCflag: CC = dregs <= (u)imm3\n");
1643 $$ = CCFLAG (&$3, imm3 ($5), 1 + $6.r0, 1, 0);
1645 else if (IS_PREG ($3))
1647 notethat ("CCflag: CC = pregs <= (u)imm3\n");
1649 $$ = CCFLAG (&$3, imm3 ($5), 1 + $6.r0, 1, 1);
1652 return yyerror ("Dreg or Preg expected");
1655 return yyerror ("Bad constant value");
1658 | REG ASSIGN REG AMPERSAND REG
1660 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1662 notethat ("COMP3op: dregs = dregs & dregs\n");
1663 $$ = COMP3OP (&$1, &$3, &$5, 2);
1666 return yyerror ("Dregs expected");
1671 notethat ("CC2stat operation\n");
1672 $$ = bfin_gen_cc2stat ($1.r0, $1.x0, $1.s0);
1677 if (IS_ALLREG ($1) && IS_ALLREG ($3))
1679 notethat ("REGMV: allregs = allregs\n");
1680 $$ = bfin_gen_regmv (&$3, &$1);
1683 return yyerror ("Register mismatch");
1690 notethat ("CC2dreg: CC = dregs\n");
1691 $$ = bfin_gen_cc2dreg (1, &$3);
1694 return yyerror ("Register mismatch");
1701 notethat ("CC2dreg: dregs = CC\n");
1702 $$ = bfin_gen_cc2dreg (0, &$1);
1705 return yyerror ("Register mismatch");
1708 | CCREG _ASSIGN_BANG CCREG
1710 notethat ("CC2dreg: CC =! CC\n");
1711 $$ = bfin_gen_cc2dreg (3, 0);
1716 | HALF_REG ASSIGN multiply_halfregs opt_mode
1718 notethat ("dsp32mult: dregs_half = multiply_halfregs (opt_mode)\n");
1720 if (!IS_H ($1) && $4.MM)
1721 return yyerror ("(M) not allowed with MAC0");
1725 $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 0,
1726 IS_H ($3.s0), IS_H ($3.s1), 0, 0,
1727 &$1, 0, &$3.s0, &$3.s1, 0);
1731 $$ = DSP32MULT (0, 0, $4.mod, 0, 0,
1732 0, 0, IS_H ($3.s0), IS_H ($3.s1),
1733 &$1, 0, &$3.s0, &$3.s1, 1);
1737 | REG ASSIGN multiply_halfregs opt_mode
1739 /* Odd registers can use (M). */
1741 return yyerror ("Dreg expected");
1743 if (IS_EVEN ($1) && $4.MM)
1744 return yyerror ("(M) not allowed with MAC0");
1748 notethat ("dsp32mult: dregs = multiply_halfregs (opt_mode)\n");
1750 $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 1,
1751 IS_H ($3.s0), IS_H ($3.s1), 0, 0,
1752 &$1, 0, &$3.s0, &$3.s1, 0);
1756 notethat ("dsp32mult: dregs = multiply_halfregs opt_mode\n");
1757 $$ = DSP32MULT (0, 0, $4.mod, 0, 1,
1758 0, 0, IS_H ($3.s0), IS_H ($3.s1),
1759 &$1, 0, &$3.s0, &$3.s1, 1);
1763 | HALF_REG ASSIGN multiply_halfregs opt_mode COMMA
1764 HALF_REG ASSIGN multiply_halfregs opt_mode
1766 if (!IS_DREG ($1) || !IS_DREG ($6))
1767 return yyerror ("Dregs expected");
1769 if (!IS_HCOMPL($1, $6))
1770 return yyerror ("Dest registers mismatch");
1772 if (check_multiply_halfregs (&$3, &$8) < 0)
1775 if ((!IS_H ($1) && $4.MM)
1776 || (!IS_H ($6) && $9.MM))
1777 return yyerror ("(M) not allowed with MAC0");
1779 notethat ("dsp32mult: dregs_hi = multiply_halfregs mxd_mod, "
1780 "dregs_lo = multiply_halfregs opt_mode\n");
1783 $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 0,
1784 IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
1785 &$1, 0, &$3.s0, &$3.s1, 1);
1787 $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 0,
1788 IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
1789 &$1, 0, &$3.s0, &$3.s1, 1);
1792 | REG ASSIGN multiply_halfregs opt_mode COMMA REG ASSIGN multiply_halfregs opt_mode
1794 if (!IS_DREG ($1) || !IS_DREG ($6))
1795 return yyerror ("Dregs expected");
1797 if ((IS_EVEN ($1) && $6.regno - $1.regno != 1)
1798 || (IS_EVEN ($6) && $1.regno - $6.regno != 1))
1799 return yyerror ("Dest registers mismatch");
1801 if (check_multiply_halfregs (&$3, &$8) < 0)
1804 if ((IS_EVEN ($1) && $4.MM)
1805 || (IS_EVEN ($6) && $9.MM))
1806 return yyerror ("(M) not allowed with MAC0");
1808 notethat ("dsp32mult: dregs = multiply_halfregs mxd_mod, "
1809 "dregs = multiply_halfregs opt_mode\n");
1812 $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 1,
1813 IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
1814 &$1, 0, &$3.s0, &$3.s1, 1);
1816 $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 1,
1817 IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
1818 &$1, 0, &$3.s0, &$3.s1, 1);
1823 | a_assign ASHIFT REG_A BY HALF_REG
1825 if (!REG_SAME ($1, $3))
1826 return yyerror ("Aregs must be same");
1828 if (IS_DREG ($5) && !IS_H ($5))
1830 notethat ("dsp32shift: A0 = ASHIFT A0 BY dregs_lo\n");
1831 $$ = DSP32SHIFT (3, 0, &$5, 0, 0, IS_A1 ($1));
1834 return yyerror ("Dregs expected");
1837 | HALF_REG ASSIGN ASHIFT HALF_REG BY HALF_REG smod
1839 if (IS_DREG ($6) && !IS_H ($6))
1841 notethat ("dsp32shift: dregs_half = ASHIFT dregs_half BY dregs_lo\n");
1842 $$ = DSP32SHIFT (0, &$1, &$6, &$4, $7.s0, HL2 ($1, $4));
1845 return yyerror ("Dregs expected");
1848 | a_assign REG_A LESS_LESS expr
1850 if (!REG_SAME ($1, $2))
1851 return yyerror ("Aregs must be same");
1853 if (IS_UIMM ($4, 5))
1855 notethat ("dsp32shiftimm: A0 = A0 << uimm5\n");
1856 $$ = DSP32SHIFTIMM (3, 0, imm5 ($4), 0, 0, IS_A1 ($1));
1859 return yyerror ("Bad shift value");
1862 | REG ASSIGN REG LESS_LESS expr vsmod
1864 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
1869 notethat ("dsp32shiftimm: dregs = dregs << expr (V, .)\n");
1870 $$ = DSP32SHIFTIMM (1, &$1, imm4 ($5), &$3, $6.s0 ? 1 : 2, 0);
1874 notethat ("dsp32shiftimm: dregs = dregs << uimm5 (.)\n");
1875 $$ = DSP32SHIFTIMM (2, &$1, imm6 ($5), &$3, $6.s0 ? 1 : 2, 0);
1878 else if ($6.s0 == 0 && IS_PREG ($1) && IS_PREG ($3))
1880 if (EXPR_VALUE ($5) == 2)
1882 notethat ("PTR2op: pregs = pregs << 2\n");
1883 $$ = PTR2OP (&$1, &$3, 1);
1885 else if (EXPR_VALUE ($5) == 1)
1887 notethat ("COMP3op: pregs = pregs << 1\n");
1888 $$ = COMP3OP (&$1, &$3, &$3, 5);
1891 return yyerror ("Bad shift value");
1894 return yyerror ("Bad shift value or register");
1896 | HALF_REG ASSIGN HALF_REG LESS_LESS expr
1898 if (IS_UIMM ($5, 4))
1900 notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4\n");
1901 $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, 2, HL2 ($1, $3));
1904 return yyerror ("Bad shift value");
1906 | HALF_REG ASSIGN HALF_REG LESS_LESS expr smod
1908 if (IS_UIMM ($5, 4))
1910 notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4\n");
1911 $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, $6.s0, HL2 ($1, $3));
1914 return yyerror ("Bad shift value");
1916 | REG ASSIGN ASHIFT REG BY HALF_REG vsmod
1920 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6) && !IS_H ($6))
1925 notethat ("dsp32shift: dregs = ASHIFT dregs BY "
1926 "dregs_lo (V, .)\n");
1932 notethat ("dsp32shift: dregs = ASHIFT dregs BY dregs_lo (.)\n");
1934 $$ = DSP32SHIFT (op, &$1, &$6, &$4, $7.s0, 0);
1937 return yyerror ("Dregs expected");
1941 | HALF_REG ASSIGN EXPADJ LPAREN REG COMMA HALF_REG RPAREN vmod
1943 if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
1945 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs , dregs_lo )\n");
1946 $$ = DSP32SHIFT (7, &$1, &$7, &$5, $9.r0, 0);
1949 return yyerror ("Bad shift value or register");
1953 | HALF_REG ASSIGN EXPADJ LPAREN HALF_REG COMMA HALF_REG RPAREN
1955 if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
1957 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_lo, dregs_lo)\n");
1958 $$ = DSP32SHIFT (7, &$1, &$7, &$5, 2, 0);
1960 else if (IS_DREG_L ($1) && IS_DREG_H ($5) && IS_DREG_L ($7))
1962 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_hi, dregs_lo)\n");
1963 $$ = DSP32SHIFT (7, &$1, &$7, &$5, 3, 0);
1966 return yyerror ("Bad shift value or register");
1971 | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN
1973 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1975 notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs )\n");
1976 $$ = DSP32SHIFT (10, &$1, &$7, &$5, 2, 0);
1979 return yyerror ("Register mismatch");
1982 | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN LPAREN X RPAREN
1984 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1986 notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs ) (X)\n");
1987 $$ = DSP32SHIFT (10, &$1, &$7, &$5, 3, 0);
1990 return yyerror ("Register mismatch");
1993 | REG ASSIGN EXTRACT LPAREN REG COMMA HALF_REG RPAREN xpmod
1995 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG_L ($7))
1997 notethat ("dsp32shift: dregs = EXTRACT (dregs, dregs_lo ) (.)\n");
1998 $$ = DSP32SHIFT (10, &$1, &$7, &$5, $9.r0, 0);
2001 return yyerror ("Register mismatch");
2004 | a_assign REG_A _GREATER_GREATER_GREATER expr
2006 if (!REG_SAME ($1, $2))
2007 return yyerror ("Aregs must be same");
2009 if (IS_UIMM ($4, 5))
2011 notethat ("dsp32shiftimm: Ax = Ax >>> uimm5\n");
2012 $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 0, IS_A1 ($1));
2015 return yyerror ("Shift value range error");
2017 | a_assign LSHIFT REG_A BY HALF_REG
2019 if (REG_SAME ($1, $3) && IS_DREG_L ($5))
2021 notethat ("dsp32shift: Ax = LSHIFT Ax BY dregs_lo\n");
2022 $$ = DSP32SHIFT (3, 0, &$5, 0, 1, IS_A1 ($1));
2025 return yyerror ("Register mismatch");
2028 | HALF_REG ASSIGN LSHIFT HALF_REG BY HALF_REG
2030 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2032 notethat ("dsp32shift: dregs_lo = LSHIFT dregs_hi BY dregs_lo\n");
2033 $$ = DSP32SHIFT (0, &$1, &$6, &$4, 2, HL2 ($1, $4));
2036 return yyerror ("Register mismatch");
2039 | REG ASSIGN LSHIFT REG BY HALF_REG vmod
2041 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2043 notethat ("dsp32shift: dregs = LSHIFT dregs BY dregs_lo (V )\n");
2044 $$ = DSP32SHIFT ($7.r0 ? 1: 2, &$1, &$6, &$4, 2, 0);
2047 return yyerror ("Register mismatch");
2050 | REG ASSIGN SHIFT REG BY HALF_REG
2052 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2054 notethat ("dsp32shift: dregs = SHIFT dregs BY dregs_lo\n");
2055 $$ = DSP32SHIFT (2, &$1, &$6, &$4, 2, 0);
2058 return yyerror ("Register mismatch");
2061 | a_assign REG_A GREATER_GREATER expr
2063 if (REG_SAME ($1, $2) && IS_IMM ($4, 6) >= 0)
2065 notethat ("dsp32shiftimm: Ax = Ax >> imm6\n");
2066 $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 1, IS_A1 ($1));
2069 return yyerror ("Accu register expected");
2072 | REG ASSIGN REG GREATER_GREATER expr vmod
2076 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2078 notethat ("dsp32shiftimm: dregs = dregs >> uimm5 (V)\n");
2079 $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, 2, 0);
2082 return yyerror ("Register mismatch");
2086 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2088 notethat ("dsp32shiftimm: dregs = dregs >> uimm5\n");
2089 $$ = DSP32SHIFTIMM (2, &$1, -imm6 ($5), &$3, 2, 0);
2091 else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 2)
2093 notethat ("PTR2op: pregs = pregs >> 2\n");
2094 $$ = PTR2OP (&$1, &$3, 3);
2096 else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 1)
2098 notethat ("PTR2op: pregs = pregs >> 1\n");
2099 $$ = PTR2OP (&$1, &$3, 4);
2102 return yyerror ("Register mismatch");
2105 | HALF_REG ASSIGN HALF_REG GREATER_GREATER expr
2107 if (IS_UIMM ($5, 5))
2109 notethat ("dsp32shiftimm: dregs_half = dregs_half >> uimm5\n");
2110 $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3, 2, HL2 ($1, $3));
2113 return yyerror ("Register mismatch");
2115 | HALF_REG ASSIGN HALF_REG _GREATER_GREATER_GREATER expr smod
2117 if (IS_UIMM ($5, 5))
2119 notethat ("dsp32shiftimm: dregs_half = dregs_half >>> uimm5\n");
2120 $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3,
2121 $6.s0, HL2 ($1, $3));
2124 return yyerror ("Register or modifier mismatch");
2128 | REG ASSIGN REG _GREATER_GREATER_GREATER expr vsmod
2130 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2135 notethat ("dsp32shiftimm: dregs = dregs >>> uimm5 (V, .)\n");
2136 $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, $6.s0, 0);
2140 notethat ("dsp32shiftimm: dregs = dregs >>> uimm5 (.)\n");
2141 $$ = DSP32SHIFTIMM (2, &$1, -uimm5 ($5), &$3, $6.s0, 0);
2145 return yyerror ("Register mismatch");
2148 | HALF_REG ASSIGN ONES REG
2150 if (IS_DREG_L ($1) && IS_DREG ($4))
2152 notethat ("dsp32shift: dregs_lo = ONES dregs\n");
2153 $$ = DSP32SHIFT (6, &$1, 0, &$4, 3, 0);
2156 return yyerror ("Register mismatch");
2159 | REG ASSIGN PACK LPAREN HALF_REG COMMA HALF_REG RPAREN
2161 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2163 notethat ("dsp32shift: dregs = PACK (dregs_hi , dregs_hi )\n");
2164 $$ = DSP32SHIFT (4, &$1, &$7, &$5, HL2 ($5, $7), 0);
2167 return yyerror ("Register mismatch");
2170 | HALF_REG ASSIGN CCREG ASSIGN BXORSHIFT LPAREN REG_A COMMA REG RPAREN
2173 && $7.regno == REG_A0
2174 && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
2176 notethat ("dsp32shift: dregs_lo = CC = BXORSHIFT (A0 , dregs )\n");
2177 $$ = DSP32SHIFT (11, &$1, &$9, 0, 0, 0);
2180 return yyerror ("Register mismatch");
2183 | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG RPAREN
2186 && $7.regno == REG_A0
2187 && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
2189 notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , dregs)\n");
2190 $$ = DSP32SHIFT (11, &$1, &$9, 0, 1, 0);
2193 return yyerror ("Register mismatch");
2196 | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
2198 if (IS_DREG ($1) && !IS_H ($1) && !REG_SAME ($7, $9))
2200 notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , A1 , CC)\n");
2201 $$ = DSP32SHIFT (12, &$1, 0, 0, 1, 0);
2204 return yyerror ("Register mismatch");
2207 | a_assign ROT REG_A BY HALF_REG
2209 if (REG_SAME ($1, $3) && IS_DREG_L ($5))
2211 notethat ("dsp32shift: Ax = ROT Ax BY dregs_lo\n");
2212 $$ = DSP32SHIFT (3, 0, &$5, 0, 2, IS_A1 ($1));
2215 return yyerror ("Register mismatch");
2218 | REG ASSIGN ROT REG BY HALF_REG
2220 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2222 notethat ("dsp32shift: dregs = ROT dregs BY dregs_lo\n");
2223 $$ = DSP32SHIFT (2, &$1, &$6, &$4, 3, 0);
2226 return yyerror ("Register mismatch");
2229 | a_assign ROT REG_A BY expr
2233 notethat ("dsp32shiftimm: An = ROT An BY imm6\n");
2234 $$ = DSP32SHIFTIMM (3, 0, imm6 ($5), 0, 2, IS_A1 ($1));
2237 return yyerror ("Register mismatch");
2240 | REG ASSIGN ROT REG BY expr
2242 if (IS_DREG ($1) && IS_DREG ($4) && IS_IMM ($6, 6))
2244 $$ = DSP32SHIFTIMM (2, &$1, imm6 ($6), &$4, 3, IS_A1 ($1));
2247 return yyerror ("Register mismatch");
2250 | HALF_REG ASSIGN SIGNBITS REG_A
2254 notethat ("dsp32shift: dregs_lo = SIGNBITS An\n");
2255 $$ = DSP32SHIFT (6, &$1, 0, 0, IS_A1 ($4), 0);
2258 return yyerror ("Register mismatch");
2261 | HALF_REG ASSIGN SIGNBITS REG
2263 if (IS_DREG_L ($1) && IS_DREG ($4))
2265 notethat ("dsp32shift: dregs_lo = SIGNBITS dregs\n");
2266 $$ = DSP32SHIFT (5, &$1, 0, &$4, 0, 0);
2269 return yyerror ("Register mismatch");
2272 | HALF_REG ASSIGN SIGNBITS HALF_REG
2276 notethat ("dsp32shift: dregs_lo = SIGNBITS dregs_lo\n");
2277 $$ = DSP32SHIFT (5, &$1, 0, &$4, 1 + IS_H ($4), 0);
2280 return yyerror ("Register mismatch");
2283 /* The ASR bit is just inverted here. */
2284 | HALF_REG ASSIGN VIT_MAX LPAREN REG RPAREN asr_asl
2286 if (IS_DREG_L ($1) && IS_DREG ($5))
2288 notethat ("dsp32shift: dregs_lo = VIT_MAX (dregs) (..)\n");
2289 $$ = DSP32SHIFT (9, &$1, 0, &$5, ($7.r0 ? 0 : 1), 0);
2292 return yyerror ("Register mismatch");
2295 | REG ASSIGN VIT_MAX LPAREN REG COMMA REG RPAREN asr_asl
2297 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2299 notethat ("dsp32shift: dregs = VIT_MAX (dregs, dregs) (ASR)\n");
2300 $$ = DSP32SHIFT (9, &$1, &$7, &$5, 2 | ($9.r0 ? 0 : 1), 0);
2303 return yyerror ("Register mismatch");
2306 | BITMUX LPAREN REG COMMA REG COMMA REG_A RPAREN asr_asl
2308 if (IS_DREG ($3) && IS_DREG ($5) && !IS_A1 ($7))
2310 notethat ("dsp32shift: BITMUX (dregs , dregs , A0) (ASR)\n");
2311 $$ = DSP32SHIFT (8, 0, &$3, &$5, $9.r0, 0);
2314 return yyerror ("Register mismatch");
2317 | a_assign BXORSHIFT LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
2319 if (!IS_A1 ($1) && !IS_A1 ($4) && IS_A1 ($6))
2321 notethat ("dsp32shift: A0 = BXORSHIFT (A0 , A1 , CC )\n");
2322 $$ = DSP32SHIFT (12, 0, 0, 0, 0, 0);
2325 return yyerror ("Dregs expected");
2329 /* LOGI2op: BITCLR (dregs, uimm5). */
2330 | BITCLR LPAREN REG COMMA expr RPAREN
2332 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2334 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2335 $$ = LOGI2OP ($3, uimm5 ($5), 4);
2338 return yyerror ("Register mismatch");
2341 /* LOGI2op: BITSET (dregs, uimm5). */
2342 | BITSET LPAREN REG COMMA expr RPAREN
2344 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2346 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2347 $$ = LOGI2OP ($3, uimm5 ($5), 2);
2350 return yyerror ("Register mismatch");
2353 /* LOGI2op: BITTGL (dregs, uimm5). */
2354 | BITTGL LPAREN REG COMMA expr RPAREN
2356 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2358 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2359 $$ = LOGI2OP ($3, uimm5 ($5), 3);
2362 return yyerror ("Register mismatch");
2365 | CCREG _ASSIGN_BANG BITTST LPAREN REG COMMA expr RPAREN
2367 if (IS_DREG ($5) && IS_UIMM ($7, 5))
2369 notethat ("LOGI2op: CC =! BITTST (dregs , uimm5 )\n");
2370 $$ = LOGI2OP ($5, uimm5 ($7), 0);
2373 return yyerror ("Register mismatch or value error");
2376 | CCREG ASSIGN BITTST LPAREN REG COMMA expr RPAREN
2378 if (IS_DREG ($5) && IS_UIMM ($7, 5))
2380 notethat ("LOGI2op: CC = BITTST (dregs , uimm5 )\n");
2381 $$ = LOGI2OP ($5, uimm5 ($7), 1);
2384 return yyerror ("Register mismatch or value error");
2387 | IF BANG CCREG REG ASSIGN REG
2389 if ((IS_DREG ($4) || IS_PREG ($4))
2390 && (IS_DREG ($6) || IS_PREG ($6)))
2392 notethat ("ccMV: IF ! CC gregs = gregs\n");
2393 $$ = CCMV (&$6, &$4, 0);
2396 return yyerror ("Register mismatch");
2399 | IF CCREG REG ASSIGN REG
2401 if ((IS_DREG ($5) || IS_PREG ($5))
2402 && (IS_DREG ($3) || IS_PREG ($3)))
2404 notethat ("ccMV: IF CC gregs = gregs\n");
2405 $$ = CCMV (&$5, &$3, 1);
2408 return yyerror ("Register mismatch");
2411 | IF BANG CCREG JUMP expr
2413 if (IS_PCREL10 ($5))
2415 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2416 $$ = BRCC (0, 0, $5);
2419 return yyerror ("Bad jump offset");
2422 | IF BANG CCREG JUMP expr LPAREN BP RPAREN
2424 if (IS_PCREL10 ($5))
2426 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2427 $$ = BRCC (0, 1, $5);
2430 return yyerror ("Bad jump offset");
2433 | IF CCREG JUMP expr
2435 if (IS_PCREL10 ($4))
2437 notethat ("BRCC: IF CC JUMP pcrel11m2\n");
2438 $$ = BRCC (1, 0, $4);
2441 return yyerror ("Bad jump offset");
2444 | IF CCREG JUMP expr LPAREN BP RPAREN
2446 if (IS_PCREL10 ($4))
2448 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2449 $$ = BRCC (1, 1, $4);
2452 return yyerror ("Bad jump offset");
2456 notethat ("ProgCtrl: NOP\n");
2457 $$ = PROGCTRL (0, 0);
2462 notethat ("ProgCtrl: RTS\n");
2463 $$ = PROGCTRL (1, 0);
2468 notethat ("ProgCtrl: RTI\n");
2469 $$ = PROGCTRL (1, 1);
2474 notethat ("ProgCtrl: RTX\n");
2475 $$ = PROGCTRL (1, 2);
2480 notethat ("ProgCtrl: RTN\n");
2481 $$ = PROGCTRL (1, 3);
2486 notethat ("ProgCtrl: RTE\n");
2487 $$ = PROGCTRL (1, 4);
2492 notethat ("ProgCtrl: IDLE\n");
2493 $$ = PROGCTRL (2, 0);
2498 notethat ("ProgCtrl: CSYNC\n");
2499 $$ = PROGCTRL (2, 3);
2504 notethat ("ProgCtrl: SSYNC\n");
2505 $$ = PROGCTRL (2, 4);
2510 notethat ("ProgCtrl: EMUEXCPT\n");
2511 $$ = PROGCTRL (2, 5);
2518 notethat ("ProgCtrl: CLI dregs\n");
2519 $$ = PROGCTRL (3, $2.regno & CODE_MASK);
2522 return yyerror ("Dreg expected for CLI");
2529 notethat ("ProgCtrl: STI dregs\n");
2530 $$ = PROGCTRL (4, $2.regno & CODE_MASK);
2533 return yyerror ("Dreg expected for STI");
2536 | JUMP LPAREN REG RPAREN
2540 notethat ("ProgCtrl: JUMP (pregs )\n");
2541 $$ = PROGCTRL (5, $3.regno & CODE_MASK);
2544 return yyerror ("Bad register for indirect jump");
2547 | CALL LPAREN REG RPAREN
2551 notethat ("ProgCtrl: CALL (pregs )\n");
2552 $$ = PROGCTRL (6, $3.regno & CODE_MASK);
2555 return yyerror ("Bad register for indirect call");
2558 | CALL LPAREN PC PLUS REG RPAREN
2562 notethat ("ProgCtrl: CALL (PC + pregs )\n");
2563 $$ = PROGCTRL (7, $5.regno & CODE_MASK);
2566 return yyerror ("Bad register for indirect call");
2569 | JUMP LPAREN PC PLUS REG RPAREN
2573 notethat ("ProgCtrl: JUMP (PC + pregs )\n");
2574 $$ = PROGCTRL (8, $5.regno & CODE_MASK);
2577 return yyerror ("Bad register for indirect jump");
2582 if (IS_UIMM ($2, 4))
2584 notethat ("ProgCtrl: RAISE uimm4\n");
2585 $$ = PROGCTRL (9, uimm4 ($2));
2588 return yyerror ("Bad value for RAISE");
2593 notethat ("ProgCtrl: EMUEXCPT\n");
2594 $$ = PROGCTRL (10, uimm4 ($2));
2597 | TESTSET LPAREN REG RPAREN
2601 notethat ("ProgCtrl: TESTSET (pregs )\n");
2602 $$ = PROGCTRL (11, $3.regno & CODE_MASK);
2605 return yyerror ("Preg expected");
2610 if (IS_PCREL12 ($2))
2612 notethat ("UJUMP: JUMP pcrel12\n");
2616 return yyerror ("Bad value for relative jump");
2621 if (IS_PCREL12 ($2))
2623 notethat ("UJUMP: JUMP_DOT_S pcrel12\n");
2627 return yyerror ("Bad value for relative jump");
2632 if (IS_PCREL24 ($2))
2634 notethat ("CALLa: jump.l pcrel24\n");
2638 return yyerror ("Bad value for long jump");
2643 if (IS_PCREL24 ($2))
2645 notethat ("CALLa: jump.l pcrel24\n");
2649 return yyerror ("Bad value for long jump");
2654 if (IS_PCREL24 ($2))
2656 notethat ("CALLa: CALL pcrel25m2\n");
2660 return yyerror ("Bad call address");
2664 if (IS_PCREL24 ($2))
2666 notethat ("CALLa: CALL pcrel25m2\n");
2670 return yyerror ("Bad call address");
2674 /* ALU2op: DIVQ (dregs, dregs). */
2675 | DIVQ LPAREN REG COMMA REG RPAREN
2677 if (IS_DREG ($3) && IS_DREG ($5))
2678 $$ = ALU2OP (&$3, &$5, 8);
2680 return yyerror ("Bad registers for DIVQ");
2683 | DIVS LPAREN REG COMMA REG RPAREN
2685 if (IS_DREG ($3) && IS_DREG ($5))
2686 $$ = ALU2OP (&$3, &$5, 9);
2688 return yyerror ("Bad registers for DIVS");
2691 | REG ASSIGN MINUS REG vsmod
2693 if (IS_DREG ($1) && IS_DREG ($4))
2695 if ($5.r0 == 0 && $5.s0 == 0 && $5.aop == 0)
2697 notethat ("ALU2op: dregs = - dregs\n");
2698 $$ = ALU2OP (&$1, &$4, 14);
2700 else if ($5.r0 == 1 && $5.s0 == 0 && $5.aop == 3)
2702 notethat ("dsp32alu: dregs = - dregs (.)\n");
2703 $$ = DSP32ALU (15, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
2707 notethat ("dsp32alu: dregs = - dregs (.)\n");
2708 $$ = DSP32ALU (7, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
2712 return yyerror ("Dregs expected");
2715 | REG ASSIGN TILDA REG
2717 if (IS_DREG ($1) && IS_DREG ($4))
2719 notethat ("ALU2op: dregs = ~dregs\n");
2720 $$ = ALU2OP (&$1, &$4, 15);
2723 return yyerror ("Dregs expected");
2726 | REG _GREATER_GREATER_ASSIGN REG
2728 if (IS_DREG ($1) && IS_DREG ($3))
2730 notethat ("ALU2op: dregs >>= dregs\n");
2731 $$ = ALU2OP (&$1, &$3, 1);
2734 return yyerror ("Dregs expected");
2737 | REG _GREATER_GREATER_ASSIGN expr
2739 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2741 notethat ("LOGI2op: dregs >>= uimm5\n");
2742 $$ = LOGI2OP ($1, uimm5 ($3), 6);
2745 return yyerror ("Dregs expected or value error");
2748 | REG _GREATER_GREATER_GREATER_THAN_ASSIGN REG
2750 if (IS_DREG ($1) && IS_DREG ($3))
2752 notethat ("ALU2op: dregs >>>= dregs\n");
2753 $$ = ALU2OP (&$1, &$3, 0);
2756 return yyerror ("Dregs expected");
2759 | REG _LESS_LESS_ASSIGN REG
2761 if (IS_DREG ($1) && IS_DREG ($3))
2763 notethat ("ALU2op: dregs <<= dregs\n");
2764 $$ = ALU2OP (&$1, &$3, 2);
2767 return yyerror ("Dregs expected");
2770 | REG _LESS_LESS_ASSIGN expr
2772 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2774 notethat ("LOGI2op: dregs <<= uimm5\n");
2775 $$ = LOGI2OP ($1, uimm5 ($3), 7);
2778 return yyerror ("Dregs expected or const value error");
2782 | REG _GREATER_GREATER_GREATER_THAN_ASSIGN expr
2784 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2786 notethat ("LOGI2op: dregs >>>= uimm5\n");
2787 $$ = LOGI2OP ($1, uimm5 ($3), 5);
2790 return yyerror ("Dregs expected");
2793 /* Cache Control. */
2795 | FLUSH LBRACK REG RBRACK
2797 notethat ("CaCTRL: FLUSH [ pregs ]\n");
2799 $$ = CACTRL (&$3, 0, 2);
2801 return yyerror ("Bad register(s) for FLUSH");
2804 | FLUSH reg_with_postinc
2808 notethat ("CaCTRL: FLUSH [ pregs ++ ]\n");
2809 $$ = CACTRL (&$2, 1, 2);
2812 return yyerror ("Bad register(s) for FLUSH");
2815 | FLUSHINV LBRACK REG RBRACK
2819 notethat ("CaCTRL: FLUSHINV [ pregs ]\n");
2820 $$ = CACTRL (&$3, 0, 1);
2823 return yyerror ("Bad register(s) for FLUSH");
2826 | FLUSHINV reg_with_postinc
2830 notethat ("CaCTRL: FLUSHINV [ pregs ++ ]\n");
2831 $$ = CACTRL (&$2, 1, 1);
2834 return yyerror ("Bad register(s) for FLUSH");
2837 /* CaCTRL: IFLUSH [pregs]. */
2838 | IFLUSH LBRACK REG RBRACK
2842 notethat ("CaCTRL: IFLUSH [ pregs ]\n");
2843 $$ = CACTRL (&$3, 0, 3);
2846 return yyerror ("Bad register(s) for FLUSH");
2849 | IFLUSH reg_with_postinc
2853 notethat ("CaCTRL: IFLUSH [ pregs ++ ]\n");
2854 $$ = CACTRL (&$2, 1, 3);
2857 return yyerror ("Bad register(s) for FLUSH");
2860 | PREFETCH LBRACK REG RBRACK
2864 notethat ("CaCTRL: PREFETCH [ pregs ]\n");
2865 $$ = CACTRL (&$3, 0, 0);
2868 return yyerror ("Bad register(s) for PREFETCH");
2871 | PREFETCH reg_with_postinc
2875 notethat ("CaCTRL: PREFETCH [ pregs ++ ]\n");
2876 $$ = CACTRL (&$2, 1, 0);
2879 return yyerror ("Bad register(s) for PREFETCH");
2883 /* LDST: B [ pregs <post_op> ] = dregs. */
2885 | B LBRACK REG post_op RBRACK ASSIGN REG
2887 if (IS_PREG ($3) && IS_DREG ($7))
2889 notethat ("LDST: B [ pregs <post_op> ] = dregs\n");
2890 $$ = LDST (&$3, &$7, $4.x0, 2, 0, 1);
2893 return yyerror ("Register mismatch");
2896 /* LDSTidxI: B [ pregs + imm16 ] = dregs. */
2897 | B LBRACK REG plus_minus expr RBRACK ASSIGN REG
2899 if (IS_PREG ($3) && IS_RANGE(16, $5, $4.r0, 1) && IS_DREG ($8))
2901 notethat ("LDST: B [ pregs + imm16 ] = dregs\n");
2904 $$ = LDSTIDXI (&$3, &$8, 1, 2, 0, $5);
2907 return yyerror ("Register mismatch or const size wrong");
2911 /* LDSTii: W [ pregs + uimm4s2 ] = dregs. */
2912 | W LBRACK REG plus_minus expr RBRACK ASSIGN REG
2914 if (IS_PREG ($3) && IS_URANGE (4, $5, $4.r0, 2) && IS_DREG ($8))
2916 notethat ("LDSTii: W [ pregs +- uimm5m2 ] = dregs\n");
2917 $$ = LDSTII (&$3, &$8, $5, 1, 1);
2919 else if (IS_PREG ($3) && IS_RANGE(16, $5, $4.r0, 2) && IS_DREG ($8))
2921 notethat ("LDSTidxI: W [ pregs + imm17m2 ] = dregs\n");
2924 $$ = LDSTIDXI (&$3, &$8, 1, 1, 0, $5);
2927 return yyerror ("Bad register(s) or wrong constant size");
2930 /* LDST: W [ pregs <post_op> ] = dregs. */
2931 | W LBRACK REG post_op RBRACK ASSIGN REG
2933 if (IS_PREG ($3) && IS_DREG ($7))
2935 notethat ("LDST: W [ pregs <post_op> ] = dregs\n");
2936 $$ = LDST (&$3, &$7, $4.x0, 1, 0, 1);
2939 return yyerror ("Bad register(s) for STORE");
2942 | W LBRACK REG post_op RBRACK ASSIGN HALF_REG
2946 notethat ("dspLDST: W [ iregs <post_op> ] = dregs_half\n");
2947 $$ = DSPLDST (&$3, 1 + IS_H ($7), &$7, $4.x0, 1);
2949 else if ($4.x0 == 2 && IS_PREG ($3) && IS_DREG ($7))
2951 notethat ("LDSTpmod: W [ pregs <post_op>] = dregs_half\n");
2952 $$ = LDSTPMOD (&$3, &$7, &$3, 1 + IS_H ($7), 1);
2956 return yyerror ("Bad register(s) for STORE");
2959 /* LDSTiiFP: [ FP - const ] = dpregs. */
2960 | LBRACK REG plus_minus expr RBRACK ASSIGN REG
2962 Expr_Node *tmp = $4;
2963 int ispreg = IS_PREG ($7);
2966 return yyerror ("Preg expected for indirect");
2968 if (!IS_DREG ($7) && !ispreg)
2969 return yyerror ("Bad source register for STORE");
2972 tmp = unary (Expr_Op_Type_NEG, tmp);
2974 if (in_range_p (tmp, 0, 63, 3))
2976 notethat ("LDSTii: dpregs = [ pregs + uimm6m4 ]\n");
2977 $$ = LDSTII (&$2, &$7, tmp, 1, ispreg ? 3 : 0);
2979 else if ($2.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
2981 notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
2982 tmp = unary (Expr_Op_Type_NEG, tmp);
2983 $$ = LDSTIIFP (tmp, &$7, 1);
2985 else if (in_range_p (tmp, -131072, 131071, 3))
2987 notethat ("LDSTidxI: [ pregs + imm18m4 ] = dpregs\n");
2988 $$ = LDSTIDXI (&$2, &$7, 1, 0, ispreg ? 1: 0, tmp);
2991 return yyerror ("Displacement out of range for store");
2994 | REG ASSIGN W LBRACK REG plus_minus expr RBRACK xpmod
2996 if (IS_DREG ($1) && IS_PREG ($5) && IS_URANGE (4, $7, $6.r0, 2))
2998 notethat ("LDSTii: dregs = W [ pregs + uimm4s2 ] (.)\n");
2999 $$ = LDSTII (&$5, &$1, $7, 0, 1 << $9.r0);
3001 else if (IS_DREG ($1) && IS_PREG ($5) && IS_RANGE(16, $7, $6.r0, 2))
3003 notethat ("LDSTidxI: dregs = W [ pregs + imm17m2 ] (.)\n");
3006 $$ = LDSTIDXI (&$5, &$1, 0, 1, $9.r0, $7);
3009 return yyerror ("Bad register or constant for LOAD");
3012 | HALF_REG ASSIGN W LBRACK REG post_op RBRACK
3016 notethat ("dspLDST: dregs_half = W [ iregs ]\n");
3017 $$ = DSPLDST(&$5, 1 + IS_H ($1), &$1, $6.x0, 0);
3019 else if ($6.x0 == 2 && IS_DREG ($1) && IS_PREG ($5))
3021 notethat ("LDSTpmod: dregs_half = W [ pregs ]\n");
3022 $$ = LDSTPMOD (&$5, &$1, &$5, 1 + IS_H ($1), 0);
3025 return yyerror ("Bad register or post_op for LOAD");
3029 | REG ASSIGN W LBRACK REG post_op RBRACK xpmod
3031 if (IS_DREG ($1) && IS_PREG ($5))
3033 notethat ("LDST: dregs = W [ pregs <post_op> ] (.)\n");
3034 $$ = LDST (&$5, &$1, $6.x0, 1, $8.r0, 0);
3037 return yyerror ("Bad register for LOAD");
3040 | REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK xpmod
3042 if (IS_DREG ($1) && IS_PREG ($5) && IS_PREG ($7))
3044 notethat ("LDSTpmod: dregs = W [ pregs ++ pregs ] (.)\n");
3045 $$ = LDSTPMOD (&$5, &$1, &$7, 3, $9.r0);
3048 return yyerror ("Bad register for LOAD");
3051 | HALF_REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK
3053 if (IS_DREG ($1) && IS_PREG ($5) && IS_PREG ($7))
3055 notethat ("LDSTpmod: dregs_half = W [ pregs ++ pregs ]\n");
3056 $$ = LDSTPMOD (&$5, &$1, &$7, 1 + IS_H ($1), 0);
3059 return yyerror ("Bad register for LOAD");
3062 | LBRACK REG post_op RBRACK ASSIGN REG
3064 if (IS_IREG ($2) && IS_DREG ($6))
3066 notethat ("dspLDST: [ iregs <post_op> ] = dregs\n");
3067 $$ = DSPLDST(&$2, 0, &$6, $3.x0, 1);
3069 else if (IS_PREG ($2) && IS_DREG ($6))
3071 notethat ("LDST: [ pregs <post_op> ] = dregs\n");
3072 $$ = LDST (&$2, &$6, $3.x0, 0, 0, 1);
3074 else if (IS_PREG ($2) && IS_PREG ($6))
3076 notethat ("LDST: [ pregs <post_op> ] = pregs\n");
3077 $$ = LDST (&$2, &$6, $3.x0, 0, 1, 1);
3080 return yyerror ("Bad register for STORE");
3083 | LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN REG
3086 return yyerror ("Expected Dreg for last argument");
3088 if (IS_IREG ($2) && IS_MREG ($4))
3090 notethat ("dspLDST: [ iregs ++ mregs ] = dregs\n");
3091 $$ = DSPLDST(&$2, $4.regno & CODE_MASK, &$7, 3, 1);
3093 else if (IS_PREG ($2) && IS_PREG ($4))
3095 notethat ("LDSTpmod: [ pregs ++ pregs ] = dregs\n");
3096 $$ = LDSTPMOD (&$2, &$7, &$4, 0, 1);
3099 return yyerror ("Bad register for STORE");
3102 | W LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN HALF_REG
3105 return yyerror ("Expect Dreg as last argument");
3106 if (IS_PREG ($3) && IS_PREG ($5))
3108 notethat ("LDSTpmod: W [ pregs ++ pregs ] = dregs_half\n");
3109 $$ = LDSTPMOD (&$3, &$8, &$5, 1 + IS_H ($8), 1);
3112 return yyerror ("Bad register for STORE");
3115 | REG ASSIGN B LBRACK REG plus_minus expr RBRACK xpmod
3117 if (IS_DREG ($1) && IS_PREG ($5) && IS_RANGE(16, $7, $6.r0, 1))
3119 notethat ("LDSTidxI: dregs = B [ pregs + imm16 ] (%c)\n",
3123 $$ = LDSTIDXI (&$5, &$1, 0, 2, $9.r0, $7);
3126 return yyerror ("Bad register or value for LOAD");
3129 | REG ASSIGN B LBRACK REG post_op RBRACK xpmod
3131 if (IS_DREG ($1) && IS_PREG ($5))
3133 notethat ("LDST: dregs = B [ pregs <post_op> ] (%c)\n",
3135 $$ = LDST (&$5, &$1, $6.x0, 2, $8.r0, 0);
3138 return yyerror ("Bad register for LOAD");
3141 | REG ASSIGN LBRACK REG _PLUS_PLUS REG RBRACK
3143 if (IS_DREG ($1) && IS_IREG ($4) && IS_MREG ($6))
3145 notethat ("dspLDST: dregs = [ iregs ++ mregs ]\n");
3146 $$ = DSPLDST(&$4, $6.regno & CODE_MASK, &$1, 3, 0);
3148 else if (IS_DREG ($1) && IS_PREG ($4) && IS_PREG ($6))
3150 notethat ("LDSTpmod: dregs = [ pregs ++ pregs ]\n");
3151 $$ = LDSTPMOD (&$4, &$1, &$6, 0, 0);
3154 return yyerror ("Bad register for LOAD");
3157 | REG ASSIGN LBRACK REG plus_minus got_or_expr RBRACK
3159 Expr_Node *tmp = $6;
3160 int ispreg = IS_PREG ($1);
3161 int isgot = IS_RELOC($6);
3164 return yyerror ("Preg expected for indirect");
3166 if (!IS_DREG ($1) && !ispreg)
3167 return yyerror ("Bad destination register for LOAD");
3170 tmp = unary (Expr_Op_Type_NEG, tmp);
3173 notethat ("LDSTidxI: dpregs = [ pregs + sym@got ]\n");
3174 $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1: 0, tmp);
3176 else if (in_range_p (tmp, 0, 63, 3))
3178 notethat ("LDSTii: dpregs = [ pregs + uimm7m4 ]\n");
3179 $$ = LDSTII (&$4, &$1, tmp, 0, ispreg ? 3 : 0);
3181 else if ($4.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
3183 notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
3184 tmp = unary (Expr_Op_Type_NEG, tmp);
3185 $$ = LDSTIIFP (tmp, &$1, 0);
3187 else if (in_range_p (tmp, -131072, 131071, 3))
3189 notethat ("LDSTidxI: dpregs = [ pregs + imm18m4 ]\n");
3190 $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1: 0, tmp);
3194 return yyerror ("Displacement out of range for load");
3197 | REG ASSIGN LBRACK REG post_op RBRACK
3199 if (IS_DREG ($1) && IS_IREG ($4))
3201 notethat ("dspLDST: dregs = [ iregs <post_op> ]\n");
3202 $$ = DSPLDST (&$4, 0, &$1, $5.x0, 0);
3204 else if (IS_DREG ($1) && IS_PREG ($4))
3206 notethat ("LDST: dregs = [ pregs <post_op> ]\n");
3207 $$ = LDST (&$4, &$1, $5.x0, 0, 0, 0);
3209 else if (IS_PREG ($1) && IS_PREG ($4))
3211 if (REG_SAME ($1, $4) && $5.x0 != 2)
3212 return yyerror ("Pregs can't be same");
3214 notethat ("LDST: pregs = [ pregs <post_op> ]\n");
3215 $$ = LDST (&$4, &$1, $5.x0, 0, 1, 0);
3217 else if ($4.regno == REG_SP && IS_ALLREG ($1) && $5.x0 == 0)
3219 notethat ("PushPopReg: allregs = [ SP ++ ]\n");
3220 $$ = PUSHPOPREG (&$1, 0);
3223 return yyerror ("Bad register or value");
3227 /* PushPopMultiple. */
3228 | reg_with_predec ASSIGN LPAREN REG COLON expr COMMA REG COLON expr RPAREN
3230 if ($1.regno != REG_SP)
3231 yyerror ("Stack Pointer expected");
3232 if ($4.regno == REG_R7
3233 && IN_RANGE ($6, 0, 7)
3234 && $8.regno == REG_P5
3235 && IN_RANGE ($10, 0, 5))
3237 notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim , P5 : reglim )\n");
3238 $$ = PUSHPOPMULTIPLE (imm5 ($6), imm5 ($10), 1, 1, 1);
3241 return yyerror ("Bad register for PushPopMultiple");
3244 | reg_with_predec ASSIGN LPAREN REG COLON expr RPAREN
3246 if ($1.regno != REG_SP)
3247 yyerror ("Stack Pointer expected");
3249 if ($4.regno == REG_R7 && IN_RANGE ($6, 0, 7))
3251 notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim )\n");
3252 $$ = PUSHPOPMULTIPLE (imm5 ($6), 0, 1, 0, 1);
3254 else if ($4.regno == REG_P5 && IN_RANGE ($6, 0, 6))
3256 notethat ("PushPopMultiple: [ -- SP ] = (P5 : reglim )\n");
3257 $$ = PUSHPOPMULTIPLE (0, imm5 ($6), 0, 1, 1);
3260 return yyerror ("Bad register for PushPopMultiple");
3263 | LPAREN REG COLON expr COMMA REG COLON expr RPAREN ASSIGN reg_with_postinc
3265 if ($11.regno != REG_SP)
3266 yyerror ("Stack Pointer expected");
3267 if ($2.regno == REG_R7 && (IN_RANGE ($4, 0, 7))
3268 && $6.regno == REG_P5 && (IN_RANGE ($8, 0, 6)))
3270 notethat ("PushPopMultiple: (R7 : reglim , P5 : reglim ) = [ SP ++ ]\n");
3271 $$ = PUSHPOPMULTIPLE (imm5 ($4), imm5 ($8), 1, 1, 0);
3274 return yyerror ("Bad register range for PushPopMultiple");
3277 | LPAREN REG COLON expr RPAREN ASSIGN reg_with_postinc
3279 if ($7.regno != REG_SP)
3280 yyerror ("Stack Pointer expected");
3282 if ($2.regno == REG_R7 && IN_RANGE ($4, 0, 7))
3284 notethat ("PushPopMultiple: (R7 : reglim ) = [ SP ++ ]\n");
3285 $$ = PUSHPOPMULTIPLE (imm5 ($4), 0, 1, 0, 0);
3287 else if ($2.regno == REG_P5 && IN_RANGE ($4, 0, 6))
3289 notethat ("PushPopMultiple: (P5 : reglim ) = [ SP ++ ]\n");
3290 $$ = PUSHPOPMULTIPLE (0, imm5 ($4), 0, 1, 0);
3293 return yyerror ("Bad register range for PushPopMultiple");
3296 | reg_with_predec ASSIGN REG
3298 if ($1.regno != REG_SP)
3299 yyerror ("Stack Pointer expected");
3303 notethat ("PushPopReg: [ -- SP ] = allregs\n");
3304 $$ = PUSHPOPREG (&$3, 1);
3307 return yyerror ("Bad register for PushPopReg");
3314 if (IS_URANGE (16, $2, 0, 4))
3315 $$ = LINKAGE (0, uimm16s4 ($2));
3317 return yyerror ("Bad constant for LINK");
3322 notethat ("linkage: UNLINK\n");
3323 $$ = LINKAGE (1, 0);
3329 | LSETUP LPAREN expr COMMA expr RPAREN REG
3331 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5) && IS_CREG ($7))
3333 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters\n");
3334 $$ = LOOPSETUP ($3, &$7, 0, $5, 0);
3337 return yyerror ("Bad register or values for LSETUP");
3340 | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG
3342 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
3343 && IS_PREG ($9) && IS_CREG ($7))
3345 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs\n");
3346 $$ = LOOPSETUP ($3, &$7, 1, $5, &$9);
3349 return yyerror ("Bad register or values for LSETUP");
3352 | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG GREATER_GREATER expr
3354 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
3355 && IS_PREG ($9) && IS_CREG ($7)
3356 && EXPR_VALUE ($11) == 1)
3358 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs >> 1\n");
3359 $$ = LOOPSETUP ($3, &$7, 3, $5, &$9);
3362 return yyerror ("Bad register or values for LSETUP");
3369 return yyerror ("Invalid expression in loop statement");
3371 return yyerror ("Invalid loop counter register");
3372 $$ = bfin_gen_loop ($2, &$3, 0, 0);
3374 | LOOP expr REG ASSIGN REG
3376 if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3))
3378 notethat ("Loop: LOOP expr counters = pregs\n");
3379 $$ = bfin_gen_loop ($2, &$3, 1, &$5);
3382 return yyerror ("Bad register or values for LOOP");
3384 | LOOP expr REG ASSIGN REG GREATER_GREATER expr
3386 if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3) && EXPR_VALUE ($7) == 1)
3388 notethat ("Loop: LOOP expr counters = pregs >> 1\n");
3389 $$ = bfin_gen_loop ($2, &$3, 3, &$5);
3392 return yyerror ("Bad register or values for LOOP");
3398 notethat ("pseudoDEBUG: DBG\n");
3399 $$ = bfin_gen_pseudodbg (3, 7, 0);
3403 notethat ("pseudoDEBUG: DBG REG_A\n");
3404 $$ = bfin_gen_pseudodbg (3, IS_A1 ($2), 0);
3408 notethat ("pseudoDEBUG: DBG allregs\n");
3409 $$ = bfin_gen_pseudodbg (0, $2.regno & CODE_MASK, $2.regno & CLASS_MASK);
3412 | DBGCMPLX LPAREN REG RPAREN
3415 return yyerror ("Dregs expected");
3416 notethat ("pseudoDEBUG: DBGCMPLX (dregs )\n");
3417 $$ = bfin_gen_pseudodbg (3, 6, $3.regno & CODE_MASK);
3422 notethat ("psedoDEBUG: DBGHALT\n");
3423 $$ = bfin_gen_pseudodbg (3, 5, 0);
3426 | DBGA LPAREN HALF_REG COMMA expr RPAREN
3428 notethat ("pseudodbg_assert: DBGA (dregs_lo , uimm16 )\n");
3429 $$ = bfin_gen_pseudodbg_assert (IS_H ($3), &$3, uimm16 ($5));
3432 | DBGAH LPAREN REG COMMA expr RPAREN
3434 notethat ("pseudodbg_assert: DBGAH (dregs , uimm16 )\n");
3435 $$ = bfin_gen_pseudodbg_assert (3, &$3, uimm16 ($5));
3438 | DBGAL LPAREN REG COMMA expr RPAREN
3440 notethat ("psedodbg_assert: DBGAL (dregs , uimm16 )\n");
3441 $$ = bfin_gen_pseudodbg_assert (2, &$3, uimm16 ($5));
3449 /* Register rules. */
3451 REG_A: REG_A_DOUBLE_ZERO
3469 | LPAREN M COMMA MMOD RPAREN
3474 | LPAREN MMOD COMMA M RPAREN
3479 | LPAREN MMOD RPAREN
3491 asr_asl: LPAREN ASL RPAREN
3572 | LPAREN asr_asl_0 RPAREN
3584 | LPAREN asr_asl_0 COMMA sco RPAREN
3590 | LPAREN sco COMMA asr_asl_0 RPAREN
3650 | LPAREN V COMMA S RPAREN
3655 | LPAREN S COMMA V RPAREN
3717 | LPAREN MMOD RPAREN
3720 return yyerror ("Bad modifier");
3724 | LPAREN MMOD COMMA R RPAREN
3727 return yyerror ("Bad modifier");
3731 | LPAREN R COMMA MMOD RPAREN
3734 return yyerror ("Bad modifier");
3761 | LPAREN MMOD RPAREN
3766 return yyerror ("Only (W32) allowed");
3774 | LPAREN MMOD RPAREN
3779 return yyerror ("(IU) expected");
3783 reg_with_predec: LBRACK _MINUS_MINUS REG RBRACK
3789 reg_with_postinc: LBRACK REG _PLUS_PLUS RBRACK
3841 $$.r0 = 1; /* HL. */
3844 $$.aop = 0; /* aop. */
3849 $$.r0 = 1; /* HL. */
3852 $$.aop = 1; /* aop. */
3855 | LPAREN RNDL RPAREN
3857 $$.r0 = 0; /* HL. */
3860 $$.aop = 0; /* aop. */
3865 $$.r0 = 0; /* HL. */
3871 | LPAREN RNDH COMMA R RPAREN
3873 $$.r0 = 1; /* HL. */
3876 $$.aop = 0; /* aop. */
3878 | LPAREN TH COMMA R RPAREN
3880 $$.r0 = 1; /* HL. */
3883 $$.aop = 1; /* aop. */
3885 | LPAREN RNDL COMMA R RPAREN
3887 $$.r0 = 0; /* HL. */
3890 $$.aop = 0; /* aop. */
3893 | LPAREN TL COMMA R RPAREN
3895 $$.r0 = 0; /* HL. */
3898 $$.aop = 1; /* aop. */
3906 $$.x0 = 0; /* HL. */
3911 $$.x0 = 1; /* HL. */
3913 | LPAREN LO COMMA R RPAREN
3916 $$.x0 = 0; /* HL. */
3918 | LPAREN HI COMMA R RPAREN
3921 $$.x0 = 1; /* HL. */
3939 /* Assignments, Macfuncs. */
3973 if (IS_A1 ($3) && IS_EVEN ($1))
3974 return yyerror ("Cannot move A1 to even register");
3975 else if (!IS_A1 ($3) && !IS_EVEN ($1))
3976 return yyerror ("Cannot move A0 to odd register");
3984 | REG ASSIGN LPAREN a_macfunc RPAREN
3992 | HALF_REG ASSIGN LPAREN a_macfunc RPAREN
4000 | HALF_REG ASSIGN REG_A
4010 if (IS_A1 ($3) && !IS_H ($1))
4011 return yyerror ("Cannot move A1 to low half of register");
4012 else if (!IS_A1 ($3) && IS_H ($1))
4013 return yyerror ("Cannot move A0 to high half of register");
4018 a_assign multiply_halfregs
4025 | a_plusassign multiply_halfregs
4032 | a_minusassign multiply_halfregs
4042 HALF_REG STAR HALF_REG
4044 if (IS_DREG ($1) && IS_DREG ($3))
4050 return yyerror ("Dregs expected");
4074 CCREG cc_op STATUS_REG
4086 | STATUS_REG cc_op CCREG
4100 /* Expressions and Symbols. */
4104 Expr_Node_Value val;
4105 val.s_value = S_GET_NAME($1);
4106 $$ = Expr_Node_Create (Expr_Node_Reloc, val, NULL, NULL);
4112 { $$ = BFD_RELOC_BFIN_GOT; }
4114 { $$ = BFD_RELOC_BFIN_GOT17M4; }
4116 { $$ = BFD_RELOC_BFIN_FUNCDESC_GOT17M4; }
4119 got: symbol AT any_gotrel
4121 Expr_Node_Value val;
4123 $$ = Expr_Node_Create (Expr_Node_GOT_Reloc, val, $1, NULL);
4146 Expr_Node_Value val;
4148 $$ = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
4154 | LPAREN expr_1 RPAREN
4160 $$ = unary (Expr_Op_Type_COMP, $2);
4162 | MINUS expr_1 %prec TILDA
4164 $$ = unary (Expr_Op_Type_NEG, $2);
4174 expr_1: expr_1 STAR expr_1
4176 $$ = binary (Expr_Op_Type_Mult, $1, $3);
4178 | expr_1 SLASH expr_1
4180 $$ = binary (Expr_Op_Type_Div, $1, $3);
4182 | expr_1 PERCENT expr_1
4184 $$ = binary (Expr_Op_Type_Mod, $1, $3);
4186 | expr_1 PLUS expr_1
4188 $$ = binary (Expr_Op_Type_Add, $1, $3);
4190 | expr_1 MINUS expr_1
4192 $$ = binary (Expr_Op_Type_Sub, $1, $3);
4194 | expr_1 LESS_LESS expr_1
4196 $$ = binary (Expr_Op_Type_Lshift, $1, $3);
4198 | expr_1 GREATER_GREATER expr_1
4200 $$ = binary (Expr_Op_Type_Rshift, $1, $3);
4202 | expr_1 AMPERSAND expr_1
4204 $$ = binary (Expr_Op_Type_BAND, $1, $3);
4206 | expr_1 CARET expr_1
4208 $$ = binary (Expr_Op_Type_LOR, $1, $3);
4212 $$ = binary (Expr_Op_Type_BOR, $1, $3);
4224 mkexpr (int x, SYMBOL_T s)
4226 EXPR_T e = (EXPR_T) ALLOCATE (sizeof (struct expression_cell));
4233 value_match (Expr_Node *expr, int sz, int sign, int mul, int issigned)
4235 long umax = (1L << sz) - 1;
4236 long min = -1L << (sz - 1);
4237 long max = (1L << (sz - 1)) - 1;
4239 long v = EXPR_VALUE (expr);
4243 error ("%s:%d: Value Error -- Must align to %d\n", __FILE__, __LINE__, mul);
4254 if (v >= min && v <= max) return 1;
4257 fprintf(stderr, "signed value %lx out of range\n", v * mul);
4261 if (v <= umax && v >= 0)
4264 fprintf(stderr, "unsigned value %lx out of range\n", v * mul);
4269 /* Return the expression structure that allows symbol operations.
4270 If the left and right children are constants, do the operation. */
4272 binary (Expr_Op_Type op, Expr_Node *x, Expr_Node *y)
4274 if (x->type == Expr_Node_Constant && y->type == Expr_Node_Constant)
4278 case Expr_Op_Type_Add:
4279 x->value.i_value += y->value.i_value;
4281 case Expr_Op_Type_Sub:
4282 x->value.i_value -= y->value.i_value;
4284 case Expr_Op_Type_Mult:
4285 x->value.i_value *= y->value.i_value;
4287 case Expr_Op_Type_Div:
4288 if (y->value.i_value == 0)
4289 error ("Illegal Expression: Division by zero.");
4291 x->value.i_value /= y->value.i_value;
4293 case Expr_Op_Type_Mod:
4294 x->value.i_value %= y->value.i_value;
4296 case Expr_Op_Type_Lshift:
4297 x->value.i_value <<= y->value.i_value;
4299 case Expr_Op_Type_Rshift:
4300 x->value.i_value >>= y->value.i_value;
4302 case Expr_Op_Type_BAND:
4303 x->value.i_value &= y->value.i_value;
4305 case Expr_Op_Type_BOR:
4306 x->value.i_value |= y->value.i_value;
4308 case Expr_Op_Type_BXOR:
4309 x->value.i_value ^= y->value.i_value;
4311 case Expr_Op_Type_LAND:
4312 x->value.i_value = x->value.i_value && y->value.i_value;
4314 case Expr_Op_Type_LOR:
4315 x->value.i_value = x->value.i_value || y->value.i_value;
4319 error ("%s:%d: Internal compiler error\n", __FILE__, __LINE__);
4325 /* Create a new expression structure. */
4326 Expr_Node_Value val;
4328 return Expr_Node_Create (Expr_Node_Binop, val, x, y);
4333 unary (Expr_Op_Type op, Expr_Node *x)
4335 if (x->type == Expr_Node_Constant)
4339 case Expr_Op_Type_NEG:
4340 x->value.i_value = -x->value.i_value;
4342 case Expr_Op_Type_COMP:
4343 x->value.i_value = ~x->value.i_value;
4346 error ("%s:%d: Internal compiler error\n", __FILE__, __LINE__);
4352 /* Create a new expression structure. */
4353 Expr_Node_Value val;
4355 return Expr_Node_Create (Expr_Node_Unop, val, x, NULL);
4359 int debug_codeselection = 0;
4361 notethat (char *format, ...)
4364 va_start (ap, format);
4365 if (debug_codeselection)
4367 vfprintf (errorf, format, ap);
4373 main (int argc, char **argv)