本文整理汇总了C++中UNLIKELY函数的典型用法代码示例。如果您正苦于以下问题:C++ UNLIKELY函数的具体用法?C++ UNLIKELY怎么用?C++ UNLIKELY使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UNLIKELY函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: view3d_ruler_modal
static int view3d_ruler_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
bool do_draw = false;
int exit_code = OPERATOR_RUNNING_MODAL;
RulerInfo *ruler_info = op->customdata;
ScrArea *sa = ruler_info->sa;
ARegion *ar = ruler_info->ar;
RegionView3D *rv3d = ar->regiondata;
/* its possible to change spaces while running the operator [#34894] */
if (UNLIKELY(ar != CTX_wm_region(C))) {
exit_code = OPERATOR_FINISHED;
goto exit;
}
switch (event->type) {
case LEFTMOUSE:
if (event->val == KM_RELEASE) {
if (ruler_info->state == RULER_STATE_DRAG) {
/* rubber-band angle removal */
RulerItem *ruler_item = ruler_item_active_get(ruler_info);
if (ruler_item && (ruler_item->co_index == 1) && (ruler_item->flag & RULERITEM_USE_ANGLE)) {
if (!BLI_rcti_isect_pt_v(&ar->winrct, &event->x)) {
ruler_item->flag &= ~RULERITEM_USE_ANGLE;
do_draw = true;
}
}
if (ruler_info->snap_flag & RULER_SNAP_OK) {
ruler_info->snap_flag &= ~RULER_SNAP_OK;
do_draw = true;
}
ruler_info->state = RULER_STATE_NORMAL;
}
}
else {
if (ruler_info->state == RULER_STATE_NORMAL) {
if (event->ctrl ||
/* weak - but user friendly */
(ruler_info->items.first == NULL))
{
View3D *v3d = CTX_wm_view3d(C);
const bool use_depth = (v3d->drawtype >= OB_SOLID);
/* Create new line */
RulerItem *ruler_item_prev = ruler_item_active_get(ruler_info);
RulerItem *ruler_item;
/* check if we want to drag an existing point or add a new one */
ruler_info->state = RULER_STATE_DRAG;
ruler_item = ruler_item_add(ruler_info);
ruler_item_active_set(ruler_info, ruler_item);
if (use_depth) {
/* snap the first point added, not essential but handy */
ruler_item->co_index = 0;
view3d_ruler_item_mousemove(C, ruler_info, event->mval, false, true);
copy_v3_v3(ruler_info->drag_start_co, ruler_item->co[ruler_item->co_index]);
}
else {
/* initial depth either previous ruler, view offset */
if (ruler_item_prev) {
copy_v3_v3(ruler_info->drag_start_co, ruler_item_prev->co[ruler_item_prev->co_index]);
}
else {
negate_v3_v3(ruler_info->drag_start_co, rv3d->ofs);
}
copy_v3_v3(ruler_item->co[0], ruler_info->drag_start_co);
view3d_ruler_item_project(ruler_info, ruler_item->co[0], event->mval);
}
copy_v3_v3(ruler_item->co[2], ruler_item->co[0]);
ruler_item->co_index = 2;
do_draw = true;
}
else {
float mval_fl[2] = {UNPACK2(event->mval)};
RulerItem *ruler_item_pick;
int co_index;
/* select and drag */
if (view3d_ruler_pick(ruler_info, mval_fl, &ruler_item_pick, &co_index)) {
if (co_index == -1) {
if ((ruler_item_pick->flag & RULERITEM_USE_ANGLE) == 0) {
/* Add Center Point */
ruler_item_active_set(ruler_info, ruler_item_pick);
ruler_item_pick->flag |= RULERITEM_USE_ANGLE;
ruler_item_pick->co_index = 1;
ruler_info->state = RULER_STATE_DRAG;
/* find the factor */
{
float co_ss[2][2];
float fac;
ED_view3d_project_float_global(ar, ruler_item_pick->co[0], co_ss[0], V3D_PROJ_TEST_NOP);
ED_view3d_project_float_global(ar, ruler_item_pick->co[2], co_ss[1], V3D_PROJ_TEST_NOP);
//.........这里部分代码省略.........
示例2: sqrt3f
MINLINE float sqrt3f(float f)
{
if (UNLIKELY(f == 0.0f)) return 0.0f;
else if (UNLIKELY(f < 0.0f)) return -(float)(exp(log(-f) / 3.0));
else return (float)(exp(log( f) / 3.0));
}
示例3: saacos
MINLINE float saacos(float fac)
{
if (UNLIKELY(fac <= -1.0f)) return (float)M_PI;
else if (UNLIKELY(fac >= 1.0f)) return 0.0f;
else return acosf(fac);
}
示例4: bowed
int bowed(CSOUND *csound, BOWED *p)
{
MYFLT *ar = p->ar;
uint32_t offset = p->h.insdshead->ksmps_offset;
uint32_t early = p->h.insdshead->ksmps_no_end;
uint32_t n, nsmps = CS_KSMPS;
MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */
MYFLT maxVel;
int freq_changed = 0;
if (amp != p->lastamp) {
p->maxVelocity = FL(0.03) + (FL(0.2) * amp);
p->lastamp = amp;
}
maxVel = p->maxVelocity;
if (p->lastpress != *p->bowPress)
p->bowTabl.slope = p->lastpress = *p->bowPress;
/* Set Frequency if changed */
if (p->lastfreq != *p->frequency) {
/* delay - approx. filter delay */
if (p->limit<=*p->frequency)
p->lastfreq = *p->frequency;
else {
p->lastfreq = p->limit;
csound->Warning(csound, Str("frequency too low, set to minimum"));
}
p->baseDelay = CS_ESR / p->lastfreq - FL(4.0);
freq_changed = 1;
}
if (p->lastbeta != *p->betaRatio ||
freq_changed) { /* Reset delays if changed */
p->lastbeta = *p->betaRatio;
DLineL_setDelay(&p->bridgeDelay, /* bow to bridge length */
p->baseDelay * p->lastbeta);
DLineL_setDelay(&p->neckDelay, /* bow to nut (finger) length */
p->baseDelay *(FL(1.0) - p->lastbeta));
}
p->v_rate = *p->vibFreq * p->vibr->flen * csound->onedsr;
if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1;
if ((--p->kloop) == 0) {
ADSR_setDecayRate(csound, &p->adsr, (FL(1.0) - p->adsr.value) * FL(0.005));
p->adsr.target = FL(0.0);
p->adsr.rate = p->adsr.releaseRate;
p->adsr.state = RELEASE;
}
if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT));
if (UNLIKELY(early)) {
nsmps -= early;
memset(&ar[nsmps], '\0', early*sizeof(MYFLT));
}
for (n=offset;n<nsmps;n++) {
MYFLT bowVelocity;
MYFLT bridgeRefl=FL(0.0), nutRefl=FL(0.0);
MYFLT newVel=FL(0.0), velDiff=FL(0.0), stringVel=FL(0.0);
MYFLT lastOutput;
bowVelocity = maxVel * ADSR_tick(&p->adsr);
/* Bridge Reflection */
bridgeRefl = - OnePole_tick(&p->reflFilt, p->bridgeDelay.lastOutput);
nutRefl = - p->neckDelay.lastOutput; /* Nut Reflection */
stringVel = bridgeRefl + nutRefl; /* Sum is String Velocity */
velDiff = bowVelocity - stringVel; /* Differential Velocity */
/* Non-Lin Bow Function */
newVel = velDiff * BowTabl_lookup(csound, &p->bowTabl, velDiff);
DLineL_tick(&p->neckDelay, bridgeRefl + newVel); /* Do string */
DLineL_tick(&p->bridgeDelay, nutRefl + newVel); /* propagations */
if (*p->vibAmt > FL(0.0)) {
int32 temp;
MYFLT temp_time, alpha;
/* Tick on vibrato table */
p->v_time += p->v_rate; /* Update current time */
while (p->v_time >= p->vibr->flen) /* Check for end of sound */
p->v_time -= p->vibr->flen; /* loop back to beginning */
while (p->v_time < FL(0.0)) /* Check for end of sound */
p->v_time += p->vibr->flen; /* loop back to beginning */
temp_time = p->v_time;
#ifdef phase_offset
if (p->v_phaseOffset != FL(0.0)) {
temp_time += p->v_phaseOffset; /* Add phase offset */
while (temp_time >= p->vibr->flen) /* Check for end of sound */
temp_time -= p->vibr->flen; /* loop back to beginning */
while (temp_time < FL(0.0)) /* Check for end of sound */
temp_time += p->vibr->flen; /* loop back to beginning */
}
#endif
temp = (int32) temp_time; /* Integer part of time address */
/* fractional part of time address */
alpha = temp_time - (MYFLT)temp;
p->v_lastOutput = p->vibr->ftable[temp]; /* Do linear interpolation */
/* same as alpha*data[temp+1] + (1-alpha)data[temp] */
p->v_lastOutput = p->v_lastOutput +
(alpha * (p->vibr->ftable[temp+1] - p->v_lastOutput));
/* End of vibrato tick */
//.........这里部分代码省略.........
示例5: detectCycle
// throws if establishing a dependency from this to child would form a cycle
void c_BlockableWaitHandle::detectCycle(c_WaitableWaitHandle* child) const {
if (UNLIKELY(isDescendantOf(child))) {
Object e(createCycleException(child));
throw e;
}
}
示例6: BLI_kdtree_find_nearest_n__normal
/**
* Find n nearest returns number of points found, with results in nearest.
* Normal is optional, but if given will limit results to points in normal direction from co.
*
* \param r_nearest: An array of nearest, sized at least \a n.
*/
int BLI_kdtree_find_nearest_n__normal(
const KDTree *tree, const float co[3], const float nor[3],
KDTreeNearest r_nearest[],
uint n)
{
const KDTreeNode *nodes = tree->nodes;
const KDTreeNode *root;
uint *stack, defaultstack[KD_STACK_INIT];
float cur_dist;
uint totstack, cur = 0;
uint i, found = 0;
#ifdef DEBUG
BLI_assert(tree->is_balanced == true);
#endif
if (UNLIKELY((tree->root == KD_NODE_UNSET) || n == 0))
return 0;
stack = defaultstack;
totstack = KD_STACK_INIT;
root = &nodes[tree->root];
cur_dist = squared_distance(root->co, co, nor);
add_nearest(r_nearest, &found, n, root->index, cur_dist, root->co);
if (co[root->d] < root->co[root->d]) {
if (root->right != KD_NODE_UNSET)
stack[cur++] = root->right;
if (root->left != KD_NODE_UNSET)
stack[cur++] = root->left;
}
else {
if (root->left != KD_NODE_UNSET)
stack[cur++] = root->left;
if (root->right != KD_NODE_UNSET)
stack[cur++] = root->right;
}
while (cur--) {
const KDTreeNode *node = &nodes[stack[cur]];
cur_dist = node->co[node->d] - co[node->d];
if (cur_dist < 0.0f) {
cur_dist = -cur_dist * cur_dist;
if (found < n || -cur_dist < r_nearest[found - 1].dist) {
cur_dist = squared_distance(node->co, co, nor);
if (found < n || cur_dist < r_nearest[found - 1].dist)
add_nearest(r_nearest, &found, n, node->index, cur_dist, node->co);
if (node->left != KD_NODE_UNSET)
stack[cur++] = node->left;
}
if (node->right != KD_NODE_UNSET)
stack[cur++] = node->right;
}
else {
cur_dist = cur_dist * cur_dist;
if (found < n || cur_dist < r_nearest[found - 1].dist) {
cur_dist = squared_distance(node->co, co, nor);
if (found < n || cur_dist < r_nearest[found - 1].dist)
add_nearest(r_nearest, &found, n, node->index, cur_dist, node->co);
if (node->right != KD_NODE_UNSET)
stack[cur++] = node->right;
}
if (node->left != KD_NODE_UNSET)
stack[cur++] = node->left;
}
if (UNLIKELY(cur + 3 > totstack)) {
stack = realloc_nodes(stack, &totstack, defaultstack != stack);
}
}
for (i = 0; i < found; i++)
r_nearest[i].dist = sqrtf(r_nearest[i].dist);
if (stack != defaultstack)
MEM_freeN(stack);
return (int)found;
}
示例7: clarin
int clarin(CSOUND *csound, CLARIN *p)
{
MYFLT *ar = p->ar;
uint32_t offset = p->h.insdshead->ksmps_offset;
uint32_t early = p->h.insdshead->ksmps_no_end;
uint32_t n, nsmps = CS_KSMPS;
MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */
MYFLT nGain = *p->noiseGain;
int v_len = (int)p->vibr->flen;
MYFLT *v_data = p->vibr->ftable;
MYFLT vibGain = *p->vibAmt;
MYFLT vTime = p->v_time;
if (p->envelope.rate==FL(0.0)) {
p->envelope.rate = amp /(*p->attack*CS_ESR);
p->envelope.value = p->envelope.target = FL(0.55) + amp*FL(0.30);
}
p->outputGain = amp + FL(0.001);
DLineL_setDelay(&p->delayLine, /* length - approx filter delay */
(CS_ESR/ *p->frequency) * FL(0.5) - FL(1.5));
p->v_rate = *p->vibFreq * p->vibr->flen * csound->onedsr;
/* Check to see if into decay yet */
if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1;
if ((--p->kloop) == 0) {
p->envelope.state = 1; /* Start change */
p->envelope.rate = p->envelope.value / (*p->dettack * CS_ESR);
p->envelope.target = FL(0.0);
#ifdef BETA
csound->Message(csound, "Set off phase time = %f Breath v,r = %f, %f\n",
(MYFLT) CS_KCNT * CS_ONEDKR,
p->envelope.value, p->envelope.rate);
#endif
}
if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT));
if (UNLIKELY(early)) {
nsmps -= early;
memset(&ar[nsmps], '\0', early*sizeof(MYFLT));
}
for (n=offset;n<nsmps;n++) {
MYFLT pressureDiff;
MYFLT breathPressure;
int32 temp;
MYFLT temp_time, alpha;
MYFLT nextsamp;
MYFLT v_lastOutput;
MYFLT lastOutput;
breathPressure = Envelope_tick(&p->envelope);
breathPressure += breathPressure * nGain * Noise_tick(csound,&p->noise);
/* Tick on vibrato table */
vTime += p->v_rate; /* Update current time */
while (vTime >= v_len) /* Check for end of sound */
vTime -= v_len; /* loop back to beginning */
while (vTime < FL(0.0)) /* Check for end of sound */
vTime += v_len; /* loop back to beginning */
temp_time = vTime;
#ifdef have_phase
if (p->v_phaseOffset != FL(0.0)) {
temp_time += p->v_phaseOffset; /* Add phase offset */
while (temp_time >= v_len) /* Check for end of sound */
temp_time -= v_len; /* loop back to beginning */
while (temp_time < FL(0.0)) /* Check for end of sound */
temp_time += v_len; /* loop back to beginning */
}
#endif
temp = (int32) temp_time; /* Integer part of time address */
/* fractional part of time address */
alpha = temp_time - (MYFLT)temp;
v_lastOutput = v_data[temp]; /* Do linear interpolation */
/* same as alpha*data[temp+1] + (1-alpha)data[temp] */
v_lastOutput += (alpha * (v_data[temp+1] - v_lastOutput));
/* End of vibrato tick */
breathPressure += breathPressure * vibGain * v_lastOutput;
pressureDiff = OneZero_tick(&p->filter, /* differential pressure */
DLineL_lastOut(&p->delayLine));
pressureDiff = (-FL(0.95)*pressureDiff) - breathPressure;
/* of reflected and mouth */
nextsamp = pressureDiff * ReedTabl_LookUp(&p->reedTable,pressureDiff);
nextsamp = breathPressure + nextsamp;
/* perform scattering in economical way */
lastOutput = DLineL_tick(&p->delayLine, nextsamp);
lastOutput *= p->outputGain;
ar[n] = lastOutput*AMP_SCALE;
}
p->v_time = vTime;
return OK;
}
示例8: V8TestInterfaceNamedConstructorConstructorCallback
static void V8TestInterfaceNamedConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
if (!info.IsConstructCall()) {
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::constructorNotCallableAsFunction("Audio"));
return;
}
if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
v8SetReturnValue(info, info.Holder());
return;
}
ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceNamedConstructor", info.Holder(), info.GetIsolate());
if (UNLIKELY(info.Length() < 1)) {
setMinimumArityTypeError(exceptionState, 1, info.Length());
exceptionState.throwIfNeeded();
return;
}
V8StringResource<> stringArg;
bool defaultUndefinedOptionalBooleanArg;
int defaultUndefinedOptionalLongArg;
V8StringResource<> defaultUndefinedOptionalStringArg;
V8StringResource<> defaultNullStringOptionalstringArg;
V8StringResource<> optionalStringArg;
{
int numArgsPassed = info.Length();
while (numArgsPassed > 0) {
if (!info[numArgsPassed - 1]->IsUndefined())
break;
--numArgsPassed;
}
stringArg = info[0];
if (!stringArg.prepare())
return;
defaultUndefinedOptionalBooleanArg = toBoolean(info.GetIsolate(), info[1], exceptionState);
if (exceptionState.throwIfNeeded())
return;
defaultUndefinedOptionalLongArg = toInt32(info.GetIsolate(), info[2], NormalConversion, exceptionState);
if (exceptionState.throwIfNeeded())
return;
defaultUndefinedOptionalStringArg = info[3];
if (!defaultUndefinedOptionalStringArg.prepare())
return;
if (!info[4]->IsUndefined()) {
defaultNullStringOptionalstringArg = info[4];
if (!defaultNullStringOptionalstringArg.prepare())
return;
} else {
defaultNullStringOptionalstringArg = nullptr;
}
if (UNLIKELY(numArgsPassed <= 5)) {
Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
TestInterfaceNamedConstructor* impl = TestInterfaceNamedConstructor::createForJSConstructor(document, stringArg, defaultUndefinedOptionalBooleanArg, defaultUndefinedOptionalLongArg, defaultUndefinedOptionalStringArg, defaultNullStringOptionalstringArg, exceptionState);
if (exceptionState.hadException()) {
exceptionState.throwIfNeeded();
return;
}
v8::Local<v8::Object> wrapper = info.Holder();
wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo, wrapper);
v8SetReturnValue(info, wrapper);
return;
}
optionalStringArg = info[5];
if (!optionalStringArg.prepare())
return;
}
Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
TestInterfaceNamedConstructor* impl = TestInterfaceNamedConstructor::createForJSConstructor(document, stringArg, defaultUndefinedOptionalBooleanArg, defaultUndefinedOptionalLongArg, defaultUndefinedOptionalStringArg, defaultNullStringOptionalstringArg, optionalStringArg, exceptionState);
if (exceptionState.hadException()) {
exceptionState.throwIfNeeded();
return;
}
v8::Local<v8::Object> wrapper = info.Holder();
wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo, wrapper);
v8SetReturnValue(info, wrapper);
}
示例9: OpenMidiInDevice_
static int OpenMidiInDevice_(CSOUND *csound, void **userData, const char *dev)
{
int cntdev, devnum, opendevs, i;
PmEvent buffer;
PmError retval;
PmDeviceInfo *info;
// PortMidiStream *midistream;
pmall_data *data = NULL;
pmall_data *next = NULL;
if (start_portmidi(csound) != 0)
return -1;
/* check if there are any devices available */
cntdev = portMidi_getDeviceCount(0);
portMidi_listDevices(csound, 0);
/* look up device in list */
if (dev == NULL || dev[0] == '\0')
devnum =
portMidi_getPackedDeviceID((int)Pm_GetDefaultInputDeviceID(), 0);
else if (UNLIKELY((dev[0] < '0' || dev[0] > '9') && dev[0] != 'a')) {
portMidiErrMsg(csound,
Str("error: must specify a device number (>=0) or"
" 'a' for all, not a name"));
return -1;
}
else if (dev[0] != 'a') {
devnum = (int)atoi(dev);
if (UNLIKELY(devnum < 0 || devnum >= cntdev)) {
portMidiErrMsg(csound, Str("error: device number is out of range"));
return -1;
}
}
else {
// allow to proceed if 'a' is given even if there are no MIDI devices
devnum = -1;
}
if (UNLIKELY(cntdev < 1 && (dev==NULL || dev[0] != 'a'))) {
return portMidiErrMsg(csound, Str("no input devices are available"));
}
opendevs = 0;
for (i = 0; i < cntdev; i++) {
if (devnum == i || devnum == -1) {
if (opendevs == 0) {
data = (pmall_data *) malloc(sizeof(pmall_data));
next = data;
data->next = NULL;
opendevs++;
}
else {
next->next = (pmall_data *) malloc(sizeof(pmall_data));
next = next->next;
next->next = NULL;
opendevs++;
}
info = portMidi_getDeviceInfo(i, 0);
if (info->interf != NULL)
csound->Message(csound,
Str("PortMIDI: Activated input device %d: '%s' (%s)\n"),
i, info->name, info->interf);
else
csound->Message(csound,
Str("PortMIDI: Activated input device %d: '%s'\n"),
i, info->name);
retval = Pm_OpenInput(&next->midistream,
(PmDeviceID) portMidi_getRealDeviceID(i, 0),
NULL, 512L, (PmTimeProcPtr) NULL, NULL);
if (UNLIKELY(retval != pmNoError)) {
// Prevent leaking memory from "data"
if (data) {
next = data->next;
free(data);
}
return portMidiErrMsg(csound, Str("error opening input device %d: %s"),
i, Pm_GetErrorText(retval));
}
/* only interested in channel messages (note on, control change, etc.) */
/* GAB: fixed for portmidi v.23Aug06 */
Pm_SetFilter(next->midistream, (PM_FILT_ACTIVE | PM_FILT_SYSEX));
/* empty the buffer after setting filter */
while (Pm_Poll(next->midistream) == TRUE) {
Pm_Read(next->midistream, &buffer, 1);
}
}
}
*userData = (void*) data;
/* report success */
return 0;
}
示例10: vsw16_sse2_forward
int32_t
vsw16_sse2_forward(vsw16_query_t *query, const uint8_t *target, int32_t tlen,
int32_t query_start_clip, int32_t query_end_clip,
vsw_opt_t *opt, int16_t *query_end, int16_t *target_end,
int32_t direction, int32_t *overflow, int32_t *n_best, int32_t score_thr)
{
int32_t slen, i, j, k, sum = 0;
#ifdef VSW_DEBUG
int32_t l;
#endif
uint16_t cmp;
vsw16_int_t gmax, best;
vsw16_int_t zero, imin = 0, imax = 0;
__m128i zero_mm, zero_start_mm, negative_infinity_mm, positive_infinity_mm, reduce_mm;
__m128i pen_gapoe, pen_gape, *H0, *H1, *E;
// initialization
// normalize these
zero = query->zero_aln_score; // where the normalized zero alignment score occurs
negative_infinity_mm = __vsw16_mm_set1_epi16(query->min_aln_score); // the minimum possible value
positive_infinity_mm = __vsw16_mm_set1_epi16(query->max_aln_score); // the minimum possible value
score_thr += zero; // for the scoring threshold
// these are not normalized
pen_gapoe = __vsw16_mm_set1_epi16(opt->pen_gapo + opt->pen_gape); // gap open penalty
pen_gape = __vsw16_mm_set1_epi16(opt->pen_gape); // gap extend penalty
zero_mm = __vsw16_mm_set1_epi16(zero); // where the normalized zero alignment score occurs
zero_start_mm = __vsw16_mm_set1_epi16(zero); // where the normalized zero alignment score occurs
gmax = vsw16_min_value;
best = vsw16_min_value;
if(NULL != n_best) (*n_best) = 0;
reduce_mm = __vsw16_mm_set1_epi16(vsw16_mid_value);
// vectors
H0 = query->H0;
H1 = query->H1;
E = query->E;
slen = query->slen;
if(NULL != overflow) *overflow = 0;
#ifdef VSW_DEBUG
fprintf(stderr, "qlen=%d tlen=%d\n", query->qlen, tlen);
fprintf(stderr, "query_start_clip=%d query_end_clip=%d\n",
query_start_clip, query_end_clip);
#endif
// select query end only
// check stripe #: __vsw16_query_index_to_stripe_number(query->qlen, slen)
// check byte # __vsw16_query_index_to_byte_number(query->qlen, slen)
if(0 == query_start_clip) {
__m128i f;
// Set start
for(j = 0; j < slen; j++) {
// initialize E to negative infinity
__vsw_mm_store_si128(E + j, negative_infinity_mm); // E(0,j)
}
// NB: setting the start == 0 will be done later
// set the leading insertions
f = __vsw16_mm_set1_epi16(query->min_aln_score);
f = __vsw16_mm_insert_epi16(f, zero, 0);
for(j = 0; j < vsw16_values_per_128_bits; ++j) {
f = __vsw16_mm_insert(f , -opt->pen_gapo + -opt->pen_gape + (-opt->pen_gape * slen * j) + zero, j);
}
for(j = 0; j < slen; j++) {
f = __vsw16_mm_subs_epi16(f, pen_gape); // f=F(i,j)-pen_gape
f = __vsw16_mm_max_epi16(f, negative_infinity_mm); // bound with -inf
__vsw_mm_store_si128(H0 + ((slen + j - 1) % slen), f); // H(0,j)
}
}
else {
// Initialize all zeros
for(i = 0; i < slen; ++i) {
__vsw_mm_store_si128(E + i, zero_mm);
__vsw_mm_store_si128(H0 + i, zero_mm);
}
}
// the core loop
for(i = 0, sum = 0; i < tlen; i++) { // for each base in the target
__m128i e, h, f, g, max, min, *S;
max = __vsw16_mm_set1_epi16(query->min_aln_score); // max is negative infinity
min = __vsw16_mm_set1_epi16(query->max_aln_score); // min is positive infinity
S = query->query_profile + target[i] * slen; // s is the 1st score vector
// load H(i-1,-1)
h = __vsw_mm_load_si128(H0 + slen - 1); // the last stripe, which holds the j-1
if(UNLIKELY(0 < i)) { // only if we have previous results
h = __vsw_mm_slli_si128(h, vsw16_shift_bytes); // shift left since x64 is little endian
}
h = __vsw16_mm_insert_epi16(h, zero, 0);
// e does not need to be set
// set F to -inf
f = __vsw16_mm_set1_epi16(query->min_aln_score);
// leading insertions
g = __vsw16_mm_set1_epi16(query->min_aln_score);
if(0 == query_start_clip) {
g = __vsw16_mm_set1_epi16(query->min_aln_score);
g = __vsw16_mm_insert_epi16(g, -opt->pen_gapo + opt->pen_gape + zero, 0);
for(j = 1; LIKELY(j < vsw16_values_per_128_bits); j++) {
//.........这里部分代码省略.........
示例11: realpathat2
char *
realpathat2(int dirfd, char *dirfdpath, const char *name, char *resolved,
struct stat *st)
{
char *rpath, *dest, extra_buf[PATH_MAX];
const char *start, *end, *rpath_limit;
int num_links = 0;
ptrdiff_t dirfdlen;
char *pathat;
if (UNLIKELY(name == NULL)) {
/* As per Single Unix Specification V2 we must return an error if
either parameter is a null pointer. We extend this to allow
the RESOLVED parameter to be NULL in case the we are expected to
allocate the room for the return value. */
errno = EINVAL;
return NULL;
}
/* If any of the additional parameters are null, or if the name to
resolve the real path is an absolute path, use the standard
realpath() routine. */
if (UNLIKELY(dirfd < 0 || dirfdpath == NULL || name[0] == '/'))
return realpath(name, resolved);
if (name[0] == '\0') {
if (UNLIKELY(fstat(dirfd, st) < 0))
return NULL;
if (LIKELY(!resolved))
return strdup(dirfdpath);
return strcpy(resolved, dirfdpath);
}
if (LIKELY(!resolved)) {
rpath = malloc(PATH_MAX);
if (UNLIKELY(!rpath))
return NULL;
} else
rpath = resolved;
rpath_limit = rpath + PATH_MAX;
strcpy(rpath, dirfdpath);
dest = rawmemchr(rpath, '\0');
dirfdlen = dest - rpath;
for (start = end = name; *start; start = end) {
int n;
/* Skip sequence of multiple path-separators. */
while (*start == '/')
++start;
/* Find end of path component. */
for (end = start; *end && *end != '/'; ++end)
/* Nothing. */ ;
if (end - start == 0)
break;
else if (end - start == 1 && start[0] == '.')
/* nothing */ ;
else if (end - start == 2 && start[0] == '.' && start[1] == '.') {
/* Back up to previous component, ignore if at root already. */
if (dest > rpath + 1)
while ((--dest)[-1] != '/');
} else {
size_t new_size;
if (dest[-1] != '/')
*dest++ = '/';
if (dest + (end - start) >= rpath_limit) {
ptrdiff_t dest_offset = dest - rpath;
char *new_rpath;
if (UNLIKELY(resolved != NULL)) {
errno = ENAMETOOLONG;
if (dest > rpath + 1)
dest--;
*dest = '\0';
goto error;
}
new_size = (size_t)(rpath_limit - rpath);
if (end - start + 1 > PATH_MAX)
new_size += (size_t)(end - start + 1);
else
new_size += PATH_MAX;
new_rpath = (char *) realloc(rpath, new_size);
if (UNLIKELY(new_rpath == NULL))
goto error;
rpath = new_rpath;
rpath_limit = rpath + new_size;
dest = rpath + dest_offset;
}
dest = mempmove(dest, start, (size_t)(end - start));
*dest = '\0';
if (LIKELY(!strncmp(rpath, dirfdpath, (size_t)dirfdlen))) {
//.........这里部分代码省略.........
示例12: setNull
//.........这里部分代码省略.........
cls = Unit::getClass(clsName.get(), /* autoload */ false);
if (!cls) {
cls = tryAlternateCollectionClass(clsName.get());
}
if (!cls) {
cls = Unit::loadClass(clsName.get()); // with autoloading
}
} else {
cls = Unit::loadClass(clsName.get()); // with autoloading
}
Object obj;
if (RuntimeOption::UnserializationWhitelistCheck &&
(type == 'O') &&
!uns->isWhitelistedClass(clsName)) {
const char* err_msg =
"The object being unserialized with class name '%s' "
"is not in the given whitelist. "
"See http://fburl.com/SafeSerializable for more detail";
if (RuntimeOption::UnserializationWhitelistCheckWarningOnly) {
raise_warning(err_msg, clsName.c_str());
} else {
raise_error(err_msg, clsName.c_str());
}
}
if (cls) {
// Only unserialize CPP extension types which can actually
// support it. Otherwise, we risk creating a CPP object
// without having it initialized completely.
if (cls->instanceCtor() && !cls->isCppSerializable()) {
assert(obj.isNull());
} else {
obj = ObjectData::newInstance(cls);
if (UNLIKELY(cls == c_Pair::classof() && size != 2)) {
throw Exception("Pair objects must have exactly 2 elements");
}
}
} else {
obj = ObjectData::newInstance(
SystemLib::s___PHP_Incomplete_ClassClass);
obj->o_set(s_PHP_Incomplete_Class_Name, clsName);
}
operator=(obj);
if (size > 0) {
// check stack depth to avoid overflow
check_native_recursion();
if (type == 'O') {
// Collections are not allowed
if (obj->isCollection()) {
throw Exception("%s does not support the 'O' serialization "
"format", clsName.data());
}
Variant serializedNativeData = init_null();
bool hasSerializedNativeData = false;
/*
Count backwards so that i is the number of properties
remaining (to be used as an estimate for the total number
of dynamic properties when we see the first dynamic prop).
see getVariantPtr
*/
for (int64_t i = size; i--; ) {
Variant v;
示例13: lock
status_t AudioRecord::obtainBuffer(Buffer* audioBuffer, int32_t waitCount)
{
AutoMutex lock(mLock);
int active;
status_t result = NO_ERROR;
audio_track_cblk_t* cblk = mCblk;
uint32_t framesReq = audioBuffer->frameCount;
uint32_t waitTimeMs = (waitCount < 0) ? cblk->bufferTimeoutMs : WAIT_PERIOD_MS;
audioBuffer->frameCount = 0;
audioBuffer->size = 0;
uint32_t framesReady = cblk->framesReady();
if (framesReady == 0) {
cblk->lock.lock();
goto start_loop_here;
while (framesReady == 0) {
active = mActive;
if (UNLIKELY(!active)) {
cblk->lock.unlock();
return NO_MORE_BUFFERS;
}
if (UNLIKELY(!waitCount)) {
cblk->lock.unlock();
return WOULD_BLOCK;
}
if (!(cblk->flags & CBLK_INVALID_MSK)) {
mLock.unlock();
result = cblk->cv.waitRelative(cblk->lock, milliseconds(waitTimeMs));
cblk->lock.unlock();
mLock.lock();
if (mActive == 0) {
return status_t(STOPPED);
}
cblk->lock.lock();
}
if (cblk->flags & CBLK_INVALID_MSK) {
goto create_new_record;
}
if (__builtin_expect(result!=NO_ERROR, false)) {
cblk->waitTimeMs += waitTimeMs;
if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {
LOGW( "obtainBuffer timed out (is the CPU pegged?) "
"user=%08x, server=%08x", cblk->user, cblk->server);
cblk->lock.unlock();
result = mAudioRecord->start();
cblk->lock.lock();
if (result == DEAD_OBJECT) {
android_atomic_or(CBLK_INVALID_ON, &cblk->flags);
create_new_record:
result = AudioRecord::restoreRecord_l(cblk);
}
if (result != NO_ERROR) {
LOGW("obtainBuffer create Track error %d", result);
cblk->lock.unlock();
return result;
}
cblk->waitTimeMs = 0;
}
if (--waitCount == 0) {
cblk->lock.unlock();
return TIMED_OUT;
}
}
// read the server count again
start_loop_here:
framesReady = cblk->framesReady();
}
cblk->lock.unlock();
}
cblk->waitTimeMs = 0;
if (framesReq > framesReady) {
framesReq = framesReady;
}
uint32_t u = cblk->user;
uint32_t bufferEnd = cblk->userBase + cblk->frameCount;
if (u + framesReq > bufferEnd) {
framesReq = bufferEnd - u;
}
audioBuffer->flags = 0;
audioBuffer->channelCount= mChannelCount;
audioBuffer->format = mFormat;
audioBuffer->frameCount = framesReq;
audioBuffer->size = framesReq*cblk->frameSize;
audioBuffer->raw = (int8_t*)cblk->buffer(u);
active = mActive;
return active ? status_t(NO_ERROR) : status_t(STOPPED);
}
示例14: recalc_face_normals_find_index
/**
* \return a face index in \a faces and set \a r_is_flip if the face is flipped away from the center.
*/
static int recalc_face_normals_find_index(BMesh *bm, BMFace **faces, const int faces_len, bool *r_is_flip)
{
const float eps = FLT_EPSILON;
float cent_area_accum = 0.0f;
float cent[3];
const float cent_fac = 1.0f / (float)faces_len;
bool is_flip = false;
int f_start_index;
int i;
/* Search for the best loop. Members are compared in-order defined here. */
struct {
/* Squared distance from the center to the loops vertex 'l->v'.
* The normalized direction between the center and this vertex is also used for the dot-products below. */
float dist_sq;
/* Signed dot product using the normalized edge vector,
* (best of 'l->prev->v' or 'l->next->v'). */
float edge_dot;
/* Unsigned dot product using the loop-normal
* (sign is used to check if we need to flip) */
float loop_dot;
} best, test;
UNUSED_VARS_NDEBUG(bm);
zero_v3(cent);
/* first calculate the center */
for (i = 0; i < faces_len; i++) {
float f_cent[3];
const float f_area = BM_face_calc_area(faces[i]);
BM_face_calc_center_mean_weighted(faces[i], f_cent);
madd_v3_v3fl(cent, f_cent, cent_fac * f_area);
cent_area_accum += f_area;
BLI_assert(BMO_face_flag_test(bm, faces[i], FACE_TEMP) == 0);
BLI_assert(BM_face_is_normal_valid(faces[i]));
}
if (cent_area_accum != 0.0f) {
mul_v3_fl(cent, 1.0f / cent_area_accum);
}
/* Distances must start above zero,
* or we can't do meaningful calculations based on the direction to the center */
best.dist_sq = eps;
best.edge_dot = best.loop_dot = -FLT_MAX;
/* used in degenerate cases only */
f_start_index = 0;
/**
* Find the outer-most vertex, comparing distance to the center,
* then the outer-most loop attached to that vertex.
*
* Important this is correctly detected,
* where casting a ray from the center wont hit any loops past this one.
* Otherwise the result may be incorrect.
*/
for (i = 0; i < faces_len; i++) {
BMLoop *l_iter, *l_first;
l_iter = l_first = BM_FACE_FIRST_LOOP(faces[i]);
do {
bool is_best_dist_sq;
float dir[3];
sub_v3_v3v3(dir, l_iter->v->co, cent);
test.dist_sq = len_squared_v3(dir);
is_best_dist_sq = (test.dist_sq > best.dist_sq);
if (is_best_dist_sq || (test.dist_sq == best.dist_sq)) {
float edge_dir_pair[2][3];
mul_v3_fl(dir, 1.0f / sqrtf(test.dist_sq));
sub_v3_v3v3(edge_dir_pair[0], l_iter->next->v->co, l_iter->v->co);
sub_v3_v3v3(edge_dir_pair[1], l_iter->prev->v->co, l_iter->v->co);
if ((normalize_v3(edge_dir_pair[0]) > eps) &&
(normalize_v3(edge_dir_pair[1]) > eps))
{
bool is_best_edge_dot;
test.edge_dot = max_ff(dot_v3v3(dir, edge_dir_pair[0]),
dot_v3v3(dir, edge_dir_pair[1]));
is_best_edge_dot = (test.edge_dot > best.edge_dot);
if (is_best_dist_sq || is_best_edge_dot || (test.edge_dot == best.edge_dot)) {
float loop_dir[3];
cross_v3_v3v3(loop_dir, edge_dir_pair[0], edge_dir_pair[1]);
if (normalize_v3(loop_dir) > eps) {
float loop_dir_dot;
/* Highly unlikely the furthest loop is also the concave part of an ngon,
* but it can be contrived with _very_ non-planar faces - so better check. */
if (UNLIKELY(dot_v3v3(loop_dir, l_iter->f->no) < 0.0f)) {
negate_v3(loop_dir);
}
loop_dir_dot = dot_v3v3(dir, loop_dir);
test.loop_dot = fabsf(loop_dir_dot);
if (is_best_dist_sq || is_best_edge_dot || (test.loop_dot > best.loop_dot)) {
//.........这里部分代码省略.........
示例15: BLI_kdtree_find_nearest
/**
* Find nearest returns index, and -1 if no node is found.
*/
int BLI_kdtree_find_nearest(
const KDTree *tree, const float co[3],
KDTreeNearest *r_nearest)
{
const KDTreeNode *nodes = tree->nodes;
const KDTreeNode *root, *min_node;
uint *stack, defaultstack[KD_STACK_INIT];
float min_dist, cur_dist;
uint totstack, cur = 0;
#ifdef DEBUG
BLI_assert(tree->is_balanced == true);
#endif
if (UNLIKELY(tree->root == KD_NODE_UNSET))
return -1;
stack = defaultstack;
totstack = KD_STACK_INIT;
root = &nodes[tree->root];
min_node = root;
min_dist = len_squared_v3v3(root->co, co);
if (co[root->d] < root->co[root->d]) {
if (root->right != KD_NODE_UNSET)
stack[cur++] = root->right;
if (root->left != KD_NODE_UNSET)
stack[cur++] = root->left;
}
else {
if (root->left != KD_NODE_UNSET)
stack[cur++] = root->left;
if (root->right != KD_NODE_UNSET)
stack[cur++] = root->right;
}
while (cur--) {
const KDTreeNode *node = &nodes[stack[cur]];
cur_dist = node->co[node->d] - co[node->d];
if (cur_dist < 0.0f) {
cur_dist = -cur_dist * cur_dist;
if (-cur_dist < min_dist) {
cur_dist = len_squared_v3v3(node->co, co);
if (cur_dist < min_dist) {
min_dist = cur_dist;
min_node = node;
}
if (node->left != KD_NODE_UNSET)
stack[cur++] = node->left;
}
if (node->right != KD_NODE_UNSET)
stack[cur++] = node->right;
}
else {
cur_dist = cur_dist * cur_dist;
if (cur_dist < min_dist) {
cur_dist = len_squared_v3v3(node->co, co);
if (cur_dist < min_dist) {
min_dist = cur_dist;
min_node = node;
}
if (node->right != KD_NODE_UNSET)
stack[cur++] = node->right;
}
if (node->left != KD_NODE_UNSET)
stack[cur++] = node->left;
}
if (UNLIKELY(cur + 3 > totstack)) {
stack = realloc_nodes(stack, &totstack, defaultstack != stack);
}
}
if (r_nearest) {
r_nearest->index = min_node->index;
r_nearest->dist = sqrtf(min_dist);
copy_v3_v3(r_nearest->co, min_node->co);
}
if (stack != defaultstack)
MEM_freeN(stack);
return min_node->index;
}