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: Add a kreg0 register class on x86 which includes k0 #95740

Merged
merged 1 commit into from
Apr 20, 2022

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Apr 6, 2022

Previously we only exposed a kreg register class which excludes the k0
register since it can't be used in many instructions. However k0 is a
valid register and we need to have a way of marking it as clobbered for
clobber_abi.

Fixes #94977

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 6, 2022
@rust-highfive
Copy link
Collaborator

Some changes occured to rustc_codegen_gcc

cc @antoyo

@rust-highfive
Copy link
Collaborator

r? @wesleywiser

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2022
@rust-log-analyzer

This comment has been minimized.

@Amanieu Amanieu force-pushed the kreg0 branch 2 times, most recently from 260e932 to d152363 Compare April 6, 2022 23:35
@wesleywiser
Copy link
Member

This looks correct to me but I'd like someone more familiar with this space to double check.

r? @nagisa perhaps?

@rust-highfive rust-highfive assigned nagisa and unassigned wesleywiser Apr 7, 2022
@@ -29,8 +29,6 @@ fn main() {
//~^ ERROR invalid register `rsp`: the stack pointer cannot be used as an operand
asm!("", in("ip") foo);
//~^ ERROR invalid register `ip`: the instruction pointer cannot be used as an operand
asm!("", in("k0") foo);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this being removed? It is still invalid to use k0 as an input/output operand, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's now valid. I previously incorrectly thought k0 wasn't a real register, like xzr on AArch64.

Copy link
Member

Choose a reason for hiding this comment

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

I think in that case the description should be updated

However k0 is a valid register and we need to have a way of marking it as clobbered for clobber_abi.

somewhat misleadingly led me to believe that k0 was only being exposed for use as a clobber.

Comment on lines 298 to 305
k0: kreg0 = ["k0"],
k1: kreg, kreg0 = ["k1"],
k2: kreg, kreg0 = ["k2"],
k3: kreg, kreg0 = ["k3"],
k4: kreg, kreg0 = ["k4"],
k5: kreg, kreg0 = ["k5"],
k6: kreg, kreg0 = ["k6"],
k7: kreg, kreg0 = ["k7"],
Copy link
Member

Choose a reason for hiding this comment

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

I find the kreg0 register group name quite surprising. Intuitively I expected this register class to include just the k0 register, rather than being kreg + k0. In retrospective it makes sense, but I felt there was definitely a surprise factor of sorts. I wonder if there is a name which would have an obvious interpretation.

As a side note, preexisting, and probably half my fault, but isn't the naming of this group inconsistent with the other groups? We can't fix this now, can we?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have a better ideas for the register class name.

I don't think the naming is too inconsistent. kreg is what you usually want most of the time.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a better ideas for the register class name.

Hmm… kreg_full or kreg_all, perhaps?

I don't think the naming is too inconsistent. kreg is what you usually want most of the time.

Ah, I meant in relation to other classes like abcd_reg, xmm_reg, ymm_reg et al. If the convention of separating reg from types of register, kreg would be k_reg. Nothing we can do here anymore, though.

Copy link
Member

Choose a reason for hiding this comment

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

The rule is consistent but idiosyncratic: kreg, vreg, preg, then xmm_reg, x87_reg, etc.
Like

if class.len() <= 1 {
    format!("{class}reg")
else {
    format!("{class}_reg")
}

@Amanieu
Copy link
Member Author

Amanieu commented Apr 19, 2022

I think I'll just go with the most forward-compatible approach which is just to let k0 be a clobber-only register for now.

@Amanieu
Copy link
Member Author

Amanieu commented Apr 19, 2022

This avoids the naming issue since a clobber-only register class can't be used directly.

@rust-log-analyzer

This comment has been minimized.

Previously we only exposed a kreg register class which excludes the k0
register since it can't be used in many instructions. However k0 is a
valid register and we need to have a way of marking it as clobbered for
clobber_abi.

Fixes rust-lang#94977
@nagisa
Copy link
Member

nagisa commented Apr 19, 2022

@bors r+

I guess the takeaway here I have is that we probably want a mechanism to feature-gate specific register classes so that we could introduce additional ones for stable inline-asm implementations without making them insta-stable too.

@bors
Copy link
Contributor

bors commented Apr 19, 2022

📌 Commit b2bc469 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 19, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#95740 (asm: Add a kreg0 register class on x86 which includes k0)
 - rust-lang#95813 (Remove extra space before a where clause)
 - rust-lang#96029 (Refactor loop into iterator; simplify negation logic.)
 - rust-lang#96162 (interpret: Fix writing uninit to an allocation)
 - rust-lang#96165 (Miri provenance cleanup)
 - rust-lang#96205 (Use futex locks on emscripten.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 69e45d7 into rust-lang:master Apr 20, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 20, 2022
Amanieu added a commit to Amanieu/reference that referenced this pull request May 5, 2022
antoyo pushed a commit to antoyo/rust that referenced this pull request Jun 7, 2022
asm: Add a kreg0 register class on x86 which includes k0

Previously we only exposed a kreg register class which excludes the k0
register since it can't be used in many instructions. However k0 is a
valid register and we need to have a way of marking it as clobbered for
clobber_abi.

Fixes rust-lang#94977
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inline asm docs incorrectly state that k0 (x86 AVX-512) is hard-wired to zero
8 participants