2007-01-19 15:51:42 +08:00
|
|
|
//===- ARMAddressingModes.h - ARM Addressing Modes --------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-01-19 15:51:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the ARM addressing mode implementation stuff.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TARGET_ARM_ARMADDRESSINGMODES_H
|
|
|
|
#define LLVM_TARGET_ARM_ARMADDRESSINGMODES_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/SelectionDAGNodes.h"
|
|
|
|
#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,
|
|
|
|
rrx
|
|
|
|
};
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
enum AddrOpc {
|
|
|
|
add = '+', sub = '-'
|
|
|
|
};
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2010-03-18 01:52:21 +08:00
|
|
|
static inline const char *getAddrOpcStr(AddrOpc Op) {
|
|
|
|
return Op == sub ? "-" : "";
|
|
|
|
}
|
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
static inline const char *getShiftOpcStr(ShiftOpc Op) {
|
|
|
|
switch (Op) {
|
2009-10-20 05:23:15 +08:00
|
|
|
default: assert(0 && "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";
|
|
|
|
}
|
|
|
|
}
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2008-07-28 05:46:04 +08:00
|
|
|
static inline ShiftOpc getShiftOpcForNode(SDValue N) {
|
2007-01-19 15:51:42 +08:00
|
|
|
switch (N.getOpcode()) {
|
|
|
|
default: return ARM_AM::no_shift;
|
|
|
|
case ISD::SHL: return ARM_AM::lsl;
|
|
|
|
case ISD::SRL: return ARM_AM::lsr;
|
|
|
|
case ISD::SRA: return ARM_AM::asr;
|
|
|
|
case ISD::ROTR: return ARM_AM::ror;
|
|
|
|
//case ISD::ROTL: // Only if imm -> turn into ROTR.
|
|
|
|
// Can't handle RRX here, because it would require folding a flag into
|
|
|
|
// the addressing mode. :( This causes us to miss certain things.
|
|
|
|
//case ARMISD::RRX: return ARM_AM::rrx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum AMSubMode {
|
|
|
|
bad_am_submode = 0,
|
|
|
|
ia,
|
|
|
|
ib,
|
|
|
|
da,
|
|
|
|
db
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline const char *getAMSubModeStr(AMSubMode Mode) {
|
|
|
|
switch (Mode) {
|
2009-10-20 05:23:15 +08:00
|
|
|
default: assert(0 && "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.
|
|
|
|
///
|
|
|
|
static inline unsigned rotr32(unsigned Val, unsigned Amt) {
|
|
|
|
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.
|
|
|
|
///
|
|
|
|
static inline unsigned rotl32(unsigned Val, unsigned Amt) {
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
static inline unsigned getSORegOpc(ShiftOpc ShOp, unsigned Imm) {
|
|
|
|
return ShOp | (Imm << 3);
|
|
|
|
}
|
|
|
|
static inline unsigned getSORegOffset(unsigned Op) {
|
|
|
|
return Op >> 3;
|
|
|
|
}
|
|
|
|
static inline ShiftOpc getSORegShOp(unsigned Op) {
|
|
|
|
return (ShiftOpc)(Op & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getSOImmValImm - Given an encoded imm field for the reg/imm form, return
|
|
|
|
/// the 8-bit imm value.
|
|
|
|
static 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.
|
|
|
|
static 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.
|
|
|
|
static inline unsigned getSOImmValRotate(unsigned Imm) {
|
|
|
|
// 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.
|
|
|
|
unsigned TZ = CountTrailingZeros_32(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.
|
|
|
|
|
|
|
|
// For values like 0xF000000F, we should skip the first run of ones, then
|
|
|
|
// retry the hunt.
|
|
|
|
if (Imm & 1) {
|
|
|
|
unsigned TrailingOnes = CountTrailingZeros_32(~Imm);
|
|
|
|
if (TrailingOnes != 32) { // Avoid overflow on 0xFFFFFFFF
|
|
|
|
// Restart the search for a high-order bit after the initial seconds of
|
|
|
|
// ones.
|
|
|
|
unsigned TZ2 = CountTrailingZeros_32(Imm & ~((1 << TrailingOnes)-1));
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// Rotate amount must be even.
|
|
|
|
unsigned RotAmt2 = TZ2 & ~1;
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// If this fits, use it.
|
|
|
|
if (RotAmt2 != 32 && (rotr32(Imm, RotAmt2) & ~255U) == 0)
|
|
|
|
return (32-RotAmt2)&31; // HW rotates right, not left.
|
|
|
|
}
|
|
|
|
}
|
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.
|
|
|
|
static inline int getSOImmVal(unsigned Arg) {
|
|
|
|
// 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.
|
Fixed a crasher in arm disassembler within ARMInstPrinter.cpp after calling
ARM_AM::getSoImmVal(V) with a legitimate so_imm value: #245 rotate right by 2.
Introduce ARM_AM::getSOImmValOneOrNoRotate(unsigned Arg) which is called from
ARMInstPrinter.cpp's printSOImm() function, replacing ARM_AM::getSOImmVal(V).
[12:44:43] johnny:/Volumes/data/llvm/git/trunk (local-trunk) $ gdb Debug/bin/llvm-mc
GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ... done
(gdb) set args -triple=arm-apple-darwin9 -debug-only=arm-disassembler --disassemble
(gdb) r
Starting program: /Volumes/data/llvm/git/trunk/Debug/bin/llvm-mc -triple=arm-apple-darwin9 -debug-only=arm-disassembler --disassemble
Reading symbols for shared libraries ++. done
0xf5 0x71 0xf0 0x53
Opcode=201 Name=MVNi Format=ARM_FORMAT_DPFRM(4)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
-------------------------------------------------------------------------------------------------
| 0: 1: 0: 1| 0: 0: 1: 1| 1: 1: 1: 1| 0: 0: 0: 0| 0: 1: 1: 1| 0: 0: 0: 1| 1: 1: 1: 1| 0: 1: 0: 1|
-------------------------------------------------------------------------------------------------
mvnpls r7, Assertion failed: (V != -1 && "Not a valid so_imm value!"), function printSOImm, file ARMInstPrinter.cpp, line 229.
Program received signal SIGABRT, Aborted.
0x00007fff88c65886 in __kill ()
(gdb) bt
#0 0x00007fff88c65886 in __kill ()
#1 0x00007fff88d05eae in abort ()
#2 0x00007fff88cf2ef0 in __assert_rtn ()
#3 0x000000010020e422 in printSOImm (O=@0x1010bdf80, V=-1, VerboseAsm=false, MAI=0x1020106d0) at ARMInstPrinter.cpp:229
#4 0x000000010020e5fe in llvm::ARMInstPrinter::printSOImmOperand (this=0x1020107e0, MI=0x7fff5fbfee70, OpNum=1, O=@0x1010bdf80) at ARMInstPrinter.cpp:254
#5 0x00000001001ffbc0 in llvm::ARMInstPrinter::printInstruction (this=0x1020107e0, MI=0x7fff5fbfee70, O=@0x1010bdf80) at ARMGenAsmWriter.inc:3236
#6 0x000000010020c27c in llvm::ARMInstPrinter::printInst (this=0x1020107e0, MI=0x7fff5fbfee70, O=@0x1010bdf80) at ARMInstPrinter.cpp:182
#7 0x000000010003cbff in PrintInsts (DisAsm=@0x10200f4e0, Printer=@0x1020107e0, Bytes=@0x7fff5fbff060, SM=@0x7fff5fbff078) at Disassembler.cpp:65
#8 0x000000010003c8b4 in llvm::Disassembler::disassemble (T=@0x1010c13c0, Triple=@0x1010b6798, Buffer=@0x102010690) at Disassembler.cpp:153
#9 0x000000010004095c in DisassembleInput (ProgName=0x7fff5fbff3f0 "/Volumes/data/llvm/git/trunk/Debug/bin/llvm-mc") at llvm-mc.cpp:347
#10 0x000000010003eefb in main (argc=4, argv=0x7fff5fbff298) at llvm-mc.cpp:374
(gdb) q
The program is running. Exit anyway? (y or n) y
[13:36:26] johnny:/Volumes/data/llvm/git/trunk (local-trunk) $
llvm-svn: 101053
2010-04-13 02:46:53 +08:00
|
|
|
return rotl32(Arg, RotAmt) | ((RotAmt>>1) << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getSOImmValOneRotate - 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, return 0.
|
|
|
|
static unsigned getSOImmValOneRotate(unsigned Imm) {
|
|
|
|
// A5.2.4 Constants with multiple encodings
|
|
|
|
// The lowest unsigned value of rotation wins!
|
|
|
|
for (unsigned R = 1; R <= 15; ++R)
|
|
|
|
if ((Imm & rotr32(~255U, 2*R)) == 0)
|
|
|
|
return 2*R;
|
|
|
|
|
|
|
|
// Failed to find a suitable rotate amount.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getSOImmValOneOrNoRotate - Given a 32-bit immediate, if it is something
|
|
|
|
/// that can fit into a shifter_operand immediate operand, return the 12-bit
|
|
|
|
/// encoding for it. If not, return -1. This is different from getSOImmVal()
|
|
|
|
/// in that getSOImmVal() is used during codegen, for example,
|
|
|
|
/// rewriteARMFrameIndex() where return value of -1 is not considered fatal.
|
|
|
|
///
|
|
|
|
/// The current consumer of this API is printSOImm() within ARMInstPrinter.cpp
|
|
|
|
/// where return value of -1 indicates that the Arg is not a valid so_imm val!
|
|
|
|
static inline int getSOImmValOneOrNoRotate(unsigned Arg) {
|
|
|
|
// 8-bit (or less) immediates are trivially shifter_operands with a rotate
|
|
|
|
// of zero.
|
|
|
|
if ((Arg & ~255U) == 0) return Arg;
|
|
|
|
|
|
|
|
unsigned RotAmt = getSOImmValOneRotate(Arg);
|
|
|
|
|
|
|
|
// If this cannot be handled with a single shifter_op, bail out.
|
|
|
|
if (rotr32(~255U, RotAmt) & Arg)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// Encode this correctly.
|
2007-01-19 15:51:42 +08:00
|
|
|
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.
|
|
|
|
static inline bool isSOImmTwoPartVal(unsigned V) {
|
|
|
|
// 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.
|
|
|
|
static inline unsigned getSOImmTwoPartFirst(unsigned V) {
|
|
|
|
return rotr32(255U, getSOImmValRotate(V)) & V;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getSOImmTwoPartSecond - If V is a value that satisfies isSOImmTwoPartVal,
|
|
|
|
/// return the second chunk of it.
|
|
|
|
static 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.
|
|
|
|
static inline unsigned getThumbImmValShift(unsigned Imm) {
|
|
|
|
// 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.
|
|
|
|
return CountTrailingZeros_32(Imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isThumbImmShiftedVal - Return true if the specified value can be obtained
|
|
|
|
/// by left shifting a 8-bit immediate.
|
|
|
|
static 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.
|
|
|
|
static inline unsigned getThumbImm16ValShift(unsigned Imm) {
|
|
|
|
// 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.
|
|
|
|
return CountTrailingZeros_32(Imm);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
static 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.
|
|
|
|
static inline unsigned getThumbImmNonShiftedVal(unsigned V) {
|
|
|
|
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.
|
2009-07-28 13:48:47 +08:00
|
|
|
static 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.
|
2009-07-28 13:48:47 +08:00
|
|
|
static inline int getT2SOImmValRotateVal(unsigned V) {
|
2009-06-24 01:48:47 +08:00
|
|
|
unsigned RotAmt = CountLeadingZeros_32(V);
|
|
|
|
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.
|
|
|
|
static inline int getT2SOImmVal(unsigned Arg) {
|
|
|
|
// 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
|
|
|
|
2009-10-22 04:44:34 +08:00
|
|
|
static inline unsigned getT2SOImmValRotate(unsigned V) {
|
|
|
|
if ((V & ~255U) == 0) return 0;
|
|
|
|
// Use CTZ to compute the rotate amount.
|
|
|
|
unsigned RotAmt = CountTrailingZeros_32(V);
|
|
|
|
return (32 - RotAmt) & 31;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isT2SOImmTwoPartVal (unsigned Imm) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned getT2SOImmTwoPartFirst(unsigned Imm) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned getT2SOImmTwoPartSecond(unsigned Imm) {
|
|
|
|
// 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
|
|
|
|
// in bit 12, the immediate in bits 0-11, and the shift op in 13-15.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
//
|
2007-01-19 15:51:42 +08:00
|
|
|
static inline unsigned getAM2Opc(AddrOpc Opc, unsigned Imm12, ShiftOpc SO) {
|
|
|
|
assert(Imm12 < (1 << 12) && "Imm too large!");
|
|
|
|
bool isSub = Opc == sub;
|
|
|
|
return Imm12 | ((int)isSub << 12) | (SO << 13);
|
|
|
|
}
|
|
|
|
static inline unsigned getAM2Offset(unsigned AM2Opc) {
|
|
|
|
return AM2Opc & ((1 << 12)-1);
|
|
|
|
}
|
|
|
|
static inline AddrOpc getAM2Op(unsigned AM2Opc) {
|
|
|
|
return ((AM2Opc >> 12) & 1) ? sub : add;
|
|
|
|
}
|
|
|
|
static inline ShiftOpc getAM2ShiftOpc(unsigned AM2Opc) {
|
|
|
|
return (ShiftOpc)(AM2Opc >> 13);
|
|
|
|
}
|
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
|
|
|
|
// in bit 8, the immediate in bits 0-7.
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// getAM3Opc - This function encodes the addrmode3 opc field.
|
|
|
|
static inline unsigned getAM3Opc(AddrOpc Opc, unsigned char Offset) {
|
|
|
|
bool isSub = Opc == sub;
|
|
|
|
return ((int)isSub << 8) | Offset;
|
|
|
|
}
|
|
|
|
static inline unsigned char getAM3Offset(unsigned AM3Opc) {
|
|
|
|
return AM3Opc & 0xFF;
|
|
|
|
}
|
|
|
|
static inline AddrOpc getAM3Op(unsigned AM3Opc) {
|
|
|
|
return ((AM3Opc >> 8) & 1) ? sub : add;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
static inline AMSubMode getAM4SubMode(unsigned Mode) {
|
|
|
|
return (AMSubMode)(Mode & 0x7);
|
|
|
|
}
|
|
|
|
|
2010-03-17 01:46:45 +08:00
|
|
|
static 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
|
|
|
|
// operation in bit 8 and the immediate in bits 0-7.
|
2007-01-19 15:51:42 +08:00
|
|
|
//
|
2009-07-02 05:22:45 +08:00
|
|
|
// This is also used for FP load/store multiple ops. The second operand
|
2010-03-17 02:38:09 +08:00
|
|
|
// encodes the number of registers (or 2 times the number of registers
|
|
|
|
// for DPR ops) in bits 0-7. In addition, bits 8-10 encode one of the
|
|
|
|
// following two sub-modes:
|
2007-01-19 15:51:42 +08:00
|
|
|
//
|
|
|
|
// IA - Increment after
|
|
|
|
// DB - Decrement before
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// getAM5Opc - This function encodes the addrmode5 opc field.
|
|
|
|
static inline unsigned getAM5Opc(AddrOpc Opc, unsigned char Offset) {
|
|
|
|
bool isSub = Opc == sub;
|
|
|
|
return ((int)isSub << 8) | Offset;
|
|
|
|
}
|
|
|
|
static inline unsigned char getAM5Offset(unsigned AM5Opc) {
|
|
|
|
return AM5Opc & 0xFF;
|
|
|
|
}
|
|
|
|
static inline AddrOpc getAM5Op(unsigned AM5Opc) {
|
|
|
|
return ((AM5Opc >> 8) & 1) ? sub : add;
|
|
|
|
}
|
|
|
|
|
2009-11-09 08:11:35 +08:00
|
|
|
/// getAM5Opc - This function encodes the addrmode5 opc field for VLDM and
|
|
|
|
/// VSTM instructions.
|
2010-03-17 02:38:09 +08:00
|
|
|
static inline unsigned getAM5Opc(AMSubMode SubMode, unsigned char Offset) {
|
2007-01-19 15:51:42 +08:00
|
|
|
assert((SubMode == ia || SubMode == db) &&
|
|
|
|
"Illegal addressing mode 5 sub-mode!");
|
2010-03-17 02:38:09 +08:00
|
|
|
return ((int)SubMode << 8) | Offset;
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
|
|
|
static inline AMSubMode getAM5SubMode(unsigned AM5Opc) {
|
2010-03-17 02:38:09 +08:00
|
|
|
return (AMSubMode)((AM5Opc >> 8) & 0x7);
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
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
|
|
|
|
// specifier to use or zero if no explicit alignment.
|
2009-07-02 07:16:05 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
} // end namespace ARM_AM
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|