2021-04-02 21:51:59 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2021 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
2021-05-02 23:43:10 +02:00
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_SIMT_RAND_H
|
|
|
|
|
2021-11-10 00:47:27 +01:00
|
|
|
#ifdef __OPENCL_VERSION__
|
2021-04-02 21:51:59 +02:00
|
|
|
/// Generate the next pseudo-random 64-bit sequence from the 256-bit state
|
|
|
|
/// and update the state for the next call.
|
|
|
|
inline ulong
|
|
|
|
ircd_simt_rand_xoshiro256p(ulong s[4])
|
|
|
|
{
|
|
|
|
const ulong
|
|
|
|
ret = s[0] + s[3],
|
|
|
|
ent = s[1] << 17;
|
|
|
|
|
|
|
|
s[2] ^= s[0];
|
|
|
|
s[3] ^= s[1];
|
|
|
|
s[1] ^= s[3];
|
|
|
|
s[0] ^= s[3];
|
|
|
|
s[2] ^= ent;
|
|
|
|
|
|
|
|
s[3] = rotate(s[3], 45UL); // (s[3] << 45) | (s[3] >> (64 - 45));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2021-05-02 23:43:10 +02:00
|
|
|
#endif
|
2021-04-02 21:51:59 +02:00
|
|
|
|
2021-11-10 00:47:27 +01:00
|
|
|
#ifdef __OPENCL_VERSION__
|
2021-04-02 21:51:59 +02:00
|
|
|
/// Generate the next pseudo-random 64-bit sequence from the 256-bit global
|
|
|
|
/// state and update the state for the next call.
|
|
|
|
inline ulong
|
|
|
|
ircd_simt_rand_xoshiro256pg(__global ulong s[4])
|
|
|
|
{
|
|
|
|
ulong _s[4], ret;
|
|
|
|
for(uint i = 0; i < 4; i++)
|
|
|
|
_s[i] = s[i];
|
|
|
|
|
|
|
|
ret = ircd_simt_rand_xoshiro256p(_s);
|
|
|
|
for(uint i = 0; i < 4; i++)
|
|
|
|
s[i] = _s[i];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2021-05-02 23:43:10 +02:00
|
|
|
#endif
|
2021-10-06 21:10:53 +02:00
|
|
|
|
2021-11-10 00:47:27 +01:00
|
|
|
#ifdef __OPENCL_VERSION__
|
2021-10-06 21:10:53 +02:00
|
|
|
/// Generate the next pseudo-random 64-bit sequence from the 256-bit local
|
|
|
|
/// state and update the state for the next call.
|
|
|
|
inline ulong
|
|
|
|
ircd_simt_rand_xoshiro256pl(__local ulong s[4])
|
|
|
|
{
|
|
|
|
ulong _s[4], ret;
|
|
|
|
for(uint i = 0; i < 4; i++)
|
|
|
|
_s[i] = s[i];
|
|
|
|
|
|
|
|
ret = ircd_simt_rand_xoshiro256p(_s);
|
|
|
|
for(uint i = 0; i < 4; i++)
|
|
|
|
s[i] = _s[i];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|