Hi All,

We have some algorithms that has many floating arithmetic operations, we are considering to optimize it as it costs too many cycles.

We are using Update 9.1 and I have seen that now we don't need to use fract16 or fract32, just use fract, and don't need to use built-in functions like before, right?

The ways we used before to do this optimization is very complex using shifting and built-in functions, so I am thinking if there is any better way to do this job, could someone give some ideas to us?

For example, float a1 = 2.05, a2 = 100.324;

Now we want to get the result: a1+a2, a1-a2, a1*a2, a2/a1;

btw, I have seen the EE185, and its associated code is not avaliable now on the offical website now. If anyone have these code, would you please send me one for some reference, thanks!

Suppport for Embedded C native fixed-point types was added in VisualDSP++ 5.0 Update 9. This support can be used to express fixed point algorithims in C (not currently C++) source. As a quick and dirty example see the following:

#include <stdio.h>

#include <time.h>

#include <stdfix.h>

static float a1 = 0.123, a2 = 0.246;

static float res;

static clock_t start, stop;

void run_float (void) {

start = clock();

res = a1 + a2;

res += a1 - a2;

res += a1 * a2;

res += a1 / a2;

stop = clock();

}

void run_accum (void) {

// Use signed accum type which has range [-256, 256) which is suitable for

// the operands and result and avoids the need to scale.

accum a1_fract = (accum)a1; // convert operand to accum

accum a2_fract = (accum)a2;

accum res_fract;

start = clock();

res_fract = a1_fract + a2_fract;

res_fract += a1_fract - a2_fract;

res_fract += a1_fract * a2_fract;

res_fract += a1_fract / a2_fract;

stop = clock();

res = (float)res_fract;

}

void run_fract (void) {

// Use signed short fract type which has range [-1, 1)

fract a1_fract = (fract)a1; // convert operand to fract

fract a2_fract = (fract)a2;

fract res_fract;

start = clock();

res_fract = a1_fract + a2_fract;

res_fract += a1_fract - a2_fract;

res_fract += a1_fract * a2_fract;

res_fract += a1_fract / a2_fract;

stop = clock();

res = (float)res_fract;

}

int main() {

run_float();

printf("float implementation: result = %f - took %ld cycles to calculate\n",

res, (long)(stop - start));

run_fract();

printf("fract implementation: result = %f - took %ld cycles to calculate\n",

res, (long)(stop - start));

run_accum();

printf("accum implementation: result = %f - took %ld cycles to calculate\n",

res, (long)(stop - start));

return 0;

}

Using a cycle accurate simulator the output of the example follows:

float implementation: result = 0.776258 - took 690 cycles to calculate

fract implementation: result = 0.776215 - took 90 cycles to calculate

accum implementation: result = 0.776258 - took 376 cycles to calculate

While this support doesn't simplify the design of a fixed-point implemetation, for example the scaling and normalization of inputs, it does make themm easier to express in C source using a standard portable implementation.

You might wish to take a look at the compiler manual documentation for Embedded C support in the "C/C++ Compiler and Library Manual for Blackfin" manual under heading "Native Fixed-Point Types fract annd accum" which is accessible using the help system. Also see the following blog:

http://ez.analog.com/blogs/engineerzone-spotlight/2011/08/01/native-fixed-point-types-in-visualdsp-50

Regarding EE185, you will find an implementation of this in VisualDSP++, through use of header file float16.h. The interfaces are slightly different than in the EE note and the type used is called float16. Take a look at the header file for details, it's located in the install in the Blackfin/include folder. However, please note that this support is deprecated and will not be available in the next major tools release. It is also undocumented in the manuals and while we are not aware of any problems with the functions they haven't had tremendous use as far as we are aware. The problem with the idea is that you failrly quickly lose precision.

Regards,

Stuart.