|
|
7-thaumaturgy-7964.md - tgtimes - The Gopher Times |
|
|
 |
git clone git://bitreich.org/tgtimes git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/tgtimes (git://bitreich.org) |
|
|
 |
Log |
|
|
 |
Files |
|
|
 |
Refs |
|
|
 |
Tags |
|
|
 |
README |
|
|
|
--- |
|
|
|
7-thaumaturgy-7964.md (585B) |
|
|
|
--- |
|
|
|
1 # This's opus C Thaumaturgy |
|
|
|
2 |
|
|
|
3 // Returns the smaller integer of x and y but without a branch |
|
|
|
4 // (if/else/ternary, goto etc..) |
|
|
|
5 // Normally min is implemented something like this: |
|
|
|
6 // return x < y ? x : y; |
|
|
|
7 // But we have a branch there so let's do it witout. (The branch |
|
|
|
8 // free min could be used to merge arrays for example.) |
|
|
|
9 // If x < y, then -(x < y) => -1 => all 1's in two complement |
|
|
|
10 // representation. |
|
|
|
11 // So we have y ^ (x ^ y) => x |
|
|
|
12 // If x >= y, then -(x < y) => 0 so y ^ 0 is y. |
|
|
|
13 |
|
|
|
14 static inline uint8_t min(const uint8_t x, const uint8_t y) { |
|
|
|
15 return y ^ ((x ^ y) & -(x < y)); |
|
|
|
16 } |
|