Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/NativeInterpreter-0.1/src/interpreter.cpp @ 16274

Last change on this file since 16274 was 16274, checked in by bburlacu, 5 years ago

#2958: Update dll files and C++ source code to the latest version.

File size: 1.7 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        for (int rowIndex = total; rowIndex < totalRows; rowIndex += remainingRows)
53        {
54            evaluate(code, codeLength, rows, rowIndex, remainingRows);
55            std::memcpy(result + rowIndex, code[0].buf, remainingRows * sizeof(double));
56        }
57    }
58    _aligned_free(buffer);
59}
60
61#ifdef __cplusplus
62}
63#endif
Note: See TracBrowser for help on using the repository browser.