News Score: Score the News, Sort the News, Rewrite the Headlines

The mask that compiles to nothing: how HotSpot's JIT learned to reason about bits

When a developer types (x << 2) & -4, an optimizing compiler should compile it to just the shift, x << 2: the bitwise AND should disappear. Why? Imagine we have an 8-bit number x = 1011 0111 and my expression looks like (x << 2) & -4; x 1011 0111 (the original x)---------------------- x << 2 1101 1100 (x after lshift, the 2 lowest bits are always 0s) & -4 1111 1100 (-4 in two's complement -> the mask only clears lowest 2 bits)---------------------- result 1101 1...

Read more at questdb.com

© News Score  score the news, sort the news, rewrite the headlines