Conditional Compilation in assembler (.s) code for iPhone - how?

前端 未结 2 1978
栀梦
栀梦 2020-12-18 13:56

I have a few lines of assembler arm code in an .s file. Just a few routines i need to call. It works fine when building for the device, however when i switch to iPhone Simul

相关标签:
2条回答
  • 2020-12-18 14:08

    You do do it with a pre-processor macro. They are defined in TargetConditionals.h TARGET_IPHONE_SIMULATOR should be there! (You do need to #include it however.)

    0 讨论(0)
  • 2020-12-18 14:33

    Here is code I use to detect ARM vs Thumb vs Simulator:

    #include "TargetConditionals.h"
    
    #if defined(__arm__)
    # if defined(__thumb__)
    #  define COMPILE_ARM_THUMB_ASM 1
    # else
    #  define COMPILE_ARM_ASM 1
    # endif
    #endif
    
    #if TARGET_IPHONE_SIMULATOR
      // Simulator defines
    #else
      // ARM or Thumb mode defines
    #endif
    

    // And here is how you might use it

    uint32_t
    test_compare_shifted_operand(uint32_t w1) {
      uint32_t local;
    #if defined(COMPILE_ARM_ASM)
      const uint32_t shifted = (1 << 8);
      __asm__ __volatile__ (
                            "mov %[w2], #1\n\t"
                            "cmp %[w2], %[w1], lsr #8\n\t"
                            "moveq %[w2], #10\n\t"
                            "movne %[w2], #11\n\t"
                            : \
                            [w1] "+l" (w1),
                            [w2] "+l" (local)
                            : \
                            [shifted] "l" (shifted)
                            );
    #else // COMPILE_ARM_ASM
      if ((w1 >> 8) == 1) {
        local = 10;
      } else {
        local = 11;
      }
    #endif // COMPILE_ARM_ASM  
      return local;
    }
    
    0 讨论(0)
提交回复
热议问题