Skip to content

Commit 121d0bf

Browse files
committed
meshletcodec: Remove extra null checks for clang via assume
In decodeMeshletSimd, data can not be null (even if input buffer is NULL/0, this is invalid as minimum encoded size is 16 bytes). decodeVerticesSimd and decodeTrianglesSimd may return NULL if they encounter a bounds error; however, if they exit normally, we do not need to do if (!data) check. This is not obvious to the compiler from the regular function flow here unless data is explicitly marked as non-null; builtin_assume does that for clang which streamlines the branch flow here.
1 parent c4c747b commit 121d0bf

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/meshletcodec.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,11 @@ SIMD_TARGET static int decodeMeshletSimd(void* vertices, void* triangles, const
872872
assert(gDecodeTablesInitialized);
873873
(void)gDecodeTablesInitialized;
874874

875+
#ifdef __clang__
876+
// data is guaranteed to be non-null initially; if decode loops never hit bounds errors, it remains non-null
877+
__builtin_assume(data);
878+
#endif
879+
875880
// decodes 4 vertices at a time with tail processing; writes up to align(vertex_size * vertex_count, 4)
876881
// raw decoding skips tail processing by rounding up vertex count; it's safe because output buffer is guaranteed to have extra space, and tail control data is 0
877882
if (vertex_size == 4 || Raw)

0 commit comments

Comments
 (0)