static carry_result lower_sub_borrow(ir_node *left, ir_node *right, ir_mode *mode) { assert(!mode_is_signed(mode)); bitinfo *bi_left = get_bitinfo(left); if (!bi_left) { return can_carry; } bitinfo *bi_right = get_bitinfo(right); // If we have bitinfo for one node, we should also have it for // the other assert(bi_right); ir_tarval *lmin = tarval_convert_to(bitinfo_min(bi_left), mode); ir_tarval *rmin = tarval_convert_to(bitinfo_min(bi_right), mode); ir_tarval *lmax = tarval_convert_to(bitinfo_max(bi_left), mode); ir_tarval *rmax = tarval_convert_to(bitinfo_max(bi_right), mode); carry_result result = no_carry; int old_wrap_on_overflow = tarval_get_wrap_on_overflow(); tarval_set_wrap_on_overflow(false); if (tarval_sub(lmin, rmax) == tarval_bad) { result = can_carry; if (tarval_sub(lmax, rmin) == tarval_bad) { result = must_carry; } } tarval_set_wrap_on_overflow(old_wrap_on_overflow); return result; }
int main(int argc, char *argv[]) { struct sigaction sigact; struct hardware hw; int ch, min, res; bool raw = false, verbose = true; while ((ch = getopt(argc, argv, "qr")) != -1) { switch (ch) { case 'q' : verbose = false; break; case 'r' : raw = true; break; default: printf("usage: %s [-qr]\n", argv[0]); return EX_USAGE; } } res = read_config_file(ETCDIR"/config.txt"); if (res != 0) { cleanup(); return res; } res = set_mode_live(); if (res != 0) { cleanup(); return res; } hw = get_hardware_parameters(); sigact.sa_handler = do_cleanup; sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; sigaction(SIGINT, &sigact, (struct sigaction *)NULL); min = -1; for (;;) { struct bitinfo bi; struct GB_result bit; if (raw) { struct timespec slp; slp.tv_sec = 1.0 / hw.freq; slp.tv_nsec = 1e9 / hw.freq; printf("%i", get_pulse()); fflush(stdout); while (nanosleep(&slp, &slp)) ; continue; } bit = get_bit_live(); bi = get_bitinfo(); if (verbose) { if (bi.freq_reset) printf("!"); /* display first bi->t pulses */ for (unsigned long long i = 0; i < bi.t / 8; i++) for (unsigned j = 0; j < 8; j++) printf("%c", (bi.signal[i] & (1 << j)) > 0 ? '+' : '-'); /* * display pulses in the last partially filled item * bi.t is 0-based, hence the <= comparison */ for (unsigned j = 0; j <= (bi.t & 7); j++) printf("%c", (bi.signal[bi.t / 8] & (1 << j)) > 0 ? '+' : '-'); printf("\n"); } if (bit.marker == emark_toolong || bit.marker == emark_late) min++; printf("%i %i %u %llu %llu %llu %i:%i\n", bi.tlow, bi.tlast0, bi.t, bi.bit0, bi.bit20, bi.realfreq, min, get_bitpos()); if (bit.marker == emark_minute) min++; bit = next_bit(); } /* NOTREACHED */ }