e5eee823b9e6ea0e3e1031d2c22aa9a8d21cdba7
[fw/altos] / src / core / ao_int64.h
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 #ifndef _AO_INT64_H_
19 #define _AO_INT64_H_
20
21 #include <stdint.h>
22
23 typedef struct {
24         uint32_t        high;
25         uint32_t        low;
26 } ao_int64_t;
27
28 void ao_plus64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b);
29 void ao_neg64(ao_int64_t *r, ao_int64_t *a);
30 void ao_lshift64_16(ao_int64_t *r, uint16_t a, uint8_t d);
31 void ao_rshift64(ao_int64_t *r, ao_int64_t *a, uint8_t d);
32 void ao_lshift64(ao_int64_t *r, ao_int64_t *a, uint8_t d);
33 void ao_mul64_64_64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b);
34 void ao_mul64_32_32(ao_int64_t *r, int32_t a, int32_t b);
35 void ao_mul64_64_16(ao_int64_t *r, ao_int64_t *a, uint16_t b);
36
37 #define ao_int64_init32(r, a) (((r)->high = 0), (r)->low = (a))
38 #define ao_int64_init64(r, a, b) (((r)->high = (a)), (r)->low = (b))
39
40 #define ao_cast64(a) (((int64_t) (a)->high << 32) | (a)->low)
41
42 #define ao_int64_negativep(a)   (((int32_t) (a)->high) < 0)
43
44 #endif /* _AO_INT64_H_ */