MCPcopy Create free account
hub / github.com/antlr/codebuff / lessThanBranchFree

Method lessThanBranchFree

output/java_guava/1.4.19/IntMath.java:109–114  ·  view source on GitHub ↗

Returns 1 if x < y as unsigned integers, and 0 otherwise. Assumes that x - y fits into a signed int. The implementation is branch-free, and benchmarks suggest it is measurably (if narrowly) faster than the straightforward ternary expression.

(int x, int y)

Source from the content-addressed store, hash-verified

107 */
108
109 @VisibleForTesting
110 static int lessThanBranchFree(int x, int y) {
111 // The double negation is optimized away by normal Java, but is necessary for GWT
112 // to make sure bit twiddling works as expected.
113 return ~~ (x - y) >>> (Integer.SIZE - 1);
114 }
115
116 /**
117 * Returns the base-2 logarithm of {@code x}, rounded according to the specified rounding mode.

Callers 4

log2Method · 0.95
log10Method · 0.95
log10FloorMethod · 0.95
sqrtMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected