lbnppc.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 1995 Colin Plumb. All rights reserved.
  3. * For licensing and other legal details, see the file legal.c.
  4. */
  5. #ifndef LBNPPC_H
  6. #define LBNPPC_H
  7. /*
  8. * Assembly-language routines for the Power PC processor.
  9. * Annoyingly, the Power PC does not have 64/32->32 bit divide,
  10. * so the C code should be reasonably fast. But it does have
  11. * 32x32->64-bit multiplies, and these routines provide access
  12. * to that.
  13. *
  14. * In versions of CodeWarrior before 8.0, there was no PPC assembler,
  15. * so a kludged-up one in CPP is used. This requires casting an
  16. * array of unsigneds to function pointer type, and a function pointer
  17. * is not a pointer to the code, but rather a pointer to a (code,TOC)
  18. * pointer pair which we fake up.
  19. *
  20. * CodeWarrior 8.0 supports PCC assembly, which is used directly.
  21. */
  22. /*
  23. * Bignums are stored in arrays of 32-bit words, and the least
  24. * significant 32-bit word has the lowest address, thus "little-endian".
  25. * The C code is slightly more efficient this way, so unless the
  26. * processor cares (the PowerPC, like most RISCs, doesn't), it is
  27. * best to use BN_LITTLE_ENDIAN.
  28. * Note that this has NOTHING to do with the order of bytes within a 32-bit
  29. * word; the math library is insensitive to that.
  30. */
  31. #define BN_LITTLE_ENDIAN 1
  32. typedef unsigned bnword32;
  33. #define BNWORD32 bnword32
  34. #if __MWERKS__ < 0x800
  35. /* Shared transition vector array */
  36. extern unsigned const * const lbnPPC_tv[];
  37. /* A function pointer on the PowerPC is a pointer to a transition vector */
  38. #define lbnMulN1_32 \
  39. ((void (*)(bnword32 *, bnword32 const *, unsigned, bnword32))(lbnPPC_tv+0))
  40. #define lbnMulAdd1_32 \
  41. ((bnword32 (*)(bnword32 *, bnword32 const *, unsigned, bnword32))(lbnPPC_tv+1))
  42. #define lbnMulSub1_32 \
  43. ((bnword32 (*)(bnword32 *, bnword32 const *, unsigned, bnword32))(lbnPPC_tv+2))
  44. #else /* __MWERKS__ >= 0x800 */
  45. void lbnMulN1_32(bnword32 *, bnword32 const *, unsigned, bnword32);
  46. #define lbnMulN1_32 lbnMulN1_32
  47. bnword32 lbnMulAdd1_32(bnword32 *, bnword32 const *, unsigned, bnword32);
  48. #define lbnMulAdd1_32 lbnMulAdd1_32
  49. bnword32 lbnMulSub1_32(bnword32 *, bnword32 const *, unsigned, bnword32);
  50. #define lbnMulSub1_32 lbnMulSub1_32
  51. #endif /* __MWERKS__ >= 0x800 */
  52. #endif /* LBNPPC_H */