Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
bsdec-vlc.h
Go to the documentation of this file.
1// GENERATED by bsdec/gentable.py - do not edit.
2//
3// Sony's standard MDEC AC code book (FileFormat47 Table 1-7), rearranged for a
4// count-leading-zeros dispatch. Every code in the book is N zeros, a marker 1, then a
5// suffix whose width depends only on N, so one clz plus one indexed load replaces the
6// bit-at-a-time walk down a trie.
7//
8// n codes code lengths suffix width
9// 0 3 [2, 3] 2
10// 1 6 [4, 5] 3
11// 2 22 [6, 9] 6
12// 3 8 [7] 3
13// 4 8 [8] 3
14// 5 1 [6] 0
15// 6 16 [11] 4
16// 7 32 [13] 5
17// 8 32 [14] 5
18// 9 32 [15] 5
19// 10 32 [16] 5
20// 11 32 [17] 5
21//
22// 224 symbols, 269 table slots, 0 unreachable (invalid prefixes).
23//
24// Entry layout, chosen so the common path is one load and one mask:
25// bits 0..15 the MDEC run-level halfword, ready to store (0xfe00 for EOB)
26// bits 16..20 suffix bits to consume after the marker 1
27// bits 21..22 kind: 0 normal, 1 end of block, 2 escape
28// bit 23 set on a valid entry; a zero word is an invalid prefix
29
30#pragma once
31
32#include <stdint.h>
33
34#define BSDEC_VLC_MAXNZ 11
35
36#define BSDEC_VLC_HALFWORD(e) ((uint16_t)((e) & 0xffff))
37#define BSDEC_VLC_SUFFIXBITS(e) (((e) >> 16) & 0x1f)
38#define BSDEC_VLC_KIND(e) (((e) >> 21) & 3)
39#define BSDEC_VLC_VALID(e) ((e) & (1 << 23))
40
41#define BSDEC_VLC_NORMAL 0
42#define BSDEC_VLC_EOB 1
43#define BSDEC_VLC_ESCAPE 2
44
45/* Rows past 11 are the garbage-prefix sentinel: width 0, pointing at
46 the appended EOB slot, so an impossible prefix needs no bounds test. */
47static const uint8_t c_bsdecVlcSuffixBits[32] = {2, 3, 6, 3, 3, 0, 4, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
48
49static const uint16_t c_bsdecVlcOffset[32] = {0, 4, 12, 76, 84, 92, 93, 109, 141, 173, 205, 237, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, 269};
50
51static const uint32_t c_bsdecVlc[270] = {
52 // n = 0, suffix 2 bits
53 0x00a1fe00, 0x00a1fe00, 0x00820001, 0x008203ff,
54 // n = 1, suffix 3 bits
55 0x00830002, 0x008303fe, 0x00830801, 0x00830bff, 0x00820401, 0x00820401, 0x008207ff, 0x008207ff,
56 // n = 2, suffix 6 bits
57 0x00863401, 0x008637ff, 0x00860006, 0x008603fa, 0x00863001, 0x008633ff, 0x00862c01, 0x00862fff, 0x00860c02,
58 0x00860ffe, 0x00860403, 0x008607fd, 0x00860005, 0x008603fb, 0x00862801, 0x00862bff, 0x00830003, 0x00830003,
59 0x00830003, 0x00830003, 0x00830003, 0x00830003, 0x00830003, 0x00830003, 0x008303fd, 0x008303fd, 0x008303fd,
60 0x008303fd, 0x008303fd, 0x008303fd, 0x008303fd, 0x008303fd, 0x00831001, 0x00831001, 0x00831001, 0x00831001,
61 0x00831001, 0x00831001, 0x00831001, 0x00831001, 0x008313ff, 0x008313ff, 0x008313ff, 0x008313ff, 0x008313ff,
62 0x008313ff, 0x008313ff, 0x008313ff, 0x00830c01, 0x00830c01, 0x00830c01, 0x00830c01, 0x00830c01, 0x00830c01,
63 0x00830c01, 0x00830c01, 0x00830fff, 0x00830fff, 0x00830fff, 0x00830fff, 0x00830fff, 0x00830fff, 0x00830fff,
64 0x00830fff,
65 // n = 3, suffix 3 bits
66 0x00831c01, 0x00831fff, 0x00831801, 0x00831bff, 0x00830402, 0x008307fe, 0x00831401, 0x008317ff,
67 // n = 4, suffix 3 bits
68 0x00830802, 0x00830bfe, 0x00832401, 0x008327ff, 0x00830004, 0x008303fc, 0x00832001, 0x008323ff,
69 // n = 5, suffix 0 bits
70 0x00c00000,
71 // n = 6, suffix 4 bits
72 0x00844001, 0x008443ff, 0x00841402, 0x008417fe, 0x00840007, 0x008403f9, 0x00840803, 0x00840bfd, 0x00840404,
73 0x008407fc, 0x00843c01, 0x00843fff, 0x00843801, 0x00843bff, 0x00841002, 0x008413fe,
74 // n = 7, suffix 5 bits
75 0x0085000b, 0x008503f5, 0x00852002, 0x008523fe, 0x00851003, 0x008513fd, 0x0085000a, 0x008503f6, 0x00850804,
76 0x00850bfc, 0x00851c02, 0x00851ffe, 0x00855401, 0x008557ff, 0x00855001, 0x008553ff, 0x00850009, 0x008503f7,
77 0x00854c01, 0x00854fff, 0x00854801, 0x00854bff, 0x00850405, 0x008507fb, 0x00850c03, 0x00850ffd, 0x00850008,
78 0x008503f8, 0x00851802, 0x00851bfe, 0x00854401, 0x008547ff,
79 // n = 8, suffix 5 bits
80 0x00852802, 0x00852bfe, 0x00852402, 0x008527fe, 0x00851403, 0x008517fd, 0x00850c04, 0x00850ffc, 0x00850805,
81 0x00850bfb, 0x00850407, 0x008507f9, 0x00850406, 0x008507fa, 0x0085000f, 0x008503f1, 0x0085000e, 0x008503f2,
82 0x0085000d, 0x008503f3, 0x0085000c, 0x008503f4, 0x00856801, 0x00856bff, 0x00856401, 0x008567ff, 0x00856001,
83 0x008563ff, 0x00855c01, 0x00855fff, 0x00855801, 0x00855bff,
84 // n = 9, suffix 5 bits
85 0x0085001f, 0x008503e1, 0x0085001e, 0x008503e2, 0x0085001d, 0x008503e3, 0x0085001c, 0x008503e4, 0x0085001b,
86 0x008503e5, 0x0085001a, 0x008503e6, 0x00850019, 0x008503e7, 0x00850018, 0x008503e8, 0x00850017, 0x008503e9,
87 0x00850016, 0x008503ea, 0x00850015, 0x008503eb, 0x00850014, 0x008503ec, 0x00850013, 0x008503ed, 0x00850012,
88 0x008503ee, 0x00850011, 0x008503ef, 0x00850010, 0x008503f0,
89 // n = 10, suffix 5 bits
90 0x00850028, 0x008503d8, 0x00850027, 0x008503d9, 0x00850026, 0x008503da, 0x00850025, 0x008503db, 0x00850024,
91 0x008503dc, 0x00850023, 0x008503dd, 0x00850022, 0x008503de, 0x00850021, 0x008503df, 0x00850020, 0x008503e0,
92 0x0085040e, 0x008507f2, 0x0085040d, 0x008507f3, 0x0085040c, 0x008507f4, 0x0085040b, 0x008507f5, 0x0085040a,
93 0x008507f6, 0x00850409, 0x008507f7, 0x00850408, 0x008507f8,
94 // n = 11, suffix 5 bits
95 0x00850412, 0x008507ee, 0x00850411, 0x008507ef, 0x00850410, 0x008507f0, 0x0085040f, 0x008507f1, 0x00851803,
96 0x00851bfd, 0x00854002, 0x008543fe, 0x00853c02, 0x00853ffe, 0x00853802, 0x00853bfe, 0x00853402, 0x008537fe,
97 0x00853002, 0x008533fe, 0x00852c02, 0x00852ffe, 0x00857c01, 0x00857fff, 0x00857801, 0x00857bff, 0x00857401,
98 0x008577ff, 0x00857001, 0x008573ff, 0x00856c01, 0x00856fff,
99 // sentinel: every prefix longer than the book ends the block here
100 0x00a0fe00,
101};
102
103// Version-3 delta-DC size books, indexed by size 0..8: MPEG-1's DC size codes
104// (ISO/IEC 11172-2 tables B-12 and B-13). Blocks 0 and 1 of a macroblock are Cr and
105// Cb and take the chroma book; blocks 2..5 are luma and share the other one. Both
106// are prefix-free, checked at generation time, so a linear walk resolves them
107// without caring about the order.
108static const uint8_t c_bsdecDcLumaCode[9] = {0x04, 0x00, 0x01, 0x05, 0x06, 0x0e, 0x1e, 0x3e, 0x7e};
109static const uint8_t c_bsdecDcLumaBits[9] = {3, 2, 2, 3, 3, 4, 5, 6, 7};
110static const uint8_t c_bsdecDcChromaCode[9] = {0x00, 0x01, 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0x7e, 0xfe};
111static const uint8_t c_bsdecDcChromaBits[9] = {2, 2, 2, 3, 4, 5, 6, 7, 8};
void uint32_t(classId, spec)