Dan, thanks for sharing this. It is not an obvious coding technique. With the semantics of code fragment explained, it does make sense & speed!
Kind regards, Abe === Op 03/03/2022 om 23:22 schreef Dan Greiner: > At the risk of sounding pedantic, it's no secret that I think the ROTATE THEN > * SELECTED BITS instructions are the sexiest ops in the architecture. A > former colleague (thanks Tim) recently reminded me of a really cool feature > of the RXSBG instruction that I used to improve a code fragment I've used for > decades. > > For a long time, I've toyed with the following challenge. Given: > ⦁ Register "P" points to the next free location in a buffer, the size and > alignment of which are architecturally integral (i.e., a power of two), and > ⦁ Static value "C" indicates the size and alignment of the buffer in the form > of an characteristic (i.e., 2**C), and > ⦁ Register "L" contains the byte length of a prospective object to be added > to the buffer, > what is the best way to determine whether the object will fit in the buffer. > > Not counting any branch following the determination, I had previously managed > to trim this down to three instructions. For example, to determine if a > prospective insertion crosses a 4 K-byte boundary: > 1. LAY S,-1(L,P) where "S" is a scratch register. > 2. XR S,P determine the difference > 3. NILF S,X'FFFFF000' Turn off insignificant bits. > If the condition code is zero following the AND (NILF) instruction, the > object will fit. Obviously, this needs a little tweaking for 64-bit > addressing, and there are other subtleties as to whether the buffer is > completely full or there is additional remaining space. > > The exclusive-or part of a ROTATE THEN EXCLUSIVE OR SELECTED BITS (RXSBG) > instruction can be used to determine the difference between the beginning and > ending pointers, and the "selected bits" part of RXSBG effectively does the > ANDing to determine if overflow occurred. By using the RXSBGT extended > mnemonic, the test-results control is set such that the condition code > indicates the results. Thus, steps 2 and 3 from above can be combined into: > RXSBGT S,P,0,63-C,0 > > If interested, I have a handy "Will It Fit" macro to accommodate any integral > size.