thautwarm / diojit

Fully compatible CPython jit compiler. Optimising Dynamic, Interpreted, and Object-oriented(DIO) programs.
BSD 2-Clause "Simplified" License
117 stars 2 forks source link

unboxing #11

Closed thautwarm closed 3 years ago

thautwarm commented 3 years ago

dynjit now robustly brings a >=2.5x speed up, while keeping CPython semantics and doing no unboxing.

The reasons against unboxing:

  1. Unboxing requires introducing new builtin types to describe int, double, char, string, etc.

    There're many one-door decisions to make:

    1. n-bit issue: Shall we support int8, int16, ..., int128 or just an unboxed int64 type? The same to float and char(unicode, ASCII).
    2. polymorphic literal issue: Should we support polymorphically infer a literal? Or we explicitly announce that a literal is a Python int? (Answer to the second question could be "Yes". Perhaps an intrinsic function, described by to_bit(i: int, n:const[int]) -> int[n], could be introduced to make users get literals for int64, int32?
  2. Unboxing requires extra implementation for those builtin types, specifically, new "shapes" should be introduced for digit-length parameteric types, such as unboxed integer and float types.

    Specializers for them are required, on the other hands, new intrinsics should be setup. An example to support for int +(int, int) is

    From this we see it's a cumbersome task.

The reasons for boxing:

  1. allow dynjit to generate code as fast as numba/julia for numeric computation programs.
  2. ??(TODO)
thautwarm commented 3 years ago
from jit.ll.unbox import to_bit
@c.aware
def f():
    c = to_bit(120, 64) 
    # c is now storing a 64 bit integer constant
    c = to_bit(2.0, 64) 
    # c is now storing a 64 bit float constant

This optimization is feasible and many might be positive to this. However, dynjit is currently a research project developed by the individual, so that, no choice but "defer".

thautwarm commented 3 years ago

So far, no. Efforts limited. Use numba for numeric computing. We can support calling numba functions in DIO-JIT compiled functions, and we can contact numba team to do the same.