This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: processor type defines: __PPC403__, __PPC750__ would be nice?



>Today I needed to check for the processor type in
>a program that compiles on ppc403, ppc750, sh4, and generic pentium.
>The tests, judging from the specs files of my gccs, would be
>
>#ifdef __SH4__
>#if CPU==PPC403
>#if CPU==PPC750
>#ifdef __i386__
>
>Hmm.  That's not very uniform.  Is there a more uniform scheme
>I could use?  A URL where I could RTFM would be greatly appreciated.

I'll make the assumption that you're using gcc-3.0.4 since that's what
I have right in front of me.  YMMV for other versions.  Look in the
installed ppc compiler specs file for "*cpp" and the following line is
the 'expression' that is used to generate the definitions for the
preprocessor.  you could add to that line(for the powerpc specs file):

%{mcpu=403: -D__ppc403__}%{mcpu=750: -D__ppc750__}

And if you specify -mcpu=403 or -mcpu=750, then the preprocessor
symbol __PPC403__ or __PPC750__ will be defined and then can be used
to determine the cpu type.  If you modify your confg/rs6000/rs6000.h
file, you could add the above line to the end of CPU_CPU_SPEC.

For SH4 config/sh/sh.h already has the folling expression in CPU_SPEC:

%{m4:-D__SH4__}

So if you specify -m4, then the preprocessor symbol __SH4__ will be
defined.

And finally config/i386/i386.h containts in CPP_CPU_SPEC:

%{march=pentium|march=i586:-D__i586 -D__i586__ -D__pentium -D__pentium__ \
  %{!mcpu*:-D__tune_i586__ -D__tune_pentium__ }}

Which will define the preprocessor symbol __i586__ if you specify
either -mpentium or -march=i586.

This allows you to have code that looks like:

#if defined(__SH4__)
/* SH4 specific stuff */
#elif defined(__PPC403__)
/* PPC403 specific stuff */
#elif defined(__PPC750__)
/* PPC750 specific stuff */
#elif defined(__i586__)
/* Generic pentioum stuff */
#else
#error "chip specified is not one of sh4, ppc403, ppc750, or i586!"
#endif

Of course the next time you upgrade your compiler you'll have to make
the above change again and check the rs6000.h, sh.h, and i386.h to
make sure the symbols are what you expect...

For documentation on the spec file syntax, check section 3.15
(Specifying subprocesses and the switches to pass to them) of the
"Using and Porting the GNU Compiler Collection" manual/info that's
part of gcc-3.0.4 

Good luck!

-- 
Peter Barada                                   Peter.Barada@motorola.com
Wizard                                         781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola)   781-270-0193 (fax)

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]