PCDVD數位科技討論區

PCDVD數位科技討論區 (https://www.pcdvd.com.tw/index.php)
-   系統組件 (https://www.pcdvd.com.tw/forumdisplay.php?f=19)
-   -   一個 Intel 指令問題 (https://www.pcdvd.com.tw/showthread.php?t=1157601)

拿破崙波拿巴 2019-01-30 09:48 AM

一個 Intel 指令問題
 
https://www.felixcloutier.com/x86/andn

解說有點看不懂 :D

範例 opcode:
代碼:
andn  eax, ecx, edx


Performs a bitwise logical AND of inverted second operand (the first source operand) with the third operand (the second source operand). The result is stored in the first operand (destination operand).


Operand 1 mod.reg eax
Operand 2 vex.vvvv ecx
Operand 3 mod.r/m edx

到底是 Operand 1 = Operand 3 & Operand 2
還是 Operand 1 = Operand 2 & Operand 3


:confused:

abcpanadol 2019-01-30 10:43 AM

引用:
作者拿破崙波拿巴
https://www.felixcloutier.com/x86/andn

解說有點看不懂 :D

..........
到底是 Operand 1 = Operand 3 & Operand 2
還是 Operand 1 = Operand 2 & Operand 3


:confused:



Operand 1 = Operand 3 & Operand 2
Operand 1 = Operand 2 & Operand 3

這兩者相同意思啊
Operand 3 & Operand 2= Operand 2 & Operand 3
這有什麼問題呢???

youporn 2019-01-30 11:29 AM

引用:
作者拿破崙波拿巴
https://www.felixcloutier.com/x86/andn

解說有點看不懂 :D

範例 opcode:
andn eax, ecx, edx

Performs a bitwise logical AND of inverted second operand (the first source operand) with the third operand (the second source operand). The result is stored in the first operand (destination operand).


Operand 1 mod.reg eax
Operand 2 vex.vvvv ecx
Operand 3 mod.r/m edx

到底是 Operand 1 = Operand 3 & Operand 2
還是 Operand 1 = Operand 2 & Operand 3


:confused:

都不對啊 :laugh:

DEST ← (NOT SRC1) bitwiseAND SRC2;

拿破崙波拿巴 2019-01-30 01:21 PM

引用:
作者youporn
都不對啊 :laugh:

DEST ← (NOT SRC1) bitwiseAND SRC2;


所以我就覺得奇怪 有點難理解 :D

拿破崙波拿巴 2019-01-30 08:12 PM

引用:
作者youporn
都不對啊 :laugh:

DEST ← (NOT SRC1) bitwiseAND SRC2;


我終於看懂了 :D

https://software.intel.com/sites/la...&expand=298,299


代碼:
__int64 _andn_u64 (unsigned __int64 a, unsigned __int64 b)

dst[63:0] := ((NOT a[63:0]) AND b[63:0])


https://gcc.gnu.org/ml/gcc-patches/...cases.gcc.patch

代碼:
long long calc_andn_u64 (long long src1,
			 long long src2,
			 long long dummy)
{
  return (~src1 + dummy) & (src2);
}

:laugh: :laugh:


asccpu 2019-01-30 08:55 PM

也就是以下的合併?
代碼:
NOT  ECX
AND  ECX,EDX
MOV  EAX,ECX


真精簡

拿破崙波拿巴 2019-01-30 09:15 PM

引用:
作者asccpu
也就是以下的合併?

NOT ECX
AND ECX,EDX
MOV EAX,ECX


真精簡


有沒有 AVX Opcode 轉 SSEx 或 8086 操作代碼的參考資料

類似

mov rdx, [rbx+20h]
mov r9, 0C0C0C0C0C0C0C0C1h
mulx rsi, rcx, r9


mul

之類的

asccpu 2019-01-31 09:39 AM

其實CPU指令研究,我早在10多年就不再熱血了,因此不知AVX是什....
不過現在特地找一下AVX說明,看來I公司有意將8051系列指令運作方式改良用在X86上,X86離精簡指令集又更進一步了。

有關你的問題....難
要互換需對這2種指令清楚,例如 8051轉X86指令,先要明白8051指令運作方式,再由X86中選擇相同或相類似出來再取合用,簡單說就是移植,所以這幾乎要用人工。
當然也可寫成轉換程式,這相當於寫組譯程式一樣的大工程。不過最後轉完還是得用人工一一檢視合不合理。
http://ref.x86asm.net/ 這站不知有沒有你想要的資料,可以看看。

上面我所寫的片段,事實上有BUG存在,因為會破壞第2個參數內容,我想INTEL是不允許的。比較合理的轉換為:
1 把參數2複製到參數1
2 把參數1,行1的補數處理
3 把參數1與參數3做AND運算,結果存回參數1處
如此,參數2沒被破壞

拿破崙波拿巴 2019-01-31 10:22 AM

引用:
作者asccpu
其實CPU指令研究,我早在10多年就不再熱血了,因此不知AVX是什....
不過現在特地找一下AVX說明,看來I公司有意將8051系列指令運作方式改良用在X86上,X86離精簡指令集又更進一步了。

有關你的問題....難
要互換需對這2種指令清楚,例如 8051轉X86指令,先要明白8051指令運作方式,再由X86中選擇相同或相類似出來再取合用,簡單說就是移植,所以這幾乎要用人工。
當然也可寫成轉換程式,這相當於寫組譯程式一樣的大工程。不過最後轉完還是得用人工一一檢視合不合理。
http://ref.x86asm.net/ 這站不知有沒有你想要的資料,可以看看。

上面我所寫的片段,事實上有BUG存在,因為會破壞第2個參數內容,我想INTEL是不允許的。比較合理的轉換為:
1 把參數2複製到參數1
2 把參數1,行1的補數處理
3 把參數1與參數3做AND運算,結果存回參數1處
如此,參數2沒被破壞


我用的是 Pentium 處理器 暫存器大小只有128-bit
我發現 VEX128-bit 以下指令可以模擬 直接將計算結果寫到 XMM 暫存器

但是 VEX128-bit 以上的指令好像沒辦法把 dest 資料直接寫到實體的 XMM 暫存器

就算把 計算完的結果存到 uint256_t 的 dest 也頂多只能把 dest [127:0] 寫到 XMM
如果計算完的結果在128-bit 內 還可以, 如果大小超過 128-bit 就會出錯

如果要處理 帶 YMM 或 ZMM 指令 好像只能像你上面的方法把 操作代碼拆開
:think:

但也要看後面是什麼指令, 不過大部份好像都會出問題 :D

我目前只完成 BMI1/2 指令的模擬, 還想添加 AES FMA ... 等指令 提昇 Pentium C/P 值 :D :D

現在讓我最頭痛的就是 VEX 版本的 SSE-SSE4.x 的 AVX 指令, 因為數量實在太大 ...

youporn 2019-01-31 11:43 AM

好奇樓主模擬非原生指令集的目的?


所有的時間均為GMT +8。 現在的時間是12:41 AM.

vBulletin Version 3.0.1
powered_by_vbulletin 2025。