README.bn
上传用户:zbbssh
上传日期:2007-01-08
资源大小:196k
文件大小:4k
源码类别:

CA认证

开发平台:

C/C++

  1. Welcome to my multiprecision math library!  I'm a little bit proud
  2. of it, particularly its speed.  If you have a machine for which
  3. assembly-language subroutines are available (you can probably guess
  4. from the filename), it will go even faster.  Instructions for
  5. building the library with assembly subroutines are included later.
  6. Barring that, on many machines using GCC, the GNU C compiler, helps
  7. the speed significantly, because it not only supports "long long"
  8. 64-bit data types, but it can perform operations on them in line.
  9. Many compilers that support "long long" are rather inefficient when
  10. working with them.
  11. For a general description of the library and its organization, see
  12. bn.doc.  I'm very curious what you all think of it.  One thing I tried
  13. to do was to comment it better than most, although that is more apparent
  14. earlier, when I didn't know what I was doing, than later, when I was
  15. used to it and could read the code.
  16. I can't put a full number theory course in the comments, so there
  17. are some parts that are just going to be confusing unless you
  18. have background.  Here's how I suggest judging it: if you stare
  19. at the code for a while, and figure out what's going on, but think
  20. that it was harder than necessary, send me mail explaining how you
  21. think it could be made easier.  If you never manage to figure it out,
  22. then assume that it's something you never learned in school and
  23. it's not my job to teach you.
  24. But really, I can't stop you from saying whatever you want.  If you'd
  25. like to send some comments, good or bad, send me some mail.
  26. -- 
  27. -Colin <colin@nyx.cs.du.edu>
  28. ** How to compile an assembly-language version of the bignum library
  29. Assembly primitives replace some of the functions in the lbn??.c files
  30. (Where ?? is 00, 16, 32, or 64, as appropriate) with faster routines.
  31. The math library is designed to facilitate this sort of replacement.
  32. Suppose we are compiling for the mythical "DLX" processor.  Then there
  33. will be a file, called lbndlx.c, lbndlx.s or lbndlx.asm (depending
  34. on the convention for assembly source files on DLX platforms) which
  35. contains the code.  This must be assembled and linked into the library.
  36. There will also be an lbndlx.h file, which includes declarations for
  37. the DLX primitives, and preprocessor definitions to prevent the
  38. C equivalents in lbn??.c from being compiled as well.
  39. This file must be included in the lbn.h file, and that is done using
  40. the BNINCLUDE macro.  On the compiler command line, add the option
  41. "-DBNINCLUDE=lbndlx.h".  This will force lbn.h to #include "lbndlx.h".
  42. If a machine supports only one word size, such as the DEC Alpha, this is
  43. all that is needed.  Just compile the 64-bit math library, add "lbnalpha.s"
  44. to the source files, and -DBNINCLUDE=lbnalpha.h.
  45. Many machines, however, support multiple word sizes.  The Intel 80x86
  46. and Motorola 680x0 family support 16 or 32 bits, depending on the
  47. processor model, and the PowerPC and MIPS platforms support 32 or
  48. 64 bits, depending on the model.  Note that it is the size of the
  49. largest NxN->2N multiply which determines the size.  Thus, the 68000
  50. uses a 16-bit word size because the largest multiply result it can
  51. produce is 32 bits, and the SPARC v9 architecture uses a 32-bit word
  52. size because the largest multiply result it can produce is 64 bits.
  53. The only machines for which this is currently implemented are the 80x86
  54. and 680x0 families.  In this case, you must include *two* versions of
  55. the math library core routines (lbn??.c and bn??.c), the appropriate
  56. assembly primitives, and a bndlx.c file which *replaces* bninit??.c.
  57. The bndlx.c file must somehow test the machine to determine the word
  58. size, and call the appropriate bnInit??() function.
  59. For the 8086, both 16- and 32-bit assembly primitives, and a testing
  60. function (not386()) are in the lbn8086.asm file.  (The lbn80386.asm
  61. file is for the 80386 in flat model, which is 32-bit only.)
  62. For the 680x0, the 16-bit primitives are in lbn68000.c (along with
  63. an "is68020()" function which returns non-zero if 32-bit routines
  64. can be called) and the 32-bit primitives are in lbn68020.c.
  65. You may use only one or the other, or include the bn68000.c file which
  66. selects between the two.
  67. Other assembly primitives which are implemented are the Intel 960
  68. primitives (lbn960jx.s), PowerPC (lbnppc.c), and Intel 80386 flat-model,
  69. all 32 bits.