/src/test/assembly/asm/bpf-types.rs

https://gitlab.com/rust-lang/rust · Rust · 154 lines · 67 code · 23 blank · 64 comment · 5 complexity · 52abb0f690098105635c9c440234b863 MD5 · raw file

  1. // min-llvm-version: 13.0
  2. // assembly-output: emit-asm
  3. // compile-flags: --target bpfel-unknown-none -C target_feature=+alu32
  4. // needs-llvm-components: bpf
  5. #![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
  6. #![crate_type = "rlib"]
  7. #![no_core]
  8. #![allow(asm_sub_register, non_camel_case_types)]
  9. #[rustc_builtin_macro]
  10. macro_rules! asm {
  11. () => {};
  12. }
  13. #[rustc_builtin_macro]
  14. macro_rules! concat {
  15. () => {};
  16. }
  17. #[rustc_builtin_macro]
  18. macro_rules! stringify {
  19. () => {};
  20. }
  21. #[lang = "sized"]
  22. trait Sized {}
  23. #[lang = "copy"]
  24. trait Copy {}
  25. type ptr = *const u64;
  26. impl Copy for i8 {}
  27. impl Copy for i16 {}
  28. impl Copy for i32 {}
  29. impl Copy for i64 {}
  30. impl Copy for ptr {}
  31. macro_rules! check {
  32. ($func:ident $ty:ident $class:ident) => {
  33. #[no_mangle]
  34. pub unsafe fn $func(x: $ty) -> $ty {
  35. let y;
  36. asm!("{} = {}", out($class) y, in($class) x);
  37. y
  38. }
  39. };
  40. }
  41. macro_rules! check_reg {
  42. ($func:ident $ty:ident $reg:tt) => {
  43. #[no_mangle]
  44. pub unsafe fn $func(x: $ty) -> $ty {
  45. let y;
  46. asm!(concat!($reg, " = ", $reg), lateout($reg) y, in($reg) x);
  47. y
  48. }
  49. };
  50. }
  51. extern "C" {
  52. fn extern_func();
  53. }
  54. // CHECK-LABEL: sym_fn
  55. // CHECK: #APP
  56. // CHECK: call extern_func
  57. // CHECK: #NO_APP
  58. #[no_mangle]
  59. pub unsafe fn sym_fn() {
  60. asm!("call {}", sym extern_func);
  61. }
  62. // CHECK-LABEL: reg_i8:
  63. // CHECK: #APP
  64. // CHECK: r{{[0-9]+}} = r{{[0-9]+}}
  65. // CHECK: #NO_APP
  66. check!(reg_i8 i8 reg);
  67. // CHECK-LABEL: reg_i16:
  68. // CHECK: #APP
  69. // CHECK: r{{[0-9]+}} = r{{[0-9]+}}
  70. // CHECK: #NO_APP
  71. check!(reg_i16 i16 reg);
  72. // CHECK-LABEL: reg_i32:
  73. // CHECK: #APP
  74. // CHECK: r{{[0-9]+}} = r{{[0-9]+}}
  75. // CHECK: #NO_APP
  76. check!(reg_i32 i32 reg);
  77. // CHECK-LABEL: reg_i64:
  78. // CHECK: #APP
  79. // CHECK: r{{[0-9]+}} = r{{[0-9]+}}
  80. // CHECK: #NO_APP
  81. check!(reg_i64 i64 reg);
  82. // CHECK-LABEL: wreg_i8:
  83. // CHECK: #APP
  84. // CHECK: w{{[0-9]+}} = w{{[0-9]+}}
  85. // CHECK: #NO_APP
  86. check!(wreg_i8 i8 wreg);
  87. // CHECK-LABEL: wreg_i16:
  88. // CHECK: #APP
  89. // CHECK: w{{[0-9]+}} = w{{[0-9]+}}
  90. // CHECK: #NO_APP
  91. check!(wreg_i16 i16 wreg);
  92. // CHECK-LABEL: wreg_i32:
  93. // CHECK: #APP
  94. // CHECK: w{{[0-9]+}} = w{{[0-9]+}}
  95. // CHECK: #NO_APP
  96. check!(wreg_i32 i32 wreg);
  97. // CHECK-LABEL: r0_i8:
  98. // CHECK: #APP
  99. // CHECK: r0 = r0
  100. // CHECK: #NO_APP
  101. check_reg!(r0_i8 i8 "r0");
  102. // CHECK-LABEL: r0_i16:
  103. // CHECK: #APP
  104. // CHECK: r0 = r0
  105. // CHECK: #NO_APP
  106. check_reg!(r0_i16 i16 "r0");
  107. // CHECK-LABEL: r0_i32:
  108. // CHECK: #APP
  109. // CHECK: r0 = r0
  110. // CHECK: #NO_APP
  111. check_reg!(r0_i32 i32 "r0");
  112. // CHECK-LABEL: r0_i64:
  113. // CHECK: #APP
  114. // CHECK: r0 = r0
  115. // CHECK: #NO_APP
  116. check_reg!(r0_i64 i64 "r0");
  117. // CHECK-LABEL: w0_i8:
  118. // CHECK: #APP
  119. // CHECK: w0 = w0
  120. // CHECK: #NO_APP
  121. check_reg!(w0_i8 i8 "w0");
  122. // CHECK-LABEL: w0_i16:
  123. // CHECK: #APP
  124. // CHECK: w0 = w0
  125. // CHECK: #NO_APP
  126. check_reg!(w0_i16 i16 "w0");
  127. // CHECK-LABEL: w0_i32:
  128. // CHECK: #APP
  129. // CHECK: w0 = w0
  130. // CHECK: #NO_APP
  131. check_reg!(w0_i32 i32 "w0");