Gliwa-Logo
Weisse Spuren
Surprisingly different, surprisingly effective ./design2013/header-t1-4_web.png
Hacks

Hacker's Delight, by Henry S. Warren, Jr., describes a number of algorithms useful for resource-sensitive computing. Among them is a method for using a multiply instruction to implement division by a constant. There are a number of reasons why this can be useful in embedded devices, some of which do not have a divide instruction (e.g. Arm Cortex-M0). Even when a divide instruction is available, it might be undesirable, either because it is relatively slow or because the execution time is variable in a context where stable execution time is required. Even with high-performance non-embedded processors, the divide instruction might not be wanted, as explained by Matt Godbolt's lecture, "What has my compiler done for me lately? Unbolting the compiler's lid".

In fact, this algorithm is so effective that many compilers use it, silently transforming "x / 9u" into "( x * 0x38E38E39uLL ) >> 33", which can surprise the unsuspecting user while debugging. They see a division at the C source level but a multiplication in the disassembly view.

However, some of our favourite embedded compilers do not do this and so it can be useful to explicitly encode, at the C source level, the implementation using multiplication. This web page allows you to specify either signed or unsigned division by a given constant and applies the algorithm to derive the appropriate C code. The C code is intended for use with a multiply machine instruction that takes two 32-bit operands and provides convenient access to the upper 32 bits of the 64-bit result.

$$q = {n \over d}$$

$n$ type:    

$d =$



Newsbox Oben
HOT TOPICS
Message from our CEO
Learn what impact COVID19 has on GLIWA. And please let us know if we can help with temporary licenses for example.

Peter Gliwa message

Interviews on YouTube
Check-out the interviews with GLIWA CEO Peter Gliwa on Matrickz TV. In this one Peter talks with MATRICKZ CEO Dr. Hasan Akram about timing in automotive software develeopment and in this one about entrepreneurship.

Interview

T1 supports TC39x
Synchronized traces from 6 cores!
T1 makes it happen. Click here, to view a screenshot of T1 with 6 synchronized traces and some cross-core communications.

AURIX TC399

More details on the AURIX 2G can be found in Infineon's official press-release.
Newsbox Unten