共用方式為


_mm_max_epi8

Microsoft Specific

Emits the Streaming SIMD Extensions 4 (SSE4) instruction pmaxsb. This instruction chooses the larger value of the two parameters.

__m128i _mm_max_epi8( 
   __m128i a,
   __m128i b 
);

Parameters

  • [in] a
    A 128-bit parameter that contains sixteen 8-bit signed integers.

  • [in] b
    A 128-bit parameter that contains sixteen 8-bit signed integers.

Return value

A 128-bit value that can be defined with the following equations:

r0 := (a0 > b0) ? a0 : b0
r1 := (a1 > b1) ? a1 : b1
...
r15 := (a15 > b15) ? a15 : b15

Requirements

Intrinsic

Architecture

_mm_max_epi8

x86, x64

Header file <smmintrin.h>

Remarks

r0-r15, a0-a15, and b0-b15 are the sequentially ordered 8-bit components of return value r and parameters a and b. r0, a0, and b0 are the least significant 8 bits.

Before you use this intrinsic, software must ensure that the processor supports the instruction.

Example

#include <stdio.h>
#include <smmintrin.h>

int main ()
{
    __m128i a, b;

    a.m128i_i8[0] = 1;
    a.m128i_i8[1] = 2;
    a.m128i_i8[2] = 4;
    a.m128i_i8[3] = 8;
    a.m128i_i8[4] = 16;
    a.m128i_i8[5] = 32;
    a.m128i_i8[6] = 64;
    a.m128i_i8[7] = 127;
    a.m128i_i8[8] = -15;
    a.m128i_i8[9] = 15;
    a.m128i_i8[10] = 1;
    a.m128i_i8[11] = -45;
    a.m128i_i8[12] = 31;
    a.m128i_i8[13] = -100;
    a.m128i_i8[14] = 100;
    a.m128i_i8[15] = -23;

    b.m128i_i8[0] = 127;
    b.m128i_i8[1] = -64;
    b.m128i_i8[2] = 32;
    b.m128i_i8[3] = -16;
    b.m128i_i8[4] = 8;
    b.m128i_i8[5] = -4;
    b.m128i_i8[6] = 2;
    b.m128i_i8[7] = -1;
    b.m128i_i8[8] = 0;
    b.m128i_i8[9] = 0;
    b.m128i_i8[10] = -1;
    b.m128i_i8[11] = -50;
    b.m128i_i8[12] = 31;
    b.m128i_i8[13] = -4;
    b.m128i_i8[14] = 50;
    b.m128i_i8[15] = -24;

    __m128i res = _mm_max_epi8(a, b);

    printf_s("   a\t   b\t res\n%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n",
                a.m128i_i8[0], b.m128i_i8[0], res.m128i_i8[0],
                a.m128i_i8[1], b.m128i_i8[1], res.m128i_i8[1],
                a.m128i_i8[2], b.m128i_i8[2], res.m128i_i8[2]);
    printf_s("%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n",
                a.m128i_i8[3], b.m128i_i8[3], res.m128i_i8[3],
                a.m128i_i8[4], b.m128i_i8[4], res.m128i_i8[4],
                a.m128i_i8[5], b.m128i_i8[5], res.m128i_i8[5],
                a.m128i_i8[6], b.m128i_i8[6], res.m128i_i8[6]);
    printf_s("%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n",
                a.m128i_i8[7], b.m128i_i8[7], res.m128i_i8[7],
                a.m128i_i8[8], b.m128i_i8[8], res.m128i_i8[8],
                a.m128i_i8[9], b.m128i_i8[9], res.m128i_i8[9],
                a.m128i_i8[10], b.m128i_i8[10], res.m128i_i8[10]);
    printf_s("%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n%4d\t%4d\t%4d\n",
                a.m128i_i8[11], b.m128i_i8[11], res.m128i_i8[11],
                a.m128i_i8[12], b.m128i_i8[12], res.m128i_i8[12],
                a.m128i_i8[13], b.m128i_i8[13], res.m128i_i8[13],
                a.m128i_i8[14], b.m128i_i8[14], res.m128i_i8[14]);
    printf_s("%4d\t%4d\t%4d\n",
                a.m128i_i8[15], b.m128i_i8[15], res.m128i_i8[15]);

    return 0;
}
   a       b     res
   1     127     127
   2     -64       2
   4      32      32
   8     -16       8
  16       8      16
  32      -4      32
  64       2      64
 127      -1     127
 -15       0       0
  15       0      15
   1      -1       1
 -45     -50     -45
  31      31      31
-100      -4      -4
 100      50     100
 -23     -24     -23

See Also

Concepts

Compiler Intrinsics