Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3040_VectorBasedGP/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/NativeInterpreter-0.1/src/interpreter.cpp @ 17403

Last change on this file since 17403 was 16333, checked in by bburlacu, 6 years ago

#2958: Native interpreter dlls: statically link against the visual C++ runtime

File size: 1.6 KB
Line 
1#include "interpreter.h"
2
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7constexpr size_t BUFSIZE = BATCHSIZE * sizeof(double);
8
9// slow (ish?)
10__declspec(dllexport)
11double __cdecl GetValue(instruction* code, int codeLength, int row) noexcept
12{
13    return evaluate(code, codeLength, row);
14}
15
16__declspec(dllexport)
17void __cdecl GetValues(instruction* code, int codeLength, int* rows, int totalRows, double* result) noexcept
18{
19    for (int i = 0; i < totalRows; ++i)
20    {
21        result[i] = evaluate(code, codeLength, rows[i]);
22    }
23}
24
25__declspec(dllexport)
26void __cdecl GetValuesVectorized(instruction* code, int codeLength, int* rows, int totalRows, double* __restrict result) noexcept
27{
28    double* buffer = static_cast<double*>(_aligned_malloc(codeLength * BUFSIZE, 16));
29    for (int i = 0; i < codeLength; ++i)
30    {
31        instruction& in = code[i];
32        in.buf = buffer + (i * BATCHSIZE);
33
34        if (in.opcode == OpCodes::Const)
35        {
36            load(in.buf, in.value);
37        }
38    }
39
40    int remainingRows = totalRows % BATCHSIZE;
41    int total = totalRows - remainingRows;
42
43    for (int rowIndex = 0; rowIndex < total; rowIndex += BATCHSIZE)
44    {
45        evaluate(code, codeLength, rows, rowIndex, BATCHSIZE);
46        std::memcpy(result + rowIndex, code[0].buf, BUFSIZE);
47    }
48
49    // are there any rows left?
50    if (remainingRows > 0)
51    {
52        evaluate(code, codeLength, rows, total, remainingRows);
53        std::memcpy(result + total, code[0].buf, remainingRows * sizeof(double));
54    }
55    _aligned_free(buffer);
56}
57
58#ifdef __cplusplus
59}
60#endif
Note: See TracBrowser for help on using the repository browser.