]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/prefetch.rs
Adding support for the llvm `prefetch` intrinsic
[rust.git] / src / test / codegen / prefetch.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // compile-flags: -C no-prepopulate-passes
12
13 #![crate_type = "lib"]
14 #![feature(core_intrinsics)]
15
16 use std::intrinsics::{prefetch_read_data, prefetch_write_data,
17                       prefetch_read_instruction, prefetch_write_instruction};
18
19 #[no_mangle]
20 pub fn check_prefetch_read_data(data: &[i8]) {
21     unsafe {
22         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 0, i32 1)
23         prefetch_read_data(data.as_ptr(), 0);
24         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 1, i32 1)
25         prefetch_read_data(data.as_ptr(), 1);
26         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 2, i32 1)
27         prefetch_read_data(data.as_ptr(), 2);
28         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 1)
29         prefetch_read_data(data.as_ptr(), 3);
30     }
31 }
32
33 #[no_mangle]
34 pub fn check_prefetch_write_data(data: &[i8]) {
35     unsafe {
36         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 0, i32 1)
37         prefetch_write_data(data.as_ptr(), 0);
38         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 1, i32 1)
39         prefetch_write_data(data.as_ptr(), 1);
40         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 2, i32 1)
41         prefetch_write_data(data.as_ptr(), 2);
42         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 1)
43         prefetch_write_data(data.as_ptr(), 3);
44     }
45 }
46
47 #[no_mangle]
48 pub fn check_prefetch_read_instruction(data: &[i8]) {
49     unsafe {
50         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 0, i32 0)
51         prefetch_read_instruction(data.as_ptr(), 0);
52         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 1, i32 0)
53         prefetch_read_instruction(data.as_ptr(), 1);
54         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 2, i32 0)
55         prefetch_read_instruction(data.as_ptr(), 2);
56         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 0)
57         prefetch_read_instruction(data.as_ptr(), 3);
58     }
59 }
60
61 #[no_mangle]
62 pub fn check_prefetch_write_instruction(data: &[i8]) {
63     unsafe {
64         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 0, i32 0)
65         prefetch_write_instruction(data.as_ptr(), 0);
66         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 1, i32 0)
67         prefetch_write_instruction(data.as_ptr(), 1);
68         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 2, i32 0)
69         prefetch_write_instruction(data.as_ptr(), 2);
70         // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 0)
71         prefetch_write_instruction(data.as_ptr(), 3);
72     }
73 }
74
75