Coverage Report

Created: 2025-12-20 06:45

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
3.33k
  fn load_le<I>(&self) -> I
256
3.33k
  where I: Integral {
257
3.33k
    let len = self.len();
258
3.33k
    check::<I>("load", len);
259
260
3.33k
    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
3.33k
      Domain::Region { head, body, tail } => {
266
3.33k
        let mut accum = I::ZERO;
267
268
3.33k
        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
3.33k
        }
272
273
53.3k
        for elem in body.iter().rev().map(BitStore::load_value) {
274
53.3k
          maybe_shift_left(&mut accum, bits_of::<T>());
275
53.3k
          accum |= resize::<T::Mem, I>(elem);
276
53.3k
        }
277
278
3.33k
        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
3.33k
        }
284
285
3.33k
        accum
286
      },
287
    }
288
3.33k
    .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
3.33k
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<_>::{closure#0}
289
3.33k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_le::<u128>
Line
Count
Source
255
3.33k
  fn load_le<I>(&self) -> I
256
3.33k
  where I: Integral {
257
3.33k
    let len = self.len();
258
3.33k
    check::<I>("load", len);
259
260
3.33k
    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
3.33k
      Domain::Region { head, body, tail } => {
266
3.33k
        let mut accum = I::ZERO;
267
268
3.33k
        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
3.33k
        }
272
273
53.3k
        for elem in body.iter().rev().map(BitStore::load_value) {
274
53.3k
          maybe_shift_left(&mut accum, bits_of::<T>());
275
53.3k
          accum |= resize::<T::Mem, I>(elem);
276
53.3k
        }
277
278
3.33k
        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
3.33k
        }
284
285
3.33k
        accum
286
      },
287
    }
288
3.33k
    .pipe(|elem| sign(elem, len))
289
3.33k
  }
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
157k
  fn load_be<I>(&self) -> I
294
157k
  where I: Integral {
295
157k
    let len = self.len();
296
157k
    check::<I>("load", len);
297
298
157k
    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
157k
      Domain::Region { head, body, tail } => {
304
157k
        let mut accum = I::ZERO;
305
306
157k
        if let Some(elem) = head {
307
103k
          accum = get(elem, 0);
308
103k
        }
309
310
1.16M
        for elem in body.iter().map(BitStore::load_value) {
311
1.16M
          maybe_shift_left(&mut accum, bits_of::<T>());
312
1.16M
          accum |= resize::<T::Mem, I>(elem);
313
1.16M
        }
314
315
157k
        if let Some(elem) = tail {
316
45.3k
          let shamt = elem.tail().into_inner();
317
45.3k
          maybe_shift_left(&mut accum, shamt as usize);
318
45.3k
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
111k
        }
320
321
157k
        accum
322
      },
323
    }
324
157k
    .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
111k
    .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
42.3k
    .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.00k
    .pipe(|elem| sign(elem, len))
Unexecuted instantiation: <bitvec::slice::BitSlice<_, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<_>::{closure#0}
325
157k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<usize>
Line
Count
Source
293
111k
  fn load_be<I>(&self) -> I
294
111k
  where I: Integral {
295
111k
    let len = self.len();
296
111k
    check::<I>("load", len);
297
298
111k
    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
111k
      Domain::Region { head, body, tail } => {
304
111k
        let mut accum = I::ZERO;
305
306
111k
        if let Some(elem) = head {
307
103k
          accum = get(elem, 0);
308
103k
        }
309
310
481k
        for elem in body.iter().map(BitStore::load_value) {
311
481k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
481k
          accum |= resize::<T::Mem, I>(elem);
313
481k
        }
314
315
111k
        if let Some(elem) = tail {
316
45.3k
          let shamt = elem.tail().into_inner();
317
45.3k
          maybe_shift_left(&mut accum, shamt as usize);
318
45.3k
          accum |= get::<_, _, I>(elem, bits_of::<T>() as u8 - shamt);
319
66.2k
        }
320
321
111k
        accum
322
      },
323
    }
324
111k
    .pipe(|elem| sign(elem, len))
325
111k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u128>
Line
Count
Source
293
42.3k
  fn load_be<I>(&self) -> I
294
42.3k
  where I: Integral {
295
42.3k
    let len = self.len();
296
42.3k
    check::<I>("load", len);
297
298
42.3k
    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
42.3k
      Domain::Region { head, body, tail } => {
304
42.3k
        let mut accum = I::ZERO;
305
306
42.3k
        if let Some(elem) = head {
307
0
          accum = get(elem, 0);
308
42.3k
        }
309
310
677k
        for elem in body.iter().map(BitStore::load_value) {
311
677k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
677k
          accum |= resize::<T::Mem, I>(elem);
313
677k
        }
314
315
42.3k
        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
42.3k
        }
320
321
42.3k
        accum
322
      },
323
    }
324
42.3k
    .pipe(|elem| sign(elem, len))
325
42.3k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::load_be::<u16>
Line
Count
Source
293
3.00k
  fn load_be<I>(&self) -> I
294
3.00k
  where I: Integral {
295
3.00k
    let len = self.len();
296
3.00k
    check::<I>("load", len);
297
298
3.00k
    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.00k
      Domain::Region { head, body, tail } => {
304
3.00k
        let mut accum = I::ZERO;
305
306
3.00k
        if let Some(elem) = head {
307
0
          accum = get(elem, 0);
308
3.00k
        }
309
310
6.00k
        for elem in body.iter().map(BitStore::load_value) {
311
6.00k
          maybe_shift_left(&mut accum, bits_of::<T>());
312
6.00k
          accum |= resize::<T::Mem, I>(elem);
313
6.00k
        }
314
315
3.00k
        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.00k
        }
320
321
3.00k
        accum
322
      },
323
    }
324
3.00k
    .pipe(|elem| sign(elem, len))
325
3.00k
  }
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
36.3k
  fn store_le<I>(&mut self, mut value: I)
330
36.3k
  where I: Integral {
331
36.3k
    check::<I>("store", self.len());
332
333
36.3k
    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
36.3k
      Domain::Region { head, body, tail } => {
339
36.3k
        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
36.3k
        }
345
346
581k
        for elem in body.iter_mut() {
347
581k
          elem.store_value(resize(value));
348
581k
          maybe_shift_right(&mut value, bits_of::<T>());
349
581k
        }
350
351
36.3k
        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
36.3k
        }
355
      },
356
    }
357
36.3k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_le::<u128>
Line
Count
Source
329
36.3k
  fn store_le<I>(&mut self, mut value: I)
330
36.3k
  where I: Integral {
331
36.3k
    check::<I>("store", self.len());
332
333
36.3k
    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
36.3k
      Domain::Region { head, body, tail } => {
339
36.3k
        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
36.3k
        }
345
346
581k
        for elem in body.iter_mut() {
347
581k
          elem.store_value(resize(value));
348
581k
          maybe_shift_right(&mut value, bits_of::<T>());
349
581k
        }
350
351
36.3k
        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
36.3k
        }
355
      },
356
    }
357
36.3k
  }
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
178k
  fn store_be<I>(&mut self, mut value: I)
362
178k
  where I: Integral {
363
178k
    check::<I>("store", self.len());
364
365
178k
    match self.domain_mut() {
366
7.22k
      Domain::Enclave(elem) => {
367
7.22k
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
7.22k
        set(elem, value, shamt);
369
7.22k
      },
370
171k
      Domain::Region { head, body, tail } => {
371
171k
        if let Some(elem) = tail {
372
66.7k
          let tail = elem.tail().into_inner() as usize;
373
66.7k
          let shamt = bits_of::<T>() - tail;
374
66.7k
          set(elem, value, shamt as u8);
375
66.7k
          maybe_shift_right(&mut value, tail);
376
104k
        }
377
378
1.07M
        for elem in body.iter_mut().rev() {
379
1.07M
          elem.store_value(resize(value));
380
1.07M
          maybe_shift_right(&mut value, bits_of::<T>());
381
1.07M
        }
382
383
171k
        if let Some(elem) = head {
384
104k
          set(elem, value, 0);
385
104k
        }
386
      },
387
    }
388
178k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<usize>
Line
Count
Source
361
111k
  fn store_be<I>(&mut self, mut value: I)
362
111k
  where I: Integral {
363
111k
    check::<I>("store", self.len());
364
365
111k
    match self.domain_mut() {
366
7.22k
      Domain::Enclave(elem) => {
367
7.22k
        let shamt = bits_of::<T>() as u8 - elem.tail().into_inner();
368
7.22k
        set(elem, value, shamt);
369
7.22k
      },
370
104k
      Domain::Region { head, body, tail } => {
371
104k
        if let Some(elem) = tail {
372
66.7k
          let tail = elem.tail().into_inner() as usize;
373
66.7k
          let shamt = bits_of::<T>() - tail;
374
66.7k
          set(elem, value, shamt as u8);
375
66.7k
          maybe_shift_right(&mut value, tail);
376
66.7k
        }
377
378
452k
        for elem in body.iter_mut().rev() {
379
452k
          elem.store_value(resize(value));
380
452k
          maybe_shift_right(&mut value, bits_of::<T>());
381
452k
        }
382
383
104k
        if let Some(elem) = head {
384
104k
          set(elem, value, 0);
385
104k
        }
386
      },
387
    }
388
111k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<u128>
Line
Count
Source
361
34.9k
  fn store_be<I>(&mut self, mut value: I)
362
34.9k
  where I: Integral {
363
34.9k
    check::<I>("store", self.len());
364
365
34.9k
    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.9k
      Domain::Region { head, body, tail } => {
371
34.9k
        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.9k
        }
377
378
559k
        for elem in body.iter_mut().rev() {
379
559k
          elem.store_value(resize(value));
380
559k
          maybe_shift_right(&mut value, bits_of::<T>());
381
559k
        }
382
383
34.9k
        if let Some(elem) = head {
384
0
          set(elem, value, 0);
385
34.9k
        }
386
      },
387
    }
388
34.9k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0> as bitvec::field::BitField>::store_be::<i16>
Line
Count
Source
361
32.0k
  fn store_be<I>(&mut self, mut value: I)
362
32.0k
  where I: Integral {
363
32.0k
    check::<I>("store", self.len());
364
365
32.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
32.0k
      Domain::Region { head, body, tail } => {
371
32.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
32.0k
        }
377
378
64.0k
        for elem in body.iter_mut().rev() {
379
64.0k
          elem.store_value(resize(value));
380
64.0k
          maybe_shift_right(&mut value, bits_of::<T>());
381
64.0k
        }
382
383
32.0k
        if let Some(elem) = head {
384
0
          set(elem, value, 0);
385
32.0k
        }
386
      },
387
    }
388
32.0k
  }
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
375k
fn check<I>(action: &'static str, len: usize)
525
375k
where I: Integral {
526
375k
  assert!(
527
375k
    (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
375k
}
bitvec::field::check::<usize>
Line
Count
Source
524
223k
fn check<I>(action: &'static str, len: usize)
525
223k
where I: Integral {
526
223k
  assert!(
527
223k
    (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
223k
}
bitvec::field::check::<u128>
Line
Count
Source
524
117k
fn check<I>(action: &'static str, len: usize)
525
117k
where I: Integral {
526
117k
  assert!(
527
117k
    (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
117k
}
bitvec::field::check::<i16>
Line
Count
Source
524
32.0k
fn check<I>(action: &'static str, len: usize)
525
32.0k
where I: Integral {
526
32.0k
  assert!(
527
32.0k
    (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
32.0k
}
bitvec::field::check::<u16>
Line
Count
Source
524
3.00k
fn check<I>(action: &'static str, len: usize)
525
3.00k
where I: Integral {
526
3.00k
  assert!(
527
3.00k
    (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.00k
}
Unexecuted instantiation: bitvec::field::check::<_>
534
535
/// Shifts a value to the left, if it can support the shift amount.
536
1.26M
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
1.26M
  if bits_of::<T>() > shamt {
538
1.26M
    *elem <<= shamt;
539
1.26M
  }
540
1.26M
}
bitvec::field::maybe_shift_left::<usize>
Line
Count
Source
536
527k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
527k
  if bits_of::<T>() > shamt {
538
527k
    *elem <<= shamt;
539
527k
  }
540
527k
}
bitvec::field::maybe_shift_left::<u128>
Line
Count
Source
536
731k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
731k
  if bits_of::<T>() > shamt {
538
731k
    *elem <<= shamt;
539
731k
  }
540
731k
}
bitvec::field::maybe_shift_left::<u16>
Line
Count
Source
536
6.00k
fn maybe_shift_left<T: Integral>(elem: &mut T, shamt: usize) {
537
6.00k
  if bits_of::<T>() > shamt {
538
6.00k
    *elem <<= shamt;
539
6.00k
  }
540
6.00k
}
Unexecuted instantiation: bitvec::field::maybe_shift_left::<_>
541
542
/// Shifts a value to the right, if it can support the shift amount.
543
1.72M
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
1.72M
  if bits_of::<T>() > shamt {
545
1.72M
    *elem >>= shamt;
546
1.72M
  }
547
1.72M
}
bitvec::field::maybe_shift_right::<usize>
Line
Count
Source
543
519k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
519k
  if bits_of::<T>() > shamt {
545
519k
    *elem >>= shamt;
546
519k
  }
547
519k
}
bitvec::field::maybe_shift_right::<u128>
Line
Count
Source
543
1.14M
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
1.14M
  if bits_of::<T>() > shamt {
545
1.14M
    *elem >>= shamt;
546
1.14M
  }
547
1.14M
}
bitvec::field::maybe_shift_right::<i16>
Line
Count
Source
543
64.0k
fn maybe_shift_right<T: Integral>(elem: &mut T, shamt: usize) {
544
64.0k
  if bits_of::<T>() > shamt {
545
64.0k
    *elem >>= shamt;
546
64.0k
  }
547
64.0k
}
Unexecuted instantiation: bitvec::field::maybe_shift_right::<_>
548
549
#[doc = include_str!("../doc/field/get.md")]
550
149k
fn get<T, O, I>(elem: PartialElement<Const, T, O>, shamt: u8) -> I
551
149k
where
552
149k
  T: BitStore,
553
149k
  O: BitOrder,
554
149k
  I: Integral,
555
{
556
149k
  resize::<T::Mem, I>(elem.load_value() >> shamt)
557
149k
}
Unexecuted instantiation: bitvec::field::get::<u8, bitvec::order::Lsb0, usize>
bitvec::field::get::<u8, bitvec::order::Msb0, usize>
Line
Count
Source
550
149k
fn get<T, O, I>(elem: PartialElement<Const, T, O>, shamt: u8) -> I
551
149k
where
552
149k
  T: BitStore,
553
149k
  O: BitOrder,
554
149k
  I: Integral,
555
{
556
149k
  resize::<T::Mem, I>(elem.load_value() >> shamt)
557
149k
}
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
178k
fn set<T, O, I>(mut elem: PartialElement<Mut, T, O>, value: I, shamt: u8)
561
178k
where
562
178k
  T: BitStore,
563
178k
  O: BitOrder,
564
178k
  I: Integral,
565
{
566
178k
  elem.store_value(resize::<I, T::Mem>(value) << shamt);
567
178k
}
Unexecuted instantiation: bitvec::field::set::<u8, bitvec::order::Lsb0, usize>
bitvec::field::set::<u8, bitvec::order::Msb0, usize>
Line
Count
Source
560
178k
fn set<T, O, I>(mut elem: PartialElement<Mut, T, O>, value: I, shamt: u8)
561
178k
where
562
178k
  T: BitStore,
563
178k
  O: BitOrder,
564
178k
  I: Integral,
565
{
566
178k
  elem.store_value(resize::<I, T::Mem>(value) << shamt);
567
178k
}
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
160k
fn sign<I>(elem: I, width: usize) -> I
571
160k
where I: Integral {
572
160k
  if dvl::is_unsigned::<I>() {
573
160k
    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
160k
}
bitvec::field::sign::<usize>
Line
Count
Source
570
111k
fn sign<I>(elem: I, width: usize) -> I
571
111k
where I: Integral {
572
111k
  if dvl::is_unsigned::<I>() {
573
111k
    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
111k
}
bitvec::field::sign::<u128>
Line
Count
Source
570
45.6k
fn sign<I>(elem: I, width: usize) -> I
571
45.6k
where I: Integral {
572
45.6k
  if dvl::is_unsigned::<I>() {
573
45.6k
    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
45.6k
}
bitvec::field::sign::<u16>
Line
Count
Source
570
3.00k
fn sign<I>(elem: I, width: usize) -> I
571
3.00k
where I: Integral {
572
3.00k
  if dvl::is_unsigned::<I>() {
573
3.00k
    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.00k
}
Unexecuted instantiation: bitvec::field::sign::<_>
582
583
#[doc = include_str!("../doc/field/resize.md")]
584
3.20M
fn resize<T, U>(value: T) -> U
585
3.20M
where
586
3.20M
  T: Integral,
587
3.20M
  U: Integral,
588
{
589
3.20M
  let mut out = U::ZERO;
590
3.20M
  let size_t = mem::size_of::<T>();
591
3.20M
  let size_u = mem::size_of::<U>();
592
593
3.20M
  unsafe {
594
3.20M
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
3.20M
  }
596
597
3.20M
  out
598
3.20M
}
bitvec::field::resize::<u8, usize>
Line
Count
Source
584
631k
fn resize<T, U>(value: T) -> U
585
631k
where
586
631k
  T: Integral,
587
631k
  U: Integral,
588
{
589
631k
  let mut out = U::ZERO;
590
631k
  let size_t = mem::size_of::<T>();
591
631k
  let size_u = mem::size_of::<U>();
592
593
631k
  unsafe {
594
631k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
631k
  }
596
597
631k
  out
598
631k
}
bitvec::field::resize::<u8, u128>
Line
Count
Source
584
731k
fn resize<T, U>(value: T) -> U
585
731k
where
586
731k
  T: Integral,
587
731k
  U: Integral,
588
{
589
731k
  let mut out = U::ZERO;
590
731k
  let size_t = mem::size_of::<T>();
591
731k
  let size_u = mem::size_of::<U>();
592
593
731k
  unsafe {
594
731k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
731k
  }
596
597
731k
  out
598
731k
}
bitvec::field::resize::<u8, u16>
Line
Count
Source
584
6.00k
fn resize<T, U>(value: T) -> U
585
6.00k
where
586
6.00k
  T: Integral,
587
6.00k
  U: Integral,
588
{
589
6.00k
  let mut out = U::ZERO;
590
6.00k
  let size_t = mem::size_of::<T>();
591
6.00k
  let size_u = mem::size_of::<U>();
592
593
6.00k
  unsafe {
594
6.00k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
6.00k
  }
596
597
6.00k
  out
598
6.00k
}
bitvec::field::resize::<usize, u8>
Line
Count
Source
584
631k
fn resize<T, U>(value: T) -> U
585
631k
where
586
631k
  T: Integral,
587
631k
  U: Integral,
588
{
589
631k
  let mut out = U::ZERO;
590
631k
  let size_t = mem::size_of::<T>();
591
631k
  let size_u = mem::size_of::<U>();
592
593
631k
  unsafe {
594
631k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
631k
  }
596
597
631k
  out
598
631k
}
bitvec::field::resize::<u128, u8>
Line
Count
Source
584
1.14M
fn resize<T, U>(value: T) -> U
585
1.14M
where
586
1.14M
  T: Integral,
587
1.14M
  U: Integral,
588
{
589
1.14M
  let mut out = U::ZERO;
590
1.14M
  let size_t = mem::size_of::<T>();
591
1.14M
  let size_u = mem::size_of::<U>();
592
593
1.14M
  unsafe {
594
1.14M
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
1.14M
  }
596
597
1.14M
  out
598
1.14M
}
bitvec::field::resize::<i16, u8>
Line
Count
Source
584
64.0k
fn resize<T, U>(value: T) -> U
585
64.0k
where
586
64.0k
  T: Integral,
587
64.0k
  U: Integral,
588
{
589
64.0k
  let mut out = U::ZERO;
590
64.0k
  let size_t = mem::size_of::<T>();
591
64.0k
  let size_u = mem::size_of::<U>();
592
593
64.0k
  unsafe {
594
64.0k
    resize_inner::<T, U>(&value, &mut out, size_t, size_u);
595
64.0k
  }
596
597
64.0k
  out
598
64.0k
}
Unexecuted instantiation: bitvec::field::resize::<_, _>
599
600
/// Performs little-endian byte-order register resizing.
601
#[cfg(target_endian = "little")]
602
3.20M
unsafe fn resize_inner<T, U>(
603
3.20M
  src: &T,
604
3.20M
  dst: &mut U,
605
3.20M
  size_t: usize,
606
3.20M
  size_u: usize,
607
3.20M
) {
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.20M
  ptr::copy_nonoverlapping(
611
3.20M
    src as *const T as *const u8,
612
3.20M
    dst as *mut U as *mut u8,
613
3.20M
    size_t.min(size_u),
614
  );
615
3.20M
}
bitvec::field::resize_inner::<u8, usize>
Line
Count
Source
602
631k
unsafe fn resize_inner<T, U>(
603
631k
  src: &T,
604
631k
  dst: &mut U,
605
631k
  size_t: usize,
606
631k
  size_u: usize,
607
631k
) {
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
631k
  ptr::copy_nonoverlapping(
611
631k
    src as *const T as *const u8,
612
631k
    dst as *mut U as *mut u8,
613
631k
    size_t.min(size_u),
614
  );
615
631k
}
bitvec::field::resize_inner::<u8, u128>
Line
Count
Source
602
731k
unsafe fn resize_inner<T, U>(
603
731k
  src: &T,
604
731k
  dst: &mut U,
605
731k
  size_t: usize,
606
731k
  size_u: usize,
607
731k
) {
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
731k
  ptr::copy_nonoverlapping(
611
731k
    src as *const T as *const u8,
612
731k
    dst as *mut U as *mut u8,
613
731k
    size_t.min(size_u),
614
  );
615
731k
}
bitvec::field::resize_inner::<u8, u16>
Line
Count
Source
602
6.00k
unsafe fn resize_inner<T, U>(
603
6.00k
  src: &T,
604
6.00k
  dst: &mut U,
605
6.00k
  size_t: usize,
606
6.00k
  size_u: usize,
607
6.00k
) {
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
6.00k
  ptr::copy_nonoverlapping(
611
6.00k
    src as *const T as *const u8,
612
6.00k
    dst as *mut U as *mut u8,
613
6.00k
    size_t.min(size_u),
614
  );
615
6.00k
}
bitvec::field::resize_inner::<usize, u8>
Line
Count
Source
602
631k
unsafe fn resize_inner<T, U>(
603
631k
  src: &T,
604
631k
  dst: &mut U,
605
631k
  size_t: usize,
606
631k
  size_u: usize,
607
631k
) {
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
631k
  ptr::copy_nonoverlapping(
611
631k
    src as *const T as *const u8,
612
631k
    dst as *mut U as *mut u8,
613
631k
    size_t.min(size_u),
614
  );
615
631k
}
bitvec::field::resize_inner::<u128, u8>
Line
Count
Source
602
1.14M
unsafe fn resize_inner<T, U>(
603
1.14M
  src: &T,
604
1.14M
  dst: &mut U,
605
1.14M
  size_t: usize,
606
1.14M
  size_u: usize,
607
1.14M
) {
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.14M
  ptr::copy_nonoverlapping(
611
1.14M
    src as *const T as *const u8,
612
1.14M
    dst as *mut U as *mut u8,
613
1.14M
    size_t.min(size_u),
614
  );
615
1.14M
}
bitvec::field::resize_inner::<i16, u8>
Line
Count
Source
602
64.0k
unsafe fn resize_inner<T, U>(
603
64.0k
  src: &T,
604
64.0k
  dst: &mut U,
605
64.0k
  size_t: usize,
606
64.0k
  size_u: usize,
607
64.0k
) {
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
64.0k
  ptr::copy_nonoverlapping(
611
64.0k
    src as *const T as *const u8,
612
64.0k
    dst as *mut U as *mut u8,
613
64.0k
    size_t.min(size_u),
614
  );
615
64.0k
}
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
}