head 1.9; access; symbols; locks; strict; comment @ * @; 1.9 date 2005.01.13.08.42.34; author rse; state Exp; branches; next 1.8; 1.8 date 2004.01.09.11.28.22; author rse; state Exp; branches; next 1.7; 1.7 date 2004.01.09.11.25.48; author rse; state Exp; branches; next 1.6; 1.6 date 2004.01.09.11.24.21; author rse; state Exp; branches; next 1.5; 1.5 date 2003.03.23.18.07.15; author rse; state Exp; branches; next 1.4; 1.4 date 2002.06.29.11.08.35; author rse; state Exp; branches; next 1.3; 1.3 date 2002.04.29.19.16.03; author rse; state Exp; branches; next 1.2; 1.2 date 2002.04.28.18.58.01; author rse; state Exp; branches; next 1.1; 1.1 date 2002.04.28.13.22.49; author rse; state Exp; branches; next ; desc @@ 1.9 log @happy new year 2005 @ text @/* ** OSSP ui64 - 64-Bit Arithmetic ** Copyright (c) 2002-2005 Ralf S. Engelschall ** Copyright (c) 2002-2005 The OSSP Project ** ** This file is part of OSSP ui64, a 64-bit arithmetic library ** which can be found at http://www.ossp.org/pkg/lib/ui64/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** ui64.h: API declaration */ #ifndef __UI64_H__ #define __UI64_H__ #include /* embedding support */ #ifdef UI64_PREFIX #if defined(__STDC__) || defined(__cplusplus) #define __UI64_CONCAT(x,y) x ## y #define UI64_CONCAT(x,y) __UI64_CONCAT(x,y) #else #define __UI64_CONCAT(x) x #define UI64_CONCAT(x,y) __UI64_CONCAT(x)y #endif #define ui64_t UI64_CONCAT(UI64_PREFIX,ui64_t) #define ui64_zero UI64_CONCAT(UI64_PREFIX,ui64_zero) #define ui64_max UI64_CONCAT(UI64_PREFIX,ui64_max) #define ui64_n2i UI64_CONCAT(UI64_PREFIX,ui64_n2i) #define ui64_i2n UI64_CONCAT(UI64_PREFIX,ui64_i2n) #define ui64_s2i UI64_CONCAT(UI64_PREFIX,ui64_s2i) #define ui64_i2s UI64_CONCAT(UI64_PREFIX,ui64_i2s) #define ui64_add UI64_CONCAT(UI64_PREFIX,ui64_add) #define ui64_addn UI64_CONCAT(UI64_PREFIX,ui64_addn) #define ui64_sub UI64_CONCAT(UI64_PREFIX,ui64_sub) #define ui64_subn UI64_CONCAT(UI64_PREFIX,ui64_subn) #define ui64_mul UI64_CONCAT(UI64_PREFIX,ui64_mul) #define ui64_muln UI64_CONCAT(UI64_PREFIX,ui64_muln) #define ui64_div UI64_CONCAT(UI64_PREFIX,ui64_div) #define ui64_divn UI64_CONCAT(UI64_PREFIX,ui64_divn) #define ui64_and UI64_CONCAT(UI64_PREFIX,ui64_and) #define ui64_or UI64_CONCAT(UI64_PREFIX,ui64_or) #define ui64_xor UI64_CONCAT(UI64_PREFIX,ui64_xor) #define ui64_not UI64_CONCAT(UI64_PREFIX,ui64_not) #define ui64_rol UI64_CONCAT(UI64_PREFIX,ui64_rol) #define ui64_ror UI64_CONCAT(UI64_PREFIX,ui64_ror) #define ui64_len UI64_CONCAT(UI64_PREFIX,ui64_len) #define ui64_cmp UI64_CONCAT(UI64_PREFIX,ui64_cmp) #endif typedef struct { unsigned char x[8]; /* x_0, ..., x_7 */ } ui64_t; #define ui64_cons(x7,x6,x5,x4,x3,x2,x1,x0) \ { { 0x##x0, 0x##x1, 0x##x2, 0x##x3, 0x##x4, 0x##x5, 0x##x6, 0x##x7 } } /* particular values */ extern ui64_t ui64_zero (void); extern ui64_t ui64_max (void); /* import and export via ISO-C "unsigned long" */ extern ui64_t ui64_n2i (unsigned long n); extern unsigned long ui64_i2n (ui64_t x); /* import and export via ISO-C string of arbitrary base */ extern ui64_t ui64_s2i (const char *str, char **end, int base); extern char * ui64_i2s (ui64_t x, char *str, size_t len, int base); /* arithmetical operations */ extern ui64_t ui64_add (ui64_t x, ui64_t y, ui64_t *ov); extern ui64_t ui64_addn (ui64_t x, int y, int *ov); extern ui64_t ui64_sub (ui64_t x, ui64_t y, ui64_t *ov); extern ui64_t ui64_subn (ui64_t x, int y, int *ov); extern ui64_t ui64_mul (ui64_t x, ui64_t y, ui64_t *ov); extern ui64_t ui64_muln (ui64_t x, int y, int *ov); extern ui64_t ui64_div (ui64_t x, ui64_t y, ui64_t *ov); extern ui64_t ui64_divn (ui64_t x, int y, int *ov); /* bit operations */ extern ui64_t ui64_and (ui64_t x, ui64_t y); extern ui64_t ui64_or (ui64_t x, ui64_t y); extern ui64_t ui64_xor (ui64_t x, ui64_t y); extern ui64_t ui64_not (ui64_t x); extern ui64_t ui64_rol (ui64_t x, int s, ui64_t *ov); extern ui64_t ui64_ror (ui64_t x, int s, ui64_t *ov); /* other operations */ extern int ui64_len (ui64_t x); extern int ui64_cmp (ui64_t x, ui64_t y); #endif /* __UI64_H__ */ @ 1.8 log @OSSP ui64 was never done under C&W work time, so no need to give them the copyright @ text @d3 2 a4 2 ** Copyright (c) 2002-2004 Ralf S. Engelschall ** Copyright (c) 2002-2004 The OSSP Project @ 1.7 log @bump copyright for year 2004 @ text @a4 1 ** Copyright (c) 2002-2004 Cable & Wireless Deutschland @ 1.6 log @strip trailing whitespaces @ text @d3 3 a5 3 ** Copyright (c) 2002-2003 Ralf S. Engelschall ** Copyright (c) 2002-2003 The OSSP Project ** Copyright (c) 2002-2003 Cable & Wireless Deutschland @ 1.5 log @bump copyright year @ text @d47 6 a52 6 #define ui64_max UI64_CONCAT(UI64_PREFIX,ui64_max) #define ui64_n2i UI64_CONCAT(UI64_PREFIX,ui64_n2i) #define ui64_i2n UI64_CONCAT(UI64_PREFIX,ui64_i2n) #define ui64_s2i UI64_CONCAT(UI64_PREFIX,ui64_s2i) #define ui64_i2s UI64_CONCAT(UI64_PREFIX,ui64_i2s) #define ui64_add UI64_CONCAT(UI64_PREFIX,ui64_add) d54 1 a54 1 #define ui64_sub UI64_CONCAT(UI64_PREFIX,ui64_sub) d56 1 a56 1 #define ui64_mul UI64_CONCAT(UI64_PREFIX,ui64_mul) d58 1 a58 1 #define ui64_div UI64_CONCAT(UI64_PREFIX,ui64_div) d60 7 a66 7 #define ui64_and UI64_CONCAT(UI64_PREFIX,ui64_and) #define ui64_or UI64_CONCAT(UI64_PREFIX,ui64_or) #define ui64_xor UI64_CONCAT(UI64_PREFIX,ui64_xor) #define ui64_not UI64_CONCAT(UI64_PREFIX,ui64_not) #define ui64_rol UI64_CONCAT(UI64_PREFIX,ui64_rol) #define ui64_ror UI64_CONCAT(UI64_PREFIX,ui64_ror) #define ui64_len UI64_CONCAT(UI64_PREFIX,ui64_len) @ 1.4 log @add useful constructor macro @ text @d3 3 a5 3 ** Copyright (c) 2002 Ralf S. Engelschall ** Copyright (c) 2002 The OSSP Project ** Copyright (c) 2002 Cable & Wireless Deutschland @ 1.3 log @add embedding support @ text @d74 3 @ 1.2 log @first cut for a real documentation @ text @d36 34 @ 1.1 log @Add first cut of OSSP ui64, a new (sub-)library which allows us to perform 64-bit unsigned integer arithmetic in a portable way without requiring the machine to support C99's 64-bit type "unsigned long long". Basically a ui64_t is an 8 byte array of "unsigned char" elements and hence the library internally stores 64-bit values as 8 digits to the base 2^8 and also performs the mathematical operations this way. @ text @d40 1 a40 1 /* minimum/maximum values */ @