From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 20041BBAF for ; Sun, 5 Dec 2010 17:49:25 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtcBACJR+0zRVdY0gWdsb2JhbACVHI4MCBUBAQsJCgcTBB6jQowCAQWNCgEEhUmQCw X-IronPort-AV: E=Sophos;i="4.59,302,1288566000"; d="scan'208";a="69912375" Received: from mail-bw0-f52.google.com ([209.85.214.52]) by mail3-smtp-sop.national.inria.fr with ESMTP; 05 Dec 2010 17:49:24 +0100 Received: by bwz4 with SMTP id 4so9749232bwz.39 for ; Sun, 05 Dec 2010 08:49:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:content-type:mime-version :subject:from:in-reply-to:date:content-transfer-encoding:message-id :references:to:x-mailer; bh=fpP7yH0NXmrPw6UtAe3UsqPtfKI0ZBjuCJc+6tyyf+c=; b=OI4b7up1DdBKiUkzbiT3KGuZmf2mLml6jrvzeozjpJeZQGVOhFqZ8Ljg69kWyEHpNs ovdHzJrIcsgiRbl5KHei7V/lWpwlVp+gMigSwdjhqoi6sZ7+VTKxL4DNPQ8xrzBX9Pc1 4WJKgXdh5XDgo978deq2eHIT9tLJW+MBY42FA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; b=kV5oLljkLdB6blvpI6vZW/aZRGWOtTO26/EfAucLqbJOVNhJBT7CtIKTQSoU6vQFKO IvIeHEiyB+nNmENpjfBbB0jf+eN6tcrawhGyqnDj+hj1wKzCqpO+YSL0gSPoOxTQnpDH o3Z5ezx01whRXd2tSw8YKMRhb4cVW13qVWLBs= Received: by 10.204.72.130 with SMTP id m2mr2762955bkj.4.1291567762819; Sun, 05 Dec 2010 08:49:22 -0800 (PST) Received: from bespin.kosmos.all (ip-95-223-170-32.unitymediagroup.de [95.223.170.32]) by mx.google.com with ESMTPS id q15sm1517857bkk.13.2010.12.05.08.49.21 (version=SSLv3 cipher=RC4-MD5); Sun, 05 Dec 2010 08:49:22 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1081) Subject: Re: [Caml-list] Modify macro and caml_initialize function From: Benedikt Meurer In-Reply-To: <20101205171311.ff7cc923.basile@starynkevitch.net> Date: Sun, 5 Dec 2010 17:49:20 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20101204110006.A6F91BC57@yquem.inria.fr> <5EFD4D7AC6265F4D9D3A849CEA92191902182AD6@LAXA.intra.cea.fr> <20101205171311.ff7cc923.basile@starynkevitch.net> To: caml-list@yquem.inria.fr X-Mailer: Apple Mail (2.1081) X-Spam: no; 0.00; basile:01 cuoq:01 cuoq:01 iirc:01 gcc:01 gcc:01 val:01 val:01 wrote:01 wrote:01 compilers:01 inline:01 inline:01 heap:01 heap:01 On Dec 5, 2010, at 17:13 , Basile Starynkevitch wrote: > On Sun, 5 Dec 2010 17:02:37 +0100 > "CUOQ Pascal" wrote: >=20 >> ygrek wrote: >>=20 >>> BTW, while we are on this topic, why the following is not in = upstream yet? >>>=20 >>> http://eigenclass.org/R2/writings/optimizing-caml_modify >>>=20 >>> Looks like a clear win-win without drawbacks (increased code size = shouldn't be significant >>> cause Modify is only used in a couple of places). What do you think? >>=20 >> This is very interesting. Thanks for pointing it out. >=20 >=20 > Sorry to be nitpicking, but... >=20 > IIRC, there might be some rare occasions where the Modify macro could > be called several times in a C routine. And then you've got several > caml_modify_maybe_add_to_ref_table labels in the same C routine. >=20 > With GCC, you could use a local __label__ > http://gcc.gnu.org/onlinedocs/gcc/Local-Labels.html but if you want to > be portable to non GCC compilers, you'll need a Modify macro which > generates a unique label (perhaps using __LINE__ for that purpose). >=20 > I am thinking of something like [UNTESTED CODE] >=20 > #define Modify(fp, val) Modify_at(fp, val, __LINE__) >=20 > #define Modify_at(fp, val, lin) do{ = \ > value in_heap =3D 0; = \ > value _old_ =3D *(fp); = \ > *(fp) =3D (val); = \ > if (caml_gc_phase =3D=3D Phase_mark) { = \ > if (Is_in_heap (fp)) { = \ > caml_darken (_old_, NULL); = \ > in_heap =3D 1; = \ > goto caml_modify_maybe_add_to_ref_table##Lin; = \ > } = \ > } else { = \ > caml_modify_maybe_add_to_ref_table##Lin: = \ > if (Is_block (val) && Is_young (val) = \ > && ! (Is_block (_old_) && Is_young (_old_)) && = \ > (in_heap || Is_in_heap (fp)) ){ = \ > if (caml_ref_table.ptr >=3D caml_ref_table.limit){ = \ > CAMLassert (caml_ref_table.ptr =3D=3D caml_ref_table.limit); = \ > caml_realloc_ref_table (&caml_ref_table); = \ > } = \ > *caml_ref_table.ptr++ =3D (fp); = \ > } = \ > } = \ > }while(0) Just use a static inline function, maybe with = __attribute__((force_inline)) for GCC. Benedikt=