Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!ub!uhura.cc.rochester.edu!rochester!pt.cs.cmu.edu!enquirer.scandal.cs.cmu.edu!marcoz From: marcoz@enquirer.scandal.cs.cmu.edu (Marco Zagha) Newsgroups: comp.unix.wizards Subject: Re: bit movers Summary: Use Cray C intrinsics Message-ID: <12349@pt.cs.cmu.edu> Date: 14 Mar 91 07:48:21 GMT References: <789@llnl.LLNL.GOV> Organization: Carnegie-Mellon University, CS/RI Lines: 31 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