Go Down

Topic: code size (Read 1 time) previous topic - next topic

pYro_65

Like I explained above, the AVR version of arduino does not use direct port IO, I provided a version above which puts it more on par.
Here is a 1000 loop mega version unrolled that is almost half the size of the due.

Code: [Select]

#include <FastDigitalIO.h>

int main(void) __attribute__ ((naked)) __attribute__ ((section (".init9")));
inline void Wait( void ) { __asm__ __volatile__( "nop" ); }

__attribute__( ( noinline ) ) void DelayIt( void ){
  uint32_t u_Count = 0x001EFFFF;
  while( --u_Count ){
    Wait();     
  }
}

#define do10(x) x x x x x x x x x x
#define do50(x) do10(x) do10(x) do10(x) do10(x) do10(x)
#define do250(x) do50(x) do50(x) do50(x) do50(x) do50(x)
#define do1000(x) do250(x) do250(x) do250(x) do250(x)

int main() {
  FastDigitalIO< 13 > p; 
  p.mode( OUTPUT );
 
  while( true ){
    do1000(
    p.write( HIGH );
    DelayIt();
    p.write( LOW );
    DelayIt();
    )
  }
  return 0;
}


22,310 bytes

pagoda


Just to add to the confusion, here's blink with an unrolled loop - 2000*digitalWrite and delay.
Code: [Select]
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

#define do10(x) x x x x x x x x x x
#define do50(x) do10(x) do10(x) do10(x) do10(x) do10(x)
#define do250(x) do50(x) do50(x) do50(x) do50(x) do50(x)
#define do1000(x) do250(x) do250(x) do250(x) do250(x)

// the loop routine runs over and over again forever:
void loop() {
do1000(
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
)
}

Code: [Select]
code size         mega    due
normal blink      1662    9740
unrolled blink    44866   41716


Due beats Mega by 3k :D

This bears out my general experience with the Due - the larger code sizes are because it has a more comprehensive runtime. Ignoring the overhead, code for code the Due seems to be slightly better than the Mega.


I reworked some of my bulkier code and compiled for both Due / Mega.   As everybody has acknowledged, there is more overhead, but there is also a lot more performance.

#pragma message: Compiling for Arduino Due (AT91SAM3X8E)...
Binary sketch size: 62,216 bytes (of a 524,288 byte maximum)

For the Mega - compiles to:
Binary sketch size: 45,634 bytes (of a 258,048 byte maximum)

Nothing as bad as the apparent initial 6:1 sort of increase. Relax I think. :)

I think Due will be pretty good to use, well, after I re-jig the Analog input levels and assorted 5V TTL logic level changers etc.

Graeme


Go Up