-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkronecker.asm
162 lines (133 loc) · 2.32 KB
/
kronecker.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
public kronecker ; extern void kronecker(float* AMatrix, float* BMatrix, float* DestMatrix, int* SizeMatrix);
.data
ARows dd ?
ACols dd ?
BRows dd ?
BCols dd ?
DestPointer dq ?
Multiplier dd ?
.code
initializeData PROC
push rbx
bswap r8
mov DestPointer, r8
bswap r8
mov ebx, [r9]
mov ARows, ebx
mov ebx, [r9+4]
mov ACols, ebx
mov ebx, [r9+8]
mov BRows, ebx
mov ebx, [r9+12]
mov BCols, ebx
pop rbx
ret
initializeData ENDP
fillDestMatrix PROC
push rax
push rbx
push rcx
push rdx
push rsi ; iterator macierzy B
push rdi
push r12
push r13
push r14
mov r12, DestPointer
bswap r12
mov r13, rdx
mov rsi, 0
mov rdi, 0
mov rax, 0 ;; do mnozenia
mov rdx, 0 ;; do mnozenia
mov rbx, 0
mov r14, 0
cols:
rows:
fld dword ptr [r13+4*rsi]
fld dword ptr multiplier
fmulp
fstp dword ptr[r12+4*rdi]
;mov ebx, [r13+4*rsi]
;mov [r12+4*rdi], ebx
inc rsi
inc rdi
cmp edi, BCols
jnz rows
pastrows:
inc r14 ;; kolejny wiersz
mov edx, 0
mov rax, 0 ;; do dzielenia
mov rdi, 0 ;; rdi to iterator poziomy, r12 sie przesuwa przy kolejnym wierszu
mov eax, BCols
mul ACols
shl eax, 2; eax * 4
add r12, rax
cmp r14d, BRows
jnz rows
pop r14
pop r13
pop r12
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
ret
fillDestMatrix ENDP
; RCX RDX R8 R9
kronecker PROC;(float* AMatrix, float* BMatrix, float* DestMatrix, int* SizeMatrix);
push rbx ; przechowanie rejestrów
push rsi
push rdi
push r14
push r15
finit
call initializeData
mov r14, rcx
mov r15, rdx
mov r10, 0 ; iterator I
mov r11, 0 ; iterator J
mov rbx, 0 ;; iterator
outer:
inner:
mov ecx, [r14+4*rbx]
mov multiplier, ecx
mov rdx, r15
call fillDestMatrix
mov eax, BCols
shl eax, 2 ; BCols * 4
mov rcx, DestPointer
bswap rcx
add rcx, rax ; bo konwencje się psują
bswap rcx
mov DestPointer, rcx
inc rbx
inc r10
cmp r10d, ACols
jnz inner
mov eax, BRows
sub eax, 1
mul BCols
mul ACols
shl eax, 2
mov rcx, DestPointer
bswap rcx
add rcx, rax
bswap rcx
mov DestPointer, rcx
mov r10, 0
inc r11
cmp r11d, ARows
jnz outer
mov rax, r8
pop r15
pop r14
pop rdi
pop rsi
pop rbx
ret
kronecker ENDP
END
END