At 22:51 -0400 on 05/28/2012, Tony Thigpen wrote about Generating a bit mask:
I am working with some IPv6 addresses that are 128 bits long. The input to the program is an ip name or address and the number of high bits that I need to use for a compare against another ip address. So, I want to create run time routine to build the a 16 byte 'and' bit field based on the input number of bits. (I will then 'and' both addresses and then use a simple CLC.) Although a table built at compile time might be a reasonable solution, I thought this would be a good time to learn a new trick if someone has one they can share. -- Tony Thigpen
The solution is simple (I will leave the code for you). 1) Make the mask 2 double words (TOP and BOTTOM) and set both to all 0 bits. 2) Load a register with all 1 bits (64 bits). 3) LA R2,TOP 3) If length is 64 or more then save register via R2 (making TOP all 1 bits) and LA R2,BOTTOM. 4) If length is 64, you are done. 5) If length is less than 64 make SHIFT 64-length. Otherwise make SHIFT 128-length. 6) Shift the 64 bit register right SHIFT bits and then left SHIFT bits [This makes the low bits zeros] and store register via R2 (into TOP or BOTTOM).
