AnsweredAssumed Answered

Optimize Float to Fixed and Fixed to Float conversions

Question asked by johnmurray on Jun 3, 2011
Latest reply on Jun 6, 2011 by johnmurray

Is there a way to optimize the Float to Fixed And Fixed to Float conversions in the Talkthrough examples like on can with memcpy?

Or in assembler?

 

Is there an engineer to engineer note regarding this?

 

// Unoptimized function to convert the incoming fixed-point data to 32-bit floating-point format.
// This function assumes that the incoming fixed point data is in 1.31 format
void floatData(float *output, int *input, unsigned int instep, unsigned int length)
{
    int i;

    for(i = 0; i < length; i++)
    {
        output[i] = __builtin_conv_RtoF(input[instep*i]);
    }
}


// Unoptimized function to convert the outgoing floating-point data to 1.31 fixed-point format.
void fixData(int *output, float *input, unsigned int outstep, unsigned int length)
{
    int i;

    for(i = 0; i < length; i++)
    {
        output[outstep*i] = __builtin_conv_FtoR(input[i]);
    }
}


// Unoptimized function to copy from one floating-point buffer to another
void memcopy(float *input, float *output, unsigned int number)
{
   // int i;
   // for(i = 0; i < number; i++)
   // {
   //     output[i] = input[i];
   // }

   memcpy(output, input, sizeof(float) * number);
}

Outcomes