YosysHQ / picorv32

PicoRV32 - A Size-Optimized RISC-V CPU
ISC License
3.08k stars 748 forks source link

Does the multiply co-module support float number multiply? #188

Open tianyma opened 3 years ago

jyukumite commented 3 years ago

As long as you have libm or similar linked (and your timing is good, and you're managing LATCHED_MEM_RDATA), yes, works well.

    double a;
    for (a=2.14; a<10; a+=0.123) {
        double b = sqrt(a);
        double c = b*b;
        printf(("sqrt of %f is %f -> %f, out by %f\n"), a,b,c,c-a);
        if (fabs(c-a) > 0.0001) {
            printf(("%s fail\n"), __FUNCTION__);
        }
    }

    for (a=-3.14159/2; a<3.14159/2; a+=3.14159/32) {
        double b = sin(a);
        double c = asin(b);
        printf(("sin(%f) == %f, asin == %f\n"), a,b,c);
        if (fabs(c-a) > 0.0001) {
            printf(("%s fail sin/asin at %f\n"), __FUNCTION__, a);
        }
    }

    for (a=0; a<3.14159*2; a+=3.14159/23.4) {
        double b=sin(a)/cos(a);
        double c=tan(a);
        printf(("sc(%f)=%f tan(%f)=%f\n"),a,b,a,c);
        if (fabs(c-b) > 0.0001) {
            printf(("%s fail sin/cos vs tan at %f\n"), __FUNCTION__, a);
        }
    }

[snip] sqrt of 9.3970 is 3.0654 -> 9.3970, out by 0.0000 sqrt of 9.5200 is 3.0854 -> 9.5200, out by 0.0000 [snip] sin(1.3744) == 0.9807, asin == 1.3744 sin(1.4726) == 0.9951, asin == 1.4726 sc(0.0000)=0.0000 tan(0.0000)=0.0000 sc(0.1342)=0.1350 tan(0.1342)=0.1350 [snip]