Skip to content

Commit

Permalink
Merge pull request #2027 from lioncash/vfmul
Browse files Browse the repository at this point in the history
IR: Handle 256-bit VFMul
  • Loading branch information
Sonicadvance1 authored Sep 27, 2022
2 parents 3f8b872 + fe9aa68 commit 4472265
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 45 deletions.
13 changes: 8 additions & 5 deletions External/FEXCore/Source/Interface/Core/Interpreter/VectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,20 +523,23 @@ DEF_OP(VFSub) {
}

DEF_OP(VFMul) {
auto Op = IROp->C<IR::IROp_VFMul>();
const auto Op = IROp->C<IR::IROp_VFMul>();
const uint8_t OpSize = IROp->Size;

void *Src1 = GetSrc<void*>(Data->SSAData, Op->Vector1);
void *Src2 = GetSrc<void*>(Data->SSAData, Op->Vector2);
uint8_t Tmp[16];
uint8_t Tmp[Core::CPUState::XMM_AVX_REG_SIZE];

const uint8_t Elements = OpSize / Op->Header.ElementSize;
const uint8_t ElementSize = Op->Header.ElementSize;
const uint8_t Elements = OpSize / ElementSize;

const auto Func = [](auto a, auto b) { return a * b; };
switch (Op->Header.ElementSize) {
switch (ElementSize) {
DO_VECTOR_OP(4, float, Func)
DO_VECTOR_OP(8, double, Func)
default: LOGMAN_MSG_A_FMT("Unknown Element Size: {}", Op->Header.ElementSize); break;
default:
LOGMAN_MSG_A_FMT("Unknown Element Size: {}", ElementSize);
break;
}
memcpy(GDP, Tmp, OpSize);
}
Expand Down
79 changes: 58 additions & 21 deletions External/FEXCore/Source/Interface/Core/JIT/Arm64/VectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,34 +1023,71 @@ DEF_OP(VFSub) {
}

DEF_OP(VFMul) {
auto Op = IROp->C<IR::IROp_VFMul>();
const uint8_t OpSize = IROp->Size;
if (Op->Header.ElementSize == OpSize) {
// Scalar
switch (Op->Header.ElementSize) {
const auto Op = IROp->C<IR::IROp_VFMul>();
const auto OpSize = IROp->Size;

const auto ElementSize = Op->Header.ElementSize;
const auto IsScalar = ElementSize == OpSize;

const auto Dst = GetDst(Node);
const auto Vector1 = GetSrc(Op->Vector1.ID());
const auto Vector2 = GetSrc(Op->Vector2.ID());

if (HostSupportsSVE && !IsScalar) {
switch (ElementSize) {
case 2: {
fmul(Dst.Z().VnH(), Vector1.Z().VnH(), Vector2.Z().VnH());
break;
}
case 4: {
fmul(GetDst(Node).S(), GetSrc(Op->Vector1.ID()).S(), GetSrc(Op->Vector2.ID()).S());
break;
fmul(Dst.Z().VnS(), Vector1.Z().VnS(), Vector2.Z().VnS());
break;
}
case 8: {
fmul(GetDst(Node).D(), GetSrc(Op->Vector1.ID()).D(), GetSrc(Op->Vector2.ID()).D());
break;
fmul(Dst.Z().VnD(), Vector1.Z().VnD(), Vector2.Z().VnD());
break;
}
default: LOGMAN_MSG_A_FMT("Unknown Element Size: {}", Op->Header.ElementSize); break;
default:
LOGMAN_MSG_A_FMT("Unknown Element Size: {}", ElementSize);
break;
}
}
else {
// Vector
switch (Op->Header.ElementSize) {
case 4: {
fmul(GetDst(Node).V4S(), GetSrc(Op->Vector1.ID()).V4S(), GetSrc(Op->Vector2.ID()).V4S());
break;
} else {
if (IsScalar) {
switch (ElementSize) {
case 2: {
fmul(Dst.H(), Vector1.H(), Vector2.H());
break;
}
case 4: {
fmul(Dst.S(), Vector1.S(), Vector2.S());
break;
}
case 8: {
fmul(Dst.D(), Vector1.D(), Vector2.D());
break;
}
default:
LOGMAN_MSG_A_FMT("Unknown Element Size: {}", ElementSize);
break;
}
case 8: {
fmul(GetDst(Node).V2D(), GetSrc(Op->Vector1.ID()).V2D(), GetSrc(Op->Vector2.ID()).V2D());
break;
} else {
switch (ElementSize) {
case 2: {
fmul(Dst.V8H(), Vector1.V8H(), Vector2.V8H());
break;
}
case 4: {
fmul(Dst.V4S(), Vector1.V4S(), Vector2.V4S());
break;
}
case 8: {
fmul(Dst.V2D(), Vector1.V2D(), Vector2.V2D());
break;
}
default:
LOGMAN_MSG_A_FMT("Unknown Element Size: {}", ElementSize);
break;
}
default: LOGMAN_MSG_A_FMT("Unknown Element Size: {}", Op->Header.ElementSize); break;
}
}
}
Expand Down
50 changes: 31 additions & 19 deletions External/FEXCore/Source/Interface/Core/JIT/x86_64/VectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,35 +681,47 @@ DEF_OP(VFSub) {
}

DEF_OP(VFMul) {
auto Op = IROp->C<IR::IROp_VFMul>();
const uint8_t OpSize = IROp->Size;
const auto Op = IROp->C<IR::IROp_VFMul>();
const auto OpSize = IROp->Size;

if (Op->Header.ElementSize == OpSize) {
// Scalar
switch (Op->Header.ElementSize) {
const auto ElementSize = Op->Header.ElementSize;
const auto IsScalar = Op->Header.ElementSize == OpSize;

const auto Dst = GetDst(Node);
const auto Vector1 = GetSrc(Op->Vector1.ID());
const auto Vector2 = GetSrc(Op->Vector2.ID());

if (IsScalar) {
switch (ElementSize) {
case 4: {
vmulss(GetDst(Node), GetSrc(Op->Vector1.ID()), GetSrc(Op->Vector2.ID()));
break;
vmulss(Dst, Vector1, Vector2);
break;
}
case 8: {
vmulsd(GetDst(Node), GetSrc(Op->Vector1.ID()), GetSrc(Op->Vector2.ID()));
break;
vmulsd(Dst, Vector1, Vector2);
break;
}
default: LOGMAN_MSG_A_FMT("Unknown Element Size: {}", Op->Header.ElementSize); break;
default:
LOGMAN_MSG_A_FMT("Unknown Element Size: {}", ElementSize);
break;
}
}
else {
// Vector
switch (Op->Header.ElementSize) {
} else {
const auto DstYMM = ToYMM(Dst);
const auto Vector1YMM = ToYMM(Vector1);
const auto Vector2YMM = ToYMM(Vector2);

switch (ElementSize) {
case 4: {
vmulps(GetDst(Node), GetSrc(Op->Vector1.ID()), GetSrc(Op->Vector2.ID()));
break;
vmulps(DstYMM, Vector1YMM, Vector2YMM);
break;
}
case 8: {
vmulpd(GetDst(Node), GetSrc(Op->Vector1.ID()), GetSrc(Op->Vector2.ID()));
break;
vmulpd(DstYMM, Vector1YMM, Vector2YMM);
break;
}
default: LOGMAN_MSG_A_FMT("Unknown Element Size: {}", Op->Header.ElementSize); break;
default:
LOGMAN_MSG_A_FMT("Unknown Element Size: {}", ElementSize);
break;
}
}
}
Expand Down

0 comments on commit 4472265

Please sign in to comment.