Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

If Bill Gates is the Devil then Linus Torvalds must be the Messiah. -- Unknown source


devel / comp.compilers / 8086 register allocation

SubjectAuthor
* 8086 register allocationAlexei A. Frounze
+- Re: 8086 register allocationFernando
`* Re: 8086 register allocationgah4
 +* Re: 8086 register allocationHans-Peter Diettrich
 |+- Re: 8086 register allocationgah4
 |`- Re: 8086 register allocationHans-Peter Diettrich
 `- Re: 8086 register allocationThomas Koenig

1
8086 register allocation

<21-05-005@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=39&group=comp.compilers#39

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: alexfrun...@gmail.com (Alexei A. Frounze)
Newsgroups: comp.compilers
Subject: 8086 register allocation
Date: Sun, 9 May 2021 14:28:39 -0700 (PDT)
Organization: Compilers Central
Lines: 28
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <21-05-005@comp.compilers>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="18654"; mail-complaints-to="abuse@iecc.com"
Keywords: code, architecture
Posted-Date: 09 May 2021 20:04:16 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Alexei A. Frounze - Sun, 9 May 2021 21:28 UTC

For the fun of it I've implemented a greedy bottom-up local register
allocator for the intel 8086 CPU, which is known for its non-uniform
use of registers in ALU instructions and memory operands
(https://github.com/alexfru/regal86).

The motivation for it is that I haven't seen any such register
allocator in e.g. the "Dragon" book and may other texts on compilers
I've read or skimmed. And even today I can't quite come up with a
proper web search request that would return info on such allocators.
I've found one paper that very briefly talks about an allocator like
this for the IBM 370. This gives a sense that this stuff is very
yesterday in terms of both CPU architectures and modern compiler
algorithms since many seem to delegate this particular aspect of
register allocation to graph (pre)coloring and modern CPUs are more
uniform in terms of register use (or there are simply more registers
to use).

Are there any other texts that introduce and explain such register
allocators? Compiler Construction by William M. Waite and Gerhard Goos
(section 10.2.2 "Targeting") is a bit too short on the matter. But
people somehow have done things like this in the past.

Thanks,
Alex
[I don't recall anything in a textbook about it. x86 register
allocators were pretty ad-hoc due to all of the special cases
where an operand had to be in a specific register. -John]

Re: 8086 register allocation

<21-05-006@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=40&group=comp.compilers#40

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!xmission!usenet.csail.mit.edu!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: prone...@gmail.com (Fernando)
Newsgroups: comp.compilers
Subject: Re: 8086 register allocation
Date: Mon, 10 May 2021 04:46:31 -0700 (PDT)
Organization: Compilers Central
Lines: 21
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <21-05-006@comp.compilers>
References: <21-05-005@comp.compilers>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="14625"; mail-complaints-to="abuse@iecc.com"
Keywords: architecture, optimize
Posted-Date: 10 May 2021 11:05:30 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <21-05-005@comp.compilers>
 by: Fernando - Mon, 10 May 2021 11:46 UTC

Hi Alex,

I read part of your code. Very nice! The core algorithm (disregarding the x86 specific part) seems like 'local register allocation' using Belady's heuristic for spilling. I have a class about it here:

https://youtu.be/XmNXeNCGSIA

There has been some academic work about models for register allocation for x86. Two papers follow below:

* Register Allocation by Puzzle Solving, https://llvm.org/pubs/2008-06-PLDI-PuzzleSolving.pdf

* A generalized algorithm for graph-coloring register allocation, http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.10.3076&rep=rep1&type=pdf

Regards,

Fernando

> For the fun of it I've implemented a greedy bottom-up local register
> allocator for the intel 8086 CPU, which is known for its non-uniform
> use of registers in ALU instructions and memory operands
> (https://github.com/alexfru/regal86).

Re: 8086 register allocation

<21-05-007@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=41&group=comp.compilers#41

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gah...@u.washington.edu (gah4)
Newsgroups: comp.compilers
Subject: Re: 8086 register allocation
Date: Mon, 10 May 2021 14:49:27 -0700 (PDT)
Organization: Compilers Central
Lines: 25
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <21-05-007@comp.compilers>
References: <21-05-005@comp.compilers>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="32173"; mail-complaints-to="abuse@iecc.com"
Keywords: code, registers
Posted-Date: 10 May 2021 18:12:50 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <21-05-005@comp.compilers>
 by: gah4 - Mon, 10 May 2021 21:49 UTC

On Sunday, May 9, 2021 at 5:04:18 PM UTC-7, alexf...@gmail.com wrote:
> For the fun of it I've implemented a greedy bottom-up local register
> allocator for the intel 8086 CPU, which is known for its non-uniform
> use of registers in ALU instructions and memory operands
> (https://github.com/alexfru/regal86).

Reminds me of what, as far as I know, is also an unsolved problem:
register allocation for the x87.

First the 8087 was designed not knowing if it should be a stack or
register machine, so stack registers are addressable. (Even though
the addresses keep changing.)

It was also designed to have a virtual stack, which would spill to memory
on overflow, and back on underflow. That sounds nice, but it seems that
no-one tried to write the interrupt routine before the hardware was built,
and that it actually isn't possible. It seems that it isn't possible to get some
of the state bits set, such that it all works like a seamless virtual stack.

The 80287 is the same processing logic with a different bus interface
(and separate clock). As well as I know, things were redesigned later,
but it seems that there still is no virtual stack.

There are description of some compilers that give up on compiling any
code that needs more than eight registers.

Re: 8086 register allocation

<21-05-008@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=42&group=comp.compilers#42

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!usenet.csail.mit.edu!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: DrDiettr...@netscape.net (Hans-Peter Diettrich)
Newsgroups: comp.compilers
Subject: Re: 8086 register allocation
Date: Tue, 11 May 2021 03:35:11 +0200
Organization: Compilers Central
Lines: 20
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <21-05-008@comp.compilers>
References: <21-05-005@comp.compilers> <21-05-007@comp.compilers>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="73561"; mail-complaints-to="abuse@iecc.com"
Keywords: arithmetic, architecture, comment
Posted-Date: 10 May 2021 22:42:28 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <21-05-007@comp.compilers>
Content-Language: de-DE
 by: Hans-Peter Diettrich - Tue, 11 May 2021 01:35 UTC

On 5/10/21 11:49 PM, gah4 wrote:

> It was also designed to have a virtual stack, which would spill to memory
> on overflow, and back on underflow. That sounds nice, but it seems that
> no-one tried to write the interrupt routine before the hardware was built,
> and that it actually isn't possible. It seems that it isn't possible to get some
> of the state bits set, such that it all works like a seamless virtual stack.

How efficient is a virtual stack? Did anybody try to use ordinary
(integral...) registers with interrupt driven spilling?

A stack machine is convenient for calculations. Before the stack
overflows the compiler can save intermediate results, as with any other
architecture of limited register count.

DoDi
[Normal stack machines have the top few entries in registers and do the
spilling to memory in hardware. The x87 stack has 8 registers, which is
a lot for a stack machine, but the spilling was broken. You can address
into the stack but you can't really use it as a register machine. -John]

Re: 8086 register allocation

<21-05-009@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=43&group=comp.compilers#43

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gah...@u.washington.edu (gah4)
Newsgroups: comp.compilers
Subject: Re: 8086 register allocation
Date: Mon, 10 May 2021 21:19:27 -0700 (PDT)
Organization: Compilers Central
Lines: 15
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <21-05-009@comp.compilers>
References: <21-05-005@comp.compilers> <21-05-007@comp.compilers> <21-05-008@comp.compilers>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="7709"; mail-complaints-to="abuse@iecc.com"
Keywords: architecture, history
Posted-Date: 12 May 2021 23:55:52 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <21-05-008@comp.compilers>
 by: gah4 - Tue, 11 May 2021 04:19 UTC

(Snip on x87 register allocation)

> [Normal stack machines have the top few entries in registers and do the
> spilling to memory in hardware. The x87 stack has 8 registers, which is
> a lot for a stack machine, but the spilling was broken. You can address
> into the stack but you can't really use it as a register machine. -John]

It was some years ago, but I read the story about the gcc code generator,
which is designed for register machines. So, they don't quite treat it
as a register machine, but not a stack machine, either.

At any point in the code, there should be a known (constant) number
of items on the stack, so you can address the registers using that number.
I think that is what Intel expected, when they wrote that you can use
it as a register machine. It would be less fun in assembly, though.

Re: 8086 register allocation

<21-05-010@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=44&group=comp.compilers#44

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!usenet.csail.mit.edu!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.compilers
Subject: Re: 8086 register allocation
Date: Tue, 11 May 2021 06:44:07 -0000 (UTC)
Organization: news.netcologne.de
Lines: 11
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <21-05-010@comp.compilers>
References: <21-05-005@comp.compilers> <21-05-007@comp.compilers>
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="8040"; mail-complaints-to="abuse@iecc.com"
Keywords: architecture, history
Posted-Date: 12 May 2021 23:56:18 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Thomas Koenig - Tue, 11 May 2021 06:44 UTC

gah4 <gah4@u.washington.edu> schrieb:

[80x87]

> There are description of some compilers that give up on compiling any
> code that needs more than eight registers.

Even worse. If I remember correctly, Turbo Pascal 3 simply
generated wrong code if the number of stack slots was exceeded.
The user just had to make sure that the formulas were not too
complex.

Re: 8086 register allocation

<21-05-011@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=45&group=comp.compilers#45

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!usenet.csail.mit.edu!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: DrDiettr...@netscape.net (Hans-Peter Diettrich)
Newsgroups: comp.compilers
Subject: Re: 8086 register allocation
Date: Tue, 11 May 2021 09:35:17 +0200
Organization: Compilers Central
Lines: 22
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <21-05-011@comp.compilers>
References: <21-05-005@comp.compilers> <21-05-007@comp.compilers> <21-05-008@comp.compilers>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="8380"; mail-complaints-to="abuse@iecc.com"
Keywords: code, history
Posted-Date: 12 May 2021 23:56:46 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <21-05-008@comp.compilers>
Content-Language: de-DE
 by: Hans-Peter Diettrich - Tue, 11 May 2021 07:35 UTC

On 5/11/21 3:35 AM, Hans-Peter Diettrich wrote:

> A stack machine is convenient for calculations. Before the stack
> overflows the compiler can save intermediate results, as with any other
> architecture of limited register count.
>
> DoDi
> [Normal stack machines have the top few entries in registers and do the
> spilling to memory in hardware.  The x87 stack has 8 registers, which is
> a lot for a stack machine, but the spilling was broken.   You can address
> into the stack but you can't really use it as a register machine. -John]

FORTH coders know how inconvenient for humans is accessing "local
variables" in such a stack. But a compiler can track the content of the
stack.

I had some problems in understanding "spilling". After re-reading the
80287 instruction set I found that only ST(0) is usable for memory
load/store operations, making it hard to code load/store the other end
of the register stack. Thanks, John, for the kick... ;-)

DoDi

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor