Bug 1913543 - Apply the final upstream fix instead of our crude workaround. r=firefox...
[gecko.git] / third_party / highway / hwy / print-inl.h
blob46881a29da9e27111675ba534cc043975c925f74
1 // Copyright 2022 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.
16 // Print() function
18 #include "hwy/highway.h"
19 #include "hwy/print.h"
21 // Per-target include guard
22 #if defined(HIGHWAY_HWY_PRINT_INL_H_) == defined(HWY_TARGET_TOGGLE)
23 #ifdef HIGHWAY_HWY_PRINT_INL_H_
24 #undef HIGHWAY_HWY_PRINT_INL_H_
25 #else
26 #define HIGHWAY_HWY_PRINT_INL_H_
27 #endif
29 #if HWY_TARGET == HWY_RVV
30 #include "hwy/aligned_allocator.h"
31 #endif
33 HWY_BEFORE_NAMESPACE();
34 namespace hwy {
35 namespace HWY_NAMESPACE {
37 // Prints lanes around `lane`, in memory order.
38 template <class D, class V = VFromD<D>>
39 HWY_API void Print(const D d, const char* caption, V v, size_t lane_u = 0,
40 size_t max_lanes = 7) {
41 const size_t N = Lanes(d);
42 using T = TFromD<D>;
43 #if HWY_TARGET == HWY_RVV
44 auto storage = AllocateAligned<T>(N);
45 T* HWY_RESTRICT lanes = storage.get();
46 #else
47 // This works around an SVE compile error on GCC 11 and 12. Calling
48 // AllocateAligned here would seem to require it be marked with HWY_ATTR.
49 HWY_ALIGN T lanes[MaxLanes(d)];
50 #endif
51 Store(v, d, lanes);
53 const auto info = hwy::detail::MakeTypeInfo<T>();
54 hwy::detail::PrintArray(info, caption, lanes, N, lane_u, max_lanes);
57 // NOLINTNEXTLINE(google-readability-namespace-comments)
58 } // namespace HWY_NAMESPACE
59 } // namespace hwy
60 HWY_AFTER_NAMESPACE();
62 #endif // per-target include guard