Files
Parth Saini e24dc1ff4c core: add CV_CPU_GET_FN_PTR_<OPT>() to resolve dispatched function pointers
The generated cv_cpu_helper.h sets CV_TRY_<OPT> to 1 both when <OPT> is a
dispatch target and when it is part of the baseline, but an opt_<OPT> namespace
is only emitted for the dispatch case: __ocv_add_dispatched_file() guards it
with CPU_DISPATCH_FINAL, and a baseline optimization is deliberately kept out of
that list. Code that hand-rolls "#if CV_TRY_<OPT> ... opt_<OPT>::fn" therefore
fails to compile as soon as the optimization lands in the baseline, e.g. with
-DCPU_BASELINE=AVX512_ICL or -march=native on an ICL capable CPU:

  lut.dispatch.cpp:22:16: error: 'opt_AVX512_ICL' has not been declared

CV_CPU_CALL_<OPT>() already handles the namespace selection for a call. Add the
same thing for code that needs the function pointer instead:

  CV_CPU_GET_FN_PTR_<OPT>(fn)       per optimization
  CV_CPU_GET_FN_PTR_BASELINE(fn)    chain terminator
  CV_CPU_DISPATCH_FN(fn, modes)     full chain, mirrors CV_CPU_DISPATCH()

In the baseline case it resolves to cpu_baseline::fn, which is the <OPT> build
of the kernel, so no implementation is lost and no second copy is emitted. In
the dispatch case it keeps the cv::checkHardwareSupport() test and returns
opt_<OPT>::fn, and it compiles out when the optimization is unavailable.

Use it in the two places that hit this, which also removes the hand-written
preprocessor blocks. Generated code for the dispatch configuration is unchanged
(byte-identical .text with -DCPU_BASELINE=SSE3 -DCPU_DISPATCH=AVX512_ICL).

Fixes #29694
2026-08-12 18:10:38 +05:30
..