From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.devel Subject: Re: Immediate pointers Date: Mon, 31 Jan 2011 19:39:33 +0100 Message-ID: <201101311939.33776.stefan.itampe@gmail.com> References: <87ipx6vwly.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1296499120 14119 80.91.229.12 (31 Jan 2011 18:38:40 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 31 Jan 2011 18:38:40 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jan 31 19:38:35 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Pjydw-0006F8-FT for guile-devel@m.gmane.org; Mon, 31 Jan 2011 19:38:34 +0100 Original-Received: from localhost ([127.0.0.1]:43773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pjydt-0004gK-Uw for guile-devel@m.gmane.org; Mon, 31 Jan 2011 13:38:25 -0500 Original-Received: from [140.186.70.92] (port=50991 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pjydh-0004el-7M for guile-devel@gnu.org; Mon, 31 Jan 2011 13:38:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pjydf-00028R-O1 for guile-devel@gnu.org; Mon, 31 Jan 2011 13:38:12 -0500 Original-Received: from mail-fx0-f41.google.com ([209.85.161.41]:64835) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pjydf-00028G-I2 for guile-devel@gnu.org; Mon, 31 Jan 2011 13:38:11 -0500 Original-Received: by fxm12 with SMTP id 12so6853645fxm.0 for ; Mon, 31 Jan 2011 10:38:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:date:user-agent:references :in-reply-to:mime-version:content-type:content-transfer-encoding :message-id; bh=Ow5krVqpCuEjpYpHHw+iP980KRDt+YqtCe+yyuOpVsg=; b=i44Hv+PYz3xjDMjWlup8+2I87THjQ1LgUyPKDHQuuZokGm6+s51WMAhO0sX+zg1vMl syOihoUEvWLCuz9GNpCCV7Nv97eJcVbrL1qL6I9la9EVIuOIKZNAJ318HMw3p5yxoard M7SqRRSNjlE8/Mj3khKZIq9zbEicXIslrZayE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:references:in-reply-to:mime-version :content-type:content-transfer-encoding:message-id; b=nFVYkXE/dyUs4H8l6/ohYhrfdmf7Uyvkb1TXNaSj2Falwrowj2HvUBbQKcMUXo1bCt Lzo2mkaLcG8YnvkmLCG+lVqY6qzu4f+rPPPxUo3na1GFfRa3h75iogJkhR4/mMKVPsXI Vw2VkzTRlhsLg1dWGriCYG67YutuV7NLOa3hs= Original-Received: by 10.223.100.4 with SMTP id w4mr6355389fan.115.1296499089337; Mon, 31 Jan 2011 10:38:09 -0800 (PST) Original-Received: from linux-s4gz.localnet (1-1-1-39a.veo.vs.bostream.se [82.182.254.46]) by mx.google.com with ESMTPS id y3sm7502837fai.14.2011.01.31.10.38.07 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 31 Jan 2011 10:38:08 -0800 (PST) User-Agent: KMail/1.13.5 (Linux/2.6.34.7-0.5-desktop; KDE/4.4.4; x86_64; ; ) In-Reply-To: <87ipx6vwly.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.41 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11447 Archived-At: Hi, I cannot say that I'm in the tag savy bin. But out of the=20 box I remember that I kind of needed this in the guile-unify project.=20 The solution I'm trying there is to look at address ranges when checking=20 for the object type and use that to dispatch to a unify object or to work with a SCM pointer. This is hacky and works well enough to be able=20 to debug errors and test out concepts.=20 It looks like the test for adress range is not the heavy part in=20 this application so it can be tolerated there. What I really would like though is a retake on the tagging mechanism to=20 allow for some innovative modifications of the scheme engine. /Stefan On Sunday, January 30, 2011 11:46:01 pm Ludovic Court=C3=A8s wrote: > Hello! >=20 > While using (system foreign) in a couple of projects I found myself > doing quite a bit of pointer arithmetic in Scheme: >=20 > --8<---------------cut here---------------start------------->8--- > (define (foreign-array->list array-pointer element-count) > (let ((array (pointer->bytevector array-pointer > (* element-count (sizeof '*))))) > (unfold (cut >=3D <> element-count) > (lambda (element) > (let ((start (* element (sizeof '*)))) > (bytevector->pointer array start))) > 1+ > 0))) >=20 > (define (pointer+ array-pointer type index) > (let ((offset (* index (align (sizeof type) (alignof type))))) > (make-pointer (+ (pointer-address array-pointer) offset)))) >=20 > (define (foreign-string-array->list array len) > ;; Return a list of string comprising the LEN strings pointed to by the > ;; elements of ARRAY, a pointer to an array of pointers. > (unfold (cut < <> 0) > (lambda (index) > (let ((ptr (make-pointer (+ (pointer-address array) > (* index (sizeof '*)))))) > (pointer->string (dereference-pointer ptr)))) > 1- > (- len 1))) > --8<---------------cut here---------------end--------------->8--- >=20 > (Examples from > git;a=3Dblob;f=3Dmodules/simgrid.scm>.) >=20 > The problem is that each =E2=80=98make-pointer=E2=80=99 call (and =E2=80= =98dereference-pointer=E2=80=99, > etc.) conses. This can make conversion to/from C quite inefficient. >=20 > In addition, 90% of the C pointers of interest are 8-byte aligned---that= =E2=80=99s > on x86_64-linux-gnu, but it surely holds on most platforms, at least for > pointers returned by =E2=80=98malloc=E2=80=99. >=20 > So, here comes the idea of =E2=80=9Cimmediate pointers=E2=80=9D, which wo= uld fit in a > word. A 3-bit tag is used, as for immediate numbers & co; pointers that > aren=E2=80=99t 8-byte aligned are still stored in an scm_tc7_pointer cell. >=20 > I experimented with it using =E2=80=98scm_tc3_unused=E2=80=99 (=3D=3D 3).= Alas, that can=E2=80=99t > work, because it makes it impossible to use such an object as the =E2=80= =98car=E2=80=99 > of a pair: >=20 > #define SCM_I_CONSP(x) (!SCM_IMP (x) && ((1 & SCM_CELL_TYPE (x)) =3D= =3D 0)) >=20 > I would welcome feedback and help from tag-savvy people. >=20 > Thanks, > Ludo=E2=80=99.