I'm working on some Arduino code and have the following code:
uint8_t world[24][2][3];
bool getDispPixel(uint8_t x, uint8_t y, uint8_t num)
{
static uint8_t rowByte = 0; // 0 means top 8, 1 means bottom 8
static uint8_t rowBit = 0;
if(y > 7)
{
rowByte = 1;
rowBit = x - 8;
}
else
{
rowByte = 0;
rowBit = x;
}
return (world[x][rowByte][num] & (1 << rowBit)) > 0;
}
void setDispPixel(uint8_t x, uint8_t y, uint8_t num, bool state)
{
static uint8_t rowByte = 0; // 0 means top 8, 1 means bottom 8
static uint8_t rowBit = 0;
if(y > 7)
{
rowByte = 1;
rowBit = x - 8;
}
else
{
rowByte = 0;
rowBit = x;
}
if(state)
world[x][rowByte][num] |= (1 << rowBit);
else
world[x][rowByte][num] &= ~(1 << rowBit);
}
What's weird is these methods add a TON of size to the program. Even just parts of it. If i comment out the following part from just one of the methods, it drops 2536 bytes from the program size!
if(y > 7)
{
rowByte = 1;
rowBit = x - 8;
}
else
{
rowByte = 0;
rowBit = x;
}
Both methods are called quite often, over 200 times combined. I would believe it if they were marked as inline, but they are not. Any idea of what could be causing this?
Update: If I completely comment out those methods' contents it drops the size by 20k! Looks like every call to the function eats up 94 bytes. No idea why...