Skip to content

Commit edcbb0a

Browse files
jan-wassenbergcopybara-github
authored andcommitted
Workaround for inttypes.h. Fixes #938
On some systems this requires a macro to be set. Where feasible, replace int-sized printf args with static_cast<int>. PiperOrigin-RevId: 469708467
1 parent 3b801c8 commit edcbb0a

18 files changed

+53
-51
lines changed

hwy/contrib/image/image.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
// SIMD/multicore-friendly planar image representation with row accessors.
2020

21-
#include <inttypes.h>
2221
#include <stddef.h>
2322
#include <stdint.h>
2423
#include <string.h>
@@ -104,7 +103,7 @@ struct HWY_CONTRIB_DLLEXPORT ImageBase {
104103
HWY_INLINE void* VoidRow(const size_t y) const {
105104
#if HWY_IS_ASAN || HWY_IS_MSAN || HWY_IS_TSAN
106105
if (y >= ysize_) {
107-
HWY_ABORT("Row(%" PRIu64 ") >= %u\n", static_cast<uint64_t>(y), ysize_);
106+
HWY_ABORT("Row(%d) >= %u\n", static_cast<int>(y), ysize_);
108107
}
109108
#endif
110109

@@ -223,14 +222,11 @@ class Image3 {
223222

224223
Image3(ImageT&& plane0, ImageT&& plane1, ImageT&& plane2) {
225224
if (!SameSize(plane0, plane1) || !SameSize(plane0, plane2)) {
226-
HWY_ABORT("Not same size: %" PRIu64 " x %" PRIu64 ", %" PRIu64
227-
" x %" PRIu64 ", %" PRIu64 " x %" PRIu64 "\n",
228-
static_cast<uint64_t>(plane0.xsize()),
229-
static_cast<uint64_t>(plane0.ysize()),
230-
static_cast<uint64_t>(plane1.xsize()),
231-
static_cast<uint64_t>(plane1.ysize()),
232-
static_cast<uint64_t>(plane2.xsize()),
233-
static_cast<uint64_t>(plane2.ysize()));
225+
HWY_ABORT(
226+
"Not same size: %d x %d, %d x %d, %d x %d\n",
227+
static_cast<int>(plane0.xsize()), static_cast<int>(plane0.ysize()),
228+
static_cast<int>(plane1.xsize()), static_cast<int>(plane1.ysize()),
229+
static_cast<int>(plane2.xsize()), static_cast<int>(plane2.ysize()));
234230
}
235231
planes_[0] = std::move(plane0);
236232
planes_[1] = std::move(plane1);
@@ -294,9 +290,8 @@ class Image3 {
294290
HWY_INLINE void* VoidPlaneRow(const size_t c, const size_t y) const {
295291
#if HWY_IS_ASAN || HWY_IS_MSAN || HWY_IS_TSAN
296292
if (c >= kNumPlanes || y >= ysize()) {
297-
HWY_ABORT("PlaneRow(%" PRIu64 ", %" PRIu64 ") >= %" PRIu64 "\n",
298-
static_cast<uint64_t>(c), static_cast<uint64_t>(y),
299-
static_cast<uint64_t>(ysize()));
293+
HWY_ABORT("PlaneRow(%d, %d) >= %d\n", static_cast<int>(c),
294+
static_cast<int>(y), static_cast<int>(ysize()));
300295
}
301296
#endif
302297
// Use the first plane's stride because the compiler might not realize they

hwy/contrib/math/math_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
#ifndef __STDC_FORMAT_MACROS
17+
#define __STDC_FORMAT_MACROS // before inttypes.h
18+
#endif
19+
#include <inttypes.h>
1620
#include <stdio.h>
1721

1822
#include <cfloat> // FLT_MAX

hwy/contrib/sort/sort_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
#ifndef __STDC_FORMAT_MACROS
17+
#define __STDC_FORMAT_MACROS // before inttypes.h
18+
#endif
19+
#include <inttypes.h>
1620
#include <stdint.h>
1721
#include <stdio.h>
1822
#include <string.h> // memcpy

hwy/examples/benchmark.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
#ifndef __STDC_FORMAT_MACROS
17+
#define __STDC_FORMAT_MACROS // before inttypes.h
18+
#endif
1619
#include <inttypes.h>
1720
#include <stddef.h>
1821
#include <stdint.h>

hwy/nanobenchmark.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#include "hwy/nanobenchmark.h"
1717

18+
#ifndef __STDC_FORMAT_MACROS
19+
#define __STDC_FORMAT_MACROS // before inttypes.h
20+
#endif
1821
#include <inttypes.h>
1922
#include <stddef.h>
2023
#include <stdio.h>

hwy/nanobenchmark_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#include "hwy/nanobenchmark.h"
1717

18+
#ifndef __STDC_FORMAT_MACROS
19+
#define __STDC_FORMAT_MACROS // before inttypes.h
20+
#endif
1821
#include <inttypes.h>
1922
#include <stdint.h>
2023
#include <stdio.h>

hwy/print.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#include "hwy/print.h"
1717

18+
#ifndef __STDC_FORMAT_MACROS
19+
#define __STDC_FORMAT_MACROS // before inttypes.h
20+
#endif
1821
#include <inttypes.h>
1922
#include <stddef.h>
2023
#include <stdio.h>

hwy/targets.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#include "hwy/targets.h"
1717

18+
#ifndef __STDC_FORMAT_MACROS
19+
#define __STDC_FORMAT_MACROS // before inttypes.h
20+
#endif
1821
#include <inttypes.h> // PRIx64
1922
#include <stdarg.h>
2023
#include <stddef.h>

hwy/tests/arithmetic_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#include <inttypes.h>
1716
#include <stddef.h>
1817
#include <stdint.h>
1918

hwy/tests/compress_test.cc

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#include <inttypes.h> // PRIu64
1716
#include <stddef.h>
1817
#include <stdint.h>
1918
#include <string.h> // memset
@@ -44,19 +43,16 @@ void CheckStored(D d, DI di, size_t expected_pos, size_t actual_pos,
4443
const AlignedFreeUniquePtr<T[]>& expected, const T* actual_u,
4544
int line) {
4645
if (expected_pos != actual_pos) {
47-
hwy::Abort(
48-
__FILE__, line,
49-
"Size mismatch for %s: expected %" PRIu64 ", actual %" PRIu64 "\n",
50-
TypeName(T(), Lanes(d)).c_str(), static_cast<uint64_t>(expected_pos),
51-
static_cast<uint64_t>(actual_pos));
46+
hwy::Abort(__FILE__, line, "Size mismatch for %s: expected %d, actual %d\n",
47+
TypeName(T(), Lanes(d)).c_str(), static_cast<int>(expected_pos),
48+
static_cast<int>(actual_pos));
5249
}
5350
// Modified from AssertVecEqual - we may not be checking all lanes.
5451
for (size_t i = 0; i < num_to_check; ++i) {
5552
if (!IsEqual(expected[i], actual_u[i])) {
5653
const size_t N = Lanes(d);
57-
fprintf(stderr, "Mismatch at i=%" PRIu64 " of %" PRIu64 ", line %d:\n\n",
58-
static_cast<uint64_t>(i), static_cast<uint64_t>(num_to_check),
59-
line);
54+
fprintf(stderr, "Mismatch at i=%d of %d, line %d:\n\n",
55+
static_cast<int>(i), static_cast<int>(num_to_check), line);
6056
Print(di, "mask", Load(di, mask_lanes.get()), 0, N);
6157
Print(d, "in", Load(d, in.get()), 0, N);
6258
Print(d, "expect", Load(d, expected.get()), 0, N);
@@ -598,8 +594,7 @@ void PrintCompress32x4Tables() {
598594

599595
for (size_t i = 0; i < N; ++i) {
600596
for (size_t idx_byte = 0; idx_byte < sizeof(T); ++idx_byte) {
601-
printf("%" PRIu64 ",",
602-
static_cast<uint64_t>(sizeof(T) * indices[i] + idx_byte));
597+
printf("%d,", static_cast<int>(sizeof(T) * indices[i] + idx_byte));
603598
}
604599
}
605600
}
@@ -630,8 +625,7 @@ void PrintCompressNot32x4Tables() {
630625

631626
for (size_t i = 0; i < N; ++i) {
632627
for (size_t idx_byte = 0; idx_byte < sizeof(T); ++idx_byte) {
633-
printf("%" PRIu64 ",",
634-
static_cast<uint64_t>(sizeof(T) * indices[i] + idx_byte));
628+
printf("%d,", static_cast<int>(sizeof(T) * indices[i] + idx_byte));
635629
}
636630
}
637631
}
@@ -662,8 +656,7 @@ void PrintCompress64x2Tables() {
662656

663657
for (size_t i = 0; i < N; ++i) {
664658
for (size_t idx_byte = 0; idx_byte < sizeof(T); ++idx_byte) {
665-
printf("%" PRIu64 ",",
666-
static_cast<uint64_t>(sizeof(T) * indices[i] + idx_byte));
659+
printf("%d,", static_cast<int>(sizeof(T) * indices[i] + idx_byte));
667660
}
668661
}
669662
}
@@ -694,8 +687,7 @@ void PrintCompressNot64x2Tables() {
694687

695688
for (size_t i = 0; i < N; ++i) {
696689
for (size_t idx_byte = 0; idx_byte < sizeof(T); ++idx_byte) {
697-
printf("%" PRIu64 ",",
698-
static_cast<uint64_t>(sizeof(T) * indices[i] + idx_byte));
690+
printf("%d,", static_cast<int>(sizeof(T) * indices[i] + idx_byte));
699691
}
700692
}
701693
}

0 commit comments

Comments
 (0)