CCTLib
Calling-context and data-object attribution library for Intel Pin
loadspy_cross_page_tp.c
Go to the documentation of this file.
1
// Loadspy ISA edge case: cross-page redundant load. Qword load straddles
2
// two 4KB pages; back-to-back same loads should be counted as redundant
3
// by loadspy even across the page boundary.
4
#include <stdint.h>
5
#include <stddef.h>
6
#include <sys/mman.h>
7
#define WORK_COUNT 50000
8
static
volatile
uint64_t
sink
;
9
int
main
(
int
argc,
char
** argv) {
10
(void)argc; (void)argv;
11
const
size_t
pagesz = 4096;
12
void
* region = mmap(NULL, 2 * pagesz, PROT_READ | PROT_WRITE,
13
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
14
if
(region == MAP_FAILED)
return
1;
15
uint64_t* straddle = (uint64_t*)((
char
*)region + pagesz - 4);
16
*straddle = 0x1122334455667788ULL;
// seed with a known value
17
uint64_t acc = 0;
18
for
(
int
i = 0; i <
WORK_COUNT
; ++i) {
19
uint64_t v1, v2;
20
__asm__ __volatile__(
21
"movq (%[p]), %[v1]\n\t"
22
"movq (%[p]), %[v2]\n\t"
// redundant qword load, across page boundary
23
: [v1]
"=r"
(v1), [v2]
"=r"
(v2)
24
: [p]
"r"
(straddle)
25
:
"memory"
);
26
acc += v1 + v2;
27
}
28
sink
= acc;
29
munmap(region, 2 * pagesz);
30
return
0;
31
}
WORK_COUNT
#define WORK_COUNT
Definition:
loadspy_cross_page_tp.c:7
main
int main(int argc, char **argv)
Definition:
loadspy_cross_page_tp.c:9
sink
static volatile uint64_t sink
Definition:
loadspy_cross_page_tp.c:8
tests
gtest
apps
isa
loadspy_cross_page_tp.c
Generated on Wed Jul 15 2026 04:51:30 for CCTLib by
1.9.1