Skip to content

ATTINY code will never run. #960

Closed
Closed

Description

@8633brown

This section of code will never run

#elif SCALE8_AVRASM == 1
#if defined(LIB8_ATTINY)
#if (FASTLED_SCALE8_FIXED == 1)
uint8_t work=i;
#else
uint8_t work=0;
#endif
uint8_t cnt=0x80;
asm volatile(
#if (FASTLED_SCALE8_FIXED == 1)
" inc %[scale] \n\t"
" breq DONE_%= \n\t"
" clr %[work] \n\t"
#endif
"LOOP_%=: \n\t"
/*" sbrc %[scale], 0 \n\t"
" add %[work], %[i] \n\t"
" ror %[work] \n\t"
" lsr %[scale] \n\t"
" clc \n\t"*/
" sbrc %[scale], 0 \n\t"
" add %[work], %[i] \n\t"
" ror %[work] \n\t"
" lsr %[scale] \n\t"
" lsr %[cnt] \n\t"
"brcc LOOP_%= \n\t"
"DONE_%=: \n\t"
: [work] "+r" (work), [cnt] "+r" (cnt)
: [scale] "r" (scale), [i] "r" (i)
:
);
return work;
#else

as SCALE8_AVRASM can only equal 1 when LIB8_ATTINY is undefined.

FastLED/lib8tion.h

Lines 245 to 253 in 42441aa

#if !defined(LIB8_ATTINY)
#define SCALE8_C 0
#define SCALE16BY8_C 0
#define SCALE16_C 0
#define MUL8_C 0
#define QMUL8_C 0
#define EASE8_C 0
#define BLEND8_C 0
#define SCALE8_AVRASM 1

Activity

  1. self-assigned this
    on Jan 29, 2020
  2. kriegsman commented on Jan 29, 2020

    @kriegsman
    Member

    Oops. Good catch. Thank you.

  3. added
    platform: avr
    area: core
    status: stale
    status: triage
    on Apr 16, 2026
  4. zackees commented on Jun 3, 2026

    @zackees
    Member

    Tracked in FastLED/fbuild#389 for AVR / megaAVR / ATtiny fbuild platform/build support validation.

    That fbuild issue is scoped to board metadata, toolchain/backend support, and FastLED smoke-build evidence. Any remaining FastLED source/platform-code blocker should stay linked from both sides.

  5. zackees commented on Jun 3, 2026

    @zackees
    Member

    fbuild build-system status update (tracker: FastLED/fbuild#389)

    This is a FastLED-side macro-guard issue, not a build-tool issue. fbuild has no fbuild-side gap to track here. The bug is the logical inconsistency between LIB8_ATTINY and SCALE8_AVRASM in lib8tion.h / lib8tion/scale8.h.

    Cross-linked from FastLED/fbuild#389 for completeness.

  6. zackees commented on Aug 2, 2026

    @zackees
    Member

    Fixed. Closing after verifying against current master.

    The bug you reported was real. In 42441aa, lib8tion.h set SCALE8_AVRASM = 1 only in the #ifndef LIB8_ATTINY arm, while lib8tion/scale8.h guarded its ATtiny shift-and-add assembly with #elif SCALE8_AVRASM == 1 → #if defined(LIB8_ATTINY). Those two conditions were mutually exclusive, so that inner block was unreachable and ATtiny silently fell through to the plain C multiply. Good catch, and @kriegsman agreed at the time.

    It is fixed now, by restructure rather than by patching the guard. LIB8_ATTINY no longer exists anywhere in the tree — grep -rn 'LIB8_ATTINY\|SCALE8_AVRASM' src/ finds SCALE8_AVRASM only as a config macro, and LIB8_ATTINY not at all. What replaced it:

    1. Detection moved to a dedicated header. src/platforms/avr/is_avr.h defines FL_IS_AVR_ATTINY (plus FL_IS_AVR_ATTINY_MODERN, _TINY_MEMORY, _NO_UART).

    2. Dispatch happens before the macros are read. src/platforms/scale8.h:10-23 picks the implementation header up front:

      #if defined(__AVR__)
      #ifdef FL_IS_AVR_ATTINY
      #include "platforms/avr/attiny/math/scale8_attiny.h"   // no MUL: shift-and-add + C
      #else
      #include "platforms/avr/atmega/common/scale8_avr.h"    // MUL-based asm
      #endif

      The shift-and-add routine from your report now lives at scale8_attiny.h:28 — the same sbrc/add/ror/lsr/brcc loop, verbatim — and it is the only scale8() compiled on ATtiny.

    3. The config macros are now mutually exclusive by construction. src/platforms/math8_config.h sets SCALE8_C=1, SCALE8_AVRASM=0 under FL_IS_AVR_ATTINY and the exact inverse otherwise. The remaining #if SCALE8_C == 1 / #elif SCALE8_AVRASM == 1 / #else #error chains in platforms/scale8.h therefore have no dead arm — and the #error fallback makes a future regression a build failure rather than silence.

    Verified on hardware config, not just by reading: bash compile attiny85 --examples Blink succeeds (3.37KB / 8KB flash, 411 / 512 bytes RAM), and disassembling the resulting ELF with avr-objdump -d yields zero mul instructions — which is the definitive check, since the whole point of the ATtiny branch is that the part has no hardware multiplier. The MUL-based SCALE8_AVRASM code is provably not in the binary.

    Re @zackees' notes above: agreed this was a FastLED-side macro-guard issue with no fbuild component, and FastLED/fbuild#389 can stand on its own for AVR/megaAVR/ATtiny build validation.

    Thanks for the precise report — a permalink to the exact unreachable lines is the ideal way to file this kind of thing.

  7. moved this from Triage to Done in FastLED Trackeron Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: coreplatform: avrstatus: stalestatus: triage

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions