• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

henrythasler / rust-tiny-wasm / 27898942932

21 Jun 2026 08:40AM UTC coverage: 95.369% (-0.1%) from 95.5%
27898942932

push

github

henrythasler
implement fp division and store/tee

Co-authored-by: Copilot <copilot@github.com>

49 of 58 new or added lines in 5 files covered. (84.48%)

2 existing lines in 2 files now uncovered.

2121 of 2224 relevant lines covered (95.37%)

66.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.35
/src/compiler/stack.rs
1
use crate::assembler::aarch64::*;
2
use wasmparser::ValType;
3

4
pub fn valtype_to_usize(valtype: &ValType) -> usize {
444✔
5
    match valtype {
444✔
6
        ValType::I32 => INT32_SIZE,
200✔
7
        ValType::I64 => INT64_SIZE,
156✔
8
        ValType::F32 => FLOAT32_SIZE,
44✔
9
        ValType::F64 => FLOAT64_SIZE,
44✔
10
        ValType::V128 => 16,
×
11
        _ => panic!("valtype not supported"),
×
12
    }
13
}
444✔
14

15
#[derive(Debug)]
16
pub struct LocalVar {
17
    pub offset: usize,
18
    pub valtype: ValType,
19
}
20

21
pub fn get_aligned_stack_size(
177✔
22
    func_type: &wasmparser::FuncType,
177✔
23
    locals: &[(u32, ValType)],
177✔
24
) -> (usize, usize) {
177✔
25
    let mut variables_size: usize = 0;
177✔
26
    for item in func_type.params() {
178✔
27
        let size = valtype_to_usize(item);
178✔
28
        // insert padding depending on size of type
178✔
29
        variables_size = variables_size.div_ceil(size) * size;
178✔
30
        variables_size += size;
178✔
31
    }
178✔
32

33
    for (count, valtype) in locals {
177✔
34
        let size = valtype_to_usize(valtype);
44✔
35
        variables_size = variables_size.div_ceil(size) * size;
44✔
36
        variables_size += *count as usize * size;
44✔
37
    }
44✔
38

39
    let stack_size = variables_size.div_ceil(STACK_ALIGNMENT) * STACK_ALIGNMENT;
177✔
40
    assert!(
177✔
41
        stack_size.is_multiple_of(STACK_ALIGNMENT),
177✔
42
        "stack size not aligned properly: {}",
43
        stack_size
44
    );
45
    (variables_size, stack_size)
177✔
46
}
177✔
47

48
/// Initialize locals by storing zero values and pushing a struct to the stack
49
pub fn save_locals_to_stack(
20✔
50
    offset: &mut usize,
20✔
51
    locals: &[(u32, ValType)],
20✔
52
    machinecode: &mut Vec<u32>,
20✔
53
) -> Vec<LocalVar> {
20✔
54
    let mut variables = vec![];
20✔
55

56
    for (count, valtype) in locals {
44✔
57
        let size = valtype_to_usize(valtype);
44✔
58
        *offset = offset.div_ceil(size) * size;
44✔
59
        for _ in 0..*count {
44✔
60
            variables.push(LocalVar {
82✔
61
                offset: *offset,
82✔
62
                valtype: *valtype,
82✔
63
            });
82✔
64

65
            let reg_size = match valtype {
82✔
66
                ValType::I32 | ValType::F32 => RegSize::Int32bit,
66✔
67
                ValType::I64 | ValType::F64 => RegSize::Int64bit,
16✔
NEW
68
                _ => panic!("valtype not supported"),
×
69
            };
70

71
            machinecode.push(memory::str_imm_unsigned_offset(
82✔
72
                IReg::XZR,
82✔
73
                IReg::SP,
74
                *offset as u32,
82✔
75
                map_valtype_to_memsize(valtype),
82✔
76
                reg_size,
82✔
77
            ));
78
            *offset += size;
82✔
79
        }
80
    }
81
    variables
20✔
82
}
20✔
83

84
pub fn save_parameters_to_stack(
106✔
85
    offset: &mut usize,
106✔
86
    values: &[ValType],
106✔
87
    machinecode: &mut Vec<u32>,
106✔
88
) -> Vec<LocalVar> {
106✔
89
    let mut variables = vec![];
106✔
90
    for (i, valtype) in values.iter().enumerate() {
178✔
91
        let size = valtype_to_usize(valtype);
178✔
92
        *offset = offset.div_ceil(size) * size;
178✔
93
        variables.push(LocalVar {
178✔
94
            offset: *offset,
178✔
95
            valtype: *valtype,
178✔
96
        });
178✔
97
        let src_reg = match valtype {
178✔
98
            ValType::I32 | ValType::I64 => Reg::IReg(IReg::try_from(i as u32).unwrap()),
142✔
99
            ValType::F32 | ValType::F64 => Reg::FReg(FReg::try_from(i as u32).unwrap()),
36✔
100
            _ => panic!("valtype not supported"),
×
101
        };
102

103
        match src_reg {
178✔
104
            Reg::IReg(reg) => machinecode.push(memory::str_imm_unsigned_offset(
142✔
105
                reg,
142✔
106
                IReg::SP,
107
                *offset as u32,
142✔
108
                map_valtype_to_memsize(valtype),
142✔
109
                map_valtype_to_regsize(valtype),
142✔
110
            )),
111

112
            Reg::FReg(reg) => machinecode.push(fp_memory::str_imm_unsigned_offset(
36✔
113
                reg,
36✔
114
                IReg::SP,
115
                *offset as u32,
36✔
116
                map_valtype_to_regsize(valtype),
36✔
117
            )),
118
        }
119
        *offset += size;
178✔
120
    }
121
    variables
106✔
122
}
106✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc