0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-11 08:02:59 +01:00
construct/include/ircd/simt/rand.h

71 lines
1.6 KiB
C
Raw Normal View History

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.
#pragma once
#define HAVE_IRCD_SIMT_RAND_H
#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;
}
#endif
2021-04-02 21:51:59 +02: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;
}
#endif
#ifdef __OPENCL_VERSION__
/// 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