koffi 2.1.0-beta.3 → 2.1.0
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/ChangeLog.md +2 -1
- package/build/qemu/2.1.0/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0/koffi_win32_x64.tar.gz +0 -0
- package/doc/benchmarks.md +14 -14
- package/doc/benchmarks.xlsx +0 -0
- package/doc/index.rst +2 -2
- package/doc/static/perf_linux_20220812.png +0 -0
- package/doc/static/perf_windows_20220812.png +0 -0
- package/doc/types.md +10 -12
- package/package.json +2 -2
- package/qemu/registry/machines.json +2 -2
- package/qemu/registry/sha256sum.txt +2 -2
- package/src/abi_arm32.cc +23 -55
- package/src/abi_arm64.cc +22 -54
- package/src/abi_riscv64.cc +20 -52
- package/src/abi_x64_sysv.cc +20 -52
- package/src/abi_x64_win.cc +20 -52
- package/src/abi_x86.cc +24 -56
- package/src/call.cc +117 -143
- package/src/call.hh +4 -4
- package/src/ffi.cc +16 -4
- package/src/util.hh +0 -20
- package/test/callbacks.js +3 -3
- package/test/misc.c +2 -2
- package/test/sync.js +2 -2
- package/vendor/libcc/libcc.cc +75 -55
- package/vendor/libcc/libcc.hh +306 -255
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj +226 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj.filters +10 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj.user +4 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android.sln +75 -0
- package/vendor/raylib/projects/VS2022/examples/audio_module_playing.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/audio_multichannel_sound.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/audio_music_stream.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/audio_raw_stream.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/audio_sound_loading.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/audio_stream_effects.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_2d_camera.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_2d_camera_mouse_zoom.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_2d_camera_platformer.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_3d_camera_first_person.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_3d_camera_free.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_3d_camera_mode.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_3d_picking.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_basic_screen_manager.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_basic_window.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_custom_frame_control.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_custom_logging.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_drop_files.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_input_gamepad.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_input_gestures.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_input_keys.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_input_mouse.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_input_mouse_wheel.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_input_multitouch.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_loading_thread.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_random_values.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_scissor_test.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_split_screen.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_storage_values.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_vr_simulator.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_window_flags.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_window_letterbox.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/core_window_should_close.vcxproj +390 -0
- package/vendor/raylib/projects/VS2022/examples/core_world_screen.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/easings_testbed.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/embedded_files_loading.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_animation.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_billboard.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_box_collisions.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_cubicmap.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_first_person_maze.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_geometric_shapes.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_heightmap.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_loading.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_loading_gltf.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_loading_vox.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_mesh_generation.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_mesh_picking.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_orthographic_projection.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_rlgl_solar_system.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_skybox.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_waving_cubes.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/models_yaw_pitch_roll.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/rlgl_compute_shaders.vcxproj +391 -0
- package/vendor/raylib/projects/VS2022/examples/rlgl_standalone.vcxproj +391 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_basic_lighting.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_custom_uniform.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_eratosthenes.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_fog.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_hot_reloading.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_julia_set.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_mesh_instancing.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_model_shader.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_multi_sample2d.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_palette_switch.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_postprocessing.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_raymarching.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_shapes_textures.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_simple_mask.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_spotlight.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_texture_drawing.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shaders_texture_waves.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_basic_shapes.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_bouncing_ball.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_collision_area.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_colors_palette.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_draw_circle_sector.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_draw_rectangle_rounded.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_draw_ring.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_easings_ball_anim.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_easings_box_anim.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_easings_rectangle_array.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_following_eyes.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_lines_bezier.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_logo_raylib.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_logo_raylib_anim.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/shapes_rectangle_scaling.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_codepoints_loading.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_draw_3d.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_font_filters.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_font_loading.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_font_sdf.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_font_spritefont.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_format_text.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_input_box.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_raylib_fonts.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_rectangle_bounds.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_unicode.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/text_writing_anim.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_background_scrolling.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_blend_modes.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_bunnymark.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_draw_tiled.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_fog_of_war.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_gif_player.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_image_drawing.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_image_generation.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_image_loading.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_image_processing.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_image_text.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_logo_raylib.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_mouse_painting.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_npatch_drawing.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_particles_blending.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_polygon.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_raw_data.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_sprite_anim.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_sprite_button.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_sprite_explosion.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_srcrec_dstrec.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/examples/textures_to_image.vcxproj +387 -0
- package/vendor/raylib/projects/VS2022/raylib/raylib.vcxproj +340 -0
- package/vendor/raylib/projects/VS2022/raylib.sln +2347 -0
- package/build/qemu/2.1.0-beta.3/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_win32_x64.tar.gz +0 -0
- package/doc/dist/doctrees/benchmarks.doctree +0 -0
- package/doc/dist/doctrees/changes.doctree +0 -0
- package/doc/dist/doctrees/contribute.doctree +0 -0
- package/doc/dist/doctrees/environment.pickle +0 -0
- package/doc/dist/doctrees/functions.doctree +0 -0
- package/doc/dist/doctrees/index.doctree +0 -0
- package/doc/dist/doctrees/memory.doctree +0 -0
- package/doc/dist/doctrees/platforms.doctree +0 -0
- package/doc/dist/doctrees/start.doctree +0 -0
- package/doc/dist/doctrees/types.doctree +0 -0
- package/doc/dist/html/.buildinfo +0 -4
- package/doc/dist/html/_sources/benchmarks.md.txt +0 -137
- package/doc/dist/html/_sources/changes.md.txt +0 -161
- package/doc/dist/html/_sources/contribute.md.txt +0 -127
- package/doc/dist/html/_sources/functions.md.txt +0 -421
- package/doc/dist/html/_sources/index.rst.txt +0 -39
- package/doc/dist/html/_sources/memory.md.txt +0 -32
- package/doc/dist/html/_sources/platforms.md.txt +0 -31
- package/doc/dist/html/_sources/start.md.txt +0 -100
- package/doc/dist/html/_sources/types.md.txt +0 -541
- package/doc/dist/html/_static/_sphinx_javascript_frameworks_compat.js +0 -134
- package/doc/dist/html/_static/basic.css +0 -932
- package/doc/dist/html/_static/bench_linux.png +0 -0
- package/doc/dist/html/_static/bench_windows.png +0 -0
- package/doc/dist/html/_static/custom.css +0 -22
- package/doc/dist/html/_static/debug.css +0 -69
- package/doc/dist/html/_static/doctools.js +0 -264
- package/doc/dist/html/_static/documentation_options.js +0 -14
- package/doc/dist/html/_static/file.png +0 -0
- package/doc/dist/html/_static/jquery-3.6.0.js +0 -10881
- package/doc/dist/html/_static/jquery.js +0 -2
- package/doc/dist/html/_static/language_data.js +0 -199
- package/doc/dist/html/_static/minus.png +0 -0
- package/doc/dist/html/_static/perf_linux_20220623.png +0 -0
- package/doc/dist/html/_static/perf_linux_20220623_2.png +0 -0
- package/doc/dist/html/_static/perf_linux_20220627.png +0 -0
- package/doc/dist/html/_static/perf_linux_20220628.png +0 -0
- package/doc/dist/html/_static/perf_windows_20220623.png +0 -0
- package/doc/dist/html/_static/perf_windows_20220623_2.png +0 -0
- package/doc/dist/html/_static/perf_windows_20220627.png +0 -0
- package/doc/dist/html/_static/perf_windows_20220628.png +0 -0
- package/doc/dist/html/_static/plus.png +0 -0
- package/doc/dist/html/_static/pygments.css +0 -252
- package/doc/dist/html/_static/scripts/furo-extensions.js +0 -0
- package/doc/dist/html/_static/scripts/furo.js +0 -3
- package/doc/dist/html/_static/scripts/furo.js.LICENSE.txt +0 -7
- package/doc/dist/html/_static/scripts/furo.js.map +0 -1
- package/doc/dist/html/_static/searchtools.js +0 -531
- package/doc/dist/html/_static/skeleton.css +0 -296
- package/doc/dist/html/_static/styles/furo-extensions.css +0 -2
- package/doc/dist/html/_static/styles/furo-extensions.css.map +0 -1
- package/doc/dist/html/_static/styles/furo.css +0 -2
- package/doc/dist/html/_static/styles/furo.css.map +0 -1
- package/doc/dist/html/_static/underscore-1.13.1.js +0 -2042
- package/doc/dist/html/_static/underscore.js +0 -6
- package/doc/dist/html/benchmarks.html +0 -571
- package/doc/dist/html/changes.html +0 -686
- package/doc/dist/html/contribute.html +0 -403
- package/doc/dist/html/functions.html +0 -718
- package/doc/dist/html/genindex.html +0 -253
- package/doc/dist/html/index.html +0 -359
- package/doc/dist/html/memory.html +0 -346
- package/doc/dist/html/objects.inv +0 -0
- package/doc/dist/html/platforms.html +0 -371
- package/doc/dist/html/search.html +0 -261
- package/doc/dist/html/searchindex.js +0 -1
- package/doc/dist/html/start.html +0 -384
- package/doc/dist/html/types.html +0 -1061
package/vendor/libcc/libcc.hh
CHANGED
|
@@ -109,9 +109,14 @@ extern "C" const char *FelixCompiler;
|
|
|
109
109
|
#error Machine architecture not supported
|
|
110
110
|
#endif
|
|
111
111
|
|
|
112
|
-
#if
|
|
113
|
-
|
|
112
|
+
#if defined(_MSC_VER) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
113
|
+
// Sane platform
|
|
114
|
+
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
115
|
+
#define RG_BIG_ENDIAN
|
|
116
|
+
#else
|
|
117
|
+
#error This code base is not designed to support platforms with crazy endianness
|
|
114
118
|
#endif
|
|
119
|
+
|
|
115
120
|
#if UINT_MAX != 0xFFFFFFFFu
|
|
116
121
|
#error This code base is not designed to support non-32-bits int types
|
|
117
122
|
#endif
|
|
@@ -302,11 +307,17 @@ static inline constexpr int32_t ReverseBytes(int32_t i)
|
|
|
302
307
|
static inline constexpr int64_t ReverseBytes(int64_t i)
|
|
303
308
|
{ return (int64_t)ReverseBytes((uint64_t)i); }
|
|
304
309
|
|
|
305
|
-
|
|
310
|
+
#ifdef RG_BIG_ENDIAN
|
|
311
|
+
template <typename T>
|
|
312
|
+
constexpr T LittleEndian(T v) { return ReverseBytes(v); }
|
|
313
|
+
template <typename T>
|
|
314
|
+
constexpr T BigEndian(T v) { return v; }
|
|
315
|
+
#else
|
|
306
316
|
template <typename T>
|
|
307
317
|
constexpr T LittleEndian(T v) { return v; }
|
|
308
318
|
template <typename T>
|
|
309
319
|
constexpr T BigEndian(T v) { return ReverseBytes(v); }
|
|
320
|
+
#endif
|
|
310
321
|
|
|
311
322
|
#if defined(__GNUC__)
|
|
312
323
|
static inline int CountLeadingZeros(uint32_t u)
|
|
@@ -445,6 +456,26 @@ constexpr T BigEndian(T v) { return ReverseBytes(v); }
|
|
|
445
456
|
#error No implementation of CountLeadingZeros(), CountTrailingZeros() and PopCount() for this compiler / toolchain
|
|
446
457
|
#endif
|
|
447
458
|
|
|
459
|
+
static inline Size AlignLen(Size len, Size align)
|
|
460
|
+
{
|
|
461
|
+
Size aligned = (len + align - 1) / align * align;
|
|
462
|
+
return aligned;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
template <typename T>
|
|
466
|
+
static inline T *AlignUp(T *ptr, Size align)
|
|
467
|
+
{
|
|
468
|
+
uint8_t *aligned = (uint8_t *)(((uintptr_t)ptr + align - 1) / align * align);
|
|
469
|
+
return (T *)aligned;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
template <typename T>
|
|
473
|
+
static inline T *AlignDown(T *ptr, Size align)
|
|
474
|
+
{
|
|
475
|
+
uint8_t *aligned = (uint8_t *)((uintptr_t)ptr / align * align);
|
|
476
|
+
return (T *)aligned;
|
|
477
|
+
}
|
|
478
|
+
|
|
448
479
|
// Calling memcpy (and friends) with a NULL source pointer is undefined behavior
|
|
449
480
|
// even if length is 0. This is dumb, work around this.
|
|
450
481
|
static inline void *memcpy_safe(void *dest, const void *src, size_t len)
|
|
@@ -619,10 +650,179 @@ struct Vec3 {
|
|
|
619
650
|
// Memory / Allocator
|
|
620
651
|
// ------------------------------------------------------------------------
|
|
621
652
|
|
|
622
|
-
|
|
653
|
+
// I'd love to make Span default to { nullptr, 0 } but unfortunately that makes
|
|
654
|
+
// it a non-POD and prevents putting it in a union.
|
|
655
|
+
template <typename T>
|
|
656
|
+
struct Span {
|
|
657
|
+
T *ptr;
|
|
658
|
+
Size len;
|
|
623
659
|
|
|
624
|
-
|
|
625
|
-
|
|
660
|
+
Span() = default;
|
|
661
|
+
constexpr Span(T &value) : ptr(&value), len(1) {}
|
|
662
|
+
constexpr Span(std::initializer_list<T> l) : ptr(l.begin()), len((Size)l.size()) {}
|
|
663
|
+
constexpr Span(T *ptr_, Size len_) : ptr(ptr_), len(len_) {}
|
|
664
|
+
template <Size N>
|
|
665
|
+
constexpr Span(T (&arr)[N]) : ptr(arr), len(N) {}
|
|
666
|
+
|
|
667
|
+
void Reset()
|
|
668
|
+
{
|
|
669
|
+
ptr = nullptr;
|
|
670
|
+
len = 0;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
T *begin() { return ptr; }
|
|
674
|
+
const T *begin() const { return ptr; }
|
|
675
|
+
T *end() { return ptr + len; }
|
|
676
|
+
const T *end() const { return ptr + len; }
|
|
677
|
+
|
|
678
|
+
bool IsValid() const { return ptr; }
|
|
679
|
+
|
|
680
|
+
T &operator[](Size idx)
|
|
681
|
+
{
|
|
682
|
+
RG_ASSERT(idx >= 0 && idx < len);
|
|
683
|
+
return ptr[idx];
|
|
684
|
+
}
|
|
685
|
+
const T &operator[](Size idx) const
|
|
686
|
+
{
|
|
687
|
+
RG_ASSERT(idx >= 0 && idx < len);
|
|
688
|
+
return ptr[idx];
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
operator Span<const T>() const { return Span<const T>(ptr, len); }
|
|
692
|
+
|
|
693
|
+
bool operator==(const Span &other) const
|
|
694
|
+
{
|
|
695
|
+
if (len != other.len)
|
|
696
|
+
return false;
|
|
697
|
+
|
|
698
|
+
for (Size i = 0; i < len; i++) {
|
|
699
|
+
if (ptr[i] != other.ptr[i])
|
|
700
|
+
return false;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
return true;
|
|
704
|
+
}
|
|
705
|
+
bool operator!=(const Span &other) const { return !(*this == other); }
|
|
706
|
+
|
|
707
|
+
Span Take(Size offset, Size sub_len) const
|
|
708
|
+
{
|
|
709
|
+
RG_ASSERT(sub_len >= 0 && sub_len <= len);
|
|
710
|
+
RG_ASSERT(offset >= 0 && offset <= len - sub_len);
|
|
711
|
+
|
|
712
|
+
Span<T> sub;
|
|
713
|
+
sub.ptr = ptr + offset;
|
|
714
|
+
sub.len = sub_len;
|
|
715
|
+
return sub;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
template <typename U>
|
|
719
|
+
Span<U> As() const { return Span<U>((U *)ptr, len); }
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
// Use strlen() to build Span<const char> instead of the template-based
|
|
723
|
+
// array constructor.
|
|
724
|
+
template <>
|
|
725
|
+
struct Span<const char> {
|
|
726
|
+
const char *ptr;
|
|
727
|
+
Size len;
|
|
728
|
+
|
|
729
|
+
Span() = default;
|
|
730
|
+
constexpr Span(const char &ch) : ptr(&ch), len(1) {}
|
|
731
|
+
constexpr Span(const char *ptr_, Size len_) : ptr(ptr_), len(len_) {}
|
|
732
|
+
#ifdef __clang__
|
|
733
|
+
constexpr Span(const char *const &str) : ptr(str), len(str ? (Size)__builtin_strlen(str) : 0) {}
|
|
734
|
+
#else
|
|
735
|
+
constexpr Span(const char *const &str) : ptr(str), len(str ? (Size)strlen(str) : 0) {}
|
|
736
|
+
#endif
|
|
737
|
+
|
|
738
|
+
void Reset()
|
|
739
|
+
{
|
|
740
|
+
ptr = nullptr;
|
|
741
|
+
len = 0;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
const char *begin() const { return ptr; }
|
|
745
|
+
const char *end() const { return ptr + len; }
|
|
746
|
+
|
|
747
|
+
bool IsValid() const { return ptr; }
|
|
748
|
+
|
|
749
|
+
char operator[](Size idx) const
|
|
750
|
+
{
|
|
751
|
+
RG_ASSERT(idx >= 0 && idx < len);
|
|
752
|
+
return ptr[idx];
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// The implementation comes later, after TestStr() is available
|
|
756
|
+
bool operator==(Span<const char> other) const;
|
|
757
|
+
bool operator==(const char *other) const;
|
|
758
|
+
bool operator!=(Span<const char> other) const { return !(*this == other); }
|
|
759
|
+
bool operator!=(const char *other) const { return !(*this == other); }
|
|
760
|
+
|
|
761
|
+
Span Take(Size offset, Size sub_len) const
|
|
762
|
+
{
|
|
763
|
+
RG_ASSERT(sub_len >= 0 && sub_len <= len);
|
|
764
|
+
RG_ASSERT(offset >= 0 && offset <= len - sub_len);
|
|
765
|
+
|
|
766
|
+
Span<const char> sub;
|
|
767
|
+
sub.ptr = ptr + offset;
|
|
768
|
+
sub.len = sub_len;
|
|
769
|
+
return sub;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
template <typename U>
|
|
773
|
+
Span<U> As() const { return Span<U>((U *)ptr, len); }
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
template <typename T>
|
|
777
|
+
static inline constexpr Span<T> MakeSpan(T *ptr, Size len)
|
|
778
|
+
{
|
|
779
|
+
return Span<T>(ptr, len);
|
|
780
|
+
}
|
|
781
|
+
template <typename T>
|
|
782
|
+
static inline constexpr Span<T> MakeSpan(T *ptr, T *end)
|
|
783
|
+
{
|
|
784
|
+
return Span<T>(ptr, end - ptr);
|
|
785
|
+
}
|
|
786
|
+
template <typename T, Size N>
|
|
787
|
+
static inline constexpr Span<T> MakeSpan(T (&arr)[N])
|
|
788
|
+
{
|
|
789
|
+
return Span<T>(arr, N);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
template <typename T>
|
|
793
|
+
class Strider {
|
|
794
|
+
public:
|
|
795
|
+
void *ptr = nullptr;
|
|
796
|
+
Size stride;
|
|
797
|
+
|
|
798
|
+
Strider() = default;
|
|
799
|
+
constexpr Strider(T *ptr_) : ptr(ptr_), stride(RG_SIZE(T)) {}
|
|
800
|
+
constexpr Strider(T *ptr_, Size stride_) : ptr(ptr_), stride(stride_) {}
|
|
801
|
+
|
|
802
|
+
bool IsValid() const { return ptr; }
|
|
803
|
+
|
|
804
|
+
T &operator[](Size idx) const
|
|
805
|
+
{
|
|
806
|
+
RG_ASSERT(idx >= 0);
|
|
807
|
+
return *(T *)((uint8_t *)ptr + (idx * stride));
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
template <typename T>
|
|
812
|
+
static inline constexpr Strider<T> MakeStrider(T *ptr)
|
|
813
|
+
{
|
|
814
|
+
return Strider<T>(ptr, RG_SIZE(T));
|
|
815
|
+
}
|
|
816
|
+
template <typename T>
|
|
817
|
+
static inline constexpr Strider<T> MakeStrider(T *ptr, Size stride)
|
|
818
|
+
{
|
|
819
|
+
return Strider<T>(ptr, stride);
|
|
820
|
+
}
|
|
821
|
+
template <typename T, Size N>
|
|
822
|
+
static inline constexpr Strider<T> MakeStrider(T (&arr)[N])
|
|
823
|
+
{
|
|
824
|
+
return Strider<T>(arr, RG_SIZE(T));
|
|
825
|
+
}
|
|
626
826
|
|
|
627
827
|
class Allocator {
|
|
628
828
|
RG_DELETE_COPY(Allocator)
|
|
@@ -636,40 +836,60 @@ public:
|
|
|
636
836
|
Allocator() = default;
|
|
637
837
|
virtual ~Allocator() = default;
|
|
638
838
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
839
|
+
virtual void *Allocate(Size size, unsigned int flags = 0) = 0;
|
|
840
|
+
virtual void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags = 0) = 0;
|
|
841
|
+
virtual void Release(void *ptr, Size size) = 0;
|
|
842
|
+
};
|
|
642
843
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
844
|
+
Allocator *GetDefaultAllocator();
|
|
845
|
+
Allocator *GetNullAllocator();
|
|
846
|
+
|
|
847
|
+
template <typename T>
|
|
848
|
+
Span<T> AllocateMemory(Allocator *alloc, Size size, unsigned int flags = 0)
|
|
849
|
+
{
|
|
850
|
+
RG_ASSERT(size >= 0);
|
|
851
|
+
|
|
852
|
+
if (!alloc) {
|
|
853
|
+
alloc = GetDefaultAllocator();
|
|
647
854
|
}
|
|
648
855
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
RG_ASSERT(new_size >= 0);
|
|
856
|
+
T *ptr = (T *)alloc->Allocate(size, flags);
|
|
857
|
+
return MakeSpan(ptr, size);
|
|
858
|
+
}
|
|
653
859
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
860
|
+
template <typename T>
|
|
861
|
+
Span<T> ResizeMemory(Allocator *alloc, T *ptr, Size old_size, Size new_size,
|
|
862
|
+
unsigned int flags = 0)
|
|
863
|
+
{
|
|
864
|
+
RG_ASSERT(new_size >= 0);
|
|
865
|
+
|
|
866
|
+
if (!alloc) {
|
|
867
|
+
alloc = GetDefaultAllocator();
|
|
658
868
|
}
|
|
659
869
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
870
|
+
alloc->Resize((void **)&ptr, old_size, new_size, flags);
|
|
871
|
+
return MakeSpan(ptr, new_size);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
template<typename T>
|
|
875
|
+
void ReleaseMemory(Allocator *alloc, Span<T> mem)
|
|
876
|
+
{
|
|
877
|
+
if (!alloc) {
|
|
878
|
+
alloc = GetDefaultAllocator();
|
|
666
879
|
}
|
|
667
880
|
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
881
|
+
alloc->Release((void *)mem.ptr, mem.len);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
template<typename T>
|
|
885
|
+
void ReleaseMemory(Allocator *alloc, T *ptr, Size size)
|
|
886
|
+
{
|
|
887
|
+
if (!alloc) {
|
|
888
|
+
alloc = GetDefaultAllocator();
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
alloc->Release((void *)ptr, size);
|
|
892
|
+
}
|
|
673
893
|
|
|
674
894
|
class LinkedAllocator final: public Allocator {
|
|
675
895
|
struct Node {
|
|
@@ -679,7 +899,7 @@ class LinkedAllocator final: public Allocator {
|
|
|
679
899
|
struct Bucket {
|
|
680
900
|
// Keep head first or stuff will break
|
|
681
901
|
Node head;
|
|
682
|
-
|
|
902
|
+
uint8_t data[8]; // Extra size is used to align pointer
|
|
683
903
|
};
|
|
684
904
|
|
|
685
905
|
Allocator *allocator;
|
|
@@ -696,9 +916,8 @@ public:
|
|
|
696
916
|
|
|
697
917
|
void ReleaseAll();
|
|
698
918
|
|
|
699
|
-
|
|
700
|
-
void
|
|
701
|
-
void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags) override;
|
|
919
|
+
void *Allocate(Size size, unsigned int flags = 0) override;
|
|
920
|
+
void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags = 0) override;
|
|
702
921
|
void Release(void *ptr, Size size) override;
|
|
703
922
|
|
|
704
923
|
private:
|
|
@@ -709,7 +928,7 @@ private:
|
|
|
709
928
|
class BlockAllocatorBase: public Allocator {
|
|
710
929
|
struct Bucket {
|
|
711
930
|
Size used;
|
|
712
|
-
|
|
931
|
+
uint8_t data[8]; // Extra size is used to align pointer
|
|
713
932
|
};
|
|
714
933
|
|
|
715
934
|
Size block_size;
|
|
@@ -724,11 +943,11 @@ public:
|
|
|
724
943
|
RG_ASSERT(block_size > 0);
|
|
725
944
|
}
|
|
726
945
|
|
|
727
|
-
|
|
728
|
-
void
|
|
729
|
-
void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags) override;
|
|
946
|
+
void *Allocate(Size size, unsigned int flags = 0) override;
|
|
947
|
+
void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags = 0) override;
|
|
730
948
|
void Release(void *ptr, Size size) override;
|
|
731
949
|
|
|
950
|
+
protected:
|
|
732
951
|
void CopyFrom(BlockAllocatorBase *other);
|
|
733
952
|
void ForgetCurrentBlock();
|
|
734
953
|
|
|
@@ -736,9 +955,6 @@ protected:
|
|
|
736
955
|
|
|
737
956
|
private:
|
|
738
957
|
bool AllocateSeparately(Size aligned_size) const { return aligned_size >= block_size / 2; }
|
|
739
|
-
|
|
740
|
-
static Size AlignSizeValue(Size size)
|
|
741
|
-
{ return (RG_SIZE(Bucket) + size + 7) / 8 * 8 - RG_SIZE(Bucket); }
|
|
742
958
|
};
|
|
743
959
|
|
|
744
960
|
class BlockAllocator final: public BlockAllocatorBase {
|
|
@@ -873,180 +1089,6 @@ public:
|
|
|
873
1089
|
// Collections
|
|
874
1090
|
// ------------------------------------------------------------------------
|
|
875
1091
|
|
|
876
|
-
// I'd love to make Span default to { nullptr, 0 } but unfortunately that makes
|
|
877
|
-
// it a non-POD and prevents putting it in a union.
|
|
878
|
-
template <typename T>
|
|
879
|
-
struct Span {
|
|
880
|
-
T *ptr;
|
|
881
|
-
Size len;
|
|
882
|
-
|
|
883
|
-
Span() = default;
|
|
884
|
-
constexpr Span(T &value) : ptr(&value), len(1) {}
|
|
885
|
-
constexpr Span(std::initializer_list<T> l) : ptr(l.begin()), len((Size)l.size()) {}
|
|
886
|
-
constexpr Span(T *ptr_, Size len_) : ptr(ptr_), len(len_) {}
|
|
887
|
-
template <Size N>
|
|
888
|
-
constexpr Span(T (&arr)[N]) : ptr(arr), len(N) {}
|
|
889
|
-
|
|
890
|
-
void Reset()
|
|
891
|
-
{
|
|
892
|
-
ptr = nullptr;
|
|
893
|
-
len = 0;
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
T *begin() { return ptr; }
|
|
897
|
-
const T *begin() const { return ptr; }
|
|
898
|
-
T *end() { return ptr + len; }
|
|
899
|
-
const T *end() const { return ptr + len; }
|
|
900
|
-
|
|
901
|
-
bool IsValid() const { return ptr; }
|
|
902
|
-
|
|
903
|
-
T &operator[](Size idx)
|
|
904
|
-
{
|
|
905
|
-
RG_ASSERT(idx >= 0 && idx < len);
|
|
906
|
-
return ptr[idx];
|
|
907
|
-
}
|
|
908
|
-
const T &operator[](Size idx) const
|
|
909
|
-
{
|
|
910
|
-
RG_ASSERT(idx >= 0 && idx < len);
|
|
911
|
-
return ptr[idx];
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
operator Span<const T>() const { return Span<const T>(ptr, len); }
|
|
915
|
-
|
|
916
|
-
bool operator==(const Span &other) const
|
|
917
|
-
{
|
|
918
|
-
if (len != other.len)
|
|
919
|
-
return false;
|
|
920
|
-
|
|
921
|
-
for (Size i = 0; i < len; i++) {
|
|
922
|
-
if (ptr[i] != other.ptr[i])
|
|
923
|
-
return false;
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
return true;
|
|
927
|
-
}
|
|
928
|
-
bool operator!=(const Span &other) const { return !(*this == other); }
|
|
929
|
-
|
|
930
|
-
Span Take(Size offset, Size sub_len) const
|
|
931
|
-
{
|
|
932
|
-
RG_ASSERT(sub_len >= 0 && sub_len <= len);
|
|
933
|
-
RG_ASSERT(offset >= 0 && offset <= len - sub_len);
|
|
934
|
-
|
|
935
|
-
Span<T> sub;
|
|
936
|
-
sub.ptr = ptr + offset;
|
|
937
|
-
sub.len = sub_len;
|
|
938
|
-
return sub;
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
template <typename U>
|
|
942
|
-
Span<U> As() const { return Span<U>((U *)ptr, len); }
|
|
943
|
-
};
|
|
944
|
-
|
|
945
|
-
// Use strlen() to build Span<const char> instead of the template-based
|
|
946
|
-
// array constructor.
|
|
947
|
-
template <>
|
|
948
|
-
struct Span<const char> {
|
|
949
|
-
const char *ptr;
|
|
950
|
-
Size len;
|
|
951
|
-
|
|
952
|
-
Span() = default;
|
|
953
|
-
constexpr Span(const char &ch) : ptr(&ch), len(1) {}
|
|
954
|
-
constexpr Span(const char *ptr_, Size len_) : ptr(ptr_), len(len_) {}
|
|
955
|
-
#ifdef __clang__
|
|
956
|
-
constexpr Span(const char *const &str) : ptr(str), len(str ? (Size)__builtin_strlen(str) : 0) {}
|
|
957
|
-
#else
|
|
958
|
-
constexpr Span(const char *const &str) : ptr(str), len(str ? (Size)strlen(str) : 0) {}
|
|
959
|
-
#endif
|
|
960
|
-
|
|
961
|
-
void Reset()
|
|
962
|
-
{
|
|
963
|
-
ptr = nullptr;
|
|
964
|
-
len = 0;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
const char *begin() const { return ptr; }
|
|
968
|
-
const char *end() const { return ptr + len; }
|
|
969
|
-
|
|
970
|
-
bool IsValid() const { return ptr; }
|
|
971
|
-
|
|
972
|
-
char operator[](Size idx) const
|
|
973
|
-
{
|
|
974
|
-
RG_ASSERT(idx >= 0 && idx < len);
|
|
975
|
-
return ptr[idx];
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
// The implementation comes later, after TestStr() is available
|
|
979
|
-
bool operator==(Span<const char> other) const;
|
|
980
|
-
bool operator==(const char *other) const;
|
|
981
|
-
bool operator!=(Span<const char> other) const { return !(*this == other); }
|
|
982
|
-
bool operator!=(const char *other) const { return !(*this == other); }
|
|
983
|
-
|
|
984
|
-
Span Take(Size offset, Size sub_len) const
|
|
985
|
-
{
|
|
986
|
-
RG_ASSERT(sub_len >= 0 && sub_len <= len);
|
|
987
|
-
RG_ASSERT(offset >= 0 && offset <= len - sub_len);
|
|
988
|
-
|
|
989
|
-
Span<const char> sub;
|
|
990
|
-
sub.ptr = ptr + offset;
|
|
991
|
-
sub.len = sub_len;
|
|
992
|
-
return sub;
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
template <typename U>
|
|
996
|
-
Span<U> As() const { return Span<U>((U *)ptr, len); }
|
|
997
|
-
};
|
|
998
|
-
|
|
999
|
-
template <typename T>
|
|
1000
|
-
static inline constexpr Span<T> MakeSpan(T *ptr, Size len)
|
|
1001
|
-
{
|
|
1002
|
-
return Span<T>(ptr, len);
|
|
1003
|
-
}
|
|
1004
|
-
template <typename T>
|
|
1005
|
-
static inline constexpr Span<T> MakeSpan(T *ptr, T *end)
|
|
1006
|
-
{
|
|
1007
|
-
return Span<T>(ptr, end - ptr);
|
|
1008
|
-
}
|
|
1009
|
-
template <typename T, Size N>
|
|
1010
|
-
static inline constexpr Span<T> MakeSpan(T (&arr)[N])
|
|
1011
|
-
{
|
|
1012
|
-
return Span<T>(arr, N);
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
template <typename T>
|
|
1016
|
-
class Strider {
|
|
1017
|
-
public:
|
|
1018
|
-
void *ptr = nullptr;
|
|
1019
|
-
Size stride;
|
|
1020
|
-
|
|
1021
|
-
Strider() = default;
|
|
1022
|
-
constexpr Strider(T *ptr_) : ptr(ptr_), stride(RG_SIZE(T)) {}
|
|
1023
|
-
constexpr Strider(T *ptr_, Size stride_) : ptr(ptr_), stride(stride_) {}
|
|
1024
|
-
|
|
1025
|
-
bool IsValid() const { return ptr; }
|
|
1026
|
-
|
|
1027
|
-
T &operator[](Size idx) const
|
|
1028
|
-
{
|
|
1029
|
-
RG_ASSERT(idx >= 0);
|
|
1030
|
-
return *(T *)((uint8_t *)ptr + (idx * stride));
|
|
1031
|
-
}
|
|
1032
|
-
};
|
|
1033
|
-
|
|
1034
|
-
template <typename T>
|
|
1035
|
-
static inline constexpr Strider<T> MakeStrider(T *ptr)
|
|
1036
|
-
{
|
|
1037
|
-
return Strider<T>(ptr, RG_SIZE(T));
|
|
1038
|
-
}
|
|
1039
|
-
template <typename T>
|
|
1040
|
-
static inline constexpr Strider<T> MakeStrider(T *ptr, Size stride)
|
|
1041
|
-
{
|
|
1042
|
-
return Strider<T>(ptr, stride);
|
|
1043
|
-
}
|
|
1044
|
-
template <typename T, Size N>
|
|
1045
|
-
static inline constexpr Strider<T> MakeStrider(T (&arr)[N])
|
|
1046
|
-
{
|
|
1047
|
-
return Strider<T>(arr, RG_SIZE(T));
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
1092
|
template <typename T, Size N, Size AlignAs = alignof(T)>
|
|
1051
1093
|
class LocalArray {
|
|
1052
1094
|
public:
|
|
@@ -1273,8 +1315,7 @@ public:
|
|
|
1273
1315
|
len = new_capacity;
|
|
1274
1316
|
}
|
|
1275
1317
|
|
|
1276
|
-
|
|
1277
|
-
capacity * RG_SIZE(T), new_capacity * RG_SIZE(T));
|
|
1318
|
+
ptr = ResizeMemory(allocator, ptr, capacity * RG_SIZE(T), new_capacity * RG_SIZE(T)).ptr;
|
|
1278
1319
|
capacity = new_capacity;
|
|
1279
1320
|
}
|
|
1280
1321
|
}
|
|
@@ -1571,9 +1612,9 @@ public:
|
|
|
1571
1612
|
Size bucket_offset = (offset + len) % BucketSize;
|
|
1572
1613
|
|
|
1573
1614
|
if (bucket_idx >= buckets.len) {
|
|
1574
|
-
Bucket *new_bucket =
|
|
1615
|
+
Bucket *new_bucket = AllocateMemory<Bucket>(buckets.allocator, RG_SIZE(Bucket)).ptr;
|
|
1575
1616
|
new (&new_bucket->allocator) AllocatorType();
|
|
1576
|
-
new_bucket->values =
|
|
1617
|
+
new_bucket->values = AllocateMemory<T>(&new_bucket->allocator, BucketSize * RG_SIZE(T)).ptr;
|
|
1577
1618
|
|
|
1578
1619
|
buckets.Append(new_bucket);
|
|
1579
1620
|
}
|
|
@@ -1690,7 +1731,7 @@ private:
|
|
|
1690
1731
|
void DeleteBucket(Bucket *bucket)
|
|
1691
1732
|
{
|
|
1692
1733
|
bucket->allocator.~AllocatorType();
|
|
1693
|
-
|
|
1734
|
+
ReleaseMemory(buckets.allocator, bucket, RG_SIZE(Bucket));
|
|
1694
1735
|
}
|
|
1695
1736
|
};
|
|
1696
1737
|
|
|
@@ -2203,10 +2244,10 @@ private:
|
|
|
2203
2244
|
Size old_capacity = capacity;
|
|
2204
2245
|
|
|
2205
2246
|
if (new_capacity) {
|
|
2206
|
-
used =
|
|
2247
|
+
used = AllocateMemory<size_t>(allocator,
|
|
2207
2248
|
(new_capacity + (RG_SIZE(size_t) * 8) - 1) / RG_SIZE(size_t),
|
|
2208
|
-
(int)Allocator::Flag::Zero);
|
|
2209
|
-
data =
|
|
2249
|
+
(int)Allocator::Flag::Zero).ptr;
|
|
2250
|
+
data = AllocateMemory<ValueType>(allocator, new_capacity * RG_SIZE(ValueType)).ptr;
|
|
2210
2251
|
for (Size i = 0; i < new_capacity; i++) {
|
|
2211
2252
|
new (&data[i]) ValueType();
|
|
2212
2253
|
}
|
|
@@ -2228,9 +2269,9 @@ private:
|
|
|
2228
2269
|
capacity = 0;
|
|
2229
2270
|
}
|
|
2230
2271
|
|
|
2231
|
-
|
|
2272
|
+
ReleaseMemory(allocator, old_used,
|
|
2232
2273
|
(old_capacity + (RG_SIZE(size_t) * 8) - 1) / RG_SIZE(size_t));
|
|
2233
|
-
|
|
2274
|
+
ReleaseMemory(allocator, old_data, old_capacity * RG_SIZE(ValueType));
|
|
2234
2275
|
}
|
|
2235
2276
|
|
|
2236
2277
|
void MarkUsed(Size idx)
|
|
@@ -2554,18 +2595,28 @@ public:
|
|
|
2554
2595
|
// Date
|
|
2555
2596
|
// ------------------------------------------------------------------------
|
|
2556
2597
|
|
|
2557
|
-
union
|
|
2598
|
+
union LocalDate {
|
|
2558
2599
|
int32_t value;
|
|
2559
2600
|
struct {
|
|
2560
|
-
|
|
2601
|
+
#ifdef RG_BIG_ENDIAN
|
|
2602
|
+
int16_t year;
|
|
2603
|
+
int8_t month;
|
|
2604
|
+
int8_t day;
|
|
2605
|
+
#else
|
|
2561
2606
|
int8_t day;
|
|
2562
2607
|
int8_t month;
|
|
2563
2608
|
int16_t year;
|
|
2609
|
+
#endif
|
|
2564
2610
|
} st;
|
|
2565
2611
|
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2612
|
+
LocalDate() = default;
|
|
2613
|
+
#ifdef RG_BIG_ENDIAN
|
|
2614
|
+
LocalDate(int16_t year, int8_t month, int8_t day)
|
|
2615
|
+
: st({year, month, day}) { RG_ASSERT(IsValid()); }
|
|
2616
|
+
#else
|
|
2617
|
+
LocalDate(int16_t year, int8_t month, int8_t day)
|
|
2618
|
+
: st({day, month, year}) { RG_ASSERT(IsValid()); }
|
|
2619
|
+
#endif
|
|
2569
2620
|
|
|
2570
2621
|
static inline bool IsLeapYear(int16_t year)
|
|
2571
2622
|
{
|
|
@@ -2577,10 +2628,10 @@ union Date {
|
|
|
2577
2628
|
return (int8_t)(DaysPerMonth[month - 1] + (month == 2 && IsLeapYear(year)));
|
|
2578
2629
|
}
|
|
2579
2630
|
|
|
2580
|
-
static
|
|
2581
|
-
|
|
2582
|
-
static
|
|
2583
|
-
static
|
|
2631
|
+
static LocalDate Parse(Span<const char> date_str, unsigned int flags = RG_DEFAULT_PARSE_FLAGS,
|
|
2632
|
+
Span<const char> *out_remaining = nullptr);
|
|
2633
|
+
static LocalDate FromJulianDays(int days);
|
|
2634
|
+
static LocalDate FromCalendarDate(int days) { return LocalDate::FromJulianDays(days + 2440588); }
|
|
2584
2635
|
|
|
2585
2636
|
bool IsValid() const
|
|
2586
2637
|
{
|
|
@@ -2594,25 +2645,25 @@ union Date {
|
|
|
2594
2645
|
return true;
|
|
2595
2646
|
}
|
|
2596
2647
|
|
|
2597
|
-
bool operator==(
|
|
2598
|
-
bool operator!=(
|
|
2599
|
-
bool operator>(
|
|
2600
|
-
bool operator>=(
|
|
2601
|
-
bool operator<(
|
|
2602
|
-
bool operator<=(
|
|
2648
|
+
bool operator==(LocalDate other) const { return value == other.value; }
|
|
2649
|
+
bool operator!=(LocalDate other) const { return value != other.value; }
|
|
2650
|
+
bool operator>(LocalDate other) const { return value > other.value; }
|
|
2651
|
+
bool operator>=(LocalDate other) const { return value >= other.value; }
|
|
2652
|
+
bool operator<(LocalDate other) const { return value < other.value; }
|
|
2653
|
+
bool operator<=(LocalDate other) const { return value <= other.value; }
|
|
2603
2654
|
|
|
2604
2655
|
int ToJulianDays() const;
|
|
2605
2656
|
int ToCalendarDate() const { return ToJulianDays() - 2440588; }
|
|
2606
2657
|
|
|
2607
2658
|
int GetWeekDay() const;
|
|
2608
2659
|
|
|
2609
|
-
int operator-(
|
|
2660
|
+
int operator-(LocalDate other) const
|
|
2610
2661
|
{ return ToJulianDays() - other.ToJulianDays(); }
|
|
2611
2662
|
|
|
2612
|
-
|
|
2663
|
+
LocalDate operator+(int days) const
|
|
2613
2664
|
{
|
|
2614
2665
|
if (days < 5 && days > -5) {
|
|
2615
|
-
|
|
2666
|
+
LocalDate date = *this;
|
|
2616
2667
|
if (days > 0) {
|
|
2617
2668
|
while (days--) {
|
|
2618
2669
|
++date;
|
|
@@ -2624,19 +2675,19 @@ union Date {
|
|
|
2624
2675
|
}
|
|
2625
2676
|
return date;
|
|
2626
2677
|
} else {
|
|
2627
|
-
return
|
|
2678
|
+
return LocalDate::FromJulianDays(ToJulianDays() + days);
|
|
2628
2679
|
}
|
|
2629
2680
|
}
|
|
2630
2681
|
// That'll fail with INT_MAX days but that's far more days than can
|
|
2631
2682
|
// be represented as a date anyway
|
|
2632
|
-
|
|
2683
|
+
LocalDate operator-(int days) const { return *this + (-days); }
|
|
2633
2684
|
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2685
|
+
LocalDate &operator+=(int days) { *this = *this + days; return *this; }
|
|
2686
|
+
LocalDate &operator-=(int days) { *this = *this - days; return *this; }
|
|
2687
|
+
LocalDate &operator++();
|
|
2688
|
+
LocalDate operator++(int) { LocalDate date = *this; ++(*this); return date; }
|
|
2689
|
+
LocalDate &operator--();
|
|
2690
|
+
LocalDate operator--(int) { LocalDate date = *this; --(*this); return date; }
|
|
2640
2691
|
|
|
2641
2692
|
uint64_t Hash() const { return HashTraits<int32_t>::Hash(value); }
|
|
2642
2693
|
};
|
|
@@ -3067,7 +3118,7 @@ public:
|
|
|
3067
3118
|
int max_prec;
|
|
3068
3119
|
} d;
|
|
3069
3120
|
const void *ptr;
|
|
3070
|
-
|
|
3121
|
+
LocalDate date;
|
|
3071
3122
|
TimeSpec time;
|
|
3072
3123
|
Size random_len;
|
|
3073
3124
|
struct {
|
|
@@ -3110,7 +3161,7 @@ public:
|
|
|
3110
3161
|
FmtArg(float f) : type(FmtType::Float) { u.f = { f, 0, INT_MAX }; }
|
|
3111
3162
|
FmtArg(double d) : type(FmtType::Double) { u.d = { d, 0, INT_MAX }; }
|
|
3112
3163
|
FmtArg(const void *ptr) : type(FmtType::Hexadecimal) { u.u = (uint64_t)ptr; }
|
|
3113
|
-
FmtArg(const
|
|
3164
|
+
FmtArg(const LocalDate &date) : type(FmtType::Date) { u.date = date; }
|
|
3114
3165
|
|
|
3115
3166
|
FmtArg &Repeat(int new_repeat) { repeat = new_repeat; return *this; }
|
|
3116
3167
|
FmtArg &Pad(int len, char c = ' ') { pad_char = c; pad_len = len; return *this; }
|