1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use llvmint;
use std::mem;
pub unsafe trait ReadWrite { const VALUE: i32; }
pub struct Read; unsafe impl ReadWrite for Read { const VALUE: i32 = 0; }
pub struct Write; unsafe impl ReadWrite for Write { const VALUE: i32 = 1; }
pub unsafe trait Locality { const VALUE: i32; }
pub struct None; unsafe impl Locality for None { const VALUE: i32 = 0; }
pub struct Low; unsafe impl Locality for Low { const VALUE: i32 = 1; }
pub struct Medium; unsafe impl Locality for Medium { const VALUE: i32 = 2; }
pub struct High; unsafe impl Locality for High { const VALUE: i32 = 3; }
pub unsafe trait CacheType { const VALUE: i32; }
pub struct Instruction; unsafe impl CacheType for Instruction { const VALUE: i32 = 0; }
pub struct Data; unsafe impl CacheType for Data { const VALUE: i32 = 1; }
#[inline(always)]
pub fn prefetch<RW: ReadWrite, Loc: Locality, Cache: CacheType, T>(x: *const T) {
unsafe { llvmint::prefetch(mem::transmute::<*const T, *mut i8>(x), RW::VALUE, Loc::VALUE, Cache::VALUE); }
}