From: Benedikt Meurer <benedikt.meurer@googlemail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Modify macro and caml_initialize function
Date: Sun, 5 Dec 2010 17:49:20 +0100 [thread overview]
Message-ID: <A9487F78-7C88-4C82-A9AA-31838A91236C@googlemail.com> (raw)
In-Reply-To: <20101205171311.ff7cc923.basile@starynkevitch.net>
On Dec 5, 2010, at 17:13 , Basile Starynkevitch wrote:
> On Sun, 5 Dec 2010 17:02:37 +0100
> "CUOQ Pascal" <Pascal.CUOQ@cea.fr> wrote:
>
>> ygrek wrote:
>>
>>> BTW, while we are on this topic, why the following is not in upstream yet?
>>>
>>> http://eigenclass.org/R2/writings/optimizing-caml_modify
>>>
>>> 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?
>>
>> This is very interesting. Thanks for pointing it out.
>
>
> Sorry to be nitpicking, but...
>
> 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.
>
> 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).
>
> I am thinking of something like [UNTESTED CODE]
>
> #define Modify(fp, val) Modify_at(fp, val, __LINE__)
>
> #define Modify_at(fp, val, lin) do{ \
> value in_heap = 0; \
> value _old_ = *(fp); \
> *(fp) = (val); \
> if (caml_gc_phase == Phase_mark) { \
> if (Is_in_heap (fp)) { \
> caml_darken (_old_, NULL); \
> in_heap = 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 >= caml_ref_table.limit){ \
> CAMLassert (caml_ref_table.ptr == caml_ref_table.limit); \
> caml_realloc_ref_table (&caml_ref_table); \
> } \
> *caml_ref_table.ptr++ = (fp); \
> } \
> } \
> }while(0)
Just use a static inline function, maybe with __attribute__((force_inline)) for GCC.
Benedikt
prev parent reply other threads:[~2010-12-05 16:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20101204110006.A6F91BC57@yquem.inria.fr>
2010-12-05 16:02 ` CUOQ Pascal
2010-12-05 16:13 ` [Caml-list] " Basile Starynkevitch
2010-12-05 16:49 ` Benedikt Meurer [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=A9487F78-7C88-4C82-A9AA-31838A91236C@googlemail.com \
--to=benedikt.meurer@googlemail.com \
--cc=caml-list@yquem.inria.fr \
/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