resampler optimization, reduce cache pollution

git-svn-id: svn://kolibrios.org@285 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2007-01-20 07:48:13 +00:00
parent 5462727f9c
commit 6ab013ea0b
9 changed files with 173 additions and 235 deletions

View File

@ -566,14 +566,18 @@ proc new_mem_resize stdcall, new_size:dword
ret ret
endp endp
; param
; eax= linear address
;
; retval
; eax= phisical page address
align 4 align 4
proc get_pg_addr stdcall, lin_addr:dword get_pg_addr:
mov ebx, [lin_addr] shr eax, 12
shr ebx, 12 mov eax, [pages_tab+eax*4]
mov eax, [pages_tab+ebx*4]
and eax, 0xFFFFF000 and eax, 0xFFFFF000
ret ret
endp
align 4 align 4
proc page_fault_handler proc page_fault_handler

View File

@ -981,7 +981,7 @@ devices dd (R8500 shl 16)+VID_ATI
dd (R9800XT shl 16)+VID_ATI dd (R9800XT shl 16)+VID_ATI
dd 0 ;terminator dd 0 ;terminator
version dd 0x00020002 version dd 0x00030003
sz_ati_srv db 'HWCURSOR',0 sz_ati_srv db 'HWCURSOR',0

View File

@ -40,7 +40,7 @@ if used AllocPages
extrn AllocPages extrn AllocPages
end if end if
if used FreePage if used FreePage
extrn zFreePage extrn FreePage
end if end if
if used MapPage if used MapPage
extrn MapPage extrn MapPage

View File

@ -190,22 +190,22 @@ proc CreateBuffer stdcall, format:dword
mov [edi+STREAM.magic], 'WAVE' mov [edi+STREAM.magic], 'WAVE'
mov [edi+STREAM.size], STREAM_SIZE mov [edi+STREAM.size], STREAM_SIZE
stdcall KernelAlloc, 180*1024 stdcall KernelAlloc, 172*1024
mov edi, [str] mov edi, [str]
mov [edi+STREAM.base], eax mov [edi+STREAM.base], eax
add eax, 0x1000
mov [edi+STREAM.seg_0], eax mov [edi+STREAM.seg_0], eax
mov [edi+STREAM.curr_seg], eax mov [edi+STREAM.curr_seg], eax
mov [edi+STREAM.notify_off1], eax mov [edi+STREAM.notify_off1], eax
add eax, 0x7FFF add eax, 0x8000
mov [edi+STREAM.lim_0], eax mov [edi+STREAM.lim_0], eax
inc eax add eax, 0x1000
mov [edi+STREAM.seg_1], eax mov [edi+STREAM.seg_1], eax
mov [edi+STREAM.notify_off2], eax mov [edi+STREAM.notify_off2], eax
add eax, 0x7FFF add eax, 0x8000
mov [edi+STREAM.limit], eax mov [edi+STREAM.limit], eax
mov [edi+STREAM.lim_1], eax mov [edi+STREAM.lim_1], eax
inc eax
mov [edi+STREAM.work_buff], eax mov [edi+STREAM.work_buff], eax
mov [edi+STREAM.work_read], eax mov [edi+STREAM.work_read], eax
@ -213,8 +213,6 @@ proc CreateBuffer stdcall, format:dword
mov [edi+STREAM.work_count], 0 mov [edi+STREAM.work_count], 0
add eax, 0x10000 add eax, 0x10000
mov [edi+STREAM.work_top], eax mov [edi+STREAM.work_top], eax
add eax, 1024*32
mov [edi+STREAM.r_buff], eax
mov ebx, [CURRENT_TASK] mov ebx, [CURRENT_TASK]
shl ebx, 5 shl ebx, 5
@ -245,8 +243,18 @@ proc CreateBuffer stdcall, format:dword
mov ebx, [resampler_params+eax+12] mov ebx, [resampler_params+eax+12]
mov [edi+STREAM.resample], ebx mov [edi+STREAM.resample], ebx
mov edx, [edi+STREAM.base]
lea eax, [edx+0x9000]
call GetPgAddr ;eax
call FreePage ;eax
mov eax, edx
lea ebx, [edx+0x9000]
call GetPgAddr ;eax
stdcall MapPage, ebx, eax, dword 3
mov edi, [edi+STREAM.base] mov edi, [edi+STREAM.base]
mov ecx, 180*1024/4 mov ecx, (168*1024)/4
xor eax, eax xor eax, eax
rep stosd rep stosd
@ -338,52 +346,56 @@ align 4
proc play_buffer stdcall, str:dword proc play_buffer stdcall, str:dword
mov ebx, [str] mov ebx, [str]
cmp [ebx+STREAM.magic], 'WAVE' cmp [ebx+STREAM.magic], 'WAVE'
jne .fail jne .fail
cmp [ebx+STREAM.size], STREAM_SIZE cmp [ebx+STREAM.size], STREAM_SIZE
jne .fail jne .fail
mov [ebx+STREAM.flags], SND_PLAY mov edi,[ebx+STREAM.work_buff]
mov [ebx+STREAM.work_read], edi
mov eax,[ebx+STREAM.work_buff] mov [ebx+STREAM.work_write], edi
mov [ebx+STREAM.work_read], eax
mov [ebx+STREAM.work_write], eax
mov [ebx+STREAM.work_count], 0 mov [ebx+STREAM.work_count], 0
mov eax, [ebx+STREAM.seg_0] mov edx, [ebx+STREAM.base]
mov [ebx+STREAM.curr_seg], eax add edx, 0x1000
mov [ebx+STREAM.seg_0], edx
mov [ebx+STREAM.curr_seg], edx
add edx, 0x8000
mov [ebx+STREAM.lim_0], edx
add edx, 0x1000
mov [ebx+STREAM.seg_1], edx
add edx, 0x8000
mov [ebx+STREAM.lim_1], edx
mov esi, [ebx+STREAM.curr_seg] mov edx, [ebx+STREAM.seg_0]
mov edi, [ebx+STREAM.work_write] mov ecx, -128
mov edx, [ebx+STREAM.r_buff]
mov ecx, 32
mov eax, [ebx+STREAM.r_silence] mov eax, [ebx+STREAM.r_silence]
@@: @@:
mov [edx], eax mov [edx+ecx], eax
add edx, 4 add ecx, 4
dec ecx
jnz @B jnz @B
mov edx, [ebx+STREAM.r_buff] stdcall [ebx+STREAM.resample], edi, edx,\
stdcall [ebx+STREAM.resample], edi, esi, edx,\
[ebx+STREAM.r_dt],[ebx+STREAM.r_size],[ebx+STREAM.r_end] [ebx+STREAM.r_dt],[ebx+STREAM.r_size],[ebx+STREAM.r_end]
mov ebx, [str] mov ebx, [str]
add [ebx+STREAM.work_count], eax; add [ebx+STREAM.work_count], eax
add [ebx+STREAM.work_write], eax; add [ebx+STREAM.work_write], eax
mov eax, [ebx+STREAM.r_size] mov edx, [ebx+STREAM.r_size]
add [ebx+STREAM.curr_seg], eax add [ebx+STREAM.curr_seg], edx
; if DEBUG mov [ebx+STREAM.flags], SND_PLAY
; mov esi, msgPlay
; call [SysMsgBoardStr] mov eax, [ebx+STREAM.r_silence]
; end if mov edi, [ebx+STREAM.work_write]
mov ecx, [ebx+STREAM.work_top]
sub ecx, edi
shr ecx, 2
cld
rep stosd
stdcall dev_play, [hSound] stdcall dev_play, [hSound]
xor eax, eax xor eax, eax
@ -437,27 +449,35 @@ proc set_buffer stdcall, str:dword,src:dword,offs:dword,size:dword
cmp esi, new_app_base cmp esi, new_app_base
jb .fail jb .fail
mov ecx, [size] mov edi, [offs]
test ecx, ecx mov ecx, 0x8000
jz .fail
mov eax, [edx+STREAM.base] sub ecx, edi
add eax, [offs] jbe .seg_1
cmp eax, [edx+STREAM.base] sub [size], ecx
jb .fail jb .fail
mov edi, eax add edi, [edx+STREAM.base]
add eax, ecx add edi, 0x1000
sub eax, 1
cmp eax, [edx+STREAM.limit]
ja .fail
shr ecx, 2 shr ecx, 2
cld cld
rep movsd rep movsd
jmp @F
.seg_1:
add edi, [edx+STREAM.base]
add edi, 0x1000
@@:
add edi, 0x1000
mov ecx, [size]
test ecx, ecx
jz .done
cmp ecx, 0x8000
ja .fail
shr ecx, 2
rep movsd
.done:
xor eax, eax xor eax, eax
inc eax inc eax
ret ret
@ -505,33 +525,6 @@ proc free_stream
ret ret
endp endp
if 0
align 4
proc check_stream
xor edx, edx
mov ecx, [play_count]
.l1:
mov esi, [play_list+edx]
mov eax, [esi+STR.curr_seg]
cmp eax, [esi+STR.lim_0]
jb .next
mov eax, [esi+STREAM.seg_0]
mov ecx, [esi+STREAM.lim_0]
xchg eax, [ebx+STREAM.seg_1]
xchg ecx, [ebx+STREAM.lim_1]
mov [esi+STREAM.seg_0], eax
mov [esi+STREAM.lim_0], ecx
mov [esi+STR.curr_seg], eax
.next:
add edx, 4
loop .l1
ret
endp
end if
align 4 align 4
proc prepare_playlist proc prepare_playlist
@ -723,7 +716,7 @@ mm80 dq 0x8080808080808080
mm_mask dq 0xFF00FF00FF00FF00 mm_mask dq 0xFF00FF00FF00FF00
stream_map dd 0xFFFF ; 16 stream_map dd 0xFFFF ; 16
version dd 0x00020002 version dd 0x00030003
szInfinity db 'INFINITY',0 szInfinity db 'INFINITY',0
szSound db 'SOUND',0 szSound db 'SOUND',0

View File

@ -91,7 +91,6 @@ struc STREAM
.work_write dd 0 .work_write dd 0
.work_count dd 0 .work_count dd 0
.work_top dd 0 .work_top dd 0
.r_buff dd 0
.r_size dd 0 .r_size dd 0
.r_end dd 0 .r_end dd 0
.r_dt dd 0 .r_dt dd 0
@ -112,7 +111,7 @@ struc STREAM
.resample dd 0 .resample dd 0
} }
STREAM_SIZE equ 27*4 STREAM_SIZE equ 26*4
virtual at 0 virtual at 0
STREAM STREAM STREAM STREAM

View File

@ -223,9 +223,8 @@ proc refill stdcall, str:dword
.m2: .m2:
mov esi, [ebx+STREAM.curr_seg] mov esi, [ebx+STREAM.curr_seg]
mov edi, [ebx+STREAM.work_write] mov edi, [ebx+STREAM.work_write]
mov edx, [ebx+STREAM.r_buff]
stdcall [ebx+STREAM.resample], edi, esi, edx,\ stdcall [ebx+STREAM.resample], edi, esi, \
[ebx+STREAM.r_dt],[ebx+STREAM.r_size],[ebx+STREAM.r_end] [ebx+STREAM.r_dt],[ebx+STREAM.r_size],[ebx+STREAM.r_end]
mov ebx, [str] mov ebx, [str]
@ -238,6 +237,13 @@ proc refill stdcall, str:dword
cmp eax, [ebx+STREAM.lim_0] cmp eax, [ebx+STREAM.lim_0]
jb @f jb @f
mov esi, [ebx+STREAM.seg_0]
lea edi, [esi-128]
add esi, 0x7F80
mov ecx, 128/4
cld
rep movsd
mov eax, [ebx+STREAM.seg_0] mov eax, [ebx+STREAM.seg_0]
mov ecx, [ebx+STREAM.lim_0] mov ecx, [ebx+STREAM.lim_0]
xchg eax, [ebx+STREAM.seg_1] xchg eax, [ebx+STREAM.seg_1]
@ -273,18 +279,18 @@ proc refill stdcall, str:dword
endp endp
align 4 align 4
proc resample_1 stdcall, dest:dword,src:dword,r_buff:dword,\ proc resample_1 stdcall, dest:dword,src:dword,\
r_dt:dword, r_size:dword,r_end:dword r_dt:dword, r_size:dword,r_end:dword
mov edi, [r_buff] ; dest equ esp+8
add edi, 32*2 ; src equ esp+12
mov esi, [src] ; r_dt equ esp+16
mov ecx, [r_size] ; r_size equ esp+20
shr ecx, 2 ;r_end equ esp+24
rep movsd
mov edi, [dest] mov edi, [dest]
mov edx, [r_buff] mov edx, [src]
sub edx, 32*2
mov eax, 16 mov eax, 16
align 16 align 16
@ -318,43 +324,26 @@ align 16
mov [edi], ebx mov [edi], ebx
add edi, 4 add edi, 4
add eax, [esp+20] ;rdt add eax, [esp+16]
cmp eax, [esp+28] ;r_end cmp eax, [esp+24]
jb .l1 jb .l1
mov ebp, esp mov ebp, esp
mov esi, [src]
add esi, [r_size]
sub esi, 32*2
mov edx, [r_buff]
mov ecx, 16
@@:
mov ebx, [esi]
mov [edx], ebx
add esi, 4
add edx, 4
dec ecx
jnz @B
sub edi, [dest] sub edi, [dest]
mov eax, edi mov eax, edi
ret ret
endp endp
align 4 align 4
proc resample_18 stdcall, dest:dword,src:dword,r_buff:dword,\ proc resample_18 stdcall, dest:dword,src:dword,\
r_dt:dword, r_size:dword,r_end:dword r_dt:dword, r_size:dword,r_end:dword
mov edi, [r_buff]
add edi, 32
mov esi, [src]
mov ecx, [r_size]
shr ecx, 2
rep movsd
mov edi, [dest] mov edi, [dest]
mov edx, [r_buff] mov edx, [src]
sub edx, 32
mov esi, 16 mov esi, 16
align 16 align 16
@ -393,32 +382,18 @@ align 16
mov [edi], ebx mov [edi], ebx
add edi, 4 add edi, 4
add esi, [esp+20] ;rdt add esi, [esp+16]
cmp esi, [esp+28] ;r_end cmp esi, [esp+24]
jb .l1 jb .l1
mov ebp, esp mov ebp, esp
mov esi, [src]
add esi, [r_size]
sub esi, 32
mov edx, [r_buff]
mov ecx, 8
@@:
mov ebx, [esi]
mov [edx], ebx
add esi, 4
add edx, 4
dec ecx
jnz @B
sub edi, [dest] sub edi, [dest]
mov eax, edi mov eax, edi
ret ret
endp endp
align 4 align 4
proc copy_stream stdcall, dest:dword,src:dword,r_buff:dword,\ proc copy_stream stdcall, dest:dword,src:dword,\
r_dt:dword, r_size:dword,r_end:dword r_dt:dword, r_size:dword,r_end:dword
mov ecx, [r_size] mov ecx, [r_size]
@ -432,17 +407,11 @@ proc copy_stream stdcall, dest:dword,src:dword,r_buff:dword,\
endp endp
align 4 align 4
proc resample_2 stdcall, dest:dword,src:dword,r_buff:dword,\ proc resample_2 stdcall, dest:dword,src:dword,\
r_dt:dword, r_size:dword,r_end:dword r_dt:dword, r_size:dword,r_end:dword
mov edi, [r_buff] mov edx, [src]
add edi, 32*4 sub edx, 32*4
mov esi, [src]
mov ecx, [r_size]
shr ecx, 2
rep movsd ;call memcpy
mov edx, [r_buff]
mov edi, [dest] mov edi, [dest]
mov ebx, [r_dt] mov ebx, [r_dt]
mov eax, 16 mov eax, 16
@ -461,9 +430,9 @@ align 16
movd mm2, ecx movd mm2, ecx
punpcklwd mm2, mm2 punpcklwd mm2, mm2
movq mm3, qword [m7] ; // 0x8000 movq mm3, qword [m7] ;0x8000
psubw mm3, mm2 ; // 0x8000 - iconst psubw mm3, mm2 ; ;0x8000 - iconst
punpckldq mm3, mm2 punpckldq mm3, mm2
pmulhw mm0, mm3 pmulhw mm0, mm3
@ -483,36 +452,17 @@ align 16
jb .l1 jb .l1
emms emms
mov esi, [src]
add esi, [r_size]
sub esi, 32*4
mov edx, [r_buff]
mov ecx, 32
@@:
mov ebx, [esi]
mov [edx], ebx
add esi, 4
add edx, 4
dec ecx
jnz @B
sub edi, [dest] sub edi, [dest]
mov eax, edi mov eax, edi
ret ret
endp endp
align 4 align 4
proc resample_28 stdcall, dest:dword,src:dword,r_buff:dword,\ proc resample_28 stdcall, dest:dword,src:dword,\
r_dt:dword, r_size:dword,r_end:dword r_dt:dword, r_size:dword,r_end:dword
mov edi, [r_buff] mov edx, [src]
add edi, 32*2 sub edx, 32*2
mov esi, [src]
mov ecx, [r_size]
shr ecx, 2
rep movsd ;call memcpy
mov edx, [r_buff]
mov edi, [dest] mov edi, [dest]
mov ebx, [r_dt] mov ebx, [r_dt]
mov eax, 16 mov eax, 16
@ -559,18 +509,6 @@ align 16
jb .l1 jb .l1
emms emms
mov esi, [src]
add esi, [r_size]
sub esi, 32*2
mov edx, [r_buff]
mov ecx, 16
@@:
mov ebx, [esi]
mov [edx], ebx
add esi, 4
add edx, 4
dec ecx
jnz @B
sub edi, [dest] sub edi, [dest]
mov eax, edi mov eax, edi
@ -578,7 +516,7 @@ align 16
endp endp
proc m16_stereo stdcall, dest:dword,src:dword,r_buff:dword,\ proc m16_stereo stdcall, dest:dword,src:dword,\
r_dt:dword, r_size:dword,r_end:dword r_dt:dword, r_size:dword,r_end:dword
mov esi, [src] mov esi, [src]
@ -607,7 +545,7 @@ proc m16_stereo stdcall, dest:dword,src:dword,r_buff:dword,\
endp endp
align 4 align 4
proc s8_stereo stdcall, dest:dword,src:dword,r_buff:dword,\ proc s8_stereo stdcall, dest:dword,src:dword,\
r_dt:dword, r_size:dword,r_end:dword r_dt:dword, r_size:dword,r_end:dword
mov esi, [src] mov esi, [src]
@ -638,7 +576,7 @@ proc s8_stereo stdcall, dest:dword,src:dword,r_buff:dword,\
ret ret
endp endp
proc m8_stereo stdcall, dest:dword,src:dword,r_buff:dword,\ proc m8_stereo stdcall, dest:dword,src:dword,\
r_dt:dword, r_size:dword,r_end:dword r_dt:dword, r_size:dword,r_end:dword
mov esi, [src] mov esi, [src]

View File

@ -143,7 +143,7 @@ align 4
devices dd (DEVICE_ID shl 16)+VENDOR_ID devices dd (DEVICE_ID shl 16)+VENDOR_ID
dd 0 ;terminator dd 0 ;terminator
version dd 0x00020002 version dd 0x00030003
my_service db 'MY_SERVICE',0 ;max 16 chars include zero my_service db 'MY_SERVICE',0 ;max 16 chars include zero

View File

@ -457,7 +457,8 @@ proc create_primary_buff
xor eax, eax xor eax, eax
rep stosd rep stosd
stdcall GetPgAddr, [ctrl.buffer] mov eax, [ctrl.buffer]
call GetPgAddr
mov ebx, 0xC0004000 mov ebx, 0xC0004000
mov ecx, 4 mov ecx, 4
@ -501,10 +502,11 @@ proc create_primary_buff
add edi, 4 add edi, 4
loop @B loop @B
mov ecx, pcmout_bdl mov eax, pcmout_bdl
stdcall GetPgAddr, ecx mov ebx, eax
and ecx, 0xFFF call GetPgAddr ;eax
add eax, ecx and ebx, 0xFFF
add eax, ebx
mov edx, PCM_OUT_BDL mov edx, PCM_OUT_BDL
call [ctrl.ctrl_write32] call [ctrl.ctrl_write32]
@ -1130,7 +1132,7 @@ align 4
devices dd (CTRL_SIS shl 16)+VID_SIS,msg_AC, set_SIS devices dd (CTRL_SIS shl 16)+VID_SIS,msg_AC, set_SIS
dd 0 dd 0
version dd 0x00020002 version dd 0x00030003
msg_AC db '7012 AC97 controller',13,10, 0 msg_AC db '7012 AC97 controller',13,10, 0
msg_SIS db 'Silicon Integrated Systems',13,10, 0 msg_SIS db 'Silicon Integrated Systems',13,10, 0

View File

@ -521,7 +521,8 @@ proc create_primary_buff
cld cld
rep stosd rep stosd
stdcall GetPgAddr, [ctrl.buffer] mov eax, [ctrl.buffer]
call GetPgAddr
mov ebx, 0xC0002000 mov ebx, 0xC0002000
mov ecx, 4 mov ecx, 4
@ -572,10 +573,11 @@ proc create_primary_buff
add edi, 4 add edi, 4
loop @B loop @B
mov ecx, pcmout_bdl mov eax, pcmout_bdl
stdcall GetPgAddr, ecx mov ebx, eax
and ecx, 0xFFF call GetPgAddr ;eax
add eax, ecx and ebx, 0xFFF
add eax, ebx
mov edx, PCM_OUT_BDL mov edx, PCM_OUT_BDL
call [ctrl.ctrl_write32] call [ctrl.ctrl_write32]
@ -1351,7 +1353,7 @@ devices dd (CTRL_ICH shl 16)+VID_INTEL,msg_ICH, set_ICH
dd 0 ;terminator dd 0 ;terminator
version dd 0x00020002 version dd 0x00030003
msg_ICH db 'Intel ICH', 13,10, 0 msg_ICH db 'Intel ICH', 13,10, 0
msg_ICH0 db 'Intel ICH0', 13,10, 0 msg_ICH0 db 'Intel ICH0', 13,10, 0