Add comparisons (eq|neq|gt|gte)(i32|f32)

Change-Id: Ic53758162507d769548953001bd761e84d717322
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/274064
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Herb Derby 2020-02-28 11:00:36 -06:00 committed by Mike Klein
parent 4bd834b167
commit 5c5bd1a637
2 changed files with 20 additions and 5 deletions

View File

@ -1947,8 +1947,9 @@ namespace skvm {
llvm::Type *I32 = scalar ? i32 : llvm::VectorType::get(i32, K),
*F32 = scalar ? f32 : llvm::VectorType::get(f32, K);
auto I = [&](llvm::Value* v) { return b->CreateBitCast(v, I32); };
auto F = [&](llvm::Value* v) { return b->CreateBitCast(v, F32); };
auto I = [&](llvm::Value* v) { return b->CreateBitCast(v, I32); };
auto F = [&](llvm::Value* v) { return b->CreateBitCast(v, F32); };
auto SE = [&](llvm::Value* v) { return b->CreateSExt(v, I32); };
switch (op) {
default:
@ -1975,11 +1976,21 @@ namespace skvm {
case Op::sra_i32: vals[i] = b->CreateAShr(vals[x], immy); break;
case Op::shr_i32: vals[i] = b->CreateLShr(vals[x], immy); break;
case Op::eq_i32: vals[i] = SE(b->CreateICmpEQ(vals[x], vals[y])); break;
case Op::neq_i32: vals[i] = SE(b->CreateICmpNE(vals[x], vals[y])); break;
case Op::gt_i32: vals[i] = SE(b->CreateICmpSGT(vals[x], vals[y])); break;
case Op::gte_i32: vals[i] = SE(b->CreateICmpSGE(vals[x], vals[y])); break;
case Op::add_f32: vals[i] = I(b->CreateFAdd(F(vals[x]), F(vals[y]))); break;
case Op::sub_f32: vals[i] = I(b->CreateFSub(F(vals[x]), F(vals[y]))); break;
case Op::mul_f32: vals[i] = I(b->CreateFMul(F(vals[x]), F(vals[y]))); break;
case Op::div_f32: vals[i] = I(b->CreateFDiv(F(vals[x]), F(vals[y]))); break;
case Op::eq_f32: vals[i] = SE(b->CreateFCmpOEQ(F(vals[x]), F(vals[y]))); break;
case Op::neq_f32: vals[i] = SE(b->CreateFCmpONE(F(vals[x]), F(vals[y]))); break;
case Op::gt_f32: vals[i] = SE(b->CreateFCmpOGT(F(vals[x]), F(vals[y]))); break;
case Op::gte_f32: vals[i] = SE(b->CreateFCmpOGE(F(vals[x]), F(vals[y]))); break;
case Op::mad_f32:
vals[i] = I(b->CreateFAdd(b->CreateFMul(F(vals[x]), F(vals[y])),
F(vals[z])));
@ -2103,7 +2114,7 @@ namespace skvm {
SkASSERT(false == llvm::verifyModule(*mod, &llvm::outs()));
if (false) {
if (true) {
SkString path = SkStringPrintf("/tmp/%s.bc", debug_name);
std::error_code err;
llvm::raw_fd_ostream os(path.c_str(), err);

View File

@ -526,8 +526,12 @@ DEF_TEST(SkVM_cmp_i32, r) {
b.store32(b.varying<int>(), m);
}
test_interpreter_only(r, b.done(), [&](const skvm::Program& program) {
#if defined(SKVM_LLVM)
test_jit_and_interpreter
#else
test_interpreter_only
#endif
(r, b.done(), [&](const skvm::Program& program) {
int in[] = { 0,1,2,3,4,5,6,7,8,9 };
int out[SK_ARRAY_COUNT(in)];