On Mon, Jun 18, 2007 at 01:07:26PM -0700, Bart Smaalders wrote:

<mucho snippage deleted!>

> On x86, why not inline a bswap instruction?

That *is* the actual implementation of htons()/ntohs().  Here, check it out!

>From $SRC/uts/intel/ia32/ml/ia32.il:

/
/ Networking byte order functions (too bad, Intel has the wrong byte order)
/
        .inline htonl,4
        movl    (%esp), %eax
        bswap   %eax
        .end

        .inline ntohl,4
        movl    (%esp), %eax
        bswap   %eax
        .end

        .inline htons,4
        movl    (%esp), %eax
        bswap   %eax
        shrl    $16, %eax
        .end

        .inline ntohs,4
        movl    (%esp), %eax
        bswap   %eax
        shrl    $16, %eax
        .end

and from $SRC/uts/intel/amd64/ml/amd64.il:

/
/ Networking byte order functions (too bad, Intel has the wrong byte order)
/

        .inline htonl,4
        movl    %edi, %eax
        bswap   %eax
        .end

        .inline ntohl,4
        movl    %edi, %eax
        bswap   %eax
        .end

        .inline htons,4
        movl    %edi, %eax
        bswap   %eax
        shrl    $16, %eax
        .end

        .inline ntohs,4
        movl    %edi, %eax
        bswap   %eax
        shrl    $16, %eax
        .end

I didn't show DTrace numbers for the "htonl() the big-endian version" in my
previous post, but it was slower than the table-lookup whose numbers I did
share.

Dan
_______________________________________________
perf-discuss mailing list
perf-discuss@opensolaris.org

Reply via email to