常见泽1 发表于 2019-12-16 17:09

第四篇 GD32VF103C START RISC-V和Corex-M3指令测试

<p style="text-align: center;"><span style="font-size:20px;"><strong>第四篇 GD32VF103C START RISC-V和Corex-M3指令测试</strong></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">加减乘除运算应该是每个人编程都会用得到,本篇就想看看</span>RSIC-V<span style="font-family:宋体">和</span>M3<span style="font-family:宋体">的加减乘除取余等等运算有什么区别。</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><b><span style="font-size:15.0pt"><span style="font-family:宋体">乘法运算:</span></span></b></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">M3</span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">RSIC-V</span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">简单的例子反汇编:</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">RSIC-V<span style="font-family:宋体">反汇编</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><b><span style="font-size:15.0pt"><span style="font-family:宋体">除法运算:</span></span></b></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">长期以来,</span></span></span></span></span></span> <span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">ARM-32 </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">只有乘法而无除法指令。直到第一台</span></span></span></span></span></span> <span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">ARM </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">处理器诞生的大约</span></span></span></span></span></span> <span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">20 </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">年后(</span></span></span></span></span></span><span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">2005 </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">年),除法指令才成为</span></span></span></span></span></span> <span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">ARM </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">的必要组成部分</span></span></span></span></span></span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">Cortex-M3</span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">包含两个硬件除法指令,</span></span></span></span></span></span> <span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">SDIV </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">和</span></span></span></span></span></span> <span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">UDIV</span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">(</span></span></span></span></span></span><span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">Thumb-2 </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">指令)</span></span></span></span></span></span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">RSIC-V</span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt"><span style="font-family:宋体">带除法指令,</span></span></span></span></span></span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">M3 <span style="font-family:宋体">整型除法汇编</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">RSIC-V <span style="font-family:宋体">浮点数除法汇编运算</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><b><span style="font-size:15.0pt"><span style="font-family:宋体">取余运算:</span></span></b></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">RV32M </span></span></span></span></span><span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt">具有有符号和无符号整数的除法指令: </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">divide(</span></span></span></span></span><span class="fontstyle31" style="font-family:SitkaText,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">div</span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">)</span></span></span></span></span><span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt">和 </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">divide unsigned(</span></span></span></span></span><span class="fontstyle31" style="font-family:SitkaText,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">divu</span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">)</span></span></span></span></span><span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt">,它们将商放入目标寄存器。在少数情况下,程序员需要余数而不是商,因此 </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">RV32M </span></span></span></span></span><span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt">提供</span></span></span></span></span><br />
<span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">remainder(</span></span></span></span></span><span class="fontstyle31" style="font-family:SitkaText,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">rem</span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">)</span></span></span></span></span><span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt">和 </span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">remainder unsigned(</span></span></span></span></span><span class="fontstyle31" style="font-family:SitkaText,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">remu</span></span></span></span></span><span class="fontstyle01" style="font-family:TimesNewRomanPSMT,serif"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span lang="EN-US" style="font-size:11.0pt">)</span></span></span></span></span><span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt">,它们在目标寄存器写入余数,而不是商。</span></span></span></span></span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span class="fontstyle21" style="font-family:宋体"><span style="color:black"><span style="font-weight:normal"><span style="font-style:normal"><span style="font-size:11.0pt">而M3是没有取余的,需要通过乘法和加减一起来实现。</span></span></span></span></span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><b><span style="font-size:15.0pt"><span style="font-family:宋体">试验跑起来</span></span></b></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">由于我逻辑分析仪是</span>20M<span style="font-family:宋体">采样率,我把</span>RSIC-V<span style="font-family:宋体">和</span>M3<span style="font-family:宋体">的主频都设置在了</span>24MHZ<span style="font-family:宋体">,否则测的不会很准,毕竟乘除法可能只是几个指令周期的活。</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">(</span>1<span style="font-family:宋体">)</span>num=i*j+i*k <span style="font-family:宋体">乘法</span> I j <span style="font-family:宋体">整型数据</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">(</span>2<span style="font-family:宋体">)</span>num=i*j <span style="font-family:宋体">乘法</span> I j float<span style="font-family:宋体">型数据</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">(</span>3<span style="font-family:宋体">)</span>num = i/j +i/k<span style="font-family:宋体">除法</span> I j<span style="font-family:宋体">是整型数据</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">M3<span style="font-family:宋体">是硬件除法器,在整型除法里耗时比</span>RISC-V<span style="font-family:宋体">要短。</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">(</span>4<span style="font-family:宋体">)</span>num = i/j+I/K <span style="font-family:宋体">除法</span> I j<span style="font-family:宋体">是</span>float<span style="font-family:宋体">型数据</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">在浮点数除法运算力,</span>RISC-V<span style="font-family:宋体">的表现是快了一半</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">(</span>5<span style="font-family:宋体">)</span>i%j+i%k<span style="font-family:宋体">整数取余</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">虽然</span>RISC-V<span style="font-family:宋体">的取余是直接得到,和</span>M3<span style="font-family:宋体">不一样,但是耗时却更加长了,不知道改的意义在哪里???</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">总体来说,</span>RISC-V<span style="font-family:宋体">和</span>Cortex-M3<span style="font-family:宋体">在同等频率、同等运算下进行测试,很多运算指令执行速度要相对快一些。</span></span></span></p>
页: [1]
查看完整版本: 第四篇 GD32VF103C START RISC-V和Corex-M3指令测试