Thread: __cpu__ defines

__cpu__ defines

From
Bruce Momjian
Date:
As part of my spinlock testing, I noticed that we test for __cpu__ when
using gcc, and __cpu when not using gcc.  However, I see that my i386
gcc 2.95 defines both (shown using src/tools/ccsym):

__GNUC__=2__GNUC_MINOR__=95unix__i386__i386__bsdi__bsdi__ELF____GAS__=2__GAS_MINOR__=10__unix____i386____i386____bsdi____bsdi____ELF____GAS__=2__GAS_MINOR__=10__unix__i386__bsdisystem=unixsystem=bsdcpu=i386machine=i386cpu=i386machine=i386i386__i386__i386__

So, I wonder if we should be testing _just_ for __cpu, perhaps starting
in 7.5.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: __cpu__ defines

From
Larry Rosenman
Date:

--On Friday, September 12, 2003 09:53:10 -0400 Bruce Momjian
<pgman@candle.pha.pa.us> wrote:

> As part of my spinlock testing, I noticed that we test for __cpu__ when
> using gcc, and __cpu when not using gcc.  However, I see that my i386
> gcc 2.95 defines both (shown using src/tools/ccsym):
>
>     __GNUC__=2
>     __GNUC_MINOR__=95
>     unix
>     __i386__
>     i386
>     __bsdi__
>     bsdi
>     __ELF__
>     __GAS__=2
>     __GAS_MINOR__=10
>     __unix__
>     __i386__
>     __i386__
>     __bsdi__
>     __bsdi__
>     __ELF__
>     __GAS__=2
>     __GAS_MINOR__=10
>     __unix
>     __i386
>     __bsdi
>     system=unix
>     system=bsd
>     cpu=i386
>     machine=i386
>     cpu=i386
>     machine=i386
>     i386
>     __i386
>     __i386__
>
> So, I wonder if we should be testing _just_ for __cpu, perhaps starting
> in 7.5.
I corresponded with Dave Prosser of SCO, and he pointed me at the #assert
stuff.  That's where the xxx=xxx stuff comes from.


Might it make more sense to use
#if #cpu(i386)
xxx
#endif

instead of depending on the different flavors of #defines.

GCC and at least SCO's cc support this.

I sent the details to Tom, since he seems to be the spinlock maintainer.

LER



--
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

Re: __cpu__ defines

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> As part of my spinlock testing, I noticed that we test for __cpu__ when
> using gcc, and __cpu when not using gcc.
> ...
> So, I wonder if we should be testing _just_ for __cpu, perhaps starting
> in 7.5.

I might be all wet on this, but I had the idea that the __cpu__ forms
were considered more standard/common.  In any case, I can't see any
good reason not to test for both.  The amount of code saved by checking
only one is negligible; why should we take a chance on breaking things
for that?
        regards, tom lane


Re: __cpu__ defines

From
Bruce Momjian
Date:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > As part of my spinlock testing, I noticed that we test for __cpu__ when
> > using gcc, and __cpu when not using gcc.
> > ...
> > So, I wonder if we should be testing _just_ for __cpu, perhaps starting
> > in 7.5.
> 
> I might be all wet on this, but I had the idea that the __cpu__ forms
> were considered more standard/common.  In any case, I can't see any
> good reason not to test for both.  The amount of code saved by checking
> only one is negligible; why should we take a chance on breaking things
> for that?

Yes, that what confuses me --- which is standard.  Right now, we aren't
consistent.  My patch tests for __cpu__ on gcc, and both on non-gcc,
which seems safest.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: __cpu__ defines

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> As part of my spinlock testing, I noticed that we test for __cpu__ when
> using gcc, and __cpu when not using gcc.  However, I see that my i386
> gcc 2.95 defines both (shown using src/tools/ccsym):

gcc only documents the __foo__ version, so there is a small reason to lean
in that direction if you want to make it uniform.

-- 
Peter Eisentraut   peter_e@gmx.net



Re: __cpu__ defines

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Bruce Momjian writes:
> 
> > As part of my spinlock testing, I noticed that we test for __cpu__ when
> > using gcc, and __cpu when not using gcc.  However, I see that my i386
> > gcc 2.95 defines both (shown using src/tools/ccsym):
> 
> gcc only documents the __foo__ version, so there is a small reason to lean
> in that direction if you want to make it uniform.

Oh, that helps, so my logic of testing for only __foo__ on gcc, and both
when the compiler isn't gcc or isn't known is correct.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073