All Products
Search
Document Center

Elastic Compute Service:Migrate C or C++ code

Last Updated:Apr 27, 2026

Modify macros, built-in functions, intrinsics, and inline assembly to re-compile C or C++ software for YiTian ECS instances.

Macros

System macros differ by platform. The following table lists macros defined for ARM-based platforms, x86 platforms, and both.

Macro for ARM-based platforms

Macro for x86 platforms

Macro for both x86 and ARM-based platforms

__arm__

__amd64__

__STDC_HOSTED__

__thumb__

i386

__INT64_TYPE__

__ARM_ARCH_4T__

__k8__

_LP64

__aarch64__

__SSE2__

__WCHAR_MAX__

Built-in functions

GCC built-in functions (prefixed with __builtin_) that target x86 platforms, such as builtin_ia32_xxx, may fail to compile on YiTian instances.

Replace x86-specific built-in functions with ARM equivalents. For example, change the CRC-related builtin_ia32_crc32qi(a, b) to builtin_aarch64_crc32cb(a, b).

Intrinsic functions

Intrinsic functions call SIMD operations tied to x86 CPU architectures. Migrating SIMD intrinsics is the main focus when you move software to YiTian instances.

To migrate intrinsic functions from x86 platforms to YiTian instances:

  1. Add header files such as arm_neon.h and arm_sve.h for ARM intrinsic support.

  2. Replace the intrinsic functions. See Find the Best Architecture for you on the Arm Developer website.

Note
  • In the preceding steps, modify instruction sets and data types for ARM-based platforms. Example:

    • Change m128 mm_load_ps (x86) to float32x4 vld1q_f32 (ARM).

    • x86 AVX instruction sets use 256-bit registers, while AArch64 supports only 128-bit registers. Expand instructions with equivalent semantics. For example, replace m256d mm_add_ps with two vaddq_f32 SIMD instructions on AArch64.

  • YiTian instances support SVE instructions, but SVE intrinsics are not recommended due to the special programming mode. Use open source projects such as sse2neon instead.

Inline assembly

Replace x86 assembly instructions with AArch64 equivalents that use the same semantics. For example, change asm("bswap %0": "=r"(val): "0"(val)) to asm("rev %[dst], %[src]": [dst]"=r"(val): [src]"r"(val)). See How to Use Inline Assembly Language in C Code.

Sample code

The following example shows how to modify C or C++ code for migration from x86 to YiTian instances:

Code before modification:

#if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
/* GCC-compatible compiler, targeting x86/x86-64 */
#include <x86intrin.h>
#endif
uint32_t crc32_4k(uint32_t acc, char* buf) {
    for (char* end = buf + 4096; buf < end; buf += 4) {
        acc = __builtin_ia32_crc32si(acc, *(uint32_t*)buf);
    }
    return acc;
}

Code after modification:

#if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
     /* GCC-compatible compiler, targeting x86/x86-64 */
     #include <x86intrin.h>
#elif defined(__GNUC__) && defined(__ARM_NEON)
     /* GCC-compatible compiler, targeting ARM with NEON */
     #include <arm_neon.h>
  #if defined(__ARM_FEATURE_SVE)
     #include <arm_sve.h>
  #endif 
#endif

uint32_t crc32_4k(uint32_t acc, char* buf) {
    for (char* end = buf + 4096; buf < end; buf += 4) {
        acc = __builtin_aarch64_crc32cw(acc, *(uint32_t*)buf);
    }
    return acc;
}