|
|
|
|
|
by juliusgeo
1144 days ago
|
|
I was considering doing it all in a ternary statement, but I feel that the current form is also branchless because it is simply a multiply and add. The extra bounds-checking condition can probably be omitted, but I haven't tested that. for (step >>= 1; step != 0; step >>=1) {
if ((next = begin + step) < size) {
begin += PyObject_RichCompareBool(PyList_GetItem(list_obj, next), value, Py_LT) * step;
}
}
|
|
If there's no calculation being done, it'll simplify.
But if calculations are being done, it won't. If you want non-branching where the ternary options are calculated, you need to calculate both.This matters most with SIMD operations.
Look at section 2.5.1 (Branch-Equivalent SIMD Processing)
http://ftp.cvut.cz/kernel/people/geoff/cell/ps3-linux-docs/C...