From cb48ce2a344054a6dd963f5a8b830b803477d353 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tiago=20M=C3=BCck?= Date: Fri, 5 Jun 2020 12:55:42 -0500 Subject: [PATCH] mem-ruby: add addressOffset util MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Returns the offset of an address with respect to a base address. Looks unnecessary, but SLICC doesn't support casting and the '-' operator for Addr types, so the alternative to this would be to add more some helpers like 'addrToUint64' and 'uint64ToInt'. Change-Id: I90480cec4c8b2e6bb9706f8b94ed33abe3c93e78 Signed-off-by: Tiago Mück Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/31270 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/mem/ruby/protocol/RubySlicc_Util.sm | 1 + src/mem/ruby/slicc_interface/RubySlicc_Util.hh | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/mem/ruby/protocol/RubySlicc_Util.sm b/src/mem/ruby/protocol/RubySlicc_Util.sm index b8b005ab2..70648ec6e 100644 --- a/src/mem/ruby/protocol/RubySlicc_Util.sm +++ b/src/mem/ruby/protocol/RubySlicc_Util.sm @@ -37,6 +37,7 @@ NodeID intToID(int nodenum); int IDToInt(NodeID id); int addressToInt(Addr addr); Addr intToAddress(int addr); +int addressOffset(Addr addr, Addr base); int max_tokens(); Addr makeLineAddress(Addr addr); int getOffset(Addr addr); diff --git a/src/mem/ruby/slicc_interface/RubySlicc_Util.hh b/src/mem/ruby/slicc_interface/RubySlicc_Util.hh index b51b30c63..b56842520 100644 --- a/src/mem/ruby/slicc_interface/RubySlicc_Util.hh +++ b/src/mem/ruby/slicc_interface/RubySlicc_Util.hh @@ -169,6 +169,16 @@ htmCmdToRubyRequestType(const Packet *pkt) } } +inline int +addressOffset(Addr addr, Addr base) +{ + assert(addr >= base); + Addr offset = addr - base; + // sanity checks if fits in an int + assert(offset < INT_MAX); + return offset; +} + /** * This function accepts an address, a data block and a packet. If the address * range for the data block contains the address which the packet needs to -- 2.30.2