www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/25/20:01:21

Sender: nate AT cartsys DOT com
Message-ID: <35BA6D01.3293CF2C@cartsys.com>
Date: Sat, 25 Jul 1998 16:40:49 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
MIME-Version: 1.0
To: Vladimir Ignatov <ignatov AT deol DOT ru>
CC: djgpp AT delorie DOT com
Subject: Re: _lrotl replacement
References: <35b9deda DOT 40014807 AT news DOT deol DOT ru>

Vladimir Ignatov wrote:
> 
> Hello
> 
> I have some Visual C  C++ sources with  _lrotl  function (cyclic
> rotate left).  Seem it is MS extension to standart C library. Which
> replacement can i use with GCC 2.8.1 ?

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;
}

/* More portable version */
/* For constant `c', GCC should optimize it into a single `roll'
instruction (!) */

#include <limits.h>
inline unsigned long _lrotl(unsigned long n, int c)
{
   return (n << c) | (n >> ((sizeof(unsigned long) * CHAR_BIT) - c));
}

HTH
-- 

Nate Eldredge
nate AT cartsys DOT com


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019