| 1 | /* |
| 2 | * divide.h |
| 3 | * |
| 4 | * [Generated from divide, 25 September 1996] |
| 5 | */ |
| 6 | |
| 7 | #if !defined(__CC_NORCROFT) || !defined(__arm) |
| 8 | #error You must use the Norcroft ARM Compiler for Sapphire programs |
| 9 | #endif |
| 10 | |
| 11 | #pragma include_only_once |
| 12 | #pragma force_top_level |
| 13 | |
| 14 | #ifndef __divide_h |
| 15 | #define __divide_h |
| 16 | |
| 17 | #ifndef __sapphire_h |
| 18 | #include "sapphire.h" |
| 19 | #endif |
| 20 | |
| 21 | /*----- Overview ----------------------------------------------------------* |
| 22 | * |
| 23 | * Functions provided: |
| 24 | * |
| 25 | * divide |
| 26 | * div_unsigned |
| 27 | * div10 |
| 28 | * div_round |
| 29 | * div_u64x32 |
| 30 | */ |
| 31 | |
| 32 | /* --- divide --- * |
| 33 | * |
| 34 | * On entry: R0 == dividend |
| 35 | * R1 == divisor |
| 36 | * |
| 37 | * On exit: R0 == quotient |
| 38 | * R1 == remainder |
| 39 | * |
| 40 | * Use: A standard divide routine. Fairly speedy, hopefully. |
| 41 | * The results are always such that |
| 42 | * |
| 43 | * |quotient| <= |(divisor/dividend)|, |
| 44 | * |
| 45 | * |remainder| < |divisor| |
| 46 | * |
| 47 | * and |
| 48 | * |
| 49 | * quotient * divisor + remainder == dividend |
| 50 | */ |
| 51 | |
| 52 | extern routine divide; |
| 53 | |
| 54 | /* --- div_unsigned --- * |
| 55 | * |
| 56 | * On entry: R0 == dividend |
| 57 | * R1 == divisor |
| 58 | * |
| 59 | * On exit: R0 == quotient |
| 60 | * R1 == remainder |
| 61 | * |
| 62 | * Use: As for divide, except that it considers its operands to be |
| 63 | * unsigned. |
| 64 | */ |
| 65 | |
| 66 | extern routine div_unsigned; |
| 67 | |
| 68 | /* --- div10 --- * |
| 69 | * |
| 70 | * On entry: R0 == integer to divide |
| 71 | * |
| 72 | * On exit: R0 == quotient after division by 10 |
| 73 | * R1 == remainder after division by 10 |
| 74 | * |
| 75 | * Use: Divides an integer very quickly by 10. |
| 76 | * |
| 77 | * [Generated by Straylight divc] |
| 78 | */ |
| 79 | |
| 80 | extern routine div10; |
| 81 | |
| 82 | /* --- div_round --- * |
| 83 | * |
| 84 | * On entry: R0 == dividend |
| 85 | * R1 == divisor |
| 86 | * |
| 87 | * On exit: R0 == quotient, rounded to nearest integer |
| 88 | * R1 == remainder |
| 89 | * |
| 90 | * Use: Calculates a rounded-to-nearest quotient, rather than one |
| 91 | * rounded towards zero, which is what divide returns you. |
| 92 | * |
| 93 | * The remainder is fiddled during this process, so that the |
| 94 | * properties |
| 95 | * |
| 96 | * quotient * divisor + remainder == dividend |
| 97 | * |
| 98 | * and |
| 99 | * |
| 100 | * |remainder| < |divisor| |
| 101 | * |
| 102 | * still hold (so the remainder's sign may well change). |
| 103 | */ |
| 104 | |
| 105 | extern routine div_round; |
| 106 | |
| 107 | /* --- div_u64x32 --- * |
| 108 | * |
| 109 | * On entry: R0,R1 == dividend (high word in R1) |
| 110 | * R2 == divisor |
| 111 | * |
| 112 | * On exit: R0 == quotient |
| 113 | * R1 == remainder |
| 114 | * |
| 115 | * Use: Divides a 64-bit unsigned value by a 32-bit unsigned value |
| 116 | * yielding 32-bit unsigned quotient and remainder. If there |
| 117 | * are more than 32 bits of quotient, the return values are |
| 118 | * undefined. |
| 119 | */ |
| 120 | |
| 121 | extern routine div_u64x32; |
| 122 | |
| 123 | /*----- That's all, folks -------------------------------------------------*/ |
| 124 | |
| 125 | #endif |