Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /*
0003  * This file is subject to the terms and conditions of the GNU General Public
0004  * License.  See the file "COPYING" in the main directory of this archive
0005  * for more details.
0006  *
0007  * Copyright (C) 1996, 99, 2003 by Ralf Baechle
0008  */
0009 #ifndef _ASM_SWAB_H
0010 #define _ASM_SWAB_H
0011 
0012 #include <linux/compiler.h>
0013 #include <linux/types.h>
0014 
0015 #define __SWAB_64_THRU_32__
0016 
0017 #if !defined(__mips16) &&                   \
0018     ((defined(__mips_isa_rev) && (__mips_isa_rev >= 2)) ||  \
0019      defined(_MIPS_ARCH_LOONGSON3A))
0020 
0021 static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
0022 {
0023     __asm__(
0024     "   .set    push            \n"
0025     "   .set    arch=mips32r2       \n"
0026     "   wsbh    %0, %1          \n"
0027     "   .set    pop         \n"
0028     : "=r" (x)
0029     : "r" (x));
0030 
0031     return x;
0032 }
0033 #define __arch_swab16 __arch_swab16
0034 
0035 static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
0036 {
0037     __asm__(
0038     "   .set    push            \n"
0039     "   .set    arch=mips32r2       \n"
0040     "   wsbh    %0, %1          \n"
0041     "   rotr    %0, %0, 16      \n"
0042     "   .set    pop         \n"
0043     : "=r" (x)
0044     : "r" (x));
0045 
0046     return x;
0047 }
0048 #define __arch_swab32 __arch_swab32
0049 
0050 /*
0051  * Having already checked for MIPS R2, enable the optimized version for
0052  * 64-bit kernel on r2 CPUs.
0053  */
0054 #ifdef __mips64
0055 static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
0056 {
0057     __asm__(
0058     "   .set    push            \n"
0059     "   .set    arch=mips64r2       \n"
0060     "   dsbh    %0, %1          \n"
0061     "   dshd    %0, %0          \n"
0062     "   .set    pop         \n"
0063     : "=r" (x)
0064     : "r" (x));
0065 
0066     return x;
0067 }
0068 #define __arch_swab64 __arch_swab64
0069 #endif /* __mips64 */
0070 #endif /* (not __mips16) and (MIPS R2 or newer or Loongson 3A) */
0071 #endif /* _ASM_SWAB_H */