Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CInterface Demonstration of pre-made (exhaustive?) ghdl.h: A C header for all interaction between C and G/VHDL #19

Open
wants to merge 2 commits into
base: rocket-header
Choose a base branch
from

Conversation

radonnachie
Copy link

Migrated from #18

I realised that I over analysed the N Dimensional Index flattening function.

Just for a note, the idea is that an increment in a dimension's index represents indexing past all of the lower-dimension's data. This is how a 1D array can be treated as though it has multiple dimensions (by using multiple dimension-indices):

  • The lowest dimension's index does not get scaled (arr[d, r, c+1] is the value after arr[d, r, c])
  • Higher dimension's indices get scaled by the next dimension down's index (arr[d, r+1, c] is the |C|th value after arr[d, r, c])
    • This is necessarily recursive if there is more than one lower dimension (arr[d+1, r, c] is the (|R| * |C|)th value after arr[d, r, c])
  • The flat-distances between values so far have been simple on account of the dimension-index distances being 1 in only one of the dimensions. Flattening N dimension-indices will directly use the dimension-indices (eg {d,r,c}) to calculate the distance from the first value in memory (the first flat index) to the indexed value
    • arr[0, 0, c] is the ( c )th value after arr[0, 0, 0]
    • arr[0, r, 0] is the ( r * |C| )th value after arr[0, 0, 0]
    • arr[0, r, c] is the ( r * |C| + c )th value after arr[0, 0, 0]
    • arr[d, 0, 0] is the ( d * (|R| * |C|) )th value after arr[0, 0, 0]
    • arr[d, r, 0] is the ( d * (|R| * |C| + r * |C|)))th value after arr[0, 0, 0]
    • arr[d, r, c] is the ( d * (|R| * |C| + r * |C| + c) )th value after arr[0, 0, 0]
  • Differently factorising the calculations and extending should reveal the pattern:
    • arr[0, 0, 0, 0, c] is the ( c )th value
    • arr[0, 0, 0, r, c] is the ( ...(r) * |C| + c )th value
    • arr[0, 0, d, r, c] is the ( (..(d) * |R| + r) * |C| + c) )th value
    • arr[0, n, d, r, c] is the ( ((.(n) * |D| + d) * |R| + r) * |C| + c) )th value
    • arr[m, n, d, r, c] is the ( ((((m) * |N| + n) * |D| + d) * |R| + r) * |C| + c) )th value
int indx = dimIndices[0];
for (int i = 1; i < dims; i++)//Dimension-Indices listed in decreasing dimensionality (Big-Endian)
	indx = indx*dimLengths[i] + dimIndices[i];
return indx;

uhm... yeah

@radonnachie radonnachie changed the title Rocket header CInterface Demonstration of pre-made (exhaustive?) ghdl.h: A C header for all interaction between C and G/VHDL Oct 11, 2020
@radonnachie
Copy link
Author

Will happily use this pull request to further the demo in any ways we like.

I think that it maybe only the docs that need work, haven't checked.

  • Could we collapse the 2 ghdl.h files so that there is only one?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant