F14IntrinsicsAvailability.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2018-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <folly/Portability.h>
  18. // F14 has been implemented for SSE2 and NEON (so far).
  19. //
  20. // This platform detection is a bit of a mess because it combines the
  21. // detection of supported platforms (FOLLY_SSE >= 2 || FOLLY_NEON) with
  22. // the selection of platforms on which we want to use it.
  23. //
  24. // Currently no 32-bit ARM versions are desired because we don't want to
  25. // need a separate build for chips that don't have NEON. AARCH64 support
  26. // is enabled for non-mobile platforms, but on mobile platforms there
  27. // are downstream iteration order effects that have not yet been resolved.
  28. //
  29. // If FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE differs across compilation
  30. // units the program will fail to link due to a missing definition of
  31. // folly::container::detail::F14LinkCheck<X>::check() for some X.
  32. #if (FOLLY_SSE >= 2 || (FOLLY_NEON && FOLLY_AARCH64)) && !FOLLY_MOBILE
  33. #define FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE 1
  34. #else
  35. #define FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE 0
  36. #endif
  37. #if FOLLY_SSE_PREREQ(4, 2) || __ARM_FEATURE_CRC32
  38. #define FOLLY_F14_CRC_INTRINSIC_AVAILABLE 1
  39. #else
  40. #define FOLLY_F14_CRC_INTRINSIC_AVAILABLE 0
  41. #endif
  42. namespace folly {
  43. namespace f14 {
  44. namespace detail {
  45. enum class F14IntrinsicsMode { None, Simd, SimdAndCrc };
  46. static constexpr F14IntrinsicsMode getF14IntrinsicsMode() {
  47. #if !FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
  48. return F14IntrinsicsMode::None;
  49. #elif !FOLLY_F14_CRC_INTRINSIC_AVAILABLE
  50. return F14IntrinsicsMode::Simd;
  51. #else
  52. return F14IntrinsicsMode::SimdAndCrc;
  53. #endif
  54. }
  55. } // namespace detail
  56. } // namespace f14
  57. } // namespace folly