Ejemplo n.º 1
0
def py_modulo(restype, argtypes):
    if restype.is_float:
        def py_modulo(a, n):
            r = rem(a, n)

            if (r != 0) and (r < 0) ^ (n < 0):
                r += n

            return r

        instr = 'frem'
    else:
        assert restype.is_int

        def py_modulo(a, n):
            r = rem(a, n)

            if r != 0 and (r ^ n) < 0:
                r += n

            return r

        if restype.is_unsigned:
            instr = 'urem'
        else:
            instr = 'srem'

    rem = nb.declare_instruction(restype(restype, restype), instr)
    return nb.jit(restype(*argtypes))(py_modulo)
Ejemplo n.º 2
0
def py_modulo(restype, argtypes):
    if restype.is_float:

        def py_modulo(a, n):
            r = rem(a, n)

            if (r != 0) and (r < 0) ^ (n < 0):
                r += n

            return r

        instr = 'frem'
    else:
        assert restype.is_int

        def py_modulo(a, n):
            r = rem(a, n)

            if r != 0 and (r ^ n) < 0:
                r += n

            return r

        if restype.is_unsigned:
            instr = 'urem'
        else:
            instr = 'srem'

    rem = nb.declare_instruction(restype(restype, restype), instr)
    return nb.jit(restype(*argtypes))(py_modulo)
Ejemplo n.º 3
0
def test_intrinsics():
    intrin = declare_instruction(int32(int32, int32), 'srem')
    assert intrin(5, 3) == 2
Ejemplo n.º 4
0
def test_intrinsics():
    intrin = declare_instruction(int32(int32, int32), 'srem')
    assert intrin(5, 3) == 2