Coverage Report

Created: 2025-12-05 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/bitvec-1.0.1/src/field.rs
Line
Count
Source
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
          "This architecture is not supported! Please consider \
58
           filing an issue at {}",
59
          env
60
        ),
61
0
        None => unreachable!(
62
          "This architecture is not supported! Please consider \
63
           filing an issue"
64
        ),
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
          "This architecture is not supported! Please consider \
84
           filing an issue at {}",
85
          env
86
        ),
87
0
        None => unreachable!(
88
          "This architecture is not supported! Please consider \
89
           filing an issue"
90
        ),
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
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
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
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
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.99k
  fn load_le<I>(&self) -> I
256
2.99k
  where I: Integral {
257
2.99k
    let len = self.len();
258
2.99k
    check::<I>("load", len);
259
260
2.99k
    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.99k
      Domain::Region { head, body, tail } => {
266
2.99k
        let mut accum = I::ZERO;
267
268
2.99k
        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.99k
        }
272
273
47.8k
        for elem in body.iter().rev().map(BitStore::load_value) {
274
47.8k
          maybe_shift_left(&mut accum, bits_of::<T>());
275
47.8k
          accum |= resize::<T::Mem, I>(elem);
276
47.8k
        }
277
278
2.99k
        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.99k
        }
284
285
2.99k
        accum
286
      },
287
    }
288
2.99k
    .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.99k
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<_>::{closure#0}
289
2.99k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<u128>
Line
Count
Source
255
2.99k
  fn load_le<I>(&self) -> I
256
2.99k
  where I: Integral {
257
2.99k
    let len = self.len();
258
2.99k
    check::<I>("load", len);
259
260
2.99k
    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.99k
      Domain::Region { head, body, tail } => {
266
2.99k
        let mut accum = I::ZERO;
267
268
2.99k
        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.99k
        }
272
273
47.8k
        for elem in body.iter().rev().map(BitStore::load_value) {
274
47.8k
          maybe_shift_left(&mut accum, bits_of::<T>());
275
47.8k
          accum |= resize::<T::Mem, I>(elem);
276
47.8k
        }
277
278
2.99k
        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.99k
        }
284
285
2.99k
        accum
286
      },
287
    }
288
2.99k
    .pipe(|elem| sign(elem, len))
289
2.99k
  }
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
151k
  fn load_be<I>(&self) -> I
294
151k
  where I: Integral {
295
151k
    let len = self.len();
296
151k
    check::<I>("load", len);
297
298
151k
    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
151k
      Domain::Region { head, body, tail } => {
304
151k
        let mut accum = I::ZERO;
305
306
151k
        if let Some(elem) = head {
307
102k
          accum = get(elem, 0);
308
102k
        }
309
310
1.12M
        for elem in body.iter().map(BitStore::load_value) {
311
1.12M
          maybe_shift_left(&mut accum, bits_of::<T>());
312
1.12M
          accum |= resize::<T::Mem, I>(elem);
313
1.12M
        }
314
315
151k
        if let Some(elem) = tail {
316
43.2k
          let shamt = elem.tail().into_inner();
317
43.2k
          maybe_shift_left(&mut accum, shamt as usize);
318
43.2k
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
108k
        }
320
321
151k
        accum
322
      },
323
    }
324
151k
    .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
108k
    .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
40.5k
    .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.68k
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<_>::{closure#0}
325
151k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<usize>
Line
Count
Source
293
108k
  fn load_be<I>(&self) -> I
294
108k
  where I: Integral {
295
108k
    let len = self.len();
296
108k
    check::<I>("load", len);
297
298
108k
    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
108k
      Domain::Region { head, body, tail } => {
304
108k
        let mut accum = I::ZERO;
305
306
108k
        if let Some(elem) = head {
307
102k
          accum = get(elem, 0);
308
102k
        }
309
310
473k
        for elem in body.iter().map(BitStore::load_value) {
311
473k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
473k
          accum |= resize::<T::Mem, I>(elem);
313
473k
        }
314
315
108k
        if let Some(elem) = tail {
316
43.2k
          let shamt = elem.tail().into_inner();
317
43.2k
          maybe_shift_left(&mut accum, shamt as usize);
318
43.2k
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
65.3k
        }
320
321
108k
        accum
322
      },
323
    }
324
108k
    .pipe(|elem| sign(elem, len))
325
108k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u128>
Line
Count
Source
293
40.5k
  fn load_be<I>(&self) -> I
294
40.5k
  where I: Integral {
295
40.5k
    let len = self.len();
296
40.5k
    check::<I>("load", len);
297
298
40.5k
    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
40.5k
      Domain::Region { head, body, tail } => {
304
40.5k
        let mut accum = I::ZERO;
305
306
40.5k
        if let Some(elem) = head {
307
0
          accum = get(elem, 0);
308
40.5k
        }
309
310
648k
        for elem in body.iter().map(BitStore::load_value) {
311
648k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
648k
          accum |= resize::<T::Mem, I>(elem);
313
648k
        }
314
315
40.5k
        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
40.5k
        }
320
321
40.5k
        accum
322
      },
323
    }
324
40.5k
    .pipe(|elem| sign(elem, len))
325
40.5k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u16>
Line
Count
Source
293
2.68k
  fn load_be<I>(&self) -> I
294
2.68k
  where I: Integral {
295
2.68k
    let len = self.len();
296
2.68k
    check::<I>("load", len);
297
298
2.68k
    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.68k
      Domain::Region { head, body, tail } => {
304
2.68k
        let mut accum = I::ZERO;
305
306
2.68k
        if let Some(elem) = head {
307
0
          accum = get(elem, 0);
308
2.68k
        }
309
310
5.36k
        for elem in body.iter().map(BitStore::load_value) {
311
5.36k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
5.36k
          accum |= resize::<T::Mem, I>(elem);
313
5.36k
        }
314
315
2.68k
        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.68k
        }
320
321
2.68k
        accum
322
      },
323
    }
324
2.68k
    .pipe(|elem| sign(elem, len))
325
2.68k
  }
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
35.1k
  fn store_le<I>(&mut self, mut value: I)
330
35.1k
  where I: Integral {
331
35.1k
    check::<I>("store", self.len());
332
333
35.1k
    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
35.1k
      Domain::Region { head, body, tail } => {
339
35.1k
        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
35.1k
        }
345
346
562k
        for elem in body.iter_mut() {
347
562k
          elem.store_value(resize(value));
348
562k
          maybe_shift_right(&mut value, bits_of::<T>());
349
562k
        }
350
351
35.1k
        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
35.1k
        }
355
      },
356
    }
357
35.1k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_le::<u128>
Line
Count
Source
329
35.1k
  fn store_le<I>(&mut self, mut value: I)
330
35.1k
  where I: Integral {
331
35.1k
    check::<I>("store", self.len());
332
333
35.1k
    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
35.1k
      Domain::Region { head, body, tail } => {
339
35.1k
        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
35.1k
        }
345
346
562k
        for elem in body.iter_mut() {
347
562k
          elem.store_value(resize(value));
348
562k
          maybe_shift_right(&mut value, bits_of::<T>());
349
562k
        }
350
351
35.1k
        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
35.1k
        }
355
      },
356
    }
357
35.1k
  }
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
174k
  fn store_be<I>(&mut self, mut value: I)
362
174k
  where I: Integral {
363
174k
    check::<I>("store", self.len());
364
365
174k
    match self.domain_mut() {
366
6.04k
      Domain::Enclave(elem) => {
367
6.04k
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
6.04k
        set(elem, value, shamt);
369
6.04k
      },
370
168k
      Domain::Region { head, body, tail } => {
371
168k
        if let Some(elem) = tail {
372
65.8k
          let tail = elem.tail().into_inner() as usize;
373
65.8k
          let shamt = bits_of::<T>() - tail;
374
65.8k
          set(elem, value, shamt as u8);
375
65.8k
          maybe_shift_right(&mut value, tail);
376
102k
        }
377
378
1.05M
        for elem in body.iter_mut().rev() {
379
1.05M
          elem.store_value(resize(value));
380
1.05M
          maybe_shift_right(&mut value, bits_of::<T>());
381
1.05M
        }
382
383
168k
        if let Some(elem) = head {
384
102k
          set(elem, value, 0);
385
102k
        }
386
      },
387
    }
388
174k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<usize>
Line
Count
Source
361
108k
  fn store_be<I>(&mut self, mut value: I)
362
108k
  where I: Integral {
363
108k
    check::<I>("store", self.len());
364
365
108k
    match self.domain_mut() {
366
6.04k
      Domain::Enclave(elem) => {
367
6.04k
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
6.04k
        set(elem, value, shamt);
369
6.04k
      },
370
102k
      Domain::Region { head, body, tail } => {
371
102k
        if let Some(elem) = tail {
372
65.8k
          let tail = elem.tail().into_inner() as usize;
373
65.8k
          let shamt = bits_of::<T>() - tail;
374
65.8k
          set(elem, value, shamt as u8);
375
65.8k
          maybe_shift_right(&mut value, tail);
376
65.8k
        }
377
378
444k
        for elem in body.iter_mut().rev() {
379
444k
          elem.store_value(resize(value));
380
444k
          maybe_shift_right(&mut value, bits_of::<T>());
381
444k
        }
382
383
102k
        if let Some(elem) = head {
384
102k
          set(elem, value, 0);
385
102k
        }
386
      },
387
    }
388
108k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<u128>
Line
Count
Source
361
34.3k
  fn store_be<I>(&mut self, mut value: I)
362
34.3k
  where I: Integral {
363
34.3k
    check::<I>("store", self.len());
364
365
34.3k
    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
34.3k
      Domain::Region { head, body, tail } => {
371
34.3k
        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
34.3k
        }
377
378
549k
        for elem in body.iter_mut().rev() {
379
549k
          elem.store_value(resize(value));
380
549k
          maybe_shift_right(&mut value, bits_of::<T>());
381
549k
        }
382
383
34.3k
        if let Some(elem) = head {
384
0
          set(elem, value, 0);
385
34.3k
        }
386
      },
387
    }
388
34.3k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<i16>
Line
Count
Source
361
31.6k
  fn store_be<I>(&mut self, mut value: I)
362
31.6k
  where I: Integral {
363
31.6k
    check::<I>("store", self.len());
364
365
31.6k
    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
31.6k
      Domain::Region { head, body, tail } => {
371
31.6k
        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
31.6k
        }
377
378
63.3k
        for elem in body.iter_mut().rev() {
379
63.3k
          elem.store_value(resize(value));
380
63.3k
          maybe_shift_right(&mut value, bits_of::<T>());
381
63.3k
        }
382
383
31.6k
        if let Some(elem) = head {
384
0
          set(elem, value, 0);
385
31.6k
        }
386
      },
387
    }
388
31.6k
  }
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
364k
fn check<I>(action: &'static str, len: usize)
525
364k
where I: Integral {
526
364k
  assert!(
527
364k
    (1 ..= bits_of::<I>()).contains(&len),
528
0
    "cannot {} {} bits from a {}-bit region",
529
    action,
530
0
    bits_of::<I>(),
531
    len,
532
  );
533
364k
}
bitvec::field::check::<usize>
Line
Count
Source
524
217k
fn check<I>(action: &'static str, len: usize)
525
217k
where I: Integral {
526
217k
  assert!(
527
217k
    (1 ..= bits_of::<I>()).contains(&len),
528
0
    "cannot {} {} bits from a {}-bit region",
529
    action,
530
0
    bits_of::<I>(),
531
    len,
532
  );
533
217k
}
bitvec::field::check::<u128>
Line
Count
Source
524
113k
fn check<I>(action: &'static str, len: usize)
525
113k
where I: Integral {
526
113k
  assert!(
527
113k
    (1 ..= bits_of::<I>()).contains(&len),
528
0
    "cannot {} {} bits from a {}-bit region",
529
    action,
530
0
    bits_of::<I>(),
531
    len,
532
  );
533
113k
}
bitvec::field::check::<i16>
Line
Count
Source
524
31.6k
fn check<I>(action: &'static str, len: usize)
525
31.6k
where I: Integral {
526
31.6k
  assert!(
527
31.6k
    (1 ..= bits_of::<I>()).contains(&len),
528
0
    "cannot {} {} bits from a {}-bit region",
529
    action,
530
0
    bits_of::<I>(),
531
    len,
532
  );
533
31.6k
}
bitvec::field::check::<u16>
Line
Count
Source
524
2.68k
fn check<I>(action: &'static str, len: usize)
525
2.68k
where I: Integral {
526
2.68k
  assert!(
527
2.68k
    (1 ..= bits_of::<I>()).contains(&len),
528
0
    "cannot {} {} bits from a {}-bit region",
529
    action,
530
0
    bits_of::<I>(),
531
    len,
532
  );
533
2.68k
}
Unexecuted instantiation: bitvec::field::check::<_>
534
535
/// Shifts a value to the left, if it can support the shift amount.
536
1.21M
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
1.21M
  if bits_of::<T>() > shamt {
538
1.21M
    *elem <<= shamt;
539
1.21M
  }
540
1.21M
}
bitvec::field::maybe_shift_left::<usize>
Line
Count
Source
536
516k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
516k
  if bits_of::<T>() > shamt {
538
516k
    *elem <<= shamt;
539
516k
  }
540
516k
}
bitvec::field::maybe_shift_left::<u128>
Line
Count
Source
536
696k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
696k
  if bits_of::<T>() > shamt {
538
696k
    *elem <<= shamt;
539
696k
  }
540
696k
}
bitvec::field::maybe_shift_left::<u16>
Line
Count
Source
536
5.36k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
5.36k
  if bits_of::<T>() > shamt {
538
5.36k
    *elem <<= shamt;
539
5.36k
  }
540
5.36k
}
Unexecuted instantiation: bitvec::field::maybe_shift_left::<_>
541
542
/// Shifts a value to the right, if it can support the shift amount.
543
1.68M
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
1.68M
  if bits_of::<T>() > shamt {
545
1.68M
    *elem >>= shamt;
546
1.68M
  }
547
1.68M
}
bitvec::field::maybe_shift_right::<usize>
Line
Count
Source
543
510k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
510k
  if bits_of::<T>() > shamt {
545
510k
    *elem >>= shamt;
546
510k
  }
547
510k
}
bitvec::field::maybe_shift_right::<u128>
Line
Count
Source
543
1.11M
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
1.11M
  if bits_of::<T>() > shamt {
545
1.11M
    *elem >>= shamt;
546
1.11M
  }
547
1.11M
}
bitvec::field::maybe_shift_right::<i16>
Line
Count
Source
543
63.3k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
63.3k
  if bits_of::<T>() > shamt {
545
63.3k
    *elem >>= shamt;
546
63.3k
  }
547
63.3k
}
Unexecuted instantiation: bitvec::field::maybe_shift_right::<_>
548
549
#[doc = include_str!("../doc/field/get.md")]
550
145k
fn get<T, O, I>(elem: PartialElement<Const, T, O>, shamt: u8) -> I
551
145k
where
552
145k
  T: BitStore,
553
145k
  O: BitOrder,
554
145k
  I: Integral,
555
{
556
145k
  resize::<T::Mem, I>(elem.load_value() >> shamt)
557
145k
}
Unexecuted instantiation: bitvec::field::get::<u8, bitvec::order::Lsb0, usize>
bitvec::field::get::<u8, bitvec::order::Msb0, usize>
Line
Count
Source
550
145k
fn get<T, O, I>(elem: PartialElement<Const, T, O>, shamt: u8) -> I
551
145k
where
552
145k
  T: BitStore,
553
145k
  O: BitOrder,
554
145k
  I: Integral,
555
{
556
145k
  resize::<T::Mem, I>(elem.load_value() >> shamt)
557
145k
}
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
174k
fn set<T, O, I>(mut elem: PartialElement<Mut, T, O>, value: I, shamt: u8)
561
174k
where
562
174k
  T: BitStore,
563
174k
  O: BitOrder,
564
174k
  I: Integral,
565
{
566
174k
  elem.store_value(resize::<I, T::Mem>(value) << shamt);
567
174k
}
Unexecuted instantiation: bitvec::field::set::<u8, bitvec::order::Lsb0, usize>
bitvec::field::set::<u8, bitvec::order::Msb0, usize>
Line
Count
Source
560
174k
fn set<T, O, I>(mut elem: PartialElement<Mut, T, O>, value: I, shamt: u8)
561
174k
where
562
174k
  T: BitStore,
563
174k
  O: BitOrder,
564
174k
  I: Integral,
565
{
566
174k
  elem.store_value(resize::<I, T::Mem>(value) << shamt);
567
174k
}
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
154k
fn sign<I>(elem: I, width: usize) -> I
571
154k
where I: Integral {
572
154k
  if dvl::is_unsigned::<I>() {
573
154k
    return elem;
574
0
  }
575
  //  Find the number of high bits that are not loaded.
576
0
  let shamt = bits_of::<I>() - width;
577
  //  Shift left, so that the highest loaded bit is now in the sign position.
578
0
  let shl: I = elem << shamt;
579
  //  Shift right with sign extension back to the original place.
580
0
  shl >> shamt
581
154k
}
bitvec::field::sign::<usize>
Line
Count
Source
570
108k
fn sign<I>(elem: I, width: usize) -> I
571
108k
where I: Integral {
572
108k
  if dvl::is_unsigned::<I>() {
573
108k
    return elem;
574
0
  }
575
  //  Find the number of high bits that are not loaded.
576
0
  let shamt = bits_of::<I>() - width;
577
  //  Shift left, so that the highest loaded bit is now in the sign position.
578
0
  let shl: I = elem << shamt;
579
  //  Shift right with sign extension back to the original place.
580
0
  shl >> shamt
581
108k
}
bitvec::field::sign::<u128>
Line
Count
Source
570
43.5k
fn sign<I>(elem: I, width: usize) -> I
571
43.5k
where I: Integral {
572
43.5k
  if dvl::is_unsigned::<I>() {
573
43.5k
    return elem;
574
0
  }
575
  //  Find the number of high bits that are not loaded.
576
0
  let shamt = bits_of::<I>() - width;
577
  //  Shift left, so that the highest loaded bit is now in the sign position.
578
0
  let shl: I = elem << shamt;
579
  //  Shift right with sign extension back to the original place.
580
0
  shl >> shamt
581
43.5k
}
bitvec::field::sign::<u16>
Line
Count
Source
570
2.68k
fn sign<I>(elem: I, width: usize) -> I
571
2.68k
where I: Integral {
572
2.68k
  if dvl::is_unsigned::<I>() {
573
2.68k
    return elem;
574
0
  }
575
  //  Find the number of high bits that are not loaded.
576
0
  let shamt = bits_of::<I>() - width;
577
  //  Shift left, so that the highest loaded bit is now in the sign position.
578
0
  let shl: I = elem << shamt;
579
  //  Shift right with sign extension back to the original place.
580
0
  shl >> shamt
581
2.68k
}
Unexecuted instantiation: bitvec::field::sign::<_>
582
583
#[doc = include_str!("../doc/field/resize.md")]
584
3.11M
fn resize<T, U>(value: T) -> U
585
3.11M
where
586
3.11M
  T: Integral,
587
3.11M
  U: Integral,
588
{
589
3.11M
  let mut out = U::ZERO;
590
3.11M
  let size_t = mem::size_of::<T>();
591
3.11M
  let size_u = mem::size_of::<U>();
592
593
3.11M
  unsafe {
594
3.11M
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
3.11M
  }
596
597
3.11M
  out
598
3.11M
}
bitvec::field::resize::<u8, usize>
Line
Count
Source
584
619k
fn resize<T, U>(value: T) -> U
585
619k
where
586
619k
  T: Integral,
587
619k
  U: Integral,
588
{
589
619k
  let mut out = U::ZERO;
590
619k
  let size_t = mem::size_of::<T>();
591
619k
  let size_u = mem::size_of::<U>();
592
593
619k
  unsafe {
594
619k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
619k
  }
596
597
619k
  out
598
619k
}
bitvec::field::resize::<u8, u128>
Line
Count
Source
584
696k
fn resize<T, U>(value: T) -> U
585
696k
where
586
696k
  T: Integral,
587
696k
  U: Integral,
588
{
589
696k
  let mut out = U::ZERO;
590
696k
  let size_t = mem::size_of::<T>();
591
696k
  let size_u = mem::size_of::<U>();
592
593
696k
  unsafe {
594
696k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
696k
  }
596
597
696k
  out
598
696k
}
bitvec::field::resize::<u8, u16>
Line
Count
Source
584
5.36k
fn resize<T, U>(value: T) -> U
585
5.36k
where
586
5.36k
  T: Integral,
587
5.36k
  U: Integral,
588
{
589
5.36k
  let mut out = U::ZERO;
590
5.36k
  let size_t = mem::size_of::<T>();
591
5.36k
  let size_u = mem::size_of::<U>();
592
593
5.36k
  unsafe {
594
5.36k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
5.36k
  }
596
597
5.36k
  out
598
5.36k
}
bitvec::field::resize::<usize, u8>
Line
Count
Source
584
619k
fn resize<T, U>(value: T) -> U
585
619k
where
586
619k
  T: Integral,
587
619k
  U: Integral,
588
{
589
619k
  let mut out = U::ZERO;
590
619k
  let size_t = mem::size_of::<T>();
591
619k
  let size_u = mem::size_of::<U>();
592
593
619k
  unsafe {
594
619k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
619k
  }
596
597
619k
  out
598
619k
}
bitvec::field::resize::<u128, u8>
Line
Count
Source
584
1.11M
fn resize<T, U>(value: T) -> U
585
1.11M
where
586
1.11M
  T: Integral,
587
1.11M
  U: Integral,
588
{
589
1.11M
  let mut out = U::ZERO;
590
1.11M
  let size_t = mem::size_of::<T>();
591
1.11M
  let size_u = mem::size_of::<U>();
592
593
1.11M
  unsafe {
594
1.11M
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
1.11M
  }
596
597
1.11M
  out
598
1.11M
}
bitvec::field::resize::<i16, u8>
Line
Count
Source
584
63.3k
fn resize<T, U>(value: T) -> U
585
63.3k
where
586
63.3k
  T: Integral,
587
63.3k
  U: Integral,
588
{
589
63.3k
  let mut out = U::ZERO;
590
63.3k
  let size_t = mem::size_of::<T>();
591
63.3k
  let size_u = mem::size_of::<U>();
592
593
63.3k
  unsafe {
594
63.3k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
63.3k
  }
596
597
63.3k
  out
598
63.3k
}
Unexecuted instantiation: bitvec::field::resize::<_, _>
599
600
/// Performs little-endian byte-order register resizing.
601
#[cfg(target_endian = "little")]
602
3.11M
unsafe fn resize_inner<T, U>(
603
3.11M
  src: &T,
604
3.11M
  dst: &mut U,
605
3.11M
  size_t: usize,
606
3.11M
  size_u: usize,
607
3.11M
) {
608
  //  In LE, the least-significant byte is the base address, so resizing is
609
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
3.11M
  ptr::copy_nonoverlapping(
611
3.11M
    src as *const T as *const u8,
612
3.11M
    dst as *mut U as *mut u8,
613
3.11M
    size_t.min(size_u),
614
  );
615
3.11M
}
bitvec::field::resize_inner::<u8, usize>
Line
Count
Source
602
619k
unsafe fn resize_inner<T, U>(
603
619k
  src: &T,
604
619k
  dst: &mut U,
605
619k
  size_t: usize,
606
619k
  size_u: usize,
607
619k
) {
608
  //  In LE, the least-significant byte is the base address, so resizing is
609
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
619k
  ptr::copy_nonoverlapping(
611
619k
    src as *const T as *const u8,
612
619k
    dst as *mut U as *mut u8,
613
619k
    size_t.min(size_u),
614
  );
615
619k
}
bitvec::field::resize_inner::<u8, u128>
Line
Count
Source
602
696k
unsafe fn resize_inner<T, U>(
603
696k
  src: &T,
604
696k
  dst: &mut U,
605
696k
  size_t: usize,
606
696k
  size_u: usize,
607
696k
) {
608
  //  In LE, the least-significant byte is the base address, so resizing is
609
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
696k
  ptr::copy_nonoverlapping(
611
696k
    src as *const T as *const u8,
612
696k
    dst as *mut U as *mut u8,
613
696k
    size_t.min(size_u),
614
  );
615
696k
}
bitvec::field::resize_inner::<u8, u16>
Line
Count
Source
602
5.36k
unsafe fn resize_inner<T, U>(
603
5.36k
  src: &T,
604
5.36k
  dst: &mut U,
605
5.36k
  size_t: usize,
606
5.36k
  size_u: usize,
607
5.36k
) {
608
  //  In LE, the least-significant byte is the base address, so resizing is
609
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
5.36k
  ptr::copy_nonoverlapping(
611
5.36k
    src as *const T as *const u8,
612
5.36k
    dst as *mut U as *mut u8,
613
5.36k
    size_t.min(size_u),
614
  );
615
5.36k
}
bitvec::field::resize_inner::<usize, u8>
Line
Count
Source
602
619k
unsafe fn resize_inner<T, U>(
603
619k
  src: &T,
604
619k
  dst: &mut U,
605
619k
  size_t: usize,
606
619k
  size_u: usize,
607
619k
) {
608
  //  In LE, the least-significant byte is the base address, so resizing is
609
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
619k
  ptr::copy_nonoverlapping(
611
619k
    src as *const T as *const u8,
612
619k
    dst as *mut U as *mut u8,
613
619k
    size_t.min(size_u),
614
  );
615
619k
}
bitvec::field::resize_inner::<u128, u8>
Line
Count
Source
602
1.11M
unsafe fn resize_inner<T, U>(
603
1.11M
  src: &T,
604
1.11M
  dst: &mut U,
605
1.11M
  size_t: usize,
606
1.11M
  size_u: usize,
607
1.11M
) {
608
  //  In LE, the least-significant byte is the base address, so resizing is
609
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
1.11M
  ptr::copy_nonoverlapping(
611
1.11M
    src as *const T as *const u8,
612
1.11M
    dst as *mut U as *mut u8,
613
1.11M
    size_t.min(size_u),
614
  );
615
1.11M
}
bitvec::field::resize_inner::<i16, u8>
Line
Count
Source
602
63.3k
unsafe fn resize_inner<T, U>(
603
63.3k
  src: &T,
604
63.3k
  dst: &mut U,
605
63.3k
  size_t: usize,
606
63.3k
  size_u: usize,
607
63.3k
) {
608
  //  In LE, the least-significant byte is the base address, so resizing is
609
  //  just a `memmove` into a zeroed slot, taking only the lesser width.
610
63.3k
  ptr::copy_nonoverlapping(
611
63.3k
    src as *const T as *const u8,
612
63.3k
    dst as *mut U as *mut u8,
613
63.3k
    size_t.min(size_u),
614
  );
615
63.3k
}
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
}