Donotalo
Donotalo

Reputation: 13025

64-bit integer implementation for 8-bit microcontroller

I'm working on OKI 431 microcontroller. This is 8-bit microcontroller. We don't like to have any floating point operation to be performed in our project so we've eliminated all floating point operations and converted them into integer operations in some way. But we cannot eliminate one floating point operation because optimizing the calculation for integer operation requires 64-bit integer which the micro doesn't natively support. It has C compiler that supports upto 32-bit integer operation. The calculation takes too long time which is noticeable in a way to user.

I'm wondering if there is any 64-bit integer library that can be easily used in C for microcontoller coding. Or what is the easiest way to write such thing efficiently? Here efficiently implies minimize amount of time required.

Thanks in advance.

Upvotes: 3

Views: 5793

Answers (3)

avra
avra

Reputation: 3730

Whenever speed is a problem with floating point math in small embedded systems, and when integer math is not enough, fixed point math is a fast replacement.

http://forum.e-lab.de/topic.php?t=2387

http://en.wikipedia.org/wiki/Fixed-point_arithmetic

http://www.eetimes.com/discussion/other/4024639/Fixed-point-math-in-C

http://en.wikibooks.org/wiki/Embedded_Systems/Floating_Point_Unit

Upvotes: 0

nategoose
nategoose

Reputation: 12392

Since this is a micro-controller you will probably want to use a simple assembly library. The fewer operations it has to support the simpler and smaller it can be. You may also find that you can get away with smaller than 64 bit numbers (48 bit, perhaps) and reduce the run time and register requirements.

Upvotes: 3

Mike Dunlavey
Mike Dunlavey

Reputation: 40669

You may have to go into assembly to do this. The obvious things you need are:

  • addition

  • 2s complement (invert and increment)

  • left and right arithmetic shift by 1

From those you can build subtraction, multiplication, long division, and longer shifts. Keep in mind that multiplying two 64-bit numbers gives you a 128-bit number, and long division may need to be able to take a 128-bit dividend.

It will seem painfully slow, but the assumption in such a machine is that you need a small footprint, not speed. I assume you are doing these calculations at the lowest frequency you can.

An open-source library may have a slightly faster way to do it, but it could also be even slower.

Upvotes: 2

Related Questions