.set僞指令(mips)

.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 阻止彙編器調整代碼序列來將有用的指令放入分支延遲槽。


Ref: http://blog.csdn.net/adaptiver/article/details/6760220

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章