On Sun, May 21, 2017 at 7:06 AM, John Cowan <xxxxxx@ccil.org> wrote:

On Fri, May 19, 2017 at 10:34 AM, Alex Shinn <xxxxxx@gmail.com> wrote:

Arithmetic is just (define fx+ +), which is
a builtin opcode (I think a wrapped primitive would be slower, and don't
want to add new opcodes).

I thought you might implement in C a quasi-unsafe operation that just ignores the fixnum bit(s) and ignores overflow and such problems (quasi because the result is always a fixnum, but may be the wrong fixnum).

Right.  If I don't explicitly add a new opcode, then we need a new
C primitive.  The vm dispatch is then a matter of the difference
between the existing OP_ADD:

  if (fixnump(x) && fixnump(y)) {
    /* inline fast path */
  } else {
    /* generic path */
  }

and OP_FCALL2, which dispatches on the C function.  Given
accurate branch prediction vs a dynamic and non-local function
call, it's quite possible that generic + would be faster than the
fixnum specific version.  And if not, it's probably a marginal win.

-- 
Alex