[libc-commits] [libc] [libc] Major docs refresh (PR #241609)
via libc-commits
libc-commits at lists.llvm.org
Mon Nov 16 21:01:24 PST 2026
================
@@ -0,0 +1,195 @@
+(implementation_guidelines)=
+
+# Implementation Guidelines
+
+{ref}`code_style` covers naming, macros, and formatting. This page covers the
+judgment calls that come up while writing an implementation: what to optimize
+for, how to use memory, when to check inputs, and which parts of the tree are
+known to need rework.
+
+## Priorities
+
+When goals conflict, prefer them in this order:
+
+1. **Correctness.** Follow the standard. See {ref}`undefined_behavior` for
+ what to do where the standard is silent.
+2. **Readability.** Code that is long but obvious is better than code that is
+ short and clever. The character classification tables in
+ `src/__support/ctype_utils.h` are long, and anyone can see what they do.
+3. **Efficiency.** This encompasses latency, throughput, binary size, and memory
+ usage. There's no consistent formula for tradeoffs between these, but in
+ general baremetal users prioritize binary size and servers prioritize latency
+ and throughput.
+
+The memory functions and the math library are exceptions, where performance is
+an explicit goal alongside correctness.
+
+Microbenchmarks are useful for finding a direction but are not a goal in and of
+themselves. The ideal performance measurement is from sampling real systems,
+though that's impractical for most changes. The project does not have a settled
+benchmarking setup today.
+
+## Memory
+
+- **Allocate on the heap only when necessary.** Many targets have a small
+ heap or none. When allocation is needed, follow the allocation rules in
+ {ref}`code_style` and handle failure.
+- **Stack buffers may be large when the function needs them.** Prefer a
+ correct implementation with a generous buffer over a complicated one. Sizes
+ can be tuned later.
+- **Do not use unbounded recursion.** Baremetal users must be able to
+ determine the maximum stack depth statically. Recursion with an explicit
+ depth limit is acceptable.
+
+### Allocators
+
+LLVM-libc does not aim to provide its own general-purpose allocator for hosted
+systems. On Linux the supported allocator is
+[Scudo](https://llvm.org/docs/ScudoHardenedAllocator.html), and users with
+specific performance requirements are expected to bring the allocator they
+already prefer. On baremetal targets LLVM-libc provides an optimized allocator
----------------
quic-k wrote:
probably should mention why baremetal is not using scudo allocator like linux?
https://github.com/llvm/llvm-project/pull/241609
More information about the libc-commits
mailing list