home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Programming / vbcc_MorphOS / doc / vbccppc.doc < prev    next >
Text File  |  2000-08-20  |  8KB  |  224 lines

  1. vbcc - C compiler (c) in 1995-2000 by Volker Barthelmann
  2.  
  3.  
  4. INTRODUCTION
  5.  
  6.     vbcc is a free portable and retargetable ANSI C compiler.
  7.     It is clearly split into a target independant and a target dependant
  8.     part and supports emulating datatypes of the target machine on any
  9.     other machine so that it is possible to e.g. make a crosscompiler for
  10.     a 64bit machine on a 32bit machine.
  11.     This document only deals with the target dependant parts of the
  12.     PowerPC version.
  13.  
  14.  
  15. LEGAL
  16.  
  17.     vbccppc is (c) in 1995-2000 by Volker Barthelmann.
  18.     This is a development snapshot which must not be distributed.
  19.     Commercial usage is forbidden.
  20.  
  21.  
  22. ADDITIONAL OPTIONS FOR THIS VERSION
  23.  
  24.     -merge-constants
  25.  
  26.                 Place identical floating point constants at the same
  27.                 memory location. This can reduce program size and increase
  28.                 compilation time.
  29.  
  30.     -const-in-data
  31.  
  32.                 By default constant data will be placed in the .rodata
  33.                 section. Using this option it will be placed in the data
  34.                 section.
  35.                 Note that on operating systems with memory protection this
  36.                 option will disable write-protection of constant data.
  37.  
  38.     -fsub-zero
  39.  
  40.                 Use fsub to load a floating-point-register with zero.
  41.                 This is faster but requires all registers to always contain
  42.                 valid values (i.e. no NaNs etc.) which may not be the case
  43.                 depending on startup-code, libraries etc.
  44.  
  45.     -amiga-align
  46.  
  47.                 Do not require any alignments greater than 2 bytes.
  48.                 This is needed when accessing Amiga system-structures, but
  49.                 can cause a performance penalty.
  50.  
  51.     -elf
  52.  
  53.                 Do not prefix symbols with '_'. Prefix labels with '.'.
  54.  
  55.     -poweropen
  56.  
  57.                 Generate code for the PowerOpen ABI like used in AIX.
  58.                 This does not work correctly yet.
  59.  
  60.     -sc
  61.  
  62.                 Generate code for the modified PowerOpen ABI used in the
  63.                 StormC compiler.
  64.  
  65.     -no-regnames
  66.  
  67.                 Do not use register names but only numbers. This is necessary
  68.                 to avoid name-conflicts when using -elf.
  69.  
  70.     -setccs
  71.  
  72.                 The V.4 ABI requires that when varargs-functions are called
  73.                 with arguments passed in the floating-point registers this
  74.                 has to be signalled in a certain bit of the condition code
  75.                 register. vbcc usually doesn't make use of this and
  76.                 therefore does not care about that bit by default.
  77.                 This may lead to problems if you link objects compiled by
  78.                 vbcc to objects not compiled by vbcc (e.g. a different
  79.                 C-library) and call varargs-functions with floating-point
  80.                 arguments.
  81.                 In this case -setccs might help.
  82.  
  83.     -peephole
  84.  
  85.                 Perform several peephole optimizations. Currently includes:
  86.                  - better use of d16(r) addressing
  87.                  - use of indexed addressing modes
  88.                  - use of update-flag
  89.                  - use of record-flag
  90.                  - use of condition-code-registers to avoid certain branches
  91.  
  92.     -use-lmw
  93.  
  94.                 Use lmw/stmw-instructions. This can significantly reduce
  95.                 code-size. However these instructions may be slower on
  96.                 certain PPCs.
  97.  
  98.     -madd
  99.  
  100.                 Use the fmadd/fmsub instructions for combining
  101.                 multiplication with addition/subtraction in one instruction.
  102.                 As these instructions do not round between the operations,
  103.                 the have increased precision over separate addition and
  104.                 multiplication.
  105.                 While this usually does no harm, it is not ISO conforming
  106.                 and therefore not the default behaviour.
  107.  
  108.  
  109. SOME INTERNALS
  110.  
  111.     The current version generates assembly output for use with the "pasm"
  112.     assembler by Frank Wille. The generated code should work on 32bit systems
  113.     based on a PowerPC CPU using the V.4 ABI.
  114.  
  115.     The register names are:
  116.  
  117.         r0 through r31 for the general purpose registers,
  118.         f0 through f31 for the floating point registers and
  119.         cr0 through cr7 for the condition-code registers.
  120.  
  121.     The registers r0, r3-r12, f0-f13 and cr0-cr1 are used as scratch registers
  122.     (i.e. they can be destroyed in function calls), all other registers are
  123.     preserved. r1 is the stack-pointer and r13 is the small-data-pointer if
  124.     small-data-mode is used.
  125.  
  126.     The first 8 function arguments which have integer or pointer types
  127.     are passed in registers r3 through r10 and the first 8 floating-point
  128.     arguments are passed in registers f1 through f8. All other arguments
  129.     are passed on the stack.
  130.  
  131.     Integers and pointers are returned in r3, floats and doubles in f1.
  132.     All other types are returned by passing the function the address
  133.     of the result as a hidden argument - so when you call such a function
  134.     without a proper declaration in scope you can expect a crash.
  135.  
  136.     The elementary data types are represented like:
  137.  
  138.     type        size in bits        alignment in bytes (-amiga-align)
  139.  
  140.     char                8                       1 (1)
  141.     short              16                       2 (2)
  142.     int                32                       4 (2)
  143.     long               32                       4 (2)
  144.     all pointers       32                       4 (2)
  145.     float              32                       4 (2)
  146.     double             64                       8 (2)
  147.  
  148.  
  149. TARGET-SPECIFIC VARIABLE ATTRIBUTES
  150.  
  151.     The m68k-backend offers the following variable attributes:
  152.  
  153.     __saveds:   Load the pointer to the small data segment at
  154.                 function-entry. Applicable only to functions.
  155.  
  156.     __chip:     Place variable in chip-memory. Only applicable on
  157.                 AmigaOS to variables with static storage-duration.
  158.  
  159.     __far:      Do not place this variable in the small-data segment
  160.                 in small-data-mode. No effect in large-data-mode.
  161.                 Only applicable to variables with static storage-
  162.                 duration.
  163.  
  164.     __near:     Currently ignored.
  165.  
  166.  
  167. STDARG
  168.  
  169.     A possible <stdarg.h> for V.4 ABI could look like this:
  170.  
  171.     typedef struct {
  172.       int gpr;
  173.       int fpr;
  174.       char *regbase;
  175.       char *membase;
  176.     } va_list;
  177.  
  178.     char *__va_start(void);
  179.     char *__va_regbase(void);
  180.     int __va_fixedgpr(void);
  181.     int __va_fixedfpr(void);
  182.  
  183.     #define va_start(vl,dummy) \
  184.       ( \
  185.         vl.gpr=__va_fixedgpr(), \
  186.         vl.fpr=__va_fixedfpr(), \
  187.         vl.regbase=__va_regbase(), \
  188.         vl.membase=__va_start() \
  189.       )
  190.  
  191.     #define va_end(vl) (vl.regbase=vl.membase=0)
  192.  
  193.     #define __va_size(type) ((sizeof(type)+3)/4*4)
  194.     #define va_arg(vl,type) \
  195.       (__typeof(type)&15)>8? \
  196.         (vl.membase+=__va_size(type),((type*)vl.membase)[-1]) \
  197.       : \
  198.        ( \
  199.         (((__typeof(type)&15)==5||(__typeof(type)&15)==6)) ? \
  200.          ( \
  201.           ++vl.fpr<=8 ? \
  202.              ((double*)(vl.regbase+32))[vl.fpr] \
  203.           : \
  204.             (vl.membase+=__va_size(type),((type*)vl.membase)[-1]) \
  205.          ) \
  206.         : \
  207.          ( \
  208.           ++vl.gpr<=8 ? \
  209.             ((int*)(vl.regbase+0))[vl.gpr] \
  210.           : \
  211.             (vl.membase+=__va_size(type),((type*)vl.membase)[-1]) \
  212.          ) \
  213.        ) \
  214.  
  215.  
  216. KNOWN PROBLEMS
  217.  
  218.     - composite types are put on the stack rather than passed via pointer
  219.     - indication of fp-register-args with bit 6 of cr is not done well
  220.  
  221.  
  222. Volker Barthelmann                                      volker@vb.franken.de
  223.  
  224.