Changeset 88ac8672


Ignore:
Timestamp:
Apr 13, 2021, 5:37:01 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
4c4e444
Parents:
e07b589
Message:

formatting, add long long versions for exponentiation operator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/prelude/builtins.c

    re07b589 r88ac8672  
    99// Author           : Peter A. Buhr
    1010// Created On       : Fri Jul 21 16:21:03 2017
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Oct 27 14:42:00 2020
    13 // Update Count     : 111
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Apr 13 17:26:32 2021
     13// Update Count     : 117
    1414//
    1515
     
    125125} // distribution
    126126
    127 #define __CFA_BASE_COMP_1__() if ( ep == 1 ) return 1
    128 #define __CFA_BASE_COMP_2__() if ( ep == 2 ) return ep << (y - 1)
     127#define __CFA_BASE_COMP_1__() if ( x == 1 ) return 1
     128#define __CFA_BASE_COMP_2__() if ( x == 2 ) return x << (y - 1)
    129129#define __CFA_EXP_OVERFLOW__() if ( y >= sizeof(y) * CHAR_BIT ) return 0
    130130
     
    134134        __CFA_BASE_COMP_2__();                                                          /* special case, positive shifting for integral types */ \
    135135        __CFA_EXP_OVERFLOW__();                                                         /* immediate overflow, negative exponent > 2^size-1 */ \
    136         typeof(ep) op = 1;                                                                      /* accumulate odd product */ \
     136        typeof(x) op = 1;                                                                       /* accumulate odd product */ \
    137137        for ( ; y > 1; y >>= 1 ) {                                                      /* squaring exponentiation, O(log2 y) */ \
    138                 if ( (y & 1) == 1 ) op = op * ep;                               /* odd ? */ \
    139                 ep = ep * ep; \
     138                if ( (y & 1) == 1 ) op = op * x;                                /* odd ? */ \
     139                x = x * x; \
    140140        } \
    141         return ep * op
     141        return x * op
    142142
    143143static inline {
    144         long int ?\?( int ep, unsigned int y ) { __CFA_EXP__(); }
    145         long int ?\?( long int ep, unsigned long int y ) { __CFA_EXP__(); }
     144        long int ?\?( int x, unsigned int y ) { __CFA_EXP__(); }
     145        long int ?\?( long int x, unsigned long int y ) { __CFA_EXP__(); }
     146        long long int ?\?( long long int x, unsigned long long int y ) { __CFA_EXP__(); }
    146147        // unsigned computation may be faster and larger
    147         unsigned long int ?\?( unsigned int ep, unsigned int y ) { __CFA_EXP__(); }
    148         unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { __CFA_EXP__(); }
     148        unsigned long int ?\?( unsigned int x, unsigned int y ) { __CFA_EXP__(); }
     149        unsigned long int ?\?( unsigned long int x, unsigned long int y ) { __CFA_EXP__(); }
     150        unsigned long long int ?\?( unsigned long long int x, unsigned long long int y ) { __CFA_EXP__(); }
    149151} // distribution
    150152
     
    157159
    158160static inline forall( OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) {
    159         OT ?\?( OT ep, unsigned int y ) { __CFA_EXP__(); }
    160         OT ?\?( OT ep, unsigned long int y ) { __CFA_EXP__(); }
     161        OT ?\?( OT x, unsigned int y ) { __CFA_EXP__(); }
     162        OT ?\?( OT x, unsigned long int y ) { __CFA_EXP__(); }
     163        OT ?\?( OT x, unsigned long long int y ) { __CFA_EXP__(); }
    161164} // distribution
    162165
     
    166169
    167170static inline {
     171        long int ?\=?( int & x, unsigned int y ) { x = x \ y; return x; }
    168172        long int ?\=?( long int & x, unsigned long int y ) { x = x \ y; return x; }
     173        long long int ?\=?( long long int & x, unsigned long long int y ) { x = x \ y; return x; }
     174        unsigned long int ?\=?( unsigned int & x, unsigned int y ) { x = x \ y; return x; }
    169175        unsigned long int ?\=?( unsigned long int & x, unsigned long int y ) { x = x \ y; return x; }
    170         int ?\=?( int & x, unsigned long int y ) { x = x \ y; return x; }
    171         unsigned int ?\=?( unsigned int & x, unsigned long int y ) { x = x \ y; return x; }
     176        unsigned long long int ?\=?( unsigned long long int & x, unsigned long long int y ) { x = x \ y; return x; }
    172177} // distribution
    173178
Note: See TracChangeset for help on using the changeset viewer.