This function needs `@jit.unroll_safe` as well