5 ms·
There are styles of programming with no conditionals, especially in purely functional languages. A common technique inside compilers is to separate out which c
by tlb 7y ago
There are styles of programming with no conditionals, especially in purely functional languages.
A common technique inside compilers is to separate out which code gets run, and which result gets used. If everything is side-effect-free, then there's no harm in running the code whose result won't get used. In highly parallel systems, you can just run both versions and select at the end. So you can rewrite:
if foo < 2:
a = foo
else
a = 2
to:
a = phi(foo<2, 2, foo)
(the phi operator is taken from SSA notation. See https://llvm.org/docs/LangRef.html#phi-instruction https://llvm.org/docs/LangRef.html#phi-instruction if you're unfamiliar)
- 2_listerine_pls 7y agoI don't need to understand that code to tell you there is a control flow mechanism somewhere using a condition.