patch-1.3.50 linux/include/asm-alpha/byteorder.h

Next file: linux/include/asm-alpha/fpu.h
Previous file: linux/include/asm-alpha/apecs.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.49/linux/include/asm-alpha/byteorder.h linux/include/asm-alpha/byteorder.h
@@ -34,10 +34,21 @@
 extern __inline__ unsigned long int
 __ntohl(unsigned long int x)
 {
-	return (((x & 0x000000ffU) << 24) |
-		((x & 0x0000ff00U) <<  8) |
-		((x & 0x00ff0000U) >>  8) |
-		((x & 0xff000000U) >> 24));
+	unsigned long int res, t1, t2;
+
+	__asm__
+	    ("bis	%3,%3,%0	# %0 is result; %0=aabbccdd
+	      extlh	%0,5,%1		# %1 = dd000000
+	      zap	%0,0xfd,%2	# %2 = 0000cc00
+	      sll	%2,5,%2		# %2 = 00198000
+	      s8addl	%2,%1,%1	# %1 = ddcc0000
+	      zap	%0,0xfb,%2	# %2 = 00bb0000
+	      srl	%2,8,%2		# %2 = 0000bb00
+	      extbl	%0,3,%0		# %0 = 000000aa
+	      or	%1,%0,%0	# %0 = ddcc00aa
+	      or	%2,%0,%0	# %0 = ddccbbaa"
+	     : "r="(res), "r="(t1), "r="(t2) : "r"(x));
+	return res;
 }
 
 #define __constant_ntohl(x) \
@@ -49,8 +60,15 @@
 extern __inline__ unsigned short int
 __ntohs(unsigned short int x)
 {
-	return (((x & 0x00ff) << 8) |
-		((x & 0xff00) >> 8));
+	unsigned long int res, t1;
+	
+	__asm__
+	    ("bis	%2,%2,%0	# v0 is result; swap in-place.  v0=aabb
+	      extwh	%0,7,%1		# t1 = bb00
+	      extbl	%0,1,%0		# v0 = 00aa
+	      bis	%0,%1,%0	# v0 = bbaa"
+	     : "r="(res), "r="(t1) : "r"(x));
+	return res;
 }
 
 #define __constant_ntohs(x) \

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this