aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/vespa/eval/instruction/dense_cell_range_function.cpp
blob: 4268768605e51cbcc2b3b7c6ae752e2029113372 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "dense_cell_range_function.h"
#include <vespa/eval/eval/value.h>

namespace vespalib::eval {

using namespace tensor_function;

namespace {

template <typename CT>
void my_cell_range_op(InterpretedFunction::State &state, uint64_t param) {
    const auto &self = unwrap_param<DenseCellRangeFunction>(param);
    auto old_cells = state.peek(0).cells().typify<CT>();
    ConstArrayRef<CT> new_cells(&old_cells[self.offset()], self.length());
    state.pop_push(state.stash.create<DenseValueView>(self.result_type(), TypedCells(new_cells)));
}

struct MyCellRangeOp {
    template <typename CT>
    static auto invoke() { return my_cell_range_op<CT>; }
};

} // namespace <unnamed>

DenseCellRangeFunction::DenseCellRangeFunction(const ValueType &result_type,
                                               const TensorFunction &child,
                                               size_t offset, size_t length)
    : tensor_function::Op1(result_type, child),
      _offset(offset),
      _length(length)
{
    assert(result_type.cell_type() == child.result_type().cell_type());
}

DenseCellRangeFunction::~DenseCellRangeFunction() = default;

InterpretedFunction::Instruction
DenseCellRangeFunction::compile_self(const ValueBuilderFactory &, Stash &) const
{
    assert(result_type().cell_type() == child().result_type().cell_type());

    using MyTypify = TypifyCellType;
    auto op = typify_invoke<1,MyTypify,MyCellRangeOp>(result_type().cell_type());
    return InterpretedFunction::Instruction(op, wrap_param<DenseCellRangeFunction>(*this));
}

} // namespace