Changeset b7b3e41


Ignore:
Timestamp:
Jun 19, 2023, 1:57:11 PM (2 years ago)
Author:
caparson <caparson@…>
Branches:
master
Children:
adc73a5
Parents:
fa5e1aa5 (diff), 33d4bc8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
18 added
2 deleted
116 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/llheap/Paper.tex

    rfa5e1aa5 rb7b3e41  
    252252Dynamic code/data memory is managed by the dynamic loader for libraries loaded at runtime, which is complex especially in a multi-threaded program~\cite{Huang06}.
    253253However, changes to the dynamic code/data space are typically infrequent, many occurring at program startup, and are largely outside of a program's control.
    254 Stack memory is managed by the program call/return-mechanism using a simple LIFO technique, which works well for sequential programs.
    255 For stackful coroutines and user threads, a new stack is commonly created in dynamic-allocation memory.
     254Stack memory is managed by the program call/return-mechanism using a LIFO technique, which works well for sequential programs.
     255For stackful coroutines and user threads, a new stack is commonly created in the dynamic-allocation memory.
    256256This work focuses solely on management of the dynamic-allocation memory.
    257257
     
    293293\begin{enumerate}[leftmargin=*,itemsep=0pt]
    294294\item
    295 Implementation of a new stand-alone concurrent low-latency memory-allocator ($\approx$1,200 lines of code) for C/\CC programs using kernel threads (1:1 threading), and specialized versions of the allocator for the programming languages \uC and \CFA using user-level threads running on multiple kernel threads (M:N threading).
    296 
    297 \item
    298 Extend the standard C heap functionality by preserving with each allocation: its request size plus the amount allocated, whether an allocation is zero fill, and allocation alignment.
     295Implementation of a new stand-alone concurrent low-latency memory-allocator ($\approx$1,200 lines of code) for C/\CC programs using kernel threads (1:1 threading), and specialized versions of the allocator for the programming languages \uC~\cite{uC++} and \CFA~\cite{Moss18,Delisle21} using user-level threads running on multiple kernel threads (M:N threading).
     296
     297\item
     298Extend the standard C heap functionality by preserving with each allocation: its request size plus the amount allocated, whether an allocation is zero fill and/or allocation alignment.
    299299
    300300\item
     
    365365
    366366The following discussion is a quick overview of the moving-pieces that affect the design of a memory allocator and its performance.
    367 It is assumed that dynamic allocates and deallocates acquire storage for a program variable, referred to as an \newterm{object}, through calls such as @malloc@ and @free@ in C, and @new@ and @delete@ in \CC.
     367Dynamic acquires and releases obtain storage for a program variable, called an \newterm{object}, through calls such as @malloc@ and @free@ in C, and @new@ and @delete@ in \CC.
    368368Space for each allocated object comes from the dynamic-allocation zone.
    369369
     
    378378
    379379Figure~\ref{f:AllocatorComponents} shows the two important data components for a memory allocator, management and storage, collectively called the \newterm{heap}.
    380 The \newterm{management data} is a data structure located at a known memory address and contains all information necessary to manage the storage data.
    381 The management data starts with fixed-sized information in the static-data memory that references components in the dynamic-allocation memory.
     380The \newterm{management data} is a data structure located at a known memory address and contains fixed-sized information in the static-data memory that references components in the dynamic-allocation memory.
    382381For multi-threaded programs, additional management data may exist in \newterm{thread-local storage} (TLS) for each kernel thread executing the program.
    383382The \newterm{storage data} is composed of allocated and freed objects, and \newterm{reserved memory}.
     
    385384\ie only the program knows the location of allocated storage not the memory allocator.
    386385Freed objects (white) represent memory deallocated by the program, which are linked into one or more lists facilitating easy location of new allocations.
    387 Reserved memory (dark grey) is one or more blocks of memory obtained from the operating system but not yet allocated to the program;
    388 if there are multiple reserved blocks, they are also chained together, usually internally.
     386Reserved memory (dark grey) is one or more blocks of memory obtained from the \newterm{operating system} (OS) but not yet allocated to the program;
     387if there are multiple reserved blocks, they are also chained together.
    389388
    390389\begin{figure}
     
    395394\end{figure}
    396395
    397 In most allocator designs, allocated objects have management data embedded within them.
     396In many allocator designs, allocated objects and reserved blocks have management data embedded within them (see also Section~\ref{s:ObjectContainers}).
    398397Figure~\ref{f:AllocatedObject} shows an allocated object with a header, trailer, and optional spacing around the object.
    399398The header contains information about the object, \eg size, type, etc.
     
    404403When padding and spacing are necessary, neither can be used to satisfy a future allocation request while the current allocation exists.
    405404
    406 A free object also contains management data, \eg size, pointers, etc.
     405A free object often contains management data, \eg size, pointers, etc.
    407406Often the free list is chained internally so it does not consume additional storage, \ie the link fields are placed at known locations in the unused memory blocks.
    408407For internal chaining, the amount of management data for a free node defines the minimum allocation size, \eg if 16 bytes are needed for a free-list node, allocation requests less than 16 bytes are rounded up.
    409 The information in an allocated or freed object is overwritten when it transitions from allocated to freed and vice-versa by new management information and/or program data.
     408The information in an allocated or freed object is overwritten when it transitions from allocated to freed and vice-versa by new program data and/or management information.
    410409
    411410\begin{figure}
     
    428427\label{s:Fragmentation}
    429428
    430 Fragmentation is memory requested from the operating system but not used by the program;
     429Fragmentation is memory requested from the OS but not used by the program;
    431430hence, allocated objects are not fragmentation.
    432431Figure~\ref{f:InternalExternalFragmentation} shows fragmentation is divided into two forms: internal or external.
     
    443442An allocator should strive to keep internal management information to a minimum.
    444443
    445 \newterm{External fragmentation} is all memory space reserved from the operating system but not allocated to the program~\cite{Wilson95,Lim98,Siebert00}, which includes all external management data, freed objects, and reserved memory.
     444\newterm{External fragmentation} is all memory space reserved from the OS but not allocated to the program~\cite{Wilson95,Lim98,Siebert00}, which includes all external management data, freed objects, and reserved memory.
    446445This memory is problematic in two ways: heap blowup and highly fragmented memory.
    447446\newterm{Heap blowup} occurs when freed memory cannot be reused for future allocations leading to potentially unbounded external fragmentation growth~\cite{Berger00}.
    448 Memory can become \newterm{highly fragmented} after multiple allocations and deallocations of objects, resulting in a checkerboard of adjacent allocated and free areas, where the free blocks have become very small.
     447Memory can become \newterm{highly fragmented} after multiple allocations and deallocations of objects, resulting in a checkerboard of adjacent allocated and free areas, where the free blocks have become to small to service requests.
    449448% Figure~\ref{f:MemoryFragmentation} shows an example of how a small block of memory fragments as objects are allocated and deallocated over time.
    450449Heap blowup can occur due to allocator policies that are too restrictive in reusing freed memory (the allocated size cannot use a larger free block) and/or no coalescing of free storage.
     
    452451% Memory is highly fragmented when most free blocks are unusable because of their sizes.
    453452% For example, Figure~\ref{f:Contiguous} and Figure~\ref{f:HighlyFragmented} have the same quantity of external fragmentation, but Figure~\ref{f:HighlyFragmented} is highly fragmented.
    454 % If there is a request to allocate a large object, Figure~\ref{f:Contiguous} is more likely to be able to satisfy it with existing free memory, while Figure~\ref{f:HighlyFragmented} likely has to request more memory from the operating system.
     453% If there is a request to allocate a large object, Figure~\ref{f:Contiguous} is more likely to be able to satisfy it with existing free memory, while Figure~\ref{f:HighlyFragmented} likely has to request more memory from the OS.
    455454
    456455% \begin{figure}
     
    475474The first approach is a \newterm{sequential-fit algorithm} with one list of free objects that is searched for a block large enough to fit a requested object size.
    476475Different search policies determine the free object selected, \eg the first free object large enough or closest to the requested size.
    477 Any storage larger than the request can become spacing after the object or be split into a smaller free object.
     476Any storage larger than the request can become spacing after the object or split into a smaller free object.
    478477% The cost of the search depends on the shape and quality of the free list, \eg a linear versus a binary-tree free-list, a sorted versus unsorted free-list.
    479478
     
    489488
    490489The third approach is \newterm{splitting} and \newterm{coalescing algorithms}.
    491 When an object is allocated, if there are no free objects of the requested size, a larger free object may be split into two smaller objects to satisfy the allocation request without obtaining more memory from the operating system.
    492 For example, in the \newterm{buddy system}, a block of free memory is split into two equal chunks, one of those chunks is again split into two equal chunks, and so on until a block just large enough to fit the requested object is created.
    493 When an object is deallocated it is coalesced with the objects immediately before and after it in memory, if they are free, turning them into one larger object.
     490When an object is allocated, if there are no free objects of the requested size, a larger free object is split into two smaller objects to satisfy the allocation request rather than obtaining more memory from the OS.
     491For example, in the \newterm{buddy system}, a block of free memory is split into equal chunks, one of those chunks is again split, and so on until a minimal block is created that fits the requested object.
     492When an object is deallocated, it is coalesced with the objects immediately before and after it in memory, if they are free, turning them into one larger block.
    494493Coalescing can be done eagerly at each deallocation or lazily when an allocation cannot be fulfilled.
    495 In all cases, coalescing increases allocation latency, hence some allocations can cause unbounded delays during coalescing.
     494In all cases, coalescing increases allocation latency, hence some allocations can cause unbounded delays.
    496495While coalescing does not reduce external fragmentation, the coalesced blocks improve fragmentation quality so future allocations are less likely to cause heap blowup.
    497496% Splitting and coalescing can be used with other algorithms to avoid highly fragmented memory.
     
    501500\label{s:Locality}
    502501
    503 The principle of locality recognizes that programs tend to reference a small set of data, called a working set, for a certain period of time, where a working set is composed of temporal and spatial accesses~\cite{Denning05}.
     502The principle of locality recognizes that programs tend to reference a small set of data, called a \newterm{working set}, for a certain period of time, composed of temporal and spatial accesses~\cite{Denning05}.
    504503% Temporal clustering implies a group of objects are accessed repeatedly within a short time period, while spatial clustering implies a group of objects physically close together (nearby addresses) are accessed repeatedly within a short time period.
    505504% Temporal locality commonly occurs during an iterative computation with a fixed set of disjoint variables, while spatial locality commonly occurs when traversing an array.
    506 Hardware takes advantage of temporal and spatial locality through multiple levels of caching, \ie memory hierarchy.
     505Hardware takes advantage of the working set through multiple levels of caching, \ie memory hierarchy.
    507506% When an object is accessed, the memory physically located around the object is also cached with the expectation that the current and nearby objects will be referenced within a short period of time.
    508 For example, entire cache lines are transferred between memory and cache and entire virtual-memory pages are transferred between disk and memory.
     507For example, entire cache lines are transferred between cache and memory, and entire virtual-memory pages are transferred between memory and disk.
    509508% A program exhibiting good locality has better performance due to fewer cache misses and page faults\footnote{With the advent of large RAM memory, paging is becoming less of an issue in modern programming.}.
    510509
     
    532531\label{s:MutualExclusion}
    533532
    534 \newterm{Mutual exclusion} provides sequential access to the shared management data of the heap.
     533\newterm{Mutual exclusion} provides sequential access to the shared-management data of the heap.
    535534There are two performance issues for mutual exclusion.
    536535First is the overhead necessary to perform (at least) a hardware atomic operation every time a shared resource is accessed.
    537536Second is when multiple threads contend for a shared resource simultaneously, and hence, some threads must wait until the resource is released.
    538537Contention can be reduced in a number of ways:
    539 1) Using multiple fine-grained locks versus a single lock, spreading the contention across a number of locks.
     5381) Using multiple fine-grained locks versus a single lock to spread the contention across a number of locks.
    5405392) Using trylock and generating new storage if the lock is busy, yielding a classic space versus time tradeoff.
    5415403) Using one of the many lock-free approaches for reducing contention on basic data-structure operations~\cite{Oyama99}.
     
    551550a memory allocator can only affect the latter two.
    552551
    553 Assume two objects, object$_1$ and object$_2$, share a cache line.
    554 \newterm{Program-induced false-sharing} occurs when thread$_1$ passes a reference to object$_2$ to thread$_2$, and then threads$_1$ modifies object$_1$ while thread$_2$ modifies object$_2$.
     552Specifically, assume two objects, O$_1$ and O$_2$, share a cache line, with threads, T$_1$ and T$_2$.
     553\newterm{Program-induced false-sharing} occurs when T$_1$ passes a reference to O$_2$ to T$_2$, and then T$_1$ modifies O$_1$ while T$_2$ modifies O$_2$.
    555554% Figure~\ref{f:ProgramInducedFalseSharing} shows when Thread$_1$ passes Object$_2$ to Thread$_2$, a false-sharing situation forms when Thread$_1$ modifies Object$_1$ and Thread$_2$ modifies Object$_2$.
    556555% Changes to Object$_1$ invalidate CPU$_2$'s cache line, and changes to Object$_2$ invalidate CPU$_1$'s cache line.
     
    574573% \label{f:FalseSharing}
    575574% \end{figure}
    576 \newterm{Allocator-induced active false-sharing}\label{s:AllocatorInducedActiveFalseSharing} occurs when object$_1$ and object$_2$ are heap allocated and their references are passed to thread$_1$ and thread$_2$, which modify the objects.
     575\newterm{Allocator-induced active false-sharing}\label{s:AllocatorInducedActiveFalseSharing} occurs when O$_1$ and O$_2$ are heap allocated and their references are passed to T$_1$ and T$_2$, which modify the objects.
    577576% For example, in Figure~\ref{f:AllocatorInducedActiveFalseSharing}, each thread allocates an object and loads a cache-line of memory into its associated cache.
    578577% Again, changes to Object$_1$ invalidate CPU$_2$'s cache line, and changes to Object$_2$ invalidate CPU$_1$'s cache line.
     
    580579% is another form of allocator-induced false-sharing caused by program-induced false-sharing.
    581580% When an object in a program-induced false-sharing situation is deallocated, a future allocation of that object may cause passive false-sharing.
    582 when thread$_1$ passes object$_2$ to thread$_2$, and thread$_2$ subsequently deallocates object$_2$, and then object$_2$ is reallocated to thread$_2$ while thread$_1$ is still using object$_1$.
     581when T$_1$ passes O$_2$ to T$_2$, and T$_2$ subsequently deallocates O$_2$, and then O$_2$ is reallocated to T$_2$ while T$_1$ is still using O$_1$.
    583582
    584583
     
    593592\label{s:MultiThreadedMemoryAllocatorFeatures}
    594593
    595 The following features are used in the construction of multi-threaded memory-allocators:
    596 \begin{enumerate}[itemsep=0pt]
    597 \item multiple heaps: with or without a global heap, or with or without heap ownership.
    598 \item object containers: with or without ownership, fixed or variable sized, global or local free-lists.
    599 \item hybrid private/public heap
    600 \item allocation buffer
    601 \item lock-free operations
    602 \end{enumerate}
     594The following features are used in the construction of multi-threaded memory-allocators: multiple heaps, user-level threading, ownership, object containers, allocation buffer, lock-free operations.
    603595The first feature, multiple heaps, pertains to different kinds of heaps.
    604596The second feature, object containers, pertains to the organization of objects within the storage area.
     
    606598
    607599
    608 \subsection{Multiple Heaps}
     600\subsubsection{Multiple Heaps}
    609601\label{s:MultipleHeaps}
    610602
    611603A multi-threaded allocator has potentially multiple threads and heaps.
    612604The multiple threads cause complexity, and multiple heaps are a mechanism for dealing with the complexity.
    613 The spectrum ranges from multiple threads using a single heap, denoted as T:1 (see Figure~\ref{f:SingleHeap}), to multiple threads sharing multiple heaps, denoted as T:H (see Figure~\ref{f:SharedHeaps}), to one thread per heap, denoted as 1:1 (see Figure~\ref{f:PerThreadHeap}), which is almost back to a single-threaded allocator.
     605The spectrum ranges from multiple threads using a single heap, denoted as T:1, to multiple threads sharing multiple heaps, denoted as T:H, to one thread per heap, denoted as 1:1, which is almost back to a single-threaded allocator.
    614606
    615607\begin{figure}
     
    635627\end{figure}
    636628
    637 \paragraph{T:1 model} where all threads allocate and deallocate objects from one heap.
    638 Memory is obtained from the freed objects, or reserved memory in the heap, or from the operating system (OS);
    639 the heap may also return freed memory to the operating system.
     629\paragraph{T:1 model (see Figure~\ref{f:SingleHeap})} where all threads allocate and deallocate objects from one heap.
     630Memory is obtained from the freed objects, or reserved memory in the heap, or from the OS;
     631the heap may also return freed memory to the OS.
    640632The arrows indicate the direction memory conceptually moves for each kind of operation: allocation moves memory along the path from the heap/operating-system to the user application, while deallocation moves memory along the path from the application back to the heap/operating-system.
    641633To safely handle concurrency, a single lock may be used for all heap operations or fine-grained locking for different operations.
    642634Regardless, a single heap may be a significant source of contention for programs with a large amount of memory allocation.
    643635
    644 \paragraph{T:H model} where each thread allocates storage from several heaps depending on certain criteria, with the goal of reducing contention by spreading allocations/deallocations across the heaps.
     636\paragraph{T:H model (see Figure~\ref{f:SharedHeaps})} where each thread allocates storage from several heaps depending on certain criteria, with the goal of reducing contention by spreading allocations/deallocations across the heaps.
    645637The decision on when to create a new heap and which heap a thread allocates from depends on the allocator design.
    646638To determine which heap to access, each thread must point to its associated heap in some way.
     
    673665An alternative implementation is for all heaps to share one reserved memory, which requires a separate lock for the reserved storage to ensure mutual exclusion when acquiring new memory.
    674666Because multiple threads can allocate/free/reallocate adjacent storage, all forms of false sharing may occur.
    675 Other storage-management options are to use @mmap@ to set aside (large) areas of virtual memory for each heap and suballocate each heap's storage within that area, pushing part of the storage management complexity back to the operating system.
     667Other storage-management options are to use @mmap@ to set aside (large) areas of virtual memory for each heap and suballocate each heap's storage within that area, pushing part of the storage management complexity back to the OS.
    676668
    677669% \begin{figure}
     
    684676Multiple heaps increase external fragmentation as the ratio of heaps to threads increases, which can lead to heap blowup.
    685677The external fragmentation experienced by a program with a single heap is now multiplied by the number of heaps, since each heap manages its own free storage and allocates its own reserved memory.
    686 Additionally, objects freed by one heap cannot be reused by other threads without increasing the cost of the memory operations, except indirectly by returning free memory to the operating system, which can be expensive.
    687 Depending on how the operating system provides dynamic storage to an application, returning storage may be difficult or impossible, \eg the contiguous @sbrk@ area in Unix.
    688 In the worst case, a program in which objects are allocated from one heap but deallocated to another heap means these freed objects are never reused.
     678Additionally, objects freed by one heap cannot be reused by other threads without increasing the cost of the memory operations, except indirectly by returning free memory to the OS (see Section~\ref{s:Ownership}).
     679Returning storage to the OS may be difficult or impossible, \eg the contiguous @sbrk@ area in Unix.
     680% In the worst case, a program in which objects are allocated from one heap but deallocated to another heap means these freed objects are never reused.
    689681
    690682Adding a \newterm{global heap} (G) attempts to reduce the cost of obtaining/returning memory among heaps (sharing) by buffering storage within the application address-space.
    691 Now, each heap obtains and returns storage to/from the global heap rather than the operating system.
     683Now, each heap obtains and returns storage to/from the global heap rather than the OS.
    692684Storage is obtained from the global heap only when a heap allocation cannot be fulfilled, and returned to the global heap when a heap's free memory exceeds some threshold.
    693 Similarly, the global heap buffers this memory, obtaining and returning storage to/from the operating system as necessary.
     685Similarly, the global heap buffers this memory, obtaining and returning storage to/from the OS as necessary.
    694686The global heap does not have its own thread and makes no internal allocation requests;
    695687instead, it uses the application thread, which called one of the multiple heaps and then the global heap, to perform operations.
    696688Hence, the worst-case cost of a memory operation includes all these steps.
    697 With respect to heap blowup, the global heap provides an indirect mechanism to move free memory among heaps, which usually has a much lower cost than interacting with the operating system to achieve the same goal and is independent of the mechanism used by the operating system to present dynamic memory to an address space.
    698 
     689With respect to heap blowup, the global heap provides an indirect mechanism to move free memory among heaps, which usually has a much lower cost than interacting with the OS to achieve the same goal and is independent of the mechanism used by the OS to present dynamic memory to an address space.
    699690However, since any thread may indirectly perform a memory operation on the global heap, it is a shared resource that requires locking.
    700691A single lock can be used to protect the global heap or fine-grained locking can be used to reduce contention.
    701692In general, the cost is minimal since the majority of memory operations are completed without the use of the global heap.
    702693
    703 
    704 \paragraph{1:1 model (thread heaps)} where each thread has its own heap eliminating most contention and locking because threads seldom access another thread's heap (see ownership in Section~\ref{s:Ownership}).
     694\paragraph{1:1 model (see Figure~\ref{f:PerThreadHeap})} where each thread has its own heap eliminating most contention and locking because threads seldom access another thread's heap (see Section~\ref{s:Ownership}).
    705695An additional benefit of thread heaps is improved locality due to better memory layout.
    706696As each thread only allocates from its heap, all objects are consolidated in the storage area for that heap, better utilizing each CPUs cache and accessing fewer pages.
     
    708698Thread heaps can also eliminate allocator-induced active false-sharing, if memory is acquired so it does not overlap at crucial boundaries with memory for another thread's heap.
    709699For example, assume page boundaries coincide with cache line boundaries, if a thread heap always acquires pages of memory then no two threads share a page or cache line unless pointers are passed among them.
    710 Hence, allocator-induced active false-sharing cannot occur because the memory for thread heaps never overlaps.
     700% Hence, allocator-induced active false-sharing cannot occur because the memory for thread heaps never overlaps.
    711701
    712702When a thread terminates, there are two options for handling its thread heap.
     
    720710
    721711It is possible to use any of the heap models with user-level (M:N) threading.
    722 However, an important goal of user-level threading is for fast operations (creation/termination/context-switching) by not interacting with the operating system, which allows the ability to create large numbers of high-performance interacting threads ($>$ 10,000).
     712However, an important goal of user-level threading is for fast operations (creation/termination/context-switching) by not interacting with the OS, which allows the ability to create large numbers of high-performance interacting threads ($>$ 10,000).
    723713It is difficult to retain this goal, if the user-threading model is directly involved with the heap model.
    724714Figure~\ref{f:UserLevelKernelHeaps} shows that virtually all user-level threading systems use whatever kernel-level heap-model is provided by the language runtime.
     
    732722\end{figure}
    733723
    734 Adopting this model results in a subtle problem with shared heaps.
    735 With kernel threading, an operation that is started by a kernel thread is always completed by that thread.
    736 For example, if a kernel thread starts an allocation/deallocation on a shared heap, it always completes that operation with that heap even if preempted, \ie any locking correctness associated with the shared heap is preserved across preemption.
     724Adopting user threading results in a subtle problem with shared heaps.
     725With kernel threading, an operation started by a kernel thread is always completed by that thread.
     726For example, if a kernel thread starts an allocation/deallocation on a shared heap, it always completes that operation with that heap, even if preempted, \ie any locking correctness associated with the shared heap is preserved across preemption.
    737727However, this correctness property is not preserved for user-level threading.
    738728A user thread can start an allocation/deallocation on one kernel thread, be preempted (time slice), and continue running on a different kernel thread to complete the operation~\cite{Dice02}.
    739729When the user thread continues on the new kernel thread, it may have pointers into the previous kernel-thread's heap and hold locks associated with it.
    740730To get the same kernel-thread safety, time slicing must be disabled/\-enabled around these operations, so the user thread cannot jump to another kernel thread.
    741 However, eagerly disabling/enabling time-slicing on the allocation/deallocation fast path is expensive, because preemption does not happen that frequently.
     731However, eagerly disabling/enabling time-slicing on the allocation/deallocation fast path is expensive, because preemption is infrequent (milliseconds).
    742732Instead, techniques exist to lazily detect this case in the interrupt handler, abort the preemption, and return to the operation so it can complete atomically.
    743 Occasionally ignoring a preemption should be benign, but a persistent lack of preemption can result in both short and long term starvation;
    744 techniques like rollforward can be used to force an eventual preemption.
     733Occasional ignoring of a preemption should be benign, but a persistent lack of preemption can result in starvation;
     734techniques like rolling forward the preemption to the next context switch can be used.
    745735
    746736
     
    800790% For example, in Figure~\ref{f:AllocatorInducedPassiveFalseSharing}, Object$_2$ may be deallocated to Thread$_2$'s heap initially.
    801791% If Thread$_2$ reallocates Object$_2$ before it is returned to its owner heap, then passive false-sharing may occur.
     792
     793For thread heaps with ownership, it is possible to combine these approaches into a hybrid approach with both private and public heaps.% (see~Figure~\ref{f:HybridPrivatePublicHeap}).
     794The main goal of the hybrid approach is to eliminate locking on thread-local allocation/deallocation, while providing ownership to prevent heap blowup.
     795In the hybrid approach, a thread first allocates from its private heap and second from its public heap if no free memory exists in the private heap.
     796Similarly, a thread first deallocates an object to its private heap, and second to the public heap.
     797Both private and public heaps can allocate/deallocate to/from the global heap if there is no free memory or excess free memory, although an implementation may choose to funnel all interaction with the global heap through one of the heaps.
     798% Note, deallocation from the private to the public (dashed line) is unlikely because there is no obvious advantages unless the public heap provides the only interface to the global heap.
     799Finally, when a thread frees an object it does not own, the object is either freed immediately to its owner's public heap or put in the freeing thread's private heap for delayed ownership, which does allows the freeing thread to temporarily reuse an object before returning it to its owner or batch objects for an owner heap into a single return.
     800
     801% \begin{figure}
     802% \centering
     803% \input{PrivatePublicHeaps.pstex_t}
     804% \caption{Hybrid Private/Public Heap for Per-thread Heaps}
     805% \label{f:HybridPrivatePublicHeap}
     806% \vspace{10pt}
     807% \input{RemoteFreeList.pstex_t}
     808% \caption{Remote Free-List}
     809% \label{f:RemoteFreeList}
     810% \end{figure}
     811
     812% As mentioned, an implementation may have only one heap interact with the global heap, so the other heap can be simplified.
     813% For example, if only the private heap interacts with the global heap, the public heap can be reduced to a lock-protected free-list of objects deallocated by other threads due to ownership, called a \newterm{remote free-list}.
     814% To avoid heap blowup, the private heap allocates from the remote free-list when it reaches some threshold or it has no free storage.
     815% Since the remote free-list is occasionally cleared during an allocation, this adds to that cost.
     816% Clearing the remote free-list is $O(1)$ if the list can simply be added to the end of the private-heap's free-list, or $O(N)$ if some action must be performed for each freed object.
     817 
     818% If only the public heap interacts with other threads and the global heap, the private heap can handle thread-local allocations and deallocations without locking.
     819% In this scenario, the private heap must deallocate storage after reaching a certain threshold to the public heap (and then eventually to the global heap from the public heap) or heap blowup can occur.
     820% If the public heap does the major management, the private heap can be simplified to provide high-performance thread-local allocations and deallocations.
     821 
     822% The main disadvantage of each thread having both a private and public heap is the complexity of managing two heaps and their interactions in an allocator.
     823% Interestingly, heap implementations often focus on either a private or public heap, giving the impression a single versus a hybrid approach is being used.
     824% In many case, the hybrid approach is actually being used, but the simpler heap is just folded into the complex heap, even though the operations logically belong in separate heaps.
     825% For example, a remote free-list is actually a simple public-heap, but may be implemented as an integral component of the complex private-heap in an allocator, masking the presence of a hybrid approach.
    802826
    803827
     
    817841
    818842
    819 \subsection{Object Containers}
     843\subsubsection{Object Containers}
    820844\label{s:ObjectContainers}
    821845
     
    827851\eg an object is accessed by the program after it is allocated, while the header is accessed by the allocator after it is free.
    828852
    829 The alternative factors common header data to a separate location in memory and organizes associated free storage into blocks called \newterm{object containers} (\newterm{superblocks} in~\cite{Berger00}), as in Figure~\ref{f:ObjectContainer}.
     853An alternative approach factors common header data to a separate location in memory and organizes associated free storage into blocks called \newterm{object containers} (\newterm{superblocks}~\cite{Berger00}), as in Figure~\ref{f:ObjectContainer}.
    830854The header for the container holds information necessary for all objects in the container;
    831855a trailer may also be used at the end of the container.
     
    862886
    863887
    864 \subsubsection{Container Ownership}
     888\paragraph{Container Ownership}
    865889\label{s:ContainerOwnership}
    866890
     
    894918
    895919Additional restrictions may be applied to the movement of containers to prevent active false-sharing.
    896 For example, if a container changes ownership through the global heap, then when a thread allocates an object from the newly acquired container it is actively false-sharing even though no objects are passed among threads.
     920For example, if a container changes ownership through the global heap, then a thread allocating from the newly acquired container is actively false-sharing even though no objects are passed among threads.
    897921Note, once the thread frees the object, no more false sharing can occur until the container changes ownership again.
    898922To prevent this form of false sharing, container movement may be restricted to when all objects in the container are free.
    899 One implementation approach that increases the freedom to return a free container to the operating system involves allocating containers using a call like @mmap@, which allows memory at an arbitrary address to be returned versus only storage at the end of the contiguous @sbrk@ area, again pushing storage management complexity back to the operating system.
     923One implementation approach that increases the freedom to return a free container to the OS involves allocating containers using a call like @mmap@, which allows memory at an arbitrary address to be returned versus only storage at the end of the contiguous @sbrk@ area, again pushing storage management complexity back to the OS.
    900924
    901925% \begin{figure}
     
    930954
    931955
    932 \subsubsection{Container Size}
     956\paragraph{Container Size}
    933957\label{s:ContainerSize}
    934958
     
    941965However, with more objects in a container, there may be more objects that are unallocated, increasing external fragmentation.
    942966With smaller containers, not only are there more containers, but a second new problem arises where objects are larger than the container.
    943 In general, large objects, \eg greater than 64\,KB, are allocated directly from the operating system and are returned immediately to the operating system to reduce long-term external fragmentation.
     967In general, large objects, \eg greater than 64\,KB, are allocated directly from the OS and are returned immediately to the OS to reduce long-term external fragmentation.
    944968If the container size is small, \eg 1\,KB, then a 1.5\,KB object is treated as a large object, which is likely to be inappropriate.
    945969Ideally, it is best to use smaller containers for smaller objects, and larger containers for medium objects, which leads to the issue of locating the container header.
     
    970994
    971995
    972 \subsubsection{Container Free-Lists}
     996\paragraph{Container Free-Lists}
    973997\label{s:containersfreelists}
    974998
     
    10051029
    10061030
    1007 \subsubsection{Hybrid Private/Public Heap}
    1008 \label{s:HybridPrivatePublicHeap}
    1009 
    1010 Section~\ref{s:Ownership} discusses advantages and disadvantages of public heaps (T:H model and with ownership) and private heaps (thread heaps with ownership).
    1011 For thread heaps with ownership, it is possible to combine these approaches into a hybrid approach with both private and public heaps (see~Figure~\ref{f:HybridPrivatePublicHeap}).
    1012 The main goal of the hybrid approach is to eliminate locking on thread-local allocation/deallocation, while providing ownership to prevent heap blowup.
    1013 In the hybrid approach, a thread first allocates from its private heap and second from its public heap if no free memory exists in the private heap.
    1014 Similarly, a thread first deallocates an object to its private heap, and second to the public heap.
    1015 Both private and public heaps can allocate/deallocate to/from the global heap if there is no free memory or excess free memory, although an implementation may choose to funnel all interaction with the global heap through one of the heaps.
    1016 Note, deallocation from the private to the public (dashed line) is unlikely because there is no obvious advantages unless the public heap provides the only interface to the global heap.
    1017 Finally, when a thread frees an object it does not own, the object is either freed immediately to its owner's public heap or put in the freeing thread's private heap for delayed ownership, which allows the freeing thread to temporarily reuse an object before returning it to its owner or batch objects for an owner heap into a single return.
    1018 
    1019 \begin{figure}
    1020 \centering
    1021 \input{PrivatePublicHeaps.pstex_t}
    1022 \caption{Hybrid Private/Public Heap for Per-thread Heaps}
    1023 \label{f:HybridPrivatePublicHeap}
    1024 % \vspace{10pt}
    1025 % \input{RemoteFreeList.pstex_t}
    1026 % \caption{Remote Free-List}
    1027 % \label{f:RemoteFreeList}
    1028 \end{figure}
    1029 
    1030 As mentioned, an implementation may have only one heap interact with the global heap, so the other heap can be simplified.
    1031 For example, if only the private heap interacts with the global heap, the public heap can be reduced to a lock-protected free-list of objects deallocated by other threads due to ownership, called a \newterm{remote free-list}.
    1032 To avoid heap blowup, the private heap allocates from the remote free-list when it reaches some threshold or it has no free storage.
    1033 Since the remote free-list is occasionally cleared during an allocation, this adds to that cost.
    1034 Clearing the remote free-list is $O(1)$ if the list can simply be added to the end of the private-heap's free-list, or $O(N)$ if some action must be performed for each freed object.
    1035 
    1036 If only the public heap interacts with other threads and the global heap, the private heap can handle thread-local allocations and deallocations without locking.
    1037 In this scenario, the private heap must deallocate storage after reaching a certain threshold to the public heap (and then eventually to the global heap from the public heap) or heap blowup can occur.
    1038 If the public heap does the major management, the private heap can be simplified to provide high-performance thread-local allocations and deallocations.
    1039 
    1040 The main disadvantage of each thread having both a private and public heap is the complexity of managing two heaps and their interactions in an allocator.
    1041 Interestingly, heap implementations often focus on either a private or public heap, giving the impression a single versus a hybrid approach is being used.
    1042 In many case, the hybrid approach is actually being used, but the simpler heap is just folded into the complex heap, even though the operations logically belong in separate heaps.
    1043 For example, a remote free-list is actually a simple public-heap, but may be implemented as an integral component of the complex private-heap in an allocator, masking the presence of a hybrid approach.
    1044 
    1045 
    1046 \subsection{Allocation Buffer}
     1031\subsubsection{Allocation Buffer}
    10471032\label{s:AllocationBuffer}
    10481033
    10491034An allocation buffer is reserved memory (see Section~\ref{s:AllocatorComponents}) not yet allocated to the program, and is used for allocating objects when the free list is empty.
    10501035That is, rather than requesting new storage for a single object, an entire buffer is requested from which multiple objects are allocated later.
    1051 Any heap may use an allocation buffer, resulting in allocation from the buffer before requesting objects (containers) from the global heap or operating system, respectively.
     1036Any heap may use an allocation buffer, resulting in allocation from the buffer before requesting objects (containers) from the global heap or OS, respectively.
    10521037The allocation buffer reduces contention and the number of global/operating-system calls.
    10531038For coalescing, a buffer is split into smaller objects by allocations, and recomposed into larger buffer areas during deallocations.
     
    10621047
    10631048Allocation buffers may increase external fragmentation, since some memory in the allocation buffer may never be allocated.
    1064 A smaller allocation buffer reduces the amount of external fragmentation, but increases the number of calls to the global heap or operating system.
     1049A smaller allocation buffer reduces the amount of external fragmentation, but increases the number of calls to the global heap or OS.
    10651050The allocation buffer also slightly increases internal fragmentation, since a pointer is necessary to locate the next free object in the buffer.
    10661051
     
    10681053For example, when a container is created, rather than placing all objects within the container on the free list, the objects form an allocation buffer and are allocated from the buffer as allocation requests are made.
    10691054This lazy method of constructing objects is beneficial in terms of paging and caching.
    1070 For example, although an entire container, possibly spanning several pages, is allocated from the operating system, only a small part of the container is used in the working set of the allocator, reducing the number of pages and cache lines that are brought into higher levels of cache.
    1071 
    1072 
    1073 \subsection{Lock-Free Operations}
     1055For example, although an entire container, possibly spanning several pages, is allocated from the OS, only a small part of the container is used in the working set of the allocator, reducing the number of pages and cache lines that are brought into higher levels of cache.
     1056
     1057
     1058\subsubsection{Lock-Free Operations}
    10741059\label{s:LockFreeOperations}
    10751060
     
    11941179% A sequence of code that is guaranteed to run to completion before being invoked to accept another input is called serially-reusable code.~\cite{SeriallyReusable}\label{p:SeriallyReusable}
    11951180% \end{quote}
    1196 % If a KT is preempted during an allocation operation, the operating system can schedule another KT on the same CPU, which can begin an allocation operation before the previous operation associated with this CPU has completed, invalidating heap correctness.
     1181% If a KT is preempted during an allocation operation, the OS can schedule another KT on the same CPU, which can begin an allocation operation before the previous operation associated with this CPU has completed, invalidating heap correctness.
    11971182% Note, the serially-reusable problem can occur in sequential programs with preemption, if the signal handler calls the preempted function, unless the function is serially reusable.
    1198 % Essentially, the serially-reusable problem is a race condition on an unprotected critical subsection, where the operating system is providing the second thread via the signal handler.
     1183% Essentially, the serially-reusable problem is a race condition on an unprotected critical subsection, where the OS is providing the second thread via the signal handler.
    11991184%
    12001185% Library @librseq@~\cite{librseq} was used to perform a fast determination of the CPU and to ensure all memory operations complete on one CPU using @librseq@'s restartable sequences, which restart the critical subsection after undoing its writes, if the critical subsection is preempted.
     
    12561241A sequence of code that is guaranteed to run to completion before being invoked to accept another input is called serially-reusable code.~\cite{SeriallyReusable}\label{p:SeriallyReusable}
    12571242\end{quote}
    1258 If a KT is preempted during an allocation operation, the operating system can schedule another KT on the same CPU, which can begin an allocation operation before the previous operation associated with this CPU has completed, invalidating heap correctness.
     1243If a KT is preempted during an allocation operation, the OS can schedule another KT on the same CPU, which can begin an allocation operation before the previous operation associated with this CPU has completed, invalidating heap correctness.
    12591244Note, the serially-reusable problem can occur in sequential programs with preemption, if the signal handler calls the preempted function, unless the function is serially reusable.
    1260 Essentially, the serially-reusable problem is a race condition on an unprotected critical subsection, where the operating system is providing the second thread via the signal handler.
     1245Essentially, the serially-reusable problem is a race condition on an unprotected critical subsection, where the OS is providing the second thread via the signal handler.
    12611246
    12621247Library @librseq@~\cite{librseq} was used to perform a fast determination of the CPU and to ensure all memory operations complete on one CPU using @librseq@'s restartable sequences, which restart the critical subsection after undoing its writes, if the critical subsection is preempted.
     
    12731258For the T:H=CPU and 1:1 models, locking is eliminated along the allocation fastpath.
    12741259However, T:H=CPU has poor operating-system support to determine the CPU id (heap id) and prevent the serially-reusable problem for KTs.
    1275 More operating system support is required to make this model viable, but there is still the serially-reusable problem with user-level threading.
     1260More OS support is required to make this model viable, but there is still the serially-reusable problem with user-level threading.
    12761261So the 1:1 model had no atomic actions along the fastpath and no special operating-system support requirements.
    12771262The 1:1 model still has the serially-reusable problem with user-level threading, which is addressed in Section~\ref{s:UserlevelThreadingSupport}, and the greatest potential for heap blowup for certain allocation patterns.
     
    13081293A primary goal of llheap is low latency, hence the name low-latency heap (llheap).
    13091294Two forms of latency are internal and external.
    1310 Internal latency is the time to perform an allocation, while external latency is time to obtain/return storage from/to the operating system.
     1295Internal latency is the time to perform an allocation, while external latency is time to obtain/return storage from/to the OS.
    13111296Ideally latency is $O(1)$ with a small constant.
    13121297
     
    13141299The mitigating factor is that most programs have well behaved allocation patterns, where the majority of allocation operations can be $O(1)$, and heap blowup does not occur without coalescing (although the allocation footprint may be slightly larger).
    13151300
    1316 To obtain $O(1)$ external latency means obtaining one large storage area from the operating system and subdividing it across all program allocations, which requires a good guess at the program storage high-watermark and potential large external fragmentation.
     1301To obtain $O(1)$ external latency means obtaining one large storage area from the OS and subdividing it across all program allocations, which requires a good guess at the program storage high-watermark and potential large external fragmentation.
    13171302Excluding real-time operating-systems, operating-system operations are unbounded, and hence some external latency is unavoidable.
    13181303The mitigating factor is that operating-system calls can often be reduced if a programmer has a sense of the storage high-watermark and the allocator is capable of using this information (see @malloc_expansion@ \pageref{p:malloc_expansion}).
     
    13291314headers per allocation versus containers,
    13301315no coalescing to minimize latency,
    1331 global heap memory (pool) obtained from the operating system using @mmap@ to create and reuse heaps needed by threads,
     1316global heap memory (pool) obtained from the OS using @mmap@ to create and reuse heaps needed by threads,
    13321317local reserved memory (pool) per heap obtained from global pool,
    1333 global reserved memory (pool) obtained from the operating system using @sbrk@ call,
     1318global reserved memory (pool) obtained from the OS using @sbrk@ call,
    13341319optional fast-lookup table for converting allocation requests into bucket sizes,
    13351320optional statistic-counters table for accumulating counts of allocation operations.
     
    13581343Each heap uses segregated free-buckets that have free objects distributed across 91 different sizes from 16 to 4M.
    13591344All objects in a bucket are of the same size.
    1360 The number of buckets used is determined dynamically depending on the crossover point from @sbrk@ to @mmap@ allocation using @mallopt( M_MMAP_THRESHOLD )@, \ie small objects managed by the program and large objects managed by the operating system.
     1345The number of buckets used is determined dynamically depending on the crossover point from @sbrk@ to @mmap@ allocation using @mallopt( M_MMAP_THRESHOLD )@, \ie small objects managed by the program and large objects managed by the OS.
    13611346Each free bucket of a specific size has two lists.
    136213471) A free stack used solely by the KT heap-owner, so push/pop operations do not require locking.
     
    13671352Algorithm~\ref{alg:heapObjectAlloc} shows the allocation outline for an object of size $S$.
    13681353First, the allocation is divided into small (@sbrk@) or large (@mmap@).
    1369 For large allocations, the storage is mapped directly from the operating system.
     1354For large allocations, the storage is mapped directly from the OS.
    13701355For small allocations, $S$ is quantized into a bucket size.
    13711356Quantizing is performed using a binary search over the ordered bucket array.
     
    13781363heap's local pool,
    13791364global pool,
    1380 operating system (@sbrk@).
     1365OS (@sbrk@).
    13811366
    13821367\begin{algorithm}
     
    14431428Algorithm~\ref{alg:heapObjectFreeOwn} shows the de-allocation (free) outline for an object at address $A$ with ownership.
    14441429First, the address is divided into small (@sbrk@) or large (@mmap@).
    1445 For large allocations, the storage is unmapped back to the operating system.
     1430For large allocations, the storage is unmapped back to the OS.
    14461431For small allocations, the bucket associated with the request size is retrieved.
    14471432If the bucket is local to the thread, the allocation is pushed onto the thread's associated bucket.
     
    30443029
    30453030\textsf{pt3} is the only memory allocator where the total dynamic memory goes down in the second half of the program lifetime when the memory is freed by the benchmark program.
    3046 It makes pt3 the only memory allocator that gives memory back to the operating system as it is freed by the program.
     3031It makes pt3 the only memory allocator that gives memory back to the OS as it is freed by the program.
    30473032
    30483033% FOR 1 THREAD
  • doc/papers/llheap/figures/AllocatorComponents.fig

    rfa5e1aa5 rb7b3e41  
    88-2
    991200 2
    10 6 1275 2025 2700 2625
    11106 2400 2025 2700 2625
    12112 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
     
    14132 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
    1514         2700 2025 2700 2325 2400 2325 2400 2025 2700 2025
    16 -6
    17 4 2 0 50 -1 2 11 0.0000 2 165 1005 2325 2400 Management\001
    1815-6
    19162 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
     
    61582 2 0 1 0 7 60 -1 13 0.000 0 0 -1 0 0 5
    6259         3300 2700 6300 2700 6300 3000 3300 3000 3300 2700
    63 4 0 0 50 -1 2 11 0.0000 2 165 585 3300 1725 Storage\001
     604 0 0 50 -1 2 11 0.0000 2 165 1005 3300 1725 Storage Data\001
    64614 2 0 50 -1 0 11 0.0000 2 165 810 3000 1875 free objects\001
    65624 2 0 50 -1 0 11 0.0000 2 135 1140 3000 2850 reserve memory\001
    66634 1 0 50 -1 0 11 0.0000 2 120 795 2325 1500 Static Zone\001
    67644 1 0 50 -1 0 11 0.0000 2 165 1845 4800 1500 Dynamic-Allocation Zone\001
     654 2 0 50 -1 2 11 0.0000 2 165 1005 2325 2325 Management\001
     664 2 0 50 -1 2 11 0.0000 2 135 375 2325 2525 Data\001
  • doc/theses/colby_parsons_MMAth/Makefile

    rfa5e1aa5 rb7b3e41  
    5050        figures/nasus_Channel_Contention \
    5151        figures/pyke_Channel_Contention \
     52        figures/pyke_Future \
     53        figures/nasus_Future \
     54        figures/pyke_Contend_2 \
     55        figures/pyke_Contend_4 \
     56        figures/pyke_Contend_8 \
     57        figures/pyke_Spin_2 \
     58        figures/pyke_Spin_4 \
     59        figures/pyke_Spin_8 \
     60        figures/nasus_Contend_2 \
     61        figures/nasus_Contend_4 \
     62        figures/nasus_Contend_8 \
     63        figures/nasus_Spin_2 \
     64        figures/nasus_Spin_4 \
     65        figures/nasus_Spin_8 \
    5266}
    5367
     
    98112
    99113${BASE}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${DATA} \
    100                 glossary.tex style/style.tex ${Macros}/common.tex ${Macros}/indexstyle local.bib ../../bibliography/pl.bib | ${Build}
     114                glossary.tex style/style.tex ${Macros}/common.tex ${Macros}/lstlang.sty ${Macros}/indexstyle local.bib ../../bibliography/pl.bib | ${Build}
    101115        # Must have *.aux file containing citations for bibtex
    102116        if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename $@}.tex ; fi
     
    112126## Define the default recipes.
    113127
    114 ${Build}:
     128${Build} :
    115129        mkdir -p ${Build}
    116130
  • doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/balance.cfa

    rfa5e1aa5 rb7b3e41  
    3131
    3232d_actor ** actor_arr;
    33 Allocation receive( d_actor & this, start_msg & msg ) with( this ) {
     33allocation receive( d_actor & this, start_msg & msg ) with( this ) {
    3434    for ( i; Set ) {
    35         *actor_arr[i + gstart] << shared_msg;
     35        *actor_arr[i + gstart] | shared_msg;
    3636    }
    3737    return Nodelete;
    3838}
    3939
    40 Allocation receive( d_actor & this, d_msg & msg ) with( this ) {
     40allocation receive( d_actor & this, d_msg & msg ) with( this ) {
    4141    if ( recs == rounds ) return Delete;
    4242    if ( recs % Batch == 0 ) {
    4343        for ( i; Batch ) {
    44             *actor_arr[gstart + sends % Set] << shared_msg;
     44            *actor_arr[gstart + sends % Set] | shared_msg;
    4545            sends += 1;
    4646        }
     
    5050}
    5151
    52 Allocation receive( filler & this, d_msg & msg ) { return Delete; }
     52allocation receive( filler & this, d_msg & msg ) { return Delete; }
    5353
    5454int main( int argc, char * argv[] ) {
     
    163163    #ifndef MULTI
    164164        for ( i; qpw )
    165                 *actors[i * ActorsPerQueue] << start_send;
     165                *actors[i * ActorsPerQueue] | start_send;
    166166    #else
    167167    for ( i; qpw * ActorProcs ) {
    168                 *actors[i * ActorsPerQueue] << start_send;
     168                *actors[i * ActorsPerQueue] | start_send;
    169169    }
    170170    #endif
    171171   
    172172    for ( i; FillActors )
    173         *filler_actors[i] << shared_msg;
     173        *filler_actors[i] | shared_msg;
    174174
    175175    stop_actor_system();
  • doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/dynamic.cfa

    rfa5e1aa5 rb7b3e41  
    2424
    2525uint64_t start_time;
    26 Allocation receive( derived_actor & receiver, derived_msg & msg ) {
     26allocation receive( derived_actor & receiver, derived_msg & msg ) {
    2727    if ( msg.cnt >= Times ) {
    2828        printf("%.2f\n", ((double)(bench_time() - start_time)) / ((double)Times) ); // ns
     
    3333    derived_actor * d_actor = malloc();
    3434    (*d_actor){};
    35     *d_actor << *d_msg;
     35    *d_actor | *d_msg;
    3636    return Delete;
    3737}
     
    6262    derived_actor * d_actor = malloc();
    6363    (*d_actor){};
    64     *d_actor << *d_msg;
     64    *d_actor | *d_msg;
    6565
    6666
  • doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/executor.cfa

    rfa5e1aa5 rb7b3e41  
    2525struct d_msg { inline message; } shared_msg;
    2626
    27 Allocation receive( d_actor & this, d_msg & msg ) with( this ) {
     27allocation receive( d_actor & this, d_msg & msg ) with( this ) {
    2828    if ( recs == rounds ) return Finished;
    2929    if ( recs % Batch == 0 ) {
    3030        for ( i; Batch ) {
    31             gstart[sends % Set] << shared_msg;
     31            gstart[sends % Set] | shared_msg;
    3232            sends += 1;
    3333        }
     
    9494
    9595        for ( i; Actors ) {
    96                 actors[i] << shared_msg;
     96                actors[i] | shared_msg;
    9797        } // for
    9898
  • doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/matrix.cfa

    rfa5e1aa5 rb7b3e41  
    2424}
    2525
    26 Allocation receive( derived_actor & receiver, derived_msg & msg ) {
     26allocation receive( derived_actor & receiver, derived_msg & msg ) {
    2727    for ( unsigned int i = 0; i < yc; i += 1 ) { // multiply X_row by Y_col and sum products
    2828        msg.Z[i] = 0;
     
    103103
    104104        for ( unsigned int r = 0; r < xr; r += 1 ) {
    105                 actors[r] << messages[r];
     105                actors[r] | messages[r];
    106106        } // for
    107107
  • doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/repeat.cfa

    rfa5e1aa5 rb7b3e41  
    4646
    4747Client * cl;
    48 Allocation receive( Server & this, IntMsg & msg ) { msg.val = 7; *cl << msg; return Nodelete; }
    49 Allocation receive( Server & this, CharMsg & msg ) { msg.val = 'x'; *cl << msg; return Nodelete; }
    50 Allocation receive( Server & this, StateMsg & msg ) { return Finished; }
     48allocation receive( Server & this, IntMsg & msg ) { msg.val = 7; *cl | msg; return Nodelete; }
     49allocation receive( Server & this, CharMsg & msg ) { msg.val = 'x'; *cl | msg; return Nodelete; }
     50allocation receive( Server & this, StateMsg & msg ) { return Finished; }
    5151
    5252void terminateServers( Client & this ) with(this) {
    5353    for ( i; Messages ) {
    54         servers[i] << stateMsg;
     54        servers[i] | stateMsg;
    5555    } // for
    5656}
    5757
    58 Allocation reset( Client & this ) with(this) {
     58allocation reset( Client & this ) with(this) {
    5959    times += 1;
    6060    if ( times == Times ) { terminateServers( this ); return Finished; }
    6161    results = 0;
    62     this << stateMsg;
     62    this | stateMsg;
    6363    return Nodelete;
    6464}
    6565
    66 Allocation process( Client & this ) with(this) {
     66allocation process( Client & this ) with(this) {
    6767    this.results++;
    6868    if ( results == 2 * Messages ) { return reset( this ); }
     
    7070}
    7171
    72 Allocation receive( Client & this, IntMsg & msg ) { return process( this ); }
    73 Allocation receive( Client & this, CharMsg & msg ) { return process( this ); }
    74 Allocation receive( Client & this, StateMsg & msg ) with(this) {
     72allocation receive( Client & this, IntMsg & msg ) { return process( this ); }
     73allocation receive( Client & this, CharMsg & msg ) { return process( this ); }
     74allocation receive( Client & this, StateMsg & msg ) with(this) {
    7575    for ( i; Messages ) {
    76         servers[i] << intmsg[i];
    77         servers[i] << charmsg[i];
     76        servers[i] | intmsg[i];
     77        servers[i] | charmsg[i];
    7878    }
    7979    return Nodelete;
     
    124124    Client client;
    125125    cl = &client;
    126     client << stateMsg;
     126    client | stateMsg;
    127127
    128128    stop_actor_system();
  • doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/static.cfa

    rfa5e1aa5 rb7b3e41  
    2323
    2424uint64_t start_time;
    25 Allocation receive( derived_actor & receiver, derived_msg & msg ) {
     25allocation receive( derived_actor & receiver, derived_msg & msg ) {
    2626    if ( msg.cnt >= Times ) {
    2727        printf("%.2f\n", ((double)(bench_time() - start_time)) / ((double)Times) ); // ns
     
    2929    }
    3030    msg.cnt++;
    31     receiver << msg;
     31    receiver | msg;
    3232    return Nodelete;
    3333}
     
    5858    derived_actor actor;
    5959
    60     actor << msg;
     60    actor | msg;
    6161
    6262    stop_actor_system();
  • doc/theses/colby_parsons_MMAth/benchmarks/actors/plotData.py

    rfa5e1aa5 rb7b3e41  
    166166                    for idx, arr in enumerate(data):
    167167                        plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker=next(marker) )
     168                    marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' ))
    168169                    if currBench == Bench.Executor or currBench == Bench.Matrix or currBench == Bench.Balance_One or currBench == Bench.Repeat:
    169170                        plt.yscale("log")
  • doc/theses/colby_parsons_MMAth/benchmarks/channels/plotData.py

    rfa5e1aa5 rb7b3e41  
    130130                for idx, arr in enumerate(data):
    131131                    plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker=next(marker) )
    132                
     132                marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' ))
    133133                plt.yscale("log")
    134134                # plt.ylim(1, None)
  • doc/theses/colby_parsons_MMAth/benchmarks/mutex_stmt/plotData.py

    rfa5e1aa5 rb7b3e41  
    103103                for idx, arr in enumerate(data):
    104104                    plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker=next(marker) )
     105                marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' ))
    105106                plt.yscale("log")
    106107                plt.xticks(procs)
  • doc/theses/colby_parsons_MMAth/code/basic_actor_example.cfa

    rfa5e1aa5 rb7b3e41  
    1919}
    2020
    21 Allocation receive( derived_actor & receiver, derived_msg & msg ) {
     21allocation receive( derived_actor & receiver, derived_msg & msg ) {
    2222    printf("The message contained the string: %s\n", msg.word);
    2323    return Finished; // Return allocation status of Finished now that the actor is done work
  • doc/theses/colby_parsons_MMAth/diagrams/gulp.tikz

    rfa5e1aa5 rb7b3e41  
    8787
    8888% Text Node
    89 \draw (23,6) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Worker}};
     89\draw (15,6) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Executor Thread}};
    9090% Text Node
    91 \draw (85,18) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Empty local queue}};
     91\draw (85,20) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Empty local queue}};
    9292% Text Node
    9393\draw (8,197) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Sharded message queues}};
     
    101101\draw (70,71) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Gulps queue 0}};
    102102% Text Node
    103 \draw (312,6) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Worker}};
     103\draw (303,6) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Executor Thread}};
    104104% Text Node
    105 \draw (374,18) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Local queue}};
     105\draw (374,21) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Local queue}};
    106106% Text Node
    107107\draw (297,198) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Sharded message queues}};
  • doc/theses/colby_parsons_MMAth/diagrams/inverted_actor.tikz

    rfa5e1aa5 rb7b3e41  
    275275
    276276% Text Node
    277 \draw (245,-2) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Worker Threads}};
     277\draw (258,-2) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\small Executor}};
    278278% Text Node
    279 \draw (155,-2) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Actors}};
     279\draw (155,-2) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\small Actors}};
    280280% Text Node
    281 \draw (21,73) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Message}\\{\footnotesize Queues}};
     281\draw (21,73) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\small Message}\\{\small Queues}};
    282282
    283283
  • doc/theses/colby_parsons_MMAth/diagrams/standard_actor.tikz

    rfa5e1aa5 rb7b3e41  
    182182
    183183% Text Node
    184 \draw (186,6) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Worker Threads}};
     184\draw (197,6) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\small Executor}};
    185185% Text Node
    186 \draw (91,9) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Actors}};
     186\draw (91,9) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\small Actors}};
    187187% Text Node
    188 \draw (81,207) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\footnotesize Mailboxes}};
     188\draw (78,207) node [anchor=north west][inner sep=0.75pt]   [align=left] {{\small Mailboxes}};
    189189
    190190
  • doc/theses/colby_parsons_MMAth/glossary.tex

    rfa5e1aa5 rb7b3e41  
    3737\newabbreviation{toctou}{TOCTOU}{\Newterm{time-of-check to time-of-use}}
    3838
    39 \newglossaryentry{actor}
    40 {
     39\newglossaryentry{actor}{
    4140name=actor,
    4241description={A basic unit of an actor system that can store local state and send messages to other actors.}
    4342}
    4443
    45 \newglossaryentry{impl_concurrency}
    46 {
     44\newglossaryentry{gulp}{
     45name={gulp},
     46first={\Newterm{gulp}},
     47description={Move the contents of message queue to a local queue of the executor thread using a single atomic instruction.}
     48}
     49
     50\newglossaryentry{impl_concurrency}{
    4751name=implicit concurrency,
     52first={\Newterm{implicit concurrency}},
    4853description={A class of concurrency features that abstract away explicit thread synchronization and mutual exclusion.}
    4954}
    5055
    51 \newglossaryentry{actor_model}
    52 {
     56\newglossaryentry{actor_model}{
    5357name=actor model,
     58first={\Newterm{actor model}},
    5459description={A concurrent computation model, where tasks are broken into units of work that are distributed to actors in the form of messages.}
    5560}
    5661
    57 \newglossaryentry{actor_system}
    58 {
     62\newglossaryentry{actor_system}{
    5963name=actor system,
     64first={\Newterm{actor system}},
    6065description={An implementation of the actor model.}
    6166}
    6267
    63 \newglossaryentry{synch_multiplex}
    64 {
     68\newglossaryentry{synch_multiplex}{
    6569name=synchronous multiplexing,
     70first={\Newterm{synchronous multiplexing}},
    6671description={synchronization on some subset of a set of resources.}
    6772}
  • doc/theses/colby_parsons_MMAth/local.bib

    rfa5e1aa5 rb7b3e41  
    100100}
    101101
     102@misc{go:sched,
     103  author = "The Go Programming Language",
     104  title = "src/runtime/proc.go",
     105  howpublished = {\href{https://go.dev/src/runtime/proc.go}},
     106  note = "[Online; accessed 23-May-2023]"
     107}
     108
    102109@misc{go:selectref,
    103110  author = "The Go Programming Language Specification",
     
    144151@misc{linux:select,
    145152  author = "Linux man pages",
    146   title = "select(2) Linux manual page",
     153  title = "select(2) - Linux manual page",
    147154  howpublished = {\href{https://man7.org/linux/man-pages/man2/select.2.html}},
    148155  note = "[Online; accessed 23-May-2023]"
     
    151158@misc{linux:poll,
    152159  author = "Linux man pages",
    153   title = "poll(2) Linux manual page",
     160  title = "poll(2) - Linux manual page",
    154161  howpublished = {\href{https://man7.org/linux/man-pages/man2/poll.2.html}},
    155162  note = "[Online; accessed 23-May-2023]"
     
    158165@misc{linux:epoll,
    159166  author = "Linux man pages",
    160   title = "epoll(7) Linux manual page",
     167  title = "epoll(7) - Linux manual page",
    161168  howpublished = {\href{https://man7.org/linux/man-pages/man7/epoll.7.html}},
    162169  note = "[Online; accessed 23-May-2023]"
  • doc/theses/colby_parsons_MMAth/style/style.tex

    rfa5e1aa5 rb7b3e41  
    22\CFAStyle                                               % CFA code-style
    33\lstset{language=CFA}                                   % default language
     4\setlength{\gcolumnposn}{3in}
    45
    56\newcommand{\newtermFont}{\emph}
    67\newcommand{\Newterm}[1]{\newtermFont{#1}}
     8%\renewcommand{\newterm}[1]{\newtermFont{#1}}
    79
    810\newcommand{\code}[1]{\lstinline[language=CFA]{#1}}
  • doc/theses/colby_parsons_MMAth/text/CFA_intro.tex

    rfa5e1aa5 rb7b3e41  
    179179\end{cfa}
    180180
    181 \subsection{Inheritance}
     181\subsection{Inheritance}\label{s:Inheritance}
    182182Inheritance in \CFA is taken from Plan-9 C's nominal inheritance.
    183183In \CFA, @struct@s can @inline@ another struct type to gain its fields and masquerade as that type.
  • doc/theses/colby_parsons_MMAth/text/actors.tex

    rfa5e1aa5 rb7b3e41  
    66
    77% C_TODO: add citations throughout chapter
    8 Actors are a concurrent feature that abstracts threading away from a user, and instead provides \gls{actor}s and messages as building blocks for concurrency.
    9 Actors are another message passing concurrency feature, similar to channels, but with more abstraction.
    10 Actors enter the realm of what is called \gls{impl_concurrency}, where programmers can write concurrent code without having to worry about explicit thread synchronization and mutual exclusion.
    11 The study of actors can be broken into two concepts, the \gls{actor_model}, which describes the model of computation and the \gls{actor_system}, which refers to the implementation of the model in practice.
     8Actors are an indirect concurrent feature that abstracts threading away from a programmer, and instead provides \gls{actor}s and messages as building blocks for concurrency, where message passing means there is no shared data to protect, making actors amenable in a distributed environment.
     9Actors are another message passing concurrency feature, similar to channels but with more abstraction, and are in the realm of \gls{impl_concurrency}, where programmers write concurrent code without dealing with explicit thread creation or interaction.
     10The study of actors can be broken into two concepts, the \gls{actor_model}, which describes the model of computation and the \gls{actor_system}, which refers to the implementation of the model.
    1211Before discussing \CFA's actor system in detail, it is important to first describe the actor model, and the classic approach to implementing an actor system.
    1312
    14 \section{The Actor Model}
    15 The actor model is a paradigm of concurrent computation, where tasks are broken into units of work that are distributed to actors in the form of messages \cite{Hewitt73}.
    16 Actors execute asynchronously upon receiving a message and can modify their own state, make decisions, spawn more actors, and send messages to other actors.
    17 The actor model is an implicit model of concurrency.
    18 As such, one strength of the actor model is that it abstracts away many considerations that are needed in other paradigms of concurrent computation.
    19 Mutual exclusion, and locking are rarely relevant concepts to users of an actor model, as actors typically operate on local state.
    20 
    21 \section{Classic Actor System}
    22 An implementation of the actor model with a community of actors is called an actor system.
    23 Actor systems largely follow the actor model, but differ in some ways.
    24 While the definition of the actor model provides no restrictions on message ordering, actor systems tend to guarantee that messages sent from a given actor $i$ to actor $j$ will arrive at actor $j$ in the order they were sent.
    25 Another way an actor system varies from the model is that actors are often allowed to access non-local state.
    26 When this occurs it can complicate the implementation as this will break any mutual exclusion guarantees given by accessing only local state.
     13\section{Actor Model}
     14The actor model is a concurrent paradigm where computation is broken into units of work called actors, and the data for computation is distributed to actors in the form of messages~\cite{Hewitt73}.
     15An actor is composed of a \Newterm{mailbox} (message queue) and a set of \Newterm{behaviours} that receive from the mailbox to perform work.
     16Actors execute asynchronously upon receiving a message and can modify their own state, make decisions, spawn more actors, and send messages to other actors.
     17Because the actor model is implicit concurrency, its strength is that it abstracts away many details and concerns needed in other concurrent paradigms.
     18For example, mutual exclusion and locking are rarely relevant concepts in an actor model, as actors typically only operate on local state.
     19
     20An actor does not have a thread.
     21An actor is executed by an underlying \Newterm{executor} (kernel thread-pool) that fairly invokes each actor, where an actor invocation processes one or more messages from its mailbox.
     22The default number of executor threads is often proportional to the number of computer cores to achieve good performance.
     23An executor is often tunable with respect to the number of kernel threads and its scheduling algorithm, which optimize for specific actor applications and workloads \see{end of Section~\ref{s:CFAActor}}.
     24
     25\subsection{Classic Actor System}
     26An implementation of the actor model with a community of actors is called an actor system.
     27Actor systems largely follow the actor model, but can differ in some ways.
     28While the semantics of message \emph{send} is asynchronous, the implementation may be synchronous or a combination.
     29The default semantics for message \emph{receive} is FIFO, so an actor receives messages from its mailbox in temporal (arrival) order;
     30however, messages sent among actors arrive in any order.
     31Some actor systems provide priority-based mailboxes and/or priority-based message-selection within a mailbox, where custom message dispatchers search among or within a mailbox(es) with a predicate for specific kinds of actors and/or messages.
     32Some actor systems provide a shared mailbox where multiple actors receive from a common mailbox~\cite{Akka}, which is contrary to the no-sharing design of the basic actor-model (and requires additional locking).
     33For non-FIFO service, some notion of fairness (eventual progress) must exist, otherwise messages have a high latency or starve, \ie never received.
     34Finally, some actor systems provide multiple typed-mailboxes, which then lose the actor-\lstinline{become} mechanism (see Section~\ref{s:SafetyProductivity}).
     35%While the definition of the actor model provides no restrictions on message ordering, actor systems tend to guarantee that messages sent from a given actor $i$ to actor $j$ will arrive at actor $j$ in the order they were sent.
     36Another way an actor system varies from the model is allowing access to shared global-state.
     37When this occurs, it complicates the implementation as this breaks any implicit mutual-exclusion guarantees when only accessing local-state.
    2738
    2839\begin{figure}
    2940\begin{tabular}{l|l}
    30 \subfloat[Actor-centric system]{\label{f:standard_actor}\input{diagrams/standard_actor.tikz}} & 
    31 \subfloat[Message-centric system]{\label{f:inverted_actor}\raisebox{.1\height}{\input{diagrams/inverted_actor.tikz}}} 
     41\subfloat[Actor-centric system]{\label{f:standard_actor}\input{diagrams/standard_actor.tikz}} &
     42\subfloat[Message-centric system]{\label{f:inverted_actor}\raisebox{.1\height}{\input{diagrams/inverted_actor.tikz}}}
    3243\end{tabular}
    3344\caption{Classic and inverted actor implementation approaches with sharded queues.}
    3445\end{figure}
    3546
    36 \section{\CFA Actors}
    37 Actor systems \cite{} have often been implemented as an actor-centric system.
    38 As such they are constructed as a set of actors that are scheduled and run on some underlying threads.
    39 Each actor has their own queue for receiving messages, sometimes called a mailbox.
    40 When they receive messages in their mailbox, actors are moved from idle to ready queues and then scheduled on a thread to run their unit of work.
    41 This approach can be implemented with a global queue of actors, but is often implemented as each worker thread owning a queue of actors.
    42 This is known as sharding the actor queue, which is done to decrease contention across worker threads.
    43 A diagram of an actor-centric system with a sharded actor queue is shown in Figure \ref{f:standard_actor}.
     47\subsection{\CFA Actor System}
     48Figure~\ref{f:standard_actor} shows an actor system designed as \Newterm{actor-centric}, where a set of actors are scheduled and run on underlying executor threads~\cite{CAF,Akka,ProtoActor}.
     49The simplest design has a single global queue of actors accessed by the executor threads, but this approach results in high contention as both ends of the queue by the executor threads.
     50The more common design is to \Newterm{shard} the single queue among the executor threads, where actors are permanently assigned or can float among the queues.
     51Sharding significantly decreases contention among executor threads adding and removing actors to/from a queue.
     52Finally, each actor has a receive queue of messages (mailbox), which is a single consumer, multi-producer queue, \ie only the actor removes from the mailbox but multiple actors can attach messages.
     53When an actor receives a message in its mailbox, the actor is marked ready and scheduled by a thread to run the actor's current work unit on the message(s).
    4454
    4555% cite parallel theatre and our paper
    46 The actor system in \CFA is instead message-centric, an uses what is called an inverted actor system \cite{}.
    47 In this inverted actor system instead of each worker thread owning a queue of actors, they each own a queue of messages.
    48 This system is called inverted since in this scheme, actors belong to a message queue, whereas in the classic approach a message queue belongs to each actor.
    49 Since multiple actors belong to each message queue, messages to each actor are interleaved in the queue.
    50 In this scheme work is consumed from their queue and executed by underlying threads.
    51 In High-Performance Extended Actors \cite{} this inverted model is taken a step further and the message queues are sharded, so that each worker now instead owns a set of queues.
    52 A diagram of an inverted actor scheme with a sharded message queue is shown in Figure \ref{f:inverted_actor}.
    53 The arrows from the message queues to the actors in the diagram indicate interleaved messages addressed to each actor.
    54 
    55 The actor system in \CFA builds on top of the architecture laid out in High-Performance Extended Actors \cite{} and adds the following contributions:
    56 
     56Figure \ref{f:inverted_actor} shows an actor system designed as \Newterm{message-centric}, where a set of messages are scheduled and run on underlying executor threads~\cite{uC++,Nigro21}.
     57Again, the simplest design has a single global queue of messages accessed by the executor threads, but this approach has the same contention problem by the executor threads.
     58Therefore, the messages (mailboxes) are sharded and executor threads schedule each message, which points to its corresponding actor.
     59Here, an actor's messages are permanently assigned to one queue to ensure FIFO receiving and/or reduce searching for specific actor/messages.
     60Since multiple actors belong to each message queue, actor messages are interleaved on a queue.
     61This design is \Newterm{inverted} because actors belong to a message queue, whereas in the classic approach a message queue belongs to each actor.
     62% In this inverted actor system instead of each executor threads owning a queue of actors, they each own a queue of messages.
     63% In this scheme work is consumed from their queue and executed by underlying threads.
     64The inverted model can be taken a step further by sharding the message queues for each executor threads, so each executor thread owns a set of queues and cycles through them.
     65Again, this extra level of sharding is to reduce queue contention.
     66% The arrows from the message queues to the actors in the diagram indicate interleaved messages addressed to each actor.
     67
     68The actor system in \CFA uses a message-centric design, adopts several features from my prior actor work in \uC~\cite{}, and adds the following contributions related to \CFA:
    5769\begin{enumerate}[topsep=5pt,itemsep=3pt,parsep=0pt]
    5870\item
    59 Provides insight into the impact of envelope allocation in actor systems.
    60 In all actor systems dynamic allocation is needed to ensure that the lifetime of a unit of work persists from its creation until the unit of work is executed.
    61 This allocation is often called an envelope as it "packages" the information needed to run the unit of work, alongside any other information needed to send the unit of work, such as an actor's address or link fields for a list.
    62 This dynamic allocation occurs once per message sent. 
    63 This is a large source of contention on the memory allocator since all these allocations occur concurrently.
    64 A novel data structure is used to consolidate allocations to improve performance by minimizing contention on the allocator.
    65 
    66 \item
    67 Introduces work stealing in the inverted actor system.
    68 Work stealing in actor-centric systems tends to involve stealing one or more actors.
    69 In the inverted system the notion of stealing queues is introduced.
    70 The queue stealing is implemented such that the act of stealing work does not contend with non-stealing actors that are saturated with work.
    71 
    72 \item
    73 Introduces and evaluates a timestamp based work stealing heuristic with the goal of maintaining non-workstealing performance in work-saturated workloads, and improving performance on unbalanced workloads.
    74 
    75 \item
    76 Improves performance of the inverted actor system using multiple approaches to minimize contention on queues, such as queue gulping and avoiding atomic operations.
    77 
    78 \item
    79 Provides a suite of safety and productivity features including static-typing, detection of erroneous message sends, statistics tracking, and more.
     71Provide insight into the impact of envelope allocation in actor systems.
     72In all actor systems, dynamic allocation is needed to ensure the lifetime of a unit of work persists from its creation until the unit of work is executed.
     73This allocation is often called an \Newterm{envelope} as it ``packages'' the information needed to run the unit of work, alongside any other information needed to send the unit of work, such as an actor's address or link fields.
     74This dynamic allocation occurs once per message sent.
     75Unfortunately, the high rate of message sends in an actor system results in significant contention on the memory allocator.
     76A novel data structure is introduced to consolidate allocations to improve performance by minimizing allocator contention.
     77
     78\item
     79Improve performance of the inverted actor system using multiple approaches to minimize contention on queues, such as queue gulping and avoiding atomic operations.
     80
     81\item
     82Introduce work stealing in the inverted actor system.
     83Work stealing in an actor-centric system involves stealing one or more actors among executor threads.
     84In the inverted system, the notion of stealing message queues is introduced.
     85The queue stealing is implemented such that the act of stealing work does not contend with non-stealing executor threads running actors.
     86
     87\item
     88Introduce and evaluate a timestamp-based work-stealing heuristic with the goal of maintaining non-workstealing performance in work-saturated workloads and improving performance on unbalanced workloads.
     89
     90\item
     91Provide a suite of safety and productivity features including static-typing, detection of erroneous message sends, statistics tracking, and more.
    8092\end{enumerate}
    8193
    82 \section{\CFA Actor Syntax}
    83 \CFA is not an object oriented language and it does not have run-time type information (RTTI).
    84 As such all message sends and receives between actors occur using exact type matching.
    85 To use actors in \CFA you must \code{\#include <actors.hfa>}.
    86 To create an actor type one must define a struct which inherits from the base \code{actor} struct via the \code{inline} keyword.
    87 This is the Plan-9 C-style nominal inheritance discussed in Section \ref{s:poly}.
    88 Similarly to create a message type a user must define a struct which \code{inline}'s the base \code{message} struct.
    89 
    90 \begin{cfa}
    91 struct derived_actor {
    92         inline actor;      // Plan-9 C inheritance
    93 };
    94 void ?{}( derived_actor & this ) { // Default ctor
    95         ((actor &)this){};  // Call to actor ctor
    96 }
    97 
    98 struct derived_msg {
    99         inline message;  // Plan-9 C nominal inheritance
    100         char word[12];
    101 };
    102 void ?{}( derived_msg & this, char * new_word ) { // Overloaded ctor
    103         ((message &) this){ Nodelete }; // Passing allocation to ctor
    104         strcpy(this.word, new_word);
    105 }
    106 
    107 Allocation receive( derived_actor & receiver, derived_msg & msg ) {
    108         printf("The message contained the string: %s\n", msg.word);
    109         return Finished; // Return finished since actor is done
    110 }
    111 
    112 int main() {
    113         start_actor_system(); // Sets up executor
    114         derived_actor my_actor;         
    115         derived_msg my_msg{ "Hello World" }; // Constructor call
    116         my_actor << my_msg;   // Send message via left shift operator
    117         stop_actor_system(); // Waits until actors are finished
    118         return 0;
     94\section{\CFA Actor}\label{s:CFAActor}
     95\CFA is not an object oriented language and it does not have \gls{rtti}.
     96As such, all message sends and receives among actors can only occur using static type-matching, as in Typed-Akka~\cite{AkkaTyped}.
     97Figure~\ref{f:BehaviourStyles} contrasts dynamic and static type-matching.
     98Figure~\ref{l:dynamic_style} shows the dynamic style with a heterogeneous message receive and an indirect dynamic type-discrimination for message processing.
     99Figure~\ref{l:static_style} shows the static style with a homogeneous message receive and a direct static type-discrimination for message processing.
     100The static-typing style is safer because of the static check and faster because there is no dynamic type-discrimination.
     101The dynamic-typing style is more flexible because multiple kinds of messages can be handled in a behaviour condensing the processing code.
     102
     103\begin{figure}
     104\centering
     105
     106\begin{lrbox}{\myboxA}
     107\begin{cfa}[morekeywords=case]
     108allocation receive( message & msg ) {
     109        case( @msg_type1@, msg ) {      // discriminate type
     110                ... msg_d-> ...;        // msg_type1 msg_d
     111        } else case( @msg_type2@, msg ) {
     112                ... msg_d-> ...;        // msg_type2 msg_d
     113        ...
    119114}
    120115\end{cfa}
    121 
    122 The above code is a simple actor program in \CFA.
    123 There is one derived actor type and one derived message type.
    124 A single message containing a string is sent from the program main to an actor.
    125 Key things to highlight include the \code{receive} signature, and calls to \code{start_actor_system}, and \code{stop_actor_system}.
    126 To define a behaviour for some derived actor and derived message type, one must declare a routine with the signature:
     116\end{lrbox}
     117
     118\begin{lrbox}{\myboxB}
    127119\begin{cfa}
    128 Allocation receive( derived_actor & receiver, derived_msg & msg )
     120allocation receive( @msg_type1@ & msg ) {
     121        ... msg ...;
     122}
     123allocation receive( @msg_type2@ & msg ) {
     124        ... msg ...;
     125}
     126...
    129127\end{cfa}
    130 Where \code{derived_actor} and \code{derived_msg} can be any derived actor and derived message types respectively.
    131 The return value of \code{receive} must be a value from the \code{Allocation} enum:
     128\end{lrbox}
     129\subfloat[dynamic typing]{\label{l:dynamic_style}\usebox\myboxA}
     130\hspace*{10pt}
     131\vrule
     132\hspace*{10pt}
     133\subfloat[static typing]{\label{l:static_style}\usebox\myboxB}
     134\caption{Behaviour Styles}
     135\label{f:BehaviourStyles}
     136\end{figure}
     137
     138\begin{figure}
     139\centering
     140
    132141\begin{cfa}
    133 enum Allocation { Nodelete, Delete, Destroy, Finished };
     142// actor
     143struct my_actor {
     144        @inline actor;@                                                 $\C[3.25in]{// Plan-9 C inheritance}$
     145};
     146// messages
     147struct str_msg {
     148        char str[12];
     149        @inline message;@                                               $\C{// Plan-9 C inheritance}$
     150};
     151void ?{}( str_msg & this, char * str ) { strcpy( this.str, str ); }  $\C{// constructor}$
     152struct int_msg {
     153        int i;
     154        @inline message;@                                               $\C{// Plan-9 C inheritance}$
     155};
     156// behaviours
     157allocation receive( my_actor &, @str_msg & msg@ ) with(msg) {
     158        sout | "string message \"" | str | "\"";
     159        return Nodelete;                                                $\C{// actor not finished}$
     160}
     161allocation receive( my_actor &, @int_msg & msg@ ) with(msg) {
     162        sout | "integer message" | i;
     163        return Nodelete;                                                $\C{// actor not finished}$
     164}
     165int main() {
     166        str_msg str_msg{ "Hello World" };               $\C{// constructor call}$
     167        int_msg int_msg{ 42 };                                  $\C{// constructor call}$
     168        start_actor_system();                                   $\C{// sets up executor}$
     169        my_actor actor;                                                 $\C{// default constructor call}$
     170        @actor | str_msg | int_msg;@                    $\C{// cascade sends}$
     171        @actor | int_msg;@                                              $\C{// send}$
     172        @actor | finished_msg;@                                 $\C{// send => terminate actor (deallocation deferred)}$
     173        stop_actor_system();                                    $\C{// waits until actors finish}\CRT$
     174} // deallocate int_msg, str_msg, actor
    134175\end{cfa}
    135 The \code{Allocation} enum is a set of actions that dictate what the executor should do with a message or actor after a given behaviour has been completed.
    136 In the case of an actor, the \code{receive} routine returns the \code{Allocation} status to the executor which sets the status on the actor and takes the appropriate action.
    137 For messages, they either default to \code{Nodelete}, or they can be passed an \code{Allocation} via the \code{message} constructor.
    138 Message state can be updated via a call to:
     176\caption{\CFA Actor Syntax}
     177\label{f:CFAActor}
     178\end{figure}
     179
     180Figure~\ref{f:CFAActor} shows a complete \CFA actor example starting with the actor type @my_actor@ created by defining a @struct@ that inherits from the base @actor@ @struct@ via the @inline@ keyword.
     181This inheritance style is the Plan-9 C-style inheritance discussed in Section~\ref{s:Inheritance}.
     182Similarly, the message types @str_msg@ and @int_msg@ are created by defining a @struct@ that inherits from the base @message@ @struct@ via the @inline@ keyword.
     183Only @str_msg@ needs a constructor to copy the C string;
     184@int_msg@ is initialized using its \CFA auto-generated constructors.
     185There are two matching @receive@ (behaviour) routines that process the corresponding typed messages.
     186Both @receive@ routines use a @with@ clause so message fields are not qualified and return @Nodelete@ indicating the actor is not finished.
     187Also, all messages are marked with @Nodelete@ as their default allocation state.
     188The program main begins by creating two messages on the stack.
     189Then the executor system is started by calling @start_actor_system@.
     190Now an actor is created on the stack and four messages are sent it using operator @?|?@.
     191The last message is the builtin @finish_msg@, which returns @Finished@ to an executor thread, causing it to removes the actor from the actor system \see{Section~\ref{s:ActorBehaviours}}.
     192The call to @stop_actor_system@ blocks the program main until all actors are finished and removed from the actor system.
     193The program main ends by deleting the actor and two messages from the stack.
     194The output for the program is:
    139195\begin{cfa}
    140 void set_allocation( message & this, Allocation state )
     196string message "Hello World"
     197integer message 42
     198integer message 42
    141199\end{cfa}
    142200
    143 The following describes the use of each of the \code{Allocation} values:
    144 
    145 \begin{description}
    146 \item[\LstBasicStyle{\textbf{Nodelete}}]
    147 tells the executor that no action is to be taken with regard to a message or actor with this status.
    148 This indicates that the actor will receive future behaviours, and that a message may be reused.
    149 
    150 \item[\LstBasicStyle{\textbf{Delete}}]
    151 tells the executor to call the appropriate destructor and then deallocate the respective actor or message.
    152 This status is typically used with dynamically allocated actors and messages.
    153 
    154 \item[\LstBasicStyle{\textbf{Destroy}}]
    155 tells the executor to call the object's destructor.
    156 The executor will not deallocate the respective actor or message.
    157 This status is typically used with dynamically allocated actors and messages whose storage will be reused.
    158 
    159 \item[\LstBasicStyle{\textbf{Finished}}]
    160 tells the executor to mark the respective actor as being finished executing.
    161 In this case the executor will not call any destructors or deallocate any objects.
    162 This status is used when the actors are stack allocated or if the user wants to manage deallocation of actors themselves.
    163 In the case of messages, \code{Finished} is no different than \code{Nodelete} since the executor does not need to track if messages are done work.
    164 As such \code{Finished} is not supported for messages and is used internally by the executor to track if messages have been used for debugging purposes.
    165 \end{description}
    166 
    167 For the actor system to gracefully terminate, all actors must have returned a status other than \code{Nodelete}.
    168 Once an actor's allocation status has been set to something other than \code{Nodelete}, it is erroneous for the actor to receive a message.
    169 Similarly messages cannot be safely reused after their related behaviour if their status is not \code{Nodelete}.
    170 Note, it is safe to construct a message with a non-\code{Nodelete} status since the executor will only take the appropriate allocation action after a message has been delivered.
    171 
    172 The calls to \code{start_actor_system}, and \code{stop_actor_system} mark the start and end of a \CFA actor system.
    173 The call to \code{start_actor_system} sets up the executor and worker threads for the actor system.
    174 \code{start_actor_system} has three overloaded signatures which all start the actor system, but vary in executor configuration:
    175 
    176 \noindent\code{void start_actor_system()} configures the executor with one underlying worker thread and processor.
    177 
    178 \noindent\code{void start_actor_system( size_t num_thds )} configures the executor with \code{num_thds} underlying processors and \code{num_thds} worker threads.
    179 It chooses amount of queue sharding as a function of \code{num_thds}.
    180 
    181 \noindent\code{void start_actor_system( executor & this )} allows the user to allocate, configure, and pass an executor so that they have full control of executor parameterization.
    182 Executor configuration options include number of worker threads, number of queues, number of processors, and a few other toggles.
    183 
    184 All actors must be created after calling \code{start_actor_system} so that the executor can keep track of the number of actors that have been allocated but have not yet terminated.
    185 
    186 All message sends are done using the left shift operater, \ie <<, similar to the syntax of \CC's output.
    187 The signature of the left shift operator is:
     201\subsection{Actor Behaviours}\label{s:ActorBehaviours}
     202In general, a behaviour for some derived actor and derived message type is defined with following signature:
    188203\begin{cfa}
    189 Allocation ?<<?( derived_actor & receiver, derived_msg & msg )
     204allocation receive( my_actor & receiver, my_msg & msg )
    190205\end{cfa}
    191 
    192 An astute eye will notice that this is the same signature as the \code{receive} routine which is no coincidence.
    193 The \CFA compiler generates a \code{?<<?} routine definition and forward declaration for each \code{receive} routine that has the appropriate signature.
    194 The generated routine packages the message and actor in an \hyperref[s:envelope]{envelope} and adds it to the executor's queues via an executor routine.
    195 As part of packaging the envelope, the \code{?<<?} routine sets a function pointer in the envelope to point to the appropriate receive routine for given actor and message types.
    196 
     206where @my_actor@ and @my_msg@ inherit from types @actor@ and @message@, respectively.
     207The return value of @receive@ must be a value from enumerated type, @allocation@:
     208\begin{cfa}
     209enum allocation { Nodelete, Delete, Destroy, Finished };
     210\end{cfa}
     211The values represent a set of actions that dictate what the executor does with an actor or message after a given behaviour returns.
     212For actors, the @receive@ routine returns the @allocation@ status to the executor, which takes the appropriate action.
     213For messages, either the default allocation, @Nodelete@, or any changed value in the message is examined by the executor, which takes the appropriate action.
     214Message state is updated via a call to:
     215\begin{cfa}
     216void set_allocation( message & this, allocation state )
     217\end{cfa}
     218
     219In detail, the actions taken by an executor for each of the @allocation@ values are:
     220
     221\noindent@Nodelete@
     222tells the executor that no action is to be taken with regard to an actor or message.
     223This status is used when an actor continues receiving messages or a message may be reused.
     224
     225\noindent@Delete@
     226tells the executor to call the object's destructor and deallocate (delete) the object.
     227This status is used with dynamically allocated actors and messages when they are not reused.
     228
     229\noindent@Destroy@
     230tells the executor to call the object's destructor, but not deallocate the object.
     231This status is used with dynamically allocated actors and messages whose storage is reused.
     232
     233\noindent@Finished@
     234tells the executor to mark the respective actor as finished executing, but not call the object's destructor nor deallocate the object.
     235This status is used when actors or messages are global or stack allocated, or a programmer wants to manage deallocation themselves.
     236
     237For the actor system to terminate, all actors must have returned a status other than @Nodelete@.
     238After an actor is terminated, it is erroneous to send messages to it.
     239Similarly,  after a message is terminated, it cannot be sent to an actor.
     240Note, it is safe to construct an actor or message with a status other than @Nodelete@, since the executor only examines the allocation action after a behaviour returns.
     241
     242\subsection{Actor Envelopes}\label{s:envelope}
     243As stated, each message, regardless of where it is allocated, can be sent to an arbitrary number of actors, and hence, appear on an arbitrary number of message queues.
     244Because a C program manages message lifetime, messages cannot be copied for each send, otherwise who manages the copies.
     245Therefore, it up to the actor program to manage message life-time across receives.
     246However, for a message to appear on multiple message queues, it needs an arbitrary number of associated destination behaviours.
     247Hence, there is the concept of an envelop, which is dynamically allocated on each send, that wraps a message with any extra implementation fields needed to persist between send and receive.
     248Managing the envelop is straightforward because it is created at the send and deleted after the receive, \ie there is 1:1 relationship for an envelop and a many to one relationship for a message.
     249
     250% In actor systems, messages are sent and received by actors.
     251% When a actor receives a message it executes its behaviour that is associated with that message type.
     252% However the unit of work that stores the message, the receiving actor's address, and other pertinent information needs to persist between send and the receive.
     253% Furthermore the unit of work needs to be able to be stored in some fashion, usually in a queue, until it is executed by an actor.
     254% All these requirements are fulfilled by a construct called an envelope.
     255% The envelope wraps up the unit of work and also stores any information needed by data structures such as link fields.
     256
     257% One may ask, "Could the link fields and other information be stored in the message?".
     258% This is a good question to ask since messages also need to have a lifetime that persists beyond the work it delivers.
     259% However, if one were to use messages as envelopes then a message would not be able to be sent to multiple actors at a time.
     260% Therefore this approach would just push the allocation into another location, and require the user to dynamically allocate a message for every send, or require careful ordering to allow for message reuse.
     261
     262\subsection{Actor System}\label{s:ActorSystem}
     263The calls to @start_actor_system@, and @stop_actor_system@ mark the start and end of a \CFA actor system.
     264The call to @start_actor_system@ sets up an executor and executor threads for the actor system.
     265It is possible to have multiple start/stop scenarios in a program.
     266
     267@start_actor_system@ has three overloaded signatures that vary the executor's configuration:
     268
     269\noindent@void start_actor_system()@
     270configures the executor to implicitly use all preallocated kernel-threads (processors), \ie the processors created by the program main prior to starting the actor system.
     271When the number of processors is greater than 1, each executor's message queue is sharded by a factor of 16 to reduce contention, \ie for 4 executor threads (processors), there is a total of 4 $\times$ 16 message queues evenly distributed across the executor threads.
     272
     273\noindent@void start_actor_system( size_t num_thds )@
     274configures the number of executor threads to @num_thds@, with the same message queue sharding.
     275
     276\noindent@void start_actor_system( executor & this )@
     277allows the programmer to explicitly create and configure an executor for use by the actor system.
     278Executor configuration options include are discussed in Section~\ref{s:executor}.
     279
     280\noindent
     281All actors must be created \emph{after} calling @start_actor_system@ so the executor can keep track of the number of actors that have entered the system but not yet terminated.
     282
     283\subsection{Actor Send}\label{s:ActorSend}
     284All message sends are done using the vertical-bar (bit-or) operator, @?|?@, similar to the syntax of the \CFA stream I/O.
     285Hence, programmers must write a matching @?|?@ routine for each @receive@ routine, which is awkward and generates a maintenance problem that must be solved.
     286\CFA's current best approach for creating a generic @?|?@ routine requires users to create routines for their actor and message types that access the base type.
     287Since these routines are not complex, they can be generated using macros that are used to annotate the user-defined actor and message types.
     288This approach is used in \CFA's intrusive list data structure.
     289This is not much better than asking users to write the @?|?@ routine themselves in terms of maintenance, since the user needs to remember the boilerplate macro annotation.
     290
     291As stated, \CFA does not have named inheritance with RTTI.
     292\CFA does have a preliminary form of virtual routines, but it is not mature enough for use in this work.
     293Virtuals would provide a mechanism to write a single generic @?|?@ routine taking a base actor and message type, that would dynamically select the @receive@ routine from the actor argument.
     294Note, virtuals are not needed for the send; Plan-9 inheritance is sufficient because only the inherited fields are needed during the message send (only upcasting is needed).
     295
     296Therefore, a template-like approach was chosen, where the compiler generates a matching @?|?@ routine for each @receive@ routine it finds with the correct actor/message type-signature.
     297This approach requires no annotation or additional code to be written by users, thus it resolves the maintenance problem.
     298(When the \CFA virtual routines mature, it should be possible to seamlessly transition to it from the template approach.)
     299
     300Figure~\ref{f:send_gen} shows the generated send routine for the @int_msg@ receive in Figure~\ref{f:CFAActor}.
     301Operator @?|?@ has the same parameter signature as the corresponding @receive@ routine and returns an @actor@ so the operator can be cascaded.
     302The routine sets @rec_fn@ to the matching @receive@ routine using the left-hand type to perform the selection.
     303Then the routine packages the base and derived actor and message and actor, along with the receive routine into an \hyperref[s:envelope]{envelope}.
     304Finally, the envelop is added to the executor queue designated by the actor using the executor routine @send@.
     305
     306\begin{figure}
     307\begin{cfa}
     308$\LstCommentStyle{// from Figure~\ref{f:CFAActor}}$
     309struct my_actor { inline actor; };                                              $\C[3.75in]{// actor}$
     310struct int_msg { inline message; int i; };                              $\C{// message}$
     311allocation receive( @my_actor &, int_msg & msg@ ) {...} $\C{// receiver}$
     312
     313// compiler generated send operator
     314typedef allocation (*receive_t)( actor &, message & );
     315actor & ?|?( @my_actor & receiver, int_msg & msg@ ) {
     316        allocation (*rec_fn)( my_actor &, int_msg & ) = @receive@; // deduce receive routine
     317        request req{ &receiver, (actor *)&receiver, &msg, (message *)&msg, (receive_t)rec_fn };
     318        send( receiver, req );                                                          $\C{// queue message for execution}\CRT$
     319        return receiver;
     320}
     321\end{cfa}
     322\caption{Generated Send Operator}
     323\label{f:send_gen}
     324\end{figure}
     325
     326\subsection{Actor Termination}\label{s:ActorTerm}
     327During a message send, the receiving actor and message being sent are stored via pointers in the envelope.
     328These pointers have the base actor and message types, so type information of the actor and message is lost and then recovered later when the typed receive routine is called.
     329After the receive routine is done, the executor must clean up the actor and message according to their allocation status.
     330If the allocation status is @Delete@ or @Destroy@, the appropriate destructor must be called by the executor.
     331This poses a problem; the correct type of the actor or message is not available to the executor, but it needs to call the right destructor!
     332This requires downcasting from the base type to derived type, which requires a virtual system.
     333Thus, a rudimentary destructor-only virtual system was added to \CFA as part of this work.
     334This virtual system is used via Plan-9 inheritance of the @virtual_dtor@ type, shown in Figure~\ref{f:VirtDtor}.
     335The @virtual_dtor@ type maintains a pointer to the start of the object, and a pointer to the correct destructor.
     336When a type inherits the @virtual_dtor@ type, the compiler adds code to its destructor to make sure that any destructor calls along this segment of the inheritance tree is called are intercepted, and restart at the appropriate destructor for that object.
     337
     338\begin{figure}
     339\begin{cfa}
     340struct base_type { inline virtual_dtor; };
     341struct intermediate_type { inline base_type; };
     342struct derived_type { inline intermediate_type; };
     343
     344int main() {
     345    derived_type d1, d2, d3;
     346    intermediate_type & i = d2;
     347    base_type & b = d3;
     348
     349    // these will call the destructors in the correct order
     350    ^d1{}; ^i{}; ^b{};
     351}
     352
     353\end{cfa}
     354\caption{\CFA Virtual Destructor}
     355\label{f:VirtDtor}
     356\end{figure}
     357
     358This virtual destructor system was built for this work, but is general and can be used in any type in \CFA.
     359Actors and messages opt into this system by inheriting the @virtual_dtor@ type, which allows the executor to call the right destructor without knowing the derived actor or message type.
     360
     361Figure~\ref{f:ConvenienceMessages} shows three builtin convenience messages and receive routines used to terminate actors, depending on how an actor is allocated: @Delete@, @Destroy@ or @Finished@.
     362For example, in Figure~\ref{f:CFAActor}, the builtin @finished_msg@ message and receive are used to terminate the actor because the actor is allocated on the stack, so no deallocation actions are performed by the executor.
     363
     364\begin{figure}
     365\begin{cfa}
     366message __base_msg_finished $@$= { .allocation_ : Finished }; // no auto-gen constructors
     367struct __delete_msg_t { inline message; } delete_msg = __base_msg_finished;
     368struct __destroy_msg_t { inline message; } destroy_msg = __base_msg_finished;
     369struct __finished_msg_t { inline message; } finished_msg = __base_msg_finished;
     370
     371allocation receive( actor & this, __delete_msg_t & msg ) { return Delete; }
     372allocation receive( actor & this, __destroy_msg_t & msg ) { return Destroy; }
     373allocation receive( actor & this, __finished_msg_t & msg ) { return Finished; }
     374\end{cfa}
     375\caption{Builtin Convenience Messages}
     376\label{f:ConvenienceMessages}
     377\end{figure}
    197378
    198379\section{\CFA Executor}\label{s:executor}
    199 This section will describe the basic architecture of the \CFA executor.
    200 Any discussion of work stealing is omitted until Section \ref{s:steal}.
    201 The executor of an actor system is the scheduler that organizes where actors behaviours are run and how messages are sent and delivered.
    202 In \CFA the executor lays out actors across the sharded message queues in round robin order as they are created.
    203 The message queues are split across worker threads in equal chunks, or as equal as possible if the number of message queues is not divisible by the number of workers threads.
     380This section describes the basic architecture of the \CFA executor.
     381An executor of an actor system is the scheduler that organizes where actor behaviours are run and how messages are sent and delivered.
     382In \CFA, the executor is message-centric \see{Figure~\ref{f:inverted_actor}}, but extended by over sharding of a message queue \see{left side of Figure~\ref{f:gulp}}, \ie there are $M$ message queues where $M$ is greater than the number of executor threads $N$ (usually a multiple of $N$).
     383This approach reduces contention by spreading message delivery among the $M$ queues rather than $N$, while still maintaining actor FIFO message-delivery semantics.
     384The only extra overhead is each executor cycling (usually round-robin) through its $M$/$N$ queues.
     385The goal is to achieve better performance and scalability for certain kinds of actor applications by reducing executor locking.
     386Note, lock-free queues do not help because busy waiting on any atomic instruction is the source of the slowdown whether it is a lock or lock-free.
    204387
    205388\begin{figure}
     
    207390\input{diagrams/gulp.tikz}
    208391\end{center}
    209 \caption{Diagram of the queue gulping mechanism.}
     392\caption{Queue Gulping Mechanism}
    210393\label{f:gulp}
    211394\end{figure}
    212395
    213 Each worker thread iterates over its own message queues until it finds one that contains messages.
    214 At this point the worker thread \textbf{gulps} the queue.
    215 A \textbf{gulp} is a term for consuming the contents of message queue and transferring them to the local queue of worker thread.
    216 After the gulp is done atomically, this allows the worker thread to process the queue locally without any need for atomicity until the next gulp.
    217 Messages can be added to the queue that was gulped in parallel with the processing of the local queue.
    218 Additionally, prior to each gulp, the worker non-atomically checks if a queue is empty before attempting to gulp it.
    219 Between this and the gulp, the worker avoids many potentially costly lock acquisitions.
    220 An example of the queue gulping operation is shown in Figure \ref{f:gulp} where a worker thread gulps queue 0 and begins to process it locally.
    221 
    222 To process its local queue, a worker thread takes each unit of work off the queue and executes it.
    223 Since all messages to a given actor will be in the same queue, this guarantees atomicity across behaviours of that actor since it can only execute on one thread at a time.
    224 After running behaviour, the worker thread looks at the returned allocation status and takes the corresponding action.
    225 Once all actors have marked themselves as being finished the executor initiates shutdown by inserting a sentinel value into the message queues.
    226 Once a worker thread sees a sentinel it stops running.
    227 After all workers stop running the actor system shutdown is complete.
    228 
    229 \section{Envelopes}\label{s:envelope}
    230 In actor systems messages are sent and received by actors.
    231 When a actor receives a message it executes its behaviour that is associated with that message type.
    232 However the unit of work that stores the message, the receiving actor's address, and other pertinent information needs to persist between send and the receive.
    233 Furthermore the unit of work needs to be able to be stored in some fashion, usually in a queue, until it is executed by an actor.
    234 All these requirements are fulfilled by a construct called an envelope.
    235 The envelope wraps up the unit of work and also stores any information needed by data structures such as link fields.
    236 To meet the persistence requirement the envelope is dynamically allocated and cleaned up after it has been delivered and its payload has run.
    237 
    238 One may ask, "Could the link fields and other information be stored in the message?".
    239 This is a good question to ask since messages also need to have a lifetime that persists beyond the work it delivers.
    240 However, if one were to use messages as envelopes then a message would not be able to be sent to multiple actors at a time.
    241 Therefore this approach would just push the allocation into another location, and require the user to dynamically allocate a message for every send, or require careful ordering to allow for message reuse.
    242 
    243 This frequent allocation of envelopes with each message send between actors results in heavy contention on the memory allocator.
    244 As such, a way to alleviate contention on the memory allocator could result in performance improvement.
    245 Contention was reduced using a novel data structure that is called a copy queue.
    246 
    247 \subsection{The Copy Queue}\label{s:copyQueue}
    248 The copy queue is a thin layer over a dynamically sized array that is designed with the envelope use case in mind.
    249 A copy queue supports the typical queue operations of push/pop but in a different way than a typical array based queue.
    250 The copy queue is designed to take advantage of the \hyperref[s:executor]{gulping} pattern.
    251 As such the amortized rutime cost of each push/pop operation for the copy queue is $O(1)$.
    252 In contrast, a naive array based queue often has either push or pop cost $O(n)$ and the other cost $O(1)$ since for at least one of the operations all the elements of the queue have to be shifted over.
    253 Since the worker threads gulp each queue to operate on locally, this creates a usage pattern of the queue where all elements are popped from the copy queue without any interleaved pushes.
    254 As such, during pop operations there is no need to shift array elements.
    255 An index is stored in the copy queue data structure which keeps track of which element to pop next allowing pop to be $O(1)$.
    256 Push operations are amortized $O(1)$ since pushes may cause doubling reallocations of the underlying dynamic sized array.
     396Each executor thread iterates over its own message queues until it finds one with messages.
     397At this point, the executor thread atomically \gls{gulp}s the queue, meaning it moves the contents of message queue to a local queue of the executor thread using a single atomic instruction.
     398An example of the queue gulping operation is shown in the right side of Figure \ref{f:gulp}, where a executor threads gulps queue 0 and begins to process it locally.
     399This step allows an executor thread to process the local queue without any atomics until the next gulp.
     400Other executor threads can continue adding to the ends of executor thread's message queues.
     401In detail, an executor thread performs a test-and-gulp, non-atomically checking if a queue is non-empty, before attempting to gulp it.
     402If an executor misses an non-empty queue due to a race, it eventually finds the queue after cycling through its message queues.
     403This approach minimizes costly lock acquisitions.
     404
     405Processing a local queue involves: removing a unit of work from the queue, dereferencing the actor pointed-to by the work-unit, running the actor's behaviour on the work-unit message, examining the returned allocation status from the @receive@ routine for the actor and internal status in the delivered message, and taking the appropriate actions.
     406Since all messages to a given actor are in the same queue, this guarantees atomicity across behaviours of that actor since it can only execute on one thread at a time.
     407As each actor is created or terminated by an executor thread, it increments/decrements a global counter.
     408When an executor decrements the counter to zero, it sets a global boolean variable that is checked by each executor thread when it has no work.
     409Once a executor threads sees the flag is set it stops running.
     410After all executors stop, the actor system shutdown is complete.
     411
     412\subsection{Copy Queue}\label{s:copyQueue}
     413Unfortunately, the frequent allocation of envelopes for each send results in heavy contention on the memory allocator.
     414This contention is reduced using a novel data structure, called a \Newterm{copy queue}.
     415The copy queue is a thin layer over a dynamically sized array that is designed with the envelope use case in mind.
     416A copy queue supports the typical queue operations of push/pop but in a different way from a typical array-based queue.
     417
     418The copy queue is designed to take advantage of the \gls{gulp}ing pattern, giving an amortized runtime cost for each push/pop operation of $O(1)$.
     419In contrast, a na\"ive array-based queue often has either push or pop cost $O(n)$ and the other cost $O(1)$ since one of the operations requires shifting the elements of the queue.
     420Since the executor threads gulp a queue to operate on it locally, this creates a usage pattern where all elements are popped from the copy queue without any interleaved pushes.
     421As such, during pop operations there is no need to shift array elements.
     422Instead, an index is stored in the copy-queue data-structure that keeps track of which element to pop next allowing pop to be $O(1)$.
     423Push operations are amortized $O(1)$ since pushes may cause doubling reallocations of the underlying dynamic-sized array (like \CC @vector@).
    257424
    258425% C_TODO: maybe make copy_queue diagram
    259426
    260 Since the copy queue is an array, envelopes are allocated first on the stack and then copied into the copy queue to persist until they are no longer needed.
    261 For a fixed message throughput workload, once the copy queues grow in size to facilitate the number of messages in flight, there are no longer any dynamic allocations occuring in the actor system.
    262 One problem that arises with this approach is that this array based approach will often allocate more storage than what is needed.
    263 Comparitively the individual envelope allocations of a list based queue mean that the actor system will always use the minimum amount of heap space needed and will clean up eagerly.
    264 Additionally, a workload with variable message throughput could cause copy queues to allocate large amounts of space to accomodate the peaks of the throughput, even if most of that storage is not needed for the rest of the workload's execution.
    265 
    266 
    267 To mitigate this a memory reclamation scheme was introduced.
    268 Initially the memory reclamation naively reclaimed one index of the array per gulp if the array size was above a low fixed threshold.
    269 This approach had a problem.
    270 The high memory usage watermark nearly doubled with this change! The issue with this approach can easily be highlighted with an example.
    271 Say that there is a fixed throughput workload where a queue never has more than 19 messages at a time.
    272 If the copy queue starts with a size of 10, it will end up doubling at some point to size 20 to accomodate 19 messages.
    273 However, after 2 gulps and subsequent reclamations the array would be size 18.
    274 The next time 19 messages are enqueued, the array size is doubled to 36! To avoid this issue a second check was added to reclamation.
    275 Each copy queue started tracking the utilization of their array size.
    276 Reclamation would only occur if less than half of the array was being utilized.
    277 In doing this the reclamation scheme was able to achieve a lower high watermark and a lower overall memory utilization when compared to the non-reclamation copy queues.
    278 However, the use of copy queues still incurs a higher memory cost than the list based queueing.
    279 With the inclusion of a memory reclamation scheme the increase in memory usage is reasonable considering the performance gains and will be discussed further in Section \ref{s:actor_perf}.
     427Since the copy queue is an array, envelopes are allocated first on the stack and then copied into the copy queue to persist until they are no longer needed.
     428For many workload, the copy queues grow in size to facilitate the average number of messages in flight and there is no further dynamic allocations.
     429One downside of this approach that more storage is allocated than needed, \ie each copy queue is only partially full.
     430Comparatively, the individual envelope allocations of a list-based queue mean that the actor system always uses the minimum amount of heap space and cleans up eagerly.
     431Additionally, bursty workloads can cause the copy queues to allocate a large amounts of space to accommodate the peaks of the throughput, even if most of that storage is not needed for the rest of the workload's execution.
     432
     433To mitigate memory wastage, a reclamation scheme is introduced.
     434Initially, the memory reclamation na\"ively reclaims one index of the array per \gls{gulp}, if the array size is above a low fixed threshold.
     435However, this approach has a problem.
     436The high memory watermark nearly doubled!
     437The issue is highlighted with an example.
     438Assume a fixed throughput workload, where a queue never has more than 19 messages at a time.
     439If the copy queue starts with a size of 10, it ends up doubling at some point to size 20 to accommodate 19 messages.
     440However, after 2 gulps and subsequent reclamations the array size is 18.
     441The next time 19 messages are enqueued, the array size is doubled to 36!
     442To avoid this issue, a second check is added.
     443Reclamation only occurs if less than half of the array is utilized.
     444This check achieves a lower total storage and overall memory utilization compared to the non-reclamation copy queues.
     445However, the use of copy queues still incurs a higher memory cost than list-based queueing, but the increase in memory usage is reasonable considering the performance gains \see{Section~\ref{s:actor_perf}}.
    280446
    281447\section{Work Stealing}\label{s:steal}
    282 Work stealing is a scheduling strategy that attempts to load balance, and increase resource untilization by having idle threads steal work.
    283 There are many parts that make up a work stealing actor scheduler, but the two that will be highlighted in this work are the stealing mechanism and victim selection.
    284 
    285 % C_TODO enter citation for langs
     448Work stealing is a scheduling strategy to provide \Newterm{load balance}.
     449The goal is to increase resource utilization by having idle threads steal work from working threads.
     450While there are multiple parts in work-stealing scheduler, the two important components are victim selection and the stealing mechanism.
     451
    286452\subsection{Stealing Mechanism}
    287 In this discussion of work stealing the worker being stolen from will be referred to as the \textbf{victim} and the worker stealing work will be called the \textbf{thief}.
    288 The stealing mechanism presented here differs from existing work stealing actor systems due the inverted actor system.
    289 Other actor systems such as Akka \cite{} and CAF \cite{} have work stealing, but since they use an classic actor system that is actor-centric, stealing work is the act of stealing an actor from a dequeue.
    290 As an example, in CAF, the sharded actor queue is a set of double ended queues (dequeues).
    291 Whenever an actor is moved to a ready queue, it is inserted into a worker's dequeue.
    292 Workers then consume actors from the dequeue and execute their behaviours.
    293 To steal work, thieves take one or more actors from a victim's dequeue.
    294 This action creates contention on the dequeue, which can slow down the throughput of the victim.
    295 The notion of which end of the dequeue is used for stealing, consuming, and inserting is not discussed since it isn't relevant.
    296 By the pigeon hole principle there are three dequeue operations (push/victim pop/thief pop) that can occur concurrently and only two ends to a dequeue, so work stealing being present in a dequeue based system will always result in a potential increase in contention on the dequeues.
     453In work stealing, the stealing worker is called the \Newterm{thief} and the stolen-from worker is called the \Newterm{victim}.
     454The stealing mechanism presented here differs from existing work-stealing actor-systems because of the message-centric (inverted) actor-system.
     455Other actor systems, such as Akka~\cite{Akka} and CAF~\cite{CAF}, have work stealing, but use an actor-centric system where stealing is dequeuing from a non-empty ready-queue to an empty ready-queue.
     456As an example, in CAF, the sharded actor queue is a set of double-ended queues (dequeues).
     457When an actor has messages, it is inserted into a worker's dequeue (ready queue).
     458Workers then consume actors from the dequeue and execute their behaviours.
     459To steal work, thieves take one or more actors from a victim's dequeue.
     460By the pigeon hole principle, there are three dequeue operations (push/victim pop/thief pop) that can occur concurrently and only two ends to a dequeue, so work stealing in a dequeue-based system always results in a potential increase in contention on the dequeues.
     461This contention can slows down the victim's throughput.
     462Note, which end of the dequeue is used for stealing, consuming, and inserting is not discussed since the largest cost is the mutual exclusion and its duration for safely performing the queue operations.
     463
     464Work steal now becomes queue stealing, where an entire actor/message queue is stolen, which trivially preserves message ordering in a queue \see{Section~\ref{s:steal}}.
    297465
    298466% C_TODO: maybe insert stealing diagram
    299467
    300 In \CFA, the actor work stealing implementation is unique.
    301 While other systems are concerned with stealing actors, the \CFA actor system steals queues.
    302 This is a result of \CFA's use of the inverted actor system.
    303 The goal of the \CFA actor work stealing mechanism is to have a zero-victim-cost stealing mechanism.
    304 This does not means that stealing has no cost.
    305 This goal is to ensure that stealing work does not impact the performance of victim workers.
    306 This means that thieves can not contend with victims, and that victims should perform no stealing related work unless they become a thief.
    307 In theory this goal is not achieved, but results will be presented that show the goal is achieved in practice.
    308 In \CFA's actor system workers own a set of sharded queues which they iterate over and gulp.
    309 If a worker has iterated over the queues they own twice without finding any work, they try to steal a queue from another worker.
    310 Stealing a queue is done wait-free with a few atomic instructions that can only create contention with other stealing workers.
    311 To steal a queue a worker does the following:
     468In \CFA, the actor work-stealing implementation is unique because of the message-centric system.
     469In this system, it is impractical to steal actors because an actor's messages are distributed in temporal order along the message queue.
     470To ensure sequential actor execution and FIFO message delivery, actor stealing requires finding and removing all of an actor's messages, and inserting them consecutively in another message queue.
     471This operation is $O(N)$ with a non-trivial constant.
     472The only way for work stealing to become practical is to shard the message queue, which also reduces contention, and steal queues to eliminate queue searching.
     473
     474Given queue stealing, the goal is to have a zero-victim-cost stealing mechanism, which does not mean stealing has no cost.
     475It means work stealing does not affect the performance of the victim worker.
     476The implication is that thieves cannot contend with a victim, and that a victim should perform no stealing related work unless it becomes a thief.
     477In theory, this goal is not achievable, but results show the goal is achieved in practice.
     478
     479In \CFA's actor system, workers own a set of sharded queues, which they iterate over and gulp.
     480If a worker has iterated over its message queues twice without finding any work, it tries to steal a queue from another worker.
     481Stealing a queue is done wait-free with a few atomic instructions that can only create contention with other stealing workers, not the victim.
     482To steal a queue, a worker does the following:
    312483\begin{enumerate}[topsep=5pt,itemsep=3pt,parsep=0pt]
    313484\item
    314 The thief chooses a victim.
    315 
    316 \item
    317 The thief starts at a random index in the array of the victim's queues and searches for a candidate queue.
    318 A candidate queue is any queue that is not empty, is not being stolen by another thief, and is not being processed by the victim.
    319 These are not strictly enforced rules.
    320 The candidate is identified non-atomically and as such queues that do not satisfy these rules may be stolen.
    321 However, steals that do not meet these requirements do not affect correctness so they are allowed and do not constitute failed steals as the queues will still be swapped.
    322 
    323 
    324 \item
    325 Once a candidate queue is chosen, the thief attempts a wait-free swap of the victim's queue and a random on of the thief's queues.
    326 This swap can fail.
    327 If the swap is successful the thief swaps the two queues.
    328 If the swap fails, another thief must have attempted to steal one of the two queues being swapped.
    329 Failing to steal is good in this case since stealing a queue that was just swapped would likely result in stealing an empty queue.
     485The thief chooses a victim, which is trivial because all workers are stored in a shared array.
     486
     487\item
     488The thief starts at a random index in the array of the victim's queues and searches for a candidate queue.
     489A candidate queue is any non-empty queue not being processed by the victim and not being stolen by another thief.
     490These rules are not strictly enforced.
     491A candidate is identified non-atomically, and as such, queues that do not satisfy these rules may be stolen.
     492However, steals not meeting the rules do not affect correctness and do not constitute failed steals as the queue is always swapped.
     493
     494\item
     495Once a candidate queue is chosen, the thief attempts a wait-free swap of a victim's queue to a random empty thief queue.
     496If the swap successes, the steal is completed.
     497If the swap fails, the victim may have been gulping that message queue or another thief must have attempted to steal the victim's queue.
     498In either case, that message queue is highly likely to be empty.
     499
     500\item
     501Once a thief fails or succeeds in stealing a queue, it iterates over its messages queues again because new messages may have arrived during stealing.
     502Stealing is only repeated after two consecutive iterations over its owned queues without finding work.
    330503\end{enumerate}
    331504
    332 Once a thief fails or succeeds in stealing a queue, it goes back to its own set of queues and iterates over them again.
    333 It will only try to steal again once it has completed two consecutive iterations over its owned queues without finding any work.
    334 The key to the stealing mechnism is that the queues can still be operated on while they are being swapped.
    335 This elimates any contention between thieves and victims.
    336 The first key to this is that actors and workers maintain two distinct arrays of references to queues.
    337 Actors will always receive messages via the same queues.
    338 Workers, on the other hand will swap the pointers to queues in their shared array and operate on queues in the range of that array that they own.
    339 Swapping queues is a matter of atomically swapping two pointers in the worker array.
     505The key to the stealing mechanism is that the queues can still be operated on while they are being swapped.
     506This functionality eliminates any contention among thieves and victims.
     507
     508The first key to this is that actors and workers maintain two distinct arrays of references to queues.
     509Actors will always receive messages via the same queues.
     510Workers, on the other hand will swap the pointers to queues in their shared array and operate on queues in the range of that array that they own.
     511Swapping queues is a matter of atomically swapping two pointers in the worker array.
    340512As such pushes to the queues can happen concurrently during the swap since pushes happen via the actor queue references.
    341513
    342 Gulping can also occur during queue swapping, but the implementation requires more nuance than the pushes. 
    343 When a worker is not stealing it iterates across its own range of queues and gulps them one by one. 
    344 When a worker operates on a queue it first copies the current pointer from the worker array of references to a local variable. 
    345 It then uses that local variable for all queue operations until it moves to the next index of its range of the queue array. 
    346 This ensures that any swaps do not interrupt gulping operations, however this introduces a correctness issue. 
    347 If any behaviours from a queue are run by two workers at a time it violates both mutual exclusion and the actor ordering guarantees. 
    348 As such this must be avoided. 
    349 To avoid this each queue has a \code{being_processed} flag that is atomically set to \code{true} when a queue is gulped.
    350 The flag indicates that a queue is being processed locally and is set back to \code{false} once the local processing is finished.
    351 If a worker attempts to gulp a queue and finds that the \code{being_processed} flag is \code{true}, it does not gulp the queue and moves on to the next queue in its range.
    352 This is a source of contention between victims and thieves since a thief may steal a queue and set \code{being_processed} to \code{true} between a victim saving a pointer to a queue and gulping it.
    353 However, the window for this race is very small, making this contention rare. 
    354 This is why the claim is made that this mechanism is zero-victim-cost in practice but not in theory. 
    355 By collecting statistics on failed gulps due to the \code{being_processed} flag, it is found that this contention occurs ~0.05\% of the time when a gulp occurs.
     514Gulping can also occur during queue swapping, but the implementation requires more nuance than the pushes.
     515When a worker is not stealing it iterates across its own range of queues and gulps them one by one.
     516When a worker operates on a queue it first copies the current pointer from the worker array of references to a local variable.
     517It then uses that local variable for all queue operations until it moves to the next index of its range of the queue array.
     518This ensures that any swaps do not interrupt gulping operations, however this introduces a correctness issue.
     519If any behaviours from a queue are run by two workers at a time it violates both mutual exclusion and the actor ordering guarantees.
     520As such this must be avoided.
     521To avoid this each queue has a @being_processed@ flag that is atomically set to @true@ when a queue is gulped.
     522The flag indicates that a queue is being processed locally and is set back to @false@ once the local processing is finished.
     523If a worker attempts to gulp a queue and finds that the @being_processed@ flag is @true@, it does not gulp the queue and moves on to the next queue in its range.
     524This is a source of contention between victims and thieves since a thief may steal a queue and set @being_processed@ to @true@ between a victim saving a pointer to a queue and gulping it.
     525However, the window for this race is very small, making this contention rare.
     526This is why the claim is made that this mechanism is zero-victim-cost in practice but not in theory.
     527By collecting statistics on failed gulps due to the @being_processed@ flag, it is found that this contention occurs ~0.05\% of the time when a gulp occurs.
    356528Hence, the claim is made that this stealing mechanism has zero-victim-cost in practice.
    357529
    358530
    359531\subsection{Queue Swap Correctness}
    360 Given the wait-free swap used is novel, it is important to show that it is correct. 
    361 Firstly, it is clear to show that the swap is wait-free since all workers will fail or succeed in swapping the queues in a finite number of steps since there are no locks or looping. 
    362 There is no retry mechanism in the case of a failed swap, since a failed swap either means the work was already stolen, or that work was stolen from the thief. 
    363 In both cases it is apropos for a thief to given up on stealing. 
    364 \CFA-style pseudocode for the queue swap is presented below. 
    365 The swap uses compare-and-swap (\code{CAS}) which is just pseudocode for C's \code{__atomic_compare_exchange_n}.
    366 A pseudocode implementation of \code{CAS} is also shown below.
    367 The correctness of the wait-free swap will now be discussed in detail. 
     532Given the wait-free swap used is novel, it is important to show that it is correct.
     533Firstly, it is clear to show that the swap is wait-free since all workers will fail or succeed in swapping the queues in a finite number of steps since there are no locks or looping.
     534There is no retry mechanism in the case of a failed swap, since a failed swap either means the work was already stolen, or that work was stolen from the thief.
     535In both cases it is apropos for a thief to given up on stealing.
     536\CFA-style pseudocode for the queue swap is presented below.
     537The swap uses compare-and-swap (@CAS@) which is just pseudocode for C's @__atomic_compare_exchange_n@.
     538A pseudocode implementation of @CAS@ is also shown below.
     539The correctness of the wait-free swap will now be discussed in detail.
    368540To first verify sequential correctness, consider the equivalent sequential swap below:
    369541
     
    382554\end{cfa}
    383555
    384 Step 1 is missing in the sequential example since in only matter in the concurrent context presented later. 
    385 By looking at the sequential swap it is easy to see that it is correct. 
     556Step 1 is missing in the sequential example since in only matter in the concurrent context presented later.
     557By looking at the sequential swap it is easy to see that it is correct.
    386558Temporary copies of each pointer being swapped are stored, and then the original values of each pointer are set using the copy of the other pointer.
    387559
     
    403575        // Step 1:
    404576        // If either queue is 0p then they are in the process of being stolen
    405         // 0p is CForAll's equivalent of C++'s nullptr
     577        // 0p is Cforall's equivalent of C++'s nullptr
    406578        if ( vic_queue == 0p ) return false;
    407579
     
    411583        if ( !CAS( &request_queues[my_idx], &my_queue, 0p ) )
    412584                return false;
    413        
     585
    414586        // Step 3:
    415587        // Try to set victim queue ptr to be thief's queue ptr.
     
    434606Step 0 is the same as the sequential example, and the thief stores local copies of the two pointers to be swapped.
    435607\item
    436 Step 1 verifies that the stored copy of the victim queue pointer, \code{vic_queue}, is valid.
    437 If \code{vic_queue} is equal to \code{0p}, then the victim queue is part of another swap so the operation fails.
    438 No state has changed at this point so no fixups are needed. 
    439 Note, \code{my_queue} can never be equal to \code{0p} at this point since thieves only set their own queues pointers to \code{0p} when stealing.
    440 At no other point will a queue pointer be set to \code{0p}.
    441 Since each worker owns a disjoint range of the queue array, it is impossible for \code{my_queue} to be \code{0p}.
    442 \item
    443 Step 2 attempts to set the thief's queue pointer to \code{0p} via \code{CAS}.
    444 The \code{CAS} will only fail if the thief's queue pointer is no longer equal to \code{my_queue}, which implies that this thief has become a victim and its queue has been stolen.
    445 At this point the thief-turned-victim will fail and since it has not changed any state it just fails and returns false. 
    446 If the \code{CAS} succeeds then the thief's queue pointer will now be \code{0p}.
    447 Nulling the pointer is safe since only thieves look at other worker's queue ranges, and whenever thieves need to dereference a queue pointer they check for \code{0p}.
    448 \item
    449 Step 3 attempts to set the victim's queue pointer to be \code{my_queue} via \code{CAS}.
    450 If the \code{CAS} succeeds then the victim's queue pointer has been set and swap can no longer fail.
    451 If the \code{CAS} fails then the thief's queue pointer must be restored to its previous value before returning.
    452 \item 
    453 Step 4 sets the thief's queue pointer to be \code{vic_queue} completing the swap.
     608Step 1 verifies that the stored copy of the victim queue pointer, @vic_queue@, is valid.
     609If @vic_queue@ is equal to @0p@, then the victim queue is part of another swap so the operation fails.
     610No state has changed at this point so no fixups are needed.
     611Note, @my_queue@ can never be equal to @0p@ at this point since thieves only set their own queues pointers to @0p@ when stealing.
     612At no other point will a queue pointer be set to @0p@.
     613Since each worker owns a disjoint range of the queue array, it is impossible for @my_queue@ to be @0p@.
     614\item
     615Step 2 attempts to set the thief's queue pointer to @0p@ via @CAS@.
     616The @CAS@ will only fail if the thief's queue pointer is no longer equal to @my_queue@, which implies that this thief has become a victim and its queue has been stolen.
     617At this point the thief-turned-victim will fail and since it has not changed any state it just fails and returns false.
     618If the @CAS@ succeeds then the thief's queue pointer will now be @0p@.
     619Nulling the pointer is safe since only thieves look at other worker's queue ranges, and whenever thieves need to dereference a queue pointer they check for @0p@.
     620\item
     621Step 3 attempts to set the victim's queue pointer to be @my_queue@ via @CAS@.
     622If the @CAS@ succeeds then the victim's queue pointer has been set and swap can no longer fail.
     623If the @CAS@ fails then the thief's queue pointer must be restored to its previous value before returning.
     624\item
     625Step 4 sets the thief's queue pointer to be @vic_queue@ completing the swap.
    454626\end{enumerate}
    455627
     
    458630\end{theorem}
    459631
    460 Correctness of the swap is shown through the existence of an invariant. 
    461 The invariant is that when a queue pointer is set to \code{0p} by a thief, then the next write to the pointer can only be performed by the same thief.
    462 To show that this invariant holds, it is shown that it is true at each step of the swap. 
    463 Step 0 and 1 do not write and as such they cannot invalidate the invariant of any other thieves. 
    464 In step 2 a thief attempts to write \code{0p} to one of their queue pointers.
    465 This queue pointer cannot be \code{0p}.
    466 As stated above, \code{my_queue} is never equal to \code{0p} since thieves will only write \code{0p} to queue pointers from their own queue range and all worker's queue ranges are disjoint.
    467 As such step 2 upholds the invariant since in a failure case no write occurs, and in the success case, the value of the queue pointer is guaranteed to not be 0p. 
    468 In step 3 the thief attempts to write \code{my_queue} to the victim's queue pointer.
    469 If the current value of the victim's queue pointer is \code{0p}, then the CAS will fail since \code{vic_queue} cannot be equal to \code{0p} because of the check in step 1.
    470 Therefore in the success case where the \code{CAS} succeeds, the value of the victim's queue pointer must not be \code{0p}.
    471 As such, the write will never overwrite a value of \code{0p}, hence the invariant is held in the \code{CAS} of step 3.
    472 The write back to the thief's queue pointer that happens in the failure case of step three and in step 4 hold the invariant since they are the subsequent write to a \code{0p} queue pointer and they are being set by the same thief that set the pointer to \code{0p}.
    473 
    474 Given this informal proof of invariance it can be shown that the successful swap is correct. 
    475 Once a thief atomically sets their queue pointer to be \code{0p} in step 2, the invariant guarantees that pointer will not change.
    476 As such, in the success case step 3 it is known that the value of the victim's queue pointer that was overwritten must be \code{vic_queue} due to the use of \code{CAS}.
    477 Given that pointers all have unique memory locations, this first write of the successful swap is correct since it can only occur when the pointer has not changed. 
    478 By the invariant the write back in the successful case is correct since no other worker can write to the \code{0p} pointer.
    479 
    480 In the failed case the outcome is correct in steps 1 and 2 since no writes have occured so the program state is unchanged.
    481 In the failed case of step 3 the program state is safely restored to its state it had prior to the \code{0p} write in step 2, thanks to the invariant that makes the write back to the \code{0p} pointer safe.
     632Correctness of the swap is shown through the existence of an invariant.
     633The invariant is that when a queue pointer is set to @0p@ by a thief, then the next write to the pointer can only be performed by the same thief.
     634To show that this invariant holds, it is shown that it is true at each step of the swap.
     635Step 0 and 1 do not write and as such they cannot invalidate the invariant of any other thieves.
     636In step 2 a thief attempts to write @0p@ to one of their queue pointers.
     637This queue pointer cannot be @0p@.
     638As stated above, @my_queue@ is never equal to @0p@ since thieves will only write @0p@ to queue pointers from their own queue range and all worker's queue ranges are disjoint.
     639As such step 2 upholds the invariant since in a failure case no write occurs, and in the success case, the value of the queue pointer is guaranteed to not be 0p.
     640In step 3 the thief attempts to write @my_queue@ to the victim's queue pointer.
     641If the current value of the victim's queue pointer is @0p@, then the CAS will fail since @vic_queue@ cannot be equal to @0p@ because of the check in step 1.
     642Therefore in the success case where the @CAS@ succeeds, the value of the victim's queue pointer must not be @0p@.
     643As such, the write will never overwrite a value of @0p@, hence the invariant is held in the @CAS@ of step 3.
     644The write back to the thief's queue pointer that happens in the failure case of step three and in step 4 hold the invariant since they are the subsequent write to a @0p@ queue pointer and they are being set by the same thief that set the pointer to @0p@.
     645
     646Given this informal proof of invariance it can be shown that the successful swap is correct.
     647Once a thief atomically sets their queue pointer to be @0p@ in step 2, the invariant guarantees that pointer will not change.
     648As such, in the success case step 3 it is known that the value of the victim's queue pointer that was overwritten must be @vic_queue@ due to the use of @CAS@.
     649Given that pointers all have unique memory locations, this first write of the successful swap is correct since it can only occur when the pointer has not changed.
     650By the invariant the write back in the successful case is correct since no other worker can write to the @0p@ pointer.
     651
     652In the failed case the outcome is correct in steps 1 and 2 since no writes have occurred so the program state is unchanged.
     653In the failed case of step 3 the program state is safely restored to its state it had prior to the @0p@ write in step 2, thanks to the invariant that makes the write back to the @0p@ pointer safe.
    482654
    483655\subsection{Stealing Guarantees}
    484 
    485 % C_TODO insert graphs for each proof
    486 Given that the stealing operation can potentially fail, it is important to discuss the guarantees provided by the stealing implementation.
    487 Given a set of $N$ swaps a set of connected directed graphs can be constructed where each vertex is a queue and each edge is a swap directed from a thief queue to a victim queue.
    488 Since each thief can only steal from one victim at a time, each vertex can only have at most one outgoing edge.
     656Given that the stealing operation can potentially fail, it is important to discuss the guarantees provided by the stealing implementation.
     657Given a set of $N$ swaps a set of connected directed graphs can be constructed where each vertex is a queue and each edge is a swap directed from a thief queue to a victim queue.
     658Since each thief can only steal from one victim at a time, each vertex can only have at most one outgoing edge.
    489659A corollary that can be drawn from this, is that there are at most $V$ edges in this constructed set of connected directed graphs, where $V$ is the total number of vertices.
    490660
     
    498668
    499669\begin{theorem}
    500 Given $M$ thieves queues all attempting to swap with one victim queue, and no other swaps occuring that involve these queues, at least one swap is guaranteed to succeed.
     670Given $M$ thieves queues all attempting to swap with one victim queue, and no other swaps occurring that involve these queues, at least one swap is guaranteed to succeed.
    501671\end{theorem}\label{t:one_vic}
    502672A graph of the $M$ thieves swapping with one victim discussed in this theorem is presented in Figure~\ref{f:M_one_swap}.
    503673\\
    504 First it is important to state that a thief will not attempt to steal from themselves. 
    505 As such, the victim here is not also a thief. 
    506 Stepping through the code in \ref{c:swap}, for all thieves steps 0-1 succeed since the victim is not stealing and will have no queue pointers set to be \code{0p}.
    507 Similarly for all thieves step 2 will succeed since no one is stealing from any of the thieves. 
    508 In step 3 the first thief to \code{CAS} will win the race and successfully swap the queue pointer.
    509 Since it is the first one to \code{CAS} and \code{CAS} is atomic, there is no way for the \code{CAS} to fail since no other thief could have written to the victim's queue pointer and the victim did not write to the pointer since they aren't stealing.
     674First it is important to state that a thief will not attempt to steal from themselves.
     675As such, the victim here is not also a thief.
     676Stepping through the code in \ref{c:swap}, for all thieves steps 0-1 succeed since the victim is not stealing and will have no queue pointers set to be @0p@.
     677Similarly for all thieves step 2 will succeed since no one is stealing from any of the thieves.
     678In step 3 the first thief to @CAS@ will win the race and successfully swap the queue pointer.
     679Since it is the first one to @CAS@ and @CAS@ is atomic, there is no way for the @CAS@ to fail since no other thief could have written to the victim's queue pointer and the victim did not write to the pointer since they aren't stealing.
    510680Hence at least one swap is guaranteed to succeed in this case.
    511681
     
    519689
    520690\begin{theorem}
    521 Given $M$ > 1, ordered queues pointers all attempting to swap with the queue in front of them in the ordering, except the first queue, and no other swaps occuring that involve these queues, at least one swap is guaranteed to succeed.
     691Given $M$ > 1, ordered queues pointers all attempting to swap with the queue in front of them in the ordering, except the first queue, and no other swaps occurring that involve these queues, at least one swap is guaranteed to succeed.
    522692\end{theorem}\label{t:vic_chain}
    523693A graph of the chain of swaps discussed in this theorem is presented in Figure~\ref{f:chain_swap}.
    524694\\
    525 This is a proof by contradiction. 
    526 Assume no swaps occur. 
    527 Then all thieves must have failed at step 1, step 2 or step 3. 
    528 For a given thief $b$ to fail at step 1, thief $b + 1$ must have succeded at step 2 before $b$ executes step 0.
    529 Hence, not all thieves can fail at step 1. 
    530 Furthermore if a thief $b$ fails at step 1 it logically splits the chain into two subchains $0 <- b$ and $b + 1 <- M - 1$, where $b$ has become solely a victim since its swap has failed and it did not modify any state. 
    531 There must exist at least one chain containing two or more queues after since it is impossible for a split to occur both before and after a thief, since that requires failing at step 1 and succeeding at step 2. 
     695This is a proof by contradiction.
     696Assume no swaps occur.
     697Then all thieves must have failed at step 1, step 2 or step 3.
     698For a given thief $b$ to fail at step 1, thief $b + 1$ must have succeeded at step 2 before $b$ executes step 0.
     699Hence, not all thieves can fail at step 1.
     700Furthermore if a thief $b$ fails at step 1 it logically splits the chain into two subchains $0 <- b$ and $b + 1 <- M - 1$, where $b$ has become solely a victim since its swap has failed and it did not modify any state.
     701There must exist at least one chain containing two or more queues after since it is impossible for a split to occur both before and after a thief, since that requires failing at step 1 and succeeding at step 2.
    532702Hence, without loss of generality, whether thieves succeed or fail at step 1, this proof can proceed inductively.
    533703
    534 For a given thief $i$ to fail at step 2, it means that another thief $j$ had to have written to $i$'s queue pointer between $i$'s step 0 and step 2. 
    535 The only way for $j$ to write to $i$'s queue pointer would be if $j$ was stealing from $i$ and had successfully finished step 3. 
    536 If $j$ finished step 3 then the at least one swap was successful. 
    537 Therefore all thieves did not fail at step 2. 
    538 Hence all thieves must successfully complete step 2 and fail at step 3. 
    539 However, since the first worker, thief $0$, is solely a victim and not a thief, it does not change the state of any of its queue pointers. 
    540 Hence, in this case thief $1$ will always succeed in step 3 if all thieves succeed in step 2. 
     704For a given thief $i$ to fail at step 2, it means that another thief $j$ had to have written to $i$'s queue pointer between $i$'s step 0 and step 2.
     705The only way for $j$ to write to $i$'s queue pointer would be if $j$ was stealing from $i$ and had successfully finished step 3.
     706If $j$ finished step 3 then the at least one swap was successful.
     707Therefore all thieves did not fail at step 2.
     708Hence all thieves must successfully complete step 2 and fail at step 3.
     709However, since the first worker, thief $0$, is solely a victim and not a thief, it does not change the state of any of its queue pointers.
     710Hence, in this case thief $1$ will always succeed in step 3 if all thieves succeed in step 2.
    541711Thus, by contradiction with the earlier assumption that no swaps occur, at least one swap must succeed.
    542712
     
    545715\centering
    546716\begin{tabular}{l|l}
    547 \subfloat[Cyclic Swap Graph]{\label{f:cyclic_swap}\input{diagrams/cyclic_swap.tikz}} & 
    548 \subfloat[Acyclic Swap Graph]{\label{f:acyclic_swap}\input{diagrams/acyclic_swap.tikz}} 
     717\subfloat[Cyclic Swap Graph]{\label{f:cyclic_swap}\input{diagrams/cyclic_swap.tikz}} &
     718\subfloat[Acyclic Swap Graph]{\label{f:acyclic_swap}\input{diagrams/acyclic_swap.tikz}}
    549719\end{tabular}
    550720\caption{Illustrations of cyclic and acyclic swap graphs.}
     
    552722
    553723\begin{theorem}
    554 Given a set of $M > 1$ swaps occuring that form a single directed connected graph.
    555 At least one swap is guaranteed to suceed if and only if the graph does not contain a cycle.
     724Given a set of $M > 1$ swaps occurring that form a single directed connected graph.
     725At least one swap is guaranteed to succeed if and only if the graph does not contain a cycle.
    556726\end{theorem}\label{t:vic_cycle}
    557 Representations of cyclic and acylic swap graphs discussed in this theorem are presented in Figures~\ref{f:cyclic_swap} and \ref{f:acyclic_swap}.
     727Representations of cyclic and acyclic swap graphs discussed in this theorem are presented in Figures~\ref{f:cyclic_swap} and \ref{f:acyclic_swap}.
    558728\\
    559 First the reverse direction is proven. 
    560 If the graph does not contain a cycle, then there must be at least one successful swap. 
    561 Since the graph contains no cycles and is finite in size, then there must be a vertex $A$ with no outgoing edges. 
    562 The graph can then be formulated as a tree with $A$ at the top since each node only has at most one outgoing edge and there are no cycles. 
    563 The forward direction is proven by contradiction in a similar fashion to \ref{t:vic_chain}. 
    564 Assume no swaps occur. 
    565 Similar to \ref{t:vic_chain}, this graph can be inductively split into subgraphs of the same type by failure at step 1, so the proof proceeds without loss of generality. 
    566 Similar to \ref{t:vic_chain} the conclusion is drawn that all thieves must successfully complete step 2 for no swaps to occur, since for step 2 to fail, a different thief has to successfully complete step 3, which would imply a successful swap. 
    567 Hence, the only way forward is to assume all thieves successfully complete step 2. 
    568 Hence for there to be no swaps all thieves must fail step 3. 
    569 However, since $A$ has no outgoing edges, since the graph is connected there must be some $K$ such that $K < M - 1$ thieves are attempting to swap with $A$. 
    570 Since all $K$ thieves have passed step 2, similar to \ref{t:one_vic} the first one of the $K$ thieves to attempt step 3 is guaranteed to succeed. 
     729First the reverse direction is proven.
     730If the graph does not contain a cycle, then there must be at least one successful swap.
     731Since the graph contains no cycles and is finite in size, then there must be a vertex $A$ with no outgoing edges.
     732The graph can then be formulated as a tree with $A$ at the top since each node only has at most one outgoing edge and there are no cycles.
     733The forward direction is proven by contradiction in a similar fashion to \ref{t:vic_chain}.
     734Assume no swaps occur.
     735Similar to \ref{t:vic_chain}, this graph can be inductively split into subgraphs of the same type by failure at step 1, so the proof proceeds without loss of generality.
     736Similar to \ref{t:vic_chain} the conclusion is drawn that all thieves must successfully complete step 2 for no swaps to occur, since for step 2 to fail, a different thief has to successfully complete step 3, which would imply a successful swap.
     737Hence, the only way forward is to assume all thieves successfully complete step 2.
     738Hence for there to be no swaps all thieves must fail step 3.
     739However, since $A$ has no outgoing edges, since the graph is connected there must be some $K$ such that $K < M - 1$ thieves are attempting to swap with $A$.
     740Since all $K$ thieves have passed step 2, similar to \ref{t:one_vic} the first one of the $K$ thieves to attempt step 3 is guaranteed to succeed.
    571741Thus, by contradiction with the earlier assumption that no swaps occur, if the graph does not contain a cycle, at least one swap must succeed.
    572742
    573 The forward direction is proven by contrapositive. 
    574 If the graph contains a cycle then there exists a situation where no swaps occur. 
    575 This situation is constructed. 
    576 Since all vertices have at most one outgoing edge the cycle must be directed. 
    577 Furthermore, since the graph contains a cycle all vertices in the graph must have exactly one outgoing edge. 
    578 This is shown through construction of an aribtrary cyclic graph.
    579 The graph contains a directed cycle by definition, so the construction starts with $T$ vertices in a directed cycle. 
    580 Since the graph is connected, and each vertex has at most one outgoing edge, none of the vertices in the cycle have available outgoing edges to accomodate new vertices with no outgoing edges.
    581 Any vertices added to the graph must have an outgoing edge to connect, leaving the resulting graph with no available outgoing edges. 
    582 Thus, by induction all vertices in the graph must have exactly one outgoing edge. 
    583 Hence all vertices are thief queues. 
    584 Now consider the case where all thieves successfully complete step 0-1, and then they all complete step 2. 
    585 At this point all thieves are attempting to swap with a queue pointer whose value has changed to \code{0p}.
    586 If all thieves attempt the \code{CAS} before any write backs, then they will all fail.
    587 Thus, by contrapositive, if the graph contains a cycle then there exists a situation where no swaps occur. 
    588 Hence, at least one swap is guaranteed to suceed if and only if the graph does not contain a cycle.
     743The forward direction is proven by contrapositive.
     744If the graph contains a cycle then there exists a situation where no swaps occur.
     745This situation is constructed.
     746Since all vertices have at most one outgoing edge the cycle must be directed.
     747Furthermore, since the graph contains a cycle all vertices in the graph must have exactly one outgoing edge.
     748This is shown through construction of an arbitrary cyclic graph.
     749The graph contains a directed cycle by definition, so the construction starts with $T$ vertices in a directed cycle.
     750Since the graph is connected, and each vertex has at most one outgoing edge, none of the vertices in the cycle have available outgoing edges to accommodate new vertices with no outgoing edges.
     751Any vertices added to the graph must have an outgoing edge to connect, leaving the resulting graph with no available outgoing edges.
     752Thus, by induction all vertices in the graph must have exactly one outgoing edge.
     753Hence all vertices are thief queues.
     754Now consider the case where all thieves successfully complete step 0-1, and then they all complete step 2.
     755At this point all thieves are attempting to swap with a queue pointer whose value has changed to @0p@.
     756If all thieves attempt the @CAS@ before any write backs, then they will all fail.
     757Thus, by contrapositive, if the graph contains a cycle then there exists a situation where no swaps occur.
     758Hence, at least one swap is guaranteed to succeed if and only if the graph does not contain a cycle.
    589759
    590760% C_TODO: go through and use \paragraph to format to make it look nicer
    591761\subsection{Victim Selection}\label{s:victimSelect}
    592 In any work stealing algorithm thieves have some heuristic to determine which victim to choose from. 
    593 Choosing this algorithm is difficult and can have implications on performance. 
    594 There is no one selection heuristic that is known to be the best on all workloads. 
    595 Recent work focuses on locality aware scheduling in actor systems\cite{barghi18}\cite{wolke17}. 
    596 However, while locality aware scheduling provides good performance on some workloads, something as simple as randomized selection performs better on other workloads\cite{barghi18}. 
    597 Since locality aware scheduling has been explored recently, this work introduces a heuristic called \textbf{longest victim} and compares it to randomized work stealing. 
    598 The longest victim heuristic maintains a timestamp per worker thread that is updated every time a worker attempts to steal work.
    599 Thieves then attempt to steal from the thread with the oldest timestamp. 
    600 This means that if two thieves look to steal at the same time, they likely will attempt to steal from the same victim. 
    601 This does increase the chance at contention between thieves, however given that workers have multiple queues under them, often in the tens or hundreds of queues per worker it is rare for two queues to attempt so steal the same queue. 
    602 Furthermore in the case they attempt to steal the same queue at least one of them is guaranteed to successfully steal the queue as shown in Theorem \ref{t:one_vic}. 
    603 Additonally, the longest victim heuristic makes it very improbable that the no swap scenario presented in Theorem \ref{t:vic_cycle} manifests.
    604 Given the longest victim heuristic, for a cycle to manifest it would require all workers to attempt to steal in a short timeframe. 
    605 This is the only way that more than one thief could choose another thief as a victim, since timestamps are only updated upon attempts to steal. 
     762In any work stealing algorithm thieves have some heuristic to determine which victim to choose from.
     763Choosing this algorithm is difficult and can have implications on performance.
     764There is no one selection heuristic that is known to be the best on all workloads.
     765Recent work focuses on locality aware scheduling in actor systems\cite{barghi18}\cite{wolke17}.
     766However, while locality aware scheduling provides good performance on some workloads, something as simple as randomized selection performs better on other workloads\cite{barghi18}.
     767Since locality aware scheduling has been explored recently, this work introduces a heuristic called \textbf{longest victim} and compares it to randomized work stealing.
     768The longest victim heuristic maintains a timestamp per executor threads that is updated every time a worker attempts to steal work.
     769Thieves then attempt to steal from the thread with the oldest timestamp.
     770This means that if two thieves look to steal at the same time, they likely will attempt to steal from the same victim.
     771This does increase the chance at contention between thieves, however given that workers have multiple queues under them, often in the tens or hundreds of queues per worker it is rare for two queues to attempt so steal the same queue.
     772Furthermore in the case they attempt to steal the same queue at least one of them is guaranteed to successfully steal the queue as shown in Theorem \ref{t:one_vic}.
     773Additionally, the longest victim heuristic makes it very improbable that the no swap scenario presented in Theorem \ref{t:vic_cycle} manifests.
     774Given the longest victim heuristic, for a cycle to manifest it would require all workers to attempt to steal in a short timeframe.
     775This is the only way that more than one thief could choose another thief as a victim, since timestamps are only updated upon attempts to steal.
    606776In this case, the probability of lack of any successful swaps is a non issue, since it is likely that these steals were not important if all workers are trying to steal.
    607777
    608 \section{Safety and Productivity}
    609 \CFA's actor system comes with a suite of safety and productivity features. 
    610 Most of these features are present in \CFA's debug mode, but are removed when code is compiled in nodebug mode. 
     778\section{Safety and Productivity}\label{s:SafetyProductivity}
     779\CFA's actor system comes with a suite of safety and productivity features.
     780Most of these features are present in \CFA's debug mode, but are removed when code is compiled in nodebug mode.
    611781The suit of features include the following.
    612782
    613783\begin{itemize}
    614 \item Static-typed message sends. 
     784\item Static-typed message sends.
    615785If an actor does not support receiving a given message type, the actor program is rejected at compile time, allowing unsupported messages to never be sent to actors.
    616 \item Detection of message sends to Finished/Destroyed/Deleted actors. 
    617 All actors have a ticket that assigns them to a respective queue. 
     786\item Detection of message sends to Finished/Destroyed/Deleted actors.
     787All actors have a ticket that assigns them to a respective queue.
    618788The maximum integer value of the ticket is reserved to indicate that an actor is dead, and subsequent message sends result in an error.
    619 \item Actors made before the executor can result in undefined behaviour since an executor needs to be created beforehand so it can give out the tickets to actors. 
     789\item Actors made before the executor can result in undefined behaviour since an executor needs to be created beforehand so it can give out the tickets to actors.
    620790As such, this is detected and an error is printed.
    621 \item When an executor is created, the queues are handed out to worker threads in round robin order.
    622 If there are fewer queues than worker threads, then some workers will spin and never do any work.
    623 There is no reasonable use case for this behaviour so an error is printed if the number of queues is fewer than the number of worker threads.
    624 \item A warning is printed when messages are deallocated without being sent. 
    625 Since the \code{Finished} allocation status is unused for messages, it is used internally to detect if a message has been sent.
     791\item When an executor is created, the queues are handed out to executor threads in round robin order.
     792If there are fewer queues than executor threads, then some workers will spin and never do any work.
     793There is no reasonable use case for this behaviour so an error is printed if the number of queues is fewer than the number of executor threads.
     794\item A warning is printed when messages are deallocated without being sent.
     795Since the @Finished@ allocation status is unused for messages, it is used internally to detect if a message has been sent.
    626796Deallocating a message without sending it could indicate to a user that they are touching freed memory later, or it could point out extra allocations that could be removed.
     797\item Detection of messages sent but not received
     798As discussed in Section~\ref{s:executor}, once all actors have terminated shutdown is communicated to executor threads via a status flag. Upon termination the executor threads check their queues to see if any contain messages. If they do, an error is reported. Messages being sent but not received means that their allocation action did not occur and their payload was not delivered. Missing the allocation action can lead to memory leaks and missed payloads can cause unpredictable behaviour. Detecting this can indicate a race or logic error in the user's code.
    627799\end{itemize}
    628800
    629 In addition to these features, \CFA's actor system comes with a suite of statistics that can be toggled on and off. 
    630 These statistics have minimal impact on the actor system's performance since they are counted on a per worker thread basis.
    631 During shutdown of the actor system they are aggregated, ensuring that the only atomic instructions used by the statistics counting happen at shutdown. 
     801In addition to these features, \CFA's actor system comes with a suite of statistics that can be toggled on and off.
     802These statistics have minimal impact on the actor system's performance since they are counted on a per executor threads basis.
     803During shutdown of the actor system they are aggregated, ensuring that the only atomic instructions used by the statistics counting happen at shutdown.
    632804The statistics measured are as follows.
    633805
    634806\begin{description}
    635807\item[\LstBasicStyle{\textbf{Actors Created}}]
    636 Actors created. 
     808Actors created.
    637809Includes both actors made by the main and ones made by other actors.
    638810\item[\LstBasicStyle{\textbf{Messages Sent}}]
    639 Messages sent and received. 
    640 Includes termination messages send to the worker threads.
     811Messages sent and received.
     812Includes termination messages send to the executor threads.
    641813\item[\LstBasicStyle{\textbf{Gulps}}]
    642 Gulps that occured across the worker threads.
     814Gulps that occurred across the executor threads.
    643815\item[\LstBasicStyle{\textbf{Average Gulp Size}}]
    644816Average number of messages in a gulped queue.
    645817\item[\LstBasicStyle{\textbf{Missed gulps}}]
    646 Occurences where a worker missed a gulp due to the concurrent queue processing by another worker.
     818Occurrences where a worker missed a gulp due to the concurrent queue processing by another worker.
    647819\item[\LstBasicStyle{\textbf{Steal attempts}}]
    648 Worker threads attempts to steal work. 
     820Worker threads attempts to steal work.
    649821
    650822\item[\LstBasicStyle{\textbf{Steal failures (no candidates)}}]
     
    658830\end{description}
    659831
    660 These statistics enable a user of \CFA's actor system to make informed choices about how to configure their executor, or how to structure their actor program. 
    661 For example, if there is a lot of messages being stolen relative to the number of messages sent, it could indicate to a user that their workload is heavily imbalanced across worker threads.
     832These statistics enable a user of \CFA's actor system to make informed choices about how to configure their executor, or how to structure their actor program.
     833For example, if there is a lot of messages being stolen relative to the number of messages sent, it could indicate to a user that their workload is heavily imbalanced across executor threads.
    662834In another example, if the average gulp size is very high, it could indicate that the executor could use more queue sharding.
    663835
    664836% C_TODO cite poison pill messages and add languages
    665 Another productivity feature that is included is a group of poison-pill messages. 
    666 Poison-pill messages are common across actor systems, including Akka and ProtoActor \cite{}. 
    667 Poison-pill messages inform an actor to terminate. 
    668 In \CFA, due to the allocation of actors and lack of garbage collection, there needs to be a suite of poison-pills. 
    669 The messages that \CFA provides are \code{DeleteMsg}, \code{DestroyMsg}, and \code{FinishedMsg}.
    670 These messages are supported on all actor types via inheritance and when sent to an actor, the actor takes the corresponding allocation action after receiving the message. 
    671 Note that any pending messages to the actor will still be sent. 
     837Another productivity feature that is included is a group of poison-pill messages.
     838Poison-pill messages are common across actor systems, including Akka and ProtoActor \cite{}.
     839Poison-pill messages inform an actor to terminate.
     840In \CFA, due to the allocation of actors and lack of garbage collection, there needs to be a suite of poison-pills.
     841The messages that \CFA provides are @DeleteMsg@, @DestroyMsg@, and @FinishedMsg@.
     842These messages are supported on all actor types via inheritance and when sent to an actor, the actor takes the corresponding allocation action after receiving the message.
     843Note that any pending messages to the actor will still be sent.
    672844It is still the user's responsibility to ensure that an actor does not receive any messages after termination.
    673845
     
    675847\CAP{I will update the figures to have the larger font size and different line markers once we start editing this chapter.}
    676848The performance of \CFA's actor system is tested using a suite of microbenchmarks, and compared with other actor systems.
    677 Most of the benchmarks are the same as those presented in \ref{}, with a few additions. 
     849Most of the benchmarks are the same as those presented in \ref{}, with a few additions.
    678850% C_TODO cite actor paper
    679 At the time of this work the versions of the actor systems are as follows. 
    680 \CFA 1.0, \uC 7.0.0, Akka Typed 2.7.0, CAF 0.18.6, and ProtoActor-Go v0.0.0-20220528090104-f567b547ea07. 
     851At the time of this work the versions of the actor systems are as follows.
     852\CFA 1.0, \uC 7.0.0, Akka Typed 2.7.0, CAF 0.18.6, and ProtoActor-Go v0.0.0-20220528090104-f567b547ea07.
    681853Akka Classic is omitted as Akka Typed is their newest version and seems to be the direction they are headed in.
    682854The experiments are run on
     
    688860\end{list}
    689861
    690 The benchmarks are run on up to 48 cores. 
    691 On the Intel, when going beyond 24 cores there is the choice to either hop sockets or to use hyperthreads. 
    692 Either choice will cause a blip in performance trends, which can be seen in the following performance figures. 
     862The benchmarks are run on up to 48 cores.
     863On the Intel, when going beyond 24 cores there is the choice to either hop sockets or to use hyperthreads.
     864Either choice will cause a blip in performance trends, which can be seen in the following performance figures.
    693865On the Intel the choice was made to hyperthread instead of hopping sockets for experiments with more than 24 cores.
    694866
    695 All benchmarks presented are run 5 times and the median is taken. 
    696 Error bars showing the 95\% confidence intervals are drawn on each point on the graphs. 
    697 If the confidence bars are small enough, they may be obscured by the point. 
    698 In this section \uC will be compared to \CFA frequently, as the actor system in \CFA was heavily based off \uC's actor system. 
    699 As such the peformance differences that arise are largely due to the contributions of this work.
     867All benchmarks presented are run 5 times and the median is taken.
     868Error bars showing the 95\% confidence intervals are drawn on each point on the graphs.
     869If the confidence bars are small enough, they may be obscured by the point.
     870In this section \uC will be compared to \CFA frequently, as the actor system in \CFA was heavily based off \uC's actor system.
     871As such the performance differences that arise are largely due to the contributions of this work.
    700872
    701873\begin{table}[t]
     
    708880\begin{tabular}{*{5}{r|}r}
    709881        & \multicolumn{1}{c|}{\CFA (100M)} & \multicolumn{1}{c|}{CAF (10M)} & \multicolumn{1}{c|}{Akka (100M)} & \multicolumn{1}{c|}{\uC (100M)} & \multicolumn{1}{c@{}}{ProtoActor (100M)} \\
    710         \hline                                                                                                                                                 
     882        \hline
    711883        AMD             & \input{data/pykeSendStatic} \\
    712         \hline                                                                                                                                                 
     884        \hline
    713885        Intel   & \input{data/nasusSendStatic}
    714886\end{tabular}
     
    721893\begin{tabular}{*{5}{r|}r}
    722894        & \multicolumn{1}{c|}{\CFA (20M)} & \multicolumn{1}{c|}{CAF (2M)} & \multicolumn{1}{c|}{Akka (2M)} & \multicolumn{1}{c|}{\uC (20M)} & \multicolumn{1}{c@{}}{ProtoActor (2M)} \\
    723         \hline                                                                                                                                                 
     895        \hline
    724896        AMD             & \input{data/pykeSendDynamic} \\
    725         \hline                                                                                                                                                 
     897        \hline
    726898        Intel   & \input{data/nasusSendDynamic}
    727899\end{tabular}
     
    729901
    730902\subsection{Message Sends}
    731 Message sending is the key component of actor communication. 
    732 As such latency of a single message send is the fundamental unit of fast-path performance for an actor system. 
    733 The following two microbenchmarks evaluate the average latency for a static actor/message send and a dynamic actor/message send. 
    734 Static and dynamic refer to the allocation of the message and actor. 
    735 In the static send benchmark a message and actor are allocated once and then the message is sent to the same actor repeatedly until it has been sent 100 million (100M) times. 
    736 The average latency per message send is then calculated by dividing the duration by the number of sends. 
    737 This benchmark evaluates the cost of message sends in the actor use case where all actors and messages are allocated ahead of time and do not need to be created dynamically during execution. 
     903Message sending is the key component of actor communication.
     904As such latency of a single message send is the fundamental unit of fast-path performance for an actor system.
     905The following two microbenchmarks evaluate the average latency for a static actor/message send and a dynamic actor/message send.
     906Static and dynamic refer to the allocation of the message and actor.
     907In the static send benchmark a message and actor are allocated once and then the message is sent to the same actor repeatedly until it has been sent 100 million (100M) times.
     908The average latency per message send is then calculated by dividing the duration by the number of sends.
     909This benchmark evaluates the cost of message sends in the actor use case where all actors and messages are allocated ahead of time and do not need to be created dynamically during execution.
    738910The CAF static send benchmark only sends a message 10M times to avoid extensively long run times.
    739911
    740 In the dynamic send benchmark the same experiment is performed, with the change that with each send a new actor and message is allocated. 
    741 This evaluates the cost of message sends in the other common actor pattern where actors and message are created on the fly as the actor program tackles a workload of variable or unknown size. 
     912In the dynamic send benchmark the same experiment is performed, with the change that with each send a new actor and message is allocated.
     913This evaluates the cost of message sends in the other common actor pattern where actors and message are created on the fly as the actor program tackles a workload of variable or unknown size.
    742914Since dynamic sends are more expensive, this benchmark repeats the actor/message creation and send 20M times (\uC, \CFA), or 2M times (Akka, CAF, ProtoActor), to give an appropriate benchmark duration.
    743915
    744 The results from the static/dynamic send benchmarks are shown in Figures~\ref{t:StaticActorMessagePerformance} and \ref{t:DynamicActorMessagePerformance} respectively. 
    745 \CFA leads the charts in both benchmarks, largely due to the copy queue removing the majority of the envelope allocations. 
    746 In the static send benchmark all systems except CAF have static send costs that are in the same ballpark, only varying by ~70ns. 
    747 In the dynamic send benchmark all systems experience slower message sends, as expected due to the extra allocations. 
    748 However, Akka and ProtoActor, slow down by a more significant margin than the \uC and \CFA. 
     916The results from the static/dynamic send benchmarks are shown in Figures~\ref{t:StaticActorMessagePerformance} and \ref{t:DynamicActorMessagePerformance} respectively.
     917\CFA leads the charts in both benchmarks, largely due to the copy queue removing the majority of the envelope allocations.
     918In the static send benchmark all systems except CAF have static send costs that are in the same ballpark, only varying by ~70ns.
     919In the dynamic send benchmark all systems experience slower message sends, as expected due to the extra allocations.
     920However, Akka and ProtoActor, slow down by a more significant margin than the \uC and \CFA.
    749921This is likely a result of Akka and ProtoActor's garbage collection, which can suffer from hits in performance for allocation heavy workloads, whereas \uC and \CFA have explicit allocation/deallocation.
    750922
    751923\subsection{Work Stealing}
    752 \CFA's actor system has a work stealing mechanism which uses the longest victim heuristic, introduced in Section~ref{s:victimSelect}. 
     924\CFA's actor system has a work stealing mechanism which uses the longest victim heuristic, introduced in Section~ref{s:victimSelect}.
    753925In this performance section, \CFA with the longest victim heuristic is compared with other actor systems on the benchmark suite, and is separately compared with vanilla non-stealing \CFA and \CFA with randomized work stealing.
    754926
     
    779951\end{figure}
    780952
    781 There are two benchmarks in which \CFA's work stealing is solely evaluated. 
    782 The main goal of introducing work stealing to \CFA's actor system is to eliminate the pathological unbalanced cases that can present themselves in a system without some form of load balancing. 
    783 The following two microbenchmarks construct two such pathological cases, and compare the work stealing variations of \CFA. 
    784 The balance benchmarks adversarily takes advantage of the round robin assignment of actors to load all actors that will do work on specific cores and create 'dummy' actors that terminate after a single message send on all other cores.
    785 The workload on the loaded cores is the same as the executor benchmark described in \ref{s:executorPerf}, but with fewer rounds. 
    786 The balance-one benchmark loads all the work on a single core, whereas the balance-multi loads all the work on half the cores (every other core). 
    787 Given this layout, one expects the ideal speedup of work stealing in the balance-one case to be $N / N - 1$ where $N$ is the number of threads. 
    788 In the balance-multi case the ideal speedup is 0.5. 
    789 Note that in the balance-one benchmark the workload is fixed so decreasing runtime is expected. 
     953There are two benchmarks in which \CFA's work stealing is solely evaluated.
     954The main goal of introducing work stealing to \CFA's actor system is to eliminate the pathological unbalanced cases that can present themselves in a system without some form of load balancing.
     955The following two microbenchmarks construct two such pathological cases, and compare the work stealing variations of \CFA.
     956The balance benchmarks adversarially takes advantage of the round robin assignment of actors to load all actors that will do work on specific cores and create 'dummy' actors that terminate after a single message send on all other cores.
     957The workload on the loaded cores is the same as the executor benchmark described in \ref{s:executorPerf}, but with fewer rounds.
     958The balance-one benchmark loads all the work on a single core, whereas the balance-multi loads all the work on half the cores (every other core).
     959Given this layout, one expects the ideal speedup of work stealing in the balance-one case to be $N / N - 1$ where $N$ is the number of threads.
     960In the balance-multi case the ideal speedup is 0.5.
     961Note that in the balance-one benchmark the workload is fixed so decreasing runtime is expected.
    790962In the balance-multi experiment, the workload increases with the number of cores so an increasing or constant runtime is expected.
    791963
    792 On both balance microbenchmarks slightly less than ideal speedup compared to the non stealing variation is achieved by both the random and longest victim stealing heuristics. 
    793 On the balance-multi benchmark \ref{f:BalanceMultiAMD},\ref{f:BalanceMultiIntel} the random heuristic outperforms the longest victim. 
    794 This is likely a result of the longest victim heuristic having a higher stealing cost as it needs to maintain timestamps and look at all timestamps before stealing. 
     964On both balance microbenchmarks slightly less than ideal speedup compared to the non stealing variation is achieved by both the random and longest victim stealing heuristics.
     965On the balance-multi benchmark \ref{f:BalanceMultiAMD},\ref{f:BalanceMultiIntel} the random heuristic outperforms the longest victim.
     966This is likely a result of the longest victim heuristic having a higher stealing cost as it needs to maintain timestamps and look at all timestamps before stealing.
    795967Additionally, a performance cost can be observed when hyperthreading kicks in in Figure~\ref{f:BalanceMultiIntel}.
    796968
    797 In the balance-one benchmark on AMD \ref{f:BalanceOneAMD}, the performance bottoms out at 32 cores onwards likely due to the amount of work becoming less than the cost to steal it and move it across cores and cache. 
    798 On Intel \ref{f:BalanceOneIntel}, above 32 cores the performance gets worse for all variants due to hyperthreading. 
     969In the balance-one benchmark on AMD \ref{f:BalanceOneAMD}, the performance bottoms out at 32 cores onwards likely due to the amount of work becoming less than the cost to steal it and move it across cores and cache.
     970On Intel \ref{f:BalanceOneIntel}, above 32 cores the performance gets worse for all variants due to hyperthreading.
    799971Note that the non stealing variation of balance-one will slow down marginally as the cores increase due to having to create more dummy actors on the inactive cores during startup.
    800972
    801973\subsection{Executor}\label{s:executorPerf}
    802 The microbenchmarks in this section are designed to stress the executor. 
    803 The executor is the scheduler of an actor system and is responsible for organizing the interaction of worker threads to service the needs of a workload.
    804 In the executor benchmark, 40'000 actors are created and assigned a group. 
    805 Each group of actors is a group of 100 actors who send and receive 100 messages from all other actors in their group. 
    806 Each time an actor completes all their sends and receives, they are done a round. 
    807 After all groups have completed 400 rounds the system terminates. 
    808 This microbenchmark is designed to flood the executor with a large number of messages flowing between actors. 
     974The microbenchmarks in this section are designed to stress the executor.
     975The executor is the scheduler of an actor system and is responsible for organizing the interaction of executor threads to service the needs of a workload.
     976In the executor benchmark, 40'000 actors are created and assigned a group.
     977Each group of actors is a group of 100 actors who send and receive 100 messages from all other actors in their group.
     978Each time an actor completes all their sends and receives, they are done a round.
     979After all groups have completed 400 rounds the system terminates.
     980This microbenchmark is designed to flood the executor with a large number of messages flowing between actors.
    809981Given there is no work associated with each message, other than sending more messages, the intended bottleneck of this experiment is the executor message send process.
    810982
     
    822994\end{figure}
    823995
    824 The results of the executor benchmark in Figures~\ref{f:ExecutorIntel} and \ref{f:ExecutorAMD} show \CFA with the lowest runtime relative to its peers. 
    825 The difference in runtime between \uC and \CFA is largely due to the usage of the copy queue described in Section~\ref{s:copyQueue}. 
    826 The copy queue both reduces and consolidates allocations, heavily reducing contention on the memory allocator. 
    827 Additionally, due to the static typing in \CFA's actor system, it is able to get rid of expensive dynamic casts that occur in \uC to disciminate messages by type.
    828 Note that dynamic casts are ususally not very expensive, but relative to the high performance of the rest of the implementation of the \uC actor system, the cost is significant.
     996The results of the executor benchmark in Figures~\ref{f:ExecutorIntel} and \ref{f:ExecutorAMD} show \CFA with the lowest runtime relative to its peers.
     997The difference in runtime between \uC and \CFA is largely due to the usage of the copy queue described in Section~\ref{s:copyQueue}.
     998The copy queue both reduces and consolidates allocations, heavily reducing contention on the memory allocator.
     999Additionally, due to the static typing in \CFA's actor system, it is able to get rid of expensive dynamic casts that occur in \uC to discriminate messages by type.
     1000Note that dynamic casts are usually not very expensive, but relative to the high performance of the rest of the implementation of the \uC actor system, the cost is significant.
    8291001
    8301002\begin{figure}
     
    8411013\end{figure}
    8421014
    843 When comparing the \CFA stealing heuristics in Figure~\ref{f:cfaExecutorAMD} it can be seen that the random heuristic falls slightly behind the other two, but in Figure~\ref{f:cfaExecutorIntel} the runtime of all heuristics are nearly identical to eachother.
     1015When comparing the \CFA stealing heuristics in Figure~\ref{f:cfaExecutorAMD} it can be seen that the random heuristic falls slightly behind the other two, but in Figure~\ref{f:cfaExecutorIntel} the runtime of all heuristics are nearly identical to each other.
    8441016
    8451017\begin{figure}
     
    8561028\end{figure}
    8571029
    858 The repeat microbenchmark also evaluates the executor. 
    859 It stresses the executor's ability to withstand contention on queues, as it repeatedly fans out messages from a single client to 100000 servers who then all respond to the client. 
    860 After this scatter and gather repeats 200 times the benchmark terminates. 
    861 The messages from the servers to the client will likely all come in on the same queue, resulting in high contention. 
    862 As such this benchmark will not scale with the number of processors, since more processors will result in higher contention. 
    863 In Figure~\ref{f:RepeatAMD} we can see that \CFA performs well compared to \uC, however by less of a margin than the executor benchmark. 
    864 One factor in this result is that the contention on the queues poses a significant bottleneck. 
     1030The repeat microbenchmark also evaluates the executor.
     1031It stresses the executor's ability to withstand contention on queues, as it repeatedly fans out messages from a single client to 100000 servers who then all respond to the client.
     1032After this scatter and gather repeats 200 times the benchmark terminates.
     1033The messages from the servers to the client will likely all come in on the same queue, resulting in high contention.
     1034As such this benchmark will not scale with the number of processors, since more processors will result in higher contention.
     1035In Figure~\ref{f:RepeatAMD} we can see that \CFA performs well compared to \uC, however by less of a margin than the executor benchmark.
     1036One factor in this result is that the contention on the queues poses a significant bottleneck.
    8651037As such the gains from using the copy queue are much less apparent.
    8661038
     
    8791051
    8801052In Figure~\ref{f:RepeatIntel} \uC and \CFA are very comparable.
    881 In comparison with the other systems \uC does well on the repeat benchmark since it does not have work stealing. 
    882 The client of this experiment is long running and maintains a lot of state, as it needs to know the handles of all the servers. 
    883 When stealing the client or its respective queue (in \CFA's inverted model), moving the client incurs a high cost due to cache invalidation. 
    884 As such stealing the client can result in a hit in performance. 
     1053In comparison with the other systems \uC does well on the repeat benchmark since it does not have work stealing.
     1054The client of this experiment is long running and maintains a lot of state, as it needs to know the handles of all the servers.
     1055When stealing the client or its respective queue (in \CFA's inverted model), moving the client incurs a high cost due to cache invalidation.
     1056As such stealing the client can result in a hit in performance.
    8851057
    8861058This result is shown in Figure~\ref{f:cfaRepeatAMD} and \ref{f:cfaRepeatIntel} where the no-stealing version of \CFA performs better than both stealing variations.
    887 In particular on the Intel machine in Figure~\ref{f:cfaRepeatIntel}, the cost of stealing is higher, which can be seen in the vertical shift of Akka, CAF and CFA results in Figure~\ref{f:RepeatIntel} (\uC and ProtoActor do not have work stealing). 
     1059In particular on the Intel machine in Figure~\ref{f:cfaRepeatIntel}, the cost of stealing is higher, which can be seen in the vertical shift of Akka, CAF and CFA results in Figure~\ref{f:RepeatIntel} (\uC and ProtoActor do not have work stealing).
    8881060The shift for CAF is particularly large, which further supports the hypothesis that CAF's work stealing is particularly eager.
    889 In both the executor and the repeat benchmark CAF performs poorly. 
    890 It is hypothesized that CAF has an aggressive work stealing algorithm, that eagerly attempts to steal. 
    891 This results in poor performance in benchmarks with small messages containing little work per message. 
    892 On the other hand, in \ref{f:MatrixAMD} CAF performs much better since each message has a large amount of work, and few messages are sent, so the eager work stealing allows for the clean up of loose ends to occur faster. 
    893 This hypothesis stems from experimentation with \CFA. 
    894 CAF uses a randomized work stealing heuristic. 
     1061In both the executor and the repeat benchmark CAF performs poorly.
     1062It is hypothesized that CAF has an aggressive work stealing algorithm, that eagerly attempts to steal.
     1063This results in poor performance in benchmarks with small messages containing little work per message.
     1064On the other hand, in \ref{f:MatrixAMD} CAF performs much better since each message has a large amount of work, and few messages are sent, so the eager work stealing allows for the clean up of loose ends to occur faster.
     1065This hypothesis stems from experimentation with \CFA.
     1066CAF uses a randomized work stealing heuristic.
    8951067In \CFA if the system is tuned so that it steals work much more eagerly with a randomized it was able to replicate the results that CAF achieves in the matrix benchmark, but this tuning performed much worse on all other microbenchmarks that we present, since they all perform a small amount of work per message.
    8961068
     
    8991071        \setlength{\extrarowheight}{2pt}
    9001072        \setlength{\tabcolsep}{5pt}
    901        
     1073
    9021074        \caption{Executor Program Memory High Watermark}
    9031075        \label{t:ExecutorMemory}
    9041076        \begin{tabular}{*{5}{r|}r}
    9051077                & \multicolumn{1}{c|}{\CFA} & \multicolumn{1}{c|}{CAF} & \multicolumn{1}{c|}{Akka} & \multicolumn{1}{c|}{\uC} & \multicolumn{1}{c@{}}{ProtoActor} \\
    906                 \hline                                                                                                                                                 
     1078                \hline
    9071079                AMD             & \input{data/pykeExecutorMem} \\
    908                 \hline                                                                                                                                                 
     1080                \hline
    9091081                Intel   & \input{data/nasusExecutorMem}
    9101082        \end{tabular}
    9111083\end{table}
    9121084
    913 Figure~\ref{t:ExecutorMemory} shows the high memory watermark of the actor systems when running the executor benchmark on 48 cores. 
    914 \CFA has a high watermark relative to the other non-garbage collected systems \uC, and CAF. 
    915 This is a result of the copy queue data structure, as it will overallocate storage and not clean up eagerly, whereas the per envelope allocations will always allocate exactly the amount of storage needed.
     1085Figure~\ref{t:ExecutorMemory} shows the high memory watermark of the actor systems when running the executor benchmark on 48 cores.
     1086\CFA has a high watermark relative to the other non-garbage collected systems \uC, and CAF.
     1087This is a result of the copy queue data structure, as it will over-allocate storage and not clean up eagerly, whereas the per envelope allocations will always allocate exactly the amount of storage needed.
    9161088
    9171089\subsection{Matrix Multiply}
    918 The matrix benchmark evaluates the actor systems in a practical application, where actors concurrently multiplies two matrices. 
     1090The matrix benchmark evaluates the actor systems in a practical application, where actors concurrently multiplies two matrices.
    9191091The majority of the computation in this benchmark involves computing the final matrix, so this benchmark stresses the actor systems' ability to have actors run work, rather than stressing the executor or message sending system.
    9201092
     
    9241096\end{displaymath}
    9251097
    926 The benchmark uses input matrices $X$ and $Y$ that are both $3072$ by $3072$ in size. 
    927 An actor is made for each row of $X$ and is passed via message the information needed to calculate a row of the result matrix $Z$. 
    928 
    929 
    930 Given that the bottleneck of the benchmark is the computation of the result matrix, it follows that the results in Figures~\ref{f:MatrixAMD} and \ref{f:MatrixIntel} are clustered closer than other experiments. 
    931 In Figure~\ref{f:MatrixAMD} \uC and \CFA have identical performance and in Figure~\ref{f:MatrixIntel} \uC pulls ahead og \CFA after 24 cores likely due to costs associated with work stealing while hyperthreading.
    932 As mentioned in \ref{s:executorPerf}, it is hypothesized that CAF performs better in this benchmark compared to others due to its eager work stealing implementation. 
     1098The benchmark uses input matrices $X$ and $Y$ that are both $3072$ by $3072$ in size.
     1099An actor is made for each row of $X$ and is passed via message the information needed to calculate a row of the result matrix $Z$.
     1100
     1101
     1102Given that the bottleneck of the benchmark is the computation of the result matrix, it follows that the results in Figures~\ref{f:MatrixAMD} and \ref{f:MatrixIntel} are clustered closer than other experiments.
     1103In Figure~\ref{f:MatrixAMD} \uC and \CFA have identical performance and in Figure~\ref{f:MatrixIntel} \uC pulls ahead of \CFA after 24 cores likely due to costs associated with work stealing while hyperthreading.
     1104As mentioned in \ref{s:executorPerf}, it is hypothesized that CAF performs better in this benchmark compared to others due to its eager work stealing implementation.
    9331105In Figures~\ref{f:cfaMatrixAMD} and \ref{f:cfaMatrixIntel} there is little negligible performance difference across \CFA stealing heuristics.
    9341106
  • doc/theses/colby_parsons_MMAth/text/mutex_stmt.tex

    rfa5e1aa5 rb7b3e41  
    415415\begin{figure}
    416416        \centering
     417    \captionsetup[subfloat]{labelfont=footnotesize,textfont=footnotesize}
    417418        \subfloat[AMD]{
    418419                \resizebox{0.5\textwidth}{!}{\input{figures/nasus_Aggregate_Lock_2.pgf}}
     
    421422                \resizebox{0.5\textwidth}{!}{\input{figures/pyke_Aggregate_Lock_2.pgf}}
    422423        }
     424    \bigskip
    423425
    424426        \subfloat[AMD]{
     
    428430                \resizebox{0.5\textwidth}{!}{\input{figures/pyke_Aggregate_Lock_4.pgf}}
    429431        }
     432    \bigskip
    430433
    431434        \subfloat[AMD]{
  • doc/theses/colby_parsons_MMAth/thesis.tex

    rfa5e1aa5 rb7b3e41  
    113113    citecolor=blue,         % color of links to bibliography
    114114    filecolor=magenta,      % color of file links
    115     urlcolor=cyan,          % color of external links
     115    urlcolor=blue,          % color of external links
    116116    breaklinks=true
    117117}
     
    124124    urlcolor=black}
    125125}{} % end of ifthenelse (no else)
     126\usepackage{breakurl}
     127\urlstyle{rm}
    126128
    127129% \usepackage[acronym]{glossaries}
  • doc/user/figures/EHMHierarchy.fig

    rfa5e1aa5 rb7b3e41  
    2929        1 1 1.00 60.00 90.00
    3030         4950 1950 4950 1725
    31 4 1 0 50 -1 0 13 0.0000 2 135 225 1950 1650 IO\001
    32 4 1 0 50 -1 0 13 0.0000 2 135 915 4950 1650 Arithmetic\001
    33 4 1 0 50 -1 0 13 0.0000 2 150 330 1350 2100 File\001
    34 4 1 0 50 -1 0 13 0.0000 2 135 735 2550 2100 Network\001
    35 4 1 0 50 -1 0 13 0.0000 2 180 1215 3750 2100 DivideByZero\001
    36 4 1 0 50 -1 0 13 0.0000 2 150 810 4950 2100 Overflow\001
    37 4 1 0 50 -1 0 13 0.0000 2 150 915 6000 2100 Underflow\001
    38 4 1 0 50 -1 0 13 0.0000 2 180 855 3450 1200 Exception\001
     314 1 0 50 -1 0 12 0.0000 2 135 225 1950 1650 IO\001
     324 1 0 50 -1 0 12 0.0000 2 135 915 4950 1650 Arithmetic\001
     334 1 0 50 -1 0 12 0.0000 2 150 330 1350 2100 File\001
     344 1 0 50 -1 0 12 0.0000 2 135 735 2550 2100 Network\001
     354 1 0 50 -1 0 12 0.0000 2 180 1215 3750 2100 DivideByZero\001
     364 1 0 50 -1 0 12 0.0000 2 150 810 4950 2100 Overflow\001
     374 1 0 50 -1 0 12 0.0000 2 150 915 6000 2100 Underflow\001
     384 1 0 50 -1 0 12 0.0000 2 180 855 3450 1200 Exception\001
  • doc/user/user.tex

    rfa5e1aa5 rb7b3e41  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Aug 22 23:43:30 2022
    14 %% Update Count     : 5503
     13%% Last Modified On : Mon Jun  5 21:18:29 2023
     14%% Update Count     : 5521
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    108108\huge \CFA Team (past and present) \medskip \\
    109109\Large Andrew Beach, Richard Bilson, Michael Brooks, Peter A. Buhr, Thierry Delisle, \smallskip \\
    110 \Large Glen Ditchfield, Rodolfo G. Esteves, Aaron Moss, Colby Parsons, Rob Schluntz, \smallskip \\
    111 \Large Fangren Yu, Mubeen Zulfiqar
     110\Large Glen Ditchfield, Rodolfo G. Esteves, Jiada Liang, Aaron Moss, Colby Parsons \smallskip \\
     111\Large Rob Schluntz, Fangren Yu, Mubeen Zulfiqar
    112112}% author
    113113
     
    169169Like \Index*[C++]{\CC{}}, there may be both old and new ways to achieve the same effect.
    170170For example, the following programs compare the C, \CFA, and \CC I/O mechanisms, where the programs output the same result.
    171 \begin{flushleft}
    172 \begin{tabular}{@{}l@{\hspace{1em}}l@{\hspace{1em}}l@{}}
    173 \multicolumn{1}{@{}c@{\hspace{1em}}}{\textbf{C}}        & \multicolumn{1}{c}{\textbf{\CFA}}     & \multicolumn{1}{c@{}}{\textbf{\CC}}   \\
     171\begin{center}
     172\begin{tabular}{@{}lll@{}}
     173\multicolumn{1}{@{}c}{\textbf{C}}       & \multicolumn{1}{c}{\textbf{\CFA}}     & \multicolumn{1}{c@{}}{\textbf{\CC}}   \\
    174174\begin{cfa}[tabsize=3]
    175175#include <stdio.h>$\indexc{stdio.h}$
     
    199199\end{cfa}
    200200\end{tabular}
    201 \end{flushleft}
     201\end{center}
    202202While \CFA I/O \see{\VRef{s:StreamIOLibrary}} looks similar to \Index*[C++]{\CC{}}, there are important differences, such as automatic spacing between variables and an implicit newline at the end of the expression list, similar to \Index*{Python}~\cite{Python}.
    203203
     
    856856still works.
    857857Nevertheless, reversing the default action would have a non-trivial effect on case actions that compound, such as the above example of processing shell arguments.
    858 Therefore, to preserve backwards compatibility, it is necessary to introduce a new kind of ©switch© statement, called \Indexc{choose}, with no implicit fall-through semantics and an explicit fall-through if the last statement of a case-clause ends with the new keyword \Indexc{fallthrough}/\Indexc{fallthru}, \eg:
     858Therefore, to preserve backwards compatibility, it is necessary to introduce a new kind of ©switch© statement, called \Indexc{choose}, with no implicit fall-through semantics and an explicit fall-through if the last statement of a case-clause ends with the new keyword \Indexc{fallthrough}/\-\Indexc{fallthru}, \eg:
    859859\begin{cfa}
    860860®choose® ( i ) {
     
    11671167\end{cfa}
    11681168\end{itemize}
    1169 \R{Warning}: specifying the down-to range maybe unexcepted because the loop control \emph{implicitly} switches the L and H values (and toggles the increment/decrement for I):
     1169\R{Warning}: specifying the down-to range maybe unexpected because the loop control \emph{implicitly} switches the L and H values (and toggles the increment/decrement for I):
    11701170\begin{cfa}
    11711171for ( i; 1 ~ 10 )       ${\C[1.5in]{// up range}$
     
    11731173for ( i; ®10 -~ 1® )    ${\C{// \R{WRONG down range!}}\CRT}$
    11741174\end{cfa}
    1175 The reason for this sematics is that the range direction can be toggled by adding/removing the minus, ©'-'©, versus interchanging the L and H expressions, which has a greater chance of introducing errors.
     1175The reason for this semantics is that the range direction can be toggled by adding/removing the minus, ©'-'©, versus interchanging the L and H expressions, which has a greater chance of introducing errors.
    11761176
    11771177
     
    22562256Days days = Mon; // enumeration type declaration and initialization
    22572257\end{cfa}
    2258 The set of enums are injected into the variable namespace at the definition scope.
    2259 Hence, enums may be overloaded with enum/variable/function names.
    2260 \begin{cfa}
     2258The set of enums is injected into the variable namespace at the definition scope.
     2259Hence, enums may be overloaded with variable, enum, and function names.
     2260\begin{cfa}
     2261int Foo;                        $\C{// type/variable separate namespaces}$
    22612262enum Foo { Bar };
    22622263enum Goo { Bar };       $\C[1.75in]{// overload Foo.Bar}$
    2263 int Foo;                        $\C{// type/variable separate namespace}$
    22642264double Bar;                     $\C{// overload Foo.Bar, Goo.Bar}\CRT$
    22652265\end{cfa}
     
    23012301Hence, the value of enum ©Mon© is 0, ©Tue© is 1, ...\,, ©Sun© is 6.
    23022302If an enum value is specified, numbering continues by one from that value for subsequent unnumbered enums.
    2303 If an enum value is an expression, the compiler performs constant-folding to obtain a constant value.
     2303If an enum value is a \emph{constant} expression, the compiler performs constant-folding to obtain a constant value.
    23042304
    23052305\CFA allows other integral types with associated values.
     
    23132313\begin{cfa}
    23142314// non-integral numeric
    2315 enum( ®double® ) Math { PI_2 = 1.570796, PI = 3.141597,  E = 2.718282 }
     2315enum( ®double® ) Math { PI_2 = 1.570796, PI = 3.141597, E = 2.718282 }
    23162316// pointer
    2317 enum( ®char *® ) Name { Fred = "Fred",  Mary = "Mary",  Jane = "Jane" };
     2317enum( ®char *® ) Name { Fred = "Fred",  Mary = "Mary", Jane = "Jane" };
    23182318int i, j, k;
    23192319enum( ®int *® ) ptr { I = &i,  J = &j,  K = &k };
    2320 enum( ®int &® ) ref { I = i,  J = j,  K = k };
     2320enum( ®int &® ) ref { I = i,   J = j,   K = k };
    23212321// tuple
    23222322enum( ®[int, int]® ) { T = [ 1, 2 ] };
     
    23612361\begin{cfa}
    23622362enum( char * ) Name2 { ®inline Name®, Jack = "Jack", Jill = "Jill" };
    2363 enum ®/* inferred */®  Name3 { ®inline Name2®, Sue = "Sue", Tom = "Tom" };
     2363enum ®/* inferred */® Name3 { ®inline Name2®, Sue = "Sue", Tom = "Tom" };
    23642364\end{cfa}
    23652365Enumeration ©Name2© inherits all the enums and their values from enumeration ©Name© by containment, and a ©Name© enumeration is a subtype of enumeration ©Name2©.
     
    38183818                                   "[ output-file (default stdout) ] ]";
    38193819                } // choose
    3820         } catch( ®Open_Failure® * ex; ex->istream == &in ) {
     3820        } catch( ®open_failure® * ex; ex->istream == &in ) { $\C{// input file errors}$
    38213821                ®exit® | "Unable to open input file" | argv[1];
    3822         } catch( ®Open_Failure® * ex; ex->ostream == &out ) {
     3822        } catch( ®open_failure® * ex; ex->ostream == &out ) { $\C{// output file errors}$
    38233823                ®close®( in );                                          $\C{// optional}$
    38243824                ®exit® | "Unable to open output file" | argv[2];
     
    40384038
    40394039\item
    4040 \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} toggle printing the separator.
     4040\Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} globally toggle printing the separator.
    40414041\begin{cfa}[belowskip=0pt]
    40424042sout | sepDisable | 1 | 2 | 3; $\C{// turn off implicit separator}$
     
    40534053
    40544054\item
    4055 \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} toggle printing the separator with respect to the next printed item, and then return to the global separator setting.
     4055\Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} locally toggle printing the separator with respect to the next printed item, and then return to the global separator setting.
    40564056\begin{cfa}[belowskip=0pt]
    40574057sout | 1 | sepOff | 2 | 3; $\C{// turn off implicit separator for the next item}$
     
    412941296
    41304130\end{cfa}
    4131 Note, a terminating ©nl© is merged (overrides) with the implicit newline at the end of the ©sout© expression, otherwise it is impossible to to print a single newline
     4131Note, a terminating ©nl© is merged (overrides) with the implicit newline at the end of the ©sout© expression, otherwise it is impossible to print a single newline
    41324132\item
    41334133\Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} implicitly prints a newline at the end of each output expression.
  • driver/cc1.cc

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Fri Aug 26 14:23:51 2005
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 17 18:04:23 2022
    13 // Update Count     : 422
     12// Last Modified On : Fri Jun  9 11:36:44 2023
     13// Update Count     : 423
    1414//
    1515
     
    385385                                // strip inappropriate flags with an argument
    386386
    387                         } else if ( arg == "-auxbase" || arg == "-auxbase-strip" || arg == "-dumpbase" || arg == "-dumpdir" ) {
     387                        } else if ( arg == "-auxbase" || arg == "-auxbase-strip" ||
     388                                                arg == "-dumpbase" || arg == "-dumpbase-ext" || arg == "-dumpdir" ) {
    388389                                i += 1;
    389390                                #ifdef __DEBUG_H__
  • driver/cfa.cc

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 30 10:47:52 2023
    13 // Update Count     : 478
     12// Last Modified On : Fri Jun  9 14:36:41 2023
     13// Update Count     : 479
    1414//
    1515
     
    334334        #ifdef __ARM_ARCH
    335335        args[nargs++] = "-mno-outline-atomics";                         // use ARM LL/SC instructions for atomics
     336        // args[nargs++] = "-march=armv8.2-a+lse";                              // use atomic instructions
    336337        #endif // __ARM_ARCH
    337338
  • libcfa/prelude/builtins.c

    rfa5e1aa5 rb7b3e41  
    149149
    150150static inline {
    151         long int ?\?( int x, unsigned int y ) { __CFA_EXP__(); }
     151        int ?\?( int x, unsigned int y ) { __CFA_EXP__(); }
    152152        long int ?\?( long int x, unsigned long int y ) { __CFA_EXP__(); }
    153153        long long int ?\?( long long int x, unsigned long long int y ) { __CFA_EXP__(); }
    154154        // unsigned computation may be faster and larger
    155         unsigned long int ?\?( unsigned int x, unsigned int y ) { __CFA_EXP__(); }
     155        unsigned int ?\?( unsigned int x, unsigned int y ) { __CFA_EXP__(); }
    156156        unsigned long int ?\?( unsigned long int x, unsigned long int y ) { __CFA_EXP__(); }
    157157        unsigned long long int ?\?( unsigned long long int x, unsigned long long int y ) { __CFA_EXP__(); }
     
    176176
    177177static inline {
    178         long int ?\=?( int & x, unsigned int y ) { x = x \ y; return x; }
     178        int ?\=?( int & x, unsigned int y ) { x = x \ y; return x; }
    179179        long int ?\=?( long int & x, unsigned long int y ) { x = x \ y; return x; }
    180180        long long int ?\=?( long long int & x, unsigned long long int y ) { x = x \ y; return x; }
    181         unsigned long int ?\=?( unsigned int & x, unsigned int y ) { x = x \ y; return x; }
     181        unsigned int ?\=?( unsigned int & x, unsigned int y ) { x = x \ y; return x; }
    182182        unsigned long int ?\=?( unsigned long int & x, unsigned long int y ) { x = x \ y; return x; }
    183183        unsigned long long int ?\=?( unsigned long long int & x, unsigned long long int y ) { x = x \ y; return x; }
  • libcfa/prelude/sync-builtins.cf

    rfa5e1aa5 rb7b3e41  
    206206_Bool __sync_bool_compare_and_swap(volatile unsigned __int128 *, unsigned __int128, unsigned __int128,...);
    207207#endif
     208// for all pointer types
    208209forall(T &) _Bool __sync_bool_compare_and_swap(T * volatile *, T *, T*, ...);
    209210
     
    223224unsigned __int128 __sync_val_compare_and_swap(volatile unsigned __int128 *, unsigned __int128, unsigned __int128,...);
    224225#endif
     226// for all pointer types
    225227forall(T &) T * __sync_val_compare_and_swap(T * volatile *, T *, T*,...);
    226228
     
    326328void __atomic_exchange(volatile unsigned __int128 *, unsigned __int128 *, unsigned __int128 *, int);
    327329#endif
     330// for all pointer types
    328331forall(T &) T * __atomic_exchange_n(T * volatile *, T *, int);
    329332forall(T &) void __atomic_exchange(T * volatile *, T **, T **, int);
     
    359362void __atomic_load(const volatile unsigned __int128 *, unsigned __int128 *, int);
    360363#endif
     364// for all pointer types
    361365forall(T &) T * __atomic_load_n(T * const volatile *, int);
    362366forall(T &) void __atomic_load(T * const volatile *, T **, int);
     
    390394_Bool __atomic_compare_exchange   (volatile unsigned __int128 *, unsigned __int128 *, unsigned __int128 *, _Bool, int, int);
    391395#endif
     396// for all pointer types
    392397forall(T &) _Bool __atomic_compare_exchange_n (T * volatile *, T **, T*, _Bool, int, int);
    393398forall(T &) _Bool __atomic_compare_exchange   (T * volatile *, T **, T**, _Bool, int, int);
     
    423428void __atomic_store(volatile unsigned __int128 *, unsigned __int128 *, int);
    424429#endif
     430// for all pointer types
    425431forall(T &) void __atomic_store_n(T * volatile *, T *, int);
    426432forall(T &) void __atomic_store(T * volatile *, T **, int);
  • libcfa/src/common.hfa

    rfa5e1aa5 rb7b3e41  
    3232} // extern "C"
    3333static inline __attribute__((always_inline)) {
    34         unsigned char abs( signed char v ) { return abs( (int)v ); }
     34        unsigned char abs( signed char v ) { return (int)abs( (int)v ); }
    3535        // use default C routine for int
    3636        unsigned long int abs( long int v ) { return labs( v ); }
     
    7070        unsigned int min( unsigned int v1, unsigned int v2 ) { return v1 < v2 ? v1 : v2; }
    7171        long int min( long int v1, long int v2 ) { return v1 < v2 ? v1 : v2; }
    72         unsigned long int min( unsigned long int v1, unsigned int v2 ) { return v1 < v2 ? v1 : v2; }
     72        unsigned long int min( unsigned long int v1, unsigned long int v2 ) { return v1 < v2 ? v1 : v2; }
    7373        long long int min( long long int v1, long long int v2 ) { return v1 < v2 ? v1 : v2; }
    74         unsigned long long int min( unsigned long long int v1, unsigned int v2 ) { return v1 < v2 ? v1 : v2; }
     74        unsigned long long int min( unsigned long long int v1, unsigned long long int v2 ) { return v1 < v2 ? v1 : v2; }
    7575        forall( T | { int ?<?( T, T ); } )                                      // generic
    7676        T min( T v1, T v2 ) { return v1 < v2 ? v1 : v2; }
  • libcfa/src/concurrency/actor.hfa

    rfa5e1aa5 rb7b3e41  
    1313#endif // CFA_DEBUG
    1414
     15#define DEBUG_ABORT( cond, string ) CFA_DEBUG( if ( cond ) abort( string ) )
     16
    1517// Define the default number of processors created in the executor. Must be greater than 0.
    1618#define __DEFAULT_EXECUTOR_PROCESSORS__ 2
     
    2830#define __DEFAULT_EXECUTOR_BUFSIZE__ 10
    2931
    30 #define __STEAL 0 // workstealing toggle. Disjoint from toggles above
     32#define __STEAL 1 // workstealing toggle. Disjoint from toggles above
    3133
    3234// workstealing heuristic selection (only set one to be 1)
     
    4244struct executor;
    4345
    44 enum Allocation { Nodelete, Delete, Destroy, Finished }; // allocation status
    45 
    46 typedef Allocation (*__receive_fn)(actor &, message &);
     46enum allocation { Nodelete, Delete, Destroy, Finished }; // allocation status
     47
     48typedef allocation (*__receive_fn)(actor &, message &);
    4749struct request {
     50    actor * base_receiver;
    4851    actor * receiver;
     52    message * base_msg;
    4953    message * msg;
    5054    __receive_fn fn;
    51     bool stop;
    5255};
    5356
    54 static inline void ?{}( request & this ) { this.stop = true; } // default ctor makes a sentinel
    55 static inline void ?{}( request & this, actor * receiver, message * msg, __receive_fn fn ) {
     57struct a_msg {
     58    int m;
     59};
     60static inline void ?{}( request & this ) {}
     61static inline void ?{}( request & this, actor * base_receiver, actor * receiver, message * base_msg, message * msg, __receive_fn fn ) {
     62    this.base_receiver = base_receiver;
    5663    this.receiver = receiver;
     64    this.base_msg = base_msg;
    5765    this.msg = msg;
    5866    this.fn = fn;
    59     this.stop = false;
    6067}
    6168static inline void ?{}( request & this, request & copy ) {
     
    6370    this.msg = copy.msg;
    6471    this.fn = copy.fn;
    65     this.stop = copy.stop;
    6672}
    6773
     
    8187    last_size = 0;
    8288}
    83 static inline void ^?{}( copy_queue & this ) with(this) { adelete(buffer); }
     89static inline void ^?{}( copy_queue & this ) with(this) {
     90    DEBUG_ABORT( count != 0, "Actor system terminated with messages sent but not received\n" );
     91    adelete(buffer);
     92}
    8493
    8594static inline void insert( copy_queue & this, request & elem ) with(this) {
     
    115124}
    116125
    117 static inline bool isEmpty( copy_queue & this ) with(this) { return count == 0; }
     126static inline bool is_empty( copy_queue & this ) with(this) { return count == 0; }
    118127
    119128struct work_queue {
     
    176185    volatile unsigned long long stamp;
    177186    #ifdef ACTOR_STATS
    178     size_t stolen_from, try_steal, stolen, failed_swaps, msgs_stolen;
     187    size_t stolen_from, try_steal, stolen, empty_stolen, failed_swaps, msgs_stolen;
    179188    unsigned long long processed;
    180189    size_t gulps;
     
    189198    this.gulps = 0;                                 // number of gulps
    190199    this.failed_swaps = 0;                          // steal swap failures
     200    this.empty_stolen = 0;                          // queues empty after steal
    191201    this.msgs_stolen = 0;                           // number of messages stolen
    192202    #endif
     
    208218#ifdef ACTOR_STATS
    209219// aggregate counters for statistics
    210 size_t __total_tries = 0, __total_stolen = 0, __total_workers, __all_gulps = 0,
     220size_t __total_tries = 0, __total_stolen = 0, __total_workers, __all_gulps = 0, __total_empty_stolen = 0,
    211221    __total_failed_swaps = 0, __all_processed = 0, __num_actors_stats = 0, __all_msgs_stolen = 0;
    212222#endif
     
    233243        unsigned int nprocessors, nworkers, nrqueues;   // number of processors/threads/request queues
    234244        bool seperate_clus;                                                             // use same or separate cluster for executor
     245    volatile bool is_shutdown;                      // flag to communicate shutdown to worker threads
    235246}; // executor
    236247
     
    246257    __atomic_add_fetch(&__total_stolen, executor_->w_infos[id].stolen, __ATOMIC_SEQ_CST);
    247258    __atomic_add_fetch(&__total_failed_swaps, executor_->w_infos[id].failed_swaps, __ATOMIC_SEQ_CST);
     259    __atomic_add_fetch(&__total_empty_stolen, executor_->w_infos[id].empty_stolen, __ATOMIC_SEQ_CST);
    248260
    249261    // per worker steal stats (uncomment alongside the lock above this routine to print)
     
    272284    this.nrqueues = nrqueues;
    273285    this.seperate_clus = seperate_clus;
     286    this.is_shutdown = false;
    274287
    275288    if ( nworkers == nrqueues )
     
    320333
    321334static inline void ^?{}( executor & this ) with(this) {
    322     #ifdef __STEAL
    323     request sentinels[nrqueues];
    324     for ( unsigned int i = 0; i < nrqueues; i++ ) {
    325         insert( request_queues[i], sentinels[i] );              // force eventually termination
    326     } // for
    327     #else
    328     request sentinels[nworkers];
    329     unsigned int reqPerWorker = nrqueues / nworkers, extras = nrqueues % nworkers;
    330     for ( unsigned int i = 0, step = 0, range; i < nworkers; i += 1, step += range ) {
    331         range = reqPerWorker + ( i < extras ? 1 : 0 );
    332         insert( request_queues[step], sentinels[i] );           // force eventually termination
    333     } // for
    334     #endif
     335    is_shutdown = true;
    335336
    336337    for ( i; nworkers )
     
    363364    size_t avg_gulps = __all_gulps == 0 ? 0 : __all_processed / __all_gulps;
    364365    printf("\tGulps:\t\t\t\t\t%lu\n\tAverage Gulp Size:\t\t\t%lu\n\tMissed gulps:\t\t\t\t%lu\n", __all_gulps, avg_gulps, misses);
    365     printf("\tSteal attempts:\t\t\t\t%lu\n\tSteals:\t\t\t\t\t%lu\n\tSteal failures (no candidates):\t\t%lu\n\tSteal failures (failed swaps):\t\t%lu\n",
    366         __total_tries, __total_stolen, __total_tries - __total_stolen - __total_failed_swaps, __total_failed_swaps);
     366    printf("\tSteal attempts:\t\t\t\t%lu\n\tSteals:\t\t\t\t\t%lu\n\tSteal failures (no candidates):\t\t%lu\n\tSteal failures (failed swaps):\t\t%lu\t Empty steals:\t\t%lu\n",
     367        __total_tries, __total_stolen, __total_tries - __total_stolen - __total_failed_swaps, __total_failed_swaps, __total_empty_stolen);
    367368    size_t avg_steal = __total_stolen == 0 ? 0 : __all_msgs_stolen / __total_stolen;
    368369    printf("\tMessages stolen:\t\t\t%lu\n\tAverage steal size:\t\t\t%lu\n", __all_msgs_stolen, avg_steal);
     
    393394struct actor {
    394395    size_t ticket;                                          // executor-queue handle
    395     Allocation allocation_;                                         // allocation action
     396    allocation allocation_;                                         // allocation action
    396397    inline virtual_dtor;
    397398};
     
    400401    // Once an actor is allocated it must be sent a message or the actor system cannot stop. Hence, its receive
    401402    // member must be called to end it
    402     verifyf( __actor_executor_, "Creating actor before calling start_actor_system() can cause undefined behaviour.\n" );
     403    DEBUG_ABORT( __actor_executor_ == 0p, "Creating actor before calling start_actor_system() can cause undefined behaviour.\n" );
    403404    allocation_ = Nodelete;
    404405    ticket = __get_next_ticket( *__actor_executor_ );
     
    430431
    431432struct message {
    432     Allocation allocation_;                     // allocation action
     433    allocation allocation_;                     // allocation action
    433434    inline virtual_dtor;
    434435};
     
    437438    this.allocation_ = Nodelete;
    438439}
    439 static inline void ?{}( message & this, Allocation allocation ) {
    440     memcpy( &this.allocation_, &allocation, sizeof(allocation) ); // optimization to elide ctor
    441     verifyf( this.allocation_ != Finished, "The Finished Allocation status is not supported for message types.\n");
     440static inline void ?{}( message & this, allocation alloc ) {
     441    memcpy( &this.allocation_, &alloc, sizeof(allocation) ); // optimization to elide ctor
     442    DEBUG_ABORT( this.allocation_ == Finished, "The Finished allocation status is not supported for message types.\n" );
    442443}
    443444static inline void ^?{}( message & this ) with(this) {
     
    447448static inline void check_message( message & this ) {
    448449    switch ( this.allocation_ ) {                                               // analyze message status
    449         case Nodelete: CFA_DEBUG(this.allocation_ = Finished); break;
     450        case Nodelete: CFA_DEBUG( this.allocation_ = Finished ); break;
    450451        case Delete: delete( &this ); break;
    451         case Destroy: ^?{}(this); break;
     452        case Destroy: ^?{}( this ); break;
    452453        case Finished: break;
    453454    } // switch
    454455}
    455 static inline void set_allocation( message & this, Allocation state ) {
     456static inline void set_allocation( message & this, allocation state ) {
    456457    this.allocation_ = state;
    457458}
    458459
    459460static inline void deliver_request( request & this ) {
    460     this.receiver->allocation_ = this.fn( *this.receiver, *this.msg );
    461     check_message( *this.msg );
    462     check_actor( *this.receiver );
     461    DEBUG_ABORT( this.receiver->ticket == (unsigned long int)MAX, "Attempted to send message to deleted/dead actor\n" );
     462    this.base_receiver->allocation_ = this.fn( *this.receiver, *this.msg );
     463    check_message( *this.base_msg );
     464    check_actor( *this.base_receiver );
    463465}
    464466
     
    510512        curr_steal_queue = request_queues[ i + vic_start ];
    511513        // avoid empty queues and queues that are being operated on
    512         if ( curr_steal_queue == 0p || curr_steal_queue->being_processed || isEmpty( *curr_steal_queue->c_queue ) )
     514        if ( curr_steal_queue == 0p || curr_steal_queue->being_processed || is_empty( *curr_steal_queue->c_queue ) )
    513515            continue;
    514516
     
    518520            executor_->w_infos[id].msgs_stolen += curr_steal_queue->c_queue->count;
    519521            executor_->w_infos[id].stolen++;
     522            if ( is_empty( *curr_steal_queue->c_queue ) ) executor_->w_infos[id].empty_stolen++;
    520523            // __atomic_add_fetch(&executor_->w_infos[victim_id].stolen_from, 1, __ATOMIC_RELAXED);
    521524            // replaced_queue[swap_idx]++;
     
    557560}
    558561
     562#define CHECK_TERMINATION if ( unlikely( executor_->is_shutdown ) ) break Exit
    559563void main( worker & this ) with(this) {
    560564    // #ifdef ACTOR_STATS
     
    578582       
    579583        // check if queue is empty before trying to gulp it
    580         if ( isEmpty( *curr_work_queue->c_queue ) ) {
     584        if ( is_empty( *curr_work_queue->c_queue ) ) {
    581585            #ifdef __STEAL
    582586            empty_count++;
     
    591595        #endif // ACTOR_STATS
    592596        #ifdef __STEAL
    593         if ( isEmpty( *current_queue ) ) {
    594             if ( unlikely( no_steal ) ) continue;
     597        if ( is_empty( *current_queue ) ) {
     598            if ( unlikely( no_steal ) ) { CHECK_TERMINATION; continue; }
    595599            empty_count++;
    596600            if ( empty_count < steal_threshold ) continue;
    597601            empty_count = 0;
     602
     603            CHECK_TERMINATION; // check for termination
    598604
    599605            __atomic_store_n( &executor_->w_infos[id].stamp, rdtscl(), __ATOMIC_RELAXED );
     
    607613        }
    608614        #endif // __STEAL
    609         while ( ! isEmpty( *current_queue ) ) {
     615        while ( ! is_empty( *current_queue ) ) {
    610616            #ifdef ACTOR_STATS
    611617            executor_->w_infos[id].processed++;
     
    613619            &req = &remove( *current_queue );
    614620            if ( !&req ) continue;
    615             if ( req.stop ) break Exit;
    616621            deliver_request( req );
    617622        }
     
    631636
    632637static inline void send( actor & this, request & req ) {
    633     verifyf( this.ticket != (unsigned long int)MAX, "Attempted to send message to deleted/dead actor\n" );
     638    DEBUG_ABORT( this.ticket == (unsigned long int)MAX, "Attempted to send message to deleted/dead actor\n" );
    634639    send( *__actor_executor_, req, this.ticket );
    635640}
     
    641646    __all_gulps = 0;
    642647    __total_failed_swaps = 0;
     648    __total_empty_stolen = 0;
    643649    __all_processed = 0;
    644650    __num_actors_stats = 0;
     
    654660}
    655661
    656 // TODO: potentially revisit getting number of processors
    657 //  ( currently the value stored in active_cluster()->procs.total is often stale
    658 //  and doesn't reflect how many procs are allocated )
    659 // static inline void start_actor_system() { start_actor_system( active_cluster()->procs.total ); }
    660 static inline void start_actor_system() { start_actor_system( 1 ); }
     662static inline void start_actor_system() { start_actor_system( get_proc_count( *active_cluster() ) ); }
    661663
    662664static inline void start_actor_system( executor & this ) {
     
    668670
    669671static inline void stop_actor_system() {
    670     park( ); // will receive signal when actor system is finished
     672    park( ); // will be unparked when actor system is finished
    671673
    672674    if ( !__actor_executor_passed ) delete( __actor_executor_ );
     
    680682// assigned at creation to __base_msg_finished to avoid unused message warning
    681683message __base_msg_finished @= { .allocation_ : Finished };
    682 struct __DeleteMsg { inline message; } DeleteMsg = __base_msg_finished;
    683 struct __DestroyMsg { inline message; } DestroyMsg = __base_msg_finished;
    684 struct __FinishedMsg { inline message; } FinishedMsg = __base_msg_finished;
    685 
    686 Allocation receive( actor & this, __DeleteMsg & msg ) { return Delete; }
    687 Allocation receive( actor & this, __DestroyMsg & msg ) { return Destroy; }
    688 Allocation receive( actor & this, __FinishedMsg & msg ) { return Finished; }
    689 
     684struct __delete_msg_t { inline message; } delete_msg = __base_msg_finished;
     685struct __destroy_msg_t { inline message; } destroy_msg = __base_msg_finished;
     686struct __finished_msg_t { inline message; } finished_msg = __base_msg_finished;
     687
     688allocation receive( actor & this, __delete_msg_t & msg ) { return Delete; }
     689allocation receive( actor & this, __destroy_msg_t & msg ) { return Destroy; }
     690allocation receive( actor & this, __finished_msg_t & msg ) { return Finished; }
     691
  • libcfa/src/concurrency/atomic.hfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Thu May 25 15:22:46 2023
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 25 15:24:45 2023
    13 // Update Count     : 1
     12// Last Modified On : Wed Jun 14 07:48:57 2023
     13// Update Count     : 52
    1414//
    1515
    16 #define LOAD( lock ) (__atomic_load_n( &(lock), __ATOMIC_SEQ_CST ))
    17 #define LOADM( lock, memorder ) (__atomic_load_n( &(lock), memorder ))
    18 #define STORE( lock, assn ) (__atomic_store_n( &(lock), assn, __ATOMIC_SEQ_CST ))
    19 #define STOREM( lock, assn, memorder ) (__atomic_store_n( &(lock), assn, memorder ))
    20 #define CLR( lock ) (__atomic_clear( &(lock), __ATOMIC_RELEASE ))
    21 #define CLRM( lock, memorder ) (__atomic_clear( &(lock), memorder ))
    22 #define TAS( lock ) (__atomic_test_and_set( &(lock), __ATOMIC_ACQUIRE ))
    23 #define TASM( lock, memorder ) (__atomic_test_and_set( &(lock), memorder ))
    24 #define CAS( change, comp, assn ) ({typeof(comp) __temp = (comp); __atomic_compare_exchange_n( &(change), &(__temp), (assn), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ); })
    25 #define CASM( change, comp, assn, memorder... ) ({typeof(comp) * __temp = &(comp); __atomic_compare_exchange_n( &(change), &(__temp), (assn), false, memorder, memorder ); })
    26 #define CASV( change, comp, assn ) (__atomic_compare_exchange_n( &(change), &(comp), (assn), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ))
    27 #define CASVM( change, comp, assn, memorder... ) (__atomic_compare_exchange_n( &(change), &(comp), (assn), false, memorder, memorder ))
    28 #define FAS( change, assn ) (__atomic_exchange_n( &(change), (assn), __ATOMIC_SEQ_CST ))
    29 #define FASM( change, assn, memorder ) (__atomic_exchange_n( &(change), (assn), memorder ))
    30 #define FAI( change, Inc ) (__atomic_fetch_add( &(change), (Inc), __ATOMIC_SEQ_CST ))
    31 #define FAIM( change, Inc, memorder ) (__atomic_fetch_add( &(change), (Inc), memorder ))
     16#define LOAD( val ) (LOADM( val, __ATOMIC_SEQ_CST))
     17#define LOADM( val, memorder ) (__atomic_load_n( &(val), memorder))
     18
     19#define STORE( val, assn ) (STOREM( val, assn, __ATOMIC_SEQ_CST))
     20#define STOREM( val, assn, memorder ) (__atomic_store_n( &(val), assn, memorder))
     21
     22#define TAS( lock ) (TASM( lock, __ATOMIC_ACQUIRE))
     23#define TASM( lock, memorder ) (__atomic_test_and_set( &(lock), memorder))
     24
     25#define TASCLR( lock ) (TASCLRM( lock, __ATOMIC_RELEASE))
     26#define TASCLRM( lock, memorder ) (__atomic_clear( &(lock), memorder))
     27
     28#define FAS( assn, replace ) (FASM(assn, replace, __ATOMIC_SEQ_CST))
     29#define FASM( assn, replace, memorder ) (__atomic_exchange_n( &(assn), (replace), memorder))
     30
     31#define FAI( assn, Inc ) (__atomic_fetch_add( &(assn), (Inc), __ATOMIC_SEQ_CST))
     32#define FAIM( assn, Inc, memorder ) (__atomic_fetch_add( &(assn), (Inc), memorder))
     33
     34// Use __sync because __atomic with 128-bit CAA can result in calls to pthread_mutex_lock.
     35
     36// #define CAS( assn, comp, replace ) (CASM( assn, comp, replace, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
     37// #define CASM( assn, comp, replace, memorder... ) ({ typeof(comp) __temp = (comp); __atomic_compare_exchange_n( &(assn), &(__temp), (replace), false, memorder ); })
     38#define CAS( assn, comp, replace ) (__sync_bool_compare_and_swap( &assn, comp, replace))
     39#define CASM( assn, comp, replace, memorder... ) _Static_assert( false, "memory order unsupported for CAS macro" );
     40
     41// #define CASV( assn, comp, replace ) (__atomic_compare_exchange_n( &(assn), &(comp), (replace), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ))
     42// #define CASVM( assn, comp, replace, memorder... ) (__atomic_compare_exchange_n( &(assn), &(comp), (replace), false, memorder, memorder ))
     43#define CASV( assn, comp, replace ) ({ \
     44        typeof(comp) temp = comp; \
     45        typeof(comp) old = __sync_val_compare_and_swap( &(assn), (comp), (replace) ); \
     46        old == temp ? true : (comp = old, false); \
     47})
     48#define CASVM( assn, comp, replace, memorder... ) _Static_assert( false, "memory order unsupported for CASV macro" );
  • libcfa/src/concurrency/kernel.hfa

    rfa5e1aa5 rb7b3e41  
    195195        // Total number of processors
    196196        unsigned total;
     197
     198    // Number of processors constructed
     199    //  incremented at construction time, total is incremented once the processor asyncronously registers
     200        unsigned constructed;
    197201
    198202        // Total number of idle processors
     
    297301static inline struct cluster   * active_cluster  () { return publicTLS_get( this_processor )->cltr; }
    298302
     303// gets the number of constructed processors on the cluster
     304static inline unsigned get_proc_count( cluster & this ) { return this.procs.constructed; }
     305
    299306// set the number of internal processors
    300307// these processors are in addition to any explicitly declared processors
  • libcfa/src/concurrency/kernel/cluster.hfa

    rfa5e1aa5 rb7b3e41  
    4040
    4141// convert to log2 scale but using double
    42 static inline __readyQ_avg_t __to_readyQ_avg(unsigned long long intsc) { if(unlikely(0 == intsc)) return 0.0; else return log2(intsc); }
     42static inline __readyQ_avg_t __to_readyQ_avg(unsigned long long intsc) { if(unlikely(0 == intsc)) return 0.0; else return log2((__readyQ_avg_t)intsc); }
    4343
    4444#define warn_large_before warnf( !strict || old_avg < 35.0, "Suspiciously large previous average: %'lf, %'" PRId64 "ms \n", old_avg, program()`ms )
  • libcfa/src/concurrency/kernel/startup.cfa

    rfa5e1aa5 rb7b3e41  
    528528        this.name = name;
    529529        this.cltr = &_cltr;
     530    __atomic_add_fetch( &_cltr.procs.constructed, 1u, __ATOMIC_RELAXED );
    530531        this.rdq.its = 0;
    531532        this.rdq.itr = 0;
     
    595596        __cfadbg_print_safe(runtime_core, "Kernel : core %p signaling termination\n", &this);
    596597
     598    __atomic_sub_fetch( &this.cltr->procs.constructed, 1u, __ATOMIC_RELAXED );
     599
    597600        __atomic_store_n(&do_terminate, true, __ATOMIC_RELAXED);
    598601        __disable_interrupts_checked();
     
    615618        this.fdw   = 0p;
    616619        this.idle  = 0;
     620    this.constructed = 0;
    617621        this.total = 0;
    618622}
  • libcfa/src/concurrency/locks.hfa

    rfa5e1aa5 rb7b3e41  
    3232#include "select.hfa"
    3333
    34 #include <fstream.hfa>
    35 
    3634// futex headers
    3735#include <linux/futex.h>      /* Definition of FUTEX_* constants */
  • libcfa/src/containers/lockfree.hfa

    rfa5e1aa5 rb7b3e41  
    199199
    200200forall( T & )
     201struct LinkData {
     202        T * volatile top;                                                               // pointer to stack top
     203        uintptr_t count;                                                                // count each push
     204};
     205
     206forall( T & )
    201207union Link {
    202         struct {                                                                                        // 32/64-bit x 2
    203                 T * volatile top;                                                               // pointer to stack top
    204                 uintptr_t count;                                                                // count each push
    205         };
     208        LinkData(T) data;
    206209        #if __SIZEOF_INT128__ == 16
    207210        __int128                                                                                        // gcc, 128-bit integer
     
    220223                void ?{}( StackLF(T) & this ) with(this) { stack.atom = 0; }
    221224
    222                 T * top( StackLF(T) & this ) with(this) { return stack.top; }
     225                T * top( StackLF(T) & this ) with(this) { return stack.data.top; }
    223226
    224227                void push( StackLF(T) & this, T & n ) with(this) {
    225228                        *( &n )`next = stack;                                           // atomic assignment unnecessary, or use CAA
    226229                        for () {                                                                        // busy wait
    227                           if ( __atomic_compare_exchange_n( &stack.atom, &( &n )`next->atom, (Link(T))@{ {&n, ( &n )`next->count + 1} }.atom, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ) ) break; // attempt to update top node
     230                                if ( __atomic_compare_exchange_n( &stack.atom, &( &n )`next->atom, (Link(T))@{ (LinkData(T))@{ &n, ( &n )`next->data.count + 1} }.atom, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ) ) break; // attempt to update top node
    228231                        } // for
    229232                } // push
     
    232235                        Link(T) t @= stack;                                                     // atomic assignment unnecessary, or use CAA
    233236                        for () {                                                                        // busy wait
    234                           if ( t.top == 0p ) return 0p;                         // empty stack ?
    235                           if ( __atomic_compare_exchange_n( &stack.atom, &t.atom, (Link(T))@{ {( t.top )`next->top, t.count} }.atom, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ) ) return t.top; // attempt to update top node
     237                                if ( t.data.top == 0p ) return 0p;                              // empty stack ?
     238                                Link(T) * next = ( t.data.top )`next;
     239                                if ( __atomic_compare_exchange_n( &stack.atom, &t.atom, (Link(T))@{ (LinkData(T))@{ next->data.top, t.data.count } }.atom, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ) ) return t.data.top; // attempt to update top node
    236240                        } // for
    237241                } // pop
     
    239243                bool unsafe_remove( StackLF(T) & this, T * node ) with(this) {
    240244                        Link(T) * link = &stack;
    241                         for() {
    242                                 T * next = link->top;
    243                                 if( next == node ) {
    244                                         link->top = ( node )`next->top;
     245                        for () {
     246                                // TODO: Avoiding some problems with double fields access.
     247                                LinkData(T) * data = &link->data;
     248                                T * next = (T *)&(*data).top;
     249                                if ( next == node ) {
     250                                        data->top = ( node )`next->data.top;
    245251                                        return true;
    246252                                }
    247                                 if( next == 0p ) return false;
     253                                if ( next == 0p ) return false;
    248254                                link = ( next )`next;
    249255                        }
  • libcfa/src/fstream.cfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr  9 14:55:54 2022
    13 // Update Count     : 515
     12// Last Modified On : Sat Jun 17 08:51:12 2023
     13// Update Count     : 528
    1414//
    1515
     
    117117    } // for
    118118        if ( file == 0p ) {
    119                 throw (Open_Failure){ os };
     119                throw (open_failure){ os };
    120120                // abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno );
    121121        } // if
     
    137137    } // for
    138138        if ( ret == EOF ) {
    139                 throw (Close_Failure){ os };
     139                throw (close_failure){ os };
    140140                // abort | IO_MSG "close output" | nl | strerror( errno );
    141141        } // if
     
    145145ofstream & write( ofstream & os, const char data[], size_t size ) {
    146146        if ( fail( os ) ) {
    147                 throw (Write_Failure){ os };
     147                throw (write_failure){ os };
    148148                // abort | IO_MSG "attempt write I/O on failed stream";
    149149        } // if
    150150
    151151        if ( fwrite( data, 1, size, (FILE *)(os.file$) ) != size ) {
    152                 throw (Write_Failure){ os };
     152                throw (write_failure){ os };
    153153                // abort | IO_MSG "write" | nl | strerror( errno );
    154154        } // if
     
    169169          if ( cnt == 9 ) abort( "ofstream fmt EINTR spinning exceeded" );
    170170    } // for
    171         if ( len == EOF ) {
    172                 if ( ferror( (FILE *)(os.file$) ) ) {
    173                         abort | IO_MSG "invalid write";
    174                 } // if
     171        if ( len == EOF ) {                                                                     // error writing ?
     172                abort | IO_MSG "invalid write";
    175173        } // if
    176174        va_end( args );
     
    240238    } // for
    241239        if ( file == 0p ) {
    242                 throw (Open_Failure){ is };
     240                throw (open_failure){ is };
    243241                // abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno );
    244242        } // if
     
    260258    } // for
    261259        if ( ret == EOF ) {
    262                 throw (Close_Failure){ is };
     260                throw (close_failure){ is };
    263261                // abort | IO_MSG "close input" | nl | strerror( errno );
    264262        } // if
     
    268266ifstream & read( ifstream & is, char data[], size_t size ) {
    269267        if ( fail( is ) ) {
    270                 throw (Read_Failure){ is };
     268                throw (read_failure){ is };
    271269                // abort | IO_MSG "attempt read I/O on failed stream";
    272270        } // if
    273271
    274272        if ( fread( data, size, 1, (FILE *)(is.file$) ) == 0 ) {
    275                 throw (Read_Failure){ is };
     273                throw (read_failure){ is };
    276274                // abort | IO_MSG "read" | nl | strerror( errno );
    277275        } // if
     
    302300          if ( len != EOF || errno != EINTR ) break;            // timer interrupt ?
    303301    } // for
    304         if ( len == EOF ) {
    305                 if ( ferror( (FILE *)(is.file$) ) ) {
     302        if ( len == EOF ) {                                                                     // EOF or matching failure ?
     303                if ( ! feof( (FILE *)(is.file$) ) && ferror( (FILE *)(is.file$) ) ) {
    306304                        abort | IO_MSG "invalid read";
    307305                } // if
     
    318316
    319317
    320 static vtable(Open_Failure) Open_Failure_vt;
     318static vtable(open_failure) open_failure_vt;
    321319
    322320// exception I/O constructors
    323 void ?{}( Open_Failure & ex, ofstream & ostream ) with(ex) {
    324         virtual_table = &Open_Failure_vt;
     321void ?{}( open_failure & ex, ofstream & ostream ) with(ex) {
     322        virtual_table = &open_failure_vt;
    325323        ostream = &ostream;
    326324        tag = 1;
    327325} // ?{}
    328326
    329 void ?{}( Open_Failure & ex, ifstream & istream ) with(ex) {
    330         virtual_table = &Open_Failure_vt;
     327void ?{}( open_failure & ex, ifstream & istream ) with(ex) {
     328        virtual_table = &open_failure_vt;
    331329        istream = &istream;
    332330        tag = 0;
     
    334332
    335333
    336 static vtable(Close_Failure) Close_Failure_vt;
     334static vtable(close_failure) close_failure_vt;
    337335
    338336// exception I/O constructors
    339 void ?{}( Close_Failure & ex, ofstream & ostream ) with(ex) {
    340         virtual_table = &Close_Failure_vt;
     337void ?{}( close_failure & ex, ofstream & ostream ) with(ex) {
     338        virtual_table = &close_failure_vt;
    341339        ostream = &ostream;
    342340        tag = 1;
    343341} // ?{}
    344342
    345 void ?{}( Close_Failure & ex, ifstream & istream ) with(ex) {
    346         virtual_table = &Close_Failure_vt;
     343void ?{}( close_failure & ex, ifstream & istream ) with(ex) {
     344        virtual_table = &close_failure_vt;
    347345        istream = &istream;
    348346        tag = 0;
     
    350348
    351349
    352 static vtable(Write_Failure) Write_Failure_vt;
     350static vtable(write_failure) write_failure_vt;
    353351
    354352// exception I/O constructors
    355 void ?{}( Write_Failure & ex, ofstream & ostream ) with(ex) {
    356         virtual_table = &Write_Failure_vt;
     353void ?{}( write_failure & ex, ofstream & ostream ) with(ex) {
     354        virtual_table = &write_failure_vt;
    357355        ostream = &ostream;
    358356        tag = 1;
    359357} // ?{}
    360358
    361 void ?{}( Write_Failure & ex, ifstream & istream ) with(ex) {
    362         virtual_table = &Write_Failure_vt;
     359void ?{}( write_failure & ex, ifstream & istream ) with(ex) {
     360        virtual_table = &write_failure_vt;
    363361        istream = &istream;
    364362        tag = 0;
     
    366364
    367365
    368 static vtable(Read_Failure) Read_Failure_vt;
     366static vtable(read_failure) read_failure_vt;
    369367
    370368// exception I/O constructors
    371 void ?{}( Read_Failure & ex, ofstream & ostream ) with(ex) {
    372         virtual_table = &Read_Failure_vt;
     369void ?{}( read_failure & ex, ofstream & ostream ) with(ex) {
     370        virtual_table = &read_failure_vt;
    373371        ostream = &ostream;
    374372        tag = 1;
    375373} // ?{}
    376374
    377 void ?{}( Read_Failure & ex, ifstream & istream ) with(ex) {
    378         virtual_table = &Read_Failure_vt;
     375void ?{}( read_failure & ex, ifstream & istream ) with(ex) {
     376        virtual_table = &read_failure_vt;
    379377        istream = &istream;
    380378        tag = 0;
    381379} // ?{}
    382380
    383 // void throwOpen_Failure( ofstream & ostream ) {
    384 //      Open_Failure exc = { ostream };
     381// void throwopen_failure( ofstream & ostream ) {
     382//      open_failure exc = { ostream };
    385383// }
    386384
    387 // void throwOpen_Failure( ifstream & istream ) {
    388 //      Open_Failure exc = { istream };
     385// void throwopen_failure( ifstream & istream ) {
     386//      open_failure exc = { istream };
    389387// }
    390388
  • libcfa/src/fstream.hfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Oct 10 09:37:32 2021
    13 // Update Count     : 243
     12// Last Modified On : Mon Jun  5 22:00:20 2023
     13// Update Count     : 246
    1414//
    1515
     
    137137
    138138
    139 exception Open_Failure {
     139exception open_failure {
    140140        union {
    141141                ofstream * ostream;
     
    146146};
    147147
    148 void ?{}( Open_Failure & this, ofstream & );
    149 void ?{}( Open_Failure & this, ifstream & );
     148void ?{}( open_failure & this, ofstream & );
     149void ?{}( open_failure & this, ifstream & );
    150150
    151 exception Close_Failure {
     151exception close_failure {
    152152        union {
    153153                ofstream * ostream;
     
    158158};
    159159
    160 void ?{}( Close_Failure & this, ofstream & );
    161 void ?{}( Close_Failure & this, ifstream & );
     160void ?{}( close_failure & this, ofstream & );
     161void ?{}( close_failure & this, ifstream & );
    162162
    163 exception Write_Failure {
     163exception write_failure {
    164164        union {
    165165                ofstream * ostream;
     
    170170};
    171171
    172 void ?{}( Write_Failure & this, ofstream & );
    173 void ?{}( Write_Failure & this, ifstream & );
     172void ?{}( write_failure & this, ofstream & );
     173void ?{}( write_failure & this, ifstream & );
    174174
    175 exception Read_Failure {
     175exception read_failure {
    176176        union {
    177177                ofstream * ostream;
     
    182182};
    183183
    184 void ?{}( Read_Failure & this, ofstream & );
    185 void ?{}( Read_Failure & this, ifstream & );
     184void ?{}( read_failure & this, ofstream & );
     185void ?{}( read_failure & this, ifstream & );
    186186
    187187// Local Variables: //
  • libcfa/src/iostream.hfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  2 11:25:39 2023
    13 // Update Count     : 410
     12// Last Modified On : Thu Jun 15 22:34:31 2023
     13// Update Count     : 411
    1414//
    1515
     
    5151        int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
    5252}; // basic_ostream
    53        
     53
    5454forall( ostype & | basic_ostream( ostype ) )
    5555trait ostream {
     
    6868
    6969forall( T, ostype & | ostream( ostype ) )
    70         trait writeable {
     70trait writeable {
    7171        ostype & ?|?( ostype &, T );
    7272}; // writeable
     
    161161// *********************************** manipulators ***********************************
    162162
     163struct _Ostream_Flags {
     164        unsigned char eng:1;                                                            // engineering notation
     165        unsigned char neg:1;                                                            // val is negative
     166        unsigned char pc:1;                                                                     // precision specified
     167        unsigned char left:1;                                                           // left justify
     168        unsigned char nobsdp:1;                                                         // base prefix / decimal point
     169        unsigned char sign:1;                                                           // plus / minus sign
     170        unsigned char pad0:1;                                                           // zero pad
     171};
     172
    163173forall( T )
    164174struct _Ostream_Manip {
     
    168178        union {
    169179                unsigned char all;
    170                 struct {
    171                         unsigned char eng:1;                                            // engineering notation
    172                         unsigned char neg:1;                                            // val is negative
    173                         unsigned char pc:1;                                                     // precision specified
    174                         unsigned char left:1;                                           // left justify
    175                         unsigned char nobsdp:1;                                         // base prefix / decimal point
    176                         unsigned char sign:1;                                           // plus / minus sign
    177                         unsigned char pad0:1;                                           // zero pad
    178                 } flags;
     180                _Ostream_Flags flags;
    179181        };
    180182}; // _Ostream_Manip
  • libcfa/src/math.hfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Mon Apr 18 23:37:04 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Oct  8 08:40:42 2022
    13 // Update Count     : 136
     12// Last Modified On : Sun Jun 18 08:13:53 2023
     13// Update Count     : 202
    1414//
    1515
     
    236236
    237237        return (i << 32) + (sum);
    238 }
     238} // log2_u32_32
    239239
    240240//---------------------- Trigonometric ----------------------
     
    371371
    372372inline __attribute__((always_inline)) static {
    373         signed char floor( signed char n, signed char align ) { return n / align * align; }
    374         unsigned char floor( unsigned char n, unsigned char align ) { return n / align * align; }
    375         short int floor( short int n, short int align ) { return n / align * align; }
    376         unsigned short int floor( unsigned short int n, unsigned short int align ) { return n / align * align; }
    377         int floor( int n, int align ) { return n / align * align; }
    378         unsigned int floor( unsigned int n, unsigned int align ) { return n / align * align; }
    379         long int floor( long int n, long int align ) { return n / align * align; }
    380         unsigned long int floor( unsigned long int n, unsigned long int align ) { return n / align * align; }
    381         long long int floor( long long int n, long long int align ) { return n / align * align; }
    382         unsigned long long int floor( unsigned long long int n, unsigned long long int align ) { return n / align * align; }
     373        // force divide before multiply
     374        signed char floor( signed char n, signed char align ) { return (n / align) * align; }
     375        unsigned char floor( unsigned char n, unsigned char align ) { return (n / align) * align; }
     376        short int floor( short int n, short int align ) { return (n / align) * align; }
     377        unsigned short int floor( unsigned short int n, unsigned short int align ) { return (n / align) * align; }
     378        int floor( int n, int align ) { return (n / align) * align; }
     379        unsigned int floor( unsigned int n, unsigned int align ) { return (n / align) * align; }
     380        long int floor( long int n, long int align ) { return (n / align) * align; }
     381        unsigned long int floor( unsigned long int n, unsigned long int align ) { return (n / align) * align; }
     382        long long int floor( long long int n, long long int align ) { return (n / align) * align; }
     383        unsigned long long int floor( unsigned long long int n, unsigned long long int align ) { return (n / align) * align; }
    383384
    384385        // forall( T | { T ?/?( T, T ); T ?*?( T, T ); } )
    385         // T floor( T n, T align ) { return n / align * align; }
    386 
    387         signed char ceiling_div( signed char n, char align ) { return (n + (align - 1)) / align; }
    388         unsigned char ceiling_div( unsigned char n, unsigned char align ) { return (n + (align - 1)) / align; }
    389         short int ceiling_div( short int n, short int align ) { return (n + (align - 1)) / align; }
    390         unsigned short int ceiling_div( unsigned short int n, unsigned short int align ) { return (n + (align - 1)) / align; }
    391         int ceiling_div( int n, int align ) { return (n + (align - 1)) / align; }
    392         unsigned int ceiling_div( unsigned int n, unsigned int align ) { return (n + (align - 1)) / align; }
    393         long int ceiling_div( long int n, long int align ) { return (n + (align - 1)) / align; }
    394         unsigned long int ceiling_div( unsigned long int n, unsigned long int align ) { return (n + (align - 1)) / align; }
    395         long long int ceiling_div( long long int n, long long int align ) { return (n + (align - 1)) / align; }
    396         unsigned long long int ceiling_div( unsigned long long int n, unsigned long long int align ) { return (n + (align - 1)) / align; }
    397 
    398         // forall( T | { T ?+?( T, T ); T ?-?( T, T ); T ?%?( T, T ); } )
    399         // T ceiling_div( T n, T align ) { verify( is_pow2( align ) );return (n + (align - 1)) / align; }
    400 
    401         // gcc notices the div/mod pair and saves both so only one div.
    402         signed char ceiling( signed char n, signed char align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    403         unsigned char ceiling( unsigned char n, unsigned char align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    404         short int ceiling( short int n, short int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    405         unsigned short int ceiling( unsigned short int n, unsigned short int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    406         int ceiling( int n, int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    407         unsigned int ceiling( unsigned int n, unsigned int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    408         long int ceiling( long int n, long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    409         unsigned long int ceiling( unsigned long int n, unsigned long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0) , align); }
    410         long long int ceiling( long long int n, long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    411         unsigned long long int ceiling( unsigned long long int n, unsigned long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    412 
    413         // forall( T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T ); T ?/?( T, T ); } )
    414         // T ceiling( T n, T align ) { return return floor( n + (n % align != 0 ? align - 1 : 0), align ); *}
     386        // T floor( T n, T align ) { return (n / align) * align; }
     387
     388        signed char ceiling_div( signed char n, char align ) { return (n + (align - 1hh)) / align; }
     389        unsigned char ceiling_div( unsigned char n, unsigned char align ) { return (n + (align - 1hhu)) / align; }
     390        short int ceiling_div( short int n, short int align ) { return (n + (align - 1h)) / align; }
     391        unsigned short int ceiling_div( unsigned short int n, unsigned short int align ) { return (n + (align - 1hu)) / align; }
     392        int ceiling_div( int n, int align ) { return (n + (align - 1n)) / align; }
     393        unsigned int ceiling_div( unsigned int n, unsigned int align ) { return (n + (align - 1nu)) / align; }
     394        long int ceiling_div( long int n, long int align ) { return (n + (align - 1l)) / align; }
     395        unsigned long int ceiling_div( unsigned long int n, unsigned long int align ) { return (n + (align - 1lu)) / align; }
     396        long long int ceiling_div( long long int n, long long int align ) { return (n + (align - 1ll)) / align; }
     397        unsigned long long int ceiling_div( unsigned long long int n, unsigned long long int align ) { return (n + (align - 1llu)) / align; }
     398
     399        signed char ceiling( signed char n, char align ) {
     400                typeof(n) trunc = floor( n, align );
     401                return n < 0 || n == trunc ? trunc : trunc + align;
     402        }
     403        unsigned char ceiling( unsigned char n, unsigned char align ) {
     404                typeof(n) trunc = floor( n, align );
     405                return n == trunc ? trunc : trunc + align;
     406        }
     407        short int ceiling( short int n, short int align ) {
     408                typeof(n) trunc = floor( n, align );
     409                return n < 0 || n == trunc ? trunc : trunc + align;
     410        }
     411        unsigned short int ceiling( unsigned short int n, unsigned short int align ) {
     412                typeof(n) trunc = floor( n, align );
     413                return n == trunc ? trunc : trunc + align;
     414        }
     415        int ceiling( int n, int align ) {
     416                typeof(n) trunc = floor( n, align );
     417                return n < 0 || n == trunc ? trunc : trunc + align;
     418        }
     419        unsigned int ceiling( unsigned int n, unsigned int align ) {
     420                typeof(n) trunc = floor( n, align );
     421                return n == trunc ? trunc : trunc + align;
     422        }
     423        long int ceiling( long int n, long int align ) {
     424                typeof(n) trunc = floor( n, align );
     425                return n < 0 || n == trunc ? trunc : trunc + align;
     426        }
     427        unsigned long int ceiling( unsigned long int n, unsigned long int align ) {
     428                typeof(n) trunc = floor( n, align );
     429                return n == trunc ? trunc : trunc + align;
     430        }
     431        long long int ceiling( long long int n, signed long long int align ) {
     432                typeof(n) trunc = floor( n, align );
     433                return n < 0 || n == trunc ? trunc : trunc + align;
     434        }
     435        unsigned long long int ceiling( unsigned long long int n, unsigned long long int align ) {
     436                typeof(n) trunc = floor( n, align );
     437                return n == trunc ? trunc : trunc + align;
     438        }
    415439
    416440        float floor( float x ) { return floorf( x ); }
  • libcfa/src/math.trait.hfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Fri Jul 16 15:40:52 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  2 11:36:56 2023
    13 // Update Count     : 20
     12// Last Modified On : Tue Jun  6 07:59:17 2023
     13// Update Count     : 24
    1414//
    1515
     
    1717
    1818forall( U )
    19 trait Not {
     19trait not {
    2020        void ?{}( U &, zero_t );
    2121        int !?( U );
    22 }; // Not
     22}; // not
    2323
    24 forall( T | Not( T ) )
    25 trait Equality {
     24forall( T | not( T ) )
     25trait equality {
    2626        int ?==?( T, T );
    2727        int ?!=?( T, T );
    28 }; // Equality
     28}; // equality
    2929
    30 forall( U | Equality( U ) )
    31 trait Relational {
     30forall( U | equality( U ) )
     31trait relational {
    3232        int ?<?( U, U );
    3333        int ?<=?( U, U );
    3434        int ?>?( U, U );
    3535        int ?>=?( U, U );
    36 }; // Relational
     36}; // relational
    3737
    3838forall ( T )
    39 trait Signed {
     39trait Signed {  // must be capitalized, conflict with keyword signed
    4040        T +?( T );
    4141        T -?( T );
     
    4444
    4545forall( U | Signed( U ) )
    46 trait Additive {
     46trait additive {
    4747        U ?+?( U, U );
    4848        U ?-?( U, U );
    4949        U ?+=?( U &, U );
    5050        U ?-=?( U &, U );
    51 }; // Additive
     51}; // additive
    5252
    53 forall( T | Additive( T ) )
    54 trait Incdec {
     53forall( T | additive( T ) )
     54trait inc_dec {
    5555        void ?{}( T &, one_t );
    5656        // T ?++( T & );
     
    5858        // T ?--( T & );
    5959        // T --?( T & );
    60 }; // Incdec
     60}; // inc_dec
    6161
    62 forall( U | Incdec( U ) )
    63 trait Multiplicative {
     62forall( U | inc_dec( U ) )
     63trait multiplicative {
    6464        U ?*?( U, U );
    6565        U ?/?( U, U );
    6666        U ?%?( U, U );
    6767        U ?/=?( U &, U );
    68 }; // Multiplicative
     68}; // multiplicative
    6969
    70 forall( T | Relational( T ) | Multiplicative( T ) )
    71 trait Arithmetic {
    72 }; // Arithmetic
     70forall( T | relational( T ) | multiplicative( T ) )
     71trait arithmetic {
     72}; // arithmetic
    7373
    7474// Local Variables: //
  • libcfa/src/parseconfig.cfa

    rfa5e1aa5 rb7b3e41  
    144144                        in | nl;                                                                // ignore remainder of line
    145145                } // for
    146         } catch( Open_Failure * ex; ex->istream == &in ) {
     146        } catch( open_failure * ex; ex->istream == &in ) {
    147147                delete( kv_pairs );
    148148                throw *ex;
     
    203203
    204204
    205 forall(T | Relational( T ))
     205forall(T | relational( T ))
    206206[ bool ] is_nonnegative( & T value ) {
    207207        T zero_val = 0;
     
    209209}
    210210
    211 forall(T | Relational( T ))
     211forall(T | relational( T ))
    212212[ bool ] is_positive( & T value ) {
    213213        T zero_val = 0;
     
    215215}
    216216
    217 forall(T | Relational( T ))
     217forall(T | relational( T ))
    218218[ bool ] is_nonpositive( & T value ) {
    219219        T zero_val = 0;
     
    221221}
    222222
    223 forall(T | Relational( T ))
     223forall(T | relational( T ))
    224224[ bool ] is_negative( & T value ) {
    225225        T zero_val = 0;
  • libcfa/src/parseconfig.hfa

    rfa5e1aa5 rb7b3e41  
    107107
    108108
    109 forall(T | Relational( T ))
     109forall(T | relational( T ))
    110110[ bool ] is_nonnegative( & T );
    111111
    112 forall(T | Relational( T ))
     112forall(T | relational( T ))
    113113[ bool ] is_positive( & T );
    114114
    115 forall(T | Relational( T ))
     115forall(T | relational( T ))
    116116[ bool ] is_nonpositive( & T );
    117117
    118 forall(T | Relational( T ))
     118forall(T | relational( T ))
    119119[ bool ] is_negative( & T );
    120120
  • libcfa/src/rational.cfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 25 18:09:58 2022
    13 // Update Count     : 194
     12// Last Modified On : Mon Jun  5 22:49:06 2023
     13// Update Count     : 196
    1414//
    1515
     
    2020#pragma GCC visibility push(default)
    2121
    22 forall( T | Arithmetic( T ) ) {
     22forall( T | arithmetic( T ) ) {
    2323        // helper routines
    2424
     
    3939                        abort | "Invalid rational number construction: denominator cannot be equal to 0.";
    4040                } // exit
    41                 if ( d < (T){0} ) { d = -d; n = -n; } // move sign to numerator
     41                if ( d < (T){0} ) { d = -d; n = -n; }                   // move sign to numerator
    4242                return gcd( abs( n ), d );                                              // simplify
    43         } // Rationalnumber::simplify
     43        } // simplify
    4444
    4545        // constructors
    4646
    47         void ?{}( Rational(T) & r, zero_t ) {
     47        void ?{}( rational(T) & r, zero_t ) {
    4848                r{ (T){0}, (T){1} };
    4949        } // rational
    5050
    51         void ?{}( Rational(T) & r, one_t ) {
     51        void ?{}( rational(T) & r, one_t ) {
    5252                r{ (T){1}, (T){1} };
    5353        } // rational
    5454
    55         void ?{}( Rational(T) & r ) {
     55        void ?{}( rational(T) & r ) {
    5656                r{ (T){0}, (T){1} };
    5757        } // rational
    5858
    59         void ?{}( Rational(T) & r, T n ) {
     59        void ?{}( rational(T) & r, T n ) {
    6060                r{ n, (T){1} };
    6161        } // rational
    6262
    63         void ?{}( Rational(T) & r, T n, T d ) {
    64                 T t = simplify( n, d );                         // simplify
     63        void ?{}( rational(T) & r, T n, T d ) {
     64                T t = simplify( n, d );                                                 // simplify
    6565                r.[numerator, denominator] = [n / t, d / t];
    6666        } // rational
     
    6868        // getter for numerator/denominator
    6969
    70         T numerator( Rational(T) r ) {
     70        T numerator( rational(T) r ) {
    7171                return r.numerator;
    7272        } // numerator
    7373
    74         T denominator( Rational(T) r ) {
     74        T denominator( rational(T) r ) {
    7575                return r.denominator;
    7676        } // denominator
    7777
    78         [ T, T ] ?=?( & [ T, T ] dest, Rational(T) src ) {
     78        [ T, T ] ?=?( & [ T, T ] dest, rational(T) src ) {
    7979                return dest = src.[ numerator, denominator ];
    8080        } // ?=?
     
    8282        // setter for numerator/denominator
    8383
    84         T numerator( Rational(T) r, T n ) {
     84        T numerator( rational(T) r, T n ) {
    8585                T prev = r.numerator;
    86                 T t = gcd( abs( n ), r.denominator ); // simplify
     86                T t = gcd( abs( n ), r.denominator );                   // simplify
    8787                r.[numerator, denominator] = [n / t, r.denominator / t];
    8888                return prev;
    8989        } // numerator
    9090
    91         T denominator( Rational(T) r, T d ) {
     91        T denominator( rational(T) r, T d ) {
    9292                T prev = r.denominator;
    93                 T t = simplify( r.numerator, d );       // simplify
     93                T t = simplify( r.numerator, d );                               // simplify
    9494                r.[numerator, denominator] = [r.numerator / t, d / t];
    9595                return prev;
     
    9898        // comparison
    9999
    100         int ?==?( Rational(T) l, Rational(T) r ) {
     100        int ?==?( rational(T) l, rational(T) r ) {
    101101                return l.numerator * r.denominator == l.denominator * r.numerator;
    102102        } // ?==?
    103103
    104         int ?!=?( Rational(T) l, Rational(T) r ) {
     104        int ?!=?( rational(T) l, rational(T) r ) {
    105105                return ! ( l == r );
    106106        } // ?!=?
    107107
    108         int ?!=?( Rational(T) l, zero_t ) {
    109                 return ! ( l == (Rational(T)){ 0 } );
     108        int ?!=?( rational(T) l, zero_t ) {
     109                return ! ( l == (rational(T)){ 0 } );
    110110        } // ?!=?
    111111
    112         int ?<?( Rational(T) l, Rational(T) r ) {
     112        int ?<?( rational(T) l, rational(T) r ) {
    113113                return l.numerator * r.denominator < l.denominator * r.numerator;
    114114        } // ?<?
    115115
    116         int ?<=?( Rational(T) l, Rational(T) r ) {
     116        int ?<=?( rational(T) l, rational(T) r ) {
    117117                return l.numerator * r.denominator <= l.denominator * r.numerator;
    118118        } // ?<=?
    119119
    120         int ?>?( Rational(T) l, Rational(T) r ) {
     120        int ?>?( rational(T) l, rational(T) r ) {
    121121                return ! ( l <= r );
    122122        } // ?>?
    123123
    124         int ?>=?( Rational(T) l, Rational(T) r ) {
     124        int ?>=?( rational(T) l, rational(T) r ) {
    125125                return ! ( l < r );
    126126        } // ?>=?
     
    128128        // arithmetic
    129129
    130         Rational(T) +?( Rational(T) r ) {
    131                 return (Rational(T)){ r.numerator, r.denominator };
     130        rational(T) +?( rational(T) r ) {
     131                return (rational(T)){ r.numerator, r.denominator };
    132132        } // +?
    133133
    134         Rational(T) -?( Rational(T) r ) {
    135                 return (Rational(T)){ -r.numerator, r.denominator };
     134        rational(T) -?( rational(T) r ) {
     135                return (rational(T)){ -r.numerator, r.denominator };
    136136        } // -?
    137137
    138         Rational(T) ?+?( Rational(T) l, Rational(T) r ) {
     138        rational(T) ?+?( rational(T) l, rational(T) r ) {
    139139                if ( l.denominator == r.denominator ) {                 // special case
    140                         return (Rational(T)){ l.numerator + r.numerator, l.denominator };
     140                        return (rational(T)){ l.numerator + r.numerator, l.denominator };
    141141                } else {
    142                         return (Rational(T)){ l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
     142                        return (rational(T)){ l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
    143143                } // if
    144144        } // ?+?
    145145
    146         Rational(T) ?+=?( Rational(T) & l, Rational(T) r ) {
     146        rational(T) ?+=?( rational(T) & l, rational(T) r ) {
    147147                l = l + r;
    148148                return l;
    149149        } // ?+?
    150150
    151         Rational(T) ?+=?( Rational(T) & l, one_t ) {
    152                 l = l + (Rational(T)){ 1 };
     151        rational(T) ?+=?( rational(T) & l, one_t ) {
     152                l = l + (rational(T)){ 1 };
    153153                return l;
    154154        } // ?+?
    155155
    156         Rational(T) ?-?( Rational(T) l, Rational(T) r ) {
     156        rational(T) ?-?( rational(T) l, rational(T) r ) {
    157157                if ( l.denominator == r.denominator ) {                 // special case
    158                         return (Rational(T)){ l.numerator - r.numerator, l.denominator };
     158                        return (rational(T)){ l.numerator - r.numerator, l.denominator };
    159159                } else {
    160                         return (Rational(T)){ l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
     160                        return (rational(T)){ l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
    161161                } // if
    162162        } // ?-?
    163163
    164         Rational(T) ?-=?( Rational(T) & l, Rational(T) r ) {
     164        rational(T) ?-=?( rational(T) & l, rational(T) r ) {
    165165                l = l - r;
    166166                return l;
    167167        } // ?-?
    168168
    169         Rational(T) ?-=?( Rational(T) & l, one_t ) {
    170                 l = l - (Rational(T)){ 1 };
     169        rational(T) ?-=?( rational(T) & l, one_t ) {
     170                l = l - (rational(T)){ 1 };
    171171                return l;
    172172        } // ?-?
    173173
    174         Rational(T) ?*?( Rational(T) l, Rational(T) r ) {
    175                 return (Rational(T)){ l.numerator * r.numerator, l.denominator * r.denominator };
     174        rational(T) ?*?( rational(T) l, rational(T) r ) {
     175                return (rational(T)){ l.numerator * r.numerator, l.denominator * r.denominator };
    176176        } // ?*?
    177177
    178         Rational(T) ?*=?( Rational(T) & l, Rational(T) r ) {
     178        rational(T) ?*=?( rational(T) & l, rational(T) r ) {
    179179                return l = l * r;
    180180        } // ?*?
    181181
    182         Rational(T) ?/?( Rational(T) l, Rational(T) r ) {
     182        rational(T) ?/?( rational(T) l, rational(T) r ) {
    183183                if ( r.numerator < (T){0} ) {
    184184                        r.[numerator, denominator] = [-r.numerator, -r.denominator];
    185185                } // if
    186                 return (Rational(T)){ l.numerator * r.denominator, l.denominator * r.numerator };
     186                return (rational(T)){ l.numerator * r.denominator, l.denominator * r.numerator };
    187187        } // ?/?
    188188
    189         Rational(T) ?/=?( Rational(T) & l, Rational(T) r ) {
     189        rational(T) ?/=?( rational(T) & l, rational(T) r ) {
    190190                return l = l / r;
    191191        } // ?/?
     
    194194
    195195        forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } )
    196         istype & ?|?( istype & is, Rational(T) & r ) {
     196        istype & ?|?( istype & is, rational(T) & r ) {
    197197                is | r.numerator | r.denominator;
    198198                T t = simplify( r.numerator, r.denominator );
     
    203203
    204204        forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, T ); } ) {
    205                 ostype & ?|?( ostype & os, Rational(T) r ) {
     205                ostype & ?|?( ostype & os, rational(T) r ) {
    206206                        return os | r.numerator | '/' | r.denominator;
    207207                } // ?|?
    208208
    209                 void ?|?( ostype & os, Rational(T) r ) {
     209                void ?|?( ostype & os, rational(T) r ) {
    210210                        (ostype &)(os | r); ends( os );
    211211                } // ?|?
     
    213213} // distribution
    214214
    215 forall( T | Arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
    216         Rational(T) ?\?( Rational(T) x, long int y ) {
     215forall( T | arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
     216        rational(T) ?\?( rational(T) x, long int y ) {
    217217                if ( y < 0 ) {
    218                         return (Rational(T)){ x.denominator \ -y, x.numerator \ -y };
     218                        return (rational(T)){ x.denominator \ -y, x.numerator \ -y };
    219219                } else {
    220                         return (Rational(T)){ x.numerator \ y, x.denominator \ y };
     220                        return (rational(T)){ x.numerator \ y, x.denominator \ y };
    221221                } // if
    222222        } // ?\?
    223223
    224         Rational(T) ?\=?( Rational(T) & x, long int y ) {
     224        rational(T) ?\=?( rational(T) & x, long int y ) {
    225225                return x = x \ y;
    226226        } // ?\?
     
    229229// conversion
    230230
    231 forall( T | Arithmetic( T ) | { double convert( T ); } )
    232 double widen( Rational(T) r ) {
     231forall( T | arithmetic( T ) | { double convert( T ); } )
     232double widen( rational(T) r ) {
    233233        return convert( r.numerator ) / convert( r.denominator );
    234234} // widen
    235235
    236 forall( T | Arithmetic( T ) | { double convert( T ); T convert( double ); } )
    237 Rational(T) narrow( double f, T md ) {
     236forall( T | arithmetic( T ) | { double convert( T ); T convert( double ); } )
     237rational(T) narrow( double f, T md ) {
    238238        // http://www.ics.uci.edu/~eppstein/numth/frap.c
    239         if ( md <= (T){1} ) {                                   // maximum fractional digits too small?
    240                 return (Rational(T)){ convert( f ), (T){1}}; // truncate fraction
     239        if ( md <= (T){1} ) {                                                           // maximum fractional digits too small?
     240                return (rational(T)){ convert( f ), (T){1}};    // truncate fraction
    241241        } // if
    242242
     
    260260          if ( f > (double)0x7FFFFFFF ) break;                          // representation failure
    261261        } // for
    262         return (Rational(T)){ m00, m10 };
     262        return (rational(T)){ m00, m10 };
    263263} // narrow
    264264
  • libcfa/src/rational.hfa

    rfa5e1aa5 rb7b3e41  
    1212// Created On       : Wed Apr  6 17:56:25 2016
    1313// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Tue Jul 20 17:45:29 2021
    15 // Update Count     : 118
     14// Last Modified On : Mon Jun  5 22:49:05 2023
     15// Update Count     : 119
    1616//
    1717
     
    1919
    2020#include "iostream.hfa"
    21 #include "math.trait.hfa"                                                               // Arithmetic
     21#include "math.trait.hfa"                                                               // arithmetic
    2222
    2323// implementation
    2424
    25 forall( T | Arithmetic( T ) ) {
    26         struct Rational {
     25forall( T | arithmetic( T ) ) {
     26        struct rational {
    2727                T numerator, denominator;                                               // invariant: denominator > 0
    28         }; // Rational
     28        }; // rational
    2929
    3030        // constructors
    3131
    32         void ?{}( Rational(T) & r );
    33         void ?{}( Rational(T) & r, zero_t );
    34         void ?{}( Rational(T) & r, one_t );
    35         void ?{}( Rational(T) & r, T n );
    36         void ?{}( Rational(T) & r, T n, T d );
     32        void ?{}( rational(T) & r );
     33        void ?{}( rational(T) & r, zero_t );
     34        void ?{}( rational(T) & r, one_t );
     35        void ?{}( rational(T) & r, T n );
     36        void ?{}( rational(T) & r, T n, T d );
    3737
    3838        // numerator/denominator getter
    3939
    40         T numerator( Rational(T) r );
    41         T denominator( Rational(T) r );
    42         [ T, T ] ?=?( & [ T, T ] dest, Rational(T) src );
     40        T numerator( rational(T) r );
     41        T denominator( rational(T) r );
     42        [ T, T ] ?=?( & [ T, T ] dest, rational(T) src );
    4343
    4444        // numerator/denominator setter
    4545
    46         T numerator( Rational(T) r, T n );
    47         T denominator( Rational(T) r, T d );
     46        T numerator( rational(T) r, T n );
     47        T denominator( rational(T) r, T d );
    4848
    4949        // comparison
    5050
    51         int ?==?( Rational(T) l, Rational(T) r );
    52         int ?!=?( Rational(T) l, Rational(T) r );
    53         int ?!=?( Rational(T) l, zero_t );                                      // => !
    54         int ?<?( Rational(T) l, Rational(T) r );
    55         int ?<=?( Rational(T) l, Rational(T) r );
    56         int ?>?( Rational(T) l, Rational(T) r );
    57         int ?>=?( Rational(T) l, Rational(T) r );
     51        int ?==?( rational(T) l, rational(T) r );
     52        int ?!=?( rational(T) l, rational(T) r );
     53        int ?!=?( rational(T) l, zero_t );                                      // => !
     54        int ?<?( rational(T) l, rational(T) r );
     55        int ?<=?( rational(T) l, rational(T) r );
     56        int ?>?( rational(T) l, rational(T) r );
     57        int ?>=?( rational(T) l, rational(T) r );
    5858
    5959        // arithmetic
    6060
    61         Rational(T) +?( Rational(T) r );
    62         Rational(T) -?( Rational(T) r );
    63         Rational(T) ?+?( Rational(T) l, Rational(T) r );
    64         Rational(T) ?+=?( Rational(T) & l, Rational(T) r );
    65         Rational(T) ?+=?( Rational(T) & l, one_t );                     // => ++?, ?++
    66         Rational(T) ?-?( Rational(T) l, Rational(T) r );
    67         Rational(T) ?-=?( Rational(T) & l, Rational(T) r );
    68         Rational(T) ?-=?( Rational(T) & l, one_t );                     // => --?, ?--
    69         Rational(T) ?*?( Rational(T) l, Rational(T) r );
    70         Rational(T) ?*=?( Rational(T) & l, Rational(T) r );
    71         Rational(T) ?/?( Rational(T) l, Rational(T) r );
    72         Rational(T) ?/=?( Rational(T) & l, Rational(T) r );
     61        rational(T) +?( rational(T) r );
     62        rational(T) -?( rational(T) r );
     63        rational(T) ?+?( rational(T) l, rational(T) r );
     64        rational(T) ?+=?( rational(T) & l, rational(T) r );
     65        rational(T) ?+=?( rational(T) & l, one_t );                     // => ++?, ?++
     66        rational(T) ?-?( rational(T) l, rational(T) r );
     67        rational(T) ?-=?( rational(T) & l, rational(T) r );
     68        rational(T) ?-=?( rational(T) & l, one_t );                     // => --?, ?--
     69        rational(T) ?*?( rational(T) l, rational(T) r );
     70        rational(T) ?*=?( rational(T) & l, rational(T) r );
     71        rational(T) ?/?( rational(T) l, rational(T) r );
     72        rational(T) ?/=?( rational(T) & l, rational(T) r );
    7373
    7474        // I/O
    7575        forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } )
    76         istype & ?|?( istype &, Rational(T) & );
     76        istype & ?|?( istype &, rational(T) & );
    7777
    7878        forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, T ); } ) {
    79                 ostype & ?|?( ostype &, Rational(T) );
    80                 void ?|?( ostype &, Rational(T) );
     79                ostype & ?|?( ostype &, rational(T) );
     80                void ?|?( ostype &, rational(T) );
    8181        } // distribution
    8282} // distribution
    8383
    84 forall( T | Arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
    85         Rational(T) ?\?( Rational(T) x, long int y );
    86         Rational(T) ?\=?( Rational(T) & x, long int y );
     84forall( T | arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
     85        rational(T) ?\?( rational(T) x, long int y );
     86        rational(T) ?\=?( rational(T) & x, long int y );
    8787} // distribution
    8888
    8989// conversion
    90 forall( T | Arithmetic( T ) | { double convert( T ); } )
    91 double widen( Rational(T) r );
    92 forall( T | Arithmetic( T ) | { double convert( T );  T convert( double );} )
    93 Rational(T) narrow( double f, T md );
     90forall( T | arithmetic( T ) | { double convert( T ); } )
     91double widen( rational(T) r );
     92forall( T | arithmetic( T ) | { double convert( T );  T convert( double );} )
     93rational(T) narrow( double f, T md );
    9494
    9595// Local Variables: //
  • libcfa/src/stdlib.hfa

    rfa5e1aa5 rb7b3e41  
    367367
    368368        char random( void ) { return (unsigned long int)random(); }
    369         char random( char u ) { return random( (unsigned long int)u ); } // [0,u)
     369        char random( char u ) { return (unsigned long int)random( (unsigned long int)u ); } // [0,u)
    370370        char random( char l, char u ) { return random( (unsigned long int)l, (unsigned long int)u ); } // [l,u)
    371371        int random( void ) { return (long int)random(); }
    372         int random( int u ) { return random( (long int)u ); } // [0,u]
     372        int random( int u ) { return (long int)random( (long int)u ); } // [0,u]
    373373        int random( int l, int u ) { return random( (long int)l, (long int)u ); } // [l,u)
    374374        unsigned int random( void ) { return (unsigned long int)random(); }
    375         unsigned int random( unsigned int u ) { return random( (unsigned long int)u ); } // [0,u]
     375        unsigned int random( unsigned int u ) { return (unsigned long int)random( (unsigned long int)u ); } // [0,u]
    376376        unsigned int random( unsigned int l, unsigned int u ) { return random( (unsigned long int)l, (unsigned long int)u ); } // [l,u)
    377377} // distribution
  • libcfa/src/virtual_dtor.hfa

    rfa5e1aa5 rb7b3e41  
    2525    __virtual_obj_start = &this;
    2626}
    27 static inline void __CFA_dtor_shutdown( virtual_dtor & this ) with(this) {
     27static inline bool __CFA_dtor_shutdown( virtual_dtor & this ) with(this) {
     28    if ( __virtual_dtor_ptr == 1p ) return true; // stop base dtors from being called twice
    2829    if ( __virtual_dtor_ptr ) {
    2930        void (*dtor_ptr)(virtual_dtor &) = __virtual_dtor_ptr;
    3031        __virtual_dtor_ptr = 0p;
    31         dtor_ptr(*((virtual_dtor *)__virtual_obj_start)); // replace actor with base type
    32         return;
     32        dtor_ptr(*((virtual_dtor *)__virtual_obj_start)); // call most derived dtor
     33        __virtual_dtor_ptr = 1p; // stop base dtors from being called twice
     34        return true;
    3335    }
     36    return false;
    3437}
    3538static inline void __CFA_virt_free( virtual_dtor & this ) { free( this.__virtual_obj_start ); }
  • src/AST/Convert.cpp

    rfa5e1aa5 rb7b3e41  
    23432343                                old->location,
    23442344                                GET_ACCEPT_1(arg, Expr),
    2345                                 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast
     2345                                old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast,
     2346                                (ast::CastExpr::CastKind) old->kind
    23462347                        )
    23472348                );
  • src/AST/Decl.cpp

    rfa5e1aa5 rb7b3e41  
    142142bool EnumDecl::valueOf( const Decl * enumerator, long long& value ) const {
    143143        if ( enumValues.empty() ) {
    144                 long long crntVal = 0;
     144                Evaluation crntVal = {0, true, true};  // until expression is given, we know to start counting from 0
    145145                for ( const Decl * member : members ) {
    146146                        const ObjectDecl* field = strict_dynamic_cast< const ObjectDecl* >( member );
    147147                        if ( field->init ) {
    148148                                const SingleInit * init = strict_dynamic_cast< const SingleInit* >( field->init.get() );
    149                                 auto result = eval( init->value );
    150                                 if ( ! result.second ) {
     149                                crntVal = eval( init->value );
     150                                if ( ! crntVal.isEvaluableInGCC ) {
    151151                                        SemanticError( init->location, ::toString( "Non-constexpr in initialization of "
    152152                                                "enumerator: ", field ) );
    153153                                }
    154                                 crntVal = result.first;
    155154                        }
    156155                        if ( enumValues.count( field->name ) != 0 ) {
    157156                                SemanticError( location, ::toString( "Enum ", name, " has multiple members with the "   "name ", field->name ) );
    158157                        }
    159                         enumValues[ field->name ] = crntVal;
    160                         ++crntVal;
     158                        if (crntVal.hasKnownValue) {
     159                                enumValues[ field->name ] = crntVal.knownValue;
     160                        }
     161                        ++crntVal.knownValue;
    161162                }
    162163        }
  • src/AST/DeclReplacer.hpp

    rfa5e1aa5 rb7b3e41  
    1818#include <unordered_map>
    1919
    20 #include "Node.hpp"
     20namespace ast {
     21        class DeclWithType;
     22        class Expr;
     23        class Node;
     24        class TypeDecl;
     25}
    2126
    2227namespace ast {
    23         class DeclWithType;
    24         class TypeDecl;
    25         class Expr;
    2628
    27         namespace DeclReplacer {
    28                 using DeclMap = std::unordered_map< const DeclWithType *, const DeclWithType * >;
    29                 using TypeMap = std::unordered_map< const TypeDecl *, const TypeDecl * >;
    30                 using ExprMap = std::unordered_map< const DeclWithType *, const Expr * >;
     29namespace DeclReplacer {
    3130
    32                 const Node * replace( const Node * node, const DeclMap & declMap, bool debug = false );
    33                 const Node * replace( const Node * node, const TypeMap & typeMap, bool debug = false );
    34                 const Node * replace( const Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
    35                 const Node * replace( const Node * node, const ExprMap & exprMap);
    36         }
     31using DeclMap = std::unordered_map< const DeclWithType *, const DeclWithType * >;
     32using TypeMap = std::unordered_map< const TypeDecl *, const TypeDecl * >;
     33using ExprMap = std::unordered_map< const DeclWithType *, const Expr * >;
     34
     35const Node * replace( const Node * node, const DeclMap & declMap, bool debug = false );
     36const Node * replace( const Node * node, const TypeMap & typeMap, bool debug = false );
     37const Node * replace( const Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
     38const Node * replace( const Node * node, const ExprMap & exprMap);
     39
     40}
     41
    3742}
    3843
  • src/AST/Expr.cpp

    rfa5e1aa5 rb7b3e41  
    186186// --- CastExpr
    187187
    188 CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g )
    189 : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {}
     188CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g, CastKind kind )
     189: Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ), kind( kind ) {}
    190190
    191191bool CastExpr::get_lvalue() const {
  • src/AST/Expr.hpp

    rfa5e1aa5 rb7b3e41  
    5555                const Expr * e )
    5656        : decl( id ), declptr( declptr ), actualType( actual ), formalType( formal ), expr( e ) {}
     57
     58        operator bool() {return declptr;}
    5759};
    5860
     
    335337        GeneratedFlag isGenerated;
    336338
     339        enum CastKind {
     340                Default, // C
     341                Coerce, // reinterpret cast
     342                Return  // overload selection
     343        };
     344
     345        CastKind kind = Default;
     346
    337347        CastExpr( const CodeLocation & loc, const Expr * a, const Type * to,
    338                 GeneratedFlag g = GeneratedCast ) : Expr( loc, to ), arg( a ), isGenerated( g ) {}
     348                GeneratedFlag g = GeneratedCast, CastKind kind = Default ) : Expr( loc, to ), arg( a ), isGenerated( g ), kind( kind ) {}
    339349        /// Cast-to-void
    340         CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g = GeneratedCast );
     350        CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g = GeneratedCast, CastKind kind = Default );
    341351
    342352        /// Wrap a cast expression around an existing expression (always generated)
  • src/AST/Pass.hpp

    rfa5e1aa5 rb7b3e41  
    414414};
    415415
    416 /// Use when the templated visitor should update the symbol table
     416/// Use when the templated visitor should update the symbol table,
     417/// that is, when your pass core needs to query the symbol table.
     418/// Expected setups:
     419/// - For master passes that kick off at the compilation unit
     420///   - before resolver: extend WithSymbolTableX<IgnoreErrors>
     421///   - after resolver: extend WithSymbolTable and use defaults
     422///   - (FYI, for completeness, the resolver's main pass uses ValidateOnAdd when it kicks off)
     423/// - For helper passes that kick off at arbitrary points in the AST:
     424///   - take an existing symbol table as a parameter, extend WithSymbolTable,
     425///     and construct with WithSymbolTable(const SymbolTable &)
    417426struct WithSymbolTable {
    418         SymbolTable symtab;
     427        WithSymbolTable(const ast::SymbolTable & from) : symtab(from) {}
     428        WithSymbolTable(ast::SymbolTable::ErrorDetection errorMode = ast::SymbolTable::ErrorDetection::AssertClean) : symtab(errorMode) {}
     429        ast::SymbolTable symtab;
     430};
     431template <ast::SymbolTable::ErrorDetection errorMode>
     432struct WithSymbolTableX : WithSymbolTable {
     433        WithSymbolTableX() : WithSymbolTable(errorMode) {}
    419434};
    420435
  • src/AST/Pass.impl.hpp

    rfa5e1aa5 rb7b3e41  
    7272                template<typename it_t, template <class...> class container_t>
    7373                static inline void take_all( it_t it, container_t<ast::ptr<ast::Decl>> * decls, bool * mutated = nullptr ) {
    74                         if(empty(decls)) return;
     74                        if ( empty( decls ) ) return;
    7575
    7676                        std::transform(decls->begin(), decls->end(), it, [](const ast::Decl * decl) -> auto {
     
    7878                                });
    7979                        decls->clear();
    80                         if(mutated) *mutated = true;
     80                        if ( mutated ) *mutated = true;
    8181                }
    8282
    8383                template<typename it_t, template <class...> class container_t>
    8484                static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * stmts, bool * mutated = nullptr ) {
    85                         if(empty(stmts)) return;
     85                        if ( empty( stmts ) ) return;
    8686
    8787                        std::move(stmts->begin(), stmts->end(), it);
    8888                        stmts->clear();
    89                         if(mutated) *mutated = true;
     89                        if ( mutated ) *mutated = true;
    9090                }
    9191
     
    9393                /// Check if should be skipped, different for pointers and containers
    9494                template<typename node_t>
    95                 bool skip( const ast::ptr<node_t> & val) {
     95                bool skip( const ast::ptr<node_t> & val ) {
    9696                        return !val;
    9797                }
     
    110110
    111111                template<typename node_t>
    112                 const node_t & get( const node_t & val, long) {
     112                const node_t & get( const node_t & val, long ) {
    113113                        return val;
    114114                }
     
    126126                }
    127127        }
    128 
    129         template< typename core_t >
    130         template< typename node_t >
    131         auto ast::Pass< core_t >::call_accept( const node_t * node )
    132                 -> typename ast::Pass< core_t >::template generic_call_accept_result<node_t>::type
    133         {
    134                 __pedantic_pass_assert( __visit_children() );
    135                 __pedantic_pass_assert( node );
    136 
    137                 static_assert( !std::is_base_of<ast::Expr, node_t>::value, "ERROR");
    138                 static_assert( !std::is_base_of<ast::Stmt, node_t>::value, "ERROR");
    139 
    140                 auto nval = node->accept( *this );
    141                 __pass::result1<
    142                         typename std::remove_pointer< decltype( node->accept(*this) ) >::type
    143                 > res;
    144                 res.differs = nval != node;
    145                 res.value = nval;
    146                 return res;
    147         }
    148 
    149         template< typename core_t >
    150         __pass::template result1<ast::Expr> ast::Pass< core_t >::call_accept( const ast::Expr * expr ) {
    151                 __pedantic_pass_assert( __visit_children() );
    152                 __pedantic_pass_assert( expr );
    153 
    154                 auto nval = expr->accept( *this );
    155                 return { nval != expr, nval };
    156         }
    157 
    158         template< typename core_t >
    159         __pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) {
    160                 __pedantic_pass_assert( __visit_children() );
    161                 __pedantic_pass_assert( stmt );
    162 
    163                 const ast::Stmt * nval = stmt->accept( *this );
    164                 return { nval != stmt, nval };
    165         }
    166 
    167         template< typename core_t >
    168         __pass::template result1<ast::Expr> ast::Pass< core_t >::call_accept_top( const ast::Expr * expr ) {
    169                 __pedantic_pass_assert( __visit_children() );
    170                 __pedantic_pass_assert( expr );
    171 
    172                 const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 );
    173                 if ( typeSubs_ptr && expr->env ) {
    174                         *typeSubs_ptr = expr->env;
    175                 }
    176 
    177                 auto nval = expr->accept( *this );
    178                 return { nval != expr, nval };
    179         }
    180 
    181         template< typename core_t >
    182         __pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {
    183                 __pedantic_pass_assert( __visit_children() );
    184                 __pedantic_pass_assert( stmt );
    185 
    186                 // add a few useful symbols to the scope
    187                 using __pass::empty;
    188 
    189                 // get the stmts/decls that will need to be spliced in
    190                 auto stmts_before = __pass::stmtsToAddBefore( core, 0 );
    191                 auto stmts_after  = __pass::stmtsToAddAfter ( core, 0 );
    192                 auto decls_before = __pass::declsToAddBefore( core, 0 );
    193                 auto decls_after  = __pass::declsToAddAfter ( core, 0 );
    194 
    195                 // These may be modified by subnode but most be restored once we exit this statemnet.
    196                 ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::typeSubs( core, 0 ) );
    197                 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
    198                 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
    199                 ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before );
    200                 ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after  );
    201 
    202                 // Now is the time to actually visit the node
    203                 const ast::Stmt * nstmt = stmt->accept( *this );
    204 
    205                 // If the pass doesn't want to add anything then we are done
    206                 if( empty(stmts_before) && empty(stmts_after) && empty(decls_before) && empty(decls_after) ) {
    207                         return { nstmt != stmt, nstmt };
    208                 }
    209 
    210                 // Make sure that it is either adding statements or declartions but not both
    211                 // this is because otherwise the order would be awkward to predict
    212                 assert(( empty( stmts_before ) && empty( stmts_after ))
    213                     || ( empty( decls_before ) && empty( decls_after )) );
    214 
    215                 // Create a new Compound Statement to hold the new decls/stmts
    216                 ast::CompoundStmt * compound = new ast::CompoundStmt( stmt->location );
    217 
    218                 // Take all the declarations that go before
    219                 __pass::take_all( std::back_inserter( compound->kids ), decls_before );
    220                 __pass::take_all( std::back_inserter( compound->kids ), stmts_before );
    221 
    222                 // Insert the original declaration
    223                 compound->kids.emplace_back( nstmt );
    224 
    225                 // Insert all the declarations that go before
    226                 __pass::take_all( std::back_inserter( compound->kids ), decls_after );
    227                 __pass::take_all( std::back_inserter( compound->kids ), stmts_after );
    228 
    229                 return {true, compound};
    230         }
    231 
    232         template< typename core_t >
    233         template< template <class...> class container_t >
    234         __pass::template resultNstmt<container_t> ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
    235                 __pedantic_pass_assert( __visit_children() );
    236                 if( statements.empty() ) return {};
    237 
    238                 // We are going to aggregate errors for all these statements
    239                 SemanticErrorException errors;
    240 
    241                 // add a few useful symbols to the scope
    242                 using __pass::empty;
    243 
    244                 // get the stmts/decls that will need to be spliced in
    245                 auto stmts_before = __pass::stmtsToAddBefore( core, 0 );
    246                 auto stmts_after  = __pass::stmtsToAddAfter ( core, 0 );
    247                 auto decls_before = __pass::declsToAddBefore( core, 0 );
    248                 auto decls_after  = __pass::declsToAddAfter ( core, 0 );
    249 
    250                 // These may be modified by subnode but most be restored once we exit this statemnet.
    251                 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
    252                 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
    253                 ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before );
    254                 ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after  );
    255 
    256                 // update pass statitistics
    257                 pass_visitor_stats.depth++;
    258                 pass_visitor_stats.max->push(pass_visitor_stats.depth);
    259                 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    260 
    261                 __pass::resultNstmt<container_t> new_kids;
    262                 for( auto value : enumerate( statements ) ) {
    263                         try {
    264                                 size_t i = value.idx;
    265                                 const Stmt * stmt = value.val;
    266                                 __pedantic_pass_assert( stmt );
    267                                 const ast::Stmt * new_stmt = stmt->accept( *this );
    268                                 assert( new_stmt );
    269                                 if(new_stmt != stmt ) { new_kids.differs = true; }
    270 
    271                                 // Make sure that it is either adding statements or declartions but not both
    272                                 // this is because otherwise the order would be awkward to predict
    273                                 assert(( empty( stmts_before ) && empty( stmts_after ))
    274                                     || ( empty( decls_before ) && empty( decls_after )) );
    275 
    276                                 // Take all the statements which should have gone after, N/A for first iteration
    277                                 new_kids.take_all( decls_before );
    278                                 new_kids.take_all( stmts_before );
    279 
    280                                 // Now add the statement if there is one
    281                                 if(new_stmt != stmt) {
    282                                         new_kids.values.emplace_back( new_stmt, i, false );
    283                                 } else {
    284                                         new_kids.values.emplace_back( nullptr, i, true );
    285                                 }
    286 
    287                                 // Take all the declarations that go before
    288                                 new_kids.take_all( decls_after );
    289                                 new_kids.take_all( stmts_after );
     128}
     129
     130template< typename core_t >
     131template< typename node_t >
     132auto ast::Pass< core_t >::call_accept( const node_t * node ) ->
     133        typename ast::Pass< core_t >::template generic_call_accept_result<node_t>::type
     134{
     135        __pedantic_pass_assert( __visit_children() );
     136        __pedantic_pass_assert( node );
     137
     138        static_assert( !std::is_base_of<ast::Expr, node_t>::value, "ERROR" );
     139        static_assert( !std::is_base_of<ast::Stmt, node_t>::value, "ERROR" );
     140
     141        auto nval = node->accept( *this );
     142        __pass::result1<
     143                typename std::remove_pointer< decltype( node->accept(*this) ) >::type
     144        > res;
     145        res.differs = nval != node;
     146        res.value = nval;
     147        return res;
     148}
     149
     150template< typename core_t >
     151ast::__pass::template result1<ast::Expr> ast::Pass< core_t >::call_accept( const ast::Expr * expr ) {
     152        __pedantic_pass_assert( __visit_children() );
     153        __pedantic_pass_assert( expr );
     154
     155        auto nval = expr->accept( *this );
     156        return { nval != expr, nval };
     157}
     158
     159template< typename core_t >
     160ast::__pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) {
     161        __pedantic_pass_assert( __visit_children() );
     162        __pedantic_pass_assert( stmt );
     163
     164        const ast::Stmt * nval = stmt->accept( *this );
     165        return { nval != stmt, nval };
     166}
     167
     168template< typename core_t >
     169ast::__pass::template result1<ast::Expr> ast::Pass< core_t >::call_accept_top( const ast::Expr * expr ) {
     170        __pedantic_pass_assert( __visit_children() );
     171        __pedantic_pass_assert( expr );
     172
     173        const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 );
     174        if ( typeSubs_ptr && expr->env ) {
     175                *typeSubs_ptr = expr->env;
     176        }
     177
     178        auto nval = expr->accept( *this );
     179        return { nval != expr, nval };
     180}
     181
     182template< typename core_t >
     183ast::__pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {
     184        __pedantic_pass_assert( __visit_children() );
     185        __pedantic_pass_assert( stmt );
     186
     187        // add a few useful symbols to the scope
     188        using __pass::empty;
     189
     190        // get the stmts/decls that will need to be spliced in
     191        auto stmts_before = __pass::stmtsToAddBefore( core, 0 );
     192        auto stmts_after  = __pass::stmtsToAddAfter ( core, 0 );
     193        auto decls_before = __pass::declsToAddBefore( core, 0 );
     194        auto decls_after  = __pass::declsToAddAfter ( core, 0 );
     195
     196        // These may be modified by subnode but most be restored once we exit this statemnet.
     197        ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::typeSubs( core, 0 ) );
     198        ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
     199        ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
     200        ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before );
     201        ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after  );
     202
     203        // Now is the time to actually visit the node
     204        const ast::Stmt * nstmt = stmt->accept( *this );
     205
     206        // If the pass doesn't want to add anything then we are done
     207        if ( empty(stmts_before) && empty(stmts_after) && empty(decls_before) && empty(decls_after) ) {
     208                return { nstmt != stmt, nstmt };
     209        }
     210
     211        // Make sure that it is either adding statements or declartions but not both
     212        // this is because otherwise the order would be awkward to predict
     213        assert(( empty( stmts_before ) && empty( stmts_after ))
     214            || ( empty( decls_before ) && empty( decls_after )) );
     215
     216        // Create a new Compound Statement to hold the new decls/stmts
     217        ast::CompoundStmt * compound = new ast::CompoundStmt( stmt->location );
     218
     219        // Take all the declarations that go before
     220        __pass::take_all( std::back_inserter( compound->kids ), decls_before );
     221        __pass::take_all( std::back_inserter( compound->kids ), stmts_before );
     222
     223        // Insert the original declaration
     224        compound->kids.emplace_back( nstmt );
     225
     226        // Insert all the declarations that go before
     227        __pass::take_all( std::back_inserter( compound->kids ), decls_after );
     228        __pass::take_all( std::back_inserter( compound->kids ), stmts_after );
     229
     230        return { true, compound };
     231}
     232
     233template< typename core_t >
     234template< template <class...> class container_t >
     235ast::__pass::template resultNstmt<container_t> ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
     236        __pedantic_pass_assert( __visit_children() );
     237        if ( statements.empty() ) return {};
     238
     239        // We are going to aggregate errors for all these statements
     240        SemanticErrorException errors;
     241
     242        // add a few useful symbols to the scope
     243        using __pass::empty;
     244
     245        // get the stmts/decls that will need to be spliced in
     246        auto stmts_before = __pass::stmtsToAddBefore( core, 0 );
     247        auto stmts_after  = __pass::stmtsToAddAfter ( core, 0 );
     248        auto decls_before = __pass::declsToAddBefore( core, 0 );
     249        auto decls_after  = __pass::declsToAddAfter ( core, 0 );
     250
     251        // These may be modified by subnode but most be restored once we exit this statemnet.
     252        ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
     253        ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
     254        ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before );
     255        ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after  );
     256
     257        // update pass statitistics
     258        pass_visitor_stats.depth++;
     259        pass_visitor_stats.max->push(pass_visitor_stats.depth);
     260        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
     261
     262        __pass::resultNstmt<container_t> new_kids;
     263        for ( auto value : enumerate( statements ) ) {
     264                try {
     265                        size_t i = value.idx;
     266                        const Stmt * stmt = value.val;
     267                        __pedantic_pass_assert( stmt );
     268                        const ast::Stmt * new_stmt = stmt->accept( *this );
     269                        assert( new_stmt );
     270                        if ( new_stmt != stmt ) { new_kids.differs = true; }
     271
     272                        // Make sure that it is either adding statements or declartions but not both
     273                        // this is because otherwise the order would be awkward to predict
     274                        assert(( empty( stmts_before ) && empty( stmts_after ))
     275                            || ( empty( decls_before ) && empty( decls_after )) );
     276
     277                        // Take all the statements which should have gone after, N/A for first iteration
     278                        new_kids.take_all( decls_before );
     279                        new_kids.take_all( stmts_before );
     280
     281                        // Now add the statement if there is one
     282                        if ( new_stmt != stmt ) {
     283                                new_kids.values.emplace_back( new_stmt, i, false );
     284                        } else {
     285                                new_kids.values.emplace_back( nullptr, i, true );
    290286                        }
    291                         catch ( SemanticErrorException &e ) {
    292                                 errors.append( e );
     287
     288                        // Take all the declarations that go before
     289                        new_kids.take_all( decls_after );
     290                        new_kids.take_all( stmts_after );
     291                } catch ( SemanticErrorException &e ) {
     292                        errors.append( e );
     293                }
     294        }
     295        pass_visitor_stats.depth--;
     296        if ( !errors.isEmpty() ) { throw errors; }
     297
     298        return new_kids;
     299}
     300
     301template< typename core_t >
     302template< template <class...> class container_t, typename node_t >
     303ast::__pass::template resultN<container_t, node_t> ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
     304        __pedantic_pass_assert( __visit_children() );
     305        if ( container.empty() ) return {};
     306        SemanticErrorException errors;
     307
     308        pass_visitor_stats.depth++;
     309        pass_visitor_stats.max->push(pass_visitor_stats.depth);
     310        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
     311
     312        bool mutated = false;
     313        container_t<ptr<node_t>> new_kids;
     314        for ( const node_t * node : container ) {
     315                try {
     316                        __pedantic_pass_assert( node );
     317                        const node_t * new_stmt = strict_dynamic_cast< const node_t * >( node->accept( *this ) );
     318                        if ( new_stmt != node ) {
     319                                mutated = true;
     320                                new_kids.emplace_back( new_stmt );
     321                        } else {
     322                                new_kids.emplace_back( nullptr );
    293323                        }
    294                 }
    295                 pass_visitor_stats.depth--;
    296                 if ( !errors.isEmpty() ) { throw errors; }
    297 
    298                 return new_kids;
    299         }
    300 
    301         template< typename core_t >
    302         template< template <class...> class container_t, typename node_t >
    303         __pass::template resultN<container_t, node_t> ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
    304                 __pedantic_pass_assert( __visit_children() );
    305                 if( container.empty() ) return {};
    306                 SemanticErrorException errors;
    307 
    308                 pass_visitor_stats.depth++;
    309                 pass_visitor_stats.max->push(pass_visitor_stats.depth);
    310                 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    311 
    312                 bool mutated = false;
    313                 container_t<ptr<node_t>> new_kids;
    314                 for ( const node_t * node : container ) {
    315                         try {
    316                                 __pedantic_pass_assert( node );
    317                                 const node_t * new_stmt = strict_dynamic_cast< const node_t * >( node->accept( *this ) );
    318                                 if(new_stmt != node ) {
    319                                         mutated = true;
    320                                         new_kids.emplace_back( new_stmt );
    321                                 } else {
    322                                         new_kids.emplace_back( nullptr );
    323                                 }
    324 
    325                         }
    326                         catch( SemanticErrorException &e ) {
    327                                 errors.append( e );
    328                         }
    329                 }
    330 
    331                 __pedantic_pass_assert( new_kids.size() == container.size() );
    332                 pass_visitor_stats.depth--;
    333                 if ( ! errors.isEmpty() ) { throw errors; }
    334 
    335                 return ast::__pass::resultN<container_t, node_t>{ mutated, new_kids };
    336         }
    337 
    338         template< typename core_t >
    339         template<typename node_t, typename super_t, typename field_t>
    340         void ast::Pass< core_t >::maybe_accept(
    341                 const node_t * & parent,
    342                 field_t super_t::*field
    343         ) {
    344                 static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
    345 
    346                 if(__pass::skip(parent->*field)) return;
    347                 const auto & old_val = __pass::get(parent->*field, 0);
    348 
    349                 static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
    350 
    351                 auto new_val = call_accept( old_val );
    352 
    353                 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR");
    354 
    355                 if( new_val.differs ) {
    356                         auto new_parent = __pass::mutate<core_t>(parent);
    357                         new_val.apply(new_parent, field);
    358                         parent = new_parent;
    359                 }
    360         }
    361 
    362         template< typename core_t >
    363         template<typename node_t, typename super_t, typename field_t>
    364         void ast::Pass< core_t >::maybe_accept_top(
    365                 const node_t * & parent,
    366                 field_t super_t::*field
    367         ) {
    368                 static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
    369 
    370                 if(__pass::skip(parent->*field)) return;
    371                 const auto & old_val = __pass::get(parent->*field, 0);
    372 
    373                 static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
    374 
    375                 auto new_val = call_accept_top( old_val );
    376 
    377                 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR");
    378 
    379                 if( new_val.differs ) {
    380                         auto new_parent = __pass::mutate<core_t>(parent);
    381                         new_val.apply(new_parent, field);
    382                         parent = new_parent;
    383                 }
    384         }
    385 
    386         template< typename core_t >
    387         template<typename node_t, typename super_t, typename field_t>
    388         void ast::Pass< core_t >::maybe_accept_as_compound(
    389                 const node_t * & parent,
    390                 field_t super_t::*child
    391         ) {
    392                 static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
    393 
    394                 if(__pass::skip(parent->*child)) return;
    395                 const auto & old_val = __pass::get(parent->*child, 0);
    396 
    397                 static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
    398 
    399                 auto new_val = call_accept_as_compound( old_val );
    400 
    401                 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");
    402 
    403                 if( new_val.differs ) {
    404                         auto new_parent = __pass::mutate<core_t>(parent);
    405                         new_val.apply( new_parent, child );
    406                         parent = new_parent;
    407                 }
    408         }
    409 
     324                } catch ( SemanticErrorException &e ) {
     325                        errors.append( e );
     326                }
     327        }
     328
     329        __pedantic_pass_assert( new_kids.size() == container.size() );
     330        pass_visitor_stats.depth--;
     331        if ( !errors.isEmpty() ) { throw errors; }
     332
     333        return ast::__pass::resultN<container_t, node_t>{ mutated, new_kids };
     334}
     335
     336template< typename core_t >
     337template<typename node_t, typename super_t, typename field_t>
     338void ast::Pass< core_t >::maybe_accept(
     339        const node_t * & parent,
     340        field_t super_t::*field
     341) {
     342        static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
     343
     344        if ( __pass::skip( parent->*field ) ) return;
     345        const auto & old_val = __pass::get(parent->*field, 0);
     346
     347        static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR" );
     348
     349        auto new_val = call_accept( old_val );
     350
     351        static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR" );
     352
     353        if ( new_val.differs ) {
     354                auto new_parent = __pass::mutate<core_t>(parent);
     355                new_val.apply(new_parent, field);
     356                parent = new_parent;
     357        }
     358}
     359
     360template< typename core_t >
     361template<typename node_t, typename super_t, typename field_t>
     362void ast::Pass< core_t >::maybe_accept_top(
     363        const node_t * & parent,
     364        field_t super_t::*field
     365) {
     366        static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
     367
     368        if ( __pass::skip( parent->*field ) ) return;
     369        const auto & old_val = __pass::get(parent->*field, 0);
     370
     371        static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR" );
     372
     373        auto new_val = call_accept_top( old_val );
     374
     375        static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR" );
     376
     377        if ( new_val.differs ) {
     378                auto new_parent = __pass::mutate<core_t>(parent);
     379                new_val.apply(new_parent, field);
     380                parent = new_parent;
     381        }
     382}
     383
     384template< typename core_t >
     385template<typename node_t, typename super_t, typename field_t>
     386void ast::Pass< core_t >::maybe_accept_as_compound(
     387        const node_t * & parent,
     388        field_t super_t::*child
     389) {
     390        static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
     391
     392        if ( __pass::skip( parent->*child ) ) return;
     393        const auto & old_val = __pass::get(parent->*child, 0);
     394
     395        static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR" );
     396
     397        auto new_val = call_accept_as_compound( old_val );
     398
     399        static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR" );
     400
     401        if ( new_val.differs ) {
     402                auto new_parent = __pass::mutate<core_t>(parent);
     403                new_val.apply( new_parent, child );
     404                parent = new_parent;
     405        }
    410406}
    411407
     
    761757
    762758        if ( __visit_children() ) {
    763                 // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result.
    764                 auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() {
    765                         if ( enterScope ) {
    766                                 __pass::symtab::enter(core, 0);
    767                         }
    768                 }, [this, leaveScope = !this->atFunctionTop]() {
    769                         if ( leaveScope ) {
    770                                 __pass::symtab::leave(core, 0);
    771                         }
    772                 });
    773                 ValueGuard< bool > guard2( atFunctionTop );
    774                 atFunctionTop = false;
    775                 guard_scope guard3 { *this };
    776                 maybe_accept( node, &CompoundStmt::kids );
     759                // Do not enter (or leave) a new symbol table scope if atFunctionTop.
     760                // But always enter (and leave) a new general scope.
     761                if ( atFunctionTop ) {
     762                        ValueGuard< bool > guard1( atFunctionTop );
     763                        atFunctionTop = false;
     764                        guard_scope guard2( *this );
     765                        maybe_accept( node, &CompoundStmt::kids );
     766                } else {
     767                        guard_symtab guard1( *this );
     768                        guard_scope guard2( *this );
     769                        maybe_accept( node, &CompoundStmt::kids );
     770                }
    777771        }
    778772
  • src/AST/SymbolTable.cpp

    rfa5e1aa5 rb7b3e41  
    1919
    2020#include "Copy.hpp"
     21#include <iostream>
     22#include <algorithm>
     23
    2124#include "Decl.hpp"
    2225#include "Expr.hpp"
     
    8891}
    8992
    90 SymbolTable::SymbolTable()
     93SymbolTable::SymbolTable( ErrorDetection errorMode )
    9194: idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(),
    92   prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }
     95  prevScope(), scope( 0 ), repScope( 0 ), errorMode(errorMode) { ++*stats().count; }
    9396
    9497SymbolTable::~SymbolTable() { stats().size->push( idTable ? idTable->size() : 0 ); }
     98
     99void SymbolTable::OnFindError( CodeLocation location, std::string error ) const {
     100        assertf( errorMode != AssertClean, "Name collision/redefinition, found during a compilation phase where none should be possible.  Detail: %s", error.c_str() );
     101        if (errorMode == ValidateOnAdd) {
     102                SemanticError(location, error);
     103        }
     104        assertf( errorMode == IgnoreErrors, "Unrecognized symbol-table error mode %d", errorMode );
     105}
    95106
    96107void SymbolTable::enterScope() {
     
    195206                        out.push_back(decl.second);
    196207                }
     208
     209                // std::cerr << otypeKey << ' ' << out.size() << std::endl;
    197210        }
    198211
     
    269282}
    270283
    271 namespace {
    272         /// true if redeclaration conflict between two types
    273         bool addedTypeConflicts( const NamedTypeDecl * existing, const NamedTypeDecl * added ) {
    274                 if ( existing->base == nullptr ) {
    275                         return false;
    276                 } else if ( added->base == nullptr ) {
    277                         return true;
    278                 } else {
    279                         // typedef redeclarations are errors only if types are different
    280                         if ( ! ResolvExpr::typesCompatible( existing->base, added->base ) ) {
    281                                 SemanticError( added->location, "redeclaration of " + added->name );
    282                         }
    283                 }
    284                 // does not need to be added to the table if both existing and added have a base that are
    285                 // the same
     284bool SymbolTable::addedTypeConflicts(
     285                const NamedTypeDecl * existing, const NamedTypeDecl * added ) const {
     286        if ( existing->base == nullptr ) {
     287                return false;
     288        } else if ( added->base == nullptr ) {
    286289                return true;
    287         }
    288 
    289         /// true if redeclaration conflict between two aggregate declarations
    290         bool addedDeclConflicts( const AggregateDecl * existing, const AggregateDecl * added ) {
    291                 if ( ! existing->body ) {
    292                         return false;
    293                 } else if ( added->body ) {
    294                         SemanticError( added, "redeclaration of " );
    295                 }
    296                 return true;
    297         }
     290        } else {
     291                // typedef redeclarations are errors only if types are different
     292                if ( ! ResolvExpr::typesCompatible( existing->base, added->base ) ) {
     293                        OnFindError( added->location, "redeclaration of " + added->name );
     294                }
     295        }
     296        // does not need to be added to the table if both existing and added have a base that are
     297        // the same
     298        return true;
     299}
     300
     301bool SymbolTable::addedDeclConflicts(
     302                const AggregateDecl * existing, const AggregateDecl * added ) const {
     303        if ( ! existing->body ) {
     304                return false;
     305        } else if ( added->body ) {
     306                OnFindError( added, "redeclaration of " );
     307        }
     308        return true;
    298309}
    299310
     
    648659                if ( deleter && ! existing.deleter ) {
    649660                        if ( handleConflicts.mode == OnConflict::Error ) {
    650                                 SemanticError( added, "deletion of defined identifier " );
     661                                OnFindError( added, "deletion of defined identifier " );
    651662                        }
    652663                        return true;
    653664                } else if ( ! deleter && existing.deleter ) {
    654665                        if ( handleConflicts.mode == OnConflict::Error ) {
    655                                 SemanticError( added, "definition of deleted identifier " );
     666                                OnFindError( added, "definition of deleted identifier " );
    656667                        }
    657668                        return true;
     
    661672                if ( isDefinition( added ) && isDefinition( existing.id ) ) {
    662673                        if ( handleConflicts.mode == OnConflict::Error ) {
    663                                 SemanticError( added,
     674                                OnFindError( added,
    664675                                        isFunction( added ) ?
    665676                                                "duplicate function definition for " :
     
    670681        } else {
    671682                if ( handleConflicts.mode == OnConflict::Error ) {
    672                         SemanticError( added, "duplicate definition for " );
     683                        OnFindError( added, "duplicate definition for " );
    673684                }
    674685                return true;
     
    722733                // Check that a Cforall declaration doesn't override any C declaration
    723734                if ( hasCompatibleCDecl( name, mangleName ) ) {
    724                         SemanticError( decl, "Cforall declaration hides C function " );
     735                        OnFindError( decl, "Cforall declaration hides C function " );
    725736                }
    726737        } else {
     
    728739                // type-compatibility, which it may not be.
    729740                if ( hasIncompatibleCDecl( name, mangleName ) ) {
    730                         SemanticError( decl, "conflicting overload of C function " );
     741                        OnFindError( decl, "conflicting overload of C function " );
    731742                }
    732743        }
  • src/AST/SymbolTable.hpp

    rfa5e1aa5 rb7b3e41  
    9393
    9494public:
    95         SymbolTable();
     95
     96        /// Mode to control when (during which pass) user-caused name-declaration errors get reported.
     97        /// The default setting `AssertClean` supports, "I expect all user-caused errors to have been
     98        /// reported by now," or, "I wouldn't know what to do with an error; are there even any here?"
     99        enum ErrorDetection {
     100                AssertClean,               ///< invalid user decls => assert fails during addFoo (default)
     101                ValidateOnAdd,             ///< invalid user decls => calls SemanticError during addFoo
     102                IgnoreErrors               ///< acts as if unspecified decls were removed, forcing validity
     103        };
     104
     105        explicit SymbolTable(
     106                ErrorDetection             ///< mode for the lifetime of the symbol table (whole pass)
     107        );
     108        SymbolTable() : SymbolTable(AssertClean) {}
    96109        ~SymbolTable();
     110
     111        ErrorDetection getErrorMode() const {
     112                return errorMode;
     113        }
    97114
    98115        // when using an indexer manually (e.g., within a mutator traversal), it is necessary to
     
    158175
    159176private:
     177        void OnFindError( CodeLocation location, std::string error ) const;
     178
     179        template< typename T >
     180        void OnFindError( const T * obj, const std::string & error ) const {
     181                OnFindError( obj->location, toString( error, obj ) );
     182        }
     183
     184        template< typename T >
     185        void OnFindError( CodeLocation location, const T * obj, const std::string & error ) const {
     186                OnFindError( location, toString( error, obj ) );
     187        }
     188
    160189        /// Ensures that a proper backtracking scope exists before a mutation
    161190        void lazyInitScope();
     
    168197        bool removeSpecialOverrides( IdData & decl, MangleTable::Ptr & mangleTable );
    169198
    170         /// Options for handling identifier conflicts
     199        /// Error detection mode given at construction (pass-specific).
     200        /// Logically const, except that the symbol table's push-pop is achieved by autogenerated
     201        /// assignment onto self.  The feield is left motuable to keep this code-gen simple.
     202        /// Conceptual constness is preserved by all SymbolTable in a stack sharing the same mode.
     203        ErrorDetection errorMode;
     204
     205        /// Options for handling identifier conflicts.
     206        /// Varies according to AST location during traversal: captures semantics of the construct
     207        /// being visited as "would shadow" vs "must not collide."
     208        /// At a given AST location, is the same for every pass.
    171209        struct OnConflict {
    172210                enum {
    173                         Error,  ///< Throw a semantic error
     211                        Error,  ///< Follow the current pass's ErrorDetection mode (may throw a semantic error)
    174212                        Delete  ///< Delete the earlier version with the delete statement
    175213                } mode;
     
    191229                const Decl * deleter );
    192230
     231        /// true if redeclaration conflict between two types
     232        bool addedTypeConflicts( const NamedTypeDecl * existing, const NamedTypeDecl * added ) const;
     233
     234        /// true if redeclaration conflict between two aggregate declarations
     235        bool addedDeclConflicts( const AggregateDecl * existing, const AggregateDecl * added ) const;
     236
    193237        /// common code for addId, addDeletedId, etc.
    194238        void addIdCommon(
     
    213257}
    214258
     259
    215260// Local Variables: //
    216261// tab-width: 4 //
  • src/AST/Type.hpp

    rfa5e1aa5 rb7b3e41  
    451451        bool operator==(const TypeEnvKey & other) const;
    452452        bool operator<(const TypeEnvKey & other) const;
    453 };
     453        operator bool() {return base;}
     454};
     455
    454456
    455457/// tuple type e.g. `[int, char]`
  • src/AST/TypeEnvironment.cpp

    rfa5e1aa5 rb7b3e41  
    135135                }
    136136        }
    137         sub.normalize();
     137        // sub.normalize();
    138138}
    139139
  • src/AST/TypeEnvironment.hpp

    rfa5e1aa5 rb7b3e41  
    6363
    6464                int cmp = d1->var->name.compare( d2->var->name );
    65                 return cmp < 0 || ( cmp == 0 && d1->result < d2->result );
     65                return cmp > 0 || ( cmp == 0 && d1->result < d2->result );
    6666        }
    6767};
  • src/AST/Util.cpp

    rfa5e1aa5 rb7b3e41  
    8383}
    8484
     85/// Check that the MemberExpr has an aggregate type and matching member.
     86void memberMatchesAggregate( const MemberExpr * expr ) {
     87        const Type * aggrType = expr->aggregate->result->stripReferences();
     88        const AggregateDecl * decl = nullptr;
     89        if ( auto inst = dynamic_cast<const StructInstType *>( aggrType ) ) {
     90                decl = inst->base;
     91        } else if ( auto inst = dynamic_cast<const UnionInstType *>( aggrType ) ) {
     92                decl = inst->base;
     93        }
     94        assertf( decl, "Aggregate of member not correct type." );
     95
     96        for ( auto aggrMember : decl->members ) {
     97                if ( expr->member == aggrMember ) {
     98                        return;
     99                }
     100        }
     101        assertf( false, "Member not found." );
     102}
     103
    85104struct InvariantCore {
    86105        // To save on the number of visits: this is a kind of composed core.
     
    108127        }
    109128
     129        void previsit( const MemberExpr * node ) {
     130                previsit( (const ParseNode *)node );
     131                memberMatchesAggregate( node );
     132        }
     133
    110134        void postvisit( const Node * node ) {
    111135                no_strong_cycles.postvisit( node );
  • src/Common/Eval.cc

    rfa5e1aa5 rb7b3e41  
    9696// New AST
    9797struct EvalNew : public ast::WithShortCircuiting {
    98         long long int value = 0;                                                        // compose the result of the constant expression
    99         bool valid = true;                                                                      // true => constant expression and value is the result
    100                                                                                                                 // false => not constant expression, e.g., ++i
    101         bool cfavalid = true;                                                           // true => constant expression and value computable
    102                                                                                                                 // false => constant expression but value not computable, e.g., sizeof(int)
     98        Evaluation result = { 0, true, true };
    10399
    104100        void previsit( const ast::Node * ) { visit_children = false; }
    105         void postvisit( const ast::Node * ) { cfavalid = valid = false; }
     101        void postvisit( const ast::Node * ) { result.isEvaluableInGCC = result.hasKnownValue = false; }
    106102
    107103        void postvisit( const ast::UntypedExpr * ) {
     
    110106
    111107        void postvisit( const ast::ConstantExpr * expr ) {      // only handle int constants
    112                 value = expr->intValue();
     108                result.knownValue = expr->intValue();
     109                result.hasKnownValue = true;
     110                result.isEvaluableInGCC = true;
    113111        }
    114112
    115113        void postvisit( const ast::SizeofExpr * ) {
    116                 // do not change valid or value => let C figure it out
    117                 cfavalid = false;
     114                result.hasKnownValue = false;
     115                result.isEvaluableInGCC = true;
    118116        }
    119117
    120118        void postvisit( const ast::AlignofExpr * ) {
    121                 // do not change valid or value => let C figure it out
    122                 cfavalid = false;
     119                result.hasKnownValue = false;
     120                result.isEvaluableInGCC = true;
    123121        }
    124122
    125123        void postvisit( const ast::OffsetofExpr * ) {
    126                 // do not change valid or value => let C figure it out
    127                 cfavalid = false;
     124                result.hasKnownValue = false;
     125                result.isEvaluableInGCC = true;
    128126        }
    129127
    130128        void postvisit( const ast::LogicalExpr * expr ) {
    131                 std::pair<long long int, bool> arg1, arg2;
     129                Evaluation arg1, arg2;
    132130                arg1 = eval( expr->arg1 );
    133                 valid &= arg1.second;
    134                 if ( ! valid ) return;
     131                result.isEvaluableInGCC &= arg1.isEvaluableInGCC;
     132                if ( ! result.isEvaluableInGCC ) return;
    135133                arg2 = eval( expr->arg2 );
    136                 valid &= arg2.second;
    137                 if ( ! valid ) return;
     134                result.isEvaluableInGCC &= arg2.isEvaluableInGCC;
     135                if ( ! result.isEvaluableInGCC ) return;
     136
     137                result.hasKnownValue &= arg1.hasKnownValue;
     138                result.hasKnownValue &= arg2.hasKnownValue;
     139                if ( ! result.hasKnownValue ) return;
    138140
    139141                if ( expr->isAnd ) {
    140                         value = arg1.first && arg2.first;
     142                        result.knownValue = arg1.knownValue && arg2.knownValue;
    141143                } else {
    142                         value = arg1.first || arg2.first;
     144                        result.knownValue = arg1.knownValue || arg2.knownValue;
    143145                } // if
    144146        }
    145147
    146148        void postvisit( const ast::ConditionalExpr * expr ) {
    147                 std::pair<long long int, bool> arg1, arg2, arg3;
     149                Evaluation arg1, arg2, arg3;
    148150                arg1 = eval( expr->arg1 );
    149                 valid &= arg1.second;
    150                 if ( ! valid ) return;
     151                result.isEvaluableInGCC &= arg1.isEvaluableInGCC;
     152                if ( ! result.isEvaluableInGCC ) return;
    151153                arg2 = eval( expr->arg2 );
    152                 valid &= arg2.second;
    153                 if ( ! valid ) return;
     154                result.isEvaluableInGCC &= arg2.isEvaluableInGCC;
     155                if ( ! result.isEvaluableInGCC ) return;
    154156                arg3 = eval( expr->arg3 );
    155                 valid &= arg3.second;
    156                 if ( ! valid ) return;
    157 
    158                 value = arg1.first ? arg2.first : arg3.first;
     157                result.isEvaluableInGCC &= arg3.isEvaluableInGCC;
     158                if ( ! result.isEvaluableInGCC ) return;
     159
     160                result.hasKnownValue &= arg1.hasKnownValue;
     161                result.hasKnownValue &= arg2.hasKnownValue;
     162                result.hasKnownValue &= arg3.hasKnownValue;
     163                if ( ! result.hasKnownValue ) return;
     164
     165                result.knownValue = arg1.knownValue ? arg2.knownValue : arg3.knownValue;
    159166        }
    160167
    161168        void postvisit( const ast::CastExpr * expr ) {         
    162                 // cfa-cc generates a cast before every constant and many other places, e.g., (int)3, so the cast argument must
    163                 // be evaluated to get the constant value.
    164                 auto arg = eval(expr->arg);
    165                 valid = arg.second;
    166                 value = arg.first;
    167                 cfavalid = false;
     169                // cfa-cc generates a cast before every constant and many other places, e.g., (int)3,
     170                // so we must use the value from the cast argument, even though we lack any basis for evaluating wraparound effects, etc
     171                result = eval(expr->arg);
    168172        }
    169173
    170174        void postvisit( const ast::VariableExpr * expr ) {
     175                result.hasKnownValue = false;
     176                result.isEvaluableInGCC = false;
    171177                if ( const ast::EnumInstType * inst = dynamic_cast<const ast::EnumInstType *>(expr->result.get()) ) {
    172178                        if ( const ast::EnumDecl * decl = inst->base ) {
    173                                 if ( decl->valueOf( expr->var, value ) ) { // value filled by valueOf
    174                                         return;
    175                                 }
     179                                result.isEvaluableInGCC = true;
     180                                result.hasKnownValue = decl->valueOf( expr->var, result.knownValue ); // result.knownValue filled by valueOf
    176181                        }
    177182                }
    178                 valid = false;
    179183        }
    180184
    181185        void postvisit( const ast::ApplicationExpr * expr ) {
    182186                const ast::DeclWithType * function = ast::getFunction(expr);
    183                 if ( ! function || function->linkage != ast::Linkage::Intrinsic ) { valid = false; return; }
     187                if ( ! function || function->linkage != ast::Linkage::Intrinsic ) {
     188                        result.isEvaluableInGCC = false;
     189                        result.hasKnownValue = false;
     190                        return;
     191                }
    184192                const std::string & fname = function->name;
    185193                assertf( expr->args.size() == 1 || expr->args.size() == 2, "Intrinsic function with %zd arguments: %s", expr->args.size(), fname.c_str() );
     
    187195                if ( expr->args.size() == 1 ) {
    188196                        // pre/postfix operators ++ and -- => assignment, which is not constant
    189                         std::pair<long long int, bool> arg1;
     197                        Evaluation arg1;
    190198                        arg1 = eval(expr->args.front());
    191                         valid &= arg1.second;
    192                         if ( ! valid ) return;
     199                        result.isEvaluableInGCC &= arg1.isEvaluableInGCC;
     200                        if ( ! result.isEvaluableInGCC ) return;
     201
     202                        result.hasKnownValue &= arg1.hasKnownValue;
     203                        if ( ! result.hasKnownValue ) return;
    193204
    194205                        if (fname == "+?") {
    195                                 value = arg1.first;
     206                                result.knownValue = arg1.knownValue;
    196207                        } else if (fname == "-?") {
    197                                 value = -arg1.first;
     208                                result.knownValue = -arg1.knownValue;
    198209                        } else if (fname == "~?") {
    199                                 value = ~arg1.first;
     210                                result.knownValue = ~arg1.knownValue;
    200211                        } else if (fname == "!?") {
    201                                 value = ! arg1.first;
     212                                result.knownValue = ! arg1.knownValue;
    202213                        } else {
    203                                 valid = false;
     214                                result.isEvaluableInGCC = false;
     215                                result.hasKnownValue = false;
    204216                        } // if
    205217                } else { // => expr->args.size() == 2
    206218                        // infix assignment operators => assignment, which is not constant
    207                         std::pair<long long int, bool> arg1, arg2;
     219                        Evaluation arg1, arg2;
    208220                        arg1 = eval(expr->args.front());
    209                         valid &= arg1.second;
    210                         if ( ! valid ) return;
     221                        result.isEvaluableInGCC &= arg1.isEvaluableInGCC;
     222                        if ( ! result.isEvaluableInGCC ) return;
    211223                        arg2 = eval(expr->args.back());
    212                         valid &= arg2.second;
    213                         if ( ! valid ) return;
     224                        result.isEvaluableInGCC &= arg2.isEvaluableInGCC;
     225                        if ( ! result.isEvaluableInGCC ) return;
     226
     227                        result.hasKnownValue &= arg1.hasKnownValue;
     228                        result.hasKnownValue &= arg2.hasKnownValue;
     229                        if ( ! result.hasKnownValue ) return;
    214230
    215231                        if (fname == "?+?") {
    216                                 value = arg1.first + arg2.first;
     232                                result.knownValue = arg1.knownValue + arg2.knownValue;
    217233                        } else if (fname == "?-?") {
    218                                 value = arg1.first - arg2.first;
     234                                result.knownValue = arg1.knownValue - arg2.knownValue;
    219235                        } else if (fname == "?*?") {
    220                                 value = arg1.first * arg2.first;
     236                                result.knownValue = arg1.knownValue * arg2.knownValue;
    221237                        } else if (fname == "?/?") {
    222                                 if ( arg2.first ) value = arg1.first / arg2.first;
     238                                if ( arg2.knownValue ) result.knownValue = arg1.knownValue / arg2.knownValue;
    223239                        } else if (fname == "?%?") {
    224                                 if ( arg2.first ) value = arg1.first % arg2.first;
     240                                if ( arg2.knownValue ) result.knownValue = arg1.knownValue % arg2.knownValue;
    225241                        } else if (fname == "?<<?") {
    226                                 value = arg1.first << arg2.first;
     242                                result.knownValue = arg1.knownValue << arg2.knownValue;
    227243                        } else if (fname == "?>>?") {
    228                                 value = arg1.first >> arg2.first;
     244                                result.knownValue = arg1.knownValue >> arg2.knownValue;
    229245                        } else if (fname == "?<?") {
    230                                 value = arg1.first < arg2.first;
     246                                result.knownValue = arg1.knownValue < arg2.knownValue;
    231247                        } else if (fname == "?>?") {
    232                                 value = arg1.first > arg2.first;
     248                                result.knownValue = arg1.knownValue > arg2.knownValue;
    233249                        } else if (fname == "?<=?") {
    234                                 value = arg1.first <= arg2.first;
     250                                result.knownValue = arg1.knownValue <= arg2.knownValue;
    235251                        } else if (fname == "?>=?") {
    236                                 value = arg1.first >= arg2.first;
     252                                result.knownValue = arg1.knownValue >= arg2.knownValue;
    237253                        } else if (fname == "?==?") {
    238                                 value = arg1.first == arg2.first;
     254                                result.knownValue = arg1.knownValue == arg2.knownValue;
    239255                        } else if (fname == "?!=?") {
    240                                 value = arg1.first != arg2.first;
     256                                result.knownValue = arg1.knownValue != arg2.knownValue;
    241257                        } else if (fname == "?&?") {
    242                                 value = arg1.first & arg2.first;
     258                                result.knownValue = arg1.knownValue & arg2.knownValue;
    243259                        } else if (fname == "?^?") {
    244                                 value = arg1.first ^ arg2.first;
     260                                result.knownValue = arg1.knownValue ^ arg2.knownValue;
    245261                        } else if (fname == "?|?") {
    246                                 value = arg1.first | arg2.first;
     262                                result.knownValue = arg1.knownValue | arg2.knownValue;
    247263                        } else {
    248                                 valid = false;
     264                                result.isEvaluableInGCC = false;
     265                                result.hasKnownValue = false;
    249266                        }
    250267                } // if
     
    263280}
    264281
    265 std::pair<long long int, bool> eval( const ast::Expr * expr ) {
    266         ast::Pass<EvalNew> ev;
     282Evaluation eval( const ast::Expr * expr ) {
    267283        if ( expr ) {
    268                 expr->accept( ev );
    269                 return std::make_pair( ev.core.value, ev.core.valid );
     284
     285                return ast::Pass<EvalNew>::read(expr);
     286                // Evaluation ret = ast::Pass<EvalNew>::read(expr);
     287                // ret.knownValue = 777;
     288                // return ret;
     289
    270290        } else {
    271                 return std::make_pair( 0, false );
     291                return { 0, false, false };
    272292        }
    273293}
  • src/Common/Eval.h

    rfa5e1aa5 rb7b3e41  
    2323}
    2424
     25struct Evaluation {
     26        long long int knownValue;
     27        bool hasKnownValue;
     28        bool isEvaluableInGCC;
     29};
     30
    2531/// Evaluates expr as a long long int.
    2632/// If second is false, expr could not be evaluated.
    2733std::pair<long long int, bool> eval(const Expression * expr);
    28 std::pair<long long int, bool> eval(const ast::Expr * expr);
     34Evaluation eval(const ast::Expr * expr);
    2935
    3036// Local Variables: //
  • src/Concurrency/Actors.cpp

    rfa5e1aa5 rb7b3e41  
    3838    bool namedDecl = false;
    3939
    40     // finds and sets a ptr to the Allocation enum, which is needed in the next pass
     40    // finds and sets a ptr to the allocation enum, which is needed in the next pass
    4141    void previsit( const EnumDecl * decl ) {
    42         if( decl->name == "Allocation" ) *allocationDecl = decl;
     42        if( decl->name == "allocation" ) *allocationDecl = decl;
    4343    }
    4444
     
    227227                static inline derived_actor & ?|?( derived_actor & receiver, derived_msg & msg ) {
    228228                    request new_req;
    229                     Allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive;
     229                    allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive;
    230230                    __receive_fn fn = (__receive_fn)my_work_fn;
    231231                    new_req{ &receiver, &msg, fn };
     
    246246            ));
    247247           
    248             // Function type is: Allocation (*)( derived_actor &, derived_msg & )
     248            // Function type is: allocation (*)( derived_actor &, derived_msg & )
    249249            FunctionType * derivedReceive = new FunctionType();
    250250            derivedReceive->params.push_back( ast::deepCopy( derivedActorRef ) );
     
    252252            derivedReceive->returns.push_back( new EnumInstType( *allocationDecl ) );
    253253
    254             // Generates: Allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive;
     254            // Generates: allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive;
    255255            sendBody->push_back( new DeclStmt(
    256256                decl->location,
     
    263263            ));
    264264
    265             // Function type is: Allocation (*)( actor &, message & )
     265            // Function type is: allocation (*)( actor &, message & )
    266266            FunctionType * genericReceive = new FunctionType();
    267267            genericReceive->params.push_back( new ReferenceType( new StructInstType( *actorDecl ) ) );
     
    269269            genericReceive->returns.push_back( new EnumInstType( *allocationDecl ) );
    270270
    271             // Generates: Allocation (*fn)( actor &, message & ) = (Allocation (*)( actor &, message & ))my_work_fn;
     271            // Generates: allocation (*fn)( actor &, message & ) = (allocation (*)( actor &, message & ))my_work_fn;
    272272            // More readable synonymous code:
    273             //     typedef Allocation (*__receive_fn)(actor &, message &);
     273            //     typedef allocation (*__receive_fn)(actor &, message &);
    274274            //     __receive_fn fn = (__receive_fn)my_work_fn;
    275275            sendBody->push_back( new DeclStmt(
     
    285285            ));
    286286
    287             // Generates: new_req{ &receiver, &msg, fn };
     287            // Generates: new_req{ &receiver, (actor *)&receiver, &msg, (message *)&msg, fn };
    288288            sendBody->push_back( new ExprStmt(
    289289                decl->location,
     
    294294                                                new NameExpr( decl->location, "new_req" ),
    295295                        new AddressExpr( new NameExpr( decl->location, "receiver" ) ),
     296                        new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "receiver" ) ), new PointerType( new StructInstType( *actorDecl ) ), ExplicitCast ),
    296297                        new AddressExpr( new NameExpr( decl->location, "msg" ) ),
     298                        new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "msg" ) ), new PointerType( new StructInstType( *msgDecl ) ), ExplicitCast ),
    297299                        new NameExpr( decl->location, "fn" )
    298300                                        }
     
    321323            FunctionDecl * sendOperatorFunction = new FunctionDecl(
    322324                decl->location,
    323                 "?<<?",
     325                "?|?",
    324326                {},                     // forall
    325327                {
     
    422424    const StructDecl ** msgDecl = &msgDeclPtr;
    423425
    424     // first pass collects ptrs to Allocation enum, request type, and generic receive fn typedef
     426    // first pass collects ptrs to allocation enum, request type, and generic receive fn typedef
    425427    // also populates maps of all derived actors and messages
    426428    Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
  • src/GenPoly/SpecializeNew.cpp

    rfa5e1aa5 rb7b3e41  
    113113        using namespace ResolvExpr;
    114114        ast::OpenVarSet openVars, closedVars;
    115         ast::AssertionSet need, have;
    116         findOpenVars( formalType, openVars, closedVars, need, have, FirstClosed );
    117         findOpenVars( actualType, openVars, closedVars, need, have, FirstOpen );
     115        ast::AssertionSet need, have; // unused
     116        ast::TypeEnvironment env; // unused
     117        // findOpenVars( formalType, openVars, closedVars, need, have, FirstClosed );
     118        findOpenVars( actualType, openVars, closedVars, need, have, env, FirstOpen );
    118119        for ( const ast::OpenVarSet::value_type & openVar : openVars ) {
    119120                const ast::Type * boundType = subs->lookup( openVar.first );
     
    125126                        if ( closedVars.find( *inst ) == closedVars.end() ) {
    126127                                return true;
     128                        }
     129                        else {
     130                                assertf(false, "closed: %s", inst->name.c_str());
    127131                        }
    128132                // Otherwise, the variable is bound to a concrete type.
  • src/Parser/DeclarationNode.cc

    rfa5e1aa5 rb7b3e41  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 12:34:05 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Apr 20 11:46:00 2023
    13 // Update Count     : 1393
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Jun 17 14:41:48 2023
     13// Update Count     : 1405
    1414//
    1515
     
    459459        std::vector<ast::ptr<ast::Expr>> exprs;
    460460        buildList( expr, exprs );
    461         newnode->attributes.push_back(
    462                 new ast::Attribute( *name, std::move( exprs ) ) );
     461        newnode->attributes.push_back( new ast::Attribute( *name, std::move( exprs ) ) );
    463462        delete name;
    464463        return newnode;
     
    633632                                        dst->basictype = src->basictype;
    634633                                } else if ( src->basictype != DeclarationNode::NoBasicType )
    635                                         SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: " );
     634                                        SemanticError( yylloc, string( "multiple declaration types \"" ) + DeclarationNode::basicTypeNames[ dst->basictype ] +
     635                                                                   "\" and \"" + DeclarationNode::basicTypeNames[ src->basictype ] + "\"." );
    636636
    637637                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
    638638                                        dst->complextype = src->complextype;
    639639                                } else if ( src->complextype != DeclarationNode::NoComplexType )
    640                                         SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: " );
     640                                        SemanticError( yylloc, string( "multiple declaration types \"" ) + DeclarationNode::complexTypeNames[ src->complextype ] +
     641                                                                   "\" and \"" + DeclarationNode::complexTypeNames[ src->complextype ] + "\"." );
    641642
    642643                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
    643644                                        dst->signedness = src->signedness;
    644645                                } else if ( src->signedness != DeclarationNode::NoSignedness )
    645                                         SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: " );
     646                                        SemanticError( yylloc, string( "conflicting type specifier \"" ) + DeclarationNode::signednessNames[ dst->signedness ] +
     647                                                                   "\" and \"" + DeclarationNode::signednessNames[ src->signedness ] + "\"." );
    646648
    647649                                if ( dst->length == DeclarationNode::NoLength ) {
     
    650652                                        dst->length = DeclarationNode::LongLong;
    651653                                } else if ( src->length != DeclarationNode::NoLength )
    652                                         SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: " );
     654                                        SemanticError( yylloc, string( "conflicting type specifier \"" ) + DeclarationNode::lengthNames[ dst->length ] +
     655                                                                   "\" and \"" + DeclarationNode::lengthNames[ src->length ] + "\"." );
    653656                        } // if
    654657                        break;
     
    718721
    719722DeclarationNode * DeclarationNode::addEnumBase( DeclarationNode * o ) {
    720         if ( o && o -> type)  {
     723        if ( o && o->type)  {
    721724                type->base= o->type;
    722         }
     725        } // if
    723726        delete o;
    724727        return this;
     
    10031006}
    10041007
    1005 // If a typedef wraps an anonymous declaration, name the inner declaration
    1006 // so it has a consistent name across translation units.
     1008// If a typedef wraps an anonymous declaration, name the inner declaration so it has a consistent name across
     1009// translation units.
    10071010static void nameTypedefedDecl(
    10081011                DeclarationNode * innerDecl,
     
    10851088}
    10861089
    1087 void buildList( DeclarationNode * firstNode,
    1088                 std::vector<ast::ptr<ast::Decl>> & outputList ) {
     1090void buildList( DeclarationNode * firstNode, std::vector<ast::ptr<ast::Decl>> & outputList ) {
    10891091        SemanticErrorException errors;
    10901092        std::back_insert_iterator<std::vector<ast::ptr<ast::Decl>>> out( outputList );
  • src/Parser/ExpressionNode.cc

    rfa5e1aa5 rb7b3e41  
    601601ast::Expr * build_cast( const CodeLocation & location,
    602602                DeclarationNode * decl_node,
    603                 ExpressionNode * expr_node ) {
     603                ExpressionNode * expr_node,
     604                ast::CastExpr::CastKind kind ) {
    604605        ast::Type * targetType = maybeMoveBuildType( decl_node );
    605606        if ( dynamic_cast<ast::VoidType *>( targetType ) ) {
     
    607608                return new ast::CastExpr( location,
    608609                        maybeMoveBuild( expr_node ),
    609                         ast::ExplicitCast );
     610                        ast::ExplicitCast, kind );
    610611        } else {
    611612                return new ast::CastExpr( location,
    612613                        maybeMoveBuild( expr_node ),
    613614                        targetType,
    614                         ast::ExplicitCast );
     615                        ast::ExplicitCast, kind );
    615616        } // if
    616617} // build_cast
  • src/Parser/ExpressionNode.h

    rfa5e1aa5 rb7b3e41  
    6969ast::DimensionExpr * build_dimensionref( const CodeLocation &, const std::string * name );
    7070
    71 ast::Expr * build_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node );
     71ast::Expr * build_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node, ast::CastExpr::CastKind kind = ast::CastExpr::Default );
    7272ast::Expr * build_keyword_cast( const CodeLocation &, ast::AggregateDecl::Aggregate target, ExpressionNode * expr_node );
    7373ast::Expr * build_virtual_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node );
  • src/Parser/lex.ll

    rfa5e1aa5 rb7b3e41  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Tue May  2 08:45:21 2023
    13  * Update Count     : 769
     12 * Last Modified On : Fri Jun  9 10:04:00 2023
     13 * Update Count     : 770
    1414 */
    1515
     
    319319static                  { KEYWORD_RETURN(STATIC); }
    320320_Static_assert  { KEYWORD_RETURN(STATICASSERT); }               // C11
     321_static_assert  { KEYWORD_RETURN(STATICASSERT); }               // C23
    321322struct                  { KEYWORD_RETURN(STRUCT); }
    322323suspend                 { KEYWORD_RETURN(SUSPEND); }                    // CFA
  • src/Parser/parser.yy

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 26 16:45:37 2023
    13 // Update Count     : 6330
     12// Last Modified On : Sat Jun 17 18:53:24 2023
     13// Update Count     : 6347
    1414//
    1515
     
    108108        assert( declList );
    109109        // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout );
    110         DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( typeSpec );
     110        DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec );
    111111        // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout );
    112112        // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name;
    113113
    114         for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
     114        for ( DeclarationNode * cur = dynamic_cast<DeclarationNode *>( declList->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
    115115                cl->cloneBaseType( cur );
    116116        } // for
     
    206206#define NEW_ONE  new ExpressionNode( build_constantInteger( yylloc, *new string( "1" ) ) )
    207207#define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right)
    208 #define MISSING_ANON_FIELD "Missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."
    209 #define MISSING_LOW "Missing low value for up-to range so index is uninitialized."
    210 #define MISSING_HIGH "Missing high value for down-to range so index is uninitialized."
     208#define MISSING_ANON_FIELD "syntax error, missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."
     209#define MISSING_LOW "syntax error, missing low value for up-to range so index is uninitialized."
     210#define MISSING_HIGH "syntax error, missing high value for down-to range so index is uninitialized."
    211211
    212212static ForCtrl * makeForCtrl(
     
    232232ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    233233        if ( index->initializer ) {
    234                 SemanticError( yylloc, "Direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
     234                SemanticError( yylloc, "syntax error, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
    235235        } // if
    236236        if ( index->next ) {
    237                 SemanticError( yylloc, "Multiple loop indexes disallowed in for-loop declaration." );
     237                SemanticError( yylloc, "syntax error, multiple loop indexes disallowed in for-loop declaration." );
    238238        } // if
    239239        DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) );
     
    260260                        return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );
    261261                } else {
    262                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr;
     262                        SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
    263263                } // if
    264264        } else {
    265                 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr;
     265                SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed. ." ); return nullptr;
    266266        } // if
    267267} // forCtrl
    268268
    269269static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) {
    270         SemanticError( yylloc, ::toString( "Adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n"
     270        SemanticError( yylloc, ::toString( "syntax error, adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n"
    271271                                   "Possible cause is misspelled type name or missing generic parameter." ) );
    272272} // IdentifierBeforeIdentifier
    273273
    274274static void IdentifierBeforeType( string & identifier, const char * kind ) {
    275         SemanticError( yylloc, ::toString( "Identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"
     275        SemanticError( yylloc, ::toString( "syntax error, identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"
    276276                                   "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) );
    277277} // IdentifierBeforeType
     
    689689        // | RESUME '(' comma_expression ')' compound_statement
    690690        //      { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }
    691         | IDENTIFIER IDENTIFIER                                                         // syntax error
     691        | IDENTIFIER IDENTIFIER                                                         // invalid syntax rules
    692692                { IdentifierBeforeIdentifier( *$1.str, *$2.str, "n expression" ); $$ = nullptr; }
    693         | IDENTIFIER type_qualifier                                                     // syntax error
     693        | IDENTIFIER type_qualifier                                                     // invalid syntax rules
    694694                { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; }
    695         | IDENTIFIER storage_class                                                      // syntax error
     695        | IDENTIFIER storage_class                                                      // invalid syntax rules
    696696                { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; }
    697         | IDENTIFIER basic_type_name                                            // syntax error
     697        | IDENTIFIER basic_type_name                                            // invalid syntax rules
    698698                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    699         | IDENTIFIER TYPEDEFname                                                        // syntax error
     699        | IDENTIFIER TYPEDEFname                                                        // invalid syntax rules
    700700                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    701         | IDENTIFIER TYPEGENname                                                        // syntax error
     701        | IDENTIFIER TYPEGENname                                                        // invalid syntax rules
    702702                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    703703        ;
     
    931931                { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); }
    932932        | '(' RETURN type_no_function ')' cast_expression       // CFA
    933                 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; }
     933                { $$ = new ExpressionNode( build_cast( yylloc, $3, $5, ast::CastExpr::Return ) ); }
    934934        | '(' COERCE type_no_function ')' cast_expression       // CFA
    935935                { SemanticError( yylloc, "Coerce cast is currently unimplemented." ); $$ = nullptr; }
     
    10401040                // FIX ME: computes $1 twice
    10411041        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    1042                 { $$ = new ExpressionNode( build_cond( yylloc, $1, $1, $4 ) ); }
     1042                { $$ = new ExpressionNode( build_cond( yylloc, $1, $1->clone(), $4 ) ); }
    10431043        ;
    10441044
     
    11521152        identifier_or_type_name ':' attribute_list_opt statement
    11531153                { $$ = $4->add_label( yylloc, $1, $3 ); }
    1154         | identifier_or_type_name ':' attribute_list_opt error // syntax error
    1155                 {
    1156                         SemanticError( yylloc, ::toString( "Label \"", *$1.str, "\" must be associated with a statement, "
     1154        | identifier_or_type_name ':' attribute_list_opt error // invalid syntax rule
     1155                {
     1156                        SemanticError( yylloc, ::toString( "syntx error, label \"", *$1.str, "\" must be associated with a statement, "
    11571157                                                                                           "where a declaration, case, or default is not a statement. "
    11581158                                                                                           "Move the label or terminate with a semi-colon." ) );
     
    11931193        | statement_list_nodecl statement
    11941194                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    1195         | statement_list_nodecl error                                           // syntax error
    1196                 { SemanticError( yylloc, "Declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
     1195        | statement_list_nodecl error                                           // invalid syntax rule
     1196                { SemanticError( yylloc, "syntax error, declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
    11971197        ;
    11981198
     
    12191219                        $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    12201220                }
    1221         | SWITCH '(' comma_expression ')' '{' error '}'         // CFA, syntax error
    1222                 { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; }
     1221        | SWITCH '(' comma_expression ')' '{' error '}'         // CFA, invalid syntax rule error
     1222                { SemanticError( yylloc, "synatx error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
    12231223        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    12241224                { $$ = new StatementNode( build_switch( yylloc, false, $3, $5 ) ); }
     
    12281228                        $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    12291229                }
    1230         | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, syntax error
    1231                 { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; }
     1230        | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, invalid syntax rule
     1231                { SemanticError( yylloc, "syntax error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
    12321232        ;
    12331233
     
    12681268
    12691269case_label:                                                                                             // CFA
    1270         CASE error                                                                                      // syntax error
    1271                 { SemanticError( yylloc, "Missing case list after case." ); $$ = nullptr; }
     1270        CASE error                                                                                      // invalid syntax rule
     1271                { SemanticError( yylloc, "syntax error, case list missing after case." ); $$ = nullptr; }
    12721272        | CASE case_value_list ':'                                      { $$ = $2; }
    1273         | CASE case_value_list error                                            // syntax error
    1274                 { SemanticError( yylloc, "Missing colon after case list." ); $$ = nullptr; }
     1273        | CASE case_value_list error                                            // invalid syntax rule
     1274                { SemanticError( yylloc, "syntax error, colon missing after case list." ); $$ = nullptr; }
    12751275        | DEFAULT ':'                                                           { $$ = new ClauseNode( build_default( yylloc ) ); }
    12761276                // A semantic check is required to ensure only one default clause per switch/choose statement.
    1277         | DEFAULT error                                                                         //  syntax error
    1278                 { SemanticError( yylloc, "Missing colon after default." ); $$ = nullptr; }
     1277        | DEFAULT error                                                                         //  invalid syntax rules
     1278                { SemanticError( yylloc, "syntax error, colon missing after default." ); $$ = nullptr; }
    12791279        ;
    12801280
     
    14051405                        else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    14061406                }
    1407         | comma_expression updowneq comma_expression '~' '@' // CFA, error
     1407        | comma_expression updowneq comma_expression '~' '@' // CFA, invalid syntax rules
    14081408                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    1409         | '@' updowneq '@'                                                                      // CFA, error
     1409        | '@' updowneq '@'                                                                      // CFA, invalid syntax rules
    14101410                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    1411         | '@' updowneq comma_expression '~' '@'                         // CFA, error
     1411        | '@' updowneq comma_expression '~' '@'                         // CFA, invalid syntax rules
    14121412                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    1413         | comma_expression updowneq '@' '~' '@'                         // CFA, error
     1413        | comma_expression updowneq '@' '~' '@'                         // CFA, invalid syntax rules
    14141414                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    1415         | '@' updowneq '@' '~' '@'                                                      // CFA, error
     1415        | '@' updowneq '@' '~' '@'                                                      // CFA, invalid syntax rules
    14161416                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    14171417
     
    14311431                {
    14321432                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1433                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1433                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14341434                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, NEW_ONE );
    14351435                }
    1436         | comma_expression ';' '@' updowneq '@'                         // CFA, error
    1437                 { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1436        | comma_expression ';' '@' updowneq '@'                         // CFA, invalid syntax rules
     1437                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    14381438
    14391439        | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA
    14401440                { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), $7 ); }
    1441         | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, error
     1441        | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, invalid syntax rules
    14421442                {
    14431443                        if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
     
    14471447                {
    14481448                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1449                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1449                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14501450                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, $7 );
    14511451                }
    14521452        | comma_expression ';' comma_expression updowneq comma_expression '~' '@' // CFA
    14531453                { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), nullptr ); }
    1454         | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, error
     1454        | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, invalid syntax rules
    14551455                {
    14561456                        if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
     
    14601460                {
    14611461                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1462                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1462                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14631463                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, nullptr );
    14641464                }
    14651465        | comma_expression ';' '@' updowneq '@' '~' '@' // CFA
    1466                 { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1466                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    14671467
    14681468        | declaration comma_expression                                          // CFA
     
    14811481                {
    14821482                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1483                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1483                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14841484                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, NEW_ONE );
    14851485                }
     
    14951495                {
    14961496                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1497                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1497                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14981498                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, $6 );
    14991499                }
     
    15081508                {
    15091509                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1510                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1510                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    15111511                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, nullptr );
    15121512                }
    1513         | declaration '@' updowneq '@' '~' '@'                          // CFA, error
    1514                 { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1513        | declaration '@' updowneq '@' '~' '@'                          // CFA, invalid syntax rules
     1514                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    15151515
    15161516        | comma_expression ';' TYPEDEFname                                      // CFA, array type
     
    15211521        | comma_expression ';' downupdowneq TYPEDEFname         // CFA, array type
    15221522                {
    1523                         if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, "All enumation ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr; }
     1523                        if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) {
     1524                                SemanticError( yylloc, "syntax error, all enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr;
     1525                        }
    15241526                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
    15251527                }
     
    16161618        MUTEX '(' argument_expression_list_opt ')' statement
    16171619                {
    1618                         if ( ! $3 ) { SemanticError( yylloc, "mutex argument list cannot be empty." ); $$ = nullptr; }
     1620                        if ( ! $3 ) { SemanticError( yylloc, "syntax error, mutex argument list cannot be empty." ); $$ = nullptr; }
    16191621                        $$ = new StatementNode( build_mutex( yylloc, $3, $5 ) );
    16201622                }
     
    16641666                { $$ = build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ); }
    16651667        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1666         | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
    1667                 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
     1668        | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // invalid syntax rules
     1669                { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    16681670        | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    16691671                { $$ = build_waitfor_else( yylloc, build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ), $7, maybe_build_compound( yylloc, $9 ) ); }
     
    17091711                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ) ); }
    17101712        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1711         | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
    1712                 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
     1713        | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // invalid syntax rules
     1714                { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    17131715        | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    17141716                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1,
     
    20652067                        assert( $1->type );
    20662068                        if ( $1->type->qualifiers.any() ) {                     // CV qualifiers ?
    2067                                 SemanticError( yylloc, "Useless type qualifier(s) in empty declaration." ); $$ = nullptr;
     2069                                SemanticError( yylloc, "syntax error, useless type qualifier(s) in empty declaration." ); $$ = nullptr;
    20682070                        }
    20692071                        // enums are never empty declarations because there must have at least one enumeration.
    20702072                        if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ?
    2071                                 SemanticError( yylloc, "Useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;
     2073                                SemanticError( yylloc, "syntax error, useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;
    20722074                        }
    20732075                }
     
    21002102        | type_declaration_specifier
    21012103        | sue_declaration_specifier
    2102         | sue_declaration_specifier invalid_types
    2103                 {
    2104                         SemanticError( yylloc, ::toString( "Missing ';' after end of ",
     2104        | sue_declaration_specifier invalid_types                       // invalid syntax rule
     2105                {
     2106                        SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of ",
    21052107                                $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ),
    2106                                 " declaration" ) );
     2108                                " declaration." ) );
    21072109                        $$ = nullptr;
    21082110                }
     
    25842586                        // } // for
    25852587                }
     2588        | type_specifier field_declaring_list_opt '}'           // invalid syntax rule
     2589                {
     2590                        SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of previous declaration." ) );
     2591                        $$ = nullptr;
     2592                }
    25862593        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
    25872594                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
     
    26822689        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    26832690                {
    2684                         if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() )
    2685                         { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    2686 
     2691                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() ) {
     2692                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
     2693                        }
    26872694                        $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 );
    26882695                }
     
    26932700        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    26942701                {
    2695                         if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     2702                        if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) {
     2703                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
     2704                        }
    26962705                        typedefTable.makeTypedef( *$6 );
    26972706                }
     
    31663175        | IDENTIFIER IDENTIFIER
    31673176                { IdentifierBeforeIdentifier( *$1.str, *$2.str, " declaration" ); $$ = nullptr; }
    3168         | IDENTIFIER type_qualifier                                                     // syntax error
     3177        | IDENTIFIER type_qualifier                                                     // invalid syntax rules
    31693178                { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; }
    3170         | IDENTIFIER storage_class                                                      // syntax error
     3179        | IDENTIFIER storage_class                                                      // invalid syntax rules
    31713180                { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; }
    3172         | IDENTIFIER basic_type_name                                            // syntax error
     3181        | IDENTIFIER basic_type_name                                            // invalid syntax rules
    31733182                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    3174         | IDENTIFIER TYPEDEFname                                                        // syntax error
     3183        | IDENTIFIER TYPEDEFname                                                        // invalid syntax rules
    31753184                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    3176         | IDENTIFIER TYPEGENname                                                        // syntax error
     3185        | IDENTIFIER TYPEGENname                                                        // invalid syntax rules
    31773186                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    31783187        | external_function_definition
     
    32093218        | type_qualifier_list
    32103219                {
    3211                         if ( $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     3220                        if ( $1->type->qualifiers.any() ) {
     3221                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
     3222                        }
    32123223                        if ( $1->type->forall ) forall = true;          // remember generic type
    32133224                }
     
    32203231        | declaration_qualifier_list
    32213232                {
    3222                         if ( $1->type && $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     3233                        if ( $1->type && $1->type->qualifiers.any() ) {
     3234                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
     3235                        }
    32233236                        if ( $1->type && $1->type->forall ) forall = true; // remember generic type
    32243237                }
     
    32313244        | declaration_qualifier_list type_qualifier_list
    32323245                {
    3233                         if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     3246                        if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) {
     3247                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
     3248                        }
    32343249                        if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type
    32353250                }
     
    32623277                        $$ = $3; forall = false;
    32633278                        if ( $5 ) {
    3264                                 SemanticError( yylloc, "Attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
     3279                                SemanticError( yylloc, "syntax error, attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
    32653280                                $$ = nullptr;
    32663281                        } // if
  • src/ResolvExpr/Candidate.hpp

    rfa5e1aa5 rb7b3e41  
    9191
    9292/// Holdover behaviour from old `findMinCost` -- xxx -- can maybe be eliminated?
     93/*
    9394static inline void promoteCvtCost( CandidateList & candidates ) {
    9495        for ( CandidateRef & r : candidates ) {
     
    9697        }
    9798}
     99*/
    98100
    99101void print( std::ostream & os, const Candidate & cand, Indenter indent = {} );
  • src/ResolvExpr/CandidateFinder.cpp

    rfa5e1aa5 rb7b3e41  
    3838#include "typeops.h"              // for combos
    3939#include "Unify.h"
     40#include "WidenMode.h"
    4041#include "AST/Expr.hpp"
    4142#include "AST/Node.hpp"
     
    749750                        // attempt to narrow based on expected target type
    750751                        const ast::Type * returnType = funcType->returns.front();
    751                         if ( ! unify(
    752                                 returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen )
    753                         ) {
    754                                 // unification failed, do not pursue this candidate
    755                                 return;
     752                        if ( selfFinder.strictMode ) {
     753                                if ( ! unifyExact(
     754                                        returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen, noWiden() ) // xxx - is no widening correct?
     755                                ) {
     756                                        // unification failed, do not pursue this candidate
     757                                        return;
     758                                }
     759                        }
     760                        else {
     761                                if ( ! unify(
     762                                        returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen )
     763                                ) {
     764                                        // unification failed, do not pursue this candidate
     765                                        return;
     766                                }
    756767                        }
    757768                }
     
    771782                                for (size_t i=0; i<nParams; ++i) {
    772783                                        auto obj = funcDecl->params[i].strict_as<ast::ObjectDecl>();
    773                                         if (!instantiateArgument( location,
     784                                        if ( !instantiateArgument( location,
    774785                                                funcType->params[i], obj->init, args, results, genStart, symtab)) return;
    775786                                }
     
    781792                        // matches
    782793                        // no default args for indirect calls
    783                         if ( ! instantiateArgument( location,
     794                        if ( !instantiateArgument( location,
    784795                                param, nullptr, args, results, genStart, symtab ) ) return;
    785796                }
     
    874885
    875886                if ( auto structInst = aggrExpr->result.as< ast::StructInstType >() ) {
    876                         addAggMembers( structInst, aggrExpr, *cand, Cost::safe, "" );
     887                        addAggMembers( structInst, aggrExpr, *cand, Cost::unsafe, "" );
    877888                } else if ( auto unionInst = aggrExpr->result.as< ast::UnionInstType >() ) {
    878                         addAggMembers( unionInst, aggrExpr, *cand, Cost::safe, "" );
     889                        addAggMembers( unionInst, aggrExpr, *cand, Cost::unsafe, "" );
    879890                }
    880891        }
     
    10071018                                if ( auto pointer = dynamic_cast< const ast::PointerType * >( funcResult ) ) {
    10081019                                        if ( auto function = pointer->base.as< ast::FunctionType >() ) {
     1020                                                // if (!selfFinder.allowVoid && function->returns.empty()) continue;
    10091021                                                CandidateRef newFunc{ new Candidate{ *func } };
    10101022                                                newFunc->expr =
     
    10181030                                        if ( const ast::EqvClass * clz = func->env.lookup( *inst ) ) {
    10191031                                                if ( auto function = clz->bound.as< ast::FunctionType >() ) {
    1020                                                         CandidateRef newFunc{ new Candidate{ *func } };
     1032                                                        CandidateRef newFunc( new Candidate( *func ) );
    10211033                                                        newFunc->expr =
    10221034                                                                referenceToRvalueConversion( newFunc->expr, newFunc->cost );
     
    10601072                if ( found.empty() && ! errors.isEmpty() ) { throw errors; }
    10611073
     1074                // only keep the best matching intrinsic result to match C semantics (no unexpected narrowing/widening)
     1075                // TODO: keep one for each set of argument candidates?
     1076                Cost intrinsicCost = Cost::infinity;
     1077                CandidateList intrinsicResult;
     1078
    10621079                // Compute conversion costs
    10631080                for ( CandidateRef & withFunc : found ) {
     
    10821099                        if ( cvtCost != Cost::infinity ) {
    10831100                                withFunc->cvtCost = cvtCost;
    1084                                 candidates.emplace_back( std::move( withFunc ) );
    1085                         }
    1086                 }
     1101                                withFunc->cost += cvtCost;
     1102                                auto func = withFunc->expr.strict_as<ast::ApplicationExpr>()->func.as<ast::VariableExpr>();
     1103                                if (func && func->var->linkage == ast::Linkage::Intrinsic) {
     1104                                        if (withFunc->cost < intrinsicCost) {
     1105                                                intrinsicResult.clear();
     1106                                                intrinsicCost = withFunc->cost;
     1107                                        }
     1108                                        if (withFunc->cost == intrinsicCost) {
     1109                                                intrinsicResult.emplace_back(std::move(withFunc));
     1110                                        }
     1111                                }
     1112                                else {
     1113                                        candidates.emplace_back( std::move( withFunc ) );
     1114                                }
     1115                        }
     1116                }
     1117                spliceBegin( candidates, intrinsicResult );
    10871118                found = std::move( candidates );
    10881119
    10891120                // use a new list so that candidates are not examined by addAnonConversions twice
    1090                 CandidateList winners = findMinCost( found );
    1091                 promoteCvtCost( winners );
     1121                // CandidateList winners = findMinCost( found );
     1122                // promoteCvtCost( winners );
    10921123
    10931124                // function may return a struct/union value, in which case we need to add candidates
    10941125                // for implicit conversions to each of the anonymous members, which must happen after
    10951126                // `findMinCost`, since anon conversions are never the cheapest
    1096                 for ( const CandidateRef & c : winners ) {
     1127                for ( const CandidateRef & c : found ) {
    10971128                        addAnonConversions( c );
    10981129                }
    1099                 spliceBegin( candidates, winners );
    1100 
    1101                 if ( candidates.empty() && targetType && ! targetType->isVoid() ) {
     1130                // would this be too slow when we don't check cost anymore?
     1131                spliceBegin( candidates, found );
     1132
     1133                if ( candidates.empty() && targetType && ! targetType->isVoid() && !selfFinder.strictMode ) {
    11021134                        // If resolution is unsuccessful with a target type, try again without, since it
    11031135                        // will sometimes succeed when it wouldn't with a target type binding.
     
    11401172
    11411173                CandidateFinder finder( context, tenv, toType );
     1174                if (toType->isVoid()) {
     1175                        finder.allowVoid = true;
     1176                }
     1177                if ( castExpr->kind == ast::CastExpr::Return ) {
     1178                        finder.strictMode = true;
     1179                        finder.find( castExpr->arg, ResolvMode::withAdjustment() );
     1180
     1181                        // return casts are eliminated (merely selecting an overload, no actual operation)
     1182                        candidates = std::move(finder.candidates);
     1183                }
    11421184                finder.find( castExpr->arg, ResolvMode::withAdjustment() );
    11431185
     
    11451187
    11461188                CandidateList matches;
     1189                Cost minExprCost = Cost::infinity;
     1190                Cost minCastCost = Cost::infinity;
    11471191                for ( CandidateRef & cand : finder.candidates ) {
    11481192                        ast::AssertionSet need( cand->need.begin(), cand->need.end() ), have;
     
    11761220                                // count one safe conversion for each value that is thrown away
    11771221                                thisCost.incSafe( discardedValues );
    1178                                 CandidateRef newCand = std::make_shared<Candidate>(
    1179                                         restructureCast( cand->expr, toType, castExpr->isGenerated ),
    1180                                         copy( cand->env ), std::move( open ), std::move( need ), cand->cost,
    1181                                         cand->cost + thisCost );
    1182                                 inferParameters( newCand, matches );
    1183                         }
    1184                 }
    1185 
    1186                 // select first on argument cost, then conversion cost
    1187                 CandidateList minArgCost = findMinCost( matches );
    1188                 promoteCvtCost( minArgCost );
    1189                 candidates = findMinCost( minArgCost );
     1222                                // select first on argument cost, then conversion cost
     1223                                if ( cand->cost < minExprCost || ( cand->cost == minExprCost && thisCost < minCastCost ) ) {
     1224                                        minExprCost = cand->cost;
     1225                                        minCastCost = thisCost;
     1226                                        matches.clear();
     1227
     1228
     1229                                }
     1230                                // ambiguous case, still output candidates to print in error message
     1231                                if ( cand->cost == minExprCost && thisCost == minCastCost ) {
     1232                                        CandidateRef newCand = std::make_shared<Candidate>(
     1233                                                restructureCast( cand->expr, toType, castExpr->isGenerated ),
     1234                                                copy( cand->env ), std::move( open ), std::move( need ), cand->cost + thisCost);
     1235                                        // currently assertions are always resolved immediately so this should have no effect.
     1236                                        // if this somehow changes in the future (e.g. delayed by indeterminate return type)
     1237                                        // we may need to revisit the logic.
     1238                                        inferParameters( newCand, matches );
     1239                                }
     1240                                // else skip, better alternatives found
     1241
     1242                        }
     1243                }
     1244                candidates = std::move(matches);
     1245
     1246                //CandidateList minArgCost = findMinCost( matches );
     1247                //promoteCvtCost( minArgCost );
     1248                //candidates = findMinCost( minArgCost );
    11901249        }
    11911250
     
    14531512                // candidates for true result
    14541513                CandidateFinder finder2( context, tenv );
     1514                finder2.allowVoid = true;
    14551515                finder2.find( conditionalExpr->arg2, ResolvMode::withAdjustment() );
    14561516                if ( finder2.candidates.empty() ) return;
     
    14581518                // candidates for false result
    14591519                CandidateFinder finder3( context, tenv );
     1520                finder3.allowVoid = true;
    14601521                finder3.find( conditionalExpr->arg3, ResolvMode::withAdjustment() );
    14611522                if ( finder3.candidates.empty() ) return;
     
    15241585        void Finder::postvisit( const ast::ConstructorExpr * ctorExpr ) {
    15251586                CandidateFinder finder( context, tenv );
     1587                finder.allowVoid = true;
    15261588                finder.find( ctorExpr->callExpr, ResolvMode::withoutPrune() );
    15271589                for ( CandidateRef & r : finder.candidates ) {
     
    16401702                        CandidateFinder finder( context, tenv, toType );
    16411703                        finder.find( initExpr->expr, ResolvMode::withAdjustment() );
     1704
     1705                        Cost minExprCost = Cost::infinity;
     1706                        Cost minCastCost = Cost::infinity;
    16421707                        for ( CandidateRef & cand : finder.candidates ) {
    16431708                                if (reason.code == NotFound) reason.code = NoMatch;
     
    16771742                                        // count one safe conversion for each value that is thrown away
    16781743                                        thisCost.incSafe( discardedValues );
    1679                                         CandidateRef newCand = std::make_shared<Candidate>(
    1680                                                 new ast::InitExpr{
    1681                                                         initExpr->location, restructureCast( cand->expr, toType ),
    1682                                                         initAlt.designation },
    1683                                                 std::move(env), std::move( open ), std::move( need ), cand->cost, thisCost );
    1684                                         inferParameters( newCand, matches );
     1744                                        if ( cand->cost < minExprCost || ( cand->cost == minExprCost && thisCost < minCastCost ) ) {
     1745                                                minExprCost = cand->cost;
     1746                                                minCastCost = thisCost;
     1747                                                matches.clear();
     1748                                        }
     1749                                        // ambiguous case, still output candidates to print in error message
     1750                                        if ( cand->cost == minExprCost && thisCost == minCastCost ) {
     1751                                                CandidateRef newCand = std::make_shared<Candidate>(
     1752                                                        new ast::InitExpr{
     1753                                                                initExpr->location,
     1754                                                                restructureCast( cand->expr, toType ),
     1755                                                                initAlt.designation },
     1756                                                        std::move(env), std::move( open ), std::move( need ), cand->cost + thisCost );
     1757                                                // currently assertions are always resolved immediately so this should have no effect.
     1758                                                // if this somehow changes in the future (e.g. delayed by indeterminate return type)
     1759                                                // we may need to revisit the logic.
     1760                                                inferParameters( newCand, matches );
     1761                                        }
    16851762                                }
    16861763                        }
     
    16881765
    16891766                // select first on argument cost, then conversion cost
    1690                 CandidateList minArgCost = findMinCost( matches );
    1691                 promoteCvtCost( minArgCost );
    1692                 candidates = findMinCost( minArgCost );
     1767                // CandidateList minArgCost = findMinCost( matches );
     1768                // promoteCvtCost( minArgCost );
     1769                // candidates = findMinCost( minArgCost );
     1770                candidates = std::move(matches);
    16931771        }
    16941772
     
    17561834                        auto found = selected.find( mangleName );
    17571835                        if ( found != selected.end() ) {
    1758                                 if ( newCand->cost < found->second.candidate->cost ) {
     1836                                // tiebreaking by picking the lower cost on CURRENT expression
     1837                                // NOTE: this behavior is different from C semantics.
     1838                                // Specific remediations are performed for C operators at postvisit(UntypedExpr).
     1839                                // Further investigations may take place.
     1840                                if ( newCand->cost < found->second.candidate->cost
     1841                                        || (newCand->cost == found->second.candidate->cost && newCand->cvtCost < found->second.candidate->cvtCost) ) {
    17591842                                        PRINT(
    17601843                                                std::cerr << "cost " << newCand->cost << " beats "
     
    17631846
    17641847                                        found->second = PruneStruct{ newCand };
    1765                                 } else if ( newCand->cost == found->second.candidate->cost ) {
     1848                                } else if ( newCand->cost == found->second.candidate->cost && newCand->cvtCost == found->second.candidate->cvtCost ) {
    17661849                                        // if one of the candidates contains a deleted identifier, can pick the other,
    17671850                                        // since deleted expressions should not be ambiguous if there is another option
     
    18541937        */
    18551938
    1856         if ( mode.prune ) {
     1939        // optimization: don't prune for NameExpr since it never has cost
     1940        if ( mode.prune && !dynamic_cast<const ast::NameExpr *>(expr) ) {
    18571941                // trim candidates to single best one
    18581942                PRINT(
  • src/ResolvExpr/CandidateFinder.hpp

    rfa5e1aa5 rb7b3e41  
    3333        const ast::TypeEnvironment & env;  ///< Substitutions performed in this resolution
    3434        ast::ptr< ast::Type > targetType;  ///< Target type for resolution
     35        bool strictMode = false;           ///< If set to true, requires targetType to be exact match (inside return cast)
     36        bool allowVoid = false;            ///< If set to true, allow void-returning function calls (only top level, cast to void and first in comma)
    3537        std::set< std::string > otypeKeys;  /// different type may map to same key
    3638
  • src/ResolvExpr/CastCost.cc

    rfa5e1aa5 rb7b3e41  
    234234        if ( typesCompatibleIgnoreQualifiers( src, dst, env ) ) {
    235235                PRINT( std::cerr << "compatible!" << std::endl; )
     236                if (dynamic_cast<const ast::ZeroType *>(dst) || dynamic_cast<const ast::OneType *>(dst)) {
     237                        return Cost::spec;
     238                }
    236239                return Cost::zero;
    237240        } else if ( dynamic_cast< const ast::VoidType * >( dst ) ) {
  • src/ResolvExpr/CommonType.cc

    rfa5e1aa5 rb7b3e41  
    697697                        if ( auto basic2 = dynamic_cast< const ast::BasicType * >( type2 ) ) {
    698698                                #warning remove casts when `commonTypes` moved to new AST
     699                               
     700                                /*
    699701                                ast::BasicType::Kind kind = (ast::BasicType::Kind)(int)commonTypes[ (BasicType::Kind)(int)basic->kind ][ (BasicType::Kind)(int)basic2->kind ];
    700702                                if (
     
    706708                                        result = new ast::BasicType{ kind, basic->qualifiers | basic2->qualifiers };
    707709                                }
     710                                */
     711                                ast::BasicType::Kind kind;
     712                                if (basic->kind != basic2->kind && !widen.first && !widen.second) return;
     713                                else if (!widen.first) kind = basic->kind; // widen.second
     714                                else if (!widen.second) kind = basic2->kind;
     715                                else kind = (ast::BasicType::Kind)(int)commonTypes[ (BasicType::Kind)(int)basic->kind ][ (BasicType::Kind)(int)basic2->kind ];
     716                                // xxx - what does qualifiers even do here??
     717                                if ( (basic->qualifiers >= basic2->qualifiers || widen.first)
     718                                        && (basic->qualifiers <= basic2->qualifiers || widen.second) ) {
     719                                        result = new ast::BasicType{ kind, basic->qualifiers | basic2->qualifiers };
     720                                }
     721                               
    708722                        } else if (
    709723                                dynamic_cast< const ast::ZeroType * >( type2 )
     
    712726                                #warning remove casts when `commonTypes` moved to new AST
    713727                                ast::BasicType::Kind kind = (ast::BasicType::Kind)(int)commonTypes[ (BasicType::Kind)(int)basic->kind ][ (BasicType::Kind)(int)ast::BasicType::SignedInt ];
    714                                 if (
    715                                         ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers )
     728                                /*
     729                                if ( // xxx - what does qualifier even do here??
     730                                        ( ( basic->qualifiers >= type2->qualifiers )
    716731                                                || widen.first )
    717                                         && ( ( kind != basic->kind && basic->qualifiers <= type2->qualifiers )
     732                                         && ( ( /* kind != basic->kind && basic->qualifiers <= type2->qualifiers )
    718733                                                || widen.second )
    719                                 ) {
    720                                         result = new ast::BasicType{ kind, basic->qualifiers | type2->qualifiers };
     734                                )
     735                                */
     736                                if (widen.second) {
     737                                        result = new ast::BasicType{ basic->kind, basic->qualifiers | type2->qualifiers };
    721738                                }
    722739                        } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) {
     
    746763                                auto entry = open.find( *var );
    747764                                if ( entry != open.end() ) {
     765                                // if (tenv.lookup(*var)) {
    748766                                        ast::AssertionSet need, have;
    749767                                        if ( ! tenv.bindVar(
     
    10171035                void postvisit( const ast::TraitInstType * ) {}
    10181036
    1019                 void postvisit( const ast::TypeInstType * inst ) {}
    1020 
    1021                 void postvisit( const ast::TupleType * tuple) {
     1037                void postvisit( const ast::TypeInstType * ) {}
     1038
     1039                void postvisit( const ast::TupleType * tuple ) {
    10221040                        tryResolveWithTypedEnum( tuple );
    10231041                }
  • src/ResolvExpr/ConversionCost.cc

    rfa5e1aa5 rb7b3e41  
    702702
    703703        cost = costCalc( refType->base, dst, srcIsLvalue, symtab, env );
     704
     705        // xxx - should qualifiers be considered in pass-by-value?
     706        /*
    704707        if ( refType->base->qualifiers == dst->qualifiers ) {
    705708                cost.incReference();
     
    709712                cost.incUnsafe();
    710713        }
     714        */
     715        cost.incReference();
    711716}
    712717
     
    792797                        cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] );
    793798                }
     799                // this has the effect of letting any expr such as x+0, x+1 to be typed
     800                // the same as x, instead of at least int. are we willing to sacrifice this little
     801                // bit of coherence with C?
     802                // TODO: currently this does not work when no zero/one overloads exist. Find a fix for it.
     803                // cost = Cost::zero;
    794804        } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) {
    795805                cost = Cost::zero;
    796806                // +1 for zero_t ->, +1 for disambiguation
    797807                cost.incSafe( maxIntCost + 2 );
     808                // assuming 0p is supposed to be used for pointers?
    798809        }
    799810}
     
    804815                cost = Cost::zero;
    805816        } else if ( const ast::BasicType * dstAsBasic =
    806                         dynamic_cast< const ast::BasicType * >( dst ) ) {
     817                        dynamic_cast< const ast::BasicType * >( dst ) ) {               
    807818                int tableResult = costMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ];
    808819                if ( -1 == tableResult ) {
     
    813824                        cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] );
    814825                }
     826               
     827                // cost = Cost::zero;
    815828        }
    816829}
  • src/ResolvExpr/CurrentObject.cc

    rfa5e1aa5 rb7b3e41  
    689689
    690690                        auto arg = eval( expr );
    691                         index = arg.first;
     691                        assertf( arg.hasKnownValue, "Non-evaluable expression made it to IndexIterator" );
     692                        index = arg.knownValue;
    692693
    693694                        // if ( auto constExpr = dynamic_cast< const ConstantExpr * >( expr ) ) {
     
    728729                size_t getSize( const Expr * expr ) {
    729730                        auto res = eval( expr );
    730                         if ( !res.second ) {
     731                        if ( !res.hasKnownValue ) {
    731732                                SemanticError( location, toString( "Array designator must be a constant expression: ", expr ) );
    732733                        }
    733                         return res.first;
     734                        return res.knownValue;
    734735                }
    735736
  • src/ResolvExpr/FindOpenVars.cc

    rfa5e1aa5 rb7b3e41  
    2121#include "AST/Pass.hpp"
    2222#include "AST/Type.hpp"
     23#include "AST/TypeEnvironment.hpp"
    2324#include "Common/PassVisitor.h"
    2425#include "SynTree/Declaration.h"  // for TypeDecl, DeclarationWithType (ptr ...
    2526#include "SynTree/Type.h"         // for Type, Type::ForallList, ArrayType
     27
     28#include <iostream>
    2629
    2730namespace ResolvExpr {
     
    102105                        ast::AssertionSet & need;
    103106                        ast::AssertionSet & have;
     107                        ast::TypeEnvironment & env;
    104108                        bool nextIsOpen;
    105109
    106110                        FindOpenVars_new(
    107111                                ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n,
    108                                 ast::AssertionSet & h, FirstMode firstIsOpen )
    109                         : open( o ), closed( c ), need( n ), have( h ), nextIsOpen( firstIsOpen ) {}
     112                                ast::AssertionSet & h, ast::TypeEnvironment & env, FirstMode firstIsOpen )
     113                        : open( o ), closed( c ), need( n ), have( h ), env (env), nextIsOpen( firstIsOpen ) {}
    110114
    111115                        void previsit( const ast::FunctionType * type ) {
    112116                                // mark open/closed variables
    113117                                if ( nextIsOpen ) {
     118                                        // trying to remove this from resolver.
     119                                        // occasionally used in other parts so not deleting right now.
     120
     121                                        // insert open variables unbound to environment.
     122                                        env.add(type->forall);
     123
    114124                                        for ( auto & decl : type->forall ) {
    115125                                                open[ *decl ] = ast::TypeData{ decl->base };
     
    137147        void findOpenVars(
    138148                        const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed,
    139                         ast::AssertionSet & need, ast::AssertionSet & have, FirstMode firstIsOpen ) {
    140                 ast::Pass< FindOpenVars_new > finder{ open, closed, need, have, firstIsOpen };
     149                        ast::AssertionSet & need, ast::AssertionSet & have, ast::TypeEnvironment & env, FirstMode firstIsOpen ) {
     150                ast::Pass< FindOpenVars_new > finder{ open, closed, need, have, env, firstIsOpen };
    141151                type->accept( finder );
     152
     153                if (!closed.empty()) {
     154                        std::cerr << "closed: ";
     155                        for (auto& i : closed) {
     156                                std::cerr << i.first.base->location << ":" << i.first.base->name << ' ';
     157                        }
     158                        std::cerr << std::endl;
     159                }
    142160        }
    143161} // namespace ResolvExpr
  • src/ResolvExpr/FindOpenVars.h

    rfa5e1aa5 rb7b3e41  
    3333        void findOpenVars(
    3434                const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed,
    35                 ast::AssertionSet & need, ast::AssertionSet & have, FirstMode firstIsOpen );
     35                ast::AssertionSet & need, ast::AssertionSet & have, ast::TypeEnvironment & env, FirstMode firstIsOpen );
    3636} // namespace ResolvExpr
    3737
  • src/ResolvExpr/Resolver.cc

    rfa5e1aa5 rb7b3e41  
    10111011                        ast::TypeEnvironment env;
    10121012                        CandidateFinder finder( context, env );
     1013                        finder.allowVoid = true;
    10131014                        finder.find( untyped, recursion_level == 1 ? mode.atTopLevel() : mode );
    10141015                        --recursion_level;
     
    10541055
    10551056                        // promote candidate.cvtCost to .cost
    1056                         promoteCvtCost( winners );
     1057                        // promoteCvtCost( winners );
    10571058
    10581059                        // produce ambiguous errors, if applicable
     
    11061107
    11071108                /// Removes cast to type of argument (unlike StripCasts, also handles non-generated casts)
    1108                 void removeExtraneousCast( ast::ptr<ast::Expr> & expr, const ast::SymbolTable & symtab ) {
     1109                void removeExtraneousCast( ast::ptr<ast::Expr> & expr ) {
    11091110                        if ( const ast::CastExpr * castExpr = expr.as< ast::CastExpr >() ) {
    11101111                                if ( typesCompatible( castExpr->arg->result, castExpr->result ) ) {
     
    11961197                ast::ptr< ast::Expr > castExpr = new ast::CastExpr{ untyped, type };
    11971198                ast::ptr< ast::Expr > newExpr = findSingleExpression( castExpr, context );
    1198                 removeExtraneousCast( newExpr, context.symtab );
     1199                removeExtraneousCast( newExpr );
    11991200                return newExpr;
    12001201        }
     
    12611262                static size_t traceId;
    12621263                Resolver_new( const ast::TranslationGlobal & global ) :
     1264                        ast::WithSymbolTable(ast::SymbolTable::ErrorDetection::ValidateOnAdd),
    12631265                        context{ symtab, global } {}
    12641266                Resolver_new( const ResolveContext & context ) :
     
    13401342                                        auto mutAttr = mutate(attr);
    13411343                                        mutAttr->params.front() = resolved;
    1342                                         if (! result.second) {
     1344                                        if (! result.hasKnownValue) {
    13431345                                                SemanticWarning(loc, Warning::GccAttributes,
    13441346                                                        toCString( name, " priorities must be integers from 0 to 65535 inclusive: ", arg ) );
    13451347                                        }
    13461348                                        else {
    1347                                                 auto priority = result.first;
     1349                                                auto priority = result.knownValue;
    13481350                                                if (priority < 101) {
    13491351                                                        SemanticWarning(loc, Warning::GccAttributes,
     
    20402042                const ast::Type * initContext = currentObject.getCurrentType();
    20412043
    2042                 removeExtraneousCast( newExpr, symtab );
     2044                removeExtraneousCast( newExpr );
    20432045
    20442046                // check if actual object's type is char[]
  • src/ResolvExpr/SatisfyAssertions.cpp

    rfa5e1aa5 rb7b3e41  
    1616#include "SatisfyAssertions.hpp"
    1717
     18#include <iostream>
    1819#include <algorithm>
    1920#include <cassert>
     
    4546#include "SymTab/Mangler.h"
    4647
     48
     49
    4750namespace ResolvExpr {
    4851
     
    6568                        ast::AssertionSet && h, ast::AssertionSet && n, ast::OpenVarSet && o, ast::UniqueId rs )
    6669                : cdata( c ), adjType( at ), env( std::move( e ) ), have( std::move( h ) ),
    67                   need( std::move( n ) ), open( std::move( o ) ), resnSlot( rs ) {}
     70                  need( std::move( n ) ), open( std::move( o ) ), resnSlot( rs ) {
     71                        if (!have.empty()) {
     72                                // std::cerr << c.id->location << ':' << c.id->name << std::endl; // I think this was debugging code so I commented it
     73                        }
     74                  }
    6875        };
    6976
     
    139146        };
    140147
    141         /// Adds a captured assertion to the symbol table
    142         void addToSymbolTable( const ast::AssertionSet & have, ast::SymbolTable & symtab ) {
    143                 for ( auto & i : have ) {
    144                         if ( i.second.isUsed ) { symtab.addId( i.first->var ); }
    145                 }
    146         }
     148        enum AssertionResult {Fail, Skip, Success} ;
    147149
    148150        /// Binds a single assertion, updating satisfaction state
     
    155157                        "Assertion candidate does not have a unique ID: %s", toString( candidate ).c_str() );
    156158
    157                 ast::Expr * varExpr = match.cdata.combine( cand->expr->location, cand->cvtCost );
     159                ast::Expr * varExpr = match.cdata.combine( cand->expr->location, cand->cost );
    158160                varExpr->result = match.adjType;
    159161                if ( match.resnSlot ) { varExpr->inferred.resnSlots().emplace_back( match.resnSlot ); }
     
    165167
    166168        /// Satisfy a single assertion
    167         bool satisfyAssertion( ast::AssertionList::value_type & assn, SatState & sat, bool allowConversion = false, bool skipUnbound = false) {
     169        AssertionResult satisfyAssertion( ast::AssertionList::value_type & assn, SatState & sat, bool skipUnbound = false) {
    168170                // skip unused assertions
    169                 if ( ! assn.second.isUsed ) return true;
     171                // static unsigned int cnt = 0; // I think this was debugging code so I commented it
     172                if ( ! assn.second.isUsed ) return AssertionResult::Success;
     173
     174                // if (assn.first->var->name[1] == '|') std::cerr << ++cnt << std::endl; // I think this was debugging code so I commented it
    170175
    171176                // find candidates that unify with the desired type
    172                 AssnCandidateList matches;
     177                AssnCandidateList matches, inexactMatches;
    173178
    174179                std::vector<ast::SymbolTable::IdData> candidates;
     
    179184                                .strict_as<ast::FunctionType>()->params[0]
    180185                                .strict_as<ast::ReferenceType>()->base;
    181                         sat.cand->env.apply(thisArgType);
     186                        // sat.cand->env.apply(thisArgType);
     187
     188                        if (auto inst = thisArgType.as<ast::TypeInstType>()) {
     189                                auto cls = sat.cand->env.lookup(*inst);
     190                                if (cls && cls->bound) thisArgType = cls->bound;
     191                        }
    182192
    183193                        std::string otypeKey = "";
    184194                        if (thisArgType.as<ast::PointerType>()) otypeKey = Mangle::Encoding::pointer;
    185195                        else if (!isUnboundType(thisArgType)) otypeKey = Mangle::mangle(thisArgType, Mangle::Type | Mangle::NoGenericParams);
    186                         else if (skipUnbound) return false;
     196                        else if (skipUnbound) return AssertionResult::Skip;
    187197
    188198                        candidates = sat.symtab.specialLookupId(kind, otypeKey);
     
    212222
    213223                        ast::OpenVarSet closed;
    214                         findOpenVars( toType, newOpen, closed, newNeed, have, FirstClosed );
    215                         findOpenVars( adjType, newOpen, closed, newNeed, have, FirstOpen );
    216                         if ( allowConversion ) {
     224                        // findOpenVars( toType, newOpen, closed, newNeed, have, FirstClosed );
     225                        findOpenVars( adjType, newOpen, closed, newNeed, have, newEnv, FirstOpen );
     226                        ast::TypeEnvironment tempNewEnv {newEnv};
     227
     228                        if ( unifyExact( toType, adjType, tempNewEnv, newNeed, have, newOpen, WidenMode {true, true} ) ) {
     229                                // set up binding slot for recursive assertions
     230                                ast::UniqueId crntResnSlot = 0;
     231                                if ( ! newNeed.empty() ) {
     232                                        crntResnSlot = ++globalResnSlot;
     233                                        for ( auto & a : newNeed ) { a.second.resnSlot = crntResnSlot; }
     234                                }
     235
     236                                matches.emplace_back(
     237                                        cdata, adjType, std::move( tempNewEnv ), std::move( have ), std::move( newNeed ),
     238                                        std::move( newOpen ), crntResnSlot );
     239                        }
     240                        else if ( matches.empty() ) {
     241                                // restore invalidated env
     242                                // newEnv = sat.cand->env;
     243                                // newNeed.clear();
    217244                                if ( auto c = commonType( toType, adjType, newEnv, newNeed, have, newOpen, WidenMode {true, true} ) ) {
    218245                                        // set up binding slot for recursive assertions
     
    223250                                        }
    224251
    225                                         matches.emplace_back(
     252                                        inexactMatches.emplace_back(
    226253                                                cdata, adjType, std::move( newEnv ), std::move( have ), std::move( newNeed ),
    227254                                                std::move( newOpen ), crntResnSlot );
    228255                                }
    229256                        }
    230                         else {
    231                                 if ( unifyExact( toType, adjType, newEnv, newNeed, have, newOpen, WidenMode {true, true} ) ) {
    232                                         // set up binding slot for recursive assertions
    233                                         ast::UniqueId crntResnSlot = 0;
    234                                         if ( ! newNeed.empty() ) {
    235                                                 crntResnSlot = ++globalResnSlot;
    236                                                 for ( auto & a : newNeed ) { a.second.resnSlot = crntResnSlot; }
    237                                         }
    238 
    239                                         matches.emplace_back(
    240                                                 cdata, adjType, std::move( newEnv ), std::move( have ), std::move( newNeed ),
    241                                                 std::move( newOpen ), crntResnSlot );
    242                                 }
    243                         }
    244257                }
    245258
    246259                // break if no satisfying match
    247                 if ( matches.empty() ) return false;
     260                if ( matches.empty() ) matches = std::move(inexactMatches);
     261                if ( matches.empty() ) return AssertionResult::Fail;
    248262
    249263                // defer if too many satisfying matches
    250264                if ( matches.size() > 1 ) {
    251265                        sat.deferred.emplace_back( assn.first, assn.second, std::move( matches ) );
    252                         return true;
     266                        return AssertionResult::Success;
    253267                }
    254268
    255269                // otherwise bind unique match in ongoing scope
    256270                AssnCandidate & match = matches.front();
    257                 addToSymbolTable( match.have, sat.symtab );
     271                // addToSymbolTable( match.have, sat.symtab );
    258272                sat.newNeed.insert( match.need.begin(), match.need.end() );
    259273                sat.cand->env = std::move( match.env );
     
    261275
    262276                bindAssertion( assn.first, assn.second, sat.cand, match, sat.inferred );
    263                 return true;
     277                return AssertionResult::Success;
    264278        }
    265279
     
    438452                // for each current mutually-compatible set of assertions
    439453                for ( SatState & sat : sats ) {
    440                         bool allowConversion = false;
    441454                        // stop this branch if a better option is already found
    442455                        auto it = thresholds.find( pruneKey( *sat.cand ) );
     
    447460                        for (unsigned resetCount = 0; ; ++resetCount) {
    448461                                ast::AssertionList next;
    449                                 resetTyVarRenaming();
    450462                                // make initial pass at matching assertions
    451463                                for ( auto & assn : sat.need ) {
     464                                        resetTyVarRenaming();
    452465                                        // fail early if any assertion is not satisfiable
    453                                         if ( ! satisfyAssertion( assn, sat, allowConversion, !next.empty() ) ) {
    454                                                 next.emplace_back(assn);
    455                                                 // goto nextSat;
    456                                         }
    457                                 }
    458                                 // success
    459                                 if (next.empty()) break;
    460                                 // fail if nothing resolves
    461                                 else if (next.size() == sat.need.size()) {
    462                                         if (allowConversion) {
     466                                        auto result = satisfyAssertion( assn, sat, !next.empty() );
     467                                        if ( result == AssertionResult::Fail ) {
    463468                                                Indenter tabs{ 3 };
    464469                                                std::ostringstream ss;
     
    466471                                                print( ss, *sat.cand, ++tabs );
    467472                                                ss << (tabs-1) << "Could not satisfy assertion:\n";
    468                                                 ast::print( ss, next[0].first, tabs );
     473                                                ast::print( ss, assn.first, tabs );
    469474
    470475                                                errors.emplace_back( ss.str() );
    471476                                                goto nextSat;
    472477                                        }
    473 
    474                                         else {
    475                                                 allowConversion = true;
    476                                                 continue;
    477                                         }
    478                                 }
    479                                 allowConversion = false;
     478                                        else if ( result == AssertionResult::Skip ) {
     479                                                next.emplace_back(assn);
     480                                                // goto nextSat;
     481                                        }
     482                                }
     483                                // success
     484                                if (next.empty()) break;
     485
    480486                                sat.need = std::move(next);
    481487                        }
     
    531537                                                sat.cand->expr, std::move( compat.env ), std::move( compat.open ),
    532538                                                ast::AssertionSet{} /* need moved into satisfaction state */,
    533                                                 sat.cand->cost, sat.cand->cvtCost );
     539                                                sat.cand->cost );
    534540
    535541                                        ast::AssertionSet nextNewNeed{ sat.newNeed };
     
    544550                                        for ( DeferRef r : compat.assns ) {
    545551                                                AssnCandidate match = r.match;
    546                                                 addToSymbolTable( match.have, nextSymtab );
     552                                                // addToSymbolTable( match.have, nextSymtab );
    547553                                                nextNewNeed.insert( match.need.begin(), match.need.end() );
    548554
  • src/ResolvExpr/Unify.cc

    rfa5e1aa5 rb7b3e41  
    160160                env.apply( newSecond );
    161161
    162                 findOpenVars( newFirst, open, closed, need, have, FirstClosed );
    163                 findOpenVars( newSecond, open, closed, need, have, FirstOpen );
     162                // findOpenVars( newFirst, open, closed, need, have, FirstClosed );
     163                findOpenVars( newSecond, open, closed, need, have, newEnv, FirstOpen );
    164164
    165165                return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden() );
     
    964964                        // check that the other type is compatible and named the same
    965965                        auto otherInst = dynamic_cast< const XInstType * >( other );
    966                         if (otherInst && inst->name == otherInst->name) this->result = otherInst;
     966                        if (otherInst && inst->name == otherInst->name)
     967                                this->result = otherInst;
    967968                        return otherInst;
    968969                }
     
    10491050
    10501051                void postvisit( const ast::TypeInstType * typeInst ) {
    1051                         assert( open.find( *typeInst ) == open.end() );
    1052                         handleRefType( typeInst, type2 );
     1052                        // assert( open.find( *typeInst ) == open.end() );
     1053                        auto otherInst = dynamic_cast< const ast::TypeInstType * >( type2 );
     1054                        if (otherInst && typeInst->name == otherInst->name)
     1055                                this->result = otherInst;
     1056                        // return otherInst;
    10531057                }
    10541058
     
    11611165        ) {
    11621166                ast::OpenVarSet closed;
    1163                 findOpenVars( type1, open, closed, need, have, FirstClosed );
    1164                 findOpenVars( type2, open, closed, need, have, FirstOpen );
     1167                // findOpenVars( type1, open, closed, need, have, FirstClosed );
     1168                findOpenVars( type2, open, closed, need, have, env, FirstOpen );
    11651169                return unifyInexact(
    11661170                        type1, type2, env, need, have, open, WidenMode{ true, true }, common );
     
    11791183                        entry1 = var1 ? open.find( *var1 ) : open.end(),
    11801184                        entry2 = var2 ? open.find( *var2 ) : open.end();
    1181                 bool isopen1 = entry1 != open.end();
    1182                 bool isopen2 = entry2 != open.end();
    1183 
     1185                // bool isopen1 = entry1 != open.end();
     1186                // bool isopen2 = entry2 != open.end();
     1187                bool isopen1 = var1 && env.lookup(*var1);
     1188                bool isopen2 = var2 && env.lookup(*var2);
     1189
     1190                /*
    11841191                if ( isopen1 && isopen2 ) {
    11851192                        if ( entry1->second.kind != entry2->second.kind ) return false;
     
    11901197                        return env.bindVar( var1, type2, entry1->second, need, have, open, widen );
    11911198                } else if ( isopen2 ) {
    1192                         return env.bindVar( var2, type1, entry2->second, need, have, open, widen );
    1193                 } else {
     1199                        return env.bindVar( var2, type1, entry2->second, need, have, open, widen, symtab );
     1200                } */
     1201                if ( isopen1 && isopen2 ) {
     1202                        if ( var1->base->kind != var2->base->kind ) return false;
     1203                        return env.bindVarToVar(
     1204                                var1, var2, ast::TypeData{ var1->base->kind, var1->base->sized||var2->base->sized }, need, have,
     1205                                open, widen );
     1206                } else if ( isopen1 ) {
     1207                        return env.bindVar( var1, type2, ast::TypeData{var1->base}, need, have, open, widen );
     1208                } else if ( isopen2 ) {
     1209                        return env.bindVar( var2, type1, ast::TypeData{var2->base}, need, have, open, widen );
     1210                }else {
    11941211                        return ast::Pass<Unify_new>::read(
    11951212                                type1, type2, env, need, have, open, widen );
    11961213                }
     1214               
    11971215        }
    11981216
  • src/SynTree/Expression.cc

    rfa5e1aa5 rb7b3e41  
    267267}
    268268
    269 CastExpr::CastExpr( Expression * arg, Type * toType, bool isGenerated ) : arg(arg), isGenerated( isGenerated ) {
     269CastExpr::CastExpr( Expression * arg, Type * toType, bool isGenerated, CastKind kind ) : arg(arg), isGenerated( isGenerated ), kind( kind ) {
    270270        set_result(toType);
    271271}
    272272
    273 CastExpr::CastExpr( Expression * arg, bool isGenerated ) : arg(arg), isGenerated( isGenerated ) {
     273CastExpr::CastExpr( Expression * arg, bool isGenerated, CastKind kind ) : arg(arg), isGenerated( isGenerated ), kind( kind ) {
    274274        set_result( new VoidType( Type::Qualifiers() ) );
    275275}
    276276
    277 CastExpr::CastExpr( const CastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) {
     277CastExpr::CastExpr( const CastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ), kind( other.kind ) {
    278278}
    279279
  • src/SynTree/Expression.h

    rfa5e1aa5 rb7b3e41  
    271271        bool isGenerated = true;
    272272
    273         CastExpr( Expression * arg, bool isGenerated = true );
    274         CastExpr( Expression * arg, Type * toType, bool isGenerated = true );
     273        enum CastKind {
     274                Default, // C
     275                Coerce, // reinterpret cast
     276                Return  // overload selection
     277        };
     278
     279        CastKind kind = Default;
     280
     281        CastExpr( Expression * arg, bool isGenerated = true, CastKind kind = Default );
     282        CastExpr( Expression * arg, Type * toType, bool isGenerated = true, CastKind kind = Default );
    275283        CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor
    276284        CastExpr( const CastExpr & other );
  • src/Tuples/TupleAssignment.cc

    rfa5e1aa5 rb7b3e41  
    679679
    680680                                ResolvExpr::CandidateFinder finder( crntFinder.context, matcher->env );
     681                                finder.allowVoid = true;
    681682
    682683                                try {
  • src/Validate/Autogen.cpp

    rfa5e1aa5 rb7b3e41  
    321321void FuncGenerator::produceDecl( const ast::FunctionDecl * decl ) {
    322322        assert( nullptr != decl->stmts );
     323        assert( decl->type_params.size() == getGenericParams( type ).size() );
    323324
    324325        definitions.push_back( decl );
     
    356357                decl->init = nullptr;
    357358                splice( assertions, decl->assertions );
    358                 oldToNew.emplace( std::make_pair( old_param, decl ) );
     359                oldToNew.emplace( old_param, decl );
    359360                type_params.push_back( decl );
    360361        }
     
    522523        InitTweak::InitExpander_new srcParam( src );
    523524        // Assign to destination.
    524         ast::Expr * dstSelect = new ast::MemberExpr(
     525        ast::MemberExpr * dstSelect = new ast::MemberExpr(
    525526                location,
    526527                field,
     
    574575                }
    575576
    576                 ast::Expr * srcSelect = (srcParam) ? new ast::MemberExpr(
     577                ast::MemberExpr * srcSelect = (srcParam) ? new ast::MemberExpr(
    577578                        location, field, new ast::VariableExpr( location, srcParam )
    578579                ) : nullptr;
  • src/Validate/HoistStruct.cpp

    rfa5e1aa5 rb7b3e41  
    1818#include <sstream>
    1919
     20#include "AST/DeclReplacer.hpp"
    2021#include "AST/Pass.hpp"
    2122#include "AST/TranslationUnit.hpp"
     23#include "AST/Vector.hpp"
    2224
    2325namespace Validate {
     
    5153        template<typename AggrDecl>
    5254        AggrDecl const * postAggregate( AggrDecl const * );
     55        template<typename InstType>
     56        InstType const * preCollectionInstType( InstType const * type );
    5357
    5458        ast::AggregateDecl const * parent = nullptr;
     
    6670        qualifiedName( decl, ss );
    6771        return ss.str();
     72}
     73
     74void extendParams( ast::vector<ast::TypeDecl> & dstParams,
     75                ast::vector<ast::TypeDecl> const & srcParams ) {
     76        if ( srcParams.empty() ) return;
     77
     78        ast::DeclReplacer::TypeMap newToOld;
     79        ast::vector<ast::TypeDecl> params;
     80        for ( ast::ptr<ast::TypeDecl> const & srcParam : srcParams ) {
     81                ast::TypeDecl * dstParam = ast::deepCopy( srcParam.get() );
     82                dstParam->init = nullptr;
     83                newToOld.emplace( srcParam, dstParam );
     84                for ( auto assertion : dstParam->assertions ) {
     85                        assertion = ast::DeclReplacer::replace( assertion, newToOld );
     86                }
     87                params.emplace_back( dstParam );
     88        }
     89        spliceBegin( dstParams, params );
    6890}
    6991
     
    7496                mut->parent = parent;
    7597                mut->name = qualifiedName( mut );
    76                 return mut;
    77         } else {
    78                 GuardValue( parent ) = decl;
    79                 return decl;
    80         }
     98                extendParams( mut->params, parent->params );
     99                decl = mut;
     100        }
     101        GuardValue( parent ) = decl;
     102        return decl;
    81103}
    82104
     
    112134}
    113135
     136ast::AggregateDecl const * commonParent(
     137                ast::AggregateDecl const * lhs, ast::AggregateDecl const * rhs ) {
     138        for ( auto outer = lhs ; outer ; outer = outer->parent ) {
     139                for ( auto inner = rhs ; inner ; inner = inner->parent ) {
     140                        if ( outer == inner ) {
     141                                return outer;
     142                        }
     143                }
     144        }
     145        return nullptr;
     146}
     147
     148template<typename InstType>
     149InstType const * HoistStructCore::preCollectionInstType( InstType const * type ) {
     150    if ( !type->base->parent ) return type;
     151    if ( type->base->params.empty() ) return type;
     152
     153    InstType * mut = ast::mutate( type );
     154    ast::AggregateDecl const * parent =
     155        commonParent( this->parent, mut->base->parent );
     156    assert( parent );
     157
     158    std::vector<ast::ptr<ast::Expr>> args;
     159    for ( const ast::ptr<ast::TypeDecl> & param : parent->params ) {
     160        args.emplace_back( new ast::TypeExpr( param->location,
     161            new ast::TypeInstType( param )
     162        ) );
     163    }
     164    spliceBegin( mut->params, args );
     165    return mut;
     166}
     167
    114168template<typename InstType>
    115169InstType const * preInstType( InstType const * type ) {
     
    121175
    122176ast::StructInstType const * HoistStructCore::previsit( ast::StructInstType const * type ) {
    123         return preInstType( type );
     177        return preInstType( preCollectionInstType( type ) );
    124178}
    125179
    126180ast::UnionInstType const * HoistStructCore::previsit( ast::UnionInstType const * type ) {
    127         return preInstType( type );
     181        return preInstType( preCollectionInstType( type ) );
    128182}
    129183
  • src/Virtual/VirtualDtor.cpp

    rfa5e1aa5 rb7b3e41  
    146146
    147147            CompoundStmt * dtorBody = mutate( decl->stmts.get() );
    148             // Adds the following to the end of any actor/message dtor:
     148            // Adds the following to the start of any actor/message dtor:
    149149            //  __CFA_dtor_shutdown( this );
    150             dtorBody->push_front( new ExprStmt(
    151                 decl->location,
    152                                 new UntypedExpr (
    153                     decl->location,
    154                                         new NameExpr( decl->location, "__CFA_dtor_shutdown" ),
    155                                         {
    156                         new NameExpr( decl->location, decl->params.at(0)->name )
    157                                         }
    158                                 )
    159                         ));
     150            dtorBody->push_front(
     151                new IfStmt( decl->location,
     152                    new UntypedExpr (
     153                        decl->location,
     154                        new NameExpr( decl->location, "__CFA_dtor_shutdown" ),
     155                        {
     156                            new NameExpr( decl->location, decl->params.at(0)->name )
     157                        }
     158                    ),
     159                    new ReturnStmt( decl->location, nullptr )
     160                )
     161            );
    160162            return;
    161163        }
  • src/main.cc

    rfa5e1aa5 rb7b3e41  
    2828#include <list>                             // for list
    2929#include <string>                           // for char_traits, operator<<
    30 
    31 using namespace std;
    3230
    3331#include "AST/Convert.hpp"
     
    8886#include "Virtual/VirtualDtor.hpp"           // for implementVirtDtors
    8987
     88using namespace std;
     89
    9090static void NewPass( const char * const name ) {
    9191        Stats::Heap::newPass( name );
     
    335335
    336336                PASS( "Fix Qualified Types", Validate::fixQualifiedTypes, transUnit );
     337                PASS( "Eliminate Typedef", Validate::eliminateTypedef, transUnit );
    337338                PASS( "Hoist Struct", Validate::hoistStruct, transUnit );
    338                 PASS( "Eliminate Typedef", Validate::eliminateTypedef, transUnit );
    339339                PASS( "Validate Generic Parameters", Validate::fillGenericParameters, transUnit );
    340340                PASS( "Translate Dimensions", Validate::translateDimensionParameters, transUnit );
  • tests/.expect/copyfile.txt

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Fri Jun 19 13:44:05 2020
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun 19 17:58:03 2020
    13 // Update Count     : 4
     12// Last Modified On : Mon Jun  5 21:20:07 2023
     13// Update Count     : 5
    1414//
    1515
     
    3030                        exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]";
    3131                } // choose
    32         } catch( Open_Failure * ex ; ex->istream == &in ) {
     32        } catch( open_failure * ex ; ex->istream == &in ) {
    3333                exit | "Unable to open input file" | argv[1];
    34         } catch( Open_Failure * ex ; ex->ostream == &out ) {
     34        } catch( open_failure * ex ; ex->ostream == &out ) {
    3535                close( in );                                                                    // optional
    3636                exit | "Unable to open output file" | argv[2];
  • tests/.expect/mathX.arm64.txt

    rfa5e1aa5 rb7b3e41  
    787787ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    788788ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    789 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    790 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    791 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    792 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    793 ceiling(64, 64) = 64, ceiling(66, 64) = -128, ceiling(-66, 64) = 0
    794 ceiling(-128, -128) = -128, ceiling(-126, -128) = -128, ceiling(126, -128) = 0
     789ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     790ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     791ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     792ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     793ceiling(64, 64) = 64, ceiling(66, 64) = -128, ceiling(-66, 64) = -64
     794ceiling(-128, -128) = -128, ceiling(-126, -128) = 0, ceiling(126, -128) = -128
    795795
    796796unsigned char
     
    807807ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    808808ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    809 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    810 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    811 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    812 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    813 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    814 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    815 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    816 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    817 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    818 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    819 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    820 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    821 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = -32768, ceiling(-16386, 16384) = 0
    822 ceiling(-32768, -32768) = -32768, ceiling(-32766, -32768) = -32768, ceiling(32766, -32768) = 0
     809ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     810ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     811ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     812ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     813ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     814ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     815ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     816ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     817ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     818ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     819ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     820ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     821ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = -32768, ceiling(-16386, 16384) = -16384
     822ceiling(-32768, -32768) = -32768, ceiling(-32766, -32768) = 0, ceiling(32766, -32768) = -32768
    823823
    824824unsigned short int
     
    843843ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    844844ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    845 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    846 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    847 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    848 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    849 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    850 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    851 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    852 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    853 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    854 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    855 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    856 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    857 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = 0
    858 ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = 0
    859 ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = 0
    860 ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = 0
    861 ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = 0
    862 ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = 0
    863 ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = 0
    864 ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = 0
    865 ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = 0
    866 ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = 0
    867 ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = 0
    868 ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = 0
    869 ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = 0
    870 ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = 0
    871 ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = 0
    872 ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = 0
    873 ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = -1073741824, ceiling(-1073741826, 1073741824) = 0
    874 ceiling(-2147483648, -2147483648) = -2147483648, ceiling(-2147483646, -2147483648) = 0, ceiling(2147483646, -2147483648) = 0
     845ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     846ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     847ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     848ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     849ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     850ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     851ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     852ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     853ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     854ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     855ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     856ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     857ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = -16384
     858ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = -32768
     859ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = -65536
     860ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = -131072
     861ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = -262144
     862ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = -524288
     863ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = -1048576
     864ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = -2097152
     865ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = -4194304
     866ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = -8388608
     867ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = -16777216
     868ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = -33554432
     869ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = -67108864
     870ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = -134217728
     871ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = -268435456
     872ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = -536870912
     873ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = -2147483648, ceiling(-1073741826, 1073741824) = -1073741824
     874ceiling(-2147483648, -2147483648) = -2147483648, ceiling(-2147483646, -2147483648) = 0, ceiling(2147483646, -2147483648) = -2147483648
    875875
    876876unsigned int
     
    911911ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    912912ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    913 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    914 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    915 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    916 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    917 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    918 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    919 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    920 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    921 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    922 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    923 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    924 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    925 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = 0
    926 ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = 0
    927 ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = 0
    928 ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = 0
    929 ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = 0
    930 ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = 0
    931 ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = 0
    932 ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = 0
    933 ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = 0
    934 ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = 0
    935 ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = 0
    936 ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = 0
    937 ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = 0
    938 ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = 0
    939 ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = 0
    940 ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = 0
    941 ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = 2147483648, ceiling(-1073741826, 1073741824) = 0
    942 ceiling(2147483648, 2147483648) = 2147483648, ceiling(2147483650, 2147483648) = 4294967296, ceiling(-2147483650, 2147483648) = 0
    943 ceiling(4294967296, 4294967296) = 4294967296, ceiling(4294967298, 4294967296) = 8589934592, ceiling(-4294967298, 4294967296) = 0
    944 ceiling(8589934592, 8589934592) = 8589934592, ceiling(8589934594, 8589934592) = 17179869184, ceiling(-8589934594, 8589934592) = 0
    945 ceiling(17179869184, 17179869184) = 17179869184, ceiling(17179869186, 17179869184) = 34359738368, ceiling(-17179869186, 17179869184) = 0
    946 ceiling(34359738368, 34359738368) = 34359738368, ceiling(34359738370, 34359738368) = 68719476736, ceiling(-34359738370, 34359738368) = 0
    947 ceiling(68719476736, 68719476736) = 68719476736, ceiling(68719476738, 68719476736) = 137438953472, ceiling(-68719476738, 68719476736) = 0
    948 ceiling(137438953472, 137438953472) = 137438953472, ceiling(137438953474, 137438953472) = 274877906944, ceiling(-137438953474, 137438953472) = 0
    949 ceiling(274877906944, 274877906944) = 274877906944, ceiling(274877906946, 274877906944) = 549755813888, ceiling(-274877906946, 274877906944) = 0
    950 ceiling(549755813888, 549755813888) = 549755813888, ceiling(549755813890, 549755813888) = 1099511627776, ceiling(-549755813890, 549755813888) = 0
    951 ceiling(1099511627776, 1099511627776) = 1099511627776, ceiling(1099511627778, 1099511627776) = 2199023255552, ceiling(-1099511627778, 1099511627776) = 0
    952 ceiling(2199023255552, 2199023255552) = 2199023255552, ceiling(2199023255554, 2199023255552) = 4398046511104, ceiling(-2199023255554, 2199023255552) = 0
    953 ceiling(4398046511104, 4398046511104) = 4398046511104, ceiling(4398046511106, 4398046511104) = 8796093022208, ceiling(-4398046511106, 4398046511104) = 0
    954 ceiling(8796093022208, 8796093022208) = 8796093022208, ceiling(8796093022210, 8796093022208) = 17592186044416, ceiling(-8796093022210, 8796093022208) = 0
    955 ceiling(17592186044416, 17592186044416) = 17592186044416, ceiling(17592186044418, 17592186044416) = 35184372088832, ceiling(-17592186044418, 17592186044416) = 0
    956 ceiling(35184372088832, 35184372088832) = 35184372088832, ceiling(35184372088834, 35184372088832) = 70368744177664, ceiling(-35184372088834, 35184372088832) = 0
    957 ceiling(70368744177664, 70368744177664) = 70368744177664, ceiling(70368744177666, 70368744177664) = 140737488355328, ceiling(-70368744177666, 70368744177664) = 0
    958 ceiling(140737488355328, 140737488355328) = 140737488355328, ceiling(140737488355330, 140737488355328) = 281474976710656, ceiling(-140737488355330, 140737488355328) = 0
    959 ceiling(281474976710656, 281474976710656) = 281474976710656, ceiling(281474976710658, 281474976710656) = 562949953421312, ceiling(-281474976710658, 281474976710656) = 0
    960 ceiling(562949953421312, 562949953421312) = 562949953421312, ceiling(562949953421314, 562949953421312) = 1125899906842624, ceiling(-562949953421314, 562949953421312) = 0
    961 ceiling(1125899906842624, 1125899906842624) = 1125899906842624, ceiling(1125899906842626, 1125899906842624) = 2251799813685248, ceiling(-1125899906842626, 1125899906842624) = 0
    962 ceiling(2251799813685248, 2251799813685248) = 2251799813685248, ceiling(2251799813685250, 2251799813685248) = 4503599627370496, ceiling(-2251799813685250, 2251799813685248) = 0
    963 ceiling(4503599627370496, 4503599627370496) = 4503599627370496, ceiling(4503599627370498, 4503599627370496) = 9007199254740992, ceiling(-4503599627370498, 4503599627370496) = 0
    964 ceiling(9007199254740992, 9007199254740992) = 9007199254740992, ceiling(9007199254740994, 9007199254740992) = 18014398509481984, ceiling(-9007199254740994, 9007199254740992) = 0
    965 ceiling(18014398509481984, 18014398509481984) = 18014398509481984, ceiling(18014398509481986, 18014398509481984) = 36028797018963968, ceiling(-18014398509481986, 18014398509481984) = 0
    966 ceiling(36028797018963968, 36028797018963968) = 36028797018963968, ceiling(36028797018963970, 36028797018963968) = 72057594037927936, ceiling(-36028797018963970, 36028797018963968) = 0
    967 ceiling(72057594037927936, 72057594037927936) = 72057594037927936, ceiling(72057594037927938, 72057594037927936) = 144115188075855872, ceiling(-72057594037927938, 72057594037927936) = 0
    968 ceiling(144115188075855872, 144115188075855872) = 144115188075855872, ceiling(144115188075855874, 144115188075855872) = 288230376151711744, ceiling(-144115188075855874, 144115188075855872) = 0
    969 ceiling(288230376151711744, 288230376151711744) = 288230376151711744, ceiling(288230376151711746, 288230376151711744) = 576460752303423488, ceiling(-288230376151711746, 288230376151711744) = 0
    970 ceiling(576460752303423488, 576460752303423488) = 576460752303423488, ceiling(576460752303423490, 576460752303423488) = 1152921504606846976, ceiling(-576460752303423490, 576460752303423488) = 0
    971 ceiling(1152921504606846976, 1152921504606846976) = 1152921504606846976, ceiling(1152921504606846978, 1152921504606846976) = 2305843009213693952, ceiling(-1152921504606846978, 1152921504606846976) = 0
    972 ceiling(2305843009213693952, 2305843009213693952) = 2305843009213693952, ceiling(2305843009213693954, 2305843009213693952) = 4611686018427387904, ceiling(-2305843009213693954, 2305843009213693952) = 0
    973 ceiling(4611686018427387904, 4611686018427387904) = 4611686018427387904, ceiling(4611686018427387906, 4611686018427387904) = -4611686018427387904, ceiling(-4611686018427387906, 4611686018427387904) = 0
    974 ceiling(-9223372036854775808, -9223372036854775808) = -9223372036854775808, ceiling(-9223372036854775806, -9223372036854775808) = 0, ceiling(9223372036854775806, -9223372036854775808) = 0
     913ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     914ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     915ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     916ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     917ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     918ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     919ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     920ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     921ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     922ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     923ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     924ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     925ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = -16384
     926ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = -32768
     927ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = -65536
     928ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = -131072
     929ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = -262144
     930ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = -524288
     931ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = -1048576
     932ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = -2097152
     933ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = -4194304
     934ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = -8388608
     935ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = -16777216
     936ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = -33554432
     937ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = -67108864
     938ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = -134217728
     939ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = -268435456
     940ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = -536870912
     941ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = 2147483648, ceiling(-1073741826, 1073741824) = -1073741824
     942ceiling(2147483648, 2147483648) = 2147483648, ceiling(2147483650, 2147483648) = 4294967296, ceiling(-2147483650, 2147483648) = -2147483648
     943ceiling(4294967296, 4294967296) = 4294967296, ceiling(4294967298, 4294967296) = 8589934592, ceiling(-4294967298, 4294967296) = -4294967296
     944ceiling(8589934592, 8589934592) = 8589934592, ceiling(8589934594, 8589934592) = 17179869184, ceiling(-8589934594, 8589934592) = -8589934592
     945ceiling(17179869184, 17179869184) = 17179869184, ceiling(17179869186, 17179869184) = 34359738368, ceiling(-17179869186, 17179869184) = -17179869184
     946ceiling(34359738368, 34359738368) = 34359738368, ceiling(34359738370, 34359738368) = 68719476736, ceiling(-34359738370, 34359738368) = -34359738368
     947ceiling(68719476736, 68719476736) = 68719476736, ceiling(68719476738, 68719476736) = 137438953472, ceiling(-68719476738, 68719476736) = -68719476736
     948ceiling(137438953472, 137438953472) = 137438953472, ceiling(137438953474, 137438953472) = 274877906944, ceiling(-137438953474, 137438953472) = -137438953472
     949ceiling(274877906944, 274877906944) = 274877906944, ceiling(274877906946, 274877906944) = 549755813888, ceiling(-274877906946, 274877906944) = -274877906944
     950ceiling(549755813888, 549755813888) = 549755813888, ceiling(549755813890, 549755813888) = 1099511627776, ceiling(-549755813890, 549755813888) = -549755813888
     951ceiling(1099511627776, 1099511627776) = 1099511627776, ceiling(1099511627778, 1099511627776) = 2199023255552, ceiling(-1099511627778, 1099511627776) = -1099511627776
     952ceiling(2199023255552, 2199023255552) = 2199023255552, ceiling(2199023255554, 2199023255552) = 4398046511104, ceiling(-2199023255554, 2199023255552) = -2199023255552
     953ceiling(4398046511104, 4398046511104) = 4398046511104, ceiling(4398046511106, 4398046511104) = 8796093022208, ceiling(-4398046511106, 4398046511104) = -4398046511104
     954ceiling(8796093022208, 8796093022208) = 8796093022208, ceiling(8796093022210, 8796093022208) = 17592186044416, ceiling(-8796093022210, 8796093022208) = -8796093022208
     955ceiling(17592186044416, 17592186044416) = 17592186044416, ceiling(17592186044418, 17592186044416) = 35184372088832, ceiling(-17592186044418, 17592186044416) = -17592186044416
     956ceiling(35184372088832, 35184372088832) = 35184372088832, ceiling(35184372088834, 35184372088832) = 70368744177664, ceiling(-35184372088834, 35184372088832) = -35184372088832
     957ceiling(70368744177664, 70368744177664) = 70368744177664, ceiling(70368744177666, 70368744177664) = 140737488355328, ceiling(-70368744177666, 70368744177664) = -70368744177664
     958ceiling(140737488355328, 140737488355328) = 140737488355328, ceiling(140737488355330, 140737488355328) = 281474976710656, ceiling(-140737488355330, 140737488355328) = -140737488355328
     959ceiling(281474976710656, 281474976710656) = 281474976710656, ceiling(281474976710658, 281474976710656) = 562949953421312, ceiling(-281474976710658, 281474976710656) = -281474976710656
     960ceiling(562949953421312, 562949953421312) = 562949953421312, ceiling(562949953421314, 562949953421312) = 1125899906842624, ceiling(-562949953421314, 562949953421312) = -562949953421312
     961ceiling(1125899906842624, 1125899906842624) = 1125899906842624, ceiling(1125899906842626, 1125899906842624) = 2251799813685248, ceiling(-1125899906842626, 1125899906842624) = -1125899906842624
     962ceiling(2251799813685248, 2251799813685248) = 2251799813685248, ceiling(2251799813685250, 2251799813685248) = 4503599627370496, ceiling(-2251799813685250, 2251799813685248) = -2251799813685248
     963ceiling(4503599627370496, 4503599627370496) = 4503599627370496, ceiling(4503599627370498, 4503599627370496) = 9007199254740992, ceiling(-4503599627370498, 4503599627370496) = -4503599627370496
     964ceiling(9007199254740992, 9007199254740992) = 9007199254740992, ceiling(9007199254740994, 9007199254740992) = 18014398509481984, ceiling(-9007199254740994, 9007199254740992) = -9007199254740992
     965ceiling(18014398509481984, 18014398509481984) = 18014398509481984, ceiling(18014398509481986, 18014398509481984) = 36028797018963968, ceiling(-18014398509481986, 18014398509481984) = -18014398509481984
     966ceiling(36028797018963968, 36028797018963968) = 36028797018963968, ceiling(36028797018963970, 36028797018963968) = 72057594037927936, ceiling(-36028797018963970, 36028797018963968) = -36028797018963968
     967ceiling(72057594037927936, 72057594037927936) = 72057594037927936, ceiling(72057594037927938, 72057594037927936) = 144115188075855872, ceiling(-72057594037927938, 72057594037927936) = -72057594037927936
     968ceiling(144115188075855872, 144115188075855872) = 144115188075855872, ceiling(144115188075855874, 144115188075855872) = 288230376151711744, ceiling(-144115188075855874, 144115188075855872) = -144115188075855872
     969ceiling(288230376151711744, 288230376151711744) = 288230376151711744, ceiling(288230376151711746, 288230376151711744) = 576460752303423488, ceiling(-288230376151711746, 288230376151711744) = -288230376151711744
     970ceiling(576460752303423488, 576460752303423488) = 576460752303423488, ceiling(576460752303423490, 576460752303423488) = 1152921504606846976, ceiling(-576460752303423490, 576460752303423488) = -576460752303423488
     971ceiling(1152921504606846976, 1152921504606846976) = 1152921504606846976, ceiling(1152921504606846978, 1152921504606846976) = 2305843009213693952, ceiling(-1152921504606846978, 1152921504606846976) = -1152921504606846976
     972ceiling(2305843009213693952, 2305843009213693952) = 2305843009213693952, ceiling(2305843009213693954, 2305843009213693952) = 4611686018427387904, ceiling(-2305843009213693954, 2305843009213693952) = -2305843009213693952
     973ceiling(4611686018427387904, 4611686018427387904) = 4611686018427387904, ceiling(4611686018427387906, 4611686018427387904) = -9223372036854775808, ceiling(-4611686018427387906, 4611686018427387904) = -4611686018427387904
     974ceiling(-9223372036854775808, -9223372036854775808) = -9223372036854775808, ceiling(-9223372036854775806, -9223372036854775808) = 0, ceiling(9223372036854775806, -9223372036854775808) = -9223372036854775808
    975975
    976976unsigned long int
     
    10431043ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    10441044ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    1045 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    1046 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    1047 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    1048 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    1049 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    1050 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    1051 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    1052 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    1053 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    1054 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    1055 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    1056 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    1057 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = 0
    1058 ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = 0
    1059 ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = 0
    1060 ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = 0
    1061 ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = 0
    1062 ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = 0
    1063 ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = 0
    1064 ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = 0
    1065 ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = 0
    1066 ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = 0
    1067 ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = 0
    1068 ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = 0
    1069 ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = 0
    1070 ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = 0
    1071 ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = 0
    1072 ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = 0
    1073 ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = 2147483648, ceiling(-1073741826, 1073741824) = 0
    1074 ceiling(2147483648, 2147483648) = 2147483648, ceiling(2147483650, 2147483648) = 4294967296, ceiling(-2147483650, 2147483648) = 0
    1075 ceiling(4294967296, 4294967296) = 4294967296, ceiling(4294967298, 4294967296) = 8589934592, ceiling(-4294967298, 4294967296) = 0
    1076 ceiling(8589934592, 8589934592) = 8589934592, ceiling(8589934594, 8589934592) = 17179869184, ceiling(-8589934594, 8589934592) = 0
    1077 ceiling(17179869184, 17179869184) = 17179869184, ceiling(17179869186, 17179869184) = 34359738368, ceiling(-17179869186, 17179869184) = 0
    1078 ceiling(34359738368, 34359738368) = 34359738368, ceiling(34359738370, 34359738368) = 68719476736, ceiling(-34359738370, 34359738368) = 0
    1079 ceiling(68719476736, 68719476736) = 68719476736, ceiling(68719476738, 68719476736) = 137438953472, ceiling(-68719476738, 68719476736) = 0
    1080 ceiling(137438953472, 137438953472) = 137438953472, ceiling(137438953474, 137438953472) = 274877906944, ceiling(-137438953474, 137438953472) = 0
    1081 ceiling(274877906944, 274877906944) = 274877906944, ceiling(274877906946, 274877906944) = 549755813888, ceiling(-274877906946, 274877906944) = 0
    1082 ceiling(549755813888, 549755813888) = 549755813888, ceiling(549755813890, 549755813888) = 1099511627776, ceiling(-549755813890, 549755813888) = 0
    1083 ceiling(1099511627776, 1099511627776) = 1099511627776, ceiling(1099511627778, 1099511627776) = 2199023255552, ceiling(-1099511627778, 1099511627776) = 0
    1084 ceiling(2199023255552, 2199023255552) = 2199023255552, ceiling(2199023255554, 2199023255552) = 4398046511104, ceiling(-2199023255554, 2199023255552) = 0
    1085 ceiling(4398046511104, 4398046511104) = 4398046511104, ceiling(4398046511106, 4398046511104) = 8796093022208, ceiling(-4398046511106, 4398046511104) = 0
    1086 ceiling(8796093022208, 8796093022208) = 8796093022208, ceiling(8796093022210, 8796093022208) = 17592186044416, ceiling(-8796093022210, 8796093022208) = 0
    1087 ceiling(17592186044416, 17592186044416) = 17592186044416, ceiling(17592186044418, 17592186044416) = 35184372088832, ceiling(-17592186044418, 17592186044416) = 0
    1088 ceiling(35184372088832, 35184372088832) = 35184372088832, ceiling(35184372088834, 35184372088832) = 70368744177664, ceiling(-35184372088834, 35184372088832) = 0
    1089 ceiling(70368744177664, 70368744177664) = 70368744177664, ceiling(70368744177666, 70368744177664) = 140737488355328, ceiling(-70368744177666, 70368744177664) = 0
    1090 ceiling(140737488355328, 140737488355328) = 140737488355328, ceiling(140737488355330, 140737488355328) = 281474976710656, ceiling(-140737488355330, 140737488355328) = 0
    1091 ceiling(281474976710656, 281474976710656) = 281474976710656, ceiling(281474976710658, 281474976710656) = 562949953421312, ceiling(-281474976710658, 281474976710656) = 0
    1092 ceiling(562949953421312, 562949953421312) = 562949953421312, ceiling(562949953421314, 562949953421312) = 1125899906842624, ceiling(-562949953421314, 562949953421312) = 0
    1093 ceiling(1125899906842624, 1125899906842624) = 1125899906842624, ceiling(1125899906842626, 1125899906842624) = 2251799813685248, ceiling(-1125899906842626, 1125899906842624) = 0
    1094 ceiling(2251799813685248, 2251799813685248) = 2251799813685248, ceiling(2251799813685250, 2251799813685248) = 4503599627370496, ceiling(-2251799813685250, 2251799813685248) = 0
    1095 ceiling(4503599627370496, 4503599627370496) = 4503599627370496, ceiling(4503599627370498, 4503599627370496) = 9007199254740992, ceiling(-4503599627370498, 4503599627370496) = 0
    1096 ceiling(9007199254740992, 9007199254740992) = 9007199254740992, ceiling(9007199254740994, 9007199254740992) = 18014398509481984, ceiling(-9007199254740994, 9007199254740992) = 0
    1097 ceiling(18014398509481984, 18014398509481984) = 18014398509481984, ceiling(18014398509481986, 18014398509481984) = 36028797018963968, ceiling(-18014398509481986, 18014398509481984) = 0
    1098 ceiling(36028797018963968, 36028797018963968) = 36028797018963968, ceiling(36028797018963970, 36028797018963968) = 72057594037927936, ceiling(-36028797018963970, 36028797018963968) = 0
    1099 ceiling(72057594037927936, 72057594037927936) = 72057594037927936, ceiling(72057594037927938, 72057594037927936) = 144115188075855872, ceiling(-72057594037927938, 72057594037927936) = 0
    1100 ceiling(144115188075855872, 144115188075855872) = 144115188075855872, ceiling(144115188075855874, 144115188075855872) = 288230376151711744, ceiling(-144115188075855874, 144115188075855872) = 0
    1101 ceiling(288230376151711744, 288230376151711744) = 288230376151711744, ceiling(288230376151711746, 288230376151711744) = 576460752303423488, ceiling(-288230376151711746, 288230376151711744) = 0
    1102 ceiling(576460752303423488, 576460752303423488) = 576460752303423488, ceiling(576460752303423490, 576460752303423488) = 1152921504606846976, ceiling(-576460752303423490, 576460752303423488) = 0
    1103 ceiling(1152921504606846976, 1152921504606846976) = 1152921504606846976, ceiling(1152921504606846978, 1152921504606846976) = 2305843009213693952, ceiling(-1152921504606846978, 1152921504606846976) = 0
    1104 ceiling(2305843009213693952, 2305843009213693952) = 2305843009213693952, ceiling(2305843009213693954, 2305843009213693952) = 4611686018427387904, ceiling(-2305843009213693954, 2305843009213693952) = 0
    1105 ceiling(4611686018427387904, 4611686018427387904) = 4611686018427387904, ceiling(4611686018427387906, 4611686018427387904) = -4611686018427387904, ceiling(-4611686018427387906, 4611686018427387904) = 0
    1106 ceiling(-9223372036854775808, -9223372036854775808) = -9223372036854775808, ceiling(-9223372036854775806, -9223372036854775808) = 0, ceiling(9223372036854775806, -9223372036854775808) = 0
     1045ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     1046ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     1047ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     1048ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     1049ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     1050ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     1051ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     1052ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     1053ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     1054ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     1055ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     1056ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     1057ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = -16384
     1058ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = -32768
     1059ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = -65536
     1060ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = -131072
     1061ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = -262144
     1062ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = -524288
     1063ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = -1048576
     1064ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = -2097152
     1065ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = -4194304
     1066ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = -8388608
     1067ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = -16777216
     1068ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = -33554432
     1069ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = -67108864
     1070ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = -134217728
     1071ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = -268435456
     1072ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = -536870912
     1073ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = 2147483648, ceiling(-1073741826, 1073741824) = -1073741824
     1074ceiling(2147483648, 2147483648) = 2147483648, ceiling(2147483650, 2147483648) = 4294967296, ceiling(-2147483650, 2147483648) = -2147483648
     1075ceiling(4294967296, 4294967296) = 4294967296, ceiling(4294967298, 4294967296) = 8589934592, ceiling(-4294967298, 4294967296) = -4294967296
     1076ceiling(8589934592, 8589934592) = 8589934592, ceiling(8589934594, 8589934592) = 17179869184, ceiling(-8589934594, 8589934592) = -8589934592
     1077ceiling(17179869184, 17179869184) = 17179869184, ceiling(17179869186, 17179869184) = 34359738368, ceiling(-17179869186, 17179869184) = -17179869184
     1078ceiling(34359738368, 34359738368) = 34359738368, ceiling(34359738370, 34359738368) = 68719476736, ceiling(-34359738370, 34359738368) = -34359738368
     1079ceiling(68719476736, 68719476736) = 68719476736, ceiling(68719476738, 68719476736) = 137438953472, ceiling(-68719476738, 68719476736) = -68719476736
     1080ceiling(137438953472, 137438953472) = 137438953472, ceiling(137438953474, 137438953472) = 274877906944, ceiling(-137438953474, 137438953472) = -137438953472
     1081ceiling(274877906944, 274877906944) = 274877906944, ceiling(274877906946, 274877906944) = 549755813888, ceiling(-274877906946, 274877906944) = -274877906944
     1082ceiling(549755813888, 549755813888) = 549755813888, ceiling(549755813890, 549755813888) = 1099511627776, ceiling(-549755813890, 549755813888) = -549755813888
     1083ceiling(1099511627776, 1099511627776) = 1099511627776, ceiling(1099511627778, 1099511627776) = 2199023255552, ceiling(-1099511627778, 1099511627776) = -1099511627776
     1084ceiling(2199023255552, 2199023255552) = 2199023255552, ceiling(2199023255554, 2199023255552) = 4398046511104, ceiling(-2199023255554, 2199023255552) = -2199023255552
     1085ceiling(4398046511104, 4398046511104) = 4398046511104, ceiling(4398046511106, 4398046511104) = 8796093022208, ceiling(-4398046511106, 4398046511104) = -4398046511104
     1086ceiling(8796093022208, 8796093022208) = 8796093022208, ceiling(8796093022210, 8796093022208) = 17592186044416, ceiling(-8796093022210, 8796093022208) = -8796093022208
     1087ceiling(17592186044416, 17592186044416) = 17592186044416, ceiling(17592186044418, 17592186044416) = 35184372088832, ceiling(-17592186044418, 17592186044416) = -17592186044416
     1088ceiling(35184372088832, 35184372088832) = 35184372088832, ceiling(35184372088834, 35184372088832) = 70368744177664, ceiling(-35184372088834, 35184372088832) = -35184372088832
     1089ceiling(70368744177664, 70368744177664) = 70368744177664, ceiling(70368744177666, 70368744177664) = 140737488355328, ceiling(-70368744177666, 70368744177664) = -70368744177664
     1090ceiling(140737488355328, 140737488355328) = 140737488355328, ceiling(140737488355330, 140737488355328) = 281474976710656, ceiling(-140737488355330, 140737488355328) = -140737488355328
     1091ceiling(281474976710656, 281474976710656) = 281474976710656, ceiling(281474976710658, 281474976710656) = 562949953421312, ceiling(-281474976710658, 281474976710656) = -281474976710656
     1092ceiling(562949953421312, 562949953421312) = 562949953421312, ceiling(562949953421314, 562949953421312) = 1125899906842624, ceiling(-562949953421314, 562949953421312) = -562949953421312
     1093ceiling(1125899906842624, 1125899906842624) = 1125899906842624, ceiling(1125899906842626, 1125899906842624) = 2251799813685248, ceiling(-1125899906842626, 1125899906842624) = -1125899906842624
     1094ceiling(2251799813685248, 2251799813685248) = 2251799813685248, ceiling(2251799813685250, 2251799813685248) = 4503599627370496, ceiling(-2251799813685250, 2251799813685248) = -2251799813685248
     1095ceiling(4503599627370496, 4503599627370496) = 4503599627370496, ceiling(4503599627370498, 4503599627370496) = 9007199254740992, ceiling(-4503599627370498, 4503599627370496) = -4503599627370496
     1096ceiling(9007199254740992, 9007199254740992) = 9007199254740992, ceiling(9007199254740994, 9007199254740992) = 18014398509481984, ceiling(-9007199254740994, 9007199254740992) = -9007199254740992
     1097ceiling(18014398509481984, 18014398509481984) = 18014398509481984, ceiling(18014398509481986, 18014398509481984) = 36028797018963968, ceiling(-18014398509481986, 18014398509481984) = -18014398509481984
     1098ceiling(36028797018963968, 36028797018963968) = 36028797018963968, ceiling(36028797018963970, 36028797018963968) = 72057594037927936, ceiling(-36028797018963970, 36028797018963968) = -36028797018963968
     1099ceiling(72057594037927936, 72057594037927936) = 72057594037927936, ceiling(72057594037927938, 72057594037927936) = 144115188075855872, ceiling(-72057594037927938, 72057594037927936) = -72057594037927936
     1100ceiling(144115188075855872, 144115188075855872) = 144115188075855872, ceiling(144115188075855874, 144115188075855872) = 288230376151711744, ceiling(-144115188075855874, 144115188075855872) = -144115188075855872
     1101ceiling(288230376151711744, 288230376151711744) = 288230376151711744, ceiling(288230376151711746, 288230376151711744) = 576460752303423488, ceiling(-288230376151711746, 288230376151711744) = -288230376151711744
     1102ceiling(576460752303423488, 576460752303423488) = 576460752303423488, ceiling(576460752303423490, 576460752303423488) = 1152921504606846976, ceiling(-576460752303423490, 576460752303423488) = -576460752303423488
     1103ceiling(1152921504606846976, 1152921504606846976) = 1152921504606846976, ceiling(1152921504606846978, 1152921504606846976) = 2305843009213693952, ceiling(-1152921504606846978, 1152921504606846976) = -1152921504606846976
     1104ceiling(2305843009213693952, 2305843009213693952) = 2305843009213693952, ceiling(2305843009213693954, 2305843009213693952) = 4611686018427387904, ceiling(-2305843009213693954, 2305843009213693952) = -2305843009213693952
     1105ceiling(4611686018427387904, 4611686018427387904) = 4611686018427387904, ceiling(4611686018427387906, 4611686018427387904) = -9223372036854775808, ceiling(-4611686018427387906, 4611686018427387904) = -4611686018427387904
     1106ceiling(-9223372036854775808, -9223372036854775808) = -9223372036854775808, ceiling(-9223372036854775806, -9223372036854775808) = 0, ceiling(9223372036854775806, -9223372036854775808) = -9223372036854775808
    11071107
    11081108unsigned long long int
  • tests/.expect/mathX.x64.txt

    rfa5e1aa5 rb7b3e41  
    787787ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    788788ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    789 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    790 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    791 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    792 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    793 ceiling(64, 64) = 64, ceiling(66, 64) = -128, ceiling(-66, 64) = 0
    794 ceiling(-128, -128) = -128, ceiling(-126, -128) = -128, ceiling(126, -128) = 0
     789ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     790ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     791ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     792ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     793ceiling(64, 64) = 64, ceiling(66, 64) = -128, ceiling(-66, 64) = -64
     794ceiling(-128, -128) = -128, ceiling(-126, -128) = 0, ceiling(126, -128) = -128
    795795
    796796unsigned char
     
    807807ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    808808ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    809 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    810 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    811 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    812 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    813 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    814 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    815 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    816 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    817 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    818 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    819 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    820 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    821 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = -32768, ceiling(-16386, 16384) = 0
    822 ceiling(-32768, -32768) = -32768, ceiling(-32766, -32768) = -32768, ceiling(32766, -32768) = 0
     809ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     810ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     811ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     812ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     813ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     814ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     815ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     816ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     817ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     818ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     819ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     820ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     821ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = -32768, ceiling(-16386, 16384) = -16384
     822ceiling(-32768, -32768) = -32768, ceiling(-32766, -32768) = 0, ceiling(32766, -32768) = -32768
    823823
    824824unsigned short int
     
    843843ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    844844ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    845 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    846 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    847 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    848 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    849 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    850 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    851 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    852 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    853 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    854 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    855 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    856 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    857 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = 0
    858 ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = 0
    859 ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = 0
    860 ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = 0
    861 ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = 0
    862 ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = 0
    863 ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = 0
    864 ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = 0
    865 ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = 0
    866 ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = 0
    867 ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = 0
    868 ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = 0
    869 ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = 0
    870 ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = 0
    871 ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = 0
    872 ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = 0
    873 ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = -1073741824, ceiling(-1073741826, 1073741824) = 0
    874 ceiling(-2147483648, -2147483648) = -2147483648, ceiling(-2147483646, -2147483648) = 0, ceiling(2147483646, -2147483648) = 0
     845ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     846ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     847ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     848ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     849ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     850ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     851ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     852ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     853ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     854ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     855ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     856ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     857ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = -16384
     858ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = -32768
     859ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = -65536
     860ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = -131072
     861ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = -262144
     862ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = -524288
     863ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = -1048576
     864ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = -2097152
     865ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = -4194304
     866ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = -8388608
     867ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = -16777216
     868ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = -33554432
     869ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = -67108864
     870ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = -134217728
     871ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = -268435456
     872ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = -536870912
     873ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = -2147483648, ceiling(-1073741826, 1073741824) = -1073741824
     874ceiling(-2147483648, -2147483648) = -2147483648, ceiling(-2147483646, -2147483648) = 0, ceiling(2147483646, -2147483648) = -2147483648
    875875
    876876unsigned int
     
    911911ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    912912ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    913 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    914 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    915 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    916 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    917 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    918 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    919 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    920 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    921 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    922 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    923 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    924 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    925 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = 0
    926 ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = 0
    927 ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = 0
    928 ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = 0
    929 ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = 0
    930 ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = 0
    931 ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = 0
    932 ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = 0
    933 ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = 0
    934 ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = 0
    935 ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = 0
    936 ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = 0
    937 ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = 0
    938 ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = 0
    939 ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = 0
    940 ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = 0
    941 ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = 2147483648, ceiling(-1073741826, 1073741824) = 0
    942 ceiling(2147483648, 2147483648) = 2147483648, ceiling(2147483650, 2147483648) = 4294967296, ceiling(-2147483650, 2147483648) = 0
    943 ceiling(4294967296, 4294967296) = 4294967296, ceiling(4294967298, 4294967296) = 8589934592, ceiling(-4294967298, 4294967296) = 0
    944 ceiling(8589934592, 8589934592) = 8589934592, ceiling(8589934594, 8589934592) = 17179869184, ceiling(-8589934594, 8589934592) = 0
    945 ceiling(17179869184, 17179869184) = 17179869184, ceiling(17179869186, 17179869184) = 34359738368, ceiling(-17179869186, 17179869184) = 0
    946 ceiling(34359738368, 34359738368) = 34359738368, ceiling(34359738370, 34359738368) = 68719476736, ceiling(-34359738370, 34359738368) = 0
    947 ceiling(68719476736, 68719476736) = 68719476736, ceiling(68719476738, 68719476736) = 137438953472, ceiling(-68719476738, 68719476736) = 0
    948 ceiling(137438953472, 137438953472) = 137438953472, ceiling(137438953474, 137438953472) = 274877906944, ceiling(-137438953474, 137438953472) = 0
    949 ceiling(274877906944, 274877906944) = 274877906944, ceiling(274877906946, 274877906944) = 549755813888, ceiling(-274877906946, 274877906944) = 0
    950 ceiling(549755813888, 549755813888) = 549755813888, ceiling(549755813890, 549755813888) = 1099511627776, ceiling(-549755813890, 549755813888) = 0
    951 ceiling(1099511627776, 1099511627776) = 1099511627776, ceiling(1099511627778, 1099511627776) = 2199023255552, ceiling(-1099511627778, 1099511627776) = 0
    952 ceiling(2199023255552, 2199023255552) = 2199023255552, ceiling(2199023255554, 2199023255552) = 4398046511104, ceiling(-2199023255554, 2199023255552) = 0
    953 ceiling(4398046511104, 4398046511104) = 4398046511104, ceiling(4398046511106, 4398046511104) = 8796093022208, ceiling(-4398046511106, 4398046511104) = 0
    954 ceiling(8796093022208, 8796093022208) = 8796093022208, ceiling(8796093022210, 8796093022208) = 17592186044416, ceiling(-8796093022210, 8796093022208) = 0
    955 ceiling(17592186044416, 17592186044416) = 17592186044416, ceiling(17592186044418, 17592186044416) = 35184372088832, ceiling(-17592186044418, 17592186044416) = 0
    956 ceiling(35184372088832, 35184372088832) = 35184372088832, ceiling(35184372088834, 35184372088832) = 70368744177664, ceiling(-35184372088834, 35184372088832) = 0
    957 ceiling(70368744177664, 70368744177664) = 70368744177664, ceiling(70368744177666, 70368744177664) = 140737488355328, ceiling(-70368744177666, 70368744177664) = 0
    958 ceiling(140737488355328, 140737488355328) = 140737488355328, ceiling(140737488355330, 140737488355328) = 281474976710656, ceiling(-140737488355330, 140737488355328) = 0
    959 ceiling(281474976710656, 281474976710656) = 281474976710656, ceiling(281474976710658, 281474976710656) = 562949953421312, ceiling(-281474976710658, 281474976710656) = 0
    960 ceiling(562949953421312, 562949953421312) = 562949953421312, ceiling(562949953421314, 562949953421312) = 1125899906842624, ceiling(-562949953421314, 562949953421312) = 0
    961 ceiling(1125899906842624, 1125899906842624) = 1125899906842624, ceiling(1125899906842626, 1125899906842624) = 2251799813685248, ceiling(-1125899906842626, 1125899906842624) = 0
    962 ceiling(2251799813685248, 2251799813685248) = 2251799813685248, ceiling(2251799813685250, 2251799813685248) = 4503599627370496, ceiling(-2251799813685250, 2251799813685248) = 0
    963 ceiling(4503599627370496, 4503599627370496) = 4503599627370496, ceiling(4503599627370498, 4503599627370496) = 9007199254740992, ceiling(-4503599627370498, 4503599627370496) = 0
    964 ceiling(9007199254740992, 9007199254740992) = 9007199254740992, ceiling(9007199254740994, 9007199254740992) = 18014398509481984, ceiling(-9007199254740994, 9007199254740992) = 0
    965 ceiling(18014398509481984, 18014398509481984) = 18014398509481984, ceiling(18014398509481986, 18014398509481984) = 36028797018963968, ceiling(-18014398509481986, 18014398509481984) = 0
    966 ceiling(36028797018963968, 36028797018963968) = 36028797018963968, ceiling(36028797018963970, 36028797018963968) = 72057594037927936, ceiling(-36028797018963970, 36028797018963968) = 0
    967 ceiling(72057594037927936, 72057594037927936) = 72057594037927936, ceiling(72057594037927938, 72057594037927936) = 144115188075855872, ceiling(-72057594037927938, 72057594037927936) = 0
    968 ceiling(144115188075855872, 144115188075855872) = 144115188075855872, ceiling(144115188075855874, 144115188075855872) = 288230376151711744, ceiling(-144115188075855874, 144115188075855872) = 0
    969 ceiling(288230376151711744, 288230376151711744) = 288230376151711744, ceiling(288230376151711746, 288230376151711744) = 576460752303423488, ceiling(-288230376151711746, 288230376151711744) = 0
    970 ceiling(576460752303423488, 576460752303423488) = 576460752303423488, ceiling(576460752303423490, 576460752303423488) = 1152921504606846976, ceiling(-576460752303423490, 576460752303423488) = 0
    971 ceiling(1152921504606846976, 1152921504606846976) = 1152921504606846976, ceiling(1152921504606846978, 1152921504606846976) = 2305843009213693952, ceiling(-1152921504606846978, 1152921504606846976) = 0
    972 ceiling(2305843009213693952, 2305843009213693952) = 2305843009213693952, ceiling(2305843009213693954, 2305843009213693952) = 4611686018427387904, ceiling(-2305843009213693954, 2305843009213693952) = 0
    973 ceiling(4611686018427387904, 4611686018427387904) = 4611686018427387904, ceiling(4611686018427387906, 4611686018427387904) = -4611686018427387904, ceiling(-4611686018427387906, 4611686018427387904) = 0
    974 ceiling(-9223372036854775808, -9223372036854775808) = -9223372036854775808, ceiling(-9223372036854775806, -9223372036854775808) = 0, ceiling(9223372036854775806, -9223372036854775808) = 0
     913ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     914ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     915ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     916ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     917ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     918ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     919ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     920ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     921ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     922ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     923ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     924ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     925ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = -16384
     926ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = -32768
     927ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = -65536
     928ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = -131072
     929ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = -262144
     930ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = -524288
     931ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = -1048576
     932ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = -2097152
     933ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = -4194304
     934ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = -8388608
     935ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = -16777216
     936ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = -33554432
     937ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = -67108864
     938ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = -134217728
     939ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = -268435456
     940ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = -536870912
     941ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = 2147483648, ceiling(-1073741826, 1073741824) = -1073741824
     942ceiling(2147483648, 2147483648) = 2147483648, ceiling(2147483650, 2147483648) = 4294967296, ceiling(-2147483650, 2147483648) = -2147483648
     943ceiling(4294967296, 4294967296) = 4294967296, ceiling(4294967298, 4294967296) = 8589934592, ceiling(-4294967298, 4294967296) = -4294967296
     944ceiling(8589934592, 8589934592) = 8589934592, ceiling(8589934594, 8589934592) = 17179869184, ceiling(-8589934594, 8589934592) = -8589934592
     945ceiling(17179869184, 17179869184) = 17179869184, ceiling(17179869186, 17179869184) = 34359738368, ceiling(-17179869186, 17179869184) = -17179869184
     946ceiling(34359738368, 34359738368) = 34359738368, ceiling(34359738370, 34359738368) = 68719476736, ceiling(-34359738370, 34359738368) = -34359738368
     947ceiling(68719476736, 68719476736) = 68719476736, ceiling(68719476738, 68719476736) = 137438953472, ceiling(-68719476738, 68719476736) = -68719476736
     948ceiling(137438953472, 137438953472) = 137438953472, ceiling(137438953474, 137438953472) = 274877906944, ceiling(-137438953474, 137438953472) = -137438953472
     949ceiling(274877906944, 274877906944) = 274877906944, ceiling(274877906946, 274877906944) = 549755813888, ceiling(-274877906946, 274877906944) = -274877906944
     950ceiling(549755813888, 549755813888) = 549755813888, ceiling(549755813890, 549755813888) = 1099511627776, ceiling(-549755813890, 549755813888) = -549755813888
     951ceiling(1099511627776, 1099511627776) = 1099511627776, ceiling(1099511627778, 1099511627776) = 2199023255552, ceiling(-1099511627778, 1099511627776) = -1099511627776
     952ceiling(2199023255552, 2199023255552) = 2199023255552, ceiling(2199023255554, 2199023255552) = 4398046511104, ceiling(-2199023255554, 2199023255552) = -2199023255552
     953ceiling(4398046511104, 4398046511104) = 4398046511104, ceiling(4398046511106, 4398046511104) = 8796093022208, ceiling(-4398046511106, 4398046511104) = -4398046511104
     954ceiling(8796093022208, 8796093022208) = 8796093022208, ceiling(8796093022210, 8796093022208) = 17592186044416, ceiling(-8796093022210, 8796093022208) = -8796093022208
     955ceiling(17592186044416, 17592186044416) = 17592186044416, ceiling(17592186044418, 17592186044416) = 35184372088832, ceiling(-17592186044418, 17592186044416) = -17592186044416
     956ceiling(35184372088832, 35184372088832) = 35184372088832, ceiling(35184372088834, 35184372088832) = 70368744177664, ceiling(-35184372088834, 35184372088832) = -35184372088832
     957ceiling(70368744177664, 70368744177664) = 70368744177664, ceiling(70368744177666, 70368744177664) = 140737488355328, ceiling(-70368744177666, 70368744177664) = -70368744177664
     958ceiling(140737488355328, 140737488355328) = 140737488355328, ceiling(140737488355330, 140737488355328) = 281474976710656, ceiling(-140737488355330, 140737488355328) = -140737488355328
     959ceiling(281474976710656, 281474976710656) = 281474976710656, ceiling(281474976710658, 281474976710656) = 562949953421312, ceiling(-281474976710658, 281474976710656) = -281474976710656
     960ceiling(562949953421312, 562949953421312) = 562949953421312, ceiling(562949953421314, 562949953421312) = 1125899906842624, ceiling(-562949953421314, 562949953421312) = -562949953421312
     961ceiling(1125899906842624, 1125899906842624) = 1125899906842624, ceiling(1125899906842626, 1125899906842624) = 2251799813685248, ceiling(-1125899906842626, 1125899906842624) = -1125899906842624
     962ceiling(2251799813685248, 2251799813685248) = 2251799813685248, ceiling(2251799813685250, 2251799813685248) = 4503599627370496, ceiling(-2251799813685250, 2251799813685248) = -2251799813685248
     963ceiling(4503599627370496, 4503599627370496) = 4503599627370496, ceiling(4503599627370498, 4503599627370496) = 9007199254740992, ceiling(-4503599627370498, 4503599627370496) = -4503599627370496
     964ceiling(9007199254740992, 9007199254740992) = 9007199254740992, ceiling(9007199254740994, 9007199254740992) = 18014398509481984, ceiling(-9007199254740994, 9007199254740992) = -9007199254740992
     965ceiling(18014398509481984, 18014398509481984) = 18014398509481984, ceiling(18014398509481986, 18014398509481984) = 36028797018963968, ceiling(-18014398509481986, 18014398509481984) = -18014398509481984
     966ceiling(36028797018963968, 36028797018963968) = 36028797018963968, ceiling(36028797018963970, 36028797018963968) = 72057594037927936, ceiling(-36028797018963970, 36028797018963968) = -36028797018963968
     967ceiling(72057594037927936, 72057594037927936) = 72057594037927936, ceiling(72057594037927938, 72057594037927936) = 144115188075855872, ceiling(-72057594037927938, 72057594037927936) = -72057594037927936
     968ceiling(144115188075855872, 144115188075855872) = 144115188075855872, ceiling(144115188075855874, 144115188075855872) = 288230376151711744, ceiling(-144115188075855874, 144115188075855872) = -144115188075855872
     969ceiling(288230376151711744, 288230376151711744) = 288230376151711744, ceiling(288230376151711746, 288230376151711744) = 576460752303423488, ceiling(-288230376151711746, 288230376151711744) = -288230376151711744
     970ceiling(576460752303423488, 576460752303423488) = 576460752303423488, ceiling(576460752303423490, 576460752303423488) = 1152921504606846976, ceiling(-576460752303423490, 576460752303423488) = -576460752303423488
     971ceiling(1152921504606846976, 1152921504606846976) = 1152921504606846976, ceiling(1152921504606846978, 1152921504606846976) = 2305843009213693952, ceiling(-1152921504606846978, 1152921504606846976) = -1152921504606846976
     972ceiling(2305843009213693952, 2305843009213693952) = 2305843009213693952, ceiling(2305843009213693954, 2305843009213693952) = 4611686018427387904, ceiling(-2305843009213693954, 2305843009213693952) = -2305843009213693952
     973ceiling(4611686018427387904, 4611686018427387904) = 4611686018427387904, ceiling(4611686018427387906, 4611686018427387904) = -9223372036854775808, ceiling(-4611686018427387906, 4611686018427387904) = -4611686018427387904
     974ceiling(-9223372036854775808, -9223372036854775808) = -9223372036854775808, ceiling(-9223372036854775806, -9223372036854775808) = 0, ceiling(9223372036854775806, -9223372036854775808) = -9223372036854775808
    975975
    976976unsigned long int
     
    10431043ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    10441044ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    1045 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    1046 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    1047 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    1048 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    1049 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    1050 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    1051 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    1052 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    1053 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    1054 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    1055 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    1056 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    1057 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = 0
    1058 ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = 0
    1059 ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = 0
    1060 ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = 0
    1061 ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = 0
    1062 ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = 0
    1063 ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = 0
    1064 ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = 0
    1065 ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = 0
    1066 ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = 0
    1067 ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = 0
    1068 ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = 0
    1069 ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = 0
    1070 ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = 0
    1071 ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = 0
    1072 ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = 0
    1073 ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = 2147483648, ceiling(-1073741826, 1073741824) = 0
    1074 ceiling(2147483648, 2147483648) = 2147483648, ceiling(2147483650, 2147483648) = 4294967296, ceiling(-2147483650, 2147483648) = 0
    1075 ceiling(4294967296, 4294967296) = 4294967296, ceiling(4294967298, 4294967296) = 8589934592, ceiling(-4294967298, 4294967296) = 0
    1076 ceiling(8589934592, 8589934592) = 8589934592, ceiling(8589934594, 8589934592) = 17179869184, ceiling(-8589934594, 8589934592) = 0
    1077 ceiling(17179869184, 17179869184) = 17179869184, ceiling(17179869186, 17179869184) = 34359738368, ceiling(-17179869186, 17179869184) = 0
    1078 ceiling(34359738368, 34359738368) = 34359738368, ceiling(34359738370, 34359738368) = 68719476736, ceiling(-34359738370, 34359738368) = 0
    1079 ceiling(68719476736, 68719476736) = 68719476736, ceiling(68719476738, 68719476736) = 137438953472, ceiling(-68719476738, 68719476736) = 0
    1080 ceiling(137438953472, 137438953472) = 137438953472, ceiling(137438953474, 137438953472) = 274877906944, ceiling(-137438953474, 137438953472) = 0
    1081 ceiling(274877906944, 274877906944) = 274877906944, ceiling(274877906946, 274877906944) = 549755813888, ceiling(-274877906946, 274877906944) = 0
    1082 ceiling(549755813888, 549755813888) = 549755813888, ceiling(549755813890, 549755813888) = 1099511627776, ceiling(-549755813890, 549755813888) = 0
    1083 ceiling(1099511627776, 1099511627776) = 1099511627776, ceiling(1099511627778, 1099511627776) = 2199023255552, ceiling(-1099511627778, 1099511627776) = 0
    1084 ceiling(2199023255552, 2199023255552) = 2199023255552, ceiling(2199023255554, 2199023255552) = 4398046511104, ceiling(-2199023255554, 2199023255552) = 0
    1085 ceiling(4398046511104, 4398046511104) = 4398046511104, ceiling(4398046511106, 4398046511104) = 8796093022208, ceiling(-4398046511106, 4398046511104) = 0
    1086 ceiling(8796093022208, 8796093022208) = 8796093022208, ceiling(8796093022210, 8796093022208) = 17592186044416, ceiling(-8796093022210, 8796093022208) = 0
    1087 ceiling(17592186044416, 17592186044416) = 17592186044416, ceiling(17592186044418, 17592186044416) = 35184372088832, ceiling(-17592186044418, 17592186044416) = 0
    1088 ceiling(35184372088832, 35184372088832) = 35184372088832, ceiling(35184372088834, 35184372088832) = 70368744177664, ceiling(-35184372088834, 35184372088832) = 0
    1089 ceiling(70368744177664, 70368744177664) = 70368744177664, ceiling(70368744177666, 70368744177664) = 140737488355328, ceiling(-70368744177666, 70368744177664) = 0
    1090 ceiling(140737488355328, 140737488355328) = 140737488355328, ceiling(140737488355330, 140737488355328) = 281474976710656, ceiling(-140737488355330, 140737488355328) = 0
    1091 ceiling(281474976710656, 281474976710656) = 281474976710656, ceiling(281474976710658, 281474976710656) = 562949953421312, ceiling(-281474976710658, 281474976710656) = 0
    1092 ceiling(562949953421312, 562949953421312) = 562949953421312, ceiling(562949953421314, 562949953421312) = 1125899906842624, ceiling(-562949953421314, 562949953421312) = 0
    1093 ceiling(1125899906842624, 1125899906842624) = 1125899906842624, ceiling(1125899906842626, 1125899906842624) = 2251799813685248, ceiling(-1125899906842626, 1125899906842624) = 0
    1094 ceiling(2251799813685248, 2251799813685248) = 2251799813685248, ceiling(2251799813685250, 2251799813685248) = 4503599627370496, ceiling(-2251799813685250, 2251799813685248) = 0
    1095 ceiling(4503599627370496, 4503599627370496) = 4503599627370496, ceiling(4503599627370498, 4503599627370496) = 9007199254740992, ceiling(-4503599627370498, 4503599627370496) = 0
    1096 ceiling(9007199254740992, 9007199254740992) = 9007199254740992, ceiling(9007199254740994, 9007199254740992) = 18014398509481984, ceiling(-9007199254740994, 9007199254740992) = 0
    1097 ceiling(18014398509481984, 18014398509481984) = 18014398509481984, ceiling(18014398509481986, 18014398509481984) = 36028797018963968, ceiling(-18014398509481986, 18014398509481984) = 0
    1098 ceiling(36028797018963968, 36028797018963968) = 36028797018963968, ceiling(36028797018963970, 36028797018963968) = 72057594037927936, ceiling(-36028797018963970, 36028797018963968) = 0
    1099 ceiling(72057594037927936, 72057594037927936) = 72057594037927936, ceiling(72057594037927938, 72057594037927936) = 144115188075855872, ceiling(-72057594037927938, 72057594037927936) = 0
    1100 ceiling(144115188075855872, 144115188075855872) = 144115188075855872, ceiling(144115188075855874, 144115188075855872) = 288230376151711744, ceiling(-144115188075855874, 144115188075855872) = 0
    1101 ceiling(288230376151711744, 288230376151711744) = 288230376151711744, ceiling(288230376151711746, 288230376151711744) = 576460752303423488, ceiling(-288230376151711746, 288230376151711744) = 0
    1102 ceiling(576460752303423488, 576460752303423488) = 576460752303423488, ceiling(576460752303423490, 576460752303423488) = 1152921504606846976, ceiling(-576460752303423490, 576460752303423488) = 0
    1103 ceiling(1152921504606846976, 1152921504606846976) = 1152921504606846976, ceiling(1152921504606846978, 1152921504606846976) = 2305843009213693952, ceiling(-1152921504606846978, 1152921504606846976) = 0
    1104 ceiling(2305843009213693952, 2305843009213693952) = 2305843009213693952, ceiling(2305843009213693954, 2305843009213693952) = 4611686018427387904, ceiling(-2305843009213693954, 2305843009213693952) = 0
    1105 ceiling(4611686018427387904, 4611686018427387904) = 4611686018427387904, ceiling(4611686018427387906, 4611686018427387904) = -4611686018427387904, ceiling(-4611686018427387906, 4611686018427387904) = 0
    1106 ceiling(-9223372036854775808, -9223372036854775808) = -9223372036854775808, ceiling(-9223372036854775806, -9223372036854775808) = 0, ceiling(9223372036854775806, -9223372036854775808) = 0
     1045ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     1046ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     1047ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     1048ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     1049ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     1050ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     1051ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     1052ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     1053ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     1054ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     1055ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     1056ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     1057ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = -16384
     1058ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = -32768
     1059ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = -65536
     1060ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = -131072
     1061ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = -262144
     1062ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = -524288
     1063ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = -1048576
     1064ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = -2097152
     1065ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = -4194304
     1066ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = -8388608
     1067ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = -16777216
     1068ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = -33554432
     1069ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = -67108864
     1070ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = -134217728
     1071ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = -268435456
     1072ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = -536870912
     1073ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = 2147483648, ceiling(-1073741826, 1073741824) = -1073741824
     1074ceiling(2147483648, 2147483648) = 2147483648, ceiling(2147483650, 2147483648) = 4294967296, ceiling(-2147483650, 2147483648) = -2147483648
     1075ceiling(4294967296, 4294967296) = 4294967296, ceiling(4294967298, 4294967296) = 8589934592, ceiling(-4294967298, 4294967296) = -4294967296
     1076ceiling(8589934592, 8589934592) = 8589934592, ceiling(8589934594, 8589934592) = 17179869184, ceiling(-8589934594, 8589934592) = -8589934592
     1077ceiling(17179869184, 17179869184) = 17179869184, ceiling(17179869186, 17179869184) = 34359738368, ceiling(-17179869186, 17179869184) = -17179869184
     1078ceiling(34359738368, 34359738368) = 34359738368, ceiling(34359738370, 34359738368) = 68719476736, ceiling(-34359738370, 34359738368) = -34359738368
     1079ceiling(68719476736, 68719476736) = 68719476736, ceiling(68719476738, 68719476736) = 137438953472, ceiling(-68719476738, 68719476736) = -68719476736
     1080ceiling(137438953472, 137438953472) = 137438953472, ceiling(137438953474, 137438953472) = 274877906944, ceiling(-137438953474, 137438953472) = -137438953472
     1081ceiling(274877906944, 274877906944) = 274877906944, ceiling(274877906946, 274877906944) = 549755813888, ceiling(-274877906946, 274877906944) = -274877906944
     1082ceiling(549755813888, 549755813888) = 549755813888, ceiling(549755813890, 549755813888) = 1099511627776, ceiling(-549755813890, 549755813888) = -549755813888
     1083ceiling(1099511627776, 1099511627776) = 1099511627776, ceiling(1099511627778, 1099511627776) = 2199023255552, ceiling(-1099511627778, 1099511627776) = -1099511627776
     1084ceiling(2199023255552, 2199023255552) = 2199023255552, ceiling(2199023255554, 2199023255552) = 4398046511104, ceiling(-2199023255554, 2199023255552) = -2199023255552
     1085ceiling(4398046511104, 4398046511104) = 4398046511104, ceiling(4398046511106, 4398046511104) = 8796093022208, ceiling(-4398046511106, 4398046511104) = -4398046511104
     1086ceiling(8796093022208, 8796093022208) = 8796093022208, ceiling(8796093022210, 8796093022208) = 17592186044416, ceiling(-8796093022210, 8796093022208) = -8796093022208
     1087ceiling(17592186044416, 17592186044416) = 17592186044416, ceiling(17592186044418, 17592186044416) = 35184372088832, ceiling(-17592186044418, 17592186044416) = -17592186044416
     1088ceiling(35184372088832, 35184372088832) = 35184372088832, ceiling(35184372088834, 35184372088832) = 70368744177664, ceiling(-35184372088834, 35184372088832) = -35184372088832
     1089ceiling(70368744177664, 70368744177664) = 70368744177664, ceiling(70368744177666, 70368744177664) = 140737488355328, ceiling(-70368744177666, 70368744177664) = -70368744177664
     1090ceiling(140737488355328, 140737488355328) = 140737488355328, ceiling(140737488355330, 140737488355328) = 281474976710656, ceiling(-140737488355330, 140737488355328) = -140737488355328
     1091ceiling(281474976710656, 281474976710656) = 281474976710656, ceiling(281474976710658, 281474976710656) = 562949953421312, ceiling(-281474976710658, 281474976710656) = -281474976710656
     1092ceiling(562949953421312, 562949953421312) = 562949953421312, ceiling(562949953421314, 562949953421312) = 1125899906842624, ceiling(-562949953421314, 562949953421312) = -562949953421312
     1093ceiling(1125899906842624, 1125899906842624) = 1125899906842624, ceiling(1125899906842626, 1125899906842624) = 2251799813685248, ceiling(-1125899906842626, 1125899906842624) = -1125899906842624
     1094ceiling(2251799813685248, 2251799813685248) = 2251799813685248, ceiling(2251799813685250, 2251799813685248) = 4503599627370496, ceiling(-2251799813685250, 2251799813685248) = -2251799813685248
     1095ceiling(4503599627370496, 4503599627370496) = 4503599627370496, ceiling(4503599627370498, 4503599627370496) = 9007199254740992, ceiling(-4503599627370498, 4503599627370496) = -4503599627370496
     1096ceiling(9007199254740992, 9007199254740992) = 9007199254740992, ceiling(9007199254740994, 9007199254740992) = 18014398509481984, ceiling(-9007199254740994, 9007199254740992) = -9007199254740992
     1097ceiling(18014398509481984, 18014398509481984) = 18014398509481984, ceiling(18014398509481986, 18014398509481984) = 36028797018963968, ceiling(-18014398509481986, 18014398509481984) = -18014398509481984
     1098ceiling(36028797018963968, 36028797018963968) = 36028797018963968, ceiling(36028797018963970, 36028797018963968) = 72057594037927936, ceiling(-36028797018963970, 36028797018963968) = -36028797018963968
     1099ceiling(72057594037927936, 72057594037927936) = 72057594037927936, ceiling(72057594037927938, 72057594037927936) = 144115188075855872, ceiling(-72057594037927938, 72057594037927936) = -72057594037927936
     1100ceiling(144115188075855872, 144115188075855872) = 144115188075855872, ceiling(144115188075855874, 144115188075855872) = 288230376151711744, ceiling(-144115188075855874, 144115188075855872) = -144115188075855872
     1101ceiling(288230376151711744, 288230376151711744) = 288230376151711744, ceiling(288230376151711746, 288230376151711744) = 576460752303423488, ceiling(-288230376151711746, 288230376151711744) = -288230376151711744
     1102ceiling(576460752303423488, 576460752303423488) = 576460752303423488, ceiling(576460752303423490, 576460752303423488) = 1152921504606846976, ceiling(-576460752303423490, 576460752303423488) = -576460752303423488
     1103ceiling(1152921504606846976, 1152921504606846976) = 1152921504606846976, ceiling(1152921504606846978, 1152921504606846976) = 2305843009213693952, ceiling(-1152921504606846978, 1152921504606846976) = -1152921504606846976
     1104ceiling(2305843009213693952, 2305843009213693952) = 2305843009213693952, ceiling(2305843009213693954, 2305843009213693952) = 4611686018427387904, ceiling(-2305843009213693954, 2305843009213693952) = -2305843009213693952
     1105ceiling(4611686018427387904, 4611686018427387904) = 4611686018427387904, ceiling(4611686018427387906, 4611686018427387904) = -9223372036854775808, ceiling(-4611686018427387906, 4611686018427387904) = -4611686018427387904
     1106ceiling(-9223372036854775808, -9223372036854775808) = -9223372036854775808, ceiling(-9223372036854775806, -9223372036854775808) = 0, ceiling(9223372036854775806, -9223372036854775808) = -9223372036854775808
    11071107
    11081108unsigned long long int
  • tests/.expect/mathX.x86.txt

    rfa5e1aa5 rb7b3e41  
    659659ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    660660ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    661 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    662 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    663 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    664 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    665 ceiling(64, 64) = 64, ceiling(66, 64) = -128, ceiling(-66, 64) = 0
    666 ceiling(-128, -128) = -128, ceiling(-126, -128) = -128, ceiling(126, -128) = 0
     661ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     662ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     663ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     664ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     665ceiling(64, 64) = 64, ceiling(66, 64) = -128, ceiling(-66, 64) = -64
     666ceiling(-128, -128) = -128, ceiling(-126, -128) = 0, ceiling(126, -128) = -128
    667667
    668668unsigned char
     
    679679ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    680680ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    681 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    682 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    683 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    684 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    685 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    686 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    687 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    688 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    689 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    690 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    691 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    692 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    693 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = -32768, ceiling(-16386, 16384) = 0
    694 ceiling(-32768, -32768) = -32768, ceiling(-32766, -32768) = -32768, ceiling(32766, -32768) = 0
     681ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     682ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     683ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     684ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     685ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     686ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     687ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     688ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     689ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     690ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     691ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     692ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     693ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = -32768, ceiling(-16386, 16384) = -16384
     694ceiling(-32768, -32768) = -32768, ceiling(-32766, -32768) = 0, ceiling(32766, -32768) = -32768
    695695
    696696unsigned short int
     
    715715ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    716716ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    717 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    718 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    719 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    720 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    721 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    722 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    723 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    724 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    725 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    726 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    727 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    728 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    729 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = 0
    730 ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = 0
    731 ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = 0
    732 ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = 0
    733 ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = 0
    734 ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = 0
    735 ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = 0
    736 ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = 0
    737 ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = 0
    738 ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = 0
    739 ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = 0
    740 ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = 0
    741 ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = 0
    742 ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = 0
    743 ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = 0
    744 ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = 0
    745 ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = -1073741824, ceiling(-1073741826, 1073741824) = 0
    746 ceiling(-2147483648, -2147483648) = -2147483648, ceiling(-2147483646, -2147483648) = 0, ceiling(2147483646, -2147483648) = 0
     717ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     718ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     719ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     720ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     721ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     722ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     723ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     724ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     725ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     726ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     727ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     728ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     729ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = -16384
     730ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = -32768
     731ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = -65536
     732ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = -131072
     733ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = -262144
     734ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = -524288
     735ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = -1048576
     736ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = -2097152
     737ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = -4194304
     738ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = -8388608
     739ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = -16777216
     740ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = -33554432
     741ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = -67108864
     742ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = -134217728
     743ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = -268435456
     744ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = -536870912
     745ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = -2147483648, ceiling(-1073741826, 1073741824) = -1073741824
     746ceiling(-2147483648, -2147483648) = -2147483648, ceiling(-2147483646, -2147483648) = 0, ceiling(2147483646, -2147483648) = -2147483648
    747747
    748748unsigned int
     
    783783ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    784784ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    785 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    786 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    787 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    788 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    789 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    790 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    791 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    792 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    793 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    794 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    795 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    796 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    797 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = 0
    798 ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = 0
    799 ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = 0
    800 ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = 0
    801 ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = 0
    802 ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = 0
    803 ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = 0
    804 ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = 0
    805 ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = 0
    806 ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = 0
    807 ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = 0
    808 ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = 0
    809 ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = 0
    810 ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = 0
    811 ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = 0
    812 ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = 0
    813 ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = -1073741824, ceiling(-1073741826, 1073741824) = 0
    814 ceiling(-2147483648, -2147483648) = -2147483648, ceiling(-2147483646, -2147483648) = 0, ceiling(2147483646, -2147483648) = 0
     785ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     786ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     787ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     788ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     789ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     790ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     791ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     792ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     793ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     794ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     795ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     796ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     797ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = -16384
     798ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = -32768
     799ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = -65536
     800ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = -131072
     801ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = -262144
     802ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = -524288
     803ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = -1048576
     804ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = -2097152
     805ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = -4194304
     806ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = -8388608
     807ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = -16777216
     808ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = -33554432
     809ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = -67108864
     810ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = -134217728
     811ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = -268435456
     812ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = -536870912
     813ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = -2147483648, ceiling(-1073741826, 1073741824) = -1073741824
     814ceiling(-2147483648, -2147483648) = -2147483648, ceiling(-2147483646, -2147483648) = 0, ceiling(2147483646, -2147483648) = -2147483648
    815815
    816816unsigned long int
     
    851851ceiling(1, 1) = 1, ceiling(3, 1) = 3, ceiling(-3, 1) = -3
    852852ceiling(2, 2) = 2, ceiling(4, 2) = 4, ceiling(-4, 2) = -4
    853 ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = 0
    854 ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = 0
    855 ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = 0
    856 ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = 0
    857 ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = 0
    858 ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = 0
    859 ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = 0
    860 ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = 0
    861 ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = 0
    862 ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = 0
    863 ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = 0
    864 ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = 0
    865 ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = 0
    866 ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = 0
    867 ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = 0
    868 ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = 0
    869 ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = 0
    870 ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = 0
    871 ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = 0
    872 ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = 0
    873 ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = 0
    874 ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = 0
    875 ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = 0
    876 ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = 0
    877 ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = 0
    878 ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = 0
    879 ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = 0
    880 ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = 0
    881 ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = 2147483648, ceiling(-1073741826, 1073741824) = 0
    882 ceiling(2147483648, 2147483648) = 2147483648, ceiling(2147483650, 2147483648) = 4294967296, ceiling(-2147483650, 2147483648) = 0
    883 ceiling(4294967296, 4294967296) = 4294967296, ceiling(4294967298, 4294967296) = 8589934592, ceiling(-4294967298, 4294967296) = 0
    884 ceiling(8589934592, 8589934592) = 8589934592, ceiling(8589934594, 8589934592) = 17179869184, ceiling(-8589934594, 8589934592) = 0
    885 ceiling(17179869184, 17179869184) = 17179869184, ceiling(17179869186, 17179869184) = 34359738368, ceiling(-17179869186, 17179869184) = 0
    886 ceiling(34359738368, 34359738368) = 34359738368, ceiling(34359738370, 34359738368) = 68719476736, ceiling(-34359738370, 34359738368) = 0
    887 ceiling(68719476736, 68719476736) = 68719476736, ceiling(68719476738, 68719476736) = 137438953472, ceiling(-68719476738, 68719476736) = 0
    888 ceiling(137438953472, 137438953472) = 137438953472, ceiling(137438953474, 137438953472) = 274877906944, ceiling(-137438953474, 137438953472) = 0
    889 ceiling(274877906944, 274877906944) = 274877906944, ceiling(274877906946, 274877906944) = 549755813888, ceiling(-274877906946, 274877906944) = 0
    890 ceiling(549755813888, 549755813888) = 549755813888, ceiling(549755813890, 549755813888) = 1099511627776, ceiling(-549755813890, 549755813888) = 0
    891 ceiling(1099511627776, 1099511627776) = 1099511627776, ceiling(1099511627778, 1099511627776) = 2199023255552, ceiling(-1099511627778, 1099511627776) = 0
    892 ceiling(2199023255552, 2199023255552) = 2199023255552, ceiling(2199023255554, 2199023255552) = 4398046511104, ceiling(-2199023255554, 2199023255552) = 0
    893 ceiling(4398046511104, 4398046511104) = 4398046511104, ceiling(4398046511106, 4398046511104) = 8796093022208, ceiling(-4398046511106, 4398046511104) = 0
    894 ceiling(8796093022208, 8796093022208) = 8796093022208, ceiling(8796093022210, 8796093022208) = 17592186044416, ceiling(-8796093022210, 8796093022208) = 0
    895 ceiling(17592186044416, 17592186044416) = 17592186044416, ceiling(17592186044418, 17592186044416) = 35184372088832, ceiling(-17592186044418, 17592186044416) = 0
    896 ceiling(35184372088832, 35184372088832) = 35184372088832, ceiling(35184372088834, 35184372088832) = 70368744177664, ceiling(-35184372088834, 35184372088832) = 0
    897 ceiling(70368744177664, 70368744177664) = 70368744177664, ceiling(70368744177666, 70368744177664) = 140737488355328, ceiling(-70368744177666, 70368744177664) = 0
    898 ceiling(140737488355328, 140737488355328) = 140737488355328, ceiling(140737488355330, 140737488355328) = 281474976710656, ceiling(-140737488355330, 140737488355328) = 0
    899 ceiling(281474976710656, 281474976710656) = 281474976710656, ceiling(281474976710658, 281474976710656) = 562949953421312, ceiling(-281474976710658, 281474976710656) = 0
    900 ceiling(562949953421312, 562949953421312) = 562949953421312, ceiling(562949953421314, 562949953421312) = 1125899906842624, ceiling(-562949953421314, 562949953421312) = 0
    901 ceiling(1125899906842624, 1125899906842624) = 1125899906842624, ceiling(1125899906842626, 1125899906842624) = 2251799813685248, ceiling(-1125899906842626, 1125899906842624) = 0
    902 ceiling(2251799813685248, 2251799813685248) = 2251799813685248, ceiling(2251799813685250, 2251799813685248) = 4503599627370496, ceiling(-2251799813685250, 2251799813685248) = 0
    903 ceiling(4503599627370496, 4503599627370496) = 4503599627370496, ceiling(4503599627370498, 4503599627370496) = 9007199254740992, ceiling(-4503599627370498, 4503599627370496) = 0
    904 ceiling(9007199254740992, 9007199254740992) = 9007199254740992, ceiling(9007199254740994, 9007199254740992) = 18014398509481984, ceiling(-9007199254740994, 9007199254740992) = 0
    905 ceiling(18014398509481984, 18014398509481984) = 18014398509481984, ceiling(18014398509481986, 18014398509481984) = 36028797018963968, ceiling(-18014398509481986, 18014398509481984) = 0
    906 ceiling(36028797018963968, 36028797018963968) = 36028797018963968, ceiling(36028797018963970, 36028797018963968) = 72057594037927936, ceiling(-36028797018963970, 36028797018963968) = 0
    907 ceiling(72057594037927936, 72057594037927936) = 72057594037927936, ceiling(72057594037927938, 72057594037927936) = 144115188075855872, ceiling(-72057594037927938, 72057594037927936) = 0
    908 ceiling(144115188075855872, 144115188075855872) = 144115188075855872, ceiling(144115188075855874, 144115188075855872) = 288230376151711744, ceiling(-144115188075855874, 144115188075855872) = 0
    909 ceiling(288230376151711744, 288230376151711744) = 288230376151711744, ceiling(288230376151711746, 288230376151711744) = 576460752303423488, ceiling(-288230376151711746, 288230376151711744) = 0
    910 ceiling(576460752303423488, 576460752303423488) = 576460752303423488, ceiling(576460752303423490, 576460752303423488) = 1152921504606846976, ceiling(-576460752303423490, 576460752303423488) = 0
    911 ceiling(1152921504606846976, 1152921504606846976) = 1152921504606846976, ceiling(1152921504606846978, 1152921504606846976) = 2305843009213693952, ceiling(-1152921504606846978, 1152921504606846976) = 0
    912 ceiling(2305843009213693952, 2305843009213693952) = 2305843009213693952, ceiling(2305843009213693954, 2305843009213693952) = 4611686018427387904, ceiling(-2305843009213693954, 2305843009213693952) = 0
    913 ceiling(4611686018427387904, 4611686018427387904) = 4611686018427387904, ceiling(4611686018427387906, 4611686018427387904) = -4611686018427387904, ceiling(-4611686018427387906, 4611686018427387904) = 0
    914 ceiling(-9223372036854775808, -9223372036854775808) = -9223372036854775808, ceiling(-9223372036854775806, -9223372036854775808) = 0, ceiling(9223372036854775806, -9223372036854775808) = 0
     853ceiling(4, 4) = 4, ceiling(6, 4) = 8, ceiling(-6, 4) = -4
     854ceiling(8, 8) = 8, ceiling(10, 8) = 16, ceiling(-10, 8) = -8
     855ceiling(16, 16) = 16, ceiling(18, 16) = 32, ceiling(-18, 16) = -16
     856ceiling(32, 32) = 32, ceiling(34, 32) = 64, ceiling(-34, 32) = -32
     857ceiling(64, 64) = 64, ceiling(66, 64) = 128, ceiling(-66, 64) = -64
     858ceiling(128, 128) = 128, ceiling(130, 128) = 256, ceiling(-130, 128) = -128
     859ceiling(256, 256) = 256, ceiling(258, 256) = 512, ceiling(-258, 256) = -256
     860ceiling(512, 512) = 512, ceiling(514, 512) = 1024, ceiling(-514, 512) = -512
     861ceiling(1024, 1024) = 1024, ceiling(1026, 1024) = 2048, ceiling(-1026, 1024) = -1024
     862ceiling(2048, 2048) = 2048, ceiling(2050, 2048) = 4096, ceiling(-2050, 2048) = -2048
     863ceiling(4096, 4096) = 4096, ceiling(4098, 4096) = 8192, ceiling(-4098, 4096) = -4096
     864ceiling(8192, 8192) = 8192, ceiling(8194, 8192) = 16384, ceiling(-8194, 8192) = -8192
     865ceiling(16384, 16384) = 16384, ceiling(16386, 16384) = 32768, ceiling(-16386, 16384) = -16384
     866ceiling(32768, 32768) = 32768, ceiling(32770, 32768) = 65536, ceiling(-32770, 32768) = -32768
     867ceiling(65536, 65536) = 65536, ceiling(65538, 65536) = 131072, ceiling(-65538, 65536) = -65536
     868ceiling(131072, 131072) = 131072, ceiling(131074, 131072) = 262144, ceiling(-131074, 131072) = -131072
     869ceiling(262144, 262144) = 262144, ceiling(262146, 262144) = 524288, ceiling(-262146, 262144) = -262144
     870ceiling(524288, 524288) = 524288, ceiling(524290, 524288) = 1048576, ceiling(-524290, 524288) = -524288
     871ceiling(1048576, 1048576) = 1048576, ceiling(1048578, 1048576) = 2097152, ceiling(-1048578, 1048576) = -1048576
     872ceiling(2097152, 2097152) = 2097152, ceiling(2097154, 2097152) = 4194304, ceiling(-2097154, 2097152) = -2097152
     873ceiling(4194304, 4194304) = 4194304, ceiling(4194306, 4194304) = 8388608, ceiling(-4194306, 4194304) = -4194304
     874ceiling(8388608, 8388608) = 8388608, ceiling(8388610, 8388608) = 16777216, ceiling(-8388610, 8388608) = -8388608
     875ceiling(16777216, 16777216) = 16777216, ceiling(16777218, 16777216) = 33554432, ceiling(-16777218, 16777216) = -16777216
     876ceiling(33554432, 33554432) = 33554432, ceiling(33554434, 33554432) = 67108864, ceiling(-33554434, 33554432) = -33554432
     877ceiling(67108864, 67108864) = 67108864, ceiling(67108866, 67108864) = 134217728, ceiling(-67108866, 67108864) = -67108864
     878ceiling(134217728, 134217728) = 134217728, ceiling(134217730, 134217728) = 268435456, ceiling(-134217730, 134217728) = -134217728
     879ceiling(268435456, 268435456) = 268435456, ceiling(268435458, 268435456) = 536870912, ceiling(-268435458, 268435456) = -268435456
     880ceiling(536870912, 536870912) = 536870912, ceiling(536870914, 536870912) = 1073741824, ceiling(-536870914, 536870912) = -536870912
     881ceiling(1073741824, 1073741824) = 1073741824, ceiling(1073741826, 1073741824) = 2147483648, ceiling(-1073741826, 1073741824) = -1073741824
     882ceiling(2147483648, 2147483648) = 2147483648, ceiling(2147483650, 2147483648) = 4294967296, ceiling(-2147483650, 2147483648) = -2147483648
     883ceiling(4294967296, 4294967296) = 4294967296, ceiling(4294967298, 4294967296) = 8589934592, ceiling(-4294967298, 4294967296) = -4294967296
     884ceiling(8589934592, 8589934592) = 8589934592, ceiling(8589934594, 8589934592) = 17179869184, ceiling(-8589934594, 8589934592) = -8589934592
     885ceiling(17179869184, 17179869184) = 17179869184, ceiling(17179869186, 17179869184) = 34359738368, ceiling(-17179869186, 17179869184) = -17179869184
     886ceiling(34359738368, 34359738368) = 34359738368, ceiling(34359738370, 34359738368) = 68719476736, ceiling(-34359738370, 34359738368) = -34359738368
     887ceiling(68719476736, 68719476736) = 68719476736, ceiling(68719476738, 68719476736) = 137438953472, ceiling(-68719476738, 68719476736) = -68719476736
     888ceiling(137438953472, 137438953472) = 137438953472, ceiling(137438953474, 137438953472) = 274877906944, ceiling(-137438953474, 137438953472) = -137438953472
     889ceiling(274877906944, 274877906944) = 274877906944, ceiling(274877906946, 274877906944) = 549755813888, ceiling(-274877906946, 274877906944) = -274877906944
     890ceiling(549755813888, 549755813888) = 549755813888, ceiling(549755813890, 549755813888) = 1099511627776, ceiling(-549755813890, 549755813888) = -549755813888
     891ceiling(1099511627776, 1099511627776) = 1099511627776, ceiling(1099511627778, 1099511627776) = 2199023255552, ceiling(-1099511627778, 1099511627776) = -1099511627776
     892ceiling(2199023255552, 2199023255552) = 2199023255552, ceiling(2199023255554, 2199023255552) = 4398046511104, ceiling(-2199023255554, 2199023255552) = -2199023255552
     893ceiling(4398046511104, 4398046511104) = 4398046511104, ceiling(4398046511106, 4398046511104) = 8796093022208, ceiling(-4398046511106, 4398046511104) = -4398046511104
     894ceiling(8796093022208, 8796093022208) = 8796093022208, ceiling(8796093022210, 8796093022208) = 17592186044416, ceiling(-8796093022210, 8796093022208) = -8796093022208
     895ceiling(17592186044416, 17592186044416) = 17592186044416, ceiling(17592186044418, 17592186044416) = 35184372088832, ceiling(-17592186044418, 17592186044416) = -17592186044416
     896ceiling(35184372088832, 35184372088832) = 35184372088832, ceiling(35184372088834, 35184372088832) = 70368744177664, ceiling(-35184372088834, 35184372088832) = -35184372088832
     897ceiling(70368744177664, 70368744177664) = 70368744177664, ceiling(70368744177666, 70368744177664) = 140737488355328, ceiling(-70368744177666, 70368744177664) = -70368744177664
     898ceiling(140737488355328, 140737488355328) = 140737488355328, ceiling(140737488355330, 140737488355328) = 281474976710656, ceiling(-140737488355330, 140737488355328) = -140737488355328
     899ceiling(281474976710656, 281474976710656) = 281474976710656, ceiling(281474976710658, 281474976710656) = 562949953421312, ceiling(-281474976710658, 281474976710656) = -281474976710656
     900ceiling(562949953421312, 562949953421312) = 562949953421312, ceiling(562949953421314, 562949953421312) = 1125899906842624, ceiling(-562949953421314, 562949953421312) = -562949953421312
     901ceiling(1125899906842624, 1125899906842624) = 1125899906842624, ceiling(1125899906842626, 1125899906842624) = 2251799813685248, ceiling(-1125899906842626, 1125899906842624) = -1125899906842624
     902ceiling(2251799813685248, 2251799813685248) = 2251799813685248, ceiling(2251799813685250, 2251799813685248) = 4503599627370496, ceiling(-2251799813685250, 2251799813685248) = -2251799813685248
     903ceiling(4503599627370496, 4503599627370496) = 4503599627370496, ceiling(4503599627370498, 4503599627370496) = 9007199254740992, ceiling(-4503599627370498, 4503599627370496) = -4503599627370496
     904ceiling(9007199254740992, 9007199254740992) = 9007199254740992, ceiling(9007199254740994, 9007199254740992) = 18014398509481984, ceiling(-9007199254740994, 9007199254740992) = -9007199254740992
     905ceiling(18014398509481984, 18014398509481984) = 18014398509481984, ceiling(18014398509481986, 18014398509481984) = 36028797018963968, ceiling(-18014398509481986, 18014398509481984) = -18014398509481984
     906ceiling(36028797018963968, 36028797018963968) = 36028797018963968, ceiling(36028797018963970, 36028797018963968) = 72057594037927936, ceiling(-36028797018963970, 36028797018963968) = -36028797018963968
     907ceiling(72057594037927936, 72057594037927936) = 72057594037927936, ceiling(72057594037927938, 72057594037927936) = 144115188075855872, ceiling(-72057594037927938, 72057594037927936) = -72057594037927936
     908ceiling(144115188075855872, 144115188075855872) = 144115188075855872, ceiling(144115188075855874, 144115188075855872) = 288230376151711744, ceiling(-144115188075855874, 144115188075855872) = -144115188075855872
     909ceiling(288230376151711744, 288230376151711744) = 288230376151711744, ceiling(288230376151711746, 288230376151711744) = 576460752303423488, ceiling(-288230376151711746, 288230376151711744) = -288230376151711744
     910ceiling(576460752303423488, 576460752303423488) = 576460752303423488, ceiling(576460752303423490, 576460752303423488) = 1152921504606846976, ceiling(-576460752303423490, 576460752303423488) = -576460752303423488
     911ceiling(1152921504606846976, 1152921504606846976) = 1152921504606846976, ceiling(1152921504606846978, 1152921504606846976) = 2305843009213693952, ceiling(-1152921504606846978, 1152921504606846976) = -1152921504606846976
     912ceiling(2305843009213693952, 2305843009213693952) = 2305843009213693952, ceiling(2305843009213693954, 2305843009213693952) = 4611686018427387904, ceiling(-2305843009213693954, 2305843009213693952) = -2305843009213693952
     913ceiling(4611686018427387904, 4611686018427387904) = 4611686018427387904, ceiling(4611686018427387906, 4611686018427387904) = -9223372036854775808, ceiling(-4611686018427387906, 4611686018427387904) = -4611686018427387904
     914ceiling(-9223372036854775808, -9223372036854775808) = -9223372036854775808, ceiling(-9223372036854775806, -9223372036854775808) = 0, ceiling(9223372036854775806, -9223372036854775808) = -9223372036854775808
    915915
    916916unsigned long long int
  • tests/.in/copyfile.txt

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Fri Jun 19 13:44:05 2020
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun 19 17:58:03 2020
    13 // Update Count     : 4
     12// Last Modified On : Mon Jun  5 21:20:07 2023
     13// Update Count     : 5
    1414//
    1515
     
    3030                        exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]";
    3131                } // choose
    32         } catch( Open_Failure * ex ; ex->istream == &in ) {
     32        } catch( open_failure * ex ; ex->istream == &in ) {
    3333                exit | "Unable to open input file" | argv[1];
    34         } catch( Open_Failure * ex ; ex->ostream == &out ) {
     34        } catch( open_failure * ex ; ex->ostream == &out ) {
    3535                close( in );                                                                    // optional
    3636                exit | "Unable to open output file" | argv[2];
  • tests/Makefile.am

    rfa5e1aa5 rb7b3e41  
    111111# '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
    112112all-local : # This name is important to automake and implies the default build target.
    113         @+${TEST_PY} --debug=${debug} --install=${installed} --invariant ${ARCHIVE_ERRORS} ${TIMEOUT} ${GLOBAL_TIMEOUT} ${ARCH} --all
     113        @+${TEST_PY} --debug=${debug} --install=${installed} ${ARCHIVE_ERRORS} ${TIMEOUT} ${GLOBAL_TIMEOUT} ${ARCH} --all
    114114
    115115tests : all-local # synonym
  • tests/collections/vector-demo.cfa

    rfa5e1aa5 rb7b3e41  
    143143    assert( v`capacity >  5 && v`length == 5 );
    144144
    145     v[2] = -0.1;  // v is [0.0, 98.6, -0.1, 0.2, 0.3]; iter at -0.1, where only the new memory had that change
     145    v[2] = -0.1f;  // v is [0.0, 98.6, -0.1, 0.2, 0.3]; iter at -0.1, where only the new memory had that change
    146146
    147147    float val3 = iter`val;
  • tests/concurrency/actors/.expect/inherit.txt

    rfa5e1aa5 rb7b3e41  
    44A
    55A
     6A
     7A
    68Finished
  • tests/concurrency/actors/dynamic.cfa

    rfa5e1aa5 rb7b3e41  
    1919void ?{}( derived_msg & this ) { ((derived_msg &)this){ 0 }; }
    2020
    21 Allocation receive( derived_actor & receiver, derived_msg & msg ) {
     21allocation receive( derived_actor & receiver, derived_msg & msg ) {
    2222    if ( msg.cnt >= Times ) {
    2323        sout | "Done";
     
    2828    derived_actor * d_actor = alloc();
    2929    (*d_actor){};
    30     *d_actor << *d_msg;
     30    *d_actor | *d_msg;
    3131    return Delete;
    3232}
     
    5858    derived_actor * d_actor = alloc();
    5959    (*d_actor){};
    60     *d_actor << *d_msg;
     60    *d_actor | *d_msg;
    6161
    6262    printf("stopping\n");
  • tests/concurrency/actors/executor.cfa

    rfa5e1aa5 rb7b3e41  
    2424struct d_msg { inline message; } shared_msg;
    2525
    26 Allocation receive( d_actor & this, d_msg & msg ) with( this ) {
     26allocation receive( d_actor & this, d_msg & msg ) with( this ) {
    2727    if ( recs == rounds ) return Finished;
    2828    if ( recs % Batch == 0 ) {
    2929        for ( i; Batch ) {
    30             gstart[sends % Set] << shared_msg;
     30            gstart[sends % Set] | shared_msg;
    3131            sends += 1;
    3232        }
     
    9494
    9595        for ( i; Actors ) {
    96                 actors[i] << shared_msg;
     96                actors[i] | shared_msg;
    9797        } // for
    9898
  • tests/concurrency/actors/inherit.cfa

    rfa5e1aa5 rb7b3e41  
    77
    88struct Server { inline actor; };
     9
    910struct Server2 { inline Server; int b; };
     11void ^?{}( Server2 & this ) { mutex(sout) sout | 'A'; }
     12
    1013struct D_msg { int a; inline message; };
    11 struct D_msg2 { inline D_msg; };
    12 
    13 void ^?{}( Server2 & this ) { mutex(sout) sout | 'A'; }
    1414void ?{}( D_msg & this ) { set_allocation( this, Delete ); }
    1515void ^?{}( D_msg & this ) { mutex(sout) sout | 'A'; }
    1616
    17 Allocation handle() {
     17struct D_msg2 { inline D_msg; };
     18
     19allocation handle() {
    1820    return Finished;
    1921}
    2022
    21 Allocation receive( Server & receiver, D_msg & msg ) { return handle(); }
    22 Allocation receive( Server & receiver, D_msg2 & msg ) { return handle(); }
    23 Allocation receive( Server2 & receiver, D_msg & msg ) { return Delete; }
    24 Allocation receive( Server2 & receiver, D_msg2 & msg ) { return Delete; }
     23allocation receive( Server & receiver, D_msg & msg ) { return handle(); }
     24allocation receive( Server & receiver, D_msg2 & msg ) { return handle(); }
     25allocation receive( Server2 & receiver, D_msg & msg ) { return Delete; }
     26allocation receive( Server2 & receiver, D_msg2 & msg ) { return Delete; }
    2527
    2628int main() {
     
    3032        D_msg * dm = alloc();
    3133        (*dm){};
    32         D_msg2 dm2;
     34        D_msg2 * dm2 = alloc();
     35        (*dm2){};
    3336        Server2 * s = alloc();
    3437        (*s){};
    3538        Server2 * s2 = alloc();
    3639        (*s2){};
    37         *s << *dm;
    38         *s2 << dm2;
     40        *s | *dm;
     41        *s2 | *dm2;
    3942        stop_actor_system();
    4043    }
     
    4447        D_msg * dm = alloc();
    4548        (*dm){};
    46         D_msg2 dm2;
    47         s[0] << *dm;
    48         s[1] << dm2;
     49        D_msg2 * dm2 = alloc();
     50        (*dm2){};
     51        s[0] | *dm;
     52        s[1] | *dm2;
    4953        stop_actor_system();
    5054    }
  • tests/concurrency/actors/matrix.cfa

    rfa5e1aa5 rb7b3e41  
    2424}
    2525
    26 Allocation receive( derived_actor & receiver, derived_msg & msg ) {
     26allocation receive( derived_actor & receiver, derived_msg & msg ) {
    2727    for ( unsigned int i = 0; i < yc; i += 1 ) { // multiply X_row by Y_col and sum products
    2828        msg.Z[i] = 0;
     
    105105
    106106        for ( unsigned int r = 0; r < xr; r += 1 ) {
    107                 actors[r] << messages[r];
     107                actors[r] | messages[r];
    108108        } // for
    109109
  • tests/concurrency/actors/pingpong.cfa

    rfa5e1aa5 rb7b3e41  
    1919size_t times = 100000;
    2020
    21 Allocation receive( ping & receiver, p_msg & msg ) {
     21allocation receive( ping & receiver, p_msg & msg ) {
    2222    msg.count++;
    2323    if ( msg.count > times ) return Finished;
    2424
    25     Allocation retval = Nodelete;
     25    allocation retval = Nodelete;
    2626    if ( msg.count == times ) retval = Finished;
    27     *po << msg;
     27    *po | msg;
    2828    return retval;
    2929}
    3030
    31 Allocation receive( pong & receiver, p_msg & msg ) {
     31allocation receive( pong & receiver, p_msg & msg ) {
    3232    msg.count++;
    3333    if ( msg.count > times ) return Finished;
    3434   
    35     Allocation retval = Nodelete;
     35    allocation retval = Nodelete;
    3636    if ( msg.count == times ) retval = Finished;
    37     *pi << msg;
     37    *pi | msg;
    3838    return retval;
    3939}
     
    5353    pi = &pi_actor;
    5454    p_msg m;
    55     pi_actor << m;
     55    pi_actor | m;
    5656    stop_actor_system();
    5757
  • tests/concurrency/actors/poison.cfa

    rfa5e1aa5 rb7b3e41  
    1818        Server s[10];
    1919        for ( i; 10 ) {
    20             s[i] << FinishedMsg;
     20            s[i] | finished_msg;
    2121        }
    2222        stop_actor_system();
     
    2929            Server * s = alloc();
    3030            (*s){};
    31             (*s) << DeleteMsg;
     31            (*s) | delete_msg;
    3232        }
    3333        stop_actor_system();
     
    3939        Server s[10];
    4040        for ( i; 10 )
    41             s[i] << DestroyMsg;
     41            s[i] | destroy_msg;
    4242        stop_actor_system();
    4343        for ( i; 10 )
  • tests/concurrency/actors/static.cfa

    rfa5e1aa5 rb7b3e41  
    1919void ?{}( derived_msg & this ) { ((derived_msg &)this){ 0 }; }
    2020
    21 Allocation receive( derived_actor & receiver, derived_msg & msg ) {
     21allocation receive( derived_actor & receiver, derived_msg & msg ) {
    2222    if ( msg.cnt >= Times ) {
    2323        sout | "Done";
     
    2525    }
    2626    msg.cnt++;
    27     receiver << msg;
     27    receiver | msg;
    2828    return Nodelete;
    2929}
     
    5555    derived_actor actor;
    5656
    57     actor << msg;
     57    actor | msg;
    5858
    5959    printf("stopping\n");
  • tests/concurrency/actors/types.cfa

    rfa5e1aa5 rb7b3e41  
    2020
    2121// this isn't a valid receive routine since int is not a message type
    22 Allocation receive( derived_actor & receiver, int i ) with( receiver ) {
     22allocation receive( derived_actor & receiver, int i ) with( receiver ) {
    2323    mutex(sout) sout | i;
    2424    counter++;
     
    2727}
    2828
    29 Allocation receive( derived_actor & receiver, d_msg & msg ) {
     29allocation receive( derived_actor & receiver, d_msg & msg ) {
    3030    return receive( receiver, msg.num );
    3131}
     
    3636};
    3737
    38 Allocation receive( derived_actor2 & receiver, d_msg & msg ) {
     38allocation receive( derived_actor2 & receiver, d_msg & msg ) {
    3939    mutex(sout) sout | msg.num;
    4040    return Finished;
     
    4848};
    4949
    50 Allocation receive( derived_actor3 & receiver, d_msg & msg ) {
     50allocation receive( derived_actor3 & receiver, d_msg & msg ) {
    5151    mutex(sout) sout | msg.num;
    5252    if ( msg.num == -1 ) return Nodelete;
     
    5454}
    5555
    56 Allocation receive( derived_actor3 & receiver, d_msg2 & msg ) {
     56allocation receive( derived_actor3 & receiver, d_msg2 & msg ) {
    5757    mutex(sout) sout | msg.num;
    5858    return Finished;
     
    7272    b.num = 1;
    7373    c.num = 2;
    74     a << b << c;
     74    a | b | c;
    7575    stop_actor_system();
    7676
     
    8080    d_msg d_ac2_msg;
    8181    d_ac2_msg.num = 3;
    82     d_ac2_0 << d_ac2_msg;
    83     d_ac2_1 << d_ac2_msg;
     82    d_ac2_0 | d_ac2_msg;
     83    d_ac2_1 | d_ac2_msg;
    8484    stop_actor_system();
    8585
     
    9393        d_msg d_ac23_msg;
    9494        d_ac23_msg.num = 4;
    95         d_ac3_0 << d_ac23_msg;
    96         d_ac2_2 << d_ac23_msg;
     95        d_ac3_0 | d_ac23_msg;
     96        d_ac2_2 | d_ac23_msg;
    9797        stop_actor_system();
    9898    } // RAII to clean up executor
     
    107107        b1.num = -1;
    108108        c2.num = 5;
    109         a3 << b1 << c2;
     109        a3 | b1 | c2;
    110110        stop_actor_system();
    111111    } // RAII to clean up executor
     
    120120        b1.num = -1;
    121121        c2.num = 5;
    122         a4 << b1 << c2;
     122        a4 | b1 | c2;
    123123        stop_actor_system();
    124124    } // RAII to clean up executor
  • tests/concurrency/lockfree_stack.cfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Thu May 25 15:36:50 2023
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 30 19:02:32 2023
    13 // Update Count     : 18
     12// Last Modified On : Fri Jun  9 14:01:07 2023
     13// Update Count     : 68
    1414//
    1515
     
    2929        int64_t atom;
    3030        #endif // __SIZEOF_INT128__
    31 } __attribute__(( aligned( 16 ) ));
     31};
    3232
    3333struct Node {
     
    4242        n.next = stack;                                                                         // atomic assignment unnecessary
    4343        for () {                                                                                        // busy wait
    44                 if ( CASV( stack.atom, n.next.atom, ((Link){ &n, n.next.count + 1 }.atom) ) ) break; // attempt to update top node
     44                Link temp{ &n, n.next.count + 1 };
     45                if ( CASV( s.stack.atom, n.next.atom, temp.atom ) ) break; // attempt to update top node
    4546        }
    4647}
     
    5051        for () {                                                                                        // busy wait
    5152                if ( t.top == NULL ) return NULL;                               // empty stack ?
    52                 if ( CASV( stack.atom, t.atom, ((Link){ t.top->next.top, t.count }.atom) ) ) return t.top; // attempt to update top node
     53                Link temp{ t.top->next.top, t.count };
     54                if ( CASV( stack.atom, t.atom, temp.atom ) ) return t.top; // attempt to update top node
    5355        }
    5456}
     
    5759Stack stack;                                                                                    // global stack
    5860
    59 enum { Times =
    60         #if defined( __ARM_ARCH )                                                       // ARM CASV is very slow
    61         10_000
    62         #else
    63         1_000_000
    64         #endif // __arm_64__
    65 };
     61enum { Times = 2_000_000 };
    6662
    6763thread Worker {};
     
    8278
    8379        for ( i; N ) {                                                                          // push N values on stack
    84                 // storage must be 16-bytes aligned for cmpxchg16b
    85                 push( stack, *(Node *)memalign( 16, sizeof( Node ) ) );
     80                push( stack, *(Node *)new() );                                  // must be 16-byte aligned
    8681        }
    8782        {
  • tests/concurrency/waituntil/locks.cfa

    rfa5e1aa5 rb7b3e41  
    22#include <thread.hfa>
    33#include <locks.hfa>
     4#include <fstream.hfa>
    45#include <mutex_stmt.hfa>
    56
  • tests/configs/.expect/parseconfig.txt

    rfa5e1aa5 rb7b3e41  
    1212Maximum student trips: 3
    1313
    14 Open_Failure thrown when config file does not exist
     14open_failure thrown when config file does not exist
    1515Failed to open the config file
    1616
  • tests/configs/parseconfig.cfa

    rfa5e1aa5 rb7b3e41  
    6666
    6767
    68         sout | "Open_Failure thrown when config file does not exist";
     68        sout | "open_failure thrown when config file does not exist";
    6969        try {
    7070                parse_config( xstr(IN_DIR) "doesnt-exist.txt", entries, NUM_ENTRIES, parse_tabular_config_format );
    71         } catch( Open_Failure * ex ) {
     71        } catch( open_failure * ex ) {
    7272                sout | "Failed to open the config file";
    7373        }
  • tests/copyfile.cfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Fri Jun 19 13:44:05 2020
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 15 15:00:48 2020
    13 // Update Count     : 6
     12// Last Modified On : Mon Jun  5 21:20:19 2023
     13// Update Count     : 7
    1414//
    1515
     
    3030                        exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]";
    3131                } // choose
    32         } catch( Open_Failure * ex ; ex->istream == &in ) {
     32        } catch( open_failure * ex ; ex->istream == &in ) {
    3333                exit | "Unable to open input file" | argv[1];
    34         } catch( Open_Failure * ex ; ex->ostream == &out ) {
     34        } catch( open_failure * ex ; ex->ostream == &out ) {
    3535                close( in );                                                                    // optional
    3636                exit | "Unable to open output file" | argv[2];
  • tests/coroutine/devicedriver.cfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Sat Mar 16 15:30:34 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 20 09:07:19 2019
    13 // Update Count     : 90
     12// Last Modified On : Sat Jun 17 09:11:56 2023
     13// Update Count     : 94
    1414//
    1515
     
    1818
    1919enum Status { CONT, MSG, ESTX, ELNTH, ECRC };
     20
    2021coroutine Driver {
    2122        Status status;
     
    2324}; // Driver
    2425
    25 void ?{}( Driver & d, char * m ) { d.msg = m; }
    26 Status next( Driver & d, char b ) with( d ) {
    27         byte = b; resume( d ); return status;
     26void ?{}( Driver & d, char * m ) { d.msg = m; }                 // constructor
     27
     28Status next( Driver & d, char b ) with( d ) {                   // called by interrupt handler
     29        byte = b; resume( d ); return status;                           // resume coroutine at last suspend
    2830} // next
    2931
     
    7375          if ( eof( sin ) ) break eof;                                          // eof ?
    7476                choose( next( driver, byte ) ) {                                // analyse character
    75                   case MSG:
    76                         sout | "msg:" | msg;
    77                   case ESTX:
    78                         sout | "STX in message";
    79                   case ELNTH:
    80                         sout | "message too long";
    81                   case ECRC:
    82                         sout | "CRC failure";
    83                   default: ;
     77                  case CONT: ;
     78                  case MSG: sout | "msg:" | msg;
     79                  case ESTX: sout | "STX in message";
     80                  case ELNTH: sout | "message too long";
     81                  case ECRC: sout | "CRC failure";
    8482                } // choose
    8583        } // for
     
    8785
    8886// Local Variables: //
    89 // tab-width: 4 //
    9087// compile-command: "cfa -g -Wall -Wextra devicedriver.cfa" //
    9188// End: //
  • tests/io/manipulatorsInput.cfa

    rfa5e1aa5 rb7b3e41  
    77// Created On       : Sat Jun  8 17:58:54 2019
    88// Last Modified By : Peter A. Buhr
    9 // Last Modified On : Wed Jul 15 15:56:03 2020
    10 // Update Count     : 47
     9// Last Modified On : Sat Jun 17 07:56:02 2023
     10// Update Count     : 48
    1111//
    1212
     
    152152                sin | ignore( wdi( 8, ldc ) );                  sout | ldc;
    153153        }
    154 #if defined( __SIZEOF_INT128__ )
     154        #if defined( __SIZEOF_INT128__ )
    155155        {
    156156                int128 val;
     
    160160                }
    161161        }
    162 #endif // __SIZEOF_INT128__
     162        #endif // __SIZEOF_INT128__
    163163} // main
    164164
  • tests/pybin/settings.py

    rfa5e1aa5 rb7b3e41  
    141141        all_install  = [Install(o)      for o in list(dict.fromkeys(options.install))]
    142142        archive      = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None
    143         invariant    = options.invariant
     143        invariant    = options.no_invariant
    144144        continue_    = options.continue_
    145145        dry_run      = options.dry_run # must be called before tools.config_hash()
  • tests/rational.cfa

    rfa5e1aa5 rb7b3e41  
    1010// Created On       : Mon Mar 28 08:43:12 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 20 18:13:40 2021
    13 // Update Count     : 107
     12// Last Modified On : Mon Jun  5 22:58:09 2023
     13// Update Count     : 108
    1414//
    1515
     
    1919#include <fstream.hfa>
    2020
    21 typedef Rational(int) RatInt;
     21typedef rational(int) rat_int;
    2222double convert( int i ) { return (double)i; }                   // used by narrow/widen
    2323int convert( double d ) { return (int)d; }
     
    2525int main() {
    2626        sout | "constructor";
    27         RatInt a = { 3 }, b = { 4 }, c, d = 0, e = 1;
     27        rat_int a = { 3 }, b = { 4 }, c, d = 0, e = 1;
    2828        sout | "a : " | a | "b : " | b | "c : " | c | "d : " | d | "e : " | e;
    2929
    30         a = (RatInt){ 4, 8 };
    31         b = (RatInt){ 5, 7 };
     30        a = (rat_int){ 4, 8 };
     31        b = (rat_int){ 5, 7 };
    3232        sout | "a : " | a | "b : " | b;
    33         a = (RatInt){ -2, -3 };
    34         b = (RatInt){ 3, -2 };
     33        a = (rat_int){ -2, -3 };
     34        b = (rat_int){ 3, -2 };
    3535        sout | "a : " | a | "b : " | b;
    36         a = (RatInt){ -2, 3 };
    37         b = (RatInt){ 3, 2 };
     36        a = (rat_int){ -2, 3 };
     37        b = (rat_int){ 3, 2 };
    3838        sout | "a : " | a | "b : " | b;
    3939        sout | nl;
    4040
    4141        sout | "comparison";
    42         a = (RatInt){ -2 };
    43         b = (RatInt){ -3, 2 };
     42        a = (rat_int){ -2 };
     43        b = (rat_int){ -3, 2 };
    4444        sout | "a : " | a | "b : " | b;
    45         sout | "a == 0 : " | a == (Rational(int)){0}; // FIX ME
    46         sout | "a == 1 : " | a == (Rational(int)){1}; // FIX ME
     45        sout | "a == 0 : " | a == (rational(int)){0}; // FIX ME
     46        sout | "a == 1 : " | a == (rational(int)){1}; // FIX ME
    4747        sout | "a != 0 : " | a != 0;
    4848        sout | "! a : " | ! a;
     
    7373
    7474        sout | "conversion";
    75         a = (RatInt){ 3, 4 };
     75        a = (rat_int){ 3, 4 };
    7676        sout | widen( a );
    77         a = (RatInt){ 1, 7 };
     77        a = (rat_int){ 1, 7 };
    7878        sout | widen( a );
    79         a = (RatInt){ 355, 113 };
     79        a = (rat_int){ 355, 113 };
    8080        sout | widen( a );
    8181        sout | narrow( 0.75, 4 );
     
    9090
    9191        sout | "more tests";
    92         RatInt x = { 1, 2 }, y = { 2 };
     92        rat_int x = { 1, 2 }, y = { 2 };
    9393        sout | x - y;
    9494        sout | x > y;
     
    9696        sout | y | denominator( y, -2 ) | y;
    9797
    98         RatInt z = { 0, 5 };
     98        rat_int z = { 0, 5 };
    9999        sout | z;
    100100
    101101        sout | x | numerator( x, 0 ) | x;
    102102
    103         x = (RatInt){ 1, MAX } + (RatInt){ 1, MAX };
     103        x = (rat_int){ 1, MAX } + (rat_int){ 1, MAX };
    104104        sout | x;
    105         x = (RatInt){ 3, MAX } + (RatInt){ 2, MAX };
     105        x = (rat_int){ 3, MAX } + (rat_int){ 2, MAX };
    106106        sout | x;
    107107
  • tests/test.py

    rfa5e1aa5 rb7b3e41  
    114114        parser.add_argument('--install', help='Run all tests based on installed binaries or tree binaries', type=comma_separated(yes_no), default='no')
    115115        parser.add_argument('--continue', help='When multiple specifications are passed (debug/install/arch), sets whether or not to continue if the last specification failed', type=yes_no, default='yes', dest='continue_')
    116         parser.add_argument('--invariant', help='Tell the compiler to check invariants while running.', action='store_true')
     116        parser.add_argument('--invariant', help='Tell the compiler to check invariants.', action='store_true')
     117        parser.add_argument('--no-invariant', help='Tell the compiler not to check invariant.', action='store_false')
    117118        parser.add_argument('--timeout', help='Maximum duration in seconds after a single test is considered to have timed out', type=int, default=180)
    118119        parser.add_argument('--global-timeout', help='Maximum cumulative duration in seconds after the ALL tests are considered to have timed out', type=int, default=7200)
Note: See TracChangeset for help on using the changeset viewer.