Example #1
0
static void
texture_tower_create_texture (MetaTextureTower *tower,
                              int               level,
                              int               width,
                              int               height)
{
  if ((!is_power_of_two (width) || !is_power_of_two (height)) &&
      meta_texture_rectangle_check (tower->textures[level - 1]))
    {
      tower->textures[level] =
        meta_texture_rectangle_new (width, height,
                                    /* data format */
                                    TEXTURE_FORMAT,
                                    /* rowstride */
                                    width * 4,
                                    /* data */
                                    NULL);
    }
  else
    {
      tower->textures[level] = cogl_texture_new_with_size (width, height,
                                                           COGL_TEXTURE_NO_AUTO_MIPMAP,
                                                           TEXTURE_FORMAT);
    }

  tower->invalid[level].x1 = 0;
  tower->invalid[level].y1 = 0;
  tower->invalid[level].x2 = width;
  tower->invalid[level].y2 = height;
}
Example #2
0
int hash_verify(hash_t *hash)
{
    hashcount_t count = 0;
    hash_val_t chain;
    hnode_t *hptr;

    if (hash->dynamic) {    /* 1 */
        if (hash->lowmark >= hash->highmark)
            return 0;
        if (!is_power_of_two(hash->highmark))
            return 0;
        if (!is_power_of_two(hash->lowmark))
            return 0;
    }

    for (chain = 0; chain < hash->nchains; chain++) {   /* 2 */
        for (hptr = hash->table[chain]; hptr != NULL; hptr = hptr->next) {
            if ((hptr->hkey & hash->mask) != chain)
                return 0;
            count++;
        }
    }

    if (count != hash->nodecount)
        return 0;

    return 1;
}
Example #3
0
static void
texture_tower_create_texture (MetaTextureTower *tower,
                              int               level,
                              int               width,
                              int               height)
{
  if ((!is_power_of_two (width) || !is_power_of_two (height)) &&
      meta_texture_rectangle_check (tower->textures[level - 1]))
    {
      ClutterBackend *backend = clutter_get_default_backend ();
      CoglContext *context = clutter_backend_get_cogl_context (backend);

      tower->textures[level] = cogl_texture_rectangle_new_with_size (context, width, height);
    }
  else
    {
      tower->textures[level] = cogl_texture_new_with_size (width, height,
                                                           COGL_TEXTURE_NO_AUTO_MIPMAP,
                                                           TEXTURE_FORMAT);
    }

  tower->invalid[level].x1 = 0;
  tower->invalid[level].y1 = 0;
  tower->invalid[level].x2 = width;
  tower->invalid[level].y2 = height;
}
Example #4
0
bool supports_mipmaps_for(Size size)
{
#if GLLIB_GLES
	return is_power_of_two(size.x) && is_power_of_two(size.y);
#else
	(void)size;
	return true;
#endif
}
Example #5
0
/*
 * Extend the table: make it twice as large.
 */
static void stbl_extend(stbl_t *sym_table) {
  stbl_rec_t **tmp;
  stbl_rec_t *list;
  uint32_t i, n, old_size, mask;

  old_size = sym_table->size;
  n = old_size << 1;
  if (n == 0 || n >= MAX_STBL_SIZE) {
    // overflow: cannot expand 
    out_of_memory();
  }

  assert(is_power_of_two(n));

  // new data array
  tmp = (stbl_rec_t **) safe_malloc(n * sizeof(stbl_rec_t *));
  for (i=0; i<n; i++) {
    tmp[i] = NULL;
  }

  // move the data lists to tmp
  mask = n-1;
  for (i=0; i<old_size; i++) {
    list = sym_table->data[i];
    if (list != NULL) {
      stbl_restore_list(tmp, mask, list);
    }
  }

  // clean up
  safe_free(sym_table->data);
  sym_table->data = tmp;
  sym_table->size = n;
}
Example #6
0
/**
 *
 * @brief Set the number of priority groups based on the number of exception
 * priorities desired
 *
 * Exception priorities can be divided in priority groups, inside which there is
 * no preemption. The priorities inside a group are only used to decide which
 * exception will run when more than one is ready to be handled.
 *
 * The number of priorities has to be a power of two, from 1 to 128.
 *
 * @param n the number of priorities
 *
 * @return N/A
 */
void _ScbNumPriGroupSet(unsigned int n)
{
	unsigned int set;
	union __aircr reg;

	__ASSERT(is_power_of_two(n) && (n <= 128),
		 "invalid number of priorities");

	set = find_lsb_set(n);

	reg.val = __scs.scb.aircr.val;

	/* num pri    bit set   prigroup
	 * ---------------------------------
	 *      1        1          7
	 *      2        2          6
	 *      4        3          5
	 *      8        4          4
	 *     16        5          3
	 *     32        6          2
	 *     64        7          1
	 *    128        8          0
	 */

	reg.bit.prigroup = 8 - set;
	reg.bit.vectkey = SCB_AIRCR_VECTKEY_EN_W;

	__scs.scb.aircr.val = reg.val;
}
Example #7
0
/*
 * Initialize: empty table of size n. n must be a power of 2.
 * If n = 0, the default size is used.
 */
void init_stbl(stbl_t *sym_table, uint32_t n) {
  uint32_t i;
  stbl_rec_t **tmp;

  if (n == 0) {
    n = STBL_DEFAULT_SIZE;
  }

  if (n >= MAX_STBL_SIZE) {    
    out_of_memory(); // abort if too large
  }

  assert(is_power_of_two(n));

  tmp = (stbl_rec_t**) safe_malloc(n * sizeof(stbl_rec_t *));
  for (i=0; i<n; i++) {
    tmp[i] = NULL;
  }

  sym_table->size = n;
  sym_table->nelems = 0;
  sym_table->ndeleted = 0;
  sym_table->bnk = NULL;
  sym_table->free_idx = 0;
  sym_table->free_rec = NULL;
  sym_table->data = tmp;
  sym_table->finalize = default_stbl_finalizer;
}
Example #8
0
static uint64_t ivshmem_get_size(IVShmemState * s) {

    uint64_t value;
    char *ptr;

    value = strtoull(s->sizearg, &ptr, 10);
    switch (*ptr) {
        case 0: case 'M': case 'm':
            value <<= 20;
            break;
        case 'G': case 'g':
            value <<= 30;
            break;
        default:
            fprintf(stderr, "qemu: invalid ram size: %s\n", s->sizearg);
            exit(1);
    }

    /* BARs must be a power of 2 */
    if (!is_power_of_two(value)) {
        fprintf(stderr, "ivshmem: size must be power of 2\n");
        exit(1);
    }

    return value;
}
Example #9
0
int rs_rb_init(struct rs_rb *rb, void *buffer, size_t size)
{
	/*
	 * this initialization is absurd, but it is to silence gcc which issues
	 * a warning because it isn't smart enough to see that page_size is
	 * initialized AND used iif rb->mirror is true
	 */
	long page_size = 0;

	if (rb == NULL)
		return -EINVAL;
	rb->mirror = buffer == NULL;
	if (rb->mirror) {
		/* augment size to the next multiple of page size */
		page_size = sysconf(_SC_PAGE_SIZE);
		if ((size % page_size) != 0)
			size = ((size / page_size) + 1) * page_size;
	}

	if (!is_power_of_two(size))
		return -EINVAL;

	rb->base = buffer;
	rb->size = size;
	rb->size_mask = size - 1;
	rb->read = 0;
	rb->write = 0;
	rb->len = 0;

	if (rb->mirror)
		return allocate_mirrored_buffer(rb, size, page_size);

	return 0;
}
Example #10
0
// Returns the pointer to the Enclave instance on success.
uintptr_t _ECREATE(page_info_t* pi)
{
    secs_t* secs = reinterpret_cast<secs_t*>(pi->src_page);

    // Enclave size must be at least 2 pages and a power of 2.
    GP_ON(!is_power_of_two((size_t)secs->size));
    GP_ON(secs->size < (SE_PAGE_SIZE << 1));

    CEnclaveSim* ce = new CEnclaveSim(secs);
    void*   addr;

    // `ce' is not checked against NULL, since it is not
    // allocated with new(std::no_throw).
    addr = se_virtual_alloc(NULL, (size_t)secs->size, MEM_COMMIT);
    if (addr == NULL) {
        delete ce;
        return 0;
    }

    // Mark all the memory inaccessible.
    se_virtual_protect(addr, (size_t)secs->size, SGX_PROT_NONE);
    ce->get_secs()->base = addr;

    CEnclaveMngr::get_instance()->add(ce);
    return reinterpret_cast<uintptr_t>(ce);
}
Example #11
0
/*
 * Initialization:
 * - n = initial size (must be a power of 2)
 * - if n = 0, the default size is used
 */
void init_strmap(strmap_t *hmap, uint32_t n) {
  strmap_rec_t *tmp;
  uint32_t i;

  if (n == 0) {
    n = STRMAP_DEF_SIZE;
  }

  if (n >= STRMAP_MAX_SIZE) {
    out_of_memory();
  }

  assert(is_power_of_two(n));
  tmp = (strmap_rec_t *) safe_malloc(n * sizeof(strmap_rec_t));
  for (i=0; i<n; i++) {
    tmp[i].key = NULL;
  }

  hmap->data = tmp;
  hmap->size = n;
  hmap->nelems = 0;
  hmap->ndeleted = 0;

  hmap->resize_threshold = (uint32_t) (n * STRMAP_RESIZE_RATIO);
  hmap->cleanup_threshold = (uint32_t) (n * STRMAP_CLEANUP_RATIO);
}
Example #12
0
static hash_val_t compute_mask(hashcount_t size)
{
    assert (is_power_of_two(size));
    assert (size >= 2);

    return size - 1;
}
Example #13
0
void Texture::set_wrap_mode(WrapMode s, WrapMode t)
{
	NAME_PAINT_FUNCTION();

	// How to map WrapModes to GL.
	auto translate_mode = [](WrapMode mode)
	{
		if (mode == WrapMode::Mirror) {
			return GL_MIRRORED_REPEAT;
		} else if (mode == WrapMode::Repeat) {
			return GL_REPEAT;
		} else {
			return GL_CLAMP_TO_EDGE;
		}
	};

#if GLLIB_GLES
	// See Section 3.8.7 Texture Completeness in OpenGl ES 2.0 spec.
	if (!is_power_of_two()) {
		assert(s==WrapMode::Clamp && t==WrapMode::Clamp);
	}
#endif

	bind();
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, translate_mode(s));
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, translate_mode(t));
}
int gr_opengl_bm_make_render_target(int n, int *width, int *height, ubyte *bpp, int *mm_lvl, int flags)
{
	Assert( (n >= 0) && (n < MAX_BITMAPS) );

	if ( !Is_Extension_Enabled(OGL_EXT_FRAMEBUFFER_OBJECT) || Cmdline_no_fbo ) {
		return 0;
	}

	if ( (flags & BMP_FLAG_CUBEMAP) && !Is_Extension_Enabled(OGL_ARB_TEXTURE_CUBE_MAP) ) {
		return 0;
	}

	if ( (flags & BMP_FLAG_CUBEMAP) && (*width != *height) ) {
		MIN(*width, *height) = MAX(*width, *height);
	}

	// Only enforce power of two size if not supported
	if (!(Is_Extension_Enabled(OGL_ARB_TEXTURE_NON_POWER_OF_TWO)))
	{
		Assert( is_power_of_two(*width, *height) );
	}

	if ( opengl_make_render_target(bm_bitmaps[n].handle, n, width, height, bpp, mm_lvl, flags) ) {
		return 1;
	}

	return 0;
}
Example #15
0
pa_shmasyncq *pa_shmasyncq_new(unsigned n_elements, size_t element_size, void *data, int fd[2]) {
    pa_shmasyncq *l;

    pa_assert(n_elements > 0);
    pa_assert(is_power_of_two(n_elements));
    pa_assert(element_size > 0);
    pa_assert(data);
    pa_assert(fd);

    l = pa_xnew(pa_shmasyncq, 1);

    l->data = data;
    memset(data, 0, PA_SHMASYNCQ_SIZE(n_elements, element_size));

    l->data->n_elements = n_elements;
    l->data->element_size = element_size;

    if (!(l->read_fdsem = pa_fdsem_new_shm(&d->read_fdsem_data))) {
        pa_xfree(l);
        return NULL;
    }
    fd[0] = pa_fdsem_get(l->read_fdsem);

    if (!(l->write_fdsem = pa_fdsem_new(&d->write_fdsem_data, &fd[1]))) {
        pa_fdsem_free(l->read_fdsem);
        pa_xfree(l);
        return NULL;
    }

    return l;
}
Example #16
0
void emit_math1(struct brw_wm_compile *c,
		GLuint function,
		const struct brw_reg *dst,
		GLuint mask,
		const struct brw_reg *arg0)
{
   struct brw_compile *p = &c->func;
   struct intel_context *intel = &p->brw->intel;
   int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1;
   GLuint saturate = ((mask & SATURATE) ?
		      BRW_MATH_SATURATE_SATURATE :
		      BRW_MATH_SATURATE_NONE);
   struct brw_reg src;

   if (!(mask & WRITEMASK_XYZW))
      return; /* Do not emit dead code */

   assert(is_power_of_two(mask & WRITEMASK_XYZW));

   if (intel->gen >= 6 && ((arg0[0].hstride == BRW_HORIZONTAL_STRIDE_0 ||
			    arg0[0].file != BRW_GENERAL_REGISTER_FILE) ||
			   arg0[0].negate || arg0[0].abs)) {
      /* Gen6 math requires that source and dst horizontal stride be 1,
       * and that the argument be in the GRF.
       *
       * The hardware ignores source modifiers (negate and abs) on math
       * instructions, so we also move to a temp to set those up.
       */
      src = dst[dst_chan];
      brw_MOV(p, src, arg0[0]);
   } else {
      src = arg0[0];
   }

   /* Send two messages to perform all 16 operations:
    */
   brw_push_insn_state(p);
   brw_set_compression_control(p, BRW_COMPRESSION_NONE);
   brw_math(p,
	    dst[dst_chan],
	    function,
	    saturate,
	    2,
	    src,
	    BRW_MATH_DATA_VECTOR,
	    BRW_MATH_PRECISION_FULL);

   if (c->dispatch_width == 16) {
      brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
      brw_math(p,
	       offset(dst[dst_chan],1),
	       function,
	       saturate,
	       3,
	       sechalf(src),
	       BRW_MATH_DATA_VECTOR,
	       BRW_MATH_PRECISION_FULL);
   }
   brw_pop_insn_state(p);
}
Example #17
0
static VALUE
ffts_plan_initialize(VALUE self, VALUE rb_frames, VALUE rb_sign) {
  ffts_plan_t *plan;

  size_t n = RARRAY_LEN(rb_frames);
  if (!is_power_of_two(n)) {
    rb_raise(rb_eRuntimeError, "Frames must be a power of 2.");
    return Qnil;
  }

  int sign_v = NUM2INT(rb_sign);
  if (sign_v != -1 && sign_v != 1) {
    rb_raise(rb_eRuntimeError, "Sign must be 1 or -1.");
    return Qnil;
  }

  plan = ffts_init_1d(n, sign_v);

  VALUE rb_plan = Data_Wrap_Struct(cCPlan, NULL, ffts_free, plan);

  rb_funcall(self, rb_intern("n="), 1, INT2NUM(n));
  rb_funcall(self, rb_intern("frames="), 1, rb_frames);
  rb_funcall(self, rb_intern("sign="), 1, rb_sign);
  rb_funcall(self, rb_intern("plan="), 1, rb_plan);

  return self;
}
Example #18
0
bool cePatchMeshGL20::CreatePatches(iDevice *device, unsigned numP, unsigned numQ, bool wrapP, bool wrapQ)
{
  unsigned testP = _numP - 1;
  unsigned testQ = _numQ - 1;
  // check whether the number of vertices is at least dividable by the number
  // of patches we want
  if (testP % numP) return false;
  if (testQ % numQ) return false;

  unsigned numPerPatchP = testP / numP;
  unsigned numPerPatchQ = testQ / numQ;

  // check if the number of vertices per patch is of power of two
  if (!is_power_of_two(numPerPatchP)) return false;
  if (!is_power_of_two(numPerPatchQ)) return false;

  _wrapP = wrapP;
  _wrapQ = wrapQ;
  _numPatchP = numP;
  _numPatchQ = numQ;
  _patches.clear ();
  for (unsigned q=0; q<numQ; q++)
    {
      unsigned offsetQ = q * numPerPatchQ * _numP;
      for (unsigned p=0; p<numP; p++)
        {
          unsigned offset = offsetQ + (p * numPerPatchP);
          Patch* patch = CreatePatch(device, offset, numPerPatchP+1, numPerPatchQ+1);
          _patches.push_back (patch);
        }
    }

  for (int q=0; q<numQ; q++)
    {
      for (int p=0; p<numP; p++)
        {
          Patch* patch = GetPatch(p, q);
          patch->neighbours[PN_NegP] = GetPatch(p-1, q  , wrapP, wrapQ);
          patch->neighbours[PN_NegQ] = GetPatch(p  , q-1, wrapP, wrapQ);
          patch->neighbours[PN_PosP] = GetPatch(p+1, q  , wrapP, wrapQ);
          patch->neighbours[PN_PosQ] = GetPatch(p  , q+1, wrapP, wrapQ);
        }
    }
  _dirty = true;
  return true;
}
int main() {
	int i = 1;
	while( ++i < 10000000 )
	{
		if( is_power_of_two( i ) ) 
			printf("%d\n",i);
	}
}
Example #20
0
/*
	setup a textbox for rendering text
*/
static TextBox *do_render_text(float x, float y, char *str, TextColor color, int flags) {
TextBox *box;

	if ((box = new_TextBox()) == NULL)
		return NULL;

	if (str != NULL && *str) {
		if ((box->str = strdup(str)) == NULL) {
			destroy_TextBox(box);
			return NULL;
		}
	} else
		box->str = NULL;

	box->x = x;
	box->y = y;

	box->color = color;
	box->flags = flags;

	if (str != NULL && *str)
		box->w = text_width_bitfont(str, box->flags);
	else
		box->w = FONT_W;

	box->h = font_height+FONT_LINING;		/* blit_text() adds black lining */

/* ensure power of two for textures */
	if (!is_power_of_two(box->w))
		box->w = next_power_of_two(box->w);

	if (!is_power_of_two(box->h))
		box->h = next_power_of_two(box->h);

	if (box->w > TEXT_TILE_W)
		box->w = TEXT_TILE_W;

	if (box->h > TEXT_TILE_H)
		box->h = TEXT_TILE_H;

	mktexture_textbox(box);
	return box;
}
Example #21
0
static void hash_table_init(struct hash_table* ht, hash_fn_t hash_fn, eql_fn_t eql_fn, size_t capacity)
{
    ht->size     = 0;
    ht->capacity = capacity;
    ht->hash_fn  = hash_fn;
    ht->eql_fn   = eql_fn;
    ht->table    = calloc(ht->capacity, sizeof(*ht->table));
    ht->hashes   = calloc(ht->capacity, sizeof(*ht->hashes));
    assert(is_power_of_two(ht->capacity));
}
Example #22
0
void TestUtilities::testIsPowerOfTwo()
{
	UASSERT(is_power_of_two(0) == false);
	UASSERT(is_power_of_two(1) == true);
	UASSERT(is_power_of_two(2) == true);
	UASSERT(is_power_of_two(3) == false);
	for (int exponent = 2; exponent <= 31; ++exponent) {
		UASSERT(is_power_of_two((1 << exponent) - 1) == false);
		UASSERT(is_power_of_two((1 << exponent)) == true);
		UASSERT(is_power_of_two((1 << exponent) + 1) == false);
	}
	UASSERT(is_power_of_two(U32_MAX) == false);
}
static void* stack_alloc(WasmAllocator* allocator,
                         size_t size,
                         size_t align,
                         const char* file,
                         int line) {
  WasmStackAllocator* stack_allocator = (WasmStackAllocator*)allocator;
  assert(is_power_of_two(align));
  WasmStackAllocatorChunk* chunk = stack_allocator->last;
  assert(size < SIZE_MAX - align + 1);
  size_t alloc_size = size + align - 1;
  void* result;
  if (alloc_size >= CHUNK_MAX_AVAIL) {
    chunk = allocate_chunk(stack_allocator, alloc_size, file, line);
    result = align_up(chunk->current, align);
    assert((void*)((intptr_t)result + size) <= chunk->end);
    chunk->current = chunk->end;
    /* thread this chunk before first. There's no available space, so it's not
     worth considering. */
    stack_allocator->first->prev = chunk;
    stack_allocator->first = chunk;
  } else {
    assert(chunk);

    chunk->current = align_up(chunk->current, align);
    void* new_current = (void*)((intptr_t)chunk->current + size);
    if (new_current < chunk->end) {
      result = chunk->current;
      chunk->current = new_current;
    } else {
      chunk = allocate_chunk(stack_allocator, CHUNK_MAX_AVAIL, file, line);
      chunk->prev = stack_allocator->last;
      stack_allocator->last = chunk;
      chunk->current = align_up(chunk->current, align);
      result = chunk->current;
      chunk->current = (void*)((intptr_t)chunk->current + size);
      assert(chunk->current <= chunk->end);
    }

    stack_allocator->last_allocation = result;
  }

#if TRACE_ALLOCATOR
  if (file) {
    TRACEF("%s:%d: stack_alloc(%" PRIzd ", align=%" PRIzd ") => %p\n", file,
           line, size, align, result);
  }
#endif /* TRACE_ALLOCATOR */

#if WASM_STACK_ALLOCATOR_STATS
  stack_allocator->alloc_count++;
  stack_allocator->total_alloc_bytes += size;
#endif /* WASM_STACK_ALLOCATOR_STATS */
  return result;
}
Example #24
0
void xio_tcp_demux_init (xio_dmxinfo_t *dmxinfo, uint hashsize)
{
   int i;

   dmxinfo->hashsize = (hashsize) ? hashsize : XIO_TCP_DEMUX_HASHSIZE;
   assert (is_power_of_two (dmxinfo->hashsize));
   for (i=0; i<dmxinfo->hashsize; i++) {
      LIST_INIT (&dmxinfo->hashtable[i]);
   }
   LIST_INIT (&dmxinfo->listenlist);
   dmxinfo->numhashed = 0;
}
Example #25
0
void veb_tree_print(struct veb *veb)
{
    int i;
    for (i=0; i < (1 << veb->height) - 1; i++)
    {
        if (is_power_of_two(i+1))
            printf("\n");

        printf("%04d  ", node_at(veb, i+1)->key);
    }
    printf("\n");
}
Example #26
0
int
console_init(console_rx_cb rx_cb)
{
    struct console_tty *ct = &console_tty;
    struct uart_conf uc = {
        .uc_speed = MYNEWT_VAL(CONSOLE_BAUD),
        .uc_databits = 8,
        .uc_stopbits = 1,
        .uc_parity = UART_PARITY_NONE,
        .uc_flow_ctl = MYNEWT_VAL(CONSOLE_FLOW_CONTROL),
        .uc_tx_char = console_tx_char,
        .uc_rx_char = console_rx_char,
        .uc_cb_arg = ct
    };

    ct->ct_rx_cb = rx_cb;
    if (!ct->ct_dev) {
        ct->ct_tx.cr_size = MYNEWT_VAL(CONSOLE_TX_BUF_SIZE);
        ct->ct_tx.cr_buf = ct->ct_tx_buf;
        ct->ct_rx.cr_size = MYNEWT_VAL(CONSOLE_RX_BUF_SIZE);
        ct->ct_rx.cr_buf = ct->ct_rx_buf;
        ct->ct_write_char = console_queue_char;

        ct->ct_dev = (struct uart_dev *)os_dev_open(CONSOLE_UART,
          OS_TIMEOUT_NEVER, &uc);
        if (!ct->ct_dev) {
            return -1;
        }
        ct->ct_echo_off = ! MYNEWT_VAL(CONSOLE_ECHO);
    }

    /* must be a power of 2 */
    assert(is_power_of_two(MYNEWT_VAL(CONSOLE_RX_BUF_SIZE)));

#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
    console_hist_init();
#endif

    return 0;
}

void
console_pkg_init(void)
{
    int rc;

    /* Ensure this function only gets called by sysinit. */
    SYSINIT_ASSERT_ACTIVE();

    rc = console_init(NULL);
    SYSINIT_PANIC_ASSERT(rc == 0);
}
Example #27
0
        bool reduce_quantifier(
            quantifier * q,
            expr * old_body,
            expr * const * new_patterns,
            expr * const * new_no_patterns,
            expr_ref & result,
            proof_ref & result_pr) {

            if (q->get_kind() == lambda_k) return false;
            m_sorts.reset();
            expr_ref_vector bounds(m);
            bool found = false;
            for (unsigned i = 0; i < q->get_num_decls(); ++i) {
                sort* s = q->get_decl_sort(i);
                if (m_imp.is_fd(s)) {
                    unsigned bv_size = get_bv_size(s);
                    m_sorts.push_back(m_bv.mk_sort(bv_size));
                    unsigned nc = m_dt.get_datatype_num_constructors(s);
                    if (!is_power_of_two(nc) || nc == 1) {
                        bounds.push_back(m_bv.mk_ule(m.mk_var(q->get_num_decls()-i-1, m_sorts[i]), m_bv.mk_numeral(nc-1, bv_size)));
                    }                
                    found = true;
                }
                else {
                    m_sorts.push_back(s);
                }
            }
            if (!found) {
                return false;
            }
            expr_ref new_body_ref(old_body, m), tmp(m);
            if (!bounds.empty()) {
                switch (q->get_kind()) {
                case forall_k:
                    new_body_ref = m.mk_implies(mk_and(bounds), new_body_ref);
                    break;
                case exists_k:
                    bounds.push_back(new_body_ref);
                    new_body_ref = mk_and(bounds);
                    break;
                case lambda_k:
                    UNREACHABLE();
                    break;
                }
            }
            result = m.mk_quantifier(q->get_kind(), q->get_num_decls(), m_sorts.c_ptr(), q->get_decl_names(), new_body_ref, 
                                     q->get_weight(), q->get_qid(), q->get_skid(), 
                                     q->get_num_patterns(), new_patterns,
                                     q->get_num_no_patterns(), new_no_patterns);
            result_pr = nullptr;
            return true;
        }
Example #28
0
        bool reduce_arg(expr* a, expr_ref& result) {

            sort* s = get_sort(a);
            if (!m_imp.is_fd(s)) {
                return false;
            }
            unsigned bv_size = get_bv_size(s);

            if (is_var(a)) {
                result = m.mk_var(to_var(a)->get_idx(), m_bv.mk_sort(bv_size));
                return true;
            }
            SASSERT(is_app(a));
            func_decl* f = to_app(a)->get_decl();
            if (m_dt.is_constructor(f)) {
                unsigned idx = m_dt.get_constructor_idx(f);
                result = m_bv.mk_numeral(idx, bv_size);
            }
            else if (is_uninterp_const(a)) {
                func_decl* f_fresh;
                if (m_imp.m_enum2bv.find(f, f_fresh)) {
                    result = m.mk_const(f_fresh);
                    return true;
                }

                // create a fresh variable, add bounds constraints for it.
                unsigned nc = m_dt.get_datatype_num_constructors(s);
                result = m.mk_fresh_const(f->get_name().str().c_str(), m_bv.mk_sort(bv_size));
                f_fresh = to_app(result)->get_decl();
                if (!is_power_of_two(nc) || nc == 1) {
                    m_imp.m_bounds.push_back(m_bv.mk_ule(result, m_bv.mk_numeral(nc-1, bv_size)));
                }                
                expr_ref f_def(m);
                ptr_vector<func_decl> const& cs = *m_dt.get_datatype_constructors(s);
                f_def = m.mk_const(cs[nc-1]);
                for (unsigned i = nc - 1; i > 0; ) {
                    --i;
                    f_def = m.mk_ite(m.mk_eq(result, m_bv.mk_numeral(i,bv_size)), m.mk_const(cs[i]), f_def);
                }
                m_imp.m_enum2def.insert(f, f_def);
                m_imp.m_enum2bv.insert(f, f_fresh);
                m_imp.m_bv2enum.insert(f_fresh, f);
                m_imp.m_enum_consts.push_back(f);
                m_imp.m_enum_bvs.push_back(f_fresh);
                m_imp.m_enum_defs.push_back(f_def);
            }
            else {
                throw_non_fd(a);
            }
            ++m_imp.m_num_translated;
            return true;
        }
Example #29
0
	// Get closest extrusion mesh for given image dimensions
	// Caller must drop the returned pointer
	scene::IMesh* create(core::dimension2d<u32> dim)
	{
		// handle non-power of two textures inefficiently without cache
		if (!is_power_of_two(dim.Width) || !is_power_of_two(dim.Height)) {
			return createExtrusionMesh(dim.Width, dim.Height);
		}

		int maxdim = MYMAX(dim.Width, dim.Height);

		std::map<int, scene::IMesh*>::iterator
			it = m_extrusion_meshes.lower_bound(maxdim);

		if (it == m_extrusion_meshes.end()) {
			// no viable resolution found; use largest one
			it = m_extrusion_meshes.find(MAX_EXTRUSION_MESH_RESOLUTION);
			sanity_check(it != m_extrusion_meshes.end());
		}

		scene::IMesh *mesh = it->second;
		mesh->grab();
		return mesh;
	}
Example #30
0
void kat_init(kat_matrix_t **kat, int width, int height, int nnz, int sm_size) {

	/*
	 * XXX: be strict here. It's for testing purposes and we want to avoid
	 * edge cases.
	 */
	assert(width == height);
	assert(is_power_of_two(width));
	assert(is_power_of_two(sm_size));
	assert(is_power_of_two(KAT_N));

	*kat = calloc(1, sizeof(kat_matrix_t));
	assert(*kat != NULL);
	(*kat)->_.object_size += sizeof(kat_matrix_t);

	(*kat)->_.type = KAT;
	(*kat)->_.f = kat_vmt;
	(*kat)->_.w = width;
	(*kat)->_.h = height;

	(*kat)->sm_size = sm_size;
	(*kat)->_.nnz = nnz;

	(*kat)->root = NULL;

	/*
	 * This is not needed.
	 */
//	(*kat)->height =
//			ceil(
//					(log((width * height) / (sm_size * sm_size))
//							/ (double) log(KAT_K)));
//	printf("_kat init h=%d w=%d height=%d\n", width, height, (*kat)->height);
// not really
//	assert(width < sm_size * KAT_N);
//	_s_debugf(KAT_DEBUG,
//			"initializing kat_matrix_t with: n=%d, nnz=%d, sm_size=%d, height=%d\n",
//			width, nnz, sm_size, (*kat)->height);
}