]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/isa-l/erasure_code/gf_vect_dot_prod_1tbl.c
1 /**********************************************************************
2 Copyright(c) 2011-2015 Intel Corporation All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
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
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.
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 **********************************************************************/
32 #include <string.h> // for memset, memcmp
34 #include "erasure_code.h"
38 // Cached test, loop many times over small dataset
39 # define TEST_SOURCES 10
40 # define TEST_LEN 8*1024
41 # define TEST_TYPE_STR "_warm"
44 // Uncached test. Pull from large mem base.
45 # define TEST_SOURCES 10
46 # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
47 # define TEST_LEN GT_L3_CACHE / TEST_SOURCES
48 # define TEST_TYPE_STR "_cold"
50 # define TEST_TYPE_STR "_cus"
54 typedef unsigned char u8
;
56 // Global GF(256) tables
59 u8 gf_mul_table
[256 * 256];
61 void mk_gf_field(void)
67 for (i
= 0; i
< 256; i
++) {
70 s
= (s
<< 1) ^ ((s
& 0x80) ? 0x1d : 0); // mult by GF{2}
74 void mk_gf_mul_table(u8
* table
)
76 // Populate a single table with all multiply combinations for a fast,
77 // single-table lookup of GF(2^8) multiply at the expense of memory.
79 for (i
= 0; i
< 256; i
++)
80 for (j
= 0; j
< 256; j
++)
81 table
[i
* 256 + j
] = gf_mul(i
, j
);
84 void gf_vect_dot_prod_ref(int len
, int vlen
, u8
* v
, u8
** src
, u8
* dest
)
88 for (i
= 0; i
< len
; i
++) {
90 for (j
= 0; j
< vlen
; j
++)
91 s
^= gf_mul(src
[j
][i
], v
[j
]);
97 void gf_vect_dot_prod_mult(int len
, int vlen
, u8
* v
, u8
** src
, u8
* dest
)
101 for (i
= 0; i
< len
; i
++) {
103 for (j
= 0; j
< vlen
; j
++) {
104 s
^= gf_mul_table
[v
[j
] * 256 + src
[j
][i
]];
114 u8 vec
[TEST_SOURCES
], dest1
[TEST_LEN
], dest2
[TEST_LEN
];
115 u8
*matrix
[TEST_SOURCES
];
119 mk_gf_mul_table(gf_mul_table
);
121 //generate random vector and matrix/data
122 for (i
= 0; i
< TEST_SOURCES
; i
++) {
125 if (!(matrix
[i
] = malloc(TEST_LEN
))) {
126 fprintf(stderr
, "Error failure\n\n");
129 for (j
= 0; j
< TEST_LEN
; j
++)
130 matrix
[i
][j
] = rand();
134 BENCHMARK(&start
, BENCHMARK_TIME
,
135 gf_vect_dot_prod_ref(TEST_LEN
, TEST_SOURCES
, vec
, matrix
, dest1
));
136 printf("gf_vect_dot_prod_2tbl" TEST_TYPE_STR
": ");
137 perf_print(start
, (long long)TEST_LEN
* (TEST_SOURCES
+ 1));
139 BENCHMARK(&start
, BENCHMARK_TIME
,
140 gf_vect_dot_prod_mult(TEST_LEN
, TEST_SOURCES
, vec
, matrix
, dest2
));
141 printf("gf_vect_dot_prod_1tbl" TEST_TYPE_STR
": ");
142 perf_print(start
, (long long)TEST_LEN
* (TEST_SOURCES
+ 1));
144 // Compare with reference function
145 if (0 != memcmp(dest1
, dest2
, TEST_LEN
)) {
146 printf("Error, different results!\n\n");
150 printf("Pass functional test\n");