Coverage Report

Created: 2017-11-12 13:27

/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
936
{
34
936
    __m128i v, x, y, z;
35
936
36
936
    y = _mm_srli_epi32(b, SFMT_SR1);
37
936
    z = _mm_srli_si128(c, SFMT_SR2);
38
936
    v = _mm_slli_epi32(d, SFMT_SL1);
39
936
    z = _mm_xor_si128(z, a);
40
936
    z = _mm_xor_si128(z, v);
41
936
    x = _mm_slli_si128(a, SFMT_SL2);
42
936
    y = _mm_and_si128(y, sse2_param_mask.si);
43
936
    z = _mm_xor_si128(z, x);
44
936
    z = _mm_xor_si128(z, y);
45
936
    *r = z;
46
936
}
47
48
/**
49
 * This function fills the internal state array with pseudorandom
50
 * integers.
51
 * @param sfmt SFMT internal state
52
 */
53
6
void sfmt_gen_rand_all(sfmt_t * sfmt) {
54
6
    int i;
55
6
    __m128i r1, r2;
56
6
    w128_t * pstate = sfmt->state;
57
6
58
6
    r1 = pstate[SFMT_N - 2].si;
59
6
    r2 = pstate[SFMT_N - 1].si;
60
210
    for (i = 0; 
i < 210
SFMT_N210
-
SFMT_POS1210
;
i++204
)
{204
61
204
  mm_recursion(&pstate[i].si, pstate[i].si,
62
204
         pstate[i + SFMT_POS1].si, r1, r2);
63
204
  r1 = r2;
64
204
  r2 = pstate[i].si;
65
204
    }
66
738
    for (; 
i < 738
SFMT_N738
;
i++732
)
{732
67
732
  mm_recursion(&pstate[i].si, pstate[i].si,
68
732
         pstate[i + 
SFMT_POS1732
-
SFMT_N732
].si,
69
732
         r1, r2);
70
732
  r1 = r2;
71
732
  r2 = pstate[i].si;
72
732
    }
73
6
}
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 < 0
SFMT_N0
-
SFMT_POS10
;
i++0
)
{0
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 < 0
SFMT_N0
;
i++0
)
{0
97
0
  mm_recursion(&array[i].si, pstate[i].si,
98
0
         array[i + 
SFMT_POS10
-
SFMT_N0
].si, r1, r2);
99
0
  r1 = r2;
100
0
  r2 = array[i].si;
101
0
    }
102
0
    for (; 
i < size - 0
SFMT_N0
;
i++0
)
{0
103
0
  mm_recursion(&array[i].si, array[i - SFMT_N].si,
104
0
         array[i + 
SFMT_POS10
-
SFMT_N0
].si, r1, r2);
105
0
  r1 = r2;
106
0
  r2 = array[i].si;
107
0
    }
108
0
    for (j = 0; 
j < 2 * 0
SFMT_N0
- size;
j++0
)
{0
109
0
  pstate[j] = array[j + size - SFMT_N];
110
0
    }
111
0
    for (; 
i < size0
;
i++, j++0
)
{0
112
0
  mm_recursion(&array[i].si, array[i - SFMT_N].si,
113
0
         array[i + 
SFMT_POS10
-
SFMT_N0
].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