2012-02-18 20:03:15 +08:00
|
|
|
//===-- ARMAddressingModes.h - ARM Addressing Modes -------------*- C++ -*-===//
|
2007-01-19 15:51:42 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2007-01-19 15:51:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the ARM addressing mode implementation stuff.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMADDRESSINGMODES_H
|
|
|
|
#define LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMADDRESSINGMODES_H
|
2007-01-19 15:51:42 +08:00
|
|
|
|
2011-09-30 08:50:06 +08:00
|
|
|
#include "llvm/ADT/APFloat.h"
|
|
|
|
#include "llvm/ADT/APInt.h"
|
2018-09-08 11:55:25 +08:00
|
|
|
#include "llvm/ADT/bit.h"
|
2012-02-07 10:50:20 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2007-01-19 15:51:42 +08:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
namespace llvm {
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// ARM_AM - ARM Addressing Mode Stuff
|
|
|
|
namespace ARM_AM {
|
|
|
|
enum ShiftOpc {
|
|
|
|
no_shift = 0,
|
|
|
|
asr,
|
|
|
|
lsl,
|
|
|
|
lsr,
|
|
|
|
ror,
|
[ARM] Add MVE vector load/store instructions.
This adds the rest of the vector memory access instructions. It
includes contiguous loads/stores, with an ordinary addressing mode
such as [r0,#offset] (plus writeback variants); gather loads and
scatter stores with a scalar base address register and a vector of
offsets from it (written [r0,q1] or similar); and gather/scatters with
a vector of base addresses (written [q0,#offset], again with
writeback). Additionally, some of the loads can widen each loaded
value into a larger vector lane, and the corresponding stores narrow
them again.
To implement these, we also have to add the addressing modes they
need. Also, in AsmParser, the `isMem` query function now has
subqueries `isGPRMem` and `isMVEMem`, according to which kind of base
register is used by a given memory access operand.
I've also had to add an extra check in `checkTargetMatchPredicate` in
the AsmParser, without which our last-minute check of `rGPR` register
operands against SP and PC was failing an assertion because Tablegen
had inserted an immediate 0 in place of one of a pair of tied register
operands. (This matches the way the corresponding check for `MCK_rGPR`
in `validateTargetOperandClass` is guarded.) Apparently the MVE load
instructions were the first to have ever triggered this assertion, but
I think only because they were the first to have a combination of the
usual Arm pre/post writeback system and the `rGPR` class in particular.
Reviewers: dmgreen, samparker, SjoerdMeijer, t.p.northover
Subscribers: javed.absar, kristof.beyls, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D62680
llvm-svn: 364291
2019-06-25 19:24:18 +08:00
|
|
|
rrx,
|
|
|
|
uxtw
|
2007-01-19 15:51:42 +08:00
|
|
|
};
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
enum AddrOpc {
|
2011-08-04 07:50:40 +08:00
|
|
|
sub = 0,
|
|
|
|
add
|
2007-01-19 15:51:42 +08:00
|
|
|
};
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline const char *getAddrOpcStr(AddrOpc Op) { return Op == sub ? "-" : ""; }
|
2010-03-18 01:52:21 +08:00
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline const char *getShiftOpcStr(ShiftOpc Op) {
|
2007-01-19 15:51:42 +08:00
|
|
|
switch (Op) {
|
2012-02-07 10:50:20 +08:00
|
|
|
default: llvm_unreachable("Unknown shift opc!");
|
2007-01-19 15:51:42 +08:00
|
|
|
case ARM_AM::asr: return "asr";
|
|
|
|
case ARM_AM::lsl: return "lsl";
|
|
|
|
case ARM_AM::lsr: return "lsr";
|
|
|
|
case ARM_AM::ror: return "ror";
|
|
|
|
case ARM_AM::rrx: return "rrx";
|
[ARM] Add MVE vector load/store instructions.
This adds the rest of the vector memory access instructions. It
includes contiguous loads/stores, with an ordinary addressing mode
such as [r0,#offset] (plus writeback variants); gather loads and
scatter stores with a scalar base address register and a vector of
offsets from it (written [r0,q1] or similar); and gather/scatters with
a vector of base addresses (written [q0,#offset], again with
writeback). Additionally, some of the loads can widen each loaded
value into a larger vector lane, and the corresponding stores narrow
them again.
To implement these, we also have to add the addressing modes they
need. Also, in AsmParser, the `isMem` query function now has
subqueries `isGPRMem` and `isMVEMem`, according to which kind of base
register is used by a given memory access operand.
I've also had to add an extra check in `checkTargetMatchPredicate` in
the AsmParser, without which our last-minute check of `rGPR` register
operands against SP and PC was failing an assertion because Tablegen
had inserted an immediate 0 in place of one of a pair of tied register
operands. (This matches the way the corresponding check for `MCK_rGPR`
in `validateTargetOperandClass` is guarded.) Apparently the MVE load
instructions were the first to have ever triggered this assertion, but
I think only because they were the first to have a combination of the
usual Arm pre/post writeback system and the `rGPR` class in particular.
Reviewers: dmgreen, samparker, SjoerdMeijer, t.p.northover
Subscribers: javed.absar, kristof.beyls, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D62680
llvm-svn: 364291
2019-06-25 19:24:18 +08:00
|
|
|
case ARM_AM::uxtw: return "uxtw";
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
|
|
|
}
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getShiftOpcEncoding(ShiftOpc Op) {
|
2010-10-12 07:16:21 +08:00
|
|
|
switch (Op) {
|
2012-02-07 10:50:20 +08:00
|
|
|
default: llvm_unreachable("Unknown shift opc!");
|
2010-10-12 07:16:21 +08:00
|
|
|
case ARM_AM::asr: return 2;
|
|
|
|
case ARM_AM::lsl: return 0;
|
|
|
|
case ARM_AM::lsr: return 1;
|
|
|
|
case ARM_AM::ror: return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
enum AMSubMode {
|
|
|
|
bad_am_submode = 0,
|
|
|
|
ia,
|
|
|
|
ib,
|
|
|
|
da,
|
|
|
|
db
|
|
|
|
};
|
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline const char *getAMSubModeStr(AMSubMode Mode) {
|
2007-01-19 15:51:42 +08:00
|
|
|
switch (Mode) {
|
2012-02-07 10:50:20 +08:00
|
|
|
default: llvm_unreachable("Unknown addressing sub-mode!");
|
2007-01-19 15:51:42 +08:00
|
|
|
case ARM_AM::ia: return "ia";
|
|
|
|
case ARM_AM::ib: return "ib";
|
|
|
|
case ARM_AM::da: return "da";
|
|
|
|
case ARM_AM::db: return "db";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// rotr32 - Rotate a 32-bit unsigned value right by a specified # bits.
|
|
|
|
///
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned rotr32(unsigned Val, unsigned Amt) {
|
2007-01-19 15:51:42 +08:00
|
|
|
assert(Amt < 32 && "Invalid rotate amount");
|
|
|
|
return (Val >> Amt) | (Val << ((32-Amt)&31));
|
|
|
|
}
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// rotl32 - Rotate a 32-bit unsigned value left by a specified # bits.
|
|
|
|
///
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned rotl32(unsigned Val, unsigned Amt) {
|
2007-01-19 15:51:42 +08:00
|
|
|
assert(Amt < 32 && "Invalid rotate amount");
|
|
|
|
return (Val << Amt) | (Val >> ((32-Amt)&31));
|
|
|
|
}
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Addressing Mode #1: shift_operand with registers
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This 'addressing mode' is used for arithmetic instructions. It can
|
|
|
|
// represent things like:
|
|
|
|
// reg
|
|
|
|
// reg [asr|lsl|lsr|ror|rrx] reg
|
|
|
|
// reg [asr|lsl|lsr|ror|rrx] imm
|
|
|
|
//
|
|
|
|
// This is stored three operands [rega, regb, opc]. The first is the base
|
|
|
|
// reg, the second is the shift amount (or reg0 if not present or imm). The
|
|
|
|
// third operand encodes the shift opcode and the imm if a reg isn't present.
|
|
|
|
//
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getSORegOpc(ShiftOpc ShOp, unsigned Imm) {
|
2007-01-19 15:51:42 +08:00
|
|
|
return ShOp | (Imm << 3);
|
|
|
|
}
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getSORegOffset(unsigned Op) { return Op >> 3; }
|
|
|
|
inline ShiftOpc getSORegShOp(unsigned Op) { return (ShiftOpc)(Op & 7); }
|
2007-01-19 15:51:42 +08:00
|
|
|
|
|
|
|
/// getSOImmValImm - Given an encoded imm field for the reg/imm form, return
|
|
|
|
/// the 8-bit imm value.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getSOImmValImm(unsigned Imm) { return Imm & 0xFF; }
|
2009-03-31 02:49:37 +08:00
|
|
|
/// getSOImmValRot - Given an encoded imm field for the reg/imm form, return
|
2007-01-19 15:51:42 +08:00
|
|
|
/// the rotate amount.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getSOImmValRot(unsigned Imm) { return (Imm >> 8) * 2; }
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// getSOImmValRotate - Try to handle Imm with an immediate shifter operand,
|
|
|
|
/// computing the rotate amount to use. If this immediate value cannot be
|
|
|
|
/// handled with a single shifter-op, determine a good rotate amount that will
|
|
|
|
/// take a maximal chunk of bits out of the immediate.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getSOImmValRotate(unsigned Imm) {
|
2007-01-19 15:51:42 +08:00
|
|
|
// 8-bit (or less) immediates are trivially shifter_operands with a rotate
|
|
|
|
// of zero.
|
|
|
|
if ((Imm & ~255U) == 0) return 0;
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// Use CTZ to compute the rotate amount.
|
2013-05-25 06:23:49 +08:00
|
|
|
unsigned TZ = countTrailingZeros(Imm);
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// Rotate amount must be even. Something like 0x200 must be rotated 8 bits,
|
|
|
|
// not 9.
|
|
|
|
unsigned RotAmt = TZ & ~1;
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// If we can handle this spread, return it.
|
|
|
|
if ((rotr32(Imm, RotAmt) & ~255U) == 0)
|
|
|
|
return (32-RotAmt)&31; // HW rotates right, not left.
|
|
|
|
|
2010-04-14 04:35:16 +08:00
|
|
|
// For values like 0xF000000F, we should ignore the low 6 bits, then
|
2007-01-19 15:51:42 +08:00
|
|
|
// retry the hunt.
|
2010-04-14 04:35:16 +08:00
|
|
|
if (Imm & 63U) {
|
2013-05-25 06:23:49 +08:00
|
|
|
unsigned TZ2 = countTrailingZeros(Imm & ~63U);
|
2010-04-13 10:11:48 +08:00
|
|
|
unsigned RotAmt2 = TZ2 & ~1;
|
|
|
|
if ((rotr32(Imm, RotAmt2) & ~255U) == 0)
|
|
|
|
return (32-RotAmt2)&31; // HW rotates right, not left.
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// Otherwise, we have no way to cover this span of bits with a single
|
|
|
|
// shifter_op immediate. Return a chunk of bits that will be useful to
|
|
|
|
// handle.
|
|
|
|
return (32-RotAmt)&31; // HW rotates right, not left.
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getSOImmVal - Given a 32-bit immediate, if it is something that can fit
|
|
|
|
/// into an shifter_operand immediate operand, return the 12-bit encoding for
|
|
|
|
/// it. If not, return -1.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline int getSOImmVal(unsigned Arg) {
|
2007-01-19 15:51:42 +08:00
|
|
|
// 8-bit (or less) immediates are trivially shifter_operands with a rotate
|
|
|
|
// of zero.
|
|
|
|
if ((Arg & ~255U) == 0) return Arg;
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2010-03-18 02:32:39 +08:00
|
|
|
unsigned RotAmt = getSOImmValRotate(Arg);
|
2007-01-19 15:51:42 +08:00
|
|
|
|
|
|
|
// If this cannot be handled with a single shifter_op, bail out.
|
|
|
|
if (rotr32(~255U, RotAmt) & Arg)
|
|
|
|
return -1;
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// Encode this correctly.
|
|
|
|
return rotl32(Arg, RotAmt) | ((RotAmt>>1) << 8);
|
|
|
|
}
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// isSOImmTwoPartVal - Return true if the specified value can be obtained by
|
|
|
|
/// or'ing together two SOImmVal's.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline bool isSOImmTwoPartVal(unsigned V) {
|
2007-01-19 15:51:42 +08:00
|
|
|
// If this can be handled with a single shifter_op, bail out.
|
|
|
|
V = rotr32(~255U, getSOImmValRotate(V)) & V;
|
|
|
|
if (V == 0)
|
|
|
|
return false;
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// If this can be handled with two shifter_op's, accept.
|
|
|
|
V = rotr32(~255U, getSOImmValRotate(V)) & V;
|
|
|
|
return V == 0;
|
|
|
|
}
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// getSOImmTwoPartFirst - If V is a value that satisfies isSOImmTwoPartVal,
|
|
|
|
/// return the first chunk of it.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getSOImmTwoPartFirst(unsigned V) {
|
2007-01-19 15:51:42 +08:00
|
|
|
return rotr32(255U, getSOImmValRotate(V)) & V;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getSOImmTwoPartSecond - If V is a value that satisfies isSOImmTwoPartVal,
|
|
|
|
/// return the second chunk of it.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getSOImmTwoPartSecond(unsigned V) {
|
2009-08-11 23:33:49 +08:00
|
|
|
// Mask out the first hunk.
|
2007-01-19 15:51:42 +08:00
|
|
|
V = rotr32(~255U, getSOImmValRotate(V)) & V;
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// Take what's left.
|
|
|
|
assert(V == (rotr32(255U, getSOImmValRotate(V)) & V));
|
|
|
|
return V;
|
|
|
|
}
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// getThumbImmValShift - Try to handle Imm with a 8-bit immediate followed
|
|
|
|
/// by a left shift. Returns the shift amount to use.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getThumbImmValShift(unsigned Imm) {
|
2007-01-19 15:51:42 +08:00
|
|
|
// 8-bit (or less) immediates are trivially immediate operand with a shift
|
|
|
|
// of zero.
|
|
|
|
if ((Imm & ~255U) == 0) return 0;
|
|
|
|
|
|
|
|
// Use CTZ to compute the shift amount.
|
2013-05-25 06:23:49 +08:00
|
|
|
return countTrailingZeros(Imm);
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// isThumbImmShiftedVal - Return true if the specified value can be obtained
|
|
|
|
/// by left shifting a 8-bit immediate.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline bool isThumbImmShiftedVal(unsigned V) {
|
2009-08-11 23:33:49 +08:00
|
|
|
// If this can be handled with
|
2007-01-19 15:51:42 +08:00
|
|
|
V = (~255U << getThumbImmValShift(V)) & V;
|
|
|
|
return V == 0;
|
|
|
|
}
|
|
|
|
|
2009-06-24 01:48:47 +08:00
|
|
|
/// getThumbImm16ValShift - Try to handle Imm with a 16-bit immediate followed
|
|
|
|
/// by a left shift. Returns the shift amount to use.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getThumbImm16ValShift(unsigned Imm) {
|
2009-06-24 01:48:47 +08:00
|
|
|
// 16-bit (or less) immediates are trivially immediate operand with a shift
|
|
|
|
// of zero.
|
|
|
|
if ((Imm & ~65535U) == 0) return 0;
|
|
|
|
|
|
|
|
// Use CTZ to compute the shift amount.
|
2013-05-25 06:23:49 +08:00
|
|
|
return countTrailingZeros(Imm);
|
2009-06-24 01:48:47 +08:00
|
|
|
}
|
|
|
|
|
2009-08-11 23:33:49 +08:00
|
|
|
/// isThumbImm16ShiftedVal - Return true if the specified value can be
|
2009-06-24 01:48:47 +08:00
|
|
|
/// obtained by left shifting a 16-bit immediate.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline bool isThumbImm16ShiftedVal(unsigned V) {
|
2009-08-11 23:33:49 +08:00
|
|
|
// If this can be handled with
|
2009-06-24 01:48:47 +08:00
|
|
|
V = (~65535U << getThumbImm16ValShift(V)) & V;
|
|
|
|
return V == 0;
|
|
|
|
}
|
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// getThumbImmNonShiftedVal - If V is a value that satisfies
|
|
|
|
/// isThumbImmShiftedVal, return the non-shiftd value.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getThumbImmNonShiftedVal(unsigned V) {
|
2007-01-19 15:51:42 +08:00
|
|
|
return V >> getThumbImmValShift(V);
|
|
|
|
}
|
|
|
|
|
2009-07-28 13:48:47 +08:00
|
|
|
|
2009-06-24 01:48:47 +08:00
|
|
|
/// getT2SOImmValSplat - Return the 12-bit encoded representation
|
|
|
|
/// if the specified value can be obtained by splatting the low 8 bits
|
|
|
|
/// into every other byte or every byte of a 32-bit value. i.e.,
|
|
|
|
/// 00000000 00000000 00000000 abcdefgh control = 0
|
|
|
|
/// 00000000 abcdefgh 00000000 abcdefgh control = 1
|
|
|
|
/// abcdefgh 00000000 abcdefgh 00000000 control = 2
|
|
|
|
/// abcdefgh abcdefgh abcdefgh abcdefgh control = 3
|
|
|
|
/// Return -1 if none of the above apply.
|
|
|
|
/// See ARM Reference Manual A6.3.2.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline int getT2SOImmValSplatVal(unsigned V) {
|
2009-06-24 01:48:47 +08:00
|
|
|
unsigned u, Vs, Imm;
|
|
|
|
// control = 0
|
2009-08-11 23:33:49 +08:00
|
|
|
if ((V & 0xffffff00) == 0)
|
2009-06-24 01:48:47 +08:00
|
|
|
return V;
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2009-06-24 01:48:47 +08:00
|
|
|
// If the value is zeroes in the first byte, just shift those off
|
|
|
|
Vs = ((V & 0xff) == 0) ? V >> 8 : V;
|
|
|
|
// Any passing value only has 8 bits of payload, splatted across the word
|
|
|
|
Imm = Vs & 0xff;
|
|
|
|
// Likewise, any passing values have the payload splatted into the 3rd byte
|
|
|
|
u = Imm | (Imm << 16);
|
|
|
|
|
|
|
|
// control = 1 or 2
|
|
|
|
if (Vs == u)
|
|
|
|
return (((Vs == V) ? 1 : 2) << 8) | Imm;
|
|
|
|
|
|
|
|
// control = 3
|
|
|
|
if (Vs == (u | (u << 8)))
|
|
|
|
return (3 << 8) | Imm;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-07-28 13:48:47 +08:00
|
|
|
/// getT2SOImmValRotateVal - Return the 12-bit encoded representation if the
|
2009-06-24 01:48:47 +08:00
|
|
|
/// specified value is a rotated 8-bit value. Return -1 if no rotation
|
|
|
|
/// encoding is possible.
|
|
|
|
/// See ARM Reference Manual A6.3.2.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline int getT2SOImmValRotateVal(unsigned V) {
|
2013-05-25 06:23:49 +08:00
|
|
|
unsigned RotAmt = countLeadingZeros(V);
|
2009-06-24 01:48:47 +08:00
|
|
|
if (RotAmt >= 24)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// If 'Arg' can be handled with a single shifter_op return the value.
|
|
|
|
if ((rotr32(0xff000000U, RotAmt) & V) == V)
|
|
|
|
return (rotr32(V, 24 - RotAmt) & 0x7f) | ((RotAmt + 8) << 7);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getT2SOImmVal - Given a 32-bit immediate, if it is something that can fit
|
2009-08-11 23:33:49 +08:00
|
|
|
/// into a Thumb-2 shifter_operand immediate operand, return the 12-bit
|
2009-06-24 01:48:47 +08:00
|
|
|
/// encoding for it. If not, return -1.
|
|
|
|
/// See ARM Reference Manual A6.3.2.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline int getT2SOImmVal(unsigned Arg) {
|
2009-06-24 01:48:47 +08:00
|
|
|
// If 'Arg' is an 8-bit splat, then get the encoded value.
|
2009-07-28 13:48:47 +08:00
|
|
|
int Splat = getT2SOImmValSplatVal(Arg);
|
2009-06-24 01:48:47 +08:00
|
|
|
if (Splat != -1)
|
|
|
|
return Splat;
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2009-06-24 01:48:47 +08:00
|
|
|
// If 'Arg' can be handled with a single shifter_op return the value.
|
2009-07-28 13:48:47 +08:00
|
|
|
int Rot = getT2SOImmValRotateVal(Arg);
|
2009-06-24 01:48:47 +08:00
|
|
|
if (Rot != -1)
|
|
|
|
return Rot;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getT2SOImmValRotate(unsigned V) {
|
2009-10-22 04:44:34 +08:00
|
|
|
if ((V & ~255U) == 0) return 0;
|
|
|
|
// Use CTZ to compute the rotate amount.
|
2013-05-25 06:23:49 +08:00
|
|
|
unsigned RotAmt = countTrailingZeros(V);
|
2009-10-22 04:44:34 +08:00
|
|
|
return (32 - RotAmt) & 31;
|
|
|
|
}
|
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline bool isT2SOImmTwoPartVal(unsigned Imm) {
|
2009-10-22 04:44:34 +08:00
|
|
|
unsigned V = Imm;
|
|
|
|
// Passing values can be any combination of splat values and shifter
|
|
|
|
// values. If this can be handled with a single shifter or splat, bail
|
|
|
|
// out. Those should be handled directly, not with a two-part val.
|
|
|
|
if (getT2SOImmValSplatVal(V) != -1)
|
|
|
|
return false;
|
|
|
|
V = rotr32 (~255U, getT2SOImmValRotate(V)) & V;
|
|
|
|
if (V == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If this can be handled as an immediate, accept.
|
|
|
|
if (getT2SOImmVal(V) != -1) return true;
|
|
|
|
|
|
|
|
// Likewise, try masking out a splat value first.
|
|
|
|
V = Imm;
|
|
|
|
if (getT2SOImmValSplatVal(V & 0xff00ff00U) != -1)
|
|
|
|
V &= ~0xff00ff00U;
|
|
|
|
else if (getT2SOImmValSplatVal(V & 0x00ff00ffU) != -1)
|
|
|
|
V &= ~0x00ff00ffU;
|
|
|
|
// If what's left can be handled as an immediate, accept.
|
|
|
|
if (getT2SOImmVal(V) != -1) return true;
|
|
|
|
|
|
|
|
// Otherwise, do not accept.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getT2SOImmTwoPartFirst(unsigned Imm) {
|
2009-10-22 04:44:34 +08:00
|
|
|
assert (isT2SOImmTwoPartVal(Imm) &&
|
|
|
|
"Immedate cannot be encoded as two part immediate!");
|
|
|
|
// Try a shifter operand as one part
|
|
|
|
unsigned V = rotr32 (~255, getT2SOImmValRotate(Imm)) & Imm;
|
|
|
|
// If the rest is encodable as an immediate, then return it.
|
|
|
|
if (getT2SOImmVal(V) != -1) return V;
|
|
|
|
|
|
|
|
// Try masking out a splat value first.
|
|
|
|
if (getT2SOImmValSplatVal(Imm & 0xff00ff00U) != -1)
|
|
|
|
return Imm & 0xff00ff00U;
|
|
|
|
|
|
|
|
// The other splat is all that's left as an option.
|
|
|
|
assert (getT2SOImmValSplatVal(Imm & 0x00ff00ffU) != -1);
|
|
|
|
return Imm & 0x00ff00ffU;
|
|
|
|
}
|
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getT2SOImmTwoPartSecond(unsigned Imm) {
|
2009-10-22 04:44:34 +08:00
|
|
|
// Mask out the first hunk
|
|
|
|
Imm ^= getT2SOImmTwoPartFirst(Imm);
|
|
|
|
// Return what's left
|
|
|
|
assert (getT2SOImmVal(Imm) != -1 &&
|
|
|
|
"Unable to encode second part of T2 two part SO immediate");
|
|
|
|
return Imm;
|
|
|
|
}
|
|
|
|
|
2009-06-24 01:48:47 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Addressing Mode #2
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is used for most simple load/store instructions.
|
|
|
|
//
|
|
|
|
// addrmode2 := reg +/- reg shop imm
|
|
|
|
// addrmode2 := reg +/- imm12
|
|
|
|
//
|
|
|
|
// The first operand is always a Reg. The second operand is a reg if in
|
|
|
|
// reg/reg form, otherwise it's reg#0. The third field encodes the operation
|
2011-04-01 07:26:08 +08:00
|
|
|
// in bit 12, the immediate in bits 0-11, and the shift op in 13-15. The
|
2011-04-05 01:18:19 +08:00
|
|
|
// fourth operand 16-17 encodes the index mode.
|
2007-01-19 15:51:42 +08:00
|
|
|
//
|
|
|
|
// If this addressing mode is a frame index (before prolog/epilog insertion
|
|
|
|
// and code rewriting), this operand will have the form: FI#, reg0, <offs>
|
|
|
|
// with no shift amount for the frame offset.
|
2009-08-11 23:33:49 +08:00
|
|
|
//
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getAM2Opc(AddrOpc Opc, unsigned Imm12, ShiftOpc SO,
|
|
|
|
unsigned IdxMode = 0) {
|
2007-01-19 15:51:42 +08:00
|
|
|
assert(Imm12 < (1 << 12) && "Imm too large!");
|
|
|
|
bool isSub = Opc == sub;
|
2011-04-01 07:26:08 +08:00
|
|
|
return Imm12 | ((int)isSub << 12) | (SO << 13) | (IdxMode << 16) ;
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getAM2Offset(unsigned AM2Opc) {
|
2007-01-19 15:51:42 +08:00
|
|
|
return AM2Opc & ((1 << 12)-1);
|
|
|
|
}
|
2017-10-25 05:29:21 +08:00
|
|
|
inline AddrOpc getAM2Op(unsigned AM2Opc) {
|
2007-01-19 15:51:42 +08:00
|
|
|
return ((AM2Opc >> 12) & 1) ? sub : add;
|
|
|
|
}
|
2017-10-25 05:29:21 +08:00
|
|
|
inline ShiftOpc getAM2ShiftOpc(unsigned AM2Opc) {
|
2011-04-01 07:26:08 +08:00
|
|
|
return (ShiftOpc)((AM2Opc >> 13) & 7);
|
|
|
|
}
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getAM2IdxMode(unsigned AM2Opc) { return (AM2Opc >> 16); }
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Addressing Mode #3
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is used for sign-extending loads, and load/store-pair instructions.
|
|
|
|
//
|
|
|
|
// addrmode3 := reg +/- reg
|
|
|
|
// addrmode3 := reg +/- imm8
|
|
|
|
//
|
|
|
|
// The first operand is always a Reg. The second operand is a reg if in
|
|
|
|
// reg/reg form, otherwise it's reg#0. The third field encodes the operation
|
2011-04-05 01:18:19 +08:00
|
|
|
// in bit 8, the immediate in bits 0-7. The fourth operand 9-10 encodes the
|
|
|
|
// index mode.
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// getAM3Opc - This function encodes the addrmode3 opc field.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getAM3Opc(AddrOpc Opc, unsigned char Offset,
|
|
|
|
unsigned IdxMode = 0) {
|
2007-01-19 15:51:42 +08:00
|
|
|
bool isSub = Opc == sub;
|
2011-04-05 01:18:19 +08:00
|
|
|
return ((int)isSub << 8) | Offset | (IdxMode << 9);
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned char getAM3Offset(unsigned AM3Opc) { return AM3Opc & 0xFF; }
|
|
|
|
inline AddrOpc getAM3Op(unsigned AM3Opc) {
|
2007-01-19 15:51:42 +08:00
|
|
|
return ((AM3Opc >> 8) & 1) ? sub : add;
|
|
|
|
}
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getAM3IdxMode(unsigned AM3Opc) { return (AM3Opc >> 9); }
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Addressing Mode #4
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is used for load / store multiple instructions.
|
|
|
|
//
|
|
|
|
// addrmode4 := reg, <mode>
|
|
|
|
//
|
|
|
|
// The four modes are:
|
|
|
|
// IA - Increment after
|
|
|
|
// IB - Increment before
|
|
|
|
// DA - Decrement after
|
|
|
|
// DB - Decrement before
|
2010-08-28 07:18:17 +08:00
|
|
|
// For VFP instructions, only the IA and DB modes are valid.
|
2007-01-19 15:51:42 +08:00
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline AMSubMode getAM4SubMode(unsigned Mode) {
|
2007-01-19 15:51:42 +08:00
|
|
|
return (AMSubMode)(Mode & 0x7);
|
|
|
|
}
|
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getAM4ModeImm(AMSubMode SubMode) { return (int)SubMode; }
|
2007-01-19 15:51:42 +08:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Addressing Mode #5
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is used for coprocessor instructions, such as FP load/stores.
|
|
|
|
//
|
|
|
|
// addrmode5 := reg +/- imm8*4
|
|
|
|
//
|
2009-07-02 05:22:45 +08:00
|
|
|
// The first operand is always a Reg. The second operand encodes the
|
2016-01-25 18:26:26 +08:00
|
|
|
// operation (add or subtract) in bit 8 and the immediate in bits 0-7.
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// getAM5Opc - This function encodes the addrmode5 opc field.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getAM5Opc(AddrOpc Opc, unsigned char Offset) {
|
2007-01-19 15:51:42 +08:00
|
|
|
bool isSub = Opc == sub;
|
|
|
|
return ((int)isSub << 8) | Offset;
|
|
|
|
}
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned char getAM5Offset(unsigned AM5Opc) { return AM5Opc & 0xFF; }
|
|
|
|
inline AddrOpc getAM5Op(unsigned AM5Opc) {
|
2007-01-19 15:51:42 +08:00
|
|
|
return ((AM5Opc >> 8) & 1) ? sub : add;
|
|
|
|
}
|
|
|
|
|
2016-01-25 18:26:26 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Addressing Mode #5 FP16
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is used for coprocessor instructions, such as 16-bit FP load/stores.
|
|
|
|
//
|
|
|
|
// addrmode5fp16 := reg +/- imm8*2
|
|
|
|
//
|
|
|
|
// The first operand is always a Reg. The second operand encodes the
|
|
|
|
// operation (add or subtract) in bit 8 and the immediate in bits 0-7.
|
|
|
|
|
|
|
|
/// getAM5FP16Opc - This function encodes the addrmode5fp16 opc field.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned getAM5FP16Opc(AddrOpc Opc, unsigned char Offset) {
|
2016-01-25 18:26:26 +08:00
|
|
|
bool isSub = Opc == sub;
|
|
|
|
return ((int)isSub << 8) | Offset;
|
|
|
|
}
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned char getAM5FP16Offset(unsigned AM5Opc) {
|
2016-01-25 18:26:26 +08:00
|
|
|
return AM5Opc & 0xFF;
|
|
|
|
}
|
2017-10-25 05:29:21 +08:00
|
|
|
inline AddrOpc getAM5FP16Op(unsigned AM5Opc) {
|
2016-01-25 18:26:26 +08:00
|
|
|
return ((AM5Opc >> 8) & 1) ? sub : add;
|
|
|
|
}
|
|
|
|
|
2009-07-02 07:16:05 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Addressing Mode #6
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is used for NEON load / store instructions.
|
|
|
|
//
|
2010-03-21 06:13:40 +08:00
|
|
|
// addrmode6 := reg with optional alignment
|
2009-07-02 07:16:05 +08:00
|
|
|
//
|
2010-03-21 06:13:40 +08:00
|
|
|
// This is stored in two operands [regaddr, align]. The first is the
|
|
|
|
// address register. The second operand is the value of the alignment
|
2010-07-15 07:54:43 +08:00
|
|
|
// specifier in bytes or zero if no explicit alignment.
|
|
|
|
// Valid alignments depend on the specific instruction.
|
2009-07-02 07:16:05 +08:00
|
|
|
|
2010-07-13 12:44:34 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2019-07-23 17:19:24 +08:00
|
|
|
// NEON/MVE Modified Immediates
|
2010-07-13 12:44:34 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
//
|
2019-07-23 17:19:24 +08:00
|
|
|
// Several NEON and MVE instructions (e.g., VMOV) take a "modified immediate"
|
2010-07-13 12:44:34 +08:00
|
|
|
// vector operand, where a small immediate encoded in the instruction
|
|
|
|
// specifies a full NEON vector value. These modified immediates are
|
|
|
|
// represented here as encoded integers. The low 8 bits hold the immediate
|
|
|
|
// value; bit 12 holds the "Op" field of the instruction, and bits 11-8 hold
|
|
|
|
// the "Cmode" field of the instruction. The interfaces below treat the
|
|
|
|
// Op and Cmode values as a single 5-bit value.
|
|
|
|
|
2019-07-23 17:19:24 +08:00
|
|
|
inline unsigned createVMOVModImm(unsigned OpCmode, unsigned Val) {
|
2010-07-13 12:44:34 +08:00
|
|
|
return (OpCmode << 8) | Val;
|
|
|
|
}
|
2019-07-23 17:19:24 +08:00
|
|
|
inline unsigned getVMOVModImmOpCmode(unsigned ModImm) {
|
2010-07-13 12:44:34 +08:00
|
|
|
return (ModImm >> 8) & 0x1f;
|
|
|
|
}
|
2019-07-23 17:19:24 +08:00
|
|
|
inline unsigned getVMOVModImmVal(unsigned ModImm) { return ModImm & 0xff; }
|
2010-07-13 12:44:34 +08:00
|
|
|
|
2019-07-23 17:19:24 +08:00
|
|
|
/// decodeVMOVModImm - Decode a NEON/MVE modified immediate value into the
|
2010-07-13 12:44:34 +08:00
|
|
|
/// element value and the element size in bits. (If the element size is
|
|
|
|
/// smaller than the vector, it is splatted into all the elements.)
|
2019-07-23 17:19:24 +08:00
|
|
|
inline uint64_t decodeVMOVModImm(unsigned ModImm, unsigned &EltBits) {
|
|
|
|
unsigned OpCmode = getVMOVModImmOpCmode(ModImm);
|
|
|
|
unsigned Imm8 = getVMOVModImmVal(ModImm);
|
2010-07-13 12:44:34 +08:00
|
|
|
uint64_t Val = 0;
|
|
|
|
|
|
|
|
if (OpCmode == 0xe) {
|
|
|
|
// 8-bit vector elements
|
|
|
|
Val = Imm8;
|
|
|
|
EltBits = 8;
|
|
|
|
} else if ((OpCmode & 0xc) == 0x8) {
|
|
|
|
// 16-bit vector elements
|
|
|
|
unsigned ByteNum = (OpCmode & 0x6) >> 1;
|
|
|
|
Val = Imm8 << (8 * ByteNum);
|
|
|
|
EltBits = 16;
|
|
|
|
} else if ((OpCmode & 0x8) == 0) {
|
|
|
|
// 32-bit vector elements, zero with one byte set
|
|
|
|
unsigned ByteNum = (OpCmode & 0x6) >> 1;
|
|
|
|
Val = Imm8 << (8 * ByteNum);
|
|
|
|
EltBits = 32;
|
|
|
|
} else if ((OpCmode & 0xe) == 0xc) {
|
|
|
|
// 32-bit vector elements, one byte with low bits set
|
|
|
|
unsigned ByteNum = 1 + (OpCmode & 0x1);
|
|
|
|
Val = (Imm8 << (8 * ByteNum)) | (0xffff >> (8 * (2 - ByteNum)));
|
|
|
|
EltBits = 32;
|
|
|
|
} else if (OpCmode == 0x1e) {
|
|
|
|
// 64-bit vector elements
|
|
|
|
for (unsigned ByteNum = 0; ByteNum < 8; ++ByteNum) {
|
|
|
|
if ((ModImm >> ByteNum) & 1)
|
|
|
|
Val |= (uint64_t)0xff << (8 * ByteNum);
|
|
|
|
}
|
|
|
|
EltBits = 64;
|
|
|
|
} else {
|
2019-07-23 17:19:24 +08:00
|
|
|
llvm_unreachable("Unsupported VMOV immediate");
|
2010-07-13 12:44:34 +08:00
|
|
|
}
|
|
|
|
return Val;
|
|
|
|
}
|
|
|
|
|
2014-09-25 19:31:24 +08:00
|
|
|
// Generic validation for single-byte immediate (0X00, 00X0, etc).
|
2017-10-25 05:29:21 +08:00
|
|
|
inline bool isNEONBytesplat(unsigned Value, unsigned Size) {
|
2014-09-25 19:31:24 +08:00
|
|
|
assert(Size >= 1 && Size <= 4 && "Invalid size");
|
|
|
|
unsigned count = 0;
|
|
|
|
for (unsigned i = 0; i < Size; ++i) {
|
|
|
|
if (Value & 0xff) count++;
|
|
|
|
Value >>= 8;
|
|
|
|
}
|
|
|
|
return count == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Checks if Value is a correct immediate for instructions like VBIC/VORR.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline bool isNEONi16splat(unsigned Value) {
|
2014-09-25 19:31:24 +08:00
|
|
|
if (Value > 0xffff)
|
|
|
|
return false;
|
|
|
|
// i16 value with set bits only in one byte X0 or 0X.
|
|
|
|
return Value == 0 || isNEONBytesplat(Value, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode NEON 16 bits Splat immediate for instructions like VBIC/VORR
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned encodeNEONi16splat(unsigned Value) {
|
2014-09-25 19:31:24 +08:00
|
|
|
assert(isNEONi16splat(Value) && "Invalid NEON splat value");
|
|
|
|
if (Value >= 0x100)
|
|
|
|
Value = (Value >> 8) | 0xa00;
|
|
|
|
else
|
|
|
|
Value |= 0x800;
|
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Checks if Value is a correct immediate for instructions like VBIC/VORR.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline bool isNEONi32splat(unsigned Value) {
|
2014-09-25 19:31:24 +08:00
|
|
|
// i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
|
|
|
|
return Value == 0 || isNEONBytesplat(Value, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Encode NEON 32 bits Splat immediate for instructions like VBIC/VORR.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline unsigned encodeNEONi32splat(unsigned Value) {
|
2014-09-25 19:31:24 +08:00
|
|
|
assert(isNEONi32splat(Value) && "Invalid NEON splat value");
|
|
|
|
if (Value >= 0x100 && Value <= 0xff00)
|
|
|
|
Value = (Value >> 8) | 0x200;
|
|
|
|
else if (Value > 0xffff && Value <= 0xff0000)
|
|
|
|
Value = (Value >> 16) | 0x400;
|
|
|
|
else if (Value > 0xffffff)
|
|
|
|
Value = (Value >> 24) | 0x600;
|
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
|
2011-09-30 08:50:06 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Floating-point Immediates
|
|
|
|
//
|
2017-10-25 05:29:21 +08:00
|
|
|
inline float getFPImmFloat(unsigned Imm) {
|
2011-09-30 08:50:06 +08:00
|
|
|
// We expect an 8-bit binary encoding of a floating-point number here.
|
|
|
|
|
|
|
|
uint8_t Sign = (Imm >> 7) & 0x1;
|
|
|
|
uint8_t Exp = (Imm >> 4) & 0x7;
|
|
|
|
uint8_t Mantissa = Imm & 0xf;
|
|
|
|
|
2018-09-08 11:55:25 +08:00
|
|
|
// 8-bit FP IEEE Float Encoding
|
2011-09-30 08:50:06 +08:00
|
|
|
// abcd efgh aBbbbbbc defgh000 00000000 00000000
|
|
|
|
//
|
|
|
|
// where B = NOT(b);
|
2018-09-08 11:55:25 +08:00
|
|
|
uint32_t I = 0;
|
|
|
|
I |= Sign << 31;
|
|
|
|
I |= ((Exp & 0x4) != 0 ? 0 : 1) << 30;
|
|
|
|
I |= ((Exp & 0x4) != 0 ? 0x1f : 0) << 25;
|
|
|
|
I |= (Exp & 0x3) << 23;
|
|
|
|
I |= Mantissa << 19;
|
2018-09-08 12:07:41 +08:00
|
|
|
return bit_cast<float>(I);
|
2011-09-30 08:50:06 +08:00
|
|
|
}
|
|
|
|
|
2016-01-25 18:26:26 +08:00
|
|
|
/// getFP16Imm - Return an 8-bit floating-point version of the 16-bit
|
|
|
|
/// floating-point value. If the value cannot be represented as an 8-bit
|
|
|
|
/// floating-point value, then return -1.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline int getFP16Imm(const APInt &Imm) {
|
2016-01-25 18:26:26 +08:00
|
|
|
uint32_t Sign = Imm.lshr(15).getZExtValue() & 1;
|
|
|
|
int32_t Exp = (Imm.lshr(10).getSExtValue() & 0x1f) - 15; // -14 to 15
|
|
|
|
int64_t Mantissa = Imm.getZExtValue() & 0x3ff; // 10 bits
|
|
|
|
|
|
|
|
// We can handle 4 bits of mantissa.
|
|
|
|
// mantissa = (16+UInt(e:f:g:h))/16.
|
|
|
|
if (Mantissa & 0x3f)
|
|
|
|
return -1;
|
|
|
|
Mantissa >>= 6;
|
|
|
|
|
|
|
|
// We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3
|
|
|
|
if (Exp < -3 || Exp > 4)
|
|
|
|
return -1;
|
|
|
|
Exp = ((Exp+3) & 0x7) ^ 4;
|
|
|
|
|
|
|
|
return ((int)Sign << 7) | (Exp << 4) | Mantissa;
|
|
|
|
}
|
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline int getFP16Imm(const APFloat &FPImm) {
|
2016-01-25 18:26:26 +08:00
|
|
|
return getFP16Imm(FPImm.bitcastToAPInt());
|
|
|
|
}
|
|
|
|
|
2011-09-30 08:50:06 +08:00
|
|
|
/// getFP32Imm - Return an 8-bit floating-point version of the 32-bit
|
|
|
|
/// floating-point value. If the value cannot be represented as an 8-bit
|
|
|
|
/// floating-point value, then return -1.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline int getFP32Imm(const APInt &Imm) {
|
2011-09-30 08:50:06 +08:00
|
|
|
uint32_t Sign = Imm.lshr(31).getZExtValue() & 1;
|
|
|
|
int32_t Exp = (Imm.lshr(23).getSExtValue() & 0xff) - 127; // -126 to 127
|
|
|
|
int64_t Mantissa = Imm.getZExtValue() & 0x7fffff; // 23 bits
|
|
|
|
|
|
|
|
// We can handle 4 bits of mantissa.
|
|
|
|
// mantissa = (16+UInt(e:f:g:h))/16.
|
|
|
|
if (Mantissa & 0x7ffff)
|
|
|
|
return -1;
|
|
|
|
Mantissa >>= 19;
|
|
|
|
if ((Mantissa & 0xf) != Mantissa)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3
|
|
|
|
if (Exp < -3 || Exp > 4)
|
|
|
|
return -1;
|
|
|
|
Exp = ((Exp+3) & 0x7) ^ 4;
|
|
|
|
|
|
|
|
return ((int)Sign << 7) | (Exp << 4) | Mantissa;
|
|
|
|
}
|
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline int getFP32Imm(const APFloat &FPImm) {
|
2011-09-30 08:50:06 +08:00
|
|
|
return getFP32Imm(FPImm.bitcastToAPInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getFP64Imm - Return an 8-bit floating-point version of the 64-bit
|
|
|
|
/// floating-point value. If the value cannot be represented as an 8-bit
|
|
|
|
/// floating-point value, then return -1.
|
2017-10-25 05:29:21 +08:00
|
|
|
inline int getFP64Imm(const APInt &Imm) {
|
2011-09-30 08:50:06 +08:00
|
|
|
uint64_t Sign = Imm.lshr(63).getZExtValue() & 1;
|
2011-10-04 07:03:26 +08:00
|
|
|
int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023; // -1022 to 1023
|
2011-09-30 08:50:06 +08:00
|
|
|
uint64_t Mantissa = Imm.getZExtValue() & 0xfffffffffffffULL;
|
|
|
|
|
|
|
|
// We can handle 4 bits of mantissa.
|
|
|
|
// mantissa = (16+UInt(e:f:g:h))/16.
|
|
|
|
if (Mantissa & 0xffffffffffffULL)
|
|
|
|
return -1;
|
|
|
|
Mantissa >>= 48;
|
|
|
|
if ((Mantissa & 0xf) != Mantissa)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3
|
|
|
|
if (Exp < -3 || Exp > 4)
|
|
|
|
return -1;
|
|
|
|
Exp = ((Exp+3) & 0x7) ^ 4;
|
|
|
|
|
|
|
|
return ((int)Sign << 7) | (Exp << 4) | Mantissa;
|
|
|
|
}
|
|
|
|
|
2017-10-25 05:29:21 +08:00
|
|
|
inline int getFP64Imm(const APFloat &FPImm) {
|
2011-09-30 08:50:06 +08:00
|
|
|
return getFP64Imm(FPImm.bitcastToAPInt());
|
|
|
|
}
|
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
} // end namespace ARM_AM
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|