c - My Fixed point arithmetic implementation, performance -


i'm implementing fixed point arithmetic, in c, extends format of usual c types.

for example... know greatest size allowed c integer types 8 bytes.

my extension works in way

typedef struct fixed_point {    unsigned long long int chunk[chunk_element]; } fixed_point; 

where chunk_element set macro statement, when compile have specific version of fixed point stuff.

i choose way of implementation (i.e. embodie array struct) because make easier implementation of stuff like

fixed_point sum(fixed_point __x, fixed_point __y); 

my question is efficient implement stuff in way? instead work straight array defining

typedef unsigned long long int[bit_chunk_size] fixed_point 

but in case should implement stuff like

void sum(fixed_point* __z, fixed_point __x, fixed_point __y); 

which pretty tedious syntax point of view.

what think?

(ps. i'm implementing basic operator <<,>>,&,|,^,+,-,*,/ etc)

a thing check done authoritative implementations of fixed-point.

here how fixed-point addition done in arm cmsis math library:

    /**      * @brief q31 vector addition.      * @param[in]       *psrca points first input vector      * @param[in]       *psrcb points second input vector      * @param[out]      *pdst points output vector      * @param[in]       blocksize number of samples in each vector      * @return none.      */     void arm_add_q31(     q31_t * psrca,     q31_t * psrcb,     q31_t * pdst,     uint32_t blocksize); 

with:

    typedef int32_t q31_t;  // 32-bit fractional data type in 1.31 format 

as can see function works array of values. other fixed-point functions work on individual values. cmsis says (for sine function , ones work on individual values):

"this set of functions provides fast approximation sine, cosine, , square root. compared of other functions in cmsis math library, fast math functions operate on individual values , not arrays."


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -