Adding minor iree/base/ time, string view, and memory utilities.
diff --git a/runtime/src/iree/base/allocator.h b/runtime/src/iree/base/allocator.h
index 480e9ad..0d5f7a9 100644
--- a/runtime/src/iree/base/allocator.h
+++ b/runtime/src/iree/base/allocator.h
@@ -97,6 +97,18 @@
return iree_make_byte_span((uint8_t*)span.data, span.data_length);
}
+// Copies |size| bytes from |src| to |dst| without polluting the cache with
+// |dst| lines. Used when streaming data that will not be read again.
+static inline void iree_memcpy_stream_dst(void* IREE_RESTRICT dst,
+ const void* IREE_RESTRICT src,
+ iree_host_size_t size) {
+ // TODO(benvanik): implement a proper non-temporal copy. This will be
+ // architecture-specific and may have compiler-specific paths in order to emit
+ // the proper instructions. On x64 this should be using MOVNTDQ (or something
+ // in that family).
+ memcpy(dst, src, size);
+}
+
//===----------------------------------------------------------------------===//
// Totally shady stack allocation
//===----------------------------------------------------------------------===//
diff --git a/runtime/src/iree/base/assert.h b/runtime/src/iree/base/assert.h
index f6fd83e..0d6b4eb 100644
--- a/runtime/src/iree/base/assert.h
+++ b/runtime/src/iree/base/assert.h
@@ -57,7 +57,7 @@
// Assertions enabled:
-#define IREE_ASSERT(condition, ...) assert(condition)
+#define IREE_ASSERT(condition, ...) assert(IREE_UNLIKELY(condition))
// TODO(#2843): better logging of status assertions.
// #define IREE_ASSERT_OK(status) IREE_ASSERT(iree_status_is_ok(status))
diff --git a/runtime/src/iree/base/string_view.h b/runtime/src/iree/base/string_view.h
index 01e243c..048b468 100644
--- a/runtime/src/iree/base/string_view.h
+++ b/runtime/src/iree/base/string_view.h
@@ -89,6 +89,20 @@
return v;
}
+// A list of string key-value pairs.
+typedef struct iree_string_pair_list_t {
+ // Total number of pairs in the list.
+ iree_host_size_t count;
+ // Value list or NULL if no values.
+ const iree_string_pair_t* pairs;
+} iree_string_pair_list_t;
+
+// Returns an empty string pair list.
+static inline iree_string_pair_list_t iree_string_pair_list_empty(void) {
+ iree_string_pair_list_t v = {0, NULL};
+ return v;
+}
+
#define iree_string_view_literal(str) \
{ .data = (str), .size = IREE_ARRAYSIZE(str) - 1 }
@@ -106,6 +120,12 @@
const iree_string_view_t* values;
} iree_string_view_list_t;
+// Returns an empty string list.
+static inline iree_string_view_list_t iree_string_view_list_empty(void) {
+ iree_string_view_list_t v = {0, NULL};
+ return v;
+}
+
// Returns true if the two strings are equal (compare == 0).
IREE_API_EXPORT bool iree_string_view_equal(iree_string_view_t lhs,
iree_string_view_t rhs);
diff --git a/runtime/src/iree/base/time.h b/runtime/src/iree/base/time.h
index 89cad70..aaaa85e 100644
--- a/runtime/src/iree/base/time.h
+++ b/runtime/src/iree/base/time.h
@@ -173,6 +173,14 @@
: iree_relative_timeout_to_deadline_ns(timeout.nanos);
}
+// Returns a relative timeout duration in nanoseconds from the given timeout.
+static inline iree_duration_t iree_timeout_as_duration_ns(
+ iree_timeout_t timeout) {
+ return timeout.type == IREE_TIMEOUT_ABSOLUTE
+ ? iree_absolute_deadline_to_timeout_ns(timeout.nanos)
+ : timeout.nanos;
+}
+
// Returns the earliest timeout between |lhs| and |rhs|.
static inline iree_timeout_t iree_timeout_min(iree_timeout_t lhs,
iree_timeout_t rhs) {