Skip to content

Optimize multiplication by 3 #38

Description

@ZERICO2005

since sizeof(void*) is 3, multiplication by 3 is a very common operation. However, current codegen outputs ld bc, 3 \ call __imulu instead of shifts and adds push hl \ pop bc \ add hl, hl \ add hl, bc or push hl \ pop bc \ add hl, bc \ add hl, bc.

This may also allow a value in IY or IX to also be multiplied by 3

push hl
pop (bc|de)
add hl, hl
add hl, (bc|de)

lea (bc|de), iy
add iy, iy
add iy, (bc|de)

Other small constants like multiplying by 5 or 9 could also be turned into a series of shifts and adds.

See discussion here: https://discordapp.com/channels/432891584451706892/1478898419094519931

Activity

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

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