Fix issue #2: use zero extend to convert bool->int, not sign extend.
This way, we match C/C++ in that casting a bool to an int gives either the value zero or the value one. There is a new stdlib function int sign_extend(bool) that does sign extension for cases where that's desired.
This commit is contained in:
@@ -20,7 +20,7 @@ export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
|
||||
float v = float4(1,1,0,0);
|
||||
bool b = (v == 1.);
|
||||
ret = __movmsk(((int)b));
|
||||
ret = __movmsk((sign_extend(b)));
|
||||
RET[programIndex] = ret;
|
||||
}
|
||||
|
||||
|
||||
15
tests/sign-extend-1.ispc
Normal file
15
tests/sign-extend-1.ispc
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
|
||||
export void f_f(uniform float RET[], uniform float aFOO[]) {
|
||||
float a = aFOO[programIndex];
|
||||
bool b = (a == 1.);
|
||||
int32 s = sign_extend(b);
|
||||
RET[programIndex] = (s == 0xffffffff) ? 16 : 2;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 2;
|
||||
RET[0] = 16;
|
||||
}
|
||||
14
tests/sign-extend.ispc
Normal file
14
tests/sign-extend.ispc
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
|
||||
export void f_f(uniform float RET[], uniform float aFOO[]) {
|
||||
float a = aFOO[programIndex];
|
||||
bool b = (a == 1.);
|
||||
RET[programIndex] = (int)b;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
RET[0] = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user