INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

local pointers with an EXPLICIT lower bound

local pointers with an EXPLICIT lower bound

(OP)
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?

RE: local pointers with an EXPLICIT lower bound

Have you looked at the code generation?

RE: local pointers with an EXPLICIT lower bound

(OP)
Sorry, could you explain what do you mean by code generation and how I can look at that?

RE: local pointers with an EXPLICIT lower bound

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.

RE: local pointers with an EXPLICIT lower bound

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close