lundi 25 octobre 2021

combining different selection statements into one massive one without explicitly doing that in c++

Hi so I have a slightly odd problem where I am storing some data/instructions as a series of integers, transmitting them and doing some different stuff based on them.

Each integer gets split into 2 shorts, op1 and op2 and the last few bytes of op2 are also read separately as op3.

I then use op2 and op3 to collect some values (val1 and val2 here) and basically perform a statement that looks like this:

switch op1{
    case 0:
      val1 = val2;
      break;
    case 1:
      val1 += val2;
      break;
    case ...
}

however I need this code to be executing upwards of a few million times a second for my program to run effectively so ideally I want my output executable to be doing more of a switch statement that looks like:

switch op {
    case op1==0 && op2==0 && op3==0: ...
    case op1==0 && op2==0 && op3==1: ...
    case op1==0 && op2==1 && op3==0: ...
    case op1==0 && op2==1 && op3==1: ...
    case...
}

where basically instead of dividing up the integer and checking each short separately, I just check the whole integer and create some output code, however, this would be a very messy way to program this as A). I would have to write out a lot of statements by hand, more than I'm realistically willing to and B). that would lead to a lot of code duplication and code that's hard to update in the long run.

Currently I'm working in c++ but I was messing around with D and was also considering rust or go before I started, the project itself isn't massive and I just want to be able to do this easily so the massive isn't super important to me so if any of these languages make it easier than c++ I wouldn't mind switching.

Sry I realise that this is a really unusual question, hope it makes sense, please believe I'm not insane, thankyou

Aucun commentaire:

Enregistrer un commentaire