Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2001:
[Freeciv-Dev] Re: Profiling Civserver again
Home

[Freeciv-Dev] Re: Profiling Civserver again

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Profiling Civserver again
From: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Date: Wed, 01 Aug 2001 21:42:53 -0400

At 12:30 AM 01/08/02 +0100, Vasco Alexandre Da Silva Costa wrote:
>On Thu, 2 Aug 2001, Gaute B Strokkenes wrote:
>
>> On Wed, 1 Aug 2001, vasc@xxxxxxxxxxxxxx wrote:
>> > Well does gcc optimize it this way?
>> > 
>> > #define map_adjust_x(X) \
>> >   (((X) % map.xsize) + (((X >= 0) - 1) & map.xsize))
>> 
>> You mean * rather than &, right?
>
>No. Try the macro and you'll see. It IS unreadable. Don't say i didn't
>warn you. :-)   Tip: 0-1=a mask of ones 0xFFFFFFFF, 1-1=a mask of zeros
>0x00000000.
>
>> > This is faster. Its faster on all CPUs. Notice it doesn't have any
>> > branches. Of course its also pretty darn unreadable :-)

It is also unsafe. Boolean TRUE values are undefined by the standards, and 
there is no guarantee that this is not represented by any non-zero set of
bits. You need to do this as (X >= 0 ? 1 : 0) to be 100% safe.

[...]
>---
>Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa

My feeling is the leading % is the hot spot. But I don't know if integer
div is just like any arithmetic op on the current top-of-the-line chips.

I do know most have dual path or better internal processing units and
usually use prediction so as not to stall the pipeline on simple branches.

I favour the guard test, because I think the border cases where you need
this are a very small percentage, and it is the lightest weight for a 
normal case.

But like most of us I'm not sufficiently motivated to do a 10 line
program to test this out - the discussion is more fun :-).

Cheers,
RossW




[Prev in Thread] Current Thread [Next in Thread]