Fixed-Point c++ library for download

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

Hello fellow developers!

I've prepared a portable c++ library to work with fixed-point data types, using an object-oriented intuitive approach.
Complete source code and doxygen documentation are available.
Feel free to use it in your own fixed-point projects! I've compiled it with vc++ (windows), gcc 4.0 (ubuntu and mac os x).

http://ag-works.net/source.fixpoint.htm


Quickstart usage example:

Code: Select all

 TFix32<28> a = 0.500000;   // 32 bits fixed-point values on the stack,
 TFix32<28> b = 0.170000;   // with 28 decimal bits
 TFix32<28> c = 0.250000;

 TFix32<28> acc = a + b;

 // Evaluate complex expressions using infix overloaded operators
 // with maximum precision and same performance of classic macros (MUL,DIV,..)
 TFix32<28> out = ((a - c) / (a + c)) * (acc >> 1);
Main features:
  • - Object incapsulation of the fixed-point data type
    - Template parameters specify decimal precision
    - Use infix overloaded operators (+,*,..) in complex expressions instead of postfix functions (MUL,DIV,..)
    - Template optimized inlines produce fastest code (code bloat is prevented)
    - Easy and precise conversion among different decimal resolutions
    - Math functions (interoperating with standard data types)
    - Vector processing
Feedback is welcome, enjoy!

Alessandro
Last edited by alex.g on Mon Dec 11, 2006 7:08 pm, edited 1 time in total.
Free VST Plugins at http://ag-works.net/

Post

That looks really cool!

Post

Ohh! As usual a very well thought out and organised project! Thanks!

Post

thx alex, I'll have a poke about that :)

DSP
Image

Post

I'm not the greatest fan of fixed point, but this still is well worth a look, if only for the stylish use of templates. Thanks for sharing.

Post

Actually you shouldn't expect big performance improvements on modern cisc CPUs. On a P4 you get no improvements at all.

This library is for those people developing for risc architectures such as ARM and similars, with no floating-point support, i.e. in portable devices (pocket pcs, smartphones). There, floating point "emulation" (available with some compilers) is at least 50 times slower than the fixed point instructions.
In such platforms you have to use fixed-point, and this library lets you prototype as you would do with floating points or integers, without worrying about the internal decimal representation, rounding, converting etc.
[...] this still is well worth a look, if only for the stylish use of templates [...]
Actually I had a lot of fun during design, especially when implementing functions with parameters of different precision, as you can see in source code! :wink:
Free VST Plugins at http://ag-works.net/

Post

yup, I should have said "not the biggest fan of fixed point on x86". It's true that it may be useful on some platforms.

Post

How well does it deal with conversions to and from floating point?

Post

alex.g, why not create a 'log2 floating point' class? :) Something similar to IEEE floating point, but without using logE base? That should not have much worse performance than fixed point in your implementation, but will be an ultimate replacement for IEEE floating point format. You'll need a sign bit, a 'point position' variable expressed in bits (e.g. going from -16 to 15), and mantissa (that's 26 bits of mantissa in 32-bit value). Bit shift will be just an incrementing/decrementing of point position. After each math operation you'll have to normalize the number and bring its point position to the optimal state that gives the most precision (you'll have to check range of point position on this step). I think I've seen algorithms that calculate number of significant bits in a number quickly, which you can use as well.

By the way, as far as I know min/max with branching is faster on modern CPUs than bit-wise operation min/max.
Image

Post

logE base? What are you talking about? IEEE is in base 2, isn't it?

Post

mistertoast, you are right. :) I have mixed something up...

But that leads me to a question: why everyone trying to use fixed-point math while floating point is not so much different?
Image

Post

I mean, floating point implemented as integer math.
Image

Post

Lots of hardware (DSP hardware) doesn't have good floating point. fixed is great for embedded systems.

Post

*blink*

*blink*
Image
Don't do it my way.

Post

mistertoast wrote:Lots of hardware (DSP hardware) doesn't have good floating point. fixed is great for embedded systems.
Without a doubt. But with fixed point you also need to do operations you would do with floating point (in the sense I've described). E.g. fixed-point multiplication requires shift after the operation - and you have to use a wider 64-bit register for this op (which is relatively slow on 32-bit hardware - even PC).

Fixed point is quicker, of course, since you do not have to do pre-shifting before operation, and normalization after operation, but floating point offers better scalability.
Image

Post Reply

Return to “DSP and Plugin Development”