Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix simd uni instructions for sse41 #149

Open
wants to merge 2 commits into
base: v2.6_for_ie_master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 109 additions & 30 deletions src/cpu/x64/jit_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class jit_generator : public Xbyak::CodeGenerator, public c_compatible {

private:
const size_t xmm_len = 16;
const size_t ymm_len = 32;
const size_t zmm_len = 64;
#ifdef _WIN32
const size_t xmm_to_preserve_start = 6;
const size_t xmm_to_preserve = 10;
Expand Down Expand Up @@ -182,6 +184,35 @@ class jit_generator : public Xbyak::CodeGenerator, public c_compatible {

inline size_t get_size_of_abi_save_regs() { return size_of_abi_save_regs; }

using Xbyak::CodeGenerator::push;
using Xbyak::CodeGenerator::pop;

inline void push(const Xbyak::Xmm &xmm) {
if (xmm.isXMM()) {
sub(rsp, xmm_len);
uni_vmovdqu(ptr[rsp], xmm);
} else if (xmm.isYMM()) {
sub(rsp, ymm_len);
uni_vmovdqu(ptr[rsp], Xbyak::Ymm{xmm.getIdx()});
} else if (xmm.isZMM()) {
sub(rsp, zmm_len);
uni_vmovdqu(ptr[rsp], Xbyak::Zmm{xmm.getIdx()});
}
}

inline void pop(const Xbyak::Xmm &xmm) {
if (xmm.isXMM()) {
uni_vmovdqu(xmm, ptr[rsp]);
add(rsp, xmm_len);
} else if (xmm.isYMM()) {
uni_vmovdqu(Xbyak::Ymm{xmm.getIdx()}, ptr[rsp]);
add(rsp, ymm_len);
} else if (xmm.isZMM()) {
uni_vmovdqu(Xbyak::Zmm{xmm.getIdx()}, ptr[rsp]);
add(rsp, zmm_len);
}
}

void preamble() {
if (xmm_to_preserve) {
sub(rsp, xmm_to_preserve * xmm_len);
Expand Down Expand Up @@ -626,16 +657,22 @@ class jit_generator : public Xbyak::CodeGenerator, public c_compatible {
vdivps(x, op1, op2);
}

void uni_vaddps(const Xbyak::Xmm &x, const Xbyak::Operand &op1,
void uni_vaddps(const Xbyak::Xmm &x, const Xbyak::Xmm &op1,
const Xbyak::Operand &op2) {
if (is_valid_isa(avx))
vaddps(x, op1, op2);
else {
if (!x.isEqualIfNotInherited(op1)) movups(x, op1);
addps(x, op2);
if (x.getIdx() == op1.getIdx()) {
addps(x, op2);
} else if (x.isEqualIfNotInherited(op2)) {
addps(x, op1);
} else {
movups(x, op1);
addps(x, op2);
}
}
}
void uni_vaddps(const Xbyak::Ymm &x, const Xbyak::Operand &op1,
void uni_vaddps(const Xbyak::Ymm &x, const Xbyak::Ymm &op1,
const Xbyak::Operand &op2) {
vaddps(x, op1, op2);
}
Expand Down Expand Up @@ -744,16 +781,25 @@ class jit_generator : public Xbyak::CodeGenerator, public c_compatible {
vsubss(x, Xbyak::Xmm(op1.getIdx()), Xbyak::Xmm(op2.getIdx()));
}

void uni_vsubps(const Xbyak::Xmm &x, const Xbyak::Operand &op1,
void uni_vsubps(const Xbyak::Xmm &x, const Xbyak::Xmm &op1,
const Xbyak::Operand &op2) {
if (is_valid_isa(avx))
vsubps(x, op1, op2);
else {
if (!x.isEqualIfNotInherited(op1)) movups(x, op1);
subps(x, op2);
if (x.getIdx() == op1.getIdx()) {
subps(x, op2);
} else if (x.isEqualIfNotInherited(op2)) {
push(op1);
subps(op1, op2);
movups(x, op1);
pop(op1);
} else {
movups(x, op1);
subps(x, op2);
}
}
}
void uni_vsubps(const Xbyak::Ymm &x, const Xbyak::Operand &op1,
void uni_vsubps(const Xbyak::Ymm &x, const Xbyak::Ymm &op1,
const Xbyak::Operand &op2) {
vsubps(x, op1, op2);
}
Expand Down Expand Up @@ -787,30 +833,42 @@ class jit_generator : public Xbyak::CodeGenerator, public c_compatible {
}
}

void uni_vpmulld(const Xbyak::Xmm &x1, const Xbyak::Xmm &x2,
const Xbyak::Operand &op) {
void uni_vpmulld(const Xbyak::Xmm &x, const Xbyak::Xmm &op1,
const Xbyak::Operand &op2) {
if (is_valid_isa(avx)) {
vpmulld(x1, x2, op);
vpmulld(x, op1, op2);
} else {
if (x1.getIdx() != x2.getIdx()) movdqa(x1, x2);
pmulld(x1, op);
if (x.getIdx() == op1.getIdx()) {
pmulld(x, op2);
} else if (x.isEqualIfNotInherited(op2)) {
pmulld(x, op1);
} else {
movdqa(x, op1);
pmulld(x, op2);
}
}
}
void uni_vpmulld(const Xbyak::Ymm &x1, const Xbyak::Ymm &x2,
const Xbyak::Operand &op) {
vpmulld(x1, x2, op);
}

void uni_vmulps(const Xbyak::Xmm &x, const Xbyak::Operand &op1,
void uni_vmulps(const Xbyak::Xmm &x, const Xbyak::Xmm &op1,
const Xbyak::Operand &op2) {
if (is_valid_isa(avx))
vmulps(x, op1, op2);
else {
if (!x.isEqualIfNotInherited(op1)) movups(x, op1);
mulps(x, op2);
if (x.getIdx() == op1.getIdx()) {
mulps(x, op2);
} else if (x.isEqualIfNotInherited(op2)) {
mulps(x, op1);
} else {
movups(x, op1);
mulps(x, op2);
}
}
}
void uni_vmulps(const Xbyak::Ymm &x, const Xbyak::Operand &op1,
void uni_vmulps(const Xbyak::Ymm &x, const Xbyak::Ymm &op1,
const Xbyak::Operand &op2) {
vmulps(x, op1, op2);
}
Expand Down Expand Up @@ -1212,16 +1270,22 @@ class jit_generator : public Xbyak::CodeGenerator, public c_compatible {
vpsrld(x, op, imm);
}

void uni_vmaxps(const Xbyak::Xmm &x, const Xbyak::Operand &op1,
void uni_vmaxps(const Xbyak::Xmm &x, const Xbyak::Xmm &op1,
const Xbyak::Operand &op2) {
if (is_valid_isa(avx))
vmaxps(x, op1, op2);
else {
if (!x.isEqualIfNotInherited(op1)) movups(x, op1);
maxps(x, op2);
if (x.getIdx() == op1.getIdx()) {
maxps(x, op2);
} else if (x.isEqualIfNotInherited(op2)) {
maxps(x, op1);
} else {
movups(x, op1);
maxps(x, op2);
}
}
}
void uni_vmaxps(const Xbyak::Ymm &x, const Xbyak::Operand &op1,
void uni_vmaxps(const Xbyak::Ymm &x, const Xbyak::Ymm &op1,
const Xbyak::Operand &op2) {
vmaxps(x, op1, op2);
}
Expand All @@ -1236,17 +1300,23 @@ class jit_generator : public Xbyak::CodeGenerator, public c_compatible {
}
}

void uni_vminps(const Xbyak::Xmm &x, const Xbyak::Operand &op1,
void uni_vminps(const Xbyak::Xmm &x, const Xbyak::Xmm &op1,
const Xbyak::Operand &op2) {
if (is_valid_isa(avx))
vminps(x, op1, op2);
else {
if (!x.isEqualIfNotInherited(op1)) movups(x, op1);
minps(x, op2);
if (x.getIdx() == op1.getIdx()) {
minps(x, op2);
} else if (x.isEqualIfNotInherited(op2)) {
minps(x, op1);
} else {
movups(x, op1);
minps(x, op2);
}
}
}

void uni_vminps(const Xbyak::Ymm &x, const Xbyak::Operand &op1,
void uni_vminps(const Xbyak::Ymm &x, const Xbyak::Ymm &op1,
const Xbyak::Operand &op2) {
vminps(x, op1, op2);
}
Expand Down Expand Up @@ -1283,13 +1353,22 @@ class jit_generator : public Xbyak::CodeGenerator, public c_compatible {
vpmovzxbd(y, op);
}

void uni_vcmpps(const Xbyak::Xmm &x1, const Xbyak::Xmm &x2,
const Xbyak::Operand &op, int cmp_predicate) {
void uni_vcmpps(const Xbyak::Xmm &x, const Xbyak::Xmm &op1,
const Xbyak::Operand &op2, int cmp_predicate) {
if (is_valid_isa(avx))
vcmpps(x1, x2, op, cmp_predicate);
vcmpps(x, op1, op2, cmp_predicate);
else {
if (x1.getIdx() != x2.getIdx()) uni_vmovups(x1, x2);
cmpps(x1, op, cmp_predicate);
if (x.getIdx() == op1.getIdx()) {
cmpps(x, op2, cmp_predicate);
} else if (x.isEqualIfNotInherited(op2)) {
push(op1);
cmpps(op1, op2, cmp_predicate);
movups(x, op1);
pop(op1);
} else {
movups(x, op1);
cmpps(x, op2, cmp_predicate);
}
}
}
void uni_vcmpps(const Xbyak::Ymm &x1, const Xbyak::Ymm &x2,
Expand Down