讓人迷惑的無效指令。只是為了清零標(biāo)志位,結(jié)果多執(zhí)行很多無效指令,很奇怪

(gdb) si????????????????????? ?
0x000004b4????? 182???????????????????????????? USART1->STATR &= ~(USART_FLAG_TC|USART_FLAG_TXE);
?? 0x000004a8:?????? 83 57 07 80???? lhu???? a5,-2048(a4)
?? 0x000004ac:?????? 42 05?? slli??? a0,a0,0x10
?? 0x000004ae:?????? 41 81?? srli??? a0,a0,0x10
?? 0x000004b0:?????? c2 07?? slli??? a5,a5,0x10
?? 0x000004b2:?????? c1 83?? srli??? a5,a5,0x10
=> 0x000004b4:?????? 93 f7 f7 f3???? andi??? a5,a5,-193
?? 0x000004b8:?????? c2 07?? slli??? a5,a5,0x10
?? 0x000004ba:?????? c1 83?? srli??? a5,a5,0x10
?? 0x000004bc:?????? 23 10 f7 80???? sh????? a5,-2048(a4)
(gdb) source /tmp/print_ax,gdb
a0:00000066; a1:00000000; a2:20000100; a3:40013800;
a4:40014000; a5:00000392; a6:00000000; a7:00000000;
(gdb) x /8wx 0x40013800?????? ?
0x40013800:???? 0x00000392????? 0x00000000????? 0x000001a1????? 0x0000200c
0x40013810:???? 0x00000000????? 0x00000040????? 0x00000000????? 0x00000000
(gdb) si????????????????????? ?
0x000004b8????? 182???????????????????????????? USART1->STATR &= ~(USART_FLAG_TC|USART_FLAG_TXE);
?? 0x000004a8:?????? 83 57 07 80???? lhu???? a5,-2048(a4)? //a0:0x66
?? 0x000004ac:?????? 42 05?? slli??? a0,a0,0x10 //a0:0x660000 a5:0x0392
?? 0x000004ae:?????? 41 81?? srli??? a0,a0,0x10 //a0:0x66
?? 0x000004b0:?????? c2 07?? slli??? a5,a5,0x10 //a5:0x03920000
?? 0x000004b2:?????? c1 83?? srli??? a5,a5,0x10 //a5:0x0392
?? 0x000004b4:?????? 93 f7 f7 f3???? andi??? a5,a5,-193 //0x0312
=> 0x000004b8:?????? c2 07?? slli??? a5,a5,0x10? //0x03120000
?? 0x000004ba:?????? c1 83?? srli??? a5,a5,0x10? //0x0312
?? 0x000004bc:?????? 23 10 f7 80???? sh????? a5,-2048(a4)
(gdb) source /tmp/print_ax,gdb
a0:00000066; a1:00000000; a2:20000100; a3:40013800;
a4:40014000; a5:00000312; a6:00000000; a7:00000000;

不知道為何要加以上這么幾條無效的指令,增加程序還多運(yùn)行時(shí)間。+182>+180>+178>+174>+172>+170>+168>+166>+162>+182>+180>+178>+174>+172>+170>+168>+166>+162>

slli??? a0,a0,0x10
slli??? a0,a0,0x10
slli??? a5,a5,0x10
slli??? a5,a5,0x10

slli??? a5,a5,0x10
slli??? a5,a5,0x10

應(yīng)該是編譯器的問題。我記得之前有討論過,但是我不知道怎么查看我的回復(fù),論壇似乎只能查詢我發(fā)表的主題?


182 ????????????????????????????USART1->STATR &= ~(USART_FLAG_TC|USART_FLAG_TXE);
??0x00000408 <+164>: ??lhu ????a5,-2048(a4)
??0x0000040c <+168>: ??slli ???a5,a5,0x10
??0x0000040e <+170>: ??srli ???a5,a5,0x10
??0x00000410 <+172>: ??andi ???a5,a5,-193
??0x00000414 <+176>: ??slli ???a5,a5,0x10
??0x00000416 <+178>: ??srli ???a5,a5,0x10
??0x00000418 <+180>: ??sh ?????a5,-2048(a4)

183 ????????????????????????????USART1->DATAR = c;
=> 0x0000041c <+184>: ??sh ?????a0,4(a3)

使用riscv-none-elf-gcc v12 版本得到的代碼是少了兩條slli??? a0,a0,0x10,

兩種編譯器生成的程序都能正常運(yùn)行。這么看來是編譯器的問題。

我使用的優(yōu)化級(jí)別是-0S,生成這樣的指令不應(yīng)該??!


@夢珂0123有改進(jìn)的方案嗎?


終于整明白了,是半字存取指令與工作寄存器間為確保非需要位為零而做的操作。

但是字節(jié)存取指令卻不需要這樣。第一次遇上這樣的需求。


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频