Skip to content

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.

3 participants