-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
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
Labels
No labels