LPC12xx ROM Divide
Unlike the Cortex-M3, the Cortex-M0 does not provide support for divides in hardware. This means that when application code carries out a divide operation, the compiler will insert a call to a library divide function. Thus if your application, or the library routines it invokes, use divide operations, then a certain amount of space in your FLASH will be consumed by one or more library divide functions.
[The divide function calls generated by the compiler are documented in the run-time section of the Application Binary Interface for the ARM Architecture (commonly known as the AEABI).]
NXP's LPC12xx family of MCU's include Code Red's optimized "real-time" divide functions in the MCU's built-in library ROM. These ROM divide functions operate in "near-constant-time", such that a particular divide function will provide a result in approximately the same amount of cycles, regardless of inputs and the resulting value.
This contrasts with the standard divide library routines that will be pulled from the C library, where the performance will be based on the number of bits in the quotient (the result). For a given set of tests, the ROM divide routine performance is likely to be slower than the fastest performance possible from the standard divide library routines, but quicker than the slowest performance possible from the standard divide library routines.
The other advantage to using the ROM divide library routines is that if your application carries out divide operations, the code overhead of the divide function is removed from your flash (as the routines exist in the library ROM instead).
In order to make the ROM divide routines as easy to access from application code as possible, the Code Red IDE (version 3.6.2 and later on Windows, version 3.8.2 on Linux) contains support within the LPC12xx project wizard to redirect calls generated by the compiler to the AEABI divide routines directly on to the ROM divide routines.
To enable this support, ensure that the "Enable use of RomDivide library by compiled code" option is ticked in in the project wizard options...
The LPC12xx project wizard will then cause the appropriate compiler, assembler and linker options to be set for your project.
Note that the LPC12xx project wizard will always create a file called "aeabi_romdiv_patch.s" into the src directory of your new project, which contains the code to redirect the divide function calls onto the ROM divide routines. This will only take effect if the appropriate compiler, assembler and linker options are set.
If you decide that you want to switch a project over to using the ROM divide routines when it was created without the support enabled, then you can do so as follows:
- Select the project in the Project Explorer view and then open the Project properties.
- In the left-hand list of the Properties window, open "C/C++ Build" and select "Settings" and then the "Tool Settings" tab.
Now choose "MCU C Compiler - Symbols" and add __USE_ROMDIVIDE to the "Defined Symbols".
Now choose "MCU Assembler - General" and add -D__USE_ROMDIVIDE to the "Assembler flags".
Now choose "MCU Linker - Miscellaneous" and add --allow-multiple-definition to the "Other Options". Note that this should not be necessary with current versions of the Code Red IDE.
- Repeat steps 3,4 and 5 for all Build Configurations (typically Debug and Release).