forked from ilyakurdyukov/e2k-ports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libbotan-2.19.1-e2k.patch
257 lines (245 loc) · 6.09 KB
/
libbotan-2.19.1-e2k.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
From 7c1edc83e2620bfbdc1911aa7e8fca2ace76969b Mon Sep 17 00:00:00 2001
From: Ilya Kurdyukov <[email protected]>
Date: Wed, 31 Aug 2022 16:04:35 +0700
Subject: [PATCH] libbotan-2.19.1 e2k support
---
src/build-data/arch/e2k.txt | 11 +++++++
src/build-data/detect_arch.cpp | 3 ++
src/lib/block/aes/aes_vperm/info.txt | 3 ++
src/lib/filters/filter.h | 4 +++
src/lib/misc/zfec/zfec_vperm/info.txt | 3 ++
src/lib/utils/cpuid/cpuid.cpp | 7 ++++
src/lib/utils/cpuid/cpuid.h | 44 +++++++++++++++++++++++++-
src/lib/utils/ghash/ghash_cpu/info.txt | 3 ++
src/lib/utils/os_utils.cpp | 8 +++++
src/lib/utils/simd/info.txt | 2 ++
10 files changed, 87 insertions(+), 1 deletion(-)
create mode 100644 src/build-data/arch/e2k.txt
diff --git a/src/build-data/arch/e2k.txt b/src/build-data/arch/e2k.txt
new file mode 100644
index 0000000..b2cafe7
--- /dev/null
+++ b/src/build-data/arch/e2k.txt
@@ -0,0 +1,11 @@
+endian little
+wordsize 64
+
+family e2k
+
+<isa_extensions>
+avx2
+sse2
+sse41
+ssse3
+</isa_extensions>
diff --git a/src/build-data/detect_arch.cpp b/src/build-data/detect_arch.cpp
index 3a4bf8e..4d23cc9 100644
--- a/src/build-data/detect_arch.cpp
+++ b/src/build-data/detect_arch.cpp
@@ -73,6 +73,9 @@
#elif defined(__loongarch64)
LOONGARCH64
+#elif defined(__e2k__)
+ E2K
+
#else
UNKNOWN
diff --git a/src/lib/block/aes/aes_vperm/info.txt b/src/lib/block/aes/aes_vperm/info.txt
index 0b7eaba..4ee7038 100644
--- a/src/lib/block/aes/aes_vperm/info.txt
+++ b/src/lib/block/aes/aes_vperm/info.txt
@@ -9,6 +9,8 @@ x86_32:sse2
x86_64:sse2
x86_32:ssse3
x86_64:ssse3
+e2k:sse2
+e2k:ssse3
arm32:neon
arm64:neon
ppc32:altivec
@@ -18,6 +20,7 @@ ppc64:altivec
<arch>
x86_32
x86_64
+e2k
arm32
arm64
ppc32
diff --git a/src/lib/filters/filter.h b/src/lib/filters/filter.h
index 94b9c6c..81d262b 100644
--- a/src/lib/filters/filter.h
+++ b/src/lib/filters/filter.h
@@ -155,7 +155,11 @@ class BOTAN_PUBLIC_API(2,0) Fanout_Filter : public Filter
void attach(Filter* f) { Filter::attach(f); }
+#ifdef __e2k__
+ public: /* LCC bug workaround */
+#else
private:
+#endif
friend class Threaded_Fork;
using Filter::m_write_queue;
using Filter::total_ports;
diff --git a/src/lib/misc/zfec/zfec_vperm/info.txt b/src/lib/misc/zfec/zfec_vperm/info.txt
index c0731ca..dc398e1 100644
--- a/src/lib/misc/zfec/zfec_vperm/info.txt
+++ b/src/lib/misc/zfec/zfec_vperm/info.txt
@@ -7,6 +7,8 @@ x86_32:sse2
x86_64:sse2
x86_32:ssse3
x86_64:ssse3
+e2k:sse2
+e2k:ssse3
arm32:neon
arm64:neon
</isa>
@@ -14,6 +16,7 @@ arm64:neon
<arch>
x86_32
x86_64
+e2k
arm32
arm64
</arch>
diff --git a/src/lib/utils/cpuid/cpuid.cpp b/src/lib/utils/cpuid/cpuid.cpp
index e76e12e..d98b60d 100644
--- a/src/lib/utils/cpuid/cpuid.cpp
+++ b/src/lib/utils/cpuid/cpuid.cpp
@@ -58,6 +58,13 @@ std::string CPUID::to_string()
CPUID_PRINT(avx512_clmul);
#endif
+#if defined(BOTAN_TARGET_CPU_IS_E2K_FAMILY)
+ CPUID_PRINT(sse2);
+ CPUID_PRINT(ssse3);
+ CPUID_PRINT(sse41);
+ CPUID_PRINT(avx2);
+#endif
+
#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
CPUID_PRINT(altivec);
CPUID_PRINT(power_crypto);
diff --git a/src/lib/utils/cpuid/cpuid.h b/src/lib/utils/cpuid/cpuid.h
index 04d0bbd..effcd41 100644
--- a/src/lib/utils/cpuid/cpuid.h
+++ b/src/lib/utils/cpuid/cpuid.h
@@ -355,13 +355,55 @@ class BOTAN_PUBLIC_API(2,1) CPUID final
{ return has_cpuid_bit(CPUID_RDSEED_BIT); }
#endif
+#if defined(BOTAN_TARGET_CPU_IS_E2K_FAMILY)
+ /**
+ * Check if the processor supports SSE2
+ */
+ static bool has_sse2()
+#ifdef __SSE2__
+ { return true; }
+#else
+ { return false; }
+#endif
+
+ /**
+ * Check if the processor supports SSSE3
+ */
+ static bool has_ssse3()
+#ifdef __SSSE3__
+ { return true; }
+#else
+ { return false; }
+#endif
+
+ /**
+ * Check if the processor supports SSE4.1
+ */
+ static bool has_sse41()
+#ifdef __SSE4_1__
+ { return true; }
+#else
+ { return false; }
+#endif
+
+ /**
+ * Check if the processor supports AVX2
+ */
+ static bool has_avx2()
+#ifdef __AVX2__
+ { return true; }
+#else
+ { return false; }
+#endif
+#endif
+
/**
* Check if the processor supports byte-level vector permutes
* (SSSE3, NEON, Altivec)
*/
static bool has_vperm()
{
-#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY)
+#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) || defined(BOTAN_TARGET_CPU_IS_E2K_FAMILY)
return has_ssse3();
#elif defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY)
return has_neon();
diff --git a/src/lib/utils/ghash/ghash_cpu/info.txt b/src/lib/utils/ghash/ghash_cpu/info.txt
index 1f56377..97ab5e5 100644
--- a/src/lib/utils/ghash/ghash_cpu/info.txt
+++ b/src/lib/utils/ghash/ghash_cpu/info.txt
@@ -15,6 +15,8 @@ x86_32:aesni
x86_64:sse2
x86_64:ssse3
x86_64:aesni
+e2k:sse2
+e2k:ssse3
arm64:neon
arm64:armv8crypto
ppc64:powercrypto
@@ -23,6 +25,7 @@ ppc64:powercrypto
<arch>
x86_32
x86_64
+e2k
arm64
ppc64
</arch>
diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp
index f5151da..f21aaf4 100644
--- a/src/lib/utils/os_utils.cpp
+++ b/src/lib/utils/os_utils.cpp
@@ -151,6 +151,10 @@ bool OS::running_in_privileged_state()
#endif
}
+#if defined(BOTAN_TARGET_CPU_IS_E2K_FAMILY)
+#include <x86intrin.h>
+#endif
+
uint64_t OS::get_cpu_cycle_counter()
{
uint64_t rtc = 0;
@@ -160,6 +164,10 @@ uint64_t OS::get_cpu_cycle_counter()
::QueryPerformanceCounter(&tv);
rtc = tv.QuadPart;
+#elif defined(BOTAN_TARGET_CPU_IS_E2K_FAMILY)
+ unsigned aux;
+ rtc = __rdtscp(&aux);
+
#elif defined(BOTAN_USE_GCC_INLINE_ASM)
#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY)
diff --git a/src/lib/utils/simd/info.txt b/src/lib/utils/simd/info.txt
index 4a7044a..c70f3a2 100644
--- a/src/lib/utils/simd/info.txt
+++ b/src/lib/utils/simd/info.txt
@@ -10,6 +10,7 @@ simd_32.h
x86_32:sse2
x86_64:sse2
x32:sse2
+e2k:sse2
arm32:neon
arm64:neon
ppc32:altivec
@@ -20,6 +21,7 @@ ppc64:altivec
x86_32
x86_64
x32
+e2k
arm32
arm64
ppc32
--
2.34.1