-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoctmat.c
68 lines (56 loc) · 1.68 KB
/
octmat.c
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
#include "octmat.h"
#include "oblas.h"
#include <errno.h>
#define ALIGN_TO(k, a) (((k) / (a)) + (((k) % (a)) ? 1 : 0)) * (a)
octmat *octmat_new(unsigned rows, unsigned cols) {
octmat *m = calloc(1, sizeof(octmat));
m->rows = rows;
m->cols = cols;
m->stride = ALIGN_TO(cols, OCTMAT_ALIGN);
m->bits = oblas_alloc(rows, m->stride, OCTMAT_ALIGN);
oblas_zero(m->bits, rows * m->stride);
return m;
}
void octmat_free(octmat *m) {
if (m && m->bits)
oblas_free(m->bits);
if (m)
free(m);
}
void oswaprow(octmat *a, unsigned i, unsigned j) {
if (i == j)
return;
uint8_t *ap = a->bits + i * a->stride;
uint8_t *bp = a->bits + j * a->stride;
oblas_swap(ap, bp, a->stride);
}
void oaxpy(octmat *a, octmat *b, unsigned i, unsigned j, uint8_t u) {
uint8_t *ap = a->bits + i * a->stride;
uint8_t *bp = b->bits + j * b->stride;
if (u == 0)
return;
if (u == 1) {
oblas_xor(ap, bp, a->stride);
} else {
const uint8_t *urow_hi = GF2_8_SHUF_HI + (u * 16);
const uint8_t *urow_lo = GF2_8_SHUF_LO + (u * 16);
oblas_axpy(ap, bp, a->stride, urow_lo, urow_hi);
}
}
void oaddrow(octmat *a, octmat *b, unsigned i, unsigned j) {
uint8_t *ap = a->bits + i * a->stride;
uint8_t *bp = b->bits + j * b->stride;
oblas_xor(ap, bp, a->stride);
}
void oscal(octmat *a, unsigned i, uint8_t u) {
uint8_t *ap = a->bits + i * a->stride;
if (u < 2)
return;
const uint8_t *urow_lo = GF2_8_SHUF_LO + (u * 16);
const uint8_t *urow_hi = GF2_8_SHUF_HI + (u * 16);
oblas_scal(ap, a->stride, urow_lo, urow_hi);
}
void oaxpy_b32(octmat *a, uint32_t *b, unsigned i, uint8_t u) {
uint8_t *ap = a->bits + i * a->stride;
oblas_axpy_gf2_gf256_32(ap, b, a->stride, u);
}