17

I have a coprocessor attached to the main processor. Some floating point calculations needs to be done in the coprocessor, but it does not support hardware floating point instructions, and emulation is too slow.

Now one way is to have the main processor to scale the floating point values so that they can be represented as integers, send them to the co processor, who performs some calculations, and scale back those values on return. However, that wouldn't work most of the time, as the numbers would eventually become too big or small to be out of range of those integers. So my question is, what is the fastest way of doing this properly.

7
  • 1
    Learn how floating point math works. It's easy. You should've gotten most of the necessary info at school. The rest can be found online (use Wikipedia, Google, etc). And implement floating point arithmetic routines. Commented Apr 9, 2013 at 18:44
  • But that is a slow method. I want something efficient. Commented Apr 9, 2013 at 18:44
  • 1
    @AlexeyFrunze The OP has already said that emulation is too slow. This isn't an issue of implementing floating point. Commented Apr 9, 2013 at 18:44
  • 1
    Well, something efficient can be done when the problem is defined and is sufficiently narrow. The current question is too broad/general. Commented Apr 9, 2013 at 18:46
  • 1
    fastest & properly... Give a specific problem. A formula you need to compute or something to that effect. How can we give you the fastest and proper solution to an undefined problem? Commented Apr 9, 2013 at 18:52

2 Answers 2

16

You are saying emulation is too slow. I guess you mean emulation of floating point. The only remaining alternative if scaled integers are not sufficient, is fixed point math but it's not exactly fast either, even though it's much faster than emulated float.

Also, you are never going to escape the fact that with both scaled integers, and fixed point math, you are going to get less dynamic range than with floating point.

However, if your range is known in advance, the fixed point math implementation can be tuned for the range you need.

Here is an article on fixed point. The gist of the trick is deciding how to split the variable, how many bits for the low and high part of the number.

A full implementation of fixed point for C can be found here. (BSD license.) There are others.

Sign up to request clarification or add additional context in comments.

5 Comments

Which means, such optimizations should be done on a case by case basis. No silver bullet.
@AlexeyFrunze, indeed. The OP case seems to be pretty special.
Almost +1. The links given are all pure C and one is Java. I like GnuPGP for multi-word arithmetic; in-line assembler is used to get faster multi-word operations when available. I think a fixed point 'C' library could also benefit from this. While fixed point has less dynamic range, it also has a lot less land minds, especially given the embedded tag.
@artlessnoise, sorry, I am not sure what you mean.
Which part all of it? magicfixedpoint appears to be Java. The 'C' libraries are only fixed point and don't include transcendental functions. You can also do bignum (or multi-word) type fixed point, which increased dynamic range. This can be done efficiently with carry hardware. Also floating point has dynamic precision, the larger the value the farther eta is. Fixed point does not have this issue; just to say your answer needs a little balance. Floating point is not a panacea.
6

In addition to @Amigable Clark Kant's suggestion, Anthony Williams' fixed point math library provides a C++ fixed class that can be use almost interchangeably with float or double and on ARM gives a 5x performance improvement over software floating point. It includes a complete fixed point version of the standard math library including trig and log functions etc. using the CORDIC algorithm.

1 Comment

Another project of the same sort is on google hosted project and code project link, these seem to have more of a complete library including some transcendental functions.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.