Skip to content

Commit

Permalink
i#5036 A64 scatter gather: Avoid dependency on drutil (#6389)
Browse files Browse the repository at this point in the history
drx has a BSD license so we don't want it to depend on drutil which has
an LGPL license.

The replaces the drutil_insert_get_mem_addr() call with equivalent code
to calculate the start address for the contiguous memory range.

Issue: #5036
  • Loading branch information
jackgallagher-arm authored Oct 23, 2023
1 parent 3ac4375 commit 196979b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
6 changes: 0 additions & 6 deletions ext/drx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ configure_extension(drx OFF)
use_DynamoRIO_extension(drx drcontainers)
use_DynamoRIO_extension(drx drmgr)
use_DynamoRIO_extension(drx drreg)
if (AARCH64)
use_DynamoRIO_extension(drx drutil)
endif ()

# While we use drmgr in our implementation of drx, we only use pieces that
# do not rely on drmgr's 4 phases or event orderings, and we do not include
Expand All @@ -87,9 +84,6 @@ configure_extension(drx_static ON)
use_DynamoRIO_extension(drx_static drcontainers)
use_DynamoRIO_extension(drx_static drmgr_static)
use_DynamoRIO_extension(drx_static drreg_static)
if (AARCH64)
use_DynamoRIO_extension(drx_static drutil_static)
endif ()
configure_drx_target(drx_static)

install_ext_header(drx.h)
44 changes: 23 additions & 21 deletions ext/drx/scatter_gather_aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "drx.h"
#include "drmgr.h"
#include "drreg.h"
#include "drutil.h"
#include "../ext_utils.h"
#include "scatter_gather_shared.h"

Expand Down Expand Up @@ -581,32 +580,36 @@ expand_scatter_gather(void *drcontext, instrlist_t *bb, instr_t *sg_instr,
*
* which can be expanded the same way as a regular scalar+vector scatter/gather operation.
*/
static bool
static void
expand_contiguous(void *drcontext, instrlist_t *bb, instr_t *sg_instr,
const scatter_gather_info_t *sg_info, reg_id_t scratch_gpr0,
reg_id_t scratch_gpr1, reg_id_t scratch_gpr2, reg_id_t scratch_pred,
reg_id_t scratch_vec, app_pc orig_app_pc)
{
/* Calculate the new base address in scratch_gpr0. */
const opnd_t mem =
sg_info->is_load ? instr_get_src(sg_instr, 0) : instr_get_dst(sg_instr, 0);
if (!drutil_insert_get_mem_addr(drcontext, bb, sg_instr, mem, scratch_gpr0,
scratch_gpr1))
return false;
#define EMIT(op, ...) \
instrlist_preinsert( \
bb, sg_instr, INSTR_XL8(INSTR_CREATE_##op(drcontext, __VA_ARGS__), orig_app_pc))

/* Calculate the new base address in scratch_gpr0.
* Note that we can't use drutil_insert_get_mem_addr() here because we don't want the
* BSD licensed drx to have a dependency on the LGPL licensed drutil.
*/

DR_ASSERT(sg_info->index_reg != DR_REG_NULL);

/* add scratch_gpr0, base_reg, index_reg, extend #extend_amount */
EMIT(add_extend, opnd_create_reg(scratch_gpr0), opnd_create_reg(sg_info->base_reg),
opnd_create_reg(sg_info->index_reg), OPND_CREATE_INT(sg_info->extend),
OPND_CREATE_INT(sg_info->extend_amount));

/* Populate the new vector index register, starting at 0 and incrementing by 1 every
* time.
*/

/* index scratch_vec.element_size, #0, #1 */
instrlist_preinsert(
bb, sg_instr,
INSTR_XL8(INSTR_CREATE_index_sve(
drcontext,
opnd_create_reg_element_vector(scratch_vec, sg_info->element_size),
/*starting value=*/opnd_create_immed_int(0, OPSZ_5b),
/*increment=*/opnd_create_immed_int(1, OPSZ_5b)),
orig_app_pc));
EMIT(index_sve, opnd_create_reg_element_vector(scratch_vec, sg_info->element_size),
/*starting value=*/opnd_create_immed_int(0, OPSZ_5b),
/*increment=*/opnd_create_immed_int(1, OPSZ_5b));

/* Create a new scatter_gather_info_t with the updated registers. */
scatter_gather_info_t modified_sg_info = *sg_info;
Expand All @@ -629,7 +632,7 @@ expand_contiguous(void *drcontext, instrlist_t *bb, instr_t *sg_instr,
expand_scatter_gather(drcontext, bb, sg_instr, &modified_sg_info, scratch_gpr1,
scratch_gpr2, scratch_pred, orig_app_pc);

return true;
#undef EMIT
}

/* Spill a scratch predicate or vector register.
Expand Down Expand Up @@ -916,10 +919,9 @@ drx_expand_scatter_gather(void *drcontext, instrlist_t *bb, OUT bool *expanded)

if (is_contiguous) {
/* scalar+scalar predicated contiguous access */
if (!expand_contiguous(drcontext, bb, sg_instr, &sg_info, scratch_gpr[0],
scratch_gpr[1], scratch_gpr[2], scratch_pred, scratch_vec,
orig_app_pc))
goto drx_expand_scatter_gather_exit;
expand_contiguous(drcontext, bb, sg_instr, &sg_info, scratch_gpr[0],
scratch_gpr[1], scratch_gpr[2], scratch_pred, scratch_vec,
orig_app_pc);
} else {
/* scalar+vector or vector+immediate scatter/gather */
expand_scatter_gather(drcontext, bb, sg_instr, &sg_info, scratch_gpr[0],
Expand Down

0 comments on commit 196979b

Please sign in to comment.