Add avg_{up,down}_int{8,16} routines to stdlib

These compute the average of two given values, rounding up and down,
respectively, if the result isn't exact.  When possible, these are
mapped to target-specific intrinsics (PADD[BW] on IA and VH[R]ADD[US]
on NEON.)

A subsequent commit will add pattern-matching to generate calls to
these intrinsincs when the corresponding patterns are detected in the
IR.)
This commit is contained in:
Matt Pharr
2013-08-03 20:44:25 -07:00
parent 4f48d3258a
commit 5b20b06bd9
23 changed files with 592 additions and 15 deletions

13
tests/avg-down-int16.ispc Normal file
View File

@@ -0,0 +1,13 @@
export uniform int width() { return programCount; }
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float bf) {
int16 a = aFOO[programIndex];
int16 b = bf;
RET[programIndex] = avg_down(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = ((int)programIndex + 1 + 5) / 2;
}

13
tests/avg-down-int8.ispc Normal file
View File

@@ -0,0 +1,13 @@
export uniform int width() { return programCount; }
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float bf) {
int8 a = aFOO[programIndex];
int8 b = bf;
RET[programIndex] = avg_down(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = ((int)programIndex + 1 + 5) / 2;
}

View File

@@ -0,0 +1,13 @@
export uniform int width() { return programCount; }
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float bf) {
unsigned int16 a = aFOO[programIndex];
unsigned int16 b = bf;
RET[programIndex] = avg_down(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = ((int)programIndex + 1 + 5) / 2;
}

13
tests/avg-down-uint8.ispc Normal file
View File

@@ -0,0 +1,13 @@
export uniform int width() { return programCount; }
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float bf) {
unsigned int8 a = aFOO[programIndex];
unsigned int8 b = bf;
RET[programIndex] = avg_down(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = ((int)programIndex + 1 + 5) / 2;
}

13
tests/avg-up-int16.ispc Normal file
View File

@@ -0,0 +1,13 @@
export uniform int width() { return programCount; }
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float bf) {
int16 a = aFOO[programIndex];
int16 b = bf;
RET[programIndex] = avg_up(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = ((int)programIndex + 1 + 5 + 1) / 2;
}

13
tests/avg-up-int8.ispc Normal file
View File

@@ -0,0 +1,13 @@
export uniform int width() { return programCount; }
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float bf) {
int8 a = aFOO[programIndex];
int8 b = bf;
RET[programIndex] = avg_up(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = ((int)programIndex + 1 + 5 + 1) / 2;
}

13
tests/avg-up-uint16.ispc Normal file
View File

@@ -0,0 +1,13 @@
export uniform int width() { return programCount; }
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float bf) {
unsigned int16 a = aFOO[programIndex];
unsigned int16 b = bf;
RET[programIndex] = avg_up(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = ((int)programIndex + 1 + 5 + 1) / 2;
}

13
tests/avg-up-uint8.ispc Normal file
View File

@@ -0,0 +1,13 @@
export uniform int width() { return programCount; }
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float bf) {
unsigned int8 a = aFOO[programIndex];
unsigned int8 b = bf;
RET[programIndex] = avg_up(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = ((int)programIndex + 1 + 5 + 1) / 2;
}