public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gas/RISC-V: adjust assembler for opcode table re-ordering
@ 2023-01-06 12:34 Jan Beulich
  2023-01-07 23:29 ` Aurelien Jarno
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Beulich @ 2023-01-06 12:34 UTC (permalink / raw)
  To: Binutils
  Cc: Palmer Dabbelt, Andrew Waterman, Jim Wilson, Nelson Chu, Aurelien Jarno

PR gas/29940

With the single-operand JAL entry now sitting ahead of the two-operand
one, the parsing of a two-operand insn would first try to parse an 'a'-
style operand, resulting in the insertion of bogus (and otherwise
unused) undefined symbols in the symbol table, having register names.
Since 'a' is used as 1st operand only with J and JAL, and since JAL is
the only insn _also_ allowing for a register as 1st operand (and then
there being a 2nd one), special case this parsing aspect right there.
---
This, of course, is fragile, but I guess such workarounds are
unavoidable with the chosen approach of (recurring) parsing, and with
register names being special only in certain contexts.

A more generic approach, then possibly also helping performance, might
be to count the number of operands first, and do full parsing only when
the count matches that in the operand specifier string (at least when
there are multiple insn forms).

The similar workaround in my_getSmallExpression() actually looks
suspicious to me: I expect that it would get in the way of using equates
"shadowing" names of GPRs.

--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -3266,6 +3266,17 @@ riscv_ip (char *str, struct riscv_cl_ins
 	      continue;
 
 	    case 'a': /* 20-bit PC-relative offset.  */
+	      /* Like in my_getSmallExpression() we need to avoid emitting
+		 a stray undefined symbol if the 1st JAL entry doesn't match,
+		 but the 2nd (with 2 operands) might.  */
+	      if (oparg == insn->args)
+		{
+		  asargStart = asarg;
+		  if (reg_lookup (&asarg, RCLASS_GPR, NULL)
+		      && (*asarg == ',' || (ISSPACE (*asarg) && asarg[1] == ',')))
+		    break;
+		  asarg = asargStart;
+		}
 	    jump:
 	      my_getExpression (imm_expr, asarg);
 	      asarg = expr_end;

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-01-12  8:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06 12:34 [PATCH] gas/RISC-V: adjust assembler for opcode table re-ordering Jan Beulich
2023-01-07 23:29 ` Aurelien Jarno
2023-01-09 17:07   ` Jan Beulich
2023-01-09 19:07     ` Palmer Dabbelt
2023-01-09 21:59       ` Maciej W. Rozycki
2023-01-10  9:25         ` Jan Beulich
2023-01-10 22:58           ` Maciej W. Rozycki
2023-01-11  9:28             ` Jan Beulich
2023-01-12  1:28               ` Maciej W. Rozycki
2023-01-12  8:26                 ` Jan Beulich
2023-01-12  8:40                   ` Andrew Waterman
2023-01-10 12:31     ` Nick Clifton
2023-01-10 20:14       ` Palmer Dabbelt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).