shithub: libvpx

Download patch

ref: 10f8b36146efff888448316775007b39da31b011
parent: 8bec177dc441c0f619f80471205ddeaa249e2e12
author: James Zern <jzern@google.com>
date: Mon Aug 27 13:13:09 EDT 2012

msvs/tests: fix data alignment for asm tests

Replace DECLARE_ALIGNED_ with vpx_memalign()

DECLARE_ALIGNED (__declspec(align())) does not work as intended when
used on class data members:

Data in classes or structures is aligned within the class or structure
at the minimum of its natural alignment and the current packing setting
(from #pragma pack or the /Zp compiler option)

Change-Id: I304aaa6c3716fbfae24675ecf192f4b40787e83e

--- a/test/intrapred_test.cc
+++ b/test/intrapred_test.cc
@@ -16,6 +16,7 @@
 #include "vpx_config.h"
 #include "vpx_rtcd.h"
 #include "vp8/common/blockd.h"
+#include "vpx_mem/vpx_mem.h"
 }
 
 namespace {
@@ -216,9 +217,27 @@
 
 class IntraPredYTest : public ::testing::TestWithParam<intra_pred_y_fn_t>,
     protected IntraPredBase {
+ public:
+  static void SetUpTestCase() {
+    data_array_ = reinterpret_cast<uint8_t*>(
+        vpx_memalign(kDataAlignment, kDataBufferSize));
+  }
+
+  static void TearDownTestCase() {
+    vpx_free(data_array_);
+    data_array_ = NULL;
+  }
+
  protected:
   static const int kBlockSize = 16;
+  static const int kDataAlignment = 16;
   static const int kStride = kBlockSize * 3;
+  // We use 48 so that the data pointer of the first pixel in each row of
+  // each macroblock is 16-byte aligned, and this gives us access to the
+  // top-left and top-right corner pixels belonging to the top-left/right
+  // macroblocks.
+  // We use 17 lines so we have one line above us for top-prediction.
+  static const int kDataBufferSize = kStride * (kBlockSize + 1);
 
   virtual void SetUp() {
     pred_fn_ = GetParam();
@@ -232,14 +251,11 @@
   }
 
   intra_pred_y_fn_t pred_fn_;
-  // We use 48 so that the data pointer of the first pixel in each row of
-  // each macroblock is 16-byte aligned, and this gives us access to the
-  // top-left and top-right corner pixels belonging to the top-left/right
-  // macroblocks.
-  // We use 17 lines so we have one line above us for top-prediction.
-  DECLARE_ALIGNED(16, uint8_t, data_array_[kStride * (kBlockSize + 1)]);
+  static uint8_t* data_array_;
 };
 
+uint8_t* IntraPredYTest::data_array_ = NULL;
+
 TEST_P(IntraPredYTest, IntraPredTests) {
   RunTest();
 }
@@ -270,9 +286,28 @@
 
 class IntraPredUVTest : public ::testing::TestWithParam<intra_pred_uv_fn_t>,
     protected IntraPredBase {
+ public:
+  static void SetUpTestCase() {
+    data_array_ = reinterpret_cast<uint8_t*>(
+        vpx_memalign(kDataAlignment, kDataBufferSize));
+  }
+
+  static void TearDownTestCase() {
+    vpx_free(data_array_);
+    data_array_ = NULL;
+  }
+
  protected:
   static const int kBlockSize = 8;
+  static const int kDataAlignment = 8;
   static const int kStride = kBlockSize * 3;
+  // We use 24 so that the data pointer of the first pixel in each row of
+  // each macroblock is 8-byte aligned, and this gives us access to the
+  // top-left and top-right corner pixels belonging to the top-left/right
+  // macroblocks.
+  // We use 9 lines so we have one line above us for top-prediction.
+  // [0] = U, [1] = V
+  static const int kDataBufferSize = 2 * kStride * (kBlockSize + 1);
 
   virtual void SetUp() {
     pred_fn_ = GetParam();
@@ -293,8 +328,10 @@
   // macroblocks.
   // We use 9 lines so we have one line above us for top-prediction.
   // [0] = U, [1] = V
-  DECLARE_ALIGNED(8, uint8_t, data_array_[2 * kStride * (kBlockSize + 1)]);
+  static uint8_t* data_array_;
 };
+
+uint8_t* IntraPredUVTest::data_array_ = NULL;
 
 TEST_P(IntraPredUVTest, IntraPredTests) {
   RunTest();
--- a/test/sad_test.cc
+++ b/test/sad_test.cc
@@ -17,6 +17,7 @@
 #include "./vpx_config.h"
 #include "./vpx_rtcd.h"
 #include "vp8/common/blockd.h"
+#include "vpx_mem/vpx_mem.h"
 }
 
 #include "test/acm_random.h"
@@ -34,7 +35,25 @@
 
 namespace {
 class SADTest : public PARAMS(int, int, sad_m_by_n_fn_t) {
-  protected:
+ public:
+  static void SetUpTestCase() {
+    source_data_ = reinterpret_cast<uint8_t*>(
+        vpx_memalign(kDataAlignment, kDataBufferSize));
+    reference_data_ = reinterpret_cast<uint8_t*>(
+        vpx_memalign(kDataAlignment, kDataBufferSize));
+  }
+
+  static void TearDownTestCase() {
+    vpx_free(source_data_);
+    source_data_ = NULL;
+    vpx_free(reference_data_);
+    reference_data_ = NULL;
+  }
+
+ protected:
+  static const int kDataAlignment = 16;
+  static const int kDataBufferSize = 16 * 32;
+
   virtual void SetUp() {
     sad_fn_ = GET_PARAM(2);
     height_ = GET_PARAM(1);
@@ -100,13 +119,16 @@
 
   // Handle blocks up to 16x16 with stride up to 32
   int height_, width_;
-  DECLARE_ALIGNED(16, uint8_t, source_data_[16*32]);
+  static uint8_t* source_data_;
   int source_stride_;
-  DECLARE_ALIGNED(16, uint8_t, reference_data_[16*32]);
+  static uint8_t* reference_data_;
   int reference_stride_;
 
   ACMRandom rnd_;
 };
+
+uint8_t* SADTest::source_data_ = NULL;
+uint8_t* SADTest::reference_data_ = NULL;
 
 TEST_P(SADTest, MaxRef) {
   FillConstant(source_data_, source_stride_, 0);
--- a/test/sixtap_predict_test.cc
+++ b/test/sixtap_predict_test.cc
@@ -17,8 +17,8 @@
 extern "C" {
 #include "./vpx_config.h"
 #include "./vpx_rtcd.h"
-#include "vpx_ports/mem.h"
 #include "vpx/vpx_integer.h"
+#include "vpx_mem/vpx_mem.h"
 }
 
 namespace {
@@ -31,11 +31,30 @@
                                     int  dst_pitch);
 
 class SixtapPredictTest : public PARAMS(int, int, sixtap_predict_fn_t) {
+ public:
+  static void SetUpTestCase() {
+    src_ = reinterpret_cast<uint8_t*>(vpx_memalign(kDataAlignment, kSrcSize));
+    dst_ = reinterpret_cast<uint8_t*>(vpx_memalign(kDataAlignment, kDstSize));
+    dst_c_ = reinterpret_cast<uint8_t*>(vpx_memalign(kDataAlignment, kDstSize));
+  }
+
+  static void TearDownTestCase() {
+    vpx_free(src_);
+    src_ = NULL;
+    vpx_free(dst_);
+    dst_ = NULL;
+    vpx_free(dst_c_);
+    dst_c_ = NULL;
+  }
+
  protected:
   // Make test arrays big enough for 16x16 functions. Six-tap filters
   // need 5 extra pixels outside of the macroblock.
   static const int kSrcStride = 21;
   static const int kDstStride = 16;
+  static const int kDataAlignment = 16;
+  static const int kSrcSize = kSrcStride * kSrcStride + 1;
+  static const int kDstSize = kDstStride * kDstStride;
 
   virtual void SetUp() {
     width_ = GET_PARAM(0);
@@ -52,17 +71,18 @@
   // The src stores the macroblock we will filter on, and makes it 1 byte larger
   // in order to test unaligned access. The result is stored in dst and dst_c(c
   // reference code result).
-  DECLARE_ALIGNED(16, uint8_t, src_[kSrcStride * kSrcStride + 1]);
-  DECLARE_ALIGNED(16, uint8_t, dst_[kDstStride * kDstStride]);
-  DECLARE_ALIGNED(16, uint8_t, dst_c_[kDstStride * kDstStride]);
+  static uint8_t* src_;
+  static uint8_t* dst_;
+  static uint8_t* dst_c_;
 };
 
-TEST_P(SixtapPredictTest, TestWithPresetData) {
-  const size_t src_size = sizeof(src_) / sizeof(uint8_t);
-  const size_t dst_size = sizeof(dst_) / sizeof(uint8_t);
+uint8_t* SixtapPredictTest::src_ = NULL;
+uint8_t* SixtapPredictTest::dst_ = NULL;
+uint8_t* SixtapPredictTest::dst_c_ = NULL;
 
+TEST_P(SixtapPredictTest, TestWithPresetData) {
   // Test input
-  static const uint8_t test_data[src_size] = {
+  static const uint8_t test_data[kSrcSize] = {
     216, 184, 4, 191, 82, 92, 41, 0, 1, 226, 236, 172, 20, 182, 42, 226, 177,
     79, 94, 77, 179, 203, 206, 198, 22, 192, 19, 75, 17, 192, 44, 233, 120,
     48, 168, 203, 141, 210, 203, 143, 180, 184, 59, 201, 110, 102, 171, 32,
@@ -94,7 +114,7 @@
   };
 
   // Expected result
-  static const uint8_t expected_dst[dst_size] = {
+  static const uint8_t expected_dst[kDstSize] = {
     117, 102, 74, 135, 42, 98, 175, 206, 70, 73, 222, 197, 50, 24, 39, 49, 38,
     105, 90, 47, 169, 40, 171, 215, 200, 73, 109, 141, 53, 85, 177, 164, 79,
     208, 124, 89, 212, 18, 81, 145, 151, 164, 217, 153, 91, 154, 102, 102,
@@ -128,10 +148,8 @@
 using libvpx_test::ACMRandom;
 
 TEST_P(SixtapPredictTest, TestWithRandomData) {
-  const size_t src_size = sizeof(src_) / sizeof(uint8_t);
-
   ACMRandom rnd(ACMRandom::DeterministicSeed());
-  for (size_t i = 0; i < src_size; ++i)
+  for (int i = 0; i < kSrcSize; ++i)
     src_[i] = rnd.Rand8();
 
   // Run tests for all possible offsets.