Inline Assembly Comments

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Inline Assembly Comments

Romanenkov Kirill via cfe-dev
Hi,

I'm investigating how inline assembly is used in C projects. While doing so, I found that a number of projects include comments as part of their inline assembly snippets. The code snippet below is an example:

#include <stdint.h>

uint64_t atomic_swap_long(volatile uint64_t *p, uint64_t v) {
  __asm __volatile(
    "xchgq %1,%0; # atomic_swap_long"
: "+r" (v),   /* 0 */
 "+m" (*p)); /* 1 */
  return v;
}

When compiling with GCC (gcc -O1 -S) the following code is produced for the inline assembly snippet on my system:

 #APP
# 4 "inline-assembly-comment.c" 1
xchgq (%rdi),%rax; # atomic_swap_long
# 0 "" 2
#NO_APP

With Clang 3.8 and below, an empty line is inserted instead of the comment:

#APP
xchgq %rsi, (%rdi)
#NO_APP

With Clang 3.9 and 4.0, the newline disappeared but the comment is still not part of the assembly code.

The comment is retained on the LLVM IR level:

%5 = call i64 asm sideeffect "xchgq\09$1,$0; # atomic_swap_long", "=r,=*m,0,*m,~{dirflag},~{fpsr},~{flags}"(i64* %4, i64 %3, i64* %4)

Is this intended? Should I open a bug report?

- Manuel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Inline Assembly Comments

Romanenkov Kirill via cfe-dev


On 07/13/2017 06:51 AM, Manuel Rigger via cfe-dev wrote:
Hi,

I'm investigating how inline assembly is used in C projects. While doing so, I found that a number of projects include comments as part of their inline assembly snippets. The code snippet below is an example:

#include <stdint.h>

uint64_t atomic_swap_long(volatile uint64_t *p, uint64_t v) {
  __asm __volatile(
    "xchgq %1,%0; # atomic_swap_long"
: "+r" (v),   /* 0 */
 "+m" (*p)); /* 1 */
  return v;
}

When compiling with GCC (gcc -O1 -S) the following code is produced for the inline assembly snippet on my system:

 #APP
# 4 "inline-assembly-comment.c" 1
xchgq (%rdi),%rax; # atomic_swap_long
# 0 "" 2
#NO_APP

With Clang 3.8 and below, an empty line is inserted instead of the comment:

#APP
xchgq %rsi, (%rdi)
#NO_APP
With Clang 3.9 and 4.0, the newline disappeared but the comment is still not part of the assembly code.
The comment is retained on the LLVM IR level:
%5 = call i64 asm sideeffect "xchgq\09$1,$0; # atomic_swap_long", "=r,=*m,0,*m,~{dirflag},~{fpsr},~{flags}"(i64* %4, i64 %3, i64* %4)
Is this intended? Should I open a bug report?

Please feel free to file a bug report. Retaining the comments seems like a useful thing to do.

 -Hal

- Manuel


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Inline Assembly Comments

Romanenkov Kirill via cfe-dev
In reply to this post by Romanenkov Kirill via cfe-dev
AFAIK we retain all assembly comments by default. I just tried this locally and it seems to work as expected with inline assembly comments should be preserved by default.

I suspect the comment does exist, but is on the next line. Currently, the trailing semicolon at the end of your instruction is interpreted as an EOL so the following comment is interpreted as a full line comment (We may want to change that). If you remove the semicolon you should find it on the same line. 

-Nirav


On Thu, Jul 13, 2017 at 7:51 AM, Manuel Rigger via cfe-dev <[hidden email]> wrote:
Hi,

I'm investigating how inline assembly is used in C projects. While doing so, I found that a number of projects include comments as part of their inline assembly snippets. The code snippet below is an example:

#include <stdint.h>

uint64_t atomic_swap_long(volatile uint64_t *p, uint64_t v) {
  __asm __volatile(
    "xchgq %1,%0; # atomic_swap_long"
: "+r" (v),   /* 0 */
 "+m" (*p)); /* 1 */
  return v;
}

When compiling with GCC (gcc -O1 -S) the following code is produced for the inline assembly snippet on my system:

 #APP
# 4 "inline-assembly-comment.c" 1
xchgq (%rdi),%rax; # atomic_swap_long
# 0 "" 2
#NO_APP

With Clang 3.8 and below, an empty line is inserted instead of the comment:

#APP
xchgq %rsi, (%rdi)
#NO_APP

With Clang 3.9 and 4.0, the newline disappeared but the comment is still not part of the assembly code.

The comment is retained on the LLVM IR level:

%5 = call i64 asm sideeffect "xchgq\09$1,$0; # atomic_swap_long", "=r,=*m,0,*m,~{dirflag},~{fpsr},~{flags}"(i64* %4, i64 %3, i64* %4)

Is this intended? Should I open a bug report?

- Manuel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Inline Assembly Comments

Romanenkov Kirill via cfe-dev
I filed a bug (see https://bugs.llvm.org/show_bug.cgi?id=33770).

It seems the comment is swallowed (i.e., it is also not on the next line). I verified this locally and using Compiler Explorer (see https://godbolt.org/). Removing the trailing semicolon lets the comment appear when using Clang 4.0, but not on versions below it.

- Manuel

2017-07-13 16:36 GMT+02:00 Nirav Davé <[hidden email]>:
AFAIK we retain all assembly comments by default. I just tried this locally and it seems to work as expected with inline assembly comments should be preserved by default.

I suspect the comment does exist, but is on the next line. Currently, the trailing semicolon at the end of your instruction is interpreted as an EOL so the following comment is interpreted as a full line comment (We may want to change that). If you remove the semicolon you should find it on the same line. 

-Nirav


On Thu, Jul 13, 2017 at 7:51 AM, Manuel Rigger via cfe-dev <[hidden email]> wrote:
Hi,

I'm investigating how inline assembly is used in C projects. While doing so, I found that a number of projects include comments as part of their inline assembly snippets. The code snippet below is an example:

#include <stdint.h>

uint64_t atomic_swap_long(volatile uint64_t *p, uint64_t v) {
  __asm __volatile(
    "xchgq %1,%0; # atomic_swap_long"
: "+r" (v),   /* 0 */
 "+m" (*p)); /* 1 */
  return v;
}

When compiling with GCC (gcc -O1 -S) the following code is produced for the inline assembly snippet on my system:

 #APP
# 4 "inline-assembly-comment.c" 1
xchgq (%rdi),%rax; # atomic_swap_long
# 0 "" 2
#NO_APP

With Clang 3.8 and below, an empty line is inserted instead of the comment:

#APP
xchgq %rsi, (%rdi)
#NO_APP

With Clang 3.9 and 4.0, the newline disappeared but the comment is still not part of the assembly code.

The comment is retained on the LLVM IR level:

%5 = call i64 asm sideeffect "xchgq\09$1,$0; # atomic_swap_long", "=r,=*m,0,*m,~{dirflag},~{fpsr},~{flags}"(i64* %4, i64 %3, i64* %4)

Is this intended? Should I open a bug report?

- Manuel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Inline Assembly Comments

Romanenkov Kirill via cfe-dev
It looks like godbolt's comment filtering is removing the line if it gets placed on a separate line. The comments do appear for 4.0 and later. 

-Nirav

On Thu, Jul 13, 2017 at 10:59 AM, Manuel Rigger <[hidden email]> wrote:
I filed a bug (see https://bugs.llvm.org/show_bug.cgi?id=33770).

It seems the comment is swallowed (i.e., it is also not on the next line). I verified this locally and using Compiler Explorer (see https://godbolt.org/). Removing the trailing semicolon lets the comment appear when using Clang 4.0, but not on versions below it.

- Manuel

2017-07-13 16:36 GMT+02:00 Nirav Davé <[hidden email]>:
AFAIK we retain all assembly comments by default. I just tried this locally and it seems to work as expected with inline assembly comments should be preserved by default.

I suspect the comment does exist, but is on the next line. Currently, the trailing semicolon at the end of your instruction is interpreted as an EOL so the following comment is interpreted as a full line comment (We may want to change that). If you remove the semicolon you should find it on the same line. 

-Nirav


On Thu, Jul 13, 2017 at 7:51 AM, Manuel Rigger via cfe-dev <[hidden email]> wrote:
Hi,

I'm investigating how inline assembly is used in C projects. While doing so, I found that a number of projects include comments as part of their inline assembly snippets. The code snippet below is an example:

#include <stdint.h>

uint64_t atomic_swap_long(volatile uint64_t *p, uint64_t v) {
  __asm __volatile(
    "xchgq %1,%0; # atomic_swap_long"
: "+r" (v),   /* 0 */
 "+m" (*p)); /* 1 */
  return v;
}

When compiling with GCC (gcc -O1 -S) the following code is produced for the inline assembly snippet on my system:

 #APP
# 4 "inline-assembly-comment.c" 1
xchgq (%rdi),%rax; # atomic_swap_long
# 0 "" 2
#NO_APP

With Clang 3.8 and below, an empty line is inserted instead of the comment:

#APP
xchgq %rsi, (%rdi)
#NO_APP

With Clang 3.9 and 4.0, the newline disappeared but the comment is still not part of the assembly code.

The comment is retained on the LLVM IR level:

%5 = call i64 asm sideeffect "xchgq\09$1,$0; # atomic_swap_long", "=r,=*m,0,*m,~{dirflag},~{fpsr},~{flags}"(i64* %4, i64 %3, i64* %4)

Is this intended? Should I open a bug report?

- Manuel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev





_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Inline Assembly Comments

Romanenkov Kirill via cfe-dev
Ah, okay. Locally, I only tested Clang versions up to 3.9.

Should we close the bug report? Having slightly different conventions than GCC here is probably not an issue.

- Manuel

2017-07-13 17:46 GMT+02:00 Nirav Davé <[hidden email]>:
It looks like godbolt's comment filtering is removing the line if it gets placed on a separate line. The comments do appear for 4.0 and later. 

-Nirav

On Thu, Jul 13, 2017 at 10:59 AM, Manuel Rigger <[hidden email]> wrote:
I filed a bug (see https://bugs.llvm.org/show_bug.cgi?id=33770).

It seems the comment is swallowed (i.e., it is also not on the next line). I verified this locally and using Compiler Explorer (see https://godbolt.org/). Removing the trailing semicolon lets the comment appear when using Clang 4.0, but not on versions below it.

- Manuel

2017-07-13 16:36 GMT+02:00 Nirav Davé <[hidden email]>:
AFAIK we retain all assembly comments by default. I just tried this locally and it seems to work as expected with inline assembly comments should be preserved by default.

I suspect the comment does exist, but is on the next line. Currently, the trailing semicolon at the end of your instruction is interpreted as an EOL so the following comment is interpreted as a full line comment (We may want to change that). If you remove the semicolon you should find it on the same line. 

-Nirav


On Thu, Jul 13, 2017 at 7:51 AM, Manuel Rigger via cfe-dev <[hidden email]> wrote:
Hi,

I'm investigating how inline assembly is used in C projects. While doing so, I found that a number of projects include comments as part of their inline assembly snippets. The code snippet below is an example:

#include <stdint.h>

uint64_t atomic_swap_long(volatile uint64_t *p, uint64_t v) {
  __asm __volatile(
    "xchgq %1,%0; # atomic_swap_long"
: "+r" (v),   /* 0 */
 "+m" (*p)); /* 1 */
  return v;
}

When compiling with GCC (gcc -O1 -S) the following code is produced for the inline assembly snippet on my system:

 #APP
# 4 "inline-assembly-comment.c" 1
xchgq (%rdi),%rax; # atomic_swap_long
# 0 "" 2
#NO_APP

With Clang 3.8 and below, an empty line is inserted instead of the comment:

#APP
xchgq %rsi, (%rdi)
#NO_APP

With Clang 3.9 and 4.0, the newline disappeared but the comment is still not part of the assembly code.

The comment is retained on the LLVM IR level:

%5 = call i64 asm sideeffect "xchgq\09$1,$0; # atomic_swap_long", "=r,=*m,0,*m,~{dirflag},~{fpsr},~{flags}"(i64* %4, i64 %3, i64* %4)

Is this intended? Should I open a bug report?

- Manuel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev






_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Inline Assembly Comments

Romanenkov Kirill via cfe-dev
Seems reasonable. Some variation in comments between gcc and llvm is fundamental as the integrated assembler will not output preprocessor comments (e.g. /**/ and //) though it accepts them while gcc just passes the inline assembly string through with appropriate replacements. Some minor comment shifting should be fine.  

-Nirav

On Mon, Jul 17, 2017 at 4:39 AM, Manuel Rigger <[hidden email]> wrote:
Ah, okay. Locally, I only tested Clang versions up to 3.9.

Should we close the bug report? Having slightly different conventions than GCC here is probably not an issue.

- Manuel

2017-07-13 17:46 GMT+02:00 Nirav Davé <[hidden email]>:
It looks like godbolt's comment filtering is removing the line if it gets placed on a separate line. The comments do appear for 4.0 and later. 

-Nirav

On Thu, Jul 13, 2017 at 10:59 AM, Manuel Rigger <[hidden email]> wrote:
I filed a bug (see https://bugs.llvm.org/show_bug.cgi?id=33770).

It seems the comment is swallowed (i.e., it is also not on the next line). I verified this locally and using Compiler Explorer (see https://godbolt.org/). Removing the trailing semicolon lets the comment appear when using Clang 4.0, but not on versions below it.

- Manuel

2017-07-13 16:36 GMT+02:00 Nirav Davé <[hidden email]>:
AFAIK we retain all assembly comments by default. I just tried this locally and it seems to work as expected with inline assembly comments should be preserved by default.

I suspect the comment does exist, but is on the next line. Currently, the trailing semicolon at the end of your instruction is interpreted as an EOL so the following comment is interpreted as a full line comment (We may want to change that). If you remove the semicolon you should find it on the same line. 

-Nirav


On Thu, Jul 13, 2017 at 7:51 AM, Manuel Rigger via cfe-dev <[hidden email]> wrote:
Hi,

I'm investigating how inline assembly is used in C projects. While doing so, I found that a number of projects include comments as part of their inline assembly snippets. The code snippet below is an example:

#include <stdint.h>

uint64_t atomic_swap_long(volatile uint64_t *p, uint64_t v) {
  __asm __volatile(
    "xchgq %1,%0; # atomic_swap_long"
: "+r" (v),   /* 0 */
 "+m" (*p)); /* 1 */
  return v;
}

When compiling with GCC (gcc -O1 -S) the following code is produced for the inline assembly snippet on my system:

 #APP
# 4 "inline-assembly-comment.c" 1
xchgq (%rdi),%rax; # atomic_swap_long
# 0 "" 2
#NO_APP

With Clang 3.8 and below, an empty line is inserted instead of the comment:

#APP
xchgq %rsi, (%rdi)
#NO_APP

With Clang 3.9 and 4.0, the newline disappeared but the comment is still not part of the assembly code.

The comment is retained on the LLVM IR level:

%5 = call i64 asm sideeffect "xchgq\09$1,$0; # atomic_swap_long", "=r,=*m,0,*m,~{dirflag},~{fpsr},~{flags}"(i64* %4, i64 %3, i64* %4)

Is this intended? Should I open a bug report?

- Manuel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev







_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev