1/*
2 * Copyright (c) 2015-2016, Intel Corporation
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * * Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Intel Corporation nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** \file
30 * \brief Multibit: lookup tables and support code.
31 *
32 * This C file contains the constant tables used by multibit, so we don't end
33 * up creating copies of them for every unit that uses it.
34 */
35
36#include "multibit.h"
37#include "ue2common.h"
38
39const u8 mmbit_keyshift_lut[32] = {
40 30, 30, 24, 24, 24, 24, 24, 24, 18, 18, 18,
41 18, 18, 18, 12, 12, 12, 12, 12, 12, 6, 6,
42 6, 6, 6, 6, 0, 0, 0, 0, 0, 0
43};
44
45// The only actually valid values of ks are as shown in the LUT above, but a
46// division is just too expensive.
47const u8 mmbit_maxlevel_from_keyshift_lut[32] = {
48 0, 0, 0, 0, 0, 0,
49 1, 1, 1, 1, 1, 1,
50 2, 2, 2, 2, 2, 2,
51 3, 3, 3, 3, 3, 3,
52 4, 4, 4, 4, 4, 4,
53 5, 5
54};
55
56const u8 mmbit_maxlevel_direct_lut[32] = {
57 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3,
58 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1,
59 1, 1, 1, 1, 0, 0, 0, 0, 0, 0
60};
61
62#define ZERO_TO_LUT(x) ((1ULL << x) - 1)
63
64const u64a mmbit_zero_to_lut[65] = {
65 ZERO_TO_LUT(0),
66 ZERO_TO_LUT(1),
67 ZERO_TO_LUT(2),
68 ZERO_TO_LUT(3),
69 ZERO_TO_LUT(4),
70 ZERO_TO_LUT(5),
71 ZERO_TO_LUT(6),
72 ZERO_TO_LUT(7),
73 ZERO_TO_LUT(8),
74 ZERO_TO_LUT(9),
75 ZERO_TO_LUT(10),
76 ZERO_TO_LUT(11),
77 ZERO_TO_LUT(12),
78 ZERO_TO_LUT(13),
79 ZERO_TO_LUT(14),
80 ZERO_TO_LUT(15),
81 ZERO_TO_LUT(16),
82 ZERO_TO_LUT(17),
83 ZERO_TO_LUT(18),
84 ZERO_TO_LUT(19),
85 ZERO_TO_LUT(20),
86 ZERO_TO_LUT(21),
87 ZERO_TO_LUT(22),
88 ZERO_TO_LUT(23),
89 ZERO_TO_LUT(24),
90 ZERO_TO_LUT(25),
91 ZERO_TO_LUT(26),
92 ZERO_TO_LUT(27),
93 ZERO_TO_LUT(28),
94 ZERO_TO_LUT(29),
95 ZERO_TO_LUT(30),
96 ZERO_TO_LUT(31),
97 ZERO_TO_LUT(32),
98 ZERO_TO_LUT(33),
99 ZERO_TO_LUT(34),
100 ZERO_TO_LUT(35),
101 ZERO_TO_LUT(36),
102 ZERO_TO_LUT(37),
103 ZERO_TO_LUT(38),
104 ZERO_TO_LUT(39),
105 ZERO_TO_LUT(40),
106 ZERO_TO_LUT(41),
107 ZERO_TO_LUT(42),
108 ZERO_TO_LUT(43),
109 ZERO_TO_LUT(44),
110 ZERO_TO_LUT(45),
111 ZERO_TO_LUT(46),
112 ZERO_TO_LUT(47),
113 ZERO_TO_LUT(48),
114 ZERO_TO_LUT(49),
115 ZERO_TO_LUT(50),
116 ZERO_TO_LUT(51),
117 ZERO_TO_LUT(52),
118 ZERO_TO_LUT(53),
119 ZERO_TO_LUT(54),
120 ZERO_TO_LUT(55),
121 ZERO_TO_LUT(56),
122 ZERO_TO_LUT(57),
123 ZERO_TO_LUT(58),
124 ZERO_TO_LUT(59),
125 ZERO_TO_LUT(60),
126 ZERO_TO_LUT(61),
127 ZERO_TO_LUT(62),
128 ZERO_TO_LUT(63),
129 ~0ULL
130};
131
132const u32 mmbit_root_offset_from_level[7] = {
133 0,
134 1,
135 1 + (1 << MMB_KEY_SHIFT),
136 1 + (1 << MMB_KEY_SHIFT) + (1 << MMB_KEY_SHIFT * 2),
137 1 + (1 << MMB_KEY_SHIFT) + (1 << MMB_KEY_SHIFT * 2) + (1 << MMB_KEY_SHIFT * 3),
138 1 + (1 << MMB_KEY_SHIFT) + (1 << MMB_KEY_SHIFT * 2) + (1 << MMB_KEY_SHIFT * 3) + (1 << MMB_KEY_SHIFT * 4),
139 1 + (1 << MMB_KEY_SHIFT) + (1 << MMB_KEY_SHIFT * 2) + (1 << MMB_KEY_SHIFT * 3) + (1 << MMB_KEY_SHIFT * 4) + (1 << MMB_KEY_SHIFT * 5),
140};
141