summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-16 23:35:59 -0400
committerbd <bdunahu@operationnull.com>2025-04-16 23:35:59 -0400
commit796b2691146a3a4eaace4fa155d3c0c2f7379832 (patch)
tree8dd83f646bd9ef29ff3c3c492e4f64485d44c1b7 /inc
parent23d3ebb2702e6b08c7f6b997067e1bc76483b813 (diff)
Fix a bug related to parsing immediates in decode
Diffstat (limited to 'inc')
-rw-r--r--inc/pipe_spec.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/inc/pipe_spec.h b/inc/pipe_spec.h
index 772314e..d211b72 100644
--- a/inc/pipe_spec.h
+++ b/inc/pipe_spec.h
@@ -65,4 +65,21 @@
*/
#define GET_MID_BITS(k, m, n) GET_LS_BITS((k) >> (m), ((n) - (m)))
+/**
+ * Return the bits from integer K starting at N and ending at M using a bit
+ * mask, but sign-extends the result. This is required to parse immediates.
+ * @param the integer to be parsed
+ * @param the index of the starting bit to be parsed
+ * @param the index of the ending bit to be parsed
+ * @return a section of bits from K
+ */
+// clang-format off
+#define GET_BITS_SIGN_EXTEND(k, m, n) \
+ ({\
+ int _f = GET_MID_BITS(k, m, n); \
+ int _w = (n) - (m) - (1); \
+ _f = (_f & (1 << (_w - 1))) ? (_f | (-1 << _w)) : _f; \
+ })
+// clang-format on
+
#endif /* DEFINITIONS_H_INCLUDED */