memory tips for ultra low jitter

Bare metal programming in PureBasic, for experienced users
User avatar
oryaaaaa
Enthusiast
Enthusiast
Posts: 791
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

memory tips for ultra low jitter

Post by oryaaaaa »

This tips from my high quality sound player.

The slight jitter not even allowed software, the following Tips will help.
  • Don't use MOVQ
  • Use MOVNTQ, MOVNTDQ, then don't use CPU cache memory
  • Use MMX register

Code: Select all

Procedure InitializeMemory(*memory, mem_size.i)
  Protected s.i
  
  If *memory 
    If mem_size%8>0
      s = mem_size + (8 - mem_size%8)
    Else
      s = mem_size
    EndIf 
    If s < 1
      ProcedureReturn
    EndIf

    !PXOR mm1, mm1
    !MOV Eax, [p.v_s]
    !MOV Ecx, [p.p_memory]
    !InitializeMemory: 
    !movntq [Ecx], mm1
    !ADD  Ecx, 8
    !SUB  Eax, 8
    !JNZ InitializeMemory
    !emms
  Else
    ; error
    End 
  EndIf
EndProcedure

*buffer = AllocateMemory(4096, #PB_Memory_NoClear)
InitializeMemory(*buffer, 4096)
ReWriteMemory
http://www.purebasic.fr/english/viewtop ... 12&t=60968
  • This code use for After decode process or After sound process or For Asio buffer.
  • Bit holding voltage rise in the memory circuit of the memory chip for ultra low jitter.
  • Ranking of quality : 1st MMX(movntq), 2nd AVX (vmovntdq) 3rd SSE(movntdq)

Code: Select all

Procedure ReWriteMemory(*memory, mem_size.i)
  Protected s.i
  
  If mem_size%16>0
    s = mem_size + (16 - mem_size%16)
  Else
    s = mem_size
  EndIf
  
  !PXOR xmm0, xmm0
  !MOV Eax, [p.v_s]
  !MOV Ecx, [p.p_memory]
  !ReWrite: 
  !PXOR xmm0, xmm0
  !movdqa xmm0, [Ecx]
  !movntdq [Ecx], xmm0
  !ADD  Ecx, 16
  !SUB  Eax, 16
  !JNZ ReWrite 
EndProcedure
CopyMemory for ultra low jitter
  • Don't use MOVQ
  • Use MOVNTQ, MOVNTDQ, then don't use CPU cache memory
  • Use MMX register

Code: Select all

Procedure CopyMemoryMMX(*memory_in, *memory_out, mem_size.i)
  Protected s.i ; integer
  
  If mem_size%8>0 ; adjust align
    s = mem_size + (8 - mem_size%8)
  Else
    s = mem_size
  EndIf
  
  If s < 1
    ProcedureReturn
  EndIf 
  
  CompilerSelect #PB_Compiler_Processor
    CompilerCase #PB_Processor_x86
      !PXOR mm1, mm1
      !MOV Eax, [p.v_s]
      !MOV Ecx, [p.p_memory_in]
      !MOV Edx, [p.p_memory_out]
      !CopyMemoryMMX: 
      !PXOR mm1, mm1
      !movq mm1, [Ecx]
      !movntq [Edx], mm1
      !ADD  Ecx, 8
      !ADD  Edx, 8
      !SUB  Eax, 8
      !JNZ CopyMemoryMMX
      !emms
      ProcedureReturn
    CompilerCase #PB_Processor_x64
      !PXOR mm1, mm1
      !MOV Rax, [p.v_s]
      !MOV Rcx, [p.p_memory_in]
      !MOV Rdx, [p.p_memory_out]
      !CopyMemoryMMX:
      !PXOR mm1, mm1
      !movq mm1, [Rcx]
      !movntq [Rdx], mm1
      !ADD  Rcx, 8
      !ADD  Rdx, 8
      !SUB  Rax, 8
      !JNZ CopyMemoryMMX
      !emms
      ProcedureReturn
  CompilerEndSelect 
  
EndProcedure
That is, jitter is caused by CPU cache use.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: memory tips for ultra low jitter

Post by Rescator »

A comment/response to this is found under off-topic at http://www.purebasic.fr/english/viewtop ... 17&t=61134
Post Reply