@sentryware/s2-node 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +45 -0
- package/.dockerignore +1 -0
- package/.gitmodules +3 -0
- package/CHANGELOG.md +33 -0
- package/LICENSE +201 -0
- package/README.md +147 -0
- package/binding.gyp +170 -0
- package/docker/Dockerfile.node20.test +8 -0
- package/docker/Dockerfile.node22.test +8 -0
- package/docker/Dockerfile.node24.test +8 -0
- package/index.d.ts +117 -0
- package/index.js +6 -0
- package/jest.config.js +184 -0
- package/package.json +43 -0
- package/publish-linux.sh +18 -0
- package/publish-osx.sh +19 -0
- package/src/builder.cc +84 -0
- package/src/builder.h +29 -0
- package/src/cell.cc +71 -0
- package/src/cell.h +26 -0
- package/src/cell_id.cc +210 -0
- package/src/cell_id.h +44 -0
- package/src/cell_union.cc +237 -0
- package/src/cell_union.h +34 -0
- package/src/earth.cc +185 -0
- package/src/earth.h +33 -0
- package/src/latlng.cc +132 -0
- package/src/latlng.h +28 -0
- package/src/loop.cc +51 -0
- package/src/loop.h +21 -0
- package/src/point.cc +69 -0
- package/src/point.h +23 -0
- package/src/polygon.cc +36 -0
- package/src/polygon.h +20 -0
- package/src/polyline.cc +186 -0
- package/src/polyline.h +34 -0
- package/src/region_coverer.cc +450 -0
- package/src/region_coverer.h +56 -0
- package/src/s2.cc +27 -0
- package/test/Cell.test.js +37 -0
- package/test/CellId.test.js +135 -0
- package/test/CellUnion.test.js +150 -0
- package/test/Earth.test.js +62 -0
- package/test/LatLng.test.js +45 -0
- package/test/Point.test.js +14 -0
- package/test/Polyline.test.js +78 -0
- package/test/RegionCoverer.test.js +301 -0
- package/test.sh +16 -0
- package/third_party/s2geometry/.travis.yml +163 -0
- package/third_party/s2geometry/AUTHORS +13 -0
- package/third_party/s2geometry/CONTRIBUTING.md +65 -0
- package/third_party/s2geometry/CONTRIBUTORS +30 -0
- package/third_party/s2geometry/LICENSE +202 -0
- package/third_party/s2geometry/NOTICE +5 -0
- package/third_party/s2geometry/README.md +127 -0
- package/third_party/s2geometry/doc/examples/point_index.cc +44 -0
- package/third_party/s2geometry/doc/examples/term_index.cc +99 -0
- package/third_party/s2geometry/doc/examples/term_index.py +101 -0
- package/third_party/s2geometry/src/python/coder.i +125 -0
- package/third_party/s2geometry/src/python/pywraps2_test.py +786 -0
- package/third_party/s2geometry/src/python/s2.i +37 -0
- package/third_party/s2geometry/src/python/s2_common.i +756 -0
- package/third_party/s2geometry/src/s2/_fp_contract_off.h +60 -0
- package/third_party/s2geometry/src/s2/base/casts.h +318 -0
- package/third_party/s2geometry/src/s2/base/commandlineflags.h +67 -0
- package/third_party/s2geometry/src/s2/base/integral_types.h +31 -0
- package/third_party/s2geometry/src/s2/base/log_severity.h +40 -0
- package/third_party/s2geometry/src/s2/base/logging.h +173 -0
- package/third_party/s2geometry/src/s2/base/mutex.h +61 -0
- package/third_party/s2geometry/src/s2/base/port.h +999 -0
- package/third_party/s2geometry/src/s2/base/spinlock.h +60 -0
- package/third_party/s2geometry/src/s2/base/stringprintf.cc +107 -0
- package/third_party/s2geometry/src/s2/base/stringprintf.h +53 -0
- package/third_party/s2geometry/src/s2/base/strtoint.cc +65 -0
- package/third_party/s2geometry/src/s2/base/strtoint.h +106 -0
- package/third_party/s2geometry/src/s2/base/timer.h +50 -0
- package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector.cc +164 -0
- package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector.h +110 -0
- package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector_test.cc +232 -0
- package/third_party/s2geometry/src/s2/encoded_s2point_vector.cc +838 -0
- package/third_party/s2geometry/src/s2/encoded_s2point_vector.h +140 -0
- package/third_party/s2geometry/src/s2/encoded_s2point_vector_test.cc +344 -0
- package/third_party/s2geometry/src/s2/encoded_s2shape_index.cc +181 -0
- package/third_party/s2geometry/src/s2/encoded_s2shape_index.h +276 -0
- package/third_party/s2geometry/src/s2/encoded_s2shape_index_test.cc +244 -0
- package/third_party/s2geometry/src/s2/encoded_string_vector.cc +66 -0
- package/third_party/s2geometry/src/s2/encoded_string_vector.h +164 -0
- package/third_party/s2geometry/src/s2/encoded_string_vector_test.cc +69 -0
- package/third_party/s2geometry/src/s2/encoded_uint_vector.h +299 -0
- package/third_party/s2geometry/src/s2/encoded_uint_vector_test.cc +124 -0
- package/third_party/s2geometry/src/s2/id_set_lexicon.cc +81 -0
- package/third_party/s2geometry/src/s2/id_set_lexicon.h +199 -0
- package/third_party/s2geometry/src/s2/id_set_lexicon_test.cc +70 -0
- package/third_party/s2geometry/src/s2/mutable_s2shape_index.cc +1585 -0
- package/third_party/s2geometry/src/s2/mutable_s2shape_index.h +600 -0
- package/third_party/s2geometry/src/s2/mutable_s2shape_index_test.cc +589 -0
- package/third_party/s2geometry/src/s2/r1interval.h +220 -0
- package/third_party/s2geometry/src/s2/r1interval_test.cc +185 -0
- package/third_party/s2geometry/src/s2/r2.h +26 -0
- package/third_party/s2geometry/src/s2/r2rect.cc +93 -0
- package/third_party/s2geometry/src/s2/r2rect.h +234 -0
- package/third_party/s2geometry/src/s2/r2rect_test.cc +228 -0
- package/third_party/s2geometry/src/s2/s1angle.cc +54 -0
- package/third_party/s2geometry/src/s2/s1angle.h +336 -0
- package/third_party/s2geometry/src/s2/s1angle_test.cc +185 -0
- package/third_party/s2geometry/src/s2/s1chord_angle.cc +159 -0
- package/third_party/s2geometry/src/s2/s1chord_angle.h +369 -0
- package/third_party/s2geometry/src/s2/s1chord_angle_test.cc +207 -0
- package/third_party/s2geometry/src/s2/s1interval.cc +296 -0
- package/third_party/s2geometry/src/s2/s1interval.h +266 -0
- package/third_party/s2geometry/src/s2/s1interval_test.cc +469 -0
- package/third_party/s2geometry/src/s2/s2boolean_operation.cc +2391 -0
- package/third_party/s2geometry/src/s2/s2boolean_operation.h +501 -0
- package/third_party/s2geometry/src/s2/s2boolean_operation_test.cc +1400 -0
- package/third_party/s2geometry/src/s2/s2builder.cc +1828 -0
- package/third_party/s2geometry/src/s2/s2builder.h +1057 -0
- package/third_party/s2geometry/src/s2/s2builder_graph.cc +1084 -0
- package/third_party/s2geometry/src/s2/s2builder_graph.h +799 -0
- package/third_party/s2geometry/src/s2/s2builder_graph_test.cc +462 -0
- package/third_party/s2geometry/src/s2/s2builder_layer.h +50 -0
- package/third_party/s2geometry/src/s2/s2builder_test.cc +1329 -0
- package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer.cc +313 -0
- package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer.h +221 -0
- package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer_test.cc +261 -0
- package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies.cc +392 -0
- package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies.h +86 -0
- package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies_test.cc +182 -0
- package/third_party/s2geometry/src/s2/s2builderutil_graph_shape.h +57 -0
- package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer.cc +212 -0
- package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer.h +218 -0
- package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer_test.cc +367 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer.cc +74 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer.h +122 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer_test.cc +167 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer.cc +191 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer.h +211 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer_test.cc +312 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer.cc +105 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer.h +174 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer_test.cc +220 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer.cc +98 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer.h +292 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer_test.cc +233 -0
- package/third_party/s2geometry/src/s2/s2builderutil_snap_functions.cc +354 -0
- package/third_party/s2geometry/src/s2/s2builderutil_snap_functions.h +239 -0
- package/third_party/s2geometry/src/s2/s2builderutil_snap_functions_test.cc +716 -0
- package/third_party/s2geometry/src/s2/s2builderutil_testing.cc +37 -0
- package/third_party/s2geometry/src/s2/s2builderutil_testing.h +100 -0
- package/third_party/s2geometry/src/s2/s2builderutil_testing_test.cc +85 -0
- package/third_party/s2geometry/src/s2/s2cap.cc +347 -0
- package/third_party/s2geometry/src/s2/s2cap.h +286 -0
- package/third_party/s2geometry/src/s2/s2cap_test.cc +379 -0
- package/third_party/s2geometry/src/s2/s2cell.cc +552 -0
- package/third_party/s2geometry/src/s2/s2cell.h +249 -0
- package/third_party/s2geometry/src/s2/s2cell_id.cc +619 -0
- package/third_party/s2geometry/src/s2/s2cell_id.h +705 -0
- package/third_party/s2geometry/src/s2/s2cell_id_test.cc +633 -0
- package/third_party/s2geometry/src/s2/s2cell_index.cc +149 -0
- package/third_party/s2geometry/src/s2/s2cell_index.h +660 -0
- package/third_party/s2geometry/src/s2/s2cell_index_test.cc +411 -0
- package/third_party/s2geometry/src/s2/s2cell_test.cc +687 -0
- package/third_party/s2geometry/src/s2/s2cell_union.cc +515 -0
- package/third_party/s2geometry/src/s2/s2cell_union.h +399 -0
- package/third_party/s2geometry/src/s2/s2cell_union_test.cc +598 -0
- package/third_party/s2geometry/src/s2/s2centroids.cc +84 -0
- package/third_party/s2geometry/src/s2/s2centroids.h +87 -0
- package/third_party/s2geometry/src/s2/s2centroids_test.cc +82 -0
- package/third_party/s2geometry/src/s2/s2closest_cell_query.cc +123 -0
- package/third_party/s2geometry/src/s2/s2closest_cell_query.h +385 -0
- package/third_party/s2geometry/src/s2/s2closest_cell_query_base.h +841 -0
- package/third_party/s2geometry/src/s2/s2closest_cell_query_base_test.cc +63 -0
- package/third_party/s2geometry/src/s2/s2closest_cell_query_test.cc +412 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query.cc +106 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query.h +421 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query_base.h +946 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query_base_test.cc +59 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query_test.cc +505 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query_testing.h +91 -0
- package/third_party/s2geometry/src/s2/s2closest_point_query.cc +66 -0
- package/third_party/s2geometry/src/s2/s2closest_point_query.h +465 -0
- package/third_party/s2geometry/src/s2/s2closest_point_query_base.h +767 -0
- package/third_party/s2geometry/src/s2/s2closest_point_query_base_test.cc +63 -0
- package/third_party/s2geometry/src/s2/s2closest_point_query_test.cc +312 -0
- package/third_party/s2geometry/src/s2/s2contains_point_query.h +328 -0
- package/third_party/s2geometry/src/s2/s2contains_point_query_test.cc +159 -0
- package/third_party/s2geometry/src/s2/s2contains_vertex_query.cc +39 -0
- package/third_party/s2geometry/src/s2/s2contains_vertex_query.h +66 -0
- package/third_party/s2geometry/src/s2/s2contains_vertex_query_test.cc +67 -0
- package/third_party/s2geometry/src/s2/s2convex_hull_query.cc +198 -0
- package/third_party/s2geometry/src/s2/s2convex_hull_query.h +110 -0
- package/third_party/s2geometry/src/s2/s2convex_hull_query_test.cc +208 -0
- package/third_party/s2geometry/src/s2/s2coords.cc +146 -0
- package/third_party/s2geometry/src/s2/s2coords.h +459 -0
- package/third_party/s2geometry/src/s2/s2coords_internal.h +71 -0
- package/third_party/s2geometry/src/s2/s2coords_test.cc +218 -0
- package/third_party/s2geometry/src/s2/s2crossing_edge_query.cc +380 -0
- package/third_party/s2geometry/src/s2/s2crossing_edge_query.h +220 -0
- package/third_party/s2geometry/src/s2/s2crossing_edge_query_test.cc +382 -0
- package/third_party/s2geometry/src/s2/s2debug.cc +23 -0
- package/third_party/s2geometry/src/s2/s2debug.h +69 -0
- package/third_party/s2geometry/src/s2/s2distance_target.h +165 -0
- package/third_party/s2geometry/src/s2/s2earth.cc +52 -0
- package/third_party/s2geometry/src/s2/s2earth.h +268 -0
- package/third_party/s2geometry/src/s2/s2earth_test.cc +146 -0
- package/third_party/s2geometry/src/s2/s2edge_clipping.cc +462 -0
- package/third_party/s2geometry/src/s2/s2edge_clipping.h +183 -0
- package/third_party/s2geometry/src/s2/s2edge_clipping_test.cc +335 -0
- package/third_party/s2geometry/src/s2/s2edge_crosser.cc +85 -0
- package/third_party/s2geometry/src/s2/s2edge_crosser.h +343 -0
- package/third_party/s2geometry/src/s2/s2edge_crosser_test.cc +264 -0
- package/third_party/s2geometry/src/s2/s2edge_crossings.cc +515 -0
- package/third_party/s2geometry/src/s2/s2edge_crossings.h +138 -0
- package/third_party/s2geometry/src/s2/s2edge_crossings_internal.h +59 -0
- package/third_party/s2geometry/src/s2/s2edge_crossings_test.cc +246 -0
- package/third_party/s2geometry/src/s2/s2edge_distances.cc +419 -0
- package/third_party/s2geometry/src/s2/s2edge_distances.h +192 -0
- package/third_party/s2geometry/src/s2/s2edge_distances_test.cc +539 -0
- package/third_party/s2geometry/src/s2/s2edge_tessellator.cc +276 -0
- package/third_party/s2geometry/src/s2/s2edge_tessellator.h +101 -0
- package/third_party/s2geometry/src/s2/s2edge_tessellator_test.cc +492 -0
- package/third_party/s2geometry/src/s2/s2edge_vector_shape.h +85 -0
- package/third_party/s2geometry/src/s2/s2edge_vector_shape_test.cc +66 -0
- package/third_party/s2geometry/src/s2/s2error.cc +29 -0
- package/third_party/s2geometry/src/s2/s2error.h +147 -0
- package/third_party/s2geometry/src/s2/s2error_test.cc +31 -0
- package/third_party/s2geometry/src/s2/s2furthest_edge_query.cc +117 -0
- package/third_party/s2geometry/src/s2/s2furthest_edge_query.h +439 -0
- package/third_party/s2geometry/src/s2/s2furthest_edge_query_test.cc +487 -0
- package/third_party/s2geometry/src/s2/s2latlng.cc +90 -0
- package/third_party/s2geometry/src/s2/s2latlng.h +234 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect.cc +727 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect.h +434 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect_bounder.cc +344 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect_bounder.h +89 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect_bounder_test.cc +306 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect_test.cc +1030 -0
- package/third_party/s2geometry/src/s2/s2latlng_test.cc +165 -0
- package/third_party/s2geometry/src/s2/s2lax_loop_shape.cc +104 -0
- package/third_party/s2geometry/src/s2/s2lax_loop_shape.h +153 -0
- package/third_party/s2geometry/src/s2/s2lax_loop_shape_test.cc +101 -0
- package/third_party/s2geometry/src/s2/s2lax_polygon_shape.cc +348 -0
- package/third_party/s2geometry/src/s2/s2lax_polygon_shape.h +183 -0
- package/third_party/s2geometry/src/s2/s2lax_polygon_shape_test.cc +234 -0
- package/third_party/s2geometry/src/s2/s2lax_polyline_shape.cc +118 -0
- package/third_party/s2geometry/src/s2/s2lax_polyline_shape.h +124 -0
- package/third_party/s2geometry/src/s2/s2lax_polyline_shape_test.cc +62 -0
- package/third_party/s2geometry/src/s2/s2loop.cc +1509 -0
- package/third_party/s2geometry/src/s2/s2loop.h +711 -0
- package/third_party/s2geometry/src/s2/s2loop_measures.cc +313 -0
- package/third_party/s2geometry/src/s2/s2loop_measures.h +280 -0
- package/third_party/s2geometry/src/s2/s2loop_measures_test.cc +367 -0
- package/third_party/s2geometry/src/s2/s2loop_test.cc +1371 -0
- package/third_party/s2geometry/src/s2/s2max_distance_targets.cc +265 -0
- package/third_party/s2geometry/src/s2/s2max_distance_targets.h +241 -0
- package/third_party/s2geometry/src/s2/s2max_distance_targets_test.cc +367 -0
- package/third_party/s2geometry/src/s2/s2measures.cc +128 -0
- package/third_party/s2geometry/src/s2/s2measures.h +78 -0
- package/third_party/s2geometry/src/s2/s2measures_test.cc +135 -0
- package/third_party/s2geometry/src/s2/s2metrics.cc +122 -0
- package/third_party/s2geometry/src/s2/s2metrics.h +199 -0
- package/third_party/s2geometry/src/s2/s2metrics_test.cc +127 -0
- package/third_party/s2geometry/src/s2/s2min_distance_targets.cc +295 -0
- package/third_party/s2geometry/src/s2/s2min_distance_targets.h +273 -0
- package/third_party/s2geometry/src/s2/s2min_distance_targets_test.cc +239 -0
- package/third_party/s2geometry/src/s2/s2padded_cell.cc +162 -0
- package/third_party/s2geometry/src/s2/s2padded_cell.h +108 -0
- package/third_party/s2geometry/src/s2/s2padded_cell_test.cc +138 -0
- package/third_party/s2geometry/src/s2/s2point.h +38 -0
- package/third_party/s2geometry/src/s2/s2point_compression.cc +388 -0
- package/third_party/s2geometry/src/s2/s2point_compression.h +78 -0
- package/third_party/s2geometry/src/s2/s2point_compression_test.cc +305 -0
- package/third_party/s2geometry/src/s2/s2point_index.h +345 -0
- package/third_party/s2geometry/src/s2/s2point_index_test.cc +147 -0
- package/third_party/s2geometry/src/s2/s2point_region.cc +72 -0
- package/third_party/s2geometry/src/s2/s2point_region.h +76 -0
- package/third_party/s2geometry/src/s2/s2point_region_test.cc +100 -0
- package/third_party/s2geometry/src/s2/s2point_span.h +57 -0
- package/third_party/s2geometry/src/s2/s2point_test.cc +47 -0
- package/third_party/s2geometry/src/s2/s2point_vector_shape.h +127 -0
- package/third_party/s2geometry/src/s2/s2point_vector_shape_test.cc +59 -0
- package/third_party/s2geometry/src/s2/s2pointutil.cc +131 -0
- package/third_party/s2geometry/src/s2/s2pointutil.h +138 -0
- package/third_party/s2geometry/src/s2/s2pointutil_test.cc +157 -0
- package/third_party/s2geometry/src/s2/s2polygon.cc +1569 -0
- package/third_party/s2geometry/src/s2/s2polygon.h +934 -0
- package/third_party/s2geometry/src/s2/s2polygon_test.cc +3025 -0
- package/third_party/s2geometry/src/s2/s2polyline.cc +645 -0
- package/third_party/s2geometry/src/s2/s2polyline.h +379 -0
- package/third_party/s2geometry/src/s2/s2polyline_alignment.cc +414 -0
- package/third_party/s2geometry/src/s2/s2polyline_alignment.h +245 -0
- package/third_party/s2geometry/src/s2/s2polyline_alignment_internal.h +158 -0
- package/third_party/s2geometry/src/s2/s2polyline_alignment_test.cc +610 -0
- package/third_party/s2geometry/src/s2/s2polyline_measures.cc +42 -0
- package/third_party/s2geometry/src/s2/s2polyline_measures.h +53 -0
- package/third_party/s2geometry/src/s2/s2polyline_measures_test.cc +57 -0
- package/third_party/s2geometry/src/s2/s2polyline_simplifier.cc +187 -0
- package/third_party/s2geometry/src/s2/s2polyline_simplifier.h +109 -0
- package/third_party/s2geometry/src/s2/s2polyline_simplifier_test.cc +165 -0
- package/third_party/s2geometry/src/s2/s2polyline_test.cc +554 -0
- package/third_party/s2geometry/src/s2/s2predicates.cc +1486 -0
- package/third_party/s2geometry/src/s2/s2predicates.h +282 -0
- package/third_party/s2geometry/src/s2/s2predicates_internal.h +135 -0
- package/third_party/s2geometry/src/s2/s2predicates_test.cc +1427 -0
- package/third_party/s2geometry/src/s2/s2projections.cc +109 -0
- package/third_party/s2geometry/src/s2/s2projections.h +161 -0
- package/third_party/s2geometry/src/s2/s2projections_test.cc +78 -0
- package/third_party/s2geometry/src/s2/s2r2rect.cc +88 -0
- package/third_party/s2geometry/src/s2/s2r2rect.h +292 -0
- package/third_party/s2geometry/src/s2/s2r2rect_test.cc +312 -0
- package/third_party/s2geometry/src/s2/s2region.cc +26 -0
- package/third_party/s2geometry/src/s2/s2region.h +142 -0
- package/third_party/s2geometry/src/s2/s2region_coverer.cc +514 -0
- package/third_party/s2geometry/src/s2/s2region_coverer.h +356 -0
- package/third_party/s2geometry/src/s2/s2region_coverer_test.cc +509 -0
- package/third_party/s2geometry/src/s2/s2region_intersection.cc +84 -0
- package/third_party/s2geometry/src/s2/s2region_intersection.h +79 -0
- package/third_party/s2geometry/src/s2/s2region_term_indexer.cc +270 -0
- package/third_party/s2geometry/src/s2/s2region_term_indexer.h +299 -0
- package/third_party/s2geometry/src/s2/s2region_term_indexer_test.cc +209 -0
- package/third_party/s2geometry/src/s2/s2region_test.cc +370 -0
- package/third_party/s2geometry/src/s2/s2region_union.cc +90 -0
- package/third_party/s2geometry/src/s2/s2region_union.h +83 -0
- package/third_party/s2geometry/src/s2/s2region_union_test.cc +89 -0
- package/third_party/s2geometry/src/s2/s2shape.h +283 -0
- package/third_party/s2geometry/src/s2/s2shape_index.cc +321 -0
- package/third_party/s2geometry/src/s2/s2shape_index.h +781 -0
- package/third_party/s2geometry/src/s2/s2shape_index_buffered_region.cc +113 -0
- package/third_party/s2geometry/src/s2/s2shape_index_buffered_region.h +135 -0
- package/third_party/s2geometry/src/s2/s2shape_index_buffered_region_test.cc +162 -0
- package/third_party/s2geometry/src/s2/s2shape_index_measures.cc +92 -0
- package/third_party/s2geometry/src/s2/s2shape_index_measures.h +100 -0
- package/third_party/s2geometry/src/s2/s2shape_index_measures_test.cc +136 -0
- package/third_party/s2geometry/src/s2/s2shape_index_region.h +350 -0
- package/third_party/s2geometry/src/s2/s2shape_index_region_test.cc +161 -0
- package/third_party/s2geometry/src/s2/s2shape_index_test.cc +24 -0
- package/third_party/s2geometry/src/s2/s2shape_measures.cc +138 -0
- package/third_party/s2geometry/src/s2/s2shape_measures.h +95 -0
- package/third_party/s2geometry/src/s2/s2shape_measures_test.cc +139 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries.cc +120 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries.h +66 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries_test.cc +170 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_coding.cc +253 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_coding.h +283 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_coding_test.cc +54 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force.cc +40 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force.h +41 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force_test.cc +55 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_count_edges.h +57 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_count_edges_test.cc +43 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator.cc +45 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator.h +72 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator_test.cc +116 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point.cc +107 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point.h +48 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point_test.cc +104 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator.cc +58 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator.h +65 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator_test.cc +61 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_shape_edge.h +58 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_shape_edge_id.h +97 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_testing.cc +104 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_testing.h +36 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs.cc +440 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs.h +72 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs_test.cc +184 -0
- package/third_party/s2geometry/src/s2/s2testing.cc +464 -0
- package/third_party/s2geometry/src/s2/s2testing.h +385 -0
- package/third_party/s2geometry/src/s2/s2testing_test.cc +166 -0
- package/third_party/s2geometry/src/s2/s2text_format.cc +506 -0
- package/third_party/s2geometry/src/s2/s2text_format.h +289 -0
- package/third_party/s2geometry/src/s2/s2text_format_test.cc +417 -0
- package/third_party/s2geometry/src/s2/s2wedge_relations.cc +80 -0
- package/third_party/s2geometry/src/s2/s2wedge_relations.h +64 -0
- package/third_party/s2geometry/src/s2/s2wedge_relations_test.cc +89 -0
- package/third_party/s2geometry/src/s2/sequence_lexicon.h +296 -0
- package/third_party/s2geometry/src/s2/sequence_lexicon_test.cc +113 -0
- package/third_party/s2geometry/src/s2/strings/ostringstream.cc +35 -0
- package/third_party/s2geometry/src/s2/strings/ostringstream.h +105 -0
- package/third_party/s2geometry/src/s2/strings/serialize.cc +46 -0
- package/third_party/s2geometry/src/s2/strings/serialize.h +40 -0
- package/third_party/s2geometry/src/s2/third_party/absl/algorithm/algorithm.h +187 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/attributes.h +666 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/casts.h +189 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/config.h +462 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/dynamic_annotations.cc +129 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/dynamic_annotations.h +394 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/atomic_hook.h +168 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/identity.h +33 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/inline_variable.h +117 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/invoke.h +188 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/raw_logging.cc +254 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/raw_logging.h +205 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/throw_delegate.cc +106 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/throw_delegate.h +71 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/unaligned_access.h +322 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/log_severity.h +77 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/macros.h +236 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/optimization.h +177 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/policy_checks.h +124 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/port.h +97 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/thread_annotations.h +277 -0
- package/third_party/s2geometry/src/s2/third_party/absl/container/fixed_array.h +523 -0
- package/third_party/s2geometry/src/s2/third_party/absl/container/inlined_vector.h +1453 -0
- package/third_party/s2geometry/src/s2/third_party/absl/container/internal/compressed_tuple.h +191 -0
- package/third_party/s2geometry/src/s2/third_party/absl/container/internal/container_memory.h +424 -0
- package/third_party/s2geometry/src/s2/third_party/absl/container/internal/layout.h +739 -0
- package/third_party/s2geometry/src/s2/third_party/absl/memory/memory.h +755 -0
- package/third_party/s2geometry/src/s2/third_party/absl/meta/type_traits.h +436 -0
- package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128.cc +232 -0
- package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128.h +656 -0
- package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128_have_intrinsic.inc +3 -0
- package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128_no_intrinsic.inc +3 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii.cc +198 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii.h +239 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii_ctype.h +66 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/bits.h +53 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/memutil.cc +110 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/memutil.h +146 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/resize_uninitialized.h +72 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/match.cc +38 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/match.h +89 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/numbers.cc +909 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/numbers.h +187 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/str_cat.cc +240 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/str_cat.h +398 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/str_join.h +22 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/str_split.cc +47 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/str_split.h +43 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/string_view.cc +245 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/string_view.h +602 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/strip.cc +42 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/strip.h +130 -0
- package/third_party/s2geometry/src/s2/third_party/absl/types/span.h +793 -0
- package/third_party/s2geometry/src/s2/third_party/absl/utility/utility.h +299 -0
- package/third_party/s2geometry/src/s2/util/bits/bit-interleave.cc +274 -0
- package/third_party/s2geometry/src/s2/util/bits/bit-interleave.h +53 -0
- package/third_party/s2geometry/src/s2/util/bits/bits.cc +155 -0
- package/third_party/s2geometry/src/s2/util/bits/bits.h +745 -0
- package/third_party/s2geometry/src/s2/util/coding/coder.cc +83 -0
- package/third_party/s2geometry/src/s2/util/coding/coder.h +553 -0
- package/third_party/s2geometry/src/s2/util/coding/nth-derivative.h +134 -0
- package/third_party/s2geometry/src/s2/util/coding/transforms.h +62 -0
- package/third_party/s2geometry/src/s2/util/coding/varint.cc +289 -0
- package/third_party/s2geometry/src/s2/util/coding/varint.h +476 -0
- package/third_party/s2geometry/src/s2/util/endian/endian.h +859 -0
- package/third_party/s2geometry/src/s2/util/gtl/btree.h +2471 -0
- package/third_party/s2geometry/src/s2/util/gtl/btree_container.h +411 -0
- package/third_party/s2geometry/src/s2/util/gtl/btree_map.h +79 -0
- package/third_party/s2geometry/src/s2/util/gtl/btree_set.h +73 -0
- package/third_party/s2geometry/src/s2/util/gtl/compact_array.h +653 -0
- package/third_party/s2geometry/src/s2/util/gtl/container_logging.h +291 -0
- package/third_party/s2geometry/src/s2/util/gtl/dense_hash_set.h +358 -0
- package/third_party/s2geometry/src/s2/util/gtl/densehashtable.h +1493 -0
- package/third_party/s2geometry/src/s2/util/gtl/hashtable_common.h +253 -0
- package/third_party/s2geometry/src/s2/util/gtl/layout.h +28 -0
- package/third_party/s2geometry/src/s2/util/gtl/legacy_random_shuffle.h +77 -0
- package/third_party/s2geometry/src/s2/util/hash/mix.h +76 -0
- package/third_party/s2geometry/src/s2/util/math/exactfloat/exactfloat.cc +832 -0
- package/third_party/s2geometry/src/s2/util/math/exactfloat/exactfloat.h +646 -0
- package/third_party/s2geometry/src/s2/util/math/mathutil.cc +75 -0
- package/third_party/s2geometry/src/s2/util/math/mathutil.h +189 -0
- package/third_party/s2geometry/src/s2/util/math/matrix3x3.h +574 -0
- package/third_party/s2geometry/src/s2/util/math/vector.h +569 -0
- package/third_party/s2geometry/src/s2/util/math/vector3_hash.h +54 -0
- package/third_party/s2geometry/src/s2/util/units/length-units.cc +21 -0
- package/third_party/s2geometry/src/s2/util/units/length-units.h +135 -0
- package/third_party/s2geometry/src/s2/util/units/physical-units.h +313 -0
- package/third_party/s2geometry/src/s2/value_lexicon.h +234 -0
- package/third_party/s2geometry/src/s2/value_lexicon_test.cc +121 -0
- package/third_party/s2geometry/third_party/cmake/FindGFlags.cmake +48 -0
- package/third_party/s2geometry/third_party/cmake/FindGlog.cmake +48 -0
|
@@ -0,0 +1,745 @@
|
|
|
1
|
+
// Copyright 2002 Google Inc. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS-IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
|
|
16
|
+
#ifndef S2_UTIL_BITS_BITS_H_
|
|
17
|
+
#define S2_UTIL_BITS_BITS_H_
|
|
18
|
+
|
|
19
|
+
//
|
|
20
|
+
// Various bit-twiddling functions, all of which are static members of the Bits
|
|
21
|
+
// class (making it effectively a namespace). Operands are unsigned integers.
|
|
22
|
+
// Munging bits in _signed_ integers is fraught with peril! For example,
|
|
23
|
+
// -5 << n has undefined behavior (for some values of n).
|
|
24
|
+
//
|
|
25
|
+
// Bits provide the following:
|
|
26
|
+
//
|
|
27
|
+
// * Count(Ones.*|LeadingZeros.*)? . In a similar vein, there's also the
|
|
28
|
+
// Find[LM]SBSetNonZero.* family of functions. You can think of them as
|
|
29
|
+
// (trailing|leading) zero bit count + 1. Also in a similar vein,
|
|
30
|
+
// (Capped)?Difference, which count the number of one bits in foo ^ bar.
|
|
31
|
+
//
|
|
32
|
+
// * ReverseBits${power_of_two}
|
|
33
|
+
//
|
|
34
|
+
// * Log2(Floor|Ceiling)(NonZero)?.* - The NonZero variants have undefined
|
|
35
|
+
// behavior if argument is 0.
|
|
36
|
+
//
|
|
37
|
+
// * Bytes(ContainByte(LessThan)?|AllInRange) - These scan a sequence of bytes
|
|
38
|
+
// looking for one with(out)? some property.
|
|
39
|
+
//
|
|
40
|
+
// * (Get|Set|Copy)Bits
|
|
41
|
+
//
|
|
42
|
+
// * GetLowBits - Extract N lowest bits from value.
|
|
43
|
+
//
|
|
44
|
+
// The only other thing is BitPattern, which is a trait class template (not in
|
|
45
|
+
// Bits) containing a few bit patterns (which vary based on value of template
|
|
46
|
+
// parameter).
|
|
47
|
+
|
|
48
|
+
#include "s2/third_party/absl/base/casts.h"
|
|
49
|
+
#include "s2/third_party/absl/numeric/int128.h"
|
|
50
|
+
#if defined(__i386__) || defined(__x86_64__)
|
|
51
|
+
#include <x86intrin.h>
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
#include <type_traits>
|
|
55
|
+
|
|
56
|
+
#include "s2/base/integral_types.h"
|
|
57
|
+
#include "s2/base/logging.h"
|
|
58
|
+
#include "s2/base/port.h"
|
|
59
|
+
#include "s2/third_party/absl/base/macros.h"
|
|
60
|
+
|
|
61
|
+
class Bits {
|
|
62
|
+
public:
|
|
63
|
+
// A traits class template for unsigned integer type sizes. Primary
|
|
64
|
+
// information contained herein is corresponding (unsigned) integer type.
|
|
65
|
+
// E.g. UnsignedTypeBySize<32>::Type is uint32. Used by UnsignedType.
|
|
66
|
+
template<int size /* in bytes */>
|
|
67
|
+
struct UnsignedTypeBySize;
|
|
68
|
+
|
|
69
|
+
// Auxiliary struct for figuring out an unsigned type for a given type.
|
|
70
|
+
template<typename T> struct UnsignedType {
|
|
71
|
+
typedef typename UnsignedTypeBySize<sizeof(T)>::Type Type;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Return the number of one bits in the given integer.
|
|
75
|
+
static int CountOnesInByte(unsigned char n);
|
|
76
|
+
|
|
77
|
+
static int CountOnes(uint32 n) {
|
|
78
|
+
#if defined(__powerpc64__) && defined(__GNUC__)
|
|
79
|
+
// Use popcount builtin if we know it is inlined and fast.
|
|
80
|
+
return PopcountWithBuiltin(n);
|
|
81
|
+
#elif (defined(__i386__) || defined(__x86_64__)) && defined(__POPCNT__) && \
|
|
82
|
+
defined(__GNUC__)
|
|
83
|
+
return PopcountWithBuiltin(n);
|
|
84
|
+
#else
|
|
85
|
+
n -= ((n >> 1) & 0x55555555);
|
|
86
|
+
n = ((n >> 2) & 0x33333333) + (n & 0x33333333);
|
|
87
|
+
return static_cast<int>((((n + (n >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24);
|
|
88
|
+
#endif
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Count bits using sideways addition [WWG'57]. See Knuth TAOCP v4 7.1.3(59)
|
|
92
|
+
static inline int CountOnes64(uint64 n) {
|
|
93
|
+
#if defined(__powerpc64__) && defined(__GNUC__)
|
|
94
|
+
return PopcountWithBuiltin(n);
|
|
95
|
+
#elif defined(__x86_64__) && defined(__POPCNT__) && defined(__GNUC__)
|
|
96
|
+
return PopcountWithBuiltin(n);
|
|
97
|
+
#elif defined(_LP64)
|
|
98
|
+
n -= (n >> 1) & 0x5555555555555555ULL;
|
|
99
|
+
n = ((n >> 2) & 0x3333333333333333ULL) + (n & 0x3333333333333333ULL);
|
|
100
|
+
return static_cast<int>(
|
|
101
|
+
(((n + (n >> 4)) & 0xF0F0F0F0F0F0F0FULL) * 0x101010101010101ULL) >> 56);
|
|
102
|
+
#else
|
|
103
|
+
return CountOnes(n >> 32) + CountOnes(n & 0xffffffff);
|
|
104
|
+
#endif
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Count bits in uint128
|
|
108
|
+
static inline int CountOnes128(absl::uint128 n) {
|
|
109
|
+
return Bits::CountOnes64(absl::Uint128High64(n)) +
|
|
110
|
+
Bits::CountOnes64(absl::Uint128Low64(n));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Count leading zeroes. This is similar to wordsize - 1 - floor(log2(n)).
|
|
114
|
+
// Returns number of bits if n is 0.
|
|
115
|
+
static inline int CountLeadingZeros32(uint32 n) {
|
|
116
|
+
// Instead of using __builtin_clz(), we explicitly write target specific
|
|
117
|
+
// assembly because we want to handle n == 0. If we used __builtin_clz(),
|
|
118
|
+
// we would need to use something like "n ? __builtin_clz(n) : 32". The
|
|
119
|
+
// check is not necessary on POWER and aarch64 but we cannot depend on
|
|
120
|
+
// that because __builtin_clz(0) is documented to be undefined.
|
|
121
|
+
#if defined(__aarch64__) && defined(__GNUC__)
|
|
122
|
+
int32 count;
|
|
123
|
+
asm("clz %w0,%w1" : "=r"(count) : "r"(n));
|
|
124
|
+
return count;
|
|
125
|
+
#elif (defined(__i386__) || defined(__x86_64__)) && defined(__LZCNT__) && \
|
|
126
|
+
defined(__GNUC__)
|
|
127
|
+
return __lzcnt32(n);
|
|
128
|
+
#elif (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
|
|
129
|
+
if (n == 0) return 32;
|
|
130
|
+
int32 idx;
|
|
131
|
+
asm("bsr %1, %0"
|
|
132
|
+
: "=r"(idx)
|
|
133
|
+
: "ro"(n)
|
|
134
|
+
: "cc"); // bsr writes Z flag
|
|
135
|
+
return 31 ^ idx;
|
|
136
|
+
#elif defined(__powerpc64__) && defined(__GNUC__)
|
|
137
|
+
int32 count;
|
|
138
|
+
asm("cntlzw %0,%1" : "=r"(count) : "r"(n));
|
|
139
|
+
return count;
|
|
140
|
+
#elif defined(__GNUC__)
|
|
141
|
+
return CountLeadingZerosWithBuiltin(n);
|
|
142
|
+
#else
|
|
143
|
+
return CountLeadingZeros32_Portable(n);
|
|
144
|
+
#endif
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static inline int CountLeadingZeros64(uint64 n) {
|
|
148
|
+
#if defined(__aarch64__) && defined(__GNUC__)
|
|
149
|
+
int64 count;
|
|
150
|
+
asm("clz %0,%1" : "=r"(count) : "r"(n));
|
|
151
|
+
return static_cast<int>(count);
|
|
152
|
+
#elif defined(__powerpc64__) && defined(__GNUC__)
|
|
153
|
+
int64 count;
|
|
154
|
+
asm("cntlzd %0,%1" : "=r"(count) : "r"(n));
|
|
155
|
+
return static_cast<int>(count);
|
|
156
|
+
#elif (defined(__i386__) || defined(__x86_64__)) && defined(__LZCNT__) && \
|
|
157
|
+
defined(__GNUC__)
|
|
158
|
+
return __lzcnt64(n);
|
|
159
|
+
#elif defined(__x86_64__) && defined(__GNUC__)
|
|
160
|
+
if (n == 0) return 64;
|
|
161
|
+
int64 idx;
|
|
162
|
+
asm ("bsr %1, %0"
|
|
163
|
+
: "=r"(idx)
|
|
164
|
+
: "ro"(n)
|
|
165
|
+
: "cc"); // bsr writes Z flag
|
|
166
|
+
return static_cast<int>(63 ^ idx);
|
|
167
|
+
#elif defined(__GNUC__)
|
|
168
|
+
return CountLeadingZerosWithBuiltin(n);
|
|
169
|
+
#else
|
|
170
|
+
return CountLeadingZeros64_Portable(n);
|
|
171
|
+
#endif
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static inline int CountLeadingZeros128(absl::uint128 n) {
|
|
175
|
+
if (uint64 hi = absl::Uint128High64(n))
|
|
176
|
+
return Bits::CountLeadingZeros64(hi);
|
|
177
|
+
return Bits::CountLeadingZeros64(absl::Uint128Low64(n)) + 64;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Reverse the bits in the given integer.
|
|
181
|
+
static uint8 ReverseBits8(uint8 n);
|
|
182
|
+
static uint32 ReverseBits32(uint32 n);
|
|
183
|
+
static uint64 ReverseBits64(uint64 n);
|
|
184
|
+
static absl::uint128 ReverseBits128(absl::uint128 n);
|
|
185
|
+
|
|
186
|
+
// Return the number of one bits in the byte sequence.
|
|
187
|
+
static int Count(const void *m, int num_bytes);
|
|
188
|
+
|
|
189
|
+
// Return the number of different bits in the given byte sequences.
|
|
190
|
+
// (i.e., the Hamming distance)
|
|
191
|
+
static int Difference(const void *m1, const void *m2, int num_bytes);
|
|
192
|
+
|
|
193
|
+
// Return the number of different bits in the given byte sequences,
|
|
194
|
+
// up to a maximum. Values larger than the maximum may be returned
|
|
195
|
+
// (because multiple bits are checked at a time), but the function
|
|
196
|
+
// may exit early if the cap is exceeded.
|
|
197
|
+
static int CappedDifference(const void *m1, const void *m2,
|
|
198
|
+
int num_bytes, int cap);
|
|
199
|
+
|
|
200
|
+
// Return floor(log2(n)) for positive integer n. Returns -1 iff n == 0.
|
|
201
|
+
static int Log2Floor(uint32 n);
|
|
202
|
+
static int Log2Floor64(uint64 n);
|
|
203
|
+
static int Log2Floor128(absl::uint128 n);
|
|
204
|
+
|
|
205
|
+
// Potentially faster version of Log2Floor() that returns an
|
|
206
|
+
// undefined value if n == 0
|
|
207
|
+
static int Log2FloorNonZero(uint32 n);
|
|
208
|
+
static int Log2FloorNonZero64(uint64 n);
|
|
209
|
+
static int Log2FloorNonZero128(absl::uint128 n);
|
|
210
|
+
|
|
211
|
+
// Return ceiling(log2(n)) for positive integer n. Returns -1 iff n == 0.
|
|
212
|
+
static int Log2Ceiling(uint32 n);
|
|
213
|
+
static int Log2Ceiling64(uint64 n);
|
|
214
|
+
static int Log2Ceiling128(absl::uint128 n);
|
|
215
|
+
|
|
216
|
+
// Return the first set least / most significant bit, 0-indexed. Returns an
|
|
217
|
+
// undefined value if n == 0. FindLSBSetNonZero() is similar to ffs() except
|
|
218
|
+
// that it's 0-indexed, while FindMSBSetNonZero() is the same as
|
|
219
|
+
// Log2FloorNonZero().
|
|
220
|
+
static int FindLSBSetNonZero(uint32 n);
|
|
221
|
+
static int FindLSBSetNonZero64(uint64 n);
|
|
222
|
+
static int FindLSBSetNonZero128(absl::uint128 n);
|
|
223
|
+
static int FindMSBSetNonZero(uint32 n) { return Log2FloorNonZero(n); }
|
|
224
|
+
static int FindMSBSetNonZero64(uint64 n) { return Log2FloorNonZero64(n); }
|
|
225
|
+
static int FindMSBSetNonZero128(absl::uint128 n) {
|
|
226
|
+
return Log2FloorNonZero128(n);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Viewing bytes as a stream of unsigned bytes, does that stream
|
|
230
|
+
// contain any byte equal to c?
|
|
231
|
+
template <class T> static bool BytesContainByte(T bytes, uint8 c);
|
|
232
|
+
|
|
233
|
+
// Viewing bytes as a stream of unsigned bytes, does that stream
|
|
234
|
+
// contain any byte b < c?
|
|
235
|
+
template <class T> static bool BytesContainByteLessThan(T bytes, uint8 c);
|
|
236
|
+
|
|
237
|
+
// Viewing bytes as a stream of unsigned bytes, are all elements of that
|
|
238
|
+
// stream in [lo, hi]?
|
|
239
|
+
template <class T> static bool BytesAllInRange(T bytes, uint8 lo, uint8 hi);
|
|
240
|
+
|
|
241
|
+
// Extract 'nbits' consecutive bits from 'src'. Position of bits are
|
|
242
|
+
// specified by 'offset' from the LSB. 'T' is a scalar type (integral,
|
|
243
|
+
// float or pointer) whose size is the same as one of the unsigned types.
|
|
244
|
+
// The return type is an unsigned type having the same size as T.
|
|
245
|
+
template<typename T>
|
|
246
|
+
static typename UnsignedType<T>::Type GetBits(const T src,
|
|
247
|
+
const int offset,
|
|
248
|
+
const int nbits) {
|
|
249
|
+
typedef typename UnsignedType<T>::Type UnsignedT;
|
|
250
|
+
const UnsignedT unsigned_src = absl::bit_cast<UnsignedT>(src);
|
|
251
|
+
S2_DCHECK_GT(sizeof(UnsignedT) * 8, offset);
|
|
252
|
+
S2_DCHECK_GE(sizeof(UnsignedT) * 8, offset + nbits);
|
|
253
|
+
return GetBitsImpl(unsigned_src, offset, nbits);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Overwrite 'nbits' consecutive bits of 'dest.'. Position of bits are
|
|
257
|
+
// specified by an offset from the LSB. 'T' is a scalar type (integral,
|
|
258
|
+
// float or pointer) whose size is the same as one of the unsigned types.
|
|
259
|
+
template<typename T>
|
|
260
|
+
static void SetBits(const typename UnsignedType<T>::Type value,
|
|
261
|
+
const int offset,
|
|
262
|
+
const int nbits,
|
|
263
|
+
T* const dest) {
|
|
264
|
+
typedef typename UnsignedType<T>::Type UnsignedT;
|
|
265
|
+
const UnsignedT unsigned_dest = absl::bit_cast<UnsignedT>(*dest);
|
|
266
|
+
S2_DCHECK_GT(sizeof(UnsignedT) * 8, offset);
|
|
267
|
+
S2_DCHECK_GE(sizeof(UnsignedT) * 8, offset + nbits);
|
|
268
|
+
const UnsignedT mask = NBitsFromLSB<UnsignedT>(nbits);
|
|
269
|
+
const UnsignedT unsigned_result =
|
|
270
|
+
(unsigned_dest & ~(mask << offset)) | ((value & mask) << offset);
|
|
271
|
+
*dest = absl::bit_cast<T>(unsigned_result);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Combine SetBits and GetBits for convenience. This is meant to be a
|
|
275
|
+
// replacement for BitCopy() for some use cases. Unlike BitCopy(),
|
|
276
|
+
// Bits::CopyBits() operating on multibyte types has the same behavior on
|
|
277
|
+
// big-endian and little-endian machines. Sample usage:
|
|
278
|
+
//
|
|
279
|
+
// uint32 a, b;
|
|
280
|
+
// Bits::CopyBits(&a, 0, b, 12, 3);
|
|
281
|
+
template<typename DestType, typename SrcType>
|
|
282
|
+
static void CopyBits(DestType* const dest,
|
|
283
|
+
const int dest_offset,
|
|
284
|
+
const SrcType src,
|
|
285
|
+
const int src_offset,
|
|
286
|
+
const int nbits) {
|
|
287
|
+
const typename UnsignedType<SrcType>::Type value =
|
|
288
|
+
GetBits(src, src_offset, nbits);
|
|
289
|
+
SetBits(value, dest_offset, nbits, dest);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Extract the lowest 'nbits' consecutive bits from 'src'.
|
|
293
|
+
// Bits::GetLowBits(13, 3); /* = 5 (0b1101 => 0b101) */
|
|
294
|
+
template<typename T>
|
|
295
|
+
static typename UnsignedType<T>::Type GetLowBits(const T src,
|
|
296
|
+
const int nbits) {
|
|
297
|
+
typedef typename UnsignedType<T>::Type UnsignedT;
|
|
298
|
+
const UnsignedT unsigned_src = absl::bit_cast<UnsignedT>(src);
|
|
299
|
+
S2_DCHECK_GE(sizeof(UnsignedT) * 8, nbits);
|
|
300
|
+
return GetLowBitsImpl(unsigned_src, nbits);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private:
|
|
304
|
+
// We only use this for unsigned types and for 0 <= n <= sizeof(UnsignedT).
|
|
305
|
+
template<typename UnsignedT>
|
|
306
|
+
static UnsignedT NBitsFromLSB(const int nbits) {
|
|
307
|
+
const UnsignedT all_ones = ~static_cast<UnsignedT>(0);
|
|
308
|
+
return nbits == 0 ? static_cast<UnsignedT>(0)
|
|
309
|
+
: all_ones >> (sizeof(UnsignedT) * 8 - nbits);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
template<typename UnsignedT>
|
|
313
|
+
static inline UnsignedT GetBitsImpl(const UnsignedT src,
|
|
314
|
+
const int offset,
|
|
315
|
+
const int nbits);
|
|
316
|
+
template <typename UnsignedT>
|
|
317
|
+
static inline UnsignedT GetLowBitsImpl(const UnsignedT src, const int nbits);
|
|
318
|
+
|
|
319
|
+
#ifdef __GNUC__
|
|
320
|
+
static int CountLeadingZerosWithBuiltin(unsigned n);
|
|
321
|
+
// NOLINTNEXTLINE(runtime/int)
|
|
322
|
+
static int CountLeadingZerosWithBuiltin(unsigned long n);
|
|
323
|
+
// NOLINTNEXTLINE(runtime/int)
|
|
324
|
+
static int CountLeadingZerosWithBuiltin(unsigned long long n);
|
|
325
|
+
static int PopcountWithBuiltin(unsigned n);
|
|
326
|
+
static int PopcountWithBuiltin(unsigned long n); // NOLINT(runtime/int)
|
|
327
|
+
static int PopcountWithBuiltin(unsigned long long n); // NOLINT(runtime/int)
|
|
328
|
+
#if defined(__BMI__) && (defined(__i386__) || defined(__x86_64__))
|
|
329
|
+
static inline uint32 GetBitsImpl(const uint32 src,
|
|
330
|
+
const int offset,
|
|
331
|
+
const int nbits);
|
|
332
|
+
#endif
|
|
333
|
+
#if defined(__BMI__) && defined(__x86_64__)
|
|
334
|
+
static inline uint64 GetBitsImpl(const uint64 src,
|
|
335
|
+
const int offset,
|
|
336
|
+
const int nbits);
|
|
337
|
+
#endif
|
|
338
|
+
#if defined(__BMI2__) && (defined(__i386__) || defined(__x86_64__))
|
|
339
|
+
static inline uint32 GetLowBitsImpl(const uint32 src, const int nbits);
|
|
340
|
+
#endif
|
|
341
|
+
#if defined(__BMI2__) && defined(__x86_64__)
|
|
342
|
+
static inline uint64 GetLowBitsImpl(const uint64 src, const int nbits);
|
|
343
|
+
#endif
|
|
344
|
+
#endif // __GNUC__
|
|
345
|
+
|
|
346
|
+
// Portable implementations.
|
|
347
|
+
static int Log2Floor_Portable(uint32 n);
|
|
348
|
+
static int Log2Floor64_Portable(uint64 n);
|
|
349
|
+
static int Log2FloorNonZero_Portable(uint32 n);
|
|
350
|
+
static int Log2FloorNonZero64_Portable(uint64 n);
|
|
351
|
+
static int CountLeadingZeros32_Portable(uint32 n);
|
|
352
|
+
static int CountLeadingZeros64_Portable(uint64 n);
|
|
353
|
+
static int FindLSBSetNonZero_Portable(uint32 n);
|
|
354
|
+
static int FindLSBSetNonZero64_Portable(uint64 n);
|
|
355
|
+
|
|
356
|
+
static const char num_bits[];
|
|
357
|
+
Bits(Bits const&) = delete;
|
|
358
|
+
void operator=(Bits const&) = delete;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// A utility class for some handy bit patterns. The names l and h
|
|
362
|
+
// were chosen to match Knuth Volume 4: l is 0x010101... and h is 0x808080...;
|
|
363
|
+
// half_ones is ones in the lower half only. We assume sizeof(T) is 1 or even.
|
|
364
|
+
template <class T> struct BitPattern {
|
|
365
|
+
typedef typename std::make_unsigned<T>::type U;
|
|
366
|
+
static const U half_ones = (static_cast<U>(1) << (sizeof(U) * 4)) - 1;
|
|
367
|
+
static const U l =
|
|
368
|
+
(sizeof(U) == 1) ? 1 : (half_ones / 0xff * (half_ones + 2));
|
|
369
|
+
static const U h = ~(l * 0x7f);
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// ------------------------------------------------------------------------
|
|
373
|
+
// Implementation details follow
|
|
374
|
+
// ------------------------------------------------------------------------
|
|
375
|
+
|
|
376
|
+
#if defined(__GNUC__)
|
|
377
|
+
|
|
378
|
+
inline int Bits::Log2Floor(uint32 n) {
|
|
379
|
+
return n == 0 ? -1 : 31 ^ __builtin_clz(n);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
inline int Bits::Log2FloorNonZero(uint32 n) {
|
|
383
|
+
return 31 ^ __builtin_clz(n);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
inline int Bits::FindLSBSetNonZero(uint32 n) {
|
|
387
|
+
return __builtin_ctz(n);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
inline int Bits::Log2Floor64(uint64 n) {
|
|
391
|
+
return n == 0 ? -1 : 63 ^ __builtin_clzll(n);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
inline int Bits::Log2FloorNonZero64(uint64 n) {
|
|
395
|
+
return 63 ^ __builtin_clzll(n);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
inline int Bits::FindLSBSetNonZero64(uint64 n) {
|
|
399
|
+
return __builtin_ctzll(n);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
#elif defined(_MSC_VER)
|
|
403
|
+
|
|
404
|
+
inline int Bits::FindLSBSetNonZero(uint32 n) {
|
|
405
|
+
return Bits::FindLSBSetNonZero_Portable(n);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
inline int Bits::FindLSBSetNonZero64(uint64 n) {
|
|
409
|
+
return Bits::FindLSBSetNonZero64_Portable(n);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
inline int Bits::Log2FloorNonZero(uint32 n) {
|
|
413
|
+
#ifdef _M_IX86
|
|
414
|
+
_asm {
|
|
415
|
+
bsr ebx, n
|
|
416
|
+
mov n, ebx
|
|
417
|
+
}
|
|
418
|
+
return n;
|
|
419
|
+
#else
|
|
420
|
+
return Bits::Log2FloorNonZero_Portable(n);
|
|
421
|
+
#endif
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
inline int Bits::Log2Floor(uint32 n) {
|
|
425
|
+
#ifdef _M_IX86
|
|
426
|
+
_asm {
|
|
427
|
+
xor ebx, ebx
|
|
428
|
+
mov eax, n
|
|
429
|
+
and eax, eax
|
|
430
|
+
jz return_ebx
|
|
431
|
+
bsr ebx, eax
|
|
432
|
+
return_ebx:
|
|
433
|
+
mov n, ebx
|
|
434
|
+
}
|
|
435
|
+
return n;
|
|
436
|
+
#else
|
|
437
|
+
return Bits::Log2Floor_Portable(n);
|
|
438
|
+
#endif
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
inline int Bits::Log2Floor64(uint64 n) {
|
|
442
|
+
return Bits::Log2Floor64_Portable(n);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
inline int Bits::Log2FloorNonZero64(uint64 n) {
|
|
446
|
+
return Bits::Log2FloorNonZero64_Portable(n);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
#else // !__GNUC__ && !_MSC_VER
|
|
450
|
+
|
|
451
|
+
inline int Bits::Log2Floor(uint32 n) {
|
|
452
|
+
return Bits::Log2Floor_Portable(n);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
inline int Bits::Log2FloorNonZero(uint32 n) {
|
|
456
|
+
return Bits::Log2FloorNonZero_Portable(n);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
inline int Bits::FindLSBSetNonZero(uint32 n) {
|
|
460
|
+
return Bits::FindLSBSetNonZero_Portable(n);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
inline int Bits::Log2Floor64(uint64 n) {
|
|
464
|
+
return Bits::Log2Floor64_Portable(n);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
inline int Bits::Log2FloorNonZero64(uint64 n) {
|
|
468
|
+
return Bits::Log2FloorNonZero64_Portable(n);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
inline int Bits::FindLSBSetNonZero64(uint64 n) {
|
|
472
|
+
return Bits::FindLSBSetNonZero64_Portable(n);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
#endif
|
|
476
|
+
|
|
477
|
+
inline int Bits::Log2Floor128(absl::uint128 n) {
|
|
478
|
+
if (uint64 hi = absl::Uint128High64(n)) return 64 + Log2FloorNonZero64(hi);
|
|
479
|
+
return Log2Floor64(absl::Uint128Low64(n));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
inline int Bits::Log2FloorNonZero128(absl::uint128 n) {
|
|
483
|
+
if (uint64 hi = absl::Uint128High64(n)) return 64 + Log2FloorNonZero64(hi);
|
|
484
|
+
return Log2FloorNonZero64(absl::Uint128Low64(n));
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
inline int Bits::FindLSBSetNonZero128(absl::uint128 n) {
|
|
488
|
+
if (uint64 lo = absl::Uint128Low64(n)) return Bits::FindLSBSetNonZero64(lo);
|
|
489
|
+
return 64 + Bits::FindLSBSetNonZero64(absl::Uint128High64(n));
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
inline int Bits::CountOnesInByte(unsigned char n) {
|
|
493
|
+
return num_bits[n];
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
inline uint8 Bits::ReverseBits8(unsigned char n) {
|
|
497
|
+
#if defined(__aarch64__) && defined(__GNUC__)
|
|
498
|
+
// aarch64 has a reverse bits instruction but there is no gcc builtin.
|
|
499
|
+
uint32 result;
|
|
500
|
+
const uint32 n_shifted = static_cast<uint32>(n) << 24;
|
|
501
|
+
asm("rbit %w0, %w1" : "=r"(result) : "r"(n_shifted));
|
|
502
|
+
return static_cast<uint8>(result);
|
|
503
|
+
#elif defined (__powerpc64__)
|
|
504
|
+
uint64 temp = n;
|
|
505
|
+
// bpermd selects a byte's worth of bits from its second input. Grab one byte
|
|
506
|
+
// at a time, in reversed order. 0x3f is the lowest order bit of a 64-bit int.
|
|
507
|
+
// Bits 0x0 through 0x37 will all be zero, and bits 0x38 through 0x3f will
|
|
508
|
+
// hold the 8 bits from `n`.
|
|
509
|
+
uint64 result = __builtin_bpermd(0x3f3e3d3c3b3a3938, temp);
|
|
510
|
+
return static_cast<unsigned char>(result);
|
|
511
|
+
#else
|
|
512
|
+
n = static_cast<unsigned char>(((n >> 1) & 0x55) | ((n & 0x55) << 1));
|
|
513
|
+
n = static_cast<unsigned char>(((n >> 2) & 0x33) | ((n & 0x33) << 2));
|
|
514
|
+
return static_cast<unsigned char>(((n >> 4) & 0x0f) | ((n & 0x0f) << 4));
|
|
515
|
+
#endif
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
inline uint32 Bits::ReverseBits32(uint32 n) {
|
|
519
|
+
#if defined(__aarch64__) && defined(__GNUC__)
|
|
520
|
+
uint32 result;
|
|
521
|
+
asm("rbit %w0, %w1" : "=r"(result) : "r"(n));
|
|
522
|
+
return result;
|
|
523
|
+
#elif defined(__powerpc64__)
|
|
524
|
+
uint64 temp = n;
|
|
525
|
+
uint64 result_0 = __builtin_bpermd(0x3f3e3d3c3b3a3938, temp) << 24;
|
|
526
|
+
uint64 result_1 = __builtin_bpermd(0x3736353433323130, temp) << 16;
|
|
527
|
+
uint64 result_2 = __builtin_bpermd(0x2f2e2d2c2b2a2928, temp) << 8;
|
|
528
|
+
uint64 result_3 = __builtin_bpermd(0x2726252423222120, temp);
|
|
529
|
+
return static_cast<uint32>(result_0 | result_1 | result_2 | result_3);
|
|
530
|
+
#else
|
|
531
|
+
n = ((n >> 1) & 0x55555555) | ((n & 0x55555555) << 1);
|
|
532
|
+
n = ((n >> 2) & 0x33333333) | ((n & 0x33333333) << 2);
|
|
533
|
+
n = ((n >> 4) & 0x0F0F0F0F) | ((n & 0x0F0F0F0F) << 4);
|
|
534
|
+
return bswap_32(n);
|
|
535
|
+
#endif
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
inline uint64 Bits::ReverseBits64(uint64 n) {
|
|
539
|
+
#if defined(__aarch64__) && defined(__GNUC__)
|
|
540
|
+
uint64 result;
|
|
541
|
+
asm("rbit %0, %1" : "=r"(result) : "r"(n));
|
|
542
|
+
return result;
|
|
543
|
+
#elif defined(__powerpc64__)
|
|
544
|
+
uint64 result_lo0 = __builtin_bpermd(0x3f3e3d3c3b3a3938, n) << 56;
|
|
545
|
+
uint64 result_lo1 = __builtin_bpermd(0x3736353433323130, n) << 48;
|
|
546
|
+
uint64 result_lo2 = __builtin_bpermd(0x2f2e2d2c2b2a2928, n) << 40;
|
|
547
|
+
uint64 result_lo3 = __builtin_bpermd(0x2726252423222120, n) << 32;
|
|
548
|
+
uint64 result_hi0 = __builtin_bpermd(0x1f1e1d1c1b1a1918, n) << 24;
|
|
549
|
+
uint64 result_hi1 = __builtin_bpermd(0x1716151413121110, n) << 16;
|
|
550
|
+
uint64 result_hi2 = __builtin_bpermd(0x0f0e0d0c0b0a0908, n) << 8;
|
|
551
|
+
uint64 result_hi3 = __builtin_bpermd(0x0706050403020100, n);
|
|
552
|
+
return (result_lo0 | result_lo1 | result_lo2 | result_lo3 |
|
|
553
|
+
result_hi0 | result_hi1 | result_hi2 | result_hi3);
|
|
554
|
+
#elif defined(_LP64)
|
|
555
|
+
n = ((n >> 1) & 0x5555555555555555ULL) | ((n & 0x5555555555555555ULL) << 1);
|
|
556
|
+
n = ((n >> 2) & 0x3333333333333333ULL) | ((n & 0x3333333333333333ULL) << 2);
|
|
557
|
+
n = ((n >> 4) & 0x0F0F0F0F0F0F0F0FULL) | ((n & 0x0F0F0F0F0F0F0F0FULL) << 4);
|
|
558
|
+
return bswap_64(n);
|
|
559
|
+
#else
|
|
560
|
+
return ReverseBits32( n >> 32 ) |
|
|
561
|
+
(static_cast<uint64>(ReverseBits32(n & 0xffffffff)) << 32);
|
|
562
|
+
#endif
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
inline absl::uint128 Bits::ReverseBits128(absl::uint128 n) {
|
|
566
|
+
return absl::MakeUint128(ReverseBits64(absl::Uint128Low64(n)),
|
|
567
|
+
ReverseBits64(absl::Uint128High64(n)));
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
inline int Bits::Log2FloorNonZero_Portable(uint32 n) {
|
|
571
|
+
// Just use the common routine
|
|
572
|
+
return Log2Floor(n);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// Log2Floor64() is defined in terms of Log2Floor32(), Log2FloorNonZero32()
|
|
576
|
+
inline int Bits::Log2Floor64_Portable(uint64 n) {
|
|
577
|
+
const uint32 topbits = static_cast<uint32>(n >> 32);
|
|
578
|
+
if (topbits == 0) {
|
|
579
|
+
// Top bits are zero, so scan in bottom bits
|
|
580
|
+
return Log2Floor(static_cast<uint32>(n));
|
|
581
|
+
} else {
|
|
582
|
+
return 32 + Log2FloorNonZero(topbits);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// Log2FloorNonZero64() is defined in terms of Log2FloorNonZero32()
|
|
587
|
+
inline int Bits::Log2FloorNonZero64_Portable(uint64 n) {
|
|
588
|
+
const uint32 topbits = static_cast<uint32>(n >> 32);
|
|
589
|
+
if (topbits == 0) {
|
|
590
|
+
// Top bits are zero, so scan in bottom bits
|
|
591
|
+
return Log2FloorNonZero(static_cast<uint32>(n));
|
|
592
|
+
} else {
|
|
593
|
+
return 32 + Log2FloorNonZero(topbits);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// FindLSBSetNonZero64() is defined in terms of FindLSBSetNonZero()
|
|
598
|
+
inline int Bits::FindLSBSetNonZero64_Portable(uint64 n) {
|
|
599
|
+
const uint32 bottombits = static_cast<uint32>(n);
|
|
600
|
+
if (bottombits == 0) {
|
|
601
|
+
// Bottom bits are zero, so scan in top bits
|
|
602
|
+
return 32 + FindLSBSetNonZero(static_cast<uint32>(n >> 32));
|
|
603
|
+
} else {
|
|
604
|
+
return FindLSBSetNonZero(bottombits);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
template <class T>
|
|
609
|
+
inline bool Bits::BytesContainByteLessThan(T bytes, uint8 c) {
|
|
610
|
+
auto l = BitPattern<T>::l;
|
|
611
|
+
auto h = BitPattern<T>::h;
|
|
612
|
+
// The c <= 0x80 code is straight out of Knuth Volume 4.
|
|
613
|
+
// Usually c will be manifestly constant.
|
|
614
|
+
return c <= 0x80 ?
|
|
615
|
+
((h & (bytes - l * c) & ~bytes) != 0) :
|
|
616
|
+
((((bytes - l * c) | (bytes ^ h)) & h) != 0);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
template <class T> inline bool Bits::BytesContainByte(T bytes, uint8 c) {
|
|
620
|
+
// Usually c will be manifestly constant.
|
|
621
|
+
return Bits::BytesContainByteLessThan<T>(bytes ^ (c * BitPattern<T>::l), 1);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
template <class T>
|
|
625
|
+
inline bool Bits::BytesAllInRange(T bytes, uint8 lo, uint8 hi) {
|
|
626
|
+
auto l = BitPattern<T>::l;
|
|
627
|
+
auto h = BitPattern<T>::h;
|
|
628
|
+
// In the common case, lo and hi are manifest constants.
|
|
629
|
+
if (lo > hi) {
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
if (hi - lo < 128) {
|
|
633
|
+
auto x = bytes - l * lo;
|
|
634
|
+
auto y = bytes + l * (127 - hi);
|
|
635
|
+
return ((x | y) & h) == 0;
|
|
636
|
+
}
|
|
637
|
+
return !Bits::BytesContainByteLessThan(bytes + (255 - hi) * l,
|
|
638
|
+
lo + (255 - hi));
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// Specializations for Bits::UnsignedTypeBySize. For unsupported type
|
|
642
|
+
// sizes, a compile-time error will be generated.
|
|
643
|
+
template<>
|
|
644
|
+
struct Bits::UnsignedTypeBySize<1> {
|
|
645
|
+
typedef uint8 Type;
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
template<>
|
|
649
|
+
struct Bits::UnsignedTypeBySize<2> {
|
|
650
|
+
typedef uint16 Type;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
template<>
|
|
654
|
+
struct Bits::UnsignedTypeBySize<4> {
|
|
655
|
+
typedef uint32 Type;
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
template<>
|
|
659
|
+
struct Bits::UnsignedTypeBySize<8> {
|
|
660
|
+
typedef uint64 Type;
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
template<>
|
|
664
|
+
struct Bits::UnsignedTypeBySize<16> {
|
|
665
|
+
typedef absl::uint128 Type;
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
#ifdef __GNUC__
|
|
669
|
+
inline int Bits::CountLeadingZerosWithBuiltin(unsigned n) {
|
|
670
|
+
if (n == 0) {
|
|
671
|
+
return sizeof(n) * 8; // __builtin_clz(0) is undefined.
|
|
672
|
+
}
|
|
673
|
+
return __builtin_clz(n);
|
|
674
|
+
}
|
|
675
|
+
// NOLINTNEXTLINE(runtime/int)
|
|
676
|
+
inline int Bits::CountLeadingZerosWithBuiltin(unsigned long n) {
|
|
677
|
+
if (n == 0) {
|
|
678
|
+
return sizeof(n) * 8; // __builtin_clzl(0) is undefined.
|
|
679
|
+
}
|
|
680
|
+
return __builtin_clzl(n);
|
|
681
|
+
}
|
|
682
|
+
// NOLINTNEXTLINE(runtime/int)
|
|
683
|
+
inline int Bits::CountLeadingZerosWithBuiltin(unsigned long long n) {
|
|
684
|
+
if (n == 0) {
|
|
685
|
+
return sizeof(n) * 8; // __builtin_clzll(0) is undefined.
|
|
686
|
+
}
|
|
687
|
+
return __builtin_clzll(n);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
inline int Bits::PopcountWithBuiltin(unsigned n) {
|
|
691
|
+
return __builtin_popcount(n);
|
|
692
|
+
}
|
|
693
|
+
// NOLINTNEXTLINE(runtime/int)
|
|
694
|
+
inline int Bits::PopcountWithBuiltin(unsigned long n) {
|
|
695
|
+
return __builtin_popcountl(n);
|
|
696
|
+
}
|
|
697
|
+
// NOLINTNEXTLINE(runtime/int)
|
|
698
|
+
inline int Bits::PopcountWithBuiltin(unsigned long long n) {
|
|
699
|
+
return __builtin_popcountll(n);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
#if defined(__BMI__) && (defined(__i386__) || defined(__x86_64__))
|
|
703
|
+
inline uint32 Bits::GetBitsImpl(const uint32 src,
|
|
704
|
+
const int offset,
|
|
705
|
+
const int nbits) {
|
|
706
|
+
return _bextr_u32(src, offset, nbits);
|
|
707
|
+
}
|
|
708
|
+
#endif
|
|
709
|
+
|
|
710
|
+
#if defined(__BMI__) && defined(__x86_64__)
|
|
711
|
+
inline uint64 Bits::GetBitsImpl(const uint64 src,
|
|
712
|
+
const int offset,
|
|
713
|
+
const int nbits) {
|
|
714
|
+
return _bextr_u64(src, offset, nbits);
|
|
715
|
+
}
|
|
716
|
+
#endif
|
|
717
|
+
|
|
718
|
+
#if defined(__BMI2__) && (defined(__i386__) || defined(__x86_64__))
|
|
719
|
+
inline uint32 Bits::GetLowBitsImpl(const uint32 src, const int nbits) {
|
|
720
|
+
return _bzhi_u32(src, nbits);
|
|
721
|
+
}
|
|
722
|
+
#endif
|
|
723
|
+
|
|
724
|
+
#if defined(__BMI2__) && defined(__x86_64__)
|
|
725
|
+
inline uint64 Bits::GetLowBitsImpl(const uint64 src, const int nbits) {
|
|
726
|
+
return _bzhi_u64(src, nbits);
|
|
727
|
+
}
|
|
728
|
+
#endif
|
|
729
|
+
|
|
730
|
+
#endif // __GNUC__
|
|
731
|
+
|
|
732
|
+
template<typename UnsignedT>
|
|
733
|
+
inline UnsignedT Bits::GetBitsImpl(const UnsignedT src,
|
|
734
|
+
const int offset,
|
|
735
|
+
const int nbits) {
|
|
736
|
+
const UnsignedT result = (src >> offset) & NBitsFromLSB<UnsignedT>(nbits);
|
|
737
|
+
return result;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
template<typename UnsignedT>
|
|
741
|
+
inline UnsignedT Bits::GetLowBitsImpl(const UnsignedT src, const int nbits) {
|
|
742
|
+
return GetBitsImpl(src, 0, nbits);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
#endif // S2_UTIL_BITS_BITS_H_
|