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.

6713: value assignment taking many clock cycles

I have been having an issue with a certain arithmetic calculation. It is rather complex (a normalised least means squares update):

num = epsilon*nf[k].e[0];

frac = num / nf[k].enorm;

sub = p*frac;

res = nf[k].h - sub;

nf[k].h = res;

As you can see, I have split up the calculation into components num, frac, sub, res.

However, the part that causes the huge cycle count is the final assignment of res to nf[k].h.

Note: 'nf' is an array of structures. Within a loop, I am working on the k'th structure and its elements (.h, .e[0] etc) at a time. All values are float

I have tried storing my structures in memory so they are accessed as close as possible to sequential order.

I have checked the disassembly and when doing the assignment, the program seems to branch off into a '_divf' and '_isnanf' assembly commands for no apparent reason. This should not be due to interrupts, since i think interrupts should be turned off when debugging. 

I have tried declaring the value as volatile, but that doesnt help.

I have tried casting to float, but that only helps by a fractional amount, nowhere near for this to be actually used in practice.

Does anyone know what the problem could be?

SMALL UPDATE:

I have tried assigning nf[k].h directly to a small decimal such as 1.1. this works fine.
I tried assigning nf[k].h directly to a large decimal such as 1.9999999999999999999. This failed as before. Even if i cast this decimal to (float).
I tried assigning 'res' to a small decimal such as 1.1. this doesnt work either

UPDATE 2:

I narrowed it down to the line "frac = ..." etc. If i dont divide it by enorm, then the expected cycle count is observed. However, this division is crucial to my program. Is there a way around this? I can successfully assign a local variable to 1/enorm. However, when i try to use this variable to calculate frac, the same problem occurs where it takes an insanely large amount of clock cycles. 

If it helps, the value for "num" is usually very small, to the order of ^-10 usually. Could this be the issue? I tried scaling up and down by 10^6 but this doesnt help/makes things worse

  • Hi Rajan Chauhan,

    Welcome to the TI E2E forum. I hope you will find many good answers here and in the TI.com documents and in the TI Wiki Pages. Be sure to search those for helpful information and to browse for the questions others may have asked on similar topics.

    This device forum is good for device-specific or hardware/driver questions.

    Please try to give us the answers for the following questions.

    1. You have given a Code snippet and started explaining about it. But it does not tell about what is that you are trying to do and waht is the expected output and what is the actual out put etc. 

    2. What is the type and size of of the variable nf[k]? what is the value of k?. I presume it is a structure variable but the complete structure is not given here.

    3. Is this code snippet belongs to any of the TI packages? If yes, specify the name of the pacakage, version and file name.

    4. How did you measure the cycle count? you used any profile clock using CCS?

    And on the whole, the information provided here is not sufficient/complete to give any suggestions/answers/comments.