Skip to content

unit ValComparator

em.coremark/ValComparator.em
package em.coremark

import BenchAlgI
import ComparatorI
import Crc
import Utils

module ValComparator: ComparatorI

    proxy Bench0: BenchAlgI
    proxy Bench1: BenchAlgI

private:

    function calc(pval: int16*): int16

end

def calc(pval)
    auto val = <uint16>*pval
    auto optype = <uint8>(val >> 7) & 1
    return <int16>(val & 0x007f) if optype
    auto flag = val & 0x7
    auto vtype = (val >> 3) & 0xf
    vtype |= vtype << 4
    var ret: uint16
    switch flag
    case 0
        ret = Bench0.run(<uarg_t>vtype)
        Utils.bindCrc(Bench0.kind(), ret)
        break
    case 1
        ret = Bench1.run(<uarg_t>vtype)
        Utils.bindCrc(Bench1.kind(), ret)
        break
    default
        ret = val
        break
    end
    auto newcrc = Crc.add16(<int16>ret, Utils.getCrc(Utils.Kind.FINAL))
    Utils.setCrc(Utils.Kind.FINAL, Crc.add16(<int16>ret, Utils.getCrc(Utils.Kind.FINAL)))
    ret &= 0x007f
    *pval = <int16>((val & 0xff00) | 0x0080 | ret)   ## cache the result
    return <int16>ret
end

def compare(a, b)
    auto val1 = calc(&a.val)
    auto val2 = calc(&b.val)
    return val1 - val2
end