Skip to content

Optimized _MultiplyHLBC #595

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Optimized _MultiplyHLBC #595

wants to merge 1 commit into from

Conversation

ZERICO2005
Copy link
Contributor

I was comparing __imulu to _MultiplyHLBC. Since there is no branching in either routine, I could remove instructions that were common to both routines. I then found that __imulu is faster and smaller. With the only difference being that it preserves AF, while _MultiplyHLBC destroys AF.

__imulu
	; 7 bytes + 7F + 6R + 3W
	push	af
	add	a, h
	ld	d, b
	ld	d, a
	ld	e, c
	pop	de
	pop	af

_MultiplyHLBC:
	; 18 bytes + 18F + 3R + 3W
	push	iy
	ld	iy, 0
	add	iy, de
	add	iy, de
	inc	sp
	ld	c, 0
	lea	hl, iy + 0
	pop	iy

Based on this, _MultiplyHLBC has been replaced with the code for __imulu. It seems like A doesn't need to be preserved based on the routines that use _MultiplyHLBC, so it seems safe to comment out push af \ pop af.

In total this should remove 13 bytes + 13F + 3W from _MultiplyHLBC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants