CCTLib
Calling-context and data-object attribution library for Intel Pin
loadspy_tn_simple.c
Go to the documentation of this file.
1 // True-negative victim for loadspy: an intervening store between the two
2 // loads invalidates redundancy tracking. Each pair does load-store-load.
3 #include <stdint.h>
4 
5 #define WORK_COUNT 100000
6 
7 static volatile uint64_t sink;
8 static uint64_t buf[WORK_COUNT]; // static: BSS, not stack
9 
10 __attribute__((noinline)) uint64_t load8(volatile uint64_t* p) { return *p; }
11 __attribute__((noinline)) void store8(volatile uint64_t* p, uint64_t v) { *p = v; }
12 
13 int main(int argc, char** argv) {
14  (void)argc; (void)argv;
15  for (int i = 0; i < WORK_COUNT; ++i) store8(&buf[i], (uint64_t)i);
16 
17  uint64_t s = 0;
18  for (int i = 0; i < WORK_COUNT; ++i) {
19  s += load8(&buf[i]);
20  store8(&buf[i], (uint64_t)(i * 3 + 1)); // intervening store: kills redundancy
21  s += load8(&buf[i]);
22  }
23 
24  sink = s;
25  return 0;
26 }
#define WORK_COUNT
int main(int argc, char **argv)
static uint64_t buf[WORK_COUNT]
__attribute__((noinline))
static volatile uint64_t sink