Re: 請問MMX與GCC C & ASM的問題

看板ASM (組合語言)作者 (耶 很棒)時間18年前 (2007/05/24 18:21), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/4 (看更多)
※ 引述《yanming (雪地中的雁子)》之銘言: : ※ 引述《zxvc (zxvc)》之銘言: : : 最近作專題要編譯一個程式: : : http://iie.fing.edu.uy/investigacion/grupos/gmm/proyectos/tararira/ingles.php3 : : 不過這程式是用C語言與x86指令寫的, : : 這程式的原作者似乎是用gcc 3編譯的。 : : 可是我手邊的機器多是用gcc 4, : : 結果編譯的時候出現一堆問題,我試著看看自己有沒有能力修正。 : : 之前也沒有用過MMX與GCC C & ASM,只在MASM上寫過一點x86。 : : 我現在遇到一個問題, : : 就是以下我自己寫的一個小程式為什麼無法用gcc編譯成功呢? : : 我的編譯器是gcc 4.0.3,編譯的時候出現這個錯誤: : : gcc test.c -mmmx : : test.c: In function 'main': : : test.c:9: error: impossible register constraint in 'asm' : : test.c:15: confused by earlier errors, bailing out : : ~~~~~~~~~~~~~~~~~~~ test.c ~~~~~~~~~~~~~~~~~~~~ : : #include <stdlib.h> : : #include <stdio.h> : : int main () : : { : : double a, b; : : a = 5.0; : : b = 0.0; : : asm ( : : "movq %1, %0 \n\t" : : : "=y" (b) : : : "m" (a)); : : printf ("Hello world.: %6.2f\n", b); : : return 0; : : } : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ : : 『: "=y" (b)』那一行我是參考這篇文章設定的: : : http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Machine-Constraints.html#Machine-Constraints : : 或者縮減網址: : : http://0rz.tw/ce2AA : : 希望有高手能幫我解答,謝謝。 : __asm{movq xmm0,temp_int} : 請問當我在用 intel inline assembly 時, : 編譯到這一行時, : .net 會出現 "不合法的資料型態"的錯誤類別 : 改成 __asm{movq mm0,temp_int} 時就可以正確運作 : 這是由於 xmm0 是浮點數暫存器的關係嗎? : 如果是,那要怎麼使用 SSE 的指令呢?(xmm0 ~ xmm7 都不能用嗎?) 前言 (廢話): mm0 ~ mm7 是 MMX registers (各 64-bit, 跟 fpu stack 有對應關係,很煩的) xmm0 ~ xmm7 是 SSE 新加的沒錯,各 128-bit,為獨立單元 movq 這個指令當初是跟 MMX 一併加入的,只能作用在 MMX registers 上 後來 SSE1 雖然加上 xmm0 ~ xmm7,但此時 movq 還不能用在 xmm0 ~ xmm7 上喔 到了 SSE2,Intel 把 movq 這類指令也加上了可以作用在 xmm registers 上的 form "All of 64-bit SIMD integer instructions introduced with MMX technology and SSE extensions (with the exception of the PSHUFW instruction) have been extended by SSE2 extensions to operate on 128-bit packed integer operands located in XMM registers" (Intel 這麼做的目的,是為了全面抛棄 MMX, 以前的 MMX code 只要把 mm0 ~ mm7 都換成 xmm0 ~ xmm7,再重新 assemble/compile 大部份都不需要手動去改...) 例如 movq xmm0, mem 就會從 mem 拿 64 bits 放進 xmm0[63:0],xmm0[127:64] 則填 0 好啦,講了這麼多廢話, 大概給你兩個建議: 1. 不要再用 mm0 ~ mm7,全改用 xmm0 ~ xmm7 吧 2. 換新的 compiler,確定可以支援 SSE2 的... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.25.140 ※ 編輯: l71cm 來自: 140.112.25.140 (05/24 18:25)
文章代碼(AID): #16LMSLJK (ASM)
討論串 (同標題文章)
本文引述了以下文章的的內容:
以下文章回應了本文
完整討論串 (本文為第 3 之 4 篇):
文章代碼(AID): #16LMSLJK (ASM)