drowe67 / freedv-gui

GUI Application for FreeDV – open source digital voice for HF radio
https://freedv.org/
GNU Lesser General Public License v2.1
206 stars 52 forks source link

Compile error on Raspbian "Buster" #40

Closed dl9sec closed 4 years ago

dl9sec commented 4 years ago

Hi,

i tried to build the latest freedv on an Raspberry Pi 3 on Raspbian "Buster". Codec2 and LPCNet seems to build well, but when compiling freedv-gui, the build process stops at about 25% with the following error:

/home/pi/projects/freedv-gui/src/fdmdv2_main.cpp: In function ‘void __cpuid(int*, int)’:
/home/pi/projects/freedv-gui/src/fdmdv2_main.cpp:4490:6: error: impossible constraint in ‘asm’
     );
      ^
make[2]: *** [src/CMakeFiles/freedv.dir/build.make:128: src/CMakeFiles/freedv.dir/fdmdv2_main.cpp.o] Fehler 1

Maybe this part of code isn't supported on ARM targets.

Any solutions how to solve?

Thanks in advance.

Regards, Thorsten

ghost commented 4 years ago

Try something like this:

#if defined(__x86_64__)
// checkAvxSupport
//
// Tests the underlying platform for AVX support.  2020 needs AVX support
to run
// in real-time, and old processors do not offer AVX support
//
void __cpuid(int* cpuinfo, int info)
{
    __asm__ __volatile__(
        "xchg %%ebx, %%edi;"
        "cpuid;"
        "xchg %%ebx, %%edi;"
        :"=a" (cpuinfo[0]), "=D" (cpuinfo[1]), "=c" (cpuinfo[2]), "=d"
(cpuinfo[3])
        :"0" (info)
    );
}

// These methods are defined for Windows but must be created otherwise
unsigned long long __xgetbv(unsigned int index)
{
    unsigned int eax, edx;
    __asm__ __volatile__(
        "xgetbv;"
        : "=a" (eax), "=d"(edx)
        : "c" (index)
    );
    return ((unsigned long long)edx << 32) | eax;
}

void MainFrame::checkAvxSupport(void)
{

    int cpuinfo[4];
    __cpuid(cpuinfo, 1);

    bool avxSupported = false;

    avxSupported = cpuinfo[2] & (1 << 28) || false;
    bool osxsaveSupported = cpuinfo[2] & (1 << 27) || false;
    if (osxsaveSupported && avxSupported)
    {
        // _XCR_XFEATURE_ENABLED_MASK = 0
        unsigned long long xcrFeatureMask = __xgetbv(0);
        avxSupported = (xcrFeatureMask & 0x6) == 0x6;
    }

    isAvxPresent = false;
}
#else
void MainFrame::checkAvxSupport(void)
{
    isAvxPresent = false;
}
#endif
dl9sec commented 4 years ago

Great stuff! Thank you very much, builds like a charm now :-D

Regards, Thorsten