public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Big-endian Gcc on Intel IA32
@ 2001-12-23  7:26 dewar
  0 siblings, 0 replies; 30+ messages in thread
From: dewar @ 2001-12-23  7:26 UTC (permalink / raw)
  To: dewar, fw; +Cc: gcc, torvalds

<<Yes, but the interesting case (at least if you have to match a given
external representation) is not addressed:
>>

Well if you are somehow reading 8 bit values through an interface to
a 36-bit machine, then you have to define that separately. That has nothing
whatsoever to do with this discussion.

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Big-endian Gcc on Intel IA32
@ 2001-12-23  7:06 dewar
  2001-12-23  7:08 ` Florian Weimer
  0 siblings, 1 reply; 30+ messages in thread
From: dewar @ 2001-12-23  7:06 UTC (permalink / raw)
  To: dewar, fw; +Cc: gcc, torvalds

<<I wouldn't tackle this problem at the struct level, but at the
discrete type level, IOW introduce additional integer types with
different resentation.  This would already greatly help in many cases.
>>

Yes, I already suggested this, and noted that this was what we did
in Realia COBOL (see archives)

<<If you've got signed-magnitude representation, you've got plenty of
positions in which you can place the sign bit.
>>

There are no S&M machines, so this is bogus. There are 1's complement machines
but the issue is not affected by 1s or 2s complement. Even for S&M, the
sign bit was always the most significant, so you are inventing a non-existant
problem here.

<<If the machine is word-adressed, all we do in this regard won't help
much to increase portability because a lot of data structures with a
given external representation assume you can access individual octets,
and the mapping to a useful machine implementation is certainly not
straightforward.  For example, how does an IP header look on a 36 bit
machine?
>>>

The point is that it is quite straightforward to address the problem WITHIN
an address unit. Ada already does this. Have a look at what GNAT implements
here with the Bit_Order attribute (and also see the discussion of why it
is not easy to do more). This is in the GNAT RM.

^ permalink raw reply	[flat|nested] 30+ messages in thread
* RE: Big-endian Gcc on Intel IA32
@ 2001-12-20  5:36 Etienne Lorrain
  0 siblings, 0 replies; 30+ messages in thread
From: Etienne Lorrain @ 2001-12-20  5:36 UTC (permalink / raw)
  To: gcc

  Just a (maybe meaningless) comment on attributes:

 When you begin to describe your variables with __attribute__(()),
 for instance to optimise code size or speed, you also feel a need
 to test if the variable as such or such attributes, for instance in
 inline functions/macro. Let's take the example of align/alignof:

  struct longstruct mydata __attribute__((aligned(16)));

  static const struct longstruct emptydata = {};

  void init_mydata (struct longstruct *mydataptr)
  {
  if (alignof (emptydata) > 4)
      fast_memcpy(...);
    else
      slow_memcopy(...);
  }

  Maybe a more generic way to define and test attributes, at least
 for structure types, would be something like:

  typedef struct {
      unsigned field1, field2;
      char field3;
      const unsigned __aligned__ = 16; /* not counted in sizeof() */
      } an_aligned_16_type;

  an_aligned_16_type data;

  { if (data.__aligned__ == 16) {} else {} }

  In the same spirit:
  typedef struct {
      const unsigned __packed__ = 1;
      unsigned short d1;
      unsigned long d2;
      }

  typedef struct {
      const unsigned __segment__ = __segment_gs;
      unsigned char red;
      unsigned char green;
      unsigned char blue;
      } what_I_need_for_another_project;

  void fct (void)
  {
  const unsigned __aligned__ = 64;

  ....
  }

  The programmer could also define his own attributes.
  Would also not break too much "indent" and "lint" kind of software.

  No, I do not have the time to implement, sorry.
  Etienne.

___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Courrier : http://courrier.yahoo.fr

^ permalink raw reply	[flat|nested] 30+ messages in thread
* RE: Big-endian Gcc on Intel IA32
@ 2001-12-19 11:47 Bernard Dautrevaux
  2001-12-19 13:09 ` Linus Torvalds
  0 siblings, 1 reply; 30+ messages in thread
From: Bernard Dautrevaux @ 2001-12-19 11:47 UTC (permalink / raw)
  To: 'Linus Torvalds', Morten Welinder; +Cc: gcc

> -----Original Message-----
> From: Linus Torvalds [mailto:torvalds@transmeta.com]
> Sent: Tuesday, December 18, 2001 11:28 PM
> To: Morten Welinder
> Cc: gcc@gcc.gnu.org
> Subject: Re: Big-endian Gcc on Intel IA32
> 

	<skipped>

> 
> (To the person suggesting how to do it in C++ - you _can_ get 
> a subset of
> this in C by the above "embed in a structure" trick).
> 

Just can't resist comment on this. In fact in C++ you can do a lot more; you
can also define all the needed and meaningful operators on this type, so
that you may, for example, add or subtract an int from it, but not add two
of these or multiply them.

Using this C++ "trick" (if you want to call it that way; in fact it's
standard C++ coding practice) you can quite simply defined all the little
endian scalar types, even specifying they are not aligned like the host
processor may expect, and use them as if they were native types. 

Then you only have to define the variable or struct field as little-endian
and you will always swap bytes when reading/writing without having to add
htonl() around each operation. Moreover on some processors, like PowerPC,
you in fact have "load and reverse" and "store and reverse" instruction that
you can use in the inline asm instruction implementing the "convert to
native type" and "assign native type" operations, so that the performance
penalty is in fact very small.

I opersonally have defined such a set of classes for our Object Oriented
Real Time Kernel (SoftKernel) and use it on the PowerPC or 68xxx processors
to access PCI bridges, x86-family devices or USB data structures and
devices, in a way that allow the exact same source code to also be compiled
for an x86 processor and work identically in big-endian and little-endian
environments.

The only thing this does not address is bit-fields. We decided in fact to
handle them manually to be sure of the result, and always choose the
underlying scalar type to ensure that we never have "split-fields".

Just my (obviously C++ biased) .02euros

	Bernard

--------------------------------------------
Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
92400 COURBEVOIE
FRANCE
Tel:	+33 (0) 1 47 68 80 80
Fax:	+33 (0) 1 47 88 97 85
e-mail:	dautrevaux@microprocess.com
		b.dautrevaux@usa.net
-------------------------------------------- 

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Big-endian Gcc on Intel IA32
@ 2001-12-18 11:41 Morten Welinder
  2001-12-18 11:42 ` Phil Edwards
  2001-12-18 14:48 ` Linus Torvalds
  0 siblings, 2 replies; 30+ messages in thread
From: Morten Welinder @ 2001-12-18 11:41 UTC (permalink / raw)
  To: gcc; +Cc: torvalds


Linus Torvalds <torvalds at transmeta dot com> wrote...

> (Inside the kernel, I'd love to be able to taint pointers and data that
> came from user space, for example, to make sure that the compiler will
> refuse to even _compile_ code that uses such data without the proper
> safety checks. This is not all that different from keeping track of what
> byte-order a specific datum has).

I would guess that you can do this with C++.

Now I realize that you are not about to rewrite the kernel in C++
(unless you have sampled a bit too much Glogg recently, :-)  What
I am saying is that you could probably make minor changes to the
current source code such that...

1. Its C interpretation does not change.
2. Its C++ interpretation would have a user_data* type and do the
   check you ask for.

I.e., you could use g++ as the San Jose checker, ;-)  The .o files
would not be any good, of course.

I seem to remember that once upon a time you said that you wanted
type int when you deal with ints (as opposed to having some typedef
name like off_t).  If that is still true, I guess you will not like
this kind of approach.

Morten

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Big-endian Gcc on Intel IA32
@ 2001-12-18  3:49 dewar
  2001-12-23  6:59 ` Florian Weimer
  0 siblings, 1 reply; 30+ messages in thread
From: dewar @ 2001-12-18  3:49 UTC (permalink / raw)
  To: dewar, fw; +Cc: gcc, torvalds

<<Yes, in the general case, this is of course right.  But for two's
complement, octet-adressed machines, endian representation clauses for
discrete types could be implemented without major problems, I think,
at least if you restrict yourself to the little/big endian case and
ignore PDP endian.
>>

I will just give one example of a problem. What do you do with a type
which is a union, one branch of which is a four byte integer, the other
branch is two two-byte integers. Here is another problem, do you want
to allow non-contiguous fields in the case of bit field specifications.
Again, I refer people to the Norm Cohen paper on this subject. Yes, it
is possible that you can find a restricted set of cases you can deal
with at the struct level, but Florian's suggestion that the only
restriction necessary is 2-s complement (what's that got to do with
the problem???) and octet-addressed machines (what's that got to do with
the problem--it's easier to deal with this problem on word addressed machines)
is flawed.

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Big-endian Gcc on Intel IA32
@ 2001-12-17 18:39 dewar
  2001-12-17 18:59 ` Per Bothner
  0 siblings, 1 reply; 30+ messages in thread
From: dewar @ 2001-12-17 18:39 UTC (permalink / raw)
  To: guerby, torvalds; +Cc: dewar, gcc

> Too bad about the algol syntax and all the overkill features (hey, I think
> C++ is complex, Ada is so far off the scale that it's not even funny).>

Well this is not the place for language wars, but in practice those who know
Ada well and C++ well typically find then to be languages of similar
complexity (with perhaps a little bias showing one way or the other), but
a judgment that Ada is "so far off the scale" is one that in my experience
only comes from those who do not know Ada well, or even at all (to be fair
there are plenty of Ada folks who say dubious things about C++ without knowing
the language -- it seems to be a regrettable tendency in the programming
language area for people to have strong opinions about languages they don't
know. As a COBOL expert, I encounter that phenomenon all the time :-) :-)

Anyway, as I say, I don't think that this is the place for language wars,
and flame bait statements like the one quoted here :-)

What I *do* think we can usefully do is to learn from useful features in
the various languages, especially when we are discussing adding new features
to an existing language. In this particular case, I would really like to
see GNU C (and g++) implement some of the Ada features in the data
representation area for two reasons:

  1. These are really useful in controlling layout of data, and dealing with
  such issues as bit order etc.

  2. If this handling was in the back end, it would be more efficient, and
  would allow us to rip a lot of junk out of the Ada front end.

A candidate is indeed some kind of assistance for handling endianess. What
we did in the Realia COBOL compiler, which certainly is helpful and does
not raise awkward language issues, is to simply define the equivalent of
an attribute that applies to an integral type which says what endianess
it has (in Realia COBOL, COMP-4 was IBM compatible big endian, and COMP-5
was Intel little-endian). That's quite easy to implement as a gcc attribute
and would be very useful. This would avoid getting into the more complex
record layout issues.

Another candidate would be bit packed arrays. In practice this is a very
useful feature. Currently the circuitry for bit packing is in the front end
of the Ada compiler, but it would be nice to move it into the back end so
that other GNU languages could take advantage of it.

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Big-endian Gcc on Intel IA32
@ 2001-12-17 13:14 dewar
  2001-12-17 13:42 ` guerby
                   ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: dewar @ 2001-12-17 13:14 UTC (permalink / raw)
  To: dewar, gcc, torvalds

<<<<One thing that might be helpful for portability issues like this, where
the user _is_ willing and able to recompile the application, but maybe
not able to find all subtly users of byte-order dependencies would be to
allow the notion of "byte order attributes" on data structures.
>>


This is a much trickier language feature to design than you would imagine.
We have been struggling with this in Ada for a while.

<<Imagine being able to just tag the data structures with "this data
structure is big-endian", and have the compiler automatically do the
conversion when a value is loaded from such a data structure.
>>

I't snice to imagine, but hard to work out the details.
I am definitely not opposed to this, and indeed support an effort
to try to design such a feature. A good starting point for reading
is Norm Cohen's tutorial on the Bit_Order attribute in Ada (not sure
what the reference is, perhaps someone else can supply it).

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Big-endian Gcc on Intel IA32
@ 2001-12-17 12:08 dewar
  2001-12-17 13:10 ` Linus Torvalds
  0 siblings, 1 reply; 30+ messages in thread
From: dewar @ 2001-12-17 12:08 UTC (permalink / raw)
  To: bose.ghanta, gcc

<<My question to you all is:  Is there a big-endian GCC available on IA32?
                                       If available, who is the source of
contact and what is the effort involved here?
>>

The code quality would be significantly decreased, and you would have 
compatibility problems with everything in site. To me this sounds like
a bad alley to walk down.

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Big-endian Gcc on Intel IA32
@ 2001-12-17 12:00 Ghanta, Bose
  0 siblings, 0 replies; 30+ messages in thread
From: Ghanta, Bose @ 2001-12-17 12:00 UTC (permalink / raw)
  To: 'gcc@gcc.gnu.org'; +Cc: Ghanta, Bose

Dar Gcc members,

  Today we use GCC on PA-RISC a big-endian compiler.  We like it a lot. We
would continue to use it in the current and future products at our company
(Stratus computer inc.).

We are now thinking of a platform migration to Intel IA32 platform.  As you
all know Intel IA32 is a little endian processor family and GCC and all
other products run in little endian format on IA32.  I need to address an
interoperability issue for our customers and big-endian GCC will solve some
part of this problem.

My question to you all is:  Is there a big-endian GCC available on IA32?  
                                       If available, who is the source of
contact and what is the effort involved here?  

Our current product is:

	GCC is a native (big endian) compiler hosted and targeted to a
proprietary OS(VOS) on
	a commodity (PA-RISC) processor.  ELF is the object files.
Proprietary OS (VOS) and
	follows mostly standard ABI.

  Our future plan is: 

	Create GCC as a native (big endian) compiler hosted and targeted to
a proprietary OS (VOS) on
	 a commodity (IA-32) processor. ELF is the object files.
Proprietary OS (VOS) and follows mostly
	 standard ABI.

I would appreciate any help from you here.

My phone number is: (978) 461 7617
      email is:	        Bose_Ghanta@stratus.com

Thank you,
Bose

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2001-12-23 15:08 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-23  7:26 Big-endian Gcc on Intel IA32 dewar
  -- strict thread matches above, loose matches on Subject: below --
2001-12-23  7:06 dewar
2001-12-23  7:08 ` Florian Weimer
2001-12-20  5:36 Etienne Lorrain
2001-12-19 11:47 Bernard Dautrevaux
2001-12-19 13:09 ` Linus Torvalds
2001-12-18 11:41 Morten Welinder
2001-12-18 11:42 ` Phil Edwards
2001-12-18 14:48 ` Linus Torvalds
2001-12-18  3:49 dewar
2001-12-23  6:59 ` Florian Weimer
2001-12-17 18:39 dewar
2001-12-17 18:59 ` Per Bothner
2001-12-17 13:14 dewar
2001-12-17 13:42 ` guerby
2001-12-17 13:43 ` Linus Torvalds
2001-12-17 14:22   ` guerby
2001-12-17 14:52     ` Linus Torvalds
2001-12-17 15:01   ` Richard Henderson
2001-12-17 15:12     ` Linus Torvalds
2001-12-17 15:54       ` Richard Henderson
2001-12-17 17:43         ` Linus Torvalds
2001-12-17 18:12           ` Richard Henderson
2001-12-18 11:55       ` Jason Riedy
2001-12-17 16:43   ` Ross Smith
2001-12-18  1:28 ` Florian Weimer
2001-12-17 12:08 dewar
2001-12-17 13:10 ` Linus Torvalds
2001-12-17 14:00   ` Alan Lehotsky
2001-12-17 12:00 Ghanta, Bose

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).