Introduction to MMX, XMM, SSE and SSE2 Technology Multimedia Extension, Streaming SIMD Extension 11/23/98, 5/6/99, 2/5/03, 5/10/04, 5/4/05

Download Report

Transcript Introduction to MMX, XMM, SSE and SSE2 Technology Multimedia Extension, Streaming SIMD Extension 11/23/98, 5/6/99, 2/5/03, 5/10/04, 5/4/05

Introduction to MMX, XMM, SSE and SSE2 Technology Multimedia Extension, Streaming SIMD Extension 11/23/98, 5/6/99, 2/5/03, 5/10/04, 5/4/05 1

SISD - Single Instruction, Single Data 2  Traditional computers  In general, one instruction processes one data item Memory Control Unit Execution Unit

SIMD - Single Instruction, Multiple Data  One instruction can process multiple data items  Useful when large amounts of regularly organized data is processed  Example: Matrix and vector calculations  This is the basis of MMX and XMM Memory Control Unit Execution Units 3

MISD Memory Control Unit Execution Units  MISD: Multiple instructions process one data item.

4

5 MIMD  MIMD: Multiple instructions process multiple data items.

Control Unit Execution Unit Control Unit Execution Unit Memory Control Unit Execution Unit Control Unit Execution Unit

6 Your Turn  How would you classify a traditional computer under this system?

 How would you classify a Shemp which has multiple processors?

 How would you classify a computer having a Intel Dual Core processor?

7 Potential Applications MMX and SSE  graphics  MEG video/image processing  music synthesis  speech compression/recognition  video conferencing  matrix and vector calculations  Advanced 3D graphics (SSE2)  Speech recognition (SSE2)  Scientific and engineering applications (SSE2)

MMX  4 new data types  New instructions  Uses 8 existing 64 bit floating point registers 8

9 The floating point registers  Floating point is processed by eight 80 bit registers ST(0), ST(1), …ST(7) in the floating point unit.

 When doing floating point arithmetic, these registers are organized in a stack.

 Programming floating point is quite different that programming integer arithmetic.

 Floating point calculations are done using 80 bits even when the program specifies storing 32 or 64 bit data values.

Advantages of using the floating 10 point registers in MMX.  The registers already exist. Only logic had to be added to the chip.

 The operating system already knows about the floating point registers.  When a computer is switches from one program to another, the state (registers) of the current program must be saved so state can be restored when the program becomes the active program once again.

 The floating point registers are automatically saved as part of the state of a program.

 MMX worked under existing operating systems!

New data types for MMX  64 bits long. One data item can store: 8 one byte integers: 4 two byte integers: 2 four byte integers 1 eight byte integer 11

SSE and SSE2  SSE – S treaming S IMD E xtensions  SSE2 introduced eight 128 bit XMM registers  These registers are disjoint from the floating point/MMX registers  SSE (Pentium III) can handle 4 single floating point numbers  SSE2 (Pentium 4) can also handle 2 double floating point numbers 12

13 New data types for XMM  128 bits: Can be used as: 16 one byte integers 8 two byte integers 4 doubleword integers or single precision floating 2 quadword integers or double precision floating

14 Your turn  Your program uses 3 arrays of 160,000 byte integers. We need to add the elements in the first two arrays to calculate the third array.

 Using a standard Pentium, how many “operations” are needed? (One operation includes loading 2 values into CPU, adding, storing the result and the associate loop processing)  How many XMM operations would be needed?

15 New instructions  Process the new data types 16, 8,4, or 2 data items (64 bits or 128 bits) at a time.

 Types of instructions: Add / Subtract Multiply/Multiply and add Shift Logical (AND, NAND, OR, XOR) Pack and unpack Move Shuffle and unpack (SSE)

16 Saturation  Handling overflow when adding 16, 8, 4, or 2 values at a time is a problem. Programmers can specify that when overflow occurs, the “sum” should be replaced by the maximum legal value.  Example: Unsigned byte addition 80h + A0h = 120h ===> overflow Instead the machine stores FFh.

 Likewise when subtracting.

17 Comparison operations  Consider <, >, <=, >=, =, and < > operations.

 Consider comparing two 64 bits quantities each holding 8, 4, or 2 values.

 Comparing multiple values at a time is a problem. So the MMX instructions store 0 for false and -1 for true for each of individual data items.

Example 1: Calculating Dot Products 18  7 Consider calculating S = A i B i i = 0 using MMX  Assume A i integers.

and B i are stored as signed 16 bit  Assume that the products and sums should be calculated using 32 bits.

 Assume that all values have two “binary” places.

Example 1: Calculating Dot Products 19  Storing A and B (64 bit vectors) 0 2 4 6 8 10 12 14 bytes 0 1 2 3 4 5 6 7 subscripts A B  We store each A i and B i item as 16 bit integers, 4 per 64 bit data item. Assume each value has 2 binary places

Example 1: Calculating Dot Products  Multiply and add instruction 2 20 4 30 3

* * * * * * * *

40 5 50 

+ + + +

806 1520 20

Example 1: MMX: Calculating Dot Products  Packed Multiply and add instruction 2 20 4 30 3

* * * * * * * *

40 5 50  806

+ + + +

1520 21  Packed Add

+ +

2326  (Normal) Add

+

Example 1: Calculating Dot Products 

Approximate algorithm

– Load left half of A into a FP register. – Multiply and add by left half of B.

– Shift products right 2 bits. (Products should have only two binary places.) – Repeat with right halves of A and B using a different register.

Add the second sum to the first.

Store the result.

22

Example 1: Calculating Dot Products 

Approximate algorithm (Conclusion)

– Add the two sums together in EAX to get the final sum.

23

Example 1: Calculating Dot Products 24  Intel claims that standard Pentiums would require 40 instructions to carry this out. Using MMX technology, only 13 instructions are needed. Speed improves by even a greater ratio.

Example 2: 24-bit color video blending 25  Suppose we have are displaying 640 by 480 pixel video that uses 24 bit colors - 8 bits for red, 8 for green, and 8 for blue.

 Suppose we are currently showing one picture which we want to fade out and replace by “fading” in a second picture.

 Suppose that we want to do the fade out/in in 255 steps.

Example 2: 24-bit color video blending  For each step, for each of 3 colors and for each of the 640 by 480 pixels we must calculate: Result_pixel = NewPicture_pixel * (i/255) +OldPicture_pixel * (1-(i/255)) where “i” is the step counter.

26  This formula must be calculated 640 * 480 * 3 * 255 = 235,008,000 times on 8 bit data!

Example 2: 24-bit color video blending 27  Intel calculates that this requires execution of 1.4 billion instructions on a standard PC even ignoring the calculation of i/255 and (1-i/255) and loop control.  With MMX, we can calculate 4 values in parallel. The number of MMX instructions would be 525 million. (Because the multiply instruction only applies to word data, the byte data must be unpacked into words and repacked after the calculation.)

28 Also included in MMX  Intel increased cache size when MMX was introduced (necessary for SIMD machines)  Programs run faster on MMX machines even if the SIMD instructions are not used  Excellent marketing: – Programs run faster on MMX machine – People want/buy MMX – Software publishers are encouraged to rewrite programs to take advantage of the new instructions

29 Information source  http://www.intel.com/drg/mmx/manuals/ overview/index.htm#intro (no longer available)  http://developer.intel.com/drg/mmx/manuals/ (no longer available)  http://www.intel.com/design/Pentium4/manuals/24 547012.pdf

(IA-32 Intel Architecture Software Developer’s Manual, vol. 1)  This slide show is MMX.PPT

Your Turn  1. Characterize the kinds of problems where SIMD is helpful.

 2. Give examples of problems where SIMD is useful.

30