当我进行写屏蔽的AVX-512存储时,如下所示:
vmovdqu8 [rsi] {k1}, zmm0
将所述指令的错,如果在{1} {}未映射的访问的存储器,但写掩码的一些部分是所有那些位置零(即,数据不是实际是由于改性面具)。
要求它的另一种方式是,如果这些AVX-512掩蔽存储有一个类似的故障抑制能力为[rsi, rsi + 63]
在AVX引入。
答案 0 :(得分:9)
如果被掩盖的元素接触无效内存,则不会引发任何故障。
这里有一些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**
此测试的工作方式如下: