[fpc-pascal] intel vs att asm (fstp instruction) (osx/clang features)
Ched
charles.edouard.des.vastes.vignes at gmail.com
Wed May 4 22:30:45 CEST 2016
Hello,
I have something like this which seems to work very nicely
Cheers, Ched'
PROCEDURE SINCOS(CONST X: DOUBLE; VAR S, C: DOUBLE);
BEGIN
{$IFDEF NOASM}
S:=SIN(X);
C:=COS(X);
{$ELSE}
{$IFDEF VER70}
IF TEST8087=3 THEN
ASM
FLD X
DB $D9,$FB
LES DI,C
FSTP DOUBLE(ES:[DI])
LES DI,S
FSTP DOUBLE(ES:[DI])
END
ELSE
BEGIN
S:=SYSTEM.SIN(X);
C:=SYSTEM.COS(X);
END;
{$ELSE}
ASM
FLD X
FSINCOS
MOV ECX,C
FSTP DOUBLE([ECX])
MOV ECX,S
FSTP DOUBLE([ECX])
END
{$ENDIF}
{$ENDIF}
END;
Le 04.05.2016 à 10:14, Pierre Free Pascal a écrit :
> I think the correct solution for you is to use explicit size information:
>
>
>
> FSTP SINGLE PTR [EDX]
>
> FSTP SINGLE PTR [EAX]
>
>
>
> but
>
> FSTP [s]
>
> and
>
> FSTP [c]
>
> would be even better, I don’t know if this syntax is Delphi compatible or not.
>
>
>
> It seems that indeed Free Pascal does not set the size of those instruction,
>
> but seems to use single as default size for internal code generation…
>
> When generating assembler file for GNU assembler or NASM,
>
> it does not seem to print out this “assumed” size, which indeed
>
> leads to a failure using –Anasm option on trunk compiler with i386-win32 target.
>
>
>
> My GNU as version 2.26 does not seem to need an explicit size,
>
> but I don’t know what Xcode uses, isn’t it also a GNU assembler?
>
> Could you tell us which assembler is used?
>
>
>
>
>
> Pierre
>
>
>
>
>
> *De :*fpc-pascal-bounces at lists.freepascal.org [mailto:fpc-pascal-bounces at lists.freepascal.org] *De la
> part de* Dmitry Boyarintsev
> *Envoyé :* mercredi 4 mai 2016 02:28
> *À :* FPC-Pascal users discussions
> *Objet :* [fpc-pascal] intel vs att asm (fstp instruction) (osx/clang features)
>
>
>
> Hello,
>
>
>
> I'm dealing with the following code (from ZenGL library), targeting OSX
>
> ---------------
>
> {$mode delphi}
>
>
>
> procedure m_SinCos( Angle : Single; out s, c : Single ); assembler;
>
> asm
>
> FLD Angle
>
> FSINCOS
>
> FSTP [EDX]
>
> FSTP [EAX]
>
> end;
>
>
>
> var
>
> s,c: single;
>
> begin
>
> m_SinCos(0,s,c);
>
> end.
>
> ---------------
>
>
>
> The latest Xcode 7.0 tools does recognize the generated assembler (fpc trunk):
>
> ---------
>
> # [5] FLD Angle
>
> flds 8(%ebp)
>
> # [6] FSINCOS
>
> fsincos
>
> # [7] FSTP [EDX]
>
> fstp (%edx)
>
> # [8] FSTP [EAX]
>
> fstp (%eax)
>
> ---------
>
>
>
> as a problem:
>
>
>
> Assembling program
>
> test.s:21:2: error: ambiguous instructions require an explicit suffix (could be 'fstps', 'fstpl', or 'fstpt')
>
> fstp (%edx)
>
> ^
>
> test.s:23:2: error: ambiguous instructions require an explicit suffix (could be 'fstps', 'fstpl', or 'fstpt')
>
> fstp (%eax)
>
>
>
> One interested could search the internet for the problem encountered with other platforms, and find out
> that the newer clang is somewhat backward incompatible.
>
>
>
> My first attempt was to replace to put the suggested FSTPS instruction in place:
>
> FSTPS [EDX]
>
> However, the compiler stopped me, complaining about "FSTPS" is not a recognized instruction.
>
>
>
> The next approach was to rewrite the function into at&t syntax. (The actual implementation could be found
> at sincos() of RTL math unit).
>
>
>
> Is it a yet to be developed feature for FPC to satisfy demands of external tools relies on?
>
>
>
> I presume since the compiler parses intel asm and translates it into at&t asm, it should take into
> consideration requirements of the latest osx building tools.
>
> Or is it already supported and I'm just missing a compiler switch?
>
>
>
> thanks,
>
> Dmitry
>
>
>
>
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list