void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) {
  // Compute maximal alignment.
  int align = _insts.alignment();
  // Always allow for empty slop around each section.
  int slop = (int) CodeSection::end_slop();

  assert(blob() == NULL, "only once");
  set_blob(BufferBlob::create(_name, code_size + (align+slop) * (SECT_LIMIT+1)));
  if (blob() == NULL) {
    // The assembler constructor will throw a fatal on an empty CodeBuffer.
    return;  // caller must test this
  }

  // Set up various pointers into the blob.
  initialize(_total_start, _total_size);

  assert((uintptr_t)insts_begin() % CodeEntryAlignment == 0, "instruction start not code entry aligned");

  pd_initialize();

  if (locs_size != 0) {
    _insts.initialize_locs(locs_size / sizeof(relocInfo));
  }

  verify_section_allocation();
}
Exemple #2
0
void reflect_X()
{
   int i;
   
   if (2*N > NMAX)
     {
	fprintf(comp_log,"The problem size is too big!\n");
	fprintf(comp_log,"Note: If you use XANTISYMMETRY, NMAX must be adjusted to buffer twice\n");
	fprintf(comp_log,"the size of the half-problem.\n");

	exit(-1);
     }
   
   for (i=0; i<N; ++i)
     {
	mblob[i+N] = mblob[i];
	blobguts[i+N] = blobguts[i];

	mblob[i+N].blob0.y *= -1.0;
	mblob[i+N].blob0.strength *= -1.0;
	blobguts[i+N].th *= -1.0;
	set_blob(&(blobguts[i+N]),&(tmpparms[i+N]));
     }
   
   N *= 2;
}
Exemple #3
0
void read_text_file(const char* filename, Value* contentsOut)
{
    if (!file_exists(filename)) {
        set_null(contentsOut);
        return;
    }

    FILE* fp = fopen(filename, "r");

    if (fp == NULL) {
        // Unlikely to reach here since we just checked file_exists. But possible.
        set_null(contentsOut);
        return;
    }

    // Get file size
    fseek(fp, 0, SEEK_END);
    size_t file_size = ftell(fp);
    rewind(fp);

    // Read raw data.
    touch(contentsOut);
    set_blob(contentsOut, int(file_size));

    size_t bytesRead = fread(as_blob(contentsOut), 1, file_size, fp);
    
    if (bytesRead < file_size)
        string_resize(contentsOut, (int) bytesRead);

    fclose(fp);
}
/**
 * Integrate a sparse array
 */
void Sparsematrix::integrate_sparsearray(Sparsearray *sp) {
  float spw = (float) sp->width;
  int opw = (int)sp->width;
  int oph = (int)sp->height;
  float ow = (float) width;
  int dlen = sp->datalen;
  if (layout == 0) {
    // CENTERFIXEDWIDTH
    int xofs = (int) ((ow - spw) / 2.0);
    for (int idx = 0; idx < dlen; idx += 3) {
      int ox = sp->data[idx + 1];
      int ny = (int) sp->data[idx + 2];
      if (ox > trimPixelsLeft && ox < (opw - trimPixelsRight) && ny > trimPixelsTop && ny < (oph - trimPixelsBottom)) {
        int nx = (int) ((float) ox + xofs);
        if (ny <= height + blobhalfheight) {
          set_blob(nx, ny);
        }
      }
    }
  } else if (layout == 1) {
    // STRETCH
    for (int idx = 0; idx < dlen; idx += 3) {
      int ox = sp->data[idx + 1];
      int nx = (int) (((float) ox / spw) * ow);
      int ny = (int) sp->data[idx + 2];
      if (ox > trimPixelsLeft && ox < (opw - trimPixelsRight) && ny > trimPixelsTop && ny < (oph - trimPixelsBottom)) {
        if (ny <= (int) height + (int) blobhalfheight) {
          set_blob(nx, ny);
        }
      }
    }
  } else if (layout == 2) {
    // LEFTFIXEDWIDTH
    for (int idx = 0; idx < dlen; idx += 3) {
      int nx = (int) sp->data[idx + 1];
      int ny = (int) sp->data[idx + 2];
      if (ny <= ((int) height + (int) blobhalfheight) && (nx > trimPixelsLeft && nx < (opw - trimPixelsRight) && ny > trimPixelsTop && ny < (oph - trimPixelsBottom))) {
        set_blob(nx, ny);
      }
    }
  }
}
Exemple #5
0
void vel_field()
{
   int j;

   vel_cputime_ref = clock();
   vel_cputime = 0;
   velsum_cputime = 0;
   veldirect_cputime = 0;
   mp_cputime = 0;

   for (j=0; j<N; ++j)
     set_blob(&(blobguts[j]),&(tmpparms[j]));
   
   if (xantisymm)
     /* Double the number of computational elements by reflecting them
      * about the x-axis. */
     reflect_X();

   wipe_vort_vel_field();

   Create_Hierarchy();

   
#ifdef CACHERESORT
	cache_resort();
#endif

#ifdef MULTIPROC  
   if (total_processes == 2)
     peer();
   else
     {
	if (rank == 0) 
	  master();
	else 
	  slave();
	
	finish();
     }
#else
   /* single processor code */

   if (xantisymm)
     for (j=0; j<N/2; ++j) 
       { 
#ifdef LINEAR
	 dpos_vel_linear(j);
#else
#ifdef NOFASTMP
	 dpos_vel(j);
#else
	 dpos_vel_fast(j);
#endif
#endif
       }
   else
     for (j=0; j<N; ++j) 
       { 
#ifdef LINEAR
	 dpos_vel_linear(j);
#else
#ifdef NOFASTMP
	 dpos_vel(j);
#else
	 dpos_vel_fast(j);
#endif
#endif
       }
#endif  
   
   if (xantisymm)
   /* re-adjust */
     N /= 2;
   
#ifdef CORRECTVEL4
   correct_vel_4();
#endif
   Release_Links(mplevels);

   if (B != 0)
     {
       solve_bdy_matrix(walls,Bpiv,BdyMat);
       for (j=0; j<N; ++j)
	 bdy_vel(mblob[j].blob0.x,mblob[j].blob0.y,
		 &(mblob[j].blob0.dx),&(mblob[j].blob0.dy));
     }

   vel_cputime += clock()-vel_cputime_ref;
   fprintf(cpu_log,"%07d %12.4e %12.4e %12.4e %12.4e %12.4e %12.4e\n",
	   N,
	   ((double)(vel_cputime))/((double)CLOCKS_PER_SEC),
	   ((double)(velsum_cputime))/((double)CLOCKS_PER_SEC),
	   ((double)(veldirect_cputime))/((double)CLOCKS_PER_SEC),
	   ((double)(mp_cputime))/((double)CLOCKS_PER_SEC),
	   ((double)(mp_Init_Fine_Grid))/((double)CLOCKS_PER_SEC),
	   ((double)(mp_Advance_Coeffs))/((double)CLOCKS_PER_SEC)
	   );
   fflush(cpu_log);
}
void CodeBuffer::free_blob() {
  if (_blob != NULL) {
    BufferBlob::free(_blob);
    set_blob(NULL);
  }
}
Exemple #7
0
int main()
{
     auto b = get_blob();
     modify_blob(b);
     set_blob(b);    
}