File: test_value.cc

package info (click to toggle)
yosys 0.52-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 69,796 kB
  • sloc: ansic: 696,955; cpp: 239,736; python: 14,617; yacc: 3,529; sh: 2,175; makefile: 1,945; lex: 697; perl: 445; javascript: 323; tcl: 162; vhdl: 115
file content (60 lines) | stat: -rw-r--r-- 1,557 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <cassert>
#include <cstdint>

#include "cxxrtl/cxxrtl.h"

int main()
{
    {
        // shl exceeding Bits should be masked
        cxxrtl::value<6> a(1u);
        cxxrtl::value<6> b(8u);
        cxxrtl::value<6> c = a.shl(b);
        assert(c.get<uint64_t>() == 0);
    }

    {
        // sshr of unreasonably large size should sign extend correctly
        cxxrtl::value<64> a(0u, 0x80000000u);
        cxxrtl::value<64> b(0u, 1u);
        cxxrtl::value<64> c = a.sshr(b);
        assert(c.get<uint64_t>() == 0xffffffffffffffffu);
    }

    {
        // sshr of exteeding Bits should sign extend correctly
        cxxrtl::value<8> a(0x80u);
        cxxrtl::value<8> b(10u);
        cxxrtl::value<8> c = a.sshr(b);
        assert(c.get<uint64_t>() == 0xffu);
    }

    {
        // Sign extension should occur correctly
        cxxrtl::value<64> a(0x23456789u, 0x8abcdef1u);
        cxxrtl::value<8> b(32u);
        cxxrtl::value<64> c = a.sshr(b);
        assert(c.get<uint64_t>() == 0xffffffff8abcdef1u);
    }

    {
        // ctlz should work with Bits that are a multiple of chunk size
        cxxrtl::value<32> a(0x00040000u);
        assert(a.ctlz() == 13);
    }

    {
        // bmux clears top bits of result
        cxxrtl::value<8> val(0x1fu);
        cxxrtl::value<1> sel(0u);
        assert(val.template bmux<4>(sel).get<uint64_t>() == 0xfu);
    }

    {
        // stream operator smoke test
        cxxrtl::value<8> val(0x1fu);
        std::ostringstream oss;
        oss << val;
        assert(oss.str() == "8'1f");
    }
}