emit_x64_vector: Deduplicate a bit of code in EmitVectorSetElement{8, 32, 64} functions
Given both branches are the same, we can hoist out the common code.
This commit is contained in:
parent
593eca7fb1
commit
0bee648b4f
1 changed files with 13 additions and 16 deletions
|
@ -172,19 +172,18 @@ void EmitX64::EmitVectorGetElement64(EmitContext& ctx, IR::Inst* inst) {
|
||||||
void EmitX64::EmitVectorSetElement8(EmitContext& ctx, IR::Inst* inst) {
|
void EmitX64::EmitVectorSetElement8(EmitContext& ctx, IR::Inst* inst) {
|
||||||
auto args = ctx.reg_alloc.GetArgumentInfo(inst);
|
auto args = ctx.reg_alloc.GetArgumentInfo(inst);
|
||||||
ASSERT(args[1].IsImmediate());
|
ASSERT(args[1].IsImmediate());
|
||||||
u8 index = args[1].GetImmediateU8();
|
const u8 index = args[1].GetImmediateU8();
|
||||||
|
const Xbyak::Xmm source_vector = ctx.reg_alloc.UseScratchXmm(args[0]);
|
||||||
|
|
||||||
if (code.DoesCpuSupport(Xbyak::util::Cpu::tSSE41)) {
|
if (code.DoesCpuSupport(Xbyak::util::Cpu::tSSE41)) {
|
||||||
Xbyak::Xmm source_vector = ctx.reg_alloc.UseScratchXmm(args[0]);
|
const Xbyak::Reg8 source_elem = ctx.reg_alloc.UseGpr(args[2]).cvt8();
|
||||||
Xbyak::Reg8 source_elem = ctx.reg_alloc.UseGpr(args[2]).cvt8();
|
|
||||||
|
|
||||||
code.pinsrb(source_vector, source_elem.cvt32(), index);
|
code.pinsrb(source_vector, source_elem.cvt32(), index);
|
||||||
|
|
||||||
ctx.reg_alloc.DefineValue(inst, source_vector);
|
ctx.reg_alloc.DefineValue(inst, source_vector);
|
||||||
} else {
|
} else {
|
||||||
Xbyak::Xmm source_vector = ctx.reg_alloc.UseScratchXmm(args[0]);
|
const Xbyak::Reg32 source_elem = ctx.reg_alloc.UseScratchGpr(args[2]).cvt32();
|
||||||
Xbyak::Reg32 source_elem = ctx.reg_alloc.UseScratchGpr(args[2]).cvt32();
|
const Xbyak::Reg32 tmp = ctx.reg_alloc.ScratchGpr().cvt32();
|
||||||
Xbyak::Reg32 tmp = ctx.reg_alloc.ScratchGpr().cvt32();
|
|
||||||
|
|
||||||
code.pextrw(tmp, source_vector, index / 2);
|
code.pextrw(tmp, source_vector, index / 2);
|
||||||
if (index % 2 == 0) {
|
if (index % 2 == 0) {
|
||||||
|
@ -218,18 +217,17 @@ void EmitX64::EmitVectorSetElement16(EmitContext& ctx, IR::Inst* inst) {
|
||||||
void EmitX64::EmitVectorSetElement32(EmitContext& ctx, IR::Inst* inst) {
|
void EmitX64::EmitVectorSetElement32(EmitContext& ctx, IR::Inst* inst) {
|
||||||
auto args = ctx.reg_alloc.GetArgumentInfo(inst);
|
auto args = ctx.reg_alloc.GetArgumentInfo(inst);
|
||||||
ASSERT(args[1].IsImmediate());
|
ASSERT(args[1].IsImmediate());
|
||||||
u8 index = args[1].GetImmediateU8();
|
const u8 index = args[1].GetImmediateU8();
|
||||||
|
const Xbyak::Xmm source_vector = ctx.reg_alloc.UseScratchXmm(args[0]);
|
||||||
|
|
||||||
if (code.DoesCpuSupport(Xbyak::util::Cpu::tSSE41)) {
|
if (code.DoesCpuSupport(Xbyak::util::Cpu::tSSE41)) {
|
||||||
Xbyak::Xmm source_vector = ctx.reg_alloc.UseScratchXmm(args[0]);
|
const Xbyak::Reg32 source_elem = ctx.reg_alloc.UseGpr(args[2]).cvt32();
|
||||||
Xbyak::Reg32 source_elem = ctx.reg_alloc.UseGpr(args[2]).cvt32();
|
|
||||||
|
|
||||||
code.pinsrd(source_vector, source_elem, index);
|
code.pinsrd(source_vector, source_elem, index);
|
||||||
|
|
||||||
ctx.reg_alloc.DefineValue(inst, source_vector);
|
ctx.reg_alloc.DefineValue(inst, source_vector);
|
||||||
} else {
|
} else {
|
||||||
Xbyak::Xmm source_vector = ctx.reg_alloc.UseScratchXmm(args[0]);
|
const Xbyak::Reg32 source_elem = ctx.reg_alloc.UseScratchGpr(args[2]).cvt32();
|
||||||
Xbyak::Reg32 source_elem = ctx.reg_alloc.UseScratchGpr(args[2]).cvt32();
|
|
||||||
|
|
||||||
code.pinsrw(source_vector, source_elem, index * 2);
|
code.pinsrw(source_vector, source_elem, index * 2);
|
||||||
code.shr(source_elem, 16);
|
code.shr(source_elem, 16);
|
||||||
|
@ -242,18 +240,17 @@ void EmitX64::EmitVectorSetElement32(EmitContext& ctx, IR::Inst* inst) {
|
||||||
void EmitX64::EmitVectorSetElement64(EmitContext& ctx, IR::Inst* inst) {
|
void EmitX64::EmitVectorSetElement64(EmitContext& ctx, IR::Inst* inst) {
|
||||||
auto args = ctx.reg_alloc.GetArgumentInfo(inst);
|
auto args = ctx.reg_alloc.GetArgumentInfo(inst);
|
||||||
ASSERT(args[1].IsImmediate());
|
ASSERT(args[1].IsImmediate());
|
||||||
u8 index = args[1].GetImmediateU8();
|
const u8 index = args[1].GetImmediateU8();
|
||||||
|
const Xbyak::Xmm source_vector = ctx.reg_alloc.UseScratchXmm(args[0]);
|
||||||
|
|
||||||
if (code.DoesCpuSupport(Xbyak::util::Cpu::tSSE41)) {
|
if (code.DoesCpuSupport(Xbyak::util::Cpu::tSSE41)) {
|
||||||
Xbyak::Xmm source_vector = ctx.reg_alloc.UseScratchXmm(args[0]);
|
const Xbyak::Reg64 source_elem = ctx.reg_alloc.UseGpr(args[2]);
|
||||||
Xbyak::Reg64 source_elem = ctx.reg_alloc.UseGpr(args[2]);
|
|
||||||
|
|
||||||
code.pinsrq(source_vector, source_elem, index);
|
code.pinsrq(source_vector, source_elem, index);
|
||||||
|
|
||||||
ctx.reg_alloc.DefineValue(inst, source_vector);
|
ctx.reg_alloc.DefineValue(inst, source_vector);
|
||||||
} else {
|
} else {
|
||||||
Xbyak::Xmm source_vector = ctx.reg_alloc.UseScratchXmm(args[0]);
|
const Xbyak::Reg64 source_elem = ctx.reg_alloc.UseScratchGpr(args[2]);
|
||||||
Xbyak::Reg64 source_elem = ctx.reg_alloc.UseScratchGpr(args[2]);
|
|
||||||
|
|
||||||
code.pinsrw(source_vector, source_elem.cvt32(), index * 4);
|
code.pinsrw(source_vector, source_elem.cvt32(), index * 4);
|
||||||
code.shr(source_elem, 16);
|
code.shr(source_elem, 16);
|
||||||
|
|
Loading…
Reference in a new issue