www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2004/11/10/16:12:14

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Date: Wed, 10 Nov 2004 22:59:24 +0200
From: "Eli Zaretskii" <eliz AT gnu DOT org>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp-workers AT delorie DOT com
Message-ID: <01c4c768$Blat.v2.2.2$4dcfb280@zahav.net.il>
X-Mailer: emacs 21.3.50 (via feedmail 8 I) and Blat ver 2.2.2
Subject: Alignment problem on Windows XP
Reply-To: djgpp-workers AT delorie DOT com

The short test program attached at the end of this message prints
zero values on Windows 98, but a user who tried it on XP told me it
printed "4", which means that __attribute__((__aligned__)) is not
working on XP.

The assembly emitted by GCC is okay, so I suspect that the XP DPMI
host somehow screws up our alignment.  Any ideas why this happens or
how to overcome it?

In case you are curious, this comes from Emacs which needs to have
certain variables aligned on 8-byte boundary to be able to use the
low-order bits of their address for Lisp data type tags.  Previously,
high-order bits were used, but that limited the maximum size of a
buffer to 128MB, while with LSB tags we can go as far as 256MB.  So
I'd like to have this problem solved on XP as well, if at all
possible.

-------------------------------------------------------------------
#include <stdio.h>

#define GCTYPEBITS 3
#  define DECL_ALIGN(type, var) \
    type __attribute__ ((__aligned__ (1 << GCTYPEBITS))) var

struct SS
{
  char *ptr;
  long nr;
};


DECL_ALIGN (struct SS, ss1);
DECL_ALIGN (struct SS, ss2);
DECL_ALIGN (struct SS, ss3);
DECL_ALIGN (struct SS, ss4);

int
main ()
{
  int rem;

  rem = (unsigned long)&ss1 % 8;
  printf ("ss1: rem %d\n", rem);
  rem = (unsigned long)&ss2 % 8;
  printf ("ss2: rem %d\n", rem);
  rem = (unsigned long)&ss3 % 8;
  printf ("ss3: rem %d\n", rem);
  rem = (unsigned long)&ss4 % 8;
  printf ("ss4: rem %d\n", rem);

  return 0;
}

- Raw text -


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