IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 26, 2019, 8:48:49 AM (7 years ago)
Author:
eugene
Message:

adding bitshift operators

Location:
branches/eam_branches/ipp-20191011/Ohana/src/opihi/lib.shell
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20191011/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r40291 r41137  
    7878    if (!strcmp (argv[i], "atan2"))  { type = ST_BINARY; strcpy (argv[i], "a"); goto gotit; }
    7979    if (!strcmp (argv[i], "datan2")) { type = ST_BINARY; strcpy (argv[i], "d"); goto gotit; }
     80
     81    if (!strcmp (argv[i], "<-"))     { type = ST_BINARY; strcpy (argv[i], "l"); goto gotit; }
     82    if (!strcmp (argv[i], "->"))     { type = ST_BINARY; strcpy (argv[i], "r"); goto gotit; }
     83
    8084    if (!strcmp (argv[i], ","))      { type = ST_COMMA; goto gotit; }
    8185
     
    99103    if (!strcmp (argv[i], ">>"))     { type = ST_LOGIC; strcpy (argv[i], "U"); goto gotit; }
    100104    if (!strcmp (argv[i], "<<"))     { type = ST_LOGIC; strcpy (argv[i], "D"); goto gotit; }
     105
     106    /* XXX I would like to change the syntax to allow << and >> to mean bitshifts
     107       but that means breaking these older values which means MIN and MAX */
     108    // for now, use <- and -> to mean bitshift
    101109
    102110    if (!strcmp (argv[i], "&&"))     { type = ST_AND; strcpy (argv[i], "A"); goto gotit; }
  • branches/eam_branches/ipp-20191011/Ohana/src/opihi/lib.shell/stack_math.c

    r40331 r41137  
    357357    case 'A': VV_FUNC(ST_SCALAR_INT, (*M1 && *M2) ? 1 : 0);
    358358    case 'O': VV_FUNC(ST_SCALAR_INT, (*M1 || *M2) ? 1 : 0);
     359
     360    case 'l': {
     361      if ((V1->vector->type == OPIHI_FLT) || (V2->vector->type == OPIHI_FLT)) {
     362        // bitshift is not valid with float valuess
     363        CopyVector (OUT[0].vector, V1[0].vector);
     364        for (i = 0; i < Nx; i++) {
     365          OUT[0].vector[0].elements.Flt[i] = NAN;
     366        }
     367        break;
     368      }
     369      // I could just do this for all types and bitshift regardless...
     370      opihi_int *M1  =  V1[0].vector[0].elements.Int;
     371      opihi_int *M2  =  V2[0].vector[0].elements.Int;
     372      opihi_int *out = OUT[0].vector[0].elements.Int;
     373      for (i = 0; i < Nx; i++, out++, M1++, M2++) {
     374        *out = *M1 << *M2;
     375      }
     376      break;
     377    }
     378
     379    case 'r': {
     380      if ((V1->vector->type == OPIHI_FLT) || (V2->vector->type == OPIHI_FLT)) {
     381        // bitshift is not valid with float valuess
     382        CopyVector (OUT[0].vector, V1[0].vector);
     383        for (i = 0; i < Nx; i++) {
     384          OUT[0].vector[0].elements.Flt[i] = NAN;
     385        }
     386        break;
     387      }
     388      // I could just do this for all types and bitshift regardless...
     389      opihi_int *M1  =  V1[0].vector[0].elements.Int;
     390      opihi_int *M2  =  V2[0].vector[0].elements.Int;
     391      opihi_int *out = OUT[0].vector[0].elements.Int;
     392      for (i = 0; i < Nx; i++, out++, M1++, M2++) {
     393        *out = *M1 >> *M2;
     394      }
     395      break;
     396    }
     397
    359398    default:
    360399      snprintf (line, 512, "error: op %c not defined!", op[0]);
     
    469508    case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);
    470509    case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);
     510
     511    case 'l': {
     512      if (V2->vector->type == OPIHI_FLT) {
     513        // bitshift is not valid with float valuess
     514        CopyVector (OUT[0].vector, V2[0].vector);
     515        for (i = 0; i < Nx; i++) {
     516          OUT[0].vector[0].elements.Flt[i] = NAN;
     517        }
     518        break;
     519      }
     520      opihi_int  M1  =  V1[0].IntValue;                                 \
     521      opihi_int *M2  =  V2[0].vector[0].elements.Int;
     522      opihi_int *out = OUT[0].vector[0].elements.Int;
     523      for (i = 0; i < Nx; i++, out++, M2++) {
     524        *out = M1 << *M2;
     525      }
     526      break;
     527    }
     528
     529    case 'r': {
     530      if (V2->vector->type == OPIHI_FLT) {
     531        // bitshift is not valid with float valuess
     532        CopyVector (OUT[0].vector, V2[0].vector);
     533        for (i = 0; i < Nx; i++) {
     534          OUT[0].vector[0].elements.Flt[i] = NAN;
     535        }
     536        break;
     537      }
     538      opihi_int  M1  =  V1[0].IntValue;                                 \
     539      opihi_int *M2  =  V2[0].vector[0].elements.Int;
     540      opihi_int *out = OUT[0].vector[0].elements.Int;
     541      for (i = 0; i < Nx; i++, out++, M2++) {
     542        *out = M1 >> *M2;
     543      }
     544      break;
     545    }
     546
    471547    default:
    472548      snprintf (line, 512, "error: op %c not defined!", op[0]);
     
    577653    case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);
    578654    case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);
     655
     656    case 'l': {
     657      if (V1->vector->type == OPIHI_FLT) {
     658        // bitshift is not valid with float valuess
     659        CopyVector (OUT[0].vector, V1[0].vector);
     660        for (i = 0; i < Nx; i++) {
     661          OUT[0].vector[0].elements.Flt[i] = NAN;
     662        }
     663        break;
     664      }
     665      opihi_int *M1  =  V1[0].vector[0].elements.Int;
     666      opihi_int  M2  =  V2[0].IntValue;                                 \
     667      opihi_int *out = OUT[0].vector[0].elements.Int;
     668      for (i = 0; i < Nx; i++, out++, M1++) {
     669        *out = *M1 << M2;
     670      }
     671      break;
     672    }
     673
     674    case 'r': {
     675      if (V1->vector->type == OPIHI_FLT) {
     676        // bitshift is not valid with float valuess
     677        CopyVector (OUT[0].vector, V1[0].vector);
     678        for (i = 0; i < Nx; i++) {
     679          OUT[0].vector[0].elements.Flt[i] = NAN;
     680        }
     681        break;
     682      }
     683      opihi_int *M1  =  V1[0].vector[0].elements.Int;
     684      opihi_int  M2  =  V2[0].IntValue;                                 \
     685      opihi_int *out = OUT[0].vector[0].elements.Int;
     686      for (i = 0; i < Nx; i++, out++, M1++) {
     687        *out = *M1 >> M2;
     688      }
     689      break;
     690    }
     691
    579692    default:
    580693      snprintf (line, 512, "error: op %c not defined!", op[0]);
     
    670783    case 'A': MV_FUNC((*M1 && *M2) ? 1 : 0);
    671784    case 'O': MV_FUNC((*M1 || *M2) ? 1 : 0);
     785
     786    case 'l': {
     787      if (V1->vector->type == OPIHI_FLT) {
     788        // bitshift is not valid with float valuess
     789        CopyVector (OUT[0].vector, V1[0].vector);
     790        for (i = 0; i < Nx; i++) {
     791          OUT[0].vector[0].elements.Flt[i] = NAN;
     792        }
     793        break;
     794      }
     795      opihi_int *M1  =  V1[0].vector[0].elements.Int;
     796      opihi_int  M2  =  V2[0].IntValue;                                 \
     797      opihi_int *out = OUT[0].vector[0].elements.Int;
     798      for (i = 0; i < Nx; i++, out++, M1++) {
     799        *out = *M1 << M2;
     800      }
     801      break;
     802    }
     803
     804    case 'r': {
     805      if (V1->vector->type == OPIHI_FLT) {
     806        // bitshift is not valid with float valuess
     807        CopyVector (OUT[0].vector, V1[0].vector);
     808        for (i = 0; i < Nx; i++) {
     809          OUT[0].vector[0].elements.Flt[i] = NAN;
     810        }
     811        break;
     812      }
     813      opihi_int *M1  =  V1[0].vector[0].elements.Int;
     814      opihi_int  M2  =  V2[0].IntValue;                                 \
     815      opihi_int *out = OUT[0].vector[0].elements.Int;
     816      for (i = 0; i < Nx; i++, out++, M1++) {
     817        *out = *M1 >> M2;
     818      }
     819      break;
     820    }
     821
    672822    default:
    673823      snprintf (line, 512, "error: op %c not defined!", op[0]);
Note: See TracChangeset for help on using the changeset viewer.