Clueing For Looks

Written by Hunter Jansen on November 03, 2014

So, today’s post is going to mainly be a bit of a journal for what I find in my initial look through of JSL and Snort to see what needs updating. I don’t anticipate this post being too too large, but more as a reference for me for later as much as anything.

I’ll start off looking through both for any mention of ASM in the source as well as seeking out any .s (assembler) extension files to see what’s in there as well. For fun, I’ll probably include the commands that I’ve run to find these and any relevant code bits.

Also, since last time, I’ve finally figured out how to claim JSL as the one I’ll be working on on the Linaro Performance Challenge Site - So I guess it’s official. At least, I think I have - I was hoping to be able to claim both to work on, but it seems I’m only allowed one at at time?

JSL

More info about JSL here.

To start off with, we need to get JSL onto our x86 machine to investigate what the haps is. I’ll use fedpkg to pull it in:

$- fedpkg clone -a jsl
$- cd jsl
$- fedpkg prep

This pulls in jsl, changes to it’s directory and uses fedpkg to prep the rest of the code. So now we’ve got all the source for JSL on our machine.

At the time of writing this, I’m looking at jsl-0.3.0.

So now I’ll look for assembler files (.s files):

find . -name "*.[sS]"

This comes back with a single result:

./jsl-0.3.0/src/lock_SunOS.s

The file name for this is probably a pretty good hint that we might not need to do a port for it, as it looks like it’s just something required for SunOS. A bit more poking around inside the file itself has the following in the comments:

!  atomic compare-and-swap routines for V8 sparc 
!  and for V8+ (ultrasparc)

So it doesn’t look like anything will need to be done with that file to port over to Aarch64.

And finally I’ll look for files with ASM or asm in them:

$- egrep -R "__asm__|asm[[:space:]]*\("

This comes back with two files:

jsl-0.3.0/src/jsutil.c:    asm("int $3");
jsl-0.3.0/src/jslock.c:    __asm__ __volatile__ (

At first glance these look like a locking mechanism and something else.

jsl-0.3.0/src/jslock.c.c

now to look at jsl-0.3.0/src/jslock.c

asm calls can be found in one/three spots. it’s in an if/elseif/else defining the js_CompareAndSwap function for different architectures:

/* Exclude Alpha NT. */
#if defined(_WIN32) && defined(_M_IX86)
#pragma warning( disable : 4035 )

static JS_INLINE int
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
{   
    __asm { 
        mov eax, ov
        mov ecx, nv
        mov ebx, w
        lock cmpxchg [ebx], ecx
        sete al
        and eax, 1h
    }
}

#elif defined(__GNUC__) && defined(__i386__)

/* Note: This fails on 386 cpus, cmpxchgl is a >= 486 instruction */
static JS_INLINE int
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
{
    unsigned int res;

    __asm__ __volatile__ (
                          "lock\n"
                          "cmpxchgl %2, (%1)\n"
                          "sete %%al\n"
                          "andl $1, %%eax\n"
                          : "=a" (res)
                          : "r" (w), "r" (nv), "a" (ov)
                          : "cc", "memory");
    return (int)res;
}

#elif defined(SOLARIS) && defined(sparc) && defined(ULTRA_SPARC)

static JS_INLINE int
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
{
#if defined(__GNUC__)
    unsigned int res;
    JS_ASSERT(ov != nv);
    asm volatile ("\
stbar\n\
cas [%1],%2,%3\n\
cmp %2,%3\n\
be,a 1f\n\
mov 1,%0\n\
mov 0,%0\n\
1:"
                  : "=r" (res)
                  : "r" (w), "r" (ov), "r" (nv));
    return (int)res;
#else /* !__GNUC__ */
    extern int compare_and_swap(jsword*, jsword, jsword);
    JS_ASSERT(ov != nv);
    return compare_and_swap(w, ov, nv);
#endif
}

This is the first place that looks like it’s probably going to need some work done. I’ll probably have to define a js_CompareAndSwap function for aarch, and make sure I’ve got the appropriate constants defined. It’s not a lot,
but it’s a start.

That’s all the time I’ve got for today!

(Both of these commands were plucked from class) Until Next time -Hunter