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 | |
17 | #pragma once |
18 | |
19 | #include <folly/Portability.h> |
20 | |
21 | // F14 has been implemented for SSE2 and NEON (so far). |
22 | // |
23 | // This platform detection is a bit of a mess because it combines the |
24 | // detection of supported platforms (FOLLY_SSE >= 2 || FOLLY_NEON) with |
25 | // the selection of platforms on which we want to use it. |
26 | // |
27 | // Currently no 32-bit ARM versions are desired because we don't want to |
28 | // need a separate build for chips that don't have NEON. AARCH64 support |
29 | // is enabled for non-mobile platforms, but on mobile platforms there |
30 | // are downstream iteration order effects that have not yet been resolved. |
31 | // |
32 | // If FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE differs across compilation |
33 | // units the program will fail to link due to a missing definition of |
34 | // folly::container::detail::F14LinkCheck<X>::check() for some X. |
35 | #if (FOLLY_SSE >= 2 || (FOLLY_NEON && FOLLY_AARCH64)) && !FOLLY_MOBILE |
36 | #define FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE 1 |
37 | #else |
38 | #define FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE 0 |
39 | #endif |
40 | |
41 | #if FOLLY_SSE_PREREQ(4, 2) || __ARM_FEATURE_CRC32 |
42 | #define FOLLY_F14_CRC_INTRINSIC_AVAILABLE 1 |
43 | #else |
44 | #define FOLLY_F14_CRC_INTRINSIC_AVAILABLE 0 |
45 | #endif |
46 | |
47 | namespace folly { |
48 | namespace f14 { |
49 | namespace detail { |
50 | |
51 | enum class F14IntrinsicsMode { None, Simd, SimdAndCrc }; |
52 | |
53 | static constexpr F14IntrinsicsMode getF14IntrinsicsMode() { |
54 | #if !FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE |
55 | return F14IntrinsicsMode::None; |
56 | #elif !FOLLY_F14_CRC_INTRINSIC_AVAILABLE |
57 | return F14IntrinsicsMode::Simd; |
58 | #else |
59 | return F14IntrinsicsMode::SimdAndCrc; |
60 | #endif |
61 | } |
62 | |
63 | } // namespace detail |
64 | } // namespace f14 |
65 | } // namespace folly |
66 | |