2014-05-24 20:50:23 +08:00
|
|
|
//===- AArch64AddressingModes.h - AArch64 Addressing Modes ------*- C++ -*-===//
|
2014-03-29 18:18:08 +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
|
2014-03-29 18:18:08 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2014-05-24 20:50:23 +08:00
|
|
|
// This file contains the AArch64 addressing mode implementation stuff.
|
2014-03-29 18:18:08 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64ADDRESSINGMODES_H
|
|
|
|
#define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64ADDRESSINGMODES_H
|
2014-03-29 18:18:08 +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"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
/// AArch64_AM - AArch64 Addressing Mode Stuff
|
|
|
|
namespace AArch64_AM {
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Shifts
|
|
|
|
//
|
|
|
|
|
2014-05-12 22:13:17 +08:00
|
|
|
enum ShiftExtendType {
|
|
|
|
InvalidShiftExtend = -1,
|
2014-03-29 18:18:08 +08:00
|
|
|
LSL = 0,
|
2014-05-12 22:13:17 +08:00
|
|
|
LSR,
|
|
|
|
ASR,
|
|
|
|
ROR,
|
|
|
|
MSL,
|
|
|
|
|
|
|
|
UXTB,
|
|
|
|
UXTH,
|
|
|
|
UXTW,
|
|
|
|
UXTX,
|
|
|
|
|
|
|
|
SXTB,
|
|
|
|
SXTH,
|
|
|
|
SXTW,
|
|
|
|
SXTX,
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// getShiftName - Get the string encoding for the shift type.
|
2014-05-24 20:50:23 +08:00
|
|
|
static inline const char *getShiftExtendName(AArch64_AM::ShiftExtendType ST) {
|
2014-03-29 18:18:08 +08:00
|
|
|
switch (ST) {
|
2015-01-05 18:15:49 +08:00
|
|
|
default: llvm_unreachable("unhandled shift type!");
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64_AM::LSL: return "lsl";
|
|
|
|
case AArch64_AM::LSR: return "lsr";
|
|
|
|
case AArch64_AM::ASR: return "asr";
|
|
|
|
case AArch64_AM::ROR: return "ror";
|
|
|
|
case AArch64_AM::MSL: return "msl";
|
|
|
|
case AArch64_AM::UXTB: return "uxtb";
|
|
|
|
case AArch64_AM::UXTH: return "uxth";
|
|
|
|
case AArch64_AM::UXTW: return "uxtw";
|
|
|
|
case AArch64_AM::UXTX: return "uxtx";
|
|
|
|
case AArch64_AM::SXTB: return "sxtb";
|
|
|
|
case AArch64_AM::SXTH: return "sxth";
|
|
|
|
case AArch64_AM::SXTW: return "sxtw";
|
|
|
|
case AArch64_AM::SXTX: return "sxtx";
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
2014-04-28 12:05:08 +08:00
|
|
|
return nullptr;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getShiftType - Extract the shift type.
|
2014-05-24 20:50:23 +08:00
|
|
|
static inline AArch64_AM::ShiftExtendType getShiftType(unsigned Imm) {
|
2014-05-12 22:13:17 +08:00
|
|
|
switch ((Imm >> 6) & 0x7) {
|
2014-05-24 20:50:23 +08:00
|
|
|
default: return AArch64_AM::InvalidShiftExtend;
|
|
|
|
case 0: return AArch64_AM::LSL;
|
|
|
|
case 1: return AArch64_AM::LSR;
|
|
|
|
case 2: return AArch64_AM::ASR;
|
|
|
|
case 3: return AArch64_AM::ROR;
|
|
|
|
case 4: return AArch64_AM::MSL;
|
2014-05-12 22:13:17 +08:00
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getShiftValue - Extract the shift value.
|
|
|
|
static inline unsigned getShiftValue(unsigned Imm) {
|
|
|
|
return Imm & 0x3f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getShifterImm - Encode the shift type and amount:
|
|
|
|
/// imm: 6-bit shift amount
|
|
|
|
/// shifter: 000 ==> lsl
|
|
|
|
/// 001 ==> lsr
|
|
|
|
/// 010 ==> asr
|
|
|
|
/// 011 ==> ror
|
|
|
|
/// 100 ==> msl
|
|
|
|
/// {8-6} = shifter
|
|
|
|
/// {5-0} = imm
|
2014-05-24 20:50:23 +08:00
|
|
|
static inline unsigned getShifterImm(AArch64_AM::ShiftExtendType ST,
|
2014-05-12 22:13:17 +08:00
|
|
|
unsigned Imm) {
|
2014-03-29 18:18:08 +08:00
|
|
|
assert((Imm & 0x3f) == Imm && "Illegal shifted immedate value!");
|
2014-05-12 22:13:17 +08:00
|
|
|
unsigned STEnc = 0;
|
|
|
|
switch (ST) {
|
|
|
|
default: llvm_unreachable("Invalid shift requested");
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64_AM::LSL: STEnc = 0; break;
|
|
|
|
case AArch64_AM::LSR: STEnc = 1; break;
|
|
|
|
case AArch64_AM::ASR: STEnc = 2; break;
|
|
|
|
case AArch64_AM::ROR: STEnc = 3; break;
|
|
|
|
case AArch64_AM::MSL: STEnc = 4; break;
|
2014-05-12 22:13:17 +08:00
|
|
|
}
|
|
|
|
return (STEnc << 6) | (Imm & 0x3f);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Extends
|
|
|
|
//
|
|
|
|
|
|
|
|
/// getArithShiftValue - get the arithmetic shift value.
|
|
|
|
static inline unsigned getArithShiftValue(unsigned Imm) {
|
|
|
|
return Imm & 0x7;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getExtendType - Extract the extend type for operands of arithmetic ops.
|
2014-05-24 20:50:23 +08:00
|
|
|
static inline AArch64_AM::ShiftExtendType getExtendType(unsigned Imm) {
|
2014-05-12 22:13:17 +08:00
|
|
|
assert((Imm & 0x7) == Imm && "invalid immediate!");
|
|
|
|
switch (Imm) {
|
|
|
|
default: llvm_unreachable("Compiler bug!");
|
2014-05-24 20:50:23 +08:00
|
|
|
case 0: return AArch64_AM::UXTB;
|
|
|
|
case 1: return AArch64_AM::UXTH;
|
|
|
|
case 2: return AArch64_AM::UXTW;
|
|
|
|
case 3: return AArch64_AM::UXTX;
|
|
|
|
case 4: return AArch64_AM::SXTB;
|
|
|
|
case 5: return AArch64_AM::SXTH;
|
|
|
|
case 6: return AArch64_AM::SXTW;
|
|
|
|
case 7: return AArch64_AM::SXTX;
|
2014-05-12 22:13:17 +08:00
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
static inline AArch64_AM::ShiftExtendType getArithExtendType(unsigned Imm) {
|
2014-05-12 22:13:17 +08:00
|
|
|
return getExtendType((Imm >> 3) & 0x7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Mapping from extend bits to required operation:
|
2014-03-29 18:18:08 +08:00
|
|
|
/// shifter: 000 ==> uxtb
|
|
|
|
/// 001 ==> uxth
|
|
|
|
/// 010 ==> uxtw
|
|
|
|
/// 011 ==> uxtx
|
|
|
|
/// 100 ==> sxtb
|
|
|
|
/// 101 ==> sxth
|
|
|
|
/// 110 ==> sxtw
|
|
|
|
/// 111 ==> sxtx
|
2014-05-24 20:50:23 +08:00
|
|
|
inline unsigned getExtendEncoding(AArch64_AM::ShiftExtendType ET) {
|
2014-05-12 22:13:17 +08:00
|
|
|
switch (ET) {
|
|
|
|
default: llvm_unreachable("Invalid extend type requested");
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64_AM::UXTB: return 0; break;
|
|
|
|
case AArch64_AM::UXTH: return 1; break;
|
|
|
|
case AArch64_AM::UXTW: return 2; break;
|
|
|
|
case AArch64_AM::UXTX: return 3; break;
|
|
|
|
case AArch64_AM::SXTB: return 4; break;
|
|
|
|
case AArch64_AM::SXTH: return 5; break;
|
|
|
|
case AArch64_AM::SXTW: return 6; break;
|
|
|
|
case AArch64_AM::SXTX: return 7; break;
|
2014-05-12 22:13:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getArithExtendImm - Encode the extend type and shift amount for an
|
|
|
|
/// arithmetic instruction:
|
|
|
|
/// imm: 3-bit extend amount
|
2014-03-29 18:18:08 +08:00
|
|
|
/// {5-3} = shifter
|
|
|
|
/// {2-0} = imm3
|
2014-05-24 20:50:23 +08:00
|
|
|
static inline unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET,
|
2014-03-29 18:18:08 +08:00
|
|
|
unsigned Imm) {
|
|
|
|
assert((Imm & 0x7) == Imm && "Illegal shifted immedate value!");
|
2014-05-12 22:13:17 +08:00
|
|
|
return (getExtendEncoding(ET) << 3) | (Imm & 0x7);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getMemDoShift - Extract the "do shift" flag value for load/store
|
|
|
|
/// instructions.
|
|
|
|
static inline bool getMemDoShift(unsigned Imm) {
|
|
|
|
return (Imm & 0x1) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getExtendType - Extract the extend type for the offset operand of
|
|
|
|
/// loads/stores.
|
2014-05-24 20:50:23 +08:00
|
|
|
static inline AArch64_AM::ShiftExtendType getMemExtendType(unsigned Imm) {
|
2014-05-12 22:13:17 +08:00
|
|
|
return getExtendType((Imm >> 1) & 0x7);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getExtendImm - Encode the extend type and amount for a load/store inst:
|
2014-03-30 16:30:28 +08:00
|
|
|
/// doshift: should the offset be scaled by the access size
|
2014-03-29 18:18:08 +08:00
|
|
|
/// shifter: 000 ==> uxtb
|
|
|
|
/// 001 ==> uxth
|
|
|
|
/// 010 ==> uxtw
|
|
|
|
/// 011 ==> uxtx
|
|
|
|
/// 100 ==> sxtb
|
|
|
|
/// 101 ==> sxth
|
|
|
|
/// 110 ==> sxtw
|
|
|
|
/// 111 ==> sxtx
|
|
|
|
/// {3-1} = shifter
|
2014-03-30 16:30:28 +08:00
|
|
|
/// {0} = doshift
|
2014-05-24 20:50:23 +08:00
|
|
|
static inline unsigned getMemExtendImm(AArch64_AM::ShiftExtendType ET,
|
2014-05-12 22:13:17 +08:00
|
|
|
bool DoShift) {
|
|
|
|
return (getExtendEncoding(ET) << 1) | unsigned(DoShift);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t ror(uint64_t elt, unsigned size) {
|
|
|
|
return ((elt & 1) << (size-1)) | (elt >> 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// processLogicalImmediate - Determine if an immediate value can be encoded
|
|
|
|
/// as the immediate operand of a logical instruction for the given register
|
|
|
|
/// size. If so, return true with "encoding" set to the encoded value in
|
|
|
|
/// the form N:immr:imms.
|
2014-11-04 07:24:10 +08:00
|
|
|
static inline bool processLogicalImmediate(uint64_t Imm, unsigned RegSize,
|
|
|
|
uint64_t &Encoding) {
|
|
|
|
if (Imm == 0ULL || Imm == ~0ULL ||
|
[AArch64][AsmParser] NFC: Generalize LogicalImm[Not](32|64) code
Summary:
All variants of isLogicalImm[Not](32|64) can be combined into a single templated function, same for printLogicalImm(32|64).
By making it use a template instead, further SVE patches can use it for other data types as well (e.g. 8, 16 bits).
Reviewers: fhahn, rengolin, aadg, echristo, kristof.beyls, samparker
Reviewed By: samparker
Subscribers: aemerson, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D42294
llvm-svn: 323646
2018-01-29 21:05:38 +08:00
|
|
|
(RegSize != 64 &&
|
|
|
|
(Imm >> RegSize != 0 || Imm == (~0ULL >> (64 - RegSize)))))
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// First, determine the element size.
|
2014-11-04 07:24:10 +08:00
|
|
|
unsigned Size = RegSize;
|
2014-11-04 07:06:31 +08:00
|
|
|
|
|
|
|
do {
|
2014-11-04 07:24:10 +08:00
|
|
|
Size /= 2;
|
|
|
|
uint64_t Mask = (1ULL << Size) - 1;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-11-04 07:24:10 +08:00
|
|
|
if ((Imm & Mask) != ((Imm >> Size) & Mask)) {
|
|
|
|
Size *= 2;
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-11-04 07:24:10 +08:00
|
|
|
} while (Size > 2);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// Second, determine the rotation to make the element be: 0^m 1^n.
|
2014-11-04 07:24:10 +08:00
|
|
|
uint32_t CTO, I;
|
|
|
|
uint64_t Mask = ((uint64_t)-1LL) >> (64 - Size);
|
|
|
|
Imm &= Mask;
|
2014-11-04 07:06:31 +08:00
|
|
|
|
2014-11-04 07:24:10 +08:00
|
|
|
if (isShiftedMask_64(Imm)) {
|
|
|
|
I = countTrailingZeros(Imm);
|
2014-12-16 02:48:43 +08:00
|
|
|
assert(I < 64 && "undefined behavior");
|
2015-02-12 23:35:40 +08:00
|
|
|
CTO = countTrailingOnes(Imm >> I);
|
2014-11-04 07:06:31 +08:00
|
|
|
} else {
|
2014-11-04 07:24:10 +08:00
|
|
|
Imm |= ~Mask;
|
|
|
|
if (!isShiftedMask_64(~Imm))
|
2014-11-04 07:06:31 +08:00
|
|
|
return false;
|
|
|
|
|
2015-02-12 23:35:40 +08:00
|
|
|
unsigned CLO = countLeadingOnes(Imm);
|
2014-11-04 07:24:10 +08:00
|
|
|
I = 64 - CLO;
|
2015-02-12 23:35:40 +08:00
|
|
|
CTO = CLO + countTrailingOnes(Imm) - (64 - Size);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-11-04 07:24:10 +08:00
|
|
|
// Encode in Immr the number of RORs it would take to get *from* 0^m 1^n
|
2014-12-01 14:14:52 +08:00
|
|
|
// to our target value, where I is the number of RORs to go the opposite
|
2014-11-04 07:06:31 +08:00
|
|
|
// direction.
|
2014-12-01 14:14:52 +08:00
|
|
|
assert(Size > I && "I should be smaller than element size");
|
2014-11-04 07:24:10 +08:00
|
|
|
unsigned Immr = (Size - I) & (Size - 1);
|
2014-11-04 07:06:31 +08:00
|
|
|
|
|
|
|
// If size has a 1 in the n'th bit, create a value that has zeroes in
|
|
|
|
// bits [0, n] and ones above that.
|
2014-11-04 07:24:10 +08:00
|
|
|
uint64_t NImms = ~(Size-1) << 1;
|
2014-11-04 07:06:31 +08:00
|
|
|
|
|
|
|
// Or the CTO value into the low bits, which must be below the Nth bit
|
|
|
|
// bit mentioned above.
|
2014-11-04 07:24:10 +08:00
|
|
|
NImms |= (CTO-1);
|
2014-11-04 07:06:31 +08:00
|
|
|
|
|
|
|
// Extract the seventh bit and toggle it to create the N field.
|
2014-11-04 07:24:10 +08:00
|
|
|
unsigned N = ((NImms >> 6) & 1) ^ 1;
|
2014-11-04 07:06:31 +08:00
|
|
|
|
2014-11-04 07:24:10 +08:00
|
|
|
Encoding = (N << 12) | (Immr << 6) | (NImms & 0x3f);
|
2014-11-04 07:06:31 +08:00
|
|
|
return true;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// isLogicalImmediate - Return true if the immediate is valid for a logical
|
|
|
|
/// immediate instruction of the given register size. Return false otherwise.
|
|
|
|
static inline bool isLogicalImmediate(uint64_t imm, unsigned regSize) {
|
|
|
|
uint64_t encoding;
|
|
|
|
return processLogicalImmediate(imm, regSize, encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// encodeLogicalImmediate - Return the encoded immediate value for a logical
|
|
|
|
/// immediate instruction of the given register size.
|
|
|
|
static inline uint64_t encodeLogicalImmediate(uint64_t imm, unsigned regSize) {
|
|
|
|
uint64_t encoding = 0;
|
|
|
|
bool res = processLogicalImmediate(imm, regSize, encoding);
|
|
|
|
assert(res && "invalid logical immediate");
|
|
|
|
(void)res;
|
|
|
|
return encoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// decodeLogicalImmediate - Decode a logical immediate value in the form
|
|
|
|
/// "N:immr:imms" (where the immr and imms fields are each 6 bits) into the
|
|
|
|
/// integer value it represents with regSize bits.
|
|
|
|
static inline uint64_t decodeLogicalImmediate(uint64_t val, unsigned regSize) {
|
|
|
|
// Extract the N, imms, and immr fields.
|
|
|
|
unsigned N = (val >> 12) & 1;
|
|
|
|
unsigned immr = (val >> 6) & 0x3f;
|
|
|
|
unsigned imms = val & 0x3f;
|
|
|
|
|
|
|
|
assert((regSize == 64 || N == 0) && "undefined logical immediate encoding");
|
|
|
|
int len = 31 - countLeadingZeros((N << 6) | (~imms & 0x3f));
|
|
|
|
assert(len >= 0 && "undefined logical immediate encoding");
|
|
|
|
unsigned size = (1 << len);
|
|
|
|
unsigned R = immr & (size - 1);
|
|
|
|
unsigned S = imms & (size - 1);
|
|
|
|
assert(S != size - 1 && "undefined logical immediate encoding");
|
|
|
|
uint64_t pattern = (1ULL << (S + 1)) - 1;
|
|
|
|
for (unsigned i = 0; i < R; ++i)
|
|
|
|
pattern = ror(pattern, size);
|
|
|
|
|
|
|
|
// Replicate the pattern to fill the regSize.
|
|
|
|
while (size != regSize) {
|
|
|
|
pattern |= (pattern << size);
|
|
|
|
size *= 2;
|
|
|
|
}
|
|
|
|
return pattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isValidDecodeLogicalImmediate - Check to see if the logical immediate value
|
|
|
|
/// in the form "N:immr:imms" (where the immr and imms fields are each 6 bits)
|
|
|
|
/// is a valid encoding for an integer value with regSize bits.
|
|
|
|
static inline bool isValidDecodeLogicalImmediate(uint64_t val,
|
|
|
|
unsigned regSize) {
|
|
|
|
// Extract the N and imms fields needed for checking.
|
|
|
|
unsigned N = (val >> 12) & 1;
|
|
|
|
unsigned imms = val & 0x3f;
|
|
|
|
|
|
|
|
if (regSize == 32 && N != 0) // undefined logical immediate encoding
|
|
|
|
return false;
|
|
|
|
int len = 31 - countLeadingZeros((N << 6) | (~imms & 0x3f));
|
|
|
|
if (len < 0) // undefined logical immediate encoding
|
|
|
|
return false;
|
|
|
|
unsigned size = (1 << len);
|
|
|
|
unsigned S = imms & (size - 1);
|
|
|
|
if (S == size - 1) // undefined logical immediate encoding
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Floating-point Immediates
|
|
|
|
//
|
|
|
|
static inline float getFPImmFloat(unsigned Imm) {
|
|
|
|
// 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
|
2014-03-29 18:18:08 +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;
|
|
|
|
return bit_cast<float>(I);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2015-11-27 21:04:48 +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.
|
|
|
|
static inline int getFP16Imm(const APInt &Imm) {
|
|
|
|
uint32_t Sign = Imm.lshr(15).getZExtValue() & 1;
|
|
|
|
int32_t Exp = (Imm.lshr(10).getSExtValue() & 0x1f) - 15; // -14 to 15
|
|
|
|
int32_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int getFP16Imm(const APFloat &FPImm) {
|
|
|
|
return getFP16Imm(FPImm.bitcastToAPInt());
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +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.
|
|
|
|
static inline int getFP32Imm(const APInt &Imm) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int getFP32Imm(const APFloat &FPImm) {
|
|
|
|
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.
|
|
|
|
static inline int getFP64Imm(const APInt &Imm) {
|
|
|
|
uint64_t Sign = Imm.lshr(63).getZExtValue() & 1;
|
|
|
|
int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023; // -1022 to 1023
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int getFP64Imm(const APFloat &FPImm) {
|
|
|
|
return getFP64Imm(FPImm.bitcastToAPInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// AdvSIMD Modified Immediates
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// 0x00 0x00 0x00 abcdefgh 0x00 0x00 0x00 abcdefgh
|
|
|
|
static inline bool isAdvSIMDModImmType1(uint64_t Imm) {
|
|
|
|
return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
|
|
|
|
((Imm & 0xffffff00ffffff00ULL) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType1(uint64_t Imm) {
|
|
|
|
return (Imm & 0xffULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType1(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = Imm;
|
|
|
|
return (EncVal << 32) | EncVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x00 0x00 abcdefgh 0x00 0x00 0x00 abcdefgh 0x00
|
|
|
|
static inline bool isAdvSIMDModImmType2(uint64_t Imm) {
|
|
|
|
return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
|
|
|
|
((Imm & 0xffff00ffffff00ffULL) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType2(uint64_t Imm) {
|
|
|
|
return (Imm & 0xff00ULL) >> 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType2(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = Imm;
|
|
|
|
return (EncVal << 40) | (EncVal << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x00 abcdefgh 0x00 0x00 0x00 abcdefgh 0x00 0x00
|
|
|
|
static inline bool isAdvSIMDModImmType3(uint64_t Imm) {
|
|
|
|
return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
|
|
|
|
((Imm & 0xff00ffffff00ffffULL) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType3(uint64_t Imm) {
|
|
|
|
return (Imm & 0xff0000ULL) >> 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType3(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = Imm;
|
|
|
|
return (EncVal << 48) | (EncVal << 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
// abcdefgh 0x00 0x00 0x00 abcdefgh 0x00 0x00 0x00
|
|
|
|
static inline bool isAdvSIMDModImmType4(uint64_t Imm) {
|
|
|
|
return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
|
|
|
|
((Imm & 0x00ffffff00ffffffULL) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType4(uint64_t Imm) {
|
|
|
|
return (Imm & 0xff000000ULL) >> 24;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType4(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = Imm;
|
|
|
|
return (EncVal << 56) | (EncVal << 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x00 abcdefgh 0x00 abcdefgh 0x00 abcdefgh 0x00 abcdefgh
|
|
|
|
static inline bool isAdvSIMDModImmType5(uint64_t Imm) {
|
|
|
|
return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
|
|
|
|
(((Imm & 0x00ff0000ULL) >> 16) == (Imm & 0x000000ffULL)) &&
|
|
|
|
((Imm & 0xff00ff00ff00ff00ULL) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType5(uint64_t Imm) {
|
|
|
|
return (Imm & 0xffULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType5(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = Imm;
|
|
|
|
return (EncVal << 48) | (EncVal << 32) | (EncVal << 16) | EncVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// abcdefgh 0x00 abcdefgh 0x00 abcdefgh 0x00 abcdefgh 0x00
|
|
|
|
static inline bool isAdvSIMDModImmType6(uint64_t Imm) {
|
|
|
|
return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
|
|
|
|
(((Imm & 0xff000000ULL) >> 16) == (Imm & 0x0000ff00ULL)) &&
|
|
|
|
((Imm & 0x00ff00ff00ff00ffULL) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType6(uint64_t Imm) {
|
|
|
|
return (Imm & 0xff00ULL) >> 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType6(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = Imm;
|
|
|
|
return (EncVal << 56) | (EncVal << 40) | (EncVal << 24) | (EncVal << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x00 0x00 abcdefgh 0xFF 0x00 0x00 abcdefgh 0xFF
|
|
|
|
static inline bool isAdvSIMDModImmType7(uint64_t Imm) {
|
|
|
|
return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
|
|
|
|
((Imm & 0xffff00ffffff00ffULL) == 0x000000ff000000ffULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType7(uint64_t Imm) {
|
|
|
|
return (Imm & 0xff00ULL) >> 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType7(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = Imm;
|
|
|
|
return (EncVal << 40) | (EncVal << 8) | 0x000000ff000000ffULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x00 abcdefgh 0xFF 0xFF 0x00 abcdefgh 0xFF 0xFF
|
|
|
|
static inline bool isAdvSIMDModImmType8(uint64_t Imm) {
|
|
|
|
return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
|
|
|
|
((Imm & 0xff00ffffff00ffffULL) == 0x0000ffff0000ffffULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType8(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = Imm;
|
|
|
|
return (EncVal << 48) | (EncVal << 16) | 0x0000ffff0000ffffULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType8(uint64_t Imm) {
|
|
|
|
return (Imm & 0x00ff0000ULL) >> 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
// abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh
|
|
|
|
static inline bool isAdvSIMDModImmType9(uint64_t Imm) {
|
|
|
|
return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
|
|
|
|
((Imm >> 48) == (Imm & 0x0000ffffULL)) &&
|
|
|
|
((Imm >> 56) == (Imm & 0x000000ffULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType9(uint64_t Imm) {
|
|
|
|
return (Imm & 0xffULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType9(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = Imm;
|
|
|
|
EncVal |= (EncVal << 8);
|
|
|
|
EncVal |= (EncVal << 16);
|
|
|
|
EncVal |= (EncVal << 32);
|
|
|
|
return EncVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg hhhhhhhh
|
|
|
|
// cmode: 1110, op: 1
|
|
|
|
static inline bool isAdvSIMDModImmType10(uint64_t Imm) {
|
|
|
|
uint64_t ByteA = Imm & 0xff00000000000000ULL;
|
|
|
|
uint64_t ByteB = Imm & 0x00ff000000000000ULL;
|
|
|
|
uint64_t ByteC = Imm & 0x0000ff0000000000ULL;
|
|
|
|
uint64_t ByteD = Imm & 0x000000ff00000000ULL;
|
|
|
|
uint64_t ByteE = Imm & 0x00000000ff000000ULL;
|
|
|
|
uint64_t ByteF = Imm & 0x0000000000ff0000ULL;
|
|
|
|
uint64_t ByteG = Imm & 0x000000000000ff00ULL;
|
|
|
|
uint64_t ByteH = Imm & 0x00000000000000ffULL;
|
|
|
|
|
|
|
|
return (ByteA == 0ULL || ByteA == 0xff00000000000000ULL) &&
|
|
|
|
(ByteB == 0ULL || ByteB == 0x00ff000000000000ULL) &&
|
|
|
|
(ByteC == 0ULL || ByteC == 0x0000ff0000000000ULL) &&
|
|
|
|
(ByteD == 0ULL || ByteD == 0x000000ff00000000ULL) &&
|
|
|
|
(ByteE == 0ULL || ByteE == 0x00000000ff000000ULL) &&
|
|
|
|
(ByteF == 0ULL || ByteF == 0x0000000000ff0000ULL) &&
|
|
|
|
(ByteG == 0ULL || ByteG == 0x000000000000ff00ULL) &&
|
|
|
|
(ByteH == 0ULL || ByteH == 0x00000000000000ffULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType10(uint64_t Imm) {
|
2014-04-01 20:22:20 +08:00
|
|
|
uint8_t BitA = (Imm & 0xff00000000000000ULL) != 0;
|
|
|
|
uint8_t BitB = (Imm & 0x00ff000000000000ULL) != 0;
|
|
|
|
uint8_t BitC = (Imm & 0x0000ff0000000000ULL) != 0;
|
|
|
|
uint8_t BitD = (Imm & 0x000000ff00000000ULL) != 0;
|
|
|
|
uint8_t BitE = (Imm & 0x00000000ff000000ULL) != 0;
|
|
|
|
uint8_t BitF = (Imm & 0x0000000000ff0000ULL) != 0;
|
|
|
|
uint8_t BitG = (Imm & 0x000000000000ff00ULL) != 0;
|
|
|
|
uint8_t BitH = (Imm & 0x00000000000000ffULL) != 0;
|
|
|
|
|
|
|
|
uint8_t EncVal = BitA;
|
2014-03-29 18:18:08 +08:00
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitB;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitC;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitD;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitE;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitF;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitG;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitH;
|
|
|
|
return EncVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType10(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = 0;
|
|
|
|
if (Imm & 0x80) EncVal |= 0xff00000000000000ULL;
|
|
|
|
if (Imm & 0x40) EncVal |= 0x00ff000000000000ULL;
|
|
|
|
if (Imm & 0x20) EncVal |= 0x0000ff0000000000ULL;
|
|
|
|
if (Imm & 0x10) EncVal |= 0x000000ff00000000ULL;
|
|
|
|
if (Imm & 0x08) EncVal |= 0x00000000ff000000ULL;
|
|
|
|
if (Imm & 0x04) EncVal |= 0x0000000000ff0000ULL;
|
|
|
|
if (Imm & 0x02) EncVal |= 0x000000000000ff00ULL;
|
|
|
|
if (Imm & 0x01) EncVal |= 0x00000000000000ffULL;
|
|
|
|
return EncVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// aBbbbbbc defgh000 0x00 0x00 aBbbbbbc defgh000 0x00 0x00
|
|
|
|
static inline bool isAdvSIMDModImmType11(uint64_t Imm) {
|
|
|
|
uint64_t BString = (Imm & 0x7E000000ULL) >> 25;
|
|
|
|
return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
|
|
|
|
(BString == 0x1f || BString == 0x20) &&
|
|
|
|
((Imm & 0x0007ffff0007ffffULL) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType11(uint64_t Imm) {
|
2014-04-01 20:22:20 +08:00
|
|
|
uint8_t BitA = (Imm & 0x80000000ULL) != 0;
|
|
|
|
uint8_t BitB = (Imm & 0x20000000ULL) != 0;
|
|
|
|
uint8_t BitC = (Imm & 0x01000000ULL) != 0;
|
|
|
|
uint8_t BitD = (Imm & 0x00800000ULL) != 0;
|
|
|
|
uint8_t BitE = (Imm & 0x00400000ULL) != 0;
|
|
|
|
uint8_t BitF = (Imm & 0x00200000ULL) != 0;
|
|
|
|
uint8_t BitG = (Imm & 0x00100000ULL) != 0;
|
|
|
|
uint8_t BitH = (Imm & 0x00080000ULL) != 0;
|
|
|
|
|
|
|
|
uint8_t EncVal = BitA;
|
2014-03-29 18:18:08 +08:00
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitB;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitC;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitD;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitE;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitF;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitG;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitH;
|
|
|
|
return EncVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType11(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = 0;
|
|
|
|
if (Imm & 0x80) EncVal |= 0x80000000ULL;
|
|
|
|
if (Imm & 0x40) EncVal |= 0x3e000000ULL;
|
|
|
|
else EncVal |= 0x40000000ULL;
|
|
|
|
if (Imm & 0x20) EncVal |= 0x01000000ULL;
|
|
|
|
if (Imm & 0x10) EncVal |= 0x00800000ULL;
|
|
|
|
if (Imm & 0x08) EncVal |= 0x00400000ULL;
|
|
|
|
if (Imm & 0x04) EncVal |= 0x00200000ULL;
|
|
|
|
if (Imm & 0x02) EncVal |= 0x00100000ULL;
|
|
|
|
if (Imm & 0x01) EncVal |= 0x00080000ULL;
|
|
|
|
return (EncVal << 32) | EncVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// aBbbbbbb bbcdefgh 0x00 0x00 0x00 0x00 0x00 0x00
|
|
|
|
static inline bool isAdvSIMDModImmType12(uint64_t Imm) {
|
|
|
|
uint64_t BString = (Imm & 0x7fc0000000000000ULL) >> 54;
|
|
|
|
return ((BString == 0xff || BString == 0x100) &&
|
|
|
|
((Imm & 0x0000ffffffffffffULL) == 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t encodeAdvSIMDModImmType12(uint64_t Imm) {
|
2014-04-01 20:22:20 +08:00
|
|
|
uint8_t BitA = (Imm & 0x8000000000000000ULL) != 0;
|
|
|
|
uint8_t BitB = (Imm & 0x0040000000000000ULL) != 0;
|
|
|
|
uint8_t BitC = (Imm & 0x0020000000000000ULL) != 0;
|
|
|
|
uint8_t BitD = (Imm & 0x0010000000000000ULL) != 0;
|
|
|
|
uint8_t BitE = (Imm & 0x0008000000000000ULL) != 0;
|
|
|
|
uint8_t BitF = (Imm & 0x0004000000000000ULL) != 0;
|
|
|
|
uint8_t BitG = (Imm & 0x0002000000000000ULL) != 0;
|
|
|
|
uint8_t BitH = (Imm & 0x0001000000000000ULL) != 0;
|
|
|
|
|
|
|
|
uint8_t EncVal = BitA;
|
2014-03-29 18:18:08 +08:00
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitB;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitC;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitD;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitE;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitF;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitG;
|
|
|
|
EncVal <<= 1;
|
|
|
|
EncVal |= BitH;
|
|
|
|
return EncVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t decodeAdvSIMDModImmType12(uint8_t Imm) {
|
|
|
|
uint64_t EncVal = 0;
|
|
|
|
if (Imm & 0x80) EncVal |= 0x8000000000000000ULL;
|
|
|
|
if (Imm & 0x40) EncVal |= 0x3fc0000000000000ULL;
|
|
|
|
else EncVal |= 0x4000000000000000ULL;
|
|
|
|
if (Imm & 0x20) EncVal |= 0x0020000000000000ULL;
|
|
|
|
if (Imm & 0x10) EncVal |= 0x0010000000000000ULL;
|
|
|
|
if (Imm & 0x08) EncVal |= 0x0008000000000000ULL;
|
|
|
|
if (Imm & 0x04) EncVal |= 0x0004000000000000ULL;
|
|
|
|
if (Imm & 0x02) EncVal |= 0x0002000000000000ULL;
|
|
|
|
if (Imm & 0x01) EncVal |= 0x0001000000000000ULL;
|
|
|
|
return (EncVal << 32) | EncVal;
|
|
|
|
}
|
|
|
|
|
2018-02-06 21:13:21 +08:00
|
|
|
/// Returns true if Imm is the concatenation of a repeating pattern of type T.
|
|
|
|
template <typename T>
|
|
|
|
static inline bool isSVEMaskOfIdenticalElements(int64_t Imm) {
|
2018-09-11 12:08:05 +08:00
|
|
|
auto Parts = bit_cast<std::array<T, sizeof(int64_t) / sizeof(T)>>(Imm);
|
|
|
|
return all_of(Parts, [&](T Elem) { return Elem == Parts[0]; });
|
2018-02-06 21:13:21 +08:00
|
|
|
}
|
|
|
|
|
2018-05-25 17:47:52 +08:00
|
|
|
/// Returns true if Imm is valid for CPY/DUP.
|
|
|
|
template <typename T>
|
|
|
|
static inline bool isSVECpyImm(int64_t Imm) {
|
2018-06-04 15:24:23 +08:00
|
|
|
bool IsImm8 = int8_t(Imm) == Imm;
|
|
|
|
bool IsImm16 = int16_t(Imm & ~0xff) == Imm;
|
|
|
|
|
2018-05-25 17:47:52 +08:00
|
|
|
if (std::is_same<int8_t, typename std::make_signed<T>::type>::value)
|
2018-06-04 15:24:23 +08:00
|
|
|
return IsImm8 || uint8_t(Imm) == Imm;
|
|
|
|
|
|
|
|
if (std::is_same<int16_t, typename std::make_signed<T>::type>::value)
|
|
|
|
return IsImm8 || IsImm16 || uint16_t(Imm & ~0xff) == Imm;
|
|
|
|
|
|
|
|
return IsImm8 || IsImm16;
|
2018-05-29 18:39:49 +08:00
|
|
|
}
|
2018-05-25 17:47:52 +08:00
|
|
|
|
2018-05-29 18:39:49 +08:00
|
|
|
/// Returns true if Imm is valid for ADD/SUB.
|
|
|
|
template <typename T>
|
|
|
|
static inline bool isSVEAddSubImm(int64_t Imm) {
|
|
|
|
bool IsInt8t =
|
|
|
|
std::is_same<int8_t, typename std::make_signed<T>::type>::value;
|
|
|
|
return uint8_t(Imm) == Imm || (!IsInt8t && uint16_t(Imm & ~0xff) == Imm);
|
2018-05-25 17:47:52 +08:00
|
|
|
}
|
|
|
|
|
2018-06-01 15:25:46 +08:00
|
|
|
/// Return true if Imm is valid for DUPM and has no single CPY/DUP equivalent.
|
|
|
|
static inline bool isSVEMoveMaskPreferredLogicalImmediate(int64_t Imm) {
|
2018-09-11 12:08:05 +08:00
|
|
|
if (isSVECpyImm<int64_t>(Imm))
|
2018-06-01 15:25:46 +08:00
|
|
|
return false;
|
|
|
|
|
2018-09-11 12:08:05 +08:00
|
|
|
auto S = bit_cast<std::array<int32_t, 2>>(Imm);
|
|
|
|
auto H = bit_cast<std::array<int16_t, 4>>(Imm);
|
|
|
|
auto B = bit_cast<std::array<int8_t, 8>>(Imm);
|
2018-09-09 00:50:56 +08:00
|
|
|
|
2018-09-11 12:08:05 +08:00
|
|
|
if (isSVEMaskOfIdenticalElements<int32_t>(Imm) && isSVECpyImm<int32_t>(S[0]))
|
2018-06-01 15:25:46 +08:00
|
|
|
return false;
|
2018-09-11 12:08:05 +08:00
|
|
|
if (isSVEMaskOfIdenticalElements<int16_t>(Imm) && isSVECpyImm<int16_t>(H[0]))
|
2018-09-09 00:43:49 +08:00
|
|
|
return false;
|
2018-09-11 12:08:05 +08:00
|
|
|
if (isSVEMaskOfIdenticalElements<int8_t>(Imm) && isSVECpyImm<int8_t>(B[0]))
|
|
|
|
return false;
|
|
|
|
return isLogicalImmediate(Imm, 64);
|
2018-06-01 15:25:46 +08:00
|
|
|
}
|
|
|
|
|
2016-06-16 09:42:25 +08:00
|
|
|
inline static bool isAnyMOVZMovAlias(uint64_t Value, int RegWidth) {
|
|
|
|
for (int Shift = 0; Shift <= RegWidth - 16; Shift += 16)
|
|
|
|
if ((Value & ~(0xffffULL << Shift)) == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool isMOVZMovAlias(uint64_t Value, int Shift, int RegWidth) {
|
|
|
|
if (RegWidth == 32)
|
|
|
|
Value &= 0xffffffffULL;
|
|
|
|
|
|
|
|
// "lsl #0" takes precedence: in practice this only affects "#0, lsl #0".
|
|
|
|
if (Value == 0 && Shift != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (Value & ~(0xffffULL << Shift)) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool isMOVNMovAlias(uint64_t Value, int Shift, int RegWidth) {
|
|
|
|
// MOVZ takes precedence over MOVN.
|
|
|
|
if (isAnyMOVZMovAlias(Value, RegWidth))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Value = ~Value;
|
|
|
|
if (RegWidth == 32)
|
|
|
|
Value &= 0xffffffffULL;
|
|
|
|
|
|
|
|
return isMOVZMovAlias(Value, Shift, RegWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool isAnyMOVWMovAlias(uint64_t Value, int RegWidth) {
|
|
|
|
if (isAnyMOVZMovAlias(Value, RegWidth))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// It's not a MOVZ, but it might be a MOVN.
|
|
|
|
Value = ~Value;
|
|
|
|
if (RegWidth == 32)
|
|
|
|
Value &= 0xffffffffULL;
|
|
|
|
|
|
|
|
return isAnyMOVZMovAlias(Value, RegWidth);
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
} // end namespace AArch64_AM
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|