Coverage Report

Created: 2026-05-30 06:08

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
4.12k
  fn load_le<I>(&self) -> I
256
4.12k
  where I: Integral {
257
4.12k
    let len = self.len();
258
4.12k
    check::<I>("load", len);
259
260
4.12k
    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
4.12k
      Domain::Region { head, body, tail } => {
266
4.12k
        let mut accum = I::ZERO;
267
268
4.12k
        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
4.12k
        }
272
273
65.9k
        for elem in body.iter().rev().map(BitStore::load_value) {
274
65.9k
          maybe_shift_left(&mut accum, bits_of::<T>());
275
65.9k
          accum |= resize::<T::Mem, I>(elem);
276
65.9k
        }
277
278
4.12k
        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
4.12k
        }
284
285
4.12k
        accum
286
      },
287
    }
288
4.12k
    .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
4.12k
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<_>::{closure#0}
289
4.12k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<u128>
Line
Count
Source
255
4.12k
  fn load_le<I>(&self) -> I
256
4.12k
  where I: Integral {
257
4.12k
    let len = self.len();
258
4.12k
    check::<I>("load", len);
259
260
4.12k
    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
4.12k
      Domain::Region { head, body, tail } => {
266
4.12k
        let mut accum = I::ZERO;
267
268
4.12k
        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
4.12k
        }
272
273
65.9k
        for elem in body.iter().rev().map(BitStore::load_value) {
274
65.9k
          maybe_shift_left(&mut accum, bits_of::<T>());
275
65.9k
          accum |= resize::<T::Mem, I>(elem);
276
65.9k
        }
277
278
4.12k
        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
4.12k
        }
284
285
4.12k
        accum
286
      },
287
    }
288
4.12k
    .pipe(|elem| sign(elem, len))
289
4.12k
  }
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
187k
  fn load_be<I>(&self) -> I
294
187k
  where I: Integral {
295
187k
    let len = self.len();
296
187k
    check::<I>("load", len);
297
298
187k
    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
187k
      Domain::Region { head, body, tail } => {
304
187k
        let mut accum = I::ZERO;
305
306
187k
        if let Some(elem) = head {
307
124k
          accum = get(elem, 0);
308
124k
        }
309
310
1.39M
        for elem in body.iter().map(BitStore::load_value) {
311
1.39M
          maybe_shift_left(&mut accum, bits_of::<T>());
312
1.39M
          accum |= resize::<T::Mem, I>(elem);
313
1.39M
        }
314
315
187k
        if let Some(elem) = tail {
316
54.0k
          let shamt = elem.tail().into_inner();
317
54.0k
          maybe_shift_left(&mut accum, shamt as usize);
318
54.0k
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
133k
        }
320
321
187k
        accum
322
      },
323
    }
324
187k
    .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
133k
    .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
50.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
3.74k
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<_>::{closure#0}
325
187k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<usize>
Line
Count
Source
293
133k
  fn load_be<I>(&self) -> I
294
133k
  where I: Integral {
295
133k
    let len = self.len();
296
133k
    check::<I>("load", len);
297
298
133k
    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
133k
      Domain::Region { head, body, tail } => {
304
133k
        let mut accum = I::ZERO;
305
306
133k
        if let Some(elem) = head {
307
124k
          accum = get(elem, 0);
308
124k
        }
309
310
579k
        for elem in body.iter().map(BitStore::load_value) {
311
579k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
579k
          accum |= resize::<T::Mem, I>(elem);
313
579k
        }
314
315
133k
        if let Some(elem) = tail {
316
54.0k
          let shamt = elem.tail().into_inner();
317
54.0k
          maybe_shift_left(&mut accum, shamt as usize);
318
54.0k
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
79.5k
        }
320
321
133k
        accum
322
      },
323
    }
324
133k
    .pipe(|elem| sign(elem, len))
325
133k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u128>
Line
Count
Source
293
50.2k
  fn load_be<I>(&self) -> I
294
50.2k
  where I: Integral {
295
50.2k
    let len = self.len();
296
50.2k
    check::<I>("load", len);
297
298
50.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
50.2k
      Domain::Region { head, body, tail } => {
304
50.2k
        let mut accum = I::ZERO;
305
306
50.2k
        if let Some(elem) = head {
307
0
          accum = get(elem, 0);
308
50.2k
        }
309
310
804k
        for elem in body.iter().map(BitStore::load_value) {
311
804k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
804k
          accum |= resize::<T::Mem, I>(elem);
313
804k
        }
314
315
50.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
50.2k
        }
320
321
50.2k
        accum
322
      },
323
    }
324
50.2k
    .pipe(|elem| sign(elem, len))
325
50.2k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u16>
Line
Count
Source
293
3.74k
  fn load_be<I>(&self) -> I
294
3.74k
  where I: Integral {
295
3.74k
    let len = self.len();
296
3.74k
    check::<I>("load", len);
297
298
3.74k
    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
3.74k
      Domain::Region { head, body, tail } => {
304
3.74k
        let mut accum = I::ZERO;
305
306
3.74k
        if let Some(elem) = head {
307
0
          accum = get(elem, 0);
308
3.74k
        }
309
310
7.49k
        for elem in body.iter().map(BitStore::load_value) {
311
7.49k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
7.49k
          accum |= resize::<T::Mem, I>(elem);
313
7.49k
        }
314
315
3.74k
        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
3.74k
        }
320
321
3.74k
        accum
322
      },
323
    }
324
3.74k
    .pipe(|elem| sign(elem, len))
325
3.74k
  }
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
42.7k
  fn store_le<I>(&mut self, mut value: I)
330
42.7k
  where I: Integral {
331
42.7k
    check::<I>("store", self.len());
332
333
42.7k
    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
42.7k
      Domain::Region { head, body, tail } => {
339
42.7k
        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
42.7k
        }
345
346
684k
        for elem in body.iter_mut() {
347
684k
          elem.store_value(resize(value));
348
684k
          maybe_shift_right(&mut value, bits_of::<T>());
349
684k
        }
350
351
42.7k
        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
42.7k
        }
355
      },
356
    }
357
42.7k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_le::<u128>
Line
Count
Source
329
42.7k
  fn store_le<I>(&mut self, mut value: I)
330
42.7k
  where I: Integral {
331
42.7k
    check::<I>("store", self.len());
332
333
42.7k
    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
42.7k
      Domain::Region { head, body, tail } => {
339
42.7k
        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
42.7k
        }
345
346
684k
        for elem in body.iter_mut() {
347
684k
          elem.store_value(resize(value));
348
684k
          maybe_shift_right(&mut value, bits_of::<T>());
349
684k
        }
350
351
42.7k
        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
42.7k
        }
355
      },
356
    }
357
42.7k
  }
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
213k
  fn store_be<I>(&mut self, mut value: I)
362
213k
  where I: Integral {
363
213k
    check::<I>("store", self.len());
364
365
213k
    match self.domain_mut() {
366
7.77k
      Domain::Enclave(elem) => {
367
7.77k
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
7.77k
        set(elem, value, shamt);
369
7.77k
      },
370
206k
      Domain::Region { head, body, tail } => {
371
206k
        if let Some(elem) = tail {
372
80.4k
          let tail = elem.tail().into_inner() as usize;
373
80.4k
          let shamt = bits_of::<T>() - tail;
374
80.4k
          set(elem, value, shamt as u8);
375
80.4k
          maybe_shift_right(&mut value, tail);
376
125k
        }
377
378
1.29M
        for elem in body.iter_mut().rev() {
379
1.29M
          elem.store_value(resize(value));
380
1.29M
          maybe_shift_right(&mut value, bits_of::<T>());
381
1.29M
        }
382
383
206k
        if let Some(elem) = head {
384
125k
          set(elem, value, 0);
385
125k
        }
386
      },
387
    }
388
213k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<usize>
Line
Count
Source
361
133k
  fn store_be<I>(&mut self, mut value: I)
362
133k
  where I: Integral {
363
133k
    check::<I>("store", self.len());
364
365
133k
    match self.domain_mut() {
366
7.77k
      Domain::Enclave(elem) => {
367
7.77k
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
7.77k
        set(elem, value, shamt);
369
7.77k
      },
370
125k
      Domain::Region { head, body, tail } => {
371
125k
        if let Some(elem) = tail {
372
80.4k
          let tail = elem.tail().into_inner() as usize;
373
80.4k
          let shamt = bits_of::<T>() - tail;
374
80.4k
          set(elem, value, shamt as u8);
375
80.4k
          maybe_shift_right(&mut value, tail);
376
80.4k
        }
377
378
544k
        for elem in body.iter_mut().rev() {
379
544k
          elem.store_value(resize(value));
380
544k
          maybe_shift_right(&mut value, bits_of::<T>());
381
544k
        }
382
383
125k
        if let Some(elem) = head {
384
125k
          set(elem, value, 0);
385
125k
        }
386
      },
387
    }
388
133k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<u128>
Line
Count
Source
361
42.0k
  fn store_be<I>(&mut self, mut value: I)
362
42.0k
  where I: Integral {
363
42.0k
    check::<I>("store", self.len());
364
365
42.0k
    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
42.0k
      Domain::Region { head, body, tail } => {
371
42.0k
        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
42.0k
        }
377
378
672k
        for elem in body.iter_mut().rev() {
379
672k
          elem.store_value(resize(value));
380
672k
          maybe_shift_right(&mut value, bits_of::<T>());
381
672k
        }
382
383
42.0k
        if let Some(elem) = head {
384
0
          set(elem, value, 0);
385
42.0k
        }
386
      },
387
    }
388
42.0k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<i16>
Line
Count
Source
361
38.2k
  fn store_be<I>(&mut self, mut value: I)
362
38.2k
  where I: Integral {
363
38.2k
    check::<I>("store", self.len());
364
365
38.2k
    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
38.2k
      Domain::Region { head, body, tail } => {
371
38.2k
        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
38.2k
        }
377
378
76.5k
        for elem in body.iter_mut().rev() {
379
76.5k
          elem.store_value(resize(value));
380
76.5k
          maybe_shift_right(&mut value, bits_of::<T>());
381
76.5k
        }
382
383
38.2k
        if let Some(elem) = head {
384
0
          set(elem, value, 0);
385
38.2k
        }
386
      },
387
    }
388
38.2k
  }
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
448k
fn check<I>(action: &'static str, len: usize)
525
448k
where I: Integral {
526
448k
  assert!(
527
448k
    (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
448k
}
bitvec::field::check::<usize>
Line
Count
Source
524
267k
fn check<I>(action: &'static str, len: usize)
525
267k
where I: Integral {
526
267k
  assert!(
527
267k
    (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
267k
}
bitvec::field::check::<u128>
Line
Count
Source
524
139k
fn check<I>(action: &'static str, len: usize)
525
139k
where I: Integral {
526
139k
  assert!(
527
139k
    (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
139k
}
bitvec::field::check::<i16>
Line
Count
Source
524
38.2k
fn check<I>(action: &'static str, len: usize)
525
38.2k
where I: Integral {
526
38.2k
  assert!(
527
38.2k
    (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
38.2k
}
bitvec::field::check::<u16>
Line
Count
Source
524
3.74k
fn check<I>(action: &'static str, len: usize)
525
3.74k
where I: Integral {
526
3.74k
  assert!(
527
3.74k
    (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
3.74k
}
Unexecuted instantiation: bitvec::field::check::<_>
534
535
/// Shifts a value to the left, if it can support the shift amount.
536
1.51M
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
1.51M
  if bits_of::<T>() > shamt {
538
1.51M
    *elem <<= shamt;
539
1.51M
  }
540
1.51M
}
bitvec::field::maybe_shift_left::<usize>
Line
Count
Source
536
633k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
633k
  if bits_of::<T>() > shamt {
538
633k
    *elem <<= shamt;
539
633k
  }
540
633k
}
bitvec::field::maybe_shift_left::<u128>
Line
Count
Source
536
870k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
870k
  if bits_of::<T>() > shamt {
538
870k
    *elem <<= shamt;
539
870k
  }
540
870k
}
bitvec::field::maybe_shift_left::<u16>
Line
Count
Source
536
7.49k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
7.49k
  if bits_of::<T>() > shamt {
538
7.49k
    *elem <<= shamt;
539
7.49k
  }
540
7.49k
}
Unexecuted instantiation: bitvec::field::maybe_shift_left::<_>
541
542
/// Shifts a value to the right, if it can support the shift amount.
543
2.05M
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
2.05M
  if bits_of::<T>() > shamt {
545
2.05M
    *elem >>= shamt;
546
2.05M
  }
547
2.05M
}
bitvec::field::maybe_shift_right::<usize>
Line
Count
Source
543
624k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
624k
  if bits_of::<T>() > shamt {
545
624k
    *elem >>= shamt;
546
624k
  }
547
624k
}
bitvec::field::maybe_shift_right::<u128>
Line
Count
Source
543
1.35M
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
1.35M
  if bits_of::<T>() > shamt {
545
1.35M
    *elem >>= shamt;
546
1.35M
  }
547
1.35M
}
bitvec::field::maybe_shift_right::<i16>
Line
Count
Source
543
76.5k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
76.5k
  if bits_of::<T>() > shamt {
545
76.5k
    *elem >>= shamt;
546
76.5k
  }
547
76.5k
}
Unexecuted instantiation: bitvec::field::maybe_shift_right::<_>
548
549
#[doc = include_str!("../doc/field/get.md")]
550
178k
fn get<T, O, I>(elem: PartialElement<Const, T, O>, shamt: u8) -> I
551
178k
where
552
178k
  T: BitStore,
553
178k
  O: BitOrder,
554
178k
  I: Integral,
555
{
556
178k
  resize::<T::Mem, I>(elem.load_value() >> shamt)
557
178k
}
Unexecuted instantiation: bitvec::field::get::<u8, bitvec::order::Lsb0, usize>
bitvec::field::get::<u8, bitvec::order::Msb0, usize>
Line
Count
Source
550
178k
fn get<T, O, I>(elem: PartialElement<Const, T, O>, shamt: u8) -> I
551
178k
where
552
178k
  T: BitStore,
553
178k
  O: BitOrder,
554
178k
  I: Integral,
555
{
556
178k
  resize::<T::Mem, I>(elem.load_value() >> shamt)
557
178k
}
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
213k
fn set<T, O, I>(mut elem: PartialElement<Mut, T, O>, value: I, shamt: u8)
561
213k
where
562
213k
  T: BitStore,
563
213k
  O: BitOrder,
564
213k
  I: Integral,
565
{
566
213k
  elem.store_value(resize::<I, T::Mem>(value) << shamt);
567
213k
}
Unexecuted instantiation: bitvec::field::set::<u8, bitvec::order::Lsb0, usize>
bitvec::field::set::<u8, bitvec::order::Msb0, usize>
Line
Count
Source
560
213k
fn set<T, O, I>(mut elem: PartialElement<Mut, T, O>, value: I, shamt: u8)
561
213k
where
562
213k
  T: BitStore,
563
213k
  O: BitOrder,
564
213k
  I: Integral,
565
{
566
213k
  elem.store_value(resize::<I, T::Mem>(value) << shamt);
567
213k
}
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
191k
fn sign<I>(elem: I, width: usize) -> I
571
191k
where I: Integral {
572
191k
  if dvl::is_unsigned::<I>() {
573
191k
    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
191k
}
bitvec::field::sign::<usize>
Line
Count
Source
570
133k
fn sign<I>(elem: I, width: usize) -> I
571
133k
where I: Integral {
572
133k
  if dvl::is_unsigned::<I>() {
573
133k
    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
133k
}
bitvec::field::sign::<u128>
Line
Count
Source
570
54.3k
fn sign<I>(elem: I, width: usize) -> I
571
54.3k
where I: Integral {
572
54.3k
  if dvl::is_unsigned::<I>() {
573
54.3k
    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
54.3k
}
bitvec::field::sign::<u16>
Line
Count
Source
570
3.74k
fn sign<I>(elem: I, width: usize) -> I
571
3.74k
where I: Integral {
572
3.74k
  if dvl::is_unsigned::<I>() {
573
3.74k
    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
3.74k
}
Unexecuted instantiation: bitvec::field::sign::<_>
582
583
#[doc = include_str!("../doc/field/resize.md")]
584
3.82M
fn resize<T, U>(value: T) -> U
585
3.82M
where
586
3.82M
  T: Integral,
587
3.82M
  U: Integral,
588
{
589
3.82M
  let mut out = U::ZERO;
590
3.82M
  let size_t = mem::size_of::<T>();
591
3.82M
  let size_u = mem::size_of::<U>();
592
593
3.82M
  unsafe {
594
3.82M
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
3.82M
  }
596
597
3.82M
  out
598
3.82M
}
bitvec::field::resize::<u8, usize>
Line
Count
Source
584
758k
fn resize<T, U>(value: T) -> U
585
758k
where
586
758k
  T: Integral,
587
758k
  U: Integral,
588
{
589
758k
  let mut out = U::ZERO;
590
758k
  let size_t = mem::size_of::<T>();
591
758k
  let size_u = mem::size_of::<U>();
592
593
758k
  unsafe {
594
758k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
758k
  }
596
597
758k
  out
598
758k
}
bitvec::field::resize::<u8, u128>
Line
Count
Source
584
870k
fn resize<T, U>(value: T) -> U
585
870k
where
586
870k
  T: Integral,
587
870k
  U: Integral,
588
{
589
870k
  let mut out = U::ZERO;
590
870k
  let size_t = mem::size_of::<T>();
591
870k
  let size_u = mem::size_of::<U>();
592
593
870k
  unsafe {
594
870k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
870k
  }
596
597
870k
  out
598
870k
}
bitvec::field::resize::<u8, u16>
Line
Count
Source
584
7.49k
fn resize<T, U>(value: T) -> U
585
7.49k
where
586
7.49k
  T: Integral,
587
7.49k
  U: Integral,
588
{
589
7.49k
  let mut out = U::ZERO;
590
7.49k
  let size_t = mem::size_of::<T>();
591
7.49k
  let size_u = mem::size_of::<U>();
592
593
7.49k
  unsafe {
594
7.49k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
7.49k
  }
596
597
7.49k
  out
598
7.49k
}
bitvec::field::resize::<usize, u8>
Line
Count
Source
584
758k
fn resize<T, U>(value: T) -> U
585
758k
where
586
758k
  T: Integral,
587
758k
  U: Integral,
588
{
589
758k
  let mut out = U::ZERO;
590
758k
  let size_t = mem::size_of::<T>();
591
758k
  let size_u = mem::size_of::<U>();
592
593
758k
  unsafe {
594
758k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
758k
  }
596
597
758k
  out
598
758k
}
bitvec::field::resize::<u128, u8>
Line
Count
Source
584
1.35M
fn resize<T, U>(value: T) -> U
585
1.35M
where
586
1.35M
  T: Integral,
587
1.35M
  U: Integral,
588
{
589
1.35M
  let mut out = U::ZERO;
590
1.35M
  let size_t = mem::size_of::<T>();
591
1.35M
  let size_u = mem::size_of::<U>();
592
593
1.35M
  unsafe {
594
1.35M
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
1.35M
  }
596
597
1.35M
  out
598
1.35M
}
bitvec::field::resize::<i16, u8>
Line
Count
Source
584
76.5k
fn resize<T, U>(value: T) -> U
585
76.5k
where
586
76.5k
  T: Integral,
587
76.5k
  U: Integral,
588
{
589
76.5k
  let mut out = U::ZERO;
590
76.5k
  let size_t = mem::size_of::<T>();
591
76.5k
  let size_u = mem::size_of::<U>();
592
593
76.5k
  unsafe {
594
76.5k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
76.5k
  }
596
597
76.5k
  out
598
76.5k
}
Unexecuted instantiation: bitvec::field::resize::<_, _>
599
600
/// Performs little-endian byte-order register resizing.
601
#[cfg(target_endian = "little")]
602
3.82M
unsafe fn resize_inner<T, U>(
603
3.82M
  src: &T,
604
3.82M
  dst: &mut U,
605
3.82M
  size_t: usize,
606
3.82M
  size_u: usize,
607
3.82M
) {
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.82M
  ptr::copy_nonoverlapping(
611
3.82M
    src as *const T as *const u8,
612
3.82M
    dst as *mut U as *mut u8,
613
3.82M
    size_t.min(size_u),
614
  );
615
3.82M
}
bitvec::field::resize_inner::<u8, usize>
Line
Count
Source
602
758k
unsafe fn resize_inner<T, U>(
603
758k
  src: &T,
604
758k
  dst: &mut U,
605
758k
  size_t: usize,
606
758k
  size_u: usize,
607
758k
) {
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
758k
  ptr::copy_nonoverlapping(
611
758k
    src as *const T as *const u8,
612
758k
    dst as *mut U as *mut u8,
613
758k
    size_t.min(size_u),
614
  );
615
758k
}
bitvec::field::resize_inner::<u8, u128>
Line
Count
Source
602
870k
unsafe fn resize_inner<T, U>(
603
870k
  src: &T,
604
870k
  dst: &mut U,
605
870k
  size_t: usize,
606
870k
  size_u: usize,
607
870k
) {
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
870k
  ptr::copy_nonoverlapping(
611
870k
    src as *const T as *const u8,
612
870k
    dst as *mut U as *mut u8,
613
870k
    size_t.min(size_u),
614
  );
615
870k
}
bitvec::field::resize_inner::<u8, u16>
Line
Count
Source
602
7.49k
unsafe fn resize_inner<T, U>(
603
7.49k
  src: &T,
604
7.49k
  dst: &mut U,
605
7.49k
  size_t: usize,
606
7.49k
  size_u: usize,
607
7.49k
) {
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
7.49k
  ptr::copy_nonoverlapping(
611
7.49k
    src as *const T as *const u8,
612
7.49k
    dst as *mut U as *mut u8,
613
7.49k
    size_t.min(size_u),
614
  );
615
7.49k
}
bitvec::field::resize_inner::<usize, u8>
Line
Count
Source
602
758k
unsafe fn resize_inner<T, U>(
603
758k
  src: &T,
604
758k
  dst: &mut U,
605
758k
  size_t: usize,
606
758k
  size_u: usize,
607
758k
) {
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
758k
  ptr::copy_nonoverlapping(
611
758k
    src as *const T as *const u8,
612
758k
    dst as *mut U as *mut u8,
613
758k
    size_t.min(size_u),
614
  );
615
758k
}
bitvec::field::resize_inner::<u128, u8>
Line
Count
Source
602
1.35M
unsafe fn resize_inner<T, U>(
603
1.35M
  src: &T,
604
1.35M
  dst: &mut U,
605
1.35M
  size_t: usize,
606
1.35M
  size_u: usize,
607
1.35M
) {
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.35M
  ptr::copy_nonoverlapping(
611
1.35M
    src as *const T as *const u8,
612
1.35M
    dst as *mut U as *mut u8,
613
1.35M
    size_t.min(size_u),
614
  );
615
1.35M
}
bitvec::field::resize_inner::<i16, u8>
Line
Count
Source
602
76.5k
unsafe fn resize_inner<T, U>(
603
76.5k
  src: &T,
604
76.5k
  dst: &mut U,
605
76.5k
  size_t: usize,
606
76.5k
  size_u: usize,
607
76.5k
) {
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
76.5k
  ptr::copy_nonoverlapping(
611
76.5k
    src as *const T as *const u8,
612
76.5k
    dst as *mut U as *mut u8,
613
76.5k
    size_t.min(size_u),
614
  );
615
76.5k
}
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
}