Imported Upstream version 0.7.0
[platform/upstream/libjxl.git] / third_party / highway / hwy / contrib / sort / vqsort_kv128d.cc
1 // Copyright 2021 Google LLC
2 // SPDX-License-Identifier: Apache-2.0
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 #include "hwy/contrib/sort/vqsort.h"
17
18 #undef HWY_TARGET_INCLUDE
19 // clang-format off
20 // (avoid line break, which would prevent Copybara rules from matching)
21 #define HWY_TARGET_INCLUDE "hwy/contrib/sort/vqsort_kv128d.cc"  //NOLINT
22 // clang-format on
23 #include "hwy/foreach_target.h"  // IWYU pragma: keep
24
25 // After foreach_target
26 #include "hwy/contrib/sort/traits128-inl.h"
27 #include "hwy/contrib/sort/vqsort-inl.h"
28
29 HWY_BEFORE_NAMESPACE();
30 namespace hwy {
31 namespace HWY_NAMESPACE {
32
33 void SortKV128Desc(uint64_t* HWY_RESTRICT keys, size_t num,
34                    uint64_t* HWY_RESTRICT buf) {
35 #if VQSORT_ENABLED
36   SortTag<uint64_t> d;
37   detail::SharedTraits<detail::Traits128<detail::OrderDescendingKV128>> st;
38   Sort(d, st, keys, num, buf);
39 #else
40   (void) keys;
41   (void) num;
42   (void) buf;
43   HWY_ASSERT(0);
44 #endif
45 }
46
47 // NOLINTNEXTLINE(google-readability-namespace-comments)
48 }  // namespace HWY_NAMESPACE
49 }  // namespace hwy
50 HWY_AFTER_NAMESPACE();
51
52 #if HWY_ONCE
53 namespace hwy {
54 namespace {
55 HWY_EXPORT(SortKV128Desc);
56 }  // namespace
57
58 void Sorter::operator()(K64V64* HWY_RESTRICT keys, size_t n,
59                         SortDescending) const {
60   HWY_DYNAMIC_DISPATCH(SortKV128Desc)
61   (reinterpret_cast<uint64_t*>(keys), n * 2, Get<uint64_t>());
62 }
63
64 }  // namespace hwy
65 #endif  // HWY_ONCE