Ignore:
Timestamp:
May 6, 2016, 3:06:29 PM (9 years ago)
Author:
meunier
Message:
  • Added several versions of rosenfeld: { SLOW, FAST } x { FEATURES, NO_FEATURES }
  • Added native linux compilation support
  • Added a script to check results natively
  • Started to refactor nrc code
File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/rosenfeld/src/ecc_common.c

    r798 r821  
    88#include <math.h>
    99
    10 #ifdef CLI
    1110#include "nrc_os_config.h"
    1211#include "nrc.h"
    13 #endif
    1412
    1513#if TARGET_OS == LINUX
     
    4442    return (a > b ? a : b);
    4543}
     44
     45
    4646// ------------------------------------------
    4747uint32 ui32Max3(uint32 a, uint32 b, uint32 c)
     
    5050    return ui32Max2(ui32Max2(a, b), c);
    5151}
     52
     53
    5254// ----------------------------------------------------
    5355uint32 ui32Max4(uint32 a, uint32 b, uint32 c, uint32 d)
     
    5658    return ui32Max2(ui32Max2(a, b), ui32Max2(c,d));
    5759}
     60
     61
    5862// --------------------------------
    5963uint32 ui32Min2(uint32 a, uint32 b)
     
    6266    return (a < b ? a : b);
    6367}
     68
     69
    6470// ------------------------------------------
    6571uint32 ui32Min3(uint32 a, uint32 b, uint32 c)
     
    6874    return ui32Min2(ui32Min2(a, b), c);
    6975}
     76
     77
    7078// ----------------------------------------------------
    7179uint32 ui32Min4(uint32 a, uint32 b, uint32 c, uint32 d)
     
    7482    return ui32Min2(ui32Min2(a, b), ui32Min2(c,d));
    7583}
     84
     85
    7686/* ----------------------------------- */
    7787uint32 ui32MinNonNul2(uint32 a, uint32 b)
     
    8494    return a;
    8595}
     96
     97
    8698/* --------------------------------------------- */
    8799uint32 ui32MinNonNul3(uint32 a, uint32 b, uint32 c)
     
    96108    return m;
    97109}
     110
     111
    98112/* ---------------------------------------------------- */
    99113uint32 ui32MinNonNul3Cond(uint32 a0, uint32 a1, uint32 a2)
     
    105119    return m;
    106120}
     121
     122
    107123/* ----------------------------------------------------------- */
    108124uint32 ui32MinNonNul4(uint32 a0, uint32 a1, uint32 a2, uint32 a3)
     
    118134    return m;
    119135}
     136
     137
    120138/* ---------------------------------------------------------------------- */
    121139uint32 ui32MinNonNul5(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4)
     
    132150    return m;
    133151}
     152
     153
    134154/* -------------------------------------------------------------------------- */
    135155uint32 ui32MinNonNul5Cond(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4)
     
    141161    return m;
    142162}
     163
     164
    143165/* ------------------------------------------------------------------------------------------------------- */
    144166uint32 ui32MinNonNul8(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7)
     
    158180    return m;
    159181}
     182
     183
    160184/* ------------------------------------------------------------------------------------------------------------------ */
    161185uint32 ui32MinNonNul9(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7, uint32 a8)
     
    176200    return m;
    177201}
     202
     203
    178204/* ---------------------------------------------------------------------------------------------------------------------- */
    179205uint32 ui32MinNonNul9Cond(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7, uint32 a8)
     
    190216    return m;
    191217}
    192 // --------------------------------
    193 void initT(uint32 *T, uint32 nemax)
    194 // --------------------------------
     218
     219
     220// ---------------------------------
     221void initT(uint32 * T, uint32 nemax)
     222// ---------------------------------
    195223{
    196224    int i;
     
    199227    }
    200228}
     229
     230
    201231/* -------------------------- */
    202232//void initA(uint32 *A, uint32 nemax)
     
    208238    }
    209239}*/
     240
     241
    210242// --------------------------------
    211243void initZ(uint32 *T, uint32 nemax)
     
    217249    }
    218250}
     251
     252
    219253// --------------------------------------
    220254void check_initT(uint32 *T, uint32 nemax)
     
    223257    check_initT_range(T, 0, nemax, nemax);
    224258}
     259
     260
    225261// --------------------------------------
    226262void check_initZ(uint32 *T, uint32 nemax)
     
    229265    check_initZ_range(T, 0, nemax, nemax);
    230266}
     267
     268
    231269// ---------------------------------------------------------------
    232270void check_initT_range(uint32 *T, uint32 i0, uint32 ii, uint32 i1)
     
    243281    }
    244282}
     283
     284
    245285// ---------------------------------------------------------------
    246286void check_initR_range(uint32 *R, uint32 i0, uint32 ii, uint32 i1)
     
    257297    }
    258298}
     299
     300
    259301// ---------------------------------------------------------------
    260302void check_initZ_range(uint32 *T, uint32 i0, uint32 ii, uint32 i1)
     
    271313    }
    272314}
     315
     316
    273317/* --------------------------------------------------------------------------------------------------- */
    274318void binarisation_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 seuil, uint8 val, uint8 **Y)
     
    309353    }
    310354}
    311 /* ------------------------------------------------------------------------------- */
    312 void graphviz_write_ui8vector(uint8 *v, int i0, int i1, char *format, char *filename)
    313 /* ------------------------------------------------------------------------------- */
    314 {
    315     int i;
     355/* ---------------------------------------------------------------------------------- */
     356void 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
    316365    int fd;
    317     char complete_filename[64];
    318    
    319     snprintf(complete_filename, 64, "%s.dot", filename);
    320    
    321366    fd = open(complete_filename, O_CREAT | O_TRUNC);
    322     //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }
    323367   
    324368    fprintf(fd, "digraph %s {\n", filename);
     
    328372    fprintf(fd, "}\n");
    329373    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/* ------------------------------------------------------------------------------------ */
     390void 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
    336399    int fd;
    337     char complete_filename[64];
    338    
    339     snprintf(complete_filename, 64, "%s.dot", filename);
    340    
    341    
    342400    fd = open(complete_filename, O_CREAT | O_TRUNC);
    343     //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }
    344401   
    345402    fprintf(fd, "digraph %s {\n", filename);
     
    349406    fprintf(fd, "}\n");
    350407    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/* ------------------------------------------------------------------------------------ */
     426void 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
    357435    int fd;
    358     char complete_filename[64];
    359    
    360     snprintf(complete_filename, 64, "%s.dot", filename);
    361    
    362    
    363436    fd = open(complete_filename, O_CREAT | O_TRUNC);
    364     //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }
    365437   
    366438    fprintf(fd, "digraph %s {\n", filename);
     
    370442    fprintf(fd, "}\n");
    371443    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/* -------------------------------------------------------------------------------- */
     462void mod_ui32matrix_ui8matrix(uint32 ** X, int i0, int i1, int j0, int j1, uint8 ** Y)
     463/* -------------------------------------------------------------------------------- */
    376464{
    377465    int i, j;
     
    382470    }
    383471}
    384 // ------------------------------------------------------------------------------------------
    385 void positive_mod_ui32matrix_ui8matrix(uint32 **X, int i0, int i1, int j0, int j1, uint8 **Y)
    386 // ------------------------------------------------------------------------------------------
     472
     473
     474// --------------------------------------------------------------------------------------------
     475void positive_mod_ui32matrix_ui8matrix(uint32 ** X, int i0, int i1, int j0, int j1, uint8 ** Y)
     476// --------------------------------------------------------------------------------------------
    387477{
    388478    int i, j;
     
    392482                if (X[i][j] < 255) {
    393483                    Y[i][j] = X[i][j]; // pour que e=1 reste rouge
    394                 } else {
     484                }
     485                else {
    395486                    Y[i][j] = (X[i][j] % 254) + 1;
    396487                }
    397             } else {
     488            }
     489            else {
    398490                Y[i][j] = 0;
    399491            }
     
    402494    }
    403495}
    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/* ---------------------------------------------------------------------------------------- */
     499void 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
    409508    int fd;
    410     char complete_filename[64];
    411    
    412     snprintf(complete_filename, 64, "%s.dot", filename);
    413    
    414    
    415509    fd = open(complete_filename, O_CREAT | O_TRUNC);
    416     //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }
    417510   
    418511    fprintf(fd, "digraph %s {\n", filename);
     
    422515    fprintf(fd, "}\n");
    423516    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
    425533// --------------------------------------
    426534uint32 mt19937_uint32(uint32 a, uint32 b)
     
    431539    uint32 x32;
    432540
    433     if (b < a) return mt19937_uint32(b, a);
     541    if (b < a) {
     542        return mt19937_uint32(b, a);
     543    }
    434544   
    435545    //printf("a = %u b = %u\n", a, b);
     
    441551    return x32;
    442552}
    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// ------------------------
     556bool 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;
    453565   
    454566    return b;
    455567}
    456 // ------------------------------------------------------------
    457 void check_no_write(uint32 **T, int i0, int i1, int j0, int j1)
    458 // ------------------------------------------------------------
     568
     569
     570// -------------------------------------------------------------
     571void check_no_write(uint32 ** T, int i0, int i1, int j0, int j1)
     572// -------------------------------------------------------------
    459573{
    460574    int i, j;
     
    467581    }
    468582}
     583
     584
Note: See TracChangeset for help on using the changeset viewer.