sprhawk / python-on-a-chip

Automatically exported from code.google.com/p/python-on-a-chip
Other
0 stars 0 forks source link

Make native function tables const to save RAM #130

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Native fonction tables (usr_nat_fxn_table, std_nat_fxn_table) are not declared 
const and are mapped in RAM. It doesn't look like theses tables can be updated 
and would better fit in ROM.

Declaring this arrays as const (interp.c, pmImgCreator.py) solve the problem.

Expected memory gain : a few bytes ... (sizeof(ptr)*len(tables) => 88bytes on 
my platform).

Original issue reported on code.google.com by monnet.a...@gmail.com on 26 Aug 2010 at 9:00

GoogleCodeExporter commented 9 years ago
Good idea.  Every byte matters.  I'll definitely make this change.

Original comment by dwhall...@gmail.com on 26 Aug 2010 at 4:57

GoogleCodeExporter commented 9 years ago
I used this website to use const correctly: 
http://en.wikipedia.org/wiki/Const-correctness
However, it didn't explicitly mention how to do function pointers, so I'm 
giving it my best guess.

Original comment by dwhall...@gmail.com on 26 Aug 2010 at 9:08

GoogleCodeExporter commented 9 years ago
Size of sections of two platforms before and after applying the changes:

at91sam7s-ek (144 bytes RAM saved):

    Before:
       text    data     bss     dec     hex filename
      52317    2232   12812   67361   10721 main.elf

    After:
       text    data     bss     dec     hex filename
      52461    2088   12812   67361   10721 main.elf

econotag (188 bytes RAM saved):

    Before:
       text    data     bss     dec     hex filename
      68688    2360   24448   95496   17508 src/platform/econotag/main.elf

    After:
       text    data     bss     dec     hex filename
      68440    2172   24448   95060   17354 src/platform/econotag/main.elf

Original comment by dwhall...@gmail.com on 29 Aug 2010 at 4:37

GoogleCodeExporter commented 9 years ago
r587
- Added 'const' to template string in tools/pmImgCreator.py
- Added 'const' to std/usr_nat_fxn_table in vm/interp.c
- Added 'const' to pm_init() arg in vm/pm.c,h and img.c,h

Tests pass.  Sizes checked on most platforms (above).
Mainlined directly.

Original comment by dwhall...@gmail.com on 29 Aug 2010 at 4:54

GoogleCodeExporter commented 9 years ago
Note: This change broke the build for platform/mbed.  Issue #138 fixed the 
build break.

Original comment by dwhall...@gmail.com on 20 Sep 2010 at 9:16