/* cairo - a vector graphics library with display and print output * * Copyright © 2004 Keith Packard * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public * License version 2.1 as published by the Free Software Foundation * (the "LGPL") or, at your option, under the terms of the Mozilla * Public License Version 1.1 (the "MPL"). If you do not alter this * notice, a recipient may use your version of this file under either * the MPL or the LGPL. * * You should have received a copy of the LGPL along with this library * in the file COPYING-LGPL-2.1; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * You should have received a copy of the MPL along with this library * in the file COPYING-MPL-1.1 * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY * OF ANY KIND, either express or implied. See the LGPL or the MPL for * the specific language governing rights and limitations. * * The Original Code is the cairo graphics library. * * The Initial Developer of the Original Code is Keith Packard * * Contributor(s): * Keith R. Packard * */ #include "config.h" /* * 64-bit datatypes. implemented * as a pair of 32-bit ints */ typedef struct uint64 { uint32_t lo, hi; } uint64_t, int64_t; int32_t int64_trunc_int32(int64_t val); uint64_t uint32_to_uint64 (uint32_t i); #define uint64_to_uint32(a) ((a).lo) uint64_t uint64_add (uint64_t a, uint64_t b); uint64_t uint64_sub (uint64_t a, uint64_t b); uint64_t uint64_mul (uint64_t a, uint64_t b); uint64_t uint32x32_64_mul (uint32_t a, uint32_t b); uint64_t uint64_lsl (uint64_t a, int shift); uint64_t uint64_rsl (uint64_t a, int shift); uint64_t uint64_rsa (uint64_t a, int shift); int uint64_lt (uint64_t a, uint64_t b); int uint64_eq (uint64_t a, uint64_t b); int64_t int64_negate (int64_t a); #define uint64_negative(a) (((int32_t) ((a).hi)) < 0) #define uint64_to_int64(i) (i) #define int64_to_uint64(i) (i) int64_t int32_to_int64(int32_t i); #define int64_to_int32(a) ((int32_t) uint64_to_uint32(a)) #define int64_add(a,b) uint64_add (a,b) #define int64_sub(a,b) uint64_sub (a,b) #define int64_mul(a,b) uint64_mul (a,b) int64_t int32x32_64_mul (int32_t a, int32_t b); int int64_lt (uint64_t a, uint64_t b); #define int64_eq(a,b) uint64_eq (a,b) #define int64_lsl(a,b) uint64_lsl (a,b) #define int64_rsl(a,b) uint64_rsl (a,b) #define int64_rsa(a,b) uint64_rsa (a,b) #define int64_negative(a) (((int32_t) ((a).hi)) < 0) /* * 64-bit comparisions derived from lt or eq */ #define uint64_le(a,b) (!uint64_gt(a,b)) #define uint64_ne(a,b) (!uint64_eq(a,b)) #define uint64_ge(a,b) (!uint64_lt(a,b)) #define uint64_gt(a,b) uint64_lt(b,a) #define int64_le(a,b) (!int64_gt(a,b)) #define int64_ne(a,b) (!int64_eq(a,b)) #define int64_ge(a,b) (!int64_lt(a,b)) #define int64_gt(a,b) int64_lt(b,a) /* * As the C implementation always computes both, create * a function which returns both for the 'native' type as well */ typedef struct uquorem64 { uint64_t quo; uint64_t rem; } uquorem64_t; typedef struct quorem64 { int64_t quo; int64_t rem; } quorem64_t; uquorem64_t uint64_divrem (uint64_t num, uint64_t den); quorem64_t int64_divrem (int64_t num, int64_t den); #ifdef DEBUG char* ui64toa(uint64_t n, uint8_t zeropad_len); char* i64toa(int64_t n, uint8_t zeropad_len); #endif