OSDN Git Service

gas: blackfin: reject invalid 16bit acc add insns
[pf3gnuchains/pf3gnuchains4x.git] / gas / config / bfin-parse.y
1 /* bfin-parse.y  ADI Blackfin parser
2    Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
3    Free Software Foundation, Inc.
4
5    This file is part of GAS, the GNU Assembler.
6
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.
11
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.
16
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.  */
21 %{
22
23 #include "as.h"
24 #include <obstack.h>
25
26 #include "bfin-aux.h"  /* Opcode generating auxiliaries.  */
27 #include "libbfd.h"
28 #include "elf/common.h"
29 #include "elf/bfin.h"
30
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)
33
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)
37
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)
41
42 #define DSP32SHIFT(sopcde, dst0, src0, src1, sop, hls)  \
43         bfin_gen_dsp32shift (sopcde, dst0, src0, src1, sop, hls)
44
45 #define DSP32SHIFTIMM(sopcde, dst0, immag, src1, sop, hls)  \
46         bfin_gen_dsp32shiftimm (sopcde, dst0, immag, src1, sop, hls)
47
48 #define LDIMMHALF_R(reg, h, s, z, hword) \
49         bfin_gen_ldimmhalf (reg, h, s, z, hword, 1)
50
51 #define LDIMMHALF_R5(reg, h, s, z, hword) \
52         bfin_gen_ldimmhalf (reg, h, s, z, hword, 2)
53
54 #define LDSTIDXI(ptr, reg, w, sz, z, offset)  \
55         bfin_gen_ldstidxi (ptr, reg, w, sz, z, offset)
56
57 #define LDST(ptr, reg, aop, sz, z, w)  \
58         bfin_gen_ldst (ptr, reg, aop, sz, z, w)
59
60 #define LDSTII(ptr, reg, offset, w, op)  \
61         bfin_gen_ldstii (ptr, reg, offset, w, op)
62
63 #define DSPLDST(i, m, reg, aop, w) \
64         bfin_gen_dspldst (i, reg, aop, w, m)
65
66 #define LDSTPMOD(ptr, reg, idx, aop, w) \
67         bfin_gen_ldstpmod (ptr, reg, aop, w, idx)
68
69 #define LDSTIIFP(offset, reg, w)  \
70         bfin_gen_ldstiifp (reg, offset, w)
71
72 #define LOGI2OP(dst, src, opc) \
73         bfin_gen_logi2op (opc, src, dst.regno & CODE_MASK)
74
75 #define ALU2OP(dst, src, opc)  \
76         bfin_gen_alu2op (dst, src, opc)
77
78 #define BRCC(t, b, offset) \
79         bfin_gen_brcc (t, b, offset)
80
81 #define UJUMP(offset) \
82         bfin_gen_ujump (offset)
83
84 #define PROGCTRL(prgfunc, poprnd) \
85         bfin_gen_progctrl (prgfunc, poprnd)
86
87 #define PUSHPOPMULTIPLE(dr, pr, d, p, w) \
88         bfin_gen_pushpopmultiple (dr, pr, d, p, w)
89
90 #define PUSHPOPREG(reg, w) \
91         bfin_gen_pushpopreg (reg, w)
92
93 #define CALLA(addr, s)  \
94         bfin_gen_calla (addr, s)
95
96 #define LINKAGE(r, framesize) \
97         bfin_gen_linkage (r, framesize)
98
99 #define COMPI2OPD(dst, src, op)  \
100         bfin_gen_compi2opd (dst, src, op)
101
102 #define COMPI2OPP(dst, src, op)  \
103         bfin_gen_compi2opp (dst, src, op)
104
105 #define DAGMODIK(i, op)  \
106         bfin_gen_dagmodik (i, op)
107
108 #define DAGMODIM(i, m, op, br)  \
109         bfin_gen_dagmodim (i, m, op, br)
110
111 #define COMP3OP(dst, src0, src1, opc)   \
112         bfin_gen_comp3op (src0, src1, dst, opc)
113
114 #define PTR2OP(dst, src, opc)   \
115         bfin_gen_ptr2op (dst, src, opc)
116
117 #define CCFLAG(x, y, opc, i, g)  \
118         bfin_gen_ccflag (x, y, opc, i, g)
119
120 #define CCMV(src, dst, t) \
121         bfin_gen_ccmv (src, dst, t)
122
123 #define CACTRL(reg, a, op) \
124         bfin_gen_cactrl (reg, a, op)
125
126 #define LOOPSETUP(soffset, c, rop, eoffset, reg) \
127         bfin_gen_loopsetup (soffset, c, rop, eoffset, reg)
128
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)
138
139 #define IS_PCREL4(expr) \
140         (value_match (expr, 4, 0, 2, 0))
141
142 #define IS_LPPCREL10(expr) \
143         (value_match (expr, 10, 0, 2, 0))
144
145 #define IS_PCREL10(expr) \
146         (value_match (expr, 10, 0, 2, 1))
147
148 #define IS_PCREL12(expr) \
149         (value_match (expr, 12, 0, 2, 1))
150
151 #define IS_PCREL24(expr) \
152         (value_match (expr, 24, 0, 2, 1))
153
154
155 static int value_match (Expr_Node *, int, int, int, int);
156
157 extern FILE *errorf;
158 extern INSTR_T insn;
159
160 static Expr_Node *binary (Expr_Op_Type, Expr_Node *, Expr_Node *);
161 static Expr_Node *unary  (Expr_Op_Type, Expr_Node *);
162
163 static void notethat (char *, ...);
164
165 char *current_inputline;
166 extern char *yytext;
167 int yyerror (char *);
168
169 void error (char *format, ...)
170 {
171     va_list ap;
172     static char buffer[2000];
173
174     va_start (ap, format);
175     vsprintf (buffer, format, ap);
176     va_end (ap);
177
178     as_bad ("%s", buffer);
179 }
180
181 int
182 yyerror (char *msg)
183 {
184   if (msg[0] == '\0')
185     error ("%s", msg);
186
187   else if (yytext[0] != ';')
188     error ("%s. Input text was %s.", msg, yytext);
189   else
190     error ("%s.", msg);
191
192   return -1;
193 }
194
195 static int
196 in_range_p (Expr_Node *exp, int from, int to, unsigned int mask)
197 {
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;
204 }
205
206 extern int yylex (void);
207
208 #define imm3(x) EXPR_VALUE (x)
209 #define imm4(x) EXPR_VALUE (x)
210 #define uimm4(x) EXPR_VALUE (x)
211 #define imm5(x) EXPR_VALUE (x)
212 #define uimm5(x) EXPR_VALUE (x)
213 #define imm6(x) EXPR_VALUE (x)
214 #define imm7(x) EXPR_VALUE (x)
215 #define uimm8(x) EXPR_VALUE (x)
216 #define imm16(x) EXPR_VALUE (x)
217 #define uimm16s4(x) ((EXPR_VALUE (x)) >> 2)
218 #define uimm16(x) EXPR_VALUE (x)
219
220 /* Return true if a value is inside a range.  */
221 #define IN_RANGE(x, low, high) \
222   (((EXPR_VALUE(x)) >= (low)) && (EXPR_VALUE(x)) <= ((high)))
223
224 /* Auxiliary functions.  */
225
226 static int
227 valid_dreg_pair (Register *reg1, Expr_Node *reg2)
228 {
229   if (!IS_DREG (*reg1))
230     {
231       yyerror ("Dregs expected");
232       return 0;
233     }
234
235   if (reg1->regno != 1 && reg1->regno != 3)
236     {
237       yyerror ("Bad register pair");
238       return 0;
239     }
240
241   if (imm7 (reg2) != reg1->regno - 1)
242     {
243       yyerror ("Bad register pair");
244       return 0;
245     }
246
247   reg1->regno--;
248   return 1;
249 }
250
251 static int
252 check_multiply_halfregs (Macfunc *aa, Macfunc *ab)
253 {
254   if ((!REG_EQUAL (aa->s0, ab->s0) && !REG_EQUAL (aa->s0, ab->s1))
255       || (!REG_EQUAL (aa->s1, ab->s1) && !REG_EQUAL (aa->s1, ab->s0)))
256     return yyerror ("Source multiplication register mismatch");
257
258   return 0;
259 }
260
261
262 /* Check mac option.  */
263
264 static int
265 check_macfunc_option (Macfunc *a, Opt_mode *opt)
266 {
267   /* Default option is always valid.  */
268   if (opt->mod == 0)
269     return 0;
270
271   if ((a->w == 1 && a->P == 1
272        && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_IU
273        && opt->mod != M_S2RND && opt->mod != M_ISS2)
274       || (a->w == 1 && a->P == 0
275           && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_IU
276           && opt->mod != M_T && opt->mod != M_TFU && opt->mod != M_S2RND
277           && opt->mod != M_ISS2 && opt->mod != M_IH)
278       || (a->w == 0 && a->P == 0
279           && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_W32))
280     return -1;
281
282   return 0;
283 }
284
285 /* Check (vector) mac funcs and ops.  */
286
287 static int
288 check_macfuncs (Macfunc *aa, Opt_mode *opa,
289                 Macfunc *ab, Opt_mode *opb)
290 {
291   /* Variables for swapping.  */
292   Macfunc mtmp;
293   Opt_mode otmp;
294
295   /* The option mode should be put at the end of the second instruction
296      of the vector except M, which should follow MAC1 instruction.  */
297   if (opa->mod != 0)
298     return yyerror ("Bad opt mode");
299
300   /* If a0macfunc comes before a1macfunc, swap them.  */
301
302   if (aa->n == 0)
303     {
304       /*  (M) is not allowed here.  */
305       if (opa->MM != 0)
306         return yyerror ("(M) not allowed with A0MAC");
307       if (ab->n != 1)
308         return yyerror ("Vector AxMACs can't be same");
309
310       mtmp = *aa; *aa = *ab; *ab = mtmp;
311       otmp = *opa; *opa = *opb; *opb = otmp;
312     }
313   else
314     {
315       if (opb->MM != 0)
316         return yyerror ("(M) not allowed with A0MAC");
317       if (ab->n != 0)
318         return yyerror ("Vector AxMACs can't be same");
319     }
320
321   /*  If both ops are one of 0, 1, or 2, we have multiply_halfregs in both
322   assignment_or_macfuncs.  */
323   if ((aa->op == 0 || aa->op == 1 || aa->op == 2)
324       && (ab->op == 0 || ab->op == 1 || ab->op == 2))
325     {
326       if (check_multiply_halfregs (aa, ab) < 0)
327         return -1;
328     }
329   else
330     {
331       /*  Only one of the assign_macfuncs has a half reg multiply
332       Evil trick: Just 'OR' their source register codes:
333       We can do that, because we know they were initialized to 0
334       in the rules that don't use multiply_halfregs.  */
335       aa->s0.regno |= (ab->s0.regno & CODE_MASK);
336       aa->s1.regno |= (ab->s1.regno & CODE_MASK);
337     }
338
339   if (aa->w == ab->w && aa->P != ab->P)
340     return yyerror ("Destination Dreg sizes (full or half) must match");
341
342   if (aa->w && ab->w)
343     {
344       if (aa->P && (aa->dst.regno - ab->dst.regno) != 1)
345         return yyerror ("Destination Dregs (full) must differ by one");
346       if (!aa->P && aa->dst.regno != ab->dst.regno)
347         return yyerror ("Destination Dregs (half) must match");
348     }
349
350   /* Make sure mod flags get ORed, too.  */
351   opb->mod |= opa->mod;
352
353   /* Check option.  */
354   if (check_macfunc_option (aa, opb) < 0
355       && check_macfunc_option (ab, opb) < 0)
356     return yyerror ("bad option");
357
358   /* Make sure first macfunc has got both P flags ORed.  */
359   aa->P |= ab->P;
360
361   return 0;
362 }
363
364
365 static int
366 is_group1 (INSTR_T x)
367 {
368   /* Group1 is dpsLDST, LDSTpmod, LDST, LDSTiiFP, LDSTii.  */
369   if ((x->value & 0xc000) == 0x8000 || (x->value == 0x0000))
370     return 1;
371
372   return 0;
373 }
374
375 static int
376 is_group2 (INSTR_T x)
377 {
378   if ((((x->value & 0xfc00) == 0x9c00)  /* dspLDST.  */
379        && !((x->value & 0xfde0) == 0x9c60)  /* dagMODim.  */
380        && !((x->value & 0xfde0) == 0x9ce0)  /* dagMODim with bit rev.  */
381        && !((x->value & 0xfde0) == 0x9d60)) /* pick dagMODik.  */
382       || (x->value == 0x0000))
383     return 1;
384   return 0;
385 }
386
387 static int
388 is_store (INSTR_T x)
389 {
390   if (!x)
391     return 0;
392
393   if ((x->value & 0xf000) == 0x8000)
394     {
395       int aop = ((x->value >> 9) & 0x3);
396       int w = ((x->value >> 11) & 0x1);
397       if (!w || aop == 3)
398         return 0;
399       return 1;
400     }
401
402   if (((x->value & 0xFF60) == 0x9E60) ||  /* dagMODim_0 */
403       ((x->value & 0xFFF0) == 0x9F60))    /* dagMODik_0 */
404     return 0;
405
406   /* decode_dspLDST_0 */
407   if ((x->value & 0xFC00) == 0x9C00)
408     {
409       int w = ((x->value >> 9) & 0x1);
410       if (w)
411         return 1;
412     }
413
414   return 0;
415 }
416
417 static INSTR_T
418 gen_multi_instr_1 (INSTR_T dsp32, INSTR_T dsp16_grp1, INSTR_T dsp16_grp2)
419 {
420   int mask1 = dsp32 ? insn_regmask (dsp32->value, dsp32->next->value) : 0;
421   int mask2 = dsp16_grp1 ? insn_regmask (dsp16_grp1->value, 0) : 0;
422   int mask3 = dsp16_grp2 ? insn_regmask (dsp16_grp2->value, 0) : 0;
423
424   if ((mask1 & mask2) || (mask1 & mask3) || (mask2 & mask3))
425     yyerror ("resource conflict in multi-issue instruction");
426
427   /* Anomaly 05000074 */
428   if (ENABLE_AC_05000074
429       && dsp32 != NULL && dsp16_grp1 != NULL
430       && (dsp32->value & 0xf780) == 0xc680
431       && ((dsp16_grp1->value & 0xfe40) == 0x9240
432           || (dsp16_grp1->value & 0xfe08) == 0xba08
433           || (dsp16_grp1->value & 0xfc00) == 0xbc00))
434     yyerror ("anomaly 05000074 - Multi-Issue Instruction with \
435 dsp32shiftimm in slot1 and P-reg Store in slot2 Not Supported");
436
437   if (is_store (dsp16_grp1) && is_store (dsp16_grp2))
438     yyerror ("Only one instruction in multi-issue instruction can be a store");
439
440   return bfin_gen_multi_instr (dsp32, dsp16_grp1, dsp16_grp2);
441 }
442
443 %}
444
445 %union {
446   INSTR_T instr;
447   Expr_Node *expr;
448   SYMBOL_T symbol;
449   long value;
450   Register reg;
451   Macfunc macfunc;
452   struct { int r0; int s0; int x0; int aop; } modcodes;
453   struct { int r0; } r0;
454   Opt_mode mod;
455 }
456
457
458 /* Tokens.  */
459
460 /* Vector Specific.  */
461 %token BYTEOP16P BYTEOP16M
462 %token BYTEOP1P BYTEOP2P BYTEOP3P
463 %token BYTEUNPACK BYTEPACK
464 %token PACK
465 %token SAA
466 %token ALIGN8 ALIGN16 ALIGN24
467 %token VIT_MAX
468 %token EXTRACT DEPOSIT EXPADJ SEARCH
469 %token ONES SIGN SIGNBITS
470
471 /* Stack.  */
472 %token LINK UNLINK
473
474 /* Registers.  */
475 %token REG
476 %token PC
477 %token CCREG BYTE_DREG
478 %token REG_A_DOUBLE_ZERO REG_A_DOUBLE_ONE
479 %token A_ZERO_DOT_L A_ZERO_DOT_H A_ONE_DOT_L A_ONE_DOT_H
480 %token HALF_REG
481
482 /* Progctrl.  */
483 %token NOP
484 %token RTI RTS RTX RTN RTE
485 %token HLT IDLE
486 %token STI CLI
487 %token CSYNC SSYNC
488 %token EMUEXCPT
489 %token RAISE EXCPT
490 %token LSETUP
491 %token LOOP
492 %token LOOP_BEGIN
493 %token LOOP_END
494 %token DISALGNEXCPT
495 %token JUMP JUMP_DOT_S JUMP_DOT_L
496 %token CALL
497
498 /* Emulator only.  */
499 %token ABORT
500
501 /* Operators.  */
502 %token NOT TILDA BANG
503 %token AMPERSAND BAR
504 %token PERCENT
505 %token CARET
506 %token BXOR
507
508 %token MINUS PLUS STAR SLASH
509 %token NEG
510 %token MIN MAX ABS
511 %token DOUBLE_BAR
512 %token _PLUS_BAR_PLUS _PLUS_BAR_MINUS _MINUS_BAR_PLUS _MINUS_BAR_MINUS
513 %token _MINUS_MINUS _PLUS_PLUS
514
515 /* Shift/rotate ops.  */
516 %token SHIFT LSHIFT ASHIFT BXORSHIFT
517 %token _GREATER_GREATER_GREATER_THAN_ASSIGN
518 %token ROT
519 %token LESS_LESS GREATER_GREATER
520 %token _GREATER_GREATER_GREATER
521 %token _LESS_LESS_ASSIGN _GREATER_GREATER_ASSIGN
522 %token DIVS DIVQ
523
524 /* In place operators.  */
525 %token ASSIGN _STAR_ASSIGN
526 %token _BAR_ASSIGN _CARET_ASSIGN _AMPERSAND_ASSIGN
527 %token _MINUS_ASSIGN _PLUS_ASSIGN
528
529 /* Assignments, comparisons.  */
530 %token _ASSIGN_BANG _LESS_THAN_ASSIGN _ASSIGN_ASSIGN
531 %token GE LT LE GT
532 %token LESS_THAN
533
534 /* Cache.  */
535 %token FLUSHINV FLUSH
536 %token IFLUSH PREFETCH
537
538 /* Misc.  */
539 %token PRNT
540 %token OUTC
541 %token WHATREG
542 %token TESTSET
543
544 /* Modifiers.  */
545 %token ASL ASR
546 %token B W
547 %token NS S CO SCO
548 %token TH TL
549 %token BP
550 %token BREV
551 %token X Z
552 %token M MMOD
553 %token R RND RNDL RNDH RND12 RND20
554 %token V
555 %token LO HI
556
557 /* Bit ops.  */
558 %token BITTGL BITCLR BITSET BITTST BITMUX
559
560 /* Debug.  */
561 %token DBGAL DBGAH DBGHALT DBG DBGA DBGCMPLX
562
563 /* Semantic auxiliaries.  */
564
565 %token IF COMMA BY
566 %token COLON SEMICOLON
567 %token RPAREN LPAREN LBRACK RBRACK
568 %token STATUS_REG
569 %token MNOP
570 %token SYMBOL NUMBER
571 %token GOT GOT17M4 FUNCDESC_GOT17M4
572 %token AT PLTPC
573
574 /* Types.  */
575 %type <instr> asm
576 %type <value> MMOD
577 %type <mod> opt_mode
578
579 %type <value> NUMBER
580 %type <r0> aligndir
581 %type <modcodes> byteop_mod
582 %type <reg> a_assign
583 %type <reg> a_plusassign
584 %type <reg> a_minusassign
585 %type <macfunc> multiply_halfregs
586 %type <macfunc> assign_macfunc
587 %type <macfunc> a_macfunc
588 %type <expr> expr_1
589 %type <instr> asm_1
590 %type <r0> vmod
591 %type <modcodes> vsmod
592 %type <modcodes> ccstat
593 %type <r0> cc_op
594 %type <reg> CCREG
595 %type <reg> reg_with_postinc
596 %type <reg> reg_with_predec
597
598 %type <r0> searchmod
599 %type <expr> symbol
600 %type <symbol> SYMBOL
601 %type <expr> eterm
602 %type <reg> REG
603 %type <reg> BYTE_DREG
604 %type <reg> REG_A_DOUBLE_ZERO
605 %type <reg> REG_A_DOUBLE_ONE
606 %type <reg> REG_A
607 %type <reg> STATUS_REG
608 %type <expr> expr
609 %type <r0> xpmod
610 %type <r0> xpmod1
611 %type <modcodes> smod
612 %type <modcodes> b3_op
613 %type <modcodes> rnd_op
614 %type <modcodes> post_op
615 %type <reg> HALF_REG
616 %type <r0> iu_or_nothing
617 %type <r0> plus_minus
618 %type <r0> asr_asl
619 %type <r0> asr_asl_0
620 %type <modcodes> sco
621 %type <modcodes> amod0
622 %type <modcodes> amod1
623 %type <modcodes> amod2
624 %type <r0> op_bar_op
625 %type <r0> w32_or_nothing
626 %type <r0> c_align
627 %type <r0> min_max
628 %type <expr> got
629 %type <expr> got_or_expr
630 %type <expr> pltpc
631 %type <value> any_gotrel GOT GOT17M4 FUNCDESC_GOT17M4
632
633 /* Precedence rules.  */
634 %left BAR
635 %left CARET
636 %left AMPERSAND
637 %left LESS_LESS GREATER_GREATER
638 %left PLUS MINUS
639 %left STAR SLASH PERCENT
640
641 %right ASSIGN
642
643 %right TILDA BANG
644 %start statement
645 %%
646 statement:
647         | asm
648         {
649           insn = $1;
650           if (insn == (INSTR_T) 0)
651             return NO_INSN_GENERATED;
652           else if (insn == (INSTR_T) - 1)
653             return SEMANTIC_ERROR;
654           else
655             return INSN_GENERATED;
656         }
657         ;
658
659 asm: asm_1 SEMICOLON
660         /* Parallel instructions.  */
661         | asm_1 DOUBLE_BAR asm_1 DOUBLE_BAR asm_1 SEMICOLON
662         {
663           if (($1->value & 0xf800) == 0xc000)
664             {
665               if (is_group1 ($3) && is_group2 ($5))
666                 $$ = gen_multi_instr_1 ($1, $3, $5);
667               else if (is_group2 ($3) && is_group1 ($5))
668                 $$ = gen_multi_instr_1 ($1, $5, $3);
669               else
670                 return yyerror ("Wrong 16 bit instructions groups, slot 2 and slot 3 must be 16-bit instrution group");
671             }
672           else if (($3->value & 0xf800) == 0xc000)
673             {
674               if (is_group1 ($1) && is_group2 ($5))
675                 $$ = gen_multi_instr_1 ($3, $1, $5);
676               else if (is_group2 ($1) && is_group1 ($5))
677                 $$ = gen_multi_instr_1 ($3, $5, $1);
678               else
679                 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 3 must be 16-bit instrution group");
680             }
681           else if (($5->value & 0xf800) == 0xc000)
682             {
683               if (is_group1 ($1) && is_group2 ($3))
684                 $$ = gen_multi_instr_1 ($5, $1, $3);
685               else if (is_group2 ($1) && is_group1 ($3))
686                 $$ = gen_multi_instr_1 ($5, $3, $1);
687               else
688                 return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be 16-bit instrution group");
689             }
690           else
691             error ("\nIllegal Multi Issue Construct, at least any one of the slot must be DSP32 instruction group\n");
692         }
693
694         | asm_1 DOUBLE_BAR asm_1 SEMICOLON
695         {
696           if (($1->value & 0xf800) == 0xc000)
697             {
698               if (is_group1 ($3))
699                 $$ = gen_multi_instr_1 ($1, $3, 0);
700               else if (is_group2 ($3))
701                 $$ = gen_multi_instr_1 ($1, 0, $3);
702               else
703                 return yyerror ("Wrong 16 bit instructions groups, slot 2 must be the 16-bit instruction group");
704             }
705           else if (($3->value & 0xf800) == 0xc000)
706             {
707               if (is_group1 ($1))
708                 $$ = gen_multi_instr_1 ($3, $1, 0);
709               else if (is_group2 ($1))
710                 $$ = gen_multi_instr_1 ($3, 0, $1);
711               else
712                 return yyerror ("Wrong 16 bit instructions groups, slot 1 must be the 16-bit instruction group");
713             }
714           else if (is_group1 ($1) && is_group2 ($3))
715               $$ = gen_multi_instr_1 (0, $1, $3);
716           else if (is_group2 ($1) && is_group1 ($3))
717             $$ = gen_multi_instr_1 (0, $3, $1);
718           else
719             return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be the 16-bit instruction group");
720         }
721         | error
722         {
723         $$ = 0;
724         yyerror ("");
725         yyerrok;
726         }
727         ;
728
729 /* DSPMAC.  */
730
731 asm_1:
732         MNOP
733         {
734           $$ = DSP32MAC (3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
735         }
736         | assign_macfunc opt_mode
737         {
738           int op0, op1;
739           int w0 = 0, w1 = 0;
740           int h00, h10, h01, h11;
741
742           if (check_macfunc_option (&$1, &$2) < 0)
743             return yyerror ("bad option");
744
745           if ($1.n == 0)
746             {
747               if ($2.MM)
748                 return yyerror ("(m) not allowed with a0 unit");
749               op1 = 3;
750               op0 = $1.op;
751               w1 = 0;
752               w0 = $1.w;
753               h00 = IS_H ($1.s0);
754               h10 = IS_H ($1.s1);
755               h01 = h11 = 0;
756             }
757           else
758             {
759               op1 = $1.op;
760               op0 = 3;
761               w1 = $1.w;
762               w0 = 0;
763               h00 = h10 = 0;
764               h01 = IS_H ($1.s0);
765               h11 = IS_H ($1.s1);
766             }
767           $$ = DSP32MAC (op1, $2.MM, $2.mod, w1, $1.P, h01, h11, h00, h10,
768                          &$1.dst, op0, &$1.s0, &$1.s1, w0);
769         }
770
771
772 /* VECTOR MACs.  */
773
774         | assign_macfunc opt_mode COMMA assign_macfunc opt_mode
775         {
776           Register *dst;
777
778           if (check_macfuncs (&$1, &$2, &$4, &$5) < 0)
779             return -1;
780           notethat ("assign_macfunc (.), assign_macfunc (.)\n");
781
782           if ($1.w)
783             dst = &$1.dst;
784           else
785             dst = &$4.dst;
786
787           $$ = DSP32MAC ($1.op, $2.MM, $5.mod, $1.w, $1.P,
788                          IS_H ($1.s0),  IS_H ($1.s1), IS_H ($4.s0), IS_H ($4.s1),
789                          dst, $4.op, &$1.s0, &$1.s1, $4.w);
790         }
791
792 /* DSPALU.  */
793
794         | DISALGNEXCPT
795         {
796           notethat ("dsp32alu: DISALGNEXCPT\n");
797           $$ = DSP32ALU (18, 0, 0, 0, 0, 0, 0, 0, 3);
798         }
799         | REG ASSIGN LPAREN a_plusassign REG_A RPAREN
800         {
801           if (IS_DREG ($1) && !IS_A1 ($4) && IS_A1 ($5))
802             {
803               notethat ("dsp32alu: dregs = ( A0 += A1 )\n");
804               $$ = DSP32ALU (11, 0, 0, &$1, 0, 0, 0, 0, 0);
805             }
806           else
807             return yyerror ("Register mismatch");
808         }
809         | HALF_REG ASSIGN LPAREN a_plusassign REG_A RPAREN
810         {
811           if (!IS_A1 ($4) && IS_A1 ($5))
812             {
813               notethat ("dsp32alu: dregs_half = ( A0 += A1 )\n");
814               $$ = DSP32ALU (11, IS_H ($1), 0, &$1, 0, 0, 0, 0, 1);
815             }
816           else
817             return yyerror ("Register mismatch");
818         }
819         | A_ZERO_DOT_H ASSIGN HALF_REG
820         {
821           notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
822           $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
823         }
824         | A_ONE_DOT_H ASSIGN HALF_REG
825         {
826           notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
827           $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
828         }
829         | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16P LPAREN REG
830           COLON expr COMMA REG COLON expr RPAREN aligndir
831         {
832           if (!IS_DREG ($2) || !IS_DREG ($4))
833             return yyerror ("Dregs expected");
834           else if (!valid_dreg_pair (&$9, $11))
835             return yyerror ("Bad dreg pair");
836           else if (!valid_dreg_pair (&$13, $15))
837             return yyerror ("Bad dreg pair");
838           else
839             {
840               notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16P (dregs_pair , dregs_pair ) (aligndir)\n");
841               $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 0);
842             }
843         }
844
845         | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16M LPAREN REG COLON expr COMMA
846           REG COLON expr RPAREN aligndir
847         {
848           if (!IS_DREG ($2) || !IS_DREG ($4))
849             return yyerror ("Dregs expected");
850           else if (!valid_dreg_pair (&$9, $11))
851             return yyerror ("Bad dreg pair");
852           else if (!valid_dreg_pair (&$13, $15))
853             return yyerror ("Bad dreg pair");
854           else
855             {
856               notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16M (dregs_pair , dregs_pair ) (aligndir)\n");
857               $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 1);
858             }
859         }
860
861         | LPAREN REG COMMA REG RPAREN ASSIGN BYTEUNPACK REG COLON expr aligndir
862         {
863           if (!IS_DREG ($2) || !IS_DREG ($4))
864             return yyerror ("Dregs expected");
865           else if (!valid_dreg_pair (&$8, $10))
866             return yyerror ("Bad dreg pair");
867           else
868             {
869               notethat ("dsp32alu: (dregs , dregs ) = BYTEUNPACK dregs_pair (aligndir)\n");
870               $$ = DSP32ALU (24, 0, &$2, &$4, &$8, 0, $11.r0, 0, 1);
871             }
872         }
873         | LPAREN REG COMMA REG RPAREN ASSIGN SEARCH REG LPAREN searchmod RPAREN
874         {
875           if (REG_SAME ($2, $4))
876             return yyerror ("Illegal dest register combination");
877
878           if (IS_DREG ($2) && IS_DREG ($4) && IS_DREG ($8))
879             {
880               notethat ("dsp32alu: (dregs , dregs ) = SEARCH dregs (searchmod)\n");
881               $$ = DSP32ALU (13, 0, &$2, &$4, &$8, 0, 0, 0, $10.r0);
882             }
883           else
884             return yyerror ("Register mismatch");
885         }
886         | REG ASSIGN A_ONE_DOT_L PLUS A_ONE_DOT_H COMMA
887           REG ASSIGN A_ZERO_DOT_L PLUS A_ZERO_DOT_H
888         {
889           if (REG_SAME ($1, $7))
890             return yyerror ("Illegal dest register combination");
891
892           if (IS_DREG ($1) && IS_DREG ($7))
893             {
894               notethat ("dsp32alu: dregs = A1.l + A1.h, dregs = A0.l + A0.h  \n");
895               $$ = DSP32ALU (12, 0, &$1, &$7, 0, 0, 0, 0, 1);
896             }
897           else
898             return yyerror ("Register mismatch");
899         }
900
901
902         | REG ASSIGN REG_A PLUS REG_A COMMA REG ASSIGN REG_A MINUS REG_A amod1
903         {
904           if (REG_SAME ($1, $7))
905             return yyerror ("Resource conflict in dest reg");
906
907           if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
908               && IS_A1 ($9) && !IS_A1 ($11))
909             {
910               notethat ("dsp32alu: dregs = A1 + A0 , dregs = A1 - A0 (amod1)\n");
911               $$ = DSP32ALU (17, 0, &$1, &$7, 0, 0, $12.s0, $12.x0, 0);
912
913             }
914           else if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
915                    && !IS_A1 ($9) && IS_A1 ($11))
916             {
917               notethat ("dsp32alu: dregs = A0 + A1 , dregs = A0 - A1 (amod1)\n");
918               $$ = DSP32ALU (17, 0, &$1, &$7, 0, 0, $12.s0, $12.x0, 1);
919             }
920           else
921             return yyerror ("Register mismatch");
922         }
923
924         | REG ASSIGN REG plus_minus REG COMMA REG ASSIGN REG plus_minus REG amod1
925         {
926           if ($4.r0 == $10.r0)
927             return yyerror ("Operators must differ");
928
929           if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5)
930               && REG_SAME ($3, $9) && REG_SAME ($5, $11))
931             {
932               notethat ("dsp32alu: dregs = dregs + dregs,"
933                        "dregs = dregs - dregs (amod1)\n");
934               $$ = DSP32ALU (4, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, 2);
935             }
936           else
937             return yyerror ("Register mismatch");
938         }
939
940 /*  Bar Operations.  */
941
942         | REG ASSIGN REG op_bar_op REG COMMA REG ASSIGN REG op_bar_op REG amod2
943         {
944           if (!REG_SAME ($3, $9) || !REG_SAME ($5, $11))
945             return yyerror ("Differing source registers");
946
947           if (!IS_DREG ($1) || !IS_DREG ($3) || !IS_DREG ($5) || !IS_DREG ($7))
948             return yyerror ("Dregs expected");
949
950           if (REG_SAME ($1, $7))
951             return yyerror ("Resource conflict in dest reg");
952
953           if ($4.r0 == 1 && $10.r0 == 2)
954             {
955               notethat ("dsp32alu:  dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
956               $$ = DSP32ALU (1, 1, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
957             }
958           else if ($4.r0 == 0 && $10.r0 == 3)
959             {
960               notethat ("dsp32alu:  dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
961               $$ = DSP32ALU (1, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
962             }
963           else
964             return yyerror ("Bar operand mismatch");
965         }
966
967         | REG ASSIGN ABS REG vmod
968         {
969           int op;
970
971           if (IS_DREG ($1) && IS_DREG ($4))
972             {
973               if ($5.r0)
974                 {
975                   notethat ("dsp32alu: dregs = ABS dregs (v)\n");
976                   op = 6;
977                 }
978               else
979                 {
980                   /* Vector version of ABS.  */
981                   notethat ("dsp32alu: dregs = ABS dregs\n");
982                   op = 7;
983                 }
984               $$ = DSP32ALU (op, 0, 0, &$1, &$4, 0, 0, 0, 2);
985             }
986           else
987             return yyerror ("Dregs expected");
988         }
989         | a_assign ABS REG_A
990         {
991           notethat ("dsp32alu: Ax = ABS Ax\n");
992           $$ = DSP32ALU (16, IS_A1 ($1), 0, 0, 0, 0, 0, 0, IS_A1 ($3));
993         }
994         | A_ZERO_DOT_L ASSIGN HALF_REG
995         {
996           if (IS_DREG_L ($3))
997             {
998               notethat ("dsp32alu: A0.l = reg_half\n");
999               $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
1000             }
1001           else
1002             return yyerror ("A0.l = Rx.l expected");
1003         }
1004         | A_ONE_DOT_L ASSIGN HALF_REG
1005         {
1006           if (IS_DREG_L ($3))
1007             {
1008               notethat ("dsp32alu: A1.l = reg_half\n");
1009               $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
1010             }
1011           else
1012             return yyerror ("A1.l = Rx.l expected");
1013         }
1014
1015         | REG ASSIGN c_align LPAREN REG COMMA REG RPAREN
1016         {
1017           if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1018             {
1019               notethat ("dsp32shift: dregs = ALIGN8 (dregs , dregs )\n");
1020               $$ = DSP32SHIFT (13, &$1, &$7, &$5, $3.r0, 0);
1021             }
1022           else
1023             return yyerror ("Dregs expected");
1024         }
1025
1026         | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN byteop_mod
1027         {
1028           if (!IS_DREG ($1))
1029             return yyerror ("Dregs expected");
1030           else if (!valid_dreg_pair (&$5, $7))
1031             return yyerror ("Bad dreg pair");
1032           else if (!valid_dreg_pair (&$9, $11))
1033             return yyerror ("Bad dreg pair");
1034           else
1035             {
1036               notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
1037               $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, $13.s0, 0, $13.r0);
1038             }
1039         }
1040         | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1041         {
1042           if (!IS_DREG ($1))
1043             return yyerror ("Dregs expected");
1044           else if (!valid_dreg_pair (&$5, $7))
1045             return yyerror ("Bad dreg pair");
1046           else if (!valid_dreg_pair (&$9, $11))
1047             return yyerror ("Bad dreg pair");
1048           else
1049             {
1050               notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
1051               $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, 0, 0, 0);
1052             }
1053         }
1054
1055         | REG ASSIGN BYTEOP2P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1056           rnd_op
1057         {
1058           if (!IS_DREG ($1))
1059             return yyerror ("Dregs expected");
1060           else if (!valid_dreg_pair (&$5, $7))
1061             return yyerror ("Bad dreg pair");
1062           else if (!valid_dreg_pair (&$9, $11))
1063             return yyerror ("Bad dreg pair");
1064           else
1065             {
1066               notethat ("dsp32alu: dregs = BYTEOP2P (dregs_pair , dregs_pair ) (rnd_op)\n");
1067               $$ = DSP32ALU (22, $13.r0, 0, &$1, &$5, &$9, $13.s0, $13.x0, $13.aop);
1068             }
1069         }
1070
1071         | REG ASSIGN BYTEOP3P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
1072           b3_op
1073         {
1074           if (!IS_DREG ($1))
1075             return yyerror ("Dregs expected");
1076           else if (!valid_dreg_pair (&$5, $7))
1077             return yyerror ("Bad dreg pair");
1078           else if (!valid_dreg_pair (&$9, $11))
1079             return yyerror ("Bad dreg pair");
1080           else
1081             {
1082               notethat ("dsp32alu: dregs = BYTEOP3P (dregs_pair , dregs_pair ) (b3_op)\n");
1083               $$ = DSP32ALU (23, $13.x0, 0, &$1, &$5, &$9, $13.s0, 0, 0);
1084             }
1085         }
1086
1087         | REG ASSIGN BYTEPACK LPAREN REG COMMA REG RPAREN
1088         {
1089           if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1090             {
1091               notethat ("dsp32alu: dregs = BYTEPACK (dregs , dregs )\n");
1092               $$ = DSP32ALU (24, 0, 0, &$1, &$5, &$7, 0, 0, 0);
1093             }
1094           else
1095             return yyerror ("Dregs expected");
1096         }
1097
1098         | HALF_REG ASSIGN HALF_REG ASSIGN SIGN LPAREN HALF_REG RPAREN STAR
1099           HALF_REG PLUS SIGN LPAREN HALF_REG RPAREN STAR HALF_REG
1100         {
1101           if (IS_HCOMPL ($1, $3) && IS_HCOMPL ($7, $14) && IS_HCOMPL ($10, $17))
1102             {
1103               notethat ("dsp32alu:      dregs_hi = dregs_lo ="
1104                        "SIGN (dregs_hi) * dregs_hi + "
1105                        "SIGN (dregs_lo) * dregs_lo \n");
1106
1107                 $$ = DSP32ALU (12, 0, 0, &$1, &$7, &$10, 0, 0, 0);
1108             }
1109           else
1110             return yyerror ("Dregs expected");
1111         }
1112         | REG ASSIGN REG plus_minus REG amod1
1113         {
1114           if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1115             {
1116               if ($6.aop == 0)
1117                 {
1118                   /* No saturation flag specified, generate the 16 bit variant.  */
1119                   notethat ("COMP3op: dregs = dregs +- dregs\n");
1120                   $$ = COMP3OP (&$1, &$3, &$5, $4.r0);
1121                 }
1122               else
1123                 {
1124                  /* Saturation flag specified, generate the 32 bit variant.  */
1125                  notethat ("dsp32alu: dregs = dregs +- dregs (amod1)\n");
1126                  $$ = DSP32ALU (4, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
1127                 }
1128             }
1129           else
1130             if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($5) && $4.r0 == 0)
1131               {
1132                 notethat ("COMP3op: pregs = pregs + pregs\n");
1133                 $$ = COMP3OP (&$1, &$3, &$5, 5);
1134               }
1135             else
1136               return yyerror ("Dregs expected");
1137         }
1138         | REG ASSIGN min_max LPAREN REG COMMA REG RPAREN vmod
1139         {
1140           int op;
1141
1142           if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
1143             {
1144               if ($9.r0)
1145                 op = 6;
1146               else
1147                 op = 7;
1148
1149               notethat ("dsp32alu: dregs = {MIN|MAX} (dregs, dregs)\n");
1150               $$ = DSP32ALU (op, 0, 0, &$1, &$5, &$7, 0, 0, $3.r0);
1151             }
1152           else
1153             return yyerror ("Dregs expected");
1154         }
1155
1156         | a_assign MINUS REG_A
1157         {
1158           notethat ("dsp32alu: Ax = - Ax\n");
1159           $$ = DSP32ALU (14, IS_A1 ($1), 0, 0, 0, 0, 0, 0, IS_A1 ($3));
1160         }
1161         | HALF_REG ASSIGN HALF_REG plus_minus HALF_REG amod1
1162         {
1163           notethat ("dsp32alu: dregs_lo = dregs_lo +- dregs_lo (amod1)\n");
1164           $$ = DSP32ALU (2 | $4.r0, IS_H ($1), 0, &$1, &$3, &$5,
1165                          $6.s0, $6.x0, HL2 ($3, $5));
1166         }
1167         | a_assign a_assign expr
1168         {
1169           if (EXPR_VALUE ($3) == 0 && !REG_SAME ($1, $2))
1170             {
1171               notethat ("dsp32alu: A1 = A0 = 0\n");
1172               $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, 2);
1173             }
1174           else
1175             return yyerror ("Bad value, 0 expected");
1176         }
1177
1178         /* Saturating.  */
1179         | a_assign REG_A LPAREN S RPAREN
1180         {
1181           if (REG_SAME ($1, $2))
1182             {
1183               notethat ("dsp32alu: Ax = Ax (S)\n");
1184               $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 1, 0, IS_A1 ($1));
1185             }
1186           else
1187             return yyerror ("Registers must be equal");
1188         }
1189
1190         | HALF_REG ASSIGN REG LPAREN RND RPAREN
1191         {
1192           if (IS_DREG ($3))
1193             {
1194               notethat ("dsp32alu: dregs_half = dregs (RND)\n");
1195               $$ = DSP32ALU (12, IS_H ($1), 0, &$1, &$3, 0, 0, 0, 3);
1196             }
1197           else
1198             return yyerror ("Dregs expected");
1199         }
1200
1201         | HALF_REG ASSIGN REG plus_minus REG LPAREN RND12 RPAREN
1202         {
1203           if (IS_DREG ($3) && IS_DREG ($5))
1204             {
1205               notethat ("dsp32alu: dregs_half = dregs (+-) dregs (RND12)\n");
1206               $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 0, $4.r0);
1207             }
1208           else
1209             return yyerror ("Dregs expected");
1210         }
1211
1212         | HALF_REG ASSIGN REG plus_minus REG LPAREN RND20 RPAREN
1213         {
1214           if (IS_DREG ($3) && IS_DREG ($5))
1215             {
1216               notethat ("dsp32alu: dregs_half = dregs -+ dregs (RND20)\n");
1217               $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 1, $4.r0 | 2);
1218             }
1219           else
1220             return yyerror ("Dregs expected");
1221         }
1222
1223         | a_assign REG_A
1224         {
1225           if (!REG_SAME ($1, $2))
1226             {
1227               notethat ("dsp32alu: An = Am\n");
1228               $$ = DSP32ALU (8, 0, 0, 0, 0, 0, IS_A1 ($1), 0, 3);
1229             }
1230           else
1231             return yyerror ("Accu reg arguments must differ");
1232         }
1233
1234         | a_assign REG
1235         {
1236           if (IS_DREG ($2))
1237             {
1238               notethat ("dsp32alu: An = dregs\n");
1239               $$ = DSP32ALU (9, 0, 0, 0, &$2, 0, 1, 0, IS_A1 ($1) << 1);
1240             }
1241           else
1242             return yyerror ("Dregs expected");
1243         }
1244
1245         | REG ASSIGN HALF_REG xpmod
1246         {
1247           if (!IS_H ($3))
1248             {
1249               if ($1.regno == REG_A0x && IS_DREG ($3))
1250                 {
1251                   notethat ("dsp32alu: A0.x = dregs_lo\n");
1252                   $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 1);
1253                 }
1254               else if ($1.regno == REG_A1x && IS_DREG ($3))
1255                 {
1256                   notethat ("dsp32alu: A1.x = dregs_lo\n");
1257                   $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 3);
1258                 }
1259               else if (IS_DREG ($1) && IS_DREG ($3))
1260                 {
1261                   notethat ("ALU2op: dregs = dregs_lo\n");
1262                   $$ = ALU2OP (&$1, &$3, 10 | ($4.r0 ? 0: 1));
1263                 }
1264               else
1265                 return yyerror ("Register mismatch");
1266             }
1267           else
1268             return yyerror ("Low reg expected");
1269         }
1270
1271         | HALF_REG ASSIGN expr
1272         {
1273           notethat ("LDIMMhalf: pregs_half = imm16\n");
1274
1275           if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
1276               && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
1277             return yyerror ("Wrong register for load immediate");
1278
1279           if (!IS_IMM ($3, 16) && !IS_UIMM ($3, 16))
1280             return yyerror ("Constant out of range");
1281
1282           $$ = LDIMMHALF_R (&$1, IS_H ($1), 0, 0, $3);
1283         }
1284
1285         | a_assign expr
1286         {
1287           notethat ("dsp32alu: An = 0\n");
1288
1289           if (imm7 ($2) != 0)
1290             return yyerror ("0 expected");
1291
1292           $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, IS_A1 ($1));
1293         }
1294
1295         | REG ASSIGN expr xpmod1
1296         {
1297           if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
1298               && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
1299             return yyerror ("Wrong register for load immediate");
1300
1301           if ($4.r0 == 0)
1302             {
1303               /* 7 bit immediate value if possible.
1304                  We will check for that constant value for efficiency
1305                  If it goes to reloc, it will be 16 bit.  */
1306               if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_DREG ($1))
1307                 {
1308                   notethat ("COMPI2opD: dregs = imm7 (x) \n");
1309                   $$ = COMPI2OPD (&$1, imm7 ($3), 0);
1310                 }
1311               else if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_PREG ($1))
1312                 {
1313                   notethat ("COMPI2opP: pregs = imm7 (x)\n");
1314                   $$ = COMPI2OPP (&$1, imm7 ($3), 0);
1315                 }
1316               else
1317                 {
1318                   if (IS_CONST ($3) && !IS_IMM ($3, 16))
1319                     return yyerror ("Immediate value out of range");
1320
1321                   notethat ("LDIMMhalf: regs = luimm16 (x)\n");
1322                   /* reg, H, S, Z.   */
1323                   $$ = LDIMMHALF_R5 (&$1, 0, 1, 0, $3);
1324                 }
1325             }
1326           else
1327             {
1328               /* (z) There is no 7 bit zero extended instruction.
1329               If the expr is a relocation, generate it.   */
1330
1331               if (IS_CONST ($3) && !IS_UIMM ($3, 16))
1332                 return yyerror ("Immediate value out of range");
1333
1334               notethat ("LDIMMhalf: regs = luimm16 (x)\n");
1335               /* reg, H, S, Z.  */
1336               $$ = LDIMMHALF_R5 (&$1, 0, 0, 1, $3);
1337             }
1338         }
1339
1340         | HALF_REG ASSIGN REG
1341         {
1342           if (IS_H ($1))
1343             return yyerror ("Low reg expected");
1344
1345           if (IS_DREG ($1) && $3.regno == REG_A0x)
1346             {
1347               notethat ("dsp32alu: dregs_lo = A0.x\n");
1348               $$ = DSP32ALU (10, 0, 0, &$1, 0, 0, 0, 0, 0);
1349             }
1350           else if (IS_DREG ($1) && $3.regno == REG_A1x)
1351             {
1352               notethat ("dsp32alu: dregs_lo = A1.x\n");
1353               $$ = DSP32ALU (10, 0, 0, &$1, 0, 0, 0, 0, 1);
1354             }
1355           else
1356             return yyerror ("Register mismatch");
1357         }
1358
1359         | REG ASSIGN REG op_bar_op REG amod0
1360         {
1361           if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1362             {
1363               notethat ("dsp32alu: dregs = dregs .|. dregs (amod0)\n");
1364               $$ = DSP32ALU (0, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
1365             }
1366           else
1367             return yyerror ("Register mismatch");
1368         }
1369
1370         | REG ASSIGN BYTE_DREG xpmod
1371         {
1372           if (IS_DREG ($1) && IS_DREG ($3))
1373             {
1374               notethat ("ALU2op: dregs = dregs_byte\n");
1375               $$ = ALU2OP (&$1, &$3, 12 | ($4.r0 ? 0: 1));
1376             }
1377           else
1378             return yyerror ("Register mismatch");
1379         }
1380
1381         | a_assign ABS REG_A COMMA a_assign ABS REG_A
1382         {
1383           if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
1384             {
1385               notethat ("dsp32alu: A1 = ABS A1 , A0 = ABS A0\n");
1386               $$ = DSP32ALU (16, 0, 0, 0, 0, 0, 0, 0, 3);
1387             }
1388           else
1389             return yyerror ("Register mismatch");
1390         }
1391
1392         | a_assign MINUS REG_A COMMA a_assign MINUS REG_A
1393         {
1394           if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
1395             {
1396               notethat ("dsp32alu: A1 = - A1 , A0 = - A0\n");
1397               $$ = DSP32ALU (14, 0, 0, 0, 0, 0, 0, 0, 3);
1398             }
1399           else
1400             return yyerror ("Register mismatch");
1401         }
1402
1403         | a_minusassign REG_A w32_or_nothing
1404         {
1405           if (!IS_A1 ($1) && IS_A1 ($2))
1406             {
1407               notethat ("dsp32alu: A0 -= A1\n");
1408               $$ = DSP32ALU (11, 0, 0, 0, 0, 0, $3.r0, 0, 3);
1409             }
1410           else
1411             return yyerror ("Register mismatch");
1412         }
1413
1414         | REG _MINUS_ASSIGN expr
1415         {
1416           if (IS_IREG ($1) && EXPR_VALUE ($3) == 4)
1417             {
1418               notethat ("dagMODik: iregs -= 4\n");
1419               $$ = DAGMODIK (&$1, 3);
1420             }
1421           else if (IS_IREG ($1) && EXPR_VALUE ($3) == 2)
1422             {
1423               notethat ("dagMODik: iregs -= 2\n");
1424               $$ = DAGMODIK (&$1, 1);
1425             }
1426           else
1427             return yyerror ("Register or value mismatch");
1428         }
1429
1430         | REG _PLUS_ASSIGN REG LPAREN BREV RPAREN
1431         {
1432           if (IS_IREG ($1) && IS_MREG ($3))
1433             {
1434               notethat ("dagMODim: iregs += mregs (opt_brev)\n");
1435               /* i, m, op, br.  */
1436               $$ = DAGMODIM (&$1, &$3, 0, 1);
1437             }
1438           else if (IS_PREG ($1) && IS_PREG ($3))
1439             {
1440               notethat ("PTR2op: pregs += pregs (BREV )\n");
1441               $$ = PTR2OP (&$1, &$3, 5);
1442             }
1443           else
1444             return yyerror ("Register mismatch");
1445         }
1446
1447         | REG _MINUS_ASSIGN REG
1448         {
1449           if (IS_IREG ($1) && IS_MREG ($3))
1450             {
1451               notethat ("dagMODim: iregs -= mregs\n");
1452               $$ = DAGMODIM (&$1, &$3, 1, 0);
1453             }
1454           else if (IS_PREG ($1) && IS_PREG ($3))
1455             {
1456               notethat ("PTR2op: pregs -= pregs\n");
1457               $$ = PTR2OP (&$1, &$3, 0);
1458             }
1459           else
1460             return yyerror ("Register mismatch");
1461         }
1462
1463         | REG_A _PLUS_ASSIGN REG_A w32_or_nothing
1464         {
1465           if (!IS_A1 ($1) && IS_A1 ($3))
1466             {
1467               notethat ("dsp32alu: A0 += A1 (W32)\n");
1468               $$ = DSP32ALU (11, 0, 0, 0, 0, 0, $4.r0, 0, 2);
1469             }
1470           else
1471             return yyerror ("Register mismatch");
1472         }
1473
1474         | REG _PLUS_ASSIGN REG
1475         {
1476           if (IS_IREG ($1) && IS_MREG ($3))
1477             {
1478               notethat ("dagMODim: iregs += mregs\n");
1479               $$ = DAGMODIM (&$1, &$3, 0, 0);
1480             }
1481           else
1482             return yyerror ("iregs += mregs expected");
1483         }
1484
1485         | REG _PLUS_ASSIGN expr
1486         {
1487           if (IS_IREG ($1))
1488             {
1489               if (EXPR_VALUE ($3) == 4)
1490                 {
1491                   notethat ("dagMODik: iregs += 4\n");
1492                   $$ = DAGMODIK (&$1, 2);
1493                 }
1494               else if (EXPR_VALUE ($3) == 2)
1495                 {
1496                   notethat ("dagMODik: iregs += 2\n");
1497                   $$ = DAGMODIK (&$1, 0);
1498                 }
1499               else
1500                 return yyerror ("iregs += [ 2 | 4 ");
1501             }
1502           else if (IS_PREG ($1) && IS_IMM ($3, 7))
1503             {
1504               notethat ("COMPI2opP: pregs += imm7\n");
1505               $$ = COMPI2OPP (&$1, imm7 ($3), 1);
1506             }
1507           else if (IS_DREG ($1) && IS_IMM ($3, 7))
1508             {
1509               notethat ("COMPI2opD: dregs += imm7\n");
1510               $$ = COMPI2OPD (&$1, imm7 ($3), 1);
1511             }
1512           else if ((IS_DREG ($1) || IS_PREG ($1)) && IS_CONST ($3))
1513             return yyerror ("Immediate value out of range");
1514           else
1515             return yyerror ("Register mismatch");
1516         }
1517
1518         | REG _STAR_ASSIGN REG
1519         {
1520           if (IS_DREG ($1) && IS_DREG ($3))
1521             {
1522               notethat ("ALU2op: dregs *= dregs\n");
1523               $$ = ALU2OP (&$1, &$3, 3);
1524             }
1525           else
1526             return yyerror ("Register mismatch");
1527         }
1528
1529         | SAA LPAREN REG COLON expr COMMA REG COLON expr RPAREN aligndir
1530         {
1531           if (!valid_dreg_pair (&$3, $5))
1532             return yyerror ("Bad dreg pair");
1533           else if (!valid_dreg_pair (&$7, $9))
1534             return yyerror ("Bad dreg pair");
1535           else
1536             {
1537               notethat ("dsp32alu: SAA (dregs_pair , dregs_pair ) (aligndir)\n");
1538               $$ = DSP32ALU (18, 0, 0, 0, &$3, &$7, $11.r0, 0, 0);
1539             }
1540         }
1541
1542         | a_assign REG_A LPAREN S RPAREN COMMA a_assign REG_A LPAREN S RPAREN
1543         {
1544           if (REG_SAME ($1, $2) && REG_SAME ($7, $8) && !REG_SAME ($1, $7))
1545             {
1546               notethat ("dsp32alu: A1 = A1 (S) , A0 = A0 (S)\n");
1547               $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 1, 0, 2);
1548             }
1549           else
1550             return yyerror ("Register mismatch");
1551         }
1552
1553         | REG ASSIGN LPAREN REG PLUS REG RPAREN LESS_LESS expr
1554         {
1555           if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6)
1556               && REG_SAME ($1, $4))
1557             {
1558               if (EXPR_VALUE ($9) == 1)
1559                 {
1560                   notethat ("ALU2op: dregs = (dregs + dregs) << 1\n");
1561                   $$ = ALU2OP (&$1, &$6, 4);
1562                 }
1563               else if (EXPR_VALUE ($9) == 2)
1564                 {
1565                   notethat ("ALU2op: dregs = (dregs + dregs) << 2\n");
1566                   $$ = ALU2OP (&$1, &$6, 5);
1567                 }
1568               else
1569                 return yyerror ("Bad shift value");
1570             }
1571           else if (IS_PREG ($1) && IS_PREG ($4) && IS_PREG ($6)
1572                    && REG_SAME ($1, $4))
1573             {
1574               if (EXPR_VALUE ($9) == 1)
1575                 {
1576                   notethat ("PTR2op: pregs = (pregs + pregs) << 1\n");
1577                   $$ = PTR2OP (&$1, &$6, 6);
1578                 }
1579               else if (EXPR_VALUE ($9) == 2)
1580                 {
1581                   notethat ("PTR2op: pregs = (pregs + pregs) << 2\n");
1582                   $$ = PTR2OP (&$1, &$6, 7);
1583                 }
1584               else
1585                 return yyerror ("Bad shift value");
1586             }
1587           else
1588             return yyerror ("Register mismatch");
1589         }
1590
1591 /*  COMP3 CCFLAG.  */
1592         | REG ASSIGN REG BAR REG
1593         {
1594           if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1595             {
1596               notethat ("COMP3op: dregs = dregs | dregs\n");
1597               $$ = COMP3OP (&$1, &$3, &$5, 3);
1598             }
1599           else
1600             return yyerror ("Dregs expected");
1601         }
1602         | REG ASSIGN REG CARET REG
1603         {
1604           if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1605             {
1606               notethat ("COMP3op: dregs = dregs ^ dregs\n");
1607               $$ = COMP3OP (&$1, &$3, &$5, 4);
1608             }
1609           else
1610             return yyerror ("Dregs expected");
1611         }
1612         | REG ASSIGN REG PLUS LPAREN REG LESS_LESS expr RPAREN
1613         {
1614           if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($6))
1615             {
1616               if (EXPR_VALUE ($8) == 1)
1617                 {
1618                   notethat ("COMP3op: pregs = pregs + (pregs << 1)\n");
1619                   $$ = COMP3OP (&$1, &$3, &$6, 6);
1620                 }
1621               else if (EXPR_VALUE ($8) == 2)
1622                 {
1623                   notethat ("COMP3op: pregs = pregs + (pregs << 2)\n");
1624                   $$ = COMP3OP (&$1, &$3, &$6, 7);
1625                 }
1626               else
1627                   return yyerror ("Bad shift value");
1628             }
1629           else
1630             return yyerror ("Dregs expected");
1631         }
1632         | CCREG ASSIGN REG_A _ASSIGN_ASSIGN REG_A
1633         {
1634           if ($3.regno == REG_A0 && $5.regno == REG_A1)
1635             {
1636               notethat ("CCflag: CC = A0 == A1\n");
1637               $$ = CCFLAG (0, 0, 5, 0, 0);
1638             }
1639           else
1640             return yyerror ("AREGs are in bad order or same");
1641         }
1642         | CCREG ASSIGN REG_A LESS_THAN REG_A
1643         {
1644           if ($3.regno == REG_A0 && $5.regno == REG_A1)
1645             {
1646               notethat ("CCflag: CC = A0 < A1\n");
1647               $$ = CCFLAG (0, 0, 6, 0, 0);
1648             }
1649           else
1650             return yyerror ("AREGs are in bad order or same");
1651         }
1652         | CCREG ASSIGN REG LESS_THAN REG iu_or_nothing
1653         {
1654           if ((IS_DREG ($3) && IS_DREG ($5))
1655               || (IS_PREG ($3) && IS_PREG ($5)))
1656             {
1657               notethat ("CCflag: CC = dpregs < dpregs\n");
1658               $$ = CCFLAG (&$3, $5.regno & CODE_MASK, $6.r0, 0, IS_PREG ($3) ? 1 : 0);
1659             }
1660           else
1661             return yyerror ("Bad register in comparison");
1662         }
1663         | CCREG ASSIGN REG LESS_THAN expr iu_or_nothing
1664         {
1665           if (!IS_DREG ($3) && !IS_PREG ($3))
1666             return yyerror ("Bad register in comparison");
1667
1668           if (($6.r0 == 1 && IS_IMM ($5, 3))
1669               || ($6.r0 == 3 && IS_UIMM ($5, 3)))
1670             {
1671               notethat ("CCflag: CC = dpregs < (u)imm3\n");
1672               $$ = CCFLAG (&$3, imm3 ($5), $6.r0, 1, IS_PREG ($3) ? 1 : 0);
1673             }
1674           else
1675             return yyerror ("Bad constant value");
1676         }
1677         | CCREG ASSIGN REG _ASSIGN_ASSIGN REG
1678         {
1679           if ((IS_DREG ($3) && IS_DREG ($5))
1680               || (IS_PREG ($3) && IS_PREG ($5)))
1681             {
1682               notethat ("CCflag: CC = dpregs == dpregs\n");
1683               $$ = CCFLAG (&$3, $5.regno & CODE_MASK, 0, 0, IS_PREG ($3) ? 1 : 0);
1684             }
1685           else
1686             return yyerror ("Bad register in comparison");
1687         }
1688         | CCREG ASSIGN REG _ASSIGN_ASSIGN expr
1689         {
1690           if (!IS_DREG ($3) && !IS_PREG ($3))
1691             return yyerror ("Bad register in comparison");
1692
1693           if (IS_IMM ($5, 3))
1694             {
1695               notethat ("CCflag: CC = dpregs == imm3\n");
1696               $$ = CCFLAG (&$3, imm3 ($5), 0, 1, IS_PREG ($3) ? 1 : 0);
1697             }
1698           else
1699             return yyerror ("Bad constant range");
1700         }
1701         | CCREG ASSIGN REG_A _LESS_THAN_ASSIGN REG_A
1702         {
1703           if ($3.regno == REG_A0 && $5.regno == REG_A1)
1704             {
1705               notethat ("CCflag: CC = A0 <= A1\n");
1706               $$ = CCFLAG (0, 0, 7, 0, 0);
1707             }
1708           else
1709             return yyerror ("AREGs are in bad order or same");
1710         }
1711         | CCREG ASSIGN REG _LESS_THAN_ASSIGN REG iu_or_nothing
1712         {
1713           if ((IS_DREG ($3) && IS_DREG ($5))
1714               || (IS_PREG ($3) && IS_PREG ($5)))
1715             {
1716               notethat ("CCflag: CC = dpregs <= dpregs (..)\n");
1717               $$ = CCFLAG (&$3, $5.regno & CODE_MASK,
1718                            1 + $6.r0, 0, IS_PREG ($3) ? 1 : 0);
1719             }
1720           else
1721             return yyerror ("Bad register in comparison");
1722         }
1723         | CCREG ASSIGN REG _LESS_THAN_ASSIGN expr iu_or_nothing
1724         {
1725           if (!IS_DREG ($3) && !IS_PREG ($3))
1726             return yyerror ("Bad register in comparison");
1727
1728           if (($6.r0 == 1 && IS_IMM ($5, 3))
1729               || ($6.r0 == 3 && IS_UIMM ($5, 3)))
1730             {
1731               notethat ("CCflag: CC = dpregs <= (u)imm3\n");
1732               $$ = CCFLAG (&$3, imm3 ($5), 1 + $6.r0, 1, IS_PREG ($3) ? 1 : 0);
1733             }
1734           else
1735             return yyerror ("Bad constant value");
1736         }
1737
1738         | REG ASSIGN REG AMPERSAND REG
1739         {
1740           if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
1741             {
1742               notethat ("COMP3op: dregs = dregs & dregs\n");
1743               $$ = COMP3OP (&$1, &$3, &$5, 2);
1744             }
1745           else
1746             return yyerror ("Dregs expected");
1747         }
1748
1749         | ccstat
1750         {
1751           notethat ("CC2stat operation\n");
1752           $$ = bfin_gen_cc2stat ($1.r0, $1.x0, $1.s0);
1753         }
1754
1755         | REG ASSIGN REG
1756         {
1757           if ((IS_GENREG ($1) && IS_GENREG ($3))
1758               || (IS_GENREG ($1) && IS_DAGREG ($3))
1759               || (IS_DAGREG ($1) && IS_GENREG ($3))
1760               || (IS_DAGREG ($1) && IS_DAGREG ($3))
1761               || (IS_GENREG ($1) && $3.regno == REG_USP)
1762               || ($1.regno == REG_USP && IS_GENREG ($3))
1763               || ($1.regno == REG_USP && $3.regno == REG_USP)
1764               || (IS_DREG ($1) && IS_SYSREG ($3))
1765               || (IS_PREG ($1) && IS_SYSREG ($3))
1766               || (IS_SYSREG ($1) && IS_GENREG ($3))
1767               || (IS_ALLREG ($1) && IS_EMUDAT ($3))
1768               || (IS_EMUDAT ($1) && IS_ALLREG ($3))
1769               || (IS_SYSREG ($1) && $3.regno == REG_USP))
1770             {
1771               $$ = bfin_gen_regmv (&$3, &$1);
1772             }
1773           else
1774             return yyerror ("Unsupported register move");
1775         }
1776
1777         | CCREG ASSIGN REG
1778         {
1779           if (IS_DREG ($3))
1780             {
1781               notethat ("CC2dreg: CC = dregs\n");
1782               $$ = bfin_gen_cc2dreg (1, &$3);
1783             }
1784           else
1785             return yyerror ("Only 'CC = Dreg' supported");
1786         }
1787
1788         | REG ASSIGN CCREG
1789         {
1790           if (IS_DREG ($1))
1791             {
1792               notethat ("CC2dreg: dregs = CC\n");
1793               $$ = bfin_gen_cc2dreg (0, &$1);
1794             }
1795           else
1796             return yyerror ("Only 'Dreg = CC' supported");
1797         }
1798
1799         | CCREG _ASSIGN_BANG CCREG
1800         {
1801           notethat ("CC2dreg: CC =! CC\n");
1802           $$ = bfin_gen_cc2dreg (3, 0);
1803         }
1804
1805 /* DSPMULT.  */
1806
1807         | HALF_REG ASSIGN multiply_halfregs opt_mode
1808         {
1809           notethat ("dsp32mult: dregs_half = multiply_halfregs (opt_mode)\n");
1810
1811           if (!IS_H ($1) && $4.MM)
1812             return yyerror ("(M) not allowed with MAC0");
1813
1814           if ($4.mod != 0 && $4.mod != M_FU && $4.mod != M_IS
1815               && $4.mod != M_IU && $4.mod != M_T && $4.mod != M_TFU
1816               && $4.mod != M_S2RND && $4.mod != M_ISS2 && $4.mod != M_IH)
1817             return yyerror ("bad option.");
1818
1819           if (IS_H ($1))
1820             {
1821               $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 0,
1822                               IS_H ($3.s0), IS_H ($3.s1), 0, 0,
1823                               &$1, 0, &$3.s0, &$3.s1, 0);
1824             }
1825           else
1826             {
1827               $$ = DSP32MULT (0, 0, $4.mod, 0, 0,
1828                               0, 0, IS_H ($3.s0), IS_H ($3.s1),
1829                               &$1, 0, &$3.s0, &$3.s1, 1);
1830             }
1831         }
1832
1833         | REG ASSIGN multiply_halfregs opt_mode
1834         {
1835           /* Odd registers can use (M).  */
1836           if (!IS_DREG ($1))
1837             return yyerror ("Dreg expected");
1838
1839           if (IS_EVEN ($1) && $4.MM)
1840             return yyerror ("(M) not allowed with MAC0");
1841
1842           if ($4.mod != 0 && $4.mod != M_FU && $4.mod != M_IS
1843               && $4.mod != M_S2RND && $4.mod != M_ISS2)
1844             return yyerror ("bad option");
1845
1846           if (!IS_EVEN ($1))
1847             {
1848               notethat ("dsp32mult: dregs = multiply_halfregs (opt_mode)\n");
1849
1850               $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 1,
1851                               IS_H ($3.s0), IS_H ($3.s1), 0, 0,
1852                               &$1, 0, &$3.s0, &$3.s1, 0);
1853             }
1854           else
1855             {
1856               notethat ("dsp32mult: dregs = multiply_halfregs opt_mode\n");
1857               $$ = DSP32MULT (0, 0, $4.mod, 0, 1,
1858                               0, 0, IS_H ($3.s0), IS_H ($3.s1),
1859                               &$1,  0, &$3.s0, &$3.s1, 1);
1860             }
1861         }
1862
1863         | HALF_REG ASSIGN multiply_halfregs opt_mode COMMA
1864           HALF_REG ASSIGN multiply_halfregs opt_mode
1865         {
1866           if (!IS_DREG ($1) || !IS_DREG ($6))
1867             return yyerror ("Dregs expected");
1868
1869           if (!IS_HCOMPL($1, $6))
1870             return yyerror ("Dest registers mismatch");
1871
1872           if (check_multiply_halfregs (&$3, &$8) < 0)
1873             return -1;
1874
1875           if ((!IS_H ($1) && $4.MM)
1876               || (!IS_H ($6) && $9.MM))
1877             return yyerror ("(M) not allowed with MAC0");
1878
1879           notethat ("dsp32mult: dregs_hi = multiply_halfregs mxd_mod, "
1880                     "dregs_lo = multiply_halfregs opt_mode\n");
1881
1882           if (IS_H ($1))
1883             $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 0,
1884                             IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
1885                             &$1, 0, &$3.s0, &$3.s1, 1);
1886           else
1887             $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 0,
1888                             IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
1889                             &$1, 0, &$3.s0, &$3.s1, 1);
1890         }
1891
1892         | REG ASSIGN multiply_halfregs opt_mode COMMA REG ASSIGN multiply_halfregs opt_mode
1893         {
1894           if (!IS_DREG ($1) || !IS_DREG ($6))
1895             return yyerror ("Dregs expected");
1896
1897           if ((IS_EVEN ($1) && $6.regno - $1.regno != 1)
1898               || (IS_EVEN ($6) && $1.regno - $6.regno != 1))
1899             return yyerror ("Dest registers mismatch");
1900
1901           if (check_multiply_halfregs (&$3, &$8) < 0)
1902             return -1;
1903
1904           if ((IS_EVEN ($1) && $4.MM)
1905               || (IS_EVEN ($6) && $9.MM))
1906             return yyerror ("(M) not allowed with MAC0");
1907
1908           notethat ("dsp32mult: dregs = multiply_halfregs mxd_mod, "
1909                    "dregs = multiply_halfregs opt_mode\n");
1910
1911           if (IS_EVEN ($1))
1912             $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 1,
1913                             IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
1914                             &$1, 0, &$3.s0, &$3.s1, 1);
1915           else
1916             $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 1,
1917                             IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
1918                             &$1, 0, &$3.s0, &$3.s1, 1);
1919         }
1920
1921 \f
1922 /* SHIFTs.  */
1923         | a_assign ASHIFT REG_A BY HALF_REG
1924         {
1925           if (!REG_SAME ($1, $3))
1926             return yyerror ("Aregs must be same");
1927
1928           if (IS_DREG ($5) && !IS_H ($5))
1929             {
1930               notethat ("dsp32shift: A0 = ASHIFT A0 BY dregs_lo\n");
1931               $$ = DSP32SHIFT (3, 0, &$5, 0, 0, IS_A1 ($1));
1932             }
1933           else
1934             return yyerror ("Dregs expected");
1935         }
1936
1937         | HALF_REG ASSIGN ASHIFT HALF_REG BY HALF_REG smod
1938         {
1939           if (IS_DREG ($6) && !IS_H ($6))
1940             {
1941               notethat ("dsp32shift: dregs_half = ASHIFT dregs_half BY dregs_lo\n");
1942               $$ = DSP32SHIFT (0, &$1, &$6, &$4, $7.s0, HL2 ($1, $4));
1943             }
1944           else
1945             return yyerror ("Dregs expected");
1946         }
1947
1948         | a_assign REG_A LESS_LESS expr
1949         {
1950           if (!REG_SAME ($1, $2))
1951             return yyerror ("Aregs must be same");
1952
1953           if (IS_UIMM ($4, 5))
1954             {
1955               notethat ("dsp32shiftimm: A0 = A0 << uimm5\n");
1956               $$ = DSP32SHIFTIMM (3, 0, imm5 ($4), 0, 0, IS_A1 ($1));
1957             }
1958           else
1959             return yyerror ("Bad shift value");
1960         }
1961
1962         | REG ASSIGN REG LESS_LESS expr vsmod
1963         {
1964           if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
1965             {
1966               if ($6.r0)
1967                 {
1968                   /*  Vector?  */
1969                   notethat ("dsp32shiftimm: dregs = dregs << expr (V, .)\n");
1970                   $$ = DSP32SHIFTIMM (1, &$1, imm4 ($5), &$3, $6.s0 ? 1 : 2, 0);
1971                 }
1972               else
1973                 {
1974                   notethat ("dsp32shiftimm: dregs =  dregs << uimm5 (.)\n");
1975                   $$ = DSP32SHIFTIMM (2, &$1, imm6 ($5), &$3, $6.s0 ? 1 : 2, 0);
1976                 }
1977             }
1978           else if ($6.s0 == 0 && IS_PREG ($1) && IS_PREG ($3))
1979             {
1980               if (EXPR_VALUE ($5) == 2)
1981                 {
1982                   notethat ("PTR2op: pregs = pregs << 2\n");
1983                   $$ = PTR2OP (&$1, &$3, 1);
1984                 }
1985               else if (EXPR_VALUE ($5) == 1)
1986                 {
1987                   notethat ("COMP3op: pregs = pregs << 1\n");
1988                   $$ = COMP3OP (&$1, &$3, &$3, 5);
1989                 }
1990               else
1991                 return yyerror ("Bad shift value");
1992             }
1993           else
1994             return yyerror ("Bad shift value or register");
1995         }
1996         | HALF_REG ASSIGN HALF_REG LESS_LESS expr smod
1997         {
1998           if (IS_UIMM ($5, 4))
1999             {
2000               if ($6.s0)
2001                 {
2002                   notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4 (S)\n");
2003                   $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, $6.s0, HL2 ($1, $3));
2004                 }
2005               else
2006                 {
2007                   notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4\n");
2008                   $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, 2, HL2 ($1, $3));
2009                 }
2010             }
2011           else
2012             return yyerror ("Bad shift value");
2013         }
2014         | REG ASSIGN ASHIFT REG BY HALF_REG vsmod
2015         {
2016           int op;
2017
2018           if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6) && !IS_H ($6))
2019             {
2020               if ($7.r0)
2021                 {
2022                   op = 1;
2023                   notethat ("dsp32shift: dregs = ASHIFT dregs BY "
2024                            "dregs_lo (V, .)\n");
2025                 }
2026               else
2027                 {
2028
2029                   op = 2;
2030                   notethat ("dsp32shift: dregs = ASHIFT dregs BY dregs_lo (.)\n");
2031                 }
2032               $$ = DSP32SHIFT (op, &$1, &$6, &$4, $7.s0, 0);
2033             }
2034           else
2035             return yyerror ("Dregs expected");
2036         }
2037
2038 /*  EXPADJ.  */
2039         | HALF_REG ASSIGN EXPADJ LPAREN REG COMMA HALF_REG RPAREN vmod
2040         {
2041           if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
2042             {
2043               notethat ("dsp32shift: dregs_lo = EXPADJ (dregs , dregs_lo )\n");
2044               $$ = DSP32SHIFT (7, &$1, &$7, &$5, $9.r0, 0);
2045             }
2046           else
2047             return yyerror ("Bad shift value or register");
2048         }
2049
2050
2051         | HALF_REG ASSIGN EXPADJ LPAREN HALF_REG COMMA HALF_REG RPAREN
2052         {
2053           if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
2054             {
2055               notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_lo, dregs_lo)\n");
2056               $$ = DSP32SHIFT (7, &$1, &$7, &$5, 2, 0);
2057             }
2058           else if (IS_DREG_L ($1) && IS_DREG_H ($5) && IS_DREG_L ($7))
2059             {
2060               notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_hi, dregs_lo)\n");
2061               $$ = DSP32SHIFT (7, &$1, &$7, &$5, 3, 0);
2062             }
2063           else
2064             return yyerror ("Bad shift value or register");
2065         }
2066
2067 /* DEPOSIT.  */
2068
2069         | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN
2070         {
2071           if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2072             {
2073               notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs )\n");
2074               $$ = DSP32SHIFT (10, &$1, &$7, &$5, 2, 0);
2075             }
2076           else
2077             return yyerror ("Register mismatch");
2078         }
2079
2080         | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN LPAREN X RPAREN
2081         {
2082           if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2083             {
2084               notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs ) (X)\n");
2085               $$ = DSP32SHIFT (10, &$1, &$7, &$5, 3, 0);
2086             }
2087           else
2088             return yyerror ("Register mismatch");
2089         }
2090
2091         | REG ASSIGN EXTRACT LPAREN REG COMMA HALF_REG RPAREN xpmod
2092         {
2093           if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG_L ($7))
2094             {
2095               notethat ("dsp32shift: dregs = EXTRACT (dregs, dregs_lo ) (.)\n");
2096               $$ = DSP32SHIFT (10, &$1, &$7, &$5, $9.r0, 0);
2097             }
2098           else
2099             return yyerror ("Register mismatch");
2100         }
2101
2102         | a_assign REG_A _GREATER_GREATER_GREATER expr
2103         {
2104           if (!REG_SAME ($1, $2))
2105             return yyerror ("Aregs must be same");
2106
2107           if (IS_UIMM ($4, 5))
2108             {
2109               notethat ("dsp32shiftimm: Ax = Ax >>> uimm5\n");
2110               $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 0, IS_A1 ($1));
2111             }
2112           else
2113             return yyerror ("Shift value range error");
2114         }
2115         | a_assign LSHIFT REG_A BY HALF_REG
2116         {
2117           if (REG_SAME ($1, $3) && IS_DREG_L ($5))
2118             {
2119               notethat ("dsp32shift: Ax = LSHIFT Ax BY dregs_lo\n");
2120               $$ = DSP32SHIFT (3, 0, &$5, 0, 1, IS_A1 ($1));
2121             }
2122           else
2123             return yyerror ("Register mismatch");
2124         }
2125
2126         | HALF_REG ASSIGN LSHIFT HALF_REG BY HALF_REG
2127         {
2128           if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2129             {
2130               notethat ("dsp32shift: dregs_lo = LSHIFT dregs_hi BY dregs_lo\n");
2131               $$ = DSP32SHIFT (0, &$1, &$6, &$4, 2, HL2 ($1, $4));
2132             }
2133           else
2134             return yyerror ("Register mismatch");
2135         }
2136
2137         | REG ASSIGN LSHIFT REG BY HALF_REG vmod
2138         {
2139           if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2140             {
2141               notethat ("dsp32shift: dregs = LSHIFT dregs BY dregs_lo (V )\n");
2142               $$ = DSP32SHIFT ($7.r0 ? 1: 2, &$1, &$6, &$4, 2, 0);
2143             }
2144           else
2145             return yyerror ("Register mismatch");
2146         }
2147
2148         | REG ASSIGN SHIFT REG BY HALF_REG
2149         {
2150           if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2151             {
2152               notethat ("dsp32shift: dregs = SHIFT dregs BY dregs_lo\n");
2153               $$ = DSP32SHIFT (2, &$1, &$6, &$4, 2, 0);
2154             }
2155           else
2156             return yyerror ("Register mismatch");
2157         }
2158
2159         | a_assign REG_A GREATER_GREATER expr
2160         {
2161           if (REG_SAME ($1, $2) && IS_IMM ($4, 6) >= 0)
2162             {
2163               notethat ("dsp32shiftimm: Ax = Ax >> imm6\n");
2164               $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 1, IS_A1 ($1));
2165             }
2166           else
2167             return yyerror ("Accu register expected");
2168         }
2169
2170         | REG ASSIGN REG GREATER_GREATER expr vmod
2171         {
2172           if ($6.r0 == 1)
2173             {
2174               if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2175                 {
2176                   notethat ("dsp32shiftimm: dregs = dregs >> uimm5 (V)\n");
2177                   $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, 2, 0);
2178                 }
2179               else
2180                 return yyerror ("Register mismatch");
2181             }
2182           else
2183             {
2184               if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2185                 {
2186                   notethat ("dsp32shiftimm: dregs = dregs >> uimm5\n");
2187                   $$ = DSP32SHIFTIMM (2, &$1, -imm6 ($5), &$3, 2, 0);
2188                 }
2189               else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 2)
2190                 {
2191                   notethat ("PTR2op: pregs = pregs >> 2\n");
2192                   $$ = PTR2OP (&$1, &$3, 3);
2193                 }
2194               else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 1)
2195                 {
2196                   notethat ("PTR2op: pregs = pregs >> 1\n");
2197                   $$ = PTR2OP (&$1, &$3, 4);
2198                 }
2199               else
2200                 return yyerror ("Register mismatch");
2201             }
2202         }
2203         | HALF_REG ASSIGN HALF_REG GREATER_GREATER expr
2204         {
2205           if (IS_UIMM ($5, 5))
2206             {
2207               notethat ("dsp32shiftimm:  dregs_half =  dregs_half >> uimm5\n");
2208               $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3, 2, HL2 ($1, $3));
2209             }
2210           else
2211             return yyerror ("Register mismatch");
2212         }
2213         | HALF_REG ASSIGN HALF_REG _GREATER_GREATER_GREATER expr smod
2214         {
2215           if (IS_UIMM ($5, 5))
2216             {
2217               notethat ("dsp32shiftimm: dregs_half = dregs_half >>> uimm5\n");
2218               $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3,
2219                                   $6.s0, HL2 ($1, $3));
2220             }
2221           else
2222             return yyerror ("Register or modifier mismatch");
2223         }
2224
2225
2226         | REG ASSIGN REG _GREATER_GREATER_GREATER expr vsmod
2227         {
2228           if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
2229             {
2230               if ($6.r0)
2231                 {
2232                   /* Vector?  */
2233                   notethat ("dsp32shiftimm: dregs  =  dregs >>> uimm5 (V, .)\n");
2234                   $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, $6.s0, 0);
2235                 }
2236               else
2237                 {
2238                   notethat ("dsp32shiftimm: dregs  =  dregs >>> uimm5 (.)\n");
2239                   $$ = DSP32SHIFTIMM (2, &$1, -uimm5 ($5), &$3, $6.s0, 0);
2240                 }
2241             }
2242           else
2243             return yyerror ("Register mismatch");
2244         }
2245
2246         | HALF_REG ASSIGN ONES REG
2247         {
2248           if (IS_DREG_L ($1) && IS_DREG ($4))
2249             {
2250               notethat ("dsp32shift: dregs_lo = ONES dregs\n");
2251               $$ = DSP32SHIFT (6, &$1, 0, &$4, 3, 0);
2252             }
2253           else
2254             return yyerror ("Register mismatch");
2255         }
2256
2257         | REG ASSIGN PACK LPAREN HALF_REG COMMA HALF_REG RPAREN
2258         {
2259           if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2260             {
2261               notethat ("dsp32shift: dregs = PACK (dregs_hi , dregs_hi )\n");
2262               $$ = DSP32SHIFT (4, &$1, &$7, &$5, HL2 ($5, $7), 0);
2263             }
2264           else
2265             return yyerror ("Register mismatch");
2266         }
2267
2268         | HALF_REG ASSIGN CCREG ASSIGN BXORSHIFT LPAREN REG_A COMMA REG RPAREN
2269         {
2270           if (IS_DREG ($1)
2271               && $7.regno == REG_A0
2272               && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
2273             {
2274               notethat ("dsp32shift: dregs_lo = CC = BXORSHIFT (A0 , dregs )\n");
2275               $$ = DSP32SHIFT (11, &$1, &$9, 0, 0, 0);
2276             }
2277           else
2278             return yyerror ("Register mismatch");
2279         }
2280
2281         | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG RPAREN
2282         {
2283           if (IS_DREG ($1)
2284               && $7.regno == REG_A0
2285               && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
2286             {
2287               notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , dregs)\n");
2288               $$ = DSP32SHIFT (11, &$1, &$9, 0, 1, 0);
2289             }
2290           else
2291             return yyerror ("Register mismatch");
2292         }
2293
2294         | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
2295         {
2296           if (IS_DREG ($1) && !IS_H ($1) && !REG_SAME ($7, $9))
2297             {
2298               notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , A1 , CC)\n");
2299               $$ = DSP32SHIFT (12, &$1, 0, 0, 1, 0);
2300             }
2301           else
2302             return yyerror ("Register mismatch");
2303         }
2304
2305         | a_assign ROT REG_A BY HALF_REG
2306         {
2307           if (REG_SAME ($1, $3) && IS_DREG_L ($5))
2308             {
2309               notethat ("dsp32shift: Ax = ROT Ax BY dregs_lo\n");
2310               $$ = DSP32SHIFT (3, 0, &$5, 0, 2, IS_A1 ($1));
2311             }
2312           else
2313             return yyerror ("Register mismatch");
2314         }
2315
2316         | REG ASSIGN ROT REG BY HALF_REG
2317         {
2318           if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
2319             {
2320               notethat ("dsp32shift: dregs = ROT dregs BY dregs_lo\n");
2321               $$ = DSP32SHIFT (2, &$1, &$6, &$4, 3, 0);
2322             }
2323           else
2324             return yyerror ("Register mismatch");
2325         }
2326
2327         | a_assign ROT REG_A BY expr
2328         {
2329           if (IS_IMM ($5, 6))
2330             {
2331               notethat ("dsp32shiftimm: An = ROT An BY imm6\n");
2332               $$ = DSP32SHIFTIMM (3, 0, imm6 ($5), 0, 2, IS_A1 ($1));
2333             }
2334           else
2335             return yyerror ("Register mismatch");
2336         }
2337
2338         | REG ASSIGN ROT REG BY expr
2339         {
2340           if (IS_DREG ($1) && IS_DREG ($4) && IS_IMM ($6, 6))
2341             {
2342               $$ = DSP32SHIFTIMM (2, &$1, imm6 ($6), &$4, 3, IS_A1 ($1));
2343             }
2344           else
2345             return yyerror ("Register mismatch");
2346         }
2347
2348         | HALF_REG ASSIGN SIGNBITS REG_A
2349         {
2350           if (IS_DREG_L ($1))
2351             {
2352               notethat ("dsp32shift: dregs_lo = SIGNBITS An\n");
2353               $$ = DSP32SHIFT (6, &$1, 0, 0, IS_A1 ($4), 0);
2354             }
2355           else
2356             return yyerror ("Register mismatch");
2357         }
2358
2359         | HALF_REG ASSIGN SIGNBITS REG
2360         {
2361           if (IS_DREG_L ($1) && IS_DREG ($4))
2362             {
2363               notethat ("dsp32shift: dregs_lo = SIGNBITS dregs\n");
2364               $$ = DSP32SHIFT (5, &$1, 0, &$4, 0, 0);
2365             }
2366           else
2367             return yyerror ("Register mismatch");
2368         }
2369
2370         | HALF_REG ASSIGN SIGNBITS HALF_REG
2371         {
2372           if (IS_DREG_L ($1))
2373             {
2374               notethat ("dsp32shift: dregs_lo = SIGNBITS dregs_lo\n");
2375               $$ = DSP32SHIFT (5, &$1, 0, &$4, 1 + IS_H ($4), 0);
2376             }
2377           else
2378             return yyerror ("Register mismatch");
2379         }
2380
2381         /* The ASR bit is just inverted here. */
2382         | HALF_REG ASSIGN VIT_MAX LPAREN REG RPAREN asr_asl
2383         {
2384           if (IS_DREG_L ($1) && IS_DREG ($5))
2385             {
2386               notethat ("dsp32shift: dregs_lo = VIT_MAX (dregs) (..)\n");
2387               $$ = DSP32SHIFT (9, &$1, 0, &$5, ($7.r0 ? 0 : 1), 0);
2388             }
2389           else
2390             return yyerror ("Register mismatch");
2391         }
2392
2393         | REG ASSIGN VIT_MAX LPAREN REG COMMA REG RPAREN asr_asl
2394         {
2395           if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
2396             {
2397               notethat ("dsp32shift: dregs = VIT_MAX (dregs, dregs) (ASR)\n");
2398               $$ = DSP32SHIFT (9, &$1, &$7, &$5, 2 | ($9.r0 ? 0 : 1), 0);
2399             }
2400           else
2401             return yyerror ("Register mismatch");
2402         }
2403
2404         | BITMUX LPAREN REG COMMA REG COMMA REG_A RPAREN asr_asl
2405         {
2406           if (REG_SAME ($3, $5))
2407             return yyerror ("Illegal source register combination");
2408
2409           if (IS_DREG ($3) && IS_DREG ($5) && !IS_A1 ($7))
2410             {
2411               notethat ("dsp32shift: BITMUX (dregs , dregs , A0) (ASR)\n");
2412               $$ = DSP32SHIFT (8, 0, &$3, &$5, $9.r0, 0);
2413             }
2414           else
2415             return yyerror ("Register mismatch");
2416         }
2417
2418         | a_assign BXORSHIFT LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
2419         {
2420           if (!IS_A1 ($1) && !IS_A1 ($4) && IS_A1 ($6))
2421             {
2422               notethat ("dsp32shift: A0 = BXORSHIFT (A0 , A1 , CC )\n");
2423               $$ = DSP32SHIFT (12, 0, 0, 0, 0, 0);
2424             }
2425           else
2426             return yyerror ("Dregs expected");
2427         }
2428
2429
2430 /* LOGI2op:     BITCLR (dregs, uimm5).  */
2431         | BITCLR LPAREN REG COMMA expr RPAREN
2432         {
2433           if (IS_DREG ($3) && IS_UIMM ($5, 5))
2434             {
2435               notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2436               $$ = LOGI2OP ($3, uimm5 ($5), 4);
2437             }
2438           else
2439             return yyerror ("Register mismatch");
2440         }
2441
2442 /* LOGI2op:     BITSET (dregs, uimm5).  */
2443         | BITSET LPAREN REG COMMA expr RPAREN
2444         {
2445           if (IS_DREG ($3) && IS_UIMM ($5, 5))
2446             {
2447               notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2448               $$ = LOGI2OP ($3, uimm5 ($5), 2);
2449             }
2450           else
2451             return yyerror ("Register mismatch");
2452         }
2453
2454 /* LOGI2op:     BITTGL (dregs, uimm5).  */
2455         | BITTGL LPAREN REG COMMA expr RPAREN
2456         {
2457           if (IS_DREG ($3) && IS_UIMM ($5, 5))
2458             {
2459               notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
2460               $$ = LOGI2OP ($3, uimm5 ($5), 3);
2461             }
2462           else
2463             return yyerror ("Register mismatch");
2464         }
2465
2466         | CCREG _ASSIGN_BANG BITTST LPAREN REG COMMA expr RPAREN
2467         {
2468           if (IS_DREG ($5) && IS_UIMM ($7, 5))
2469             {
2470               notethat ("LOGI2op: CC =! BITTST (dregs , uimm5 )\n");
2471               $$ = LOGI2OP ($5, uimm5 ($7), 0);
2472             }
2473           else
2474             return yyerror ("Register mismatch or value error");
2475         }
2476
2477         | CCREG ASSIGN BITTST LPAREN REG COMMA expr RPAREN
2478         {
2479           if (IS_DREG ($5) && IS_UIMM ($7, 5))
2480             {
2481               notethat ("LOGI2op: CC = BITTST (dregs , uimm5 )\n");
2482               $$ = LOGI2OP ($5, uimm5 ($7), 1);
2483             }
2484           else
2485             return yyerror ("Register mismatch or value error");
2486         }
2487
2488         | IF BANG CCREG REG ASSIGN REG
2489         {
2490           if ((IS_DREG ($4) || IS_PREG ($4))
2491               && (IS_DREG ($6) || IS_PREG ($6)))
2492             {
2493               notethat ("ccMV: IF ! CC gregs = gregs\n");
2494               $$ = CCMV (&$6, &$4, 0);
2495             }
2496           else
2497             return yyerror ("Register mismatch");
2498         }
2499
2500         | IF CCREG REG ASSIGN REG
2501         {
2502           if ((IS_DREG ($5) || IS_PREG ($5))
2503               && (IS_DREG ($3) || IS_PREG ($3)))
2504             {
2505               notethat ("ccMV: IF CC gregs = gregs\n");
2506               $$ = CCMV (&$5, &$3, 1);
2507             }
2508           else
2509             return yyerror ("Register mismatch");
2510         }
2511
2512         | IF BANG CCREG JUMP expr
2513         {
2514           if (IS_PCREL10 ($5))
2515             {
2516               notethat ("BRCC: IF !CC JUMP  pcrel11m2\n");
2517               $$ = BRCC (0, 0, $5);
2518             }
2519           else
2520             return yyerror ("Bad jump offset");
2521         }
2522
2523         | IF BANG CCREG JUMP expr LPAREN BP RPAREN
2524         {
2525           if (IS_PCREL10 ($5))
2526             {
2527               notethat ("BRCC: IF !CC JUMP  pcrel11m2\n");
2528               $$ = BRCC (0, 1, $5);
2529             }
2530           else
2531             return yyerror ("Bad jump offset");
2532         }
2533
2534         | IF CCREG JUMP expr
2535         {
2536           if (IS_PCREL10 ($4))
2537             {
2538               notethat ("BRCC: IF CC JUMP  pcrel11m2\n");
2539               $$ = BRCC (1, 0, $4);
2540             }
2541           else
2542             return yyerror ("Bad jump offset");
2543         }
2544
2545         | IF CCREG JUMP expr LPAREN BP RPAREN
2546         {
2547           if (IS_PCREL10 ($4))
2548             {
2549               notethat ("BRCC: IF !CC JUMP  pcrel11m2\n");
2550               $$ = BRCC (1, 1, $4);
2551             }
2552           else
2553             return yyerror ("Bad jump offset");
2554         }
2555         | NOP
2556         {
2557           notethat ("ProgCtrl: NOP\n");
2558           $$ = PROGCTRL (0, 0);
2559         }
2560
2561         | RTS
2562         {
2563           notethat ("ProgCtrl: RTS\n");
2564           $$ = PROGCTRL (1, 0);
2565         }
2566
2567         | RTI
2568         {
2569           notethat ("ProgCtrl: RTI\n");
2570           $$ = PROGCTRL (1, 1);
2571         }
2572
2573         | RTX
2574         {
2575           notethat ("ProgCtrl: RTX\n");
2576           $$ = PROGCTRL (1, 2);
2577         }
2578
2579         | RTN
2580         {
2581           notethat ("ProgCtrl: RTN\n");
2582           $$ = PROGCTRL (1, 3);
2583         }
2584
2585         | RTE
2586         {
2587           notethat ("ProgCtrl: RTE\n");
2588           $$ = PROGCTRL (1, 4);
2589         }
2590
2591         | IDLE
2592         {
2593           notethat ("ProgCtrl: IDLE\n");
2594           $$ = PROGCTRL (2, 0);
2595         }
2596
2597         | CSYNC
2598         {
2599           notethat ("ProgCtrl: CSYNC\n");
2600           $$ = PROGCTRL (2, 3);
2601         }
2602
2603         | SSYNC
2604         {
2605           notethat ("ProgCtrl: SSYNC\n");
2606           $$ = PROGCTRL (2, 4);
2607         }
2608
2609         | EMUEXCPT
2610         {
2611           notethat ("ProgCtrl: EMUEXCPT\n");
2612           $$ = PROGCTRL (2, 5);
2613         }
2614
2615         | CLI REG
2616         {
2617           if (IS_DREG ($2))
2618             {
2619               notethat ("ProgCtrl: CLI dregs\n");
2620               $$ = PROGCTRL (3, $2.regno & CODE_MASK);
2621             }
2622           else
2623             return yyerror ("Dreg expected for CLI");
2624         }
2625
2626         | STI REG
2627         {
2628           if (IS_DREG ($2))
2629             {
2630               notethat ("ProgCtrl: STI dregs\n");
2631               $$ = PROGCTRL (4, $2.regno & CODE_MASK);
2632             }
2633           else
2634             return yyerror ("Dreg expected for STI");
2635         }
2636
2637         | JUMP LPAREN REG RPAREN
2638         {
2639           if (IS_PREG ($3))
2640             {
2641               notethat ("ProgCtrl: JUMP (pregs )\n");
2642               $$ = PROGCTRL (5, $3.regno & CODE_MASK);
2643             }
2644           else
2645             return yyerror ("Bad register for indirect jump");
2646         }
2647
2648         | CALL LPAREN REG RPAREN
2649         {
2650           if (IS_PREG ($3))
2651             {
2652               notethat ("ProgCtrl: CALL (pregs )\n");
2653               $$ = PROGCTRL (6, $3.regno & CODE_MASK);
2654             }
2655           else
2656             return yyerror ("Bad register for indirect call");
2657         }
2658
2659         | CALL LPAREN PC PLUS REG RPAREN
2660         {
2661           if (IS_PREG ($5))
2662             {
2663               notethat ("ProgCtrl: CALL (PC + pregs )\n");
2664               $$ = PROGCTRL (7, $5.regno & CODE_MASK);
2665             }
2666           else
2667             return yyerror ("Bad register for indirect call");
2668         }
2669
2670         | JUMP LPAREN PC PLUS REG RPAREN
2671         {
2672           if (IS_PREG ($5))
2673             {
2674               notethat ("ProgCtrl: JUMP (PC + pregs )\n");
2675               $$ = PROGCTRL (8, $5.regno & CODE_MASK);
2676             }
2677           else
2678             return yyerror ("Bad register for indirect jump");
2679         }
2680
2681         | RAISE expr
2682         {
2683           if (IS_UIMM ($2, 4))
2684             {
2685               notethat ("ProgCtrl: RAISE uimm4\n");
2686               $$ = PROGCTRL (9, uimm4 ($2));
2687             }
2688           else
2689             return yyerror ("Bad value for RAISE");
2690         }
2691
2692         | EXCPT expr
2693         {
2694                 notethat ("ProgCtrl: EMUEXCPT\n");
2695                 $$ = PROGCTRL (10, uimm4 ($2));
2696         }
2697
2698         | TESTSET LPAREN REG RPAREN
2699         {
2700           if (IS_PREG ($3))
2701             {
2702               if ($3.regno == REG_SP || $3.regno == REG_FP)
2703                 return yyerror ("Bad register for TESTSET");
2704
2705               notethat ("ProgCtrl: TESTSET (pregs )\n");
2706               $$ = PROGCTRL (11, $3.regno & CODE_MASK);
2707             }
2708           else
2709             return yyerror ("Preg expected");
2710         }
2711
2712         | JUMP expr
2713         {
2714           if (IS_PCREL12 ($2))
2715             {
2716               notethat ("UJUMP: JUMP pcrel12\n");
2717               $$ = UJUMP ($2);
2718             }
2719           else
2720             return yyerror ("Bad value for relative jump");
2721         }
2722
2723         | JUMP_DOT_S expr
2724         {
2725           if (IS_PCREL12 ($2))
2726             {
2727               notethat ("UJUMP: JUMP_DOT_S pcrel12\n");
2728               $$ = UJUMP($2);
2729             }
2730           else
2731             return yyerror ("Bad value for relative jump");
2732         }
2733
2734         | JUMP_DOT_L expr
2735         {
2736           if (IS_PCREL24 ($2))
2737             {
2738               notethat ("CALLa: jump.l pcrel24\n");
2739               $$ = CALLA ($2, 0);
2740             }
2741           else
2742             return yyerror ("Bad value for long jump");
2743         }
2744
2745         | JUMP_DOT_L pltpc
2746         {
2747           if (IS_PCREL24 ($2))
2748             {
2749               notethat ("CALLa: jump.l pcrel24\n");
2750               $$ = CALLA ($2, 2);
2751             }
2752           else
2753             return yyerror ("Bad value for long jump");
2754         }
2755
2756         | CALL expr
2757         {
2758           if (IS_PCREL24 ($2))
2759             {
2760               notethat ("CALLa: CALL pcrel25m2\n");
2761               $$ = CALLA ($2, 1);
2762             }
2763           else
2764             return yyerror ("Bad call address");
2765         }
2766         | CALL pltpc
2767         {
2768           if (IS_PCREL24 ($2))
2769             {
2770               notethat ("CALLa: CALL pcrel25m2\n");
2771               $$ = CALLA ($2, 2);
2772             }
2773           else
2774             return yyerror ("Bad call address");
2775         }
2776
2777 /* ALU2ops.  */
2778 /* ALU2op:      DIVQ (dregs, dregs).  */
2779         | DIVQ LPAREN REG COMMA REG RPAREN
2780         {
2781           if (IS_DREG ($3) && IS_DREG ($5))
2782             $$ = ALU2OP (&$3, &$5, 8);
2783           else
2784             return yyerror ("Bad registers for DIVQ");
2785         }
2786
2787         | DIVS LPAREN REG COMMA REG RPAREN
2788         {
2789           if (IS_DREG ($3) && IS_DREG ($5))
2790             $$ = ALU2OP (&$3, &$5, 9);
2791           else
2792             return yyerror ("Bad registers for DIVS");
2793         }
2794
2795         | REG ASSIGN MINUS REG vsmod
2796         {
2797           if (IS_DREG ($1) && IS_DREG ($4))
2798             {
2799               if ($5.r0 == 0 && $5.s0 == 0 && $5.aop == 0)
2800                 {
2801                   notethat ("ALU2op: dregs = - dregs\n");
2802                   $$ = ALU2OP (&$1, &$4, 14);
2803                 }
2804               else if ($5.r0 == 1 && $5.s0 == 0 && $5.aop == 3)
2805                 {
2806                   notethat ("dsp32alu: dregs = - dregs (.)\n");
2807                   $$ = DSP32ALU (15, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
2808                 }
2809               else
2810                 {
2811                   notethat ("dsp32alu: dregs = - dregs (.)\n");
2812                   $$ = DSP32ALU (7, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
2813                 }
2814             }
2815           else
2816             return yyerror ("Dregs expected");
2817         }
2818
2819         | REG ASSIGN TILDA REG
2820         {
2821           if (IS_DREG ($1) && IS_DREG ($4))
2822             {
2823               notethat ("ALU2op: dregs = ~dregs\n");
2824               $$ = ALU2OP (&$1, &$4, 15);
2825             }
2826           else
2827             return yyerror ("Dregs expected");
2828         }
2829
2830         | REG _GREATER_GREATER_ASSIGN REG
2831         {
2832           if (IS_DREG ($1) && IS_DREG ($3))
2833             {
2834               notethat ("ALU2op: dregs >>= dregs\n");
2835               $$ = ALU2OP (&$1, &$3, 1);
2836             }
2837           else
2838             return yyerror ("Dregs expected");
2839         }
2840
2841         | REG _GREATER_GREATER_ASSIGN expr
2842         {
2843           if (IS_DREG ($1) && IS_UIMM ($3, 5))
2844             {
2845               notethat ("LOGI2op: dregs >>= uimm5\n");
2846               $$ = LOGI2OP ($1, uimm5 ($3), 6);
2847             }
2848           else
2849             return yyerror ("Dregs expected or value error");
2850         }
2851
2852         | REG _GREATER_GREATER_GREATER_THAN_ASSIGN REG
2853         {
2854           if (IS_DREG ($1) && IS_DREG ($3))
2855             {
2856               notethat ("ALU2op: dregs >>>= dregs\n");
2857               $$ = ALU2OP (&$1, &$3, 0);
2858             }
2859           else
2860             return yyerror ("Dregs expected");
2861         }
2862
2863         | REG _LESS_LESS_ASSIGN REG
2864         {
2865           if (IS_DREG ($1) && IS_DREG ($3))
2866             {
2867               notethat ("ALU2op: dregs <<= dregs\n");
2868               $$ = ALU2OP (&$1, &$3, 2);
2869             }
2870           else
2871             return yyerror ("Dregs expected");
2872         }
2873
2874         | REG _LESS_LESS_ASSIGN expr
2875         {
2876           if (IS_DREG ($1) && IS_UIMM ($3, 5))
2877             {
2878               notethat ("LOGI2op: dregs <<= uimm5\n");
2879               $$ = LOGI2OP ($1, uimm5 ($3), 7);
2880             }
2881           else
2882             return yyerror ("Dregs expected or const value error");
2883         }
2884
2885
2886         | REG _GREATER_GREATER_GREATER_THAN_ASSIGN expr
2887         {
2888           if (IS_DREG ($1) && IS_UIMM ($3, 5))
2889             {
2890               notethat ("LOGI2op: dregs >>>= uimm5\n");
2891               $$ = LOGI2OP ($1, uimm5 ($3), 5);
2892             }
2893           else
2894             return yyerror ("Dregs expected");
2895         }
2896
2897 /* Cache Control.  */
2898
2899         | FLUSH LBRACK REG RBRACK
2900         {
2901           notethat ("CaCTRL: FLUSH [ pregs ]\n");
2902           if (IS_PREG ($3))
2903             $$ = CACTRL (&$3, 0, 2);
2904           else
2905             return yyerror ("Bad register(s) for FLUSH");
2906         }
2907
2908         | FLUSH reg_with_postinc
2909         {
2910           if (IS_PREG ($2))
2911             {
2912               notethat ("CaCTRL: FLUSH [ pregs ++ ]\n");
2913               $$ = CACTRL (&$2, 1, 2);
2914             }
2915           else
2916             return yyerror ("Bad register(s) for FLUSH");
2917         }
2918
2919         | FLUSHINV LBRACK REG RBRACK
2920         {
2921           if (IS_PREG ($3))
2922             {
2923               notethat ("CaCTRL: FLUSHINV [ pregs ]\n");
2924               $$ = CACTRL (&$3, 0, 1);
2925             }
2926           else
2927             return yyerror ("Bad register(s) for FLUSH");
2928         }
2929
2930         | FLUSHINV reg_with_postinc
2931         {
2932           if (IS_PREG ($2))
2933             {
2934               notethat ("CaCTRL: FLUSHINV [ pregs ++ ]\n");
2935               $$ = CACTRL (&$2, 1, 1);
2936             }
2937           else
2938             return yyerror ("Bad register(s) for FLUSH");
2939         }
2940
2941 /* CaCTRL:      IFLUSH [pregs].  */
2942         | IFLUSH LBRACK REG RBRACK
2943         {
2944           if (IS_PREG ($3))
2945             {
2946               notethat ("CaCTRL: IFLUSH [ pregs ]\n");
2947               $$ = CACTRL (&$3, 0, 3);
2948             }
2949           else
2950             return yyerror ("Bad register(s) for FLUSH");
2951         }
2952
2953         | IFLUSH reg_with_postinc
2954         {
2955           if (IS_PREG ($2))
2956             {
2957               notethat ("CaCTRL: IFLUSH [ pregs ++ ]\n");
2958               $$ = CACTRL (&$2, 1, 3);
2959             }
2960           else
2961             return yyerror ("Bad register(s) for FLUSH");
2962         }
2963
2964         | PREFETCH LBRACK REG RBRACK
2965         {
2966           if (IS_PREG ($3))
2967             {
2968               notethat ("CaCTRL: PREFETCH [ pregs ]\n");
2969               $$ = CACTRL (&$3, 0, 0);
2970             }
2971           else
2972             return yyerror ("Bad register(s) for PREFETCH");
2973         }
2974
2975         | PREFETCH reg_with_postinc
2976         {
2977           if (IS_PREG ($2))
2978             {
2979               notethat ("CaCTRL: PREFETCH [ pregs ++ ]\n");
2980               $$ = CACTRL (&$2, 1, 0);
2981             }
2982           else
2983             return yyerror ("Bad register(s) for PREFETCH");
2984         }
2985
2986 /* LOAD/STORE.  */
2987 /* LDST:        B [ pregs <post_op> ] = dregs.  */
2988
2989         | B LBRACK REG post_op RBRACK ASSIGN REG
2990         {
2991           if (!IS_DREG ($7))
2992             return yyerror ("Dreg expected for source operand");
2993           if (!IS_PREG ($3))
2994             return yyerror ("Preg expected in address");
2995
2996           notethat ("LDST: B [ pregs <post_op> ] = dregs\n");
2997           $$ = LDST (&$3, &$7, $4.x0, 2, 0, 1);
2998         }
2999
3000 /* LDSTidxI:    B [ pregs + imm16 ] = dregs.  */
3001         | B LBRACK REG plus_minus expr RBRACK ASSIGN REG
3002         {
3003           Expr_Node *tmp = $5;
3004
3005           if (!IS_DREG ($8))
3006             return yyerror ("Dreg expected for source operand");
3007           if (!IS_PREG ($3))
3008             return yyerror ("Preg expected in address");
3009
3010           if (IS_RELOC ($5))
3011             return yyerror ("Plain symbol used as offset");
3012
3013           if ($4.r0)
3014             tmp = unary (Expr_Op_Type_NEG, tmp);
3015
3016           if (in_range_p (tmp, -32768, 32767, 0))
3017             {
3018               notethat ("LDST: B [ pregs + imm16 ] = dregs\n");
3019               $$ = LDSTIDXI (&$3, &$8, 1, 2, 0, $5);
3020             }
3021           else
3022             return yyerror ("Displacement out of range");
3023         }
3024
3025
3026 /* LDSTii:      W [ pregs + uimm4s2 ] = dregs.  */
3027         | W LBRACK REG plus_minus expr RBRACK ASSIGN REG
3028         {
3029           Expr_Node *tmp = $5;
3030
3031           if (!IS_DREG ($8))
3032             return yyerror ("Dreg expected for source operand");
3033           if (!IS_PREG ($3))
3034             return yyerror ("Preg expected in address");
3035
3036           if ($4.r0)
3037             tmp = unary (Expr_Op_Type_NEG, tmp);
3038
3039           if (IS_RELOC ($5))
3040             return yyerror ("Plain symbol used as offset");
3041
3042           if (in_range_p (tmp, 0, 30, 1))
3043             {
3044               notethat ("LDSTii: W [ pregs +- uimm5m2 ] = dregs\n");
3045               $$ = LDSTII (&$3, &$8, tmp, 1, 1);
3046             }
3047           else if (in_range_p (tmp, -65536, 65535, 1))
3048             {
3049               notethat ("LDSTidxI: W [ pregs + imm17m2 ] = dregs\n");
3050               $$ = LDSTIDXI (&$3, &$8, 1, 1, 0, tmp);
3051             }
3052           else
3053             return yyerror ("Displacement out of range");
3054         }
3055
3056 /* LDST:        W [ pregs <post_op> ] = dregs.  */
3057         | W LBRACK REG post_op RBRACK ASSIGN REG
3058         {
3059           if (!IS_DREG ($7))
3060             return yyerror ("Dreg expected for source operand");
3061           if (!IS_PREG ($3))
3062             return yyerror ("Preg expected in address");
3063
3064           notethat ("LDST: W [ pregs <post_op> ] = dregs\n");
3065           $$ = LDST (&$3, &$7, $4.x0, 1, 0, 1);
3066         }
3067
3068         | W LBRACK REG post_op RBRACK ASSIGN HALF_REG
3069         {
3070           if (!IS_DREG ($7))
3071             return yyerror ("Dreg expected for source operand");
3072           if ($4.x0 == 2)
3073             {
3074               if (!IS_IREG ($3) && !IS_PREG ($3))
3075                 return yyerror ("Ireg or Preg expected in address");
3076             }
3077           else if (!IS_IREG ($3))
3078             return yyerror ("Ireg expected in address");
3079
3080           if (IS_IREG ($3))
3081             {
3082               notethat ("dspLDST: W [ iregs <post_op> ] = dregs_half\n");
3083               $$ = DSPLDST (&$3, 1 + IS_H ($7), &$7, $4.x0, 1);
3084             }
3085           else
3086             {
3087               notethat ("LDSTpmod: W [ pregs ] = dregs_half\n");
3088               $$ = LDSTPMOD (&$3, &$7, &$3, 1 + IS_H ($7), 1);
3089             }
3090         }
3091
3092 /* LDSTiiFP:    [ FP - const ] = dpregs.  */
3093         | LBRACK REG plus_minus expr RBRACK ASSIGN REG
3094         {
3095           Expr_Node *tmp = $4;
3096           int ispreg = IS_PREG ($7);
3097
3098           if (!IS_PREG ($2))
3099             return yyerror ("Preg expected in address");
3100
3101           if (!IS_DREG ($7) && !ispreg)
3102             return yyerror ("Preg expected for source operand");
3103
3104           if ($3.r0)
3105             tmp = unary (Expr_Op_Type_NEG, tmp);
3106
3107           if (IS_RELOC ($4))
3108             return yyerror ("Plain symbol used as offset");
3109
3110           if (in_range_p (tmp, 0, 63, 3))
3111             {
3112               notethat ("LDSTii: dpregs = [ pregs + uimm6m4 ]\n");
3113               $$ = LDSTII (&$2, &$7, tmp, 1, ispreg ? 3 : 0);
3114             }
3115           else if ($2.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
3116             {
3117               notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
3118               tmp = unary (Expr_Op_Type_NEG, tmp);
3119               $$ = LDSTIIFP (tmp, &$7, 1);
3120             }
3121           else if (in_range_p (tmp, -131072, 131071, 3))
3122             {
3123               notethat ("LDSTidxI: [ pregs + imm18m4 ] = dpregs\n");
3124               $$ = LDSTIDXI (&$2, &$7, 1, 0, ispreg ? 1 : 0, tmp);
3125             }
3126           else
3127             return yyerror ("Displacement out of range");
3128         }
3129
3130         | REG ASSIGN W LBRACK REG plus_minus expr RBRACK xpmod
3131         {
3132           Expr_Node *tmp = $7;
3133           if (!IS_DREG ($1))
3134             return yyerror ("Dreg expected for destination operand");
3135           if (!IS_PREG ($5))
3136             return yyerror ("Preg expected in address");
3137
3138           if ($6.r0)
3139             tmp = unary (Expr_Op_Type_NEG, tmp);
3140
3141           if (IS_RELOC ($7))
3142             return yyerror ("Plain symbol used as offset");
3143
3144           if (in_range_p (tmp, 0, 30, 1))
3145             {
3146               notethat ("LDSTii: dregs = W [ pregs + uimm5m2 ] (.)\n");
3147               $$ = LDSTII (&$5, &$1, tmp, 0, 1 << $9.r0);
3148             }
3149           else if (in_range_p (tmp, -65536, 65535, 1))
3150             {
3151               notethat ("LDSTidxI: dregs = W [ pregs + imm17m2 ] (.)\n");
3152               $$ = LDSTIDXI (&$5, &$1, 0, 1, $9.r0, tmp);
3153             }
3154           else
3155             return yyerror ("Displacement out of range");
3156         }
3157
3158         | HALF_REG ASSIGN W LBRACK REG post_op RBRACK
3159         {
3160           if (!IS_DREG ($1))
3161             return yyerror ("Dreg expected for source operand");
3162           if ($6.x0 == 2)
3163             {
3164               if (!IS_IREG ($5) && !IS_PREG ($5))
3165                 return yyerror ("Ireg or Preg expected in address");
3166             }
3167           else if (!IS_IREG ($5))
3168             return yyerror ("Ireg expected in address");
3169
3170           if (IS_IREG ($5))
3171             {
3172               notethat ("dspLDST: dregs_half = W [ iregs <post_op> ]\n");
3173               $$ = DSPLDST(&$5, 1 + IS_H ($1), &$1, $6.x0, 0);
3174             }
3175           else
3176             {
3177               notethat ("LDSTpmod: dregs_half = W [ pregs <post_op> ]\n");
3178               $$ = LDSTPMOD (&$5, &$1, &$5, 1 + IS_H ($1), 0);
3179             }
3180         }
3181
3182
3183         | REG ASSIGN W LBRACK REG post_op RBRACK xpmod
3184         {
3185           if (!IS_DREG ($1))
3186             return yyerror ("Dreg expected for destination operand");
3187           if (!IS_PREG ($5))
3188             return yyerror ("Preg expected in address");
3189
3190           notethat ("LDST: dregs = W [ pregs <post_op> ] (.)\n");
3191           $$ = LDST (&$5, &$1, $6.x0, 1, $8.r0, 0);
3192         }
3193
3194         | REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK xpmod
3195         {
3196           if (!IS_DREG ($1))
3197             return yyerror ("Dreg expected for destination operand");
3198           if (!IS_PREG ($5) || !IS_PREG ($7))
3199             return yyerror ("Preg expected in address");
3200
3201           notethat ("LDSTpmod: dregs = W [ pregs ++ pregs ] (.)\n");
3202           $$ = LDSTPMOD (&$5, &$1, &$7, 3, $9.r0);
3203         }
3204
3205         | HALF_REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK
3206         {
3207           if (!IS_DREG ($1))
3208             return yyerror ("Dreg expected for destination operand");
3209           if (!IS_PREG ($5) || !IS_PREG ($7))
3210             return yyerror ("Preg expected in address");
3211
3212           notethat ("LDSTpmod: dregs_half = W [ pregs ++ pregs ]\n");
3213           $$ = LDSTPMOD (&$5, &$1, &$7, 1 + IS_H ($1), 0);
3214         }
3215
3216         | LBRACK REG post_op RBRACK ASSIGN REG
3217         {
3218           if (!IS_IREG ($2) && !IS_PREG ($2))
3219             return yyerror ("Ireg or Preg expected in address");
3220           else if (IS_IREG ($2) && !IS_DREG ($6))
3221             return yyerror ("Dreg expected for source operand");
3222           else if (IS_PREG ($2) && !IS_DREG ($6) && !IS_PREG ($6))
3223             return yyerror ("Dreg or Preg expected for source operand");
3224
3225           if (IS_IREG ($2))
3226             {
3227               notethat ("dspLDST: [ iregs <post_op> ] = dregs\n");
3228               $$ = DSPLDST(&$2, 0, &$6, $3.x0, 1);
3229             }
3230           else if (IS_DREG ($6))
3231             {
3232               notethat ("LDST: [ pregs <post_op> ] = dregs\n");
3233               $$ = LDST (&$2, &$6, $3.x0, 0, 0, 1);
3234             }
3235           else
3236             {
3237               notethat ("LDST: [ pregs <post_op> ] = pregs\n");
3238               $$ = LDST (&$2, &$6, $3.x0, 0, 1, 1);
3239             }
3240         }
3241
3242         | LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN REG
3243         {
3244           if (!IS_DREG ($7))
3245             return yyerror ("Dreg expected for source operand");
3246
3247           if (IS_IREG ($2) && IS_MREG ($4))
3248             {
3249               notethat ("dspLDST: [ iregs ++ mregs ] = dregs\n");
3250               $$ = DSPLDST(&$2, $4.regno & CODE_MASK, &$7, 3, 1);
3251             }
3252           else if (IS_PREG ($2) && IS_PREG ($4))
3253             {
3254               notethat ("LDSTpmod: [ pregs ++ pregs ] = dregs\n");
3255               $$ = LDSTPMOD (&$2, &$7, &$4, 0, 1);
3256             }
3257           else
3258             return yyerror ("Preg ++ Preg or Ireg ++ Mreg expected in address");
3259         }
3260
3261         | W LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN HALF_REG
3262         {
3263           if (!IS_DREG ($8))
3264             return yyerror ("Dreg expected for source operand");
3265
3266           if (IS_PREG ($3) && IS_PREG ($5))
3267             {
3268               notethat ("LDSTpmod: W [ pregs ++ pregs ] = dregs_half\n");
3269               $$ = LDSTPMOD (&$3, &$8, &$5, 1 + IS_H ($8), 1);
3270             }
3271           else
3272             return yyerror ("Preg ++ Preg expected in address");
3273         }
3274
3275         | REG ASSIGN B LBRACK REG plus_minus expr RBRACK xpmod
3276         {
3277           Expr_Node *tmp = $7;
3278           if (!IS_DREG ($1))
3279             return yyerror ("Dreg expected for destination operand");
3280           if (!IS_PREG ($5))
3281             return yyerror ("Preg expected in address");
3282
3283           if ($6.r0)
3284             tmp = unary (Expr_Op_Type_NEG, tmp);
3285
3286           if (IS_RELOC ($7))
3287             return yyerror ("Plain symbol used as offset");
3288
3289           if (in_range_p (tmp, -32768, 32767, 0))
3290             {
3291               notethat ("LDSTidxI: dregs = B [ pregs + imm16 ] (%c)\n",
3292                        $9.r0 ? 'X' : 'Z');
3293               $$ = LDSTIDXI (&$5, &$1, 0, 2, $9.r0, tmp);
3294             }
3295           else
3296             return yyerror ("Displacement out of range");
3297         }
3298
3299         | REG ASSIGN B LBRACK REG post_op RBRACK xpmod
3300         {
3301           if (!IS_DREG ($1))
3302             return yyerror ("Dreg expected for destination operand");
3303           if (!IS_PREG ($5))
3304             return yyerror ("Preg expected in address");
3305
3306           notethat ("LDST: dregs = B [ pregs <post_op> ] (%c)\n",
3307                     $8.r0 ? 'X' : 'Z');
3308           $$ = LDST (&$5, &$1, $6.x0, 2, $8.r0, 0);
3309         }
3310
3311         | REG ASSIGN LBRACK REG _PLUS_PLUS REG RBRACK
3312         {
3313           if (!IS_DREG ($1))
3314             return yyerror ("Dreg expected for destination operand");
3315
3316           if (IS_IREG ($4) && IS_MREG ($6))
3317             {
3318               notethat ("dspLDST: dregs = [ iregs ++ mregs ]\n");
3319               $$ = DSPLDST(&$4, $6.regno & CODE_MASK, &$1, 3, 0);
3320             }
3321           else if (IS_PREG ($4) && IS_PREG ($6))
3322             {
3323               notethat ("LDSTpmod: dregs = [ pregs ++ pregs ]\n");
3324               $$ = LDSTPMOD (&$4, &$1, &$6, 0, 0);
3325             }
3326           else
3327             return yyerror ("Preg ++ Preg or Ireg ++ Mreg expected in address");
3328         }
3329
3330         | REG ASSIGN LBRACK REG plus_minus got_or_expr RBRACK
3331         {
3332           Expr_Node *tmp = $6;
3333           int ispreg = IS_PREG ($1);
3334           int isgot = IS_RELOC($6);
3335
3336           if (!IS_PREG ($4))
3337             return yyerror ("Preg expected in address");
3338
3339           if (!IS_DREG ($1) && !ispreg)
3340             return yyerror ("Dreg or Preg expected for destination operand");
3341
3342           if (tmp->type == Expr_Node_Reloc
3343               && strcmp (tmp->value.s_value,
3344                          "_current_shared_library_p5_offset_") != 0)
3345             return yyerror ("Plain symbol used as offset");
3346
3347           if ($5.r0)
3348             tmp = unary (Expr_Op_Type_NEG, tmp);
3349
3350           if (isgot)
3351             {
3352               notethat ("LDSTidxI: dpregs = [ pregs + sym@got ]\n");
3353               $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1 : 0, tmp);
3354             }
3355           else if (in_range_p (tmp, 0, 63, 3))
3356             {
3357               notethat ("LDSTii: dpregs = [ pregs + uimm7m4 ]\n");
3358               $$ = LDSTII (&$4, &$1, tmp, 0, ispreg ? 3 : 0);
3359             }
3360           else if ($4.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
3361             {
3362               notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
3363               tmp = unary (Expr_Op_Type_NEG, tmp);
3364               $$ = LDSTIIFP (tmp, &$1, 0);
3365             }
3366           else if (in_range_p (tmp, -131072, 131071, 3))
3367             {
3368               notethat ("LDSTidxI: dpregs = [ pregs + imm18m4 ]\n");
3369               $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1 : 0, tmp);
3370
3371             }
3372           else
3373             return yyerror ("Displacement out of range");
3374         }
3375
3376         | REG ASSIGN LBRACK REG post_op RBRACK
3377         {
3378           if (!IS_IREG ($4) && !IS_PREG ($4))
3379             return yyerror ("Ireg or Preg expected in address");
3380           else if (IS_IREG ($4) && !IS_DREG ($1))
3381             return yyerror ("Dreg expected in destination operand");
3382           else if (IS_PREG ($4) && !IS_DREG ($1) && !IS_PREG ($1)
3383                    && ($4.regno != REG_SP || !IS_ALLREG ($1) || $5.x0 != 0))
3384             return yyerror ("Dreg or Preg expected in destination operand");
3385
3386           if (IS_IREG ($4))
3387             {
3388               notethat ("dspLDST: dregs = [ iregs <post_op> ]\n");
3389               $$ = DSPLDST (&$4, 0, &$1, $5.x0, 0);
3390             }
3391           else if (IS_DREG ($1))
3392             {
3393               notethat ("LDST: dregs = [ pregs <post_op> ]\n");
3394               $$ = LDST (&$4, &$1, $5.x0, 0, 0, 0);
3395             }
3396           else if (IS_PREG ($1))
3397             {
3398               if (REG_SAME ($1, $4) && $5.x0 != 2)
3399                 return yyerror ("Pregs can't be same");
3400
3401               notethat ("LDST: pregs = [ pregs <post_op> ]\n");
3402               $$ = LDST (&$4, &$1, $5.x0, 0, 1, 0);
3403             }
3404           else
3405             {
3406               notethat ("PushPopReg: allregs = [ SP ++ ]\n");
3407               $$ = PUSHPOPREG (&$1, 0);
3408             }
3409         }
3410
3411
3412 /*  PushPopMultiple.  */
3413         | reg_with_predec ASSIGN LPAREN REG COLON expr COMMA REG COLON expr RPAREN
3414         {
3415           if ($1.regno != REG_SP)
3416             yyerror ("Stack Pointer expected");
3417           if ($4.regno == REG_R7
3418               && IN_RANGE ($6, 0, 7)
3419               && $8.regno == REG_P5
3420               && IN_RANGE ($10, 0, 5))
3421             {
3422               notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim , P5 : reglim )\n");
3423               $$ = PUSHPOPMULTIPLE (imm5 ($6), imm5 ($10), 1, 1, 1);
3424             }
3425           else
3426             return yyerror ("Bad register for PushPopMultiple");
3427         }
3428
3429         | reg_with_predec ASSIGN LPAREN REG COLON expr RPAREN
3430         {
3431           if ($1.regno != REG_SP)
3432             yyerror ("Stack Pointer expected");
3433
3434           if ($4.regno == REG_R7 && IN_RANGE ($6, 0, 7))
3435             {
3436               notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim )\n");
3437               $$ = PUSHPOPMULTIPLE (imm5 ($6), 0, 1, 0, 1);
3438             }
3439           else if ($4.regno == REG_P5 && IN_RANGE ($6, 0, 6))
3440             {
3441               notethat ("PushPopMultiple: [ -- SP ] = (P5 : reglim )\n");
3442               $$ = PUSHPOPMULTIPLE (0, imm5 ($6), 0, 1, 1);
3443             }
3444           else
3445             return yyerror ("Bad register for PushPopMultiple");
3446         }
3447
3448         | LPAREN REG COLON expr COMMA REG COLON expr RPAREN ASSIGN reg_with_postinc
3449         {
3450           if ($11.regno != REG_SP)
3451             yyerror ("Stack Pointer expected");
3452           if ($2.regno == REG_R7 && (IN_RANGE ($4, 0, 7))
3453               && $6.regno == REG_P5 && (IN_RANGE ($8, 0, 6)))
3454             {
3455               notethat ("PushPopMultiple: (R7 : reglim , P5 : reglim ) = [ SP ++ ]\n");
3456               $$ = PUSHPOPMULTIPLE (imm5 ($4), imm5 ($8), 1, 1, 0);
3457             }
3458           else
3459             return yyerror ("Bad register range for PushPopMultiple");
3460         }
3461
3462         | LPAREN REG COLON expr RPAREN ASSIGN reg_with_postinc
3463         {
3464           if ($7.regno != REG_SP)
3465             yyerror ("Stack Pointer expected");
3466
3467           if ($2.regno == REG_R7 && IN_RANGE ($4, 0, 7))
3468             {
3469               notethat ("PushPopMultiple: (R7 : reglim ) = [ SP ++ ]\n");
3470               $$ = PUSHPOPMULTIPLE (imm5 ($4), 0, 1, 0, 0);
3471             }
3472           else if ($2.regno == REG_P5 && IN_RANGE ($4, 0, 6))
3473             {
3474               notethat ("PushPopMultiple: (P5 : reglim ) = [ SP ++ ]\n");
3475               $$ = PUSHPOPMULTIPLE (0, imm5 ($4), 0, 1, 0);
3476             }
3477           else
3478             return yyerror ("Bad register range for PushPopMultiple");
3479         }
3480
3481         | reg_with_predec ASSIGN REG
3482         {
3483           if ($1.regno != REG_SP)
3484             yyerror ("Stack Pointer expected");
3485
3486           if (IS_ALLREG ($3))
3487             {
3488               notethat ("PushPopReg: [ -- SP ] = allregs\n");
3489               $$ = PUSHPOPREG (&$3, 1);
3490             }
3491           else
3492             return yyerror ("Bad register for PushPopReg");
3493         }
3494
3495 /* Linkage.  */
3496
3497         | LINK expr
3498         {
3499           if (IS_URANGE (16, $2, 0, 4))
3500             $$ = LINKAGE (0, uimm16s4 ($2));
3501           else
3502             return yyerror ("Bad constant for LINK");
3503         }
3504
3505         | UNLINK
3506         {
3507                 notethat ("linkage: UNLINK\n");
3508                 $$ = LINKAGE (1, 0);
3509         }
3510
3511
3512 /* LSETUP.  */
3513
3514         | LSETUP LPAREN expr COMMA expr RPAREN REG
3515         {
3516           if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5) && IS_CREG ($7))
3517             {
3518               notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters\n");
3519               $$ = LOOPSETUP ($3, &$7, 0, $5, 0);
3520             }
3521           else
3522             return yyerror ("Bad register or values for LSETUP");
3523
3524         }
3525         | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG
3526         {
3527           if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
3528               && IS_PREG ($9) && IS_CREG ($7))
3529             {
3530               notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs\n");
3531               $$ = LOOPSETUP ($3, &$7, 1, $5, &$9);
3532             }
3533           else
3534             return yyerror ("Bad register or values for LSETUP");
3535         }
3536
3537         | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG GREATER_GREATER expr
3538         {
3539           if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
3540               && IS_PREG ($9) && IS_CREG ($7)
3541               && EXPR_VALUE ($11) == 1)
3542             {
3543               notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs >> 1\n");
3544               $$ = LOOPSETUP ($3, &$7, 3, $5, &$9);
3545             }
3546           else
3547             return yyerror ("Bad register or values for LSETUP");
3548         }
3549
3550 /* LOOP.  */
3551         | LOOP expr REG
3552         {
3553           if (!IS_RELOC ($2))
3554             return yyerror ("Invalid expression in loop statement");
3555           if (!IS_CREG ($3))
3556             return yyerror ("Invalid loop counter register");
3557         $$ = bfin_gen_loop ($2, &$3, 0, 0);
3558         }
3559         | LOOP expr REG ASSIGN REG
3560         {
3561           if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3))
3562             {
3563               notethat ("Loop: LOOP expr counters = pregs\n");
3564               $$ = bfin_gen_loop ($2, &$3, 1, &$5);
3565             }
3566           else
3567             return yyerror ("Bad register or values for LOOP");
3568         }
3569         | LOOP expr REG ASSIGN REG GREATER_GREATER expr
3570         {
3571           if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3) && EXPR_VALUE ($7) == 1)
3572             {
3573               notethat ("Loop: LOOP expr counters = pregs >> 1\n");
3574               $$ = bfin_gen_loop ($2, &$3, 3, &$5);
3575             }
3576           else
3577             return yyerror ("Bad register or values for LOOP");
3578         }
3579
3580 /* LOOP_BEGIN.  */
3581         | LOOP_BEGIN NUMBER
3582         {
3583           Expr_Node_Value val;
3584           val.i_value = $2;
3585           Expr_Node *tmp = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
3586           bfin_loop_attempt_create_label (tmp, 1);
3587           if (!IS_RELOC (tmp))
3588             return yyerror ("Invalid expression in LOOP_BEGIN statement");
3589           bfin_loop_beginend (tmp, 1);
3590           $$ = 0;
3591         }
3592         | LOOP_BEGIN expr
3593         {
3594           if (!IS_RELOC ($2))
3595             return yyerror ("Invalid expression in LOOP_BEGIN statement");
3596
3597           bfin_loop_beginend ($2, 1);
3598           $$ = 0;
3599         }
3600
3601 /* LOOP_END.  */
3602         | LOOP_END NUMBER
3603         {
3604           Expr_Node_Value val;
3605           val.i_value = $2;
3606           Expr_Node *tmp = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
3607           bfin_loop_attempt_create_label (tmp, 1);
3608           if (!IS_RELOC (tmp))
3609             return yyerror ("Invalid expression in LOOP_END statement");
3610           bfin_loop_beginend (tmp, 0);
3611           $$ = 0;
3612         }
3613         | LOOP_END expr
3614         {
3615           if (!IS_RELOC ($2))
3616             return yyerror ("Invalid expression in LOOP_END statement");
3617
3618           bfin_loop_beginend ($2, 0);
3619           $$ = 0;
3620         }
3621
3622 /* pseudoDEBUG.  */
3623
3624         | ABORT
3625         {
3626           notethat ("psedoDEBUG: ABORT\n");
3627           $$ = bfin_gen_pseudodbg (3, 3, 0);
3628         }
3629
3630         | DBG
3631         {
3632           notethat ("pseudoDEBUG: DBG\n");
3633           $$ = bfin_gen_pseudodbg (3, 7, 0);
3634         }
3635         | DBG REG_A
3636         {
3637           notethat ("pseudoDEBUG: DBG REG_A\n");
3638           $$ = bfin_gen_pseudodbg (3, IS_A1 ($2), 0);
3639         }
3640         | DBG REG
3641         {
3642           notethat ("pseudoDEBUG: DBG allregs\n");
3643           $$ = bfin_gen_pseudodbg (0, $2.regno & CODE_MASK, ($2.regno & CLASS_MASK) >> 4);
3644         }
3645
3646         | DBGCMPLX LPAREN REG RPAREN
3647         {
3648           if (!IS_DREG ($3))
3649             return yyerror ("Dregs expected");
3650           notethat ("pseudoDEBUG: DBGCMPLX (dregs )\n");
3651           $$ = bfin_gen_pseudodbg (3, 6, ($3.regno & CODE_MASK) >> 4);
3652         }
3653
3654         | DBGHALT
3655         {
3656           notethat ("psedoDEBUG: DBGHALT\n");
3657           $$ = bfin_gen_pseudodbg (3, 5, 0);
3658         }
3659
3660         | HLT
3661         {
3662           notethat ("psedoDEBUG: HLT\n");
3663           $$ = bfin_gen_pseudodbg (3, 4, 0);
3664         }
3665
3666         | DBGA LPAREN HALF_REG COMMA expr RPAREN
3667         {
3668           notethat ("pseudodbg_assert: DBGA (regs_lo/hi , uimm16 )\n");
3669           $$ = bfin_gen_pseudodbg_assert (IS_H ($3), &$3, uimm16 ($5));
3670         }
3671
3672         | DBGAH LPAREN REG COMMA expr RPAREN
3673         {
3674           notethat ("pseudodbg_assert: DBGAH (regs , uimm16 )\n");
3675           $$ = bfin_gen_pseudodbg_assert (3, &$3, uimm16 ($5));
3676         }
3677
3678         | DBGAL LPAREN REG COMMA expr RPAREN
3679         {
3680           notethat ("psedodbg_assert: DBGAL (regs , uimm16 )\n");
3681           $$ = bfin_gen_pseudodbg_assert (2, &$3, uimm16 ($5));
3682         }
3683
3684         | OUTC expr
3685         {
3686           if (!IS_UIMM ($2, 8))
3687             return yyerror ("Constant out of range");
3688           notethat ("psedodbg_assert: OUTC uimm8\n");
3689           $$ = bfin_gen_pseudochr (uimm8 ($2));
3690         }
3691
3692         | OUTC REG
3693         {
3694           if (!IS_DREG ($2))
3695             return yyerror ("Dregs expected");
3696           notethat ("psedodbg_assert: OUTC dreg\n");
3697           $$ = bfin_gen_pseudodbg (2, $2.regno & CODE_MASK, 0);
3698         }
3699
3700 ;
3701
3702 /*  AUX RULES.  */
3703
3704 /*  Register rules.  */
3705
3706 REG_A:  REG_A_DOUBLE_ZERO
3707         {
3708         $$ = $1;
3709         }
3710         | REG_A_DOUBLE_ONE
3711         {
3712         $$ = $1;
3713         }
3714         ;
3715
3716
3717 /*  Modifiers. */
3718
3719 opt_mode:
3720         {
3721         $$.MM = 0;
3722         $$.mod = 0;
3723         }
3724         | LPAREN M COMMA MMOD RPAREN
3725         {
3726         $$.MM = 1;
3727         $$.mod = $4;
3728         }
3729         | LPAREN MMOD COMMA M RPAREN
3730         {
3731         $$.MM = 1;
3732         $$.mod = $2;
3733         }
3734         | LPAREN MMOD RPAREN
3735         {
3736         $$.MM = 0;
3737         $$.mod = $2;
3738         }
3739         | LPAREN M RPAREN
3740         {
3741         $$.MM = 1;
3742         $$.mod = 0;
3743         }
3744         ;
3745
3746 asr_asl: LPAREN ASL RPAREN
3747         {
3748         $$.r0 = 1;
3749         }
3750         | LPAREN ASR RPAREN
3751         {
3752         $$.r0 = 0;
3753         }
3754         ;
3755
3756 sco:
3757         {
3758         $$.s0 = 0;
3759         $$.x0 = 0;
3760         }
3761         | S
3762         {
3763         $$.s0 = 1;
3764         $$.x0 = 0;
3765         }
3766         | CO
3767         {
3768         $$.s0 = 0;
3769         $$.x0 = 1;
3770         }
3771         | SCO
3772         {
3773         $$.s0 = 1;
3774         $$.x0 = 1;
3775         }
3776         ;
3777
3778 asr_asl_0:
3779         ASL
3780         {
3781         $$.r0 = 1;
3782         }
3783         | ASR
3784         {
3785         $$.r0 = 0;
3786         }
3787         ;
3788
3789 amod0:
3790         {
3791         $$.s0 = 0;
3792         $$.x0 = 0;
3793         }
3794         | LPAREN sco RPAREN
3795         {
3796         $$.s0 = $2.s0;
3797         $$.x0 = $2.x0;
3798         }
3799         ;
3800
3801 amod1:
3802         {
3803         $$.s0 = 0;
3804         $$.x0 = 0;
3805         $$.aop = 0;
3806         }
3807         | LPAREN NS RPAREN
3808         {
3809         $$.s0 = 0;
3810         $$.x0 = 0;
3811         $$.aop = 1;
3812         }
3813         | LPAREN S RPAREN
3814         {
3815         $$.s0 = 1;
3816         $$.x0 = 0;
3817         $$.aop = 1;
3818         }
3819         ;
3820
3821 amod2:
3822         {
3823         $$.r0 = 0;
3824         $$.s0 = 0;
3825         $$.x0 = 0;
3826         }
3827         | LPAREN asr_asl_0 RPAREN
3828         {
3829         $$.r0 = 2 + $2.r0;
3830         $$.s0 = 0;
3831         $$.x0 = 0;
3832         }
3833         | LPAREN sco RPAREN
3834         {
3835         $$.r0 = 0;
3836         $$.s0 = $2.s0;
3837         $$.x0 = $2.x0;
3838         }
3839         | LPAREN asr_asl_0 COMMA sco RPAREN
3840         {
3841         $$.r0 = 2 + $2.r0;
3842         $$.s0 = $4.s0;
3843         $$.x0 = $4.x0;
3844         }
3845         | LPAREN sco COMMA asr_asl_0 RPAREN
3846         {
3847         $$.r0 = 2 + $4.r0;
3848         $$.s0 = $2.s0;
3849         $$.x0 = $2.x0;
3850         }
3851         ;
3852
3853 xpmod:
3854         {
3855         $$.r0 = 0;
3856         }
3857         | LPAREN Z RPAREN
3858         {
3859         $$.r0 = 0;
3860         }
3861         | LPAREN X RPAREN
3862         {
3863         $$.r0 = 1;
3864         }
3865         ;
3866
3867 xpmod1:
3868         {
3869         $$.r0 = 0;
3870         }
3871         | LPAREN X RPAREN
3872         {
3873         $$.r0 = 0;
3874         }
3875         | LPAREN Z RPAREN
3876         {
3877         $$.r0 = 1;
3878         }
3879         ;
3880
3881 vsmod:
3882         {
3883         $$.r0 = 0;
3884         $$.s0 = 0;
3885         $$.aop = 0;
3886         }
3887         | LPAREN NS RPAREN
3888         {
3889         $$.r0 = 0;
3890         $$.s0 = 0;
3891         $$.aop = 3;
3892         }
3893         | LPAREN S RPAREN
3894         {
3895         $$.r0 = 0;
3896         $$.s0 = 1;
3897         $$.aop = 3;
3898         }
3899         | LPAREN V RPAREN
3900         {
3901         $$.r0 = 1;
3902         $$.s0 = 0;
3903         $$.aop = 3;
3904         }
3905         | LPAREN V COMMA S RPAREN
3906         {
3907         $$.r0 = 1;
3908         $$.s0 = 1;
3909         }
3910         | LPAREN S COMMA V RPAREN
3911         {
3912         $$.r0 = 1;
3913         $$.s0 = 1;
3914         }
3915         ;
3916
3917 vmod:
3918         {
3919         $$.r0 = 0;
3920         }
3921         | LPAREN V RPAREN
3922         {
3923         $$.r0 = 1;
3924         }
3925         ;
3926
3927 smod:
3928         {
3929         $$.s0 = 0;
3930         }
3931         | LPAREN S RPAREN
3932         {
3933         $$.s0 = 1;
3934         }
3935         ;
3936
3937 searchmod:
3938           GE
3939         {
3940         $$.r0 = 1;
3941         }
3942         | GT
3943         {
3944         $$.r0 = 0;
3945         }
3946         | LE
3947         {
3948         $$.r0 = 3;
3949         }
3950         | LT
3951         {
3952         $$.r0 = 2;
3953         }
3954         ;
3955
3956 aligndir:
3957         {
3958         $$.r0 = 0;
3959         }
3960         | LPAREN R RPAREN
3961         {
3962         $$.r0 = 1;
3963         }
3964         ;
3965
3966 byteop_mod:
3967         LPAREN R RPAREN
3968         {
3969         $$.r0 = 0;
3970         $$.s0 = 1;
3971         }
3972         | LPAREN MMOD RPAREN
3973         {
3974         if ($2 != M_T)
3975           return yyerror ("Bad modifier");
3976         $$.r0 = 1;
3977         $$.s0 = 0;
3978         }
3979         | LPAREN MMOD COMMA R RPAREN
3980         {
3981         if ($2 != M_T)
3982           return yyerror ("Bad modifier");
3983         $$.r0 = 1;
3984         $$.s0 = 1;
3985         }
3986         | LPAREN R COMMA MMOD RPAREN
3987         {
3988         if ($4 != M_T)
3989           return yyerror ("Bad modifier");
3990         $$.r0 = 1;
3991         $$.s0 = 1;
3992         }
3993         ;
3994
3995
3996
3997 c_align:
3998         ALIGN8
3999         {
4000         $$.r0 = 0;
4001         }
4002         | ALIGN16
4003         {
4004         $$.r0 = 1;
4005         }
4006         | ALIGN24
4007         {
4008         $$.r0 = 2;
4009         }
4010         ;
4011
4012 w32_or_nothing:
4013         {
4014         $$.r0 = 0;
4015         }
4016         | LPAREN MMOD RPAREN
4017         {
4018           if ($2 == M_W32)
4019             $$.r0 = 1;
4020           else
4021             return yyerror ("Only (W32) allowed");
4022         }
4023         ;
4024
4025 iu_or_nothing:
4026         {
4027         $$.r0 = 1;
4028         }
4029         | LPAREN MMOD RPAREN
4030         {
4031           if ($2 == M_IU)
4032             $$.r0 = 3;
4033           else
4034             return yyerror ("(IU) expected");
4035         }
4036         ;
4037
4038 reg_with_predec: LBRACK _MINUS_MINUS REG RBRACK
4039         {
4040         $$ = $3;
4041         }
4042         ;
4043
4044 reg_with_postinc: LBRACK REG _PLUS_PLUS RBRACK
4045         {
4046         $$ = $2;
4047         }
4048         ;
4049
4050 /* Operators.  */
4051
4052 min_max:
4053         MIN
4054         {
4055         $$.r0 = 1;
4056         }
4057         | MAX
4058         {
4059         $$.r0 = 0;
4060         }
4061         ;
4062
4063 op_bar_op:
4064         _PLUS_BAR_PLUS
4065         {
4066         $$.r0 = 0;
4067         }
4068         | _PLUS_BAR_MINUS
4069         {
4070         $$.r0 = 1;
4071         }
4072         | _MINUS_BAR_PLUS
4073         {
4074         $$.r0 = 2;
4075         }
4076         | _MINUS_BAR_MINUS
4077         {
4078         $$.r0 = 3;
4079         }
4080         ;
4081
4082 plus_minus:
4083         PLUS
4084         {
4085         $$.r0 = 0;
4086         }
4087         | MINUS
4088         {
4089         $$.r0 = 1;
4090         }
4091         ;
4092
4093 rnd_op:
4094         LPAREN RNDH RPAREN
4095         {
4096           $$.r0 = 1;    /* HL.  */
4097           $$.s0 = 0;    /* s.  */
4098           $$.x0 = 0;    /* x.  */
4099           $$.aop = 0;   /* aop.  */
4100         }
4101
4102         | LPAREN TH RPAREN
4103         {
4104           $$.r0 = 1;    /* HL.  */
4105           $$.s0 = 0;    /* s.  */
4106           $$.x0 = 0;    /* x.  */
4107           $$.aop = 1;   /* aop.  */
4108         }
4109
4110         | LPAREN RNDL RPAREN
4111         {
4112           $$.r0 = 0;    /* HL.  */
4113           $$.s0 = 0;    /* s.  */
4114           $$.x0 = 0;    /* x.  */
4115           $$.aop = 0;   /* aop.  */
4116         }
4117
4118         | LPAREN TL RPAREN
4119         {
4120           $$.r0 = 0;    /* HL.  */
4121           $$.s0 = 0;    /* s.  */
4122           $$.x0 = 0;    /* x.  */
4123           $$.aop = 1;
4124         }
4125
4126         | LPAREN RNDH COMMA R RPAREN
4127         {
4128           $$.r0 = 1;    /* HL.  */
4129           $$.s0 = 1;    /* s.  */
4130           $$.x0 = 0;    /* x.  */
4131           $$.aop = 0;   /* aop.  */
4132         }
4133         | LPAREN TH COMMA R RPAREN
4134         {
4135           $$.r0 = 1;    /* HL.  */
4136           $$.s0 = 1;    /* s.  */
4137           $$.x0 = 0;    /* x.  */
4138           $$.aop = 1;   /* aop.  */
4139         }
4140         | LPAREN RNDL COMMA R RPAREN
4141         {
4142           $$.r0 = 0;    /* HL.  */
4143           $$.s0 = 1;    /* s.  */
4144           $$.x0 = 0;    /* x.  */
4145           $$.aop = 0;   /* aop.  */
4146         }
4147
4148         | LPAREN TL COMMA R RPAREN
4149         {
4150           $$.r0 = 0;    /* HL.  */
4151           $$.s0 = 1;    /* s.  */
4152           $$.x0 = 0;    /* x.  */
4153           $$.aop = 1;   /* aop.  */
4154         }
4155         ;
4156
4157 b3_op:
4158         LPAREN LO RPAREN
4159         {
4160           $$.s0 = 0;    /* s.  */
4161           $$.x0 = 0;    /* HL.  */
4162         }
4163         | LPAREN HI RPAREN
4164         {
4165           $$.s0 = 0;    /* s.  */
4166           $$.x0 = 1;    /* HL.  */
4167         }
4168         | LPAREN LO COMMA R RPAREN
4169         {
4170           $$.s0 = 1;    /* s.  */
4171           $$.x0 = 0;    /* HL.  */
4172         }
4173         | LPAREN HI COMMA R RPAREN
4174         {
4175           $$.s0 = 1;    /* s.  */
4176           $$.x0 = 1;    /* HL.  */
4177         }
4178         ;
4179
4180 post_op:
4181         {
4182         $$.x0 = 2;
4183         }
4184         | _PLUS_PLUS
4185         {
4186         $$.x0 = 0;
4187         }
4188         | _MINUS_MINUS
4189         {
4190         $$.x0 = 1;
4191         }
4192         ;
4193
4194 /* Assignments, Macfuncs.  */
4195
4196 a_assign:
4197         REG_A ASSIGN
4198         {
4199         $$ = $1;
4200         }
4201         ;
4202
4203 a_minusassign:
4204         REG_A _MINUS_ASSIGN
4205         {
4206         $$ = $1;
4207         }
4208         ;
4209
4210 a_plusassign:
4211         REG_A _PLUS_ASSIGN
4212         {
4213         $$ = $1;
4214         }
4215         ;
4216
4217 assign_macfunc:
4218         REG ASSIGN REG_A
4219         {
4220           if (IS_A1 ($3) && IS_EVEN ($1))
4221             return yyerror ("Cannot move A1 to even register");
4222           else if (!IS_A1 ($3) && !IS_EVEN ($1))
4223             return yyerror ("Cannot move A0 to odd register");
4224
4225           $$.w = 1;
4226           $$.P = 1;
4227           $$.n = IS_A1 ($3);
4228           $$.op = 3;
4229           $$.dst = $1;
4230           $$.s0.regno = 0;
4231           $$.s1.regno = 0;
4232         }
4233         | a_macfunc
4234         {
4235           $$ = $1;
4236           $$.w = 0; $$.P = 0;
4237           $$.dst.regno = 0;
4238         }
4239         | REG ASSIGN LPAREN a_macfunc RPAREN
4240         {
4241           if ($4.n && IS_EVEN ($1))
4242             return yyerror ("Cannot move A1 to even register");
4243           else if (!$4.n && !IS_EVEN ($1))
4244             return yyerror ("Cannot move A0 to odd register");
4245
4246           $$ = $4;
4247           $$.w = 1;
4248           $$.P = 1;
4249           $$.dst = $1;
4250         }
4251
4252         | HALF_REG ASSIGN LPAREN a_macfunc RPAREN
4253         {
4254           if ($4.n && !IS_H ($1))
4255             return yyerror ("Cannot move A1 to low half of register");
4256           else if (!$4.n && IS_H ($1))
4257             return yyerror ("Cannot move A0 to high half of register");
4258
4259           $$ = $4;
4260           $$.w = 1;
4261           $$.P = 0;
4262           $$.dst = $1;
4263         }
4264
4265         | HALF_REG ASSIGN REG_A
4266         {
4267           if (IS_A1 ($3) && !IS_H ($1))
4268             return yyerror ("Cannot move A1 to low half of register");
4269           else if (!IS_A1 ($3) && IS_H ($1))
4270             return yyerror ("Cannot move A0 to high half of register");
4271
4272           $$.w = 1;
4273           $$.P = 0;
4274           $$.n = IS_A1 ($3);
4275           $$.op = 3;
4276           $$.dst = $1;
4277           $$.s0.regno = 0;
4278           $$.s1.regno = 0;
4279         }
4280         ;
4281
4282 a_macfunc:
4283         a_assign multiply_halfregs
4284         {
4285           $$.n = IS_A1 ($1);
4286           $$.op = 0;
4287           $$.s0 = $2.s0;
4288           $$.s1 = $2.s1;
4289         }
4290         | a_plusassign multiply_halfregs
4291         {
4292           $$.n = IS_A1 ($1);
4293           $$.op = 1;
4294           $$.s0 = $2.s0;
4295           $$.s1 = $2.s1;
4296         }
4297         | a_minusassign multiply_halfregs
4298         {
4299           $$.n = IS_A1 ($1);
4300           $$.op = 2;
4301           $$.s0 = $2.s0;
4302           $$.s1 = $2.s1;
4303         }
4304         ;
4305
4306 multiply_halfregs:
4307         HALF_REG STAR HALF_REG
4308         {
4309           if (IS_DREG ($1) && IS_DREG ($3))
4310             {
4311               $$.s0 = $1;
4312               $$.s1 = $3;
4313             }
4314           else
4315             return yyerror ("Dregs expected");
4316         }
4317         ;
4318
4319 cc_op:
4320         ASSIGN
4321         {
4322         $$.r0 = 0;
4323         }
4324         | _BAR_ASSIGN
4325         {
4326         $$.r0 = 1;
4327         }
4328         | _AMPERSAND_ASSIGN
4329         {
4330         $$.r0 = 2;
4331         }
4332         | _CARET_ASSIGN
4333         {
4334         $$.r0 = 3;
4335         }
4336         ;
4337
4338 ccstat:
4339         CCREG cc_op STATUS_REG
4340         {
4341           $$.r0 = $3.regno;
4342           $$.x0 = $2.r0;
4343           $$.s0 = 0;
4344         }
4345         | CCREG cc_op V
4346         {
4347           $$.r0 = 0x18;
4348           $$.x0 = $2.r0;
4349           $$.s0 = 0;
4350         }
4351         | STATUS_REG cc_op CCREG
4352         {
4353           $$.r0 = $1.regno;
4354           $$.x0 = $2.r0;
4355           $$.s0 = 1;
4356         }
4357         | V cc_op CCREG
4358         {
4359           $$.r0 = 0x18;
4360           $$.x0 = $2.r0;
4361           $$.s0 = 1;
4362         }
4363         ;
4364
4365 /* Expressions and Symbols.  */
4366
4367 symbol: SYMBOL
4368         {
4369         Expr_Node_Value val;
4370         val.s_value = S_GET_NAME($1);
4371         $$ = Expr_Node_Create (Expr_Node_Reloc, val, NULL, NULL);
4372         }
4373         ;
4374
4375 any_gotrel:
4376         GOT
4377         { $$ = BFD_RELOC_BFIN_GOT; }
4378         | GOT17M4
4379         { $$ = BFD_RELOC_BFIN_GOT17M4; }
4380         | FUNCDESC_GOT17M4
4381         { $$ = BFD_RELOC_BFIN_FUNCDESC_GOT17M4; }
4382         ;
4383
4384 got:    symbol AT any_gotrel
4385         {
4386         Expr_Node_Value val;
4387         val.i_value = $3;
4388         $$ = Expr_Node_Create (Expr_Node_GOT_Reloc, val, $1, NULL);
4389         }
4390         ;
4391
4392 got_or_expr:    got
4393         {
4394         $$ = $1;
4395         }
4396         | expr
4397         {
4398         $$ = $1;
4399         }
4400         ;
4401
4402 pltpc :
4403         symbol AT PLTPC
4404         {
4405         $$ = $1;
4406         }
4407         ;
4408
4409 eterm: NUMBER
4410         {
4411         Expr_Node_Value val;
4412         val.i_value = $1;
4413         $$ = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
4414         }
4415         | symbol
4416         {
4417         $$ = $1;
4418         }
4419         | LPAREN expr_1 RPAREN
4420         {
4421         $$ = $2;
4422         }
4423         | TILDA expr_1
4424         {
4425         $$ = unary (Expr_Op_Type_COMP, $2);
4426         }
4427         | MINUS expr_1 %prec TILDA
4428         {
4429         $$ = unary (Expr_Op_Type_NEG, $2);
4430         }
4431         ;
4432
4433 expr: expr_1
4434         {
4435         $$ = $1;
4436         }
4437         ;
4438
4439 expr_1: expr_1 STAR expr_1
4440         {
4441         $$ = binary (Expr_Op_Type_Mult, $1, $3);
4442         }
4443         | expr_1 SLASH expr_1
4444         {
4445         $$ = binary (Expr_Op_Type_Div, $1, $3);
4446         }
4447         | expr_1 PERCENT expr_1
4448         {
4449         $$ = binary (Expr_Op_Type_Mod, $1, $3);
4450         }
4451         | expr_1 PLUS expr_1
4452         {
4453         $$ = binary (Expr_Op_Type_Add, $1, $3);
4454         }
4455         | expr_1 MINUS expr_1
4456         {
4457         $$ = binary (Expr_Op_Type_Sub, $1, $3);
4458         }
4459         | expr_1 LESS_LESS expr_1
4460         {
4461         $$ = binary (Expr_Op_Type_Lshift, $1, $3);
4462         }
4463         | expr_1 GREATER_GREATER expr_1
4464         {
4465         $$ = binary (Expr_Op_Type_Rshift, $1, $3);
4466         }
4467         | expr_1 AMPERSAND expr_1
4468         {
4469         $$ = binary (Expr_Op_Type_BAND, $1, $3);
4470         }
4471         | expr_1 CARET expr_1
4472         {
4473         $$ = binary (Expr_Op_Type_LOR, $1, $3);
4474         }
4475         | expr_1 BAR expr_1
4476         {
4477         $$ = binary (Expr_Op_Type_BOR, $1, $3);
4478         }
4479         | eterm
4480         {
4481         $$ = $1;
4482         }
4483         ;
4484
4485
4486 %%
4487
4488 EXPR_T
4489 mkexpr (int x, SYMBOL_T s)
4490 {
4491   EXPR_T e = (EXPR_T) ALLOCATE (sizeof (struct expression_cell));
4492   e->value = x;
4493   EXPR_SYMBOL(e) = s;
4494   return e;
4495 }
4496
4497 static int
4498 value_match (Expr_Node *exp, int sz, int sign, int mul, int issigned)
4499 {
4500   int umax = (1 << sz) - 1;
4501   int min = -1 << (sz - 1);
4502   int max = (1 << (sz - 1)) - 1;
4503
4504   int v = (EXPR_VALUE (exp)) & 0xffffffff;
4505
4506   if ((v % mul) != 0)
4507     {
4508       error ("%s:%d: Value Error -- Must align to %d\n", __FILE__, __LINE__, mul);
4509       return 0;
4510     }
4511
4512   v /= mul;
4513
4514   if (sign)
4515     v = -v;
4516
4517   if (issigned)
4518     {
4519       if (v >= min && v <= max) return 1;
4520
4521 #ifdef DEBUG
4522       fprintf(stderr, "signed value %lx out of range\n", v * mul);
4523 #endif
4524       return 0;
4525     }
4526   if (v <= umax && v >= 0)
4527     return 1;
4528 #ifdef DEBUG
4529   fprintf(stderr, "unsigned value %lx out of range\n", v * mul);
4530 #endif
4531   return 0;
4532 }
4533
4534 /* Return the expression structure that allows symbol operations.
4535    If the left and right children are constants, do the operation.  */
4536 static Expr_Node *
4537 binary (Expr_Op_Type op, Expr_Node *x, Expr_Node *y)
4538 {
4539   Expr_Node_Value val;
4540
4541   if (x->type == Expr_Node_Constant && y->type == Expr_Node_Constant)
4542     {
4543       switch (op)
4544         {
4545         case Expr_Op_Type_Add:
4546           x->value.i_value += y->value.i_value;
4547           break;
4548         case Expr_Op_Type_Sub:
4549           x->value.i_value -= y->value.i_value;
4550           break;
4551         case Expr_Op_Type_Mult:
4552           x->value.i_value *= y->value.i_value;
4553           break;
4554         case Expr_Op_Type_Div:
4555           if (y->value.i_value == 0)
4556             error ("Illegal Expression:  Division by zero.");
4557           else
4558             x->value.i_value /= y->value.i_value;
4559           break;
4560         case Expr_Op_Type_Mod:
4561           x->value.i_value %= y->value.i_value;
4562           break;
4563         case Expr_Op_Type_Lshift:
4564           x->value.i_value <<= y->value.i_value;
4565           break;
4566         case Expr_Op_Type_Rshift:
4567           x->value.i_value >>= y->value.i_value;
4568           break;
4569         case Expr_Op_Type_BAND:
4570           x->value.i_value &= y->value.i_value;
4571           break;
4572         case Expr_Op_Type_BOR:
4573           x->value.i_value |= y->value.i_value;
4574           break;
4575         case Expr_Op_Type_BXOR:
4576           x->value.i_value ^= y->value.i_value;
4577           break;
4578         case Expr_Op_Type_LAND:
4579           x->value.i_value = x->value.i_value && y->value.i_value;
4580           break;
4581         case Expr_Op_Type_LOR:
4582           x->value.i_value = x->value.i_value || y->value.i_value;
4583           break;
4584
4585         default:
4586           error ("%s:%d: Internal assembler error\n", __FILE__, __LINE__);
4587         }
4588       return x;
4589     }
4590   /* Canonicalize order to EXPR OP CONSTANT.  */
4591   if (x->type == Expr_Node_Constant)
4592     {
4593       Expr_Node *t = x;
4594       x = y;
4595       y = t;
4596     }
4597   /* Canonicalize subtraction of const to addition of negated const.  */
4598   if (op == Expr_Op_Type_Sub && y->type == Expr_Node_Constant)
4599     {
4600       op = Expr_Op_Type_Add;
4601       y->value.i_value = -y->value.i_value;
4602     }
4603   if (y->type == Expr_Node_Constant && x->type == Expr_Node_Binop
4604       && x->Right_Child->type == Expr_Node_Constant)
4605     {
4606       if (op == x->value.op_value && x->value.op_value == Expr_Op_Type_Add)
4607         {
4608           x->Right_Child->value.i_value += y->value.i_value;
4609           return x;
4610         }
4611     }
4612
4613   /* Create a new expression structure.  */
4614   val.op_value = op;
4615   return Expr_Node_Create (Expr_Node_Binop, val, x, y);
4616 }
4617
4618 static Expr_Node *
4619 unary (Expr_Op_Type op, Expr_Node *x)
4620 {
4621   if (x->type == Expr_Node_Constant)
4622     {
4623       switch (op)
4624         {
4625         case Expr_Op_Type_NEG:
4626           x->value.i_value = -x->value.i_value;
4627           break;
4628         case Expr_Op_Type_COMP:
4629           x->value.i_value = ~x->value.i_value;
4630           break;
4631         default:
4632           error ("%s:%d: Internal assembler error\n", __FILE__, __LINE__);
4633         }
4634       return x;
4635     }
4636   else
4637     {
4638       /* Create a new expression structure.  */
4639       Expr_Node_Value val;
4640       val.op_value = op;
4641       return Expr_Node_Create (Expr_Node_Unop, val, x, NULL);
4642     }
4643 }
4644
4645 int debug_codeselection = 0;
4646 static void
4647 notethat (char *format, ...)
4648 {
4649   va_list ap;
4650   va_start (ap, format);
4651   if (debug_codeselection)
4652     {
4653       vfprintf (errorf, format, ap);
4654     }
4655   va_end (ap);
4656 }
4657
4658 #ifdef TEST
4659 main (int argc, char **argv)
4660 {
4661   yyparse();
4662 }
4663 #endif
4664