Skip to content

inlined ASM code: invalid output constraint #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4ntoine opened this issue Dec 26, 2014 · 3 comments
Closed

inlined ASM code: invalid output constraint #12

4ntoine opened this issue Dec 26, 2014 · 3 comments
Labels

Comments

@4ntoine
Copy link
Owner

4ntoine commented Dec 26, 2014

Clang issue related to backend most likely

/Applications/A.app/Contents/Resources/Java/hardware/a/cores/a/wiring.c:185:15: error: invalid
      output constraint '=w' in asm
                "brne 1b" : "=w" (us) : "0" (us) // 2 cycles

wiring.c (part):

/* Delay for the given number of microseconds.  Assumes a 8 or 16 MHz clock. */
void delayMicroseconds(unsigned int us)
{
    // calling avrlib's delay_us() function with low values (e.g. 1 or
    // 2 microseconds) gives delays longer than desired.
    //delay_us(us);
#if F_CPU >= 20000000L
    // for the 20 MHz clock on rare Arduino boards

    // for a one-microsecond delay, simply wait 2 cycle and return. The overhead
    // of the function call yields a delay of exactly a one microsecond.
    __asm__ __volatile__ (
        "nop" "\n\t"
        "nop"); //just waiting 2 cycle
    if (--us == 0)
        return;

    // the following loop takes a 1/5 of a microsecond (4 cycles)
    // per iteration, so execute it five times for each microsecond of
    // delay requested.
    us = (us<<2) + us; // x5 us

    // account for the time taken in the preceeding commands.
    us -= 2;

#elif F_CPU >= 16000000L
    // for the 16 MHz clock on most Arduino boards

    // for a one-microsecond delay, simply return.  the overhead
    // of the function call yields a delay of approximately 1 1/8 us.
    if (--us == 0)
        return;

    // the following loop takes a quarter of a microsecond (4 cycles)
    // per iteration, so execute it four times for each microsecond of
    // delay requested.
    us <<= 2;

    // account for the time taken in the preceeding commands.
    us -= 2;
#else
    // for the 8 MHz internal clock on the ATmega168

    // for a one- or two-microsecond delay, simply return.  the overhead of
    // the function calls takes more than two microseconds.  can't just
    // subtract two, since us is unsigned; we'd overflow.
    if (--us == 0)
        return;
    if (--us == 0)
        return;

    // the following loop takes half of a microsecond (4 cycles)
    // per iteration, so execute it twice for each microsecond of
    // delay requested.
    us <<= 1;

    // partially compensate for the time taken by the preceeding commands.
    // we can't subtract any more than this or we'd overflow w/ small delays.
    us--;
#endif

    // busy wait
    __asm__ __volatile__ (
        "1: sbiw %0,1" "\n\t" // 2 cycles
        "brne 1b" : "=w" (us) : "0" (us) // 2 cycles
    );
}
@4ntoine 4ntoine added the bug label Dec 26, 2014
@4ntoine
Copy link
Owner Author

4ntoine commented Dec 26, 2014

Unfortunately i can't understand at the moment what =w means.
If i comment that asm inline code or replace =w with =r (which seems to be correct) if i'm getting:

fatal error: error in backend: Inline asm not supported by this streamer because we don't have an asm parser for this target

@4ntoine
Copy link
Owner Author

4ntoine commented Dec 26, 2014

I was wrong, "w" is AVR-related constraint and it's valid code:
http://stackoverflow.com/questions/27654116/what-does-w-in-gcc-inline-assembly-mean

@4ntoine
Copy link
Owner Author

4ntoine commented Dec 26, 2014

back-end issue

@4ntoine 4ntoine closed this as completed Dec 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant