Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 *
4 * Copyright (C) IBM Corporation, 2012
5 *
6 * Author: Anton Blanchard <anton@au.ibm.com>
7 */
8
9/*
10 * Sparse (as at v0.5.0) gets very, very confused by this file.
11 * Make it a bit simpler for it.
12 */
13#if !defined(__CHECKER__)
14#include <altivec.h>
15#else
16#define vec_xor(a, b) a ^ b
17#define vector __attribute__((vector_size(16)))
18#endif
19
20#include "xor_vmx.h"
21
22typedef vector signed char unative_t;
23
24#define DEFINE(V) \
25 unative_t *V = (unative_t *)V##_in; \
26 unative_t V##_0, V##_1, V##_2, V##_3
27
28#define LOAD(V) \
29 do { \
30 V##_0 = V[0]; \
31 V##_1 = V[1]; \
32 V##_2 = V[2]; \
33 V##_3 = V[3]; \
34 } while (0)
35
36#define STORE(V) \
37 do { \
38 V[0] = V##_0; \
39 V[1] = V##_1; \
40 V[2] = V##_2; \
41 V[3] = V##_3; \
42 } while (0)
43
44#define XOR(V1, V2) \
45 do { \
46 V1##_0 = vec_xor(V1##_0, V2##_0); \
47 V1##_1 = vec_xor(V1##_1, V2##_1); \
48 V1##_2 = vec_xor(V1##_2, V2##_2); \
49 V1##_3 = vec_xor(V1##_3, V2##_3); \
50 } while (0)
51
52void __xor_altivec_2(unsigned long bytes,
53 unsigned long * __restrict v1_in,
54 const unsigned long * __restrict v2_in)
55{
56 DEFINE(v1);
57 DEFINE(v2);
58 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
59
60 do {
61 LOAD(v1);
62 LOAD(v2);
63 XOR(v1, v2);
64 STORE(v1);
65
66 v1 += 4;
67 v2 += 4;
68 } while (--lines > 0);
69}
70
71void __xor_altivec_3(unsigned long bytes,
72 unsigned long * __restrict v1_in,
73 const unsigned long * __restrict v2_in,
74 const unsigned long * __restrict v3_in)
75{
76 DEFINE(v1);
77 DEFINE(v2);
78 DEFINE(v3);
79 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
80
81 do {
82 LOAD(v1);
83 LOAD(v2);
84 LOAD(v3);
85 XOR(v1, v2);
86 XOR(v1, v3);
87 STORE(v1);
88
89 v1 += 4;
90 v2 += 4;
91 v3 += 4;
92 } while (--lines > 0);
93}
94
95void __xor_altivec_4(unsigned long bytes,
96 unsigned long * __restrict v1_in,
97 const unsigned long * __restrict v2_in,
98 const unsigned long * __restrict v3_in,
99 const unsigned long * __restrict v4_in)
100{
101 DEFINE(v1);
102 DEFINE(v2);
103 DEFINE(v3);
104 DEFINE(v4);
105 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
106
107 do {
108 LOAD(v1);
109 LOAD(v2);
110 LOAD(v3);
111 LOAD(v4);
112 XOR(v1, v2);
113 XOR(v3, v4);
114 XOR(v1, v3);
115 STORE(v1);
116
117 v1 += 4;
118 v2 += 4;
119 v3 += 4;
120 v4 += 4;
121 } while (--lines > 0);
122}
123
124void __xor_altivec_5(unsigned long bytes,
125 unsigned long * __restrict v1_in,
126 const unsigned long * __restrict v2_in,
127 const unsigned long * __restrict v3_in,
128 const unsigned long * __restrict v4_in,
129 const unsigned long * __restrict v5_in)
130{
131 DEFINE(v1);
132 DEFINE(v2);
133 DEFINE(v3);
134 DEFINE(v4);
135 DEFINE(v5);
136 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
137
138 do {
139 LOAD(v1);
140 LOAD(v2);
141 LOAD(v3);
142 LOAD(v4);
143 LOAD(v5);
144 XOR(v1, v2);
145 XOR(v3, v4);
146 XOR(v1, v5);
147 XOR(v1, v3);
148 STORE(v1);
149
150 v1 += 4;
151 v2 += 4;
152 v3 += 4;
153 v4 += 4;
154 v5 += 4;
155 } while (--lines > 0);
156}
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 *
16 * Copyright (C) IBM Corporation, 2012
17 *
18 * Author: Anton Blanchard <anton@au.ibm.com>
19 */
20#include <altivec.h>
21
22#include <linux/preempt.h>
23#include <linux/export.h>
24#include <linux/sched.h>
25#include <asm/switch_to.h>
26
27typedef vector signed char unative_t;
28
29#define DEFINE(V) \
30 unative_t *V = (unative_t *)V##_in; \
31 unative_t V##_0, V##_1, V##_2, V##_3
32
33#define LOAD(V) \
34 do { \
35 V##_0 = V[0]; \
36 V##_1 = V[1]; \
37 V##_2 = V[2]; \
38 V##_3 = V[3]; \
39 } while (0)
40
41#define STORE(V) \
42 do { \
43 V[0] = V##_0; \
44 V[1] = V##_1; \
45 V[2] = V##_2; \
46 V[3] = V##_3; \
47 } while (0)
48
49#define XOR(V1, V2) \
50 do { \
51 V1##_0 = vec_xor(V1##_0, V2##_0); \
52 V1##_1 = vec_xor(V1##_1, V2##_1); \
53 V1##_2 = vec_xor(V1##_2, V2##_2); \
54 V1##_3 = vec_xor(V1##_3, V2##_3); \
55 } while (0)
56
57void xor_altivec_2(unsigned long bytes, unsigned long *v1_in,
58 unsigned long *v2_in)
59{
60 DEFINE(v1);
61 DEFINE(v2);
62 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
63
64 preempt_disable();
65 enable_kernel_altivec();
66
67 do {
68 LOAD(v1);
69 LOAD(v2);
70 XOR(v1, v2);
71 STORE(v1);
72
73 v1 += 4;
74 v2 += 4;
75 } while (--lines > 0);
76
77 disable_kernel_altivec();
78 preempt_enable();
79}
80EXPORT_SYMBOL(xor_altivec_2);
81
82void xor_altivec_3(unsigned long bytes, unsigned long *v1_in,
83 unsigned long *v2_in, unsigned long *v3_in)
84{
85 DEFINE(v1);
86 DEFINE(v2);
87 DEFINE(v3);
88 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
89
90 preempt_disable();
91 enable_kernel_altivec();
92
93 do {
94 LOAD(v1);
95 LOAD(v2);
96 LOAD(v3);
97 XOR(v1, v2);
98 XOR(v1, v3);
99 STORE(v1);
100
101 v1 += 4;
102 v2 += 4;
103 v3 += 4;
104 } while (--lines > 0);
105
106 disable_kernel_altivec();
107 preempt_enable();
108}
109EXPORT_SYMBOL(xor_altivec_3);
110
111void xor_altivec_4(unsigned long bytes, unsigned long *v1_in,
112 unsigned long *v2_in, unsigned long *v3_in,
113 unsigned long *v4_in)
114{
115 DEFINE(v1);
116 DEFINE(v2);
117 DEFINE(v3);
118 DEFINE(v4);
119 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
120
121 preempt_disable();
122 enable_kernel_altivec();
123
124 do {
125 LOAD(v1);
126 LOAD(v2);
127 LOAD(v3);
128 LOAD(v4);
129 XOR(v1, v2);
130 XOR(v3, v4);
131 XOR(v1, v3);
132 STORE(v1);
133
134 v1 += 4;
135 v2 += 4;
136 v3 += 4;
137 v4 += 4;
138 } while (--lines > 0);
139
140 disable_kernel_altivec();
141 preempt_enable();
142}
143EXPORT_SYMBOL(xor_altivec_4);
144
145void xor_altivec_5(unsigned long bytes, unsigned long *v1_in,
146 unsigned long *v2_in, unsigned long *v3_in,
147 unsigned long *v4_in, unsigned long *v5_in)
148{
149 DEFINE(v1);
150 DEFINE(v2);
151 DEFINE(v3);
152 DEFINE(v4);
153 DEFINE(v5);
154 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
155
156 preempt_disable();
157 enable_kernel_altivec();
158
159 do {
160 LOAD(v1);
161 LOAD(v2);
162 LOAD(v3);
163 LOAD(v4);
164 LOAD(v5);
165 XOR(v1, v2);
166 XOR(v3, v4);
167 XOR(v1, v5);
168 XOR(v1, v3);
169 STORE(v1);
170
171 v1 += 4;
172 v2 += 4;
173 v3 += 4;
174 v4 += 4;
175 v5 += 4;
176 } while (--lines > 0);
177
178 disable_kernel_altivec();
179 preempt_enable();
180}
181EXPORT_SYMBOL(xor_altivec_5);