From 1ac0d0889c8ca6b0ad37f45b23bf260a556e1ce7 Mon Sep 17 00:00:00 2001 From: Earl Ou Date: Fri, 11 Sep 2020 09:03:04 +0800 Subject: [PATCH] systemc: avoid dynamic_cast in the critical path NodeList is in the critical path of the systemc scheduler in gem5. A unnecessary dynamic_cast in the NodeList slow down the event process by about 15%. Fix the issue by avoiding dynamic_cast. We see about 15% speed improvement on the example provided by Matthias Jung: https://gist.github.com/myzinsky/557200aa04556de44a317e0a10f51840 Compare with Accellera implementation, gem5 version is originally 10x slower and now it's about 8.5x slower. Change-Id: I3b4ddca31e58e1d4e96144a4021b0a5bb956fda4 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34355 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- src/systemc/core/list.hh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/systemc/core/list.hh b/src/systemc/core/list.hh index b1c5f5521..6ba28259c 100644 --- a/src/systemc/core/list.hh +++ b/src/systemc/core/list.hh @@ -102,8 +102,13 @@ struct NodeList : public ListNode prevListNode = t; } - T *getNext() { return dynamic_cast(nextListNode); } - bool empty() { return getNext() == nullptr; } + T * + getNext() + { + return empty() ? nullptr : static_cast(nextListNode); + } + + bool empty() { return nextListNode == this; } }; } // namespace sc_gem5 -- 2.30.2