[PICA] Implement MAX

This commit is contained in:
wheremyfoodat 2022-12-07 02:31:41 +02:00
parent ca4726aba1
commit 448f84ceb4
2 changed files with 25 additions and 0 deletions

View file

@ -24,6 +24,7 @@ void PICAShader::run() {
case ShaderOpcodes::IFC: ifc(instruction); break;
case ShaderOpcodes::IFU: ifu(instruction); break;
case ShaderOpcodes::LOOP: loop(instruction); break;
case ShaderOpcodes::MAX: max(instruction); break;
case ShaderOpcodes::MIN: min(instruction); break;
case ShaderOpcodes::MOV: mov(instruction); break;
case ShaderOpcodes::MOVA: mova(instruction); break;
@ -169,6 +170,28 @@ void PICAShader::mul(u32 instruction) {
}
}
void PICAShader::max(u32 instruction) {
const u32 operandDescriptor = operandDescriptors[instruction & 0x7f];
const u32 src1 = (instruction >> 12) & 0x7f;
const u32 src2 = (instruction >> 7) & 0x1f; // src2 coming first because PICA moment
const u32 idx = (instruction >> 19) & 3;
const u32 dest = (instruction >> 21) & 0x1f;
if (idx) Helpers::panic("[PICA] MAX: idx != 0");
vec4f srcVec1 = getSourceSwizzled<1>(src1, operandDescriptor);
vec4f srcVec2 = getSourceSwizzled<2>(src2, operandDescriptor);
vec4f& destVector = getDest(dest);
u32 componentMask = operandDescriptor & 0xf;
for (int i = 0; i < 4; i++) {
if (componentMask & (1 << i)) {
const auto mininum = srcVec1[3 - i] > srcVec2[3 - i] ? srcVec1[3 - i] : srcVec2[3 - i];
destVector[3 - i] = mininum;
}
}
}
void PICAShader::min(u32 instruction) {
const u32 operandDescriptor = operandDescriptors[instruction & 0x7f];
const u32 src1 = (instruction >> 12) & 0x7f;