Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/benchmark/benchmark_sse3.cpp
6174 views
1
/*
2
* Copyright 2020 The Emscripten Authors. All rights reserved.
3
* Emscripten is available under two separate licenses, the MIT license and the
4
* University of Illinois/NCSA Open Source License. Both these licenses can be
5
* found in the LICENSE file.
6
*/
7
#include <pmmintrin.h>
8
#include "benchmark_sse.h"
9
10
int main() {
11
printf ("{ \"workload\": %u, \"results\": [\n", N);
12
13
float *src_flt = alloc_float_buffer();
14
float *src2_flt = alloc_float_buffer();
15
float *dst_flt = alloc_float_buffer();
16
for(int i = 0; i < N; ++i) src_flt[i] = (float)(1.0 + (double)rand() / RAND_MAX);
17
for(int i = 0; i < N; ++i) src2_flt[i] = (float)(1.0 + (double)rand() / RAND_MAX);
18
19
double *src_dbl = alloc_double_buffer();
20
double *src2_dbl = alloc_double_buffer();
21
double *dst_dbl = alloc_double_buffer();
22
for(int i = 0; i < N; ++i) src_dbl[i] = 1.0 + (double)rand() / RAND_MAX;
23
for(int i = 0; i < N; ++i) src2_dbl[i] = 1.0 + (double)rand() / RAND_MAX;
24
25
int *src_int = alloc_int_buffer();
26
int *src2_int = alloc_int_buffer();
27
int *dst_int = alloc_int_buffer();
28
for(int i = 0; i < N; ++i) src_int[i] = rand();
29
for(int i = 0; i < N; ++i) src2_int[i] = rand();
30
31
float scalarTime = 0.f;
32
33
// Benchmarks start:
34
SETCHART("load");
35
LOAD_STORE_I("_mm_lddqu_si128", _mm_lddqu_si128, 0, _mm_store_si128, 0, 4);
36
LOAD_STORE_D("_mm_loaddup_pd", _mm_loaddup_pd, 0, _mm_store_pd, double*, 0, 2);
37
38
SETCHART("double arithmetic");
39
BINARYOP_D_DD("_mm_addsub_pd", _mm_addsub_pd, _mm_load_pd(src_dbl), _mm_load_pd(src2_dbl));
40
BINARYOP_D_DD("_mm_hadd_pd", _mm_hadd_pd, _mm_load_pd(src_dbl), _mm_load_pd(src2_dbl));
41
BINARYOP_D_DD("_mm_hsub_pd", _mm_hsub_pd, _mm_load_pd(src_dbl), _mm_load_pd(src2_dbl));
42
43
SETCHART("double swizzle");
44
UNARYOP_D_D("_mm_movedup_pd", _mm_movedup_pd, _mm_load_pd(src_dbl));
45
46
SETCHART("float arithmetic");
47
BINARYOP_F_FF("_mm_addsub_ps", _mm_addsub_ps, _mm_load_ps(src_flt), _mm_load_ps(src2_flt));
48
BINARYOP_F_FF("_mm_hadd_ps", _mm_hadd_ps, _mm_load_ps(src_flt), _mm_load_ps(src2_flt));
49
BINARYOP_F_FF("_mm_hsub_ps", _mm_hsub_ps, _mm_load_ps(src_flt), _mm_load_ps(src2_flt));
50
51
SETCHART("float swizzle");
52
UNARYOP_F_F("_mm_movehdup_ps", _mm_movehdup_ps, _mm_load_ps(src_flt));
53
UNARYOP_F_F("_mm_moveldup_ps", _mm_moveldup_ps, _mm_load_ps(src_flt));
54
55
// Benchmarks end:
56
printf("]}\n");
57
}
58
59