Forum: ARM programming with GCC/GNU tools ARM fixed point vs. floating point

Author: danrok (Guest)
Posted on:

Rate this post
0 useful
not useful
I'm creating application on ARM STM32F103VE. I have to multiply several
matrix in very short time. I'm thinking about using Fixed Point, to
speed up my calculations. So that I wrote union:

typedef union fxpntu{
  int full;
  struct fxpnts{
    int_fast32_t fraction : 31;
    int_fast32_t integer : 1;
  } part;
} fxpnt_t;

My Fixed Point representation is Q1.31.

Than, I created multiplying function:

/* Return: c = a * b */
fxpnt_t fxmul(fxpnt_t* a, fxpnt_t* b) {
  fxpnt_t c;

  _fxpnt_accu64.full = a->full*b->full;

  fxreg |= (_fxpnt_accu64.part.H == 0 && (a->full != 0 || b->full != 
  fxreg |= FX_UFLOW >> 3;

  c.full = _fxpnt_accu64.part.H;

  c.full = FX_UFLOW?0x01:_fxpnt_accu64.part.H;

  return c;

where _fxpnt_accu64 is global object, to hold result.
I made few tests in CrossWorks and results are weird:

float a = -150.534433;
float b = 0.05323;
c = a*b;            // 47 Instructions
c = a+b;            // 55 Instructions
c = a-b;            // 49 Instructions
c = a/b;            // 139 Instructions
ans = fxmul(&fx2, &fx1);   // 165 Instructions

I checked my own multiplying function, and
fxreg |= (_fxpnt_accu64.part.H == 0 && (a->full != 0 || b->full != 
0))<<0x05;  <-- this line takes 43 Instructions.

Can someone explain, or send any link about creating fixed point
on ARM Cortex M-3, or example code? Maybe I'm doing something wrong,
maybe I don't get point of fixed multiplying..

Thanks for Your feedback.

Author: Marcus Harnisch (mharnisch)
Posted on:

Rate this post
0 useful
not useful
danrok wrote:
> Thanks for Your feedback.

Could you provide an example of what you are actually compiling? The 
fragments above do not make sense. For instance there is no structure 
with member H, fxreg is not defined, FX_UFLOW and FX_UFLOW_CLEAR are 
unknown macros.

Please test the example before posting otherwise you are wasting all of 
our times including your own.



Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.