Sender: nate AT cartsys DOT com Message-ID: <35BD4E1F.52F0E0D6@cartsys.com> Date: Mon, 27 Jul 1998 21:05:51 -0700 From: Nate Eldredge MIME-Version: 1.0 To: Vladimir Ignatov CC: djgpp AT delorie DOT com Subject: Re: _lrotl replacement References: <35b9deda DOT 40014807 AT news DOT deol DOT ru> <35BA6D01 DOT 3293CF2C AT cartsys DOT com> <35ba8f68 DOT 1442551 AT news DOT deol DOT ru> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Vladimir Ignatov wrote: > > On Sat, 25 Jul 1998 16:40:49 -0700, Nate Eldredge > wrote: > > >Assuming it does something similar to what it did in Turbo C: > > > >/* Non-portable version */ > > > >inline unsigned long _lrotl(unsigned long n, int c) > >{ > > asm("roll %b2, %0" > > : "=g" (n) > > : "0" (n), "ci" (c)); > > return n; > >} > > Wow! Thanks, thats look good. Meanwhile i write own version which is > look like: > > inline int _lrotl > ( > int iValue, > int iRotate > ) > { > asm > ( > "rol %%cl, %0 \n" That should work. Some versions of GAS will apparently choke if the opcode doesn't have the correct suffix ("l", in this case). > : "=r" (iValue) Ok. I used "g" to give the compiler a little more freedom ("g" allows it in a register or memory). > : "c" (iRotate), "0" (iValue) > ); > > return iValue; > } > > So my questions is: > > > asm("roll %b2, %0" > a) That is %b2 mean? Ah. That is deep GCC/asm magic. :) It's an undocumented feature which I learned from Eli, in conjunction with the comment at the top of config/i386/i386.md in the GCC source. Adding "b" to an operand makes it the byte version of that operand. In this case, since operand 2 could have constraint "c", that would convert %ecx to %cl. There are other useful ones, you might want to see that comment. > > > : "0" (n), "ci" (c)); > b) That is "ci" mean? You can combine constraint letters, in which case the compiler will generate the operand as any of the letters you gave. In this case, it can put operand 2 in %ecx ("c") or it can make it an immediate integer constant ("i"). (Actually, come to think of it, for maximum safety, that "i" should be "I", which will limit the constant to the range 0..31. Anything else would be illegal.) -- Nate Eldredge nate AT cartsys DOT com