|
| 1 | +/* automatically generated by rust-bindgen */ |
| 2 | + |
| 3 | +#![allow( |
| 4 | + dead_code, |
| 5 | + non_snake_case, |
| 6 | + non_camel_case_types, |
| 7 | + non_upper_case_globals |
| 8 | +)] |
| 9 | + |
| 10 | +#[repr(C)] |
| 11 | +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] |
| 12 | +pub struct __BindgenBitfieldUnit<Storage, Align> { |
| 13 | + storage: Storage, |
| 14 | + align: [Align; 0], |
| 15 | +} |
| 16 | +impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { |
| 17 | + #[inline] |
| 18 | + pub const fn new(storage: Storage) -> Self { |
| 19 | + Self { storage, align: [] } |
| 20 | + } |
| 21 | +} |
| 22 | +impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> |
| 23 | +where |
| 24 | + Storage: AsRef<[u8]> + AsMut<[u8]>, |
| 25 | +{ |
| 26 | + #[inline] |
| 27 | + pub fn get_bit(&self, index: usize) -> bool { |
| 28 | + debug_assert!(index / 8 < self.storage.as_ref().len()); |
| 29 | + let byte_index = index / 8; |
| 30 | + let byte = self.storage.as_ref()[byte_index]; |
| 31 | + let bit_index = if cfg!(target_endian = "big") { |
| 32 | + 7 - (index % 8) |
| 33 | + } else { |
| 34 | + index % 8 |
| 35 | + }; |
| 36 | + let mask = 1 << bit_index; |
| 37 | + byte & mask == mask |
| 38 | + } |
| 39 | + #[inline] |
| 40 | + pub fn set_bit(&mut self, index: usize, val: bool) { |
| 41 | + debug_assert!(index / 8 < self.storage.as_ref().len()); |
| 42 | + let byte_index = index / 8; |
| 43 | + let byte = &mut self.storage.as_mut()[byte_index]; |
| 44 | + let bit_index = if cfg!(target_endian = "big") { |
| 45 | + 7 - (index % 8) |
| 46 | + } else { |
| 47 | + index % 8 |
| 48 | + }; |
| 49 | + let mask = 1 << bit_index; |
| 50 | + if val { |
| 51 | + *byte |= mask; |
| 52 | + } else { |
| 53 | + *byte &= !mask; |
| 54 | + } |
| 55 | + } |
| 56 | + #[inline] |
| 57 | + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { |
| 58 | + debug_assert!(bit_width <= 64); |
| 59 | + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); |
| 60 | + debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); |
| 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] |
| 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!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); |
| 79 | + for i in 0..(bit_width as usize) { |
| 80 | + let mask = 1 << i; |
| 81 | + let val_bit_is_set = val & mask == mask; |
| 82 | + let index = if cfg!(target_endian = "big") { |
| 83 | + bit_width as usize - 1 - i |
| 84 | + } else { |
| 85 | + i |
| 86 | + }; |
| 87 | + self.set_bit(index + bit_offset, val_bit_is_set); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | +#[repr(C, packed(4))] |
| 92 | +#[repr(align(4))] |
| 93 | +#[derive(Debug, Default, Copy, Clone)] |
| 94 | +pub struct Test { |
| 95 | + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u64>, |
| 96 | +} |
| 97 | +#[test] |
| 98 | +fn bindgen_test_layout_Test() { |
| 99 | + assert_eq!( |
| 100 | + ::std::mem::size_of::<Test>(), |
| 101 | + 8usize, |
| 102 | + concat!("Size of: ", stringify!(Test)) |
| 103 | + ); |
| 104 | + assert_eq!( |
| 105 | + ::std::mem::align_of::<Test>(), |
| 106 | + 4usize, |
| 107 | + concat!("Alignment of ", stringify!(Test)) |
| 108 | + ); |
| 109 | +} |
| 110 | +impl Test { |
| 111 | + #[inline] |
| 112 | + pub fn x(&self) -> u64 { |
| 113 | + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 56u8) as u64) } |
| 114 | + } |
| 115 | + #[inline] |
| 116 | + pub fn set_x(&mut self, val: u64) { |
| 117 | + unsafe { |
| 118 | + let val: u64 = ::std::mem::transmute(val); |
| 119 | + self._bitfield_1.set(0usize, 56u8, val as u64) |
| 120 | + } |
| 121 | + } |
| 122 | + #[inline] |
| 123 | + pub fn y(&self) -> u64 { |
| 124 | + unsafe { ::std::mem::transmute(self._bitfield_1.get(56usize, 8u8) as u64) } |
| 125 | + } |
| 126 | + #[inline] |
| 127 | + pub fn set_y(&mut self, val: u64) { |
| 128 | + unsafe { |
| 129 | + let val: u64 = ::std::mem::transmute(val); |
| 130 | + self._bitfield_1.set(56usize, 8u8, val as u64) |
| 131 | + } |
| 132 | + } |
| 133 | + #[inline] |
| 134 | + pub fn new_bitfield_1(x: u64, y: u64) -> __BindgenBitfieldUnit<[u8; 8usize], u64> { |
| 135 | + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize], u64> = |
| 136 | + Default::default(); |
| 137 | + __bindgen_bitfield_unit.set(0usize, 56u8, { |
| 138 | + let x: u64 = unsafe { ::std::mem::transmute(x) }; |
| 139 | + x as u64 |
| 140 | + }); |
| 141 | + __bindgen_bitfield_unit.set(56usize, 8u8, { |
| 142 | + let y: u64 = unsafe { ::std::mem::transmute(y) }; |
| 143 | + y as u64 |
| 144 | + }); |
| 145 | + __bindgen_bitfield_unit |
| 146 | + } |
| 147 | +} |
0 commit comments