Skip to content

Commit

Permalink
i#1569 AArch64: Fix macros to create AND,ANDs with imms. (#3010)
Browse files Browse the repository at this point in the history
Instructions that take logical immediates are not encoded with shifts.

Issue: #1569
  • Loading branch information
fhahn authored May 16, 2018
1 parent ab738f7 commit 6427ce0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
24 changes: 22 additions & 2 deletions core/arch/aarch64/instr_create.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,34 @@
(opnd_is_reg(rm_or_imm) ? \
INSTR_CREATE_adds_shift(dc, rd, rn, rm_or_imm, OPND_CREATE_LSL(), OPND_CREATE_INT(0)) : \
INSTR_CREATE_adds_imm(dc, rd, rn, rm_or_imm, OPND_CREATE_INT(0)))

/**
* Creates an AND instruction with one output and two inputs.
* \param dc The void * dcontext used to allocate memory for the instr_t.
* \param rd The output register.
* \param rn The first input register.
* \param rm_or_imm The second input register or immediate.
*/
#define INSTR_CREATE_and(dc, rd, rn, rm_or_imm) \
INSTR_CREATE_and_shift(dc, rd, rn, rm_or_imm, OPND_CREATE_LSL(), OPND_CREATE_INT(0))
(opnd_is_immed(rm_or_imm) ? instr_create_1dst_2src((dc), OP_and, (rd), (rn), (rm_or_imm)) : \
INSTR_CREATE_and_shift(dc, rd, rn, rm_or_imm, OPND_CREATE_LSL(), \
OPND_CREATE_INT(0)))
#define INSTR_CREATE_and_shift(dc, rd, rn, rm, sht, sha) \
instr_create_1dst_4src((dc), OP_and, (rd), (rn), \
opnd_create_reg_ex(opnd_get_reg(rm), 0, DR_OPND_SHIFTED), \
opnd_add_flags((sht), DR_OPND_IS_SHIFT), (sha))

/**
* Creates an ANDS instruction with one output and two inputs.
* \param dc The void * dcontext used to allocate memory for the instr_t.
* \param rd The output register.
* \param rn The first input register.
* \param rm_or_imm The second input register or immediate.
*/
#define INSTR_CREATE_ands(dc, rd, rn, rm_or_imm) \
INSTR_CREATE_ands_shift(dc, rd, rn, rm_or_imm, OPND_CREATE_LSL(), OPND_CREATE_INT(0))
(opnd_is_immed(rm_or_imm) ? instr_create_1dst_2src((dc), OP_ands, (rd), (rn), (rm_or_imm)) : \
INSTR_CREATE_ands_shift(dc, rd, rn, rm_or_imm, OPND_CREATE_LSL(), \
OPND_CREATE_INT(0)))
#define INSTR_CREATE_ands_shift(dc, rd, rn, rm, sht, sha) \
instr_create_1dst_4src((dc), OP_ands, (rd), (rn), \
opnd_create_reg_ex(opnd_get_reg(rm), 0, DR_OPND_SHIFTED), \
Expand Down
27 changes: 26 additions & 1 deletion suite/tests/api/ir_aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,33 @@ test_ldar(void *dc)
}

static void
test_fmov_general(void *dc)
test_instrs_with_logic_imm(void *dc)
{
byte *pc;
instr_t *instr;

instr = INSTR_CREATE_and(dc, opnd_create_reg(DR_REG_X10),
opnd_create_reg(DR_REG_X9), OPND_CREATE_INT(0xFFFF));
test_instr_encoding(dc, OP_and, instr);

instr = INSTR_CREATE_and(dc, opnd_create_reg(DR_REG_W5),
opnd_create_reg(DR_REG_W5), OPND_CREATE_INT(0xFF));
test_instr_encoding(dc, OP_and, instr);

instr = INSTR_CREATE_ands(dc, opnd_create_reg(DR_REG_X23),
opnd_create_reg(DR_REG_X19), OPND_CREATE_INT(0xFFFFFF));
test_instr_encoding(dc, OP_ands, instr);

instr = INSTR_CREATE_ands(dc, opnd_create_reg(DR_REG_W3),
opnd_create_reg(DR_REG_W8), OPND_CREATE_INT(0xF));
test_instr_encoding(dc, OP_ands, instr);
}

static void
test_fmov_general(void *dc)
{
byte *pc;
instr_t *instr;
instr = INSTR_CREATE_fmov_general(dc, opnd_create_reg(DR_REG_H10),
opnd_create_reg(DR_REG_W9));
test_instr_encoding(dc, OP_fmov, instr);
Expand Down Expand Up @@ -1585,6 +1607,9 @@ main(int argc, char *argv[])
test_ldar(dcontext);
print("test_ldar complete\n");

test_instrs_with_logic_imm(dcontext);
print("test_instrs_with_logic_imm complete\n");

test_fmov_general(dcontext);
print("test_fmov_general complete\n");

Expand Down
5 changes: 5 additions & 0 deletions suite/tests/api/ir_aarch64.expect
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ ldar (%x1)[8byte] -> %x0
ldarb (%x1)[1byte] -> %w0
ldarh (%x1)[2byte] -> %w0
test_ldar complete
and %x9 $0x000000000000ffff -> %x10
and %w5 $0x00000000000000ff -> %w5
ands %x19 $0x0000000000ffffff -> %x23
ands %w8 $0x000000000000000f -> %w3
test_instrs_with_logic_imm complete
fmov %w9 -> %h10
fmov %w4 -> %s14
fmov %x8 -> %h23
Expand Down

0 comments on commit 6427ce0

Please sign in to comment.