Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #253: Use non-ternary varaction2 sequence for abs() builtin function #255

Merged
merged 1 commit into from
Jun 20, 2022

Conversation

JGRennison
Copy link
Contributor

This avoids the function argument being replicated in the output and being executed at run-time three times.

…n function

This avoids the function argument being replicated in the output
and being executed at run-time three times.
Copy link
Contributor

@glx22 glx22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick test by changing https://github.com/OpenTTD/nml/blob/master/regression/019_switch.nml#L10 from return 0 to return abs(current_year)

Before:

// Name: @return_action_0
4 * 107 02 0A FF 89
24 20 \dxFFFFFFFF
\2cmp 1A 20 \dx00000000
\2< 1A 20 \dx00000001
\2^ 1A 20 \dx00000001
\2sto 1A 20 \dx00000080 	// guard
\2^ 1A 20 \dx00000001
\2sto 1A 20 \dx00000081 	// !guard
\2r 7D 81 20 \dxFFFFFFFF
\2* 24 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000082
\2r 1A 20 \dx00000000
\2- 24 20 \dxFFFFFFFF
\2* 7D 80 20 \dxFFFFFFFF
\2+ 7D 82 00 \dxFFFFFFFF
\b0
\wx8000 // Return computed value

After:

// Name: @return_action_0
4 * 42 02 0A FF 89
24 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000080 	// input
\2cmp 1A 20 \dx00000000
\2- 1A 20 \dx00000001
\2* 7D 80 00 \dxFFFFFFFF
\b0
\wx8000 // Return computed value

And this was a very simple expression, I can see how it's even better for size and execution with a complex expression.

@glx22 glx22 merged commit 434327e into OpenTTD:master Jun 20, 2022
@JGRennison JGRennison deleted the fix-253 branch June 20, 2022 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants