Recent

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

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Assembler - logN and many more ..
« on: July 18, 2016, 10:08:21 pm »
Hi all,

there's no sub forum for Assembler questions here ..
.. which means, only a very few people
are working on assembler code in FPC / LCL  ?


I need some mathematical functions such as logN:
( Log.N(X) := Log.2(X) / Log.2(N) )


From which sources can I learn how to write
working FPC / LCL assembler code to make my functions work ?

Thanks,
Peter


The following code works in Delphi 5, but not in Lazarus (1.6).

-----------------------------------------------------
function LogN( Base, X: Extended): Extended;
{$ifdef FPC} begin {$ASMMODE intel} {$endif}
asm
        FLD1
        FLD     X
        FYL2X
        FLD1
        FLD     Base
        FYL2X
        FDIV           // Lazarus Warning: fdivrp without operand translated into fdivrpP
        FWAIT
end;
{$ifdef FPC} end; {$endif}


« Last Edit: July 18, 2016, 10:17:07 pm by PeterX »
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 674
Re: Assembler - logN and many more ..
« Reply #1 on: July 19, 2016, 08:02:22 pm »
Are you compiling that code in a unit that uses {$mode delphi}? When using Delphi code, always compile using {$mode delphi}.

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #2 on: July 19, 2016, 10:27:03 pm »
Oh, yes, I compile with {$mode objfpc}{$H+}

Does this have an influence on how the assembler code is compiled ?
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 674
Re: Assembler - logN and many more ..
« Reply #3 on: July 19, 2016, 10:30:16 pm »
It influences whether or need you need to use the "assembler" modifier for a pure assembly routine. It does not change how the inline assembly gets parsed.

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #4 on: July 19, 2016, 10:35:00 pm »
Okay, because I switched back to DELPHI mode and the error messages are the same :

FDIV:
- Warning: fdivrp without operand translated into fdivrpP
- Warning: "fdivrp" without operand translated into "fdivrp %st,%st(1)"
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 674
Re: Assembler - logN and many more ..
« Reply #5 on: July 19, 2016, 10:38:21 pm »
Those are not errors. They are warnings. If the resulting code has different behaviour in Delphi and FPC, please file a bug report at http://bugs.freepascal.org

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #6 on: July 19, 2016, 10:39:44 pm »
Are You sure ?
This is an old Dephi 5 project ..
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 674
Re: Assembler - logN and many more ..
« Reply #7 on: July 19, 2016, 10:40:23 pm »
Am I sure about what?

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #8 on: July 19, 2016, 10:42:55 pm »
Well, did Borland / Inprise / Embarcadero probably change the synthax of assembler over the years ?
I have no possibilities to verify this assembler code in an actual Delphi compiler ..
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 674
Re: Assembler - logN and many more ..
« Reply #9 on: July 19, 2016, 10:44:17 pm »
I did not say they changed the behaviour. I said to file a bug report with FPC if the behaviour is different in Delphi compared to FPC.

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #10 on: July 19, 2016, 10:46:33 pm »
Okay, no problem.

I'll file a bug report.

But often I get the answer - "it is as it is".


Is out there any table that translates DELPHI assembler  to AT&T or intel assembler ?
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 674
Re: Assembler - logN and many more ..
« Reply #11 on: July 19, 2016, 10:48:01 pm »
Delphi only supports Intel-style assembly. I.e., Intel-style assembly in FPC should behave the same as the assembly in Delphi.

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Assembler - logN and many more ..
« Reply #12 on: July 19, 2016, 10:49:35 pm »
Delphi only supports Intel-style assembly. I.e., Intel-style assembly in FPC should behave the same as the assembly in Delphi.
Okay, I take Your word .. ;-)
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 #13 on: July 19, 2016, 10:51:58 pm »
Bug report:

Under "Category " there is no option "Assembler"  .. :-(
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 674
Re: Assembler - logN and many more ..
« Reply #14 on: July 19, 2016, 10:52:30 pm »
It's part of the compiler.