Skip to content

Commit

Permalink
i5483: Added binutils tests and fixed failures
Browse files Browse the repository at this point in the history
  - Added binutils tests that do encode and match against expected opcodes
  (this is opposite of the current binutils tests)
  - Removed 66h prefix to pass binutils test
  - Broadcast entries were not reachable. Fixed operand size for
  broadcast. (Updated VNNI tests also)

Issue: #5483
  • Loading branch information
prasun3 committed May 10, 2022
1 parent 250158d commit 2572d9a
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 16 deletions.
34 changes: 18 additions & 16 deletions core/ir/x86/decode_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -5833,13 +5833,15 @@ const instr_info_t prefix_extensions[][12] = {
{INVALID, 0xf3385218, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0x66385218, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0xf2385218, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
/* vex */
{INVALID, 0x385218, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0xf3385218, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{VEX_W_EXT, 0x66385218, "(vex_W ext 112)", xx, xx, xx, xx, xx, no, x, 112},
{VEX_W_EXT, 0x385218, "(vex_W ext 112)", xx, xx, xx, xx, xx, no, x, 112},
{INVALID, 0xf2385218, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
/* evex */
{INVALID, 0x385218, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{EVEX_Wb_EXT,0xf3385218, "(evex_Wb ext 273)", xx, xx, xx, xx, xx, no, x, 273},
{EVEX_Wb_EXT,0x66385218, "(evex_Wb ext 269)", xx, xx, xx, xx, xx, no, x, 269},
{EVEX_Wb_EXT, 0x385218, "(evex_Wb ext 269)", xx, xx, xx, xx, xx, no, x, 269},
{INVALID, 0xf2385218, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
} , { /* prefix extension 190 */
{INVALID, 0x387218, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
Expand Down Expand Up @@ -9324,38 +9326,38 @@ const instr_info_t evex_Wb_extensions[][4] = {
{OP_vsqrtsd, 0xf20f5140, "vsqrtsd", Vdq, xx, KE1b, Hdq, Wsd, mrm|evex|ttt1s, x, tevexwb[266][3]},
{OP_vsqrtsd, 0xf20f5150, "vsqrtsd", Vdq, xx, KE1b, Hdq, Usd, mrm|evex|er|ttt1s, x, END_LIST},
}, { /* evex_W_ext 267 */
{OP_vpdpbusd, 0x66385008, "vpdpbusd", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, END_LIST},
{OP_vpdpbusd, 0x66385018, "vpdpbusd", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, END_LIST},
{OP_vpdpbusd, 0x66385008, "vpdpbusd", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, tevexwb[267][1]},
{OP_vpdpbusd, 0x66385018, "vpdpbusd", Ve, xx, KEd, He, TYPE_W, OPSZ_4, mrm|evex|ttfv, x, END_LIST},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
}, { /* evex_W_ext 268 */
{OP_vpdpbusds, 0x66385108, "vpdpbusds", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, END_LIST},
{OP_vpdpbusds, 0x66385118, "vpdpbusds", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, END_LIST},
{OP_vpdpbusds, 0x66385108, "vpdpbusds", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, tevexwb[268][1]},
{OP_vpdpbusds, 0x66385118, "vpdpbusds", Ve, xx, KEd, He, TYPE_W, OPSZ_4, mrm|evex|ttfv, x, END_LIST},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
}, { /* evex_W_ext 269 */
{OP_vpdpwssd, 0x66385208, "vpdpwssd", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, END_LIST},
{OP_vpdpwssd, 0x66385218, "vpdpwssd", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, END_LIST},
{OP_vpdpwssd, 0x66385208, "vpdpwssd", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, tevexwb[269][1]},
{OP_vpdpwssd, 0x66385218, "vpdpwssd", Ve, xx, KEd, He, TYPE_W, OPSZ_4, mrm|evex|ttfv, x, END_LIST},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
}, { /* evex_W_ext 270 */
{OP_vpdpwssds, 0x66385308, "vpdpwssds", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, END_LIST},
{OP_vpdpwssds, 0x66385318, "vpdpwssds", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, END_LIST},
{OP_vpdpwssds, 0x66385308, "vpdpwssds", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, tevexwb[270][1]},
{OP_vpdpwssds, 0x66385318, "vpdpwssds", Ve, xx, KEd, He, TYPE_W, OPSZ_4, mrm|evex|ttfv, x, END_LIST},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
},{ /* evex_W_ext 271 */
{OP_vcvtne2ps2bf16, 0xf2387208, "vcvtne2ps2bf16", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, END_LIST},
{OP_vcvtne2ps2bf16, 0xf2387218, "vcvtne2ps2bf16", Ve, xx, KEd, He, Wqq, mrm|evex|ttfv, x, END_LIST},
{OP_vcvtne2ps2bf16, 0xf2387208, "vcvtne2ps2bf16", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, tevexwb[271][1]},
{OP_vcvtne2ps2bf16, 0xf2387218, "vcvtne2ps2bf16", Ve, xx, KEd, He, TYPE_W, OPSZ_4, mrm|evex|ttfv, x, END_LIST},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
},{ /* evex_W_ext 272 */
{OP_vcvtneps2bf16, 0xf3387208, "vcvtneps2bf16", Vh_e, xx, KEd, We, xx, mrm|evex|ttfv, x, END_LIST},
{OP_vcvtneps2bf16, 0xf3387218, "vcvtneps2bf16", Vh_e, xx, KEd, Wqq, xx, mrm|evex|ttfv, x, END_LIST},
{OP_vcvtneps2bf16, 0xf3387208, "vcvtneps2bf16", Vh_e, xx, KEd, We, xx, mrm|evex|ttfv, x, tevexwb[272][1]},
{OP_vcvtneps2bf16, 0xf3387218, "vcvtneps2bf16", Vh_e, xx, KEd, TYPE_W, OPSZ_4, xx, mrm|evex|ttfv, x, END_LIST},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
},{ /* evex_W_ext 273 */
{OP_vdpbf16ps, 0xf3385208, "vdpbf16ps", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, END_LIST},
{OP_vdpbf16ps, 0xf3385218, "vdpbf16ps", Ve, xx, KEd, He, Wqq, mrm|evex|ttfv, x, END_LIST},
{OP_vdpbf16ps, 0xf3385208, "vdpbf16ps", Ve, xx, KEd, He, We, mrm|evex|ttfv, x, tevexwb[273][1]},
{OP_vdpbf16ps, 0xf3385218, "vdpbf16ps", Ve, xx, KEd, He, TYPE_W, OPSZ_4, mrm|evex|ttfv, x, END_LIST},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
},
Expand Down
44 changes: 44 additions & 0 deletions third_party/binutils/test_decenc/drdecode_decenc_x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,55 @@ test_s(byte *subtest_asm)
instr_destroy(GD, instr);
}

# define PREFIX_EVEX_z 0x000800000
# define REGARG(reg) opnd_create_reg(DR_REG_##reg)
# include <string.h>
# include "encode_test.h"

static byte buf[32768];

/* emits the instruction to buf (for tests that wish to do additional checks on
* the output) */
static void
test_instr_encode(void *dc, instr_t *instr, uint len_expect)
{
instr_t *decin;
uint len;
byte *pc = instr_encode(dc, instr, buf);
len = (int)(pc - (byte *)buf);
# if VERBOSE
disassemble_with_info(dc, buf, STDOUT, true, true);
# endif
ASSERT(len == len_expect);
decin = instr_create(dc);
decode(dc, buf, decin);
ASSERT(instr_same(instr, decin));
instr_destroy(dc, instr);
instr_destroy(dc, decin);
}

static void
test_avx512_bf16_encoding(void *dc)
{
// from binutils-2.37.90/gas/testsuite/gas/i386
# include "x86-64-avx512_bf16.h"
# include "x86-64-avx512_bf16_vl.h"
}

static void
test_encode_decode()
{
void *dcontext = dr_standalone_init();

test_avx512_bf16_encoding(dcontext);
}

int
main()
{
dr_printf("test_x86_64_s:\n");
test_s((byte *)test_x86_64_s_asm);
test_encode_decode();
dr_printf("done\n");
return 0;
}
Expand Down
56 changes: 56 additions & 0 deletions third_party/binutils/test_decenc/encode_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifdef X64

enum {
ENCODE_FLAG_SET_DST_SIZE_HALF = 1,
ENCODE_FLAG_Z = 2,
};

# define ASSERT(x) \
((void)((!(x)) ? (dr_fprintf(STDERR, "ASSERT FAILURE: %s:%d: %s\n", \
__FILE__, __LINE__, #x), \
dr_abort(), 0) \
: 0))

# define HANDLE_FLAGS(instr, flags) \
do { \
if (flags & ENCODE_FLAG_Z) { \
instr_set_prefix_flag(instr, PREFIX_EVEX_z); \
} \
if (flags & ENCODE_FLAG_SET_DST_SIZE_HALF) { \
opnd_t dst = instr_get_dst(instr, 0); \
if (opnd_get_size(dst) == OPSZ_64) \
opnd_set_size(&dst, OPSZ_32); \
else if (opnd_get_size(dst) == OPSZ_32) \
opnd_set_size(&dst, OPSZ_16); \
else if (opnd_get_size(dst) == OPSZ_16) \
opnd_set_size(&dst, OPSZ_8); \
instr_set_dst(instr, 0, dst); \
} \
} while (0)

//
# if VERBOSE
# define PRINT_TEST_NAME(name) // add fprintf
# else
# define PRINT_TEST_NAME(x)
# endif

# define ENCODE_TEST_3args(name, opc, flags, arg1, arg2, arg3) \
do { \
instr_t *instr = INSTR_CREATE_##opc(dc, arg1, arg2, arg3); \
PRINT_TEST_NAME(name); \
HANDLE_FLAGS(instr, flags); \
test_instr_encode(dc, instr, sizeof(name)); \
ASSERT(!memcmp(buf, name, sizeof(name))); \
} while (0)

# define ENCODE_TEST_4args(name, opc, flags, arg1, arg2, arg3, arg4) \
do { \
instr_t *instr = INSTR_CREATE_##opc(dc, arg1, arg2, arg3, arg4); \
PRINT_TEST_NAME(name); \
HANDLE_FLAGS(instr, flags); \
test_instr_encode(dc, instr, sizeof(name)); \
ASSERT(!memcmp(buf, name, sizeof(name))); \
} while (0)

#endif
32 changes: 32 additions & 0 deletions third_party/binutils/test_decenc/x86-64-avx512_bf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// clang-format off
byte bf16_test00[] = { 0x62, 0x02, 0x17, 0x40, 0x72, 0xf4,}; //
byte bf16_test01[] = { 0x62, 0x22, 0x17, 0x47, 0x72, 0xb4, 0xf5, 0x00, 0x00, 0x00, 0x10,}; //
byte bf16_test02[] = { 0x62, 0x42, 0x17, 0x50, 0x72, 0x31,}; //
byte bf16_test03[] = { 0x62, 0x62, 0x17, 0x40, 0x72, 0x71, 0x7f,}; //
byte bf16_test04[] = { 0x62, 0x62, 0x17, 0xd7, 0x72, 0xb2, 0x00, 0xe0, 0xff, 0xff,}; //
byte bf16_test05[] = { 0x62, 0x02, 0x7e, 0x48, 0x72, 0xf5,}; //
byte bf16_test06[] = { 0x62, 0x22, 0x7e, 0x4f, 0x72, 0xb4, 0xf5, 0x00, 0x00, 0x00, 0x10,}; //
byte bf16_test07[] = { 0x62, 0x42, 0x7e, 0x58, 0x72, 0x31,}; //
byte bf16_test08[] = { 0x62, 0x62, 0x7e, 0x48, 0x72, 0x71, 0x7f,}; //
byte bf16_test09[] = { 0x62, 0x62, 0x7e, 0xdf, 0x72, 0xb2, 0x00, 0xe0, 0xff, 0xff,}; //
byte bf16_test10[] = { 0x62, 0x02, 0x16, 0x40, 0x52, 0xf4,}; //
byte bf16_test11[] = { 0x62, 0x22, 0x16, 0x47, 0x52, 0xb4, 0xf5, 0x00, 0x00, 0x00, 0x10,}; //
byte bf16_test12[] = { 0x62, 0x42, 0x16, 0x50, 0x52, 0x31,}; //
byte bf16_test13[] = { 0x62, 0x62, 0x16, 0x40, 0x52, 0x71, 0x7f,}; //
byte bf16_test14[] = { 0x62, 0x62, 0x16, 0xd7, 0x52, 0xb2, 0x00, 0xe0, 0xff, 0xff,}; //

ENCODE_TEST_4args(bf16_test00, vcvtne2ps2bf16_mask, 0, REGARG (ZMM30), REGARG(K0), REGARG (ZMM29), REGARG (ZMM28));
ENCODE_TEST_4args(bf16_test01, vcvtne2ps2bf16_mask, 0, REGARG (ZMM30), REGARG(K7), REGARG (ZMM29), opnd_create_base_disp(DR_REG_RBP, DR_REG_R14, 8, 0x10000000, OPSZ_64));
ENCODE_TEST_4args(bf16_test02, vcvtne2ps2bf16_mask, 0, REGARG (ZMM30), REGARG(K0), REGARG (ZMM29), opnd_create_base_disp(DR_REG_R9, DR_REG_NULL, 0, 0, OPSZ_4));
ENCODE_TEST_4args(bf16_test03, vcvtne2ps2bf16_mask, 0, REGARG (ZMM30), REGARG(K0), REGARG (ZMM29), opnd_create_base_disp(DR_REG_RCX, DR_REG_NULL, 0, 0x1fc0, OPSZ_64));
ENCODE_TEST_4args(bf16_test04, vcvtne2ps2bf16_mask, ENCODE_FLAG_Z, REGARG (ZMM30), REGARG(K7), REGARG (ZMM29), opnd_create_base_disp(DR_REG_RDX, DR_REG_NULL, 0, 0xffffe000, OPSZ_4));
ENCODE_TEST_3args(bf16_test05, vcvtneps2bf16_mask, ENCODE_FLAG_SET_DST_SIZE_HALF, REGARG (ZMM30), REGARG(K0), REGARG (ZMM29));
ENCODE_TEST_3args(bf16_test06, vcvtneps2bf16_mask, ENCODE_FLAG_SET_DST_SIZE_HALF, REGARG (ZMM30), REGARG(K7), opnd_create_base_disp(DR_REG_RBP, DR_REG_R14, 8, 0x10000000, OPSZ_64));
ENCODE_TEST_3args(bf16_test07, vcvtneps2bf16_mask, ENCODE_FLAG_SET_DST_SIZE_HALF, REGARG (ZMM30), REGARG(K0), opnd_create_base_disp(DR_REG_R9, DR_REG_NULL, 0, 0, OPSZ_4));
ENCODE_TEST_3args(bf16_test08, vcvtneps2bf16_mask, ENCODE_FLAG_SET_DST_SIZE_HALF, REGARG (ZMM30), REGARG(K0), opnd_create_base_disp(DR_REG_RCX, DR_REG_NULL, 0, 0x1fc0, OPSZ_64));
ENCODE_TEST_3args(bf16_test09, vcvtneps2bf16_mask, ENCODE_FLAG_SET_DST_SIZE_HALF|ENCODE_FLAG_Z, REGARG (ZMM30), REGARG(K7), opnd_create_base_disp(DR_REG_RDX, DR_REG_NULL, 0, 0xffffe000, OPSZ_4));
ENCODE_TEST_4args(bf16_test10, vdpbf16ps_mask, 0, REGARG (ZMM30), REGARG(K0), REGARG (ZMM29), REGARG (ZMM28));
ENCODE_TEST_4args(bf16_test11, vdpbf16ps_mask, 0, REGARG (ZMM30), REGARG(K7), REGARG (ZMM29), opnd_create_base_disp(DR_REG_RBP, DR_REG_R14, 8, 0x10000000, OPSZ_64));
ENCODE_TEST_4args(bf16_test12, vdpbf16ps_mask, 0, REGARG (ZMM30), REGARG(K0), REGARG (ZMM29), opnd_create_base_disp(DR_REG_R9, DR_REG_NULL, 0, 0, OPSZ_4));
ENCODE_TEST_4args(bf16_test13, vdpbf16ps_mask, 0, REGARG (ZMM30), REGARG(K0), REGARG (ZMM29), opnd_create_base_disp(DR_REG_RCX, DR_REG_NULL, 0, 0x1fc0, OPSZ_64));
ENCODE_TEST_4args(bf16_test14, vdpbf16ps_mask, ENCODE_FLAG_Z, REGARG (ZMM30), REGARG(K7), REGARG (ZMM29), opnd_create_base_disp(DR_REG_RDX, DR_REG_NULL, 0, 0xffffe000, OPSZ_4));
Loading

0 comments on commit 2572d9a

Please sign in to comment.