Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o %t |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 2 | void t1(int len) { |
Anders Carlsson | 9f2505b | 2009-01-11 21:23:27 +0000 | [diff] [blame] | 3 | __asm__ volatile("" : "=&r"(len), "+&r"(len)); |
Anders Carlsson | 2763b3a | 2009-01-11 19:46:50 +0000 | [diff] [blame] | 4 | } |
Anders Carlsson | 9f2505b | 2009-01-11 21:23:27 +0000 | [diff] [blame] | 5 | |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 6 | void t2(unsigned long long t) { |
Anders Carlsson | 9f2505b | 2009-01-11 21:23:27 +0000 | [diff] [blame] | 7 | __asm__ volatile("" : "+m"(t)); |
| 8 | } |
| 9 | |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 10 | void t3(unsigned char *src, unsigned long long temp) { |
Anders Carlsson | 9f2505b | 2009-01-11 21:23:27 +0000 | [diff] [blame] | 11 | __asm__ volatile("" : "+m"(temp), "+r"(src)); |
| 12 | } |
| 13 | |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 14 | void t4() { |
Anders Carlsson | ebaae2a | 2009-01-12 02:22:13 +0000 | [diff] [blame] | 15 | unsigned long long a; |
| 16 | struct reg { unsigned long long a, b; } b; |
| 17 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 18 | __asm__ volatile ("":: "m"(a), "m"(b)); |
Anders Carlsson | ebaae2a | 2009-01-12 02:22:13 +0000 | [diff] [blame] | 19 | } |
Anders Carlsson | 9f2505b | 2009-01-11 21:23:27 +0000 | [diff] [blame] | 20 | |
Anders Carlsson | 03eb543 | 2009-01-27 20:38:24 +0000 | [diff] [blame] | 21 | // PR3417 |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 22 | void t5(int i) { |
Anders Carlsson | 03eb543 | 2009-01-27 20:38:24 +0000 | [diff] [blame] | 23 | asm("nop" : "=r"(i) : "0"(t5)); |
| 24 | } |
Anders Carlsson | 6032979 | 2009-02-22 02:11:23 +0000 | [diff] [blame] | 25 | |
| 26 | // PR3641 |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 27 | void t6(void) { |
Anders Carlsson | 6032979 | 2009-02-22 02:11:23 +0000 | [diff] [blame] | 28 | __asm__ volatile("" : : "i" (t6)); |
| 29 | } |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 30 | |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 31 | // RUN: grep "T7 NAMED: \$1" %t |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 32 | void t7(int a) { |
| 33 | __asm__ volatile("T7 NAMED: %[input]" : "+r"(a): [input] "i" (4)); |
Chris Lattner | 02af974 | 2009-03-10 06:38:02 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 36 | // RUN: grep "T8 NAMED MODIFIER: \${0:c}" %t |
Chris Lattner | 02af974 | 2009-03-10 06:38:02 +0000 | [diff] [blame] | 37 | void t8() { |
| 38 | __asm__ volatile("T8 NAMED MODIFIER: %c[input]" :: [input] "i" (4)); |
| 39 | } |
Chris Lattner | 88beebe | 2009-03-10 06:42:37 +0000 | [diff] [blame] | 40 | |
| 41 | // PR3682 |
| 42 | unsigned t9(unsigned int a) { |
| 43 | asm("bswap %0 %1" : "+r" (a)); |
| 44 | return a; |
| 45 | } |
Anders Carlsson | ec91dab | 2009-04-03 05:57:08 +0000 | [diff] [blame] | 46 | |
| 47 | // PR3908 |
| 48 | // RUN: grep "PR3908 \$1 \$3 \$2 \$0" %t |
| 49 | void t10(int r) { |
| 50 | __asm__("PR3908 %[lf] %[xx] %[li] %[r]" : [r] "+r" (r) : [lf] "mx" (0), [li] "mr" (0), [xx] "x" ((double)(0))); |
| 51 | } |
Chris Lattner | 4df4ee0 | 2009-05-03 07:27:51 +0000 | [diff] [blame] | 52 | |
| 53 | |
| 54 | // PR3373 |
| 55 | unsigned t11(signed char input) { |
| 56 | unsigned output; |
| 57 | __asm__("xyz" |
| 58 | : "=a" (output) |
| 59 | : "0" (input)); |
| 60 | return output; |
| 61 | } |
Chris Lattner | ede9d90 | 2009-05-03 07:53:25 +0000 | [diff] [blame] | 62 | |
Chris Lattner | a077b5c | 2009-05-03 08:21:20 +0000 | [diff] [blame] | 63 | // PR3373 |
| 64 | unsigned char t12(unsigned input) { |
| 65 | unsigned char output; |
| 66 | __asm__("xyz" |
| 67 | : "=a" (output) |
| 68 | : "0" (input)); |
| 69 | return output; |
| 70 | } |
Chris Lattner | ede9d90 | 2009-05-03 07:53:25 +0000 | [diff] [blame] | 71 | |
Chris Lattner | 3351f11 | 2009-05-03 08:32:32 +0000 | [diff] [blame] | 72 | unsigned char t13(unsigned input) { |
| 73 | unsigned char output; |
| 74 | __asm__("xyz %1" |
| 75 | : "=a" (output) |
| 76 | : "0" (input)); |
| 77 | return output; |
| 78 | } |
Chris Lattner | ede9d90 | 2009-05-03 07:53:25 +0000 | [diff] [blame] | 79 | |
Chris Lattner | 0bdaa5b | 2009-05-03 09:05:53 +0000 | [diff] [blame] | 80 | struct large { |
| 81 | int x[1000]; |
| 82 | }; |
| 83 | |
| 84 | unsigned long t15(int x, struct large *P) { |
| 85 | __asm__("xyz " |
| 86 | : "=r" (x) |
| 87 | : "m" (*P), "0" (x)); |
| 88 | return x; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | |
Chris Lattner | 3351f11 | 2009-05-03 08:32:32 +0000 | [diff] [blame] | 93 | |
| 94 | // bitfield destination of an asm. |
Chris Lattner | ede9d90 | 2009-05-03 07:53:25 +0000 | [diff] [blame] | 95 | struct S { |
| 96 | int a : 4; |
| 97 | }; |
| 98 | |
Chris Lattner | 3351f11 | 2009-05-03 08:32:32 +0000 | [diff] [blame] | 99 | void t14(struct S *P) { |
Chris Lattner | ede9d90 | 2009-05-03 07:53:25 +0000 | [diff] [blame] | 100 | __asm__("abc %0" : "=r"(P->a) ); |
| 101 | } |
Chris Lattner | 3351f11 | 2009-05-03 08:32:32 +0000 | [diff] [blame] | 102 | |
| 103 | |
Chris Lattner | 4053983 | 2009-10-13 04:32:07 +0000 | [diff] [blame] | 104 | // PR4938 |
| 105 | int t16() { |
| 106 | int a,b; |
| 107 | asm ( "nop;" |
| 108 | :"=%c" (a) |
| 109 | : "r" (b) |
| 110 | ); |
| 111 | return 0; |
| 112 | } |