LMM Floating Point Demo
jazzed
Posts: 11,803
Here's a small floating point program that fits in LMM memory.
It is using double precision variables and the 64 bit library which is default code generation.
For some reason using the -m32bit-doubles option makes the program to big for LMM.
Here's the code:
It is using double precision variables and the 64 bit library which is default code generation.
For some reason using the -m32bit-doubles option makes the program to big for LMM.
propeller-elf-gcc -o fpdemo.elf -Os -m64bit-doubles -Wall fpdemo.c -lm propeller-elf-strip fpdemo.elf ls -al fpdemo.elf -rwxr-xr-x 1 steve sudo 30656 Nov 8 15:35 fpdemo.elf Propeller Version 1 on /dev/ttyUSB0 Writing 30432 bytes to Propeller RAM. Verifying ... Upload OK! [ Entering terminal mode. Type ESC or Control-C to exit. ] Simple Floating Point Demo 1.000000 * 1.000000 = 1.000000 1.010000 * 1.100000 = 1.111000 1.020000 * 1.200000 = 1.224000 1.030000 * 1.300000 = 1.339000 1.040000 * 1.400000 = 1.456000 1.050000 * 1.500000 = 1.575000 1.060000 * 1.600000 = 1.696000 1.070000 * 1.700000 = 1.819000 1.080000 * 1.800000 = 1.944000 1.090000 * 1.900000 = 2.071000 1.100000 * 2.000000 = 2.200000 1.110000 * 2.100000 = 2.331000 1.120000 * 2.200000 = 2.464000 1.130000 * 2.300000 = 2.599000 1.140000 * 2.400000 = 2.736000 1.150000 * 2.500000 = 2.875000 1.160000 * 2.600000 = 3.016000 1.170000 * 2.700000 = 3.159000 1.180000 * 2.800000 = 3.304000 1.190000 * 2.900000 = 3.451000 1.200000 * 3.000000 = 3.600000 1.210000 * 3.100000 = 3.751000 1.220000 * 3.200000 = 3.904000 1.230000 * 3.300000 = 4.059000 1.240000 * 3.400000 = 4.216000 1.250000 * 3.500000 = 4.375000 1.260000 * 3.600000 = 4.536000 1.270000 * 3.700000 = 4.699000 1.280000 * 3.800000 = 4.864000 1.290000 * 3.900000 = 5.031000
Here's the code:
/** * @file fpdemo.c * Simple floating point demo. */ #include <stdio.h> #include <stdlib.h> #include <math.h> int main() { double v1 = 1; // assign to supress uninitialized warnings double v2 = 1; printf("Simple Floating Point Demo\n"); while(v2 < 4) { printf("%f * %f = %f\n",v1,v2,v1*v2); v1 += 0.01; v2 += 0.1; } return 0; }
Comments
Larger with 32 bit floats? That doesn't make any sense - there must be another compiler option you need to add.
By the way, how do you find out with GCC how big the actual C program is? 30k seems very large for such a small program, but presumably that 30k includes all the drivers, the libraries, the kernel etc?
Here is an example of the results of objdump on fibo.elf: The stuff you care about is:
1) .xmmkernel which contains the COG image of the XMM kernel needed to run the program.
2) .header is a small header I put on all XMM programs that gives a tiny subset of the information from the ELF file. It is primarily used to find the start address and in flash/eeprom programs the address in flash/eeprom of the SRAM and hub initializers.
3) .init contains the C startup code
4) .text contains the program code and possibly constant data. We can also place COG images here that will later be loaded into a COG using coginit or cognew.
5) .fini contains the C finalization code
6) .hub contains data to be loaded into hub memory
7) .ctors contains C++ constructors and any other code that should run before main()
8) .dtors contains C++ destructors and any other code that should run after main() exits
9) .bss contains uninitialized data and doesn't take up any space in the object file. It is initialized to zero by the startup code
10) .heap is just the address where the heap will start.
This program was compiled with -mxmmc (similar to Catalina's SMALL memory model) so all data goes in hub memory. If it had been compiled with -mxmm (similar to Catalina's LARGE memory model) there would also be a .data section containing initialized data to be loaded into external RAM.
Thanks for the explanation David.