/src/librustc_platform_intrinsics/lib.rs

https://gitlab.com/alx741/rust · Rust · 111 lines · 86 code · 16 blank · 9 comment · 6 complexity · 79bbd31b1a718e33f3847f445fb1d32a MD5 · raw file

  1. // Copyright 2015 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. #![crate_name = "rustc_platform_intrinsics"]
  11. #![unstable(feature = "rustc_private", issue = "27812")]
  12. #![crate_type = "dylib"]
  13. #![crate_type = "rlib"]
  14. #![feature(staged_api)]
  15. #![cfg_attr(not(stage0), deny(warnings))]
  16. #![allow(bad_style)]
  17. pub struct Intrinsic {
  18. pub inputs: &'static [&'static Type],
  19. pub output: &'static Type,
  20. pub definition: IntrinsicDef,
  21. }
  22. #[derive(Clone, Hash, Eq, PartialEq)]
  23. pub enum Type {
  24. Void,
  25. Integer(/* signed */ bool, u8, /* llvm width */ u8),
  26. Float(u8),
  27. Pointer(&'static Type, Option<&'static Type>, /* const */ bool),
  28. Vector(&'static Type, Option<&'static Type>, u8),
  29. Aggregate(bool, &'static [&'static Type]),
  30. }
  31. pub enum IntrinsicDef {
  32. Named(&'static str),
  33. }
  34. static I8: Type = Type::Integer(true, 8, 8);
  35. static I16: Type = Type::Integer(true, 16, 16);
  36. static I32: Type = Type::Integer(true, 32, 32);
  37. static I64: Type = Type::Integer(true, 64, 64);
  38. static U8: Type = Type::Integer(false, 8, 8);
  39. static U16: Type = Type::Integer(false, 16, 16);
  40. static U32: Type = Type::Integer(false, 32, 32);
  41. static U64: Type = Type::Integer(false, 64, 64);
  42. static F32: Type = Type::Float(32);
  43. static F64: Type = Type::Float(64);
  44. static I32_8: Type = Type::Integer(true, 32, 8);
  45. static I8x8: Type = Type::Vector(&I8, None, 8);
  46. static U8x8: Type = Type::Vector(&U8, None, 8);
  47. static I8x16: Type = Type::Vector(&I8, None, 16);
  48. static U8x16: Type = Type::Vector(&U8, None, 16);
  49. static I8x32: Type = Type::Vector(&I8, None, 32);
  50. static U8x32: Type = Type::Vector(&U8, None, 32);
  51. static I16x4: Type = Type::Vector(&I16, None, 4);
  52. static U16x4: Type = Type::Vector(&U16, None, 4);
  53. static I16x8: Type = Type::Vector(&I16, None, 8);
  54. static U16x8: Type = Type::Vector(&U16, None, 8);
  55. static I16x16: Type = Type::Vector(&I16, None, 16);
  56. static U16x16: Type = Type::Vector(&U16, None, 16);
  57. static I32x2: Type = Type::Vector(&I32, None, 2);
  58. static U32x2: Type = Type::Vector(&U32, None, 2);
  59. static I32x4: Type = Type::Vector(&I32, None, 4);
  60. static U32x4: Type = Type::Vector(&U32, None, 4);
  61. static I32x8: Type = Type::Vector(&I32, None, 8);
  62. static U32x8: Type = Type::Vector(&U32, None, 8);
  63. static I64x1: Type = Type::Vector(&I64, None, 1);
  64. static U64x1: Type = Type::Vector(&U64, None, 1);
  65. static I64x2: Type = Type::Vector(&I64, None, 2);
  66. static U64x2: Type = Type::Vector(&U64, None, 2);
  67. static I64x4: Type = Type::Vector(&I64, None, 4);
  68. static U64x4: Type = Type::Vector(&U64, None, 4);
  69. static F32x2: Type = Type::Vector(&F32, None, 2);
  70. static F32x4: Type = Type::Vector(&F32, None, 4);
  71. static F32x8: Type = Type::Vector(&F32, None, 8);
  72. static F64x1: Type = Type::Vector(&F64, None, 1);
  73. static F64x2: Type = Type::Vector(&F64, None, 2);
  74. static F64x4: Type = Type::Vector(&F64, None, 4);
  75. static I32x4_F32: Type = Type::Vector(&I32, Some(&F32), 4);
  76. static I32x8_F32: Type = Type::Vector(&I32, Some(&F32), 8);
  77. static I64x2_F64: Type = Type::Vector(&I64, Some(&F64), 2);
  78. static I64x4_F64: Type = Type::Vector(&I64, Some(&F64), 4);
  79. static VOID: Type = Type::Void;
  80. mod x86;
  81. mod arm;
  82. mod aarch64;
  83. impl Intrinsic {
  84. pub fn find(name: &str) -> Option<Intrinsic> {
  85. if name.starts_with("x86_") {
  86. x86::find(name)
  87. } else if name.starts_with("arm_") {
  88. arm::find(name)
  89. } else if name.starts_with("aarch64_") {
  90. aarch64::find(name)
  91. } else {
  92. None
  93. }
  94. }
  95. }