Coverage Report

Created: 2019-07-03 22:50

/home/liu/buildslave/linux-x64-runtests/build/lib/3rdparty/sfmt/SFMT-sse2.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
/**
3
 * @file  SFMT-sse2.h
4
 * @brief SIMD oriented Fast Mersenne Twister(SFMT) for Intel SSE2
5
 *
6
 * @author Mutsuo Saito (Hiroshima University)
7
 * @author Makoto Matsumoto (Hiroshima University)
8
 *
9
 * @note We assume LITTLE ENDIAN in this file
10
 *
11
 * Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
12
 * University. All rights reserved.
13
 *
14
 * The new BSD License is applied to this software, see LICENSE.txt
15
 */
16
17
#ifndef SFMT_SSE2_H
18
#define SFMT_SSE2_H
19
20
inline static void mm_recursion(__m128i * r, __m128i a, __m128i b,
21
        __m128i c, __m128i d);
22
23
/**
24
 * This function represents the recursion formula.
25
 * @param r an output
26
 * @param a a 128-bit part of the interal state array
27
 * @param b a 128-bit part of the interal state array
28
 * @param c a 128-bit part of the interal state array
29
 * @param d a 128-bit part of the interal state array
30
 */
31
inline static void mm_recursion(__m128i * r, __m128i a, __m128i b,
32
        __m128i c, __m128i d)
33
410M
{
34
410M
    __m128i v, x, y, z;
35
410M
36
410M
    y = _mm_srli_epi32(b, SFMT_SR1);
37
410M
    z = _mm_srli_si128(c, SFMT_SR2);
38
410M
    v = _mm_slli_epi32(d, SFMT_SL1);
39
410M
    z = _mm_xor_si128(z, a);
40
410M
    z = _mm_xor_si128(z, v);
41
410M
    x = _mm_slli_si128(a, SFMT_SL2);
42
410M
    y = _mm_and_si128(y, sse2_param_mask.si);
43
410M
    z = _mm_xor_si128(z, x);
44
410M
    z = _mm_xor_si128(z, y);
45
410M
    *r = z;
46
410M
}
47
48
/**
49
 * This function fills the internal state array with pseudorandom
50
 * integers.
51
 * @param sfmt SFMT internal state
52
 */
53
3.42M
void sfmt_gen_rand_all(sfmt_t * sfmt) {
54
3.42M
    int i;
55
3.42M
    __m128i r1, r2;
56
3.42M
    w128_t * pstate = sfmt->state;
57
3.42M
58
3.42M
    r1 = pstate[SFMT_N - 2].si;
59
3.42M
    r2 = pstate[SFMT_N - 1].si;
60
105M
    for (i = 0; i < SFMT_N - SFMT_POS1; 
i++102M
) {
61
102M
  mm_recursion(&pstate[i].si, pstate[i].si,
62
102M
         pstate[i + SFMT_POS1].si, r1, r2);
63
102M
  r1 = r2;
64
102M
  r2 = pstate[i].si;
65
102M
    }
66
322M
    for (; i < SFMT_N; 
i++318M
) {
67
318M
  mm_recursion(&pstate[i].si, pstate[i].si,
68
318M
         pstate[i + SFMT_POS1 - SFMT_N].si,
69
318M
         r1, r2);
70
318M
  r1 = r2;
71
318M
  r2 = pstate[i].si;
72
318M
    }
73
3.42M
}
74
75
/**
76
 * This function fills the user-specified array with pseudorandom
77
 * integers.
78
 * @param sfmt SFMT internal state.
79
 * @param array an 128-bit array to be filled by pseudorandom numbers.
80
 * @param size number of 128-bit pseudorandom numbers to be generated.
81
 */
82
static void gen_rand_array(sfmt_t * sfmt, w128_t * array, int size)
83
0
{
84
0
    int i, j;
85
0
    __m128i r1, r2;
86
0
    w128_t * pstate = sfmt->state;
87
0
88
0
    r1 = pstate[SFMT_N - 2].si;
89
0
    r2 = pstate[SFMT_N - 1].si;
90
0
    for (i = 0; i < SFMT_N - SFMT_POS1; i++) {
91
0
  mm_recursion(&array[i].si, pstate[i].si,
92
0
         pstate[i + SFMT_POS1].si, r1, r2);
93
0
  r1 = r2;
94
0
  r2 = array[i].si;
95
0
    }
96
0
    for (; i < SFMT_N; i++) {
97
0
  mm_recursion(&array[i].si, pstate[i].si,
98
0
         array[i + SFMT_POS1 - SFMT_N].si, r1, r2);
99
0
  r1 = r2;
100
0
  r2 = array[i].si;
101
0
    }
102
0
    for (; i < size - SFMT_N; i++) {
103
0
  mm_recursion(&array[i].si, array[i - SFMT_N].si,
104
0
         array[i + SFMT_POS1 - SFMT_N].si, r1, r2);
105
0
  r1 = r2;
106
0
  r2 = array[i].si;
107
0
    }
108
0
    for (j = 0; j < 2 * SFMT_N - size; j++) {
109
0
  pstate[j] = array[j + size - SFMT_N];
110
0
    }
111
0
    for (; i < size; i++, j++) {
112
0
  mm_recursion(&array[i].si, array[i - SFMT_N].si,
113
0
         array[i + SFMT_POS1 - SFMT_N].si, r1, r2);
114
0
  r1 = r2;
115
0
  r2 = array[i].si;
116
0
  pstate[j] = array[i];
117
0
    }
118
0
}
119
120
121
#endif