print-inl.h 1.9 KB

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