mem-ruby: add addressOffset util

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 <tiago.muck@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/31270
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Tiago Mück
2020-06-05 12:55:42 -05:00
parent 7e738c00d2
commit cb48ce2a34
2 changed files with 11 additions and 0 deletions

View File

@@ -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);

View File

@@ -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