Code - Difference is one method is for signed short int-s and another for unsigned short int.
short signedShortIntSwap(short int* a , short int* b){ short tmp = *a; *a = *b; *b = tmp; return *a;}unsigned short unsignedShortIntSwap(unsigned short int* a ,unsigned short int* b){ unsigned short tmp = *a; *a = *b; *b = tmp; return *a;}
Assembly: - gcc -c -m64 -o func1 func1.c -O2 -fno-tree-vectorize
0000000000000000 <signedShortIntSwap>: 0: f3 0f 1e fa endbr64 4: 0f b7 07 movzx eax,WORD PTR [rdi] 7: 0f b7 16 movzx edx,WORD PTR [rsi] a: 66 89 17 mov WORD PTR [rdi],dx d: 66 89 06 mov WORD PTR [rsi],ax 10: 0f b7 07 movzx eax,WORD PTR [rdi] 13: c3 ret 14: 66 66 2e 0f 1f 84 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 1b: 00 00 00 00 1f: 90 nop0000000000000020 <unsignedShortIntSwap>: 20: f3 0f 1e fa endbr64 24: 0f b7 07 movzx eax,WORD PTR [rdi] 27: 0f b7 16 movzx edx,WORD PTR [rsi] 2a: 66 89 17 mov WORD PTR [rdi],dx 2d: 66 89 06 mov WORD PTR [rsi],ax 30: 0f b7 07 movzx eax,WORD PTR [rdi] 33: c3 ret 34: 66 66 2e 0f 1f 84 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 3b: 00 00 00 00 3f: 90 nop
- Why do we have
movzx eax,WORD PTR [rdi]
repeated for each functions at address4
&&10
and24
&&30
. - Why is for both signed and unsigned function have identical instruction set. In which case it differs?