This is an archive of the discontinued LLVM Phabricator instance.

sanitizer_common: support printing __m128i type
ClosedPublic

Authored by dvyukov on May 10 2021, 6:37 AM.

Details

Summary

__m128i is vector SSE type used in tsan.
It's handy to be able to print it for debugging.

Diff Detail

Event Timeline

dvyukov requested review of this revision.May 10 2021, 6:37 AM
dvyukov created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2021, 6:37 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
dvyukov added inline comments.May 10 2021, 6:45 AM
compiler-rt/lib/sanitizer_common/sanitizer_printf.cpp
175–177

Humm... I run arc lint... the lines below are changed by it, I did not change them. And arc lint does not produce any more warnings/changes....

vitalybuka accepted this revision.May 11 2021, 7:49 PM
vitalybuka added inline comments.
compiler-rt/lib/sanitizer_common/tests/sanitizer_printf_test.cpp
165

this unusual format
if it's just few places maybe just continue to type printf("%lx%016lx", (u64)(n >> 64), (u64)n) ?

This revision is now accepted and ready to land.May 11 2021, 7:49 PM
dvyukov added inline comments.May 11 2021, 10:35 PM
compiler-rt/lib/sanitizer_common/tests/sanitizer_printf_test.cpp
165

It's not this simple because __m128i is not an integer, it's some implementation-defined type, may be a struct, may have some implementation-specific attributes.

We could do something along the lines of the following helpers:

u64 m128part(__m128i v, bool lo) {
  u64 x[2];
  internal_memcpy(&x, &v, sizeof(x));
  return lo ? x[0] : x[1];
}

#define M128FMT "%016llx%016llx"

And use them as:

Printf("value: " M128FMT "\n", m128part(v, true), m128part(v, false));

... but on second though this won't work as well because printing u64 will revert bytes (high byte goes first), this is generally confusing for a vector. It may contain 2 u64s, or 4 u32s, or 8 u16s, so there is even no common way to revert it back while reading the log.

Or we could add a helper function that prints a single value only:

void PrintVec(const char* prefix, __m128i v);

And then add DPrintVec/DPrintVec2 defines on top.

Currently I do:

DPrintf2("  MOP: shadow=%V access=%V\n", shadow, access);

Your call.

This revision was landed with ongoing or failed builds.Jul 12 2021, 7:13 AM
This revision was automatically updated to reflect the committed changes.