| 1 | //
|
|---|
| 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.
|
|---|
| 6 | //
|
|---|
| 7 | // builtins.c --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Peter A. Buhr
|
|---|
| 10 | // Created On : Fri Jul 21 16:21:03 2017
|
|---|
| 11 | // Last Modified By : Peter A. Buhr
|
|---|
| 12 | // Last Modified On : Thu Feb 8 12:47:59 2018
|
|---|
| 13 | // Update Count : 19
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | // exception implementation
|
|---|
| 17 |
|
|---|
| 18 | typedef unsigned long long __cfaabi_abi_exception_type_t;
|
|---|
| 19 |
|
|---|
| 20 | #include "../libcfa/virtual.h"
|
|---|
| 21 | #include "../libcfa/exception.h"
|
|---|
| 22 |
|
|---|
| 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 |
|
|---|
| 26 | // exponentiation operator implementation
|
|---|
| 27 |
|
|---|
| 28 | extern "C" {
|
|---|
| 29 | float powf( float x, float y );
|
|---|
| 30 | double pow( double x, double y );
|
|---|
| 31 | long double powl( long double x, long double y );
|
|---|
| 32 | float _Complex cpowf( float _Complex x, _Complex float z );
|
|---|
| 33 | double _Complex cpow( double _Complex x, _Complex double z );
|
|---|
| 34 | long double _Complex cpowl( long double _Complex x, _Complex long double z );
|
|---|
| 35 | } // extern "C"
|
|---|
| 36 |
|
|---|
| 37 | static inline float ?\?( float x, float y ) { return powf( x, y ); }
|
|---|
| 38 | static inline double ?\?( double x, double y ) { return pow( x, y ); }
|
|---|
| 39 | static inline long double ?\?( long double x, long double y ) { return powl( x, y ); }
|
|---|
| 40 | static inline float _Complex ?\?( float _Complex x, _Complex float y ) { return cpowf(x, y ); }
|
|---|
| 41 | static inline double _Complex ?\?( double _Complex x, _Complex double y ) { return cpow( x, y ); }
|
|---|
| 42 | static inline long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); }
|
|---|
| 43 |
|
|---|
| 44 | static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent
|
|---|
| 45 | if ( y == 0 ) return 1; // base case
|
|---|
| 46 | if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only
|
|---|
| 47 | typeof( ep ) op = 1; // accumulate odd product
|
|---|
| 48 | for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)
|
|---|
| 49 | if ( (y & 1) == 1 ) op *= ep; // odd ?
|
|---|
| 50 | ep *= ep;
|
|---|
| 51 | } // for
|
|---|
| 52 | return ep * op;
|
|---|
| 53 | } // ?\?
|
|---|
| 54 |
|
|---|
| 55 | // FIX ME, cannot resolve the "T op = 1".
|
|---|
| 56 |
|
|---|
| 57 | // static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } )
|
|---|
| 58 | // T ?\?( T ep, unsigned long int y ) {
|
|---|
| 59 | // if ( y == 0 ) return 1;
|
|---|
| 60 | // T op = 1;
|
|---|
| 61 | // for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)
|
|---|
| 62 | // if ( (y & 1) == 1 ) op = op * ep; // odd ?
|
|---|
| 63 | // ep = ep * ep;
|
|---|
| 64 | // } // for
|
|---|
| 65 | // return ep * op;
|
|---|
| 66 | // } // ?\?
|
|---|
| 67 |
|
|---|
| 68 | // unsigned computation may be faster and larger
|
|---|
| 69 | static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent
|
|---|
| 70 | if ( y == 0 ) return 1; // base case
|
|---|
| 71 | if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only
|
|---|
| 72 | typeof( ep ) op = 1; // accumulate odd product
|
|---|
| 73 | for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)
|
|---|
| 74 | if ( (y & 1) == 1 ) op *= ep; // odd ?
|
|---|
| 75 | ep *= ep;
|
|---|
| 76 | } // for
|
|---|
| 77 | return ep * op;
|
|---|
| 78 | } // ?\?
|
|---|
| 79 |
|
|---|
| 80 | static inline double ?\?( long int x, signed long int y ) { // allow negative exponent
|
|---|
| 81 | if ( y >= 0 ) return (double)(x \ (unsigned long int)y);
|
|---|
| 82 | else return 1.0 / x \ (unsigned int)(-y);
|
|---|
| 83 | } // ?\?
|
|---|
| 84 |
|
|---|
| 85 | // FIXME (x \ (unsigned long int)y) relies on X ?\?(T, unsigned long) a function that is neither
|
|---|
| 86 | // defined, nor passed as an assertion parameter. Without user-defined conversions, cannot specify
|
|---|
| 87 | // X as a type that casts to double, yet it doesn't make sense to write functions with that type
|
|---|
| 88 | // signature where X is double.
|
|---|
| 89 |
|
|---|
| 90 | // static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); double ?/?( double, T ); } )
|
|---|
| 91 | // double ?\?( T x, signed long int y ) {
|
|---|
| 92 | // if ( y >= 0 ) return (double)(x \ (unsigned long int)y);
|
|---|
| 93 | // else return 1.0 / x \ (unsigned long int)(-y);
|
|---|
| 94 | // } // ?\?
|
|---|
| 95 |
|
|---|
| 96 | static inline long int ?\=?( long int & x, unsigned long int y ) { x = x \ y; return x; }
|
|---|
| 97 | static inline unsigned long int ?\=?( unsigned long int & x, unsigned long int y ) { x = x \ y; return x; }
|
|---|
| 98 | static inline int ?\=?( int & x, unsigned long int y ) { x = x \ y; return x; }
|
|---|
| 99 | static inline unsigned int ?\=?( unsigned int & x, unsigned long int y ) { x = x \ y; return x; }
|
|---|
| 100 |
|
|---|
| 101 | // Local Variables: //
|
|---|
| 102 | // mode: c //
|
|---|
| 103 | // tab-width: 4 //
|
|---|
| 104 | // End: //
|
|---|