1 // Copyright 2022 Google LLC
2 // SPDX-License-Identifier: Apache-2.0
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
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_
26 #define HIGHWAY_HWY_PRINT_INL_H_
29 #if HWY_TARGET == HWY_RVV
30 #include "hwy/aligned_allocator.h"
33 HWY_BEFORE_NAMESPACE();
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
);
43 #if HWY_TARGET == HWY_RVV
44 auto storage
= AllocateAligned
<T
>(N
);
45 T
* HWY_RESTRICT lanes
= storage
.get();
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
)];
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
60 HWY_AFTER_NAMESPACE();
62 #endif // per-target include guard