echo "RUNNING SETUP FOR THE PROCESS LOCKS MODULE"

cat >lconftest.il << EOF
void lock_acquire(int * lock);
.inline lock_acquire, 4
 1:
    set 1, %o1
    cas [%o0], %g0, %o1
    tst %o1
    bne 1b
    nop
    membar #LoadLoad | #LoadStore
.end
void lock_release(int * lock);
.inline lock_release, 4
    membar #StoreStore | #LoadStore
    clr [%o0]
.end
EOF
cat >lconftest.c << EOF
int main(int argc, char ** argv)
{
    int lock = 0;
    lock_acquire(&lock);
    lock_release(&lock);
    return 0;
}
EOF
lac_compile="$CC $CFLAGS $CPPFLAGS lconftest.il lconftest.c -o lconftest"
if (eval $lac_compile) 2>lconftest.err ; then
	cat lconftest.err
    echo "SPARC V9 inline spin locks supported...yes"
    echo "SPARC V9 inline spin locks supported...yes" >>config.log
    if test -z "$HAVE_SPARC_INLINE_PROCESS_LOCKS" ; then
        CFLAGS="$CFLAGS ${master_top_srcdir}/src/mpid/common/locks/mpidu_process_locks_sparc_v9.il"
        HAVE_SPARC_INLINE_PROCESS_LOCKS=yes
        export HAVE_SPARC_INLINE_PROCESS_LOCKS
    fi
else
    echo "SPARC V9 inline spin locks supported...no"
    echo "SPARC V9 inline spin locks supported...no" >>config.log
    cat lconftest.il >>config.log
    cat lconftest.c >>config.log
    cat lconftest.err >>config.log
fi
rm -f lconftest*

cat >lconftest.il << EOF
void lock_acquire(int * lock);
.inline lock_acquire, 4
 1:
    ldstub [%o0], %o1
    cmp %o1, %g0
    bne 1b
    nop
.end
void lock_release(int * lock);
.inline lock_release, 4
    stbar
    clrb [%o0]
.end
EOF
cat >lconftest.c << EOF
int main(int argc, char ** argv)
{
    int lock = 0;
    lock_acquire(&lock);
    lock_release(&lock);
    return 0;
}
EOF
lac_compile="$CC $CFLAGS $CPPFLAGS lconftest.il lconftest.c -o lconftest"
if (eval $lac_compile) 2>lconftest.err ; then
	cat lconftest.err
    echo "SPARC V8 inline spin locks supported...yes"
    echo "SPARC V8 inline spin locks supported...yes" >>config.log
    # FIXME: DO NOT SET CFLAGS UNCONDITIONALLY LIKE THIS
    # (autoconf can fail if CFLAGS is changed; this should also 
    # only be applied where it is needed; this can cause this
    # inline to be added to mpicc et al, which is definately *not* what
    # you want to do)
    if test -z "$HAVE_SPARC_INLINE_PROCESS_LOCKS" ; then
        CFLAGS="$CFLAGS ${master_top_srcdir}/src/mpid/common/locks/mpidu_process_locks_sparc_v8.il"
        HAVE_SPARC_INLINE_PROCESS_LOCKS=yes
        export HAVE_SPARC_INLINE_PROCESS_LOCKS
    fi
else
    echo "SPARC V8 inline spin locks supported...no"
    echo "SPARC V8 inline spin locks supported...no" >>config.log
    cat lconftest.il >>config.log
    cat lconftest.c >>config.log
    cat lconftest.err >>config.log
fi
rm -f lconftest*
