|
|
|
@ -24,21 +24,30 @@ namespace gen {
|
|
|
|
|
|
|
|
|
|
using namespace platform::jit; // NOLINT
|
|
|
|
|
|
|
|
|
|
bool VVVJitCode::init(int d) {
|
|
|
|
|
bool VXXJitCode::init(int d, int scalar_index) {
|
|
|
|
|
// It's not necessary to use avx512 since it would slow down the frequency
|
|
|
|
|
// and this kernel is not compute bound.
|
|
|
|
|
return MayIUse(avx);
|
|
|
|
|
return MayIUse(avx) && scalar_index >= 0 && scalar_index <= 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VVVJitCode::generate() {
|
|
|
|
|
void VXXJitCode::generate() {
|
|
|
|
|
// do not need push stack, and do not need save avx512reg if do not use avx512
|
|
|
|
|
int offset = 0;
|
|
|
|
|
if (with_relu_) {
|
|
|
|
|
vxorps(ymm_zero, ymm_zero, ymm_zero);
|
|
|
|
|
}
|
|
|
|
|
if (scalar_index_ == 1) {
|
|
|
|
|
vbroadcastss(ymm_src1, ptr[param1]);
|
|
|
|
|
} else if (scalar_index_ == 2) {
|
|
|
|
|
vbroadcastss(ymm_src2, ptr[param2]);
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < num_ / AVX_FLOAT_BLOCK; ++i) {
|
|
|
|
|
vmovups(ymm_src1, ptr[param1 + offset]);
|
|
|
|
|
vmovups(ymm_src2, ptr[param2 + offset]);
|
|
|
|
|
if (scalar_index_ != 1) {
|
|
|
|
|
vmovups(ymm_src1, ptr[param1 + offset]);
|
|
|
|
|
}
|
|
|
|
|
if (scalar_index_ != 2) {
|
|
|
|
|
vmovups(ymm_src2, ptr[param2 + offset]);
|
|
|
|
|
}
|
|
|
|
|
if (type_ == operand_type::mul) {
|
|
|
|
|
vmulps(ymm_dst, ymm_src1, ymm_src2);
|
|
|
|
|
} else if (type_ == operand_type::add) {
|
|
|
|
@ -52,8 +61,12 @@ void VVVJitCode::generate() {
|
|
|
|
|
}
|
|
|
|
|
int rest = num_ % AVX_FLOAT_BLOCK;
|
|
|
|
|
if (rest >= 4) {
|
|
|
|
|
vmovups(xmm_src1, ptr[param1 + offset]);
|
|
|
|
|
vmovups(xmm_src2, ptr[param2 + offset]);
|
|
|
|
|
if (scalar_index_ != 1) {
|
|
|
|
|
vmovups(xmm_src1, ptr[param1 + offset]);
|
|
|
|
|
}
|
|
|
|
|
if (scalar_index_ != 2) {
|
|
|
|
|
vmovups(xmm_src2, ptr[param2 + offset]);
|
|
|
|
|
}
|
|
|
|
|
if (type_ == operand_type::mul) {
|
|
|
|
|
vmulps(xmm_dst, xmm_src1, xmm_src2);
|
|
|
|
|
} else if (type_ == operand_type::add) {
|
|
|
|
@ -67,8 +80,12 @@ void VVVJitCode::generate() {
|
|
|
|
|
rest -= 4;
|
|
|
|
|
}
|
|
|
|
|
if (rest >= 2) {
|
|
|
|
|
vmovq(xmm_src1, ptr[param1 + offset]);
|
|
|
|
|
vmovq(xmm_src2, ptr[param2 + offset]);
|
|
|
|
|
if (scalar_index_ != 1) {
|
|
|
|
|
vmovups(xmm_src1, ptr[param1 + offset]);
|
|
|
|
|
}
|
|
|
|
|
if (scalar_index_ != 2) {
|
|
|
|
|
vmovups(xmm_src2, ptr[param2 + offset]);
|
|
|
|
|
}
|
|
|
|
|
if (type_ == operand_type::mul) {
|
|
|
|
|
vmulps(xmm_dst, xmm_src1, xmm_src2);
|
|
|
|
|
} else if (type_ == operand_type::add) {
|
|
|
|
@ -82,8 +99,12 @@ void VVVJitCode::generate() {
|
|
|
|
|
rest -= 2;
|
|
|
|
|
}
|
|
|
|
|
if (rest > 0) {
|
|
|
|
|
vmovss(xmm_src1, ptr[param1 + offset]);
|
|
|
|
|
vmovss(xmm_src2, ptr[param2 + offset]);
|
|
|
|
|
if (scalar_index_ != 1) {
|
|
|
|
|
vmovups(xmm_src1, ptr[param1 + offset]);
|
|
|
|
|
}
|
|
|
|
|
if (scalar_index_ != 2) {
|
|
|
|
|
vmovups(xmm_src2, ptr[param2 + offset]);
|
|
|
|
|
}
|
|
|
|
|
if (type_ == operand_type::mul) {
|
|
|
|
|
vmulss(xmm_dst, xmm_src1, xmm_src2);
|
|
|
|
|
} else if (type_ == operand_type::add) {
|
|
|
|
@ -96,6 +117,7 @@ void VVVJitCode::generate() {
|
|
|
|
|
}
|
|
|
|
|
ret();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace gen
|
|
|
|
|
} // namespace jitkernel
|
|
|
|
|
} // namespace math
|
|
|
|
|