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