Add unit tests for for-loop unrolling
Change-Id: I350a6768ac124362b0d3e0f17e7a026265acf804 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353627 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
15595ea39c
commit
3d81fdcbd2
@ -485,6 +485,8 @@ sksl_settings_tests = [
|
||||
|
||||
sksl_rte_tests = [
|
||||
"$_tests/sksl/runtime/ConversionConstructors.rte",
|
||||
"$_tests/sksl/runtime/LoopInt.rte",
|
||||
"$_tests/sksl/runtime/LoopFloat.rte",
|
||||
"$_tests/sksl/runtime/SampleWithConstantMatrix.rte",
|
||||
"$_tests/sksl/runtime/SampleWithExplicitCoord.rte",
|
||||
"$_tests/sksl/runtime/SampleWithUniformMatrix.rte",
|
||||
|
@ -920,16 +920,20 @@ namespace skvm {
|
||||
|
||||
I32 Builder:: eq(I32 x, I32 y) {
|
||||
if (x.id == y.id) { return splat(~0); }
|
||||
if (int X,Y; this->allImm(x.id,&X, y.id,&Y)) { return splat(X==Y ? ~0 : 0); }
|
||||
return {this, this->push(Op:: eq_i32, x.id, y.id)};
|
||||
}
|
||||
I32 Builder::neq(I32 x, I32 y) {
|
||||
if (int X,Y; this->allImm(x.id,&X, y.id,&Y)) { return splat(X!=Y ? ~0 : 0); }
|
||||
return ~(x == y);
|
||||
}
|
||||
I32 Builder:: gt(I32 x, I32 y) {
|
||||
if (int X,Y; this->allImm(x.id,&X, y.id,&Y)) { return splat(X> Y ? ~0 : 0); }
|
||||
return {this, this->push(Op:: gt_i32, x.id, y.id)};
|
||||
}
|
||||
I32 Builder::gte(I32 x, I32 y) {
|
||||
if (x.id == y.id) { return splat(~0); }
|
||||
if (int X,Y; this->allImm(x.id,&X, y.id,&Y)) { return splat(X>=Y ? ~0 : 0); }
|
||||
return ~(x < y);
|
||||
}
|
||||
I32 Builder:: lt(I32 x, I32 y) { return y>x; }
|
||||
|
40
tests/sksl/runtime/LoopFloat.rte
Normal file
40
tests/sksl/runtime/LoopFloat.rte
Normal file
@ -0,0 +1,40 @@
|
||||
// Should return 5
|
||||
float return_loop() {
|
||||
for (float i = 0; i < 10; ++i) {
|
||||
if (i == 5) { return i; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Should return 35
|
||||
float continue_loop() {
|
||||
float sum = 0;
|
||||
for (float i = 0; i < 10; ++i) {
|
||||
if (i < 5) { continue; }
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
// Should return 15
|
||||
float break_loop() {
|
||||
float sum = 0;
|
||||
for (float i = 0; i < 10; ++i) {
|
||||
if (i > 5) { break; }
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
// Should return ~1.725
|
||||
float float_loop() {
|
||||
float sum = 0;
|
||||
for (float i = 0.123; i < 0.6; i += 0.111) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
half4 main() {
|
||||
return half4(return_loop(), continue_loop(), break_loop(), float_loop());
|
||||
}
|
31
tests/sksl/runtime/LoopInt.rte
Normal file
31
tests/sksl/runtime/LoopInt.rte
Normal file
@ -0,0 +1,31 @@
|
||||
// Should return 5
|
||||
int return_loop() {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
if (i == 5) { return i; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Should return 35
|
||||
int continue_loop() {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
if (i < 5) { continue; }
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
// Should return 15
|
||||
int break_loop() {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
if (i > 5) { break; }
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
half4 main() {
|
||||
return half4(return_loop(), continue_loop(), break_loop(), 1);
|
||||
}
|
10
tests/sksl/runtime/golden/LoopFloat.skvm
Normal file
10
tests/sksl/runtime/golden/LoopFloat.skvm
Normal file
@ -0,0 +1,10 @@
|
||||
4 registers, 8 instructions:
|
||||
0 r0 = splat 40A00000 (5)
|
||||
1 r1 = splat 420C0000 (35)
|
||||
2 r2 = splat 41700000 (15)
|
||||
3 r3 = splat 3FDCCCCD (1.725)
|
||||
loop:
|
||||
4 store32 ptr1 r0
|
||||
5 store32 ptr2 r1
|
||||
6 store32 ptr3 r2
|
||||
7 store32 ptr4 r3
|
10
tests/sksl/runtime/golden/LoopInt.skvm
Normal file
10
tests/sksl/runtime/golden/LoopInt.skvm
Normal file
@ -0,0 +1,10 @@
|
||||
4 registers, 8 instructions:
|
||||
0 r0 = splat 40A00000 (5)
|
||||
1 r1 = splat 420C0000 (35)
|
||||
2 r2 = splat 41700000 (15)
|
||||
3 r3 = splat 3F800000 (1)
|
||||
loop:
|
||||
4 store32 ptr1 r0
|
||||
5 store32 ptr2 r1
|
||||
6 store32 ptr3 r2
|
||||
7 store32 ptr4 r3
|
Loading…
Reference in New Issue
Block a user