Andreas Sandberg has uploaded this change for review. ( https://gem5-review.googlesource.com/8201


Change subject: sim: Add gtoh/htog helpers that take an explicit endianness
......................................................................

sim: Add gtoh/htog helpers that take an explicit endianness

Add helper functions to swap between guest byte order and host byte
order that take a guest endianness as a parameter. These functions are
called htog and htog to be consistent with the helper functions that
extract guest byte order from a compile time constant.

Change-Id: Ie6be7dfd3b7a58ad6bfb57b25be5f85b5f425929
Signed-off-by: Andreas Sandberg <andreas.sandb...@arm.com>
---
M src/sim/byteswap.hh
1 file changed, 14 insertions(+), 0 deletions(-)



diff --git a/src/sim/byteswap.hh b/src/sim/byteswap.hh
index 2c3517f..a46f8f5 100644
--- a/src/sim/byteswap.hh
+++ b/src/sim/byteswap.hh
@@ -154,6 +154,20 @@
         #error Invalid Endianess
 #endif

+template <typename T>
+inline T htog(T value, ByteOrder guest_byte_order)
+{
+    return guest_byte_order == BigEndianByteOrder ?
+        htobe(value) : htole(value);
+}
+
+template <typename T>
+inline T gtoh(T value, ByteOrder guest_byte_order)
+{
+    return guest_byte_order == BigEndianByteOrder ?
+        betoh(value) : letoh(value);
+}
+
 namespace BigEndianGuest
 {
     const ByteOrder GuestByteOrder = BigEndianByteOrder;

--
To view, visit https://gem5-review.googlesource.com/8201
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie6be7dfd3b7a58ad6bfb57b25be5f85b5f425929
Gerrit-Change-Number: 8201
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <andreas.sandb...@arm.com>
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to