Opened 4 years ago

Last modified 4 years ago

#6220 new defect

Small array optimizations: stack allocation — at Version 1

Reported by: mahge930 Owned by: mahge930
Priority: normal Milestone: NeedsInput
Component: Run-time Version:
Keywords: Cc: casella, sjoelund.se, adrpo, AnHeuermann

Description (last modified by mahge930)

Arrays of OpenModelica runtime are defined as the following struct

struct {
  int ndims;
  _index_t *dim_size;
  void* data;
  m_boolean flexible;
};

Here is a very basic "small static" array of 1 dimension that can be a starting point for implementation.

SMALL_ARRAY_1(name, type, dim1) \
      struct { \
        int ndims; \
        _index_t *dim_size; \
        void* data; \
        m_boolean flexible; \
        _index_t dim_size_d[1]; \
        type data_d[dim1]; \
      } name = {1, arr1.dim_size_d, arr1.data_d, 0, {dim1}, {0}};

It can be used as

SMALL_ARRAY_1(arr1, modelica_real, 3);

to declare an arr1 array of modelica_real with 1 dimension of size 3.

This matches the expected interface for normal (non-static) arrays while keeping its data on stack. That is, it can be passed to functions that we already use for the normal arrays. Of course there are warning about incompatibility of passed pointers and so on. For example this can be passed to "getter" functions as

real_array_get(arr1, 1, _i) = 1;

We need to figure out a way to safely copy these and normal arrays between each other (if that turns out to be needed).

There are many things that can go wrong with this. We will find out.

If you have suggestions, ideas, tricks, concerns ... please let me know :). We want to implement this with as small change as possible to code generation and Modelica compilation.

Change History (1)

comment:1 Changed 4 years ago by mahge930

  • Description modified (diff)
Note: See TracTickets for help on using tickets.