Add support for "new" and "delete" to the language.

Issue #139.
This commit is contained in:
Matt Pharr
2012-01-27 14:47:06 -08:00
parent bdba3cd97d
commit 664dc3bdda
26 changed files with 938 additions and 167 deletions

View File

@@ -0,0 +1,47 @@
// Must provide function name or function pointer for function call expression
export void saxpy_ispc(uniform int N,
uniform float scale,
uniform float X[],
uniform float Y[],
uniform float result[])
{
foreach (i = 0 ... N) {
result[i] = scale * X[i] + Y[i];
}
}
task void saxpy_ispc_task(uniform int N,
uniform int span,
uniform float scale,
uniform float X[],
uniform float Y[],
uniform float result[])
{
uniform int indexStart;
uniform int indexEnd;
indexStart = (taskIndex * span);
indexEnd = min(N, indexStart + (span)/8);
foreach (i = indexStart ... indexEnd) {
result[i] = scale * X[i] + Y[i];
}
uniform int k =0;
for (k=0; k<8;k++) {
indexStart = (((7-taskIndex-k)%8) * span) + k(span/8);
indexEnd = min(N, indexStart + (span)/8);
foreach (i = indexStart ... indexEnd) {
result[i] = scale * X[i] + Y[i];
}
}
}
export void saxpy_ispc_withtasks(uniform int N,
uniform float scale,
uniform float X[],
uniform float Y[],
uniform float result[])
{
uniform int span = N / 8; // 8 tasks
launch[N/span] < saxpy_ispc_task(N, span, scale, X, Y, result) >;
}

View File

@@ -0,0 +1,5 @@
// Illegal to delete non-pointer type
void func(int a) {
delete a;
}

View File

@@ -0,0 +1,5 @@
// Syntax error
int * func(int a) {
return const new int[a];
}

View File

@@ -0,0 +1,5 @@
// Syntax error
int * func(int a) {
return new int[a](10);
}

View File

@@ -0,0 +1,7 @@
// Type conversion only possible from atomic types
struct P { int x; };
int * func(P p) {
return new int[p];
}

View File

@@ -0,0 +1,5 @@
// Illegal to provide "varying" allocation count with "uniform new" expression
int * func(int x) {
return uniform new int[x];
}

View File

@@ -0,0 +1,5 @@
// Can't convert from varying type "int32 *" to uniform type "int32 * uniform" for return
int * uniform func(int x) {
return new int[x];
}

View File

@@ -0,0 +1,12 @@
// Can't convert from varying type "float" to uniform type "uniform float" for initializer
struct Point {
uniform float x, y, z;
};
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
float a = aFOO[programIndex];
uniform Point * uniform buf = uniform new uniform Point(a, b, 1234.);
RET[programIndex] = buf->y;
delete buf;
}