Changeset 821 for soft/giet_vm/applications/rosenfeld/src/ecc_common.c
- Timestamp:
- May 6, 2016, 3:06:29 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/src/ecc_common.c
r798 r821 8 8 #include <math.h> 9 9 10 #ifdef CLI11 10 #include "nrc_os_config.h" 12 11 #include "nrc.h" 13 #endif14 12 15 13 #if TARGET_OS == LINUX … … 44 42 return (a > b ? a : b); 45 43 } 44 45 46 46 // ------------------------------------------ 47 47 uint32 ui32Max3(uint32 a, uint32 b, uint32 c) … … 50 50 return ui32Max2(ui32Max2(a, b), c); 51 51 } 52 53 52 54 // ---------------------------------------------------- 53 55 uint32 ui32Max4(uint32 a, uint32 b, uint32 c, uint32 d) … … 56 58 return ui32Max2(ui32Max2(a, b), ui32Max2(c,d)); 57 59 } 60 61 58 62 // -------------------------------- 59 63 uint32 ui32Min2(uint32 a, uint32 b) … … 62 66 return (a < b ? a : b); 63 67 } 68 69 64 70 // ------------------------------------------ 65 71 uint32 ui32Min3(uint32 a, uint32 b, uint32 c) … … 68 74 return ui32Min2(ui32Min2(a, b), c); 69 75 } 76 77 70 78 // ---------------------------------------------------- 71 79 uint32 ui32Min4(uint32 a, uint32 b, uint32 c, uint32 d) … … 74 82 return ui32Min2(ui32Min2(a, b), ui32Min2(c,d)); 75 83 } 84 85 76 86 /* ----------------------------------- */ 77 87 uint32 ui32MinNonNul2(uint32 a, uint32 b) … … 84 94 return a; 85 95 } 96 97 86 98 /* --------------------------------------------- */ 87 99 uint32 ui32MinNonNul3(uint32 a, uint32 b, uint32 c) … … 96 108 return m; 97 109 } 110 111 98 112 /* ---------------------------------------------------- */ 99 113 uint32 ui32MinNonNul3Cond(uint32 a0, uint32 a1, uint32 a2) … … 105 119 return m; 106 120 } 121 122 107 123 /* ----------------------------------------------------------- */ 108 124 uint32 ui32MinNonNul4(uint32 a0, uint32 a1, uint32 a2, uint32 a3) … … 118 134 return m; 119 135 } 136 137 120 138 /* ---------------------------------------------------------------------- */ 121 139 uint32 ui32MinNonNul5(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4) … … 132 150 return m; 133 151 } 152 153 134 154 /* -------------------------------------------------------------------------- */ 135 155 uint32 ui32MinNonNul5Cond(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4) … … 141 161 return m; 142 162 } 163 164 143 165 /* ------------------------------------------------------------------------------------------------------- */ 144 166 uint32 ui32MinNonNul8(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7) … … 158 180 return m; 159 181 } 182 183 160 184 /* ------------------------------------------------------------------------------------------------------------------ */ 161 185 uint32 ui32MinNonNul9(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7, uint32 a8) … … 176 200 return m; 177 201 } 202 203 178 204 /* ---------------------------------------------------------------------------------------------------------------------- */ 179 205 uint32 ui32MinNonNul9Cond(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7, uint32 a8) … … 190 216 return m; 191 217 } 192 // -------------------------------- 193 void initT(uint32 *T, uint32 nemax) 194 // -------------------------------- 218 219 220 // --------------------------------- 221 void initT(uint32 * T, uint32 nemax) 222 // --------------------------------- 195 223 { 196 224 int i; … … 199 227 } 200 228 } 229 230 201 231 /* -------------------------- */ 202 232 //void initA(uint32 *A, uint32 nemax) … … 208 238 } 209 239 }*/ 240 241 210 242 // -------------------------------- 211 243 void initZ(uint32 *T, uint32 nemax) … … 217 249 } 218 250 } 251 252 219 253 // -------------------------------------- 220 254 void check_initT(uint32 *T, uint32 nemax) … … 223 257 check_initT_range(T, 0, nemax, nemax); 224 258 } 259 260 225 261 // -------------------------------------- 226 262 void check_initZ(uint32 *T, uint32 nemax) … … 229 265 check_initZ_range(T, 0, nemax, nemax); 230 266 } 267 268 231 269 // --------------------------------------------------------------- 232 270 void check_initT_range(uint32 *T, uint32 i0, uint32 ii, uint32 i1) … … 243 281 } 244 282 } 283 284 245 285 // --------------------------------------------------------------- 246 286 void check_initR_range(uint32 *R, uint32 i0, uint32 ii, uint32 i1) … … 257 297 } 258 298 } 299 300 259 301 // --------------------------------------------------------------- 260 302 void check_initZ_range(uint32 *T, uint32 i0, uint32 ii, uint32 i1) … … 271 313 } 272 314 } 315 316 273 317 /* --------------------------------------------------------------------------------------------------- */ 274 318 void binarisation_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 seuil, uint8 val, uint8 **Y) … … 309 353 } 310 354 } 311 /* ------------------------------------------------------------------------------- */ 312 void graphviz_write_ui8vector(uint8 *v, int i0, int i1, char *format, char *filename) 313 /* ------------------------------------------------------------------------------- */ 314 { 315 int i; 355 /* ---------------------------------------------------------------------------------- */ 356 void graphviz_write_ui8vector(uint8 * v, int i0, int i1, char * format, char * filename) 357 /* ---------------------------------------------------------------------------------- */ 358 { 359 int i; 360 char complete_filename[64]; 361 362 snprintf(complete_filename, 64, "%s.dot", filename); 363 364 #if TARGET_OS == GIETVM 316 365 int fd; 317 char complete_filename[64];318 319 snprintf(complete_filename, 64, "%s.dot", filename);320 321 366 fd = open(complete_filename, O_CREAT | O_TRUNC); 322 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }323 367 324 368 fprintf(fd, "digraph %s {\n", filename); … … 328 372 fprintf(fd, "}\n"); 329 373 close(fd); 330 } 331 /* --------------------------------------------------------------------------------- */ 332 void graphviz_write_ui16vector(uint16 *v, int i0, int i1, char *format, char *filename) 333 /* --------------------------------------------------------------------------------- */ 334 { 335 int i; 374 #elif TARGET_OS == LINUX 375 FILE * f; 376 f = fopen(complete_filename, "w"); 377 if (f == NULL) { 378 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 379 } 380 381 fprintf(f, "digraph %s {\n", filename); 382 for (i = i0; i <= i1; i++) { 383 fprintf(f, "%3d -> %3d;\n", i, v[i]); 384 } 385 fprintf(f, "}\n"); 386 fclose(f); 387 #endif 388 } 389 /* ------------------------------------------------------------------------------------ */ 390 void graphviz_write_ui16vector(uint16 * v, int i0, int i1, char * format, char * filename) 391 /* ------------------------------------------------------------------------------------ */ 392 { 393 int i; 394 char complete_filename[64]; 395 396 snprintf(complete_filename, 64, "%s.dot", filename); 397 398 #if TARGET_OS == GIETVM 336 399 int fd; 337 char complete_filename[64];338 339 snprintf(complete_filename, 64, "%s.dot", filename);340 341 342 400 fd = open(complete_filename, O_CREAT | O_TRUNC); 343 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }344 401 345 402 fprintf(fd, "digraph %s {\n", filename); … … 349 406 fprintf(fd, "}\n"); 350 407 close(fd); 351 } 352 /* --------------------------------------------------------------------------------- */ 353 void graphviz_write_ui32vector(uint32 *v, int i0, int i1, char *format, char *filename) 354 /* --------------------------------------------------------------------------------- */ 355 { 356 int i; 408 #elif TARGET_OS == LINUX 409 FILE * f; 410 f = fopen(complete_filename, "w"); 411 if (f == NULL) { 412 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 413 } 414 415 fprintf(f, "digraph %s {\n", filename); 416 for (i = i0; i <= i1; i++) { 417 fprintf(f, "%3d -> %3d;\n", i, v[i]); 418 } 419 fprintf(f, "}\n"); 420 fclose(f); 421 #endif 422 } 423 424 425 /* ------------------------------------------------------------------------------------ */ 426 void graphviz_write_ui32vector(uint32 * v, int i0, int i1, char * format, char * filename) 427 /* ------------------------------------------------------------------------------------ */ 428 { 429 int i; 430 char complete_filename[64]; 431 432 snprintf(complete_filename, 64, "%s.dot", filename); 433 434 #if TARGET_OS == GIETVM 357 435 int fd; 358 char complete_filename[64];359 360 snprintf(complete_filename, 64, "%s.dot", filename);361 362 363 436 fd = open(complete_filename, O_CREAT | O_TRUNC); 364 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }365 437 366 438 fprintf(fd, "digraph %s {\n", filename); … … 370 442 fprintf(fd, "}\n"); 371 443 close(fd); 372 } 373 /* ------------------------------------------------------------------------------ */ 374 void mod_ui32matrix_ui8matrix(uint32 **X, int i0, int i1, int j0, int j1, uint8 **Y) 375 /* ------------------------------------------------------------------------------ */ 444 #elif TARGET_OS == LINUX 445 FILE * f; 446 f = fopen(complete_filename, "w"); 447 if (f == NULL) { 448 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 449 } 450 451 fprintf(f, "digraph %s {\n", filename); 452 for (i = i0; i <= i1; i++) { 453 fprintf(f, "%3d -> %3d;\n", i, v[i]); 454 } 455 fprintf(f, "}\n"); 456 fclose(f); 457 #endif 458 } 459 460 461 /* -------------------------------------------------------------------------------- */ 462 void mod_ui32matrix_ui8matrix(uint32 ** X, int i0, int i1, int j0, int j1, uint8 ** Y) 463 /* -------------------------------------------------------------------------------- */ 376 464 { 377 465 int i, j; … … 382 470 } 383 471 } 384 // ------------------------------------------------------------------------------------------ 385 void positive_mod_ui32matrix_ui8matrix(uint32 **X, int i0, int i1, int j0, int j1, uint8 **Y) 386 // ------------------------------------------------------------------------------------------ 472 473 474 // -------------------------------------------------------------------------------------------- 475 void positive_mod_ui32matrix_ui8matrix(uint32 ** X, int i0, int i1, int j0, int j1, uint8 ** Y) 476 // -------------------------------------------------------------------------------------------- 387 477 { 388 478 int i, j; … … 392 482 if (X[i][j] < 255) { 393 483 Y[i][j] = X[i][j]; // pour que e=1 reste rouge 394 } else { 484 } 485 else { 395 486 Y[i][j] = (X[i][j] % 254) + 1; 396 487 } 397 } else { 488 } 489 else { 398 490 Y[i][j] = 0; 399 491 } … … 402 494 } 403 495 } 404 /* --------------------------------------------------------------------------------- */ 405 void graphviz_write_ui32vector_par(uint32 *v, int i0, int i1, char *format, char *filename) 406 /* --------------------------------------------------------------------------------- */ 407 { 408 int i; 496 497 498 /* ---------------------------------------------------------------------------------------- */ 499 void graphviz_write_ui32vector_par(uint32 * v, int i0, int i1, char * format, char * filename) 500 /* ---------------------------------------------------------------------------------------- */ 501 { 502 int i; 503 char complete_filename[64]; 504 505 snprintf(complete_filename, 64, "%s.dot", filename); 506 507 #if TARGET_OS == GIETVM 409 508 int fd; 410 char complete_filename[64];411 412 snprintf(complete_filename, 64, "%s.dot", filename);413 414 415 509 fd = open(complete_filename, O_CREAT | O_TRUNC); 416 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }417 510 418 511 fprintf(fd, "digraph %s {\n", filename); … … 422 515 fprintf(fd, "}\n"); 423 516 close(fd); 424 } 517 #else 518 FILE * f; 519 f = fopen(complete_filename, "w"); 520 if (f == NULL) { 521 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 522 } 523 fprintf(f, "digraph %s {\n", filename); 524 for (i = i0; i <= i1; i++) { 525 fprintf(f, "%3d -> %3d;\n", i, v[i]); 526 } 527 fprintf(f, "}\n"); 528 fclose(f); 529 #endif 530 } 531 532 425 533 // -------------------------------------- 426 534 uint32 mt19937_uint32(uint32 a, uint32 b) … … 431 539 uint32 x32; 432 540 433 if (b < a) return mt19937_uint32(b, a); 541 if (b < a) { 542 return mt19937_uint32(b, a); 543 } 434 544 435 545 //printf("a = %u b = %u\n", a, b); … … 441 551 return x32; 442 552 } 443 // ----------------------- 444 BOOL strto_Bool(char *str) 445 // ----------------------- 446 { 447 BOOL b = TRUE; 448 if (strcmp(str, "TRUE" ) == 0) b = TRUE; 449 if (strcmp(str, "true" ) == 0) b = TRUE; 450 451 if (strcmp(str, "FALSE") == 0) b = FALSE; 452 if (strcmp(str, "false") == 0) b = FALSE; 553 554 555 // ------------------------ 556 bool strto_Bool(char * str) 557 // ------------------------ 558 { 559 bool b = true; 560 if (strcmp(str, "TRUE" ) == 0) b = true; 561 if (strcmp(str, "true" ) == 0) b = true; 562 563 if (strcmp(str, "FALSE") == 0) b = false; 564 if (strcmp(str, "false") == 0) b = false; 453 565 454 566 return b; 455 567 } 456 // ------------------------------------------------------------ 457 void check_no_write(uint32 **T, int i0, int i1, int j0, int j1) 458 // ------------------------------------------------------------ 568 569 570 // ------------------------------------------------------------- 571 void check_no_write(uint32 ** T, int i0, int i1, int j0, int j1) 572 // ------------------------------------------------------------- 459 573 { 460 574 int i, j; … … 467 581 } 468 582 } 583 584
Note: See TracChangeset
for help on using the changeset viewer.