Beispiel #1
0
def test_mulAddF64_random():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.0001

    random.seed(0)

    op = 0  # fixed at this mode

    test_vector = []

    for test in range(500):
        a = get_rand(-100000.0, 100000.0, 10)
        b = get_rand(-100000.0, 100000.0, 10)
        c = get_rand(-100000.0, 100000.0, 10)

        for op in range(4):
            out = mul_add_op(a, b, c, op)

            a = floatToFN(a, precision=precision)
            b = floatToFN(b, precision=precision)
            c = floatToFN(c, precision=precision)
            out = floatToFN(out, precision=precision)

            test_vector.append([op, a, b, c, 0, out])

    run_tv_test(MulAddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
Beispiel #2
0
def test_hypothesis_mulAddF64(a, b, c):

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.0000001

    out = a * b + c

    op = 0  # fixed at this mode
    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    c = floatToFN(c, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        MulAddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  op   a   b   c   roundingMode  out*'),
            [
                op,
                a,
                b,
                c,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Beispiel #3
0
def test_mulAddF16_ones():

    expWidth = 5
    sigWidth = 11
    precision = expWidth + sigWidth
    tolerance = 0.001

    test_vector = []

    for op in range(4):
        a = 1.0
        b = 1.0
        c = 1.0
        out = mul_add_op(a, b, c, op)

        a = floatToFN(a, precision=precision)
        b = floatToFN(b, precision=precision)
        c = floatToFN(c, precision=precision)
        out = floatToFN(out, precision=precision)

        test_vector.append([op, a, b, c, 0, out])

    run_tv_test(MulAddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
Beispiel #4
0
def test_mulAddF64_negative():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.00001

    test_vector = []

    for op in range(4):
        a = -192.40012
        b = -0.00005712
        c = -34
        out = mul_add_op(a, b, c, op)

        a = floatToFN(a, precision=precision)
        b = floatToFN(b, precision=precision)
        c = floatToFN(c, precision=precision)
        out = floatToFN(out, precision=precision)

        test_vector.append([op, a, b, c, 0, out])

    run_tv_test(MulAddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
Beispiel #5
0
def test_mulAddF64_mixed():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.00001

    test_vector = []

    for op in range(4):
        a = 0.0004781
        b = -1892.0192
        c = -1284.129001
        out = mul_add_op(a, b, c, op)

        a = floatToFN(a, precision=precision)
        b = floatToFN(b, precision=precision)
        c = floatToFN(c, precision=precision)
        out = floatToFN(out, precision=precision)

        test_vector.append([op, a, b, c, 0, out])

    run_tv_test(MulAddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
Beispiel #6
0
def test_mulAddF64_positive():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.00001

    test_vector = []

    for op in range(4):
        a = 19284.0122
        b = 1292131.012
        c = 549999.01
        out = mul_add_op(a, b, c, op)

        a = floatToFN(a, precision=precision)
        b = floatToFN(b, precision=precision)
        c = floatToFN(c, precision=precision)
        out = floatToFN(out, precision=precision)

        test_vector.append([op, a, b, c, 0, out])

    run_tv_test(MulAddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
Beispiel #7
0
def test_mulAddF32_negative():

    expWidth = 8
    sigWidth = 24
    precision = expWidth + sigWidth
    tolerance = 0.00001

    test_vector = []

    for op in range(4):
        a = -102.501
        b = -51.1112
        c = -0.019
        out = mul_add_op(a, b, c, op)

        a = floatToFN(a, precision=precision)
        b = floatToFN(b, precision=precision)
        c = floatToFN(c, precision=precision)
        out = floatToFN(out, precision=precision)

        test_vector.append([op, a, b, c, 0, out])

    run_tv_test(MulAddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
Beispiel #8
0
def test_mulAddF32_positive():

    expWidth = 8
    sigWidth = 24
    precision = expWidth + sigWidth
    tolerance = 0.00001

    test_vector = []

    for op in range(4):
        a = 1923.01
        b = 391.051
        c = 32.301
        out = mul_add_op(a, b, c, op)

        a = floatToFN(a, precision=precision)
        b = floatToFN(b, precision=precision)
        c = floatToFN(c, precision=precision)
        out = floatToFN(out, precision=precision)

        test_vector.append([op, a, b, c, 0, out])

    run_tv_test(MulAddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)