Difference between revisions of "FPC HowToDo"

From Lazarus wiki
(Adding dynlinking)
(Dynamic linking + finalization)
Line 28: Line 28:
  
 
* '''Required for''': Implement decent finalization and initialization of dynamic libraries and avoid random behaviour due to bad duplicate symbol resolving.
 
* '''Required for''': Implement decent finalization and initialization of dynamic libraries and avoid random behaviour due to bad duplicate symbol resolving.
* '''Platforms implemented''': win32, Darwin/i386 (Solaris?)
+
* '''Platforms implemented''': win32, Darwin  (Solaris?)
 
* '''Platforms Todo''': FreeBSD, Linux and all platforms with a flat linker space in general.
 
* '''Platforms Todo''': FreeBSD, Linux and all platforms with a flat linker space in general.
 
* '''Generic usable routines''': Probably requires link.res magic. Also test with -Bsymbolic
 
* '''Generic usable routines''': Probably requires link.res magic. Also test with -Bsymbolic

Revision as of 14:33, 9 December 2007

This page provides an overview of features, both mandatory and optional, which have been implemented/tested on at least one platform, but which still have to or could be added for other platforms.


Mandatory

Widestring manager

  • Required for: proper functioning of locale-dependent widestring and ansistring operations (assignments, comparisons)
  • Platforms implemented: Windows, unix (partially: assignments and some comparisons)
  • Platforms Todo: unix (comparisons), OS/2, symbian, macos9, morphos, netware
  • Generic usable routines: rtl/inc/wstringh.inc, rtl/inc/wustring.inc
  • What: implement widestring manager helpers. Add them to your system unit if they can be linked into any binary, or into a unit called "cwstring" if they depend on an external library on which programs should not depend by default. If added to the system unit, also define FPC_NOGENERICANSIROUTINES at the top of your platform's sysutils unit.
  • Existing implementations: win{32,64,ce}/system.pp (complete? -- search for widestringmanager), rtl/unix/cwstring.pp (partial)
  • Tests: tests/test/twide*.pp and some in tests/tbs and tests/webtbs. Mostly not available and still need to be written.


i386/arm fpu/sse initialisation

  • Required for: initialising global variables indicating the presence of certain fpu types, so that the fpu exception masking routines also adjust the exception masks of these fpus.
  • Platforms implemented: win32, Linux, FreeBSD/i386, Darwin/i386
  • Platforms Todo: wince, OS/2, BeOS
  • Generic usable routines: rtl/i386/i386.inc (fpc_cpucodeinit), rtl/arm/arm.inc (fpc_cpucodeinit)
  • What: call fpc_cpucodeinit in your system unit's initialisation code, and catch the potential "illegal instruction" exception in your exception/signal handler, checking/setting a global variable in the process indicating lacking support for the tested fpu type
  • Existing implementations: rtl/win32/system.pp (search for os_supports_sse and fpc_cpucodeinit), rtl/linux/system.pp and rtl/linux/arm/sighnd.inc and rtl/linux/i386/sighnd.inc (idem), rtl/bsd/system.pp and rtl/freebsd/i386/sighnd.inc (idem)
  • Tests: tests/test/units/math/tmask*.pp compiled with -Cfsse2 (i386) or with -Cf{fpa,fpa10,fpa11} (arm)

Dynamic linking + finalization

  • Required for: Implement decent finalization and initialization of dynamic libraries and avoid random behaviour due to bad duplicate symbol resolving.
  • Platforms implemented: win32, Darwin (Solaris?)
  • Platforms Todo: FreeBSD, Linux and all platforms with a flat linker space in general.
  • Generic usable routines: Probably requires link.res magic. Also test with -Bsymbolic
  • What:  ???
  • Existing implementations: Existing targets don't have a flat linker space over binary + dyn libs, and thus are "easier"
  • Tests: Most dynlinking on Linux mantis issues. E.g. http://www.freepascal.org/mantis/view.php?id=8397

Optional

Compiler optimizations

(u)int32x(u)int32 to (u)int64 multiplication

  • Required for: optimizing 32x32->64 bit multiplications (several 32 bit architectures can do this without needing to perform a full 64 bit multiplication)
  • Platforms implemented: PowerPC 32
  • Platforms Todo: all other 32 bit architectures
  • Generic routines: compiler/nadd.pas (use_generic_mul32to64/first_add64bitint/try_make_mul32to64)
  • What: override taddnode.use_generic_mul32to64 and let it return false, then add support to your architecture's muln handler for performing signed and unsigned 32 bit int to signed/unsigned 64 bit int multiplications (i.e., left.resultdef and right.resultdef = 32 bit ints, self.resultdef = 64 bit int)
  • Existing implementations: compiler/powerpc/ncpuadd.pas (second_add64bit, search for MULHW/MULHWU)
  • Tests: tests/test/cg/tmul3264.pp
  • Notes: does not occur much in at least the rtl/compiler code base

Bit(field) getting/setting primitives

  • Required for: being able to use the generic tcginnode code and still getting (close to) optimal code, faster record register variables and faster bitpacked records/arrays
  • Platforms implemented: PowerPC 32/64
  • Platforms Todo: all other architectures
  • Generic routines: compiler/cgobj.pas (a*subsetreg, a*subsetref, a_bit_test*)
  • What: override (some of) the subsetreg/subsetref routines to use architecture-specific opcodes for setting/getting bits and/or bitfields (the a_bit_test* routines mostly use the subsetref/reg routines under the hood, except for a_bit_test_reg_reg_reg, so in general it's better to implement special cases for the subsetreg/ref routines as these are used in more cases)
  • Existing implementations: compiler/ppcgen/cgppc.pas (a_load_subsetref_regs_noindex), compiler/powerpc/cgcpu.pas (a_load_subsetreg_reg, a_load_subsetreg_subsetreg, a_load_regconst_subsetreg_intern), compiler/powerpc64/cgcpu.pas (a_load_subsetreg_reg, a_load_const_subsetreg, a_load_regconst_subsetreg_intern)
  • Tests: tests/test/tparray*.pp, tests/test/tprec*.pp, tests/test/trecreg*.pp