paddw vs paddb
1 #include<stdio.h>
2 #include<inttypes.h>
3 int main()
4 {
5 uint8_t
a[8]={1,2,3,4,5,6,7,8},b[8]={1,2,3,4,5,6,7,8},i;
6 asm("movq (%1), %%mm0 \n"
7 "paddb (%0), %%mm0 \n"
8 "movq %%mm0, (%0) \n"
9 :
10 :"r"(b),"r"(a)
11 :"%mm0"
12 );
13 for(i=0;i<8;i++)
14 printf("%d ",b[i]);
15 return 0;
16 }
17Both the programs give the same output
WHY IS IT SO? i am using paddb and paddw. it dosent make any diff?
1 #include<stdio.h>
2 #include<inttypes.h>
3 int main()
4 {
5 uint8_t
a[8]={1,2,3,4,5,6,7,8},b[8]={1,2,3,4,5,6,7,8},i;
6 asm("movq (%1), %%mm0 \n"
7 "paddd (%0), %%mm0 \n"
8 "movq %%mm0, (%0) \n"
9 :
10 :"r"(b),"r"(a)
11 :"%mm0"
12 );
13 for(i=0;i<8;i++)
14 printf("%d ",b[i]);
15 return 0;
16 }
17~
ankit jain
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
Quoted 19 lines · Ankit Jain
1 #include<stdio.h>
2 #include<inttypes.h>
3 int main()
4 {
5 uint8_t
a[8]={1,2,3,4,5,6,7,8},b[8]={1,2,3,4,5,6,7,8},i;
6 asm("movq (%1), %%mm0 \n"
7 "paddb (%0), %%mm0 \n"
8 "movq %%mm0, (%0) \n"
9 :
10 :"r"(b),"r"(a)
11 :"%mm0"
12 );
13 for(i=0;i<8;i++)
14 printf("%d ",b[i]);
15 return 0;
16 }
17Quoted 4 lines
Both the programs give the same output
WHY IS IT SO? i am using paddb and paddw. it dosent make any diff?
Insert to a or b value for which a[i]+b[i]>255 where i is odd and you will see the difference, ie. a[7]=255.
Signature · 1 line
Maciej Hrebien
thanks
but if u can solve one more problem
'a' is uint8_t type and i want to extract only 4 int and store it as a word in mmx register
i am not able to understand that because movq is extracting 8 bytes at a time.
actually the problem is overflow. saturation is not tht helpfull
thanks
ankit jain
Quoted 22 lines · --- Maciej Hrebien
Quoted 21 lines · Ankit Jain
1 #include<stdio.h> 2 #include<inttypes.h> 3 int main() 4 { 5 uint8_t a[8]={1,2,3,4,5,6,7,8},b[8]={1,2,3,4,5,6,7,8},i; 6 asm("movq (%1), %%mm0 \n" 7 "paddb (%0), %%mm0 \n" 8 "movq %%mm0, (%0) \n" 9 : 10 :"r"(b),"r"(a) 11 :"%mm0" 12 ); 13 for(i=0;i<8;i++) 14 printf("%d ",b[i]); 15 return 0; 16 } 17Both the programs give the same output
Quoted 18 lines
Quoted 1 line
WHY IS IT SO? i am using paddb and paddw. it
dosent
Quoted 1 line
make any diff?
Insert to a or b value for which a[i]+b[i]>255 where i is odd
and you will see the difference, ie. a[7]=255.Signature · 8 lines
Maciej Hrebien - To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
Quoted 5 lines · Ankit Jain
thanks
but if u can solve one more problem
Quoted 8 lines
'a' is
uint8_ttype and i want to extract only 4 int and store it as a word in mmx registeri am not able to understand that because movq is
extracting 8 bytes at a time.actually the problem is overflow. saturation is not tht helpfull
I don't know if i understand your question right but for 32-bit transfers (4 bytes) you have MOVD instruction.
Signature · 1 line
Maciej Hrebien
hi
i know about movd but i want to move 16bit atr a time
thanks
Quoted 13 lines · --- Maciej Hrebien
Quoted 6 lines · Ankit Jain
thanks
but if u can solve one more problem
'a' is
uint8_ttype and i want to extract only 4int
Quoted 5 lines
and store it as a word in mmx register
i am not able to understand that because movq is
extracting 8 bytes at a time.
Quoted 19 lines
Quoted 1 line
actually the problem is overflow. saturation is
not
Quoted 1 line
tht helpfull
I don't know if i understand your question right but for
32-bit transfers (4 bytes) you have MOVD instruction.Signature · 8 lines
Maciej Hrebien - To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
Quoted 4 lines · Ankit Jain
hi
i know about movd but i want to move 16bit atr a time
You can't move a word to a mmx register directly. You have to simulate it ie. with a temp ored with the destination register:
pxor %mm7,%mm7
xor %eax,%eax
movw your_word,%ax
movd %eax,%mm7
por %mm7,%mm0
which moves your_word to the lowest part of mm0 and you have to be sure that low word of mm0 is zeroed before the operation. Or you can:
movd %mm0,%eax
movw your_word,%ax
movd %eax,%mm0
etc. but i don't recomend this kind of coding. Keep your words together and use movq.
Signature · 1 line
Maciej Hrebien