Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BRAMAS Berenger
spetabaru
Commits
d85911d2
Commit
d85911d2
authored
Sep 07, 2020
by
CARDOSI Paul
Browse files
Fix logic and math.
parent
c5d46ffc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Src/Random/SpPhiloxGenerator.hpp
View file @
d85911d2
...
...
@@ -57,27 +57,38 @@ class SpPhiloxGenerator {
// Skip the specified number of steps
void
Skip
(
uint64
count
)
{
temp_counter_
+=
count
;
if
(
temp_counter_
>
3
)
{
temp_counter_
=
temp_counter_
%
4
;
force_compute_
=
true
;
const
auto
count_lo
=
static_cast
<
uint32
>
((
count
-
temp_counter_
)
/
4
);
auto
count_hi
=
static_cast
<
uint32
>
((
count
-
temp_counter_
)
/
4
>>
32
);
counter_
[
0
]
+=
count_lo
;
if
(
counter_
[
0
]
<
count_lo
)
{
++
count_hi
;
if
(
count
>
0
)
{
if
(
temp_counter_
>
3
)
{
SkipOne
();
temp_counter_
=
0
;
force_compute_
=
true
;
}
const
auto
position
=
temp_counter_
+
count
;
if
(
position
>
3
)
{
force_compute_
=
true
;
temp_counter_
=
position
%
4
;
const
auto
nbOfCounterIncrements
=
position
/
4
;
const
auto
count_lo
=
static_cast
<
uint32
>
(
nbOfCounterIncrements
);
auto
count_hi
=
static_cast
<
uint32
>
(
nbOfCounterIncrements
>>
32
);
// 128 bit add
counter_
[
0
]
+=
count_lo
;
if
(
counter_
[
0
]
<
count_lo
)
{
++
count_hi
;
}
counter_
[
1
]
+=
count_hi
;
if
(
counter_
[
1
]
<
count_hi
)
{
if
(
++
counter_
[
2
]
==
0
)
{
++
counter_
[
3
];
counter_
[
1
]
+=
count_hi
;
if
(
counter_
[
1
]
<
count_hi
)
{
if
(
++
counter_
[
2
]
==
0
)
{
++
counter_
[
3
];
}
}
}
else
{
temp_counter_
=
position
;
}
}
}
...
...
@@ -88,6 +99,7 @@ class SpPhiloxGenerator {
if
(
temp_counter_
>
3
)
{
temp_counter_
=
0
;
SkipOne
();
temp_results_
=
counter_
;
ExecuteRounds
();
}
else
if
(
force_compute_
)
{
...
...
@@ -97,7 +109,7 @@ class SpPhiloxGenerator {
}
uint32
value
=
temp_results_
[
temp_counter_
];
temp_counter_
++
;
temp_counter_
++
;
return
value
;
}
...
...
@@ -143,6 +155,7 @@ class SpPhiloxGenerator {
// Skip one step
void
SkipOne
()
{
// 128 bit increment
if
(
++
counter_
[
0
]
==
0
)
{
if
(
++
counter_
[
1
]
==
0
)
{
if
(
++
counter_
[
2
]
==
0
)
{
...
...
@@ -170,8 +183,6 @@ class SpPhiloxGenerator {
temp_results_
=
ComputeSingleRound
(
temp_results_
,
key
);
RaiseKey
(
&
key
);
}
SkipOne
();
}
// Helper function for a single round of the underlying Philox algorithm.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment