Skip to contentSkip to conversation

__arch__swab24()

parisc-linux LaMont Jones 3 participants 3 messages Aug 1, 2003

lore
Share & tools
lore
#0 lore raw

The following patch implements __arch__swab24() optimally for hppa.

It also has the side effect of making some other things happier. :-)

Any comments before I commit it to 2.4 and 2.5?

lamont

Index: include/asm-parisc/byteorder.h
===================================================================
RCS file: /var/cvs/linux/include/asm-parisc/byteorder.h,v retrieving revision 1.7

asm-parisc/byteorder.h +12 -0
diff -u -r1.7 byteorder.h
@@ -14,6 +14,17 @@
 	return x;
 }
 
+static __inline__ __const__ __u32 ___arch__swab24(__u32 x)
+{
+	unsigned int temp;
+	__asm__("shd %0, %0, 8, %1\n\t"		/* shift xabcxabc -> cxab */
+		"dep %1, 15, 8, %1\n\t"		/* deposit cxab -> cbab */
+		"shd %r0, %1, 8, %0"		/* shift 0000cbab -> 0cba */
+		: "=r" (x), "=&r" (temp)
+		: "0" (x));
+	return x;
+}
+
 static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
 {
 	unsigned int temp;
@@ -63,6 +74,7 @@
 #endif
 
 #define __arch__swab16(x) ___arch__swab16(x)
+#define __arch__swab24(x) ___arch__swab24(x)
 #define __arch__swab32(x) ___arch__swab32(x)
 
 #endif /* __GNUC__ */
#1 lore raw
Quoted 1 line · LaMont Jones

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;
}
Signature · 3 lines
"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
#2 lore raw
Quoted 6 lines
Quoted 3 lines · LaMont Jones

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.

[...]

? no pb on my b180 (32bits kernel 2.4.21-pa6)

Joel

------------------------------------------------------
Soldes Tiscali ADSL : 27,50 euros/mois jusque fin 2003. On s'habitue vite à payer son ADSL moins cher!
Plus d'info? Cliquez ici... http://reg.tiscali.be/default.asp?lg=fr