nareshmlx/opencv-pr huggingface dataset:
**File:** cmake/OpenCVCompilerOptimizations.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -104,7 +104,7 @@ ocv_optimization_process_obsolete_option(ENABLE_AVX2 AVX2 ON)
 ocv_optimization_process_obsolete_option(ENABLE_FMA3 FMA3 ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VFPV3 VFPV3 OFF)
-ocv_optimization_process_obsolete_option(ENABLE_NEON NEON OFF)
+ocv_optimization_process_obsolete_option(ENABLE_NEON NEON ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VSX VSX ON)
 
@@ -170,7 +170,29 @@ elseif(" ${CMAKE_CXX_FLAGS} " MATCHES " -march=native | -xHost | /QxHost ")
```

Review comment:
> For dispatched optimization we still need to modify compiler flags anyway. Yes, perhaps users will be required to manually provide flags for dispatched files via `CPU_XXX_FLAGS_ON` variables. Examples with our cmake-toolchain file from this PR: * Build with RVV as a baseline: ` -DENABLE_RVV=ON` * Build without RVV in a baseline, but with dispatched RVV files: `-DCPU_DISPATCH=RVV -DCPU_RVV_FLAGS_ON=-march=rv64gcv` > empty or other values of CPU_BASELINE are used for limiting of used features Doesn't `CPU_BASELINE_DISABLE` do this? I tried to use it with this PR and enabled RVV compiler flags: `-DENABLE_RVV=ON -DCPU_BASELINE_DISABLE=RVV`, but I'm not sure if correct macros are being set in cv_cpu_config.h: ```.h // OpenCV CPU baseline features #define CV_CPU_COMPILE_RVV 1 #define CV_CPU_BASELINE_COMPILE_RVV 1 #define CV_CPU_BASELINE_FEATURES 0 \ , CV_CPU_RVV \ // OpenCV supported CPU dispatched features #define CV_CPU_DISPATCH_FEATURES 0 \ ```
**File:** platforms/linux/arm.toolchain.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -48,32 +48,23 @@ if(NOT DEFINED ARM_LINUX_SYSROOT AND DEFINED GNU_MACHINE)
   set(ARM_LINUX_SYSROOT /usr/${GNU_MACHINE}${FLOAT_ABI_SUFFIX})
 endif()
 
-if(NOT DEFINED CMAKE_CXX_FLAGS)
-  set(CMAKE_CXX_FLAGS           "" CACHE INTERNAL "")
-  set(CMAKE_C_FLAGS             "" CACHE INTERNAL "")
-  set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")
-  set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")
-  set(CMAKE_EXE_LINKER_FLAGS    "" CACHE INTERNAL "")
```

Review comment:
Oh, I remembered, it was an issue with CMAKE_CXX_FLAGS. As I understand, modern cmake (3.7+) have respective `_INIT` variables for toolchain files specifically (https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_INIT.html). In new commit I've updated some of our toolchains to use them too.
**File:** platforms/linux/arm.toolchain.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -48,32 +48,23 @@ if(NOT DEFINED ARM_LINUX_SYSROOT AND DEFINED GNU_MACHINE)
   set(ARM_LINUX_SYSROOT /usr/${GNU_MACHINE}${FLOAT_ABI_SUFFIX})
 endif()
 
-if(NOT DEFINED CMAKE_CXX_FLAGS)
-  set(CMAKE_CXX_FLAGS           "" CACHE INTERNAL "")
-  set(CMAKE_C_FLAGS             "" CACHE INTERNAL "")
-  set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")
-  set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")
-  set(CMAKE_EXE_LINKER_FLAGS    "" CACHE INTERNAL "")
```

Review comment:
Looks like these options are lost: - https://pullrequest.opencv.org/buildbot/builders/precommit_armv8/builds/100061 - https://pullrequest.opencv.org/buildbot/builders/precommit_armv7/builds/100073
**File:** cmake/OpenCVCompilerOptimizations.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -104,7 +104,7 @@ ocv_optimization_process_obsolete_option(ENABLE_AVX2 AVX2 ON)
 ocv_optimization_process_obsolete_option(ENABLE_FMA3 FMA3 ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VFPV3 VFPV3 OFF)
-ocv_optimization_process_obsolete_option(ENABLE_NEON NEON OFF)
+ocv_optimization_process_obsolete_option(ENABLE_NEON NEON ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VSX VSX ON)
 
@@ -170,7 +170,29 @@ elseif(" ${CMAKE_CXX_FLAGS} " MATCHES " -march=native | -xHost | /QxHost ")
```

Review comment:
`CPU_BASELINE=NATIVE` should be supported.
**File:** cmake/OpenCVCompilerOptimizations.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...
**Review Line:** 586

**Code Changes:**
```diff
   set(CPU_${OPT}_USAGE_COUNT 0 CACHE INTERNAL "")
   if("${CPU_${OPT}_FLAGS_ON}" STREQUAL "disabled")
@@ -577,7 +584,7 @@ foreach(OPT ${CPU_KNOWN_OPTIMIZATIONS})
   if(CPU_${OPT}_SUPPORTED)
     if(";${CPU_DISPATCH};" MATCHES ";${OPT};" AND NOT __is_from_baseline)
       list(APPEND CPU_DISPATCH_FINAL ${OPT})
-    elseif(__is_from_baseline)
+    elseif(__is_from_baseline AND NOT __is_disabled)
       if(NOT ";${CPU_BASELINE_FINAL};" MATCHES ";${OPT};")
         list(APPEND CPU_BASELINE_FINAL ${OPT})
       endif()
```

Review comment:
`CPU_BASELINE_DISABLE` should not affect `CPU_DISPATCH` modes.
**File:** platforms/linux/arm.toolchain.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -48,32 +48,23 @@ if(NOT DEFINED ARM_LINUX_SYSROOT AND DEFINED GNU_MACHINE)
   set(ARM_LINUX_SYSROOT /usr/${GNU_MACHINE}${FLOAT_ABI_SUFFIX})
 endif()
 
-if(NOT DEFINED CMAKE_CXX_FLAGS)
-  set(CMAKE_CXX_FLAGS           "" CACHE INTERNAL "")
-  set(CMAKE_C_FLAGS             "" CACHE INTERNAL "")
-  set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")
-  set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")
-  set(CMAKE_EXE_LINKER_FLAGS    "" CACHE INTERNAL "")
```

Review comment:
This is because cmake version on buildbot is too old (3.5.1) for this [feature](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_INIT.html) (`CMAKE_<LANG>_FLAGS_INIT`). I propose raising minimum cmake version to 3.7.
**File:** cmake/OpenCVCompilerOptimizations.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -104,7 +104,7 @@ ocv_optimization_process_obsolete_option(ENABLE_AVX2 AVX2 ON)
 ocv_optimization_process_obsolete_option(ENABLE_FMA3 FMA3 ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VFPV3 VFPV3 OFF)
-ocv_optimization_process_obsolete_option(ENABLE_NEON NEON OFF)
+ocv_optimization_process_obsolete_option(ENABLE_NEON NEON ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VSX VSX ON)
 
@@ -170,7 +170,29 @@ elseif(" ${CMAKE_CXX_FLAGS} " MATCHES " -march=native | -xHost | /QxHost ")
```

Review comment:
I'm still against forcing of `DETECT`. It could be default, but it should not be forced. We should not block user to disable some OpenCV intrinsics, e.g. for debug/testing purposes. Even if they are "enabled in compiler".
**File:** cmake/OpenCVCompilerOptimizations.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -104,7 +104,7 @@ ocv_optimization_process_obsolete_option(ENABLE_AVX2 AVX2 ON)
 ocv_optimization_process_obsolete_option(ENABLE_FMA3 FMA3 ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VFPV3 VFPV3 OFF)
-ocv_optimization_process_obsolete_option(ENABLE_NEON NEON OFF)
+ocv_optimization_process_obsolete_option(ENABLE_NEON NEON ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VSX VSX ON)
 
@@ -170,7 +170,29 @@ elseif(" ${CMAKE_CXX_FLAGS} " MATCHES " -march=native | -xHost | /QxHost ")
```

Review comment:
Why do we lost `_IMPLIES` configuration?
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -145,7 +145,7 @@ if(NOT OPENCV_SKIP_CMAKE_SYSTEM_FILE)
 endif()
 
 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)  # https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
-  if(NOT CMAKE_TOOLCHAIN_FILE)
+  if(NOT CMAKE_CROSSCOMPILING)
     if(WIN32)
       set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory" FORCE)
     else()
@@ -513,10 +513,6 @@ OCV_OPTION(OPENCV_ENABLE_MEMORY_SANITIZER "Better support for memory/address san
```

Review comment:
There is already something for platforms: https://github.com/opencv/opencv/tree/4.x/cmake/platforms We could add similar for processors.
**File:** platforms/linux/flags-aarch64.cmake
**Change Type:** added
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -0,0 +1,19 @@
+# see https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#index-march
+function(ocv_set_platform_flags VAR)
+  unset(flags)
+  if(ENABLE_BF16)
+    set(flags "${flags}+bf16")
+  endif()
+  if(ENABLE_DOTPROD)
+    set(flags "${flags}+dotprod")
+  endif()
```

Review comment:
Google uses `-march=armv8.2-a+bf16` for dispatched code: https://github.com/google/XNNPACK/blob/f416ab3d2781c8eb53eaa999239138296146b5e0/CMakeLists.txt#L836 Why do we need `8.4`?
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -145,7 +145,7 @@ if(NOT OPENCV_SKIP_CMAKE_SYSTEM_FILE)
 endif()
 
 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)  # https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
-  if(NOT CMAKE_TOOLCHAIN_FILE)
+  if(NOT CMAKE_CROSSCOMPILING)
     if(WIN32)
       set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory" FORCE)
     else()
@@ -513,10 +513,6 @@ OCV_OPTION(OPENCV_ENABLE_MEMORY_SANITIZER "Better support for memory/address san
```

Review comment:
> platforms/linux OSX/iOS? android? other OS? We should not depend on "linux" here.
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -145,7 +145,7 @@ if(NOT OPENCV_SKIP_CMAKE_SYSTEM_FILE)
 endif()
 
 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)  # https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
-  if(NOT CMAKE_TOOLCHAIN_FILE)
+  if(NOT CMAKE_CROSSCOMPILING)
     if(WIN32)
       set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory" FORCE)
     else()
@@ -513,10 +513,6 @@ OCV_OPTION(OPENCV_ENABLE_MEMORY_SANITIZER "Better support for memory/address san
```

Review comment:
This block's purpose is to use the same flags for native Linux compilation as for cross-compilation with **our** toolchain files. * It is not applicable to Android, because it uses own toolchain files from NDK and doesn't have native compilation (or does it?). * Also not applicable to OSX/iOS because we rely on CMake/XCode to set platform flags for specific target. * Not so sure about Windows, but it was not handled specifically by OpenCVCompilerOptimizations.cmake (we have only GCC/Clang flags there for AArch64). * Other platforms are not officially supported by us and I think we should recommend users to use there own cmake-toolchain files for these cases.
**File:** platforms/linux/flags-aarch64.cmake
**Change Type:** added
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -0,0 +1,19 @@
+# see https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#index-march
+function(ocv_set_platform_flags VAR)
+  unset(flags)
+  if(ENABLE_BF16)
+    set(flags "${flags}+bf16")
+  endif()
+  if(ENABLE_DOTPROD)
+    set(flags "${flags}+dotprod")
+  endif()
```

Review comment:
I used this table from GCC documentation to establish baselines with assumption that actual hardware also lines up with it and there are no platforms which have `dotprod` on top of `armv8.2-a`, plus an assumption that compiler can optimize code better for such "baseline" arch. ``` arch value Architecture Includes by default ‘armv8-a’ Armv8-A ‘+fp’, ‘+simd’ ‘armv8.1-a’ Armv8.1-A ‘armv8-a’, ‘+crc’, ‘+lse’, ‘+rdma’ ‘armv8.2-a’ Armv8.2-A ‘armv8.1-a’ ‘armv8.3-a’ Armv8.3-A ‘armv8.2-a’, ‘+pauth’ ‘armv8.4-a’ Armv8.4-A ‘armv8.3-a’, ‘+flagm’, ‘+fp16fml’, ‘+dotprod’ ‘armv8.5-a’ Armv8.5-A ‘armv8.4-a’, ‘+sb’, ‘+ssbs’, ‘+predres’ ‘armv8.6-a’ Armv8.6-A ‘armv8.5-a’, ‘+bf16’, ‘+i8mm’ ``` Should I change it back to `armv8.2-a+...`?
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -145,7 +145,7 @@ if(NOT OPENCV_SKIP_CMAKE_SYSTEM_FILE)
 endif()
 
 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)  # https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
-  if(NOT CMAKE_TOOLCHAIN_FILE)
+  if(NOT CMAKE_CROSSCOMPILING)
     if(WIN32)
       set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory" FORCE)
     else()
@@ -513,10 +513,6 @@ OCV_OPTION(OPENCV_ENABLE_MEMORY_SANITIZER "Better support for memory/address san
```

Review comment:
Perhaps we can move this specific block to `Linux.cmake` if it has all used variables being set at the time of importing (e.g. `CMAKE_CROSSCOMPILING`). I'll try it.
**File:** cmake/OpenCVCompilerOptimizations.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -104,7 +104,7 @@ ocv_optimization_process_obsolete_option(ENABLE_AVX2 AVX2 ON)
 ocv_optimization_process_obsolete_option(ENABLE_FMA3 FMA3 ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VFPV3 VFPV3 OFF)
-ocv_optimization_process_obsolete_option(ENABLE_NEON NEON OFF)
+ocv_optimization_process_obsolete_option(ENABLE_NEON NEON ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VSX VSX ON)
 
@@ -170,7 +170,29 @@ elseif(" ${CMAKE_CXX_FLAGS} " MATCHES " -march=native | -xHost | /QxHost ")
```

Review comment:
I had concerns that it might affect compilation flags for dispatched or baseline files. I'll try to restore it.
**File:** cmake/OpenCVCompilerOptimizations.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -104,7 +104,7 @@ ocv_optimization_process_obsolete_option(ENABLE_AVX2 AVX2 ON)
 ocv_optimization_process_obsolete_option(ENABLE_FMA3 FMA3 ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VFPV3 VFPV3 OFF)
-ocv_optimization_process_obsolete_option(ENABLE_NEON NEON OFF)
+ocv_optimization_process_obsolete_option(ENABLE_NEON NEON ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VSX VSX ON)
 
@@ -170,7 +170,29 @@ elseif(" ${CMAKE_CXX_FLAGS} " MATCHES " -march=native | -xHost | /QxHost ")
```

Review comment:
I've added support of an empty `CPU_BASELINE`. Currently this configuration is broken due to incorrect macros being used somewhere in DNN inline optimizations: compiler has feature enabled and some macros are enabled too, but some other macros from generated cv_cpu_config.hpp are disabled, thus causing missing symbols. ``` /usr/bin/ld: modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/cpu_kernels/conv_winograd_f63.cpp.o: in function `cv::dnn::runWinograd63(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::Ptr<cv::dnn::FastConv> const&, int, float, float, cv::dnn::dnn4_v20240521::ActivationLayer*, bool)::{lambda(cv::Range const&)#1}::operator()(cv::Range const&) const': /work/opencv/modules/dnn/src/layers/cpu_kernels/conv_winograd_f63.cpp:205: undefined reference to `cv::dnn::winofunc_BtXB_8x8_F32(float const*, int, float*, int, int, int)' /usr/bin/ld: modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/cpu_kernels/conv_winograd_f63.cpp.o: in function `cv::dnn::runWinograd63(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::Ptr<cv::dnn::FastConv> const&, int, float, float, cv::dnn::dnn4_v20240521::ActivationLayer*, bool)::{lambda(cv::Range const&)#2}::operator()(cv::Range const&) const': /work/opencv/modules/dnn/src/layers/cpu_kernels/conv_winograd_f63.cpp:302: undefined reference to `cv::dnn::winofunc_accum_F32(float const*, float const*, float*, int, int, int, int, int, int)' /usr/bin/ld: /work/opencv/modules/dnn/src/layers/cpu_kernels/conv_winograd_f63.cpp:368: undefined reference to `cv::dnn::winofunc_AtXA_8x8_F32(float const*, int, float*, int, float*, int, float, float, float, bool)' collect2: error: ld returned 1 exit status ``` It is not related to this PR and we'll need to resolve this issue separately, my quick fix attempt has failed.
**File:** platforms/linux/flags-aarch64.cmake
**Change Type:** added
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -0,0 +1,19 @@
+# see https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#index-march
+function(ocv_set_platform_flags VAR)
+  unset(flags)
+  if(ENABLE_BF16)
+    set(flags "${flags}+bf16")
+  endif()
+  if(ENABLE_DOTPROD)
+    set(flags "${flags}+dotprod")
+  endif()
```

Review comment:
Changed it to use `armv8.2-a+...` combination with feature flags. It became slightly more complicated, but I believe it's OK. Please let me know if we need to revert it.
**File:** cmake/OpenCVCompilerOptimizations.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -104,7 +104,7 @@ ocv_optimization_process_obsolete_option(ENABLE_AVX2 AVX2 ON)
 ocv_optimization_process_obsolete_option(ENABLE_FMA3 FMA3 ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VFPV3 VFPV3 OFF)
-ocv_optimization_process_obsolete_option(ENABLE_NEON NEON OFF)
+ocv_optimization_process_obsolete_option(ENABLE_NEON NEON ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VSX VSX ON)
 
@@ -170,7 +170,29 @@ elseif(" ${CMAKE_CXX_FLAGS} " MATCHES " -march=native | -xHost | /QxHost ")
```

Review comment:
Just "empty" handling is not enough. > We should not block user to disable some OpenCV intrinsics, e.g. for debug/testing purposes. Even if they are "enabled in compiler".
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -145,7 +145,7 @@ if(NOT OPENCV_SKIP_CMAKE_SYSTEM_FILE)
 endif()
 
 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)  # https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
-  if(NOT CMAKE_TOOLCHAIN_FILE)
+  if(NOT CMAKE_CROSSCOMPILING)
     if(WIN32)
       set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory" FORCE)
     else()
@@ -513,10 +513,6 @@ OCV_OPTION(OPENCV_ENABLE_MEMORY_SANITIZER "Better support for memory/address san
```

Review comment:
Lets move out that from the root CMake file.
**File:** cmake/OpenCVCompilerOptimizations.cmake
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -104,7 +104,7 @@ ocv_optimization_process_obsolete_option(ENABLE_AVX2 AVX2 ON)
 ocv_optimization_process_obsolete_option(ENABLE_FMA3 FMA3 ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VFPV3 VFPV3 OFF)
-ocv_optimization_process_obsolete_option(ENABLE_NEON NEON OFF)
+ocv_optimization_process_obsolete_option(ENABLE_NEON NEON ON)
 
 ocv_optimization_process_obsolete_option(ENABLE_VSX VSX ON)
 
@@ -170,7 +170,29 @@ elseif(" ${CMAKE_CXX_FLAGS} " MATCHES " -march=native | -xHost | /QxHost ")
```

Review comment:
User can disable OpenCV intrinsics on affected platforms in two ways: * set `-DCPU_BASELINE=` - disable all intrinsics * set `-DCPU_BASELINE_DISABLE=RVV` - disable selected categories Example: ``` cmake \ -DRISCV_CLANG_BUILD_ROOT=/chains/llvm-main -DRISCV_GCC_INSTALL_ROOT=/chains/riscv-gcc-14.1.0 -DCMAKE_TOOLCHAIN_FILE=/opencv/platforms/linux/riscv64-clang.toolchain.cmake -DBUILD_SHARED_LIBS=OFF -DWITH_OPENCL=OFF \ -DENABLE_RVV=ON \ # choose RVV flags in the toolchain -DCPU_BASELINE= \ # disable all intrinsics -DBUILD_opencv_dnn=OFF \ # know issue -DCMAKE_BUILD_TYPE=Release \ ../opencv ``` CMake output: ``` ... -- CPU/HW features: -- Baseline: ... -- C++ flags (Release): -march=rv64gcv --gcc-toolchain=/chains/riscv-gcc-14.1.0 -w -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -pthread -Qunused-arguments -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG ... ``` Generated cv_cpu_config.h: ```.h // OpenCV CPU baseline features #define CV_CPU_BASELINE_FEATURES 0 \ // OpenCV supported CPU dispatched features #define CV_CPU_DISPATCH_FEATURES 0 \ ``` ------- If we don't change `CPU_BASELINE` (leave it `DETECT`), then OpenCV intrinsics will be enabled, cv_cpu_config.h: ``` // OpenCV CPU baseline features #define CV_CPU_COMPILE_RVV 1 #define CV_CPU_BASELINE_COMPILE_RVV 1 #define CV_CPU_BASELINE_FEATURES 0 \ , CV_CPU_RVV \ // OpenCV supported CPU dispatched features #define CV_CPU_DISPATCH_FEATURES 0 \ ```
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #25901: RISC-V/AArch64: disable CPU features detection - This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU...

**Code Changes:**
```diff
@@ -145,7 +145,7 @@ if(NOT OPENCV_SKIP_CMAKE_SYSTEM_FILE)
 endif()
 
 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)  # https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
-  if(NOT CMAKE_TOOLCHAIN_FILE)
+  if(NOT CMAKE_CROSSCOMPILING)
     if(WIN32)
       set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory" FORCE)
     else()
@@ -513,10 +513,6 @@ OCV_OPTION(OPENCV_ENABLE_MEMORY_SANITIZER "Better support for memory/address san
```

Review comment:
Moved to `cmake/platforms/OpenCV-Linux.cmake`