User:Ovinus/sandbox3

SSE background

Introduction and history
Intel introduced MMX technology in 1997 with the Pentium P5 line of processors, adding eight 64-bit registers, called MM0 through MM7. Each such register may hold a single 64-bit integer, or multiple smaller integers to be operated on in parallel--an example of single instruction, multiple data (SIMD). For example, the instruction  adds 32-bit integers from MM0 and MM1 in parallel, writing to MM0. Architecturally, these registers were mapped onto the existing x87 FPU registers, and thus code cannot simultaneously use x87 and MMX instructions without conflict.

AMD aimed to enhance the MMX instruction set with 3DNow!, introduced 1998, by adding floating-point instructions that use the MMX registers. 3DNow! never garnered much popularity and was officially deprecated in 2010. In 1999, Intel added Streaming SIMD Extensions (SSE) with the Pentium III, adding eight new 128-bit registers named XMM0 through XMM7, along with a control register for them, called MXCSR. With AMD64, the 64-bit version of the x86 architecture, the count of SSE registers was doubled to 16 (XMM0 through XMM15). The original SSE instructions mostly operated on single-precision floating-point numbers, but included both SIMD and scalar (single data) instructions; for example,  adds the single-precision floats in the lowermost quarter of XMM0 and of XMM1, writing to XMM0, while   adds four pairs of single-precision floats in parallel. SSE2, released 2000, added double-precision and many new integer SSE instructions, essentially extending and supplanting the MMX technology. Integer SSE instructions are architecturally no different from floating-point instructions; floats may be treated as integers and vice versa. Successive extensions added new instructions (SSE3, SSSE3, and SSE4) performing complex operations such as shuffling data within a register.

The next major architectural change came with Advanced Vector Extensions, released in 2011 by Intel, expanding the SSE registers to 256-bit AVX registers, named YMM0 through YMM15. The SSE registers map onto the lower halves of the corresponding AVX registers. AVX contains extensions of SSE's floating-point operations, but no integer operations. In terms of functionality, the AVX registers were akin to two SSE registers joined together: Most instructions cannot move data between the 128-bit "lanes". This restriction changed somewhat with the 2013 introduction of AVX2, which extended SSE integer instructions to AVX registers, added new instructions, and added a few lane-crossing instructions. Introduced in 2013, the FMA3 and FMA4 instruction sets (of which only the former is still supported) added fused multiply–accumulate floating-point instructions to SSE and AVX registers. Other, miscellaneous instruction sets have been added to the SSE and AVX registers.

AVX-512 added hundreds of new instructions, expanded the 256-bit AVX registers into 512-bit AVX-512 registers and doubled the register count to 32 (ZMM0 through ZMM31). Like the transition from SSE to AVX, the AVX registers map to the lower halves of corresponding AVX-512 registers, and most of the AVX-512 instructions may also be applied to the smaller registers (but always require an EVEX prefix). It also adds 8 "opmask" registers, named K0 through K7, which can be used to arbitrarily select what portions of a SIMD register are affected by an operation. AVX-512 is subdivided into sets of instructions, of which only AVX-512F ("Foundation") is required; AVX-512-capable CPUs vary in which instruction sets they support.

Instruction encoding and table notation
An example of a CISC (complex instruction) computer architecture, x86 instructions are variable in length and coded with a combination of prefixes attached to an opcode, which determines the instruction, followed by several arguments---registers, memory addresses, and immediates (data for immediate use). The following table uses Intel assembly syntax, in which the write destination of an operation (if applicable) is the first argument.

A particular instruction has some opcode (, for example, is ) and may be followed by its encoded operands, in this case denoted   ... (don't know what that syntax means tbh). Immediate byte values are indicated with. There is no prefix peculiar to MMX instructions, but SSE, AVX, and AVX-512 instructions are prefixed with a one-byte  prefix, a VEX prefix, and an EVEX prefix, respectively, determining (among other things) the width of the instruction. A REX prefix is used for certain operations on 64-bit registers and determining their behavior.

In the table, mm indicates a SIMD register, which should be extended to the corresponding vector length for the corresponding widened instructions. Typically, the mnemonic for SSE instructions is the same as the corresponding MMX instruction, while AVX and AVX-512 instructions begin with the letter V. Thus, the SSE instruction  adds 32-bit integers in parallel, writing to the first argument, while the analogous AVX2 instruction is denoted. Instructions that do not follow this exact pattern are indicated in the columns. r/m32 indicates a 32-bit argument that may either be a 32-bit general purpose register or a memory location. imm8 indicates an 8-bit integer immediate, an arbitrary byte encoded directly into the instruction. For example,  will bitwise shift right the contents of the AVX register by however many bits specified in imm8.