// add the entire signal b to this signal, at the subpixel destination offset. // void MLSignal::add2D(const MLSignal& b, const Vec2& destOffset) { MLSignal& a = *this; Vec2 iDestOffset, fDestOffset; destOffset.getIntAndFracParts(iDestOffset, fDestOffset); int destX = iDestOffset[0]; int destY = iDestOffset[1]; float srcPosFX = fDestOffset[0]; float srcPosFY = fDestOffset[1]; MLRect srcRect(0, 0, b.getWidth() + 1, b.getHeight() + 1); // add (1, 1) for interpolation MLRect destRect = srcRect.translated(iDestOffset).intersect(getBoundsRect()); for(int j=destRect.top(); j<destRect.bottom(); ++j) { for(int i=destRect.left(); i<destRect.right(); ++i) { a(i, j) += b.getInterpolatedLinear(i - destX - srcPosFX, j - destY - srcPosFY); } } setConstant(false); }
// private signal constructor: make a reference to a slice of the external signal. // of course this object will be meaningless when the other Signal is gone, so // use wih care -- only as a temporary, ideally. Is there a way to force // the object to be a temporary? In other words not allow a named // MLSignal notTemporary(pOther, 4); // // NOTE this signal will not pass checkIntegrity()! // MLSignal::MLSignal(const MLSignal* other, int slice) : mData(0), mDataAligned(0), mCopy(0), mCopyAligned(0) { mRate = kMLToBeCalculated; setConstant(false); if(other->getDepth() > 1) // make 2d slice { mDataAligned = other->mDataAligned + other->plane(slice); mWidth = other->mWidth; mHeight = other->mHeight; mDepth = 1; } else if(other->getHeight() > 1) // make 1d slice { mDataAligned = other->mDataAligned + other->row(slice); mWidth = other->mWidth; mHeight = 1; mDepth = 1; } else { // signal to take slice of must be 2d or 3d! assert(false); } mWidthBits = bitsToContain(mWidth); mHeightBits = bitsToContain(mHeight); mDepthBits = bitsToContain(mDepth); mSize = 1 << mWidthBits << mHeightBits << mDepthBits; mConstantMask = mSize - 1; }
void setIdentity() { setConstant(T(0)); uint nn = std::min(nrows,ncols); for (uint ii=0; ii<nn; ++ii) m[ii*ncols+ii] = T(1); }
// TODO SSE void MLSignal::sigLerp(const MLSignal& b, const MLSample mix) { int n = min(mSize, b.getSize()); for(int i = 0; i < n; ++i) { mDataAligned[i] = lerp(mDataAligned[i], b.mDataAligned[i], mix); } setConstant(false); }
void MLSignal::sigMax(const MLSignal& b) { int n = min(mSize, b.getSize()); for(int i = 0; i < n; ++i) { MLSample f = mDataAligned[i]; mDataAligned[i] = max(f, b.mDataAligned[i]); } setConstant(false); }
// TODO SSE void MLSignal::sigClamp(const MLSignal& a, const MLSignal& b) { int n = min(mSize, a.getSize()); n = min(n, b.getSize()); for(int i = 0; i < n; ++i) { MLSample f = mDataAligned[i]; mDataAligned[i] = clamp(f, a.mDataAligned[i], b.mDataAligned[i]); } setConstant(false); }
void MLSignal::copy(const MLSignal& b) { const bool kb = b.isConstant(); if (kb) { setToConstant(b.mDataAligned[0]); } else { const int n = min(mSize, b.getSize()); std::copy(b.mDataAligned, b.mDataAligned + n, mDataAligned); setConstant(false); } }
// add the entire signal b to this signal, at the integer destination offset. // void MLSignal::add2D(const MLSignal& b, int destX, int destY) { MLSignal& a = *this; MLRect srcRect(0, 0, b.getWidth(), b.getHeight()); MLRect destRect = srcRect.translated(Vec2(destX, destY)).intersect(getBoundsRect()); for(int j=destRect.top(); j<destRect.bottom(); ++j) { for(int i=destRect.left(); i<destRect.right(); ++i) { a(i, j) += b(i - destX, j - destY); } } setConstant(false); }
// TODO SSE void MLSignal::divide(const MLSignal& b) { const bool ka = isConstant(); const bool kb = b.isConstant(); if (ka && kb) { setToConstant(mDataAligned[0] + b.mDataAligned[0]); } else { const int n = min(mSize, b.getSize()); if (ka && !kb) { MLSample fa = mDataAligned[0]; for(int i = 0; i < n; ++i) { mDataAligned[i] = fa / b[i]; } } else if (!ka && kb) { MLSample fb = b[0]; for(int i = 0; i < n; ++i) { mDataAligned[i] /= fb; } } else { for(int i = 0; i < n; ++i) { mDataAligned[i] /= b.mDataAligned[i]; } } setConstant(false); } }
Plane( const VectorImpl &normal, PRECISION constant, bool forceNormalize = true ) { setNormal( normal, forceNormalize ); setConstant( constant ); }
void Stats::setConstant( const QString& name, float value ) { setConstant(name, QString::number(value)); }
void setZero() {setConstant(T(0)); }
bool SetVariableCommand::executeImpl( DebuggerSession* session, folly::dynamic* responseMsg ) { folly::dynamic body = folly::dynamic::object; folly::dynamic variables = folly::dynamic::array; auto& args = tryGetObject(getMessage(), "arguments", s_emptyArgs); ServerObject* obj = session->getServerObject(m_objectId); if (obj == nullptr) { throw DebuggerCommandException("Invalid variablesReference specified."); } const std::string& suppliedName = tryGetString(args, "name", ""); if (suppliedName.empty()) { throw DebuggerCommandException("Invalid variable name specified."); } // Remove any prefixes that we would have added to the variable name // before presenting it to the front-end. std::string name = removeVariableNamePrefix(suppliedName); bool success = false; const std::string& strValue = tryGetString(args, "value", ""); try { if (obj->objectType() == ServerObjectType::Scope) { ScopeObject* scope = static_cast<ScopeObject*>(obj); switch (scope->m_scopeType) { case ScopeType::Locals: success = setLocalVariable( session, name, strValue, scope, &body ); break; case ScopeType::ServerConstants: success = setConstant( session, name, strValue, scope, &body ); break; // Superglobals and core constants are provided by the current execution // context, rather than trying to overwrite them here, defer to the PHP // console, which will let the runtime enforce whatever policies are // appropriate. case ScopeType::Superglobals: m_debugger->sendUserMessage( "Could not directly set value of superglobal variable, you may " "be able to set this value by running a Hack/PHP command in the " " console.", DebugTransport::OutputLevelError ); break; default: assertx(false); } } else if (obj->objectType() == ServerObjectType::Variable) { VariableObject* variable = static_cast<VariableObject*>(obj); Variant& variant = variable->m_variable; if (variant.isArray()) { success = setArrayVariable(session, name, strValue, variable, &body); } else if (variant.isObject()) { success = setObjectVariable(session, name, strValue, variable, &body); } else { throw DebuggerCommandException( "Failed to set variable: Unexpected variable type." ); } } } catch (DebuggerCommandException e) { m_debugger->sendUserMessage( e.what(), DebugTransport::OutputLevelError ); throw e; } if (!success) { throw DebuggerCommandException( "Failed to set variable." ); } (*responseMsg)["body"] = body; return false; }
// update to support more types bool ATKIOperator::loadConstant(Stream *program, uint8_t operandIndex, uint8_t flags) { char buffer[21]; memset(buffer, 0, 21); int index = 0; bool valid = false; while(Antikythera::readProgram(program)) { char c = (char)program->read(); program->print(c); if (c == '(') { valid = true; break; } if (index == 5) { #ifdef ANTIKYTHERA_DEBUG Antikythera::lastErrorString = m_name + "::load() - constant count has too many digits."; #endif program->flush(); return false; } if (!isdigit(c)) { #ifdef ANTIKYTHERA_DEBUG Antikythera::lastErrorString = m_name + "::load() - constant count contains invalid character: " + String(c); #endif program->flush(); return false; } buffer[index++] = c; } if (!valid) { #ifdef ANTIKYTHERA_DEBUG Antikythera::lastErrorString = m_name + "::load() - unexpected end of stream while reading constant count."; #endif program->flush(); return false; } #ifdef ANTIKYTHERA_DEBUG program->print("[initialize constant:"); program->print((int)operandIndex); program->print(", count:"); program->print(buffer); program->println("]"); #endif initializeConstant(operandIndex, (uint16_t)strtoul(buffer, NULL, 10)); uint8_t operandType = flags & 0x0F; uint8_t maxLength = 0; switch (operandType) { case OPERANDTYPE_INT16: maxLength = 6; break; case OPERANDTYPE_FLOAT: return true; case OPERANDTYPE_STRING: return true; case OPERANDTYPE_UINT32: maxLength = 10; break; } #ifdef ANTIKYTHERA_DEBUG program->print("[reading "); program->print(m_constantSize[operandIndex]); program->print(", type:"); program->print((int)operandType); program->println(" constants]"); #endif for (int count = 0; count < m_constantSize[operandIndex]; count++) { memset(buffer, 0, 21); index = 0; valid = false; if (operandType == OPERANDTYPE_INT16) { while(Antikythera::readProgram(program)) { char c = (char)program->read(); program->print(c); if (c == ',') { if (count == (m_constantSize[operandIndex] - 1)) { #ifdef ANTIKYTHERA_DEBUG m_lastErrorString = m_name + "::load() - constant count is less than number of constants."; #endif program->flush(); return false; } valid = true; break; } if (c == ')') { if (count != (m_constantSize[operandIndex] - 1)) { #ifdef ANTIKYTHERA_DEBUG m_lastErrorString = m_name + "::load() - constant count is greater than number of constants."; #endif program->flush(); return false; } valid = true; break; } if (index == maxLength) { #ifdef ANTIKYTHERA_DEBUG m_lastErrorString = m_name + "::load() - constant has too many digits."; #endif program->flush(); return false; } if (c && (strchr("-0123456789", c) == NULL)) { #ifdef ANTIKYTHERA_DEBUG m_lastErrorString = m_name + "::load() - constant contains invalid character: " + String(c); #endif program->flush(); return false; } buffer[index++] = c; } if (!valid) { #ifdef ANTIKYTHERA_DEBUG m_lastErrorString = m_name + "::load() - unexpected end of stream while reading constant."; #endif program->flush(); return false; } } else if (operandType == OPERANDTYPE_UINT32) { while(Antikythera::readProgram(program)) { char c = (char)program->read(); program->print(c); if (c == ',') { if (count == (m_constantSize[operandIndex] - 1)) { #ifdef ANTIKYTHERA_DEBUG m_lastErrorString = m_name + "::load() - constant count is less than number of constants."; #endif program->flush(); return false; } valid = true; break; } if (c == ')') { if (count != (m_constantSize[operandIndex] - 1)) { #ifdef ANTIKYTHERA_DEBUG m_lastErrorString = m_name + "::load() - constant count is greater than number of constants."; #endif program->flush(); return false; } valid = true; break; } if (index == maxLength) { #ifdef ANTIKYTHERA_DEBUG m_lastErrorString = m_name + "::load() - constant has too many digits."; #endif program->flush(); return false; } if (!isdigit(c)) { #ifdef ANTIKYTHERA_DEBUG m_lastErrorString = m_name + "::load() - constant contains invalid character: " + String(c); #endif program->flush(); return false; } buffer[index++] = c; } if (!valid) { #ifdef ANTIKYTHERA_DEBUG m_lastErrorString = m_name + "::load() - unexpected end of stream while reading constant."; #endif program->flush(); return false; } } #ifdef ANTIKYTHERA_DEBUG program->print("[value"); program->print((int)count); program->print(":"); program->print(buffer); program->println("]"); #endif switch (operandType) { case OPERANDTYPE_INT16: { int16_t t0 = (int16_t)strtol(buffer, NULL, 10); setConstant(operandIndex, count, &t0); } break; case OPERANDTYPE_FLOAT: return true; case OPERANDTYPE_STRING: return true; case OPERANDTYPE_UINT32: { uint32_t t3 = (int32_t)strtoul(buffer, NULL, 10); setConstant(operandIndex, count, &t3); } break; } } return true; }
// read n samples from an external sample pointer plus a sample offset into start of signal. // void MLSignal::read(const MLSample *input, const int offset, const int n) { setConstant(false); std::copy(input + offset, input + offset + n, mDataAligned); }
Plane( const VectorImpl &normal, const VectorImpl &point, bool forceNormalize = true ) { setNormal( normal, forceNormalize ); setConstant( -( _normal * point ) ); }
Plane( const VectorImpl &p0, const VectorImpl &p1, const VectorImpl p2 ) { setNormal( ( p2 - p1 ) ^ ( p0 - p1 ) ); setConstant( -( _normal * p0 ) ); }
bool Bass::assemble(const string& statement) { string s = statement; if(s.match("block {")) return true; if(s.match("} endblock")) return true; //constant name(value) if(s.match("constant ?*(*)")) { lstring p = s.trim<1>("constant ", ")").split<1>("("); setConstant(p(0), evaluate(p(1))); return true; } //scope name { if(s.match("scope ?* {") || s.match("scope {")) { s.trim<1>("scope ", "{").strip(); if(s.endsWith(":")) { setConstant(s.rtrim<1>(":"), pc()); appendSymfile(s, pc()); } scope.append(s); return true; } //} if(s.match("} endscope")) { scope.removeLast(); return true; } //label: or label: { if(s.match("?*:") || s.match("?*: {")) { s.rtrim<1>(" {"); s.rtrim<1>(":"); setConstant(s, pc()); appendSymfile(s, pc()); return true; } //- or - { if(s.match("-") || s.match("- {")) { setConstant({"lastLabel#", lastLabelCounter++}, pc()); return true; } //+ or + { if(s.match("+") || s.match("+ {")) { setConstant({"nextLabel#", nextLabelCounter++}, pc()); return true; } //} if(s.match("} endconstant")) { return true; } //output "filename" [, create] if(s.match("output ?*")) { lstring p = s.ltrim<1>("output ").qsplit(",").strip(); string filename = {filepath(), p.take(0).trim<1>("\"")}; if(filename != ".//dev/null") { bool create = (p.size() && p(0) == "create"); target(filename, create); }else{ #if defined(_WIN32) target("./NUL", false); #else target("/dev/null", false); #endif } return true; } //endian (lsb|msb) if(s.match("endian ?*")) { s.ltrim<1>("endian "); if(s == "lsb") { endian = Endian::LSB; return true; } if(s == "msb") { endian = Endian::MSB; return true; } error("invalid endian mode"); } //origin offset if(s.match("origin ?*")) { s.ltrim<1>("origin "); origin = evaluate(s); seek(origin); return true; } //base offset if(s.match("base ?*")) { s.ltrim<1>("base "); base = evaluate(s) - origin; return true; } //push variable [, ...] if(s.match("push ?*")) { lstring p = s.ltrim<1>("push ").qsplit(",").strip(); for(auto& t : p) { if(t == "origin") { pushStack.append(origin); } else if(t == "base") { pushStack.append(base); } else if(t == "pc") { pushStack.append(origin); pushStack.append(base); } else { error("unrecognized push variable: ", t); } } return true; } //pull variable [, ...] if(s.match("pull ?*")) { lstring p = s.ltrim<1>("pull ").qsplit(",").strip(); for(auto& t : p) { if(t == "origin") { origin = decimal(pushStack.takeLast()); seek(origin); } else if(t == "base") { base = integer(pushStack.takeLast()); } else if(t == "pc") { base = integer(pushStack.takeLast()); origin = decimal(pushStack.takeLast()); seek(origin); } else { error("unrecognized pull variable: ", t); } } return true; } //insert [name, ] filename [, offset] [, length] if(s.match("insert ?*")) { lstring p = s.ltrim<1>("insert ").qsplit(",").strip(); string name; if(!p(0).match("\"*\"")) name = p.take(0); if(!p(0).match("\"*\"")) error("missing filename"); string filename = {filepath(), p.take(0).trim<1>("\"")}; file fp; if(!fp.open(filename, file::mode::read)) error("file not found: ", filename); unsigned offset = p.size() ? evaluate(p.take(0)) : 0; if(offset > fp.size()) offset = fp.size(); unsigned length = p.size() ? evaluate(p.take(0)) : 0; if(length == 0) length = fp.size() - offset; if(name) { setConstant({name}, pc()); setConstant({name, ".size"}, length); } fp.seek(offset); while(!fp.end() && length--) write(fp.read()); return true; } //fill length [, with] if(s.match("fill ?*")) { lstring p = s.ltrim<1>("fill ").qsplit(",").strip(); unsigned length = evaluate(p(0)); unsigned byte = evaluate(p(1, "0")); while(length--) write(byte); return true; } //map 'char' [, value] [, length] if(s.match("map ?*")) { lstring p = s.ltrim<1>("map ").qsplit(",").strip(); uint8_t index = evaluate(p(0)); int64_t value = evaluate(p(1, "0")); int64_t length = evaluate(p(2, "1")); for(signed n = 0; n < length; n++) { stringTable[index + n] = value + n; } return true; } //d[bwldq] ("string"|variable) [, ...] unsigned dataLength = 0; if(s.beginsWith("db ")) dataLength = 1; if(s.beginsWith("dw ")) dataLength = 2; if(s.beginsWith("dl ")) dataLength = 3; if(s.beginsWith("dd ")) dataLength = 4; if(s.beginsWith("dq ")) dataLength = 8; if(dataLength) { s = s.slice(3); //remove prefix lstring p = s.qsplit(",").strip(); for(auto& t : p) { if(t.match("\"*\"")) { t = text(t); for(auto& b : t) write(stringTable[b], dataLength); } else { write(evaluate(t), dataLength); } } return true; } if(s.beginsWith("ieee32 ")) { dataLength = 4; s = s.slice(7); //remove directive lstring p = s.qsplit(",").strip(); for(auto& t : p) { /*if(!t.match("")) { error("invalid single precision float"); }*/ uint64_t data = 0; *(float*)&data = real(t); //printf("\n%x", data); write(data, dataLength); } return true; } if(s.beginsWith("ieee64 ")) { dataLength = 8; s = s.slice(7); //remove directive lstring p = s.qsplit(",").strip(); for(auto& t : p) { /*if(!t.match("")) { error("invalid double precision float"); }*/ uint64_t data = 0; *(double*)&data = real(t); //printf("\n%llx", data); write(data, dataLength); } return true; } //print ("string"|variable) [, ...] if(s.match("print ?*")) { s.ltrim<1>("print ").strip(); if(writePhase()) { lstring p = s.qsplit(",").strip(); for(auto& t : p) { if(t.match("\"*\"")) { print(text(t)); } else { print(evaluate(t)); } } } return true; } //notice "string" if(s.match("notice \"*\"")) { if(writePhase()) { s.ltrim<1>("notice ").strip(); notice(text(s)); } return true; } //warning "string" if(s.match("warning \"*\"")) { if(writePhase()) { s.ltrim<1>("warning ").strip(); warning(text(s)); } return true; } //error "string" if(s.match("error \"*\"")) { if(writePhase()) { s.ltrim<1>("error ").strip(); error(text(s)); } return true; } return false; }