18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_SWAB_H
38c2ecf20Sopenharmony_ci#define _ASM_X86_SWAB_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/types.h>
68c2ecf20Sopenharmony_ci#include <linux/compiler.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_cistatic inline __attribute_const__ __u32 __arch_swab32(__u32 val)
98c2ecf20Sopenharmony_ci{
108c2ecf20Sopenharmony_ci	asm("bswapl %0" : "=r" (val) : "0" (val));
118c2ecf20Sopenharmony_ci	return val;
128c2ecf20Sopenharmony_ci}
138c2ecf20Sopenharmony_ci#define __arch_swab32 __arch_swab32
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistatic inline __attribute_const__ __u64 __arch_swab64(__u64 val)
168c2ecf20Sopenharmony_ci{
178c2ecf20Sopenharmony_ci#ifdef __i386__
188c2ecf20Sopenharmony_ci	union {
198c2ecf20Sopenharmony_ci		struct {
208c2ecf20Sopenharmony_ci			__u32 a;
218c2ecf20Sopenharmony_ci			__u32 b;
228c2ecf20Sopenharmony_ci		} s;
238c2ecf20Sopenharmony_ci		__u64 u;
248c2ecf20Sopenharmony_ci	} v;
258c2ecf20Sopenharmony_ci	v.u = val;
268c2ecf20Sopenharmony_ci	asm("bswapl %0 ; bswapl %1 ; xchgl %0,%1"
278c2ecf20Sopenharmony_ci	    : "=r" (v.s.a), "=r" (v.s.b)
288c2ecf20Sopenharmony_ci	    : "0" (v.s.a), "1" (v.s.b));
298c2ecf20Sopenharmony_ci	return v.u;
308c2ecf20Sopenharmony_ci#else /* __i386__ */
318c2ecf20Sopenharmony_ci	asm("bswapq %0" : "=r" (val) : "0" (val));
328c2ecf20Sopenharmony_ci	return val;
338c2ecf20Sopenharmony_ci#endif
348c2ecf20Sopenharmony_ci}
358c2ecf20Sopenharmony_ci#define __arch_swab64 __arch_swab64
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#endif /* _ASM_X86_SWAB_H */
38