LCOV - code coverage report
Current view: top level - autotest/cpp - testsse.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 173 173 100.0 %
Date: 2024-11-21 22:18:42 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include <stdio.h>
       2             : 
       3             : #include "gdalsse_priv.h"
       4             : 
       5             : #define MY_ASSERT(x)                                                           \
       6             :     do                                                                         \
       7             :     {                                                                          \
       8             :         if (!(x))                                                              \
       9             :         {                                                                      \
      10             :             printf("test at line %d failed !\n", __LINE__);                    \
      11             :             exit(1);                                                           \
      12             :         }                                                                      \
      13             :     } while (0)
      14             : 
      15           2 : int main()
      16             : {
      17             :     {
      18           2 :         double x = 1.23;
      19           2 :         XMMReg4Double reg = XMMReg4Double::Load1ValHighAndLow(&x);
      20             :         double res[4];
      21           2 :         reg.Store4Val(res);
      22           2 :         MY_ASSERT(res[0] == x);
      23           2 :         MY_ASSERT(res[1] == x);
      24           2 :         MY_ASSERT(res[2] == x);
      25           2 :         MY_ASSERT(res[3] == x);
      26             :     }
      27             : 
      28             :     {
      29           2 :         unsigned char input[] = {1, 2, 3, 4};
      30           2 :         XMMReg4Double reg = XMMReg4Double::Load4Val(input);
      31             :         double res[4];
      32           2 :         reg.Store4Val(res);
      33           2 :         MY_ASSERT(res[0] == input[0]);
      34           2 :         MY_ASSERT(res[1] == input[1]);
      35           2 :         MY_ASSERT(res[2] == input[2]);
      36           2 :         MY_ASSERT(res[3] == input[3]);
      37             : 
      38             :         unsigned char output[4];
      39           2 :         reg.Store4Val(output);
      40           2 :         MY_ASSERT(output[0] == input[0]);
      41           2 :         MY_ASSERT(output[1] == input[1]);
      42           2 :         MY_ASSERT(output[2] == input[2]);
      43           2 :         MY_ASSERT(output[3] == input[3]);
      44             :     }
      45             : 
      46             :     {
      47           2 :         unsigned short input[] = {1, 65535, 3, 65534};
      48           2 :         XMMReg4Double reg = XMMReg4Double::Load4Val(input);
      49             :         double res[4];
      50           2 :         reg.Store4Val(res);
      51           2 :         MY_ASSERT(res[0] == input[0]);
      52           2 :         MY_ASSERT(res[1] == input[1]);
      53           2 :         MY_ASSERT(res[2] == input[2]);
      54           2 :         MY_ASSERT(res[3] == input[3]);
      55             : 
      56             :         unsigned short output[4];
      57           2 :         reg.Store4Val(output);
      58           2 :         MY_ASSERT(output[0] == input[0]);
      59           2 :         MY_ASSERT(output[1] == input[1]);
      60           2 :         MY_ASSERT(output[2] == input[2]);
      61           2 :         MY_ASSERT(output[3] == input[3]);
      62             :     }
      63             : 
      64             :     {
      65           2 :         short input[] = {1, 32767, 3, -32768};
      66           2 :         XMMReg4Double reg = XMMReg4Double::Load4Val(input);
      67             :         double res[4];
      68           2 :         reg.Store4Val(res);
      69           2 :         MY_ASSERT(res[0] == input[0]);
      70           2 :         MY_ASSERT(res[1] == input[1]);
      71           2 :         MY_ASSERT(res[2] == input[2]);
      72           2 :         MY_ASSERT(res[3] == input[3]);
      73             :     }
      74             : 
      75             :     {
      76           2 :         float input[] = {1.0f, 2.0f, 3.0f, 4.0f};
      77           2 :         XMMReg4Double reg = XMMReg4Double::Load4Val(input);
      78             :         double res[4];
      79           2 :         reg.Store4Val(res);
      80           2 :         MY_ASSERT(res[0] == input[0]);
      81           2 :         MY_ASSERT(res[1] == input[1]);
      82           2 :         MY_ASSERT(res[2] == input[2]);
      83           2 :         MY_ASSERT(res[3] == input[3]);
      84             : 
      85             :         float output[4];
      86           2 :         reg.Store4Val(output);
      87           2 :         MY_ASSERT(output[0] == input[0]);
      88           2 :         MY_ASSERT(output[1] == input[1]);
      89           2 :         MY_ASSERT(output[2] == input[2]);
      90           2 :         MY_ASSERT(output[3] == input[3]);
      91             :     }
      92             : 
      93             :     {
      94           2 :         double input[] = {1.0, 2.0, 3.0, 4.0};
      95           2 :         XMMReg4Double reg = XMMReg4Double::Load4Val(input);
      96             :         double res[4];
      97           2 :         reg.Store4Val(res);
      98           2 :         MY_ASSERT(res[0] == input[0]);
      99           2 :         MY_ASSERT(res[1] == input[1]);
     100           2 :         MY_ASSERT(res[2] == input[2]);
     101           2 :         MY_ASSERT(res[3] == input[3]);
     102             : 
     103           2 :         MY_ASSERT(reg.GetHorizSum() ==
     104             :                   input[0] + input[1] + input[2] + input[3]);
     105             : 
     106           2 :         double input2[] = {100.0, 200.0};
     107           2 :         reg.AddToLow(XMMReg2Double::Load2Val(input2));
     108           2 :         reg.Store4Val(res);
     109           2 :         MY_ASSERT(res[0] == input[0] + input2[0]);
     110           2 :         MY_ASSERT(res[1] == input[1] + input2[1]);
     111           2 :         MY_ASSERT(res[2] == input[2]);
     112           2 :         MY_ASSERT(res[3] == input[3]);
     113             :     }
     114             : 
     115             :     {
     116           2 :         double input[] = {1.0, 2.0, 3.0, 4.0};
     117           2 :         double input2[] = {10.0, 9.0, 8.0, 7.0};
     118           2 :         XMMReg4Double reg = XMMReg4Double::Load4Val(input);
     119           2 :         XMMReg4Double reg2 = XMMReg4Double::Load4Val(input2);
     120             : 
     121             :         double res[4];
     122             : 
     123           2 :         (reg + reg2).Store4Val(res);
     124           2 :         MY_ASSERT(res[0] == input[0] + input2[0]);
     125           2 :         MY_ASSERT(res[1] == input[1] + input2[1]);
     126           2 :         MY_ASSERT(res[2] == input[2] + input2[2]);
     127           2 :         MY_ASSERT(res[3] == input[3] + input2[3]);
     128             : 
     129           2 :         reg += reg2;
     130           2 :         reg.Store4Val(res);
     131           2 :         MY_ASSERT(res[0] == input[0] + input2[0]);
     132           2 :         MY_ASSERT(res[1] == input[1] + input2[1]);
     133           2 :         MY_ASSERT(res[2] == input[2] + input2[2]);
     134           2 :         MY_ASSERT(res[3] == input[3] + input2[3]);
     135             : 
     136           2 :         reg = reg - reg2;
     137           2 :         reg.Store4Val(res);
     138           2 :         MY_ASSERT(res[0] == input[0]);
     139           2 :         MY_ASSERT(res[1] == input[1]);
     140           2 :         MY_ASSERT(res[2] == input[2]);
     141           2 :         MY_ASSERT(res[3] == input[3]);
     142             : 
     143           2 :         (reg * reg2).Store4Val(res);
     144           2 :         MY_ASSERT(res[0] == input[0] * input2[0]);
     145           2 :         MY_ASSERT(res[1] == input[1] * input2[1]);
     146           2 :         MY_ASSERT(res[2] == input[2] * input2[2]);
     147           2 :         MY_ASSERT(res[3] == input[3] * input2[3]);
     148             : 
     149           2 :         (reg / reg2).Store4Val(res);
     150           2 :         MY_ASSERT(res[0] == input[0] / input2[0]);
     151           2 :         MY_ASSERT(res[1] == input[1] / input2[1]);
     152           2 :         MY_ASSERT(res[2] == input[2] / input2[2]);
     153           2 :         MY_ASSERT(res[3] == input[3] / input2[3]);
     154             : 
     155           2 :         reg *= reg2;
     156           2 :         reg.Store4Val(res);
     157           2 :         MY_ASSERT(res[0] == input[0] * input2[0]);
     158           2 :         MY_ASSERT(res[1] == input[1] * input2[1]);
     159           2 :         MY_ASSERT(res[2] == input[2] * input2[2]);
     160           2 :         MY_ASSERT(res[3] == input[3] * input2[3]);
     161             : 
     162           2 :         reg = XMMReg4Double::Load4Val(input);
     163           2 :         reg2 = reg;
     164           2 :         reg2.Store4Val(res);
     165           2 :         MY_ASSERT(res[0] == input[0]);
     166           2 :         MY_ASSERT(res[1] == input[1]);
     167           2 :         MY_ASSERT(res[2] == input[2]);
     168           2 :         MY_ASSERT(res[3] == input[3]);
     169             : 
     170             :         unsigned char mask[32];
     171             : 
     172           2 :         XMMReg4Double::Equals(reg, reg).StoreMask(mask);
     173           2 :         MY_ASSERT(mask[0] == 0xFF);
     174           2 :         MY_ASSERT(mask[8] == 0xFF);
     175           2 :         MY_ASSERT(mask[16] == 0xFF);
     176           2 :         MY_ASSERT(mask[24] == 0xFF);
     177             : 
     178           2 :         XMMReg4Double::NotEquals(reg, reg).StoreMask(mask);
     179           2 :         MY_ASSERT(mask[0] == 0);
     180           2 :         MY_ASSERT(mask[8] == 0);
     181           2 :         MY_ASSERT(mask[16] == 0);
     182           2 :         MY_ASSERT(mask[24] == 0);
     183             : 
     184           2 :         XMMReg4Double::Greater(reg, reg).StoreMask(mask);
     185           2 :         MY_ASSERT(mask[0] == 0);
     186           2 :         MY_ASSERT(mask[8] == 0);
     187           2 :         MY_ASSERT(mask[16] == 0);
     188           2 :         MY_ASSERT(mask[24] == 0);
     189             : 
     190           2 :         double diff[] = {1.5, -1.5, -0.5, 0.5};
     191           2 :         XMMReg4Double::Greater(reg, reg + XMMReg4Double::Load4Val(diff))
     192           2 :             .StoreMask(mask);
     193           2 :         MY_ASSERT(mask[0] == 0);
     194           2 :         MY_ASSERT(mask[8] == 0xFF);
     195           2 :         MY_ASSERT(mask[16] == 0xFF);
     196           2 :         MY_ASSERT(mask[24] == 0);
     197             : 
     198           2 :         XMMReg4Double::Min(reg, reg + XMMReg4Double::Load4Val(diff))
     199           2 :             .Store4Val(res);
     200           2 :         MY_ASSERT(res[0] == input[0]);
     201           2 :         MY_ASSERT(res[1] == input[1] + diff[1]);
     202           2 :         MY_ASSERT(res[2] == input[2] + diff[2]);
     203           2 :         MY_ASSERT(res[3] == input[3]);
     204             : 
     205           2 :         reg = XMMReg4Double::Load4Val(input);
     206           2 :         XMMReg4Double reg_diff = XMMReg4Double::Load4Val(diff);
     207           2 :         XMMReg4Double::Ternary(XMMReg4Double::Greater(reg, reg + reg_diff), reg,
     208             :                                reg_diff)
     209           2 :             .Store4Val(res);
     210           2 :         MY_ASSERT(res[0] == diff[0]);
     211           2 :         MY_ASSERT(res[1] == input[1]);
     212           2 :         MY_ASSERT(res[2] == input[2]);
     213           2 :         MY_ASSERT(res[3] == diff[3]);
     214             :     }
     215             : 
     216             : #ifndef USE_SSE2_EMULATION
     217             :     {
     218           1 :         float input[] = {-1.3f, 1.5f, 40000.3f, 65537.0f};
     219             :         GUInt16 output[4];
     220           1 :         GDALCopy4Words(input, output);
     221           1 :         MY_ASSERT(output[0] == 0);
     222           1 :         MY_ASSERT(output[1] == 2);
     223           1 :         MY_ASSERT(output[2] == 40000);
     224           1 :         MY_ASSERT(output[3] == 65535);
     225             :     }
     226             : #endif
     227             : 
     228             : #ifndef USE_SSE2_EMULATION
     229             :     {
     230           1 :         float input[] = {-1.3f,    1.5f, 40000.3f, 65537.0f,
     231             :                          40000.3f, 1.3f, 65537.0f, -1.3f};
     232             :         GUInt16 output[8];
     233           1 :         GDALCopy8Words(input, output);
     234           1 :         MY_ASSERT(output[0] == 0);
     235           1 :         MY_ASSERT(output[1] == 2);
     236           1 :         MY_ASSERT(output[2] == 40000);
     237           1 :         MY_ASSERT(output[3] == 65535);
     238           1 :         MY_ASSERT(output[4] == 40000);
     239           1 :         MY_ASSERT(output[5] == 1);
     240           1 :         MY_ASSERT(output[6] == 65535);
     241           1 :         MY_ASSERT(output[7] == 0);
     242             :     }
     243             : 
     244             :     {
     245           1 :         float input[] = {-1.3f,    1.5f, 40000.3f, 65537.0f,
     246             :                          40000.3f, 1.3f, 65537.0f, -1.3f};
     247             :         unsigned char output[8];
     248           1 :         GDALCopy8Words<float, unsigned char>(input, output);
     249           1 :         MY_ASSERT(output[0] == 0);
     250           1 :         MY_ASSERT(output[1] == 2);
     251           1 :         MY_ASSERT(output[2] == 255);
     252           1 :         MY_ASSERT(output[3] == 255);
     253           1 :         MY_ASSERT(output[4] == 255);
     254           1 :         MY_ASSERT(output[5] == 1);
     255           1 :         MY_ASSERT(output[6] == 255);
     256           1 :         MY_ASSERT(output[7] == 0);
     257             :     }
     258             : 
     259             : #endif
     260             : 
     261           2 :     return 0;
     262             : }

Generated by: LCOV version 1.14