18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
28c2ecf20Sopenharmony_ci#ifndef _UAPI__ALPHA_COMPILER_H
38c2ecf20Sopenharmony_ci#define _UAPI__ALPHA_COMPILER_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * Herein are macros we use when describing various patterns we want to GCC.
78c2ecf20Sopenharmony_ci * In all cases we can get better schedules out of the compiler if we hide
88c2ecf20Sopenharmony_ci * as little as possible inside inline assembly.  However, we want to be
98c2ecf20Sopenharmony_ci * able to know what we'll get out before giving up inline assembly.  Thus
108c2ecf20Sopenharmony_ci * these tests and macros.
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3
148c2ecf20Sopenharmony_ci# define __kernel_insbl(val, shift)	__builtin_alpha_insbl(val, shift)
158c2ecf20Sopenharmony_ci# define __kernel_inswl(val, shift)	__builtin_alpha_inswl(val, shift)
168c2ecf20Sopenharmony_ci# define __kernel_insql(val, shift)	__builtin_alpha_insql(val, shift)
178c2ecf20Sopenharmony_ci# define __kernel_inslh(val, shift)	__builtin_alpha_inslh(val, shift)
188c2ecf20Sopenharmony_ci# define __kernel_extbl(val, shift)	__builtin_alpha_extbl(val, shift)
198c2ecf20Sopenharmony_ci# define __kernel_extwl(val, shift)	__builtin_alpha_extwl(val, shift)
208c2ecf20Sopenharmony_ci# define __kernel_cmpbge(a, b)		__builtin_alpha_cmpbge(a, b)
218c2ecf20Sopenharmony_ci#else
228c2ecf20Sopenharmony_ci# define __kernel_insbl(val, shift)					\
238c2ecf20Sopenharmony_ci  ({ unsigned long __kir;						\
248c2ecf20Sopenharmony_ci     __asm__("insbl %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val));	\
258c2ecf20Sopenharmony_ci     __kir; })
268c2ecf20Sopenharmony_ci# define __kernel_inswl(val, shift)					\
278c2ecf20Sopenharmony_ci  ({ unsigned long __kir;						\
288c2ecf20Sopenharmony_ci     __asm__("inswl %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val));	\
298c2ecf20Sopenharmony_ci     __kir; })
308c2ecf20Sopenharmony_ci# define __kernel_insql(val, shift)					\
318c2ecf20Sopenharmony_ci  ({ unsigned long __kir;						\
328c2ecf20Sopenharmony_ci     __asm__("insql %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val));	\
338c2ecf20Sopenharmony_ci     __kir; })
348c2ecf20Sopenharmony_ci# define __kernel_inslh(val, shift)					\
358c2ecf20Sopenharmony_ci  ({ unsigned long __kir;						\
368c2ecf20Sopenharmony_ci     __asm__("inslh %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val));	\
378c2ecf20Sopenharmony_ci     __kir; })
388c2ecf20Sopenharmony_ci# define __kernel_extbl(val, shift)					\
398c2ecf20Sopenharmony_ci  ({ unsigned long __kir;						\
408c2ecf20Sopenharmony_ci     __asm__("extbl %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val));	\
418c2ecf20Sopenharmony_ci     __kir; })
428c2ecf20Sopenharmony_ci# define __kernel_extwl(val, shift)					\
438c2ecf20Sopenharmony_ci  ({ unsigned long __kir;						\
448c2ecf20Sopenharmony_ci     __asm__("extwl %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val));	\
458c2ecf20Sopenharmony_ci     __kir; })
468c2ecf20Sopenharmony_ci# define __kernel_cmpbge(a, b)						\
478c2ecf20Sopenharmony_ci  ({ unsigned long __kir;						\
488c2ecf20Sopenharmony_ci     __asm__("cmpbge %r2,%1,%0" : "=r"(__kir) : "rI"(b), "rJ"(a));	\
498c2ecf20Sopenharmony_ci     __kir; })
508c2ecf20Sopenharmony_ci#endif
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#ifdef __alpha_cix__
538c2ecf20Sopenharmony_ci# if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3
548c2ecf20Sopenharmony_ci#  define __kernel_cttz(x)		__builtin_ctzl(x)
558c2ecf20Sopenharmony_ci#  define __kernel_ctlz(x)		__builtin_clzl(x)
568c2ecf20Sopenharmony_ci#  define __kernel_ctpop(x)		__builtin_popcountl(x)
578c2ecf20Sopenharmony_ci# else
588c2ecf20Sopenharmony_ci#  define __kernel_cttz(x)						\
598c2ecf20Sopenharmony_ci   ({ unsigned long __kir;						\
608c2ecf20Sopenharmony_ci      __asm__("cttz %1,%0" : "=r"(__kir) : "r"(x));			\
618c2ecf20Sopenharmony_ci      __kir; })
628c2ecf20Sopenharmony_ci#  define __kernel_ctlz(x)						\
638c2ecf20Sopenharmony_ci   ({ unsigned long __kir;						\
648c2ecf20Sopenharmony_ci      __asm__("ctlz %1,%0" : "=r"(__kir) : "r"(x));			\
658c2ecf20Sopenharmony_ci      __kir; })
668c2ecf20Sopenharmony_ci#  define __kernel_ctpop(x)						\
678c2ecf20Sopenharmony_ci   ({ unsigned long __kir;						\
688c2ecf20Sopenharmony_ci      __asm__("ctpop %1,%0" : "=r"(__kir) : "r"(x));			\
698c2ecf20Sopenharmony_ci      __kir; })
708c2ecf20Sopenharmony_ci# endif
718c2ecf20Sopenharmony_ci#else
728c2ecf20Sopenharmony_ci# define __kernel_cttz(x)						\
738c2ecf20Sopenharmony_ci  ({ unsigned long __kir;						\
748c2ecf20Sopenharmony_ci     __asm__(".arch ev67; cttz %1,%0" : "=r"(__kir) : "r"(x));		\
758c2ecf20Sopenharmony_ci     __kir; })
768c2ecf20Sopenharmony_ci# define __kernel_ctlz(x)						\
778c2ecf20Sopenharmony_ci  ({ unsigned long __kir;						\
788c2ecf20Sopenharmony_ci     __asm__(".arch ev67; ctlz %1,%0" : "=r"(__kir) : "r"(x));		\
798c2ecf20Sopenharmony_ci     __kir; })
808c2ecf20Sopenharmony_ci# define __kernel_ctpop(x)						\
818c2ecf20Sopenharmony_ci  ({ unsigned long __kir;						\
828c2ecf20Sopenharmony_ci     __asm__(".arch ev67; ctpop %1,%0" : "=r"(__kir) : "r"(x));		\
838c2ecf20Sopenharmony_ci     __kir; })
848c2ecf20Sopenharmony_ci#endif
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/*
888c2ecf20Sopenharmony_ci * Beginning with EGCS 1.1, GCC defines __alpha_bwx__ when the BWX
898c2ecf20Sopenharmony_ci * extension is enabled.  Previous versions did not define anything
908c2ecf20Sopenharmony_ci * we could test during compilation -- too bad, so sad.
918c2ecf20Sopenharmony_ci */
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#if defined(__alpha_bwx__)
948c2ecf20Sopenharmony_ci#define __kernel_ldbu(mem)	(mem)
958c2ecf20Sopenharmony_ci#define __kernel_ldwu(mem)	(mem)
968c2ecf20Sopenharmony_ci#define __kernel_stb(val,mem)	((mem) = (val))
978c2ecf20Sopenharmony_ci#define __kernel_stw(val,mem)	((mem) = (val))
988c2ecf20Sopenharmony_ci#else
998c2ecf20Sopenharmony_ci#define __kernel_ldbu(mem)				\
1008c2ecf20Sopenharmony_ci  ({ unsigned char __kir;				\
1018c2ecf20Sopenharmony_ci     __asm__(".arch ev56;				\
1028c2ecf20Sopenharmony_ci	      ldbu %0,%1" : "=r"(__kir) : "m"(mem));	\
1038c2ecf20Sopenharmony_ci     __kir; })
1048c2ecf20Sopenharmony_ci#define __kernel_ldwu(mem)				\
1058c2ecf20Sopenharmony_ci  ({ unsigned short __kir;				\
1068c2ecf20Sopenharmony_ci     __asm__(".arch ev56;				\
1078c2ecf20Sopenharmony_ci	      ldwu %0,%1" : "=r"(__kir) : "m"(mem));	\
1088c2ecf20Sopenharmony_ci     __kir; })
1098c2ecf20Sopenharmony_ci#define __kernel_stb(val,mem)				\
1108c2ecf20Sopenharmony_ci  __asm__(".arch ev56;					\
1118c2ecf20Sopenharmony_ci	   stb %1,%0" : "=m"(mem) : "r"(val))
1128c2ecf20Sopenharmony_ci#define __kernel_stw(val,mem)				\
1138c2ecf20Sopenharmony_ci  __asm__(".arch ev56;					\
1148c2ecf20Sopenharmony_ci	   stw %1,%0" : "=m"(mem) : "r"(val))
1158c2ecf20Sopenharmony_ci#endif
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#endif /* _UAPI__ALPHA_COMPILER_H */
119