Coverage Report

Created: 2024-10-17 09:27

/home/runner/actions-runner/_work/fuel-vm/fuel-vm/fuel-asm/src/pack.rs
Line
Count
Source
1
//! Functions for packing instruction data into bytes or u32s.
2
3
use crate::{
4
    Imm06,
5
    Imm12,
6
    Imm18,
7
    Imm24,
8
    RegId,
9
};
10
11
12.4k
pub(super) fn bytes_from_ra(ra: RegId) -> [u8; 3] {
12
12.4k
    u8x3_from_u8x4(u32_from_ra(ra).to_be_bytes())
13
12.4k
}
14
15
2.34k
pub(super) fn bytes_from_ra_rb(ra: RegId, rb: RegId) -> [u8; 3] {
16
2.34k
    u8x3_from_u8x4(u32_from_ra_rb(ra, rb).to_be_bytes())
17
2.34k
}
18
19
1.14k
pub(super) fn bytes_from_ra_rb_rc(ra: RegId, rb: RegId, rc: RegId) -> [u8; 3] {
20
1.14k
    u8x3_from_u8x4(u32_from_ra_rb_rc(ra, rb, rc).to_be_bytes())
21
1.14k
}
22
23
5.64k
pub(super) fn bytes_from_ra_rb_rc_rd(
24
5.64k
    ra: RegId,
25
5.64k
    rb: RegId,
26
5.64k
    rc: RegId,
27
5.64k
    rd: RegId,
28
5.64k
) -> [u8; 3] {
29
5.64k
    u8x3_from_u8x4(u32_from_ra_rb_rc_rd(ra, rb, rc, rd).to_be_bytes())
30
5.64k
}
31
32
834
pub(super) fn bytes_from_ra_rb_rc_imm06(
33
834
    ra: RegId,
34
834
    rb: RegId,
35
834
    rc: RegId,
36
834
    imm: Imm06,
37
834
) -> [u8; 3] {
38
834
    u8x3_from_u8x4(u32_from_ra_rb_rc_imm06(ra, rb, rc, imm).to_be_bytes())
39
834
}
40
41
44.8k
pub(super) fn bytes_from_ra_rb_imm12(ra: RegId, rb: RegId, imm: Imm12) -> [u8; 3] {
42
44.8k
    u8x3_from_u8x4(u32_from_ra_rb_imm12(ra, rb, imm).to_be_bytes())
43
44.8k
}
44
45
14.2k
pub(super) fn bytes_from_ra_imm18(ra: RegId, imm: Imm18) -> [u8; 3] {
46
14.2k
    u8x3_from_u8x4(u32_from_ra_imm18(ra, imm).to_be_bytes())
47
14.2k
}
48
49
2.12k
pub(super) fn bytes_from_imm24(imm: Imm24) -> [u8; 3] {
50
2.12k
    u8x3_from_u8x4(u32_from_imm24(imm).to_be_bytes())
51
2.12k
}
52
53
81.5k
fn u32_from_ra(r: RegId) -> u32 {
54
81.5k
    (r.0 as u32) << 18
55
81.5k
}
56
57
54.7k
fn u32_from_rb(r: RegId) -> u32 {
58
54.7k
    (r.0 as u32) << 12
59
54.7k
}
60
61
7.62k
fn u32_from_rc(r: RegId) -> u32 {
62
7.62k
    (r.0 as u32) << 6
63
7.62k
}
64
65
5.64k
fn u32_from_rd(r: RegId) -> u32 {
66
5.64k
    r.0 as u32
67
5.64k
}
68
69
834
fn u32_from_imm06(imm: Imm06) -> u32 {
70
834
    imm.0 as u32
71
834
}
72
73
44.8k
fn u32_from_imm12(imm: Imm12) -> u32 {
74
44.8k
    imm.0 as u32
75
44.8k
}
76
77
14.2k
fn u32_from_imm18(imm: Imm18) -> u32 {
78
14.2k
    imm.0
79
14.2k
}
80
81
2.12k
fn u32_from_imm24(imm: Imm24) -> u32 {
82
2.12k
    imm.0
83
2.12k
}
84
85
54.7k
fn u32_from_ra_rb(ra: RegId, rb: RegId) -> u32 {
86
54.7k
    u32_from_ra(ra) | u32_from_rb(rb)
87
54.7k
}
88
89
7.62k
fn u32_from_ra_rb_rc(ra: RegId, rb: RegId, rc: RegId) -> u32 {
90
7.62k
    u32_from_ra_rb(ra, rb) | u32_from_rc(rc)
91
7.62k
}
92
93
5.64k
fn u32_from_ra_rb_rc_rd(ra: RegId, rb: RegId, rc: RegId, rd: RegId) -> u32 {
94
5.64k
    u32_from_ra_rb_rc(ra, rb, rc) | u32_from_rd(rd)
95
5.64k
}
96
97
834
fn u32_from_ra_rb_rc_imm06(ra: RegId, rb: RegId, rc: RegId, imm: Imm06) -> u32 {
98
834
    u32_from_ra_rb_rc(ra, rb, rc) | u32_from_imm06(imm)
99
834
}
100
101
44.8k
fn u32_from_ra_rb_imm12(ra: RegId, rb: RegId, imm: Imm12) -> u32 {
102
44.8k
    u32_from_ra_rb(ra, rb) | u32_from_imm12(imm)
103
44.8k
}
104
105
14.2k
fn u32_from_ra_imm18(ra: RegId, imm: Imm18) -> u32 {
106
14.2k
    u32_from_ra(ra) | u32_from_imm18(imm)
107
14.2k
}
108
109
// Ignore the opcode byte, take the remaining instruction data.
110
83.6k
fn u8x3_from_u8x4([_, a, b, c]: [u8; 4]) -> [u8; 3] {
111
83.6k
    [a, b, c]
112
83.6k
}