Skip to content

Support 64-bit OpSwitch literals - #24

Closed
LegNeato wants to merge 1 commit into
mainfrom
codex/op-switch-64-bit-literals
Closed

LegNeato wants to merge 1 commit into
mainfrom
codex/op-switch-64-bit-literals

Conversation

@LegNeato

Copy link
Copy Markdown
Collaborator

Support decoding OpSwitch case tables whose selector uses 64-bit literals. The grammar operand is context-dependent, so generated OpSwitch now uses a lossless SwitchTargets operand with typed 32-bit and 64-bit views instead of assuming LiteralInteger is always one word.

This also gates grammar-parser codegen reexports behind the codegen feature so the package test set compiles without that optional feature.

Validation:

  • cargo test -p rspirv2 -p rspirv2-types
  • rust-gpu: cargo test -p rustc_codegen_spirv --features cranelift-backend linker::input
  • rust-gpu: cargo run -p compiletests --features cranelift-backend -- dis/add_two_ints_cranelift

@LegNeato LegNeato changed the title [codex] support 64-bit OpSwitch literals Support 64-bit OpSwitch literals May 28, 2026
@LegNeato

Copy link
Copy Markdown
Collaborator Author

Note: written by AI

@LegNeato
LegNeato marked this pull request as ready for review May 28, 2026 20:59
@LegNeato

LegNeato commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Oops, didn't see #21. @Firestar99 , do you think you can use something like this or is your PR better? This one seems straightforward and smaller but I bet it is missing something

@Firestar99 Firestar99 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've shrunk the other PR in half by deleting an old stale branch, due to which github changed the base of the PR to main, throwing out half of the commits which were already merged...

And now the other PR is actually smaller :D

Comment on lines +255 to +274
#[inline]
fn dis_fmt(&self, f: &mut Formatter<'_>, ctx: &OperandDisContext<'_>) -> std::fmt::Result {
if self
.words
.len()
.is_multiple_of(switch_case_word_len::<SwitchLiteral32>())
{
for case in self.cases::<SwitchLiteral32>().expect("validated above") {
case.dis_fmt(f, ctx)?;
}
} else {
for case in self
.cases::<SwitchLiteral64>()
.expect("validated on construction")
{
case.dis_fmt(f, ctx)?;
}
}
Ok(())
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The biggest problem would be that it just tries to decode it as 32bit, so if you encounter a a 6-word switch it'll just assume it's 32bit and disassemble it like that without even checking. Which is really bad if you want to use disassembly for tooling.

The other PR doesn't properly solve this case either yet, there I was assuming that OpSwitch had a ResultIdType operand but it doesn't, which is why it's hitting unwraps. The only way to properly implement it would be to accumulate a def-use chain in DisContext (or rather a ResultId (def) -> PrimitiveType would be sufficient). I've somewhat started that in the other branch it seems like without finishing it off...

@Firestar99

Copy link
Copy Markdown
Member

Superseded by #21

@Firestar99 Firestar99 closed this Jun 15, 2026
@LegNeato
LegNeato deleted the codex/op-switch-64-bit-literals branch June 15, 2026 15:12
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.

2 participants