Recent

Author Topic: Assembler - logN and many more ..  (Read 12292 times)

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 674
Re: Assembler - logN and many more ..
« Reply #30 on: July 20, 2016, 12:37:04 pm »
This program prints exactly the same result when compiled with Kylix 3 (~ Delphi 6.5) and FPC 3.1.1:

Code: [Select]
fpc}
{$mode delphi}
{$endif}

function LogN( Base, X: Extended): Extended;
assembler;
asm
        FLD1
        FLD     X
        FYL2X
        FLD1
        FLD     Base
        FYL2X
        FDIV           // Lazarus Warning: fdivrp without operand translated into fdivrpP
        FWAIT
end;

begin
  writeln(logn(2,10));
end.

Result:

Code: [Select]
$ dcc tt3.pp
Borland Delphi for Linux Version 14.5
Copyright (c) 1983,2002 Borland Software Corporation
tt3.pp(22)
23 lines, 0.01 seconds, 23412 bytes code, 3132 bytes data.
$ ./tt3
 3.32192809488736E+0000


$ ppn69 ./tt3.pp
Free Pascal Compiler version 3.1.1 [2016/07/19] for i386
Copyright (c) 1993-2016 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling ./tt3.pp
tt3.pp(14,9) Warning: fdivrp without operand translated into fdivrpP
tt3.pp(14,9) Warning: "fdivrp" without operand translated into "fdivrp %st,%st(1)"
Linking tt3
21 lines compiled, 0.2 sec
2 warning(s) issued

$ ./tt3
 3.32192809488736234781E+0000

So at least FPC and Kylix 3 interpret "fdiv" in Intel-style inline assembly in exactly the same way.

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #31 on: July 20, 2016, 12:44:37 pm »
Note this guidance also means that the other way around is hardly possible: compile fpc code that contains proper FDIV into Delphi ....would lead to floating point stack corruption.
But in this case, changing Delphi sourcecode FDIV's to FDIVP's will solve it.
I have replaced the FDIV with FDIVP.

Now Lazarus (1.6) reports for FDIVP:        Warning: "fdivrp" without operand translated into "fdivrp %st,%st(1)"

What would be the proper assembler code for this in FreePascal ASM ?
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #32 on: July 20, 2016, 01:23:50 pm »
Thaddy, Jonas,

You both contributed to the solution !


Thaddy, the code I first presented, really crashes in Lazarus but not in Delphi !
=> removed  begin .. end   and added   assembler;

Jonas, I want correct code in FPC style, for the future.
=> replacing the FDIV with FDIVP is one step forward !


Thank You both !
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #33 on: September 09, 2016, 05:45:48 pm »
I am not finished with all these ancient assembler things ..
I still have some warnings with unresolved ASM instructions.


Today I found an old thread on google:
https://groups.google.com/forum/#!topic/borland.public.delphi.language.basm/pJDd8LFXVQw


Maybe this helps fixing all these old Delphi 5 code fragments, throwing

- Warning: fmulp without operand translated into fmulpP
- Warning: "faddp" without operand translated into "faddp %st,%st(1)"
- Warning: "faddp" without operand translated into "faddp %st,%st(1)"
etc ...
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #34 on: September 09, 2016, 06:21:22 pm »
Okay, in the google thread I found a INTEL statement:

".. FADD instruction:

The no operand version of the floating point add instructions always results
in the register stack being popped.  In some assemblers, the mnemonic for
this instruction is FADD rather than FADDP.

    Sentences that are virtually identical to this appear for FSUB, FMUL,
and FDIV.  What this means is that no matter how the no operand version of
the instruction is implemented, be it FADD, or FADDP, it will pop the stack.
This means that even though some assemblers choose to support the FADD
mnemonic, it will always act like the FADDP instruction.  You can expect
similar behavior for FSUB, FMUL, and FDIV."



And from another post:    FADD = FADDP = FADDP ST(1) = FADDP ST(1),ST(0)


This should make it clear, finally ..  :)
« Last Edit: September 09, 2016, 06:48:13 pm by PeterX »
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #35 on: September 09, 2016, 06:53:29 pm »
.. and these warnings from Lazarus 1.6 are the wrong text:

FADD   =>   Warning: faddp without operand translated into faddpP"

FMUL   =>   "Warning: fmulp without operand translated into fmulpP"

FSUB   =>   "Warning: fsubrp without operand translated into fsubrpP"
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #36 on: September 09, 2016, 07:32:08 pm »
When I use "FDIVP", I get

=> Warning: "fdivrp" without operand translated into "fdivrp %st,%st(1)"


When I then replace "FDIVP"   with   "fdivrp %st,%st(1)", I get

=> Fatal: illegal character "'%'" ($25)


Wrong recommendation text ?
Or because I use {$ASMMODE intel} ?
« Last Edit: September 09, 2016, 07:37:43 pm by PeterX »
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7625
Re: Assembler - logN and many more ..
« Reply #37 on: September 09, 2016, 09:14:10 pm »
I think you get a general errormessage that is for AT&T syntax.

So probably you simply need to use two operand syntax

fdivrp st1,st0

or so. I gambled that AT&T->intel required an inversion of arguments, but my copro asm is not really 100%.

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #38 on: September 10, 2016, 04:31:52 pm »
I gambled that AT&T->intel required an inversion of arguments, but my copro asm is not really 100%.
Yes, seems to be AT&T synthax.

And  "fdivp st(1), st(0)"   instead of  "fdivrp %st,%st(1)"  compiles.
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #39 on: September 17, 2016, 09:54:26 pm »
on     FSUB
I get  "Warning: fsubrp without operand translated into fsubrpP"

But to me  FSUB ST(1), ST(0)  is <>  fsubrpP
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job