This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Calculation of displacement of a variable.


Rama Singh wrote:

--- C Jaiprakash, Noida
<cjaiprakash@noida.hcltech.com> wrote: >


Hi,
  I am working on a gcc port, i have a question
about how displacements
are calculated for variables in gcc. Consider for ex
following code

void fun()
{
   char a,b,c,d;
   int    x,y,z;
   long  i,j,k;

}
Assuming following sizes for char = 8 bit
int = 16 bit
long = 32 bit
following will the dislacements for above variables


a = Base Reg + 1
b = Base Reg + 2
c = Base Reg + 3
d = Base Reg + 4

x = Base Reg + 6
y = Base Reg + 8
z = Base Reg + 10

i = Base Reg + 12
j = Base Reg + 16
k = Base Reg + 20

But the problem is h/w accesses memory as nth byte
ot nth word so ( Base
Reg
+ 1 ) if accessed in byte access mode will read 1st
byte.
For ex byte at 0001h if BASE REG = 0000h
and it will access 1st word if memory is accessed in
word mode. i.e a
word from memory location 0002h.

Due to this behaviour of h/w the actual
displacements should have been
generated as below

a = Base Reg + 1
b = Base Reg + 2
c = Base Reg + 3
d = Base Reg + 4

x = Base Reg + 3
y = Base Reg + 4
z = Base Reg + 5

i = Base Reg + 6
j = Base Reg + 8
k = Base Reg + 10

Is it possible to generate such displacements in
gcc? Basically
definitions of BITS_PER_UNIT and UNITS_PER_WORD here
are dependent on
mode, i.e for QImode : BITS_PER_UNIT = 8,
UNITS_PER_WORD = 2 HImode :
BITS_PER_UNIT = 16, UNITS_PER_WORD = 1 SImode :
BITS_PER_UNIT = 16,
UNITS_PER_WORD = 1

Can this behaviour be implemented in gcc? any
pointers in this direction
are appreciated.



I am not sure about your hardware but whatever is
clear from your mail is that you can have two memory
addresses both deferring on the basis of _Modes_. Now
if you are switching Memory_Access_mode through some
instruction then you must be emitting that
memory_switch_insn. Following that just have the
BAse_Reg + Displacement/2 otherwise keep the default
setting of Base_Reg + Displacement.


Yes abosulte address can be divided by 2 for higher modes but this will be a costly thing to do.

This is a little
tricky part but the displacement can be modified in
your target.c file.


Again same as above, for non constant offset the cost is very high. So this idea of dividing or modifying displacement can not be applied.

C Jaiprakash


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]