gcc error: impossible constraint in 'asm' building Audio lib

Status
Not open for further replies.

darryln

New member
I am getting an error on utility/dspinst.h when building the Audio library standalone (SSAT wrapper). I'm not sure my gcc command line options are right. Can anyone advise?

Arduino 1.8.1 with Teensyduino 1.6.7 installed.
Toolchain is gcc-arm-none-eabi-4_8-2014q3 copied from the app install @ .../hardware/tools/arm.
Audio lib is from github @ 2aaf78e.
Targeting K66 (__MK66FX1M0__).

Note: I use -std=gnu++11 because gnu++0x is deprecated, but I believe they are identical.

Error:
Code:
In file included from /Users/.../Documents/Arduino/libraries/Audio/effect_multiply.h:31:0,
                 from /Users/.../Documents/Arduino/libraries/Audio/effect_multiply.cpp:27:
/Users/.../Documents/Arduino/libraries/Audio/utility/dspinst.h: In member function 'virtual void AudioEffectMultiply::update()':
/Users/.../Documents/Arduino/libraries/Audio/utility/dspinst.h:38:92: error: impossible constraint in 'asm'
  asm volatile("ssat %0, %1, %2, asr %3" : "=r" (out) : "I" (bits), "r" (val), "I" (rshift));


Command line:

/Users/..../teensytools/arm/bin/arm-none-eabi-gcc -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++11 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -MMD -D__MK66FX1M0__ -DTEENSYDUINO=134 -DARDUINO=10801 -DF_CPU=180000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DCORE_TEENSY -I[include paths] -c /Users/.../Documents/Arduino/libraries/Audio/effect_multiply.cpp -o /Users/.../Documents/Arduino/teensy36_makefile/build/libraries/Audio/effect_multiply.cpp.o
 
Note, I've never looked at the ARM GCC backend, but generally the 'I' constraint is for constants. However the code is:

Code:
static inline int32_t signed_saturate_rshift(int32_t val, int bits, int rshift)
{
#if defined(KINETISK)
        int32_t out;
        asm volatile("ssat %0, %1, %2, asr %3" : "=r" (out) : "I" (bits), "r" (val), "I" (rshift));
        return out;
#elif defined(KINETISL)
        int32_t out, max;
        out = val >> rshift;
        max = 1 << (bits - 1);
        if (out >= 0) {
                if (out > max - 1) out = max - 1;
        } else {
                if (out < -max) out = -max;
        }
        return out;
#endif
}

Given you only use -O optimization, it may not do the optimization that would replace rshift with a constant. Try using -O2 or -Os instead.
 
It compiles fine in Arduino, even with Tools > Optimize set to "Fast" (which is -O optimize).

Perhaps give Arduino a try with verbose info while compiling set in File > Preferences. Then you can see the exact command line Arduino uses to compile this file.
 
Thanks for the replies.

Initially, I did copy the command line from the arduino build log, but probably munged something. I went through platform.txt and boards.txt to piece together the correct command lines for cpp, c, asm, and link. One problem was that I was calling gcc, not g++. The below options produced a successful compile and link, but I haven't tested the code yet. Debug optimization (i.e. none) since I'm using JTAG. I'll experiment with the various optimization flags later.

Code:
/Users/.../teensytools/arm/bin/arm-none-eabi-g++ -c -Og -g -Wall \
  -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++11 -fno-rtti \
  -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant \ 
  -D__MK66FX1M0__ -DTEENSYDUINO=134 -DARDUINO=10801 -DF_CPU=180000000 -DUSB_SERIAL \
  -DLAYOUT_US_ENGLISH -DCORE_TEENSY \
  -I[includes] -c /Users/.../Documents/Arduino/libraries/Audio/effect_multiply.cpp -o \   /Users/.../Documents/Arduino/teensy36_makefile/build/libraries/Audio/effect_multiply.cpp.o \
 
Status
Not open for further replies.
Back
Top