CCTLib
Calling-context and data-object attribution library for Intel Pin
redspy_zero_fill_tp.c
Go to the documentation of this file.
1 // Redspy ISA edge case: SIMD zero-fill (common redundancy pattern in
2 // real-world code). pxor xmm, xmm zeroes an xmm register, then movdqu
3 // writes 16 zero bytes to memory. Doing this twice to the same address
4 // writes the SAME 16 zero bytes -> second is redundant.
5 //
6 // The common real-world pattern this reflects: initializing memory to
7 // zero by calling memset(buf, 0, N) then writing zeros again (defensive
8 // double-clear, or two callers along the same code path).
9 #include <stdint.h>
10 #define WORK_COUNT 10000
11 static volatile uint64_t sink;
12 static uint64_t buf[2] __attribute__((aligned(16)));
13 int main(int argc, char** argv) {
14  (void)argc; (void)argv;
15  for (int i = 0; i < WORK_COUNT; ++i) {
16  __asm__ __volatile__(
17  "pxor %%xmm0, %%xmm0\n\t" // xmm0 = 0
18  "movdqu %%xmm0, (%[p])\n\t" // 16B zero write
19  "movdqu %%xmm0, (%[p])\n\t" // 16B zero write again -- redundant
20  :
21  : [p] "r"(buf)
22  : "memory", "xmm0");
23  }
24  sink = buf[0];
25  return 0;
26 }
static uint64_t buf[ITERS]
#define WORK_COUNT
int main(int argc, char **argv)
static volatile uint64_t sink
static uint64_t buf[2] __attribute__((aligned(16)))