// model
typedef enum{
- Core路Status路mu = 0
+ Core路Status路mu = 0
,Core路Status路good
,Core路Status路bad
}Core路Status;
typedef struct{
- }Core路Tableau;
+ Core路Status (*good)();
+ Core路Status (*bad)();
- typedef struct{
- Core路Tableau tableau;
- unint status;
- }Core路Tableau路Face;
-
- typedef struct Core路Action;
- typedef struct Core路Link;
-
- typedef Core路Link *(*Core路Fn)(Core路Link *);
-
- typedef struct{
- Core路Fn good;
- Core-Fn bad;
- }Core路Action;
-
- typedef struct{
- Core路Tableau *face;
- Core路Tableau *State;
- Core路Action *act;
- }Core路Link;
-
- // Then define the functions separately
- Local Core路Link *Core路Action路good_function(Core路Link *lnk){
- lnk->face->status = Core路Status路good;
- return NULL;
- }
-
- Local void call(Core路Link *lnk){
- while(lnk) lnk = lnk->act(lnk);
- }
-
- Local Core路Link *Core路Action路bad_function(Core路Link *lnk){
- lnk->face->status = Core路Status路bad;
- return NULL;
- }
-
- // Assign the function pointers to a struct
- Local Core路Action action = {
- .good = Core路Action路good_function,
- .bad = Core路Action路bad_function
- };
-
-
- // -----implementation
-
- typedef struct{
- Core路Tableau tableau;
- }Core路Tableau路State;
+ void *(*offset)(void *p ,size_t 螖);
+ void *(*offset_8AU)(void *p ,size_t 螖);
+ bool (*is_aligned_on_8AU)(void *p);
+ void *(*floor_within_aligned_8AU)(void *p);
+ void *(*ceiling_within_aligned_8AU)(void *p);
+ } Core路Action;
+ typedef struct Core路action;
//----------------------------------------
- // utility
-
- struct{
- void *offset(void *p ,size_t 螖);
- void *offset_8AU(void *p ,size_t 螖);
-
- // given an 8AU window aligned on an 8AU boundary
- bool is_aligned_on_8AU(void *p);
- void *floor_within_aligned_8AU(void *p);
- void *ceiling_within_aligned_8AU(void *p);
- }Core;
-
- //----------------------------------------
- // Area model
+ // Tape model
+ typedef struct Core路Tape路Address;
+ typedef struct Core路Tape路Remote;
typedef struct Core路Tape;
- typedef struct{
- Core路Tableau路Face;
- Core路Tape *tape;
- extent_t extent;
- Core路Link extent_mu;
- Core路Link extent_next;
- }Core路Tape路Tableau路Face;
-
typedef enum{
- Core路Area路Topology路mu
- ,Core路Area路Topology路nonexistent // pointer to tape is NULL
- ,Core路Area路Topology路empty // tape has no cells
- ,Core路Area路Topology路singleton // extent is zero
- ,Core路Area路Topology路segment // finite non-singleton tape
- ,Core路Area路Topology路circle // initial location recurs
- ,Core路Area路Topology路cyclic // a location recurs
- ,Core路Area路Topology路infinite // exists, not empty, no cycle, no rightmost
- }Core路Tape路Topology;
+ Core路Area路Topo路mu
+ ,Core路Area路Topo路nonexistent // pointer to tape is NULL
+ ,Core路Area路Topo路empty // tape has no cells
+ ,Core路Area路Topo路singleton // extent is zero
+ ,Core路Area路Topo路segment // finite non-singleton tape
+ ,Core路Area路Topo路circle // initial location recurs
+ ,Core路Area路Topo路cyclic // a location recurs
+ ,Core路Area路Topo路infinite // exists, not empty, no cycle, no rightmost
+ }Core路Tape路Topo;
typedef struct{
- Core路Fn
- Core路Tape路Topology (*topology)(Core路Tape *tape);
- extent_t extent(Core路Area *area);
-
- }Core路Tape路Action;
-
- typedef struct Core路Area; // extends Tape
-
- typedef struct{
- Core路Tape路Tableau路Face tape_tableau;
- Core路Area *area;
- void *position_left;
- void *position_right;
-
- }Core路Area路Tableau路Face;
+ Core路Tape路Topo (*topo)(Core路Tape *tape);
+ extent_t (*extent)(Core路Area *area);
+ void read(Core路Tape路Address ,Core路Tape路Remote);
+ void write(Core路Tape路Address ,Core路Tape路Remote);
+ }Core路Tape路ActionTable;
+ //----------------------------------------
+ // Area model
+ typedef struct Core路Area;
typedef struct{
Core路Tape路Action tape;
bool overlap(Core路Area *a ,Core路Area *b);
void largest_aligned_64(Core路Area *outer ,Core路Area *inner_64);
- } Core路Area路Action;
+ } Core路Area路ActionTable;
//----------------------------------------
// if tape machine does not support step left, then Status路leftmost will be reported as Status路interim
typedef enum{
- Core路TM路Head路Status路mu
+ Core路TM路Head路Status路mu
,Core路TM路Head路Status路not_on_tape = 1
,Core路TM路Head路Status路on_leftmost = 1 << 1
,Core路TM路Head路Status路in_interim = 1 << 2
,Core路TM路Head路Status路on_rightmost = 1 << 3
}Core路TM路Head路Status;
- const uint Core路TM路Head路Status路bad =
+ const Core路TM路Head路Status Core路TM路Head路Status路on_track =
Core路TM路Head路Status路mu
| Core路TM路Head路Status路not_on_tape
;
- const uint Core路TM路Head路Status路good =
+ const Core路TM路Head路Status Core路TM路Head路Status路derailed =
Core路TM路Head路Status路leftmost
| Core路TM路Head路Status路interim
| Core路TM路Head路Status路rightmost
;
- typedef struct{
- Core路Tableau路Face
- Core路Area路M *a;
- Core路TM路Head路Status status; // perhaps integrate this with Core路tableau status
- Core路Tape路Topology topology;
- }Core路TM_NX路Tableau路Face;
-
- // default Tableau
- Local Core路TM_NX路Tableau Core路TM_NX路t;
-
typedef struct{
void mount(Core路TM_NX路Tableau *);
void rewind(Core路TM_NX路Tableau *);
+ bool can_step(Core路TM_NX路Tableau *);
void step(Core路TM_NX路Tableau *);
void step_left(Core路TM_NX路Tableau *);
- void status(Core路TM_NX路Tableau *);
- void topology(Core路TM_NX路Tableau *);
+ void topo(Core路TM_NX路Tableau *);
+ void head_status(Core路TM_NX路Tableau *);
} Core路TM_NX路Action;
// default actions table
Local Core路TM_NX路Action Core路TM_NX路action;
// Map
typedef enum{
- Core路Map路Status路mu = 0
+ Core路Map路Status路mu = 0
,Core路Map路Status路no_tape
,Core路Map路Status路not_computable
,Core路Map路Status路complete
} Core路Map路Status;
typedef enum{
- Core路Map路Completion路mu = 0
+ Core路Map路Completion路mu = 0
,Core路Map路Completion路no_tape
,Core路Map路Completion路not_computable
,Core路Map路Completion路failed
,Core路Map路Completion路write_gap
} Core路Map路Completion;
- const uint Core路Map路Completion路bad =
- Core路Map路Completion路no_tape
+ const uint Core路Map路Completion路derailed =
+ Core路Map路Completion路no_tape
| Core路Map路Completion路not_computable
| Core路Map路Completion路failed
;
- const uint Core路Map路Completion路good =
- Core路Map路Completion路perfect_fit
+ const uint Core路Map路Completion路on_track =
+ Core路Map路Completion路perfect_fit
| Core路Map路Completion路read_surplus
| Core路Map路Completion路read_surplus_write_gap
| Core路Map路Completion路write_available
}
- //----------------------------------------
- // Copy
-
- typedef enum{
- Core路Copy路Status路mu = 0
- ,Core路Copy路Status路argument_guard = 1
- ,Core路Copy路Status路perfect_fit = 2
- ,Core路Copy路Status路read_surplus = 4
- ,Core路Copy路Status路read_surplus_write_gap = 8
- ,Core路Copy路Status路write_available = 16
- ,Core路Copy路Status路write_gap = 32
- } Core路Copy路Status;
-
- typedef struct{
- Core路TM read;
- Core路TM write;
- Core路Function init;
- Core路Function copy_cell;
- Core路Function step;
- Core路Function status;
- } Core路Copy路Link;
-
- typedef struct{
-
- uint8AU_t Area路read_8AU_zero(Core路Area *area ,void *r);
- uint8AU_t Area路read_8AU_fwd(Core路Area *area ,void *r);
- uint8AU_t Area路read_8AU_rev(Core路Area *area_8AU ,void *r);
-
- // hex conversion
- uint16_t byte_to_hex(uint8_t byte);
- uint8_t hex_to_byte(uint16_t hex);
-
- // copy one area to another, possibly with a transformation
- Map路Status Core路map(Core路Map路Fn fn);
- Map路Fn Map路AU_by_AU;
- Map路Fn Map路by_8AU;
- Map路Fn Map路write_hex;
- Map路Fn Map路read_hex;
-
- } Core路MapFn路Face;
-
#endif
typedef uint64_t (*ReadFn64)(Area * ,uint64_t *);
-Local路Topology Area路topology_byte_array(Area *area){
- if(!area) return Core路Area路Topology路nonexistent;
- if(!area->position) return Core路Area路Topology路empty;
- if(area->extent == 0) return Core路Area路Topology路singleton;
- return Core路Area路Topology路finite;
+Local路Topo Area路topo_byte_array(Area *area){
+ if(!area) return Core路Area路Topo路nonexistent;
+ if(!area->position) return Core路Area路Topo路empty;
+ if(area->extent == 0) return Core路Area路Topo路singleton;
+ return Core路Area路Topo路finite;
}
+
+Local路Topo Area路topo_byte_array(Area *area){
+ if(!area) return Core路Area路Topo路nonexistent;
+ if(!area->position) return Core路Area路Topo路empty;
+ if(area->extent == 0) return Core路Area路Topo路singleton;
+ return Core路Area路Topo路finite;
+}
+
+
+ typedef struct{
+ AU *position;
+ extent_t extent;
+ } Core路Area;
+
+
+
+ typedef struct{
+ Core路Area *area;
+ AU *hd;
+ } Core路TM路Array;
+
+
+ Local Node *Core路step_AU(Node *node){
+ Core路Step路Node *step_node = (Core路Step路Node *)node;
+ step_node->hd = Core路offset(step_node->tm->hd ,1);
+ return node->next;
+ }
+
+ Local Node *Core路step_8AU(Node *node){
+ Core路Step路Node *step_node = (Core路Step路Node *)node;
+ step_node->hd = Core路offset_8AU(step_node->tm->hd ,1);
+ return node->next;
+ }
+
+
+
-----
typedef struct{
Core路Tableau *tableau;
--- /dev/null
+ /*
+ Core - core memory operations.
+
+ 'ATP' Used in comments. 'At This Point' in the code.
+
+ 'Tape' refers to an tape (in contrast to a point) in the address space.
+
+ A non-exist array is said to be non-existent.
+ An array with zero elements has 'length == 0' or is 'empty'.
+
+ In contrast, an allocation does not exist if it has zero bytes.
+
+ It is better to separate the tableau than have a union, and let the
+ optimizer figure out the memory life times, and what can be reused.
+
+ Nodes include neighbor links, that makes traversal more efficient.
+
+
+*/
+
+#define Core路DEBUG
+
+#ifndef FACE
+#define Core路IMPLEMENTATION
+#define FAC
+#endif
+
+//--------------------------------------------------------------------------------
+// Interface
+
+#ifndef Core路FACE
+#define Core路FACE
+
+ #include <stdint.h>
+ #include <stddef.h>
+
+ //----------------------------------------
+ // utility
+
+ struct{
+ void *offset(void *p ,size_t 螖);
+ void *offset_8AU(void *p ,size_t 螖);
+
+ // given an 8AU window aligned on an 8AU boundary
+ bool is_aligned_on_8AU(void *p);
+ void *floor_within_aligned_8AU(void *p);
+ void *ceiling_within_aligned_8AU(void *p);
+ }Core路U;
+ Core路U Core路u;
+
+ //----------------------------------------
+ // memory
+
+ #define extentof(x)(sizeof(x) - 1)
+ #define extent_t size_t
+
+ // AU == Addressable Unit
+ // given an AU is an 8 bit byte, 4AU is 32 bits, and 8 AU is 64 bits.
+ #define AU uint8_t;
+
+ //----------------------------------------
+ // model
+
+ typedef enum{
+ Core路Status路mu = 0
+ ,Core路Status路on_track
+ ,Core路Status路derailed
+ }Core路Status;
+
+ typedef struct{
+ }Core路Tableau;
+
+ typedef struct{
+ Core路Tableau tableau;
+ unint status;
+ }Core路Tableau路Face;
+
+ typedef struct Core路Link;
+
+ typedef struct{
+ Core路ActionTable *action;
+ Core路Tableau *face;
+ Core路Tableau *state;
+ Core路NextTable *next_table;
+ }Core路Link;
+
+ typedef enum {
+ Core路Link路Mode路none = 0
+ ,Core路Link路Mode路action = 1
+ ,Core路Link路Mode路face = 2
+ ,Core路Link路Mode路state = 4
+ ,Core路Link路Mode路next_table = 8
+ ,Core路Link路Mode路bad_mode = 16
+ ,Core路Link路Mode路bad_link = 32
+ }Core路Link路Mode;
+
+ Local uint Core路Link路check(Core路Link *l ,Core路Link路Mode m){
+ Core路Link路Mode error = Core路Link路Mode路none;
+
+ if(m == Core路Link路Mode路none){
+ fprintf(stderr,"Core路Area路Array路read:: given zero mode");
+ error |= Core路Link路Mode路bad_mode;
+ }
+ if(m >= Core路Link路Mode路bad_mode){
+ fprintf(stderr,"Core路Area路Array路read:: illegal check mode");
+ error |= Core路Link路Mode路bad_mode;
+ }
+ if(!l){
+ fprintf(stderr,"Core路Area路Array路read:: given NULL link");
+ error |= Core路Link路Mode路bad_link;
+ }
+
+ if(error) return error;
+
+ if( (m & Core路Link路Mode路action) && !l->action){
+ fprintf(stderr,"Core路Area路Array路read:: given NULL action");
+ error |= Core路Link路Mode路action;
+ }
+ if( (m & Core路Link路Mode路face) && !l->face){
+ fprintf(stderr,"Core路Area路Array路read:: given NULL face");
+ error |= Core路Link路Mode路face;
+ }
+ if( (m & Core路Link路Mode路state) && !l->state){
+ fprintf(stderr,"Core路Area路Array路read:: given NULL state");
+ error |= Core路Link路Mode路state;
+ }
+ if( (m & Core路Link路Mode路next_table) && !l->next_table){
+ fprintf(stderr,"Core路Area路Array路read:: given NULL next_table");
+ error |= Core路Link路Mode路next_table;
+ }
+
+ return error;
+ }
+
+ typedef struct{
+ uint (*check)(Core路Link *l ,Core路Link路Mode m);
+ }Core路Link路ActionTable;
+
+
+ typedef Core路Link *(*Core路Action)(Core路Link *);
+
+ typedef struct{
+ Core路Action on_track; // -> status
+ Core路Action derailed; // -> status
+ }Core路ActionTable;
+
+ Local Core路Link *Core路Action路on_track(Core路Link *lnk){
+ lnk->face->status = Core路Status路on_track;
+ return NULL;
+ }
+
+ Local Core路Link *Core路Action路derailed(Core路Link *lnk){
+ lnk->face->status = Core路Status路derailed;
+ return NULL;
+ }
+
+ // The most common continuations
+ typedef struct{
+ Core路Link on_track;
+ Core路Link derailed;
+ }Core路NextTable;
+
+
+ Local void initiate(Core路Link *lnk){
+ while(lnk) lnk = lnk->action(lnk);
+ }
+
+ typedef struct Core路State;
+
+ Local void call(
+ Core路Action action
+ ,Core路Face *face
+ ,Core路State *state
+ ){
+ Core路Link link{
+ .action = action
+ ,.face = face
+ ,.state = state
+ ,.next_table = NULL;
+ }
+ initiate(&link);
+ }
+
+ Local Core路Tableau路Face Core路Tableau路face{
+ .tableau = {
+ }
+ .status = Core路Status路mu
+ }
+
+ Local Core路Link路ActionTable Core路Link路action_table = {
+ ,.check = Core路Link路check
+ };
+
+ Local Core路ActionTable Core路action_table = {
+ .on_track = Core路Action路on_track,
+ ,.derailed = Core路Action路derailed
+ ,.check = Core路Link路check
+ };
+
+ Local Core路NextTable Core路next_table{
+ .on_track = Core路Action路on_track
+ ,.derailed = Core路Action路derailed
+ };
+
+ Local Core路Link Core路link{
+ .action = NULL
+ ,.face = NULL
+ ,.state = NULL
+ ,.next_table = &Core路next_table
+ }
+
+ //----------------------------------------
+ // Tape model
+
+ typedef struct Core路Tape;
+ typedef struct Core路Tape路Address;
+ typedef struct Core路Tape路Remote;
+
+ typedef struct{
+ Core路Tableau路Face;
+ Core路Tape *tape;
+ Core路Tape路Address *address;
+ Core路Tape路remote *remote;
+ extent_t extent;
+ }Core路Tape路Tableau路Face;
+
+ typedef Local void (*Core路Tape路copy)(
+ Core路Tape路Address *address
+ ,Core路Tape路Remote *remote
+ );
+
+ typedef enum{
+ Core路Area路Topo路mu
+ ,Core路Area路Topo路nonexistent // pointer to tape is NULL
+ ,Core路Area路Topo路empty // tape has no cells
+ ,Core路Area路Topo路singleton // extent is zero
+ ,Core路Area路Topo路segment // finite non-singleton tape
+ ,Core路Area路Topo路circle // initial location recurs
+ ,Core路Area路Topo路cyclic // a location recurs
+ ,Core路Area路Topo路infinite // exists, not empty, no cycle, no rightmost
+ }Core路Tape路Topo;
+
+ typedef enum{
+ Core路Status路mu = 0
+ ,Core路Status路on_track
+ ,Core路Status路empty_tape
+ ,Core路Status路empty_tape
+ }Core路Tape路Extent路Next;
+
+ typedef struct{
+ Core路Action topo;
+ Core路Action copy; // *address -> *remote
+ Core路Action extent;
+ }Core路Tape路ActionTable;
+
+ //----------------------------------------
+ // Area model
+
+ typedef struct Core路Area; // extends Tape
+
+ typedef struct{
+ Core路Tape路Tableau路Face tape;
+ Core路Area *area;
+ void *position;
+ void *position_right;
+ AU *pt;
+ AU *pt_complement;
+ Core路Area *a;
+ Core路Area *b;
+ bool q; // predicate -> q
+ }Core路Area路Tableau路Face;
+
+ typedef struct{
+ Core路Tape路ActionTable tape;
+
+ Core路Action position_right; // sets position_right
+
+ Core路Action complement; // AU *pt -> AU *pt_complement
+
+ // area relationships
+ Core路Action address_valid; // a encloses pt
+ Core路Action encloses_pt_strictly_q; // " pt not on a bound
+ Core路Action encloses_area_q; // a encloses b
+ Core路Action encloses_area_strictly_q; // " no bounds touching
+ Core路Action overlap_q; // a overlaps b
+ // a is an outer byte array, b is an inner aligned word64 array
+ Core路Action largest_aligned_64_q;
+ } Core路Area路Action;
+
+ //----------------------------------------
+ // Tape Machine
+
+ typedef struct Core路TM_NX;
+
+ // if tape machine does not support step left, then Status路leftmost will be reported as Status路interim
+ typedef enum{
+ Core路TM路Head路Status路mu
+ ,Core路TM路Head路Status路not_on_tape = 1
+ ,Core路TM路Head路Status路on_leftmost = 1 << 1
+ ,Core路TM路Head路Status路in_interim = 1 << 2
+ ,Core路TM路Head路Status路on_rightmost = 1 << 3
+ }Core路TM路Head路Status;
+
+ const uint Core路TM路Head路Status路derailed =
+ Core路TM路Head路Status路mu
+ | Core路TM路Head路Status路not_on_tape
+ ;
+
+ const uint Core路TM路Head路Status路can_step =
+ Core路TM路Head路Status路leftmost
+ | Core路TM路Head路Status路interim
+ ;
+
+ typedef struct{
+ Core路Tableau路Face face;
+ Core路Tape *tape;
+ Core路Tape路Topo topo;
+ void *read_pt; // various machines will have different read types
+ }Core路TM_NX路Tableau路Face;
+
+ // default Tableau
+ Local Core路TM_NX路Tableau Core路TM_NX路t;
+
+ typedef struct{
+ Core路Action mount;
+ Core路Action rewind;
+ Core路Action can_step;
+ Core路Action step_right;
+ Core路Action step_left;
+ Core路Action read; // -> read_pt
+ Core路Action write; // writes data found at read_pt
+ Core路Action status;
+ Core路Action topo;
+ } Core路TM_NX路Action;
+ // default actions table
+ Local Core路TM_NX路Action Core路TM_NX路action;
+
+ // default link
+ Core路Link Core路TM_NX路link;
+
+
+ //----------------------------------------
+ // Map
+
+ typedef enum{
+ Core路Map路Status路mu = 0
+ ,Core路Map路Status路no_tape
+ ,Core路Map路Status路not_computable
+ ,Core路Map路Status路complete
+ } Core路Map路Status;
+
+ typedef enum{
+ Core路Map路Completion路mu = 0
+ ,Core路Map路Completion路no_tape
+ ,Core路Map路Completion路not_computable
+ ,Core路Map路Completion路failed
+ ,Core路Map路Completion路perfect_fit
+ ,Core路Map路Completion路read_surplus
+ ,Core路Map路Completion路read_surplus_write_gap
+ ,Core路Map路Completion路write_available
+ ,Core路Map路Completion路write_gap
+ } Core路Map路Completion;
+
+ const uint Core路Map路Completion路derailed =
+ Core路Map路Completion路no_tape
+ | Core路Map路Completion路not_computable
+ | Core路Map路Completion路failed
+ ;
+
+ const uint Core路Map路Completion路on_track =
+ Core路Map路Completion路perfect_fit
+ | Core路Map路Completion路read_surplus
+ | Core路Map路Completion路read_surplus_write_gap
+ | Core路Map路Completion路write_available
+ | Core路Map路Completion路write_gap
+ ;
+
+ typedef Core路Map路Fn (*Core路Map路Fn)();
+
+ // Link for Map
+ typedef struct{
+ Core路Link *domain;
+ Core路Link *range;
+ Core路Map路Fn *fn;
+ Core路Map路Status status;
+ } Core路Map路Tableau;
+
+ void Core路map(Core路Map路Tableau t);
+
+ // true if function enters the map loop, otherwise false.
+ void Core路map(Core路Map路Tableau *t){
+ #ifdef Core路DEBUG
+ if(!t){
+ fprintf(stderr, "Core路Map路Tableau:: given NULL t");
+ return;
+ }
+ uint error = 0;
+ if( t->status & Core路Map路Completion路derailed != 0 ){
+ fprintf(stderr, "Core路Map:: prior map completion status is derailed.");
+ }
+ call(status ,t->domain);
+ if(t->domain->tableau->status & Core路TM路Head路Status路on_track == 0){
+ fprintf(stderr, "Core路Map:: domain is not on_track.");
+ error++;
+ }
+ call(status ,t->range);
+ if(t->range->tableau->status & Core路TM路Head路Status路on_track == 0){
+ fprintf(stderr, "Core路Map:: range is not on_track.");
+ error++;
+ }
+ if(error > 0) return;
+ #endif
+
+
+ }
+
+ //----------------------------------------
+ // Copy
+
+ typedef enum{
+ Core路Copy路Status路mu = 0
+ ,Core路Copy路Status路argument_guard = 1
+ ,Core路Copy路Status路perfect_fit = 2
+ ,Core路Copy路Status路read_surplus = 4
+ ,Core路Copy路Status路read_surplus_write_gap = 8
+ ,Core路Copy路Status路write_available = 16
+ ,Core路Copy路Status路write_gap = 32
+ } Core路Copy路Status;
+
+ typedef struct{
+ Core路TM read;
+ Core路TM write;
+ Core路Function init;
+ Core路Function copy_cell;
+ Core路Function step;
+ Core路Function status;
+ } Core路Copy路Link;
+
+ typedef struct{
+
+ uint8AU_t Area路read_8AU_zero(Core路Area *area ,void *r);
+ uint8AU_t Area路read_8AU_fwd(Core路Area *area ,void *r);
+ uint8AU_t Area路read_8AU_rev(Core路Area *area_8AU ,void *r);
+
+ // hex conversion
+ uint16_t byte_to_hex(uint8_t byte);
+ uint8_t hex_to_byte(uint16_t hex);
+
+ // copy one area to another, possibly with a transformation
+ Map路Status Core路map(Core路Map路Fn fn);
+ Map路Fn Map路AU_by_AU;
+ Map路Fn Map路by_8AU;
+ Map路Fn Map路write_hex;
+ Map路Fn Map路read_hex;
+
+ } Core路MapFn路Face;
+
+
+#endif
+
+//--------------------------------------------------------------------------------
+// Implementation
+#ifdef Core路IMPLEMENTATION
+ // declarations available to all of the IMPLEMENTATION go here
+ //
+ #ifdef Core路DEBUG
+ #include <stdio.h>
+ #endif
+
+ //----------------------------------------
+ // model
+
+
+
+ typedef struct{
+ Core路Tableau tableau;
+ }Core路Tableau路State;
+
+
+ // some default instances
+
+ //----------------------------------------
+ // Tape model - Array Area
+ // an array area is represented by `position` and `extent`.
+
+ // identical to Core路Link, used for typing pointers
+ typedef struct{
+ Core路Area路ActionTable *action;
+ Core路Area路Tableau路Face *face;
+ Core路Area路Tableau路State *state;
+ Core路NextTable *next_table;
+ }Core路Area路Array路Link;
+
+ Core路Link *Core路Area路Array路topo(Core路Link *lnk){
+ #ifdef Core路Debug
+ if(!lnk){
+ fprintf(stderr,"Core路Area路Array路topo:: given NULL lnk");
+ return NULL;
+ }
+ if(!lnk->face){
+ fprintf(stderr,"Core路Area路Array路topo:: given NULL face");
+ return NULL;
+ }
+ #endif
+ l = (Core路Area路Array路Link *)lnk;
+ if(l->face->extent == 0) l->face->status = Core路Area路Topo路singleton;
+ l->face->status = Core路Area路Topo路segment;
+ return &l->next_table->on_track;
+ }
+
+ Core路Link *Core路Area路Array路copy(Core路Link *link){
+ #ifdef Core路Debug
+ uint error = Core路Link路check(
+ link
+ ,Core路Link路Mode路action | Core路Link路Mode路face | Core路Link路Mode路next_table
+ );
+ if(error) return &link->next_table->derailed;
+ if(!&link->face->remote) return &link->next_table->derailed;
+ Core路Link link2{
+ .action = Core路Area路address_valid
+ ,.face = link->face
+ ,.state = NULL
+ ,.next_table = {
+ .on_track = NULL
+ .derailed = link->next_table->derailed
+ }
+ }
+ initiate(link2);
+ #endif
+ l = (Core路Area路Array路Link *)link;
+ return &link->next_table->on_track;
+ }
+
+
+ Local Core路Area路ActionTable Core路Area路Array路action_table = {
+ .tape = {
+ .topo = Core路Area路Array路topo
+ .read
+ .write
+ .extent
+ }
+ .psoition_right
+ .complement
+ .address_valid
+ .encloses_pt_strictly_q
+ .encloses_area_q
+ .encloses_area_strictly_q
+ .overlap_q
+ }
+
+ typedef struct{
+ AU *position;
+ extent_t extent;
+ } Core路Area;
+
+ // I removed the unions, as they are debugging hazards, and also might confuse the optimizer
+ typedef struct{
+ struct{
+ } byte_by_byte;
+ struct{
+ Area area_64;
+ } copy_64;
+ struct{
+ } read_hex;
+ struct{
+ } write_hex;
+ } Core路TableauLocal;
+
+ // this part goes into Maplib.a
+ #ifndef LOCAL
+ #endif
+
+ #ifdef LOCAL
+
+ //----------------------------------------
+ // Position/Pointer/Address whatever you want to call it
+
+ Local void *Core路offset_8(void *p ,size_t 螖){
+ #ifdef Core路Debug
+ if(!p){
+ fprintf(stderr,"Core路offset_8:: given NULL `p'");
+ return NULL;
+ }
+ #endif
+ return (void *)((AU *)p) + 螖;
+ }
+
+ Local void *Core路offset_64(void *p ,size_t 螖){
+ #ifdef Core路Debug
+ if(!p){
+ fprintf(stderr,"Core路offset_64:: given NULL `p'");
+ return NULL;
+ }
+ #endif
+ return (void *)((uint64_t *)p) + 螖;
+ }
+
+ Local bool Core路is_aligned_on_64(void *p){
+ #ifdef Core路Debug
+ if(!p){
+ fprintf(stderr,"Core路is_aligned_on_64:: given NULL `p'");
+ return false;
+ }
+ #endif
+ return ((uintptr_t)p & 0x7) == 0;
+ }
+
+ // find the lowest address in an 8 byte aligned window
+ // returns the byte pointer to the least address byte in the window
+ Local void *Core路floor_64(void *p){
+ #ifdef Core路Debug
+ if(!p){
+ fprintf(stderr,"Core路floor_64:: given NULL `p'");
+ return NULL;
+ }
+ #endif
+ return (void *)((uintptr_t)p & ~(uintptr_t)0x7);
+ }
+
+ // find the largest address in an 8 byte aligned window
+ // returns the byte pointer to the greatest address byte in the window
+ Local void *Core路ceiling_64(void *p){
+ #ifdef Core路Debug
+ if(!p){
+ fprintf(stderr,"Core路ceiling_64:: given NULL `p'");
+ return NULL;
+ }
+ #endif
+ return (void *)((uintptr_t)p | 0x7);
+ }
+
+ //----------------------------------------
+ // Area
+
+ // initialize an area
+
+ Local void Core路Area路set_position(Core路Area *area ,void *new_position){
+ area->position = new_position;
+ }
+ Local extent_t Core路Area路set_extent(Core路Area *area ,exent_t extent){
+ return area->extent = extent;
+ }
+ Local void Core路Area路set_position_right(Core路Area *area ,void *new_position_right){
+ Core路Area路set_extent(new_position_right - area->position);
+ }
+ Local void Core路Area路init_pe(Core路Area *area ,AU *position ,extent_t extent){
+ Core路Area路set_position(position);
+ Core路Area路set_extent(extent);
+ }
+ Local void Core路Area路init_pp(Core路Area *area ,void *position_left ,void *position_right){
+ Core路Area路set_position_left(position_left);
+ Core路Area路set_position_right(position_right);
+ }
+
+ // read area properties
+
+ Local bool Core路Area路empty(Core路Area *area){
+ #ifdef Core路Debug
+ if(!area){
+ fprintf(stderr,"Core路Area路empty:: given NULL area");
+ return true;
+ }
+ #endif
+ return area->position == NULL;
+ }
+
+ // Requesting a NULL position is a logical error, because a NULL position
+ // means the Area is empty and has no position. Instead, use the `empty`
+ // predicate.
+ Local AU *Core路Area路position(Core路Area *area){
+ #ifdef Core路Debug
+ if(!area){
+ fprintf(stderr,"Core路Area路position:: given NULL area");
+ return NULL;
+ }
+ if(!area->position){
+ fprintf(stderr,"Core路Area路position:: request for position when it is NULL");
+ }
+ #endif
+ return area->position;
+ }
+
+
+ Local AU *Core路Area路position_right(Core路Area *area){
+ #ifdef Core路Debug
+ if(!area){
+ fprintf(stderr,"Core路Area路position_right:: given NULL area");
+ return NULL;
+ }
+ #endif
+ return area->position + area->extent;
+ }
+ Local extent_t Core路Area路extent(Core路Area *area){
+ #ifdef Core路Debug
+ if(!area){
+ fprintf(stderr,"Core路Area路extent:: given NULL area");
+ return 0;
+ }
+ #endif
+ return area->extent;
+ }
+ Local AU Core路Area路length_Kung(Core路Area *area){
+ if(!Core路Area路position_left(area)) return 0;
+ if(Core路Area路extent(area) >= 2) return 3;
+ return Core路Area路extent(area) + 1;
+ }
+
+ Local bool Core路Area路encloses_pt(Core路Area *area ,AU *pt){
+ return
+ (pt >= Core路Area路position_left(area))
+ && (pt <= Core路Area路position_right(area));
+ }
+ Local bool Core路Area路encloses_pt_strictly(Core路Area *area ,AU *pt){
+ return
+ (pt > Core路Area路position_left(area))
+ && (pt < Core路Area路position_right(area));
+ }
+ Local bool Core路Area路encloses_area(Core路Area *outer ,Core路Area *inner){
+ return
+ (Core路Area路position_left(inner) >= Core路Area路position_left(outer))
+ && (Core路Area路position_right(inner) <= Core路Area路position_right(outer));
+ }
+ Local bool Core路Area路encloses_area_strictly(Core路Area *outer ,Core路Area *inner){
+ return
+ (Core路Area路position_left(inner) > Core路Area路position_left(outer))
+ && (Core路Area路position_right(inner) < Core路Area路position_right(outer));
+ }
+
+ // Possible cases of overlap ,including just touching
+ // 1. interval 0 to the right of interval 1 ,just touching p00 == p11
+ // 2. interval 0 to the left of interval 1 ,just touching p01 == p10
+ // 3. interval 0 wholly contained in interval 1
+ // 4. interval 0 wholly contains interval 1
+ Local bool Core路Area路overlap(Core路Area *area0 ,Core路Area *area1){
+ return
+ Core路Area路position_right(area0) >= Core路Area路position_left(area1)
+ && Core路Area路position_left(area0) <= Core路Area路position_right(area1);
+ }
+
+ // find the largest contained interval aligned on 64 bit boundaries
+ static void Core路Area路largest_aligned_64(Core路Area *outer ,Core路Area *inner_64){
+ uintptr_t p0 = (uintptr_t)Core路Area路position_left(outer);
+ uintptr_t p1 = (uintptr_t)Core路Area路position_right(outer);
+
+ AU *p0_64 = (AU *)( (p0 + 0x7) & ~(uintptr_t)0x7 );
+ AU *p1_64 = (AU *)( (p1 - 0x7) & ~(uintptr_t)0x7 );
+
+ if(p1_64 < p0_64){
+ Core路Area路set_position(inner_64 ,NULL);
+ }else{
+ Core路Area路init_pp(inner_64 ,p0_64 ,p1_64);
+ }
+ }
+
+ // complement against the extent of the area (reverse direction)
+ // works for byte pointer
+ // works for aligned word pointer
+ Local AU *Core路Area路complement(Core路Area *area ,AU *r){
+ return Core路Area路position_left(area) + (Core路Area路position_right(area) - r);
+ }
+
+ //----------------------------------------
+ // read functions
+
+ // consider instead using `copy_zero`
+ Local AU Core路Area路read_8_zero(Core路Area *area ,void *r){
+ return 0;
+ }
+ Local uint64_t Core路Area路read_64_zero(Core路Area *area ,void *r){
+ return 0;
+ }
+
+ Local AU Core路Area路read_8_fwd(){
+ Core路Area a = Core路tf.read;
+ AU **r = &Core路tf.read_pt;
+
+ #ifdef Core路Debug
+ if(!a || !*r){
+ fprintf(stderr ,"Core路Area路read_8_fwd:: read read_pt: %p %p\n" ,a ,*r);
+ return Core路Map路Read路Status路argument_guard;
+ }
+ if( !Core路Area路enclose_pt(area ,r) ){
+ fprintf(stderr,"Core路Area路read_8_fwd:: out of interval read\n");
+ }
+ #endif
+ return *(AU *)r;
+ }
+
+ Local AU Core路Area路read_8_fwd(Core路Area *area ,void *r){
+ #ifdef Core路Debug
+ if(!area || !r){
+ fprintf(stderr,"Core路Area路read_8_fwd:: area r: %p %p\n" ,area ,r);
+ return 0;
+ }
+ if( !Core路Area路enclose_pt(area ,r) ){
+ fprintf(stderr,"Core路Area路read_8_fwd:: out of interval read\n");
+ }
+ #endif
+ return *(AU *)r;
+ }
+
+ // Given a pointer to the least address byte of a uint64_t, return the value
+ Local uint64_t Core路Area路read_64_fwd(Core路Area *area ,void *r){
+ #ifdef Core路Debug
+ if(!area || !r){
+ fprintf(stderr,"Core路Area路read_8_fwd:: area r: %p %p\n" ,area ,r);
+ return 0;
+ }
+ if(!Core路Area路enclose_pt(area ,r) ){
+ fprintf(stderr,"Core路Area路read_8_fwd:: out of interval read\n");
+ }
+ #endif
+ return *(uint64_t *)r;
+ }
+
+ Local AU Core路Area路read_8_rev(Core路Area *area ,AU *r){
+ return *(Core路complement(area ,r));
+ }
+
+ Local uint64_t Core路Area路read_64_rev(Core路Area *area_64 ,AU *r){
+ return __builtin_bswap64( *(uint64_t *)Core路floor_64(Core路complement(area_64 ,r)) );
+ }
+
+ //----------------------------------------
+ // Map
+
+ // Map function using trampoline execution model
+ Local Core路Map路Status Core路map(Core路Map路Fn fn){
+ #ifdef Core路Debug
+ if(!fn){
+ fprintf(stderr,"Core路map:: given null function");
+ return Core路Map路argument_guard;
+ }
+ if(
+ true
+ && fn != Core路Map路by_8AU
+ && fn != Core路Map路AU_by_AU
+ && fn != Core路write_hex
+ && fn != Core路read_hex
+ ){
+ fprintf(stderr,"Core路map:: unrecognized copy function\n");
+ return Core路Map路argument_guard;
+ )
+ #endif
+
+ while(fn) fn = fn();
+ return tf.copy.status;
+ }
+
+ //----------------------------------------
+ // copy byte_by_byte
+
+ Core路Map路Fn Core路Map路Map路ByteByByte路perfect_fit;
+ Core路Map路Fn Core路Map路Map路ByteByByte路read_surplus;
+ Core路Map路Fn Core路Map路Map路ByteByByte路write_available;
+
+ Local Core路Map路Fn Core路Map路AU_by_AU(){
+ if(Core路Area路extent(Core路tf.copy.read) == Core路Area路extent(Core路tf.copy.write))
+ return Core路Map路ByteByByte路perfect_fit;
+
+ if(Core路Area路extent(Core路tf.copy.read) > Core路Area路extent(Core路tf.copy.write))
+ return Core路Map路ByteByByte路read_surplus;
+
+ return Core路Map路ByteByByte路write_available;
+ }
+
+ Local Core路Map路Fn Core路Map路ByteByByte路perfect_fit(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do{
+ **w = Core路tf.copy.read_fn_8(Core路tf.copy.read ,*r);
+ if(*r == r1) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ Core路tf.copy.status = Core路Map路Status路perfect_fit;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ByteByByte路read_surplus(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+ AU *w1 = Core路Area路position_right(Core路tf.copy.write);
+
+ do{
+ **w = Core路tf.copy.read_fn_8(Core路tf.copy.read ,*r);
+ if(*w == w1) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ Core路tf.copy.status = Core路Map路Status路write_available;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ByteByByte路write_avalable(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do{
+ **w = Core路tf.copy.read_fn_8(Core路tf.copy.read ,*r);
+ if(*r == r1) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ Core路tf.copy.status = Core路Map路Status路read_surplus;
+ return NULL;
+ }
+
+ //----------------------------------------
+ // copy copy_64
+
+ // 64-bit copy function with updated TableauFace terminology
+ Core路Map路Fn Core路Map路by_8AU;
+ Core路Map路Fn Core路Map路ByWord64路leadin;
+ Core路Map路Fn Core路Map路ByWord64路bulk;
+ Core路Map路Fn Core路Map路ByWord64路tail;
+
+ // Initialize the copy_64 process
+ Local Core路Map路Fn Core路Map路by_8AU(){
+ // Determine the largest 64-bit aligned region within the read area
+ Core路Area路largest_aligned_64(Core路tf.copy.read ,&Core路tl.copy_64.area_64);
+
+ // Choose the correct function based on alignment
+ if(Core路Area路empty(&Core路tl.copy_64.area_64)) return Core路Map路ByWord64路tail;
+ if(Core路is_aligned_on_64(Core路Area路position(Core路tf.copy.read))) return Core路Map路ByWord64路bulk;
+ return Core路Map路ByWord64路leadin;
+ }
+
+ // Lead-in byte copy (until alignment)
+ Local Core路Map路Fn Core路Map路ByWord64路leadin(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r0_64 = Core路Area路position(&Core路tl.copy_64.area_64);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do{
+ **w = Core路tf.copy.read_fn_8(Core路tf.copy.read ,r0_64 ,*r);
+ if(*r == r0_64) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ return Core路Map路ByWord64路bulk;
+ }
+
+ // Bulk word copy
+ Local Core路Map路Fn Core路Map路ByWord64路bulk(){
+ uint64_t **r = (uint64_t **)&Core路tf.copy.read_pt;
+ uint64_t **w = (uint64_t **)&Core路tf.copy.write_pt;
+ uint64_t *r1_64 = Core路Area路position_right(&Core路tl.copy_64.area_64);
+
+ do{
+ **w = Core路tf.copy.read_fn_64(Core路tf.copy.read ,r1_64 ,*r);
+ if(*r == r1_64) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ return Core路Map路ByWord64路tail;
+ }
+
+ // Tail byte copy (unaligned trailing bytes)
+ Local Core路Map路Fn Core路Map路ByWord64路tail(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(&Core路tl.copy_64.area_64);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do{
+ **w = Core路tf.copy.read_fn_8(Core路tf.copy.read ,r1 ,*r);
+ if(*r == r1) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ Core路tf.copy.status = Core路Map路Status路perfect_fit;
+ return NULL;
+ }
+
+ //----------------------------------------
+ // copy write hex
+
+ Local uint16_t Core路byte_to_hex(AU byte){
+ static const char hex_digits[] = "0123456789ABCDEF";
+ return
+ (hex_digits[byte >> 4] << 8)
+ | hex_digits[byte & 0x0F];
+ }
+
+ // Forward Declarations
+ Core路Map路Fn Core路Map路write_hex;
+ Core路Map路Fn Core路Map路WriteHex路perfect_fit;
+ Core路Map路Fn Core路Map路WriteHex路read_surplus;
+ Core路Map路Fn Core路Map路WriteHex路write_available;
+
+ // Hex Encoding: Initialize Map
+ Local Core路Map路Fn Core路Map路write_hex(){
+ if(Core路Area路extent(Core路tf.copy.read) == (Core路Area路extent(Core路tf.copy.write) >> 1)){
+ return Core路Map路WriteHex路perfect_fit;
+ }
+ if(Core路Area路extent(Core路tf.copy.read) > (Core路Area路extent(Core路tf.copy.write) >> 1)){
+ return Core路Map路WriteHex路read_surplus;
+ }
+ return Core路Map路WriteHex路write_available;
+ }
+
+ Local Core路Map路Fn Core路Map路WriteHex路perfect_fit(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ *(uint16_t *)*w = Core路hex.byte_to_hex(**r);
+ if(*r == r1) break;
+ (*r)++;
+ (*w) += 2;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路perfect_fit;
+ return NULL;
+ }
+
+ // Hex Encoding: Read Surplus
+ Local Core路Map路Fn Core路Map路WriteHex路read_surplus(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.write);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ *(uint16_t *)*w = Core路write_hex.byte_to_hex(**r);
+ if(*r == r1) break;
+ (*r)++;
+ (*w) += 2;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路read_surplus;
+ return NULL;
+ }
+
+ // Hex Encoding: Write Available
+ Local Core路Map路Fn Core路Map路WriteHex路write_available(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+ AU *w1 = Core路Area路position_right(Core路tf.copy.write);
+
+ do {
+ *(uint16_t *)*w = Core路write_hex.byte_to_hex(**r);
+ if(*w == w1) break;
+ (*r)++;
+ (*w) += 2;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路write_available;
+ return NULL;
+ }
+
+ //----------------------------------------
+ // copy read hex
+
+ Local AU Core路hex_to_byte(uint16_t hex){
+ AU high = hex >> 8;
+ AU low = hex & 0xFF;
+
+ high =
+ (high >= '0' && high <= '9') ? (high - '0')
+ : (high >= 'A' && high <= 'F') ? (high - 'A' + 10)
+ : (high >= 'a' && high <= 'f') ? (high - 'a' + 10)
+ : 0;
+
+ low =
+ (low >= '0' && low <= '9') ? (low - '0')
+ : (low >= 'A' && low <= 'F') ? (low - 'A' + 10)
+ : (low >= 'a' && low <= 'f') ? (low - 'a' + 10)
+ : 0;
+
+ return (high << 4) | low;
+ }
+
+ Core路Map路Fn Core路Map路read_hex;
+ Core路Map路Fn Core路Map路ReadHex路perfect_fit;
+ Core路Map路Fn Core路Map路ReadHex路read_surplus;
+ Core路Map路Fn Core路Map路ReadHex路write_available;
+
+ Local Core路Map路Fn Core路Map路read_hex(){
+ if((Core路Area路extent(Core路tf.copy.read) >> 1) == Core路Area路extent(Core路tf.copy.write)){
+ return Core路Map路ReadHex路perfect_fit;
+ }
+ if((Core路Area路extent(Core路tf.copy.read) >> 1) > Core路Area路extent(Core路tf.copy.write)){
+ return Core路Map路ReadHex路read_surplus;
+ }
+ return Core路Map路ReadHex路write_available;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路perfect_fit(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ **w = Core路hex_to_byte(*(uint16_t *)*r);
+ if(*r == r1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路perfect_fit;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路read_surplus(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.write);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ **w = Core路tf.read_hex.hex_to_byte(*(uint16_t *)*r);
+ if(*r == r1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路read_surplus;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路write_available(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+ AU *w1 = Core路Area路position_right(Core路tf.copy.write);
+
+ do {
+ **w = Core路tf.read_hex.hex_to_byte(*(uint16_t *)*r);
+ if(*w == w1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路write_available;
+ return NULL;
+ }
+
+ //----------------------------------------
+ // copy read hex
+
+ Core路Map路Fn Core路Map路read_hex;
+ Core路Map路Fn Core路Map路ReadHex路perfect_fit;
+ Core路Map路Fn Core路Map路ReadHex路read_surplus;
+ Core路Map路Fn Core路Map路ReadHex路write_available;
+
+ Local Core路Map路Fn Core路Map路read_hex(){
+ if((Core路Area路extent(Core路tf.copy.read) >> 1) == Core路Area路extent(Core路tf.copy.write)){
+ return Core路Map路ReadHex路perfect_fit;
+ }
+ if((Core路Area路extent(Core路tf.copy.read) >> 1) > Core路Area路extent(Core路tf.copy.write)){
+ return Core路Map路ReadHex路read_surplus;
+ }
+ return Core路Map路ReadHex路write_available;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路perfect_fit(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ **w = Core路hex_to_byte(*(uint16_t *)*r);
+ if(*r == r1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路perfect_fit;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路read_surplus(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.write);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ **w = Core路hex_to_byte(*(uint16_t *)*r);
+ if(*r == r1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路read_surplus;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路write_available(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+ AU *w1 = Core路Area路position_right(Core路tf.copy.write);
+
+ do {
+ **w = Core路hex_to_byte(*(uint16_t *)*r);
+ if(*w == w1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路write_available;
+ return NULL;
+ }
+
+ //----------------------------------------
+ // Initialization Blocks
+
+ //----------------------------------------
+ // Tableaux
+
+ Core路TableauFace tf = {
+ .copy = {
+ .read = NULL
+ ,.write = NULL
+ ,.read_fn_8 = Core路Area路read_8_fwd
+ ,.read_fn_64 = Core路Area路read_64_fwd
+ ,.read_pt = NULL
+ ,.write_pt = NULL
+ ,.status = Core路Map路Status路uninitialized
+ }
+ };
+
+ Core路TableauLocal tl = {
+ .copy_64 = {
+ .area_64 = {NULL ,0}
+ }
+ };
+
+ Core路M m = {
+ .Area路init_pe = Core路Area路init_pe
+ ,.Area路init_pp = Core路Area路init_pp
+ ,.Area路set_position = Core路Area路set_position
+ ,.Area路set_position_left = Core路Area路set_position
+ ,.Area路set_position_right = Core路Area路set_position_right
+ ,.Area路set_extent = Core路Area路set_extent
+ ,.Area路position = Core路Area路position
+ ,.Area路position_left = Core路Area路position
+ ,.Area路position_right = Core路Area路position_right
+ ,.Area路extent = Core路Area路extent
+ ,.Area路length_Kung = Core路Area路length_Kung
+ ,.Area路empty = Core路Area路empty
+
+ ,.Area路encloses_pt = Core路Area路encloses_pt
+ ,.Area路encloses_pt_strictly = Core路Area路encloses_pt_strictly
+ ,.Area路encloses_area = Core路Area路encloses_area
+ ,.Area路encloses_area_strictly = Core路Area路encloses_area_strictly
+ ,.Area路overlap = Core路Area路overlap
+ ,.Area路largest_aligned_64 = Core路Area路largest_aligned_64
+ ,.Area路complement = Core路Area路complement
+
+ ,.Area路read_8_zero = Core路Area路read_8_zero
+ ,.Area路read_8_fwd = Core路Area路read_8_fwd
+ ,.Area路read_8_rev = Core路Area路read_8_rev
+ ,.Area路read_64_zero = Core路Area路read_64_zero
+ ,.Area路read_64_fwd = Core路Area路read_64_fwd
+ ,.Area路read_64_rev = Core路Area路read_64_rev
+
+ ,.is_aligned_on_64 = Core路is_aligned_on_64
+ ,.floor_64 = Core路floor_64
+ ,.ceiling_64 = Core路ceiling_64
+ ,.offset_8 = Core路offset_8
+ ,.offset_64 = Core路offset_64
+
+ ,.byte_to_hex = Core路byte_to_hex
+ ,.hex_to_byte = Core路hex_to_byte
+
+ ,.copy = Core路map
+ ,.Map路AU_by_AU = Core路Map路AU_by_AU
+ ,.Map路by_8AU = Core路Map路by_8AU
+ ,.Map路write_hex = Core路Map路write_hex
+ ,.Map路read_hex = Core路Map路read_hex
+ };
+
+ #endif // LOCAL
+
+#endif // IMPLEMENTATION
--- /dev/null
+ /*
+ Core - core memory operations.
+
+ 'ATP' Used in comments. 'At This Point' in the code.
+
+ 'Tape' refers to an tape (in contrast to a point) in the address space.
+
+ A non-exist array is said to be non-existent.
+ An array with zero elements has 'length == 0' or is 'empty'.
+
+ In contrast, an allocation does not exist if it has zero bytes.
+
+ It is better to separate the tableau than have a union, and let the
+ optimizer figure out the memory life times, and what can be reused.
+
+ Nodes include neighbor links, that makes traversal more efficient.
+
+
+*/
+
+#define Core路DEBUG
+
+#ifndef FACE
+#define Core路IMPLEMENTATION
+#define FAC
+#endif
+
+//--------------------------------------------------------------------------------
+// Interface
+
+#ifndef Core路FACE
+#define Core路FACE
+
+ #include <stdint.h>
+ #include <stddef.h>
+
+ //----------------------------------------
+ // utility
+
+ struct{
+ void *offset(void *p ,size_t 螖);
+ void *offset_8AU(void *p ,size_t 螖);
+
+ // given an 8AU window aligned on an 8AU boundary
+ bool is_aligned_on_8AU(void *p);
+ void *floor_within_aligned_8AU(void *p);
+ void *ceiling_within_aligned_8AU(void *p);
+ }Core路U;
+ Core路U Core路u;
+
+ //----------------------------------------
+ // memory
+
+ #define extentof(x)(sizeof(x) - 1)
+ #define extent_t size_t
+
+ // AU == Addressable Unit
+ // given an AU is an 8 bit byte, 4AU is 32 bits, and 8 AU is 64 bits.
+ #define AU uint8_t;
+
+ //----------------------------------------
+ // model
+
+ typedef enum{
+ Core路Status路mu = 0
+ ,Core路Status路on_track
+ ,Core路Status路derailed
+ }Core路Status;
+
+ typedef struct{
+ }Core路Tableau;
+
+ typedef struct{
+ Core路Tableau tableau;
+ unint status;
+ }Core路Tableau路Face;
+
+ typedef struct Core路Link;
+
+ typedef struct{
+ Core路ActionTable *action;
+ Core路Tableau *face;
+ Core路Tableau *state;
+ Core路NextTable *next_table;
+ }Core路Link;
+
+ typedef enum {
+ Core路Link路Mode路none = 0
+ ,Core路Link路Mode路action = 1
+ ,Core路Link路Mode路face = 2
+ ,Core路Link路Mode路state = 4
+ ,Core路Link路Mode路next_table = 8
+ ,Core路Link路Mode路bad_mode = 16
+ ,Core路Link路Mode路bad_link = 32
+ }Core路Link路Mode;
+
+ Local uint Core路Link路check(Core路Link *l ,Core路Link路Mode m){
+ Core路Link路Mode error = Core路Link路Mode路none;
+
+ if(m == Core路Link路Mode路none){
+ fprintf(stderr,"Core路Area路Array路read:: given zero mode");
+ error |= Core路Link路Mode路bad_mode;
+ }
+ if(m >= Core路Link路Mode路bad_mode){
+ fprintf(stderr,"Core路Area路Array路read:: illegal check mode");
+ error |= Core路Link路Mode路bad_mode;
+ }
+ if(!l){
+ fprintf(stderr,"Core路Area路Array路read:: given NULL link");
+ error |= Core路Link路Mode路bad_link;
+ }
+
+ if(error) return error;
+
+ if( (m & Core路Link路Mode路action) && !l->action){
+ fprintf(stderr,"Core路Area路Array路read:: given NULL action");
+ error |= Core路Link路Mode路action;
+ }
+ if( (m & Core路Link路Mode路face) && !l->face){
+ fprintf(stderr,"Core路Area路Array路read:: given NULL face");
+ error |= Core路Link路Mode路face;
+ }
+ if( (m & Core路Link路Mode路state) && !l->state){
+ fprintf(stderr,"Core路Area路Array路read:: given NULL state");
+ error |= Core路Link路Mode路state;
+ }
+ if( (m & Core路Link路Mode路next_table) && !l->next_table){
+ fprintf(stderr,"Core路Area路Array路read:: given NULL next_table");
+ error |= Core路Link路Mode路next_table;
+ }
+
+ return error;
+ }
+
+ typedef struct{
+ uint (*check)(Core路Link *l ,Core路Link路Mode m);
+ }Core路Link路ActionTable;
+
+
+ typedef Core路Link *(*Core路Action)(Core路Link *);
+
+ typedef struct{
+ Core路Action on_track; // -> status
+ Core路Action derailed; // -> status
+ }Core路ActionTable;
+
+ Local Core路Link *Core路Action路on_track(Core路Link *lnk){
+ lnk->face->status = Core路Status路on_track;
+ return NULL;
+ }
+
+ Local Core路Link *Core路Action路derailed(Core路Link *lnk){
+ lnk->face->status = Core路Status路derailed;
+ return NULL;
+ }
+
+ // The most common continuations
+ typedef struct{
+ Core路Link on_track;
+ Core路Link derailed;
+ }Core路NextTable;
+
+
+ Local void initiate(Core路Link *lnk){
+ while(lnk) lnk = lnk->action(lnk);
+ }
+
+ typedef struct Core路State;
+
+ Local void call(
+ Core路Action action
+ ,Core路Face *face
+ ,Core路State *state
+ ){
+ Core路Link link{
+ .action = action
+ ,.face = face
+ ,.state = state
+ ,.next_table = NULL;
+ }
+ initiate(&link);
+ }
+
+ Local Core路Tableau路Face Core路Tableau路face{
+ .tableau = {
+ }
+ .status = Core路Status路mu
+ }
+
+ Local Core路Link路ActionTable Core路Link路action_table = {
+ ,.check = Core路Link路check
+ };
+
+ Local Core路ActionTable Core路action_table = {
+ .on_track = Core路Action路on_track,
+ ,.derailed = Core路Action路derailed
+ ,.check = Core路Link路check
+ };
+
+ Local Core路NextTable Core路next_table{
+ .on_track = Core路Action路on_track
+ ,.derailed = Core路Action路derailed
+ };
+
+ Local Core路Link Core路link{
+ .action = NULL
+ ,.face = NULL
+ ,.state = NULL
+ ,.next_table = &Core路next_table
+ }
+
+ //----------------------------------------
+ // Tape model
+
+ typedef struct Core路Tape;
+ typedef struct Core路Tape路Address;
+ typedef struct Core路Tape路Remote;
+
+ typedef struct{
+ Core路Tableau路Face;
+ Core路Tape *tape;
+ Core路Tape路Address *address;
+ Core路Tape路remote *remote;
+ extent_t extent;
+ }Core路Tape路Tableau路Face;
+
+ typedef Local void (*Core路Tape路copy)(
+ Core路Tape路Address *address
+ ,Core路Tape路Remote *remote
+ );
+
+ typedef enum{
+ Core路Area路Topo路mu
+ ,Core路Area路Topo路nonexistent // pointer to tape is NULL
+ ,Core路Area路Topo路empty // tape has no cells
+ ,Core路Area路Topo路singleton // extent is zero
+ ,Core路Area路Topo路segment // finite non-singleton tape
+ ,Core路Area路Topo路circle // initial location recurs
+ ,Core路Area路Topo路cyclic // a location recurs
+ ,Core路Area路Topo路infinite // exists, not empty, no cycle, no rightmost
+ }Core路Tape路Topo;
+
+ typedef enum{
+ Core路Status路mu = 0
+ ,Core路Status路on_track
+ ,Core路Status路empty_tape
+ ,Core路Status路empty_tape
+ }Core路Tape路Extent路Next;
+
+ typedef struct{
+ Core路Action topo;
+ Core路Action copy; // *address -> *remote
+ Core路Action extent;
+ }Core路Tape路ActionTable;
+
+ //----------------------------------------
+ // Area model
+
+ typedef struct Core路Area; // extends Tape
+
+ typedef struct{
+ Core路Tape路Tableau路Face tape;
+ Core路Area *area;
+ void *position;
+ void *position_right;
+ AU *pt;
+ AU *pt_complement;
+ Core路Area *a;
+ Core路Area *b;
+ bool q; // predicate -> q
+ }Core路Area路Tableau路Face;
+
+ typedef struct{
+ Core路Tape路ActionTable tape;
+
+ Core路Action position_right; // sets position_right
+
+ Core路Action complement; // AU *pt -> AU *pt_complement
+
+ // area relationships
+ Core路Action address_valid; // a encloses pt
+ Core路Action encloses_pt_strictly_q; // " pt not on a bound
+ Core路Action encloses_area_q; // a encloses b
+ Core路Action encloses_area_strictly_q; // " no bounds touching
+ Core路Action overlap_q; // a overlaps b
+ // a is an outer byte array, b is an inner aligned word64 array
+ Core路Action largest_aligned_64_q;
+ } Core路Area路Action;
+
+ //----------------------------------------
+ // Tape Machine
+
+ typedef struct Core路TM_NX;
+
+ // if tape machine does not support step left, then Status路leftmost will be reported as Status路interim
+ typedef enum{
+ Core路TM路Head路Status路mu
+ ,Core路TM路Head路Status路not_on_tape = 1
+ ,Core路TM路Head路Status路on_leftmost = 1 << 1
+ ,Core路TM路Head路Status路in_interim = 1 << 2
+ ,Core路TM路Head路Status路on_rightmost = 1 << 3
+ }Core路TM路Head路Status;
+
+ const uint Core路TM路Head路Status路derailed =
+ Core路TM路Head路Status路mu
+ | Core路TM路Head路Status路not_on_tape
+ ;
+
+ const uint Core路TM路Head路Status路can_step =
+ Core路TM路Head路Status路leftmost
+ | Core路TM路Head路Status路interim
+ ;
+
+ typedef struct{
+ Core路Tableau路Face face;
+ Core路Tape *tape;
+ Core路Tape路Topo topo;
+ void *read_pt; // various machines will have different read types
+ }Core路TM_NX路Tableau路Face;
+
+ // default Tableau
+ Local Core路TM_NX路Tableau Core路TM_NX路t;
+
+ typedef struct{
+ Core路Action mount;
+ Core路Action rewind;
+ Core路Action can_step;
+ Core路Action step_right;
+ Core路Action step_left;
+ Core路Action read; // -> read_pt
+ Core路Action write; // writes data found at read_pt
+ Core路Action status;
+ Core路Action topo;
+ } Core路TM_NX路Action;
+ // default actions table
+ Local Core路TM_NX路Action Core路TM_NX路action;
+
+ // default link
+ Core路Link Core路TM_NX路link;
+
+
+ //----------------------------------------
+ // Map
+
+ typedef enum{
+ Core路Map路Status路mu = 0
+ ,Core路Map路Status路no_tape
+ ,Core路Map路Status路not_computable
+ ,Core路Map路Status路complete
+ } Core路Map路Status;
+
+ typedef enum{
+ Core路Map路Completion路mu = 0
+ ,Core路Map路Completion路no_tape
+ ,Core路Map路Completion路not_computable
+ ,Core路Map路Completion路failed
+ ,Core路Map路Completion路perfect_fit
+ ,Core路Map路Completion路read_surplus
+ ,Core路Map路Completion路read_surplus_write_gap
+ ,Core路Map路Completion路write_available
+ ,Core路Map路Completion路write_gap
+ } Core路Map路Completion;
+
+ const uint Core路Map路Completion路derailed =
+ Core路Map路Completion路no_tape
+ | Core路Map路Completion路not_computable
+ | Core路Map路Completion路failed
+ ;
+
+ const uint Core路Map路Completion路on_track =
+ Core路Map路Completion路perfect_fit
+ | Core路Map路Completion路read_surplus
+ | Core路Map路Completion路read_surplus_write_gap
+ | Core路Map路Completion路write_available
+ | Core路Map路Completion路write_gap
+ ;
+
+ typedef Core路Map路Fn (*Core路Map路Fn)();
+
+ // Link for Map
+ typedef struct{
+ Core路Link *domain;
+ Core路Link *range;
+ Core路Map路Fn *fn;
+ Core路Map路Status status;
+ } Core路Map路Tableau;
+
+ void Core路map(Core路Map路Tableau t);
+
+ // true if function enters the map loop, otherwise false.
+ void Core路map(Core路Map路Tableau *t){
+ #ifdef Core路DEBUG
+ if(!t){
+ fprintf(stderr, "Core路Map路Tableau:: given NULL t");
+ return;
+ }
+ uint error = 0;
+ if( t->status & Core路Map路Completion路derailed != 0 ){
+ fprintf(stderr, "Core路Map:: prior map completion status is derailed.");
+ }
+ call(status ,t->domain);
+ if(t->domain->tableau->status & Core路TM路Head路Status路on_track == 0){
+ fprintf(stderr, "Core路Map:: domain is not on_track.");
+ error++;
+ }
+ call(status ,t->range);
+ if(t->range->tableau->status & Core路TM路Head路Status路on_track == 0){
+ fprintf(stderr, "Core路Map:: range is not on_track.");
+ error++;
+ }
+ if(error > 0) return;
+ #endif
+
+
+ }
+
+ //----------------------------------------
+ // Copy
+
+ typedef enum{
+ Core路Copy路Status路mu = 0
+ ,Core路Copy路Status路argument_guard = 1
+ ,Core路Copy路Status路perfect_fit = 2
+ ,Core路Copy路Status路read_surplus = 4
+ ,Core路Copy路Status路read_surplus_write_gap = 8
+ ,Core路Copy路Status路write_available = 16
+ ,Core路Copy路Status路write_gap = 32
+ } Core路Copy路Status;
+
+ typedef struct{
+ Core路TM read;
+ Core路TM write;
+ Core路Function init;
+ Core路Function copy_cell;
+ Core路Function step;
+ Core路Function status;
+ } Core路Copy路Link;
+
+ typedef struct{
+
+ uint8AU_t Area路read_8AU_zero(Core路Area *area ,void *r);
+ uint8AU_t Area路read_8AU_fwd(Core路Area *area ,void *r);
+ uint8AU_t Area路read_8AU_rev(Core路Area *area_8AU ,void *r);
+
+ // hex conversion
+ uint16_t byte_to_hex(uint8_t byte);
+ uint8_t hex_to_byte(uint16_t hex);
+
+ // copy one area to another, possibly with a transformation
+ Map路Status Core路map(Core路Map路Fn fn);
+ Map路Fn Map路AU_by_AU;
+ Map路Fn Map路by_8AU;
+ Map路Fn Map路write_hex;
+ Map路Fn Map路read_hex;
+
+ } Core路MapFn路Face;
+
+
+#endif
+
+//--------------------------------------------------------------------------------
+// Implementation
+#ifdef Core路IMPLEMENTATION
+ // declarations available to all of the IMPLEMENTATION go here
+ //
+ #ifdef Core路DEBUG
+ #include <stdio.h>
+ #endif
+
+ //----------------------------------------
+ // model
+
+ typedef struct{
+ Core路Tableau tableau;
+ }Core路Tableau路State;
+
+
+ // some default instances
+
+ //----------------------------------------
+ // Tape model - Array Area
+ // an array area is represented by `position` and `extent`.
+
+ // identical to Core路Link, used for typing pointers
+ typedef struct{
+ Core路Area路ActionTable *action;
+ Core路Area路Tableau路Face *face;
+ Core路Area路Tableau路State *state;
+ Core路NextTable *next_table;
+ }Core路Area路Array路Link;
+
+ Core路Link *Core路Area路Array路topo(Core路Link *lnk){
+ #ifdef Core路Debug
+ if(!lnk){
+ fprintf(stderr,"Core路Area路Array路topo:: given NULL lnk");
+ return NULL;
+ }
+ if(!lnk->face){
+ fprintf(stderr,"Core路Area路Array路topo:: given NULL face");
+ return NULL;
+ }
+ #endif
+ l = (Core路Area路Array路Link *)lnk;
+ if(l->face->extent == 0) l->face->status = Core路Area路Topo路singleton;
+ l->face->status = Core路Area路Topo路segment;
+ return &l->next_table->on_track;
+ }
+
+ Core路Link *Core路Area路Array路copy(Core路Link *link){
+ #ifdef Core路Debug
+ uint error = Core路Link路check(
+ link
+ ,Core路Link路Mode路action | Core路Link路Mode路face | Core路Link路Mode路next_table
+ );
+ if(error) return &link->next_table->derailed;
+ if(!&link->face->remote) return &link->next_table->derailed;
+ Core路Link link2{
+ .action = Core路Area路address_valid
+ ,.face = link->face
+ ,.state = NULL
+ ,.next_table = {
+ .on_track = NULL
+ .derailed = link->next_table->derailed
+ }
+ }
+ initiate(link2);
+ #endif
+ l = (Core路Area路Array路Link *)link;
+ return &link->next_table->on_track;
+ }
+
+
+ Local Core路Area路ActionTable Core路Area路Array路action_table = {
+ .tape = {
+ .topo = Core路Area路Array路topo
+ .read
+ .write
+ .extent
+ }
+ .psoition_right
+ .complement
+ .address_valid
+ .encloses_pt_strictly_q
+ .encloses_area_q
+ .encloses_area_strictly_q
+ .overlap_q
+ }
+
+ typedef struct{
+ AU *position;
+ extent_t extent;
+ } Core路Area;
+
+ // I removed the unions, as they are debugging hazards, and also might confuse the optimizer
+ typedef struct{
+ struct{
+ } byte_by_byte;
+ struct{
+ Area area_64;
+ } copy_64;
+ struct{
+ } read_hex;
+ struct{
+ } write_hex;
+ } Core路TableauLocal;
+
+ // this part goes into Maplib.a
+ #ifndef LOCAL
+ #endif
+
+ #ifdef LOCAL
+
+ //----------------------------------------
+ // Position/Pointer/Address whatever you want to call it
+
+ Local void *Core路offset_8(void *p ,size_t 螖){
+ #ifdef Core路Debug
+ if(!p){
+ fprintf(stderr,"Core路offset_8:: given NULL `p'");
+ return NULL;
+ }
+ #endif
+ return (void *)((AU *)p) + 螖;
+ }
+
+ Local void *Core路offset_64(void *p ,size_t 螖){
+ #ifdef Core路Debug
+ if(!p){
+ fprintf(stderr,"Core路offset_64:: given NULL `p'");
+ return NULL;
+ }
+ #endif
+ return (void *)((uint64_t *)p) + 螖;
+ }
+
+ Local bool Core路is_aligned_on_64(void *p){
+ #ifdef Core路Debug
+ if(!p){
+ fprintf(stderr,"Core路is_aligned_on_64:: given NULL `p'");
+ return false;
+ }
+ #endif
+ return ((uintptr_t)p & 0x7) == 0;
+ }
+
+ // find the lowest address in an 8 byte aligned window
+ // returns the byte pointer to the least address byte in the window
+ Local void *Core路floor_64(void *p){
+ #ifdef Core路Debug
+ if(!p){
+ fprintf(stderr,"Core路floor_64:: given NULL `p'");
+ return NULL;
+ }
+ #endif
+ return (void *)((uintptr_t)p & ~(uintptr_t)0x7);
+ }
+
+ // find the largest address in an 8 byte aligned window
+ // returns the byte pointer to the greatest address byte in the window
+ Local void *Core路ceiling_64(void *p){
+ #ifdef Core路Debug
+ if(!p){
+ fprintf(stderr,"Core路ceiling_64:: given NULL `p'");
+ return NULL;
+ }
+ #endif
+ return (void *)((uintptr_t)p | 0x7);
+ }
+
+ //----------------------------------------
+ // Area
+
+ // initialize an area
+
+ Local void Core路Area路set_position(Core路Area *area ,void *new_position){
+ area->position = new_position;
+ }
+ Local extent_t Core路Area路set_extent(Core路Area *area ,exent_t extent){
+ return area->extent = extent;
+ }
+ Local void Core路Area路set_position_right(Core路Area *area ,void *new_position_right){
+ Core路Area路set_extent(new_position_right - area->position);
+ }
+ Local void Core路Area路init_pe(Core路Area *area ,AU *position ,extent_t extent){
+ Core路Area路set_position(position);
+ Core路Area路set_extent(extent);
+ }
+ Local void Core路Area路init_pp(Core路Area *area ,void *position_left ,void *position_right){
+ Core路Area路set_position_left(position_left);
+ Core路Area路set_position_right(position_right);
+ }
+
+ // read area properties
+
+ Local bool Core路Area路empty(Core路Area *area){
+ #ifdef Core路Debug
+ if(!area){
+ fprintf(stderr,"Core路Area路empty:: given NULL area");
+ return true;
+ }
+ #endif
+ return area->position == NULL;
+ }
+
+ // Requesting a NULL position is a logical error, because a NULL position
+ // means the Area is empty and has no position. Instead, use the `empty`
+ // predicate.
+ Local AU *Core路Area路position(Core路Area *area){
+ #ifdef Core路Debug
+ if(!area){
+ fprintf(stderr,"Core路Area路position:: given NULL area");
+ return NULL;
+ }
+ if(!area->position){
+ fprintf(stderr,"Core路Area路position:: request for position when it is NULL");
+ }
+ #endif
+ return area->position;
+ }
+
+
+ Local AU *Core路Area路position_right(Core路Area *area){
+ #ifdef Core路Debug
+ if(!area){
+ fprintf(stderr,"Core路Area路position_right:: given NULL area");
+ return NULL;
+ }
+ #endif
+ return area->position + area->extent;
+ }
+ Local extent_t Core路Area路extent(Core路Area *area){
+ #ifdef Core路Debug
+ if(!area){
+ fprintf(stderr,"Core路Area路extent:: given NULL area");
+ return 0;
+ }
+ #endif
+ return area->extent;
+ }
+ Local AU Core路Area路length_Kung(Core路Area *area){
+ if(!Core路Area路position_left(area)) return 0;
+ if(Core路Area路extent(area) >= 2) return 3;
+ return Core路Area路extent(area) + 1;
+ }
+
+ Local bool Core路Area路encloses_pt(Core路Area *area ,AU *pt){
+ return
+ (pt >= Core路Area路position_left(area))
+ && (pt <= Core路Area路position_right(area));
+ }
+ Local bool Core路Area路encloses_pt_strictly(Core路Area *area ,AU *pt){
+ return
+ (pt > Core路Area路position_left(area))
+ && (pt < Core路Area路position_right(area));
+ }
+ Local bool Core路Area路encloses_area(Core路Area *outer ,Core路Area *inner){
+ return
+ (Core路Area路position_left(inner) >= Core路Area路position_left(outer))
+ && (Core路Area路position_right(inner) <= Core路Area路position_right(outer));
+ }
+ Local bool Core路Area路encloses_area_strictly(Core路Area *outer ,Core路Area *inner){
+ return
+ (Core路Area路position_left(inner) > Core路Area路position_left(outer))
+ && (Core路Area路position_right(inner) < Core路Area路position_right(outer));
+ }
+
+ // Possible cases of overlap ,including just touching
+ // 1. interval 0 to the right of interval 1 ,just touching p00 == p11
+ // 2. interval 0 to the left of interval 1 ,just touching p01 == p10
+ // 3. interval 0 wholly contained in interval 1
+ // 4. interval 0 wholly contains interval 1
+ Local bool Core路Area路overlap(Core路Area *area0 ,Core路Area *area1){
+ return
+ Core路Area路position_right(area0) >= Core路Area路position_left(area1)
+ && Core路Area路position_left(area0) <= Core路Area路position_right(area1);
+ }
+
+ // find the largest contained interval aligned on 64 bit boundaries
+ static void Core路Area路largest_aligned_64(Core路Area *outer ,Core路Area *inner_64){
+ uintptr_t p0 = (uintptr_t)Core路Area路position_left(outer);
+ uintptr_t p1 = (uintptr_t)Core路Area路position_right(outer);
+
+ AU *p0_64 = (AU *)( (p0 + 0x7) & ~(uintptr_t)0x7 );
+ AU *p1_64 = (AU *)( (p1 - 0x7) & ~(uintptr_t)0x7 );
+
+ if(p1_64 < p0_64){
+ Core路Area路set_position(inner_64 ,NULL);
+ }else{
+ Core路Area路init_pp(inner_64 ,p0_64 ,p1_64);
+ }
+ }
+
+ // complement against the extent of the area (reverse direction)
+ // works for byte pointer
+ // works for aligned word pointer
+ Local AU *Core路Area路complement(Core路Area *area ,AU *r){
+ return Core路Area路position_left(area) + (Core路Area路position_right(area) - r);
+ }
+
+ //----------------------------------------
+ // read functions
+
+ // consider instead using `copy_zero`
+ Local AU Core路Area路read_8_zero(Core路Area *area ,void *r){
+ return 0;
+ }
+ Local uint64_t Core路Area路read_64_zero(Core路Area *area ,void *r){
+ return 0;
+ }
+
+ Local AU Core路Area路read_8_fwd(){
+ Core路Area a = Core路tf.read;
+ AU **r = &Core路tf.read_pt;
+
+ #ifdef Core路Debug
+ if(!a || !*r){
+ fprintf(stderr ,"Core路Area路read_8_fwd:: read read_pt: %p %p\n" ,a ,*r);
+ return Core路Map路Read路Status路argument_guard;
+ }
+ if( !Core路Area路enclose_pt(area ,r) ){
+ fprintf(stderr,"Core路Area路read_8_fwd:: out of interval read\n");
+ }
+ #endif
+ return *(AU *)r;
+ }
+
+ Local AU Core路Area路read_8_fwd(Core路Area *area ,void *r){
+ #ifdef Core路Debug
+ if(!area || !r){
+ fprintf(stderr,"Core路Area路read_8_fwd:: area r: %p %p\n" ,area ,r);
+ return 0;
+ }
+ if( !Core路Area路enclose_pt(area ,r) ){
+ fprintf(stderr,"Core路Area路read_8_fwd:: out of interval read\n");
+ }
+ #endif
+ return *(AU *)r;
+ }
+
+ // Given a pointer to the least address byte of a uint64_t, return the value
+ Local uint64_t Core路Area路read_64_fwd(Core路Area *area ,void *r){
+ #ifdef Core路Debug
+ if(!area || !r){
+ fprintf(stderr,"Core路Area路read_8_fwd:: area r: %p %p\n" ,area ,r);
+ return 0;
+ }
+ if(!Core路Area路enclose_pt(area ,r) ){
+ fprintf(stderr,"Core路Area路read_8_fwd:: out of interval read\n");
+ }
+ #endif
+ return *(uint64_t *)r;
+ }
+
+ Local AU Core路Area路read_8_rev(Core路Area *area ,AU *r){
+ return *(Core路complement(area ,r));
+ }
+
+ Local uint64_t Core路Area路read_64_rev(Core路Area *area_64 ,AU *r){
+ return __builtin_bswap64( *(uint64_t *)Core路floor_64(Core路complement(area_64 ,r)) );
+ }
+
+ //----------------------------------------
+ // Map
+
+ // Map function using trampoline execution model
+ Local Core路Map路Status Core路map(Core路Map路Fn fn){
+ #ifdef Core路Debug
+ if(!fn){
+ fprintf(stderr,"Core路map:: given null function");
+ return Core路Map路argument_guard;
+ }
+ if(
+ true
+ && fn != Core路Map路by_8AU
+ && fn != Core路Map路AU_by_AU
+ && fn != Core路write_hex
+ && fn != Core路read_hex
+ ){
+ fprintf(stderr,"Core路map:: unrecognized copy function\n");
+ return Core路Map路argument_guard;
+ )
+ #endif
+
+ while(fn) fn = fn();
+ return tf.copy.status;
+ }
+
+ //----------------------------------------
+ // copy byte_by_byte
+
+ Core路Map路Fn Core路Map路Map路ByteByByte路perfect_fit;
+ Core路Map路Fn Core路Map路Map路ByteByByte路read_surplus;
+ Core路Map路Fn Core路Map路Map路ByteByByte路write_available;
+
+ Local Core路Map路Fn Core路Map路AU_by_AU(){
+ if(Core路Area路extent(Core路tf.copy.read) == Core路Area路extent(Core路tf.copy.write))
+ return Core路Map路ByteByByte路perfect_fit;
+
+ if(Core路Area路extent(Core路tf.copy.read) > Core路Area路extent(Core路tf.copy.write))
+ return Core路Map路ByteByByte路read_surplus;
+
+ return Core路Map路ByteByByte路write_available;
+ }
+
+ Local Core路Map路Fn Core路Map路ByteByByte路perfect_fit(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do{
+ **w = Core路tf.copy.read_fn_8(Core路tf.copy.read ,*r);
+ if(*r == r1) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ Core路tf.copy.status = Core路Map路Status路perfect_fit;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ByteByByte路read_surplus(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+ AU *w1 = Core路Area路position_right(Core路tf.copy.write);
+
+ do{
+ **w = Core路tf.copy.read_fn_8(Core路tf.copy.read ,*r);
+ if(*w == w1) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ Core路tf.copy.status = Core路Map路Status路write_available;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ByteByByte路write_avalable(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do{
+ **w = Core路tf.copy.read_fn_8(Core路tf.copy.read ,*r);
+ if(*r == r1) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ Core路tf.copy.status = Core路Map路Status路read_surplus;
+ return NULL;
+ }
+
+ //----------------------------------------
+ // copy copy_64
+
+ // 64-bit copy function with updated TableauFace terminology
+ Core路Map路Fn Core路Map路by_8AU;
+ Core路Map路Fn Core路Map路ByWord64路leadin;
+ Core路Map路Fn Core路Map路ByWord64路bulk;
+ Core路Map路Fn Core路Map路ByWord64路tail;
+
+ // Initialize the copy_64 process
+ Local Core路Map路Fn Core路Map路by_8AU(){
+ // Determine the largest 64-bit aligned region within the read area
+ Core路Area路largest_aligned_64(Core路tf.copy.read ,&Core路tl.copy_64.area_64);
+
+ // Choose the correct function based on alignment
+ if(Core路Area路empty(&Core路tl.copy_64.area_64)) return Core路Map路ByWord64路tail;
+ if(Core路is_aligned_on_64(Core路Area路position(Core路tf.copy.read))) return Core路Map路ByWord64路bulk;
+ return Core路Map路ByWord64路leadin;
+ }
+
+ // Lead-in byte copy (until alignment)
+ Local Core路Map路Fn Core路Map路ByWord64路leadin(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r0_64 = Core路Area路position(&Core路tl.copy_64.area_64);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do{
+ **w = Core路tf.copy.read_fn_8(Core路tf.copy.read ,r0_64 ,*r);
+ if(*r == r0_64) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ return Core路Map路ByWord64路bulk;
+ }
+
+ // Bulk word copy
+ Local Core路Map路Fn Core路Map路ByWord64路bulk(){
+ uint64_t **r = (uint64_t **)&Core路tf.copy.read_pt;
+ uint64_t **w = (uint64_t **)&Core路tf.copy.write_pt;
+ uint64_t *r1_64 = Core路Area路position_right(&Core路tl.copy_64.area_64);
+
+ do{
+ **w = Core路tf.copy.read_fn_64(Core路tf.copy.read ,r1_64 ,*r);
+ if(*r == r1_64) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ return Core路Map路ByWord64路tail;
+ }
+
+ // Tail byte copy (unaligned trailing bytes)
+ Local Core路Map路Fn Core路Map路ByWord64路tail(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(&Core路tl.copy_64.area_64);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do{
+ **w = Core路tf.copy.read_fn_8(Core路tf.copy.read ,r1 ,*r);
+ if(*r == r1) break;
+ (*r)++;
+ (*w)++;
+ }while(true);
+
+ Core路tf.copy.status = Core路Map路Status路perfect_fit;
+ return NULL;
+ }
+
+ //----------------------------------------
+ // copy write hex
+
+ Local uint16_t Core路byte_to_hex(AU byte){
+ static const char hex_digits[] = "0123456789ABCDEF";
+ return
+ (hex_digits[byte >> 4] << 8)
+ | hex_digits[byte & 0x0F];
+ }
+
+ // Forward Declarations
+ Core路Map路Fn Core路Map路write_hex;
+ Core路Map路Fn Core路Map路WriteHex路perfect_fit;
+ Core路Map路Fn Core路Map路WriteHex路read_surplus;
+ Core路Map路Fn Core路Map路WriteHex路write_available;
+
+ // Hex Encoding: Initialize Map
+ Local Core路Map路Fn Core路Map路write_hex(){
+ if(Core路Area路extent(Core路tf.copy.read) == (Core路Area路extent(Core路tf.copy.write) >> 1)){
+ return Core路Map路WriteHex路perfect_fit;
+ }
+ if(Core路Area路extent(Core路tf.copy.read) > (Core路Area路extent(Core路tf.copy.write) >> 1)){
+ return Core路Map路WriteHex路read_surplus;
+ }
+ return Core路Map路WriteHex路write_available;
+ }
+
+ Local Core路Map路Fn Core路Map路WriteHex路perfect_fit(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ *(uint16_t *)*w = Core路hex.byte_to_hex(**r);
+ if(*r == r1) break;
+ (*r)++;
+ (*w) += 2;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路perfect_fit;
+ return NULL;
+ }
+
+ // Hex Encoding: Read Surplus
+ Local Core路Map路Fn Core路Map路WriteHex路read_surplus(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.write);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ *(uint16_t *)*w = Core路write_hex.byte_to_hex(**r);
+ if(*r == r1) break;
+ (*r)++;
+ (*w) += 2;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路read_surplus;
+ return NULL;
+ }
+
+ // Hex Encoding: Write Available
+ Local Core路Map路Fn Core路Map路WriteHex路write_available(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+ AU *w1 = Core路Area路position_right(Core路tf.copy.write);
+
+ do {
+ *(uint16_t *)*w = Core路write_hex.byte_to_hex(**r);
+ if(*w == w1) break;
+ (*r)++;
+ (*w) += 2;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路write_available;
+ return NULL;
+ }
+
+ //----------------------------------------
+ // copy read hex
+
+ Local AU Core路hex_to_byte(uint16_t hex){
+ AU high = hex >> 8;
+ AU low = hex & 0xFF;
+
+ high =
+ (high >= '0' && high <= '9') ? (high - '0')
+ : (high >= 'A' && high <= 'F') ? (high - 'A' + 10)
+ : (high >= 'a' && high <= 'f') ? (high - 'a' + 10)
+ : 0;
+
+ low =
+ (low >= '0' && low <= '9') ? (low - '0')
+ : (low >= 'A' && low <= 'F') ? (low - 'A' + 10)
+ : (low >= 'a' && low <= 'f') ? (low - 'a' + 10)
+ : 0;
+
+ return (high << 4) | low;
+ }
+
+ Core路Map路Fn Core路Map路read_hex;
+ Core路Map路Fn Core路Map路ReadHex路perfect_fit;
+ Core路Map路Fn Core路Map路ReadHex路read_surplus;
+ Core路Map路Fn Core路Map路ReadHex路write_available;
+
+ Local Core路Map路Fn Core路Map路read_hex(){
+ if((Core路Area路extent(Core路tf.copy.read) >> 1) == Core路Area路extent(Core路tf.copy.write)){
+ return Core路Map路ReadHex路perfect_fit;
+ }
+ if((Core路Area路extent(Core路tf.copy.read) >> 1) > Core路Area路extent(Core路tf.copy.write)){
+ return Core路Map路ReadHex路read_surplus;
+ }
+ return Core路Map路ReadHex路write_available;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路perfect_fit(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ **w = Core路hex_to_byte(*(uint16_t *)*r);
+ if(*r == r1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路perfect_fit;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路read_surplus(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.write);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ **w = Core路tf.read_hex.hex_to_byte(*(uint16_t *)*r);
+ if(*r == r1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路read_surplus;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路write_available(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+ AU *w1 = Core路Area路position_right(Core路tf.copy.write);
+
+ do {
+ **w = Core路tf.read_hex.hex_to_byte(*(uint16_t *)*r);
+ if(*w == w1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路write_available;
+ return NULL;
+ }
+
+ //----------------------------------------
+ // copy read hex
+
+ Core路Map路Fn Core路Map路read_hex;
+ Core路Map路Fn Core路Map路ReadHex路perfect_fit;
+ Core路Map路Fn Core路Map路ReadHex路read_surplus;
+ Core路Map路Fn Core路Map路ReadHex路write_available;
+
+ Local Core路Map路Fn Core路Map路read_hex(){
+ if((Core路Area路extent(Core路tf.copy.read) >> 1) == Core路Area路extent(Core路tf.copy.write)){
+ return Core路Map路ReadHex路perfect_fit;
+ }
+ if((Core路Area路extent(Core路tf.copy.read) >> 1) > Core路Area路extent(Core路tf.copy.write)){
+ return Core路Map路ReadHex路read_surplus;
+ }
+ return Core路Map路ReadHex路write_available;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路perfect_fit(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ **w = Core路hex_to_byte(*(uint16_t *)*r);
+ if(*r == r1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路perfect_fit;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路read_surplus(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.write);
+ AU **w = &Core路tf.copy.write_pt;
+
+ do {
+ **w = Core路hex_to_byte(*(uint16_t *)*r);
+ if(*r == r1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路read_surplus;
+ return NULL;
+ }
+
+ Local Core路Map路Fn Core路Map路ReadHex路write_available(){
+ AU **r = &Core路tf.copy.read_pt;
+ AU *r1 = Core路Area路position_right(Core路tf.copy.read);
+ AU **w = &Core路tf.copy.write_pt;
+ AU *w1 = Core路Area路position_right(Core路tf.copy.write);
+
+ do {
+ **w = Core路hex_to_byte(*(uint16_t *)*r);
+ if(*w == w1) break;
+ (*r) += 2;
+ (*w)++;
+ } while(true);
+
+ Core路tf.copy.status = Core路Map路Status路write_available;
+ return NULL;
+ }
+
+ //----------------------------------------
+ // Initialization Blocks
+
+ //----------------------------------------
+ // Tableaux
+
+ Core路TableauFace tf = {
+ .copy = {
+ .read = NULL
+ ,.write = NULL
+ ,.read_fn_8 = Core路Area路read_8_fwd
+ ,.read_fn_64 = Core路Area路read_64_fwd
+ ,.read_pt = NULL
+ ,.write_pt = NULL
+ ,.status = Core路Map路Status路uninitialized
+ }
+ };
+
+ Core路TableauLocal tl = {
+ .copy_64 = {
+ .area_64 = {NULL ,0}
+ }
+ };
+
+ Core路M m = {
+ .Area路init_pe = Core路Area路init_pe
+ ,.Area路init_pp = Core路Area路init_pp
+ ,.Area路set_position = Core路Area路set_position
+ ,.Area路set_position_left = Core路Area路set_position
+ ,.Area路set_position_right = Core路Area路set_position_right
+ ,.Area路set_extent = Core路Area路set_extent
+ ,.Area路position = Core路Area路position
+ ,.Area路position_left = Core路Area路position
+ ,.Area路position_right = Core路Area路position_right
+ ,.Area路extent = Core路Area路extent
+ ,.Area路length_Kung = Core路Area路length_Kung
+ ,.Area路empty = Core路Area路empty
+
+ ,.Area路encloses_pt = Core路Area路encloses_pt
+ ,.Area路encloses_pt_strictly = Core路Area路encloses_pt_strictly
+ ,.Area路encloses_area = Core路Area路encloses_area
+ ,.Area路encloses_area_strictly = Core路Area路encloses_area_strictly
+ ,.Area路overlap = Core路Area路overlap
+ ,.Area路largest_aligned_64 = Core路Area路largest_aligned_64
+ ,.Area路complement = Core路Area路complement
+
+ ,.Area路read_8_zero = Core路Area路read_8_zero
+ ,.Area路read_8_fwd = Core路Area路read_8_fwd
+ ,.Area路read_8_rev = Core路Area路read_8_rev
+ ,.Area路read_64_zero = Core路Area路read_64_zero
+ ,.Area路read_64_fwd = Core路Area路read_64_fwd
+ ,.Area路read_64_rev = Core路Area路read_64_rev
+
+ ,.is_aligned_on_64 = Core路is_aligned_on_64
+ ,.floor_64 = Core路floor_64
+ ,.ceiling_64 = Core路ceiling_64
+ ,.offset_8 = Core路offset_8
+ ,.offset_64 = Core路offset_64
+
+ ,.byte_to_hex = Core路byte_to_hex
+ ,.hex_to_byte = Core路hex_to_byte
+
+ ,.copy = Core路map
+ ,.Map路AU_by_AU = Core路Map路AU_by_AU
+ ,.Map路by_8AU = Core路Map路by_8AU
+ ,.Map路write_hex = Core路Map路write_hex
+ ,.Map路read_hex = Core路Map路read_hex
+ };
+
+ #endif // LOCAL
+
+#endif // IMPLEMENTATION
-#+TITLE: Model and related
+#+TITLE: Model
#+AUTHOR: Thomas
#+STARTUP: content
The details of the TableauFace type are shown to the user. The actions are
declared to be given a TableauFace, so any directly calls will work. Inside each action the tableau is converted from TableauFace to Tableau.
+=> Core uses separate Face and State tableaux
** Tableau structure
Such a link could be reduced to two pointers if the single tableau variation is used.
+==> Core uses proposal 3
+
+
* Mixing continuations with fall through execution.
#+BEGIN_SRC c
Actually we need default continuations anyway. In many cases these could
be generic. Argument guard continuations could be 'good' or 'bad'.
+
+=> Core uses option 2
+
+* Continuations and linking
+
+**proposal 1
+
+Put continuations on the interface tableau. The reasoning is that the programmer will want to set them, but actually this is not a general programming task. Rather it occurs up front as part of a 'wiring' phase, and is then typically it is not done again.
+
+Consider this example.
+
+#+BEGIN_SRC c
+ typedef struct{
+ Core路Tape路Tableau路Face tape_tableau;
+ Core路Area *area;
+ void *position_left;
+ void *position_right;
+ AU *pt0;
+ AU *pt1
+ Core路Area *a;
+ Core路Area *b;
+ bool q; // predicate -> q
+ Core路Link next;
+ }Core路Area路Tableau路Face;
+#+END_SRC
+
+The idea is that there is one interface tableau used for all of the Area路Tableau actions, but it has a link field. Normally while the linked together functions are running, they can not set the 'next' link, as that information comes from a higher level. For example, after `encloses_pt_q` runs, it has no idea as to where the programmer wants control to flow next.
+
+**proposal 2
+
+Add a fourth pointer to a link. This points to the continuations block.
+
+#+BEGIN_SRC c
+ typedef struct{
+ Core路Tableau *face;
+ Core路Tableau *state;
+ Core路ActionTable *action;
+ Core路NextTable *next_table;
+ }Core路Link;
+#+END_SRC
+
+We may then describe the program flow network as a series of next_tables, and then view the program as traversing a graph.
+
+In database representation a set of nodes, and the dual graph is specified as a bridge table. It is more efficient when traversing a graph, to keep make the neighbor list a property of the node. Thus, "Link" can be seen as a node with a neighbor list.
+
+=> Core uses option 2