Debian Codegraph @

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

raw
1 #include <stdint.h>
2 #include <stddef.h>
3 #include <string.h>
4
5 #include "libbase64.h"
6 #include "../../tables/tables.h"
7 #include "../../codecs.h"
8 #include "config.h"
9 #include "../../env.h"
10
11 #if HAVE_NEON64
12 #include <arm_neon.h>
13
14 // Only enable inline assembly on supported compilers.
15 #if !defined(__wasm__) && (defined(__GNUC__) || defined(__clang__))
16 #define BASE64_NEON64_USE_ASM
17 #endif
18
19 static BASE64_FORCE_INLINE uint8x16x4_t
20 load_64byte_table (const uint8_t *p)
21 {
22 #ifdef BASE64_NEON64_USE_ASM
23
24 // Force the table to be loaded into contiguous registers. GCC will not
25 // normally allocate contiguous registers for a `uint8x16x4_t'. These
26 // registers are chosen to not conflict with the ones in the enc loop.
27 register uint8x16_t t0 __asm__ ("v8");
28 register uint8x16_t t1 __asm__ ("v9");
29 register uint8x16_t t2 __asm__ ("v10");
30 register uint8x16_t t3 __asm__ ("v11");
31
32 __asm__ (
33 "ld1 {%[t0].16b, %[t1].16b, %[t2].16b, %[t3].16b}, [%[src]], #64 \n\t"
34 : [src] "+r" (p),
35 [t0] "=w" (t0),
36 [t1] "=w" (t1),
37 [t2] "=w" (t2),
38 [t3] "=w" (t3)
39 );
40
41 return (uint8x16x4_t) {
42 .val[0] = t0,
43 .val[1] = t1,
44 .val[2] = t2,
45 .val[3] = t3,
46 };
47 #else
48 return vld1q_u8_x4(p);
49 #endif
50 }
51
52 #include "../generic/32/dec_loop.c"
53 #include "../generic/64/enc_loop.c"
54 #include "dec_loop.c"
55
56 #ifdef BASE64_NEON64_USE_ASM
57 # include "enc_loop_asm.c"
58 #else
59 # include "enc_reshuffle.c"
60 # include "enc_loop.c"
61 #endif
62
63 #endif // HAVE_NEON64
64
65 // Stride size is so large on these NEON 64-bit functions
66 // (48 bytes encode, 64 bytes decode) that we inline the
67 // uint64 codec to stay performant on smaller inputs.
68
69 void
70 base64_stream_encode_neon64 BASE64_ENC_PARAMS
71 {
72 #if HAVE_NEON64
73 #include "../generic/enc_head.c"
74 enc_loop_neon64(&s, &slen, &o, &olen);
75 enc_loop_generic_64(&s, &slen, &o, &olen);
76 #include "../generic/enc_tail.c"
77 #else
78 base64_enc_stub(state, src, srclen, out, outlen);
79 #endif
80 }
81
82 int
83 base64_stream_decode_neon64 BASE64_DEC_PARAMS
84 {
85 #if HAVE_NEON64
86 #include "../generic/dec_head.c"
87 dec_loop_neon64(&s, &slen, &o, &olen);
88 dec_loop_generic_32(&s, &slen, &o, &olen);
89 #include "../generic/dec_tail.c"
90 #else
91 return base64_dec_stub(state, src, srclen, out, outlen);
92 #endif
93 }