45 lines
985 B
C++
45 lines
985 B
C++
|
/*
|
||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||
|
*
|
||
|
* Copyright 2019 Danny Robson <danny@nerdcruft.net>
|
||
|
*/
|
||
|
|
||
|
#include "rdrand.hpp"
|
||
|
|
||
|
using cruft::rand::rdrand;
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
rdrand::rdrand ()
|
||
|
{ ; }
|
||
|
|
||
|
|
||
|
//---------------------------------------------------------------------------------------
|
||
|
rdrand::rdrand (std::string const &)
|
||
|
: rdrand ()
|
||
|
{ ; }
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
rdrand::result_type
|
||
|
rdrand::operator() ()
|
||
|
{
|
||
|
uint64_t res;
|
||
|
char success;
|
||
|
|
||
|
__asm__ __volatile__ (
|
||
|
"rdrand %0;"
|
||
|
"setc %1;"
|
||
|
|
||
|
: "=r" (res)
|
||
|
, "=qm" (success)
|
||
|
);
|
||
|
|
||
|
if (!__builtin_expect(success, 1))
|
||
|
throw std::runtime_error ("no value available for rdrand");
|
||
|
|
||
|
return res;
|
||
|
}
|