コード例 #1
0
ファイル: sphere.cpp プロジェクト: xinlongz/ComputerGraphics
static void init_sphere()
{
    static bool initialized = false;
    if ( initialized )
        return;

    for ( int i = 0; i <= SPHERE_NUM_LAT; i++ ) {
        for ( int j = 0; j <= SPHERE_NUM_LON; j++ ) {
            real_t lat = real_t( i ) / SPHERE_NUM_LAT;
            real_t lon = real_t( j ) / SPHERE_NUM_LON;
            float* vptr = &Vertices[VERTEX_SIZE * SINDEX(i,j)];

            vptr[TCOORD_OFFSET + 0] = lon;
            vptr[TCOORD_OFFSET + 1] = 1-lat;

            lat *= PI;
            lon *= 2 * PI;
            real_t sinlat = sin( lat );

            vptr[NORMAL_OFFSET + 0] = vptr[VERTEX_OFFSET + 0] = sinlat * sin( lon );
            vptr[NORMAL_OFFSET + 1] = vptr[VERTEX_OFFSET + 1] = cos( lat ),
            vptr[NORMAL_OFFSET + 2] = vptr[VERTEX_OFFSET + 2] = sinlat * cos( lon );
        }
    }

    for ( int i = 0; i < SPHERE_NUM_LAT; i++ ) {
        for ( int j = 0; j < SPHERE_NUM_LON; j++ ) {
            unsigned int* iptr = &Indices[6 * ( SPHERE_NUM_LON * i + j )];

            unsigned int i00 = SINDEX(i,  j  );
            unsigned int i10 = SINDEX(i+1,j  );
            unsigned int i11 = SINDEX(i+1,j+1);
            unsigned int i01 = SINDEX(i,  j+1);

            iptr[0] = i00;
            iptr[1] = i10;
            iptr[2] = i11;
            iptr[3] = i11;
            iptr[4] = i01;
            iptr[5] = i00;
        }
    }
	
    initialized = true;
	
}
コード例 #2
0
/* This function handles (ctx->state_count < 32767) */
uint32_t FUNC_NAME(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx,
                   PrefilterRuleStore *pmq, const uint8_t *buf, uint32_t buflen)
{
    uint32_t i = 0;
    int matches = 0;

    uint8_t mpm_bitarray[ctx->mpm_bitarray_size];
    memset(mpm_bitarray, 0, ctx->mpm_bitarray_size);

    const uint8_t* restrict xlate = ctx->translate_table;
    STYPE *state_table = (STYPE*)ctx->state_table;
    STYPE state = 0;
    int c = xlate[buf[0]];
    /* If buflen at least 4 bytes and buf 4-byte aligned. */
    if (buflen >= (4 + EXTRA) && ((uintptr_t)buf & 0x3) == 0) {
        BUF_TYPE data = *(BUF_TYPE* restrict)(&buf[0]);
        uint64_t index = 0;
        /* Process 4*floor(buflen/4) bytes. */
        i = 0;
        while ((i + EXTRA) < (buflen & ~0x3)) {
            BUF_TYPE data1 = *(BUF_TYPE* restrict)(&buf[i + 4]);
            index = SINDEX(index, state);
            state = SLOAD(state_table + index + c);
            c = xlate[BYTE1(data)];
            if (unlikely(SCHECK(state))) {
                matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
            }
            i++;
            index = SINDEX(index, state);
            state = SLOAD(state_table + index + c);
            c = xlate[BYTE2(data)];
            if (unlikely(SCHECK(state))) {
                matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
            }
            i++;
            index = SINDEX(index, state);
            state = SLOAD(state_table + index + c);
            c = xlate[BYTE3(data)];
            if (unlikely(SCHECK(state))) {
                matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
            }
            data = data1;
            i++;
            index = SINDEX(index, state);
            state = SLOAD(state_table + index + c);
            c = xlate[BYTE0(data)];
            if (unlikely(SCHECK(state))) {
                matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
            }
            i++;
        }
    }
    /* Process buflen % 4 bytes. */
    for (; i < buflen; i++) {
        size_t index = 0 ;
        index = SINDEX(index, state);
        state = SLOAD(state_table + index + c);
#ifndef __tile__
        if (likely(i+1 < buflen))
#endif
            c = xlate[buf[i+1]];
        if (unlikely(SCHECK(state))) {
            matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
        }
    } /* for (i = 0; i < buflen; i++) */

    return matches;
}