std::vector<Unity> TileGrid::getUnitiesOnPosition(sf::Vector2f playerUpperLeft) const{ std::vector<Unity> adjacent; sf::Vector2i ul = sf::Vector2i((int) playerUpperLeft.x/unitySize, (int) playerUpperLeft.y/unitySize); sf::Vector2i ll = sf::Vector2i((int) playerUpperLeft.x/unitySize, (int) (playerUpperLeft.y + 32)/unitySize); sf::Vector2i ur = sf::Vector2i((int) (playerUpperLeft.x + 32)/unitySize, (int) playerUpperLeft.y/unitySize); sf::Vector2i lr = sf::Vector2i((int) (playerUpperLeft.x + 32)/unitySize, (int) (playerUpperLeft.y + 32)/unitySize); ul = checkCondition(ul); ll = checkCondition(ll); ur = checkCondition(ur); lr = checkCondition(lr); int upperLeft = ul.x + ul.y * xCells; int lowerLeft = ll.x + ll.y * xCells; int upperRight = ur.x + ur.y * xCells; int lowerRight = lr.x + lr.y * xCells; adjacent.push_back(upperLeft >= (xCells * yCells) ? this->unities[xCells * yCells - 1] : this->unities[upperLeft]); if(lowerLeft != upperLeft){ adjacent.push_back(lowerLeft >= (xCells * yCells) ? this->unities[xCells * yCells - 1] : this->unities[lowerLeft]); } if(upperRight != lowerLeft && upperRight != upperLeft){ adjacent.push_back(upperRight >= (xCells * yCells) ? this->unities[xCells * yCells - 1] : this->unities[upperRight]); } if(lowerRight != upperRight && lowerRight != lowerLeft && lowerRight != upperLeft){ adjacent.push_back(lowerRight >= (xCells * yCells) ? this->unities[xCells * yCells - 1] : this->unities[lowerRight]); } return adjacent; }
ExprType ExprPrototypeNode::prep(bool wantScalar, ExprVarEnvBuilder& envBuilder) { // TODO: implement prototype bool error=false; checkCondition(false, "Prototypes are currently not supported",error); return ExprType().Error(); #if 0 bool error = false; if (_retTypeSet) checkCondition(returnType().isValid(), "Function has bad return type", error); _argTypes.clear(); for (int c = 0; c < numChildren(); c++) { ExprType type = child(c)->type(); checkCondition(type.isValid(), "Function has a parameter with a bad type", error); _argTypes.push_back(type); ExprLocalVar* localVar = new ExprLocalVar(type); envBuilder.current()->add(((ExprVarNode*)child(c))->name(), localVar); std::cerr << "after create localvar phi " << localVar->getPhi() << std::endl; child(c)->prep(wantScalar, envBuilder); } if (error) setType(ExprType().Error()); else setType(ExprType().None().Varying()); return _type; #endif }
ExprType ExprFuncNode::prep(bool wantScalar, ExprVarEnvBuilder& envBuilder) { bool error = false; int nargs = numChildren(); _promote.resize(nargs, 0); // find function using per-expression callback and then global table // TODO: put lookup of local functions here _func = 0; if (ExprLocalFunctionNode* localFunction = envBuilder.current()->findFunction(_name)) { _localFunc = localFunction; setTypeWithChildLife(localFunction->prep(this, wantScalar, envBuilder)); // TODO: we need to type check arguments here } else { if (!_func) _func = _expr->resolveFunc(_name); if (!_func) _func = ExprFunc::lookup(_name); // check that function exists and that the function has the right number of arguments if (checkCondition(_func, "Function " + _name + " has no definition", error) && checkCondition(nargs >= _func->minArgs(), "Too few args for function" + _name, error) && checkCondition( nargs <= _func->maxArgs() || _func->maxArgs() < 0, "Too many args for function " + _name, error)) { const ExprFuncX* funcx = _func->funcx(); ExprType type = funcx->prep(this, wantScalar, envBuilder); setTypeWithChildLife(type); } else { // didn't match num args or function not found ExprNode::prep(false, envBuilder); // prep arguments anyways to catch as many errors as possible! setTypeWithChildLife(ExprType().Error()); } } return _type; }
static GLuint loadProgram(const char* pVS, const char* pFS, int aCount, const char* attribs[], int vCount, const char* varyings[]) { GLint compileSuccess, linkSuccess; GLchar compilerSpew[256]; GLuint programHandle = glCreateProgram(); GLuint vsHandle = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vsHandle, 1, &pVS, 0); glCompileShader(vsHandle); glGetShaderiv(vsHandle, GL_COMPILE_STATUS, &compileSuccess); glGetShaderInfoLog(vsHandle, sizeof(compilerSpew), 0, compilerSpew); checkCondition(compileSuccess, ("Can't compile VS:\n%s", compilerSpew)); glAttachShader(programHandle, vsHandle); GLuint fsHandle = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fsHandle, 1, &pFS, 0); glCompileShader(fsHandle); glGetShaderiv(fsHandle, GL_COMPILE_STATUS, &compileSuccess); glGetShaderInfoLog(fsHandle, sizeof(compilerSpew), 0, compilerSpew); checkCondition(compileSuccess, ("Can't compile FS:\n%s", compilerSpew)); glAttachShader(programHandle, fsHandle); for (int a = 0; a < aCount; a++) glBindAttribLocation(programHandle, a, attribs[a]); if (vCount) { glTransformFeedbackVaryings(programHandle, vCount, varyings, GL_INTERLEAVED_ATTRIBS); checkCondition(glGetError() == GL_NO_ERROR, "OpenGL error."); } glLinkProgram(programHandle); glGetProgramiv(programHandle, GL_LINK_STATUS, &linkSuccess); glGetProgramInfoLog(programHandle, sizeof(compilerSpew), 0, compilerSpew); checkCondition(linkSuccess, compilerSpew); int total = -1; glGetProgramiv(programHandle, GL_ACTIVE_UNIFORMS, &total); for(int i = 0; i < total; ++i) { int name_len=-1, num=-1; GLenum type = GL_ZERO; char name[100]; glGetActiveUniform(programHandle, GLuint(i), sizeof(name)-1, &name_len, &num, &type, name); name[name_len] = '\0'; GLuint location = glGetUniformLocation(programHandle, name); printf("uniform[%d]: %s\n", location, name); } glUseProgram(programHandle); return programHandle; }
ExprType ExprVarNode::prep(bool wantScalar, ExprVarEnvBuilder& envBuilder) { // ask expression to resolve var bool error = false; if ((_localVar = envBuilder.current()->find(name()))) { if(_localVar->type().isError()){ /// Some friendlier error suggestions if(ExprLocalVarPhi* phi=dynamic_cast<ExprLocalVarPhi*>(_localVar)){ if(!phi->_thenVar->type().isError() && !phi->_elseVar->type().isError()){ addError(std::string("Variable ")+name()+" defined in conditionals inconsistently."); } } } setType(_localVar->type()); return _type; } else { // user defined external variable _var = _expr->resolveVar(name()); if (!_var) { if (const VarBlockCreator* creator = _expr->varBlockCreator()) { // data block defined external var _var = creator->resolveVar(name()); } } if (_var) { _expr->addVar(name()); // register used variable so _expr->usedVar() works setType(_var->type()); return _type; } } // If we get here we do not have a variable! checkCondition(_var || _localVar, std::string("No variable named ''") + name() + "'", error); setType(ExprType().Error()); return _type; }
ExprType ExprCondNode::prep(bool wantScalar, ExprVarEnvBuilder& envBuilder) { // TODO: determine if extra environments are necessary, currently not included ExprType condType, thenType, elseType; bool error = false; condType = child(0)->prep(true, envBuilder); checkIsFP(condType, error); thenType = child(1)->prep(wantScalar, envBuilder); elseType = child(2)->prep(wantScalar, envBuilder); checkIsValue(thenType, error); checkIsValue(elseType, error); checkCondition(ExprType::valuesCompatible(thenType, elseType), "Types of conditional are not compatible", error); if (error) setType(ExprType().Error()); else { if (thenType.isString()) setType(thenType); else setType(thenType.isFP(1) ? elseType : thenType); _type.setLifetime(condType, thenType, elseType); } return _type; }
void parseBlackList() { QString filename = QTest::qFindTestData(QStringLiteral("BLACKLIST")); if (filename.isEmpty()) return; QFile ignored(filename); if (!ignored.open(QIODevice::ReadOnly)) return; QByteArray function; while (!ignored.atEnd()) { QByteArray line = ignored.readLine().simplified(); if (line.isEmpty() || line.startsWith('#')) continue; if (line.startsWith('[')) { function = line.mid(1, line.length() - 2); continue; } bool condition = checkCondition(line); if (condition) { if (!function.size()) { ignoreAll = true; } else { if (!ignoredTests) ignoredTests = new std::set<QByteArray>; ignoredTests->insert(function); } } } }
bool CDropManager::doDrop(CPC* _pPC, CNPC * _pNPC, const int _dropIndex, const int _prob, const int _pos, bool _bPreferenceIndex) { if( _pPC == NULL || _pNPC == NULL ) { GAMELOG << init("EVENT_AUTOMATION_WARN") << "_pPC, _pNPC is 0" << end; return false; } CDropInfo * pDrop = getDropInfo(_dropIndex); if( pDrop == NULL ) return false; if( !checkCondition( _pPC, _pNPC, pDrop) ) return false; switch( pDrop->getDropType() ) { case 0: // Multi 확률만 맞는 아이템은 다 떨어 뜨린다. return doDropRandom(_pPC, _pNPC, pDrop, _bPreferenceIndex); case 1: // Once-Random 리스트중에 확률에 따라 하나만 떨구나. return doDropOnceRandom(_pPC, _pNPC, pDrop, _prob, _bPreferenceIndex); case 2: // Once-Select 리스트중에 하나를 선택해 드랍 // 외부 선택으로 돌릴까나? ㅡㅡ; return doDropOnceSelect(_pPC, _pNPC, pDrop, _pos, _bPreferenceIndex); default: return false; } return true; }
// TODO: Check if clickables overlap and warn accordingly void gsGame::switchToView() { for (auto& pair : directions) { pair.second = ""; } clickAreas.clear(); sprites.clear(); items.clear(); line1.setText(""); line2.setText(""); for (auto module : activeModules) { module->leave(); } activeModules.clear(); bg = g_tm->getTexture("game", "black.png"); if (transitionStart != -1 && SDL_GetTicks() - transitionStart < transitionTime) { return; } if (view.find("onLeave") != view.end()) { for (auto action : view["onLeave"]) { doAction(action.get<std::string>()); } } std::string file = "media/views/" + nextView + ".json"; view = jsonFromFile(file); if (view.find("bg") != view.end()) { bg = g_tm->getTexture("views", view["bg"]); } else { bg = g_tm->getTexture("views", nextView + ".png"); } for (auto dir : possibleDirections) { directions[dir] = ""; if (view.find(dir) != view.end()) { directions[dir] = view[dir].get<std::string>(); } } extractModifiers(view); if (view.find("triggers") != view.end()) { json triggers = view["triggers"]; for (auto trigger : triggers) { if (checkCondition(trigger["condition"].get<std::string>())) { extractModifiers(trigger["modifiers"]); break; } } } // Make sure we don't change view again transitionStart = -1; transitionTime = -1; nextView = ""; }
void CueContrastKernel::runkernel(CvPoint2D32f* nextpos, CSCVector* prob_cand, float* rel, float hval) { if(debug) std::cout << getName() << "::runkernel()\n"; bool result = false; int count = 0; CvPoint2D32f oldpos = m_y0; //CvSize objsize = m_track.winnerSize; if(debug) std::cout << getName() << "::runkernel()::oldpos = [" << oldpos.x << " " << oldpos.y << "]\n"; while(!result){ switch(m_opmode) { case SIMPLE: //cropNResize(&oldpos, &objsize, hval); cropNResize(&oldpos, &m_objsizenorm, hval); calculateProbability(prob_cand, hval); break; default: std::cerr << getName() << "::runkernel()::Currently only SIMPLE mode is supported!\n"; return; } computeWeights(prob_cand); // Step2 findNextLocation(nextpos, hval); // Step 3 //if(debug) std::cout << getName() << "::runkernel()::nextpos = [" << nextpos->x << " " << nextpos->y << "]\n"; result = checkCondition(&oldpos, nextpos, count); // Step 6 if(debug) std::cout << getName() << "::runkernel()::count = " << count << ", nextpos = [" << nextpos->x << ", " << nextpos->y << "]\n"; count++; } (*rel) = computeSimilarity(prob_cand, &m_target_model); if(debug) std::cout << getName() << "::runkernel()::while() loop complete::count = " << count << ", rel = " << (*rel) << ", nextpos = [" << nextpos->x << ", " << nextpos->y << "]\n"; }
/* BIC Immediate Encoding T1 BIC{S}<c> <Rd>,<Rn>,#<const> 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |1 1 1 1 0 |i||0| 0 0 0 1 |S| Rn |0| imm3 | Rd | imm8 | where: S If present, specifies that the instruction updates the flags. Otherwise, the instruction does not update the flags. <c><q> See Standard assembler syntax fields on page A6-7. <Rd> Specifies the destination register. If <Rd> is omitted, this register is the same as <Rn>. <Rn> Specifies the register that contains the operand. <const> Specifies the immediate value to be tested against the value obtained from <Rn>. See Modified immediate constants in Thumb instructions on page A5-15 for the range of allowed values. */ void BICImmediateT1(uint32_t instruction) { uint32_t imm8 = getBits(instruction, 7, 0); uint32_t Rd = getBits(instruction, 11, 8); uint32_t Rn = getBits(instruction, 19, 16); uint32_t imm3 = getBits(instruction, 14, 12); uint32_t statusFlag = getBits(instruction, 20, 20); uint32_t i = getBits(instruction, 26, 26); uint32_t bit7 = getBits(instruction, 7, 7); uint32_t temp = (i << 3 ) | imm3; uint32_t modifyControl = (temp << 1) | bit7; uint32_t ModifiedConstant = ModifyImmediateConstant(modifyControl, imm8, statusFlag); if(inITBlock()) { if( checkCondition(cond) ) executeBICImmediate(ModifiedConstant, Rd, Rn, statusFlag); shiftITState(); } else executeBICImmediate(ModifiedConstant, Rd, Rn, statusFlag); coreReg[PC] += 4; }
void SymbolCheckVisitor::visit(ASTWhile& ast) { ast.getCondition().accept(*this); checkCondition(ast, mCurrentType); ast.getBody().accept(*this); }
/* VABS Floating-point Absolute takes the absolute value of a single-precision register, and places the result in a second register. VABS<c>.F32 <Sd>, <Sm> 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |1 1 1 0| 1 1 1 0 1| D| 1 1| 0 0 0 0| Vd | 1 0 1 sz 1 1 M 0| Vm | where : <c>, <q> See Standard assembler syntax fields on page A7-175. <Sd>, <Sm> The destination single-precision register and the operand single-precision register. <Dd>, <Dm> The destination double-precision register and the operand double-precision register, for a double-precision operation. */ void VABS(uint32_t instruction) { uint32_t Vd = getBits(instruction,15,12); uint32_t Vm = getBits(instruction,3,0); uint32_t sz = getBits(instruction,8,8); uint32_t M = getBits(instruction,5,5); uint32_t D = getBits(instruction,22,22); uint32_t d = determineRegisterBasedOnSZ(D, Vd, sz); uint32_t m = determineRegisterBasedOnSZ(M, Vm, sz); executeFPUChecking(); if(inITBlock()) { if( checkCondition(cond) ) { if(sz == 1) ThrowError(); //undefined instruction if sz == 1 in FPv4-SP architecture else writeSinglePrecision(d, FPAbs(fpuSinglePrecision[m], 32 ) ); } shiftITState(); } else { if(sz == 1) ThrowError(); //undefined instruction if sz == 1 in FPv4-SP architecture else writeSinglePrecision(d, FPAbs(fpuSinglePrecision[m], 32 ) ); } coreReg[PC] += 4; }
/*Load Register Signed Halfword (immediate) Encoding T2 LDRSH<c> <Rt>,[<Rn>,#-<imm8>] LDRSH<c> <Rt>,[<Rn>],#+/-<imm8> LDRSH<c> <Rt>,[<Rn>,#+/-<imm8>]! 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 | 1 1 1 1 1| 0 0| 1 0 0 1 1| Rn | Rt | 1| P|U|W| imm8 | where: <c><q> See Standard assembler syntax fields on page A6-7. <Rt> Specifies the destination register. <Rn> Specifies the base register. This register is allowed to be the SP. If this register is the PC, see LDRSH (literal) on page A6-120. +/- Is + or omitted to indicate that the immediate offset is added to the base register value (add == TRUE), or – to indicate that the offset is to be subtracted (add == FALSE). Different instructions are generated for #0 and #-0. <imm> Specifies the immediate offset added to or subtracted from the value of <Rn> to form the address. The range of allowed values is 0-4095 for encoding T1, and 0-255 for encoding T2. For the offset addressing syntax, <imm> can be omitted, meaning an offset of 0. */ void LDRSHImmediateT2(uint32_t instruction) { uint32_t imm8 = getBits(instruction, 7, 0); uint32_t Rt = getBits(instruction,15,12); uint32_t Rn = getBits(instruction,19,16); uint32_t W = getBits(instruction,8,8); uint32_t U = getBits(instruction,9,9); uint32_t P = getBits(instruction,10,10); uint32_t address; if(U == 1) address = coreReg[Rn] + imm8; else address = coreReg[Rn] - imm8; int check = isOffPostOrPreIndex(P,W); if(check == UNDEFINED || Rt == 0b1111 || Rn == 0b1111) ThrowError(); if(inITBlock()) { if( checkCondition(cond) ) { if(check == OFFINDEX) writeToCoreRegisters(Rt , signExtend( loadByteFromMemory(address, 2), 16) ); else if(check == PREINDEX) { writeToCoreRegisters(Rt , signExtend( loadByteFromMemory(address, 2), 16) ); coreReg[Rn] = address; } else { writeToCoreRegisters(Rt , signExtend( loadByteFromMemory(coreReg[Rn], 2), 16) ); coreReg[Rn] = address; } } shiftITState(); } else { if(check == OFFINDEX) writeToCoreRegisters(Rt , signExtend( loadByteFromMemory(address, 2), 16) ); else if(check == PREINDEX) { writeToCoreRegisters(Rt , signExtend( loadByteFromMemory(address, 2), 16) ); coreReg[Rn] = address; } else { writeToCoreRegisters(Rt , signExtend( loadByteFromMemory(coreReg[Rn], 2), 16) ); coreReg[Rn] = address; } } coreReg[PC] += 4; }
//test case for CC void test_checkCondition_given_0011_and_C_flag_not_set_should_return_1(void) { //create test case cond = 0b0011; resetCarryFlag(); int result = checkCondition(cond); TEST_ASSERT_EQUAL(1,result); }
//test case for VC void test_checkCondition_given_0111_and_OV_flag_set_should_return_0(void) { //create test case cond = 0b0111; setOverflowFlag(); int result = checkCondition(cond); TEST_ASSERT_EQUAL(0,result); }
//test case for PL void test_checkCondition_given_0101_and_N_flag_not_set_should_return_1(void) { //create test case cond = 0b0101; resetNegativeFlag(); int result = checkCondition(cond); TEST_ASSERT_EQUAL(1,result); }
update_status DisappearOutCamera::update() { if (collider->isEnable()) { //if necessary conditions is true and check if entity is outside of the camera and destroy if (checkCondition() && outsideCamera()) { parent->destroy(); } } return UPDATE_CONTINUE; }
//test case for NE void test_checkCondition_given_0001_and_Z_flag_set_should_return_0(void) { //create test case cond = 0b0001; setZeroFlag(); int result = checkCondition(cond); TEST_ASSERT_EQUAL(0,result); }
//test case for LT void test_checkCondition_given_1011_if_N_flag_set_and_OV_flag_reset_should_return_1(void) { //create test case cond = 0b1011; setNegativeFlag(); resetOverflowFlag(); int result = checkCondition(cond); TEST_ASSERT_EQUAL(1,result); }
//test case for GE void test_checkCondition_given_1010_if_N_flag_and_OV_flag_different_should_return_0(void) { //create test case cond = 0b1010; resetNegativeFlag(); setOverflowFlag(); int result = checkCondition(cond); TEST_ASSERT_EQUAL(0,result); }
//test case for HI void test_checkCondition_given_1000_and_C_flag_set_and_Z_flag_reset_should_return_1(void) { //create test case cond = 0b1000; setCarryFlag(); resetZeroFlag(); int result = checkCondition(cond); TEST_ASSERT_EQUAL(1,result); }
ExprType ExprLocalFunctionNode::prep(bool wantScalar, ExprVarEnvBuilder& envBuilder) { #if 0 // TODO: no local functions for now bool error = false; // prep prototype and check for errors ExprPrototypeNode* prototype = (ExprPrototypeNode*)child(0); ExprVarEnv functionEnv; functionEnv.resetAndSetParent(&env); if (!prototype->prep(false, functionEnv).isValid()) error = true; // decide what return type we want bool returnWantsScalar = false; if (!error && prototype->isReturnTypeSet()) returnWantsScalar = prototype->returnType().isFP(1); // prep block and check for errors ExprNode* block = child(1); ExprType blockType = block->prep(returnWantsScalar, functionEnv); if (!error && blockType.isValid()) { if (prototype->isReturnTypeSet()) { if (blockType != prototype->returnType()) { checkCondition(false, "In function result of block '" + blockType.toString() + "' does not match given return type " + prototype->returnType().toString(), error); } } else prototype->setReturnType(blockType); // register the function in the symbol table env.addFunction(prototype->name(), this); } else { checkCondition(false, "Invalid type for blockType is " + blockType.toString(), error); error = true; } return _type = error ? ExprType().Error() : ExprType().None().Varying(); #else bool error=false; checkCondition(false,"Local functions are currently not supported.",error); return ExprType().Error(); #endif }
//test case for LE // possibility 4: N is 1, OV is 1, Z is 0 void test_checkCondition_given_1101_and_possiblilty4_should_return_0(void) { //create test case cond = 0b1101; setNegativeFlag(); setOverflowFlag(); resetZeroFlag(); int result = checkCondition(cond); TEST_ASSERT_EQUAL(0,result); }
void SymbolCheckVisitor::visit(ASTIf& ast) { ast.getCondition().accept(*this); checkCondition(ast, mCurrentType); ast.getStatement().accept(*this); if ( ast.hasElseStatement() ) { ast.getElseStatement().accept(*this); } }
/** * Returns the relation with only the selected tuples following the selection operator * operator.op: logic operator (<, <=, ==, >=, >) * operator.column: the index of the column to be evaluated * operator.value: the value to be compared with the column using the logic operator * * @param relation Relation object * @param op Operator struct * @return Relation */ Relation select(Relation relation, Operator op) { for (int i = 0; i < relation.size(); i++) { vector<float> tupla = relation.getTupla(i); if ( !checkCondition(op.value, tupla[op.column], op.op) ) { relation.removeTupla(i); } } return relation; }
ExprType ExprAssignNode::prep(bool wantScalar, ExprVarEnvBuilder& envBuilder) { _assignedType = child(0)->prep(false, envBuilder); std::unique_ptr<ExprLocalVar> localVar(new ExprLocalVar(child(0)->type())); _localVar = localVar.get(); envBuilder.current()->add(_name, std::move(localVar)); bool error = false; checkCondition( _assignedType.isValid(), std::string("Assignment operation has bad type: ") + _type.toString(), error); if (error) setType(ExprType().Error()); else setTypeWithChildLife(ExprType().None()); return _type; }
int getCount(int *arr, int n) { int i, j, k, cnt = 0; for (i = 0; i < n-2; ++i) { for (j = i+1; j < n-1; ++j) { for (k = j+1; k < n; ++k) { if (checkCondition(arr[i], arr[j], arr[k])) cnt++; } } } return cnt; }
/*Test Register Encoding T1 TST<c> <Rn>,<Rm> 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |0 1 0 0 0 0| 1 0 0 0| Rm | Rn | unused | where: <c><q> See Standard assembler syntax fields on page A6-7. <Rn> Specifies the register that contains the first operand. <Rm> Specifies the register that is optionally shifted and used as the second operand. <shift> Specifies the shift to apply to the value read from <Rm>. If <shift> is omitted, no shift is applied and both encodings are permitted. If <shift> is specified, only encoding T2 is permitted. The possible shifts and how they are encoded are described in Shifts applied to a register on page A6-12. */ void TSTRegisterT1(uint32_t instruction) { uint32_t Rm = getBits(instruction,21,19); uint32_t Rn = getBits(instruction,18,16); if(inITBlock()) { if( checkCondition(cond) ) executeTSTRegister(Rn, Rm, 0, 0); shiftITState(); } else executeTSTRegister(Rn, Rm, 0, 0); coreReg[PC] += 2; }
/*Load Register(Immediate) Encoding T3 LDR<c>.W <Rt>,[<Rn>{,#<imm12>}] 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |1 1 1 1 1| 0 0| 0 1 1 0 1| Rn | Rt | imm12 | where: <c><q> See Standard assembler syntax fields on page A6-7. <Rt> Specifies the destination register. This register is allowed to be the SP. It is also allowed to be the PC, provided the instruction is either outside an IT block or the last instruction of an IT block. If it is the PC, it causes a branch to the address (data) loaded into the PC. <Rn> Specifies the base register. This register is allowed to be the SP. If this register is the PC, see LDR (literal) on page A6-90. +/- Is + or omitted to indicate that the immediate offset is added to the base register value (add == TRUE), or – to indicate that the offset is to be subtracted (add == FALSE). Different instructions are generated for #0 and #-0. <imm> Specifies the immediate offset added to or subtracted from the value of <Rn> to form the address. Allowed values are multiples of 4 in the range 0-124 for encoding T1, multiples of 4 in the range 0-1020 for encoding T2, any value in the range 0-4095 for encoding T3, and any value in the range 0-255 for encoding T4. For the offset addressing syntax, <imm> can be omitted, meaning an offset of 0. */ void LDRImmediateT3(uint32_t instruction) { uint32_t imm12 = getBits(instruction,11,0); uint32_t Rn = getBits(instruction,19,16); uint32_t Rt = getBits(instruction,15,12); uint32_t address = coreReg[Rn] + imm12; if(inITBlock()) { if( checkCondition(cond) ) { if(Rt == PC) { if( getBits(address,1,0) == 0b00) writeToCoreRegisters(Rt , loadByteFromMemory(address, 4) ); else { //placePCtoVectorTable(UsageFault); ThrowError(); } } else writeToCoreRegisters(Rt , loadByteFromMemory(address, 4) ); } shiftITState(); } else { if(Rt == PC) { if( getBits(address,1,0) == 0b00) writeToCoreRegisters(Rt , loadByteFromMemory(address, 4) ); else { //placePCtoVectorTable(UsageFault); ThrowError(); } } else writeToCoreRegisters(Rt , loadByteFromMemory(address, 4) ); } if(Rt != PC) coreReg[PC] += 4; }