Skip to content

Commit 4f800e5

Browse files
committed
[seq/zynq] Compute total time
1 parent 1a924de commit 4f800e5

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

lib/nacs-seq/zynq/dma.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "dma.h"
2020

2121
#include <concepts>
22+
#include <type_traits>
2223

2324
namespace NaCs::Seq::Zynq::DMA {
2425

@@ -149,6 +150,23 @@ struct Printer {
149150
std::ostream &stm;
150151
};
151152

153+
struct TimeKeeper {
154+
template<typename T>
155+
void inst(T inst)
156+
{
157+
using T2 = std::remove_cv_t<T>;
158+
if constexpr (std::same_as<T2,Inst_v0::Wait1> ||
159+
std::same_as<T2,Inst_v0::Wait2>) {
160+
time += inst.cycle + 1;
161+
}
162+
}
163+
void invalid(auto)
164+
{
165+
}
166+
167+
uint64_t time{0};
168+
};
169+
152170
}
153171

154172
NACS_EXPORT() size_t count(std::span<const uint8_t> code, uint32_t version)
@@ -167,4 +185,12 @@ NACS_EXPORT() void print(std::ostream &stm, std::span<const uint8_t> code,
167185
state.run(printer, code, version);
168186
}
169187

188+
NACS_EXPORT() uint64_t total_time(std::span<const uint8_t> code, uint32_t version)
189+
{
190+
ExeState state;
191+
TimeKeeper keeper;
192+
state.run(keeper, code, version);
193+
return keeper.time;
194+
}
195+
170196
}

lib/nacs-seq/zynq/dma.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ size_t count(std::span<const uint8_t> code, uint32_t version);
355355
*/
356356
void print(std::ostream &stm, std::span<const uint8_t> code, uint32_t version);
357357

358+
/**
359+
* Total time it takes to execute the instructions
360+
*/
361+
uint64_t total_time(std::span<const uint8_t> code, uint32_t version);
362+
358363
}
359364

360365
#endif

0 commit comments

Comments
 (0)