当前位置: 首页>>代码示例>>C++>>正文


C++ Int函数代码示例

本文整理汇总了C++中Int函数的典型用法代码示例。如果您正苦于以下问题:C++ Int函数的具体用法?C++ Int怎么用?C++ Int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mutate

Expr Simplify::visit(const Cast *op, ExprInfo *bounds) {
    // We don't try to reason about bounds through casts for now
    Expr value = mutate(op->value, nullptr);

    if (may_simplify(op->type) && may_simplify(op->value.type())) {
        const Call *call = value.as<Call>();
        const Cast *cast = value.as<Cast>();
        const Broadcast *broadcast_value = value.as<Broadcast>();
        const Ramp *ramp_value = value.as<Ramp>();
        double f = 0.0;
        int64_t i = 0;
        uint64_t u = 0;
        if (call && (call->is_intrinsic(Call::indeterminate_expression) ||
                     call->is_intrinsic(Call::signed_integer_overflow))) {
            if (call->is_intrinsic(Call::indeterminate_expression)) {
                return make_indeterminate_expression(op->type);
            } else {
                return make_signed_integer_overflow(op->type);
            }
        } else if (value.type() == op->type) {
            return value;
        } else if (op->type.is_int() &&
                   const_float(value, &f) &&
                   std::isfinite(f)) {
            // float -> int
            return IntImm::make(op->type, safe_numeric_cast<int64_t>(f));
        } else if (op->type.is_uint() &&
                   const_float(value, &f) &&
                   std::isfinite(f)) {
            // float -> uint
            return UIntImm::make(op->type, safe_numeric_cast<uint64_t>(f));
        } else if (op->type.is_float() &&
                   const_float(value, &f)) {
            // float -> float
            return FloatImm::make(op->type, f);
        } else if (op->type.is_int() &&
                   const_int(value, &i)) {
            // int -> int
            return IntImm::make(op->type, i);
        } else if (op->type.is_uint() &&
                   const_int(value, &i)) {
            // int -> uint
            return UIntImm::make(op->type, safe_numeric_cast<uint64_t>(i));
        } else if (op->type.is_float() &&
                   const_int(value, &i)) {
            // int -> float
            return FloatImm::make(op->type, safe_numeric_cast<double>(i));
        } else if (op->type.is_int() &&
                   const_uint(value, &u)) {
            // uint -> int
            return IntImm::make(op->type, safe_numeric_cast<int64_t>(u));
        } else if (op->type.is_uint() &&
                   const_uint(value, &u)) {
            // uint -> uint
            return UIntImm::make(op->type, u);
        } else if (op->type.is_float() &&
                   const_uint(value, &u)) {
            // uint -> float
            return FloatImm::make(op->type, safe_numeric_cast<double>(u));
        } else if (cast &&
                   op->type.code() == cast->type.code() &&
                   op->type.bits() < cast->type.bits()) {
            // If this is a cast of a cast of the same type, where the
            // outer cast is narrower, the inner cast can be
            // eliminated.
            return mutate(Cast::make(op->type, cast->value), bounds);
        } else if (cast &&
                   (op->type.is_int() || op->type.is_uint()) &&
                   (cast->type.is_int() || cast->type.is_uint()) &&
                   op->type.bits() <= cast->type.bits() &&
                   op->type.bits() <= op->value.type().bits()) {
            // If this is a cast between integer types, where the
            // outer cast is narrower than the inner cast and the
            // inner cast's argument, the inner cast can be
            // eliminated. The inner cast is either a sign extend
            // or a zero extend, and the outer cast truncates the extended bits
            return mutate(Cast::make(op->type, cast->value), bounds);
        } else if (broadcast_value) {
            // cast(broadcast(x)) -> broadcast(cast(x))
            return mutate(Broadcast::make(Cast::make(op->type.element_of(), broadcast_value->value), broadcast_value->lanes), bounds);
        } else if (ramp_value &&
                   op->type.element_of() == Int(64) &&
                   op->value.type().element_of() == Int(32)) {
            // cast(ramp(a, b, w)) -> ramp(cast(a), cast(b), w)
            return mutate(Ramp::make(Cast::make(op->type.element_of(), ramp_value->base),
                                     Cast::make(op->type.element_of(), ramp_value->stride),
                                     ramp_value->lanes), bounds);
        }
    }

    if (value.same_as(op->value)) {
        return op;
    } else {
        return Cast::make(op->type, value);
    }
}
开发者ID:jiapei100,项目名称:Halide,代码行数:96,代码来源:Simplify_Cast.cpp

示例2: main

int main (){
  Any *a2 = x1x_f (  );
  Any *a4 = x1x_f (  );
  Any *a3 = a4;
  Any a5 = Int(0);
  Any a6 = Int(0);
  a3[a5.i] = a6;
  Any a12 = Int(0);
  Any a35 = Int(0);
  Any a36 = Int( sizeof( a2 ) / sizeof( a2[0] ) );
  Any a13 = a2[a12.i];
  Any a10 = toStr ( a13 );
  println ( a10 );
  Any a19 = Int(1);
  a35 = Int(0);
  a36 = Int( sizeof( a2 ) / sizeof( a2[0] ) );
  Any a20 = a2[a19.i];
  Any a17 = toStr ( a20 );
  println ( a17 );
  Any a26 = Int(0);
  a35 = Int(0);
  a36 = Int( sizeof( a3 ) / sizeof( a3[0] ) );
  Any a27 = a3[a26.i];
  Any a24 = toStr ( a27 );
  println ( a24 );
  Any a33 = Int(1);
  a35 = Int(0);
  a36 = Int( sizeof( a3 ) / sizeof( a3[0] ) );
  Any a34 = a3[a33.i];
  Any a31 = toStr ( a34 );
  println ( a31 );
  return 0;
}
开发者ID:Matt--,项目名称:Whiley-wyce,代码行数:33,代码来源:ListAssign_Valid_9.c

示例3: Int

namespace Json {

const Value Value::null;
const Int Value::minInt = Int ( ~ (UInt (-1) / 2) );
const Int Value::maxInt = Int ( UInt (-1) / 2 );
const UInt Value::maxUInt = UInt (-1);

ValueAllocator::~ValueAllocator ()
{
}

class DefaultValueAllocator : public ValueAllocator
{
public:
    virtual ~DefaultValueAllocator ()
    {
    }

    virtual char* makeMemberName ( const char* memberName )
    {
        return duplicateStringValue ( memberName );
    }

    virtual void releaseMemberName ( char* memberName )
    {
        releaseStringValue ( memberName );
    }

    virtual char* duplicateStringValue ( const char* value,
                                         unsigned int length = unknown )
    {
        //@todo invesgate this old optimization
        //if ( !value  ||  value[0] == 0 )
        //   return 0;

        if ( length == unknown )
            length = (unsigned int)strlen (value);

        char* newString = static_cast<char*> ( malloc ( length + 1 ) );
        memcpy ( newString, value, length );
        newString[length] = 0;
        return newString;
    }

    virtual void releaseStringValue ( char* value )
    {
        if ( value )
            free ( value );
    }
};

static ValueAllocator*& valueAllocator ()
{
    static ValueAllocator* valueAllocator = new DefaultValueAllocator;
    return valueAllocator;
}

static struct DummyValueAllocatorInitializer
{
    DummyValueAllocatorInitializer ()
    {
        valueAllocator ();     // ensure valueAllocator() statics are initialized before main().
    }
} dummyValueAllocatorInitializer;

// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// class Value::CZString
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////

// Notes: index_ indicates if the string was allocated when
// a string is stored.

Value::CZString::CZString ( int index )
    : cstr_ ( 0 )
    , index_ ( index )
{
}

Value::CZString::CZString ( const char* cstr, DuplicationPolicy allocate )
    : cstr_ ( allocate == duplicate ? valueAllocator ()->makeMemberName (cstr)
              : cstr )
    , index_ ( allocate )
{
}

Value::CZString::CZString ( const CZString& other )
    : cstr_ ( other.index_ != noDuplication&&   other.cstr_ != 0
              ?  valueAllocator ()->makeMemberName ( other.cstr_ )
              : other.cstr_ )
    , index_ ( other.cstr_ ? (other.index_ == noDuplication ? noDuplication : duplicate)
               : other.index_ )
{
}

Value::CZString::~CZString ()
{
//.........这里部分代码省略.........
开发者ID:CFQuantum,项目名称:CFQuantumd,代码行数:101,代码来源:json_value.cpp

示例4: Int

 Int operator+(int x) { return *this + Int(x); }
开发者ID:Nobody-7,项目名称:tcpppl_answers,代码行数:1,代码来源:ex04.cpp

示例5: aliasing

void aliasing() {
  // If the loop container is only used for a declaration of a temporary
  // variable to hold each element, we can name the new variable for the
  // converted range-based loop as the temporary variable's name.

  // In the following case, "T" is used as a temporary variable to hold each
  // element, and thus we consider the name "T" aliased to the loop.
  // The extra blank braces are left as a placeholder for after the variable
  // declaration is deleted.
  for (int I = 0; I < N; ++I) {
    Val &T = Arr[I];
    {}
    int Y = T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & T : Arr)
  // CHECK-FIXES-NOT: Val &{{[a-z_]+}} =
  // CHECK-FIXES-NEXT: {}
  // CHECK-FIXES-NEXT: int Y = T.X;

  // The container was not only used to initialize a temporary loop variable for
  // the container's elements, so we do not alias the new loop variable.
  for (int I = 0; I < N; ++I) {
    Val &T = Arr[I];
    int Y = T.X;
    int Z = Arr[I].X + T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & Elem : Arr)
  // CHECK-FIXES-NEXT: Val &T = Elem;
  // CHECK-FIXES-NEXT: int Y = T.X;
  // CHECK-FIXES-NEXT: int Z = Elem.X + T.X;

  for (int I = 0; I < N; ++I) {
    Val T = Arr[I];
    int Y = T.X;
    int Z = Arr[I].X + T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & Elem : Arr)
  // CHECK-FIXES-NEXT: Val T = Elem;
  // CHECK-FIXES-NEXT: int Y = T.X;
  // CHECK-FIXES-NEXT: int Z = Elem.X + T.X;

  // The same for pseudo-arrays like std::vector<T> (or here dependent<Val>)
  // which provide a subscript operator[].
  for (int I = 0; I < V.size(); ++I) {
    Val &T = V[I];
    {}
    int Y = T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & T : V)
  // CHECK-FIXES-NEXT: {}
  // CHECK-FIXES-NEXT: int Y = T.X;

  // The same with a call to at()
  for (int I = 0; I < Pv->size(); ++I) {
    Val &T = Pv->at(I);
    {}
    int Y = T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & T : *Pv)
  // CHECK-FIXES-NEXT: {}
  // CHECK-FIXES-NEXT: int Y = T.X;

  for (int I = 0; I < N; ++I) {
    Val &T = func(Arr[I]);
    int Y = T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & Elem : Arr)
  // CHECK-FIXES-NEXT: Val &T = func(Elem);
  // CHECK-FIXES-NEXT: int Y = T.X;

  int IntArr[N];
  for (unsigned I = 0; I < N; ++I) {
    if (int Alias = IntArr[I]) {
      sideEffect(Alias);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Alias : IntArr)
  // CHECK-FIXES-NEXT: if (Alias)

  for (unsigned I = 0; I < N; ++I) {
    while (int Alias = IntArr[I]) {
      sideEffect(Alias);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Alias : IntArr)
  // CHECK-FIXES-NEXT: while (Alias)

  for (unsigned I = 0; I < N; ++I) {
    switch (int Alias = IntArr[I]) {
    default:
      sideEffect(Alias);
    }
//.........这里部分代码省略.........
开发者ID:sambatyon,项目名称:clang-tools-extra,代码行数:101,代码来源:modernize-loop-convert-extra.cpp

示例6: f_add

Any f_add(Any a, Any b)
{
    return Int(a.data.i + b.data.i);
} 
开发者ID:Matt--,项目名称:Whiley-wyce,代码行数:4,代码来源:hellocount2.c

示例7: solve

 void solve() {
   result = ( math::mod_pow(Int(3), n, m) + m - 1 ) % m;
 }
开发者ID:sh19910711,项目名称:codeforces-solutions,代码行数:3,代码来源:main.cpp

示例8: g

/*double df(double x) { double h = 1e-5; return (f(x+h)-f(x))/h; } */
double g(double x) { return Int(x) - alpha * alpha - 5 * sqrt(x); }
开发者ID:tokar1,项目名称:mech-math,代码行数:2,代码来源:main.cpp

示例9: buildConstraint

static
void buildConstraint(vec<Formula>& ps, vec<Int>& Cs, vec<Formula>& carry, vec<int>& base, int digit_no, vec<vec<Formula> >& out_digits, int max_cost, PBOptions* options)
{
    assert(ps.size() == Cs.size());

    if (FEnv::topSize() > max_cost) throw Exception_TooBig();
    /**
    pf("buildConstraint(");
    for (int i = 0; i < ps.size(); i++)
        pf("%d*%s ", Cs[i], (*debug_names)[index(ps[i])]);
    pf("+ %d carry)\n", carry.size());
    **/

    if (digit_no == base.size()){
    	out_digits.push();
        // Final digit, build sorter for rest:
        // -- add carry bits:
        if (options->opt_sorting_network_encoding == unarySortAddEncoding)
        	 buildSorter(ps, Cs, carry, out_digits.last(), options);
        else {
	        for (int i = 0; i < carry.size(); i++)
	            ps.push(carry[i]),
	            Cs.push(1);
	        buildSorter(ps, Cs, out_digits.last(), options);
        }
    }else{
        vec<Formula>    ps_rem;
        vec<int>        Cs_rem;
        vec<Formula>    ps_div;
        vec<Int>        Cs_div;

        // Split sum according to base:
        int B = base[digit_no];
        for (int i = 0; i < Cs.size(); i++){
            Int div = Cs[i] / Int(B);
            int rem = toint(Cs[i] % Int(B));
            if (div > 0){
                ps_div.push(ps[i]);
                Cs_div.push(div);
            }
            if (rem > 0){
                ps_rem.push(ps[i]);
                Cs_rem.push(rem);
            }
        }
        vec<Formula> result;
		if (options->opt_sorting_network_encoding == unarySortAddEncoding)
        	 buildSorter(ps_rem, Cs_rem, carry, result, options);
        else {
	        // Add carry bits:
	        for (int i = 0; i < carry.size(); i++)
	            ps_rem.push(carry[i]),
	            Cs_rem.push(1);
	
	        // Build sorting network:
	        buildSorter(ps_rem, Cs_rem, result, options);
        }
        
        // Get carry bits:
        carry.clear();
        for (int i = B-1; i < result.size(); i += B)
            carry.push(result[i]);

        out_digits.push();
        for (int i = 0; i < B-1; i++){
            Formula out = _0_;
            for (int j = 0; j < result.size(); j += B){
                int n = j+B-1;
                if (j + i < result.size())
                    out |= result[j + i] & ((n >= result.size()) ? _1_ : ~result[n]);
            }
            out_digits.last().push(out);
        }

        buildConstraint(ps_div, Cs_div, carry, base, digit_no+1, out_digits, max_cost, options); // <<== change to normal loop
    }
}
开发者ID:broesdecat,项目名称:Minisatid,代码行数:77,代码来源:PbSolver_convertSort.C

示例10: visit

    void visit(const Pipeline *op) {
        if (op->buffer != func.name()) {
            IRMutator::visit(op);
        } else {
            
            // We're interested in the case where exactly one of the
            // mins of the buffer depends on the loop_var, and none of
            // the extents do.
            string dim = "";
            Expr min, extent;

            for (size_t i = 0; i < func.args().size(); i++) {
                string min_name = func.name() + "." + func.args()[i] + ".min";
                string extent_name = func.name() + "." + func.args()[i] + ".extent";
                assert(scope.contains(min_name) && scope.contains(extent_name));
                Expr this_min = scope.get(min_name);
                Expr this_extent = scope.get(extent_name);

                if (ExprDependsOnVar(this_extent, loop_var).result) {
                    min = Expr();
                    extent = Expr();
                    break;
                }

                if (ExprDependsOnVar(this_min, loop_var).result) {
                    if (min.defined()) {
                        min = Expr();
                        extent = Expr();
                        break;
                    } else {
                        dim = func.args()[i];
                        min = this_min;
                        extent = this_extent;
                    }
                }
            }

            if (min.defined()) {
                // Ok, we've isolated a function, a dimension to slide along, and loop variable to slide over
                log(2) << "Sliding " << func.name() << " over dimension " << dim << " along loop variable " << loop_var << "\n";
                
                Expr loop_var_expr = new Variable(Int(32), loop_var);
                Expr steady_state = loop_var_expr > loop_min;
                Expr initial_min = substitute(loop_var, loop_min, min);

                // The new min is one beyond the max we reached on the last loop iteration
                Expr new_min = substitute(loop_var, loop_var_expr - 1, min + extent);
                // The new extent is the old extent shrunk by how much we trimmed off the min
                Expr new_extent = extent + min - new_min;

                new_min = new Select(steady_state, new_min, initial_min);
                new_extent = new Select(steady_state, new_extent, extent);

                stmt = new LetStmt(func.name() + "." + dim + ".extent", new_extent, op);
                stmt = new LetStmt(func.name() + "." + dim + ".min", new_min, stmt);

            } else {
                log(2) << "Could not perform sliding window optimization of " << func.name() << " over " << loop_var << "\n";
                stmt = op;
            }


        }
    }
开发者ID:mokerjoke,项目名称:Halide,代码行数:64,代码来源:SlidingWindow.cpp

示例11: cloneUnique

namespace Json {

template <typename T>
static std::unique_ptr<T> cloneUnique(const std::unique_ptr<T>& p) {
  std::unique_ptr<T> r;
  if (p) {
    r = std::unique_ptr<T>(new T(*p));
  }
  return r;
}

// This is a walkaround to avoid the static initialization of Value::null.
// kNull must be word-aligned to avoid crashing on ARM.  We use an alignment of
// 8 (instead of 4) as a bit of future-proofing.
#if defined(__ARMEL__)
#define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
#else
#define ALIGNAS(byte_alignment)
#endif
// static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 };
// const unsigned char& kNullRef = kNull[0];
// const Value& Value::null = reinterpret_cast<const Value&>(kNullRef);
// const Value& Value::nullRef = null;

// static
Value const& Value::nullSingleton() {
  static Value const nullStatic;
  return nullStatic;
}

// for backwards compatibility, we'll leave these global references around, but
// DO NOT use them in JSONCPP library code any more!
Value const& Value::null = Value::nullSingleton();
Value const& Value::nullRef = Value::nullSingleton();

const Int Value::minInt = Int(~(UInt(-1) / 2));
const Int Value::maxInt = Int(UInt(-1) / 2);
const UInt Value::maxUInt = UInt(-1);
#if defined(JSON_HAS_INT64)
const Int64 Value::minInt64 = Int64(~(UInt64(-1) / 2));
const Int64 Value::maxInt64 = Int64(UInt64(-1) / 2);
const UInt64 Value::maxUInt64 = UInt64(-1);
// The constant is hard-coded because some compiler have trouble
// converting Value::maxUInt64 to a double correctly (AIX/xlC).
// Assumes that UInt64 is a 64 bits integer.
static const double maxUInt64AsDouble = 18446744073709551615.0;
#endif // defined(JSON_HAS_INT64)
const LargestInt Value::minLargestInt = LargestInt(~(LargestUInt(-1) / 2));
const LargestInt Value::maxLargestInt = LargestInt(LargestUInt(-1) / 2);
const LargestUInt Value::maxLargestUInt = LargestUInt(-1);

const UInt Value::defaultRealPrecision = 17;

#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
template <typename T, typename U>
static inline bool InRange(double d, T min, U max) {
  // The casts can lose precision, but we are looking only for
  // an approximate range. Might fail on edge cases though. ~cdunn
  // return d >= static_cast<double>(min) && d <= static_cast<double>(max);
  return d >= min && d <= max;
}
#else  // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
static inline double integerToDouble(Json::UInt64 value) {
  return static_cast<double>(Int64(value / 2)) * 2.0 +
         static_cast<double>(Int64(value & 1));
}

template <typename T> static inline double integerToDouble(T value) {
  return static_cast<double>(value);
}

template <typename T, typename U>
static inline bool InRange(double d, T min, U max) {
  return d >= integerToDouble(min) && d <= integerToDouble(max);
}
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)

/** Duplicates the specified string value.
 * @param value Pointer to the string to duplicate. Must be zero-terminated if
 *              length is "unknown".
 * @param length Length of the value. if equals to unknown, then it will be
 *               computed using strlen(value).
 * @return Pointer on the duplicate instance of string.
 */
static inline char* duplicateStringValue(const char* value, size_t length) {
  // Avoid an integer overflow in the call to malloc below by limiting length
  // to a sane value.
  if (length >= static_cast<size_t>(Value::maxInt))
    length = Value::maxInt - 1;

  char* newString = static_cast<char*>(malloc(length + 1));
  if (newString == nullptr) {
    throwRuntimeError("in Json::Value::duplicateStringValue(): "
                      "Failed to allocate string value buffer");
  }
  memcpy(newString, value, length);
  newString[length] = 0;
  return newString;
}

//.........这里部分代码省略.........
开发者ID:mloy,项目名称:jsoncpp,代码行数:101,代码来源:json_value.cpp

示例12: Int

void CodeGen_X86::visit(const Cast *op) {

    if (!op->type.is_vector()) {
        // We only have peephole optimizations for vectors in here.
        CodeGen_Posix::visit(op);
        return;
    }

    vector<Expr> matches;

    struct Pattern {
        Target::Feature feature;
        bool wide_op;
        Type type;
        int min_lanes;
        string intrin;
        Expr pattern;
    };

    static Pattern patterns[] = {
        {   Target::FeatureEnd, true, Int(8, 16), 0, "llvm.x86.sse2.padds.b",
            i8_sat(wild_i16x_ + wild_i16x_)
        },
        {   Target::FeatureEnd, true, Int(8, 16), 0, "llvm.x86.sse2.psubs.b",
            i8_sat(wild_i16x_ - wild_i16x_)
        },
        {   Target::FeatureEnd, true, UInt(8, 16), 0, "llvm.x86.sse2.paddus.b",
            u8_sat(wild_u16x_ + wild_u16x_)
        },
        {   Target::FeatureEnd, true, UInt(8, 16), 0, "llvm.x86.sse2.psubus.b",
            u8(max(wild_i16x_ - wild_i16x_, 0))
        },
        {   Target::FeatureEnd, true, Int(16, 8), 0, "llvm.x86.sse2.padds.w",
            i16_sat(wild_i32x_ + wild_i32x_)
        },
        {   Target::FeatureEnd, true, Int(16, 8), 0, "llvm.x86.sse2.psubs.w",
            i16_sat(wild_i32x_ - wild_i32x_)
        },
        {   Target::FeatureEnd, true, UInt(16, 8), 0, "llvm.x86.sse2.paddus.w",
            u16_sat(wild_u32x_ + wild_u32x_)
        },
        {   Target::FeatureEnd, true, UInt(16, 8), 0, "llvm.x86.sse2.psubus.w",
            u16(max(wild_i32x_ - wild_i32x_, 0))
        },

        // Only use the avx2 version if we have > 8 lanes
        {   Target::AVX2, true, Int(16, 16), 9, "llvm.x86.avx2.pmulh.w",
            i16((wild_i32x_ * wild_i32x_) / 65536)
        },
        {   Target::AVX2, true, UInt(16, 16), 9, "llvm.x86.avx2.pmulhu.w",
            u16((wild_u32x_ * wild_u32x_) / 65536)
        },

        {   Target::FeatureEnd, true, Int(16, 8), 0, "llvm.x86.sse2.pmulh.w",
            i16((wild_i32x_ * wild_i32x_) / 65536)
        },
        {   Target::FeatureEnd, true, UInt(16, 8), 0, "llvm.x86.sse2.pmulhu.w",
            u16((wild_u32x_ * wild_u32x_) / 65536)
        },
        {   Target::FeatureEnd, true, UInt(8, 16), 0, "llvm.x86.sse2.pavg.b",
            u8(((wild_u16x_ + wild_u16x_) + 1) / 2)
        },
        {   Target::FeatureEnd, true, UInt(16, 8), 0, "llvm.x86.sse2.pavg.w",
            u16(((wild_u32x_ + wild_u32x_) + 1) / 2)
        },
        {   Target::FeatureEnd, false, Int(16, 8), 0, "packssdwx8",
            i16_sat(wild_i32x_)
        },
        {   Target::FeatureEnd, false, Int(8, 16), 0, "packsswbx16",
            i8_sat(wild_i16x_)
        },
        {   Target::FeatureEnd, false, UInt(8, 16), 0, "packuswbx16",
            u8_sat(wild_i16x_)
        },
        {   Target::SSE41, false, UInt(16, 8), 0, "packusdwx8",
            u16_sat(wild_i32x_)
        }
    };

    for (size_t i = 0; i < sizeof(patterns)/sizeof(patterns[0]); i++) {
        const Pattern &pattern = patterns[i];

        if (!target.has_feature(pattern.feature)) {
            continue;
        }

        if (op->type.lanes() < pattern.min_lanes) {
            continue;
        }

        if (expr_match(pattern.pattern, op, matches)) {
            bool match = true;
            if (pattern.wide_op) {
                // Try to narrow the matches to the target type.
                for (size_t i = 0; i < matches.size(); i++) {
                    matches[i] = lossless_cast(op->type, matches[i]);
                    if (!matches[i].defined()) match = false;
                }
            }
            if (match) {
//.........这里部分代码省略.........
开发者ID:cyanjc321,项目名称:Halide,代码行数:101,代码来源:CodeGen_X86.cpp

示例13: lineWrap

std::string lineWrap(const std::string &input, const UInt maximumLineLength)
{
  if (maximumLineLength == 0)
  {
    return input;
  }
  std::string result = input;

  std::string::size_type lineStartPosition = result.find_first_not_of(' '); //don't wrap any leading spaces in the string

  while (lineStartPosition != std::string::npos)
  {
    //------------------------------------------------

    const std::string::size_type searchFromPosition = lineStartPosition + maximumLineLength;

    if (searchFromPosition >= result.length())
    {
      break;
    }

    //------------------------------------------------

    //first check to see if there is another new line character before the maximum line length
    //we can't use find for this unfortunately because it doesn't take both a beginning and an end for its search range
    std::string::size_type nextLineStartPosition = std::string::npos;
    for (std::string::size_type currentPosition = lineStartPosition; currentPosition <= searchFromPosition; currentPosition++)
    {
      if (result[currentPosition] == '\n')
      {
        nextLineStartPosition = currentPosition + 1;
        break;
      }
    }

    //------------------------------------------------

    //if there ia another new line character before the maximum line length, we need to start this loop again from that position
    if (nextLineStartPosition != std::string::npos)
    {
      lineStartPosition = nextLineStartPosition;
    }
    else
    {
      std::string::size_type spacePosition = std::string::npos;

      //search backwards for the last space character (must use signed Int because lineStartPosition can be 0)
      for (Int currentPosition = Int(searchFromPosition); currentPosition >= Int(lineStartPosition); currentPosition--)
      {
        if (result[currentPosition] == ' ')
        {
          spacePosition = currentPosition;
          break;
        }
      }

      //if we didn't find a space searching backwards, we must hyphenate
      if (spacePosition == std::string::npos)
      {
        result.insert(searchFromPosition, "-\n");
        lineStartPosition = searchFromPosition + 2; //make sure the next search ignores the hyphen
      }
      else //if we found a space to split on, replace it with a new line character
      {
        result.replace(spacePosition, 1, 1, '\n');
        lineStartPosition = spacePosition + 1;
      }
    }

    //------------------------------------------------
  }

  return result;
}
开发者ID:Jcamilorada,项目名称:HEVC,代码行数:74,代码来源:Debug.cpp

示例14: GET_LOG

    std::pair< std::vector< SParamOptMsg< SamplePointT > >, bool >
    ParameterOptimizationServer< SamplePointT, SamplePointGrid >
    ::GetNConvergedElements( )
    {
      typedef GeometricOptimizationBase<SamplePointT> Base;
      const Int nMaxElements = nProcessingElements * LocalSetup.InputParameters().nOptNumElementPerPE * 3; 
      if( VoxelQueue.Size() > nMaxElements )
      {
        GET_LOG( osLogFile ) << "Number of elements from structure: " << VoxelQueue.Size() << std::endl;
        GET_LOG( osLogFile ) << "   exceeds the maximum number of elements to be fitted: " << nMaxElements << std::endl;
        GET_LOG( osLogFile ) << "Limiting to " <<   nMaxElements << " elements " << std::endl;
        VoxelQueue.RandomizedSetMaxElements( nMaxElements );
      }
      
      std::queue<int> WaitQueue;
      for( int i = 1; i <= (nProcessingElements - 1); i ++ )  // start from 1, since 0 is Server
        WaitQueue.push( i );
      typedef XDMParallel::MultiElementDistribution<SamplePointT>       MultiElementDistributor;
      MultiElementDistributor SingleVoxelDistributor(1);
      Utilities::WorkUnitDistribution( VoxelQueue, SingleVoxelDistributor, WaitQueue, Base::Comm, osLogFile, 0,  XDMParallel::FIT_MC );
      GET_LOG( osLogFile ) << "Finished with Initial Work Unit Distribution " << std::endl;

      typedef SParamOptMsg< SamplePointT > ParamOptMsg;
      vector<ParamOptMsg> oConvergedSamplePoints;
      Int nElementsToFit  = LocalSetup.InputParameters().nOptNumElementPerPE;   // parameters?
      int NumClients      = nProcessingElements -1;
      Int NumElementsUsed = NumClients;
      while( ! VoxelQueue.Empty() || WaitQueue.size() < NumClients
             || Int( oConvergedSamplePoints.size() ) >= nElementsToFit )   
      {
        Int                  nClientPE;
        Int                  nCommand;
        vector<ParamOptMsg> TmpResult;
        ParamOptMsg          oOptResult;
        NumElementsUsed ++; 
        Base::Comm.RecvCommand( &nClientPE, &nCommand );  
        RUNTIME_ASSERT( nCommand == XDMParallel::REPORT_MC, "\nDriver::Server: Unknown command from client recv \n" );
        Base::Comm.RecvWorkUnitList( nClientPE, TmpResult );
        RUNTIME_ASSERT( TmpResult.size() == 1, "[This error check shall be removed after debugging] Error: Size mismatch in PMC\n " );
        oOptResult = TmpResult[0];
        if( oOptResult.bConverged )
          oConvergedSamplePoints.push_back( oOptResult );
        
        if ( oConvergedSamplePoints.size() < nElementsToFit && (NumElementsUsed < nMaxElements) ) // if there's still voxels left
          Utilities::WorkUnitDistribution( VoxelQueue, SingleVoxelDistributor, WaitQueue, Base::Comm, osLogFile, 0,  XDMParallel::FIT_MC );
        else                                     // tell client that we're done
          Base::Comm.SendCommand( nMyID, nClientPE, XDMParallel::WAIT );
      }
      
      if( oConvergedSamplePoints.size() > nElementsToFit )
      {
        GET_LOG( osLogFile ) << "Needed " << nElementsToFit << " Ended with "
                             <<   oConvergedSamplePoints.size()  << std::endl;
        std::sort( oConvergedSamplePoints.begin(), oConvergedSamplePoints.end()  ); // sort by quality, ascending
        int nExtraPoints = oConvergedSamplePoints.size() - nElementsToFit;
        oConvergedSamplePoints.erase( oConvergedSamplePoints.begin(),
                                      oConvergedSamplePoints.begin() + nExtraPoints ); // keep only the last nElementsToFit
        GET_LOG( osLogFile ) << "List has been trimed to the best " << oConvergedSamplePoints.size() << " elements " << std::endl;
      }
      return  std::make_pair( oConvergedSamplePoints, oConvergedSamplePoints.size() >= nElementsToFit );
    }
开发者ID:chongbingbao,项目名称:IceNine,代码行数:61,代码来源:ParameterOptimizationServer.tmpl.cpp

示例15: args

Expr BufferBuilder::build() const {
    std::vector<Expr> args(10);
    if (buffer_memory.defined()) {
        args[0] = buffer_memory;
    } else {
        args[0] = Call::make(type_of<struct halide_buffer_t *>(), Call::alloca, {(int)sizeof(halide_buffer_t)}, Call::Intrinsic);
    }

    std::string shape_var_name = unique_name('t');
    Expr shape_var = Variable::make(type_of<halide_dimension_t *>(), shape_var_name);
    if (shape_memory.defined()) {
        args[1] = shape_memory;
    } else if (dimensions == 0) {
        args[1] = make_zero(type_of<halide_dimension_t *>());
    } else {
        args[1] = shape_var;
    }

    if (host.defined()) {
        args[2] = host;
    } else {
        args[2] = make_zero(type_of<void *>());
    }

    if (device.defined()) {
        args[3] = device;
    } else {
        args[3] = make_zero(UInt(64));
    }

    if (device_interface.defined()) {
        args[4] = device_interface;
    } else {
        args[4] = make_zero(type_of<struct halide_device_interface_t *>());
    }

    args[5] = (int)type.code();
    args[6] = type.bits();
    args[7] = dimensions;

    std::vector<Expr> shape;
    for (size_t i = 0; i < (size_t)dimensions; i++) {
        if (i < mins.size()) {
            shape.push_back(mins[i]);
        } else {
            shape.push_back(0);
        }
        if (i < extents.size()) {
            shape.push_back(extents[i]);
        } else {
            shape.push_back(0);
        }
        if (i < strides.size()) {
            shape.push_back(strides[i]);
        } else {
            shape.push_back(0);
        }
        // per-dimension flags, currently unused.
        shape.push_back(0);
    }
    for (const Expr &e : shape) {
        internal_assert(e.type() == Int(32))
            << "Buffer shape fields must be int32_t:" << e << "\n";
    }
    Expr shape_arg = Call::make(type_of<halide_dimension_t *>(), Call::make_struct, shape, Call::Intrinsic);
    if (shape_memory.defined()) {
        args[8] = shape_arg;
    } else if (dimensions == 0) {
        args[8] = make_zero(type_of<halide_dimension_t *>());
    } else {
        args[8] = shape_var;
    }

    Expr flags = make_zero(UInt(64));
    if (host_dirty.defined()) {
        flags = select(host_dirty,
                       make_const(UInt(64), halide_buffer_flag_host_dirty),
                       make_zero(UInt(64)));
    }
    if (device_dirty.defined()) {
        flags = flags | select(device_dirty,
                               make_const(UInt(64), halide_buffer_flag_device_dirty),
                               make_zero(UInt(64)));
    }
    args[9] = flags;

    Expr e = Call::make(type_of<struct halide_buffer_t *>(), Call::buffer_init, args, Call::Extern);

    if (!shape_memory.defined() && dimensions != 0) {
        e = Let::make(shape_var_name, shape_arg, e);
    }

    return e;
}
开发者ID:bleibig,项目名称:Halide,代码行数:94,代码来源:IROperator.cpp


注:本文中的Int函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。