File: enc_loop.c

package info (click to toggle)
python-librt 0.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 920 kB
  • sloc: ansic: 13,889; python: 293; makefile: 6
file content (61 lines) | stat: -rw-r--r-- 1,506 bytes parent folder | download | duplicates (2)
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
static BASE64_FORCE_INLINE void
enc_loop_avx512_inner (const uint8_t **s, uint8_t **o)
{
	// Load input.
	__m512i src = _mm512_loadu_si512((__m512i *) *s);

	// Reshuffle, translate, store.
	src = enc_reshuffle_translate(src);
	_mm512_storeu_si512((__m512i *) *o, src);

	*s += 48;
	*o += 64;
}

static inline void
enc_loop_avx512 (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen)
{
	if (*slen < 64) {
		return;
	}

	// Process blocks of 48 bytes at a time. Because blocks are loaded 64
	// bytes at a time, ensure that there will be at least 24 remaining
	// bytes after the last round, so that the final read will not pass
	// beyond the bounds of the input buffer.
	size_t rounds = (*slen - 24) / 48;

	*slen -= rounds * 48;   // 48 bytes consumed per round
	*olen += rounds * 64;   // 64 bytes produced per round

	while (rounds > 0) {
		if (rounds >= 8) {
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			rounds -= 8;
			continue;
		}
		if (rounds >= 4) {
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			rounds -= 4;
			continue;
		}
		if (rounds >= 2) {
			enc_loop_avx512_inner(s, o);
			enc_loop_avx512_inner(s, o);
			rounds -= 2;
			continue;
		}
		enc_loop_avx512_inner(s, o);
		break;
	}
}