-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// The test checks that template non-type parameters can be used to set an array dimension. | ||
// RUN: %{ispc} %s --ast-dump --target=host --nostdlib | FileCheck %s -check-prefix=CHECK-AST | ||
// RUN: %{ispc} %s --target=host --nostdlib -o %t.o | ||
|
||
// CHECK-AST: FunctionTemplate {{.*}} [ void(varying float * uniform arr)] "func" | ||
// CHECK-AST: Variable O (uniform float[C]) | ||
// CHECK-AST: (instantiation <64>) {{.*}} [ void(varying float * uniform arr)] "func" | ||
// CHECK-AST: Variable O (uniform float[64]) | ||
|
||
template <int C> noinline void func(float arr[C]) { | ||
uniform float O[C] = {0}; | ||
arr[programIndex] = O[programIndex]; | ||
} | ||
|
||
void test(float x[]) { | ||
func<64>(x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// The test checks that template type and non-type parameters can be used to declare an array. | ||
// RUN: %{ispc} %s --ast-dump --target=host --nostdlib | FileCheck %s -check-prefix=CHECK-AST | ||
// RUN: %{ispc} %s --target=host --nostdlib -o %t.o | ||
|
||
// CHECK-AST: FunctionTemplate {{.*}} [ void(uniform T * uniform arr)] "func" | ||
// CHECK-AST: Variable O (uniform T[C]) | ||
// CHECK-AST: (instantiation <varying float, 64>) {{.*}} [ void(uniform float * uniform arr)] "func" | ||
// CHECK-AST: Variable O (uniform float[64]) | ||
|
||
template <typename T, int C> noinline void func(uniform T arr[C]) { | ||
uniform T O[C] = {0}; | ||
arr[programIndex] = O[programIndex]; | ||
} | ||
|
||
void test(uniform float x[]) { | ||
func<float, 64>(x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// The test checks that enum type can be used for array indexing | ||
// RUN: %{ispc} %s --ast-dump --target=host --nostdlib | FileCheck %s | ||
// RUN: %{ispc} %s --target=host --nostdlib -o %t.o | ||
|
||
// CHECK: FunctionTemplate {{.*}} [ /*unbound*/ T(varying int32 * uniform a)] "func" | ||
// CHECK Variable arr (/*unbound*/ T[C]) | ||
// CHECK: (instantiation <varying int32, 64, 0, 3>) {{.*}} [ varying int32(varying int32 * uniform a)] "func" | ||
// CHECK: ReturnStmt | ||
// CHECK: IndexExpr | ||
// CHECK: SymbolExpr {{.*}} [varying int32[64]] symbol name: arr | ||
// CHECK: ConstExpr {{.*}} [const uniform int64] (0) | ||
// CHECK: IndexExpr | ||
// CHECK: SymbolExpr {{.*}} [varying int32[64]] symbol name: arr | ||
// CHECK: ConstExpr {{.*}} [const uniform int64] (3) | ||
|
||
enum Foo { | ||
ZERO, | ||
ONE, | ||
TWO, | ||
THREE | ||
}; | ||
|
||
template<typename T, uint C, Foo N1, Foo N2> | ||
noinline T func(int a[]) { | ||
T arr[C]; | ||
for (uniform uint i = 0; i < C; i++) { | ||
arr[i] = a[i] + i; | ||
} | ||
return arr[N1] + arr[N2]; | ||
} | ||
|
||
int test(int a[]) { | ||
return func<int, 64, ZERO, THREE>(a); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This test checks function overloading when arrays are used as parameter | ||
// RUN: %{ispc} %s --emit-llvm-text --target=host --nostdlib -o - | FileCheck %s | ||
// CHECK-LABEL: define void @func__ | ||
// CHECK-LABEL: define void @test___ | ||
// CHECK: call void @func___vyfCuni64Cuni32 | ||
// CHECK-LABEL: define linkonce_odr void @func___vyfCuni64Cuni32 | ||
|
||
noinline void func(uniform float arr1[64], uniform float arr2[32]) { | ||
uniform float O[64] = {0}; | ||
arr1[programIndex] = O[programIndex] + arr2[programIndex]; | ||
} | ||
|
||
template <typename T, int C1, int C2> noinline void func(uniform T arr1[C1], uniform T arr2[C2]) { | ||
uniform T O[C1] = {0}; | ||
arr2[programIndex] = O[programIndex] + arr2[programIndex]; | ||
} | ||
|
||
void test(uniform float x[], uniform float y[]) { | ||
func<float, 64, 32>(x, y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// This test checks that multidimensional array can be created using template parameters. | ||
// RUN: %{ispc} %s --emit-llvm-text --target=host --nostdlib -o - | FileCheck %s | ||
|
||
// CHECK-LABEL: define linkonce_odr void @func___Cuni1Cuni2Cuni3Cuni4Cuni5Cuni6 | ||
// CHECK: <{{.*}} x float> <float 4.000000e+00, | ||
// REQUIRES: X86_ENABLED | ||
|
||
template<int N1, int N2, int N3, int N4, int N5, int N6> | ||
noinline void func(uniform float RET[]) { | ||
float a[][N2][] = { { { N1 }, { N2 } }, { { N3 }, { N4 } }, { { N5 }, { N6 } } }; | ||
RET[programIndex] = a[N1][N1][0]; | ||
} | ||
|
||
void test(uniform float RET[]) { | ||
func<1, 2, 3, 4, 5, 6>(RET); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// This tests checks multidimensional arrays inside nested templates | ||
// RUN: %{ispc} %s --emit-llvm-text --target=host --nostdlib -o - | FileCheck %s | ||
|
||
// CHECK-LABEL: @test___ | ||
// CHECK: call {{.*}} @foo_level_1___vyiCuni64 | ||
// CHECK: @foo_level_1___vyiCuni64__ | ||
// CHECK: alloca [64 x [64 x [64 x i32]]] | ||
// CHECK: call {{.*}} @foo_level_2___vyiCuni64 | ||
// CHECK: @foo_level_2___vyiCuni64 | ||
// CHECK: alloca [64 x [64 x [64 x i32]]] | ||
|
||
template <typename T, int C> | ||
noinline void foo_level_2(uniform float ret[], uniform int b[C][C][C]) { | ||
uniform int a[C][C][C]; | ||
for (uniform int i = 0; i < C; ++i) | ||
for (uniform int j = 0; j < C; ++j) | ||
for (uniform int k = 0; k < C; ++k) { | ||
a[i][j][k] = 100*i+10*j+k; | ||
b[i][j][k] = 100*i+10*j-k; | ||
} | ||
|
||
ret[programIndex] = *(a[2][3] + 1); | ||
} | ||
|
||
template <typename T, int C> | ||
noinline void foo_level_1(uniform float ret[]) { | ||
uniform int a[C][C][C]; | ||
foo_level_2<T, C>(ret, a); | ||
} | ||
|
||
void test(uniform float ret[]) { | ||
foo_level_1<int, 64>(ret); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Check out of bounds warning for arrays inside templates. | ||
// RUN: %{ispc} --target=host --nowrap --nostdlib %s 2>&1 | FileCheck %s | ||
|
||
// CHECK-COUNT-1: Warning: Array index "8" may be out of bounds for 8 element array. | ||
|
||
template <int C> void testArrayAccess(uniform int ret[], uniform int arr[]) | ||
{ | ||
uniform int O[C] = {0}; | ||
ret[0] = O[arr[0] % C]; // Valid access | ||
ret[1] = O[C]; // Non-Valid access | ||
} | ||
|
||
void test(uniform int ret[], uniform int arr[]) { | ||
testArrayAccess<8>(ret, arr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Check compiler diagnostics when arrays are declared incorrectly inside templates. | ||
// RUN: not %{ispc} --target=host --nowrap --nostdlib %s -o - 2>&1 | FileCheck %s | ||
|
||
// CHECK: Error: Illegal to assign to array type "varying float[5]" | ||
template <typename T, uint C> | ||
void doo(uniform T *varying x) { | ||
T a[C] = { 1,2,3,4,5}; | ||
a += 3; | ||
} | ||
|
||
void test(float *x) { | ||
doo<float, 5>(x); | ||
} | ||
|
||
// CHECK: Error: Arrays with unsized dimensions in dimensions after the first one are illegal in function parameter lists | ||
template <uint C> | ||
void func(int a[C][]) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Check that custom variable can't be used as template argument (yet). | ||
|
||
// RUN: not %{ispc} --target=host --nowrap --nostdlib %s -o - 2>&1 | FileCheck %s | ||
// CHECK: Only integral, enum types and non-type template parameters are allowed as template arguments. | ||
|
||
template <int C> noinline void func(float arr[C]) { | ||
uniform float O[C] = {0}; | ||
arr[programIndex] = O[programIndex]; | ||
} | ||
|
||
void test(float x[]) { | ||
uniform int N = 32; | ||
func<N>(x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters