From: Jan Schukat <shookie@email.de>
To: 14599@debbugs.gnu.org
Subject: bug#14599: An option to make vector allocation aligned
Date: Wed, 12 Jun 2013 15:37:28 +0200 [thread overview]
Message-ID: <51B87998.9060402@email.de> (raw)
Hello,
If you want to access native uniform vectors from c, sometimes you
really want guarantees about the alignment.
Fortunately the the (byte)vector format and allocation makes that pretty
easy to implement: just add a little padding between the header and the
actual data.
So for my own project, this is what I'm doing, and there shouldn't be
much of a memory impact unless there are tons of small vectors used,
which isn't very lispy anyway.
This isn't necessarily true for vectors created from pre-existing
buffers (the take_*vector functions), but there you have control over
the pointer you pass, so you can make it true if needed.
So if there is interest, maybe this could be integrated into the build
system as a configuration like this:
--- libguile/bytevectors.c 2013-04-11 02:16:30.000000000 +0200
+++ bytevectors.c 2013-06-12 14:45:16.000000000 +0200
@@ -223,10 +223,18 @@
c_len = len * (scm_i_array_element_type_sizes[element_type] / 8);
+#ifdef SCM_VECTOR_ALIGN
+ contents = scm_gc_malloc_pointerless (SCM_BYTEVECTOR_HEADER_BYTES
+ c_len + SCM_VECTOR_ALIGN,
+ SCM_GC_BYTEVECTOR);
+ ret = PTR2SCM (contents);
+ contents += SCM_BYTEVECTOR_HEADER_BYTES;
+ contents += (addr + (SCM_VECTOR_ALIGN - 1)) & -SCM_VECTOR_ALIGN;
+#else
contents = scm_gc_malloc_pointerless
(SCM_BYTEVECTOR_HEADER_BYTES + c_len,
SCM_GC_BYTEVECTOR);
ret = PTR2SCM (contents);
contents += SCM_BYTEVECTOR_HEADER_BYTES;
+#endif
SCM_BYTEVECTOR_SET_LENGTH (ret, c_len);
SCM_BYTEVECTOR_SET_CONTENTS (ret, contents);
It could even be possible to make the alignment a run-time decision, but
for that the api and read syntax for vectors need to be extended. Which
could be worthwhile ...
Apart from that, I see there are issues with the native mingw builds
again, which I haven't noticed earlier since I primarily develop on
linux, but I can reproduce the problem shown in #14361.
Regards
Jan Schukat
next reply other threads:[~2013-06-12 13:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-12 13:37 Jan Schukat [this message]
2013-06-12 14:59 ` bug#14599: An option to make vector allocation aligned Ludovic Courtès
2013-06-12 15:32 ` Jan Schukat
2013-06-12 21:14 ` Jan Schukat
2013-06-13 13:31 ` Ludovic Courtès
2013-06-14 1:33 ` Daniel Hartwig
2013-06-14 8:32 ` Jan Schukat
2013-06-14 12:21 ` Ludovic Courtès
2013-06-17 10:04 ` Jan Schukat
2013-06-12 20:37 ` Andy Wingo
2013-06-13 7:07 ` Jan Schukat
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=51B87998.9060402@email.de \
--to=shookie@email.de \
--cc=14599@debbugs.gnu.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).