Coverage Report

Created: 2025-07-12 06:37

/rust/registry/src/index.crates.io-6f17d22bba15001f/bitvec-1.0.1/src/field.rs
Line
Count
Source (jump to first uncovered line)
1
#![doc = include_str!("../doc/field.md")]
2
3
use core::{
4
  mem,
5
  ptr,
6
};
7
8
use funty::Integral;
9
use tap::Pipe;
10
use wyz::comu::{
11
  Const,
12
  Mut,
13
};
14
15
use crate::{
16
  array::BitArray,
17
  devel as dvl,
18
  domain::{
19
    Domain,
20
    PartialElement,
21
  },
22
  mem::bits_of,
23
  order::{
24
    BitOrder,
25
    Lsb0,
26
    Msb0,
27
  },
28
  slice::BitSlice,
29
  store::BitStore,
30
  view::BitViewSized,
31
};
32
#[cfg(feature = "alloc")]
33
use crate::{
34
  boxed::BitBox,
35
  vec::BitVec,
36
};
37
38
mod io;
39
mod tests;
40
41
#[doc = include_str!("../doc/field/BitField.md")]
42
pub trait BitField {
43
  #[inline]
44
  #[cfg(not(tarpaulin_include))]
45
  #[doc = include_str!("../doc/field/BitField_load.md")]
46
0
  fn load<I>(&self) -> I
47
0
  where I: Integral {
48
0
    if cfg!(target_endian = "little") {
49
0
      self.load_le::<I>()
50
    }
51
0
    else if cfg!(target_endian = "big") {
52
0
      self.load_be::<I>()
53
    }
54
    else {
55
0
      match option_env!("CARGO_PKG_REPOSITORY") {
56
0
        Some(env) => unreachable!(
57
0
          "This architecture is not supported! Please consider \
58
0
           filing an issue at {}",
59
0
          env
60
0
        ),
61
0
        None => unreachable!(
62
0
          "This architecture is not supported! Please consider \
63
0
           filing an issue"
64
0
        ),
65
      }
66
    }
67
0
  }
68
69
  #[inline]
70
  #[cfg(not(tarpaulin_include))]
71
  #[doc = include_str!("../doc/field/BitField_store.md")]
72
0
  fn store<I>(&mut self, value: I)
73
0
  where I: Integral {
74
0
    if cfg!(target_endian = "little") {
75
0
      self.store_le::<I>(value);
76
0
    }
77
0
    else if cfg!(target_endian = "big") {
78
0
      self.store_be::<I>(value);
79
0
    }
80
    else {
81
0
      match option_env!("CARGO_PKG_REPOSITORY") {
82
0
        Some(env) => unreachable!(
83
0
          "This architecture is not supported! Please consider \
84
0
           filing an issue at {}",
85
0
          env
86
0
        ),
87
0
        None => unreachable!(
88
0
          "This architecture is not supported! Please consider \
89
0
           filing an issue"
90
0
        ),
91
      }
92
    }
93
0
  }
94
95
  #[doc = include_str!("../doc/field/BitField_load_le.md")]
96
  fn load_le<I>(&self) -> I
97
  where I: Integral;
98
99
  #[doc = include_str!("../doc/field/BitField_load_be.md")]
100
  fn load_be<I>(&self) -> I
101
  where I: Integral;
102
103
  #[doc = include_str!("../doc/field/BitField_store_le.md")]
104
  fn store_le<I>(&mut self, value: I)
105
  where I: Integral;
106
107
  #[doc = include_str!("../doc/field/BitField_store_be.md")]
108
  fn store_be<I>(&mut self, value: I)
109
  where I: Integral;
110
}
111
112
#[doc = include_str!("../doc/field/BitField_Lsb0.md")]
113
impl<T> BitField for BitSlice<T, Lsb0>
114
where T: BitStore
115
{
116
  #[inline]
117
  #[doc = include_str!("../doc/field/BitField_Lsb0_load_le.md")]
118
0
  fn load_le<I>(&self) -> I
119
0
  where I: Integral {
120
0
    let len = self.len();
121
0
    check::<I>("load", len);
122
0
123
0
    match self.domain() {
124
      //  In Lsb0, the head counts distance from LSedge to first live bit.
125
0
      Domain::Enclave(elem) => get(elem, elem.head().into_inner()),
126
0
      Domain::Region { head, body, tail } => {
127
0
        let mut accum = I::ZERO;
128
129
0
        if let Some(elem) = tail {
130
0
          accum = get(elem, 0);
131
0
        }
132
133
0
        for elem in body.iter().rev().map(BitStore::load_value) {
134
0
          maybe_shift_left(&mut accum, bits_of::<T>());
135
0
          accum |= resize::<T::Mem, I>(elem);
136
0
        }
137
138
0
        if let Some(elem) = head {
139
0
          let shamt = elem.head().into_inner();
140
0
          maybe_shift_left(
141
0
            &mut accum,
142
0
            bits_of::<T>() - shamt as usize,
143
0
          );
144
0
          accum |= get::<_, _, I>(elem, shamt);
145
0
        }
146
147
0
        accum
148
      },
149
    }
150
0
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<u8> as bitvec::field::BitField>::load_le::<usize>::{closure#0}
Unexecuted instantiation: <bitvec::slice::BitSlice<_> as bitvec::field::BitField>::load_le::<_>::{closure#0}
151
0
  }
Unexecuted instantiation: <bitvec::slice::BitSlice<u8> as bitvec::field::BitField>::load_le::<usize>
Unexecuted instantiation: <bitvec::slice::BitSlice<_> as bitvec::field::BitField>::load_le::<_>
152
153
  #[inline]
154
  #[doc = include_str!("../doc/field/BitField_Lsb0_load_be.md")]
155
0
  fn load_be<I>(&self) -> I
156
0
  where I: Integral {
157
0
    let len = self.len();
158
0
    check::<I>("load", len);
159
0
160
0
    match self.domain() {
161
0
      Domain::Enclave(elem) => get(elem, elem.head().into_inner()),
162
0
      Domain::Region { head, body, tail } => {
163
0
        let mut accum = I::ZERO;
164
165
0
        if let Some(elem) = head {
166
0
          accum = get(elem, elem.head().into_inner());
167
0
        }
168
169
0
        for elem in body.iter().map(BitStore::load_value) {
170
0
          maybe_shift_left(&mut accum, bits_of::<T>());
171
0
          accum |= resize::<T::Mem, I>(elem);
172
0
        }
173
174
0
        if let Some(elem) = tail {
175
0
          let shamt = elem.tail().into_inner() as usize;
176
0
          maybe_shift_left(&mut accum, shamt);
177
0
          accum |= get::<_, _, I>(elem, 0);
178
0
        }
179
180
0
        accum
181
      },
182
    }
183
0
    .pipe(|elem| sign(elem, len))
184
0
  }
185
186
  #[inline]
187
  #[doc = include_str!("../doc/field/BitField_Lsb0_store_le.md")]
188
0
  fn store_le<I>(&mut self, mut value: I)
189
0
  where I: Integral {
190
0
    check::<I>("store", self.len());
191
0
192
0
    match self.domain_mut() {
193
0
      Domain::Enclave(elem) => {
194
0
        let shamt = elem.head().into_inner();
195
0
        set(elem, value, shamt);
196
0
      },
197
0
      Domain::Region { head, body, tail } => {
198
0
        if let Some(elem) = head {
199
0
          let shamt = elem.head().into_inner();
200
0
          set(elem, value, shamt);
201
0
          let rshamt = bits_of::<T>() - shamt as usize;
202
0
          maybe_shift_right(&mut value, rshamt);
203
0
        }
204
205
0
        for elem in body.iter_mut() {
206
0
          elem.store_value(resize(value));
207
0
          maybe_shift_right(&mut value, bits_of::<T>());
208
0
        }
209
210
0
        if let Some(elem) = tail {
211
0
          set(elem, value, 0);
212
0
        }
213
      },
214
    }
215
0
  }
Unexecuted instantiation: <bitvec::slice::BitSlice<u8> as bitvec::field::BitField>::store_le::<usize>
Unexecuted instantiation: <bitvec::slice::BitSlice<_> as bitvec::field::BitField>::store_le::<_>
216
217
  #[inline]
218
  #[doc = include_str!("../doc/field/BitField_Lsb0_store_be.md")]
219
0
  fn store_be<I>(&mut self, mut value: I)
220
0
  where I: Integral {
221
0
    check::<I>("store", self.len());
222
0
223
0
    match self.domain_mut() {
224
0
      Domain::Enclave(elem) => {
225
0
        let shamt = elem.head().into_inner();
226
0
        set(elem, value, shamt);
227
0
      },
228
0
      Domain::Region { head, body, tail } => {
229
0
        if let Some(elem) = tail {
230
0
          let shamt = elem.tail().into_inner() as usize;
231
0
          set(elem, value, 0);
232
0
          maybe_shift_right(&mut value, shamt);
233
0
        }
234
235
0
        for elem in body.iter_mut().rev() {
236
0
          elem.store_value(resize(value));
237
0
          maybe_shift_right(&mut value, bits_of::<T>());
238
0
        }
239
240
0
        if let Some(elem) = head {
241
0
          let shamt = elem.head().into_inner();
242
0
          set(elem, value, shamt);
243
0
        }
244
      },
245
    }
246
0
  }
247
}
248
249
#[doc = include_str!("../doc/field/BitField_Msb0.md")]
250
impl<T> BitField for BitSlice<T, Msb0>
251
where T: BitStore
252
{
253
  #[inline]
254
  #[doc = include_str!("../doc/field/BitField_Msb0_load_le.md")]
255
2.46k
  fn load_le<I>(&self) -> I
256
2.46k
  where I: Integral {
257
2.46k
    let len = self.len();
258
2.46k
    check::<I>("load", len);
259
2.46k
260
2.46k
    match self.domain() {
261
0
      Domain::Enclave(elem) => {
262
0
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
263
0
        get(elem, shamt)
264
      },
265
2.46k
      Domain::Region { head, body, tail } => {
266
2.46k
        let mut accum = I::ZERO;
267
268
2.46k
        if let Some(elem) = tail {
269
0
          let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
270
0
          accum = get(elem, shamt);
271
2.46k
        }
272
273
39.3k
        for elem in body.iter().rev().map(BitStore::load_value) {
274
39.3k
          maybe_shift_left(&mut accum, bits_of::<T>());
275
39.3k
          accum |= resize::<T::Mem, I>(elem);
276
39.3k
        }
277
278
2.46k
        if let Some(elem) = head {
279
0
          let shamt =
280
0
            bits_of::<T>() - elem.head().into_inner() as usize;
281
0
          maybe_shift_left(&mut accum, shamt);
282
0
          accum |= get::<_, _, I>(elem, 0);
283
2.46k
        }
284
285
2.46k
        accum
286
      },
287
    }
288
2.46k
    .pipe(|elem| sign(elem, len))
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<u128>::{closure#0}
Line
Count
Source
288
2.46k
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<_>::{closure#0}
289
2.46k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<u128>
Line
Count
Source
255
2.46k
  fn load_le<I>(&self) -> I
256
2.46k
  where I: Integral {
257
2.46k
    let len = self.len();
258
2.46k
    check::<I>("load", len);
259
2.46k
260
2.46k
    match self.domain() {
261
0
      Domain::Enclave(elem) => {
262
0
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
263
0
        get(elem, shamt)
264
      },
265
2.46k
      Domain::Region { head, body, tail } => {
266
2.46k
        let mut accum = I::ZERO;
267
268
2.46k
        if let Some(elem) = tail {
269
0
          let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
270
0
          accum = get(elem, shamt);
271
2.46k
        }
272
273
39.3k
        for elem in body.iter().rev().map(BitStore::load_value) {
274
39.3k
          maybe_shift_left(&mut accum, bits_of::<T>());
275
39.3k
          accum |= resize::<T::Mem, I>(elem);
276
39.3k
        }
277
278
2.46k
        if let Some(elem) = head {
279
0
          let shamt =
280
0
            bits_of::<T>() - elem.head().into_inner() as usize;
281
0
          maybe_shift_left(&mut accum, shamt);
282
0
          accum |= get::<_, _, I>(elem, 0);
283
2.46k
        }
284
285
2.46k
        accum
286
      },
287
    }
288
2.46k
    .pipe(|elem| sign(elem, len))
289
2.46k
  }
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<_>
290
291
  #[inline]
292
  #[doc = include_str!("../doc/field/BitField_Msb0_load_be.md")]
293
119k
  fn load_be<I>(&self) -> I
294
119k
  where I: Integral {
295
119k
    let len = self.len();
296
119k
    check::<I>("load", len);
297
119k
298
119k
    match self.domain() {
299
0
      Domain::Enclave(elem) => {
300
0
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
301
0
        get(elem, shamt)
302
      },
303
119k
      Domain::Region { head, body, tail } => {
304
119k
        let mut accum = I::ZERO;
305
306
119k
        if let Some(elem) = head {
307
78.8k
          accum = get(elem, 0);
308
78.8k
        }
309
310
885k
        for elem in body.iter().map(BitStore::load_value) {
311
885k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
885k
          accum |= resize::<T::Mem, I>(elem);
313
885k
        }
314
315
119k
        if let Some(elem) = tail {
316
34.3k
          let shamt = elem.tail().into_inner();
317
34.3k
          maybe_shift_left(&mut accum, shamt as usize);
318
34.3k
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
84.8k
        }
320
321
119k
        accum
322
      },
323
    }
324
119k
    .pipe(|elem| sign(elem, len))
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<usize>::{closure#0}
Line
Count
Source
324
84.8k
    .pipe(|elem| sign(elem, len))
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u128>::{closure#0}
Line
Count
Source
324
32.2k
    .pipe(|elem| sign(elem, len))
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u16>::{closure#0}
Line
Count
Source
324
2.16k
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<_>::{closure#0}
325
119k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<usize>
Line
Count
Source
293
84.8k
  fn load_be<I>(&self) -> I
294
84.8k
  where I: Integral {
295
84.8k
    let len = self.len();
296
84.8k
    check::<I>("load", len);
297
84.8k
298
84.8k
    match self.domain() {
299
0
      Domain::Enclave(elem) => {
300
0
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
301
0
        get(elem, shamt)
302
      },
303
84.8k
      Domain::Region { head, body, tail } => {
304
84.8k
        let mut accum = I::ZERO;
305
306
84.8k
        if let Some(elem) = head {
307
78.8k
          accum = get(elem, 0);
308
78.8k
        }
309
310
365k
        for elem in body.iter().map(BitStore::load_value) {
311
365k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
365k
          accum |= resize::<T::Mem, I>(elem);
313
365k
        }
314
315
84.8k
        if let Some(elem) = tail {
316
34.3k
          let shamt = elem.tail().into_inner();
317
34.3k
          maybe_shift_left(&mut accum, shamt as usize);
318
34.3k
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
50.4k
        }
320
321
84.8k
        accum
322
      },
323
    }
324
84.8k
    .pipe(|elem| sign(elem, len))
325
84.8k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u128>
Line
Count
Source
293
32.2k
  fn load_be<I>(&self) -> I
294
32.2k
  where I: Integral {
295
32.2k
    let len = self.len();
296
32.2k
    check::<I>("load", len);
297
32.2k
298
32.2k
    match self.domain() {
299
0
      Domain::Enclave(elem) => {
300
0
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
301
0
        get(elem, shamt)
302
      },
303
32.2k
      Domain::Region { head, body, tail } => {
304
32.2k
        let mut accum = I::ZERO;
305
306
32.2k
        if let Some(elem) = head {
307
0
          accum = get(elem, 0);
308
32.2k
        }
309
310
515k
        for elem in body.iter().map(BitStore::load_value) {
311
515k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
515k
          accum |= resize::<T::Mem, I>(elem);
313
515k
        }
314
315
32.2k
        if let Some(elem) = tail {
316
0
          let shamt = elem.tail().into_inner();
317
0
          maybe_shift_left(&mut accum, shamt as usize);
318
0
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
32.2k
        }
320
321
32.2k
        accum
322
      },
323
    }
324
32.2k
    .pipe(|elem| sign(elem, len))
325
32.2k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u16>
Line
Count
Source
293
2.16k
  fn load_be<I>(&self) -> I
294
2.16k
  where I: Integral {
295
2.16k
    let len = self.len();
296
2.16k
    check::<I>("load", len);
297
2.16k
298
2.16k
    match self.domain() {
299
0
      Domain::Enclave(elem) => {
300
0
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
301
0
        get(elem, shamt)
302
      },
303
2.16k
      Domain::Region { head, body, tail } => {
304
2.16k
        let mut accum = I::ZERO;
305
306
2.16k
        if let Some(elem) = head {
307
0
          accum = get(elem, 0);
308
2.16k
        }
309
310
4.32k
        for elem in body.iter().map(BitStore::load_value) {
311
4.32k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
4.32k
          accum |= resize::<T::Mem, I>(elem);
313
4.32k
        }
314
315
2.16k
        if let Some(elem) = tail {
316
0
          let shamt = elem.tail().into_inner();
317
0
          maybe_shift_left(&mut accum, shamt as usize);
318
0
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
2.16k
        }
320
321
2.16k
        accum
322
      },
323
    }
324
2.16k
    .pipe(|elem| sign(elem, len))
325
2.16k
  }
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<_>
326
327
  #[inline]
328
  #[doc = include_str!("../doc/field/BitField_Msb0_store_le.md")]
329
27.9k
  fn store_le<I>(&mut self, mut value: I)
330
27.9k
  where I: Integral {
331
27.9k
    check::<I>("store", self.len());
332
27.9k
333
27.9k
    match self.domain_mut() {
334
0
      Domain::Enclave(elem) => {
335
0
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
336
0
        set(elem, value, shamt);
337
0
      },
338
27.9k
      Domain::Region { head, body, tail } => {
339
27.9k
        if let Some(elem) = head {
340
0
          let shamt =
341
0
            bits_of::<T>() - elem.head().into_inner() as usize;
342
0
          set(elem, value, 0);
343
0
          maybe_shift_right(&mut value, shamt);
344
27.9k
        }
345
346
446k
        for elem in body.iter_mut() {
347
446k
          elem.store_value(resize(value));
348
446k
          maybe_shift_right(&mut value, bits_of::<T>());
349
446k
        }
350
351
27.9k
        if let Some(elem) = tail {
352
0
          let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
353
0
          set(elem, value, shamt);
354
27.9k
        }
355
      },
356
    }
357
27.9k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_le::<u128>
Line
Count
Source
329
27.9k
  fn store_le<I>(&mut self, mut value: I)
330
27.9k
  where I: Integral {
331
27.9k
    check::<I>("store", self.len());
332
27.9k
333
27.9k
    match self.domain_mut() {
334
0
      Domain::Enclave(elem) => {
335
0
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
336
0
        set(elem, value, shamt);
337
0
      },
338
27.9k
      Domain::Region { head, body, tail } => {
339
27.9k
        if let Some(elem) = head {
340
0
          let shamt =
341
0
            bits_of::<T>() - elem.head().into_inner() as usize;
342
0
          set(elem, value, 0);
343
0
          maybe_shift_right(&mut value, shamt);
344
27.9k
        }
345
346
446k
        for elem in body.iter_mut() {
347
446k
          elem.store_value(resize(value));
348
446k
          maybe_shift_right(&mut value, bits_of::<T>());
349
446k
        }
350
351
27.9k
        if let Some(elem) = tail {
352
0
          let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
353
0
          set(elem, value, shamt);
354
27.9k
        }
355
      },
356
    }
357
27.9k
  }
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::store_le::<_>
358
359
  #[inline]
360
  #[doc = include_str!("../doc/field/BitField_Msb0_store_be.md")]
361
135k
  fn store_be<I>(&mut self, mut value: I)
362
135k
  where I: Integral {
363
135k
    check::<I>("store", self.len());
364
135k
365
135k
    match self.domain_mut() {
366
5.61k
      Domain::Enclave(elem) => {
367
5.61k
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
5.61k
        set(elem, value, shamt);
369
5.61k
      },
370
130k
      Domain::Region { head, body, tail } => {
371
130k
        if let Some(elem) = tail {
372
50.7k
          let tail = elem.tail().into_inner() as usize;
373
50.7k
          let shamt = bits_of::<T>() - tail;
374
50.7k
          set(elem, value, shamt as u8);
375
50.7k
          maybe_shift_right(&mut value, tail);
376
79.4k
        }
377
378
818k
        for elem in body.iter_mut().rev() {
379
818k
          elem.store_value(resize(value));
380
818k
          maybe_shift_right(&mut value, bits_of::<T>());
381
818k
        }
382
383
130k
        if let Some(elem) = head {
384
79.2k
          set(elem, value, 0);
385
79.2k
        }
386
      },
387
    }
388
135k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<usize>
Line
Count
Source
361
84.8k
  fn store_be<I>(&mut self, mut value: I)
362
84.8k
  where I: Integral {
363
84.8k
    check::<I>("store", self.len());
364
84.8k
365
84.8k
    match self.domain_mut() {
366
5.61k
      Domain::Enclave(elem) => {
367
5.61k
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
5.61k
        set(elem, value, shamt);
369
5.61k
      },
370
79.2k
      Domain::Region { head, body, tail } => {
371
79.2k
        if let Some(elem) = tail {
372
50.7k
          let tail = elem.tail().into_inner() as usize;
373
50.7k
          let shamt = bits_of::<T>() - tail;
374
50.7k
          set(elem, value, shamt as u8);
375
50.7k
          maybe_shift_right(&mut value, tail);
376
50.7k
        }
377
378
343k
        for elem in body.iter_mut().rev() {
379
343k
          elem.store_value(resize(value));
380
343k
          maybe_shift_right(&mut value, bits_of::<T>());
381
343k
        }
382
383
79.2k
        if let Some(elem) = head {
384
79.2k
          set(elem, value, 0);
385
79.2k
        }
386
      },
387
    }
388
84.8k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<u128>
Line
Count
Source
361
26.5k
  fn store_be<I>(&mut self, mut value: I)
362
26.5k
  where I: Integral {
363
26.5k
    check::<I>("store", self.len());
364
26.5k
365
26.5k
    match self.domain_mut() {
366
0
      Domain::Enclave(elem) => {
367
0
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
0
        set(elem, value, shamt);
369
0
      },
370
26.5k
      Domain::Region { head, body, tail } => {
371
26.5k
        if let Some(elem) = tail {
372
0
          let tail = elem.tail().into_inner() as usize;
373
0
          let shamt = bits_of::<T>() - tail;
374
0
          set(elem, value, shamt as u8);
375
0
          maybe_shift_right(&mut value, tail);
376
26.5k
        }
377
378
425k
        for elem in body.iter_mut().rev() {
379
425k
          elem.store_value(resize(value));
380
425k
          maybe_shift_right(&mut value, bits_of::<T>());
381
425k
        }
382
383
26.5k
        if let Some(elem) = head {
384
0
          set(elem, value, 0);
385
26.5k
        }
386
      },
387
    }
388
26.5k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<i16>
Line
Count
Source
361
24.4k
  fn store_be<I>(&mut self, mut value: I)
362
24.4k
  where I: Integral {
363
24.4k
    check::<I>("store", self.len());
364
24.4k
365
24.4k
    match self.domain_mut() {
366
0
      Domain::Enclave(elem) => {
367
0
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
0
        set(elem, value, shamt);
369
0
      },
370
24.4k
      Domain::Region { head, body, tail } => {
371
24.4k
        if let Some(elem) = tail {
372
0
          let tail = elem.tail().into_inner() as usize;
373
0
          let shamt = bits_of::<T>() - tail;
374
0
          set(elem, value, shamt as u8);
375
0
          maybe_shift_right(&mut value, tail);
376
24.4k
        }
377
378
48.8k
        for elem in body.iter_mut().rev() {
379
48.8k
          elem.store_value(resize(value));
380
48.8k
          maybe_shift_right(&mut value, bits_of::<T>());
381
48.8k
        }
382
383
24.4k
        if let Some(elem) = head {
384
0
          set(elem, value, 0);
385
24.4k
        }
386
      },
387
    }
388
24.4k
  }
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<_>
389
}
390
391
#[doc = include_str!("../doc/field/impl_BitArray.md")]
392
impl<A, O> BitField for BitArray<A, O>
393
where
394
  O: BitOrder,
395
  A: BitViewSized,
396
  BitSlice<A::Store, O>: BitField,
397
{
398
  #[inline(always)]
399
0
  fn load_le<I>(&self) -> I
400
0
  where I: Integral {
401
0
    let mut accum = I::ZERO;
402
403
0
    for elem in self.as_raw_slice().iter().map(BitStore::load_value).rev() {
404
0
      maybe_shift_left(&mut accum, bits_of::<A::Store>());
405
0
      accum |= resize::<_, I>(elem);
406
0
    }
407
408
0
    sign(accum, self.len())
409
0
  }
410
411
  #[inline(always)]
412
0
  fn load_be<I>(&self) -> I
413
0
  where I: Integral {
414
0
    let mut accum = I::ZERO;
415
416
0
    for elem in self.as_raw_slice().iter().map(BitStore::load_value) {
417
0
      maybe_shift_left(&mut accum, bits_of::<A::Store>());
418
0
      accum |= resize::<_, I>(elem);
419
0
    }
420
421
0
    sign(accum, self.len())
422
0
  }
423
424
  #[inline(always)]
425
0
  fn store_le<I>(&mut self, mut value: I)
426
0
  where I: Integral {
427
0
    for slot in self.as_raw_mut_slice() {
428
0
      slot.store_value(resize(value));
429
0
      maybe_shift_right(&mut value, bits_of::<A::Store>());
430
0
    }
431
0
  }
432
433
  #[inline(always)]
434
0
  fn store_be<I>(&mut self, mut value: I)
435
0
  where I: Integral {
436
0
    for slot in self.as_raw_mut_slice().iter_mut().rev() {
437
0
      slot.store_value(resize(value));
438
0
      maybe_shift_right(&mut value, bits_of::<A::Store>());
439
0
    }
440
0
  }
441
}
442
443
#[cfg(feature = "alloc")]
444
#[cfg(not(tarpaulin_include))]
445
impl<T, O> BitField for BitBox<T, O>
446
where
447
  T: BitStore,
448
  O: BitOrder,
449
  BitSlice<T, O>: BitField,
450
{
451
  #[inline(always)]
452
0
  fn load_le<I>(&self) -> I
453
0
  where I: Integral {
454
0
    self.as_bitslice().load_le()
455
0
  }
456
457
  #[inline(always)]
458
0
  fn load_be<I>(&self) -> I
459
0
  where I: Integral {
460
0
    self.as_bitslice().load_be()
461
0
  }
462
463
  #[inline(always)]
464
0
  fn store_le<I>(&mut self, value: I)
465
0
  where I: Integral {
466
0
    self.as_mut_bitslice().store_le(value)
467
0
  }
468
469
  #[inline(always)]
470
0
  fn store_be<I>(&mut self, value: I)
471
0
  where I: Integral {
472
0
    self.as_mut_bitslice().store_be(value)
473
0
  }
474
}
475
476
#[cfg(feature = "alloc")]
477
#[cfg(not(tarpaulin_include))]
478
impl<T, O> BitField for BitVec<T, O>
479
where
480
  T: BitStore,
481
  O: BitOrder,
482
  BitSlice<T, O>: BitField,
483
{
484
  #[inline(always)]
485
0
  fn load_le<I>(&self) -> I
486
0
  where I: Integral {
487
0
    self.as_bitslice().load_le()
488
0
  }
489
490
  #[inline(always)]
491
0
  fn load_be<I>(&self) -> I
492
0
  where I: Integral {
493
0
    self.as_bitslice().load_be()
494
0
  }
495
496
  #[inline(always)]
497
0
  fn store_le<I>(&mut self, value: I)
498
0
  where I: Integral {
499
0
    self.as_mut_bitslice().store_le(value)
500
0
  }
501
502
  #[inline(always)]
503
0
  fn store_be<I>(&mut self, value: I)
504
0
  where I: Integral {
505
0
    self.as_mut_bitslice().store_be(value)
506
0
  }
507
}
508
509
/** Asserts that a bit-slice is not longer than a memory element.
510
511
## Type Parameters
512
513
- `I`: The integer type being stored into or loaded out of a bit-slice.
514
515
## Parameters
516
517
- `action`: the verb being performed. One of `"load"` or `"store"`.
518
- `len`: the length of the bit-slice under test.
519
520
## Panics
521
522
This panics if `len` is not in `1 ..= U::BITS`.
523
**/
524
285k
fn check<I>(action: &'static str, len: usize)
525
285k
where I: Integral {
526
285k
  assert!(
527
285k
    (1 ..= bits_of::<I>()).contains(&len),
528
0
    "cannot {} {} bits from a {}-bit region",
529
0
    action,
530
0
    bits_of::<I>(),
531
    len,
532
  );
533
285k
}
bitvec::field::check::<usize>
Line
Count
Source
524
169k
fn check<I>(action: &'static str, len: usize)
525
169k
where I: Integral {
526
169k
  assert!(
527
169k
    (1 ..= bits_of::<I>()).contains(&len),
528
0
    "cannot {} {} bits from a {}-bit region",
529
0
    action,
530
0
    bits_of::<I>(),
531
    len,
532
  );
533
169k
}
bitvec::field::check::<u128>
Line
Count
Source
524
89.1k
fn check<I>(action: &'static str, len: usize)
525
89.1k
where I: Integral {
526
89.1k
  assert!(
527
89.1k
    (1 ..= bits_of::<I>()).contains(&len),
528
0
    "cannot {} {} bits from a {}-bit region",
529
0
    action,
530
0
    bits_of::<I>(),
531
    len,
532
  );
533
89.1k
}
bitvec::field::check::<i16>
Line
Count
Source
524
24.4k
fn check<I>(action: &'static str, len: usize)
525
24.4k
where I: Integral {
526
24.4k
  assert!(
527
24.4k
    (1 ..= bits_of::<I>()).contains(&len),
528
0
    "cannot {} {} bits from a {}-bit region",
529
0
    action,
530
0
    bits_of::<I>(),
531
    len,
532
  );
533
24.4k
}
bitvec::field::check::<u16>
Line
Count
Source
524
2.16k
fn check<I>(action: &'static str, len: usize)
525
2.16k
where I: Integral {
526
2.16k
  assert!(
527
2.16k
    (1 ..= bits_of::<I>()).contains(&len),
528
0
    "cannot {} {} bits from a {}-bit region",
529
0
    action,
530
0
    bits_of::<I>(),
531
    len,
532
  );
533
2.16k
}
Unexecuted instantiation: bitvec::field::check::<_>
534
535
/// Shifts a value to the left, if it can support the shift amount.
536
959k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
959k
  if bits_of::<T>() > shamt {
538
959k
    *elem <<= shamt;
539
959k
  }
540
959k
}
bitvec::field::maybe_shift_left::<usize>
Line
Count
Source
536
400k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
400k
  if bits_of::<T>() > shamt {
538
400k
    *elem <<= shamt;
539
400k
  }
540
400k
}
bitvec::field::maybe_shift_left::<u128>
Line
Count
Source
536
555k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
555k
  if bits_of::<T>() > shamt {
538
555k
    *elem <<= shamt;
539
555k
  }
540
555k
}
bitvec::field::maybe_shift_left::<u16>
Line
Count
Source
536
4.32k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
4.32k
  if bits_of::<T>() > shamt {
538
4.32k
    *elem <<= shamt;
539
4.32k
  }
540
4.32k
}
Unexecuted instantiation: bitvec::field::maybe_shift_left::<_>
541
542
/// Shifts a value to the right, if it can support the shift amount.
543
1.31M
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
1.31M
  if bits_of::<T>() > shamt {
545
1.31M
    *elem >>= shamt;
546
1.31M
  }
547
1.31M
}
bitvec::field::maybe_shift_right::<usize>
Line
Count
Source
543
394k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
394k
  if bits_of::<T>() > shamt {
545
394k
    *elem >>= shamt;
546
394k
  }
547
394k
}
bitvec::field::maybe_shift_right::<u128>
Line
Count
Source
543
872k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
872k
  if bits_of::<T>() > shamt {
545
872k
    *elem >>= shamt;
546
872k
  }
547
872k
}
bitvec::field::maybe_shift_right::<i16>
Line
Count
Source
543
48.8k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
48.8k
  if bits_of::<T>() > shamt {
545
48.8k
    *elem >>= shamt;
546
48.8k
  }
547
48.8k
}
Unexecuted instantiation: bitvec::field::maybe_shift_right::<_>
548
549
#[doc = include_str!("../doc/field/get.md")]
550
113k
fn get<T, O, I>(elem: PartialElement<Const, T, O>, shamt: u8) -> I
551
113k
where
552
113k
  T: BitStore,
553
113k
  O: BitOrder,
554
113k
  I: Integral,
555
113k
{
556
113k
  resize::<T::Mem, I>(elem.load_value() >> shamt)
557
113k
}
Unexecuted instantiation: bitvec::field::get::<u8, bitvec::order::Lsb0, usize>
bitvec::field::get::<u8, bitvec::order::Msb0, usize>
Line
Count
Source
550
113k
fn get<T, O, I>(elem: PartialElement<Const, T, O>, shamt: u8) -> I
551
113k
where
552
113k
  T: BitStore,
553
113k
  O: BitOrder,
554
113k
  I: Integral,
555
113k
{
556
113k
  resize::<T::Mem, I>(elem.load_value() >> shamt)
557
113k
}
Unexecuted instantiation: bitvec::field::get::<u8, bitvec::order::Msb0, u128>
Unexecuted instantiation: bitvec::field::get::<u8, bitvec::order::Msb0, u16>
Unexecuted instantiation: bitvec::field::get::<_, _, _>
558
559
#[doc = include_str!("../doc/field/set.md")]
560
135k
fn set<T, O, I>(mut elem: PartialElement<Mut, T, O>, value: I, shamt: u8)
561
135k
where
562
135k
  T: BitStore,
563
135k
  O: BitOrder,
564
135k
  I: Integral,
565
135k
{
566
135k
  elem.store_value(resize::<I, T::Mem>(value) << shamt);
567
135k
}
Unexecuted instantiation: bitvec::field::set::<u8, bitvec::order::Lsb0, usize>
bitvec::field::set::<u8, bitvec::order::Msb0, usize>
Line
Count
Source
560
135k
fn set<T, O, I>(mut elem: PartialElement<Mut, T, O>, value: I, shamt: u8)
561
135k
where
562
135k
  T: BitStore,
563
135k
  O: BitOrder,
564
135k
  I: Integral,
565
135k
{
566
135k
  elem.store_value(resize::<I, T::Mem>(value) << shamt);
567
135k
}
Unexecuted instantiation: bitvec::field::set::<u8, bitvec::order::Msb0, u128>
Unexecuted instantiation: bitvec::field::set::<u8, bitvec::order::Msb0, i16>
Unexecuted instantiation: bitvec::field::set::<_, _, _>
568
569
#[doc = include_str!("../doc/field/sign.md")]
570
121k
fn sign<I>(elem: I, width: usize) -> I
571
121k
where I: Integral {
572
121k
  if dvl::is_unsigned::<I>() {
573
121k
    return elem;
574
0
  }
575
0
  //  Find the number of high bits that are not loaded.
576
0
  let shamt = bits_of::<I>() - width;
577
0
  //  Shift left, so that the highest loaded bit is now in the sign position.
578
0
  let shl: I = elem << shamt;
579
0
  //  Shift right with sign extension back to the original place.
580
0
  shl >> shamt
581
121k
}
bitvec::field::sign::<usize>
Line
Count
Source
570
84.8k
fn sign<I>(elem: I, width: usize) -> I
571
84.8k
where I: Integral {
572
84.8k
  if dvl::is_unsigned::<I>() {
573
84.8k
    return elem;
574
0
  }
575
0
  //  Find the number of high bits that are not loaded.
576
0
  let shamt = bits_of::<I>() - width;
577
0
  //  Shift left, so that the highest loaded bit is now in the sign position.
578
0
  let shl: I = elem << shamt;
579
0
  //  Shift right with sign extension back to the original place.
580
0
  shl >> shamt
581
84.8k
}
bitvec::field::sign::<u128>
Line
Count
Source
570
34.6k
fn sign<I>(elem: I, width: usize) -> I
571
34.6k
where I: Integral {
572
34.6k
  if dvl::is_unsigned::<I>() {
573
34.6k
    return elem;
574
0
  }
575
0
  //  Find the number of high bits that are not loaded.
576
0
  let shamt = bits_of::<I>() - width;
577
0
  //  Shift left, so that the highest loaded bit is now in the sign position.
578
0
  let shl: I = elem << shamt;
579
0
  //  Shift right with sign extension back to the original place.
580
0
  shl >> shamt
581
34.6k
}
bitvec::field::sign::<u16>
Line
Count
Source
570
2.16k
fn sign<I>(elem: I, width: usize) -> I
571
2.16k
where I: Integral {
572
2.16k
  if dvl::is_unsigned::<I>() {
573
2.16k
    return elem;
574
0
  }
575
0
  //  Find the number of high bits that are not loaded.
576
0
  let shamt = bits_of::<I>() - width;
577
0
  //  Shift left, so that the highest loaded bit is now in the sign position.
578
0
  let shl: I = elem << shamt;
579
0
  //  Shift right with sign extension back to the original place.
580
0
  shl >> shamt
581
2.16k
}
Unexecuted instantiation: bitvec::field::sign::<_>
582
583
#[doc = include_str!("../doc/field/resize.md")]
584
2.43M
fn resize<T, U>(value: T) -> U
585
2.43M
where
586
2.43M
  T: Integral,
587
2.43M
  U: Integral,
588
2.43M
{
589
2.43M
  let mut out = U::ZERO;
590
2.43M
  let size_t = mem::size_of::<T>();
591
2.43M
  let size_u = mem::size_of::<U>();
592
2.43M
593
2.43M
  unsafe {
594
2.43M
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
2.43M
  }
596
2.43M
597
2.43M
  out
598
2.43M
}
bitvec::field::resize::<u8, usize>
Line
Count
Source
584
479k
fn resize<T, U>(value: T) -> U
585
479k
where
586
479k
  T: Integral,
587
479k
  U: Integral,
588
479k
{
589
479k
  let mut out = U::ZERO;
590
479k
  let size_t = mem::size_of::<T>();
591
479k
  let size_u = mem::size_of::<U>();
592
479k
593
479k
  unsafe {
594
479k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
479k
  }
596
479k
597
479k
  out
598
479k
}
bitvec::field::resize::<u8, u128>
Line
Count
Source
584
555k
fn resize<T, U>(value: T) -> U
585
555k
where
586
555k
  T: Integral,
587
555k
  U: Integral,
588
555k
{
589
555k
  let mut out = U::ZERO;
590
555k
  let size_t = mem::size_of::<T>();
591
555k
  let size_u = mem::size_of::<U>();
592
555k
593
555k
  unsafe {
594
555k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
555k
  }
596
555k
597
555k
  out
598
555k
}
bitvec::field::resize::<u8, u16>
Line
Count
Source
584
4.32k
fn resize<T, U>(value: T) -> U
585
4.32k
where
586
4.32k
  T: Integral,
587
4.32k
  U: Integral,
588
4.32k
{
589
4.32k
  let mut out = U::ZERO;
590
4.32k
  let size_t = mem::size_of::<T>();
591
4.32k
  let size_u = mem::size_of::<U>();
592
4.32k
593
4.32k
  unsafe {
594
4.32k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
4.32k
  }
596
4.32k
597
4.32k
  out
598
4.32k
}
bitvec::field::resize::<usize, u8>
Line
Count
Source
584
479k
fn resize<T, U>(value: T) -> U
585
479k
where
586
479k
  T: Integral,
587
479k
  U: Integral,
588
479k
{
589
479k
  let mut out = U::ZERO;
590
479k
  let size_t = mem::size_of::<T>();
591
479k
  let size_u = mem::size_of::<U>();
592
479k
593
479k
  unsafe {
594
479k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
479k
  }
596
479k
597
479k
  out
598
479k
}
bitvec::field::resize::<u128, u8>
Line
Count
Source
584
872k
fn resize<T, U>(value: T) -> U
585
872k
where
586
872k
  T: Integral,
587
872k
  U: Integral,
588
872k
{
589
872k
  let mut out = U::ZERO;
590
872k
  let size_t = mem::size_of::<T>();
591
872k
  let size_u = mem::size_of::<U>();
592
872k
593
872k
  unsafe {
594
872k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
872k
  }
596
872k
597
872k
  out
598
872k
}
bitvec::field::resize::<i16, u8>
Line
Count
Source
584
48.8k
fn resize<T, U>(value: T) -> U
585
48.8k
where
586
48.8k
  T: Integral,
587
48.8k
  U: Integral,
588
48.8k
{
589
48.8k
  let mut out = U::ZERO;
590
48.8k
  let size_t = mem::size_of::<T>();
591
48.8k
  let size_u = mem::size_of::<U>();
592
48.8k
593
48.8k
  unsafe {
594
48.8k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
48.8k
  }
596
48.8k
597
48.8k
  out
598
48.8k
}
Unexecuted instantiation: bitvec::field::resize::<_, _>
599
600
/// Performs little-endian byte-order register resizing.
601
#[cfg(target_endian = "little")]
602
2.43M
unsafe fn resize_inner<T, U>(
603
2.43M
  src: &T,
604
2.43M
  dst: &mut U,
605
2.43M
  size_t: usize,
606
2.43M
  size_u: usize,
607
2.43M
) {
608
2.43M
  //  In LE, the least-significant byte is the base address, so resizing is
609
2.43M
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
2.43M
  ptr::copy_nonoverlapping(
611
2.43M
    src as *const T as *const u8,
612
2.43M
    dst as *mut U as *mut u8,
613
2.43M
    size_t.min(size_u),
614
2.43M
  );
615
2.43M
}
bitvec::field::resize_inner::<u8, usize>
Line
Count
Source
602
479k
unsafe fn resize_inner<T, U>(
603
479k
  src: &T,
604
479k
  dst: &mut U,
605
479k
  size_t: usize,
606
479k
  size_u: usize,
607
479k
) {
608
479k
  //  In LE, the least-significant byte is the base address, so resizing is
609
479k
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
479k
  ptr::copy_nonoverlapping(
611
479k
    src as *const T as *const u8,
612
479k
    dst as *mut U as *mut u8,
613
479k
    size_t.min(size_u),
614
479k
  );
615
479k
}
bitvec::field::resize_inner::<u8, u128>
Line
Count
Source
602
555k
unsafe fn resize_inner<T, U>(
603
555k
  src: &T,
604
555k
  dst: &mut U,
605
555k
  size_t: usize,
606
555k
  size_u: usize,
607
555k
) {
608
555k
  //  In LE, the least-significant byte is the base address, so resizing is
609
555k
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
555k
  ptr::copy_nonoverlapping(
611
555k
    src as *const T as *const u8,
612
555k
    dst as *mut U as *mut u8,
613
555k
    size_t.min(size_u),
614
555k
  );
615
555k
}
bitvec::field::resize_inner::<u8, u16>
Line
Count
Source
602
4.32k
unsafe fn resize_inner<T, U>(
603
4.32k
  src: &T,
604
4.32k
  dst: &mut U,
605
4.32k
  size_t: usize,
606
4.32k
  size_u: usize,
607
4.32k
) {
608
4.32k
  //  In LE, the least-significant byte is the base address, so resizing is
609
4.32k
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
4.32k
  ptr::copy_nonoverlapping(
611
4.32k
    src as *const T as *const u8,
612
4.32k
    dst as *mut U as *mut u8,
613
4.32k
    size_t.min(size_u),
614
4.32k
  );
615
4.32k
}
bitvec::field::resize_inner::<usize, u8>
Line
Count
Source
602
479k
unsafe fn resize_inner<T, U>(
603
479k
  src: &T,
604
479k
  dst: &mut U,
605
479k
  size_t: usize,
606
479k
  size_u: usize,
607
479k
) {
608
479k
  //  In LE, the least-significant byte is the base address, so resizing is
609
479k
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
479k
  ptr::copy_nonoverlapping(
611
479k
    src as *const T as *const u8,
612
479k
    dst as *mut U as *mut u8,
613
479k
    size_t.min(size_u),
614
479k
  );
615
479k
}
bitvec::field::resize_inner::<u128, u8>
Line
Count
Source
602
872k
unsafe fn resize_inner<T, U>(
603
872k
  src: &T,
604
872k
  dst: &mut U,
605
872k
  size_t: usize,
606
872k
  size_u: usize,
607
872k
) {
608
872k
  //  In LE, the least-significant byte is the base address, so resizing is
609
872k
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
872k
  ptr::copy_nonoverlapping(
611
872k
    src as *const T as *const u8,
612
872k
    dst as *mut U as *mut u8,
613
872k
    size_t.min(size_u),
614
872k
  );
615
872k
}
bitvec::field::resize_inner::<i16, u8>
Line
Count
Source
602
48.8k
unsafe fn resize_inner<T, U>(
603
48.8k
  src: &T,
604
48.8k
  dst: &mut U,
605
48.8k
  size_t: usize,
606
48.8k
  size_u: usize,
607
48.8k
) {
608
48.8k
  //  In LE, the least-significant byte is the base address, so resizing is
609
48.8k
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
48.8k
  ptr::copy_nonoverlapping(
611
48.8k
    src as *const T as *const u8,
612
48.8k
    dst as *mut U as *mut u8,
613
48.8k
    size_t.min(size_u),
614
48.8k
  );
615
48.8k
}
Unexecuted instantiation: bitvec::field::resize_inner::<_, _>
616
617
/// Performs big-endian byte-order register resizing.
618
#[cfg(target_endian = "big")]
619
unsafe fn resize_inner<T, U>(
620
  src: &T,
621
  dst: &mut U,
622
  size_t: usize,
623
  size_u: usize,
624
) {
625
  let src = src as *const T as *const u8;
626
  let dst = dst as *mut U as *mut u8;
627
628
  //  In BE, shrinking a value requires moving the source base-pointer up in
629
  //  memory (to a higher address, lower significance),
630
  if size_t > size_u {
631
    ptr::copy_nonoverlapping(src.add(size_t - size_u), dst, size_u);
632
  }
633
  //  While expanding a value requires moving the *destination* base-pointer
634
  //  up (and leaving the lower address, higher significance bytes zeroed).
635
  else {
636
    ptr::copy_nonoverlapping(src, dst.add(size_u - size_t), size_t);
637
  }
638
}