Changeset 777 for soft/giet_vm/giet_libs
- Timestamp:
- Feb 4, 2016, 6:25:22 PM (9 years ago)
- Location:
- soft/giet_vm/giet_libs
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/malloc.c
r709 r777 8 8 #include "malloc.h" 9 9 #include "stdio.h" 10 #include "stdlib.h" 10 11 #include "giet_config.h" 11 12 … … 214 215 215 216 //////////////////////////////////////// 216 void * remote_malloc( unsignedint size,217 void * remote_malloc( int size, 217 218 unsigned int x, 218 219 unsigned int y ) … … 278 279 #endif 279 280 280 return (void*) base;281 return (void*) base; 281 282 282 283 } // end remote_malloc() … … 284 285 285 286 ////////////////////////////////// 286 void * malloc( unsignedint size )287 void * malloc( int size ) 287 288 { 288 289 // get cluster coordinates 289 unsigned int 290 unsigned int 291 unsigned int 290 unsigned int x; 291 unsigned int y; 292 unsigned int lpid; 292 293 giet_proc_xyp( &x, &y, &lpid ); 293 294 294 295 return remote_malloc( size, x, y ); 295 296 } 297 298 299 //////////////////////////////////// 300 void * calloc ( int nbmem, int size ) 301 { 302 void * a = malloc( nbmem * size ); 303 memset( a, 0, nbmem * size ); 304 return a; 305 } 296 306 297 307 /////////////////////////////////////////// -
soft/giet_vm/giet_libs/malloc.h
r709 r777 93 93 unsigned int y ); 94 94 95 extern void* malloc( unsigned int size ); 95 extern void * malloc( int size ); 96 extern void * calloc( int nbmem, 97 int size ); 96 98 97 extern void * remote_malloc( unsignedint size,98 unsigned int x,99 unsigned int y );99 extern void * remote_malloc( int size, 100 unsigned int x, 101 unsigned int y ); 100 102 101 103 extern void free(void * ptr); -
soft/giet_vm/giet_libs/math.h
r667 r777 7 7 8 8 double fabs (double x); 9 double fmod (double x, double y); 9 10 double floor (double x); 11 double ceil (double x); 10 12 double sin (double x); 11 13 double cos (double x); 12 14 double pow (double x, double y); 15 double exp (double x); 13 16 int isnan (double x); 14 17 int isfinite(double x); -
soft/giet_vm/giet_libs/math/e_pow.c
r682 r777 103 103 int32_t i,j,k,yisint,n; 104 104 int32_t hx,hy,ix,iy; 105 u _int32_t lx,ly;105 uint32_t lx,ly; 106 106 107 107 EXTRACT_WORDS(hx,lx,x); … … 180 180 181 181 /* (x<0)**(non-int) is NaN */ 182 if(((((u _int32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x);182 if(((((uint32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x); 183 183 184 184 /* |y| is huge */ … … 251 251 252 252 s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ 253 if(((((u _int32_t)hx>>31)-1)|(yisint-1))==0)253 if(((((uint32_t)hx>>31)-1)|(yisint-1))==0) 254 254 s = -one;/* (-ve)**(odd int) */ 255 255 … … 312 312 { 313 313 double z = __ieee754_pow(x, y); 314 if (isnan(y)) 314 if (isnan(y)) { 315 315 return z; 316 } 316 317 if (isnan(x)) { 317 318 if (y == 0.0) { … … 322 323 if (x == 0.0) { 323 324 if (y == 0.0) { 324 325 return 0; /* pow(0.0,0.0) */ 325 326 } 326 327 if (isfinite(y) && y < 0.0) { … … 332 333 if (isfinite(x) && isfinite(y)) { 333 334 if (isnan(z)) { 334 return 0.0 /0.0; /* pow neg**non-int */335 return 0.0 / 0.0; /* pow neg**non-int */ 335 336 } 336 337 { 337 338 double ret = huge; 338 339 y *= 0.5; 339 if(x<zero&&rint(y)!=y) ret = -huge; 340 if (x < zero && rint(y) !=y ) { 341 ret = -huge; 342 } 340 343 return ret; 341 344 } … … 347 350 return z; 348 351 } 352 353 /* 354 * Pseudo exp function (QM) 355 * There probably is a better implementation 356 */ 357 double exp(double x) 358 { 359 const double e = 2.71828182846; 360 return pow(e, x); 361 } 362 -
soft/giet_vm/giet_libs/math/e_rem_pio2.c
r581 r777 75 75 double tx[3]; 76 76 int32_t e0,i,j,nx,n,ix,hx; 77 u _int32_t low;77 uint32_t low; 78 78 79 79 GET_HIGH_WORD(hx,x); /* high word of x */ … … 115 115 y[0] = r-w; /* quick check no cancellation */ 116 116 } else { 117 u _int32_t high;117 uint32_t high; 118 118 j = ix>>20; 119 119 y[0] = r-w; -
soft/giet_vm/giet_libs/math/e_sqrt.c
r581 r777 93 93 int32_t sign = (int)0x80000000; 94 94 int32_t ix0,s0,q,m,t,i; 95 u _int32_t r,t1,s1,ix1,q1;95 uint32_t r,t1,s1,ix1,q1; 96 96 97 97 EXTRACT_WORDS(ix0,ix1,x); … … 168 168 if (z>=one) { 169 169 z = one+tiny; 170 if (q1==(u _int32_t)0xffffffff) { q1=0; q += 1;}170 if (q1==(uint32_t)0xffffffff) { q1=0; q += 1;} 171 171 else if (z>one) { 172 if (q1==(u _int32_t)0xfffffffe) q+=1;172 if (q1==(uint32_t)0xfffffffe) q+=1; 173 173 q1+=2; 174 174 } else -
soft/giet_vm/giet_libs/math/math_private.h
r588 r777 16 16 #define _MATH_PRIVATE_H_ 17 17 18 typedef unsigned int u_int32_t; 19 18 typedef unsigned int uint32_t; 20 19 typedef int int32_t; 20 typedef unsigned long long int uint64_t; 21 typedef long long int int64_t; 21 22 22 23 /* The original fdlibm code used statements like: … … 51 52 struct 52 53 { 53 u _int32_t msw;54 u _int32_t lsw;54 uint32_t msw; 55 uint32_t lsw; 55 56 } parts; 56 57 } ieee_double_shape_type; … … 64 65 struct 65 66 { 66 u _int32_t lsw;67 u _int32_t msw;67 uint32_t lsw; 68 uint32_t msw; 68 69 } parts; 69 70 } ieee_double_shape_type; -
soft/giet_vm/giet_libs/math/s_copysign.c
r581 r777 24 24 double copysign(double x, double y) 25 25 { 26 u _int32_t hx,hy;26 uint32_t hx,hy; 27 27 GET_HIGH_WORD(hx,x); 28 28 GET_HIGH_WORD(hy,y); -
soft/giet_vm/giet_libs/math/s_fabs.c
r581 r777 22 22 double fabs(double x) 23 23 { 24 u _int32_t high;24 uint32_t high; 25 25 GET_HIGH_WORD(high,x); 26 26 SET_HIGH_WORD(x,high&0x7fffffff); -
soft/giet_vm/giet_libs/math/s_finite.c
r581 r777 23 23 int isfinite(double x) 24 24 { 25 u _int32_t hx;25 uint32_t hx; 26 26 27 27 GET_HIGH_WORD(hx, x); -
soft/giet_vm/giet_libs/math/s_floor.c
r581 r777 11 11 12 12 /* Modified for GIET-VM static OS at UPMC, France 2015. 13 13 */ 14 14 15 15 /* … … 28 28 double floor(double x) 29 29 { 30 int32_t i0,i1,j0; 31 u_int32_t i,j; 32 EXTRACT_WORDS(i0,i1,x); 33 j0 = ((i0>>20)&0x7ff)-0x3ff; 34 if(j0<20) { 35 if(j0<0) { /* raise inexact if x != 0 */ 36 if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ 37 if(i0>=0) {i0=i1=0;} 38 else if(((i0&0x7fffffff)|i1)!=0) 39 { i0=0xbff00000;i1=0;} 40 } 41 } else { 42 i = (0x000fffff)>>j0; 43 if(((i0&i)|i1)==0) return x; /* x is integral */ 44 if(huge+x>0.0) { /* raise inexact flag */ 45 if(i0<0) i0 += (0x00100000)>>j0; 46 i0 &= (~i); i1=0; 47 } 48 } 49 } else if (j0>51) { 50 if(j0==0x400) return x+x; /* inf or NaN */ 51 else return x; /* x is integral */ 52 } else { 53 i = ((u_int32_t)(0xffffffff))>>(j0-20); 54 if((i1&i)==0) return x; /* x is integral */ 55 if(huge+x>0.0) { /* raise inexact flag */ 56 if(i0<0) { 57 if(j0==20) i0+=1; 58 else { 59 j = i1+(1<<(52-j0)); 60 if(j<i1) i0 +=1 ; /* got a carry */ 61 i1=j; 62 } 63 } 64 i1 &= (~i); 65 } 66 } 67 INSERT_WORDS(x,i0,i1); 68 return x; 30 int32_t i0, i1, j0; 31 uint32_t i, j; 32 EXTRACT_WORDS(i0, i1, x); 33 j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; 34 if (j0 < 20) { 35 if (j0 < 0) { /* raise inexact if x != 0 */ 36 if (huge + x > 0.0) {/* return 0*sign(x) if |x|<1 */ 37 if (i0 >= 0) { 38 i0 = i1 = 0; 39 } 40 else if (((i0 & 0x7fffffff) | i1) != 0) { 41 i0 = 0xbff00000; 42 i1 = 0; 43 } 44 } 45 } 46 else { 47 i = (0x000fffff) >> j0; 48 if (((i0 & i) | i1) == 0) { 49 return x; /* x is integral */ 50 } 51 if (huge + x > 0.0) { /* raise inexact flag */ 52 if (i0 < 0) { 53 i0 += (0x00100000) >> j0; 54 } 55 i0 &= (~i); 56 i1 = 0; 57 } 58 } 59 } 60 else if (j0 > 51) { 61 if (j0 == 0x400) { 62 return x + x; /* inf or NaN */ 63 } 64 else { 65 return x; /* x is integral */ 66 } 67 } 68 else { 69 i = ((uint32_t) (0xffffffff)) >> (j0 - 20); 70 if ((i1 & i)== 0) { 71 return x; /* x is integral */ 72 } 73 if (huge + x > 0.0) { /* raise inexact flag */ 74 if (i0 < 0) { 75 if (j0 == 20) { 76 i0 += 1; 77 } 78 else { 79 j = i1 + (1 << (52 - j0)); 80 if (j < i1) { 81 i0 += 1 ; /* got a carry */ 82 } 83 i1 = j; 84 } 85 } 86 i1 &= (~i); 87 } 88 } 89 INSERT_WORDS(x, i0, i1); 90 return x; 69 91 } 70 92 -
soft/giet_vm/giet_libs/math/s_isnan.c
r581 r777 26 26 EXTRACT_WORDS(hx,lx,x); 27 27 hx &= 0x7fffffff; 28 hx |= (u _int32_t)(lx|(-lx))>>31;28 hx |= (uint32_t)(lx|(-lx))>>31; 29 29 hx = 0x7ff00000 - hx; 30 return (int)(((u _int32_t)hx)>>31);30 return (int)(((uint32_t)hx)>>31); 31 31 } -
soft/giet_vm/giet_libs/math/s_rint.c
r581 r777 35 35 { 36 36 int32_t i0, j0, sx; 37 u _int32_t i,i1;37 uint32_t i,i1; 38 38 double t; 39 39 /* We use w = x + 2^52; t = w - 2^52; trick to round x to integer. … … 47 47 EXTRACT_WORDS(i0,i1,x); 48 48 /* Unbiased exponent */ 49 j0 = ((((u _int32_t)i0) >> 20)&0x7ff)-0x3ff;49 j0 = ((((uint32_t)i0) >> 20)&0x7ff)-0x3ff; 50 50 51 51 if (j0 > 51) { … … 57 57 58 58 /* Sign */ 59 sx = ((u _int32_t)i0) >> 31;59 sx = ((uint32_t)i0) >> 31; 60 60 61 61 if (j0<20) { … … 81 81 } 82 82 } else { 83 i = ((u _int32_t)(0xffffffff))>>(j0-20);83 i = ((uint32_t)(0xffffffff))>>(j0-20); 84 84 if ((i1&i)==0) return x; /* x is integral */ 85 85 i>>=1; -
soft/giet_vm/giet_libs/stdlib.c
r772 r777 110 110 } 111 111 return dst; 112 }113 114 ///////////////////////////////////115 int strlen( const char* string )116 {117 unsigned int i = 0;118 while ( string[i] != 0 ) i++;119 return i;120 }121 122 ///////////////////////////////123 int strcmp( const char * s1,124 const char * s2 )125 {126 while (1)127 {128 if (*s1 != *s2) return 1;129 if (*s1 == 0) break;130 s1++, s2++;131 }132 return 0;133 }134 135 /////////////////////////136 char* strcpy( char* dest,137 const char* source )138 {139 if (!dest || !source) return dest;140 141 while (*source)142 {143 *(dest) = *(source);144 dest++;145 source++;146 }147 *dest = 0;148 return dest;149 112 } 150 113 -
soft/giet_vm/giet_libs/stdlib.h
r772 r777 41 41 unsigned int size ); 42 42 43 ////////////////////////////////////////////////////////////////////////////////////////44 // This function returns the number of characters in a string.45 // The terminating NUL character is not taken into account.46 ////////////////////////////////////////////////////////////////////////////////////////47 int strlen( const char* string );48 49 ////////////////////////////////////////////////////////////////////////////////////////50 // This function compare the two s1 & s2 strings.51 // It returns 0 if strings are identical (including the terminating NUL character).52 // It returns 1 if they are not.53 ////////////////////////////////////////////////////////////////////////////////////////54 int strcmp( const char* s1,55 const char* s2 );56 57 ////////////////////////////////////////////////////////////////////////////////////////58 // This function copies the source string to the dest string.59 // It returns a pointer on the dest string.60 ////////////////////////////////////////////////////////////////////////////////////////61 char* strcpy( char* dest,62 const char* source );63 43 64 44 /////////////////////////////////////////////////////////////////////////////////////// -
soft/giet_vm/giet_libs/string.c
r607 r777 7 7 8 8 /////////////////////////////////////////////////////////////////////////////////// 9 // char * strcpy ( char * destination, const char * source)9 // char * strcpy (char * destination, const char * source) 10 10 /////////////////////////////////////////////////////////////////////////////////// 11 char * strcpy ( char * destination, const char * source)11 char * strcpy (char * destination, const char * source) 12 12 { 13 if (!destination || !source) 13 if (!destination || !source) { 14 14 return destination; 15 } 15 16 16 while (*source) 17 while (*source) { 17 18 *(destination++) = *(source++); 19 } 18 20 19 21 return destination; 20 22 } 21 23 24 22 25 /////////////////////////////////////////////////////////////////////////////////// 23 // int strcmp ( const char * str1, const char * str2)26 // char * strncpy (char * destination, const char * source, int maxlen) 24 27 /////////////////////////////////////////////////////////////////////////////////// 25 int strcmp ( const char * str1, const char * str2)28 char * strncpy(char * dest, const char * src, int n) 26 29 { 27 if (!str1 || !str2) 30 int i; 31 for (i = 0; i < n && src[i] != '\0'; i++) { 32 dest[i] = src[i]; 33 } 34 for (; i < n ; i++) { 35 dest[i] = '\0'; 36 } 37 return dest; 38 } 39 40 41 /////////////////////////////////////////////////////////////////////////////////// 42 // int strcmp (const char * str1, const char * str2) 43 /////////////////////////////////////////////////////////////////////////////////// 44 int strcmp (const char * str1, const char * str2) 45 { 46 if (!str1 || !str2) { 28 47 return -123456; // return a value out of the char's bounds 48 } 29 49 30 while (*str1 && *str1 == *str2) 31 { 50 while (*str1 && *str1 == *str2) { 32 51 str1++; 33 52 str2++; … … 40 59 // int strlen ( const char * str ) 41 60 /////////////////////////////////////////////////////////////////////////////////// 42 int strlen ( const char * str)61 int strlen (const char * str) 43 62 { 44 const char * s = str;63 const char * s = str; 45 64 46 while (*s) 65 while (*s) { 47 66 s++; 48 67 } 49 68 return (s - str); 50 69 } 70 71 72 /////////////////////////////////////////////////////////////////////////////////// 73 // char * strchr(const char * str) 74 /////////////////////////////////////////////////////////////////////////////////// 75 char * strchr(const char * str, int c) 76 { 77 const char * s = str; 78 const char ch = c; 79 while (*s != ch && *s != '\0') { 80 s++; 81 } 82 83 return (char *) s; 84 } 85 51 86 52 87 // Local Variables: -
soft/giet_vm/giet_libs/string.h
r607 r777 9 9 #define _STRING_H 10 10 11 char * strcpy ( char * destination, const char * source ); 12 int strcmp ( const char * str1, const char * str2 ); 13 int strlen ( const char * str ); 11 //////////////////////////////////////////////////////////////////////////////////////// 12 // This function copies the source string to the dest string. 13 // It returns a pointer on the dest string. 14 //////////////////////////////////////////////////////////////////////////////////////// 15 char * strcpy(char * destination, const char * source); 16 17 //////////////////////////////////////////////////////////////////////////////////////// 18 // The strncpy() function is similar to strcpy, except that at most n bytes of src 19 // are copied. If there is no null byte among the first n bytes of src, the string 20 // placed in dest will not be null terminated. 21 //////////////////////////////////////////////////////////////////////////////////////// 22 char * strncpy(char * dest, const char * src, int n); 23 24 //////////////////////////////////////////////////////////////////////////////////////// 25 //The strcmp() function compares the two strings s1 and s2. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. 26 //////////////////////////////////////////////////////////////////////////////////////// 27 int strcmp(const char * str1, const char * str2); 28 29 //////////////////////////////////////////////////////////////////////////////////////// 30 // This function returns the number of characters in a string. 31 // The terminating NULL character is not taken into account. 32 //////////////////////////////////////////////////////////////////////////////////////// 33 int strlen(const char * str); 34 35 //////////////////////////////////////////////////////////////////////////////////////// 36 // The strchr() function returns a pointer to the first occurrence of the character c 37 // in the string s. 38 //////////////////////////////////////////////////////////////////////////////////////// 39 char * strchr(const char * str, int c); 14 40 15 41 #endif
Note: See TracChangeset
for help on using the changeset viewer.