Changeset 00e80b6 for src/libcfa/gmp
- Timestamp:
- Jul 27, 2017, 2:02:36 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 7d49b72
- Parents:
- 25bd9074
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/gmp
r25bd9074 r00e80b6 1 // 1 // 2 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 3 3 // 4 4 // The contents of this file are covered under the licence agreement in the 5 5 // file "LICENCE" distributed with Cforall. 6 // 7 // gmp -- 8 // 6 // 7 // gmp -- 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Tue Apr 19 08:43:43 2016 … … 12 12 // Last Modified On : Fri Jul 7 09:33:20 2017 13 13 // Update Count : 15 14 // 14 // 15 15 16 16 // https://gmplib.org/gmp-man-6.1.1.pdf … … 24 24 25 25 // constructor 26 static inline void ?{}( Int * this ) { mpz_init( this->mpz ); }27 static inline void ?{}( Int * this, Int init ) { mpz_init_set( this->mpz, init.mpz ); }28 static inline void ?{}( Int * this, zero_t ) { mpz_init_set_si( this->mpz, 0 ); }29 static inline void ?{}( Int * this, one_t ) { mpz_init_set_si( this->mpz, 1 ); }30 static inline void ?{}( Int * this, signed long int init ) { mpz_init_set_si( this->mpz, init ); }31 static inline void ?{}( Int * this, unsigned long int init ) { mpz_init_set_ui( this->mpz, init ); }32 static inline void ?{}( Int * this, const char * val ) { if ( mpz_init_set_str( this->mpz, val, 0 ) ) abort(); }33 static inline void ^?{}( Int * this ) { mpz_clear( this->mpz ); }26 static inline void ?{}( Int & this ) { mpz_init( this.mpz ); } 27 static inline void ?{}( Int & this, Int init ) { mpz_init_set( this.mpz, init.mpz ); } 28 static inline void ?{}( Int & this, zero_t ) { mpz_init_set_si( this.mpz, 0 ); } 29 static inline void ?{}( Int & this, one_t ) { mpz_init_set_si( this.mpz, 1 ); } 30 static inline void ?{}( Int & this, signed long int init ) { mpz_init_set_si( this.mpz, init ); } 31 static inline void ?{}( Int & this, unsigned long int init ) { mpz_init_set_ui( this.mpz, init ); } 32 static inline void ?{}( Int & this, const char * val ) { if ( mpz_init_set_str( this.mpz, val, 0 ) ) abort(); } 33 static inline void ^?{}( Int & this ) { mpz_clear( this.mpz ); } 34 34 35 35 // assignment 36 static inline Int ?=?( Int * lhs, Int rhs ) { mpz_set( lhs->mpz, rhs.mpz ); return *lhs; }37 static inline Int ?=?( Int * lhs, long int rhs ) { mpz_set_si( lhs->mpz, rhs ); return *lhs; }38 static inline Int ?=?( Int * lhs, unsigned long int rhs ) { mpz_set_ui( lhs->mpz, rhs ); return *lhs; }39 static inline Int ?=?( Int * lhs, const char * rhs ) { if ( mpz_set_str( lhs->mpz, rhs, 0 ) ) { printf( "invalid string conversion\n" ); abort(); } return *lhs; }40 41 static inline char ?=?( char * lhs, Int rhs ) { char val = mpz_get_si( rhs.mpz ); *lhs = val; return val; }42 static inline short int ?=?( short int * lhs, Int rhs ) { short int val = mpz_get_si( rhs.mpz ); *lhs = val; return val; }43 static inline int ?=?( int * lhs, Int rhs ) { int val = mpz_get_si( rhs.mpz ); *lhs = val; return val; }44 static inline long int ?=?( long int * lhs, Int rhs ) { long int val = mpz_get_si( rhs.mpz ); *lhs = val; return val; }45 static inline unsigned char ?=?( unsigned char * lhs, Int rhs ) { unsigned char val = mpz_get_ui( rhs.mpz ); *lhs = val; return val; }46 static inline unsigned short int ?=?( unsigned short int * lhs, Int rhs ) { unsigned short int val = mpz_get_ui( rhs.mpz ); *lhs = val; return val; }47 static inline unsigned int ?=?( unsigned int * lhs, Int rhs ) { unsigned int val = mpz_get_ui( rhs.mpz ); *lhs = val; return val; }48 static inline unsigned long int ?=?( unsigned long int * lhs, Int rhs ) { unsigned long int val = mpz_get_ui( rhs.mpz ); *lhs = val; return val; }36 static inline Int ?=?( Int & lhs, Int rhs ) { mpz_set( lhs.mpz, rhs.mpz ); return lhs; } 37 static inline Int ?=?( Int & lhs, long int rhs ) { mpz_set_si( lhs.mpz, rhs ); return lhs; } 38 static inline Int ?=?( Int & lhs, unsigned long int rhs ) { mpz_set_ui( lhs.mpz, rhs ); return lhs; } 39 static inline Int ?=?( Int & lhs, const char * rhs ) { if ( mpz_set_str( lhs.mpz, rhs, 0 ) ) { printf( "invalid string conversion\n" ); abort(); } return lhs; } 40 41 static inline char ?=?( char & lhs, Int rhs ) { char val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 42 static inline short int ?=?( short int & lhs, Int rhs ) { short int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 43 static inline int ?=?( int & lhs, Int rhs ) { int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 44 static inline long int ?=?( long int & lhs, Int rhs ) { long int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 45 static inline unsigned char ?=?( unsigned char & lhs, Int rhs ) { unsigned char val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 46 static inline unsigned short int ?=?( unsigned short int & lhs, Int rhs ) { unsigned short int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 47 static inline unsigned int ?=?( unsigned int & lhs, Int rhs ) { unsigned int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 48 static inline unsigned long int ?=?( unsigned long int & lhs, Int rhs ) { unsigned long int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 49 49 50 50 // conversions … … 99 99 static inline Int ?&?( Int oper1, unsigned long int oper2 ) { Int conjunction, temp; mpz_set_ui( temp.mpz, oper2 ); mpz_and( conjunction.mpz, oper1.mpz, temp.mpz ); return conjunction; } 100 100 static inline Int ?&?( unsigned long int oper1, Int oper2 ) { Int conjunction, temp; mpz_set_ui( temp.mpz, oper1 ); mpz_and( conjunction.mpz, temp.mpz, oper2.mpz ); return conjunction; } 101 static inline Int ?&=?( Int * lhs, Int rhs ) { return *lhs = *lhs & rhs; }101 static inline Int ?&=?( Int & lhs, Int rhs ) { return lhs = lhs & rhs; } 102 102 103 103 static inline Int ?|?( Int oper1, Int oper2 ) { Int disjunction; mpz_ior( disjunction.mpz, oper1.mpz, oper2.mpz ); return disjunction; } … … 106 106 static inline Int ?|?( Int oper1, unsigned long int oper2 ) { Int disjunction, temp; mpz_set_ui( temp.mpz, oper2 ); mpz_ior( disjunction.mpz, oper1.mpz, temp.mpz ); return disjunction; } 107 107 static inline Int ?|?( unsigned long int oper1, Int oper2 ) { Int disjunction, temp; mpz_set_ui( temp.mpz, oper1 ); mpz_ior( disjunction.mpz, temp.mpz, oper2.mpz ); return disjunction; } 108 static inline Int ?|=?( Int * lhs, Int rhs ) { return *lhs = *lhs | rhs; }108 static inline Int ?|=?( Int & lhs, Int rhs ) { return lhs = lhs | rhs; } 109 109 110 110 static inline Int ?^?( Int oper1, Int oper2 ) { Int disjunction; mpz_xor( disjunction.mpz, oper1.mpz, oper2.mpz ); return disjunction; } … … 113 113 static inline Int ?^?( Int oper1, unsigned long int oper2 ) { Int disjunction, temp; mpz_set_ui( temp.mpz, oper2 ); mpz_ior( disjunction.mpz, oper1.mpz, temp.mpz ); return disjunction; } 114 114 static inline Int ?^?( unsigned long int oper1, Int oper2 ) { Int disjunction, temp; mpz_set_ui( temp.mpz, oper1 ); mpz_ior( disjunction.mpz, temp.mpz, oper2.mpz ); return disjunction; } 115 static inline Int ?^=?( Int * lhs, Int rhs ) { return *lhs = *lhs ^ rhs; }115 static inline Int ?^=?( Int & lhs, Int rhs ) { return lhs = lhs ^ rhs; } 116 116 117 117 static inline Int ?+?( Int addend1, Int addend2 ) { Int sum; mpz_add( sum.mpz, addend1.mpz, addend2.mpz ); return sum; } … … 120 120 static inline Int ?+?( Int addend1, unsigned long int addend2 ) { Int sum; mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); return sum; } 121 121 static inline Int ?+?( unsigned long int addend2, Int addend1 ) { Int sum; mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); return sum; } 122 static inline Int ?+=?( Int * lhs, Int rhs ) { return *lhs = *lhs + rhs; }123 static inline Int ?+=?( Int * lhs, long int rhs ) { return *lhs = *lhs + rhs; }124 static inline Int ?+=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs + rhs; }125 static inline Int ++?( Int * lhs ) { return *lhs += 1; }126 static inline Int ?++( Int * lhs ) { Int ret = *lhs; *lhs += 1; return ret; }122 static inline Int ?+=?( Int & lhs, Int rhs ) { return lhs = lhs + rhs; } 123 static inline Int ?+=?( Int & lhs, long int rhs ) { return lhs = lhs + rhs; } 124 static inline Int ?+=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs + rhs; } 125 static inline Int ++?( Int & lhs ) { return lhs += 1; } 126 static inline Int ?++( Int & lhs ) { Int ret = lhs; lhs += 1; return ret; } 127 127 128 128 static inline Int ?-?( Int minuend, Int subtrahend ) { Int diff; mpz_sub( diff.mpz, minuend.mpz, subtrahend.mpz ); return diff; } … … 131 131 static inline Int ?-?( Int minuend, unsigned long int subtrahend ) { Int diff; mpz_sub_ui( diff.mpz, minuend.mpz, subtrahend ); return diff; } 132 132 static inline Int ?-?( unsigned long int minuend, Int subtrahend ) { Int diff; mpz_ui_sub( diff.mpz, minuend, subtrahend.mpz ); return diff; } 133 static inline Int ?-=?( Int * lhs, Int rhs ) { return *lhs = *lhs - rhs; }134 static inline Int ?-=?( Int * lhs, long int rhs ) { return *lhs = *lhs - rhs; }135 static inline Int ?-=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs - rhs; }136 static inline Int --?( Int * lhs ) { return *lhs -= 1; }137 static inline Int ?--( Int * lhs ) { Int ret = *lhs; *lhs -= 1; return ret; }133 static inline Int ?-=?( Int & lhs, Int rhs ) { return lhs = lhs - rhs; } 134 static inline Int ?-=?( Int & lhs, long int rhs ) { return lhs = lhs - rhs; } 135 static inline Int ?-=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs - rhs; } 136 static inline Int --?( Int & lhs ) { return lhs -= 1; } 137 static inline Int ?--( Int & lhs ) { Int ret = lhs; lhs -= 1; return ret; } 138 138 139 139 static inline Int ?*?( Int multiplicator, Int multiplicand ) { Int product; mpz_mul( product.mpz, multiplicator.mpz, multiplicand.mpz ); return product; } … … 142 142 static inline Int ?*?( Int multiplicator, unsigned long int multiplicand ) { Int product; mpz_mul_ui( product.mpz, multiplicator.mpz, multiplicand ); return product; } 143 143 static inline Int ?*?( unsigned long int multiplicand, Int multiplicator ) { Int product; mpz_mul_ui( product.mpz, multiplicator.mpz, multiplicand ); return product; } 144 static inline Int ?*=?( Int * lhs, Int rhs ) { return *lhs = *lhs * rhs; }145 static inline Int ?*=?( Int * lhs, long int rhs ) { return *lhs = *lhs * rhs; }146 static inline Int ?*=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs * rhs; }144 static inline Int ?*=?( Int & lhs, Int rhs ) { return lhs = lhs * rhs; } 145 static inline Int ?*=?( Int & lhs, long int rhs ) { return lhs = lhs * rhs; } 146 static inline Int ?*=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs * rhs; } 147 147 148 148 // some code for operators "/" and "%" taken from g++ gmpxx.h … … 187 187 return quotient; 188 188 } // ?/? 189 static inline Int ?/=?( Int * lhs, Int rhs ) { return *lhs = *lhs / rhs; }190 static inline Int ?/=?( Int * lhs, long int rhs ) { return *lhs = *lhs / rhs; }191 static inline Int ?/=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs / rhs; }189 static inline Int ?/=?( Int & lhs, Int rhs ) { return lhs = lhs / rhs; } 190 static inline Int ?/=?( Int & lhs, long int rhs ) { return lhs = lhs / rhs; } 191 static inline Int ?/=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs / rhs; } 192 192 193 193 static inline [ Int, Int ] div( Int dividend, Int divisor ) { Int quotient, remainder; mpz_fdiv_qr( quotient.mpz, remainder.mpz, dividend.mpz, divisor.mpz ); return [ quotient, remainder ]; } … … 228 228 return remainder; 229 229 } // ?%? 230 static inline Int ?%=?( Int * lhs, Int rhs ) { return *lhs = *lhs % rhs; }231 static inline Int ?%=?( Int * lhs, long int rhs ) { return *lhs = *lhs % rhs; }232 static inline Int ?%=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs % rhs; }230 static inline Int ?%=?( Int & lhs, Int rhs ) { return lhs = lhs % rhs; } 231 static inline Int ?%=?( Int & lhs, long int rhs ) { return lhs = lhs % rhs; } 232 static inline Int ?%=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs % rhs; } 233 233 234 234 static inline Int ?<<?( Int shiften, mp_bitcnt_t shift ) { Int shifted; mpz_mul_2exp( shifted.mpz, shiften.mpz, shift ); return shifted; } 235 static inline Int ?<<=?( Int * lhs, mp_bitcnt_t shift ) { return *lhs = *lhs << shift; }235 static inline Int ?<<=?( Int & lhs, mp_bitcnt_t shift ) { return lhs = lhs << shift; } 236 236 static inline Int ?>>?( Int shiften, mp_bitcnt_t shift ) { Int shifted; mpz_fdiv_q_2exp( shifted.mpz, shiften.mpz, shift ); return shifted; } 237 static inline Int ?>>=?( Int * lhs, mp_bitcnt_t shift ) { return *lhs = *lhs >> shift; }237 static inline Int ?>>=?( Int & lhs, mp_bitcnt_t shift ) { return lhs = lhs >> shift; } 238 238 239 239 // number functions
Note: See TracChangeset
for help on using the changeset viewer.