[a5f0529] | 1 | //
|
---|
[a1edafa] | 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
[a5f0529] | 6 | //
|
---|
| 7 | // builtins.c --
|
---|
| 8 | //
|
---|
[a1edafa] | 9 | // Author : Peter A. Buhr
|
---|
| 10 | // Created On : Fri Jul 21 16:21:03 2017
|
---|
[169d944] | 11 | // Last Modified By : Peter A. Buhr
|
---|
| 12 | // Last Modified On : Thu Feb 8 12:47:59 2018
|
---|
| 13 | // Update Count : 19
|
---|
[a5f0529] | 14 | //
|
---|
[a1edafa] | 15 |
|
---|
| 16 | // exception implementation
|
---|
| 17 |
|
---|
[36982fc] | 18 | typedef unsigned long long __cfaabi_abi_exception_type_t;
|
---|
[fa4805f] | 19 |
|
---|
[a5f0529] | 20 | #include "../libcfa/virtual.h"
|
---|
[fa4805f] | 21 | #include "../libcfa/exception.h"
|
---|
[a1edafa] | 22 |
|
---|
[169d944] | 23 | void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
|
---|
| 24 | void abort ( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
|
---|
| 25 |
|
---|
[d2887f7] | 26 | // increment/decrement unification
|
---|
| 27 |
|
---|
| 28 | static inline forall( dtype T | { T& ?+=?( T&, one_t ); } )
|
---|
| 29 | T& ++? ( T& x ) { return x += 1; }
|
---|
| 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; }
|
---|
| 33 |
|
---|
| 34 | static inline forall( dtype T | { T& ?-=?( T&, one_t ); } )
|
---|
| 35 | T& --? ( T& x ) { return x -= 1; }
|
---|
| 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; }
|
---|
| 39 |
|
---|
[a1edafa] | 40 | // exponentiation operator implementation
|
---|
| 41 |
|
---|
| 42 | extern "C" {
|
---|
| 43 | float powf( float x, float y );
|
---|
| 44 | double pow( double x, double y );
|
---|
| 45 | long double powl( long double x, long double y );
|
---|
| 46 | float _Complex cpowf( float _Complex x, _Complex float z );
|
---|
| 47 | double _Complex cpow( double _Complex x, _Complex double z );
|
---|
| 48 | long double _Complex cpowl( long double _Complex x, _Complex long double z );
|
---|
| 49 | } // extern "C"
|
---|
| 50 |
|
---|
| 51 | static inline float ?\?( float x, float y ) { return powf( x, y ); }
|
---|
| 52 | static inline double ?\?( double x, double y ) { return pow( x, y ); }
|
---|
| 53 | static inline long double ?\?( long double x, long double y ) { return powl( x, y ); }
|
---|
| 54 | static inline float _Complex ?\?( float _Complex x, _Complex float y ) { return cpowf(x, y ); }
|
---|
| 55 | static inline double _Complex ?\?( double _Complex x, _Complex double y ) { return cpow( x, y ); }
|
---|
| 56 | static inline long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); }
|
---|
| 57 |
|
---|
[fe97a7d8] | 58 | static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent
|
---|
[a1edafa] | 59 | if ( y == 0 ) return 1; // base case
|
---|
[fe97a7d8] | 60 | if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only
|
---|
| 61 | typeof( ep ) op = 1; // accumulate odd product
|
---|
[a1edafa] | 62 | for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)
|
---|
[fe97a7d8] | 63 | if ( (y & 1) == 1 ) op *= ep; // odd ?
|
---|
| 64 | ep *= ep;
|
---|
| 65 | } // for
|
---|
| 66 | return ep * op;
|
---|
[a1edafa] | 67 | } // ?\?
|
---|
| 68 |
|
---|
[fe97a7d8] | 69 | // FIX ME, cannot resolve the "T op = 1".
|
---|
[a1edafa] | 70 |
|
---|
| 71 | // static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } )
|
---|
[fe97a7d8] | 72 | // T ?\?( T ep, unsigned long int y ) {
|
---|
[a1edafa] | 73 | // if ( y == 0 ) return 1;
|
---|
[fe97a7d8] | 74 | // T op = 1;
|
---|
[a1edafa] | 75 | // for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)
|
---|
[fe97a7d8] | 76 | // if ( (y & 1) == 1 ) op = op * ep; // odd ?
|
---|
| 77 | // ep = ep * ep;
|
---|
[a1edafa] | 78 | // } // for
|
---|
[fe97a7d8] | 79 | // return ep * op;
|
---|
[a1edafa] | 80 | // } // ?\?
|
---|
| 81 |
|
---|
| 82 | // unsigned computation may be faster and larger
|
---|
[fe97a7d8] | 83 | static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent
|
---|
[a1edafa] | 84 | if ( y == 0 ) return 1; // base case
|
---|
[fe97a7d8] | 85 | if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only
|
---|
| 86 | typeof( ep ) op = 1; // accumulate odd product
|
---|
[a1edafa] | 87 | for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)
|
---|
[fe97a7d8] | 88 | if ( (y & 1) == 1 ) op *= ep; // odd ?
|
---|
| 89 | ep *= ep;
|
---|
| 90 | } // for
|
---|
| 91 | return ep * op;
|
---|
[a1edafa] | 92 | } // ?\?
|
---|
| 93 |
|
---|
[fe97a7d8] | 94 | static inline double ?\?( long int x, signed long int y ) { // allow negative exponent
|
---|
[a1edafa] | 95 | if ( y >= 0 ) return (double)(x \ (unsigned long int)y);
|
---|
| 96 | else return 1.0 / x \ (unsigned int)(-y);
|
---|
| 97 | } // ?\?
|
---|
| 98 |
|
---|
[36982fc] | 99 | // FIXME (x \ (unsigned long int)y) relies on X ?\?(T, unsigned long) a function that is neither
|
---|
| 100 | // defined, nor passed as an assertion parameter. Without user-defined conversions, cannot specify
|
---|
| 101 | // X as a type that casts to double, yet it doesn't make sense to write functions with that type
|
---|
[e472d54] | 102 | // signature where X is double.
|
---|
| 103 |
|
---|
| 104 | // static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); double ?/?( double, T ); } )
|
---|
| 105 | // double ?\?( T x, signed long int y ) {
|
---|
| 106 | // if ( y >= 0 ) return (double)(x \ (unsigned long int)y);
|
---|
| 107 | // else return 1.0 / x \ (unsigned long int)(-y);
|
---|
| 108 | // } // ?\?
|
---|
[a1edafa] | 109 |
|
---|
[1ae06fa] | 110 | static inline long int ?\=?( long int & x, unsigned long int y ) { x = x \ y; return x; }
|
---|
| 111 | static inline unsigned long int ?\=?( unsigned long int & x, unsigned long int y ) { x = x \ y; return x; }
|
---|
| 112 | static inline int ?\=?( int & x, unsigned long int y ) { x = x \ y; return x; }
|
---|
| 113 | static inline unsigned int ?\=?( unsigned int & x, unsigned long int y ) { x = x \ y; return x; }
|
---|
[a1edafa] | 114 |
|
---|
| 115 | // Local Variables: //
|
---|
| 116 | // mode: c //
|
---|
| 117 | // tab-width: 4 //
|
---|
| 118 | // End: //
|
---|