CCTLib
Calling-context and data-object attribution library for Intel Pin
ins_reuse_tight_loop.c
Go to the documentation of this file.
1
// Instruction-reuse victim: a tight 4-instruction inline-asm loop. Every
2
// instruction inside the loop is re-executed after exactly 4 instructions
3
// (mov / add / cmp / jl), so the ins_reuse histogram should be strongly
4
// peaked around the bin covering distance ~4 (bin index 3, which covers
5
// [4,8)).
6
//
7
// N=1e6 iterations gives a substantial signal above libc-startup noise.
8
#include <stdint.h>
9
10
static
volatile
uint64_t
sink
;
11
12
int
main
(
int
argc,
char
** argv) {
13
(void)argc; (void)argv;
14
uint64_t acc = 0;
15
uint64_t n = 1000000;
16
// Force a real tight loop in the emitted code. The `.p2align 4` keeps
17
// the loop entry cache-line-aligned so timing/instrumentation is
18
// reproducible.
19
__asm__ __volatile__ (
20
"movq $0, %[a]\n\t"
21
".p2align 4\n"
22
"1:\n\t"
23
"addq $1, %[a]\n\t"
24
"subq $1, %[n]\n\t"
25
"jnz 1b\n\t"
26
: [
a
]
"+r"
(acc), [n]
"+r"
(n)
27
:
28
:
"cc"
29
);
30
sink
= acc;
31
return
0;
32
}
main
int main(int argc, char **argv)
Definition:
ins_reuse_tight_loop.c:12
sink
static volatile uint64_t sink
Definition:
ins_reuse_tight_loop.c:10
a
int a[1000]
Definition:
testArray.c:5
tests
gtest
apps
ins_reuse_tight_loop.c
Generated on Wed Jul 15 2026 04:51:30 for CCTLib by
1.9.1