ciphoneassemblyarm

How to choose between compiling ARM assembly file if iOS device and using regular C if iOS simulator


In one of projects I have a file written in ARM assembly that uses NEON to optimize a calculation I am doing it. I also have a file that does the exact same thing except that it is written in C. Currently I just comment out the C functions that are being defined in assembly and just add a

extern void myFunction();

to the C file. What i would like to do is have this in the C file

#ifdef device
extern void myFunction();
#else
void myFunction() {
   /* code here */
}
#endif

I would also need something similar in the assembly file but im not sure how to do preprocessor directives in ARM assembly.

So to sum all this up im looking for a preprocessor definition that tells me what device im am building for and a way to use preprocessor directives in assembly.


Solution

  • In your C file:

    #if defined __arm__
    extern void myFunction();
    #else
    void myFunction() {
       /* code here */
    }
    #endif
    

    In your assembly file:

    #if defined __arm__
    /* code here */
    #endif
    

    (Xcode applies the C preprocessor to .s files as well).