Пример #1
0
int setup_output_ports(char* file_name)
{
    int port_index;
    char attr_name[30];
    int status;
    int point_index;

    status = h5_get_attr(file_name, "outputs", "number_of_ports", &total_output_ports);

    if (total_output_ports == 0) return 1;
    status = h5_get_attr(file_name, "settings", "starting_index", &starting_index);
    inspect(status, "fail to get h5 attributes");

    for (port_index = 1; port_index <= total_output_ports; port_index++)
    {
        sprintf(attr_name, "port_%02d_write_timedomain", port_index);
        status = h5_get_attr(file_name, "outputs", attr_name, &(output_ports[port_index].write_timedomain));
        inspect(status, "fail to get h5 attributes");
        sprintf(attr_name, "port_%02d_number_of_points", port_index);
        status = h5_get_attr(file_name, "outputs", attr_name, &(output_ports[port_index].total_points));
        inspect(status, "fail to get h5 attributes");
        sprintf(attr_name, "port_%02d_polarization", port_index);
        status = h5_get_attr(file_name, "outputs", attr_name, &(output_ports[port_index].polarization));
        inspect(status, "fail to get h5 attributes");
        output_ports[port_index].fields = (double **)mem2(type_double, total_timesteps, output_ports[port_index].total_points);
        inspect(output_ports[port_index].fields, "fail to allocate memory for output probes");
        sprintf(attr_name, "/outputs/port_%02d_points", port_index);
        output_ports[port_index].probe_points = (int **)h5_load2(file_name, attr_name, output_ports[port_index].total_points, 3);
        inspect(output_ports[port_index].probe_points, "fail to allocate memory for port points");
        for (point_index = 0; point_index < output_ports[port_index].total_points; point_index ++)
        {
            output_ports[port_index].probe_points[point_index][0] = output_ports[port_index].probe_points[point_index][0] - starting_index;
            output_ports[port_index].probe_points[point_index][1] = output_ports[port_index].probe_points[point_index][1] - starting_index;
            output_ports[port_index].probe_points[point_index][2] = output_ports[port_index].probe_points[point_index][2] - starting_index;
        }
    }
    return 1;
}
Пример #2
0
EXPORT_C GSBenchmark(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
	::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS);

	FILE* file = fopen("c:\\temp1\\log.txt", "a");

	fprintf(file, "-------------------------\n\n");

	if(1)
	{
		GSLocalMemory * pMem = new GSLocalMemory();
		GSLocalMemory& mem(*pMem);
		

		static struct {int psm; const char* name;} s_format[] =
		{
			{PSM_PSMCT32, "32"},
			{PSM_PSMCT24, "24"},
			{PSM_PSMCT16, "16"},
			{PSM_PSMCT16S, "16S"},
			{PSM_PSMT8, "8"},
			{PSM_PSMT4, "4"},
			{PSM_PSMT8H, "8H"},
			{PSM_PSMT4HL, "4HL"},
			{PSM_PSMT4HH, "4HH"},
			{PSM_PSMZ32, "32Z"},
			{PSM_PSMZ24, "24Z"},
			{PSM_PSMZ16, "16Z"},
			{PSM_PSMZ16S, "16ZS"},
		};

		uint8* ptr = (uint8*)_aligned_malloc(1024 * 1024 * 4, 32);

		for(int i = 0; i < 1024 * 1024 * 4; i++) ptr[i] = (uint8)i;

		//

		for(int tbw = 5; tbw <= 10; tbw++)
		{
			int n = 256 << ((10 - tbw) * 2);

			int w = 1 << tbw;
			int h = 1 << tbw;

			fprintf(file, "%d x %d\n\n", w, h);

			for(size_t i = 0; i < countof(s_format); i++)
			{
				const GSLocalMemory::psm_t& psm = GSLocalMemory::m_psm[s_format[i].psm];

				GSLocalMemory::writeImage wi = psm.wi;
				GSLocalMemory::readImage ri = psm.ri;
				GSLocalMemory::readTexture rtx = psm.rtx;
				GSLocalMemory::readTexture rtxP = psm.rtxP;

				GIFRegBITBLTBUF BITBLTBUF;

				BITBLTBUF.SBP = 0;
				BITBLTBUF.SBW = w / 64;
				BITBLTBUF.SPSM = s_format[i].psm;
				BITBLTBUF.DBP = 0;
				BITBLTBUF.DBW = w / 64;
				BITBLTBUF.DPSM = s_format[i].psm;

				GIFRegTRXPOS TRXPOS;

				TRXPOS.SSAX = 0;
				TRXPOS.SSAY = 0;
				TRXPOS.DSAX = 0;
				TRXPOS.DSAY = 0;

				GIFRegTRXREG TRXREG;

				TRXREG.RRW = w;
				TRXREG.RRH = h;

				GSVector4i r(0, 0, w, h);

				GIFRegTEX0 TEX0;

				TEX0.TBP0 = 0;
				TEX0.TBW = w / 64;

				GIFRegTEXA TEXA;

				TEXA.TA0 = 0;
				TEXA.TA1 = 0x80;
				TEXA.AEM = 0;

				int trlen = w * h * psm.trbpp / 8;
				int len = w * h * psm.bpp / 8;

				clock_t start, end;

				_ftprintf(file, _T("[%4s] "), s_format[i].name);

				start = clock();

				for(int j = 0; j < n; j++)
				{
					int x = 0;
					int y = 0;

					(mem.*wi)(x, y, ptr, trlen, BITBLTBUF, TRXPOS, TRXREG);
				}

				end = clock();

				fprintf(file, "%6d %6d | ", (int)((float)trlen * n / (end - start) / 1000), (int)((float)(w * h) * n / (end - start) / 1000));

				start = clock();

				for(int j = 0; j < n; j++)
				{
					int x = 0;
					int y = 0;

					(mem.*ri)(x, y, ptr, trlen, BITBLTBUF, TRXPOS, TRXREG);
				}

				end = clock();

				fprintf(file, "%6d %6d | ", (int)((float)trlen * n / (end - start) / 1000), (int)((float)(w * h) * n / (end - start) / 1000));

				const GSOffset* o = mem.GetOffset(TEX0.TBP0, TEX0.TBW, TEX0.PSM);

				start = clock();

				for(int j = 0; j < n; j++)
				{
					(mem.*rtx)(o, r, ptr, w * 4, TEXA);
				}

				end = clock();

				fprintf(file, "%6d %6d ", (int)((float)len * n / (end - start) / 1000), (int)((float)(w * h) * n / (end - start) / 1000));

				if(psm.pal > 0)
				{
					start = clock();

					for(int j = 0; j < n; j++)
					{
						(mem.*rtxP)(o, r, ptr, w, TEXA);
					}

					end = clock();

					fprintf(file, "| %6d %6d ", (int)((float)len * n / (end - start) / 1000), (int)((float)(w * h) * n / (end - start) / 1000));
				}

				fprintf(file, "\n");

				fflush(file);
			}

			fprintf(file, "\n");
		}

		_aligned_free(ptr);
		delete pMem;
	}

	//

	if(0)
	{
		GSLocalMemory * pMem2 = new GSLocalMemory();
		GSLocalMemory& mem2(*pMem2);

		uint8* ptr = (uint8*)_aligned_malloc(1024 * 1024 * 4, 32);

		for(int i = 0; i < 1024 * 1024 * 4; i++) ptr[i] = (uint8)i;

		const GSLocalMemory::psm_t& psm = GSLocalMemory::m_psm[PSM_PSMCT32];

		GSLocalMemory::writeImage wi = psm.wi;

		GIFRegBITBLTBUF BITBLTBUF;

		BITBLTBUF.DBP = 0;
		BITBLTBUF.DBW = 32;
		BITBLTBUF.DPSM = PSM_PSMCT32;

		GIFRegTRXPOS TRXPOS;

		TRXPOS.DSAX = 0;
		TRXPOS.DSAY = 1;

		GIFRegTRXREG TRXREG;

		TRXREG.RRW = 256;
		TRXREG.RRH = 256;

		int trlen = 256 * 256 * psm.trbpp / 8;

		int x = 0;
		int y = 0;

		(mem2.*wi)(x, y, ptr, trlen, BITBLTBUF, TRXPOS, TRXREG);
		delete pMem2;
	}

	//

	fclose(file);
	PostQuitMessage(0);
}
Пример #3
0
bool MemFile::open (const std::string &path_, bool uncompress)
{
	MEMORY mem(MAX_IMAGE_SIZE + 1);
	size_t uRead = 0;

	// Check if zlib is available
#ifdef HAVE_ZLIBSTAT
	bool have_zlib = true;
#elif defined(HAVE_ZLIB)
	bool have_zlib = CheckLibrary("zlib", "zlibVersion") && zlibVersion()[0] == ZLIB_VERSION[0];
#else
	bool have_zlib = false;
#endif

#ifdef HAVE_ZLIB
	// Try opening as a zip file
	if (uncompress && have_zlib)
	{
		unzFile hfZip = unzOpen(path_.c_str());
		if (hfZip)
		{
			int nRet;
			unz_file_info sInfo;
			uLong ulMaxSize = 0;

			// Iterate through the contents of the zip looking for a file with a suitable size
			for (nRet = unzGoToFirstFile(hfZip); nRet == UNZ_OK; nRet = unzGoToNextFile(hfZip))
			{
				char szFile[MAX_PATH];

				// Get details of the current file
				unzGetCurrentFileInfo(hfZip, &sInfo, szFile, MAX_PATH, nullptr, 0, nullptr, 0);

				// Ignore directories and empty files
				if (!sInfo.uncompressed_size)
					continue;

				// If the file extension is recognised, read the file contents
				// ToDo: GetFileType doesn't really belong here?
				if (GetFileType(szFile) != ftUnknown && unzOpenCurrentFile(hfZip) == UNZ_OK)
				{
					nRet = unzReadCurrentFile(hfZip, mem, static_cast<unsigned int>(mem.size));
					unzCloseCurrentFile(hfZip);
					break;
				}

				// Rememeber the largest uncompressed file size
				if (sInfo.uncompressed_size > ulMaxSize)
					ulMaxSize = sInfo.uncompressed_size;
			}

			// Did we fail to find a matching extension?
			if (nRet == UNZ_END_OF_LIST_OF_FILE)
			{
				// Loop back over the archive
				for (nRet = unzGoToFirstFile(hfZip); nRet == UNZ_OK; nRet = unzGoToNextFile(hfZip))
				{
					// Get details of the current file
					unzGetCurrentFileInfo(hfZip, &sInfo, nullptr, 0, nullptr, 0, nullptr, 0);

					// Open the largest file found about
					if (sInfo.uncompressed_size == ulMaxSize && unzOpenCurrentFile(hfZip) == UNZ_OK)
					{
						nRet = unzReadCurrentFile(hfZip, mem, static_cast<unsigned int>(mem.size));
						unzCloseCurrentFile(hfZip);
						break;
					}
				}
			}

			// Close the zip archive
			unzClose(hfZip);

			// Stop if something went wrong
			if (nRet < 0)
				throw util::exception("zip extraction failed (", nRet, ")");

			uRead = nRet;
			m_compress = Compress::Zip;
		}
		else
		{
			// Open as gzipped or uncompressed
			gzFile gf = gzopen(path_.c_str(), "rb");
			if (gf == Z_NULL)
				throw posix_error(errno, path_.c_str());

			uRead = gzread(gf, mem, static_cast<unsigned>(mem.size));
			m_compress = (gztell(gf) != FileSize(path_)) ? Compress::Gzip : Compress::None;
			gzclose(gf);
		}
	}
	else
#endif // HAVE_ZLIB
	{
		// Open as normal file if we couldn't use zlib above
		FILE *f = fopen(path_.c_str(), "rb");
		if (!f)
			throw posix_error(errno, path_.c_str());

		uRead = fread(mem, 1, mem.size, f);
		fclose(f);
		m_compress = Compress::None;
	}


	// zip compressed? (and not handled above)
	if (uncompress && mem[0U] == 'P' && mem[1U] == 'K')
		throw util::exception("zlib (zlib1.dll) is required for zip support");

	// gzip compressed?
	if (uncompress && mem[0U] == 0x1f && mem[1U] == 0x8b && mem[2U] == 0x08)
	{
		if (!have_zlib)
			throw util::exception("zlib (zlib1.dll) is required for gzip support");

#ifdef HAVE_ZLIB
		MEMORY mem2(MAX_IMAGE_SIZE + 1);
		uint8_t flags = mem[3];
		auto pb = mem.pb + 10, pbEnd = mem.pb + mem.size;

		if (flags & 0x04)	// EXTRA_FIELD
		{
			if (pb < pbEnd - 1)
				pb += 2 + pb[0] + (pb[1] << 8);
		}

		if (flags & 0x08 || flags & 0x10)	// ORIG_NAME or COMMENT
		{
			while (pb < pbEnd && *pb++);
		}

		if (flags & 0x02)	// HEAD_CRC
			pb += 2;

		z_stream stream = {};
		stream.next_in = pb;
		stream.avail_in = (pb < pbEnd) ? static_cast<uInt>(pbEnd - pb) : 0;
		stream.next_out = mem2.pb;
		stream.avail_out = mem2.size;

		auto zerr = inflateInit2(&stream, -MAX_WBITS);
		if (zerr == Z_OK)
		{
			zerr = inflate(&stream, Z_FINISH);
			inflateEnd(&stream);
		}

		if (zerr != Z_STREAM_END)
			throw util::exception("gzip decompression failed (", zerr, ")");

		memcpy(mem.pb, mem2.pb, uRead = stream.total_out);
		m_compress = Compress::Zip;
#endif
	}

	// bzip2 compressed?
	if (uncompress && mem[0U] == 'B' && mem[1U] == 'Z')
	{
#ifdef HAVE_BZIP2
		if (!CheckLibrary("bzip2", "BZ2_bzBuffToBuffDecompress"))
#endif
			throw util::exception("libbz2 (bzip2.dll) is required for bzip2 support");

#ifdef HAVE_BZIP2
		MEMORY mem2(MAX_IMAGE_SIZE + 1);

		auto uBzRead = static_cast<unsigned>(mem2.size);
		auto bzerr = BZ2_bzBuffToBuffDecompress(reinterpret_cast<char *>(mem2.pb), &uBzRead, reinterpret_cast<char *>(mem.pb), uRead, 0, 0);
		if (bzerr != BZ_OK)
			throw util::exception("bzip2 decompression failed (", bzerr, ")");

		memcpy(mem.pb, mem2.pb, uRead = uBzRead);
		m_compress = Compress::Bzip2;
#endif // HAVE_BZIP2
	}

	if (uRead <= MAX_IMAGE_SIZE)
		return open(mem.pb, static_cast<int>(uRead), path_);

	throw util::exception("file size too big");
}
Пример #4
0
int main( int argc, char ** argv )
{
  FILE * pFile;
  int i, do_continue;
  char in_file[MAX_STR+1], out_file[MAX_STR+1], line[MAX_STR+1];

  do_continue = i = 0;
  pFile = NULL;

do
  {
  printf("Input file? "); fgets( in_file, MAX_STR, stdin );
  printf("Output file? "); fgets( out_file, MAX_STR, stdin );
  sscanf( in_file, "%s\n", in_file );
  sscanf( out_file, "%s\n", out_file );

  pFile = fopen( in_file, "r" );
  if( pFile == NULL ) return 1;

  fout = fopen( out_file, "w" );
  if( fout == NULL ) return 2;
  
  if( init( pFile ) ) goto unable_to_parse;

  do 
    {
      fprintf( fout, "c#%d ", cycle );
      wb(); mem3(); mem2(); mem1(); ex(); id(); if2(); if1(); /* pretend all stages are happening simultaneously */
      fprintf( fout, "\n");
      /* move everything down the pipeline */
      if( !MEM3_stall ) { WB = MEM3; WB_count = MEM3_count; }
      if( !MEM2_stall ) { MEM3 = MEM2; MEM3_count = MEM2_count; }
      if( !MEM1_stall ) { MEM2 = MEM1; MEM2_count = MEM1_count; }
      if( !EX_stall   ) { MEM1 = EX; MEM1_count = EX_count; }
      if( !ID_stall   ) { EX = ID; EX_count = ID_count; } else MEM1 = EMPTY;
      if( !IF2_stall  ) { ID = IF2; ID_count = IF2_count; }
      if( !IF1_stall  ) { IF2 = IF1; IF2_count = IF1_count; ++inst_cycle; }
      if( flush ) { IF1 = EMPTY; IF2 = EMPTY; ID = EMPTY; EX = EMPTY; flush = FALSE; --inst_cycle; }
      ++cycle;
      Registers[0] = 0; /* reset R0 if it was accidently set */
    } while( ( (IF1 != EMPTY) || (IF2 != EMPTY) || (ID != EMPTY) || (EX != EMPTY) || (MEM1 != EMPTY) || (MEM2 != EMPTY) || (MEM3 != EMPTY) || (WB != EMPTY) ) );

  /* print end status */
  print_regs( fout ); print_mem( fout );

  unable_to_parse:
  for( i = 0; i < instcount; ++i )
    free( Instructions[i] );
  fclose( pFile );
  fclose( fout );

  printf("would you like to run again? ");
  fgets( line, MAX_STR, stdin );
  do_continue = ( line[0] == 'y' || line[0] == 'Y' ) ? 1 : 0;
  } while( do_continue );

 goto end;
 for( i = 0; i < instcount; ++i )
   free( Instructions[i] );
 fclose( pFile );
 fclose( fout );
 end:
 return 0;
}