From b5464a6825e40e6d8ab2dd86c7ff5d65bedd64d4 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Wed, 21 Sep 2016 16:51:16 +0100 Subject: [AArch64][SVE 15/32] Add {insert,extract}_all_fields helpers Several of the SVE operands use the aarch64_operand fields array to store the fields that make up the operand, rather than hard-coding the names in the C code. This patch adds helpers for inserting and extracting those fields. opcodes/ * aarch64-asm.c: Include libiberty.h. (insert_fields): New function. (aarch64_ins_imm): Use it. * aarch64-dis.c (extract_fields): New function. (aarch64_ext_imm): Use it. --- opcodes/aarch64-dis.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'opcodes/aarch64-dis.c') diff --git a/opcodes/aarch64-dis.c b/opcodes/aarch64-dis.c index 9ffc713..67daa66 100644 --- a/opcodes/aarch64-dis.c +++ b/opcodes/aarch64-dis.c @@ -145,6 +145,26 @@ extract_fields (aarch64_insn code, aarch64_insn mask, ...) return value; } +/* Extract the value of all fields in SELF->fields from instruction CODE. + The least significant bit comes from the final field. */ + +static aarch64_insn +extract_all_fields (const aarch64_operand *self, aarch64_insn code) +{ + aarch64_insn value; + unsigned int i; + enum aarch64_field_kind kind; + + value = 0; + for (i = 0; i < ARRAY_SIZE (self->fields) && self->fields[i] != FLD_NIL; ++i) + { + kind = self->fields[i]; + value <<= fields[kind].width; + value |= extract_field (kind, code, 0); + } + return value; +} + /* Sign-extend bit I of VALUE. */ static inline int32_t sign_extend (aarch64_insn value, unsigned i) @@ -575,14 +595,8 @@ aarch64_ext_imm (const aarch64_operand *self, aarch64_opnd_info *info, const aarch64_inst *inst ATTRIBUTE_UNUSED) { int64_t imm; - /* Maximum of two fields to extract. */ - assert (self->fields[2] == FLD_NIL); - if (self->fields[1] == FLD_NIL) - imm = extract_field (self->fields[0], code, 0); - else - /* e.g. TBZ b5:b40. */ - imm = extract_fields (code, 0, 2, self->fields[0], self->fields[1]); + imm = extract_all_fields (self, code); if (info->type == AARCH64_OPND_FPIMM) info->imm.is_fp = 1; -- cgit v1.1