@whitequark try using different constants to suicide by; this is a special case of since mine and this approach usually requires a small correction afterwards (to the tube of conditionally adding one or something like that).

Or am I misreading and this is more witchy?

Follow

@whitequark of I remember by the time I'm home in the evening I will get godbolt to spit out the more general case of this witchery

@whitequark

All compilers I've seen can do this optimization. See for example godbolt.org/z/v34E58deK, which has the "add a fixup from the upper word of the multiplication result". The reason why it's necessary is that you don't actually want multiplicative inverse modulo 2^wordsize in the case when the input value is not divisible by the constant.

@whitequark Sorry, my example was wrong (the weirdness in there was purely to handle rounding in negatives).

godbolt.org/z/WTajrPKze is an example with the additional weirdness I was thinking of.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.