I am looking for a signed integer comparison function cmp(x: Int, y: Int) -> Int which does not use any comparison operators (<, <=, >, >=, <=>, etc.), does not use widening to a larger size of integer, and ideally only uses addition, subtraction, bitwise operators and the equality and inequality operators (==, !=).
I have tested the comparison operators here, here and here, but all of them fail for certain input values (here is a test program in Rust). The first two seem the most promising, and they fail for the same values, probably because of underflow in the subtraction.
You didn't specify what
cmpis actually supposed to do. I'm assuming it should calculatex > yas in the test code you link to, that is, this is not a three-way comparison as in some of the other questions you link to.You can then use
(with arithmetic shift and
-wrapping).