michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef jit_shared_CodeGenerator_shared_inl_h michael@0: #define jit_shared_CodeGenerator_shared_inl_h michael@0: michael@0: #include "jit/shared/CodeGenerator-shared.h" michael@0: michael@0: namespace js { michael@0: namespace jit { michael@0: michael@0: static inline int32_t michael@0: ToInt32(const LAllocation *a) michael@0: { michael@0: if (a->isConstantValue()) michael@0: return a->toConstant()->toInt32(); michael@0: if (a->isConstantIndex()) michael@0: return a->toConstantIndex()->index(); michael@0: MOZ_ASSUME_UNREACHABLE("this is not a constant!"); michael@0: } michael@0: static inline double michael@0: ToDouble(const LAllocation *a) michael@0: { michael@0: return a->toConstant()->toNumber(); michael@0: } michael@0: michael@0: static inline Register michael@0: ToRegister(const LAllocation &a) michael@0: { michael@0: JS_ASSERT(a.isGeneralReg()); michael@0: return a.toGeneralReg()->reg(); michael@0: } michael@0: michael@0: static inline Register michael@0: ToRegister(const LAllocation *a) michael@0: { michael@0: return ToRegister(*a); michael@0: } michael@0: michael@0: static inline Register michael@0: ToRegister(const LDefinition *def) michael@0: { michael@0: return ToRegister(*def->output()); michael@0: } michael@0: michael@0: static inline Register michael@0: ToTempRegisterOrInvalid(const LDefinition *def) michael@0: { michael@0: if (def->isBogusTemp()) michael@0: return InvalidReg; michael@0: return ToRegister(def); michael@0: } michael@0: michael@0: static inline Register michael@0: ToTempUnboxRegister(const LDefinition *def) michael@0: { michael@0: return ToTempRegisterOrInvalid(def); michael@0: } michael@0: michael@0: static inline Register michael@0: ToRegisterOrInvalid(const LDefinition *a) michael@0: { michael@0: return a ? ToRegister(a) : InvalidReg; michael@0: } michael@0: michael@0: static inline FloatRegister michael@0: ToFloatRegister(const LAllocation &a) michael@0: { michael@0: JS_ASSERT(a.isFloatReg()); michael@0: return a.toFloatReg()->reg(); michael@0: } michael@0: michael@0: static inline FloatRegister michael@0: ToFloatRegister(const LAllocation *a) michael@0: { michael@0: return ToFloatRegister(*a); michael@0: } michael@0: michael@0: static inline FloatRegister michael@0: ToFloatRegister(const LDefinition *def) michael@0: { michael@0: return ToFloatRegister(*def->output()); michael@0: } michael@0: michael@0: static inline AnyRegister michael@0: ToAnyRegister(const LAllocation &a) michael@0: { michael@0: JS_ASSERT(a.isGeneralReg() || a.isFloatReg()); michael@0: if (a.isGeneralReg()) michael@0: return AnyRegister(ToRegister(a)); michael@0: return AnyRegister(ToFloatRegister(a)); michael@0: } michael@0: michael@0: static inline AnyRegister michael@0: ToAnyRegister(const LAllocation *a) michael@0: { michael@0: return ToAnyRegister(*a); michael@0: } michael@0: michael@0: static inline AnyRegister michael@0: ToAnyRegister(const LDefinition *def) michael@0: { michael@0: return ToAnyRegister(def->output()); michael@0: } michael@0: michael@0: static inline Int32Key michael@0: ToInt32Key(const LAllocation *a) michael@0: { michael@0: if (a->isConstant()) michael@0: return Int32Key(ToInt32(a)); michael@0: return Int32Key(ToRegister(a)); michael@0: } michael@0: michael@0: static inline ValueOperand michael@0: GetValueOutput(LInstruction *ins) michael@0: { michael@0: #if defined(JS_NUNBOX32) michael@0: return ValueOperand(ToRegister(ins->getDef(TYPE_INDEX)), michael@0: ToRegister(ins->getDef(PAYLOAD_INDEX))); michael@0: #elif defined(JS_PUNBOX64) michael@0: return ValueOperand(ToRegister(ins->getDef(0))); michael@0: #else michael@0: #error "Unknown" michael@0: #endif michael@0: } michael@0: michael@0: static inline ValueOperand michael@0: GetTempValue(const Register &type, const Register &payload) michael@0: { michael@0: #if defined(JS_NUNBOX32) michael@0: return ValueOperand(type, payload); michael@0: #elif defined(JS_PUNBOX64) michael@0: (void)type; michael@0: return ValueOperand(payload); michael@0: #else michael@0: #error "Unknown" michael@0: #endif michael@0: } michael@0: michael@0: void michael@0: CodeGeneratorShared::saveLive(LInstruction *ins) michael@0: { michael@0: JS_ASSERT(!ins->isCall()); michael@0: LSafepoint *safepoint = ins->safepoint(); michael@0: masm.PushRegsInMask(safepoint->liveRegs()); michael@0: } michael@0: michael@0: void michael@0: CodeGeneratorShared::restoreLive(LInstruction *ins) michael@0: { michael@0: JS_ASSERT(!ins->isCall()); michael@0: LSafepoint *safepoint = ins->safepoint(); michael@0: masm.PopRegsInMask(safepoint->liveRegs()); michael@0: } michael@0: michael@0: void michael@0: CodeGeneratorShared::restoreLiveIgnore(LInstruction *ins, RegisterSet ignore) michael@0: { michael@0: JS_ASSERT(!ins->isCall()); michael@0: LSafepoint *safepoint = ins->safepoint(); michael@0: masm.PopRegsInMaskIgnore(safepoint->liveRegs(), ignore); michael@0: } michael@0: michael@0: void michael@0: CodeGeneratorShared::saveLiveVolatile(LInstruction *ins) michael@0: { michael@0: JS_ASSERT(!ins->isCall()); michael@0: LSafepoint *safepoint = ins->safepoint(); michael@0: RegisterSet regs = RegisterSet::Intersect(safepoint->liveRegs(), RegisterSet::Volatile()); michael@0: masm.PushRegsInMask(regs); michael@0: } michael@0: michael@0: void michael@0: CodeGeneratorShared::restoreLiveVolatile(LInstruction *ins) michael@0: { michael@0: JS_ASSERT(!ins->isCall()); michael@0: LSafepoint *safepoint = ins->safepoint(); michael@0: RegisterSet regs = RegisterSet::Intersect(safepoint->liveRegs(), RegisterSet::Volatile()); michael@0: masm.PopRegsInMask(regs); michael@0: } michael@0: michael@0: } // ion michael@0: } // js michael@0: michael@0: #endif /* jit_shared_CodeGenerator_shared_inl_h */