|
From: Mark A. <mar...@gm...> - 2015-03-29 17:26:44
|
Hi, I was writing unit tests for some code that used the x86 compiler intrinsic _mm_maskstore_ps ( https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-C32657F6-AAF5-4DCC-AC94-2BA02AEBADFB.htm). I observed that Valgrind 3.10.1 thought the resulting instruction was illegal. However, non-valgrind execution of the code works correctly (on an avx machine, of course). Compiler gcc (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2 (same with clang 3.5.0) Code snippet to reproduce: #include <immintrin.h> #include <xmmintrin.h> #include <iostream> int main(int, char **) { float dest[32]; __m128 source = _mm_set1_ps(1.0); __m128i mask128 = _mm_set_epi32(0, -1, -1, -1); _mm_maskstore_ps(dest, mask128, source); std::cout << dest[0] << dest[1] << dest[2] << dest[3]; // Writes "111?" to stdout return 0; } g++ source.cpp -g -mavx -lstdc++ valgrind ./a.out ==442== Memcheck, a memory error detector ==442== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==442== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==442== Command: ./a.out ==442== vex amd64->IR: unhandled instruction bytes: 0xC4 0xE2 0x71 0x2E 0x0 0x8B 0x9D 0x6C vex amd64->IR: REX=0 REX.W=0 REX.R=0 REX.X=0 REX.B=0 vex amd64->IR: VEX=1 VEX.L=0 VEX.nVVVV=0x1 ESC=0F38 vex amd64->IR: PFX.66=1 PFX.F2=0 PFX.F3=0 ==442== valgrind: Unrecognised instruction at address 0x400835. ==442== at 0x400835: _mm_maskstore_ps (avxintrin.h:937) ==442== by 0x400835: main (maskstore-bug.cpp:10) ==442== Your program just tried to execute an instruction that Valgrind ==442== did not recognise. There are two possible reasons for this. ==442== 1. Your program has a bug and erroneously jumped to a non-code ==442== location. If you are running Memcheck and you just saw a ==442== warning about a bad jump, it's probably your program's fault. ==442== 2. The instruction is legitimate but Valgrind doesn't handle it, ==442== i.e. it's Valgrind's fault. If you think this is the case or ==442== you are not sure, please let us know and we'll try to fix it. ==442== Either way, Valgrind will now raise a SIGILL signal which will ==442== probably kill your program. ==442== ==442== Process terminating with default action of signal 4 (SIGILL) ==442== Illegal opcode at address 0x400835 ==442== at 0x400835: _mm_maskstore_ps (avxintrin.h:937) ==442== by 0x400835: main (maskstore-bug.cpp:10) ==442== ==442== HEAP SUMMARY: ==442== in use at exit: 0 bytes in 0 blocks ==442== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==442== ==442== All heap blocks were freed -- no leaks are possible ==442== ==442== For counts of detected and suppressed errors, rerun with: -v ==442== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) Illegal instruction (core dumped) Further observations I made: * use of _mm_maskload_ps was fine * disassembly by DDT showed that a VMASKMOVPS was being generated, which is correct * different masks, or an aligned dest made no difference Is this a known issue, or have I done something wrong, or? Thanks! Mark |