# Design¶

## Requirements¶

### Error Handling¶

• Provide a way to register error types.

• Provide a method for error handlers to be put on a thread’s context stack.

• Then, when an error happens, the error handler is called.

• If it succeeds, continue.

• If it doesn’t succeed, call the next handler.

• If they all don’t succeed, call a procedure given when registering the error.

• Provide macros to make restart easy?

### Runtime Type Reflection¶

This submodule is designed to allow runtime type information.

Types should include the following information:

• Size (from sizeof()). Should be a part of type data in Yvm.

• Alignment (C11). Should be a part of type data in Yvm.

• Destructor (if any).

• Copier function (if any).

• Default constructor? (Basically to create a zero version of the type.)

The public type is a pointer to the actual type info.

There should be a macro to create the type and a function to follow the Any interface requirements.

### Command-Line Option Parsing¶

• Add descriptions, including of the program itself.

• Add automatic -h and --help using descriptions.

• Take away the boilerplate of the loop.

• Add subcommands and allow recursion.

• How do I make a subcommand optional?

### SIMD¶

Users should be able to define a vector of any primitive type that is not a pointer and is a power of 2 bits size. They should also be able to define vectors of any power of 2 length.

If the length of the vector is bigger than any available on the platform, then the vector should be implemented with the next smallest vector size, recursively until actual vector operations (or primitive ops for platforms with none) are reached.

For actual vector operations, they should be implemented as macros, so that platform-specific SIMD can look the same to users.

Required operations:

• Element-wise add, subtract, multiply, divide, mod, remainder, and comparisons, floating point and integer.

• Bitwise operations, like in arith, for integer vectors.

• Floating point <-> integer (signed and unsigned) casts, if applicable.

• They are not applicable if the floating point sizes are wrong.

• The implementation of these should follow the same wrap, overflow, and abort semantics of other arithmetic operations, like in arith.

• shufflevector.

• extractelement.

• insertelement.

• Max and min.

• Reduction multiply.

• Reduction and.

• Reduction or.

• Reduction xor.

• Splice.

• Predicated addition, subtraction, multiplication, division, remainder, mod.

• Predicated logical operations.

• Predicated bitwise operations.

• Scatter and gather, as well as masked scatter and gather.

• Expanding loads and compressed stores.

## Development¶

This section consists of information that programmers need to know to work on code in this module.

### Hash¶

The hash section of the module is a direct and manual translation of SpookyHash from C++ to C. Each function in the module is labelled with the name of the function that the function was translated from, if there is such a function.

However, the rotation function Rot64() has been moved to include/yc/arith.h and renamed to y_lrot64(), and it has been made more general (for use outside of the hash submodule) to be resistant against possible Undefined Behavior.