void ComputeCostOfBox (box *b) { long different_costs; long i; long j; long new_cost; cost_info cost_list[MAX_PARTICLES_PER_BOX]; cost_info winner; long winner_index; long cost_index[MAX_PARTICLES_PER_BOX]; if (b->type == PARENT) b->cost = ((b->num_v_list * V_LIST_COST(Expansion_Terms)) / DIVISOR(Expansion_Terms)) + 1; else { different_costs = 0; for (i = 0; i < b->num_particles; i++) { new_cost = b->particles[i]->cost; for (j = 0; j < different_costs; j++) { if (new_cost == cost_list[j].cost) break; } if (j == different_costs) { cost_list[different_costs].cost = new_cost; cost_list[different_costs].num = 1; different_costs += 1; } else cost_list[j].num += 1; } winner.cost = cost_list[0].cost; winner.num = 1; winner_index = 0; cost_index[0] = 0; for (i = 1; i < different_costs; i++) { if (cost_list[i].num > cost_list[winner_index].num) { winner.cost = cost_list[i].cost; winner.num = 1; winner_index = i; cost_index[0] = i; } else { if (cost_list[i].num == cost_list[winner_index].num) { cost_index[winner.num] = i; winner.num += 1; } } } if (winner.num != 1) { for (i = 1; i < winner.num; i++) winner.cost += cost_list[cost_index[i]].cost; winner.cost /= winner.num; } b->cost = (winner.cost * b->num_particles) / DIVISOR(Expansion_Terms); if (b->cost == 0) b->cost = 1; } }
static int i8250_setup(struct uart *dev, const struct uart_params *params) { uint8_t line_stat; line_stat = calc_line_stat(params); line_stat = UART_NO_PARITY | UART_8BITS_WORD | UART_1_STOP_BIT; /* Turn off the interrupt */ out8(0x0, dev->base_addr + UART_IER); /* Set DLAB */ out8(UART_DLAB, dev->base_addr + UART_LCR); /* Set the baud rate */ out8(DIVISOR(params->baud_rate) & 0xFF, dev->base_addr + UART_DLL); out8((DIVISOR(params->baud_rate) >> 8) & 0xFF, dev->base_addr + UART_DLH); /* Set the line status */ out8(line_stat, dev->base_addr + UART_LCR); /* Uart enable FIFO */ out8(UART_ENABLE_FIFO, dev->base_addr + UART_FCR); /* Uart enable modem (turn on DTR, RTS, and OUT2) */ out8(UART_ENABLE_MODEM, dev->base_addr + UART_MCR); /*enable rx interrupt*/ if (params->irq) { /*enable rx interrupt*/ out8(UART_IER_RX_ENABLE, dev->base_addr + UART_IER); } return 0; }
static void serial_mem_hardware_init(int port, int speed, int word_bits, int parity, int stop_bits) { unsigned char reg; /* We will assume 8n1 for now. Does anyone use anything else these days? */ /* Disable interrupts. */ writeb(0, MEMBASE + 0x01); /* Assert RTS and DTR. */ writeb(3, MEMBASE + 0x04); /* Set the divisor latch. */ reg = readb(MEMBASE + 0x03); writeb(reg | 0x80, MEMBASE + 0x03); /* Write the divisor. */ writeb(DIVISOR(speed) & 0xFF, MEMBASE); writeb(DIVISOR(speed) >> 8 & 0xFF, MEMBASE + 1); /* Restore the previous value of the divisor. */ writeb(reg & ~0x80, MEMBASE + 0x03); }
void _acb_poly_powsum_one_series_sieved(acb_ptr z, const acb_t s, slong n, slong len, slong prec) { slong * divisors; slong powers_alloc; slong i, j, k, ibound, kprev, power_of_two, horner_point; int critical_line, integer; acb_ptr powers; acb_ptr t, u, x; acb_ptr p1, p2; arb_t logk, v, w; critical_line = arb_is_exact(acb_realref(s)) && (arf_cmp_2exp_si(arb_midref(acb_realref(s)), -1) == 0); integer = arb_is_zero(acb_imagref(s)) && arb_is_int(acb_realref(s)); divisors = flint_calloc(n / 2 + 1, sizeof(slong)); powers_alloc = (n / 6 + 1) * len; powers = _acb_vec_init(powers_alloc); ibound = n_sqrt(n); for (i = 3; i <= ibound; i += 2) if (DIVISOR(i) == 0) for (j = i * i; j <= n; j += 2 * i) DIVISOR(j) = i; t = _acb_vec_init(len); u = _acb_vec_init(len); x = _acb_vec_init(len); arb_init(logk); arb_init(v); arb_init(w); power_of_two = 1; while (power_of_two * 2 <= n) power_of_two *= 2; horner_point = n / power_of_two; _acb_vec_zero(z, len); kprev = 0; COMPUTE_POWER(x, 2, kprev); for (k = 1; k <= n; k += 2) { /* t = k^(-s) */ if (DIVISOR(k) == 0) { COMPUTE_POWER(t, k, kprev); } else { p1 = POWER(DIVISOR(k)); p2 = POWER(k / DIVISOR(k)); if (len == 1) acb_mul(t, p1, p2, prec); else _acb_poly_mullow(t, p1, len, p2, len, len, prec); } if (k * 3 <= n) _acb_vec_set(POWER(k), t, len); _acb_vec_add(u, u, t, len, prec); while (k == horner_point && power_of_two != 1) { _acb_poly_mullow(t, z, len, x, len, len, prec); _acb_vec_add(z, t, u, len, prec); power_of_two /= 2; horner_point = n / power_of_two; horner_point -= (horner_point % 2 == 0); } } _acb_poly_mullow(t, z, len, x, len, len, prec); _acb_vec_add(z, t, u, len, prec); flint_free(divisors); _acb_vec_clear(powers, powers_alloc); _acb_vec_clear(t, len); _acb_vec_clear(u, len); _acb_vec_clear(x, len); arb_clear(logk); arb_clear(v); arb_clear(w); }
static int cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...) { static int irq_state = 0; channel_data_t* chan; cyg_uint8 ier; int ret = 0; CYGARC_HAL_SAVE_GP(); // Some of the diagnostic print code calls through here with no idea what the ch_data is. // Go ahead and assume it is channels[0]. if (__ch_data == 0) __ch_data = (void*)&channels[0]; chan = (channel_data_t*)__ch_data; switch (__func) { case __COMMCTL_IRQ_ENABLE: irq_state = 1; HAL_READ_UINT8(chan->base + SER_16550_IER, ier); ier |= SIO_IER_ERDAI; HAL_WRITE_UINT8(chan->base + SER_16550_IER, ier); HAL_INTERRUPT_SET_LEVEL(chan->isr_vector, 1); HAL_INTERRUPT_UNMASK(chan->isr_vector); break; case __COMMCTL_IRQ_DISABLE: ret = irq_state; irq_state = 0; HAL_READ_UINT8(chan->base + SER_16550_IER, ier); ier &= ~SIO_IER_ERDAI; HAL_WRITE_UINT8(chan->base + SER_16550_IER, ier); HAL_INTERRUPT_MASK(chan->isr_vector); break; case __COMMCTL_DBG_ISR_VECTOR: ret = chan->isr_vector; break; case __COMMCTL_SET_TIMEOUT: { va_list ap; va_start(ap, __func); ret = chan->msec_timeout; chan->msec_timeout = va_arg(ap, cyg_uint32); va_end(ap); } break; case __COMMCTL_SETBAUD: { cyg_uint32 baud_rate; cyg_uint16 baud_divisor; cyg_uint8* port = chan->base; va_list ap; va_start(ap, __func); baud_rate = va_arg(ap, cyg_uint32); va_end(ap); switch (baud_rate) { case 110: baud_divisor = DIVISOR(110); break; case 150: baud_divisor = DIVISOR(150); break; case 300: baud_divisor = DIVISOR(300); break; case 600: baud_divisor = DIVISOR(600); break; case 1200: baud_divisor = DIVISOR(1200); break; case 2400: baud_divisor = DIVISOR(2400); break; case 4800: baud_divisor = DIVISOR(4800); break; case 7200: baud_divisor = DIVISOR(7200); break; case 9600: baud_divisor = DIVISOR(9600); break; case 14400: baud_divisor = DIVISOR(14400); break; case 19200: baud_divisor = DIVISOR(19200); break; case 38400: baud_divisor = DIVISOR(38400); break; case 57600: baud_divisor = DIVISOR(57600); break; case 115200: baud_divisor = DIVISOR(115200); break; case 230400: baud_divisor = DIVISOR(230400); break; default: return -1; break; // Invalid baud rate selected } // Disable port interrupts while changing hardware HAL_READ_UINT8(port+SER_16550_IER, ier); HAL_WRITE_UINT8(port+SER_16550_IER, 0); // Set baud rate. cyg_hal_plf_serial_set_baud(port, baud_divisor); // Reenable interrupts if necessary HAL_WRITE_UINT8(port+SER_16550_IER, ier); } break; case __COMMCTL_GETBAUD: break; default: break; } CYGARC_HAL_RESTORE_GP(); return ret; }