CCTLib
Calling-context and data-object attribution library for Intel Pin
loadspy_tp_simple.c
Go to the documentation of this file.
1 // True-positive victim for loadspy: two consecutive loads from the same
2 // address with NO intervening store. The second load reads the SAME value
3 // that the first load produced -- redundant.
4 #include <stdint.h>
5 
6 #define WORK_COUNT 100000
7 
8 static volatile uint64_t sink;
9 static uint64_t buf[WORK_COUNT]; // static: BSS, not stack
10 
11 __attribute__((noinline)) uint64_t load8(volatile uint64_t* p) { return *p; }
12 __attribute__((noinline)) void store8(volatile uint64_t* p, uint64_t v) { *p = v; }
13 
14 int main(int argc, char** argv) {
15  (void)argc; (void)argv;
16  for (int i = 0; i < WORK_COUNT; ++i) store8(&buf[i], (uint64_t)i);
17 
18  uint64_t s = 0;
19  for (int i = 0; i < WORK_COUNT; ++i) {
20  s += load8(&buf[i]);
21  s += load8(&buf[i]); // redundant load: same value, no intervening store
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