Please explain first what point to which a loop (C / C ++) is useful to unearned Has become optimizable?
Secondly, connected to the first question, at what point should the anarchy be not forwarded? Should the unorganized divisions always be divided into dividing the powers of 2? Or is it related to how many calculations your CPU can make? A ratio which is a multiplier of your cache line size? Etc.
For example, if I had a loop from 0 to 99, which would be better / how would I decide (except which test and error) - is a scientific method:
- 0 to 49 for two loops and two "operations"
- 0 to 24 for each loop and four "operations"
- 0 to 19 and Five "operations" per loop
- 0 to 9 and ten "operations" per loop
I can not question any about loop anaololing There is no answer about which This implementation is a bit different from the classic version, but it still works.
Assume that you are applying a mask in a block of memory:
while (n--> Gtr; 0) {* ptr ++ & amp; = Mask; }Then, it can be unearned in this way:
switch (n% 4) {case 0: * ptr ++ & Amp; = Mask; Case 3: * ptr ++ & amp; = Mask; Case 2: * ptr ++ & amp; = Mask; Case 1: * ptr ++ & amp; = Mask; } While ((n - = 4)> 0); Loop unrolling is useful if the walking cost is a significant percentage of the cost of work done within the loop walking. A good optimizing compiler can find it at your optimum level of optimization. If your compiler fails to do so, then you have to shell out yourself.As stated in the observations, after computing the computing cost of jumping, there is no significant significance compared to the calculation. Unauthorized loop body is taken to extremes, from the loop anaololing the education cache may be beaten, it can harm the performance (similar to the aggressive use of the function inlining).
No comments:
Post a Comment