ara icon indicating copy to clipboard operation
ara copied to clipboard

vfmv.f.s instruction doesn't seem to work in Verilator

Open sashkent3 opened this issue 2 years ago • 1 comments

My setup

I should note that my setup is different from the one suggested in README.md in two ways:

  • I'm using Verilator v4.222 since I've been unable to compile v4.214 because of verilator/verilator#3390.
  • I've updated toolchain/riscv-llvm to llvmorg-16.0.3 tag since I need support for the latest RVV Intrinsic specification.

My problem

Consider the following code that I've put in apps/vfmv_test/main.c:

#ifndef SPIKE
#include "printf.h"
#else
#include <stdio.h>
#endif

#include <riscv_vector.h>

float echo_bad(float x) {
    size_t vl = __riscv_vsetvl_e32m1(1);
    vfloat32m1_t x_v = __riscv_vfmv_s_f_f32m1(x, vl);
    return __riscv_vfmv_f_s_f32m1_f32(x_v);
}

float echo_good(float x) {
    float y;
    size_t vl = __riscv_vsetvl_e32m1(1);
    vfloat32m1_t x_v = __riscv_vfmv_s_f_f32m1(x, vl);
    __riscv_vse32_v_f32m1(&y, x_v, vl);
    return y;
}

int main() {
    if (echo_good(0.0) != 0.0)
        printf("Error: echo_good(0.0) != 0.0\n");
    else
        printf("Success: echo_good(0.0) == 0.0\n");
    if (echo_bad(0.0) != 0.0)
        printf("Error: echo_bad(0.0) != 0.0\n");
    else
        printf("Success: echo_bad(0.0) == 0.0\n");
}

If I simulate it with Spike, I get the expected prints:

Success: echo_good(0.0) == 0.0
Success: echo_bad(0.0) == 0.0

However Verilator simulation gives:

Success: echo_good(0.0) == 0.0
Error: echo_bad(0.0) != 0.0

Is vfmv.f.s really supported as stated in FUNCTIONALITIES.md? Am I missing something?

sashkent3 avatar May 10 '23 05:05 sashkent3

The issue persists even if I downgrade Verilator to the recommended v4.214 and manually add the missing header.

sashkent3 avatar May 12 '23 21:05 sashkent3