示例#1
0
void armv7a::add_with_carry(bits* result, uint32_t* carry_out, uint32_t* overflow, const bits& x, const bits& y, uint32_t carry_in)
{
    uint64_t unsigned_sum = UInt(x) + UInt(y) + (uint64_t)carry_in;
    uint64_t signed_sum = SInt(x) + SInt(y) + (uint64_t)carry_in;
    result->val = unsigned_sum & mask(x.n - 1, 0);
    result->n = x.n;
    *carry_out = (UInt(*result) == unsigned_sum) ? 0 : 1;
    *overflow = (SInt(*result) == signed_sum) ? 0 : 1;
}
示例#2
0
文件: s.c 项目: kostelnik/jwmtools
void STests(int level) {
  // unit self tests
  char *a, *b, *c;
  int i,j,k;
  int ol = S_DEBUG_LEVEL;
  S_DEBUG_LEVEL=level;
  
  // test
  a = SCreate("Hello World");
  STest(a,"Hello World","string creation");
  
  // test
  SFree(a);
  STestI((intptr_t)a,0,"string free and set to NULL");
        
  // test
  a = SCreate("0123456789");
  i = SPos(a,"0");    STestI(i,0,"position of char on the begining of string");
  i = SPos(a,"012");  STestI(i,0,"position of string on the begining of string");
  i = SPos(a,"9");    STestI(i,9,"position of char on the end of string");
  i = SPos(a,"789");  STestI(i,7,"position of string on the end of string");
  i = SPos(a,"4");    STestI(i,4,"position of char in the middle of string");
  i = SPos(a,"456");  STestI(i,4,"position of string in the middle of string");
  SFree(a);
  
  // test
  //S_DEBUG_LEVEL=1;
  a = SCreate("I walked into bar and talked to bar");
  b = SCreateReplace(a,"bar","BAR");
  STest(b,"I walked into BAR and talked to BAR",
        "replacing on the end of string");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("foo bar foo");
  b = SCreateReplace(a,"bar","BAR");
  STest(b,"foo BAR foo",
        "replacing in the middle of string once");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("foo bar and bar foo");
  b = SCreateReplace(a,"bar","BAR");
  STest(b,"foo BAR and BAR foo",
        "replacing in the middle of string twice");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("foo bar foo");
  b = SCreateReplace(a,"foo","FOO");
  STest(b,"FOO bar FOO",
        "replacing on the begining and end of string");
  SFree(a);
  SFree(b);
  
  // test
  a = SCreate("abc");
  b = SCreateReplace(a,"b","B");
  STest(b,"aBc",
        "replacing one char on 2nd position");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("abc");
  b = SCreateReplace(a,"a","A");
  STest(b,"Abc",
        "replacing one char on 1st position");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("abc");
  b = SCreateReplace(a,"c","C");
  STest(b,"abC",
        "replacing one char on last position");
  SFree(a);
  SFree(b);
  
  // test
  a = SCreate("abc");
  b = SCreateReplace(a,"b","BBB");
  STest(b,"aBBBc",
        "replacing one char with 3char string");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("abbbc");
  b = SCreateReplace(a,"bbb","B");
  STest(b,"aBc",
        "replacing string with one char");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("abbba");
  b = SCreateReplace(a,"a","AA");
  STest(b,"AAbbbAA",
        "multiple replacement with different length");
  SFree(a);
  SFree(b);
  
  // test
  a = SCreate("97%");
  b = SCreateReplace(a,"%","");
  STest(b,"97",
        "replacing percent sing from 97%%");
  SFree(a);
  SFree(b);
  
  // test
  a = SCreate("  Mono: Playback 62 [97%] [-2.00dB] [on]");
  i = SPos(a,"[");
  j = SPos(a,"]");
  b = SCreateBetween(a,i+1,j-1);
  c = SCreateReplace(b,"%","");
  k = SInt(c);
  STestI(k,97,"extracting alsa volume");
  SFree(a);
  SFree(b);
  SFree(c);
  
  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  b = SCreateBetween(a,10,50);
  STest(b,"Abcde","create string between longer that source");
  SFree(a);
  SFree(b);

  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  i = SPosFrom(a,"A",0);
  STestI(i,0,"position from 0 at 0");
  SFree(a);

  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  i = SPosFrom(a,"A",1);
  STestI(i,5,"position from 1 at 5");
  SFree(a);

  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  i = SPosFrom(a,"A",8);
  STestI(i,10,"position from 8 at 10");
  SFree(a);

  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  i = SPosFrom(a,"A",11);
  STestI(i,-1,"position from 11 at -1");
  SFree(a);

  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  i = SPosFrom(a,"e",11);
  STestI(i,14,"position from 14 at -1");
  SFree(a);

  if (S_DEBUG_LEVEL >= 1)
    printf("STest: all %d tests passed\n",S_TEST_ID);
  S_DEBUG_LEVEL=ol;        
}