Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment after JMP at indentation level 0 #35

Closed
mmcloughlin opened this issue Jan 11, 2019 · 5 comments
Closed

Comment after JMP at indentation level 0 #35

mmcloughlin opened this issue Jan 11, 2019 · 5 comments

Comments

@mmcloughlin
Copy link

mmcloughlin commented Jan 11, 2019

I have the following:

// Code generated by command: go run asm.go -out sum.s -stubs stub.go. DO NOT EDIT.

#include "textflag.h"

// func Sum(xs []uint64) uint64
TEXT ·Sum(SB), NOSPLIT, $0-32
	MOVQ xs_base(FP), AX
	MOVQ xs_len+8(FP), CX

	// Initialize sum register to zero.
	XORQ DX, DX

	// Loop until zero bytes remain.
loop:
	CMPQ CX, $0x00
	JE   done

	// Load from pointer and add to running sum.
	ADDQ (AX), DX

	// Advance pointer, decrement byte count.
	ADDQ $0x08, AX
	DECQ CX
	JMP  loop

	// Store sum to return value.
done:
	MOVQ DX, ret+24(FP)
	RET

I am not sure I agree with the asmfmt result here:

$ asmfmt -d ./examples/sum/sum.s
diff ./examples/sum/sum.s asmfmt/./examples/sum/sum.s
--- /var/folders/p5/84p384bs42v7pbgfx0db9gq80000gn/T/asmfmt374566857	2019-01-11 12:30:24.000000000 -0800
+++ /var/folders/p5/84p384bs42v7pbgfx0db9gq80000gn/T/asmfmt487530132	2019-01-11 12:30:24.000000000 -0800
@@ -23,7 +23,7 @@
 	DECQ CX
 	JMP  loop

-	// Store sum to return value.
+// Store sum to return value.
 done:
 	MOVQ DX, ret+24(FP)
 	RET

Is this intended behavior?

@klauspost
Copy link
Owner

The comment is intended to document what is below. The label is considered "global" and is therefore not indented, and the comment above keeps that indentation. So yes, it is intended.

If you want it indented, it can be moved to after the label

@mmcloughlin
Copy link
Author

Why does it move the comment before "done" but not the comment before "loop"?

@mmcloughlin
Copy link
Author

I think this is a minimal example of what I'm asking:

$ cat labelcomments.s
#include "textflag.h"

TEXT ·LabelComments(SB), NOSPLIT, $0-32
	XORQ AX, AX
	// A
a:
	JMP b
	// B
b:
	XORQ AX, AX
$ asmfmt labelcomments.s
#include "textflag.h"

TEXT ·LabelComments(SB), NOSPLIT, $0-32
	XORQ AX, AX

	// A
a:
	JMP b

// B
b:
	XORQ AX, AX

@klauspost
Copy link
Owner

JMP and RET are considered terminators meaning they terminate the block they are in.

Comments are seen as belonging to whatever is following them. Therefore the B is considered as belonging to the b label.

@mmcloughlin
Copy link
Author

I know what terminator instructions are. It does not seem right to me that they should affect formatting in this way.

Comments are seen as belonging to whatever is following them.

This seems reasonable. Therefore A should belong to the a label also.

Anyway, seems clear that you intended it to work this way, and we just happen to disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants