If you're not familiar with policy-based design, that's OK... I'm willing to help point you in the right direction. Basically, you leverage the compiler to maintain a bunch of implementations of these particularly branch-y functions like the color combiner:
Code: Select all
#include <cstdint>
// Make policies some chromabypass; we either do it, or not.
template <bool kOtherModesKeyEn>
void combiner_1cycle_chromabypass();
template <>
void combiner_1cycle_chromabypass<false>() {}
template <>
void combiner_1cycle_chromabypass<true>() {
chromabypass.r = *combiner_rgbsub_a_r[1];
chromabypass.g = *combiner_rgbsub_a_g[1];
chromabypass.b = *combiner_rgbsub_a_b[1];
}
// OK, here's the implementation for combiner_1cycle.
template <bool kOtherModesKeyEn>
void combiner_1cycle(int adseed, uint32_t* curpixel_cvg) {
// Template magic! Use policies to specify whether this version
// of the color combiner should do chroma bypass or not.
combiner_1cycle_chromabypass<kOtherModesKeyEn>();
// ...
}
// Then just generate a variants of combiner_1cycle
// and select amongst them with a list of function ptrs.
void (*combiner_1cycle_ptrs[])(int, uint32_t*) = {
combiner_1cycle<true>,
combiner_1cycle<false>
};