Skip to content

Commit

Permalink
i#2985 drx_expand_scatter_gather(): Add initial support to expand int…
Browse files Browse the repository at this point in the history
…o scalar sequences. (#3831)

Adds the function drx_expand_scatter_gather() that is capable of expanding
AVX-512 scatter and gather and AVX2 gather instructions into equivalent
sequences of scalar code.

WARNING: Do not use yet, support is incomplete.

In particular,

* Certain registers may be clobbered by the sequence and will not be restored.
* Application state may not be properly restored if the sequence is getting interrupted.
* drreg may fail if used in other phases in addition to app2app (xref #3823).

Furthermore,

* AArch64 support is missing (xref #3837).
* The qword index and value versions are not supported in 32-bit mode.

Adds a limited test for the expanded sequences. The test works with above limitations,
because the clobbered registers are not live in the test application and the application
does not check the mask state until the instruction is complete. In the test application
this may result in occasional duplicated scalar loads and stores, but will not break the
test.

Adds a check for the mask registers to test client.avx512ctx.

Issue: #2985, #3837
  • Loading branch information
Hendrik Greving committed Sep 17, 2019
1 parent 704b750 commit 4359ef1
Show file tree
Hide file tree
Showing 9 changed files with 1,248 additions and 4 deletions.
2 changes: 2 additions & 0 deletions api/docs/release.dox
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ Further non-compatibility-affecting changes include:
- Added the function proc_num_opmask_registers();
- reg_get_value_ex() now supports reading AVX-512 mask registers.
- Added the function reg_is_bnd().
- Added the functions instr_is_gather() and instr_is_scatter().
- Added the function drx_expand_scatter_gather().

**************************************************
<hr>
Expand Down
18 changes: 18 additions & 0 deletions core/arch/aarch64/instr.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,21 @@ instr_is_exclusive_store(instr_t *instr)
}
return false;
}

DR_API
bool
instr_is_scatter(instr_t *instr)
{
/* FIXME i#3837: add support. */
ASSERT_NOT_IMPLEMENTED(false);
return false;
}

DR_API
bool
instr_is_gather(instr_t *instr)
{
/* FIXME i#3837: add support. */
ASSERT_NOT_IMPLEMENTED(false);
return false;
}
16 changes: 16 additions & 0 deletions core/arch/arm/instr.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,3 +883,19 @@ instr_is_exclusive_store(instr_t *instr)
return (opcode == OP_strex || opcode == OP_strexb || opcode == OP_strexd ||
opcode == OP_strexh);
}

DR_API
bool
instr_is_scatter(instr_t *instr)
{
/* XXX i#3837: no scatter-store on ARM? */
return false;
}

DR_API
bool
instr_is_gather(instr_t *instr)
{
/* XXX i#3837: no gather-load on ARM? */
return false;
}
14 changes: 14 additions & 0 deletions core/arch/instr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,20 @@ DR_API
bool
instr_is_exclusive_store(instr_t *instr);

DR_API
/**
* Returns true iff \p instr is a scatter-store instruction.
*/
bool
instr_is_scatter(instr_t *instr);

DR_API
/**
* Returns true iff \p instr is a gather-load instruction.
*/
bool
instr_is_gather(instr_t *instr);

bool
instr_predicate_reads_srcs(dr_pred_type_t pred);

Expand Down
34 changes: 34 additions & 0 deletions core/arch/x86/instr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2265,3 +2265,37 @@ instr_is_exclusive_store(instr_t *instr)
{
return false;
}

DR_API
bool
instr_is_scatter(instr_t *instr)
{
switch (instr_get_opcode(instr)) {
case OP_vpscatterdd:
case OP_vscatterdpd:
case OP_vscatterdps:
case OP_vpscatterdq:
case OP_vpscatterqd:
case OP_vscatterqpd:
case OP_vscatterqps:
case OP_vpscatterqq: return true;
default: return false;
}
}

DR_API
bool
instr_is_gather(instr_t *instr)
{
switch (instr_get_opcode(instr)) {
case OP_vpgatherdd:
case OP_vgatherdpd:
case OP_vgatherdps:
case OP_vpgatherdq:
case OP_vpgatherqd:
case OP_vgatherqpd:
case OP_vgatherqps:
case OP_vpgatherqq: return true;
default: return false;
}
}
Loading

0 comments on commit 4359ef1

Please sign in to comment.