Bug 372188

Summary: vex amd64->IR: unhandled instruction bytes: 0x66 0xF 0x3A 0x62 0x4A 0x10 0x10 0x48 0x83 0xC2 (PCMPxSTRx $0x10)
Product: [Developer tools] valgrind Reporter: Wayne Arnold <wayne.arnold>
Component: vexAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal CC: ivosh
Priority: NOR    
Version First Reported In: 3.13 SVN   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: unit test from rapidjson that uses sse4.2

Description Wayne Arnold 2016-11-07 16:27:41 UTC
appears to be another instance of pcmpistrm  that is not being recognized.

  1477b0:       66 0f 3a 62 48 10 10    pcmpistrm $0x10,0x10(%rax),%xmm1
  1477b7:       48 83 c0 10             add    $0x10,%rax
  1477bb:       66 0f 7e c1             movd   %xmm0,%ecx
  1477bf:       85 c9                   test   %ecx,%ecx


this is in a 3rd party library,  rapidjson compiled with  support for SSE4.2 enabled

I don't have the source available

vex amd64->IR: unhandled instruction bytes: 0x66 0xF 0x3A 0x62 0x4A 0x10 0x10 0x48 0x83 0xC2
vex amd64->IR:   REX=0 REX.W=0 REX.R=0 REX.X=0 REX.B=0
vex amd64->IR:   VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=0F3A
vex amd64->IR:   PFX.66=1 PFX.F2=0 PFX.F3=0
==9471== valgrind: Unrecognised instruction at address 0x8c4115a0.
==9471==    at 0x8C4115A0: void rapidjson_sse42::GenericReader<rapidjson_sse42::UTF8<char>, rapidjson_sse42::UTF8<char>, rapidjson_sse42::CrtAllocator>::ParseObject<1u, rapidjson_sse42:
:GenericInsituStringStream<rapidjson_sse42::UTF8<char> >, rapidjson_sse42::GenericDocument<rapidjson_sse42::UTF8<char>, rapidjson_sse42::MemoryPoolAllocator<rapidjson_sse42::CrtAllocato
r>, rapidjson_sse42::CrtAllocator> >(rapidjson_sse42::GenericInsituStringStream<rapidjson_sse42::UTF8<char> >&, rapidjson_sse42::GenericDocument<rapidjson_sse42::UTF8<char>, rapidjson_s
se42::MemoryPoolAllocator<rapidjson_sse42::CrtAllocator>, rapidjson_sse42::CrtAllocator>&) (reader.h:299)
==9471==    by 0x8C4107ED: rapidjson_sse42::ParseResult rapidjson_sse42::GenericReader<rapidjson_sse42::UTF8<char>, rapidjson_sse42::UTF8<char>, rapidjson_sse42::CrtAllocator>::Parse<1u
, rapidjson_sse42::GenericInsituStringStream<rapidjson_sse42::UTF8<char> >, rapidjson_sse42::GenericDocument<rapidjson_sse42::UTF8<char>, rapidjson_sse42::MemoryPoolAllocator<rapidjson_
sse42::CrtAllocator>, rapidjson_sse42::CrtAllocator> >(rapidjson_sse42::GenericInsituStringStream<rapidjson_sse42::UTF8<char> >&, rapidjson_sse42::GenericDocument<rapidjson_sse42::UTF8<
char>, rapidjson_sse42::MemoryPoolAllocator<rapidjson_sse42::CrtAllocator>, rapidjson_sse42::CrtAllocator>&) (reader.h:498)
==9471==    by 0x8C410686: rapidjson_sse42::GenericDocument<rapidjson_sse42::UTF8<char>, rapidjson_sse42::MemoryPoolAllocator<rapidjson_sse42::CrtAllocator>, rapidjson_sse42::CrtAllocator>& rapidjson_sse42::GenericDocument<rapidjson_sse42::UTF8<char>, rapidjson_sse42::MemoryPoolAllocator<rapidjson_sse42::CrtAllocator>, rapidjson_sse42::CrtAllocator>::ParseStream<1u, rapidjson_sse42::UTF8<char>, rapidjson_sse42::GenericInsituStringStream<rapidjson_sse42::UTF8<char> > >(rapidjson_sse42::GenericInsituStringStream<rapidjson_sse42::UTF8<char> >&) (document.h:2150)
Comment 1 Wayne Arnold 2016-11-07 16:33:12 UTC
sorry,  real instance,  there are a number when disassembled

  1485a0:       66 0f 3a 62 4a 10 10    pcmpistrm $0x10,0x10(%rdx),%xmm1
  1485a7:       48 83 c2 10             add    $0x10,%rdx
  1485ab:       66 0f 7e c0             movd   %xmm0,%eax
Comment 2 Wayne Arnold 2016-11-07 17:07:01 UTC
  148a20:       66 0f 3a 62 49 10 10    pcmpistrm $0x10,0x10(%rcx),%xmm1
  148a27:       48 83 c1 10             add    $0x10,%rcx
  148a2b:       66 0f 7e c0             movd   %xmm0,%eax
  148a2f:       85 c0                   test   %eax,%eax
Comment 3 Wayne Arnold 2017-03-05 21:57:20 UTC
Created attachment 104388 [details]
unit test from rapidjson that uses sse4.2

unit test from rapidjson that fails with illegal instruction for pcmpistri  when using MEM for arg2
Comment 4 Wayne Arnold 2017-03-05 22:04:21 UTC
SSE 4.2 adds four string text processing instructions PCMPISTRI, PCMPISTRM, PCMPESTRI and PCMPESTRM. These instructions take three parameters, arg1 an xmm register, arg2 an xmm or a 128-bit memory location and IMM8 an 8-bit immediate control byte

the current valgrind code implements the 1st case  xmm register for both arg1 and arg2

is it possible to add the 2nd case of arg2 being being a memory location
Comment 5 Wayne Arnold 2017-03-06 02:33:00 UTC
the unit test is from:  https://github.com/miloyip/rapidjson
Comment 6 Wayne Arnold 2017-04-07 14:13:26 UTC
any suggestions on how to add in the MEM option.  are there other instructions that can be used as a guide ?
Comment 7 Ivo Raisr 2017-05-05 15:48:56 UTC
Wayne, I don't think there are any specific instructions of how to add support for new instructions into Valgrind.
You need to work by analogy and do a very little investigation.

Pick an instruction already supported by Valgrind which does very similar thing as pcmpistrm. Have a look how it is supported in VEX subsystem (guest_amd64_*, host_amd64_*) and also provide a test case for it, possibly under none/tests/amd64 directory.
Comment 8 Julian Seward 2017-05-12 14:11:34 UTC
Fixed, vex r3366, valgrind r16367.
Comment 9 Wayne Arnold 2017-05-17 15:51:52 UTC
thank you. I was able to run this updated version on our code.