[decompiler] More inline vector functions (#3861)

This adds more recognition for inlined vector functions to the
decompiler, which can clean up a bunch of ugly looking code/`rlet`s.


![image](https://github.com/user-attachments/assets/1f7b4627-81bd-481b-b828-76b9f7ba13b3)

Unfortunately, this changes the numbering of ops in the decomp, since
all the vector instructions get combined in a single "operation" by the
decompiler. I really tried to avoid having this ever happen in the
decompiler and this is one of the few cases where it has. So I had to
update a bunch of type casts.

For that reason I haven't turned this on in Jak 2 yet, although I am
planning to do that at some point. (probably at the same time as porting
back a bunch of jak 3 improvements to jak 2)

---------

Co-authored-by: water111 <awaterford1111445@gmail.com>
This commit is contained in:
water111
2025-02-16 15:59:17 -05:00
committed by GitHub
parent b07d0d9ced
commit 2a4d3d7a4a
340 changed files with 22771 additions and 36134 deletions
+13 -4
View File
@@ -1652,6 +1652,7 @@ void SimpleExpressionElement::update_from_stack_vector_plus_float_times(
const Env& env,
FormPool& pool,
FormStack& stack,
FixedOperatorKind op,
std::vector<FormElement*>* result,
bool allow_side_effects) {
std::vector<Form*> popped_args = pop_to_forms({m_expr.get_arg(0).var(), m_expr.get_arg(1).var(),
@@ -1668,9 +1669,8 @@ void SimpleExpressionElement::update_from_stack_vector_plus_float_times(
}
auto new_form = pool.alloc_element<GenericElement>(
GenericOperator::make_fixed(FixedOperatorKind::VECTOR_PLUS_FLOAT_TIMES),
std::vector<Form*>{popped_args.at(0), popped_args.at(1), popped_args.at(2),
popped_args.at(3)});
GenericOperator::make_fixed(op), std::vector<Form*>{popped_args.at(0), popped_args.at(1),
popped_args.at(2), popped_args.at(3)});
result->push_back(new_form);
}
@@ -2585,8 +2585,17 @@ void SimpleExpressionElement::update_from_stack(const Env& env,
update_from_stack_vectors_in_common(FixedOperatorKind::VECTOR_LENGTH, env, pool, stack,
result, allow_side_effects);
break;
case SimpleExpression::Kind::VECTOR_LENGTH_SQUARED:
update_from_stack_vectors_in_common(FixedOperatorKind::VECTOR_LENGTH_SQUARED, env, pool,
stack, result, allow_side_effects);
break;
case SimpleExpression::Kind::VECTOR_PLUS_FLOAT_TIMES:
update_from_stack_vector_plus_float_times(env, pool, stack, result, allow_side_effects);
update_from_stack_vector_plus_float_times(
env, pool, stack, FixedOperatorKind::VECTOR_PLUS_FLOAT_TIMES, result, allow_side_effects);
break;
case SimpleExpression::Kind::VECTOR_PLUS_TIMES:
update_from_stack_vector_plus_float_times(
env, pool, stack, FixedOperatorKind::VECTOR_PLUS_TIMES, result, allow_side_effects);
break;
default:
throw std::runtime_error(