-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Support for const string interpolation into inline assembly #132083
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
Comments
Requests from #132012 (comment) is fulfilled. Bonus question I guess. Do we want |
@rustbot claim |
I'm unclear why this is |
It might be surprising to users that |
One possible use-case for a feature like this might be implementing special operations for the NVPTX target: One special instruction in NVPTX is to fetch from texture memory. To fetch from texture memory that stores f32 values an inline assembly instruction looks like this: #[inline]
pub unsafe fn _tex_1d_fetch_f32(tex_object: u64, x: i32) -> f32 {
let mut res: f32;
asm! {
"tex.1d.v4.f32.s32 {{{f1}, {f2}, {f3}, {f4}}}, [{tex_object}, {{{x}}}];",
tex_object = in(reg64) tex_object,
x = in(reg32) x,
f1 = out(reg32) res,
f2 = out(reg32) _,
f3 = out(reg32) _,
f4 = out(reg32) _,
}
res
} With the proposed solution this function could be made generic over the 32 Bit type it fetches and the 32 Bit type of the indexing variable x: #[inline]
pub unsafe fn _tex_1d_fetch_32<T : TexDType32, U: TexCType> (tex_object: u64, x: U) -> T {
let mut res: T;
asm! {
"tex.1d.v4.{dtype}.{ctype} {{{f1}, {f2}, {f3}, {f4}}}, [{tex_object}, {{{x}}}];",
tex_object = in(reg64) tex_object,
x = in(reg32) x,
f1 = out(reg32) res,
f2 = out(reg32) _,
f3 = out(reg32) _,
f4 = out(reg32) _,
dtype = interpolate T::TYPE,
ctype = interpolate U::TYPE,
}
res
} (It would be benefitial to be generic over the register size as well, but this is another topic I think. Another way to implement such special operations could be using LLVM intrinsics. However, I do not know if LLVM intrinsics do exist for all special NVPTX instructions and how stable these are.). |
Related to this comment.
Maybe related to #93332
This feature request targets the inline assembly macro
asm!
and globally scope assemblyglobal_asm!
to support direct string interpolation into the assembly template.The semantic works very much like a
format!
in a narrower sense, that only constant string is supported. The proposed macro word isinterpolate $expr
where$expr
is a const-evaluatable expression that yields a&'static str
constant value.An example of how it would work is as follows.
The one and only instantiation of
asm!
macro, when completely expanded through codegen, might have yield the following assembly line.The text was updated successfully, but these errors were encountered: