← Back to context

Comment by eru

1 month ago

I was more thinking of eg lexicographic comparisons of strings, not just comparing by length.

Yes, if you have a smart enough compiler, or a simple enough comparison, this will simplify.

You could use CMP(A, B) as part of your lexographic comparison and then have it output the result of the first non-zero result (unless you find both strings are equal, in which case, you would output zero) when comparing characters.

If you implement the operators, you can use CMP(A, B) to turn it into a three value output, since it works solely using Boolean logic, but I would be surprised if it simplified. I am half prepared to be surprised since the compiler might do some CSE after inlining and then do some other transformation. That said, you really only want to use CMP(A, B) for numerical comparisons.

  • Yes, you can definitely manually define it. I was talking about what we can reasonably expect the compiler to figure out on its own.