Ejemplo n.º 1
0
/*
17.6.1.2212 SLITERAL
STRING
Interpretation: Interpretation semantics for this word are undefined.
Compilation: ( c-addr1 u -- )
Append the run-time semantics given below to the current definition.
Run-time: ( -- c-addr2 u )
Return c-addr2u describing a string consisting of the characters specified by c-addr1 u
during compilation. A program shall not alter the returned string.
See: A.17.6.112.0 SLITERAL.
*/
static void do_sliteral(void)
{
/*
: sliteral ( c-addr u -- )
	postpone ahead rot rot
	( save a pointer to the string at runtime)
	here >r
	( copy string to data space)
	2dup here swap cmove
	dup allot align
	rot postpone then
	( compile runtime string address)
	r> postpone literal
	( compile runtime string length)
	postpone literal
	drop ( c-addr)
	; immediate

: str s" sample string" ;
str type cr cr
: stest [ str ] sliteral ;
: stest [ str ] sliteral 1- swap 1+ swap ." string is:" cr cr type cr cr ;

 */
do_ahead(); do_rot(); do_rot();
do_here(); do_to_r();
do_two_dup(); do_here(); do_swap(); do_cmove();
do_dup(); do_allot(); do_align();
do_rot(); do_then();
do_r_from(); do_literal();
do_literal();
do_drop();

}
Ejemplo n.º 2
0
static void
epiphany_elf_section_text (int i)
{
  obj_elf_text (i);

  do_align (1, NULL, 0, 0);
  force_code_align = FALSE;
}
Ejemplo n.º 3
0
/**
 * Compute a permuation of the blocks to
 * minimize the cost of alignment.  Greedy packer.
 *
 * @param start starting position for the first block
 * @param count size of the two arrays
 * @param sizes the sizes of the individual blocks
 * @param perm the permutation of the blocks (updated)
 */
static void
block_align (size_t start, unsigned int count, const size_t * sizes,
             unsigned int *perm)
{
    unsigned int i;
    unsigned int j;
    unsigned int tmp;
    unsigned int best;
    ssize_t badness;
    size_t cpos;
    size_t cend;
    ssize_t cbad;
    unsigned int cval;

    cpos = start;
    for (i = 0; i < count; i++)
    {
        start = cpos;
        badness = 0x7FFFFFFF;
        best = -1;
        for (j = i; j < count; j++)
        {
            cval = perm[j];
            cend = cpos + sizes[cval];
            if (cpos % DBLOCK_SIZE == 0)
            {
                /* prefer placing the largest blocks first */
                cbad = -(cend % DBLOCK_SIZE);
            }
            else
            {
                if (cpos / DBLOCK_SIZE == cend / DBLOCK_SIZE)
                {
                    /* Data fits into the same block! Prefer small left-overs! */
                    cbad = DBLOCK_SIZE - cend % DBLOCK_SIZE;
                }
                else
                {
                    /* Would have to waste space to re-align, add big factor, this
                     * case is a real loss (proportional to space wasted)! */
                    cbad = DBLOCK_SIZE * (DBLOCK_SIZE - cpos % DBLOCK_SIZE);
                }
            }
            if (cbad < badness)
            {
                best = j;
                badness = cbad;
            }
        }
        GNUNET_assert (best != -1);
        tmp = perm[i];
        perm[i] = perm[best];
        perm[best] = tmp;
        cpos += sizes[perm[i]];
        cpos = do_align (start, cpos);
    }
}
Ejemplo n.º 4
0
/** 
 * <JA>
 * HMM状態ごとの forced alignment を行う(単語が逆順で与えられる場合)
 * 
 * @param revwords [in] 単語列(逆順)
 * @param num [in] @a revwords の単語数
 * @param param [in] 入力特徴ベクトル列
 * @param align [out] アラインメント結果を格納するSentence構造体
 * @param r [i/o] 認識処理インスタンス
 * </JA>
 * <EN>
 * Do forced alignment per state for the given word sequence (reversed order).
 * 
 * @param revwords [in] word sequence in reversed direction
 * @param num [in] length of @a revwords
 * @param param [in] input parameter vectors
 * @param align [out] Sentence data area to store the alignment result
 * @param r [i/o] recognition process instance
 * </EN>
 * @callgraph
 * @callergraph
 */
void
state_rev_align(WORD_ID *revwords, short num, HTK_Param *param, SentenceAlign *align, RecogProcess *r)
{
  WORD_ID *words;		/* word sequence (true order) */
  int p;
  words = (WORD_ID *)mymalloc(sizeof(WORD_ID) * num);
  for (p=0;p<num;p++) words[p] = revwords[num-p-1];
  do_align(words, num, param, PER_STATE, align, r);
  free(words);
}
Ejemplo n.º 5
0
/** 
 * <JA>
 * 単語ごとの forced alignment を行う(単語が逆順で与えられる場合)
 * 
 * @param revwords [in] 単語列(逆順)
 * @param wnum [in] @a revwords の単語数
 * @param param [in] 入力特徴ベクトル列
 * @param align [out] アラインメント結果を格納するSentence構造体
 * @param r [i/o] 認識処理インスタンス
 * </JA>
 * <EN>
 * Do forced alignment per word for the given word sequence (reversed order).
 * 
 * @param revwords [in] word sequence in reversed direction
 * @param wnum [in] length of @a revwords
 * @param param [in] input parameter vectors
 * @param align [out] Sentence data area to store the alignment result
 * @param r [i/o] recognition process instance
 * </EN>
 * @callgraph
 * @callergraph
 */
void
word_rev_align(WORD_ID *revwords, short wnum, HTK_Param *param, SentenceAlign *align, RecogProcess *r)
{
  WORD_ID *words;		/* word sequence (true order) */
  int w;
  words = (WORD_ID *)mymalloc(sizeof(WORD_ID) * wnum);
  for (w=0;w<wnum;w++) words[w] = revwords[wnum-w-1];
  do_align(words, wnum, param, PER_WORD, align, r);
  free(words);
}
Ejemplo n.º 6
0
static void
epiphany_elf_section_rtn (int i)
{
  obj_elf_section (i);

  if (force_code_align)
    {
      do_align (1, NULL, 0, 0);
      force_code_align = FALSE;
    }
}
Ejemplo n.º 7
0
void gp_text_clear(gp_pixmap *pixmap, const gp_text_style *style,
                  gp_coord x, gp_coord y, int align,
		  gp_pixel bg_color, gp_size size)
{
	gp_coord topleft_x, topleft_y;

	GP_ASSERT(do_align(&topleft_x, &topleft_y, align, x, y, style, size) == 0,
	         "Invalid aligment flags");

	gp_fill_rect_xywh(pixmap, topleft_x, topleft_y,
	                  size, gp_text_height(style), bg_color);
}
Ejemplo n.º 8
0
Archivo: syntax.c Proyecto: ezrec/vasm
static void alignment(char *s,int mode)
{
  int align,max=0;
  expr *fill=0;

  align = parse_constexpr(&s);
  s = skip(s);
  if (*s == ',') {
    s = skip(s+1);
    if (*s != ',')
      fill = parse_expr_tmplab(&s);
    s = skip(s);
    if (*s == ',') {
      s = skip(s+1);
      max = parse_constexpr(&s);
    }
  }
  if (!mode)
    mode = CPU_DEF_ALIGN;
  do_align(mode==1?align:(1<<align),fill,max);
  eol(s);
}
Ejemplo n.º 9
0
void gp_text(gp_pixmap *pixmap, const gp_text_style *style,
             gp_coord x, gp_coord y, int align,
	     gp_pixel fg_color, gp_pixel bg_color,
             const char *str)
{
	GP_CHECK_PIXMAP(pixmap);

	if (str == NULL)
		return;

	if (style == NULL)
		style = &gp_default_style;

	gp_coord topleft_x, topleft_y;

	gp_size w = gp_text_width(style, str);

	GP_ASSERT(do_align(&topleft_x, &topleft_y, align, x, y, style, w) == 0,
	         "Invalid aligment flags");

	gp_text_raw(pixmap, style, topleft_x, topleft_y,
	            align & GP_TEXT_NOBG, fg_color, bg_color, str);
}
Ejemplo n.º 10
0
/** 
 * <JA>
 * HMM状態ごとの forced alignment を行う. 
 * 
 * @param words [in] 単語列
 * @param num [in] @a words の単語数
 * @param param [in] 入力特徴ベクトル列
 * @param align [out] アラインメント結果を格納するSentence構造体
 * @param r [i/o] 認識処理インスタンス
 * </JA>
 * <EN>
 * Do forced alignment per HMM state for the given word sequence.
 * 
 * @param words [in] word sequence
 * @param num [in] length of @a words
 * @param param [in] input parameter vectors
 * @param align [out] Sentence data area to store the alignment result
 * @param r [i/o] recognition process instance
 * </EN>
 * @callgraph
 * @callergraph
 */
void
state_align(WORD_ID *words, short num, HTK_Param *param, SentenceAlign *align, RecogProcess *r)
{
  do_align(words, num, param, PER_STATE, align, r);
}
Ejemplo n.º 11
0
/** 
 * <JA>
 * 音素ごとの forced alignment を行う. 
 * 
 * @param words [in] 単語列
 * @param num [in] @a words の単語数
 * @param param [in] 入力特徴ベクトル列
 * @param align [out] アラインメント結果を格納するSentence構造体
 * @param r [i/o] 認識処理インスタンス
 * </JA>
 * <EN>
 * Do forced alignment per phoneme for the given word sequence.
 * 
 * @param words [in] word sequence
 * @param num [in] length of @a words
 * @param param [in] input parameter vectors
 * @param align [out] Sentence data area to store the alignment result
 * @param r [i/o] recognition process instance
 * </EN>
 * @callgraph
 * @callergraph
 */
void
phoneme_align(WORD_ID *words, short num, HTK_Param *param, SentenceAlign *align, RecogProcess *r)
{
  do_align(words, num, param, PER_PHONEME, align, r);
}
Ejemplo n.º 12
0
/** 
 * <JA>
 * 単語ごとの forced alignment を行う. 
 * 
 * @param words [in] 単語列
 * @param wnum [in] @a words の単語数
 * @param param [in] 入力特徴ベクトル列
 * @param align [out] アラインメント結果を格納するSentence構造体
 * @param r [i/o] 認識処理インスタンス
 * </JA>
 * <EN>
 * Do forced alignment per word for the given word sequence.
 * 
 * @param words [in] word sequence
 * @param wnum [in] length of @a words
 * @param param [in] input parameter vectors
 * @param align [out] Sentence data area to store the alignment result
 * @param r [i/o] recognition process instance
 * </EN>
 * @callgraph
 * @callergraph
 */
void
word_align(WORD_ID *words, short wnum, HTK_Param *param, SentenceAlign *align, RecogProcess *r)
{
  do_align(words, wnum, param, PER_WORD, align, r);
}
Ejemplo n.º 13
0
/**
 * Finish building the directory.  Frees the
 * builder context and returns the directory
 * in-memory.
 *
 * @param bld directory to finish
 * @param rsize set to the number of bytes needed
 * @param rdata set to the encoded directory
 * @return GNUNET_OK on success
 */
int
GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
                                    size_t * rsize, void **rdata)
{
    char *data;
    char *sptr;
    size_t *sizes;
    unsigned int *perm;
    unsigned int i;
    unsigned int j;
    struct BuilderEntry *pos;
    struct BuilderEntry **bes;
    size_t size;
    size_t psize;
    size_t off;
    ssize_t ret;
    uint32_t big;

    size = strlen (GNUNET_DIRECTORY_MAGIC) + sizeof (uint32_t);
    size += GNUNET_CONTAINER_meta_data_get_serialized_size (bld->meta);
    sizes = NULL;
    perm = NULL;
    bes = NULL;
    if (0 < bld->count)
    {
        sizes = GNUNET_malloc (bld->count * sizeof (size_t));
        perm = GNUNET_malloc (bld->count * sizeof (unsigned int));
        bes = GNUNET_malloc (bld->count * sizeof (struct BuilderEntry *));
        pos = bld->head;
        for (i = 0; i < bld->count; i++)
        {
            perm[i] = i;
            bes[i] = pos;
            sizes[i] = pos->len;
            pos = pos->next;
        }
        block_align (size, bld->count, sizes, perm);
        /* compute final size with alignment */
        for (i = 0; i < bld->count; i++)
        {
            psize = size;
            size += sizes[perm[i]];
            size = do_align (psize, size);
        }
    }
    *rsize = size;
    data = GNUNET_malloc_large (size);
    if (data == NULL)
    {
        GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
        *rsize = 0;
        *rdata = NULL;
        GNUNET_free_non_null (sizes);
        GNUNET_free_non_null (perm);
        GNUNET_free_non_null (bes);
        return GNUNET_SYSERR;
    }
    *rdata = data;
    memcpy (data, GNUNET_DIRECTORY_MAGIC, strlen (GNUNET_DIRECTORY_MAGIC));
    off = strlen (GNUNET_DIRECTORY_MAGIC);

    sptr = &data[off + sizeof (uint32_t)];
    ret =
        GNUNET_CONTAINER_meta_data_serialize (bld->meta, &sptr,
                size - off - sizeof (uint32_t),
                GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
    GNUNET_assert (ret != -1);
    big = htonl (ret);
    memcpy (&data[off], &big, sizeof (uint32_t));
    off += sizeof (uint32_t) + ret;
    for (j = 0; j < bld->count; j++)
    {
        i = perm[j];
        psize = off;
        off += sizes[i];
        off = do_align (psize, off);
        memcpy (&data[off - sizes[i]], &(bes[i])[1], sizes[i]);
        GNUNET_free (bes[i]);
    }
    GNUNET_free_non_null (sizes);
    GNUNET_free_non_null (perm);
    GNUNET_free_non_null (bes);
    GNUNET_assert (off == size);
    GNUNET_CONTAINER_meta_data_destroy (bld->meta);
    GNUNET_free (bld);
    return GNUNET_OK;
}