bit movers

Marco Zagha marcoz at enquirer.scandal.cs.cmu.edu
Thu Mar 14 17:48:21 AEST 1991


In article <789 at llnl.LLNL.GOV>, handeli at ocfmail.ocf.llnl.gov writes:
> I need a C function which can move arbitrary
> bits around from one memory location to another
> with a bit offset of anything. For example,
> the call might look like
> 
> movebits(a1,ioff1,a2,ioff2,nbits)
> 
> where a1 and a2 are char arrays
> ioff1 and ioff2 are bit offsets into the
> char arrays
> nbits is the number of bits to move.
> a1 might be source address and a2 might be
> destination address.

I assume that since you cross-posted this to comp.unix.cray,
that you want a Cray routine?  If so, look into the C
intrinsics.  In particular,

	_gbits(x, y, z) -- get y bits, starting at the zth bit of x

Aside from putting a loop around the function and handling
word boundaries, you should be able to write a simple, efficient
routine.  You should compile your code with "-h intrinsics"
so that the compiler generates inline code instead of a function
call.

== Marco Zagha
Carnegie Mellon School of Computer Science
Internet: marcoz at cs.cmu.edu            Uucp:   ...!seismo!cs.cmu.edu!marcoz  
Bitnet:   marcoz%cs.cmu.edu at cmuccvma   CSnet:  marcoz%cs.cmu.edu at relay.cs.net



More information about the Comp.unix.wizards mailing list