xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/aarch64-inline-asm.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple arm64-none-linux-gnu -emit-llvm -o - %s | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // The only part clang really deals with is the lvalue/rvalue
4f4a2713aSLionel Sambuc // distinction on constraints. It's sufficient to emit llvm and make
5f4a2713aSLionel Sambuc // sure that's sane.
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc long var;
8f4a2713aSLionel Sambuc 
test_generic_constraints(int var32,long var64)9f4a2713aSLionel Sambuc void test_generic_constraints(int var32, long var64) {
10f4a2713aSLionel Sambuc     asm("add %0, %1, %1" : "=r"(var32) : "0"(var32));
11f4a2713aSLionel Sambuc // CHECK: [[R32_ARG:%[a-zA-Z0-9]+]] = load i32*
12f4a2713aSLionel Sambuc // CHECK: call i32 asm "add $0, $1, $1", "=r,0"(i32 [[R32_ARG]])
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc     asm("add %0, %1, %1" : "=r"(var64) : "0"(var64));
15f4a2713aSLionel Sambuc // CHECK: [[R32_ARG:%[a-zA-Z0-9]+]] = load i64*
16f4a2713aSLionel Sambuc // CHECK: call i64 asm "add $0, $1, $1", "=r,0"(i64 [[R32_ARG]])
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc     asm("ldr %0, %1" : "=r"(var32) : "m"(var));
19f4a2713aSLionel Sambuc     asm("ldr %0, [%1]" : "=r"(var64) : "r"(&var));
20f4a2713aSLionel Sambuc // CHECK: call i32 asm "ldr $0, $1", "=r,*m"(i64* @var)
21f4a2713aSLionel Sambuc // CHECK: call i64 asm "ldr $0, [$1]", "=r,r"(i64* @var)
22f4a2713aSLionel Sambuc }
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc float f;
25f4a2713aSLionel Sambuc double d;
test_constraint_w()26f4a2713aSLionel Sambuc void test_constraint_w() {
27f4a2713aSLionel Sambuc     asm("fadd %s0, %s1, %s1" : "=w"(f) : "w"(f));
28f4a2713aSLionel Sambuc // CHECK: [[FLT_ARG:%[a-zA-Z_0-9]+]] = load float* @f
29f4a2713aSLionel Sambuc // CHECK: call float asm "fadd ${0:s}, ${1:s}, ${1:s}", "=w,w"(float [[FLT_ARG]])
30f4a2713aSLionel Sambuc 
31f4a2713aSLionel Sambuc     asm("fadd %d0, %d1, %d1" : "=w"(d) : "w"(d));
32f4a2713aSLionel Sambuc // CHECK: [[DBL_ARG:%[a-zA-Z_0-9]+]] = load double* @d
33f4a2713aSLionel Sambuc // CHECK: call double asm "fadd ${0:d}, ${1:d}, ${1:d}", "=w,w"(double [[DBL_ARG]])
34f4a2713aSLionel Sambuc }
35f4a2713aSLionel Sambuc 
test_constraints_immed(void)36f4a2713aSLionel Sambuc void test_constraints_immed(void) {
37f4a2713aSLionel Sambuc     asm("add x0, x0, %0" : : "I"(4095) : "x0");
38f4a2713aSLionel Sambuc     asm("and w0, w0, %0" : : "K"(0xaaaaaaaa) : "w0");
39f4a2713aSLionel Sambuc     asm("and x0, x0, %0" : : "L"(0xaaaaaaaaaaaaaaaa) : "x0");
40f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect "add x0, x0, $0", "I,~{x0}"(i32 4095)
41f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect "and w0, w0, $0", "K,~{w0}"(i32 -1431655766)
42f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect "and x0, x0, $0", "L,~{x0}"(i64 -6148914691236517206)
43f4a2713aSLionel Sambuc }
44f4a2713aSLionel Sambuc 
test_constraint_S(void)45f4a2713aSLionel Sambuc void test_constraint_S(void) {
46f4a2713aSLionel Sambuc     int *addr;
47f4a2713aSLionel Sambuc     asm("adrp %0, %A1\n\t"
48f4a2713aSLionel Sambuc         "add %0, %0, %L1" : "=r"(addr) : "S"(&var));
49f4a2713aSLionel Sambuc // CHECK: call i32* asm "adrp $0, ${1:A}\0A\09add $0, $0, ${1:L}", "=r,S"(i64* @var)
50f4a2713aSLionel Sambuc }
51f4a2713aSLionel Sambuc 
test_constraint_Q(void)52f4a2713aSLionel Sambuc void test_constraint_Q(void) {
53f4a2713aSLionel Sambuc     int val;
54f4a2713aSLionel Sambuc     asm("ldxr %0, %1" : "=r"(val) : "Q"(var));
55f4a2713aSLionel Sambuc // CHECK: call i32 asm "ldxr $0, $1", "=r,*Q"(i64* @var)
56f4a2713aSLionel Sambuc }
57