Ignore:
Timestamp:
May 24, 2019, 10:19:41 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d908563
Parents:
6a9d4b4 (diff), 292642a (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.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/prelude/builtins.c

    r6a9d4b4 r933f32f  
    1010// Created On       : Fri Jul 21 16:21:03 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  5 21:40:38 2018
    13 // Update Count     : 20
     12// Last Modified On : Tue Mar 26 23:10:36 2019
     13// Update Count     : 95
    1414//
    1515
     
    4242typedef unsigned long long __cfaabi_abi_exception_type_t;
    4343
     44#include <limits.h>                                                                             // CHAR_BIT
    4445#include "../src/virtual.h"
    4546#include "../src/exception.h"
     
    5051// increment/decrement unification
    5152
    52 static inline forall( dtype T | { T& ?+=?( T&, one_t ); } )
    53 T& ++? ( T& x ) { return x += 1; }
     53static inline {
     54        forall( dtype DT | { DT & ?+=?( DT &, one_t ); } )
     55        DT & ++?( DT & x ) { return x += 1; }
    5456
    55 static inline forall( dtype T | sized(T) | { void ?{}( T&, T ); void ^?{}( T& ); T& ?+=?( T&, one_t ); } )
    56 T& ?++ ( T& x ) { T tmp = x; x += 1; return tmp; }
     57        forall( dtype DT | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?+=?( DT &, one_t ); } )
     58        DT & ?++( DT & x ) { DT tmp = x; x += 1; return tmp; }
    5759
    58 static inline forall( dtype T | { T& ?-=?( T&, one_t ); } )
    59 T& --? ( T& x ) { return x -= 1; }
     60        forall( dtype DT | { DT & ?-=?( DT &, one_t ); } )
     61        DT & --?( DT & x ) { return x -= 1; }
    6062
    61 static inline forall( dtype T | sized(T) | { void ?{}( T&, T ); void ^?{}( T& ); T& ?-=?( T&, one_t ); } )
    62 T& ?-- ( T& x ) { T tmp = x; x -= 1; return tmp; }
     63        forall( dtype DT | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?-=?( DT &, one_t ); } )
     64        DT & ?--( DT & x ) { DT tmp = x; x -= 1; return tmp; }
     65} // distribution
     66
     67// universal typed pointer constant
     68// Compiler issue: there is a problem with anonymous types that do not have a size.
     69static inline forall( dtype DT | sized(DT) ) DT * intptr( uintptr_t addr ) { return (DT *)addr; }
    6370
    6471// exponentiation operator implementation
     
    7380} // extern "C"
    7481
    75 static inline float ?\?( float x, float y ) { return powf( x, y ); }
    76 static inline double ?\?( double x, double y ) { return pow( x, y ); }
    77 static inline long double ?\?( long double x, long double y ) { return powl( x, y ); }
    78 static inline float _Complex ?\?( float _Complex x, _Complex float y ) { return cpowf(x, y ); }
    79 static inline double _Complex ?\?( double _Complex x, _Complex double y ) { return cpow( x, y ); }
    80 static inline long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); }
     82static inline {
     83        float ?\?( float x, float y ) { return powf( x, y ); }
     84        double ?\?( double x, double y ) { return pow( x, y ); }
     85        long double ?\?( long double x, long double y ) { return powl( x, y ); }
     86        float _Complex ?\?( float _Complex x, _Complex float y ) { return cpowf(x, y ); }
     87        double _Complex ?\?( double _Complex x, _Complex double y ) { return cpow( x, y ); }
     88        long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); }
     89} // distribution
    8190
    82 static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent
    83         if ( y == 0 ) return 1;                                                         // base case
    84         if ( ep == 2 ) return ep << (y - 1);                            // special case, positive shifting only
    85         typeof( ep ) op = 1;                                                            // accumulate odd product
    86         for ( ; y > 1; y >>= 1 ) {                                                      // squaring exponentiation, O(log2 y)
    87                 if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
    88                 ep *= ep;
    89         } // for
    90         return ep * op;
    91 } // ?\?
     91#define __CFA_BASE_COMP_1__() if ( ep == 1 ) return 1
     92#define __CFA_BASE_COMP_2__() if ( ep == 2 ) return ep << (y - 1)
     93#define __CFA_EXP_OVERFLOW__() if ( y >= sizeof(y) * CHAR_BIT ) return 0
    9294
    93 static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
    94 T ?\?( T ep, unsigned long int y ) {
    95         if ( y == 0 ) return 1;
    96         T op = 1;
    97         for ( ; y > 1; y >>= 1 ) {                                                      // squaring exponentiation, O(log2 y)
    98                 if ( (y & 1) == 1 ) op = op * ep;                               // odd ?
    99                 ep = ep * ep;
    100         } // for
    101         return ep * op;
    102 } // ?\?
     95#define __CFA_EXP__() \
     96        if ( y == 0 ) return 1;                                                         /* convention */ \
     97        __CFA_BASE_COMP_1__();                                                          /* base case */ \
     98        __CFA_BASE_COMP_2__();                                                          /* special case, positive shifting for integral types */ \
     99        __CFA_EXP_OVERFLOW__();                                                         /* immediate overflow, negative exponent > 2^size-1 */ \
     100        typeof(ep) op = 1;                                                                      /* accumulate odd product */ \
     101        for ( ; y > 1; y >>= 1 ) {                                                      /* squaring exponentiation, O(log2 y) */ \
     102                if ( (y & 1) == 1 ) op = op * ep;                               /* odd ? */ \
     103                ep = ep * ep; \
     104        } \
     105        return ep * op
    103106
    104 // unsigned computation may be faster and larger
    105 static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent
    106         if ( y == 0 ) return 1;                                                         // base case
    107         if ( ep == 2 ) return ep << (y - 1);                            // special case, positive shifting only
    108         typeof( ep ) op = 1;                                                            // accumulate odd product
    109         for ( ; y > 1; y >>= 1 ) {                                                      // squaring exponentiation, O(log2 y)
    110                 if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
    111                 ep *= ep;
    112         } // for
    113         return ep * op;
    114 } // ?\?
     107static inline {
     108        long int ?\?( int ep, unsigned int y ) { __CFA_EXP__(); }
     109        long int ?\?( long int ep, unsigned long int y ) { __CFA_EXP__(); }
     110        // unsigned computation may be faster and larger
     111        unsigned long int ?\?( unsigned int ep, unsigned int y ) { __CFA_EXP__(); }
     112        unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { __CFA_EXP__(); }
     113} // distribution
    115114
    116 static inline double ?\?( long int x, signed long int y ) {     // allow negative exponent
    117         if ( y >=  0 ) return (double)(x \ (unsigned long int)y);
    118         else return 1.0 / x \ (unsigned int)(-y);
    119 } // ?\?
     115#undef __CFA_BASE_COMP_1__
     116#undef __CFA_BASE_COMP_2__
     117#undef __CFA_EXP_OVERFLOW__
     118#define __CFA_BASE_COMP_1__()
     119#define __CFA_BASE_COMP_2__()
     120#define __CFA_EXP_OVERFLOW__()
    120121
    121 // FIXME (x \ (unsigned long int)y) relies on X ?\?(T, unsigned long) a function that is neither
    122 // defined, nor passed as an assertion parameter. Without user-defined conversions, cannot specify
    123 // X as a type that casts to double, yet it doesn't make sense to write functions with that type
    124 // signature where X is double.
     122static inline forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) {
     123        OT ?\?( OT ep, unsigned int y ) { __CFA_EXP__(); }
     124        OT ?\?( OT ep, unsigned long int y ) { __CFA_EXP__(); }
     125} // distribution
    125126
    126 // static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); double ?/?( double, T ); } )
    127 // double ?\?( T x, signed long int y ) {
    128 //     if ( y >=  0 ) return (double)(x \ (unsigned long int)y);
    129 //     else return 1.0 / x \ (unsigned long int)(-y);
    130 // } // ?\?
     127#undef __CFA_BASE_COMP_1__
     128#undef __CFA_BASE_COMP_2__
     129#undef __CFA_EXP_OVERFLOW__
    131130
    132 static inline long int ?\=?( long int & x, unsigned long int y ) { x = x \ y; return x; }
    133 static inline unsigned long int ?\=?( unsigned long int & x, unsigned long int y ) { x = x \ y; return x; }
    134 static inline int ?\=?( int & x, unsigned long int y ) { x = x \ y; return x; }
    135 static inline unsigned int ?\=?( unsigned int & x, unsigned long int y ) { x = x \ y; return x; }
     131static inline {
     132        long int ?\=?( long int & x, unsigned long int y ) { x = x \ y; return x; }
     133        unsigned long int ?\=?( unsigned long int & x, unsigned long int y ) { x = x \ y; return x; }
     134        int ?\=?( int & x, unsigned long int y ) { x = x \ y; return x; }
     135        unsigned int ?\=?( unsigned int & x, unsigned long int y ) { x = x \ y; return x; }
     136} // distribution
    136137
    137138// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.