2 * Copyright © 2013 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 void ao_plus64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b) {
23 r->low = t = a->low + b->low;
24 r->high = a->high + b->high;
29 void ao_rshift64(ao_int64_t *r, ao_int64_t *a, uint8_t d) {
31 r->high = (int32_t) a->high >> d;
34 r->low |= a->high << (32 - d);
38 r->low = (int32_t) a->high >> d;
42 void ao_lshift64(ao_int64_t *r, ao_int64_t *a, uint8_t d) {
44 r->high = a->high << d;
47 r->high |= a->low >> (32 - d);
51 r->high = a->low << d;
55 void ao_umul64(ao_int64_t *r, uint32_t a, uint32_t b)
60 r1 = (uint32_t) (uint16_t) a * (uint16_t) b;
61 r2 = (uint32_t) (uint16_t) (a >> 16) * (uint16_t) b;
62 r3 = (uint32_t) (uint16_t) a * (uint16_t) (b >> 16);
63 r4 = (uint32_t) (uint16_t) (a >> 16) * (uint16_t) (b >> 16);
68 t.high = (uint32_t) r2 >> 16;
70 ao_plus64(&u, &s, &t);
72 v.high = (int32_t) r3 >> 16;
77 void ao_neg64(ao_int64_t *r, ao_int64_t *a) {
84 void ao_mul64(ao_int64_t *r, int32_t a, int32_t b) {
100 void ao_umul64_16(ao_int64_t *r, ao_int64_t *a, uint16_t b) {
101 ao_umul64(r, a->low, b);
102 r->high += a->high * b;
105 void ao_mul64_16(ao_int64_t *r, ao_int64_t *a, uint16_t b) {
106 if ((int32_t) a->high < 0) {
110 ao_umul64_16(r, &t, b);
113 ao_umul64_16(r, a, b);