handeli@ocfmail.ocf.llnl.gov (03/14/91)
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. Anybody have such a function?
marcoz@enquirer.scandal.cs.cmu.edu (Marco Zagha) (03/14/91)
In article <789@llnl.LLNL.GOV>, handeli@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@cs.cmu.edu Uucp: ...!seismo!cs.cmu.edu!marcoz Bitnet: marcoz%cs.cmu.edu@cmuccvma CSnet: marcoz%cs.cmu.edu@relay.cs.net