Skip to content

embedded_types

Seven C11 headers hold a fully atomic thread scheduler, atomic types, compiler directives and platform directives. Under those are the fixed-width integers, the machine word, the index and the lane. Each library in a build takes them from one place.

The target sets three widths, and the build sets none. Pick a target to see them. A cell is one byte.

Target
#define EMBED_WORD_BITS  
#define EMBED_INDEX_BITS 
#define EMBED_LANE_BITS  

The word is embed_word, the register that each count, mask and carry runs in. The index is embed_index, for each offset and length. The lane is embed_lane, the widest vector register of the target. The word and the lane tells how each width comes from the target.

The headers

header what it holds
embed_types.h the widths, the boolean, the word, the index, the raw word, and their assertions
embed_compiler_directives.h the compiler directives, feature checks, the static assertion, attribute wrappers and diagnostic pragmas; and the platform directives, the byte order, the unaligned load, the widest vector register and the host and device marker
embed_dispatch_layout.h EMBED_TABLE_LAYOUT, EMBED_CALL, EMBED_ENTRY, and the macros behind them
embed_atomic.h the atomic types: a 32-bit word and a 64-bit word for host, part and GPU threads, on the arm of the target
embed_turnstile.h the thread scheduler: turnstiles that readers pass through and that a writer drains, with a backoff and the sleep on the address of a word
embed_ticket_ring.h the ticket ring: a ring of job slots that a ticket indexes, with a push and a pop inside a pass through a turnstile
embed_lane.h the lane, its loads, fills, arithmetic and byte masks

No header allocates memory or runs code at startup. The first three include only stddef.h and stdint.h. Each entry of the atomics and the lane has EMBED_HOST_DEVICE, so a kernel calls the same functions that a host walk calls.

A first use

#include "embed_types.h"
#include "embed_dispatch_layout.h"

static embed_u32 crc;
static embed_word accumulator;
static embed_index offset;

static embed_word at_odd_offset(const embed_u8 *bytes)
{
    return *(const embed_raw_word *)(const void *)(bytes + 1);
}

typedef struct
{
    embed_index (*length)(const embed_u8 *at);
    embed_bool (*is_empty)(const embed_u8 *at);
} ScanNs;
EMBED_TABLE_LAYOUT(ScanNs, length, is_empty);

embed_raw_word is embed_word with EMBED_RAW on it. That attribute lowers the alignment to 1 and permits access through an alias. C leaves a read through the plain embed_word undefined where the address is not a multiple of the word width.

EMBED_TABLE_LAYOUT emits one static assertion for the byte offset of each member, and one for sizeof(ScanNs). The build fails where the list leaves out a member, or where padding comes between two members.

What the headers guarantee

SECURITY.md tells what the headers guarantee, and what they do not diagnose.