void test() {
  // for (int i = 0; i < 1000; i++)
  // {
  //     for (int j = 0; j < 1000; j++)
  //     {
  //         assert_true(eq(karatsuba(intx(i), intx(j)), intx(i) * intx(j)), true);
  //     }
  // }

  // multiplication_speed();
  // return;

  // cout << (intx(-10) < intx(-5)) << endl;
  // cout << intx(-5) << endl;
  // cout << intx(-10) << endl;
  // cout << intx(-5) - intx(-10) << endl;
  // cout << intx(-10) - intx(-5) << endl;
  // return;

  ifstream input("intx.test.in");

  set<string> enabled_ops;
  enabled_ops.insert("add");
  enabled_ops.insert("sub");
  enabled_ops.insert("neg");
  enabled_ops.insert("lt");
  enabled_ops.insert("mul");
  enabled_ops.insert("div");
  enabled_ops.insert("mod");
  enabled_ops.insert("fib");
  enabled_ops.insert("fac");
  enabled_ops.insert("gcd");

  // int line = 0, n;
  int n;
  string op, s, ans;
  intx a, b;
  while (input >> op) {

    // printf("%d %s\n", ++line, op.c_str());

    intx res;
    if (op == "add") {
      input >> s;
      a = intx(s);
      input >> s;
      b = intx(s);
    } else if (op == "sub") {
intx randint(int len) {
    stringstream ss;
    ss << rand() % 9 + 1;
    for (int i = 0; i < len-1; i++)
        ss << rand() % 10;

    return intx(ss.str());
}
Example #3
0
inline jshort Atomic::add(jshort add_value, volatile jshort* dest) {
    // Most platforms do not support atomic add on a 2-byte value. However,
    // if the value occupies the most significant 16 bits of an aligned 32-bit
    // word, then we can do this with an atomic add of (add_value << 16)
    // to the 32-bit word.
    //
    // The least significant parts of this 32-bit word will never be affected, even
    // in case of overflow/underflow.
    //
    // Use the ATOMIC_SHORT_PAIR macro (see macros.hpp) to get the desired alignment.
#ifdef VM_LITTLE_ENDIAN
    assert((intx(dest) & 0x03) == 0x02, "wrong alignment");
    jint new_value = Atomic::add(add_value << 16, (volatile jint*)(dest-1));
#else
    assert((intx(dest) & 0x03) == 0x00, "wrong alignment");
    jint new_value = Atomic::add(add_value << 16, (volatile jint*)(dest));
#endif
    return (jshort)(new_value >> 16); // preserves sign
}
Example #4
0
File: video.c Project: fysnet/FYSOS
void get_video_eedid(void) {
  struct REGS regs;
  bit8u crc, edid[128];
  struct S_EEDID *p = (struct S_EEDID *) edid;
  int i;
  bool b;
  
  // VESA VBE/DC (Display Data Channel) - INSTALLATION CHECK / CAPABILITIES
  regs.eax = 0x00004F15;
  regs.ebx = 0x00000000;
  b = intx(0x10, &regs);
  
  // successful?
  if (!b && ((regs.eax & 0x0000FFFF) == 0x004F)) {
    //win_printf(main_win, "Vesa Supported EEDID call...\n");
    regs.eax = 0x00004F15;
    regs.ebx = 0x00000001;
    regs.ecx = 0x00000000;
    regs.edx = 0x00000000;
    regs.edi = MK_OFF((bit32u) edid);
    regs.es = MK_SEG((bit32u) edid);
    b = intx(0x10, &regs);
    if (!b && ((regs.eax & 0x0000FFFF) == 0x004F)) {
      //win_printf(main_win, "EDID: b = %i, eax = 0x%08X\n\n", b, regs.eax);   // 0x0000004F = successfull
      fdebug(edid, 128);
      crc = 0;
      for (i=0; i<128; i++)
        crc += edid[i];
      //win_printf(main_win, "EDID crc = 0x%02X\n", crc);
      // if crc != 0, error
      if (crc == 0) {
        //printf("size of struct S_EEDID = %i\n", sizeof(struct S_EEDID));
        printf("0x%02X 0x%02X 0x%02X\n", p->est_timings1, p->est_timings2, p->est_timings_resv);
        
      }
    }
  }
}
intx fastmul(const intx &an, const intx &bn) {
    string as = an.to_string(), bs = bn.to_string();
    int n = size(as), m = size(bs), l = 1,
        len = 5, radix = 100000,
        *a = new int[n], alen = 0,
        *b = new int[m], blen = 0;
    memset(a, 0, n << 2);
    memset(b, 0, m << 2);
    for (int i = n - 1; i >= 0; i -= len, alen++)
        for (int j = min(len - 1, i); j >= 0; j--)
            a[alen] = a[alen] * 10 + as[i - j] - '0';
    for (int i = m - 1; i >= 0; i -= len, blen++)
        for (int j = min(len - 1, i); j >= 0; j--)
            b[blen] = b[blen] * 10 + bs[i - j] - '0';
    while (l < 2*max(alen,blen)) l <<= 1;
    cpx *A = new cpx[l], *B = new cpx[l];
    rep(i,0,l) A[i] = cpx(i < alen ? a[i] : 0, 0);
    rep(i,0,l) B[i] = cpx(i < blen ? b[i] : 0, 0);
    fft(A, l); fft(B, l);
    rep(i,0,l) A[i] *= B[i];
    fft(A, l, true);
    ull *data = new ull[l];
    rep(i,0,l) data[i] = (ull)(round(real(A[i])));
    rep(i,0,l-1)
        if (data[i] >= (unsigned int)(radix)) {
            data[i+1] += data[i] / radix;
            data[i] %= radix;
        }
    int stop = l-1;
    while (stop > 0 && data[stop] == 0) stop--;
    stringstream ss;
    ss << data[stop];
    for (int i = stop - 1; i >= 0; i--)
        ss << setfill('0') << setw(len) << data[i];
    delete[] A; delete[] B;
    delete[] a; delete[] b;
    delete[] data;
    return intx(ss.str());
}
Example #6
0
File: video.c Project: fysnet/FYSOS
bit16u get_video_info(struct S_MODE_INFO *modeinfo) {
  int i, j;
  struct REGS regs;
  bit16u vesa_modes[VESA_MODE_SIZE];
  bit8u  buffer[512];
  
  // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  // clear the buffer first
  memset(buffer, 0, 512);
  
  // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  // call the BIOS, first setting the first 4 bytes to 'VBE2'
  // Since it returns 512 bytes, we need to use a spare buffer.
  memcpy(buffer, "VBE2", 4);
  regs.eax = 0x00004F00;
  regs.edi = MK_OFF((bit32u) buffer);
  regs.es = MK_SEG((bit32u) buffer);
  intx(0x10, &regs);
  if ((regs.eax & 0x0000FFFF) != 0x004F)
    return 0;
  
  // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  // now get the supported modes.  We have to do this incase
  //  the BIOS builds the list on the fly (Bochs BIOS does this)
  bit16u *p = (bit16u *) MK_FP(buffer + 0x0E);
  memcpy(vesa_modes, p, ((VESA_MODE_SIZE - 1) * 2));
  vesa_modes[(VESA_MODE_SIZE - 1)] = 0xFFFF;
  
  // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  // Now scroll through the list of modes to see if we find any
  //  capable for our use.
  i = 0; j = 0;
  struct S_VIDEO_MODE_INFO *info = (struct S_VIDEO_MODE_INFO *) buffer;
  while (vesa_modes[i] < 0xFFFF) {
    memset(info, 0, sizeof(struct S_VIDEO_MODE_INFO));
    regs.eax = 0x00004F01;
    regs.ecx = vesa_modes[i];
    regs.edi = MK_OFF((bit32u) info);
    regs.es = MK_SEG((bit32u) info);
    intx(0x10, &regs);
    if ((regs.eax & 0x0000FFFF) == 0x004F) {
      if ((info->mode_attrb & 0x01) &&  // supported by the current hardware (video card and monitor)
          (info->bits_pixel >= 8) &&
         ((info->mode_attrb & (1<<7)) && (info->linear_base > 0)) &&  // bit 7 = 1 if LFB is available for this mode
        (
          (info->memory_model == 4) || // model = 4 = packed pixel
          (info->memory_model == 6)    // model = 6 = direct color
        )
       ) {
        modeinfo[j].lfb = info->linear_base;
        modeinfo[j].xres = info->x_res;
        modeinfo[j].yres = info->y_res;
        modeinfo[j].bytes_per_scanline = info->bytes_scanline;
        modeinfo[j].bits_per_pixel = info->bits_pixel;
        modeinfo[j].red = ((info->red_field_pos << 8) | info->red_mask_size);
        modeinfo[j].grn = ((info->green_field_pos << 8) | info->green_mask_size);
        modeinfo[j].blu = ((info->blue_field_pos << 8) | info->blue_mask_size);
        vid_modes[j] = vesa_modes[i];
        modeinfo[j].memory_model = info->memory_model;
        if (++j == VIDEO_MAX_MODES)
          break;
      }
    }
    i++;
  }
  return j;
}
intx gcd(intx a, intx b) {
  return eq(b, intx(0)) ? a : gcd(b, a % b);
}
  int n;
  string op, s, ans;
  intx a, b;
  while (input >> op) {

    // printf("%d %s\n", ++line, op.c_str());

    intx res;
    if (op == "add") {
      input >> s;
      a = intx(s);
      input >> s;
      b = intx(s);
    } else if (op == "sub") {
      input >> s;
      a = intx(s);
      input >> s;
      b = intx(s);
    } else if (op == "mul") {
      input >> s;
      a = intx(s);
      input >> s;
      b = intx(s);
    } else if (op == "div") {
      input >> s;
      a = intx(s);
      input >> s;
      b = intx(s);
    } else if (op == "mod") {
      input >> s;
      a = intx(s);