local/remote address test in one instruction

local/remote address test in one instruction

Postby notzed » Fri Sep 19, 2014 1:36 am

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.
notzed
 
Posts: 331
Joined: Mon Dec 17, 2012 12:28 am
Location: Australia

Re: local/remote address test in one instruction

Postby aolofsson » Fri Sep 19, 2014 2:32 am

Very nice!
User avatar
aolofsson
 
Posts: 1005
Joined: Tue Dec 11, 2012 6:59 pm
Location: Lexington, Massachusetts,USA


Return to Assembly

Who is online

Users browsing this forum: No registered users and 1 guest