当使用带AVX-512负载和存储掩码寄存器,是提高了无效故障访问屏蔽掉元素?

问题描述 投票:7回答:1

当我做了writemasked AVX-512店,就像这样:

vmovdqu8 [rsi] {k1}, zmm0

如果将在[rsi, rsi + 63]访问的存储器的某些部分没有被映射的指示故障但写掩码对于所有那些位置(即,该数据是不实际由于掩模修改)为零。

要求它的另一种方式是,如果这些AVX-512蒙面店有AVX到vmaskmov推出了类似的故障抑制能力。

x86 avx avx512
1个回答
10
投票

如果被屏蔽了元件触摸无效的内存无故障引发。

enter image description here


下面是一些的Windows测试代码,以证明屏蔽确实抑制内存故障。

#include <immintrin.h>
#include <iostream>
#include <Windows.h>
using namespace std; 


int main(){
    const size_t PAGE = 4096;

    //  Map 2 pages.
    char* ptr = (char*)VirtualAlloc(
        nullptr, 2*PAGE,
        MEM_COMMIT,
        PAGE_READWRITE
    );

    //  Store 64 bytes across page boundary.
    cout << "Store across page boundary." << endl;
    _mm512_storeu_si512(ptr + PAGE - 32, _mm512_set1_epi8(-1));

    //  Unmap top page.
    cout << "Unmap top page." << endl;
    VirtualFree(ptr + PAGE, PAGE, MEM_DECOMMIT);

    //  Write on boundary masking out the part that touches the top (unmapped page).
    //  Does not crash because bad accesses are masked out.
    cout << "Store across page boundary, but mask out bytes that are on unmapped page." << endl;
    _mm512_mask_storeu_epi8(ptr + PAGE - 32, 0x00000000ffffffff, _mm512_set1_epi8(-1));

    //  Store 64 bytes across page boundary.
    //  Crashes because of bad access.
    cout << "Store across page boundary." << endl;
    _mm512_storeu_si512(ptr + PAGE - 32, _mm512_set1_epi8(-1));

    cout << "Release bottom page." << endl;
    VirtualFree(ptr, 0, MEM_RELEASE);

    system("pause");
}

输出:

Store across page boundary.
Unmap top page.
Store across page boundary, but mask out bytes that are on unmapped page.
Store across page boundary.
**Access violation**

这个测试的工作原理如下:

  1. 地图2相邻页。
  2. 不要跨页边界的AVX512店来证明这两个页面映射。
  3. 映射到该上页。
  4. 照此AVX512商店,但屏蔽掉那些从上面的字节数。它不会崩溃。
  5. 重复第1 AVX512存储(无屏蔽)。它崩溃,由此证明上部页已被取消映射和掩蔽抑制崩溃。
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.