Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / sh / include / asm / cmpxchg-grb.h
blobe12279ea35cf74a018716e09f24cfa2138d53e10
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_SH_CMPXCHG_GRB_H
3 #define __ASM_SH_CMPXCHG_GRB_H
5 static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
7 unsigned long retval;
9 __asm__ __volatile__ (
10 " .align 2 \n\t"
11 " mova 1f, r0 \n\t" /* r0 = end point */
12 " nop \n\t"
13 " mov r15, r1 \n\t" /* r1 = saved sp */
14 " mov #-4, r15 \n\t" /* LOGIN */
15 " mov.l @%1, %0 \n\t" /* load old value */
16 " mov.l %2, @%1 \n\t" /* store new value */
17 "1: mov r1, r15 \n\t" /* LOGOUT */
18 : "=&r" (retval),
19 "+r" (m),
20 "+r" (val) /* inhibit r15 overloading */
22 : "memory", "r0", "r1");
24 return retval;
27 static inline unsigned long xchg_u16(volatile u16 *m, unsigned long val)
29 unsigned long retval;
31 __asm__ __volatile__ (
32 " .align 2 \n\t"
33 " mova 1f, r0 \n\t" /* r0 = end point */
34 " mov r15, r1 \n\t" /* r1 = saved sp */
35 " mov #-6, r15 \n\t" /* LOGIN */
36 " mov.w @%1, %0 \n\t" /* load old value */
37 " extu.w %0, %0 \n\t" /* extend as unsigned */
38 " mov.w %2, @%1 \n\t" /* store new value */
39 "1: mov r1, r15 \n\t" /* LOGOUT */
40 : "=&r" (retval),
41 "+r" (m),
42 "+r" (val) /* inhibit r15 overloading */
44 : "memory" , "r0", "r1");
46 return retval;
49 static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
51 unsigned long retval;
53 __asm__ __volatile__ (
54 " .align 2 \n\t"
55 " mova 1f, r0 \n\t" /* r0 = end point */
56 " mov r15, r1 \n\t" /* r1 = saved sp */
57 " mov #-6, r15 \n\t" /* LOGIN */
58 " mov.b @%1, %0 \n\t" /* load old value */
59 " extu.b %0, %0 \n\t" /* extend as unsigned */
60 " mov.b %2, @%1 \n\t" /* store new value */
61 "1: mov r1, r15 \n\t" /* LOGOUT */
62 : "=&r" (retval),
63 "+r" (m),
64 "+r" (val) /* inhibit r15 overloading */
66 : "memory" , "r0", "r1");
68 return retval;
71 static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
72 unsigned long new)
74 unsigned long retval;
76 __asm__ __volatile__ (
77 " .align 2 \n\t"
78 " mova 1f, r0 \n\t" /* r0 = end point */
79 " nop \n\t"
80 " mov r15, r1 \n\t" /* r1 = saved sp */
81 " mov #-8, r15 \n\t" /* LOGIN */
82 " mov.l @%3, %0 \n\t" /* load old value */
83 " cmp/eq %0, %1 \n\t"
84 " bf 1f \n\t" /* if not equal */
85 " mov.l %2, @%3 \n\t" /* store new value */
86 "1: mov r1, r15 \n\t" /* LOGOUT */
87 : "=&r" (retval),
88 "+r" (old), "+r" (new) /* old or new can be r15 */
89 : "r" (m)
90 : "memory" , "r0", "r1", "t");
92 return retval;
95 #endif /* __ASM_SH_CMPXCHG_GRB_H */