Linux 4.6-rc6
[linux/fpc-iii.git] / arch / powerpc / lib / xor_vmx.c
blob07f49f1568e5eacccf5ea19929d572ff2eb68cfc
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.
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.
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.
16 * Copyright (C) IBM Corporation, 2012
18 * Author: Anton Blanchard <anton@au.ibm.com>
20 #include <altivec.h>
22 #include <linux/preempt.h>
23 #include <linux/export.h>
24 #include <linux/sched.h>
25 #include <asm/switch_to.h>
27 typedef vector signed char unative_t;
29 #define DEFINE(V) \
30 unative_t *V = (unative_t *)V##_in; \
31 unative_t V##_0, V##_1, V##_2, V##_3
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)
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)
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)
57 void xor_altivec_2(unsigned long bytes, unsigned long *v1_in,
58 unsigned long *v2_in)
60 DEFINE(v1);
61 DEFINE(v2);
62 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
64 preempt_disable();
65 enable_kernel_altivec();
67 do {
68 LOAD(v1);
69 LOAD(v2);
70 XOR(v1, v2);
71 STORE(v1);
73 v1 += 4;
74 v2 += 4;
75 } while (--lines > 0);
77 disable_kernel_altivec();
78 preempt_enable();
80 EXPORT_SYMBOL(xor_altivec_2);
82 void xor_altivec_3(unsigned long bytes, unsigned long *v1_in,
83 unsigned long *v2_in, unsigned long *v3_in)
85 DEFINE(v1);
86 DEFINE(v2);
87 DEFINE(v3);
88 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
90 preempt_disable();
91 enable_kernel_altivec();
93 do {
94 LOAD(v1);
95 LOAD(v2);
96 LOAD(v3);
97 XOR(v1, v2);
98 XOR(v1, v3);
99 STORE(v1);
101 v1 += 4;
102 v2 += 4;
103 v3 += 4;
104 } while (--lines > 0);
106 disable_kernel_altivec();
107 preempt_enable();
109 EXPORT_SYMBOL(xor_altivec_3);
111 void xor_altivec_4(unsigned long bytes, unsigned long *v1_in,
112 unsigned long *v2_in, unsigned long *v3_in,
113 unsigned long *v4_in)
115 DEFINE(v1);
116 DEFINE(v2);
117 DEFINE(v3);
118 DEFINE(v4);
119 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
121 preempt_disable();
122 enable_kernel_altivec();
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);
134 v1 += 4;
135 v2 += 4;
136 v3 += 4;
137 v4 += 4;
138 } while (--lines > 0);
140 disable_kernel_altivec();
141 preempt_enable();
143 EXPORT_SYMBOL(xor_altivec_4);
145 void 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)
149 DEFINE(v1);
150 DEFINE(v2);
151 DEFINE(v3);
152 DEFINE(v4);
153 DEFINE(v5);
154 unsigned long lines = bytes / (sizeof(unative_t)) / 4;
156 preempt_disable();
157 enable_kernel_altivec();
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);
171 v1 += 4;
172 v2 += 4;
173 v3 += 4;
174 v4 += 4;
175 v5 += 4;
176 } while (--lines > 0);
178 disable_kernel_altivec();
179 preempt_enable();
181 EXPORT_SYMBOL(xor_altivec_5);