It is currently Wed Jan 20, 2021 4:24 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Shifting bits in an arbitrary number of bytes
PostPosted: Sat Jun 21, 2014 1:09 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 5:38 am
Posts: 254
Location: Australia
I found it, I had to dec ecx immediately before the jump condition test, because of the zero flag I'm assuming. Well encryption is already 80% faster with just these simple changes, I don't know if I need to work on more optimisations since RSA is falling out of use to ECC these days.


Top
 Profile  
Reply with quote  
 Post subject: Re: Shifting bits in an arbitrary number of bytes
PostPosted: Fri Oct 03, 2014 1:44 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
A faster implementation of the two procedures ...
Code:
Procedure ShiftLeftBuffer(*data, length.l)
  !xor eax, eax
  !mov ecx, [p.v_length]
  !dec ecx
  !jc slb_exit
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov rdx, [p.p_data]
    !slb_loop: 
    !mov ah, [rdx + rcx]
    !shl eax, 1
    !mov [rdx + rcx], ah
  CompilerElse
    !mov edx, [p.p_data]
    !slb_loop: 
    !mov ah, [edx + ecx]
    !shl eax, 1
    !mov [edx + ecx], ah
  CompilerEndIf
  !shr eax, 9
  !sub ecx, 1
  !jnc slb_loop
  !slb_exit:
  !shr eax, 7
  ProcedureReturn
EndProcedure

Procedure ShiftRightBuffer(*data, length.l)
  !xor eax, eax
  !mov ecx, [p.v_length]
  !and ecx, ecx
  !jz srb_exit
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov rdx, [p.p_data]
    !srb_loop: 
    !mov ah, [rdx]
    !shr eax, 1
    !mov [rdx], ah
    !inc rdx
  CompilerElse
    !mov edx, [p.p_data]
    !srb_loop: 
    !mov ah, [edx]
    !shr eax, 1
    !mov [edx], ah
    !inc edx
  CompilerEndIf 
  !shl eax, 9
  !dec ecx
  !jnz srb_loop
  !srb_exit:
  !shr eax, 16
  !and eax, 1
  ProcedureReturn
EndProcedure

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Shifting bits in an arbitrary number of bytes
PostPosted: Thu Dec 04, 2014 12:56 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 5:38 am
Posts: 254
Location: Australia
Thanks I have been doing some testing and noticed it doesn't help with my large number module any more, so I will have to optimise some more. I've noticed that all the time is spent on this:

Code:
      While i
        i=i-1
        If j
          j=j-1
          sum = PeekA(*h1\num+i) + PeekA(*h2\num+j) + carry
        Else
          sum = PeekA(*h1\num+i) + carry
        EndIf
        If sum > $FF : carry = 1 : Else : carry = 0 : EndIf
        PokeA(*h1\num+i, sum)
      Wend


so looks like I'll have to delve into assembly again


Top
 Profile  
Reply with quote  
 Post subject: Re: Shifting bits in an arbitrary number of bytes
PostPosted: Thu Dec 04, 2014 6:10 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
coco2 wrote:
Thanks I have been doing some testing and noticed it doesn't help with my large number module any more, so I will have to optimise some more. I've noticed that all the time is spent on this:

You could already speed this up a lot without using asm.
I wanted to try something with you huge.pbi code to improve the speed but your code depends on cc2debug.pbi and it looks like you didn't post that code.

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Shifting bits in an arbitrary number of bytes
PostPosted: Thu Dec 04, 2014 10:07 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 5:38 am
Posts: 254
Location: Australia
This one?

Code:
Macro DebugOut(DebugText)
  Debug #PB_Compiler_Module+"::"+#PB_Compiler_Procedure+": "+DebugText
EndMacro

Macro DebugPrintN (DebugText)
  PrintN(#PB_Compiler_Module+"::"+#PB_Compiler_Procedure+": "+DebugText)
EndMacro


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye