Page 1 of 1

local/remote address test in one instruction

PostPosted: Fri Sep 19, 2014 1:36 am
by notzed
The basic test is that the top 12 bits are zero or non-zero:

Code: Select all
   if (((unsigned) ptr) & 0xfff00000) {
   /* is global/remote */
        }


This takes at least 3 instructions and a scratch register. load 0, load $fff0 << 16, and the and.

But the following does the same in one instruction and one scratch register:

Code: Select all
  if ((unsigned int)ptr) >> 20) {
  }


i.e. lsr #20.

Re: local/remote address test in one instruction

PostPosted: Fri Sep 19, 2014 2:32 am
by aolofsson
Very nice!