diff --git a/docs/ispc.txt b/docs/ispc.txt index 4cfefdd1..53c2bfa2 100644 --- a/docs/ispc.txt +++ b/docs/ispc.txt @@ -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 ================= diff --git a/module.cpp b/module.cpp index cf8b2836..2881c810 100644 --- a/module.cpp +++ b/module.cpp @@ -909,12 +909,27 @@ Module::execPreprocessor(const char* infilename, llvm::raw_string_ostream* ostre clang::PreprocessorOptions &opts = inst.getPreprocessorOpts(); - //Add defs for ISPC and PI + // Add defs for ISPC and PI 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)); }