RE: [GD-Windows] forcing value to bool 'true' or 'false' (perform ance warning)
Brought to you by:
vexxed72
From: Tom F. <to...@mu...> - 2002-04-23 11:09:22
|
You're surely not going to tell me that bool b = i != 0; doesn't involve a conditional. Anyway, I remember somebody coming up with this: bool b = ((unsigned int)(a|-a))>>31; Whether in practice it's faster or not, I don't know, but there's no conditional jumps required. Tom Forsyth - purely hypothetical Muckyfoot bloke. This email is the product of your deranged imagination, and does not in any way imply existence of the author. > -----Original Message----- > From: Tom Hubina [mailto:to...@3d...] > Sent: 23 April 2002 02:22 > To: gam...@li... > Subject: Re: [GD-Windows] forcing value to bool 'true' or 'false' > (performance warning) > > > At 06:04 PM 4/22/2002, Rich wrote: > >Well, the compiler will generate code to convert an int (4 > bytes) to a > >bool (usually 1 byte), whether or not it matters for performance is > >dubious. > > > >You can eliminate the warning by doing 'bool p = i ? true : false;' > > Icky. You don't need conditionals for this. > > When I convert between int and bool I've been using the > following to get > rid of the warning: > > bool p = i != 0; > > or in the case of Win32 API stuff: > > bool p = i != FALSE; > > In any case ... the performance issue for most cases is > probably minimal. I > would only be concerned if I was doing it inside a tight loop > that got > called a lot and was actually showing up as a spike when > profiling. When in > doubt, check the assembly. > > Tom > > > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > |