Example #1
0
File: bloom.c Project: pfq/PFQ
static int bloom_init(arguments_t args)
{
	unsigned int m = GET_ARG_0(unsigned int, args);
	size_t n = LEN_ARRAY_1(args);
	__be32 *ips = GET_ARRAY_1(__be32, args);
	__be32 mask;
	size_t i;

	char *mem;

	m = clp2(m);

	/* set bloom filter fold mask */

	SET_ARG_0(args, m-1);

	if (m > (1UL << 24)) {
		printk(KERN_INFO "[PFQ|init] bloom filter: maximum number of bins exceeded (2^24)!\n");
		return -EPERM;
	}

	mem = kzalloc(m >> 3, GFP_KERNEL);
	if (!mem) {
		printk(KERN_INFO "[PFQ|init] bloom filter: out of memory!\n");
		return -ENOMEM;
	}

	/* set bloom filter memory */

	SET_ARG_1(args, mem);

	mask = inet_make_mask(GET_ARG_2(int, args));

	/* set network mask */

	SET_ARG_2(args, mask);

	pr_devel("[PFQ|init] bloom filter@%p: k=4, n=%zu, m=%u size=%u netmask=%pI4 bytes.\n", mem, n, m, m>>3, &mask);

	for(i = 0; i < n; i++)
	{
		uint32_t h1 = hfun1(be32_to_cpu(ips[i] & mask)) & (m-1);
		uint32_t h2 = hfun2(be32_to_cpu(ips[i] & mask)) & (m-1);
		uint32_t h3 = hfun3(be32_to_cpu(ips[i] & mask)) & (m-1);
		uint32_t h4 = hfun4(be32_to_cpu(ips[i] & mask)) & (m-1);

		BF_SET(mem, h1);
		BF_SET(mem, h2);
		BF_SET(mem, h3);
		BF_SET(mem, h4);

		pr_devel("[PFQ|init] bloom filter: -> set address %pI4\n", ips+i);
	}

	return 0;
}
Example #2
0
static ctf_id_t
ctf_add_encoded(ctf_file_t *fp, uint_t flag,
    const char *name, const ctf_encoding_t *ep, uint_t kind)
{
	ctf_dtdef_t *dtd;
	ctf_id_t type;

	if (ep == NULL)
		return (ctf_set_errno(fp, EINVAL));

	if ((type = ctf_add_generic(fp, flag, name, &dtd)) == CTF_ERR)
		return (CTF_ERR); /* errno is set for us */

	dtd->dtd_data.ctt_info = CTF_TYPE_INFO(kind, flag, 0);
	dtd->dtd_data.ctt_size = clp2(P2ROUNDUP(ep->cte_bits, NBBY) / NBBY);
	dtd->dtd_u.dtu_enc = *ep;

	return (type);
}
Example #3
0
void FXTVDistort::init(void) {
	// asignar recursos y tal, cargar ficheros, blabla
	int demowidth = miDemo->getWidth();
	int demoheight = miDemo->getHeight();

	int twidth = clp2(demowidth);
	int theight = clp2(demoheight);
	
	this->setTextureSize(twidth, theight);
	BlurTexture = EmptyTexture();								
	ccr=0.5;
	ccg=0.5;
	ccb=0.5;
	cca=0.0;
	fac1=GL_SRC_ALPHA;
	fac2=GL_ONE_MINUS_SRC_ALPHA;

	xMax = float(demowidth) / twidth;
	yMax = float(demoheight) / theight;

	int i,j;
	float longint;
	float floati,floatj;
	
	longint=1/TVDISTORTINTERV;
	for(i=0;i<=TVDISTORTINTERV;i++) {
		floati=float(i);
		for(j=0;j<=TVDISTORTINTERV;j++) {
			floatj=float(j);
			// la textura va de 0 a 1
			texPos[i][j][0]=xMax*(floati)/TVDISTORTINTERV; // x
			texPos[i][j][1]=yMax*(floatj)/TVDISTORTINTERV; // y
			texPos[i][j][2]=0.0f; // z

			// quads de 0.. demowidth  blabla
			quadPos[i][j][0]=-demowidth/2.0+demowidth*(floati)/TVDISTORTINTERV; // x
			quadPos[i][j][1]=-demoheight/2.0+demoheight*(floatj)/TVDISTORTINTERV; // y
			quadPos[i][j][2]=0.0f; // z

			randQuadPos[i][j][0]=2*(float(rand())/RAND_MAX)-1; // de -1..1
			randQuadPos[i][j][1]=2*(float(rand())/RAND_MAX)-1; // de -1..1
			randQuadPos[i][j][2]=0.0f;

			
		}
	}

	for(i=0;i<TVD_NUMPARAMS;i++) {
		params[i]=0.0;
	}

	float mu, sigma, x, pi, normal, constante, maximo, xinit, xfin, alturaInterv;
	
	mu=9.9465108746;
	sigma=0.9824992603;
	pi=3.1415926535;
	maximo=0;
	//xinit=7.25;
	//xfin=13;
	xinit=4;
	xfin=16;
	
	alturaInterv=float(demoheight)/float(TVDISTORTINTERV);

	constante=1/(sigma * sqrt(2*pi));
	for(i=0;i<=TVDISTORTINTERV;i++) {
		/* x=4..17 ........ 17-4 = 13*/
		x=(float(i)/TVDISTORTINTERV)*(xfin-xinit) + xinit;
		normal=constante * exp(-(pow((x-mu/sigma),2))/2);
		normalMagnit[i]=normal/constante; // La division es para normalizar a 1
		if(normal>maximo)
			maximo=normal;
		
		normalInterv[i]=(alturaInterv+ normalMagnit[i])*i - demoheight/2;

	}

}