Changeset 3e2e9b2 for libcfa/prelude/builtins.c
- Timestamp:
- Nov 28, 2024, 3:31:29 PM (3 weeks ago)
- Branches:
- master
- Children:
- 509ec82
- Parents:
- 956b389 (diff), f5e37a4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/prelude/builtins.c
r956b389 r3e2e9b2 44 44 typedef unsigned long long __cfaabi_abi_exception_type_t; 45 45 46 #include <limits.h> // CHAR_BIT47 46 #include "../src/virtual.h" 48 47 #include "../src/exception.h" … … 132 131 } // distribution 133 132 134 #define __CFA_EXP__() \ 135 if ( y == 0 ) return 1; /* convention */ \ 136 __CFA_EXP_INT__( /* special cases for integral types */ \ 137 if ( x == 1 ) return 1; /* base case */ \ 138 if ( x == 2 ) return x << (y - 1); /* positive shifting */ \ 139 if ( y >= sizeof(y) * CHAR_BIT ) return 0; /* immediate overflow, negative exponent > 2^size-1 */ \ 140 ) \ 141 typeof(x) op = 1; /* accumulate odd product */ \ 142 typeof(x) w = x; /* FIX-ME: possible bug in the box pass changing value argument through parameter */ \ 143 for ( ; y > 1; y >>= 1 ) { /* squaring exponentiation, O(log2 y) */ \ 144 if ( (y & 1) == 1 ) op = op * w; /* odd ? */ \ 145 w = w * w; \ 146 } \ 147 return w * op 148 #define __CFA_EXP_INT__(...) __VA_ARGS__ 133 int ?\?( int x, unsigned int y ); 134 long int ?\?( long int x, unsigned long int y ); 135 long long int ?\?( long long int x, unsigned long long int y ); 136 // unsigned computation may be faster and larger 137 unsigned int ?\?( unsigned int x, unsigned int y ); 138 unsigned long int ?\?( unsigned long int x, unsigned long int y ); 139 unsigned long long int ?\?( unsigned long long int x, unsigned long long int y ); 149 140 150 static inline { 151 int ?\?( int x, unsigned int y ) { __CFA_EXP__(); } 152 long int ?\?( long int x, unsigned long int y ) { __CFA_EXP__(); } 153 long long int ?\?( long long int x, unsigned long long int y ) { __CFA_EXP__(); } 154 // unsigned computation may be faster and larger 155 unsigned int ?\?( unsigned int x, unsigned int y ) { __CFA_EXP__(); } 156 unsigned long int ?\?( unsigned long int x, unsigned long int y ) { __CFA_EXP__(); } 157 unsigned long long int ?\?( unsigned long long int x, unsigned long long int y ) { __CFA_EXP__(); } 141 forall( OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) { 142 OT ?\?( OT x, unsigned int y ); 143 OT ?\?( OT x, unsigned long int y ); 144 OT ?\?( OT x, unsigned long long int y ); 158 145 } // distribution 159 160 #undef __CFA_EXP_INT__161 #define __CFA_EXP_INT__(...)162 163 static inline forall( OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) {164 OT ?\?( OT x, unsigned int y ) { __CFA_EXP__(); }165 OT ?\?( OT x, unsigned long int y ) { __CFA_EXP__(); }166 OT ?\?( OT x, unsigned long long int y ) { __CFA_EXP__(); }167 } // distribution168 169 #undef __CFA_EXP_INT__170 #undef __CFA_EXP__171 146 172 147 static inline {
Note: See TracChangeset
for help on using the changeset viewer.