Signed-off-by: Jordan Justen <[email protected]>
---
 tests/util/CMakeLists.txt    |    1 +
 tests/util/piglit-bitset.cpp |  139 ++++++++++++++++++++++++++++++++++++++++++
 tests/util/piglit-bitset.h   |   53 ++++++++++++++++
 3 files changed, 193 insertions(+)
 create mode 100644 tests/util/piglit-bitset.cpp
 create mode 100644 tests/util/piglit-bitset.h

diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt
index cbcf050..1d41f81 100644
--- a/tests/util/CMakeLists.txt
+++ b/tests/util/CMakeLists.txt
@@ -6,6 +6,7 @@ set(UTIL_INCLUDES
        )
 
 set(UTIL_SOURCES
+       piglit-bitset.cpp
        piglit-util.c
        )
 
diff --git a/tests/util/piglit-bitset.cpp b/tests/util/piglit-bitset.cpp
new file mode 100644
index 0000000..d77c5ee
--- /dev/null
+++ b/tests/util/piglit-bitset.cpp
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2013 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file piglit-bitset.cpp
+ */
+
+#include <vector>
+
+#include "piglit-bitset.h"
+
+class piglit_bitset
+{
+public:
+       piglit_bitset()
+               : v(), size_in_bits(0),
+                 all_bits_set(true), all_bits_clear(true)
+       {}
+
+       unsigned size()
+       {
+               return size_in_bits;
+       }
+
+       bool all_set()
+       {
+               return all_bits_set;
+       }
+
+       bool all_clear()
+       {
+               return all_bits_clear;
+       }
+
+       void append(bool bit);
+       bool is_set(unsigned pos);
+
+private:
+       std::vector<unsigned> v;
+       unsigned size_in_bits;
+       bool all_bits_set;
+       bool all_bits_clear;
+};
+
+void piglit_bitset::append(bool bit)
+{
+       all_bits_set = all_bits_set && bit;
+       all_bits_clear = all_bits_clear && !bit;
+       unsigned mask = 1u << (size_in_bits % (8 * sizeof(unsigned)));
+       unsigned word = size_in_bits / (8 * sizeof(unsigned));
+       if (mask == 1) {
+               v.push_back(0);
+       }
+       if (!bit) {
+               v[word] = v[word] & ~mask;
+       } else {
+               v[word] = v[word] | mask;
+       }
+       size_in_bits++;
+}
+
+bool piglit_bitset::is_set(unsigned pos)
+{
+       if (pos >= size_in_bits)
+               return false;
+       unsigned mask = 1u << (pos % (8 * sizeof(unsigned)));
+       unsigned word = pos / (8 * sizeof(unsigned));
+       return (v[word] & mask) != 0 ? true : false;
+}
+
+extern "C" {
+
+void*
+piglit_bitset_create(void)
+{
+       piglit_bitset *b = new piglit_bitset();
+       return (void*) b;
+}
+
+void
+piglit_bitset_destroy(void *bitset)
+{
+       piglit_bitset *b = (piglit_bitset *) bitset;
+       delete b;
+}
+
+unsigned
+piglit_bitset_size(void *bitset)
+{
+       piglit_bitset *b = (piglit_bitset *) bitset;
+       return b->size();
+}
+
+bool
+piglit_bitset_is_set(void *bitset, unsigned bit_num)
+{
+       return ((piglit_bitset *) bitset)->is_set(bit_num);
+}
+
+bool
+piglit_bitset_is_all_set(void *bitset)
+{
+       return ((piglit_bitset *) bitset)->all_set();
+}
+
+bool
+piglit_bitset_is_all_clear(void *bitset)
+{
+       return ((piglit_bitset *) bitset)->all_clear();
+}
+
+void
+piglit_bitset_append(void *bitset, bool bit)
+{
+       ((piglit_bitset *) bitset)->append(bit);
+}
+
+} // extern "C"
+
diff --git a/tests/util/piglit-bitset.h b/tests/util/piglit-bitset.h
new file mode 100644
index 0000000..6fdcd28
--- /dev/null
+++ b/tests/util/piglit-bitset.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void*
+piglit_bitset_create(void);
+
+void
+piglit_bitset_destroy(void *bitset);
+
+unsigned
+piglit_bitset_size(void *bitset);
+
+bool
+piglit_bitset_is_set(void *bitset, unsigned bit_num);
+
+bool
+piglit_bitset_is_all_set(void *bitset);
+
+bool
+piglit_bitset_is_all_clear(void *bitset);
+
+void
+piglit_bitset_append(void *bitset, bool bit);
+
+#ifdef __cplusplus
+} /* end extern "C" */
+#endif
-- 
1.7.10.4

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to