上一篇文章对MMX,SSE,SSE2及SSE3技术做了基本的概述,本篇文章就先对MMX技术所提供的运算指令进行介绍 在汇编程式里执行MMX运算指令的基本步骤如下:将多个整数放在一起组成MMX所需的压缩整数类型...
.section .data packedvalue1: .byte 10, 20, -30, 40, 50, 60, -70, 80 packedvalue2: .short 10, 20, 30, 40 packedvalue3: .int 10, 20 .section .bss .lcomm result, 8 .section .text .globl _start _start: movq packedvalue1, %mm0 movq packedvalue2, %mm1 movq packedvalue3, %mm2 movq %mm2, result |
Data Type 数据类型 |
Positive Overflow Value 正溢出值 |
Negative Overflow Value 负溢出值 |
---|---|---|
Signed byte 有符号字节整数 |
127 | -128 |
Signed word 有符号字整数 |
32,767 | -32,768 |
Unsigned byte 无符号字节整数 |
255 | 0 |
Unsigned word 无符号字整数 |
65,535 | 0 |
MMX Instruction MMX指令 |
Description 指令描述 |
---|---|
PADDB |
Add packed byte integers with wraparound 使用wraparound截断溢出方式进行压缩字节整数的加运算 |
PADDW |
Add packed word integers with wraparound 使用wraparound截断溢出方式进行压缩字整数的加运算 |
PADDD |
Add packed doubleword integers with wraparound 使用wraparound截断溢出方式进行压缩双字整数的加运算 |
PADDSB |
Add packed byte integers with signed saturation 压缩字节整数的有符号饱和加运算 |
PADDSW |
Add packed word integers with signed saturation 压缩字整数的有符号饱和加运算 |
PADDUSB |
Add packed byte integers with unsigned saturation 压缩字节整数的无符号饱和加运算 |
PADDUSW |
Add packed word integers with unsigned saturation 压缩字整数的无符号饱和加运算 |
PSUBB |
Subtract packed byte integers with wraparound 使用wraparound截断溢出方式进行压缩字节整数的减运算 |
PSUBW |
Subtract packed word integers with wraparound 使用wraparound截断溢出方式进行压缩字整数的减运算 |
PSUBD |
Subtract packed doubleword integers with wraparound 使用wraparound截断溢出方式进行压缩双字整数的减运算 |
PSUBSB |
Subtract packed byte integers with signed saturation 压缩字节整数的有符号饱和减运算 |
PSUBSW |
Subtract packed word integers with signed saturation 压缩字整数的有符号饱和减运算 |
PSUBUSB |
Subtract packed byte integers with unsigned saturation 压缩字节整数的无符号饱和减运算 |
PSUBUSW |
Subtract packed word integers with unsigned saturation 压缩字整数的无符号饱和减运算 |
PADDSB source, destination |
PADDSB %mm1, %mm0 |
# mmxadd.s - An example of performing MMX addition
.section .data
value1:
.int 10, 20
value2:
.int 30, 40
.section .bss
.lcomm result, 8
.section .text
.globl _start
_start:
nop
movq value1, %mm0
movq value2, %mm1
paddd %mm1, %mm0
movq %mm0, result
movl $1, %eax
movl $0, %ebx
int $0x80
|
$ as -gstabs -o mmxadd.o mmxadd.s $ ld -o mmxadd mmxadd.o $ gdb -q mmxadd Reading symbols from /root/asm_example/adv/mmxadd...done. (gdb) b _start Breakpoint 1 at 0x8048074: file mmxadd.s, line 12. (gdb) r Starting program: /root/asm_example/adv/mmxadd Breakpoint 1, _start () at mmxadd.s:12 12 nop (gdb) s 13 movq value1, %mm0 (gdb) s 14 movq value2, %mm1 (gdb) s 15 paddd %mm1, %mm0 (gdb) info all ........................................................ st0 -nan(0x140000000a) (raw 0xffff000000140000000a) st1 -nan(0x280000001e) (raw 0xffff000000280000001e) ........................................................ |
......................................... 15 paddd %mm1, %mm0 (gdb) s 16 movq %mm0, result (gdb) s 17 movl $1, %eax (gdb) x/2d &value1 0x804909c |
Instruction 指令 |
Description 描述 |
---|---|
PAND |
Performs a bitwise logic AND of the source and destination operands 对源和目标操作数执行按位逻辑与运算 |
PANDN |
Performs a bitwise logical NOT of the destination operand, and then an AND of the source and destination operands 先对目标操作数执行按位逻辑非运算,再将逻辑非的结果和源操作数进行按位与运算 |
POR |
Performs a bitwise logical OR of the source and destination operands 对源和目标操作数执行按位逻辑或运算 |
PXOR |
Performs a bitwise logical exclusive-OR of the source and destination operands 对源和目标操作数执行按位逻辑异或运算 |
PSLL |
Performs a logical left shift of the operand, filling empty bits with zeroes 根据源操作数,对目标操作数进行逻辑左移,左移所产生的空位用零来填充 |
PSRL |
Performs a logical right shift of the operand, filling empty bits with zeroes 根据源操作数,对目标操作数进行逻辑右移,右移所产生的空位用零来填充 |
PAND mm/m64, mm PANDN mm/m64, mm POR mm/m64, mm PXOR mm/m64, mm |
PAND:DEST ← DEST AND SRC; |
PANDN:DEST ← (NOT DEST) AND SRC; POR:DEST ← DEST OR SRC; PXOR:DEST ← DEST XOR SRC; |
PSLLW mm/m64, mm PSLLW imm8, mm PSLLD mm/m64, mm PSLLD imm8, mm PSLLQ mm/m64, mm PSLLQ imm8, mm |
PSRAW mm/m64, mm PSRAW imm8, mm PSRAD mm/m64, mm PSRAD imm8, mm |
Instruction 指令 |
Description 描述 |
---|---|
PCMPEQB |
Compares packed byte integer values for equality 对源和目标操作数里的8个字节整数值进行比较,判断它们是否相等 |
PCMPEQW |
Compares packed word integer values for equality 对源和目标操作数里的4个16位的字整数值进行比较,判断它们是否相等 |
PCMPEQD |
Compares packed doubleword integer values for equality 对源和目标操作数里的2个32位的双字整数值进行比较,判断它们是否相等 |
PCMPGTB |
Determines whether the packed byte integer values are greater than another 对源和目标操作数里的8个字节整数值进行比较,判断目标是否大于源 |
PCMPGTW |
Determines whether the packed word integer values are greater than another 对源和目标操作数里的4个16位的字整数值进行比较,判断目标是否大于源 |
PCMPGTD |
Determines whether the packed doubleword integer values are greater than another 对源和目标操作数里的2个32位的双字整数值进行比较,判断目标是否大于源 |
# mmxcomp.s - An example of performing MMX comparison
.section .data
value1:
.short 10, 20, -30, 40
value2:
.short 10, 40, -30, 45
.section .bss
.lcomm result, 8
.section .text
.globl _start
_start:
nop
movq value1, %mm0
movq value2, %mm1
pcmpeqw %mm1, %mm0
movq %mm0, result
movl $1, %eax
movl $0, %ebx
int $0x80
|
$ as -gstabs -o mmxcomp.o mmxcomp.s $ ld -o mmxcomp mmxcomp.o $ gdb -q mmxcomp Reading symbols from /root/asm_example/adv/mmxcomp...done. (gdb) b _start Breakpoint 1 at 0x8048074: file mmxcomp.s, line 12. (gdb) r Starting program: /root/asm_example/adv/mmxcomp Breakpoint 1, _start () at mmxcomp.s:12 12 nop (gdb) s 13 movq value1, %mm0 (gdb) s 14 movq value2, %mm1 (gdb) s 15 pcmpeqw %mm1, %mm0 (gdb) s 16 movq %mm0, result (gdb) s 17 movl $1, %eax (gdb) x/4dh &value1 0x804909c |