From ba9bb3338f86323ab432cbb557246a6a078eefd4 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Thu, 3 Nov 2011 15:59:06 -0700 Subject: [PATCH] Add tests for function pointers. --- tests/funcptr-null-1.ispc | 23 +++++++++++++++++++++++ tests/funcptr-null-2.ispc | 26 ++++++++++++++++++++++++++ tests/funcptr-null-3.ispc | 29 +++++++++++++++++++++++++++++ tests/funcptr-null-4.ispc | 29 +++++++++++++++++++++++++++++ tests/funcptr-null-5.ispc | 29 +++++++++++++++++++++++++++++ tests/funcptr-null-6.ispc | 29 +++++++++++++++++++++++++++++ tests/funcptr-uniform-1.ispc | 23 +++++++++++++++++++++++ tests/funcptr-uniform-10.ispc | 25 +++++++++++++++++++++++++ tests/funcptr-uniform-2.ispc | 25 +++++++++++++++++++++++++ tests/funcptr-uniform-3.ispc | 23 +++++++++++++++++++++++ tests/funcptr-uniform-4.ispc | 23 +++++++++++++++++++++++ tests/funcptr-uniform-5.ispc | 24 ++++++++++++++++++++++++ tests/funcptr-uniform-6.ispc | 24 ++++++++++++++++++++++++ tests/funcptr-uniform-7.ispc | 24 ++++++++++++++++++++++++ tests/funcptr-uniform-8.ispc | 24 ++++++++++++++++++++++++ tests/funcptr-uniform-9.ispc | 28 ++++++++++++++++++++++++++++ tests/funcptr-varying-1.ispc | 23 +++++++++++++++++++++++ tests/funcptr-varying-2.ispc | 24 ++++++++++++++++++++++++ tests/funcptr-varying-3.ispc | 25 +++++++++++++++++++++++++ tests/funcptr-varying-4.ispc | 25 +++++++++++++++++++++++++ tests/funcptr-varying-5.ispc | 26 ++++++++++++++++++++++++++ tests/funcptr-varying-6.ispc | 24 ++++++++++++++++++++++++ tests/funcptr-varying-7.ispc | 24 ++++++++++++++++++++++++ tests/funcptr-varying-8.ispc | 24 ++++++++++++++++++++++++ tests/funcptr-varying-9.ispc | 25 +++++++++++++++++++++++++ 25 files changed, 628 insertions(+) create mode 100644 tests/funcptr-null-1.ispc create mode 100644 tests/funcptr-null-2.ispc create mode 100644 tests/funcptr-null-3.ispc create mode 100644 tests/funcptr-null-4.ispc create mode 100644 tests/funcptr-null-5.ispc create mode 100644 tests/funcptr-null-6.ispc create mode 100644 tests/funcptr-uniform-1.ispc create mode 100644 tests/funcptr-uniform-10.ispc create mode 100644 tests/funcptr-uniform-2.ispc create mode 100644 tests/funcptr-uniform-3.ispc create mode 100644 tests/funcptr-uniform-4.ispc create mode 100644 tests/funcptr-uniform-5.ispc create mode 100644 tests/funcptr-uniform-6.ispc create mode 100644 tests/funcptr-uniform-7.ispc create mode 100644 tests/funcptr-uniform-8.ispc create mode 100644 tests/funcptr-uniform-9.ispc create mode 100644 tests/funcptr-varying-1.ispc create mode 100644 tests/funcptr-varying-2.ispc create mode 100644 tests/funcptr-varying-3.ispc create mode 100644 tests/funcptr-varying-4.ispc create mode 100644 tests/funcptr-varying-5.ispc create mode 100644 tests/funcptr-varying-6.ispc create mode 100644 tests/funcptr-varying-7.ispc create mode 100644 tests/funcptr-varying-8.ispc create mode 100644 tests/funcptr-varying-9.ispc diff --git a/tests/funcptr-null-1.ispc b/tests/funcptr-null-1.ispc new file mode 100644 index 00000000..c07e7910 --- /dev/null +++ b/tests/funcptr-null-1.ispc @@ -0,0 +1,23 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + uniform FuncType func = foo; + RET[programIndex] = (func ? func : bar)(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; +} diff --git a/tests/funcptr-null-2.ispc b/tests/funcptr-null-2.ispc new file mode 100644 index 00000000..596577c1 --- /dev/null +++ b/tests/funcptr-null-2.ispc @@ -0,0 +1,26 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + FuncType func = foo; + if (a == 2) + func = NULL; + RET[programIndex] = (func ? func : bar)(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; + RET[1] = 0; +} diff --git a/tests/funcptr-null-3.ispc b/tests/funcptr-null-3.ispc new file mode 100644 index 00000000..02fe9549 --- /dev/null +++ b/tests/funcptr-null-3.ispc @@ -0,0 +1,29 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + FuncType func = foo; + if (a == 2) + func = NULL; + if (func != NULL) + RET[programIndex] = func(a, b); + else + RET[programIndex] = -1; +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; + RET[1] = -1; +} diff --git a/tests/funcptr-null-4.ispc b/tests/funcptr-null-4.ispc new file mode 100644 index 00000000..739d6c1c --- /dev/null +++ b/tests/funcptr-null-4.ispc @@ -0,0 +1,29 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + FuncType func = NULL; + if (a == 2) + func = foo; + if (func != NULL) + RET[programIndex] = func(a, b); + else + RET[programIndex] = -1; +} + +export void result(uniform float RET[]) { + RET[programIndex] = -1; + RET[1] = 2; +} diff --git a/tests/funcptr-null-5.ispc b/tests/funcptr-null-5.ispc new file mode 100644 index 00000000..c78445d0 --- /dev/null +++ b/tests/funcptr-null-5.ispc @@ -0,0 +1,29 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + FuncType func = NULL; + if (a == 2) + func = foo; + if (func) + RET[programIndex] = func(a, b); + else + RET[programIndex] = -1; +} + +export void result(uniform float RET[]) { + RET[programIndex] = -1; + RET[1] = 2; +} diff --git a/tests/funcptr-null-6.ispc b/tests/funcptr-null-6.ispc new file mode 100644 index 00000000..cf92c4a7 --- /dev/null +++ b/tests/funcptr-null-6.ispc @@ -0,0 +1,29 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + FuncType func = NULL; + if (a == 2) + func = foo; + if (!func) + RET[programIndex] = -1; + else + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = -1; + RET[1] = 2; +} diff --git a/tests/funcptr-uniform-1.ispc b/tests/funcptr-uniform-1.ispc new file mode 100644 index 00000000..858e25df --- /dev/null +++ b/tests/funcptr-uniform-1.ispc @@ -0,0 +1,23 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + uniform FuncType func = foo; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; +} diff --git a/tests/funcptr-uniform-10.ispc b/tests/funcptr-uniform-10.ispc new file mode 100644 index 00000000..75fcbfe9 --- /dev/null +++ b/tests/funcptr-uniform-10.ispc @@ -0,0 +1,25 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + uniform FuncType func[] = { bar, foo }; + float a = aFOO[programIndex]; + float b = aFOO[0]-1; // == 0 + func[min(a, 0)] = foo; + RET[programIndex] = func[0](a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = programIndex+1; +} diff --git a/tests/funcptr-uniform-2.ispc b/tests/funcptr-uniform-2.ispc new file mode 100644 index 00000000..849c9492 --- /dev/null +++ b/tests/funcptr-uniform-2.ispc @@ -0,0 +1,25 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + uniform FuncType func = bar; + if (aFOO[0] == 1) + func = foo; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; +} diff --git a/tests/funcptr-uniform-3.ispc b/tests/funcptr-uniform-3.ispc new file mode 100644 index 00000000..31a9b30e --- /dev/null +++ b/tests/funcptr-uniform-3.ispc @@ -0,0 +1,23 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + uniform FuncType func = (aFOO[0] == 1) ? foo : bar; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; +} diff --git a/tests/funcptr-uniform-4.ispc b/tests/funcptr-uniform-4.ispc new file mode 100644 index 00000000..3dfdc0e1 --- /dev/null +++ b/tests/funcptr-uniform-4.ispc @@ -0,0 +1,23 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + uniform FuncType func = min; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 0; +} diff --git a/tests/funcptr-uniform-5.ispc b/tests/funcptr-uniform-5.ispc new file mode 100644 index 00000000..2224e177 --- /dev/null +++ b/tests/funcptr-uniform-5.ispc @@ -0,0 +1,24 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +static uniform FuncType func = foo; + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; +} diff --git a/tests/funcptr-uniform-6.ispc b/tests/funcptr-uniform-6.ispc new file mode 100644 index 00000000..72b2925c --- /dev/null +++ b/tests/funcptr-uniform-6.ispc @@ -0,0 +1,24 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + static uniform FuncType func = foo; + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; +} diff --git a/tests/funcptr-uniform-7.ispc b/tests/funcptr-uniform-7.ispc new file mode 100644 index 00000000..4de98fd8 --- /dev/null +++ b/tests/funcptr-uniform-7.ispc @@ -0,0 +1,24 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + uniform FuncType func[] = { foo, bar }; + float a = aFOO[programIndex]; + float b = aFOO[0]-1; // == 0 + RET[programIndex] = func[(int)b](a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = programIndex+1; +} diff --git a/tests/funcptr-uniform-8.ispc b/tests/funcptr-uniform-8.ispc new file mode 100644 index 00000000..4de98fd8 --- /dev/null +++ b/tests/funcptr-uniform-8.ispc @@ -0,0 +1,24 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + uniform FuncType func[] = { foo, bar }; + float a = aFOO[programIndex]; + float b = aFOO[0]-1; // == 0 + RET[programIndex] = func[(int)b](a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = programIndex+1; +} diff --git a/tests/funcptr-uniform-9.ispc b/tests/funcptr-uniform-9.ispc new file mode 100644 index 00000000..7506252c --- /dev/null +++ b/tests/funcptr-uniform-9.ispc @@ -0,0 +1,28 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + if (a < b) + return a; + else + return b; +} + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + uniform FuncType func[] = { foo, bar }; + float a = aFOO[programIndex]; + float b = aFOO[0]-1; // == 0 + RET[programIndex] = ((a == 1) ? bar : foo)(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = programIndex+1; + RET[0] = 0; +} diff --git a/tests/funcptr-varying-1.ispc b/tests/funcptr-varying-1.ispc new file mode 100644 index 00000000..ef9c662c --- /dev/null +++ b/tests/funcptr-varying-1.ispc @@ -0,0 +1,23 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + FuncType func = foo; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; +} diff --git a/tests/funcptr-varying-2.ispc b/tests/funcptr-varying-2.ispc new file mode 100644 index 00000000..b68fa7ed --- /dev/null +++ b/tests/funcptr-varying-2.ispc @@ -0,0 +1,24 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + FuncType func = bar; + func = foo; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; +} diff --git a/tests/funcptr-varying-3.ispc b/tests/funcptr-varying-3.ispc new file mode 100644 index 00000000..7463d9d3 --- /dev/null +++ b/tests/funcptr-varying-3.ispc @@ -0,0 +1,25 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + +FuncType func = bar; + +export void f_f(uniform float RET[], uniform float aFOO[]) { + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + func = foo; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; +} diff --git a/tests/funcptr-varying-4.ispc b/tests/funcptr-varying-4.ispc new file mode 100644 index 00000000..9ad1be24 --- /dev/null +++ b/tests/funcptr-varying-4.ispc @@ -0,0 +1,25 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + static FuncType func = bar; + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + func = foo; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1 + 1*programIndex; +} diff --git a/tests/funcptr-varying-5.ispc b/tests/funcptr-varying-5.ispc new file mode 100644 index 00000000..f6680d28 --- /dev/null +++ b/tests/funcptr-varying-5.ispc @@ -0,0 +1,26 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + FuncType func; + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + func = (a == 2) ? foo : bar; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 0; + RET[1] = 2; +} diff --git a/tests/funcptr-varying-6.ispc b/tests/funcptr-varying-6.ispc new file mode 100644 index 00000000..a24912e2 --- /dev/null +++ b/tests/funcptr-varying-6.ispc @@ -0,0 +1,24 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + static FuncType func = bar; + float a = aFOO[programIndex]; + float b = aFOO[0]-1; + RET[programIndex] = func(a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 0; +} diff --git a/tests/funcptr-varying-7.ispc b/tests/funcptr-varying-7.ispc new file mode 100644 index 00000000..043d2ff9 --- /dev/null +++ b/tests/funcptr-varying-7.ispc @@ -0,0 +1,24 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + FuncType func[] = { foo, bar }; + float a = aFOO[programIndex]; + float b = aFOO[0]-1; // == 0 + RET[programIndex] = func[(int)b](a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = programIndex+1; +} diff --git a/tests/funcptr-varying-8.ispc b/tests/funcptr-varying-8.ispc new file mode 100644 index 00000000..043d2ff9 --- /dev/null +++ b/tests/funcptr-varying-8.ispc @@ -0,0 +1,24 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return min(a, b); +} + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + FuncType func[] = { foo, bar }; + float a = aFOO[programIndex]; + float b = aFOO[0]-1; // == 0 + RET[programIndex] = func[(int)b](a, b); +} + +export void result(uniform float RET[]) { + RET[programIndex] = programIndex+1; +} diff --git a/tests/funcptr-varying-9.ispc b/tests/funcptr-varying-9.ispc new file mode 100644 index 00000000..c6a2defd --- /dev/null +++ b/tests/funcptr-varying-9.ispc @@ -0,0 +1,25 @@ + +export uniform int width() { return programCount; } + +typedef float (*FuncType)(float, float); + +float foo(float a, float b) { + return a+b; +} + +static float bar(float a, float b) { + return a