// // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // builtins.c -- // // Author : Peter A. Buhr // Created On : Fri Jul 21 16:21:03 2017 // Last Modified By : Peter A. Buhr // Last Modified On : Fri Jul 21 17:01:54 2017 // Update Count : 11 // // exception implementation typedef unsigned long long __cfaabi_exception_type_t; #include "../libcfa/exception.h" // exponentiation operator implementation extern "C" { float powf( float x, float y ); double pow( double x, double y ); long double powl( long double x, long double y ); float _Complex cpowf( float _Complex x, _Complex float z ); double _Complex cpow( double _Complex x, _Complex double z ); long double _Complex cpowl( long double _Complex x, _Complex long double z ); } // extern "C" static inline float ?\?( float x, float y ) { return powf( x, y ); } static inline double ?\?( double x, double y ) { return pow( x, y ); } static inline long double ?\?( long double x, long double y ) { return powl( x, y ); } static inline float _Complex ?\?( float _Complex x, _Complex float y ) { return cpowf(x, y ); } static inline double _Complex ?\?( double _Complex x, _Complex double y ) { return cpow( x, y ); } static inline long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); } static inline long int ?\?( long int pe, unsigned long y ) { // disallow negative exponent if ( y == 0 ) return 1; // base case if ( pe == 2 ) return pe << (y - 1); // special case, positive shifting only typeof( pe ) po = 1; // accumulate odd product for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) if ( (y & 1) == 1 ) po *= pe; // odd ? pe *= pe; } // while return pe * po; } // ?\? // FIX ME, cannot resolve the "T po = 1". // static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } ) // T ?\?( T pe, unsigned long y ) { // if ( y == 0 ) return 1; // T po = 1; // for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) // if ( (y & 1) == 1 ) po = po * pe; // odd ? // pe = pe * pe; // } // for // return pe * po; // } // ?\? // unsigned computation may be faster and larger static inline unsigned long int ?\?( unsigned long int pe, unsigned long y ) { // disallow negative exponent if ( y == 0 ) return 1; // base case if ( pe == 2 ) return pe << (y - 1); // special case, positive shifting only typeof( pe ) po = 1; // accumulate odd product for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) if ( (y & 1) == 1 ) po *= pe; // odd ? pe *= pe; } // while return pe * po; } // ?\? static inline double ?\?( long int x, signed long y ) { // allow negative exponent if ( y >= 0 ) return (double)(x \ (unsigned long int)y); else return 1.0 / x \ (unsigned int)(-y); } // ?\? static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); double ?/?( double, T ); } ) double ?\?( T x, signed long y ) { if ( y >= 0 ) return (double)(x \ (unsigned long int)y); else return 1.0 / x \ (unsigned int)(-y); } // ?\? static inline long int ?\=?( long int * x, unsigned long y ) { *x = *x \ y; return *x; } static inline long int ?\=?( unsigned long int * x, unsigned long y ) { *x = *x \ y; return *x; } static inline int ?\=?( int * x, unsigned long y ) { *x = *x \ y; return *x; } static inline int ?\=?( unsigned int * x, unsigned long y ) { *x = *x \ y; return *x; } // Local Variables: // // mode: c // // tab-width: 4 // // End: //