Beispiel #1
0
 public int loops;                               /* Loops per iterations */
 public override void ShowStats()
 {
     ByteMark.OutputString(
         string.Format("  Number of loops: {0}", loops));
     ByteMark.OutputString(
         string.Format("  Array size: {0}", arraysize));
 }
    /*************************
    ** LoadNumArrayWithRand **
    **************************
    ** Load up an array with random longs.
    */
    private static void LoadNumArrayWithRand(int[][] array, /* Pointer to arrays */
                                             int arraysize,
                                             int numarrays) /* # of elements in array */
    {
        int i;                                              /* Used for index */

        /*
        ** Initialize the random number generator
        */
        ByteMark.randnum(13);

        /*
        ** Load up first array with randoms
        */
        for (i = 0; i < arraysize; i++)
        {
            array[0][i] = ByteMark.randnum(0);
        }

        /*
        ** Now, if there's more than one array to load, copy the
        ** first into each of the others.
        */
        for (i = 1; i < numarrays; i++)
        {
            // the old code didn't do a memcpy, so I'm not doing
            // an Array.Copy()
            for (int j = 0; j < arraysize; j++)
            {
                array[i][j] = array[0][j];
            }
        }

        return;
    }
Beispiel #3
0
    /**********************
    ** create_text_block **
    ***********************
    ** Build a block of text randomly loaded with words.  The words
    ** come from the wordcatalog (which must be loaded before you
    ** call this).
    ** *tb points to the memory where the text is to be built.
    ** tblen is the # of bytes to put into the text block
    ** maxlinlen is the maximum length of any line (line end indicated
    **  by a carriage return).
    */
    private static void create_text_block(byte[] tb,
                                          int tblen,
                                          short maxlinlen)
    {
        int bytessofar;       /* # of bytes so far */
        int linelen;          /* Line length */

        bytessofar = 0;
        do
        {
            /*
            ** Pick a random length for a line and fill the line.
            ** Make sure the line can fit (haven't exceeded tablen) and also
            ** make sure you leave room to append a carriage return.
            */
            linelen = ByteMark.abs_randwc(maxlinlen - 6) + 6;
            if ((linelen + bytessofar) > tblen)
            {
                linelen = tblen - bytessofar;
            }

            if (linelen > 1)
            {
                create_text_line(tb, linelen, bytessofar);
            }
            tb[linelen] = (byte)'\n';          /* Add the carriage return */

            bytessofar += linelen;
        } while (bytessofar < tblen);
    }
Beispiel #4
0
    public static int Main(string[] args)
    {
        ByteMark app    = new ByteMark();
        int      result = app.ExecuteCore(args);

        return(result);
    }
Beispiel #5
0
    /********************
    ** randomize_wts() **
    *********************
    ** Intialize the weights in the middle and output layers to
    ** random values between -0.25..+0.25
    ** Function rand() returns a value between 0 and 32767.
    **
    ** NOTE: Had to make alterations to how the random numbers were
    ** created.  -- RG.
    **/
    public static void randomize_wts()
    {
        int    neurode, i;
        double value;

        /*
        ** Following not used int benchmark version -- RG
        **
        **        printf("\n Please enter a random number seed (1..32767):  ");
        **        scanf("%d", &i);
        **        srand(i);
        */

        for (neurode = 0; neurode < MID_SIZE; neurode++)
        {
            for (i = 0; i < IN_SIZE; i++)
            {
                value = (double)ByteMark.abs_randwc(100000);
                value = value / (double)100000.0 - (double)0.5;
                mid_wts[neurode, i] = value / 2;
            }
        }
        for (neurode = 0; neurode < OUT_SIZE; neurode++)
        {
            for (i = 0; i < MID_SIZE; i++)
            {
                value = (double)ByteMark.abs_randwc(100000);
                value = value / (double)10000.0 - (double)0.5;
                out_wts[neurode, i] = value / 2;
            }
        }
        return;
    }
Beispiel #6
0
    /**********************
    ** DoAssignIteration **
    ***********************
    ** This routine executes one iteration of the assignment test.
    ** It returns the number of ticks elapsed in the iteration.
    */
    private static long DoAssignIteration(int[][,] arraybase, int numarrays)
    {
        long elapsed;                   /* Elapsed ticks */
        int  i;

        /*
        ** Load up the arrays with a random table.
        */
        LoadAssignArrayWithRand(arraybase, numarrays);

        /*
        ** Start the stopwatch
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Execute assignment algorithms
        */
        for (i = 0; i < numarrays; i++)
        {
            Assignment(arraybase[i]);
        }

        /*
        ** Get elapsed time
        */
        return(ByteMark.StopStopwatch(elapsed));
    }
    /*************************
    ** LoadNumArrayWithRand **
    **************************
    ** Load up an array with random longs.
    */
    private static void LoadNumArrayWithRand(int[,] array,  /* Pointer to arrays */
                                             int arraysize,
                                             int numarrays) /* # of elements in array */
    {
        int i;                                              /* Used for index */

        /*
        ** Initialize the random number generator
        */
        ByteMark.randnum(13);

        /*
        ** Load up first array with randoms
        */
        for (i = 0; i < arraysize; i++)
        {
            array[0, i] = ByteMark.randnum(0);
        }

        /*
        ** Now, if there's more than one array to load, copy the
        ** first into each of the others.
        */
        while (--numarrays > 0)
        {
            for (int j = 0; j < arraysize; j++, i++)
            {
                array[numarrays, j] = array[0, j];
            }
        }

        return;
    }
Beispiel #8
0
 public int bitfieldarraysize = global.BITFARRAYSIZE; /* Bit field array size */
 public override void ShowStats()
 {
     ByteMark.OutputString(
         string.Format("  Operations array size: {0}", bitoparraysize));
     ByteMark.OutputString(
         string.Format("  Bitfield array size: {0}", bitfieldarraysize));
 }
Beispiel #9
0
    long DoEmFloatIteration(InternalFPF[] abase,
                            InternalFPF[] bbase,
                            InternalFPF[] cbase,
                            int arraysize, int loops)
    {
        long elapsed;          /* For the stopwatch */

        byte[] jtable = new byte[] { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3 };
        int    i;

        /*
        ** Begin timing
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Each pass through the array performs operations in
        ** the followingratios:
        **   4 adds, 4 subtracts, 5 multiplies, 3 divides
        ** (adds and subtracts being nearly the same operation)
        */
        while (loops-- > 0)
        {
            for (i = 0; i < arraysize; i++)
            {
                switch (jtable[i % 16])
                {
                case 0:     /* Add */
                    AddSubInternalFPF(0, abase[i],
                                      bbase[i],
                                      cbase[i]);
                    break;

                case 1:     /* Subtract */
                    AddSubInternalFPF(1, abase[i],
                                      bbase[i],
                                      cbase[i]);
                    break;

                case 2:     /* Multiply */
                    MultiplyInternalFPF(abase[i],
                                        bbase[i],
                                        cbase[i]);
                    break;

                case 3:     /* Divide */
                    DivideInternalFPF(abase[i],
                                      bbase[i],
                                      cbase[i]);
                    break;
                }
            }
        }

        return(ByteMark.StopStopwatch(elapsed));
    }
Beispiel #10
0
    /*
    ** Perform the transcendental/trigonometric portion of the
    ** benchmark.  This benchmark calculates the first n
    ** fourier coefficients of the function (x+1)^x defined
    ** on the interval 0,2.
    */
    public override double Run()
    {
        double[] abase;         /* Base of A[] coefficients array */
        double[] bbase;         /* Base of B[] coefficients array */
        long     accumtime;     /* Accumulated time in ticks */
        double   iterations;    /* # of iterations */

        /*
        ** See if we need to do self-adjustment code.
        */
        if (this.adjust == 0)
        {
            this.arraysize = 100; /* Start at 100 elements */
            while (true)
            {
                abase = new double[this.arraysize];
                bbase = new double[this.arraysize];

                /*
                ** Do an iteration of the tests.  If the elapsed time is
                ** less than or equal to the permitted minimum, re-allocate
                ** larger arrays and try again.
                */
                if (DoFPUTransIteration(abase, bbase, this.arraysize) > global.min_ticks)
                {
                    break;
                }
                this.arraysize += 50;
            }
        }
        else
        {
            /*
            ** Don't need self-adjustment.  Just allocate the
            ** arrays, and go.
            */
            abase = new double[this.arraysize];
            bbase = new double[this.arraysize];
        }

        accumtime  = 0L;
        iterations = 0.0;
        do
        {
            accumtime  += DoFPUTransIteration(abase, bbase, this.arraysize);
            iterations += (double)this.arraysize * (double)2.0 - (double)1.0;
        } while (ByteMark.TicksToSecs(accumtime) < this.request_secs);

        if (this.adjust == 0)
        {
            this.adjust = 1;
        }

        return(iterations / (double)ByteMark.TicksToFracSecs(accumtime));
    }
Beispiel #11
0
    /********************
    ** LoadStringArray **
    *********************
    ** Initialize the string array with random strings of
    ** varying sizes.
    ** Returns the pointer to the offset pointer array.
    ** Note that since we're creating a number of arrays, this
    ** routine builds one array, then copies it into the others.
    */
    private static void LoadStringArray(string[][] array,          /* String array */
                                        int arraysize,             /* Size of array */
                                        int numarrays)             /* # of arrays */
    {
        /*
        ** Initialize random number generator.
        */
        ByteMark.randnum(13);

        /*
        ** Load up the first array with randoms
        */

        int i;

        for (i = 0; i < arraysize; i++)
        {
            int length;

            length      = 4 + ByteMark.abs_randwc(76);
            array[0][i] = "";

            /*
            ** Fill up the string with random bytes.
            */
            StringBuilder builder = new StringBuilder(length);

            int add;
            for (add = 0; add < length; add++)
            {
                char myChar = (char)(ByteMark.abs_randwc(96) + 32);
                builder.Append(myChar);
            }
            array[0][i] = builder.ToString();
        }

        /*
        ** We now have initialized a single full array.  If there
        ** is more than one array, copy the original into the
        ** others.
        */
        int k;

        for (k = 1; k < numarrays; k++)
        {
            for (i = 0; i < arraysize; i++)
            {
                array[k][i] = array[0][i];
            }
        }
    }
    /***************
	** LoadAssign **
	****************
	** The array given by arraybase is loaded with positive random
	** numbers.  Elements in the array are capped at 5,000,000.
	*/
    private static void LoadAssign(int[,] arraybase)
    {
        short i, j;

        /*
		** Reset random number generator so things repeat.
		*/
        ByteMark.randnum(13);

        for (i = 0; i < global.ASSIGNROWS; i++)
            for (j = 0; j < global.ASSIGNROWS; j++)
                arraybase[i, j] = ByteMark.abs_randwc(5000000);
        return;
    }
Beispiel #13
0
    /*********************
    ** create_text_line **
    **********************
    ** Create a random line of text, stored at *dt.  The line may be
    ** no more than nchars long.
    */
    private static void create_text_line(byte[] dt, int nchars, int lower)
    {
        int    charssofar;    /* # of characters so far */
        int    tomove;        /* # of characters to move */
        string myword;        /* Local buffer for words */

        int index = 0;

        charssofar = 0;

        do
        {
            /*
            ** Grab a random word from the wordcatalog
            */
            myword = wordcatarray[ByteMark.abs_randwc(Huffman.WORDCATSIZE)];

            /*
            ** Append a blank.
            */
            myword += " ";
            tomove  = myword.Length;

            /*
            ** See how long it is.  If its length+charssofar > nchars, we have
            ** to trim it.
            */
            if ((tomove + charssofar) > nchars)
            {
                tomove = nchars - charssofar;
            }

            /*
            ** Attach the word to the current line.  Increment counter.
            */
            for (int i = 0; i < tomove; i++)
            {
                dt[lower + index++] = (byte)myword[i];
            }
            charssofar += tomove;

            /*
            ** If we're done, bail out.  Otherwise, go get another word.
            */
        } while (charssofar < nchars);

        return;
    }
Beispiel #14
0
    /********************
    ** DoIDEAIteration **
    *********************
    ** Execute a single iteration of the IDEA encryption algorithm.
    ** Actually, a single iteration is one encryption and one
    ** decryption.
    */
    private static long DoIDEAIteration(byte[] plain1,
                                        byte[] crypt1,
                                        byte[] plain2,
                                        int arraysize,
                                        int nloops,
                                        char[] Z,
                                        char[] DK)
    {
        int  i;
        int  j;
        long elapsed;

        /*
        ** Start the stopwatch.
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Do everything for nloops.
        */

        for (i = 0; i < nloops; i++)
        {
            for (j = 0; j < arraysize; j += 8)
            {
                cipher_idea(plain1, crypt1, j, Z);  /* Encrypt */
            }
            for (j = 0; j < arraysize; j += 8)
            {
                cipher_idea(crypt1, plain2, j, DK);  /* Decrypt */
            }
        }

        // Validate output
        for (j = 0; j < arraysize; j++)
        {
            if (plain1[j] != plain2[j])
            {
                string error = String.Format("IDEA: error at index {0} ({1} <> {2})!", j, (int)plain1[j], (int)plain2[j]);
                throw new Exception(error);
            }
        }

        /*
        ** Get elapsed time.
        */
        return(ByteMark.StopStopwatch(elapsed));
    }
    /***********************
    ** DoNumSortIteration **
    ************************
    ** This routine executes one iteration of the numeric
    ** sort benchmark.  It returns the number of ticks
    ** elapsed for the iteration.
    */

    // JTR: The last 2 parms are no longer needed as they
    // can be inferred from the arraybase. <shrug>
    private static int DoNumSortIteration(int[,] arraybase, int arraysize, int numarrays)
    {
        long elapsed;          /* Elapsed ticks */
        int  i;

        /*
        ** Load up the array with random numbers
        */
        LoadNumArrayWithRand(arraybase, arraysize, numarrays);

        /*
        ** Start the stopwatch
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Execute a heap of heapsorts
        */
        for (i = 0; i < numarrays; i++)
        {
            //          NumHeapSort(arraybase+i*arraysize,0L,arraysize-1L);
            NumHeapSort(arraybase, i, arraysize - 1);
        }

        /*
        ** Get elapsed time
        */
        elapsed = ByteMark.StopStopwatch(elapsed);
#if DEBUG
        {
            for (i = 0; i < arraysize - 1; i++)
            {   /*
                ** Compare to check for proper
                ** sort.
                */
                if (arraybase[0, i + 1] < arraybase[0, i])
                {
                    Console.Write("size: {0}, count: {1}, total: {2}\n", arraysize, numarrays, arraybase.Length);
                    Console.Write("Sort Error at index {0}\n", i);
                    break;
                }
            }
        }
#endif

        return((int)elapsed);
    }
Beispiel #16
0
    /**************************
    ** DoStringSortIteration **
    ***************************
    ** This routine executes one iteration of the string
    ** sort benchmark.  It returns the number of ticks
    ** Note that this routine also builds the offset pointer
    ** array.
    */

    private static int DoStringSortIteration(string[][] arraybase, int numarrays, int arraysize)
    {
        long elapsed;            /* Elapsed ticks */
        int  i;

        /*
        ** Load up the array(s) with random numbers
        */
        LoadStringArray(arraybase, arraysize, numarrays);

        /*
        ** Start the stopwatch
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Execute heapsorts
        */
        for (i = 0; i < numarrays; i++)
        {
            // StrHeapSort(tempobase,tempsbase,nstrings,0L,nstrings-1);
            StrHeapSort(arraybase[i], 0, arraysize - 1);
        }

        /*
        ** Record elapsed time
        */
        elapsed = ByteMark.StopStopwatch(elapsed);

#if DEBUG
        for (i = 0; i < arraysize - 1; i++)
        {
            /*
            ** Compare strings to check for proper
            ** sort.
            */
            if (StringOrdinalComparer.Compare(arraybase[0][i + 1], arraybase[0][i]) < 0)
            {
                Console.Write("Error in StringSort!  arraybase[0][{0}]='{1}', arraybase[0][{2}]='{3}\n", i, arraybase[0][i], i + 1, arraybase[0][i + 1]);
                break;
            }
        }
#endif

        return((int)elapsed);
    }
Beispiel #17
0
    private static void build_problem(double[][] a, int n, double[] b)
    {
        int    i, j, k, k1;
        double rcon;

        ByteMark.randnum(13);

        for (i = 0; i < n; i++)
        {
            b[i] = (double)(ByteMark.abs_randwc(100) + 1);
            for (j = 0; j < n; j++)
            {
                if (i == j)
                {
                    a[i][j] = (double)(ByteMark.abs_randwc(1000) + 1);
                }
                else
                {
                    a[i][j] = (double)0.0;
                }
            }
        }

        for (i = 0; i < 8 * n; i++)
        {
            k  = ByteMark.abs_randwc(n);
            k1 = ByteMark.abs_randwc(n);
            if (k != k1)
            {
                if (k < k1)
                {
                    rcon = 1.0;
                }
                else
                {
                    rcon = -1.0;
                }
                for (j = 0; j < n; j++)
                {
                    a[k][j] += a[k1][j] * rcon;
                }
                b[k] += b[k1] * rcon;
            }
        }
    }
Beispiel #18
0
    void SetupCPUEmFloatArrays(InternalFPF[] abase,
                               InternalFPF[] bbase,
                               InternalFPF[] cbase,
                               int arraysize)
    {
        int         i;
        InternalFPF locFPF1, locFPF2;

        locFPF1 = new InternalFPF();
        locFPF2 = new InternalFPF();

        for (i = 0; i < arraysize; i++)
        {
            LongToInternalFPF(ByteMark.randwc(50000), locFPF1);
            LongToInternalFPF(ByteMark.randwc(50000) + 1, locFPF2);
            DivideInternalFPF(locFPF1, locFPF2, abase[i]);
            LongToInternalFPF(ByteMark.randwc(50000) + 1, locFPF2);
            DivideInternalFPF(locFPF1, locFPF2, bbase[i]);
        }
        return;
    }
Beispiel #19
0
    /*
    ** Perform an iteration of the FPU Transcendental/trigonometric
    ** benchmark.  Here, an iteration consists of calculating the
    ** first n fourier coefficients of the function (x+1)^x on
    ** the interval 0,2.  n is given by arraysize.
    ** NOTE: The # of integration steps is fixed at
    ** 200.
    */
    private static long DoFPUTransIteration(double[] abase, double[] bbase, int arraysize)
    {
        double omega;   /* Fundamental frequency */
        int    i;       /* Index */
        long   elapsed; /* Elapsed time */

        elapsed = ByteMark.StartStopwatch();

        /*
        ** Calculate the fourier series.  Begin by
        ** calculating A[0].
        */

        abase[0] = TrapezoidIntegrate(0.0, 2.0, 200, 0.0, 0) / 2.0;

        /*
        ** Calculate the fundamental frequency.
        ** ( 2 * pi ) / period...and since the period
        ** is 2, omega is simply pi.
        */
        omega = 3.1415926535897921;

        for (i = 1; i < arraysize; i++)
        {
            /*
            ** Calculate A[i] terms.  Note, once again, that we
            ** can ignore the 2/period term outside the integral
            ** since the period is 2 and the term cancels itself
            ** out.
            */
            abase[i] = TrapezoidIntegrate(0.0, 2.0, 200, omega * (double)i, 1);

            bbase[i] = TrapezoidIntegrate(0.0, 2.0, 200, omega * (double)i, 2);
        }

        /*
        ** All done, stop the stopwatch
        */
        return(ByteMark.StopStopwatch(elapsed));
    }
    /********************
    ** DoNNetIteration **
    *********************
    ** Do a single iteration of the neural net benchmark.
    ** By iteration, we mean a "learning" pass.
    */
    public static long DoNNetIteration(long nloops)
    {
        long elapsed;          /* Elapsed time */
        int  patt;

        /*
        ** Run nloops learning cycles.  Notice that, counted with
        ** the learning cycle is the weight randomization and
        ** zeroing of changes.  This should reduce clock jitter,
        ** since we don't have to stop and start the clock for
        ** each iteration.
        */
        elapsed = ByteMark.StartStopwatch();
        while (nloops-- != 0)
        {
            randomize_wts();
            zero_changes();
            iteration_count = 1;
            learned         = F;
            numpasses       = 0;
            while (learned == F)
            {
                for (patt = 0; patt < numpats; patt++)
                {
                    worst_error = 0.0;      /* reset this every pass through data */
                    move_wt_changes();      /* move last pass's wt changes to momentum array */
                    do_forward_pass(patt);
                    do_back_pass(patt);
                    iteration_count++;
                }
                numpasses++;
                learned = check_out_error();
            }
        }

        return(ByteMark.StopStopwatch(elapsed));
    }
Beispiel #21
0
    private static long DoLUIteration(double[][] a, double[] b, double[][][] abase, double[][] bbase, int numarrays)
    {
        double[][] locabase;
        double[]   locbbase;
        long       elapsed;
        int        k, j, i;

        for (j = 0; j < numarrays; j++)
        {
            locabase = abase[j];
            locbbase = bbase[j];
            for (i = 0; i < global.LUARRAYROWS; i++)
            {
                for (k = 0; k < global.LUARRAYCOLS; k++)
                {
                    locabase[i][k] = a[i][k];
                }
            }
            for (i = 0; i < global.LUARRAYROWS; i++)
            {
                locbbase[i] = b[i];
            }
        }

        elapsed = ByteMark.StartStopwatch();

        for (i = 0; i < numarrays; i++)
        {
            locabase = abase[i];
            locbbase = bbase[i];

            lusolve(locabase, global.LUARRAYROWS, locbbase);
        }

        return(ByteMark.StopStopwatch(elapsed));
    }
Beispiel #22
0
    /*
    ** emfloat.c
    ** Source for emulated floating-point routines.
    ** BYTEmark (tm)
    ** BYTE's Native Mode Benchmarks
    ** Rick Grehan, BYTE Magazine.
    **
    ** Created:
    ** Last update: 3/95
    **
    ** DISCLAIMER
    ** The source, executable, and documentation files that comprise
    ** the BYTEmark benchmarks are made available on an "as is" basis.
    ** This means that we at BYTE Magazine have made every reasonable
    ** effort to verify that the there are no errors in the source and
    ** executable code.  We cannot, however, guarantee that the programs
    ** are error-free.  Consequently, McGraw-HIll and BYTE Magazine make
    ** no claims in regard to the fitness of the source code, executable
    ** code, and documentation of the BYTEmark.
    **  Furthermore, BYTE Magazine, McGraw-Hill, and all employees
    ** of McGraw-Hill cannot be held responsible for any damages resulting
    ** from the use of this code or the results obtained from using
    ** this code.
    */

    /*
    ** Floating-point emulator.
    ** These routines are only "sort of" IEEE-compliant.  All work is
    ** done using an internal representation.  Also, the routines do
    ** not check for many of the exceptions that might occur.
    ** Still, the external formats produced are IEEE-compatible,
    ** with the restriction that they presume a low-endian machine
    ** (though the endianism will not effect the performance).
    **
    ** Some code here was based on work done by Steve Snelgrove of
    ** Orem, UT.  Other code comes from routines presented in
    ** the long-ago book: "Microprocessor Programming for
    ** Computer Hobbyists" by Neill Graham.
    */

    /*****************************
    ** FLOATING-POINT EMULATION **
    *****************************/

    /**************
    ** DoEmFloat **
    ***************
    ** Perform the floating-point emulation routines portion of the
    ** CPU benchmark.  Returns the operations per second.
    */
    public override double Run()
    {
        InternalFPF[] abase;          /* Base of A array */
        InternalFPF[] bbase;          /* Base of B array */
        InternalFPF[] cbase;          /* Base of C array */
        long          accumtime;      /* Accumulated time in ticks */
        double        iterations;     /* # of iterations */
        long          tickcount;      /* # of ticks */
        int           loops;          /* # of loops */

        /*
        ** Test the emulation routines.
        */

        abase = new InternalFPF[this.arraysize];
        bbase = new InternalFPF[this.arraysize];
        cbase = new InternalFPF[this.arraysize];

        for (int i = 0; i < this.arraysize; i++)
        {
            abase[i] = new InternalFPF();
            bbase[i] = new InternalFPF();
            cbase[i] = new InternalFPF();
        }

        /*
         * for (int i = 0; i < this.arraysize; i++)
         * {
         *  abase[i].type = IFPF.IFPF_IS_ZERO;
         *  abase[i].sign = (byte)0;
         *  abase[i].exp = (short)0;
         *  abase[i].mantissa = new char[INTERNAL_FPF_PRECISION];
         *
         *  bbase[i].type = IFPF.IFPF_IS_ZERO;
         *  bbase[i].sign = (byte)0;
         *  bbase[i].exp = (short)0;
         *  bbase[i].mantissa = new char[INTERNAL_FPF_PRECISION];
         *
         *  cbase[i].type = IFPF.IFPF_IS_ZERO;
         *  cbase[i].sign = (byte)0;
         *  cbase[i].exp = (short)0;
         *  cbase[i].mantissa = new char[INTERNAL_FPF_PRECISION];
         * }
         */

        /*
        ** Set up the arrays
        */
        SetupCPUEmFloatArrays(abase, bbase, cbase, this.arraysize);

        /*
        ** See if we need to do self-adjusting code.
        */
        if (this.adjust == 0)
        {
            this.loops = 0;

            /*
            ** Do an iteration of the tests.  If the elapsed time is
            ** less than minimum, increase the loop count and try
            ** again.
            */
            for (loops = 1; loops < global.CPUEMFLOATLOOPMAX; loops += loops)
            {
                tickcount = DoEmFloatIteration(abase, bbase, cbase,
                                               this.arraysize,
                                               loops);
                if (tickcount > global.min_ticks)
                {
                    this.loops = loops;
                    break;
                }
            }
        }

        /*
        ** Verify that selft adjustment code worked.
        */
        if (this.loops == 0)
        {
            throw new Exception("CPU:EMFPU -- CMPUEMFLOATLOOPMAX limit hit\n");
        }

        /*
        ** All's well if we get here.  Repeatedly perform floating
        ** tests until the accumulated time is greater than the
        ** # of seconds requested.
        ** Each iteration performs arraysize * 3 operations.
        */
        accumtime  = 0L;
        iterations = (double)0.0;
        do
        {
            accumtime += DoEmFloatIteration(abase, bbase, cbase,
                                            this.arraysize,
                                            this.loops);
            iterations += (double)1.0;
        } while (ByteMark.TicksToSecs(accumtime) < this.request_secs);

        /*
        ** Clean up, calculate results, and go home.
        ** Also, indicate that adjustment is done.
        */

        if (this.adjust == 0)
        {
            this.adjust = 1;
        }
        double emflops = (iterations * (double)this.loops) /
                         (double)ByteMark.TicksToFracSecs(accumtime);

        return(emflops);
    }
Beispiel #23
0
 public static int Main(string[] args)
 {
     ByteMark app = new ByteMark();
     int result = app.ExecuteCore(args);
     return result;
 }
Beispiel #24
0
    public override double Run()
    {
        string[][] arraybase;   /* Base pointers of array */
        long       accumtime;   /* Accumulated time */
        double     iterations;  /* Iteration counter */

        /*
        ** See if we need to do self adjustment code.
        */
        if (this.adjust == 0)
        {
            /*
            ** Self-adjustment code.  The system begins by sorting 1
            ** array.  If it does that in no time, then two arrays
            ** are built and sorted.  This process continues until
            ** enough arrays are built to handle the tolerance.
            */
            this.numarrays = 1;
            while (true)
            {
                /*
                ** Allocate space for arrays
                */
                arraybase = new string[this.numarrays][];
                for (int i = 0; i < this.numarrays; i++)
                {
                    arraybase[i] = new string[this.arraysize];
                }

                /*
                ** Do an iteration of the string sort.  If the
                ** elapsed time is less than or equal to the permitted
                ** minimum, then allocate for more arrays and
                ** try again.
                */
                if (DoStringSortIteration(arraybase,
                                          this.numarrays,
                                          this.arraysize) > global.min_ticks)
                {
                    break;          /* We're ok...exit */
                }
                if (this.numarrays++ > global.NUMSTRARRAYS)
                {
                    throw new Exception("CPU:SSORT -- NUMSTRARRAYS hit.");
                }
            }
        }
        else
        {
            /*
            ** Allocate space for arrays
            */
            arraybase = new string[this.numarrays][];
            for (int i = 0; i < this.numarrays; i++)
            {
                arraybase[i] = new string[this.arraysize];
            }
        }

        /*
        ** All's well if we get here.  Repeatedly perform sorts until the
        ** accumulated elapsed time is greater than # of seconds requested.
        */
        accumtime  = 0L;
        iterations = (double)0.0;

        do
        {
            accumtime += DoStringSortIteration(arraybase,
                                               this.numarrays,
                                               this.arraysize);
            iterations += (double)this.numarrays;
        } while (ByteMark.TicksToSecs(accumtime) < this.request_secs);

        if (this.adjust == 0)
        {
            this.adjust = 1;
        }

        /*
        ** Clean up, calculate results, and go home.
        ** Set flag to show we don't need to rerun adjustment code.
        */

        return(iterations * (double)this.numarrays / ByteMark.TicksToFracSecs(accumtime));
    }
Beispiel #25
0
    /**************
    ** DoHuffman **
    ***************
    ** Execute a huffman compression on a block of plaintext.
    ** Note that (as with IDEA encryption) an iteration of the
    ** Huffman test includes a compression AND a decompression.
    ** Also, the compression cycle includes building the
    ** Huffman tree.
    */
    public override double Run()
    {
        huff_node[] hufftree;
        long        accumtime;
        double      iterations;

        byte[] comparray;
        byte[] decomparray;
        byte[] plaintext;

        InitWords();

        /*
        ** Allocate memory for the plaintext and the compressed text.
        ** We'll be really pessimistic here, and allocate equal amounts
        ** for both (though we know...well, we PRESUME) the compressed
        ** stuff will take less than the plain stuff.
        ** Also note that we'll build a 3rd buffer to decompress
        ** into, and we preallocate space for the huffman tree.
        ** (We presume that the Huffman tree will grow no larger
        ** than 512 bytes.  This is actually a super-conservative
        ** estimate...but, who cares?)
        */
        plaintext   = new byte[this.arraysize];
        comparray   = new byte[this.arraysize];
        decomparray = new byte[this.arraysize];

        hufftree = new huff_node[512];

        /*
        ** Build the plaintext buffer.  Since we want this to
        ** actually be able to compress, we'll use the
        ** wordcatalog to build the plaintext stuff.
        */
        create_text_block(plaintext, this.arraysize - 1, 500);
        //		for (int i = 0; i < this.arraysize-1; i++) {
        //			Console.Write((char)plaintext[i]);
        //		}
        plaintext[this.arraysize - 1] = (byte)'\0';
        // plaintextlen=this.arraysize;

        /*
        ** See if we need to perform self adjustment loop.
        */
        if (this.adjust == 0)
        {
            /*
            ** Do self-adjustment.  This involves initializing the
            ** # of loops and increasing the loop count until we
            ** get a number of loops that we can use.
            */

            for (this.loops = 100;
                 this.loops < global.MAXHUFFLOOPS;
                 this.loops += 10)
            {
                if (DoHuffIteration(plaintext,
                                    comparray,
                                    decomparray,
                                    this.arraysize,
                                    this.loops,
                                    hufftree) > global.min_ticks)
                {
                    break;
                }
            }
        }

        /*
        ** All's well if we get here.  Do the test.
        */
        accumtime  = 0L;
        iterations = (double)0.0;

        do
        {
            accumtime += DoHuffIteration(plaintext,
                                         comparray,
                                         decomparray,
                                         this.arraysize,
                                         this.loops,
                                         hufftree);
            iterations += (double)this.loops;
        } while (ByteMark.TicksToSecs(accumtime) < this.request_secs);

        /*
        ** Clean up, calculate results, and go home.  Be sure to
        ** show that we don't have to rerun adjustment code.
        */
        //this.iterspersec=iterations / TicksToFracSecs(accumtime);

        if (this.adjust == 0)
        {
            this.adjust = 1;
        }

        return(iterations / ByteMark.TicksToFracSecs(accumtime));
    }
Beispiel #26
0
    public override double Run()
    {
        int i;

        char[] Z       = new char[global.KEYLEN];
        char[] DK      = new char[global.KEYLEN];
        char[] userkey = new char[8];
        long   accumtime;
        double iterations;

        byte[] plain1;               /* First plaintext buffer */
        byte[] crypt1;               /* Encryption buffer */
        byte[] plain2;               /* Second plaintext buffer */

        /*
        ** Re-init random-number generator.
        */
        ByteMark.randnum(3);

        /*
        ** Build an encryption/decryption key
        */
        for (i = 0; i < 8; i++)
        {
            userkey[i] = (char)(ByteMark.abs_randwc(60000) & 0xFFFF);
        }
        for (i = 0; i < global.KEYLEN; i++)
        {
            Z[i] = (char)0;
        }

        /*
        ** Compute encryption/decryption subkeys
        */
        en_key_idea(userkey, Z);
        de_key_idea(Z, DK);

        /*
        ** Allocate memory for buffers.  We'll make 3, called plain1,
        ** crypt1, and plain2.  It works like this:
        **   plain1 >>encrypt>> crypt1 >>decrypt>> plain2.
        ** So, plain1 and plain2 should match.
        ** Also, fill up plain1 with sample text.
        */
        plain1 = new byte[this.arraysize];
        crypt1 = new byte[this.arraysize];
        plain2 = new byte[this.arraysize];

        /*
        ** Note that we build the "plaintext" by simply loading
        ** the array up with random numbers.
        */
        for (i = 0; i < this.arraysize; i++)
        {
            plain1[i] = (byte)(ByteMark.abs_randwc(255) & 0xFF);
        }

        /*
        ** See if we need to perform self adjustment loop.
        */
        if (this.adjust == 0)
        {
            /*
            ** Do self-adjustment.  This involves initializing the
            ** # of loops and increasing the loop count until we
            ** get a number of loops that we can use.
            */
            for (this.loops = 100;
                 this.loops < global.MAXIDEALOOPS;
                 this.loops += 10)
            {
                if (DoIDEAIteration(plain1, crypt1, plain2,
                                    this.arraysize,
                                    this.loops,
                                    Z, DK) > global.min_ticks)
                {
                    break;
                }
            }
        }

        /*
        ** All's well if we get here.  Do the test.
        */
        accumtime  = 0;
        iterations = (double)0.0;

        do
        {
            accumtime += DoIDEAIteration(plain1, crypt1, plain2,
                                         this.arraysize,
                                         this.loops, Z, DK);
            iterations += (double)this.loops;
        } while (ByteMark.TicksToSecs(accumtime) < this.request_secs);

        /*
        ** Clean up, calculate results, and go home.  Be sure to
        ** show that we don't have to rerun adjustment code.
        */

        if (this.adjust == 0)
        {
            this.adjust = 1;
        }

        return(iterations / ByteMark.TicksToFracSecs(accumtime));
    }
Beispiel #27
0
    double DoNNET(NNetStruct locnnetstruct)
    {
        //    string errorcontext = "CPU:NNET";
        //    int systemerror = 0;
        long   accumtime  = 0;
        double iterations = 0.0;

        /*
        ** Init random number generator.
        ** NOTE: It is important that the random number generator
        **  be re-initialized for every pass through this test.
        **  The NNET algorithm uses the random number generator
        **  to initialize the net.  Results are sensitive to
        **  the initial neural net state.
        */
        ByteMark.randnum(3);

        /*
        ** Read in the input and output patterns.  We'll do this
        ** only once here at the beginning.  These values don't
        ** change once loaded.
        */
        read_data_file();

        /*
        ** See if we need to perform self adjustment loop.
        */
        if (locnnetstruct.adjust == 0)
        {
            /*
            ** Do self-adjustment.  This involves initializing the
            ** # of loops and increasing the loop count until we
            ** get a number of loops that we can use.
            */
            for (locnnetstruct.loops = 1;
                 locnnetstruct.loops < MAXNNETLOOPS;
                 locnnetstruct.loops++)
            {
                ByteMark.randnum(3);
                if (DoNNetIteration(locnnetstruct.loops) > global.min_ticks)
                {
                    break;
                }
            }
        }

        /*
        ** All's well if we get here.  Do the test.
        */
        accumtime  = 0L;
        iterations = (double)0.0;

        do
        {
            ByteMark.randnum(3);    /* Gotta do this for Neural Net */
            accumtime  += DoNNetIteration(locnnetstruct.loops);
            iterations += (double)locnnetstruct.loops;
        } while (ByteMark.TicksToSecs(accumtime) < locnnetstruct.request_secs);

        /*
        ** Clean up, calculate results, and go home.  Be sure to
        ** show that we don't have to rerun adjustment code.
        */
        locnnetstruct.iterspersec = iterations / ByteMark.TicksToFracSecs(accumtime);

        if (locnnetstruct.adjust == 0)
        {
            locnnetstruct.adjust = 1;
        }


        return(locnnetstruct.iterspersec);
    }
Beispiel #28
0
    /********************
    ** DoHuffIteration **
    *********************
    ** Perform the huffman benchmark.  This routine
    **  (a) Builds the huffman tree
    **  (b) Compresses the text
    **  (c) Decompresses the text and verifies correct decompression
    */
    private static long DoHuffIteration(byte[] plaintext,
                                        byte[] comparray,
                                        byte[] decomparray,
                                        int arraysize,
                                        int nloops,
                                        huff_node[] hufftree)
    {
        int   i;                         /* Index */
        int   j;                         /* Bigger index */
        int   root;                      /* Pointer to huffman tree root */
        float lowfreq1, lowfreq2;        /* Low frequency counters */
        int   lowidx1, lowidx2;          /* Indexes of low freq. elements */
        int   bitoffset;                 /* Bit offset into text */
        int   textoffset;                /* Char offset into text */
        int   maxbitoffset;              /* Holds limit of bit offset */
        int   bitstringlen;              /* Length of bitstring */
        int   c;                         /* Character from plaintext */

        byte[] bitstring = new byte[30]; /* Holds bitstring */
        long   elapsed;                  /* For stopwatch */

        /*
        ** Start the stopwatch
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Do everything for nloops
        */
        while (nloops-- != 0)
        {
            /*
            ** Calculate the frequency of each byte value. Store the
            ** results in what will become the "leaves" of the
            ** Huffman tree.  Interior nodes will be built in those
            ** nodes greater than node #255.
            */
            for (i = 0; i < 256; i++)
            {
                hufftree[i].freq = (float)0.0;
                hufftree[i].c    = (byte)i;
            }

            for (j = 0; j < arraysize; j++)
            {
                hufftree[plaintext[j]].freq += (float)1.0;
            }

            for (i = 0; i < 256; i++)
            {
                if (hufftree[i].freq != (float)0.0)
                {
                    hufftree[i].freq /= (float)arraysize;
                }
            }

            /*
            ** Build the huffman tree.  First clear all the parent
            ** pointers and left/right pointers.  Also, discard all
            ** nodes that have a frequency of true 0.
            */
            for (i = 0; i < 512; i++)
            {
                if (hufftree[i].freq == (float)0.0)
                {
                    hufftree[i].parent = EXCLUDED;
                }
                else
                {
                    hufftree[i].parent = hufftree[i].left = hufftree[i].right = -1;
                }
            }

            /*
            ** Go through the tree. Finding nodes of really low
            ** frequency.
            */
            root = 255;                       /* Starting root node-1 */
            while (true)
            {
                lowfreq1 = (float)2.0; lowfreq2 = (float)2.0;
                lowidx1  = -1; lowidx2 = -1;

                /*
                ** Find first lowest frequency.
                */
                for (i = 0; i <= root; i++)
                {
                    if (hufftree[i].parent < 0)
                    {
                        if (hufftree[i].freq < lowfreq1)
                        {
                            lowfreq1 = hufftree[i].freq;
                            lowidx1  = i;
                        }
                    }
                }

                /*
                ** Did we find a lowest value?  If not, the
                ** tree is done.
                */
                if (lowidx1 == -1)
                {
                    break;
                }

                /*
                ** Find next lowest frequency
                */
                for (i = 0; i <= root; i++)
                {
                    if ((hufftree[i].parent < 0) && (i != lowidx1))
                    {
                        if (hufftree[i].freq < lowfreq2)
                        {
                            lowfreq2 = hufftree[i].freq;
                            lowidx2  = i;
                        }
                    }
                }

                /*
                ** If we could only find one item, then that
                ** item is surely the root, and (as above) the
                ** tree is done.
                */
                if (lowidx2 == -1)
                {
                    break;
                }

                /*
                ** Attach the two new nodes to the current root, and
                ** advance the current root.
                */
                root++;                 /* New root */
                hufftree[lowidx1].parent = root;
                hufftree[lowidx2].parent = root;
                hufftree[root].freq      = lowfreq1 + lowfreq2;
                hufftree[root].left      = lowidx1;
                hufftree[root].right     = lowidx2;
                hufftree[root].parent    = -2;    /* Show root */
            }

            /*
            ** Huffman tree built...compress the plaintext
            */
            bitoffset = 0;                           /* Initialize bit offset */
            for (i = 0; i < arraysize; i++)
            {
                c = (int)plaintext[i];                 /* Fetch character */

                /*
                ** Build a bit string for byte c
                */
                bitstringlen = 0;
                while (hufftree[c].parent != -2)
                {
                    if (hufftree[hufftree[c].parent].left == c)
                    {
                        bitstring[bitstringlen] = (byte)'0';
                    }
                    else
                    {
                        bitstring[bitstringlen] = (byte)'1';
                    }
                    c = hufftree[c].parent;
                    bitstringlen++;
                }

                /*
                ** Step backwards through the bit string, setting
                ** bits in the compressed array as you go.
                */
                while (bitstringlen-- != 0)
                {
                    SetCompBit(comparray, bitoffset, bitstring[bitstringlen]);
                    bitoffset++;
                }
            }

            /*
            ** Compression done.  Perform de-compression.
            */
            maxbitoffset = bitoffset;
            bitoffset    = 0;
            textoffset   = 0;
            do
            {
                i = root;
                while (hufftree[i].left != -1)
                {
                    if (GetCompBit(comparray, bitoffset) == 0)
                    {
                        i = hufftree[i].left;
                    }
                    else
                    {
                        i = hufftree[i].right;
                    }
                    bitoffset++;
                }
                decomparray[textoffset] = hufftree[i].c;

#if DEBUG
                if (hufftree[i].c != plaintext[textoffset])
                {
                    /* Show error */
                    string error = String.Format("Huffman: error at textoffset {0}", textoffset);
                    throw new Exception(error);
                }
#endif
                textoffset++;
            } while (bitoffset < maxbitoffset);
        }       /* End the big while(nloops--) from above */

        /*
        ** All done
        */
        return(ByteMark.StopStopwatch(elapsed));
    }
Beispiel #29
0
 public override void ShowStats()
 {
     ByteMark.OutputString(
         string.Format("  Number of coefficients: {0}", arraysize));
 }
Beispiel #30
0
    public override double Run()
    {
        double[][]   a;
        double[]     b;
        double[][][] abase = null;
        double[][]   bbase = null;
        int          n;
        int          i;
        long         accumtime;
        double       iterations;

        /*
        ** Our first step is to build a "solvable" problem.  This
        ** will become the "seed" set that all others will be
        ** derived from. (I.E., we'll simply copy these arrays
        ** into the others.
        */
        a = new double[global.LUARRAYROWS][];
        for (int j = 0; j < global.LUARRAYROWS; j++)
        {
            a[j] = new double[global.LUARRAYCOLS];
        }
        b = new double[global.LUARRAYROWS];
        n = global.LUARRAYROWS;

        s_LUtempvv = new double[global.LUARRAYROWS];

        build_problem(a, n, b);

        if (this.adjust == 0)
        {
            for (i = 1; i <= MAXLUARRAYS; i++)
            {
                abase = new double[i + 1][][];
                for (int j = 0; j < i + 1; j++)
                {
                    abase[j] = new double[global.LUARRAYROWS][];
                    for (int k = 0; k < global.LUARRAYROWS; k++)
                    {
                        abase[j][k] = new double[global.LUARRAYCOLS];
                    }
                }

                bbase = new double[i + 1][];
                for (int j = 0; j < i + 1; j++)
                {
                    bbase[j] = new double[global.LUARRAYROWS];
                }

                if (DoLUIteration(a, b, abase, bbase, i) > global.min_ticks)
                {
                    this.numarrays = i;
                    break;
                }
            }

            if (this.numarrays == 0)
            {
                throw new Exception("FPU:LU -- Array limit reached");
            }
        }
        else
        {
            abase = new double[this.numarrays][][];
            for (int j = 0; j < this.numarrays; j++)
            {
                abase[j] = new double[global.LUARRAYROWS][];
                for (int k = 0; k < global.LUARRAYROWS; k++)
                {
                    abase[j][k] = new double[global.LUARRAYCOLS];
                }
            }
            bbase = new double[this.numarrays][];
            for (int j = 0; j < this.numarrays; j++)
            {
                bbase[j] = new double[global.LUARRAYROWS];
            }
        }

        accumtime  = 0;
        iterations = 0.0;

        do
        {
            accumtime  += DoLUIteration(a, b, abase, bbase, this.numarrays);
            iterations += (double)this.numarrays;
        } while (ByteMark.TicksToSecs(accumtime) < this.request_secs);

        if (this.adjust == 0)
        {
            this.adjust = 1;
        }

        return(iterations / ByteMark.TicksToFracSecs(accumtime));
    }
Beispiel #31
0
 public override void ShowStats()
 {
     ByteMark.OutputString(
         string.Format("  Number of arrays: {0}", numarrays));
 }