//rotate right uint32_t ror(uint32_t value, int amount, int Sbit, struct state *sPtr){ uint32_t rotated = 0; for(int i = 31; i >= 0; i--){ rotated <<= 1; int pos = (i+32+amount)%32; rotated |= checkBin(value, pos, pos); if(Sbit == 1){ setCBit(checkBin(rotated,31,31), sPtr); } } return rotated; }
void setCPSR(uint32_t result, int Sbit, struct state *sPtr){ if(Sbit == 1){ if(result == 0){ setZBit(1, sPtr); } else { setZBit(0, sPtr); } setNBit(checkBin(result,31,31), sPtr); } }
//logical shift left uint32_t lsl(uint32_t value, int amount, int Sbit, struct state *sPtr){ uint32_t shifted = value << amount; if(amount != 0){ int carry = checkBin(value, 32-amount, 32-amount); if(Sbit == 1){ setCBit(carry, sPtr); } } return shifted; }
double crossValidation(const std::vector<Example>& examples, const std::vector<unsigned>& topology, unsigned bins) { std::vector<Example> shuff(examples); std::random_shuffle(shuff.begin(), shuff.end()); std::vector<Examples> sets; partition(sets, shuff, bins); double error = 0.0; for(unsigned i = 0; i < bins; i++) { error += checkBin(i, sets, topology, examples.size()); } return error / bins; }
int main(int argc, char** argv) { char* appDir = getenv("APPDIR"); char bin[] = "ls"; if (appDir == NULL) { fprintf(stderr, "Invalid application directory.\n"); return 1; } char* cmd = (char*)malloc((strlen(appDir) + 1 + strlen(bin) + 1) * sizeof(char)); strcpy(cmd, appDir); strcat(cmd, "/"); strcat(cmd, bin); if (checkBin(cmd)) { system(cmd); } else { printf("The binary is corrupted.\n"); } return 0; }
uint32_t rotateRTwo(uint32_t exp) { //Rotate right twice to for operand immediate check int lastTwo = checkBin(exp, 0, 1); exp >>= 2; exp |= lastTwo << 30; return exp; }