//seive function this takes only one argument because the create function allows only one parameter.
void *eratosthenes(void *threadnum){
    size_t i;
    size_t min;
    size_t max;
    size_t offset = 0;
    size_t ops = (long int)threadnum;
    long long z;
    
    
    for (i = 0; i < (ops+1); i++){
        max = offset + sieve[i];
        min = offset + 1;
        offset += sieve[i];
        if (sqrt(size) < max){
            max = sqrt(size);
        }
    }
    
    //http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
    for(i = min; i < (max+1); i++){
        if(TESTBIT(threadstack, i)){
            //z = i^2
            // all values that are mulitles of z should be marked
            for (z = i * i; z < size; z += i){
                if(TESTBIT(threadstack, z)){
                    CLEARBIT(threadstack, z);
                }
            }
        }
    }
    return 0;
}
Example #2
0
static char quant2(OCTREE tree)
{
	if (tree->leaf)   return(tree->colorindex);
	else					return(quant2(tree->next[
								TESTBIT(quant_r, MAXDEPTH - tree->level) * 4 +
								TESTBIT(quant_g, MAXDEPTH - tree->level) * 2 +
								TESTBIT(quant_b, MAXDEPTH - tree->level)]));
}
//print out all the paired primes
void printallprimes(void){
    size_t pair;
    int count = 1;
    for (size_t i = 2; i < (size - 1); i++){
        if (TESTBIT(threadstack, i)){
            pair = i + 2;
            if(TESTBIT(threadstack, pair)){
                printf("Pair %d: (%d,%d)\n", count,(int)i, (int)pair);
                count++;
            }
        }
    }
}
Example #4
0
int usb_data_ready(void)
{
#if defined _USE_TIMED_USB
	if (TESTBIT(USB_STATUS, USB_RXE))
		return 0;
	else
	{
		usb_on = 1;
		return 1;
	}
#else
	return !TESTBIT(USB_STATUS, USB_RXE);
#endif /* _USE_TIMED_USB */
}
Example #5
0
int test_sensor(int s)
{
	if ((0 > s) || (s >= SENSOR_COUNT))
		return 0;
													
	return !TESTBIT(sensor_value(), s);
}
Example #6
0
void
eoftn(struct interpass_prolog *ipp)
{
	int i;

	if (ipp->ipp_ip.ip_lbl == 0)
		return; /* no code needs to be generated */

	/* return from function code */
	for (i = 0; i < MAXREGS; i++)
		if (TESTBIT(p2env.p_regs, i))
			printf("	mov %s,-%d[%s]\n",
			    rnames[i],regoff[i], rnames[FPREG]);

	/* struct return needs special treatment */
	if (ftype == STRTY || ftype == UNIONTY) {
		printf("	mov ax, 8[bp]\n");
		printf("	leave\n");
		/* FIXME: ret n is not in 8086 */
		printf("	ret %d\n", 4 + ipp->ipp_argstacksize);
	} else {
		printf("	mov sp, bp\n");
		printf("	pop bp\n");
		if (ipp->ipp_argstacksize)
			/* CHECK ME */
			printf("	add sp, #%d\n", ipp->ipp_argstacksize);
		printf("	ret\n");
	}
}
Example #7
0
void
prologue(struct interpass_prolog *ipp)
{
	int i;

	/*
	 * Subtract both space for automatics and permanent regs.
	 * XXX - no struct return yet.
	 */

	fpsub = p2maxautooff;
	if (fpsub >= AUTOINIT/SZCHAR)
		fpsub -= AUTOINIT/SZCHAR;
	regm = regf = nfp = 0;
	for (i = 0; i < MAXREGS; i++)
		if (TESTBIT(p2env.p_regs, i)) {
			if (i <= A7) {
				regm |= (1 << i);
				fpsub += 4;
			} else if (i >= FP0) {
				regf |= (1 << (i - FP0));
				fpsub += 12;
				nfp += 12;
			} else
				comperr("bad reg range");
		}
	printf("	link.%c %%fp,#%d\n", fpsub > 32768 ? 'l' : 'w', -fpsub);
	if (regm)
		printf("	movem.l #%d,%d(%%fp)\n", regm, -fpsub + nfp);
	if (regf)
		printf("	fmovem #%d,%d(%%fp)\n", regf, -fpsub);
}
Example #8
0
void
eoftn(struct interpass_prolog *ipp)
{
	int i;

	if (ipp->ipp_ip.ip_lbl == 0)
		return; /* no code needs to be generated */

	/* return from function code */
	for (i = 0; i < MAXREGS; i++)
		if (TESTBIT(ipp->ipp_regs, i))
			printf("	movl -%d(%s),%s\n",
			    regoff[i], rnames[FPREG], rnames[i]);

	/* struct return needs special treatment */
	if (ftype == STRTY || ftype == UNIONTY) {
		printf("	movl 8(%%ebp),%%eax\n");
		printf("	leave\n");
		printf("	ret $%d\n", 4 + ipp->ipp_argstacksize);
	} else {
		printf("	leave\n");
		if (ipp->ipp_argstacksize)
			printf("	ret $%d\n", ipp->ipp_argstacksize);
		else
			printf("	ret\n");
	}

#if defined(ELFABI)
	printf("\t.size " EXPREFIX "%s,.-" EXPREFIX "%s\n", ipp->ipp_name,
	    ipp->ipp_name);
#endif
}
Example #9
0
int usb_putchar_timed(char ch, uint16_t delay)
{
	uint8_t timer_id = 0;
	
	if (!usb_on)
		return 0;
		
	timer_id = start_timer(delay);
	
	while (TESTBIT(USB_STATUS, USB_TXE))
		if (timer_id)
			if (!timer_value(timer_id))
			{
				stop_timer(timer_id);
				timer_id = 0;
				usb_on = 0;
				return 0;
			}
	
	stop_timer(timer_id);
	timer_id = 0;
	
	USB_DATA = ch;
	return 0;
}
Example #10
0
void PrintBit(int n,int b)
{
	int i;
	for(i=b-1;i>=0;i--)
		printf("%d",TESTBIT(n,i));
	printf("\n");

}
void lcd_spi_transmit_CMD(unsigned char temp){
   CLEARBIT(PORTB,RS);
   CLEARBIT(PORTB,SS_bar);
   SPDR = temp;
   while(!TESTBIT(SPSR,SPIF));
   SPSR &= 0x7F;
   SETBIT(PORTB, SS_bar);
 }
Example #12
0
int	usb_getchar(void)
{
#if defined _USE_TIMED_USB
	return usb_getchar_timed(USB_TIMEOUT);
#else
	while (TESTBIT(USB_STATUS, USB_RXE));
	return USB_DATA;
#endif /* _USE_TIMED_USB */
}
/*
;*********************************
 NAME:       lcd_spi_transmit_DATA
 ASSUMES:    temp = byte to transmit to LCD.
             SPI port is configured.
 RETURNS:    nothing
 MODIFIES:   temp, SPCR
 CALLED BY:  init_dsp, update
 DESCRITION: outputs a byte passed in r16 via SPI port. Waits for
             data to be written by spi port before continuing.
 *****************************************************************
 */
  void lcd_spi_transmit_DATA(unsigned char data){
    PORTB = (1 << RS);
    CLEARBIT(PORTB, SS_bar);
    CLEARBIT(SPSR, SPIF);
    SPDR = data;
    while(!TESTBIT(SPSR,SPIF));
    SPSR &= 0x7F;
    SETBIT(PORTB, SS_bar);
  }
Example #14
0
bool bitsetVar::getVar(const char **s, uint32 *v) {
    if (!get_args(s, name, v, 1))
        return false;
    if (*v > maxavail) {
        ScriptError("Index out of range (0..%d)", maxavail);
        return false;
    }
    *v = TESTBIT(data, *v);
    return true;
}
Example #15
0
int usb_putchar(char ch)
{
#if defined _USE_TIMED_USB
	return usb_putchar_timed(ch, USB_TIMEOUT);
#else
	while (TESTBIT(USB_STATUS, USB_TXE));
	USB_DATA = ch;
	return 0;
#endif /* _USE_TIMED_USB */
}
Example #16
0
/*
 * Deal with gcc warnings.
 */
void
warner(int type, ...)
{
	va_list ap;
	char *w;

	if (TESTBIT(warnary, type) == 0)
		return; /* no warning */
	if (TESTBIT(werrary, type)) {
		w = "error";
		incerr();
	} else
		w = "warning";

	va_start(ap, type);
	fprintf(stderr, "%s:%d: %s: ", ftitle, lineno, w);
	vfprintf(stderr, warntxt[type], ap);
	fprintf(stderr, "\n");
	va_end(ap);
}
Example #17
0
void main()
{
	int n;
	printf("Enter the number:");
	scanf("%d",&n);
	getchar();
	if(TESTBIT(n,1))
		printf("No is not power of 2\n");
	else 
		printf("NO is power of 2\n");

}
Example #18
0
static void inserttree(OCTREE *tree, UINT depth)
{
	UINT branch;

	if (*tree == NULL)
		newandinit(tree,depth);
	(*tree)->colorcount++;
	(*tree)->rgbsum.r += insert_rgb[RED];
	(*tree)->rgbsum.g += insert_rgb[GREEN];
	(*tree)->rgbsum.b += insert_rgb[BLUE];
	if ((*tree)->leaf == FALSE && depth < leaflevel) {
		branch = TESTBIT(insert_rgb[RED],MAXDEPTH - depth) * 4 +
					TESTBIT(insert_rgb[GREEN],MAXDEPTH - depth) * 2 +
					TESTBIT(insert_rgb[BLUE],MAXDEPTH - depth);
		if ((*tree)->next[branch] == NULL) {
			(*tree)->children++;
			if ((*tree)->children == 2)
				makereduceable(depth,*tree);
		}
		inserttree(&((*tree)->next[branch]), depth + 1);
	}
}
Example #19
0
void menu_sensors(void)
{
	uint8_t	idx;

	sprintf(lcd_line0, "бундш           ");

	for (idx = 0; idx < 3; idx++)
		lcd_line0[13 + idx] = (TESTBIT(secondary_sensors, idx))?'1':'.';

	for (idx = 0; idx < 16; idx++)
		lcd_line1[idx] = (TEST_SENSOR(idx))?'1':'.';

	menu_common();
}
Example #20
0
/*
 * calculate stack size and offsets
 */
static int
offcalc(struct interpass_prolog *ipp)
{
	int i, addto;

	addto = p2maxautooff;
	if (addto >= AUTOINIT/SZCHAR)
		addto -= AUTOINIT/SZCHAR;
	for (i = 0; i < MAXREGS; i++)
		if (TESTBIT(ipp->ipp_regs, i)) {
			addto += SZINT/SZCHAR;
			regoff[i] = addto;
		}
	return addto;
}
Example #21
0
/*
 * Print out the prolog assembler.
 * addto and regoff are already calculated.
 */
static void
prtprolog(struct interpass_prolog *ipp, int addto)
{
	int i;

	printf("	pushl %%ebp\n");
	printf("	movl %%esp,%%ebp\n");
#if defined(MACHOABI)
	printf("	subl $8,%%esp\n");	/* 16-byte stack alignment */
#endif
	if (addto)
		printf("	subl $%d,%%esp\n", addto);
	for (i = 0; i < MAXREGS; i++)
		if (TESTBIT(ipp->ipp_regs, i))
			printf("	movl %s,-%d(%s)\n",
			    rnames[i], regoff[i], rnames[FPREG]);
}
Example #22
0
void
prologue(struct interpass_prolog *ipp)
{
	int i, j;

	for (j = i = 0; i < MAXREGS; i++)
		if (TESTBIT(ipp->ipp_regs, i))
			j++;

	printf(".LP%d:	.word 0%o\n", prolnum, j);
	if (ipp->ipp_vis)
		printf("	.globl %s\n", ipp->ipp_name);
	printf("%s:\n", ipp->ipp_name);
	printf("	sta 3,@40\n");	/* save ret pc on stack */
	printf("	lda 2,.LP%d-.,1\n", prolnum);
	printf("	jsr @45\n");
	prolnum++;
}
Example #23
0
void	shift_one(uint8_t data)
{
	int	i;
	for (i = 0; i < 8; i++)
	{
		
		if (TESTBIT(data, i))
			SETBIT(SHIFT_OUT_PORT, SHIFT_OUT_BIT);
		else 
			CLEARBIT(SHIFT_OUT_PORT, SHIFT_OUT_BIT);
		
		SETBIT(SHIFT_CLK_PORT, SHIFT_CLK_BIT);
		_delay_us(SHIFT_DELAY);
		CLEARBIT(SHIFT_CLK_PORT, SHIFT_CLK_BIT);
		CLEARBIT(SHIFT_OUT_PORT, SHIFT_OUT_BIT);
		_delay_us(SHIFT_DELAY);
	}
}
Example #24
0
/*
 * Print out the prolog assembler.
 * addto and regoff are already calculated.
 */
static void
prtprolog(struct interpass_prolog *ipp, int addto)
{
	int i;

#if 1
	/* FIXME: can't use enter/leave if generating i8086 */
	if (addto == 0 || addto > 65535 || 1) {
		printf("	push bp\n\tmov bp,sp\n");
		if (addto)
			printf("	sub sp,#%d\n", addto);
	} else
		printf("	enter %d,0\n", addto);
#endif
	for (i = 0; i < MAXREGS; i++)
		if (TESTBIT(p2env.p_regs, i))
			printf("	mov -%d[%s],%s\n",
			     regoff[i], rnames[FPREG], rnames[i]);
}
Example #25
0
/*
 * Print out the prolog assembler.
 * addto and regoff are already calculated.
 */
static void
prtprolog(struct interpass_prolog *ipp, int addto)
{
	int i;

#if 1
#if defined(MACHOABI)
	addto += 8;
#endif
	if (addto == 0 || addto > 65535) {
		printf("	pushl %%ebp\n\tmovl %%esp,%%ebp\n");
		if (addto)
			printf("	subl $%d,%%esp\n", addto);
	} else
		printf("	enter $%d,$0\n", addto);
#endif
	for (i = 0; i < MAXREGS; i++)
		if (TESTBIT(ipp->ipp_regs, i))
			printf("	movl %s,-%d(%s)\n",
			    rnames[i], regoff[i], rnames[FPREG]);
}
Example #26
0
void
eoftn(struct interpass_prolog *ipp)
{
	int i;

	if (ipp->ipp_ip.ip_lbl == 0)
		return; /* no code needs to be generated */

	/* return from function code */
	for (i = 0; i < MAXREGS; i++)
		if (TESTBIT(ipp->ipp_regs, i)) {
			if (i <= R31)
				printf("\tldw\t%d(%%r3),%s\n",
				    regoff[i], rnames[i]);
			else if (i <= RETD0)
				printf("\tldw\t%d(%%r3),%s\n"
				    "\tldw\t%d(%%r3),%s\n",
				    regoff[i] + 0, rnames[rl[i - RD0]],
				    regoff[i] + 4, rnames[rh[i - RD0]]);
			else if (i <= FR31)
				printf("\tfldws\t%d(%%r3),%s\n",
				    regoff[i], rnames[i]);
			else
				printf("\tfldds\t%d(%%r3),%s\n",
				    regoff[i], rnames[i]);
		}

	if (p2calls || p2maxautooff > 4) {
		if (p2calls)
			printf("\tldw\t-20(%%r3),%%rp\n");
		printf("\tcopy\t%%r3,%%r1\n"
		    "\tldw\t0(%%r3),%%r3\n"
		    "\tbv\t%%r0(%%rp)\n"
		    "\tcopy\t%%r1,%%sp\n");
	} else
		printf("\tbv\t%%r0(%%rp)\n\tnop\n");

	printf("\t.exit\n\t.procend\n\t.size\t%s, .-%s\n",
	    ipp->ipp_name, ipp->ipp_name);
}
Example #27
0
/*
 * calculate stack size and offsets
 */
static int
offcalc(struct interpass_prolog *ipp)
{
	int i, addto, off;

	addto = 32;
	if (p2calls) {
		i = p2calls - 1;
		/* round up to 4 args */
		if (i < 4)
			i = 4;
		addto += i * 4;
	}

	for (off = 4, i = 0; i < MAXREGS; i++)
		if (TESTBIT(ipp->ipp_regs, i)) {
			regoff[i] = off;
			off += szty(PERMTYPE(i)) * SZINT/SZCHAR;
		}
	addto += off + p2maxautooff;
	return (addto + 63) & ~63;
}
Example #28
0
/*
 * Print out the prolog assembler.
 * addto and regoff are already calculated.
 */
void
prtprolog(struct interpass_prolog *ipp, int addto)
{
	int i;

	/* if this functions calls nothing -- no frame is needed */
	if (p2calls || p2maxautooff > 4) {
		printf("\tcopy\t%%r3,%%r1\n\tcopy\t%%sp,%%r3\n");
		if (addto < 0x2000)
			printf("\tstw,ma\t%%r1,%d(%%sp)\n", addto);
		else if (addto < 0x802000)
			printf("\tstw,ma\t%%r1,8192(%%sp)\n"
			    "\taddil\t%d-8192,%%sp\n"
			    "\tcopy\t%%r1,%%sp\n", addto);
		else
			comperr("too much local allocation");
		if (p2calls)
			printf("\tstw\t%%rp,-20(%%r3)\n");
	}

	for (i = 0; i < MAXREGS; i++)
		if (TESTBIT(ipp->ipp_regs, i)) {
			if (i <= R31)
				printf("\tstw\t%s,%d(%%r3)\n",
				    rnames[i], regoff[i]);
			else if (i <= RETD0)
				printf("\tstw\t%s,%d(%%r3)\n"
				    "\tstw\t%s,%d(%%r3)\n",
				    rnames[rl[i - RD0]], regoff[i] + 0,
				    rnames[rh[i - RD0]], regoff[i] + 4);
			else if (i <= FR31)
				printf("\tfstws\t%s,%d(%%r3)\n",
				    rnames[i], regoff[i]);
			else
				printf("\tfstds\t%s,%d(%%r3)\n",
				    rnames[i], regoff[i]);
		}
}
Example #29
0
void
eoftn(struct interpass_prolog *ipp)
{
	int i, j;

	if (ipp->ipp_ip.ip_lbl == 0)
		return; /* no code needs to be generated */

	/* return from function code */
	for (j = i = 0; i < MAXREGS; i++)
		if (TESTBIT(ipp->ipp_regs, i))
			j++;
	printf("	lda 2,.LP%d-.,1\n", prolnum);
	printf("	jmp @46\n");
	printf(".LP%d:	.word 0%o\n", prolnum, j);
	prolnum++;
	while (ldq) {
		printf(".LP%d:	.word 0%o", ldq->lab, ldq->val);
		if (ldq->name && *ldq->name)
			printf("+%s", ldq->name);
		printf("\n");
		ldq = ldq->next;
	}
}
Example #30
0
int usb_getchar_timed(uint16_t delay)
{
	uint8_t timer_id = 0;

	if (!usb_on)
		return -1;

	timer_id = start_timer(delay);
	
	while (TESTBIT(USB_STATUS, USB_RXE))
		if (timer_id)
			if (!timer_value(timer_id))
			{
				stop_timer(timer_id);
				timer_id = 0;
//				usb_on = 0;
				return -1;
			}

	stop_timer(timer_id);
	timer_id = 0;

	return USB_DATA;
}