From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,e489d6e4973d889f X-Google-Attributes: gid1164f8,public X-Google-Thread: 102b75,e489d6e4973d889f X-Google-Attributes: gid102b75,public X-Google-Thread: 115614,e489d6e4973d889f X-Google-Attributes: gid115614,public X-Google-ArrivalTime: 2001-08-31 03:10:33 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!148.122.208.68!news2.oke.nextra.no!nextra.com!hydro.com!not-for-mail From: Terje Mathisen Newsgroups: comp.arch,comp.sys.dec,comp.unix.aix Subject: Re: Can POWER4, 5 etc continue where Alpha was stopped? Date: Fri, 31 Aug 2001 12:09:07 +0200 Organization: Hydro Message-ID: <3B8F6243.F26ABBB0@hda.hydro.com> References: <88525dde.0108260914.7c63d8c3@posting.google.com> <9mgps0$12ee$1@ausnews.austin.ibm.com> <9mhbh0$pbq$1@ausnews.austin.ibm.com> <3B8C8AC4.59ED22CB@hda.hydro.com> NNTP-Posting-Host: no115350c8.hda.hydro.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en Xref: archiver1.google.com comp.arch:16066 comp.sys.dec:6854 comp.unix.aix:22886 Maynard Handley wrote: > > In article <3B8C8AC4.59ED22CB@hda.hydro.com>, Terje Mathisen > wrote: > > Optimized code can indeed make use of a fast way to determine if a > > number is a power of two, I've used that particular idiom several times. > > I think the main thing is to ensure that things like this are wrapped in a > macro rather than directly in the code. Not only does that make the code > much easier to read but it allows one to restructure the macro if > appropriate to a new platform. (Unlikely for this example, but can be > likely in other situations eg when one moves from big to little-endian.) Absolutely! In my own code I've tried to use this kind of stuff inside a macro, i.e. if (ispowerof2(n)) { ... } This also makes it much easier to replace the macro with a function, something that would be needed if I later needed to switch to a different (fp?) number format. BTW, the same test on a single prec fp number is even easier, since it just needs to verify that the fractional part of the mantissa is zero: #define float_ispowerof2(n) (((*(t_uint32 *) &n) & 0x07ffffff) == 0) Terje -- - Using self-discipline, see http://www.eiffel.com/discipline "almost all programming can be viewed as an exercise in caching"