blob: da3bfe5cc161557f770d49dc0a1a67d10676b04a [file] [log] [blame]
Harvey Harrison13f78772009-01-06 14:56:24 -08001#ifndef _S390_SWAB_H
2#define _S390_SWAB_H
3
4/*
Harvey Harrison13f78772009-01-06 14:56:24 -08005 * S390 version
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02006 * Copyright IBM Corp. 1999
Harvey Harrison13f78772009-01-06 14:56:24 -08007 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
8 */
9
Heiko Carstens0680ba02009-01-09 12:14:52 +010010#include <linux/types.h>
Harvey Harrison13f78772009-01-06 14:56:24 -080011
12#ifndef __s390x__
13# define __SWAB_64_THRU_32__
14#endif
15
16#ifdef __s390x__
17static inline __u64 __arch_swab64p(const __u64 *x)
18{
19 __u64 result;
20
21 asm volatile("lrvg %0,%1" : "=d" (result) : "m" (*x));
22 return result;
23}
24#define __arch_swab64p __arch_swab64p
25
26static inline __u64 __arch_swab64(__u64 x)
27{
28 __u64 result;
29
30 asm volatile("lrvgr %0,%1" : "=d" (result) : "d" (x));
31 return result;
32}
33#define __arch_swab64 __arch_swab64
34
35static inline void __arch_swab64s(__u64 *x)
36{
37 *x = __arch_swab64p(x);
38}
39#define __arch_swab64s __arch_swab64s
40#endif /* __s390x__ */
41
42static inline __u32 __arch_swab32p(const __u32 *x)
43{
44 __u32 result;
45
46 asm volatile(
47#ifndef __s390x__
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010048 " icm %0,8,%O1+3(%R1)\n"
49 " icm %0,4,%O1+2(%R1)\n"
50 " icm %0,2,%O1+1(%R1)\n"
51 " ic %0,%1"
52 : "=&d" (result) : "Q" (*x) : "cc");
Harvey Harrison13f78772009-01-06 14:56:24 -080053#else /* __s390x__ */
54 " lrv %0,%1"
55 : "=d" (result) : "m" (*x));
56#endif /* __s390x__ */
57 return result;
58}
59#define __arch_swab32p __arch_swab32p
60
61#ifdef __s390x__
62static inline __u32 __arch_swab32(__u32 x)
63{
64 __u32 result;
65
66 asm volatile("lrvr %0,%1" : "=d" (result) : "d" (x));
67 return result;
68}
69#define __arch_swab32 __arch_swab32
70#endif /* __s390x__ */
71
72static inline __u16 __arch_swab16p(const __u16 *x)
73{
74 __u16 result;
75
76 asm volatile(
77#ifndef __s390x__
Martin Schwidefskyaffbb422012-04-11 14:28:12 +020078 " icm %0,2,%O1+1(%R1)\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010079 " ic %0,%1\n"
80 : "=&d" (result) : "Q" (*x) : "cc");
Harvey Harrison13f78772009-01-06 14:56:24 -080081#else /* __s390x__ */
82 " lrvh %0,%1"
83 : "=d" (result) : "m" (*x));
84#endif /* __s390x__ */
85 return result;
86}
87#define __arch_swab16p __arch_swab16p
88
89#endif /* _S390_SWAB_H */