Add immediate instruction getting assembled as its compressed variant by default

61 views
Skip to first unread message

Shubhodeep Roychoudhury

unread,
Oct 24, 2017, 2:10:40 AM10/24/17
to RISC-V SW Dev
I am seeing that the addi instruction in some of the directed tests (.s files) are getting assembled into the compressed variant of addi, when compiled with the support for C extension.

Is there any flag/setting that will prevent that from taking place? I would want the addi in my tests to show up as their regular rv32i variant whereas the compressed one should be assembled only when I use c.addi in my tests.

You can follow the steps given below to recreate this issue

1. Put the following in your .s file (simple.s in this case) 

    .text

   addi    x5, x5, 12
   addi    x5, x5, 12
   addi    x5, x5, 12
   addi    x5, x5, 12
   addi    x5, x5, 12

   .end

2. Next compile the .s file and disassemble the binary

riscv64-unknown-elf-as -c -march=rv64imafdc -ggdb -o simple.o simple.s
riscv64-unknown-elf-objdump simple.o  -xsCd > simple.dis

3. The disassembly seems to be having the compressed variant instead of the regular addi

Disassembly of section .text:

0000000000000000 <.L0 >:
   0: 02b1                 addi t0,t0,12
0000000000000002 <.L0 >:
   2: 02b1                 addi t0,t0,12
0000000000000004 <.L0 >:
   4: 02b1                 addi t0,t0,12
0000000000000006 <.L0 >:
   6: 02b1                 addi t0,t0,12
0000000000000008 <.L0 >:
   8: 02b1                 addi t0,t0,12

Regards,
Shubhodeep

Andrew Waterman

unread,
Oct 24, 2017, 2:19:10 AM10/24/17
to Shubhodeep Roychoudhury, RISC-V SW Dev
This is by design; you're using an assembler that defaults to
supporting the C extension.

On the command line, you can use -march=<something without c>, e.g.,
-march=rv32ima.

In the source code, you can use .option norvc.
> --
> You received this message because you are subscribed to the Google Groups
> "RISC-V SW Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sw-dev+un...@groups.riscv.org.
> To post to this group, send email to sw-...@groups.riscv.org.
> Visit this group at
> https://groups.google.com/a/groups.riscv.org/group/sw-dev/.
> To view this discussion on the web visit
> https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/300e260f-8b6b-4fc4-83e2-94fd01aab074%40groups.riscv.org.

Richard Herveille

unread,
Oct 24, 2017, 3:27:18 AM10/24/17
to Andrew Waterman, Shubhodeep Roychoudhury, RISC-V SW Dev, Richard Herveille
smime.p7m

Andrew Waterman

unread,
Oct 24, 2017, 4:53:26 AM10/24/17
to Richard Herveille, Shubhodeep Roychoudhury, RISC-V SW Dev
In both cases GAS will reject the instructions.

If you want to restrict GAS to compress only certain instructions, I'd recommend writing .option norvc initially; then for each code segment you want to allow C instructions, write .option push; .option rvc; c.addi a0,1; c.slli a0, 1; .option pop.  It's extremely verbose, but it does the right thing.

On Tue, Oct 24, 2017 at 12:27 AM, Richard Herveille <richard....@roalogic.com> wrote:

If you use either option to disable defaulting to C-instructions, will c.addi still be a valid opcode?

Maybe I should rephrase. Will either of the suggested options stop defaulting to C-instructions or disable support for C-instructions all together?

 

Thanks,

Richard

 

 

id:image001.png@01D348FE.8B6D1030

 

Richard Herveille

Managing Director

Phone +31 (45) 405 5681

Cell +31 (6) 5207 2230

richard....@roalogic.com

 

 

--

You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.

To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+unsubscribe@groups.riscv.org.

To post to this group, send email to sw-...@groups.riscv.org.

Bruce Hoult

unread,
Oct 24, 2017, 6:38:46 AM10/24/17
to Andrew Waterman, Richard Herveille, Shubhodeep Roychoudhury, RISC-V SW Dev
My days of writing hairy assembly language were before I switched to *nix/gas, but I'm guessing you could make a macro that expanded "rvc addi a0,1" to emit the relevant .option directives before and after the instruction.

On Tue, Oct 24, 2017 at 11:53 AM, Andrew Waterman <and...@sifive.com> wrote:
In both cases GAS will reject the instructions.

If you want to restrict GAS to compress only certain instructions, I'd recommend writing .option norvc initially; then for each code segment you want to allow C instructions, write .option push; .option rvc; c.addi a0,1; c.slli a0, 1; .option pop.  It's extremely verbose, but it does the right thing.

 

--

You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.

To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+un...@groups.riscv.org.

To post to this group, send email to sw-...@groups.riscv.org.

--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+unsubscribe@groups.riscv.org.
To post to this group, send email to sw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/sw-dev/.
Reply all
Reply to author
Forward
0 new messages