diff --git a/configure.ac b/configure.ac index c8403c816..e5dfc5327 100644 --- a/configure.ac +++ b/configure.ac @@ -190,6 +190,7 @@ AC_SUBST(CFG_CXXFLAGS_STD_OLDEST) _MY_CXX_CHECK_OPT(CFG_CXXFLAGS_WEXTRA,-Wextra) _MY_CXX_CHECK_OPT(CFG_CXXFLAGS_WEXTRA,-Wfloat-conversion) _MY_CXX_CHECK_OPT(CFG_CXXFLAGS_WEXTRA,-Wlogical-op) +_MY_CXX_CHECK_OPT(CFG_CXXFLAGS_WEXTRA,-Wthread-safety) AC_SUBST(CFG_CXXFLAGS_WEXTRA) # Flags for compiling Verilator internals including parser always diff --git a/include/verilated.mk.in b/include/verilated.mk.in index 584427299..6eec3a240 100644 --- a/include/verilated.mk.in +++ b/include/verilated.mk.in @@ -109,6 +109,14 @@ ifeq ($(VM_SC),1) endif endif +####################################################################### +##### Threaded builds + +ifneq ($(VM_THREADS),0) + # Need C++11 at least, so always default to newest + CPPFLAGS += -DVM_THREADED $(CFG_CXXFLAGS_STD_NEWEST) +endif + ####################################################################### ##### Stub diff --git a/src/V3EmitMk.cpp b/src/V3EmitMk.cpp index ad8e9346e..6eeb008d8 100644 --- a/src/V3EmitMk.cpp +++ b/src/V3EmitMk.cpp @@ -62,6 +62,8 @@ public: of.puts("\n### Switches...\n"); of.puts("# Coverage output mode? 0/1 (from --coverage)\n"); of.puts("VM_COVERAGE = "); of.puts(v3Global.opt.coverage()?"1":"0"); of.puts("\n"); + of.puts("# Threaded output mode? 0/1/N threads (from --threads)\n"); + of.puts("VM_THREADS = "); of.puts(cvtToStr(v3Global.opt.threads())); of.puts("\n"); of.puts("# Tracing output mode? 0/1 (from --trace)\n"); of.puts("VM_TRACE = "); of.puts(v3Global.opt.trace()?"1":"0"); of.puts("\n"); diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 911dc60e9..cfb0b7ab2 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -984,6 +984,11 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char shift; m_prefix = argv[i]; if (m_modPrefix=="") m_modPrefix = m_prefix; } + else if ( !strcmp (sw, "-no-threads") ) { m_threads = 0; } // Undocumented until functional + else if ( !strcmp (sw, "-threads") && (i+1)v3fatal("--threads must be >= 0: "< ['--cc --coverage-toggle --coverage-line --coverage-user --trace --vpi $root/include/verilated_save.cpp'], - make_flags => 'DRIVER_STD=newest CPPFLAGS_ADD=-DVL_THREADED=1', + verilator_flags2 => ['--cc --coverage-toggle --coverage-line --coverage-user --trace --threads 1 --vpi $root/include/verilated_save.cpp'], ); execute ( diff --git a/test_regress/t/t_threads_counter.v b/test_regress/t/t_threads_counter.v new file mode 100644 index 000000000..dabcf0a77 --- /dev/null +++ b/test_regress/t/t_threads_counter.v @@ -0,0 +1,24 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2017 by Wilson Snyder. + +module t (/*AUTOARG*/ + // Inputs + clk + ); + + input clk; + + integer cyc; + + always @ (posedge clk) begin + cyc <= cyc + 1; + if (cyc!=0) begin + if (cyc==10) begin + $write("*-* All Finished *-*\n"); + $finish; + end + end + end +endmodule diff --git a/test_regress/t/t_threads_counter_0.pl b/test_regress/t/t_threads_counter_0.pl new file mode 100755 index 000000000..3bcf004fd --- /dev/null +++ b/test_regress/t/t_threads_counter_0.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003-2009 by Wilson Snyder. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. + +top_filename("t/t_threads_counter.v"); + +compile ( + verilator_flags2 => ['--cc --no-threads'], + ); + +execute ( + check_finished=>1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_threads_counter_1.pl b/test_regress/t/t_threads_counter_1.pl new file mode 100755 index 000000000..8cf80808b --- /dev/null +++ b/test_regress/t/t_threads_counter_1.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003-2009 by Wilson Snyder. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. + +top_filename("t/t_threads_counter.v"); + +compile ( + verilator_flags2 => ['--cc --threads 1'], + ); + +execute ( + check_finished=>1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_threads_counter_2.pl b/test_regress/t/t_threads_counter_2.pl new file mode 100755 index 000000000..c1519604c --- /dev/null +++ b/test_regress/t/t_threads_counter_2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003-2009 by Wilson Snyder. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. + +top_filename("t/t_threads_counter.v"); + +compile ( + verilator_flags2 => ['--cc --threads 2'], + ); + +execute ( + check_finished=>1, + ); + +ok(1); +1;