cpu_utils.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/base/cpu_utils.h"
  5. #include "base/cpu.h"
  6. #include "build/build_config.h"
  7. namespace remoting {
  8. namespace {
  9. // Supporting SSE3 is a requirement for Chromium on x86/x64 so that is our base
  10. // alignment. Both SSE3 (x86) and NEON (ARM) benefit from 16 byte alignment in
  11. // libyuv so make that the default. If the CPU supports AVX2, then we will use
  12. // that alignment instead. In the cases where AVX512 is used in libyuv, the
  13. // alignment requirements are the same as for AVX2.
  14. constexpr int kDefaultAlignmentBytes = 16;
  15. constexpr int kAvx2AlignmentBytes = 32;
  16. } // namespace
  17. bool IsCpuSupported() {
  18. #if defined(ARCH_CPU_X86_FAMILY)
  19. // x86 Chromium builds target SSE3.
  20. // See crbug.com/1251642 for more info.
  21. if (!base::CPU().has_sse3()) {
  22. return false;
  23. }
  24. #endif
  25. return true;
  26. }
  27. int GetSimdMemoryAlignment() {
  28. // We only need to calculate this once since the processor capabilities won't
  29. // change while the process is running.
  30. static const int alignment =
  31. base::CPU().has_avx2() ? kAvx2AlignmentBytes : kDefaultAlignmentBytes;
  32. return alignment;
  33. }
  34. } // namespace remoting