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

ASM output removing labels used by cbz and cbnz instructions on aarch64 #318

Closed
GrayJack opened this issue Oct 7, 2024 · 5 comments · Fixed by #322
Closed

ASM output removing labels used by cbz and cbnz instructions on aarch64 #318

GrayJack opened this issue Oct 7, 2024 · 5 comments · Fixed by #322

Comments

@GrayJack
Copy link

GrayJack commented Oct 7, 2024

I noticed that the output of cargo asm on aarch64 removes the labels used on the branching instructions cbz and cbnz.

I made a simple strchr example:

#[no_mangle]
pub unsafe extern "C" fn strchr(mut str: *const c_char, ch: c_int) -> *mut c_char {
    let ch = ch as c_char;
    loop {
        if *str == 0 {
            break ptr::null_mut();
        }

        if *str == ch {
            break str as *mut c_char;
        }

        str = str.add(1);
    }
}

Output:

	.globl	_strchr
	.p2align	2
_strchr:
Lfunc_begin439:
	.cfi_startproc
	ldrb w9, [x0]
	cbz w9, LBB439_4
	and w8, w1, #0xff
	cmp w9, w8
	b.eq LBB439_5
	ldrb w9, [x0, #1]!
	cbnz w9, LBB439_2
	mov x0, #0
LBB439_5:
	ret

Expected result should be:

	.globl	_strchr
	.p2align	2
_strchr:
	ldrb	w9, [x0]
	cbz	w9, LBB439_4
	and	w8, w1, #0xff
LBB439_2:
	cmp	w9, w8
	b.eq	LBB439_5
	ldrb	w9, [x0, #1]!
	cbnz	w9, LBB439_2
LBB439_4:
	mov	x0, #0
LBB439_5:
	ret

I tested this on aarch64 macOS and Linux and this happens to these instruction on both.

@pacak
Copy link
Owner

pacak commented Oct 7, 2024

Is this actual or expected output? And what should the other output should be?

@GrayJack
Copy link
Author

GrayJack commented Oct 7, 2024

Sorry, I forgot to include that.

The expected result would be:

	.globl	_strchr
	.p2align	2
_strchr:
	ldrb	w9, [x0]
	cbz	w9, LBB439_4
	and	w8, w1, #0xff
LBB439_2:
	cmp	w9, w8
	b.eq	LBB439_5
	ldrb	w9, [x0, #1]!
	cbnz	w9, LBB439_2
LBB439_4:
	mov	x0, #0
LBB439_5:
	ret

@pacak
Copy link
Owner

pacak commented Oct 7, 2024

Will take a look. Can you include the .s file from target folder? You should be able to find exact name if you pass one or more -v flags - this way I should be able to test if it worked without having to mess with cross-compilation.

@GrayJack
Copy link
Author

GrayJack commented Oct 7, 2024

Sure! Here it is:

tests-02b2c38f374f3d00.s.zip

@pacak
Copy link
Owner

pacak commented Oct 17, 2024

0.2.41 is out, this issue should be fixed.

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

Successfully merging a pull request may close this issue.

2 participants