brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.2 KiB · 9687c99 Raw
293 lines · c
1// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s2 3// PR104154__asm__ ("foo1");5__asm__ ("foo2");6__asm__ ("foo3");7// CHECK: module asm "foo1"8// CHECK-NEXT: module asm "foo2"9// CHECK-NEXT: module asm "foo3"10 11void t1(int len) {12  __asm__ volatile("" : "=&r"(len), "+&r"(len));13}14 15void t2(unsigned long long t)  {16  __asm__ volatile("" : "+m"(t));17}18 19void t3(unsigned char *src, unsigned long long temp) {20  __asm__ volatile("" : "+m"(temp), "+r"(src));21}22 23void t4(void) {24  unsigned long long a;25  struct reg { unsigned long long a, b; } b;26 27  __asm__ volatile ("":: "m"(a), "m"(b));28}29 30// PR341731void t5(int i) {32  asm("nop" : "=r"(i) : "0"(t5));33}34 35// PR364136void t6(void) {37  __asm__ volatile("" : : "i" (t6));38}39 40void t7(int a) {41  __asm__ volatile("T7 NAMED: %[input]" : "+r"(a): [input] "i" (4));42  // CHECK: @t7(i3243  // CHECK: T7 NAMED: $144}45 46void t8(void) {47  __asm__ volatile("T8 NAMED MODIFIER: %c[input]" :: [input] "i" (4));48  // CHECK: @t8()49  // CHECK: T8 NAMED MODIFIER: ${0:c}50}51 52// PR368253unsigned t9(unsigned int a) {54  asm("bswap %0 %1" : "+r" (a));55  return a;56}57 58// PR390859void t10(int r) {60  __asm__("PR3908 %[lf] %[xx] %[li] %[r]" : [r] "+r" (r) : [lf] "mx" (0), [li] "mr" (0), [xx] "x" ((double)(0)));61 62// CHECK: @t10(63// CHECK:PR3908 $1 $3 $2 $064}65 66// PR337367unsigned t11(signed char input) {68  unsigned  output;69  __asm__("xyz"70          : "=a" (output)71          : "0" (input));72  return output;73}74 75// PR337376unsigned char t12(unsigned input) {77  unsigned char output;78  __asm__("xyz"79          : "=a" (output)80          : "0" (input));81  return output;82}83 84unsigned char t13(unsigned input) {85  unsigned char output;86  __asm__("xyz %1"87          : "=a" (output)88          : "0" (input));89  return output;90}91 92struct large {93  int x[1000];94};95 96unsigned long t15(int x, struct large *P) {97  __asm__("xyz "98          : "=r" (x)99          : "m" (*P), "0" (x));100  return x;101}102 103// bitfield destination of an asm.104struct S {105  int a : 4;106};107 108void t14(struct S *P) {109  __asm__("abc %0" : "=r"(P->a) );110}111 112// PR4938113int t16(void) {114  int a,b;115  asm ( "nop;"116       :"=%c" (a)117       : "r" (b)118       );119  return 0;120}121 122// PR6475123void t17(void) {124  int i;125  __asm__ ( "nop": "=m"(i));126 127// CHECK: @t17()128// CHECK: call void asm "nop", "=*m,129}130 131int t18(unsigned data) {132  int a, b;133 134  asm("xyz" :"=a"(a), "=d"(b) : "a"(data));135  return a + b;136// CHECK: t18(i32137// CHECK: = call {{.*}}asm "xyz"138// CHECK-NEXT: extractvalue139// CHECK-NEXT: extractvalue140}141 142// PR6780143int t19(unsigned data) {144  int a, b;145 146  asm("x{abc|def|ghi}z" :"=r"(a): "r"(data));147  return a + b;148  // CHECK: t19(i32149  // CHECK: = call {{.*}}asm "x$(abc$|def$|ghi$)z"150}151 152// PR6845 - Mismatching source/dest fp types.153double t20(double x) {154  register long double result;155  __asm __volatile ("frndint"  : "=t" (result) : "0" (x));156  return result;157 158  // CHECK: @t20159  // CHECK: fpext double {{.*}} to x86_fp80160  // CHECK-NEXT: call x86_fp80 asm sideeffect "frndint"161  // CHECK: fptrunc x86_fp80 {{.*}} to double162}163 164float t21(long double x) {165  register float result;166  __asm __volatile ("frndint"  : "=t" (result) : "0" (x));167  return result;168  // CHECK: @t21169  // CHECK: call x86_fp80 asm sideeffect "frndint"170  // CHECK-NEXT: fptrunc x86_fp80 {{.*}} to float171}172 173// accept 'l' constraint174unsigned char t22(unsigned char a, unsigned char b) {175  unsigned int la = a;176  unsigned int lb = b;177  unsigned int bigres;178  unsigned char res;179  __asm__ ("0:\n1:\n" : [bigres] "=la"(bigres) : [la] "0"(la), [lb] "c"(lb) :180                        "edx", "cc");181  res = bigres;182  return res;183}184 185// accept 'l' constraint186unsigned char t23(unsigned char a, unsigned char b) {187  unsigned int la = a;188  unsigned int lb = b;189  unsigned char res;190  __asm__ ("0:\n1:\n" : [res] "=la"(res) : [la] "0"(la), [lb] "c"(lb) :191                        "edx", "cc");192  return res;193}194 195void *t24(char c) {196  void *addr;197  // CHECK: @t24198  // CHECK: zext i8 {{.*}} to i32199  // CHECK-NEXT: call ptr asm "foobar"200  __asm__ ("foobar" : "=a" (addr) : "0" (c));201  return addr;202}203 204// PR10299 - fpsr, fpcr205void t25(void)206{207  __asm__ __volatile__(					   \208		       "finit"				   \209		       :				   \210		       :				   \211		       :"st","st(1)","st(2)","st(3)",	   \212			"st(4)","st(5)","st(6)","st(7)",   \213			"fpsr","fpcr"			   \214							   );215}216 217// AVX registers218typedef long long __m256i __attribute__((__vector_size__(32)));219void t26 (__m256i *p) {220  __asm__ volatile("vmovaps  %0, %%ymm0" :: "m" (*(__m256i*)p) : "ymm0");221}222 223// Check to make sure the inline asm non-standard dialect attribute _not_ is224// emitted.225void t27(void) {226  asm volatile("nop");227// CHECK: @t27228// CHECK: call void asm sideeffect "nop"229// CHECK-NOT: ia_nsdialect230// CHECK: ret void231}232 233// Check handling of '*' and '#' constraint modifiers.234void t28(void)235{236  asm volatile ("/* %0 */" : : "i#*X,*r" (1));237// CHECK: @t28238// CHECK: call void asm sideeffect "/* $0 */", "i|r,~{dirflag},~{fpsr},~{flags}"(i32 1)239}240 241static unsigned t29_var[1];242 243void t29(void) {244  asm volatile("movl %%eax, %0"245               :246               : "m"(t29_var));247  // CHECK: @t29248  // CHECK: call void asm sideeffect "movl %eax, $0", "*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1 x i32]) @t29_var)249}250 251void t30(int len) {252  __asm__ volatile(""253                   : "+&&rm"(len));254  // CHECK: @t30255  // CHECK: call void asm sideeffect "", "=*&rm,0,~{dirflag},~{fpsr},~{flags}"256}257 258void t31(int len) {259  __asm__ volatile(""260                   : "+%%rm"(len), "+rm"(len));261  // CHECK: @t31262  // CHECK: call void asm sideeffect "", "=*%rm,=*rm,0,1,~{dirflag},~{fpsr},~{flags}"263}264 265// CHECK: @t32266int t32(int cond)267{268  asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop);269  // CHECK: callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,!i,!i,~{dirflag},~{fpsr},~{flags}"(i32 %0) #1270  // CHECK-NEXT: to label %asm.fallthrough [label %label_true, label %loop]271  return 0;272loop:273  return 0;274label_true:275  return 1;276}277 278void *t33(void *ptr)279{280  void *ret;281  asm ("lea %1, %0" : "=r" (ret) : "p" (ptr));282  return ret;283 284  // CHECK: @t33285  // CHECK: %1 = call ptr asm "lea $1, $0", "=r,p,~{dirflag},~{fpsr},~{flags}"(ptr %0)286}287 288void t34(void) {289  __asm__ volatile("T34 CC NAMED MODIFIER: %cc[input]" :: [input] "i" (4));290  // CHECK: @t34()291  // CHECK: T34 CC NAMED MODIFIER: ${0:c}292}293