static void sub(const RView& X, const RView& Y, Result& result) { const int * x = X.data(); const int * y = Y.data(); int * z = result.data(); __m128i px, py, pz, px1, py1, pz1; for(int i=0; i<DIM_N-(DIM_N&0x7); i+=8) { px = _mm_load_si128((const __m128i *)x); py = _mm_load_si128((const __m128i *)y); pz = _mm_sub_epi32(px, py); px1 = _mm_load_si128((const __m128i *)(x+4)); py1 = _mm_load_si128((const __m128i *)(y+4)); _mm_store_si128((__m128i *)z, pz); pz1 = _mm_sub_epi32(px1, py1); _mm_store_si128((__m128i *)(z+4), pz1); x += 8; y += 8; z += 8; } for(int i=DIM_N-(DIM_N&0x7); i<DIM_N; ++i) { result[i] = X[i] - Y[i]; } }
static void add(const RView& X, const RView& Y, Result& result) { const float * x = X.data(); const float * y = Y.data(); float * z = result.data(); __m128 px, py, pz, px1, py1, pz1; for(int i=0; i<DIM_N-(DIM_N&0x7); i+=8) { px = _mm_load_ps(x); py = _mm_load_ps(y); pz = _mm_add_ps(px, py); px1 = _mm_load_ps(x+4); py1 = _mm_load_ps(y+4); _mm_store_ps(z, pz); pz1 = _mm_add_ps(px1, py1); _mm_store_ps(z+4, pz1); x += 8; y += 8; z += 8; } for(int i=DIM_N-(DIM_N&0x7); i<DIM_N; ++i) { result[i] = X[i] + Y[i]; } }
/** * Stream operator for QDebug */ QDebug operator<<(QDebug dbg, const RView& v) { dbg.nospace() << "RView(" << (RObject&) v << ", name: " << v.getName() << ", centerPoint: " << v.getCenterPoint() << ", width: " << v.getWidth() << ", height: " << v.getHeight() << ")"; return dbg.space(); }
QScriptValue REcmaSharedPointerView::setHeight (QScriptContext* context, QScriptEngine* engine) { //REcmaHelper::functionStart("REcmaSharedPointerView::setHeight", context, engine); //qDebug() << "ECMAScript WRAPPER: REcmaSharedPointerView::setHeight"; //QCoreApplication::processEvents(); QScriptValue result = engine->undefinedValue(); // public function: can be called from ECMA wrapper of ECMA shell: RView* self = getSelf("setHeight", context); //Q_ASSERT(self!=NULL); if (self==NULL) { return REcmaHelper::throwError("self is NULL", context); } if( context->argumentCount() == 1 && ( context->argument(0).isNumber() ) /* type: double */ ){ // prepare arguments: // argument isStandardType double a0 = (double) context->argument( 0 ). toNumber(); // end of arguments // call C++ function: // return type 'void' self->setHeight(a0); } else { return REcmaHelper::throwError("Wrong number/types of arguments for RView.setHeight().", context); } //REcmaHelper::functionEnd("REcmaSharedPointerView::setHeight", context, engine); return result; }
static void dotprod(const RView& X, const RView& Y, T& result) { #ifdef MKL const float * x = X.data(); const float * y = Y.data(); result = cblas_sdot(DIM_N, x, 1, y, 1); #else for (int i=0; i<DIM_N; ++i) result += X[i] * Y[i]; #endif }
QScriptValue REcmaSharedPointerView::getBox (QScriptContext* context, QScriptEngine* engine) { //REcmaHelper::functionStart("REcmaSharedPointerView::getBox", context, engine); //qDebug() << "ECMAScript WRAPPER: REcmaSharedPointerView::getBox"; //QCoreApplication::processEvents(); QScriptValue result = engine->undefinedValue(); // public function: can be called from ECMA wrapper of ECMA shell: RView* self = getSelf("getBox", context); //Q_ASSERT(self!=NULL); if (self==NULL) { return REcmaHelper::throwError("self is NULL", context); } if( context->argumentCount() == 0 ){ // prepare arguments: // end of arguments // call C++ function: // return type 'RBox' RBox cppResult = self->getBox(); // return type: RBox // not standard type nor reference result = qScriptValueFromValue(engine, cppResult); } else { return REcmaHelper::throwError("Wrong number/types of arguments for RView.getBox().", context); } //REcmaHelper::functionEnd("REcmaSharedPointerView::getBox", context, engine); return result; }
QScriptValue REcmaSharedPointerView::isSelectedForPropertyEditing (QScriptContext* context, QScriptEngine* engine) { //REcmaHelper::functionStart("REcmaSharedPointerView::isSelectedForPropertyEditing", context, engine); //qDebug() << "ECMAScript WRAPPER: REcmaSharedPointerView::isSelectedForPropertyEditing"; //QCoreApplication::processEvents(); QScriptValue result = engine->undefinedValue(); // public function: can be called from ECMA wrapper of ECMA shell: RView* self = getSelf("isSelectedForPropertyEditing", context); //Q_ASSERT(self!=NULL); if (self==NULL) { return REcmaHelper::throwError("self is NULL", context); } if( context->argumentCount() == 0 ){ // prepare arguments: // end of arguments // call C++ function: // return type 'bool' bool cppResult = self->isSelectedForPropertyEditing(); // return type: bool // standard Type result = QScriptValue(cppResult); } else { return REcmaHelper::throwError("Wrong number/types of arguments for RView.isSelectedForPropertyEditing().", context); } //REcmaHelper::functionEnd("REcmaSharedPointerView::isSelectedForPropertyEditing", context, engine); return result; }
// Y = Y + alpha * X // saddly, there is no madd instr. for Fp in SSE static void madd(const float& alpha, const RView& X, Result& result) #ifdef __SSE_4_1__ { const int * x = X.data(); int * y = result.data(); __m128i px, px1, px2, py, py1, py2; __m128i alpha_p = _mm_set_epi32(alpha, alpha, alpha, alpha); for(int i=0; i<DIM_N - (DIM_N%12); i+=12) { px = _mm_load_si128((const __m128i *)x); px1 = _mm_load_si128((const __m128i *)(x+4)); px2 = _mm_load_si128(x+8) py = _mm_load_si128(y); py1 = _mm_load_si128(y+4); py2 = _mm_load_si128(y+8); py = _mm_add_epi32(py, _mm_mullo_epi32(alpha_a, px)); py1 = _mm_add_epi32(py1, _mm_mullo_epi32(alpha_a, px1)); py2 = _mm_add_epi32(py2, _mm_mullo_epi32(alpha_a, px2)); _mm_store_si128(y, py); _mm_store_si128(y+4, py1); _mm_store_si128(y+8, py2); x += 12; y += 12; } for(int i=DIM_N - (DIM_N%12); i<DIM_N; ++i) { result[i] += alpha * X[i]; } }
// Y = Y + alpha * X // saddly, there is no madd instr. for Fp in SSE static void madd(const float& alpha, const RView& X, Result& result) { //printf("SSE DIM_N = %d\n", DIM_N); const float * x = X.data(); float * y = result.data(); float __const_alpha[4] = {alpha, alpha, alpha, alpha}; __m128 a, px, px1, py, py1; a = _mm_load_ps(&__const_alpha[0]); for(int i=0; i<DIM_N - (DIM_N&0x7); i+=8) { px = _mm_load_ps(x); px1 = _mm_load_ps(x+4); py = _mm_load_ps(y); py1 = _mm_load_ps(y+4); py = _mm_add_ps(py, _mm_mul_ps(a, px)); py1 = _mm_add_ps(py1, _mm_mul_ps(a, px1)); _mm_store_ps(y, py); _mm_store_ps(y+4, py1); x += 8; y += 8; } for(int i=DIM_N - (DIM_N&0x7); i<DIM_N; ++i) { result[i] += alpha * X[i]; } }
// Y = alpha * X static void mul(const float& alpha, const RView& X, Result& result) { const float * x = X.data(); float * y = result.data(); float __const_alpha[4] = {alpha, alpha, alpha, alpha}; __m128 a, px, px1, px2, py, py1, py2; a = _mm_load_ps(__const_alpha); for(int i=0; i<DIM_N - (DIM_N%12); i+=12) { px = _mm_load_ps(x); px1 = _mm_load_ps(x+4); px2 = _mm_load_ps(x+8); py = _mm_mul_ps(a, px); py1 = _mm_mul_ps(a, px1); py2 = _mm_mul_ps(a, px2); _mm_store_ps(y, py); _mm_store_ps(y+4, py1); _mm_store_ps(y+8, py2); x += 12; y += 12; } for(int i=DIM_N - DIM_N%12; i<DIM_N; ++i) { result[i] = alpha * X[i]; } }
// **************************************************************************** // // Function Name: RCompositeSelection::Write // // Description: Writes this selection to the specified archive // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RCompositeSelection::Write( RArchive& archive ) const { uLONG count = Count( ); // First, store the number of items in the selection archive << count; RView* pView = GetView(); YSelectionIterator iterator = Start( ); for( count = 0; iterator != End( ); ++iterator, ++count ) { // Retrieve the indicies of the views and write them out archive << pView->GetIndexOfComponentView( *iterator ); } TpsAssert( count == (uLONG)Count( ), "Count written to archive does not match count in selection" ); }
// **************************************************************************** // // Function Name: RGroupSelectionAction::Do( ) // // Description: Does the action // // Returns: TRUE if the action was sucessful // // Exceptions: None // // **************************************************************************** // BOOLEAN RGroupSelectionAction::Do( ) { // Call the base method to setup the state properly RUndoableAction::Do( ); // Bail if the component was'nt created properly if( !m_pGroupDocument ) return FALSE; // Get the z position of the top most component to use as the group components z-position RView* pParentView = m_pCurrentSelection->GetView( ); YSelectionIterator iterator = m_OldSelection.Start( ); YComponentZPosition groupZPosition = pParentView->GetComponentZPosition( *iterator ); // Make a component collection RComponentCollection componentCollection ( m_OldSelection ); // Unselect the current selection m_pCurrentSelection->UnselectAll( ); // Add the group component m_pParentDocument->AddComponent( m_pGroupDocument ); // Transfer the components to the group m_pGroupDocument->TransferComponents( m_pParentDocument, componentCollection, componentCollection.GetBoundingRect( ), RRealRect( m_GroupBoundingRect.WidthHeight( ) ) ); // Combine the component attributes of the collection with that of the group RComponentAttributes attributes = m_pGroupDocument->GetComponentAttributes( ); componentCollection.CombineAttributes( attributes ); m_pGroupDocument->SetComponentAttributes( attributes ); // Set the z position of the group component pParentView->SetComponentZPosition( m_pGroupDocument->GetView( pParentView ), groupZPosition ); // Tell the view that its layout has changed m_pCurrentSelection->GetView()->XUpdateAllViews( kLayoutChanged, 0 ); // Select the group component m_pCurrentSelection->Select( m_pGroupDocument, TRUE ); return TRUE; }
ExecStatus ElementUnion<SView,RView>:: post(Home home, SView x0, IdxViewArray& xs, RView x1) { int n = xs.size(); // s2 \subseteq {1,...,n} Iter::Ranges::Singleton s(0, n-1); GECODE_ME_CHECK(x1.intersectI(home,s)); (void) new (home) ElementUnion<SView,RView>(home,x0,xs,x1); return ES_OK; }
static void madd(const T& alpha, const RView& X, Result& result) { //printf("Scalar DIM_N = %d\n", DIM_N); #ifndef MKL for(int i=0; i<DIM_N; ++i) result[i] += alpha * X[i]; #else const float * x = X.data(); float * y = result.data(); cblas_saxpy(DIM_N, alpha, x, 1, y, 1); #endif }
QScriptValue REcmaSharedPointerView::getProperty (QScriptContext* context, QScriptEngine* engine) { //REcmaHelper::functionStart("REcmaSharedPointerView::getProperty", context, engine); //qDebug() << "ECMAScript WRAPPER: REcmaSharedPointerView::getProperty"; //QCoreApplication::processEvents(); QScriptValue result = engine->undefinedValue(); // public function: can be called from ECMA wrapper of ECMA shell: RView* self = getSelf("getProperty", context); //Q_ASSERT(self!=NULL); if (self==NULL) { return REcmaHelper::throwError("self is NULL", context); } if( context->argumentCount() == 1 && ( context->argument(0).isVariant() || context->argument(0).isQObject() || context->argument(0).isNull() ) /* type: RPropertyTypeId */ ){ // prepare arguments: // argument isCopyable and has default constructor and isSimpleClass RPropertyTypeId* ap0 = qscriptvalue_cast< RPropertyTypeId* >( context->argument( 0 ) ); if (ap0 == NULL) { return REcmaHelper::throwError("RView: Argument 0 is not of type RPropertyTypeId.", context); } RPropertyTypeId a0 = *ap0; // end of arguments // call C++ function: // return type 'QPair < QVariant , RPropertyAttributes >' QPair < QVariant , RPropertyAttributes > cppResult = self->getProperty(a0); // return type: QPair < QVariant , RPropertyAttributes > // Pair of ...: //result = REcmaHelper::pairToScriptValue(engine, cppResult); QVariantList vl; QVariant v; // first type of pair is variant: if (QString(cppResult.first.typeName())=="RLineweight::Lineweight") { v.setValue((int)cppResult.first.value<RLineweight::Lineweight>()); } else { v.setValue(cppResult.first); } vl.append(v); v.setValue(cppResult.second); vl.append(v); result = qScriptValueFromValue(engine, vl); } else if( context->argumentCount() == 2 && ( context->argument(0).isVariant() || context->argument(0).isQObject() || context->argument(0).isNull() ) /* type: RPropertyTypeId */ && ( context->argument(1).isBool() ) /* type: bool */ ){ // prepare arguments: // argument isCopyable and has default constructor and isSimpleClass RPropertyTypeId* ap0 = qscriptvalue_cast< RPropertyTypeId* >( context->argument( 0 ) ); if (ap0 == NULL) { return REcmaHelper::throwError("RView: Argument 0 is not of type RPropertyTypeId.", context); } RPropertyTypeId a0 = *ap0; // argument isStandardType bool a1 = (bool) context->argument( 1 ). toBool(); // end of arguments // call C++ function: // return type 'QPair < QVariant , RPropertyAttributes >' QPair < QVariant , RPropertyAttributes > cppResult = self->getProperty(a0 , a1); // return type: QPair < QVariant , RPropertyAttributes > // Pair of ...: //result = REcmaHelper::pairToScriptValue(engine, cppResult); QVariantList vl; QVariant v; // first type of pair is variant: if (QString(cppResult.first.typeName())=="RLineweight::Lineweight") { v.setValue((int)cppResult.first.value<RLineweight::Lineweight>()); } else { v.setValue(cppResult.first); } vl.append(v); v.setValue(cppResult.second); vl.append(v); result = qScriptValueFromValue(engine, vl); } else if( context->argumentCount() == 3 && ( context->argument(0).isVariant() || context->argument(0).isQObject() || context->argument(0).isNull() ) /* type: RPropertyTypeId */ && ( context->argument(1).isBool() ) /* type: bool */ && ( context->argument(2).isBool() ) /* type: bool */ ){ // prepare arguments: // argument isCopyable and has default constructor and isSimpleClass RPropertyTypeId* ap0 = qscriptvalue_cast< RPropertyTypeId* >( context->argument( 0 ) ); if (ap0 == NULL) { return REcmaHelper::throwError("RView: Argument 0 is not of type RPropertyTypeId.", context); } RPropertyTypeId a0 = *ap0; // argument isStandardType bool a1 = (bool) context->argument( 1 ). toBool(); // argument isStandardType bool a2 = (bool) context->argument( 2 ). toBool(); // end of arguments // call C++ function: // return type 'QPair < QVariant , RPropertyAttributes >' QPair < QVariant , RPropertyAttributes > cppResult = self->getProperty(a0 , a1 , a2); // return type: QPair < QVariant , RPropertyAttributes > // Pair of ...: //result = REcmaHelper::pairToScriptValue(engine, cppResult); QVariantList vl; QVariant v; // first type of pair is variant: if (QString(cppResult.first.typeName())=="RLineweight::Lineweight") { v.setValue((int)cppResult.first.value<RLineweight::Lineweight>()); } else { v.setValue(cppResult.first); } vl.append(v); v.setValue(cppResult.second); vl.append(v); result = qScriptValueFromValue(engine, vl); } else { return REcmaHelper::throwError("Wrong number/types of arguments for RView.getProperty().", context); } //REcmaHelper::functionEnd("REcmaSharedPointerView::getProperty", context, engine); return result; }
QScriptValue REcmaSharedPointerView::setCenterPoint (QScriptContext* context, QScriptEngine* engine) { //REcmaHelper::functionStart("REcmaSharedPointerView::setCenterPoint", context, engine); //qDebug() << "ECMAScript WRAPPER: REcmaSharedPointerView::setCenterPoint"; //QCoreApplication::processEvents(); QScriptValue result = engine->undefinedValue(); // public function: can be called from ECMA wrapper of ECMA shell: RView* self = getSelf("setCenterPoint", context); //Q_ASSERT(self!=NULL); if (self==NULL) { return REcmaHelper::throwError("self is NULL", context); } if( context->argumentCount() == 1 && ( context->argument(0).isVariant() || context->argument(0).isQObject() || context->argument(0).isNull() ) /* type: RVector */ ){ // prepare arguments: // argument isCopyable and has default constructor and isSimpleClass RVector* ap0 = qscriptvalue_cast< RVector* >( context->argument( 0 ) ); if (ap0 == NULL) { return REcmaHelper::throwError("RView: Argument 0 is not of type RVector.", context); } RVector a0 = *ap0; // end of arguments // call C++ function: // return type 'void' self->setCenterPoint(a0); } else { return REcmaHelper::throwError("Wrong number/types of arguments for RView.setCenterPoint().", context); } //REcmaHelper::functionEnd("REcmaSharedPointerView::setCenterPoint", context, engine); return result; }
QScriptValue REcmaSharedPointerView::setProperty (QScriptContext* context, QScriptEngine* engine) { //REcmaHelper::functionStart("REcmaSharedPointerView::setProperty", context, engine); //qDebug() << "ECMAScript WRAPPER: REcmaSharedPointerView::setProperty"; //QCoreApplication::processEvents(); QScriptValue result = engine->undefinedValue(); // public function: can be called from ECMA wrapper of ECMA shell: RView* self = getSelf("setProperty", context); //Q_ASSERT(self!=NULL); if (self==NULL) { return REcmaHelper::throwError("self is NULL", context); } if( context->argumentCount() == 2 && ( context->argument(0).isVariant() || context->argument(0).isQObject() || context->argument(0).isNull() ) /* type: RPropertyTypeId */ && ( context->argument(1).isVariant() || context->argument(1).isQObject() || context->argument(1).isNumber() || context->argument(1).isString() || context->argument(1).isBool() || context->argument(1).isArray() || context->argument(1).isNull() || context->argument(1).isUndefined() ) /* type: QVariant */ ){ // prepare arguments: // argument isCopyable and has default constructor and isSimpleClass RPropertyTypeId* ap0 = qscriptvalue_cast< RPropertyTypeId* >( context->argument( 0 ) ); if (ap0 == NULL) { return REcmaHelper::throwError("RView: Argument 0 is not of type RPropertyTypeId.", context); } RPropertyTypeId a0 = *ap0; // argument isCopyable or pointer QVariant a1 = qscriptvalue_cast< QVariant >( context->argument( 1 ) ); // end of arguments // call C++ function: // return type 'bool' bool cppResult = self->setProperty(a0 , a1); // return type: bool // standard Type result = QScriptValue(cppResult); } else if( context->argumentCount() == 3 && ( context->argument(0).isVariant() || context->argument(0).isQObject() || context->argument(0).isNull() ) /* type: RPropertyTypeId */ && ( context->argument(1).isVariant() || context->argument(1).isQObject() || context->argument(1).isNumber() || context->argument(1).isString() || context->argument(1).isBool() || context->argument(1).isArray() || context->argument(1).isNull() || context->argument(1).isUndefined() ) /* type: QVariant */ && ( context->argument(2).isVariant() || context->argument(2).isQObject() || context->argument(2).isNull() ) /* type: RTransaction * */ ){ // prepare arguments: // argument isCopyable and has default constructor and isSimpleClass RPropertyTypeId* ap0 = qscriptvalue_cast< RPropertyTypeId* >( context->argument( 0 ) ); if (ap0 == NULL) { return REcmaHelper::throwError("RView: Argument 0 is not of type RPropertyTypeId.", context); } RPropertyTypeId a0 = *ap0; // argument isCopyable or pointer QVariant a1 = qscriptvalue_cast< QVariant >( context->argument( 1 ) ); // argument is pointer RTransaction * a2 = NULL; a2 = REcmaHelper::scriptValueTo<RTransaction >( context->argument(2) ); if (a2==NULL && !context->argument(2).isNull()) { return REcmaHelper::throwError("RView: Argument 2 is not of type RTransaction *RTransaction *.", context); } // end of arguments // call C++ function: // return type 'bool' bool cppResult = self->setProperty(a0 , a1 , a2); // return type: bool // standard Type result = QScriptValue(cppResult); } else { return REcmaHelper::throwError("Wrong number/types of arguments for RView.setProperty().", context); } //REcmaHelper::functionEnd("REcmaSharedPointerView::setProperty", context, engine); return result; }
// **************************************************************************** // // Function Name: RBreakGroupAction::Do( ) // // Description: Does the action // // Returns: TRUE if the action was sucessful // // Exceptions: None // // **************************************************************************** // BOOLEAN RBreakGroupAction::Do( ) { // Call the base method to setup the state properly RUndoableAction::Do( ); // Get the group components view m_pGroupView = *m_pCurrentSelection->Start( ); // Unselect the group component m_pCurrentSelection->UnselectAll( ); RView* pParentView = m_pCurrentSelection->GetView( ); // Get the z-position of the group YComponentZPosition groupZPosition = pParentView->GetComponentZPosition( m_pGroupView ); // Remove the components from the group document YComponentIterator iterator = m_pGroupDocument->GetComponentCollectionStart( ); while( iterator != m_pGroupDocument->GetComponentCollectionEnd( ) ) { // Get the view that is in the group RComponentView* pView = dynamic_cast<RComponentView*>( (*iterator)->GetView( m_pGroupView ) ); TpsAssert( pView, "Not a component view." ); // Make a copy of the iterator, as we are going to delete it next YComponentIterator tempIterator = iterator; ++tempIterator; // Get the component document RComponentDocument* pComponent = *iterator; // Remove the component from the group m_pGroupDocument->RemoveComponent( pComponent ); // NULL out the views parent pView->SetParentView( NULL ); // Now add it to its original parent docuemnt m_pParentDocument->AddComponent( pComponent ); // Set the correct z-position pParentView->SetComponentZPosition( pComponent->GetView( pParentView ), groupZPosition ); // Increment the z-position for the next component groupZPosition++; // Move the view back to the coordinate space of its parent view YComponentBoundingRect temp = pView->GetBoundingRect( ); temp *= m_pGroupView->GetBoundingRect( ).GetTransform( ); pView->SetBoundingRect( temp ); // Select the component m_pCurrentSelection->Select( pView, TRUE ); // Reassign the iterator iterator = tempIterator; } // Remove the group component m_pParentDocument->RemoveComponent( m_pGroupDocument ); // Update the view that its layout has changed m_pCurrentSelection->GetView()->XUpdateAllViews( kLayoutChanged, 0 ); // Copy the selection so that we can undo m_OldSelection = *m_pCurrentSelection; return TRUE; }