Skip to content

Commit

Permalink
Fix uses of __restrict__
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 599275577
Change-Id: I8885a9f153c8e6874efb00dfee9b862751fc73ae
  • Loading branch information
laramiel authored and copybara-github committed Jan 17, 2024
1 parent 00f80fc commit e5f0043
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions tensorstore/internal/nditerable_copy_benchmark_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@
#include "tensorstore/util/result.h"
#include "tensorstore/util/status.h"

#if defined(__clang__) || defined(__GNUC__)
#define TENSORSTORE_INTERNAL_RESTRICT __restrict__
#elif defined(_MSC_VER)
#define TENSORSTORE_INTERNAL_RESTRICT __restrict
#else
#define TENSORSTORE_INTERNAL_RESTRICT
#endif

namespace {

void DoCopyUnrolled(const uint8_t* __restrict__ src,
uint8_t* __restrict__ target, int64_t inner_size,
int64_t outer_size, ptrdiff_t src_outer_stride,
ptrdiff_t target_outer_stride) {
void DoCopyUnrolled(const uint8_t* TENSORSTORE_INTERNAL_RESTRICT src,
uint8_t* TENSORSTORE_INTERNAL_RESTRICT target,
int64_t inner_size, int64_t outer_size,
ptrdiff_t src_outer_stride, ptrdiff_t target_outer_stride) {
const auto do_outer_unroll = [&](auto outer_unroll_size) {
constexpr size_t kNumRows = decltype(outer_unroll_size)::value;
const uint8_t* src_rows[kNumRows];
Expand Down Expand Up @@ -84,9 +92,10 @@ void DoCopySimple(const uint8_t* src, uint8_t* target, int64_t inner_size,
}
}

void DoCopySimpleRestrict(const uint8_t* __restrict__ src,
uint8_t* __restrict__ target, int64_t inner_size,
int64_t outer_size, ptrdiff_t src_outer_stride,
void DoCopySimpleRestrict(const uint8_t* TENSORSTORE_INTERNAL_RESTRICT src,
uint8_t* TENSORSTORE_INTERNAL_RESTRICT target,
int64_t inner_size, int64_t outer_size,
ptrdiff_t src_outer_stride,
ptrdiff_t target_outer_stride) {
for (int64_t outer_i = 0; outer_i < outer_size; ++outer_i) {
for (int64_t inner_i = 0; inner_i < inner_size; ++inner_i) {
Expand All @@ -96,11 +105,11 @@ void DoCopySimpleRestrict(const uint8_t* __restrict__ src,
}
}

void DoCopySimpleRestrictNoBuiltin(const uint8_t* __restrict__ src,
uint8_t* __restrict__ target,
int64_t inner_size, int64_t outer_size,
ptrdiff_t src_outer_stride,
ptrdiff_t target_outer_stride)
void DoCopySimpleRestrictNoBuiltin(
const uint8_t* TENSORSTORE_INTERNAL_RESTRICT src,
uint8_t* TENSORSTORE_INTERNAL_RESTRICT target, int64_t inner_size,
int64_t outer_size, ptrdiff_t src_outer_stride,
ptrdiff_t target_outer_stride)
#if ABSL_HAVE_ATTRIBUTE(no_builtin)
__attribute__((no_builtin))
#endif
Expand Down

0 comments on commit e5f0043

Please sign in to comment.