summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-15 02:30:14 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-15 02:30:14 +0000
commit5bded43a8b43a0da5abf953c37ffd6fcd77f4443 (patch)
treeeadd5d60b23c54fcf2a9f546743682a708bbd28e
parent332747f6df0cd2af6535d81ccde00ade374563fa (diff)
Clean IDEA struct. Replace with local static variables
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@49 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
-rw-r--r--cleanbench.c3
-rw-r--r--fourier.c18
-rw-r--r--idea.c45
-rw-r--r--nmglobal.h40
4 files changed, 34 insertions, 72 deletions
diff --git a/cleanbench.c b/cleanbench.c
index abb9994..50b2c43 100644
--- a/cleanbench.c
+++ b/cleanbench.c
@@ -81,7 +81,6 @@ for (i = 0; i < NUMTESTS; i++) {
** Initialize test data structures to default
** values.
*/
-global_ideastruct.arraysize=IDEAARRAYSIZE;
global_huffstruct.arraysize=HUFFARRAYSIZE;
puts("BYTEmark* Native Mode Benchmark ver. 2 (10/95)");
@@ -91,7 +90,7 @@ puts("\nTEST : Iterations/sec. : Old Index : New Index");
puts(" : : Pentium 90* : AMD K6/233*");
puts("--------------------:------------------:-------------:------------");
-for(i=FPEMULATION;i<NUMTESTS;i++)
+for(i=IDEA;i<NUMTESTS;i++)
{
if(tests_to_do[i])
{ printf("%s :",ftestnames[i]);
diff --git a/fourier.c b/fourier.c
index 81ec5b2..d45f784 100644
--- a/fourier.c
+++ b/fourier.c
@@ -44,19 +44,19 @@ DoFourier(void)
clock_t total_time = 0;
int iterations = 0;
static int is_adjusted = FALSE;
+ static int array_size = 100;
if (is_adjusted == FALSE) {
is_adjusted = TRUE;
- locfourierstruct->arraysize = 100L; /* Start at 100 elements */
while (1) {
- abase = realloc(abase, locfourierstruct->arraysize * sizeof(double));
+ abase = realloc(abase, array_size * sizeof(double));
if (!abase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
}
- bbase = realloc(bbase, locfourierstruct->arraysize * sizeof(double));
+ bbase = realloc(bbase, array_size * sizeof(double));
if (!bbase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
free(abase);
@@ -69,27 +69,27 @@ DoFourier(void)
** larger arrays and try again.
*/
- if (DoFPUTransIteration(abase,bbase, locfourierstruct->arraysize) > MINIMUM_TICKS) {
+ if (DoFPUTransIteration(abase,bbase, array_size) > MINIMUM_TICKS) {
break;
}
/*
** Make bigger arrays and try again.
*/
- locfourierstruct->arraysize += 50L;
+ array_size += 50;
}
} else {
/*
** Don't need self-adjustment. Just allocate the
** arrays, and go.
*/
- abase = malloc(locfourierstruct->arraysize * sizeof(double));
+ abase = malloc(array_size * sizeof(double));
if (!abase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
}
- bbase = malloc(locfourierstruct->arraysize * sizeof(double));
+ bbase = malloc(array_size * sizeof(double));
if (!bbase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
free(abase);
@@ -98,8 +98,8 @@ DoFourier(void)
}
do {
- total_time += DoFPUTransIteration(abase,bbase,locfourierstruct->arraysize);
- iterations += locfourierstruct->arraysize * 2 - 1;
+ total_time += DoFPUTransIteration(abase,bbase,array_size);
+ iterations += array_size * 2 - 1;
} while (total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC);
free(abase);
diff --git a/idea.c b/idea.c
index 2bc7f9b..bd8d539 100644
--- a/idea.c
+++ b/idea.c
@@ -20,30 +20,32 @@
**
*/
+/* Following constant defines the max number of loops the
+** system will attempt. Keeps things from going off into the
+** weeds. */
+/*#define LOOP_MAX 50000L*/
+#define LOOP_MAX 500000L
+
/*
-** DEFINES
+** Following constant sets the size of the arrays.
+** NOTE: For the IDEA algorithm to work properly, this
+** number MUST be some multiple of 8.
*/
+#define ARRAY_SIZE 4000
+
#define IDEAKEYSIZE 16
#define IDEABLOCKSIZE 8
#define ROUNDS 8
#define KEYLEN (6*ROUNDS+4)
-/*
-** MACROS
-*/
#define low16(x) ((x) & 0x0FFFF)
#define MUL(x,y) (x=mul(low16(x),y))
-
typedef uint16_t IDEAkey[KEYLEN];
-/*
-** PROTOTYPES
-*/
static clock_t DoIDEAIteration(unsigned char *plain1,
unsigned char *crypt1, unsigned char *plain2,
- unsigned long arraysize, unsigned long nloops,
- IDEAkey Z, IDEAkey DK);
+ unsigned long nloops, IDEAkey Z, IDEAkey DK);
static uint16_t mul(register uint16_t a, register uint16_t b);
static uint16_t inv(uint16_t x);
static void en_key_idea(uint16_t userkey[8], IDEAkey Z);
@@ -70,6 +72,7 @@ DoIDEA(void)
uint16_t userkey[8];
int i;
static int is_adjusted = FALSE;
+ static int loops = 100;
randnum(3);
@@ -96,20 +99,20 @@ DoIDEA(void)
** So, plain1 and plain2 should match.
** Also, fill up plain1 with sample text.
*/
- plain1 = malloc(locideastruct->arraysize);
+ plain1 = malloc(ARRAY_SIZE);
if (!plain1) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
}
- crypt1 = malloc(locideastruct->arraysize);
+ crypt1 = malloc(ARRAY_SIZE);
if (!crypt1) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
free(plain1);
exit(1);
}
- plain2 = malloc(locideastruct->arraysize);
+ plain2 = malloc(ARRAY_SIZE);
if (!plain2) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
free(plain1);
@@ -120,7 +123,7 @@ DoIDEA(void)
** Note that we build the "plaintext" by simply loading
** the array up with random numbers.
*/
- for (i = 0;i < locideastruct->arraysize; i++) {
+ for (i = 0;i < ARRAY_SIZE; i++) {
plain1[i] = (unsigned char)(abs_randwc(255) & 0xFF);
}
@@ -134,8 +137,8 @@ DoIDEA(void)
** # of loops and increasing the loop count until we
** get a number of loops that we can use.
*/
- for (locideastruct->loops = 100; locideastruct->loops < MAXIDEALOOPS; locideastruct->loops += 10) {
- if (DoIDEAIteration(plain1, crypt1, plain2, locideastruct->arraysize, locideastruct->loops, Z, DK) > MINIMUM_TICKS) {
+ for (; loops < LOOP_MAX; loops += 10) {
+ if (DoIDEAIteration(plain1, crypt1, plain2, loops, Z, DK) > MINIMUM_TICKS) {
break;
}
}
@@ -146,8 +149,8 @@ DoIDEA(void)
*/
do {
- total_time += DoIDEAIteration(plain1, crypt1, plain2, locideastruct->arraysize, locideastruct->loops, Z, DK);
- iterations += locideastruct->loops;
+ total_time += DoIDEAIteration(plain1, crypt1, plain2, loops, Z, DK);
+ iterations += loops;
} while (total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC);
free(plain1);
@@ -165,7 +168,7 @@ DoIDEA(void)
** decryption.
*/
static clock_t
-DoIDEAIteration(unsigned char *plain1, unsigned char *crypt1, unsigned char *plain2, unsigned long arraysize, unsigned long nloops, IDEAkey Z, IDEAkey DK)
+DoIDEAIteration(unsigned char *plain1, unsigned char *crypt1, unsigned char *plain2, unsigned long nloops, IDEAkey Z, IDEAkey DK)
{
clock_t start, stop;
register unsigned long i;
@@ -174,12 +177,12 @@ DoIDEAIteration(unsigned char *plain1, unsigned char *crypt1, unsigned char *pla
start = clock();
for (i = 0; i < nloops; i++) {
- for (j = 0; j < arraysize; j += sizeof(uint16_t) * 4) {
+ for (j = 0; j < ARRAY_SIZE; j += sizeof(uint16_t) * 4) {
cipher_idea((uint16_t *)(plain1 + j), (uint16_t *)(crypt1 + j), Z); /* Encrypt */
}
}
- for (j = 0; j < arraysize; j += sizeof(uint16_t) * 4) {
+ for (j = 0; j < ARRAY_SIZE; j += sizeof(uint16_t) * 4) {
cipher_idea((uint16_t *)(crypt1 + j), (uint16_t *)(plain2 + j), DK); /* Decrypt */
}
diff --git a/nmglobal.h b/nmglobal.h
index 5e8f70a..cd49cad 100644
--- a/nmglobal.h
+++ b/nmglobal.h
@@ -50,56 +50,16 @@ typedef struct {
double results; /* Results */
} EmFloatStruct;
-/*************************
-** FOURIER COEFFICIENTS **
-*************************/
-
-/*
-** TYPEDEFS
-*/
typedef struct {
double results; /* Results */
- unsigned long arraysize; /* Size of coeff. arrays */
} FourierStruct;
-/*************************
-** ASSIGNMENT ALGORITHM **
-*************************/
-
-/*
-** TYPEDEFS
-*/
typedef struct {
double results; /* Results */
} AssignStruct;
-/********************
-** IDEA ENCRYPTION **
-********************/
-
-/*
-** DEFINES
-*/
-/* Following constant defines the max number of loops the
-** system will attempt. Keeps things from going off into the
-** weeds. */
-/*#define MAXIDEALOOPS 50000L*/
-#define MAXIDEALOOPS 500000L
-
-/*
-** Following constant sets the size of the arrays.
-** NOTE: For the IDEA algorithm to work properly, this
-** number MUST be some multiple of 8.
-*/
-#define IDEAARRAYSIZE 4000L
-
-/*
-** TYPEDEFS
-*/
typedef struct {
double results; /* Results */
- unsigned long arraysize; /* Size of array */
- unsigned long loops; /* # of times to convert */
} IDEAStruct;