@@ -110,7 +110,7 @@ encode_calculate_length:
110
110
test al , al # If we 're at the terminating null character then we' re ready to encode
111
111
jz encode_message
112
112
lea rdx , [ rax + 4 * rax ] # We get the codebook entry at the specific index
113
- lea r8 , [ r13 + 4 * rdx ]
113
+ lea r8 , [ r13 + 8 * rdx ]
114
114
add r14 , QWORD PTR [ r8 + bitstr_len ] # And add the encoded word length to the total
115
115
inc rcx
116
116
jmp encode_calculate_length
@@ -134,7 +134,7 @@ encode_message_bits:
134
134
test dil , dil # If we 're at the the null terminator we' re done
135
135
jz encode_done
136
136
lea rdx , [ rdi + 4 * rdi ] # Get the codebook entry
137
- lea r10 , [ r13 + 4 * rdx ]
137
+ lea r10 , [ r13 + 8 * rdx ]
138
138
mov r11 , QWORD PTR [ r10 + bitstr_len ] # Load the bitstring length
139
139
lea r14 , [ r10 ] # The bitstring qword we're currently processing
140
140
encode_message_bits_qword:
@@ -225,14 +225,22 @@ decode_done:
225
225
# rdi - The starting address of the codebook we want to generate
226
226
# rsi - Huffman - tree root (ptr)
227
227
generate_codebook:
228
- sub rsp , bitstr_size + 8 # 8 extra bytes for alignment
228
+ push r12
229
+ sub rsp , bitstr_size + 16 # 16 extra bytes for alignment
230
+ mov r12 , rsi
229
231
xorps xmm0 , xmm0 # Create a 0 - initialized bitstring. This will be
230
232
movaps XMMWORD PTR [ rsp ], xmm0 # used in the recursive function calls
231
233
movaps XMMWORD PTR [ rsp + 16 ], xmm0
232
234
mov QWORD PTR [ rsp + 32 ], 0
235
+ xor rsi , rsi
236
+ mov rdx , codebook_size
237
+ call memset
238
+ mov rdi , rax
239
+ mov rsi , r12
233
240
mov rdx , rsp
234
241
call generate_codebook_recurse
235
- add rsp , bitstr_size + 8
242
+ add rsp , bitstr_size + 16
243
+ pop r12
236
244
ret
237
245
238
246
# rdi - The codebook's starting address
@@ -254,7 +262,7 @@ generate_codebook_recurse:
254
262
movaps xmm1 , XMMWORD PTR [ rdx + 16 ]
255
263
mov r9 , QWORD PTR [ rdx + 32 ]
256
264
lea rax , [ r8 + 4 * r8 ] # The index calculation needs to add 40 * index. With lea arithmetic this can be represented as
257
- lea r10 , [ rdi + 4 * rax ] # base address + 4 * ( 5 * index). This is done in two lea instructions
265
+ lea r10 , [ rdi + 8 * rax ] # base address + 8 * ( 5 * index). This is done in two lea instructions
258
266
movups XMMWORD PTR [ r10 ], xmm0 # And copy the data over to it
259
267
movups XMMWORD PTR [ r10 + 16 ], xmm1
260
268
mov QWORD PTR [ r10 + 32 ], r9
@@ -436,7 +444,7 @@ print_codebook_loop:
436
444
cmp rbx , 255
437
445
jg print_codebook_done
438
446
lea rax , [ rbx + 4 * rbx ] # We get the codebook entry at the specific index
439
- lea r10 , [ r12 + 4 * rax ]
447
+ lea r10 , [ r12 + 8 * rax ]
440
448
mov rdx , QWORD PTR [ r10 + bitstr_len ] # Load the length of the bitstring
441
449
test rdx , rdx # If it 's zero then the codepoint didn' t exist in the original alphabet , skip
442
450
jz print_codebook_counters
0 commit comments