does -xtarget or -xchip predefine any macros that define the chip?

Hi,

I am working on a project where I need to compile different versions of the code for the different UltraSPARC chips. I can easily tell the compiler to compile for an US-IV on my US-IIIi development machine, e.g. with the -xtarget=ultra4 flag.Does the compiler define some internal macros, that make it possible to find out which chip it compiles for? E.g. something like

[code]

#ifdef __US-IV

<statements>

#endif

#ifdef __US-IIICu

<statements>

#endif

[/code]

Regards,

Bernd

[562 byte] By [dtugrid] at [2007-11-26 9:12:03]
# 1

You can see all macros that compiler defines when using [b]-v[/b] compiler option. Among other information, it shows compiler front-end invocation options that include all -D's:

[code]

$ CC -g -v -xarch=amd64 a.cc

###command line files and options (expanded):

### -g -v -xarch=amd64 a.cc

### CC: Note: NLSPATH = /opt/SUNWspro/prod/bin/../lib/locale/%L/LC_MESSAGES/%N.cat:/opt/SUNWspro/prod/b in/../../lib/locale/%L/LC_MESSAGES/%N.cat

/opt/SUNWspro/prod/bin/ccfe -y-o -ya.o -y-fbe -y/opt/SUNWspro/prod/bin/fbe

-y-xarch=amd64 -xarch=amd64

<skip>

-D__SunOS_5_10 -D__SUNPRO_CC=0x580 -Dunix -Dsun -D__x86_64 -D__x86_64__

-D__amd64 -D__amd64__ -D__unix -D__sun

-D__BUILTIN_VA_STRUCT -D__SVR4 -D__SUNPRO_CC_COMPAT=5 -g

<skip>

/tmp/ccfe.21295.0.s >&/tmp/ccfe.21295.1.err

[/code]

MaximKartashev at 2007-7-6 23:33:07 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
The workaround for this is to configure your makefile, so that when itpasses -xtarget=ultra4 it also passes -DTARGET_ARCH=ultra4.Then your source code can test for TARGET_ARCH=ultra4--chris
ChrisQuenelle at 2007-7-6 23:33:07 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
Adding yet another define to the Makefile is only a workaround and not really 'user friendly'. In fact this method is quite error prone, and I'd rather see the compiler defining a macro I could use. Bernd
dtugrid at 2007-7-6 23:33:07 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4

I understand what you're saying, and I'm not trying to argue with you.

I agree it would be more convenient if the compiler defined those symbols

for you. However, I think it is not error prone to update the Makefile.

Your makefile must already have something like this:

XX_FLAGS_ULTRA3 = -xchip=ultra3

XX_FLAGS_ULTRA4 = -xchip=ultra4

I am only suggesting to update these settings like this:

XX_FLAGS_ULTRA3 = -xchip=ultra3 -DCHIP=ultra3

XX_FLAGS_ULTRA4 = -xchip=ultra4 -DCHIP=ultra4

If your Makefile was able to ignore the chip values, then I agree

it would be a big increase in complexity to add new -D options.

But because it must already be controlling -xchip, it doesn't seem

like a difficult workaround to add control for new -D options to

the same part of the Makefile.

ChrisQuenelle at 2007-7-6 23:33:07 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5

> If your Makefile was able to ignore the chip values,

> then I agree

> it would be a big increase in complexity to add new

> -D options.

> But because it must already be controlling -xchip, it

> doesn't seem

> like a difficult workaround to add control for new -D

> options to

> the same part of the Makefile.

There are two scenarios:

a) compiling for the native platform: here I am usually using something like

CHIP = -`fpversion -foption`

in the Makefile - so here a compiler defined macro would really be helpful, because

I don't know beforehand the result of fpversion.

b) cross-compiling: There I can't use fpversion, so your apprcach could be applied.

However, the compiler defined macro would also be useful here.

Furthermore, a compiler defined macro would set a kind of a "standard", all developers

could rely on, unlike user defined macros that are not consistent. Already in this thread

we have used at least 3 different macro names to do the same thing. ;-)

dtugrid at 2007-7-6 23:33:07 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 6
To get this functionality, you can submit an RFE (request for enhancement) at http://bugs.sun.com/services/bugreport/index.jsp
MaximKartashev at 2007-7-6 23:33:07 > top of Java-index,Development Tools,Solaris and Linux Development Tools...