-
Notifications
You must be signed in to change notification settings - Fork 296
loongarch: Add basic support for LoongArch32 #1837
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
Open
heiher
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
heiher:loong32
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! `LoongArch32` intrinsics | ||
|
||
use crate::arch::asm; | ||
|
||
#[allow(improper_ctypes)] | ||
unsafe extern "unadjusted" { | ||
#[link_name = "llvm.loongarch.cacop.w"] | ||
fn __cacop(a: i32, b: i32, c: i32); | ||
#[link_name = "llvm.loongarch.csrrd.w"] | ||
fn __csrrd(a: i32) -> i32; | ||
#[link_name = "llvm.loongarch.csrwr.w"] | ||
fn __csrwr(a: i32, b: i32) -> i32; | ||
#[link_name = "llvm.loongarch.csrxchg.w"] | ||
fn __csrxchg(a: i32, b: i32, c: i32) -> i32; | ||
} | ||
|
||
/// Generates the cache operation instruction | ||
#[inline] | ||
#[unstable(feature = "stdarch_loongarch", issue = "117427")] | ||
pub unsafe fn cacop<const IMM12: i32>(a: i32, b: i32) { | ||
static_assert_simm_bits!(IMM12, 12); | ||
__cacop(a, b, IMM12); | ||
} | ||
|
||
/// Reads the CSR | ||
#[inline] | ||
#[unstable(feature = "stdarch_loongarch", issue = "117427")] | ||
pub unsafe fn csrrd<const IMM14: i32>() -> i32 { | ||
static_assert_uimm_bits!(IMM14, 14); | ||
__csrrd(IMM14) | ||
} | ||
|
||
/// Writes the CSR | ||
#[inline] | ||
#[unstable(feature = "stdarch_loongarch", issue = "117427")] | ||
pub unsafe fn csrwr<const IMM14: i32>(a: i32) -> i32 { | ||
static_assert_uimm_bits!(IMM14, 14); | ||
__csrwr(a, IMM14) | ||
} | ||
|
||
/// Exchanges the CSR | ||
#[inline] | ||
#[unstable(feature = "stdarch_loongarch", issue = "117427")] | ||
pub unsafe fn csrxchg<const IMM14: i32>(a: i32, b: i32) -> i32 { | ||
static_assert_uimm_bits!(IMM14, 14); | ||
__csrxchg(a, b, IMM14) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to have these in the common code returning
isize
? It is technically a breaking change but this is still an unstable feature.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comments. I don't quite understand why this is considered a breaking change. Previously, LoongArch64 exported
csrrd(i32) -> i64
, and it sill does. Now, LoongArch32 is introducingcsrrd(i32) -> i32
, which doesn't change the existing behavior.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm suggesting having a single shared intrinsic
csrrd(i32) -> isize
instead of separate ones for loongarch32 and loongarch64.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see -- I misunderstood your point. On 32-bit target, the link name for
__csrrd
isllvm.*.csrrd.w
, while on 64-bit it'scsrrd.d
. That means we'd need to use#[cfg()]
in the shared code? Would it be better to just keep things as they are?