_mm_extract_si64, _mm_extracti_si64

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at _mm_extract_si64, _mm_extracti_si64.

Microsoft Specific**

Generates the extrq instruction to extract specified bits from the low 64 bits of its first argument.

Syntax

__m128i _mm_extract_si64(  
   __m128i Source,  
   __m128i Descriptor  
);  
__m128i _mm_extracti_si64(  
   __m128i Source,  
   int Length,  
   int Index  
);  

Parameters

[in] Source
A 128-bit field with input data in its lower 64 bits.

[in] Descriptor
A 128-bit field that describes the bit field to extract.

[in] Length
An integer that specifies the length of the field to extract.

[in] Index
An integer that specifies the index of the field to extract

Return Value

A 128-bit field with the extracted field in its least significant bits.

Requirements

Intrinsic Architecture
_mm_extract_si64 SSE4a
_mm_extracti_si64 SSE4a

Header file <intrin.h>

Remarks

This intrinsic generates the extrq instruction to extract bits from Source.There are two versions of this intrinsic: _mm_extracti_si64 is the immediate version, and _mm_extract_si64 is the non-immediate one. Each version extracts from Source a bit field defined by its length and the index of its least significant bit. The values of the length and index are taken mod 64, thus both -1 and 127 are interpreted as 63. If the sum of the (reduced) index and (reduced) field length is greater than 64, the results are undefined. A value of zero for field length is interpreted as 64. If the field length and bit index are both zero, bits 63:0 of Source are extracted. If the field length is zero but the bit index is non-zero, the results are undefined.

In a call to _mm_extract_si64, the Descriptor contains the index in bits 13:8 and the field length of the data to be extracted in bits 5:0..

If you call _mm_extracti_si64 with arguments that the compiler cannot determine to be integer constants the compiler generates code to pack those values into an XMM register (Descriptor) and to call _mm_extract_si64.

To determine hardware support for the extrq instruction, call the __cpuid intrinsic with InfoType=0x80000001 and check bit 6 of CPUInfo[2] (ECX). This bit will be 1 if the instruction is supported, and 0 otherwise. If you run code that uses this intrinsic hardware that does not support the extrq instruction, the results are unpredictable.

Example

// Compile this sample with: /EHsc  
#include <iostream>  
#include <intrin.h>  
using namespace std;  
  
union {  
    __m128i m;  
    unsigned __int64 ui64[2];  
} source, descriptor, result1, result2, result3;  
  
int  
main()  
{  
    source.ui64[0] =     0xfedcba9876543210ll;  
    descriptor.ui64[0] = 0x0000000000000b1bll;  
  
    result1.m = _mm_extract_si64 (source.m, descriptor.m);  
    result2.m = _mm_extracti_si64(source.m, 27, 11);  
    result3.ui64[0] = (source.ui64[0] >> 11) & 0x7ffffff;  
  
    cout << hex << "result1 = 0x" << result1.ui64[0] << endl;  
    cout << "result2 = 0x" << result2.ui64[0] << endl;  
    cout << "result3 = 0x" << result3.ui64[0] << endl;  
}  
result1 = 0x30eca86  
result2 = 0x30eca86  
result3 = 0x30eca86  

END Microsoft Specific

Copyright 2007 by Advanced Micro Devices, Inc. All rights reserved. Reproduced with permission from Advanced Micro Devices, Inc.

See Also

_mm_insert_si64, _mm_inserti_si64
Compiler Intrinsics