[mercury-users] User-defined Extension of builtin__copy?

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Sep 21 01:53:04 AEST 2005


On 19-Sep-2005, Kral Stefan <skral at mips.complang.tuwien.ac.at> wrote:
> Thank you for taking the time to help me with my little
> Mercury-GMP bindings project!

You are welcome.

> But, now that you ask;-) Forcing the creation of unique copies can
> be helpful for micro-benchmarks, evaluating the performance of the
> library. The GMP library is smarter than we (thought), eg. it 
> detects that X*X can be done by using a specialized, faster 
> algorithm for calculating squares. To turn that optimization off, 
> we can force the creation of a unique copy.

How does that help? Does GMP decide whether two operands are the same
by comparing their addresses?

> Apparently, the boxing/unboxing checks looks something like
> 	if (sizeof(GMPInt *) <= sizeof(MR_Word)) { ... }
> 
> Any reasonable C compilers should be able to optimize that check away.

Yes, of course. However, in one arm of the switch, there is a call to
memcpy (buried under several layers of macros). If the size is such
that you get the arm without the memcpy, there should be no performance
impact, as you found. There should also be no impact if the C compiler
specializes the memcpy with the constant size argument, but as of about
three/four years ago, it didn't do that.

> The library reuses memory wherever possible, but only in
> a clean way, using unique modes. Apart from that, everything
> is clear and simple, using the conservative GC interface.
> 
> In retrospect, I think that this qualifies the type as stable.

You aren't allowed to table predicates that have unique arguments
(the table's references to the arguments would destroy their uniqueness).
If I understand you correctly, you won't ever reuse the memory of
a nonunique gmpint, so I agree, gmpints can be said to be stable.

> I am confident that gmpint is getting more and more mature.
> (We are working on gmpfloat and gmprational libraries, too.)
> Our integer GMP-bindings will be ready for release in just about 2 weeks.

That's nice to hear.

Zoltan Somogyi <zs at cs.mu.OZ.AU> http://www.cs.mu.oz.au/~zs/
Department of Computer Science and Software Engineering, Univ. of Melbourne
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list