Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

local pointers with an EXPLICIT lower bound 1

Status
Not open for further replies.

ya0037

Programmer
Oct 7, 2010
30
0
0
DE
I have tried to test my code and confronted with st strange:
making local pointers with an EXPLICIT lower bound seems to generate faster code.
Is this right? In case it is, why?
 
Have you looked at the code generation?
 
Sorry, could you explain what do you mean by code generation and how I can look at that?
 
Depends on the compiler - some compilers will generate an assembler listing if requested to do so. You can then compare the ones with and without the lower bound.

Alternatively, in the debugger, set a breakpoint where the code is accessing an array index and have a look at the disassembly.

At a guess, if you specify a lower bound of 0, it will be faster (since it is easier to compute arrays from a 0 index). If it is any other lower bound, the speed will be the same.
 
Just to clarify - say there are 3 arrays

integer a(-5:5), b(0:10), c(11)

And there are 3 computations

a(2) = 10
b(2) = 10
c(2) = 10

To compute the index

addr(a(2)) = addr(a) + (2 - (-5)) * size(integer)
addr(b(2)) = addr(b) + (2 - (0)) * size(integer) optimized to b + 2 * size(integer)
addr(c(2)) = addr(c) + (2 - (1)) * size(integer)

The computation of b has one instruction less so in theory, it will be faster.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top