OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* cairo - a vector graphics library with display and print output | 2 /* cairo - a vector graphics library with display and print output |
3 * | 3 * |
4 * Copyright © 2004 Keith Packard | 4 * Copyright © 2004 Keith Packard |
5 * | 5 * |
6 * This program is free software; you can redistribute it and/or modify | 6 * This program is free software; you can redistribute it and/or modify |
7 * it under the terms of the GNU General Public License version 2 as | 7 * it under the terms of the GNU General Public License version 2 as |
8 * published by the Free Software Foundation; | 8 * published by the Free Software Foundation; |
9 * | 9 * |
10 * This program is distributed in the hope that it will be useful, | 10 * This program is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 * GNU General Public License for more details. | 13 * GNU General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU General Public License | 15 * You should have received a copy of the GNU General Public License |
16 * along with this program; if not, write to the Free Software | 16 * along with this program; if not, write to the Free Software |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 * | 18 * |
19 * The original code as contributed to the cairo library under | 19 * The original code as contributed to the cairo library under |
20 * the dual license MPL+LGPL. We used the LGPL relicensing clause to | 20 * the dual license MPL+LGPL. We used the LGPL relicensing clause to |
21 * get a GPL version of this code which now lives here. This header is | 21 * get a GPL version of this code which now lives here. This header is |
22 * unmodified other than the licensing clause. | 22 * unmodified other than the licensing clause. |
23 * | 23 * |
24 * The Original Code is the cairo graphics library. | 24 * The Original Code is the cairo graphics library. |
25 * | 25 * |
26 * The Initial Developer of the Original Code is Keith Packard | 26 * The Initial Developer of the Original Code is Keith Packard |
27 * | 27 * |
28 * Contributor(s): | 28 * Contributor(s): |
29 * Keith R. Packard <keithp@keithp.com> | 29 * Keith R. Packard <keithp@keithp.com> |
| 30 * |
| 31 * Code changes for ns-3 from upstream are marked with `//PDB' |
30 */ | 32 */ |
31 | 33 |
32 #include "cairo-wideint-private.h" | 34 #include "cairo-wideint-private.h" |
33 | 35 |
34 /** | 36 /** |
35 * \file | 37 * \file |
36 * \ingroup highprec | 38 * \ingroup highprec |
37 * Implementation of the cairo_x functions which implement high precision arithm
etic. | 39 * Implementation of the cairo_x functions which implement high precision arithm
etic. |
38 */ | 40 */ |
39 | 41 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 int den_neg = _cairo_int64_negative (den); | 306 int den_neg = _cairo_int64_negative (den); |
305 cairo_uquorem64_t uqr; | 307 cairo_uquorem64_t uqr; |
306 cairo_quorem64_t qr; | 308 cairo_quorem64_t qr; |
307 | 309 |
308 if (num_neg) | 310 if (num_neg) |
309 num = _cairo_int64_negate (num); | 311 num = _cairo_int64_negate (num); |
310 if (den_neg) | 312 if (den_neg) |
311 den = _cairo_int64_negate (den); | 313 den = _cairo_int64_negate (den); |
312 uqr = _cairo_uint64_divrem (num, den); | 314 uqr = _cairo_uint64_divrem (num, den); |
313 if (num_neg) | 315 if (num_neg) |
314 » qr.rem = _cairo_int64_negate (uqr.rem); | 316 » qr.rem = _cairo_int64_negate ((cairo_int64_t)uqr.rem); //PDB cast |
315 else | 317 else |
316 qr.rem = uqr.rem; | 318 qr.rem = uqr.rem; |
317 if (num_neg != den_neg) | 319 if (num_neg != den_neg) |
318 » qr.quo = (cairo_int64_t) _cairo_int64_negate (uqr.quo); | 320 » qr.quo = (cairo_int64_t) _cairo_int64_negate ((cairo_int64_t)uqr.quo);
//PDB cast |
319 else | 321 else |
320 qr.quo = (cairo_int64_t) uqr.quo; | 322 qr.quo = (cairo_int64_t) uqr.quo; |
321 return qr; | 323 return qr; |
322 } | 324 } |
323 | 325 |
324 #if HAVE_UINT128_T | 326 #if HAVE_UINT128_T |
325 | 327 |
326 const char * cairo_impl128 = "uint128_t"; | 328 const char * cairo_impl128 = "uint128_t"; |
327 | 329 |
328 cairo_uquorem128_t | 330 cairo_uquorem128_t |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 { | 684 { |
683 cairo_uquorem64_t result; | 685 cairo_uquorem64_t result; |
684 cairo_uint64_t B = _cairo_uint32s_to_uint64 (1, 0); | 686 cairo_uint64_t B = _cairo_uint32s_to_uint64 (1, 0); |
685 | 687 |
686 /* These are the high 64 bits of the *96* bit numerator. We're | 688 /* These are the high 64 bits of the *96* bit numerator. We're |
687 * going to represent the numerator as xB + y, where x is a 64, | 689 * going to represent the numerator as xB + y, where x is a 64, |
688 * and y is a 32 bit number. */ | 690 * and y is a 32 bit number. */ |
689 cairo_uint64_t x = _cairo_uint128_to_uint64 (_cairo_uint128_rsl(num, 32)); | 691 cairo_uint64_t x = _cairo_uint128_to_uint64 (_cairo_uint128_rsl(num, 32)); |
690 | 692 |
691 /* Initialise the result to indicate overflow. */ | 693 /* Initialise the result to indicate overflow. */ |
692 result.quo = _cairo_uint32s_to_uint64 (-1U, -1U); | 694 result.quo = _cairo_uint32s_to_uint64 (UINT_MAX, UINT_MAX); //PDB cast |
693 result.rem = den; | 695 result.rem = den; |
694 | 696 |
695 /* Don't bother if the quotient is going to overflow. */ | 697 /* Don't bother if the quotient is going to overflow. */ |
696 if (_cairo_uint64_ge (x, den)) { | 698 if (_cairo_uint64_ge (x, den)) { |
697 return /* overflow */ result; | 699 return /* overflow */ result; |
698 } | 700 } |
699 | 701 |
700 if (_cairo_uint64_lt (x, B)) { | 702 if (_cairo_uint64_lt (x, B)) { |
701 /* When the final quotient is known to fit in 32 bits, then | 703 /* When the final quotient is known to fit in 32 bits, then |
702 * num < 2^64 if and only if den < 2^32. */ | 704 * num < 2^64 if and only if den < 2^32. */ |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 } | 751 } |
750 else { | 752 else { |
751 q = uint64_hi32 (x); | 753 q = uint64_hi32 (x); |
752 r = _cairo_uint64_to_uint32 (x); | 754 r = _cairo_uint64_to_uint32 (x); |
753 } | 755 } |
754 quotient = q; | 756 quotient = q; |
755 | 757 |
756 /* Add the main term's contribution to quotient. Note B-v = | 758 /* Add the main term's contribution to quotient. Note B-v = |
757 * -v as an uint32 (unless v = 0) */ | 759 * -v as an uint32 (unless v = 0) */ |
758 if (v) | 760 if (v) |
759 » quorem = _cairo_uint64_divrem (_cairo_uint32x32_64_mul (q, -v), den)
; | 761 » quorem = _cairo_uint64_divrem (_cairo_uint32x32_64_mul (q, -(int32_t
)v), den); //PDB cast |
760 else | 762 else |
761 quorem = _cairo_uint64_divrem (_cairo_uint32s_to_uint64 (q, 0), den)
; | 763 quorem = _cairo_uint64_divrem (_cairo_uint32s_to_uint64 (q, 0), den)
; |
762 quotient += _cairo_uint64_to_uint32 (quorem.quo); | 764 quotient += _cairo_uint64_to_uint32 (quorem.quo); |
763 | 765 |
764 /* Add the contribution of the subterm and start computing the | 766 /* Add the contribution of the subterm and start computing the |
765 * true remainder. */ | 767 * true remainder. */ |
766 remainder = _cairo_uint32s_to_uint64 (r, y); | 768 remainder = _cairo_uint32s_to_uint64 (r, y); |
767 if (_cairo_uint64_ge (remainder, den)) { | 769 if (_cairo_uint64_ge (remainder, den)) { |
768 remainder = _cairo_uint64_sub (remainder, den); | 770 remainder = _cairo_uint64_sub (remainder, den); |
769 quotient++; | 771 quotient++; |
(...skipping 28 matching lines...) Expand all Loading... |
798 if (num_neg) | 800 if (num_neg) |
799 num = _cairo_int128_negate (num); | 801 num = _cairo_int128_negate (num); |
800 if (den_neg) | 802 if (den_neg) |
801 nonneg_den = _cairo_int64_negate (den); | 803 nonneg_den = _cairo_int64_negate (den); |
802 else | 804 else |
803 nonneg_den = den; | 805 nonneg_den = den; |
804 | 806 |
805 uqr = _cairo_uint_96by64_32x64_divrem (num, nonneg_den); | 807 uqr = _cairo_uint_96by64_32x64_divrem (num, nonneg_den); |
806 if (_cairo_uint64_eq (uqr.rem, _cairo_int64_to_uint64 (nonneg_den))) { | 808 if (_cairo_uint64_eq (uqr.rem, _cairo_int64_to_uint64 (nonneg_den))) { |
807 /* bail on overflow. */ | 809 /* bail on overflow. */ |
808 » qr.quo = _cairo_uint32s_to_uint64 (0x7FFFFFFF, -1U);; | 810 » qr.quo = _cairo_uint32s_to_uint64 (0x7FFFFFFF, UINT_MAX); //PDB cast |
809 qr.rem = den; | 811 qr.rem = den; |
810 return qr; | 812 return qr; |
811 } | 813 } |
812 | 814 |
813 if (num_neg) | 815 if (num_neg) |
814 » qr.rem = _cairo_int64_negate (uqr.rem); | 816 » qr.rem = _cairo_int64_negate ((cairo_int64_t)uqr.rem); //PDB cast |
815 else | 817 else |
816 qr.rem = uqr.rem; | 818 qr.rem = uqr.rem; |
817 if (num_neg != den_neg) | 819 if (num_neg != den_neg) |
818 » qr.quo = _cairo_int64_negate (uqr.quo); | 820 » qr.quo = _cairo_int64_negate ((cairo_int64_t)uqr.quo); //PDB cast |
819 else | 821 else |
820 qr.quo = uqr.quo; | 822 qr.quo = uqr.quo; |
821 return qr; | 823 return qr; |
822 } | 824 } |
OLD | NEW |