Skip to content

equzero and cmpequ instrinsics #34

@ZERICO2005

Description

@ZERICO2005

Currently, comparing to zero uses __*cmpzero, and checking for only equality between integers uses __*cmpu or __*cmps. Slightly faster routines that only output to the Z flag could be used instead, so I am proposing adding __*equzero and __*cmpeq.

__*cmpzero : Z P
__*equzero : Z

__*cmpu    : Z C
__*cmps    : Z P V
__*cmpeq   : Z
  • __*equzero and __*cmpeq can be emitted instead of __*cmpzero and __*cmp(u/s) when only the Z flag (or equality) is needed.
  • __*equzero can be aliased to __*cmpzero without issue.
  • __*cmpeq can be aliased to __*cmpu or __*cmps without issue.

For the most part, this is mainly a speed optimization. However, adding __llequzero and __i48equzero could be a beneficial size optimization, since the sign flag is basically never used from __llcmpzero and __i48cmpzero. So we could link just the smaller __llequzero and __i48equzero routines.

; 21 bytes
__llcmpzero:
	inc	b
	dec	b
	ret	nz
	inc.s	bc
	dec	c
	jr	nz, .p_nz
	or	a, a
	sbc	hl, bc
	jr	nz, .p_nz
	sbc	hl, de
	ret	z
	add	hl, de
.p_nz:
	inc	b
	ld	b, 0
	ret

; 15 bytes
__llequzero:
	inc	b
	dec	b
	ret	nz
	inc	c
	dec	c
	ret	nz
	add	hl, bc
	or	a, a
	sbc	hl, bc
	ret	nz
	sbc	hl, de
	add	hl, de
	ret

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions