home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / os2 / pgp263.arj / PGP263I.SRC / PGP263II.ZIP / src / platform.h < prev    next >
C/C++ Source or Header  |  1996-01-06  |  11KB  |  328 lines

  1. /*    platform.h - computer platform customization for PGP
  2.     multiprecision math package.  #Included in mpilib.h.
  3. */
  4. #ifndef PLATFORM_H
  5. #define PLATFORM_H
  6.  
  7. /* Platform customization:
  8.  * A version which runs on almost any computer can be implemented by
  9.  * defining PORTABLE and MPORTABLE, preferably as a command line
  10.  * parameter.  Faster versions can be generated by specifying specific
  11.  * parameters, such as size of unit and MULTUNIT, and by supplying some
  12.  * of the critical in assembly.  
  13.  *
  14.  * This file holds customizations for different environments.
  15.  * This is done in one of two ways:
  16.  *    1. A symbol is defined on the command line which designates a 
  17.  *    particular environment, such as MSDOS.  This file detects the 
  18.  *    environment symbol and sets the appropriate low-level defines.
  19.  *
  20.  *    2. If no environment is named, the low-level defines are set in
  21.  *    the same manner as for PGP 2.0, thereby providing an easy upgrade.
  22.  *
  23.  * Following are a description of the low-level definition symbols:
  24.  *
  25.  * The following preprocessor symbols should be conditionally set to 
  26.  * optimize for a particular environment.
  27.  *
  28.  * Define one of the following:
  29.  *    UNIT8, UNIT16, or UNIT32    - specifies size of operands for
  30.  *    multiprecision add, subtract, shift, and initialization operations.
  31.  * Define one of the following:
  32.  *    MUNIT8, MUNIT16, MUNIT32    - specified size of operands for 
  33.  *    multiprecision multiply and mod_mult.  This must be less than or
  34.  *    equal to unit size.  It should be the word size for the native
  35.  *    atomic multiply instruction.  For a 16x16 bit multiply yielding a
  36.  *    32-bit product, MUNIT16 should be set.
  37.  * Define one (or more) of the following:
  38.  *    PEASANT, MERRITT, UPTON, SMITH    -algorithm used for modmult.All defined
  39.  *    algorithms are compiled, but the first defined name listed will be 
  40.  *    assigned to the generic entry point symbols.  Multiple algorithms are
  41.  *    used primarily for testing.
  42.  * HIGHFIRST - specified if longs are stored with the most significant
  43.  *    bit at the lowest address (Motorola), undefined otherwise.  This should
  44.  *    be defined on the command line, normally in the makefile.
  45.  *
  46.  * The following symbol, if initialized, is set to specific values:
  47.  * ALIGN - variable declaration attribute which forces optimum alignment
  48.  *    of words, e.g. for VAX C: ALIGN=_align(quadword)
  49.  *
  50.  * The following symbols correspond to individual multiprecision routines
  51.  * that may be implemented with assembly language.  If they are implemented
  52.  * in assembly, the symbols should be defined with the name of the
  53.  * corresponding external entry points, e.g., mp_addc=P_ADDC
  54.  *    mp_setp        - set precision for external routines
  55.  *    mp_addc        - add with carry
  56.  *    mp_subb        - subtract with borrow
  57.  *    mp_rotate_left - rotate left
  58.  *    mp_compare     - compare
  59.  *    mp_move        - move
  60.  *    unitfill0      - zero fill
  61.  *    mp_smul        - multiply vector by single word *
  62.  *    mp_smula       - multiply vector by single word and accumulate *
  63.  *    mp_dmul        - full multiply 
  64.  *    mp_set_recip   - setup for mp_quo_digit
  65.  *    mp_quo_digit   - quotient digit for modulus reduction
  66.  *
  67.  * Either mp_smul or mp_smula should be defined.  mp_smula provides
  68.  * for accumulation to an existing value, while mp_smul is for use of the
  69.  * older definition of mp_smul, used in PGP 2.0, which assumed that the high 
  70.  * order accumulator word is zero.   Use of mp_smula causes one less word of 
  71.  * precision to be used, thereby slightly increasing speed.
  72.  */
  73.  
  74. /********************************************************************
  75.  * Environment customization.  Please send any additions or corrections
  76.  * to Philip Zimmermann.
  77.  */
  78. #ifndef PORTABLE
  79.  
  80. #ifdef MSDOS
  81. #ifndef i386 /* gcc */
  82. #define UNIT16
  83. #define MUNIT16
  84. #define mp_setp        P_SETP
  85. #define mp_addc        P_ADDC
  86. #define mp_subb        P_SUBB
  87. #define mp_rotate_left    P_ROTL
  88. #define mp_smula    P_SMULA
  89. #define mp_quo_digit    P_QUO_DIGIT
  90. #define mp_set_recip    P_SETRECIP
  91. #define SMITH
  92. #define PLATFORM_SPECIFIED
  93. #endif /* i386 */
  94. #endif /* MSDOS */
  95.  
  96. #ifdef VMS
  97.  
  98. #ifdef __DECC
  99. #define _VMS_DECC    /* Compiler is DECC */
  100. #ifdef __alpha
  101. #define _VMS_ALPHA    /* Platform alpha */
  102. #define _VMS_T_PLATFORM "DECC/Alpha"
  103. #endif
  104. #ifdef __vax
  105. #define _VMS_VAX    /* Platform VAX */
  106. #define _VMS_T_PLATFORM "DECC/VAX"
  107. #endif
  108. #else            /* #ifdef __DECC */
  109. #ifdef VAXC
  110. #define _VMS_VAX    /* Platform _must_ be VAX for VAXC w/o __DECC */
  111. #define _VMS_VAXC    /* Compiler _is_ VAXC */
  112. #define _VMS_T_PLATFORM "VAXC/VAX"
  113. #endif            /* #ifdef VAXC */
  114. #endif            /* #else (#ifdef __DECC) */
  115.  
  116. #define UNIT32         /* use 32-bit units */
  117. #define MUNIT16        /* not used in C code, only in assembler */
  118. #define UPTON
  119. #ifndef __ALPHA
  120. #define mp_setp        p_setp
  121. #define mp_addc        p_addc
  122. #define mp_subb        p_subb
  123. #define mp_rotate_left    p_rotl
  124. #define mp_smul    p_smul
  125. #define mp_dmul    p_dmul
  126. #define mp_compare    p_cmp
  127. #endif
  128. #define ALIGN _align(quadword)
  129.  
  130. #pragma builtins
  131. #ifdef __DECC
  132. #define mp_move( dst, src)  memcpy((char *) dst,(char *) src, global_precision*4)
  133. #define unitfill0( r, unitcount) memset( (char *) r, 0, unitcount*4)
  134. #define mp_burn(r) memset( (char *) r, 0, global_precision*4)
  135. #define mp_init0(r) mp_burn(r)    /* Just for documentation purposes */
  136. #else
  137. #define mp_move( dst, src)  _MOVC3( global_precision*4, (char *) src, (char *) dst)
  138. #define unitfill0( r, unitcount) _MOVC5( 0, (char *) 0, 0, unitcount*4, (char *) r)
  139. #define mp_burn(r) _MOVC5(0, (char *) 0, 0, global_precision*4, (char *) r)
  140. #define mp_init0(r) mp_burn(r)    /* Just for documentation purposes */
  141. #endif    /* __DECC */
  142.  
  143. #define PLATFORM_SPECIFIED
  144. #endif            /* #ifdef VMS */
  145.  
  146. #if defined(mips) || defined(__mips)
  147. /*
  148.  * Needs r3kd.s and r3000.s (or r3000.c)
  149.  */
  150. #define UNIT32
  151. #define MUNIT32
  152. #define SMITH
  153. #define mp_dmul        p_dmul
  154. #define mp_setp        p_setp
  155. #define mp_addc        p_addc
  156. #define mp_subb        p_subb
  157. #define mp_rotate_left    p_rotl
  158. #define mp_smula    p_smula
  159. #define mp_quo_digit    p_quo_digit
  160. #define mp_set_recip    p_setrecip
  161. #define PLATFORM_SPECIFIED
  162. #endif /* mips */
  163.  
  164. #ifdef i386
  165. /*
  166.  * Needs 80386.S
  167.  */
  168. #define UNIT32
  169. #define MUNIT32
  170. #define SMITH
  171. #define mp_setp        P_SETP
  172. #define mp_addc        P_ADDC
  173. #define mp_subb        P_SUBB
  174. #define mp_rotate_left    P_ROTL
  175. #define unitfill0(r,ct) memset((void*)r, 0, (ct)*sizeof(unit))
  176. #define mp_smula    P_SMULA
  177. #define mp_quo_digit    p_quo_digit
  178. #define mp_set_recip    p_setrecip
  179. #define PLATFORM_SPECIFIED
  180. #endif /* i386 */
  181.  
  182. #ifdef sparc
  183. /*
  184.  * Needs sparc.s
  185.  */
  186. #define UNIT32
  187. #define MERRITT
  188. #define mp_setp        P_SETP
  189. #define mp_addc        P_ADDC
  190. #define mp_subb        P_SUBB
  191. #define mp_rotate_left    P_ROTL
  192. #define unitfill0(r,ct) memset((void*)r, 0, (ct)*sizeof(unit))
  193. #define PLATFORM_SPECIFIED
  194. #endif /* sparc */
  195.  
  196. #if defined(mc68000) || defined(mc68020)
  197. /*
  198.  * Needs mc68020.S
  199.  */
  200. #define UNIT32
  201. #define mp_setp        P_SETP
  202. #define mp_addc        P_ADDC
  203. #define mp_subb        P_SUBB
  204. #define mp_rotate_left    P_ROTL
  205. #define unitfill0(r,ct) memset((void*)r, 0, (ct)*sizeof(unit))
  206. #if defined(sun3) || defined(mc68020)
  207. # define UPTON
  208. # define MUNIT32
  209. # define mp_smul    P_SMUL
  210. /* # define mp_dmul    P_DMUL */ /* mc68020.s has a bug in P_DMUL */
  211. #else
  212. # define SMITH
  213. # define MUNIT16
  214. #endif
  215. #define PLATFORM_SPECIFIED
  216. #endif /* mc68000 */
  217.  
  218. #ifdef AMIGA
  219. #define UNIT32
  220. #define mp_addc         P_ADDC
  221. #define mp_subb         P_SUBB
  222. #define mp_rotate_left  P_ROTL
  223. #define mp_setp         P_SETP
  224. #ifdef _M68020
  225. #define mp_smul         P_SMUL
  226. #define UPTON
  227. #define MUNIT32                 /* 32-bit multiplies for >=68020 */
  228. #else /* _M68020 */
  229. #define SMITH
  230. #define MUNIT16
  231. #endif /* _M68020 */
  232. #define PLATFORM_SPECIFIED
  233. #endif /* AMIGA */
  234.  
  235. /*
  236.  * Notes on the WIN32 port: (David Boreham davidb@daylight.demon.co.uk)
  237.  *
  238.  * The port is very lightweight, save for the assembler routines for MP arithmetic.
  239.  * In general, the old DOS code is used, except where it is broken for NT and Win95,
  240.  * for example we don't use short pathnames or fold filenames to lowercase.
  241.  * The MP arithmetic routines in PGP can work in a portable mode using the MERRITT
  242.  * code. This is very much slower than Thad Smith's code. Unfortunately, Thad's
  243.  * code assumes that sizeof(long) > sizeof (int), which is not the case in Win32.
  244.  * This means that his C code will not work. I have re-implemented his 8086 assembler
  245.  * in 386 code, optimised for the Pentium pipeline. This works fine and if you're
  246.  * building for one of the 386 compatible processors (386, 486, Pentium, clones etc.)
  247.  * define USE_WIN_ASSEMBLER in the project options and build that version.
  248.  * If you're building for another processor (PowerPC, MIPS, Alpha) then you need to
  249.  * either a) write assembler routines for those processors (and send the code back
  250.  * for inclusion in the distribution) or b) use the portable, slower, code by not
  251.  * defining USE_WIN32_ASSEMBLER.
  252.  * The assembler code needs the Microsoft compiler. The non-assembler version
  253.  * should work with any compiler. I've not tested any other compilers.
  254.  * I've done extensive profiling on this and other versions of PGP on NT.
  255.  * Some of the optimisations I've tried out are not in this code because they
  256.  * didn't give a significant performance improvement, but did make the code
  257.  * rather un-portable back to the other supported platforms (DOS, OS/2 etc).
  258.  * Lastly, if you're underwhelmed by the speed of this PGP compared to the
  259.  * old 16-bit DOS version, don't blame me: PGP uses the IDEA encryption
  260.  * system, which is inherently 16-bit. It also suffers from some rather
  261.  * poor I/O code design, which can soak up performance on a proper operating
  262.  * system.
  263.  */
  264. #ifdef WIN32
  265. #define UNIT32
  266. #ifdef USE_WIN32_ASSEMBLER
  267. #define SMITH
  268. #define MUNIT32
  269. #else
  270. #define MERRITT
  271. #endif
  272. #define PLATFORM_SPECIFIED
  273. #endif
  274.  
  275. #ifdef MACTC5
  276. /*
  277.  * needs mp_macasm.c
  278.  */
  279. #define UNIT32
  280. #if defined(M68030) || defined(CODEWARRIOR)        /* 680[234]0 capable */
  281. #define MUNIT32
  282. #else
  283. #define MUNIT16
  284. #endif
  285. #define mp_setp        P_SETP
  286. #define mp_addc        P_ADDC
  287. #define mp_subb        P_SUBB
  288. #define mp_smul        P_SMUL
  289. #define mp_rotate_left    P_ROTL
  290. #define UPTON
  291. #define unitfill0(r,ct) memset((void*)r, 0, (ct)*sizeof(unit))
  292. #define PLATFORM_SPECIFIED
  293. #endif /* MACTC5 */
  294.  
  295. #ifdef ATARI
  296. #define UNIT32
  297. #define MUNIT16
  298. #define mp_setp        P_SETP
  299. #define mp_addc        P_ADDC
  300. #define mp_subb        P_SUBB
  301. #define mp_smul        P_SMUL
  302. #define mp_rotate_left    P_ROTL
  303. #define UPTON
  304. #define unitfill0(r,ct) memset((void*)r, 0, (ct)*sizeof(unit))
  305. #define PLATFORM_SPECIFIED
  306. #endif /* ATARI */
  307.  
  308. /* Add additional platforms here ... */
  309.  
  310. /**************** End of system specification ************************/
  311.  
  312. #ifndef PLATFORM_SPECIFIED
  313. /* No platform explicitly selected.  Customization is controlled by
  314.  * PORTABLE and MPORTABLE.
  315.  */
  316. #define mp_setp        P_SETP
  317. #define mp_addc        P_ADDC
  318. #define mp_subb        P_SUBB
  319. #define mp_rotate_left    P_ROTL
  320. #define UPTON
  321. #define unitfill0(r,ct) memset((void*)r, 0, (ct)*sizeof(unit))
  322. #ifndef MPORTABLE
  323. #define mp_smul    P_SMUL
  324. #endif    /* MPORTABLE */
  325. #endif    /* PLATFORM_SPECIFIED */
  326. #endif    /* PORTABLE */
  327. #endif    /* PLATFORM_H */
  328.