Skip to content

Commit fceb3d1

Browse files
committed
Optimize to remove integer division by two in op_or() computation.
1 parent c19d5cf commit fceb3d1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/toGLSL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ void ToGLSL::UseExtraFunctionDependency(const std::string &name)
10631063
}
10641064
else if (name == "op_or")
10651065
{
1066-
bformata(code, "int op_or(int a, int b) { int result = (a < 0 || b < 0) ? -2147483648 : 0; if (a < 0) a -= -2147483648; if (b < 0) b -= -2147483648; int n = 1; ivec2 ab = ivec2(a, b); for (int i = 0; i < 31; i++) { ivec2 ab_div = ab / 2; ivec2 ab_rem = ab - ab_div*2; result += n * ((ab_rem.x + ab_rem.y + 1) / 2); ab = ab_div; n += n; } return result; }\n");
1066+
bformata(code, "int op_or(int a, int b) { int result = (a < 0 || b < 0) ? -2147483648 : 0; if (a < 0) a -= -2147483648; if (b < 0) b -= -2147483648; int n = 1; ivec2 ab = ivec2(a, b); for (int i = 0; i < 31; i++) { ivec2 ab_div = ab / 2; ivec2 ab_rem = ab - ab_div*2; result += n * (ab_rem.x + ab_rem.y - ab_rem.x*ab_rem.y); ab = ab_div; n += n; } return result; }\n");
10671067
PrintComponentWrapper2(code, "op_or", "ivec2", "ivec3", "ivec4");
10681068
}
10691069
else if (name == "op_xor")

0 commit comments

Comments
 (0)