Stream: cranelift

Topic: ineg vs bnot


view this post on Zulip Firestar99 (Aug 04 2026 at 15:09):

Am I missing something, or what's the difference between ineg and bnot? With ineg being two's complement aka. a bitwise invert, shouldn't they both be the same operation?

In aarch64 lowering, I see ineg lowered into 0 - x whereas bnot turns into orr_not(...). I'd guessisub affects processor flags for eg. nz, overflow, whereas bnot doesn't. But flags aren't modelled in clif, so why make the difference on that level?

view this post on Zulip Chris Fallin (Aug 04 2026 at 15:14):

Two's complement negation is ~x + 1 (negation and bitwise invert are equivalent in ones-complement) -- so they're distinct

view this post on Zulip Firestar99 (Aug 04 2026 at 16:11):

Thanks... now I feel kinda silly for asking this question, but oh well

view this post on Zulip Chris Fallin (Aug 04 2026 at 17:35):

no worries! it's definitely not intuitive at first


Last updated: Aug 30 2026 at 09:07 UTC