On Sat, 8 Dec 2001, Frank Heckenbach wrote:
Mirsad Todorovac wrote:
Yes, I've thought about this when I translated the MD5 unit for GPC. Currently it does (left) rotation as (w shl s) or (w shr (32 - s)) (which is translated from similar C code).
The backend seems to have support for rotation, so it might be easy to add it in GPC (I haven't checked yet, but it appears so).
If we do it, I think it should not be operators (because that would change the syntax more than necessary), but rather simple predefines functions (`RotateLeft', `RotateRight'?).
On the other hand, it belongs to the same family of operations as ``shl'' and ``shr'', doesn't it?
Of course, if a range of bytes is rotated, it's very useful to preserve carry flag somewhere - but I guess one has to do asm for that, doesn't he?
I'm not even sure how easy it is in asm. At least on IA32, if my information is correct, "The Carry Flag will contain the value of the last bit rotated out", but the old value of CF is not rotated in, so this would take some extra work, anyway.
On some processors there are both flavors of rotation (through carry, where old carry is rotated in - and rotation where the bit rotated out is rotated directly in).
If i wanted to scroll a large b&w bitmap, I would do it with one instruction per 32 points, while extracting the bit that travels between 32-bit words manually would take at least two additional instruction (masking it out from first word and or-ing it into second), which can be 3x slower.
But this is perhaps only a specific example.
So I guess for the (few, I assume) situations where someone wants to rotate more than one work (not byte), they'll have to do some manual coding, anyway, whether in Pascal or asm. Am I missing something?
well, if I had RORC: (which even ancient Z80 had)
+--+ +--+--+--+--+--+--+--+--+ +-> | | -> | | | | | | | | | -+ | +--+ +--+--+--+--+--+--+--+--+ | | | +---------------------------------------+
Then I could do form of loop unrolled shifting of neghboring words (for example a bitmap picture), sort of:
rorc (r0)+ rorc (r0)+ rorc (r0)+ rorc (r0)+ . . . rorc (r0)+
(in VAX-like assembler) Now, address register is auto-incremented, while carry flag transfers bits that travel between words.
But this is digression from PASCAL thematics - since I can't think of efficient and elegant syntax and semantics for carry flag in pascal.
But calculating a checksum that would be xor-ed and rotated with each new word isn't hard ot imagine, and isn't that rare use.
Marvin (I feel better as Marvin, my nickname from college than my real name).
-- This message has been made up using recycled ideas and language constructs. No plant or animal has been injured in process of making this message.