aboutsummaryrefslogtreecommitdiff
path: root/clang/test/CodeGen/inline-asm-intel.c
blob: 30f2352a5ab8b8d1bb38e0b5a36a589ca2ce5fcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// REQUIRES: x86-registered-target

/// Accept intel inline asm but write it out as att:
// RUN: %clang_cc1 -triple i386-unknown-linux -mllvm -x86-asm-syntax=att -inline-asm=intel -Werror -target-feature +hreset -target-feature +pconfig -target-feature +sgx -ffreestanding -O0 -S %s -o - | FileCheck --check-prefix=ATT %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux -mllvm -x86-asm-syntax=att -inline-asm=intel -Werror -target-feature +hreset -target-feature +pconfig -target-feature +sgx -ffreestanding -O0 -S %s -o - | FileCheck --check-prefix=ATT %s

/// Accept intel inline asm and write it out as intel:
// RUN: %clang_cc1 -triple i386-unknown-linux -mllvm -x86-asm-syntax=intel -inline-asm=intel -Werror -target-feature +hreset -target-feature +pconfig -target-feature +sgx -ffreestanding -O0 -S %s -o - | FileCheck  --check-prefix=INTEL %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux -mllvm -x86-asm-syntax=intel -inline-asm=intel -Werror -target-feature +hreset -target-feature +pconfig -target-feature +sgx -ffreestanding -O0 -S %s -o - | FileCheck  --check-prefix=INTEL %s

/// Check MS compat mode (_MSC_VER defined). The driver always picks intel
/// output in that mode, so test only that.
// RUN: %clang_cc1 -triple i386-pc-win32 -mllvm -x86-asm-syntax=intel -inline-asm=intel -Werror -target-feature +hreset -target-feature +pconfig -target-feature +sgx -ffreestanding -O0 -S %s -o - -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 | FileCheck  --check-prefix=INTEL %s
// RUN: %clang_cc1 -triple x86_64-pc-win32 -mllvm -x86-asm-syntax=intel -inline-asm=intel -Werror -target-feature +hreset -target-feature +pconfig -target-feature +sgx -ffreestanding -O0 -S %s -o - -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 | FileCheck  --check-prefix=INTEL %s

// Test that intrinsics headers still work with -masm=intel.
#ifdef _MSC_VER
#include <intrin.h>
#else
#include <x86intrin.h>
#endif

void f(void) {
  // Intrinsic headers contain macros and inline functions.
  // Inline assembly in both are checked only when they are
  // referenced, so reference a few intrinsics here.
  __SSC_MARK(4);
  int a;
  _hreset(a);
  _pconfig_u32(0, (void*)0);

  _encls_u32(0, (void*)0);
  _enclu_u32(0, (void*)0);
  _enclv_u32(0, (void*)0);
#ifdef _MSC_VER
  __movsb((void*)0, (void*)0, 0);
  __movsd((void*)0, (void*)0, 0);
  __movsw((void*)0, (void*)0, 0);
  __stosb((void*)0, 0, 0);
  __stosd((void*)0, 0, 0);
  __stosw((void*)0, 0, 0);
#ifdef __x86_64__
  __movsq((void*)0, (void*)0, 0);
  __stosq((void*)0, 0, 0);
#endif
  __cpuid((void*)0, 0);
  __cpuidex((void*)0, 0, 0);
  __halt();
  __nop();
  __readmsr(0);
  __readcr3();
  __writecr3(0);

  _InterlockedExchange_HLEAcquire((void*)0, 0);
  _InterlockedExchange_HLERelease((void*)0, 0);
  _InterlockedCompareExchange_HLEAcquire((void*)0, 0, 0);
  _InterlockedCompareExchange_HLERelease((void*)0, 0, 0);
#ifdef __x86_64__
  _InterlockedExchange64_HLEAcquire((void*)0, 0);
  _InterlockedExchange64_HLERelease((void*)0, 0);
  _InterlockedCompareExchange64_HLEAcquire((void*)0, 0, 0);
  _InterlockedCompareExchange64_HLERelease((void*)0, 0, 0);
#endif
#endif


  __asm__("mov eax, ebx");
  // ATT: movl %ebx, %eax
  // INTEL: mov eax, ebx

  // Explicitly overriding asm style per block works:
  __asm__(".att_syntax\nmovl %ebx, %eax");
  // ATT: movl %ebx, %eax
  // INTEL: mov eax, ebx

  // The .att_syntax was only scoped to the previous statement.
  // (This is different from gcc, where `.att_syntax` is in
  // effect from that point on, so portable code would want an
  // explicit `.intel_syntax noprefix\n` at the start of this string).
  __asm__("mov eax, ebx");
  // ATT: movl %ebx, %eax
  // INTEL: mov eax, ebx
}