From 4861c8b7ed22c4b86177c05eea60796a039a7fc1 Mon Sep 17 00:00:00 2001 From: daniel Date: Sat, 21 Jul 2007 15:32:15 +0000 Subject: [PATCH] * Convert clongdouble from double <=> quadruple on non-x86. git-svn-id: trunk@8114 - --- rtl/inc/ctypes.pp | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/rtl/inc/ctypes.pp b/rtl/inc/ctypes.pp index f18ab10b62..0707f3705f 100644 --- a/rtl/inc/ctypes.pp +++ b/rtl/inc/ctypes.pp @@ -76,7 +76,8 @@ type {$ifdef windows} clongdouble=double; {$else} - {$define longdouble_assignment_overload} + {$ifdef x86} + {$define longdouble_assignment_overload_real80} clongdouble = packed record value:extended; {$ifdef defined(cpu64) or defined(darwin)} @@ -85,6 +86,10 @@ type padding:array[0..1] of byte; {$endif} end; + {$else} + {$define longdouble_assignment_overload_real128} + clongdouble = packed array [0..15] of byte; + {$endif} {$endif} Pclongdouble=^clongdouble; @@ -94,14 +99,20 @@ type {$endif} -{$ifdef longdouble_assignment_overload} +{$ifdef longdouble_assignment_overload_real80} operator := (const v:clongdouble):r:extended; operator := (const v:extended):r:clongdouble; {$endif} +{$ifdef longdouble_assignment_overload_real128} +{Non-x86 typically doesn't have extended. To be fixed once this changes.} +operator := (const v:clongdouble):r:double; +operator := (const v:double):r:clongdouble; +{$endif} + implementation -{$ifdef longdouble_assignment_overload} +{$ifdef longdouble_assignment_overload_real80} operator := (const v:clongdouble):r:extended;inline; begin @@ -115,4 +126,29 @@ begin end; {$endif} +{$ifdef longdouble_assignment_overload_real128} + +{$ifdef ENDIAN_LITTLE} +const r128_mantissa_ofs=0; + r128_exponent_ofs=14; +{$else} +const r128_mantissa_ofs=2; + r128_exponent_ofs=0; +{$endif} + +operator := (const v:clongdouble):r:double;inline; + +begin + qword(r):=(qword(Pword(@v[r128_exponent_ofs])^) shl 52) or + (Pqword(@v[r128_mantissa_ofs])^ shr 12); +end; + +operator := (const v:double):r:clongdouble;inline; + +begin + Pword(@r[r128_exponent_ofs])^:=qword(v) shr 52; + Pqword(@r[r128_mantissa_ofs])^:=qword(v) shl 12; +end; +{$endif} + end.