コード例 #1
0
ファイル: render.cpp プロジェクト: torandi/omgspaceponnies
static void render_walls(double dt) {
    //Draw walls

    for(int x=0; x<MAP_WIDTH; ++x) {
        for(int y=0; y<MAP_HEIGHT; ++y) {
            if(map_value(x, y) > 0) {
                glPushMatrix();
#ifdef DEBUG
                if(map_value(x,y) == 2) {
                    texture_colors[0]=0;
                    texture_colors[1]=1;
                    texture_colors[2]=0;
                    map[y][x] = 1;
                } else {
                    texture_colors[0]=1;
                    texture_colors[1]=0.5;
                    texture_colors[2]=1;
                }
#endif
                glTranslatef(x*64-32,y*64-32,0);
                box.render(dt);
                glPopMatrix();
            }
        }
    }
}
コード例 #2
0
ファイル: uinst.c プロジェクト: ajdupree/cs316-m2s
static char *x86_uinst_dep_name_get(int dep)
{
	if (X86_DEP_IS_VALID(dep))
		return x86_uinst_dep_name[dep];
	else
		return map_value(&x86_uinst_dep_map, dep);
}
コード例 #3
0
ファイル: player.cpp プロジェクト: ext/omgspaceponnies
void Player::calc_fire(bool detect_kill) {
	//fire_end.x = ((pos.x/64)+1)*64;
	//fire_end.y = ((pos.y/64)+1)*64;
	fire_end = pos;
	int len = 0;
	while(len < MAX_FIRE_LENGHT) {
		len += 32;
		vector_t prev(fire_end);
		fire_end.x+= 32*cos(angle);
		fire_end.y+= 32*sin(angle);

		for(int i=0; i < NUM_PLAYERS; ++i) {
			if(i != id && players[i] != NULL && players[i]->dead == 0) {
				vector_t d;
				d.x = fire_end.x - players[i]->pos.x;
				d.y = fire_end.y - players[i]->pos.y;
				if(d.norm() < PLAYER_W/2.0)  {
					players[i]->dead = 1;
					printf("Killed player %i\n", i);
					char buffer[128];
					sprintf(buffer, "omg kil %i", i);
				}
			}

			int mx, my;
			calc_map_index(fire_end, mx, my);
			if(map_value(mx, my) > 0) {
				fire_end = prev;
				//map[my][mx]+=10;
				break;
			}
		}
	}

}
コード例 #4
0
ファイル: json_write.c プロジェクト: clandgraf/experimental
static void _json_write_object(FILE * file, map_t map, unsigned int depth)
{
    if (map_size(map) == 0) {
        fputs("{}", file);
    } else {
        bool first = true;

        fputs("{\n", file);

        for_each_map(it, map) {
            if (first) first = false;
            else fputs(",\n");

            for (int i = 0; i < depth + 1; i++)
                fputs("    ", file);
            _json_write_string(file, map_key(it));
            fputs(": ");
            _json_write(file, map_value(it), depth + 1);
        }

        fputs("\n", file);
        for (int i = 0; i < depth; i++)
            fputs("    ", file);
        fputs("}", file);
    }
}
コード例 #5
0
ファイル: gpu.c プロジェクト: ajdupree/cs316-m2s
static void si_config_dump(FILE *f)
{
    /* Device configuration */
    fprintf(f, "[ Config.Device ]\n");
    fprintf(f, "NumComputeUnits = %d\n", si_gpu_num_compute_units);
    fprintf(f, "NumWavefrontPools = %d\n", si_gpu_num_wavefront_pools);
    fprintf(f, "NumStreamCores = %d\n", si_gpu_num_stream_cores);
    fprintf(f, "NumRegisters = %d\n", si_gpu_num_registers);
    fprintf(f, "RegisterAllocSize = %d\n", si_gpu_register_alloc_size);
    fprintf(f, "RegisterAllocGranularity = %s\n",
            map_value(&si_gpu_register_alloc_granularity_map,
                      si_gpu_register_alloc_granularity));
    fprintf(f, "WavefrontSize = %d\n", si_emu_wavefront_size);
    fprintf(f, "MaxWorkGroupsPerWavefrontPool= %d\n", si_gpu_max_work_groups_per_wavefront_pool);
    fprintf(f, "MaxWavefrontsPerWavefrontPool = %d\n", si_gpu_max_wavefronts_per_wavefront_pool);
    fprintf(f, "SIMDALULatency = %d\n", si_gpu_simd_alu_latency);
    fprintf(f, "SIMDIssueWidth = %d\n", si_gpu_simd_issue_width);
    fprintf(f, "ScalarUnitALULatency = %d\n", si_gpu_scalar_unit_alu_latency);
    fprintf(f, "ScalarUnitIssueWidth = %d\n", si_gpu_scalar_unit_issue_width);
    fprintf(f, "BranchUnitLatency = %d\n", si_gpu_branch_unit_latency);
    fprintf(f, "BranchUnitIssueWidth = %d\n", si_gpu_branch_unit_issue_width);
    fprintf(f, "SchedulingPolicy = %s\n", map_value(&si_gpu_sched_policy_map,
            si_gpu_sched_policy));
    fprintf(f, "\n");

    /* Local Memory */
    fprintf(f, "[ Config.LocalMemory ]\n");
    fprintf(f, "Size = %d\n", si_gpu_local_mem_size);
    fprintf(f, "AllocSize = %d\n", si_gpu_local_mem_alloc_size);
    fprintf(f, "BlockSize = %d\n", si_gpu_local_mem_block_size);
    fprintf(f, "Latency = %d\n", si_gpu_local_mem_latency);
    fprintf(f, "Ports = %d\n", si_gpu_local_mem_num_ports);
    fprintf(f, "\n");

    /* End of configuration */
    fprintf(f, "\n");
}
コード例 #6
0
ファイル: main.cpp プロジェクト: ruhulsbu/ShortReadAlignment
void kmer_inverted_index(vector<pair<string, string> >& reference, vector<reference_index>& refindex)
{
	int input, cases = 0, overlap, index_time;

	string str1, str2;
	for(int i = 0; i < KMER; i++)
		for(int k = 0; k < BASE; k++ )
			base_power_kmer[i][k] = pow(BASE, i) * k;

	long kmer_choices = (long) (pow(4, KMER) + 9);	
	for(int i = 0; i < reference.size(); i++)
	{
		reference_index refinfo;
		refinfo.name = reference.at(i).first;
		refinfo.ref = reference.at(i).second;
		refinfo.rev = reverse_complement(reference.at(i).second);

		refinfo.index = new int [kmer_choices];
		memset(refinfo.index, -1, (sizeof(int) * kmer_choices));
		refinfo.revind = new int [kmer_choices];
		memset(refinfo.revind, -1, (sizeof(int) * kmer_choices));

		//cout << "ref: " << refinfo.name << " and name = " << refinfo.ref.size() << endl;

		long hash_key = 0;
		int map_val = 0;
		for(int k = 0, i = KMER - 2; k < KMER - 1; k++, i--)
		{
			map_val = map_value(refinfo.ref.at(k));
			hash_key += base_power_kmer[i][map_val];
		}

		for(int k = KMER - 1; k < refinfo.ref.length(); k++)
		{
			map_val = map_value(refinfo.ref.at(k));
			hash_key = (hash_key << 2) + map_val;
			
			if(refinfo.index[hash_key] == -1)
			{
				vector<int> pos;
				refinfo.position.push_back(pos);
				refinfo.index[hash_key] = refinfo.position.size() - 1;
			} 
					
			refinfo.position[refinfo.index[hash_key]].push_back(k - KMER + 1);		
			map_val = map_value(refinfo.ref.at(k - KMER + 1));
			hash_key -= base_power_kmer[KMER - 1][map_val];
		}

		/////////////////////////////////////////////////////////////////////////////////////

		hash_key = 0;
		map_val = 0;
		for(int k = 0, i = KMER - 2; k < KMER - 1; k++, i--)
		{
			map_val = map_value(refinfo.rev.at(k));
			hash_key += base_power_kmer[i][map_val];
		}

		for(int k = KMER - 1; k < refinfo.rev.length(); k++)
		{
			map_val = map_value(refinfo.rev.at(k));
			hash_key = (hash_key << 2) + map_val;
			
			if(refinfo.revind[hash_key] == -1)
			{
				vector<int> pos;
				refinfo.position.push_back(pos);
				refinfo.revind[hash_key] = refinfo.position.size() - 1;
			} 
					
			refinfo.position[refinfo.revind[hash_key]].push_back(k - KMER + 1);
			map_val = map_value(refinfo.rev.at(k - KMER + 1));
			hash_key -= base_power_kmer[KMER - 1][map_val];
		}
	
		//cout << "Total index size = " << refinfo.position.size() << endl;	
		refindex.push_back(refinfo);
		
	}

}
コード例 #7
0
bvt boolbvt::convert_byte_update(const byte_update_exprt &expr)
{
  if(expr.operands().size()!=3)
    throw "byte_update takes three operands";
    
  const exprt &op=expr.op0();
  const exprt &offset_expr=expr.offset();
  const exprt &value=expr.value();

  bool little_endian;
  
  if(expr.id()==ID_byte_update_little_endian)
    little_endian=true;
  else if(expr.id()==ID_byte_update_big_endian)
    little_endian=false;
  else
    assert(false);

  bvt bv=convert_bv(op);
  
  const bvt &value_bv=convert_bv(value);
  std::size_t update_width=value_bv.size();
  std::size_t byte_width=8;
  
  if(update_width>bv.size())
    update_width=bv.size();

  // see if the byte number is constant

  mp_integer index;
  if(!to_integer(offset_expr, index))
  {
    // yes!
    mp_integer offset=index*8;
    
    if(offset+update_width>mp_integer(bv.size()) || offset<0)
    {
      // out of bounds
    }
    else
    {
      if(little_endian)
      {
        for(std::size_t i=0; i<update_width; i++)
          bv[integer2size_t(offset+i)]=value_bv[i];
      }
      else
      {
        endianness_mapt map_op(op.type(), false, ns);
        endianness_mapt map_value(value.type(), false, ns);
        
        std::size_t offset_i=integer2unsigned(offset);
        
        for(std::size_t i=0; i<update_width; i++)
        {
          size_t index_op=map_op.map_bit(offset_i+i);
          size_t index_value=map_value.map_bit(i);

          assert(index_op<bv.size());
          assert(index_value<value_bv.size());
          
          bv[index_op]=value_bv[index_value];
        }
      }
    }

    return bv;
  }

  // byte_update with variable index
  for(std::size_t offset=0; offset<bv.size(); offset+=byte_width)
  {
    // index condition
    equal_exprt equality;
    equality.lhs()=offset_expr;
    equality.rhs()=from_integer(offset/byte_width, offset_expr.type());
    literalt equal=convert(equality);
    
    endianness_mapt map_op(op.type(), little_endian, ns);
    endianness_mapt map_value(value.type(), little_endian, ns);

    for(std::size_t bit=0; bit<update_width; bit++)
      if(offset+bit<bv.size())
      {
        std::size_t bv_o=map_op.map_bit(offset+bit);
        std::size_t value_bv_o=map_value.map_bit(bit);
        
        bv[bv_o]=prop.lselect(equal, value_bv[value_bv_o], bv[bv_o]);
      }
  }
  
  return bv;
}
コード例 #8
0
ファイル: bin-file.c プロジェクト: ajdupree/cs316-m2s
static void si_bin_file_read_enc_dict(struct si_bin_file_t *bin_file)
{
    struct elf_file_t *elf_file;
    struct elf_buffer_t *buffer;
    Elf32_Ehdr *elf_header;

    struct elf_program_header_t *program_header;

    struct si_bin_enc_dict_entry_t *enc_dict_entry;
    struct si_bin_enc_dict_entry_header_t *enc_dict_entry_header;
    int enc_dict_entry_count;

    int i;

    /* ELF header */
    elf_file = bin_file->elf_file;
    elf_header = elf_file->header;
    buffer = &elf_file->buffer;
    elf_debug("**\n** Parsing AMD Binary (Internal ELF file)\n** %s\n**\n\n", elf_file->path);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(elf_header->e_ident[EI_CLASS], ELFCLASS32);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(elf_header->e_ident[EI_DATA], ELFDATA2LSB);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(elf_header->e_ident[EI_OSABI], 0x64);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(elf_header->e_ident[EI_ABIVERSION], 1);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(elf_header->e_type, ET_EXEC);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(elf_header->e_machine, 0x7d);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(elf_header->e_entry, 0);

    /* Look for encoding dictionary (program header with type 'PT_LOPROC+2') */
    program_header = NULL;
    for (i = 0; i < list_count(elf_file->program_header_list); i++)
    {
        program_header = list_get(elf_file->program_header_list, i);
        if (program_header->header->p_type == PT_LOPROC + 2)
            break;
    }
    if (i == list_count(elf_file->program_header_list) || !program_header)
        fatal("%s: no encoding dictionary", elf_file->path);
    elf_debug("Encoding dictionary found in program header %d\n", i);

    /* Parse encoding dictionary */
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(program_header->header->p_vaddr, 0);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(program_header->header->p_paddr, 0);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(program_header->header->p_memsz, 0);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(program_header->header->p_flags, 0);
    SI_BIN_FILE_NOT_SUPPORTED_NEQ(program_header->header->p_align, 0);
    assert(program_header->header->p_filesz % sizeof(struct si_bin_enc_dict_entry_header_t) == 0);
    enc_dict_entry_count = program_header->header->p_filesz / sizeof(struct si_bin_enc_dict_entry_header_t);
    elf_debug("  -> %d entries\n\n", enc_dict_entry_count);

    /* Read encoding dictionary entries */
    bin_file->enc_dict = list_create();
    elf_buffer_seek(buffer, program_header->header->p_offset);
    for (i = 0; i < enc_dict_entry_count; i++) {

        /* Create entry */
        enc_dict_entry = calloc(1, sizeof(struct si_bin_enc_dict_entry_t));
        enc_dict_entry->header = elf_buffer_tell(buffer);
        elf_buffer_read(buffer, NULL, sizeof(struct si_bin_enc_dict_entry_header_t));
        list_add(bin_file->enc_dict, enc_dict_entry);

        /* Store encoding dictionary entry for Evergreen (code 9) */
        if (enc_dict_entry->header->d_machine == 9)
        {
            bin_file->enc_dict_entry_southern_islands = enc_dict_entry;
        }
        else if (enc_dict_entry->header->d_machine == 26)
        {
            /* Southern Islands has code 26 */
            bin_file->enc_dict_entry_southern_islands = enc_dict_entry;
        }
    }

    /* Debug */
    elf_debug("idx %-15s %-10s %-10s %-10s %-10s\n", "d_machine", "d_type",
              "d_offset", "d_size", "d_flags");
    for (i = 0; i < 80; i++)
        elf_debug("-");
    elf_debug("\n");
    for (i = 0; i < list_count(bin_file->enc_dict); i++)
    {
        char machine_str[MAX_STRING_SIZE];

        enc_dict_entry = list_get(bin_file->enc_dict, i);
        enc_dict_entry_header = enc_dict_entry->header;
        snprintf(machine_str, sizeof(machine_str), "%d (%s)",
                 enc_dict_entry_header->d_machine, map_value(&enc_dict_machine_map,
                         enc_dict_entry_header->d_machine - 1));
        elf_debug("%3d %-15s 0x%-8x 0x%-8x %-10d 0x%-8x\n",
                  i, machine_str,
                  enc_dict_entry_header->d_type,
                  enc_dict_entry_header->d_offset,
                  enc_dict_entry_header->d_size,
                  enc_dict_entry_header->d_flags);
    }
    elf_debug("\n\n");
}
コード例 #9
0
ファイル: bin-file.c プロジェクト: ajdupree/cs316-m2s
/* Read next note at the current position of the PT_NOTE segment */
static void si_bin_file_read_note_header(struct si_bin_file_t *bin_file, struct si_bin_enc_dict_entry_t *enc_dict_entry)
{
    struct elf_buffer_t *buffer;

    struct pt_note_header_t *header;
    void *desc;

    int count;
    char *note_type_str;

    /* Read note header */
    buffer = &enc_dict_entry->pt_note_buffer;
    header = elf_buffer_tell(buffer);
    count = elf_buffer_read(buffer, NULL, sizeof(struct pt_note_header_t));
    if (count < sizeof(struct pt_note_header_t))
        fatal("%s: error decoding note header", bin_file->elf_file->path);

    /* Read note description (payload) */
    desc = elf_buffer_tell(buffer);
    count = elf_buffer_read(buffer, NULL, header->descsz);
    if (count < header->descsz)
        fatal("%s: error decoding note description", bin_file->elf_file->path);

    /* Debug */
    note_type_str = map_value(&pt_note_type_map, header->type);
    elf_debug("  note: type=%d (%s), descsz=%d\n",
              header->type, note_type_str, header->descsz);

    /* Analyze note */
    switch (header->type)
    {

    case 1:  /* ELF_NOTE_ATI_PROGINFO */
    {
        int prog_info_count;
        struct pt_note_prog_info_entry_t *prog_info_entry;
        int i;

        /* Get number of entries */
        assert(header->descsz % sizeof(struct pt_note_prog_info_entry_t) == 0);
        prog_info_count = header->descsz / sizeof(struct pt_note_prog_info_entry_t);
        elf_debug("\tnote including device configuration unique to the program (%d entries)\n",
                  prog_info_count);

        /* Decode entries */
        for (i = 0; i < prog_info_count; i++)
        {
            prog_info_entry = desc + i * sizeof(struct pt_note_prog_info_entry_t);
            elf_debug("\tprog_info_entry: addr=0x%x (%s), value=%u\n",
                      prog_info_entry->address, map_value(&prog_info_entry_map,
                              prog_info_entry->address), prog_info_entry->value);

            /* Analyze entry */
            switch (prog_info_entry->address)
            {

            case 0x00002e13:  /* COMPUTE_PGM_RSRC2 */
                enc_dict_entry->compute_pgm_rsrc2 = (struct si_bin_compute_pgm_rsrc2_t*)&prog_info_entry->value;
                break;

            case 0x80000080:  /* AMU_ABI_NUM_GPR_USED */
                enc_dict_entry->num_gpr_used = prog_info_entry->value;
                break;

            case 0x80000082:  /* AMU_ABI_LDS_SIZE_USED */
                enc_dict_entry->lds_size_used = prog_info_entry->value;
                break;

            case 0x80000084:  /* AMU_ABI_STACK_SIZE_USED */
                enc_dict_entry->stack_size_used = prog_info_entry->value;
                break;
            case 0x80001000:  /* AMU_ABI_USER_ELEMENT_COUNT */
                enc_dict_entry->userElementCount = prog_info_entry->value;
                i++;

                /* Analyze user elements */
                for(int j = 0; j < 4 * enc_dict_entry->userElementCount; j++)
                {
                    prog_info_entry = desc + i * sizeof(struct pt_note_prog_info_entry_t);
                    elf_debug("\tprog_info_entry: addr=0x%x (%s), value=%u\n",
                              prog_info_entry->address, map_value(&prog_info_entry_map,
                                      prog_info_entry->address), prog_info_entry->value);
                    switch(j % 4)
                    {
                    case 0:
                        enc_dict_entry->userElements[j / 4].dataClass = prog_info_entry->value;
                        break;
                    case 1:
                        enc_dict_entry->userElements[j / 4].apiSlot = prog_info_entry->value;
                        break;
                    case 2:
                        enc_dict_entry->userElements[j / 4].startUserReg = prog_info_entry->value;
                        break;
                    case 3:
                        enc_dict_entry->userElements[j / 4].userRegCount = prog_info_entry->value;
                        break;
                    }

                    i++;
                }
                break;
            }
        }
        break;
    }


    case 2:  /* ELF_NOTE_ATI_INPUTS */
    {
        /* FIXME: Analyze program inputs */
        if (header->descsz)
            warning("%s: pt_note '%s' with descsz != 0 ignored (desc value = 0x%x)",
                    note_type_str, __FUNCTION__, * (unsigned int *) desc);

        break;
    }


    case 3:  /* ELF_NOTE_ATI_OUTPUTS */
    {
        /* FIXME: Analyze program inputs */
        if (header->descsz)
            warning("%s: pt_note '%s' with descsz != 0 ignored (desc value = 0x%x)",
                    note_type_str, __FUNCTION__, * (unsigned int *) desc);

        break;
    }


    case 4:  /* ELF_NOTE_ATI_CONDOUT */
        break;

    case 5:  /* ELF_NOTE_ATI_FLOAT32CONSTS */
    case 6:  /* ELF_NOTE_ATI_INT32CONSTS */
    case 7:  /* ELF_NOTE_ATI_BOOL32CONSTS */
    {
        int data_segment_desc_count;
        struct pt_note_data_segment_desc_t *data_segment_desc;

        struct si_bin_enc_dict_entry_consts_t *consts;
        char const_value[MAX_STRING_SIZE];

        int j;

        /* Get number of entries */
        consts = enc_dict_entry->consts;
        assert(header->descsz % sizeof(struct pt_note_data_segment_desc_t) == 0);
        data_segment_desc_count = header->descsz / sizeof(struct pt_note_data_segment_desc_t);
        elf_debug("\tnote including data for constant buffers (%d entries)\n",
                  data_segment_desc_count);

        /* Decode entries */
        for (j = 0; j < data_segment_desc_count; j++)
        {
            data_segment_desc = desc + j * sizeof(struct pt_note_data_segment_desc_t);
            if (header->type == 5)
                snprintf(const_value, sizeof(const_value), "{%g,%g,%g,%g}",
                         consts->float_consts[data_segment_desc->offset][0],
                         consts->float_consts[data_segment_desc->offset][1],
                         consts->float_consts[data_segment_desc->offset][2],
                         consts->float_consts[data_segment_desc->offset][3]);
            else if (header->type == 6)
                snprintf(const_value, sizeof(const_value), "{%u,%u,%u,%u}",
                         consts->int_consts[data_segment_desc->offset][0],
                         consts->int_consts[data_segment_desc->offset][1],
                         consts->int_consts[data_segment_desc->offset][2],
                         consts->int_consts[data_segment_desc->offset][3]);
            else
                snprintf(const_value, sizeof(const_value), "%d",
                         consts->bool_consts[data_segment_desc->offset]);
            elf_debug("\tdata_segment_desc[%d]: offset=0x%x, size=%d, value=%s\n",
                      j, data_segment_desc->offset, data_segment_desc->size, const_value);
        }
        break;
    }


    case 8:  /* ELF_NOTE_ATI_EARLYEXIT */
    {
        Elf32_Word early_exit;

        /* Get 'early_exit' value */
        early_exit = header->descsz ? * (uint32_t *) desc : 0;
        elf_debug("\tearly_exit = %s\n", early_exit ? "TRUE" : "FALSE");
        break;
    }


    case 9:  /* ELF_NOTE_ATI_GLOBAL_BUFFERS */
    {
        Elf32_Word global_buffers;
        global_buffers = header->descsz ? * (uint32_t *) desc : 0;
        elf_debug("\tglobal_buffers = %s\n", global_buffers ? "TRUE" : "FALSE");
        break;
    }


    case 10:  /* ELF_NOTE_ATI_CONSTANT_BUFFERS */
    {
        int constant_buffer_count;
        struct pt_note_constant_buffer_mask_t *constant_buffer_mask;
        int i;

        /* Get number of entries */
        assert(header->descsz % sizeof(struct pt_note_constant_buffer_mask_t) == 0);
        constant_buffer_count = header->descsz / sizeof(struct pt_note_constant_buffer_mask_t);
        elf_debug("\tnote including number and size of constant buffers (%d entries)\n",
                  constant_buffer_count);

        /* Decode entries */
        for (i = 0; i < constant_buffer_count; i++) {
            constant_buffer_mask = desc + i * sizeof(struct pt_note_constant_buffer_mask_t);
            elf_debug("\tconstant_buffer[%d].size = %d (vec4f constants)\n",
                      constant_buffer_mask->index, constant_buffer_mask->size);
        }
        break;
    }


    case 11:  /* ELF_NOTE_ATI_INPUT_SAMPLERS */
        break;

    case 12:  /* ELF_NOTE_ATI_PERSISTENT_BUFFERS */
    {
        Elf32_Word persistent_buffers;
        persistent_buffers = header->descsz ? * (uint32_t *) desc : 0;
        elf_debug("\tpersistent_buffers = %s\n", persistent_buffers ? "TRUE" : "FALSE");
        break;
    }


    case 13:  /* ELF_NOTE_ATI_SCRATCH_BUFFERS */
    {
        Elf32_Word scratch_buffers;
        scratch_buffers = header->descsz ? * (uint32_t *) desc : 0;
        elf_debug("\tscratch_buffers = %s\n", scratch_buffers ? "TRUE" : "FALSE");
        break;
    }


    case 14:  /* ELF_NOTE_ATI_SUB_CONSTANT_BUFFERS */
        break;

    case 15:  /* ELF_NOTE_ATI_UAV_MAILBOX_SIZE */
        break;

    case 16:  /* ELF_NOTE_ATI_UAV */
    {
        int uav_entry_count;
        struct pt_note_uav_entry_t *uav_entry;
        int i;

        assert(header->descsz % sizeof(struct pt_note_uav_entry_t) == 0);
        uav_entry_count = header->descsz / sizeof(struct pt_note_uav_entry_t);
        elf_debug("\tnote (%d entries)\n", uav_entry_count);

        /* Decode entries */
        for (i = 0; i < uav_entry_count; i++) {
            uav_entry = desc + i * sizeof(struct pt_note_uav_entry_t);
            elf_debug("\tuav_entry[%d].uav = %d [%d, %d, %d]\n", i, uav_entry->id,
                      uav_entry->unknown1, uav_entry->unknown2, uav_entry->unknown3);
        }
        break;
    }


    case 17:  /* ELF_NOTE_ATI_UAV_OP_MASK */
        break;

    default:
        elf_debug("\tunknown type\n");
    }
}
コード例 #10
0
ファイル: typelib.c プロジェクト: WASSUM/longene_travel
static void test_dump_typelib(const char *name)
{
    WCHAR wszString[260];
    ITypeInfo *info;
    ITypeLib *lib;
    int count;
    int i;

    MultiByteToWideChar(CP_ACP, 0, name, -1, wszString, 260);
    OLE_CHECK(LoadTypeLib(wszString, &lib));
    count = ITypeLib_GetTypeInfoCount(lib);
    printf("/* interfaces count: %d */\n", count);
    for (i = 0; i < count; i++)
    {
        TYPEATTR *attr;
        BSTR name;
        int f = 0;

        OLE_CHECK(ITypeLib_GetDocumentation(lib, i, &name, NULL, NULL, NULL));
        printf("{\n"
               "  %s,\n", dump_string(name));
        SysFreeString(name);

        OLE_CHECK(ITypeLib_GetTypeInfo(lib, i, &info));
        ITypeInfo_GetTypeAttr(info, &attr);
        printf("  /*kind*/ %s, /*flags*/ 0x%x, /*align*/ %d, /*size*/ %d,\n"
               "  /*#vtbl*/ %d, /*#func*/ %d,\n"
               "  {\n",
            map_value(attr->typekind, tkind_map), attr->wTypeFlags, attr->cbAlignment, attr->cbSizeInstance, attr->cbSizeVft,
            attr->cFuncs);
        ITypeInfo_ReleaseTypeAttr(info, attr);
        while (1)
        {
            FUNCDESC *desc;
            BSTR tab[256];
            UINT cNames;
            int p;

            if (FAILED(ITypeInfo_GetFuncDesc(info, f, &desc)))
                break;
            printf("    {\n"
                   "      0x%x, /*func*/ %s, /*inv*/ %s, /*call*/ 0x%x,\n",
                desc->memid, map_value(desc->funckind, funckind_map), map_value(desc->invkind, invkind_map),
                desc->callconv);
            printf("      /*#param*/ %d, /*#opt*/ %d, /*vtbl*/ %d, /*#scodes*/ %d, /*flags*/ 0x%x,\n",
                desc->cParams, desc->cParamsOpt, desc->oVft, desc->cScodes, desc->wFuncFlags);
            printf("      {%d, %x}, /* ret */\n", desc->elemdescFunc.tdesc.vt, desc->elemdescFunc.paramdesc.wParamFlags);
            printf("      { /* params */\n");
            for (p = 0; p < desc->cParams; p++)
            {
                ELEMDESC e = desc->lprgelemdescParam[p];
                printf("        {%d, %x},\n", e.tdesc.vt, e.paramdesc.wParamFlags);
            }
            printf("        {-1, -1}\n");
            printf("      },\n");
            printf("      { /* names */\n");
            OLE_CHECK(ITypeInfo_GetNames(info, desc->memid, tab, 256, &cNames));
            for (p = 0; p < cNames; p++)
            {
                printf("        %s,\n", dump_string(tab[p]));
                SysFreeString(tab[p]);
            }
            printf("        NULL,\n");
            printf("      },\n");
            printf("    },\n");
            ITypeInfo_ReleaseFuncDesc(info, desc);
            f++;
        }
        printf("  }\n");
        printf("},\n");
        ITypeInfo_Release(info);
    }
    ITypeLib_Release(lib);
}
コード例 #11
0
int count_kmer_match(string& str1, string& str2, int start, int end)
{
	string kmer; 
	int i, k, sum;
	vector<int> lis_vector;
	vector<int> indexing;

	unordered_map<long, int> map;
	vector<pair<long, int> > vecmap;

	//cout << "Length of Str1 = " << str1.length() << ", and Str2 = " << str2.length() << endl;
	for(int k = 0; k < ANCHOR; k++)
		vecmap.push_back(make_pair(-1, -1));

	bool flag = true;
	long hash_key = 0;
	int map_val; 
	long base_power_kmer = pow(BASE, PRIMANCHORWORD - 1);

	for(int k = 0; k < str2.length(); k++)
	{
		if(flag == true && k + PRIMANCHORWORD > str2.length())
			break;
		for(int l = k, e = k; l < e + PRIMANCHORWORD - 1 && flag == true; l++, k++)
		{
			map_val = map_value(str2.at(l));
			if(map_val == -1)
				break;

			hash_key = (hash_key << 2) + map_val;
			//cout << "For character " << read.at(k) << ", at position = " << k <<
			//	", the hash_key = " << hash_key << endl;
		}

		map_val = map_value(str2.at(k));
		if(map_val == -1)
		{
			//cout << "Encountered invalid character N ########################" << endl;
			flag = true;
			hash_key = 0;
			continue;
		}
		else
			flag = false;

		hash_key = (hash_key << 2) + map_val;

		if(map.find(hash_key) == map.end())
		{
			map[hash_key] = k - PRIMANCHORWORD + 1;
		}
		else 
			map[hash_key] = -1; //now 05-25-15
		//cout << "For character " << read.at(k) << ", at position = " << k <<
		//		", the hash_key = " << hash_key << endl;
	
		vecmap[k] = make_pair(hash_key, k - PRIMANCHORWORD + 1);
		map_val = map_value(str2.at(k - PRIMANCHORWORD + 1));
		hash_key = hash_key - base_power_kmer * map_val;
	}

	flag = true;
	hash_key = 0;
	base_power_kmer = pow(BASE, PRIMANCHORWORD - 1);
	//cout << "LIS Pref for Ref From " << (start - 1) << ", And End = " << (end - 1) << endl;

	for(int k = start - 1, i = 0; k < end - 1; k++, i++)
	{
		if(flag == true && k + PRIMANCHORWORD > end)
			break;
		for(int l = k, e = k; l < e + PRIMANCHORWORD - 1 && flag == true; l++, k++, i++)
		{
			map_val = map_value(str1.at(l));
			if(map_val == -1)
				break;

			hash_key = (hash_key << 2) + map_val;
			//cout << "For character " << read.at(k) << ", at position = " << k <<
			//	", the hash_key = " << hash_key << endl;
		}

		map_val = map_value(str1.at(k));
		if(map_val == -1)
		{
			//cout << "Encountered invalid character N ########################" << endl;
			flag = true;
			hash_key = 0;
			continue;
		}
		else
			flag = false;

		hash_key = (hash_key << 2) + map_val;

		if(map.find(hash_key) != map.end())
                {
			/*
			cout << "Read Index = " << (map[hash_key]) << ", Ref Index = " << (k - PRIMANCHORWORD + 1) << endl;
			cout << "Read = " << str2.substr(map[hash_key], PRIMANCHORWORD) << endl;
			cout << "Refe = " << str1.substr(k - PRIMANCHORWORD + 1, PRIMANCHORWORD) << endl;
			*/
                        if(map[hash_key] != -1 && (abs(map[hash_key] - (i - PRIMANCHORWORD + 1)) < 5))//5 not 4
                        {
                                lis_vector.push_back(map[hash_key]);
				//cout << "Passed" << endl;
                        }
			else
			{
				for(int j = max(0, i - 3); j < min(i + 3, vecmap.size()); j++)
				{
					if(vecmap[j].first == hash_key)
					{
						lis_vector.push_back(vecmap[j].second);
						vecmap[j].first = -1;
						break;
					}
				}

			}
			//cout << endl;
                }

		//cout << "For character " << read.at(k) << ", at position = " << k <<
		//		", the hash_key = " << hash_key << endl;
	
		map_val = map_value(str1.at(k - PRIMANCHORWORD + 1));
		hash_key = hash_key - base_power_kmer * map_val;
	}


	int lis_size = lis_vector.size();
	
	if(lis_size < 10) 
		return -1 * lis_size;

	find_lis_vector(lis_vector, indexing);
	/*
	if(DEBUG == 99)
	{
		for (i = 0; i < indexing.size(); i++)
		{
                	printf("\t%d", lis_vector[indexing[i]]);
        		if((i +1) % 12 == 0)
        			printf("\n");
		}
		printf("\n");
	}
	*/
	k = lis_vector[indexing[0]];
	sum = PRIMANCHORWORD;
	for(i = 1; i < indexing.size(); i++)
	{
		if(lis_vector[indexing[i]] - k < PRIMANCHORWORD)
		{
			sum = sum + (lis_vector[indexing[i]] - k);
		}
		else
			sum = sum + PRIMANCHORWORD;

		k = lis_vector[indexing[i]];
	}

	//cout << "LIS SUM for PRIMANCHORWORD = " << PRIMANCHORWORD << " is = " << sum << endl;
	lis_vector.clear();
	indexing.clear();

	if((100.0 * sum / ANCHOR)  < PRIMANCHORPIDENT)//0.65
	{
		return -1 * sum;//lis_size;
	}
	else
	{
		return lis_size;
	}
}
コード例 #12
0
void NotificationCenter::AddObserver(const char *notify_name, observer proc, boost::shared_ptr<void> user_data) {
	boost::optional<std::string> key = CreateKey(notify_name);
	boost::tuple<observer, boost::shared_ptr<void> > value = boost::make_tuple<observer, boost::shared_ptr<void> >(proc, user_data);
	boost::mutex::scoped_lock lk(observer_list_mtx);
	observer_list.insert(map_value(key, value));
}
コード例 #13
0
ファイル: m2s.c プロジェクト: abhaykadam/vm
void sim_stats_summary(void)
{
	long long now = ke_timer();
	long long gpu_now = gk_timer();
	long long inst_count;

	double sec_count;
	double inst_per_sec;
	double inst_per_cycle;
	double branch_acc;
	double cycles_per_sec;

	/* Check if any simulation was actually performed */
	inst_count = cpu_sim_kind == cpu_sim_functional ? ke->inst_count : cpu->inst;
	if (!inst_count)
		return;

	/* Statistics */
	fprintf(stderr, "\n");
	fprintf(stderr, ";\n");
	fprintf(stderr, "; Simulation Statistics Summary\n");
	fprintf(stderr, ";\n");
	fprintf(stderr, "\n");

	/* CPU functional simulation */
	sec_count = (double) now / 1e6;
	inst_per_sec = sec_count > 0.0 ? (double) inst_count / sec_count : 0.0;
	fprintf(stderr, "[ CPU ]\n");
	fprintf(stderr, "Time = %.2f\n", sec_count);
	fprintf(stderr, "Instructions = %lld\n", inst_count);
	fprintf(stderr, "InstructionsPerSecond = %.0f\n", inst_per_sec);
	fprintf(stderr, "Contexts = %d\n", ke->running_list_max);
	fprintf(stderr, "Memory = %lu\n", mem_max_mapped_space);
	fprintf(stderr, "SimEnd = %s\n", map_value(&ke_sim_finish_map, ke_sim_finish));

	/* CPU detailed simulation */
	if (cpu_sim_kind == cpu_sim_detailed)
	{
		inst_per_cycle = cpu->cycle ? (double) cpu->inst / cpu->cycle : 0.0;
		branch_acc = cpu->branches ? (double) (cpu->branches - cpu->mispred) / cpu->branches : 0.0;
		cycles_per_sec = sec_count > 0.0 ? (double) cpu->cycle / sec_count : 0.0;
		fprintf(stderr, "Cycles = %lld\n", cpu->cycle);
		fprintf(stderr, "InstructionsPerCycle = %.4g\n", inst_per_cycle);
		fprintf(stderr, "BranchPredictionAccuracy = %.4g\n", branch_acc);
		fprintf(stderr, "CyclesPerSecond = %.0f\n", cycles_per_sec);
	}
	fprintf(stderr, "\n");

	/* GPU functional simulation */
	if (gk->ndrange_count)
	{
		sec_count = (double) gpu_now / 1e6;
		inst_per_sec = sec_count > 0.0 ? (double) gk->inst_count / sec_count : 0.0;
		fprintf(stderr, "[ GPU ]\n");
		fprintf(stderr, "Time = %.2f\n", sec_count);
		fprintf(stderr, "NDRangeCount = %d\n", gk->ndrange_count);
		fprintf(stderr, "Instructions = %lld\n", gk->inst_count);
		fprintf(stderr, "InstructionsPerSecond = %.0f\n", inst_per_sec);
	
		/* GPU detailed simulation */
		if (gpu_sim_kind == gpu_sim_detailed)
		{
			inst_per_cycle = gpu->cycle ? (double) gk->inst_count / gpu->cycle : 0.0;
			cycles_per_sec = sec_count > 0.0 ? (double) gpu->cycle / sec_count : 0.0;
			fprintf(stderr, "Cycles = %lld\n", gpu->cycle);
			fprintf(stderr, "InstructionsPerCycle = %.4g\n", inst_per_cycle);
			fprintf(stderr, "CyclesPerSecond = %.0f\n", cycles_per_sec);
		}
		fprintf(stderr, "\n");
	}
}
コード例 #14
0
ファイル: isa.c プロジェクト: Peilong/multi2sim-4.0-hc
void evg_isa_write_task_commit(struct evg_work_item_t *work_item)
{
	struct linked_list_t *task_list = work_item->write_task_list;
	struct evg_wavefront_t *wavefront = work_item->wavefront;
	struct evg_work_group_t *work_group = work_item->work_group;

	struct evg_isa_write_task_t *wt;
	struct evg_inst_t *inst;

	/* Process first tasks of type:
	 *  - EVG_ISA_WRITE_TASK_WRITE_DEST
	 *  - EVG_ISA_WRITE_TASK_WRITE_LDS
	 */
	for (linked_list_head(task_list); !linked_list_is_end(task_list); )
	{

		/* Get task */
		wt = linked_list_get(task_list);
		assert(wt->work_item == work_item);
		inst = wt->inst;

		switch (wt->kind)
		{
		
		case EVG_ISA_WRITE_TASK_WRITE_DEST:
		{
			if (wt->write_mask)
				evg_isa_write_gpr(work_item, wt->gpr, wt->rel, wt->chan, wt->value);
			work_item->pv.elem[wt->inst->alu] = wt->value;

			/* Debug */
			if (evg_isa_debugging())
			{
				evg_isa_debug("  i%d:%s", work_item->id,
					map_value(&evg_pv_map, wt->inst->alu));
				if (wt->write_mask)
				{
					evg_isa_debug(",");
					evg_inst_dump_gpr(wt->gpr, wt->rel, wt->chan, 0,
						debug_file(evg_isa_debug_category));
				}
				evg_isa_debug("<=");
				gpu_isa_dest_value_dump(inst, &wt->value,
					debug_file(evg_isa_debug_category));
			}

			break;
		}

		case EVG_ISA_WRITE_TASK_WRITE_LDS:
		{
			struct mem_t *local_mem;
			union evg_reg_t lds_value;

			local_mem = work_group->local_mem;
			assert(local_mem);
			assert(wt->lds_value_size);
			mem_write(local_mem, wt->lds_addr, wt->lds_value_size, &wt->lds_value);

			/* Debug */
			lds_value.as_uint = wt->lds_value;
			evg_isa_debug("  i%d:LDS[0x%x]<=(%u,%gf) (%d bytes)", work_item->id, wt->lds_addr,
				lds_value.as_uint, lds_value.as_float, (int) wt->lds_value_size);
			break;
		}

		default:
			linked_list_next(task_list);
			continue;
		}

		/* Done with this task */
		repos_free_object(evg_isa_write_task_repos, wt);
		linked_list_remove(task_list);
	}

	/* Process PUSH_BEFORE, PRED_SET */
	for (linked_list_head(task_list); !linked_list_is_end(task_list); )
	{
		/* Get task */
		wt = linked_list_get(task_list);
		inst = wt->inst;

		/* Process */
		switch (wt->kind)
		{

		case EVG_ISA_WRITE_TASK_PUSH_BEFORE:
		{
			if (!wavefront->push_before_done)
				evg_wavefront_stack_push(wavefront);
			wavefront->push_before_done = 1;
			break;
		}

		case EVG_ISA_WRITE_TASK_SET_PRED:
		{
			int update_pred = EVG_ALU_WORD1_OP2.update_pred;
			int update_exec_mask = EVG_ALU_WORD1_OP2.update_exec_mask;

			assert(inst->info->fmt[1] == EVG_FMT_ALU_WORD1_OP2);
			if (update_pred)
				evg_work_item_set_pred(work_item, wt->cond);
			if (update_exec_mask)
				evg_work_item_set_active(work_item, wt->cond);

			/* Debug */
			if (debug_status(evg_isa_debug_category))
			{
				if (update_pred && update_exec_mask)
					evg_isa_debug("  i%d:act/pred<=%d", work_item->id, wt->cond);
				else if (update_pred)
					evg_isa_debug("  i%d:pred=%d", work_item->id, wt->cond);
				else if (update_exec_mask)
					evg_isa_debug("  i%d:pred=%d", work_item->id, wt->cond);
			}
			break;
		}

		default:
			abort();
		}
		
		/* Done with task */
		repos_free_object(evg_isa_write_task_repos, wt);
		linked_list_remove(task_list);
	}

	/* List should be empty */
	assert(!linked_list_count(task_list));
}
コード例 #15
0
void read_vs_reference(string& read, string& read_name, int dir, vector<reference_index>& refindex, 
				vector<pair<int, vector<pair<int, int> > > >& primary_chain)
{
	time_t start, end;

	//unordered_map<long, int> kmer_list;
	unordered_map<long, int> kmer_map;
	vector<pair<long, int> > kmer_list;
	//vector<pair<int, vector<pair<int, int> > > > primary_chain;
	cout << "\t readseq: " << read_name << " with length = " << read.length() 
			<< " comparing to " << refindex.size() << " references" << endl;
	
	time(&start);

	bool flag = true;
	long hash_key = 0;
	int map_val; 

	for(int k = 0; k < read.length(); k++)
	{
		if(flag == true && k + KMER > read.length())
			break;
		for(int l = k, end = k, i = KMER - 2; l < end + KMER - 1 && flag == true; l++, k++, i--)
		{
			map_val = map_value(read.at(l));
			if(map_val == -1)
				break;

			hash_key += base_power_kmer[i][map_val];
			
			//cout << "For character " << read.at(k) << ", at position = " << k <<
			//	", the hash_key = " << hash_key << endl;
		}

		map_val = map_value(read.at(k));
		if(map_val == -1)
		{
			//cout << "Encountered invalid character N ########################" << endl;
			flag = true;
			hash_key = 0;
			continue;
		}
		else
			flag = false;

		hash_key = hash_key * BASE + map_val;

		if(kmer_map.find(hash_key) == kmer_map.end())
		{
			kmer_map[hash_key] = k - KMER + 1;
		}
		else
			kmer_map[hash_key] = -1;//need work here
		//cout << "For character " << read.at(k) << ", at position = " << k <<
		//		", the hash_key = " << hash_key << endl;
	 	//if(kmer_map[hash_key] != -1)
                kmer_list.push_back(make_pair(hash_key, k - KMER + 1));
		
		map_val = map_value(read.at(k - KMER + 1));
		hash_key -= base_power_kmer[KMER - 1][map_val];
	}



	for(int index = 0; index < refindex.size(); index++)
	{
		vector<pair<int, int> > kmer_index;
	
		for(auto it = kmer_list.cbegin(); it != kmer_list.cend(); ++it)
		{
			//std::cout << " " << it->first << ":" << it->second;  // cannot modify *it
  			//std::cout << std::endl;
			
			if(it->second != -1 && refindex.at(index).index[it->first] != -1)
			{
				vector<int> pos = refindex.at(index).position.at(refindex.at(index).index[it->first]);
				//cout << "Size of the Vector == " << pos.size() << endl;
				//if(pos.size() > 3)//experiment 04-21-2015 failed
				//	continue;			

				for(int i = 0; i < pos.size(); i++)
				{
					kmer_index.push_back(make_pair(pos.at(i), it->second));
				}
			}
			
		}
		
		if(kmer_index.size() == 0) 
			continue;

		sort(kmer_index.begin(), kmer_index.end(), compare_function);
		/*		
		for(int k = 0; k < kmer_index.size(); k++)
		{
			cout << "For the ref_index = " << index << ": " << kmer_index.at(k).first << ": " << 
				kmer_index.at(k).second << endl;
		}
		
		cout << endl << "After the refinement: " << endl << endl;
		*/
		refine_kmer_index(kmer_index, primary_chain, read, dir, refindex, index);
		/*
		for(int k = 0; k < kmer_index.size(); k++)
		{
			cout << "For the ref_index = " << index << ": " << kmer_index.at(k).first << ": " << 
				kmer_index.at(k).second << endl;
		}
		
		cout << endl;
		*/
		/*
		int first_index, last_index;
		int max_count = 0, count = 0;
		int i = 0, j = 0;
		bool flag = true;

		for(int k = 0; k < kmer_index.size(); k++)
                {
                        if(kmer_index[k].first == -1)
                                continue;

                        first_index = kmer_index[k].first + 1 - kmer_index[k].second;///1.3
                        last_index = kmer_index[k].first + 1 - kmer_index[k].second + read.length() / 1.35;
                        if((first_index >= 1) && (last_index <= refindex[index].ref.length()))
                        {
                                //kmer_ref.push_back(make_pair(index * MAXLEN + dir, make_pair(first_index, last_index)));
                                kmer_ref.push_back(make_pair(index * MAXLEN + dir, kmer_index[k]));
                                //cout << "Pushing: first = " << kmer_index[i].first << " And second = " << kmer_index[i].second << endl;
                        }

		}
		*/

		kmer_index.clear();

	}

	time(&end);

	cout << "Total time taken inside read_vs_reference = " << difftime(end, start) << endl;
	cout << "size of the candidate idices = " << primary_chain.size() << endl << endl;
	
	kmer_list.clear();
	/*
	sort(primary_chain.begin(), primary_chain.end(), compare_chain);

	for(int i = 0; i < primary_chain.size(); i++)
        {
                cout << "\t" << i << ") " << primary_chain[i].first << " == " << primary_chain[i].second.size() << endl;
                for(int k = 0; k < primary_chain[i].second.size(); k++)
                        cout << "\t\tref = " << primary_chain[i].second[k].first << " : read = " <<
                                primary_chain[i].second[k].second << " : diff = "  <<
                                (primary_chain[i].second[k].first - primary_chain[i].second[k].second) << endl;
        }
	
        primary_chain.clear();
	*/

	return;
}
コード例 #16
0
bool find_alignment_direction(string& read, reference_index& reference, ofstream& fp_detail)
{
	time_t start, end;

	time(&start);

	bool flag = true;
	long hash_key = 0;
	int map_val;
	int forward_map_count = 0;
	int reverse_map_count = 0; 

	for(int k = 0; k < read.length() && k < SEED; k++)
	{
		if(flag == true && k + KMER > read.length())
			break;
		for(int l = k, end = k, i = KMER - 2; l < end + KMER - 1 && flag == true; l++, k++, i--)
		{
			map_val = map_value(read.at(l));
			if(map_val == -1)
				break;

			hash_key += base_power_kmer[i][map_val];
			
			//cout << "For character " << read.at(k) << ", at position = " << k <<
			//	", the hash_key = " << hash_key << endl;
		}

		map_val = map_value(read.at(k));
		if(map_val == -1)
		{
			//cout << "Encountered invalid character N ########################" << endl;
			flag = true;
			hash_key = 0;
			continue;
		}
		else
			flag = false;

		hash_key = hash_key * BASE + map_val;

		if(reference.index[hash_key] != -1)
		{
			forward_map_count += 1;
		}
		if(reference.revind[hash_key] != -1)
		{
			reverse_map_count += 1;
		}
		
		//cout << "For character " << read.at(k) << ", at position = " << k <<
		//		", the hash_key = " << hash_key << endl;
	
		map_val = map_value(read.at(k - KMER + 1));
		hash_key -= base_power_kmer[KMER - 1][map_val];
	}

	if(forward_map_count >= reverse_map_count)
		return true;
	else 
		return false;

}
コード例 #17
0
int
abi_do_setsockopt(unsigned long *sp)
{
	int error;
	int level, optname;

	error = verify_area(VERIFY_READ,
			((unsigned long *)sp),
			5*sizeof(long));
	if (error)
		return error;

	get_user(level, ((unsigned long *)sp)+1);
	get_user(optname, ((unsigned long *)sp)+2);

	if (abi_traced(ABI_TRACE_STREAMS|ABI_TRACE_SOCKSYS)) {
		u_long optval, optlen;

		get_user(optval, ((u_long *)sp) + 3);
		get_user(optlen, ((u_long *)sp) + 4);
		__abi_trace("setsockopt level=%d, optname=%d, "
				"optval=0x%08lx, optlen=0x%08lx\n",
				level, optname, optval, optlen);
	}

	switch (level) {
		case 0: /* IPPROTO_IP aka SOL_IP */
			/* This is correct for the SCO family. Hopefully
			 * it is correct for other SYSV...
			 */
			optname--;
			if (optname == 0)
				optname = 4;
			if (optname > 4) {
				optname += 24;
				if (optname <= 33)
					optname--;
				if (optname < 32 || optname > 36)
					return -EINVAL;
			}
			put_user(optname, ((unsigned long *)sp)+2);
			break;

		case 0xffff:
			put_user(SOL_SOCKET, ((unsigned long *)sp)+1);
			optname = map_value(current->exec_domain->sockopt_map, optname, 0);
			put_user(optname, ((unsigned long *)sp)+2);

			switch (optname) {
				case SO_LINGER: {
					unsigned long optlen;

					/* SO_LINGER takes a struct linger
					 * as the argument but some code
					 * uses an int and expects to get
					 * away without an error. Sigh...
					 */
					get_user(optlen, ((unsigned long *)sp)+4);
					if (optlen == sizeof(int))
						return 0;
					break;
				}

				/* The following are not currently implemented
				 * under Linux so we must fake them in
				 * reasonable ways. (Only SO_PROTOTYPE is
				 * documented in SCO's man page).
				 */
				case SO_PROTOTYPE:
				case SO_ORDREL:
				case SO_SNDTIMEO:
				case SO_RCVTIMEO:
					return -ENOPROTOOPT;

				case SO_USELOOPBACK:
				case SO_SNDLOWAT:
				case SO_RCVLOWAT:
					return 0;

				/* The following are not currenty implemented
				 * under Linux and probably aren't settable
				 * anyway.
				 */
				case SO_IMASOCKET:
					return -ENOPROTOOPT;
			}

		default:
			/* FIXME: We assume everything else uses the
			 * same level and option numbers. This is true
			 * for IPPROTO_TCP(/SOL_TCP) and TCP_NDELAY
			 * but is known to be incorrect for other
			 * potential options :-(.
			 */
			break;
	}

	return sys_socketcall(SYS_SETSOCKOPT, sp);
}
コード例 #18
0
void read_vs_reference(string& read, string& read_name, int dir, vector<reference_index>& refindex, 
				vector<pair<int, vector<pair<int, int> > > >& primary_chain)
{
	time_t start, end;
	vector<pair<long, int> > kmer_list;
	//unordered_map<long, int> kmer_list;
	//unordered_map<long, int> kmer_map;
	//vector<pair<int, vector<pair<int, int> > > > primary_chain;

	//cout << "\t readseq: " << read_name << " with length = " << read.length() 
	//		<< " comparing to " << refindex.size() << " references" << endl;
	
	time(&start);

	bool flag = true;
	long hash_key = 0;
	int map_val; 
	int readlen = read.length();
	long prehashval = -1;
	int prehashcnt = 0;

	for(int k = 0; k < read.length(); k++)
	{
		if(flag == true)
		{
			if(k + KMER > read.length())
				break;
			for(int l = k, end = k, i = KMER - 2; l < end + KMER - 1; l++, k++, i--)
			{
				map_val = map_value(read.at(l));
				if(map_val == -1)
					break;

				hash_key += base_power_kmer[i][map_val];
			
				//cout << "For character " << read.at(k) << ", at position = " << k <<
				//	", the hash_key = " << hash_key << endl;
			}
		}	

		map_val = map_value(read.at(k));
		if(map_val == -1)
		{
			//cout << "Encountered invalid character N ########################" << endl;
			flag = true;
			hash_key = 0;
			continue;
		}
		else
			flag = false;

		hash_key = hash_key * BASE + map_val;
		/*	
		if(kmer_map.find(hash_key) == kmer_map.end())
		{
			kmer_map[hash_key] = 1;//k - KMER + 1;
			kmer_list.push_back(make_pair(hash_key, k - KMER + 1));
		}
		else
		{
			kmer_map[hash_key] += 1;//-1;//need work here
		
			if(kmer_list[kmer_list.size() - 1].first != hash_key)
				kmer_list.push_back(make_pair(hash_key, k - KMER + 1));
			else
				kmer_list[kmer_list.size() - 1].second = k - KMER + 1;
			
		}
		//cout << "For character " << read.at(k) << ", at position = " << k <<
		//		", the hash_key = " << hash_key << endl;
	 	*/
	 	if(prehashval != hash_key)
		{
                	kmer_list.push_back(make_pair(hash_key, k - KMER + 1));
			prehashval = hash_key;
			prehashcnt = 1;
		}
		else
		{
			if(prehashcnt > 2)//suppress same character repeat
                                kmer_list[kmer_list.size() - 1].second = k - KMER + 1;
			else
				kmer_list.push_back(make_pair(hash_key, k - KMER + 1));

			prehashcnt += 1;
		}
		
		map_val = map_value(read.at(k - KMER + 1));
		hash_key -= base_power_kmer[KMER - 1][map_val];
	}

	{
		cout << "Starting KMER Chain Analysis for " << dir << endl;
		vector<vector<pair<int, int> > > kmer_index;
		for(int i = 0; i < refindex.size(); i++)
		{
			vector<pair<int, int> > kmer_pair;
			kmer_index.push_back(kmer_pair);
		}

		int interval = 1, index, reflen;
		int kmer_ref_loc, kmer_read_loc;

		for(int k = 0; k < kmer_list.size(); k++)
		{
			if(basic_index.index[kmer_list[k].first] == -1)
				continue;
			//vector<int> pos = basic_index.position[basic_index.index[kmer_list[k].first]];
			int ref_location;
			//for(int i = 0; i < pos.size(); i++)
			for(vector<int>::iterator it = basic_index.position[basic_index.index[kmer_list[k].first]].begin(); 
				it != basic_index.position[basic_index.index[kmer_list[k].first]].end(); ++it) 
			{
				ref_location = *it;
				if(ref_location < 0)//if(pos[i] < 0)
				{
					index = abs(ref_location) - 1;//abs(pos[i]) - 1;
					reflen = refindex[index].ref.length();
					continue;
				}
				kmer_ref_loc = ref_location;// pos[i];
				kmer_read_loc = kmer_list[k].second;
				if(CIRCULAR == 0 || kmer_ref_loc - kmer_read_loc / 1.3 >= 0 &&
					kmer_ref_loc + (readlen - kmer_read_loc) / 1.3 < reflen)
				{
					//cout << "index = " << index << endl;
					//assert(index >= 0 && index < refindex.size());
					kmer_index[index].push_back(make_pair(kmer_ref_loc, kmer_read_loc));
				}
			}
		}

		for(int index = 0; index < refindex.size(); index++)
		{
			if(kmer_index[index].size() == 0)
				continue;
			sort(kmer_index[index].begin(), kmer_index[index].end(), compare_function);
			/*for(int i = 0; i < kmer_index[index].size(); i++)
			{
				cout << "first = " << kmer_index[index][i].first << ", and second = " << kmer_index[index][i].second << endl;
			}*/
			refine_kmer_index(kmer_index[index], primary_chain, read, dir, refindex, index);
			kmer_index[index].clear();
		}
	}

	if(SINGLE == 1)
	{
		kmer_list.clear();
		return;
	}

	{
		cout << "Starting Reverse Analysis for " << FR << endl;
		vector<vector<pair<int, int> > > kmer_index;
		kmer_index.clear();
		for(int i = 0; i < refindex.size(); i++)
		{
			vector<pair<int, int> > kmer_pair;
			kmer_index.push_back(kmer_pair);
		}

		int interval = 1, index, reflen;
		int kmer_ref_loc, kmer_read_loc;

		for(int k = 0; k < kmer_list.size(); k++)
		{
			if(basic_index.revind[kmer_list[k].first] == -1)
				continue;
			//vector<int> pos = basic_index.position[basic_index.revind[kmer_list[k].first]];
			int ref_location;
			//for(int i = 0; i < pos.size(); i++)
			for(vector<int>::iterator it = basic_index.position[basic_index.revind[kmer_list[k].first]].begin();
                                it != basic_index.position[basic_index.revind[kmer_list[k].first]].end(); ++it)
			{
				ref_location = *it;
				if(ref_location < 0)//if(pos[i] < 0)
				{
					index = abs(ref_location) - 1;//index = abs(pos[i]) - 1;
					reflen = refindex[index].rev.length();
					continue;
				}
				kmer_ref_loc = reflen - KMER - ref_location;
				//kmer_ref_loc = reflen - KMER - pos[i];
				kmer_read_loc = readlen - KMER - kmer_list[k].second;
				if(CIRCULAR == 0 || kmer_ref_loc - kmer_read_loc / 1.3 >= 0 &&
					kmer_ref_loc + (readlen - kmer_read_loc) / 1.3 < reflen)
				{
					//cout << "index = " << index << endl;
					//assert(index >= 0 && index < refindex.size());
					kmer_index[index].push_back(make_pair(kmer_ref_loc, kmer_read_loc));
				}
			}
		}

		for(int index = 0; index < refindex.size(); index++)
		{
			if(kmer_index[index].size() == 0)
				continue;
			sort(kmer_index[index].begin(), kmer_index[index].end(), compare_function);
			/*for(int i = 0; i < kmer_index[index].size(); i++)
			{
				cout << "first = " << kmer_index[index][i].first << ", and second = " << kmer_index[index][i].second << endl;
			}*/
			refine_kmer_index(kmer_index[index], primary_chain, read, FR, refindex, index);
			kmer_index[index].clear();
		}
	}



	time(&end);
	//cout << "Total time taken inside read_vs_reference = " << difftime(end, start) << endl;
	//cout << "size of the candidate idices = " << primary_chain.size() << endl << endl;

	//kmer_map.clear();	
	kmer_list.clear();
	
	return;
}