[LLVMdev] Saturation Arithmetic Canonical Form?

Josh Klontz josh.klontz at gmail.com
Thu Nov 7 13:54:58 PST 2013


Are there best practices regarding how to express saturation arithmetic in
LLVM IR? In particular I want to make sure the IR translates efficiently to
(SSE) vector instructions when executed in a simple loop.

My first thought was to implement this naively by zero extending and
branching on the minimum and maximum values. However, I'm also aware of
branchfree alternatives[1]. Do the current instruction selection algorithms
favor one of these forms over the other? I haven't been able to find any
definitive answers on this after having read [2-5]. Perhaps I'm overlooking
a component of the C++ API that makes this easy?

Thanks in advance!
-Josh

[1] http://locklessinc.com/articles/sat_arithmetic/
[2] http://llvm.org/docs/LangRef.html#add-instruction
[3] http://llvm.1065342.n5.nabble.com/overflow-saturation-stuff-td30736.html
[4] http://llvm.1065342.n5.nabble.com/max-min-intrinsics-td52307.html
[5] http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-June/040843.html



--
View this message in context: http://llvm.1065342.n5.nabble.com/Saturation-Arithmetic-Canonical-Form-tp62979.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.



More information about the llvm-dev mailing list