www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/16/02:37:29

Date: Tue, 16 Jun 1998 09:35:53 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: lubaldo AT adinet DOT com DOT uy
cc: djgpp AT delorie DOT com
Subject: Re: 64k demo
In-Reply-To: <3.0.1.32.19980616011946.006a2bcc@adinet.com.uy>
Message-ID: <Pine.SUN.3.91.980616093058.12747I-100000@is>
MIME-Version: 1.0

On Tue, 16 Jun 1998 lubaldo AT adinet DOT com DOT uy wrote:

> 	I am not sure why is this, but maybe because GCC knows the sizes of the
> global static array and the offset in the data segment, and in a lot of
> cases it can directly access this array without doing arithmetic to find
> the address. In the 2nd method it cannot know the address of the array of
> pointers and the pointer so it has to find the pointer first (adding to the
> first pointer the value of the line we request) and then it has to add the
> value of this pointer to the column we say. In the 3rd method it knows
> where is the pointer array but not the 1d array, so it does not have to do
> the addition to find the pointer but the addition of the value of the
> pointer and the column we want.
> 	So, my question is if this is true and if it is not true, why is this?

I doubt the above is true.  At the very least, you should look at the 
code emitted by the compiler (gcc -S) and show that it indeed generates 
different code in these cases, and that the differences can indeed 
justify the speed variation you observed.

It is much more probable that changing the implementation caused you to 
change your C source in a subtle way that overflowed the processor's data 
cache, in which case you should see a twofold performance penalty.

> 	My recommendation: for multidimensional arrays try to use them static if
> you can. For 1d arrays I don't know, but it seems that 1d arrays also be
> faster if they are static since GCC know the address directly and don't
> have to add the pointer plus the number of the element we want.

This shouldn't be a problem, since GCC will put the this address in a 
register, and won't access memory more than once.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019