#ifndef WIDTH_H #define WIDTH_H #include #include #include "port.h" #define PW_LANES 8 #define PW_AUDIT_CAPACITY 16 #define PW_AUDIT_SEED UINT32_C(2166136261) #define PW_AUDIT_PRIME UINT32_C(16777619) #define PW_LANE_SALT UINT32_C(0x9e3779b9) typedef enum { PW_BIT = 1, PW_RANGE = 2, PW_WRITE = 3, PW_BEGIN = 4, PW_COMMIT = 5, PW_ABORT = 6, PW_COPY = 7, PW_SWAP = 8, PW_RESTORE = 9 } PWOperation; typedef enum { PW_OK = 0, PW_INVALID = 1, PW_STATE = 2 } PWResult; typedef struct { int32_t op; int32_t lane; int32_t a; int32_t b; int32_t c; } PWRequest; typedef struct { uint32_t live; uint32_t pending; uint32_t active; uint32_t dirty; uint32_t generation; uint32_t accepted; uint32_t rejected; } PWLane; typedef struct { uint32_t sequence; PWRequest request; int32_t result; uint32_t before; uint32_t after; } PWEvent; typedef struct { PWEvent entries[PW_AUDIT_CAPACITY]; size_t head; size_t count; uint32_t digest; } PWAudit; typedef struct { PWLane lanes[PW_LANES]; uint32_t initial[PW_LANES]; uint32_t sequence; uint32_t ok; uint32_t bad; PWAudit audit; PWPort port; } PWContext; typedef struct { PWLane lanes[PW_LANES]; uint32_t sequence; uint32_t ok; uint32_t bad; uint32_t audit; uint32_t invalid_requests; } PWSnapshot; void pw_init(PWContext *context, int32_t seed); int pw_apply(PWContext *context, const PWRequest *request); uint32_t pw_effective(const PWContext *context, int lane); void pw_snapshot(const PWContext *context, PWSnapshot *snapshot); void pw_audit_init(PWAudit *audit); void pw_audit_push(PWAudit *audit, const PWEvent *event); size_t pw_audit_count(const PWAudit *audit); uint32_t pw_audit_digest(const PWAudit *audit); int pw_audit_at(const PWAudit *audit, size_t index, PWEvent *event); int pw_decimal(const char *data, size_t length, int32_t *value); int pw_parse_request(const char *data, size_t length, PWRequest *request); int pw_parse_seed(const char *data, size_t length, int32_t *seed); #endif