Provides guidance on managing hierarchical target systems and implementing builtin functions in ISPC.
Install
mkdir -p .claude/skills/ispc-builtins && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/3326" && unzip -o skill.zip -d .claude/skills/ispc-builtins && rm skill.zipInstalls to .claude/skills/ispc-builtins
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Best practices for creating and modifying ISPC builtin files. Use when adding target-specific optimizations, implementing new builtin functions, or working with the hierarchical target system.Key capabilities
- →Map ISPC target hierarchies
- →Manage target-specific LLVM IR builtins
- →Resolve symbol dependencies across target parents
- →Override parent builtin functions
How it works
Consults the internal `targetParentMap` to determine the inheritance chain of CPU targets and applies the minimal necessary overrides.
Inputs & outputs
When to use ispc-builtins
- →Adding target-specific optimizations
- →Implementing new builtin functions
- →Navigating the hierarchical target system
About this skill
ISPC Builtins Guide
Understanding the hierarchical target system is critical for correctly implementing and maintaining builtins.
Architecture Overview
ISPC's standard library consist of two layers:
- Standard Library (
stdlib/stdlib.ispc) — User-visible functions written in ISPC language - Builtins (
builtins/) — Target-specific implementations in LLVM IR that support the stdlib
Hierarchical Target System
Key Concept: Targets are organized hierarchically. A child target inherits all functions from its parent that it doesn't explicitly override.
Target Parent Map (src/builtins.cpp)
The hierarchy is defined in targetParentMap:
std::unordered_map<ISPCTarget, ISPCTarget> targetParentMap = {
// ARM NEON -> generic
{ISPCTarget::neon_i8x16, ISPCTarget::generic_i8x16},
// AVX512 hierarchy: dmr -> gnr -> spr -> icl -> skx -> generic
{ISPCTarget::avx10_2dmr_x16, ISPCTarget::avx512gnr_x16},
{ISPCTarget::avx512gnr_x16, ISPCTarget::avx512spr_x16},
{ISPCTarget::avx512spr_x16, ISPCTarget::avx512icl_x16},
{ISPCTarget::avx512icl_x16, ISPCTarget::avx512skx_x16},
{ISPCTarget::avx512skx_x16, ISPCTarget::generic_i1x16},
// AVX/SSE hierarchy: avx2vnni -> avx2 -> avx1 -> sse4 -> sse2 -> generic
{ISPCTarget::avx2vnni_i32x8, ISPCTarget::avx2_i32x8},
{ISPCTarget::avx2_i32x8, ISPCTarget::avx1_i32x8},
// ...
};
How Linking Works
When compiling user code:
- Link the target-specific builtins (e.g.,
avx512skx-x16) - Check for unresolved symbols
- If unresolved, link parent target's builtins (e.g.,
generic-i1x16) - Repeat until all symbols are resolved or error
Implication: You only need to implement functions that differ from the parent.
File Structure (builtins/)
| File Pattern | Description |
|---|---|
target-<isa>-<variant>.ll | Target-specific LLVM IR (e.g., target-avx512skx-x16.ll) |
target-<isa>-common.ll | Shared code for ISA family (e.g., target-sse4-common.ll) |
target-<isa>-utils.ll | Utility macros/functions for ISA (e.g., target-avx512-utils.ll) |
generic.ispc | Target-independent implementations in ISPC |
util.m4 | M4 macros for generating LLVM IR |
Function signatures are declared in stdlib/include/builtins.isph.
Creating/Modifying Builtins
Step 1: Define the Function Signature
Add declaration to stdlib/include/builtins.isph:
EXT inline READNONE varying float __my_builtin_float(varying float);
Step 2: Implement Generic Fallback and Optimized Versions
New builtins must always have a generic implementation in generic.ispc. This ensures all targets work correctly via hierarchy fallback.
Then add optimized LLVM IR versions at the appropriate level — they will be inherited by all children:
avx512skx— inherited byicl,spr,gnr,dmravx512icl— inherited byspr,gnr,dmr(overridesskx)
Example optimized implementation in target-avx512skx-x16.ll:
define <16 x float> @__my_builtin_float(<16 x float> %input) nounwind readnone alwaysinline {
%result = call <16 x float> @llvm.x86.avx512.something(<16 x float> %input)
ret <16 x float> %result
}
Best Practices
- Leverage hierarchy — Only implement what differs from parent; don't copy-paste
- Use generic as fallback — Implement in
generic.ispcfirst, optimize later - Use
include()— Share code viatarget-*-utils.llfiles - Mark functions correctly — Use
nounwind readnone alwaysinlineattributes
Testing Builtins
See CLAUDE.md for build, lit test, and IR/assembly inspection commands.
Verify Correct Builtin Was Linked
Dump IR before optimizations to see builtins as they were linked:
build/bin/ispc test.ispc --target=avx512skx-x16 --debug-phase=pre:first --dump-file=dbg -o /dev/null
# Check dbg/ir_*.ll files for the builtin implementation
When not to use it
- →Writing standard ISPC code not requiring custom hardware backends
- →General C++ library development
Prerequisites
Limitations
- →Requires understanding of target-specific LLVM IR
- →Changes require rebuilding the ISPC compiler
How it compares
Provides a direct navigation path through target hierarchies rather than manually inspecting the full ISPC codebase.
Compared to similar skills
ispc-builtins side by side with the closest alternatives in the catalog.
Try saying
Example prompts that trigger this skill in your AI assistant.
More by ispc
View all by ispc →You might also like
cpp-pro
sickn33
Write idiomatic C++ code with modern features, RAII, smart pointers, and STL algorithms. Handles templates, move semantics, and performance optimization. Use PROACTIVELY for C++ refactoring, memory safety, or complex C++ patterns.
building
zilliztech
Use when building knowhere from source, configuring build options (CPU/GPU/DISKANN/ASAN), or troubleshooting compilation errors
cpp-pro
sleepyvani
Writes, optimizes, and debugs C++ applications using modern C++20/23 features, template metaprogramming, and high-performance systems techniques. Use when building or refactoring C++ code requiring concepts, ranges, coroutines, SIMD optimization, or careful memory management — or when addressing per
dev_unity_unreal
AllurinsX
dev_unity_unreal — an agent skill by AllurinsX.
unreal-engine-cpp-pro
sickn33
Expert guide for Unreal Engine 5.x C++ development, covering UObject hygiene, performance patterns, and best practices.
code-coverage-with-gcov
gadievron
Add gcov code coverage instrumentation to C/C++ projects