Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(869)

Unified Diff: src/a64/assembler-a64-inl.h

Issue 170403003: templatize operand constructors (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/a64/assembler-a64.cc ('k') | src/a64/builtins-a64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/a64/assembler-a64-inl.h
diff --git a/src/a64/assembler-a64-inl.h b/src/a64/assembler-a64-inl.h
index ebd3ec8b4d919b4e2212aefa5aa5fe919dd6ebc8..09e23ea99743b1e0f49150331a80f1e8b0424872 100644
--- a/src/a64/assembler-a64-inl.h
+++ b/src/a64/assembler-a64-inl.h
@@ -264,16 +264,65 @@ inline FPRegister CPURegister::D() const {
// Operand.
-#define DECLARE_INT_OPERAND_CONSTRUCTOR(type) \
-Operand::Operand(type immediate, RelocInfo::Mode rmode) \
- : immediate_(immediate), \
- reg_(NoReg), \
- rmode_(rmode) {}
-DECLARE_INT_OPERAND_CONSTRUCTOR(int64_t)
-DECLARE_INT_OPERAND_CONSTRUCTOR(uint64_t)
-DECLARE_INT_OPERAND_CONSTRUCTOR(int32_t) // NOLINT(readability/casting)
-DECLARE_INT_OPERAND_CONSTRUCTOR(uint32_t)
-#undef DECLARE_INT_OPERAND_CONSTRUCTOR
+template<typename T>
+Operand::Operand(Handle<T> value) : reg_(NoReg) {
+ initialize_handle(value);
+}
+
+
+// Default initializer is for int types
+template<typename int_t>
+struct OperandInitializer {
+ static const bool kIsIntType = true;
+ static inline RelocInfo::Mode rmode_for(int_t) {
+ return sizeof(int_t) == 8 ? RelocInfo::NONE64 : RelocInfo::NONE32;
+ }
+ static inline int64_t immediate_for(int_t t) {
+ STATIC_ASSERT(sizeof(int_t) <= 8);
+ return t;
+ }
+};
+
+
+template<>
+struct OperandInitializer<Smi*> {
+ static const bool kIsIntType = false;
+ static inline RelocInfo::Mode rmode_for(Smi* t) {
+ return RelocInfo::NONE64;
+ }
+ static inline int64_t immediate_for(Smi* t) {;
+ return reinterpret_cast<int64_t>(t);
+ }
+};
+
+
+template<>
+struct OperandInitializer<ExternalReference> {
+ static const bool kIsIntType = false;
+ static inline RelocInfo::Mode rmode_for(ExternalReference t) {
+ return RelocInfo::EXTERNAL_REFERENCE;
+ }
+ static inline int64_t immediate_for(ExternalReference t) {;
+ return reinterpret_cast<int64_t>(t.address());
+ }
+};
+
+
+template<typename T>
+Operand::Operand(T t)
+ : immediate_(OperandInitializer<T>::immediate_for(t)),
+ reg_(NoReg),
+ rmode_(OperandInitializer<T>::rmode_for(t)) {}
+
+
+template<typename T>
+Operand::Operand(T t, RelocInfo::Mode rmode)
+ : immediate_(OperandInitializer<T>::immediate_for(t)),
+ reg_(NoReg),
+ rmode_(rmode) {
+ STATIC_ASSERT(OperandInitializer<T>::kIsIntType);
+}
+
Operand::Operand(Register reg, Shift shift, unsigned shift_amount)
: reg_(reg),
@@ -302,12 +351,6 @@ Operand::Operand(Register reg, Extend extend, unsigned shift_amount)
}
-Operand::Operand(Smi* value)
- : immediate_(reinterpret_cast<intptr_t>(value)),
- reg_(NoReg),
- rmode_(RelocInfo::NONE64) {}
-
-
bool Operand::IsImmediate() const {
return reg_.Is(NoReg);
}
« no previous file with comments | « src/a64/assembler-a64.cc ('k') | src/a64/builtins-a64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698