Integer Selection

| No Comments

A branchless, lookup-free, alternative to code like if (a<b) x=c; else x=d; is ((((a-b) >> (WORDBITS-1)) & (c^d)) ^ d). This code assumes that the shift is signed, which, of course, C does not promise.

Leave a comment

About this Entry

This page contains a single entry by Pete Shanahan published on November 30, 2005 1:25 PM.

Integer Minimum or Maximum was the previous entry in this blog.

Least Significant 1 Bit is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.