Changes in src/prelude/builtins.c [a5f0529:fa4805f]
- File:
-
- 1 edited
-
src/prelude/builtins.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/prelude/builtins.c
ra5f0529 rfa4805f 1 //2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo3 //4 // The contents of this file are covered under the licence agreement in the5 // file "LICENCE" distributed with Cforall.6 //7 // builtins.c --8 //9 // Author : Peter A. Buhr10 // Created On : Fri Jul 21 16:21:03 201711 // Last Modified By : Andrew Beach12 // Last Modified On : Tus Jul 25 15:33:00 201713 // Update Count : 1414 //15 16 // exception implementation17 18 1 typedef unsigned long long __cfaabi_exception_type_t; 19 2 20 #include "../libcfa/virtual.h"21 3 #include "../libcfa/exception.h" 22 23 // exponentiation operator implementation24 25 extern "C" {26 float powf( float x, float y );27 double pow( double x, double y );28 long double powl( long double x, long double y );29 float _Complex cpowf( float _Complex x, _Complex float z );30 double _Complex cpow( double _Complex x, _Complex double z );31 long double _Complex cpowl( long double _Complex x, _Complex long double z );32 } // extern "C"33 34 static inline float ?\?( float x, float y ) { return powf( x, y ); }35 static inline double ?\?( double x, double y ) { return pow( x, y ); }36 static inline long double ?\?( long double x, long double y ) { return powl( x, y ); }37 static inline float _Complex ?\?( float _Complex x, _Complex float y ) { return cpowf(x, y ); }38 static inline double _Complex ?\?( double _Complex x, _Complex double y ) { return cpow( x, y ); }39 static inline long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); }40 41 static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent42 if ( y == 0 ) return 1; // base case43 if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only44 typeof( ep ) op = 1; // accumulate odd product45 for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)46 if ( (y & 1) == 1 ) op *= ep; // odd ?47 ep *= ep;48 } // for49 return ep * op;50 } // ?\?51 52 // FIX ME, cannot resolve the "T op = 1".53 54 // static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } )55 // T ?\?( T ep, unsigned long int y ) {56 // if ( y == 0 ) return 1;57 // T op = 1;58 // for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)59 // if ( (y & 1) == 1 ) op = op * ep; // odd ?60 // ep = ep * ep;61 // } // for62 // return ep * op;63 // } // ?\?64 65 // unsigned computation may be faster and larger66 static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent67 if ( y == 0 ) return 1; // base case68 if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only69 typeof( ep ) op = 1; // accumulate odd product70 for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)71 if ( (y & 1) == 1 ) op *= ep; // odd ?72 ep *= ep;73 } // for74 return ep * op;75 } // ?\?76 77 static inline double ?\?( long int x, signed long int y ) { // allow negative exponent78 if ( y >= 0 ) return (double)(x \ (unsigned long int)y);79 else return 1.0 / x \ (unsigned int)(-y);80 } // ?\?81 82 static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); double ?/?( double, T ); } )83 double ?\?( T x, signed long int y ) {84 if ( y >= 0 ) return (double)(x \ (unsigned long int)y);85 else return 1.0 / x \ (unsigned long int)(-y);86 } // ?\?87 88 static inline long int ?\=?( long int * x, unsigned long int y ) { *x = *x \ y; return *x; }89 static inline unsigned long int ?\=?( unsigned long int * x, unsigned long int y ) { *x = *x \ y; return *x; }90 static inline int ?\=?( int * x, unsigned long int y ) { *x = *x \ y; return *x; }91 static inline unsigned int ?\=?( unsigned int * x, unsigned long int y ) { *x = *x \ y; return *x; }92 93 // Local Variables: //94 // mode: c //95 // tab-width: 4 //96 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.