xref: /openbmc/linux/arch/alpha/include/uapi/asm/swab.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*6f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
296433f6eSDavid Howells #ifndef _ALPHA_SWAB_H
396433f6eSDavid Howells #define _ALPHA_SWAB_H
496433f6eSDavid Howells 
596433f6eSDavid Howells #include <linux/types.h>
696433f6eSDavid Howells #include <linux/compiler.h>
796433f6eSDavid Howells #include <asm/compiler.h>
896433f6eSDavid Howells 
996433f6eSDavid Howells #ifdef __GNUC__
1096433f6eSDavid Howells 
__arch_swab32(__u32 x)1196433f6eSDavid Howells static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
1296433f6eSDavid Howells {
1396433f6eSDavid Howells 	/*
1496433f6eSDavid Howells 	 * Unfortunately, we can't use the 6 instruction sequence
1596433f6eSDavid Howells 	 * on ev6 since the latency of the UNPKBW is 3, which is
1696433f6eSDavid Howells 	 * pretty hard to hide.  Just in case a future implementation
1796433f6eSDavid Howells 	 * has a lower latency, here's the sequence (also by Mike Burrows)
1896433f6eSDavid Howells 	 *
1996433f6eSDavid Howells 	 * UNPKBW a0, v0       v0: 00AA00BB00CC00DD
2096433f6eSDavid Howells 	 * SLL v0, 24, a0      a0: BB00CC00DD000000
2196433f6eSDavid Howells 	 * BIS v0, a0, a0      a0: BBAACCBBDDCC00DD
2296433f6eSDavid Howells 	 * EXTWL a0, 6, v0     v0: 000000000000BBAA
2396433f6eSDavid Howells 	 * ZAP a0, 0xf3, a0    a0: 00000000DDCC0000
2496433f6eSDavid Howells 	 * ADDL a0, v0, v0     v0: ssssssssDDCCBBAA
2596433f6eSDavid Howells 	 */
2696433f6eSDavid Howells 
2796433f6eSDavid Howells 	__u64 t0, t1, t2, t3;
2896433f6eSDavid Howells 
2996433f6eSDavid Howells 	t0 = __kernel_inslh(x, 7);	/* t0 : 0000000000AABBCC */
3096433f6eSDavid Howells 	t1 = __kernel_inswl(x, 3);	/* t1 : 000000CCDD000000 */
3196433f6eSDavid Howells 	t1 |= t0;			/* t1 : 000000CCDDAABBCC */
3296433f6eSDavid Howells 	t2 = t1 >> 16;			/* t2 : 0000000000CCDDAA */
3396433f6eSDavid Howells 	t0 = t1 & 0xFF00FF00;		/* t0 : 00000000DD00BB00 */
3496433f6eSDavid Howells 	t3 = t2 & 0x00FF00FF;		/* t3 : 0000000000CC00AA */
3596433f6eSDavid Howells 	t1 = t0 + t3;			/* t1 : ssssssssDDCCBBAA */
3696433f6eSDavid Howells 
3796433f6eSDavid Howells 	return t1;
3896433f6eSDavid Howells }
3996433f6eSDavid Howells #define __arch_swab32 __arch_swab32
4096433f6eSDavid Howells 
4196433f6eSDavid Howells #endif /* __GNUC__ */
4296433f6eSDavid Howells 
4396433f6eSDavid Howells #endif /* _ALPHA_SWAB_H */
44