From f97a2d68c8e0ae0e10d11b3f08a415685a899f6f Mon Sep 17 00:00:00 2001 From: "james.brodman" Date: Tue, 22 Oct 2013 18:29:20 -0400 Subject: [PATCH] Bugfix for non-const shift amt and unit tests. --- builtins/util.m4 | 4 +--- tests/shift-1.ispc | 14 ++++++++++++++ tests/shift-2.ispc | 15 +++++++++++++++ tests/shift-3.ispc | 14 ++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 tests/shift-1.ispc create mode 100644 tests/shift-2.ispc create mode 100644 tests/shift-3.ispc diff --git a/builtins/util.m4 b/builtins/util.m4 index 4cb46310..c1582e51 100644 --- a/builtins/util.m4 +++ b/builtins/util.m4 @@ -815,7 +815,6 @@ forloop(i, 1, eval(WIDTH-1), ` %ret_`'i = insertelement %ret_`'eva ret %ret_`'eval(WIDTH-1) not_const: - ; store two instances of the vector into memory %ptr = alloca , i32 3 %ptr0 = getelementptr * %ptr, i32 0 store zeroinitializer, * %ptr0 @@ -824,8 +823,7 @@ not_const: %ptr2 = getelementptr * %ptr, i32 2 store zeroinitializer, * %ptr2 - ; compute offset in [0,vectorwidth-1], then index into the doubled-up vector - %offset = add i32 %1, 16 + %offset = add i32 %1, WIDTH %ptr_as_elt_array = bitcast * %ptr to [eval(3*WIDTH) x $1] * %load_ptr = getelementptr [eval(3*WIDTH) x $1] * %ptr_as_elt_array, i32 0, i32 %offset %load_ptr_vec = bitcast $1 * %load_ptr to * diff --git a/tests/shift-1.ispc b/tests/shift-1.ispc new file mode 100644 index 00000000..2062e36b --- /dev/null +++ b/tests/shift-1.ispc @@ -0,0 +1,14 @@ + +export uniform int width() { return programCount; } + +export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) { + int a = aFOO[programIndex]; + int rot = shift(a, -1); + RET[programIndex] = rot; +} + +export void result(uniform float RET[]) { + varying int val = programIndex; + if (val < 0) val = 0; + RET[programIndex] = val; +} diff --git a/tests/shift-2.ispc b/tests/shift-2.ispc new file mode 100644 index 00000000..6cb88e8a --- /dev/null +++ b/tests/shift-2.ispc @@ -0,0 +1,15 @@ + +export uniform int width() { return programCount; } + +export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) { + int a = aFOO[programIndex]; + uniform int delta = b - 6; // -1 + int rot = shift(a, delta); + RET[programIndex] = rot; +} + +export void result(uniform float RET[]) { + varying int val = programIndex; + if (val < 0) val = 0; + RET[programIndex] = val; +} diff --git a/tests/shift-3.ispc b/tests/shift-3.ispc new file mode 100644 index 00000000..827d076f --- /dev/null +++ b/tests/shift-3.ispc @@ -0,0 +1,14 @@ + +export uniform int width() { return programCount; } + +export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) { + int a = aFOO[programIndex]; + int rot = shift(a, 1); + RET[programIndex] = rot; +} + +export void result(uniform float RET[]) { + varying int val = 2 + programIndex; + if (val > programCount) val = 0; + RET[programIndex] = val; +}