CCTLib
Calling-context and data-object attribution library for Intel Pin
deadspy_tn_simple.c
Go to the documentation of this file.
1 // True-negative victim: same total number of stores, but each pair of
2 // writes to a cell has an intervening READ, so neither write is dead.
3 //
4 // Anti-optimization measures match the TP program so the two are directly
5 // comparable.
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 
10 #define WORK_COUNT 10000
11 
12 static volatile uint64_t sink;
13 
14 __attribute__((noinline)) void store8(volatile uint64_t* p, uint64_t v) {
15  *p = v;
16 }
17 __attribute__((noinline)) uint64_t load8(volatile uint64_t* p) {
18  return *p;
19 }
20 
21 int main(int argc, char** argv) {
22  (void)argc; (void)argv;
23  uint64_t buf[WORK_COUNT];
24  for (int i = 0; i < WORK_COUNT; ++i) buf[i] = 0xAAULL;
25 
26  uint64_t s = 0;
27  for (int i = 0; i < WORK_COUNT; ++i) {
28  store8(&buf[i], 1);
29  s += load8(&buf[i]); // reads buf[i], so the previous write is USED, not dead
30  store8(&buf[i], 2);
31  s += load8(&buf[i]); // ditto
32  }
33 
34  sink = s;
35  return 0;
36 }
#define WORK_COUNT
int main(int argc, char **argv)
__attribute__((noinline))
static volatile uint64_t sink
static uint64_t buf[ITERS]