unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
To: lloda <lloda@sarc.name>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: more advanced bytevector => supervectors
Date: Wed, 8 Sep 2021 13:32:53 +0200	[thread overview]
Message-ID: <CAGua6m1R+SeibL2LXwejCqKjDcoiHmSFz5P9LFa73gX0i2Arrw@mail.gmail.com> (raw)
In-Reply-To: <C1E1E682-CAE2-4838-8922-BF5E98E1D303@sarc.name>

[-- Attachment #1: Type: text/plain, Size: 3156 bytes --]

When I made this code work I will start examine the impact of the design. I
suspect that it will, for complex cases
if not compiled be way slower then the compiled part and this is really the
hot path. For one thing, we will create 2 closures that
allocates memory at each iteration if not inlined. The best solutionis that
wingo can design a very fast compiler targeting
this case in the beginning meaning that guile just handle it perfectly even
with potentially 1000:s of cases. Second
posibility is if guiile had a fast compiler that when feeding a lambda to
it, it would optimise it. we could simulate this
by simply pass lists representing code and use compile to compile it, but
my experience is that it's very time consuming
to do this. I can experiment a little here to see the actual timing.

Anyhow the idea with a fast compiler is that it could prepare in¨the first
compiler the setup so that it is really fast to
compile compared to starting from scratch. Here the advice from wingo would
be apprisiated.

A final posibility which is not too bad speedwise is to do the following
inside the loop and create one big dispatch like
that is executed each iteration.

(let ((val (if (= endian 'little)
                   (if float?
                       (if (= m 4) (get-f32 v1 k1 'little) (get-d64 v1 k1
'little))
                        ...))

(if (= endian 'little)
    (if float?
         (if (= m 4) (set-f32 v1 k1 val 'little) (set-d64 v1 k1 val
'little))
              ...))

This is ideally the code should compile to if it can't create all possible
loops

Now I do not like to adjust my code to output this as it makes the
framework less powerfulll and useful as every case
will be a special case. But what about if you could mark a code less
important. what we want is a dispatch like so

(if (= endian 'little) #:level-2 ...)

And in the first pass, if will be handled if endian is known (will reduce
complexity) else it will in the first pass freeze
this one and continue with the whole shebang. the level2 will be the basic
compiler, but where the #:level-2 tag is ignored.
Maybe this is a no issue and the compiler handles this gracefully.

Also The compiler could note that endian nbits single? float? etc etc is
really created outside the loop and prepare the code for
handling all cases. essentialle make sure to compile all nodes and make an
area in the code to modify. then when before the loop
the code can decide which version to use outside the loop (here we can use
padding or a goto in case if the padded area is so large
that a goto saves time. this means that the compiler has 33 cases for the
ref and 33 cases for the set! part in my most general
version which is ok as they each are typically small. So what I would do if
I where the compiler do the following layout pseudo,

(if ... (copy RefStub1 to StubX ...)
(if ... (copy SetStub1 to  StubY ...)
goto loop
StubRef1
...
StubRefN

StubSet1
...
StubSetN
loop:
(let lp (...)
  (let ((val StubX))
     StubY)
   (iwhen... (lp ...)))

this can be quite fast.

Self modifying code rocks!!!

[-- Attachment #2: Type: text/html, Size: 4151 bytes --]

  reply	other threads:[~2021-09-08 11:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02 15:45 more advanced bytevector => supervectors Stefan Israelsson Tampe
2021-09-02 15:54 ` Stefan Israelsson Tampe
2021-09-06  2:10   ` Stefan Israelsson Tampe
2021-09-02 19:11 ` Matt Wette
2021-09-02 19:47   ` tomas
2021-09-08  2:04 ` Stefan Israelsson Tampe
2021-09-08  7:18   ` lloda
2021-09-08 11:32     ` Stefan Israelsson Tampe [this message]
2021-09-11 17:03     ` Stefan Israelsson Tampe
2021-09-11 18:21       ` lloda
2021-09-15  0:12 ` Stefan Israelsson Tampe

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=CAGua6m1R+SeibL2LXwejCqKjDcoiHmSFz5P9LFa73gX0i2Arrw@mail.gmail.com \
    --to=stefan.itampe@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=lloda@sarc.name \
    /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).