#pragma once
#include "MacroAssembler.h"
#include <wtf/PrintStream.h>
namespace JSC {
typedef MacroAssembler::FPRegisterID FPRReg;
#define InvalidFPRReg ((::JSC::FPRReg)-1)
#if ENABLE(JIT)
#if CPU(X86) || CPU(X86_64)
class FPRInfo {
public:
typedef FPRReg RegisterType;
static const unsigned numberOfRegisters = 6;
static const unsigned numberOfArgumentRegisters = 8;
static const FPRReg fpRegT0 = X86Registers::xmm0;
static const FPRReg fpRegT1 = X86Registers::xmm1;
static const FPRReg fpRegT2 = X86Registers::xmm2;
static const FPRReg fpRegT3 = X86Registers::xmm3;
static const FPRReg fpRegT4 = X86Registers::xmm4;
static const FPRReg fpRegT5 = X86Registers::xmm5;
#if CPU(X86_64)
static const FPRReg argumentFPR0 = X86Registers::xmm0; static const FPRReg argumentFPR1 = X86Registers::xmm1; static const FPRReg argumentFPR2 = X86Registers::xmm2; static const FPRReg argumentFPR3 = X86Registers::xmm3; static const FPRReg argumentFPR4 = X86Registers::xmm4; static const FPRReg argumentFPR5 = X86Registers::xmm5; static const FPRReg argumentFPR6 = X86Registers::xmm6;
static const FPRReg argumentFPR7 = X86Registers::xmm7;
#endif
static const FPRReg returnValueFPR = X86Registers::xmm0;
COMPILE_ASSERT(X86Registers::xmm0 == 0, xmm0_is_0);
COMPILE_ASSERT(X86Registers::xmm1 == 1, xmm1_is_1);
COMPILE_ASSERT(X86Registers::xmm2 == 2, xmm2_is_2);
COMPILE_ASSERT(X86Registers::xmm3 == 3, xmm3_is_3);
COMPILE_ASSERT(X86Registers::xmm4 == 4, xmm4_is_4);
COMPILE_ASSERT(X86Registers::xmm5 == 5, xmm5_is_5);
static FPRReg toRegister(unsigned index)
{
return (FPRReg)index;
}
static unsigned toIndex(FPRReg reg)
{
unsigned result = (unsigned)reg;
if (result >= numberOfRegisters)
return InvalidIndex;
return result;
}
static FPRReg toArgumentRegister(unsigned index)
{
return (FPRReg)index;
}
static const char* debugName(FPRReg reg)
{
ASSERT(reg != InvalidFPRReg);
return MacroAssembler::fprName(reg);
}
static const unsigned InvalidIndex = 0xffffffff;
};
#endif // CPU(X86) || CPU(X86_64)
#if CPU(ARM)
class FPRInfo {
public:
typedef FPRReg RegisterType;
static const unsigned numberOfRegisters = 6;
static const FPRReg fpRegT0 = ARMRegisters::d0;
static const FPRReg fpRegT1 = ARMRegisters::d1;
static const FPRReg fpRegT2 = ARMRegisters::d2;
static const FPRReg fpRegT3 = ARMRegisters::d3;
static const FPRReg fpRegT4 = ARMRegisters::d4;
static const FPRReg fpRegT5 = ARMRegisters::d5;
static const FPRReg returnValueFPR = ARMRegisters::d0;
#if CPU(ARM_HARDFP)
static const FPRReg argumentFPR0 = ARMRegisters::d0; static const FPRReg argumentFPR1 = ARMRegisters::d1; #endif
COMPILE_ASSERT(ARMRegisters::d0 == 0, d0_is_0);
COMPILE_ASSERT(ARMRegisters::d1 == 1, d1_is_1);
COMPILE_ASSERT(ARMRegisters::d2 == 2, d2_is_2);
COMPILE_ASSERT(ARMRegisters::d3 == 3, d3_is_3);
COMPILE_ASSERT(ARMRegisters::d4 == 4, d4_is_4);
COMPILE_ASSERT(ARMRegisters::d5 == 5, d5_is_5);
static FPRReg toRegister(unsigned index)
{
return (FPRReg)index;
}
static unsigned toIndex(FPRReg reg)
{
return (unsigned)reg;
}
static const char* debugName(FPRReg reg)
{
ASSERT(reg != InvalidFPRReg);
return MacroAssembler::fprName(reg);
}
static const unsigned InvalidIndex = 0xffffffff;
};
#endif // CPU(ARM)
#if CPU(ARM64)
class FPRInfo {
public:
typedef FPRReg RegisterType;
static const unsigned numberOfRegisters = 23;
static const unsigned numberOfArgumentRegisters = 8;
static const FPRReg fpRegT0 = ARM64Registers::q0;
static const FPRReg fpRegT1 = ARM64Registers::q1;
static const FPRReg fpRegT2 = ARM64Registers::q2;
static const FPRReg fpRegT3 = ARM64Registers::q3;
static const FPRReg fpRegT4 = ARM64Registers::q4;
static const FPRReg fpRegT5 = ARM64Registers::q5;
static const FPRReg fpRegT6 = ARM64Registers::q6;
static const FPRReg fpRegT7 = ARM64Registers::q7;
static const FPRReg fpRegT8 = ARM64Registers::q16;
static const FPRReg fpRegT9 = ARM64Registers::q17;
static const FPRReg fpRegT10 = ARM64Registers::q18;
static const FPRReg fpRegT11 = ARM64Registers::q19;
static const FPRReg fpRegT12 = ARM64Registers::q20;
static const FPRReg fpRegT13 = ARM64Registers::q21;
static const FPRReg fpRegT14 = ARM64Registers::q22;
static const FPRReg fpRegT15 = ARM64Registers::q23;
static const FPRReg fpRegT16 = ARM64Registers::q24;
static const FPRReg fpRegT17 = ARM64Registers::q25;
static const FPRReg fpRegT18 = ARM64Registers::q26;
static const FPRReg fpRegT19 = ARM64Registers::q27;
static const FPRReg fpRegT20 = ARM64Registers::q28;
static const FPRReg fpRegT21 = ARM64Registers::q29;
static const FPRReg fpRegT22 = ARM64Registers::q30;
static const FPRReg fpRegCS0 = ARM64Registers::q8;
static const FPRReg fpRegCS1 = ARM64Registers::q9;
static const FPRReg fpRegCS2 = ARM64Registers::q10;
static const FPRReg fpRegCS3 = ARM64Registers::q11;
static const FPRReg fpRegCS4 = ARM64Registers::q12;
static const FPRReg fpRegCS5 = ARM64Registers::q13;
static const FPRReg fpRegCS6 = ARM64Registers::q14;
static const FPRReg fpRegCS7 = ARM64Registers::q15;
static const FPRReg argumentFPR0 = ARM64Registers::q0; static const FPRReg argumentFPR1 = ARM64Registers::q1; static const FPRReg argumentFPR2 = ARM64Registers::q2; static const FPRReg argumentFPR3 = ARM64Registers::q3; static const FPRReg argumentFPR4 = ARM64Registers::q4; static const FPRReg argumentFPR5 = ARM64Registers::q5; static const FPRReg argumentFPR6 = ARM64Registers::q6; static const FPRReg argumentFPR7 = ARM64Registers::q7;
static const FPRReg returnValueFPR = ARM64Registers::q0;
static FPRReg toRegister(unsigned index)
{
ASSERT(index < numberOfRegisters);
static const FPRReg registerForIndex[numberOfRegisters] = {
fpRegT0, fpRegT1, fpRegT2, fpRegT3, fpRegT4, fpRegT5, fpRegT6, fpRegT7,
fpRegT8, fpRegT9, fpRegT10, fpRegT11, fpRegT12, fpRegT13, fpRegT14, fpRegT15,
fpRegT16, fpRegT17, fpRegT18, fpRegT19, fpRegT20, fpRegT21, fpRegT22
};
return registerForIndex[index];
}
static unsigned toIndex(FPRReg reg)
{
ASSERT(reg != InvalidFPRReg);
ASSERT(static_cast<int>(reg) < 32);
static const unsigned indexForRegister[32] = {
0, 1, 2, 3, 4, 5, 6, 7,
InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, InvalidIndex
};
unsigned result = indexForRegister[reg];
return result;
}
static FPRReg toArgumentRegister(unsigned index)
{
ASSERT(index < 8);
return static_cast<FPRReg>(index);
}
static const char* debugName(FPRReg reg)
{
ASSERT(reg != InvalidFPRReg);
return MacroAssembler::fprName(reg);
}
static const unsigned InvalidIndex = 0xffffffff;
};
#endif // CPU(ARM64)
#if CPU(MIPS)
class FPRInfo {
public:
typedef FPRReg RegisterType;
static const unsigned numberOfRegisters = 7;
static const FPRReg fpRegT0 = MIPSRegisters::f0;
static const FPRReg fpRegT1 = MIPSRegisters::f2;
static const FPRReg fpRegT2 = MIPSRegisters::f4;
static const FPRReg fpRegT3 = MIPSRegisters::f6;
static const FPRReg fpRegT4 = MIPSRegisters::f8;
static const FPRReg fpRegT5 = MIPSRegisters::f10;
static const FPRReg fpRegT6 = MIPSRegisters::f18;
static const FPRReg returnValueFPR = MIPSRegisters::f0;
static const FPRReg argumentFPR0 = MIPSRegisters::f12;
static const FPRReg argumentFPR1 = MIPSRegisters::f14;
static FPRReg toRegister(unsigned index)
{
static const FPRReg registerForIndex[numberOfRegisters] = {
fpRegT0, fpRegT1, fpRegT2, fpRegT3, fpRegT4, fpRegT5, fpRegT6 };
ASSERT(index < numberOfRegisters);
return registerForIndex[index];
}
static unsigned toIndex(FPRReg reg)
{
ASSERT(reg != InvalidFPRReg);
ASSERT(reg < 20);
static const unsigned indexForRegister[20] = {
0, InvalidIndex, 1, InvalidIndex,
2, InvalidIndex, 3, InvalidIndex,
4, InvalidIndex, 5, InvalidIndex,
InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex,
InvalidIndex, InvalidIndex, 6, InvalidIndex,
};
unsigned result = indexForRegister[reg];
return result;
}
static const char* debugName(FPRReg reg)
{
ASSERT(reg != InvalidFPRReg);
return MacroAssembler::fprName(reg);
}
static const unsigned InvalidIndex = 0xffffffff;
};
#endif // CPU(MIPS)
#endif // ENABLE(JIT)
}
namespace WTF {
inline void printInternal(PrintStream& out, JSC::FPRReg reg)
{
#if ENABLE(JIT)
out.print("%", JSC::FPRInfo::debugName(reg));
#else
out.printf("%%fr%d", reg);
#endif
}
}