Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Macro_rules! for generating const-generic parameters
Hello,
I am currently working on a performance critical part of a person project (long-range router plotter for Elite: Dangerous, using parallel beam-search across and implicit graph) and i want to do some compile-time branch-elimination (at the cost of code size).
The signature for my worker functions looks like this:
pub(crate) fn route_beam_impl<
const REFUEL: bool,
const SHIP: bool,
const LIMIT: bool,
>(&self, args: ArgTuple) -> _
And contains a few if
s that disable parts of the code based on the const-generics parameters.
My idea is to generate an array of functions pointers for every combination of parameters using a macro and then at runtime computing an index into the array and calling the corresponding function (that call is outside the hot path, so the indirection doesn't matter) but i'm struggling with the implementation since I have almost no experience writing macros.
My idea was to have a macro invocation like const FN: [RouteFn;8] = generate_static_dispatch_array(Self::route_beam_impl; REFUEL, SHIP, LIMIT)
which would then generate something like
const FN: [RouteFn;8] = [
Self::route_beam_impl<false,false,false>,
Self::route_beam_impl<false,false,true>,
Self::route_beam_impl<false,true,false>,
...
];
But I'm not sure how to actually implement my idea.
Best regards,
Daniel
1 post - 1 participant
🏷️ rust_feed