stillwater-sc / universal

Large collection of number systems providing custom arithmetic and mixed-precision algorithms for AI, Machine Learning, Computer Vision, Signal Processing, CAE, EDA, control, optimization, estimation, and approximation.
MIT License
391 stars 58 forks source link

Implement specialized posit<16,2> addition #403

Closed davidmallasen closed 7 months ago

davidmallasen commented 7 months ago

Following issue #343 I implemented the specialized posit<16,2> addition following the guidelines from softposit. I think it is working correctly, but the tests are not computing the golden solution correctly. When I run the exhaustive tests with the reportTestCases=true, I get the following fails:

.
.
.
8.8817841970012523234e-16 +                -8.0703125 !=                -8.0703125 golden reference is             -3.0087890625
    0b0.00000000000001.1. +     0b1.10.11.00000010010 !=     0b1.10.11.00000010010 golden reference is     0b1.10.01.10000001001
FAIL
8.8817841970012523234e-16 +               -8.06640625 !=               -8.06640625 golden reference is                -3.0078125
    0b0.00000000000001.1. +     0b1.10.11.00000010001 !=     0b1.10.11.00000010001 golden reference is     0b1.10.01.10000001000
FAIL
8.8817841970012523234e-16 +                   -8.0625 !=                   -8.0625 golden reference is                -3.0078125
    0b0.00000000000001.1. +     0b1.10.11.00000010000 !=     0b1.10.11.00000010000 golden reference is     0b1.10.01.10000001000
FAIL
8.8817841970012523234e-16 +               -8.05859375 !=               -8.05859375 golden reference is             -3.0068359375
    0b0.00000000000001.1. +     0b1.10.11.00000001111 !=     0b1.10.11.00000001111 golden reference is     0b1.10.01.10000000111
FAIL
8.8817841970012523234e-16 +                -8.0546875 !=                -8.0546875 golden reference is             -3.0068359375
    0b0.00000000000001.1. +     0b1.10.11.00000001110 !=     0b1.10.11.00000001110 golden reference is     0b1.10.01.10000000111
FAIL
8.8817841970012523234e-16 +               -8.05078125 !=               -8.05078125 golden reference is              -3.005859375
    0b0.00000000000001.1. +     0b1.10.11.00000001101 !=     0b1.10.11.00000001101 golden reference is     0b1.10.01.10000000110
FAIL
8.8817841970012523234e-16 +                 -8.046875 !=                 -8.046875 golden reference is              -3.005859375
    0b0.00000000000001.1. +     0b1.10.11.00000001100 !=     0b1.10.11.00000001100 golden reference is     0b1.10.01.10000000110
FAIL
8.8817841970012523234e-16 +               -8.04296875 !=               -8.04296875 golden reference is             -3.0048828125
    0b0.00000000000001.1. +     0b1.10.11.00000001011 !=     0b1.10.11.00000001011 golden reference is     0b1.10.01.10000000101
FAIL
8.8817841970012523234e-16 +                -8.0390625 !=                -8.0390625 golden reference is             -3.0048828125
    0b0.00000000000001.1. +     0b1.10.11.00000001010 !=     0b1.10.11.00000001010 golden reference is     0b1.10.01.10000000101
FAIL
8.8817841970012523234e-16 +               -8.03515625 !=               -8.03515625 golden reference is               -3.00390625
    0b0.00000000000001.1. +     0b1.10.11.00000001001 !=     0b1.10.11.00000001001 golden reference is     0b1.10.01.10000000100
FAIL
8.8817841970012523234e-16 +                  -8.03125 !=                  -8.03125 golden reference is               -3.00390625
    0b0.00000000000001.1. +     0b1.10.11.00000001000 !=     0b1.10.11.00000001000 golden reference is     0b1.10.01.10000000100
.
.
.

Where I believe the computed value is correct and the golden one isn't.

I checked the to_double() function and it seems to be correct, but calls some other functions in posit_impl.hpp that I don't know. Could you have a look at this @Ravenwater @theo-lemurian ?

Ravenwater commented 7 months ago

I'll take a look at the golden reference path

Ravenwater commented 7 months ago

gnarly situation of crossing bad edits: turns out that the golden reference is ok, the failure is in the proper carry propagation in the exponent and regime, as shown here:


Fast specialization posit<16,2>: report test cases
 posit< 16,2> useed scale     4     minpos scale        -56     maxpos scale         56  :  0

FAIL
1.3877787807814456755e-17 + 4.5474735088646411896e-13 != 1.3642420526593923569e-12 golden reference is 4.5474735088646411896e-13
    0b0.000000000000001.. +     0b0.000000000001.11.0 !=     0b0.00000000001.00.10 golden reference is     0b0.000000000001.11.0
FAIL
1.3877787807814456755e-17 + 6.8212102632969617844e-13 != 1.5916157281026244164e-12 golden reference is 6.8212102632969617844e-13
    0b0.000000000000001.. +     0b0.000000000001.11.1 !=     0b0.00000000001.00.11 golden reference is     0b0.000000000001.11.1
FAIL
1.3877787807814456755e-17 +             -3.9990234375 !=            -1.99951171875 golden reference is             -3.9990234375
    0b0.000000000000001.. +     0b1.10.01.11111111111 !=     0b1.10.00.11111111111 golden reference is     0b1.10.01.11111111111
FAIL
1.3877787807814456755e-17 +              -3.998046875 !=            -1.99951171875 golden reference is              -3.998046875
    0b0.000000000000001.. +     0b1.10.01.11111111110 !=     0b1.10.00.11111111111 golden reference is     0b1.10.01.11111111110
FAIL
1.3877787807814456755e-17 +             -3.9970703125 !=             -1.9990234375 golden reference is             -3.9970703125
    0b0.000000000000001.. +     0b1.10.01.11111111101 !=     0b1.10.00.11111111110 golden reference is     0b1.10.01.11111111101
FAIL
1.3877787807814456755e-17 +               -3.99609375 !=             -1.9990234375 golden reference is               -3.99609375
    0b0.000000000000001.. +     0b1.10.01.11111111100 !=     0b1.10.00.11111111110 golden reference is     0b1.10.01.11111111100
FAIL
1.3877787807814456755e-17 +             -3.9951171875 !=            -1.99853515625 golden reference is             -3.9951171875
    0b0.000000000000001.. +     0b1.10.01.11111111011 !=     0b1.10.00.11111111101 golden reference is     0b1.10.01.11111111011
FAIL
1.3877787807814456755e-17 +              -3.994140625 !=            -1.99853515625 golden reference is              -3.994140625
    0b0.000000000000001.. +     0b1.10.01.11111111010 !=     0b1.10.00.11111111101 golden reference is     0b1.10.01.11111111010
FAIL
1.3877787807814456755e-17 +             -3.9931640625 !=              -1.998046875 golden reference is             -3.9931640625
    0b0.000000000000001.. +     0b1.10.01.11111111001 !=     0b1.10.00.11111111100 golden reference is     0b1.10.01.11111111001
FAIL
1.3877787807814456755e-17 +                -3.9921875 !=              -1.998046875 golden reference is                -3.9921875
    0b0.000000000000001.. +     0b1.10.01.11111111000 !=     0b1.10.00.11111111100 golden reference is     0b1.10.01.11111111000```

Now need to figure out what is going wrong.