On 11/11/22 08:40, Richard Henderson wrote:
Add a helper function for computing the size of a type.

Signed-off-by: Richard Henderson <richard.hender...@linaro.org>
---
  include/tcg/tcg.h | 16 ++++++++++++++++
  tcg/tcg.c         | 26 ++++++++++++--------------
  2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index f2da340bb9..8bcd60d0ed 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -319,6 +319,22 @@ typedef enum TCGType {
  #endif
  } TCGType;
+/**
+ * tcg_type_size
+ * @t: type
+ *
+ * Return the size of the type in bytes.
+ */
+static inline int tcg_type_size(TCGType t)
+{
+    unsigned i = t;
+    if (i >= TCG_TYPE_V64) {
+        tcg_debug_assert(i < TCG_TYPE_COUNT);
+        i -= TCG_TYPE_V64 - 1;
+    }
+    return 4 << i;

I'd feel safer if we assign TCG_TYPE_I32 .. TCG_TYPE_V256 in TCGType,
just in case.

+}

Reviewed-by: Philippe Mathieu-Daudé <phi...@linaro.org>


Reply via email to