Commit 29f73ad1 authored by jacob.bramley's avatar jacob.bramley Committed by Commit bot

[arm64] Fix some signed/unsigned type inconsistencies.

This fixes several warnings when cross-building using GCC (since r31087,
5cf1c0bc).

In particular, CPURegister::code() now returns 'int', matching the other
platforms (and the coding style guide). The rest of the patch consists
of similar changes to make this work.

BUG=

Review URL: https://codereview.chromium.org/1393043003

Cr-Commit-Position: refs/heads/master@{#31176}
parent 93e93983
......@@ -41,7 +41,7 @@ void RelocInfo::set_target_address(Address target,
}
inline unsigned CPURegister::code() const {
inline int CPURegister::code() const {
DCHECK(IsValid());
return reg_code;
}
......@@ -54,12 +54,12 @@ inline CPURegister::RegisterType CPURegister::type() const {
inline RegList CPURegister::Bit() const {
DCHECK(reg_code < (sizeof(RegList) * kBitsPerByte));
DCHECK(static_cast<size_t>(reg_code) < (sizeof(RegList) * kBitsPerByte));
return IsValid() ? 1UL << reg_code : 0;
}
inline unsigned CPURegister::SizeInBits() const {
inline int CPURegister::SizeInBits() const {
DCHECK(IsValid());
return reg_size;
}
......
......@@ -110,17 +110,17 @@ void CPURegList::RemoveCalleeSaved() {
}
CPURegList CPURegList::GetCalleeSaved(unsigned size) {
CPURegList CPURegList::GetCalleeSaved(int size) {
return CPURegList(CPURegister::kRegister, size, 19, 29);
}
CPURegList CPURegList::GetCalleeSavedFP(unsigned size) {
CPURegList CPURegList::GetCalleeSavedFP(int size) {
return CPURegList(CPURegister::kFPRegister, size, 8, 15);
}
CPURegList CPURegList::GetCallerSaved(unsigned size) {
CPURegList CPURegList::GetCallerSaved(int size) {
// Registers x0-x18 and lr (x30) are caller-saved.
CPURegList list = CPURegList(CPURegister::kRegister, size, 0, 18);
list.Combine(lr);
......@@ -128,7 +128,7 @@ CPURegList CPURegList::GetCallerSaved(unsigned size) {
}
CPURegList CPURegList::GetCallerSavedFP(unsigned size) {
CPURegList CPURegList::GetCallerSavedFP(int size) {
// Registers d0-d7 and d16-d31 are caller-saved.
CPURegList list = CPURegList(CPURegister::kFPRegister, size, 0, 7);
list.Combine(CPURegList(CPURegister::kFPRegister, size, 16, 31));
......@@ -1278,10 +1278,8 @@ void Assembler::rorv(const Register& rd,
// Bitfield operations.
void Assembler::bfm(const Register& rd,
const Register& rn,
unsigned immr,
unsigned imms) {
void Assembler::bfm(const Register& rd, const Register& rn, int immr,
int imms) {
DCHECK(rd.SizeInBits() == rn.SizeInBits());
Instr N = SF(rd) >> (kSFOffset - kBitfieldNOffset);
Emit(SF(rd) | BFM | N |
......@@ -1291,10 +1289,8 @@ void Assembler::bfm(const Register& rd,
}
void Assembler::sbfm(const Register& rd,
const Register& rn,
unsigned immr,
unsigned imms) {
void Assembler::sbfm(const Register& rd, const Register& rn, int immr,
int imms) {
DCHECK(rd.Is64Bits() || rn.Is32Bits());
Instr N = SF(rd) >> (kSFOffset - kBitfieldNOffset);
Emit(SF(rd) | SBFM | N |
......@@ -1304,10 +1300,8 @@ void Assembler::sbfm(const Register& rd,
}
void Assembler::ubfm(const Register& rd,
const Register& rn,
unsigned immr,
unsigned imms) {
void Assembler::ubfm(const Register& rd, const Register& rn, int immr,
int imms) {
DCHECK(rd.SizeInBits() == rn.SizeInBits());
Instr N = SF(rd) >> (kSFOffset - kBitfieldNOffset);
Emit(SF(rd) | UBFM | N |
......@@ -1317,10 +1311,8 @@ void Assembler::ubfm(const Register& rd,
}
void Assembler::extr(const Register& rd,
const Register& rn,
const Register& rm,
unsigned lsb) {
void Assembler::extr(const Register& rd, const Register& rn, const Register& rm,
int lsb) {
DCHECK(rd.SizeInBits() == rn.SizeInBits());
DCHECK(rd.SizeInBits() == rm.SizeInBits());
Instr N = SF(rd) >> (kSFOffset - kBitfieldNOffset);
......
......@@ -80,15 +80,15 @@ struct CPURegister {
kNoRegister
};
static CPURegister Create(unsigned code, unsigned size, RegisterType type) {
static CPURegister Create(int code, int size, RegisterType type) {
CPURegister r = {code, size, type};
return r;
}
unsigned code() const;
int code() const;
RegisterType type() const;
RegList Bit() const;
unsigned SizeInBits() const;
int SizeInBits() const;
int SizeInBytes() const;
bool Is32Bits() const;
bool Is64Bits() const;
......@@ -117,14 +117,14 @@ struct CPURegister {
bool is(const CPURegister& other) const { return Is(other); }
bool is_valid() const { return IsValid(); }
unsigned reg_code;
unsigned reg_size;
int reg_code;
int reg_size;
RegisterType reg_type;
};
struct Register : public CPURegister {
static Register Create(unsigned code, unsigned size) {
static Register Create(int code, int size) {
return Register(CPURegister::Create(code, size, CPURegister::kRegister));
}
......@@ -199,7 +199,7 @@ struct FPRegister : public CPURegister {
kCode_no_reg = -1
};
static FPRegister Create(unsigned code, unsigned size) {
static FPRegister Create(int code, int size) {
return FPRegister(
CPURegister::Create(code, size, CPURegister::kFPRegister));
}
......@@ -384,13 +384,13 @@ class CPURegList {
DCHECK(IsValid());
}
CPURegList(CPURegister::RegisterType type, unsigned size, RegList list)
CPURegList(CPURegister::RegisterType type, int size, RegList list)
: list_(list), size_(size), type_(type) {
DCHECK(IsValid());
}
CPURegList(CPURegister::RegisterType type, unsigned size,
unsigned first_reg, unsigned last_reg)
CPURegList(CPURegister::RegisterType type, int size, int first_reg,
int last_reg)
: size_(size), type_(type) {
DCHECK(((type == CPURegister::kRegister) &&
(last_reg < kNumberOfRegisters)) ||
......@@ -447,12 +447,12 @@ class CPURegList {
CPURegister PopHighestIndex();
// AAPCS64 callee-saved registers.
static CPURegList GetCalleeSaved(unsigned size = kXRegSizeInBits);
static CPURegList GetCalleeSavedFP(unsigned size = kDRegSizeInBits);
static CPURegList GetCalleeSaved(int size = kXRegSizeInBits);
static CPURegList GetCalleeSavedFP(int size = kDRegSizeInBits);
// AAPCS64 caller-saved registers. Note that this includes lr.
static CPURegList GetCallerSaved(unsigned size = kXRegSizeInBits);
static CPURegList GetCallerSavedFP(unsigned size = kDRegSizeInBits);
static CPURegList GetCallerSaved(int size = kXRegSizeInBits);
static CPURegList GetCallerSavedFP(int size = kDRegSizeInBits);
// Registers saved as safepoints.
static CPURegList GetSafepointSavedRegisters();
......@@ -480,25 +480,25 @@ class CPURegList {
return CountSetBits(list_, kRegListSizeInBits);
}
unsigned RegisterSizeInBits() const {
int RegisterSizeInBits() const {
DCHECK(IsValid());
return size_;
}
unsigned RegisterSizeInBytes() const {
int RegisterSizeInBytes() const {
int size_in_bits = RegisterSizeInBits();
DCHECK((size_in_bits % kBitsPerByte) == 0);
return size_in_bits / kBitsPerByte;
}
unsigned TotalSizeInBytes() const {
int TotalSizeInBytes() const {
DCHECK(IsValid());
return RegisterSizeInBytes() * Count();
}
private:
RegList list_;
unsigned size_;
int size_;
CPURegister::RegisterType type_;
bool IsValid() const {
......@@ -1120,39 +1120,24 @@ class Assembler : public AssemblerBase {
// Bitfield instructions.
// Bitfield move.
void bfm(const Register& rd,
const Register& rn,
unsigned immr,
unsigned imms);
void bfm(const Register& rd, const Register& rn, int immr, int imms);
// Signed bitfield move.
void sbfm(const Register& rd,
const Register& rn,
unsigned immr,
unsigned imms);
void sbfm(const Register& rd, const Register& rn, int immr, int imms);
// Unsigned bitfield move.
void ubfm(const Register& rd,
const Register& rn,
unsigned immr,
unsigned imms);
void ubfm(const Register& rd, const Register& rn, int immr, int imms);
// Bfm aliases.
// Bitfield insert.
void bfi(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
void bfi(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
bfm(rd, rn, (rd.SizeInBits() - lsb) & (rd.SizeInBits() - 1), width - 1);
}
// Bitfield extract and insert low.
void bfxil(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
void bfxil(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
bfm(rd, rn, lsb, lsb + width - 1);
......@@ -1160,26 +1145,20 @@ class Assembler : public AssemblerBase {
// Sbfm aliases.
// Arithmetic shift right.
void asr(const Register& rd, const Register& rn, unsigned shift) {
void asr(const Register& rd, const Register& rn, int shift) {
DCHECK(shift < rd.SizeInBits());
sbfm(rd, rn, shift, rd.SizeInBits() - 1);
}
// Signed bitfield insert in zero.
void sbfiz(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
void sbfiz(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
sbfm(rd, rn, (rd.SizeInBits() - lsb) & (rd.SizeInBits() - 1), width - 1);
}
// Signed bitfield extract.
void sbfx(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
void sbfx(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
sbfm(rd, rn, lsb, lsb + width - 1);
......@@ -1202,33 +1181,27 @@ class Assembler : public AssemblerBase {
// Ubfm aliases.
// Logical shift left.
void lsl(const Register& rd, const Register& rn, unsigned shift) {
unsigned reg_size = rd.SizeInBits();
void lsl(const Register& rd, const Register& rn, int shift) {
int reg_size = rd.SizeInBits();
DCHECK(shift < reg_size);
ubfm(rd, rn, (reg_size - shift) % reg_size, reg_size - shift - 1);
}
// Logical shift right.
void lsr(const Register& rd, const Register& rn, unsigned shift) {
void lsr(const Register& rd, const Register& rn, int shift) {
DCHECK(shift < rd.SizeInBits());
ubfm(rd, rn, shift, rd.SizeInBits() - 1);
}
// Unsigned bitfield insert in zero.
void ubfiz(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
void ubfiz(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
ubfm(rd, rn, (rd.SizeInBits() - lsb) & (rd.SizeInBits() - 1), width - 1);
}
// Unsigned bitfield extract.
void ubfx(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
void ubfx(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
ubfm(rd, rn, lsb, lsb + width - 1);
......@@ -1250,10 +1223,8 @@ class Assembler : public AssemblerBase {
}
// Extract.
void extr(const Register& rd,
const Register& rn,
const Register& rm,
unsigned lsb);
void extr(const Register& rd, const Register& rn, const Register& rm,
int lsb);
// Conditional select: rd = cond ? rn : rm.
void csel(const Register& rd,
......
......@@ -32,8 +32,8 @@ const unsigned kInstructionSizeLog2 = 2;
const unsigned kLoadLiteralScaleLog2 = 2;
const unsigned kMaxLoadLiteralRange = 1 * MB;
const unsigned kNumberOfRegisters = 32;
const unsigned kNumberOfFPRegisters = 32;
const int kNumberOfRegisters = 32;
const int kNumberOfFPRegisters = 32;
// Callee saved registers are x19-x30(lr).
const int kNumberOfCalleeSavedRegisters = 11;
const int kFirstCalleeSavedRegisterIndex = 19;
......@@ -42,23 +42,22 @@ const int kNumberOfCalleeSavedFPRegisters = 8;
const int kFirstCalleeSavedFPRegisterIndex = 8;
// Callee saved registers with no specific purpose in JS are x19-x25.
const unsigned kJSCalleeSavedRegList = 0x03f80000;
// TODO(all): k<Y>RegSize should probably be k<Y>RegSizeInBits.
const unsigned kWRegSizeInBits = 32;
const unsigned kWRegSizeInBitsLog2 = 5;
const unsigned kWRegSize = kWRegSizeInBits >> 3;
const unsigned kWRegSizeLog2 = kWRegSizeInBitsLog2 - 3;
const unsigned kXRegSizeInBits = 64;
const unsigned kXRegSizeInBitsLog2 = 6;
const unsigned kXRegSize = kXRegSizeInBits >> 3;
const unsigned kXRegSizeLog2 = kXRegSizeInBitsLog2 - 3;
const unsigned kSRegSizeInBits = 32;
const unsigned kSRegSizeInBitsLog2 = 5;
const unsigned kSRegSize = kSRegSizeInBits >> 3;
const unsigned kSRegSizeLog2 = kSRegSizeInBitsLog2 - 3;
const unsigned kDRegSizeInBits = 64;
const unsigned kDRegSizeInBitsLog2 = 6;
const unsigned kDRegSize = kDRegSizeInBits >> 3;
const unsigned kDRegSizeLog2 = kDRegSizeInBitsLog2 - 3;
const int kWRegSizeInBits = 32;
const int kWRegSizeInBitsLog2 = 5;
const int kWRegSize = kWRegSizeInBits >> 3;
const int kWRegSizeLog2 = kWRegSizeInBitsLog2 - 3;
const int kXRegSizeInBits = 64;
const int kXRegSizeInBitsLog2 = 6;
const int kXRegSize = kXRegSizeInBits >> 3;
const int kXRegSizeLog2 = kXRegSizeInBitsLog2 - 3;
const int kSRegSizeInBits = 32;
const int kSRegSizeInBitsLog2 = 5;
const int kSRegSize = kSRegSizeInBits >> 3;
const int kSRegSizeLog2 = kSRegSizeInBitsLog2 - 3;
const int kDRegSizeInBits = 64;
const int kDRegSizeInBitsLog2 = 6;
const int kDRegSize = kDRegSizeInBits >> 3;
const int kDRegSizeLog2 = kDRegSizeInBitsLog2 - 3;
const int64_t kWRegMask = 0x00000000ffffffffL;
const int64_t kXRegMask = 0xffffffffffffffffL;
const int64_t kSRegMask = 0x00000000ffffffffL;
......@@ -86,13 +85,13 @@ const int64_t kXMaxInt = 0x7fffffffffffffffL;
const int64_t kXMinInt = 0x8000000000000000L;
const int32_t kWMaxInt = 0x7fffffff;
const int32_t kWMinInt = 0x80000000;
const unsigned kIp0Code = 16;
const unsigned kIp1Code = 17;
const unsigned kFramePointerRegCode = 29;
const unsigned kLinkRegCode = 30;
const unsigned kZeroRegCode = 31;
const unsigned kJSSPCode = 28;
const unsigned kSPRegInternalCode = 63;
const int kIp0Code = 16;
const int kIp1Code = 17;
const int kFramePointerRegCode = 29;
const int kLinkRegCode = 30;
const int kZeroRegCode = 31;
const int kJSSPCode = 28;
const int kSPRegInternalCode = 63;
const unsigned kRegCodeMask = 0x1f;
const unsigned kShiftAmountWRegMask = 0x1f;
const unsigned kShiftAmountXRegMask = 0x3f;
......
......@@ -209,7 +209,7 @@ void MacroAssembler::Mov(const Register& rd, uint64_t imm) {
// halfword, and movk for subsequent halfwords.
DCHECK((reg_size % 16) == 0);
bool first_mov_done = false;
for (unsigned i = 0; i < (rd.SizeInBits() / 16); i++) {
for (int i = 0; i < (rd.SizeInBits() / 16); i++) {
uint64_t imm16 = (imm >> (16 * i)) & 0xffffL;
if (imm16 != ignored_halfword) {
if (!first_mov_done) {
......
......@@ -8147,7 +8147,7 @@ TEST(zero_dest) {
uint64_t literal_base = 0x0100001000100101UL;
__ Mov(x0, 0);
__ Mov(x1, literal_base);
for (unsigned i = 2; i < x30.code(); i++) {
for (int i = 2; i < x30.code(); i++) {
__ Add(Register::XRegFromCode(i), Register::XRegFromCode(i-1), x1);
}
before.Dump(&masm);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment