Set a preprocessor #define based on the target ISA.

For example, ISPC_TARGET_SSE4 is #defined for the sse4 targets, etc.
This commit is contained in:
Matt Pharr
2011-10-15 11:56:18 -07:00
parent c21e704a5c
commit 1ab05c0351
2 changed files with 35 additions and 6 deletions

View File

@@ -57,6 +57,7 @@ Contents:
+ `Basic Command-line Options`_
+ `Selecting The Compilation Target`_
+ `The Preprocessor`_
* `The ISPC Language`_
@@ -288,10 +289,6 @@ with application code, enter the following command
ispc foo.ispc -o foo.o
``ispc`` automatically runs the C preprocessor on your input program before
compiling it. (This functionality can be disabled with the ``--nocpp``
command-line argument.)
Basic Command-line Options
--------------------------
@@ -380,6 +377,23 @@ use ``--target=sse2``. (As with the other options in this section, see the
output of ``ispc --help`` for a full list of supported targets.)
The Preprocessor
----------------
``ispc`` automatically runs the C preprocessor on your input program before
compiling it. Thus, you can use ``#ifdef``, ``#define``', and so forth in
your ispc programs (This functionality can be disabled with the ``--nocpp``
command-line argument.)
Three preprocessor symbols are automatically defined before the
preprocessor runs. First, ``ISPC`` is defined, so that it can be detected
that the ``ispc`` compiler is running over the program. Next, a symbol
indicating the target instruction set is defined. With an SSE2 target,
``ISPC_TARGET_SSE2`` is defined; ``ISPC_TARGET_SSE4`` is defined for SSE4,
and ``ISPC_TARGET_AVX`` for AVX. Finally, ``PI`` is defined for
convenience, having the value 3.1415926535.
The ISPC Language
=================

View File

@@ -913,8 +913,23 @@ Module::execPreprocessor(const char* infilename, llvm::raw_string_ostream* ostre
opts.addMacroDef("ISPC");
opts.addMacroDef("PI=3.1415926535");
// Add #define for current compilation target
switch (g->target.isa) {
case Target::SSE2:
opts.addMacroDef("ISPC_TARGET_SSE2");
break;
case Target::SSE4:
opts.addMacroDef("ISPC_TARGET_SSE4");
break;
case Target::AVX:
opts.addMacroDef("ISPC_TARGET_AVX");
break;
default:
FATAL("Unhandled target ISA in preprocessor symbol definition");
}
for (unsigned int i = 0; i < g->cppArgs.size(); ++i) {
// Sanity Check, should really begin with -D
// Sanity check--should really begin with -D
if (g->cppArgs[i].substr(0,2) == "-D") {
opts.addMacroDef(g->cppArgs[i].substr(2));
}