Skip to contentSkip to conversation

RISC-V: Fix isa string logic bug, use popcount to count bits

PATCH Superseded Michael Clark 2 participants 4 messages Mar 9, 2018 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RISC-V: Fix isa string logic bug, use popcount to count bits

Cc Palmer Dabbelt <[email protected]>
Cc Peter Maydell <[email protected]>
---
 target/riscv/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.c +1 -1
index 4851890..f0d6d1d 100644
@@ -391,7 +391,7 @@ static const TypeInfo riscv_cpu_type_info = {
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
-    size_t maxlen = 5 + ctz32(cpu->env.misa);
+    size_t maxlen = 5 + __builtin_popcountll(cpu->env.misa);
     char *isa_string = g_new0(char, maxlen);
     snprintf(isa_string, maxlen, "rv%d", TARGET_LONG_BITS);
     for (i = 0; i < sizeof(riscv_exts); i++) {
Signature · 1 line
2.7.0
#1 lore raw
Quoted 12 lines · Michael Clark
Cc Palmer Dabbelt <[email protected]>
Cc Peter Maydell <[email protected]>
---
  target/riscv/cpu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.c +0 -0
index 4851890..f0d6d1d 100644

target/riscv/cpu.c static const TypeInfo riscv_cpu_type_info = { · line 394

Quoted 5 lines
target/riscv/cpu.c +1 -1
@@ -391,7 +391,7 @@ static const TypeInfo riscv_cpu_type_info = {
  char *riscv_isa_string(RISCVCPU *cpu)
  {
      int i;
-    size_t maxlen = 5 + ctz32(cpu->env.misa);
+    size_t maxlen = 5 + __builtin_popcountll(cpu->env.misa);

I'd rather you used ctpop64() from host-utils.h, so we have a centralized place to change things just once in case we have to tweak the use of __builtin_popcount when targetting a different compiler.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#2 lore raw
In reply to Michael Clark

[resend, this time with proper cc's]

Quoted 12 lines · Michael Clark
Cc Palmer Dabbelt <[email protected]>
Cc Peter Maydell <[email protected]>
---
  target/riscv/cpu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.c +0 -0
index 4851890..f0d6d1d 100644

target/riscv/cpu.c static const TypeInfo riscv_cpu_type_info = { · line 397

Quoted 8 lines
target/riscv/cpu.c +1 -1
@@ -391,7 +391,7 @@ static const TypeInfo riscv_cpu_type_info = {
  char *riscv_isa_string(RISCVCPU *cpu)
  {
      int i;
-    size_t maxlen = 5 + ctz32(cpu->env.misa);
+    size_t maxlen = 5 + __builtin_popcountll(cpu->env.misa);
      char *isa_string = g_new0(char, maxlen);
      snprintf(isa_string, maxlen, "rv%d", TARGET_LONG_BITS);
      for (i = 0; i < sizeof(riscv_exts); i++) {

I'd rather you used ctpop64() from host-utils.h, so we have a centralized place to change things just once in case we have to tweak the use of __builtin_popcount when targetting a different compiler.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#3 lore raw
Quoted 21 lines · Eric Blake

[resend, this time with proper cc's]

Quoted 17 lines · Michael Clark
Cc Palmer Dabbelt <[email protected]>
Cc Peter Maydell <[email protected]>
---
  target/riscv/cpu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.c +1 -1
index 4851890..f0d6d1d 100644
@@ -391,7 +391,7 @@ static const TypeInfo riscv_cpu_type_info = {
  char *riscv_isa_string(RISCVCPU *cpu)
  {
      int i;
-    size_t maxlen = 5 + ctz32(cpu->env.misa);
+    size_t maxlen = 5 + __builtin_popcountll(cpu->env.misa);
Quoted 8 lines

target/riscv/cpu.c static const TypeInfo riscv_cpu_type_info = { · line 397

Quoted 4 lines
target/riscv/cpu.c +0 -0
      char *isa_string = g_new0(char, maxlen);
      snprintf(isa_string, maxlen, "rv%d", TARGET_LONG_BITS);
      for (i = 0; i < sizeof(riscv_exts); i++) {

I'd rather you used ctpop64() from host-utils.h, so we have a centralized place to change things just once in case we have to tweak the use of __builtin_popcount when targetting a different compiler.

Okay. I'll revise the patch...