18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 28c2ecf20Sopenharmony_ci#ifndef __ASM_SH_SWAB_H 38c2ecf20Sopenharmony_ci#define __ASM_SH_SWAB_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* 68c2ecf20Sopenharmony_ci * Copyright (C) 1999 Niibe Yutaka 78c2ecf20Sopenharmony_ci * Copyright (C) 2000, 2001 Paolo Alberelli 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#include <linux/compiler.h> 108c2ecf20Sopenharmony_ci#include <linux/types.h> 118c2ecf20Sopenharmony_ci#include <asm-generic/swab.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistatic inline __attribute_const__ __u32 __arch_swab32(__u32 x) 148c2ecf20Sopenharmony_ci{ 158c2ecf20Sopenharmony_ci __asm__( 168c2ecf20Sopenharmony_ci "swap.b %1, %0\n\t" 178c2ecf20Sopenharmony_ci "swap.w %0, %0\n\t" 188c2ecf20Sopenharmony_ci "swap.b %0, %0" 198c2ecf20Sopenharmony_ci : "=r" (x) 208c2ecf20Sopenharmony_ci : "r" (x)); 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci return x; 238c2ecf20Sopenharmony_ci} 248c2ecf20Sopenharmony_ci#define __arch_swab32 __arch_swab32 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic inline __attribute_const__ __u16 __arch_swab16(__u16 x) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci __asm__( 298c2ecf20Sopenharmony_ci "swap.b %1, %0" 308c2ecf20Sopenharmony_ci : "=r" (x) 318c2ecf20Sopenharmony_ci : "r" (x)); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci return x; 348c2ecf20Sopenharmony_ci} 358c2ecf20Sopenharmony_ci#define __arch_swab16 __arch_swab16 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic inline __u64 __arch_swab64(__u64 val) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci union { 408c2ecf20Sopenharmony_ci struct { __u32 a,b; } s; 418c2ecf20Sopenharmony_ci __u64 u; 428c2ecf20Sopenharmony_ci } v, w; 438c2ecf20Sopenharmony_ci v.u = val; 448c2ecf20Sopenharmony_ci w.s.b = __arch_swab32(v.s.a); 458c2ecf20Sopenharmony_ci w.s.a = __arch_swab32(v.s.b); 468c2ecf20Sopenharmony_ci return w.u; 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci#define __arch_swab64 __arch_swab64 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#endif /* __ASM_SH_SWAB_H */ 51