//-------------------------------------------------------------------------------------------------- // // @ CopyRight Roberti & Parau Enterprises, Inc. 2021-2023 // // This work is licensed under the Creative Commons Attribution 4.0 International License. // To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ // or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. // //-------------------------------------------------------------------------------------------------- // // Driver to test and compare performance of the HEAPSORT macro // provided with the RISC-V module of DVASM // // This program sort a vector of long integers // // The following definition are used to control compilation // // #define SIZE vector_length // // It must always be defined. For example if // // #define SIZE 8 // // The vector to be sorted will contain 8 random number // // #define FUNCTION // // It must always be defined. Valid values are: // // dvasmsortlong // linuxsortlong // optsortlong // // #define REPEAT number_of_repeat // // It must always be defined. It is used to test performance // For example: // // #define REPEAT 1000 // // will repeat the sort of the same vector 1000 times // // #define PRINT // // When this definition is included the sorted vector is printed // to check for sort correctness // #include #include #include #include //----------------------- Compilation definitions ----------------- #define SIZE (1 << 18) #define FUNCTION dvasmsortlong #define REPEAT 10000 //#define PRINT //----------------------- End of compilation definitions ---------- void dvasmsortlong(void *base, size_t num); void sortlinux(void *base, size_t num, size_t size, long (*cmp_func)(const long *, const long *), void (*swap_func)(void *, void *, int size)); #define linuxsortlong(v, l) sortlinux(v, l, sizeof(long), &comp_func, NULL) long comp_func(const long *a, const long *b) { return *a - *b; } void optsortlong(long *base, size_t num); int main(int argc, char **argv) { // // Allocate vector // long *v= (long *) malloc(SIZE * sizeof(long)); // // Seed the random number generator // srandom(17); // // Generate random numbers for the vetor // long *w= v; for (int i= 0; i < SIZE; i++) { *w= random(); w++; } // // Sort the vector as amny times as specified in REPAT // for (int i= 0; i < REPEAT; i++) FUNCTION(v, SIZE); // Sort vector // // Generate print code if PRINT is defined // #ifdef PRINT for (int i= 0; i < SIZE; i++) printf("Heap entry is: %6d %ld\n", i, v[i]); #endif }