[Libva] [PATCH v2] test: use valarray for raw image comparison
Scott D Phillips
scott.d.phillips at intel.com
Mon Oct 17 20:00:51 UTC 2016
std::valarray can fuse elementwise operations across arrays for
more efficient comparison.
Signed-off-by: Scott D Phillips <scott.d.phillips at intel.com>
---
Changes since v1:
- s/width * height/sizes/
- Added another array 'signs' which ensures that 0 and 255 never
compare as separated by one.
Also, the patch about /dev/urandom actually was accidentally
generating all zeroes instead of random data. Fixing the bug
there eliminated the performance gain, so I'm dropping that patch
from the series.
test/i965_jpeg_encode_test.cpp | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/test/i965_jpeg_encode_test.cpp b/test/i965_jpeg_encode_test.cpp
index 29c14dc..173cd93 100644
--- a/test/i965_jpeg_encode_test.cpp
+++ b/test/i965_jpeg_encode_test.cpp
@@ -30,6 +30,7 @@
#include <cstring>
#include <memory>
#include <tuple>
+#include <valarray>
namespace JPEG {
namespace Encode {
@@ -400,23 +401,19 @@ protected:
ASSERT_EQ(expect->height(), image.height);
ASSERT_NO_FAILURE(uint8_t *data = mapBuffer<uint8_t>(image.buf));
- auto isClose = [](const uint8_t& a, const uint8_t& b) {
- return std::abs(int(a)-int(b)) <= 2;
- };
-
for (size_t i(0); i < image.num_planes; ++i) {
- size_t w = expect->widths[i];
- size_t h = expect->heights[i];
-
- const ByteData::value_type *source = expect->plane(i);
- const uint8_t *result = data + image.offsets[i];
- ASSERT_GE(image.pitches[i], w);
- for (size_t r(0); r < h; ++r) {
- EXPECT_TRUE(std::equal(result, result + w, source, isClose))
- << "Byte(s) mismatch in plane " << i << " row " << r;
- source += w;
- result += image.pitches[i];
- }
+ ASSERT_GE(image.pitches[i], expect->widths[i]);
+ std::valarray<uint8_t> source(expect->plane(i), expect->sizes[i]);
+ std::gslice result_slice(0, {expect->heights[i], expect->widths[i]},
+ {image.pitches[i], 1});
+ std::valarray<uint8_t> result = std::valarray<uint8_t>(
+ data + image.offsets[i],
+ image.pitches[i] * expect->heights[i])[result_slice];
+ std::valarray<uint8_t> signs(1, result.size());
+ signs[result > source] = -1;
+ ASSERT_EQ(source.size(), result.size());
+ EXPECT_TRUE((source * signs - result * signs).max() <= 2)
+ << "Byte(s) mismatch in plane " << i;
}
unmapBuffer(image.buf);
--
2.7.4
More information about the Libva
mailing list