lifting-bits / remill

Library for lifting machine code to LLVM bitcode
Apache License 2.0
1.22k stars 142 forks source link

Add Semantics for AVX512VL instruction #435

Open adahsuzixin opened 3 years ago

adahsuzixin commented 3 years ago

Hi,team

I have question for adding Semantics for AVX512VL instruction. For example, let's see the following two instructions.

instruction binary
vpshufb %xmm2,%xmm3,%xmm0{%k1}{z} 62 f2 65 89 00 c2
vpshufb %xmm2,%xmm3,%xmm0{%k1} 62 f2 65 09 00 c2

In first situation, it should have 5 arguments in Semantics function. However, the instruction form from docs/XED/xed.txt has only 4 arguments at most.

4386 VPSHUFB VPSHUFB_XMMu8_MASKmskw_XMMu8_XMMu8_AVX512 AVX512 AVX512EVEX AVX512BW_128 ATTRIBUTES: MASKOP_EVEX
 4 
    0 REG0 EXPLICIT W NT_LOOKUP_FN U8 XMM_R3 
    1 REG1 EXPLICIT R NT_LOOKUP_FN I1 MASK1 
    2 REG2 EXPLICIT R NT_LOOKUP_FN U8 XMM_N3 
    3 REG3 EXPLICIT R NT_LOOKUP_FN U8 XMM_B3 

So in this situation, we lost {z} flag after decoding with the help of xed. Is there any good way to get the {z} flag? We need the flag to implement the Semantics shown below.

(KL, VL) = (16, 128), (32, 256), (64, 512)
jmask←(KL-1) & ~0xF
                // 0x00, 0x10, 0x30 depending on the VL
FOR j = 0 TO KL-1
                // dest
    IF kl[ i ] or no_masking
        index←src.byte[ j ];
        IF index & 0x80
            Dest.byte[ j ]←0;
        ELSE
            index←(index & 0xF) + (j & jmask);
                // 16-element in-lane lookup
            Dest.byte[ j ]←src.byte[ index ];
    ELSE if zeroing
        Dest.byte[ j ]←0;
DEST[MAXVL-1:VL] ← 0;
pgoodman commented 3 years ago

We'll need to add support for the mask registers to Remill's wrapper around XED's decoder. docs/XED/xed.txt is rather old, it should be updated.

pgoodman commented 3 years ago

The xed.txt file is produced from XED's xed-tables.c file, or tables.c file. I recall that I manually had to build the xed-tables.c file from XED's repo... it was a long time ago that I made that file.

adahsuzixin commented 3 years ago

Thanks for your reply. Can you consider prioritizing avx512-support things up after api_improvement?

adahsuzixin commented 3 years ago

BTW, I wonder whether it will help to update xed to 11.2.0 in cxx-common. It looks like there are some improvements in AVX512.

pgoodman commented 3 years ago

It looks to me like the XED version we use is the master branch at the time of producing artifacts. I will look into triggering the workflows to do a rebuild to get a more up-to-date version of XED.

Are you willing to sponsor the development of the AVX512 instruction set extensions to Remill?

adahsuzixin commented 3 years ago

Sure, I'd like to help. But due to my recent work priority, I'm not sure whether I can keep up with the community steps :-)