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
2020-02-26 15:12:45 +03:00
2026-07-09 12:35:42 +03:00
2018-10-11 17:57:51 +00:00
2025-08-01 09:50:10 +03:00

OpenCV: Open Source Computer Vision Library

Resources

Contributing

Please read the contribution guidelines before starting work on a pull request.

Summary of the guidelines:

  • One pull request per issue;
  • Choose the right base branch;
  • Include tests and documentation;
  • Clean up "oops" commits before submitting;
  • Follow the coding style guide.

Additional Resources

Description
Languages
C++ 87.6%
C 3.2%
Python 2.9%
CMake 2%
Java 1.5%
Other 2.6%