1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit/shared/CodeGenerator-shared-inl.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,188 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef jit_shared_CodeGenerator_shared_inl_h 1.11 +#define jit_shared_CodeGenerator_shared_inl_h 1.12 + 1.13 +#include "jit/shared/CodeGenerator-shared.h" 1.14 + 1.15 +namespace js { 1.16 +namespace jit { 1.17 + 1.18 +static inline int32_t 1.19 +ToInt32(const LAllocation *a) 1.20 +{ 1.21 + if (a->isConstantValue()) 1.22 + return a->toConstant()->toInt32(); 1.23 + if (a->isConstantIndex()) 1.24 + return a->toConstantIndex()->index(); 1.25 + MOZ_ASSUME_UNREACHABLE("this is not a constant!"); 1.26 +} 1.27 +static inline double 1.28 +ToDouble(const LAllocation *a) 1.29 +{ 1.30 + return a->toConstant()->toNumber(); 1.31 +} 1.32 + 1.33 +static inline Register 1.34 +ToRegister(const LAllocation &a) 1.35 +{ 1.36 + JS_ASSERT(a.isGeneralReg()); 1.37 + return a.toGeneralReg()->reg(); 1.38 +} 1.39 + 1.40 +static inline Register 1.41 +ToRegister(const LAllocation *a) 1.42 +{ 1.43 + return ToRegister(*a); 1.44 +} 1.45 + 1.46 +static inline Register 1.47 +ToRegister(const LDefinition *def) 1.48 +{ 1.49 + return ToRegister(*def->output()); 1.50 +} 1.51 + 1.52 +static inline Register 1.53 +ToTempRegisterOrInvalid(const LDefinition *def) 1.54 +{ 1.55 + if (def->isBogusTemp()) 1.56 + return InvalidReg; 1.57 + return ToRegister(def); 1.58 +} 1.59 + 1.60 +static inline Register 1.61 +ToTempUnboxRegister(const LDefinition *def) 1.62 +{ 1.63 + return ToTempRegisterOrInvalid(def); 1.64 +} 1.65 + 1.66 +static inline Register 1.67 +ToRegisterOrInvalid(const LDefinition *a) 1.68 +{ 1.69 + return a ? ToRegister(a) : InvalidReg; 1.70 +} 1.71 + 1.72 +static inline FloatRegister 1.73 +ToFloatRegister(const LAllocation &a) 1.74 +{ 1.75 + JS_ASSERT(a.isFloatReg()); 1.76 + return a.toFloatReg()->reg(); 1.77 +} 1.78 + 1.79 +static inline FloatRegister 1.80 +ToFloatRegister(const LAllocation *a) 1.81 +{ 1.82 + return ToFloatRegister(*a); 1.83 +} 1.84 + 1.85 +static inline FloatRegister 1.86 +ToFloatRegister(const LDefinition *def) 1.87 +{ 1.88 + return ToFloatRegister(*def->output()); 1.89 +} 1.90 + 1.91 +static inline AnyRegister 1.92 +ToAnyRegister(const LAllocation &a) 1.93 +{ 1.94 + JS_ASSERT(a.isGeneralReg() || a.isFloatReg()); 1.95 + if (a.isGeneralReg()) 1.96 + return AnyRegister(ToRegister(a)); 1.97 + return AnyRegister(ToFloatRegister(a)); 1.98 +} 1.99 + 1.100 +static inline AnyRegister 1.101 +ToAnyRegister(const LAllocation *a) 1.102 +{ 1.103 + return ToAnyRegister(*a); 1.104 +} 1.105 + 1.106 +static inline AnyRegister 1.107 +ToAnyRegister(const LDefinition *def) 1.108 +{ 1.109 + return ToAnyRegister(def->output()); 1.110 +} 1.111 + 1.112 +static inline Int32Key 1.113 +ToInt32Key(const LAllocation *a) 1.114 +{ 1.115 + if (a->isConstant()) 1.116 + return Int32Key(ToInt32(a)); 1.117 + return Int32Key(ToRegister(a)); 1.118 +} 1.119 + 1.120 +static inline ValueOperand 1.121 +GetValueOutput(LInstruction *ins) 1.122 +{ 1.123 +#if defined(JS_NUNBOX32) 1.124 + return ValueOperand(ToRegister(ins->getDef(TYPE_INDEX)), 1.125 + ToRegister(ins->getDef(PAYLOAD_INDEX))); 1.126 +#elif defined(JS_PUNBOX64) 1.127 + return ValueOperand(ToRegister(ins->getDef(0))); 1.128 +#else 1.129 +#error "Unknown" 1.130 +#endif 1.131 +} 1.132 + 1.133 +static inline ValueOperand 1.134 +GetTempValue(const Register &type, const Register &payload) 1.135 +{ 1.136 +#if defined(JS_NUNBOX32) 1.137 + return ValueOperand(type, payload); 1.138 +#elif defined(JS_PUNBOX64) 1.139 + (void)type; 1.140 + return ValueOperand(payload); 1.141 +#else 1.142 +#error "Unknown" 1.143 +#endif 1.144 +} 1.145 + 1.146 +void 1.147 +CodeGeneratorShared::saveLive(LInstruction *ins) 1.148 +{ 1.149 + JS_ASSERT(!ins->isCall()); 1.150 + LSafepoint *safepoint = ins->safepoint(); 1.151 + masm.PushRegsInMask(safepoint->liveRegs()); 1.152 +} 1.153 + 1.154 +void 1.155 +CodeGeneratorShared::restoreLive(LInstruction *ins) 1.156 +{ 1.157 + JS_ASSERT(!ins->isCall()); 1.158 + LSafepoint *safepoint = ins->safepoint(); 1.159 + masm.PopRegsInMask(safepoint->liveRegs()); 1.160 +} 1.161 + 1.162 +void 1.163 +CodeGeneratorShared::restoreLiveIgnore(LInstruction *ins, RegisterSet ignore) 1.164 +{ 1.165 + JS_ASSERT(!ins->isCall()); 1.166 + LSafepoint *safepoint = ins->safepoint(); 1.167 + masm.PopRegsInMaskIgnore(safepoint->liveRegs(), ignore); 1.168 +} 1.169 + 1.170 +void 1.171 +CodeGeneratorShared::saveLiveVolatile(LInstruction *ins) 1.172 +{ 1.173 + JS_ASSERT(!ins->isCall()); 1.174 + LSafepoint *safepoint = ins->safepoint(); 1.175 + RegisterSet regs = RegisterSet::Intersect(safepoint->liveRegs(), RegisterSet::Volatile()); 1.176 + masm.PushRegsInMask(regs); 1.177 +} 1.178 + 1.179 +void 1.180 +CodeGeneratorShared::restoreLiveVolatile(LInstruction *ins) 1.181 +{ 1.182 + JS_ASSERT(!ins->isCall()); 1.183 + LSafepoint *safepoint = ins->safepoint(); 1.184 + RegisterSet regs = RegisterSet::Intersect(safepoint->liveRegs(), RegisterSet::Volatile()); 1.185 + masm.PopRegsInMask(regs); 1.186 +} 1.187 + 1.188 +} // ion 1.189 +} // js 1.190 + 1.191 +#endif /* jit_shared_CodeGenerator_shared_inl_h */