tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] inline assembly problem with cmovcl/cmovbl


From: Somchai Smythe
Subject: [Tinycc-devel] inline assembly problem with cmovcl/cmovbl
Date: Sat, 2 Dec 2017 14:04:10 +0700

Hello again tcc list,

gcc, clang, and even pcc take this code just fine, but tcc won't
compile it   I can tell you that I did build tcc from git commit id
9e0d23cc47359149a39eafffdbb133963980b6ed and that version of tcc works
for most things.

I realize there are other ways to get this cpuid information, but if I
wanted to use cmovcl in some other code I think the inline assembler
really is broken.  I tried the synonym cmovbl, but it didn't work
either.  Both cmovc and cmovb are listed in intel's manual as
generating 0x04 0x42 /r, so I think they are just two mnemonics for
the same instruction.  If I delete the 'l' suffix, and use bare
'cmovc' (or bare 'cmovb'), it will compile.  Since push, mov, etc.
accept the suffixes, cmovc should too.

$ cat bob.c
#include <stdlib.h>
#include <stdio.h>

unsigned long int haverdrand(void);

unsigned long int haverdrand(void) {
  unsigned long int ret;

  __asm__ volatile (
        "pushfq\n\
        pushq   %%rcx\n\
        movl    $1,%%eax        # get leaf #1\n\
        cpuid\n\
        xorl    %%eax,%%eax\n\
        btl     $30,%%ecx       # RDRAND\n\
        movl    $1,%%ecx\n\
        cmovcl  %%ecx,%%eax\n\
        popq    %%rcx\n\
        popfq"
        : "=a" (ret)
  );
  return ret;
}

int main(void) {
  fputs("YOU DO ",stdout);
  if (!haverdrand())
    fputs("NOT ",stdout);
  fputs("HAVE RDRAND SUPPORT.\n",stdout);
  return EXIT_SUCCESS;
}
$ gcc bob.c -o bob
$ ./bob
YOU DO HAVE RDRAND SUPPORT.
$ rm bob
$ clang bob.c -o bob
$ ./bob
YOU DO HAVE RDRAND SUPPORT.
$ rm bob
$ pcc bob.c -o bob
$ ./bob
YOU DO HAVE RDRAND SUPPORT.
$ rm bob
$ tcc bob.c -o bob
bob.c:20: error: unknown opcode 'cmovcl'
$ ls -ld bob
ls: cannot access 'bob': No such file or directory
$



reply via email to

[Prev in Thread] Current Thread [Next in Thread]