- Timestamp:
- Aug 10, 2020, 3:47:34 PM (5 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:
- 153d0f52
- Parents:
- 1eb239e4 (diff), e2702fd (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. - Location:
- libcfa
- Files:
-
- 17 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/configure.ac
r1eb239e4 r8465b4d 8 8 AM_SILENT_RULES([yes]) 9 9 10 m4_include([../ automake/cfa.m4])10 m4_include([../tools/build/cfa.m4]) 11 11 12 12 AM_INIT_AUTOMAKE([subdir-objects]) -
libcfa/prelude/defines.hfa.in
r1eb239e4 r8465b4d 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 // defines.hfa.in -- 8 // 9 // Author : Thierry Delisle 10 // Created On : Thu Apr 30 15:23:00 2020 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 14 // 15 16 //----------------------------------------------------------------------- 17 // Global Support 1 /* prelude/defines.hfa.in. Generated from configure.ac by autoheader. */ 2 3 /* Location of cfa command. */ 4 #undef CFA_BINDIR 5 6 /* Defined if io_uring support is present when compiling libcfathread and 7 supports the operation IORING_OP_ACCEPT. */ 8 #undef CFA_HAVE_IORING_OP_ACCEPT 9 10 /* Defined if io_uring support is present when compiling libcfathread and 11 supports the operation IORING_OP_ASYNC_CANCEL. */ 12 #undef CFA_HAVE_IORING_OP_ASYNC_CANCEL 13 14 /* Defined if io_uring support is present when compiling libcfathread and 15 supports the operation IORING_OP_CLOSE. */ 16 #undef CFA_HAVE_IORING_OP_CLOSE 17 18 /* Defined if io_uring support is present when compiling libcfathread and 19 supports the operation IORING_OP_CONNECT. */ 20 #undef CFA_HAVE_IORING_OP_CONNECT 21 22 /* Defined if io_uring support is present when compiling libcfathread and 23 supports the operation IORING_OP_EPOLL_CTL. */ 24 #undef CFA_HAVE_IORING_OP_EPOLL_CTL 25 26 /* Defined if io_uring support is present when compiling libcfathread and 27 supports the operation IORING_OP_FADVISE. */ 28 #undef CFA_HAVE_IORING_OP_FADVISE 29 30 /* Defined if io_uring support is present when compiling libcfathread and 31 supports the operation IORING_OP_FALLOCATE. */ 32 #undef CFA_HAVE_IORING_OP_FALLOCATE 33 34 /* Defined if io_uring support is present when compiling libcfathread and 35 supports the operation IORING_OP_FILES_UPDATE. */ 36 #undef CFA_HAVE_IORING_OP_FILES_UPDATE 37 38 /* Defined if io_uring support is present when compiling libcfathread and 39 supports the operation IORING_OP_FSYNC. */ 40 #undef CFA_HAVE_IORING_OP_FSYNC 41 42 /* Defined if io_uring support is present when compiling libcfathread and 43 supports the operation IORING_OP_LINK_TIMEOUT. */ 44 #undef CFA_HAVE_IORING_OP_LINK_TIMEOUT 45 46 /* Defined if io_uring support is present when compiling libcfathread and 47 supports the operation IORING_OP_MADVISE. */ 48 #undef CFA_HAVE_IORING_OP_MADVISE 49 50 /* Defined if io_uring support is present when compiling libcfathread and 51 supports the operation IORING_OP_NOP. */ 52 #undef CFA_HAVE_IORING_OP_NOP 53 54 /* Defined if io_uring support is present when compiling libcfathread and 55 supports the operation IORING_OP_OPENAT. */ 56 #undef CFA_HAVE_IORING_OP_OPENAT 57 58 /* Defined if io_uring support is present when compiling libcfathread and 59 supports the operation IORING_OP_OPENAT2. */ 60 #undef CFA_HAVE_IORING_OP_OPENAT2 61 62 /* Defined if io_uring support is present when compiling libcfathread and 63 supports the operation IORING_OP_POLL_ADD. */ 64 #undef CFA_HAVE_IORING_OP_POLL_ADD 65 66 /* Defined if io_uring support is present when compiling libcfathread and 67 supports the operation IORING_OP_POLL_REMOVE. */ 68 #undef CFA_HAVE_IORING_OP_POLL_REMOVE 69 70 /* Defined if io_uring support is present when compiling libcfathread and 71 supports the operation IORING_OP_PROVIDE_BUFFERS. */ 72 #undef CFA_HAVE_IORING_OP_PROVIDE_BUFFERS 73 74 /* Defined if io_uring support is present when compiling libcfathread and 75 supports the operation IORING_OP_READ. */ 76 #undef CFA_HAVE_IORING_OP_READ 77 78 /* Defined if io_uring support is present when compiling libcfathread and 79 supports the operation IORING_OP_READV. */ 80 #undef CFA_HAVE_IORING_OP_READV 81 82 /* Defined if io_uring support is present when compiling libcfathread and 83 supports the operation IORING_OP_READ_FIXED. */ 84 #undef CFA_HAVE_IORING_OP_READ_FIXED 85 86 /* Defined if io_uring support is present when compiling libcfathread and 87 supports the operation IORING_OP_RECV. */ 88 #undef CFA_HAVE_IORING_OP_RECV 89 90 /* Defined if io_uring support is present when compiling libcfathread and 91 supports the operation IORING_OP_RECVMSG. */ 92 #undef CFA_HAVE_IORING_OP_RECVMSG 93 94 /* Defined if io_uring support is present when compiling libcfathread and 95 supports the operation IORING_OP_REMOVE_BUFFER. */ 96 #undef CFA_HAVE_IORING_OP_REMOVE_BUFFER 97 98 /* Defined if io_uring support is present when compiling libcfathread and 99 supports the operation IORING_OP_SEND. */ 100 #undef CFA_HAVE_IORING_OP_SEND 101 102 /* Defined if io_uring support is present when compiling libcfathread and 103 supports the operation IORING_OP_SENDMSG. */ 104 #undef CFA_HAVE_IORING_OP_SENDMSG 105 106 /* Defined if io_uring support is present when compiling libcfathread and 107 supports the operation IORING_OP_SPLICE. */ 108 #undef CFA_HAVE_IORING_OP_SPLICE 109 110 /* Defined if io_uring support is present when compiling libcfathread and 111 supports the operation IORING_OP_STATX. */ 112 #undef CFA_HAVE_IORING_OP_STATX 113 114 /* Defined if io_uring support is present when compiling libcfathread and 115 supports the operation IORING_OP_SYNC_FILE_RANGE. */ 116 #undef CFA_HAVE_IORING_OP_SYNC_FILE_RANGE 117 118 /* Defined if io_uring support is present when compiling libcfathread and 119 supports the operation IORING_OP_TIMEOUT. */ 120 #undef CFA_HAVE_IORING_OP_TIMEOUT 121 122 /* Defined if io_uring support is present when compiling libcfathread and 123 supports the operation IORING_OP_TIMEOUT_REMOVE. */ 124 #undef CFA_HAVE_IORING_OP_TIMEOUT_REMOVE 125 126 /* Defined if io_uring support is present when compiling libcfathread and 127 supports the operation IORING_OP_WRITE. */ 128 #undef CFA_HAVE_IORING_OP_WRITE 129 130 /* Defined if io_uring support is present when compiling libcfathread and 131 supports the operation IORING_OP_WRITEV. */ 132 #undef CFA_HAVE_IORING_OP_WRITEV 133 134 /* Defined if io_uring support is present when compiling libcfathread and 135 supports the operation IORING_OP_WRITE_FIXED. */ 136 #undef CFA_HAVE_IORING_OP_WRITE_FIXED 137 138 /* Defined if io_uring support is present when compiling libcfathread and 139 supports the flag ASYNC. */ 140 #undef CFA_HAVE_IOSQE_ASYNC 141 142 /* Defined if io_uring support is present when compiling libcfathread and 143 supports the flag FIXED_FILE. */ 144 #undef CFA_HAVE_IOSQE_FIXED_FILE 145 146 /* Defined if io_uring support is present when compiling libcfathread and 147 supports the flag IO_DRAIN. */ 148 #undef CFA_HAVE_IOSQE_IO_DRAIN 149 150 /* Defined if io_uring support is present when compiling libcfathread and 151 supports the flag IO_HARDLINK. */ 152 #undef CFA_HAVE_IOSQE_IO_HARDLINK 153 154 /* Defined if io_uring support is present when compiling libcfathread and 155 supports the flag IO_LINK. */ 156 #undef CFA_HAVE_IOSQE_IO_LINK 157 18 158 /* Defined if io_uring support is present when compiling libcfathread. */ 19 159 #undef CFA_HAVE_LINUX_IO_URING_H 20 160 21 //-----------------------------------------------------------------------22 // Operations23 /* Defined if io_uring support is present when compiling libcfathread and24 supports the operation IORING_OP_NOP. */25 #undef CFA_HAVE_IORING_OP_NOP26 27 /* Defined if io_uring support is present when compiling libcfathread and28 supports the operation IORING_OP_READV. */29 #undef CFA_HAVE_IORING_OP_READV30 31 /* Defined if io_uring support is present when compiling libcfathread and32 supports the operation IORING_OP_WRITEV. */33 #undef CFA_HAVE_IORING_OP_WRITEV34 35 /* Defined if io_uring support is present when compiling libcfathread and36 supports the operation IORING_OP_FSYNC. */37 #undef CFA_HAVE_IORING_OP_FSYNC38 39 /* Defined if io_uring support is present when compiling libcfathread and40 supports the operation IORING_OP_READ_FIXED. */41 #undef CFA_HAVE_IORING_OP_READ_FIXED42 43 /* Defined if io_uring support is present when compiling libcfathread and44 supports the operation IORING_OP_WRITE_FIXED. */45 #undef CFA_HAVE_IORING_OP_WRITE_FIXED46 47 /* Defined if io_uring support is present when compiling libcfathread and48 supports the operation IORING_OP_POLL_ADD. */49 #undef CFA_HAVE_IORING_OP_POLL_ADD50 51 /* Defined if io_uring support is present when compiling libcfathread and52 supports the operation IORING_OP_POLL_REMOVE. */53 #undef CFA_HAVE_IORING_OP_POLL_REMOVE54 55 /* Defined if io_uring support is present when compiling libcfathread and56 supports the operation IORING_OP_SYNC_FILE_RANGE. */57 #undef CFA_HAVE_IORING_OP_SYNC_FILE_RANGE58 59 /* Defined if io_uring support is present when compiling libcfathread and60 supports the operation IORING_OP_SENDMSG. */61 #undef CFA_HAVE_IORING_OP_SENDMSG62 63 /* Defined if io_uring support is present when compiling libcfathread and64 supports the operation IORING_OP_RECVMSG. */65 #undef CFA_HAVE_IORING_OP_RECVMSG66 67 /* Defined if io_uring support is present when compiling libcfathread and68 supports the operation IORING_OP_TIMEOUT. */69 #undef CFA_HAVE_IORING_OP_TIMEOUT70 71 /* Defined if io_uring support is present when compiling libcfathread and72 supports the operation IORING_OP_TIMEOUT_REMOVE. */73 #undef CFA_HAVE_IORING_OP_TIMEOUT_REMOVE74 75 /* Defined if io_uring support is present when compiling libcfathread and76 supports the operation IORING_OP_ACCEPT. */77 #undef CFA_HAVE_IORING_OP_ACCEPT78 79 /* Defined if io_uring support is present when compiling libcfathread and80 supports the operation IORING_OP_ASYNC_CANCEL. */81 #undef CFA_HAVE_IORING_OP_ASYNC_CANCEL82 83 /* Defined if io_uring support is present when compiling libcfathread and84 supports the operation IORING_OP_LINK_TIMEOUT. */85 #undef CFA_HAVE_IORING_OP_LINK_TIMEOUT86 87 /* Defined if io_uring support is present when compiling libcfathread and88 supports the operation IORING_OP_CONNECT. */89 #undef CFA_HAVE_IORING_OP_CONNECT90 91 /* Defined if io_uring support is present when compiling libcfathread and92 supports the operation IORING_OP_FALLOCATE. */93 #undef CFA_HAVE_IORING_OP_FALLOCATE94 95 /* Defined if io_uring support is present when compiling libcfathread and96 supports the operation IORING_OP_OPENAT. */97 #undef CFA_HAVE_IORING_OP_OPENAT98 99 /* Defined if io_uring support is present when compiling libcfathread and100 supports the operation IORING_OP_CLOSE. */101 #undef CFA_HAVE_IORING_OP_CLOSE102 103 /* Defined if io_uring support is present when compiling libcfathread and104 supports the operation IORING_OP_FILES_UPDATE. */105 #undef CFA_HAVE_IORING_OP_FILES_UPDATE106 107 /* Defined if io_uring support is present when compiling libcfathread and108 supports the operation IORING_OP_STATX. */109 #undef CFA_HAVE_IORING_OP_STATX110 111 /* Defined if io_uring support is present when compiling libcfathread and112 supports the operation IORING_OP_READ. */113 #undef CFA_HAVE_IORING_OP_READ114 115 /* Defined if io_uring support is present when compiling libcfathread and116 supports the operation IORING_OP_WRITE. */117 #undef CFA_HAVE_IORING_OP_WRITE118 119 /* Defined if io_uring support is present when compiling libcfathread and120 supports the operation IORING_OP_FADVISE. */121 #undef CFA_HAVE_IORING_OP_FADVISE122 123 /* Defined if io_uring support is present when compiling libcfathread and124 supports the operation IORING_OP_MADVISE. */125 #undef CFA_HAVE_IORING_OP_MADVISE126 127 /* Defined if io_uring support is present when compiling libcfathread and128 supports the operation IORING_OP_SEND. */129 #undef CFA_HAVE_IORING_OP_SEND130 131 /* Defined if io_uring support is present when compiling libcfathread and132 supports the operation IORING_OP_RECV. */133 #undef CFA_HAVE_IORING_OP_RECV134 135 /* Defined if io_uring support is present when compiling libcfathread and136 supports the operation IORING_OP_OPENAT2. */137 #undef CFA_HAVE_IORING_OP_OPENAT2138 139 /* Defined if io_uring support is present when compiling libcfathread and140 supports the operation IORING_OP_EPOLL_CTL. */141 #undef CFA_HAVE_IORING_OP_EPOLL_CTL142 143 /* Defined if io_uring support is present when compiling libcfathread and144 supports the operation IORING_OP_SPLICE. */145 #undef CFA_HAVE_IORING_OP_SPLICE146 147 /* Defined if io_uring support is present when compiling libcfathread and148 supports the operation IORING_OP_PROVIDE_BUFFERS. */149 #undef CFA_HAVE_IORING_OP_PROVIDE_BUFFERS150 151 /* Defined if io_uring support is present when compiling libcfathread and152 supports the operation IORING_OP_REMOVE_BUFFER. */153 #undef CFA_HAVE_IORING_OP_REMOVE_BUFFER154 155 //-----------------------------------------------------------------------156 // Flags157 /* Defined if io_uring support is present when compiling libcfathread and158 supports the flag FIXED_FILE. */159 #undef CFA_HAVE_IOSQE_FIXED_FILE160 161 /* Defined if io_uring support is present when compiling libcfathread and162 supports the flag IO_DRAIN. */163 #undef CFA_HAVE_IOSQE_IO_DRAIN164 165 /* Defined if io_uring support is present when compiling libcfathread and166 supports the flag ASYNC. */167 #undef CFA_HAVE_IOSQE_ASYNC168 169 /* Defined if io_uring support is present when compiling libcfathread and170 supports the flag IO_LINK. */171 #undef CFA_HAVE_IOSQE_IO_LINK172 173 /* Defined if io_uring support is present when compiling libcfathread and174 supports the flag IO_HARDLINK. */175 #undef CFA_HAVE_IOSQE_IO_HARDLINK176 177 161 /* Defined if io_uring support is present when compiling libcfathread and 178 162 supports the flag SPLICE_F_FD_IN_FIXED. */ 179 163 #undef CFA_HAVE_SPLICE_F_FD_IN_FIXED 180 164 181 //----------------------------------------------------------------------- 182 // Other calls 165 /* Location of include files. */ 166 #undef CFA_INCDIR 167 168 /* Location of cc1 and cfa-cpp commands. */ 169 #undef CFA_LIBDIR 170 171 /* Location of cfa install. */ 172 #undef CFA_PREFIX 173 174 /* Define to 1 if you have the <dlfcn.h> header file. */ 175 #undef HAVE_DLFCN_H 176 177 /* Define to 1 if you have the <inttypes.h> header file. */ 178 #undef HAVE_INTTYPES_H 179 180 /* Define to 1 if you have the <linux/io_uring.h> header file. */ 181 #undef HAVE_LINUX_IO_URING_H 182 183 /* Define to 1 if you have the <memory.h> header file. */ 184 #undef HAVE_MEMORY_H 185 183 186 /* Define to 1 if you have the `preadv2' function. */ 184 187 #undef HAVE_PREADV2 … … 187 190 #undef HAVE_PWRITEV2 188 191 189 //----------------------------------------------------------------------- 190 // Statistics 192 /* Define to 1 if you have the <stdint.h> header file. */ 193 #undef HAVE_STDINT_H 194 195 /* Define to 1 if you have the <stdlib.h> header file. */ 196 #undef HAVE_STDLIB_H 197 198 /* Define to 1 if you have the <strings.h> header file. */ 199 #undef HAVE_STRINGS_H 200 201 /* Define to 1 if you have the <string.h> header file. */ 202 #undef HAVE_STRING_H 203 204 /* Define to 1 if you have the <sys/stat.h> header file. */ 205 #undef HAVE_SYS_STAT_H 206 207 /* Define to 1 if you have the <sys/types.h> header file. */ 208 #undef HAVE_SYS_TYPES_H 209 210 /* Define to 1 if you have the <unistd.h> header file. */ 211 #undef HAVE_UNISTD_H 212 213 /* Define to the sub-directory where libtool stores uninstalled libraries. */ 214 #undef LT_OBJDIR 215 216 /* Name of package */ 217 #undef PACKAGE 218 219 /* Define to the address where bug reports for this package should be sent. */ 220 #undef PACKAGE_BUGREPORT 221 222 /* Define to the full name of this package. */ 223 #undef PACKAGE_NAME 224 225 /* Define to the full name and version of this package. */ 226 #undef PACKAGE_STRING 227 228 /* Define to the one symbol short name of this package. */ 229 #undef PACKAGE_TARNAME 230 231 /* Define to the home page for this package. */ 232 #undef PACKAGE_URL 233 234 /* Define to the version of this package. */ 235 #undef PACKAGE_VERSION 236 237 /* Define to 1 if you have the ANSI C header files. */ 238 #undef STDC_HEADERS 239 240 /* Version number of package */ 241 #undef VERSION 242 191 243 /* Defined if libcfathread was compiled without support for statistics. */ 192 244 #undef __CFA_NO_STATISTICS__ -
libcfa/src/Makefile.am
r1eb239e4 r8465b4d 19 19 ACLOCAL_AMFLAGS = -I automake 20 20 21 include $( srcdir)/../../src/cfa.make21 include $(top_srcdir)/../tools/build/cfa.make 22 22 23 23 libdir = ${CFA_LIBDIR} -
libcfa/src/bitmanip.hfa
r1eb239e4 r8465b4d 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 -
libcfa/src/heap.cfa
r1eb239e4 r8465b4d 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // heap.c --7 // heap.cfa -- 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 5 22:21:27202013 // Update Count : 8 5312 // Last Modified On : Sun Aug 9 12:23:20 2020 13 // Update Count : 894 14 14 // 15 15 … … 23 23 #include <sys/mman.h> // mmap, munmap 24 24 25 #include "bits/align.hfa" // lib Pow225 #include "bits/align.hfa" // libAlign 26 26 #include "bits/defs.hfa" // likely, unlikely 27 27 #include "bits/locks.hfa" // __spinlock_t … … 88 88 } // default_heap_expansion 89 89 90 bool default_heap_exhausted() __attribute__(( weak )) { // find and free some storage91 // Returning false prints "out of heap memory" message and aborts.92 return false;93 } // default_heap_exhausted94 95 90 96 91 #ifdef __CFA_DEBUG__ 97 static unsigned int allocFree;// running total of allocations minus frees92 static size_t allocUnfreed; // running total of allocations minus frees 98 93 99 94 static void prtUnfreed() { 100 if ( alloc Free!= 0 ) {95 if ( allocUnfreed != 0 ) { 101 96 // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT. 102 97 char helpText[512]; 103 int len = snprintf( helpText, sizeof(helpText), "CFA warning (UNIX pid:%ld) : program terminating with % u(0x%x) bytes of storage allocated but not freed.\n"98 int len = snprintf( helpText, sizeof(helpText), "CFA warning (UNIX pid:%ld) : program terminating with %zu(0x%zx) bytes of storage allocated but not freed.\n" 104 99 "Possible cause is unfreed storage allocated by the program or system/library routines called from the program.\n", 105 (long int)getpid(), alloc Free, allocFree); // always print the UNIX pid100 (long int)getpid(), allocUnfreed, allocUnfreed ); // always print the UNIX pid 106 101 __cfaabi_bits_write( STDERR_FILENO, helpText, len ); // print debug/nodebug 107 102 } // if … … 110 105 extern "C" { 111 106 void heapAppStart() { // called by __cfaabi_appready_startup 112 alloc Free= 0;107 allocUnfreed = 0; 113 108 } // heapAppStart 114 109 … … 226 221 #define __STATISTICS__ 227 222 228 // Bucket sizemust be multiple of 16.223 // Size of array must harmonize with NoBucketSizes and individual bucket sizes must be multiple of 16. 229 224 // Smaller multiples of 16 and powers of 2 are common allocation sizes, so make them generate the minimum required bucket size. 230 225 // malloc(0) returns 0p, so no bucket is necessary for 0 bytes returning an address that can be freed. … … 249 244 }; 250 245 251 static_assert( NoBucketSizes == sizeof(bucketSizes) / sizeof(bucketSizes[0] ), "size of bucket array wrong" );246 static_assert( NoBucketSizes == sizeof(bucketSizes) / sizeof(bucketSizes[0] ), "size of bucket array wrong" ); 252 247 253 248 #ifdef FASTLOOKUP … … 267 262 #ifdef __STATISTICS__ 268 263 // Heap statistics counters. 264 static unsigned int malloc_calls; 265 static unsigned long long int malloc_storage; 266 static unsigned int aalloc_calls; 267 static unsigned long long int aalloc_storage; 268 static unsigned int calloc_calls; 269 static unsigned long long int calloc_storage; 270 static unsigned int memalign_calls; 271 static unsigned long long int memalign_storage; 272 static unsigned int amemalign_calls; 273 static unsigned long long int amemalign_storage; 274 static unsigned int cmemalign_calls; 275 static unsigned long long int cmemalign_storage; 276 static unsigned int resize_calls; 277 static unsigned long long int resize_storage; 278 static unsigned int realloc_calls; 279 static unsigned long long int realloc_storage; 280 static unsigned int free_calls; 281 static unsigned long long int free_storage; 282 static unsigned int mmap_calls; 269 283 static unsigned long long int mmap_storage; 270 static unsigned int m map_calls;284 static unsigned int munmap_calls; 271 285 static unsigned long long int munmap_storage; 272 static unsigned int munmap_calls;286 static unsigned int sbrk_calls; 273 287 static unsigned long long int sbrk_storage; 274 static unsigned int sbrk_calls;275 static unsigned long long int malloc_storage;276 static unsigned int malloc_calls;277 static unsigned long long int free_storage;278 static unsigned int free_calls;279 static unsigned long long int aalloc_storage;280 static unsigned int aalloc_calls;281 static unsigned long long int calloc_storage;282 static unsigned int calloc_calls;283 static unsigned long long int memalign_storage;284 static unsigned int memalign_calls;285 static unsigned long long int amemalign_storage;286 static unsigned int amemalign_calls;287 static unsigned long long int cmemalign_storage;288 static unsigned int cmemalign_calls;289 static unsigned long long int resize_storage;290 static unsigned int resize_calls;291 static unsigned long long int realloc_storage;292 static unsigned int realloc_calls;293 288 // Statistics file descriptor (changed by malloc_stats_fd). 294 static int stat fd = STDERR_FILENO; // default stderr289 static int stat_fd = STDERR_FILENO; // default stderr 295 290 296 291 // Use "write" because streams may be shutdown when calls are made. … … 312 307 " sbrk: calls %u / storage %llu\n", 313 308 malloc_calls, malloc_storage, 314 aalloc_calls, calloc_storage,309 aalloc_calls, aalloc_storage, 315 310 calloc_calls, calloc_storage, 316 311 memalign_calls, memalign_storage, … … 410 405 411 406 412 // static inline void noMemory() {413 // abort( "Heap memory exhausted at %zu bytes.\n"414 // "Possible cause is very large memory allocation and/or large amount of unfreed storage allocated by the program or system/library routines.",415 // ((char *)(sbrk( 0 )) - (char *)(heapManager.heapBegin)) );416 // } // noMemory417 418 419 407 static inline void checkAlign( size_t alignment ) { 420 if ( alignment < libAlign() || ! libPow2( alignment ) ) {408 if ( alignment < libAlign() || ! is_pow2( alignment ) ) { 421 409 abort( "Alignment %zu for memory allocation is less than %d and/or not a power of 2.", alignment, libAlign() ); 422 410 } // if … … 441 429 header = realHeader( header ); // backup from fake to real header 442 430 } else { 443 alignment = 0;431 alignment = libAlign(); // => no fake header 444 432 } // if 445 433 } // fakeHeader … … 450 438 header = headerAddr( addr ); 451 439 452 440 if ( unlikely( heapEnd < addr ) ) { // mmapped ? 453 441 fakeHeader( header, alignment ); 454 442 size = header->kind.real.blockSize & -3; // mmap size … … 478 466 } // headers 479 467 480 #define NO_MEMORY_MSG " noheap memory available for allocating %zd new bytes."468 #define NO_MEMORY_MSG "insufficient heap memory available for allocating %zd new bytes." 481 469 482 470 static inline void * extend( size_t size ) with( heapManager ) { … … 486 474 // If the size requested is bigger than the current remaining storage, increase the size of the heap. 487 475 488 size_t increase = libCeiling( size > heapExpand ? size : heapExpand, libAlign() ); 489 Succeed: 490 { 491 if ( sbrk( increase ) != (void *)-1 ) break Succeed; // succeed ? 492 if ( default_heap_exhausted() ) { // try fix 493 if ( sbrk( increase ) != (void *)-1 ) break Succeed; // succeed ? 494 } // if 476 size_t increase = ceiling2( size > heapExpand ? size : heapExpand, libAlign() ); 477 if ( sbrk( increase ) == (void *)-1 ) { // failed, no memory ? 495 478 unlock( extlock ); 496 479 abort( NO_MEMORY_MSG, size ); // give up 497 } 480 } // if 498 481 #ifdef __STATISTICS__ 499 482 sbrk_calls += 1; … … 531 514 posn = Bsearchl( (unsigned int)tsize, bucketSizes, (size_t)maxBucketsUsed ); 532 515 HeapManager.FreeHeader * freeElem = &freeLists[posn]; 533 // #ifdef FASTLOOKUP 534 // if ( tsize < LookupSizes ) 535 // freeElem = &freeLists[lookup[tsize]]; 536 // else 537 // #endif // FASTLOOKUP 538 // freeElem = bsearchl( tsize, freeLists, (size_t)maxBucketsUsed ); // binary search 539 // HeapManager.FreeHeader * freeElem = 540 // #ifdef FASTLOOKUP 541 // tsize < LookupSizes ? &freeLists[lookup[tsize]] : 542 // #endif // FASTLOOKUP 543 // bsearchl( tsize, freeLists, (size_t)maxBucketsUsed ); // binary search 544 assert( freeElem <= &freeLists[maxBucketsUsed] ); // subscripting error ? 545 assert( tsize <= freeElem->blockSize ); // search failure ? 516 verify( freeElem <= &freeLists[maxBucketsUsed] ); // subscripting error ? 517 verify( tsize <= freeElem->blockSize ); // search failure ? 546 518 tsize = freeElem->blockSize; // total space needed for request 547 519 … … 573 545 } else { // large size => mmap 574 546 if ( unlikely( size > ULONG_MAX - pageSize ) ) return 0p; 575 tsize = libCeiling( tsize, pageSize ); // must be multiple of page size547 tsize = ceiling2( tsize, pageSize ); // must be multiple of page size 576 548 #ifdef __STATISTICS__ 577 549 __atomic_add_fetch( &mmap_calls, 1, __ATOMIC_SEQ_CST ); 578 550 __atomic_add_fetch( &mmap_storage, tsize, __ATOMIC_SEQ_CST ); 579 551 #endif // __STATISTICS__ 580 Succeed: 581 { 582 block = (HeapManager.Storage *)mmap( 0, tsize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, mmapFd, 0 ); 583 if ( block != (HeapManager.Storage *)MAP_FAILED ) break Succeed; // succeed ? 584 if ( errno == ENOMEM && default_heap_exhausted() ) { // out of memory and try again ? 585 block = (HeapManager.Storage *)mmap( 0, tsize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, mmapFd, 0 ); 586 if ( block != (HeapManager.Storage *)MAP_FAILED ) break Succeed; // succeed ? 587 } // if 588 if ( errno == ENOMEM ) abort( NO_MEMORY_MSG, tsize ); 552 553 block = (HeapManager.Storage *)mmap( 0, tsize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, mmapFd, 0 ); 554 if ( block == (HeapManager.Storage *)MAP_FAILED ) { // failed ? 555 if ( errno == ENOMEM ) abort( NO_MEMORY_MSG, tsize ); // no memory 589 556 // Do not call strerror( errno ) as it may call malloc. 590 557 abort( "(HeapManager &)0x%p.doMalloc() : internal error, mmap failure, size:%zu error:%d.", &heapManager, tsize, errno ); 591 } 558 } //if 592 559 #ifdef __CFA_DEBUG__ 593 560 // Set new memory to garbage so subsequent uninitialized usages might fail. … … 599 566 block->header.kind.real.size = size; // store allocation size 600 567 void * addr = &(block->data); // adjust off header to user bytes 568 verify( ((uintptr_t)addr & (libAlign() - 1)) == 0 ); // minimum alignment ? 601 569 602 570 #ifdef __CFA_DEBUG__ 603 assert( ((uintptr_t)addr & (libAlign() - 1)) == 0 ); // minimum alignment ? 604 __atomic_add_fetch( &allocFree, tsize, __ATOMIC_SEQ_CST ); 571 __atomic_add_fetch( &allocUnfreed, tsize, __ATOMIC_SEQ_CST ); 605 572 if ( traceHeap() ) { 606 573 enum { BufferSize = 64 }; 607 574 char helpText[BufferSize]; 608 575 int len = snprintf( helpText, BufferSize, "%p = Malloc( %zu ) (allocated %zu)\n", addr, size, tsize ); 609 // int len = snprintf( helpText, BufferSize, "Malloc %p %zu\n", addr, size );610 576 __cfaabi_bits_write( STDERR_FILENO, helpText, len ); // print debug/nodebug 611 577 } // if … … 659 625 660 626 #ifdef __CFA_DEBUG__ 661 __atomic_add_fetch( &alloc Free, -size, __ATOMIC_SEQ_CST );627 __atomic_add_fetch( &allocUnfreed, -size, __ATOMIC_SEQ_CST ); 662 628 if ( traceHeap() ) { 663 enum { BufferSize = 64 }; 664 char helpText[BufferSize]; 629 char helpText[64]; 665 630 int len = snprintf( helpText, sizeof(helpText), "Free( %p ) size:%zu\n", addr, size ); 666 631 __cfaabi_bits_write( STDERR_FILENO, helpText, len ); // print debug/nodebug … … 685 650 for ( HeapManager.Storage * p = freeLists[i].freeList; p != 0p; p = p->header.kind.real.next ) { 686 651 #else 687 for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; /* p = getNext( p )->top */) { 688 typeof(p) temp = ( p )`next->top; // FIX ME: direct assignent fails, initialization works 689 p = temp; 652 for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; p = (p)`next->top ) { 690 653 #endif // BUCKETLOCK 691 654 total += size; … … 729 692 730 693 char * end = (char *)sbrk( 0 ); 731 heapBegin = heapEnd = sbrk( (char *) libCeiling( (long unsigned int)end, libAlign() ) - end ); // move start of heap to multiple of alignment694 heapBegin = heapEnd = sbrk( (char *)ceiling2( (long unsigned int)end, libAlign() ) - end ); // move start of heap to multiple of alignment 732 695 } // HeapManager 733 696 … … 737 700 if ( traceHeapTerm() ) { 738 701 printStats(); 739 // if ( prtfree() ) prtFree( heapManager, true );702 // prtUnfreed() called in heapAppStop() 740 703 } // if 741 704 #endif // __STATISTICS__ … … 746 709 void memory_startup( void ) { 747 710 #ifdef __CFA_DEBUG__ 748 if ( unlikely( heapBoot ) ) {// check for recursion during system boot711 if ( heapBoot ) { // check for recursion during system boot 749 712 // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT. 750 713 abort( "boot() : internal error, recursively invoked during system boot." ); … … 753 716 #endif // __CFA_DEBUG__ 754 717 755 // assert( heapManager.heapBegin != 0 );718 //verify( heapManager.heapBegin != 0 ); 756 719 //heapManager{}; 757 720 if ( heapManager.heapBegin == 0p ) heapManager{}; // sanity check … … 765 728 766 729 static inline void * mallocNoStats( size_t size ) { // necessary for malloc statistics 767 verify( heapManager.heapBegin != 0 ); // called before memory_startup ?730 verify( heapManager.heapBegin != 0p ); // called before memory_startup ? 768 731 if ( unlikely( size ) == 0 ) return 0p; // 0 BYTE ALLOCATION RETURNS NULL POINTER 769 732 … … 801 764 802 765 803 static inline void * memalignNoStats( size_t alignment, size_t size ) { // necessary for malloc statistics766 static inline void * memalignNoStats( size_t alignment, size_t size ) { 804 767 if ( unlikely( size ) == 0 ) return 0p; // 0 BYTE ALLOCATION RETURNS NULL POINTER 805 768 … … 823 786 824 787 // address in the block of the "next" alignment address 825 char * user = (char *) libCeiling( (uintptr_t)(addr + sizeof(HeapManager.Storage)), alignment );788 char * user = (char *)ceiling2( (uintptr_t)(addr + sizeof(HeapManager.Storage)), alignment ); 826 789 827 790 // address of header from malloc … … 851 814 #endif // __CFA_DEBUG__ 852 815 headers( "cmemalign", addr, header, freeElem, bsize, alignment ); 816 817 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero. 853 818 #ifndef __CFA_DEBUG__ 854 855 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.856 819 if ( ! mapped ) 857 820 #endif // __CFA_DEBUG__ … … 865 828 866 829 867 // supported mallopt options868 #ifndef M_MMAP_THRESHOLD869 #define M_MMAP_THRESHOLD (-1)870 #endif // M_TOP_PAD871 #ifndef M_TOP_PAD872 #define M_TOP_PAD (-2)873 #endif // M_TOP_PAD874 875 876 830 extern "C" { 877 831 // Allocates size bytes and returns a pointer to the allocated memory. The contents are undefined. If size is 0, … … 889 843 // Same as malloc() except size bytes is an array of dim elements each of elemSize bytes. 890 844 void * aalloc( size_t dim, size_t elemSize ) { 845 size_t size = dim * elemSize; 891 846 #ifdef __STATISTICS__ 892 847 __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST ); 893 __atomic_add_fetch( &aalloc_storage, dim * elemSize, __ATOMIC_SEQ_CST );894 #endif // __STATISTICS__ 895 896 return mallocNoStats( dim * elemSize );848 __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST ); 849 #endif // __STATISTICS__ 850 851 return mallocNoStats( size ); 897 852 } // aalloc 898 853 … … 907 862 return callocNoStats( dim, elemSize ); 908 863 } // calloc 864 909 865 910 866 // Change the size of the memory block pointed to by oaddr to size bytes. The contents are undefined. If oaddr is … … 915 871 #ifdef __STATISTICS__ 916 872 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST ); 917 __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );918 873 #endif // __STATISTICS__ 919 874 920 875 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 921 876 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases 922 if ( unlikely( oaddr == 0p ) ) return mallocNoStats( size ); 877 if ( unlikely( oaddr == 0p ) ) { 878 #ifdef __STATISTICS__ 879 __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST ); 880 #endif // __STATISTICS__ 881 return mallocNoStats( size ); 882 } // if 923 883 924 884 HeapManager.Storage.Header * header; 925 885 HeapManager.FreeHeader * freeElem; 926 size_t bsize, oalign = 0;886 size_t bsize, oalign; 927 887 headers( "resize", oaddr, header, freeElem, bsize, oalign ); 928 888 929 889 size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket 930 890 // same size, DO NOT preserve STICKY PROPERTIES. 931 if ( oalign == 0&& size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size891 if ( oalign <= libAlign() && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size 932 892 header->kind.real.blockSize &= -2; // no alignment and turn off 0 fill 933 893 header->kind.real.size = size; // reset allocation size 934 894 return oaddr; 935 895 } // if 896 897 #ifdef __STATISTICS__ 898 __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST ); 899 #endif // __STATISTICS__ 936 900 937 901 // change size, DO NOT preserve STICKY PROPERTIES. … … 946 910 #ifdef __STATISTICS__ 947 911 __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST ); 948 __atomic_add_fetch( &realloc_storage, size, __ATOMIC_SEQ_CST );949 912 #endif // __STATISTICS__ 950 913 951 914 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 952 915 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases 953 if ( unlikely( oaddr == 0p ) ) return mallocNoStats( size ); 916 if ( unlikely( oaddr == 0p ) ) { 917 #ifdef __STATISTICS__ 918 __atomic_add_fetch( &realloc_storage, size, __ATOMIC_SEQ_CST ); 919 #endif // __STATISTICS__ 920 return mallocNoStats( size ); 921 } // if 954 922 955 923 HeapManager.Storage.Header * header; 956 924 HeapManager.FreeHeader * freeElem; 957 size_t bsize, oalign = 0;925 size_t bsize, oalign; 958 926 headers( "realloc", oaddr, header, freeElem, bsize, oalign ); 959 927 … … 969 937 } // if 970 938 939 #ifdef __STATISTICS__ 940 __atomic_add_fetch( &realloc_storage, size, __ATOMIC_SEQ_CST ); 941 #endif // __STATISTICS__ 942 971 943 // change size and copy old content to new storage 972 944 973 945 void * naddr; 974 if ( likely( oalign == 0 ) ) { // previous request memalign?946 if ( likely( oalign <= libAlign() ) ) { // previous request not aligned ? 975 947 naddr = mallocNoStats( size ); // create new area 976 948 } else { … … 991 963 } // realloc 992 964 965 993 966 // Same as malloc() except the memory address is a multiple of alignment, which must be a power of two. (obsolete) 994 967 void * memalign( size_t alignment, size_t size ) { … … 1004 977 // Same as aalloc() with memory alignment. 1005 978 void * amemalign( size_t alignment, size_t dim, size_t elemSize ) { 979 size_t size = dim * elemSize; 1006 980 #ifdef __STATISTICS__ 1007 981 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); 1008 __atomic_add_fetch( &cmemalign_storage, dim * elemSize, __ATOMIC_SEQ_CST );1009 #endif // __STATISTICS__ 1010 1011 return memalignNoStats( alignment, dim * elemSize );982 __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST ); 983 #endif // __STATISTICS__ 984 985 return memalignNoStats( alignment, size ); 1012 986 } // amemalign 1013 987 … … 1035 1009 // free(3). 1036 1010 int posix_memalign( void ** memptr, size_t alignment, size_t size ) { 1037 if ( alignment < sizeof(void *) || ! libPow2( alignment ) ) return EINVAL; // check alignment1011 if ( alignment < libAlign() || ! is_pow2( alignment ) ) return EINVAL; // check alignment 1038 1012 * memptr = memalign( alignment, size ); 1039 1013 return 0; … … 1049 1023 // Same as valloc but rounds size to multiple of page size. 1050 1024 void * pvalloc( size_t size ) { 1051 return memalign( pageSize, libCeiling( size, pageSize ) );1025 return memalign( pageSize, ceiling2( size, pageSize ) ); 1052 1026 } // pvalloc 1053 1027 … … 1087 1061 } // malloc_alignment 1088 1062 1063 1089 1064 // Set the alignment for an the allocation and return previous alignment or 0 if no alignment. 1090 1065 size_t $malloc_alignment_set( void * addr, size_t alignment ) { … … 1169 1144 } // malloc_stats 1170 1145 1146 1171 1147 // Changes the file descripter where malloc_stats() writes statistics. 1172 1148 int malloc_stats_fd( int fd __attribute__(( unused )) ) { 1173 1149 #ifdef __STATISTICS__ 1174 int temp = stat fd;1175 stat fd = fd;1150 int temp = stat_fd; 1151 stat_fd = fd; 1176 1152 return temp; 1177 1153 #else … … 1194 1170 } // mallopt 1195 1171 1172 1196 1173 // Attempt to release free memory at the top of the heap (by calling sbrk with a suitable argument). 1197 1174 int malloc_trim( size_t ) { … … 1204 1181 // malloc). 1205 1182 int malloc_info( int options, FILE * stream ) { 1206 if ( options != 0 ) { errno = EINVAL; return -1; } 1183 if ( options != 0 ) { errno = EINVAL; return -1; } 1184 #ifdef __STATISTICS__ 1207 1185 return printStatsXML( stream ); 1186 #else 1187 return 0; // unsupported 1188 #endif // __STATISTICS__ 1208 1189 } // malloc_info 1209 1190 … … 1220 1201 // Restores the state of all malloc internal bookkeeping variables to the values recorded in the opaque data 1221 1202 // structure pointed to by state. 1222 int malloc_set_state( void * ptr) {1203 int malloc_set_state( void * ) { 1223 1204 return 0; // unsupported 1224 1205 } // malloc_set_state … … 1230 1211 #ifdef __STATISTICS__ 1231 1212 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST ); 1232 __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );1233 1213 #endif // __STATISTICS__ 1234 1214 1235 1215 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 1236 1216 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases 1237 if ( unlikely( oaddr == 0p ) ) return memalignNoStats( nalign, size ); 1238 1239 if ( unlikely( nalign == 0 ) ) nalign = libAlign(); // reset alignment to minimum 1217 if ( unlikely( oaddr == 0p ) ) { 1218 #ifdef __STATISTICS__ 1219 __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST ); 1220 #endif // __STATISTICS__ 1221 return memalignNoStats( nalign, size ); 1222 } // if 1223 1224 if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum 1240 1225 #ifdef __CFA_DEBUG__ 1241 1226 else … … 1245 1230 HeapManager.Storage.Header * header; 1246 1231 HeapManager.FreeHeader * freeElem; 1247 size_t bsize, oalign = 0;1232 size_t bsize, oalign; 1248 1233 headers( "resize", oaddr, header, freeElem, bsize, oalign ); 1249 1234 size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket 1250 1235 1251 1236 if ( oalign <= nalign && (uintptr_t)oaddr % nalign == 0 ) { // <= alignment and new alignment happens to match 1252 if ( oalign > =libAlign() ) { // fake header ?1237 if ( oalign > libAlign() ) { // fake header ? 1253 1238 headerAddr( oaddr )->kind.fake.alignment = nalign | 1; // update alignment (could be the same) 1254 1239 } // if … … 1260 1245 } // if 1261 1246 1247 #ifdef __STATISTICS__ 1248 __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST ); 1249 #endif // __STATISTICS__ 1250 1262 1251 // change size, DO NOT preserve STICKY PROPERTIES. 1263 1252 free( oaddr ); … … 1267 1256 1268 1257 void * realloc( void * oaddr, size_t nalign, size_t size ) { 1269 if ( unlikely( nalign == 0 ) ) nalign = libAlign();// reset alignment to minimum1258 if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum 1270 1259 #ifdef __CFA_DEBUG__ 1271 1260 else … … 1275 1264 HeapManager.Storage.Header * header; 1276 1265 HeapManager.FreeHeader * freeElem; 1277 size_t bsize, oalign = 0;1266 size_t bsize, oalign; 1278 1267 headers( "realloc", oaddr, header, freeElem, bsize, oalign ); 1279 1268 1280 1269 if ( oalign <= nalign && (uintptr_t)oaddr % nalign == 0 ) { // <= alignment and new alignment happens to match 1281 if ( oalign > =libAlign() ) { // fake header ?1270 if ( oalign > libAlign() ) { // fake header ? 1282 1271 headerAddr( oaddr )->kind.fake.alignment = nalign | 1; // update alignment (could be the same) 1283 1272 } // if -
libcfa/src/heap.hfa
r1eb239e4 r8465b4d 10 10 // Created On : Tue May 26 11:23:55 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 5 14:55:55202013 // Update Count : 1 412 // Last Modified On : Sat Aug 8 17:36:48 2020 13 // Update Count : 16 14 14 // 15 15 … … 18 18 size_t default_mmap_start(); // CFA extras 19 19 size_t default_heap_expansion(); 20 bool default_heap_exhausted(); // unsafe to call printf!21 20 22 21 bool traceHeap(); … … 31 30 bool checkFreeOn(); 32 31 bool checkFreeOff(); 32 33 // supported mallopt options 34 #ifndef M_MMAP_THRESHOLD 35 #define M_MMAP_THRESHOLD (-1) 36 #endif // M_TOP_PAD 37 #ifndef M_TOP_PAD 38 #define M_TOP_PAD (-2) 39 #endif // M_TOP_PAD 33 40 34 41 extern "C" { -
libcfa/src/iostream.cfa
r1eb239e4 r8465b4d 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jul 20 15:00:37202013 // Update Count : 112 412 // Last Modified On : Mon Aug 10 09:32:14 2020 13 // Update Count : 1126 14 14 // 15 15 … … 615 615 sepOff( os ); \ 616 616 fmt2.flags.left = true; \ 617 int msigd = ceiling ( high1( fmt.val ), 3 ); \617 int msigd = ceiling_div( high1( fmt.val ), 3 ); \ 618 618 fmt2.wd = f.wd - (fmt.pc > msigd ? fmt.pc : msigd); \ 619 619 if ( ! fmt.flags.nobsdp ) fmt2.wd -= 1; /* compensate for 0 base specifier */ \ … … 704 704 if ( f.base == 'd' && (f.flags.neg || f.flags.sign) ) bs = 1; // sign ? 705 705 } else { 706 dig = ceiling ( high1( f.val ), bits );706 dig = ceiling_div( high1( f.val ), bits ); 707 707 if ( ! f.flags.nobsdp ) { // base prefix ? 708 708 if ( f.base == 'o' ) {
Note:
See TracChangeset
for help on using the changeset viewer.