i965: Only insert error message if not already present
authorMatt Turner <mattst88@gmail.com>
Mon, 18 Sep 2017 21:07:20 +0000 (14:07 -0700)
committerMatt Turner <mattst88@gmail.com>
Wed, 4 Oct 2017 21:08:54 +0000 (14:08 -0700)
Some restrictions require something like strides to match between src
and dest. For multi-source instructions, I'd rather encapsulate the
logic for not inserting already present errors in ERROR_IF than
open-coding it multiple places.

src/intel/compiler/brw_eu_validate.c

index 99abc6b4f9ed3d5621272a50a8a81a6f52ca8893..8fcc5293666aeee3d0a07a5862e8eb40bb4884e5 100644 (file)
@@ -44,15 +44,23 @@ cat(struct string *dest, const struct string src)
 }
 #define CAT(dest, src) cat(&dest, (struct string){src, strlen(src)})
 
+static bool
+contains(const struct string haystack, const struct string needle)
+{
+   return memmem(haystack.str, haystack.len, needle.str, needle.len) != NULL;
+}
+#define CONTAINS(haystack, needle) \
+   contains(haystack, (struct string){needle, strlen(needle)})
+
 #define error(str)   "\tERROR: " str "\n"
 #define ERROR_INDENT "\t       "
 
 #define ERROR(msg) ERROR_IF(true, msg)
-#define ERROR_IF(cond, msg)          \
-   do {                              \
-      if (cond) {                    \
-         CAT(error_msg, error(msg)); \
-      }                              \
+#define ERROR_IF(cond, msg)                             \
+   do {                                                 \
+      if ((cond) && !CONTAINS(error_msg, error(msg))) { \
+         CAT(error_msg, error(msg));                    \
+      }                                                 \
    } while(0)
 
 #define CHECK(func, args...)                             \