diff options
author | Martin Jeřábek <martin.jerabek01@gmail.com> | 2019-03-14 13:50:58 +0100 |
---|---|---|
committer | tgingold <tgingold@users.noreply.github.com> | 2021-04-22 18:55:28 +0200 |
commit | 2a926485e11b3081b7df9ef4855043b3363027dc (patch) | |
tree | 46de251ecf599b76aede5b11fd9fc243fdb1bead /src/grt/grt-waves.adb | |
parent | 792f4dbc5b7e692a9862cdfcc4b0243016e5be1c (diff) | |
download | ghdl-2a926485e11b3081b7df9ef4855043b3363027dc.tar.gz ghdl-2a926485e11b3081b7df9ef4855043b3363027dc.tar.bz2 ghdl-2a926485e11b3081b7df9ef4855043b3363027dc.zip |
grt: optimize wave dump
Instead of walking through all the signals every cycle,
keep an array of changed signals (without duplicates).
Before dumping, sort the array. Afterwards clear it.
This massively improves performance on big designs.
Diffstat (limited to 'src/grt/grt-waves.adb')
-rw-r--r-- | src/grt/grt-waves.adb | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/grt/grt-waves.adb b/src/grt/grt-waves.adb index a69aa119a..b3d575c3a 100644 --- a/src/grt/grt-waves.adb +++ b/src/grt/grt-waves.adb @@ -45,6 +45,7 @@ with Grt.Ghw; use Grt.Ghw; with Grt.Wave_Opt; use Grt.Wave_Opt; with Grt.Wave_Opt.File; use Grt.Wave_Opt.File; with Grt.Wave_Opt.Design; use Grt.Wave_Opt.Design; +with Ada.Containers.Generic_Array_Sort; pragma Elaborate_All (Grt.Rtis_Utils); pragma Elaborate_All (Grt.Table); @@ -853,6 +854,7 @@ package body Grt.Waves is -- If the signal number is 0, then assign a valid signal number. if Num = 0 then Nbr_Dumped_Signals := Nbr_Dumped_Signals + 1; + Sig.Dump_Table_Idx := Dump_Table_Index(Nbr_Dumped_Signals); Sig.Alink := To_Ghdl_Signal_Ptr (Integer_Address (Nbr_Dumped_Signals)); Num := Nbr_Dumped_Signals; @@ -1780,9 +1782,19 @@ package body Grt.Waves is procedure Wave_Cycle is + type Arr_Type is array (Dump_Table_Index range <>) of Ghdl_Signal_Ptr; + + function Cmp (Left, Right : Ghdl_Signal_Ptr) return Boolean is + begin + return Left.Dump_Table_Idx < Right.Dump_Table_Idx; + end Cmp; + + procedure Sort is new Ada.Containers.Generic_Array_Sort + (Dump_Table_Index, Ghdl_Signal_Ptr, Arr_Type, "<" => Cmp); + Diff : Std_Time; Sig : Ghdl_Signal_Ptr; - Last : Natural; + Last : Dump_Table_Index; begin if not In_Cyc then Wave_Section ("CYC" & NUL); @@ -1796,15 +1808,20 @@ package body Grt.Waves is -- Dump signals. Last := 0; - for I in Dump_Table.First .. Dump_Table.Last loop - Sig := Dump_Table.Table (I); - if Sig.Flags.RO_Event then - Wave_Put_ULEB128 (Ghdl_U32 (I - Last)); - Last := I; - Write_Signal_Value (Sig); - Sig.Flags.RO_Event := False; - end if; - end loop; + if Changed_Sig_Table.First <= Changed_Sig_Table.Last then + Sort (Arr_Type (Changed_Sig_Table.Table + (Changed_Sig_Table.First .. Changed_Sig_Table.Last))); + for I in Changed_Sig_Table.First .. Changed_Sig_Table.Last loop + Sig := Changed_Sig_Table.Table(I); + if Sig.Flags.RO_Event then + Wave_Put_ULEB128 (Ghdl_U32 (Sig.Dump_Table_Idx - Last)); + Last := Sig.Dump_Table_Idx; + Write_Signal_Value (Sig); + Sig.Flags.RO_Event := False; + end if; + end loop; + Changed_Sig_Table.Set_Last (0); + end if; Wave_Put_Byte (0); end Wave_Cycle; |