File: benchmark_sse3.cpp

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 121,860 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,366; asm: 2,415; lisp: 1,869
file content (57 lines) | stat: -rw-r--r-- 2,335 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Copyright 2020 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */
#include <pmmintrin.h>
#include "benchmark_sse.h"

int main() {
  printf ("{ \"workload\": %u, \"results\": [\n", N);

  float *src_flt = alloc_float_buffer();
  float *src2_flt = alloc_float_buffer();
  float *dst_flt = alloc_float_buffer();
  for(int i = 0; i < N; ++i) src_flt[i] = (float)(1.0 + (double)rand() / RAND_MAX);
  for(int i = 0; i < N; ++i) src2_flt[i] = (float)(1.0 + (double)rand() / RAND_MAX);

  double *src_dbl = alloc_double_buffer();
  double *src2_dbl = alloc_double_buffer();
  double *dst_dbl = alloc_double_buffer();
  for(int i = 0; i < N; ++i) src_dbl[i] = 1.0 + (double)rand() / RAND_MAX;
  for(int i = 0; i < N; ++i) src2_dbl[i] = 1.0 + (double)rand() / RAND_MAX;

  int *src_int = alloc_int_buffer();
  int *src2_int = alloc_int_buffer();
  int *dst_int = alloc_int_buffer();
  for(int i = 0; i < N; ++i) src_int[i] = rand();
  for(int i = 0; i < N; ++i) src2_int[i] = rand();

  float scalarTime = 0.f;

  // Benchmarks start:
  SETCHART("load");
  LOAD_STORE_I("_mm_lddqu_si128", _mm_lddqu_si128, 0, _mm_store_si128, 0, 4);
  LOAD_STORE_D("_mm_loaddup_pd", _mm_loaddup_pd, 0, _mm_store_pd, double*, 0, 2);

  SETCHART("double arithmetic");
  BINARYOP_D_DD("_mm_addsub_pd", _mm_addsub_pd, _mm_load_pd(src_dbl), _mm_load_pd(src2_dbl));
  BINARYOP_D_DD("_mm_hadd_pd", _mm_hadd_pd, _mm_load_pd(src_dbl), _mm_load_pd(src2_dbl));
  BINARYOP_D_DD("_mm_hsub_pd", _mm_hsub_pd, _mm_load_pd(src_dbl), _mm_load_pd(src2_dbl));

  SETCHART("double swizzle");
  UNARYOP_D_D("_mm_movedup_pd", _mm_movedup_pd, _mm_load_pd(src_dbl));

  SETCHART("float arithmetic");
  BINARYOP_F_FF("_mm_addsub_ps", _mm_addsub_ps, _mm_load_ps(src_flt), _mm_load_ps(src2_flt));
  BINARYOP_F_FF("_mm_hadd_ps", _mm_hadd_ps, _mm_load_ps(src_flt), _mm_load_ps(src2_flt));
  BINARYOP_F_FF("_mm_hsub_ps", _mm_hsub_ps, _mm_load_ps(src_flt), _mm_load_ps(src2_flt));

  SETCHART("float swizzle");
  UNARYOP_F_F("_mm_movehdup_ps", _mm_movehdup_ps, _mm_load_ps(src_flt));
  UNARYOP_F_F("_mm_moveldup_ps", _mm_moveldup_ps, _mm_load_ps(src_flt));

  // Benchmarks end:
  printf("]}\n");
}