ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

Commit: 6ea45a030a59bbdfb99c91b35c1584124627b4f4
Parent: 05efc8efd5bac3faec0b00e33377007c1b8d296b
Author: Randy Palamar
Date:   Mon, 20 Jul 2026 18:25:23 -0700

util: delete old macro names

Diffstat:
Mbeamformer_core.c | 10+++++-----
Mbeamformer_shared_memory.c | 4++--
Mbuild.c | 18+++++++++---------
Mintrinsics.c | 4++++
Mlib/ogl_beamformer_lib.c | 12++++++------
Mmain_linux.c | 6+++---
Mmath.c | 10+++++-----
Mtests/decode.c | 2+-
Mtests/throughput.c | 36++++++++++++++++++------------------
Mthreads.c | 6+++---
Mutil.c | 27+++++++++++++--------------
Mutil.h | 12+-----------
Mvulkan.c | 4++--
13 files changed, 72 insertions(+), 79 deletions(-)

diff --git a/beamformer_core.c b/beamformer_core.c @@ -731,7 +731,7 @@ plan_compute_pipeline(BeamformerComputePlan *cp, BeamformerParameterBlock *pb, A db->transmit_receive_orientation = pb->parameters.transmit_receive_orientation; // NOTE(rnp): old gcc will miscompile an assignment - mem_copy(cp->xdc_transform.E, pb->parameters.xdc_transform.E, sizeof(cp->xdc_transform)); + memory_copy(cp->xdc_transform.E, pb->parameters.xdc_transform.E, sizeof(cp->xdc_transform)); cp->voxel_transform = m4_mul(cp->ui_voxel_transform, pb->parameters.das_voxel_transform); cp->xdc_element_pitch = pb->parameters.xdc_element_pitch; @@ -1376,7 +1376,7 @@ do_compute_shader(BeamformerCtx *ctx, VulkanHandle cmd, BeamformerComputePlan *c glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); } - mem_copy(aframe->voxel_transform.E, frame->voxel_transform.E, sizeof(frame->voxel_transform)); + memory_copy(aframe->voxel_transform.E, frame->voxel_transform.E, sizeof(frame->voxel_transform)); aframe->compound_count = frame->compound_count; aframe->acquisition_kind = frame->acquisition_kind; }break; @@ -1421,7 +1421,7 @@ complete_queue(BeamformerCtx *ctx, BeamformWorkQueue *q, Arena *arena) spin_wait(table->write_index != atomic_load_u32(&table->read_index)); ComputeShaderStats *stats = ctx->compute_shader_stats; if (sizeof(stats->table) <= ec->size) - mem_copy(beamformer_shared_memory_scratch_arena(sm, ctx->shared_memory_size).beg, + memory_copy(beamformer_shared_memory_scratch_arena(sm, ctx->shared_memory_size).beg, &stats->table, sizeof(stats->table)); }break; InvalidDefaultCase; @@ -1494,7 +1494,7 @@ complete_queue(BeamformerCtx *ctx, BeamformWorkQueue *q, Arena *arena) frame->compound_count = cp->acquisition_count; frame->parameter_block = work->compute_context.parameter_block; frame->view_plane_tag = work->compute_context.view_plane; - mem_copy(frame->voxel_transform.E, cp->voxel_transform.E, sizeof(cp->voxel_transform)); + memory_copy(frame->voxel_transform.E, cp->voxel_transform.E, sizeof(cp->voxel_transform)); VulkanHandle cmd = vk_command_begin(VulkanTimeline_Compute); vk_command_timestamp(cmd); @@ -1635,7 +1635,7 @@ coalesce_timing_table(ComputeTimingTable *t, ComputeShaderStats *stats) t->compute_frame_active = 0; stats_index = stats->latest_frame_index = (stats_index + 1) % countof(stats->table.times); stats->table.shader_count = t->in_flight_shader_count; - mem_copy(stats->table.shader_ids, t->in_flight_shader_ids, sizeof(t->in_flight_shader_ids)); + memory_copy(stats->table.shader_ids, t->in_flight_shader_ids, sizeof(t->in_flight_shader_ids)); }break; case ComputeTimingInfoKind_Shader:{ diff --git a/beamformer_shared_memory.c b/beamformer_shared_memory.c @@ -174,7 +174,7 @@ beamform_work_queue_pop(BeamformWorkQueue *q) { BeamformWork *result = 0; - static_assert(ISPOWEROF2(countof(q->work_items)), "queue capacity must be a power of 2"); + static_assert(IsPowerOfTwo(countof(q->work_items)), "queue capacity must be a power of 2"); u64 val = atomic_load_u64(&q->queue); u64 mask = countof(q->work_items) - 1; u64 widx = val & mask; @@ -197,7 +197,7 @@ beamform_work_queue_push(BeamformWorkQueue *q) { BeamformWork *result = 0; - static_assert(ISPOWEROF2(countof(q->work_items)), "queue capacity must be a power of 2"); + static_assert(IsPowerOfTwo(countof(q->work_items)), "queue capacity must be a power of 2"); u64 val = atomic_load_u64(&q->queue); u64 mask = countof(q->work_items) - 1; u64 widx = val & mask; diff --git a/build.c b/build.c @@ -168,7 +168,7 @@ build_log_base(BuildLogKind kind, char *format, va_list args) read_only local_persist char *prefixes[BuildLogKind_Count + 1] = {BUILD_LOG_KINDS "[INVALID] "}; #undef X FILE *out = kind == BuildLogKind_Error? stderr : stdout; - fputs(prefixes[MIN(kind, BuildLogKind_Count)], out); + fputs(prefixes[Min(kind, BuildLogKind_Count)], out); vfprintf(out, format, args); fputc('\n', out); } @@ -487,7 +487,7 @@ os_spawn_process(CommandList *cmd, Stream sb) } w32_process_info = {0}; /* TODO(rnp): warn if we need to clamp last string */ - sb.widx = MIN(sb.widx, (i32)(KB(32) - 1)); + sb.widx = Min(sb.widx, (i32)(KB(32) - 1)); if (sb.widx < sb.cap) sb.data[sb.widx] = 0; else sb.data[sb.widx - 1] = 0; @@ -2332,7 +2332,7 @@ meta_expansion_token(MetaExpansionParser *p) #undef X default:{ chop = 0; - if (BETWEEN(p->s.data[0], '0', '9')) result = MetaExpansionToken_Number; + if (Between(p->s.data[0], '0', '9')) result = MetaExpansionToken_Number; else result = MetaExpansionToken_Identifier; }break; } @@ -3173,7 +3173,7 @@ metagen_push_table(MetaprogramContext *m, Arena scratch, str8 row_start, str8 ro for (uz column = 0; column < columns - 1; column++) { s8 *strings = column_strings[column]; for (uz row = 0; row < rows; row++) - column_widths[column] = MAX(column_widths[column], (u32)strings[row].len); + column_widths[column] = Max(column_widths[column], (u32)strings[row].len); } } @@ -3357,13 +3357,13 @@ meta_struct_member_elements(MetaContext *ctx, MetaStruct *s, u32 member) } function void -metagen_push_counted_enum_body(MetaprogramContext *m, s8 kind, s8 prefix, s8 mid, s8 suffix, s8 *ids, iz ids_count) +metagen_push_counted_enum_body(MetaprogramContext *m, s8 kind, s8 prefix, s8 mid, s8 suffix, s8 *ids, i64 ids_count) { - iz max_id_length = 0; - for (iz id = 0; id < ids_count; id++) - max_id_length = MAX(max_id_length, ids[id].len); + i64 max_id_length = 0; + for (i64 id = 0; id < ids_count; id++) + max_id_length = Max(max_id_length, ids[id].len); - for (iz id = 0; id < ids_count; id++) { + for (i64 id = 0; id < ids_count; id++) { meta_begin_line(m, prefix, kind, ids[id]); meta_pad(m, ' ', 1 + (i32)(max_id_length - ids[id].len)); meta_push(m, mid); diff --git a/intrinsics.c b/intrinsics.c @@ -18,6 +18,10 @@ #define read_only #endif +#if !defined(countof) + #define countof(a) (i64)(sizeof(a) / sizeof(*a)) +#endif + #if COMPILER_MSVC #define alignas(n) __declspec(align(n)) #define pack_struct(s) __pragma(pack(push, 1)) s __pragma(pack(pop)) diff --git a/lib/ogl_beamformer_lib.c b/lib/ogl_beamformer_lib.c @@ -214,7 +214,7 @@ beamformer_error_string(BeamformerLibErrorKind kind) #define X(type, num, string) string, local_persist const char *error_string_table[] = {BEAMFORMER_LIB_ERRORS "invalid error kind"}; #undef X - return error_string_table[MIN(kind, countof(error_string_table) - 1)]; + return error_string_table[Min(kind, countof(error_string_table) - 1)]; } BeamformerLibErrorKind @@ -352,8 +352,8 @@ parameter_block_region_upload(void *data, u32 size, u32 block, BeamformerParamet i32 lock = BeamformerSharedMemoryLockKind_Count + (i32)block; b32 result = valid_parameter_block(block) && lib_try_lock(lock, timeout_ms); if (result) { - mem_copy((u8 *)beamformer_parameter_block(g_beamformer_library_context.bp, block) + block_offset, - data, size); + memory_copy((u8 *)beamformer_parameter_block(g_beamformer_library_context.bp, block) + block_offset, + data, size); mark_parameter_block_region_dirty(g_beamformer_library_context.bp, block, region_id); lib_release_lock(lock); } @@ -387,7 +387,7 @@ beamformer_push_pipeline_at(i32 *shaders, u32 shader_count, BeamformerDataKind d i32 lock = BeamformerSharedMemoryLockKind_Count + (i32)block; if (valid_parameter_block(block) && lib_try_lock(lock, g_beamformer_library_context.timeout_ms)) { BeamformerParameterBlock *b = beamformer_parameter_block(g_beamformer_library_context.bp, block); - mem_copy(&b->pipeline.shaders, shaders, shader_count * sizeof(*shaders)); + memory_copy(&b->pipeline.shaders, shaders, shader_count * sizeof(*shaders)); mark_parameter_block_region_dirty(g_beamformer_library_context.bp, block, BeamformerParameterBlockRegion_ComputePipeline); b->pipeline.shader_count = shader_count; @@ -679,7 +679,7 @@ beamformer_export(BeamformerExportContext export, void *out, i32 timeout_ms) if (lib_try_lock(BeamformerSharedMemoryLockKind_ScratchSpace, 0)) { Arena scratch = beamformer_shared_memory_scratch_arena(g_beamformer_library_context.bp, g_beamformer_library_context.shared_memory_size); - mem_copy(out, scratch.beg, export.size); + memory_copy(out, scratch.beg, export.size); lib_release_lock(BeamformerSharedMemoryLockKind_ScratchSpace); result = 1; } @@ -770,7 +770,7 @@ beamformer_set_live_parameters(BeamformerLiveImagingParameters *new) { b32 result = 0; if (check_shared_memory()) { - mem_copy(&g_beamformer_library_context.bp->live_imaging_parameters, new, sizeof(*new)); + memory_copy(&g_beamformer_library_context.bp->live_imaging_parameters, new, sizeof(*new)); store_fence(); result = 1; } diff --git a/main_linux.c b/main_linux.c @@ -131,9 +131,9 @@ os_create_thread(const char *name, void *user_context, os_thread_entry_point_fn if (name) { char buffer[16]; - s8 name_str = c_str_to_s8((char *)name); - u64 length = (u64)CLAMP(name_str.len, 0, countof(buffer) - 1); - mem_copy(buffer, (char *)name, length); + str8 name_str = str8_from_c_str((char *)name); + u64 length = (u64)Clamp(name_str.length, 0, countof(buffer) - 1); + memory_copy(buffer, (char *)name, length); buffer[length] = 0; pthread_setname_np(thread, buffer); } diff --git a/math.c b/math.c @@ -145,7 +145,7 @@ subrange_n_from_n_m_count(u64 n, u64 n_count, u64 m) u64 per_lane = m / n_count; u64 leftover = m - per_lane * n_count; - u64 leftovers_before_n = MIN(leftover, n); + u64 leftovers_before_n = Min(leftover, n); u64 base_index = n * per_lane + leftovers_before_n; u64 one_past_last_index = base_index + per_lane + ((n < leftover) ? 1 : 0); @@ -188,8 +188,8 @@ function v2 clamp_v2_rect(v2 v, Rect r) { v2 result = v; - result.x = CLAMP(v.x, r.pos.x, r.pos.x + r.size.x); - result.y = CLAMP(v.y, r.pos.y, r.pos.y + r.size.y); + result.x = Clamp(v.x, r.pos.x, r.pos.x + r.size.x); + result.y = Clamp(v.y, r.pos.y, r.pos.y + r.size.y); return result; } @@ -696,8 +696,8 @@ obb_raycast(m4 obb_orientation, v3 obb_size, v3 obb_center, ray r) } if (result != -1) { - f32 tmin = MAX(MAX(MIN(t[0], t[1]), MIN(t[2], t[3])), MIN(t[4], t[5])); - f32 tmax = MIN(MIN(MAX(t[0], t[1]), MAX(t[2], t[3])), MAX(t[4], t[5])); + f32 tmin = Max(Max(Min(t[0], t[1]), Min(t[2], t[3])), Min(t[4], t[5])); + f32 tmax = Min(Min(Max(t[0], t[1]), Max(t[2], t[3])), Max(t[4], t[5])); if (tmax >= 0 && tmin <= tmax) { result = tmin > 0 ? tmin : tmax; } else { diff --git a/tests/decode.c b/tests/decode.c @@ -266,7 +266,7 @@ main(i32 argc, char *argv[]) BeamformerLiveImagingParameters lip = {.active = 1, .save_enabled = 1}; s8 short_name = s8("Decode Bench"); - mem_copy(lip.save_name_tag, short_name.data, (uz)short_name.len); + memory_copy(lip.save_name_tag, short_name.data, (u64)short_name.len); lip.save_name_tag_length = (i32)short_name.len; beamformer_set_live_parameters(&lip); diff --git a/tests/throughput.c b/tests/throughput.c @@ -168,11 +168,11 @@ beamformer_simple_parameters_from_zbp_file(BeamformerSimpleParameters *bp, char bp->speed_of_sound = header->speed_of_sound; bp->time_offset = header->time_offset; - mem_copy(bp->channel_mapping, header->channel_mapping, sizeof(*bp->channel_mapping) * bp->channel_count); - mem_copy(bp->xdc_transform.E, header->transducer_transform_matrix, sizeof(bp->xdc_transform)); - mem_copy(bp->xdc_element_pitch.E, header->transducer_element_pitch, sizeof(bp->xdc_element_pitch)); + memory_copy(bp->channel_mapping, header->channel_mapping, sizeof(*bp->channel_mapping) * bp->channel_count); + memory_copy(bp->xdc_transform.E, header->transducer_transform_matrix, sizeof(bp->xdc_transform)); + memory_copy(bp->xdc_element_pitch.E, header->transducer_element_pitch, sizeof(bp->xdc_element_pitch)); // NOTE(rnp): ignores emission count and ensemble count - mem_copy(bp->raw_data_dimensions.E, header->raw_data_dimension, sizeof(bp->raw_data_dimensions)); + memory_copy(bp->raw_data_dimensions.E, header->raw_data_dimension, sizeof(bp->raw_data_dimensions)); bp->data_kind = (BeamformerDataKind)ZBP_DataKind_Int16; raw_data->kind = ZBP_DataKind_Int16; @@ -204,14 +204,14 @@ beamformer_simple_parameters_from_zbp_file(BeamformerSimpleParameters *bp, char if (acquisition_kind == ZBP_AcquisitionKind_UFORCES || acquisition_kind == ZBP_AcquisitionKind_UHERCULES) { - mem_copy(bp->sparse_elements, header->sparse_elements, sizeof(*bp->sparse_elements) * bp->acquisition_count); + memory_copy(bp->sparse_elements, header->sparse_elements, sizeof(*bp->sparse_elements) * bp->acquisition_count); } if (acquisition_kind == ZBP_AcquisitionKind_RCA_TPW || acquisition_kind == ZBP_AcquisitionKind_RCA_VLS) { - mem_copy(bp->focal_depths, header->focal_depths, sizeof(*bp->focal_depths) * bp->acquisition_count); - mem_copy(bp->steering_angles, header->steering_angles, sizeof(*bp->steering_angles) * bp->acquisition_count); + memory_copy(bp->focal_depths, header->focal_depths, sizeof(*bp->focal_depths) * bp->acquisition_count); + memory_copy(bp->steering_angles, header->steering_angles, sizeof(*bp->steering_angles) * bp->acquisition_count); for EachIndex(bp->acquisition_count, it) bp->transmit_receive_orientations[it] = bp->transmit_receive_orientation; } @@ -244,17 +244,17 @@ beamformer_simple_parameters_from_zbp_file(BeamformerSimpleParameters *bp, char bp->contrast_mode = header->contrast_mode; if (header->channel_mapping_offset != -1) { - mem_copy(bp->channel_mapping, raw.data + header->channel_mapping_offset, + memory_copy(bp->channel_mapping, raw.data + header->channel_mapping_offset, sizeof(*bp->channel_mapping) * bp->channel_count); } else { for EachIndex(bp->channel_count, it) bp->channel_mapping[it] = it; } - mem_copy(bp->xdc_transform.E, header->transducer_transform_matrix, sizeof(bp->xdc_transform)); - mem_copy(bp->xdc_element_pitch.E, header->transducer_element_pitch, sizeof(bp->xdc_element_pitch)); + memory_copy(bp->xdc_transform.E, header->transducer_transform_matrix, sizeof(bp->xdc_transform)); + memory_copy(bp->xdc_element_pitch.E, header->transducer_element_pitch, sizeof(bp->xdc_element_pitch)); // NOTE(rnp): ignores group count and ensemble count - mem_copy(bp->raw_data_dimensions.E, header->raw_data_dimension, sizeof(bp->raw_data_dimensions)); + memory_copy(bp->raw_data_dimensions.E, header->raw_data_dimension, sizeof(bp->raw_data_dimensions)); bp->data_kind = header->raw_data_kind; raw_data->kind = header->raw_data_kind; @@ -312,7 +312,7 @@ beamformer_simple_parameters_from_zbp_file(BeamformerSimpleParameters *bp, char case ZBP_AcquisitionKind_UFORCES:{ ZBP_uFORCESParameters *p = (ZBP_uFORCESParameters *)(raw.data + header->acquisition_parameters_offset); - mem_copy(bp->sparse_elements, raw.data + p->sparse_elements_offset, + memory_copy(bp->sparse_elements, raw.data + p->sparse_elements_offset, sizeof(*bp->sparse_elements) * bp->acquisition_count); }break; @@ -325,26 +325,26 @@ beamformer_simple_parameters_from_zbp_file(BeamformerSimpleParameters *bp, char bp->single_focus = 1; bp->single_orientation = 1; - mem_copy(bp->sparse_elements, raw.data + p->sparse_elements_offset, + memory_copy(bp->sparse_elements, raw.data + p->sparse_elements_offset, sizeof(*bp->sparse_elements) * bp->acquisition_count); }break; case ZBP_AcquisitionKind_RCA_TPW:{ ZBP_TPWParameters *p = (ZBP_TPWParameters *)(raw.data + header->acquisition_parameters_offset); - mem_copy(bp->transmit_receive_orientations, raw.data + p->transmit_receive_orientations_offset, + memory_copy(bp->transmit_receive_orientations, raw.data + p->transmit_receive_orientations_offset, sizeof(*bp->transmit_receive_orientations) * bp->acquisition_count); - mem_copy(bp->steering_angles, raw.data + p->tilting_angles_offset, + memory_copy(bp->steering_angles, raw.data + p->tilting_angles_offset, sizeof(*bp->steering_angles) * bp->acquisition_count); for EachIndex(bp->acquisition_count, it) - bp->focal_depths[it] = F32_INFINITY; + bp->focal_depths[it] = inf32(); }break; case ZBP_AcquisitionKind_RCA_VLS:{ ZBP_VLSParameters *p = (ZBP_VLSParameters *)(raw.data + header->acquisition_parameters_offset); - mem_copy(bp->transmit_receive_orientations, raw.data + p->transmit_receive_orientations_offset, + memory_copy(bp->transmit_receive_orientations, raw.data + p->transmit_receive_orientations_offset, sizeof(*bp->transmit_receive_orientations) * bp->acquisition_count); f32 *focal_depths = (f32 *)(raw.data + p->focal_depths_offset); @@ -526,7 +526,7 @@ execute_study(Arena arena, Stream path, Options *options) }; s8 short_name = s8("Throughput"); - mem_copy(lip.save_name_tag, short_name.data, (uz)short_name.len); + memory_copy(lip.save_name_tag, short_name.data, (uz)short_name.len); lip.save_name_tag_length = (i32)short_name.len; beamformer_set_live_parameters(&lip); diff --git a/threads.c b/threads.c @@ -18,14 +18,14 @@ function void thread_context_barrier_wait(void *broadcast, u64 broadcast_size, u64 broadcast_lane_index) { ThreadContext *ctx = thread_context_local; - u64 broadcast_size_clamped = MIN(broadcast_size, sizeof(ctx->lane_context.broadcast_memory[0])); + u64 broadcast_size_clamped = Min(broadcast_size, sizeof(ctx->lane_context.broadcast_memory[0])); if (broadcast && lane_index() == broadcast_lane_index) - mem_copy(ctx->lane_context.broadcast_memory, broadcast, broadcast_size_clamped); + memory_copy(ctx->lane_context.broadcast_memory, broadcast, broadcast_size_clamped); os_barrier_enter(ctx->lane_context.barrier); if (broadcast && lane_index() != broadcast_lane_index) - mem_copy(broadcast, ctx->lane_context.broadcast_memory, broadcast_size_clamped); + memory_copy(broadcast, ctx->lane_context.broadcast_memory, broadcast_size_clamped); if (broadcast) os_barrier_enter(ctx->lane_context.barrier); diff --git a/util.c b/util.c @@ -24,7 +24,6 @@ memory_equal(void *restrict left, void *restrict right, u64 n) return result; } -#define mem_copy memory_copy function void memory_copy(void *restrict dest, void *restrict src, u64 n) { @@ -121,11 +120,11 @@ arena_aligned_start(Arena a, uz alignment) } #define arena_capacity(a, t) arena_capacity_(a, sizeof(t), alignof(t)) -function iz -arena_capacity_(Arena *a, iz size, uz alignment) +function i64 +arena_capacity_(Arena *a, i64 size, u64 alignment) { - iz available = a->end - (u8 *)arena_aligned_start(*a, alignment); - iz result = available / size; + i64 available = a->end - (u8 *)arena_aligned_start(*a, alignment); + i64 result = available / size; return result; } @@ -226,7 +225,7 @@ enum { DA_INITIAL_CAP = 16 }; #define da_append_count(a, s, items, item_count) do { \ da_reserve((a), (s), (item_count)); \ - mem_copy((s)->data + (s)->count, (items), sizeof(*(items)) * (uz)(item_count)); \ + memory_copy((s)->data + (s)->count, (items), sizeof(*(items)) * (uz)(item_count)); \ (s)->count += (item_count); \ } while (0) @@ -245,7 +244,7 @@ da_reserve_(Arena *a, void *data, da_count *capacity, da_count needed, u64 align * on the stack or someone allocated something in the middle of the arena during usage) */ if (!data || a->beg != (u8 *)data + cap * size) { void *copy = arena_alloc(a, .size = size, .align = align, .count = cap); - if (data) mem_copy(copy, data, (uz)(cap * size)); + if (data) memory_copy(copy, data, (uz)(cap * size)); data = copy; } @@ -290,8 +289,8 @@ utf16_decode(u16 *data, iz length) if (length) { result.consumed = 1; result.cp = data[0]; - if (length > 1 && BETWEEN(data[0], 0xD800u, 0xDBFFu) - && BETWEEN(data[1], 0xDC00u, 0xDFFFu)) + if (length > 1 && Between(data[0], 0xD800u, 0xDBFFu) + && Between(data[1], 0xDC00u, 0xDFFFu)) { result.consumed = 2; result.cp = ((data[0] - 0xD800u) << 10u) | ((data[1] - 0xDC00u) + 0x10000u); @@ -351,7 +350,7 @@ stream_reset(Stream *s, i32 index) function void stream_commit(Stream *s, i32 count) { - s->errors |= !BETWEEN(s->widx + count, 0, s->cap); + s->errors |= !Between(s->widx + count, 0, s->cap); if (!s->errors) s->widx += count; } @@ -425,7 +424,7 @@ stream_append_u64_width(Stream *s, u64 n, u64 min_width) u8 tmp[64]; u8 *end = tmp + sizeof(tmp); u8 *beg = end; - min_width = MIN(sizeof(tmp), min_width); + min_width = Min(sizeof(tmp), min_width); do { *--beg = (u8)('0' + (n % 10)); } while (n /= 10); while (end - beg > 0 && (uz)(end - beg) < min_width) @@ -589,7 +588,7 @@ u128_hash_from_data(void *data, uz size) { u128 result = {0}; XXH128_hash_t hash = XXH3_128bits_withSeed(data, size, 4969); - mem_copy(&result, &hash, sizeof(result)); + memory_copy(&result, &hash, sizeof(result)); return result; } @@ -816,10 +815,10 @@ push_s8_from_parts_(Arena *arena, s8 joiner, s8 *parts, iz count) iz offset = 0; for (iz i = 0; i < count; i++) { if (i != 0) { - mem_copy(result.data + offset, joiner.data, (uz)joiner.len); + memory_copy(result.data + offset, joiner.data, (uz)joiner.len); offset += joiner.len; } - mem_copy(result.data + offset, parts[i].data, (uz)parts[i].len); + memory_copy(result.data + offset, parts[i].data, (uz)parts[i].len); offset += parts[i].len; } result.data[result.len] = 0; diff --git a/util.h b/util.h @@ -106,12 +106,6 @@ typedef u64 uptr; #define str_(...) #__VA_ARGS__ #define str(...) str_(__VA_ARGS__) -#define countof(a) (iz)(sizeof(a) / sizeof(*a)) -#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b)) -#define CLAMP(x, a, b) ((x) < (a) ? (a) : (x) > (b) ? (b) : (x)) -#define ISPOWEROF2(a) (((a) & ((a) - 1)) == 0) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define swap(a, b) do {typeof(a) __tmp = (a); (a) = (b); (b) = __tmp;} while(0) #define Abs(a) ((a) < 0 ? -(a) : (a)) @@ -131,7 +125,6 @@ typedef u64 uptr; #define f32_equal(x, y) (Abs((x) - (y)) <= F32_EPSILON * Max(1.0f, Max(Abs(x), Abs(y)))) #define DeferLoop(begin, end) for (i32 _i_ = ((begin), 0); !_i_; _i_ += 1, (end)) -#define DeferLoopTag(begin, end, tag) for (i32 __##tag = ((begin), 0); !__##tag ; __##tag += 1, (end)) #define EachBit(a, it) (u64 it = ctz_u64(a); it != 64; a &= ~(1u << (it)), it = ctz_u64(a)) #define EachElement(array, it) (u64 it = 0; it < countof(array); it += 1) @@ -194,7 +187,6 @@ typedef u64 uptr; #define U16_MAX (0x0000FFFFUL) #define U32_MAX (0xFFFFFFFFUL) #define U64_MAX (0xFFFFFFFFFFFFFFFFULL) -#define F32_INFINITY (1e+300*1e+300) #define F32_EPSILON (1e-6f) #ifndef PI #define PI (3.14159265358979323846f) @@ -314,7 +306,7 @@ typedef union { struct { f32 w, h; }; f32 E[2]; } v2; -#define V2_INFINITY (v2){{-F32_INFINITY, F32_INFINITY}} +#define V2_INFINITY (v2){{-inf32(), inf32()}} typedef union { struct { f32 x, y, z; }; @@ -350,8 +342,6 @@ typedef struct { } ray; typedef struct { v2 pos, size; } Rect; -#define INVERTED_INFINITY_RECT (Rect){.pos = {.x = -F32_INFINITY, .y = -F32_INFINITY}, \ - .size = {.x = -F32_INFINITY, .y = -F32_INFINITY}} typedef struct { u8 *data; diff --git a/vulkan.c b/vulkan.c @@ -2038,7 +2038,7 @@ vk_buffer_buffer_copy(VulkanBuffer *destination, VulkanBuffer *source, u64 desti // NOTE(rnp): don't trash the CPU cache for large data stores if (non_temporal) memory_copy_non_temporal(dest, src, size); - else mem_copy(dest, src, size); + else memory_copy(dest, src, size); } }break; InvalidDefaultCase; @@ -2055,7 +2055,7 @@ vk_buffer_buffer_copy(VulkanBuffer *destination, VulkanBuffer *source, u64 desti // NOTE(rnp): don't trash the CPU cache for large data stores if (non_temporal) memory_copy_non_temporal(dest, src, size); - else mem_copy(dest, src, size); + else memory_copy(dest, src, size); b32 coherent = vk->memory_info.memory_host_coherent[destination->memory_kind]; if (!coherent) {