]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/erasure_code/gf_vect_mul_sse_test.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / isa-l / erasure_code / gf_vect_mul_sse_test.c
1 /**********************************************************************
2 Copyright(c) 2011-2015 Intel Corporation All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
12 distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include "erasure_code.h"
33
34 #define TEST_SIZE (128*1024)
35
36 typedef unsigned char u8;
37
38 int main(int argc, char *argv[])
39 {
40 int i;
41 u8 *buff1, *buff2, *buff3, gf_const_tbl[64], a = 2;
42 int tsize;
43 int align, size;
44 unsigned char *efence_buff1;
45 unsigned char *efence_buff2;
46 unsigned char *efence_buff3;
47
48 printf("gf_vect_mul_sse_test: ");
49
50 gf_vect_mul_init(a, gf_const_tbl);
51
52 buff1 = (u8 *) malloc(TEST_SIZE);
53 buff2 = (u8 *) malloc(TEST_SIZE);
54 buff3 = (u8 *) malloc(TEST_SIZE);
55
56 if (NULL == buff1 || NULL == buff2 || NULL == buff3) {
57 printf("buffer alloc error\n");
58 return -1;
59 }
60 // Fill with rand data
61 for (i = 0; i < TEST_SIZE; i++)
62 buff1[i] = rand();
63
64 gf_vect_mul_sse(TEST_SIZE, gf_const_tbl, buff1, buff2);
65
66 for (i = 0; i < TEST_SIZE; i++) {
67 if (gf_mul(a, buff1[i]) != buff2[i]) {
68 printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n", i,
69 buff1[i], buff2[i], gf_mul(2, buff1[i]));
70 return -1;
71 }
72 }
73
74 gf_vect_mul_base(TEST_SIZE, gf_const_tbl, buff1, buff3);
75
76 // Check reference function
77 for (i = 0; i < TEST_SIZE; i++) {
78 if (buff2[i] != buff3[i]) {
79 printf("fail at %d, 0x%x x 0x%d = 0x%x (0x%x)\n",
80 i, a, buff1[i], buff2[i], gf_mul(a, buff1[i]));
81 return -1;
82 }
83 }
84
85 for (i = 0; i < TEST_SIZE; i++)
86 buff1[i] = rand();
87
88 // Check each possible constant
89 for (a = 0; a != 255; a++) {
90 gf_vect_mul_init(a, gf_const_tbl);
91 gf_vect_mul_sse(TEST_SIZE, gf_const_tbl, buff1, buff2);
92
93 for (i = 0; i < TEST_SIZE; i++)
94 if (gf_mul(a, buff1[i]) != buff2[i]) {
95 printf("fail at %d, 0x%x x %d = 0x%x (0x%x)\n",
96 i, a, buff1[i], buff2[i], gf_mul(2, buff1[i]));
97 return -1;
98 }
99 putchar('.');
100 }
101
102 // Check buffer len
103 for (tsize = TEST_SIZE; tsize > 0; tsize -= 32) {
104 a = rand();
105 gf_vect_mul_init(a, gf_const_tbl);
106 gf_vect_mul_sse(tsize, gf_const_tbl, buff1, buff2);
107
108 for (i = 0; i < tsize; i++)
109 if (gf_mul(a, buff1[i]) != buff2[i]) {
110 printf("fail at %d, 0x%x x %d = 0x%x (0x%x)\n",
111 i, a, buff1[i], buff2[i], gf_mul(2, buff1[i]));
112 return -1;
113 }
114 if (0 == tsize % (32 * 8)) {
115 putchar('.');
116 fflush(0);
117 }
118 }
119
120 // Run tests at end of buffer for Electric Fence
121 align = 32;
122 a = 2;
123
124 gf_vect_mul_init(a, gf_const_tbl);
125 for (size = 0; size < TEST_SIZE; size += align) {
126 // Line up TEST_SIZE from end
127 efence_buff1 = buff1 + size;
128 efence_buff2 = buff2 + size;
129 efence_buff3 = buff3 + size;
130
131 gf_vect_mul_sse(TEST_SIZE - size, gf_const_tbl, efence_buff1, efence_buff2);
132
133 for (i = 0; i < TEST_SIZE - size; i++)
134 if (gf_mul(a, efence_buff1[i]) != efence_buff2[i]) {
135 printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n",
136 i, efence_buff1[i], efence_buff2[i], gf_mul(2,
137 efence_buff1
138 [i]));
139 return 1;
140 }
141
142 gf_vect_mul_base(TEST_SIZE - size, gf_const_tbl, efence_buff1, efence_buff3);
143
144 // Check reference function
145 for (i = 0; i < TEST_SIZE - size; i++)
146 if (efence_buff2[i] != efence_buff3[i]) {
147 printf("fail at %d, 0x%x x 0x%d = 0x%x (0x%x)\n",
148 i, a, efence_buff2[i], efence_buff3[i], gf_mul(2,
149 efence_buff1
150 [i]));
151 return 1;
152 }
153
154 putchar('.');
155 }
156
157 printf(" done: Pass\n");
158 fflush(0);
159 return 0;
160 }