1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::rv_core::instruction::executor::prelude::*;

pub fn vf(
    Opfvf {
        vd,
        rs1,
        vs2: _,
        vm: _,
    }: Opfvf,
    v: &mut VectorContext<'_>,
    f: &FloatRegisters,
) -> Result<(), String> {
    let vreg = v
        .get(vd)
        .iter_fp()?
        .map(|vs2| ArbitraryFloat::copy_type(&vs2, f[rs1]))
        .collect_fp();

    v.apply(vd, vreg);

    Ok(())
}

pub fn fs(
    Vwfunary0 {
        dest: rd,
        vs2,
        vm: _,
        ..
    }: Vwfunary0,
    v: &VectorContext<'_>,
    f: &mut FloatRegisters,
) -> Result<(), String> {
    let first_value = v.get(vs2).iter_fp()?.next().unwrap();

    let value = match first_value {
        ArbitraryFloat::F32(fp) => {
            let (_, rest) = decompose(f[rd]);
            compose(fp, rest)
        }
        ArbitraryFloat::F64(fp) => fp,
    };

    f[rd] = value;

    Ok(())
}

pub fn sf(
    Vrfunary0 { vd, rs1, vm: _, .. }: Vrfunary0,
    v: &mut VectorContext<'_>,
    f: &FloatRegisters,
) -> Result<(), String> {
    let first_value = f64::to_le_bytes(f[rs1]);

    let vreg = v.get(vd);
    let mut vreg_data = vreg.iter_byte().collect_vec();

    vreg_data[..v.vec_engine.sew.fp()?.byte_length()]
        .copy_from_slice(&first_value[..v.vec_engine.sew.byte_length()]);

    v.apply(vd, vreg_data.into_iter().collect());

    Ok(())
}