Git Product home page Git Product logo

Comments (5)

tibbe avatar tibbe commented on July 28, 2024

I think this

stg_fetchAddByteArrayIntzh
/* MutableByteArray# s -> Int# -> Int# -> State# s -> (# State# s, Int# #) */
{
    W_ arr, p, ind, incr, h, len;
    arr  = R1; 
    ind  = R2;
    incr = R3;

    p = arr + SIZEOF_StgArrWords + WDS(ind);
    (h) = foreign "C" atomic_inc_with(incr, p) [];

    RET_N(h);
}

could be replaced by

foreign import ccall unsafe "atomic_inc_with" fetchAddByteArrayInt
    :: MutableByteArray# s -> Int -> Int -> IO Int

except I'm not quite sure about the s parameter to MBA#.

Relevant docs: https://www.haskell.org/ghc/docs/7.6.3/html/users_guide/ffi.html#idp56267600

from haskell-lockfree.

tibbe avatar tibbe commented on July 28, 2024

Figured it out: you also need to give the UnliftedFFITypes language pragma to be allowed to mention MBA# in the FFI import.

from haskell-lockfree.

rrnewton avatar rrnewton commented on July 28, 2024

How do you picture this working for CAS? It's a funky case because it currently returns a pair from the CMM primop:

stg_casMutVarzh ( gcptr mv, gcptr old, gcptr new )
{
    gcptr h;
    (h) = ccall cas(mv + SIZEOF_StgHeader + OFFSET_StgMutVar_var,
                          old, new);
    if (h != old) {
        return (1,h);
    } else {
        if (GET_INFO(mv) == stg_MUT_VAR_CLEAN_info) {
           ccall dirty_MUT_VAR(BaseReg "ptr", mv "ptr");
        }
        return (0,new);
    }

Assuming it is possible to do the GET_INFO/dirty bits in C, then there's just the issue of returning the two values efficiently. Could pass an output param for one and poke the pointer...

from haskell-lockfree.

tibbe avatar tibbe commented on July 28, 2024

Poking a pointer sounds like the way to go.

On Sun, Apr 13, 2014 at 3:57 AM, Ryan Newton [email protected]:

How do you picture this working for CAS? It's a funky case because it
currently returns a pair from the CMM primop:

stg_casMutVarzh ( gcptr mv, gcptr old, gcptr new ){
gcptr h;
(h) = ccall cas(mv + SIZEOF_StgHeader + OFFSET_StgMutVar_var,
old, new);
if (h != old) {
return (1,h);
} else {
if (GET_INFO(mv) == stg_MUT_VAR_CLEAN_info) {
ccall dirty_MUT_VAR(BaseReg "ptr", mv "ptr");
}
return (0,new);
}

Assuming it is possible to do the GET_INFO/dirty bits in C, then there's
just the issue of returning the two values efficiently. Could pass an
output param for one and poke the pointer...

Reply to this email directly or view it on GitHubhttps://github.com//issues/27#issuecomment-40298247
.

from haskell-lockfree.

rrnewton avatar rrnewton commented on July 28, 2024

Yeah, it's a write to memory rather than returning in registers but worth it to turn the double function call into a single one.

from haskell-lockfree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.