It is a bit early in the morning :-D
What I really meant to ask, was can we take an expression that is 0 or non-zero and convert it to 0 or -1. Either an all-0 or all-1 bitmask.
0->0
non-zero->-1
With pure arithmetic and no conditional statements. With conditional statements, there are many ways and all are easy. But without, its not as simple.
I noticed that (A OR -A) = 0 for 0, but turns the high bit on except for the sign bit power of 2 value e.g. 0x80000000. Perhaps using CDQ.
Code:
mov eax, [val]
mov edx, eax
neg edx
or eax, edx
cdq
mov eax, edx
Could that really be the simplest algorithm to do it?
The only other interesting property like this I could think of is <0 -> -1, 0 -> 0, >1 ->1 which also would be about as tricky without conditionals and purely arithmetically.
Actually you do something along the lines of multiply the output of previous code by the carry flag after subtracting from 0(sub, adc, mul) and I don't think you can avoid the mul.
Any thoughts