unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* are double cells safe to use?
@ 2013-10-29 10:15 Roland Orre
  2013-10-29 10:45 ` Roland Orre
  2013-10-29 17:17 ` Mark H Weaver
  0 siblings, 2 replies; 5+ messages in thread
From: Roland Orre @ 2013-10-29 10:15 UTC (permalink / raw)
  To: guile-user; +Cc: guile-devel

I consider using double cells for efficient implementation of binary trees.

Is this safe? (i.e. no pre-assumptions made somewhere what these are used for)

For prototyping I intended to add
double-cons
set-cbr!
set-ccr!
cbr
ccr

to the scheme level. Is this safe?
They will only contain or refer to SCM data types.

Of course I could add an own datatype, but as double cells contains
exactly what I need and they are used internally I consider them being
the obvious choice.

I wrote to both user and devel as I consider this may be more of a
devel question.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: are double cells safe to use?
  2013-10-29 10:15 are double cells safe to use? Roland Orre
@ 2013-10-29 10:45 ` Roland Orre
  2013-10-29 12:22   ` Ludovic Courtès
  2013-10-29 17:17 ` Mark H Weaver
  1 sibling, 1 reply; 5+ messages in thread
From: Roland Orre @ 2013-10-29 10:45 UTC (permalink / raw)
  To: guile-user; +Cc: guile-devel

Sorry, double cells are even encouraged to use according the manual under
"Allocating cells"  (I had missed that)
and no specific cares as long as they contain only SCM.

On Tue, Oct 29, 2013 at 11:15 AM, Roland Orre <roland.orre@gmail.com> wrote:
> I consider using double cells for efficient implementation of binary trees.
>
> Is this safe? (i.e. no pre-assumptions made somewhere what these are used for)
>
> For prototyping I intended to add
> double-cons
> set-cbr!
> set-ccr!
> cbr
> ccr
>
> to the scheme level. Is this safe?
> They will only contain or refer to SCM data types.
>
> Of course I could add an own datatype, but as double cells contains
> exactly what I need and they are used internally I consider them being
> the obvious choice.
>
> I wrote to both user and devel as I consider this may be more of a
> devel question.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: are double cells safe to use?
  2013-10-29 10:45 ` Roland Orre
@ 2013-10-29 12:22   ` Ludovic Courtès
  0 siblings, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2013-10-29 12:22 UTC (permalink / raw)
  To: guile-user; +Cc: guile-devel

Hi,

Roland Orre <roland.orre@gmail.com> skribis:

> Sorry, double cells are even encouraged to use according the manual under
> "Allocating cells"  (I had missed that)
> and no specific cares as long as they contain only SCM.

Well, that part of the manual is slightly deprecated.  ;-)

I’d recommend using an appropriate data type instead.  If the code you
write is in Scheme, you’d better use records (info "(guile) Record
Overview").

If the code is in C, you’d better use ‘scm_gc_malloc’ and allocate as
much room as needed to hold your C struct.

HTH!

Ludo’.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: are double cells safe to use?
  2013-10-29 10:15 are double cells safe to use? Roland Orre
  2013-10-29 10:45 ` Roland Orre
@ 2013-10-29 17:17 ` Mark H Weaver
  2013-10-29 18:04   ` Roland Orre
  1 sibling, 1 reply; 5+ messages in thread
From: Mark H Weaver @ 2013-10-29 17:17 UTC (permalink / raw)
  To: Roland Orre; +Cc: guile-user, guile-devel

Roland Orre <roland.orre@gmail.com> writes:

> I consider using double cells for efficient implementation of binary trees.
>
> Is this safe? (i.e. no pre-assumptions made somewhere what these are used for)
>
> For prototyping I intended to add
> double-cons
> set-cbr!
> set-ccr!
> cbr
> ccr
>
> to the scheme level. Is this safe?

No, this won't work.  First of all, double cells cannot be used to store
four SCM values, because the first word of a double cell has to contain
the type tag.  Pairs avoid the type tag by the clever hack: the low bit
of every SCM value is 0, so if the first word of a heap object has 0 in
the low bit, that heap object is assumed to be a pair.  But this means
that every other heap object must start with a word whose low bit is 1.

So the best you could do with a double cell would be to store three SCM
objects, which is no better space efficiency than you already get with a
vector of size 3 (in the master branch, which will become Guile 2.2).

Another problem with creating yet another new fundamental data type is
that in order to use it efficiently, we'd need to create more VM
instructions to access it.  That means more opcodes from our limited
8-bit opcode space, and more code in the VM, which is bad because
ideally a VM should be compact for good cache behavior.

I think you should just use records, or maybe vectors, for this.

     Mark



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: are double cells safe to use?
  2013-10-29 17:17 ` Mark H Weaver
@ 2013-10-29 18:04   ` Roland Orre
  0 siblings, 0 replies; 5+ messages in thread
From: Roland Orre @ 2013-10-29 18:04 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-user, guile-devel

Thanks,

> So the best you could do with a double cell would be to store three SCM
> objects, which is no better space efficiency than you already get with a
> vector of size 3 (in the master branch, which will become Guile 2.2).

but with the vector I also have an extra cell (single?) pointing to the vector.
For this kind of things I've earlier always used records (with new smobs)
or vectors, but now I wanted to make it as space efficient as possible.
It'll be a memory based database which will be "static" (re-indexed daily,
Day-Stout-Warren trees) and contain  (in the long run..., billions of records)

I guess the best alternative then is to use smob with e.g. a 4-word
(SCM) vector.
which implies 6 scm_t_bits, but if a 4 word vector is equally space
efficient I may
better go for that.


On Tue, Oct 29, 2013 at 6:17 PM, Mark H Weaver <mhw@netris.org> wrote:
> Roland Orre <roland.orre@gmail.com> writes:
>
>> I consider using double cells for efficient implementation of binary trees.
>>
>> Is this safe? (i.e. no pre-assumptions made somewhere what these are used for)
>>
>> For prototyping I intended to add
>> double-cons
>> set-cbr!
>> set-ccr!
>> cbr
>> ccr
>>
>> to the scheme level. Is this safe?
>
> No, this won't work.  First of all, double cells cannot be used to store
> four SCM values, because the first word of a double cell has to contain
> the type tag.  Pairs avoid the type tag by the clever hack: the low bit
> of every SCM value is 0, so if the first word of a heap object has 0 in
> the low bit, that heap object is assumed to be a pair.  But this means
> that every other heap object must start with a word whose low bit is 1.
>
> So the best you could do with a double cell would be to store three SCM
> objects, which is no better space efficiency than you already get with a
> vector of size 3 (in the master branch, which will become Guile 2.2).
>
> Another problem with creating yet another new fundamental data type is
> that in order to use it efficiently, we'd need to create more VM
> instructions to access it.  That means more opcodes from our limited
> 8-bit opcode space, and more code in the VM, which is bad because
> ideally a VM should be compact for good cache behavior.
>
> I think you should just use records, or maybe vectors, for this.
>
>      Mark



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-10-29 18:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-29 10:15 are double cells safe to use? Roland Orre
2013-10-29 10:45 ` Roland Orre
2013-10-29 12:22   ` Ludovic Courtès
2013-10-29 17:17 ` Mark H Weaver
2013-10-29 18:04   ` Roland Orre

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).