OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [tests/] [bvt21.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// This file is part of the uSTL library, an STL implementation.
2
//
3
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
4
// This file is free software, distributed under the MIT License.
5
 
6
#include "stdtest.h"
7
 
8
template <typename T>
9
void TestBswap (T v)
10
{
11
    const T vsw (bswap(v));
12
#if BYTE_ORDER == LITTLE_ENDIAN
13
    const T vbe (vsw), vle (v);
14
#elif BYTE_ORDER == BIG_ENDIAN
15
    const T vbe (v), vle (vsw);
16
#endif
17
    static const char ok[2][4] = { "bad", "ok" };
18
    cout << "bswap(" << v << ") = " << vsw << endl;
19
    cout << "le_to_native(" << v << ") = " << ok[le_to_native(vle) == v] << endl;
20
    cout << "native_to_le(" << v << ") = " << ok[native_to_le(v) == vle] << endl;
21
    cout << "be_to_native(" << v << ") = " << ok[be_to_native(vbe) == v] << endl;
22
    cout << "native_to_be(" << v << ") = " << ok[native_to_be(v) == vbe] << endl;
23
}
24
 
25
void TestUtility (void)
26
{
27
    cout << "DivRU(13,5) = " << DivRU(13,5) << endl;
28
    cout << "DivRU(15,5) = " << DivRU(15,5) << endl;
29
    cout << "DivRU(-12,5) = " << DivRU(-12,5) << endl;
30
    cout << endl;
31
    cout << "Align(5) = " << Align(5) << endl;
32
    cout << "Align(5,2) = " << Align(5,2) << endl;
33
    cout << "Align(17,7) = " << Align(17,7) << endl;
34
    cout << "Align(14,7) = " << Align(14,7) << endl;
35
    cout << endl;
36
    cout << "NextPow2(0) = " << NextPow2(0) << endl;
37
    cout << "NextPow2(1) = " << NextPow2(1) << endl;
38
    cout << "NextPow2(4) = " << NextPow2(4) << endl;
39
    cout << "NextPow2(3827) = " << NextPow2(3827) << endl;
40
    cout << "NextPow2(0xFFFFFFF0) = " << NextPow2(0xFFFFFFF0) << endl;
41
    cout << endl;
42
    cout << "advance(42,0) = " << advance(42,0) << endl;
43
    cout << "advance(42,3) = " << advance(42,3) << endl;
44
    const void *cvp = (const void*) 0x1234;
45
    void* vp = (void*) 0x4321;
46
    cout << ios::hex;
47
    cout << "cvp = " << cvp << endl;
48
    cout << "vp = " << vp << endl;
49
    cout << "advance(cvp,5) = " << advance(cvp,5) << endl;
50
    cout << "advance(vp,4) = " << advance(vp,4) << endl;
51
    cout << "distance(cvp,vp) = " << distance(cvp,vp) << endl;
52
    cout << "abs_distance(vp,cvp) = " << abs_distance(vp,cvp) << endl;
53
    cout << ios::dec << endl;
54
    const int32_t c_Numbers[] = { 1, 2, 3, 4, 5 };
55
    const int32_t c_Empty[] = { };
56
    cout << "size_of_elements(3, c_Numbers) = " << size_of_elements(3, c_Numbers) << endl;
57
    cout << "VectorSize(c_Numbers[5]) = " << VectorSize(c_Numbers) << endl;
58
    cout << "VectorSize(c_Numbers[0]) = " << VectorSize(c_Empty) << endl;
59
    cout << endl;
60
    cout << "BitsInType(uint32_t) = " << BitsInType(uint32_t) << endl;
61
    cout << "BitsInType(int16_t) = " << BitsInType(int16_t) << endl;
62
    cout << "BitsInType(char) = " << BitsInType(char) << endl;
63
    cout << ios::hex << endl;
64
    cout << "BitMask(uint32_t,12) = " << BitMask(uint32_t,12) << endl;
65
    cout << "BitMask(uint16_t,1) = " << BitMask(uint16_t,1) << endl;
66
    cout << "BitMask(uint8_t,8) = " << BitMask(uint8_t,8) << endl;
67
    cout << "BitMask(uint16_t,0) = " << BitMask(uint16_t,0) << endl;
68
    cout << endl;
69
    uint16_t packed16 = 0xCDCD;
70
    pack_type (uint8_t(0x42), packed16);
71
    cout << "pack_type(uint8_t, uint16_t) = " << packed16 << endl;
72
    uint32_t packed32 = 0xCDCDCDCD;
73
    pack_type (uint8_t(0x42), packed32);
74
    cout << "pack_type(uint8_t, uint32_t) = " << packed32 << endl;
75
    packed32 = 0xCDCDCDCD;
76
    pack_type (uint16_t(0x4243), packed32);
77
    cout << "pack_type(uint16_t, uint32_t) = " << packed32 << endl;
78
    #if HAVE_INT64_T
79
        uint64_t packed64 = UINT64_C(0x123456789ABCDEF0);
80
        pack_type (uint8_t(0x42), packed64);
81
        cout << "pack_type(uint8_t, uint64_t) = " << packed64 << endl;
82
        packed64 = UINT64_C(0x123456789ABCDEF0);
83
        pack_type (uint32_t(0x42434445), packed64);
84
        cout << "pack_type(uint32_t, uint64_t) = " << packed64 << endl;
85
    #else
86
        cout << "No 64bit types available on this platform" << endl;
87
    #endif
88
    cout << endl;
89
    TestBswap (uint16_t (0x1234));
90
    TestBswap (uint32_t (0x12345678));
91
    #if HAVE_INT64_T
92
        TestBswap (uint64_t (UINT64_C(0x123456789ABCDEF0)));
93
    #else
94
        cout << "No 64bit types available on this platform" << endl;
95
    #endif
96
    cout << ios::dec << endl;
97
    cout << "absv(12) = " << absv(12) << endl;
98
    cout << "absv(-12) = " << absv(-12) << endl;
99
    cout << "sign(12) = " << sign(12) << endl;
100
    cout << "sign(-12) = " << sign(-12) << endl;
101
    cout << "sign(0) = " << sign(0) << endl;
102
    cout << "min(3,4) = " << min(3,4) << endl;
103
    cout << "min(6U,1U) = " << min(6U,1U) << endl;
104
    cout << "max(-3,-6) = " << max(-3,-6) << endl;
105
    cout << "max(-3L,6L) = " << max(-3L,6L) << endl;
106
}
107
 
108
StdBvtMain (TestUtility)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.