From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jan Schukat Newsgroups: gmane.lisp.guile.bugs Subject: bug#14599: An option to make vector allocation aligned Date: Wed, 12 Jun 2013 15:37:28 +0200 Message-ID: <51B87998.9060402@email.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1371044295 9544 80.91.229.3 (12 Jun 2013 13:38:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 12 Jun 2013 13:38:15 +0000 (UTC) To: 14599@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Jun 12 15:38:14 2013 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UmlFc-0002v8-Sy for guile-bugs@m.gmane.org; Wed, 12 Jun 2013 15:38:13 +0200 Original-Received: from localhost ([::1]:51782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmlFc-0004Kl-Hq for guile-bugs@m.gmane.org; Wed, 12 Jun 2013 09:38:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmlFW-0004KR-LU for bug-guile@gnu.org; Wed, 12 Jun 2013 09:38:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UmlFT-0001Ox-JF for bug-guile@gnu.org; Wed, 12 Jun 2013 09:38:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54222) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmlFT-0001Oo-FW for bug-guile@gnu.org; Wed, 12 Jun 2013 09:38:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1UmlFS-000528-SY for bug-guile@gnu.org; Wed, 12 Jun 2013 09:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jan Schukat Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 12 Jun 2013 13:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 14599 X-GNU-PR-Package: guile X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.137104428119342 (code B ref -1); Wed, 12 Jun 2013 13:38:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Jun 2013 13:38:01 +0000 Original-Received: from localhost ([127.0.0.1]:58457 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UmlFR-00051r-CL for submit@debbugs.gnu.org; Wed, 12 Jun 2013 09:38:01 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:41785) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UmlFP-00051e-AM for submit@debbugs.gnu.org; Wed, 12 Jun 2013 09:37:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UmlFC-0001KZ-Ew for submit@debbugs.gnu.org; Wed, 12 Jun 2013 09:37:53 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:51099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmlFC-0001KV-B3 for submit@debbugs.gnu.org; Wed, 12 Jun 2013 09:37:46 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmlF5-0004JS-Nt for bug-guile@gnu.org; Wed, 12 Jun 2013 09:37:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UmlEz-0001GO-9z for bug-guile@gnu.org; Wed, 12 Jun 2013 09:37:39 -0400 Original-Received: from mout.web.de ([212.227.17.11]:58857) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmlEy-0001FN-Ve for bug-guile@gnu.org; Wed, 12 Jun 2013 09:37:33 -0400 Original-Received: from [192.168.0.27] ([92.231.241.64]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0M9XbT-1UdeIn2j6N-00CzTq for ; Wed, 12 Jun 2013 15:37:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 X-Provags-ID: V03:K0:+vlz2YM+i8/Gr0HN+FFArYbOdMDW20D/WO6SF50MBKkteFhujci bRV/XcHMhM3iDZgPIQNmFDSmdOhw4EgCKUGLfppOJXsj41OQuvr7vOJQ4Tzda4LGe0bKZvi BefO0sAHVbohNM9YMw7n1sdmwhb9oPvroHpi9cqneNQ0ozlve9akULn+5weAWSe9YeIW4a+ Lkr81WTak+zJcamuSvGeA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7167 Archived-At: 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