Changeset da3b790
- Timestamp:
- Aug 10, 2020, 2:23:29 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- fd24f8c
- Parents:
- c1f38e6c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bitmanip.hfa
rc1f38e6c rda3b790 11 11 // Created On : Sat Mar 14 18:12:27 2020 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Tue Jun 9 15:14:04202014 // Update Count : 1 2313 // Last Modified On : Mon Aug 10 09:21:02 2020 14 // Update Count : 139 15 15 // 16 16 … … 21 21 // Bits are numbered 1-N. 22 22 23 //#include <assert.h>23 #include <assert.h> 24 24 25 25 #define __bitsizeof( n ) (sizeof(n) * __CHAR_BIT__) … … 89 89 90 90 // Returns n aligned at the floor of align, clear bits above or equal to align, giving n % align. 91 signed char floor2( signed char n, char align ) { /*assert( is_pow2( align ) );*/return n & -align; }92 unsigned char floor2( unsigned char n, unsigned char align ) { /*assert( is_pow2( align ) );*/return n & -align; }93 short int floor2( short int n, short int align ) { /*assert( is_pow2( align ) );*/return n & -align; }94 unsigned short int floor2( unsigned short int n, unsigned short int align ) { /*assert( is_pow2( align ) );*/return n & -align; }95 int floor2( int n, int align ) { /*assert( is_pow2( align ) );*/return n & -align; }96 unsigned int floor2( unsigned int n, unsigned int align ) { /*assert( is_pow2( align ) );*/return n & -align; }97 long int floor2( long int n, long int align ) { /*assert( is_pow2( align ) );*/return n & -align; }98 unsigned long int floor2( unsigned long int n, unsigned long int align ) { /*assert( is_pow2( align ) );*/return n & -align; }99 long long int floor2( long long int n, long long int align ) { /*assert( is_pow2( align ) );*/return n & -align; }100 unsigned long long int floor2( unsigned long long int n, unsigned long long int align ) { /*assert( is_pow2( align ) );*/return n & -align; }91 signed char floor2( signed char n, signed char align ) { verify( is_pow2( align ) ); return n & -align; } 92 unsigned char floor2( unsigned char n, unsigned char align ) { verify( is_pow2( align ) ); return n & -align; } 93 short int floor2( short int n, short int align ) { verify( is_pow2( align ) ); return n & -align; } 94 unsigned short int floor2( unsigned short int n, unsigned short int align ) { verify( is_pow2( align ) ); return n & -align; } 95 int floor2( int n, int align ) { verify( is_pow2( align ) ); return n & -align; } 96 unsigned int floor2( unsigned int n, unsigned int align ) { verify( is_pow2( align ) ); return n & -align; } 97 long int floor2( long int n, long int align ) { verify( is_pow2( align ) ); return n & -align; } 98 unsigned long int floor2( unsigned long int n, unsigned long int align ) { verify( is_pow2( align ) ); return n & -align; } 99 long long int floor2( long long int n, long long int align ) { verify( is_pow2( align ) ); return n & -align; } 100 unsigned long long int floor2( unsigned long long int n, unsigned long long int align ) { verify( is_pow2( align ) ); return n & -align; } 101 101 102 102 // forall( otype T | { T ?&?( T, T ); T -?( T ); } ) 103 // T floor2( T n, T align ) { /* assert( is_pow2( align ) ); */return n & -align; }103 // T floor2( T n, T align ) { verify( is_pow2( align ) ); return n & -align; } 104 104 105 signed char floor( signed char n, char align ) { return n / align * align; }105 signed char floor( signed char n, signed char align ) { return n / align * align; } 106 106 unsigned char floor( unsigned char n, unsigned char align ) { return n / align * align; } 107 107 short int floor( short int n, short int align ) { return n / align * align; } … … 118 118 119 119 // Returns n aligned at the ceiling of align, negate, round down, negate is the same as round up. 120 signed char ceiling2( signed char n, char align ) { /*assert( is_pow2( align ) );*/return -floor2( -n, align ); }121 unsigned char ceiling2( unsigned char n, unsigned char align ) { /*assert( is_pow2( align ) );*/return -floor2( -n, align ); }122 short int ceiling2( short int n, short int align ) { /*assert( is_pow2( align ) );*/return -floor2( -n, align ); }123 unsigned short int ceiling2( unsigned short int n, unsigned short int align ) { /*assert( is_pow2( align ) );*/return -floor2( -n, align ); }124 int ceiling2( int n, int align ) { /*assert( is_pow2( align ) );*/return -floor2( -n, align ); }125 unsigned int ceiling2( unsigned int n, unsigned int align ) { /*assert( is_pow2( align ) );*/return -floor2( -n, align ); }126 long int ceiling2( long int n, long int align ) { /*assert( is_pow2( align ) );*/return -floor2( -n, align ); }127 unsigned long int ceiling2( unsigned long int n, unsigned long int align ) { /*assert( is_pow2( align ) );*/return -floor2( -n, align ); }128 long long int ceiling2( long long int n, long long int align ) { /*assert( is_pow2( align ) );*/return -floor2( -n, align ); }129 unsigned long long int ceiling2( unsigned long long int n, unsigned long long int align ) { /*assert( is_pow2( align ) );*/return -floor2( -n, align ); }120 signed char ceiling2( signed char n, signed char align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 121 unsigned char ceiling2( unsigned char n, unsigned char align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 122 short int ceiling2( short int n, short int align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 123 unsigned short int ceiling2( unsigned short int n, unsigned short int align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 124 int ceiling2( int n, int align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 125 unsigned int ceiling2( unsigned int n, unsigned int align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 126 long int ceiling2( long int n, long int align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 127 unsigned long int ceiling2( unsigned long int n, unsigned long int align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 128 long long int ceiling2( long long int n, long long int align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 129 unsigned long long int ceiling2( unsigned long long int n, unsigned long long int align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 130 130 131 131 // forall( otype T | { T floor2( T, T ); T -?( T ); } ) 132 // T ceiling2( T n, T align ) { /* assert( is_pow2( align ) ); */return -floor2( -n, align ); }132 // T ceiling2( T n, T align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 133 133 134 signed char ceiling( signed char n, char align ) { return (n + (align - 1)) / align; } 135 unsigned char ceiling( unsigned char n, unsigned char align ) { return (n + (align - 1)) / align; } 136 short int ceiling( short int n, short int align ) { return (n + (align - 1)) / align; } 137 unsigned short int ceiling( unsigned short int n, unsigned short int align ) { return (n + (align - 1)) / align; } 138 int ceiling( int n, int align ) { return (n + (align - 1)) / align; } 139 unsigned int ceiling( unsigned int n, unsigned int align ) { return (n + (align - 1)) / align; } 140 long int ceiling( long int n, long int align ) { return (n + (align - 1)) / align; } 141 unsigned long int ceiling( unsigned long int n, unsigned long int align ) { return (n + (align - 1)) / align; } 142 long long int ceiling( long long int n, long long int align ) { return (n + (align - 1)) / align; } 143 unsigned long long int ceiling( unsigned long long int n, unsigned long long int align ) { return (n + (align - 1)) / align; } 134 signed char ceiling_div( signed char n, char align ) { return (n + (align - 1)) / align; } 135 unsigned char ceiling_div( unsigned char n, unsigned char align ) { return (n + (align - 1)) / align; } 136 short int ceiling_div( short int n, short int align ) { return (n + (align - 1)) / align; } 137 unsigned short int ceiling_div( unsigned short int n, unsigned short int align ) { return (n + (align - 1)) / align; } 138 int ceiling_div( int n, int align ) { return (n + (align - 1)) / align; } 139 unsigned int ceiling_div( unsigned int n, unsigned int align ) { return (n + (align - 1)) / align; } 140 long int ceiling_div( long int n, long int align ) { return (n + (align - 1)) / align; } 141 unsigned long int ceiling_div( unsigned long int n, unsigned long int align ) { return (n + (align - 1)) / align; } 142 long long int ceiling_div( long long int n, long long int align ) { return (n + (align - 1)) / align; } 143 unsigned long long int ceiling_div( unsigned long long int n, unsigned long long int align ) { return (n + (align - 1)) / align; } 144 145 // forall( otype T | { T ?+?( T, T ); T ?-?( T, T ); T ?%?( T, T ); } ) 146 // T ceiling_div( T n, T align ) { verify( is_pow2( align ) );return (n + (align - 1)) / align; } 147 148 // gcc notices the div/mod pair and saves both so only one div. 149 signed char ceiling( signed char n, signed char align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); } 150 unsigned char ceiling( unsigned char n, unsigned char align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); } 151 short int ceiling( short int n, short int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); } 152 unsigned short int ceiling( unsigned short int n, unsigned short int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); } 153 int ceiling( int n, int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); } 154 unsigned int ceiling( unsigned int n, unsigned int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); } 155 long int ceiling( long int n, long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); } 156 unsigned long int ceiling( unsigned long int n, unsigned long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0) , align); } 157 long long int ceiling( long long int n, long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); } 158 unsigned long long int ceiling( unsigned long long int n, unsigned long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); } 144 159 145 160 // forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T ); T ?/?( T, T ); } ) 146 // T ceiling( T n, T align ) { return (n + (align - (T){1})) / align;}161 // T ceiling( T n, T align ) { return return floor( n + (n % align != 0 ? align - 1 : 0), align ); *} 147 162 } // distribution 148 163
Note: See TracChangeset
for help on using the changeset viewer.