Skip to content

Unnecessary code in Power-function #8

@vsariola

Description

@vsariola

In 4klang.asm, the lines 251-253 are:

fld1
fadd	st0	
fyl2x

I believe they do absolutely nothing to the stack and can be removed. To see this, I added some comments:

         ; Stack: x
fld1     ; Stack: 1 x
fadd st0 ; Stack: 2 x
fyl2x    ; Stack: x*log2(2)      ... which is *drumfill* just x

I think they are a left-over from a time when the power function could compute any power, not just 2^x. Also, I'm just learning x86 assembly so there could be something I'm missing here; however, I just ran some regression tests after deleting these three lines and all my regression tests seem to pass.

Also, the comments seem to be completely off, I think better comments could be:

              ; x
fld1          ; 1 x
fadd st0      ; 2 x
fyl2x         ; x // until this line could be completely removed?
fld1          ; 1 x
fld st1       ; x 1 x
fprem         ; mod(x,1) 1 x
f2xm1         ; 2^mod(x,1)-1 1 x
faddp st1,st0 ; 2^mod(x,1) x
fscale        ; 2^mod(x,1)*2^trunc(x) x
              ; Equal to:
              ; 2^x x
fstp st1      ; 2^x
ret

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions