A relatively new machine instruction, FIND LEFTMOST ONE (FLOGR R1,R2) may be helpful here (if the extended-immediate facility is available).
FLOGR returns in R1 the bit position (0-63) of the first one-bit encountered in a 64-bit register (R2), left-to-right. If the register is zero, then 64 (40 hex) is returned. There's a little more to this, described in the POP manual. Another instruction, perhaps less likely to help in this case, is POPULATION COUNT (POPCNT R1,R2), which counts the number of one-bits in each of the eight bytes of a 64-bit register. Essentially, it returns eight sums. -----Original Message----- From: IBM Mainframe Assembler List [mailto:[email protected]] On Behalf Of robin Sent: Tuesday, May 29, 2012 8:00 AM To: [email protected] Subject: Re: Generating a bit mask From: Tony Thigpen Sent: Tuesday, 29 May 2012 12:51 PM >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.) A good way is to determine the bit start position. Put 8 bits in a GPR. If shift is 1 thru 7, shift right the required no. of bits. Then store that. For the end byte, do the same, only shift left. For the bytes between the initial byte and end byte, store zero or more characters (each of 8 one-bits). >Although a table built at compile time might be a reasonable solution, How so? You say that the number of bits is input -- i.e. not a compile-time value. > I thought this would be a good time to learn a new trick if someone >has one they can share.
