Changeset 8dbfb7e for libcfa/prelude
- Timestamp:
- Mar 26, 2019, 5:07:10 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 363b48f
- Parents:
- ae6b6cf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/prelude/builtins.c
rae6b6cf r8dbfb7e 10 10 // Created On : Fri Jul 21 16:21:03 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Mar 10 10:52:50201913 // Update Count : 3112 // Last Modified On : Tue Mar 26 14:05:49 2019 13 // Update Count : 84 14 14 // 15 15 … … 26 26 // increment/decrement unification 27 27 28 static inline forall( dtype T | { T & ?+=?(T &, one_t ); } )29 T & ++? (T & x ) { return x += 1; }28 static inline forall( dtype DT | { DT & ?+=?( DT &, one_t ); } ) 29 DT & ++?( DT & x ) { return x += 1; } 30 30 31 static inline forall( dtype T | sized(T) | { void ?{}( T &, T ); void ^?{}( T & ); T & ?+=?(T &, one_t ); } )32 T & ?++ ( T & x ) {T tmp = x; x += 1; return tmp; }31 static inline forall( dtype DT | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?+=?( DT &, one_t ); } ) 32 DT & ?++( DT & x ) { DT tmp = x; x += 1; return tmp; } 33 33 34 static inline forall( dtype T | { T & ?-=?(T &, one_t ); } )35 T & --? (T & x ) { return x -= 1; }34 static inline forall( dtype DT | { DT & ?-=?( DT &, one_t ); } ) 35 DT & --?( DT & x ) { return x -= 1; } 36 36 37 static inline forall( dtype T | sized(T) | { void ?{}( T &, T ); void ^?{}( T & ); T & ?-=?(T &, one_t ); } )38 T & ?-- ( T & x ) {T tmp = x; x -= 1; return tmp; }37 static inline forall( dtype DT | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?-=?( DT &, one_t ); } ) 38 DT & ?--( DT & x ) { DT tmp = x; x -= 1; return tmp; } 39 39 40 40 // universal typed pointer constant 41 41 42 static inline forall( dtype T ) T * intptr( uintptr_t addr ) { return (T *)addr; } 42 // Compiler issue: there is a problem with anonymous types that do not have a size. 43 static inline forall( dtype DT | sized(DT) ) DT * intptr( uintptr_t addr ) { return (DT *)addr; } 43 44 44 45 // exponentiation operator implementation … … 60 61 static inline long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); } 61 62 62 static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent 63 if ( y == 0 ) return 1; // base case 64 if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only 65 typeof( ep ) op = 1; // accumulate odd product 66 for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) 67 if ( (y & 1) == 1 ) op *= ep; // odd ? 68 ep *= ep; 69 } // for 70 return ep * op; 63 #define __CFA_EXP__() \ 64 if ( y == 0 ) return 1; /* base case */ \ 65 __CFA_BASE_COMP_1__() /* base case */ \ 66 __CFA_BASE_COMP_2__() /* special case, positive shifting for integral types */ \ 67 __CFA_EXP_OVERFLOW__() /* immediate overflow, negative exponent > 2^size-1 */ \ 68 typeof(ep) op = 1; /* accumulate odd product */ \ 69 for ( ; y > 1; y >>= 1 ) { /* squaring exponentiation, O(log2 y) */ \ 70 if ( (y & 1) == 1 ) op = op * ep; /* odd ? */ \ 71 ep = ep * ep; \ 72 } \ 73 return ep * op 74 75 #define __CFA_BASE_COMP_1__() if ( ep == 1 ) return 1; 76 #define __CFA_BASE_COMP_2__() if ( ep == 2 ) return ep << (y - 1); 77 #define __CFA_EXP_OVERFLOW__() if ( y >= sizeof(y) * 8 ) return 0; 78 79 static inline long int ?\?( int ep, unsigned int y ) { 80 __CFA_EXP__(); 71 81 } // ?\? 72 82 73 static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } ) 74 T ?\?( T ep, unsigned long int y ) { 75 if ( y == 0 ) return 1; 76 T op = 1; 77 for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) 78 if ( (y & 1) == 1 ) op = op * ep; // odd ? 79 ep = ep * ep; 80 } // for 81 return ep * op; 83 static inline long int ?\?( long int ep, unsigned long int y ) { 84 __CFA_EXP__(); 82 85 } // ?\? 83 86 84 87 // unsigned computation may be faster and larger 85 static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent 86 if ( y == 0 ) return 1; // base case 87 if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only 88 typeof( ep ) op = 1; // accumulate odd product 89 for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) 90 if ( (y & 1) == 1 ) op *= ep; // odd ? 91 ep *= ep; 92 } // for 93 return ep * op; 88 static inline unsigned long int ?\?( unsigned int ep, unsigned int y ) { 89 __CFA_EXP__(); 94 90 } // ?\? 95 91 96 static inline double ?\?( long int x, signed long int y ) { // allow negative exponent 97 if ( y >= 0 ) return (double)(x \ (unsigned long int)y); 98 else return 1.0 / x \ (unsigned int)(-y); 92 static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { 93 __CFA_EXP__(); 99 94 } // ?\? 100 95 101 // FIXME (x \ (unsigned long int)y) relies on X ?\?(T, unsigned long) a function that is neither 102 // defined, nor passed as an assertion parameter. Without user-defined conversions, cannot specify 103 // X as a type that casts to double, yet it doesn't make sense to write functions with that type 104 // signature where X is double. 96 #undef __CFA_BASE_COMP_1__ 97 #undef __CFA_BASE_COMP_2__ 98 #undef __CFA_EXP_OVERFLOW__ 99 #define __CFA_BASE_COMP_1__() 100 #define __CFA_BASE_COMP_2__() 101 #define __CFA_EXP_OVERFLOW__() 105 102 106 // static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); double ?/?( double, T ); } ) 107 // double ?\?( T x, signed long int y ) { 108 // if ( y >= 0 ) return (double)(x \ (unsigned long int)y); 109 // else return 1.0 / x \ (unsigned long int)(-y); 110 // } // ?\? 103 static inline forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) 104 OT ?\?( OT ep, unsigned int y ) { 105 __CFA_EXP__(); 106 } // ?\? 107 108 static inline forall( otype OT | { void ?{}( OT & this, zero_t ); void ?{}( OT & this, one_t ); int ?==?( OT, OT ); OT ?*?( OT, OT ); } ) 109 OT ?\?( OT ep, unsigned long int y ) { 110 __CFA_EXP__(); 111 } // ?\? 112 113 #undef __CFA_BASE_COMP_1__ 114 #undef __CFA_BASE_COMP_2__ 115 #undef __CFA_EXP_OVERFLOW__ 111 116 112 117 static inline long int ?\=?( long int & x, unsigned long int y ) { x = x \ y; return x; }
Note: See TracChangeset
for help on using the changeset viewer.