18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 28c2ecf20Sopenharmony_ci#ifndef _ALPHA_SWAB_H 38c2ecf20Sopenharmony_ci#define _ALPHA_SWAB_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/types.h> 68c2ecf20Sopenharmony_ci#include <linux/compiler.h> 78c2ecf20Sopenharmony_ci#include <asm/compiler.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifdef __GNUC__ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_cistatic inline __attribute_const__ __u32 __arch_swab32(__u32 x) 128c2ecf20Sopenharmony_ci{ 138c2ecf20Sopenharmony_ci /* 148c2ecf20Sopenharmony_ci * Unfortunately, we can't use the 6 instruction sequence 158c2ecf20Sopenharmony_ci * on ev6 since the latency of the UNPKBW is 3, which is 168c2ecf20Sopenharmony_ci * pretty hard to hide. Just in case a future implementation 178c2ecf20Sopenharmony_ci * has a lower latency, here's the sequence (also by Mike Burrows) 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * UNPKBW a0, v0 v0: 00AA00BB00CC00DD 208c2ecf20Sopenharmony_ci * SLL v0, 24, a0 a0: BB00CC00DD000000 218c2ecf20Sopenharmony_ci * BIS v0, a0, a0 a0: BBAACCBBDDCC00DD 228c2ecf20Sopenharmony_ci * EXTWL a0, 6, v0 v0: 000000000000BBAA 238c2ecf20Sopenharmony_ci * ZAP a0, 0xf3, a0 a0: 00000000DDCC0000 248c2ecf20Sopenharmony_ci * ADDL a0, v0, v0 v0: ssssssssDDCCBBAA 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci __u64 t0, t1, t2, t3; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci t0 = __kernel_inslh(x, 7); /* t0 : 0000000000AABBCC */ 308c2ecf20Sopenharmony_ci t1 = __kernel_inswl(x, 3); /* t1 : 000000CCDD000000 */ 318c2ecf20Sopenharmony_ci t1 |= t0; /* t1 : 000000CCDDAABBCC */ 328c2ecf20Sopenharmony_ci t2 = t1 >> 16; /* t2 : 0000000000CCDDAA */ 338c2ecf20Sopenharmony_ci t0 = t1 & 0xFF00FF00; /* t0 : 00000000DD00BB00 */ 348c2ecf20Sopenharmony_ci t3 = t2 & 0x00FF00FF; /* t3 : 0000000000CC00AA */ 358c2ecf20Sopenharmony_ci t1 = t0 + t3; /* t1 : ssssssssDDCCBBAA */ 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci return t1; 388c2ecf20Sopenharmony_ci} 398c2ecf20Sopenharmony_ci#define __arch_swab32 __arch_swab32 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#endif /* __GNUC__ */ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#endif /* _ALPHA_SWAB_H */ 44