ARM fixed point vs. floating point

Guest #1767379
Hi,
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 != 
0))<<0x05;
  fxreg |= FX_UFLOW >> 3;

  c.full = _fxpnt_accu64.part.H;

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

  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.
#1771058
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.

--
Marcus
http://www.doulos.com/arm/

Reply

A question of your own? This thread is over 16 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.