简体   繁体   English

编译错误“'asm'中的不可能约束”

[英]compiling error “impossible constraint in 'asm'”

I tried to compile Csmith on my "SunOS sun4v 5.10" system, but I got errors like these: 我试图在“ SunOS sun4v 5.10”系统上编译Csmith,但是出现了以下错误:

platform.cpp: In function 'long unsigned int platform_gen_seed()':
platform.cpp:78: error: impossible constraint in 'asm'

Could anyone tell where is the mistake? 谁能说出错误在哪里?

#if (TARGET_CPU_powerpc == 1 || TARGET_CPU_powerpc64 == 1)
/*For PPC, got from:
http://lists.ozlabs.org/pipermail/linuxppc-dev/1999-October/003889.html
*/
static unsigned long long read_time(void) {
    unsigned long long retval;
    unsigned long junk;
    __asm__ __volatile__ ("\n\
1:  mftbu %1\n\
    mftb %L0\n\
    mftbu %0\n\
    cmpw %0,%1\n\
    bne 1b"
    : "=r" (retval), "=r" (junk));
    return retval;
}
#else
#ifdef WIN32
static unsigned __int64 read_time(void) {
        unsigned l, h;
        _asm {rdtsc    
        mov l, eax  
        mov h, edx 
        }
        return (h << 32) + l ;
}
#else
static long long read_time(void) {
        long long l;
        asm volatile(   "rdtsc\n\t"
                : "=A" (l)
        );
        return l;
}
#endif
#endif

unsigned long platform_gen_seed()
{
    return (long) read_time();
}

The problem is that the code you're trying to compile assumes that any target CPU that's not a PowerPC must be an x86 processor. 问题在于,您要编译的代码假定所有不是PowerPC的目标CPU都必须是x86处理器。 The code simply doesn't doesn't support your SPARC CPU. 该代码根本不支持您的SPARC CPU。

Fortunately the code doesn't seem to be critical, it's apparently only used to seed a random number generator, which is then used to create random C programs. 幸运的是,该代码似乎并不关键,它显然仅用于播种随机数生成器,然后用于创建随机C程序。 The goal being to prevent multiple instances of the program that are started at the same time from generating the same random programs. 目的是防止同时启动的程序的多个实例生成相同的随机程序。 I'd replace the code with something more portable that's not dependent on the CPU. 我将用不依赖于CPU的更具移植性的代码替换代码。 Something like this: 像这样:

#ifdef WIN32

unsigned long platform_gen_seed()
{
    LARGE_INTEGER now;
    QueryPerformanceCounter(&now);
    return now.LowPart;
}

#else /* assume something Unix-like */

static unsigned long generic_gen_seed() {
    pid_t pid = getpid();
    time_t now;
    time(&now);
    return (unsigned long)(now ^ (pid << 16 | ((pid >> 16) & 0xFFFF)));
}

#ifdef CLOCK_REALTIME

unsigned long platform_gen_seed()
{
    struct timespec now, resolution;
    if (clock_gettime(CLOCK_REALTIME, &now) == -1
        || clock_getres(CLOCK_REALTIME, &resolution) == -1
            || resolution.tv_sec > 0 || resolution.tv_nsec > 1000000) {
        return generic_gen_seed();
    }
    return (now.tv_nsec / resolution.tv_nsec
        + now.tv_sec * resolution.tv_nsec);
}

#else 

unsigned long platform_gen_seed()
{
    return generic_gen_seed();
}

#endif /* CLOCK_REALTIME */

#endif /* WIN32 */

The code has been test in isolation on Linux and Windows. 该代码已在Linux和Windows上进行了单独测试。 It should also work in isolation on Solaris SPARC, but I don't know how well it work in context of the actual program. 它也应该在Solaris SPARC上独​​立工作,但是我不知道它在实际程序中的运行情况如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM