1#[cfg(feature = "nightly")]
2use rustc_macros::HashStable_Generic;
3
4use crate::{Align, HasDataLayout, Size};
5
6#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
for RegKind where __CTX: crate::HashStableContext {
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
RegKind::Integer => {}
RegKind::Float => {}
RegKind::Vector => {}
}
}
}
};HashStable_Generic))]
7#[derive(#[automatically_derived]
impl ::core::marker::Copy for RegKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for RegKind {
#[inline]
fn clone(&self) -> RegKind { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for RegKind {
#[inline]
fn eq(&self, other: &RegKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for RegKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for RegKind {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for RegKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
RegKind::Integer => "Integer",
RegKind::Float => "Float",
RegKind::Vector => "Vector",
})
}
}Debug)]
8pub enum RegKind {
9 Integer,
10 Float,
11 Vector,
12}
13
14#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
for Reg where __CTX: crate::HashStableContext {
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
Reg { kind: ref __binding_0, size: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_Generic))]
15#[derive(#[automatically_derived]
impl ::core::marker::Copy for Reg { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Reg {
#[inline]
fn clone(&self) -> Reg {
let _: ::core::clone::AssertParamIsClone<RegKind>;
let _: ::core::clone::AssertParamIsClone<Size>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Reg {
#[inline]
fn eq(&self, other: &Reg) -> bool {
self.kind == other.kind && self.size == other.size
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Reg {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<RegKind>;
let _: ::core::cmp::AssertParamIsEq<Size>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Reg {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
::core::hash::Hash::hash(&self.kind, state);
::core::hash::Hash::hash(&self.size, state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for Reg {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "Reg", "kind",
&self.kind, "size", &&self.size)
}
}Debug)]
16pub struct Reg {
17 pub kind: RegKind,
18 pub size: Size,
19}
20
21macro_rules! reg_ctor {
22 ($name:ident, $kind:ident, $bits:expr) => {
23 pub fn $name() -> Reg {
24 Reg { kind: RegKind::$kind, size: Size::from_bits($bits) }
25 }
26 };
27}
28
29impl Reg {
30 Reg
Reg { kind: RegKind::Integer, size: Size::from_bits(8) };reg_ctor!(i8, Integer, 8);
31 Reg
Reg { kind: RegKind::Integer, size: Size::from_bits(16) };reg_ctor!(i16, Integer, 16);
32 Reg
Reg { kind: RegKind::Integer, size: Size::from_bits(32) };reg_ctor!(i32, Integer, 32);
33 Reg
Reg { kind: RegKind::Integer, size: Size::from_bits(64) };reg_ctor!(i64, Integer, 64);
34 Reg
Reg { kind: RegKind::Integer, size: Size::from_bits(128) };reg_ctor!(i128, Integer, 128);
35
36 Reg
Reg { kind: RegKind::Float, size: Size::from_bits(32) };reg_ctor!(f32, Float, 32);
37 Reg
Reg { kind: RegKind::Float, size: Size::from_bits(64) };reg_ctor!(f64, Float, 64);
38}
39
40impl Reg {
41 pub fn align<C: HasDataLayout>(&self, cx: &C) -> Align {
42 let dl = cx.data_layout();
43 match self.kind {
44 RegKind::Integer => match self.size.bits() {
45 1 => dl.i1_align,
46 2..=8 => dl.i8_align,
47 9..=16 => dl.i16_align,
48 17..=32 => dl.i32_align,
49 33..=64 => dl.i64_align,
50 65..=128 => dl.i128_align,
51 _ => {
::core::panicking::panic_fmt(format_args!("unsupported integer: {0:?}",
self));
}panic!("unsupported integer: {self:?}"),
52 },
53 RegKind::Float => match self.size.bits() {
54 16 => dl.f16_align,
55 32 => dl.f32_align,
56 64 => dl.f64_align,
57 128 => dl.f128_align,
58 _ => {
::core::panicking::panic_fmt(format_args!("unsupported float: {0:?}",
self));
}panic!("unsupported float: {self:?}"),
59 },
60 RegKind::Vector => dl.llvmlike_vector_align(self.size),
61 }
62 }
63}