简体   繁体   English

RiscV 汇编程序 - 试验 RV32I 的“slli”命令

[英]RiscV assembler - experimenting with the 'slli' command for RV32I

I have been testing the following code on RiscV with the RV32I and RV64I assembler.我一直在使用 RV32I 和 RV64I 汇编器在 RiscV 上测试以下代码。

The assembly source file is汇编源文件是

.text
slli   x31,x31,63

When I assemble for 32 bit targets I obtain the following machine code output.当我为 32 位目标组装时,我获得以下机器代码输出。

 03ff9f93                slli    x31,x31,0x3f

A warning is thrown but it appears the upper 7 bits of the instruction word are not 'reserved'.抛出警告,但指令字的高 7 位似乎没有“保留”。 Doing a quick hand assembly I would expect 01ff9f93 .做一个快速手工组装我希望01ff9f93 I realize that it is incorrect to use the immediate operand value of 63 but the assembler will write the 63 value anyway.我意识到使用 63 的立即操作数值是不正确的,但汇编程序无论如何都会写入 63 值。 This does not seem like correct operation.这似乎不是正确的操作。

One way to avoid this potential problem is to set the assembler command line option of --fatal-warnings .避免这种潜在问题的一种方法是设置--fatal-warnings的汇编命令行选项。 And the build process will halt.并且构建过程将停止。 But at a -warn level it appears the 7 upper bits of the 32 target for the 'slli' command can be overwritten and you can create a legitimate RV64I instruction.但是在-warn级别,似乎可以覆盖 'slli' 命令的 32 个目标的高 7 位,并且您可以创建合法的 RV64I 指令。

To keep the build simple for this test, I did the following.为了使此测试的构建简单,我执行了以下操作。

  1. Created source file - "test.s"创建的源文件 - “test.s”
  2. Copied source file to the bin directory of the RiscV 32 bit build.将源文件复制到 RiscV 32 位构建的 bin 目录。 Then,然后,

    ./riscv32-unknown-elf-as -L --fatal-warnings test.s

or或者

 ./riscv32-unknown-elf-as -L -warn test.s
  1. Create list file创建列表文件

    ./riscv32-unknown-elf-objdump -h -l -M numeric,no-aliases -S -d -EL a.out ./riscv32-unknown-elf-objdump -h -l -M 数字,无别名 -S -d -EL a.out

The lower lines of output will look something like this below if you set -warn level in the assembler.如果在汇编程序中设置 -warn 级别,输出的较低行将如下所示。

Disassembly of section .text:

00000000 <.text>:
   0:   03ff9f93                slli    x31,x31,0x3f

I am wondering why the assembler takes this approach and shouldn't the upper 7 bits for 'slii' with RV32I always be stuck-at 0?我想知道为什么汇编程序采用这种方法,RV32I 的“slii”的高 7 位不应该总是停留在 0?

This problem was considered a bug and the assembler code has been changed and merged.这个问题被认为是一个错误,汇编代码已被更改和合并。 You can see details at GitHub riscv/riscv-binutils-gdb on the riscv-next branch.您可以在 riscv-next 分支上的 GitHub riscv/riscv-binutils-gdb 上查看详细信息。 In 'gas' (the assembler) the severity level was changed from 'warn' to 'error' - preventing any illegal RV32I machine code to be created (03ff9f93 is not legal machine code for the slli command on RV32I).在“gas”(汇编程序)中,严重性级别从“warn”更改为“error”——防止创建任何非法的 RV32I 机器代码(03ff9f93 不是 RV32I 上 slli 命令的合法机器代码)。

For osgx - I am still intrigued by your comment that there are no separate 32/64 bit encoders.对于 osgx - 我仍然对您的评论很感兴趣,即没有单独的 32/64 位编码器。 Can you please clarify?你能澄清一下吗?

Just a short remark:只是一个简短的评论:

I can see from the spec (Version 20190608-Base-Ratified ) on pages 130 for RV32I and 131 for RV64I that there should be a difference in the encoding of the SLLI instruction.我可以从 RV32I 的第 130 页和 RV64I 的第 131 页的规范(版本 20190608-Base-Ratified )中看到,SLLI 指令的编码应该有所不同。

RV32I for the shift amount is limited to 5 bits and for RV64I this is extended to 6 bits. RV32I 的移位量限制为 5 位,而 RV64I 则扩展到 6 位。 So depending on the used assembler, there should be differences in the binary that results and in the displayed warnings or errors.因此,根据所使用的汇编程序,产生的二进制文件和显示的警告或错误应该有所不同。

Greets Joachim问候约阿希姆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM