This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: How to set REX prefix when using RDRAND?
- From: Jeffrey Walton <noloader at gmail dot com>
- To: Mason <slash dot tmp at free dot fr>
- Cc: GCC help <gcc-help at gcc dot gnu dot org>
- Date: Mon, 12 Oct 2015 13:41:59 -0400
- Subject: Re: How to set REX prefix when using RDRAND?
- Authentication-results: sourceware.org; auth=none
- References: <CAH8yC8notjAYqQ4FRMvtP8rV+Ks=G7i83mbae_ttAnBMJz5rEg at mail dot gmail dot com> <561B7D6A dot 4000709 at free dot fr>
- Reply-to: noloader at gmail dot com
On Mon, Oct 12, 2015 at 5:29 AM, Mason <slash.tmp@free.fr> wrote:
> On 12/10/2015 10:34, Jeffrey Walton wrote:
>> I'm not able to compile a program that uses `rdrand` and a word64 due
>> to "Error: operand size mismatch for `rdrand'". If I try to explicitly
>> use `rdrandq` and the word64, then it results in
>> "Error: invalid instruction suffix for `rdrand'"
>
> (I'm not a gcc developer.)
>
> I think it would be a good idea to provide a minimal example of
> what you are compiling,
In the code below, output is a byte[] with a length of size. safety is
a failsafe.
The two different word sizes handle the X86, X32, and X64 platforms.
BOOL_X86 is set by __i386__ and friends.
Jeff
*****
This code produces "Error: invalid instruction suffix for `rdrand'":
#if BOOL_X86
word32 val;
#else // X32 and X64
word64 val;
#endif
while (size && safety)
{
char rc;
__asm__ volatile(
#if BOOL_X86
"rdrandl %0 ; setc %1"
#else
"rdrandq %0 ; setc %1"
#endif
: "=rm" (val), "=qm" (rc)
:
: "cc"
);
if (rc)
{
size_t count = (size < sizeof(val) ? size : sizeof(val));
memcpy(output, &val, count);
size =- count;
}
else
{
safety--;
}
}
*****
This code produces "Error: operand size mismatch for `rdrand'"
__asm__ volatile(
#if BOOL_X86
"rdrand %0 ; setc %1"
#else
"rdrand %0 ; setc %1"
#endif
: "=rm" (val), "=qm" (rc)
:
: "cc"
);
Jeff