Commit fb82adde authored by dcarney@chromium.org's avatar dcarney@chromium.org

templatize operand constructors

R=jochen@chromium.org

BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19441 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 60c08a8b
......@@ -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);
}
......
......@@ -247,13 +247,7 @@ bool AreSameSizeAndType(const CPURegister& reg1, const CPURegister& reg2,
}
Operand::Operand(const ExternalReference& f)
: immediate_(reinterpret_cast<intptr_t>(f.address())),
reg_(NoReg),
rmode_(RelocInfo::EXTERNAL_REFERENCE) {}
Operand::Operand(Handle<Object> handle) : reg_(NoReg) {
void Operand::initialize_handle(Handle<Object> handle) {
AllowDeferredHandleDereference using_raw_address;
// Verify all Objects referred by code are NOT in new space.
......
......@@ -570,23 +570,6 @@ class Operand {
// TODO(all): If necessary, study more in details which methods
// TODO(all): should be inlined or not.
public:
// #<immediate>
// where <immediate> is int64_t.
// GCC complains about ambiguous aliasing if we don't explicitly declare the
// variants.
// The simple literal-value wrappers are allowed to be implicit constructors
// because Operand is a wrapper class that doesn't normally perform any type
// conversion.
inline Operand(int64_t immediate,
RelocInfo::Mode rmode = RelocInfo::NONE64); // NOLINT(runtime/explicit)
inline Operand(uint64_t immediate,
RelocInfo::Mode rmode = RelocInfo::NONE64); // NOLINT(runtime/explicit)
inline Operand(int32_t immediate,
RelocInfo::Mode rmode = RelocInfo::NONE32); // NOLINT(runtime/explicit)
inline Operand(uint32_t immediate,
RelocInfo::Mode rmode = RelocInfo::NONE32); // NOLINT(runtime/explicit)
// rm, {<shift> {#<shift_amount>}}
// where <shift> is one of {LSL, LSR, ASR, ROR}.
// <shift_amount> is uint6_t.
......@@ -603,9 +586,16 @@ class Operand {
Extend extend,
unsigned shift_amount = 0);
inline explicit Operand(Smi* value);
explicit Operand(const ExternalReference& f);
explicit Operand(Handle<Object> handle);
template<typename T>
inline explicit Operand(Handle<T> handle);
// Implicit constructor for all int types, ExternalReference, and Smi.
template<typename T>
inline Operand(T t); // NOLINT(runtime/explicit)
// Implicit constructor for int types.
template<typename int_t>
inline Operand(int_t t, RelocInfo::Mode rmode);
inline bool IsImmediate() const;
inline bool IsShiftedRegister() const;
......@@ -632,6 +622,7 @@ class Operand {
inline static Operand UntagSmiAndScale(Register smi, int scale);
private:
void initialize_handle(Handle<Object> value);
int64_t immediate_;
Register reg_;
Shift shift_;
......
......@@ -1027,7 +1027,7 @@ void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
// 3a. Patch the first argument if necessary when calling a function.
Label shift_arguments;
__ Mov(call_type, call_type_JS_func);
__ Mov(call_type, static_cast<int>(call_type_JS_func));
{ Label convert_to_object, use_global_receiver, patch_receiver;
// Change context eagerly in case we need the global receiver.
__ Ldr(cp, FieldMemOperand(function, JSFunction::kContextOffset));
......@@ -1078,7 +1078,7 @@ void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
// Restore the function and flag in the registers.
__ Peek(function, Operand(argc, LSL, kXRegSizeInBytesLog2));
__ Mov(call_type, call_type_JS_func);
__ Mov(call_type, static_cast<int>(call_type_JS_func));
__ B(&patch_receiver);
__ Bind(&use_global_receiver);
......@@ -1096,11 +1096,11 @@ void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
// 3b. Check for function proxy.
__ Bind(&slow);
__ Mov(call_type, call_type_func_proxy);
__ Mov(call_type, static_cast<int>(call_type_func_proxy));
__ Cmp(receiver_type, JS_FUNCTION_PROXY_TYPE);
__ B(eq, &shift_arguments);
__ Bind(&non_function);
__ Mov(call_type, call_type_non_func);
__ Mov(call_type, static_cast<int>(call_type_non_func));
// 3c. Patch the first argument when calling a non-function. The
// CALL_NON_FUNCTION builtin expects the non-function callee as
......@@ -1138,7 +1138,7 @@ void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
__ Cbz(call_type, &js_function);
// Expected number of arguments is 0 for CALL_NON_FUNCTION.
__ Mov(x2, 0);
__ Cmp(call_type, call_type_func_proxy);
__ Cmp(call_type, static_cast<int>(call_type_func_proxy));
__ B(ne, &non_proxy);
__ Push(function); // Re-add proxy object as additional argument.
......
......@@ -2539,7 +2539,7 @@ void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) {
Register the_hole = x13;
Label parameters_loop, parameters_test;
__ Mov(loop_count, mapped_params);
__ Add(index, param_count, Context::MIN_CONTEXT_SLOTS);
__ Add(index, param_count, static_cast<int>(Context::MIN_CONTEXT_SLOTS));
__ Sub(index, index, mapped_params);
__ SmiTag(index);
__ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
......
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