Add -Wshadow to the gcc command line options used when compiling the binutils.
[binutils.git] / gas / config / bfin-parse.y
blob311246080a63bd280bf106ede38c765a5aeb426d
1 /* bfin-parse.y ADI Blackfin parser
2 Copyright 2005, 2006, 2007, 2008, 2009
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20 02110-1301, USA. */
23 #include "as.h"
24 #include <obstack.h>
26 #include "bfin-aux.h" /* Opcode generating auxiliaries. */
27 #include "libbfd.h"
28 #include "elf/common.h"
29 #include "elf/bfin.h"
31 #define DSP32ALU(aopcde, HL, dst1, dst0, src0, src1, s, x, aop) \
32 bfin_gen_dsp32alu (HL, aopcde, aop, s, x, dst0, dst1, src0, src1)
34 #define DSP32MAC(op1, MM, mmod, w1, P, h01, h11, h00, h10, dst, op0, src0, src1, w0) \
35 bfin_gen_dsp32mac (op1, MM, mmod, w1, P, h01, h11, h00, h10, op0, \
36 dst, src0, src1, w0)
38 #define DSP32MULT(op1, MM, mmod, w1, P, h01, h11, h00, h10, dst, op0, src0, src1, w0) \
39 bfin_gen_dsp32mult (op1, MM, mmod, w1, P, h01, h11, h00, h10, op0, \
40 dst, src0, src1, w0)
42 #define DSP32SHIFT(sopcde, dst0, src0, src1, sop, hls) \
43 bfin_gen_dsp32shift (sopcde, dst0, src0, src1, sop, hls)
45 #define DSP32SHIFTIMM(sopcde, dst0, immag, src1, sop, hls) \
46 bfin_gen_dsp32shiftimm (sopcde, dst0, immag, src1, sop, hls)
48 #define LDIMMHALF_R(reg, h, s, z, hword) \
49 bfin_gen_ldimmhalf (reg, h, s, z, hword, 1)
51 #define LDIMMHALF_R5(reg, h, s, z, hword) \
52 bfin_gen_ldimmhalf (reg, h, s, z, hword, 2)
54 #define LDSTIDXI(ptr, reg, w, sz, z, offset) \
55 bfin_gen_ldstidxi (ptr, reg, w, sz, z, offset)
57 #define LDST(ptr, reg, aop, sz, z, w) \
58 bfin_gen_ldst (ptr, reg, aop, sz, z, w)
60 #define LDSTII(ptr, reg, offset, w, op) \
61 bfin_gen_ldstii (ptr, reg, offset, w, op)
63 #define DSPLDST(i, m, reg, aop, w) \
64 bfin_gen_dspldst (i, reg, aop, w, m)
66 #define LDSTPMOD(ptr, reg, idx, aop, w) \
67 bfin_gen_ldstpmod (ptr, reg, aop, w, idx)
69 #define LDSTIIFP(offset, reg, w) \
70 bfin_gen_ldstiifp (reg, offset, w)
72 #define LOGI2OP(dst, src, opc) \
73 bfin_gen_logi2op (opc, src, dst.regno & CODE_MASK)
75 #define ALU2OP(dst, src, opc) \
76 bfin_gen_alu2op (dst, src, opc)
78 #define BRCC(t, b, offset) \
79 bfin_gen_brcc (t, b, offset)
81 #define UJUMP(offset) \
82 bfin_gen_ujump (offset)
84 #define PROGCTRL(prgfunc, poprnd) \
85 bfin_gen_progctrl (prgfunc, poprnd)
87 #define PUSHPOPMULTIPLE(dr, pr, d, p, w) \
88 bfin_gen_pushpopmultiple (dr, pr, d, p, w)
90 #define PUSHPOPREG(reg, w) \
91 bfin_gen_pushpopreg (reg, w)
93 #define CALLA(addr, s) \
94 bfin_gen_calla (addr, s)
96 #define LINKAGE(r, framesize) \
97 bfin_gen_linkage (r, framesize)
99 #define COMPI2OPD(dst, src, op) \
100 bfin_gen_compi2opd (dst, src, op)
102 #define COMPI2OPP(dst, src, op) \
103 bfin_gen_compi2opp (dst, src, op)
105 #define DAGMODIK(i, op) \
106 bfin_gen_dagmodik (i, op)
108 #define DAGMODIM(i, m, op, br) \
109 bfin_gen_dagmodim (i, m, op, br)
111 #define COMP3OP(dst, src0, src1, opc) \
112 bfin_gen_comp3op (src0, src1, dst, opc)
114 #define PTR2OP(dst, src, opc) \
115 bfin_gen_ptr2op (dst, src, opc)
117 #define CCFLAG(x, y, opc, i, g) \
118 bfin_gen_ccflag (x, y, opc, i, g)
120 #define CCMV(src, dst, t) \
121 bfin_gen_ccmv (src, dst, t)
123 #define CACTRL(reg, a, op) \
124 bfin_gen_cactrl (reg, a, op)
126 #define LOOPSETUP(soffset, c, rop, eoffset, reg) \
127 bfin_gen_loopsetup (soffset, c, rop, eoffset, reg)
129 #define HL2(r1, r0) (IS_H (r1) << 1 | IS_H (r0))
130 #define IS_RANGE(bits, expr, sign, mul) \
131 value_match(expr, bits, sign, mul, 1)
132 #define IS_URANGE(bits, expr, sign, mul) \
133 value_match(expr, bits, sign, mul, 0)
134 #define IS_CONST(expr) (expr->type == Expr_Node_Constant)
135 #define IS_RELOC(expr) (expr->type != Expr_Node_Constant)
136 #define IS_IMM(expr, bits) value_match (expr, bits, 0, 1, 1)
137 #define IS_UIMM(expr, bits) value_match (expr, bits, 0, 1, 0)
139 #define IS_PCREL4(expr) \
140 (value_match (expr, 4, 0, 2, 0))
142 #define IS_LPPCREL10(expr) \
143 (value_match (expr, 10, 0, 2, 0))
145 #define IS_PCREL10(expr) \
146 (value_match (expr, 10, 0, 2, 1))
148 #define IS_PCREL12(expr) \
149 (value_match (expr, 12, 0, 2, 1))
151 #define IS_PCREL24(expr) \
152 (value_match (expr, 24, 0, 2, 1))
155 static int value_match (Expr_Node *expr, int sz, int sign, int mul, int issigned);
157 extern FILE *errorf;
158 extern INSTR_T insn;
160 static Expr_Node *binary (Expr_Op_Type, Expr_Node *, Expr_Node *);
161 static Expr_Node *unary (Expr_Op_Type, Expr_Node *);
163 static void notethat (char *format, ...);
165 char *current_inputline;
166 extern char *yytext;
167 int yyerror (char *msg);
169 void error (char *format, ...)
171 va_list ap;
172 static char buffer[2000];
174 va_start (ap, format);
175 vsprintf (buffer, format, ap);
176 va_end (ap);
178 as_bad ("%s", buffer);
182 yyerror (char *msg)
184 if (msg[0] == '\0')
185 error ("%s", msg);
187 else if (yytext[0] != ';')
188 error ("%s. Input text was %s.", msg, yytext);
189 else
190 error ("%s.", msg);
192 return -1;
195 static int
196 in_range_p (Expr_Node *exp, int from, int to, unsigned int mask)
198 int val = EXPR_VALUE (exp);
199 if (exp->type != Expr_Node_Constant)
200 return 0;
201 if (val < from || val > to)
202 return 0;
203 return (val & mask) == 0;
206 extern int yylex (void);
208 #define imm3(x) EXPR_VALUE (x)
209 #define imm4(x) EXPR_VALUE (x)
210 #define uimm4(x) EXPR_VALUE (x)
211 #define imm5(x) EXPR_VALUE (x)
212 #define uimm5(x) EXPR_VALUE (x)
213 #define imm6(x) EXPR_VALUE (x)
214 #define imm7(x) EXPR_VALUE (x)
215 #define imm16(x) EXPR_VALUE (x)
216 #define uimm16s4(x) ((EXPR_VALUE (x)) >> 2)
217 #define uimm16(x) EXPR_VALUE (x)
219 /* Return true if a value is inside a range. */
220 #define IN_RANGE(x, low, high) \
221 (((EXPR_VALUE(x)) >= (low)) && (EXPR_VALUE(x)) <= ((high)))
223 /* Auxiliary functions. */
225 static int
226 valid_dreg_pair (Register *reg1, Expr_Node *reg2)
228 if (!IS_DREG (*reg1))
230 yyerror ("Dregs expected");
231 return 0;
234 if (reg1->regno != 1 && reg1->regno != 3)
236 yyerror ("Bad register pair");
237 return 0;
240 if (imm7 (reg2) != reg1->regno - 1)
242 yyerror ("Bad register pair");
243 return 0;
246 reg1->regno--;
247 return 1;
250 static int
251 check_multiply_halfregs (Macfunc *aa, Macfunc *ab)
253 if ((!REG_EQUAL (aa->s0, ab->s0) && !REG_EQUAL (aa->s0, ab->s1))
254 || (!REG_EQUAL (aa->s1, ab->s1) && !REG_EQUAL (aa->s1, ab->s0)))
255 return yyerror ("Source multiplication register mismatch");
257 return 0;
261 /* Check mac option. */
263 static int
264 check_macfunc_option (Macfunc *a, Opt_mode *opt)
266 /* Default option is always valid. */
267 if (opt->mod == 0)
268 return 0;
270 if ((a->w == 1 && a->P == 1
271 && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_IU
272 && opt->mod != M_S2RND && opt->mod != M_ISS2)
273 || (a->w == 1 && a->P == 0
274 && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_IU
275 && opt->mod != M_T && opt->mod != M_TFU && opt->mod != M_S2RND
276 && opt->mod != M_ISS2 && opt->mod != M_IH)
277 || (a->w == 0 && a->P == 0
278 && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_W32))
279 return -1;
281 return 0;
284 /* Check (vector) mac funcs and ops. */
286 static int
287 check_macfuncs (Macfunc *aa, Opt_mode *opa,
288 Macfunc *ab, Opt_mode *opb)
290 /* Variables for swapping. */
291 Macfunc mtmp;
292 Opt_mode otmp;
294 /* The option mode should be put at the end of the second instruction
295 of the vector except M, which should follow MAC1 instruction. */
296 if (opa->mod != 0)
297 return yyerror ("Bad opt mode");
299 /* If a0macfunc comes before a1macfunc, swap them. */
301 if (aa->n == 0)
303 /* (M) is not allowed here. */
304 if (opa->MM != 0)
305 return yyerror ("(M) not allowed with A0MAC");
306 if (ab->n != 1)
307 return yyerror ("Vector AxMACs can't be same");
309 mtmp = *aa; *aa = *ab; *ab = mtmp;
310 otmp = *opa; *opa = *opb; *opb = otmp;
312 else
314 if (opb->MM != 0)
315 return yyerror ("(M) not allowed with A0MAC");
316 if (ab->n != 0)
317 return yyerror ("Vector AxMACs can't be same");
320 /* If both ops are one of 0, 1, or 2, we have multiply_halfregs in both
321 assignment_or_macfuncs. */
322 if ((aa->op == 0 || aa->op == 1 || aa->op == 2)
323 && (ab->op == 0 || ab->op == 1 || ab->op == 2))
325 if (check_multiply_halfregs (aa, ab) < 0)
326 return -1;
328 else
330 /* Only one of the assign_macfuncs has a half reg multiply
331 Evil trick: Just 'OR' their source register codes:
332 We can do that, because we know they were initialized to 0
333 in the rules that don't use multiply_halfregs. */
334 aa->s0.regno |= (ab->s0.regno & CODE_MASK);
335 aa->s1.regno |= (ab->s1.regno & CODE_MASK);
338 if (aa->w == ab->w && aa->P != ab->P)
340 return yyerror ("macfuncs must differ");
341 if (aa->w && (aa->dst.regno - ab->dst.regno != 1))
342 return yyerror ("Destination Dregs must differ by one");
345 /* Make sure mod flags get ORed, too. */
346 opb->mod |= opa->mod;
348 /* Check option. */
349 if (check_macfunc_option (aa, opb) < 0
350 && check_macfunc_option (ab, opb) < 0)
351 return yyerror ("bad option");
353 /* Make sure first macfunc has got both P flags ORed. */
354 aa->P |= ab->P;
356 return 0;
360 static int
361 is_group1 (INSTR_T x)
363 /* Group1 is dpsLDST, LDSTpmod, LDST, LDSTiiFP, LDSTii. */
364 if ((x->value & 0xc000) == 0x8000 || (x->value == 0x0000))
365 return 1;
367 return 0;
370 static int
371 is_group2 (INSTR_T x)
373 if ((((x->value & 0xfc00) == 0x9c00) /* dspLDST. */
374 && !((x->value & 0xfde0) == 0x9c60) /* dagMODim. */
375 && !((x->value & 0xfde0) == 0x9ce0) /* dagMODim with bit rev. */
376 && !((x->value & 0xfde0) == 0x9d60)) /* pick dagMODik. */
377 || (x->value == 0x0000))
378 return 1;
379 return 0;
382 static INSTR_T
383 gen_multi_instr_1 (INSTR_T dsp32, INSTR_T dsp16_grp1, INSTR_T dsp16_grp2)
385 int mask1 = dsp32 ? insn_regmask (dsp32->value, dsp32->next->value) : 0;
386 int mask2 = dsp16_grp1 ? insn_regmask (dsp16_grp1->value, 0) : 0;
387 int mask3 = dsp16_grp2 ? insn_regmask (dsp16_grp2->value, 0) : 0;
389 if ((mask1 & mask2) || (mask1 & mask3) || (mask2 & mask3))
390 yyerror ("resource conflict in multi-issue instruction");
392 /* Anomaly 05000074 */
393 if (ENABLE_AC_05000074
394 && dsp32 != NULL && dsp16_grp1 != NULL
395 && (dsp32->value & 0xf780) == 0xc680
396 && ((dsp16_grp1->value & 0xfe40) == 0x9240
397 || (dsp16_grp1->value & 0xfe08) == 0xba08
398 || (dsp16_grp1->value & 0xfc00) == 0xbc00))
399 yyerror ("anomaly 05000074 - Multi-Issue Instruction with \
400 dsp32shiftimm in slot1 and P-reg Store in slot2 Not Supported");
402 return bfin_gen_multi_instr (dsp32, dsp16_grp1, dsp16_grp2);
407 %union {
408 INSTR_T instr;
409 Expr_Node *expr;
410 SYMBOL_T symbol;
411 long value;
412 Register reg;
413 Macfunc macfunc;
414 struct { int r0; int s0; int x0; int aop; } modcodes;
415 struct { int r0; } r0;
416 Opt_mode mod;
420 /* Tokens. */
422 /* Vector Specific. */
423 %token BYTEOP16P BYTEOP16M
424 %token BYTEOP1P BYTEOP2P BYTEOP2M BYTEOP3P
425 %token BYTEUNPACK BYTEPACK
426 %token PACK
427 %token SAA
428 %token ALIGN8 ALIGN16 ALIGN24
429 %token VIT_MAX
430 %token EXTRACT DEPOSIT EXPADJ SEARCH
431 %token ONES SIGN SIGNBITS
433 /* Stack. */
434 %token LINK UNLINK
436 /* Registers. */
437 %token REG
438 %token PC
439 %token CCREG BYTE_DREG
440 %token REG_A_DOUBLE_ZERO REG_A_DOUBLE_ONE
441 %token A_ZERO_DOT_L A_ZERO_DOT_H A_ONE_DOT_L A_ONE_DOT_H
442 %token HALF_REG
444 /* Progctrl. */
445 %token NOP
446 %token RTI RTS RTX RTN RTE
447 %token HLT IDLE
448 %token STI CLI
449 %token CSYNC SSYNC
450 %token EMUEXCPT
451 %token RAISE EXCPT
452 %token LSETUP
453 %token LOOP
454 %token LOOP_BEGIN
455 %token LOOP_END
456 %token DISALGNEXCPT
457 %token JUMP JUMP_DOT_S JUMP_DOT_L
458 %token CALL
460 /* Emulator only. */
461 %token ABORT
463 /* Operators. */
464 %token NOT TILDA BANG
465 %token AMPERSAND BAR
466 %token PERCENT
467 %token CARET
468 %token BXOR
470 %token MINUS PLUS STAR SLASH
471 %token NEG
472 %token MIN MAX ABS
473 %token DOUBLE_BAR
474 %token _PLUS_BAR_PLUS _PLUS_BAR_MINUS _MINUS_BAR_PLUS _MINUS_BAR_MINUS
475 %token _MINUS_MINUS _PLUS_PLUS
477 /* Shift/rotate ops. */
478 %token SHIFT LSHIFT ASHIFT BXORSHIFT
479 %token _GREATER_GREATER_GREATER_THAN_ASSIGN
480 %token ROT
481 %token LESS_LESS GREATER_GREATER
482 %token _GREATER_GREATER_GREATER
483 %token _LESS_LESS_ASSIGN _GREATER_GREATER_ASSIGN
484 %token DIVS DIVQ
486 /* In place operators. */
487 %token ASSIGN _STAR_ASSIGN
488 %token _BAR_ASSIGN _CARET_ASSIGN _AMPERSAND_ASSIGN
489 %token _MINUS_ASSIGN _PLUS_ASSIGN
491 /* Assignments, comparisons. */
492 %token _ASSIGN_BANG _LESS_THAN_ASSIGN _ASSIGN_ASSIGN
493 %token GE LT LE GT
494 %token LESS_THAN
496 /* Cache. */
497 %token FLUSHINV FLUSH
498 %token IFLUSH PREFETCH
500 /* Misc. */
501 %token PRNT
502 %token OUTC
503 %token WHATREG
504 %token TESTSET
506 /* Modifiers. */
507 %token ASL ASR
508 %token B W
509 %token NS S CO SCO
510 %token TH TL
511 %token BP
512 %token BREV
513 %token X Z
514 %token M MMOD
515 %token R RND RNDL RNDH RND12 RND20
516 %token V
517 %token LO HI
519 /* Bit ops. */
520 %token BITTGL BITCLR BITSET BITTST BITMUX
522 /* Debug. */
523 %token DBGAL DBGAH DBGHALT DBG DBGA DBGCMPLX
525 /* Semantic auxiliaries. */
527 %token IF COMMA BY
528 %token COLON SEMICOLON
529 %token RPAREN LPAREN LBRACK RBRACK
530 %token STATUS_REG
531 %token MNOP
532 %token SYMBOL NUMBER
533 %token GOT GOT17M4 FUNCDESC_GOT17M4
534 %token AT PLTPC
536 /* Types. */
537 %type <instr> asm
538 %type <value> MMOD
539 %type <mod> opt_mode
541 %type <value> NUMBER
542 %type <r0> aligndir
543 %type <modcodes> byteop_mod
544 %type <reg> a_assign
545 %type <reg> a_plusassign
546 %type <reg> a_minusassign
547 %type <macfunc> multiply_halfregs
548 %type <macfunc> assign_macfunc
549 %type <macfunc> a_macfunc
550 %type <expr> expr_1
551 %type <instr> asm_1
552 %type <r0> vmod
553 %type <modcodes> vsmod
554 %type <modcodes> ccstat
555 %type <r0> cc_op
556 %type <reg> CCREG
557 %type <reg> reg_with_postinc
558 %type <reg> reg_with_predec
560 %type <r0> searchmod
561 %type <expr> symbol
562 %type <symbol> SYMBOL
563 %type <expr> eterm
564 %type <reg> REG
565 %type <reg> BYTE_DREG
566 %type <reg> REG_A_DOUBLE_ZERO
567 %type <reg> REG_A_DOUBLE_ONE
568 %type <reg> REG_A
569 %type <reg> STATUS_REG
570 %type <expr> expr
571 %type <r0> xpmod
572 %type <r0> xpmod1
573 %type <modcodes> smod
574 %type <modcodes> b3_op
575 %type <modcodes> rnd_op
576 %type <modcodes> post_op
577 %type <reg> HALF_REG
578 %type <r0> iu_or_nothing
579 %type <r0> plus_minus
580 %type <r0> asr_asl
581 %type <r0> asr_asl_0
582 %type <modcodes> sco
583 %type <modcodes> amod0
584 %type <modcodes> amod1
585 %type <modcodes> amod2
586 %type <r0> op_bar_op
587 %type <r0> w32_or_nothing
588 %type <r0> c_align
589 %type <r0> min_max
590 %type <expr> got
591 %type <expr> got_or_expr
592 %type <expr> pltpc
593 %type <value> any_gotrel GOT GOT17M4 FUNCDESC_GOT17M4
595 /* Precedence rules. */
596 %left BAR
597 %left CARET
598 %left AMPERSAND
599 %left LESS_LESS GREATER_GREATER
600 %left PLUS MINUS
601 %left STAR SLASH PERCENT
603 %right ASSIGN
605 %right TILDA BANG
606 %start statement
608 statement:
609 | asm
611 insn = $1;
612 if (insn == (INSTR_T) 0)
613 return NO_INSN_GENERATED;
614 else if (insn == (INSTR_T) - 1)
615 return SEMANTIC_ERROR;
616 else
617 return INSN_GENERATED;
621 asm: asm_1 SEMICOLON
622 /* Parallel instructions. */
623 | asm_1 DOUBLE_BAR asm_1 DOUBLE_BAR asm_1 SEMICOLON
625 if (($1->value & 0xf800) == 0xc000)
627 if (is_group1 ($3) && is_group2 ($5))
628 $$ = gen_multi_instr_1 ($1, $3, $5);
629 else if (is_group2 ($3) && is_group1 ($5))
630 $$ = gen_multi_instr_1 ($1, $5, $3);
631 else
632 return yyerror ("Wrong 16 bit instructions groups, slot 2 and slot 3 must be 16-bit instrution group");
634 else if (($3->value & 0xf800) == 0xc000)
636 if (is_group1 ($1) && is_group2 ($5))
637 $$ = gen_multi_instr_1 ($3, $1, $5);
638 else if (is_group2 ($1) && is_group1 ($5))
639 $$ = gen_multi_instr_1 ($3, $5, $1);
640 else
641 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 3 must be 16-bit instrution group");
643 else if (($5->value & 0xf800) == 0xc000)
645 if (is_group1 ($1) && is_group2 ($3))
646 $$ = gen_multi_instr_1 ($5, $1, $3);
647 else if (is_group2 ($1) && is_group1 ($3))
648 $$ = gen_multi_instr_1 ($5, $3, $1);
649 else
650 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be 16-bit instrution group");
652 else
653 error ("\nIllegal Multi Issue Construct, at least any one of the slot must be DSP32 instruction group\n");
656 | asm_1 DOUBLE_BAR asm_1 SEMICOLON
658 if (($1->value & 0xf800) == 0xc000)
660 if (is_group1 ($3))
661 $$ = gen_multi_instr_1 ($1, $3, 0);
662 else if (is_group2 ($3))
663 $$ = gen_multi_instr_1 ($1, 0, $3);
664 else
665 return yyerror ("Wrong 16 bit instructions groups, slot 2 must be the 16-bit instruction group");
667 else if (($3->value & 0xf800) == 0xc000)
669 if (is_group1 ($1))
670 $$ = gen_multi_instr_1 ($3, $1, 0);
671 else if (is_group2 ($1))
672 $$ = gen_multi_instr_1 ($3, 0, $1);
673 else
674 return yyerror ("Wrong 16 bit instructions groups, slot 1 must be the 16-bit instruction group");
676 else if (is_group1 ($1) && is_group2 ($3))
677 $$ = gen_multi_instr_1 (0, $1, $3);
678 else if (is_group2 ($1) && is_group1 ($3))
679 $$ = gen_multi_instr_1 (0, $3, $1);
680 else
681 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be the 16-bit instruction group");
683 | error
685 $$ = 0;
686 yyerror ("");
687 yyerrok;
691 /* DSPMAC. */
693 asm_1:
694 MNOP
696 $$ = DSP32MAC (3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
698 | assign_macfunc opt_mode
700 int op0, op1;
701 int w0 = 0, w1 = 0;
702 int h00, h10, h01, h11;
704 if (check_macfunc_option (&$1, &$2) < 0)
705 return yyerror ("bad option");
707 if ($1.n == 0)
709 if ($2.MM)
710 return yyerror ("(m) not allowed with a0 unit");
711 op1 = 3;
712 op0 = $1.op;
713 w1 = 0;
714 w0 = $1.w;
715 h00 = IS_H ($1.s0);
716 h10 = IS_H ($1.s1);
717 h01 = h11 = 0;
719 else
721 op1 = $1.op;
722 op0 = 3;
723 w1 = $1.w;
724 w0 = 0;
725 h00 = h10 = 0;
726 h01 = IS_H ($1.s0);
727 h11 = IS_H ($1.s1);
729 $$ = DSP32MAC (op1, $2.MM, $2.mod, w1, $1.P, h01, h11, h00, h10,
730 &$1.dst, op0, &$1.s0, &$1.s1, w0);
734 /* VECTOR MACs. */
736 | assign_macfunc opt_mode COMMA assign_macfunc opt_mode
738 Register *dst;
740 if (check_macfuncs (&$1, &$2, &$4, &$5) < 0)
741 return -1;
742 notethat ("assign_macfunc (.), assign_macfunc (.)\n");
744 if ($1.w)
745 dst = &$1.dst;
746 else
747 dst = &$4.dst;
749 $$ = DSP32MAC ($1.op, $2.MM, $5.mod, $1.w, $1.P,
750 IS_H ($1.s0), IS_H ($1.s1), IS_H ($4.s0), IS_H ($4.s1),
751 dst, $4.op, &$1.s0, &$1.s1, $4.w);
754 /* DSPALU. */
756 | DISALGNEXCPT
758 notethat ("dsp32alu: DISALGNEXCPT\n");
759 $$ = DSP32ALU (18, 0, 0, 0, 0, 0, 0, 0, 3);
761 | REG ASSIGN LPAREN a_plusassign REG_A RPAREN
763 if (IS_DREG ($1) && !IS_A1 ($4) && IS_A1 ($5))
765 notethat ("dsp32alu: dregs = ( A0 += A1 )\n");
766 $$ = DSP32ALU (11, 0, 0, &$1, 0, 0, 0, 0, 0);
768 else
769 return yyerror ("Register mismatch");
771 | HALF_REG ASSIGN LPAREN a_plusassign REG_A RPAREN
773 if (!IS_A1 ($4) && IS_A1 ($5))
775 notethat ("dsp32alu: dregs_half = ( A0 += A1 )\n");
776 $$ = DSP32ALU (11, IS_H ($1), 0, &$1, 0, 0, 0, 0, 1);
778 else
779 return yyerror ("Register mismatch");
781 | A_ZERO_DOT_H ASSIGN HALF_REG
783 notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
784 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
786 | A_ONE_DOT_H ASSIGN HALF_REG
788 notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
789 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
791 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16P LPAREN REG
792 COLON expr COMMA REG COLON expr RPAREN aligndir
794 if (!IS_DREG ($2) || !IS_DREG ($4))
795 return yyerror ("Dregs expected");
796 else if (!valid_dreg_pair (&$9, $11))
797 return yyerror ("Bad dreg pair");
798 else if (!valid_dreg_pair (&$13, $15))
799 return yyerror ("Bad dreg pair");
800 else
802 notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16P (dregs_pair , dregs_pair ) (half)\n");
803 $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 0);
807 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16M LPAREN REG COLON expr COMMA
808 REG COLON expr RPAREN aligndir
810 if (!IS_DREG ($2) || !IS_DREG ($4))
811 return yyerror ("Dregs expected");
812 else if (!valid_dreg_pair (&$9, $11))
813 return yyerror ("Bad dreg pair");
814 else if (!valid_dreg_pair (&$13, $15))
815 return yyerror ("Bad dreg pair");
816 else
818 notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16M (dregs_pair , dregs_pair ) (aligndir)\n");
819 $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 1);
823 | LPAREN REG COMMA REG RPAREN ASSIGN BYTEUNPACK REG COLON expr aligndir
825 if (!IS_DREG ($2) || !IS_DREG ($4))
826 return yyerror ("Dregs expected");
827 else if (!valid_dreg_pair (&$8, $10))
828 return yyerror ("Bad dreg pair");
829 else
831 notethat ("dsp32alu: (dregs , dregs ) = BYTEUNPACK dregs_pair (aligndir)\n");
832 $$ = DSP32ALU (24, 0, &$2, &$4, &$8, 0, $11.r0, 0, 1);
835 | LPAREN REG COMMA REG RPAREN ASSIGN SEARCH REG LPAREN searchmod RPAREN
837 if (IS_DREG ($2) && IS_DREG ($4) && IS_DREG ($8))
839 notethat ("dsp32alu: (dregs , dregs ) = SEARCH dregs (searchmod)\n");
840 $$ = DSP32ALU (13, 0, &$2, &$4, &$8, 0, 0, 0, $10.r0);
842 else
843 return yyerror ("Register mismatch");
845 | REG ASSIGN A_ONE_DOT_L PLUS A_ONE_DOT_H COMMA
846 REG ASSIGN A_ZERO_DOT_L PLUS A_ZERO_DOT_H
848 if (IS_DREG ($1) && IS_DREG ($7))
850 notethat ("dsp32alu: dregs = A1.l + A1.h, dregs = A0.l + A0.h \n");
851 $$ = DSP32ALU (12, 0, &$1, &$7, 0, 0, 0, 0, 1);
853 else
854 return yyerror ("Register mismatch");
858 | REG ASSIGN REG_A PLUS REG_A COMMA REG ASSIGN REG_A MINUS REG_A amod1
860 if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
861 && IS_A1 ($9) && !IS_A1 ($11))
863 notethat ("dsp32alu: dregs = A1 + A0 , dregs = A1 - A0 (amod1)\n");
864 $$ = DSP32ALU (17, 0, &$1, &$7, 0, 0, $12.s0, $12.x0, 0);
867 else if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
868 && !IS_A1 ($9) && IS_A1 ($11))
870 notethat ("dsp32alu: dregs = A0 + A1 , dregs = A0 - A1 (amod1)\n");
871 $$ = DSP32ALU (17, 0, &$1, &$7, 0, 0, $12.s0, $12.x0, 1);
873 else
874 return yyerror ("Register mismatch");
877 | REG ASSIGN REG plus_minus REG COMMA REG ASSIGN REG plus_minus REG amod1
879 if ($4.r0 == $10.r0)
880 return yyerror ("Operators must differ");
882 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5)
883 && REG_SAME ($3, $9) && REG_SAME ($5, $11))
885 notethat ("dsp32alu: dregs = dregs + dregs,"
886 "dregs = dregs - dregs (amod1)\n");
887 $$ = DSP32ALU (4, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, 2);
889 else
890 return yyerror ("Register mismatch");
893 /* Bar Operations. */
895 | REG ASSIGN REG op_bar_op REG COMMA REG ASSIGN REG op_bar_op REG amod2
897 if (!REG_SAME ($3, $9) || !REG_SAME ($5, $11))
898 return yyerror ("Differing source registers");
900 if (!IS_DREG ($1) || !IS_DREG ($3) || !IS_DREG ($5) || !IS_DREG ($7))
901 return yyerror ("Dregs expected");
904 if ($4.r0 == 1 && $10.r0 == 2)
906 notethat ("dsp32alu: dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
907 $$ = DSP32ALU (1, 1, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
909 else if ($4.r0 == 0 && $10.r0 == 3)
911 notethat ("dsp32alu: dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
912 $$ = DSP32ALU (1, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
914 else
915 return yyerror ("Bar operand mismatch");
918 | REG ASSIGN ABS REG vmod
920 int op;
922 if (IS_DREG ($1) && IS_DREG ($4))
924 if ($5.r0)
926 notethat ("dsp32alu: dregs = ABS dregs (v)\n");
927 op = 6;
929 else
931 /* Vector version of ABS. */
932 notethat ("dsp32alu: dregs = ABS dregs\n");
933 op = 7;
935 $$ = DSP32ALU (op, 0, 0, &$1, &$4, 0, 0, 0, 2);
937 else
938 return yyerror ("Dregs expected");
940 | a_assign ABS REG_A
942 notethat ("dsp32alu: Ax = ABS Ax\n");
943 $$ = DSP32ALU (16, IS_A1 ($1), 0, 0, 0, 0, 0, 0, IS_A1 ($3));
945 | A_ZERO_DOT_L ASSIGN HALF_REG
947 if (IS_DREG_L ($3))
949 notethat ("dsp32alu: A0.l = reg_half\n");
950 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
952 else
953 return yyerror ("A0.l = Rx.l expected");
955 | A_ONE_DOT_L ASSIGN HALF_REG
957 if (IS_DREG_L ($3))
959 notethat ("dsp32alu: A1.l = reg_half\n");
960 $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
962 else
963 return yyerror ("A1.l = Rx.l expected");
966 | REG ASSIGN c_align LPAREN REG COMMA REG RPAREN
968 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
970 notethat ("dsp32shift: dregs = ALIGN8 (dregs , dregs )\n");
971 $$ = DSP32SHIFT (13, &$1, &$7, &$5, $3.r0, 0);
973 else
974 return yyerror ("Dregs expected");
977 | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN byteop_mod
979 if (!IS_DREG ($1))
980 return yyerror ("Dregs expected");
981 else if (!valid_dreg_pair (&$5, $7))
982 return yyerror ("Bad dreg pair");
983 else if (!valid_dreg_pair (&$9, $11))
984 return yyerror ("Bad dreg pair");
985 else
987 notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
988 $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, $13.s0, 0, $13.r0);
991 | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
993 if (!IS_DREG ($1))
994 return yyerror ("Dregs expected");
995 else if (!valid_dreg_pair (&$5, $7))
996 return yyerror ("Bad dreg pair");
997 else if (!valid_dreg_pair (&$9, $11))
998 return yyerror ("Bad dreg pair");
999 else
1001 notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
1002 $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, 0, 0, 0);
1006 | REG ASSIGN BYTEOP2P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1007 rnd_op
1009 if (!IS_DREG ($1))
1010 return yyerror ("Dregs expected");
1011 else if (!valid_dreg_pair (&$5, $7))
1012 return yyerror ("Bad dreg pair");
1013 else if (!valid_dreg_pair (&$9, $11))
1014 return yyerror ("Bad dreg pair");
1015 else
1017 notethat ("dsp32alu: dregs = BYTEOP2P (dregs_pair , dregs_pair ) (rnd_op)\n");
1018 $$ = DSP32ALU (22, $13.r0, 0, &$1, &$5, &$9, $13.s0, $13.x0, $13.aop);
1022 | REG ASSIGN BYTEOP2M LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1023 rnd_op
1025 if (!IS_DREG ($1))
1026 return yyerror ("Dregs expected");
1027 else if (!valid_dreg_pair (&$5, $7))
1028 return yyerror ("Bad dreg pair");
1029 else if (!valid_dreg_pair (&$9, $11))
1030 return yyerror ("Bad dreg pair");
1031 else
1033 notethat ("dsp32alu: dregs = BYTEOP2P (dregs_pair , dregs_pair ) (rnd_op)\n");
1034 $$ = DSP32ALU (22, $13.r0, 0, &$1, &$5, &$9, $13.s0, 0, $13.x0);
1038 | REG ASSIGN BYTEOP3P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1039 b3_op
1041 if (!IS_DREG ($1))
1042 return yyerror ("Dregs expected");
1043 else if (!valid_dreg_pair (&$5, $7))
1044 return yyerror ("Bad dreg pair");
1045 else if (!valid_dreg_pair (&$9, $11))
1046 return yyerror ("Bad dreg pair");
1047 else
1049 notethat ("dsp32alu: dregs = BYTEOP3P (dregs_pair , dregs_pair ) (b3_op)\n");
1050 $$ = DSP32ALU (23, $13.x0, 0, &$1, &$5, &$9, $13.s0, 0, 0);
1054 | REG ASSIGN BYTEPACK LPAREN REG COMMA REG RPAREN
1056 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1058 notethat ("dsp32alu: dregs = BYTEPACK (dregs , dregs )\n");
1059 $$ = DSP32ALU (24, 0, 0, &$1, &$5, &$7, 0, 0, 0);
1061 else
1062 return yyerror ("Dregs expected");
1065 | HALF_REG ASSIGN HALF_REG ASSIGN SIGN LPAREN HALF_REG RPAREN STAR
1066 HALF_REG PLUS SIGN LPAREN HALF_REG RPAREN STAR HALF_REG
1068 if (IS_HCOMPL ($1, $3) && IS_HCOMPL ($7, $14) && IS_HCOMPL ($10, $17))
1070 notethat ("dsp32alu: dregs_hi = dregs_lo ="
1071 "SIGN (dregs_hi) * dregs_hi + "
1072 "SIGN (dregs_lo) * dregs_lo \n");
1074 $$ = DSP32ALU (12, 0, 0, &$1, &$7, &$10, 0, 0, 0);
1076 else
1077 return yyerror ("Dregs expected");
1079 | REG ASSIGN REG plus_minus REG amod1
1081 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1083 if ($6.aop == 0)
1085 /* No saturation flag specified, generate the 16 bit variant. */
1086 notethat ("COMP3op: dregs = dregs +- dregs\n");
1087 $$ = COMP3OP (&$1, &$3, &$5, $4.r0);
1089 else
1091 /* Saturation flag specified, generate the 32 bit variant. */
1092 notethat ("dsp32alu: dregs = dregs +- dregs (amod1)\n");
1093 $$ = DSP32ALU (4, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
1096 else
1097 if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($5) && $4.r0 == 0)
1099 notethat ("COMP3op: pregs = pregs + pregs\n");
1100 $$ = COMP3OP (&$1, &$3, &$5, 5);
1102 else
1103 return yyerror ("Dregs expected");
1105 | REG ASSIGN min_max LPAREN REG COMMA REG RPAREN vmod
1107 int op;
1109 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1111 if ($9.r0)
1112 op = 6;
1113 else
1114 op = 7;
1116 notethat ("dsp32alu: dregs = {MIN|MAX} (dregs, dregs)\n");
1117 $$ = DSP32ALU (op, 0, 0, &$1, &$5, &$7, 0, 0, $3.r0);
1119 else
1120 return yyerror ("Dregs expected");
1123 | a_assign MINUS REG_A
1125 notethat ("dsp32alu: Ax = - Ax\n");
1126 $$ = DSP32ALU (14, IS_A1 ($1), 0, 0, 0, 0, 0, 0, IS_A1 ($3));
1128 | HALF_REG ASSIGN HALF_REG plus_minus HALF_REG amod1
1130 notethat ("dsp32alu: dregs_lo = dregs_lo +- dregs_lo (amod1)\n");
1131 $$ = DSP32ALU (2 | $4.r0, IS_H ($1), 0, &$1, &$3, &$5,
1132 $6.s0, $6.x0, HL2 ($3, $5));
1134 | a_assign a_assign expr
1136 if (EXPR_VALUE ($3) == 0 && !REG_SAME ($1, $2))
1138 notethat ("dsp32alu: A1 = A0 = 0\n");
1139 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, 2);
1141 else
1142 return yyerror ("Bad value, 0 expected");
1145 /* Saturating. */
1146 | a_assign REG_A LPAREN S RPAREN
1148 if (REG_SAME ($1, $2))
1150 notethat ("dsp32alu: Ax = Ax (S)\n");
1151 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 1, 0, IS_A1 ($1));
1153 else
1154 return yyerror ("Registers must be equal");
1157 | HALF_REG ASSIGN REG LPAREN RND RPAREN
1159 if (IS_DREG ($3))
1161 notethat ("dsp32alu: dregs_half = dregs (RND)\n");
1162 $$ = DSP32ALU (12, IS_H ($1), 0, &$1, &$3, 0, 0, 0, 3);
1164 else
1165 return yyerror ("Dregs expected");
1168 | HALF_REG ASSIGN REG plus_minus REG LPAREN RND12 RPAREN
1170 if (IS_DREG ($3) && IS_DREG ($5))
1172 notethat ("dsp32alu: dregs_half = dregs (+-) dregs (RND12)\n");
1173 $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 0, $4.r0);
1175 else
1176 return yyerror ("Dregs expected");
1179 | HALF_REG ASSIGN REG plus_minus REG LPAREN RND20 RPAREN
1181 if (IS_DREG ($3) && IS_DREG ($5))
1183 notethat ("dsp32alu: dregs_half = dregs -+ dregs (RND20)\n");
1184 $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 1, $4.r0 | 2);
1186 else
1187 return yyerror ("Dregs expected");
1190 | a_assign REG_A
1192 if (!REG_SAME ($1, $2))
1194 notethat ("dsp32alu: An = Am\n");
1195 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, IS_A1 ($1), 0, 3);
1197 else
1198 return yyerror ("Accu reg arguments must differ");
1201 | a_assign REG
1203 if (IS_DREG ($2))
1205 notethat ("dsp32alu: An = dregs\n");
1206 $$ = DSP32ALU (9, 0, 0, 0, &$2, 0, 1, 0, IS_A1 ($1) << 1);
1208 else
1209 return yyerror ("Dregs expected");
1212 | REG ASSIGN HALF_REG xpmod
1214 if (!IS_H ($3))
1216 if ($1.regno == REG_A0x && IS_DREG ($3))
1218 notethat ("dsp32alu: A0.x = dregs_lo\n");
1219 $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 1);
1221 else if ($1.regno == REG_A1x && IS_DREG ($3))
1223 notethat ("dsp32alu: A1.x = dregs_lo\n");
1224 $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 3);
1226 else if (IS_DREG ($1) && IS_DREG ($3))
1228 notethat ("ALU2op: dregs = dregs_lo\n");
1229 $$ = ALU2OP (&$1, &$3, 10 | ($4.r0 ? 0: 1));
1231 else
1232 return yyerror ("Register mismatch");
1234 else
1235 return yyerror ("Low reg expected");
1238 | HALF_REG ASSIGN expr
1240 notethat ("LDIMMhalf: pregs_half = imm16\n");
1242 if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
1243 && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
1244 return yyerror ("Wrong register for load immediate");
1246 if (!IS_IMM ($3, 16) && !IS_UIMM ($3, 16))
1247 return yyerror ("Constant out of range");
1249 $$ = LDIMMHALF_R (&$1, IS_H ($1), 0, 0, $3);
1252 | a_assign expr
1254 notethat ("dsp32alu: An = 0\n");
1256 if (imm7 ($2) != 0)
1257 return yyerror ("0 expected");
1259 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, IS_A1 ($1));
1262 | REG ASSIGN expr xpmod1
1264 if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
1265 && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
1266 return yyerror ("Wrong register for load immediate");
1268 if ($4.r0 == 0)
1270 /* 7 bit immediate value if possible.
1271 We will check for that constant value for efficiency
1272 If it goes to reloc, it will be 16 bit. */
1273 if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_DREG ($1))
1275 notethat ("COMPI2opD: dregs = imm7 (x) \n");
1276 $$ = COMPI2OPD (&$1, imm7 ($3), 0);
1278 else if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_PREG ($1))
1280 notethat ("COMPI2opP: pregs = imm7 (x)\n");
1281 $$ = COMPI2OPP (&$1, imm7 ($3), 0);
1283 else
1285 if (IS_CONST ($3) && !IS_IMM ($3, 16))
1286 return yyerror ("Immediate value out of range");
1288 notethat ("LDIMMhalf: regs = luimm16 (x)\n");
1289 /* reg, H, S, Z. */
1290 $$ = LDIMMHALF_R5 (&$1, 0, 1, 0, $3);
1293 else
1295 /* (z) There is no 7 bit zero extended instruction.
1296 If the expr is a relocation, generate it. */
1298 if (IS_CONST ($3) && !IS_UIMM ($3, 16))
1299 return yyerror ("Immediate value out of range");
1301 notethat ("LDIMMhalf: regs = luimm16 (x)\n");
1302 /* reg, H, S, Z. */
1303 $$ = LDIMMHALF_R5 (&$1, 0, 0, 1, $3);
1307 | HALF_REG ASSIGN REG
1309 if (IS_H ($1))
1310 return yyerror ("Low reg expected");
1312 if (IS_DREG ($1) && $3.regno == REG_A0x)
1314 notethat ("dsp32alu: dregs_lo = A0.x\n");
1315 $$ = DSP32ALU (10, 0, 0, &$1, 0, 0, 0, 0, 0);
1317 else if (IS_DREG ($1) && $3.regno == REG_A1x)
1319 notethat ("dsp32alu: dregs_lo = A1.x\n");
1320 $$ = DSP32ALU (10, 0, 0, &$1, 0, 0, 0, 0, 1);
1322 else
1323 return yyerror ("Register mismatch");
1326 | REG ASSIGN REG op_bar_op REG amod0
1328 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1330 notethat ("dsp32alu: dregs = dregs .|. dregs (amod0)\n");
1331 $$ = DSP32ALU (0, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
1333 else
1334 return yyerror ("Register mismatch");
1337 | REG ASSIGN BYTE_DREG xpmod
1339 if (IS_DREG ($1) && IS_DREG ($3))
1341 notethat ("ALU2op: dregs = dregs_byte\n");
1342 $$ = ALU2OP (&$1, &$3, 12 | ($4.r0 ? 0: 1));
1344 else
1345 return yyerror ("Register mismatch");
1348 | a_assign ABS REG_A COMMA a_assign ABS REG_A
1350 if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
1352 notethat ("dsp32alu: A1 = ABS A1 , A0 = ABS A0\n");
1353 $$ = DSP32ALU (16, 0, 0, 0, 0, 0, 0, 0, 3);
1355 else
1356 return yyerror ("Register mismatch");
1359 | a_assign MINUS REG_A COMMA a_assign MINUS REG_A
1361 if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
1363 notethat ("dsp32alu: A1 = - A1 , A0 = - A0\n");
1364 $$ = DSP32ALU (14, 0, 0, 0, 0, 0, 0, 0, 3);
1366 else
1367 return yyerror ("Register mismatch");
1370 | a_minusassign REG_A w32_or_nothing
1372 if (!IS_A1 ($1) && IS_A1 ($2))
1374 notethat ("dsp32alu: A0 -= A1\n");
1375 $$ = DSP32ALU (11, 0, 0, 0, 0, 0, $3.r0, 0, 3);
1377 else
1378 return yyerror ("Register mismatch");
1381 | REG _MINUS_ASSIGN expr
1383 if (IS_IREG ($1) && EXPR_VALUE ($3) == 4)
1385 notethat ("dagMODik: iregs -= 4\n");
1386 $$ = DAGMODIK (&$1, 3);
1388 else if (IS_IREG ($1) && EXPR_VALUE ($3) == 2)
1390 notethat ("dagMODik: iregs -= 2\n");
1391 $$ = DAGMODIK (&$1, 1);
1393 else
1394 return yyerror ("Register or value mismatch");
1397 | REG _PLUS_ASSIGN REG LPAREN BREV RPAREN
1399 if (IS_IREG ($1) && IS_MREG ($3))
1401 notethat ("dagMODim: iregs += mregs (opt_brev)\n");
1402 /* i, m, op, br. */
1403 $$ = DAGMODIM (&$1, &$3, 0, 1);
1405 else if (IS_PREG ($1) && IS_PREG ($3))
1407 notethat ("PTR2op: pregs += pregs (BREV )\n");
1408 $$ = PTR2OP (&$1, &$3, 5);
1410 else
1411 return yyerror ("Register mismatch");
1414 | REG _MINUS_ASSIGN REG
1416 if (IS_IREG ($1) && IS_MREG ($3))
1418 notethat ("dagMODim: iregs -= mregs\n");
1419 $$ = DAGMODIM (&$1, &$3, 1, 0);
1421 else if (IS_PREG ($1) && IS_PREG ($3))
1423 notethat ("PTR2op: pregs -= pregs\n");
1424 $$ = PTR2OP (&$1, &$3, 0);
1426 else
1427 return yyerror ("Register mismatch");
1430 | REG_A _PLUS_ASSIGN REG_A w32_or_nothing
1432 if (!IS_A1 ($1) && IS_A1 ($3))
1434 notethat ("dsp32alu: A0 += A1 (W32)\n");
1435 $$ = DSP32ALU (11, 0, 0, 0, 0, 0, $4.r0, 0, 2);
1437 else
1438 return yyerror ("Register mismatch");
1441 | REG _PLUS_ASSIGN REG
1443 if (IS_IREG ($1) && IS_MREG ($3))
1445 notethat ("dagMODim: iregs += mregs\n");
1446 $$ = DAGMODIM (&$1, &$3, 0, 0);
1448 else
1449 return yyerror ("iregs += mregs expected");
1452 | REG _PLUS_ASSIGN expr
1454 if (IS_IREG ($1))
1456 if (EXPR_VALUE ($3) == 4)
1458 notethat ("dagMODik: iregs += 4\n");
1459 $$ = DAGMODIK (&$1, 2);
1461 else if (EXPR_VALUE ($3) == 2)
1463 notethat ("dagMODik: iregs += 2\n");
1464 $$ = DAGMODIK (&$1, 0);
1466 else
1467 return yyerror ("iregs += [ 2 | 4 ");
1469 else if (IS_PREG ($1) && IS_IMM ($3, 7))
1471 notethat ("COMPI2opP: pregs += imm7\n");
1472 $$ = COMPI2OPP (&$1, imm7 ($3), 1);
1474 else if (IS_DREG ($1) && IS_IMM ($3, 7))
1476 notethat ("COMPI2opD: dregs += imm7\n");
1477 $$ = COMPI2OPD (&$1, imm7 ($3), 1);
1479 else if ((IS_DREG ($1) || IS_PREG ($1)) && IS_CONST ($3))
1480 return yyerror ("Immediate value out of range");
1481 else
1482 return yyerror ("Register mismatch");
1485 | REG _STAR_ASSIGN REG
1487 if (IS_DREG ($1) && IS_DREG ($3))
1489 notethat ("ALU2op: dregs *= dregs\n");
1490 $$ = ALU2OP (&$1, &$3, 3);
1492 else
1493 return yyerror ("Register mismatch");
1496 | SAA LPAREN REG COLON expr COMMA REG COLON expr RPAREN aligndir
1498 if (!valid_dreg_pair (&$3, $5))
1499 return yyerror ("Bad dreg pair");
1500 else if (!valid_dreg_pair (&$7, $9))
1501 return yyerror ("Bad dreg pair");
1502 else
1504 notethat ("dsp32alu: SAA (dregs_pair , dregs_pair ) (aligndir)\n");
1505 $$ = DSP32ALU (18, 0, 0, 0, &$3, &$7, $11.r0, 0, 0);
1509 | a_assign REG_A LPAREN S RPAREN COMMA a_assign REG_A LPAREN S RPAREN
1511 if (REG_SAME ($1, $2) && REG_SAME ($7, $8) && !REG_SAME ($1, $7))
1513 notethat ("dsp32alu: A1 = A1 (S) , A0 = A0 (S)\n");
1514 $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 1, 0, 2);
1516 else
1517 return yyerror ("Register mismatch");
1520 | REG ASSIGN LPAREN REG PLUS REG RPAREN LESS_LESS expr
1522 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6)
1523 && REG_SAME ($1, $4))
1525 if (EXPR_VALUE ($9) == 1)
1527 notethat ("ALU2op: dregs = (dregs + dregs) << 1\n");
1528 $$ = ALU2OP (&$1, &$6, 4);
1530 else if (EXPR_VALUE ($9) == 2)
1532 notethat ("ALU2op: dregs = (dregs + dregs) << 2\n");
1533 $$ = ALU2OP (&$1, &$6, 5);
1535 else
1536 return yyerror ("Bad shift value");
1538 else if (IS_PREG ($1) && IS_PREG ($4) && IS_PREG ($6)
1539 && REG_SAME ($1, $4))
1541 if (EXPR_VALUE ($9) == 1)
1543 notethat ("PTR2op: pregs = (pregs + pregs) << 1\n");
1544 $$ = PTR2OP (&$1, &$6, 6);
1546 else if (EXPR_VALUE ($9) == 2)
1548 notethat ("PTR2op: pregs = (pregs + pregs) << 2\n");
1549 $$ = PTR2OP (&$1, &$6, 7);
1551 else
1552 return yyerror ("Bad shift value");
1554 else
1555 return yyerror ("Register mismatch");
1558 /* COMP3 CCFLAG. */
1559 | REG ASSIGN REG BAR REG
1561 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1563 notethat ("COMP3op: dregs = dregs | dregs\n");
1564 $$ = COMP3OP (&$1, &$3, &$5, 3);
1566 else
1567 return yyerror ("Dregs expected");
1569 | REG ASSIGN REG CARET REG
1571 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1573 notethat ("COMP3op: dregs = dregs ^ dregs\n");
1574 $$ = COMP3OP (&$1, &$3, &$5, 4);
1576 else
1577 return yyerror ("Dregs expected");
1579 | REG ASSIGN REG PLUS LPAREN REG LESS_LESS expr RPAREN
1581 if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($6))
1583 if (EXPR_VALUE ($8) == 1)
1585 notethat ("COMP3op: pregs = pregs + (pregs << 1)\n");
1586 $$ = COMP3OP (&$1, &$3, &$6, 6);
1588 else if (EXPR_VALUE ($8) == 2)
1590 notethat ("COMP3op: pregs = pregs + (pregs << 2)\n");
1591 $$ = COMP3OP (&$1, &$3, &$6, 7);
1593 else
1594 return yyerror ("Bad shift value");
1596 else
1597 return yyerror ("Dregs expected");
1599 | CCREG ASSIGN REG_A _ASSIGN_ASSIGN REG_A
1601 if ($3.regno == REG_A0 && $5.regno == REG_A1)
1603 notethat ("CCflag: CC = A0 == A1\n");
1604 $$ = CCFLAG (0, 0, 5, 0, 0);
1606 else
1607 return yyerror ("AREGs are in bad order or same");
1609 | CCREG ASSIGN REG_A LESS_THAN REG_A
1611 if ($3.regno == REG_A0 && $5.regno == REG_A1)
1613 notethat ("CCflag: CC = A0 < A1\n");
1614 $$ = CCFLAG (0, 0, 6, 0, 0);
1616 else
1617 return yyerror ("AREGs are in bad order or same");
1619 | CCREG ASSIGN REG LESS_THAN REG iu_or_nothing
1621 if ((IS_DREG ($3) && IS_DREG ($5))
1622 || (IS_PREG ($3) && IS_PREG ($5)))
1624 notethat ("CCflag: CC = dpregs < dpregs\n");
1625 $$ = CCFLAG (&$3, $5.regno & CODE_MASK, $6.r0, 0, IS_PREG ($3) ? 1 : 0);
1627 else
1628 return yyerror ("Bad register in comparison");
1630 | CCREG ASSIGN REG LESS_THAN expr iu_or_nothing
1632 if (!IS_DREG ($3) && !IS_PREG ($3))
1633 return yyerror ("Bad register in comparison");
1635 if (($6.r0 == 1 && IS_IMM ($5, 3))
1636 || ($6.r0 == 3 && IS_UIMM ($5, 3)))
1638 notethat ("CCflag: CC = dpregs < (u)imm3\n");
1639 $$ = CCFLAG (&$3, imm3 ($5), $6.r0, 1, IS_PREG ($3) ? 1 : 0);
1641 else
1642 return yyerror ("Bad constant value");
1644 | CCREG ASSIGN REG _ASSIGN_ASSIGN REG
1646 if ((IS_DREG ($3) && IS_DREG ($5))
1647 || (IS_PREG ($3) && IS_PREG ($5)))
1649 notethat ("CCflag: CC = dpregs == dpregs\n");
1650 $$ = CCFLAG (&$3, $5.regno & CODE_MASK, 0, 0, IS_PREG ($3) ? 1 : 0);
1652 else
1653 return yyerror ("Bad register in comparison");
1655 | CCREG ASSIGN REG _ASSIGN_ASSIGN expr
1657 if (!IS_DREG ($3) && !IS_PREG ($3))
1658 return yyerror ("Bad register in comparison");
1660 if (IS_IMM ($5, 3))
1662 notethat ("CCflag: CC = dpregs == imm3\n");
1663 $$ = CCFLAG (&$3, imm3 ($5), 0, 1, IS_PREG ($3) ? 1 : 0);
1665 else
1666 return yyerror ("Bad constant range");
1668 | CCREG ASSIGN REG_A _LESS_THAN_ASSIGN REG_A
1670 if ($3.regno == REG_A0 && $5.regno == REG_A1)
1672 notethat ("CCflag: CC = A0 <= A1\n");
1673 $$ = CCFLAG (0, 0, 7, 0, 0);
1675 else
1676 return yyerror ("AREGs are in bad order or same");
1678 | CCREG ASSIGN REG _LESS_THAN_ASSIGN REG iu_or_nothing
1680 if ((IS_DREG ($3) && IS_DREG ($5))
1681 || (IS_PREG ($3) && IS_PREG ($5)))
1683 notethat ("CCflag: CC = dpregs <= dpregs (..)\n");
1684 $$ = CCFLAG (&$3, $5.regno & CODE_MASK,
1685 1 + $6.r0, 0, IS_PREG ($3) ? 1 : 0);
1687 else
1688 return yyerror ("Bad register in comparison");
1690 | CCREG ASSIGN REG _LESS_THAN_ASSIGN expr iu_or_nothing
1692 if (!IS_DREG ($3) && !IS_PREG ($3))
1693 return yyerror ("Bad register in comparison");
1695 if (($6.r0 == 1 && IS_IMM ($5, 3))
1696 || ($6.r0 == 3 && IS_UIMM ($5, 3)))
1698 notethat ("CCflag: CC = dpregs <= (u)imm3\n");
1699 $$ = CCFLAG (&$3, imm3 ($5), 1 + $6.r0, 1, IS_PREG ($3) ? 1 : 0);
1701 else
1702 return yyerror ("Bad constant value");
1705 | REG ASSIGN REG AMPERSAND REG
1707 if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1709 notethat ("COMP3op: dregs = dregs & dregs\n");
1710 $$ = COMP3OP (&$1, &$3, &$5, 2);
1712 else
1713 return yyerror ("Dregs expected");
1716 | ccstat
1718 notethat ("CC2stat operation\n");
1719 $$ = bfin_gen_cc2stat ($1.r0, $1.x0, $1.s0);
1722 | REG ASSIGN REG
1724 if ((IS_GENREG ($1) && IS_GENREG ($3))
1725 || (IS_GENREG ($1) && IS_DAGREG ($3))
1726 || (IS_DAGREG ($1) && IS_GENREG ($3))
1727 || (IS_DAGREG ($1) && IS_DAGREG ($3))
1728 || (IS_GENREG ($1) && $3.regno == REG_USP)
1729 || ($1.regno == REG_USP && IS_GENREG ($3))
1730 || (IS_DREG ($1) && IS_SYSREG ($3))
1731 || (IS_PREG ($1) && IS_SYSREG ($3))
1732 || (IS_SYSREG ($1) && IS_DREG ($3))
1733 || (IS_SYSREG ($1) && IS_PREG ($3))
1734 || (IS_SYSREG ($1) && $3.regno == REG_USP))
1736 $$ = bfin_gen_regmv (&$3, &$1);
1738 else
1739 return yyerror ("Register mismatch");
1742 | CCREG ASSIGN REG
1744 if (IS_DREG ($3))
1746 notethat ("CC2dreg: CC = dregs\n");
1747 $$ = bfin_gen_cc2dreg (1, &$3);
1749 else
1750 return yyerror ("Register mismatch");
1753 | REG ASSIGN CCREG
1755 if (IS_DREG ($1))
1757 notethat ("CC2dreg: dregs = CC\n");
1758 $$ = bfin_gen_cc2dreg (0, &$1);
1760 else
1761 return yyerror ("Register mismatch");
1764 | CCREG _ASSIGN_BANG CCREG
1766 notethat ("CC2dreg: CC =! CC\n");
1767 $$ = bfin_gen_cc2dreg (3, 0);
1770 /* DSPMULT. */
1772 | HALF_REG ASSIGN multiply_halfregs opt_mode
1774 notethat ("dsp32mult: dregs_half = multiply_halfregs (opt_mode)\n");
1776 if (!IS_H ($1) && $4.MM)
1777 return yyerror ("(M) not allowed with MAC0");
1779 if ($4.mod != 0 && $4.mod != M_FU && $4.mod != M_IS
1780 && $4.mod != M_IU && $4.mod != M_T && $4.mod != M_TFU
1781 && $4.mod != M_S2RND && $4.mod != M_ISS2 && $4.mod != M_IH)
1782 return yyerror ("bad option.");
1784 if (IS_H ($1))
1786 $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 0,
1787 IS_H ($3.s0), IS_H ($3.s1), 0, 0,
1788 &$1, 0, &$3.s0, &$3.s1, 0);
1790 else
1792 $$ = DSP32MULT (0, 0, $4.mod, 0, 0,
1793 0, 0, IS_H ($3.s0), IS_H ($3.s1),
1794 &$1, 0, &$3.s0, &$3.s1, 1);
1798 | REG ASSIGN multiply_halfregs opt_mode
1800 /* Odd registers can use (M). */
1801 if (!IS_DREG ($1))
1802 return yyerror ("Dreg expected");
1804 if (IS_EVEN ($1) && $4.MM)
1805 return yyerror ("(M) not allowed with MAC0");
1807 if ($4.mod != 0 && $4.mod != M_FU && $4.mod != M_IS
1808 && $4.mod != M_S2RND && $4.mod != M_ISS2)
1809 return yyerror ("bad option");
1811 if (!IS_EVEN ($1))
1813 notethat ("dsp32mult: dregs = multiply_halfregs (opt_mode)\n");
1815 $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 1,
1816 IS_H ($3.s0), IS_H ($3.s1), 0, 0,
1817 &$1, 0, &$3.s0, &$3.s1, 0);
1819 else
1821 notethat ("dsp32mult: dregs = multiply_halfregs opt_mode\n");
1822 $$ = DSP32MULT (0, 0, $4.mod, 0, 1,
1823 0, 0, IS_H ($3.s0), IS_H ($3.s1),
1824 &$1, 0, &$3.s0, &$3.s1, 1);
1828 | HALF_REG ASSIGN multiply_halfregs opt_mode COMMA
1829 HALF_REG ASSIGN multiply_halfregs opt_mode
1831 if (!IS_DREG ($1) || !IS_DREG ($6))
1832 return yyerror ("Dregs expected");
1834 if (!IS_HCOMPL($1, $6))
1835 return yyerror ("Dest registers mismatch");
1837 if (check_multiply_halfregs (&$3, &$8) < 0)
1838 return -1;
1840 if ((!IS_H ($1) && $4.MM)
1841 || (!IS_H ($6) && $9.MM))
1842 return yyerror ("(M) not allowed with MAC0");
1844 notethat ("dsp32mult: dregs_hi = multiply_halfregs mxd_mod, "
1845 "dregs_lo = multiply_halfregs opt_mode\n");
1847 if (IS_H ($1))
1848 $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 0,
1849 IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
1850 &$1, 0, &$3.s0, &$3.s1, 1);
1851 else
1852 $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 0,
1853 IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
1854 &$1, 0, &$3.s0, &$3.s1, 1);
1857 | REG ASSIGN multiply_halfregs opt_mode COMMA REG ASSIGN multiply_halfregs opt_mode
1859 if (!IS_DREG ($1) || !IS_DREG ($6))
1860 return yyerror ("Dregs expected");
1862 if ((IS_EVEN ($1) && $6.regno - $1.regno != 1)
1863 || (IS_EVEN ($6) && $1.regno - $6.regno != 1))
1864 return yyerror ("Dest registers mismatch");
1866 if (check_multiply_halfregs (&$3, &$8) < 0)
1867 return -1;
1869 if ((IS_EVEN ($1) && $4.MM)
1870 || (IS_EVEN ($6) && $9.MM))
1871 return yyerror ("(M) not allowed with MAC0");
1873 notethat ("dsp32mult: dregs = multiply_halfregs mxd_mod, "
1874 "dregs = multiply_halfregs opt_mode\n");
1876 if (IS_EVEN ($1))
1877 $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 1,
1878 IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
1879 &$1, 0, &$3.s0, &$3.s1, 1);
1880 else
1881 $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 1,
1882 IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
1883 &$1, 0, &$3.s0, &$3.s1, 1);
1887 /* SHIFTs. */
1888 | a_assign ASHIFT REG_A BY HALF_REG
1890 if (!REG_SAME ($1, $3))
1891 return yyerror ("Aregs must be same");
1893 if (IS_DREG ($5) && !IS_H ($5))
1895 notethat ("dsp32shift: A0 = ASHIFT A0 BY dregs_lo\n");
1896 $$ = DSP32SHIFT (3, 0, &$5, 0, 0, IS_A1 ($1));
1898 else
1899 return yyerror ("Dregs expected");
1902 | HALF_REG ASSIGN ASHIFT HALF_REG BY HALF_REG smod
1904 if (IS_DREG ($6) && !IS_H ($6))
1906 notethat ("dsp32shift: dregs_half = ASHIFT dregs_half BY dregs_lo\n");
1907 $$ = DSP32SHIFT (0, &$1, &$6, &$4, $7.s0, HL2 ($1, $4));
1909 else
1910 return yyerror ("Dregs expected");
1913 | a_assign REG_A LESS_LESS expr
1915 if (!REG_SAME ($1, $2))
1916 return yyerror ("Aregs must be same");
1918 if (IS_UIMM ($4, 5))
1920 notethat ("dsp32shiftimm: A0 = A0 << uimm5\n");
1921 $$ = DSP32SHIFTIMM (3, 0, imm5 ($4), 0, 0, IS_A1 ($1));
1923 else
1924 return yyerror ("Bad shift value");
1927 | REG ASSIGN REG LESS_LESS expr vsmod
1929 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
1931 if ($6.r0)
1933 /* Vector? */
1934 notethat ("dsp32shiftimm: dregs = dregs << expr (V, .)\n");
1935 $$ = DSP32SHIFTIMM (1, &$1, imm4 ($5), &$3, $6.s0 ? 1 : 2, 0);
1937 else
1939 notethat ("dsp32shiftimm: dregs = dregs << uimm5 (.)\n");
1940 $$ = DSP32SHIFTIMM (2, &$1, imm6 ($5), &$3, $6.s0 ? 1 : 2, 0);
1943 else if ($6.s0 == 0 && IS_PREG ($1) && IS_PREG ($3))
1945 if (EXPR_VALUE ($5) == 2)
1947 notethat ("PTR2op: pregs = pregs << 2\n");
1948 $$ = PTR2OP (&$1, &$3, 1);
1950 else if (EXPR_VALUE ($5) == 1)
1952 notethat ("COMP3op: pregs = pregs << 1\n");
1953 $$ = COMP3OP (&$1, &$3, &$3, 5);
1955 else
1956 return yyerror ("Bad shift value");
1958 else
1959 return yyerror ("Bad shift value or register");
1961 | HALF_REG ASSIGN HALF_REG LESS_LESS expr smod
1963 if (IS_UIMM ($5, 4))
1965 if ($6.s0)
1967 notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4 (S)\n");
1968 $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, $6.s0, HL2 ($1, $3));
1970 else
1972 notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4\n");
1973 $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, 2, HL2 ($1, $3));
1976 else
1977 return yyerror ("Bad shift value");
1979 | REG ASSIGN ASHIFT REG BY HALF_REG vsmod
1981 int op;
1983 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6) && !IS_H ($6))
1985 if ($7.r0)
1987 op = 1;
1988 notethat ("dsp32shift: dregs = ASHIFT dregs BY "
1989 "dregs_lo (V, .)\n");
1991 else
1994 op = 2;
1995 notethat ("dsp32shift: dregs = ASHIFT dregs BY dregs_lo (.)\n");
1997 $$ = DSP32SHIFT (op, &$1, &$6, &$4, $7.s0, 0);
1999 else
2000 return yyerror ("Dregs expected");
2003 /* EXPADJ. */
2004 | HALF_REG ASSIGN EXPADJ LPAREN REG COMMA HALF_REG RPAREN vmod
2006 if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
2008 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs , dregs_lo )\n");
2009 $$ = DSP32SHIFT (7, &$1, &$7, &$5, $9.r0, 0);
2011 else
2012 return yyerror ("Bad shift value or register");
2016 | HALF_REG ASSIGN EXPADJ LPAREN HALF_REG COMMA HALF_REG RPAREN
2018 if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
2020 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_lo, dregs_lo)\n");
2021 $$ = DSP32SHIFT (7, &$1, &$7, &$5, 2, 0);
2023 else if (IS_DREG_L ($1) && IS_DREG_H ($5) && IS_DREG_L ($7))
2025 notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_hi, dregs_lo)\n");
2026 $$ = DSP32SHIFT (7, &$1, &$7, &$5, 3, 0);
2028 else
2029 return yyerror ("Bad shift value or register");
2032 /* DEPOSIT. */
2034 | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN
2036 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2038 notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs )\n");
2039 $$ = DSP32SHIFT (10, &$1, &$7, &$5, 2, 0);
2041 else
2042 return yyerror ("Register mismatch");
2045 | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN LPAREN X RPAREN
2047 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2049 notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs ) (X)\n");
2050 $$ = DSP32SHIFT (10, &$1, &$7, &$5, 3, 0);
2052 else
2053 return yyerror ("Register mismatch");
2056 | REG ASSIGN EXTRACT LPAREN REG COMMA HALF_REG RPAREN xpmod
2058 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG_L ($7))
2060 notethat ("dsp32shift: dregs = EXTRACT (dregs, dregs_lo ) (.)\n");
2061 $$ = DSP32SHIFT (10, &$1, &$7, &$5, $9.r0, 0);
2063 else
2064 return yyerror ("Register mismatch");
2067 | a_assign REG_A _GREATER_GREATER_GREATER expr
2069 if (!REG_SAME ($1, $2))
2070 return yyerror ("Aregs must be same");
2072 if (IS_UIMM ($4, 5))
2074 notethat ("dsp32shiftimm: Ax = Ax >>> uimm5\n");
2075 $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 0, IS_A1 ($1));
2077 else
2078 return yyerror ("Shift value range error");
2080 | a_assign LSHIFT REG_A BY HALF_REG
2082 if (REG_SAME ($1, $3) && IS_DREG_L ($5))
2084 notethat ("dsp32shift: Ax = LSHIFT Ax BY dregs_lo\n");
2085 $$ = DSP32SHIFT (3, 0, &$5, 0, 1, IS_A1 ($1));
2087 else
2088 return yyerror ("Register mismatch");
2091 | HALF_REG ASSIGN LSHIFT HALF_REG BY HALF_REG
2093 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2095 notethat ("dsp32shift: dregs_lo = LSHIFT dregs_hi BY dregs_lo\n");
2096 $$ = DSP32SHIFT (0, &$1, &$6, &$4, 2, HL2 ($1, $4));
2098 else
2099 return yyerror ("Register mismatch");
2102 | REG ASSIGN LSHIFT REG BY HALF_REG vmod
2104 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2106 notethat ("dsp32shift: dregs = LSHIFT dregs BY dregs_lo (V )\n");
2107 $$ = DSP32SHIFT ($7.r0 ? 1: 2, &$1, &$6, &$4, 2, 0);
2109 else
2110 return yyerror ("Register mismatch");
2113 | REG ASSIGN SHIFT REG BY HALF_REG
2115 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2117 notethat ("dsp32shift: dregs = SHIFT dregs BY dregs_lo\n");
2118 $$ = DSP32SHIFT (2, &$1, &$6, &$4, 2, 0);
2120 else
2121 return yyerror ("Register mismatch");
2124 | a_assign REG_A GREATER_GREATER expr
2126 if (REG_SAME ($1, $2) && IS_IMM ($4, 6) >= 0)
2128 notethat ("dsp32shiftimm: Ax = Ax >> imm6\n");
2129 $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 1, IS_A1 ($1));
2131 else
2132 return yyerror ("Accu register expected");
2135 | REG ASSIGN REG GREATER_GREATER expr vmod
2137 if ($6.r0 == 1)
2139 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2141 notethat ("dsp32shiftimm: dregs = dregs >> uimm5 (V)\n");
2142 $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, 2, 0);
2144 else
2145 return yyerror ("Register mismatch");
2147 else
2149 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2151 notethat ("dsp32shiftimm: dregs = dregs >> uimm5\n");
2152 $$ = DSP32SHIFTIMM (2, &$1, -imm6 ($5), &$3, 2, 0);
2154 else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 2)
2156 notethat ("PTR2op: pregs = pregs >> 2\n");
2157 $$ = PTR2OP (&$1, &$3, 3);
2159 else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 1)
2161 notethat ("PTR2op: pregs = pregs >> 1\n");
2162 $$ = PTR2OP (&$1, &$3, 4);
2164 else
2165 return yyerror ("Register mismatch");
2168 | HALF_REG ASSIGN HALF_REG GREATER_GREATER expr
2170 if (IS_UIMM ($5, 5))
2172 notethat ("dsp32shiftimm: dregs_half = dregs_half >> uimm5\n");
2173 $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3, 2, HL2 ($1, $3));
2175 else
2176 return yyerror ("Register mismatch");
2178 | HALF_REG ASSIGN HALF_REG _GREATER_GREATER_GREATER expr smod
2180 if (IS_UIMM ($5, 5))
2182 notethat ("dsp32shiftimm: dregs_half = dregs_half >>> uimm5\n");
2183 $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3,
2184 $6.s0, HL2 ($1, $3));
2186 else
2187 return yyerror ("Register or modifier mismatch");
2191 | REG ASSIGN REG _GREATER_GREATER_GREATER expr vsmod
2193 if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2195 if ($6.r0)
2197 /* Vector? */
2198 notethat ("dsp32shiftimm: dregs = dregs >>> uimm5 (V, .)\n");
2199 $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, $6.s0, 0);
2201 else
2203 notethat ("dsp32shiftimm: dregs = dregs >>> uimm5 (.)\n");
2204 $$ = DSP32SHIFTIMM (2, &$1, -uimm5 ($5), &$3, $6.s0, 0);
2207 else
2208 return yyerror ("Register mismatch");
2211 | HALF_REG ASSIGN ONES REG
2213 if (IS_DREG_L ($1) && IS_DREG ($4))
2215 notethat ("dsp32shift: dregs_lo = ONES dregs\n");
2216 $$ = DSP32SHIFT (6, &$1, 0, &$4, 3, 0);
2218 else
2219 return yyerror ("Register mismatch");
2222 | REG ASSIGN PACK LPAREN HALF_REG COMMA HALF_REG RPAREN
2224 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2226 notethat ("dsp32shift: dregs = PACK (dregs_hi , dregs_hi )\n");
2227 $$ = DSP32SHIFT (4, &$1, &$7, &$5, HL2 ($5, $7), 0);
2229 else
2230 return yyerror ("Register mismatch");
2233 | HALF_REG ASSIGN CCREG ASSIGN BXORSHIFT LPAREN REG_A COMMA REG RPAREN
2235 if (IS_DREG ($1)
2236 && $7.regno == REG_A0
2237 && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
2239 notethat ("dsp32shift: dregs_lo = CC = BXORSHIFT (A0 , dregs )\n");
2240 $$ = DSP32SHIFT (11, &$1, &$9, 0, 0, 0);
2242 else
2243 return yyerror ("Register mismatch");
2246 | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG RPAREN
2248 if (IS_DREG ($1)
2249 && $7.regno == REG_A0
2250 && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
2252 notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , dregs)\n");
2253 $$ = DSP32SHIFT (11, &$1, &$9, 0, 1, 0);
2255 else
2256 return yyerror ("Register mismatch");
2259 | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
2261 if (IS_DREG ($1) && !IS_H ($1) && !REG_SAME ($7, $9))
2263 notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , A1 , CC)\n");
2264 $$ = DSP32SHIFT (12, &$1, 0, 0, 1, 0);
2266 else
2267 return yyerror ("Register mismatch");
2270 | a_assign ROT REG_A BY HALF_REG
2272 if (REG_SAME ($1, $3) && IS_DREG_L ($5))
2274 notethat ("dsp32shift: Ax = ROT Ax BY dregs_lo\n");
2275 $$ = DSP32SHIFT (3, 0, &$5, 0, 2, IS_A1 ($1));
2277 else
2278 return yyerror ("Register mismatch");
2281 | REG ASSIGN ROT REG BY HALF_REG
2283 if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2285 notethat ("dsp32shift: dregs = ROT dregs BY dregs_lo\n");
2286 $$ = DSP32SHIFT (2, &$1, &$6, &$4, 3, 0);
2288 else
2289 return yyerror ("Register mismatch");
2292 | a_assign ROT REG_A BY expr
2294 if (IS_IMM ($5, 6))
2296 notethat ("dsp32shiftimm: An = ROT An BY imm6\n");
2297 $$ = DSP32SHIFTIMM (3, 0, imm6 ($5), 0, 2, IS_A1 ($1));
2299 else
2300 return yyerror ("Register mismatch");
2303 | REG ASSIGN ROT REG BY expr
2305 if (IS_DREG ($1) && IS_DREG ($4) && IS_IMM ($6, 6))
2307 $$ = DSP32SHIFTIMM (2, &$1, imm6 ($6), &$4, 3, IS_A1 ($1));
2309 else
2310 return yyerror ("Register mismatch");
2313 | HALF_REG ASSIGN SIGNBITS REG_A
2315 if (IS_DREG_L ($1))
2317 notethat ("dsp32shift: dregs_lo = SIGNBITS An\n");
2318 $$ = DSP32SHIFT (6, &$1, 0, 0, IS_A1 ($4), 0);
2320 else
2321 return yyerror ("Register mismatch");
2324 | HALF_REG ASSIGN SIGNBITS REG
2326 if (IS_DREG_L ($1) && IS_DREG ($4))
2328 notethat ("dsp32shift: dregs_lo = SIGNBITS dregs\n");
2329 $$ = DSP32SHIFT (5, &$1, 0, &$4, 0, 0);
2331 else
2332 return yyerror ("Register mismatch");
2335 | HALF_REG ASSIGN SIGNBITS HALF_REG
2337 if (IS_DREG_L ($1))
2339 notethat ("dsp32shift: dregs_lo = SIGNBITS dregs_lo\n");
2340 $$ = DSP32SHIFT (5, &$1, 0, &$4, 1 + IS_H ($4), 0);
2342 else
2343 return yyerror ("Register mismatch");
2346 /* The ASR bit is just inverted here. */
2347 | HALF_REG ASSIGN VIT_MAX LPAREN REG RPAREN asr_asl
2349 if (IS_DREG_L ($1) && IS_DREG ($5))
2351 notethat ("dsp32shift: dregs_lo = VIT_MAX (dregs) (..)\n");
2352 $$ = DSP32SHIFT (9, &$1, 0, &$5, ($7.r0 ? 0 : 1), 0);
2354 else
2355 return yyerror ("Register mismatch");
2358 | REG ASSIGN VIT_MAX LPAREN REG COMMA REG RPAREN asr_asl
2360 if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2362 notethat ("dsp32shift: dregs = VIT_MAX (dregs, dregs) (ASR)\n");
2363 $$ = DSP32SHIFT (9, &$1, &$7, &$5, 2 | ($9.r0 ? 0 : 1), 0);
2365 else
2366 return yyerror ("Register mismatch");
2369 | BITMUX LPAREN REG COMMA REG COMMA REG_A RPAREN asr_asl
2371 if (IS_DREG ($3) && IS_DREG ($5) && !IS_A1 ($7))
2373 notethat ("dsp32shift: BITMUX (dregs , dregs , A0) (ASR)\n");
2374 $$ = DSP32SHIFT (8, 0, &$3, &$5, $9.r0, 0);
2376 else
2377 return yyerror ("Register mismatch");
2380 | a_assign BXORSHIFT LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
2382 if (!IS_A1 ($1) && !IS_A1 ($4) && IS_A1 ($6))
2384 notethat ("dsp32shift: A0 = BXORSHIFT (A0 , A1 , CC )\n");
2385 $$ = DSP32SHIFT (12, 0, 0, 0, 0, 0);
2387 else
2388 return yyerror ("Dregs expected");
2392 /* LOGI2op: BITCLR (dregs, uimm5). */
2393 | BITCLR LPAREN REG COMMA expr RPAREN
2395 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2397 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2398 $$ = LOGI2OP ($3, uimm5 ($5), 4);
2400 else
2401 return yyerror ("Register mismatch");
2404 /* LOGI2op: BITSET (dregs, uimm5). */
2405 | BITSET LPAREN REG COMMA expr RPAREN
2407 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2409 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2410 $$ = LOGI2OP ($3, uimm5 ($5), 2);
2412 else
2413 return yyerror ("Register mismatch");
2416 /* LOGI2op: BITTGL (dregs, uimm5). */
2417 | BITTGL LPAREN REG COMMA expr RPAREN
2419 if (IS_DREG ($3) && IS_UIMM ($5, 5))
2421 notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2422 $$ = LOGI2OP ($3, uimm5 ($5), 3);
2424 else
2425 return yyerror ("Register mismatch");
2428 | CCREG _ASSIGN_BANG BITTST LPAREN REG COMMA expr RPAREN
2430 if (IS_DREG ($5) && IS_UIMM ($7, 5))
2432 notethat ("LOGI2op: CC =! BITTST (dregs , uimm5 )\n");
2433 $$ = LOGI2OP ($5, uimm5 ($7), 0);
2435 else
2436 return yyerror ("Register mismatch or value error");
2439 | CCREG ASSIGN BITTST LPAREN REG COMMA expr RPAREN
2441 if (IS_DREG ($5) && IS_UIMM ($7, 5))
2443 notethat ("LOGI2op: CC = BITTST (dregs , uimm5 )\n");
2444 $$ = LOGI2OP ($5, uimm5 ($7), 1);
2446 else
2447 return yyerror ("Register mismatch or value error");
2450 | IF BANG CCREG REG ASSIGN REG
2452 if ((IS_DREG ($4) || IS_PREG ($4))
2453 && (IS_DREG ($6) || IS_PREG ($6)))
2455 notethat ("ccMV: IF ! CC gregs = gregs\n");
2456 $$ = CCMV (&$6, &$4, 0);
2458 else
2459 return yyerror ("Register mismatch");
2462 | IF CCREG REG ASSIGN REG
2464 if ((IS_DREG ($5) || IS_PREG ($5))
2465 && (IS_DREG ($3) || IS_PREG ($3)))
2467 notethat ("ccMV: IF CC gregs = gregs\n");
2468 $$ = CCMV (&$5, &$3, 1);
2470 else
2471 return yyerror ("Register mismatch");
2474 | IF BANG CCREG JUMP expr
2476 if (IS_PCREL10 ($5))
2478 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2479 $$ = BRCC (0, 0, $5);
2481 else
2482 return yyerror ("Bad jump offset");
2485 | IF BANG CCREG JUMP expr LPAREN BP RPAREN
2487 if (IS_PCREL10 ($5))
2489 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2490 $$ = BRCC (0, 1, $5);
2492 else
2493 return yyerror ("Bad jump offset");
2496 | IF CCREG JUMP expr
2498 if (IS_PCREL10 ($4))
2500 notethat ("BRCC: IF CC JUMP pcrel11m2\n");
2501 $$ = BRCC (1, 0, $4);
2503 else
2504 return yyerror ("Bad jump offset");
2507 | IF CCREG JUMP expr LPAREN BP RPAREN
2509 if (IS_PCREL10 ($4))
2511 notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
2512 $$ = BRCC (1, 1, $4);
2514 else
2515 return yyerror ("Bad jump offset");
2517 | NOP
2519 notethat ("ProgCtrl: NOP\n");
2520 $$ = PROGCTRL (0, 0);
2523 | RTS
2525 notethat ("ProgCtrl: RTS\n");
2526 $$ = PROGCTRL (1, 0);
2529 | RTI
2531 notethat ("ProgCtrl: RTI\n");
2532 $$ = PROGCTRL (1, 1);
2535 | RTX
2537 notethat ("ProgCtrl: RTX\n");
2538 $$ = PROGCTRL (1, 2);
2541 | RTN
2543 notethat ("ProgCtrl: RTN\n");
2544 $$ = PROGCTRL (1, 3);
2547 | RTE
2549 notethat ("ProgCtrl: RTE\n");
2550 $$ = PROGCTRL (1, 4);
2553 | IDLE
2555 notethat ("ProgCtrl: IDLE\n");
2556 $$ = PROGCTRL (2, 0);
2559 | CSYNC
2561 notethat ("ProgCtrl: CSYNC\n");
2562 $$ = PROGCTRL (2, 3);
2565 | SSYNC
2567 notethat ("ProgCtrl: SSYNC\n");
2568 $$ = PROGCTRL (2, 4);
2571 | EMUEXCPT
2573 notethat ("ProgCtrl: EMUEXCPT\n");
2574 $$ = PROGCTRL (2, 5);
2577 | CLI REG
2579 if (IS_DREG ($2))
2581 notethat ("ProgCtrl: CLI dregs\n");
2582 $$ = PROGCTRL (3, $2.regno & CODE_MASK);
2584 else
2585 return yyerror ("Dreg expected for CLI");
2588 | STI REG
2590 if (IS_DREG ($2))
2592 notethat ("ProgCtrl: STI dregs\n");
2593 $$ = PROGCTRL (4, $2.regno & CODE_MASK);
2595 else
2596 return yyerror ("Dreg expected for STI");
2599 | JUMP LPAREN REG RPAREN
2601 if (IS_PREG ($3))
2603 notethat ("ProgCtrl: JUMP (pregs )\n");
2604 $$ = PROGCTRL (5, $3.regno & CODE_MASK);
2606 else
2607 return yyerror ("Bad register for indirect jump");
2610 | CALL LPAREN REG RPAREN
2612 if (IS_PREG ($3))
2614 notethat ("ProgCtrl: CALL (pregs )\n");
2615 $$ = PROGCTRL (6, $3.regno & CODE_MASK);
2617 else
2618 return yyerror ("Bad register for indirect call");
2621 | CALL LPAREN PC PLUS REG RPAREN
2623 if (IS_PREG ($5))
2625 notethat ("ProgCtrl: CALL (PC + pregs )\n");
2626 $$ = PROGCTRL (7, $5.regno & CODE_MASK);
2628 else
2629 return yyerror ("Bad register for indirect call");
2632 | JUMP LPAREN PC PLUS REG RPAREN
2634 if (IS_PREG ($5))
2636 notethat ("ProgCtrl: JUMP (PC + pregs )\n");
2637 $$ = PROGCTRL (8, $5.regno & CODE_MASK);
2639 else
2640 return yyerror ("Bad register for indirect jump");
2643 | RAISE expr
2645 if (IS_UIMM ($2, 4))
2647 notethat ("ProgCtrl: RAISE uimm4\n");
2648 $$ = PROGCTRL (9, uimm4 ($2));
2650 else
2651 return yyerror ("Bad value for RAISE");
2654 | EXCPT expr
2656 notethat ("ProgCtrl: EMUEXCPT\n");
2657 $$ = PROGCTRL (10, uimm4 ($2));
2660 | TESTSET LPAREN REG RPAREN
2662 if (IS_PREG ($3))
2664 notethat ("ProgCtrl: TESTSET (pregs )\n");
2665 $$ = PROGCTRL (11, $3.regno & CODE_MASK);
2667 else
2668 return yyerror ("Preg expected");
2671 | JUMP expr
2673 if (IS_PCREL12 ($2))
2675 notethat ("UJUMP: JUMP pcrel12\n");
2676 $$ = UJUMP ($2);
2678 else
2679 return yyerror ("Bad value for relative jump");
2682 | JUMP_DOT_S expr
2684 if (IS_PCREL12 ($2))
2686 notethat ("UJUMP: JUMP_DOT_S pcrel12\n");
2687 $$ = UJUMP($2);
2689 else
2690 return yyerror ("Bad value for relative jump");
2693 | JUMP_DOT_L expr
2695 if (IS_PCREL24 ($2))
2697 notethat ("CALLa: jump.l pcrel24\n");
2698 $$ = CALLA ($2, 0);
2700 else
2701 return yyerror ("Bad value for long jump");
2704 | JUMP_DOT_L pltpc
2706 if (IS_PCREL24 ($2))
2708 notethat ("CALLa: jump.l pcrel24\n");
2709 $$ = CALLA ($2, 2);
2711 else
2712 return yyerror ("Bad value for long jump");
2715 | CALL expr
2717 if (IS_PCREL24 ($2))
2719 notethat ("CALLa: CALL pcrel25m2\n");
2720 $$ = CALLA ($2, 1);
2722 else
2723 return yyerror ("Bad call address");
2725 | CALL pltpc
2727 if (IS_PCREL24 ($2))
2729 notethat ("CALLa: CALL pcrel25m2\n");
2730 $$ = CALLA ($2, 2);
2732 else
2733 return yyerror ("Bad call address");
2736 /* ALU2ops. */
2737 /* ALU2op: DIVQ (dregs, dregs). */
2738 | DIVQ LPAREN REG COMMA REG RPAREN
2740 if (IS_DREG ($3) && IS_DREG ($5))
2741 $$ = ALU2OP (&$3, &$5, 8);
2742 else
2743 return yyerror ("Bad registers for DIVQ");
2746 | DIVS LPAREN REG COMMA REG RPAREN
2748 if (IS_DREG ($3) && IS_DREG ($5))
2749 $$ = ALU2OP (&$3, &$5, 9);
2750 else
2751 return yyerror ("Bad registers for DIVS");
2754 | REG ASSIGN MINUS REG vsmod
2756 if (IS_DREG ($1) && IS_DREG ($4))
2758 if ($5.r0 == 0 && $5.s0 == 0 && $5.aop == 0)
2760 notethat ("ALU2op: dregs = - dregs\n");
2761 $$ = ALU2OP (&$1, &$4, 14);
2763 else if ($5.r0 == 1 && $5.s0 == 0 && $5.aop == 3)
2765 notethat ("dsp32alu: dregs = - dregs (.)\n");
2766 $$ = DSP32ALU (15, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
2768 else
2770 notethat ("dsp32alu: dregs = - dregs (.)\n");
2771 $$ = DSP32ALU (7, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
2774 else
2775 return yyerror ("Dregs expected");
2778 | REG ASSIGN TILDA REG
2780 if (IS_DREG ($1) && IS_DREG ($4))
2782 notethat ("ALU2op: dregs = ~dregs\n");
2783 $$ = ALU2OP (&$1, &$4, 15);
2785 else
2786 return yyerror ("Dregs expected");
2789 | REG _GREATER_GREATER_ASSIGN REG
2791 if (IS_DREG ($1) && IS_DREG ($3))
2793 notethat ("ALU2op: dregs >>= dregs\n");
2794 $$ = ALU2OP (&$1, &$3, 1);
2796 else
2797 return yyerror ("Dregs expected");
2800 | REG _GREATER_GREATER_ASSIGN expr
2802 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2804 notethat ("LOGI2op: dregs >>= uimm5\n");
2805 $$ = LOGI2OP ($1, uimm5 ($3), 6);
2807 else
2808 return yyerror ("Dregs expected or value error");
2811 | REG _GREATER_GREATER_GREATER_THAN_ASSIGN REG
2813 if (IS_DREG ($1) && IS_DREG ($3))
2815 notethat ("ALU2op: dregs >>>= dregs\n");
2816 $$ = ALU2OP (&$1, &$3, 0);
2818 else
2819 return yyerror ("Dregs expected");
2822 | REG _LESS_LESS_ASSIGN REG
2824 if (IS_DREG ($1) && IS_DREG ($3))
2826 notethat ("ALU2op: dregs <<= dregs\n");
2827 $$ = ALU2OP (&$1, &$3, 2);
2829 else
2830 return yyerror ("Dregs expected");
2833 | REG _LESS_LESS_ASSIGN expr
2835 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2837 notethat ("LOGI2op: dregs <<= uimm5\n");
2838 $$ = LOGI2OP ($1, uimm5 ($3), 7);
2840 else
2841 return yyerror ("Dregs expected or const value error");
2845 | REG _GREATER_GREATER_GREATER_THAN_ASSIGN expr
2847 if (IS_DREG ($1) && IS_UIMM ($3, 5))
2849 notethat ("LOGI2op: dregs >>>= uimm5\n");
2850 $$ = LOGI2OP ($1, uimm5 ($3), 5);
2852 else
2853 return yyerror ("Dregs expected");
2856 /* Cache Control. */
2858 | FLUSH LBRACK REG RBRACK
2860 notethat ("CaCTRL: FLUSH [ pregs ]\n");
2861 if (IS_PREG ($3))
2862 $$ = CACTRL (&$3, 0, 2);
2863 else
2864 return yyerror ("Bad register(s) for FLUSH");
2867 | FLUSH reg_with_postinc
2869 if (IS_PREG ($2))
2871 notethat ("CaCTRL: FLUSH [ pregs ++ ]\n");
2872 $$ = CACTRL (&$2, 1, 2);
2874 else
2875 return yyerror ("Bad register(s) for FLUSH");
2878 | FLUSHINV LBRACK REG RBRACK
2880 if (IS_PREG ($3))
2882 notethat ("CaCTRL: FLUSHINV [ pregs ]\n");
2883 $$ = CACTRL (&$3, 0, 1);
2885 else
2886 return yyerror ("Bad register(s) for FLUSH");
2889 | FLUSHINV reg_with_postinc
2891 if (IS_PREG ($2))
2893 notethat ("CaCTRL: FLUSHINV [ pregs ++ ]\n");
2894 $$ = CACTRL (&$2, 1, 1);
2896 else
2897 return yyerror ("Bad register(s) for FLUSH");
2900 /* CaCTRL: IFLUSH [pregs]. */
2901 | IFLUSH LBRACK REG RBRACK
2903 if (IS_PREG ($3))
2905 notethat ("CaCTRL: IFLUSH [ pregs ]\n");
2906 $$ = CACTRL (&$3, 0, 3);
2908 else
2909 return yyerror ("Bad register(s) for FLUSH");
2912 | IFLUSH reg_with_postinc
2914 if (IS_PREG ($2))
2916 notethat ("CaCTRL: IFLUSH [ pregs ++ ]\n");
2917 $$ = CACTRL (&$2, 1, 3);
2919 else
2920 return yyerror ("Bad register(s) for FLUSH");
2923 | PREFETCH LBRACK REG RBRACK
2925 if (IS_PREG ($3))
2927 notethat ("CaCTRL: PREFETCH [ pregs ]\n");
2928 $$ = CACTRL (&$3, 0, 0);
2930 else
2931 return yyerror ("Bad register(s) for PREFETCH");
2934 | PREFETCH reg_with_postinc
2936 if (IS_PREG ($2))
2938 notethat ("CaCTRL: PREFETCH [ pregs ++ ]\n");
2939 $$ = CACTRL (&$2, 1, 0);
2941 else
2942 return yyerror ("Bad register(s) for PREFETCH");
2945 /* LOAD/STORE. */
2946 /* LDST: B [ pregs <post_op> ] = dregs. */
2948 | B LBRACK REG post_op RBRACK ASSIGN REG
2950 if (!IS_DREG ($7))
2951 return yyerror ("Dreg expected for source operand");
2952 if (!IS_PREG ($3))
2953 return yyerror ("Preg expected in address");
2955 notethat ("LDST: B [ pregs <post_op> ] = dregs\n");
2956 $$ = LDST (&$3, &$7, $4.x0, 2, 0, 1);
2959 /* LDSTidxI: B [ pregs + imm16 ] = dregs. */
2960 | B LBRACK REG plus_minus expr RBRACK ASSIGN REG
2962 Expr_Node *tmp = $5;
2964 if (!IS_DREG ($8))
2965 return yyerror ("Dreg expected for source operand");
2966 if (!IS_PREG ($3))
2967 return yyerror ("Preg expected in address");
2969 if (IS_RELOC ($5))
2970 return yyerror ("Plain symbol used as offset");
2972 if ($4.r0)
2973 tmp = unary (Expr_Op_Type_NEG, tmp);
2975 if (in_range_p (tmp, -32768, 32767, 0))
2977 notethat ("LDST: B [ pregs + imm16 ] = dregs\n");
2978 $$ = LDSTIDXI (&$3, &$8, 1, 2, 0, $5);
2980 else
2981 return yyerror ("Displacement out of range");
2985 /* LDSTii: W [ pregs + uimm4s2 ] = dregs. */
2986 | W LBRACK REG plus_minus expr RBRACK ASSIGN REG
2988 Expr_Node *tmp = $5;
2990 if (!IS_DREG ($8))
2991 return yyerror ("Dreg expected for source operand");
2992 if (!IS_PREG ($3))
2993 return yyerror ("Preg expected in address");
2995 if ($4.r0)
2996 tmp = unary (Expr_Op_Type_NEG, tmp);
2998 if (IS_RELOC ($5))
2999 return yyerror ("Plain symbol used as offset");
3001 if (in_range_p (tmp, 0, 30, 1))
3003 notethat ("LDSTii: W [ pregs +- uimm5m2 ] = dregs\n");
3004 $$ = LDSTII (&$3, &$8, tmp, 1, 1);
3006 else if (in_range_p (tmp, -65536, 65535, 1))
3008 notethat ("LDSTidxI: W [ pregs + imm17m2 ] = dregs\n");
3009 $$ = LDSTIDXI (&$3, &$8, 1, 1, 0, tmp);
3011 else
3012 return yyerror ("Displacement out of range");
3015 /* LDST: W [ pregs <post_op> ] = dregs. */
3016 | W LBRACK REG post_op RBRACK ASSIGN REG
3018 if (!IS_DREG ($7))
3019 return yyerror ("Dreg expected for source operand");
3020 if (!IS_PREG ($3))
3021 return yyerror ("Preg expected in address");
3023 notethat ("LDST: W [ pregs <post_op> ] = dregs\n");
3024 $$ = LDST (&$3, &$7, $4.x0, 1, 0, 1);
3027 | W LBRACK REG post_op RBRACK ASSIGN HALF_REG
3029 if (!IS_DREG ($7))
3030 return yyerror ("Dreg expected for source operand");
3031 if ($4.x0 == 2)
3033 if (!IS_IREG ($3) && !IS_PREG ($3))
3034 return yyerror ("Ireg or Preg expected in address");
3036 else if (!IS_IREG ($3))
3037 return yyerror ("Ireg expected in address");
3039 if (IS_IREG ($3))
3041 notethat ("dspLDST: W [ iregs <post_op> ] = dregs_half\n");
3042 $$ = DSPLDST (&$3, 1 + IS_H ($7), &$7, $4.x0, 1);
3044 else
3046 notethat ("LDSTpmod: W [ pregs ] = dregs_half\n");
3047 $$ = LDSTPMOD (&$3, &$7, &$3, 1 + IS_H ($7), 1);
3051 /* LDSTiiFP: [ FP - const ] = dpregs. */
3052 | LBRACK REG plus_minus expr RBRACK ASSIGN REG
3054 Expr_Node *tmp = $4;
3055 int ispreg = IS_PREG ($7);
3057 if (!IS_PREG ($2))
3058 return yyerror ("Preg expected in address");
3060 if (!IS_DREG ($7) && !ispreg)
3061 return yyerror ("Preg expected for source operand");
3063 if ($3.r0)
3064 tmp = unary (Expr_Op_Type_NEG, tmp);
3066 if (IS_RELOC ($4))
3067 return yyerror ("Plain symbol used as offset");
3069 if (in_range_p (tmp, 0, 63, 3))
3071 notethat ("LDSTii: dpregs = [ pregs + uimm6m4 ]\n");
3072 $$ = LDSTII (&$2, &$7, tmp, 1, ispreg ? 3 : 0);
3074 else if ($2.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
3076 notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
3077 tmp = unary (Expr_Op_Type_NEG, tmp);
3078 $$ = LDSTIIFP (tmp, &$7, 1);
3080 else if (in_range_p (tmp, -131072, 131071, 3))
3082 notethat ("LDSTidxI: [ pregs + imm18m4 ] = dpregs\n");
3083 $$ = LDSTIDXI (&$2, &$7, 1, 0, ispreg ? 1 : 0, tmp);
3085 else
3086 return yyerror ("Displacement out of range");
3089 | REG ASSIGN W LBRACK REG plus_minus expr RBRACK xpmod
3091 Expr_Node *tmp = $7;
3092 if (!IS_DREG ($1))
3093 return yyerror ("Dreg expected for destination operand");
3094 if (!IS_PREG ($5))
3095 return yyerror ("Preg expected in address");
3097 if ($6.r0)
3098 tmp = unary (Expr_Op_Type_NEG, tmp);
3100 if (IS_RELOC ($7))
3101 return yyerror ("Plain symbol used as offset");
3103 if (in_range_p (tmp, 0, 30, 1))
3105 notethat ("LDSTii: dregs = W [ pregs + uimm5m2 ] (.)\n");
3106 $$ = LDSTII (&$5, &$1, tmp, 0, 1 << $9.r0);
3108 else if (in_range_p (tmp, -65536, 65535, 1))
3110 notethat ("LDSTidxI: dregs = W [ pregs + imm17m2 ] (.)\n");
3111 $$ = LDSTIDXI (&$5, &$1, 0, 1, $9.r0, tmp);
3113 else
3114 return yyerror ("Displacement out of range");
3117 | HALF_REG ASSIGN W LBRACK REG post_op RBRACK
3119 if (!IS_DREG ($1))
3120 return yyerror ("Dreg expected for source operand");
3121 if ($6.x0 == 2)
3123 if (!IS_IREG ($5) && !IS_PREG ($5))
3124 return yyerror ("Ireg or Preg expected in address");
3126 else if (!IS_IREG ($5))
3127 return yyerror ("Ireg expected in address");
3129 if (IS_IREG ($5))
3131 notethat ("dspLDST: dregs_half = W [ iregs <post_op> ]\n");
3132 $$ = DSPLDST(&$5, 1 + IS_H ($1), &$1, $6.x0, 0);
3134 else
3136 notethat ("LDSTpmod: dregs_half = W [ pregs <post_op> ]\n");
3137 $$ = LDSTPMOD (&$5, &$1, &$5, 1 + IS_H ($1), 0);
3142 | REG ASSIGN W LBRACK REG post_op RBRACK xpmod
3144 if (!IS_DREG ($1))
3145 return yyerror ("Dreg expected for destination operand");
3146 if (!IS_PREG ($5))
3147 return yyerror ("Preg expected in address");
3149 notethat ("LDST: dregs = W [ pregs <post_op> ] (.)\n");
3150 $$ = LDST (&$5, &$1, $6.x0, 1, $8.r0, 0);
3153 | REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK xpmod
3155 if (!IS_DREG ($1))
3156 return yyerror ("Dreg expected for destination operand");
3157 if (!IS_PREG ($5) || !IS_PREG ($7))
3158 return yyerror ("Preg expected in address");
3160 notethat ("LDSTpmod: dregs = W [ pregs ++ pregs ] (.)\n");
3161 $$ = LDSTPMOD (&$5, &$1, &$7, 3, $9.r0);
3164 | HALF_REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK
3166 if (!IS_DREG ($1))
3167 return yyerror ("Dreg expected for destination operand");
3168 if (!IS_PREG ($5) || !IS_PREG ($7))
3169 return yyerror ("Preg expected in address");
3171 notethat ("LDSTpmod: dregs_half = W [ pregs ++ pregs ]\n");
3172 $$ = LDSTPMOD (&$5, &$1, &$7, 1 + IS_H ($1), 0);
3175 | LBRACK REG post_op RBRACK ASSIGN REG
3177 if (!IS_IREG ($2) && !IS_PREG ($2))
3178 return yyerror ("Ireg or Preg expected in address");
3179 else if (IS_IREG ($2) && !IS_DREG ($6))
3180 return yyerror ("Dreg expected for source operand");
3181 else if (IS_PREG ($2) && !IS_DREG ($6) && !IS_PREG ($6))
3182 return yyerror ("Dreg or Preg expected for source operand");
3184 if (IS_IREG ($2))
3186 notethat ("dspLDST: [ iregs <post_op> ] = dregs\n");
3187 $$ = DSPLDST(&$2, 0, &$6, $3.x0, 1);
3189 else if (IS_DREG ($6))
3191 notethat ("LDST: [ pregs <post_op> ] = dregs\n");
3192 $$ = LDST (&$2, &$6, $3.x0, 0, 0, 1);
3194 else
3196 notethat ("LDST: [ pregs <post_op> ] = pregs\n");
3197 $$ = LDST (&$2, &$6, $3.x0, 0, 1, 1);
3201 | LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN REG
3203 if (!IS_DREG ($7))
3204 return yyerror ("Dreg expected for source operand");
3206 if (IS_IREG ($2) && IS_MREG ($4))
3208 notethat ("dspLDST: [ iregs ++ mregs ] = dregs\n");
3209 $$ = DSPLDST(&$2, $4.regno & CODE_MASK, &$7, 3, 1);
3211 else if (IS_PREG ($2) && IS_PREG ($4))
3213 notethat ("LDSTpmod: [ pregs ++ pregs ] = dregs\n");
3214 $$ = LDSTPMOD (&$2, &$7, &$4, 0, 1);
3216 else
3217 return yyerror ("Preg ++ Preg or Ireg ++ Mreg expected in address");
3220 | W LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN HALF_REG
3222 if (!IS_DREG ($8))
3223 return yyerror ("Dreg expected for source operand");
3225 if (IS_PREG ($3) && IS_PREG ($5))
3227 notethat ("LDSTpmod: W [ pregs ++ pregs ] = dregs_half\n");
3228 $$ = LDSTPMOD (&$3, &$8, &$5, 1 + IS_H ($8), 1);
3230 else
3231 return yyerror ("Preg ++ Preg expected in address");
3234 | REG ASSIGN B LBRACK REG plus_minus expr RBRACK xpmod
3236 Expr_Node *tmp = $7;
3237 if (!IS_DREG ($1))
3238 return yyerror ("Dreg expected for destination operand");
3239 if (!IS_PREG ($5))
3240 return yyerror ("Preg expected in address");
3242 if ($6.r0)
3243 tmp = unary (Expr_Op_Type_NEG, tmp);
3245 if (IS_RELOC ($7))
3246 return yyerror ("Plain symbol used as offset");
3248 if (in_range_p (tmp, -32768, 32767, 0))
3250 notethat ("LDSTidxI: dregs = B [ pregs + imm16 ] (%c)\n",
3251 $9.r0 ? 'X' : 'Z');
3252 $$ = LDSTIDXI (&$5, &$1, 0, 2, $9.r0, tmp);
3254 else
3255 return yyerror ("Displacement out of range");
3258 | REG ASSIGN B LBRACK REG post_op RBRACK xpmod
3260 if (!IS_DREG ($1))
3261 return yyerror ("Dreg expected for destination operand");
3262 if (!IS_PREG ($5))
3263 return yyerror ("Preg expected in address");
3265 notethat ("LDST: dregs = B [ pregs <post_op> ] (%c)\n",
3266 $8.r0 ? 'X' : 'Z');
3267 $$ = LDST (&$5, &$1, $6.x0, 2, $8.r0, 0);
3270 | REG ASSIGN LBRACK REG _PLUS_PLUS REG RBRACK
3272 if (!IS_DREG ($1))
3273 return yyerror ("Dreg expected for destination operand");
3275 if (IS_IREG ($4) && IS_MREG ($6))
3277 notethat ("dspLDST: dregs = [ iregs ++ mregs ]\n");
3278 $$ = DSPLDST(&$4, $6.regno & CODE_MASK, &$1, 3, 0);
3280 else if (IS_PREG ($4) && IS_PREG ($6))
3282 notethat ("LDSTpmod: dregs = [ pregs ++ pregs ]\n");
3283 $$ = LDSTPMOD (&$4, &$1, &$6, 0, 0);
3285 else
3286 return yyerror ("Preg ++ Preg or Ireg ++ Mreg expected in address");
3289 | REG ASSIGN LBRACK REG plus_minus got_or_expr RBRACK
3291 Expr_Node *tmp = $6;
3292 int ispreg = IS_PREG ($1);
3293 int isgot = IS_RELOC($6);
3295 if (!IS_PREG ($4))
3296 return yyerror ("Preg expected in address");
3298 if (!IS_DREG ($1) && !ispreg)
3299 return yyerror ("Dreg or Preg expected for destination operand");
3301 if (tmp->type == Expr_Node_Reloc
3302 && strcmp (tmp->value.s_value,
3303 "_current_shared_library_p5_offset_") != 0)
3304 return yyerror ("Plain symbol used as offset");
3306 if ($5.r0)
3307 tmp = unary (Expr_Op_Type_NEG, tmp);
3309 if (isgot)
3311 notethat ("LDSTidxI: dpregs = [ pregs + sym@got ]\n");
3312 $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1 : 0, tmp);
3314 else if (in_range_p (tmp, 0, 63, 3))
3316 notethat ("LDSTii: dpregs = [ pregs + uimm7m4 ]\n");
3317 $$ = LDSTII (&$4, &$1, tmp, 0, ispreg ? 3 : 0);
3319 else if ($4.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
3321 notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
3322 tmp = unary (Expr_Op_Type_NEG, tmp);
3323 $$ = LDSTIIFP (tmp, &$1, 0);
3325 else if (in_range_p (tmp, -131072, 131071, 3))
3327 notethat ("LDSTidxI: dpregs = [ pregs + imm18m4 ]\n");
3328 $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1 : 0, tmp);
3331 else
3332 return yyerror ("Displacement out of range");
3335 | REG ASSIGN LBRACK REG post_op RBRACK
3337 if (!IS_IREG ($4) && !IS_PREG ($4))
3338 return yyerror ("Ireg or Preg expected in address");
3339 else if (IS_IREG ($4) && !IS_DREG ($1))
3340 return yyerror ("Dreg expected in destination operand");
3341 else if (IS_PREG ($4) && !IS_DREG ($1) && !IS_PREG ($1)
3342 && ($4.regno != REG_SP || !IS_ALLREG ($1) || $5.x0 != 0))
3343 return yyerror ("Dreg or Preg expected in destination operand");
3345 if (IS_IREG ($4))
3347 notethat ("dspLDST: dregs = [ iregs <post_op> ]\n");
3348 $$ = DSPLDST (&$4, 0, &$1, $5.x0, 0);
3350 else if (IS_DREG ($1))
3352 notethat ("LDST: dregs = [ pregs <post_op> ]\n");
3353 $$ = LDST (&$4, &$1, $5.x0, 0, 0, 0);
3355 else if (IS_PREG ($1))
3357 if (REG_SAME ($1, $4) && $5.x0 != 2)
3358 return yyerror ("Pregs can't be same");
3360 notethat ("LDST: pregs = [ pregs <post_op> ]\n");
3361 $$ = LDST (&$4, &$1, $5.x0, 0, 1, 0);
3363 else
3365 notethat ("PushPopReg: allregs = [ SP ++ ]\n");
3366 $$ = PUSHPOPREG (&$1, 0);
3371 /* PushPopMultiple. */
3372 | reg_with_predec ASSIGN LPAREN REG COLON expr COMMA REG COLON expr RPAREN
3374 if ($1.regno != REG_SP)
3375 yyerror ("Stack Pointer expected");
3376 if ($4.regno == REG_R7
3377 && IN_RANGE ($6, 0, 7)
3378 && $8.regno == REG_P5
3379 && IN_RANGE ($10, 0, 5))
3381 notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim , P5 : reglim )\n");
3382 $$ = PUSHPOPMULTIPLE (imm5 ($6), imm5 ($10), 1, 1, 1);
3384 else
3385 return yyerror ("Bad register for PushPopMultiple");
3388 | reg_with_predec ASSIGN LPAREN REG COLON expr RPAREN
3390 if ($1.regno != REG_SP)
3391 yyerror ("Stack Pointer expected");
3393 if ($4.regno == REG_R7 && IN_RANGE ($6, 0, 7))
3395 notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim )\n");
3396 $$ = PUSHPOPMULTIPLE (imm5 ($6), 0, 1, 0, 1);
3398 else if ($4.regno == REG_P5 && IN_RANGE ($6, 0, 6))
3400 notethat ("PushPopMultiple: [ -- SP ] = (P5 : reglim )\n");
3401 $$ = PUSHPOPMULTIPLE (0, imm5 ($6), 0, 1, 1);
3403 else
3404 return yyerror ("Bad register for PushPopMultiple");
3407 | LPAREN REG COLON expr COMMA REG COLON expr RPAREN ASSIGN reg_with_postinc
3409 if ($11.regno != REG_SP)
3410 yyerror ("Stack Pointer expected");
3411 if ($2.regno == REG_R7 && (IN_RANGE ($4, 0, 7))
3412 && $6.regno == REG_P5 && (IN_RANGE ($8, 0, 6)))
3414 notethat ("PushPopMultiple: (R7 : reglim , P5 : reglim ) = [ SP ++ ]\n");
3415 $$ = PUSHPOPMULTIPLE (imm5 ($4), imm5 ($8), 1, 1, 0);
3417 else
3418 return yyerror ("Bad register range for PushPopMultiple");
3421 | LPAREN REG COLON expr RPAREN ASSIGN reg_with_postinc
3423 if ($7.regno != REG_SP)
3424 yyerror ("Stack Pointer expected");
3426 if ($2.regno == REG_R7 && IN_RANGE ($4, 0, 7))
3428 notethat ("PushPopMultiple: (R7 : reglim ) = [ SP ++ ]\n");
3429 $$ = PUSHPOPMULTIPLE (imm5 ($4), 0, 1, 0, 0);
3431 else if ($2.regno == REG_P5 && IN_RANGE ($4, 0, 6))
3433 notethat ("PushPopMultiple: (P5 : reglim ) = [ SP ++ ]\n");
3434 $$ = PUSHPOPMULTIPLE (0, imm5 ($4), 0, 1, 0);
3436 else
3437 return yyerror ("Bad register range for PushPopMultiple");
3440 | reg_with_predec ASSIGN REG
3442 if ($1.regno != REG_SP)
3443 yyerror ("Stack Pointer expected");
3445 if (IS_ALLREG ($3))
3447 notethat ("PushPopReg: [ -- SP ] = allregs\n");
3448 $$ = PUSHPOPREG (&$3, 1);
3450 else
3451 return yyerror ("Bad register for PushPopReg");
3454 /* Linkage. */
3456 | LINK expr
3458 if (IS_URANGE (16, $2, 0, 4))
3459 $$ = LINKAGE (0, uimm16s4 ($2));
3460 else
3461 return yyerror ("Bad constant for LINK");
3464 | UNLINK
3466 notethat ("linkage: UNLINK\n");
3467 $$ = LINKAGE (1, 0);
3471 /* LSETUP. */
3473 | LSETUP LPAREN expr COMMA expr RPAREN REG
3475 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5) && IS_CREG ($7))
3477 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters\n");
3478 $$ = LOOPSETUP ($3, &$7, 0, $5, 0);
3480 else
3481 return yyerror ("Bad register or values for LSETUP");
3484 | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG
3486 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
3487 && IS_PREG ($9) && IS_CREG ($7))
3489 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs\n");
3490 $$ = LOOPSETUP ($3, &$7, 1, $5, &$9);
3492 else
3493 return yyerror ("Bad register or values for LSETUP");
3496 | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG GREATER_GREATER expr
3498 if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
3499 && IS_PREG ($9) && IS_CREG ($7)
3500 && EXPR_VALUE ($11) == 1)
3502 notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs >> 1\n");
3503 $$ = LOOPSETUP ($3, &$7, 3, $5, &$9);
3505 else
3506 return yyerror ("Bad register or values for LSETUP");
3509 /* LOOP. */
3510 | LOOP expr REG
3512 if (!IS_RELOC ($2))
3513 return yyerror ("Invalid expression in loop statement");
3514 if (!IS_CREG ($3))
3515 return yyerror ("Invalid loop counter register");
3516 $$ = bfin_gen_loop ($2, &$3, 0, 0);
3518 | LOOP expr REG ASSIGN REG
3520 if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3))
3522 notethat ("Loop: LOOP expr counters = pregs\n");
3523 $$ = bfin_gen_loop ($2, &$3, 1, &$5);
3525 else
3526 return yyerror ("Bad register or values for LOOP");
3528 | LOOP expr REG ASSIGN REG GREATER_GREATER expr
3530 if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3) && EXPR_VALUE ($7) == 1)
3532 notethat ("Loop: LOOP expr counters = pregs >> 1\n");
3533 $$ = bfin_gen_loop ($2, &$3, 3, &$5);
3535 else
3536 return yyerror ("Bad register or values for LOOP");
3539 /* LOOP_BEGIN. */
3540 | LOOP_BEGIN expr
3542 if (!IS_RELOC ($2))
3543 return yyerror ("Invalid expression in LOOP_BEGIN statement");
3545 bfin_loop_beginend ($2, 1);
3546 $$ = 0;
3549 /* LOOP_END. */
3550 | LOOP_END expr
3552 if (!IS_RELOC ($2))
3553 return yyerror ("Invalid expression in LOOP_END statement");
3555 bfin_loop_beginend ($2, 0);
3556 $$ = 0;
3559 /* pseudoDEBUG. */
3561 | DBG
3563 notethat ("pseudoDEBUG: DBG\n");
3564 $$ = bfin_gen_pseudodbg (3, 7, 0);
3566 | DBG REG_A
3568 notethat ("pseudoDEBUG: DBG REG_A\n");
3569 $$ = bfin_gen_pseudodbg (3, IS_A1 ($2), 0);
3571 | DBG REG
3573 notethat ("pseudoDEBUG: DBG allregs\n");
3574 $$ = bfin_gen_pseudodbg (0, $2.regno & CODE_MASK, $2.regno & CLASS_MASK);
3577 | DBGCMPLX LPAREN REG RPAREN
3579 if (!IS_DREG ($3))
3580 return yyerror ("Dregs expected");
3581 notethat ("pseudoDEBUG: DBGCMPLX (dregs )\n");
3582 $$ = bfin_gen_pseudodbg (3, 6, $3.regno & CODE_MASK);
3585 | DBGHALT
3587 notethat ("psedoDEBUG: DBGHALT\n");
3588 $$ = bfin_gen_pseudodbg (3, 5, 0);
3591 | HLT
3593 notethat ("psedoDEBUG: HLT\n");
3594 $$ = bfin_gen_pseudodbg (3, 4, 0);
3597 | DBGA LPAREN HALF_REG COMMA expr RPAREN
3599 notethat ("pseudodbg_assert: DBGA (regs_lo/hi , uimm16 )\n");
3600 $$ = bfin_gen_pseudodbg_assert (IS_H ($3), &$3, uimm16 ($5));
3603 | DBGAH LPAREN REG COMMA expr RPAREN
3605 notethat ("pseudodbg_assert: DBGAH (regs , uimm16 )\n");
3606 $$ = bfin_gen_pseudodbg_assert (3, &$3, uimm16 ($5));
3609 | DBGAL LPAREN REG COMMA expr RPAREN
3611 notethat ("psedodbg_assert: DBGAL (regs , uimm16 )\n");
3612 $$ = bfin_gen_pseudodbg_assert (2, &$3, uimm16 ($5));
3618 /* AUX RULES. */
3620 /* Register rules. */
3622 REG_A: REG_A_DOUBLE_ZERO
3624 $$ = $1;
3626 | REG_A_DOUBLE_ONE
3628 $$ = $1;
3633 /* Modifiers. */
3635 opt_mode:
3637 $$.MM = 0;
3638 $$.mod = 0;
3640 | LPAREN M COMMA MMOD RPAREN
3642 $$.MM = 1;
3643 $$.mod = $4;
3645 | LPAREN MMOD COMMA M RPAREN
3647 $$.MM = 1;
3648 $$.mod = $2;
3650 | LPAREN MMOD RPAREN
3652 $$.MM = 0;
3653 $$.mod = $2;
3655 | LPAREN M RPAREN
3657 $$.MM = 1;
3658 $$.mod = 0;
3662 asr_asl: LPAREN ASL RPAREN
3664 $$.r0 = 1;
3666 | LPAREN ASR RPAREN
3668 $$.r0 = 0;
3672 sco:
3674 $$.s0 = 0;
3675 $$.x0 = 0;
3679 $$.s0 = 1;
3680 $$.x0 = 0;
3682 | CO
3684 $$.s0 = 0;
3685 $$.x0 = 1;
3687 | SCO
3689 $$.s0 = 1;
3690 $$.x0 = 1;
3694 asr_asl_0:
3697 $$.r0 = 1;
3699 | ASR
3701 $$.r0 = 0;
3705 amod0:
3707 $$.s0 = 0;
3708 $$.x0 = 0;
3710 | LPAREN sco RPAREN
3712 $$.s0 = $2.s0;
3713 $$.x0 = $2.x0;
3717 amod1:
3719 $$.s0 = 0;
3720 $$.x0 = 0;
3721 $$.aop = 0;
3723 | LPAREN NS RPAREN
3725 $$.s0 = 0;
3726 $$.x0 = 0;
3727 $$.aop = 1;
3729 | LPAREN S RPAREN
3731 $$.s0 = 1;
3732 $$.x0 = 0;
3733 $$.aop = 1;
3737 amod2:
3739 $$.r0 = 0;
3740 $$.s0 = 0;
3741 $$.x0 = 0;
3743 | LPAREN asr_asl_0 RPAREN
3745 $$.r0 = 2 + $2.r0;
3746 $$.s0 = 0;
3747 $$.x0 = 0;
3749 | LPAREN sco RPAREN
3751 $$.r0 = 0;
3752 $$.s0 = $2.s0;
3753 $$.x0 = $2.x0;
3755 | LPAREN asr_asl_0 COMMA sco RPAREN
3757 $$.r0 = 2 + $2.r0;
3758 $$.s0 = $4.s0;
3759 $$.x0 = $4.x0;
3761 | LPAREN sco COMMA asr_asl_0 RPAREN
3763 $$.r0 = 2 + $4.r0;
3764 $$.s0 = $2.s0;
3765 $$.x0 = $2.x0;
3769 xpmod:
3771 $$.r0 = 0;
3773 | LPAREN Z RPAREN
3775 $$.r0 = 0;
3777 | LPAREN X RPAREN
3779 $$.r0 = 1;
3783 xpmod1:
3785 $$.r0 = 0;
3787 | LPAREN X RPAREN
3789 $$.r0 = 0;
3791 | LPAREN Z RPAREN
3793 $$.r0 = 1;
3797 vsmod:
3799 $$.r0 = 0;
3800 $$.s0 = 0;
3801 $$.aop = 0;
3803 | LPAREN NS RPAREN
3805 $$.r0 = 0;
3806 $$.s0 = 0;
3807 $$.aop = 3;
3809 | LPAREN S RPAREN
3811 $$.r0 = 0;
3812 $$.s0 = 1;
3813 $$.aop = 3;
3815 | LPAREN V RPAREN
3817 $$.r0 = 1;
3818 $$.s0 = 0;
3819 $$.aop = 3;
3821 | LPAREN V COMMA S RPAREN
3823 $$.r0 = 1;
3824 $$.s0 = 1;
3826 | LPAREN S COMMA V RPAREN
3828 $$.r0 = 1;
3829 $$.s0 = 1;
3833 vmod:
3835 $$.r0 = 0;
3837 | LPAREN V RPAREN
3839 $$.r0 = 1;
3843 smod:
3845 $$.s0 = 0;
3847 | LPAREN S RPAREN
3849 $$.s0 = 1;
3853 searchmod:
3856 $$.r0 = 1;
3858 | GT
3860 $$.r0 = 0;
3862 | LE
3864 $$.r0 = 3;
3866 | LT
3868 $$.r0 = 2;
3872 aligndir:
3874 $$.r0 = 0;
3876 | LPAREN R RPAREN
3878 $$.r0 = 1;
3882 byteop_mod:
3883 LPAREN R RPAREN
3885 $$.r0 = 0;
3886 $$.s0 = 1;
3888 | LPAREN MMOD RPAREN
3890 if ($2 != M_T)
3891 return yyerror ("Bad modifier");
3892 $$.r0 = 1;
3893 $$.s0 = 0;
3895 | LPAREN MMOD COMMA R RPAREN
3897 if ($2 != M_T)
3898 return yyerror ("Bad modifier");
3899 $$.r0 = 1;
3900 $$.s0 = 1;
3902 | LPAREN R COMMA MMOD RPAREN
3904 if ($4 != M_T)
3905 return yyerror ("Bad modifier");
3906 $$.r0 = 1;
3907 $$.s0 = 1;
3913 c_align:
3914 ALIGN8
3916 $$.r0 = 0;
3918 | ALIGN16
3920 $$.r0 = 1;
3922 | ALIGN24
3924 $$.r0 = 2;
3928 w32_or_nothing:
3930 $$.r0 = 0;
3932 | LPAREN MMOD RPAREN
3934 if ($2 == M_W32)
3935 $$.r0 = 1;
3936 else
3937 return yyerror ("Only (W32) allowed");
3941 iu_or_nothing:
3943 $$.r0 = 1;
3945 | LPAREN MMOD RPAREN
3947 if ($2 == M_IU)
3948 $$.r0 = 3;
3949 else
3950 return yyerror ("(IU) expected");
3954 reg_with_predec: LBRACK _MINUS_MINUS REG RBRACK
3956 $$ = $3;
3960 reg_with_postinc: LBRACK REG _PLUS_PLUS RBRACK
3962 $$ = $2;
3966 /* Operators. */
3968 min_max:
3971 $$.r0 = 1;
3973 | MAX
3975 $$.r0 = 0;
3979 op_bar_op:
3980 _PLUS_BAR_PLUS
3982 $$.r0 = 0;
3984 | _PLUS_BAR_MINUS
3986 $$.r0 = 1;
3988 | _MINUS_BAR_PLUS
3990 $$.r0 = 2;
3992 | _MINUS_BAR_MINUS
3994 $$.r0 = 3;
3998 plus_minus:
3999 PLUS
4001 $$.r0 = 0;
4003 | MINUS
4005 $$.r0 = 1;
4009 rnd_op:
4010 LPAREN RNDH RPAREN
4012 $$.r0 = 1; /* HL. */
4013 $$.s0 = 0; /* s. */
4014 $$.x0 = 0; /* x. */
4015 $$.aop = 0; /* aop. */
4018 | LPAREN TH RPAREN
4020 $$.r0 = 1; /* HL. */
4021 $$.s0 = 0; /* s. */
4022 $$.x0 = 0; /* x. */
4023 $$.aop = 1; /* aop. */
4026 | LPAREN RNDL RPAREN
4028 $$.r0 = 0; /* HL. */
4029 $$.s0 = 0; /* s. */
4030 $$.x0 = 0; /* x. */
4031 $$.aop = 0; /* aop. */
4034 | LPAREN TL RPAREN
4036 $$.r0 = 0; /* HL. */
4037 $$.s0 = 0; /* s. */
4038 $$.x0 = 0; /* x. */
4039 $$.aop = 1;
4042 | LPAREN RNDH COMMA R RPAREN
4044 $$.r0 = 1; /* HL. */
4045 $$.s0 = 1; /* s. */
4046 $$.x0 = 0; /* x. */
4047 $$.aop = 0; /* aop. */
4049 | LPAREN TH COMMA R RPAREN
4051 $$.r0 = 1; /* HL. */
4052 $$.s0 = 1; /* s. */
4053 $$.x0 = 0; /* x. */
4054 $$.aop = 1; /* aop. */
4056 | LPAREN RNDL COMMA R RPAREN
4058 $$.r0 = 0; /* HL. */
4059 $$.s0 = 1; /* s. */
4060 $$.x0 = 0; /* x. */
4061 $$.aop = 0; /* aop. */
4064 | LPAREN TL COMMA R RPAREN
4066 $$.r0 = 0; /* HL. */
4067 $$.s0 = 1; /* s. */
4068 $$.x0 = 0; /* x. */
4069 $$.aop = 1; /* aop. */
4073 b3_op:
4074 LPAREN LO RPAREN
4076 $$.s0 = 0; /* s. */
4077 $$.x0 = 0; /* HL. */
4079 | LPAREN HI RPAREN
4081 $$.s0 = 0; /* s. */
4082 $$.x0 = 1; /* HL. */
4084 | LPAREN LO COMMA R RPAREN
4086 $$.s0 = 1; /* s. */
4087 $$.x0 = 0; /* HL. */
4089 | LPAREN HI COMMA R RPAREN
4091 $$.s0 = 1; /* s. */
4092 $$.x0 = 1; /* HL. */
4096 post_op:
4098 $$.x0 = 2;
4100 | _PLUS_PLUS
4102 $$.x0 = 0;
4104 | _MINUS_MINUS
4106 $$.x0 = 1;
4110 /* Assignments, Macfuncs. */
4112 a_assign:
4113 REG_A ASSIGN
4115 $$ = $1;
4119 a_minusassign:
4120 REG_A _MINUS_ASSIGN
4122 $$ = $1;
4126 a_plusassign:
4127 REG_A _PLUS_ASSIGN
4129 $$ = $1;
4133 assign_macfunc:
4134 REG ASSIGN REG_A
4136 if (IS_A1 ($3) && IS_EVEN ($1))
4137 return yyerror ("Cannot move A1 to even register");
4138 else if (!IS_A1 ($3) && !IS_EVEN ($1))
4139 return yyerror ("Cannot move A0 to odd register");
4141 $$.w = 1;
4142 $$.P = 1;
4143 $$.n = IS_A1 ($3);
4144 $$.op = 3;
4145 $$.dst = $1;
4146 $$.s0.regno = 0;
4147 $$.s1.regno = 0;
4149 | a_macfunc
4151 $$ = $1;
4152 $$.w = 0; $$.P = 0;
4153 $$.dst.regno = 0;
4155 | REG ASSIGN LPAREN a_macfunc RPAREN
4157 if ($4.n && IS_EVEN ($1))
4158 return yyerror ("Cannot move A1 to even register");
4159 else if (!$4.n && !IS_EVEN ($1))
4160 return yyerror ("Cannot move A0 to odd register");
4162 $$ = $4;
4163 $$.w = 1;
4164 $$.P = 1;
4165 $$.dst = $1;
4168 | HALF_REG ASSIGN LPAREN a_macfunc RPAREN
4170 if ($4.n && !IS_H ($1))
4171 return yyerror ("Cannot move A1 to low half of register");
4172 else if (!$4.n && IS_H ($1))
4173 return yyerror ("Cannot move A0 to high half of register");
4175 $$ = $4;
4176 $$.w = 1;
4177 $$.P = 0;
4178 $$.dst = $1;
4181 | HALF_REG ASSIGN REG_A
4183 if (IS_A1 ($3) && !IS_H ($1))
4184 return yyerror ("Cannot move A1 to low half of register");
4185 else if (!IS_A1 ($3) && IS_H ($1))
4186 return yyerror ("Cannot move A0 to high half of register");
4188 $$.w = 1;
4189 $$.P = 0;
4190 $$.n = IS_A1 ($3);
4191 $$.op = 3;
4192 $$.dst = $1;
4193 $$.s0.regno = 0;
4194 $$.s1.regno = 0;
4198 a_macfunc:
4199 a_assign multiply_halfregs
4201 $$.n = IS_A1 ($1);
4202 $$.op = 0;
4203 $$.s0 = $2.s0;
4204 $$.s1 = $2.s1;
4206 | a_plusassign multiply_halfregs
4208 $$.n = IS_A1 ($1);
4209 $$.op = 1;
4210 $$.s0 = $2.s0;
4211 $$.s1 = $2.s1;
4213 | a_minusassign multiply_halfregs
4215 $$.n = IS_A1 ($1);
4216 $$.op = 2;
4217 $$.s0 = $2.s0;
4218 $$.s1 = $2.s1;
4222 multiply_halfregs:
4223 HALF_REG STAR HALF_REG
4225 if (IS_DREG ($1) && IS_DREG ($3))
4227 $$.s0 = $1;
4228 $$.s1 = $3;
4230 else
4231 return yyerror ("Dregs expected");
4235 cc_op:
4236 ASSIGN
4238 $$.r0 = 0;
4240 | _BAR_ASSIGN
4242 $$.r0 = 1;
4244 | _AMPERSAND_ASSIGN
4246 $$.r0 = 2;
4248 | _CARET_ASSIGN
4250 $$.r0 = 3;
4254 ccstat:
4255 CCREG cc_op STATUS_REG
4257 $$.r0 = $3.regno;
4258 $$.x0 = $2.r0;
4259 $$.s0 = 0;
4261 | CCREG cc_op V
4263 $$.r0 = 0x18;
4264 $$.x0 = $2.r0;
4265 $$.s0 = 0;
4267 | STATUS_REG cc_op CCREG
4269 $$.r0 = $1.regno;
4270 $$.x0 = $2.r0;
4271 $$.s0 = 1;
4273 | V cc_op CCREG
4275 $$.r0 = 0x18;
4276 $$.x0 = $2.r0;
4277 $$.s0 = 1;
4281 /* Expressions and Symbols. */
4283 symbol: SYMBOL
4285 Expr_Node_Value val;
4286 val.s_value = S_GET_NAME($1);
4287 $$ = Expr_Node_Create (Expr_Node_Reloc, val, NULL, NULL);
4291 any_gotrel:
4293 { $$ = BFD_RELOC_BFIN_GOT; }
4294 | GOT17M4
4295 { $$ = BFD_RELOC_BFIN_GOT17M4; }
4296 | FUNCDESC_GOT17M4
4297 { $$ = BFD_RELOC_BFIN_FUNCDESC_GOT17M4; }
4300 got: symbol AT any_gotrel
4302 Expr_Node_Value val;
4303 val.i_value = $3;
4304 $$ = Expr_Node_Create (Expr_Node_GOT_Reloc, val, $1, NULL);
4308 got_or_expr: got
4310 $$ = $1;
4312 | expr
4314 $$ = $1;
4318 pltpc :
4319 symbol AT PLTPC
4321 $$ = $1;
4325 eterm: NUMBER
4327 Expr_Node_Value val;
4328 val.i_value = $1;
4329 $$ = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
4331 | symbol
4333 $$ = $1;
4335 | LPAREN expr_1 RPAREN
4337 $$ = $2;
4339 | TILDA expr_1
4341 $$ = unary (Expr_Op_Type_COMP, $2);
4343 | MINUS expr_1 %prec TILDA
4345 $$ = unary (Expr_Op_Type_NEG, $2);
4349 expr: expr_1
4351 $$ = $1;
4355 expr_1: expr_1 STAR expr_1
4357 $$ = binary (Expr_Op_Type_Mult, $1, $3);
4359 | expr_1 SLASH expr_1
4361 $$ = binary (Expr_Op_Type_Div, $1, $3);
4363 | expr_1 PERCENT expr_1
4365 $$ = binary (Expr_Op_Type_Mod, $1, $3);
4367 | expr_1 PLUS expr_1
4369 $$ = binary (Expr_Op_Type_Add, $1, $3);
4371 | expr_1 MINUS expr_1
4373 $$ = binary (Expr_Op_Type_Sub, $1, $3);
4375 | expr_1 LESS_LESS expr_1
4377 $$ = binary (Expr_Op_Type_Lshift, $1, $3);
4379 | expr_1 GREATER_GREATER expr_1
4381 $$ = binary (Expr_Op_Type_Rshift, $1, $3);
4383 | expr_1 AMPERSAND expr_1
4385 $$ = binary (Expr_Op_Type_BAND, $1, $3);
4387 | expr_1 CARET expr_1
4389 $$ = binary (Expr_Op_Type_LOR, $1, $3);
4391 | expr_1 BAR expr_1
4393 $$ = binary (Expr_Op_Type_BOR, $1, $3);
4395 | eterm
4397 $$ = $1;
4404 EXPR_T
4405 mkexpr (int x, SYMBOL_T s)
4407 EXPR_T e = (EXPR_T) ALLOCATE (sizeof (struct expression_cell));
4408 e->value = x;
4409 EXPR_SYMBOL(e) = s;
4410 return e;
4413 static int
4414 value_match (Expr_Node *exp, int sz, int sign, int mul, int issigned)
4416 int umax = (1 << sz) - 1;
4417 int min = -1 << (sz - 1);
4418 int max = (1 << (sz - 1)) - 1;
4420 int v = (EXPR_VALUE (exp)) & 0xffffffff;
4422 if ((v % mul) != 0)
4424 error ("%s:%d: Value Error -- Must align to %d\n", __FILE__, __LINE__, mul);
4425 return 0;
4428 v /= mul;
4430 if (sign)
4431 v = -v;
4433 if (issigned)
4435 if (v >= min && v <= max) return 1;
4437 #ifdef DEBUG
4438 fprintf(stderr, "signed value %lx out of range\n", v * mul);
4439 #endif
4440 return 0;
4442 if (v <= umax && v >= 0)
4443 return 1;
4444 #ifdef DEBUG
4445 fprintf(stderr, "unsigned value %lx out of range\n", v * mul);
4446 #endif
4447 return 0;
4450 /* Return the expression structure that allows symbol operations.
4451 If the left and right children are constants, do the operation. */
4452 static Expr_Node *
4453 binary (Expr_Op_Type op, Expr_Node *x, Expr_Node *y)
4455 Expr_Node_Value val;
4457 if (x->type == Expr_Node_Constant && y->type == Expr_Node_Constant)
4459 switch (op)
4461 case Expr_Op_Type_Add:
4462 x->value.i_value += y->value.i_value;
4463 break;
4464 case Expr_Op_Type_Sub:
4465 x->value.i_value -= y->value.i_value;
4466 break;
4467 case Expr_Op_Type_Mult:
4468 x->value.i_value *= y->value.i_value;
4469 break;
4470 case Expr_Op_Type_Div:
4471 if (y->value.i_value == 0)
4472 error ("Illegal Expression: Division by zero.");
4473 else
4474 x->value.i_value /= y->value.i_value;
4475 break;
4476 case Expr_Op_Type_Mod:
4477 x->value.i_value %= y->value.i_value;
4478 break;
4479 case Expr_Op_Type_Lshift:
4480 x->value.i_value <<= y->value.i_value;
4481 break;
4482 case Expr_Op_Type_Rshift:
4483 x->value.i_value >>= y->value.i_value;
4484 break;
4485 case Expr_Op_Type_BAND:
4486 x->value.i_value &= y->value.i_value;
4487 break;
4488 case Expr_Op_Type_BOR:
4489 x->value.i_value |= y->value.i_value;
4490 break;
4491 case Expr_Op_Type_BXOR:
4492 x->value.i_value ^= y->value.i_value;
4493 break;
4494 case Expr_Op_Type_LAND:
4495 x->value.i_value = x->value.i_value && y->value.i_value;
4496 break;
4497 case Expr_Op_Type_LOR:
4498 x->value.i_value = x->value.i_value || y->value.i_value;
4499 break;
4501 default:
4502 error ("%s:%d: Internal assembler error\n", __FILE__, __LINE__);
4504 return x;
4506 /* Canonicalize order to EXPR OP CONSTANT. */
4507 if (x->type == Expr_Node_Constant)
4509 Expr_Node *t = x;
4510 x = y;
4511 y = t;
4513 /* Canonicalize subtraction of const to addition of negated const. */
4514 if (op == Expr_Op_Type_Sub && y->type == Expr_Node_Constant)
4516 op = Expr_Op_Type_Add;
4517 y->value.i_value = -y->value.i_value;
4519 if (y->type == Expr_Node_Constant && x->type == Expr_Node_Binop
4520 && x->Right_Child->type == Expr_Node_Constant)
4522 if (op == x->value.op_value && x->value.op_value == Expr_Op_Type_Add)
4524 x->Right_Child->value.i_value += y->value.i_value;
4525 return x;
4529 /* Create a new expression structure. */
4530 val.op_value = op;
4531 return Expr_Node_Create (Expr_Node_Binop, val, x, y);
4534 static Expr_Node *
4535 unary (Expr_Op_Type op, Expr_Node *x)
4537 if (x->type == Expr_Node_Constant)
4539 switch (op)
4541 case Expr_Op_Type_NEG:
4542 x->value.i_value = -x->value.i_value;
4543 break;
4544 case Expr_Op_Type_COMP:
4545 x->value.i_value = ~x->value.i_value;
4546 break;
4547 default:
4548 error ("%s:%d: Internal assembler error\n", __FILE__, __LINE__);
4550 return x;
4552 else
4554 /* Create a new expression structure. */
4555 Expr_Node_Value val;
4556 val.op_value = op;
4557 return Expr_Node_Create (Expr_Node_Unop, val, x, NULL);
4561 int debug_codeselection = 0;
4562 static void
4563 notethat (char *format, ...)
4565 va_list ap;
4566 va_start (ap, format);
4567 if (debug_codeselection)
4569 vfprintf (errorf, format, ap);
4571 va_end (ap);
4574 #ifdef TEST
4575 main (int argc, char **argv)
4577 yyparse();
4579 #endif