/src/test/codegen/prefetch.rs

https://gitlab.com/jianglu/rust · Rust · 73 lines · 40 code · 7 blank · 26 comment · 0 complexity · 7b72df8ed908de67e21cf436b9e5e788 MD5 · raw file

  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. // compile-flags: -C no-prepopulate-passes
  11. #![crate_type = "lib"]
  12. #![feature(core_intrinsics)]
  13. use std::intrinsics::{prefetch_read_data, prefetch_write_data,
  14. prefetch_read_instruction, prefetch_write_instruction};
  15. #[no_mangle]
  16. pub fn check_prefetch_read_data(data: &[i8]) {
  17. unsafe {
  18. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 0, i32 1)
  19. prefetch_read_data(data.as_ptr(), 0);
  20. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 1, i32 1)
  21. prefetch_read_data(data.as_ptr(), 1);
  22. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 2, i32 1)
  23. prefetch_read_data(data.as_ptr(), 2);
  24. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 1)
  25. prefetch_read_data(data.as_ptr(), 3);
  26. }
  27. }
  28. #[no_mangle]
  29. pub fn check_prefetch_write_data(data: &[i8]) {
  30. unsafe {
  31. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 0, i32 1)
  32. prefetch_write_data(data.as_ptr(), 0);
  33. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 1, i32 1)
  34. prefetch_write_data(data.as_ptr(), 1);
  35. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 2, i32 1)
  36. prefetch_write_data(data.as_ptr(), 2);
  37. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 1)
  38. prefetch_write_data(data.as_ptr(), 3);
  39. }
  40. }
  41. #[no_mangle]
  42. pub fn check_prefetch_read_instruction(data: &[i8]) {
  43. unsafe {
  44. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 0, i32 0)
  45. prefetch_read_instruction(data.as_ptr(), 0);
  46. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 1, i32 0)
  47. prefetch_read_instruction(data.as_ptr(), 1);
  48. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 2, i32 0)
  49. prefetch_read_instruction(data.as_ptr(), 2);
  50. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 0)
  51. prefetch_read_instruction(data.as_ptr(), 3);
  52. }
  53. }
  54. #[no_mangle]
  55. pub fn check_prefetch_write_instruction(data: &[i8]) {
  56. unsafe {
  57. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 0, i32 0)
  58. prefetch_write_instruction(data.as_ptr(), 0);
  59. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 1, i32 0)
  60. prefetch_write_instruction(data.as_ptr(), 1);
  61. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 2, i32 0)
  62. prefetch_write_instruction(data.as_ptr(), 2);
  63. // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 0)
  64. prefetch_write_instruction(data.as_ptr(), 3);
  65. }
  66. }