[parisc-linux] __arch__swab24()

Matthew Wilcox willy@debian.org
Fri, 1 Aug 2003 18:00:22 +0100


On Fri, Aug 01, 2003 at 10:22:55AM -0600, LaMont Jones wrote:
> Any comments before I commit it to 2.4 and 2.5?

Here's what I came up with based on your patch.  It's embedded in a
test program.

#include <stdio.h>

typedef int __u32;

static int vanilla_swab24(int i)
{
        return ((i & 0xff) << 16) | (i & 0xff00) | ((i & 0xff0000) >> 16);
}

static __inline__ __const__ __u32 ___arch__swab24(__u32 x)
{
        __asm__("shd %0, %0, 8, %0\n\t"         /* shift xabcxabc -> cxab */
                "dep %0, 15, 8, %0\n\t"         /* deposit cxab -> cbab */
                "shd %%r0, %0, 8, %0"           /* shift 0000cbab -> 0cba */
                : "=r" (x)
                : "0" (x));
        return x;
}

int main(void)
{
        int i; 
        for (i = 0; i < 0x1ffffff; i++) { 
                if (___arch__swab24(i) != vanilla_swab24(i))
                        printf("Problem with i = %d\n", i);
        }
        return 0;
}


-- 
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk