Coverage Report

Created: 2026-09-15 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/bitvec-1.1.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.01k
  fn load_le<I>(&self) -> I
256
4.01k
  where I: Integral {
257
4.01k
    let len = self.len();
258
4.01k
    check::<I>("load", len);
259
260
4.01k
    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.01k
      Domain::Region { head, body, tail } => {
266
4.01k
        let mut accum = I::ZERO;
267
268
4.01k
        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.01k
        }
272
273
64.2k
        for elem in body.iter().rev().map(BitStore::load_value) {
274
64.2k
          maybe_shift_left(&mut accum, bits_of::<T>());
275
64.2k
          accum |= resize::<T::Mem, I>(elem);
276
64.2k
        }
277
278
4.01k
        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.01k
        }
284
285
4.01k
        accum
286
      },
287
    }
288
4.01k
    .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.01k
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<_>::{closure#0}
289
4.01k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<u128>
Line
Count
Source
255
4.01k
  fn load_le<I>(&self) -> I
256
4.01k
  where I: Integral {
257
4.01k
    let len = self.len();
258
4.01k
    check::<I>("load", len);
259
260
4.01k
    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.01k
      Domain::Region { head, body, tail } => {
266
4.01k
        let mut accum = I::ZERO;
267
268
4.01k
        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.01k
        }
272
273
64.2k
        for elem in body.iter().rev().map(BitStore::load_value) {
274
64.2k
          maybe_shift_left(&mut accum, bits_of::<T>());
275
64.2k
          accum |= resize::<T::Mem, I>(elem);
276
64.2k
        }
277
278
4.01k
        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.01k
        }
284
285
4.01k
        accum
286
      },
287
    }
288
4.01k
    .pipe(|elem| sign(elem, len))
289
4.01k
  }
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
174k
  fn load_be<I>(&self) -> I
294
174k
  where I: Integral {
295
174k
    let len = self.len();
296
174k
    check::<I>("load", len);
297
298
174k
    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
174k
      Domain::Region { head, body, tail } => {
304
174k
        let mut accum = I::ZERO;
305
306
174k
        if let Some(elem) = head {
307
114k
          accum = get(elem, 0);
308
114k
        }
309
310
1.29M
        for elem in body.iter().map(BitStore::load_value) {
311
1.29M
          maybe_shift_left(&mut accum, bits_of::<T>());
312
1.29M
          accum |= resize::<T::Mem, I>(elem);
313
1.29M
        }
314
315
174k
        if let Some(elem) = tail {
316
50.6k
          let shamt = elem.tail().into_inner();
317
50.6k
          maybe_shift_left(&mut accum, shamt as usize);
318
50.6k
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
123k
        }
320
321
174k
        accum
322
      },
323
    }
324
174k
    .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
123k
    .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
46.9k
    .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.69k
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<_>::{closure#0}
325
174k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<usize>
Line
Count
Source
293
123k
  fn load_be<I>(&self) -> I
294
123k
  where I: Integral {
295
123k
    let len = self.len();
296
123k
    check::<I>("load", len);
297
298
123k
    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
123k
      Domain::Region { head, body, tail } => {
304
123k
        let mut accum = I::ZERO;
305
306
123k
        if let Some(elem) = head {
307
114k
          accum = get(elem, 0);
308
114k
        }
309
310
531k
        for elem in body.iter().map(BitStore::load_value) {
311
531k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
531k
          accum |= resize::<T::Mem, I>(elem);
313
531k
        }
314
315
123k
        if let Some(elem) = tail {
316
50.6k
          let shamt = elem.tail().into_inner();
317
50.6k
          maybe_shift_left(&mut accum, shamt as usize);
318
50.6k
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
72.8k
        }
320
321
123k
        accum
322
      },
323
    }
324
123k
    .pipe(|elem| sign(elem, len))
325
123k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u128>
Line
Count
Source
293
46.9k
  fn load_be<I>(&self) -> I
294
46.9k
  where I: Integral {
295
46.9k
    let len = self.len();
296
46.9k
    check::<I>("load", len);
297
298
46.9k
    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
46.9k
      Domain::Region { head, body, tail } => {
304
46.9k
        let mut accum = I::ZERO;
305
306
46.9k
        if let Some(elem) = head {
307
0
          accum = get(elem, 0);
308
46.9k
        }
309
310
751k
        for elem in body.iter().map(BitStore::load_value) {
311
751k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
751k
          accum |= resize::<T::Mem, I>(elem);
313
751k
        }
314
315
46.9k
        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
46.9k
        }
320
321
46.9k
        accum
322
      },
323
    }
324
46.9k
    .pipe(|elem| sign(elem, len))
325
46.9k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u16>
Line
Count
Source
293
3.69k
  fn load_be<I>(&self) -> I
294
3.69k
  where I: Integral {
295
3.69k
    let len = self.len();
296
3.69k
    check::<I>("load", len);
297
298
3.69k
    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.69k
      Domain::Region { head, body, tail } => {
304
3.69k
        let mut accum = I::ZERO;
305
306
3.69k
        if let Some(elem) = head {
307
0
          accum = get(elem, 0);
308
3.69k
        }
309
310
7.38k
        for elem in body.iter().map(BitStore::load_value) {
311
7.38k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
7.38k
          accum |= resize::<T::Mem, I>(elem);
313
7.38k
        }
314
315
3.69k
        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.69k
        }
320
321
3.69k
        accum
322
      },
323
    }
324
3.69k
    .pipe(|elem| sign(elem, len))
325
3.69k
  }
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
39.5k
  fn store_le<I>(&mut self, mut value: I)
330
39.5k
  where I: Integral {
331
39.5k
    check::<I>("store", self.len());
332
333
39.5k
    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
39.5k
      Domain::Region { head, body, tail } => {
339
39.5k
        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
39.5k
        }
345
346
633k
        for elem in body.iter_mut() {
347
633k
          elem.store_value(resize(value));
348
633k
          maybe_shift_right(&mut value, bits_of::<T>());
349
633k
        }
350
351
39.5k
        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
39.5k
        }
355
      },
356
    }
357
39.5k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_le::<u128>
Line
Count
Source
329
39.5k
  fn store_le<I>(&mut self, mut value: I)
330
39.5k
  where I: Integral {
331
39.5k
    check::<I>("store", self.len());
332
333
39.5k
    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
39.5k
      Domain::Region { head, body, tail } => {
339
39.5k
        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
39.5k
        }
345
346
633k
        for elem in body.iter_mut() {
347
633k
          elem.store_value(resize(value));
348
633k
          maybe_shift_right(&mut value, bits_of::<T>());
349
633k
        }
350
351
39.5k
        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
39.5k
        }
355
      },
356
    }
357
39.5k
  }
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
196k
  fn store_be<I>(&mut self, mut value: I)
362
196k
  where I: Integral {
363
196k
    check::<I>("store", self.len());
364
365
196k
    match self.domain_mut() {
366
7.64k
      Domain::Enclave(elem) => {
367
7.64k
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
7.64k
        set(elem, value, shamt);
369
7.64k
      },
370
189k
      Domain::Region { head, body, tail } => {
371
189k
        if let Some(elem) = tail {
372
73.8k
          let tail = elem.tail().into_inner() as usize;
373
73.8k
          let shamt = bits_of::<T>() - tail;
374
73.8k
          set(elem, value, shamt as u8);
375
73.8k
          maybe_shift_right(&mut value, tail);
376
115k
        }
377
378
1.18M
        for elem in body.iter_mut().rev() {
379
1.18M
          elem.store_value(resize(value));
380
1.18M
          maybe_shift_right(&mut value, bits_of::<T>());
381
1.18M
        }
382
383
189k
        if let Some(elem) = head {
384
115k
          set(elem, value, 0);
385
115k
        }
386
      },
387
    }
388
196k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<usize>
Line
Count
Source
361
123k
  fn store_be<I>(&mut self, mut value: I)
362
123k
  where I: Integral {
363
123k
    check::<I>("store", self.len());
364
365
123k
    match self.domain_mut() {
366
7.64k
      Domain::Enclave(elem) => {
367
7.64k
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
7.64k
        set(elem, value, shamt);
369
7.64k
      },
370
115k
      Domain::Region { head, body, tail } => {
371
115k
        if let Some(elem) = tail {
372
73.8k
          let tail = elem.tail().into_inner() as usize;
373
73.8k
          let shamt = bits_of::<T>() - tail;
374
73.8k
          set(elem, value, shamt as u8);
375
73.8k
          maybe_shift_right(&mut value, tail);
376
73.8k
        }
377
378
499k
        for elem in body.iter_mut().rev() {
379
499k
          elem.store_value(resize(value));
380
499k
          maybe_shift_right(&mut value, bits_of::<T>());
381
499k
        }
382
383
115k
        if let Some(elem) = head {
384
115k
          set(elem, value, 0);
385
115k
        }
386
      },
387
    }
388
123k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<u128>
Line
Count
Source
361
38.5k
  fn store_be<I>(&mut self, mut value: I)
362
38.5k
  where I: Integral {
363
38.5k
    check::<I>("store", self.len());
364
365
38.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
38.5k
      Domain::Region { head, body, tail } => {
371
38.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
38.5k
        }
377
378
617k
        for elem in body.iter_mut().rev() {
379
617k
          elem.store_value(resize(value));
380
617k
          maybe_shift_right(&mut value, bits_of::<T>());
381
617k
        }
382
383
38.5k
        if let Some(elem) = head {
384
0
          set(elem, value, 0);
385
38.5k
        }
386
      },
387
    }
388
38.5k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<i16>
Line
Count
Source
361
34.8k
  fn store_be<I>(&mut self, mut value: I)
362
34.8k
  where I: Integral {
363
34.8k
    check::<I>("store", self.len());
364
365
34.8k
    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.8k
      Domain::Region { head, body, tail } => {
371
34.8k
        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.8k
        }
377
378
69.7k
        for elem in body.iter_mut().rev() {
379
69.7k
          elem.store_value(resize(value));
380
69.7k
          maybe_shift_right(&mut value, bits_of::<T>());
381
69.7k
        }
382
383
34.8k
        if let Some(elem) = head {
384
0
          set(elem, value, 0);
385
34.8k
        }
386
      },
387
    }
388
34.8k
  }
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
414k
fn check<I>(action: &'static str, len: usize)
525
414k
where I: Integral {
526
414k
  assert!(
527
414k
    (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
414k
}
bitvec::field::check::<usize>
Line
Count
Source
524
246k
fn check<I>(action: &'static str, len: usize)
525
246k
where I: Integral {
526
246k
  assert!(
527
246k
    (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
246k
}
bitvec::field::check::<u128>
Line
Count
Source
524
129k
fn check<I>(action: &'static str, len: usize)
525
129k
where I: Integral {
526
129k
  assert!(
527
129k
    (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
129k
}
bitvec::field::check::<i16>
Line
Count
Source
524
34.8k
fn check<I>(action: &'static str, len: usize)
525
34.8k
where I: Integral {
526
34.8k
  assert!(
527
34.8k
    (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
34.8k
}
bitvec::field::check::<u16>
Line
Count
Source
524
3.69k
fn check<I>(action: &'static str, len: usize)
525
3.69k
where I: Integral {
526
3.69k
  assert!(
527
3.69k
    (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.69k
}
Unexecuted instantiation: bitvec::field::check::<_>
534
535
/// Shifts a value to the left, if it can support the shift amount.
536
1.40M
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
1.40M
  if bits_of::<T>() > shamt {
538
1.40M
    *elem <<= shamt;
539
1.40M
  }
540
1.40M
}
bitvec::field::maybe_shift_left::<usize>
Line
Count
Source
536
582k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
582k
  if bits_of::<T>() > shamt {
538
582k
    *elem <<= shamt;
539
582k
  }
540
582k
}
bitvec::field::maybe_shift_left::<u128>
Line
Count
Source
536
815k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
815k
  if bits_of::<T>() > shamt {
538
815k
    *elem <<= shamt;
539
815k
  }
540
815k
}
bitvec::field::maybe_shift_left::<u16>
Line
Count
Source
536
7.38k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
7.38k
  if bits_of::<T>() > shamt {
538
7.38k
    *elem <<= shamt;
539
7.38k
  }
540
7.38k
}
Unexecuted instantiation: bitvec::field::maybe_shift_left::<_>
541
542
/// Shifts a value to the right, if it can support the shift amount.
543
1.89M
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
1.89M
  if bits_of::<T>() > shamt {
545
1.89M
    *elem >>= shamt;
546
1.89M
  }
547
1.89M
}
bitvec::field::maybe_shift_right::<usize>
Line
Count
Source
543
573k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
573k
  if bits_of::<T>() > shamt {
545
573k
    *elem >>= shamt;
546
573k
  }
547
573k
}
bitvec::field::maybe_shift_right::<u128>
Line
Count
Source
543
1.25M
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
1.25M
  if bits_of::<T>() > shamt {
545
1.25M
    *elem >>= shamt;
546
1.25M
  }
547
1.25M
}
bitvec::field::maybe_shift_right::<i16>
Line
Count
Source
543
69.7k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
69.7k
  if bits_of::<T>() > shamt {
545
69.7k
    *elem >>= shamt;
546
69.7k
  }
547
69.7k
}
Unexecuted instantiation: bitvec::field::maybe_shift_right::<_>
548
549
#[doc = include_str!("../doc/field/get.md")]
550
165k
fn get<T, O, I>(elem: PartialElement<Const, T, O>, shamt: u8) -> I
551
165k
where
552
165k
  T: BitStore,
553
165k
  O: BitOrder,
554
165k
  I: Integral,
555
{
556
165k
  resize::<T::Mem, I>(elem.load_value() >> shamt)
557
165k
}
Unexecuted instantiation: bitvec::field::get::<u8, bitvec::order::Lsb0, usize>
bitvec::field::get::<u8, bitvec::order::Msb0, usize>
Line
Count
Source
550
165k
fn get<T, O, I>(elem: PartialElement<Const, T, O>, shamt: u8) -> I
551
165k
where
552
165k
  T: BitStore,
553
165k
  O: BitOrder,
554
165k
  I: Integral,
555
{
556
165k
  resize::<T::Mem, I>(elem.load_value() >> shamt)
557
165k
}
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
197k
fn set<T, O, I>(mut elem: PartialElement<Mut, T, O>, value: I, shamt: u8)
561
197k
where
562
197k
  T: BitStore,
563
197k
  O: BitOrder,
564
197k
  I: Integral,
565
{
566
197k
  elem.store_value(resize::<I, T::Mem>(value) << shamt);
567
197k
}
Unexecuted instantiation: bitvec::field::set::<u8, bitvec::order::Lsb0, usize>
bitvec::field::set::<u8, bitvec::order::Msb0, usize>
Line
Count
Source
560
197k
fn set<T, O, I>(mut elem: PartialElement<Mut, T, O>, value: I, shamt: u8)
561
197k
where
562
197k
  T: BitStore,
563
197k
  O: BitOrder,
564
197k
  I: Integral,
565
{
566
197k
  elem.store_value(resize::<I, T::Mem>(value) << shamt);
567
197k
}
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
178k
fn sign<I>(elem: I, width: usize) -> I
571
178k
where I: Integral {
572
178k
  if dvl::is_unsigned::<I>() {
573
178k
    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
178k
}
bitvec::field::sign::<usize>
Line
Count
Source
570
123k
fn sign<I>(elem: I, width: usize) -> I
571
123k
where I: Integral {
572
123k
  if dvl::is_unsigned::<I>() {
573
123k
    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
123k
}
bitvec::field::sign::<u128>
Line
Count
Source
570
50.9k
fn sign<I>(elem: I, width: usize) -> I
571
50.9k
where I: Integral {
572
50.9k
  if dvl::is_unsigned::<I>() {
573
50.9k
    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
50.9k
}
bitvec::field::sign::<u16>
Line
Count
Source
570
3.69k
fn sign<I>(elem: I, width: usize) -> I
571
3.69k
where I: Integral {
572
3.69k
  if dvl::is_unsigned::<I>() {
573
3.69k
    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.69k
}
Unexecuted instantiation: bitvec::field::sign::<_>
582
583
#[doc = include_str!("../doc/field/resize.md")]
584
3.53M
fn resize<T, U>(value: T) -> U
585
3.53M
where
586
3.53M
  T: Integral,
587
3.53M
  U: Integral,
588
{
589
3.53M
  let mut out = U::ZERO;
590
3.53M
  let size_t = mem::size_of::<T>();
591
3.53M
  let size_u = mem::size_of::<U>();
592
593
3.53M
  unsafe {
594
3.53M
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
3.53M
  }
596
597
3.53M
  out
598
3.53M
}
bitvec::field::resize::<u8, usize>
Line
Count
Source
584
697k
fn resize<T, U>(value: T) -> U
585
697k
where
586
697k
  T: Integral,
587
697k
  U: Integral,
588
{
589
697k
  let mut out = U::ZERO;
590
697k
  let size_t = mem::size_of::<T>();
591
697k
  let size_u = mem::size_of::<U>();
592
593
697k
  unsafe {
594
697k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
697k
  }
596
597
697k
  out
598
697k
}
bitvec::field::resize::<u8, u128>
Line
Count
Source
584
815k
fn resize<T, U>(value: T) -> U
585
815k
where
586
815k
  T: Integral,
587
815k
  U: Integral,
588
{
589
815k
  let mut out = U::ZERO;
590
815k
  let size_t = mem::size_of::<T>();
591
815k
  let size_u = mem::size_of::<U>();
592
593
815k
  unsafe {
594
815k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
815k
  }
596
597
815k
  out
598
815k
}
bitvec::field::resize::<u8, u16>
Line
Count
Source
584
7.38k
fn resize<T, U>(value: T) -> U
585
7.38k
where
586
7.38k
  T: Integral,
587
7.38k
  U: Integral,
588
{
589
7.38k
  let mut out = U::ZERO;
590
7.38k
  let size_t = mem::size_of::<T>();
591
7.38k
  let size_u = mem::size_of::<U>();
592
593
7.38k
  unsafe {
594
7.38k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
7.38k
  }
596
597
7.38k
  out
598
7.38k
}
bitvec::field::resize::<usize, u8>
Line
Count
Source
584
697k
fn resize<T, U>(value: T) -> U
585
697k
where
586
697k
  T: Integral,
587
697k
  U: Integral,
588
{
589
697k
  let mut out = U::ZERO;
590
697k
  let size_t = mem::size_of::<T>();
591
697k
  let size_u = mem::size_of::<U>();
592
593
697k
  unsafe {
594
697k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
697k
  }
596
597
697k
  out
598
697k
}
bitvec::field::resize::<u128, u8>
Line
Count
Source
584
1.25M
fn resize<T, U>(value: T) -> U
585
1.25M
where
586
1.25M
  T: Integral,
587
1.25M
  U: Integral,
588
{
589
1.25M
  let mut out = U::ZERO;
590
1.25M
  let size_t = mem::size_of::<T>();
591
1.25M
  let size_u = mem::size_of::<U>();
592
593
1.25M
  unsafe {
594
1.25M
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
1.25M
  }
596
597
1.25M
  out
598
1.25M
}
bitvec::field::resize::<i16, u8>
Line
Count
Source
584
69.7k
fn resize<T, U>(value: T) -> U
585
69.7k
where
586
69.7k
  T: Integral,
587
69.7k
  U: Integral,
588
{
589
69.7k
  let mut out = U::ZERO;
590
69.7k
  let size_t = mem::size_of::<T>();
591
69.7k
  let size_u = mem::size_of::<U>();
592
593
69.7k
  unsafe {
594
69.7k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
69.7k
  }
596
597
69.7k
  out
598
69.7k
}
Unexecuted instantiation: bitvec::field::resize::<_, _>
599
600
/// Performs little-endian byte-order register resizing.
601
#[cfg(target_endian = "little")]
602
3.53M
unsafe fn resize_inner<T, U>(
603
3.53M
  src: &T,
604
3.53M
  dst: &mut U,
605
3.53M
  size_t: usize,
606
3.53M
  size_u: usize,
607
3.53M
) {
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.53M
  ptr::copy_nonoverlapping(
611
3.53M
    src as *const T as *const u8,
612
3.53M
    dst as *mut U as *mut u8,
613
3.53M
    size_t.min(size_u),
614
  );
615
3.53M
}
bitvec::field::resize_inner::<u8, usize>
Line
Count
Source
602
697k
unsafe fn resize_inner<T, U>(
603
697k
  src: &T,
604
697k
  dst: &mut U,
605
697k
  size_t: usize,
606
697k
  size_u: usize,
607
697k
) {
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
697k
  ptr::copy_nonoverlapping(
611
697k
    src as *const T as *const u8,
612
697k
    dst as *mut U as *mut u8,
613
697k
    size_t.min(size_u),
614
  );
615
697k
}
bitvec::field::resize_inner::<u8, u128>
Line
Count
Source
602
815k
unsafe fn resize_inner<T, U>(
603
815k
  src: &T,
604
815k
  dst: &mut U,
605
815k
  size_t: usize,
606
815k
  size_u: usize,
607
815k
) {
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
815k
  ptr::copy_nonoverlapping(
611
815k
    src as *const T as *const u8,
612
815k
    dst as *mut U as *mut u8,
613
815k
    size_t.min(size_u),
614
  );
615
815k
}
bitvec::field::resize_inner::<u8, u16>
Line
Count
Source
602
7.38k
unsafe fn resize_inner<T, U>(
603
7.38k
  src: &T,
604
7.38k
  dst: &mut U,
605
7.38k
  size_t: usize,
606
7.38k
  size_u: usize,
607
7.38k
) {
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.38k
  ptr::copy_nonoverlapping(
611
7.38k
    src as *const T as *const u8,
612
7.38k
    dst as *mut U as *mut u8,
613
7.38k
    size_t.min(size_u),
614
  );
615
7.38k
}
bitvec::field::resize_inner::<usize, u8>
Line
Count
Source
602
697k
unsafe fn resize_inner<T, U>(
603
697k
  src: &T,
604
697k
  dst: &mut U,
605
697k
  size_t: usize,
606
697k
  size_u: usize,
607
697k
) {
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
697k
  ptr::copy_nonoverlapping(
611
697k
    src as *const T as *const u8,
612
697k
    dst as *mut U as *mut u8,
613
697k
    size_t.min(size_u),
614
  );
615
697k
}
bitvec::field::resize_inner::<u128, u8>
Line
Count
Source
602
1.25M
unsafe fn resize_inner<T, U>(
603
1.25M
  src: &T,
604
1.25M
  dst: &mut U,
605
1.25M
  size_t: usize,
606
1.25M
  size_u: usize,
607
1.25M
) {
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.25M
  ptr::copy_nonoverlapping(
611
1.25M
    src as *const T as *const u8,
612
1.25M
    dst as *mut U as *mut u8,
613
1.25M
    size_t.min(size_u),
614
  );
615
1.25M
}
bitvec::field::resize_inner::<i16, u8>
Line
Count
Source
602
69.7k
unsafe fn resize_inner<T, U>(
603
69.7k
  src: &T,
604
69.7k
  dst: &mut U,
605
69.7k
  size_t: usize,
606
69.7k
  size_u: usize,
607
69.7k
) {
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
69.7k
  ptr::copy_nonoverlapping(
611
69.7k
    src as *const T as *const u8,
612
69.7k
    dst as *mut U as *mut u8,
613
69.7k
    size_t.min(size_u),
614
  );
615
69.7k
}
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
}