[mercury-users] Human beats compiler?

Michael Day mikeday at yeslogic.com
Sun Jan 4 23:13:53 AEDT 2009


This hand-rolled C predicate appears to work, and is almost as short as 
the original Mercury implementation. Are there any obvious problems?

:- pred filter_neg(list(int), list(int)).
:- mode filter_neg(di, uo) is det.

:- pragma foreign_proc(c,
         filter_neg(Xs::di, Ys::uo),
         [will_not_call_mercury, thread_safe, promise_pure], "
     Ys = Xs;

     while (Xs != 0)
     {
         MR_Integer X = (MR_Integer) MR_hl_field(MR_mktag(1), Xs, 0);
         MR_Word Xs0 = (MR_Word) MR_hl_field(MR_mktag(1), Xs, 1);

         if (X < 0)
         {
             MR_hl_field(MR_mktag(1), Xs, 0) = 0;
         }

         Xs = Xs0;
     }
").

It surprised me that this code was grade independent; at least it seems 
to work fine in asm_fast.gc as well as hlc.gc. Are there any issues that 
could pop up with this kind of code in certain grades?

This seems like a convenient way of squeezing out some more performance 
without having to abandon the standard list type, and that's good.

Cheers,

Michael

-- 
Print XML with Prince!
http://www.princexml.com
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list