about summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-11-21 18:00:43 +0100
committerptitSeb <sebastien.chev@gmail.com>2023-11-21 18:00:58 +0100
commitafe6fbe3b330929bde1a36712346bda2ffc7d9f9 (patch)
treee79e73f8bf46cf7cee4c667954d53fd0047147fe /tests
parent39568bff2fe3dc8d907d0738ccca4c14501cd808 (diff)
downloadbox64-afe6fbe3b330929bde1a36712346bda2ffc7d9f9.tar.gz
box64-afe6fbe3b330929bde1a36712346bda2ffc7d9f9.zip
Added full support for the SHA cpu extension
Diffstat (limited to 'tests')
-rw-r--r--tests/ref28.txt31
-rwxr-xr-xtests/test28bin0 -> 25008 bytes
-rw-r--r--tests/test28.c134
3 files changed, 165 insertions, 0 deletions
diff --git a/tests/ref28.txt b/tests/ref28.txt
new file mode 100644
index 00000000..033d0f49
--- /dev/null
+++ b/tests/ref28.txt
@@ -0,0 +1,31 @@
+test SHA Ext
+sha1rnds4(00000000-00000000-00000000-00000000 ,00000004-00000003-00000002-00000001, 0x0) => f40757f7-b4b82290-eab46b51-56a09e67
+sha1rnds4(00000000-00000000-00000000-00000000 ,00000004-00000003-00000002-00000001, 0x1) => 9477347e-209fe171-5285d814-5bb67ae9
+sha1rnds4(00000000-00000000-00000000-00000000 ,00000004-00000003-00000002-00000001, 0x2) => e27962a9-e186daec-1ca4d63c-23c6ef38
+sha1rnds4(00000000-00000000-00000000-00000000 ,00000004-00000003-00000002-00000001, 0x3) => f32a4da8-6c2529f4-85aebf4c-b298b076
+sha1rnds4(00000000-00000000-00000000-00000000 ,ffffffff-00000000-01234567-80000000, 0x0) => 986d7873-b5db5395-2ab46b29-16a09e66
+sha1rnds4(00000000-00000000-00000000-00000000 ,ffffffff-00000000-01234567-80000000, 0x1) => 78dd5f0b-21c31271-9285d7eb-1bb67ae8
+sha1rnds4(00000000-00000000-00000000-00000000 ,ffffffff-00000000-01234567-80000000, 0x2) => c6df831c-e2aa0bf1-5ca4d613-e3c6ef36
+sha1rnds4(00000000-00000000-00000000-00000000 ,ffffffff-00000000-01234567-80000000, 0x3) => 57906d5d-6d485af4-c5aebf23-7298b075
+sha1rnds4(00000004-00000003-00000002-00000001 ,ffffffff-00000000-01234567-80000000, 0x0) => d8ae9505-35dd5bf7-eab46f39-96a09e86
+sha1rnds4(00000004-00000003-00000002-00000001 ,ffffffff-00000000-01234567-80000000, 0x1) => f91d79e9-61c513cc-4285dbed-1bb67b08
+sha1rnds4(00000004-00000003-00000002-00000001 ,ffffffff-00000000-01234567-80000000, 0x2) => 4721274f-62ac1813-9ca4da2b-a3c6ef57
+sha1rnds4(00000004-00000003-00000002-00000001 ,ffffffff-00000000-01234567-80000000, 0x3) => 57d20b8d-ad4a5c6d-b5aec325-7298b095
+sha1msg1(00000000-00000000-00000000-00000000 ,00000004-00000003-00000002-00000001) => 00000000-00000000-00000004-00000003
+sha1msg1(00000000-00000000-00000000-00000000 ,ffffffff-00000000-01234567-80000000) => 00000000-00000000-ffffffff-00000000
+sha1msg1(00000004-00000003-00000002-00000001 ,ffffffff-00000000-01234567-80000000) => 00000006-00000002-fffffffd-00000001
+sha1msg2(00000000-00000000-00000000-00000000 ,00000004-00000003-00000002-00000001) => 00000006-00000004-00000002-0000000c
+sha1msg2(00000000-00000000-00000000-00000000 ,ffffffff-00000000-01234567-80000000) => 00000000-02468ace-00000001-00000000
+sha1msg2(00000004-00000003-00000002-00000001 ,ffffffff-00000000-01234567-80000000) => 00000008-02468ac8-00000005-00000012
+sha1nexte(00000000-00000000-00000000-00000000 ,00000004-00000003-00000002-00000001) => 00000004-00000003-00000002-00000001
+sha1nexte(00000000-00000000-00000000-00000000 ,ffffffff-00000000-01234567-80000000) => ffffffff-00000000-01234567-80000000
+sha1nexte(00000004-00000003-00000002-00000001 ,ffffffff-00000000-01234567-80000000) => 00000000-00000000-01234567-80000000
+sha256msg1(00000000-00000000-00000000-00000000 ,00000004-00000003-00000002-00000001) => 02004000-00000000-00000000-00000000
+sha256msg1(00000000-00000000-00000000-00000000 ,ffffffff-00000000-01234567-80000000) => 11002000-00000000-00000000-00000000
+sha256msg1(00000004-00000003-00000002-00000001 ,ffffffff-00000000-01234567-80000000) => 11002004-08010003-0600c002-04008001
+sha256msg2(00000000-00000000-00000000-00000000 ,00000004-00000003-00000002-00000001) => 100000a1-cc000078-00028000-0001e000
+sha256msg2(00000000-00000000-00000000-00000000 ,ffffffff-00000000-01234567-80000000) => 00006fe7-00000000-003fffff-00000000
+sha256msg2(00000004-00000003-00000002-00000001 ,ffffffff-00000000-01234567-80000000) => 0000b02c-0000a003-00400001-00000001
+sha256rnds2(00000000-00000000-00000000-00000000 ,00000004-00000003-00000002-00000001 ,ffffffff-00000000-01234567-80000000) => 6da40f0a-88601101-0353cda8-88400100
+sha256rnds2(00000004-00000003-00000002-00000001 ,00000000-00000000-00000000-00000000 ,ffffffff-00000000-01234567-80000000) => fc0f56a9-80000003-1bf348ad-80000006
+sha256rnds2(ffffffff-00000000-01234567-80000000 ,00000004-00000003-00000002-00000001 ,00000000-00000000-00000000-00000000) => c8b008c8-8983566d-ec5ad91b-89634665
diff --git a/tests/test28 b/tests/test28
new file mode 100755
index 00000000..43aee286
--- /dev/null
+++ b/tests/test28
Binary files differdiff --git a/tests/test28.c b/tests/test28.c
new file mode 100644
index 00000000..86df4a90
--- /dev/null
+++ b/tests/test28.c
@@ -0,0 +1,134 @@
+// build with  gcc -O0 -g -msha -msse4.2 test28.c -o test28
+// and -m32 for 32bits version
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <math.h>
+#include <pmmintrin.h>
+#include <immintrin.h>
+
+typedef unsigned char u8x16 __attribute__ ((vector_size (16)));
+typedef unsigned short u16x8 __attribute__ ((vector_size (16)));
+typedef unsigned int  u32x4 __attribute__ ((vector_size (16)));
+typedef unsigned long int  u64x2 __attribute__ ((vector_size (16)));
+typedef float  f32x4 __attribute__ ((vector_size (16)));
+typedef double d64x2 __attribute__ ((vector_size (16)));
+
+typedef union {
+        __m128i mm;
+        __m128  mf;
+        __m128d md;
+        u8x16   u8;
+        u16x8   u16;
+        u32x4   u32;
+        u64x2   u64;
+        f32x4   f32;
+        d64x2   d64;
+} v128;
+
+static const uint32_t A[] = {0, 0, 0, 0};
+static const uint32_t B[] = {1, 2, 3, 4};
+static const uint32_t C[] = {0x80000000, 0x1234567, 0, 0xffffffff};
+
+static void print_u32(v128 a) {
+  printf("%08x-%08x-%08x-%08x", a.u32[3], a.u32[2], a.u32[1], a.u32[0]);
+}
+
+static void print_u32_res(v128 a, v128 b, const char* op, v128 res) {
+  printf("%s(", op);
+  print_u32(a);
+  printf(" ,");
+  print_u32(b);
+  printf(") => ");
+  print_u32(res);
+  printf("\n");
+}
+static void print_u32_u8_res(v128 a, v128 b, const char* op, uint8_t ib, v128 res) {
+  printf("%s(", op);
+  print_u32(a);
+  printf(" ,");
+  print_u32(b);
+  printf(", 0x%x) => ", ib);
+  print_u32(res);
+  printf("\n");
+}
+
+static void print_3u32_res(v128 a, v128 b, v128 c, const char* op, v128 res) {
+  printf("%s(", op);
+  print_u32(a);
+  printf(" ,");
+  print_u32(b);
+  printf(" ,");
+  print_u32(c);
+  printf(") => ");
+  print_u32(res);
+  printf("\n");
+}
+
+int main(int argc, const char** argv)
+{
+  printf("test SHA Ext\n");
+
+  v128 a, b, c, d;
+  int ret;
+  #define LOAD(a, A) a.u32[0] = A[0]; a.u32[1] = A[1]; a.u32[2] = A[2]; a.u32[3] = A[3]
+
+  #define GO2I_(A, B, C, I)  \
+    LOAD(a, A); \
+    LOAD(b, B); \
+    c.mm = _mm_##C##_epu32(a.mm, b.mm, I); \
+    print_u32_u8_res(a, b, #C, I, c)
+
+  #define GO2(A, B, C)  \
+    LOAD(a, A); \
+    LOAD(b, B); \
+    c.mm = _mm_##C##_epu32(a.mm, b.mm); \
+    print_u32_res(a, b, #C, c)
+
+  #define GO3(A, B, C, D)  \
+    LOAD(a, A); \
+    LOAD(b, B); \
+    LOAD(c, C); \
+    d.mm = _mm_##D##_epu32(a.mm, b.mm, c.mm); \
+    print_3u32_res(a, b, c, #D, d)
+
+
+  #define GO2I(A, B, C)   \
+  GO2I_(A, B, C, 0x00);   \
+  GO2I_(A, B, C, 0x01);   \
+  GO2I_(A, B, C, 0x02);   \
+  GO2I_(A, B, C, 0x03)
+
+  GO2I(A, B, sha1rnds4);
+  GO2I(A, C, sha1rnds4);
+  GO2I(B, C, sha1rnds4);
+
+  GO2(A, B, sha1msg1);
+  GO2(A, C, sha1msg1);
+  GO2(B, C, sha1msg1);
+
+  GO2(A, B, sha1msg2);
+  GO2(A, C, sha1msg2);
+  GO2(B, C, sha1msg2);
+
+  GO2(A, B, sha1nexte);
+  GO2(A, C, sha1nexte);
+  GO2(B, C, sha1nexte);
+
+  GO2(A, B, sha256msg1);
+  GO2(A, C, sha256msg1);
+  GO2(B, C, sha256msg1);
+
+  GO2(A, B, sha256msg2);
+  GO2(A, C, sha256msg2);
+  GO2(B, C, sha256msg2);
+
+  GO3(A, B, C, sha256rnds2);
+  GO3(B, A, C, sha256rnds2);
+  GO3(C, B, A, sha256rnds2);
+
+  return 0;
+}