6

When I use the riscv64-unknown-elf-gcc, there is few differences between option -march=rv64g and -march=rv64gc.

-march=64g will use RVC codes in standard library functions, for example, the prinft, as much as possible but not in my own functions. While the -march=64gc, use the RVC codes in both types of functions.

I don't know whether this is default. But if I want to forbid the RVC codes so that even in the standard library functions without the RVC codes, what should I do?

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
tuck theo
  • 79
  • 5

2 Answers2

1

Recompile the riscv-gnu-tool with option --with-arch=rv64g --disable-multilib

tuck theo
  • 79
  • 5
  • Instead of riscv-gnu-tool did you mean https://github.com/riscv/riscv-gnu-toolchain? – osgx May 11 '17 at 02:43
1

I've used the following with gcc (11.3.0) and clang (17.0.0) on RISC-V hardware (underlying uarch of sifive,u74-mc with isa of rv64imafdc) to use uncompressed RISC-V instructions.

hello.S:

.global main

.data
hello:  .asciz "Hello, world!\n"

.text
main:
  addi sp,sp,-8
  sd   ra,0(sp)

  la   a0,hello
  call printf

  li   a0,0
  ld   ra,0(sp)
  addi sp,sp,8
  ret

gcc -march=rv64g -o hello hello.S or clang -march=rv64g -o hello hello.S. Verify that your code has uncompressed instructions:

objdump -d -M no-aliases hello

...
0000000000000668 <main>:
 668:   ff810113            addi    sp,sp,-8
 66c:   00113023            sd  ra,0(sp)
 670:   00002517            auipc   a0,0x2
 674:   9d053503            ld  a0,-1584(a0) # 2040 <_GLOBAL_OFFSET_TABLE_+0x8>
 678:   f29ff0ef            jal ra,5a0 <printf@plt>
 67c:   00000513            addi    a0,zero,0
 680:   00013083            ld  ra,0(sp)
 684:   00810113            addi    sp,sp,8
 688:   00008067            jalr    zero,0(ra)

Two things to note: the instructions are 32-bits wide, and they do not have c. in front of them.

Finally note that the executable is linked with standard libraries, and those libraries may have been compiled with support of the c extension. You can confirm this with -M no-aliases to objdump -D and instructions that look like c.beqz, c.addi, etc.

Joe
  • 2,352
  • 20
  • 38