如何使用 LLVM 验证新创建的指令?
如何使用 LLVM 验证新创建的指令?
我是 LLVM 和计算机体系结构的新手。 创建了针对 RISCV-32 架构的 bfloat16 类型算术的新指令。 我想知道这个算术指令的输出是否正确。我想验证浮点寄存器中存储的值是否采用 IEEE754 bfloat16 格式。
clang-14 -c -g -v --target=riscv32-unknown-elf -march=rv32izfh0p1 -menable-experimental-extensions -I/usr/include -o main.o main.c
riscv32-unknown-elf-gcc -g -o main main.o
我通过上面的命令编译了它,并确认汇编代码输出良好,如下所示。
然后,我尝试使用 qemu-riscv32 运行编译后的可执行文件并进行调试使用gdb。但发生了非法指令错误。
问题 我认为发生了非法指令错误,因为 QEMU 和 gdb 没有有关我创建的新指令的信息。除了修改QEMU和GDB之外,还有什么方法可以验证新创建的指令吗?
How can I validate a newly created instruction using LLVM?
I am new to LLVM and computer architecture.
Created a new instruction of bfloat16 type arithmetic targeting the RISCV-32 architecture.
I was wondering if the output of this arithmetic instruction was correct. And I wanted to verify that the value stored in the float register is in IEEE754 bfloat16 format.
clang-14 -c -g -v --target=riscv32-unknown-elf -march=rv32izfh0p1 -menable-experimental-extensions -I/usr/include -o main.o main.c
riscv32-unknown-elf-gcc -g -o main main.o
I compiled it through the above command, and it was confirmed that the assembly code came out well as shown below.
Then, I tried to run compiled executable file with qemu-riscv32 and debug it using gdb. But an error illegal instruction occurred.
Question
I think an illegal instruction error occurred because QEMU and gdb don't have information about the new instruction I created. Other than modifying QEMU and GDB, is there any way to validate the newly created instruction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果通过添加新指令来扩展 CPU 架构,则不仅需要在工具链(然后使用该新指令输出代码)中添加对这些指令的支持,而且还需要在 CPU 实现本身中添加对这些指令的支持(以便它可以执行编译器现在生成的代码)。您可以在真实的硬件 CPU 上执行此操作,实际上,它会从对其 RTL 的更改开始,这些更改可以在模拟中进行测试;或者您可以在 CPU 的模拟版本(例如 QEMU 提供的 CPU)上执行此操作。但是,如果您根本没有包含新指令的 CPU 实现,那么让编译器发出它们就没有意义,因为您没有任何东西可以运行编译器生成的代码。
If you extend a CPU architecture by adding new instructions to it, you need to add support for those in not just the toolchain (which will then output code using that new instruction) but also in the CPU implementation itself (so that it can execute the code your compiler now generates). You can do that either on a real hardware CPU, which in practice will start with changes to its RTL which can be tested in simulation; or you can do it on an emulated version of the CPU such as that which QEMU provides. But if you don't have an implementation of a CPU at all that has your new instructions in it, there's no point in having the compiler emit them, because you have nothing that can run the code that compiler produces.