diff options
author | Gabe Black <gabeblack@google.com> | 2018-05-24 01:37:55 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-08-08 10:09:54 +0000 |
commit | 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f (patch) | |
tree | 7b6faaacb4574a555e561534aa4a8508c0624c32 /src/systemc/tests/systemc/datatypes/int/misc | |
parent | 7235d3b5211d0ba8f528d930a4c1e7ad62eec51a (diff) | |
download | gem5-16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f.tar.xz |
systemc: Import tests from the Accellera systemc distribution.
Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6
Reviewed-on: https://gem5-review.googlesource.com/10845
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/tests/systemc/datatypes/int/misc')
6 files changed, 370 insertions, 0 deletions
diff --git a/src/systemc/tests/systemc/datatypes/int/misc/test01/golden/test01.log b/src/systemc/tests/systemc/datatypes/int/misc/test01/golden/test01.log new file mode 100644 index 000000000..8201117d0 --- /dev/null +++ b/src/systemc/tests/systemc/datatypes/int/misc/test01/golden/test01.log @@ -0,0 +1,45 @@ +SystemC Simulation + +*** sc_int *** +sc_int_concref = sc_signed +0 +1 +sc_int_concref = sc_unsigned +0 +-2 +sc_int_concref = sc_bv_base +0 +-1 +sc_int_concref = sc_lv_base +1 +0 +sc_int_subref = sc_signed +16 +sc_int_subref = sc_unsigned +32 +sc_int_subref = sc_bv_base +48 +sc_int_subref = sc_lv_base +64 + +*** sc_uint *** +sc_uint_concref = sc_signed +0 +1 +sc_uint_concref = sc_unsigned +0 +2 +sc_uint_concref = sc_bv_base +0 +3 +sc_uint_concref = sc_lv_base +1 +0 +sc_uint_subref = sc_signed +16 +sc_uint_subref = sc_unsigned +32 +sc_uint_subref = sc_bv_base +48 +sc_uint_subref = sc_lv_base +64 diff --git a/src/systemc/tests/systemc/datatypes/int/misc/test01/test01.cpp b/src/systemc/tests/systemc/datatypes/int/misc/test01/test01.cpp new file mode 100644 index 000000000..dd9f75994 --- /dev/null +++ b/src/systemc/tests/systemc/datatypes/int/misc/test01/test01.cpp @@ -0,0 +1,140 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with the + License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing + permissions and limitations under the License. + + *****************************************************************************/ + +/***************************************************************************** + + test01.cpp -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-03-24 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +// test of sc_[u]int_(conc|sub)ref assignment from sc_[un]signed and +// sc_(bv|lv)_base + +#include "systemc.h" + +int +sc_main( int, char*[] ) +{ + sc_bigint<4> a = 1; + sc_biguint<4> b = 2; + sc_bv<4> c = 3; + sc_lv<4> d = 4; + + { + cout << "\n*** sc_int ***" << endl; + + sc_int<2> e = 0; + sc_int<2> f = 0; + sc_int<8> g = 0; + + cout << "sc_int_concref = sc_signed" << endl; + (e, f) = a; + cout << e << endl; + cout << f << endl; + + cout << "sc_int_concref = sc_unsigned" << endl; + (e, f) = b; + cout << e << endl; + cout << f << endl; + + cout << "sc_int_concref = sc_bv_base" << endl; + (e, f) = c; + cout << e << endl; + cout << f << endl; + + cout << "sc_int_concref = sc_lv_base" << endl; + (e, f) = d; + cout << e << endl; + cout << f << endl; + + cout << "sc_int_subref = sc_signed" << endl; + g( 7, 4 ) = a; + cout << g << endl; + + cout << "sc_int_subref = sc_unsigned" << endl; + g( 7, 4 ) = b; + cout << g << endl; + + cout << "sc_int_subref = sc_bv_base" << endl; + g( 7, 4 ) = c; + cout << g << endl; + + cout << "sc_int_subref = sc_lv_base" << endl; + g( 7, 4 ) = d; + cout << g << endl; + } + + { + cout << "\n*** sc_uint ***" << endl; + + sc_uint<2> e = 0; + sc_uint<2> f = 0; + sc_uint<8> g = 0; + + cout << "sc_uint_concref = sc_signed" << endl; + (e, f) = a; + cout << e << endl; + cout << f << endl; + + cout << "sc_uint_concref = sc_unsigned" << endl; + (e, f) = b; + cout << e << endl; + cout << f << endl; + + cout << "sc_uint_concref = sc_bv_base" << endl; + (e, f) = c; + cout << e << endl; + cout << f << endl; + + cout << "sc_uint_concref = sc_lv_base" << endl; + (e, f) = d; + cout << e << endl; + cout << f << endl; + + cout << "sc_uint_subref = sc_signed" << endl; + g( 7, 4 ) = a; + cout << g << endl; + + cout << "sc_uint_subref = sc_unsigned" << endl; + g( 7, 4 ) = b; + cout << g << endl; + + cout << "sc_uint_subref = sc_bv_base" << endl; + g( 7, 4 ) = c; + cout << g << endl; + + cout << "sc_uint_subref = sc_lv_base" << endl; + g( 7, 4 ) = d; + cout << g << endl; + } + + return 0; +} diff --git a/src/systemc/tests/systemc/datatypes/int/misc/test02/golden/test02.log b/src/systemc/tests/systemc/datatypes/int/misc/test02/golden/test02.log new file mode 100644 index 000000000..0d934d401 --- /dev/null +++ b/src/systemc/tests/systemc/datatypes/int/misc/test02/golden/test02.log @@ -0,0 +1,2 @@ +SystemC Simulation +Program completed diff --git a/src/systemc/tests/systemc/datatypes/int/misc/test02/test02.cpp b/src/systemc/tests/systemc/datatypes/int/misc/test02/test02.cpp new file mode 100644 index 000000000..d27e98062 --- /dev/null +++ b/src/systemc/tests/systemc/datatypes/int/misc/test02/test02.cpp @@ -0,0 +1,128 @@ +#include "systemc.h" + + +inline void dump(sc_signed& value) +{ + sc_digit* ptr = value.get_raw(); + printf(" %08x_%08x_%08x_%08x\n", + (int)ptr[3], (int)ptr[2], (int)ptr[1], (int)ptr[0]); + cout << " " << value << endl; +} + +inline void dump(sc_unsigned& value) +{ + sc_digit* ptr = value.get_raw(); + printf(" %08x_%08x_%08x_%08x\n", + (int)ptr[3], (int)ptr[2], (int)ptr[1], (int)ptr[0]); + cout << " " << value << endl; +} + +#define PARSE( SUBJECT ) \ +{ \ + src_p = SUBJECT; \ + cout << endl << #SUBJECT << ":" << endl; \ + svalue = src_p; \ + dump(svalue); \ + cout << endl; \ + value = src_p; \ + dump(value); \ +} +#define TEST(SUBJECT,EXPECTED) \ +{ \ + value = SUBJECT; \ + if ( value.to_uint64() != EXPECTED ) \ + { \ + printf("%s(%d): %s: %llx != %llx\n", \ + __FILE__, __LINE__, SUBJECT, value.to_uint64(), (uint64)EXPECTED);\ + } \ +} + +#define TESTs64(SUBJECT,EXPECTED) \ +{ \ + svalue64 = SUBJECT; \ + if ( svalue64 != (long long)EXPECTED ) \ + { \ + printf("%s(%d): %s: %llx != %llx\n", \ + __FILE__, __LINE__, SUBJECT, value.to_uint64(), (uint64)EXPECTED);\ + }\ +} + +#define TESTu64(SUBJECT,EXPECTED) \ +{ \ + uvalue64 = SUBJECT; \ + if ( uvalue64 != EXPECTED ) \ + { \ + printf("%s(%d): %s: %llx != %llx\n", \ + __FILE__, __LINE__, SUBJECT, value.to_uint64(), (uint64)EXPECTED);\ + }\ +} + + +int sc_main(int, char**) +{ + char buffer[128]; + unsigned long long expected; + sc_bigint<120> svalue; + sc_int<64> svalue64; + sc_uint<64> uvalue64; + sc_biguint<120> value; + + + TESTs64("0xusffffffff", 0xffffffff); + TESTs64("0xusffffffff", 0xffffffff); + TESTs64("0xusfffffff", 0xfffffff); + TESTs64("0XUSfedcab876543210", 0xfedcab876543210ull); + TESTs64("0ous77777777", 077777777); + TESTs64("0ous77777777", 077777777); + TESTs64("0Ous7654321076543", 07654321076543ull); + TESTs64("55555555555555", 55555555555555ull); + TESTs64("0bus1100110011001100", 0xcccc); + TESTs64("0bus1111111011011100101110101001100001110110010101000011001000010000", + 0xfedcba9876543210ll); + + TESTu64("0xusffffffff", 0xffffffff); + TESTu64("0xusffffffff", 0xffffffff); + TESTu64("0xusfffffff", 0xfffffff); + TESTu64("0XUSfedcab876543210", 0xfedcab876543210ull); + TESTu64("0ous77777777", 077777777); + TESTu64("0ous77777777", 077777777); + TESTu64("0Ous7654321076543", 07654321076543ull); + TESTu64("55555555555555", 55555555555555ull); + TESTu64("0bus1100110011001100", 0xcccc); + TESTu64("0bus1111111011011100101110101001100001110110010101000011001000010000", + 0xfedcba9876543210ll); + for ( int i = 0; i < 60; i++ ) + { + for ( int j = 0; j < 16; j++ ) + { + expected = j; + expected = expected << i; + sprintf(buffer, "0Xus%llx", expected); + TEST(buffer, expected); + TESTs64(buffer, expected); + TESTu64(buffer, expected); + sprintf(buffer, "0ous%llo", expected); + TEST(buffer, expected); + TESTs64(buffer, expected); + TESTu64(buffer, expected); + sprintf(buffer, "%lld", expected); + TEST(buffer, expected); + TESTs64(buffer, expected); + TESTu64(buffer, expected); + } + } + TEST("0xusffffffff", 0xffffffff); + TEST("0xusffffffff", 0xffffffff); + TEST("0xusfffffff", 0xfffffff); + TEST("0XUSfedcab876543210", 0xfedcab876543210ull); + TEST("0ous77777777", 077777777); + TEST("0ous77777777", 077777777); + TEST("0Ous7654321076543", 07654321076543ull); + TEST("55555555555555", 55555555555555ull); + TEST("0bus1100110011001100", 0xcccc); + TEST("0bus1111111011011100101110101001100001110110010101000011001000010000", + 0xfedcba9876543210ll); + + cerr << "Program completed" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/datatypes/int/misc/test03/golden/test03.log b/src/systemc/tests/systemc/datatypes/int/misc/test03/golden/test03.log new file mode 100644 index 000000000..3d586cecc --- /dev/null +++ b/src/systemc/tests/systemc/datatypes/int/misc/test03/golden/test03.log @@ -0,0 +1,21 @@ +SystemC Simulation +BI(3,0).to_int() = 15 +BI(3,0).to_uint() = 15 +BI(3,0).to_int64() = 15 +BI(3,0).to_uint64() = 15 +BI(3,0).to_double() = 15 +I(3,0).to_int() = 15 +I(3,0).to_uint() = 15 +I(3,0).to_int64() = 15 +I(3,0).to_uint64() = 15 +I(3,0).to_double() = 15 +UI(3,0).to_int() = 15 +UI(3,0).to_uint() = 15 +UI(3,0).to_int64() = 15 +UI(3,0).to_uint64() = 15 +UI(3,0).to_double() = 15 +UBI(3,0).to_int() = 15 +UBI(3,0).to_uint() = 15 +UBI(3,0).to_int64() = 15 +UBI(3,0).to_uint64() = 15 +UBI(3,0).to_double() = 15 diff --git a/src/systemc/tests/systemc/datatypes/int/misc/test03/test03.cpp b/src/systemc/tests/systemc/datatypes/int/misc/test03/test03.cpp new file mode 100644 index 000000000..13f4af2d9 --- /dev/null +++ b/src/systemc/tests/systemc/datatypes/int/misc/test03/test03.cpp @@ -0,0 +1,34 @@ +#include "systemc.h" + +#define TEST(EXP) cout << #EXP << " = " << EXP << endl; +int +sc_main( int argc, char* argv[] ) +{ + sc_bigint<8> BI = 0xff; + sc_int<8> I = BI; + sc_uint<8> UI = BI; + sc_biguint<8> UBI = BI; + +TEST(BI(3,0).to_int()) +TEST(BI(3,0).to_uint()) +TEST(BI(3,0).to_int64()) +TEST(BI(3,0).to_uint64()) +TEST(BI(3,0).to_double()) +TEST(I(3,0).to_int()) +TEST(I(3,0).to_uint()) +TEST(I(3,0).to_int64()) +TEST(I(3,0).to_uint64()) +TEST(I(3,0).to_double()) +TEST(UI(3,0).to_int()) +TEST(UI(3,0).to_uint()) +TEST(UI(3,0).to_int64()) +TEST(UI(3,0).to_uint64()) +TEST(UI(3,0).to_double()) +TEST(UBI(3,0).to_int()) +TEST(UBI(3,0).to_uint()) +TEST(UBI(3,0).to_int64()) +TEST(UBI(3,0).to_uint64()) +TEST(UBI(3,0).to_double()) + + return 0; +} |