Pinguino Forum

Full Version: Code bloat?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4

JoeDaRock

I installed the Pinguino IDE and tried a simple led blink program. According to the IDE status window, this extremely simple program compiles to over 2K bytes! Can this be correct?

Joe
Hi Joe,
Yes it is. .pde programs are just the front end. To use pinMode or digitalwrite functions, Pinguino needs some libraries. The real program (main32.c) need some other ones (for ex. newlib.c and cdc.c).
All together it is only 2K. Not so bad but we could make better in the future.
Régis

JoeDaRock

"Not so bad but we could make better in the future."
--------------------

Not so bad? That's horrible! That's more memory than many PIC's even have in total. If I did this in assembler, or even C, it would compile to less than a couple hundred bytes of object code, maybe less than 100.

Joe
I know that and when I need something very compact I also use asm or make my own optimized C program but it's not the point with Pinguino (or Arduino). Not that we don't care about memory but we have to make choices between simplicity and memory (not between simplicity and efficiency !).
Try to write a program with USB and one-wire protocol and check your code size and what produces Pinguino. You could be surprised.
Régis.


(28-09-2011, 09:58 PM)JoeDaRock Wrote: [ -> ]"Not so bad but we could make better in the future."
--------------------

Not so bad? That's horrible! That's more memory than many PIC's even have in total. If I did this in assembler, or even C, it would compile to less than a couple hundred bytes of object code, maybe less than 100.

Joe

JoeDaRock

(28-09-2011, 10:11 PM)regis Wrote: [ -> ]I know that and when I need something very compact I also use asm or make my own optimized C program but it's not the point with Pinguino (or Arduino). Not that we don't care about memory but we have to make choices between simplicity and memory (not between simplicity and efficiency !).
Try to write a program with USB and one-wire protocol and check your code size and what produces Pinguino. You could be surprised.
Régis.


(28-09-2011, 09:58 PM)JoeDaRock Wrote: [ -> ]"Not so bad but we could make better in the future."
--------------------

Not so bad? That's horrible! That's more memory than many PIC's even have in total. If I did this in assembler, or even C, it would compile to less than a couple hundred bytes of object code, maybe less than 100.

Joe

Olimex

I do believe the actual code for blinking led is not even more than 10 bytes, but as Regis said in the code you load there are runtime libraries included which go in your code no matter if you use them or not
Just for simplicity think that your code starts after the first 2K of flash :-)

Tsvetan

lonemangx

It seems that it has much more bloat compared to arduino. I was surprised to see the ff code's size:

Code:
int level[2];
int length = 0;

uchar* intToChar(int);

void setup()
{
        level[0] = 10;
        level[1] = 200;
}

void loop()
{
    USB.send("hello",5);
    USB.send(intToChar(level[0]), length);
    USB.send(intToChar(level[1]), length);
    delay(2000);
}

uchar* intToChar(int val) {
    uchar chars[5] = {0};
    int i = 0;
    float temp[2] = {0};    
    
    if((val/10000) >= 1) length = 5;
    else if((val/1000) >= 1) length = 4;
    else if((val/100) >= 1) length = 3;
    else if((val/10) >= 1) length = 2;
    else length = 1;
    
    for(i = length; i > 0; i--) {
        temp[0] = pow(10, i);
        temp[1] = pow(10, i-1);
        chars[length - i] = 48 + ( (val%((int)temp[0]))/((int)temp[1]) );
    }
        
    return chars;
}

code size: 13194 / 24575 bytes (53% used)

I have used Arduino for a long time and I don't think this few lines of code would be this much BIG! I hope the code could be further optimized.

Is the ff. error related to size not fitting inside pinguino?
Code:
warning: relocation of section "udata_main_6" failed, relocating to a shared memory location
error: linker script has no definition that matches the type of section "udata_main_6"
error while linking /home/homer/Apps/pinguino_sketches/IRdecoder.o
(01-10-2011, 04:44 PM)Olimex Wrote: [ -> ]I do believe the actual code for blinking led is not even more than 10 bytes, but as Regis said in the code you load there are runtime libraries included which go in your code no matter if you use them or not

Can't the linker drop dead code?
In that particular case it is more a problem with sdcc math lib. than with Pinguino. Just try without floats ...
Régis



(15-10-2011, 03:53 PM)lonemangx Wrote: [ -> ]It seems that it has much more bloat compared to arduino. I was surprised to see the ff code's size:

Code:
int level[2];
int length = 0;

uchar* intToChar(int);

void setup()
{
        level[0] = 10;
        level[1] = 200;
}

void loop()
{
    USB.send("hello",5);
    USB.send(intToChar(level[0]), length);
    USB.send(intToChar(level[1]), length);
    delay(2000);
}

uchar* intToChar(int val) {
    uchar chars[5] = {0};
    int i = 0;
    float temp[2] = {0};    
    
    if((val/10000) >= 1) length = 5;
    else if((val/1000) >= 1) length = 4;
    else if((val/100) >= 1) length = 3;
    else if((val/10) >= 1) length = 2;
    else length = 1;
    
    for(i = length; i > 0; i--) {
        temp[0] = pow(10, i);
        temp[1] = pow(10, i-1);
        chars[length - i] = 48 + ( (val%((int)temp[0]))/((int)temp[1]) );
    }
        
    return chars;
}

code size: 13194 / 24575 bytes (53% used)

I have used Arduino for a long time and I don't think this few lines of code would be this much BIG! I hope the code could be further optimized.

Is the ff. error related to size not fitting inside pinguino?
Code:
warning: relocation of section "udata_main_6" failed, relocating to a shared memory location
error: linker script has no definition that matches the type of section "udata_main_6"
error while linking /home/homer/Apps/pinguino_sketches/IRdecoder.o

William

(15-10-2011, 03:53 PM)lonemangx Wrote: [ -> ]It seems that it has much more bloat compared to arduino. I was surprised to see the ff code's size:

Code:
int level[2];
int length = 0;

uchar* intToChar(int);

void setup()
{
        level[0] = 10;
        level[1] = 200;
}

void loop()
{
    USB.send("hello",5);
    USB.send(intToChar(level[0]), length);
    USB.send(intToChar(level[1]), length);
    delay(2000);
}

uchar* intToChar(int val) {
    uchar chars[5] = {0};
    int i = 0;
    float temp[2] = {0};    
    
    if((val/10000) >= 1) length = 5;
    else if((val/1000) >= 1) length = 4;
    else if((val/100) >= 1) length = 3;
    else if((val/10) >= 1) length = 2;
    else length = 1;
    
    for(i = length; i > 0; i--) {
        temp[0] = pow(10, i);
        temp[1] = pow(10, i-1);
        chars[length - i] = 48 + ( (val%((int)temp[0]))/((int)temp[1]) );
    }
        
    return chars;
}

code size: 13194 / 24575 bytes (53% used)

I have used Arduino for a long time and I don't think this few lines of code would be this much BIG! I hope the code could be further optimized.

Is the ff. error related to size not fitting inside pinguino?
Code:
warning: relocation of section "udata_main_6" failed, relocating to a shared memory location
error: linker script has no definition that matches the type of section "udata_main_6"
error while linking /home/homer/Apps/pinguino_sketches/IRdecoder.o

Is that some code for converting an integer to a string? If so, I'm not sure why the floating point operations are needed, and I don't understand the part where you do the modulo by a division of consecutive digits. Here is a sketch of how to do this more efficiently. It is not complete, and not tested, and it might be buggy, but should give the general idea of what to do. Needs tidying to terminate the string etc. if you need that, but gives a start. Don't flame me if this is unwelcome; Just trying to help.

Code:
// store each digit in val as a char in s[]
s[0] = '0';
int n = 0;
int t = val;
while (t > 0)
{
  s[n++] = 48 + (t - (t % 10));
  t /= 10;
}
// reverse the chars in place
n--;
i = 0;
for (n--, i = 0; i < n; i++, n--)
{
  int q = s[i];
  s[i] = s[n];
  s[n] = q;
}
Pages: 1 2 3 4