2
0
mirror of https://git.missingno.dev/kolibrios-nvme-driver/ synced 2024-11-12 19:27:28 +01:00

perf: use bit shift instead of multiplication where possible

This commit is contained in:
Abdur-Rahman Mansoor 2024-08-08 12:34:24 -04:00
parent 29f04eb37b
commit f502f3cfaa
2 changed files with 18 additions and 7 deletions

View File

@ -981,7 +981,7 @@ proc get_new_cid stdcall, pci:dword, y:dword
mov eax, [pci]
mov eax, dword [eax + pcidev.queue_entries]
mov ecx, [y]
imul ecx, sizeof.NVM_QUEUE_ENTRY
shl ecx, SIZEOF_NVM_QUEUE_ENTRY
movzx eax, word [eax + ecx + NVM_QUEUE_ENTRY.head]
ret
@ -1072,7 +1072,7 @@ proc cqyhdbl_write stdcall, pci:dword, y:dword, cqh:dword
imul dx, ax
add dx, 0x1000
mov ecx, [y]
imul ecx, sizeof.NVM_QUEUE_ENTRY
shl ecx, SIZEOF_NVM_QUEUE_ENTRY
mov edi, dword [esi + pcidev.queue_entries]
lea edi, dword [edi + ecx]
mov eax, [cqh]
@ -1092,7 +1092,7 @@ proc sqytdbl_write stdcall, pci:dword, y:word, cmd:dword
mov edi, [pci]
mov edi, dword [edi + pcidev.queue_entries]
movzx ebx, [y]
imul ebx, sizeof.NVM_QUEUE_ENTRY
shl ebx, SIZEOF_NVM_QUEUE_ENTRY
lea edi, [edi + ebx]
mov eax, dword [edi + NVM_QUEUE_ENTRY.cmd_ptr]
mov edx, dword [edi + NVM_QUEUE_ENTRY.sq_ptr]
@ -1100,9 +1100,9 @@ proc sqytdbl_write stdcall, pci:dword, y:word, cmd:dword
mov ecx, dword [esi + SQ_ENTRY.cdw0]
shr ecx, 16 ; Get CID
mov ebx, ecx
imul ebx, sizeof.NVM_QUEUE_ENTRY
shl ebx, SIZEOF_NVM_QUEUE_ENTRY
add ebx, eax
imul ecx, sizeof.SQ_ENTRY
shl ecx, SIZEOF_SQ_ENTRY
lea edx, [edx + ecx]
stdcall memcpyd, edx, esi, sizeof.SQ_ENTRY / 4
mov ecx, dword [ebx + NVMQCMD.mutex_ptr]
@ -1172,7 +1172,7 @@ proc consume_cq_entries stdcall, pci:dword, queue:dword
push esi edi
mov esi, [pci]
mov ecx, [queue]
imul ecx, sizeof.NVM_QUEUE_ENTRY
shl ecx, SIZEOF_NVM_QUEUE_ENTRY
mov esi, dword [esi + pcidev.queue_entries]
lea esi, [esi + ecx]
mov edi, dword [esi + NVM_QUEUE_ENTRY.cq_ptr]
@ -1191,7 +1191,7 @@ proc consume_cq_entries stdcall, pci:dword, queue:dword
cmp cx, word [esi + NVM_QUEUE_ENTRY.tail]
je .end
mov edx, ecx
imul edx, sizeof.CQ_ENTRY
shl edx, SIZEOF_CQ_ENTRY
mov ax, word [edi + edx + CQ_ENTRY.status]
;DEBUGF DBG_INFO, "Status: 0x%x\n", ax
inc cx

View File

@ -27,6 +27,9 @@ SUPPORTED_LBADS = 9 ; KolibriOS only supports LBADS of 512, later on w
SQ_ALLOC_SIZE = NVM_ASQS * sizeof.SQ_ENTRY
CQ_ALLOC_SIZE = NVM_ACQS * sizeof.CQ_ENTRY
QUEUE_ALLOC_SIZE = SQ_ALLOC_SIZE + CQ_ALLOC_SIZE
SIZEOF_SQ_ENTRY = 6 ; log2(sizeof.SQ_ENTRY)
SIZEOF_CQ_ENTRY = 4 ; log2(sizeof.CQ_ENTRY)
SIZEOF_NVM_QUEUE_ENTRY = 4 ; log2(sizeof.NVM_QUEUE_ENTRY)
MSIXCAP_CID = 0x11
MSIXCAP_MXE = 1 shl 15 ; MSI-X Enable bit
@ -567,7 +570,15 @@ assert sizeof.CQ_ENTRY = 16
assert sizeof.IDENTC = 4096
assert sizeof.IDENTN = 4096
assert sizeof.NSGRANLS = 288
assert SIZEOF_SQ_ENTRY = 6
assert SIZEOF_CQ_ENTRY = 4
assert (SQ_ENTRIES * sizeof.SQ_ENTRY) mod PAGE_SIZE = 0
assert (CQ_ENTRIES * sizeof.CQ_ENTRY) mod PAGE_SIZE = 0
; NOTE: DO NOT CHANGE THIS ASSERTION!
; If you do decide to change it, you'll have
; to modify the source code manually since it
; uses bit shifts to multiply by the struct size
assert sizeof.NVM_QUEUE_ENTRY = 16
assert SIZEOF_NVM_QUEUE_ENTRY = 4
; vim: syntax=fasm