From: Rick Hohensee <humbubba@smarty.smart.net>
To: linux-kernel@vger.kernel.org
Subject: Re: Why Plan 9 C compilers don't have asm("")
Date: Mon, 23 Jul 2001 00:39:16 -0400 (EDT) [thread overview]
Message-ID: <200107230439.AAA19725@smarty.smart.net> (raw)
What if Forth only had one stack?
Looking at optimizations and calling conventions, I did some gas/cpp
macros that implement caller-hikes, callee passes. The caller makes the
space for the callee's stack frame, but it's up to the callee to populate
it if necessary. Sometimes it isn't. In assembly the current context can
see the whole stack, and "osimpa" macros not all included here make the
parent frame, the current frame, and the most recently exited child frame
3 sets of named locals. This is in conjunction with x86 RET imm16 , which
does a stack frame drop for free. I got the Ackerman function, a nasty
little recursion excercise, and rather C's home court, about 50% faster
than Gcc 3.0 -O3 -fomit-frame-pointer. The Gcc version does optimize out
the two tail recursions, leaving one non-tail recursion. I beat that with
all 3 tail recursions remaining in my code. i.e. this is the first version
that worked. I stared at this monster for 2 full days looking for where I
had written "increment" instead of "decrement". Now it appears to produce
the correct results.
..........................................................................
#define cell 4
#define cells *4
#define sM 4 (%esp)
#define sN 8 (%esp)
/* some of the parent's locals */
#define pM ((def_hike +2) cells) (%esp)
#define pN ((def_hike +3) cells) (%esp)
#define def(routine,HIKE) \
def_hike = HIKE ; \
.globl routine ; \
routine:
#define fed ret $(def_hike cells)
#define child(callee) child_hike = callee ## _hike
#define hike(by) subl $(by cells) , %esp
#define do(callee) \
hike(def_hike) ;\
call callee
/* Asmacs exerpts as pertains */
#define testsubtract cmpl
#define ifzero jz
#define decrement decl
#define increment incl
#define to ,
#define with ,
#define copy movl
#define A %eax
def(Ack,2)
testsubtract $0 with pM
ifzero alpha
testsubtract $0 with pN
ifzero beta
# return( Ack(M - 1, Ack(M, (N - 1))) );
copy pN to A
decrement A
copy A to sN
copy pM to A
copy A to sM
do(Ack)
copy A to sN
decrement sM
do(Ack)
fed
# return( N + 1 );
alpha: copy pN to A # M=0
increment A
fed
# return( Ack(M - 1, 1) );
beta: copy $1 to sN # N=0
copy pM to A
decrement A
copy A to sM
do(Ack)
fed
#___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___
def(main,2) # known OK
copy $2 to sM
copy $8 to sN
do(Ack)
fed
/* Rick Hohensee 2001 */
/* The Ackerman function in GNU gas with cpp macros for "asmacs"
verbosifications and "osimpa" caller-hikes, callee-passes subroutine
parameter passing
Parts of asmacs, osimpa.cpp and local renamings included in this file for
clarity.
osimpa stuff, with locals names to reflect the C code example and osimpa
callee-passes, i.e. pM instead of Pa, sM instead of a, etc.
The full asmacs is in Janet_Reno and H3sm. osimpa isn't out yet.
*/
....................................................................
I compared this to the C version on Bagley's language shootout
page by hacking that down to use
<snip>
main () {
return Ack(3,8);
}
so it just returns the low byte of the result, as does my code.
C can pick this up after the expressions are parsed. Whereas this models
"stack-array plus accumulator", that's actually less aggravation to
program directly than Forth stack manipulations (well, maybe), so I'll
probably code this on top of shasm without an expression parser. osimpa
stands for "one stack in memory plus accumulator".
Rick Hohensee
www.clienux.com
next reply other threads:[~2001-07-23 4:23 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-23 4:39 Rick Hohensee [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-07-09 3:03 Why Plan 9 C compilers don't have asm("") Rick Hohensee
[not found] <mailman.994629840.17424.linux-kernel2news@redhat.com>
2001-07-09 0:08 ` Pete Zaitcev
2001-07-09 0:28 ` Victor Yodaiken
2001-07-07 6:16 Rick Hohensee
2001-07-06 17:24 Rick Hohensee
2001-07-06 23:54 ` David S. Miller
2001-07-07 0:16 ` H. Peter Anvin
2001-07-07 0:37 ` David S. Miller
2001-07-05 3:26 Rick Hohensee
2001-07-04 10:10 Rick Hohensee
2001-07-04 3:37 Rick Hohensee
2001-07-04 3:36 ` Olivier Galibert
2001-07-04 6:24 ` Cort Dougan
2001-07-04 8:03 ` H. Peter Anvin
2001-07-04 17:22 ` Linus Torvalds
2001-07-06 8:38 ` Cort Dougan
2001-07-06 11:43 ` David S. Miller
2001-07-06 18:44 ` Linus Torvalds
2001-07-06 20:02 ` Cort Dougan
2001-07-08 21:55 ` Victor Yodaiken
2001-07-08 22:28 ` Alan Cox
2001-07-08 22:29 ` David S. Miller
2001-07-09 1:22 ` Johan Kullstam
2001-07-21 22:10 ` Richard Henderson
2001-07-22 3:43 ` Linus Torvalds
2001-07-22 3:59 ` Mike Castle
2001-07-22 6:49 ` Richard Henderson
2001-07-22 7:44 ` Linus Torvalds
2001-07-22 15:53 ` Richard Henderson
2001-07-22 19:08 ` Linus Torvalds
2001-07-04 7:15 ` pazke
2001-07-05 1:02 ` Michael Meissner
2001-07-05 1:54 ` Rick Hohensee
2001-07-05 16:54 ` Michael Meissner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200107230439.AAA19725@smarty.smart.net \
--to=humbubba@smarty.smart.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox