home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / test / source / TestSpanUtils.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  2.5 KB  |  110 lines

  1. #include <vd2/system/cpuaccel.h>
  2. #include <vd2/system/filesys.h>
  3. #include <vd2/system/memory.h>
  4. #include "..\..\Kasumi\h\blt_spanutils.h"
  5. #include "..\..\Kasumi\h\blt_spanutils_x86.h"
  6. #include "test.h"
  7.  
  8. DEFINE_TEST(SpanUtils) {
  9.     uint32 ext = CPUCheckForExtensions();
  10.     CPUEnableExtensions(ext);
  11.  
  12.     // horiz_expand2x_coaligned
  13.     for(int pass = 0; pass < 2; ++pass) {
  14.         void (*hfunc)(uint8 *dst, const uint8 *src, sint32 w);
  15.  
  16.         if (pass == 0)
  17.             hfunc = nsVDPixmapSpanUtils::horiz_expand2x_coaligned;
  18.         else if (pass == 1) {
  19. #ifdef _M_IX86
  20.             if (!(ext & CPUF_SUPPORTS_INTEGER_SSE))
  21.                 continue;
  22.  
  23.             hfunc = nsVDPixmapSpanUtils::horiz_expand2x_coaligned_ISSE;
  24. #else
  25.             continue;
  26. #endif
  27.         }
  28.  
  29.         uint8 dst[64];
  30.         uint8 src[32];
  31.  
  32.         for(int w = 1; w <= 32; ++w) {
  33.             memset(src, 0x40, sizeof src);
  34.             memset(dst, 0xCD, sizeof dst);
  35.  
  36.             int sw = (w + 1) >> 1;
  37.             for(int j=0; j<sw; ++j)
  38.                 src[4 + j] = j << 4;
  39.  
  40.             hfunc(dst+4, src+4, w);
  41.  
  42.             TEST_ASSERT(!VDMemCheck8(dst, 0xCD, 4));
  43.             TEST_ASSERT(!VDMemCheck8(dst + 4 + w, 0xCD, 60 - w));
  44.  
  45.             for(int j=0; j<w-1; ++j) {
  46.                 TEST_ASSERT(dst[4 + j] == (j << 3));
  47.             }
  48.             TEST_ASSERT(dst[3 + w] == ((sw - 1) << 4));
  49.         }
  50.     }
  51.  
  52.     // vert_expand2x_centered
  53.     for(int pass = 0; pass < 2; ++pass) {
  54.         void (*hfunc)(uint8 *dst, const uint8 *const *srcs, sint32 w, uint8 phase);
  55.  
  56.         if (pass == 0)
  57.             hfunc = nsVDPixmapSpanUtils::vert_expand2x_centered;
  58.         else if (pass == 1) {
  59. #ifdef _M_IX86
  60.             if (!(ext & CPUF_SUPPORTS_INTEGER_SSE))
  61.                 continue;
  62.  
  63.             hfunc = nsVDPixmapSpanUtils::vert_expand2x_centered_ISSE;
  64. #else
  65.             continue;
  66. #endif
  67.         }
  68.  
  69.         uint8 dst[64];
  70.         uint8 src1[64];
  71.         uint8 src2[64];
  72.  
  73.         for(int inv = 0; inv < 2; ++inv) {
  74.             uint8 phase = inv ? 0xc0 : 0x40;
  75.  
  76.             const uint8 *const srcs[2]={src1 + 4, src2 + 4};
  77.  
  78.             for(int w = 1; w <= 32; ++w) {
  79.                 memset(src1, 0x40, sizeof src1);
  80.                 memset(src2, 0x40, sizeof src2);
  81.                 memset(dst, 0xCD, sizeof dst);
  82.  
  83.                 for(int j=0; j<w; ++j) {
  84.                     src1[4 + j] = (uint8)(rand() & 0xff);
  85.                     src2[4 + j] = (uint8)(rand() & 0xff);
  86.                 }
  87.  
  88.                 hfunc(dst + 4, srcs, w, phase);
  89.  
  90.                 TEST_ASSERT(!VDMemCheck8(dst, 0xCD, 4));
  91.                 TEST_ASSERT(!VDMemCheck8(dst + 4 + w, 0xCD, 60 - w));
  92.  
  93.                 const uint8 *chk1 = inv ? src1 : src2;
  94.                 const uint8 *chk3 = inv ? src2 : src1;
  95.  
  96.                 for(int j=0; j<w-1; ++j) {
  97.                     uint32 c3 = chk3[4 + j];
  98.                     uint32 c1 = chk1[4 + j];
  99.                     uint32 cc = (3*c3 + c1 + 2) >> 2;
  100.                     uint32 cr = dst[4 + j];
  101.  
  102.                     TEST_ASSERT(cr == cc);
  103.                 }
  104.             }
  105.         }
  106.     }
  107.  
  108.     return 0;
  109. }
  110.