News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

DataVector

Started by Biterider, February 11, 2024, 06:49:37 PM

Previous topic - Next topic

Biterider

Hi
The DataVector and the SortedDataVector are the last elements in the Vector development.
They hold the information of all Items in a single block of memory. The difference to the specialised objects created using the TVector template is that DataVectors do not need a defined Item size at compile time. This definition is done at runtime and can be of any size. The consequence is that the internal management is a bit more time consuming  compared to the specialised objects.

The next step is to review all the code, see if there are common code paths, and perhaps adjust the object inheritance.
It would also be nice if the macro iterators could be unified.  :biggrin:

Attached are the 2 objects and my current testbed.

Regards, Biterider

HSE

Hi Biterider!

Quote from: Biterider on February 11, 2024, 06:49:37 PMthe internal management is a bit more time consuming compared to the specialised objects.

 :thumbsup: Any other size than 1, 2, 4 and 8 need additional steps.

HSE
Equations in Assembly: SmplMath

Biterider

Hi
One thing I didn't like was that in the DataVector implementation posted above, the sort method could potentially fail, while all other peer implementations are fail-safe and don't need to return a status code.

It took me some time to find alternatives. Finally I managed to rework the method with a variable size memory in the stack. I omitted the stack probe because the required memory sizes are much smaller than a page size that could trigger a page fault.

Method SortedDataVector.Sort, uses xbx xdi xsi
[font=Verdana, Arial, Helvetica, sans-serif]  SetObject xsi[/font]
  if TARGET_BITNESS eq 32
    sub esp, [xsi].dItemSize                            ;Probing?
  else
    mov eax, [xsi].dItemSize
    sub xsp, xax                                        ;Probing?
  endif
  mov ebx, [xsi].dCount
  xor eax, eax
  test ebx, ebx
  setnz al                                              ;If exists, skip first item
  mov [xsi].dCount, eax                                 ;Set list new initial count
  .if !ZERO?
    mov xdi, [xsi].pItems
    .while TRUE
      dec ebx
      .break .if ZERO?
      mov eax, [xsi].dItemSize
      add xdi, xax                                      ;Move to next item
      if TARGET_BITNESS eq 32
        mov ecx, esp
        invoke MemClone, ecx, edi, [esi].dItemSize      ;Store item on a temp location on the stack
        OCall esi.Insert, esp                           ;Insert it
      else
        invoke MemClone, addr [rsp + 28h], xdi, [xsi].dItemSize ;Store item on a temp location
        OCall xsi.Insert, addr [rsp + 28h]              ;Insert it
      endif
    .endw
  .endif
  if TARGET_BITNESS eq 32
    add esp, [xsi].dItemSize
  else
    mov eax, [xsi].dItemSize
    add xsp, xax
  endif
MethodEnd


Biterider

Biterider

Hi
The last step is complete!

The inheritance path has been optimised and the common ancestor is called Vector  :cool:
The macro iterators are located in the same file so that they can be shared by all descendant objects.
All previous iterators have been reduced to a single version that covers all cases.
The sorting algorithm for the DataVector object described in the previous post has been rewritten so that it is fail-safe like all other implementations.
Serialisation was also analysed and implemented.
Finally, new specific constants (IDs, Errors, etc.) have been created for vectors.

All files can be downloaded from the GitHub repo.
My last testbed is attached.

Regards, Biterider

HSE

Hi Biterider,

Quote from: Biterider on February 17, 2024, 05:47:54 PMAll files can be downloaded from the GitHub repo.

Which GiHub repo?  :biggrin:  :biggrin:

(Vector.inc must be in some other repo  :rolleyes: )

HSE
Equations in Assembly: SmplMath

Biterider

Hi HSE
I had a sync problem again. Tortoise reports that all changes have been pushed, but this is not the case.
Maybe I need to rebuild the .git directory...  :sad:

The file is now on the repo.  :biggrin:

Biterider

PS: Later... I added Vector.asm, which was really missing, and updated the descendant compilation files to reflect the change.

HSE

Hi Biterider!

I only use git, and I check uploads with git status.

Thanks, HSE.
Equations in Assembly: SmplMath