-
Notifications
You must be signed in to change notification settings - Fork 477
/
Copy pathblock_class.c
369 lines (359 loc) · 11.4 KB
/
block_class.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*
* This file is part of the Minecraft Overviewer.
*
* Minecraft Overviewer is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Minecraft Overviewer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "block_class.h"
#include "utils.h"
#if defined(__i386__) || defined(__x86_64__)
#include <immintrin.h>
#endif
#if defined(__aarch64__)
#include <arm_neon.h>
#endif
bool block_class_is_subset(
mc_block_t block,
const mc_block_t block_class[],
size_t block_class_len) {
size_t i = 0;
#if defined(__AVX512F__) && defined(__AVX512BW__)
for (; i / 32 < block_class_len / 32; i += 32) {
const __m512i block_class_vec = _mm512_loadu_si512(
(__m512i*)&block_class[i]);
const __m512i block_vec = _mm512_set1_epi16(block);
const __mmask32 block_cmp = _mm512_cmpeq_epi16_mask(block_vec, block_class_vec);
if (block_cmp) {
return true;
}
}
#endif
#if defined(__AVX2__)
for (; i / 16 < block_class_len / 16; i += 16) {
const __m256i block_class_vec = _mm256_loadu_si256(
(__m256i*)&block_class[i]);
const __m256i block_vec = _mm256_set1_epi16(block);
const __m256i block_cmp = _mm256_cmpeq_epi16(block_vec, block_class_vec);
if (_mm256_movemask_epi8(block_cmp)) {
return true;
}
}
#endif
#ifdef __SSE2__
for (; i / 8 < block_class_len / 8; i += 8) {
const __m128i block_class_vec = _mm_loadu_si128(
(__m128i*)&block_class[i]);
const __m128i block_vec = _mm_set1_epi16(block);
const __m128i block_cmp = _mm_cmpeq_epi16(block_vec, block_class_vec);
if (_mm_movemask_epi8(block_cmp)) {
return true;
}
}
#endif
#if defined(__aarch64__)
for (; i / 8 < block_class_len / 8; i += 8) {
const uint16x8_t block_class_vec = vld1q_u16(
(uint16_t*)&block_class[i]);
const uint16x8_t block_vec = vmovq_n_u16(block);
const uint16x8_t block_cmp = vceqq_u16(block_vec, (uint16x8_t) block_class_vec);
if(vgetq_lane_s64((int64x2_t) block_cmp, 0) +
vgetq_lane_s64((int64x2_t) block_cmp, 1)) {
return true;
}
}
#endif
#ifdef __MMX__
for (; i / 4 < block_class_len / 4; i += 4) {
const __m64 block_class_vec = _mm_cvtsi64_m64(
*(uint64_t*)&block_class[i]);
const __m64 block_vec = _mm_set1_pi16(block);
const __m64 block_cmp = _mm_cmpeq_pi16(block_vec, block_class_vec);
if (_mm_cvtm64_si64(block_cmp)) {
return true;
}
}
#endif
for (; i < block_class_len; ++i) {
if (block == block_class[i]) {
return true;
}
}
return false;
}
bool block_class_is_wall(mc_block_t block) {
mc_block_t mask = 0b11111111;
mc_block_t prefix = 0b111 << 8; // 1792 is the starting offset
// if the xor zeroes all bits, the prefix must've matched.
return ((block & ~mask) ^ prefix) == 0;
}
const mc_block_t block_class_stair[] = {
block_oak_stairs,
block_brick_stairs,
block_stone_brick_stairs,
block_nether_brick_stairs,
block_sandstone_stairs,
block_spruce_stairs,
block_birch_stairs,
block_jungle_stairs,
block_crimson_stairs,
block_warped_stairs,
block_quartz_stairs,
block_acacia_stairs,
block_dark_oak_stairs,
block_red_sandstone_stairs,
block_smooth_red_sandstone_stairs,
block_purpur_stairs,
block_prismarine_stairs,
block_dark_prismarine_stairs,
block_prismarine_brick_stairs,
block_mossy_cobblestone_stairs,
block_cobblestone_stairs,
block_smooth_quartz_stairs,
block_polished_granite_stairs,
block_polished_diorite_stairs,
block_polished_andesite_stairs,
block_stone_stairs,
block_granite_stairs,
block_diorite_stairs,
block_andesite_stairs,
block_end_stone_brick_stairs,
block_red_nether_brick_stairs,
block_mossy_stone_brick_stairs,
block_smooth_sandstone_stairs,
block_blackstone_stairs,
block_polished_blackstone_stairs,
block_polished_blackstone_brick_stairs,
block_cut_copper_stairs,
block_exposed_cut_copper_stairs,
block_weathered_cut_copper_stairs,
block_oxidized_cut_copper_stairs,
block_waxed_cut_copper_stairs,
block_waxed_exposed_cut_copper_stairs,
block_waxed_weathered_cut_copper_stairs,
block_waxed_oxidized_cut_copper_stairs,
block_cobbled_deepslate_stairs,
block_polished_deepslate_stairs,
block_deepslate_brick_stairs,
block_deepslate_tile_stairs,
block_mangrove_stairs,
block_mud_brick_stairs};
const size_t block_class_stair_len = COUNT_OF(block_class_stair);
const mc_block_t block_class_door[] = {
block_wooden_door,
block_iron_door,
block_spruce_door,
block_birch_door,
block_jungle_door,
block_acacia_door,
block_dark_oak_door,
block_crimson_door,
block_mangrove_door,
block_warped_door};
const size_t block_class_door_len = COUNT_OF(block_class_door);
const mc_block_t block_class_ancil[] = {
block_wooden_door,
block_iron_door,
block_spruce_door,
block_birch_door,
block_jungle_door,
block_acacia_door,
block_dark_oak_door,
block_crimson_door,
block_mangrove_door,
block_oak_stairs,
block_brick_stairs,
block_stone_brick_stairs,
block_nether_brick_stairs,
block_sandstone_stairs,
block_spruce_stairs,
block_birch_stairs,
block_jungle_stairs,
block_quartz_stairs,
block_acacia_stairs,
block_dark_oak_stairs,
block_crimson_stairs,
block_warped_stairs,
block_red_sandstone_stairs,
block_smooth_red_sandstone_stairs,
block_purpur_stairs,
block_prismarine_stairs,
block_dark_prismarine_stairs,
block_prismarine_brick_stairs,
block_cobblestone_stairs,
block_mossy_cobblestone_stairs,
block_mossy_stone_brick_stairs,
block_smooth_quartz_stairs,
block_polished_granite_stairs,
block_polished_diorite_stairs,
block_polished_andesite_stairs,
block_stone_stairs,
block_granite_stairs,
block_diorite_stairs,
block_andesite_stairs,
block_end_stone_brick_stairs,
block_red_nether_brick_stairs,
block_smooth_sandstone_stairs,
block_blackstone_stairs,
block_polished_blackstone_stairs,
block_polished_blackstone_brick_stairs,
block_cut_copper_stairs,
block_exposed_cut_copper_stairs,
block_weathered_cut_copper_stairs,
block_oxidized_cut_copper_stairs,
block_waxed_cut_copper_stairs,
block_waxed_exposed_cut_copper_stairs,
block_waxed_weathered_cut_copper_stairs,
block_waxed_oxidized_cut_copper_stairs,
block_cobbled_deepslate_stairs,
block_polished_deepslate_stairs,
block_deepslate_brick_stairs,
block_deepslate_tile_stairs,
block_mangrove_stairs,
block_mud_brick_stairs,
block_grass,
block_flowing_water,
block_water,
block_glass,
block_redstone_wire,
block_ice,
block_portal,
block_waterlily,
block_andesite_wall,
block_brick_wall,
block_cobblestone_wall,
block_diorite_wall,
block_end_stone_brick_wall,
block_granite_wall,
block_mossy_cobblestone_wall,
block_mossy_stone_brick_wall,
block_nether_brick_wall,
block_prismarine_wall,
block_red_nether_brick_wall,
block_red_sandstone_wall,
block_sandstone_wall,
block_stone_brick_wall,
block_blackstone_wall,
block_polished_blackstone_wall,
block_polished_blackstone_brick_wall,
block_double_plant,
block_stained_glass,
block_cobbled_deepslate_wall,
block_polished_deepslate_wall,
block_deepslate_brick_wall,
block_deepslate_tile_wall,
block_mud_brick_wall};
const size_t block_class_ancil_len = COUNT_OF(block_class_ancil);
const mc_block_t block_class_alt_height[] = {
block_stone_slab,
block_oak_stairs,
block_brick_stairs,
block_stone_brick_stairs,
block_nether_brick_stairs,
block_sandstone_stairs,
block_spruce_stairs,
block_birch_stairs,
block_jungle_stairs,
block_quartz_stairs,
block_acacia_stairs,
block_dark_oak_stairs,
block_crimson_stairs,
block_warped_stairs,
block_red_sandstone_stairs,
block_smooth_red_sandstone_stairs,
block_prismarine_stairs,
block_dark_prismarine_stairs,
block_prismarine_brick_stairs,
block_cobblestone_stairs,
block_mossy_cobblestone_stairs,
block_mossy_stone_brick_stairs,
block_smooth_quartz_stairs,
block_polished_granite_stairs,
block_polished_diorite_stairs,
block_polished_andesite_stairs,
block_stone_stairs,
block_granite_stairs,
block_diorite_stairs,
block_andesite_stairs,
block_end_stone_brick_stairs,
block_red_nether_brick_stairs,
block_smooth_sandstone_stairs,
block_blackstone_stairs,
block_polished_blackstone_stairs,
block_polished_blackstone_brick_stairs,
block_mud_brick_stairs,
block_prismarine_slab,
block_dark_prismarine_slab,
block_prismarine_brick_slab,
block_andesite_slab,
block_diorite_slab,
block_granite_slab,
block_polished_andesite_slab,
block_polished_diorite_slab,
block_polished_granite_slab,
block_red_nether_brick_slab,
block_smooth_sandstone_slab,
block_cut_sandstone_slab,
block_smooth_red_sandstone_slab,
block_cut_red_sandstone_slab,
block_end_stone_brick_slab,
block_blackstone_slab,
block_polished_blackstone_slab,
block_polished_blackstone_brick_slab,
block_mossy_cobblestone_slab,
block_mossy_stone_brick_slab,
block_smooth_quartz_slab,
block_smooth_stone_slab,
block_stone_slab2,
block_purpur_stairs,
block_purpur_slab,
block_wooden_slab,
block_cut_copper_stairs,
block_exposed_cut_copper_stairs,
block_weathered_cut_copper_stairs,
block_oxidized_cut_copper_stairs,
block_waxed_cut_copper_stairs,
block_waxed_exposed_cut_copper_stairs,
block_waxed_weathered_cut_copper_stairs,
block_waxed_oxidized_cut_copper_stairs,
block_cut_copper_slab,
block_exposed_cut_copper_slab,
block_weathered_cut_copper_slab,
block_oxidized_cut_copper_slab,
block_waxed_cut_copper_slab,
block_waxed_exposed_cut_copper_slab,
block_waxed_weathered_cut_copper_slab,
block_waxed_oxidized_cut_copper_slab,
block_cobbled_deepslate_stairs,
block_polished_deepslate_stairs,
block_deepslate_brick_stairs,
block_deepslate_tile_stairs,
block_mangrove_stairs,
block_cobbled_deepslate_slab,
block_polished_deepslate_slab,
block_deepslate_brick_slab,
block_deepslate_tile_slab,
block_mud_brick_slab,
block_mangrove_slab};
const size_t block_class_alt_height_len = COUNT_OF(block_class_alt_height);
const mc_block_t block_class_nether_roof[] = {
block_bedrock,
block_netherrack,
block_quartz_ore,
block_lava,
block_soul_sand,
block_basalt,
block_blackstone,
block_soul_soil,
block_nether_gold_ore,
block_ancient_debris};
const size_t block_class_nether_roof_len = COUNT_OF(block_class_nether_roof);