Unlike the Cortex-M3 and M4, 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).]
Certain NXP Cortex-M0 based MCU’s, such as LPC11Axx, LPC11Exx, LPC11Uxx and LPC12xx, include optimized code in ROM to carry out divide operations. 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).
Enabling the use of ROM Divide in LPCXpresso IDE
In order to make the ROM divide routines as easy to access from application code as possible, LPCXpresso IDE contains support within the project wizards for appropriate MCUs 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 project wizard will then cause the appropriate compiler, assembler and linker options to be set for your project.
Note that these 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".
Repeat steps 3 and 4 for all Build Configurations (typically Debug and Release)
Note : in some circumstances, in order for your project to link, you may also need to add "--allow-multiple-definition" to the "Other Options" of the "MCU Linker - Miscellaneous" properties. This should not be necessary in LPCXpresso v7 though.