user-0 提问: window C的内嵌汇编转linux C 的内嵌汇编

回复:
user: user-0
content: 我是这样想的，DECODE_YUYV_MMX_line  这个函数里的发错了，不知道谁能确定一下能那样改不？

user: user-0
content: 引用 11 楼 zhao4zhong1 的回复:-msse3  Support MMX, SSE, SSE2 and SSE3 built-in functions and code generation  ？  这个我是这个加的    gcc asm.c  -o asm -mmmx  又试了 gcc asm.c  -o asm -msse3 错误还是依旧

user: user-1
content: -msse3  Support MMX, SSE, SSE2 and SSE3 built-in functions and code generation  ？

user: user-0
content: 引用 8 楼 derekrose 的回复:通不过编译 报错？asm.c:274:9: 以下是报错 error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter asm.c:274:9: error: invalid 'asm': operand number missing after %-letter

user: user-0
content: 是啊，都通过不了

user: user-2
content: 通不过编译 报错？

user: user-0
content: void DECODE_YUYV_MMX_line(TARGB32* pDstLine,const TUInt8* pYUYV,long width) {     long expand8_width=(width>>3)<<3;          if (expand8_width>0)     {         __asm__ volatile(             "mov     %ecx,(%2)\n\t"             "mov     %eax,(%0)\n\t"             "mov     %edx,(%1)\n\t"             "lea     %eax,[%eax+%ecx*2]\n\t"             "lea     %edx,[%edx+%ecx*4]\n\t"             "neg     %ecx\n\t"                        "loop_beign:\n\t"             // YUYV_Loader_MMX(%eax+%ecx*2)             // YUV422ToRGB32_MMX(%edx+%ecx*4,movq)              "add     %ecx,8\n\t"             "jnz     loop_beign\n\t"              "mov     (%0),%eax\n\t"             "mov     (%1),%edx\n\t"             :"=r"(pYUYV),"=r"(pDstLine),"=r"(expand8_width)             :             :"memory","%eax","%edx","%ecx");     }      //处理边界     DECODE_YUYV_Common_line(pDstLine,pYUYV,width-expand8_width); }  void DECODE_YUYV_MMX(const TUInt8* pYUYV,const TPicRegion* DstPic) {     assert((DstPic->width & 1)==0);           long YUV_byte_width=(DstPic->width>>1)<<2,y;     TARGB32* pDstLine=DstPic->pdata;      for (y=0;y<DstPic->height;++y)     {         DECODE_YUYV_MMX_line(pDstLine,pYUYV,DstPic->width);         pYUYV+=YUV_byte_width;         pDstLine+=DstPic->byte_width>>2;     }         // asm emms     __asm__ volatile ("emms" ::: "memory"); }

user: user-0
content: 引用 5 楼 zhao4zhong1 的回复:gcc-inline-asm.pdf这个我看了，但是初学，问题很多。 下面是我关于这个方面的改变  //一次处理8个颜色输出 #define YUV422ToRGB32_MMX(out_RGB_reg,WriteCode)                                                 \    /*input :  mm0 = Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0    */                                                \    /*         mm1 = 00 u3 00 u2 00 u1 00 u0    */                                                \    /*         mm2 = 00 v3 00 v2 00 v1 00 v0    */                                                \    /*output : [out_RGB_reg -- out_RGB_reg+8*4]                 */                                \                                                                                                  \       __asm__ volatile(   "psubusb     %%mm0,(%0)\n\t"        /* %%mm0 : Y -= 16                       */      \                           "psubsw      %%mm1,(%1)\n\t"       /* %%mm1 : u -= 128                      */      \                           "movq        %%mm7,%%mm0\n\t"                                                              \                           "psubsw      %%mm2,(%1)\n\t"       /* %%mm2 : v -= 128                      */      \                           "pand        %%mm0,(%2)\n\t"    /* %%mm0 = 00 Y6 00 Y4 00 Y2 00 Y0       */      \                           "psllw       %%mm1,3\n\t"                 /* %%mm1 : u *= 8                        */      \                           "psllw       %%mm2,3\n\t"                 /* %%mm2 : v *= 8                        */      \                           "psrlw       %%mm7,8\n\t"                 /* %%mm7 = 00 Y7 00 Y5 00 Y3 00 Y1       */      \                           "movq        %%mm3,%%mm1\n\t"                                                              \                           "movq        %%mm4,%%mm2\n\t"                                                              \                                                                                              \                           "pmulhw      %%mm1,(%5)\n\t"   /* %%mm1 = u * U_green                   */      \                           "psllw       %%mm0,3\n\t"                 /* y*=8                                */      \                           "pmulhw      %%mm2,(%6)\n\t"   /* %%mm2 = v * V_green                   */      \                           "psllw       %%mm7,3\n\t"                 /* y*=8                                */      \                           "pmulhw      %%mm3,(%4)\n\t"                                                   \                           "paddsw      %%mm1,%%mm2\n\t"                                                              \                           "pmulhw      %%mm4,(%7)\n\t"                                                    \                           "movq        %%mm2,%%mm3\n\t"                                                              \                           "pmulhw      %%mm0,(%3)\n\t"                                                  \                           "movq        %%mm6,%%mm4\n\t"                                                              \                           "pmulhw      %%mm7,(%3)\n\t"                                                  \                           "movq        %%mm5,%%mm1\n\t"                                                              \                           "paddsw      %%mm3,%%mm0\n\t"               /* %%mm3 = B6 B4 B2 B0       */                  \                           "paddsw      %%mm2,%%mm7\n\t"               /* %%mm2 = B7 B5 B3 B1       */                  \                           "paddsw      %%mm4,%%mm0\n\t"               /* %%mm4 = R6 R4 R2 R0       */                  \                           "paddsw      %%mm6,%%mm7\n\t"               /* %%mm6 = R7 R5 R3 R1       */                  \                           "paddsw      %%mm1,%%mm0\n\t"               /* %%mm1 = G6 G4 G2 G0       */                  \                           "paddsw      %%mm5,%%mm7\n\t"               /* %%mm5 = G7 G5 G3 G1       */                  \                                                                                              \                           "packuswb    %%mm3,%%mm4\n\t"               /* %%mm3 = R6 R4 R2 R0 B6 B4 B2 B0 to [0-255] */ \                           "packuswb    %%mm2,%%mm6\n\t"               /* %%mm2 = R7 R5 R3 R1 B7 B5 B3 B1 to [0-255] */ \                           "packuswb    %%mm5,%%mm1\n\t"               /* %%mm5 = G6 G4 G2 G0 G7 G5 G3 G1 to [0-255] */ \                           "movq        %%mm4,%%mm3\n\t"                                                              \                           "punpcklbw   %%mm3,%%mm2\n\t"               /* %%mm3 = B7 B6 B5 B4 B3 B2 B1 B0     */        \                           "punpckldq   %%mm1,%%mm5\n\t"               /* %%mm1 = G7 G5 G3 G1 xx xx xx xx     */        \                           "punpckhbw   %%mm4,%%mm2\n\t"               /* %%mm4 = R7 R6 R5 R4 R3 R2 R1 R0     */        \                           "punpckhbw   %%mm5,%%mm1\n\t"               /* %%mm5 = G7 G6 G5 G4 G3 G2 G1 G0     */        \                                                                                              \             /*out*/                                                                          \                           "pcmpeqb     %%mm2,%%mm2\n\t"               /* %%mm2 = FF FF FF FF FF FF FF FF     */        \                                                                                              \                           "movq        %%mm0,%%mm3\n\t"                                                              \                           "movq        %%mm7,%%mm4\n\t"                                                              \                           "punpcklbw   %%mm0,%%mm5\n\t"             /* %%mm0 = G3 B3 G2 B2 G1 B1 G0 B0       */        \                           "punpcklbw   %%mm7,%%mm2\n\t"             /* %%mm7 = FF R3 FF R2 FF R1 FF R0       */        \                           "movq        %%mm1,%%mm0\n\t"                                                              \                           "movq        %%mm6,%%mm3\n\t"                                                              \                           "punpcklwd   %%mm0,%%mm7\n\t"             /* %%mm0 = FF R1 G1 B1 FF R0 G0 B0       */        \                           "punpckhwd   %%mm1,%%mm7\n\t"             /* %%mm1 = FF R3 G3 B3 FF R2 G2 B2       */        \                           "WriteCode   [out_RGB_reg],%%mm0\n\t"                                                    \                           "movq        %%mm7,%%mm4\n\t"                                                              \                           "punpckhbw   %%mm6,%%mm5\n\t"             /* %%mm6 = G7 B7 G6 B6 G5 B5 G4 B4       */        \                           "WriteCode   [out_RGB_reg+8],%%mm1\n\t"                                                  \                           "punpckhbw   %%mm7,%%mm2\n\t"             /* %%mm7 = FF R7 FF R6 FF R5 FF R4      */         \                           "movq        %%mm0,%%mm6\n\t"                                                              \                           "punpcklwd   %%mm6,%%mm7\n\t"             /* %%mm6 = FF R5 G5 B5 FF R4 G4 B4      */         \                           "punpckhwd   %%mm0,%%mm7\n\t"             /* %%mm0 = FF R7 G7 B7 FF R6 G6 B6      */         \                           "WriteCode  [out_RGB_reg+8*2],%%mm6\n\t"                                                 \                           "WriteCode  [out_RGB_reg+8*3],%%mm0\n\t"                                               \                           :"r"(csMMX_16_b),"r"(csMMX_128_w),"r"(csMMX_0x00FF_w),"r"(csMMX_Y_coeff_w),"r"(csMMX_U_blue_w),"r"(csMMX_U_green_w),"r"(csMMX_V_green_w),"r"(csMMX_V_red_w)\                           :\                           :"memory", "%eax");    #define YUYV_Loader_MMX(in_yuv_reg)                                                         \    __asm__ volatile ("movq        %%mm0,[in_yuv_reg  ]\n\t" /*%%mm0=V1 Y3 U1 Y2 V0 Y1 U0 Y0  */                \                      "movq        %%mm4,[in_yuv_reg+8]\n\t" /*%%mm4=V3 Y7 U3 Y6 V2 Y5 U2 Y4  */                \                      "movq        %%mm1,%%mm0           \n\t"                                                  \                      "movq        %%mm5,%%mm4           \n\t"                                                  \                      "psrlw       %%mm1,8             \n\t" /*%%mm1=00 V1 00 U1 00 V0 00 U0  */                \                      "psrlw       %%mm5,8             \n\t" /*%%mm5=00 V3 00 U3 00 V2 00 U2  */                \                      "pand        %%mm0,(%0)\n\t" /*%%mm0=00 Y3 00 Y2 00 Y1 00 Y0  */                \                      "pand        %%mm4,(%0)\n\t" /*%%mm4=00 Y7 00 Y6 00 Y5 00 Y4  */                \                      "packuswb    %%mm1,%%mm5           \n\t" /*%%mm1=V3 U3 V2 U2 V1 U1 V0 U0  */                \                      "movq        %%mm2,%%mm1           \n\t"                                                  \                      "packuswb    %%mm0,%%mm4           \n\t" /*%%mm0=Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0  */                \                      "psllw       %%mm1,8             \n\t" /*%%mm1=U3 00 U2 00 U1 00 U0 00  */                \                      "psrlw       %%mm2,8             \n\t" /*%%mm2=00 V3 00 V2 00 V1 00 V0  */                \                      "psrlw       %%mm1,8             \n\t" /*mm1=00 U3 00 U2 00 U1 00 U0  */                \                      : "r" (csMMX_0x00FF_w)\                      :\                      :"memory" );

user: user-1
content: gcc-inline-asm.pdf

user: user-0
content: #define YUV422ToRGB32_MMX(out_RGB_reg,WriteCode)                                                 \    /*input :  mm0 = Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0    */                                                \    /*         mm1 = 00 u3 00 u2 00 u1 00 u0    */                                                \    /*         mm2 = 00 v3 00 v2 00 v1 00 v0    */                                                \    /*output : [out_RGB_reg -- out_RGB_reg+8*4]                 */                                \                                                                                                  \           asm   psubusb     mm0,csMMX_16_b        /* mm0 : Y -= 16                       */      \           asm   psubsw      mm1,csMMX_128_w       /* mm1 : u -= 128                      */      \           asm   movq        mm7,mm0                                                              \           asm   psubsw      mm2,csMMX_128_w       /* mm2 : v -= 128                      */      \           asm   pand        mm0,csMMX_0x00FF_w    /* mm0 = 00 Y6 00 Y4 00 Y2 00 Y0       */      \           asm   psllw       mm1,3                 /* mm1 : u *= 8                        */      \           asm   psllw       mm2,3                 /* mm2 : v *= 8                        */      \           asm   psrlw       mm7,8                 /* mm7 = 00 Y7 00 Y5 00 Y3 00 Y1       */      \           asm   movq        mm3,mm1                                                              \           asm   movq        mm4,mm2                                                              \                                                                                                  \           asm   pmulhw      mm1,csMMX_U_green_w   /* mm1 = u * U_green                   */      \           asm   psllw       mm0,3                 /* y*=8                                */      \           asm   pmulhw      mm2,csMMX_V_green_w   /* mm2 = v * V_green                   */      \           asm   psllw       mm7,3                 /* y*=8                                */      \           asm   pmulhw      mm3,csMMX_U_blue_w                                                   \           asm   paddsw      mm1,mm2                                                              \           asm   pmulhw      mm4,csMMX_V_red_w                                                    \           asm   movq        mm2,mm3                                                              \           asm   pmulhw      mm0,csMMX_Y_coeff_w                                                  \           asm   movq        mm6,mm4                                                              \           asm   pmulhw      mm7,csMMX_Y_coeff_w                                                  \           asm   movq        mm5,mm1                                                              \           asm   paddsw      mm3,mm0               /* mm3 = B6 B4 B2 B0       */                  \           asm   paddsw      mm2,mm7               /* mm2 = B7 B5 B3 B1       */                  \           asm   paddsw      mm4,mm0               /* mm4 = R6 R4 R2 R0       */                  \           asm   paddsw      mm6,mm7               /* mm6 = R7 R5 R3 R1       */                  \           asm   paddsw      mm1,mm0               /* mm1 = G6 G4 G2 G0       */                  \           asm   paddsw      mm5,mm7               /* mm5 = G7 G5 G3 G1       */                  \                                                                                                  \           asm   packuswb    mm3,mm4               /* mm3 = R6 R4 R2 R0 B6 B4 B2 B0 to [0-255] */ \           asm   packuswb    mm2,mm6               /* mm2 = R7 R5 R3 R1 B7 B5 B3 B1 to [0-255] */ \           asm   packuswb    mm5,mm1               /* mm5 = G6 G4 G2 G0 G7 G5 G3 G1 to [0-255] */ \           asm   movq        mm4,mm3                                                              \           asm   punpcklbw   mm3,mm2               /* mm3 = B7 B6 B5 B4 B3 B2 B1 B0     */        \           asm   punpckldq   mm1,mm5               /* mm1 = G7 G5 G3 G1 xx xx xx xx     */        \           asm   punpckhbw   mm4,mm2               /* mm4 = R7 R6 R5 R4 R3 R2 R1 R0     */        \           asm   punpckhbw   mm5,mm1               /* mm5 = G7 G6 G5 G4 G3 G2 G1 G0     */        \                                                                                                  \                 /*out*/                                                                          \           asm   pcmpeqb     mm2,mm2               /* mm2 = FF FF FF FF FF FF FF FF     */        \                                                                                                  \           asm   movq        mm0,mm3                                                              \           asm   movq        mm7,mm4                                                              \           asm   punpcklbw   mm0,mm5             /* mm0 = G3 B3 G2 B2 G1 B1 G0 B0       */        \           asm   punpcklbw   mm7,mm2             /* mm7 = FF R3 FF R2 FF R1 FF R0       */        \           asm   movq        mm1,mm0                                                              \           asm   movq        mm6,mm3                                                              \           asm   punpcklwd   mm0,mm7             /* mm0 = FF R1 G1 B1 FF R0 G0 B0       */        \           asm   punpckhwd   mm1,mm7             /* mm1 = FF R3 G3 B3 FF R2 G2 B2       */        \           asm   WriteCode   [out_RGB_reg],mm0                                                    \           asm   movq        mm7,mm4                                                              \           asm   punpckhbw   mm6,mm5             /* mm6 = G7 B7 G6 B6 G5 B5 G4 B4       */        \           asm   WriteCode   [out_RGB_reg+8],mm1                                                  \           asm   punpckhbw   mm7,mm2             /* mm7 = FF R7 FF R6 FF R5 FF R4      */         \           asm   movq        mm0,mm6                                                              \           asm   punpcklwd   mm6,mm7             /* mm6 = FF R5 G5 B5 FF R4 G4 B4      */         \           asm   punpckhwd   mm0,mm7             /* mm0 = FF R7 G7 B7 FF R6 G6 B6      */         \           asm   WriteCode  [out_RGB_reg+8*2],mm6                                                 \           asm   WriteCode  [out_RGB_reg+8*3],mm0                                           //YUV视频格式到RGB32格式的转换函数，MMX指令实现版本     #define YUYV_Loader_MMX(in_yuv_reg)                                                         \           asm   movq        mm0,[in_yuv_reg  ] /*mm0=V1 Y3 U1 Y2 V0 Y1 U0 Y0  */                \           asm   movq        mm4,[in_yuv_reg+8] /*mm4=V3 Y7 U3 Y6 V2 Y5 U2 Y4  */                \           asm   movq        mm1,mm0                                                             \           asm   movq        mm5,mm4                                                             \           asm   psrlw       mm1,8              /*mm1=00 V1 00 U1 00 V0 00 U0  */                \           asm   psrlw       mm5,8              /*mm5=00 V3 00 U3 00 V2 00 U2  */                \           asm   pand        mm0,csMMX_0x00FF_w /*mm0=00 Y3 00 Y2 00 Y1 00 Y0  */                \           asm   pand        mm4,csMMX_0x00FF_w /*mm4=00 Y7 00 Y6 00 Y5 00 Y4  */                \           asm   packuswb    mm1,mm5            /*mm1=V3 U3 V2 U2 V1 U1 V0 U0  */                \           asm   movq        mm2,mm1                                                             \           asm   packuswb    mm0,mm4            /*mm0=Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0  */                \           asm   psllw       mm1,8              /*mm1=U3 00 U2 00 U1 00 U0 00  */                \           asm   psrlw       mm2,8              /*mm2=00 V3 00 V2 00 V1 00 V0  */                \           asm   psrlw       mm1,8              /*mm1=00 U3 00 U2 00 U1 00 U0  */                          void DECODE_YUYV_MMX_line(TARGB32* pDstLine,const TUInt8* pYUYV,long width)     {         long expand8_width=(width>>3)<<3;                  if (expand8_width>0)         {             asm             {                 mov     ecx,expand8_width                 mov     eax,pYUYV                 mov     edx,pDstLine                 lea     eax,[eax+ecx*2]                 lea     edx,[edx+ecx*4]                 neg     ecx                                loop_beign:                 YUYV_Loader_MMX(eax+ecx*2)                 YUV422ToRGB32_MMX(edx+ecx*4,movq)                  add     ecx,8                 jnz     loop_beign                  mov     pYUYV,eax                 mov     pDstLine,edx             }         }          //处理边界         DECODE_YUYV_Common_line(pDstLine,pYUYV,width-expand8_width);     }  void DECODE_YUYV_MMX(const TUInt8* pYUYV,const TPicRegion* DstPic) {           long YUV_byte_width=(DstPic->width>>1)<<2,y;     TARGB32* pDstLine=DstPic->pdata;      for (y=0;y<DstPic->height;++y)     {         DECODE_YUYV_MMX_line(pDstLine,pYUYV,DstPic->width);         pYUYV+=YUV_byte_width;         pDstLine+=DstPic->byte_width>>2;     }         asm emms } 这个是我修改后的，会产生问题： asm.c: In function ‘DECODE_YUYV_MMX_line’: asm.c:423:13: error: expected ‘(’ before ‘{’ token asm.c:424:17: error: unknown type name ‘mov’ asm.c:425:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘mov’ asm.c: In function ‘DECODE_YUYV_MMX’: asm.c:459:9: error: expected ‘(’ before ‘emms’ asm.c:459:9: error: ‘emms’ undeclared (first use in this function) asm.c:459:9: note: each undeclared identifier is reported only once for each function it appears in asm.c:460:1: error: expected ‘;’ before ‘}’ token asm.c: In function ‘DECODE_YUYV_MMX_line’: asm.c:495:1: error: expected declaration or statement at end of input

user: user-3
content: 现在手写汇编已经不能提高运行效率了，编译器更懂怎么针对cpu进行优化 除非代码写的烂，编译器没办法优化。

user: user-4
content: 直接拷贝过去，不行吗？

user: user-0
content: 续接上面的函数主体  void DECODE_YUYV_MMX_line(TARGB32* pDstLine,const TUInt8* pYUYV,long width)     {         long expand8_width=(width>>3)<<3;                  if (expand8_width>0)         {             asm             {                 mov     ecx,expand8_width                 mov     eax,pYUYV                 mov     edx,pDstLine                 lea     eax,[eax+ecx*2]                 lea     edx,[edx+ecx*4]                 neg     ecx                                loop_beign:                 YUYV_Loader_MMX(eax+ecx*2)                 YUV422ToRGB32_MMX(edx+ecx*4,movq)                  add     ecx,8                 jnz     loop_beign                  mov     pYUYV,eax                 mov     pDstLine,edx             }         }          //处理边界         DECODE_YUYV_Common_line(pDstLine,pYUYV,width-expand8_width);     }  void DECODE_YUYV_MMX(const TUInt8* pYUYV,const TPicRegion& DstPic) {     assert((DstPic.width & 1)==0);           long YUV_byte_width=(DstPic.width>>1)<<2;     TARGB32* pDstLine=DstPic.pdata;      for (long y=0;y<DstPic.height;++y)     {         DECODE_YUYV_MMX_line(pDstLine,pYUYV,DstPic.width);         pYUYV+=YUV_byte_width;         ((TUInt8*&)pDstLine)+=DstPic.byte_width;     }         asm emms }

user: user-0
content: 现在改成功了，但是总题就在于没有实现应有的功能

user: user-1
content: 偶遇到类似问题都是用 “每次用/*...*/注释掉不同部分再重新编译，直到定位到具体语法出错的位置。” 的方法解决的。