eeric/rv_core/instruction/executor/v/
vfclass.rs

1use std::num::FpCategory;
2
3use num_traits::{Float, Zero};
4
5use crate::rv_core::instruction::executor::prelude::*;
6
7pub fn v(
8    Vfunary1 {
9        dest: vd, vs2, vm, ..
10    }: Vfunary1,
11    v: &mut VectorContext<'_>,
12) -> Result<(), String> {
13    let vreg = v
14        .get(vs2)
15        .iter_fp()?
16        .masked_map(v.default_mask(vm), v.get(vd).iter_eew(), |vs2| {
17            match vs2.classify() {
18                FpCategory::Infinite if vs2 < ArbitraryFloat::zero() => 1 << 0,
19                FpCategory::Normal if vs2 < ArbitraryFloat::zero() => 1 << 1,
20                FpCategory::Subnormal if vs2 < ArbitraryFloat::zero() => 1 << 2,
21                FpCategory::Zero if vs2 < ArbitraryFloat::zero() => 1 << 3,
22                FpCategory::Zero if vs2 > ArbitraryFloat::zero() => 1 << 4,
23                FpCategory::Subnormal if vs2 > ArbitraryFloat::zero() => 1 << 5,
24                FpCategory::Normal if vs2 > ArbitraryFloat::zero() => 1 << 6,
25                FpCategory::Infinite if vs2 > ArbitraryFloat::zero() => 1 << 7,
26                FpCategory::Nan => 1 << 9,
27                _ => 0,
28            }
29        })
30        .collect_with_eew(v.vec_engine.sew);
31
32    v.apply(vd, vreg);
33
34    Ok(())
35}