当前位置: 首页 > Linux

ARMv9SVE-SVE2入门教程(二)如何运行SVE程序

时间:2023-04-06 11:17:29 Linux

?在深入学习SVE指令之前,我们需要搭建一个可以运行和调试SVE指令的实验环境。由于树莓派4b不支持SVE扩展,我们可以使用QEMU+ARM64实验平台来模拟SVE指令。runninglinuxkernel_5.0项目在github,或者在腾讯编码仓库。具体使用方法请参考里面的Readme。访问github:https://github.com/figozhang/...访问腾讯编码仓库:https://benshushu.coding.net/...启用QEMU中的SVE扩展,需要指定"-cpuQEMU程序中的"参数,例如"-cpumax,sve=on,sve256=on"表示开启所有CPU特性,包含SVE扩展,SVE支持的向量长度设置为256位。读者也可以设置其他长度的SVE,比如1024位的SVE长度。启动QEMU的命令如下。$qemu-system-aarch64-m1024-cpumax,sve=on,sve256=on-Mvirt,gic-version=3,its=on,iommu=smmuv3-nographic-smp4-kernelarch/arm64/boot/Image-append"noinintrdsched_debugroot=/dev/vdarootfstype=ext4rwcrashkernel=256Mloglevel=8"-driveif=none,file=rootfs_debian_arm64.ext4,id=hd0-devicevirtio-blk-device,drive=hd0--fsdevlocal,id=kmod_dev,path=./kmodules,security_model=none-devicevirtio-9p-pci,fsdev=kmod_dev,mount_tag=kmod_mount使用下面的SVE指令编写一个简单的汇编程序。1.section.data23.align34print_hello_sve:5.string"hellosve\n"67.section.text8.globlmain9main:10stpx29,x30,[sp,-16]!1112movx2,#413whilelop0.s,xzr,x214movz0.s,p0/z,#0x551516adrpx0,print_hello_sve17添加x0,x0,:lo12:print_hello_sve18blprintf1920movx0,#021ldpx29,x30,[sp],1622ret此汇编程序打印“hellosve”。为了测试SVE指令是否可以编译运行,我们在第13-14行添加两条SVE指令,其中WHILELO指令初始化P0预测寄存器。后面我们会介绍WHILELO指令。MOV是将立即数移动到Z0向量寄存器。首先启动QEMU+ARM64实验平台。QEMU+ARM64实验平台的使用方法请参考《奔跑吧linux内核 入门篇》第二版1.5.3节。运行run_rlk_arm64.sh脚本并输入运行参数。run_rlk_arm64.sh脚本启用了SVE扩展。$./run_rlk_arm64.shrun登录QEMU+ARM64系统后,可以通过“/proc/cpuinfo”节点查看系统是否支持SVE扩展。在“Features”中,显示了当前CPU支持的所有硬件特性,如SVE等。cat/proc/cpuinfoprocessor:0BogoMIPS:125.00特性:svefpasimdevtstrmaesCPU实现者:0x00CPU架构:8CPU变体:0x0CPU部分:0x051CPU修订:0使用GCC编译此汇编程序。GCC从GCC8开始支持SVE指令。gcchello_sve.S-ohello_svehello_sve.S:Assemblermessages:hello_sve.S:13:Error:selectedprocessordoesnotsupport`whilelop0.s,xzr,x2'hello_sve.S:14:Error:selectedprocessordoesnotsupport`movz0.s,p0/z,#0x55'直接用"gcchello_sve.S-ohello_sve"编译,会出现无法识别SVE指令的错误。我们需要设置“-march”参数来指定处理器架构。例如“-march=armv8-a+sve”表示编译的程序需要支持ARMv8架构和SVE扩展。gcchello_sve.S-ohello_sve-g-march=armv8-a+sve编译完成后运行hello_sve程序。./hello_svehellosve这样我们就搭建了一个可以运行SVE命令的实验环境。如何单步调试SVE程序?接下来我们使用GDB单步执行SVE指令。启动GDB调试程序。gdbhello_sve在main函数入口处设置断点。(gdb)bmainBreakpoint1at0x76c:文件hello_sve.S,第10行。输入“r”命令开始调试。GDB将在断点处停止。(gdb)rStartingprogram:/mnt/sve/example_hello_sve/hello_sveBreakpoint1,main()athello_sve.S:1010stpx29,x30,[sp,-16]!(gdb)使用“s”命令单步执行.使用“inforeg”命令查看寄存器的值,如图,使用inforegp0查看预测寄存器p0的值,或者使用inforegz0查看z0向量寄存器的值。ARM64视频课程