[Cobolforgcc-devel] Re: Cleaned 128 bit math
Status: Pre-Alpha
Brought to you by:
timjosling
From: Tim J. <te...@me...> - 2000-08-20 07:07:09
|
"Theodore J. Seward, Jr." wrote: > > Tim, > > I think I have all the routine names and warning messages cleaned up. If you find any errors, please let me know and I'll gladly fix them. > > Good Luck - Ted Seward > > -------------------------------------------------- > Signed 128 bit routine (LL = stands for long long) > -------------------------------------------------- > > typedef name: binLLL > typedef pointer name: binLLLPtr > > Note: binLLL is the same definition as binULLL > binLLLPtr is the same definition as binULLLPtr > > INT128_MIN = Binary minimum value: -170141183460469231731687303715884105728 > INT128_MAX = Binary maximum value: +170141183460469231731687303715884105727 > INT128_ZERO = Binary value: 0 > > Header File: COBR_BIN128LLL.h > Routines: COBR_BIN128LLL.c > > > Example > ------- > > #include "COBR_BIN128LLL.h" > > binLLL a,b,c,r; > char str[50]; > > cobr_LLL_i32toi(b,57); > cobr_LLL_i32toi(c,10); > cobr_LLL_div(a,r,b,c); > printf("a = %s\n",cobr_LLL_itoa(str,a)); /* prints 5 */ > printf("r = %s\n",cobr_LLL_itoa(str,r)); /* prints 7 */ > > > Arithmetic > ---------- > > cobr_LLL_add(a,b,c) - a := b + c > cobr_LLL_sub(a,b,c) - a := b - c > cobr_LLL_mul(a,b,c) - a := b * c > cobr_LLL_div(a,r,b,c) - a := b / c; r := b % c > cobr_LLL_complement(a) - a := -a > cobr_LLL_copy(a,b) - a := b [Macro] > cobr_LLL_zero(a) - a := 0 [Macro] > > > Comparisons > ----------- > > cobr_LLL_compare(a,b) - a::b; -1 := a<b, 0 := a==b, +1 := a>b > cobr_LLL_eq(a,b) - a::b, 1 := a==b, 0 := a!=b [Macro] > cobr_LLL_ne(a,b) - a::b, 1 := a!=b, 0 := a==b [Macro] > cobr_LLL_lt(a,b) - a::b, 1 := a<b, 0 := a>=b [Macro] > cobr_LLL_le(a,b) - a::b, 1 := a<=b, 0 := a>b [Macro] > cobr_LLL_gt(a,b) - a::b, 1 := a>b, 0 := a<=b [Macro] > cobr_LLL_ge(a,b) - a::b, 1 := a>=b, 0 := a<b [Macro] > cobr_LLL_ifzero(a) - a::0, 1 := a==0, 0 := a!=0 [Macro] > > > Convert from LL to other type > ----------------------------- > > cobr_LLL_itoa(&ascii,a) - returns ASCII ascii := a (returns ptr to ascii) > cobr_LLL_itod(&pd,pdlen,a) - returns Packed pd := a > cobr_LLL_itoi8(&i8, a) - returns INT8 *i8 := a > cobr_LLL_itoi16(&i16,a) - returns INT16 *i16 := a > cobr_LLL_itoi32(&i32,a) - returns INT32 *i32 := a > cobr_LLL_itoi64(&i64,a) - returns INT64 *i64 := a > > > Convert other types to LL > ------------------------- > > cobr_LLL_dtoi(a,&pd,pdlen) - sets Packed a := pd > cobr_LLL_atoi(a,&ascii) - sets ASCII a := ASCII > cobr_LLL_i8toi(a,i8) - sets INT8 a := i8 > cobr_LLL_i16toi(a,i16) - sets INT16 a := i16 > cobr_LLL_i32toi(a,i32) - sets INT32 a := i32 > cobr_LLL_i64toi(a,i64) - sets INT64 a := i64 > > > Shifts > ------ > > cobr_LLL_shl(a,n) - a := a << n > cobr_LLL_shra(a,n) - a := a >> n [arithmetic] > cobr_LLL_shr(a,n) - a := a >> n [logical] > > > -------------------------------------------------------------- > Unsigned 128 bit routine (ULL = stands for unsigned long long) > -------------------------------------------------------------- > > typedef name: binULLL > typedef pointer name: binULLLPtr > > Note: binULLL is the same definition as binLLL > binULLLPtr is the same definition as binLLLPtr > > UINT128_MIN = Binary minimum value: 0 > UINT128_MAX = Binary maximum value: 340282366920938463463374607431768211455 > UINT128_MAX = Binary value: 0 > > Header File: COBR_BIN128ULLL.h > Routines: COBR_BIN128ULLL.c > > > Example > ------- > > #include "COBR_BIN128ULLL.h" > > binULLL a,b,c,r; > char str[50]; > > cobr_ULLL_i32toi(b,57); > cobr_ULLL_i32toi(c,10); > cobr_ULLL_div(a,r,b,c); > printf("a = %s\n",cobr_ULLL_itoa(str,a)); /* prints 5 */ > printf("r = %s\n",cobr_ULLL_itoa(str,r)); /* prints 7 */ > > > Arithmetic > ---------- > > cobr_ULLL_add(a,b,c) - a := b + c > cobr_ULLL_sub(a,b,c) - a := b - c > cobr_ULLL_mul(a,b,c) - a := b * c > cobr_ULLL_div(a,r,b,c) - a := b / c; r := b % c > cobr_ULLL_copy(a,b) - a := b [Macro] > cobr_ULLL_zero(a) - a := 0 [Macro] > > > Comparisons > ----------- > > cobr_ULLL_compare(a,b) - a::b; -1 := a<b, 0 := a==b, +1 := a>b > cobr_ULLL_eq(a,b) - a::b, 1 := a==b, 0 := a!=b [Macro] > cobr_ULLL_ne(a,b) - a::b, 1 := a!=b, 0 := a==b [Macro] > cobr_ULLL_lt(a,b) - a::b, 1 := a<b, 0 := a>=b [Macro] > cobr_ULLL_le(a,b) - a::b, 1 := a<=b, 0 := a>b [Macro] > cobr_ULLL_gt(a,b) - a::b, 1 := a>b, 0 := a<=b [Macro] > cobr_ULLL_ge(a,b) - a::b, 1 := a>=b, 0 := a<b [Macro] > cobr_ULLL_ifzero(a) - a::0, 1 := a==0, 0 := a!=0 [Macro] > > > Convert from ULL to other type > ------------------------------ > > cobr_ULLL_itoa(&ascii,a) - returns ASCII ascii := a (returns ptr to ascii) > cobr_ULLL_itod(&pd,pdlen,a) - returns Packed pd := a > cobr_ULLL_itoi8(&i8, a) - returns INT8 *i8 := a > cobr_ULLL_itoi16(&i16,a) - returns INT16 *i16 := a > cobr_ULLL_itoi32(&i32,a) - returns INT32 *i32 := a > cobr_ULLL_itoi64(&i64,a) - returns INT64 *i64 := a > > > Convert other types to ULL > -------------------------- > > cobr_ULLL_dtoi(a,&pd,pdlen) - sets Packed a := pd > cobr_ULLL_atoi(a,&ascii) - sets ASCII a := ASCII > cobr_ULLL_i8toi(a,i8) - sets INT8 a := i8 > cobr_ULLL_i16toi(a,i16) - sets INT16 a := i16 > cobr_ULLL_i32toi(a,i32) - sets INT32 a := i32 > cobr_ULLL_i64toi(a,i64) - sets INT64 a := i64 > > > Shifts > ------ > > cobr_ULLL_shl(a,n) - a := a << n > cobr_ULLL_shr(a,n) - a := a >> n > > > > ---------------------------- > Ideas on Future Optimization > ---------------------------- > > The divide routine is the slowest. Anything that speeds up a routine that is called by division will speed up division (shl, shr, add, sub). > > Modify the routines to use register types for the most commonly called routines. > > Consider special macro forms of commonly called routines from (add, sub, shl, shr) for divide & multiply. Use these macros inside of the other math routines so there is a savings on function linkage. > > Name: cobr_bin128.tar.gz > cobr_bin128.tar.gz Type: Unix Tape Archive (application/x-tar) > Encoding: base64 |