Home | History | Annotate | Download | only in arm-neon-tests
      1 /*
      2 
      3 Copyright (c) 2009, 2010, 2011 STMicroelectronics
      4 Written by Christophe Lyon
      5 
      6 Permission is hereby granted, free of charge, to any person obtaining a copy
      7 of this software and associated documentation files (the "Software"), to deal
      8 in the Software without restriction, including without limitation the rights
      9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     10 copies of the Software, and to permit persons to whom the Software is
     11 furnished to do so, subject to the following conditions:
     12 
     13 The above copyright notice and this permission notice shall be included in
     14 all copies or substantial portions of the Software.
     15 
     16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     22 THE SOFTWARE.
     23 
     24 */
     25 
     26 #if defined(__arm__) || defined(__aarch64__)
     27 #include <arm_neon.h>
     28 #else
     29 #include "stm-arm-neon.h"
     30 #endif
     31 
     32 #include "stm-arm-neon-ref.h"
     33 
     34 #if defined(__cplusplus)
     35 #include <cstdint>
     36 #else
     37 #if defined(_MSC_VER)
     38 #include "msstdint.h"
     39 #else
     40 #include <stdint.h>
     41 #endif
     42 #endif
     43 
     44 #ifndef INSN_NAME
     45 #define INSN_NAME vaddhn
     46 #define TEST_MSG "VADDHN"
     47 #endif
     48 
     49 #define FNNAME1(NAME) void exec_ ## NAME (void)
     50 #define FNNAME(NAME) FNNAME1(NAME)
     51 
     52 FNNAME (INSN_NAME)
     53 {
     54   /* Basic test: vec64=vaddhn(vec128_a, vec128_b), then store the result.  */
     55 #define TEST_VADDHN1(INSN, T1, T2, W, W2, N)				\
     56   VECT_VAR(vector64, T1, W2, N) = INSN##_##T2##W(VECT_VAR(vector1, T1, W, N), \
     57 						 VECT_VAR(vector2, T1, W, N)); \
     58   vst1_##T2##W2(VECT_VAR(result, T1, W2, N), VECT_VAR(vector64, T1, W2, N))
     59 
     60 #define TEST_VADDHN(INSN, T1, T2, W, W2, N)				\
     61   TEST_VADDHN1(INSN, T1, T2, W, W2, N)
     62 
     63   /* With ARM RVCT, we need to declare variables before any executable
     64      statement */
     65   DECL_VARIABLE_64BITS_VARIANTS(vector64);
     66   DECL_VARIABLE_128BITS_VARIANTS(vector1);
     67   DECL_VARIABLE_128BITS_VARIANTS(vector2);
     68 
     69   clean_results ();
     70 
     71   /* Fill input vector1 and vector2 with arbitrary values */
     72   VDUP(vector1, q, int, s, 16, 8, 50*(UINT8_MAX+1));
     73   VDUP(vector1, q, int, s, 32, 4, 50*(UINT16_MAX+1));
     74   VDUP(vector1, q, int, s, 64, 2, 24*((uint64_t)UINT32_MAX+1));
     75   VDUP(vector1, q, uint, u, 16, 8, 3*(UINT8_MAX+1));
     76   VDUP(vector1, q, uint, u, 32, 4, 55*(UINT16_MAX+1));
     77   VDUP(vector1, q, uint, u, 64, 2, 3*((uint64_t)UINT32_MAX+1));
     78 
     79   VDUP(vector2, q, int, s, 16, 8, (uint16_t)UINT8_MAX);
     80   VDUP(vector2, q, int, s, 32, 4, (uint32_t)UINT16_MAX);
     81   VDUP(vector2, q, int, s, 64, 2, (uint64_t)UINT32_MAX);
     82   VDUP(vector2, q, uint, u, 16, 8, (uint16_t)UINT8_MAX);
     83   VDUP(vector2, q, uint, u, 32, 4, (uint32_t)UINT16_MAX);
     84   VDUP(vector2, q, uint, u, 64, 2, (uint64_t)UINT32_MAX);
     85 
     86   TEST_VADDHN(INSN_NAME, int, s, 16, 8, 8);
     87   TEST_VADDHN(INSN_NAME, int, s, 32, 16, 4);
     88   TEST_VADDHN(INSN_NAME, int, s, 64, 32, 2);
     89   TEST_VADDHN(INSN_NAME, uint, u, 16, 8, 8);
     90   TEST_VADDHN(INSN_NAME, uint, u, 32, 16, 4);
     91   TEST_VADDHN(INSN_NAME, uint, u, 64, 32, 2);
     92 
     93   dump_results_hex (TEST_MSG);
     94 }
     95