source: src/libcfa/stdlib @ f32e53e

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since f32e53e was 53a6c2a, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

change meaning of sepOn, and replace #if with #pragma once in include files

  • Property mode set to 100644
File size: 8.4 KB
Line 
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// stdlib --
8//
9// Author           : Peter A. Buhr
10// Created On       : Thu Jan 28 17:12:35 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Fri Jul  7 09:34:49 2017
13// Update Count     : 219
14//
15
16#pragma once
17
18//---------------------------------------
19
20extern "C" {
21#ifndef EXIT_FAILURE
22#define EXIT_FAILURE    1                                                               // failing exit status
23#define EXIT_SUCCESS    0                                                               // successful exit status
24#endif // ! EXIT_FAILURE
25} // extern "C"
26
27//---------------------------------------
28
29// allocation, non-array types
30static inline forall( dtype T | sized(T) ) T * malloc( void ) {
31        //printf( "X1\n" );
32        return (T *)(void *)malloc( (size_t)sizeof(T) );        // C malloc
33} // malloc
34
35extern "C" { void * calloc( size_t dim, size_t size ); } // default C routine
36static inline forall( dtype T | sized(T) ) T * calloc( size_t dim ) {
37        //printf( "X2\n" );
38        return (T *)(void *)calloc( dim, sizeof(T) );           // C cmalloc
39}
40
41extern "C" { void * realloc( void * ptr, size_t size ); } // default C routine for void *
42static inline forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size ) {
43        //printf( "X3\n" );
44        return (T *)(void *)realloc( (void *)ptr, size );
45}
46
47extern "C" { void * memalign( size_t align, size_t size ); } // use default C routine for void *
48static inline forall( dtype T | sized(T) ) T * memalign( size_t align ) {
49        //printf( "X4\n" );
50        return (T *)memalign( align, sizeof(T) );
51} // memalign
52
53static inline forall( dtype T | sized(T) ) T * aligned_alloc( size_t align ) {
54        //printf( "X5\n" );
55        return (T *)memalign( align, sizeof(T) );
56} // aligned_alloc
57
58extern "C" { int posix_memalign( void ** ptr, size_t align, size_t size ); } // use default C routine for void *
59static inline forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align ) {
60        //printf( "X6\n" );
61        return posix_memalign( (void **)ptr, align, sizeof(T) );
62} // posix_memalign
63
64
65extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void *
66
67static inline forall( dtype T | sized(T) ) T * alloc( void ) {
68        //printf( "X7\n" );
69        return (T *)(void *)malloc( (size_t)sizeof(T) );        // C malloc
70} // alloc
71static inline forall( dtype T | sized(T) ) T * alloc( char fill ) {
72        //printf( "X8\n" );
73        T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
74    return memset( ptr, (int)fill, sizeof(T) );                 // initial with fill value
75} // alloc
76
77static inline forall( dtype T | sized(T) ) T * alloc( size_t dim ) {
78        //printf( "X9\n" );
79        return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
80} // alloc
81static inline forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill ) {
82        //printf( "X10\n" );
83        T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
84    return memset( ptr, (int)fill, dim * sizeof(T) );
85} // alloc
86
87static inline forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim ) {
88        //printf( "X11\n" );
89        return (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
90} // alloc
91forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
92
93static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align ) {
94        //printf( "X13\n" );
95        return (T *)memalign( align, sizeof(T) );
96} // align_alloc
97static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill ) {
98        //printf( "X14\n" );
99    T * ptr = (T *)memalign( align, sizeof(T) );
100    return memset( ptr, (int)fill, sizeof(T) );
101} // align_alloc
102
103static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim ) {
104        //printf( "X15\n" );
105        return (T *)memalign( align, dim * sizeof(T) );
106} // align_alloc
107static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill ) {
108        //printf( "X16\n" );
109    T * ptr = (T *)memalign( align, dim * sizeof(T) );
110    return memset( ptr, (int)fill, dim * sizeof(T) );
111} // align_alloc
112
113
114// data, non-array types
115static inline forall( dtype T | sized(T) ) T * memset( T * dest, char c ) {
116        //printf( "X17\n" );
117        return memset( dest, c, sizeof(T) );
118} // memset
119extern "C" { void * memcpy( void * dest, const void * src, size_t size ); } // use default C routine for void *
120static inline forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src ) {
121        //printf( "X18\n" );
122        return memcpy( dest, src, sizeof(T) );
123} // memcpy
124
125// data, array types
126static inline forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ) {
127        //printf( "X19\n" );
128        return (void *)memset( dest, c, dim * sizeof(T) );      // C memset
129} // memset
130static inline forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ) {
131        //printf( "X20\n" );
132        return (void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
133} // memcpy
134
135// allocation/deallocation and constructor/destructor, non-array types
136forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );
137forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );
138forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } ) void delete( T * ptr, Params rest );
139
140// allocation/deallocation and constructor/destructor, array types
141forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );
142forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );
143forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } ) void adelete( size_t dim, T arr[], Params rest );
144
145//---------------------------------------
146
147int ato( const char * ptr );
148unsigned int ato( const char * ptr );
149long int ato( const char * ptr );
150unsigned long int ato( const char * ptr );
151long long int ato( const char * ptr );
152unsigned long long int ato( const char * ptr );
153float ato( const char * ptr );
154double ato( const char * ptr );
155long double ato( const char * ptr );
156float _Complex ato( const char * ptr );
157double _Complex ato( const char * ptr );
158long double _Complex ato( const char * ptr );
159
160int strto( const char * sptr, char ** eptr, int base );
161unsigned int strto( const char * sptr, char ** eptr, int base );
162long int strto( const char * sptr, char ** eptr, int base );
163unsigned long int strto( const char * sptr, char ** eptr, int base );
164long long int strto( const char * sptr, char ** eptr, int base );
165unsigned long long int strto( const char * sptr, char ** eptr, int base );
166float strto( const char * sptr, char ** eptr );
167double strto( const char * sptr, char ** eptr );
168long double strto( const char * sptr, char ** eptr );
169float _Complex strto( const char * sptr, char ** eptr );
170double _Complex strto( const char * sptr, char ** eptr );
171long double _Complex strto( const char * sptr, char ** eptr );
172
173//---------------------------------------
174
175forall( otype T | { int ?<?( T, T ); } )
176T * bsearch( T key, const T * arr, size_t dim );
177
178forall( otype T | { int ?<?( T, T ); } )
179unsigned int bsearch( T key, const T * arr, size_t dim );
180
181
182forall( otype T | { int ?<?( T, T ); } )
183void qsort( const T * arr, size_t dim );
184
185//---------------------------------------
186
187forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
188[ T, T ] div( T t1, T t2 );
189
190//---------------------------------------
191
192unsigned char abs( signed char );
193extern "C" { int abs( int ); }                                                  // use default C routine for int
194unsigned long int abs( long int );
195unsigned long long int abs( long long int );
196float abs( float );
197double abs( double );
198long double abs( long double );
199float abs( float _Complex );
200double abs( double _Complex );
201long double abs( long double _Complex );
202forall( otype T | { void ?{}( T *, zero_t ); int ?<?( T, T ); T -?( T ); } )
203T abs( T );
204
205//---------------------------------------
206
207void rand48seed( long int s );
208char rand48( void );
209int rand48( void );
210unsigned int rand48( void );
211long int rand48( void );
212unsigned long int rand48( void );
213float rand48( void );
214double rand48( void );
215float _Complex rand48( void );
216double _Complex rand48( void );
217long double _Complex rand48( void );
218
219//---------------------------------------
220
221forall( otype T | { int ?<?( T, T ); } )
222T min( T t1, T t2 );
223
224forall( otype T | { int ?>?( T, T ); } )
225T max( T t1, T t2 );
226
227forall( otype T | { T min( T, T ); T max( T, T ); } )
228T clamp( T value, T min_val, T max_val );
229
230forall( otype T )
231void swap( T * t1, T * t2 );
232
233// Local Variables: //
234// mode: c //
235// tab-width: 4 //
236// End: //
Note: See TracBrowser for help on using the repository browser.