Re: arm9e: how do I invert sign of a halfword?



Frank Buss <fb@xxxxxxxxxxxxx> wrote:
Everett M. Greene wrote:

VV's (corrected) solution works in all cases. Wilco's
is suspect for large values (>0x40000000), but I haven't
investigated the boundary cases.

It works for values > 0x3fff, because it doesn't matter that
the LSL #17 shift operation shifts the highest bit out of the
32 bit register, because subtracting 0x10000 from any 16 bit
word results still in the same 16 bit word, only the upper
(not present) bits are switched all to 1. Nice solution!

The point I was raising was that shifting a value between
0x4000 and 0x7FFF left one place results in a significant
bit being shifted into the sign bit. There was a question
in my mind as to whether that would work correctly.

I have since run a simulation of the process and find it
works in all cases except the one value of 0x8000. Of
course, no solution works in this case...
.