News:

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

Main Menu

Multi dimensionnal structure and word multidimensional VARARG 64 32

Started by TouEnMasm, April 18, 2021, 04:20:30 AM

Previous topic - Next topic

TouEnMasm

There is two problems in the code below,DXVA.h
DXVA_PicEntry_H264 RefPicList[2][32];            a 2 * 32 structure  (DXVA_PicEntry_H264)
SHORT  Weights[2][32][3][2]                           a short de 2*32*3*2   
How To translate this in masm.
A soluce could be to change this in :
RefPicList DXVA_PicEntry_H264 64 dup (<>)
Weights WORD 384 dup(?)
Perhaps someone had a better soluce ?.




/* H.264/AVC picture entry data structure */
typedef struct _DXVA_PicEntry_H264 {
  union {
    struct {
      UCHAR  Index7Bits      : 7;
      UCHAR  AssociatedFlag  : 1;
    };
    UCHAR  bPicEntry;
  };
} DXVA_PicEntry_H264, *LPDXVA_PicEntry_H264;  /* 1 byte */

typedef struct _DXVA_Slice_H264_Long {
  UINT   BSNALunitDataLocation; /* type 1..5 */
  UINT   SliceBytesInBuffer; /* for off-host parse */
  USHORT wBadSliceChopping;  /* for off-host parse */

  USHORT first_mb_in_slice;
  USHORT NumMbsForSlice;

  USHORT BitOffsetToSliceData; /* after CABAC alignment */

  UCHAR  slice_type;
  UCHAR  luma_log2_weight_denom;
  UCHAR  chroma_log2_weight_denom;
  UCHAR  num_ref_idx_l0_active_minus1;
  UCHAR  num_ref_idx_l1_active_minus1;
  CHAR   slice_alpha_c0_offset_div2;
  CHAR   slice_beta_offset_div2;
  UCHAR  Reserved8Bits;
  DXVA_PicEntry_H264 RefPicList[2][32]; /* L0 & L1 */
  SHORT  Weights[2][32][3][2]; /* L0 & L1; Y, Cb, Cr */
  CHAR   slice_qs_delta;
                               /* rest off-host parse */
  CHAR   slice_qp_delta;
  UCHAR  redundant_pic_cnt;
  UCHAR  direct_spatial_mv_pred_flag;
  UCHAR  cabac_init_idc;
  UCHAR  disable_deblocking_filter_idc;
  USHORT slice_id;
} DXVA_Slice_H264_Long, *LPDXVA_Slice_H264_Long;


Fa is a musical note to play with CL

Biterider

Hi
I would say that
RefPicList DXVA_PicEntry_H264 64 dup (<>)
Weights WORD 384 dup(?)

is the right way to go

Biterider

TouEnMasm

In fact seem to be simple

RESINFO STRUCT
        Hfichier      dd  ?   ;            Handle de ressourcr
        Pfichier      dd  ?   ;             pointeur de ressource
        Tfichier      dd  ?   ;,            taille du fichier ressource
RESINFO  ENDS

Quote
qessai qword 8 dup (5 dup(30 dup(0)))
tabresinfo    RESINFO  8 dup (5 dup(30 dup(<>)))

sizeof qessai         9600       LENGTHOF 1200
sizeof tabresinfo   14400     LENGTHOF 1200

just stay a little question  :icon_idea: How to address that ????????
Fa is a musical note to play with CL

daydreamer

How to adress that?
Look help file for more high-level structure addressing
Structname.variablename
instead of keep track of the different offsets to different variables in struct
Multiple leas combined or mul? For adress?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

HSE

#4
Quote from: TouEnMasm on April 18, 2021, 04:20:30 AM

RefPicList DXVA_PicEntry_H264 64 dup (<>)
Weights WORD 384 dup(?)


More meaningfull is:


RefPicList DXVA_PicEntry_H264 2*32 dup (<>)
Weights WORD 2*32*3*2 dup(?)


In other way you are losing information and gaining nothing.

first position is a=0, b=0, c=0; last is a=8-1, b=5-1, c=30-1

(a*5*30+b*30+c)*8
(a*5*30+b*30+c)*12

Can you see that is more easy if declaration was 8*5*30?
Equations in Assembly: SmplMath

Biterider

#5
Hi
Quote from: HSE on April 18, 2021, 06:59:58 AM

RefPicList DXVA_PicEntry_H264 2*32 dup (<>)


Weights WORD 2*32*3*2 dup(?)
In other way you are losing information and gaining nothing.

That's right and is a better solution   :thumbsup:
I second that.

Biterider

TouEnMasm


This one seem to be working

Quote
;tabresinfo    RESINFO  8 dup (5 dup(30 dup(<>)))
;tabresinfo    RESINFO  Z dup (Y dup(X dup(<>))) >> Z=8,Y=5,X=30       
;
.const
   X equ 30
   Y equ 5
   Z equ 8
.data
tabresinfo    RESINFO  8 dup (5 dup(30 dup(<>)))

.code
;################################################################
GetXYZadress PROC  x:DWORD,  y:DWORD,  z:DWORD
   Local retour:DWORD
         mov adress,1
;effective adress = lea tabresinfo + offset
;offset for  x    @x = sizeof (RESINFO) * x     ;
;offset for  y   mean that x is full so @y = [sizeof (RESINFO) * X] * y
;offset for z    mean that y is full so @z = [[sizeof (RESINFO) * X] * Y] * z
;calcul
   ;x
   mov ecx,sizeof(RESINFO)    
   mov edx,0
   mov eax,x
   mul ecx
   mov adress,eax
   ;y
   mov ecx,sizeof(RESINFO)   
   mov edx,0
   mov eax,X
   mul ecx
   mov ecx,y
   mul ecx
   add adress,eax
   ;z
   mov ecx,sizeof(RESINFO)   
   mov edx,0
   mov eax,X
   mul ecx
   mov ecx,Y
   mul ecx
   mov ecx,z
   mul ecx
   add adress,eax   
   
   mov eax,offset  tabresinfo
   add eax,adress
         ret

GetXYZadress endp

;################################################################
Fa is a musical note to play with CL

daydreamer

Not tested to do it SIMD

Movups xmm0,xyz
Movd xmm1, sizeof(resinfo)
Shufps xmm1,xmm1,all ; constant that shuffles. To all 4
Pmuludq xmm0,xmm1
Movaps addresses,xmm0
Movd eax,xmm0
Add eax,[addresses+4]
Add eax,[addresses+8]
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

HSE

Equations in Assembly: SmplMath

TouEnMasm

Here the c method


long long contenu [5][10][16];
long long essai;
int main()
{
essai = 555;
printf(" size : %u \n",sizeof contenu);
contenu[3][5][8] = essai;
printf(" [3][5][8] : %llu \n",contenu[3][5][8]);
_getch();
    return 0;



Quote
_main:
  00000000: 55                 push        ebp
  00000001: 8B EC              mov         ebp,esp
  00000003: 83 EC 40           sub         esp,40h
  00000006: 53                 push        ebx
  00000007: 56                 push        esi
  00000008: 57                 push        edi
  00000009: 33 C0              xor         eax,eax
  0000000B: C7 05 00 00 00 00  mov         dword ptr [?essai@@3_JA],22Bh
            2B 02 00 00
  00000015: A3 04 00 00 00     mov         dword ptr [?essai@@3_JA+4],eax        ;load qword essai
;--------------------------------------------------------------------------------------------------------
  0000001A: 68 00 19 00 00     push        1900h
  0000001F: 68 00 00 00 00     push        offset ??_C@_0N@KJIMBLEH@?5size?5?3?5?$CFu?5?6@
  00000024: E8 00 00 00 00     call        _printf
  00000029: 83 C4 08           add         esp,8
;------------------------------------------------------------------------------------------------------------
  0000002C: B8 00 05 00 00     mov         eax,500h   
                    imul        ecx,eax,3               ;result ecx ? [3][5][8]
  00000034: BA 80 00 00 00     mov         edx,80h
  00000039: 6B C2 05           imul        eax,edx,5
  0000003C: 8D 8C 01 00 00 00  lea         ecx,?contenu@@3PAY19BA@_JA[ecx+eax]
            00
  00000043: BA 08 00 00 00     mov         edx,8
  00000048: C1 E2 03           shl         edx,3
  0000004B: A1 00 00 00 00     mov         eax,dword ptr [?essai@@3_JA]
  00000050: 8B 35 04 00 00 00  mov         esi,dword ptr [?essai@@3_JA+4]
  00000056: 89 04 11           mov         dword ptr [ecx+edx],eax
  00000059: 89 74 11 04        mov         dword ptr [ecx+edx+4],esi
  0000005D: B8 00 05 00 00     mov         eax,500h
  00000062: 6B C8 03           imul        ecx,eax,3
  00000065: BA 80 00 00 00     mov         edx,80h
  0000006A: 6B C2 05           imul        eax,edx,5
  0000006D: 8D 8C 01 00 00 00  lea         ecx,?contenu@@3PAY19BA@_JA[ecx+eax]
            00
  00000074: BA 08 00 00 00     mov         edx,8
  00000079: C1 E2 03           shl         edx,3
  0000007C: 8B 44 11 04        mov         eax,dword ptr [ecx+edx+4]
  00000080: 50                 push        eax
  00000081: 8B 0C 11           mov         ecx,dword ptr [ecx+edx]
  00000084: 51                 push        ecx
  00000085: 68 00 00 00 00     push        offset ??_C@_0BE@EALIJHLA@?5?$FL3?$FN?$FL5?$FN?$FL8?$FN?5?3?5?$CFllu?5?6@
  0000008A: E8 00 00 00 00     call        _printf
  0000008F: 83 C4 0C           add         esp,0Ch
  00000092: FF 15 00 00 00 00  call        dword ptr [__imp___getch]
  00000098: 33 C0              xor         eax,eax
  0000009A: 5F                 pop         edi
  0000009B: 5E                 pop         esi
  0000009C: 5B                 pop         ebx
  0000009D: 8B E5              mov         esp,ebp
  0000009F: 5D                 pop         ebp
  000000A0: C3                 ret
500h = 10*16*8 = 1280 = 500h  ;...




Fa is a musical note to play with CL

jj2007

Quote from: daydreamer on April 18, 2021, 08:19:27 PM
Not tested to do it SIMD

Movups xmm0,xyz
Movd xmm1, sizeof(resinfo)

This is so advanced that my old debugger doesn't recognise it! Really, you should test it:
include \masm32\include\masm32rt.inc
.686p
.xmm
.data
resinfo dq 123
.code
start:
  int 3
  nops 2
  movd xmm1, sizeof(resinfo)
  nops 4
  invoke ExitProcess, 0
end start

CPU Disasm
Address   Hex dump          Command                                  Comments
00401000   .  CC            int3
00401001   .  90            nop
00401002   .  90            nop
00401003   .  660F6EC8      movd xmm1, eax
00401007      08            db 08                                    ; Backspace
00401008      90            nop
00401009      90            nop
0040100A      90            nop
0040100B      90            nop
0040100C  /.  6A 00         push 0                                   ; /ExitCode = 0
0040100E  \.  E8 01000000   call <jmp.&kernel32.ExitProcess>         ; \KERNEL32.ExitProcess

daydreamer

Quote from: HSE on April 19, 2021, 09:06:20 AM
Quote from: daydreamer on April 18, 2021, 08:19:27 PM
Not tested

Naturally. Nice final, but main part is missing  :biggrin:
I was thinking of fetch from adress where x:dword, Y:dword, Z:dword is
But anyway multiply every time is inefficient, TouEnMasm would be good to store 3 constants somewhere so you can add pointer,xconstant when in innerloop for increment x or y or Z pointer,which is faster
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

HSE

Quote from: jj2007 on April 19, 2021, 05:35:06 PM
This is so advanced that my old debugger doesn't recognise it! Really, you should test it:

  ...
  movd xmm1, sizeof(resinfo)
  ...

:biggrin: That it's not a valid instruction!

Must use a GPR:

   mov eax, 8
   movd xmm1, eax


JJ: your assembler is half smart, it write sizeof(resinfo) but in a wrong place  :biggrin: 

Equations in Assembly: SmplMath

TouEnMasm

Hello,
Here a soluce in 32 bits for creating multidimesionnal array of 2,3,4 dimensions.
Usage is simple:

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,lpCmdLine:XMASM,nShowCmd:DWORD
Local ppcallback:DWORD,ppath,pstarwar
;---- invoke caller,essai         ok
mov ppath,CREATEMULTI (byte,20,MAX_PATH) ;2 dimensions ,classic array of path
mov pstarwar,CREATEMULTI (QWORD,5,5,10,10) ;4 dimensions
mov edx,MAX_PATH
invoke GetMultiAddr,ppath,3,0     ;le 4eme chemin
;edx = adresse

invoke GetMultiAddr,pstarwar,3,0,1,0
;invoke GetMultiAddr,ptableau,5,0

mov eax,0
ret
WinMain endp



GetMultiAddr, is a c proc using VARARG ,perhaps he need to be improve
There is also in the source a CALLBACK MACRO.



Fa is a musical note to play with CL

HSE

Hi Yves!

     Look so much code for so little.
     Anyway still I can't make to work in Masm32.  :biggrin:

     if is working how you wanted: Fantastic  :thumbsup:
     
Equations in Assembly: SmplMath