Exemplo n.º 1
0
int Octree::findNearestColor(const Octree* octree, RGBAPixel color) {
	assert(octree != nullptr);

	uint8_t red = rgba_red(color);
	uint8_t green = rgba_green(color);
	uint8_t blue = rgba_blue(color);
	uint8_t alpha = rgba_alpha(color);

	const Octree* node = octree;
	for (int i = 7; i >= 8 - OCTREE_COLOR_BITS; i--) {
		if (node->hasColor())
			break;
		int index = (nth_bit(red, i) << 3) | (nth_bit(green, i) << 2) | nth_bit(blue, i) << 1 | nth_bit(alpha, i);
		if (node->hasChildren(index))
			node = node->getChildren(index);
		else
			break;
	}

	if (node->hasColor())
		return node->getColorID();
	auto& colors = node->subtree_colors;
	int min_distance = -1;
	int best_color = -1;
	for (auto it = colors.begin(); it != colors.end(); ++it) {
		int distance = rgba_distance2(color, it->second);
		if (best_color == -1 || distance < min_distance) {
			min_distance = distance;
			best_color = it->first;
		}
	}
	// this shouldn't happen if all the colors are cached
	assert(best_color != -1);
	return best_color;
}
Exemplo n.º 2
0
Octree* Octree::findOrCreateNode(Octree* octree, RGBAPixel color) {
	assert(octree != nullptr);

	uint8_t red = rgba_red(color);
	uint8_t green = rgba_green(color);
	uint8_t blue = rgba_blue(color);
	uint8_t alpha = rgba_alpha(color);

	Octree* node = octree;
	for (int i = 7; i >= 8 - OCTREE_COLOR_BITS; i--) {
		int index = (nth_bit(red, i) << 3) | (nth_bit(green, i) << 2) | nth_bit(blue, i) << 1 | nth_bit(alpha, i);
		node = node->getChildren(index);
		assert(node != nullptr);
	}
	return node;
}
void c1_AllocTable::init_tables () {
  for (int rnr = 0; rnr < nofRegs; rnr++) {
    _reg_mask[rnr] = nth_bit(rnr);
  }

  _free_reg[0] = FrameMap::cpu_reg2rnr(FrameMap::first_register()); // if all free use esi
  _free_reg[nofRegsExp2 - 1] = nofRegs;
  for (int i = 1; i < nofRegsExp2; i++) {
    for (int r = 0; r < nofRegs; r++) {
      if (!is_set_nth_bit(i, r)) {
        _free_reg[i] = r; break;
      }
    }
  }
}
Exemplo n.º 4
0
  T modular_exponentation(T a, T b, T n)
  {
    T c = 0;
    T d = 1;
    
    for(int i = (sizeof(T)*8) - 1; i >= 0; i--){	
      c = 2*c;
      d = (d * d) % n;
      
      if(nth_bit(b, i)){
	c = c + 1;
	d = (d * a) % n;
      }
    }
    
    return d;
  }
Exemplo n.º 5
0
inline bool is_set_nth_bit(intptr_t  x, int n) { return mask_bits (x, nth_bit(n)) != NoBits; }
Exemplo n.º 6
0
inline void  clear_nth_bit(intptr_t& x, int n) { clear_bits(x, nth_bit(n)); }
Exemplo n.º 7
0
// bit-operations using the n.th bit
inline void    set_nth_bit(intptr_t& x, int n) { set_bits  (x, nth_bit(n)); }
Exemplo n.º 8
0
 */

#ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP
#define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP

#include "gc_implementation/concurrentMarkSweep/freeChunk.hpp"
#include "memory/allocation.hpp"

// Forward declarations
class CompactibleFreeListSpace;

class PromotedObject VALUE_OBJ_CLASS_SPEC {
private:
    enum {
        promoted_mask  = right_n_bits(2),   // i.e. 0x3
        displaced_mark = nth_bit(2),        // i.e. 0x4
        next_mask      = ~(right_n_bits(3)) // i.e. ~(0x7)
    };

    // Below, we want _narrow_next in the "higher" 32 bit slot,
    // whose position will depend on endian-ness of the platform.
    // This is so that there is no interference with the
    // cms_free_bit occupying bit position 7 (lsb == 0)
    // when we are using compressed oops; see FreeChunk::is_free().
    // We cannot move the cms_free_bit down because currently
    // biased locking code assumes that age bits are contiguous
    // with the lock bits. Even if that assumption were relaxed,
    // the least position we could move this bit to would be
    // to bit position 3, which would require 16 byte alignment.
    typedef struct {
#ifdef VM_LITTLE_ENDIAN
Exemplo n.º 9
0
// Implementation notes: For space reasons, state & counter are both encoded in one word,
// The state is encoded using some of the least significant bits, the counter is using the
// more significant bits. The counter is incremented before a method is activated and an
// action is triggered when when count() > limit().

class InvocationCounter VALUE_OBJ_CLASS_SPEC {
    friend class VMStructs;
private:                             // bit no: |31  3|  2  | 1 0 |
    unsigned int _counter;              // format: [count|carry|state]

    enum PrivateConstants {
        number_of_state_bits = 2,
        number_of_carry_bits = 1,
        number_of_noncount_bits = number_of_state_bits + number_of_carry_bits,
        number_of_count_bits = BitsPerInt - number_of_noncount_bits,
        state_limit          = nth_bit(number_of_state_bits),
        count_grain          = nth_bit(number_of_state_bits + number_of_carry_bits),
        carry_mask           = right_n_bits(number_of_carry_bits) << number_of_state_bits,
        state_mask           = right_n_bits(number_of_state_bits),
        status_mask          = right_n_bits(number_of_state_bits + number_of_carry_bits),
        count_mask           = ((int)(-1) ^ status_mask)
    };

public:
    static int InterpreterInvocationLimit;        // CompileThreshold scaled for interpreter use
    static int InterpreterBackwardBranchLimit;    // A separate threshold for on stack replacement
    static int InterpreterProfileLimit;           // Profiling threshold scaled for interpreter use

    typedef address (*Action)(methodHandle method, TRAPS);

    enum PublicConstants {
void c1_AllocTable::init_tables () {
  for (int i = 0; i < max; i++) {
    _reg_mask[i] = nth_bit(i);
  }
}
Exemplo n.º 11
0
int main(int argc, char **argv) {
  long t;
  long bit_count;
  long out_lines;
  long line, bitno;

  if ((argc != 3) || (sscanf(argv[1], "%d", &width)) != 1) {
    printf("Usage: %s WIDTH FILE\n", argv[0]);
    exit(0);
  }
  fp = fopen(argv[2], "r");
  if (fp == NULL) {
    printf("Could not open file '%s'!\n", argv[2]);
    exit(1);
  }
  fseek(fp, 0L, SEEK_END);
  bytes = ftell(fp);
  fseek(fp, 0L, SEEK_SET);

  if ((buffer = (char *)malloc(bytes+1)) == NULL) {
    printf("Out of memory!\n");
    exit(1);
  }

  if (fread(buffer, bytes, 1, fp) != 1) {
    printf("Error reading input file!\n");
    exit(1);    
  }
  fclose(fp);

  bit_count = 8*bytes;
  t = out_lines = (bit_count/width) + (bit_count%width);
  for (addr_bits = 0; t; addr_bits++) t >>= 1;

  printf("module rom(clk, address, data);\n"
	 "   input wire clk;\n"
	 "   output reg [%d:0] data;\n"
	 "   input [%d:0] address;\n"
	 "   reg [%d:0] addr_reg;\n\n"
	 "   always @(posedge clk)\n"
	 "      addr_reg <= address;\n\n"
	 "   always @*\n"
	 "     begin\n"
	 "        case (addr_reg)\n", width-1, addr_bits-1, addr_bits-1);

  for (line = 0; line < out_lines; line++) {
    printf("    	  %d'd%ld : data = %d'b", addr_bits, line, width);
    for (bitno = 0; bitno < width; bitno++) {
      if (nth_bit((line*width)+bitno)) {
	printf("1");
      } else {
	printf("0");
      }
    }
    printf(";\n");
  }
  
  printf("    	  default : data = %d'b0;\n"
	 "        endcase\n"
	 "     end\n"
	 "endmodule\n", width);
  
  return 0;
}
Exemplo n.º 12
0
 bool has_annotation(ID id) { return (nth_bit((int)id) & _annotations_present) != 0; }
Exemplo n.º 13
0
 // Set the annotation name:
 void set_annotation(ID id) {
   assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
   _annotations_present |= nth_bit((int)id);
 }