module ALU

Extended Modules

Defined in:

components/cpu/alu.cr

Constant Summary

OP_HASH = {0 => ->(a : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128, b : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128) do 0 end, 1 => ->(a : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128, b : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128) do a + b end, 2 => ->(a : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128, b : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128) do a - b end, 3 => ->(a : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128, b : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128) do a & b end, 4 => ->(a : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128, b : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128) do a | b end}

Instance Method Summary

Instance Method Detail

def run_op(a : Int, b : Int, opcode : Int) : Int #

TODO Full documentation Run an operation on two integer operands (a, b). Parameters should be the same type; a size/signedness mismatch results in undefined behavior.


[View source]
def run_op_safe(a : Int, b : Int, opcode : Int) : Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128 | Nil #

Run an operation on two integer operands (a, b). Parameter types are checked to prevent undefined behavior. Nil is returned if size/signedness has a mismatch.


[View source]