Unify ART's various implementations of bit_cast.
ART had several implementations of art::bit_cast:
1. one in runtime/base/casts.h, declared as:
template <class Dest, class Source>
inline Dest bit_cast(const Source& source);
2. another one in runtime/utils.h, declared as:
template<typename U, typename V>
static inline V bit_cast(U in);
3. and a third local version, in runtime/memory_region.h,
similar to the previous one:
template<typename Source, typename Destination>
static Destination MemoryRegion::local_bit_cast(Source in);
This CL removes versions 2. and 3. and changes their callers
to use 1. instead. That version was chosen over the others
as:
- it was the oldest one in the code base; and
- its syntax was closer to the standard C++ cast operators,
as it supports the following use:
bit_cast<Destination>(source)
since `Source' can be deduced from `source'.
Change-Id: I7334fd5d55bf0b8a0c52cb33cfbae6894ff83633
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc
index 561dcb7..787a170 100644
--- a/compiler/optimizing/code_generator.cc
+++ b/compiler/optimizing/code_generator.cc
@@ -628,7 +628,7 @@
++i, DexRegisterLocation::Kind::kConstant, High32Bits(value));
DCHECK_LT(i, environment_size);
} else if (current->IsDoubleConstant()) {
- int64_t value = bit_cast<double, int64_t>(current->AsDoubleConstant()->GetValue());
+ int64_t value = bit_cast<int64_t, double>(current->AsDoubleConstant()->GetValue());
stack_map_stream_.AddDexRegisterEntry(
i, DexRegisterLocation::Kind::kConstant, Low32Bits(value));
stack_map_stream_.AddDexRegisterEntry(
@@ -641,7 +641,7 @@
stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kConstant, 0);
} else {
DCHECK(current->IsFloatConstant()) << current->DebugName();
- int32_t value = bit_cast<float, int32_t>(current->AsFloatConstant()->GetValue());
+ int32_t value = bit_cast<int32_t, float>(current->AsFloatConstant()->GetValue());
stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kConstant, value);
}
break;
diff --git a/compiler/optimizing/code_generator.h b/compiler/optimizing/code_generator.h
index ecaa6f0..07ca6b1 100644
--- a/compiler/optimizing/code_generator.h
+++ b/compiler/optimizing/code_generator.h
@@ -271,7 +271,7 @@
return 0;
} else {
DCHECK(constant->IsFloatConstant());
- return bit_cast<float, int32_t>(constant->AsFloatConstant()->GetValue());
+ return bit_cast<int32_t, float>(constant->AsFloatConstant()->GetValue());
}
}
@@ -281,12 +281,12 @@
} else if (constant->IsNullConstant()) {
return 0;
} else if (constant->IsFloatConstant()) {
- return bit_cast<float, int32_t>(constant->AsFloatConstant()->GetValue());
+ return bit_cast<int32_t, float>(constant->AsFloatConstant()->GetValue());
} else if (constant->IsLongConstant()) {
return constant->AsLongConstant()->GetValue();
} else {
DCHECK(constant->IsDoubleConstant());
- return bit_cast<double, int64_t>(constant->AsDoubleConstant()->GetValue());
+ return bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue());
}
}
diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc
index 02b9b32..e808a12 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -680,7 +680,7 @@
value = constant->AsLongConstant()->GetValue();
} else {
DCHECK(constant->IsDoubleConstant());
- value = bit_cast<double, int64_t>(constant->AsDoubleConstant()->GetValue());
+ value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue());
}
__ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value)));
__ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value)));
@@ -3665,7 +3665,7 @@
}
} else if (constant->IsFloatConstant()) {
float fp_value = constant->AsFloatConstant()->GetValue();
- int32_t value = bit_cast<float, int32_t>(fp_value);
+ int32_t value = bit_cast<int32_t, float>(fp_value);
Immediate imm(value);
if (destination.IsFpuRegister()) {
XmmRegister dest = destination.AsFpuRegister<XmmRegister>();
@@ -3699,7 +3699,7 @@
} else {
DCHECK(constant->IsDoubleConstant());
double dbl_value = constant->AsDoubleConstant()->GetValue();
- int64_t value = bit_cast<double, int64_t>(dbl_value);
+ int64_t value = bit_cast<int64_t, double>(dbl_value);
int32_t low_value = Low32Bits(value);
int32_t high_value = High32Bits(value);
Immediate low(low_value);
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index d09c8f8..b12f57e 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -625,7 +625,7 @@
HConstant* constant = source.GetConstant();
int64_t value = constant->AsLongConstant()->GetValue();
if (constant->IsDoubleConstant()) {
- value = bit_cast<double, int64_t>(constant->AsDoubleConstant()->GetValue());
+ value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue());
} else {
DCHECK(constant->IsLongConstant());
value = constant->AsLongConstant()->GetValue();
@@ -3344,7 +3344,7 @@
}
} else if (constant->IsFloatConstant()) {
float fp_value = constant->AsFloatConstant()->GetValue();
- int32_t value = bit_cast<float, int32_t>(fp_value);
+ int32_t value = bit_cast<int32_t, float>(fp_value);
Immediate imm(value);
if (destination.IsFpuRegister()) {
XmmRegister dest = destination.AsFpuRegister<XmmRegister>();
@@ -3362,7 +3362,7 @@
} else {
DCHECK(constant->IsDoubleConstant()) << constant->DebugName();
double fp_value = constant->AsDoubleConstant()->GetValue();
- int64_t value = bit_cast<double, int64_t>(fp_value);
+ int64_t value = bit_cast<int64_t, double>(fp_value);
Immediate imm(value);
if (destination.IsFpuRegister()) {
XmmRegister dest = destination.AsFpuRegister<XmmRegister>();
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index 07ff8ba..df847aa 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -1875,20 +1875,22 @@
float GetValue() const { return value_; }
bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
- return bit_cast<float, int32_t>(other->AsFloatConstant()->value_) ==
- bit_cast<float, int32_t>(value_);
+ return bit_cast<uint32_t, float>(other->AsFloatConstant()->value_) ==
+ bit_cast<uint32_t, float>(value_);
}
size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); }
bool IsMinusOne() const OVERRIDE {
- return bit_cast<uint32_t>(AsFloatConstant()->GetValue()) == bit_cast<uint32_t>((-1.0f));
+ return bit_cast<uint32_t, float>(AsFloatConstant()->GetValue()) ==
+ bit_cast<uint32_t, float>((-1.0f));
}
bool IsZero() const OVERRIDE {
return AsFloatConstant()->GetValue() == 0.0f;
}
bool IsOne() const OVERRIDE {
- return bit_cast<uint32_t>(AsFloatConstant()->GetValue()) == bit_cast<uint32_t>(1.0f);
+ return bit_cast<uint32_t, float>(AsFloatConstant()->GetValue()) ==
+ bit_cast<uint32_t, float>(1.0f);
}
DECLARE_INSTRUCTION(FloatConstant);
@@ -1906,20 +1908,22 @@
double GetValue() const { return value_; }
bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
- return bit_cast<double, int64_t>(other->AsDoubleConstant()->value_) ==
- bit_cast<double, int64_t>(value_);
+ return bit_cast<uint64_t, double>(other->AsDoubleConstant()->value_) ==
+ bit_cast<uint64_t, double>(value_);
}
size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); }
bool IsMinusOne() const OVERRIDE {
- return bit_cast<uint64_t>(AsDoubleConstant()->GetValue()) == bit_cast<uint64_t>((-1.0));
+ return bit_cast<uint64_t, double>(AsDoubleConstant()->GetValue()) ==
+ bit_cast<uint64_t, double>((-1.0));
}
bool IsZero() const OVERRIDE {
return AsDoubleConstant()->GetValue() == 0.0;
}
bool IsOne() const OVERRIDE {
- return bit_cast<uint64_t>(AsDoubleConstant()->GetValue()) == bit_cast<uint64_t>(1.0);
+ return bit_cast<uint64_t, double>(AsDoubleConstant()->GetValue()) ==
+ bit_cast<uint64_t, double>(1.0);
}
DECLARE_INSTRUCTION(DoubleConstant);
diff --git a/compiler/optimizing/ssa_builder.cc b/compiler/optimizing/ssa_builder.cc
index ba11e90..ae6bf16 100644
--- a/compiler/optimizing/ssa_builder.cc
+++ b/compiler/optimizing/ssa_builder.cc
@@ -359,12 +359,12 @@
if (result == nullptr) {
HGraph* graph = constant->GetBlock()->GetGraph();
ArenaAllocator* allocator = graph->GetArena();
- result = new (allocator) HFloatConstant(bit_cast<int32_t, float>(constant->GetValue()));
+ result = new (allocator) HFloatConstant(bit_cast<float, int32_t>(constant->GetValue()));
constant->GetBlock()->InsertInstructionBefore(result, constant->GetNext());
} else {
// If there is already a constant with the expected type, we know it is
// the floating point equivalent of this constant.
- DCHECK_EQ((bit_cast<float, int32_t>(result->GetValue())), constant->GetValue());
+ DCHECK_EQ((bit_cast<int32_t, float>(result->GetValue())), constant->GetValue());
}
return result;
}
@@ -381,12 +381,12 @@
if (result == nullptr) {
HGraph* graph = constant->GetBlock()->GetGraph();
ArenaAllocator* allocator = graph->GetArena();
- result = new (allocator) HDoubleConstant(bit_cast<int64_t, double>(constant->GetValue()));
+ result = new (allocator) HDoubleConstant(bit_cast<double, int64_t>(constant->GetValue()));
constant->GetBlock()->InsertInstructionBefore(result, constant->GetNext());
} else {
// If there is already a constant with the expected type, we know it is
// the floating point equivalent of this constant.
- DCHECK_EQ((bit_cast<double, int64_t>(result->GetValue())), constant->GetValue());
+ DCHECK_EQ((bit_cast<int64_t, double>(result->GetValue())), constant->GetValue());
}
return result;
}