randdata.c 2.18 KB

/**************************************************************************
 *                                                                        *
 *               Copyright (C) 1994, Silicon Graphics, Inc.               *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright  law.  They  may not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *                                                                        *
 *************************************************************************/

/*
 * File:	randinst.c
 * Creator:	rww@sgi.com
 * Create Date:	Wed Sep 28 13:52:37 PDT 1994
 *
 * This file has some functions to generate random instructions.
 *
 */

#include <stdio.h>
#include <string.h>

typedef unsigned long int	u32;

u32 R32(void);
void init_random(void);

main( int argc, char **argv )
{
    int i, c;
    u32 inst;
    u32 inst1;
    u32 inst2;
    u32 inst3;
    char buf[80];
    FILE *data;
    int wide;

    if( argc == 1 ) {
	fprintf(stderr,"Usage: %s count [width]\n", argv[0] );
	exit(1);
    };

    init_random();

    data = fopen("dmem","w");

    c = atoi(argv[1]);

    wide = 1;
    if( argc > 2 )
	wide = atoi( argv[2] );

    if( wide == 1 )
	i=1;
    else
	i=0;

    for(; i<=c; i++) {

	inst = R32();

	if( wide == 1 ) {
	    printf("dep $%d 0x%08x\n", i, inst );
	    fwrite( & inst, sizeof( inst ), 1, data );
	} else {
	    inst1 = R32();
	    inst2 = R32();
	    inst3 = R32();
	    printf("dep $v%d 0x%08x%08x 0x%08x%08x\n", i, inst, inst1, inst2, inst3 );
	    fwrite( & inst, sizeof( inst ), 1, data );
	    fwrite( & inst1, sizeof( inst ), 1, data );
	    fwrite( & inst2, sizeof( inst ), 1, data );
	    fwrite( & inst3, sizeof( inst ), 1, data );
	};
    };

    fclose( data );
}

void
init_random( void )
{
    int rseed;

    rseed = time( 0 );
    srandom(rseed);
}

u32
R32( void )
{
    return( (random()<<1) | (random() & 1) );
}