日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【Verilog语法】PC-relatve branch 以及 Delay Slot 的含义

發(fā)布時間:2024/2/28 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Verilog语法】PC-relatve branch 以及 Delay Slot 的含义 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.


簡單來說,PC-relatve 是PC相對尋址。與之相反的是絕對尋址(在當前PC所在的region中尋址)

[討論] 談談SH系列的 Delay Slot 延遲槽 和 branch指令

今天在調試SH2A時,CPU很意外的進入了delay slot中斷。
對于Delay Slot這個概率,不是很清楚,于是網上搜索了一下資料。

我們可以將Delay Slot翻譯為延遲槽。流水線結構的CPU在執(zhí)行分支branch或者跳轉jump指令時,由于此過程時間比較長,需要延遲一下,故可在此段時間內執(zhí)行下一條指令,這就是branch delay slot的概念。

但如果在延遲槽的時間內執(zhí)行一條未譯碼的指令時(也就是該指令來不及譯碼,延遲槽就結束了),會發(fā)生此類中斷(SH2A為例)。所以常常可見編譯器將高級語言翻譯為匯編代碼時,插入NOP指令來等待延遲。


先看段代碼:(取自 linux 2.6.17 for godson2)

801ea9d4: 02202021 move a0,s1 801ea9d8: 27a50014 addiu a1,sp,20 801ea9dc: 0c0ce551 jal 80339544 <pcibios_resource_to_bus> 801ea9e0: 02403021 move a2,s2 801ea9e4: 8e240010 lw a0,16(s1) ...

pcibios_resource_to_bus 的原型是:

void __devinit pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, struct resource *res);

其中,在有HOTPLUG的情況下

__devinit <=> __init <=> __attribute__ ((__section__ (".init.text")))

表示把該 pcibios_resource_to_bus 生成的機器碼置于初始化代碼節(jié)(詳細定義于include/linux/init.h)
jal (jump and link) 類似于x86 的 call

回到最上面的匯編碼,很明顯在調用 pcibios_resource_to_bus 前,先要向 a0, a1, a2 中置入3個參數, 可是我們看到第三個參數居然在 jal 后面!這就是 branch delay slot,從名字猜測應該是跳轉延遲,也就是當執(zhí)行到 jal 這條指令時,延遲一下,把下面的 move 指令執(zhí)行完后再執(zhí)行這條 jal 。

一直以來就這樣理解,有點困惑,今天特意查了下:(取自維基百科)

Many of these early RISC designs also shared a not-so-nice feature, the branch delay slot. A branch delay slot is an instruction space immediately following a jump or branch. The instruction in this space is executed whether or not the branch is taken (in other words the effect of the branch is delayed). This instruction keeps the ALU of the CPU busy for the extra time normally needed to perform a branch. Nowadays the branch delay slot is considered an unfortunate side effect of a particular strategy for implementing some RISC designs, and modern RISC designs generally do away with it (such as PowerPC, more recent versions of SPARC, and MIPS).

可以看出,上面的 “move a2, s2” 是位于 branch delay slot 中的,應該是跳轉類型的指令執(zhí)行時間相對來說有點長,需要處于 branch delay slot 中的指令,占據 ALU 來贏去跳轉類型指令相對多的執(zhí)行時間。

如果把 “move a2, s2” 移到 jal 指令前,那處于branch delay slot 的就是 “l(fā)w a0,16(s1)”, 很明顯當CPU執(zhí)行到"jal 80339544" 時,由于時間稍長,那 “l(fā)w a0, 16(s1)” 就會被執(zhí)行,很明顯這將導致傳給 pcibios_resource_to_bus 的第一個參數被覆蓋.顯然這類指令順序的調整是編譯器干的.

總結

以上是生活随笔為你收集整理的【Verilog语法】PC-relatve branch 以及 Delay Slot 的含义的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。