support of operators

This commit is contained in:
Ilia Filippov
2013-10-07 15:43:31 +04:00
parent 2741e3c1d0
commit 2e724b095e
7 changed files with 299 additions and 45 deletions

70
tests/operators.ispc Normal file
View File

@@ -0,0 +1,70 @@
export uniform int width() { return programCount; }
struct S {
float a;
};
// References "struct&" were put in random order to test them.
struct S operator*(struct S& rr, struct S rv) {
struct S c;
c.a = rr.a + rv.a + 2;
return c;
}
struct S operator/(struct S& rr, struct S& rv) {
struct S c;
c.a = rr.a - rr.a + 2;
return c;
}
struct S operator%(struct S rr, struct S& rv) {
struct S c;
c.a = rr.a + rv.a + 2;
return c;
}
struct S operator+(struct S rr, struct S rv) {
struct S c;
c.a = rr.a / rv.a + 3;
return c;
}
struct S operator-(struct S rr, struct S& rv) {
struct S c;
c.a = rr.a + rv.a + 2;
return c;
}
struct S operator>>(struct S& rr, struct S rv) {
struct S c;
c.a = rr.a / rv.a + 3;
return c;
}
struct S operator<<(struct S& rr, struct S& rv) {
struct S c;
c.a = rr.a + rv.a + 2;
return c;
}
struct S a, a1;
struct S b, b1;
struct S d1, d2, d3, d4, d5, d6, d7;
export void f_f(uniform float RET[], uniform float aFOO[]) {
a.a = aFOO[programIndex];
b.a = -aFOO[programIndex];
d1 = a * b;
d2 = a / b;
d3 = a % b;
d4 = a + b;
d5 = a - b;
d6 = a >> b;
d7 = a << b;
RET[programIndex] = d1.a + d2.a + d3.a + d4.a + d5.a + d6.a + d7.a;
}
export void result(uniform float RET[4]) {
RET[programIndex] = 14;
}

64
tests/operators1.ispc Normal file
View File

@@ -0,0 +1,64 @@
export uniform int width() { return programCount; }
struct S {
float a;
};
// References "struct&" were put in random order to test them.
struct S operator*(struct S& rr, struct S rv) {
struct S c;
c.a = rr.a + rv.a + 2;
return c;
}
struct S operator/(struct S& rr, struct S& rv) {
struct S c;
c.a = rr.a - rr.a + 2;
return c;
}
struct S operator%(struct S rr, struct S& rv) {
struct S c;
c.a = rr.a + rv.a + 2;
return c;
}
struct S operator+(struct S rr, struct S rv) {
struct S c;
c.a = rr.a / rv.a + 3;
return c;
}
struct S operator-(struct S rr, struct S& rv) {
struct S c;
c.a = rr.a + rv.a + 2;
return c;
}
struct S operator>>(struct S& rr, struct S rv) {
struct S c;
c.a = rr.a / rv.a + 3;
return c;
}
struct S operator<<(struct S& rr, struct S& rv) {
struct S c;
c.a = rr.a + rv.a + 2;
return c;
}
struct S a;
struct S b;
struct S d;
export void f_f(uniform float RET[], uniform float aFOO[]) {
a.a = 5;
b.a = -5;
d = a * b + b / a - a << (b - b) - a;
RET[programIndex] = d.a;
}
export void result(uniform float RET[4]) {
RET[programIndex] = 12;
}

51
tests/operators2.ispc Normal file
View File

@@ -0,0 +1,51 @@
int off;
export uniform int width() { return programCount; }
struct S {
float a;
};
struct S operator+(struct S rr, struct S rv) {
struct S c;
c.a = rr.a / rv.a + 3;
if (off == 1)
c.a = 22;
return c;
}
struct S operator/(struct S rr, struct S rv) {
struct S c;
c.a = rr.a + rv.a + 10;
if (off == 1)
c.a = 33;
return c;
}
struct S a;
struct S b;
struct S d;
export void f_f(uniform float RET[], uniform float aFOO[]) {
int T = programIndex;
a.a = aFOO[programIndex];
b.a = -aFOO[programIndex];
if (programIndex == 3)
off = 1;
else
off = 0;
if (T % 2)
d = a + b;
else
d = a / b;
RET[programIndex] = d.a;
}
export void result(uniform float RET[4]) {
if (programIndex % 2)
RET[programIndex] = 2;
else
RET[programIndex] = 10;
RET[3] = 22;
}