public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: New back end ia16: 16-bit Intel x86
@ 2007-08-06 14:23 Uros Bizjak
  2007-08-07  1:29 ` Rask Ingemann Lambertsen
  0 siblings, 1 reply; 56+ messages in thread
From: Uros Bizjak @ 2007-08-06 14:23 UTC (permalink / raw)
  To: GCC Patches; +Cc: Rask Ingemann Lambertsen, Jan Hubicka, Richard Kenner, rridge

Hello!

> On Wed, Aug 01, 2007 at 08:47:25AM -0400, Richard Kenner wrote:
> > > Could you give an outline of the benefits of merging it with the i386 port?
> > 
> > It's a subset of the registers and basically the same instruction set.
> > It has exactly the same relationship to the i386 port as the i386 port
> > has to the x86_64 port and that's merged.
>
>    What I mean when I ask you to mention benefits of merging ia16 into i386
> is things like
>
>  - will it make the compiler easier to maintain?
>  - will it make the compiler run faster?
>  - will it make the compiler use less memory?
>  - will it make the compiler produce better code?
>  - will it make the compiler easier to use?
>
> but feel free to add anything else that comes to your mind.
>   

IMO, point 1 outweighs all other points. The 16bit port is not something 
I'd consider heavily used port, so my main concern here would be a 
possible bitrot of the contributed code. To avoid this, I think that as 
much as possible code should be shared between much tested i386 and 
ix86_16 parts. This way, all improvements to i386 backend would 
automatically be available to ix86_16 backend. And since quite some 
people look into i386 code, much more eyeballs will stare at your code 
too, surely much more than if your code would be hidden in some obscure 
directory. Please also remember that quite some of your 
ideas/improvements based on your (not even released) backend  were added 
to generic i386 backend, so both backends would benefit from code share. 
And considering the fact that every year processing power and memory 
(almost) doubles, I wouldn't care too much about the speed and memory 
consumption in this particular case as it is far less important than 
point 1, 4 and perhaps 5.

As an example, existing MIPS backend covers all targets from one code 
base, ranging from embedded 16bit to 64bit targets.

If you choose this approach, I can help you to factor out common code to 
merge both backends.

Thanks for this great contribution,
Uros.


^ permalink raw reply	[flat|nested] 56+ messages in thread
* Re: New back end ia16: 16-bit Intel x86
@ 2007-08-19 19:58 Ross Ridge
  0 siblings, 0 replies; 56+ messages in thread
From: Ross Ridge @ 2007-08-19 19:58 UTC (permalink / raw)
  To: gcc-patches

Ross Ridge writes:
>You also need to add the cost zero extending the 16-bit pointer values to
>32-bits, so using 32-bit addressing modes will only rarely be worthwhile.

Rask Ingemann Lambertsen writes:
>Daniel and Peter have modelled the 32-bit registers with separate top
>and bottom halves to be able to keep track of when the top half has
>been touched.

I was assuming optimizations like this.  Even with hand optimized 16-bit
assembly it's hard to use the 32-bit addressing modes effectively. 

>> Code that operates on SP only needs to set or restore SP to work
>> correctly.
>
>It also doesn't clobber the upper half of %esp, obviously it doesn't need
>to restore it.

Code that clobbers the upper half of ESP doesn't need to restore it for
code the only uses SP to work correctly.  From GCC's perspective, this is
a calling convention issue.  In the 16-bit IA-32 calling convetions the
upper 16-bits of all the 32-bit registers (other than EIP) are undefined
at entry and are all call clobbered.  It might be worth while for H. Peter
Anvin and Daniel Verkamp's port to have an option where GCC assumes the
higher 16-bits of ESP are zero, but the "ABI" doesn't guarantee this.

>> No.  The full 32-bit segment offset is checked against the segment limit
>> in both real mode and 16-bit protected mode.  Even if that weren't the
>> case, and it's possible to trick the CPU to use a segment limit other
>> than 0xFFFF in real mode, all 32-bits of ESP would be used to calculate
>> the 32-bit linear address.
>
>I'm just going by the documented maximum real address mode address of
>0xfffff.

The actual documented maximum real mode address is 0x10FFEF.  In 16-bit
protected mode the segment limits can be set arbitrarily.

>  It's OK if the CPU raises an exception; my worry would have been
>silent stack corruption.

That's absurd.  It's not OK for GCC to generate code that would cause
a correct program to crash.

					Ross Ridge

^ permalink raw reply	[flat|nested] 56+ messages in thread
* Re: New back end ia16: 16-bit Intel x86
@ 2007-08-19 16:11 Ross Ridge
  2007-08-19 17:36 ` Rask Ingemann Lambertsen
  0 siblings, 1 reply; 56+ messages in thread
From: Ross Ridge @ 2007-08-19 16:11 UTC (permalink / raw)
  To: gcc-patches

Rask Ingemann Lambertsen writes:
>It doesn't seem to be a likely problem to me. Code operating on %sp
>can't clobber the top half[1]. Code operating on %esp will need to
>restore it or run into trouble. It would be very unusual to not restore
>the stack pointer.

Code that operates on SP only needs to set or restore SP to work
correctly.

>If this was to be a problem, you wouldn't be able to just use
>".code16gcc".

Yes.

>[1] Strictly speaking, only bits 16-19 are of any concern.

No.  The full 32-bit segment offset is checked against the segment limit
in both real mode and 16-bit protected mode.  Even if that weren't the
case, and it's possible to trick the CPU to use a segment limit other
than 0xFFFF in real mode, all 32-bits of ESP would be used to calculate
the 32-bit linear address.

					Ross Ridge

^ permalink raw reply	[flat|nested] 56+ messages in thread
* Re: New back end ia16: 16-bit Intel x86
@ 2007-08-18 20:46 Ross Ridge
  2007-08-19 16:20 ` Rask Ingemann Lambertsen
  0 siblings, 1 reply; 56+ messages in thread
From: Ross Ridge @ 2007-08-18 20:46 UTC (permalink / raw)
  To: gcc-patches

Rask Ingemann Lambertsen writes:
>It is not different in your case! You're targetting the i386, so you
>can use i386 addressing modes at just the cost of a 0x67 prefix

You also need to add the cost zero extending the 16-bit pointer values to
32-bits, so using 32-bit addressing modes will only rarely be worthwhile.
Unlike with 16-bit integers, which are available in both 16-bit and
32-bit modes, 16-bit pointers are where in practice real space savings
can be acheived.

>With disp(%esp) being valid on i386, you don't have that problem either.

Only if you can assume the higher 16-bits of ESP are zero.

					Ross Ridge

^ permalink raw reply	[flat|nested] 56+ messages in thread
* Re: New back end ia16: 16-bit Intel x86
@ 2007-08-02 20:15 Ross Ridge
  0 siblings, 0 replies; 56+ messages in thread
From: Ross Ridge @ 2007-08-02 20:15 UTC (permalink / raw)
  To: gcc-patches

Rask Ingemann Lambertsen writes:
> Used for what exactly?

Never mind.  You've convinced me that you don't see your port as anything
more than a toy.

					Ross Ridge

^ permalink raw reply	[flat|nested] 56+ messages in thread
* Re: New back end ia16: 16-bit Intel x86
@ 2007-08-01 19:25 Ross Ridge
  2007-08-01 22:57 ` Rask Ingemann Lambertsen
  0 siblings, 1 reply; 56+ messages in thread
From: Ross Ridge @ 2007-08-01 19:25 UTC (permalink / raw)
  To: gcc-patches

Ross Ridge wrote:
> I have 16-bit C code, that when compiled with my 16 year-old Borland
> C++ compiler, produces code that uses 32-bit registers and instructions.

Rask Ingemann Lambertsen writes:
>   Why cant the latter group do what the Linux kernel does? That is, use
>i386 gcc and i386 binutils for low-level 16-bit system code targetting an
>i386 or better.

I can't speak for anyone but myself, but I don't use hacks like
".code16gcc" or code everything assembly because I've got a fully
functional 16-bit IA-32 C compiler that I can use instead.  It would be
nice to use GCC entirely in my projects but I'm not going to replace a
working tool with a broken one to do so.

Let me ask you question.  Are you serious about this port?  Is it just a
toy, a fun project to work on, or do you expect to be used for serious
development?  Who do you expect to use the port?  If you're serious
about this port then you shouldn't be asking why people can't the same
hacks the Linux kernel does, but instead if your port couldn't be used
one day with Linux kernel.

On the other hand, if it's ment to be little more than a toy then you
can just ignore everything I've said.  The name "ia16" is still wrong,
but if it's just going to become, at best, a little-used embedded target,
I really don't care what you call it.

					Ross Ridge

^ permalink raw reply	[flat|nested] 56+ messages in thread
[parent not found: <20070801153758.ACBB974253@caffeine.csclub.uwaterloo.ca.suse.lists.egcs-patches>]
* Re: New back end ia16: 16-bit Intel x86
@ 2007-08-01 15:38 Ross Ridge
  2007-08-01 17:59 ` Rask Ingemann Lambertsen
  0 siblings, 1 reply; 56+ messages in thread
From: Ross Ridge @ 2007-08-01 15:38 UTC (permalink / raw)
  To: gcc-patches

Rask Ingemann Lambertsen writes:
>You know, over the years Intel (and for x86-64, AMD) fixed (or worked
>around) many shortcomings of the i8086:
>
>   1) Addressing modes, most notably the lack of sp relative addressing.
>   2) Tight register constraints.
>   3) Registers with no 8-bit move instructions.
>   4) Lack (or prohibitive slowness) of useful instructions.

Except for the first point, your port should take advantage of the
improvements made in those areas.

As I see it, there's two groups of developers who would want to use
your port.  Thoses writing embedded applications targeting the 80186
and those writing low-level 16-bit system code, like boot loaders.
The later group of people are targetting at least i386 processors, and
can often assume more modern processors are being used.  I have 16-bit
C code, that when compiled with my 16 year-old Borland C++ compiler,
produces code that uses 32-bit registers and instructions.  I think
features like this would be a lot more useful today in a 16-bit IA-32
compiler than getting the RTX costs right on a processor like the 80286
that hasn't been made in a couple of decades.

>> Ideally a 16-bit IA-32 port should
>> be merged into the i386 port, just like the x86_64 port.
>
>   Q: How do I know you didn't discuss that with the i386 maintainers?

Like I said, while ideally they should be merged, I can see good reasons
for not doing so.  I'm not really arguing for that, at least not at
this point.

>Now, x87 hardware floating point gives an easy upportunity for sharing
>code between 16-bit and 32-bit modes[1], but with reg-stack.c already split
>out from the i386 back end and 16-bit x87 not having all that many
>instructions to write patterns for, I doubt the saving is worth the amount
>of extra grot that a merge of ia16 and i386 would produce.

Ideally, the 16-bit port should support the entire IA-32 instruction set,
and I don't see that happening if the ports aren't merged.  Maybe it
will be never worth the trouble, but it would make your port a lot more
useful to me.

					Ross Ridge

^ permalink raw reply	[flat|nested] 56+ messages in thread
* Re: New back end ia16: 16-bit Intel x86
@ 2007-07-31 18:06 Ross Ridge
  2007-08-01  0:34 ` Rask Ingemann Lambertsen
  0 siblings, 1 reply; 56+ messages in thread
From: Ross Ridge @ 2007-07-31 18:06 UTC (permalink / raw)
  To: gcc-patches

Michael Matz writes:
> Blaeh, that's all ugly.  I actually think that ia16 is a reasonable name 
>for this ISA, even though Rask just made it up.

I think "ia16" is an ugly backformation and being made up like this
there's a risk of it conflicting with something else in the future.

>It's generating code for the 16 bit mode (which works on all the intel
>CPUs) which for all practical measures is a different CPU architecture
>than the same chip in 32bit or 64bit mode (it just happens to share some
>mnemonics and insn encodings).

That's absurd.  By sharing the same instruction set and registers, for
"all practical measures" it is the same CPU architecture.  There's a
bigger difference between 32-bit and 64-bit mode and GCC doesn't treat the
x86_64 as a different architecture.  Ideally a 16-bit IA-32 port should
be merged into the i386 port, just like the x86_64 port.  Given the
limitations of Rask Ingemann Lambertsen's port I'm not entirely sure
why it wasn't, though I can see some good reasons for keeping it seperate.

					Ross Ridge

^ permalink raw reply	[flat|nested] 56+ messages in thread
* Re: New back end ia16: 16-bit Intel x86
@ 2007-07-31 15:24 Ross Ridge
  2007-07-31 17:44 ` Michael Matz
  0 siblings, 1 reply; 56+ messages in thread
From: Ross Ridge @ 2007-07-31 15:24 UTC (permalink / raw)
  To: gcc-patches

Rask Ingemann Lambertsen writes:
> It is the best I can think of. Probably my preference was for x86-16,
>but that's not possible (see below). With IA-32 and IA-64 being well
>established, I think IA-16 is a good choice because it conveys the
>information that it's Intel's 16-bit architecture.

It's not Intel's 16-bit architecture, that's the problem.  It's Intel's
IA-32 architecture in 16-bit mode.  Your port seems to be limited to
just the 16-bit IA-32 CPUs, but architecturely there's no reason why
the port couldn't use, for example, SSE instructions and registers.
They work in both real mode and 16-bit protected mode.

>>According to Intel, processors like the 8086 and 80286 are part of the IA-32
>> architecture and there is no IA-16.
>
> Interesting idea. There was no IA-32 until the 80386 appeared.

There was no IA-32 until the Itanium and the IA-64 architecture appeared.
The architecture didn't have a consistant formal name until then.

> The "32" in "IA-32" of course refers to the fact that it is a
>32-bit architecture, unlike the previous members of the x86 family.

No, the "32" is there to distingish it from the IA-64 architecture.
When Intel introduced the IA-32 name, processors like the 8086 and 808186
were explictly documented as being part of the architecture.  Like other
CPU architectures it encompasses 16-bit, 32-bit and now 64-bit processors.

>The "i386" name was a mistake and should not be repeated...

Given the lack of a formal name at the time it seems a reasonable enough
choice to me.

> (so "i8086" is out as well).

Well, if your port is going to be strictly limitted to targetting only
16-bit IA-32 processors then "i80x86" would probably be most descriptive
and accurate name for the target.  However, I don't see why it should
be limitted to just 16-bit processors.

>I'm sure that dashes in the back end name will be rejected.
>Consider the s/x86-64/x86_64/h mess.

I did say "something like i386-16" so "i386_16", "ia32rm16" or anything
that indicates that IA-32 processors in 16-bit mode are being targetted.

					Ross Ridge

^ permalink raw reply	[flat|nested] 56+ messages in thread
* Re: New back end ia16: 16-bit Intel x86
@ 2007-07-31  0:50 Ross Ridge
  2007-07-31  8:54 ` Tristan Gingold
  2007-07-31 13:46 ` Rask Ingemann Lambertsen
  0 siblings, 2 replies; 56+ messages in thread
From: Ross Ridge @ 2007-07-31  0:50 UTC (permalink / raw)
  To: gcc-patches

Rask Ingemann Lambertsen writes:
> This is a patch set to add a new back end for 16-bit x86 CPUs. 

Umm... is "ia16" the best name for this target?  According to Intel,
processors like the 8086 and 80286 are part of the IA-32 architecture and
there is no IA-16.  I think a more accurate name would be something like
"i386-16" since the new target is really just a 16-bit variation of what
GCC calls the i386 architecture.

					Ross Ridge

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

end of thread, other threads:[~2007-08-21 18:54 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-06 14:23 New back end ia16: 16-bit Intel x86 Uros Bizjak
2007-08-07  1:29 ` Rask Ingemann Lambertsen
2007-08-07 17:37   ` Daniel Jacobowitz
2007-08-07 20:03   ` Uros Bizjak
2007-08-08 12:21     ` Jan Hubicka
2007-08-08 17:30       ` Mark Mitchell
2007-08-08 23:22         ` Richard Kenner
2007-08-08 18:52       ` Rask Ingemann Lambertsen
2007-08-08 20:24         ` Michael Matz
2007-08-08 20:59         ` H.J. Lu
2007-08-08 22:46           ` DJ Delorie
2007-08-09  9:33         ` Jan Hubicka
2007-08-09 14:01           ` Rask Ingemann Lambertsen
2007-08-09 15:43           ` DJ Delorie
2007-08-08 15:28     ` Rask Ingemann Lambertsen
2007-08-17 22:38       ` H. Peter Anvin
2007-08-18  2:34         ` Rask Ingemann Lambertsen
2007-08-18  5:33           ` H. Peter Anvin
2007-08-18 17:36             ` Rask Ingemann Lambertsen
2007-08-18 17:50               ` H. Peter Anvin
2007-08-18 20:39                 ` Rask Ingemann Lambertsen
2007-08-19  2:11                   ` H. Peter Anvin
2007-08-19 12:25                     ` Rask Ingemann Lambertsen
2007-08-19 20:07                       ` H. Peter Anvin
2007-08-21  8:48                       ` H. Peter Anvin
2007-08-21 14:35                         ` Rask Ingemann Lambertsen
2007-08-21 17:46                           ` H. Peter Anvin
2007-08-21 18:56                             ` Real-mode i386 back end (Was: New back end ia16: 16-bit Intel x86) Rask Ingemann Lambertsen
2007-08-19  7:29                   ` New back end ia16: 16-bit Intel x86 H. Peter Anvin
2007-08-19 10:56                     ` Rask Ingemann Lambertsen
2007-08-19 21:40                       ` H. Peter Anvin
  -- strict thread matches above, loose matches on Subject: below --
2007-08-19 19:58 Ross Ridge
2007-08-19 16:11 Ross Ridge
2007-08-19 17:36 ` Rask Ingemann Lambertsen
2007-08-18 20:46 Ross Ridge
2007-08-19 16:20 ` Rask Ingemann Lambertsen
2007-08-02 20:15 Ross Ridge
2007-08-01 19:25 Ross Ridge
2007-08-01 22:57 ` Rask Ingemann Lambertsen
     [not found] <20070801153758.ACBB974253@caffeine.csclub.uwaterloo.ca.suse.lists.egcs-patches>
2007-08-01 17:44 ` Andi Kleen
2007-08-01 15:38 Ross Ridge
2007-08-01 17:59 ` Rask Ingemann Lambertsen
2007-07-31 18:06 Ross Ridge
2007-08-01  0:34 ` Rask Ingemann Lambertsen
2007-08-01  9:53   ` Richard Kenner
2007-08-01 12:33     ` Rask Ingemann Lambertsen
2007-08-01 12:44       ` Richard Kenner
2007-08-01 13:41         ` Rask Ingemann Lambertsen
2007-08-01 13:52           ` Richard Kenner
2007-08-01 10:38   ` Jan Hubicka
2007-08-01 17:30     ` Rask Ingemann Lambertsen
2007-07-31 15:24 Ross Ridge
2007-07-31 17:44 ` Michael Matz
2007-07-31  0:50 Ross Ridge
2007-07-31  8:54 ` Tristan Gingold
2007-07-31 13:46 ` Rask Ingemann Lambertsen

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).