• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
2 #[repr(C)]
3 #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
4 pub struct __BindgenBitfieldUnit<Storage> {
5     storage: Storage,
6 }
7 impl<Storage> __BindgenBitfieldUnit<Storage> {
8     #[inline]
new(storage: Storage) -> Self9     pub const fn new(storage: Storage) -> Self {
10         Self { storage }
11     }
12 }
13 impl<Storage> __BindgenBitfieldUnit<Storage>
14 where
15     Storage: AsRef<[u8]> + AsMut<[u8]>,
16 {
17     #[inline]
get_bit(&self, index: usize) -> bool18     pub fn get_bit(&self, index: usize) -> bool {
19         debug_assert!(index / 8 < self.storage.as_ref().len());
20         let byte_index = index / 8;
21         let byte = self.storage.as_ref()[byte_index];
22         let bit_index = if cfg!(target_endian = "big") {
23             7 - (index % 8)
24         } else {
25             index % 8
26         };
27         let mask = 1 << bit_index;
28         byte & mask == mask
29     }
30     #[inline]
set_bit(&mut self, index: usize, val: bool)31     pub fn set_bit(&mut self, index: usize, val: bool) {
32         debug_assert!(index / 8 < self.storage.as_ref().len());
33         let byte_index = index / 8;
34         let byte = &mut self.storage.as_mut()[byte_index];
35         let bit_index = if cfg!(target_endian = "big") {
36             7 - (index % 8)
37         } else {
38             index % 8
39         };
40         let mask = 1 << bit_index;
41         if val {
42             *byte |= mask;
43         } else {
44             *byte &= !mask;
45         }
46     }
47     #[inline]
get(&self, bit_offset: usize, bit_width: u8) -> u6448     pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
49         debug_assert!(bit_width <= 64);
50         debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
51         debug_assert!(
52             (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(),
53         );
54         let mut val = 0;
55         for i in 0..(bit_width as usize) {
56             if self.get_bit(i + bit_offset) {
57                 let index = if cfg!(target_endian = "big") {
58                     bit_width as usize - 1 - i
59                 } else {
60                     i
61                 };
62                 val |= 1 << index;
63             }
64         }
65         val
66     }
67     #[inline]
set(&mut self, bit_offset: usize, bit_width: u8, val: u64)68     pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
69         debug_assert!(bit_width <= 64);
70         debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
71         debug_assert!(
72             (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(),
73         );
74         for i in 0..(bit_width as usize) {
75             let mask = 1 << i;
76             let val_bit_is_set = val & mask == mask;
77             let index = if cfg!(target_endian = "big") {
78                 bit_width as usize - 1 - i
79             } else {
80                 i
81             };
82             self.set_bit(index + bit_offset, val_bit_is_set);
83         }
84     }
85 }
86 #[repr(C, packed(4))]
87 #[derive(Debug, Default, Copy, Clone)]
88 pub struct Test {
89     pub foo: u64,
90     pub _bitfield_align_1: [u64; 0],
91     pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>,
92 }
93 #[allow(clippy::unnecessary_operation, clippy::identity_op)]
94 const _: () = {
95     ["Size of Test"][::std::mem::size_of::<Test>() - 16usize];
96     ["Alignment of Test"][::std::mem::align_of::<Test>() - 4usize];
97     ["Offset of field: Test::foo"][::std::mem::offset_of!(Test, foo) - 0usize];
98 };
99 impl Test {
100     #[inline]
x(&self) -> u64101     pub fn x(&self) -> u64 {
102         unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 56u8) as u64) }
103     }
104     #[inline]
set_x(&mut self, val: u64)105     pub fn set_x(&mut self, val: u64) {
106         unsafe {
107             let val: u64 = ::std::mem::transmute(val);
108             self._bitfield_1.set(0usize, 56u8, val as u64)
109         }
110     }
111     #[inline]
y(&self) -> u64112     pub fn y(&self) -> u64 {
113         unsafe { ::std::mem::transmute(self._bitfield_1.get(56usize, 8u8) as u64) }
114     }
115     #[inline]
set_y(&mut self, val: u64)116     pub fn set_y(&mut self, val: u64) {
117         unsafe {
118             let val: u64 = ::std::mem::transmute(val);
119             self._bitfield_1.set(56usize, 8u8, val as u64)
120         }
121     }
122     #[inline]
new_bitfield_1(x: u64, y: u64) -> __BindgenBitfieldUnit<[u8; 8usize]>123     pub fn new_bitfield_1(x: u64, y: u64) -> __BindgenBitfieldUnit<[u8; 8usize]> {
124         let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default();
125         __bindgen_bitfield_unit
126             .set(
127                 0usize,
128                 56u8,
129                 {
130                     let x: u64 = unsafe { ::std::mem::transmute(x) };
131                     x as u64
132                 },
133             );
134         __bindgen_bitfield_unit
135             .set(
136                 56usize,
137                 8u8,
138                 {
139                     let y: u64 = unsafe { ::std::mem::transmute(y) };
140                     y as u64
141                 },
142             );
143         __bindgen_bitfield_unit
144     }
145 }
146