Debian Codegraph @

mypyc/lib-rt/base64/arch/neon64/enc_loop.c

raw
1 static BASE64_FORCE_INLINE void
2 enc_loop_neon64_inner (const uint8_t **s, uint8_t **o, const uint8x16x4_t tbl_enc)
3 {
4 // Load 48 bytes and deinterleave:
5 uint8x16x3_t src = vld3q_u8(*s);
6
7 // Divide bits of three input bytes over four output bytes:
8 uint8x16x4_t out = enc_reshuffle(src);
9
10 // The bits have now been shifted to the right locations;
11 // translate their values 0..63 to the Base64 alphabet.
12 // Use a 64-byte table lookup:
13 out.val[0] = vqtbl4q_u8(tbl_enc, out.val[0]);
14 out.val[1] = vqtbl4q_u8(tbl_enc, out.val[1]);
15 out.val[2] = vqtbl4q_u8(tbl_enc, out.val[2]);
16 out.val[3] = vqtbl4q_u8(tbl_enc, out.val[3]);
17
18 // Interleave and store output:
19 vst4q_u8(*o, out);
20
21 *s += 48;
22 *o += 64;
23 }
24
25 static inline void
26 enc_loop_neon64 (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen)
27 {
28 size_t rounds = *slen / 48;
29
30 *slen -= rounds * 48; // 48 bytes consumed per round
31 *olen += rounds * 64; // 64 bytes produced per round
32
33 // Load the encoding table:
34 const uint8x16x4_t tbl_enc = load_64byte_table(base64_table_enc_6bit);
35
36 while (rounds > 0) {
37 if (rounds >= 8) {
38 enc_loop_neon64_inner(s, o, tbl_enc);
39 enc_loop_neon64_inner(s, o, tbl_enc);
40 enc_loop_neon64_inner(s, o, tbl_enc);
41 enc_loop_neon64_inner(s, o, tbl_enc);
42 enc_loop_neon64_inner(s, o, tbl_enc);
43 enc_loop_neon64_inner(s, o, tbl_enc);
44 enc_loop_neon64_inner(s, o, tbl_enc);
45 enc_loop_neon64_inner(s, o, tbl_enc);
46 rounds -= 8;
47 continue;
48 }
49 if (rounds >= 4) {
50 enc_loop_neon64_inner(s, o, tbl_enc);
51 enc_loop_neon64_inner(s, o, tbl_enc);
52 enc_loop_neon64_inner(s, o, tbl_enc);
53 enc_loop_neon64_inner(s, o, tbl_enc);
54 rounds -= 4;
55 continue;
56 }
57 if (rounds >= 2) {
58 enc_loop_neon64_inner(s, o, tbl_enc);
59 enc_loop_neon64_inner(s, o, tbl_enc);
60 rounds -= 2;
61 continue;
62 }
63 enc_loop_neon64_inner(s, o, tbl_enc);
64 break;
65 }
66 }