内联汇编的兼容性 - \n\t 与 ;

Compatibility of inline assembly - \n\t versus ;

编写内联汇编的正确方法是什么(除了避免它)?使用 ; 还是 \n\t 更好?

(Microsoft 编译器除外 __asm)

没有 "correct" 多行汇编与内联的方法。只要是最易读的。

示例:GMP 对相同的 bswap 函数使用不同的 asm 代码样式

/* bswap is available on i486 and up and is fast.  A combination rorw  /
   roll  / rorw  is used in glibc for plain i386 (and in the linux
   kernel with xchgb instead of rorw), but this is not done here, because
   i386 means generic x86 and mixing word and dword operations will cause
   partial register stalls on P6 chips.  */
#if defined (__GNUC__) && ! defined (NO_ASM)            \
  && HAVE_HOST_CPU_FAMILY_x86 && ! HAVE_HOST_CPU_i386   \
  && GMP_LIMB_BITS == 32
#define BSWAP_LIMB(dst, src)                        \
  do {                                  \
    __asm__ ("bswap %0" : "=r" (dst) : "0" (src));          \
  } while (0)
#endif

#if defined (__GNUC__) && ! defined (NO_ASM)            \
  && defined (__amd64__) && GMP_LIMB_BITS == 64
#define BSWAP_LIMB(dst, src)                        \
  do {                                  \
    __asm__ ("bswap %q0" : "=r" (dst) : "0" (src));         \
  } while (0)
#endif

#if defined (__GNUC__) && ! defined (__INTEL_COMPILER)          \
    && ! defined (NO_ASM) && defined (__ia64) && GMP_LIMB_BITS == 64
#define BSWAP_LIMB(dst, src)                        \
  do {                                  \
    __asm__ ("mux1 %0 = %1, @rev" : "=r" (dst) :  "r" (src));       \
  } while (0)
#endif

/* As per glibc. */
#if defined (__GNUC__) && ! defined (NO_ASM)                    \
  && HAVE_HOST_CPU_FAMILY_m68k && GMP_LIMB_BITS == 32
#define BSWAP_LIMB(dst, src)                        \
  do {                                  \
    mp_limb_t  __bswapl_src = (src);                    \
    __asm__ ("ror%.w %#8, %0\n\t"                   \
         "swap   %0\n\t"                        \
         "ror%.w %#8, %0"                       \
         : "=d" (dst)                       \
         : "0" (__bswapl_src));                 \
  } while (0)
#endif