2012-04-13 01:08:20 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 11:35:28 +00:00
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: Verilator: Netlist (top level) functions
|
|
|
|
//
|
2019-11-08 03:33:59 +00:00
|
|
|
// Code available from: https://verilator.org
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2020-03-21 15:24:24 +00:00
|
|
|
// Copyright 2003-2020 by Wilson Snyder. This program is free software; you
|
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 21:07:57 +00:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
2020-03-21 15:24:24 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
// CHEAT!
|
|
|
|
#define V3NUMBER_ASCII_BINARY
|
|
|
|
#define _V3ERROR_NO_GLOBAL_ 1
|
2018-10-14 17:43:24 +00:00
|
|
|
|
|
|
|
#include <config_build.h>
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
#include "V3Error.cpp"
|
2014-11-22 16:48:39 +00:00
|
|
|
#include "V3FileLine.cpp"
|
2006-08-26 11:35:28 +00:00
|
|
|
#include "V3Number.cpp"
|
2018-10-14 17:43:24 +00:00
|
|
|
#include "V3Number.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
2018-10-14 17:43:24 +00:00
|
|
|
#include <cstdarg>
|
2006-08-26 11:35:28 +00:00
|
|
|
|
2017-07-07 00:25:59 +00:00
|
|
|
void test(const string& lhss, const string& op, const string& rhss, const string& exps) {
|
2006-08-26 11:35:28 +00:00
|
|
|
char* l1 = strdup(lhss.c_str());
|
|
|
|
char* r1 = strdup(rhss.c_str());
|
|
|
|
char* e1 = strdup(exps.c_str());
|
|
|
|
|
2019-07-11 02:04:58 +00:00
|
|
|
FileLine fl = new FileLine(FileLine::builtInFinename());
|
2006-08-26 11:35:28 +00:00
|
|
|
|
2019-06-29 01:43:37 +00:00
|
|
|
V3Number lhnum (fl, l1);
|
|
|
|
V3Number rhnum (fl, r1);
|
|
|
|
V3Number expnum (fl, e1);
|
|
|
|
V3Number gotnum (fl, expnum.width());
|
2006-08-26 11:35:28 +00:00
|
|
|
|
2019-05-19 20:13:13 +00:00
|
|
|
if (op=="redOr") gotnum.opRedOr (lhnum);
|
|
|
|
else if (op=="redAnd") gotnum.opRedAnd (lhnum);
|
|
|
|
else if (op=="redXor") gotnum.opRedXor (lhnum);
|
|
|
|
else if (op=="redXnor") gotnum.opRedXnor (lhnum);
|
|
|
|
else if (op=="concat") gotnum.opConcat (lhnum, rhnum);
|
|
|
|
else if (op=="repl") gotnum.opRepl (lhnum, rhnum);
|
|
|
|
else if (op=="~") gotnum.opNot (lhnum);
|
|
|
|
else if (op=="!") gotnum.opLogNot (lhnum);
|
|
|
|
else if (op=="negate") gotnum.opNegate (lhnum);
|
|
|
|
else if (op=="+") gotnum.opAdd (lhnum, rhnum);
|
|
|
|
else if (op=="-") gotnum.opSub (lhnum, rhnum);
|
|
|
|
else if (op=="*") gotnum.opMul (lhnum, rhnum);
|
|
|
|
else if (op=="/") gotnum.opDiv (lhnum, rhnum);
|
|
|
|
else if (op=="%") gotnum.opModDiv (lhnum, rhnum);
|
|
|
|
else if (op=="&") gotnum.opAnd (lhnum, rhnum);
|
|
|
|
else if (op=="|") gotnum.opOr (lhnum, rhnum);
|
|
|
|
else if (op=="<") gotnum.opLt (lhnum, rhnum);
|
|
|
|
else if (op==">") gotnum.opGt (lhnum, rhnum);
|
|
|
|
else if (op==">>") gotnum.opShiftR (lhnum, rhnum);
|
|
|
|
else if (op=="<<") gotnum.opShiftL (lhnum, rhnum);
|
|
|
|
else if (op=="==") gotnum.opEq (lhnum, rhnum);
|
|
|
|
else if (op=="===") gotnum.opCaseEq (lhnum, rhnum);
|
|
|
|
else if (op=="==?") gotnum.opWildEq (lhnum, rhnum);
|
|
|
|
else if (op=="!=") gotnum.opNeq (lhnum, rhnum);
|
|
|
|
else if (op=="!==") gotnum.opCaseNeq (lhnum, rhnum);
|
|
|
|
else if (op=="!=?") gotnum.opWildNeq (lhnum, rhnum);
|
|
|
|
else if (op=="<=") gotnum.opLte (lhnum, rhnum);
|
|
|
|
else if (op==">=") gotnum.opGte (lhnum, rhnum);
|
|
|
|
else if (op=="&&") gotnum.opLogAnd (lhnum, rhnum);
|
|
|
|
else if (op=="||") gotnum.opLogOr (lhnum, rhnum);
|
2006-08-26 11:35:28 +00:00
|
|
|
else v3fatalSrc("Bad opcode: "<<op);
|
|
|
|
|
|
|
|
UINFO(0,"------- Test:\n"
|
2019-05-19 20:13:13 +00:00
|
|
|
<<" "<<lhnum<<" "<<op<<endl
|
|
|
|
<<" "<<rhnum<<endl
|
|
|
|
<<" = "<<expnum<<endl
|
|
|
|
<<" =? "<<gotnum<<endl);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
2019-06-29 01:43:37 +00:00
|
|
|
V3Number ok (fl, 1);
|
2019-05-19 20:13:13 +00:00
|
|
|
ok.opCaseEq(expnum, gotnum);
|
2008-09-04 15:03:46 +00:00
|
|
|
if (ok.toUInt()!=1) {
|
2019-05-19 20:13:13 +00:00
|
|
|
v3fatalSrc("%Error:Test FAILED");
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2018-10-14 22:39:33 +00:00
|
|
|
|
|
|
|
free(l1);
|
|
|
|
free(r1);
|
|
|
|
free(e1);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
UINFO(0,"Test starting\n");
|
2008-06-10 01:25:10 +00:00
|
|
|
|
2019-05-19 20:13:13 +00:00
|
|
|
test("32'b10", "|", "32'b10", "32'b10");
|
|
|
|
test( "2'bx0", "|", "2'b10", "2'b10");
|
|
|
|
test("32'b0x", "|", "32'b10", "32'b1x");
|
|
|
|
test("32'b10", "&", "32'b11", "32'b10");
|
|
|
|
test("32'b10", "+", "32'b10", "32'b100");
|
|
|
|
test("3'b000", "negate", "", "3'b000");
|
|
|
|
test("3'b001", "negate", "", "3'b111");
|
|
|
|
test("32'b11", "-", "32'b001", "32'b10");
|
|
|
|
test("3'b000", "-", "3'b111", "3'b001");
|
|
|
|
test("3'b000", "-", "3'b000", "3'b000");
|
|
|
|
test("57'h000000010F0CCE7", "*", "57'h10", "57'h10F0CCE70");
|
|
|
|
test("57'h000000010F0CCE7", "*", "57'h0DE34E7FFFFFFFF", "57'h02A9D57EF0F3319");
|
|
|
|
test("67'h7FFFFFFFFFFFFFFFF", "*", "67'h4000000003C8A8D6A", "67'h3FFFFFFFFC3757296");
|
|
|
|
test("99'h7FFFFFFFFFFFFFFFFFFFFFFFF", "*", "99'h0000000000000000091338A80", "99'h7FFFFFFFFFFFFFFFF6ECC7580");
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
cout<<"Test completed\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//###################################################################
|
|
|
|
// Local Variables:
|
|
|
|
// compile-command: "make V3Number_test && ./V3Number_test "
|
|
|
|
// End:
|