Grok  9.7.5
print-inl.h
Go to the documentation of this file.
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.
15 
16 // Print() function
17 
18 #include <inttypes.h>
19 #include <stdint.h>
20 
21 #include "hwy/base.h"
22 #include "hwy/tests/test_util.h"
23 
24 // Per-target include guard
25 #if defined(HIGHWAY_HWY_PRINT_INL_H_) == \
26  defined(HWY_TARGET_TOGGLE)
27 #ifdef HIGHWAY_HWY_PRINT_INL_H_
28 #undef HIGHWAY_HWY_PRINT_INL_H_
29 #else
30 #define HIGHWAY_HWY_PRINT_INL_H_
31 #endif
32 
34 namespace hwy {
35 namespace HWY_NAMESPACE {
36 
37 template <typename T, HWY_IF_LANE_SIZE(T, 1)>
38 HWY_NOINLINE void PrintValue(T value) {
39  uint8_t byte;
40  CopyBytes<1>(&value, &byte); // endian-safe: we ensured sizeof(T)=1.
41  fprintf(stderr, "0x%02X,", byte);
42 }
43 
44 #if HWY_HAVE_FLOAT16
45 HWY_NOINLINE void PrintValue(float16_t value) {
46  uint16_t bits;
47  CopyBytes<2>(&value, &bits);
48  fprintf(stderr, "0x%02X,", bits);
49 }
50 #endif
51 
52 template <typename T, HWY_IF_NOT_LANE_SIZE(T, 1)>
53 HWY_NOINLINE void PrintValue(T value) {
54  fprintf(stderr, "%g,", double(value));
55 }
56 
57 // Prints lanes around `lane`, in memory order.
58 template <class D, class V = Vec<D>>
59 void Print(const D d, const char* caption, VecArg<V> v, size_t lane_u = 0,
60  size_t max_lanes = 7) {
61  using T = TFromD<D>;
62  const size_t N = Lanes(d);
63  auto lanes = AllocateAligned<T>(N);
64  Store(v, d, lanes.get());
65 
66  const auto info = hwy::detail::MakeTypeInfo<T>();
67  hwy::detail::PrintArray(info, caption, lanes.get(), N, lane_u, max_lanes);
68 }
69 
70 // NOLINTNEXTLINE(google-readability-namespace-comments)
71 } // namespace HWY_NAMESPACE
72 } // namespace hwy
74 
75 #endif // per-target include guard
#define HWY_NOINLINE
Definition: base.h:65
d
Definition: rvv-inl.h:1656
V VecArg
Definition: ops/shared-inl.h:301
HWY_NOINLINE void PrintValue(T value)
Definition: print-inl.h:38
HWY_API size_t Lanes(Simd< T, N, kPow2 > d)
Definition: arm_sve-inl.h:218
void Print(const D d, const char *caption, VecArg< V > v, size_t lane_u=0, size_t max_lanes=7)
Definition: print-inl.h:59
N
Definition: rvv-inl.h:1656
HWY_API void Store(Vec128< T, N > v, Simd< T, N, 0 > d, T *HWY_RESTRICT aligned)
Definition: arm_neon-inl.h:2397
const vfloat64m1_t v
Definition: rvv-inl.h:1656
typename D::T TFromD
Definition: ops/shared-inl.h:192
HWY_DLLEXPORT void PrintArray(const TypeInfo &info, const char *caption, const void *array_void, size_t N, size_t lane_u=0, size_t max_lanes=7)
Definition: aligned_allocator.h:27
HWY_AFTER_NAMESPACE()
HWY_BEFORE_NAMESPACE()
#define HWY_NAMESPACE
Definition: set_macros-inl.h:80
Definition: base.h:248