• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(
2     dead_code,
3     non_snake_case,
4     non_camel_case_types,
5     non_upper_case_globals
6 )]
7 
8 #[repr(C)]
9 #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
10 pub struct __BindgenBitfieldUnit<Storage> {
11     storage: Storage,
12 }
13 impl<Storage> __BindgenBitfieldUnit<Storage> {
14     #[inline]
new(storage: Storage) -> Self15     pub const fn new(storage: Storage) -> Self {
16         Self { storage }
17     }
18 }
19 impl<Storage> __BindgenBitfieldUnit<Storage>
20 where
21     Storage: AsRef<[u8]> + AsMut<[u8]>,
22 {
23     #[inline]
get_bit(&self, index: usize) -> bool24     pub fn get_bit(&self, index: usize) -> bool {
25         debug_assert!(index / 8 < self.storage.as_ref().len());
26         let byte_index = index / 8;
27         let byte = self.storage.as_ref()[byte_index];
28         let bit_index = if cfg!(target_endian = "big") {
29             7 - (index % 8)
30         } else {
31             index % 8
32         };
33         let mask = 1 << bit_index;
34         byte & mask == mask
35     }
36     #[inline]
set_bit(&mut self, index: usize, val: bool)37     pub fn set_bit(&mut self, index: usize, val: bool) {
38         debug_assert!(index / 8 < self.storage.as_ref().len());
39         let byte_index = index / 8;
40         let byte = &mut self.storage.as_mut()[byte_index];
41         let bit_index = if cfg!(target_endian = "big") {
42             7 - (index % 8)
43         } else {
44             index % 8
45         };
46         let mask = 1 << bit_index;
47         if val {
48             *byte |= mask;
49         } else {
50             *byte &= !mask;
51         }
52     }
53     #[inline]
get(&self, bit_offset: usize, bit_width: u8) -> u6454     pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
55         debug_assert!(bit_width <= 64);
56         debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
57         debug_assert!(
58             (bit_offset + (bit_width as usize)) / 8 <=
59                 self.storage.as_ref().len()
60         );
61         let mut val = 0;
62         for i in 0..(bit_width as usize) {
63             if self.get_bit(i + bit_offset) {
64                 let index = if cfg!(target_endian = "big") {
65                     bit_width as usize - 1 - i
66                 } else {
67                     i
68                 };
69                 val |= 1 << index;
70             }
71         }
72         val
73     }
74     #[inline]
set(&mut self, bit_offset: usize, bit_width: u8, val: u64)75     pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
76         debug_assert!(bit_width <= 64);
77         debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
78         debug_assert!(
79             (bit_offset + (bit_width as usize)) / 8 <=
80                 self.storage.as_ref().len()
81         );
82         for i in 0..(bit_width as usize) {
83             let mask = 1 << i;
84             let val_bit_is_set = val & mask == mask;
85             let index = if cfg!(target_endian = "big") {
86                 bit_width as usize - 1 - i
87             } else {
88                 i
89             };
90             self.set_bit(index + bit_offset, val_bit_is_set);
91         }
92     }
93 }
94 #[repr(C)]
95 #[repr(align(16))]
96 #[derive(Debug, Default, Copy, Clone)]
97 pub struct HasBigBitfield {
98     pub _bitfield_align_1: [u64; 0],
99     pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>,
100 }
101 #[test]
bindgen_test_layout_HasBigBitfield()102 fn bindgen_test_layout_HasBigBitfield() {
103     assert_eq!(
104         ::std::mem::size_of::<HasBigBitfield>(),
105         16usize,
106         concat!("Size of: ", stringify!(HasBigBitfield))
107     );
108     assert_eq!(
109         ::std::mem::align_of::<HasBigBitfield>(),
110         16usize,
111         concat!("Alignment of ", stringify!(HasBigBitfield))
112     );
113 }
114 impl HasBigBitfield {
115     #[inline]
x(&self) -> i128116     pub fn x(&self) -> i128 {
117         unsafe {
118             ::std::mem::transmute(self._bitfield_1.get(0usize, 128u8) as u128)
119         }
120     }
121     #[inline]
set_x(&mut self, val: i128)122     pub fn set_x(&mut self, val: i128) {
123         unsafe {
124             let val: u128 = ::std::mem::transmute(val);
125             self._bitfield_1.set(0usize, 128u8, val as u64)
126         }
127     }
128     #[inline]
new_bitfield_1(x: i128) -> __BindgenBitfieldUnit<[u8; 16usize]>129     pub fn new_bitfield_1(x: i128) -> __BindgenBitfieldUnit<[u8; 16usize]> {
130         let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> =
131             Default::default();
132         __bindgen_bitfield_unit.set(0usize, 128u8, {
133             let x: u128 = unsafe { ::std::mem::transmute(x) };
134             x as u64
135         });
136         __bindgen_bitfield_unit
137     }
138 }
139 #[repr(C)]
140 #[repr(align(16))]
141 #[derive(Debug, Default, Copy, Clone)]
142 pub struct HasTwoBigBitfields {
143     pub _bitfield_align_1: [u64; 0],
144     pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>,
145 }
146 #[test]
bindgen_test_layout_HasTwoBigBitfields()147 fn bindgen_test_layout_HasTwoBigBitfields() {
148     assert_eq!(
149         ::std::mem::size_of::<HasTwoBigBitfields>(),
150         16usize,
151         concat!("Size of: ", stringify!(HasTwoBigBitfields))
152     );
153     assert_eq!(
154         ::std::mem::align_of::<HasTwoBigBitfields>(),
155         16usize,
156         concat!("Alignment of ", stringify!(HasTwoBigBitfields))
157     );
158 }
159 impl HasTwoBigBitfields {
160     #[inline]
x(&self) -> i128161     pub fn x(&self) -> i128 {
162         unsafe {
163             ::std::mem::transmute(self._bitfield_1.get(0usize, 80u8) as u128)
164         }
165     }
166     #[inline]
set_x(&mut self, val: i128)167     pub fn set_x(&mut self, val: i128) {
168         unsafe {
169             let val: u128 = ::std::mem::transmute(val);
170             self._bitfield_1.set(0usize, 80u8, val as u64)
171         }
172     }
173     #[inline]
y(&self) -> i128174     pub fn y(&self) -> i128 {
175         unsafe {
176             ::std::mem::transmute(self._bitfield_1.get(80usize, 48u8) as u128)
177         }
178     }
179     #[inline]
set_y(&mut self, val: i128)180     pub fn set_y(&mut self, val: i128) {
181         unsafe {
182             let val: u128 = ::std::mem::transmute(val);
183             self._bitfield_1.set(80usize, 48u8, val as u64)
184         }
185     }
186     #[inline]
new_bitfield_1( x: i128, y: i128, ) -> __BindgenBitfieldUnit<[u8; 16usize]>187     pub fn new_bitfield_1(
188         x: i128,
189         y: i128,
190     ) -> __BindgenBitfieldUnit<[u8; 16usize]> {
191         let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> =
192             Default::default();
193         __bindgen_bitfield_unit.set(0usize, 80u8, {
194             let x: u128 = unsafe { ::std::mem::transmute(x) };
195             x as u64
196         });
197         __bindgen_bitfield_unit.set(80usize, 48u8, {
198             let y: u128 = unsafe { ::std::mem::transmute(y) };
199             y as u64
200         });
201         __bindgen_bitfield_unit
202     }
203 }
204