Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abseil-cpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
abseil-cpp
Commits
022527c5
Unverified
Commit
022527c5
authored
Oct 29, 2021
by
Milad Fa
Committed by
GitHub
Oct 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Randen and PCG on Big Endian platforms (#1031)
parent
cc413f8b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletions
+29
-1
absl/random/internal/explicit_seed_seq.h
+1
-1
absl/random/internal/randen_engine.h
+7
-0
absl/random/internal/randen_slow.cc
+21
-0
No files found.
absl/random/internal/explicit_seed_seq.h
View file @
022527c5
...
...
@@ -74,7 +74,7 @@ class ExplicitSeedSeq {
template
<
typename
OutIterator
>
void
generate
(
OutIterator
begin
,
OutIterator
end
)
{
for
(
size_t
index
=
0
;
begin
!=
end
;
begin
++
)
{
*
begin
=
state_
.
empty
()
?
0
:
little_endian
::
FromHost32
(
state_
[
index
++
])
;
*
begin
=
state_
.
empty
()
?
0
:
state_
[
index
++
]
;
if
(
index
>=
state_
.
size
())
{
index
=
0
;
}
...
...
absl/random/internal/randen_engine.h
View file @
022527c5
...
...
@@ -121,6 +121,13 @@ class alignas(16) randen_engine {
const
size_t
requested_entropy
=
(
entropy_size
==
0
)
?
8u
:
entropy_size
;
std
::
fill
(
std
::
begin
(
buffer
)
+
requested_entropy
,
std
::
end
(
buffer
),
0
);
seq
.
generate
(
std
::
begin
(
buffer
),
std
::
begin
(
buffer
)
+
requested_entropy
);
#ifdef ABSL_IS_BIG_ENDIAN
// Randen expects the seed buffer to be in Little Endian; reverse it on
// Big Endian platforms.
for
(
sequence_result_type
&
e
:
buffer
)
{
e
=
absl
::
little_endian
::
FromHost
(
e
);
}
#endif
// The Randen paper suggests preferentially initializing even-numbered
// 128-bit vectors of the randen state (there are 16 such vectors).
// The seed data is merged into the state offset by 128-bits, which
...
...
absl/random/internal/randen_slow.cc
View file @
022527c5
...
...
@@ -395,6 +395,23 @@ inline ABSL_RANDOM_INTERNAL_ATTRIBUTE_ALWAYS_INLINE void Permute(
}
}
// Enables native loads in the round loop by pre-swapping.
inline
ABSL_RANDOM_INTERNAL_ATTRIBUTE_ALWAYS_INLINE
void
SwapEndian
(
absl
::
uint128
*
state
)
{
#ifdef ABSL_IS_BIG_ENDIAN
for
(
uint32_t
block
=
0
;
block
<
RandenTraits
::
kFeistelBlocks
;
++
block
)
{
uint64_t
new_lo
=
absl
::
little_endian
::
ToHost64
(
static_cast
<
uint64_t
>
(
state
[
block
]
>>
64
));
uint64_t
new_hi
=
absl
::
little_endian
::
ToHost64
(
static_cast
<
uint64_t
>
((
state
[
block
]
<<
64
)
>>
64
));
state
[
block
]
=
(
static_cast
<
absl
::
uint128
>
(
new_hi
)
<<
64
)
|
new_lo
;
}
#else
// Avoid warning about unused variable.
(
void
)
state
;
#endif
}
}
// namespace
namespace
absl
{
...
...
@@ -439,8 +456,12 @@ void RandenSlow::Generate(const void* keys_void, void* state_void) {
const
absl
::
uint128
prev_inner
=
state
[
0
];
SwapEndian
(
state
);
Permute
(
state
,
keys
);
SwapEndian
(
state
);
// Ensure backtracking resistance.
*
state
^=
prev_inner
;
}
...
...
Write
Preview
Markdown
is supported
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