Hexagon (target/hexagon) Clean up disassembly of control and system regs
PATCH 1/1 Hexagon (target/hexagon) Clean up disassembly of control and system regs
Change disassembly of control regs from C{num}/{name} to {name} Change disassembly of system regs from S{num}/r{num} to {name}
--- target/hexagon/printinsn.c | 22 ++++++++++++++++++---- target/hexagon/gen_printinsn.py | 14 ++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-)
target/hexagon/printinsn.c +18 -4
@@ -23,18 +23,32 @@#include "internal.h" #include "decode.h" +static char regstr[10 ]; +static const char *sreg2str (unsigned int reg) { -if (reg <TOTAL_PER_THREAD_REGS ) { -return hexagon_regnames[reg]; +#ifndef CONFIG_USER_ONLY +if (reg <NUM_SREGS ) { +return hexagon_sregnames[reg]; }else { -return "???" ; +snprintf (regstr,sizeof (regstr),"S%d" , reg); +return regstr; } +#else +snprintf (regstr,sizeof (regstr),"S%d" , reg); +return regstr; +#endif }static const char *creg2str (unsigned int reg) { -return sreg2str (reg +HEX_REG_SA0 ); +unsigned int gpr = reg +HEX_REG_SA0 ; +if (gpr <TOTAL_PER_THREAD_REGS ) { +return hexagon_regnames[gpr]; + }else { +snprintf (regstr,sizeof (regstr),"C%d" , reg); +return regstr; + } }static void snprintinsn (GString *buf,Insn *insn)
target/hexagon/gen_printinsn.py +8 -6
@@ -28,13 +28,14 @@ ## Generate data for printing each instruction (format string + operands) ## def regprinter(m): - str = m.group(1) - str += ":".join(["%d"] * len(m.group(2))) - str += m.group(3) if ("S" in m.group(1)) and (len(m.group(2)) == 1): - str += "/%s" + str = "%s" elif ("C" in m.group(1)) and (len(m.group(2)) == 1): - str += "/%s" + str = "%s" + else: + str = m.group(1) + str += ":".join(["%d"] * len(m.group(2))) + str += m.group(3) return str
@@ -142,11 +143,12 @@ def main(): else: regno = ri if len(b) == 1: - f.write(f", insn->regno[{regno}]") if "S" in a: f.write(f", sreg2str(insn->regno[{regno}])") elif "C" in a: f.write(f", creg2str(insn->regno[{regno}])") + else: + f.write(f", insn->regno[{regno}]") elif len(b) == 2: f.write(f", insn->regno[{regno}] + 1" f", insn->regno[{regno}]") else:
Signature · 1 line
2.43.0
Quoted 39 lines · Taylor Simpson
Change disassembly of control regs from C{num}/{name} to {name} Change disassembly of system regs from S{num}/r{num} to {name}
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/printinsn.c | 22 ++++++++++++++++++---- target/hexagon/gen_printinsn.py | 14 ++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-)target/hexagon/printinsn.c +11
-3@@ -23,18 +23,32 @@#include "internal.h" #include "decode.h" +static char regstr[10 ]; +static const char *sreg2str (unsigned int reg) { -if (reg <TOTAL_PER_THREAD_REGS ) { -return hexagon_regnames[reg]; +#ifndef CONFIG_USER_ONLY +if (reg <NUM_SREGS ) { +return hexagon_sregnames[reg]; }else { -return "???" ; +snprintf (regstr,sizeof (regstr),"S%d" , reg); +return regstr; } +#else +snprintf (regstr,sizeof (regstr),"S%d" , reg); +return regstr; +#endif }static const char *creg2str (unsigned int reg) {
target/hexagon/printinsn.c line 53
Quoted 10 lines
target/hexagon/printinsn.c +7
-1-return sreg2str (reg +HEX_REG_SA0 ); +unsigned int gpr = reg +HEX_REG_SA0 ; +if (gpr <TOTAL_PER_THREAD_REGS ) { +return hexagon_regnames[gpr]; + }else { +snprintf (regstr,sizeof (regstr),"C%d" , reg); +return regstr; + } }
Seems like this change also depends on some kind of mutex around regstr[] so that we know it's not being used concurrently by multiple threads. Translation is single-threaded but if we gained another caller we wouldn't remember to come back and remediate this.
I suppose we could take an input buffer/length. Or maybe we just add another static _regnames[] array to solve the lifetime/race problems?
Quoted 39 lines
target/hexagon/printinsn.c +0
-0static void snprintinsn (GString *buf,Insn *insn)target/hexagon/gen_printinsn.py +8
-6@@ -28,13 +28,14 @@ ## Generate data for printing each instruction (format string + operands) ## def regprinter(m): - str = m.group(1) - str += ":".join(["%d"] * len(m.group(2))) - str += m.group(3) if ("S" in m.group(1)) and (len(m.group(2)) == 1): - str += "/%s" + str = "%s" elif ("C" in m.group(1)) and (len(m.group(2)) == 1): - str += "/%s" + str = "%s" + else: + str = m.group(1) + str += ":".join(["%d"] * len(m.group(2))) + str += m.group(3) return str@@ -142,11 +143,12 @@ def main(): else: regno = ri if len(b) == 1: - f.write(f", insn->regno[{regno}]") if "S" in a: f.write(f", sreg2str(insn->regno[{regno}])") elif "C" in a: f.write(f", creg2str(insn->regno[{regno}])") + else: + f.write(f", insn->regno[{regno}]") elif len(b) == 2: f.write(f", insn->regno[{regno}] + 1" f", insn->regno[{regno}]") else:
Quoted 58 lines · Brian Cain
Quoted 39 lines · Taylor Simpson
Change disassembly of control regs from C{num}/{name} to {name} Change disassembly of system regs from S{num}/r{num} to {name}
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/printinsn.c | 22 ++++++++++++++++++---- target/hexagon/gen_printinsn.py | 14 ++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-)target/hexagon/printinsn.c +11
-3@@ -23,18 +23,32 @@#include "internal.h" #include "decode.h" +static char regstr[10 ]; +static const char *sreg2str (unsigned int reg) { -if (reg <TOTAL_PER_THREAD_REGS ) { -return hexagon_regnames[reg]; +#ifndef CONFIG_USER_ONLY +if (reg <NUM_SREGS ) { +return hexagon_sregnames[reg]; }else { -return "???" ; +snprintf (regstr,sizeof (regstr),"S%d" , reg); +return regstr; } +#else +snprintf (regstr,sizeof (regstr),"S%d" , reg); +return regstr; +#endif }static const char *creg2str (unsigned int reg) {target/hexagon/printinsn.c line 53
Quoted 10 lines
target/hexagon/printinsn.c +7
-1-return sreg2str (reg +HEX_REG_SA0 ); +unsigned int gpr = reg +HEX_REG_SA0 ; +if (gpr <TOTAL_PER_THREAD_REGS ) { +return hexagon_regnames[gpr]; + }else { +snprintf (regstr,sizeof (regstr),"C%d" , reg); +return regstr; + } }Seems like this change also depends on some kind of mutex around regstr[] so that we know it's not being used concurrently by multiple threads. Translation is single-threaded but if we gained another caller we wouldn't remember to come back and remediate this.
Quoted 4 lines
I suppose we could take an input buffer/length. Or maybe we just add another static _regnames[] array to solve the lifetime/race problems?
How about putting a regstr field in the Insn struct (and pass Insn* to these two functions)?
Thanks,
Taylor
Quoted 67 lines · Taylor Simpson
On Mon, Aug 10, 2026 at 1:34 PM Brian Cain <[email protected]> wrote:
On 8/10/2026 1:28 PM, Taylor Simpson wrote: > Change disassembly of control regs from C{num}/{name} to {name} > Change disassembly of system regs from S{num}/r{num} to {name} > > Signed-off-by: Taylor Simpson <[email protected]> > --- > target/hexagon/printinsn.c | 22 ++++++++++++++++++---- > target/hexagon/gen_printinsn.py | 14 ++++++++------ > 2 files changed, 26 insertions(+), 10 deletions(-) > > diff --git a/target/hexagon/printinsn.c b/target/hexagon/printinsn.c > index a7e46f4bcd..b55d3b0b35 100644 > --- a/target/hexagon/printinsn.c > +++ b/target/hexagon/printinsn.c > @@ -23,18 +23,32 @@ > #include "internal.h" > #include "decode.h" > > +static char regstr[10]; > + > static const char *sreg2str(unsigned int reg) > { > - if (reg < TOTAL_PER_THREAD_REGS) { > - return hexagon_regnames[reg]; > +#ifndef CONFIG_USER_ONLY > + if (reg < NUM_SREGS) { > + return hexagon_sregnames[reg]; > } else { > - return "???"; > + snprintf(regstr, sizeof(regstr), "S%d", reg); > + return regstr; > } > +#else > + snprintf(regstr, sizeof(regstr), "S%d", reg); > + return regstr; > +#endif > } > > static const char *creg2str(unsigned int reg) > { > - return sreg2str(reg + HEX_REG_SA0); > + unsigned int gpr = reg + HEX_REG_SA0; > + if (gpr < TOTAL_PER_THREAD_REGS) { > + return hexagon_regnames[gpr]; > + } else { > + snprintf(regstr, sizeof(regstr), "C%d", reg); > + return regstr; > + } > } > Seems like this change also depends on some kind of mutex around regstr[] so that we know it's not being used concurrently by multiple threads. Translation is single-threaded but if we gained another caller we wouldn't remember to come back and remediate this. I suppose we could take an input buffer/length. Or maybe we just add another static _regnames[] array to solve the lifetime/race problems?
Quoted 2 lines
How about putting a regstr field in the Insn struct (and pass Insn* to these two functions)?
A character array? Sure: seems like that should work.
But if we have a static array for the others why not leverage that here too? We can statically fill these values, right?
Quoted 3 lines
Thanks,
Taylor
Quoted 70 lines · Brian Cain
On 8/10/2026 3:53 PM, Taylor Simpson wrote:
Quoted 58 lines · Brian Cain
Quoted 39 lines · Taylor Simpson
Change disassembly of control regs from C{num}/{name} to {name} Change disassembly of system regs from S{num}/r{num} to {name}
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/printinsn.c | 22 ++++++++++++++++++---- target/hexagon/gen_printinsn.py | 14 ++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-)target/hexagon/printinsn.c +11
-3@@ -23,18 +23,32 @@#include "internal.h" #include "decode.h" +static char regstr[10 ]; +static const char *sreg2str (unsigned int reg) { -if (reg <TOTAL_PER_THREAD_REGS ) { -return hexagon_regnames[reg]; +#ifndef CONFIG_USER_ONLY +if (reg <NUM_SREGS ) { +return hexagon_sregnames[reg]; }else { -return "???" ; +snprintf (regstr,sizeof (regstr),"S%d" , reg); +return regstr; } +#else +snprintf (regstr,sizeof (regstr),"S%d" , reg); +return regstr; +#endif }static const char *creg2str (unsigned int reg) {target/hexagon/printinsn.c line 53
Quoted 10 lines
target/hexagon/printinsn.c +7
-1-return sreg2str (reg +HEX_REG_SA0 ); +unsigned int gpr = reg +HEX_REG_SA0 ; +if (gpr <TOTAL_PER_THREAD_REGS ) { +return hexagon_regnames[gpr]; + }else { +snprintf (regstr,sizeof (regstr),"C%d" , reg); +return regstr; + } }Seems like this change also depends on some kind of mutex around regstr[] so that we know it's not being used concurrently by multiple threads. Translation is single-threaded but if we gained another caller we wouldn't remember to come back and remediate this.
Quoted 4 lines
I suppose we could take an input buffer/length. Or maybe we just add another static _regnames[] array to solve the lifetime/race problems?
Quoted 9 lines
How about putting a regstr field in the Insn struct (and pass Insn* to these two functions)?
A character array? Sure: seems like that should work.
But if we have a static array for the others why not leverage that here too? We can statically fill these values, right?
These are for cases where there is some sort of error and the reg number is larger than NUM_SREGS/TOTAL_PER_THREAD_REGS. So, we wouldn't know how to size these without looking at the number of bits in the encoding of each instruction that has one of these. However, that could change over time if the architecture adds new instructions.
The regno field in the Insn struct is a uint8_t, so we could create static arrays with 256 entries and
We could revert back to returning "???". Alternatively, S<unknown> or C<unknown> would be more readable.
Thoughts?
Hi Taylor,
Quoted 29 lines · Taylor Simpson
Quoted 9 lines · Brian Cain
Quoted 9 lines
Seems like this change also depends on some kind of mutex around regstr[] so that we know it's not being used concurrently by multiple threads. Translation is single-threaded but if we gained another caller we wouldn't remember to come back and remediate this.
I suppose we could take an input buffer/length. Or maybe we just add another static _regnames[] array to solve the lifetime/race problems?
Quoted 9 lines
How about putting a regstr field in the Insn struct (and pass Insn* to these two functions)?
A character array? Sure: seems like that should work.
But if we have a static array for the others why not leverage that here too? We can statically fill these values, right?
These are for cases where there is some sort of error and the reg number is larger than NUM_SREGS/TOTAL_PER_THREAD_REGS. So, we wouldn't know how to size these without looking at the number of bits in the encoding of each instruction that has one of these. However, that could change over time if the architecture adds new instructions.
Quoted 5 lines
The regno field in the Insn struct is a
uint8_t, so we could create static arrays with 256 entries andWe could revert back to returning "???". Alternatively, S<unknown> or C<unknown> would be more readable.
Hexagon frontend already relies a lot on generators, why not also generate a static array?
Quoted 82 lines · Taylor Simpson
On Mon, Aug 10, 2026 at 3:12 PM Brian Cain <[email protected]> wrote:
On 8/10/2026 3:53 PM, Taylor Simpson wrote:Quoted 66 lines
On Mon, Aug 10, 2026 at 1:34 PM Brian Cain <[email protected]> wrote: On 8/10/2026 1:28 PM, Taylor Simpson wrote: > Change disassembly of control regs from C{num}/{name} to {name} > Change disassembly of system regs from S{num}/r{num} to {name} > > Signed-off-by: Taylor Simpson <[email protected]> > --- > target/hexagon/printinsn.c | 22 ++++++++++++++++++---- > target/hexagon/gen_printinsn.py | 14 ++++++++------ > 2 files changed, 26 insertions(+), 10 deletions(-) > > diff --git a/target/hexagon/printinsn.c b/target/hexagon/printinsn.c > index a7e46f4bcd..b55d3b0b35 100644 > --- a/target/hexagon/printinsn.c > +++ b/target/hexagon/printinsn.c > @@ -23,18 +23,32 @@ > #include "internal.h" > #include "decode.h" > > +static char regstr[10]; > + > static const char *sreg2str(unsigned int reg) > { > - if (reg < TOTAL_PER_THREAD_REGS) { > - return hexagon_regnames[reg]; > +#ifndef CONFIG_USER_ONLY > + if (reg < NUM_SREGS) { > + return hexagon_sregnames[reg]; > } else { > - return "???"; > + snprintf(regstr, sizeof(regstr), "S%d", reg); > + return regstr; > } > +#else > + snprintf(regstr, sizeof(regstr), "S%d", reg); > + return regstr; > +#endif > } > > static const char *creg2str(unsigned int reg) > { > - return sreg2str(reg + HEX_REG_SA0); > + unsigned int gpr = reg + HEX_REG_SA0; > + if (gpr < TOTAL_PER_THREAD_REGS) { > + return hexagon_regnames[gpr]; > + } else { > + snprintf(regstr, sizeof(regstr), "C%d", reg); > + return regstr; > + } > } > Seems like this change also depends on some kind of mutex around regstr[] so that we know it's not being used concurrently by multiple threads. Translation is single-threaded but if we gained another caller we wouldn't remember to come back and remediate this.Quoted 9 lines
I suppose we could take an input buffer/length. Or maybe we just add another static _regnames[] array to solve the lifetime/race problems? How about putting a regstr field in the Insn struct (and pass Insn* to these two functions)?
Quoted 8 lines
A character array? Sure: seems like that should work.
But if we have a static array for the others why not leverage that here too? We can statically fill these values, right?
These are for cases where there is some sort of error and the reg number is larger than NUM_SREGS/TOTAL_PER_THREAD_REGS. So, we wouldn't know how to size these without looking at the number of bits in the encoding of each instruction that has one of these. However, that could change over time if the architecture adds new instructions.
Ah, okay, right.
Okay - any solution that mitigates the race should suffice, then.
Quoted 8 lines
The regno field in the Insn struct is a
uint8_t, so we could create static arrays with 256 entries andWe could revert back to returning "???". Alternatively, S<unknown> or C<unknown> would be more readable.
Thoughts?
Quoted 94 lines · Brian Cain
On 8/10/2026 4:32 PM, Taylor Simpson wrote:
Quoted 70 lines · Brian Cain
On 8/10/2026 3:53 PM, Taylor Simpson wrote:
Quoted 58 lines · Brian Cain
Quoted 39 lines · Taylor Simpson
Change disassembly of control regs from C{num}/{name} to {name} Change disassembly of system regs from S{num}/r{num} to {name}
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/printinsn.c | 22 ++++++++++++++++++---- target/hexagon/gen_printinsn.py | 14 ++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-)target/hexagon/printinsn.c +11
-3@@ -23,18 +23,32 @@#include "internal.h" #include "decode.h" +static char regstr[10 ]; +static const char *sreg2str (unsigned int reg) { -if (reg <TOTAL_PER_THREAD_REGS ) { -return hexagon_regnames[reg]; +#ifndef CONFIG_USER_ONLY +if (reg <NUM_SREGS ) { +return hexagon_sregnames[reg]; }else { -return "???" ; +snprintf (regstr,sizeof (regstr),"S%d" , reg); +return regstr; } +#else +snprintf (regstr,sizeof (regstr),"S%d" , reg); +return regstr; +#endif }static const char *creg2str (unsigned int reg) {target/hexagon/printinsn.c line 53
Quoted 10 lines
target/hexagon/printinsn.c +7
-1-return sreg2str (reg +HEX_REG_SA0 ); +unsigned int gpr = reg +HEX_REG_SA0 ; +if (gpr <TOTAL_PER_THREAD_REGS ) { +return hexagon_regnames[gpr]; + }else { +snprintf (regstr,sizeof (regstr),"C%d" , reg); +return regstr; + } }Seems like this change also depends on some kind of mutex around regstr[] so that we know it's not being used concurrently by multiple threads. Translation is single-threaded but if we gained another caller we wouldn't remember to come back and remediate this.
Quoted 4 lines
I suppose we could take an input buffer/length. Or maybe we just add another static _regnames[] array to solve the lifetime/race problems?
Quoted 9 lines
How about putting a regstr field in the Insn struct (and pass Insn* to these two functions)?
A character array? Sure: seems like that should work.
But if we have a static array for the others why not leverage that here too? We can statically fill these values, right?
These are for cases where there is some sort of error and the reg number is larger than NUM_SREGS/TOTAL_PER_THREAD_REGS. So, we wouldn't know how to size these without looking at the number of bits in the encoding of each instruction that has one of these. However, that could change over time if the architecture adds new instructions.
Quoted 4 lines
Ah, okay, right.
Okay - any solution that mitigates the race should suffice, then.
I'll go with static arrays with 256 entries. Stand by for v2 of the patch.