Add support for "switch" statements.
Switches with both uniform and varying "switch" expressions are supported. Switch statements with varying expressions and very large numbers of labels may not perform well; some issues to be filed shortly will track opportunities for improving these.
This commit is contained in:
18
tests/switch-1.ispc
Normal file
18
tests/switch-1.ispc
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
switch (b) {
|
||||
default:
|
||||
RET[programIndex] = -1;
|
||||
break;
|
||||
case 5:
|
||||
RET[programIndex] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
}
|
||||
44
tests/switch-10.ispc
Normal file
44
tests/switch-10.ispc
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
int switchit(int a, uniform int b) {
|
||||
switch (a) {
|
||||
case 3:
|
||||
return 1;
|
||||
case 7:
|
||||
case 6:
|
||||
case 4:
|
||||
case 5:
|
||||
if (a & 1)
|
||||
break;
|
||||
return 2;
|
||||
case 1: {
|
||||
switch (a+b) {
|
||||
case 6:
|
||||
return 42;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -1234;
|
||||
}
|
||||
case 32:
|
||||
*((int *)NULL) = 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
int x = switchit(a, b);
|
||||
RET[programIndex] = x;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
RET[0] = 42;
|
||||
RET[2] = 1;
|
||||
RET[6] = RET[4] = 3;
|
||||
RET[5] = RET[3] = 2;
|
||||
}
|
||||
50
tests/switch-11.ispc
Normal file
50
tests/switch-11.ispc
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
int switchit(int a, uniform int b) {
|
||||
switch (a) {
|
||||
case 3:
|
||||
return 1;
|
||||
case 7:
|
||||
case 6:
|
||||
case 4:
|
||||
case 5:
|
||||
if (a & 1)
|
||||
break;
|
||||
return 2;
|
||||
case 1: {
|
||||
switch (a+b) {
|
||||
case 60:
|
||||
return -1234;
|
||||
default:
|
||||
break;
|
||||
case 6:
|
||||
if (b == 5)
|
||||
break;
|
||||
return -42;
|
||||
case 12:
|
||||
return -1;
|
||||
}
|
||||
return 42;
|
||||
}
|
||||
case 32:
|
||||
*((int *)NULL) = 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
int x = switchit(a, b);
|
||||
RET[programIndex] = x;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
RET[0] = 42;
|
||||
RET[2] = 1;
|
||||
RET[6] = RET[4] = 3;
|
||||
RET[5] = RET[3] = 2;
|
||||
}
|
||||
54
tests/switch-12.ispc
Normal file
54
tests/switch-12.ispc
Normal file
@@ -0,0 +1,54 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
int switchit(int a, uniform int b) {
|
||||
switch (a) {
|
||||
case 3:
|
||||
return 1;
|
||||
case 7:
|
||||
case 6:
|
||||
case 4:
|
||||
case 5:
|
||||
if (a & 1)
|
||||
break;
|
||||
return 2;
|
||||
case 1: {
|
||||
switch (a+b) {
|
||||
case 60:
|
||||
return -1234;
|
||||
default:
|
||||
break;
|
||||
case 6:
|
||||
int count = 0;
|
||||
for (count = 0; count < 10; ++count) {
|
||||
a += b;
|
||||
if (a == 11)
|
||||
break;
|
||||
}
|
||||
return a;
|
||||
case 12:
|
||||
return -1;
|
||||
}
|
||||
return 42;
|
||||
}
|
||||
case 32:
|
||||
*((int *)NULL) = 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
int x = switchit(a, b);
|
||||
RET[programIndex] = x;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
RET[0] = 11;
|
||||
RET[2] = 1;
|
||||
RET[6] = RET[4] = 3;
|
||||
RET[5] = RET[3] = 2;
|
||||
}
|
||||
17
tests/switch-2.ispc
Normal file
17
tests/switch-2.ispc
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
switch (b) {
|
||||
default:
|
||||
RET[programIndex] = -1;
|
||||
case 5:
|
||||
RET[programIndex] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
}
|
||||
18
tests/switch-3.ispc
Normal file
18
tests/switch-3.ispc
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
switch (b) {
|
||||
case 5:
|
||||
RET[programIndex] = 0;
|
||||
break;
|
||||
default:
|
||||
RET[programIndex] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
}
|
||||
24
tests/switch-4.ispc
Normal file
24
tests/switch-4.ispc
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
int switchit(int a, uniform int b) {
|
||||
int r = 0;
|
||||
switch (a) {
|
||||
case 3:
|
||||
r = 1;
|
||||
break;
|
||||
default:
|
||||
r = 0;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
int x = switchit(a, b);
|
||||
RET[programIndex] = x;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = (programIndex == 2) ? 1 : 0;
|
||||
}
|
||||
22
tests/switch-5.ispc
Normal file
22
tests/switch-5.ispc
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
int switchit(int a, uniform int b) {
|
||||
int r = 0;
|
||||
switch (a) {
|
||||
case 3:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
int x = switchit(a, b);
|
||||
RET[programIndex] = x;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = (programIndex == 2) ? 1 : 0;
|
||||
}
|
||||
27
tests/switch-6.ispc
Normal file
27
tests/switch-6.ispc
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
int switchit(int a, uniform int b) {
|
||||
switch (a) {
|
||||
case 3:
|
||||
return 1;
|
||||
case 7:
|
||||
if (b == 5)
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
int x = switchit(a, b);
|
||||
RET[programIndex] = x;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
RET[2] = 1;
|
||||
RET[6] = -1;
|
||||
}
|
||||
32
tests/switch-7.ispc
Normal file
32
tests/switch-7.ispc
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
int switchit(int a, uniform int b) {
|
||||
switch (a) {
|
||||
case 3:
|
||||
return 1;
|
||||
case 7:
|
||||
case 6:
|
||||
case 4:
|
||||
case 5:
|
||||
if (a & 1)
|
||||
break;
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
int x = switchit(a, b);
|
||||
RET[programIndex] = x;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
RET[2] = 1;
|
||||
RET[6] = RET[4] = 3;
|
||||
RET[5] = RET[3] = 2;
|
||||
}
|
||||
36
tests/switch-8.ispc
Normal file
36
tests/switch-8.ispc
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
int switchit(int a, uniform int b) {
|
||||
switch (a) {
|
||||
case 3:
|
||||
return 1;
|
||||
case 7:
|
||||
case 6:
|
||||
case 4:
|
||||
case 5:
|
||||
if (a & 1)
|
||||
break;
|
||||
return 2;
|
||||
case 32:
|
||||
*((int *)NULL) = 0;
|
||||
//CO default:
|
||||
case 1:
|
||||
case 2:
|
||||
return 0;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
int x = switchit(a, b);
|
||||
RET[programIndex] = x;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
RET[2] = 1;
|
||||
RET[6] = RET[4] = 3;
|
||||
RET[5] = RET[3] = 2;
|
||||
}
|
||||
34
tests/switch-9.ispc
Normal file
34
tests/switch-9.ispc
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
int switchit(int a, uniform int b) {
|
||||
switch (a) {
|
||||
case 3:
|
||||
return 1;
|
||||
case 7:
|
||||
case 6:
|
||||
case 4:
|
||||
case 5:
|
||||
if (a & 1)
|
||||
break;
|
||||
return 2;
|
||||
case 32:
|
||||
*((int *)NULL) = 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
int a = aFOO[programIndex];
|
||||
int x = switchit(a, b);
|
||||
RET[programIndex] = x;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
RET[2] = 1;
|
||||
RET[6] = RET[4] = 3;
|
||||
RET[5] = RET[3] = 2;
|
||||
}
|
||||
Reference in New Issue
Block a user