11844Swollman/* { dg-do run } */ 250476Speter/* { dg-require-effective-target ssse3 } */ 323549Swosch/* { dg-options "-O2 -fno-strict-aliasing -mssse3" } */ 423549Swosch 535784Swosch#ifndef CHECK_H 623549Swosch#define CHECK_H "ssse3-check.h" 723549Swosch#endif 823549Swosch 923549Swosch#ifndef TEST 1023549Swosch#define TEST ssse3_test 1123549Swosch#endif 1223549Swosch 1323549Swosch#include CHECK_H 1423549Swosch 1595327Sobrien#include "ssse3-vals.h" 1623549Swosch 1723549Swosch#include <tmmintrin.h> 1823549Swosch 1923549Swosch#ifndef __AVX__ 2023549Swosch/* Test the 64-bit form */ 2123549Swoschstatic void 2223549Swoschssse3_test_phaddw (int *i1, int *i2, int *r) 2323549Swosch{ 2423549Swosch __m64 t1 = *(__m64 *) i1; 2523549Swosch __m64 t2 = *(__m64 *) i2; 2623549Swosch *(__m64 *) r = _mm_hadd_pi16 (t1, t2); 2795509Sru _mm_empty (); 2896164Sru} 2944922Sbde#endif 3023549Swosch 311638Srgrimes/* Test the 128-bit form */ 3294940Srustatic void 3323549Swoschssse3_test_phaddw128 (int *i1, int *i2, int *r) 3499875Sru{ 3599875Sru /* Assumes incoming pointers are 16-byte aligned */ 3699875Sru __m128i t1 = *(__m128i *) i1; 3799875Sru __m128i t2 = *(__m128i *) i2; 38133369Sharti *(__m128i *) r = _mm_hadd_epi16 (t1, t2); 3999875Sru} 4099875Sru 4199875Sru/* Routine to manually compute the results */ 4299875Srustatic void 4395306Srucompute_correct_result(int *i1, int *i2, int *r) 4499875Sru{ 45133369Sharti short *s1 = (short *) i1; 4695306Sru short *s2 = (short *) i2; 47134903Simp short *sout = (short *) r; 4890311Sru int i; 4990311Sru 5090311Sru for (i = 0; i < 4; i++) 51134903Simp sout[i] = s1[2 * i] + s1[2 * i + 1]; 5290311Sru 5390311Sru for (i = 0; i < 4; i++) 5490311Sru sout[i + 4] = s2[2 * i] + s2[2 * i + 1]; 5590311Sru} 5695306Sru 571638Srgrimesstatic void 5895306SruTEST (void) 591638Srgrimes{ 601638Srgrimes int i; 61133369Sharti int r [4] __attribute__ ((aligned(16))); 6253152Smarcel int ck [4]; 631638Srgrimes int fail = 0; 641638Srgrimes 651638Srgrimes for (i = 0; i < 256; i += 8) 66133369Sharti { 671638Srgrimes /* Manually compute the result */ 681638Srgrimes compute_correct_result (&vals[i + 0], &vals[i + 4], ck); 6995509Sru 7096668Sru#ifndef __AVX__ 7195356Sru /* Run the 64-bit tests */ 7295306Sru ssse3_test_phaddw (&vals[i + 0], &vals[i + 2], &r[0]); 7315061Swosch ssse3_test_phaddw (&vals[i + 4], &vals[i + 6], &r[2]); 741638Srgrimes fail += chk_128 (ck, r); 7597769Sru#endif 7696668Sru 7796668Sru /* Run the 128-bit tests */ 7896668Sru ssse3_test_phaddw128 (&vals[i + 0], &vals[i + 4], r); 7996668Sru fail += chk_128 (ck, r); 8096668Sru } 8196668Sru 8296668Sru if (fail != 0) 83133369Sharti abort (); 8496668Sru} 8596668Sru