本文整理汇总了C++中mozilla::Abs方法的典型用法代码示例。如果您正苦于以下问题:C++ mozilla::Abs方法的具体用法?C++ mozilla::Abs怎么用?C++ mozilla::Abs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozilla
的用法示例。
在下文中一共展示了mozilla::Abs方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lowerUMod
bool
LIRGeneratorX86Shared::lowerModI(MMod *mod)
{
if (mod->isUnsigned())
return lowerUMod(mod);
if (mod->rhs()->isConstant()) {
int32_t rhs = mod->rhs()->toConstant()->value().toInt32();
int32_t shift = FloorLog2(Abs(rhs));
if (rhs != 0 && uint32_t(1) << shift == Abs(rhs)) {
LModPowTwoI *lir = new(alloc()) LModPowTwoI(useRegisterAtStart(mod->lhs()), shift);
if (mod->fallible() && !assignSnapshot(lir, Bailout_DoubleOutput))
return false;
return defineReuseInput(lir, mod, 0);
} else if (rhs != 0 &&
gen->optimizationInfo().registerAllocator() != RegisterAllocator_LSRA)
{
LDivOrModConstantI *lir;
lir = new(alloc()) LDivOrModConstantI(useRegister(mod->lhs()), rhs, tempFixed(edx));
if (mod->fallible() && !assignSnapshot(lir, Bailout_DoubleOutput))
return false;
return defineFixed(lir, mod, LAllocation(AnyRegister(eax)));
}
}
LModI *lir = new(alloc()) LModI(useRegister(mod->lhs()),
useRegister(mod->rhs()),
tempFixed(eax));
if (mod->fallible() && !assignSnapshot(lir, Bailout_DoubleOutput))
return false;
return defineFixed(lir, mod, LAllocation(AnyRegister(edx)));
}
示例2: lowerUMod
void
LIRGeneratorX86Shared::lowerModI(MMod* mod)
{
if (mod->isUnsigned()) {
lowerUMod(mod);
return;
}
if (mod->rhs()->isConstant()) {
int32_t rhs = mod->rhs()->toConstant()->toInt32();
int32_t shift = FloorLog2(Abs(rhs));
if (rhs != 0 && uint32_t(1) << shift == Abs(rhs)) {
LModPowTwoI* lir = new(alloc()) LModPowTwoI(useRegisterAtStart(mod->lhs()), shift);
if (mod->fallible())
assignSnapshot(lir, Bailout_DoubleOutput);
defineReuseInput(lir, mod, 0);
return;
}
if (rhs != 0) {
LDivOrModConstantI* lir;
lir = new(alloc()) LDivOrModConstantI(useRegister(mod->lhs()), rhs, tempFixed(edx));
if (mod->fallible())
assignSnapshot(lir, Bailout_DoubleOutput);
defineFixed(lir, mod, LAllocation(AnyRegister(eax)));
return;
}
}
LModI* lir = new(alloc()) LModI(useRegister(mod->lhs()),
useRegister(mod->rhs()),
tempFixed(eax));
if (mod->fallible())
assignSnapshot(lir, Bailout_DoubleOutput);
defineFixed(lir, mod, LAllocation(AnyRegister(edx)));
}
示例3: lowerUDiv
void
LIRGeneratorX86Shared::lowerDivI(MDiv *div)
{
if (div->isUnsigned()) {
lowerUDiv(div);
return;
}
// Division instructions are slow. Division by constant denominators can be
// rewritten to use other instructions.
if (div->rhs()->isConstant()) {
int32_t rhs = div->rhs()->toConstant()->value().toInt32();
// Division by powers of two can be done by shifting, and division by
// other numbers can be done by a reciprocal multiplication technique.
int32_t shift = FloorLog2(Abs(rhs));
if (rhs != 0 && uint32_t(1) << shift == Abs(rhs)) {
LAllocation lhs = useRegisterAtStart(div->lhs());
LDivPowTwoI *lir;
if (!div->canBeNegativeDividend()) {
// Numerator is unsigned, so does not need adjusting.
lir = new(alloc()) LDivPowTwoI(lhs, lhs, shift, rhs < 0);
} else {
// Numerator is signed, and needs adjusting, and an extra
// lhs copy register is needed.
lir = new(alloc()) LDivPowTwoI(lhs, useRegister(div->lhs()), shift, rhs < 0);
}
if (div->fallible())
assignSnapshot(lir, Bailout_DoubleOutput);
defineReuseInput(lir, div, 0);
return;
}
if (rhs != 0 &&
gen->optimizationInfo().registerAllocator() != RegisterAllocator_LSRA)
{
LDivOrModConstantI *lir;
lir = new(alloc()) LDivOrModConstantI(useRegister(div->lhs()), rhs, tempFixed(eax));
if (div->fallible())
assignSnapshot(lir, Bailout_DoubleOutput);
defineFixed(lir, div, LAllocation(AnyRegister(edx)));
return;
}
}
LDivI *lir = new(alloc()) LDivI(useRegister(div->lhs()), useRegister(div->rhs()),
tempFixed(edx));
if (div->fallible())
assignSnapshot(lir, Bailout_DoubleOutput);
defineFixed(lir, div, LAllocation(AnyRegister(eax)));
}
示例4: Abs
bool
js::math_abs_handle(JSContext *cx, js::HandleValue v, js::MutableHandleValue r)
{
double x;
if (!ToNumber(cx, v, &x))
return false;
double z = Abs(x);
r.setNumber(z);
return true;
}
示例5: Abs
JSBool
js_math_abs(JSContext *cx, unsigned argc, Value *vp)
{
double x, z;
if (argc == 0) {
vp->setDouble(js_NaN);
return JS_TRUE;
}
if (!ToNumber(cx, vp[2], &x))
return JS_FALSE;
z = Abs(x);
vp->setNumber(z);
return JS_TRUE;
}
示例6: CallArgsFromVp
bool
js_math_abs(JSContext *cx, unsigned argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() == 0) {
args.rval().setNaN();
return true;
}
double x;
if (!ToNumber(cx, args[0], &x))
return false;
double z = Abs(x);
args.rval().setNumber(z);
return true;
}
示例7: if
//.........这里部分代码省略.........
do_QueryInterface(mStreams[i]);
int64_t pos;
rv = stream->Tell(&pos);
NS_ENSURE_SUCCESS(rv, rv);
int64_t seek = XPCOM_MIN(pos, remaining);
rv = stream->Seek(NS_SEEK_CUR, -seek);
NS_ENSURE_SUCCESS(rv, rv);
mCurrentStream = i;
mStartedReadingCurrent = seek != -pos;
remaining -= seek;
}
return NS_OK;
}
if (aWhence == NS_SEEK_CUR) {
NS_ASSERTION(aOffset == 0, "Should have handled all non-zero values");
return NS_OK;
}
if (aWhence == NS_SEEK_END) {
if (aOffset > 0) {
return NS_ERROR_INVALID_ARG;
}
int64_t remaining = aOffset;
for (uint32_t i = mStreams.Length() - 1; i != (uint32_t)-1; --i) {
nsCOMPtr<nsISeekableStream> stream =
do_QueryInterface(mStreams[i]);
// See if all remaining streams should be seeked to end
if (remaining == 0) {
if (i >= oldCurrentStream) {
rv = stream->Seek(NS_SEEK_END, 0);
NS_ENSURE_SUCCESS(rv, rv);
}
else {
break;
}
}
// Get position in current stream
int64_t streamPos;
if (i < oldCurrentStream) {
streamPos = 0;
} else {
uint64_t avail;
rv = mStreams[i]->Available(&avail);
NS_ENSURE_SUCCESS(rv, rv);
streamPos = avail;
}
// See if we have enough data in the current stream.
if (Abs(remaining) < streamPos) {
rv = stream->Seek(NS_SEEK_END, remaining);
NS_ENSURE_SUCCESS(rv, rv);
mCurrentStream = i;
mStartedReadingCurrent = true;
remaining = 0;
} else if (Abs(remaining) > streamPos) {
if (i > oldCurrentStream ||
(i == oldCurrentStream && !oldStartedReadingCurrent)) {
// We're already at start so no need to seek this stream
remaining += streamPos;
} else {
int64_t avail;
rv = stream->Tell(&avail);
NS_ENSURE_SUCCESS(rv, rv);
int64_t newPos = streamPos + XPCOM_MIN(avail, Abs(remaining));
rv = stream->Seek(NS_SEEK_END, -newPos);
NS_ENSURE_SUCCESS(rv, rv);
mCurrentStream = i;
mStartedReadingCurrent = true;
remaining += newPos;
}
}
else {
NS_ASSERTION(remaining == streamPos, "Huh?");
remaining = 0;
}
}
return NS_OK;
}
// other Seeks not implemented yet
return NS_ERROR_NOT_IMPLEMENTED;
}