


package types

import Chisel._

class ValExec_CompareRecFN_lt(expWidth: Int, sigWidth: Int) extends Module
{
    val io = new Bundle {
        val a = Bits(INPUT, expWidth + sigWidth)
        val b = Bits(INPUT, expWidth + sigWidth)
        val expected = new Bundle {
            val out = Bits(INPUT, 1)
            val exceptionFlags = Bits(INPUT, 5)
        }
        val actual = new Bundle {
            val out = Bits(OUTPUT, 1)
            val exceptionFlags = Bits(OUTPUT, 5)
        }
        val check = Bool(OUTPUT)
        val pass = Bool(OUTPUT)
    }

    val compareRecFN = Module(new CompareRecFN(expWidth, sigWidth))
    compareRecFN.io.a := recFNFromFN(expWidth, sigWidth, io.a)
    compareRecFN.io.b := recFNFromFN(expWidth, sigWidth, io.b)
    compareRecFN.io.signaling := Bool(true)

    io.actual.out := compareRecFN.io.lt
    io.actual.exceptionFlags := compareRecFN.io.exceptionFlags

    io.check := Bool(true)
    io.pass :=
        (io.actual.out === io.expected.out) &&
        (io.actual.exceptionFlags === io.expected.exceptionFlags)
}

class ValExec_CompareRecF16_lt extends ValExec_CompareRecFN_lt(5, 11)
class ValExec_CompareRecF32_lt extends ValExec_CompareRecFN_lt(8, 24)
class ValExec_CompareRecF64_lt extends ValExec_CompareRecFN_lt(11, 53)

class ValExec_CompareRecFN_le(expWidth: Int, sigWidth: Int) extends Module
{
    val io = new Bundle {
        val a = Bits(INPUT, expWidth + sigWidth)
        val b = Bits(INPUT, expWidth + sigWidth)
        val expected = new Bundle {
            val out = Bits(INPUT, 1)
            val exceptionFlags = Bits(INPUT, 5)
        }
        val actual = new Bundle {
            val out = Bits(OUTPUT, 1)
            val exceptionFlags = Bits(OUTPUT, 5)
        }
        val check = Bool(OUTPUT)
        val pass = Bool(OUTPUT)
    }

    val compareRecFN = Module(new CompareRecFN(expWidth, sigWidth))
    compareRecFN.io.a := recFNFromFN(expWidth, sigWidth, io.a)
    compareRecFN.io.b := recFNFromFN(expWidth, sigWidth, io.b)
    compareRecFN.io.signaling := Bool(true)

    io.actual.out := compareRecFN.io.lt || compareRecFN.io.eq
    io.actual.exceptionFlags := compareRecFN.io.exceptionFlags

    io.check := Bool(true)
    io.pass :=
        (io.actual.out === io.expected.out) &&
        (io.actual.exceptionFlags === io.expected.exceptionFlags)
}

class ValExec_CompareRecF16_le extends ValExec_CompareRecFN_le(5, 11)
class ValExec_CompareRecF32_le extends ValExec_CompareRecFN_le(8, 24)
class ValExec_CompareRecF64_le extends ValExec_CompareRecFN_le(11, 53)

class ValExec_CompareRecFN_eq(expWidth: Int, sigWidth: Int) extends Module
{
    val io = new Bundle {
        val a = Bits(INPUT, expWidth + sigWidth)
        val b = Bits(INPUT, expWidth + sigWidth)
        val expected = new Bundle {
            val out = Bits(INPUT, 1)
            val exceptionFlags = Bits(INPUT, 5)
        }
        val actual = new Bundle {
            val out = Bits(OUTPUT, 1)
            val exceptionFlags = Bits(OUTPUT, 5)
        }
        val check = Bool(OUTPUT)
        val pass = Bool(OUTPUT)
    }

    val compareRecFN = Module(new CompareRecFN(expWidth, sigWidth))
    compareRecFN.io.a := recFNFromFN(expWidth, sigWidth, io.a)
    compareRecFN.io.b := recFNFromFN(expWidth, sigWidth, io.b)
    compareRecFN.io.signaling := Bool(false)

    io.actual.out := compareRecFN.io.eq
    io.actual.exceptionFlags := compareRecFN.io.exceptionFlags

    io.check := Bool(true)
    io.pass :=
        (io.actual.out === io.expected.out) &&
        (io.actual.exceptionFlags === io.expected.exceptionFlags)
}

class ValExec_CompareRecF16_eq extends ValExec_CompareRecFN_eq(5, 11)
class ValExec_CompareRecF32_eq extends ValExec_CompareRecFN_eq(8, 24)
class ValExec_CompareRecF64_eq extends ValExec_CompareRecFN_eq(11, 53)

