Add memcpy(), memmove() and memset() to the standard library.

Issue #183.
This commit is contained in:
Matt Pharr
2012-03-05 16:09:00 -08:00
parent c152ae3c32
commit 3b95452481
9 changed files with 338 additions and 3 deletions

17
tests/memcpy-uniform.ispc Normal file
View File

@@ -0,0 +1,17 @@
export uniform int width() { return programCount; }
export void f_f(uniform float RET[], uniform float aFOO[]) {
int32 * uniform src = uniform new int32[1024];
int32 * uniform dst = uniform new int32[1024];
foreach (i = 0 ... 1024)
src[i] = i;
memcpy(&dst[32], src, (1024-32)*sizeof(uniform int));
RET[programIndex] = dst[64+programIndex];
}
export void result(uniform float RET[]) {
RET[programIndex] = 32 + programIndex;
}

21
tests/memcpy-varying.ispc Normal file
View File

@@ -0,0 +1,21 @@
export uniform int width() { return programCount; }
export void f_f(uniform float RET[], uniform float aFOO[]) {
int32 *src = new int32[1024];
int32 *dst = new int32[1024];
for (uniform int i = 0; i < 1024; ++i)
src[i] = programIndex * 10000 + i;
if (programIndex == 2)
memcpy(dst, src, programCount*sizeof(uniform int));
else
memcpy(dst, src, programCount*sizeof(uniform int));
RET[programIndex] = dst[programIndex];
}
export void result(uniform float RET[]) {
RET[programIndex] = 10000 * programIndex + programIndex;
}

View File

@@ -0,0 +1,16 @@
export uniform int width() { return programCount; }
export void f_f(uniform float RET[], uniform float aFOO[]) {
int32 * uniform buf = uniform new int32[1024];
foreach (i = 0 ... 1024)
buf[i] = i;
memmove(&buf[1], buf, (1024-1)*sizeof(uniform int));
RET[programIndex] = buf[programIndex];
}
export void result(uniform float RET[]) {
RET[programIndex] = max(0, programIndex-1);
}

View File

@@ -0,0 +1,19 @@
export uniform int width() { return programCount; }
export void f_f(uniform float RET[], uniform float aFOO[]) {
int32 *buf = new int32[1024];
for (uniform int i = 0; i < 1024; ++i)
buf[i] = programIndex * 10000 + i;
if (programIndex == 2)
memmove(buf, buf+programCount/2, programCount*sizeof(uniform int));
RET[programIndex] = buf[0];
}
export void result(uniform float RET[]) {
RET[programIndex] = 10000 * programIndex;
RET[2] = 10000 * 2 + programCount/2;
}

16
tests/memset-uniform.ispc Normal file
View File

@@ -0,0 +1,16 @@
export uniform int width() { return programCount; }
export void f_f(uniform float RET[], uniform float aFOO[]) {
int32 * uniform buf = uniform new int32[1024];
buf[0] = 0;
memset(buf+1, 0x7f, 1024*sizeof(uniform int32));
int v = buf[programIndex];
RET[programIndex] = (v == 0x7f7f7f7f);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1;
RET[0] = 0;
}

21
tests/memset-varying.ispc Normal file
View File

@@ -0,0 +1,21 @@
export uniform int width() { return programCount; }
export void f_f(uniform float RET[], uniform float aFOO[]) {
int32 * varying buf = varying new int32[1024*(programIndex+1)];
if (programIndex & 1) {
memset(buf, 0xff, 1024*(programIndex+1)*sizeof(uniform int32));
}
else {
memset(buf, 0x01, 1024*(programIndex+1)*sizeof(uniform int32));
}
int v = buf[0];
int expected = (programIndex & 1) ? 0xffffffff : 0x01010101;
RET[programIndex] = (v == expected);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1;
}