This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28027: floating-point number and shift issue

Part Number: TMS320F28027

Hi team,

Here's an issue from the customer may need your help:

float M_factor;

uint32_t pwm_duty_tmp;

1) Since M_factor is floating point data and PWM_duty_tmp is an integer, the operations involved are as follows:

A. pwm_duty_tmp= M_factor*256;

B. pwm_duty_tmp= M_factor<<8;

Which one is faster?

2) Does M_factor lose data during the shift (provided that PWM_duty_tmp= M_factor*256 is correct)?

3) If a floating-point number can be shifted, what are the instructions?

Could you help check this case? Thanks.

Best Regards,

Cherry

  • Which one is faster?

    left shift is faster. please refer to the C28x instruction set and C28x extended instruction set docs for such questions. Also, you can write a test program and check the disassembly as well since sometimes these cycle counts vary with optimisation levels, processor settings, etc. However, there will be an overhead of moving the value to the ACC from the variable in RAM. So add 1 cycle to that. 

    Does M_factor lose data during the shift (provided that PWM_duty_tmp= M_factor*256 is correct)?

    You shouldn't lose data if M_factor*256 is correct

    3) If a floating-point number can be shifted, what are the instructions?

    It will use the same 32 bit instruction, LSL ACC,#16 bit

    -Shantanu