.set偽指令(mips)

來源:互聯網
上載者:User

.set push --> save all settings
.set reorder/noreorder --> let/don't let assembler reorder instructions
.set at/noat --> let/don't let assembler use the register $at in instruction aliases (li,la, etc.)
.set pop --> restore saved settings

.set mipsn。n是一個從0到5的數字,或是數字32或64。1到5,32或64使彙編器從來源程式中的這一點開始接受相應ISA層級的指令。 .set mipsn 不僅影響允許使用那些指令,還影響到某些宏如何被擴充。 .set mips0保持原本的ISA層級:這個層級是您通過命令列選項選擇的,或者是您的配置的預設值。您可以通過這個特性在32位彙編模式中使用r4000的指令。小心使用這個命令!
命令‘.set mips16’使彙編器進入MIPS 16模式,傳統的彙編器不支援這個命令
偽操作 .set mips3 告訴彙編器下面的指令是MIPS IV(64位指令集,相容32位指令)中的指令。

1..set noreorder/reorder
預設彙編器處在reorder的模式下,該模式允許彙編器對指令進行重新排序,以避免流水線堵塞並獲得更好的效能,在這種模式下,是不允許在代碼中插入 nop指令的。反之,在noreorder模式下,指令的順序不會被改變也不會對代碼進行任何最佳化。這樣做的優點是程式員可以完全控制碼的執行順序,缺點是必須手工對指令排序,並在分支和載入指令的延遲槽中填上有用的指令或nop指令.比如:
.set noreorder
lw   t0, 0(a0)
nop        #載入指令延遲槽
sub  t0, 1
bne  t0, zero, loop
nop        #分支指令延遲槽
.set reorder
2. .set volatile/novolatile
處在volatile區的所有存取指令都不會被移動位置(特別是存取指令之間的相對位置)。這一點對訪問記憶體映射裝置的寄存器非常重要。因為對於外圍裝置而言,讀寫的次序十分重要。另外對讀狀態寄存器也非常重要。因為想得到的狀態都是最新的。舉例來說,如果下列代碼沒有使用.set volatile,那麼彙編器很有可能會對第二個lw指令移到指令的前面,因為這樣可以填充第一條lw指令的延遲槽:
.set volatile
lw   t0, 0(a0)
sw   t0, 0(a1)
lw   t0, 4(a0)
.set novalatile
避免流水線堵塞的操作以及其他各種最佳化措施不受該設定的影響.

 

《see mips run》關於.set指令的介紹:

.set directives:
These are used to tell the assembler how to do its work. By default,MIPS assemblers try to ?ll branch and load delay slots automatically by reorder-
ing the instructions around them(but don’tworry—the assembler never moves instructions around in ways that are unsafe; it leaves delay slots
un?lled if it can’t ?nd a safe rearrangement). Most of the time this is helpful, because itmeans you don’t have to worry about ?lling delay slots
as you write your assembly files.
But what if we need to retain precise control over instruction ordering, as in the case of a heavily used library function? This is the purpose of the .set noreorder directive: It tells the assembler to suppress its reordering capabilities until the next time
it encounters a corresponding
.set reorder directive.
For the section of code enclosed between this pair of directives, we’re telling the assembler to put the op-codes it generates into the object file in the same order as the instructions are written.
Labels: “1:” is a numeric label, which most assemblers will accept as a local label. You can have as many labels called “1” as you like in a pro-gram; a reference to “1f ” (forward) will get the next one in sequence and “1b” (back) the previous one. That’s
very useful.
Instructions: You’ll notice some unexpected sequences, since the .set noreorder exposes the underlying branch delay slots, and leaves us to ensure (for ef?ciency) that load data is never used by the following instruction.
For example, note the use of register t2 in the second half of the unrolled loop. It’s necessary to use a second register because the lbu t2,-1(a0) is in the delay slot of the preceding branch instruction and thereforemust not overwrite t0—if the branch is
taken, the code at its target will make use of the value in t0.

 

《see mips run》最後的“mips glossary”裡也有提到:

noat, nomacro, noreorder: Assembly language controls, which provide the programmer with a way of disabling some more complicated things the assem-bler does and that are not always welcome (the corresponding names without the “no” switch the features back
on again).
.set noat prevents the assembler from translating assembly code into binary sequences relying on the at/$1 register.
.set nomacro prevents the assembler from translating a single assembly statement into more than one instruction.
.set noreorder prevents the assembler fromjuggling the code sequence to move useful instructions into the branch delay slot.

《see mips run》中文版
noat, nomacro, noreorder: 組合語言控制操作,為程式員提供了一種方式來關閉彙編器做的一些更複雜的工作,這些工作不總是受歡迎的(相應的沒有“no”的名字將該特性重新開啟)
.set noat 阻止彙編器將彙編代碼翻譯成二進位序列依賴at/$1寄存器
.set nomacro 阻止彙編器將一條彙編代碼翻譯成多條指令
.set noreorder 阻止彙編器調整代碼序列來將有用的指令放入分支延遲槽。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.