162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * LoongArch SIMD XOR operations
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2023 WANG Xuerui <git@xen0n.name>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <linux/export.h>
962306a36Sopenharmony_ci#include <linux/sched.h>
1062306a36Sopenharmony_ci#include <asm/fpu.h>
1162306a36Sopenharmony_ci#include <asm/xor_simd.h>
1262306a36Sopenharmony_ci#include "xor_simd.h"
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#define MAKE_XOR_GLUE_2(flavor)							\
1562306a36Sopenharmony_civoid xor_##flavor##_2(unsigned long bytes, unsigned long * __restrict p1,	\
1662306a36Sopenharmony_ci		      const unsigned long * __restrict p2)			\
1762306a36Sopenharmony_ci{										\
1862306a36Sopenharmony_ci	kernel_fpu_begin();							\
1962306a36Sopenharmony_ci	__xor_##flavor##_2(bytes, p1, p2);					\
2062306a36Sopenharmony_ci	kernel_fpu_end();							\
2162306a36Sopenharmony_ci}										\
2262306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(xor_##flavor##_2)
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define MAKE_XOR_GLUE_3(flavor)							\
2562306a36Sopenharmony_civoid xor_##flavor##_3(unsigned long bytes, unsigned long * __restrict p1,	\
2662306a36Sopenharmony_ci		      const unsigned long * __restrict p2,			\
2762306a36Sopenharmony_ci		      const unsigned long * __restrict p3)			\
2862306a36Sopenharmony_ci{										\
2962306a36Sopenharmony_ci	kernel_fpu_begin();							\
3062306a36Sopenharmony_ci	__xor_##flavor##_3(bytes, p1, p2, p3);					\
3162306a36Sopenharmony_ci	kernel_fpu_end();							\
3262306a36Sopenharmony_ci}										\
3362306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(xor_##flavor##_3)
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define MAKE_XOR_GLUE_4(flavor)							\
3662306a36Sopenharmony_civoid xor_##flavor##_4(unsigned long bytes, unsigned long * __restrict p1,	\
3762306a36Sopenharmony_ci		      const unsigned long * __restrict p2,			\
3862306a36Sopenharmony_ci		      const unsigned long * __restrict p3,			\
3962306a36Sopenharmony_ci		      const unsigned long * __restrict p4)			\
4062306a36Sopenharmony_ci{										\
4162306a36Sopenharmony_ci	kernel_fpu_begin();							\
4262306a36Sopenharmony_ci	__xor_##flavor##_4(bytes, p1, p2, p3, p4);				\
4362306a36Sopenharmony_ci	kernel_fpu_end();							\
4462306a36Sopenharmony_ci}										\
4562306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(xor_##flavor##_4)
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define MAKE_XOR_GLUE_5(flavor)							\
4862306a36Sopenharmony_civoid xor_##flavor##_5(unsigned long bytes, unsigned long * __restrict p1,	\
4962306a36Sopenharmony_ci		      const unsigned long * __restrict p2,			\
5062306a36Sopenharmony_ci		      const unsigned long * __restrict p3,			\
5162306a36Sopenharmony_ci		      const unsigned long * __restrict p4,			\
5262306a36Sopenharmony_ci		      const unsigned long * __restrict p5)			\
5362306a36Sopenharmony_ci{										\
5462306a36Sopenharmony_ci	kernel_fpu_begin();							\
5562306a36Sopenharmony_ci	__xor_##flavor##_5(bytes, p1, p2, p3, p4, p5);				\
5662306a36Sopenharmony_ci	kernel_fpu_end();							\
5762306a36Sopenharmony_ci}										\
5862306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(xor_##flavor##_5)
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define MAKE_XOR_GLUES(flavor)		\
6162306a36Sopenharmony_ci	MAKE_XOR_GLUE_2(flavor);	\
6262306a36Sopenharmony_ci	MAKE_XOR_GLUE_3(flavor);	\
6362306a36Sopenharmony_ci	MAKE_XOR_GLUE_4(flavor);	\
6462306a36Sopenharmony_ci	MAKE_XOR_GLUE_5(flavor)
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#ifdef CONFIG_CPU_HAS_LSX
6762306a36Sopenharmony_ciMAKE_XOR_GLUES(lsx);
6862306a36Sopenharmony_ci#endif
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#ifdef CONFIG_CPU_HAS_LASX
7162306a36Sopenharmony_ciMAKE_XOR_GLUES(lasx);
7262306a36Sopenharmony_ci#endif
73