Skip to content

[HLSL] Propose generic bitfield intrinsics in LLVM #89641

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
bogner opened this issue Apr 22, 2024 · 1 comment
Open

[HLSL] Propose generic bitfield intrinsics in LLVM #89641

bogner opened this issue Apr 22, 2024 · 1 comment
Labels
HLSL HLSL Language Support

Comments

@bogner
Copy link
Contributor

bogner commented Apr 22, 2024

As per the conclusions in #87367, we should propose adding bitfield instructions as generic LLVM intrinsics. Specifically, we need operations for Bfi, Ibfe, and Ubfe.

These operations exist in several ISAs (sometimes spelled differently, as in BFX on ARM archs), so I think it's reasonable to argue that having a generic for intrinsic for them is useful.

Acceptance Criteria

  • Either consensus from the LLVM community that we should add these operations, or a well reasoned rejection
    • this discussion will occur on the LLVM discourse
@pinskia
Copy link

pinskia commented Apr 23, 2024

Note GCC's IRs have BIT_FIELD_REF/BIT_INSERT_EXPR (gimple) and zero_extract/sign_extract (RTL; zero_extract can be on lhs of an RTL insn) which is used for both bit field extractions and inserts.

BIT_FIELD_REF takes 3 operands, 0: the original SSA_NAME; 1: bit width, 2: bits starting psoition (1 and 2 have to be constants); the resulting type needs to be the same precision as the bit width (the sign/zero extract is implicit with the cast afterwards)
BIT_INSERT_EXPR takes 3 operands, 0: the original SSA_NAME, 1: the replacement value (SSA_NAME or constant), 2: starting position. The width is taken based on the replacement value precision/size

zero_extract/sign_extract takes 3 operands, similar as BIT_FIELD_REF except for the resulting mode is the same as the inner mode is the same as the outer mode. To do an bit insert, you have a zero_extract on the lhs describing which bits are inserted including width.

how this helps to see understand how at least one other compiler handle this.

@damyanp damyanp moved this to Ready in HLSL Support Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HLSL HLSL Language Support
Projects
Status: Ready
Development

No branches or pull requests

3 participants