Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!csun!kithrup!sef From: sef@kithrup.COM (Sean Eric Fagan) Newsgroups: comp.lang.c Subject: Re: which bits are set Message-ID: <1990Dec17.071404.6544@kithrup.COM> Date: 17 Dec 90 07:14:04 GMT References: <1990Dec12.205114.2376@uvm.edu> <3047:Dec1618:51:1590@kramden.acf.nyu.edu> Organization: Kithrup Enterprises, Ltd. Lines: 21 In article <3047:Dec1618:51:1590@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >The brute force (i.e., fast) approach is to use a big table. Eek. Why do that? The only way I can think of to do it faster than the presented method is to get rid of the shift and loop: set_bits[0] = val&1; set_bits[1] = val&2; set_bits[2] = val&4; /* ... */ set_bits[31] = val&0x80000000; Takes 32 sequential statements; on some machines, it will take 32 instructions, while on others, it might take 64. It should not take more than that, though (r0 <= val&mask; (set_bits+x) <= r0). -- Sean Eric Fagan | "I made the universe, but please don't blame me for it; sef@kithrup.COM | I had a bellyache at the time." -----------------+ -- The Turtle (Stephen King, _It_) Any opinions expressed are my own, and generally unpopular with others.