pouët.net

chunky to planar

category: code [glöplog]
Quote:
@krabob: IIRC it's hidden somewhere here:
http://graphics.stanford.edu/~seander/bithacks.html

Nice page, but it doesn't seem to contain anything about clamping or saturating addition, or even computations on individual bytes in parallel, apart from detecting a specific byte value.
added on the 2011-02-03 08:56:35 by Blueberry Blueberry
Quote:
Compute the minimum (min) or maximum (max) of two integers without branching

Isn't that clamping ?
It is, though the first version
Quote:
r = y ^ ((x ^ y) & -(x < y)); // min(x, y)
isn't really without branching, as the comparison will usually be compiled into a branch.

Clamping to a power of two minus one is not mentioned as a special case, though. There are special tricks for that (as discussed in the ADA thread).
added on the 2011-02-03 16:05:26 by Blueberry Blueberry
yeah thanks, that's the thread I was searching for ! I dunno why I thought windden posted on it.
When akawalampadu was out, I understood you did it after that thread, perfect job as always !!
And fucking good double trick !
added on the 2011-02-03 20:37:02 by krabob krabob
Yeah I know I'm late, but...

Quote:

Code:r = y ^ ((x ^ y) & -(x < y)); // min(x, y)

isn't really without branching, as the comparison will usually be compiled into a branch.

Well that depends on your platform, e.g. MIPS has "slt", and x86 has set* and cmov.
added on the 2011-04-23 11:00:56 by ryg ryg
68k CPUs also have Scc opcodes.
added on the 2011-04-23 11:22:47 by hitchhikr hitchhikr

login