MCPcopy Create free account
hub / github.com/ararog/Unrar4iOS / Optimize

Method Optimize

Unrar4iOS/unrar/rarvm.cpp:776–840  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

774
775#ifdef VM_OPTIMIZE
776void RarVM::Optimize(VM_PreparedProgram *Prg)
777{
778 VM_PreparedCommand *Code=&Prg->Cmd[0];
779 uint CodeSize=Prg->CmdCount;
780
781 for (uint I=0;I<CodeSize;I++)
782 {
783 VM_PreparedCommand *Cmd=Code+I;
784
785 // Replace universal opcodes with faster byte or word only processing
786 // opcodes.
787 switch(Cmd->OpCode)
788 {
789 case VM_MOV:
790 Cmd->OpCode=Cmd->ByteMode ? VM_MOVB:VM_MOVD;
791 continue;
792 case VM_CMP:
793 Cmd->OpCode=Cmd->ByteMode ? VM_CMPB:VM_CMPD;
794 continue;
795 }
796 if ((VM_CmdFlags[Cmd->OpCode] & VMCF_CHFLAGS)==0)
797 continue;
798
799 // If we do not have jump commands between the current operation
800 // and next command which will modify processor flags, we can replace
801 // the current command with faster version which does not need to
802 // modify flags.
803 bool FlagsRequired=false;
804 for (uint J=I+1;J<CodeSize;J++)
805 {
806 int Flags=VM_CmdFlags[Code[J].OpCode];
807 if (Flags & (VMCF_JUMP|VMCF_PROC|VMCF_USEFLAGS))
808 {
809 FlagsRequired=true;
810 break;
811 }
812 if (Flags & VMCF_CHFLAGS)
813 break;
814 }
815
816 // Below we'll replace universal opcodes with faster byte or word only
817 // processing opcodes, which also do not modify processor flags to
818 // provide better performance.
819 if (FlagsRequired)
820 continue;
821 switch(Cmd->OpCode)
822 {
823 case VM_ADD:
824 Cmd->OpCode=Cmd->ByteMode ? VM_ADDB:VM_ADDD;
825 continue;
826 case VM_SUB:
827 Cmd->OpCode=Cmd->ByteMode ? VM_SUBB:VM_SUBD;
828 continue;
829 case VM_INC:
830 Cmd->OpCode=Cmd->ByteMode ? VM_INCB:VM_INCD;
831 continue;
832 case VM_DEC:
833 Cmd->OpCode=Cmd->ByteMode ? VM_DECB:VM_DECD;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected