Skip to content

trapexit/armdbccg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

armdbccg: optimal ARM divide-by-constant code generator

This is a tool, based on ARM's divc.c app found in their old ARM Software Development Toolkit, which will generate ARMv3 assembly to divide an unsigned integer by a constant. This is an optimization due to the lack of hardware supported division. The limitation is that the constant must be either equal to (2^n - 2^m) or (2^n + 2^m).

The original tool output assembly for armasm and only generated the quotient and remainder. This tool outputs a C/C++ header file with 3 static inlined inline assembly functions that can return either quotient and remainder, just quotient, or just remainder.

This style was chosen over the assembly versions or a non-inline function version so that the compiler can fully inline the code. The compiler appears not to inline the function unless declared __inline. If you wish for it to be called as a function and not inlined simply remove the __inline declarator.

Usage

armdbccg

$ ./armdbccg --help
armdbccg: optimal ARM divide-by-constant code generator
Usage: ./build/armdbccg [OPTIONS] [divisor]

Positionals:
  divisor INT                 constant divisor

Options:
  -h,--help                   Print this help message and exit
  -v,--version                print version and exit
  -o,--output-path PATH       dirpath or filepath for output

$ ./armdbccg 10
header file written: div_by_10.h

header

#include "div_by_10.h"


unsigned x;


x = div_by_10_q(100);

Notes

headers

See https://github.com/trapexit/armdbccg/tree/master/headers for a number of headers for available constant divs between 3 and 256.

segfaults

There appears to be a bug in the armcc and armcpp compiler which if the 'qr' version is used but the remainder variable in the 'div_t' struct is not used it will segfault. It is currently unclear why this occurs but without the source code there likely isn't anything that can be done about it. If you don't need both values you should simply use one of the other functions. Worse case remove the __inline declarator.

Documentation

Other Links

Support

Development and support of the projects I maintain require a significant amount of time and effort.

If you are a personal user and find my software and its support valuable and would like to support the project financially it would be very much appreciated.

https://github.com/trapexit/support

About

optimal ARM divide-by-constant code generator

Resources

License

Stars

Watchers

Forks

Languages