Path: blob/main/test/benchmark/benchmark_sse3.cpp
6174 views
/*1* Copyright 2020 The Emscripten Authors. All rights reserved.2* Emscripten is available under two separate licenses, the MIT license and the3* University of Illinois/NCSA Open Source License. Both these licenses can be4* found in the LICENSE file.5*/6#include <pmmintrin.h>7#include "benchmark_sse.h"89int main() {10printf ("{ \"workload\": %u, \"results\": [\n", N);1112float *src_flt = alloc_float_buffer();13float *src2_flt = alloc_float_buffer();14float *dst_flt = alloc_float_buffer();15for(int i = 0; i < N; ++i) src_flt[i] = (float)(1.0 + (double)rand() / RAND_MAX);16for(int i = 0; i < N; ++i) src2_flt[i] = (float)(1.0 + (double)rand() / RAND_MAX);1718double *src_dbl = alloc_double_buffer();19double *src2_dbl = alloc_double_buffer();20double *dst_dbl = alloc_double_buffer();21for(int i = 0; i < N; ++i) src_dbl[i] = 1.0 + (double)rand() / RAND_MAX;22for(int i = 0; i < N; ++i) src2_dbl[i] = 1.0 + (double)rand() / RAND_MAX;2324int *src_int = alloc_int_buffer();25int *src2_int = alloc_int_buffer();26int *dst_int = alloc_int_buffer();27for(int i = 0; i < N; ++i) src_int[i] = rand();28for(int i = 0; i < N; ++i) src2_int[i] = rand();2930float scalarTime = 0.f;3132// Benchmarks start:33SETCHART("load");34LOAD_STORE_I("_mm_lddqu_si128", _mm_lddqu_si128, 0, _mm_store_si128, 0, 4);35LOAD_STORE_D("_mm_loaddup_pd", _mm_loaddup_pd, 0, _mm_store_pd, double*, 0, 2);3637SETCHART("double arithmetic");38BINARYOP_D_DD("_mm_addsub_pd", _mm_addsub_pd, _mm_load_pd(src_dbl), _mm_load_pd(src2_dbl));39BINARYOP_D_DD("_mm_hadd_pd", _mm_hadd_pd, _mm_load_pd(src_dbl), _mm_load_pd(src2_dbl));40BINARYOP_D_DD("_mm_hsub_pd", _mm_hsub_pd, _mm_load_pd(src_dbl), _mm_load_pd(src2_dbl));4142SETCHART("double swizzle");43UNARYOP_D_D("_mm_movedup_pd", _mm_movedup_pd, _mm_load_pd(src_dbl));4445SETCHART("float arithmetic");46BINARYOP_F_FF("_mm_addsub_ps", _mm_addsub_ps, _mm_load_ps(src_flt), _mm_load_ps(src2_flt));47BINARYOP_F_FF("_mm_hadd_ps", _mm_hadd_ps, _mm_load_ps(src_flt), _mm_load_ps(src2_flt));48BINARYOP_F_FF("_mm_hsub_ps", _mm_hsub_ps, _mm_load_ps(src_flt), _mm_load_ps(src2_flt));4950SETCHART("float swizzle");51UNARYOP_F_F("_mm_movehdup_ps", _mm_movehdup_ps, _mm_load_ps(src_flt));52UNARYOP_F_F("_mm_moveldup_ps", _mm_moveldup_ps, _mm_load_ps(src_flt));5354// Benchmarks end:55printf("]}\n");56}575859