From: David Thompson <dthompson2@worcester.edu>
To: guile-devel@gnu.org
Cc: wingo@pobox.com
Subject: Attempting to unbox struct fields
Date: Sun, 28 Feb 2016 10:03:48 -0500 [thread overview]
Message-ID: <8737scubaj.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> (raw)
Hello wingo and list,
A couple days ago on #guile, I started a conversation about optimizing
some record types I use for linear algebra to take advantage of unboxed
arithmetic in the upcoming Guile 2.2. Andy informed me of a temporary
hack I could try, but then said that The Right Thing is for Guile to
unbox struct fields. So, I thought since Andy wrote such a nice post on
his blog about about Guile compiler tasks [0] that maybe I would give it
a try! I have gone about as far as I can on my own (not far), and seek
the guiding light of the Guile maintainers to help unblock me.
The task is as follows, quoting from the above mentioned blog post:
Guile's "structs", on which records are implemented, support unboxed
values, but these values are untyped, not really integrated with the
record layer, and always boxed in the VM. Your task would be to
design a language facility that allows us to declare records with
typed fields, and to store unboxed values in those fields, and to
cause access to their values to emit boxing/unboxing instructions
around them. The optimizer will get rid of those boxing/unboxing
instructions if it can. Good luck!
I took an exploratory romp around the codebase and here's what I've
learned:
- Guile indeed supports unboxed fields in the struct implementation.
Currently it only supports unboxed unsigned integers, but there's some
preprocessor magic that can be removed to enable unboxed signed
integers and doubles:
switch (field_type)
{
case 'u':
data[p] = SCM_NUM2ULONG (3, val);
break;
#if 0
case 'i':
data[p] = SCM_NUM2LONG (3, val);
break;
case 'd':
*((double *)&(data[p])) = scm_num2dbl (val, (char *)SCM_ARG3);
break;
#endif
...
- It's easy enough to create a vtable with unboxed fields:
(define vtable (make-vtable "uwuw"))
(define s (make-struct vtable 123 456))
(struct-ref s 0) ;; => 123
- struct-ref/immediate and struct-set!/immediate are the VM operations
for reading from/writing to structs
- Roughly speaking, in the case of unboxed unsigned integers, one would
want to insert a scm->u64 instruction before setting the value of an
unboxed field, and one would want to insert a u64->scm instructor
after getting the value of an unboxed field.
- In TreeIL, struct refs and sets are primcalls, and when compiling to
CPS they receive some special treatment to unbox the index component
of the respective operations. This might be the procedure that will
insert the boxing/unboxing instructions for the struct fields, but I'm
not sure.
Now that I've learned a little bit, I have a bunch of questions that I
cannot yet answer:
- Is it possible to know the layout of a vtable at compile time?
- If so, where is that information stored?
- If not, does this mean that TreeIL needs to be changed to be able to
store typed struct field data in order to generate the correct CPS?
- Can the TreeIL format even be reasonably changed since its a public
interface that people target when writing their own language
implementations?
Basically, how could I possibly get my hands on the vtable information
at compile time?
Help would be very much appreciated!
Thanks,
--
David Thompson
GPG Key: 0FF1D807
[0] http://wingolog.org/archives/2016/02/04/guile-compiler-tasks
next reply other threads:[~2016-02-28 15:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-28 15:03 David Thompson [this message]
2016-02-28 21:30 ` Attempting to unbox struct fields Thompson, David
2016-02-29 3:56 ` Mark H Weaver
2016-02-29 14:26 ` Thompson, David
2016-02-29 17:43 ` Mark H Weaver
2016-02-29 21:09 ` Thompson, David
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
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8737scubaj.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me \
--to=dthompson2@worcester.edu \
--cc=guile-devel@gnu.org \
--cc=wingo@pobox.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).