Skip to content

optimize sign extension #43

@ZERICO2005

Description

@ZERICO2005

Here are some common patterns that can be optimized (based on usages in khicas on ez80-clang 19.1.0):

361 times:

; current
	rlc	a
	sbc	hl, hl

; optimal
	rlca
	sbc	hl, hl

97 times:

; current
	ld	l, a
	rlc	l
	sbc	hl, hl

; optimal
	rlca
	rrca ; note that this can be removed all bits in A are the same (so A = 0 or A = -1)
	sbc	hl, hl

250 times:

; current
	rlc	a
	sbc	a, a

; optimal
	rlca
	sbc	a, a

I suppose more generally, rlc a and rrc a can be transformed into rlca and rrca if only the carry flag is needed

Metadata

Metadata

Assignees

No one assigned

    Labels

    missed optimizationMissed optimizations generate correct (no bugs) but not optimal code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions