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

Add support for asm!() #97

Merged
merged 1 commit into from
Apr 26, 2022
Merged

Add support for asm!() #97

merged 1 commit into from
Apr 26, 2022

Conversation

Patryk27
Copy link
Contributor

@Patryk27 Patryk27 commented Apr 24, 2022

Closes #91.

Abstract

Starting from 1.59.0, rustc has been removed support for the llvm_asm!() macro, making it impossible to use avr-device with newer compilers.

This merge requests adjusts the code, so that it continues to use llvm_asm!() on older compilers (such as the infamous nightly-2021-01-07), but switches to asm!() on the newer ones.

Due Diligence

I've checked the code on nightly-2021-01-07 and a custom-built rustc from around yesterday (b759b2218649016cc40e82bdd6d958e2277ff6d7), and everything seems to be working correctly.

I've compared the generated LLVM IRs for an application I'm developing, and they are virtually identical:

enable():

older rustc:
  tail call addrspace(0) void asm sideeffect "sei", ""() #10, !srcloc !5

newer rustc:
  tail call addrspace(0) void asm sideeffect alignstack "sei", "~{sreg},~{memory}"() #14, !srcloc !6

disable():

older rustc:
  %0 = tail call addrspace(0) i8 asm sideeffect "in $0,0x3F", "=r"() #10, !srcloc !2
  tail call addrspace(0) void asm sideeffect "cli", ""() #10, !srcloc !3

newer rustc:
  %1 = tail call addrspace(0) i8 asm sideeffect alignstack "in ${0}, 0x3F", "=&r,~{sreg},~{memory}"() #14, !srcloc !2
  tail call addrspace(0) void asm sideeffect alignstack "cli", "~{sreg},~{memory}"() #14, !srcloc !3

The compiled binary seems to be working correctly on an Atmega328p, too.

Follow-ups

I've also got a similar set of changes to avr-hal, I'll try pushing the merge request in a few minutes :-)

README.md Show resolved Hide resolved
Copy link
Owner

@Rahix Rahix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thank you so much for the PR, this is really great! There is just one thing I'd like to be different, see comments below :)

build.rs Outdated Show resolved Hide resolved
src/asm.rs Outdated Show resolved Hide resolved
@Patryk27 Patryk27 requested a review from Rahix April 26, 2022 16:36
Copy link
Owner

@Rahix Rahix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Rahix Rahix merged commit 91d0ad8 into Rahix:main Apr 26, 2022
@Patryk27 Patryk27 deleted the asm branch April 26, 2022 19:41
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 this pull request may close these issues.

llvm_asm! removed in latest nightly rust
2 participants