| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#include "jit/x86-shared/Architecture-x86-shared.h" |
| 8 |
#if !defined(JS_CODEGEN_X86) && !defined(JS_CODEGEN_X64) |
| 9 |
# error "Wrong architecture. Only x86 and x64 should build this file!" |
| 10 |
#endif |
| 11 |
|
| 12 |
#include <iterator> |
| 13 |
|
| 14 |
#include "jit/RegisterSets.h" |
| 15 |
|
| 16 |
const char* js::jit::FloatRegister::name() const { |
| 17 |
static const char* const names[] = { |
| 18 |
|
| 19 |
#ifdef JS_CODEGEN_X64 |
| 20 |
# define FLOAT_REGS_(TYPE) \ |
| 21 |
"%xmm0" TYPE, "%xmm1" TYPE, "%xmm2" TYPE, "%xmm3" TYPE, "%xmm4" TYPE, \ |
| 22 |
"%xmm5" TYPE, "%xmm6" TYPE, "%xmm7" TYPE, "%xmm8" TYPE, "%xmm9" TYPE, \ |
| 23 |
"%xmm10" TYPE, "%xmm11" TYPE, "%xmm12" TYPE, "%xmm13" TYPE, \ |
| 24 |
"%xmm14" TYPE, "%xmm15" TYPE |
| 25 |
#else |
| 26 |
# define FLOAT_REGS_(TYPE) \ |
| 27 |
"%xmm0" TYPE, "%xmm1" TYPE, "%xmm2" TYPE, "%xmm3" TYPE, "%xmm4" TYPE, \ |
| 28 |
"%xmm5" TYPE, "%xmm6" TYPE, "%xmm7" TYPE |
| 29 |
#endif |
| 30 |
|
| 31 |
// These should be enumerated in the same order as in |
| 32 |
// FloatRegisters::ContentType. |
| 33 |
FLOAT_REGS_(".s"), FLOAT_REGS_(".d"), FLOAT_REGS_(".i4"), |
| 34 |
FLOAT_REGS_(".s4") |
| 35 |
#undef FLOAT_REGS_ |
| 36 |
|
| 37 |
}; |
| 38 |
MOZ_ASSERT(size_t(code()) < std::size(names)); |
| 39 |
return names[size_t(code())]; |
| 40 |
} |
| 41 |
|
| 42 |
js::jit::FloatRegisterSet js::jit::FloatRegister::ReduceSetForPush( |
| 43 |
const FloatRegisterSet& s) { |
| 44 |
SetType bits = s.bits(); |
| 45 |
|
| 46 |
// Ignore all SIMD register, if not supported. |
| 47 |
#ifndef ENABLE_WASM_SIMD |
| 48 |
bits &= Codes::AllPhysMask * Codes::SpreadScalar; |
| 49 |
#endif |
| 50 |
|
| 51 |
// Exclude registers which are already pushed with a larger type. High bits |
| 52 |
// are associated with larger register types. Thus we keep the set of |
| 53 |
// registers which are not included in larger type. |
| 54 |
bits &= ~(bits >> (1 * Codes::TotalPhys)); |
| 55 |
bits &= ~(bits >> (2 * Codes::TotalPhys)); |
| 56 |
bits &= ~(bits >> (3 * Codes::TotalPhys)); |
| 57 |
|
| 58 |
return FloatRegisterSet(bits); |
| 59 |
} |
| 60 |
|
| 61 |
uint32_t js::jit::FloatRegister::GetPushSizeInBytes(const FloatRegisterSet& s) { |
| 62 |
SetType all = s.bits(); |
| 63 |
SetType set128b = (all >> (uint32_t(Codes::Simd128) * Codes::TotalPhys)) & |
| 64 |
Codes::AllPhysMask; |
| 65 |
SetType doubleSet = (all >> (uint32_t(Codes::Double) * Codes::TotalPhys)) & |
| 66 |
Codes::AllPhysMask; |
| 67 |
SetType singleSet = (all >> (uint32_t(Codes::Single) * Codes::TotalPhys)) & |
| 68 |
Codes::AllPhysMask; |
| 69 |
|
| 70 |
// PushRegsInMask pushes the largest register first, and thus avoids pushing |
| 71 |
// aliased registers. So we have to filter out the physical registers which |
| 72 |
// are already pushed as part of larger registers. |
| 73 |
SetType set64b = doubleSet & ~set128b; |
| 74 |
SetType set32b = singleSet & ~set64b & ~set128b; |
| 75 |
|
| 76 |
static_assert(Codes::AllPhysMask <= 0xffff, |
| 77 |
"We can safely use CountPopulation32"); |
| 78 |
uint32_t count32b = mozilla::CountPopulation32(set32b); |
| 79 |
|
| 80 |
#if defined(JS_CODEGEN_X64) |
| 81 |
// If we have an odd number of 32 bits values, then we increase the size to |
| 82 |
// keep the stack aligned on 8 bytes. Note: Keep in sync with |
| 83 |
// PushRegsInMask, and PopRegsInMaskIgnore. |
| 84 |
count32b += count32b & 1; |
| 85 |
#endif |
| 86 |
|
| 87 |
return mozilla::CountPopulation32(set128b) * (4 * sizeof(int32_t)) + |
| 88 |
mozilla::CountPopulation32(set64b) * sizeof(double) + |
| 89 |
count32b * sizeof(float); |
| 90 |
} |
| 91 |
uint32_t js::jit::FloatRegister::getRegisterDumpOffsetInBytes() { |
| 92 |
return uint32_t(encoding()) * sizeof(FloatRegisters::RegisterContent); |
| 93 |
} |