summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2016-01-24 02:10:56 -0800
committerGravatar Yuri Kunde Schlesner2016-01-24 02:15:56 -0800
commitc1071c1ff7701e2e31dd8909a1cc58fee34c9db9 (patch)
treed20f4fd5bc59ed41a807d989ca552545bea4218e /src
parentMerge pull request #1334 from tfarley/hw-depth-modifiers (diff)
downloadyuzu-c1071c1ff7701e2e31dd8909a1cc58fee34c9db9.tar.gz
yuzu-c1071c1ff7701e2e31dd8909a1cc58fee34c9db9.tar.xz
yuzu-c1071c1ff7701e2e31dd8909a1cc58fee34c9db9.zip
Shader JIT: Fix off-by-one error when compiling JMPs
There was a mistake in the JMP code which meant that one instruction at the destination would be skipped when the jump was taken. This commit also changes the meaning of the culprit parameter to make it less confusing and avoid similar mistakes in the future.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/shader/shader_jit_x64.cpp10
-rw-r--r--src/video_core/shader/shader_jit_x64.h2
2 files changed, 6 insertions, 6 deletions
diff --git a/src/video_core/shader/shader_jit_x64.cpp b/src/video_core/shader/shader_jit_x64.cpp
index 00415e402..09a127032 100644
--- a/src/video_core/shader/shader_jit_x64.cpp
+++ b/src/video_core/shader/shader_jit_x64.cpp
@@ -653,7 +653,7 @@ void JitCompiler::Compile_IF(Instruction instr) {
653 FixupBranch b = J_CC(CC_Z, true); 653 FixupBranch b = J_CC(CC_Z, true);
654 654
655 // Compile the code that corresponds to the condition evaluating as true 655 // Compile the code that corresponds to the condition evaluating as true
656 Compile_Block(instr.flow_control.dest_offset - 1); 656 Compile_Block(instr.flow_control.dest_offset);
657 657
658 // If there isn't an "ELSE" condition, we are done here 658 // If there isn't an "ELSE" condition, we are done here
659 if (instr.flow_control.num_instructions == 0) { 659 if (instr.flow_control.num_instructions == 0) {
@@ -667,7 +667,7 @@ void JitCompiler::Compile_IF(Instruction instr) {
667 667
668 // This code corresponds to the "ELSE" condition 668 // This code corresponds to the "ELSE" condition
669 // Comple the code that corresponds to the condition evaluating as false 669 // Comple the code that corresponds to the condition evaluating as false
670 Compile_Block(instr.flow_control.dest_offset + instr.flow_control.num_instructions - 1); 670 Compile_Block(instr.flow_control.dest_offset + instr.flow_control.num_instructions);
671 671
672 SetJumpTarget(b2); 672 SetJumpTarget(b2);
673} 673}
@@ -691,7 +691,7 @@ void JitCompiler::Compile_LOOP(Instruction instr) {
691 691
692 auto loop_start = GetCodePtr(); 692 auto loop_start = GetCodePtr();
693 693
694 Compile_Block(instr.flow_control.dest_offset); 694 Compile_Block(instr.flow_control.dest_offset + 1);
695 695
696 ADD(32, R(LOOPCOUNT_REG), R(LOOPINC)); // Increment LOOPCOUNT_REG by Z-component 696 ADD(32, R(LOOPCOUNT_REG), R(LOOPINC)); // Increment LOOPCOUNT_REG by Z-component
697 SUB(32, R(LOOPCOUNT), Imm8(1)); // Increment loop count by 1 697 SUB(32, R(LOOPCOUNT), Imm8(1)); // Increment loop count by 1
@@ -717,12 +717,12 @@ void JitCompiler::Compile_JMP(Instruction instr) {
717 SetJumpTarget(b); 717 SetJumpTarget(b);
718} 718}
719 719
720void JitCompiler::Compile_Block(unsigned stop) { 720void JitCompiler::Compile_Block(unsigned end) {
721 // Save current offset pointer 721 // Save current offset pointer
722 unsigned* prev_offset_ptr = offset_ptr; 722 unsigned* prev_offset_ptr = offset_ptr;
723 unsigned offset = *prev_offset_ptr; 723 unsigned offset = *prev_offset_ptr;
724 724
725 while (offset <= stop) 725 while (offset < end)
726 Compile_NextInstr(&offset); 726 Compile_NextInstr(&offset);
727 727
728 // Restore current offset pointer 728 // Restore current offset pointer
diff --git a/src/video_core/shader/shader_jit_x64.h b/src/video_core/shader/shader_jit_x64.h
index 3afbceccf..5ad2d9606 100644
--- a/src/video_core/shader/shader_jit_x64.h
+++ b/src/video_core/shader/shader_jit_x64.h
@@ -61,7 +61,7 @@ public:
61 void Compile_MAD(Instruction instr); 61 void Compile_MAD(Instruction instr);
62 62
63private: 63private:
64 void Compile_Block(unsigned stop); 64 void Compile_Block(unsigned end);
65 void Compile_NextInstr(unsigned* offset); 65 void Compile_NextInstr(unsigned* offset);
66 66
67 void Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRegister src_reg, Gen::X64Reg dest); 67 void Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRegister src_reg, Gen::X64Reg dest);