Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit f44f9c5

Browse files
rfrankeOpenModelica-Hudson
authored andcommitted
Small optimization to RefArray code generation
1 parent 1ee8c83 commit f44f9c5

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10949,20 +10949,22 @@ protected
1094910949
list<String> tmpVarIndexListNew = {};
1095010950
list<DAE.Subscript> arraySubscripts;
1095110951
list<Integer> arrayDimensions;
10952+
Boolean toColumnMajor;
1095210953
algorithm
1095310954
arraySubscripts := ComponentReference.crefLastSubs(varName);
1095410955
varName := ComponentReference.crefStripLastSubs(varName);//removeSubscripts(varName);
1095510956
if(BaseHashTable.hasKey(varName, iVarToArrayIndexMapping)) then
1095610957
((arrayDimensions,varIndices)) := BaseHashTable.get(varName, iVarToArrayIndexMapping); //varIndices are rowMajorOrder!
1095710958
arraySize := arrayLength(varIndices);
1095810959
concreteVarIndex := getUnrolledArrayIndex(arraySubscripts,arrayDimensions);
10959-
if iColumnMajor then
10960+
toColumnMajor := iColumnMajor and listLength(arrayDimensions) > 1;
10961+
if toColumnMajor then
1096010962
concreteVarIndex := convertIndexToColumnMajor(concreteVarIndex, arrayDimensions);
1096110963
end if;
1096210964
//print("SimCodeUtil.getVarIndexInfosByMapping: Found variable index for '" + ComponentReference.printComponentRefStr(iVarName) + "'. The value is " + intString(concreteVarIndex) + "\n");
1096310965
for arrayIdx in 0:(arraySize-1) loop
1096410966
idx := arraySize-arrayIdx;
10965-
if iColumnMajor then
10967+
if toColumnMajor then
1096610968
// convert to row major so that column major access will give this idx
1096710969
idx := convertIndexToRowMajor(idx, arrayDimensions);
1096810970
end if;
@@ -10978,7 +10980,7 @@ algorithm
1097810980
end if;
1097910981
end if;
1098010982
end for;
10981-
if isVarIndexListConsecutive(iVarToArrayIndexMapping,iVarName) and iColumnMajor then
10983+
if isVarIndexListConsecutive(iVarToArrayIndexMapping,iVarName) and toColumnMajor then
1098210984
//if the array is not completely stuffed (e.g. some array variables have been derived and became dummy-derivatives), the array will not be initialized as a consecutive array, therefore we cannot take the colMajor-indexes
1098310985
// otherwise convert to column major for consecutive array
1098410986
concreteVarIndex := convertIndexToColumnMajor(concreteVarIndex, arrayDimensions);
@@ -11017,22 +11019,8 @@ protected function convertIndexToRowMajor
1101711019
input Integer idx; // one based, row-major ordered
1101811020
input list<Integer> arrayDimensions;
1101911021
output Integer idxOut; // one based, column-major ordered
11020-
protected
11021-
Integer idx0, ndim, length, dimj, idxj, fac;
1102211022
algorithm
11023-
ndim := listLength(arrayDimensions);
11024-
length := List.fold(arrayDimensions, intMul, 1);
11025-
idx0 := idx - 1; // zero based
11026-
idxOut := 1; // one based
11027-
fac := 1;
11028-
for i in 1:listLength(arrayDimensions) loop
11029-
dimj := listGet(arrayDimensions, ndim - i + 1);
11030-
length := intDiv(length, dimj);
11031-
idxj := intDiv(idx0, length);
11032-
idx0 := idx0 - idxj*length;
11033-
idxOut := idxOut + idxj*fac;
11034-
fac := fac * dimj;
11035-
end for;
11023+
idxOut := convertIndexToColumnMajor(idx, listReverse(arrayDimensions));
1103611024
end convertIndexToRowMajor;
1103711025

1103811026
protected function convertIndexToColumnMajor

0 commit comments

Comments
 (0)