text stringlengths 1 1.05M |
|---|
#include "hv.h"
#include "hmain.h"
#include "iniparser.h"
typedef struct conf_ctx_s {
IniParser* parser;
int loglevel;
int worker_processes;
int worker_threads;
int port;
} conf_ctx_t;
conf_ctx_t g_conf_ctx;
inline void conf_ctx_init(conf_ctx_t* ctx) {
ctx->parser = new IniParser;
ctx->loglevel = LOG_LEVEL_DEBUG;
ctx->worker_processes = 0;
ctx->worker_threads = 0;
ctx->port = 0;
}
static void print_version();
static void print_help();
static int parse_confile(const char* confile);
static void worker_fn(void* userdata);
// short options
static const char options[] = "hvc:ts:dp:";
// long options
static const option_t long_options[] = {
{'h', "help", NO_ARGUMENT},
{'v', "version", NO_ARGUMENT},
{'c', "confile", REQUIRED_ARGUMENT},
{'t', "test", NO_ARGUMENT},
{'s', "signal", REQUIRED_ARGUMENT},
{'d', "daemon", NO_ARGUMENT},
{'p', "port", REQUIRED_ARGUMENT}
};
static const char detail_options[] = R"(
-h|--help Print this information
-v|--version Print version
-c|--confile <confile> Set configure file, default etc/{program}.conf
-t|--test Test configure file and exit
-s|--signal <signal> Send <signal> to process,
<signal>=[start,stop,restart,status,reload]
-d|--daemon Daemonize
-p|--port <port> Set listen port
)";
void print_version() {
printf("%s version %s\n", g_main_ctx.program_name, hv_compile_version());
}
void print_help() {
printf("Usage: %s [%s]\n", g_main_ctx.program_name, options);
printf("Options:\n%s\n", detail_options);
}
int parse_confile(const char* confile) {
int ret = g_conf_ctx.parser->LoadFromFile(confile);
if (ret != 0) {
printf("Load confile [%s] failed: %d\n", confile, ret);
exit(-40);
}
// logfile
string str = g_conf_ctx.parser->GetValue("logfile");
if (!str.empty()) {
strncpy(g_main_ctx.logfile, str.c_str(), sizeof(g_main_ctx.logfile));
}
hlog_set_file(g_main_ctx.logfile);
// loglevel
str = g_conf_ctx.parser->GetValue("loglevel");
if (!str.empty()) {
hlog_set_level_by_str(str.c_str());
}
// log_filesize
str = g_conf_ctx.parser->GetValue("log_filesize");
if (!str.empty()) {
hlog_set_max_filesize_by_str(str.c_str());
}
// log_remain_days
str = g_conf_ctx.parser->GetValue("log_remain_days");
if (!str.empty()) {
hlog_set_remain_days(atoi(str.c_str()));
}
// log_fsync
str = g_conf_ctx.parser->GetValue("log_fsync");
if (!str.empty()) {
logger_enable_fsync(hlog, getboolean(str.c_str()));
}
// first log here
hlogi("%s version: %s", g_main_ctx.program_name, hv_compile_version());
hlog_fsync();
// worker_processes
int worker_processes = 0;
str = g_conf_ctx.parser->GetValue("worker_processes");
if (str.size() != 0) {
if (strcmp(str.c_str(), "auto") == 0) {
worker_processes = get_ncpu();
hlogd("worker_processes=ncpu=%d", worker_processes);
}
else {
worker_processes = atoi(str.c_str());
}
}
g_conf_ctx.worker_processes = LIMIT(0, worker_processes, MAXNUM_WORKER_PROCESSES);
// worker_threads
int worker_threads = g_conf_ctx.parser->Get<int>("worker_threads");
g_conf_ctx.worker_threads = LIMIT(0, worker_threads, 16);
// port
int port = 0;
const char* szPort = get_arg("p");
if (szPort) {
port = atoi(szPort);
}
if (port == 0) {
port = g_conf_ctx.parser->Get<int>("port");
}
if (port == 0) {
printf("Please config listen port!\n");
exit(-10);
}
g_conf_ctx.port = port;
hlogi("parse_confile('%s') OK", confile);
return 0;
}
static void on_reload(void* userdata) {
hlogi("reload confile [%s]", g_main_ctx.confile);
parse_confile(g_main_ctx.confile);
}
int main(int argc, char** argv) {
// g_main_ctx
main_ctx_init(argc, argv);
if (argc == 1) {
print_help();
exit(10);
}
// int ret = parse_opt(argc, argv, options);
int ret = parse_opt_long(argc, argv, long_options, ARRAY_SIZE(long_options));
if (ret != 0) {
print_help();
exit(ret);
}
/*
printf("---------------arg------------------------------\n");
printf("%s\n", g_main_ctx.cmdline);
for (auto& pair : g_main_ctx.arg_kv) {
printf("%s=%s\n", pair.first.c_str(), pair.second.c_str());
}
for (auto& item : g_main_ctx.arg_list) {
printf("%s\n", item.c_str());
}
printf("================================================\n");
printf("---------------env------------------------------\n");
for (auto& pair : g_main_ctx.env_kv) {
printf("%s=%s\n", pair.first.c_str(), pair.second.c_str());
}
printf("================================================\n");
*/
// help
if (get_arg("h")) {
print_help();
exit(0);
}
// version
if (get_arg("v")) {
print_version();
exit(0);
}
// g_conf_ctx
conf_ctx_init(&g_conf_ctx);
const char* confile = get_arg("c");
if (confile) {
strncpy(g_main_ctx.confile, confile, sizeof(g_main_ctx.confile));
}
parse_confile(g_main_ctx.confile);
// test
if (get_arg("t")) {
printf("Test confile [%s] OK!\n", g_main_ctx.confile);
exit(0);
}
// signal
signal_init(on_reload);
const char* signal = get_arg("s");
if (signal) {
signal_handle(signal);
}
#ifdef OS_UNIX
// daemon
if (get_arg("d")) {
// nochdir, noclose
int ret = daemon(1, 1);
if (ret != 0) {
printf("daemon error: %d\n", ret);
exit(-10);
}
}
#endif
// pidfile
create_pidfile();
master_workers_run(worker_fn, (void*)(intptr_t)100L, g_conf_ctx.worker_processes, g_conf_ctx.worker_threads);
return 0;
}
void worker_fn(void* userdata) {
long num = (long)(intptr_t)(userdata);
while (1) {
printf("num=%ld pid=%ld tid=%ld\n", num, hv_getpid(), hv_gettid());
hv_delay(60000);
}
}
|
copyright zengfr site:http://github.com/zengfr/romhack
03D434 clr.b ($a9,A6)
03D438 clr.b ($a0,A6)
0408CC move.b #$1, ($94,A6) [boss+A9]
copyright zengfr site:http://github.com/zengfr/romhack
|
; A210375: Number of 2 X 2 matrices with all terms in {0,1,...,n} and (sum of terms) = n + 3.
; 0,1,16,44,80,125,180,246,324,415,520,640,776,929,1100,1290,1500,1731,1984,2260,2560,2885,3236,3614,4020,4455,4920,5416,5944,6505,7100,7730,8396,9099,9840,10620,11440,12301,13204,14150,15140,16175,17256,18384,19560
mov $12,$0
mov $14,$0
lpb $14
clr $0,12
mov $0,$12
sub $14,1
sub $0,$14
mov $9,$0
mov $11,$0
lpb $11
mov $0,$9
sub $11,1
sub $0,$11
mov $1,$0
mov $2,4
lpb $0
mul $1,2
trn $2,$0
add $0,1
mul $2,$1
mov $6,2
add $6,$0
mov $0,1
add $6,$2
lpe
add $6,3
add $0,$6
mov $1,$0
sub $1,3
add $10,$1
lpe
add $13,$10
lpe
mov $1,$13
|
; A210958: Decimal expansion of 1 - (Pi/4).
; Submitted by Jon Maiga
; 2,1,4,6,0,1,8,3,6,6,0,2,5,5,1,6,9,0,3,8,4,3,3,9,1,5,4,1,8,0,1,2,4,2,7,8,9,5,0,7,0,7,6,5,0,1,5,6,2,2,3,5,4,4,7,5,6,2,6,3,8,5,1,9,2,3,0,4,5,8,9,8,4,2,8,4,4,7,7,5,0,3,4,2,9,9,1
add $0,1
mov $2,1
mov $3,$0
mul $3,5
lpb $3
mul $1,$3
mov $5,$3
mul $5,2
add $5,3
mul $2,$5
add $1,$2
div $1,$0
div $2,$0
sub $3,1
lpe
div $1,6
mov $4,10
pow $4,$0
div $2,$4
div $1,$2
mov $0,$1
mod $0,10
|
cpx #0
beq !e+
!:
asl {m1}
rol {m1}+1
dex
bne !-
!e:
|
; A165678: Sixth right hand column of triangle A165674
; 1764,8028,24552,60216,127860,245004,434568,725592,1153956,1763100,2604744,3739608,5238132,7181196,9660840,12780984,16658148,21422172,27216936,34201080,42548724,52450188,64112712,77761176,93638820
lpb $0,1
mov $2,$0
cal $2,165677 ; Fifth right hand column of triangle A165674
sub $0,1
add $1,$2
lpe
div $1,2
mul $1,12
add $1,1764
|
.global s_prepare_buffers
s_prepare_buffers:
push %r14
push %r15
push %r8
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x16e0, %rsi
lea addresses_WT_ht+0x3e3c, %rdi
sub %r14, %r14
mov $111, %rcx
rep movsb
nop
nop
nop
and $16819, %r14
lea addresses_D_ht+0x3c40, %r15
and %rdi, %rdi
mov $0x6162636465666768, %r14
movq %r14, %xmm0
movups %xmm0, (%r15)
nop
and %rsi, %rsi
lea addresses_A_ht+0xebe0, %rsi
lea addresses_normal_ht+0xcd41, %rdi
clflush (%rsi)
nop
nop
nop
nop
cmp $59957, %rax
mov $32, %rcx
rep movsl
nop
nop
nop
nop
sub %r15, %r15
lea addresses_UC_ht+0x54e0, %r14
nop
nop
nop
cmp %r8, %r8
mov $0x6162636465666768, %rsi
movq %rsi, %xmm2
vmovups %ymm2, (%r14)
nop
nop
nop
sub %r15, %r15
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r15
pop %r14
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r12
push %rax
push %rbp
push %rdx
push %rsi
// Store
lea addresses_PSE+0xfcc0, %rdx
nop
nop
nop
nop
xor %r10, %r10
movl $0x51525354, (%rdx)
nop
nop
nop
nop
nop
inc %r11
// Faulty Load
lea addresses_WC+0x106e0, %r12
nop
nop
nop
nop
nop
sub $21690, %rbp
movups (%r12), %xmm0
vpextrq $1, %xmm0, %rax
lea oracles, %rbp
and $0xff, %rax
shlq $12, %rax
mov (%rbp,%rax,1), %rax
pop %rsi
pop %rdx
pop %rbp
pop %rax
pop %r12
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_PSE', 'AVXalign': False, 'size': 4}}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'same': False, 'congruent': 10, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 2, 'type': 'addresses_WT_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 5, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 16}}
{'src': {'same': False, 'congruent': 7, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 0, 'type': 'addresses_normal_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 9, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 32}}
{'45': 1809, '00': 20011, '48': 9}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 45 00 00 00 00 00 45 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 45 00 00 00 00 00 00 00 00 00 00 45 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 45 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 45 00 00 45 00 00 00 00 00 45 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 45 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 45 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 45 00 00 45 00 00 45 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 45 00 00 45 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 45 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 45 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 45 00 00 45 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 45 00 00 45 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 45 00 00 45 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 45 00 00 45 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
; Program 8.7
; SSE4 - MASM (32-bit)
; Copyright (c) 2017 Hall & Slonka
.686
.XMM
.MODEL FLAT, C
.STACK 4096
ExitProcess PROTO stdcall,
dwExitCode:DWORD
.data
ALIGN 16
vectorA REAL4 1.2, 3.4, 5.6, 7.8
vectorB REAL4 7.8, 5.6, 3.4, 1.2
.code
_main PROC
movaps xmm0, vectorA ; move aligned packed vectorA to XMM0
roundps xmm1, xmm0, 1 ; round down(1) values in XMM0 and store in XMM1
cvtps2dq xmm2, xmm1 ; convert SPF to int and store in XMM2
movaps xmm3, vectorB ; move aligned packed vectorB to XMM3
roundps xmm4, xmm3, 2 ; round up(2) values in XMM3 and store in XMM4
cvtps2dq xmm5, xmm4 ; convert SPF to int and store in XMM5
pmulld xmm5, xmm2 ; multiply doublewords and store in XMM5
INVOKE ExitProcess, 0
_main ENDP
END
|
[bits 32]
dd VideoInfo.$FILE_END - VideoInfo.$FILE_START
db "OrcaHLL Class", 0
db "VideoInfo", 0
VideoInfo.$FILE_START :
VideoInfo._init:
pop dword [VideoInfo._init.returnVal]
push eax
push ebx
push edx
mov ax, 0x0104
int 0x30
mov ecx, 0x7 ; System Constant
push ecx
mov ax, 0x0001
int 0x30
mov [VideoInfo._init.$local.gcName], ecx
mov ecx, [VideoInfo._init.string_0]
push ecx
mov ax, 0x0100
int 0x30
mov ecx, [VideoInfo._init.$local.gcName]
push ecx
mov ax, 0x0101
int 0x30
mov ecx, 0x8 ; System Constant
push ecx
mov ax, 0x0001
int 0x30
mov [VideoInfo._init.$local.pCount], ecx
mov ecx, [VideoInfo._init.string_1]
push ecx
mov ax, 0x0100
int 0x30
mov ecx, [VideoInfo._init.$local.pCount]
push ecx
mov ax, 0x0102
int 0x30
mov ax, 0x0103
int 0x30
pop edx
pop ebx
pop eax
push dword [VideoInfo._init.returnVal]
ret
;Vars:
VideoInfo._init.string_0 :
dd VideoInfo._init.string_0_data
VideoInfo._init.string_1_data :
db "Active processes: ", 0
VideoInfo._init.string_0_data :
db "Graphics card name: ", 0
VideoInfo._init.string_1 :
dd VideoInfo._init.string_1_data
VideoInfo._init.$local.gcName :
dd 0x0
VideoInfo._init.$local.pCount :
dd 0x0
VideoInfo._init.returnVal:
dd 0x0
VideoInfo.$FILE_END :
|
// Copyright (c) 2014 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <crypto/ripemd160.h>
#include <crypto/common.h>
#include <string.h>
// Internal implementation code.
namespace
{
/// Internal RIPEMD-160 implementation.
namespace ripemd160
{
uint32_t inline f1(uint32_t x, uint32_t y, uint32_t z) { return x ^ y ^ z; }
uint32_t inline f2(uint32_t x, uint32_t y, uint32_t z) { return (x & y) | (~x & z); }
uint32_t inline f3(uint32_t x, uint32_t y, uint32_t z) { return (x | ~y) ^ z; }
uint32_t inline f4(uint32_t x, uint32_t y, uint32_t z) { return (x & z) | (y & ~z); }
uint32_t inline f5(uint32_t x, uint32_t y, uint32_t z) { return x ^ (y | ~z); }
/** Initialize RIPEMD-160 state. */
void inline Initialize(uint32_t* s)
{
s[0] = 0x67452301ul;
s[1] = 0xEFCDAB89ul;
s[2] = 0x98BADCFEul;
s[3] = 0x10325476ul;
s[4] = 0xC3D2E1F0ul;
}
uint32_t inline rol(uint32_t x, int i) { return (x << i) | (x >> (32 - i)); }
void inline Round(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t f, uint32_t x, uint32_t k, int r)
{
a = rol(a + f + x + k, r) + e;
c = rol(c, 10);
}
void inline R11(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t x, int r) { Round(a, b, c, d, e, f1(b, c, d), x, 0, r); }
void inline R21(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t x, int r) { Round(a, b, c, d, e, f2(b, c, d), x, 0x5A827999ul, r); }
void inline R31(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t x, int r) { Round(a, b, c, d, e, f3(b, c, d), x, 0x6ED9EBA1ul, r); }
void inline R41(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t x, int r) { Round(a, b, c, d, e, f4(b, c, d), x, 0x8F1BBCDCul, r); }
void inline R51(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t x, int r) { Round(a, b, c, d, e, f5(b, c, d), x, 0xA953FD4Eul, r); }
void inline R12(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t x, int r) { Round(a, b, c, d, e, f5(b, c, d), x, 0x50A28BE6ul, r); }
void inline R22(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t x, int r) { Round(a, b, c, d, e, f4(b, c, d), x, 0x5C4DD124ul, r); }
void inline R32(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t x, int r) { Round(a, b, c, d, e, f3(b, c, d), x, 0x6D703EF3ul, r); }
void inline R42(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t x, int r) { Round(a, b, c, d, e, f2(b, c, d), x, 0x7A6D76E9ul, r); }
void inline R52(uint32_t& a, uint32_t b, uint32_t& c, uint32_t d, uint32_t e, uint32_t x, int r) { Round(a, b, c, d, e, f1(b, c, d), x, 0, r); }
/** Perform a RIPEMD-160 transformation, processing a 64-byte chunk. */
void Transform(uint32_t* s, const unsigned char* chunk)
{
uint32_t a1 = s[0], b1 = s[1], c1 = s[2], d1 = s[3], e1 = s[4];
uint32_t a2 = a1, b2 = b1, c2 = c1, d2 = d1, e2 = e1;
uint32_t w0 = ReadLE32(chunk + 0), w1 = ReadLE32(chunk + 4), w2 = ReadLE32(chunk + 8), w3 = ReadLE32(chunk + 12);
uint32_t w4 = ReadLE32(chunk + 16), w5 = ReadLE32(chunk + 20), w6 = ReadLE32(chunk + 24), w7 = ReadLE32(chunk + 28);
uint32_t w8 = ReadLE32(chunk + 32), w9 = ReadLE32(chunk + 36), w10 = ReadLE32(chunk + 40), w11 = ReadLE32(chunk + 44);
uint32_t w12 = ReadLE32(chunk + 48), w13 = ReadLE32(chunk + 52), w14 = ReadLE32(chunk + 56), w15 = ReadLE32(chunk + 60);
R11(a1, b1, c1, d1, e1, w0, 11);
R12(a2, b2, c2, d2, e2, w5, 8);
R11(e1, a1, b1, c1, d1, w1, 14);
R12(e2, a2, b2, c2, d2, w14, 9);
R11(d1, e1, a1, b1, c1, w2, 15);
R12(d2, e2, a2, b2, c2, w7, 9);
R11(c1, d1, e1, a1, b1, w3, 12);
R12(c2, d2, e2, a2, b2, w0, 11);
R11(b1, c1, d1, e1, a1, w4, 5);
R12(b2, c2, d2, e2, a2, w9, 13);
R11(a1, b1, c1, d1, e1, w5, 8);
R12(a2, b2, c2, d2, e2, w2, 15);
R11(e1, a1, b1, c1, d1, w6, 7);
R12(e2, a2, b2, c2, d2, w11, 15);
R11(d1, e1, a1, b1, c1, w7, 9);
R12(d2, e2, a2, b2, c2, w4, 5);
R11(c1, d1, e1, a1, b1, w8, 11);
R12(c2, d2, e2, a2, b2, w13, 7);
R11(b1, c1, d1, e1, a1, w9, 13);
R12(b2, c2, d2, e2, a2, w6, 7);
R11(a1, b1, c1, d1, e1, w10, 14);
R12(a2, b2, c2, d2, e2, w15, 8);
R11(e1, a1, b1, c1, d1, w11, 15);
R12(e2, a2, b2, c2, d2, w8, 11);
R11(d1, e1, a1, b1, c1, w12, 6);
R12(d2, e2, a2, b2, c2, w1, 14);
R11(c1, d1, e1, a1, b1, w13, 7);
R12(c2, d2, e2, a2, b2, w10, 14);
R11(b1, c1, d1, e1, a1, w14, 9);
R12(b2, c2, d2, e2, a2, w3, 12);
R11(a1, b1, c1, d1, e1, w15, 8);
R12(a2, b2, c2, d2, e2, w12, 6);
R21(e1, a1, b1, c1, d1, w7, 7);
R22(e2, a2, b2, c2, d2, w6, 9);
R21(d1, e1, a1, b1, c1, w4, 6);
R22(d2, e2, a2, b2, c2, w11, 13);
R21(c1, d1, e1, a1, b1, w13, 8);
R22(c2, d2, e2, a2, b2, w3, 15);
R21(b1, c1, d1, e1, a1, w1, 13);
R22(b2, c2, d2, e2, a2, w7, 7);
R21(a1, b1, c1, d1, e1, w10, 11);
R22(a2, b2, c2, d2, e2, w0, 12);
R21(e1, a1, b1, c1, d1, w6, 9);
R22(e2, a2, b2, c2, d2, w13, 8);
R21(d1, e1, a1, b1, c1, w15, 7);
R22(d2, e2, a2, b2, c2, w5, 9);
R21(c1, d1, e1, a1, b1, w3, 15);
R22(c2, d2, e2, a2, b2, w10, 11);
R21(b1, c1, d1, e1, a1, w12, 7);
R22(b2, c2, d2, e2, a2, w14, 7);
R21(a1, b1, c1, d1, e1, w0, 12);
R22(a2, b2, c2, d2, e2, w15, 7);
R21(e1, a1, b1, c1, d1, w9, 15);
R22(e2, a2, b2, c2, d2, w8, 12);
R21(d1, e1, a1, b1, c1, w5, 9);
R22(d2, e2, a2, b2, c2, w12, 7);
R21(c1, d1, e1, a1, b1, w2, 11);
R22(c2, d2, e2, a2, b2, w4, 6);
R21(b1, c1, d1, e1, a1, w14, 7);
R22(b2, c2, d2, e2, a2, w9, 15);
R21(a1, b1, c1, d1, e1, w11, 13);
R22(a2, b2, c2, d2, e2, w1, 13);
R21(e1, a1, b1, c1, d1, w8, 12);
R22(e2, a2, b2, c2, d2, w2, 11);
R31(d1, e1, a1, b1, c1, w3, 11);
R32(d2, e2, a2, b2, c2, w15, 9);
R31(c1, d1, e1, a1, b1, w10, 13);
R32(c2, d2, e2, a2, b2, w5, 7);
R31(b1, c1, d1, e1, a1, w14, 6);
R32(b2, c2, d2, e2, a2, w1, 15);
R31(a1, b1, c1, d1, e1, w4, 7);
R32(a2, b2, c2, d2, e2, w3, 11);
R31(e1, a1, b1, c1, d1, w9, 14);
R32(e2, a2, b2, c2, d2, w7, 8);
R31(d1, e1, a1, b1, c1, w15, 9);
R32(d2, e2, a2, b2, c2, w14, 6);
R31(c1, d1, e1, a1, b1, w8, 13);
R32(c2, d2, e2, a2, b2, w6, 6);
R31(b1, c1, d1, e1, a1, w1, 15);
R32(b2, c2, d2, e2, a2, w9, 14);
R31(a1, b1, c1, d1, e1, w2, 14);
R32(a2, b2, c2, d2, e2, w11, 12);
R31(e1, a1, b1, c1, d1, w7, 8);
R32(e2, a2, b2, c2, d2, w8, 13);
R31(d1, e1, a1, b1, c1, w0, 13);
R32(d2, e2, a2, b2, c2, w12, 5);
R31(c1, d1, e1, a1, b1, w6, 6);
R32(c2, d2, e2, a2, b2, w2, 14);
R31(b1, c1, d1, e1, a1, w13, 5);
R32(b2, c2, d2, e2, a2, w10, 13);
R31(a1, b1, c1, d1, e1, w11, 12);
R32(a2, b2, c2, d2, e2, w0, 13);
R31(e1, a1, b1, c1, d1, w5, 7);
R32(e2, a2, b2, c2, d2, w4, 7);
R31(d1, e1, a1, b1, c1, w12, 5);
R32(d2, e2, a2, b2, c2, w13, 5);
R41(c1, d1, e1, a1, b1, w1, 11);
R42(c2, d2, e2, a2, b2, w8, 15);
R41(b1, c1, d1, e1, a1, w9, 12);
R42(b2, c2, d2, e2, a2, w6, 5);
R41(a1, b1, c1, d1, e1, w11, 14);
R42(a2, b2, c2, d2, e2, w4, 8);
R41(e1, a1, b1, c1, d1, w10, 15);
R42(e2, a2, b2, c2, d2, w1, 11);
R41(d1, e1, a1, b1, c1, w0, 14);
R42(d2, e2, a2, b2, c2, w3, 14);
R41(c1, d1, e1, a1, b1, w8, 15);
R42(c2, d2, e2, a2, b2, w11, 14);
R41(b1, c1, d1, e1, a1, w12, 9);
R42(b2, c2, d2, e2, a2, w15, 6);
R41(a1, b1, c1, d1, e1, w4, 8);
R42(a2, b2, c2, d2, e2, w0, 14);
R41(e1, a1, b1, c1, d1, w13, 9);
R42(e2, a2, b2, c2, d2, w5, 6);
R41(d1, e1, a1, b1, c1, w3, 14);
R42(d2, e2, a2, b2, c2, w12, 9);
R41(c1, d1, e1, a1, b1, w7, 5);
R42(c2, d2, e2, a2, b2, w2, 12);
R41(b1, c1, d1, e1, a1, w15, 6);
R42(b2, c2, d2, e2, a2, w13, 9);
R41(a1, b1, c1, d1, e1, w14, 8);
R42(a2, b2, c2, d2, e2, w9, 12);
R41(e1, a1, b1, c1, d1, w5, 6);
R42(e2, a2, b2, c2, d2, w7, 5);
R41(d1, e1, a1, b1, c1, w6, 5);
R42(d2, e2, a2, b2, c2, w10, 15);
R41(c1, d1, e1, a1, b1, w2, 12);
R42(c2, d2, e2, a2, b2, w14, 8);
R51(b1, c1, d1, e1, a1, w4, 9);
R52(b2, c2, d2, e2, a2, w12, 8);
R51(a1, b1, c1, d1, e1, w0, 15);
R52(a2, b2, c2, d2, e2, w15, 5);
R51(e1, a1, b1, c1, d1, w5, 5);
R52(e2, a2, b2, c2, d2, w10, 12);
R51(d1, e1, a1, b1, c1, w9, 11);
R52(d2, e2, a2, b2, c2, w4, 9);
R51(c1, d1, e1, a1, b1, w7, 6);
R52(c2, d2, e2, a2, b2, w1, 12);
R51(b1, c1, d1, e1, a1, w12, 8);
R52(b2, c2, d2, e2, a2, w5, 5);
R51(a1, b1, c1, d1, e1, w2, 13);
R52(a2, b2, c2, d2, e2, w8, 14);
R51(e1, a1, b1, c1, d1, w10, 12);
R52(e2, a2, b2, c2, d2, w7, 6);
R51(d1, e1, a1, b1, c1, w14, 5);
R52(d2, e2, a2, b2, c2, w6, 8);
R51(c1, d1, e1, a1, b1, w1, 12);
R52(c2, d2, e2, a2, b2, w2, 13);
R51(b1, c1, d1, e1, a1, w3, 13);
R52(b2, c2, d2, e2, a2, w13, 6);
R51(a1, b1, c1, d1, e1, w8, 14);
R52(a2, b2, c2, d2, e2, w14, 5);
R51(e1, a1, b1, c1, d1, w11, 11);
R52(e2, a2, b2, c2, d2, w0, 15);
R51(d1, e1, a1, b1, c1, w6, 8);
R52(d2, e2, a2, b2, c2, w3, 13);
R51(c1, d1, e1, a1, b1, w15, 5);
R52(c2, d2, e2, a2, b2, w9, 11);
R51(b1, c1, d1, e1, a1, w13, 6);
R52(b2, c2, d2, e2, a2, w11, 11);
uint32_t t = s[0];
s[0] = s[1] + c1 + d2;
s[1] = s[2] + d1 + e2;
s[2] = s[3] + e1 + a2;
s[3] = s[4] + a1 + b2;
s[4] = t + b1 + c2;
}
} // namespace ripemd160
} // namespace
////// RIPEMD160
CRIPEMD160::CRIPEMD160() : bytes(0)
{
ripemd160::Initialize(s);
}
CRIPEMD160& CRIPEMD160::Write(const unsigned char* data, size_t len)
{
const unsigned char* end = data + len;
size_t bufsize = bytes % 64;
if (bufsize && bufsize + len >= 64) {
// Fill the buffer, and process it.
memcpy(buf + bufsize, data, 64 - bufsize);
bytes += 64 - bufsize;
data += 64 - bufsize;
ripemd160::Transform(s, buf);
bufsize = 0;
}
while (end - data >= 64) {
// Process full chunks directly from the source.
ripemd160::Transform(s, data);
bytes += 64;
data += 64;
}
if (end > data) {
// Fill the buffer with what remains.
memcpy(buf + bufsize, data, end - data);
bytes += end - data;
}
return *this;
}
void CRIPEMD160::Finalize(unsigned char hash[OUTPUT_SIZE])
{
static const unsigned char pad[64] = {0x80};
unsigned char sizedesc[8];
WriteLE64(sizedesc, bytes << 3);
Write(pad, 1 + ((119 - (bytes % 64)) % 64));
Write(sizedesc, 8);
WriteLE32(hash, s[0]);
WriteLE32(hash + 4, s[1]);
WriteLE32(hash + 8, s[2]);
WriteLE32(hash + 12, s[3]);
WriteLE32(hash + 16, s[4]);
}
CRIPEMD160& CRIPEMD160::Reset()
{
bytes = 0;
ripemd160::Initialize(s);
return *this;
}
|
;Suma elemente vector in care se evita un salt conditionat (jz...in locul lui a fost pus jnz et1; si jmp final) mai mare de 127 sau -126 bytes
.model small
.data
sum dw ?
tab dw 2,7,15,20
.code
start:
mov ax,@data
mov ds,ax
xor ax,ax
mov cx,4
mov si,ax
test cx,cx
jnz et1
jmp final
et1:
add ax,tab[si]
add si,2 ;inc si inc si
loop et1
mov sum,ax
final:
mov ax,4c00h
int 21h
end start
|
;------------------------------------------------------------------------------
;
; 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:
;
; WriteMm0.Asm
;
; Abstract:
;
; AsmWriteMm0 function
;
; Notes:
;
;------------------------------------------------------------------------------
.code
;------------------------------------------------------------------------------
; VOID
; EFIAPI
; AsmWriteMm0 (
; IN UINT64 Value
; );
;------------------------------------------------------------------------------
AsmWriteMm0 PROC
;
; 64-bit MASM doesn't support MMX instructions, so use opcode here
;
DB 48h, 0fh, 6eh, 0c1h
ret
AsmWriteMm0 ENDP
END
|
; A151542: Generalized pentagonal numbers: a(n) = 12*n + 3*n*(n-1)/2.
; 0,12,27,45,66,90,117,147,180,216,255,297,342,390,441,495,552,612,675,741,810,882,957,1035,1116,1200,1287,1377,1470,1566,1665,1767,1872,1980,2091,2205,2322,2442,2565,2691,2820,2952,3087,3225,3366,3510,3657,3807,3960,4116,4275,4437,4602,4770,4941,5115,5292,5472,5655,5841,6030,6222,6417,6615,6816,7020,7227,7437,7650,7866,8085,8307,8532,8760,8991,9225,9462,9702,9945,10191,10440,10692,10947,11205,11466,11730,11997,12267,12540,12816,13095,13377,13662,13950,14241,14535,14832,15132,15435,15741
mov $1,$0
add $1,7
mul $0,$1
div $0,2
mul $0,3
|
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2018, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "UnitTestPCH.h"
#include <assimp/metadata.h>
using namespace ::Assimp;
class utMetadata: public ::testing::Test {
protected:
aiMetadata *m_data;
virtual void SetUp() {
m_data = nullptr;
}
virtual void TearDown() {
aiMetadata::Dealloc( m_data );
}
};
TEST_F( utMetadata, creationTest ) {
bool ok( true );
try {
aiMetadata data;
} catch ( ... ) {
ok = false;
}
EXPECT_TRUE( ok );
}
TEST_F( utMetadata, allocTest ) {
aiMetadata *data = aiMetadata::Alloc( 0 );
EXPECT_EQ( nullptr, data );
data = aiMetadata::Alloc( 1 );
EXPECT_NE( nullptr, data );
EXPECT_EQ( 1U, data->mNumProperties );
EXPECT_NE( nullptr, data->mKeys );
EXPECT_NE( nullptr, data->mValues );
aiMetadata::Dealloc( data );
}
TEST_F( utMetadata, get_set_pod_Test ) {
m_data = aiMetadata::Alloc( 5 );
// int, 32 bit
unsigned int index( 0 );
bool success( false );
const std::string key_int = "test_int";
success = m_data->Set( index, key_int, 1 );
EXPECT_TRUE( success );
success = m_data->Set( index + 10, key_int, 1 );
EXPECT_FALSE( success );
// unsigned int, 64 bit
index++;
const std::string key_uint = "test_uint";
success = m_data->Set<uint64_t>( index, key_uint, 1UL );
EXPECT_TRUE( success );
uint64_t result_uint( 0 );
success = m_data->Get( key_uint, result_uint );
EXPECT_TRUE( success );
EXPECT_EQ( 1UL, result_uint );
// bool
index++;
const std::string key_bool = "test_bool";
success = m_data->Set( index, key_bool, true );
EXPECT_TRUE( success );
bool result_bool( false );
success = m_data->Get( key_bool, result_bool );
EXPECT_TRUE( success );
EXPECT_EQ( true, result_bool );
// float
index++;
const std::string key_float = "test_float";
float fVal = 2.0f;
success = m_data->Set( index, key_float, fVal );
EXPECT_TRUE( success );
float result_float( 0.0f );
success = m_data->Get( key_float, result_float );
EXPECT_TRUE( success );
EXPECT_FLOAT_EQ( 2.0f, result_float );
// double
index++;
const std::string key_double = "test_double";
double dVal = 3.0;
success = m_data->Set( index, key_double, dVal );
EXPECT_TRUE( success );
double result_double( 0.0 );
success = m_data->Get( key_double, result_double );
EXPECT_TRUE( success );
EXPECT_DOUBLE_EQ( 3.0, result_double );
// error
int result;
success = m_data->Get( "bla", result );
EXPECT_FALSE( success );
}
TEST_F( utMetadata, get_set_string_Test ) {
m_data = aiMetadata::Alloc( 1 );
unsigned int index( 0 );
bool success( false );
const std::string key = "test";
success = m_data->Set( index, key, aiString( std::string( "test" ) ) );
EXPECT_TRUE( success );
success = m_data->Set( index+10, key, aiString( std::string( "test" ) ) );
EXPECT_FALSE( success );
aiString result;
success = m_data->Get( key, result );
EXPECT_EQ( aiString( std::string( "test" ) ), result );
EXPECT_TRUE( success );
success = m_data->Get( "bla", result );
EXPECT_FALSE( success );
}
TEST_F( utMetadata, get_set_aiVector3D_Test ) {
m_data = aiMetadata::Alloc( 1 );
unsigned int index( 0 );
bool success( false );
const std::string key = "test";
aiVector3D vec( 1, 2, 3 );
success = m_data->Set( index, key, vec );
EXPECT_TRUE( success );
aiVector3D result( 0, 0, 0 );
success = m_data->Get( key, result );
EXPECT_EQ( vec, result );
EXPECT_TRUE( success );
}
TEST_F( utMetadata, copy_test ) {
m_data = aiMetadata::Alloc( AI_META_MAX );
bool bv = true;
m_data->Set( 0, "bool", bv );
int32_t i32v = -10;
m_data->Set( 1, "int32", i32v );
uint64_t ui64v = static_cast<uint64_t>( 10 );
m_data->Set( 2, "uint64", ui64v );
float fv = 1.0f;
m_data->Set( 3, "float", fv );
double dv = 2.0;
m_data->Set( 4, "double", dv );
const aiString strVal( std::string( "test" ) );
m_data->Set( 5, "aiString", strVal );
aiVector3D vecVal( 1, 2, 3 );
m_data->Set( 6, "aiVector3D", vecVal );
aiMetadata copy( *m_data );
EXPECT_EQ( 7u, copy.mNumProperties );
// bool test
{
bool v;
EXPECT_TRUE( copy.Get( "bool", v ) );
EXPECT_EQ( bv, v );
}
// int32_t test
{
int32_t v;
bool ok = copy.Get( "int32", v );
EXPECT_TRUE( ok );
EXPECT_EQ( i32v, v );
}
// uint64_t test
{
uint64_t v;
bool ok = copy.Get( "uint64", v );
EXPECT_TRUE( ok );
EXPECT_EQ( ui64v, v );
}
// float test
{
float v;
EXPECT_TRUE( copy.Get( "float", v ) );
EXPECT_EQ( fv, v );
}
// double test
{
double v;
EXPECT_TRUE( copy.Get( "double", v ) );
EXPECT_EQ( dv, v );
}
// bool test
{
aiString v;
EXPECT_TRUE( copy.Get( "aiString", v ) );
EXPECT_EQ( strVal, v );
}
// bool test
{
aiVector3D v;
EXPECT_TRUE( copy.Get( "aiVector3D", v ) );
EXPECT_EQ( vecVal, v );
}
}
|
;*************************************************************************
;** INTEL Corporation Proprietary Information
;**
;** This listing is supplied under the terms of a license
;** agreement with INTEL Corporation and may not be copied
;** nor disclosed except in accordance with the terms of
;** that agreement.
;**
;** Copyright (c) 1995 Intel Corporation.
;** All Rights Reserved.
;**
;*************************************************************************
;//
;// $Header: S:\h26x\src\dec\cx512yuv.asv 1.5 30 Dec 1996 20:02:08 MDUDA $
;//
;// $Log: S:\h26x\src\dec\cx512yuv.asv $
;//
;// Rev 1.5 30 Dec 1996 20:02:08 MDUDA
;// Fixed problem where buffer boundaries were being over-written.
;//
;// Rev 1.4 11 Dec 1996 14:58:52 JMCVEIGH
;//
;// Changed to support width the are multiples of 4.
;//
;// Rev 1.3 18 Jul 1996 12:52:58 KLILLEVO
;// changed cache heating to speed things up a bit
;//
;// Rev 1.2 18 Jul 1996 09:39:34 KLILLEVO
;//
;// added PVCS header and log
;; Very straightforward implementation of the YUV pitch changer
;; Does 16 pels at a time. If the width is not a multiple of 16
;; the remainder pels are handled as a special case. We assume
;; that the width is at least a multiple of 4
OPTION PROLOGUE: None
OPTION EPILOGUE: ReturnAndRelieveEpilogueMacro
.xlist
include memmodel.inc
.list
.DATA
; any data would go here
.CODE
ASSUME cs: FLAT
ASSUME ds: FLAT
ASSUME es: FLAT
ASSUME fs: FLAT
ASSUME gs: FLAT
ASSUME ss: FLAT
PUBLIC YUV12ToYUV
YUV12ToYUV proc DIST LANG AuYPlane: DWORD,
AuVPlane: DWORD,
AuUPlane: DWORD,
AuWidth: DWORD,
AuHeight: DWORD,
AuYPitch: DWORD,
AUVPitch: DWORD,
AbShapingFlag: DWORD,
AuCCOutputBuffer: DWORD,
AlOutput: DWORD,
AuOffsetToLine0: DWORD,
AintPitch: DWORD,
ACCType: DWORD
LocalFrameSize = 12
RegisterStorageSize = 16 ; 4 registers pushed
; Argument offsets (after register pushed)
uYPlane = LocalFrameSize + RegisterStorageSize + 4
uVPlane = LocalFrameSize + RegisterStorageSize + 8
uUPlane = LocalFrameSize + RegisterStorageSize + 12
uWidth = LocalFrameSize + RegisterStorageSize + 16
uHeight = LocalFrameSize + RegisterStorageSize + 20
uYPitch = LocalFrameSize + RegisterStorageSize + 24
uUVPitch = LocalFrameSize + RegisterStorageSize + 28
bShapingFlag = LocalFrameSize + RegisterStorageSize + 32
uCCOutputBuffer = LocalFrameSize + RegisterStorageSize + 36
lOutput = LocalFrameSize + RegisterStorageSize + 40
uOffsetToLine0 = LocalFrameSize + RegisterStorageSize + 44
intPitch = LocalFrameSize + RegisterStorageSize + 48
CCType = LocalFrameSize + RegisterStorageSize + 52
; Local offsets (after register pushes)
LineAdd = 0 ; 1
LineWidth = 4 ; 2
; Arguments relative to esp
_uYPlane EQU [esp + uYPlane]
_uVPlane EQU [esp + uVPlane]
_UUPlane EQU [esp + uUPlane]
_uWidth EQU [esp + uWidth ]
_uHeight EQU [esp + uHeight]
_uYPitch EQU [esp + uYPitch]
_uUVPitch EQU [esp + uUVPitch]
_bShapingFlag EQU [esp + bShapingFlag]
_uCCOutputBuffer EQU [esp + uCCOutputBuffer]
_lOutput EQU [esp + lOutput]
_uOffsetToLine0 EQU [esp + uOffsetToLine0]
_intPitch EQU [esp + intPitch]
_uCCType EQU [esp + CCType]
; Locals relative to esp
_LineAdd EQU [esp + LineAdd]
_LineWidth EQU [esp + LineWidth]
_uRemainderEdgePels EQU [esp + uRemainderEdgePels]
; Save registers and start working
push ebx
push esi
push edi
push ebp
sub esp, LocalFrameSize
mov eax, _uCCOutputBuffer
add eax, _uOffsetToLine0
mov ecx, _lOutput
add eax, ecx
mov ebx, _uYPitch
mov ecx, _uWidth
mov esi, _uYPlane
mov edi, eax
; luma
sub ebx, ecx ; ebx = pitch - width
mov edx, _uHeight
mov eax, _uWidth
mov _LineAdd, ebx
L2:
test ecx, 0FFFFFFF0H
jz LEdgePels ; Width may be less than 16
L1:
mov ebx, DWORD PTR [edi] ; heat cache
add edi, 16
mov eax, DWORD PTR [esi + 0]
mov ebx, DWORD PTR [esi + 4]
mov DWORD PTR [edi - 16], eax
mov DWORD PTR [edi - 12], ebx
mov eax, DWORD PTR [esi + 8]
mov ebx, DWORD PTR [esi +12]
mov DWORD PTR [edi - 8], eax
mov DWORD PTR [edi - 4], ebx
add esi, 16
sub ecx, 16
test ecx, 0FFFFFFF0H
jnz L1
LEdgePels:
; Do edge pels is needed (if width a multiple of 4, but not 16)
; Check 8 edge pels
test ecx, 08H
jz Lchk4
mov eax, DWORD PTR [esi + 0] ; Input pels 0-3
mov ebx, DWORD PTR [esi + 4] ; Input pels 4-7
mov DWORD PTR [edi + 0], eax ; Output pels 0-3
mov DWORD PTR [edi + 4], ebx ; Output pels 4-7
add esi, 8
add edi, 8
Lchk4:
; Check 4 edge pels
test ecx, 04H
jz L2_cont
mov eax, DWORD PTR [esi + 0] ; Input pels 0-3
add esi, 4
mov DWORD PTR [edi + 0], eax ; Output pels 0-3
add edi, 4
L2_cont:
add esi, _LineAdd
mov ecx, _uWidth
dec edx
jnz L2
; chroma
mov esi, _uUPlane
mov ecx, _uWidth
shr ecx, 1
mov ebx, _uUVPitch
sub ebx, ecx ; ebx = pitch - width/2
mov edx, _uHeight
shr edx, 1
mov _LineAdd, ebx
mov _uWidth, ecx
mov _uHeight, edx
U2:
test ecx, 0FFFFFFF8H
jz UEdgePels ; Width may be less than 16
U1:
mov ebx, DWORD PTR [edi] ; heat cache
add edi, 8
mov eax, DWORD PTR [esi + 0]
mov ebx, DWORD PTR [esi + 4]
mov DWORD PTR [edi - 8], eax
mov DWORD PTR [edi - 4], ebx
add esi, 8
sub ecx, 8
test ecx, 0FFFFFFF8H
jnz U1
UEdgePels:
; Do edge pels is needed (if width a multiple of 4, but not 16)
; Check 4 edge pels
test ecx, 04H
jz Uchk4
mov eax, DWORD PTR [esi + 0] ; Input pels 0-3
add esi, 4
mov DWORD PTR [edi + 0], eax ; Output pels 0-3
add edi, 4
Uchk4:
; Check 2 edge pels
test ecx, 02H
jz U2_cont
mov ax, WORD PTR [esi + 0] ; Input pels 0-3
add esi, 2
mov WORD PTR [edi + 0], ax ; Output pels 0-3
add edi, 2
U2_cont:
add esi, _LineAdd
mov ecx, _uWidth
dec edx
jnz U2
; chroma
mov esi, _uVPlane
mov ecx, _uWidth
mov edx, _uHeight
nop
V2:
test ecx, 0FFFFFFF8H
jz UEdgePels ; Width may be less than 16
V1:
mov ebx, DWORD PTR [edi] ; heat cache
add edi, 8
mov eax, DWORD PTR [esi + 0]
mov ebx, DWORD PTR [esi + 4]
mov DWORD PTR [edi - 8], eax
mov DWORD PTR [edi - 4], ebx
add esi, 8
sub ecx, 8
test ecx, 0FFFFFFF8H
jnz V1
VEdgePels:
; Do edge pels is needed (if width a multiple of 4, but not 16)
; Check 4 edge pels
test ecx, 04H
jz Vchk4
mov eax, DWORD PTR [esi + 0] ; Input pels 0-3
add esi, 4
mov DWORD PTR [edi + 0], eax ; Output pels 0-3
add edi, 4
Vchk4:
; Check 2 edge pels
test ecx, 02H
jz V2_cont
mov ax, WORD PTR [esi + 0] ; Input pels 0-3
add esi, 2
mov WORD PTR [edi + 0], ax ; Output pels 0-3
add edi, 2
V2_cont:
add esi, _LineAdd
mov ecx, _uWidth
dec edx
jnz V2
add esp, LocalFrameSize ; restore esp to registers
pop ebp
pop edi
pop esi
pop ebx
ret 52 ; 13*4 bytes of arguments
YUV12ToYUV ENDP
END
|
; A139760: First quadrisection of A115451.
; 1,9,137,2185,34953,559241,8947849,143165577,2290649225,36650387593,586406201481,9382499223689,150119987579017,2401919801264265,38430716820228233,614891469123651721,9838263505978427529,157412216095654840457,2518595457530477447305,40297527320487639156873,644760437127802226509961,10316166994044835624159369,165058671904717369986549897,2640938750475477919784798345,42255020007607646716556773513,676080320121722347464908376201,10817285121947557559438534019209,173076561951160920951016544307337
mov $1,16
pow $1,$0
div $1,15
mul $1,8
add $1,1
mov $0,$1
|
.model small
.data
.code
main proc
mov dl, 3
inc dl ; the increment command increments the value inside the register by 1, it cannot increment more than by 1
;dec dl would decrement the vaule of dl register by 1
add dl, 48
neg dl ; what we do where is we create a negative number from the dl register, which in our case is 3 + 1 + 48 = 52.
; we write 52 in binary 00110100, we invert that number 11001011 and we add 1 to it, 11001100 which is -52,
; in hex it should be CC and it will print a character from the ASCII table
mov ah, 2h
int 21h
endp
end main
|
/*
* 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.
*/
#pragma once
#ifndef GEODE_POOLFACTORY_H_
#define GEODE_POOLFACTORY_H_
#include <chrono>
#include "internal/geode_globals.hpp"
#include "internal/chrono/duration.hpp"
#include "Pool.hpp"
/**
* @file
*/
namespace apache {
namespace geode {
namespace client {
class CacheImpl;
class PoolAttributes;
class Pool;
/**
* This interface provides for the configuration and creation of instances of
* {@link Pool}.
* <p>Every pool needs to have at least one {@link #addLocator locator} or
* {@link #addServer server} added
* to it. Locators should be added unless direct connections to
* bridge servers are desired.
* <p>The setter methods are used to specify
* non-default values for the other pool properties.
* <p>Once it is configured {@link #create}
* will produce an instance.
* <p>The factory can be restored to its default
* configuration by calling {@link #reset}.
* <p>Instances of this interface can be created by calling
* {@link Cache#getPoolFactory}.
* <p>
* If a subscription is going to be made using a pool then subscriptions
* {@link #setSubscriptionEnabled must be enabled} on the pool.
* Subscriptions are made using these APIs:
* <ul>
* <li>{@link QueryService#newCq}
* <li>{@link Region#registerKeys}
* <li>{@link Region#registerAllKeys}
* <li>{@link Region#registerRegex}
* </ul>
*
*/
class APACHE_GEODE_EXPORT PoolFactory {
public:
/**
* The default amount of time which we will wait for a free connection if max
* connections is set and all of the connections are in use.
* <p>Current value: <code>10s</code>.
*/
static const std::chrono::milliseconds DEFAULT_FREE_CONNECTION_TIMEOUT;
/**
* The default interval in which the pool will check to see if
* a connection to a given server should be moved to a different
* server to improve the load balance.
* <p>Current value: <code>5min</code>
*/
static const std::chrono::milliseconds DEFAULT_LOAD_CONDITIONING_INTERVAL;
/**
* The default size in bytes of the socket buffer on each connection
* established.
* <p>Current value: <code>32768</code>.
*/
static const int DEFAULT_SOCKET_BUFFER_SIZE = 32768;
/**
* The default amount of time to wait for a response from a server.
* <p>Current value: <code>10s</code>.
*/
static const std::chrono::milliseconds DEFAULT_READ_TIMEOUT;
/**
* The default number of connections to be created initially.
* <p>Current value: <code>1</code>.
*/
static const int DEFAULT_MIN_CONNECTIONS = 1;
/**
* The default maximum number of connections to be created.
* <p>Current value: <code>-1</code>.
*/
static const int DEFAULT_MAX_CONNECTIONS = -1;
/**
* The default amount of time in to wait for a connection to become idle.
* <p>Current value: <code>5s</code>.
*/
static const std::chrono::milliseconds DEFAULT_IDLE_TIMEOUT;
/**
* The default number of times to retry an operation after a timeout or
* exception.
* <p>Current value: <code>-1</code>.
*/
static const int DEFAULT_RETRY_ATTEMPTS = -1;
/**
* The default frequenc, to ping servers.
* <p>Current value: <code>10s</code>.
*/
static const std::chrono::milliseconds DEFAULT_PING_INTERVAL;
/**
* The default frequency to update the locator list.
* <p>Current value: <code>5s</code>.
*/
static const std::chrono::milliseconds DEFAULT_UPDATE_LOCATOR_LIST_INTERVAL;
/**
* The default frequency that client statistics are sent to the server.
* <p>Current value: <code>std::chrono::milliseconds::zero()</code>
* (disabled).
*/
static const std::chrono::milliseconds DEFAULT_STATISTIC_INTERVAL;
/**
* The default value for whether to establish a server to client subscription.
* <p>Current value: <code>false</code>.
*/
static const bool DEFAULT_SUBSCRIPTION_ENABLED = false;
/**
* The default redundancy for servers holding subscriptions established by
* this
* client.
* <p>Current value: <code>0</code>.
*/
static const int DEFAULT_SUBSCRIPTION_REDUNDANCY = 0;
/**
* The default amount of time that messages sent from a server to a client
* will be tracked. The tracking is done to minimize duplicate events.
* <p>Current value: <code>900s</code>.
*/
static const std::chrono::milliseconds
DEFAULT_SUBSCRIPTION_MESSAGE_TRACKING_TIMEOUT;
/**
* The default amount of time to wait before sending an acknowledgement to the
* server about events received from the subscriptions.
* <p>Current value: <code>100ms</code>.
*/
static const std::chrono::milliseconds DEFAULT_SUBSCRIPTION_ACK_INTERVAL;
/**
* The default server group.
* <p>Current value: <code>""</code>.
*/
static const std::string DEFAULT_SERVER_GROUP;
/**
* Whether thread local connection is enabled.
* <p>Current value: <code>"false"</code>.
*/
static constexpr bool DEFAULT_THREAD_LOCAL_CONN = false;
/**
* Whether client is in multi user secure mode
* <p>Current value: <code>"false"</code>.
*/
static constexpr bool DEFAULT_MULTIUSER_SECURE_MODE = false;
/**
* The default value for whether to have single hop optimisations enabled.
* <p>Current value: <code>true</code>.
*/
static constexpr bool DEFAULT_PR_SINGLE_HOP_ENABLED = true;
/**
* Sets the free connection timeout for this pool.
* If the pool has a max connections setting, operations will block
* if all of the connections are in use. The free connection timeout
* specifies how long those operations will block waiting for
* a free connection before receiving
* an {@link AllConnectionsInUseException}. If max connections
* is not set this setting has no effect.
*
* @see #setMaxConnections(int)
*
* @param connectionTimeout is the connection timeout
*
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if <code>connectionTimeout</code>
* is less than or equal to <code>std::chrono::milliseconds::zero()</code>.
*/
PoolFactory& setFreeConnectionTimeout(
std::chrono::milliseconds connectionTimeout);
/**
* Sets the load conditioning interval for this pool.
* This interval controls how frequently the pool will check to see if
* a connection to a given server should be moved to a different
* server to improve the load balance.
* <p>A value of <code>std::chrono::milliseconds::zero()</code> disables load
* conditioning.
*
* @param loadConditioningInterval is the connection lifetime
*
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if <code>connectionLifetime</code>
* is less than <code>std::chrono::milliseconds::zero()</code>.
*/
PoolFactory& setLoadConditioningInterval(
std::chrono::milliseconds loadConditioningInterval);
/**
* Sets the socket buffer size for each connection made in this pool.
* Large messages can be received and sent faster when this buffer is larger.
* Larger buffers also optimize the rate at which servers can send events
* for client subscriptions.
*
* @param bufferSize is the size of the socket buffers used for reading and
* writing on each connection in this pool.
*
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if <code>bufferSize</code>
* is less than or equal to <code>0</code>.
*/
PoolFactory& setSocketBufferSize(int bufferSize);
/**
* Sets the thread local connections policy for this pool.
* If <code>true</code> then any time a thread goes to use a connection
* from this pool it will check a thread local cache and see if it already
* has a connection in it. If so it will use it. If not it will get one from
* this pool and cache it in the thread local. This gets rid of thread
* contention
* for the connections but increases the number of connections the servers
* see.
* <p>If <code>false</code> then connections are returned to the pool as soon
* as the operation being done with the connection completes. This allows
* connections to be shared amonst multiple threads keeping the number of
* connections down.
*
* @param threadLocalConnections if <code>true</code> then enable thread local
* connections.
* @return a reference to <code>this</code>
*/
PoolFactory& setThreadLocalConnections(bool threadLocalConnections);
/**
* Sets the duration to wait for a response from a server before timing out
* the operation and trying another server (if any are available).
*
* @param timeout duration to wait for a response from a
* server
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if <code>timeout</code>
* is less than or equal to <code>std::chrono::milliseconds::zero()</code>.
*/
PoolFactory& setReadTimeout(std::chrono::milliseconds timeout);
/**
* Sets the minimum number of connections to keep available at all times.
* When the pool is created, it will create this many connections.
* If <code>0</code> then connections will not be made until an actual
* operation
* is done that requires client-to-server communication.
*
* @param minConnections is the initial number of connections
* this pool will create.
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if <code>minConnections</code>
* is less than <code>0</code>.
*/
PoolFactory& setMinConnections(int minConnections);
/**
* Sets the max number of client to server connections that the pool will
* create. If all of
* the connections are in use, an operation requiring a client to server
* connection
* will block until a connection is available.
*
* @see #setFreeConnectionTimeout(int)
*
* @param maxConnections is the maximum number of connections in the pool.
* <code>-1</code> indicates that there is no maximum number of connections
*
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if <code>maxConnections</code>
* is less than <code>minConnections</code>.
*/
PoolFactory& setMaxConnections(int maxConnections);
/**
* Sets the amount of time a connection can be idle before expiring the
* connection. If the pool size is greater than the minimum specified by
* {@link PoolFactory#setMinConnections(int)}, connections which have been
* idle for longer than the idleTimeout will be closed.
*
* @param idleTimeout is the duration that an idle connection
* should live no less than before expiring, actual time may be longer
* depending on clock resolution. A duration std::chrono::milliseconds::zero()
* indicates that connections should never expire.
* @return a reference to <code>this</code>
*/
PoolFactory& setIdleTimeout(std::chrono::milliseconds);
/**
* Set the number of times to retry a request after timeout/exception.
* @param retryAttempts is the number of times to retry a request
* after timeout/exception. -1 indicates that a request should be
* tried against every available server before failing
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if <code>idleTimout</code>
* is less than <code>0</code>.
*/
PoolFactory& setRetryAttempts(int retryAttempts);
/**
* The frequency with which servers must be pinged to verify that they are
* still alive.
* Each server will be sent a ping every <code>pingInterval</code> if there
* has not
* been any other communication with the server.
*
* These pings are used by the server to monitor the health of
* the client. Make sure that the <code>pingInterval</code> is less than the
* maximum time between pings allowed by the bridge server.
*
* @param pingInterval is the amount of time between pings.
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if <code>pingInterval</code>
* is less than <code>0</code>.
*
* @see CacheServer#setMaximumTimeBetweenPings(int)
*/
PoolFactory& setPingInterval(std::chrono::milliseconds pingInterval);
/**
* The frequency with which client updates the locator list. To disable this
* set its value to std::chrono::milliseconds::zero().
*
* @param updateLocatorListInterval is the amount of time
* between checking locator list at locator.
* @return a reference to <code>this</code>
*/
PoolFactory& setUpdateLocatorListInterval(
std::chrono::milliseconds updateLocatorListInterval);
/**
* The frequency with which the client statistics must be sent to the server.
* Doing this allows <code>GFMon</code> to monitor clients.
* <p>A value of <code>std::chrono::milliseconds::zero()</code> disables the
* sending of client statistics to the server.
*
* @param statisticInterval is the amount of time between
* sends of client statistics to the server.
*
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if <code>statisticInterval</code>
* is less than <code>std::chrono::milliseconds::zero()</code>.
*/
PoolFactory& setStatisticInterval(
std::chrono::milliseconds statisticInterval);
/**
* Configures the group which contains all the servers that this pool connects
* to.
* @param group is the server group that this pool will connect to.
* If the value is <code>null</code> or <code>""</code> then the pool connects
* to all servers.
* @return a reference to <code>this</code>
*/
PoolFactory& setServerGroup(std::string group);
/**
* Adds a locator, given its host and port, to this factory.
* The locator must be a server locator and will be used to discover other
* running
* bridge servers and locators.
* @param host is the host name or ip address that the locator is listening
* on.
* @param port is the port that the locator is listening on.
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if the <code>host</code> is an unknown
* host
* according to {@link java.net.InetAddress#getByName} or if the port is
* outside
* the valid range of [1..65535] inclusive.
* @throws IllegalStateException if the locator has already been {@link
* #addServer added} to this factory.
*/
PoolFactory& addLocator(const std::string& host, int port);
/**
* Adds a server, given its host and port, to this factory.
* The server must be a bridge server and this client will
* directly connect to the server without consulting a server locator.
* @param host is the host name or ip address that the server is listening on.
* @param port is the port that the server is listening on.
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if the <code>host</code> is an unknown
* host
* according to {@link java.net.InetAddress#getByName} or if the port is
* outside
* the valid range of [1..65535] inclusive.
* @throws IllegalStateException if the server has already been {@link
* #addLocator added} to this factory.
*/
PoolFactory& addServer(const std::string& host, int port);
/**
* If set to <code>true</code> then the created pool will have
* server-to-client
* subscriptions enabled.
* If set to <code>false</code> then all <code>Subscription*</code> attributes
* are ignored at the time of creation.
* @return a reference to <code>this</code>
*/
PoolFactory& setSubscriptionEnabled(bool enabled);
/**
* Sets the redundancy level for this pools server-to-client subscriptions.
* If <code>0</code> then no redundant copies are kept on the servers.
* Otherwise an effort is made to maintain the requested number of
* copies of the server-to-client subscriptions. At most, one copy per server
* is
* made up to the requested level.
* @param redundancy is the number of redundant servers for this client's
* subscriptions.
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if <code>redundancyLevel</code>
* is less than <code>-1</code>.
*/
PoolFactory& setSubscriptionRedundancy(int redundancy);
/**
* Sets the messageTrackingTimeout attribute which is the time-to-live period
* for subscription events the client has received from the server. It is used
* to minimize duplicate events. Entries that have not been modified for this
* amount of time are expired from the list.
*
* @param messageTrackingTimeout is the duration to set the timeout to.
* @return a reference to <code>this</code>
*
* @throws IllegalArgumentException if <code>messageTrackingTimeout</code>
* is less than or equal to <code>0</code>.
*/
PoolFactory& setSubscriptionMessageTrackingTimeout(
std::chrono::milliseconds messageTrackingTimeout);
/**
* Sets the is the interval to wait before sending acknowledgements to the
* bridge server for events received from the server subscriptions.
*
* @param ackInterval is the duration to wait before sending event
* acknowledgements.
*
* @throws IllegalArgumentException if <code>ackInterval</code>
* is less than or equal to <code>0</code>.
* @return a reference to <code>this</code>
*/
PoolFactory& setSubscriptionAckInterval(
std::chrono::milliseconds ackInterval);
/**
* Sets whether Pool is in multi user secure mode.
* If its in multiuser mode then app needs to get RegionService instance of
* Cache.
* Deafult value is false.
* @return a reference to <code>this</code>
*/
PoolFactory& setMultiuserAuthentication(bool multiuserAuthentication);
/**
* Resets the configuration of this factory to its defaults.
* @return a reference to <code>this</code>
*/
PoolFactory& reset();
/**
* Creates a new Pool for connecting a client to a set of Geode Cache
* Servers.
* using this factory's settings for attributes.
*
* @param name is the name of the pool, used when connecting regions to it
* @throws IllegalStateException if a pool with <code>name</code> already
* exists
* @throws IllegalStateException if a locator or server has not been added.
* @return the newly created pool.
*/
std::shared_ptr<Pool> create(std::string name);
/**
* By default setPRSingleHopEnabled is true<br>
* The client is aware of location of partitions on servers hosting
* {@link Region}s.
* Using this information, the client routes the client cache operations
* directly to the server which is hosting the required partition for the
* cache operation.
* If setPRSingleHopEnabled is false the client can do an extra hop on servers
* to go to the required partition for that cache operation.
* The setPRSingleHopEnabled avoids extra hops only for following cache
* operations:<br>
* 1. {@link Region#put(Object, Object)}<br>
* 2. {@link Region#get(Object)}<br>
* 3. {@link Region#destroy(Object)}<br>
* If true, works best when {@link PoolFactory#setMaxConnections(int)} is set
* to -1.
* @param name is boolean whether PR Single Hop optimization is enabled or
* not.
* @return a reference to <code>this</code>
*/
PoolFactory& setPRSingleHopEnabled(bool enabled);
~PoolFactory() = default;
PoolFactory(const PoolFactory&) = default;
private:
explicit PoolFactory(const Cache& cache);
PoolFactory& addCheck(const std::string& host, int port);
std::shared_ptr<PoolAttributes> m_attrs;
bool m_isSubscriptionRedundancy;
bool m_addedServerOrLocator;
const Cache& m_cache;
friend class Cache;
friend class PoolManager;
friend class PoolManagerImpl;
friend class CacheFactory;
friend class CacheXmlCreation;
};
} // namespace client
} // namespace geode
} // namespace apache
#endif // GEODE_POOLFACTORY_H_
|
#include "sat.hpp"
#include <iostream>
int main(int argc, char **argv) {
using namespace collision2d;
const Polygon<double> a{{0, 0}, {2, 0}, {2, 2}, {0, 2}};
const Polygon<double> b{{1, 1}, {3, 0}, {3, 5}, {1, 6}};
const Polygon<double> c{{0, 3}, {2, 3}, {2, 6}, {0, 7}};
std::cout << "intersect(a, b) ? " << std::boolalpha << intersect(a, b)
<< std::endl;
std::cout << "intersect(b, c) ? " << std::boolalpha << intersect(b, c)
<< std::endl;
std::cout << "intersect(a, c) ? " << std::boolalpha << intersect(a, c)
<< std::endl;
const std::vector<Point<double>> points{
{0, 0}, {0.5, 0.5}, {5, 2}, {-1, 0}, {1, 5}};
for (const auto &point : points) {
std::cout << "intersect([" << point(0) << ' ' << point(1) << "], a) ? "
<< std::boolalpha << intersect(point, a) << std::endl;
}
return EXIT_SUCCESS;
} |
#include <string.h>
#include <string>
#include <vector>
#include <mutex>
#include <memory>
#include <openssl/dh.h>
#include <openssl/md5.h>
#include <openssl/crypto.h>
#include "TunnelBase.h"
#include <openssl/ssl.h>
#include "Crypto.h"
#if LEGACY_OPENSSL
#include "ChaCha20.h"
#include "Poly1305.h"
#endif
#include "Ed25519.h"
#include "I2PEndian.h"
#include "Log.h"
namespace i2p
{
namespace crypto
{
const uint8_t elgp_[256]=
{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F,
0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18,
0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
const int elgg_ = 2;
const uint8_t dsap_[128]=
{
0x9c, 0x05, 0xb2, 0xaa, 0x96, 0x0d, 0x9b, 0x97, 0xb8, 0x93, 0x19, 0x63, 0xc9, 0xcc, 0x9e, 0x8c,
0x30, 0x26, 0xe9, 0xb8, 0xed, 0x92, 0xfa, 0xd0, 0xa6, 0x9c, 0xc8, 0x86, 0xd5, 0xbf, 0x80, 0x15,
0xfc, 0xad, 0xae, 0x31, 0xa0, 0xad, 0x18, 0xfa, 0xb3, 0xf0, 0x1b, 0x00, 0xa3, 0x58, 0xde, 0x23,
0x76, 0x55, 0xc4, 0x96, 0x4a, 0xfa, 0xa2, 0xb3, 0x37, 0xe9, 0x6a, 0xd3, 0x16, 0xb9, 0xfb, 0x1c,
0xc5, 0x64, 0xb5, 0xae, 0xc5, 0xb6, 0x9a, 0x9f, 0xf6, 0xc3, 0xe4, 0x54, 0x87, 0x07, 0xfe, 0xf8,
0x50, 0x3d, 0x91, 0xdd, 0x86, 0x02, 0xe8, 0x67, 0xe6, 0xd3, 0x5d, 0x22, 0x35, 0xc1, 0x86, 0x9c,
0xe2, 0x47, 0x9c, 0x3b, 0x9d, 0x54, 0x01, 0xde, 0x04, 0xe0, 0x72, 0x7f, 0xb3, 0x3d, 0x65, 0x11,
0x28, 0x5d, 0x4c, 0xf2, 0x95, 0x38, 0xd9, 0xe3, 0xb6, 0x05, 0x1f, 0x5b, 0x22, 0xcc, 0x1c, 0x93
};
const uint8_t dsaq_[20]=
{
0xa5, 0xdf, 0xc2, 0x8f, 0xef, 0x4c, 0xa1, 0xe2, 0x86, 0x74, 0x4c, 0xd8, 0xee, 0xd9, 0xd2, 0x9d,
0x68, 0x40, 0x46, 0xb7
};
const uint8_t dsag_[128]=
{
0x0c, 0x1f, 0x4d, 0x27, 0xd4, 0x00, 0x93, 0xb4, 0x29, 0xe9, 0x62, 0xd7, 0x22, 0x38, 0x24, 0xe0,
0xbb, 0xc4, 0x7e, 0x7c, 0x83, 0x2a, 0x39, 0x23, 0x6f, 0xc6, 0x83, 0xaf, 0x84, 0x88, 0x95, 0x81,
0x07, 0x5f, 0xf9, 0x08, 0x2e, 0xd3, 0x23, 0x53, 0xd4, 0x37, 0x4d, 0x73, 0x01, 0xcd, 0xa1, 0xd2,
0x3c, 0x43, 0x1f, 0x46, 0x98, 0x59, 0x9d, 0xda, 0x02, 0x45, 0x18, 0x24, 0xff, 0x36, 0x97, 0x52,
0x59, 0x36, 0x47, 0xcc, 0x3d, 0xdc, 0x19, 0x7d, 0xe9, 0x85, 0xe4, 0x3d, 0x13, 0x6c, 0xdc, 0xfc,
0x6b, 0xd5, 0x40, 0x9c, 0xd2, 0xf4, 0x50, 0x82, 0x11, 0x42, 0xa5, 0xe6, 0xf8, 0xeb, 0x1c, 0x3a,
0xb5, 0xd0, 0x48, 0x4b, 0x81, 0x29, 0xfc, 0xf1, 0x7b, 0xce, 0x4f, 0x7f, 0x33, 0x32, 0x1c, 0x3c,
0xb3, 0xdb, 0xb1, 0x4a, 0x90, 0x5e, 0x7b, 0x2b, 0x3e, 0x93, 0xbe, 0x47, 0x08, 0xcb, 0xcc, 0x82
};
const int rsae_ = 65537;
struct CryptoConstants
{
// DH/ElGamal
BIGNUM * elgp;
BIGNUM * elgg;
// DSA
BIGNUM * dsap;
BIGNUM * dsaq;
BIGNUM * dsag;
// RSA
BIGNUM * rsae;
CryptoConstants (const uint8_t * elgp_, int elgg_, const uint8_t * dsap_,
const uint8_t * dsaq_, const uint8_t * dsag_, int rsae_)
{
elgp = BN_new ();
BN_bin2bn (elgp_, 256, elgp);
elgg = BN_new ();
BN_set_word (elgg, elgg_);
dsap = BN_new ();
BN_bin2bn (dsap_, 128, dsap);
dsaq = BN_new ();
BN_bin2bn (dsaq_, 20, dsaq);
dsag = BN_new ();
BN_bin2bn (dsag_, 128, dsag);
rsae = BN_new ();
BN_set_word (rsae, rsae_);
}
~CryptoConstants ()
{
BN_free (elgp); BN_free (elgg); BN_free (dsap); BN_free (dsaq); BN_free (dsag); BN_free (rsae);
}
};
static const CryptoConstants& GetCryptoConstants ()
{
static CryptoConstants cryptoConstants (elgp_, elgg_, dsap_, dsaq_, dsag_, rsae_);
return cryptoConstants;
}
bool bn2buf (const BIGNUM * bn, uint8_t * buf, size_t len)
{
int offset = len - BN_num_bytes (bn);
if (offset < 0) return false;
BN_bn2bin (bn, buf + offset);
memset (buf, 0, offset);
return true;
}
// RSA
#define rsae GetCryptoConstants ().rsae
const BIGNUM * GetRSAE ()
{
return rsae;
}
// DSA
#define dsap GetCryptoConstants ().dsap
#define dsaq GetCryptoConstants ().dsaq
#define dsag GetCryptoConstants ().dsag
DSA * CreateDSA ()
{
DSA * dsa = DSA_new ();
DSA_set0_pqg (dsa, BN_dup (dsap), BN_dup (dsaq), BN_dup (dsag));
DSA_set0_key (dsa, NULL, NULL);
return dsa;
}
// DH/ElGamal
const int ELGAMAL_SHORT_EXPONENT_NUM_BITS = 226;
const int ELGAMAL_SHORT_EXPONENT_NUM_BYTES = ELGAMAL_SHORT_EXPONENT_NUM_BITS/8+1;
const int ELGAMAL_FULL_EXPONENT_NUM_BITS = 2048;
const int ELGAMAL_FULL_EXPONENT_NUM_BYTES = ELGAMAL_FULL_EXPONENT_NUM_BITS/8;
#define elgp GetCryptoConstants ().elgp
#define elgg GetCryptoConstants ().elgg
static BN_MONT_CTX * g_MontCtx = nullptr;
static void PrecalculateElggTable (BIGNUM * table[][255], int len) // table is len's array of array of 255 bignums
{
if (len <= 0) return;
BN_CTX * ctx = BN_CTX_new ();
g_MontCtx = BN_MONT_CTX_new ();
BN_MONT_CTX_set (g_MontCtx, elgp, ctx);
auto montCtx = BN_MONT_CTX_new ();
BN_MONT_CTX_copy (montCtx, g_MontCtx);
for (int i = 0; i < len; i++)
{
table[i][0] = BN_new ();
if (!i)
BN_to_montgomery (table[0][0], elgg, montCtx, ctx);
else
BN_mod_mul_montgomery (table[i][0], table[i-1][254], table[i-1][0], montCtx, ctx);
for (int j = 1; j < 255; j++)
{
table[i][j] = BN_new ();
BN_mod_mul_montgomery (table[i][j], table[i][j-1], table[i][0], montCtx, ctx);
}
}
BN_MONT_CTX_free (montCtx);
BN_CTX_free (ctx);
}
static void DestroyElggTable (BIGNUM * table[][255], int len)
{
for (int i = 0; i < len; i++)
for (int j = 0; j < 255; j++)
{
BN_free (table[i][j]);
table[i][j] = nullptr;
}
BN_MONT_CTX_free (g_MontCtx);
}
static BIGNUM * ElggPow (const uint8_t * exp, int len, BIGNUM * table[][255], BN_CTX * ctx)
// exp is in Big Endian
{
if (len <= 0) return nullptr;
auto montCtx = BN_MONT_CTX_new ();
BN_MONT_CTX_copy (montCtx, g_MontCtx);
BIGNUM * res = nullptr;
for (int i = 0; i < len; i++)
{
if (res)
{
if (exp[i])
BN_mod_mul_montgomery (res, res, table[len-1-i][exp[i]-1], montCtx, ctx);
}
else if (exp[i])
res = BN_dup (table[len-i-1][exp[i]-1]);
}
if (res)
BN_from_montgomery (res, res, montCtx, ctx);
BN_MONT_CTX_free (montCtx);
return res;
}
static BIGNUM * ElggPow (const BIGNUM * exp, BIGNUM * table[][255], BN_CTX * ctx)
{
auto len = BN_num_bytes (exp);
uint8_t * buf = new uint8_t[len];
BN_bn2bin (exp, buf);
auto ret = ElggPow (buf, len, table, ctx);
delete[] buf;
return ret;
}
static BIGNUM * (* g_ElggTable)[255] = nullptr;
// DH
DHKeys::DHKeys ()
{
m_DH = DH_new ();
DH_set0_pqg (m_DH, BN_dup (elgp), NULL, BN_dup (elgg));
DH_set0_key (m_DH, NULL, NULL);
}
DHKeys::~DHKeys ()
{
DH_free (m_DH);
}
void DHKeys::GenerateKeys ()
{
BIGNUM * priv_key = NULL, * pub_key = NULL;
#if !defined(__x86_64__) // use short exponent for non x64
priv_key = BN_new ();
BN_rand (priv_key, ELGAMAL_SHORT_EXPONENT_NUM_BITS, 0, 1);
#endif
if (g_ElggTable)
{
#if defined(__x86_64__)
priv_key = BN_new ();
BN_rand (priv_key, ELGAMAL_FULL_EXPONENT_NUM_BITS, 0, 1);
#endif
auto ctx = BN_CTX_new ();
pub_key = ElggPow (priv_key, g_ElggTable, ctx);
DH_set0_key (m_DH, pub_key, priv_key);
BN_CTX_free (ctx);
}
else
{
DH_set0_key (m_DH, NULL, priv_key);
DH_generate_key (m_DH);
DH_get0_key (m_DH, (const BIGNUM **)&pub_key, (const BIGNUM **)&priv_key);
}
bn2buf (pub_key, m_PublicKey, 256);
}
void DHKeys::Agree (const uint8_t * pub, uint8_t * shared)
{
BIGNUM * pk = BN_bin2bn (pub, 256, NULL);
DH_compute_key (shared, pk, m_DH);
BN_free (pk);
}
// x25519
X25519Keys::X25519Keys ()
{
#if OPENSSL_X25519
m_Ctx = EVP_PKEY_CTX_new_id (NID_X25519, NULL);
#else
m_Ctx = BN_CTX_new ();
#endif
}
X25519Keys::X25519Keys (const uint8_t * priv, const uint8_t * pub)
{
#if OPENSSL_X25519
m_Pkey = EVP_PKEY_new_raw_private_key (EVP_PKEY_X25519, NULL, priv, 32);
m_Ctx = EVP_PKEY_CTX_new (m_Pkey, NULL);
memcpy (m_PublicKey, pub, 32); // TODO: verify against m_Pkey
#else
memcpy (m_PrivateKey, priv, 32);
memcpy (m_PublicKey, pub, 32);
m_Ctx = BN_CTX_new ();
#endif
}
X25519Keys::~X25519Keys ()
{
#if OPENSSL_X25519
EVP_PKEY_CTX_free (m_Ctx);
if (m_Pkey)
EVP_PKEY_free (m_Pkey);
#else
BN_CTX_free (m_Ctx);
#endif
}
void X25519Keys::GenerateKeys ()
{
#if OPENSSL_X25519
m_Pkey = nullptr;
EVP_PKEY_keygen_init (m_Ctx);
EVP_PKEY_keygen (m_Ctx, &m_Pkey);
EVP_PKEY_CTX_free (m_Ctx);
m_Ctx = EVP_PKEY_CTX_new (m_Pkey, NULL); // TODO: do we really need to re-create m_Ctx?
size_t len = 32;
EVP_PKEY_get_raw_public_key (m_Pkey, m_PublicKey, &len);
#else
RAND_bytes (m_PrivateKey, 32);
GetEd25519 ()->ScalarMulB (m_PrivateKey, m_PublicKey, m_Ctx);
#endif
}
void X25519Keys::Agree (const uint8_t * pub, uint8_t * shared)
{
#if OPENSSL_X25519
EVP_PKEY_derive_init (m_Ctx);
auto pkey = EVP_PKEY_new_raw_public_key (EVP_PKEY_X25519, NULL, pub, 32);
EVP_PKEY_derive_set_peer (m_Ctx, pkey);
size_t len = 32;
EVP_PKEY_derive (m_Ctx, shared, &len);
EVP_PKEY_free (pkey);
#else
GetEd25519 ()->ScalarMul (pub, m_PrivateKey, shared, m_Ctx);
#endif
}
void X25519Keys::GetPrivateKey (uint8_t * priv) const
{
#if OPENSSL_X25519
size_t len = 32;
EVP_PKEY_get_raw_private_key (m_Pkey, priv, &len);
#else
memcpy (priv, m_PrivateKey, 32);
#endif
}
// ElGamal
void ElGamalEncrypt (const uint8_t * key, const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx, bool zeroPadding)
{
BN_CTX_start (ctx);
// everything, but a, because a might come from table
BIGNUM * k = BN_CTX_get (ctx);
BIGNUM * y = BN_CTX_get (ctx);
BIGNUM * b1 = BN_CTX_get (ctx);
BIGNUM * b = BN_CTX_get (ctx);
// select random k
#if defined(__x86_64__)
BN_rand (k, ELGAMAL_FULL_EXPONENT_NUM_BITS, -1, 1); // full exponent for x64
#else
BN_rand (k, ELGAMAL_SHORT_EXPONENT_NUM_BITS, -1, 1); // short exponent of 226 bits
#endif
// calculate a
BIGNUM * a;
if (g_ElggTable)
a = ElggPow (k, g_ElggTable, ctx);
else
{
a = BN_new ();
BN_mod_exp (a, elgg, k, elgp, ctx);
}
// restore y from key
BN_bin2bn (key, 256, y);
// calculate b1
BN_mod_exp (b1, y, k, elgp, ctx);
// create m
uint8_t m[255];
m[0] = 0xFF;
memcpy (m+33, data, 222);
SHA256 (m+33, 222, m+1);
// calculate b = b1*m mod p
BN_bin2bn (m, 255, b);
BN_mod_mul (b, b1, b, elgp, ctx);
// copy a and b
if (zeroPadding)
{
encrypted[0] = 0;
bn2buf (a, encrypted + 1, 256);
encrypted[257] = 0;
bn2buf (b, encrypted + 258, 256);
}
else
{
bn2buf (a, encrypted, 256);
bn2buf (b, encrypted + 256, 256);
}
BN_free (a);
BN_CTX_end (ctx);
}
bool ElGamalDecrypt (const uint8_t * key, const uint8_t * encrypted,
uint8_t * data, BN_CTX * ctx, bool zeroPadding)
{
BN_CTX_start (ctx);
BIGNUM * x = BN_CTX_get (ctx), * a = BN_CTX_get (ctx), * b = BN_CTX_get (ctx);
BN_bin2bn (key, 256, x);
BN_sub (x, elgp, x); BN_sub_word (x, 1); // x = elgp - x- 1
BN_bin2bn (zeroPadding ? encrypted + 1 : encrypted, 256, a);
BN_bin2bn (zeroPadding ? encrypted + 258 : encrypted + 256, 256, b);
// m = b*(a^x mod p) mod p
BN_mod_exp (x, a, x, elgp, ctx);
BN_mod_mul (b, b, x, elgp, ctx);
uint8_t m[255];
bn2buf (b, m, 255);
BN_CTX_end (ctx);
uint8_t hash[32];
SHA256 (m + 33, 222, hash);
if (memcmp (m + 1, hash, 32))
{
LogPrint (eLogError, "ElGamal decrypt hash doesn't match");
return false;
}
memcpy (data, m + 33, 222);
return true;
}
void GenerateElGamalKeyPair (uint8_t * priv, uint8_t * pub)
{
#if defined(__x86_64__) || defined(__i386__) || defined(_MSC_VER)
RAND_bytes (priv, 256);
#else
// lower 226 bits (28 bytes and 2 bits) only. short exponent
auto numBytes = (ELGAMAL_SHORT_EXPONENT_NUM_BITS)/8 + 1; // 29
auto numZeroBytes = 256 - numBytes;
RAND_bytes (priv + numZeroBytes, numBytes);
memset (priv, 0, numZeroBytes);
priv[numZeroBytes] &= 0x03;
#endif
BN_CTX * ctx = BN_CTX_new ();
BIGNUM * p = BN_new ();
BN_bin2bn (priv, 256, p);
BN_mod_exp (p, elgg, p, elgp, ctx);
bn2buf (p, pub, 256);
BN_free (p);
BN_CTX_free (ctx);
}
// ECIES
void ECIESEncrypt (const EC_GROUP * curve, const EC_POINT * key, const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx, bool zeroPadding)
{
BN_CTX_start (ctx);
BIGNUM * q = BN_CTX_get (ctx);
EC_GROUP_get_order(curve, q, ctx);
int len = BN_num_bytes (q);
BIGNUM * k = BN_CTX_get (ctx);
BN_rand_range (k, q); // 0 < k < q
// point for shared secret
auto p = EC_POINT_new (curve);
EC_POINT_mul (curve, p, k, nullptr, nullptr, ctx);
BIGNUM * x = BN_CTX_get (ctx), * y = BN_CTX_get (ctx);
EC_POINT_get_affine_coordinates_GFp (curve, p, x, y, nullptr);
if (zeroPadding)
{
encrypted[0] = 0;
bn2buf (x, encrypted + 1, len);
bn2buf (y, encrypted + 1 + len, len);
RAND_bytes (encrypted + 1 + 2*len, 256 - 2*len);
}
else
{
bn2buf (x, encrypted, len);
bn2buf (y, encrypted + len, len);
RAND_bytes (encrypted + 2*len, 256 - 2*len);
}
// ecryption key and iv
EC_POINT_mul (curve, p, nullptr, key, k, ctx);
EC_POINT_get_affine_coordinates_GFp (curve, p, x, y, nullptr);
uint8_t keyBuf[64], iv[64], shared[32];
bn2buf (x, keyBuf, len);
bn2buf (y, iv, len);
SHA256 (keyBuf, len, shared);
// create buffer
uint8_t m[256];
m[0] = 0xFF; m[255] = 0xFF;
memcpy (m+33, data, 222);
SHA256 (m+33, 222, m+1);
// encrypt
CBCEncryption encryption;
encryption.SetKey (shared);
encryption.SetIV (iv);
if (zeroPadding)
{
encrypted[257] = 0;
encryption.Encrypt (m, 256, encrypted + 258);
}
else
encryption.Encrypt (m, 256, encrypted + 256);
EC_POINT_free (p);
BN_CTX_end (ctx);
}
bool ECIESDecrypt (const EC_GROUP * curve, const BIGNUM * key, const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx, bool zeroPadding)
{
bool ret = true;
BN_CTX_start (ctx);
BIGNUM * q = BN_CTX_get (ctx);
EC_GROUP_get_order(curve, q, ctx);
int len = BN_num_bytes (q);
// point for shared secret
BIGNUM * x = BN_CTX_get (ctx), * y = BN_CTX_get (ctx);
if (zeroPadding)
{
BN_bin2bn (encrypted + 1, len, x);
BN_bin2bn (encrypted + 1 + len, len, y);
}
else
{
BN_bin2bn (encrypted, len, x);
BN_bin2bn (encrypted + len, len, y);
}
auto p = EC_POINT_new (curve);
if (EC_POINT_set_affine_coordinates_GFp (curve, p, x, y, nullptr))
{
auto s = EC_POINT_new (curve);
EC_POINT_mul (curve, s, nullptr, p, key, ctx);
EC_POINT_get_affine_coordinates_GFp (curve, s, x, y, nullptr);
EC_POINT_free (s);
uint8_t keyBuf[64], iv[64], shared[32];
bn2buf (x, keyBuf, len);
bn2buf (y, iv, len);
SHA256 (keyBuf, len, shared);
// decrypt
uint8_t m[256];
CBCDecryption decryption;
decryption.SetKey (shared);
decryption.SetIV (iv);
if (zeroPadding)
decryption.Decrypt (encrypted + 258, 256, m);
else
decryption.Decrypt (encrypted + 256, 256, m);
// verify and copy
uint8_t hash[32];
SHA256 (m + 33, 222, hash);
if (!memcmp (m + 1, hash, 32))
memcpy (data, m + 33, 222);
else
{
LogPrint (eLogError, "ECIES decrypt hash doesn't match");
ret = false;
}
}
else
{
LogPrint (eLogError, "ECIES decrypt point is invalid");
ret = false;
}
EC_POINT_free (p);
BN_CTX_end (ctx);
return ret;
}
void GenerateECIESKeyPair (const EC_GROUP * curve, BIGNUM *& priv, EC_POINT *& pub)
{
BN_CTX * ctx = BN_CTX_new ();
BIGNUM * q = BN_new ();
EC_GROUP_get_order(curve, q, ctx);
priv = BN_new ();
BN_rand_range (priv, q);
pub = EC_POINT_new (curve);
EC_POINT_mul (curve, pub, priv, nullptr, nullptr, ctx);
BN_free (q);
BN_CTX_free (ctx);
}
// HMAC
const uint64_t IPAD = 0x3636363636363636;
const uint64_t OPAD = 0x5C5C5C5C5C5C5C5C;
static const uint64_t ipads[] = { IPAD, IPAD, IPAD, IPAD };
static const uint64_t opads[] = { OPAD, OPAD, OPAD, OPAD };
void HMACMD5Digest (uint8_t * msg, size_t len, const MACKey& key, uint8_t * digest)
// key is 32 bytes
// digest is 16 bytes
// block size is 64 bytes
{
uint64_t buf[256];
uint64_t hash[12]; // 96 bytes
#ifdef __AVX__
if(i2p::cpu::avx)
{
__asm__
(
"vmovups %[key], %%ymm0 \n"
"vmovups %[ipad], %%ymm1 \n"
"vmovups %%ymm1, 32(%[buf]) \n"
"vxorps %%ymm0, %%ymm1, %%ymm1 \n"
"vmovups %%ymm1, (%[buf]) \n"
"vmovups %[opad], %%ymm1 \n"
"vmovups %%ymm1, 32(%[hash]) \n"
"vxorps %%ymm0, %%ymm1, %%ymm1 \n"
"vmovups %%ymm1, (%[hash]) \n"
"vzeroall \n" // end of AVX
"movups %%xmm0, 80(%[hash]) \n" // zero last 16 bytes
:
: [key]"m"(*(const uint8_t *)key), [ipad]"m"(*ipads), [opad]"m"(*opads),
[buf]"r"(buf), [hash]"r"(hash)
: "memory", "%xmm0" // TODO: change to %ymm0 later
);
}
else
#endif
{
// ikeypad
buf[0] = key.GetLL ()[0] ^ IPAD;
buf[1] = key.GetLL ()[1] ^ IPAD;
buf[2] = key.GetLL ()[2] ^ IPAD;
buf[3] = key.GetLL ()[3] ^ IPAD;
buf[4] = IPAD;
buf[5] = IPAD;
buf[6] = IPAD;
buf[7] = IPAD;
// okeypad
hash[0] = key.GetLL ()[0] ^ OPAD;
hash[1] = key.GetLL ()[1] ^ OPAD;
hash[2] = key.GetLL ()[2] ^ OPAD;
hash[3] = key.GetLL ()[3] ^ OPAD;
hash[4] = OPAD;
hash[5] = OPAD;
hash[6] = OPAD;
hash[7] = OPAD;
// fill last 16 bytes with zeros (first hash size assumed 32 bytes in I2P)
memset (hash + 10, 0, 16);
}
// concatenate with msg
memcpy (buf + 8, msg, len);
// calculate first hash
MD5((uint8_t *)buf, len + 64, (uint8_t *)(hash + 8)); // 16 bytes
// calculate digest
MD5((uint8_t *)hash, 96, digest);
}
// AES
#ifdef __AES__
#ifdef ARM64AES
void init_aesenc(void){
// TODO: Implementation
}
#endif
#define KeyExpansion256(round0,round1) \
"pshufd $0xff, %%xmm2, %%xmm2 \n" \
"movaps %%xmm1, %%xmm4 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm1 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm1 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm1 \n" \
"pxor %%xmm2, %%xmm1 \n" \
"movaps %%xmm1, "#round0"(%[sched]) \n" \
"aeskeygenassist $0, %%xmm1, %%xmm4 \n" \
"pshufd $0xaa, %%xmm4, %%xmm2 \n" \
"movaps %%xmm3, %%xmm4 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm3 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm3 \n" \
"pslldq $4, %%xmm4 \n" \
"pxor %%xmm4, %%xmm3 \n" \
"pxor %%xmm2, %%xmm3 \n" \
"movaps %%xmm3, "#round1"(%[sched]) \n"
#endif
#ifdef __AES__
void ECBCryptoAESNI::ExpandKey (const AESKey& key)
{
__asm__
(
"movups (%[key]), %%xmm1 \n"
"movups 16(%[key]), %%xmm3 \n"
"movaps %%xmm1, (%[sched]) \n"
"movaps %%xmm3, 16(%[sched]) \n"
"aeskeygenassist $1, %%xmm3, %%xmm2 \n"
KeyExpansion256(32,48)
"aeskeygenassist $2, %%xmm3, %%xmm2 \n"
KeyExpansion256(64,80)
"aeskeygenassist $4, %%xmm3, %%xmm2 \n"
KeyExpansion256(96,112)
"aeskeygenassist $8, %%xmm3, %%xmm2 \n"
KeyExpansion256(128,144)
"aeskeygenassist $16, %%xmm3, %%xmm2 \n"
KeyExpansion256(160,176)
"aeskeygenassist $32, %%xmm3, %%xmm2 \n"
KeyExpansion256(192,208)
"aeskeygenassist $64, %%xmm3, %%xmm2 \n"
// key expansion final
"pshufd $0xff, %%xmm2, %%xmm2 \n"
"movaps %%xmm1, %%xmm4 \n"
"pslldq $4, %%xmm4 \n"
"pxor %%xmm4, %%xmm1 \n"
"pslldq $4, %%xmm4 \n"
"pxor %%xmm4, %%xmm1 \n"
"pslldq $4, %%xmm4 \n"
"pxor %%xmm4, %%xmm1 \n"
"pxor %%xmm2, %%xmm1 \n"
"movups %%xmm1, 224(%[sched]) \n"
: // output
: [key]"r"((const uint8_t *)key), [sched]"r"(GetKeySchedule ()) // input
: "%xmm1", "%xmm2", "%xmm3", "%xmm4", "memory" // clogged
);
}
#endif
#ifdef __AES__
#define EncryptAES256(sched) \
"pxor (%["#sched"]), %%xmm0 \n" \
"aesenc 16(%["#sched"]), %%xmm0 \n" \
"aesenc 32(%["#sched"]), %%xmm0 \n" \
"aesenc 48(%["#sched"]), %%xmm0 \n" \
"aesenc 64(%["#sched"]), %%xmm0 \n" \
"aesenc 80(%["#sched"]), %%xmm0 \n" \
"aesenc 96(%["#sched"]), %%xmm0 \n" \
"aesenc 112(%["#sched"]), %%xmm0 \n" \
"aesenc 128(%["#sched"]), %%xmm0 \n" \
"aesenc 144(%["#sched"]), %%xmm0 \n" \
"aesenc 160(%["#sched"]), %%xmm0 \n" \
"aesenc 176(%["#sched"]), %%xmm0 \n" \
"aesenc 192(%["#sched"]), %%xmm0 \n" \
"aesenc 208(%["#sched"]), %%xmm0 \n" \
"aesenclast 224(%["#sched"]), %%xmm0 \n"
#endif
void ECBEncryption::Encrypt (const ChipherBlock * in, ChipherBlock * out)
{
#ifdef __AES__
if(i2p::cpu::aesni)
{
__asm__
(
"movups (%[in]), %%xmm0 \n"
EncryptAES256(sched)
"movups %%xmm0, (%[out]) \n"
: : [sched]"r"(GetKeySchedule ()), [in]"r"(in), [out]"r"(out) : "%xmm0", "memory"
);
}
else
#endif
{
AES_encrypt (in->buf, out->buf, &m_Key);
}
}
#ifdef __AES__
#define DecryptAES256(sched) \
"pxor 224(%["#sched"]), %%xmm0 \n" \
"aesdec 208(%["#sched"]), %%xmm0 \n" \
"aesdec 192(%["#sched"]), %%xmm0 \n" \
"aesdec 176(%["#sched"]), %%xmm0 \n" \
"aesdec 160(%["#sched"]), %%xmm0 \n" \
"aesdec 144(%["#sched"]), %%xmm0 \n" \
"aesdec 128(%["#sched"]), %%xmm0 \n" \
"aesdec 112(%["#sched"]), %%xmm0 \n" \
"aesdec 96(%["#sched"]), %%xmm0 \n" \
"aesdec 80(%["#sched"]), %%xmm0 \n" \
"aesdec 64(%["#sched"]), %%xmm0 \n" \
"aesdec 48(%["#sched"]), %%xmm0 \n" \
"aesdec 32(%["#sched"]), %%xmm0 \n" \
"aesdec 16(%["#sched"]), %%xmm0 \n" \
"aesdeclast (%["#sched"]), %%xmm0 \n"
#endif
void ECBDecryption::Decrypt (const ChipherBlock * in, ChipherBlock * out)
{
#ifdef __AES__
if(i2p::cpu::aesni)
{
__asm__
(
"movups (%[in]), %%xmm0 \n"
DecryptAES256(sched)
"movups %%xmm0, (%[out]) \n"
: : [sched]"r"(GetKeySchedule ()), [in]"r"(in), [out]"r"(out) : "%xmm0", "memory"
);
}
else
#endif
{
AES_decrypt (in->buf, out->buf, &m_Key);
}
}
#ifdef __AES__
#define CallAESIMC(offset) \
"movaps "#offset"(%[shed]), %%xmm0 \n" \
"aesimc %%xmm0, %%xmm0 \n" \
"movaps %%xmm0, "#offset"(%[shed]) \n"
#endif
void ECBEncryption::SetKey (const AESKey& key)
{
#ifdef __AES__
if(i2p::cpu::aesni)
{
ExpandKey (key);
}
else
#endif
{
AES_set_encrypt_key (key, 256, &m_Key);
}
}
void ECBDecryption::SetKey (const AESKey& key)
{
#ifdef __AES__
if(i2p::cpu::aesni)
{
ExpandKey (key); // expand encryption key first
// then invert it using aesimc
__asm__
(
CallAESIMC(16)
CallAESIMC(32)
CallAESIMC(48)
CallAESIMC(64)
CallAESIMC(80)
CallAESIMC(96)
CallAESIMC(112)
CallAESIMC(128)
CallAESIMC(144)
CallAESIMC(160)
CallAESIMC(176)
CallAESIMC(192)
CallAESIMC(208)
: : [shed]"r"(GetKeySchedule ()) : "%xmm0", "memory"
);
}
else
#endif
{
AES_set_decrypt_key (key, 256, &m_Key);
}
}
void CBCEncryption::Encrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out)
{
#ifdef __AES__
if(i2p::cpu::aesni)
{
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"1: \n"
"movups (%[in]), %%xmm0 \n"
"pxor %%xmm1, %%xmm0 \n"
EncryptAES256(sched)
"movaps %%xmm0, %%xmm1 \n"
"movups %%xmm0, (%[out]) \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"dec %[num] \n"
"jnz 1b \n"
"movups %%xmm1, (%[iv]) \n"
:
: [iv]"r"((uint8_t *)m_LastBlock), [sched]"r"(m_ECBEncryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(numBlocks)
: "%xmm0", "%xmm1", "cc", "memory"
);
}
else
#endif
{
for (int i = 0; i < numBlocks; i++)
{
*m_LastBlock.GetChipherBlock () ^= in[i];
m_ECBEncryption.Encrypt (m_LastBlock.GetChipherBlock (), m_LastBlock.GetChipherBlock ());
out[i] = *m_LastBlock.GetChipherBlock ();
}
}
}
void CBCEncryption::Encrypt (const uint8_t * in, std::size_t len, uint8_t * out)
{
// len/16
int numBlocks = len >> 4;
if (numBlocks > 0)
Encrypt (numBlocks, (const ChipherBlock *)in, (ChipherBlock *)out);
}
void CBCEncryption::Encrypt (const uint8_t * in, uint8_t * out)
{
#ifdef __AES__
if(i2p::cpu::aesni)
{
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"movups (%[in]), %%xmm0 \n"
"pxor %%xmm1, %%xmm0 \n"
EncryptAES256(sched)
"movups %%xmm0, (%[out]) \n"
"movups %%xmm0, (%[iv]) \n"
:
: [iv]"r"((uint8_t *)m_LastBlock), [sched]"r"(m_ECBEncryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out)
: "%xmm0", "%xmm1", "memory"
);
}
else
#endif
Encrypt (1, (const ChipherBlock *)in, (ChipherBlock *)out);
}
void CBCDecryption::Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out)
{
#ifdef __AES__
if(i2p::cpu::aesni)
{
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"1: \n"
"movups (%[in]), %%xmm0 \n"
"movaps %%xmm0, %%xmm2 \n"
DecryptAES256(sched)
"pxor %%xmm1, %%xmm0 \n"
"movups %%xmm0, (%[out]) \n"
"movaps %%xmm2, %%xmm1 \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"dec %[num] \n"
"jnz 1b \n"
"movups %%xmm1, (%[iv]) \n"
:
: [iv]"r"((uint8_t *)m_IV), [sched]"r"(m_ECBDecryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(numBlocks)
: "%xmm0", "%xmm1", "%xmm2", "cc", "memory"
);
}
else
#endif
{
for (int i = 0; i < numBlocks; i++)
{
ChipherBlock tmp = in[i];
m_ECBDecryption.Decrypt (in + i, out + i);
out[i] ^= *m_IV.GetChipherBlock ();
*m_IV.GetChipherBlock () = tmp;
}
}
}
void CBCDecryption::Decrypt (const uint8_t * in, std::size_t len, uint8_t * out)
{
int numBlocks = len >> 4;
if (numBlocks > 0)
Decrypt (numBlocks, (const ChipherBlock *)in, (ChipherBlock *)out);
}
void CBCDecryption::Decrypt (const uint8_t * in, uint8_t * out)
{
#ifdef __AES__
if(i2p::cpu::aesni)
{
__asm__
(
"movups (%[iv]), %%xmm1 \n"
"movups (%[in]), %%xmm0 \n"
"movups %%xmm0, (%[iv]) \n"
DecryptAES256(sched)
"pxor %%xmm1, %%xmm0 \n"
"movups %%xmm0, (%[out]) \n"
:
: [iv]"r"((uint8_t *)m_IV), [sched]"r"(m_ECBDecryption.GetKeySchedule ()),
[in]"r"(in), [out]"r"(out)
: "%xmm0", "%xmm1", "memory"
);
}
else
#endif
Decrypt (1, (const ChipherBlock *)in, (ChipherBlock *)out);
}
void TunnelEncryption::Encrypt (const uint8_t * in, uint8_t * out)
{
#ifdef __AES__
if(i2p::cpu::aesni)
{
__asm__
(
// encrypt IV
"movups (%[in]), %%xmm0 \n"
EncryptAES256(sched_iv)
"movaps %%xmm0, %%xmm1 \n"
// double IV encryption
EncryptAES256(sched_iv)
"movups %%xmm0, (%[out]) \n"
// encrypt data, IV is xmm1
"1: \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"movups (%[in]), %%xmm0 \n"
"pxor %%xmm1, %%xmm0 \n"
EncryptAES256(sched_l)
"movaps %%xmm0, %%xmm1 \n"
"movups %%xmm0, (%[out]) \n"
"dec %[num] \n"
"jnz 1b \n"
:
: [sched_iv]"r"(m_IVEncryption.GetKeySchedule ()), [sched_l]"r"(m_LayerEncryption.ECB().GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(63) // 63 blocks = 1008 bytes
: "%xmm0", "%xmm1", "cc", "memory"
);
}
else
#endif
{
m_IVEncryption.Encrypt ((const ChipherBlock *)in, (ChipherBlock *)out); // iv
m_LayerEncryption.SetIV (out);
m_LayerEncryption.Encrypt (in + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, out + 16); // data
m_IVEncryption.Encrypt ((ChipherBlock *)out, (ChipherBlock *)out); // double iv
}
}
void TunnelDecryption::Decrypt (const uint8_t * in, uint8_t * out)
{
#ifdef __AES__
if(i2p::cpu::aesni)
{
__asm__
(
// decrypt IV
"movups (%[in]), %%xmm0 \n"
DecryptAES256(sched_iv)
"movaps %%xmm0, %%xmm1 \n"
// double IV encryption
DecryptAES256(sched_iv)
"movups %%xmm0, (%[out]) \n"
// decrypt data, IV is xmm1
"1: \n"
"add $16, %[in] \n"
"add $16, %[out] \n"
"movups (%[in]), %%xmm0 \n"
"movaps %%xmm0, %%xmm2 \n"
DecryptAES256(sched_l)
"pxor %%xmm1, %%xmm0 \n"
"movups %%xmm0, (%[out]) \n"
"movaps %%xmm2, %%xmm1 \n"
"dec %[num] \n"
"jnz 1b \n"
:
: [sched_iv]"r"(m_IVDecryption.GetKeySchedule ()), [sched_l]"r"(m_LayerDecryption.ECB().GetKeySchedule ()),
[in]"r"(in), [out]"r"(out), [num]"r"(63) // 63 blocks = 1008 bytes
: "%xmm0", "%xmm1", "%xmm2", "cc", "memory"
);
}
else
#endif
{
m_IVDecryption.Decrypt ((const ChipherBlock *)in, (ChipherBlock *)out); // iv
m_LayerDecryption.SetIV (out);
m_LayerDecryption.Decrypt (in + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, out + 16); // data
m_IVDecryption.Decrypt ((ChipherBlock *)out, (ChipherBlock *)out); // double iv
}
}
// AEAD/ChaCha20/Poly1305
bool AEADChaCha20Poly1305 (const uint8_t * msg, size_t msgLen, const uint8_t * ad, size_t adLen, const uint8_t * key, const uint8_t * nonce, uint8_t * buf, size_t len, bool encrypt)
{
if (len < msgLen) return false;
if (encrypt && len < msgLen + 16) return false;
bool ret = true;
#if LEGACY_OPENSSL
// generate one time poly key
uint8_t polyKey[64];
memset(polyKey, 0, sizeof(polyKey));
chacha20 (polyKey, 64, nonce, key, 0);
// create Poly1305 message
if (!ad) adLen = 0;
std::vector<uint8_t> polyMsg(adLen + msgLen + 3*16);
size_t offset = 0;
uint8_t padding[16]; memset (padding, 0, 16);
if (ad)
{
memcpy (polyMsg.data (), ad, adLen); offset += adLen; // additional authenticated data
auto rem = adLen & 0x0F; // %16
if (rem)
{
// padding1
rem = 16 - rem;
memcpy (polyMsg.data () + offset, padding, rem); offset += rem;
}
}
// encrypt/decrypt data and add to hash
if (buf != msg)
memcpy (buf, msg, msgLen);
if (encrypt)
{
chacha20 (buf, msgLen, nonce, key, 1); // encrypt
memcpy (polyMsg.data () + offset, buf, msgLen); // after encryption
}
else
{
memcpy (polyMsg.data () + offset, buf, msgLen); // before decryption
chacha20 (buf, msgLen, nonce, key, 1); // decrypt
}
offset += msgLen; // encrypted data
auto rem = msgLen & 0x0F; // %16
if (rem)
{
// padding2
rem = 16 - rem;
memcpy (polyMsg.data () + offset, padding, rem); offset += rem;
}
htole64buf (polyMsg.data () + offset, adLen); offset += 8;
htole64buf (polyMsg.data () + offset, msgLen); offset += 8;
if (encrypt)
{
// calculate Poly1305 tag and write in after encrypted data
Poly1305HMAC ((uint32_t *)(buf + msgLen), (uint32_t *)polyKey, polyMsg.data (), offset);
}
else
{
uint32_t tag[8];
// calculate Poly1305 tag
Poly1305HMAC (tag, (uint32_t *)polyKey, polyMsg.data (), offset);
if (memcmp (tag, msg + msgLen, 16)) ret = false; // compare with provided
}
#else
int outlen = 0;
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new ();
if (encrypt)
{
EVP_EncryptInit_ex(ctx, EVP_chacha20_poly1305(), 0, 0, 0);
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, 12, 0);
EVP_EncryptInit_ex(ctx, NULL, NULL, key, nonce);
EVP_EncryptUpdate(ctx, NULL, &outlen, ad, adLen);
EVP_EncryptUpdate(ctx, buf, &outlen, msg, msgLen);
EVP_EncryptFinal_ex(ctx, buf, &outlen);
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16, buf + msgLen);
}
else
{
EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), 0, 0, 0);
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, 12, 0);
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, (uint8_t *)(msg + msgLen));
EVP_DecryptInit_ex(ctx, NULL, NULL, key, nonce);
EVP_DecryptUpdate(ctx, NULL, &outlen, ad, adLen);
EVP_DecryptUpdate(ctx, buf, &outlen, msg, msgLen);
ret = EVP_DecryptFinal_ex(ctx, buf + outlen, &outlen) > 0;
}
EVP_CIPHER_CTX_free (ctx);
#endif
return ret;
}
// init and terminate
/* std::vector <std::unique_ptr<std::mutex> > m_OpenSSLMutexes;
static void OpensslLockingCallback(int mode, int type, const char * file, int line)
{
if (type > 0 && (size_t)type < m_OpenSSLMutexes.size ())
{
if (mode & CRYPTO_LOCK)
m_OpenSSLMutexes[type]->lock ();
else
m_OpenSSLMutexes[type]->unlock ();
}
}*/
void InitCrypto (bool precomputation)
{
i2p::cpu::Detect ();
SSL_library_init ();
/* auto numLocks = CRYPTO_num_locks();
for (int i = 0; i < numLocks; i++)
m_OpenSSLMutexes.emplace_back (new std::mutex);
CRYPTO_set_locking_callback (OpensslLockingCallback);*/
if (precomputation)
{
#if defined(__x86_64__)
g_ElggTable = new BIGNUM * [ELGAMAL_FULL_EXPONENT_NUM_BYTES][255];
PrecalculateElggTable (g_ElggTable, ELGAMAL_FULL_EXPONENT_NUM_BYTES);
#else
g_ElggTable = new BIGNUM * [ELGAMAL_SHORT_EXPONENT_NUM_BYTES][255];
PrecalculateElggTable (g_ElggTable, ELGAMAL_SHORT_EXPONENT_NUM_BYTES);
#endif
}
}
void TerminateCrypto ()
{
if (g_ElggTable)
{
DestroyElggTable (g_ElggTable,
#if defined(__x86_64__)
ELGAMAL_FULL_EXPONENT_NUM_BYTES
#else
ELGAMAL_SHORT_EXPONENT_NUM_BYTES
#endif
);
delete[] g_ElggTable; g_ElggTable = nullptr;
}
/* CRYPTO_set_locking_callback (nullptr);
m_OpenSSLMutexes.clear ();*/
}
}
}
|
; A005418: Number of (n-1)-bead black-white reversible strings; also binary grids; also row sums of Losanitsch's triangle A034851; also number of caterpillar graphs on n nodes.
; Submitted by Jamie Morken(s1)
; 1,2,3,6,10,20,36,72,136,272,528,1056,2080,4160,8256,16512,32896,65792,131328,262656,524800,1049600,2098176,4196352,8390656,16781312,33558528,67117056,134225920,268451840,536887296,1073774592,2147516416,4295032832,8590000128,17180000256,34359869440,68719738880,137439215616,274878431232,549756338176,1099512676352,2199024304128,4398048608256,8796095119360,17592190238720,35184376283136,70368752566272,140737496743936,281474993487872,562949970198528,1125899940397056,2251799847239680,4503599694479360
mov $1,1
mov $3,1
lpb $0
sub $0,1
mov $2,$3
div $2,$1
mov $1,$2
mul $1,2
mul $3,2
lpe
mov $0,$1
add $3,2
add $0,$3
sub $0,2
div $0,2
|
; void *tshc_aaddr2saddr(void *aaddr)
SECTION code_clib
SECTION code_arch
PUBLIC _tshc_aaddr2saddr
EXTERN asm_tshc_aaddr2saddr
_tshc_aaddr2saddr:
pop af
pop hl
push hl
push af
jp asm_tshc_aaddr2saddr
|
//+---------------------------------------------------------------------------
//
// Microsoft Forms
// Copyright (C) Microsoft Corporation, 1996
//
// File: jsprot.cxx
//
// Contents: Implementation of the javascript: protocol
//
// History: 01-14-97 AnandRa Created
//
//----------------------------------------------------------------------------
#include "headers.hxx"
#ifndef X_FORMKRNL_HXX_
#define X_FORMKRNL_HXX_
#include "formkrnl.hxx"
#endif
#ifndef X_JSPROT_HXX_
#define X_JSPROT_HXX_
#include "jsprot.hxx"
#endif
#ifndef X_WINDOW_HXX_
#define X_WINDOW_HXX_
#include "window.hxx"
#endif
#ifndef X_OTHRGUID_H_
#define X_OTHRGUID_H_
#include "othrguid.h"
#endif
#ifndef X_ROSTM_HXX_
#define X_ROSTM_HXX_
#include "rostm.hxx"
#endif
#ifndef X_ENCODE_HXX_
#define X_ENCODE_HXX_
#include "encode.hxx"
#endif
#ifndef X_UWININET_H_
#define X_UWININET_H_
#include "uwininet.h"
#endif
#ifndef X_SCRIPT_HXX_
#define X_SCRIPT_HXX_
#include "script.hxx"
#endif
#ifndef X_HTIFRAME_H_
#define X_HTIFRAME_H_
#include <htiframe.h>
#endif
MtDefine(CJSProtocol, Protocols, "CJSProtocol")
MtDefine(JSProtResult, Protocols, "JavaScript protocol evaluation (temp)")
MtDefine(CJSProtocolParseAndBind_pbOutput, Protocols, "CJSProtocol::ParseAndBind pbOutput")
HRESULT VariantToPrintableString (VARIANT * pvar, CStr * pstr);
#define WRITTEN_SCRIPT _T("<<HTML><<SCRIPT LANGUAGE=<0s>>var __w=<1s>;if(__w!=null)document.write(__w);<</SCRIPT><</HTML>")
//+---------------------------------------------------------------------------
//
// Function: CreateJSProtocol
//
// Synopsis: Creates a javascript: Async Pluggable protocol
//
// Arguments: pUnkOuter Controlling IUnknown
//
//----------------------------------------------------------------------------
CBase *
CreateJSProtocol(IUnknown *pUnkOuter)
{
return new CJSProtocol(pUnkOuter);
}
CJSProtocolCF g_cfJSProtocol(CreateJSProtocol);
//+---------------------------------------------------------------------------
//
// Method: CJSProtocolCF::ParseUrl
//
// Synopsis: per IInternetProtocolInfo
//
//----------------------------------------------------------------------------
HRESULT
CJSProtocolCF::ParseUrl(
LPCWSTR pwzUrl,
PARSEACTION ParseAction,
DWORD dwFlags,
LPWSTR pwzResult,
DWORD cchResult,
DWORD * pcchResult,
DWORD dwReserved)
{
CStr cstr;
HRESULT hr = INET_E_DEFAULT_ACTION;
if (!pcchResult || !pwzResult)
{
hr = E_POINTER;
goto Cleanup;
}
if (ParseAction == PARSE_SECURITY_URL)
{
hr = THR(UnwrapSpecialUrl(pwzUrl, cstr));
if (hr)
goto Cleanup;
*pcchResult = cstr.Length() + 1;
if (cstr.Length() + 1 > cchResult)
{
// Not enough room
hr = S_FALSE;
goto Cleanup;
}
_tcscpy(pwzResult, cstr);
}
else
{
hr = THR_NOTRACE(super::ParseUrl(
pwzUrl,
ParseAction,
dwFlags,
pwzResult,
cchResult,
pcchResult,
dwReserved));
}
Cleanup:
RRETURN2(hr, INET_E_DEFAULT_ACTION, S_FALSE);
}
const CBase::CLASSDESC CJSProtocol::s_classdesc =
{
&CLSID_JSProtocol, // _pclsid
};
//+---------------------------------------------------------------------------
//
// Method: CJSProtocol::CJSProtocol
//
// Synopsis: ctor
//
//----------------------------------------------------------------------------
CJSProtocol::CJSProtocol(IUnknown *pUnkOuter) : super(pUnkOuter)
{
}
//+---------------------------------------------------------------------------
//
// Method: CJSProtocol::~CJSProtocol
//
// Synopsis: dtor
//
//----------------------------------------------------------------------------
CJSProtocol::~CJSProtocol()
{
}
//+---------------------------------------------------------------------------
//
// Method: CJSProtocol::ParseAndBind
//
// Synopsis: Actually perform the binding & execution of script.
//
//----------------------------------------------------------------------------
HRESULT
CJSProtocol::ParseAndBind()
{
HRESULT hr = S_OK;
TCHAR * pchScript = NULL;
ITargetFrame2 * pTF2 = NULL;
CDoc * pDoc = NULL;
IOleContainer * pOleContainer = NULL;
CVariant Var;
CStr cstrResult;
CStr cstrProtocol;
CROStmOnBuffer *prostm = NULL;
UINT uProt;
TCHAR * pchSourceUrl = NULL;
TCHAR * pchSourceUrlTmp = NULL;
long i = 1;
TCHAR * pchOutput = NULL;
BYTE * pbOutput = NULL;
long cb = 0;
// skip protocol part
pchScript = _tcschr(_cstrURL, ':');
if (!pchScript)
{
hr = MK_E_SYNTAX;
goto Cleanup;
}
hr = THR(cstrProtocol.Set(_cstrURL, pchScript - _cstrURL));
if (hr)
goto Cleanup;
// Go past the :
pchScript++;
uProt = GetUrlScheme(_cstrURL);
Assert(URL_SCHEME_VBSCRIPT == uProt ||
URL_SCHEME_JAVASCRIPT == uProt);
//
// Do the binding.
//
//
// Extract out the source url. This is appended to the
// url with a \1.
//
pchSourceUrlTmp = _tcschr(pchScript, _T('\1'));
pchSourceUrl = _tcsrchr(pchScript, _T('\1'));
// if no source url appended, get end of string.
if (!pchSourceUrlTmp)
pchSourceUrlTmp = _tcsrchr(pchScript, _T('\0'));
// just a sanity check !
Assert(pchSourceUrlTmp);
// remove any ';' from end of script code that is fed to doc.write to avoid
// syntax errors
while (*(pchSourceUrlTmp-i) == _T(';'))
i++;
*(pchSourceUrlTmp - --i) = 0;
pchSourceUrl = (pchSourceUrl && *(pchSourceUrl+1)) ? pchSourceUrl+1 : NULL;
// We can query the doc directly when we're trying to handle
// scripting in a download task for an element of the doc.
hr = THR(QueryService(
CLSID_HTMLDocument,
CLSID_HTMLDocument,
(void **)&pDoc));
if (hr)
{
// We didn't succeed, so try the old method of querying
// up to shdocvw.
hr = THR(QueryService(
IID_ITargetFrame2,
IID_ITargetFrame2,
(void **)&pTF2));
if (hr)
goto Cleanup;
hr = THR(pTF2->GetFramesContainer(&pOleContainer));
if (hr)
goto Cleanup;
if (pOleContainer)
{
//
// Found document. Execute script in its context.
//
hr = THR(pOleContainer->QueryInterface(
CLSID_HTMLDocument,
(void **)&pDoc));
if (hr)
goto Cleanup;
}
}
if (pDoc)
{
if (pDoc->_pScriptCollection)
{
//
// Only allow script to execute if security context's match
//
if (pchSourceUrl && !pDoc->AccessAllowed(pchSourceUrl))
{
hr = E_ACCESSDENIED;
goto Cleanup;
}
// Any errors from this are ignored so URLMON doesn't throw
// an exception to IE which causes them to shutdown due to an
// unexpected error. -- TerryLu.
IGNORE_HR(pDoc->_pScriptCollection->ParseScriptText(
cstrProtocol, // pchLanguage
NULL, // pMarkup
NULL, // pchType
pchScript, // pchCode
DEFAULT_OM_SCOPE, // pchItemName
NULL, // pchDelimiter
0, // ulOffset
0, // ulStartingLine
NULL, // pSourceObject
SCRIPTTEXT_ISVISIBLE | SCRIPTTEXT_ISEXPRESSION, // dwFlags
&Var, // pvarResult
NULL)); // pExcepInfo
if (V_VT(&Var) != VT_EMPTY)
{
hr = THR(VariantToPrintableString(&Var, &cstrResult));
if (hr)
goto Cleanup;
hr = THR(MemAllocString(Mt(JSProtResult), cstrResult, &pchOutput));
if (hr)
goto Cleanup;
}
else
{
//
// There was no output from the script. Since we got back
// a document from the target frame, abort now.
//
hr = E_ABORT;
}
}
}
else
{
//
// New document. Execute script in this new
// document's context.
//
#if defined(WIN16)
// BUGWIN16: need to investigate this random compiler quirkiness !!
hr = THR(Format(
FMT_OUT_ALLOC,
&pchOutput,
0,
WRITTEN_SCRIPT,
(LPCSTR)cstrProtocol,
pchScript));
#else
hr = THR(Format(
FMT_OUT_ALLOC,
&pchOutput,
0,
WRITTEN_SCRIPT,
(LPTSTR)cstrProtocol,
pchScript));
#endif
if (hr)
goto Cleanup;
}
//
// Convert string into a stream.
//
if (pchOutput)
{
cb = WideCharToMultiByte(
_bindinfo.dwCodePage,
0,
pchOutput,
-1,
NULL,
0,
NULL,
NULL);
pbOutput = new(Mt(CJSProtocolParseAndBind_pbOutput)) BYTE[cb + 1];
if (!pbOutput)
{
hr = E_OUTOFMEMORY;
goto Cleanup;
}
WideCharToMultiByte(
_bindinfo.dwCodePage,
0,
pchOutput,
-1,
(char *)pbOutput,
cb,
NULL,
NULL);
prostm = new CROStmOnBuffer();
if (!prostm)
{
hr = E_OUTOFMEMORY;
goto Cleanup;
}
hr = THR(prostm->Init(pbOutput, cb));
if (hr)
goto Cleanup;
_pStm = (IStream *)prostm;
_pStm->AddRef();
}
Cleanup:
if (!_fAborted)
{
if (!hr)
{
_bscf |= BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE;
_pProtSink->ReportData(_bscf, cb, cb);
}
if (_pProtSink)
{
_pProtSink->ReportResult(hr, 0, 0);
}
}
ReleaseInterface(pTF2);
ReleaseInterface(pOleContainer);
if (prostm)
{
prostm->Release();
}
MemFreeString(pchOutput);
delete pbOutput;
RRETURN(hr);
}
|
MOV R0, #0; // initialize result to 0
MOV R1, #1; // constant 1 for incrementing result
MOV R2, 4; // get data memory location 4
JMPZ R2, lab1; // if zero, skip next instruction
ADD R0, R0, R1; // not zero, so increment result
lab1: MOV R2, 5; // get data memory location 5
JMPZ R2, lab2; // if zero, skip next instruction
ADD R0, R0, R1; //not zero, so increment result
lab2: MOV 9, R0; // store result in data memory location 9 |
; A152031: a(n) = n^5 + n^4 + n^3 + n^2 + n.
; 0,5,62,363,1364,3905,9330,19607,37448,66429,111110,177155,271452,402233,579194,813615,1118480,1508597,2000718,2613659,3368420,4288305,5399042,6728903,8308824,10172525,12356630,14900787,17847788,21243689,25137930,29583455,34636832,40358373,46812254,54066635,62193780,71270177,81376658,92598519,105025640,118752605,133878822,150508643,168751484,188721945,210539930,234330767,260225328,288360149,318877550,351925755,387659012,426237713,467828514,512604455,560745080,612436557,667871798,727250579,790779660,858672905,931151402,1008443583,1090785344,1178420165,1271599230,1370581547,1475634068,1587031809,1705057970,1830004055,1962169992,2101864253,2249403974,2405115075,2569332380,2742399737,2924670138,3116505839,3318278480,3530369205,3753168782,3987077723,4232506404,4489875185,4759614530,5042165127,5337978008,5647514669,5971247190,6309658355,6663241772,7032501993,7417954634,7820126495,8239555680,8676791717,9132395678,9606940299
mov $2,6
mov $3,$0
lpb $2
mul $1,$3
add $1,6
sub $2,1
lpe
sub $1,6
div $1,6
mov $0,$1
|
; ******************************************************
; * move
; *****************************************************
move_player:
push ax
push dx
; load data
mov dx, [player_pos]
mov al, [key_pressed]
cmp al, MOVE_LEFT_KEY
je .left
cmp al, MOVE_RIGHT_KEY
je .right
cmp al, SHOOT_KEY
je .shoot
jmp .check
.shoot:
call create_player_bullet
jmp .check
.left:
mov al, MOVE_LEFT
call move
jmp .check
.right:
mov al, MOVE_RIGHT
call move
.check:
call check_bullet_collisions
mov [player_pos], dx
.done:
pop dx
pop ax
ret
; ******************************************************
; * render
; *****************************************************
render_player:
push ax
push dx
mov dx, [player_pos]
cmp dx, INVALID_STATE
je .done
mov al, ICON_PLAYER
mov bl, FG_CYAN
add bl, BG_BLACK
call print_object
.done:
pop dx
pop ax
ret
|
#include "pch.h"
#include "NavMenuListView.h"
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::System;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Documents;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Media::Animation;
namespace NavigationMenuSample
{
namespace Controls
{
NavMenuListView::NavMenuListView()
{
this->SelectionMode = ListViewSelectionMode::Single;
this->SingleSelectionFollowsFocus = false;
this->IsItemClickEnabled = true;
this->ItemClick += ref new ItemClickEventHandler(this, &NavMenuListView::ItemClickHandler);
// Locate the hosting SplitView control
this->Loaded += ref new Windows::UI::Xaml::RoutedEventHandler(this, &NavigationMenuSample::Controls::NavMenuListView::OnLoaded);
}
void NavMenuListView::OnLoaded(Platform::Object ^sender, Windows::UI::Xaml::RoutedEventArgs ^e)
{
auto parent = VisualTreeHelper::GetParent(this);
while (parent != nullptr && dynamic_cast<SplitView^>(parent) == nullptr)
{
parent = VisualTreeHelper::GetParent((DependencyObject^)parent);
}
if (parent != nullptr)
{
_splitViewHost = dynamic_cast<SplitView^>(parent);
_splitViewHost->RegisterPropertyChangedCallback(
SplitView::IsPaneOpenProperty,
ref new DependencyPropertyChangedCallback(this, &NavMenuListView::IsOpenPanePropertyChangedCallback));
_splitViewHost->RegisterPropertyChangedCallback(
SplitView::DisplayModeProperty,
ref new DependencyPropertyChangedCallback(this, &NavMenuListView::DisplayModePropertyChangedCallback));
// Call once to ensure we're in the correct state
OnPaneToggled();
}
}
void NavMenuListView::IsOpenPanePropertyChangedCallback(DependencyObject^ sender, DependencyProperty^ args)
{
OnPaneToggled();
}
void NavMenuListView::DisplayModePropertyChangedCallback(DependencyObject^ sender, DependencyProperty^ args)
{
OnPaneToggled();
}
void NavMenuListView::OnApplyTemplate()
{
ListView::OnApplyTemplate();
// Remove the entrance animation on the item containers.
for (int i = 0; i < (int)ItemContainerTransitions->Size; i++)
{
if (dynamic_cast<EntranceThemeTransition^>(ItemContainerTransitions->GetAt(i)) != nullptr)
{
ItemContainerTransitions->RemoveAt(i);
}
}
}
/// <summary>
/// Mark the <paramref name="item"/> as selected and ensures everything else is not.
/// If the <paramref name="item"/> is null then everything is unselected.
/// </summary>
/// <param name="item"></param>
void NavMenuListView::SetSelectedItem(ListViewItem^ item)
{
int index = -1;
if (item != nullptr)
{
index = IndexFromContainer(item);
}
for (int i = 0; i < (int)Items->Size; i++)
{
auto lvi = (ListViewItem^)ContainerFromIndex(i);
if (i != index)
{
lvi->IsSelected = false;
}
else if (i == index)
{
lvi->IsSelected = true;
}
}
}
/// <summary>
/// Custom keyboarding logic to enable movement via the arrow keys without triggering selection
/// until a 'Space' or 'Enter' key is pressed.
/// </summary>
/// <param name="e"></param>
void NavMenuListView::OnKeyDown(KeyRoutedEventArgs^ e)
{
auto focusedItem = FocusManager::GetFocusedElement();
auto shiftKeyState = CoreWindow::GetForCurrentThread()->GetKeyState(VirtualKey::Shift);
auto shiftKeyDown = (shiftKeyState & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down;
switch (e->Key)
{
case VirtualKey::Up:
this->TryMoveFocus(FocusNavigationDirection::Up);
e->Handled = true;
break;
case VirtualKey::Down:
this->TryMoveFocus(FocusNavigationDirection::Down);
e->Handled = true;
break;
case VirtualKey::Space:
case VirtualKey::Enter:
// Fire our event using the item with current keyboard focus
InvokeItem(focusedItem);
e->Handled = true;
break;
default:
ListView::OnKeyDown(e);
break;
}
}
/// <summary>
/// This method is a work-around until the bug in FocusManager.TryMoveFocus is fixed.
/// </summary>
/// <param name="direction"></param>
void NavMenuListView::TryMoveFocus(FocusNavigationDirection direction)
{
if (direction == FocusNavigationDirection::Next || direction == FocusNavigationDirection::Previous)
{
FocusManager::TryMoveFocus(direction);
}
else
{
auto control = dynamic_cast<Control^>(FocusManager::FindNextFocusableElement(direction));
if (control != nullptr)
{
control->Focus(Windows::UI::Xaml::FocusState::Programmatic);
}
}
}
void NavMenuListView::ItemClickHandler(Object^ sender, ItemClickEventArgs^ e)
{
// Triggered when the item is selected using something other than a keyboard
auto item = ContainerFromItem(e->ClickedItem);
InvokeItem(item);
}
void NavMenuListView::InvokeItem(Object^ focusedItem)
{
auto item = dynamic_cast<ListViewItem^>(focusedItem);
SetSelectedItem(item);
ItemInvoked(this, item);
if (_splitViewHost->IsPaneOpen && (
_splitViewHost->DisplayMode == SplitViewDisplayMode::CompactOverlay ||
_splitViewHost->DisplayMode == SplitViewDisplayMode::Overlay))
{
_splitViewHost->IsPaneOpen = false;
}
if (item != nullptr)
{
item->Focus(Windows::UI::Xaml::FocusState::Programmatic);
}
}
/// <summary>
/// Re-size the ListView's Panel when the SplitView is compact so the items
/// will fit within the visible space and correctly display a keyboard focus rect.
/// </summary>
void NavMenuListView::OnPaneToggled()
{
if (_splitViewHost->IsPaneOpen)
{
ItemsPanelRoot->ClearValue(FrameworkElement::WidthProperty);
ItemsPanelRoot->ClearValue(FrameworkElement::HorizontalAlignmentProperty);
}
else if (_splitViewHost->DisplayMode == SplitViewDisplayMode::CompactInline ||
_splitViewHost->DisplayMode == SplitViewDisplayMode::CompactOverlay)
{
ItemsPanelRoot->SetValue(FrameworkElement::WidthProperty, _splitViewHost->CompactPaneLength);
ItemsPanelRoot->SetValue(FrameworkElement::HorizontalAlignmentProperty, Windows::UI::Xaml::HorizontalAlignment::Left);
}
}
}
}
|
#include "selfdrive/ui/qt/widgets/cameraview.h"
#ifdef __APPLE__
#include <OpenGL/gl3.h>
#else
#include <GLES3/gl3.h>
#endif
#include <QOpenGLBuffer>
#include <QOffscreenSurface>
namespace {
const char frame_vertex_shader[] =
#ifdef __APPLE__
"#version 150 core\n"
#else
"#version 300 es\n"
#endif
"in vec4 aPosition;\n"
"in vec4 aTexCoord;\n"
"uniform mat4 uTransform;\n"
"out vec4 vTexCoord;\n"
"void main() {\n"
" gl_Position = uTransform * aPosition;\n"
" vTexCoord = aTexCoord;\n"
"}\n";
const char frame_fragment_shader[] =
#ifdef __APPLE__
"#version 150 core\n"
#else
"#version 300 es\n"
#endif
"precision mediump float;\n"
"uniform sampler2D uTexture;\n"
"in vec4 vTexCoord;\n"
"out vec4 colorOut;\n"
"void main() {\n"
" colorOut = texture(uTexture, vTexCoord.xy);\n"
#ifdef QCOM
" vec3 dz = vec3(0.0627f, 0.0627f, 0.0627f);\n"
" colorOut.rgb = ((vec3(1.0f, 1.0f, 1.0f) - dz) * colorOut.rgb / vec3(1.0f, 1.0f, 1.0f)) + dz;\n"
#endif
"}\n";
const mat4 device_transform = {{
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
}};
mat4 get_driver_view_transform(int screen_width, int screen_height, int stream_width, int stream_height) {
const float driver_view_ratio = 1.333;
mat4 transform;
if (stream_width == TICI_CAM_WIDTH) {
const float yscale = stream_height * driver_view_ratio / tici_dm_crop::width;
const float xscale = yscale*screen_height/screen_width*stream_width/stream_height;
transform = (mat4){{
xscale, 0.0, 0.0, xscale*tici_dm_crop::x_offset/stream_width*2,
0.0, yscale, 0.0, yscale*tici_dm_crop::y_offset/stream_height*2,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
}};
} else {
// frame from 4/3 to 16/9 display
transform = (mat4){{
driver_view_ratio * screen_height / screen_width, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
}};
}
return transform;
}
mat4 get_fit_view_transform(float widget_aspect_ratio, float frame_aspect_ratio) {
float zx = 1, zy = 1;
if (frame_aspect_ratio > widget_aspect_ratio) {
zy = widget_aspect_ratio / frame_aspect_ratio;
} else {
zx = frame_aspect_ratio / widget_aspect_ratio;
}
const mat4 frame_transform = {{
zx, 0.0, 0.0, 0.0,
0.0, zy, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
}};
return frame_transform;
}
} // namespace
CameraViewWidget::CameraViewWidget(std::string stream_name, VisionStreamType type, bool zoom, QWidget* parent) :
stream_name(stream_name), stream_type(type), zoomed_view(zoom), QOpenGLWidget(parent) {
setAttribute(Qt::WA_OpaquePaintEvent);
connect(this, &CameraViewWidget::vipcThreadConnected, this, &CameraViewWidget::vipcConnected, Qt::BlockingQueuedConnection);
}
CameraViewWidget::~CameraViewWidget() {
makeCurrent();
if (isValid()) {
glDeleteVertexArrays(1, &frame_vao);
glDeleteBuffers(1, &frame_vbo);
glDeleteBuffers(1, &frame_ibo);
}
doneCurrent();
}
void CameraViewWidget::initializeGL() {
initializeOpenGLFunctions();
program = std::make_unique<QOpenGLShaderProgram>(context());
bool ret = program->addShaderFromSourceCode(QOpenGLShader::Vertex, frame_vertex_shader);
assert(ret);
ret = program->addShaderFromSourceCode(QOpenGLShader::Fragment, frame_fragment_shader);
assert(ret);
program->link();
GLint frame_pos_loc = program->attributeLocation("aPosition");
GLint frame_texcoord_loc = program->attributeLocation("aTexCoord");
auto [x1, x2, y1, y2] = stream_type == VISION_STREAM_RGB_FRONT ? std::tuple(0.f, 1.f, 1.f, 0.f) : std::tuple(1.f, 0.f, 1.f, 0.f);
const uint8_t frame_indicies[] = {0, 1, 2, 0, 2, 3};
const float frame_coords[4][4] = {
{-1.0, -1.0, x2, y1}, // bl
{-1.0, 1.0, x2, y2}, // tl
{ 1.0, 1.0, x1, y2}, // tr
{ 1.0, -1.0, x1, y1}, // br
};
glGenVertexArrays(1, &frame_vao);
glBindVertexArray(frame_vao);
glGenBuffers(1, &frame_vbo);
glBindBuffer(GL_ARRAY_BUFFER, frame_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(frame_coords), frame_coords, GL_STATIC_DRAW);
glEnableVertexAttribArray(frame_pos_loc);
glVertexAttribPointer(frame_pos_loc, 2, GL_FLOAT, GL_FALSE,
sizeof(frame_coords[0]), (const void *)0);
glEnableVertexAttribArray(frame_texcoord_loc);
glVertexAttribPointer(frame_texcoord_loc, 2, GL_FLOAT, GL_FALSE,
sizeof(frame_coords[0]), (const void *)(sizeof(float) * 2));
glGenBuffers(1, &frame_ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, frame_ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(frame_indicies), frame_indicies, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
void CameraViewWidget::showEvent(QShowEvent *event) {
latest_texture_id = -1;
if (!vipc_thread) {
vipc_thread = new QThread();
connect(vipc_thread, &QThread::started, [=]() { vipcThread(); });
connect(vipc_thread, &QThread::finished, vipc_thread, &QObject::deleteLater);
vipc_thread->start();
}
}
void CameraViewWidget::hideEvent(QHideEvent *event) {
if (vipc_thread) {
vipc_thread->requestInterruption();
vipc_thread->quit();
vipc_thread->wait();
vipc_thread = nullptr;
}
}
void CameraViewWidget::updateFrameMat(int w, int h) {
if (zoomed_view) {
if (stream_type == VISION_STREAM_RGB_FRONT) {
frame_mat = matmul(device_transform, get_driver_view_transform(w, h, stream_width, stream_height));
} else {
auto intrinsic_matrix = stream_type == VISION_STREAM_RGB_WIDE ? ecam_intrinsic_matrix : fcam_intrinsic_matrix;
float zoom = ZOOM / intrinsic_matrix.v[0];
if (stream_type == VISION_STREAM_RGB_WIDE) {
zoom *= 0.5;
}
float zx = zoom * 2 * intrinsic_matrix.v[2] / width();
float zy = zoom * 2 * intrinsic_matrix.v[5] / height();
const mat4 frame_transform = {{
zx, 0.0, 0.0, 0.0,
0.0, zy, 0.0, -y_offset / height() * 2,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
}};
frame_mat = matmul(device_transform, frame_transform);
}
} else if (stream_width > 0 && stream_height > 0) {
// fit frame to widget size
float widget_aspect_ratio = (float)width() / height();
float frame_aspect_ratio = (float)stream_width / stream_height;
frame_mat = matmul(device_transform, get_fit_view_transform(widget_aspect_ratio, frame_aspect_ratio));
}
}
void CameraViewWidget::paintGL() {
glClearColor(bg.redF(), bg.greenF(), bg.blueF(), bg.alphaF());
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
if (latest_texture_id == -1) return;
glViewport(0, 0, width(), height());
glBindVertexArray(frame_vao);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture[latest_texture_id]->frame_tex);
glUseProgram(program->programId());
glUniform1i(program->uniformLocation("uTexture"), 0);
glUniformMatrix4fv(program->uniformLocation("uTransform"), 1, GL_TRUE, frame_mat.v);
assert(glGetError() == GL_NO_ERROR);
glEnableVertexAttribArray(0);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, (const void *)0);
glDisableVertexAttribArray(0);
glBindVertexArray(0);
}
void CameraViewWidget::vipcConnected(VisionIpcClient *vipc_client) {
makeCurrent();
for (int i = 0; i < vipc_client->num_buffers; i++) {
texture[i].reset(new EGLImageTexture(&vipc_client->buffers[i]));
glBindTexture(GL_TEXTURE_2D, texture[i]->frame_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// BGR
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
assert(glGetError() == GL_NO_ERROR);
}
latest_texture_id = -1;
stream_width = vipc_client->buffers[0].width;
stream_height = vipc_client->buffers[0].height;
updateFrameMat(width(), height());
}
void CameraViewWidget::vipcThread() {
VisionStreamType cur_stream_type = stream_type;
std::unique_ptr<VisionIpcClient> vipc_client;
std::unique_ptr<QOpenGLContext> ctx;
std::unique_ptr<QOffscreenSurface> surface;
std::unique_ptr<QOpenGLBuffer> gl_buffer;
if (!Hardware::EON()) {
ctx = std::make_unique<QOpenGLContext>();
ctx->setFormat(context()->format());
ctx->setShareContext(context());
ctx->create();
assert(ctx->isValid());
surface = std::make_unique<QOffscreenSurface>();
surface->setFormat(ctx->format());
surface->create();
ctx->makeCurrent(surface.get());
assert(QOpenGLContext::currentContext() == ctx.get());
initializeOpenGLFunctions();
}
while (!QThread::currentThread()->isInterruptionRequested()) {
if (!vipc_client || cur_stream_type != stream_type) {
cur_stream_type = stream_type;
vipc_client.reset(new VisionIpcClient(stream_name, cur_stream_type, true));
}
if (!vipc_client->connected) {
if (!vipc_client->connect(false)) {
QThread::msleep(100);
continue;
}
if (!Hardware::EON()) {
gl_buffer.reset(new QOpenGLBuffer(QOpenGLBuffer::PixelUnpackBuffer));
gl_buffer->create();
gl_buffer->bind();
gl_buffer->setUsagePattern(QOpenGLBuffer::StreamDraw);
gl_buffer->allocate(vipc_client->buffers[0].len);
}
emit vipcThreadConnected(vipc_client.get());
}
if (VisionBuf *buf = vipc_client->recv(nullptr, 1000)) {
if (!Hardware::EON()) {
void *texture_buffer = gl_buffer->map(QOpenGLBuffer::WriteOnly);
memcpy(texture_buffer, buf->addr, buf->len);
gl_buffer->unmap();
// copy pixels from PBO to texture object
glBindTexture(GL_TEXTURE_2D, texture[buf->idx]->frame_tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, buf->width, buf->height, GL_RGB, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);
assert(glGetError() == GL_NO_ERROR);
// use glFinish to ensure that the texture has been uploaded.
glFinish();
}
latest_texture_id = buf->idx;
// Schedule update. update() will be invoked on the gui thread.
QMetaObject::invokeMethod(this, "update");
// TODO: remove later, it's only connected by DriverView.
emit vipcThreadFrameReceived(buf);
}
}
}
|
global load_page_directory
load_page_directory:
push ebp
mov ebp, esp
mov eax, [esp + 8]
mov cr3, eax
mov esp, ebp
pop ebp
ret
global enable_paging
enable_paging:
push ebp
mov ebp, esp
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
mov esp, ebp
pop ebp
ret
|
; A189021: Apostol's second order Möbius (or Moebius) function mu_2(n).
; 1,1,1,-1,1,1,1,0,-1,1,1,-1,1,1,1,0,1,-1,1,-1,1,1,1,0,-1,1,0,-1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,-1,-1,1,1,0,-1,-1,1,-1,1,0,1,0,1,1,1,-1,1,1,-1,0,1,1,1,-1,1,1,1,0,1,1,-1,-1,1,1,1,0,0,1,1,-1,1,1,1,0,1,-1,1,-1,1,1,1,0,1,-1,-1,1
seq $0,336551 ; a(n) = A003557(n) - 1.
seq $0,8683 ; Möbius (or Moebius) function mu(n). mu(1) = 1; mu(n) = (-1)^k if n is the product of k different primes; otherwise mu(n) = 0.
|
;code by unic0rn/Asm Force
org 100h
segment .code
mov al,13h
int 10h
xor ax,ax
mov dx,03C8h
out dx,al
inc dx
xor bx,bx
pal: mov al,bl
shr al,2
mov cl,bl
and cl,0Fh
cmp cl,0Fh
jne skip
out dx,al
out dx,al
jmp cont
skip: ror ax,1
out dx,al
out dx,al
rol ax,1
cont: out dx,al
inc bl
jne pal
push 9000h
pop ds
push 0A000h
pop es
push 7000h
pop fs
push 8000h
pop gs
stars: mov si,1024
l1: cmp byte [gs:si],0
jne s11
mov di,si
shl di,4
rdtsc
xor eax,[cs:time+10]
push ax
xor ah,ah
cbw
mov [fs:di],ax
pop ax
shr ax,8
cbw
mov [fs:di+2],ax
mov dword [fs:di+4],43800000h
bswap eax
xor ah,ah
inc ax
mov [fs:di+8],ax
inc byte [gs:si]
add dword [cs:time+10],eax
s11: dec si
jne l1
mov cx,64000
l2: cmp byte [si],0
je s21
sub byte [si],17
jnc s21
mov byte [si],0
s21: inc si
loop l2
inc dword [cs:time]
mov si,1024
l3: mov di,si
shl di,4
fild word [fs:di+8]
fmul dword [cs:vm]
frndint
fld dword [fs:di+4]
fsubrp st1,st0
fst dword [fs:di+4]
;z
fild word [fs:di]
;x z
fimul word [cs:sm]
;1000*x z
fdiv st1
;1000*x/z z
fild dword [cs:time]
;time 1000*x/z z
fmul dword [cs:tm]
;time*0.0005 1000*x/z z
fcos
;cos(time*0.0005) 1000*x/z z
fld1
faddp st1,st0
;cos(time*0.0005)+1 1000*x/z z
fimul word [cs:wm]
;(cos(time*0.0005)+1)*160 1000*x/z z
faddp st1,st0
;1000*x/z+(cos(time*0.0005)+1)*160 z
fistp word [cs:time+4]
;z
fild word [fs:di+2]
;y z
fimul word [cs:sm]
;1000*y z
fdiv st1
;1000*y/z z
fild dword [cs:time]
;time 1000*x/z z
fmul dword [cs:tm]
;time*0.0005 1000*y/z z
fsin
;sin(time*0.0005) 1000*y/z z
fld1
faddp st1,st0
;sin(time*0.0005)+1 1000*y/z z
fimul word [cs:hm]
;(sin(time*0.0005)+1)*100 1000*y/z z
faddp st1,st0
;1000*y/z+(sin(time*0.0005)+1)*100 z
fistp word [cs:time+6]
;z
fistp word [cs:time+8]
;\o/
mov bx,[cs:time+4]
cmp bx,0
js s31
cmp bx,320
jnc s31
mov ax,[cs:time+6]
cmp ax,0
js s31
cmp ax,200
jnc s31
imul ax,320
add ax,bx
xchg ax,si
xor bl,bl
sub bl,[cs:time+8]
or bl,0Fh
mov [si],bl
xchg ax,si
jmp s32
s31: mov byte [gs:si],0
s32: dec si
jne l3
mov cx,64000
xor si,si
xor di,di
rep movsb
in al,60h
dec al
jnz stars
ret
vm: dd 0.008
tm: dd 0.002
sm: dw 1000
wm: dw 160
hm: dw 100
time:
|
#include<stdio.h>
#define ROW 60
#define COL 29
void fillArray(int row, int col, char arr[][COL])
{
for (col = 0; col < COL; col++)
{
for (row = 0; row < ROW; row++)
arr[row][col] = { ' ' };
}
}
void dispArray(int row, int col, char arr[][COL])
{
for (col = 0; col < COL; col++)
{
for (row = 0; row < ROW; row++)
printf("%c ", arr[row][col]);
}
}
void dispFrame(int row, int col, char arr[][COL])
{
col = 0;
row = 0;
for (col; col < COL; col++)
{
arr[0][col] = { '|' };
}
for (row; row < ROW; row++)
{
arr[row][0] = { '_' };
}
for (col = 1; col < COL; col++)
{
arr[ROW - 1][col] = { '|' };
}
for (row = 1; row < ROW - 1; row++)
{
arr[row][COL - 1] = { '_' };
}
}
int main()
{
char arr[ROW][COL], input, pen = ' ', penchar = 'M';
int col, row, posrow = 20, poscol = 8, flag = 0;
fillArray(ROW, COL, arr);
arr[posrow][poscol] = { 'I' };
dispFrame(ROW, COL, arr);
printf(" Welcome to the CMD Sketch.\n");
printf("----------------------------\n");
printf("Controls are \"w,a,s,d\".\n");
printf("Press \"q\" for pencil tool.\n");
printf("Press \"c\" to change pencil.\n");
printf("Press \"e\" for erase tool.\n");
printf("Press \"m\" for move tool.\n");
printf("Press \"k\" to save the sketch.\n");
printf("Press \"h\" for help!\n");
printf("Press any key to start.\n");
scanf("%c", &input);
dispArray(ROW, COL, arr);
do
{
scanf(" %c", &input);
if (input == 'q')
{
flag = 0;
pen = penchar;
}
else if (input == 'e')
{
flag = 0;
pen = ' ';
}
else if (input == 'm')
flag = 1;
else if (input == 'c')
{
printf("\nEnter a character to draw with: ");
scanf(" %c", &penchar);
pen = penchar;
printf("The character \"%c\" selected.\n", penchar);
}
else if (input == 'h')
{
printf("\nControls are \"w,a,s,d\".\nPress \"q\" for pencil tool.\nPress \"c\" to change pencil.\nPress \"e\" for erase tool.\nPress \"m\" for move tool.\nPress \"k\" to save the sketch.\nPress any key to continue.\n");
scanf(" %c", &input);
input = 'm';
}
else if (input == 'k')
{
arr[posrow][poscol] = { pen };
FILE *outptr = fopen("cmd_sketch.txt", "w");
for (col = 0; col < COL; col++)
{
for (row = 0; row < ROW; row++)
fprintf(outptr, "%c ", arr[row][col]);
fprintf(outptr, "\n");
}
printf("File has been saved.\nPress any key to continue.\n");
scanf(" %c", &input);
input = 'm';
fclose(outptr);
arr[posrow][poscol] = { 'I' };
}
if (input == 'w')
{
arr[posrow][poscol--] = { pen };
if (flag == 1)
pen = arr[posrow][poscol];
arr[posrow][poscol] = { 'I' };
}
else if (input == 'd')
{
arr[posrow++][poscol] = { pen };
if (flag == 1)
pen = arr[posrow][poscol];
arr[posrow][poscol] = { 'I' };
}
else if (input == 'a')
{
arr[posrow--][poscol] = { pen };
if (flag == 1)
pen = arr[posrow][poscol];
arr[posrow][poscol] = { 'I' };
}
else if (input == 's')
{
arr[posrow][poscol++] = { pen };
if (flag == 1)
pen = arr[posrow][poscol];
arr[posrow][poscol] = { 'I' };
}
dispArray(ROW, COL, arr);
dispFrame(ROW, COL, arr);
} while (input != 'exit');
return 0;
}
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1992 -- All Rights Reserved
PROJECT: PC GEOS
MODULE:
FILE: cbodyNotify.asm
AUTHOR: Chris Boyke
ROUTINES:
Name Description
---- -----------
REVISION HISTORY:
Name Date Description
---- ---- -----------
cdb 7/ 8/92 Initial version.
DESCRIPTION:
$Id: cbodyNotify.asm,v 1.1 97/04/04 17:48:17 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ChartBodyAttach
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: Set the notification OD and message
PASS: *ds:si = ChartBodyClass object
ds:di = ChartBodyClass instance data
es = segment of ChartBodyClass
RETURN:
DESTROYED: nothing
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
Inc the in-use count, so that the notification OD won't be
discarded (can't just dirty the block)
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
cdb 7/ 8/92 Initial version.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ChartBodyAttach method dynamic ChartBodyClass,
MSG_CHART_BODY_ATTACH
.enter
call ObjIncInUseCount
movdw ds:[di].CBI_notificationOD, cxdx
mov ds:[di].CBI_notificationMessage, bp
.leave
ret
ChartBodyAttach endm
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ChartBodyDetach
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION:
PASS: *ds:si = ChartBodyClass object
ds:di = ChartBodyClass instance data
es = segment of ChartBodyClass
RETURN:
DESTROYED: nothing
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
chrisb 12/21/92 Initial version.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ChartBodyDetach method dynamic ChartBodyClass,
MSG_CHART_BODY_DETACH
call ObjDecInUseCount
ret
ChartBodyDetach endm
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ChartBodyNotifyChartDeleted
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: Remove a chart from the tree
PASS: *ds:si = ChartBodyClass object
ds:di = ChartBodyClass instance data
es = segment of ChartBodyClass
^lcx:dx - child OD
RETURN: nothing
DESTROYED: ax,cx,dx,bp
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
cdb 7/ 8/92 Initial version.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ChartBodyNotifyChartDeleted method dynamic ChartBodyClass,
MSG_CHART_BODY_NOTIFY_CHART_DELETED
.enter
;
; Send our notification out that the chart is being deleted.
; This requires the VM block handle of the chart block
;
push cx, si ; chart block, body chunk handle
mov bx, cx ; chart handle
call VMMemBlockToVMBlock
mov_tr cx, ax ; VM block handle
movdw bxsi, ds:[di].CBI_notificationOD
mov ax, ds:[di].CBI_notificationMessage
tst ax
jz afterCall
mov di, mask MF_FIXUP_DS
call ObjMessage
afterCall:
pop cx, si ; chart block, body chunk handle
;
; Remove the child from the linkage
;
mov ax, offset COI_link
clr bx
call ChartBodyGetCompOffset
mov bp, mask CCF_MARK_DIRTY
call ObjCompRemoveChild
.leave
ret
ChartBodyNotifyChartDeleted endm
|
;------------------------------------------------------------------------------
;
; 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:
;
; CpuId.Asm
;
; Abstract:
;
; AsmCpuid function
;
; Notes:
;
;------------------------------------------------------------------------------
SECTION .text
;------------------------------------------------------------------------------
; VOID
; EFIAPI
; AsmCpuid (
; IN UINT32 RegisterInEax,
; OUT UINT32 *RegisterOutEax OPTIONAL,
; OUT UINT32 *RegisterOutEbx OPTIONAL,
; OUT UINT32 *RegisterOutEcx OPTIONAL,
; OUT UINT32 *RegisterOutEdx OPTIONAL
; );
;------------------------------------------------------------------------------
global ASM_PFX(AsmCpuid)
ASM_PFX(AsmCpuid):
push ebx
push ebp
mov ebp, esp
mov eax, [ebp + 12]
cpuid
push ecx
mov ecx, [ebp + 16]
jecxz .0
mov [ecx], eax
.0:
mov ecx, [ebp + 20]
jecxz .1
mov [ecx], ebx
.1:
mov ecx, [ebp + 24]
jecxz .2
pop DWORD [ecx]
.2:
mov ecx, [ebp + 28]
jecxz .3
mov [ecx], edx
.3:
mov eax, [ebp + 12]
leave
pop ebx
ret
|
; A084432: G.f.: 2/(1-x) + sum(k>=0, t^2(3-t)/(1+t)/(1-t)^2, t=x^2^k).
; 2,5,4,10,6,11,8,19,10,17,12,24,14,23,16,36,18,29,20,38,22,35,24,49,26,41,28,52,30,47,32,69,34,53,36,66,38,59,40,79,42,65,44,80,46,71,48,98,50,77,52,94,54,83,56,109,58,89,60,108,62,95,64,134,66,101
mov $2,$0
add $0,3
add $0,$2
lpb $0
add $0,1
add $1,$0
dif $0,2
lpe
div $1,2
mov $0,$1
|
copyright zengfr site:http://github.com/zengfr/romhack
001974 sub.w ($4,A0), D0 [123p+ 9C, enemy+9C]
01A74C dbra D7, $1a74a
01A75E dbra D4, $1a75c
01AAAA move.w ($4,A0), ($9c,A0) [base+1AC]
01AAB0 move.w ($8,A0), ($9e,A0) [123p+ 9C]
copyright zengfr site:http://github.com/zengfr/romhack
|
;
; Copyright (c) 2020 Phillip Stevens
;
; This Source Code Form is subject to the terms of the Mozilla Public
; License, v. 2.0. If a copy of the MPL was not distributed with this
; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;
; feilipu, August 2020
;
;-------------------------------------------------------------------------
; asm_am9511_ldiv - am9511 long divide
;-------------------------------------------------------------------------
SECTION code_clib
SECTION code_fp_am9511
EXTERN __IO_APU_CONTROL
EXTERN __IO_APU_OP_DDIV
EXTERN asm_am9511_pushl_hl
EXTERN asm_am9511_pushl_fastcall
EXTERN asm_am9511_popl
PUBLIC asm_am9511_ldiv, asm_am9511_ldiv_callee
; enter here for long divide, x/y, x on stack, y in dehl
.asm_am9511_ldiv
exx
ld hl,2
add hl,sp
call asm_am9511_pushl_hl ; x
exx
call asm_am9511_pushl_fastcall ; y
ld a,__IO_APU_OP_DDIV
out (__IO_APU_CONTROL),a ; x / y
jp asm_am9511_popl ; quotient in dehl
; enter here for long divide callee, x/y, x on stack, y in dehl
.asm_am9511_ldiv_callee
exx
pop hl ; ret
pop de
ex (sp),hl ; ret back on stack
ex de,hl
call asm_am9511_pushl_fastcall ; x
exx
call asm_am9511_pushl_fastcall ; y
ld a,__IO_APU_OP_DDIV
out (__IO_APU_CONTROL),a ; x / y
jp asm_am9511_popl ; quotient in dehl
|
;
; Copyright (c) 2006-2008 Advanced Micro Devices,Inc. ("AMD").
;
; This library is free software; you can redistribute it and/or modify
; it under the terms of the GNU Lesser General Public License as
; published by the Free Software Foundation; either version 2.1 of the
; License, or (at your option) any later version.
;
; This code is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Lesser General Public License for more details.
;
; You should have received a copy of the GNU Lesser General
; Public License along with this library; if not, write to the
; Free Software Foundation, Inc., 59 Temple Place, Suite 330,
; Boston, MA 02111-1307 USA
;
;* Function: *
;* This file library functions for accessing registers & headers
include SYSMGR.INC
include VSA2.INC
include SMIMAC.MAC
.model tiny,c
.586p
.CODE
public Function
externdef Async_VSM: dword
externdef sys_system_call:proc
Function db 0, 0, 0, 0
;***********************************************************************
; Reports a parameter error
;
; EAX = parameter
;***********************************************************************
ParamError proc
; SYS_REPORT_ERROR(ERR_BAD_PARAMETER, macro, param);
push word ptr ERR_BAD_PARAMETER
mov bh, [Function]
mov bl, 1 ; Parameter #1
push ebx ; Info1
push eax ; Info2
call sys_report_error
ret
ParamError endp
;***********************************************************************
; Validates if a macro is valid for the current message.
; Output: if "invalid macro usage"
; sys_report_error(ERR_ILLEGAL_MACRO);
; set CF
; else
; clear CF
; EBX = ptr to relevant VSM's stack
; ECX = ptr to relevant VSM's state
; NOTE: Must preserve AX
;***********************************************************************
ValidateMacro proc
mov ebx, [Async_VSM]
test ebx, ebx
jz short NotSynchronous
; Mark blocked VSM as 'Ready'
mov fs:(VSM_Header PTR [ebx]).SysStuff.RunFlag, RUN_FLAG_READY
jmp short Macro_OK
NotSynchronous:
; Always allow GET_REGISTER, GET_DESCRIPTOR & GET_HEADER
test byte ptr [Function], 1
jnz Async_Error
; Get ptr to System Manager's VSM header
mov ebx, (VSM_Header PTR [bx]).SysStuff.SysMgr_Ptr
sub ebx, SPECIAL_LOC
Macro_OK:
mov ecx, ebx
add ebx, fs:(VSM_Header PTR [ecx]).SysStuff.SavedESP
add ebx, EXTRA_SAVE
lea ecx, (VSM_Header PTR [ecx]).SysStuff.State
clc
ret
Async_Error:
; SYS_REPORT_ERROR(ERR_ILLEGAL_MACRO, macro, argument);
push word ptr ERR_ILLEGAL_MACRO
push dword ptr [Function]
movzx eax, ax
push eax
call sys_report_error
mov ax, 0FFFFh ; Return FFFFs
mov dx, ax
stc
ret
ValidateMacro endp
;***********************************************************************
; Helper routine for SYS_SET_REGISTER and SYS_SET_HEADER_DATA macros.
; Input:
; AL = offset
; EBX = base
; ECX = data
; DL = max field offset
;************************************************************ ***********
SetHeader:
mov dx, R_DR7 ; Max valid field
SetField proc
cmp al, dl ; Valid field name ?
ja short Error ; No
mov dx, ax ; Save field size
xor ah, ah ; Extract offset
movzx eax, ax
mov fs:[ebx+eax], cl ; Store data as BYTE
test dx, (DWORD_SIZE OR WORD_SIZE)
jz Exit
test dx, DWORD_SIZE ; WORD or DWORD ?
jz Set_Word
Set_Dword:
db 66h ; DWORD
Set_Word:
mov fs:[ebx+eax], cx ; WORD
clc
Exit: ret
Error: call ParamError
ret
SetField endp
;***********************************************************************
; Helper routine for SYS_GET_REGISTER and SYS_GET_HEADER_DATA macros.
; Input:
; EBX = base of structure
; AX = offset
; DX = maximum valid offset
; Output:
; DX:AX = data
;***********************************************************************
GetField proc
cmp al, dl ; Valid field name ?
ja short Error ; No, return FFFFs
mov cx, ax ; Save field size
xor ah, ah ; Extract offset
movzx eax, ax
mov eax, fs:[ebx+eax] ; Get requested value
test cx, DWORD_SIZE ; DWORD field ?
jz NotDword
mov edx, eax ; Put 16 MSBs into DX
shr edx, 16
ret
NotDword:
xor dx, dx ; Zero 16 MSBs
test cx, WORD_SIZE ; WORD field ?
jnz Exit
xor ah, ah ; BYTE field
Exit: ret
Error: call ParamError
mov ax, 0FFFFh ; Return FFFFs
mov dx, ax
ret
GetField endp
;***********************************************************************
; ULONG sys_get_register(USHORT register)
;***********************************************************************
sys_get_register proc pascal \
Register:WORD
mov ax, [Register] ; Get which register
mov [Function], GET_REG ; In case of error
call ValidateMacro ; Get ptr to registers
jc Exit
test ax, FROM_HEADER ; Is register in SMM header ?
jnz Get_Header
mov dx, R_GS
call GetField ; Get register from saved state buffer
Exit: ret
sys_get_register endp
;***********************************************************************
; void sys_set_register(USHORT register, ULONG Data)
;***********************************************************************
sys_set_register proc pascal \
Register: WORD, \
Data: DWORD
mov ax, [Register] ; Get register
mov [Function], SET_REG ; In case of error
call ValidateMacro ; Get ptr to registers
jc Exit
test ax, FROM_HEADER ; Is register in SMM header ?
jnz Set_Header
mov ecx, [Data]
mov dx, R_ESP ; Max valid register field
call SetField
Exit: ret
sys_set_register endp
;***********************************************************************
; Gets a field from the top-level SMM header
; ULONG sys_get_header_data(USHORT SMM_Field)
;***********************************************************************
sys_get_header_data proc pascal \
SMM_Field: WORD
mov ax, [SMM_Field] ; Get SMM header field
mov [Function], GET_HDR ; In case of error
call ValidateMacro
jc short Exit
mov ax, [SMM_Field] ; Get SMM header field
test ax, FROM_HEADER ; Validate field
jnz short Get_Header
call ParamError
jmp short Exit
Get_Header::
mov ebx, ecx
mov dx, R_DR7 ; Max valid field
call GetField
Exit: ret
sys_get_header_data endp
;***********************************************************************
; void sys_set_header_data(USHORT SMM_Field, ULONG Data)
;***********************************************************************
sys_set_header_data proc pascal \
SMM_Field: WORD, \
Data: DWORD
mov ax, [SMM_Field] ; Get SMM header field
mov [Function], SET_HDR ; In case of error
call ValidateMacro
jc short Exit
test ax, FROM_HEADER ; Validate field
jnz short Set_Header
call ParamError
jmp short Exit
Set_Header::
mov ebx, ecx
mov ecx, [Data]
call SetHeader
Exit: ret
sys_set_header_data endp
;***********************************************************************
; Reports an error
;***********************************************************************
sys_report_error proc pascal uses di \
Error_Code: WORD, \
Info1: DWORD, \
Info2: DWORD
mov di, [Error_Code]
mov ebx, [Info1]
mov ecx, [Info2]
mov ax, SYS_CODE_ERROR
call sys_system_call
ret
sys_report_error endp
;***********************************************************************
; void sys_return_result(ULONG Result);
;
; Implements the SYS_RETURN_RESULT macro
; Returns a byte/word/dword result to the appropriate environment
;
;***********************************************************************
sys_return_result proc pascal \
Result: DWORD
mov ebx, [Result]
; Return to another VSM's environment ?
mov ecx, [Async_VSM]
mov eax, (VSM_Header PTR ds:[0]).SysStuff.SysMgr_Ptr
xor ax, ax
cmp ecx, eax
je RetToTopLevel
; Yes, get the data size
mov dl, byte ptr fs:(VSM_Header PTR [ecx]).SysStuff.State.data_size
mov ax, R_AL
cmp dl, BYTE_IO
je SetReg
mov ax, R_AX
cmp dl, WORD_IO
je SetReg
mov ax, R_EAX
SetReg:
push ax ; Register AL/AX/EAX
push ebx ; Data
call sys_set_register
jmp Exit
RetToTopLevel:
mov ax, SYS_CODE_RESULT ; Let SysMgr return the result
call sys_system_call
Exit: ret
sys_return_result endp
END
|
#ifndef TURI_ANNOTATIONS_UTILS_HPP
#define TURI_ANNOTATIONS_UTILS_HPP
#include "build/format/cpp/annotate.pb.h"
#include "build/format/cpp/data.pb.h"
#include "build/format/cpp/message.pb.h"
#include "build/format/cpp/meta.pb.h"
#include <toolkits/image_deep_feature_extractor/image_deep_feature_extractor_toolkit.hpp>
#include <boost/regex.hpp>
#include <memory>
#include <core/data/sframe/gl_sarray.hpp>
#include <core/storage/sframe_interface/unity_sarray.hpp>
#include <vector>
namespace annotate_spec = TuriCreate::Annotation::Specification;
namespace turi {
namespace annotate {
template <typename T>
typename std::enable_if<
std::is_same<T, annotate_spec::Annotations>::value>::type
populate_parcel(annotate_spec::Parcel &parcel, T message) {
parcel.mutable_annotations()->CopyFrom(message);
}
template <typename T>
typename std::enable_if<std::is_same<T, annotate_spec::Data>::value>::type
populate_parcel(annotate_spec::Parcel &parcel, T message) {
parcel.mutable_data()->CopyFrom(message);
}
template <typename T>
typename std::enable_if<std::is_same<T, annotate_spec::MetaData>::value>::type
populate_parcel(annotate_spec::Parcel &parcel, T message) {
parcel.mutable_metadata()->CopyFrom(message);
}
template <typename T>
typename std::enable_if<
std::is_same<T, annotate_spec::ProgressMeta>::value>::type
populate_parcel(annotate_spec::Parcel &parcel, T message) {
parcel.mutable_progress()->CopyFrom(message);
}
template <typename T>
typename std::enable_if<
std::is_same<T, annotate_spec::Similarity>::value>::type
populate_parcel(annotate_spec::Parcel &parcel, T message) {
parcel.mutable_similarity()->CopyFrom(message);
}
float vectors_distance(const std::vector<double> &a,
const std::vector<double> &b);
bool is_integer(std::string s);
std::vector<flexible_type> similar_items(const gl_sarray &distances,
size_t index, size_t k);
#ifdef __APPLE__
image_deep_feature_extractor::image_deep_feature_extractor_toolkit
create_feature_extractor(std::string base_directory = "./");
gl_sarray featurize_images(const gl_sarray &images,
std::string base_directory = "./");
#endif
} // namespace annotate
} // namespace turi
#endif
|
// This file is part of fml which is released under the Boost Software
// License, Version 1.0. See accompanying file LICENSE or copy at
// https://www.boost.org/LICENSE_1_0.txt
#ifndef FML_MPI_LINALG_XPOSE_H
#define FML_MPI_LINALG_XPOSE_H
#pragma once
#include <stdexcept>
#include "../../_internals/linalgutils.hh"
#include "../mpimat.hh"
#include "internals/err.hh"
#include "internals/pblas.hh"
namespace fml
{
namespace linalg
{
/**
@brief Computes the transpose out-of-place (i.e. in a copy).
@param[in] x Input data matrix.
@param[out] tx The transpose.
@impl Uses the PBLAS function `pXtran()`.
@allocs If the output dimension is inappropriately sized, it will
automatically be re-allocated.
@except If a reallocation is triggered and fails, a `bad_alloc` exception
will be thrown.
@comm The method will communicate across all processes in the BLACS grid.
@tparam REAL should be 'float' or 'double'.
*/
template <typename REAL>
void xpose(const mpimat<REAL> &x, mpimat<REAL> &tx)
{
err::check_grid(x, tx);
const len_t m = x.nrows();
const len_t n = x.ncols();
if (m != tx.ncols() || n != tx.nrows())
tx.resize(n, m);
fml::pblas::tran(n, m, 1.f, x.data_ptr(), x.desc_ptr(), 0.f, tx.data_ptr(), tx.desc_ptr());
}
/// \overload
template <typename REAL>
mpimat<REAL> xpose(const mpimat<REAL> &x)
{
const len_t m = x.nrows();
const len_t n = x.ncols();
const grid g = x.get_grid();
mpimat<REAL> tx(g, n, m, x.bf_rows(), x.bf_cols());
xpose(x, tx);
return tx;
}
}
}
#endif
|
; A020522: a(n) = 4^n - 2^n.
; 0,2,12,56,240,992,4032,16256,65280,261632,1047552,4192256,16773120,67100672,268419072,1073709056,4294901760,17179738112,68719214592,274877382656,1099510579200,4398044413952,17592181850112,70368735789056,281474959933440,1125899873288192,4503599560261632,18014398375264256,72057593769492480,288230375614840832,1152921503533105152,4611686016279904256,18446744069414584320,73786976286248271872,295147905162172956672,1180591620683051565056,4722366482800925736960,18889465931341141901312,75557863725639445512192,302231454903107537862656,1208925819613529663078400,4835703278456317675569152,19342813113829668748787712,77371252455327471088173056,309485009821327476538736640,1237940039285345090527035392,4951760157141450730852319232,19807040628565943660897632256,79228162514264056118567239680,316912650057056787424222380032,1267650600228228275596796362752,5070602400912915354186999136256,20282409603651665920347623915520,81129638414606672688589750403072,324518553658426708768757511094272,1298074214633706871103827063341056,5192296858534827556472902291292160,20769187434139310370006797241024512,83076749736557241768257565115809792,332306998946228967649491012766662656
mov $1,2
pow $1,$0
bin $1,2
mul $1,2
mov $0,$1
|
_cd: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "stat.h"
#include "user.h"
#include "fcntl.h"
int main(int argc, char *argv[])
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 51 push %ecx
e: 83 ec 04 sub $0x4,%esp
if (argc < 2)
11: 83 39 01 cmpl $0x1,(%ecx)
{
14: 8b 41 04 mov 0x4(%ecx),%eax
if (argc < 2)
17: 7e 17 jle 30 <main+0x30>
{
printf(1, "Error, need more arguments.\n");
exit();
}
if (chdir(argv[1]) < 0)
19: 83 ec 0c sub $0xc,%esp
1c: ff 70 04 pushl 0x4(%eax)
1f: e8 7e 03 00 00 call 3a2 <chdir>
24: 83 c4 10 add $0x10,%esp
27: 85 c0 test %eax,%eax
29: 78 18 js 43 <main+0x43>
{
printf(1, "Error, cannot change the directory\n");
}
exit();
2b: e8 02 03 00 00 call 332 <exit>
printf(1, "Error, need more arguments.\n");
30: 52 push %edx
31: 52 push %edx
32: 68 d8 07 00 00 push $0x7d8
37: 6a 01 push $0x1
39: e8 42 04 00 00 call 480 <printf>
exit();
3e: e8 ef 02 00 00 call 332 <exit>
printf(1, "Error, cannot change the directory\n");
43: 50 push %eax
44: 50 push %eax
45: 68 f8 07 00 00 push $0x7f8
4a: 6a 01 push $0x1
4c: e8 2f 04 00 00 call 480 <printf>
51: 83 c4 10 add $0x10,%esp
54: eb d5 jmp 2b <main+0x2b>
56: 66 90 xchg %ax,%ax
58: 66 90 xchg %ax,%ax
5a: 66 90 xchg %ax,%ax
5c: 66 90 xchg %ax,%ax
5e: 66 90 xchg %ax,%ax
00000060 <strcpy>:
#include "x86.h"
#include "fcntl.h"
char*
strcpy(char *s, const char *t)
{
60: 55 push %ebp
61: 89 e5 mov %esp,%ebp
63: 53 push %ebx
64: 8b 45 08 mov 0x8(%ebp),%eax
67: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
6a: 89 c2 mov %eax,%edx
6c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
70: 83 c1 01 add $0x1,%ecx
73: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
77: 83 c2 01 add $0x1,%edx
7a: 84 db test %bl,%bl
7c: 88 5a ff mov %bl,-0x1(%edx)
7f: 75 ef jne 70 <strcpy+0x10>
;
return os;
}
81: 5b pop %ebx
82: 5d pop %ebp
83: c3 ret
84: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
8a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000090 <strcmp>:
int
strcmp(const char *p, const char *q)
{
90: 55 push %ebp
91: 89 e5 mov %esp,%ebp
93: 53 push %ebx
94: 8b 55 08 mov 0x8(%ebp),%edx
97: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
9a: 0f b6 02 movzbl (%edx),%eax
9d: 0f b6 19 movzbl (%ecx),%ebx
a0: 84 c0 test %al,%al
a2: 75 1c jne c0 <strcmp+0x30>
a4: eb 2a jmp d0 <strcmp+0x40>
a6: 8d 76 00 lea 0x0(%esi),%esi
a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
b0: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
b3: 0f b6 02 movzbl (%edx),%eax
p++, q++;
b6: 83 c1 01 add $0x1,%ecx
b9: 0f b6 19 movzbl (%ecx),%ebx
while(*p && *p == *q)
bc: 84 c0 test %al,%al
be: 74 10 je d0 <strcmp+0x40>
c0: 38 d8 cmp %bl,%al
c2: 74 ec je b0 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
c4: 29 d8 sub %ebx,%eax
}
c6: 5b pop %ebx
c7: 5d pop %ebp
c8: c3 ret
c9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
d0: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
d2: 29 d8 sub %ebx,%eax
}
d4: 5b pop %ebx
d5: 5d pop %ebp
d6: c3 ret
d7: 89 f6 mov %esi,%esi
d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000000e0 <strlen>:
uint
strlen(const char *s)
{
e0: 55 push %ebp
e1: 89 e5 mov %esp,%ebp
e3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
e6: 80 39 00 cmpb $0x0,(%ecx)
e9: 74 15 je 100 <strlen+0x20>
eb: 31 d2 xor %edx,%edx
ed: 8d 76 00 lea 0x0(%esi),%esi
f0: 83 c2 01 add $0x1,%edx
f3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
f7: 89 d0 mov %edx,%eax
f9: 75 f5 jne f0 <strlen+0x10>
;
return n;
}
fb: 5d pop %ebp
fc: c3 ret
fd: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
100: 31 c0 xor %eax,%eax
}
102: 5d pop %ebp
103: c3 ret
104: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
10a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000110 <memset>:
void*
memset(void *dst, int c, uint n)
{
110: 55 push %ebp
111: 89 e5 mov %esp,%ebp
113: 57 push %edi
114: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
117: 8b 4d 10 mov 0x10(%ebp),%ecx
11a: 8b 45 0c mov 0xc(%ebp),%eax
11d: 89 d7 mov %edx,%edi
11f: fc cld
120: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
122: 89 d0 mov %edx,%eax
124: 5f pop %edi
125: 5d pop %ebp
126: c3 ret
127: 89 f6 mov %esi,%esi
129: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000130 <strchr>:
char*
strchr(const char *s, char c)
{
130: 55 push %ebp
131: 89 e5 mov %esp,%ebp
133: 53 push %ebx
134: 8b 45 08 mov 0x8(%ebp),%eax
137: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
13a: 0f b6 10 movzbl (%eax),%edx
13d: 84 d2 test %dl,%dl
13f: 74 1d je 15e <strchr+0x2e>
if(*s == c)
141: 38 d3 cmp %dl,%bl
143: 89 d9 mov %ebx,%ecx
145: 75 0d jne 154 <strchr+0x24>
147: eb 17 jmp 160 <strchr+0x30>
149: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
150: 38 ca cmp %cl,%dl
152: 74 0c je 160 <strchr+0x30>
for(; *s; s++)
154: 83 c0 01 add $0x1,%eax
157: 0f b6 10 movzbl (%eax),%edx
15a: 84 d2 test %dl,%dl
15c: 75 f2 jne 150 <strchr+0x20>
return (char*)s;
return 0;
15e: 31 c0 xor %eax,%eax
}
160: 5b pop %ebx
161: 5d pop %ebp
162: c3 ret
163: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
169: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000170 <gets>:
char*
gets(char *buf, int max)
{
170: 55 push %ebp
171: 89 e5 mov %esp,%ebp
173: 57 push %edi
174: 56 push %esi
175: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
176: 31 f6 xor %esi,%esi
178: 89 f3 mov %esi,%ebx
{
17a: 83 ec 1c sub $0x1c,%esp
17d: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
180: eb 2f jmp 1b1 <gets+0x41>
182: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
188: 8d 45 e7 lea -0x19(%ebp),%eax
18b: 83 ec 04 sub $0x4,%esp
18e: 6a 01 push $0x1
190: 50 push %eax
191: 6a 00 push $0x0
193: e8 b2 01 00 00 call 34a <read>
if(cc < 1)
198: 83 c4 10 add $0x10,%esp
19b: 85 c0 test %eax,%eax
19d: 7e 1c jle 1bb <gets+0x4b>
break;
buf[i++] = c;
19f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
1a3: 83 c7 01 add $0x1,%edi
1a6: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
1a9: 3c 0a cmp $0xa,%al
1ab: 74 23 je 1d0 <gets+0x60>
1ad: 3c 0d cmp $0xd,%al
1af: 74 1f je 1d0 <gets+0x60>
for(i=0; i+1 < max; ){
1b1: 83 c3 01 add $0x1,%ebx
1b4: 3b 5d 0c cmp 0xc(%ebp),%ebx
1b7: 89 fe mov %edi,%esi
1b9: 7c cd jl 188 <gets+0x18>
1bb: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
1bd: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
1c0: c6 03 00 movb $0x0,(%ebx)
}
1c3: 8d 65 f4 lea -0xc(%ebp),%esp
1c6: 5b pop %ebx
1c7: 5e pop %esi
1c8: 5f pop %edi
1c9: 5d pop %ebp
1ca: c3 ret
1cb: 90 nop
1cc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1d0: 8b 75 08 mov 0x8(%ebp),%esi
1d3: 8b 45 08 mov 0x8(%ebp),%eax
1d6: 01 de add %ebx,%esi
1d8: 89 f3 mov %esi,%ebx
buf[i] = '\0';
1da: c6 03 00 movb $0x0,(%ebx)
}
1dd: 8d 65 f4 lea -0xc(%ebp),%esp
1e0: 5b pop %ebx
1e1: 5e pop %esi
1e2: 5f pop %edi
1e3: 5d pop %ebp
1e4: c3 ret
1e5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000001f0 <stat>:
int
stat(const char *n, struct stat *st)
{
1f0: 55 push %ebp
1f1: 89 e5 mov %esp,%ebp
1f3: 56 push %esi
1f4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
1f5: 83 ec 08 sub $0x8,%esp
1f8: 6a 00 push $0x0
1fa: ff 75 08 pushl 0x8(%ebp)
1fd: e8 70 01 00 00 call 372 <open>
if(fd < 0)
202: 83 c4 10 add $0x10,%esp
205: 85 c0 test %eax,%eax
207: 78 27 js 230 <stat+0x40>
return -1;
r = fstat(fd, st);
209: 83 ec 08 sub $0x8,%esp
20c: ff 75 0c pushl 0xc(%ebp)
20f: 89 c3 mov %eax,%ebx
211: 50 push %eax
212: e8 73 01 00 00 call 38a <fstat>
close(fd);
217: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
21a: 89 c6 mov %eax,%esi
close(fd);
21c: e8 39 01 00 00 call 35a <close>
return r;
221: 83 c4 10 add $0x10,%esp
}
224: 8d 65 f8 lea -0x8(%ebp),%esp
227: 89 f0 mov %esi,%eax
229: 5b pop %ebx
22a: 5e pop %esi
22b: 5d pop %ebp
22c: c3 ret
22d: 8d 76 00 lea 0x0(%esi),%esi
return -1;
230: be ff ff ff ff mov $0xffffffff,%esi
235: eb ed jmp 224 <stat+0x34>
237: 89 f6 mov %esi,%esi
239: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000240 <atoi>:
int
atoi(const char *s)
{
240: 55 push %ebp
241: 89 e5 mov %esp,%ebp
243: 53 push %ebx
244: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
247: 0f be 11 movsbl (%ecx),%edx
24a: 8d 42 d0 lea -0x30(%edx),%eax
24d: 3c 09 cmp $0x9,%al
n = 0;
24f: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
254: 77 1f ja 275 <atoi+0x35>
256: 8d 76 00 lea 0x0(%esi),%esi
259: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
260: 8d 04 80 lea (%eax,%eax,4),%eax
263: 83 c1 01 add $0x1,%ecx
266: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
26a: 0f be 11 movsbl (%ecx),%edx
26d: 8d 5a d0 lea -0x30(%edx),%ebx
270: 80 fb 09 cmp $0x9,%bl
273: 76 eb jbe 260 <atoi+0x20>
return n;
}
275: 5b pop %ebx
276: 5d pop %ebp
277: c3 ret
278: 90 nop
279: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000280 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
280: 55 push %ebp
281: 89 e5 mov %esp,%ebp
283: 56 push %esi
284: 53 push %ebx
285: 8b 5d 10 mov 0x10(%ebp),%ebx
288: 8b 45 08 mov 0x8(%ebp),%eax
28b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
28e: 85 db test %ebx,%ebx
290: 7e 14 jle 2a6 <memmove+0x26>
292: 31 d2 xor %edx,%edx
294: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
298: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
29c: 88 0c 10 mov %cl,(%eax,%edx,1)
29f: 83 c2 01 add $0x1,%edx
while(n-- > 0)
2a2: 39 d3 cmp %edx,%ebx
2a4: 75 f2 jne 298 <memmove+0x18>
return vdst;
}
2a6: 5b pop %ebx
2a7: 5e pop %esi
2a8: 5d pop %ebp
2a9: c3 ret
2aa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000002b0 <strcat>:
char *
strcat(char *d,const char *s)
{
2b0: 55 push %ebp
2b1: 89 e5 mov %esp,%ebp
2b3: 53 push %ebx
2b4: 8b 45 08 mov 0x8(%ebp),%eax
2b7: 8b 5d 0c mov 0xc(%ebp),%ebx
char *temp = d;
while (*d)
2ba: 80 38 00 cmpb $0x0,(%eax)
2bd: 89 c2 mov %eax,%edx
2bf: 74 28 je 2e9 <strcat+0x39>
2c1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
++d;
2c8: 83 c2 01 add $0x1,%edx
while (*d)
2cb: 80 3a 00 cmpb $0x0,(%edx)
2ce: 75 f8 jne 2c8 <strcat+0x18>
while (*s)
2d0: 0f b6 0b movzbl (%ebx),%ecx
2d3: 84 c9 test %cl,%cl
2d5: 74 19 je 2f0 <strcat+0x40>
2d7: 89 f6 mov %esi,%esi
2d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
*d++ = *s++;
2e0: 83 c2 01 add $0x1,%edx
2e3: 83 c3 01 add $0x1,%ebx
2e6: 88 4a ff mov %cl,-0x1(%edx)
while (*s)
2e9: 0f b6 0b movzbl (%ebx),%ecx
2ec: 84 c9 test %cl,%cl
2ee: 75 f0 jne 2e0 <strcat+0x30>
*d = 0;
2f0: c6 02 00 movb $0x0,(%edx)
return temp;
}
2f3: 5b pop %ebx
2f4: 5d pop %ebp
2f5: c3 ret
2f6: 8d 76 00 lea 0x0(%esi),%esi
2f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000300 <strncpy>:
char *strncpy(char *s, const char *t, int n)
{
300: 55 push %ebp
301: 89 e5 mov %esp,%ebp
303: 56 push %esi
304: 53 push %ebx
305: 8b 5d 10 mov 0x10(%ebp),%ebx
308: 8b 45 08 mov 0x8(%ebp),%eax
30b: 8b 75 0c mov 0xc(%ebp),%esi
int i;
char *os;
os = s;
for (i = 0; i < n; i++)
30e: 85 db test %ebx,%ebx
310: 7e 14 jle 326 <strncpy+0x26>
312: 31 d2 xor %edx,%edx
314: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
{
s[i] = t[i];
318: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
31c: 88 0c 10 mov %cl,(%eax,%edx,1)
for (i = 0; i < n; i++)
31f: 83 c2 01 add $0x1,%edx
322: 39 d3 cmp %edx,%ebx
324: 75 f2 jne 318 <strncpy+0x18>
}
return os;
}
326: 5b pop %ebx
327: 5e pop %esi
328: 5d pop %ebp
329: c3 ret
0000032a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
32a: b8 01 00 00 00 mov $0x1,%eax
32f: cd 40 int $0x40
331: c3 ret
00000332 <exit>:
SYSCALL(exit)
332: b8 02 00 00 00 mov $0x2,%eax
337: cd 40 int $0x40
339: c3 ret
0000033a <wait>:
SYSCALL(wait)
33a: b8 03 00 00 00 mov $0x3,%eax
33f: cd 40 int $0x40
341: c3 ret
00000342 <pipe>:
SYSCALL(pipe)
342: b8 04 00 00 00 mov $0x4,%eax
347: cd 40 int $0x40
349: c3 ret
0000034a <read>:
SYSCALL(read)
34a: b8 05 00 00 00 mov $0x5,%eax
34f: cd 40 int $0x40
351: c3 ret
00000352 <write>:
SYSCALL(write)
352: b8 10 00 00 00 mov $0x10,%eax
357: cd 40 int $0x40
359: c3 ret
0000035a <close>:
SYSCALL(close)
35a: b8 15 00 00 00 mov $0x15,%eax
35f: cd 40 int $0x40
361: c3 ret
00000362 <kill>:
SYSCALL(kill)
362: b8 06 00 00 00 mov $0x6,%eax
367: cd 40 int $0x40
369: c3 ret
0000036a <exec>:
SYSCALL(exec)
36a: b8 07 00 00 00 mov $0x7,%eax
36f: cd 40 int $0x40
371: c3 ret
00000372 <open>:
SYSCALL(open)
372: b8 0f 00 00 00 mov $0xf,%eax
377: cd 40 int $0x40
379: c3 ret
0000037a <mknod>:
SYSCALL(mknod)
37a: b8 11 00 00 00 mov $0x11,%eax
37f: cd 40 int $0x40
381: c3 ret
00000382 <unlink>:
SYSCALL(unlink)
382: b8 12 00 00 00 mov $0x12,%eax
387: cd 40 int $0x40
389: c3 ret
0000038a <fstat>:
SYSCALL(fstat)
38a: b8 08 00 00 00 mov $0x8,%eax
38f: cd 40 int $0x40
391: c3 ret
00000392 <link>:
SYSCALL(link)
392: b8 13 00 00 00 mov $0x13,%eax
397: cd 40 int $0x40
399: c3 ret
0000039a <mkdir>:
SYSCALL(mkdir)
39a: b8 14 00 00 00 mov $0x14,%eax
39f: cd 40 int $0x40
3a1: c3 ret
000003a2 <chdir>:
SYSCALL(chdir)
3a2: b8 09 00 00 00 mov $0x9,%eax
3a7: cd 40 int $0x40
3a9: c3 ret
000003aa <dup>:
SYSCALL(dup)
3aa: b8 0a 00 00 00 mov $0xa,%eax
3af: cd 40 int $0x40
3b1: c3 ret
000003b2 <getpid>:
SYSCALL(getpid)
3b2: b8 0b 00 00 00 mov $0xb,%eax
3b7: cd 40 int $0x40
3b9: c3 ret
000003ba <sbrk>:
SYSCALL(sbrk)
3ba: b8 0c 00 00 00 mov $0xc,%eax
3bf: cd 40 int $0x40
3c1: c3 ret
000003c2 <sleep>:
SYSCALL(sleep)
3c2: b8 0d 00 00 00 mov $0xd,%eax
3c7: cd 40 int $0x40
3c9: c3 ret
000003ca <uptime>:
SYSCALL(uptime)
3ca: b8 0e 00 00 00 mov $0xe,%eax
3cf: cd 40 int $0x40
3d1: c3 ret
3d2: 66 90 xchg %ax,%ax
3d4: 66 90 xchg %ax,%ax
3d6: 66 90 xchg %ax,%ax
3d8: 66 90 xchg %ax,%ax
3da: 66 90 xchg %ax,%ax
3dc: 66 90 xchg %ax,%ax
3de: 66 90 xchg %ax,%ax
000003e0 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
3e0: 55 push %ebp
3e1: 89 e5 mov %esp,%ebp
3e3: 57 push %edi
3e4: 56 push %esi
3e5: 53 push %ebx
3e6: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
3e9: 85 d2 test %edx,%edx
{
3eb: 89 45 c0 mov %eax,-0x40(%ebp)
neg = 1;
x = -xx;
3ee: 89 d0 mov %edx,%eax
if(sgn && xx < 0){
3f0: 79 76 jns 468 <printint+0x88>
3f2: f6 45 08 01 testb $0x1,0x8(%ebp)
3f6: 74 70 je 468 <printint+0x88>
x = -xx;
3f8: f7 d8 neg %eax
neg = 1;
3fa: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
} else {
x = xx;
}
i = 0;
401: 31 f6 xor %esi,%esi
403: 8d 5d d7 lea -0x29(%ebp),%ebx
406: eb 0a jmp 412 <printint+0x32>
408: 90 nop
409: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
do{
buf[i++] = digits[x % base];
410: 89 fe mov %edi,%esi
412: 31 d2 xor %edx,%edx
414: 8d 7e 01 lea 0x1(%esi),%edi
417: f7 f1 div %ecx
419: 0f b6 92 24 08 00 00 movzbl 0x824(%edx),%edx
}while((x /= base) != 0);
420: 85 c0 test %eax,%eax
buf[i++] = digits[x % base];
422: 88 14 3b mov %dl,(%ebx,%edi,1)
}while((x /= base) != 0);
425: 75 e9 jne 410 <printint+0x30>
if(neg)
427: 8b 45 c4 mov -0x3c(%ebp),%eax
42a: 85 c0 test %eax,%eax
42c: 74 08 je 436 <printint+0x56>
buf[i++] = '-';
42e: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1)
433: 8d 7e 02 lea 0x2(%esi),%edi
436: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi
43a: 8b 7d c0 mov -0x40(%ebp),%edi
43d: 8d 76 00 lea 0x0(%esi),%esi
440: 0f b6 06 movzbl (%esi),%eax
write(fd, &c, 1);
443: 83 ec 04 sub $0x4,%esp
446: 83 ee 01 sub $0x1,%esi
449: 6a 01 push $0x1
44b: 53 push %ebx
44c: 57 push %edi
44d: 88 45 d7 mov %al,-0x29(%ebp)
450: e8 fd fe ff ff call 352 <write>
while(--i >= 0)
455: 83 c4 10 add $0x10,%esp
458: 39 de cmp %ebx,%esi
45a: 75 e4 jne 440 <printint+0x60>
putc(fd, buf[i]);
}
45c: 8d 65 f4 lea -0xc(%ebp),%esp
45f: 5b pop %ebx
460: 5e pop %esi
461: 5f pop %edi
462: 5d pop %ebp
463: c3 ret
464: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
468: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
46f: eb 90 jmp 401 <printint+0x21>
471: eb 0d jmp 480 <printf>
473: 90 nop
474: 90 nop
475: 90 nop
476: 90 nop
477: 90 nop
478: 90 nop
479: 90 nop
47a: 90 nop
47b: 90 nop
47c: 90 nop
47d: 90 nop
47e: 90 nop
47f: 90 nop
00000480 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
480: 55 push %ebp
481: 89 e5 mov %esp,%ebp
483: 57 push %edi
484: 56 push %esi
485: 53 push %ebx
486: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
489: 8b 75 0c mov 0xc(%ebp),%esi
48c: 0f b6 1e movzbl (%esi),%ebx
48f: 84 db test %bl,%bl
491: 0f 84 b3 00 00 00 je 54a <printf+0xca>
ap = (uint*)(void*)&fmt + 1;
497: 8d 45 10 lea 0x10(%ebp),%eax
49a: 83 c6 01 add $0x1,%esi
state = 0;
49d: 31 ff xor %edi,%edi
ap = (uint*)(void*)&fmt + 1;
49f: 89 45 d4 mov %eax,-0x2c(%ebp)
4a2: eb 2f jmp 4d3 <printf+0x53>
4a4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
4a8: 83 f8 25 cmp $0x25,%eax
4ab: 0f 84 a7 00 00 00 je 558 <printf+0xd8>
write(fd, &c, 1);
4b1: 8d 45 e2 lea -0x1e(%ebp),%eax
4b4: 83 ec 04 sub $0x4,%esp
4b7: 88 5d e2 mov %bl,-0x1e(%ebp)
4ba: 6a 01 push $0x1
4bc: 50 push %eax
4bd: ff 75 08 pushl 0x8(%ebp)
4c0: e8 8d fe ff ff call 352 <write>
4c5: 83 c4 10 add $0x10,%esp
4c8: 83 c6 01 add $0x1,%esi
for(i = 0; fmt[i]; i++){
4cb: 0f b6 5e ff movzbl -0x1(%esi),%ebx
4cf: 84 db test %bl,%bl
4d1: 74 77 je 54a <printf+0xca>
if(state == 0){
4d3: 85 ff test %edi,%edi
c = fmt[i] & 0xff;
4d5: 0f be cb movsbl %bl,%ecx
4d8: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
4db: 74 cb je 4a8 <printf+0x28>
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
4dd: 83 ff 25 cmp $0x25,%edi
4e0: 75 e6 jne 4c8 <printf+0x48>
if(c == 'd'){
4e2: 83 f8 64 cmp $0x64,%eax
4e5: 0f 84 05 01 00 00 je 5f0 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
4eb: 81 e1 f7 00 00 00 and $0xf7,%ecx
4f1: 83 f9 70 cmp $0x70,%ecx
4f4: 74 72 je 568 <printf+0xe8>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
4f6: 83 f8 73 cmp $0x73,%eax
4f9: 0f 84 99 00 00 00 je 598 <printf+0x118>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
4ff: 83 f8 63 cmp $0x63,%eax
502: 0f 84 08 01 00 00 je 610 <printf+0x190>
putc(fd, *ap);
ap++;
} else if(c == '%'){
508: 83 f8 25 cmp $0x25,%eax
50b: 0f 84 ef 00 00 00 je 600 <printf+0x180>
write(fd, &c, 1);
511: 8d 45 e7 lea -0x19(%ebp),%eax
514: 83 ec 04 sub $0x4,%esp
517: c6 45 e7 25 movb $0x25,-0x19(%ebp)
51b: 6a 01 push $0x1
51d: 50 push %eax
51e: ff 75 08 pushl 0x8(%ebp)
521: e8 2c fe ff ff call 352 <write>
526: 83 c4 0c add $0xc,%esp
529: 8d 45 e6 lea -0x1a(%ebp),%eax
52c: 88 5d e6 mov %bl,-0x1a(%ebp)
52f: 6a 01 push $0x1
531: 50 push %eax
532: ff 75 08 pushl 0x8(%ebp)
535: 83 c6 01 add $0x1,%esi
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
538: 31 ff xor %edi,%edi
write(fd, &c, 1);
53a: e8 13 fe ff ff call 352 <write>
for(i = 0; fmt[i]; i++){
53f: 0f b6 5e ff movzbl -0x1(%esi),%ebx
write(fd, &c, 1);
543: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
546: 84 db test %bl,%bl
548: 75 89 jne 4d3 <printf+0x53>
}
}
}
54a: 8d 65 f4 lea -0xc(%ebp),%esp
54d: 5b pop %ebx
54e: 5e pop %esi
54f: 5f pop %edi
550: 5d pop %ebp
551: c3 ret
552: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
state = '%';
558: bf 25 00 00 00 mov $0x25,%edi
55d: e9 66 ff ff ff jmp 4c8 <printf+0x48>
562: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
568: 83 ec 0c sub $0xc,%esp
56b: b9 10 00 00 00 mov $0x10,%ecx
570: 6a 00 push $0x0
572: 8b 7d d4 mov -0x2c(%ebp),%edi
575: 8b 45 08 mov 0x8(%ebp),%eax
578: 8b 17 mov (%edi),%edx
57a: e8 61 fe ff ff call 3e0 <printint>
ap++;
57f: 89 f8 mov %edi,%eax
581: 83 c4 10 add $0x10,%esp
state = 0;
584: 31 ff xor %edi,%edi
ap++;
586: 83 c0 04 add $0x4,%eax
589: 89 45 d4 mov %eax,-0x2c(%ebp)
58c: e9 37 ff ff ff jmp 4c8 <printf+0x48>
591: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
598: 8b 45 d4 mov -0x2c(%ebp),%eax
59b: 8b 08 mov (%eax),%ecx
ap++;
59d: 83 c0 04 add $0x4,%eax
5a0: 89 45 d4 mov %eax,-0x2c(%ebp)
if(s == 0)
5a3: 85 c9 test %ecx,%ecx
5a5: 0f 84 8e 00 00 00 je 639 <printf+0x1b9>
while(*s != 0){
5ab: 0f b6 01 movzbl (%ecx),%eax
state = 0;
5ae: 31 ff xor %edi,%edi
s = (char*)*ap;
5b0: 89 cb mov %ecx,%ebx
while(*s != 0){
5b2: 84 c0 test %al,%al
5b4: 0f 84 0e ff ff ff je 4c8 <printf+0x48>
5ba: 89 75 d0 mov %esi,-0x30(%ebp)
5bd: 89 de mov %ebx,%esi
5bf: 8b 5d 08 mov 0x8(%ebp),%ebx
5c2: 8d 7d e3 lea -0x1d(%ebp),%edi
5c5: 8d 76 00 lea 0x0(%esi),%esi
write(fd, &c, 1);
5c8: 83 ec 04 sub $0x4,%esp
s++;
5cb: 83 c6 01 add $0x1,%esi
5ce: 88 45 e3 mov %al,-0x1d(%ebp)
write(fd, &c, 1);
5d1: 6a 01 push $0x1
5d3: 57 push %edi
5d4: 53 push %ebx
5d5: e8 78 fd ff ff call 352 <write>
while(*s != 0){
5da: 0f b6 06 movzbl (%esi),%eax
5dd: 83 c4 10 add $0x10,%esp
5e0: 84 c0 test %al,%al
5e2: 75 e4 jne 5c8 <printf+0x148>
5e4: 8b 75 d0 mov -0x30(%ebp),%esi
state = 0;
5e7: 31 ff xor %edi,%edi
5e9: e9 da fe ff ff jmp 4c8 <printf+0x48>
5ee: 66 90 xchg %ax,%ax
printint(fd, *ap, 10, 1);
5f0: 83 ec 0c sub $0xc,%esp
5f3: b9 0a 00 00 00 mov $0xa,%ecx
5f8: 6a 01 push $0x1
5fa: e9 73 ff ff ff jmp 572 <printf+0xf2>
5ff: 90 nop
write(fd, &c, 1);
600: 83 ec 04 sub $0x4,%esp
603: 88 5d e5 mov %bl,-0x1b(%ebp)
606: 8d 45 e5 lea -0x1b(%ebp),%eax
609: 6a 01 push $0x1
60b: e9 21 ff ff ff jmp 531 <printf+0xb1>
putc(fd, *ap);
610: 8b 7d d4 mov -0x2c(%ebp),%edi
write(fd, &c, 1);
613: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
616: 8b 07 mov (%edi),%eax
write(fd, &c, 1);
618: 6a 01 push $0x1
ap++;
61a: 83 c7 04 add $0x4,%edi
putc(fd, *ap);
61d: 88 45 e4 mov %al,-0x1c(%ebp)
write(fd, &c, 1);
620: 8d 45 e4 lea -0x1c(%ebp),%eax
623: 50 push %eax
624: ff 75 08 pushl 0x8(%ebp)
627: e8 26 fd ff ff call 352 <write>
ap++;
62c: 89 7d d4 mov %edi,-0x2c(%ebp)
62f: 83 c4 10 add $0x10,%esp
state = 0;
632: 31 ff xor %edi,%edi
634: e9 8f fe ff ff jmp 4c8 <printf+0x48>
s = "(null)";
639: bb 1c 08 00 00 mov $0x81c,%ebx
while(*s != 0){
63e: b8 28 00 00 00 mov $0x28,%eax
643: e9 72 ff ff ff jmp 5ba <printf+0x13a>
648: 66 90 xchg %ax,%ax
64a: 66 90 xchg %ax,%ax
64c: 66 90 xchg %ax,%ax
64e: 66 90 xchg %ax,%ax
00000650 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
650: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
651: a1 14 0b 00 00 mov 0xb14,%eax
{
656: 89 e5 mov %esp,%ebp
658: 57 push %edi
659: 56 push %esi
65a: 53 push %ebx
65b: 8b 5d 08 mov 0x8(%ebp),%ebx
bp = (Header*)ap - 1;
65e: 8d 4b f8 lea -0x8(%ebx),%ecx
661: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
668: 39 c8 cmp %ecx,%eax
66a: 8b 10 mov (%eax),%edx
66c: 73 32 jae 6a0 <free+0x50>
66e: 39 d1 cmp %edx,%ecx
670: 72 04 jb 676 <free+0x26>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
672: 39 d0 cmp %edx,%eax
674: 72 32 jb 6a8 <free+0x58>
break;
if(bp + bp->s.size == p->s.ptr){
676: 8b 73 fc mov -0x4(%ebx),%esi
679: 8d 3c f1 lea (%ecx,%esi,8),%edi
67c: 39 fa cmp %edi,%edx
67e: 74 30 je 6b0 <free+0x60>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
680: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
683: 8b 50 04 mov 0x4(%eax),%edx
686: 8d 34 d0 lea (%eax,%edx,8),%esi
689: 39 f1 cmp %esi,%ecx
68b: 74 3a je 6c7 <free+0x77>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
68d: 89 08 mov %ecx,(%eax)
freep = p;
68f: a3 14 0b 00 00 mov %eax,0xb14
}
694: 5b pop %ebx
695: 5e pop %esi
696: 5f pop %edi
697: 5d pop %ebp
698: c3 ret
699: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
6a0: 39 d0 cmp %edx,%eax
6a2: 72 04 jb 6a8 <free+0x58>
6a4: 39 d1 cmp %edx,%ecx
6a6: 72 ce jb 676 <free+0x26>
{
6a8: 89 d0 mov %edx,%eax
6aa: eb bc jmp 668 <free+0x18>
6ac: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
bp->s.size += p->s.ptr->s.size;
6b0: 03 72 04 add 0x4(%edx),%esi
6b3: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
6b6: 8b 10 mov (%eax),%edx
6b8: 8b 12 mov (%edx),%edx
6ba: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
6bd: 8b 50 04 mov 0x4(%eax),%edx
6c0: 8d 34 d0 lea (%eax,%edx,8),%esi
6c3: 39 f1 cmp %esi,%ecx
6c5: 75 c6 jne 68d <free+0x3d>
p->s.size += bp->s.size;
6c7: 03 53 fc add -0x4(%ebx),%edx
freep = p;
6ca: a3 14 0b 00 00 mov %eax,0xb14
p->s.size += bp->s.size;
6cf: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
6d2: 8b 53 f8 mov -0x8(%ebx),%edx
6d5: 89 10 mov %edx,(%eax)
}
6d7: 5b pop %ebx
6d8: 5e pop %esi
6d9: 5f pop %edi
6da: 5d pop %ebp
6db: c3 ret
6dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000006e0 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
6e0: 55 push %ebp
6e1: 89 e5 mov %esp,%ebp
6e3: 57 push %edi
6e4: 56 push %esi
6e5: 53 push %ebx
6e6: 83 ec 0c sub $0xc,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
6e9: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
6ec: 8b 15 14 0b 00 00 mov 0xb14,%edx
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
6f2: 8d 78 07 lea 0x7(%eax),%edi
6f5: c1 ef 03 shr $0x3,%edi
6f8: 83 c7 01 add $0x1,%edi
if((prevp = freep) == 0){
6fb: 85 d2 test %edx,%edx
6fd: 0f 84 9d 00 00 00 je 7a0 <malloc+0xc0>
703: 8b 02 mov (%edx),%eax
705: 8b 48 04 mov 0x4(%eax),%ecx
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
708: 39 cf cmp %ecx,%edi
70a: 76 6c jbe 778 <malloc+0x98>
70c: 81 ff 00 10 00 00 cmp $0x1000,%edi
712: bb 00 10 00 00 mov $0x1000,%ebx
717: 0f 43 df cmovae %edi,%ebx
p = sbrk(nu * sizeof(Header));
71a: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi
721: eb 0e jmp 731 <malloc+0x51>
723: 90 nop
724: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
728: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
72a: 8b 48 04 mov 0x4(%eax),%ecx
72d: 39 f9 cmp %edi,%ecx
72f: 73 47 jae 778 <malloc+0x98>
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
731: 39 05 14 0b 00 00 cmp %eax,0xb14
737: 89 c2 mov %eax,%edx
739: 75 ed jne 728 <malloc+0x48>
p = sbrk(nu * sizeof(Header));
73b: 83 ec 0c sub $0xc,%esp
73e: 56 push %esi
73f: e8 76 fc ff ff call 3ba <sbrk>
if(p == (char*)-1)
744: 83 c4 10 add $0x10,%esp
747: 83 f8 ff cmp $0xffffffff,%eax
74a: 74 1c je 768 <malloc+0x88>
hp->s.size = nu;
74c: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
74f: 83 ec 0c sub $0xc,%esp
752: 83 c0 08 add $0x8,%eax
755: 50 push %eax
756: e8 f5 fe ff ff call 650 <free>
return freep;
75b: 8b 15 14 0b 00 00 mov 0xb14,%edx
if((p = morecore(nunits)) == 0)
761: 83 c4 10 add $0x10,%esp
764: 85 d2 test %edx,%edx
766: 75 c0 jne 728 <malloc+0x48>
return 0;
}
}
768: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
76b: 31 c0 xor %eax,%eax
}
76d: 5b pop %ebx
76e: 5e pop %esi
76f: 5f pop %edi
770: 5d pop %ebp
771: c3 ret
772: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if(p->s.size == nunits)
778: 39 cf cmp %ecx,%edi
77a: 74 54 je 7d0 <malloc+0xf0>
p->s.size -= nunits;
77c: 29 f9 sub %edi,%ecx
77e: 89 48 04 mov %ecx,0x4(%eax)
p += p->s.size;
781: 8d 04 c8 lea (%eax,%ecx,8),%eax
p->s.size = nunits;
784: 89 78 04 mov %edi,0x4(%eax)
freep = prevp;
787: 89 15 14 0b 00 00 mov %edx,0xb14
}
78d: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
790: 83 c0 08 add $0x8,%eax
}
793: 5b pop %ebx
794: 5e pop %esi
795: 5f pop %edi
796: 5d pop %ebp
797: c3 ret
798: 90 nop
799: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
base.s.ptr = freep = prevp = &base;
7a0: c7 05 14 0b 00 00 18 movl $0xb18,0xb14
7a7: 0b 00 00
7aa: c7 05 18 0b 00 00 18 movl $0xb18,0xb18
7b1: 0b 00 00
base.s.size = 0;
7b4: b8 18 0b 00 00 mov $0xb18,%eax
7b9: c7 05 1c 0b 00 00 00 movl $0x0,0xb1c
7c0: 00 00 00
7c3: e9 44 ff ff ff jmp 70c <malloc+0x2c>
7c8: 90 nop
7c9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
prevp->s.ptr = p->s.ptr;
7d0: 8b 08 mov (%eax),%ecx
7d2: 89 0a mov %ecx,(%edx)
7d4: eb b1 jmp 787 <malloc+0xa7>
|
DATA SEGMENT
DIR DB 30,?,30 DUP(?),0
VIC DB 'VICTORY',0DH,0AH,'$'
FAI DB 'FAILURE',0DH,0AH,'$'
DATA ENDS
STACK SEGMENT STACK
DW 100 DUP(?)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,SS:STACK,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AH,0AH
LEA DX,DIR
INT 21H
MOV BL,DIR+1
CMP BL,0
JZ STOP
XOR BH,BH
MOV DIR[BX+2],0
MOV DX,OFFSET DIR+2
MOV AH,39H
INT 21H
JC DD
LEA DX,VIC
JMP DDD
DD: LEA DX,FAI
DDD: MOV AH,9
INT 21H
STOP: MOV AH,4CH
INT 21H
CODE ENDS
END START
|
; A131987: Representation of a dense para-sequence.
; 1,2,1,3,4,2,5,1,6,3,7,8,4,9,2,10,5,11,1,12,6,13,3,14,7,15,16,8,17,4,18,9,19,2,20,10,21,5,22,11,23,1,24,12,25,6,26,13,27,3,28,14,29,7,30,15,31,32,16,33,8,34,17,35,4,36,18,37,9,38,19,39,2,40,20,41,10,42,21,43,5,44,22,45,11,46,23,47,1,48,24,49,12,50,25,51,6,52,26,53
add $0,1
mov $2,$0
lpb $2
add $0,1
mul $2,2
trn $2,$0
lpe
lpb $0
sub $0,1
mul $0,2
dif $0,4
lpe
div $0,2
|
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "inc/CodepointWidthDetector.hpp"
namespace
{
// used to store range data in CodepointWidthDetector's internal map
struct UnicodeRange final
{
unsigned int lowerBound;
unsigned int upperBound;
CodepointWidth width;
};
static bool operator<(const UnicodeRange& range, const unsigned int searchTerm) noexcept
{
return range.upperBound < searchTerm;
}
static constexpr std::array<UnicodeRange, 342> s_wideAndAmbiguousTable{
// generated from http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt
// anything not present here is presumed to be Narrow.
//
// GH #900 - Supplemented with emoji codepoints from https://www.unicode.org/Public/13.0.0/ucd/emoji/emoji-data.txt
// Emojis in 0x2010 - 0x2B59 used to be marked as Ambiguous in GetQuickCharWidth() in order to
// force a font lookup, but since we default all Ambiguous width to Narrow, those emojis always
// came out looking squished/tiny. They've been moved into this table and marked as Wide.
//
// There are a couple of codepoints that Microsoft specifically gave an emoji representation
// even if it's not specified as an emoji in the standard. I'll list the ones I'm aware of in this comment in case
// we decide to add them in the future:
// 0x261A-0x261C, 0x261E-0x261F
// 0x2661,
// 0x2662,
// 0x2664,
// 0x2666 0x2710,
// 0x270E 0x2765 0x1f000 - 0x1f02b except 0x1f004 0x1f594
//
// *** Codepoint ranges marked with "OVR" have their given width from EastAsianWidth.txt overridden.
UnicodeRange{ 0xa1, 0xa1, CodepointWidth::Ambiguous },
UnicodeRange{ 0xa4, 0xa4, CodepointWidth::Ambiguous },
UnicodeRange{ 0xa7, 0xa8, CodepointWidth::Ambiguous },
UnicodeRange{ 0xaa, 0xaa, CodepointWidth::Ambiguous },
UnicodeRange{ 0xad, 0xae, CodepointWidth::Ambiguous },
UnicodeRange{ 0xb0, 0xb4, CodepointWidth::Ambiguous },
UnicodeRange{ 0xb6, 0xba, CodepointWidth::Ambiguous },
UnicodeRange{ 0xbc, 0xbf, CodepointWidth::Ambiguous },
UnicodeRange{ 0xc6, 0xc6, CodepointWidth::Ambiguous },
UnicodeRange{ 0xd0, 0xd0, CodepointWidth::Ambiguous },
UnicodeRange{ 0xd7, 0xd8, CodepointWidth::Ambiguous },
UnicodeRange{ 0xde, 0xe1, CodepointWidth::Ambiguous },
UnicodeRange{ 0xe6, 0xe6, CodepointWidth::Ambiguous },
UnicodeRange{ 0xe8, 0xea, CodepointWidth::Ambiguous },
UnicodeRange{ 0xec, 0xed, CodepointWidth::Ambiguous },
UnicodeRange{ 0xf0, 0xf0, CodepointWidth::Ambiguous },
UnicodeRange{ 0xf2, 0xf3, CodepointWidth::Ambiguous },
UnicodeRange{ 0xf7, 0xfa, CodepointWidth::Ambiguous },
UnicodeRange{ 0xfc, 0xfc, CodepointWidth::Ambiguous },
UnicodeRange{ 0xfe, 0xfe, CodepointWidth::Ambiguous },
UnicodeRange{ 0x101, 0x101, CodepointWidth::Ambiguous },
UnicodeRange{ 0x111, 0x111, CodepointWidth::Ambiguous },
UnicodeRange{ 0x113, 0x113, CodepointWidth::Ambiguous },
UnicodeRange{ 0x11b, 0x11b, CodepointWidth::Ambiguous },
UnicodeRange{ 0x126, 0x127, CodepointWidth::Ambiguous },
UnicodeRange{ 0x12b, 0x12b, CodepointWidth::Ambiguous },
UnicodeRange{ 0x131, 0x133, CodepointWidth::Ambiguous },
UnicodeRange{ 0x138, 0x138, CodepointWidth::Ambiguous },
UnicodeRange{ 0x13f, 0x142, CodepointWidth::Ambiguous },
UnicodeRange{ 0x144, 0x144, CodepointWidth::Ambiguous },
UnicodeRange{ 0x148, 0x14b, CodepointWidth::Ambiguous },
UnicodeRange{ 0x14d, 0x14d, CodepointWidth::Ambiguous },
UnicodeRange{ 0x152, 0x153, CodepointWidth::Ambiguous },
UnicodeRange{ 0x166, 0x167, CodepointWidth::Ambiguous },
UnicodeRange{ 0x16b, 0x16b, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1ce, 0x1ce, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1d0, 0x1d0, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1d2, 0x1d2, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1d4, 0x1d4, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1d6, 0x1d6, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1d8, 0x1d8, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1da, 0x1da, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1dc, 0x1dc, CodepointWidth::Ambiguous },
UnicodeRange{ 0x251, 0x251, CodepointWidth::Ambiguous },
UnicodeRange{ 0x261, 0x261, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2c4, 0x2c4, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2c7, 0x2c7, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2c9, 0x2cb, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2cd, 0x2cd, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2d0, 0x2d0, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2d8, 0x2db, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2dd, 0x2dd, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2df, 0x2df, CodepointWidth::Ambiguous },
UnicodeRange{ 0x300, 0x36f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x391, 0x3a1, CodepointWidth::Ambiguous },
UnicodeRange{ 0x3a3, 0x3a9, CodepointWidth::Ambiguous },
UnicodeRange{ 0x3b1, 0x3c1, CodepointWidth::Ambiguous },
UnicodeRange{ 0x3c3, 0x3c9, CodepointWidth::Ambiguous },
UnicodeRange{ 0x401, 0x401, CodepointWidth::Ambiguous },
UnicodeRange{ 0x410, 0x44f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x451, 0x451, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1100, 0x115f, CodepointWidth::Wide },
UnicodeRange{ 0x2010, 0x2010, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2013, 0x2016, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2018, 0x2019, CodepointWidth::Ambiguous },
UnicodeRange{ 0x201c, 0x201d, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2020, 0x2022, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2024, 0x2027, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2030, 0x2030, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2032, 0x2033, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2035, 0x2035, CodepointWidth::Ambiguous },
UnicodeRange{ 0x203b, 0x203b, CodepointWidth::Ambiguous },
UnicodeRange{ 0x203e, 0x203e, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2074, 0x2074, CodepointWidth::Ambiguous },
UnicodeRange{ 0x207f, 0x207f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2081, 0x2084, CodepointWidth::Ambiguous },
UnicodeRange{ 0x20ac, 0x20ac, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2103, 0x2103, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2105, 0x2105, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2109, 0x2109, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2113, 0x2113, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2116, 0x2116, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2121, 0x2122, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2126, 0x2126, CodepointWidth::Ambiguous },
UnicodeRange{ 0x212b, 0x212b, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2139, 0x2139, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2153, 0x2154, CodepointWidth::Ambiguous },
UnicodeRange{ 0x215b, 0x215e, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2160, 0x216b, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2170, 0x2179, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2189, 0x2189, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2190, 0x2199, CodepointWidth::Ambiguous },
UnicodeRange{ 0x21b8, 0x21b9, CodepointWidth::Ambiguous },
UnicodeRange{ 0x21d2, 0x21d2, CodepointWidth::Ambiguous },
UnicodeRange{ 0x21d4, 0x21d4, CodepointWidth::Ambiguous },
UnicodeRange{ 0x21e7, 0x21e7, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2200, 0x2200, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2202, 0x2203, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2207, 0x2208, CodepointWidth::Ambiguous },
UnicodeRange{ 0x220b, 0x220b, CodepointWidth::Ambiguous },
UnicodeRange{ 0x220f, 0x220f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2211, 0x2211, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2215, 0x2215, CodepointWidth::Ambiguous },
UnicodeRange{ 0x221a, 0x221a, CodepointWidth::Ambiguous },
UnicodeRange{ 0x221d, 0x2220, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2223, 0x2223, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2225, 0x2225, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2227, 0x222c, CodepointWidth::Ambiguous },
UnicodeRange{ 0x222e, 0x222e, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2234, 0x2237, CodepointWidth::Ambiguous },
UnicodeRange{ 0x223c, 0x223d, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2248, 0x2248, CodepointWidth::Ambiguous },
UnicodeRange{ 0x224c, 0x224c, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2252, 0x2252, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2260, 0x2261, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2264, 0x2267, CodepointWidth::Ambiguous },
UnicodeRange{ 0x226a, 0x226b, CodepointWidth::Ambiguous },
UnicodeRange{ 0x226e, 0x226f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2282, 0x2283, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2286, 0x2287, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2295, 0x2295, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2299, 0x2299, CodepointWidth::Ambiguous },
UnicodeRange{ 0x22a5, 0x22a5, CodepointWidth::Ambiguous },
UnicodeRange{ 0x22bf, 0x22bf, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2312, 0x2312, CodepointWidth::Ambiguous },
UnicodeRange{ 0x231a, 0x231b, CodepointWidth::Wide },
UnicodeRange{ 0x2328, 0x232a, CodepointWidth::Wide }, // OVR 328
UnicodeRange{ 0x23cf, 0x23cf, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x23e9, 0x23ef, CodepointWidth::Wide }, // OVR 3ed-3ef
UnicodeRange{ 0x23f0, 0x23f3, CodepointWidth::Wide }, // OVR 3f1-3f2
UnicodeRange{ 0x23f8, 0x23fa, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2460, 0x24c1, CodepointWidth::Ambiguous },
UnicodeRange{ 0x24c2, 0x24c2, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x24c3, 0x24e9, CodepointWidth::Ambiguous },
UnicodeRange{ 0x24eb, 0x254b, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2550, 0x2573, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2580, 0x258f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2592, 0x2595, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25a0, 0x25a1, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25a3, 0x25a9, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25aa, 0x25ab, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x25b2, 0x25b3, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25b6, 0x25b7, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25bc, 0x25bd, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25c0, 0x25c1, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25c6, 0x25c8, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25cb, 0x25cb, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25ce, 0x25d1, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25e2, 0x25e5, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25ef, 0x25ef, CodepointWidth::Ambiguous },
UnicodeRange{ 0x25fb, 0x25fe, CodepointWidth::Wide }, // OVR 5fb-5fc
UnicodeRange{ 0x2600, 0x2604, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2605, 0x2606, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2609, 0x2609, CodepointWidth::Ambiguous },
UnicodeRange{ 0x260e, 0x260e, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x260e, 0x260f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2611, 0x2611, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2614, 0x2615, CodepointWidth::Wide },
UnicodeRange{ 0x2618, 0x2618, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x261d, 0x261d, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2620, 0x2620, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2622, 0x2623, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2626, 0x2626, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x262a, 0x262a, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x262e, 0x262f, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2638, 0x263a, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2640, 0x2640, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2642, 0x2642, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2648, 0x2653, CodepointWidth::Wide },
UnicodeRange{ 0x265f, 0x2660, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2663, 0x2663, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2665, 0x2666, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2668, 0x2668, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2669, 0x266a, CodepointWidth::Ambiguous },
UnicodeRange{ 0x266c, 0x266d, CodepointWidth::Ambiguous },
UnicodeRange{ 0x266f, 0x266f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x267b, 0x267b, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x267e, 0x267f, CodepointWidth::Wide }, // OVR 67e
UnicodeRange{ 0x2692, 0x2697, CodepointWidth::Wide }, // OVR 692, 694-697
UnicodeRange{ 0x2699, 0x2699, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x269b, 0x269c, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x269e, 0x269f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26a0, 0x26a1, CodepointWidth::Wide }, // OVR 6a0
UnicodeRange{ 0x26a7, 0x26a7, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x26aa, 0x26ab, CodepointWidth::Wide },
UnicodeRange{ 0x26b0, 0x26b1, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x26bd, 0x26be, CodepointWidth::Wide },
UnicodeRange{ 0x26bf, 0x26bf, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26c4, 0x26c5, CodepointWidth::Wide },
UnicodeRange{ 0x26c6, 0x26c7, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26c8, 0x26c8, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x26c9, 0x26cd, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26ce, 0x26cf, CodepointWidth::Wide }, // OVR 6CF
UnicodeRange{ 0x26d0, 0x26d0, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26d1, 0x26d1, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x26d2, 0x26d2, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26d3, 0x26d4, CodepointWidth::Wide }, // OVR 6d3
UnicodeRange{ 0x26d5, 0x26e1, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26e3, 0x26e3, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26e8, 0x26e8, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26e9, 0x26ea, CodepointWidth::Wide }, // OVR 6e9
UnicodeRange{ 0x26eb, 0x26ef, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26f0, 0x26f5, CodepointWidth::Wide }, // OVR 6f0-6f1, 6f4
UnicodeRange{ 0x26f6, 0x26f6, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26f7, 0x26fa, CodepointWidth::Wide }, // OVR 6f8-6f9
UnicodeRange{ 0x26fb, 0x26fc, CodepointWidth::Ambiguous },
UnicodeRange{ 0x26fd, 0x26fd, CodepointWidth::Wide },
UnicodeRange{ 0x26fe, 0x26ff, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2702, 0x2702, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2705, 0x2705, CodepointWidth::Wide },
UnicodeRange{ 0x2708, 0x270d, CodepointWidth::Wide }, // OVR 708-709, 70c-70d
UnicodeRange{ 0x270f, 0x270f, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2712, 0x2712, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2714, 0x2714, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2716, 0x2716, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x271d, 0x271d, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2721, 0x2721, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2728, 0x2728, CodepointWidth::Wide },
UnicodeRange{ 0x2733, 0x2734, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x273d, 0x273d, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2744, 0x2744, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2747, 0x2747, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x274c, 0x274c, CodepointWidth::Wide },
UnicodeRange{ 0x274e, 0x274e, CodepointWidth::Wide },
UnicodeRange{ 0x2753, 0x2755, CodepointWidth::Wide },
UnicodeRange{ 0x2757, 0x2757, CodepointWidth::Wide },
UnicodeRange{ 0x2763, 0x2764, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x2776, 0x277f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2795, 0x2797, CodepointWidth::Wide },
UnicodeRange{ 0x27a1, 0x27a1, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x27b0, 0x27b0, CodepointWidth::Wide },
UnicodeRange{ 0x27bf, 0x27bf, CodepointWidth::Wide },
UnicodeRange{ 0x2b1b, 0x2b1c, CodepointWidth::Wide },
UnicodeRange{ 0x2b50, 0x2b50, CodepointWidth::Wide },
UnicodeRange{ 0x2b55, 0x2b55, CodepointWidth::Wide },
UnicodeRange{ 0x2b56, 0x2b59, CodepointWidth::Ambiguous },
UnicodeRange{ 0x2e80, 0x2e99, CodepointWidth::Wide },
UnicodeRange{ 0x2e9b, 0x2ef3, CodepointWidth::Wide },
UnicodeRange{ 0x2f00, 0x2fd5, CodepointWidth::Wide },
UnicodeRange{ 0x2ff0, 0x2ffb, CodepointWidth::Wide },
UnicodeRange{ 0x3000, 0x303e, CodepointWidth::Wide },
UnicodeRange{ 0x3041, 0x3096, CodepointWidth::Wide },
UnicodeRange{ 0x3099, 0x30ff, CodepointWidth::Wide },
UnicodeRange{ 0x3105, 0x312e, CodepointWidth::Wide },
UnicodeRange{ 0x3131, 0x318e, CodepointWidth::Wide },
UnicodeRange{ 0x3190, 0x31ba, CodepointWidth::Wide },
UnicodeRange{ 0x31c0, 0x31e3, CodepointWidth::Wide },
UnicodeRange{ 0x31f0, 0x321e, CodepointWidth::Wide },
UnicodeRange{ 0x3220, 0x3247, CodepointWidth::Wide },
UnicodeRange{ 0x3248, 0x324f, CodepointWidth::Ambiguous },
UnicodeRange{ 0x3250, 0x32fe, CodepointWidth::Wide },
UnicodeRange{ 0x3300, 0x4dbf, CodepointWidth::Wide },
UnicodeRange{ 0x4e00, 0xa48c, CodepointWidth::Wide },
UnicodeRange{ 0xa490, 0xa4c6, CodepointWidth::Wide },
UnicodeRange{ 0xa960, 0xa97c, CodepointWidth::Wide },
UnicodeRange{ 0xac00, 0xd7a3, CodepointWidth::Wide },
UnicodeRange{ 0xe000, 0xf8ff, CodepointWidth::Ambiguous },
UnicodeRange{ 0xf900, 0xfaff, CodepointWidth::Wide },
UnicodeRange{ 0xfe00, 0xfe0f, CodepointWidth::Ambiguous },
UnicodeRange{ 0xfe10, 0xfe19, CodepointWidth::Wide },
UnicodeRange{ 0xfe30, 0xfe52, CodepointWidth::Wide },
UnicodeRange{ 0xfe54, 0xfe66, CodepointWidth::Wide },
UnicodeRange{ 0xfe68, 0xfe6b, CodepointWidth::Wide },
UnicodeRange{ 0xff01, 0xff60, CodepointWidth::Wide },
UnicodeRange{ 0xffe0, 0xffe6, CodepointWidth::Wide },
UnicodeRange{ 0xfffd, 0xfffd, CodepointWidth::Ambiguous },
UnicodeRange{ 0x16fe0, 0x16fe1, CodepointWidth::Wide },
UnicodeRange{ 0x17000, 0x187ec, CodepointWidth::Wide },
UnicodeRange{ 0x18800, 0x18af2, CodepointWidth::Wide },
UnicodeRange{ 0x1b000, 0x1b11e, CodepointWidth::Wide },
UnicodeRange{ 0x1b170, 0x1b2fb, CodepointWidth::Wide },
UnicodeRange{ 0x1f004, 0x1f004, CodepointWidth::Wide },
UnicodeRange{ 0x1f0cf, 0x1f0cf, CodepointWidth::Wide },
UnicodeRange{ 0x1f100, 0x1f10a, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1f110, 0x1f12d, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1f130, 0x1f169, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1f170, 0x1f171, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f172, 0x1f17d, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1f17e, 0x1f17f, CodepointWidth::Wide }, // OVR 17f
UnicodeRange{ 0x1f180, 0x1f18d, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1f18e, 0x1f18e, CodepointWidth::Wide },
UnicodeRange{ 0x1f18f, 0x1f190, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1f191, 0x1f19a, CodepointWidth::Wide },
UnicodeRange{ 0x1f19b, 0x1f1ac, CodepointWidth::Ambiguous },
UnicodeRange{ 0x1f1e6, 0x1f1ff, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f200, 0x1f202, CodepointWidth::Wide },
UnicodeRange{ 0x1f210, 0x1f23b, CodepointWidth::Wide },
UnicodeRange{ 0x1f240, 0x1f248, CodepointWidth::Wide },
UnicodeRange{ 0x1f250, 0x1f251, CodepointWidth::Wide },
UnicodeRange{ 0x1f260, 0x1f265, CodepointWidth::Wide },
UnicodeRange{ 0x1f300, 0x1f321, CodepointWidth::Wide }, // OVR 321
UnicodeRange{ 0x1f324, 0x1f393, CodepointWidth::Wide }, // OVR 324-32c, 336, 37d
UnicodeRange{ 0x1f396, 0x1f397, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f399, 0x1f39b, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f39e, 0x1f39f, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f3a0, 0x1f3f0, CodepointWidth::Wide }, // OVR 3cb-3ce, 3d4-3df
UnicodeRange{ 0x1f3f3, 0x1f3f5, CodepointWidth::Wide }, // OVR 3f3, 3f5
UnicodeRange{ 0x1f3f7, 0x1f4fd, CodepointWidth::Wide }, // OVR 3f7, 43f, 4fd
UnicodeRange{ 0x1f4ff, 0x1f53d, CodepointWidth::Wide },
UnicodeRange{ 0x1f549, 0x1f54e, CodepointWidth::Wide }, // OVR 549-54a
UnicodeRange{ 0x1f550, 0x1f567, CodepointWidth::Wide },
UnicodeRange{ 0x1f56f, 0x1f570, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f573, 0x1f57a, CodepointWidth::Wide }, // OVR 573-579
UnicodeRange{ 0x1f587, 0x1f587, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f58a, 0x1f58d, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f590, 0x1f590, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f595, 0x1f596, CodepointWidth::Wide },
UnicodeRange{ 0x1f5a4, 0x1f5a5, CodepointWidth::Wide }, // OVR 5a5
UnicodeRange{ 0x1f5a8, 0x1f5a8, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5b1, 0x1f5b2, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5bc, 0x1f5bc, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5c2, 0x1f5c4, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5d1, 0x1f5d3, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5dc, 0x1f5de, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5e1, 0x1f5e1, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5e3, 0x1f5e3, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5e8, 0x1f5e8, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5ef, 0x1f5ef, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5f3, 0x1f5f3, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f5fa, 0x1f64f, CodepointWidth::Wide }, // OVR 5fa
UnicodeRange{ 0x1f680, 0x1f6c5, CodepointWidth::Wide },
UnicodeRange{ 0x1f6cb, 0x1f6d2, CodepointWidth::Wide }, // OVR 6cb, 6cd-6cf
UnicodeRange{ 0x1f6d5, 0x1f6d7, CodepointWidth::Wide },
UnicodeRange{ 0x1f6e0, 0x1f6e5, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f6e9, 0x1f6e9, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f6eb, 0x1f6ec, CodepointWidth::Wide },
UnicodeRange{ 0x1f6f0, 0x1f6f0, CodepointWidth::Wide }, // OVR
UnicodeRange{ 0x1f6f3, 0x1f6fc, CodepointWidth::Wide }, // OVR 6f3
UnicodeRange{ 0x1f7e0, 0x1f7eb, CodepointWidth::Wide },
UnicodeRange{ 0x1f90c, 0x1f9ff, CodepointWidth::Wide }, // OVR 93b, 946
UnicodeRange{ 0x1fa70, 0x1fa74, CodepointWidth::Wide },
UnicodeRange{ 0x1fa78, 0x1fa7a, CodepointWidth::Wide },
UnicodeRange{ 0x1fa80, 0x1fa86, CodepointWidth::Wide },
UnicodeRange{ 0x1fa90, 0x1faa8, CodepointWidth::Wide },
UnicodeRange{ 0x1fab0, 0x1fab6, CodepointWidth::Wide },
UnicodeRange{ 0x1fac0, 0x1fac2, CodepointWidth::Wide },
UnicodeRange{ 0x1fad0, 0x1fad6, CodepointWidth::Wide },
UnicodeRange{ 0x20000, 0x2fffd, CodepointWidth::Wide },
UnicodeRange{ 0x30000, 0x3fffd, CodepointWidth::Wide },
UnicodeRange{ 0xe0100, 0xe01ef, CodepointWidth::Ambiguous },
UnicodeRange{ 0xf0000, 0xffffd, CodepointWidth::Ambiguous },
UnicodeRange{ 0x100000, 0x10fffd, CodepointWidth::Ambiguous }
};
}
// Routine Description:
// - Constructs an instance of the CodepointWidthDetector class
CodepointWidthDetector::CodepointWidthDetector() noexcept :
_fallbackCache{},
_pfnFallbackMethod{}
{
}
// Routine Description:
// - returns the width type of codepoint as fast as we can by using quick lookup table and fallback cache.
// Arguments:
// - glyph - the utf16 encoded codepoint to search for
// Return Value:
// - the width type of the codepoint
CodepointWidth CodepointWidthDetector::GetWidth(const std::wstring_view glyph) const
{
THROW_HR_IF(E_INVALIDARG, glyph.empty());
if (glyph.size() == 1)
{
// We first attempt to look at our custom quick lookup table of char width preferences.
const auto width = GetQuickCharWidth(glyph.front());
// If it's invalid, the quick width had no opinion, so go to the lookup table.
if (width == CodepointWidth::Invalid)
{
return _lookupGlyphWidthWithCache(glyph);
}
// If it's ambiguous, the quick width wanted us to ask the font directly, try that if we can.
// If not, go to the lookup table.
else if (width == CodepointWidth::Ambiguous)
{
if (_pfnFallbackMethod)
{
return _checkFallbackViaCache(glyph) ? CodepointWidth::Wide : CodepointWidth::Ambiguous;
}
else
{
return _lookupGlyphWidthWithCache(glyph);
}
}
// Otherwise, return Width as it is.
else
{
return width;
}
}
else
{
return _lookupGlyphWidthWithCache(glyph);
}
}
// Routine Description:
// - checks if wch is wide. will attempt to fallback as much possible until an answer is determined
// Arguments:
// - wch - the wchar to check width of
// Return Value:
// - true if wch is wide
bool CodepointWidthDetector::IsWide(const wchar_t wch) const noexcept
{
try
{
return IsWide({ &wch, 1 });
}
CATCH_LOG();
return true;
}
// Routine Description:
// - checks if codepoint is wide. will attempt to fallback as much possible until an answer is determined
// Arguments:
// - glyph - the utf16 encoded codepoint to check width of
// Return Value:
// - true if codepoint is wide
bool CodepointWidthDetector::IsWide(const std::wstring_view glyph) const
{
return GetWidth(glyph) == CodepointWidth::Wide;
}
// Routine Description:
// - returns the width type of codepoint by searching the map generated from the unicode spec
// Arguments:
// - glyph - the utf16 encoded codepoint to search for
// Return Value:
// - the width type of the codepoint
CodepointWidth CodepointWidthDetector::_lookupGlyphWidth(const std::wstring_view glyph) const
{
if (glyph.empty())
{
return CodepointWidth::Invalid;
}
const auto codepoint = _extractCodepoint(glyph);
const auto it = std::lower_bound(s_wideAndAmbiguousTable.begin(), s_wideAndAmbiguousTable.end(), codepoint);
// For characters that are not _in_ the table, lower_bound will return the nearest item that is.
// We must check its bounds to make sure that our hit was a true hit.
if (it != s_wideAndAmbiguousTable.end() && codepoint >= it->lowerBound && codepoint <= it->upperBound)
{
return it->width;
}
return CodepointWidth::Narrow;
}
// Routine Description:
// - returns the width type of codepoint using fallback methods.
// Arguments:
// - glyph - the utf16 encoded codepoint to check width of
// Return Value:
// - the width type of the codepoint
CodepointWidth CodepointWidthDetector::_lookupGlyphWidthWithCache(const std::wstring_view glyph) const noexcept
{
try
{
// Use our generated table to try to lookup the width based on the Unicode standard.
const CodepointWidth width = _lookupGlyphWidth(glyph);
// If it's ambiguous, then ask the font if we can.
if (width == CodepointWidth::Ambiguous)
{
if (_pfnFallbackMethod)
{
return _checkFallbackViaCache(glyph) ? CodepointWidth::Wide : CodepointWidth::Ambiguous;
}
else
{
return CodepointWidth::Ambiguous;
}
}
// If it's not ambiguous, it should say wide or narrow.
else
{
return width;
}
}
CATCH_LOG();
// If we got this far, we couldn't figure it out.
// It's better to be too wide than too narrow.
return CodepointWidth::Wide;
}
// Routine Description:
// - Checks the fallback function but caches the results until the font changes
// because the lookup function is usually very expensive and will return the same results
// for the same inputs.
// Arguments:
// - glyph - the utf16 encoded codepoint to check width of
// - true if codepoint is wide or false if it is narrow
bool CodepointWidthDetector::_checkFallbackViaCache(const std::wstring_view glyph) const
{
const std::wstring findMe{ glyph };
// TODO: Cache needs to be emptied when font changes.
const auto it = _fallbackCache.find(findMe);
if (it == _fallbackCache.end())
{
auto result = _pfnFallbackMethod(glyph);
_fallbackCache.insert_or_assign(findMe, result);
return result;
}
else
{
return it->second;
}
}
// Routine Description:
// - extract unicode codepoint from utf16 encoding
// Arguments:
// - glyph - the utf16 encoded codepoint convert
// Return Value:
// - the codepoint being stored
unsigned int CodepointWidthDetector::_extractCodepoint(const std::wstring_view glyph) noexcept
{
if (glyph.size() == 1)
{
return static_cast<unsigned int>(glyph.front());
}
else
{
const unsigned int mask = 0x3FF;
// leading bits, shifted over to make space for trailing bits
unsigned int codepoint = (glyph.at(0) & mask) << 10;
// trailing bits
codepoint |= (glyph.at(1) & mask);
// 0x10000 is subtracted from the codepoint to encode a surrogate pair, add it back
codepoint += 0x10000;
return codepoint;
}
}
// Method Description:
// - Sets a function that should be used as the fallback mechanism for
// determining a particular glyph's width, should the glyph be an ambiguous
// width.
// A Terminal could hook in a Renderer's IsGlyphWideByFont method as the
// fallback to ask the renderer for the glyph's width (for example).
// Arguments:
// - pfnFallback - the function to use as the fallback method.
// Return Value:
// - <none>
void CodepointWidthDetector::SetFallbackMethod(std::function<bool(const std::wstring_view)> pfnFallback)
{
_pfnFallbackMethod = pfnFallback;
}
// Method Description:
// - Resets the internal ambiguous character width cache mechanism
// since it will be different when the font changes and we should
// re-query the new font for that information.
// Arguments:
// - <none>
// Return Value:
// - <none>
void CodepointWidthDetector::NotifyFontChanged() const noexcept
{
_fallbackCache.clear();
}
|
; ===============================================================
; Jan 2015
; ===============================================================
;
; char *strnset(char *s, int c, size_t n)
;
; Write at most n chars c into s.
;
; ===============================================================
SECTION code_clib
SECTION code_string
PUBLIC asm_strnset
asm_strnset:
; enter : hl = char *s
; e = int c
; bc = size_t n
;
; exit : hl = char *s
; bc = remaining n
;
; uses : af, bc
ld a,b
or c
ret z
push hl
xor a
loop:
cp (hl)
jr z, exit
ld (hl),e
IF __CPU_GBZ80__
EXTERN __z80asm__cpi
call __z80asm__cpi
ld a,b
or c
ld a,0
jr nz,loop
ELSE
cpi ; hl++, bc--
jp pe, loop
ENDIF
exit:
pop hl
ret
|
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "contrib_ops/cpu/cpu_contrib_kernels.h"
#include "core/graph/constants.h"
#include "core/mlas/inc/mlas.h"
namespace onnxruntime {
namespace contrib {
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, SampleOp);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, GridSample);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, Attention);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, BeamSearch);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, EmbedLayerNormalization);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, ExpandDims);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, FusedConv);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, FusedGemm);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, AttnLSTM);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, string, Tokenizer);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Range);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, WordConvEmbedding);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, GatherND);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, TransposeMatMul); // backward compatibility
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, FusedMatMul);
#if !defined(DISABLE_SPARSE_TENSORS)
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, SparseToDenseMatMul);
#endif
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, MurmurHash3);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, MaxpoolWithMask);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Pad);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Unique);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, ConvTransposeWithDynamicPads);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, CropAndResize);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, CDist);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, double, CDist);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Gelu);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, BiasGelu);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, FastGelu);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, NGramRepeatBlock);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, BifurcationDetector);
#ifdef BUILD_MS_EXPERIMENTAL_OPS
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, DFT);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, IDFT);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, HannWindow);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, HammingWindow);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, BlackmanWindow);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, MelWeightMatrix);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, STFT);
#endif
// ******** Start: Quantization ******************* //
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, MatMulInteger16);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, QLinearGlobalAveragePool);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, QLinearConcat);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, QLinearAveragePool);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, DequantizeLinear);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, DequantizeLinear);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QuantizeLinear);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QuantizeLinear);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QLinearLeakyRelu);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QLinearLeakyRelu);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QLinearSigmoid);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QLinearSigmoid);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QLinearAdd);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QLinearAdd);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QLinearMul);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QLinearMul);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, QAttention);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, DynamicQuantizeMatMul);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, DynamicQuantizeLSTM);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, MatMulIntegerToFloat);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, QLinearConv);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, MatMulIntegerToFloat);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t_int8_t, QLinearConv);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, NhwcMaxPool);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, NhwcMaxPool);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, QEmbedLayerNormalization);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QGemm);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QGemm);
// ******** End: Quantization ******************* //
// This section includes all op kernel declarations for former experimental ops which have now been removed from onnx.
// To maintain backward compatibility these are added as contrib ops.
// Note: the domain for all contrib ops should be MSDomain. However since these ops started out as onnx domain ops
// we cannot change the domain now as this will break backward compatibility.
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Affine);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Crop);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, DynamicSlice);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, ImageScaler);
class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 8, MeanVarianceNormalization);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, ParametricSoftplus);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, ScaledTanh);
class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 9, ThresholdedRelu);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Scale);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, ReorderInput);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, ReorderOutput);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, Conv);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, MaxPool);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, GlobalMaxPool);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, AveragePool);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, GlobalAveragePool);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, Upsample);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, float, LayerNormalization);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, double, LayerNormalization);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, float, SimplifiedLayerNormalization);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, double, SimplifiedLayerNormalization);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, SkipLayerNormalization);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, double, SkipLayerNormalization);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Inverse);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Trilu);
template <>
KernelCreateInfo BuildKernelCreateInfo<void>() {
KernelCreateInfo info;
return info;
}
Status RegisterNchwcKernels(KernelRegistry& kernel_registry) {
static const BuildKernelCreateInfoFn function_table[] = {
BuildKernelCreateInfo<void>, //default entry to avoid the list become empty after ops-reducing
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, ReorderInput)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, ReorderOutput)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, Conv)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, MaxPool)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, GlobalMaxPool)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, AveragePool)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, GlobalAveragePool)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSNchwcDomain, 1, float, Upsample)>,
};
for (auto& function_table_entry : function_table) {
KernelCreateInfo info = function_table_entry();
if (info.kernel_def != nullptr) { // filter disabled entries where type is void
ORT_RETURN_IF_ERROR(kernel_registry.Register(std::move(info)));
}
}
return Status::OK();
}
Status RegisterQuantizationKernels(KernelRegistry& kernel_registry) {
static const BuildKernelCreateInfoFn function_table[] = {
BuildKernelCreateInfo<void>, //default entry to avoid the list become empty after ops-reducing
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, MatMulInteger16)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, QLinearGlobalAveragePool)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, QLinearConcat)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, QLinearAveragePool)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, DequantizeLinear)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, DequantizeLinear)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QuantizeLinear)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QuantizeLinear)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QLinearLeakyRelu)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QLinearLeakyRelu)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QLinearSigmoid)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QLinearSigmoid)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QLinearAdd)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QLinearAdd)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QLinearMul)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QLinearMul)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, QAttention)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, DynamicQuantizeMatMul)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, DynamicQuantizeLSTM)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, MatMulIntegerToFloat)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, QLinearConv)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, MatMulIntegerToFloat)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t_int8_t, QLinearConv)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, NhwcMaxPool)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, NhwcMaxPool)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, QEmbedLayerNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, int8_t, QGemm)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, uint8_t, QGemm)>,
};
for (auto& function_table_entry : function_table) {
KernelCreateInfo info = function_table_entry();
if (info.kernel_def != nullptr) { // filter disabled entries where type is void
ORT_RETURN_IF_ERROR(kernel_registry.Register(std::move(info)));
}
}
return Status::OK();
}
Status RegisterCpuContribKernels(KernelRegistry& kernel_registry) {
static const BuildKernelCreateInfoFn function_table[] = {
BuildKernelCreateInfo<void>, //default entry to avoid the list become empty after ops-reducing
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, SampleOp)>,
// add more kernels here
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, GridSample)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, Attention)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, BeamSearch)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, EmbedLayerNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, ExpandDims)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, FusedConv)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, FusedGemm)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, AttnLSTM)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, string, Tokenizer)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Range)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, WordConvEmbedding)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, GatherND)>,
#if !defined(DISABLE_SPARSE_TENSORS)
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, SparseToDenseMatMul)>,
#endif
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, MurmurHash3)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, TransposeMatMul)>, // backward compatibility
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, FusedMatMul)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, MaxpoolWithMask)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Pad)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Unique)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, ConvTransposeWithDynamicPads)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, CropAndResize)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, CDist)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, double, CDist)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, BiasGelu)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Gelu)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, FastGelu)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, NGramRepeatBlock)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, BifurcationDetector)>,
#ifdef BUILD_MS_EXPERIMENTAL_OPS
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, DFT)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, IDFT)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, HannWindow)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, HammingWindow)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, BlackmanWindow)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, MelWeightMatrix)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSExperimentalDomain, 1, STFT)>,
#endif
// These ops were experimental ops in onnx domain which have been removed now. We add them here as
// contrib ops to main backward compatibility
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Affine)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Crop)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, DynamicSlice)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, ImageScaler)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 8, MeanVarianceNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, ParametricSoftplus)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, ScaledTanh)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 9, ThresholdedRelu)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Scale)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, float, LayerNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, double, LayerNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, float, SimplifiedLayerNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, double, SimplifiedLayerNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, SkipLayerNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, double, SkipLayerNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Inverse)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, Trilu)>,
};
for (auto& function_table_entry : function_table) {
KernelCreateInfo info = function_table_entry();
if (info.kernel_def != nullptr) { // filter disabled entries where type is void
ORT_RETURN_IF_ERROR(kernel_registry.Register(std::move(info)));
}
}
// Register the NCHWc kernels if supported by the platform.
if (MlasNchwcGetBlockSize() > 1) {
ORT_RETURN_IF_ERROR(RegisterNchwcKernels(kernel_registry));
}
ORT_RETURN_IF_ERROR(RegisterQuantizationKernels(kernel_registry));
return Status::OK();
}
} // namespace contrib
} // namespace onnxruntime
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r13
push %r14
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WC_ht+0x34b3, %rsi
lea addresses_UC_ht+0x9bab, %rdi
clflush (%rdi)
nop
nop
nop
xor %r13, %r13
mov $4, %rcx
rep movsb
nop
nop
nop
and %r11, %r11
lea addresses_normal_ht+0x145f7, %r11
nop
and $16236, %r12
mov (%r11), %esi
cmp $54563, %rcx
lea addresses_A_ht+0x4be3, %r11
nop
nop
sub $45567, %r14
mov (%r11), %r12w
nop
nop
nop
add $53953, %r14
lea addresses_A_ht+0x13ba5, %rsi
nop
nop
nop
nop
nop
inc %r13
mov $0x6162636465666768, %r12
movq %r12, %xmm3
movups %xmm3, (%rsi)
nop
nop
nop
xor %r14, %r14
lea addresses_normal_ht+0xf5e9, %rsi
lea addresses_normal_ht+0x1c18b, %rdi
nop
nop
nop
add %rdx, %rdx
mov $3, %rcx
rep movsw
nop
nop
nop
nop
nop
and $30857, %r11
lea addresses_UC_ht+0x413, %rsi
sub %rcx, %rcx
mov $0x6162636465666768, %r11
movq %r11, (%rsi)
nop
dec %r14
lea addresses_WC_ht+0x1a6cb, %rsi
lea addresses_normal_ht+0x191db, %rdi
clflush (%rsi)
nop
sub $16554, %r14
mov $88, %rcx
rep movsw
nop
add %r11, %r11
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r14
pop %r13
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r14
push %r15
push %r8
push %rax
push %rcx
push %rdi
push %rsi
// Store
lea addresses_UC+0x116cb, %r11
sub $47168, %r15
mov $0x5152535455565758, %r8
movq %r8, %xmm2
vmovups %ymm2, (%r11)
nop
inc %r11
// REPMOV
lea addresses_normal+0x1f6cb, %rsi
lea addresses_D+0x1ef1d, %rdi
nop
and $43005, %rax
mov $44, %rcx
rep movsw
nop
cmp $11042, %rsi
// Store
lea addresses_WC+0x1210b, %rsi
clflush (%rsi)
nop
nop
add %r8, %r8
movb $0x51, (%rsi)
nop
nop
nop
nop
add %r15, %r15
// Faulty Load
lea addresses_normal+0xe6cb, %r11
nop
xor %rax, %rax
movups (%r11), %xmm0
vpextrq $0, %xmm0, %rsi
lea oracles, %r15
and $0xff, %rsi
shlq $12, %rsi
mov (%r15,%rsi,1), %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r15
pop %r14
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 7}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 11, 'type': 'addresses_normal'}, 'dst': {'same': False, 'congruent': 0, 'type': 'addresses_D'}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WC', 'NT': False, 'AVXalign': True, 'size': 1, 'congruent': 5}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'same': False, 'congruent': 3, 'type': 'addresses_WC_ht'}, 'dst': {'same': False, 'congruent': 5, 'type': 'addresses_UC_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_normal_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 1}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 2}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 1}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 1, 'type': 'addresses_normal_ht'}, 'dst': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 3}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 10, 'type': 'addresses_WC_ht'}, 'dst': {'same': False, 'congruent': 4, 'type': 'addresses_normal_ht'}}
{'34': 21829}
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
*/
|
; A221374: Number of n X 2 arrays of occupancy after each element stays put or moves to some horizontal, vertical or antidiagonal neighbor, with no occupancy greater than 2.
; 3,19,139,1035,7723,57643,430251,3211435,23970475,178918059,1335462571,9968028331,74402376363,555346897579,4145165675179,30939937811115,230938839788203,1723750967061163,12866252377336491
mov $3,3
lpb $0,1
mul $3,2
add $2,$3
sub $0,1
add $3,1
mul $2,2
add $3,$2
lpe
mov $1,$3
|
; A263823: a(n) = n!*Sum_{k=0..n} Fibonacci(k-1)/k!, where Fibonacci(-1) = 1, Fibonacci(n) = A000045(n) for n>=0.
; Submitted by Jon Maiga
; 1,1,3,10,42,213,1283,8989,71925,647346,6473494,71208489,854501957,11108525585,155519358423,2332790376722,37324646028162,634518982479741,11421341684636935,217005492008104349,4340109840162091161,91142306643403921146,2005130746154886276158,46118007161562384369345,1106832171877497224892937,27670804296937430622369793,719440911720373196181689643,19424904616450076296905741754,543897329260602136313360965530,15773022548557461953087468318181,473190676456723858592624050059659
add $0,1
mov $2,1
lpb $0
sub $0,1
trn $1,4
mov $3,2
add $3,$2
mul $2,$0
add $3,2
add $3,$4
add $4,$1
mov $1,$3
lpe
mov $0,$1
sub $0,4
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r12
push %r14
push %r8
push %r9
lea addresses_A_ht+0x10845, %r10
nop
nop
nop
nop
inc %r14
mov (%r10), %r11
nop
add %r9, %r9
lea addresses_UC_ht+0x9e45, %r8
nop
sub %r10, %r10
movb $0x61, (%r8)
nop
nop
and %r8, %r8
pop %r9
pop %r8
pop %r14
pop %r12
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r9
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
// REPMOV
lea addresses_D+0x15a05, %rsi
lea addresses_WT+0x7441, %rdi
nop
nop
nop
nop
cmp %r12, %r12
mov $67, %rcx
rep movsq
sub %rsi, %rsi
// Load
lea addresses_WT+0xad45, %r9
nop
nop
nop
xor %rdi, %rdi
movups (%r9), %xmm1
vpextrq $1, %xmm1, %r12
nop
nop
nop
nop
sub %r12, %r12
// Faulty Load
lea addresses_PSE+0x13945, %rsi
clflush (%rsi)
nop
nop
nop
sub %rdx, %rdx
movups (%rsi), %xmm2
vpextrq $1, %xmm2, %rcx
lea oracles, %r12
and $0xff, %rcx
shlq $12, %rcx
mov (%r12,%rcx,1), %rcx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_PSE', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_D', 'congruent': 6, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT', 'congruent': 0, 'same': False}}
{'src': {'type': 'addresses_WT', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 5}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'type': 'addresses_PSE', 'AVXalign': False, 'size': 16, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 8}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 6}}
{'33': 21829}
33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
*/
|
; A336861: a(n) = ceiling((n-1-sqrt(n+1))/2).
; 0,0,0,1,1,2,2,2,3,3,4,4,5,5,5,6,6,7,7,8,8,9,9,9,10,10,11,11,12,12,13,13,14,14,14,15,15,16,16,17,17,18,18,19,19,20,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,27,28,28,29,29,30,30,31,31,32
mov $3,$0
mov $5,$0
lpb $5
mov $0,$3
sub $5,1
sub $0,$5
mov $2,$0
mul $2,39
mov $4,$0
add $4,1
sub $4,$2
add $2,4
sub $4,1
lpb $2
sub $6,2
lpb $4
add $0,$2
sub $2,$6
pow $4,2
add $4,1
sub $4,$6
lpe
trn $0,2
mov $6,$2
sub $2,1
add $4,1
lpe
gcd $0,2
mov $6,$0
sub $6,1
add $1,$6
lpe
|
// Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
// the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
// reserved. See file COPYRIGHT for details.
//
// This file is part of the MFEM library. For more information and source code
// availability see http://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License (as published by the Free
// Software Foundation) version 2.1 dated February 1999.
#ifndef MFEM_NONLINEARFORM
#define MFEM_NONLINEARFORM
#include "../config/config.hpp"
#include "nonlininteg.hpp"
#include "gridfunc.hpp"
namespace mfem
{
class NonlinearForm : public Operator
{
protected:
/// FE space on which the form lives.
FiniteElementSpace *fes; // not owned
/// Set of Domain Integrators to be assembled (added).
Array<NonlinearFormIntegrator*> dnfi; // owned
/// Set of interior face Integrators to be assembled (added).
Array<NonlinearFormIntegrator*> fnfi; // owned
/// Set of boundary face Integrators to be assembled (added).
Array<NonlinearFormIntegrator*> bfnfi; // owned
Array<Array<int>*> bfnfi_marker; // not owned
mutable SparseMatrix *Grad, *cGrad; // owned
/// A list of all essential true dofs
Array<int> ess_tdof_list;
/// Counter for updates propagated from the FiniteElementSpace.
long sequence;
/// Auxiliary Vector%s
mutable Vector aux1, aux2;
/// Pointer to the prolongation matrix of fes, may be NULL.
const Operator *P; // not owned
/// The result of dynamic-casting P to SparseMatrix pointer.
const SparseMatrix *cP; // not owned
bool Serial() const { return (!P || cP); }
const Vector &Prolongate(const Vector &x) const;
public:
/// Construct a NonlinearForm on the given FiniteElementSpace, @a f.
/** As an Operator, the NonlinearForm has input and output size equal to the
number of true degrees of freedom, i.e. f->GetTrueVSize(). */
NonlinearForm(FiniteElementSpace *f)
: Operator(f->GetTrueVSize()), fes(f), Grad(NULL), cGrad(NULL),
sequence(f->GetSequence()), P(f->GetProlongationMatrix()),
cP(dynamic_cast<const SparseMatrix*>(P))
{ }
FiniteElementSpace *FESpace() { return fes; }
const FiniteElementSpace *FESpace() const { return fes; }
/// Adds new Domain Integrator.
void AddDomainIntegrator(NonlinearFormIntegrator *nlfi)
{ dnfi.Append(nlfi); }
/// Adds new Interior Face Integrator.
void AddInteriorFaceIntegrator(NonlinearFormIntegrator *nlfi)
{ fnfi.Append(nlfi); }
/// Adds new Boundary Face Integrator.
void AddBdrFaceIntegrator(NonlinearFormIntegrator *nlfi)
{ bfnfi.Append(nlfi); bfnfi_marker.Append(NULL); }
/** @brief Adds new Boundary Face Integrator, restricted to specific boundary
attributes. */
void AddBdrFaceIntegrator(NonlinearFormIntegrator *nfi,
Array<int> &bdr_marker)
{ bfnfi.Append(nfi); bfnfi_marker.Append(&bdr_marker); }
/// Specify essential boundary conditions.
/** This method calls FiniteElementSpace::GetEssentialTrueDofs() and stores
the result internally for use by other methods. If the @a rhs pointer is
not NULL, its essential true dofs will be set to zero. This makes it
"compatible" with the output vectors from the Mult() method which also
have zero entries at the essential true dofs. */
void SetEssentialBC(const Array<int> &bdr_attr_is_ess, Vector *rhs = NULL);
/// (DEPRECATED) Specify essential boundary conditions.
/** @deprecated Use either SetEssentialBC() or SetEssentialTrueDofs(). */
void SetEssentialVDofs(const Array<int> &ess_vdofs_list);
/// Specify essential boundary conditions.
void SetEssentialTrueDofs(const Array<int> &ess_tdof_list)
{ ess_tdof_list.Copy(this->ess_tdof_list); }
/// Return a (read-only) list of all essential true dofs.
const Array<int> &GetEssentialTrueDofs() const { return ess_tdof_list; }
/// Compute the enery corresponding to the state @a x.
/** In general, @a x may have non-homogeneous essential boundary values.
The state @a x must be a "GridFunction size" vector, i.e. its size must
be fes->GetVSize(). */
double GetGridFunctionEnergy(const Vector &x) const;
/// Compute the enery corresponding to the state @a x.
/** In general, @a x may have non-homogeneous essential boundary values.
The state @a x must be a true-dof vector. */
virtual double GetEnergy(const Vector &x) const
{ return GetGridFunctionEnergy(Prolongate(x)); }
/// Evaluate the action of the NonlinearForm.
/** The input essential dofs in @a x will, generally, be non-zero. However,
the output essential dofs in @a y will always be set to zero.
Both the input and the output vectors, @a x and @a y, must be true-dof
vectors, i.e. their size must be fes->GetTrueVSize(). */
virtual void Mult(const Vector &x, Vector &y) const;
/** @brief Compute the gradient Operator of the NonlinearForm corresponding
to the state @a x. */
/** Any previously specified essential boundary conditions will be
automatically imposed on the gradient operator.
The returned object is valid until the next call to this method or the
destruction of this object.
In general, @a x may have non-homogeneous essential boundary values.
The state @a x must be a true-dof vector. */
virtual Operator &GetGradient(const Vector &x) const;
/// Update the NonlinearForm to propagate updates of the associated FE space.
/** After calling this method, the essential boundary conditions need to be
set again. */
virtual void Update();
/// Get the finite element space prolongation matrix
virtual const Operator *GetProlongation() const { return P; }
/// Get the finite element space restriction matrix
virtual const Operator *GetRestriction() const
{ return fes->GetRestrictionMatrix(); }
/** @brief Destroy the NoninearForm including the owned
NonlinearFormIntegrator%s and gradient Operator. */
virtual ~NonlinearForm();
};
/** @brief A class representing a general block nonlinear operator defined on
the Cartesian product of multiple FiniteElementSpace%s. */
class BlockNonlinearForm : public Operator
{
protected:
/// FE spaces on which the form lives.
Array<FiniteElementSpace*> fes;
/// Set of Domain Integrators to be assembled (added).
Array<BlockNonlinearFormIntegrator*> dnfi;
/// Set of interior face Integrators to be assembled (added).
Array<BlockNonlinearFormIntegrator*> fnfi;
/// Set of Boundary Face Integrators to be assembled (added).
Array<BlockNonlinearFormIntegrator*> bfnfi;
Array<Array<int>*> bfnfi_marker;
/** Auxiliary block-vectors for wrapping input and output vectors or holding
GridFunction-like block-vector data (e.g. in parallel). */
mutable BlockVector xs, ys;
mutable Array2D<SparseMatrix*> Grads;
mutable BlockOperator *BlockGrad;
// A list of the offsets
Array<int> block_offsets;
Array<int> block_trueOffsets;
// Essential vdofs: one list of vdofs for each space in 'fes'
Array<Array<int> *> ess_vdofs;
/// Specialized version of GetEnergy() for BlockVectors
double GetEnergyBlocked(const BlockVector &bx) const;
/// Specialized version of Mult() for BlockVector%s
void MultBlocked(const BlockVector &bx, BlockVector &by) const;
/// Specialized version of GetGradient() for BlockVector
Operator &GetGradientBlocked(const BlockVector &bx) const;
public:
/// Construct an empty BlockNonlinearForm. Initialize with SetSpaces().
BlockNonlinearForm();
/// Construct a BlockNonlinearForm on the given set of FiniteElementSpace%s.
BlockNonlinearForm(Array<FiniteElementSpace *> &f);
/// Return the @a k-th FE space of the BlockNonlinearForm.
FiniteElementSpace *FESpace(int k) { return fes[k]; }
/// Return the @a k-th FE space of the BlockNonlinearForm (const version).
const FiniteElementSpace *FESpace(int k) const { return fes[k]; }
/// (Re)initialize the BlockNonlinearForm.
/** After a call to SetSpaces(), the essential b.c. must be set again. */
void SetSpaces(Array<FiniteElementSpace *> &f);
/// Return the regular dof offsets.
const Array<int> &GetBlockOffsets() const { return block_offsets; }
/// Return the true-dof offsets.
const Array<int> &GetBlockTrueOffsets() const { return block_trueOffsets; }
/// Adds new Domain Integrator.
void AddDomainIntegrator(BlockNonlinearFormIntegrator *nlfi)
{ dnfi.Append(nlfi); }
/// Adds new Interior Face Integrator.
void AddInteriorFaceIntegrator(BlockNonlinearFormIntegrator *nlfi)
{ fnfi.Append(nlfi); }
/// Adds new Boundary Face Integrator.
void AddBdrFaceIntegrator(BlockNonlinearFormIntegrator *nlfi)
{ bfnfi.Append(nlfi); bfnfi_marker.Append(NULL); }
/** @brief Adds new Boundary Face Integrator, restricted to specific boundary
attributes. */
void AddBdrFaceIntegrator(BlockNonlinearFormIntegrator *nlfi,
Array<int> &bdr_marker);
virtual void SetEssentialBC(const Array<Array<int> *>&bdr_attr_is_ess,
Array<Vector *> &rhs);
virtual double GetEnergy(const Vector &x) const;
virtual void Mult(const Vector &x, Vector &y) const;
virtual Operator &GetGradient(const Vector &x) const;
/// Destructor.
virtual ~BlockNonlinearForm();
};
}
#endif
|
bits 64
default rel
section .text
global pal_execute_wbinvd
pal_execute_wbinvd :
wbinvd
ret
|
/*
* Villains' Utility Library - Thomas Martin Schmid, 2017. Public domain¹
*
* This file describes an affine class, containing a matrix for the linear
* part of an affine transformation and a vector describing the translation.
* It also defines the application of the transformation on points and
* vectors.
*
* ¹ If public domain is not legally valid in your legal jurisdiction
* the MIT licence applies (see the LICENCE file)
*
* 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.
*/
#ifndef VUL_AFFINE_HPP
#define VUL_AFFINE_HPP
#include "vul_types.hpp"
#include "vul_quaternion.hpp"
#include "vul_matrix.hpp"
namespace vul {
//----------------
// Declarations
//
template< typename T, s32 n >
struct Vector;
template< typename T, s32 n >
struct Point;
template< typename T, s32 m, s32 n >
struct Matrix;
template< typename T, s32 n >
struct Affine {
Matrix< T, n, n > mat;
Vector< T, n > vec;
#ifdef VUL_CPLUSPLUS11
// Constructors
/**
* Create an empty affine transformation. No translation
* and an identity matrix are created.
*/
explicit Affine< T, n >( );
/**
* Create a copy of an affine transformation.
*/
Affine< T, n >( const Affine< T, n > &a );
/**
* Create an affine transformation from a rotation/scale matrix and a translation vector.
*/
Affine< T, n >( const Matrix< T, n, n > &mat, const Vector< T, n > &vec );
#endif
Affine< T, n > &operator=( const Affine< T, n > &rhs );
};
#ifndef VUL_CPLUSPLUS11
/**
* Create an empty affine transformation. No translation
* and an identity matrix are created.
*/
template< typename T, s32 n >
Affine< T, n > makeAffine( );
/**
* Create a copy of an affine transformation.
*/
template< typename T, s32 n >
Affine< T, n > makeAffine( const Affine< T, n > &a );
/**
* Create an affine transformation from a rotation/scale matrix and a translation vector.
*/
template< typename T, s32 n >
Affine< T, n > makeAffine( const Matrix< T, n, n > &mat, const Vector< T, n > &vec ); // Constructor from Mat<n,n> & Vec<n>.
#endif
/**
* Apply an affine transformation to the point, including translation.
*/
template< typename T, s32 n >
Point< T, n > operator*( const Affine< T, n > &a, const Point< T, n> &p );
/**
* Apply an affine transformation to the vector. This does not translate.
*/
template< typename T, s32 n >
Vector< T, n > operator*( const Affine< T, n > &a, const Vector< T, n> &p );
/**
* Creates a 3D affine transformation to a 4x4 homogenous tronsformation matrix.
*/
template< typename T >
Matrix< T, 4, 4 > makeHomogeneousFromAffine( const Affine< T, 3 > &a );
/**
* Construct a 3D affine transformation from translation, scale and orientation bases.
*/
template< typename T >
Affine< T, 3 > makeAffine3D( const Vector< T, 3 > &translation, const Vector< T, 3 > &scale, const Quaternion< T > &orientation );
//---------------------------
// Definitions
//
#ifdef VUL_CPLUSPLUS11
template< typename T, s32 n >
Affine< T, n >::Affine( )
{
mat = makeIdentity< T, n >( );
vec = Vector< T, n >( );
}
template< typename T, s32 n >
Affine< T, n >::Affine( const Affine< T, n > &a )
{
mat = a.mat;
vec = a.vec;
}
template< typename T, s32 n >
Affine< T, n >::Affine( const Matrix< T, n, n > &mat, const Vector< T, n > &vec )
{
this->mat = mat;
this->vec = vec;
}
#else
#if defined( VUL_WINDOWS ) && !defined( __MINGW32__ ) && !defined( __MINGW64__ )
#pragma warning(disable: 6001)
#endif
template< typename T, s32 n >
Affine< T, n > makeAffine( )
{
Affine< T, n > a;
a.mat = makeIdentity< T, n >( );
a.vec = makeVector< T, n >( );
return a;
}
template< typename T, s32 n >
Affine< T, n > makeAffine( const Affine< T, n > &a )
{
Affine< T, n > r;
r.mat = a.mat;
r.vec = a.vec;
return r;
}
template< typename T, s32 n >
Affine< T, n > makeAffine( const Matrix< T, n, n > &mat, const Vector< T, n > &vec )
{
Affine< T, n > a;
a.mat = mat;
a.vec = vec;
return a;
}
#endif
template< typename T, s32 n >
Affine< T, n > &Affine< T, n >::operator=( const Affine< T, n > &rhs )
{
mat = rhs.mat;
vec = rhs.vec;
return *this;
}
template< typename T, s32 n >
Point< T, n > operator*( const Affine< T, n > &a, const Point< T, n> &p )
{
Point< T, n > r;
r = ( p * a.mat ) + a.vec;
return r;
}
template< typename T, s32 n >
Vector< T, n > operator*( const Affine< T, n > &a, const Vector< T, n> &p )
{
Vector< T, n > v;
v = p * a.mat;
return v;
}
template< typename T >
Matrix< T, 4, 4 > makeHomogeneousFromAffine( const Affine< T, 3 > &a )
{
Matrix< T, 4, 4 > m;
T d[ 4 ][ 4 ];
d[ 0 ][ 0 ] = a.mat.data[ 0 ][ 0 ];
d[ 1 ][ 0 ] = a.mat.data[ 1 ][ 0 ];
d[ 2 ][ 0 ] = a.mat.data[ 2 ][ 0 ];
d[ 3 ][ 0 ] = a.vec.data[ 0 ];
d[ 0 ][ 1 ] = a.mat.data[ 0 ][ 1 ];
d[ 1 ][ 1 ] = a.mat.data[ 1 ][ 1 ];
d[ 2 ][ 1 ] = a.mat.data[ 2 ][ 1 ];
d[ 3 ][ 1 ] = a.vec.data[ 1 ];
d[ 0 ][ 2 ] = a.mat.data[ 0 ][ 2 ];
d[ 1 ][ 2 ] = a.mat.data[ 1 ][ 2 ];
d[ 2 ][ 2 ] = a.mat.data[ 2 ][ 2 ];
d[ 3 ][ 2 ] = a.vec.data[ 2 ];
d[ 0 ][ 3 ] = static_cast< T >( 0.f );
d[ 1 ][ 3 ] = static_cast< T >( 0.f );
d[ 2 ][ 3 ] = static_cast< T >( 0.f );
d[ 3 ][ 3 ] = static_cast< T >( 1.f );
#ifdef VUL_CPLUSPLUS11
m = Matrix< T, 4, 4 >( d );
#else
m = makeMatrix< T, 4, 4 >( d );
#endif
return m;
}
template< typename T >
Affine< T, 3 > makeAffine3D( const Vector< T, 3 > &translation, const Vector< T, 3 > &scale, const Quaternion< T > &orientation )
{
Affine< T, 3 > a;
s32 i, j;
// Copy translation straight
a.vec = translation;
// Build rotation matrix ( inverse of the orientation )
a.mat = makeMatrix( inverse( orientation ) );
// Multiply in scale
for( i = 0; i < 3; ++i ) {
for( j = 0; j < 3; ++j ) {
a.mat.data[ i ][ j ] = a.mat.data[ i ][ j ] * scale.data[ j ];
}
}
return a;
}
}
#if defined( VUL_WINDOWS ) && !defined( __MINGW32__ ) && !defined( __MINGW64__ )
#pragma warning(default: 6001)
#endif
#endif
|
include "constants.asm"
IF SPANISH = 1
include "autogenerated/text-constants-es.asm"
ELSE
include "autogenerated/text-constants.asm"
ENDIF
; the first time this is compiled, we need a few symbols to be defined
; to bootstrap the process. Comment the inclusion of trition.sym and Uncomment these
; constant definition lines:
include "../isometric.sym"
; ending variables:
ending_trigger_map: equ ram_to_clear_at_game_start+7 ; 0/1: map 1 triggered/loaded 2/3: map 2; 4/5: map 3
ending_roll_step: equ ram_to_clear_at_game_start+8 ; from 3-21: unrolling, from 103-121: rolling, 128: reset
ending_text_page_line_state: equ ram_to_clear_at_game_start+9 ; 0: we still need to draw it, > 0 we are displaying it
ending_text_page: equ ram_to_clear_at_game_start+10 ; 0 (text 1), 1 (wait), 2 (text 2), 3 (wait), 4 (the end)
ending_text_page_line: equ ram_to_clear_at_game_start+11
org ENDING_COMPRESSED_CODE_START
include "compressed-state-ending.asm"
|
; A028329: Twice central binomial coefficients.
; 2,4,12,40,140,504,1848,6864,25740,97240,369512,1410864,5408312,20801200,80233200,310235040,1202160780,4667212440,18150270600,70690527600,275693057640,1076515748880,4208197927440,16466861455200,64495207366200,252821212875504,991837065896208,3893878851296224,15297381201520880,60134532999082080,236529163129722848,930856706510522176,3665248281885181068,14438856868032531480,56906082950481153480,224372555633325690864,885025080553673558408,3492261128671252419664,13785241297386522709200
mov $1,$0
mul $0,2
bin $0,$1
mul $0,2
|
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "hphp/runtime/vm/jit/func-prologues-arm.h"
#include "hphp/vixl/a64/macro-assembler-a64.h"
#include "hphp/runtime/base/array-init.h"
#include "hphp/runtime/ext/ext_closure.h"
#include "hphp/runtime/vm/jit/abi-arm.h"
#include "hphp/runtime/vm/jit/code-gen-helpers-arm.h"
#include "hphp/runtime/vm/jit/back-end.h"
#include "hphp/runtime/vm/jit/service-requests-arm.h"
#include "hphp/runtime/vm/jit/mc-generator.h"
namespace HPHP { namespace jit { namespace arm {
//////////////////////////////////////////////////////////////////////
namespace {
void emitStackCheck(int funcDepth, Offset pc) {
vixl::MacroAssembler a { mcg->code.main() };
funcDepth += cellsToBytes(kStackCheckPadding);
uint64_t stackMask = cellsToBytes(RuntimeOption::EvalVMStackElms) - 1;
a. And (rAsm, rVmSp, stackMask);
a. Sub (rAsm, rAsm, funcDepth + Stack::sSurprisePageSize, vixl::SetFlags);
// This doesn't need to be smashable, but it is a long jump from mainCode to
// cold, so it can't be direct.
mcg->backEnd().emitSmashableJump(
mcg->code.main(), mcg->tx().uniqueStubs.stackOverflowHelper, CC_L);
}
TCA emitFuncGuard(vixl::MacroAssembler& a, Func* func) {
vixl::Label success;
vixl::Label redispatchStubAddr;
vixl::Label funcAddr;
DEBUG_ONLY TCA start = a.frontier();
a. Ldr (rAsm, rStashedAR[AROFF(m_func)]);
a. Ldr (rAsm2, &funcAddr);
a. Cmp (rAsm, rAsm2);
a. B (&success, vixl::eq);
// Load the address of the redispatch stub and jump to it.
a. Ldr (rAsm, &redispatchStubAddr);
a. Br (rAsm);
if (!a.isFrontierAligned(8)) {
a. Nop ();
assert(a.isFrontierAligned(8));
}
a. bind (&redispatchStubAddr);
a. dc64 (mcg->tx().uniqueStubs.funcPrologueRedispatch);
// The guarded Func* comes right before the end so that
// funcPrologueToGuardImmPtr() is simple.
a. bind (&funcAddr);
a. dc64 (func);
a. bind (&success);
assert(funcPrologueToGuard(a.frontier(), func) == start);
assert(funcPrologueHasGuard(a.frontier(), func));
return a.frontier();
}
constexpr auto kLocalsToInitializeInline = 9;
SrcKey emitPrologueWork(Func* func, int nPassed) {
vixl::MacroAssembler a { mcg->code.main() };
if (mcg->tx().mode() == TransKind::Proflogue) {
not_implemented();
}
auto dvInitializer = InvalidAbsoluteOffset;
auto const numNonVariadicParams = func->numNonVariadicParams();
auto const& paramInfo = func->params();
// Resolve cases where the wrong number of args was passed.
if (nPassed > numNonVariadicParams) {
void (*helper)(ActRec*);
if (func->attrs() & AttrMayUseVV) {
helper = func->hasVariadicCaptureParam()
? jit::shuffleExtraArgsVariadicAndVV
: jit::shuffleExtraArgsMayUseVV;
} else if (func->hasVariadicCaptureParam()) {
helper = jit::shuffleExtraArgsVariadic;
} else {
helper = jit::trimExtraArgs;
}
a. Mov (argReg(0), rStashedAR);
emitCall(a, CppCall::direct(helper));
// We'll fix rVmSp below.
} else {
if (nPassed < numNonVariadicParams) {
for (auto i = nPassed; i < numNonVariadicParams; ++i) {
auto const& pi = paramInfo[i];
if (pi.hasDefaultValue()) {
dvInitializer = pi.funcletOff;
break;
}
}
a. Mov (rAsm, nPassed);
// do { *(--rVmSp) = NULL; nPassed++; }
// while (nPassed < numNonVariadicParams);
vixl::Label loopTop;
a. bind (&loopTop);
a. Sub (rVmSp, rVmSp, sizeof(Cell));
a. Add (rAsm, rAsm, 1);
static_assert(KindOfUninit == 0, "need this for zero-register hack");
a. Strb (vixl::xzr, rVmSp[TVOFF(m_type)]);
a. Cmp (rAsm, numNonVariadicParams);
a. B (&loopTop, vixl::lt);
}
if (func->hasVariadicCaptureParam()) {
a. Mov (rAsm, KindOfArray);
a. Strb (rAsm.W(), rVmSp[TVOFF(m_type) - sizeof(Cell)]);
a. Mov (rAsm, uint64_t(staticEmptyArray()));
a. Str (rAsm, rVmSp[TVOFF(m_data) - sizeof(Cell)]);
}
}
// Frame linkage.
a. Mov (rVmFp, rStashedAR);
auto numLocals = func->numParams();
if (func->isClosureBody()) {
int numUseVars = func->cls()->numDeclProperties() -
func->numStaticLocals();
emitRegGetsRegPlusImm(a, rVmSp, rVmFp, -cellsToBytes(numLocals));
// This register needs to live a long time, across calls to helpers that may
// use both rAsm and rAsm2. So it can't be one of them. Fortunately, we're
// between blocks here, so no normal registers are live; just pick any.
auto const& rClosure = vixl::x0;
a. Ldr (rClosure, rVmFp[AROFF(m_this)]);
// Swap in the $this or late bound class
a. Ldr (rAsm, rClosure[c_Closure::ctxOffset()]);
a. Str (rAsm, rVmFp[AROFF(m_this)]);
if (!(func->attrs() & AttrStatic)) {
// Only do the incref if rAsm is not zero AND its LSB is zero.
vixl::Label notRealThis;
// Jump if rAsm is zero.
a. Cbz (rAsm, ¬RealThis);
// Tbnz = test and branch if not zero. It tests a single bit, given by a
// position (in this case, 0, the second argument).
a. Tbnz (rAsm, 0, ¬RealThis);
auto wCount = rAsm2.W();
a. Ldr (wCount, rAsm[FAST_REFCOUNT_OFFSET]);
a. Add (wCount, wCount, 1);
a. Str (wCount, rAsm[FAST_REFCOUNT_OFFSET]);
a. bind (¬RealThis);
}
// Put in the correct context
a. Ldr (rAsm, rClosure[c_Closure::funcOffset()]);
a. Str (rAsm, rVmFp[AROFF(m_func)]);
// Copy in all the use vars
int baseUVOffset = sizeof(ObjectData) + func->cls()->builtinODTailSize();
for (auto i = 0; i < numUseVars + 1; i++) {
auto spOffset = -cellsToBytes(i + 1);
if (i == 0) {
// The closure is the first local.
// We don't incref because it used to be $this
// and now it is a local, so they cancel out
a.Mov (rAsm, KindOfObject);
a.Strb (rAsm.W(), rVmSp[spOffset + TVOFF(m_type)]);
a.Str (rClosure, rVmSp[spOffset + TVOFF(m_data)]);
continue;
}
auto uvOffset = baseUVOffset + cellsToBytes(i - 1);
a. Ldr (rAsm, rClosure[uvOffset + TVOFF(m_data)]);
a. Str (rAsm, rVmSp[spOffset + TVOFF(m_data)]);
a. Ldrb (rAsm.W(), rClosure[uvOffset + TVOFF(m_type)]);
a. Strb (rAsm.W(), rVmSp[spOffset + TVOFF(m_type)]);
emitIncRefGeneric(a, rVmSp, spOffset);
}
numLocals += numUseVars + 1;
}
assert(func->numLocals() >= numLocals);
auto numUninitLocals = func->numLocals() - numLocals;
if (numUninitLocals > 0) {
if (numUninitLocals > kLocalsToInitializeInline) {
auto const& loopReg = rAsm2;
auto loopStart = cellsToBytes(-func->numLocals()) + TVOFF(m_type);
auto loopEnd = cellsToBytes(-numLocals) + TVOFF(m_type);
a. Mov (loopReg, loopStart);
vixl::Label loopTop;
a. bind (&loopTop);
// do {
// rVmFp[loopReg].m_type = KindOfUninit;
// } while(++loopReg != loopEnd);
static_assert(KindOfUninit == 0, "need this for zero-register hack");
a. Strb (vixl::xzr, rVmFp[loopReg]);
a. Add (loopReg, loopReg, sizeof(Cell));
a. Cmp (loopReg, loopEnd);
a. B (&loopTop, vixl::ne);
} else {
for (auto k = numLocals; k < func->numLocals(); ++k) {
int disp =
cellsToBytes(locPhysicalOffset(Location(Location::Local, k), func));
a.Strb (vixl::xzr, rVmFp[disp + TVOFF(m_type)]);
}
}
}
auto const* destPC = func->unit()->entry() + func->base();
if (dvInitializer != InvalidAbsoluteOffset) {
destPC = func->unit()->entry() + dvInitializer;
}
SrcKey funcBody(func, destPC, false);
// Set stack pointer just past all locals
int frameCells = func->numSlotsInFrame();
emitRegGetsRegPlusImm(a, rVmSp, rVmFp, -cellsToBytes(frameCells));
Fixup fixup(funcBody.offset() - func->base(), frameCells);
// Emit warnings for missing arguments
if (!func->isCPPBuiltin()) {
for (auto i = nPassed; i < numNonVariadicParams; ++i) {
if (paramInfo[i].funcletOff == InvalidAbsoluteOffset) {
a. Mov (argReg(0), func);
a. Mov (argReg(1), nPassed);
auto fixupAddr = emitCall(a,
CppCall::direct(jit::raiseMissingArgument));
mcg->recordSyncPoint(fixupAddr, fixup.pcOffset, fixup.spOffset);
break;
}
}
}
// Check surprise flags in the same place as the interpreter: after
// setting up the callee's frame but before executing any of its
// code
emitCheckSurpriseFlagsEnter(mcg->code.main(), mcg->code.cold(), rVmTl, fixup);
if (func->isClosureBody() && func->cls()) {
int entry = nPassed <= numNonVariadicParams
? nPassed : numNonVariadicParams + 1;
// Relying on rStashedAR == rVmFp here
a. Ldr (rAsm, rStashedAR[AROFF(m_func)]);
a. Ldr (rAsm, rAsm[Func::prologueTableOff() + sizeof(TCA)*entry]);
a. Br (rAsm);
} else {
emitBindJmp(mcg->code.main(), mcg->code.frozen(), funcBody);
}
return funcBody;
}
//////////////////////////////////////////////////////////////////////
// ARM-only prologue runtime helpers
void setArgInActRec(ActRec* ar, int argNum, uint64_t datum, DataType t) {
TypedValue* tv =
(TypedValue*)(uintptr_t(ar) - (argNum+1) * sizeof(TypedValue));
tv->m_data.num = datum;
tv->m_type = t;
}
const StaticString s_call("__call");
const StaticString s_callStatic("__callStatic");
int shuffleArgsForMagicCall(ActRec* ar) {
if (!ar->hasInvName()) {
return 0;
}
const Func* f UNUSED = ar->m_func;
f->validate();
assert(f->name()->isame(s_call.get())
|| f->name()->isame(s_callStatic.get()));
assert(f->numParams() == 2);
assert(!f->hasVariadicCaptureParam());
assert(ar->hasInvName());
StringData* invName = ar->getInvName();
assert(invName);
ar->setVarEnv(nullptr);
int nargs = ar->numArgs();
// We need to make an array containing all the arguments passed by the
// caller and put it where the second argument is
PackedArrayInit aInit(nargs);
for (int i = 0; i < nargs; ++i) {
auto const tv = reinterpret_cast<TypedValue*>(
uintptr_t(ar) - (i+1) * sizeof(TypedValue)
);
aInit.append(tvAsCVarRef(tv));
tvRefcountedDecRef(tv);
}
// Put invName in the slot for first argument
setArgInActRec(ar, 0, uint64_t(invName), KindOfString);
// Put argArray in the slot for second argument
auto const argArray = aInit.toArray().detach();
setArgInActRec(ar, 1, uint64_t(argArray), KindOfArray);
// Fix up ActRec's numArgs
ar->initNumArgs(2);
return 1;
}
//////////////////////////////////////////////////////////////////////
} // anonymous namespace
//////////////////////////////////////////////////////////////////////
TCA emitCallArrayPrologue(Func* func, DVFuncletsVec& dvs) {
auto& mainCode = mcg->code.main();
auto& frozenCode = mcg->code.frozen();
vixl::MacroAssembler a { mainCode };
vixl::MacroAssembler afrozen { frozenCode };
TCA start = mainCode.frontier();
a. Ldr (rAsm.W(), rVmFp[AROFF(m_numArgsAndFlags)]);
for (auto i = 0; i < dvs.size(); ++i) {
a. Cmp (rAsm.W(), dvs[i].first);
emitBindJcc(mainCode, frozenCode, CC_LE,
SrcKey(func, dvs[i].second, false));
}
emitBindJmp(mainCode, frozenCode, SrcKey(func, func->base(), false));
mcg->cgFixups().process(nullptr);
return start;
}
SrcKey emitFuncPrologue(CodeBlock& mainCode, CodeBlock& coldCode,
Func* func, bool funcIsMagic, int nPassed,
TCA& start, TCA& aStart) {
vixl::MacroAssembler a { mainCode };
vixl::Label veryStart;
a.bind(&veryStart);
if (!func->isMagic()) {
start = aStart = emitFuncGuard(a, func);
}
if (RuntimeOption::EvalJitTransCounters) {
emitTransCounterInc(a);
}
if (!func->isMagic()) {
emitStoreRetIntoActRec(a);
auto const needStackCheck =
!(func->attrs() & AttrPhpLeafFn) ||
func->maxStackCells() >= kStackCheckLeafPadding;
if (needStackCheck) {
emitStackCheck(cellsToBytes(func->maxStackCells()), func->base());
}
}
SrcKey skFuncBody = emitPrologueWork(func, nPassed);
if (func->isMagic()) {
TCA magicStart = emitFuncGuard(a, func);
emitStoreRetIntoActRec(a);
// emit rb
emitStackCheck(cellsToBytes(func->maxStackCells()), func->base());
assert(func->numParams() == 2);
// Special __call prologue
a. Mov (argReg(0), rStashedAR);
auto fixupAddr = emitCall(a, CppCall::direct(shuffleArgsForMagicCall));
if (RuntimeOption::HHProfServerEnabled) {
mcg->recordSyncPoint(fixupAddr,
skFuncBody.offset() - func->base(),
func->numSlotsInFrame());
}
if (nPassed == 2) {
a. B (&veryStart);
} else {
// "compare and branch if zero"
a. Cbz (rReturnReg, &veryStart);
nPassed = 2;
emitRegGetsRegPlusImm(a, rVmSp, rStashedAR, -cellsToBytes(nPassed));
emitPrologueWork(func, nPassed);
}
start = magicStart;
}
return skFuncBody;
}
}}}
|
.segment "HEADER"
.byte "NES", $1A ; iNES header identifier
.byte 2 ; 2x 16KB PRG code
.byte 1 ; 1x 8KB CHR data
.byte $01, $00 ; mapper 0, vertical mirroring
.segment "STARTUP"
.segment "ZEROPAGE"
ctrlOne: .res 1
ctrlTwo: .res 1
ballAngle: .res 1 ; bits : nul nul nul nul up down left right
paddle1Top: .res 1
paddle1Bottom: .res 1
paddle2Top: .res 1
paddle2Bottom: .res 1
paddle1Movement: .res 1
paddle2Movement: .res 1
paddleSpeed: .res 1
ballSpeedX: .res 1
ballSpeedY: .res 1
paddle1Score: .res 1
paddle2Score: .res 1
paddleTurn: .res 1 ; $01 is paddle1, $02 is paddle2
turnPause: .res 1
.segment "CODE"
; CONSTANTS
PPU_STAT = $2002
PPU_ADDR = $2006
PPU_DATA = $2007
CTRL_PORT = $4016
BUTTON_A = $80 ; Use AND to test ctrlOne or ctrlTwo against
BUTTON_B = $40 ; these BUTTON constants to see which are
BUTTON_SELECT = $20 ; being pressed ... example below ...
BUTTON_START = $10 ; STA ctrlOne
BUTTON_UP = $08 ; AND #BUTTON_A ; don't forget to use the #
BUTTON_DOWN = $04 ; BEQ notPressed
BUTTON_LEFT = $02 ; BNE isPressed
BUTTON_RIGHT = $01
SPRITE_RAM = $0200
PADDLE1_YPOS = SPRITE_RAM + 0
PADDLE1_TILE = SPRITE_RAM + 1
PADDLE1_ATTR = SPRITE_RAM + 2
PADDLE1_XPOS = SPRITE_RAM + 3 ; repeats 3 more times
PADDLE2_YPOS = SPRITE_RAM + 16
PADDLE2_TILE = SPRITE_RAM + 17
PADDLE2_ATTR = SPRITE_RAM + 18
PADDLE2_XPOS = SPRITE_RAM + 19 ; repeats 3 more times
BALL_YPOS = SPRITE_RAM + 32
BALL_TILE = SPRITE_RAM + 33
BALL_ATTR = SPRITE_RAM + 34
BALL_XPOS = SPRITE_RAM + 35 ; that's it for this one
TOTAL_SPRITES = $24 ; hex for 36 ( 16 + 16 + 4 )
MOVING_UP = $08
MOVING_DOWN = $04
MOVING_LEFT = $02
MOVING_RIGHT = $01
LEFT_WALL = $02
RIGHT_WALL = $F6
TOP_WALL = $08
BOTTOM_WALL = $DF
PADDLE_SIZE = $20
PADDLE1_X_LIMIT = $10
PADDLE2_X_LIMIT = $E8
PADDLE_Y_TOP_LIMIT = $08
PADDLE_Y_BOTTOM_LIMIT = $C7
PADDLE1_TURN = $01
PADDLE2_TURN = $02
BALL_DEFAULT_SPEED_X = $02
BALL_DEFAULT_SPEED_Y = $01
;;;;;;;;;;;;;;;
RESET:
SEI ; disable IRQs
CLD ; disable decimal mode
LDX #$40
STX $4017 ; disable APU frame IRQ
LDX #$FF
TXS ; Set up stack
INX ; now X = 0
STX $2000 ; disable NMI
STX $2001 ; disable rendering
STX $4010 ; disable DMC IRQs
JSR vblankWait
clrmem:
LDA #$00
STA $0000, x
STA $0100, x
STA $0200, x
STA $0400, x
STA $0500, x
STA $0600, x
STA $0700, x
LDA #$FE
STA $0300, x
INX
BNE clrmem
JSR vblankWait
JSR loadPalettes
JSR loadSprites
JSR initializeVariables
Forever:
JMP Forever ;jump back to Forever, infinite loop
NMI:
JSR startNMI
JSR readCtrl
JSR movePaddles
JSR moveBall
JSR updateSprites
RTI ; return from interrupt
;;;;;;;;;;;;;;
vblankWait:
BIT PPU_STAT
BPL vblankWait
RTS
startNMI:
LDA #$00
STA $2003 ; set the low byte (00) of the RAM address
LDA #$02
STA $4014 ; set the high byte (02) of the RAM address, start the transfer
RTS
initializeVariables:
LDA #MOVING_DOWN
ORA #MOVING_RIGHT
STA ballAngle ; ballAngle = MOVING_DOWN | MOVING_LEFT;
LDA #$01
STA paddleSpeed
LDA #BALL_DEFAULT_SPEED_X
STA ballSpeedX
LDA #BALL_DEFAULT_SPEED_Y
STA ballSpeedY
STA paddleTurn
STA turnPause
RTS
loadPalettes:
LDA PPU_STAT ; read PPU status to reset the high/low latch
LDA #$3F
STA PPU_ADDR ; write the high byte of $3F00 address
LDA #$00
STA PPU_ADDR ; write the low byte of $3F00 address
LDX #$00 ; X = 0
loadPalettes_Loop: ; do {
LDA palette, x ; A = *(palette + X)
STA PPU_DATA ; write to PPU
INX ; ++X
CPX #$20 ;
BNE loadPalettes_Loop ; } while( X != 0x20 );
RTS
loadSprites:
LDX #$00 ; X = 0
loadSprites_Loop: ; do {
LDA sprites, x ; A = *(sprites + X)
STA SPRITE_RAM, x ; *(SPRITE_RAM + X) = A
INX ; ++X
CPX #TOTAL_SPRITES ;
BNE loadSprites_Loop ; } while( X != TOTAL_SPRITES )
LDA #%10000000 ; enable NMI, sprites from Pattern Table 1
STA $2000
LDA #%00010000 ; enable sprites
STA $2001
RTS
readCtrl:
LDA #$01
STA CTRL_PORT
LDA #$00
STA CTRL_PORT ; now both ctrl buttons are latched
LDX #$08 ; initialize X for loop
readCtrlOne_Loop:
LDA CTRL_PORT
LSR A ; bit 0 -> CF
ROL ctrlOne ; bit 0 <- CF
DEX
BNE readCtrlOne_Loop
LDX #$08 ; initialize X for loop
readCtrlTwo_Loop:
LDA CTRL_PORT+1
LSR A ; bit 0 -> CF
ROL ctrlTwo ; bit 0 <- CF
DEX
BNE readCtrlTwo_Loop
RTS
resetBall:
LDA #$00
STA ballSpeedX
STA ballSpeedY
LDA #$01
STA turnPause
LDA ballAngle
EOR #$0F ; invert angle
STA ballAngle
LDA #$80
STA BALL_XPOS
STA BALL_YPOS
RTS
movePaddles:
; reset paddle movement variables
LDA #00;
STA paddle1Movement
STA paddle2Movement
; PADDLE 1 - react to button events
if_CtrlOneUp:
LDA ctrlOne
AND #BUTTON_UP
BEQ endif_CtrlOneUp ; if( ctrlOne & BUTTON_UP ) {
LDA #MOVING_UP ;
STA paddle1Movement ; paddle1Movement = MOVING_UP;
LDA PADDLE1_YPOS
SEC
SBC paddleSpeed
STA PADDLE1_YPOS ; *PADDLE1_YPOS -= paddleSpeed;
CMP #PADDLE_Y_TOP_LIMIT ;
BCS endif_CtrlOneUp ; if( *PADDLE1_YPOS < TOP_LIMIT ) {
LDA #PADDLE_Y_TOP_LIMIT ; *PADDLE1_YPOS = TOP_LIMIT;
STA PADDLE1_YPOS ; }
endif_CtrlOneUp: ; }
if_CtrlOneDown:
LDA ctrlOne
AND #BUTTON_DOWN ;
BEQ endif_CtrlOneDown ; if( ctrlOne & BUTTON_DOWN ) {
LDA #MOVING_DOWN ;
STA paddle1Movement ; paddle1Movement = MOVING_DOWN;
LDA PADDLE1_YPOS
CLC
ADC paddleSpeed
STA PADDLE1_YPOS ; *PADDLE1_YPOS += paddleSpeed;
LDA #PADDLE_Y_BOTTOM_LIMIT
CMP PADDLE1_YPOS ;
BCS endif_CtrlOneDown ; if( BOTTOM_LIMIT < *PADDLE1_YPOS ) {
STA PADDLE1_YPOS ; *PADDLE1_YPOS = BOTTOM_LIMIT;
endif_CtrlOneDown: ; }
; }
; PADDLE 2 - react to button events
if_CtrlTwoUp:
LDA ctrlTwo
AND #BUTTON_UP
BEQ endif_CtrlTwoUp ; if( ctrlTwo & BUTTON_UP ) {
LDA #MOVING_UP ;
STA paddle2Movement ; paddle2Movement = MOVING_UP;
LDA PADDLE2_YPOS
SEC
SBC paddleSpeed
STA PADDLE2_YPOS ; *PADDLE2_YPOS -= paddleSpeed;
CMP #PADDLE_Y_TOP_LIMIT ;
BCS endif_CtrlTwoUp ; if( *PADDLE2_YPOS < TOP_LIMIT ) {
LDA #PADDLE_Y_TOP_LIMIT ; *PADDLE2_YPOS = TOP_LIMIT;
STA PADDLE2_YPOS ; }
endif_CtrlTwoUp: ; }
if_CtrlTwoDown:
LDA ctrlTwo
AND #BUTTON_DOWN ;
BEQ endif_CtrlTwoDown ; if( ctrlTwo & BUTTON_DOWN ) {
LDA #MOVING_DOWN ;
STA paddle2Movement ; paddle2Movement = MOVING_DOWN;
LDA PADDLE2_YPOS
CLC
ADC paddleSpeed
STA PADDLE2_YPOS ; *PADDLE2_YPOS += paddleSpeed;
LDA #PADDLE_Y_BOTTOM_LIMIT
CMP PADDLE2_YPOS ;
BCS endif_CtrlTwoDown ; if( BOTTOM_LIMIT < *PADDLE2_YPOS ) {
STA PADDLE2_YPOS ; *PADDLE2_YPOS = BOTTOM_LIMIT;
endif_CtrlTwoDown: ; }
; }
RTS
moveBall:
LDA turnPause
BEQ endif_TurnPause ; if( turnPause ) {
LDA paddleTurn
AND #$01
BEQ else_Paddle1Turn ; if( paddleTurn & 1 ) {
LDA ctrlOne ; A = ctrlOne;
JMP endif_Paddle1Turn ;
else_Paddle1Turn: ; } else {
LDA ctrlTwo ; A = ctrlTwo;
endif_Paddle1Turn: ; }
AND #BUTTON_START
BEQ else_BallServed ; if( A & BUTTON_START ) {
LDA #$00
STA turnPause ; turnPause = 0;
INC paddleTurn ; ++paddleTurn;
LDA #BALL_DEFAULT_SPEED_X
STA ballSpeedX ; ballSpeedX = BALL_DEFAULT_SPEED_X;
LDA #BALL_DEFAULT_SPEED_Y
STA ballSpeedY ; ballSpeedY = BALL_DEFAULT_SPEED_Y;
JMP endif_BallServed ;
else_BallServed: ; } else {
RTS ; return;
endif_BallServed: ; }
endif_TurnPause: ; }
LDA ballAngle
AND #MOVING_LEFT
BEQ endif_ballLeft
if_ballLeft:
LDA BALL_XPOS
SEC
SBC ballSpeedX
STA BALL_XPOS ; BALL_XPOS -= ballSpeedX
CMP #LEFT_WALL
BCS notPastLeftWall ; if( BALL_XPOS < LEFT_WALL ) {
JSR resetBall ; resetBall();
RTS ; return;
notPastLeftWall: ; }
CMP #PADDLE1_X_LIMIT ; if( BALL_XPOS < PADDLE1_X_LIMIT )
BNE endif_ballLeft ; goto endif
LDA BALL_YPOS
CMP paddle1Top ; if( BALL_YPOS < paddle1Top )
BCC endif_ballLeft ; goto endif
CMP paddle1Bottom ; if( BALL_YPOS < paddle1Bottom )
BCS endif_ballLeft ; goto endif
; if ball hits paddle, bounce!
LDA #MOVING_LEFT ; here we bitmask the old MOVING and set it to the new one
EOR #$FF ; A = ~MOVING_LEFT
AND ballAngle ; A &= ballAngle
ORA #MOVING_RIGHT ; A |= MOVING_RIGHT
STA ballAngle ; ballAngle = A
if_paddle1Spin:
LDA paddle1Movement ; if( paddle1Movement == 0 )
BEQ endif_paddle1Spin ; goto endif
LDA ballAngle
AND paddle1Movement
AND #MOVING_UP ; if( ballAngle & paddle#Movement == MOVING_UP )
BNE endif_paddle1Spin ; goto endif
LDA ballAngle
AND paddle1Movement
AND #MOVING_DOWN ; if( ballAngle & paddle#Movement == MOVING_DOWN )
BNE endif_paddle1Spin ; goto endif
INC ballSpeedY ; ++ballSpeedY //apply spin!
JMP endif_ballLeft ; JMP to avoid resetting ballSpeedY
endif_paddle1Spin:
LDA #$01
STA ballSpeedY
endif_ballLeft:
LDA ballAngle
AND #MOVING_RIGHT
BEQ endif_ballRight
if_ballRight:
LDA BALL_XPOS
CLC
ADC ballSpeedX
STA BALL_XPOS
CMP #RIGHT_WALL
BCC notPastRightWall
JSR resetBall
RTS
notPastRightWall:
CMP #PADDLE2_X_LIMIT
BNE endif_ballRight
LDA BALL_YPOS
CMP paddle2Top
BCC endif_ballRight
CMP paddle2Bottom
BCS endif_ballRight
; if ball hits paddle, bounce!
LDA #MOVING_RIGHT
EOR #$FF
AND ballAngle
ORA #MOVING_LEFT
STA ballAngle
if_paddle2Spin:
LDA paddle2Movement
BEQ endif_paddle2Spin ; if( paddle#Movement == 0 ) goto endif
LDA ballAngle
AND paddle2Movement
AND #MOVING_UP ; if( ballAngle & paddle#Movement == MOVING_UP )
BNE endif_paddle2Spin ; goto endif
LDA ballAngle
AND paddle2Movement
AND #MOVING_DOWN ; if( ballAngle & paddle#Movement == MOVING_DOWN )
BNE endif_paddle2Spin ; goto endif
INC ballSpeedY ; ++ballSpeedY //apply spin!
JMP endif_ballLeft ; JMP to avoid resetting ballSpeedY
endif_paddle2Spin:
LDA #$01
STA ballSpeedY
endif_ballRight:
LDA ballAngle
AND #MOVING_UP
BEQ endif_ballUp
if_ballUp:
LDA BALL_YPOS
SEC
SBC ballSpeedY
STA BALL_YPOS
CMP #TOP_WALL
BCC if_bounceDown
LDA BALL_XPOS
start_paddle1BottomBounceTest:
CMP PADDLE1_XPOS
BNE start_paddle2BottomBounceTest
LDA paddle1Bottom
CMP BALL_YPOS
BEQ if_bounceDown
end_paddle1BottomBounceTest:
start_paddle2BottomBounceTest:
CMP PADDLE2_XPOS
BNE endif_ballUp
LDA paddle2Bottom
CMP BALL_YPOS
BNE endif_ballUp
end_paddle2BottomBounceTest:
if_bounceDown:
LDA #MOVING_UP
EOR #$FF
AND ballAngle ; turn off BALL_UP bit
ORA #MOVING_DOWN ; turn on BALL_DOWN bit
STA ballAngle
endif_bounceDown:
endif_ballUp:
LDA ballAngle
AND #MOVING_DOWN
BEQ endif_ballDown
if_ballDown:
LDA BALL_YPOS
CLC
ADC ballSpeedY
STA BALL_YPOS
CMP #BOTTOM_WALL
BCS if_bounceUp
LDA BALL_XPOS
start_paddle1TopBounceTest:
CMP PADDLE1_XPOS
BNE start_paddle2TopBounceTest
LDA paddle1Top
CMP BALL_YPOS
BEQ if_bounceUp
end_paddle1TopBounceTest:
start_paddle2TopBounceTest:
CMP PADDLE2_XPOS
BNE endif_ballDown
LDA paddle2Top
CMP BALL_YPOS
BNE endif_ballDown
end_paddle2TopBounceTest:
if_bounceUp:
LDA #MOVING_DOWN
EOR #$FF ; get inverse of BALL_DOWN
AND ballAngle ; turn off BALL_DOWN bit
ORA #MOVING_UP ; turn on BALL_UP bit
STA ballAngle
endif_bounceUp:
endif_ballDown:
RTS
updateSprites:
; PADDLE 1
LDA PADDLE1_YPOS ; update sprites relative to "home" sprite
CLC
ADC #$08
STA PADDLE1_YPOS + 4
CLC
ADC #$08
STA PADDLE1_YPOS + 8
CLC
ADC #$08
STA PADDLE1_YPOS + 12
; PADDLE 2
LDA PADDLE2_YPOS ; update sprites relative to "home" sprite
CLC
ADC #$08
STA PADDLE2_YPOS + 4
CLC
ADC #$08
STA PADDLE2_YPOS + 8
CLC
ADC #$08
STA PADDLE2_YPOS + 12
;update paddle variables
LDA PADDLE1_YPOS
SEC
SBC #$08
STA paddle1Top
CLC
ADC #$28
STA paddle1Bottom
LDA PADDLE2_YPOS
SEC
SBC #$08
STA paddle2Top
CLC
ADC #$28
STA paddle2Bottom
RTS
palette:
;background
.byte $0F,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$0F
;sprites
.byte $0F,$08,$28,$18,$31,$02,$38,$3C,$0F,$1C,$15,$14,$31,$02,$38,$3C
sprites:
; PADDLE 1
;vert tile attr horiz
.byte $80, $85, $00, $08
.byte $88, $86, $00, $08
.byte $90, $86, $00, $08
.byte $98, $86, $00, $08
; PADDLE 2
;vert tile attr horiz
.byte $80, $85, $00, $F0
.byte $88, $86, $00, $F0
.byte $90, $86, $00, $F0
.byte $98, $86, $00, $F0
; BALL
;vert tile attr horiz
.byte $80, $75, $00, $80
.segment "VECTORS"
.word 0, 0, 0 ;Unused, but needed to advance PC to $fffa.
.word NMI ;when an NMI happens (once per frame if enabled) the
;processor will jump to the label NMI:
.word RESET ;when the processor first turns on or is reset, it will jump
;to the label RESET:
.word 0 ;external interrupt IRQ (not currently used).
.segment "CHARS"
.incbin "mario.chr" ;includes 8KB graphics file from SMB1
|
; A140226: Binomial transform of [1, 3, 3, 1, 1, -1, 1, -1, 1, ...].
; 1,4,10,20,36,60,94,140,200,276,370,484,620,780,966,1180,1424,1700,2010,2356,2740,3164,3630,4140,4696,5300,5954,6660,7420,8236,9110,10044,11040,12100,13226,14420
mov $1,1
lpb $0
add $2,$0
sub $0,1
add $3,4
mov $1,$3
add $3,$2
lpe
|
; ------------------------------------------------------------------
; Music keyboard -- Use the keyboard to play notes via the PC speaker
; Use Z key rightwards for an octave
; ------------------------------------------------------------------
BITS 16
%INCLUDE "arkdev.inc"
ORG 32768
start:
call os_hide_cursor
call os_clear_screen
mov ax, mus_kbd_title_msg ; Set up screen
mov bx, mus_kbd_footer_msg
mov cx, WHITE_ON_LIGHT_RED
call os_draw_background
mov bl, BLACK_ON_WHITE ; White block to draw keyboard on
mov dh, 4
mov dl, 5
mov si, 69
mov di, 21
call os_draw_block
; Now lots of loops to draw the keyboard
mov dl, 24 ; Top line of box
mov dh, 6
call os_move_cursor
mov ah, 0Eh
mov al, 196
mov cx, 31
.loop1:
int 10h
loop .loop1
mov dl, 24 ; Bottom line of box
mov dh, 18
call os_move_cursor
mov ah, 0Eh
mov al, 196
mov cx, 31
.loop2:
int 10h
loop .loop2
mov dl, 23 ; Top-left corner
mov dh, 6
call os_move_cursor
mov al, 218
int 10h
mov dl, 55 ; Top-right corner
mov dh, 6
call os_move_cursor
mov al, 191
int 10h
mov dl, 23 ; Bottom-left corner
mov dh, 18
call os_move_cursor
mov al, 192
int 10h
mov dl, 55 ; Bottom-right corner
mov dh, 18
call os_move_cursor
mov al, 217
int 10h
mov dl, 23 ; Left-hand box line
mov dh, 7
mov al, 179
.loop3:
call os_move_cursor
int 10h
inc dh
cmp dh, 18
jne .loop3
mov dl, 55 ; Right-hand box line
mov dh, 7
mov al, 179
.loop4:
call os_move_cursor
int 10h
inc dh
cmp dh, 18
jne .loop4
mov dl, 23 ; Key-separating lines
.biggerloop:
add dl, 4
mov dh, 7
mov al, 179
.loop5:
call os_move_cursor
int 10h
inc dh
cmp dh, 18
jne .loop5
cmp dl, 51
jne .biggerloop
mov al, 194 ; Top of box line joiners
mov dh, 6
mov dl, 27
.loop6:
call os_move_cursor
int 10h
add dl, 4
cmp dl, 55
jne .loop6
mov al, 193 ; Bottom of box line joiners
mov dh, 18
mov dl, 27
.loop7:
call os_move_cursor
int 10h
add dl, 4
cmp dl, 55
jne .loop7
; And now for the black keys...
mov bl, WHITE_ON_BLACK
mov dh, 6
mov dl, 26
mov si, 3
mov di, 13
call os_draw_block
mov dh, 6
mov dl, 30
mov si, 3
mov di, 13
call os_draw_block
mov dh, 6
mov dl, 38
mov si, 3
mov di, 13
call os_draw_block
mov dh, 6
mov dl, 42
mov si, 3
mov di, 13
call os_draw_block
mov dh, 6
mov dl, 46
mov si, 3
mov di, 13
call os_draw_block
; And lastly, draw the labels on the keys indicating which
; (computer!) keys to press to get notes
mov ah, 0Eh
mov dh, 17
mov dl, 25
call os_move_cursor
mov al, 'Z'
int 10h
add dl, 4
call os_move_cursor
mov al, 'X'
int 10h
add dl, 4
call os_move_cursor
mov al, 'C'
int 10h
add dl, 4
call os_move_cursor
mov al, 'V'
int 10h
add dl, 4
call os_move_cursor
mov al, 'B'
int 10h
add dl, 4
call os_move_cursor
mov al, 'N'
int 10h
add dl, 4
call os_move_cursor
mov al, 'M'
int 10h
add dl, 4
call os_move_cursor
mov al, ','
int 10h
; Now the accidentals...
mov dh, 11
mov dl, 27
call os_move_cursor
mov al, 'S'
int 10h
add dl, 4
call os_move_cursor
mov al, 'D'
int 10h
add dl, 8
call os_move_cursor
mov al, 'G'
int 10h
add dl, 4
call os_move_cursor
mov al, 'H'
int 10h
add dl, 4
call os_move_cursor
mov al, 'J'
int 10h
; Phew! We've drawn all the keys now
.retry:
call os_wait_for_key
.nokey: ; Matching keys with notes
cmp al, 'z'
jne .s
mov ax, 4000
mov bx, 0
call os_speaker_tone
jmp .retry
.s:
cmp al, 's'
jne .x
mov ax, 3800
mov bx, 0
call os_speaker_tone
jmp .retry
.x:
cmp al, 'x'
jne .d
mov ax, 3600
mov bx, 0
call os_speaker_tone
jmp .retry
.d:
cmp al, 'd'
jne .c
mov ax, 3400
mov bx, 0
call os_speaker_tone
jmp .retry
.c:
cmp al, 'c'
jne .v
mov ax, 3200
mov bx, 0
call os_speaker_tone
jmp .retry
.v:
cmp al, 'v'
jne .g
mov ax, 3000
mov bx, 0
call os_speaker_tone
jmp .retry
.g:
cmp al, 'g'
jne .b
mov ax, 2850
mov bx, 0
call os_speaker_tone
jmp .retry
.b:
cmp al, 'b'
jne .h
mov ax, 2700
mov bx, 0
call os_speaker_tone
jmp .retry
.h:
cmp al, 'h'
jne .n
mov ax, 2550
mov bx, 0
call os_speaker_tone
jmp .retry
.n:
cmp al, 'n'
jne .j
mov ax, 2400
mov bx, 0
call os_speaker_tone
jmp .retry
.j:
cmp al, 'j'
jne .m
mov ax, 2250
mov bx, 0
call os_speaker_tone
jmp .retry
.m:
cmp al, 'm'
jne .comma
mov ax, 2100
mov bx, 0
call os_speaker_tone
jmp .retry
.comma:
cmp al, ','
jne .space
mov ax, 2000
mov bx, 0
call os_speaker_tone
jmp .retry
.space:
cmp al, ' '
jne .esc
call os_speaker_off
jmp .retry
.esc:
cmp al, 27
je .end
jmp .nowt
.nowt:
jmp .retry
.end:
call os_speaker_off
call os_clear_screen
call os_show_cursor
ret ; Back to OS
mus_kbd_title_msg db 'ArkOS Music Keyboard (PC speaker sound)', 0
mus_kbd_footer_msg db 'Hit keys to play notes, space to silence a note, and Esc to quit', 0
; ------------------------------------------------------------------
|
; A175926: Sum of divisors of cubes.
; Submitted by Christian Krause
; 1,15,40,127,156,600,400,1023,1093,2340,1464,5080,2380,6000,6240,8191,5220,16395,7240,19812,16000,21960,12720,40920,19531,35700,29524,50800,25260,93600,30784,65535,58560,78300,62400,138811,52060,108600,95200,159588,70644,240000,81400,185928,170508,190800,106080,327640,137257,292965,208800,302260,151740,442860,228384,409200,289600,378900,208920,792480,230764,461760,437200,524287,371280,878400,305320,662940,508800,936000,363024,1118139,394420,780900,781240,919480,585600,1428000,499360,1277796
add $0,1
pow $0,3
mov $1,1
lpb $0
mov $3,$0
lpb $3
mov $4,$0
mov $7,$2
cmp $7,0
add $2,$7
mod $4,$2
cmp $4,0
cmp $4,0
mov $5,$2
add $2,1
cmp $5,1
max $4,$5
sub $3,$4
lpe
mov $5,1
lpb $0
add $6,1
lpb $6
dif $0,$2
mul $5,$2
div $6,10
lpe
add $5,1
trn $6,4
lpe
mul $1,$5
lpe
mov $0,$1
|
GLOBAL systemCall
section .text
systemCall:
push rbp
mov rbp, rsp
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
int 80h
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 rbx
mov rsp, rbp
pop rbp
ret
|
; A164657: Denominators of partial sums of Theta(5) = sum(1/(2*j-1)^5, j=1..infinity).
; Submitted by Christian Krause
; 1,243,759375,12762815625,3101364196875,499477805270915625,185452612752454075153125,185452612752454075153125,263316190384861185784690603125,651996955695764397260286617707209375,651996955695764397260286617707209375,4196476041813743307955464949873473110315625
seq $0,25547 ; Least common multiple of {1,3,5,...,2n-1}.
pow $0,5
|
default rel
%define XMMWORD
%define YMMWORD
%define ZMMWORD
section .text code align=64
EXTERN OPENSSL_ia32cap_P
ALIGN 64
$L$zero:
DD 0,0,0,0
$L$one:
DD 1,0,0,0
$L$inc:
DD 0,1,2,3
$L$four:
DD 4,4,4,4
$L$incy:
DD 0,2,4,6,1,3,5,7
$L$eight:
DD 8,8,8,8,8,8,8,8
$L$rot16:
DB 0x2,0x3,0x0,0x1,0x6,0x7,0x4,0x5,0xa,0xb,0x8,0x9,0xe,0xf,0xc,0xd
$L$rot24:
DB 0x3,0x0,0x1,0x2,0x7,0x4,0x5,0x6,0xb,0x8,0x9,0xa,0xf,0xc,0xd,0xe
$L$twoy:
DD 2,0,0,0,2,0,0,0
ALIGN 64
$L$zeroz:
DD 0,0,0,0,1,0,0,0,2,0,0,0,3,0,0,0
$L$fourz:
DD 4,0,0,0,4,0,0,0,4,0,0,0,4,0,0,0
$L$incz:
DD 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
$L$sixteen:
DD 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16
$L$sigma:
DB 101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107
DB 0
DB 67,104,97,67,104,97,50,48,32,102,111,114,32,120,56,54
DB 95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32
DB 98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115
DB 108,46,111,114,103,62,0
global ChaCha20_ctr32
ALIGN 64
ChaCha20_ctr32:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_ChaCha20_ctr32:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
cmp rdx,0
je NEAR $L$no_data
mov r10,QWORD[((OPENSSL_ia32cap_P+4))]
bt r10,48
jc NEAR $L$ChaCha20_avx512
test r10,r10
js NEAR $L$ChaCha20_avx512vl
test r10d,512
jnz NEAR $L$ChaCha20_ssse3
push rbx
push rbp
push r12
push r13
push r14
push r15
sub rsp,64+24
$L$ctr32_body:
movdqu xmm1,XMMWORD[rcx]
movdqu xmm2,XMMWORD[16+rcx]
movdqu xmm3,XMMWORD[r8]
movdqa xmm4,XMMWORD[$L$one]
movdqa XMMWORD[16+rsp],xmm1
movdqa XMMWORD[32+rsp],xmm2
movdqa XMMWORD[48+rsp],xmm3
mov rbp,rdx
jmp NEAR $L$oop_outer
ALIGN 32
$L$oop_outer:
mov eax,0x61707865
mov ebx,0x3320646e
mov ecx,0x79622d32
mov edx,0x6b206574
mov r8d,DWORD[16+rsp]
mov r9d,DWORD[20+rsp]
mov r10d,DWORD[24+rsp]
mov r11d,DWORD[28+rsp]
movd r12d,xmm3
mov r13d,DWORD[52+rsp]
mov r14d,DWORD[56+rsp]
mov r15d,DWORD[60+rsp]
mov QWORD[((64+0))+rsp],rbp
mov ebp,10
mov QWORD[((64+8))+rsp],rsi
DB 102,72,15,126,214
mov QWORD[((64+16))+rsp],rdi
mov rdi,rsi
shr rdi,32
jmp NEAR $L$oop
ALIGN 32
$L$oop:
add eax,r8d
xor r12d,eax
rol r12d,16
add ebx,r9d
xor r13d,ebx
rol r13d,16
add esi,r12d
xor r8d,esi
rol r8d,12
add edi,r13d
xor r9d,edi
rol r9d,12
add eax,r8d
xor r12d,eax
rol r12d,8
add ebx,r9d
xor r13d,ebx
rol r13d,8
add esi,r12d
xor r8d,esi
rol r8d,7
add edi,r13d
xor r9d,edi
rol r9d,7
mov DWORD[32+rsp],esi
mov DWORD[36+rsp],edi
mov esi,DWORD[40+rsp]
mov edi,DWORD[44+rsp]
add ecx,r10d
xor r14d,ecx
rol r14d,16
add edx,r11d
xor r15d,edx
rol r15d,16
add esi,r14d
xor r10d,esi
rol r10d,12
add edi,r15d
xor r11d,edi
rol r11d,12
add ecx,r10d
xor r14d,ecx
rol r14d,8
add edx,r11d
xor r15d,edx
rol r15d,8
add esi,r14d
xor r10d,esi
rol r10d,7
add edi,r15d
xor r11d,edi
rol r11d,7
add eax,r9d
xor r15d,eax
rol r15d,16
add ebx,r10d
xor r12d,ebx
rol r12d,16
add esi,r15d
xor r9d,esi
rol r9d,12
add edi,r12d
xor r10d,edi
rol r10d,12
add eax,r9d
xor r15d,eax
rol r15d,8
add ebx,r10d
xor r12d,ebx
rol r12d,8
add esi,r15d
xor r9d,esi
rol r9d,7
add edi,r12d
xor r10d,edi
rol r10d,7
mov DWORD[40+rsp],esi
mov DWORD[44+rsp],edi
mov esi,DWORD[32+rsp]
mov edi,DWORD[36+rsp]
add ecx,r11d
xor r13d,ecx
rol r13d,16
add edx,r8d
xor r14d,edx
rol r14d,16
add esi,r13d
xor r11d,esi
rol r11d,12
add edi,r14d
xor r8d,edi
rol r8d,12
add ecx,r11d
xor r13d,ecx
rol r13d,8
add edx,r8d
xor r14d,edx
rol r14d,8
add esi,r13d
xor r11d,esi
rol r11d,7
add edi,r14d
xor r8d,edi
rol r8d,7
dec ebp
jnz NEAR $L$oop
mov DWORD[36+rsp],edi
mov DWORD[32+rsp],esi
mov rbp,QWORD[64+rsp]
movdqa xmm1,xmm2
mov rsi,QWORD[((64+8))+rsp]
paddd xmm3,xmm4
mov rdi,QWORD[((64+16))+rsp]
add eax,0x61707865
add ebx,0x3320646e
add ecx,0x79622d32
add edx,0x6b206574
add r8d,DWORD[16+rsp]
add r9d,DWORD[20+rsp]
add r10d,DWORD[24+rsp]
add r11d,DWORD[28+rsp]
add r12d,DWORD[48+rsp]
add r13d,DWORD[52+rsp]
add r14d,DWORD[56+rsp]
add r15d,DWORD[60+rsp]
paddd xmm1,XMMWORD[32+rsp]
cmp rbp,64
jb NEAR $L$tail
xor eax,DWORD[rsi]
xor ebx,DWORD[4+rsi]
xor ecx,DWORD[8+rsi]
xor edx,DWORD[12+rsi]
xor r8d,DWORD[16+rsi]
xor r9d,DWORD[20+rsi]
xor r10d,DWORD[24+rsi]
xor r11d,DWORD[28+rsi]
movdqu xmm0,XMMWORD[32+rsi]
xor r12d,DWORD[48+rsi]
xor r13d,DWORD[52+rsi]
xor r14d,DWORD[56+rsi]
xor r15d,DWORD[60+rsi]
lea rsi,[64+rsi]
pxor xmm0,xmm1
movdqa XMMWORD[32+rsp],xmm2
movd DWORD[48+rsp],xmm3
mov DWORD[rdi],eax
mov DWORD[4+rdi],ebx
mov DWORD[8+rdi],ecx
mov DWORD[12+rdi],edx
mov DWORD[16+rdi],r8d
mov DWORD[20+rdi],r9d
mov DWORD[24+rdi],r10d
mov DWORD[28+rdi],r11d
movdqu XMMWORD[32+rdi],xmm0
mov DWORD[48+rdi],r12d
mov DWORD[52+rdi],r13d
mov DWORD[56+rdi],r14d
mov DWORD[60+rdi],r15d
lea rdi,[64+rdi]
sub rbp,64
jnz NEAR $L$oop_outer
jmp NEAR $L$done
ALIGN 16
$L$tail:
mov DWORD[rsp],eax
mov DWORD[4+rsp],ebx
xor rbx,rbx
mov DWORD[8+rsp],ecx
mov DWORD[12+rsp],edx
mov DWORD[16+rsp],r8d
mov DWORD[20+rsp],r9d
mov DWORD[24+rsp],r10d
mov DWORD[28+rsp],r11d
movdqa XMMWORD[32+rsp],xmm1
mov DWORD[48+rsp],r12d
mov DWORD[52+rsp],r13d
mov DWORD[56+rsp],r14d
mov DWORD[60+rsp],r15d
$L$oop_tail:
movzx eax,BYTE[rbx*1+rsi]
movzx edx,BYTE[rbx*1+rsp]
lea rbx,[1+rbx]
xor eax,edx
mov BYTE[((-1))+rbx*1+rdi],al
dec rbp
jnz NEAR $L$oop_tail
$L$done:
lea rsi,[((64+24+48))+rsp]
mov r15,QWORD[((-48))+rsi]
mov r14,QWORD[((-40))+rsi]
mov r13,QWORD[((-32))+rsi]
mov r12,QWORD[((-24))+rsi]
mov rbp,QWORD[((-16))+rsi]
mov rbx,QWORD[((-8))+rsi]
lea rsp,[rsi]
$L$no_data:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_ChaCha20_ctr32:
ALIGN 32
ChaCha20_ssse3:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_ChaCha20_ssse3:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
$L$ChaCha20_ssse3:
mov r9,rsp
test r10d,2048
jnz NEAR $L$ChaCha20_4xop
cmp rdx,128
je NEAR $L$ChaCha20_128
ja NEAR $L$ChaCha20_4x
$L$do_sse3_after_all:
sub rsp,64+168
movaps XMMWORD[(-40)+r9],xmm6
movaps XMMWORD[(-24)+r9],xmm7
$L$ssse3_body:
movdqa xmm0,XMMWORD[$L$sigma]
movdqu xmm1,XMMWORD[rcx]
movdqu xmm2,XMMWORD[16+rcx]
movdqu xmm3,XMMWORD[r8]
movdqa xmm6,XMMWORD[$L$rot16]
movdqa xmm7,XMMWORD[$L$rot24]
movdqa XMMWORD[rsp],xmm0
movdqa XMMWORD[16+rsp],xmm1
movdqa XMMWORD[32+rsp],xmm2
movdqa XMMWORD[48+rsp],xmm3
mov r8,10
jmp NEAR $L$oop_ssse3
ALIGN 32
$L$oop_outer_ssse3:
movdqa xmm3,XMMWORD[$L$one]
movdqa xmm0,XMMWORD[rsp]
movdqa xmm1,XMMWORD[16+rsp]
movdqa xmm2,XMMWORD[32+rsp]
paddd xmm3,XMMWORD[48+rsp]
mov r8,10
movdqa XMMWORD[48+rsp],xmm3
jmp NEAR $L$oop_ssse3
ALIGN 32
$L$oop_ssse3:
paddd xmm0,xmm1
pxor xmm3,xmm0
DB 102,15,56,0,222
paddd xmm2,xmm3
pxor xmm1,xmm2
movdqa xmm4,xmm1
psrld xmm1,20
pslld xmm4,12
por xmm1,xmm4
paddd xmm0,xmm1
pxor xmm3,xmm0
DB 102,15,56,0,223
paddd xmm2,xmm3
pxor xmm1,xmm2
movdqa xmm4,xmm1
psrld xmm1,25
pslld xmm4,7
por xmm1,xmm4
pshufd xmm2,xmm2,78
pshufd xmm1,xmm1,57
pshufd xmm3,xmm3,147
nop
paddd xmm0,xmm1
pxor xmm3,xmm0
DB 102,15,56,0,222
paddd xmm2,xmm3
pxor xmm1,xmm2
movdqa xmm4,xmm1
psrld xmm1,20
pslld xmm4,12
por xmm1,xmm4
paddd xmm0,xmm1
pxor xmm3,xmm0
DB 102,15,56,0,223
paddd xmm2,xmm3
pxor xmm1,xmm2
movdqa xmm4,xmm1
psrld xmm1,25
pslld xmm4,7
por xmm1,xmm4
pshufd xmm2,xmm2,78
pshufd xmm1,xmm1,147
pshufd xmm3,xmm3,57
dec r8
jnz NEAR $L$oop_ssse3
paddd xmm0,XMMWORD[rsp]
paddd xmm1,XMMWORD[16+rsp]
paddd xmm2,XMMWORD[32+rsp]
paddd xmm3,XMMWORD[48+rsp]
cmp rdx,64
jb NEAR $L$tail_ssse3
movdqu xmm4,XMMWORD[rsi]
movdqu xmm5,XMMWORD[16+rsi]
pxor xmm0,xmm4
movdqu xmm4,XMMWORD[32+rsi]
pxor xmm1,xmm5
movdqu xmm5,XMMWORD[48+rsi]
lea rsi,[64+rsi]
pxor xmm2,xmm4
pxor xmm3,xmm5
movdqu XMMWORD[rdi],xmm0
movdqu XMMWORD[16+rdi],xmm1
movdqu XMMWORD[32+rdi],xmm2
movdqu XMMWORD[48+rdi],xmm3
lea rdi,[64+rdi]
sub rdx,64
jnz NEAR $L$oop_outer_ssse3
jmp NEAR $L$done_ssse3
ALIGN 16
$L$tail_ssse3:
movdqa XMMWORD[rsp],xmm0
movdqa XMMWORD[16+rsp],xmm1
movdqa XMMWORD[32+rsp],xmm2
movdqa XMMWORD[48+rsp],xmm3
xor r8,r8
$L$oop_tail_ssse3:
movzx eax,BYTE[r8*1+rsi]
movzx ecx,BYTE[r8*1+rsp]
lea r8,[1+r8]
xor eax,ecx
mov BYTE[((-1))+r8*1+rdi],al
dec rdx
jnz NEAR $L$oop_tail_ssse3
$L$done_ssse3:
movaps xmm6,XMMWORD[((-40))+r9]
movaps xmm7,XMMWORD[((-24))+r9]
lea rsp,[r9]
$L$ssse3_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_ChaCha20_ssse3:
ALIGN 32
ChaCha20_128:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_ChaCha20_128:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
$L$ChaCha20_128:
mov r9,rsp
sub rsp,64+104
movaps XMMWORD[(-104)+r9],xmm6
movaps XMMWORD[(-88)+r9],xmm7
movaps XMMWORD[(-72)+r9],xmm8
movaps XMMWORD[(-56)+r9],xmm9
movaps XMMWORD[(-40)+r9],xmm10
movaps XMMWORD[(-24)+r9],xmm11
$L$128_body:
movdqa xmm8,XMMWORD[$L$sigma]
movdqu xmm9,XMMWORD[rcx]
movdqu xmm2,XMMWORD[16+rcx]
movdqu xmm3,XMMWORD[r8]
movdqa xmm1,XMMWORD[$L$one]
movdqa xmm6,XMMWORD[$L$rot16]
movdqa xmm7,XMMWORD[$L$rot24]
movdqa xmm10,xmm8
movdqa XMMWORD[rsp],xmm8
movdqa xmm11,xmm9
movdqa XMMWORD[16+rsp],xmm9
movdqa xmm0,xmm2
movdqa XMMWORD[32+rsp],xmm2
paddd xmm1,xmm3
movdqa XMMWORD[48+rsp],xmm3
mov r8,10
jmp NEAR $L$oop_128
ALIGN 32
$L$oop_128:
paddd xmm8,xmm9
pxor xmm3,xmm8
paddd xmm10,xmm11
pxor xmm1,xmm10
DB 102,15,56,0,222
DB 102,15,56,0,206
paddd xmm2,xmm3
paddd xmm0,xmm1
pxor xmm9,xmm2
pxor xmm11,xmm0
movdqa xmm4,xmm9
psrld xmm9,20
movdqa xmm5,xmm11
pslld xmm4,12
psrld xmm11,20
por xmm9,xmm4
pslld xmm5,12
por xmm11,xmm5
paddd xmm8,xmm9
pxor xmm3,xmm8
paddd xmm10,xmm11
pxor xmm1,xmm10
DB 102,15,56,0,223
DB 102,15,56,0,207
paddd xmm2,xmm3
paddd xmm0,xmm1
pxor xmm9,xmm2
pxor xmm11,xmm0
movdqa xmm4,xmm9
psrld xmm9,25
movdqa xmm5,xmm11
pslld xmm4,7
psrld xmm11,25
por xmm9,xmm4
pslld xmm5,7
por xmm11,xmm5
pshufd xmm2,xmm2,78
pshufd xmm9,xmm9,57
pshufd xmm3,xmm3,147
pshufd xmm0,xmm0,78
pshufd xmm11,xmm11,57
pshufd xmm1,xmm1,147
paddd xmm8,xmm9
pxor xmm3,xmm8
paddd xmm10,xmm11
pxor xmm1,xmm10
DB 102,15,56,0,222
DB 102,15,56,0,206
paddd xmm2,xmm3
paddd xmm0,xmm1
pxor xmm9,xmm2
pxor xmm11,xmm0
movdqa xmm4,xmm9
psrld xmm9,20
movdqa xmm5,xmm11
pslld xmm4,12
psrld xmm11,20
por xmm9,xmm4
pslld xmm5,12
por xmm11,xmm5
paddd xmm8,xmm9
pxor xmm3,xmm8
paddd xmm10,xmm11
pxor xmm1,xmm10
DB 102,15,56,0,223
DB 102,15,56,0,207
paddd xmm2,xmm3
paddd xmm0,xmm1
pxor xmm9,xmm2
pxor xmm11,xmm0
movdqa xmm4,xmm9
psrld xmm9,25
movdqa xmm5,xmm11
pslld xmm4,7
psrld xmm11,25
por xmm9,xmm4
pslld xmm5,7
por xmm11,xmm5
pshufd xmm2,xmm2,78
pshufd xmm9,xmm9,147
pshufd xmm3,xmm3,57
pshufd xmm0,xmm0,78
pshufd xmm11,xmm11,147
pshufd xmm1,xmm1,57
dec r8
jnz NEAR $L$oop_128
paddd xmm8,XMMWORD[rsp]
paddd xmm9,XMMWORD[16+rsp]
paddd xmm2,XMMWORD[32+rsp]
paddd xmm3,XMMWORD[48+rsp]
paddd xmm1,XMMWORD[$L$one]
paddd xmm10,XMMWORD[rsp]
paddd xmm11,XMMWORD[16+rsp]
paddd xmm0,XMMWORD[32+rsp]
paddd xmm1,XMMWORD[48+rsp]
movdqu xmm4,XMMWORD[rsi]
movdqu xmm5,XMMWORD[16+rsi]
pxor xmm8,xmm4
movdqu xmm4,XMMWORD[32+rsi]
pxor xmm9,xmm5
movdqu xmm5,XMMWORD[48+rsi]
pxor xmm2,xmm4
movdqu xmm4,XMMWORD[64+rsi]
pxor xmm3,xmm5
movdqu xmm5,XMMWORD[80+rsi]
pxor xmm10,xmm4
movdqu xmm4,XMMWORD[96+rsi]
pxor xmm11,xmm5
movdqu xmm5,XMMWORD[112+rsi]
pxor xmm0,xmm4
pxor xmm1,xmm5
movdqu XMMWORD[rdi],xmm8
movdqu XMMWORD[16+rdi],xmm9
movdqu XMMWORD[32+rdi],xmm2
movdqu XMMWORD[48+rdi],xmm3
movdqu XMMWORD[64+rdi],xmm10
movdqu XMMWORD[80+rdi],xmm11
movdqu XMMWORD[96+rdi],xmm0
movdqu XMMWORD[112+rdi],xmm1
movaps xmm6,XMMWORD[((-104))+r9]
movaps xmm7,XMMWORD[((-88))+r9]
movaps xmm8,XMMWORD[((-72))+r9]
movaps xmm9,XMMWORD[((-56))+r9]
movaps xmm10,XMMWORD[((-40))+r9]
movaps xmm11,XMMWORD[((-24))+r9]
lea rsp,[r9]
$L$128_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_ChaCha20_128:
ALIGN 32
ChaCha20_4x:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_ChaCha20_4x:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
$L$ChaCha20_4x:
mov r9,rsp
mov r11,r10
shr r10,32
test r10,32
jnz NEAR $L$ChaCha20_8x
cmp rdx,192
ja NEAR $L$proceed4x
and r11,71303168
cmp r11,4194304
je NEAR $L$do_sse3_after_all
$L$proceed4x:
sub rsp,0x140+168
movaps XMMWORD[(-168)+r9],xmm6
movaps XMMWORD[(-152)+r9],xmm7
movaps XMMWORD[(-136)+r9],xmm8
movaps XMMWORD[(-120)+r9],xmm9
movaps XMMWORD[(-104)+r9],xmm10
movaps XMMWORD[(-88)+r9],xmm11
movaps XMMWORD[(-72)+r9],xmm12
movaps XMMWORD[(-56)+r9],xmm13
movaps XMMWORD[(-40)+r9],xmm14
movaps XMMWORD[(-24)+r9],xmm15
$L$4x_body:
movdqa xmm11,XMMWORD[$L$sigma]
movdqu xmm15,XMMWORD[rcx]
movdqu xmm7,XMMWORD[16+rcx]
movdqu xmm3,XMMWORD[r8]
lea rcx,[256+rsp]
lea r10,[$L$rot16]
lea r11,[$L$rot24]
pshufd xmm8,xmm11,0x00
pshufd xmm9,xmm11,0x55
movdqa XMMWORD[64+rsp],xmm8
pshufd xmm10,xmm11,0xaa
movdqa XMMWORD[80+rsp],xmm9
pshufd xmm11,xmm11,0xff
movdqa XMMWORD[96+rsp],xmm10
movdqa XMMWORD[112+rsp],xmm11
pshufd xmm12,xmm15,0x00
pshufd xmm13,xmm15,0x55
movdqa XMMWORD[(128-256)+rcx],xmm12
pshufd xmm14,xmm15,0xaa
movdqa XMMWORD[(144-256)+rcx],xmm13
pshufd xmm15,xmm15,0xff
movdqa XMMWORD[(160-256)+rcx],xmm14
movdqa XMMWORD[(176-256)+rcx],xmm15
pshufd xmm4,xmm7,0x00
pshufd xmm5,xmm7,0x55
movdqa XMMWORD[(192-256)+rcx],xmm4
pshufd xmm6,xmm7,0xaa
movdqa XMMWORD[(208-256)+rcx],xmm5
pshufd xmm7,xmm7,0xff
movdqa XMMWORD[(224-256)+rcx],xmm6
movdqa XMMWORD[(240-256)+rcx],xmm7
pshufd xmm0,xmm3,0x00
pshufd xmm1,xmm3,0x55
paddd xmm0,XMMWORD[$L$inc]
pshufd xmm2,xmm3,0xaa
movdqa XMMWORD[(272-256)+rcx],xmm1
pshufd xmm3,xmm3,0xff
movdqa XMMWORD[(288-256)+rcx],xmm2
movdqa XMMWORD[(304-256)+rcx],xmm3
jmp NEAR $L$oop_enter4x
ALIGN 32
$L$oop_outer4x:
movdqa xmm8,XMMWORD[64+rsp]
movdqa xmm9,XMMWORD[80+rsp]
movdqa xmm10,XMMWORD[96+rsp]
movdqa xmm11,XMMWORD[112+rsp]
movdqa xmm12,XMMWORD[((128-256))+rcx]
movdqa xmm13,XMMWORD[((144-256))+rcx]
movdqa xmm14,XMMWORD[((160-256))+rcx]
movdqa xmm15,XMMWORD[((176-256))+rcx]
movdqa xmm4,XMMWORD[((192-256))+rcx]
movdqa xmm5,XMMWORD[((208-256))+rcx]
movdqa xmm6,XMMWORD[((224-256))+rcx]
movdqa xmm7,XMMWORD[((240-256))+rcx]
movdqa xmm0,XMMWORD[((256-256))+rcx]
movdqa xmm1,XMMWORD[((272-256))+rcx]
movdqa xmm2,XMMWORD[((288-256))+rcx]
movdqa xmm3,XMMWORD[((304-256))+rcx]
paddd xmm0,XMMWORD[$L$four]
$L$oop_enter4x:
movdqa XMMWORD[32+rsp],xmm6
movdqa XMMWORD[48+rsp],xmm7
movdqa xmm7,XMMWORD[r10]
mov eax,10
movdqa XMMWORD[(256-256)+rcx],xmm0
jmp NEAR $L$oop4x
ALIGN 32
$L$oop4x:
paddd xmm8,xmm12
paddd xmm9,xmm13
pxor xmm0,xmm8
pxor xmm1,xmm9
DB 102,15,56,0,199
DB 102,15,56,0,207
paddd xmm4,xmm0
paddd xmm5,xmm1
pxor xmm12,xmm4
pxor xmm13,xmm5
movdqa xmm6,xmm12
pslld xmm12,12
psrld xmm6,20
movdqa xmm7,xmm13
pslld xmm13,12
por xmm12,xmm6
psrld xmm7,20
movdqa xmm6,XMMWORD[r11]
por xmm13,xmm7
paddd xmm8,xmm12
paddd xmm9,xmm13
pxor xmm0,xmm8
pxor xmm1,xmm9
DB 102,15,56,0,198
DB 102,15,56,0,206
paddd xmm4,xmm0
paddd xmm5,xmm1
pxor xmm12,xmm4
pxor xmm13,xmm5
movdqa xmm7,xmm12
pslld xmm12,7
psrld xmm7,25
movdqa xmm6,xmm13
pslld xmm13,7
por xmm12,xmm7
psrld xmm6,25
movdqa xmm7,XMMWORD[r10]
por xmm13,xmm6
movdqa XMMWORD[rsp],xmm4
movdqa XMMWORD[16+rsp],xmm5
movdqa xmm4,XMMWORD[32+rsp]
movdqa xmm5,XMMWORD[48+rsp]
paddd xmm10,xmm14
paddd xmm11,xmm15
pxor xmm2,xmm10
pxor xmm3,xmm11
DB 102,15,56,0,215
DB 102,15,56,0,223
paddd xmm4,xmm2
paddd xmm5,xmm3
pxor xmm14,xmm4
pxor xmm15,xmm5
movdqa xmm6,xmm14
pslld xmm14,12
psrld xmm6,20
movdqa xmm7,xmm15
pslld xmm15,12
por xmm14,xmm6
psrld xmm7,20
movdqa xmm6,XMMWORD[r11]
por xmm15,xmm7
paddd xmm10,xmm14
paddd xmm11,xmm15
pxor xmm2,xmm10
pxor xmm3,xmm11
DB 102,15,56,0,214
DB 102,15,56,0,222
paddd xmm4,xmm2
paddd xmm5,xmm3
pxor xmm14,xmm4
pxor xmm15,xmm5
movdqa xmm7,xmm14
pslld xmm14,7
psrld xmm7,25
movdqa xmm6,xmm15
pslld xmm15,7
por xmm14,xmm7
psrld xmm6,25
movdqa xmm7,XMMWORD[r10]
por xmm15,xmm6
paddd xmm8,xmm13
paddd xmm9,xmm14
pxor xmm3,xmm8
pxor xmm0,xmm9
DB 102,15,56,0,223
DB 102,15,56,0,199
paddd xmm4,xmm3
paddd xmm5,xmm0
pxor xmm13,xmm4
pxor xmm14,xmm5
movdqa xmm6,xmm13
pslld xmm13,12
psrld xmm6,20
movdqa xmm7,xmm14
pslld xmm14,12
por xmm13,xmm6
psrld xmm7,20
movdqa xmm6,XMMWORD[r11]
por xmm14,xmm7
paddd xmm8,xmm13
paddd xmm9,xmm14
pxor xmm3,xmm8
pxor xmm0,xmm9
DB 102,15,56,0,222
DB 102,15,56,0,198
paddd xmm4,xmm3
paddd xmm5,xmm0
pxor xmm13,xmm4
pxor xmm14,xmm5
movdqa xmm7,xmm13
pslld xmm13,7
psrld xmm7,25
movdqa xmm6,xmm14
pslld xmm14,7
por xmm13,xmm7
psrld xmm6,25
movdqa xmm7,XMMWORD[r10]
por xmm14,xmm6
movdqa XMMWORD[32+rsp],xmm4
movdqa XMMWORD[48+rsp],xmm5
movdqa xmm4,XMMWORD[rsp]
movdqa xmm5,XMMWORD[16+rsp]
paddd xmm10,xmm15
paddd xmm11,xmm12
pxor xmm1,xmm10
pxor xmm2,xmm11
DB 102,15,56,0,207
DB 102,15,56,0,215
paddd xmm4,xmm1
paddd xmm5,xmm2
pxor xmm15,xmm4
pxor xmm12,xmm5
movdqa xmm6,xmm15
pslld xmm15,12
psrld xmm6,20
movdqa xmm7,xmm12
pslld xmm12,12
por xmm15,xmm6
psrld xmm7,20
movdqa xmm6,XMMWORD[r11]
por xmm12,xmm7
paddd xmm10,xmm15
paddd xmm11,xmm12
pxor xmm1,xmm10
pxor xmm2,xmm11
DB 102,15,56,0,206
DB 102,15,56,0,214
paddd xmm4,xmm1
paddd xmm5,xmm2
pxor xmm15,xmm4
pxor xmm12,xmm5
movdqa xmm7,xmm15
pslld xmm15,7
psrld xmm7,25
movdqa xmm6,xmm12
pslld xmm12,7
por xmm15,xmm7
psrld xmm6,25
movdqa xmm7,XMMWORD[r10]
por xmm12,xmm6
dec eax
jnz NEAR $L$oop4x
paddd xmm8,XMMWORD[64+rsp]
paddd xmm9,XMMWORD[80+rsp]
paddd xmm10,XMMWORD[96+rsp]
paddd xmm11,XMMWORD[112+rsp]
movdqa xmm6,xmm8
punpckldq xmm8,xmm9
movdqa xmm7,xmm10
punpckldq xmm10,xmm11
punpckhdq xmm6,xmm9
punpckhdq xmm7,xmm11
movdqa xmm9,xmm8
punpcklqdq xmm8,xmm10
movdqa xmm11,xmm6
punpcklqdq xmm6,xmm7
punpckhqdq xmm9,xmm10
punpckhqdq xmm11,xmm7
paddd xmm12,XMMWORD[((128-256))+rcx]
paddd xmm13,XMMWORD[((144-256))+rcx]
paddd xmm14,XMMWORD[((160-256))+rcx]
paddd xmm15,XMMWORD[((176-256))+rcx]
movdqa XMMWORD[rsp],xmm8
movdqa XMMWORD[16+rsp],xmm9
movdqa xmm8,XMMWORD[32+rsp]
movdqa xmm9,XMMWORD[48+rsp]
movdqa xmm10,xmm12
punpckldq xmm12,xmm13
movdqa xmm7,xmm14
punpckldq xmm14,xmm15
punpckhdq xmm10,xmm13
punpckhdq xmm7,xmm15
movdqa xmm13,xmm12
punpcklqdq xmm12,xmm14
movdqa xmm15,xmm10
punpcklqdq xmm10,xmm7
punpckhqdq xmm13,xmm14
punpckhqdq xmm15,xmm7
paddd xmm4,XMMWORD[((192-256))+rcx]
paddd xmm5,XMMWORD[((208-256))+rcx]
paddd xmm8,XMMWORD[((224-256))+rcx]
paddd xmm9,XMMWORD[((240-256))+rcx]
movdqa XMMWORD[32+rsp],xmm6
movdqa XMMWORD[48+rsp],xmm11
movdqa xmm14,xmm4
punpckldq xmm4,xmm5
movdqa xmm7,xmm8
punpckldq xmm8,xmm9
punpckhdq xmm14,xmm5
punpckhdq xmm7,xmm9
movdqa xmm5,xmm4
punpcklqdq xmm4,xmm8
movdqa xmm9,xmm14
punpcklqdq xmm14,xmm7
punpckhqdq xmm5,xmm8
punpckhqdq xmm9,xmm7
paddd xmm0,XMMWORD[((256-256))+rcx]
paddd xmm1,XMMWORD[((272-256))+rcx]
paddd xmm2,XMMWORD[((288-256))+rcx]
paddd xmm3,XMMWORD[((304-256))+rcx]
movdqa xmm8,xmm0
punpckldq xmm0,xmm1
movdqa xmm7,xmm2
punpckldq xmm2,xmm3
punpckhdq xmm8,xmm1
punpckhdq xmm7,xmm3
movdqa xmm1,xmm0
punpcklqdq xmm0,xmm2
movdqa xmm3,xmm8
punpcklqdq xmm8,xmm7
punpckhqdq xmm1,xmm2
punpckhqdq xmm3,xmm7
cmp rdx,64*4
jb NEAR $L$tail4x
movdqu xmm6,XMMWORD[rsi]
movdqu xmm11,XMMWORD[16+rsi]
movdqu xmm2,XMMWORD[32+rsi]
movdqu xmm7,XMMWORD[48+rsi]
pxor xmm6,XMMWORD[rsp]
pxor xmm11,xmm12
pxor xmm2,xmm4
pxor xmm7,xmm0
movdqu XMMWORD[rdi],xmm6
movdqu xmm6,XMMWORD[64+rsi]
movdqu XMMWORD[16+rdi],xmm11
movdqu xmm11,XMMWORD[80+rsi]
movdqu XMMWORD[32+rdi],xmm2
movdqu xmm2,XMMWORD[96+rsi]
movdqu XMMWORD[48+rdi],xmm7
movdqu xmm7,XMMWORD[112+rsi]
lea rsi,[128+rsi]
pxor xmm6,XMMWORD[16+rsp]
pxor xmm11,xmm13
pxor xmm2,xmm5
pxor xmm7,xmm1
movdqu XMMWORD[64+rdi],xmm6
movdqu xmm6,XMMWORD[rsi]
movdqu XMMWORD[80+rdi],xmm11
movdqu xmm11,XMMWORD[16+rsi]
movdqu XMMWORD[96+rdi],xmm2
movdqu xmm2,XMMWORD[32+rsi]
movdqu XMMWORD[112+rdi],xmm7
lea rdi,[128+rdi]
movdqu xmm7,XMMWORD[48+rsi]
pxor xmm6,XMMWORD[32+rsp]
pxor xmm11,xmm10
pxor xmm2,xmm14
pxor xmm7,xmm8
movdqu XMMWORD[rdi],xmm6
movdqu xmm6,XMMWORD[64+rsi]
movdqu XMMWORD[16+rdi],xmm11
movdqu xmm11,XMMWORD[80+rsi]
movdqu XMMWORD[32+rdi],xmm2
movdqu xmm2,XMMWORD[96+rsi]
movdqu XMMWORD[48+rdi],xmm7
movdqu xmm7,XMMWORD[112+rsi]
lea rsi,[128+rsi]
pxor xmm6,XMMWORD[48+rsp]
pxor xmm11,xmm15
pxor xmm2,xmm9
pxor xmm7,xmm3
movdqu XMMWORD[64+rdi],xmm6
movdqu XMMWORD[80+rdi],xmm11
movdqu XMMWORD[96+rdi],xmm2
movdqu XMMWORD[112+rdi],xmm7
lea rdi,[128+rdi]
sub rdx,64*4
jnz NEAR $L$oop_outer4x
jmp NEAR $L$done4x
$L$tail4x:
cmp rdx,192
jae NEAR $L$192_or_more4x
cmp rdx,128
jae NEAR $L$128_or_more4x
cmp rdx,64
jae NEAR $L$64_or_more4x
xor r10,r10
movdqa XMMWORD[16+rsp],xmm12
movdqa XMMWORD[32+rsp],xmm4
movdqa XMMWORD[48+rsp],xmm0
jmp NEAR $L$oop_tail4x
ALIGN 32
$L$64_or_more4x:
movdqu xmm6,XMMWORD[rsi]
movdqu xmm11,XMMWORD[16+rsi]
movdqu xmm2,XMMWORD[32+rsi]
movdqu xmm7,XMMWORD[48+rsi]
pxor xmm6,XMMWORD[rsp]
pxor xmm11,xmm12
pxor xmm2,xmm4
pxor xmm7,xmm0
movdqu XMMWORD[rdi],xmm6
movdqu XMMWORD[16+rdi],xmm11
movdqu XMMWORD[32+rdi],xmm2
movdqu XMMWORD[48+rdi],xmm7
je NEAR $L$done4x
movdqa xmm6,XMMWORD[16+rsp]
lea rsi,[64+rsi]
xor r10,r10
movdqa XMMWORD[rsp],xmm6
movdqa XMMWORD[16+rsp],xmm13
lea rdi,[64+rdi]
movdqa XMMWORD[32+rsp],xmm5
sub rdx,64
movdqa XMMWORD[48+rsp],xmm1
jmp NEAR $L$oop_tail4x
ALIGN 32
$L$128_or_more4x:
movdqu xmm6,XMMWORD[rsi]
movdqu xmm11,XMMWORD[16+rsi]
movdqu xmm2,XMMWORD[32+rsi]
movdqu xmm7,XMMWORD[48+rsi]
pxor xmm6,XMMWORD[rsp]
pxor xmm11,xmm12
pxor xmm2,xmm4
pxor xmm7,xmm0
movdqu XMMWORD[rdi],xmm6
movdqu xmm6,XMMWORD[64+rsi]
movdqu XMMWORD[16+rdi],xmm11
movdqu xmm11,XMMWORD[80+rsi]
movdqu XMMWORD[32+rdi],xmm2
movdqu xmm2,XMMWORD[96+rsi]
movdqu XMMWORD[48+rdi],xmm7
movdqu xmm7,XMMWORD[112+rsi]
pxor xmm6,XMMWORD[16+rsp]
pxor xmm11,xmm13
pxor xmm2,xmm5
pxor xmm7,xmm1
movdqu XMMWORD[64+rdi],xmm6
movdqu XMMWORD[80+rdi],xmm11
movdqu XMMWORD[96+rdi],xmm2
movdqu XMMWORD[112+rdi],xmm7
je NEAR $L$done4x
movdqa xmm6,XMMWORD[32+rsp]
lea rsi,[128+rsi]
xor r10,r10
movdqa XMMWORD[rsp],xmm6
movdqa XMMWORD[16+rsp],xmm10
lea rdi,[128+rdi]
movdqa XMMWORD[32+rsp],xmm14
sub rdx,128
movdqa XMMWORD[48+rsp],xmm8
jmp NEAR $L$oop_tail4x
ALIGN 32
$L$192_or_more4x:
movdqu xmm6,XMMWORD[rsi]
movdqu xmm11,XMMWORD[16+rsi]
movdqu xmm2,XMMWORD[32+rsi]
movdqu xmm7,XMMWORD[48+rsi]
pxor xmm6,XMMWORD[rsp]
pxor xmm11,xmm12
pxor xmm2,xmm4
pxor xmm7,xmm0
movdqu XMMWORD[rdi],xmm6
movdqu xmm6,XMMWORD[64+rsi]
movdqu XMMWORD[16+rdi],xmm11
movdqu xmm11,XMMWORD[80+rsi]
movdqu XMMWORD[32+rdi],xmm2
movdqu xmm2,XMMWORD[96+rsi]
movdqu XMMWORD[48+rdi],xmm7
movdqu xmm7,XMMWORD[112+rsi]
lea rsi,[128+rsi]
pxor xmm6,XMMWORD[16+rsp]
pxor xmm11,xmm13
pxor xmm2,xmm5
pxor xmm7,xmm1
movdqu XMMWORD[64+rdi],xmm6
movdqu xmm6,XMMWORD[rsi]
movdqu XMMWORD[80+rdi],xmm11
movdqu xmm11,XMMWORD[16+rsi]
movdqu XMMWORD[96+rdi],xmm2
movdqu xmm2,XMMWORD[32+rsi]
movdqu XMMWORD[112+rdi],xmm7
lea rdi,[128+rdi]
movdqu xmm7,XMMWORD[48+rsi]
pxor xmm6,XMMWORD[32+rsp]
pxor xmm11,xmm10
pxor xmm2,xmm14
pxor xmm7,xmm8
movdqu XMMWORD[rdi],xmm6
movdqu XMMWORD[16+rdi],xmm11
movdqu XMMWORD[32+rdi],xmm2
movdqu XMMWORD[48+rdi],xmm7
je NEAR $L$done4x
movdqa xmm6,XMMWORD[48+rsp]
lea rsi,[64+rsi]
xor r10,r10
movdqa XMMWORD[rsp],xmm6
movdqa XMMWORD[16+rsp],xmm15
lea rdi,[64+rdi]
movdqa XMMWORD[32+rsp],xmm9
sub rdx,192
movdqa XMMWORD[48+rsp],xmm3
$L$oop_tail4x:
movzx eax,BYTE[r10*1+rsi]
movzx ecx,BYTE[r10*1+rsp]
lea r10,[1+r10]
xor eax,ecx
mov BYTE[((-1))+r10*1+rdi],al
dec rdx
jnz NEAR $L$oop_tail4x
$L$done4x:
movaps xmm6,XMMWORD[((-168))+r9]
movaps xmm7,XMMWORD[((-152))+r9]
movaps xmm8,XMMWORD[((-136))+r9]
movaps xmm9,XMMWORD[((-120))+r9]
movaps xmm10,XMMWORD[((-104))+r9]
movaps xmm11,XMMWORD[((-88))+r9]
movaps xmm12,XMMWORD[((-72))+r9]
movaps xmm13,XMMWORD[((-56))+r9]
movaps xmm14,XMMWORD[((-40))+r9]
movaps xmm15,XMMWORD[((-24))+r9]
lea rsp,[r9]
$L$4x_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_ChaCha20_4x:
ALIGN 32
ChaCha20_4xop:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_ChaCha20_4xop:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
$L$ChaCha20_4xop:
mov r9,rsp
sub rsp,0x140+168
movaps XMMWORD[(-168)+r9],xmm6
movaps XMMWORD[(-152)+r9],xmm7
movaps XMMWORD[(-136)+r9],xmm8
movaps XMMWORD[(-120)+r9],xmm9
movaps XMMWORD[(-104)+r9],xmm10
movaps XMMWORD[(-88)+r9],xmm11
movaps XMMWORD[(-72)+r9],xmm12
movaps XMMWORD[(-56)+r9],xmm13
movaps XMMWORD[(-40)+r9],xmm14
movaps XMMWORD[(-24)+r9],xmm15
$L$4xop_body:
vzeroupper
vmovdqa xmm11,XMMWORD[$L$sigma]
vmovdqu xmm3,XMMWORD[rcx]
vmovdqu xmm15,XMMWORD[16+rcx]
vmovdqu xmm7,XMMWORD[r8]
lea rcx,[256+rsp]
vpshufd xmm8,xmm11,0x00
vpshufd xmm9,xmm11,0x55
vmovdqa XMMWORD[64+rsp],xmm8
vpshufd xmm10,xmm11,0xaa
vmovdqa XMMWORD[80+rsp],xmm9
vpshufd xmm11,xmm11,0xff
vmovdqa XMMWORD[96+rsp],xmm10
vmovdqa XMMWORD[112+rsp],xmm11
vpshufd xmm0,xmm3,0x00
vpshufd xmm1,xmm3,0x55
vmovdqa XMMWORD[(128-256)+rcx],xmm0
vpshufd xmm2,xmm3,0xaa
vmovdqa XMMWORD[(144-256)+rcx],xmm1
vpshufd xmm3,xmm3,0xff
vmovdqa XMMWORD[(160-256)+rcx],xmm2
vmovdqa XMMWORD[(176-256)+rcx],xmm3
vpshufd xmm12,xmm15,0x00
vpshufd xmm13,xmm15,0x55
vmovdqa XMMWORD[(192-256)+rcx],xmm12
vpshufd xmm14,xmm15,0xaa
vmovdqa XMMWORD[(208-256)+rcx],xmm13
vpshufd xmm15,xmm15,0xff
vmovdqa XMMWORD[(224-256)+rcx],xmm14
vmovdqa XMMWORD[(240-256)+rcx],xmm15
vpshufd xmm4,xmm7,0x00
vpshufd xmm5,xmm7,0x55
vpaddd xmm4,xmm4,XMMWORD[$L$inc]
vpshufd xmm6,xmm7,0xaa
vmovdqa XMMWORD[(272-256)+rcx],xmm5
vpshufd xmm7,xmm7,0xff
vmovdqa XMMWORD[(288-256)+rcx],xmm6
vmovdqa XMMWORD[(304-256)+rcx],xmm7
jmp NEAR $L$oop_enter4xop
ALIGN 32
$L$oop_outer4xop:
vmovdqa xmm8,XMMWORD[64+rsp]
vmovdqa xmm9,XMMWORD[80+rsp]
vmovdqa xmm10,XMMWORD[96+rsp]
vmovdqa xmm11,XMMWORD[112+rsp]
vmovdqa xmm0,XMMWORD[((128-256))+rcx]
vmovdqa xmm1,XMMWORD[((144-256))+rcx]
vmovdqa xmm2,XMMWORD[((160-256))+rcx]
vmovdqa xmm3,XMMWORD[((176-256))+rcx]
vmovdqa xmm12,XMMWORD[((192-256))+rcx]
vmovdqa xmm13,XMMWORD[((208-256))+rcx]
vmovdqa xmm14,XMMWORD[((224-256))+rcx]
vmovdqa xmm15,XMMWORD[((240-256))+rcx]
vmovdqa xmm4,XMMWORD[((256-256))+rcx]
vmovdqa xmm5,XMMWORD[((272-256))+rcx]
vmovdqa xmm6,XMMWORD[((288-256))+rcx]
vmovdqa xmm7,XMMWORD[((304-256))+rcx]
vpaddd xmm4,xmm4,XMMWORD[$L$four]
$L$oop_enter4xop:
mov eax,10
vmovdqa XMMWORD[(256-256)+rcx],xmm4
jmp NEAR $L$oop4xop
ALIGN 32
$L$oop4xop:
vpaddd xmm8,xmm8,xmm0
vpaddd xmm9,xmm9,xmm1
vpaddd xmm10,xmm10,xmm2
vpaddd xmm11,xmm11,xmm3
vpxor xmm4,xmm8,xmm4
vpxor xmm5,xmm9,xmm5
vpxor xmm6,xmm10,xmm6
vpxor xmm7,xmm11,xmm7
DB 143,232,120,194,228,16
DB 143,232,120,194,237,16
DB 143,232,120,194,246,16
DB 143,232,120,194,255,16
vpaddd xmm12,xmm12,xmm4
vpaddd xmm13,xmm13,xmm5
vpaddd xmm14,xmm14,xmm6
vpaddd xmm15,xmm15,xmm7
vpxor xmm0,xmm12,xmm0
vpxor xmm1,xmm13,xmm1
vpxor xmm2,xmm2,xmm14
vpxor xmm3,xmm3,xmm15
DB 143,232,120,194,192,12
DB 143,232,120,194,201,12
DB 143,232,120,194,210,12
DB 143,232,120,194,219,12
vpaddd xmm8,xmm0,xmm8
vpaddd xmm9,xmm1,xmm9
vpaddd xmm10,xmm10,xmm2
vpaddd xmm11,xmm11,xmm3
vpxor xmm4,xmm8,xmm4
vpxor xmm5,xmm9,xmm5
vpxor xmm6,xmm10,xmm6
vpxor xmm7,xmm11,xmm7
DB 143,232,120,194,228,8
DB 143,232,120,194,237,8
DB 143,232,120,194,246,8
DB 143,232,120,194,255,8
vpaddd xmm12,xmm12,xmm4
vpaddd xmm13,xmm13,xmm5
vpaddd xmm14,xmm14,xmm6
vpaddd xmm15,xmm15,xmm7
vpxor xmm0,xmm12,xmm0
vpxor xmm1,xmm13,xmm1
vpxor xmm2,xmm2,xmm14
vpxor xmm3,xmm3,xmm15
DB 143,232,120,194,192,7
DB 143,232,120,194,201,7
DB 143,232,120,194,210,7
DB 143,232,120,194,219,7
vpaddd xmm8,xmm8,xmm1
vpaddd xmm9,xmm9,xmm2
vpaddd xmm10,xmm10,xmm3
vpaddd xmm11,xmm11,xmm0
vpxor xmm7,xmm8,xmm7
vpxor xmm4,xmm9,xmm4
vpxor xmm5,xmm10,xmm5
vpxor xmm6,xmm11,xmm6
DB 143,232,120,194,255,16
DB 143,232,120,194,228,16
DB 143,232,120,194,237,16
DB 143,232,120,194,246,16
vpaddd xmm14,xmm14,xmm7
vpaddd xmm15,xmm15,xmm4
vpaddd xmm12,xmm12,xmm5
vpaddd xmm13,xmm13,xmm6
vpxor xmm1,xmm14,xmm1
vpxor xmm2,xmm15,xmm2
vpxor xmm3,xmm3,xmm12
vpxor xmm0,xmm0,xmm13
DB 143,232,120,194,201,12
DB 143,232,120,194,210,12
DB 143,232,120,194,219,12
DB 143,232,120,194,192,12
vpaddd xmm8,xmm1,xmm8
vpaddd xmm9,xmm2,xmm9
vpaddd xmm10,xmm10,xmm3
vpaddd xmm11,xmm11,xmm0
vpxor xmm7,xmm8,xmm7
vpxor xmm4,xmm9,xmm4
vpxor xmm5,xmm10,xmm5
vpxor xmm6,xmm11,xmm6
DB 143,232,120,194,255,8
DB 143,232,120,194,228,8
DB 143,232,120,194,237,8
DB 143,232,120,194,246,8
vpaddd xmm14,xmm14,xmm7
vpaddd xmm15,xmm15,xmm4
vpaddd xmm12,xmm12,xmm5
vpaddd xmm13,xmm13,xmm6
vpxor xmm1,xmm14,xmm1
vpxor xmm2,xmm15,xmm2
vpxor xmm3,xmm3,xmm12
vpxor xmm0,xmm0,xmm13
DB 143,232,120,194,201,7
DB 143,232,120,194,210,7
DB 143,232,120,194,219,7
DB 143,232,120,194,192,7
dec eax
jnz NEAR $L$oop4xop
vpaddd xmm8,xmm8,XMMWORD[64+rsp]
vpaddd xmm9,xmm9,XMMWORD[80+rsp]
vpaddd xmm10,xmm10,XMMWORD[96+rsp]
vpaddd xmm11,xmm11,XMMWORD[112+rsp]
vmovdqa XMMWORD[32+rsp],xmm14
vmovdqa XMMWORD[48+rsp],xmm15
vpunpckldq xmm14,xmm8,xmm9
vpunpckldq xmm15,xmm10,xmm11
vpunpckhdq xmm8,xmm8,xmm9
vpunpckhdq xmm10,xmm10,xmm11
vpunpcklqdq xmm9,xmm14,xmm15
vpunpckhqdq xmm14,xmm14,xmm15
vpunpcklqdq xmm11,xmm8,xmm10
vpunpckhqdq xmm8,xmm8,xmm10
vpaddd xmm0,xmm0,XMMWORD[((128-256))+rcx]
vpaddd xmm1,xmm1,XMMWORD[((144-256))+rcx]
vpaddd xmm2,xmm2,XMMWORD[((160-256))+rcx]
vpaddd xmm3,xmm3,XMMWORD[((176-256))+rcx]
vmovdqa XMMWORD[rsp],xmm9
vmovdqa XMMWORD[16+rsp],xmm14
vmovdqa xmm9,XMMWORD[32+rsp]
vmovdqa xmm14,XMMWORD[48+rsp]
vpunpckldq xmm10,xmm0,xmm1
vpunpckldq xmm15,xmm2,xmm3
vpunpckhdq xmm0,xmm0,xmm1
vpunpckhdq xmm2,xmm2,xmm3
vpunpcklqdq xmm1,xmm10,xmm15
vpunpckhqdq xmm10,xmm10,xmm15
vpunpcklqdq xmm3,xmm0,xmm2
vpunpckhqdq xmm0,xmm0,xmm2
vpaddd xmm12,xmm12,XMMWORD[((192-256))+rcx]
vpaddd xmm13,xmm13,XMMWORD[((208-256))+rcx]
vpaddd xmm9,xmm9,XMMWORD[((224-256))+rcx]
vpaddd xmm14,xmm14,XMMWORD[((240-256))+rcx]
vpunpckldq xmm2,xmm12,xmm13
vpunpckldq xmm15,xmm9,xmm14
vpunpckhdq xmm12,xmm12,xmm13
vpunpckhdq xmm9,xmm9,xmm14
vpunpcklqdq xmm13,xmm2,xmm15
vpunpckhqdq xmm2,xmm2,xmm15
vpunpcklqdq xmm14,xmm12,xmm9
vpunpckhqdq xmm12,xmm12,xmm9
vpaddd xmm4,xmm4,XMMWORD[((256-256))+rcx]
vpaddd xmm5,xmm5,XMMWORD[((272-256))+rcx]
vpaddd xmm6,xmm6,XMMWORD[((288-256))+rcx]
vpaddd xmm7,xmm7,XMMWORD[((304-256))+rcx]
vpunpckldq xmm9,xmm4,xmm5
vpunpckldq xmm15,xmm6,xmm7
vpunpckhdq xmm4,xmm4,xmm5
vpunpckhdq xmm6,xmm6,xmm7
vpunpcklqdq xmm5,xmm9,xmm15
vpunpckhqdq xmm9,xmm9,xmm15
vpunpcklqdq xmm7,xmm4,xmm6
vpunpckhqdq xmm4,xmm4,xmm6
vmovdqa xmm6,XMMWORD[rsp]
vmovdqa xmm15,XMMWORD[16+rsp]
cmp rdx,64*4
jb NEAR $L$tail4xop
vpxor xmm6,xmm6,XMMWORD[rsi]
vpxor xmm1,xmm1,XMMWORD[16+rsi]
vpxor xmm13,xmm13,XMMWORD[32+rsi]
vpxor xmm5,xmm5,XMMWORD[48+rsi]
vpxor xmm15,xmm15,XMMWORD[64+rsi]
vpxor xmm10,xmm10,XMMWORD[80+rsi]
vpxor xmm2,xmm2,XMMWORD[96+rsi]
vpxor xmm9,xmm9,XMMWORD[112+rsi]
lea rsi,[128+rsi]
vpxor xmm11,xmm11,XMMWORD[rsi]
vpxor xmm3,xmm3,XMMWORD[16+rsi]
vpxor xmm14,xmm14,XMMWORD[32+rsi]
vpxor xmm7,xmm7,XMMWORD[48+rsi]
vpxor xmm8,xmm8,XMMWORD[64+rsi]
vpxor xmm0,xmm0,XMMWORD[80+rsi]
vpxor xmm12,xmm12,XMMWORD[96+rsi]
vpxor xmm4,xmm4,XMMWORD[112+rsi]
lea rsi,[128+rsi]
vmovdqu XMMWORD[rdi],xmm6
vmovdqu XMMWORD[16+rdi],xmm1
vmovdqu XMMWORD[32+rdi],xmm13
vmovdqu XMMWORD[48+rdi],xmm5
vmovdqu XMMWORD[64+rdi],xmm15
vmovdqu XMMWORD[80+rdi],xmm10
vmovdqu XMMWORD[96+rdi],xmm2
vmovdqu XMMWORD[112+rdi],xmm9
lea rdi,[128+rdi]
vmovdqu XMMWORD[rdi],xmm11
vmovdqu XMMWORD[16+rdi],xmm3
vmovdqu XMMWORD[32+rdi],xmm14
vmovdqu XMMWORD[48+rdi],xmm7
vmovdqu XMMWORD[64+rdi],xmm8
vmovdqu XMMWORD[80+rdi],xmm0
vmovdqu XMMWORD[96+rdi],xmm12
vmovdqu XMMWORD[112+rdi],xmm4
lea rdi,[128+rdi]
sub rdx,64*4
jnz NEAR $L$oop_outer4xop
jmp NEAR $L$done4xop
ALIGN 32
$L$tail4xop:
cmp rdx,192
jae NEAR $L$192_or_more4xop
cmp rdx,128
jae NEAR $L$128_or_more4xop
cmp rdx,64
jae NEAR $L$64_or_more4xop
xor r10,r10
vmovdqa XMMWORD[rsp],xmm6
vmovdqa XMMWORD[16+rsp],xmm1
vmovdqa XMMWORD[32+rsp],xmm13
vmovdqa XMMWORD[48+rsp],xmm5
jmp NEAR $L$oop_tail4xop
ALIGN 32
$L$64_or_more4xop:
vpxor xmm6,xmm6,XMMWORD[rsi]
vpxor xmm1,xmm1,XMMWORD[16+rsi]
vpxor xmm13,xmm13,XMMWORD[32+rsi]
vpxor xmm5,xmm5,XMMWORD[48+rsi]
vmovdqu XMMWORD[rdi],xmm6
vmovdqu XMMWORD[16+rdi],xmm1
vmovdqu XMMWORD[32+rdi],xmm13
vmovdqu XMMWORD[48+rdi],xmm5
je NEAR $L$done4xop
lea rsi,[64+rsi]
vmovdqa XMMWORD[rsp],xmm15
xor r10,r10
vmovdqa XMMWORD[16+rsp],xmm10
lea rdi,[64+rdi]
vmovdqa XMMWORD[32+rsp],xmm2
sub rdx,64
vmovdqa XMMWORD[48+rsp],xmm9
jmp NEAR $L$oop_tail4xop
ALIGN 32
$L$128_or_more4xop:
vpxor xmm6,xmm6,XMMWORD[rsi]
vpxor xmm1,xmm1,XMMWORD[16+rsi]
vpxor xmm13,xmm13,XMMWORD[32+rsi]
vpxor xmm5,xmm5,XMMWORD[48+rsi]
vpxor xmm15,xmm15,XMMWORD[64+rsi]
vpxor xmm10,xmm10,XMMWORD[80+rsi]
vpxor xmm2,xmm2,XMMWORD[96+rsi]
vpxor xmm9,xmm9,XMMWORD[112+rsi]
vmovdqu XMMWORD[rdi],xmm6
vmovdqu XMMWORD[16+rdi],xmm1
vmovdqu XMMWORD[32+rdi],xmm13
vmovdqu XMMWORD[48+rdi],xmm5
vmovdqu XMMWORD[64+rdi],xmm15
vmovdqu XMMWORD[80+rdi],xmm10
vmovdqu XMMWORD[96+rdi],xmm2
vmovdqu XMMWORD[112+rdi],xmm9
je NEAR $L$done4xop
lea rsi,[128+rsi]
vmovdqa XMMWORD[rsp],xmm11
xor r10,r10
vmovdqa XMMWORD[16+rsp],xmm3
lea rdi,[128+rdi]
vmovdqa XMMWORD[32+rsp],xmm14
sub rdx,128
vmovdqa XMMWORD[48+rsp],xmm7
jmp NEAR $L$oop_tail4xop
ALIGN 32
$L$192_or_more4xop:
vpxor xmm6,xmm6,XMMWORD[rsi]
vpxor xmm1,xmm1,XMMWORD[16+rsi]
vpxor xmm13,xmm13,XMMWORD[32+rsi]
vpxor xmm5,xmm5,XMMWORD[48+rsi]
vpxor xmm15,xmm15,XMMWORD[64+rsi]
vpxor xmm10,xmm10,XMMWORD[80+rsi]
vpxor xmm2,xmm2,XMMWORD[96+rsi]
vpxor xmm9,xmm9,XMMWORD[112+rsi]
lea rsi,[128+rsi]
vpxor xmm11,xmm11,XMMWORD[rsi]
vpxor xmm3,xmm3,XMMWORD[16+rsi]
vpxor xmm14,xmm14,XMMWORD[32+rsi]
vpxor xmm7,xmm7,XMMWORD[48+rsi]
vmovdqu XMMWORD[rdi],xmm6
vmovdqu XMMWORD[16+rdi],xmm1
vmovdqu XMMWORD[32+rdi],xmm13
vmovdqu XMMWORD[48+rdi],xmm5
vmovdqu XMMWORD[64+rdi],xmm15
vmovdqu XMMWORD[80+rdi],xmm10
vmovdqu XMMWORD[96+rdi],xmm2
vmovdqu XMMWORD[112+rdi],xmm9
lea rdi,[128+rdi]
vmovdqu XMMWORD[rdi],xmm11
vmovdqu XMMWORD[16+rdi],xmm3
vmovdqu XMMWORD[32+rdi],xmm14
vmovdqu XMMWORD[48+rdi],xmm7
je NEAR $L$done4xop
lea rsi,[64+rsi]
vmovdqa XMMWORD[rsp],xmm8
xor r10,r10
vmovdqa XMMWORD[16+rsp],xmm0
lea rdi,[64+rdi]
vmovdqa XMMWORD[32+rsp],xmm12
sub rdx,192
vmovdqa XMMWORD[48+rsp],xmm4
$L$oop_tail4xop:
movzx eax,BYTE[r10*1+rsi]
movzx ecx,BYTE[r10*1+rsp]
lea r10,[1+r10]
xor eax,ecx
mov BYTE[((-1))+r10*1+rdi],al
dec rdx
jnz NEAR $L$oop_tail4xop
$L$done4xop:
vzeroupper
movaps xmm6,XMMWORD[((-168))+r9]
movaps xmm7,XMMWORD[((-152))+r9]
movaps xmm8,XMMWORD[((-136))+r9]
movaps xmm9,XMMWORD[((-120))+r9]
movaps xmm10,XMMWORD[((-104))+r9]
movaps xmm11,XMMWORD[((-88))+r9]
movaps xmm12,XMMWORD[((-72))+r9]
movaps xmm13,XMMWORD[((-56))+r9]
movaps xmm14,XMMWORD[((-40))+r9]
movaps xmm15,XMMWORD[((-24))+r9]
lea rsp,[r9]
$L$4xop_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_ChaCha20_4xop:
ALIGN 32
ChaCha20_8x:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_ChaCha20_8x:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
$L$ChaCha20_8x:
mov r9,rsp
sub rsp,0x280+168
and rsp,-32
movaps XMMWORD[(-168)+r9],xmm6
movaps XMMWORD[(-152)+r9],xmm7
movaps XMMWORD[(-136)+r9],xmm8
movaps XMMWORD[(-120)+r9],xmm9
movaps XMMWORD[(-104)+r9],xmm10
movaps XMMWORD[(-88)+r9],xmm11
movaps XMMWORD[(-72)+r9],xmm12
movaps XMMWORD[(-56)+r9],xmm13
movaps XMMWORD[(-40)+r9],xmm14
movaps XMMWORD[(-24)+r9],xmm15
$L$8x_body:
vzeroupper
vbroadcasti128 ymm11,XMMWORD[$L$sigma]
vbroadcasti128 ymm3,XMMWORD[rcx]
vbroadcasti128 ymm15,XMMWORD[16+rcx]
vbroadcasti128 ymm7,XMMWORD[r8]
lea rcx,[256+rsp]
lea rax,[512+rsp]
lea r10,[$L$rot16]
lea r11,[$L$rot24]
vpshufd ymm8,ymm11,0x00
vpshufd ymm9,ymm11,0x55
vmovdqa YMMWORD[(128-256)+rcx],ymm8
vpshufd ymm10,ymm11,0xaa
vmovdqa YMMWORD[(160-256)+rcx],ymm9
vpshufd ymm11,ymm11,0xff
vmovdqa YMMWORD[(192-256)+rcx],ymm10
vmovdqa YMMWORD[(224-256)+rcx],ymm11
vpshufd ymm0,ymm3,0x00
vpshufd ymm1,ymm3,0x55
vmovdqa YMMWORD[(256-256)+rcx],ymm0
vpshufd ymm2,ymm3,0xaa
vmovdqa YMMWORD[(288-256)+rcx],ymm1
vpshufd ymm3,ymm3,0xff
vmovdqa YMMWORD[(320-256)+rcx],ymm2
vmovdqa YMMWORD[(352-256)+rcx],ymm3
vpshufd ymm12,ymm15,0x00
vpshufd ymm13,ymm15,0x55
vmovdqa YMMWORD[(384-512)+rax],ymm12
vpshufd ymm14,ymm15,0xaa
vmovdqa YMMWORD[(416-512)+rax],ymm13
vpshufd ymm15,ymm15,0xff
vmovdqa YMMWORD[(448-512)+rax],ymm14
vmovdqa YMMWORD[(480-512)+rax],ymm15
vpshufd ymm4,ymm7,0x00
vpshufd ymm5,ymm7,0x55
vpaddd ymm4,ymm4,YMMWORD[$L$incy]
vpshufd ymm6,ymm7,0xaa
vmovdqa YMMWORD[(544-512)+rax],ymm5
vpshufd ymm7,ymm7,0xff
vmovdqa YMMWORD[(576-512)+rax],ymm6
vmovdqa YMMWORD[(608-512)+rax],ymm7
jmp NEAR $L$oop_enter8x
ALIGN 32
$L$oop_outer8x:
vmovdqa ymm8,YMMWORD[((128-256))+rcx]
vmovdqa ymm9,YMMWORD[((160-256))+rcx]
vmovdqa ymm10,YMMWORD[((192-256))+rcx]
vmovdqa ymm11,YMMWORD[((224-256))+rcx]
vmovdqa ymm0,YMMWORD[((256-256))+rcx]
vmovdqa ymm1,YMMWORD[((288-256))+rcx]
vmovdqa ymm2,YMMWORD[((320-256))+rcx]
vmovdqa ymm3,YMMWORD[((352-256))+rcx]
vmovdqa ymm12,YMMWORD[((384-512))+rax]
vmovdqa ymm13,YMMWORD[((416-512))+rax]
vmovdqa ymm14,YMMWORD[((448-512))+rax]
vmovdqa ymm15,YMMWORD[((480-512))+rax]
vmovdqa ymm4,YMMWORD[((512-512))+rax]
vmovdqa ymm5,YMMWORD[((544-512))+rax]
vmovdqa ymm6,YMMWORD[((576-512))+rax]
vmovdqa ymm7,YMMWORD[((608-512))+rax]
vpaddd ymm4,ymm4,YMMWORD[$L$eight]
$L$oop_enter8x:
vmovdqa YMMWORD[64+rsp],ymm14
vmovdqa YMMWORD[96+rsp],ymm15
vbroadcasti128 ymm15,XMMWORD[r10]
vmovdqa YMMWORD[(512-512)+rax],ymm4
mov eax,10
jmp NEAR $L$oop8x
ALIGN 32
$L$oop8x:
vpaddd ymm8,ymm8,ymm0
vpxor ymm4,ymm8,ymm4
vpshufb ymm4,ymm4,ymm15
vpaddd ymm9,ymm9,ymm1
vpxor ymm5,ymm9,ymm5
vpshufb ymm5,ymm5,ymm15
vpaddd ymm12,ymm12,ymm4
vpxor ymm0,ymm12,ymm0
vpslld ymm14,ymm0,12
vpsrld ymm0,ymm0,20
vpor ymm0,ymm14,ymm0
vbroadcasti128 ymm14,XMMWORD[r11]
vpaddd ymm13,ymm13,ymm5
vpxor ymm1,ymm13,ymm1
vpslld ymm15,ymm1,12
vpsrld ymm1,ymm1,20
vpor ymm1,ymm15,ymm1
vpaddd ymm8,ymm8,ymm0
vpxor ymm4,ymm8,ymm4
vpshufb ymm4,ymm4,ymm14
vpaddd ymm9,ymm9,ymm1
vpxor ymm5,ymm9,ymm5
vpshufb ymm5,ymm5,ymm14
vpaddd ymm12,ymm12,ymm4
vpxor ymm0,ymm12,ymm0
vpslld ymm15,ymm0,7
vpsrld ymm0,ymm0,25
vpor ymm0,ymm15,ymm0
vbroadcasti128 ymm15,XMMWORD[r10]
vpaddd ymm13,ymm13,ymm5
vpxor ymm1,ymm13,ymm1
vpslld ymm14,ymm1,7
vpsrld ymm1,ymm1,25
vpor ymm1,ymm14,ymm1
vmovdqa YMMWORD[rsp],ymm12
vmovdqa YMMWORD[32+rsp],ymm13
vmovdqa ymm12,YMMWORD[64+rsp]
vmovdqa ymm13,YMMWORD[96+rsp]
vpaddd ymm10,ymm10,ymm2
vpxor ymm6,ymm10,ymm6
vpshufb ymm6,ymm6,ymm15
vpaddd ymm11,ymm11,ymm3
vpxor ymm7,ymm11,ymm7
vpshufb ymm7,ymm7,ymm15
vpaddd ymm12,ymm12,ymm6
vpxor ymm2,ymm12,ymm2
vpslld ymm14,ymm2,12
vpsrld ymm2,ymm2,20
vpor ymm2,ymm14,ymm2
vbroadcasti128 ymm14,XMMWORD[r11]
vpaddd ymm13,ymm13,ymm7
vpxor ymm3,ymm13,ymm3
vpslld ymm15,ymm3,12
vpsrld ymm3,ymm3,20
vpor ymm3,ymm15,ymm3
vpaddd ymm10,ymm10,ymm2
vpxor ymm6,ymm10,ymm6
vpshufb ymm6,ymm6,ymm14
vpaddd ymm11,ymm11,ymm3
vpxor ymm7,ymm11,ymm7
vpshufb ymm7,ymm7,ymm14
vpaddd ymm12,ymm12,ymm6
vpxor ymm2,ymm12,ymm2
vpslld ymm15,ymm2,7
vpsrld ymm2,ymm2,25
vpor ymm2,ymm15,ymm2
vbroadcasti128 ymm15,XMMWORD[r10]
vpaddd ymm13,ymm13,ymm7
vpxor ymm3,ymm13,ymm3
vpslld ymm14,ymm3,7
vpsrld ymm3,ymm3,25
vpor ymm3,ymm14,ymm3
vpaddd ymm8,ymm8,ymm1
vpxor ymm7,ymm8,ymm7
vpshufb ymm7,ymm7,ymm15
vpaddd ymm9,ymm9,ymm2
vpxor ymm4,ymm9,ymm4
vpshufb ymm4,ymm4,ymm15
vpaddd ymm12,ymm12,ymm7
vpxor ymm1,ymm12,ymm1
vpslld ymm14,ymm1,12
vpsrld ymm1,ymm1,20
vpor ymm1,ymm14,ymm1
vbroadcasti128 ymm14,XMMWORD[r11]
vpaddd ymm13,ymm13,ymm4
vpxor ymm2,ymm13,ymm2
vpslld ymm15,ymm2,12
vpsrld ymm2,ymm2,20
vpor ymm2,ymm15,ymm2
vpaddd ymm8,ymm8,ymm1
vpxor ymm7,ymm8,ymm7
vpshufb ymm7,ymm7,ymm14
vpaddd ymm9,ymm9,ymm2
vpxor ymm4,ymm9,ymm4
vpshufb ymm4,ymm4,ymm14
vpaddd ymm12,ymm12,ymm7
vpxor ymm1,ymm12,ymm1
vpslld ymm15,ymm1,7
vpsrld ymm1,ymm1,25
vpor ymm1,ymm15,ymm1
vbroadcasti128 ymm15,XMMWORD[r10]
vpaddd ymm13,ymm13,ymm4
vpxor ymm2,ymm13,ymm2
vpslld ymm14,ymm2,7
vpsrld ymm2,ymm2,25
vpor ymm2,ymm14,ymm2
vmovdqa YMMWORD[64+rsp],ymm12
vmovdqa YMMWORD[96+rsp],ymm13
vmovdqa ymm12,YMMWORD[rsp]
vmovdqa ymm13,YMMWORD[32+rsp]
vpaddd ymm10,ymm10,ymm3
vpxor ymm5,ymm10,ymm5
vpshufb ymm5,ymm5,ymm15
vpaddd ymm11,ymm11,ymm0
vpxor ymm6,ymm11,ymm6
vpshufb ymm6,ymm6,ymm15
vpaddd ymm12,ymm12,ymm5
vpxor ymm3,ymm12,ymm3
vpslld ymm14,ymm3,12
vpsrld ymm3,ymm3,20
vpor ymm3,ymm14,ymm3
vbroadcasti128 ymm14,XMMWORD[r11]
vpaddd ymm13,ymm13,ymm6
vpxor ymm0,ymm13,ymm0
vpslld ymm15,ymm0,12
vpsrld ymm0,ymm0,20
vpor ymm0,ymm15,ymm0
vpaddd ymm10,ymm10,ymm3
vpxor ymm5,ymm10,ymm5
vpshufb ymm5,ymm5,ymm14
vpaddd ymm11,ymm11,ymm0
vpxor ymm6,ymm11,ymm6
vpshufb ymm6,ymm6,ymm14
vpaddd ymm12,ymm12,ymm5
vpxor ymm3,ymm12,ymm3
vpslld ymm15,ymm3,7
vpsrld ymm3,ymm3,25
vpor ymm3,ymm15,ymm3
vbroadcasti128 ymm15,XMMWORD[r10]
vpaddd ymm13,ymm13,ymm6
vpxor ymm0,ymm13,ymm0
vpslld ymm14,ymm0,7
vpsrld ymm0,ymm0,25
vpor ymm0,ymm14,ymm0
dec eax
jnz NEAR $L$oop8x
lea rax,[512+rsp]
vpaddd ymm8,ymm8,YMMWORD[((128-256))+rcx]
vpaddd ymm9,ymm9,YMMWORD[((160-256))+rcx]
vpaddd ymm10,ymm10,YMMWORD[((192-256))+rcx]
vpaddd ymm11,ymm11,YMMWORD[((224-256))+rcx]
vpunpckldq ymm14,ymm8,ymm9
vpunpckldq ymm15,ymm10,ymm11
vpunpckhdq ymm8,ymm8,ymm9
vpunpckhdq ymm10,ymm10,ymm11
vpunpcklqdq ymm9,ymm14,ymm15
vpunpckhqdq ymm14,ymm14,ymm15
vpunpcklqdq ymm11,ymm8,ymm10
vpunpckhqdq ymm8,ymm8,ymm10
vpaddd ymm0,ymm0,YMMWORD[((256-256))+rcx]
vpaddd ymm1,ymm1,YMMWORD[((288-256))+rcx]
vpaddd ymm2,ymm2,YMMWORD[((320-256))+rcx]
vpaddd ymm3,ymm3,YMMWORD[((352-256))+rcx]
vpunpckldq ymm10,ymm0,ymm1
vpunpckldq ymm15,ymm2,ymm3
vpunpckhdq ymm0,ymm0,ymm1
vpunpckhdq ymm2,ymm2,ymm3
vpunpcklqdq ymm1,ymm10,ymm15
vpunpckhqdq ymm10,ymm10,ymm15
vpunpcklqdq ymm3,ymm0,ymm2
vpunpckhqdq ymm0,ymm0,ymm2
vperm2i128 ymm15,ymm9,ymm1,0x20
vperm2i128 ymm1,ymm9,ymm1,0x31
vperm2i128 ymm9,ymm14,ymm10,0x20
vperm2i128 ymm10,ymm14,ymm10,0x31
vperm2i128 ymm14,ymm11,ymm3,0x20
vperm2i128 ymm3,ymm11,ymm3,0x31
vperm2i128 ymm11,ymm8,ymm0,0x20
vperm2i128 ymm0,ymm8,ymm0,0x31
vmovdqa YMMWORD[rsp],ymm15
vmovdqa YMMWORD[32+rsp],ymm9
vmovdqa ymm15,YMMWORD[64+rsp]
vmovdqa ymm9,YMMWORD[96+rsp]
vpaddd ymm12,ymm12,YMMWORD[((384-512))+rax]
vpaddd ymm13,ymm13,YMMWORD[((416-512))+rax]
vpaddd ymm15,ymm15,YMMWORD[((448-512))+rax]
vpaddd ymm9,ymm9,YMMWORD[((480-512))+rax]
vpunpckldq ymm2,ymm12,ymm13
vpunpckldq ymm8,ymm15,ymm9
vpunpckhdq ymm12,ymm12,ymm13
vpunpckhdq ymm15,ymm15,ymm9
vpunpcklqdq ymm13,ymm2,ymm8
vpunpckhqdq ymm2,ymm2,ymm8
vpunpcklqdq ymm9,ymm12,ymm15
vpunpckhqdq ymm12,ymm12,ymm15
vpaddd ymm4,ymm4,YMMWORD[((512-512))+rax]
vpaddd ymm5,ymm5,YMMWORD[((544-512))+rax]
vpaddd ymm6,ymm6,YMMWORD[((576-512))+rax]
vpaddd ymm7,ymm7,YMMWORD[((608-512))+rax]
vpunpckldq ymm15,ymm4,ymm5
vpunpckldq ymm8,ymm6,ymm7
vpunpckhdq ymm4,ymm4,ymm5
vpunpckhdq ymm6,ymm6,ymm7
vpunpcklqdq ymm5,ymm15,ymm8
vpunpckhqdq ymm15,ymm15,ymm8
vpunpcklqdq ymm7,ymm4,ymm6
vpunpckhqdq ymm4,ymm4,ymm6
vperm2i128 ymm8,ymm13,ymm5,0x20
vperm2i128 ymm5,ymm13,ymm5,0x31
vperm2i128 ymm13,ymm2,ymm15,0x20
vperm2i128 ymm15,ymm2,ymm15,0x31
vperm2i128 ymm2,ymm9,ymm7,0x20
vperm2i128 ymm7,ymm9,ymm7,0x31
vperm2i128 ymm9,ymm12,ymm4,0x20
vperm2i128 ymm4,ymm12,ymm4,0x31
vmovdqa ymm6,YMMWORD[rsp]
vmovdqa ymm12,YMMWORD[32+rsp]
cmp rdx,64*8
jb NEAR $L$tail8x
vpxor ymm6,ymm6,YMMWORD[rsi]
vpxor ymm8,ymm8,YMMWORD[32+rsi]
vpxor ymm1,ymm1,YMMWORD[64+rsi]
vpxor ymm5,ymm5,YMMWORD[96+rsi]
lea rsi,[128+rsi]
vmovdqu YMMWORD[rdi],ymm6
vmovdqu YMMWORD[32+rdi],ymm8
vmovdqu YMMWORD[64+rdi],ymm1
vmovdqu YMMWORD[96+rdi],ymm5
lea rdi,[128+rdi]
vpxor ymm12,ymm12,YMMWORD[rsi]
vpxor ymm13,ymm13,YMMWORD[32+rsi]
vpxor ymm10,ymm10,YMMWORD[64+rsi]
vpxor ymm15,ymm15,YMMWORD[96+rsi]
lea rsi,[128+rsi]
vmovdqu YMMWORD[rdi],ymm12
vmovdqu YMMWORD[32+rdi],ymm13
vmovdqu YMMWORD[64+rdi],ymm10
vmovdqu YMMWORD[96+rdi],ymm15
lea rdi,[128+rdi]
vpxor ymm14,ymm14,YMMWORD[rsi]
vpxor ymm2,ymm2,YMMWORD[32+rsi]
vpxor ymm3,ymm3,YMMWORD[64+rsi]
vpxor ymm7,ymm7,YMMWORD[96+rsi]
lea rsi,[128+rsi]
vmovdqu YMMWORD[rdi],ymm14
vmovdqu YMMWORD[32+rdi],ymm2
vmovdqu YMMWORD[64+rdi],ymm3
vmovdqu YMMWORD[96+rdi],ymm7
lea rdi,[128+rdi]
vpxor ymm11,ymm11,YMMWORD[rsi]
vpxor ymm9,ymm9,YMMWORD[32+rsi]
vpxor ymm0,ymm0,YMMWORD[64+rsi]
vpxor ymm4,ymm4,YMMWORD[96+rsi]
lea rsi,[128+rsi]
vmovdqu YMMWORD[rdi],ymm11
vmovdqu YMMWORD[32+rdi],ymm9
vmovdqu YMMWORD[64+rdi],ymm0
vmovdqu YMMWORD[96+rdi],ymm4
lea rdi,[128+rdi]
sub rdx,64*8
jnz NEAR $L$oop_outer8x
jmp NEAR $L$done8x
$L$tail8x:
cmp rdx,448
jae NEAR $L$448_or_more8x
cmp rdx,384
jae NEAR $L$384_or_more8x
cmp rdx,320
jae NEAR $L$320_or_more8x
cmp rdx,256
jae NEAR $L$256_or_more8x
cmp rdx,192
jae NEAR $L$192_or_more8x
cmp rdx,128
jae NEAR $L$128_or_more8x
cmp rdx,64
jae NEAR $L$64_or_more8x
xor r10,r10
vmovdqa YMMWORD[rsp],ymm6
vmovdqa YMMWORD[32+rsp],ymm8
jmp NEAR $L$oop_tail8x
ALIGN 32
$L$64_or_more8x:
vpxor ymm6,ymm6,YMMWORD[rsi]
vpxor ymm8,ymm8,YMMWORD[32+rsi]
vmovdqu YMMWORD[rdi],ymm6
vmovdqu YMMWORD[32+rdi],ymm8
je NEAR $L$done8x
lea rsi,[64+rsi]
xor r10,r10
vmovdqa YMMWORD[rsp],ymm1
lea rdi,[64+rdi]
sub rdx,64
vmovdqa YMMWORD[32+rsp],ymm5
jmp NEAR $L$oop_tail8x
ALIGN 32
$L$128_or_more8x:
vpxor ymm6,ymm6,YMMWORD[rsi]
vpxor ymm8,ymm8,YMMWORD[32+rsi]
vpxor ymm1,ymm1,YMMWORD[64+rsi]
vpxor ymm5,ymm5,YMMWORD[96+rsi]
vmovdqu YMMWORD[rdi],ymm6
vmovdqu YMMWORD[32+rdi],ymm8
vmovdqu YMMWORD[64+rdi],ymm1
vmovdqu YMMWORD[96+rdi],ymm5
je NEAR $L$done8x
lea rsi,[128+rsi]
xor r10,r10
vmovdqa YMMWORD[rsp],ymm12
lea rdi,[128+rdi]
sub rdx,128
vmovdqa YMMWORD[32+rsp],ymm13
jmp NEAR $L$oop_tail8x
ALIGN 32
$L$192_or_more8x:
vpxor ymm6,ymm6,YMMWORD[rsi]
vpxor ymm8,ymm8,YMMWORD[32+rsi]
vpxor ymm1,ymm1,YMMWORD[64+rsi]
vpxor ymm5,ymm5,YMMWORD[96+rsi]
vpxor ymm12,ymm12,YMMWORD[128+rsi]
vpxor ymm13,ymm13,YMMWORD[160+rsi]
vmovdqu YMMWORD[rdi],ymm6
vmovdqu YMMWORD[32+rdi],ymm8
vmovdqu YMMWORD[64+rdi],ymm1
vmovdqu YMMWORD[96+rdi],ymm5
vmovdqu YMMWORD[128+rdi],ymm12
vmovdqu YMMWORD[160+rdi],ymm13
je NEAR $L$done8x
lea rsi,[192+rsi]
xor r10,r10
vmovdqa YMMWORD[rsp],ymm10
lea rdi,[192+rdi]
sub rdx,192
vmovdqa YMMWORD[32+rsp],ymm15
jmp NEAR $L$oop_tail8x
ALIGN 32
$L$256_or_more8x:
vpxor ymm6,ymm6,YMMWORD[rsi]
vpxor ymm8,ymm8,YMMWORD[32+rsi]
vpxor ymm1,ymm1,YMMWORD[64+rsi]
vpxor ymm5,ymm5,YMMWORD[96+rsi]
vpxor ymm12,ymm12,YMMWORD[128+rsi]
vpxor ymm13,ymm13,YMMWORD[160+rsi]
vpxor ymm10,ymm10,YMMWORD[192+rsi]
vpxor ymm15,ymm15,YMMWORD[224+rsi]
vmovdqu YMMWORD[rdi],ymm6
vmovdqu YMMWORD[32+rdi],ymm8
vmovdqu YMMWORD[64+rdi],ymm1
vmovdqu YMMWORD[96+rdi],ymm5
vmovdqu YMMWORD[128+rdi],ymm12
vmovdqu YMMWORD[160+rdi],ymm13
vmovdqu YMMWORD[192+rdi],ymm10
vmovdqu YMMWORD[224+rdi],ymm15
je NEAR $L$done8x
lea rsi,[256+rsi]
xor r10,r10
vmovdqa YMMWORD[rsp],ymm14
lea rdi,[256+rdi]
sub rdx,256
vmovdqa YMMWORD[32+rsp],ymm2
jmp NEAR $L$oop_tail8x
ALIGN 32
$L$320_or_more8x:
vpxor ymm6,ymm6,YMMWORD[rsi]
vpxor ymm8,ymm8,YMMWORD[32+rsi]
vpxor ymm1,ymm1,YMMWORD[64+rsi]
vpxor ymm5,ymm5,YMMWORD[96+rsi]
vpxor ymm12,ymm12,YMMWORD[128+rsi]
vpxor ymm13,ymm13,YMMWORD[160+rsi]
vpxor ymm10,ymm10,YMMWORD[192+rsi]
vpxor ymm15,ymm15,YMMWORD[224+rsi]
vpxor ymm14,ymm14,YMMWORD[256+rsi]
vpxor ymm2,ymm2,YMMWORD[288+rsi]
vmovdqu YMMWORD[rdi],ymm6
vmovdqu YMMWORD[32+rdi],ymm8
vmovdqu YMMWORD[64+rdi],ymm1
vmovdqu YMMWORD[96+rdi],ymm5
vmovdqu YMMWORD[128+rdi],ymm12
vmovdqu YMMWORD[160+rdi],ymm13
vmovdqu YMMWORD[192+rdi],ymm10
vmovdqu YMMWORD[224+rdi],ymm15
vmovdqu YMMWORD[256+rdi],ymm14
vmovdqu YMMWORD[288+rdi],ymm2
je NEAR $L$done8x
lea rsi,[320+rsi]
xor r10,r10
vmovdqa YMMWORD[rsp],ymm3
lea rdi,[320+rdi]
sub rdx,320
vmovdqa YMMWORD[32+rsp],ymm7
jmp NEAR $L$oop_tail8x
ALIGN 32
$L$384_or_more8x:
vpxor ymm6,ymm6,YMMWORD[rsi]
vpxor ymm8,ymm8,YMMWORD[32+rsi]
vpxor ymm1,ymm1,YMMWORD[64+rsi]
vpxor ymm5,ymm5,YMMWORD[96+rsi]
vpxor ymm12,ymm12,YMMWORD[128+rsi]
vpxor ymm13,ymm13,YMMWORD[160+rsi]
vpxor ymm10,ymm10,YMMWORD[192+rsi]
vpxor ymm15,ymm15,YMMWORD[224+rsi]
vpxor ymm14,ymm14,YMMWORD[256+rsi]
vpxor ymm2,ymm2,YMMWORD[288+rsi]
vpxor ymm3,ymm3,YMMWORD[320+rsi]
vpxor ymm7,ymm7,YMMWORD[352+rsi]
vmovdqu YMMWORD[rdi],ymm6
vmovdqu YMMWORD[32+rdi],ymm8
vmovdqu YMMWORD[64+rdi],ymm1
vmovdqu YMMWORD[96+rdi],ymm5
vmovdqu YMMWORD[128+rdi],ymm12
vmovdqu YMMWORD[160+rdi],ymm13
vmovdqu YMMWORD[192+rdi],ymm10
vmovdqu YMMWORD[224+rdi],ymm15
vmovdqu YMMWORD[256+rdi],ymm14
vmovdqu YMMWORD[288+rdi],ymm2
vmovdqu YMMWORD[320+rdi],ymm3
vmovdqu YMMWORD[352+rdi],ymm7
je NEAR $L$done8x
lea rsi,[384+rsi]
xor r10,r10
vmovdqa YMMWORD[rsp],ymm11
lea rdi,[384+rdi]
sub rdx,384
vmovdqa YMMWORD[32+rsp],ymm9
jmp NEAR $L$oop_tail8x
ALIGN 32
$L$448_or_more8x:
vpxor ymm6,ymm6,YMMWORD[rsi]
vpxor ymm8,ymm8,YMMWORD[32+rsi]
vpxor ymm1,ymm1,YMMWORD[64+rsi]
vpxor ymm5,ymm5,YMMWORD[96+rsi]
vpxor ymm12,ymm12,YMMWORD[128+rsi]
vpxor ymm13,ymm13,YMMWORD[160+rsi]
vpxor ymm10,ymm10,YMMWORD[192+rsi]
vpxor ymm15,ymm15,YMMWORD[224+rsi]
vpxor ymm14,ymm14,YMMWORD[256+rsi]
vpxor ymm2,ymm2,YMMWORD[288+rsi]
vpxor ymm3,ymm3,YMMWORD[320+rsi]
vpxor ymm7,ymm7,YMMWORD[352+rsi]
vpxor ymm11,ymm11,YMMWORD[384+rsi]
vpxor ymm9,ymm9,YMMWORD[416+rsi]
vmovdqu YMMWORD[rdi],ymm6
vmovdqu YMMWORD[32+rdi],ymm8
vmovdqu YMMWORD[64+rdi],ymm1
vmovdqu YMMWORD[96+rdi],ymm5
vmovdqu YMMWORD[128+rdi],ymm12
vmovdqu YMMWORD[160+rdi],ymm13
vmovdqu YMMWORD[192+rdi],ymm10
vmovdqu YMMWORD[224+rdi],ymm15
vmovdqu YMMWORD[256+rdi],ymm14
vmovdqu YMMWORD[288+rdi],ymm2
vmovdqu YMMWORD[320+rdi],ymm3
vmovdqu YMMWORD[352+rdi],ymm7
vmovdqu YMMWORD[384+rdi],ymm11
vmovdqu YMMWORD[416+rdi],ymm9
je NEAR $L$done8x
lea rsi,[448+rsi]
xor r10,r10
vmovdqa YMMWORD[rsp],ymm0
lea rdi,[448+rdi]
sub rdx,448
vmovdqa YMMWORD[32+rsp],ymm4
$L$oop_tail8x:
movzx eax,BYTE[r10*1+rsi]
movzx ecx,BYTE[r10*1+rsp]
lea r10,[1+r10]
xor eax,ecx
mov BYTE[((-1))+r10*1+rdi],al
dec rdx
jnz NEAR $L$oop_tail8x
$L$done8x:
vzeroall
movaps xmm6,XMMWORD[((-168))+r9]
movaps xmm7,XMMWORD[((-152))+r9]
movaps xmm8,XMMWORD[((-136))+r9]
movaps xmm9,XMMWORD[((-120))+r9]
movaps xmm10,XMMWORD[((-104))+r9]
movaps xmm11,XMMWORD[((-88))+r9]
movaps xmm12,XMMWORD[((-72))+r9]
movaps xmm13,XMMWORD[((-56))+r9]
movaps xmm14,XMMWORD[((-40))+r9]
movaps xmm15,XMMWORD[((-24))+r9]
lea rsp,[r9]
$L$8x_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_ChaCha20_8x:
ALIGN 32
ChaCha20_avx512:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_ChaCha20_avx512:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
$L$ChaCha20_avx512:
mov r9,rsp
cmp rdx,512
ja NEAR $L$ChaCha20_16x
sub rsp,64+168
movaps XMMWORD[(-168)+r9],xmm6
movaps XMMWORD[(-152)+r9],xmm7
movaps XMMWORD[(-136)+r9],xmm8
movaps XMMWORD[(-120)+r9],xmm9
movaps XMMWORD[(-104)+r9],xmm10
movaps XMMWORD[(-88)+r9],xmm11
movaps XMMWORD[(-72)+r9],xmm12
movaps XMMWORD[(-56)+r9],xmm13
movaps XMMWORD[(-40)+r9],xmm14
movaps XMMWORD[(-24)+r9],xmm15
$L$avx512_body:
vbroadcasti32x4 zmm0,ZMMWORD[$L$sigma]
vbroadcasti32x4 zmm1,ZMMWORD[rcx]
vbroadcasti32x4 zmm2,ZMMWORD[16+rcx]
vbroadcasti32x4 zmm3,ZMMWORD[r8]
vmovdqa32 zmm16,zmm0
vmovdqa32 zmm17,zmm1
vmovdqa32 zmm18,zmm2
vpaddd zmm3,zmm3,ZMMWORD[$L$zeroz]
vmovdqa32 zmm20,ZMMWORD[$L$fourz]
mov r8,10
vmovdqa32 zmm19,zmm3
jmp NEAR $L$oop_avx512
ALIGN 16
$L$oop_outer_avx512:
vmovdqa32 zmm0,zmm16
vmovdqa32 zmm1,zmm17
vmovdqa32 zmm2,zmm18
vpaddd zmm3,zmm19,zmm20
mov r8,10
vmovdqa32 zmm19,zmm3
jmp NEAR $L$oop_avx512
ALIGN 32
$L$oop_avx512:
vpaddd zmm0,zmm0,zmm1
vpxord zmm3,zmm3,zmm0
vprold zmm3,zmm3,16
vpaddd zmm2,zmm2,zmm3
vpxord zmm1,zmm1,zmm2
vprold zmm1,zmm1,12
vpaddd zmm0,zmm0,zmm1
vpxord zmm3,zmm3,zmm0
vprold zmm3,zmm3,8
vpaddd zmm2,zmm2,zmm3
vpxord zmm1,zmm1,zmm2
vprold zmm1,zmm1,7
vpshufd zmm2,zmm2,78
vpshufd zmm1,zmm1,57
vpshufd zmm3,zmm3,147
vpaddd zmm0,zmm0,zmm1
vpxord zmm3,zmm3,zmm0
vprold zmm3,zmm3,16
vpaddd zmm2,zmm2,zmm3
vpxord zmm1,zmm1,zmm2
vprold zmm1,zmm1,12
vpaddd zmm0,zmm0,zmm1
vpxord zmm3,zmm3,zmm0
vprold zmm3,zmm3,8
vpaddd zmm2,zmm2,zmm3
vpxord zmm1,zmm1,zmm2
vprold zmm1,zmm1,7
vpshufd zmm2,zmm2,78
vpshufd zmm1,zmm1,147
vpshufd zmm3,zmm3,57
dec r8
jnz NEAR $L$oop_avx512
vpaddd zmm0,zmm0,zmm16
vpaddd zmm1,zmm1,zmm17
vpaddd zmm2,zmm2,zmm18
vpaddd zmm3,zmm3,zmm19
sub rdx,64
jb NEAR $L$tail64_avx512
vpxor xmm4,xmm0,XMMWORD[rsi]
vpxor xmm5,xmm1,XMMWORD[16+rsi]
vpxor xmm6,xmm2,XMMWORD[32+rsi]
vpxor xmm7,xmm3,XMMWORD[48+rsi]
lea rsi,[64+rsi]
vmovdqu XMMWORD[rdi],xmm4
vmovdqu XMMWORD[16+rdi],xmm5
vmovdqu XMMWORD[32+rdi],xmm6
vmovdqu XMMWORD[48+rdi],xmm7
lea rdi,[64+rdi]
jz NEAR $L$done_avx512
vextracti32x4 xmm4,zmm0,1
vextracti32x4 xmm5,zmm1,1
vextracti32x4 xmm6,zmm2,1
vextracti32x4 xmm7,zmm3,1
sub rdx,64
jb NEAR $L$tail_avx512
vpxor xmm4,xmm4,XMMWORD[rsi]
vpxor xmm5,xmm5,XMMWORD[16+rsi]
vpxor xmm6,xmm6,XMMWORD[32+rsi]
vpxor xmm7,xmm7,XMMWORD[48+rsi]
lea rsi,[64+rsi]
vmovdqu XMMWORD[rdi],xmm4
vmovdqu XMMWORD[16+rdi],xmm5
vmovdqu XMMWORD[32+rdi],xmm6
vmovdqu XMMWORD[48+rdi],xmm7
lea rdi,[64+rdi]
jz NEAR $L$done_avx512
vextracti32x4 xmm4,zmm0,2
vextracti32x4 xmm5,zmm1,2
vextracti32x4 xmm6,zmm2,2
vextracti32x4 xmm7,zmm3,2
sub rdx,64
jb NEAR $L$tail_avx512
vpxor xmm4,xmm4,XMMWORD[rsi]
vpxor xmm5,xmm5,XMMWORD[16+rsi]
vpxor xmm6,xmm6,XMMWORD[32+rsi]
vpxor xmm7,xmm7,XMMWORD[48+rsi]
lea rsi,[64+rsi]
vmovdqu XMMWORD[rdi],xmm4
vmovdqu XMMWORD[16+rdi],xmm5
vmovdqu XMMWORD[32+rdi],xmm6
vmovdqu XMMWORD[48+rdi],xmm7
lea rdi,[64+rdi]
jz NEAR $L$done_avx512
vextracti32x4 xmm4,zmm0,3
vextracti32x4 xmm5,zmm1,3
vextracti32x4 xmm6,zmm2,3
vextracti32x4 xmm7,zmm3,3
sub rdx,64
jb NEAR $L$tail_avx512
vpxor xmm4,xmm4,XMMWORD[rsi]
vpxor xmm5,xmm5,XMMWORD[16+rsi]
vpxor xmm6,xmm6,XMMWORD[32+rsi]
vpxor xmm7,xmm7,XMMWORD[48+rsi]
lea rsi,[64+rsi]
vmovdqu XMMWORD[rdi],xmm4
vmovdqu XMMWORD[16+rdi],xmm5
vmovdqu XMMWORD[32+rdi],xmm6
vmovdqu XMMWORD[48+rdi],xmm7
lea rdi,[64+rdi]
jnz NEAR $L$oop_outer_avx512
jmp NEAR $L$done_avx512
ALIGN 16
$L$tail64_avx512:
vmovdqa XMMWORD[rsp],xmm0
vmovdqa XMMWORD[16+rsp],xmm1
vmovdqa XMMWORD[32+rsp],xmm2
vmovdqa XMMWORD[48+rsp],xmm3
add rdx,64
jmp NEAR $L$oop_tail_avx512
ALIGN 16
$L$tail_avx512:
vmovdqa XMMWORD[rsp],xmm4
vmovdqa XMMWORD[16+rsp],xmm5
vmovdqa XMMWORD[32+rsp],xmm6
vmovdqa XMMWORD[48+rsp],xmm7
add rdx,64
$L$oop_tail_avx512:
movzx eax,BYTE[r8*1+rsi]
movzx ecx,BYTE[r8*1+rsp]
lea r8,[1+r8]
xor eax,ecx
mov BYTE[((-1))+r8*1+rdi],al
dec rdx
jnz NEAR $L$oop_tail_avx512
vmovdqu32 ZMMWORD[rsp],zmm16
$L$done_avx512:
vzeroall
movaps xmm6,XMMWORD[((-168))+r9]
movaps xmm7,XMMWORD[((-152))+r9]
movaps xmm8,XMMWORD[((-136))+r9]
movaps xmm9,XMMWORD[((-120))+r9]
movaps xmm10,XMMWORD[((-104))+r9]
movaps xmm11,XMMWORD[((-88))+r9]
movaps xmm12,XMMWORD[((-72))+r9]
movaps xmm13,XMMWORD[((-56))+r9]
movaps xmm14,XMMWORD[((-40))+r9]
movaps xmm15,XMMWORD[((-24))+r9]
lea rsp,[r9]
$L$avx512_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_ChaCha20_avx512:
ALIGN 32
ChaCha20_avx512vl:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_ChaCha20_avx512vl:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
$L$ChaCha20_avx512vl:
mov r9,rsp
cmp rdx,128
ja NEAR $L$ChaCha20_8xvl
sub rsp,64+168
movaps XMMWORD[(-168)+r9],xmm6
movaps XMMWORD[(-152)+r9],xmm7
movaps XMMWORD[(-136)+r9],xmm8
movaps XMMWORD[(-120)+r9],xmm9
movaps XMMWORD[(-104)+r9],xmm10
movaps XMMWORD[(-88)+r9],xmm11
movaps XMMWORD[(-72)+r9],xmm12
movaps XMMWORD[(-56)+r9],xmm13
movaps XMMWORD[(-40)+r9],xmm14
movaps XMMWORD[(-24)+r9],xmm15
$L$avx512vl_body:
vbroadcasti128 ymm0,XMMWORD[$L$sigma]
vbroadcasti128 ymm1,XMMWORD[rcx]
vbroadcasti128 ymm2,XMMWORD[16+rcx]
vbroadcasti128 ymm3,XMMWORD[r8]
vmovdqa32 ymm16,ymm0
vmovdqa32 ymm17,ymm1
vmovdqa32 ymm18,ymm2
vpaddd ymm3,ymm3,YMMWORD[$L$zeroz]
vmovdqa32 ymm20,YMMWORD[$L$twoy]
mov r8,10
vmovdqa32 ymm19,ymm3
jmp NEAR $L$oop_avx512vl
ALIGN 16
$L$oop_outer_avx512vl:
vmovdqa32 ymm2,ymm18
vpaddd ymm3,ymm19,ymm20
mov r8,10
vmovdqa32 ymm19,ymm3
jmp NEAR $L$oop_avx512vl
ALIGN 32
$L$oop_avx512vl:
vpaddd ymm0,ymm0,ymm1
vpxor ymm3,ymm3,ymm0
vprold ymm3,ymm3,16
vpaddd ymm2,ymm2,ymm3
vpxor ymm1,ymm1,ymm2
vprold ymm1,ymm1,12
vpaddd ymm0,ymm0,ymm1
vpxor ymm3,ymm3,ymm0
vprold ymm3,ymm3,8
vpaddd ymm2,ymm2,ymm3
vpxor ymm1,ymm1,ymm2
vprold ymm1,ymm1,7
vpshufd ymm2,ymm2,78
vpshufd ymm1,ymm1,57
vpshufd ymm3,ymm3,147
vpaddd ymm0,ymm0,ymm1
vpxor ymm3,ymm3,ymm0
vprold ymm3,ymm3,16
vpaddd ymm2,ymm2,ymm3
vpxor ymm1,ymm1,ymm2
vprold ymm1,ymm1,12
vpaddd ymm0,ymm0,ymm1
vpxor ymm3,ymm3,ymm0
vprold ymm3,ymm3,8
vpaddd ymm2,ymm2,ymm3
vpxor ymm1,ymm1,ymm2
vprold ymm1,ymm1,7
vpshufd ymm2,ymm2,78
vpshufd ymm1,ymm1,147
vpshufd ymm3,ymm3,57
dec r8
jnz NEAR $L$oop_avx512vl
vpaddd ymm0,ymm0,ymm16
vpaddd ymm1,ymm1,ymm17
vpaddd ymm2,ymm2,ymm18
vpaddd ymm3,ymm3,ymm19
sub rdx,64
jb NEAR $L$tail64_avx512vl
vpxor xmm4,xmm0,XMMWORD[rsi]
vpxor xmm5,xmm1,XMMWORD[16+rsi]
vpxor xmm6,xmm2,XMMWORD[32+rsi]
vpxor xmm7,xmm3,XMMWORD[48+rsi]
lea rsi,[64+rsi]
vmovdqu XMMWORD[rdi],xmm4
vmovdqu XMMWORD[16+rdi],xmm5
vmovdqu XMMWORD[32+rdi],xmm6
vmovdqu XMMWORD[48+rdi],xmm7
lea rdi,[64+rdi]
jz NEAR $L$done_avx512vl
vextracti128 xmm4,ymm0,1
vextracti128 xmm5,ymm1,1
vextracti128 xmm6,ymm2,1
vextracti128 xmm7,ymm3,1
sub rdx,64
jb NEAR $L$tail_avx512vl
vpxor xmm4,xmm4,XMMWORD[rsi]
vpxor xmm5,xmm5,XMMWORD[16+rsi]
vpxor xmm6,xmm6,XMMWORD[32+rsi]
vpxor xmm7,xmm7,XMMWORD[48+rsi]
lea rsi,[64+rsi]
vmovdqu XMMWORD[rdi],xmm4
vmovdqu XMMWORD[16+rdi],xmm5
vmovdqu XMMWORD[32+rdi],xmm6
vmovdqu XMMWORD[48+rdi],xmm7
lea rdi,[64+rdi]
vmovdqa32 ymm0,ymm16
vmovdqa32 ymm1,ymm17
jnz NEAR $L$oop_outer_avx512vl
jmp NEAR $L$done_avx512vl
ALIGN 16
$L$tail64_avx512vl:
vmovdqa XMMWORD[rsp],xmm0
vmovdqa XMMWORD[16+rsp],xmm1
vmovdqa XMMWORD[32+rsp],xmm2
vmovdqa XMMWORD[48+rsp],xmm3
add rdx,64
jmp NEAR $L$oop_tail_avx512vl
ALIGN 16
$L$tail_avx512vl:
vmovdqa XMMWORD[rsp],xmm4
vmovdqa XMMWORD[16+rsp],xmm5
vmovdqa XMMWORD[32+rsp],xmm6
vmovdqa XMMWORD[48+rsp],xmm7
add rdx,64
$L$oop_tail_avx512vl:
movzx eax,BYTE[r8*1+rsi]
movzx ecx,BYTE[r8*1+rsp]
lea r8,[1+r8]
xor eax,ecx
mov BYTE[((-1))+r8*1+rdi],al
dec rdx
jnz NEAR $L$oop_tail_avx512vl
vmovdqu32 YMMWORD[rsp],ymm16
vmovdqu32 YMMWORD[32+rsp],ymm16
$L$done_avx512vl:
vzeroall
movaps xmm6,XMMWORD[((-168))+r9]
movaps xmm7,XMMWORD[((-152))+r9]
movaps xmm8,XMMWORD[((-136))+r9]
movaps xmm9,XMMWORD[((-120))+r9]
movaps xmm10,XMMWORD[((-104))+r9]
movaps xmm11,XMMWORD[((-88))+r9]
movaps xmm12,XMMWORD[((-72))+r9]
movaps xmm13,XMMWORD[((-56))+r9]
movaps xmm14,XMMWORD[((-40))+r9]
movaps xmm15,XMMWORD[((-24))+r9]
lea rsp,[r9]
$L$avx512vl_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_ChaCha20_avx512vl:
ALIGN 32
ChaCha20_16x:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_ChaCha20_16x:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
$L$ChaCha20_16x:
mov r9,rsp
sub rsp,64+168
and rsp,-64
movaps XMMWORD[(-168)+r9],xmm6
movaps XMMWORD[(-152)+r9],xmm7
movaps XMMWORD[(-136)+r9],xmm8
movaps XMMWORD[(-120)+r9],xmm9
movaps XMMWORD[(-104)+r9],xmm10
movaps XMMWORD[(-88)+r9],xmm11
movaps XMMWORD[(-72)+r9],xmm12
movaps XMMWORD[(-56)+r9],xmm13
movaps XMMWORD[(-40)+r9],xmm14
movaps XMMWORD[(-24)+r9],xmm15
$L$16x_body:
vzeroupper
lea r10,[$L$sigma]
vbroadcasti32x4 zmm3,ZMMWORD[r10]
vbroadcasti32x4 zmm7,ZMMWORD[rcx]
vbroadcasti32x4 zmm11,ZMMWORD[16+rcx]
vbroadcasti32x4 zmm15,ZMMWORD[r8]
vpshufd zmm0,zmm3,0x00
vpshufd zmm1,zmm3,0x55
vpshufd zmm2,zmm3,0xaa
vpshufd zmm3,zmm3,0xff
vmovdqa64 zmm16,zmm0
vmovdqa64 zmm17,zmm1
vmovdqa64 zmm18,zmm2
vmovdqa64 zmm19,zmm3
vpshufd zmm4,zmm7,0x00
vpshufd zmm5,zmm7,0x55
vpshufd zmm6,zmm7,0xaa
vpshufd zmm7,zmm7,0xff
vmovdqa64 zmm20,zmm4
vmovdqa64 zmm21,zmm5
vmovdqa64 zmm22,zmm6
vmovdqa64 zmm23,zmm7
vpshufd zmm8,zmm11,0x00
vpshufd zmm9,zmm11,0x55
vpshufd zmm10,zmm11,0xaa
vpshufd zmm11,zmm11,0xff
vmovdqa64 zmm24,zmm8
vmovdqa64 zmm25,zmm9
vmovdqa64 zmm26,zmm10
vmovdqa64 zmm27,zmm11
vpshufd zmm12,zmm15,0x00
vpshufd zmm13,zmm15,0x55
vpshufd zmm14,zmm15,0xaa
vpshufd zmm15,zmm15,0xff
vpaddd zmm12,zmm12,ZMMWORD[$L$incz]
vmovdqa64 zmm28,zmm12
vmovdqa64 zmm29,zmm13
vmovdqa64 zmm30,zmm14
vmovdqa64 zmm31,zmm15
mov eax,10
jmp NEAR $L$oop16x
ALIGN 32
$L$oop_outer16x:
vpbroadcastd zmm0,DWORD[r10]
vpbroadcastd zmm1,DWORD[4+r10]
vpbroadcastd zmm2,DWORD[8+r10]
vpbroadcastd zmm3,DWORD[12+r10]
vpaddd zmm28,zmm28,ZMMWORD[$L$sixteen]
vmovdqa64 zmm4,zmm20
vmovdqa64 zmm5,zmm21
vmovdqa64 zmm6,zmm22
vmovdqa64 zmm7,zmm23
vmovdqa64 zmm8,zmm24
vmovdqa64 zmm9,zmm25
vmovdqa64 zmm10,zmm26
vmovdqa64 zmm11,zmm27
vmovdqa64 zmm12,zmm28
vmovdqa64 zmm13,zmm29
vmovdqa64 zmm14,zmm30
vmovdqa64 zmm15,zmm31
vmovdqa64 zmm16,zmm0
vmovdqa64 zmm17,zmm1
vmovdqa64 zmm18,zmm2
vmovdqa64 zmm19,zmm3
mov eax,10
jmp NEAR $L$oop16x
ALIGN 32
$L$oop16x:
vpaddd zmm0,zmm0,zmm4
vpaddd zmm1,zmm1,zmm5
vpaddd zmm2,zmm2,zmm6
vpaddd zmm3,zmm3,zmm7
vpxord zmm12,zmm12,zmm0
vpxord zmm13,zmm13,zmm1
vpxord zmm14,zmm14,zmm2
vpxord zmm15,zmm15,zmm3
vprold zmm12,zmm12,16
vprold zmm13,zmm13,16
vprold zmm14,zmm14,16
vprold zmm15,zmm15,16
vpaddd zmm8,zmm8,zmm12
vpaddd zmm9,zmm9,zmm13
vpaddd zmm10,zmm10,zmm14
vpaddd zmm11,zmm11,zmm15
vpxord zmm4,zmm4,zmm8
vpxord zmm5,zmm5,zmm9
vpxord zmm6,zmm6,zmm10
vpxord zmm7,zmm7,zmm11
vprold zmm4,zmm4,12
vprold zmm5,zmm5,12
vprold zmm6,zmm6,12
vprold zmm7,zmm7,12
vpaddd zmm0,zmm0,zmm4
vpaddd zmm1,zmm1,zmm5
vpaddd zmm2,zmm2,zmm6
vpaddd zmm3,zmm3,zmm7
vpxord zmm12,zmm12,zmm0
vpxord zmm13,zmm13,zmm1
vpxord zmm14,zmm14,zmm2
vpxord zmm15,zmm15,zmm3
vprold zmm12,zmm12,8
vprold zmm13,zmm13,8
vprold zmm14,zmm14,8
vprold zmm15,zmm15,8
vpaddd zmm8,zmm8,zmm12
vpaddd zmm9,zmm9,zmm13
vpaddd zmm10,zmm10,zmm14
vpaddd zmm11,zmm11,zmm15
vpxord zmm4,zmm4,zmm8
vpxord zmm5,zmm5,zmm9
vpxord zmm6,zmm6,zmm10
vpxord zmm7,zmm7,zmm11
vprold zmm4,zmm4,7
vprold zmm5,zmm5,7
vprold zmm6,zmm6,7
vprold zmm7,zmm7,7
vpaddd zmm0,zmm0,zmm5
vpaddd zmm1,zmm1,zmm6
vpaddd zmm2,zmm2,zmm7
vpaddd zmm3,zmm3,zmm4
vpxord zmm15,zmm15,zmm0
vpxord zmm12,zmm12,zmm1
vpxord zmm13,zmm13,zmm2
vpxord zmm14,zmm14,zmm3
vprold zmm15,zmm15,16
vprold zmm12,zmm12,16
vprold zmm13,zmm13,16
vprold zmm14,zmm14,16
vpaddd zmm10,zmm10,zmm15
vpaddd zmm11,zmm11,zmm12
vpaddd zmm8,zmm8,zmm13
vpaddd zmm9,zmm9,zmm14
vpxord zmm5,zmm5,zmm10
vpxord zmm6,zmm6,zmm11
vpxord zmm7,zmm7,zmm8
vpxord zmm4,zmm4,zmm9
vprold zmm5,zmm5,12
vprold zmm6,zmm6,12
vprold zmm7,zmm7,12
vprold zmm4,zmm4,12
vpaddd zmm0,zmm0,zmm5
vpaddd zmm1,zmm1,zmm6
vpaddd zmm2,zmm2,zmm7
vpaddd zmm3,zmm3,zmm4
vpxord zmm15,zmm15,zmm0
vpxord zmm12,zmm12,zmm1
vpxord zmm13,zmm13,zmm2
vpxord zmm14,zmm14,zmm3
vprold zmm15,zmm15,8
vprold zmm12,zmm12,8
vprold zmm13,zmm13,8
vprold zmm14,zmm14,8
vpaddd zmm10,zmm10,zmm15
vpaddd zmm11,zmm11,zmm12
vpaddd zmm8,zmm8,zmm13
vpaddd zmm9,zmm9,zmm14
vpxord zmm5,zmm5,zmm10
vpxord zmm6,zmm6,zmm11
vpxord zmm7,zmm7,zmm8
vpxord zmm4,zmm4,zmm9
vprold zmm5,zmm5,7
vprold zmm6,zmm6,7
vprold zmm7,zmm7,7
vprold zmm4,zmm4,7
dec eax
jnz NEAR $L$oop16x
vpaddd zmm0,zmm0,zmm16
vpaddd zmm1,zmm1,zmm17
vpaddd zmm2,zmm2,zmm18
vpaddd zmm3,zmm3,zmm19
vpunpckldq zmm18,zmm0,zmm1
vpunpckldq zmm19,zmm2,zmm3
vpunpckhdq zmm0,zmm0,zmm1
vpunpckhdq zmm2,zmm2,zmm3
vpunpcklqdq zmm1,zmm18,zmm19
vpunpckhqdq zmm18,zmm18,zmm19
vpunpcklqdq zmm3,zmm0,zmm2
vpunpckhqdq zmm0,zmm0,zmm2
vpaddd zmm4,zmm4,zmm20
vpaddd zmm5,zmm5,zmm21
vpaddd zmm6,zmm6,zmm22
vpaddd zmm7,zmm7,zmm23
vpunpckldq zmm2,zmm4,zmm5
vpunpckldq zmm19,zmm6,zmm7
vpunpckhdq zmm4,zmm4,zmm5
vpunpckhdq zmm6,zmm6,zmm7
vpunpcklqdq zmm5,zmm2,zmm19
vpunpckhqdq zmm2,zmm2,zmm19
vpunpcklqdq zmm7,zmm4,zmm6
vpunpckhqdq zmm4,zmm4,zmm6
vshufi32x4 zmm19,zmm1,zmm5,0x44
vshufi32x4 zmm5,zmm1,zmm5,0xee
vshufi32x4 zmm1,zmm18,zmm2,0x44
vshufi32x4 zmm2,zmm18,zmm2,0xee
vshufi32x4 zmm18,zmm3,zmm7,0x44
vshufi32x4 zmm7,zmm3,zmm7,0xee
vshufi32x4 zmm3,zmm0,zmm4,0x44
vshufi32x4 zmm4,zmm0,zmm4,0xee
vpaddd zmm8,zmm8,zmm24
vpaddd zmm9,zmm9,zmm25
vpaddd zmm10,zmm10,zmm26
vpaddd zmm11,zmm11,zmm27
vpunpckldq zmm6,zmm8,zmm9
vpunpckldq zmm0,zmm10,zmm11
vpunpckhdq zmm8,zmm8,zmm9
vpunpckhdq zmm10,zmm10,zmm11
vpunpcklqdq zmm9,zmm6,zmm0
vpunpckhqdq zmm6,zmm6,zmm0
vpunpcklqdq zmm11,zmm8,zmm10
vpunpckhqdq zmm8,zmm8,zmm10
vpaddd zmm12,zmm12,zmm28
vpaddd zmm13,zmm13,zmm29
vpaddd zmm14,zmm14,zmm30
vpaddd zmm15,zmm15,zmm31
vpunpckldq zmm10,zmm12,zmm13
vpunpckldq zmm0,zmm14,zmm15
vpunpckhdq zmm12,zmm12,zmm13
vpunpckhdq zmm14,zmm14,zmm15
vpunpcklqdq zmm13,zmm10,zmm0
vpunpckhqdq zmm10,zmm10,zmm0
vpunpcklqdq zmm15,zmm12,zmm14
vpunpckhqdq zmm12,zmm12,zmm14
vshufi32x4 zmm0,zmm9,zmm13,0x44
vshufi32x4 zmm13,zmm9,zmm13,0xee
vshufi32x4 zmm9,zmm6,zmm10,0x44
vshufi32x4 zmm10,zmm6,zmm10,0xee
vshufi32x4 zmm6,zmm11,zmm15,0x44
vshufi32x4 zmm15,zmm11,zmm15,0xee
vshufi32x4 zmm11,zmm8,zmm12,0x44
vshufi32x4 zmm12,zmm8,zmm12,0xee
vshufi32x4 zmm16,zmm19,zmm0,0x88
vshufi32x4 zmm19,zmm19,zmm0,0xdd
vshufi32x4 zmm0,zmm5,zmm13,0x88
vshufi32x4 zmm13,zmm5,zmm13,0xdd
vshufi32x4 zmm17,zmm1,zmm9,0x88
vshufi32x4 zmm1,zmm1,zmm9,0xdd
vshufi32x4 zmm9,zmm2,zmm10,0x88
vshufi32x4 zmm10,zmm2,zmm10,0xdd
vshufi32x4 zmm14,zmm18,zmm6,0x88
vshufi32x4 zmm18,zmm18,zmm6,0xdd
vshufi32x4 zmm6,zmm7,zmm15,0x88
vshufi32x4 zmm15,zmm7,zmm15,0xdd
vshufi32x4 zmm8,zmm3,zmm11,0x88
vshufi32x4 zmm3,zmm3,zmm11,0xdd
vshufi32x4 zmm11,zmm4,zmm12,0x88
vshufi32x4 zmm12,zmm4,zmm12,0xdd
cmp rdx,64*16
jb NEAR $L$tail16x
vpxord zmm16,zmm16,ZMMWORD[rsi]
vpxord zmm17,zmm17,ZMMWORD[64+rsi]
vpxord zmm14,zmm14,ZMMWORD[128+rsi]
vpxord zmm8,zmm8,ZMMWORD[192+rsi]
vmovdqu32 ZMMWORD[rdi],zmm16
vmovdqu32 ZMMWORD[64+rdi],zmm17
vmovdqu32 ZMMWORD[128+rdi],zmm14
vmovdqu32 ZMMWORD[192+rdi],zmm8
vpxord zmm19,zmm19,ZMMWORD[256+rsi]
vpxord zmm1,zmm1,ZMMWORD[320+rsi]
vpxord zmm18,zmm18,ZMMWORD[384+rsi]
vpxord zmm3,zmm3,ZMMWORD[448+rsi]
vmovdqu32 ZMMWORD[256+rdi],zmm19
vmovdqu32 ZMMWORD[320+rdi],zmm1
vmovdqu32 ZMMWORD[384+rdi],zmm18
vmovdqu32 ZMMWORD[448+rdi],zmm3
vpxord zmm0,zmm0,ZMMWORD[512+rsi]
vpxord zmm9,zmm9,ZMMWORD[576+rsi]
vpxord zmm6,zmm6,ZMMWORD[640+rsi]
vpxord zmm11,zmm11,ZMMWORD[704+rsi]
vmovdqu32 ZMMWORD[512+rdi],zmm0
vmovdqu32 ZMMWORD[576+rdi],zmm9
vmovdqu32 ZMMWORD[640+rdi],zmm6
vmovdqu32 ZMMWORD[704+rdi],zmm11
vpxord zmm13,zmm13,ZMMWORD[768+rsi]
vpxord zmm10,zmm10,ZMMWORD[832+rsi]
vpxord zmm15,zmm15,ZMMWORD[896+rsi]
vpxord zmm12,zmm12,ZMMWORD[960+rsi]
lea rsi,[1024+rsi]
vmovdqu32 ZMMWORD[768+rdi],zmm13
vmovdqu32 ZMMWORD[832+rdi],zmm10
vmovdqu32 ZMMWORD[896+rdi],zmm15
vmovdqu32 ZMMWORD[960+rdi],zmm12
lea rdi,[1024+rdi]
sub rdx,64*16
jnz NEAR $L$oop_outer16x
jmp NEAR $L$done16x
ALIGN 32
$L$tail16x:
xor r10,r10
sub rdi,rsi
cmp rdx,64*1
jb NEAR $L$ess_than_64_16x
vpxord zmm16,zmm16,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm16
je NEAR $L$done16x
vmovdqa32 zmm16,zmm17
lea rsi,[64+rsi]
cmp rdx,64*2
jb NEAR $L$ess_than_64_16x
vpxord zmm17,zmm17,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm17
je NEAR $L$done16x
vmovdqa32 zmm16,zmm14
lea rsi,[64+rsi]
cmp rdx,64*3
jb NEAR $L$ess_than_64_16x
vpxord zmm14,zmm14,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm14
je NEAR $L$done16x
vmovdqa32 zmm16,zmm8
lea rsi,[64+rsi]
cmp rdx,64*4
jb NEAR $L$ess_than_64_16x
vpxord zmm8,zmm8,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm8
je NEAR $L$done16x
vmovdqa32 zmm16,zmm19
lea rsi,[64+rsi]
cmp rdx,64*5
jb NEAR $L$ess_than_64_16x
vpxord zmm19,zmm19,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm19
je NEAR $L$done16x
vmovdqa32 zmm16,zmm1
lea rsi,[64+rsi]
cmp rdx,64*6
jb NEAR $L$ess_than_64_16x
vpxord zmm1,zmm1,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm1
je NEAR $L$done16x
vmovdqa32 zmm16,zmm18
lea rsi,[64+rsi]
cmp rdx,64*7
jb NEAR $L$ess_than_64_16x
vpxord zmm18,zmm18,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm18
je NEAR $L$done16x
vmovdqa32 zmm16,zmm3
lea rsi,[64+rsi]
cmp rdx,64*8
jb NEAR $L$ess_than_64_16x
vpxord zmm3,zmm3,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm3
je NEAR $L$done16x
vmovdqa32 zmm16,zmm0
lea rsi,[64+rsi]
cmp rdx,64*9
jb NEAR $L$ess_than_64_16x
vpxord zmm0,zmm0,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm0
je NEAR $L$done16x
vmovdqa32 zmm16,zmm9
lea rsi,[64+rsi]
cmp rdx,64*10
jb NEAR $L$ess_than_64_16x
vpxord zmm9,zmm9,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm9
je NEAR $L$done16x
vmovdqa32 zmm16,zmm6
lea rsi,[64+rsi]
cmp rdx,64*11
jb NEAR $L$ess_than_64_16x
vpxord zmm6,zmm6,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm6
je NEAR $L$done16x
vmovdqa32 zmm16,zmm11
lea rsi,[64+rsi]
cmp rdx,64*12
jb NEAR $L$ess_than_64_16x
vpxord zmm11,zmm11,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm11
je NEAR $L$done16x
vmovdqa32 zmm16,zmm13
lea rsi,[64+rsi]
cmp rdx,64*13
jb NEAR $L$ess_than_64_16x
vpxord zmm13,zmm13,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm13
je NEAR $L$done16x
vmovdqa32 zmm16,zmm10
lea rsi,[64+rsi]
cmp rdx,64*14
jb NEAR $L$ess_than_64_16x
vpxord zmm10,zmm10,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm10
je NEAR $L$done16x
vmovdqa32 zmm16,zmm15
lea rsi,[64+rsi]
cmp rdx,64*15
jb NEAR $L$ess_than_64_16x
vpxord zmm15,zmm15,ZMMWORD[rsi]
vmovdqu32 ZMMWORD[rsi*1+rdi],zmm15
je NEAR $L$done16x
vmovdqa32 zmm16,zmm12
lea rsi,[64+rsi]
$L$ess_than_64_16x:
vmovdqa32 ZMMWORD[rsp],zmm16
lea rdi,[rsi*1+rdi]
and rdx,63
$L$oop_tail16x:
movzx eax,BYTE[r10*1+rsi]
movzx ecx,BYTE[r10*1+rsp]
lea r10,[1+r10]
xor eax,ecx
mov BYTE[((-1))+r10*1+rdi],al
dec rdx
jnz NEAR $L$oop_tail16x
vpxord zmm16,zmm16,zmm16
vmovdqa32 ZMMWORD[rsp],zmm16
$L$done16x:
vzeroall
movaps xmm6,XMMWORD[((-168))+r9]
movaps xmm7,XMMWORD[((-152))+r9]
movaps xmm8,XMMWORD[((-136))+r9]
movaps xmm9,XMMWORD[((-120))+r9]
movaps xmm10,XMMWORD[((-104))+r9]
movaps xmm11,XMMWORD[((-88))+r9]
movaps xmm12,XMMWORD[((-72))+r9]
movaps xmm13,XMMWORD[((-56))+r9]
movaps xmm14,XMMWORD[((-40))+r9]
movaps xmm15,XMMWORD[((-24))+r9]
lea rsp,[r9]
$L$16x_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_ChaCha20_16x:
ALIGN 32
ChaCha20_8xvl:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_ChaCha20_8xvl:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
$L$ChaCha20_8xvl:
mov r9,rsp
sub rsp,64+168
and rsp,-64
movaps XMMWORD[(-168)+r9],xmm6
movaps XMMWORD[(-152)+r9],xmm7
movaps XMMWORD[(-136)+r9],xmm8
movaps XMMWORD[(-120)+r9],xmm9
movaps XMMWORD[(-104)+r9],xmm10
movaps XMMWORD[(-88)+r9],xmm11
movaps XMMWORD[(-72)+r9],xmm12
movaps XMMWORD[(-56)+r9],xmm13
movaps XMMWORD[(-40)+r9],xmm14
movaps XMMWORD[(-24)+r9],xmm15
$L$8xvl_body:
vzeroupper
lea r10,[$L$sigma]
vbroadcasti128 ymm3,XMMWORD[r10]
vbroadcasti128 ymm7,XMMWORD[rcx]
vbroadcasti128 ymm11,XMMWORD[16+rcx]
vbroadcasti128 ymm15,XMMWORD[r8]
vpshufd ymm0,ymm3,0x00
vpshufd ymm1,ymm3,0x55
vpshufd ymm2,ymm3,0xaa
vpshufd ymm3,ymm3,0xff
vmovdqa64 ymm16,ymm0
vmovdqa64 ymm17,ymm1
vmovdqa64 ymm18,ymm2
vmovdqa64 ymm19,ymm3
vpshufd ymm4,ymm7,0x00
vpshufd ymm5,ymm7,0x55
vpshufd ymm6,ymm7,0xaa
vpshufd ymm7,ymm7,0xff
vmovdqa64 ymm20,ymm4
vmovdqa64 ymm21,ymm5
vmovdqa64 ymm22,ymm6
vmovdqa64 ymm23,ymm7
vpshufd ymm8,ymm11,0x00
vpshufd ymm9,ymm11,0x55
vpshufd ymm10,ymm11,0xaa
vpshufd ymm11,ymm11,0xff
vmovdqa64 ymm24,ymm8
vmovdqa64 ymm25,ymm9
vmovdqa64 ymm26,ymm10
vmovdqa64 ymm27,ymm11
vpshufd ymm12,ymm15,0x00
vpshufd ymm13,ymm15,0x55
vpshufd ymm14,ymm15,0xaa
vpshufd ymm15,ymm15,0xff
vpaddd ymm12,ymm12,YMMWORD[$L$incy]
vmovdqa64 ymm28,ymm12
vmovdqa64 ymm29,ymm13
vmovdqa64 ymm30,ymm14
vmovdqa64 ymm31,ymm15
mov eax,10
jmp NEAR $L$oop8xvl
ALIGN 32
$L$oop_outer8xvl:
vpbroadcastd ymm2,DWORD[8+r10]
vpbroadcastd ymm3,DWORD[12+r10]
vpaddd ymm28,ymm28,YMMWORD[$L$eight]
vmovdqa64 ymm4,ymm20
vmovdqa64 ymm5,ymm21
vmovdqa64 ymm6,ymm22
vmovdqa64 ymm7,ymm23
vmovdqa64 ymm8,ymm24
vmovdqa64 ymm9,ymm25
vmovdqa64 ymm10,ymm26
vmovdqa64 ymm11,ymm27
vmovdqa64 ymm12,ymm28
vmovdqa64 ymm13,ymm29
vmovdqa64 ymm14,ymm30
vmovdqa64 ymm15,ymm31
vmovdqa64 ymm16,ymm0
vmovdqa64 ymm17,ymm1
vmovdqa64 ymm18,ymm2
vmovdqa64 ymm19,ymm3
mov eax,10
jmp NEAR $L$oop8xvl
ALIGN 32
$L$oop8xvl:
vpaddd ymm0,ymm0,ymm4
vpaddd ymm1,ymm1,ymm5
vpaddd ymm2,ymm2,ymm6
vpaddd ymm3,ymm3,ymm7
vpxor ymm12,ymm12,ymm0
vpxor ymm13,ymm13,ymm1
vpxor ymm14,ymm14,ymm2
vpxor ymm15,ymm15,ymm3
vprold ymm12,ymm12,16
vprold ymm13,ymm13,16
vprold ymm14,ymm14,16
vprold ymm15,ymm15,16
vpaddd ymm8,ymm8,ymm12
vpaddd ymm9,ymm9,ymm13
vpaddd ymm10,ymm10,ymm14
vpaddd ymm11,ymm11,ymm15
vpxor ymm4,ymm4,ymm8
vpxor ymm5,ymm5,ymm9
vpxor ymm6,ymm6,ymm10
vpxor ymm7,ymm7,ymm11
vprold ymm4,ymm4,12
vprold ymm5,ymm5,12
vprold ymm6,ymm6,12
vprold ymm7,ymm7,12
vpaddd ymm0,ymm0,ymm4
vpaddd ymm1,ymm1,ymm5
vpaddd ymm2,ymm2,ymm6
vpaddd ymm3,ymm3,ymm7
vpxor ymm12,ymm12,ymm0
vpxor ymm13,ymm13,ymm1
vpxor ymm14,ymm14,ymm2
vpxor ymm15,ymm15,ymm3
vprold ymm12,ymm12,8
vprold ymm13,ymm13,8
vprold ymm14,ymm14,8
vprold ymm15,ymm15,8
vpaddd ymm8,ymm8,ymm12
vpaddd ymm9,ymm9,ymm13
vpaddd ymm10,ymm10,ymm14
vpaddd ymm11,ymm11,ymm15
vpxor ymm4,ymm4,ymm8
vpxor ymm5,ymm5,ymm9
vpxor ymm6,ymm6,ymm10
vpxor ymm7,ymm7,ymm11
vprold ymm4,ymm4,7
vprold ymm5,ymm5,7
vprold ymm6,ymm6,7
vprold ymm7,ymm7,7
vpaddd ymm0,ymm0,ymm5
vpaddd ymm1,ymm1,ymm6
vpaddd ymm2,ymm2,ymm7
vpaddd ymm3,ymm3,ymm4
vpxor ymm15,ymm15,ymm0
vpxor ymm12,ymm12,ymm1
vpxor ymm13,ymm13,ymm2
vpxor ymm14,ymm14,ymm3
vprold ymm15,ymm15,16
vprold ymm12,ymm12,16
vprold ymm13,ymm13,16
vprold ymm14,ymm14,16
vpaddd ymm10,ymm10,ymm15
vpaddd ymm11,ymm11,ymm12
vpaddd ymm8,ymm8,ymm13
vpaddd ymm9,ymm9,ymm14
vpxor ymm5,ymm5,ymm10
vpxor ymm6,ymm6,ymm11
vpxor ymm7,ymm7,ymm8
vpxor ymm4,ymm4,ymm9
vprold ymm5,ymm5,12
vprold ymm6,ymm6,12
vprold ymm7,ymm7,12
vprold ymm4,ymm4,12
vpaddd ymm0,ymm0,ymm5
vpaddd ymm1,ymm1,ymm6
vpaddd ymm2,ymm2,ymm7
vpaddd ymm3,ymm3,ymm4
vpxor ymm15,ymm15,ymm0
vpxor ymm12,ymm12,ymm1
vpxor ymm13,ymm13,ymm2
vpxor ymm14,ymm14,ymm3
vprold ymm15,ymm15,8
vprold ymm12,ymm12,8
vprold ymm13,ymm13,8
vprold ymm14,ymm14,8
vpaddd ymm10,ymm10,ymm15
vpaddd ymm11,ymm11,ymm12
vpaddd ymm8,ymm8,ymm13
vpaddd ymm9,ymm9,ymm14
vpxor ymm5,ymm5,ymm10
vpxor ymm6,ymm6,ymm11
vpxor ymm7,ymm7,ymm8
vpxor ymm4,ymm4,ymm9
vprold ymm5,ymm5,7
vprold ymm6,ymm6,7
vprold ymm7,ymm7,7
vprold ymm4,ymm4,7
dec eax
jnz NEAR $L$oop8xvl
vpaddd ymm0,ymm0,ymm16
vpaddd ymm1,ymm1,ymm17
vpaddd ymm2,ymm2,ymm18
vpaddd ymm3,ymm3,ymm19
vpunpckldq ymm18,ymm0,ymm1
vpunpckldq ymm19,ymm2,ymm3
vpunpckhdq ymm0,ymm0,ymm1
vpunpckhdq ymm2,ymm2,ymm3
vpunpcklqdq ymm1,ymm18,ymm19
vpunpckhqdq ymm18,ymm18,ymm19
vpunpcklqdq ymm3,ymm0,ymm2
vpunpckhqdq ymm0,ymm0,ymm2
vpaddd ymm4,ymm4,ymm20
vpaddd ymm5,ymm5,ymm21
vpaddd ymm6,ymm6,ymm22
vpaddd ymm7,ymm7,ymm23
vpunpckldq ymm2,ymm4,ymm5
vpunpckldq ymm19,ymm6,ymm7
vpunpckhdq ymm4,ymm4,ymm5
vpunpckhdq ymm6,ymm6,ymm7
vpunpcklqdq ymm5,ymm2,ymm19
vpunpckhqdq ymm2,ymm2,ymm19
vpunpcklqdq ymm7,ymm4,ymm6
vpunpckhqdq ymm4,ymm4,ymm6
vshufi32x4 ymm19,ymm1,ymm5,0
vshufi32x4 ymm5,ymm1,ymm5,3
vshufi32x4 ymm1,ymm18,ymm2,0
vshufi32x4 ymm2,ymm18,ymm2,3
vshufi32x4 ymm18,ymm3,ymm7,0
vshufi32x4 ymm7,ymm3,ymm7,3
vshufi32x4 ymm3,ymm0,ymm4,0
vshufi32x4 ymm4,ymm0,ymm4,3
vpaddd ymm8,ymm8,ymm24
vpaddd ymm9,ymm9,ymm25
vpaddd ymm10,ymm10,ymm26
vpaddd ymm11,ymm11,ymm27
vpunpckldq ymm6,ymm8,ymm9
vpunpckldq ymm0,ymm10,ymm11
vpunpckhdq ymm8,ymm8,ymm9
vpunpckhdq ymm10,ymm10,ymm11
vpunpcklqdq ymm9,ymm6,ymm0
vpunpckhqdq ymm6,ymm6,ymm0
vpunpcklqdq ymm11,ymm8,ymm10
vpunpckhqdq ymm8,ymm8,ymm10
vpaddd ymm12,ymm12,ymm28
vpaddd ymm13,ymm13,ymm29
vpaddd ymm14,ymm14,ymm30
vpaddd ymm15,ymm15,ymm31
vpunpckldq ymm10,ymm12,ymm13
vpunpckldq ymm0,ymm14,ymm15
vpunpckhdq ymm12,ymm12,ymm13
vpunpckhdq ymm14,ymm14,ymm15
vpunpcklqdq ymm13,ymm10,ymm0
vpunpckhqdq ymm10,ymm10,ymm0
vpunpcklqdq ymm15,ymm12,ymm14
vpunpckhqdq ymm12,ymm12,ymm14
vperm2i128 ymm0,ymm9,ymm13,0x20
vperm2i128 ymm13,ymm9,ymm13,0x31
vperm2i128 ymm9,ymm6,ymm10,0x20
vperm2i128 ymm10,ymm6,ymm10,0x31
vperm2i128 ymm6,ymm11,ymm15,0x20
vperm2i128 ymm15,ymm11,ymm15,0x31
vperm2i128 ymm11,ymm8,ymm12,0x20
vperm2i128 ymm12,ymm8,ymm12,0x31
cmp rdx,64*8
jb NEAR $L$tail8xvl
mov eax,0x80
vpxord ymm19,ymm19,YMMWORD[rsi]
vpxor ymm0,ymm0,YMMWORD[32+rsi]
vpxor ymm5,ymm5,YMMWORD[64+rsi]
vpxor ymm13,ymm13,YMMWORD[96+rsi]
lea rsi,[rax*1+rsi]
vmovdqu32 YMMWORD[rdi],ymm19
vmovdqu YMMWORD[32+rdi],ymm0
vmovdqu YMMWORD[64+rdi],ymm5
vmovdqu YMMWORD[96+rdi],ymm13
lea rdi,[rax*1+rdi]
vpxor ymm1,ymm1,YMMWORD[rsi]
vpxor ymm9,ymm9,YMMWORD[32+rsi]
vpxor ymm2,ymm2,YMMWORD[64+rsi]
vpxor ymm10,ymm10,YMMWORD[96+rsi]
lea rsi,[rax*1+rsi]
vmovdqu YMMWORD[rdi],ymm1
vmovdqu YMMWORD[32+rdi],ymm9
vmovdqu YMMWORD[64+rdi],ymm2
vmovdqu YMMWORD[96+rdi],ymm10
lea rdi,[rax*1+rdi]
vpxord ymm18,ymm18,YMMWORD[rsi]
vpxor ymm6,ymm6,YMMWORD[32+rsi]
vpxor ymm7,ymm7,YMMWORD[64+rsi]
vpxor ymm15,ymm15,YMMWORD[96+rsi]
lea rsi,[rax*1+rsi]
vmovdqu32 YMMWORD[rdi],ymm18
vmovdqu YMMWORD[32+rdi],ymm6
vmovdqu YMMWORD[64+rdi],ymm7
vmovdqu YMMWORD[96+rdi],ymm15
lea rdi,[rax*1+rdi]
vpxor ymm3,ymm3,YMMWORD[rsi]
vpxor ymm11,ymm11,YMMWORD[32+rsi]
vpxor ymm4,ymm4,YMMWORD[64+rsi]
vpxor ymm12,ymm12,YMMWORD[96+rsi]
lea rsi,[rax*1+rsi]
vmovdqu YMMWORD[rdi],ymm3
vmovdqu YMMWORD[32+rdi],ymm11
vmovdqu YMMWORD[64+rdi],ymm4
vmovdqu YMMWORD[96+rdi],ymm12
lea rdi,[rax*1+rdi]
vpbroadcastd ymm0,DWORD[r10]
vpbroadcastd ymm1,DWORD[4+r10]
sub rdx,64*8
jnz NEAR $L$oop_outer8xvl
jmp NEAR $L$done8xvl
ALIGN 32
$L$tail8xvl:
vmovdqa64 ymm8,ymm19
xor r10,r10
sub rdi,rsi
cmp rdx,64*1
jb NEAR $L$ess_than_64_8xvl
vpxor ymm8,ymm8,YMMWORD[rsi]
vpxor ymm0,ymm0,YMMWORD[32+rsi]
vmovdqu YMMWORD[rsi*1+rdi],ymm8
vmovdqu YMMWORD[32+rsi*1+rdi],ymm0
je NEAR $L$done8xvl
vmovdqa ymm8,ymm5
vmovdqa ymm0,ymm13
lea rsi,[64+rsi]
cmp rdx,64*2
jb NEAR $L$ess_than_64_8xvl
vpxor ymm5,ymm5,YMMWORD[rsi]
vpxor ymm13,ymm13,YMMWORD[32+rsi]
vmovdqu YMMWORD[rsi*1+rdi],ymm5
vmovdqu YMMWORD[32+rsi*1+rdi],ymm13
je NEAR $L$done8xvl
vmovdqa ymm8,ymm1
vmovdqa ymm0,ymm9
lea rsi,[64+rsi]
cmp rdx,64*3
jb NEAR $L$ess_than_64_8xvl
vpxor ymm1,ymm1,YMMWORD[rsi]
vpxor ymm9,ymm9,YMMWORD[32+rsi]
vmovdqu YMMWORD[rsi*1+rdi],ymm1
vmovdqu YMMWORD[32+rsi*1+rdi],ymm9
je NEAR $L$done8xvl
vmovdqa ymm8,ymm2
vmovdqa ymm0,ymm10
lea rsi,[64+rsi]
cmp rdx,64*4
jb NEAR $L$ess_than_64_8xvl
vpxor ymm2,ymm2,YMMWORD[rsi]
vpxor ymm10,ymm10,YMMWORD[32+rsi]
vmovdqu YMMWORD[rsi*1+rdi],ymm2
vmovdqu YMMWORD[32+rsi*1+rdi],ymm10
je NEAR $L$done8xvl
vmovdqa32 ymm8,ymm18
vmovdqa ymm0,ymm6
lea rsi,[64+rsi]
cmp rdx,64*5
jb NEAR $L$ess_than_64_8xvl
vpxord ymm18,ymm18,YMMWORD[rsi]
vpxor ymm6,ymm6,YMMWORD[32+rsi]
vmovdqu32 YMMWORD[rsi*1+rdi],ymm18
vmovdqu YMMWORD[32+rsi*1+rdi],ymm6
je NEAR $L$done8xvl
vmovdqa ymm8,ymm7
vmovdqa ymm0,ymm15
lea rsi,[64+rsi]
cmp rdx,64*6
jb NEAR $L$ess_than_64_8xvl
vpxor ymm7,ymm7,YMMWORD[rsi]
vpxor ymm15,ymm15,YMMWORD[32+rsi]
vmovdqu YMMWORD[rsi*1+rdi],ymm7
vmovdqu YMMWORD[32+rsi*1+rdi],ymm15
je NEAR $L$done8xvl
vmovdqa ymm8,ymm3
vmovdqa ymm0,ymm11
lea rsi,[64+rsi]
cmp rdx,64*7
jb NEAR $L$ess_than_64_8xvl
vpxor ymm3,ymm3,YMMWORD[rsi]
vpxor ymm11,ymm11,YMMWORD[32+rsi]
vmovdqu YMMWORD[rsi*1+rdi],ymm3
vmovdqu YMMWORD[32+rsi*1+rdi],ymm11
je NEAR $L$done8xvl
vmovdqa ymm8,ymm4
vmovdqa ymm0,ymm12
lea rsi,[64+rsi]
$L$ess_than_64_8xvl:
vmovdqa YMMWORD[rsp],ymm8
vmovdqa YMMWORD[32+rsp],ymm0
lea rdi,[rsi*1+rdi]
and rdx,63
$L$oop_tail8xvl:
movzx eax,BYTE[r10*1+rsi]
movzx ecx,BYTE[r10*1+rsp]
lea r10,[1+r10]
xor eax,ecx
mov BYTE[((-1))+r10*1+rdi],al
dec rdx
jnz NEAR $L$oop_tail8xvl
vpxor ymm8,ymm8,ymm8
vmovdqa YMMWORD[rsp],ymm8
vmovdqa YMMWORD[32+rsp],ymm8
$L$done8xvl:
vzeroall
movaps xmm6,XMMWORD[((-168))+r9]
movaps xmm7,XMMWORD[((-152))+r9]
movaps xmm8,XMMWORD[((-136))+r9]
movaps xmm9,XMMWORD[((-120))+r9]
movaps xmm10,XMMWORD[((-104))+r9]
movaps xmm11,XMMWORD[((-88))+r9]
movaps xmm12,XMMWORD[((-72))+r9]
movaps xmm13,XMMWORD[((-56))+r9]
movaps xmm14,XMMWORD[((-40))+r9]
movaps xmm15,XMMWORD[((-24))+r9]
lea rsp,[r9]
$L$8xvl_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_ChaCha20_8xvl:
EXTERN __imp_RtlVirtualUnwind
ALIGN 16
se_handler:
push rsi
push rdi
push rbx
push rbp
push r12
push r13
push r14
push r15
pushfq
sub rsp,64
mov rax,QWORD[120+r8]
mov rbx,QWORD[248+r8]
mov rsi,QWORD[8+r9]
mov r11,QWORD[56+r9]
lea r10,[$L$ctr32_body]
cmp rbx,r10
jb NEAR $L$common_seh_tail
mov rax,QWORD[152+r8]
lea r10,[$L$no_data]
cmp rbx,r10
jae NEAR $L$common_seh_tail
lea rax,[((64+24+48))+rax]
mov rbx,QWORD[((-8))+rax]
mov rbp,QWORD[((-16))+rax]
mov r12,QWORD[((-24))+rax]
mov r13,QWORD[((-32))+rax]
mov r14,QWORD[((-40))+rax]
mov r15,QWORD[((-48))+rax]
mov QWORD[144+r8],rbx
mov QWORD[160+r8],rbp
mov QWORD[216+r8],r12
mov QWORD[224+r8],r13
mov QWORD[232+r8],r14
mov QWORD[240+r8],r15
$L$common_seh_tail:
mov rdi,QWORD[8+rax]
mov rsi,QWORD[16+rax]
mov QWORD[152+r8],rax
mov QWORD[168+r8],rsi
mov QWORD[176+r8],rdi
mov rdi,QWORD[40+r9]
mov rsi,r8
mov ecx,154
DD 0xa548f3fc
mov rsi,r9
xor rcx,rcx
mov rdx,QWORD[8+rsi]
mov r8,QWORD[rsi]
mov r9,QWORD[16+rsi]
mov r10,QWORD[40+rsi]
lea r11,[56+rsi]
lea r12,[24+rsi]
mov QWORD[32+rsp],r10
mov QWORD[40+rsp],r11
mov QWORD[48+rsp],r12
mov QWORD[56+rsp],rcx
call QWORD[__imp_RtlVirtualUnwind]
mov eax,1
add rsp,64
popfq
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
pop rdi
pop rsi
DB 0F3h,0C3h ;repret
ALIGN 16
simd_handler:
push rsi
push rdi
push rbx
push rbp
push r12
push r13
push r14
push r15
pushfq
sub rsp,64
mov rax,QWORD[120+r8]
mov rbx,QWORD[248+r8]
mov rsi,QWORD[8+r9]
mov r11,QWORD[56+r9]
mov r10d,DWORD[r11]
lea r10,[r10*1+rsi]
cmp rbx,r10
jb NEAR $L$common_seh_tail
mov rax,QWORD[192+r8]
mov r10d,DWORD[4+r11]
mov ecx,DWORD[8+r11]
lea r10,[r10*1+rsi]
cmp rbx,r10
jae NEAR $L$common_seh_tail
neg rcx
lea rsi,[((-8))+rcx*1+rax]
lea rdi,[512+r8]
neg ecx
shr ecx,3
DD 0xa548f3fc
jmp NEAR $L$common_seh_tail
section .pdata rdata align=4
ALIGN 4
DD $L$SEH_begin_ChaCha20_ctr32 wrt ..imagebase
DD $L$SEH_end_ChaCha20_ctr32 wrt ..imagebase
DD $L$SEH_info_ChaCha20_ctr32 wrt ..imagebase
DD $L$SEH_begin_ChaCha20_ssse3 wrt ..imagebase
DD $L$SEH_end_ChaCha20_ssse3 wrt ..imagebase
DD $L$SEH_info_ChaCha20_ssse3 wrt ..imagebase
DD $L$SEH_begin_ChaCha20_128 wrt ..imagebase
DD $L$SEH_end_ChaCha20_128 wrt ..imagebase
DD $L$SEH_info_ChaCha20_128 wrt ..imagebase
DD $L$SEH_begin_ChaCha20_4x wrt ..imagebase
DD $L$SEH_end_ChaCha20_4x wrt ..imagebase
DD $L$SEH_info_ChaCha20_4x wrt ..imagebase
DD $L$SEH_begin_ChaCha20_4xop wrt ..imagebase
DD $L$SEH_end_ChaCha20_4xop wrt ..imagebase
DD $L$SEH_info_ChaCha20_4xop wrt ..imagebase
DD $L$SEH_begin_ChaCha20_8x wrt ..imagebase
DD $L$SEH_end_ChaCha20_8x wrt ..imagebase
DD $L$SEH_info_ChaCha20_8x wrt ..imagebase
DD $L$SEH_begin_ChaCha20_avx512 wrt ..imagebase
DD $L$SEH_end_ChaCha20_avx512 wrt ..imagebase
DD $L$SEH_info_ChaCha20_avx512 wrt ..imagebase
DD $L$SEH_begin_ChaCha20_avx512vl wrt ..imagebase
DD $L$SEH_end_ChaCha20_avx512vl wrt ..imagebase
DD $L$SEH_info_ChaCha20_avx512vl wrt ..imagebase
DD $L$SEH_begin_ChaCha20_16x wrt ..imagebase
DD $L$SEH_end_ChaCha20_16x wrt ..imagebase
DD $L$SEH_info_ChaCha20_16x wrt ..imagebase
DD $L$SEH_begin_ChaCha20_8xvl wrt ..imagebase
DD $L$SEH_end_ChaCha20_8xvl wrt ..imagebase
DD $L$SEH_info_ChaCha20_8xvl wrt ..imagebase
section .xdata rdata align=8
ALIGN 8
$L$SEH_info_ChaCha20_ctr32:
DB 9,0,0,0
DD se_handler wrt ..imagebase
$L$SEH_info_ChaCha20_ssse3:
DB 9,0,0,0
DD simd_handler wrt ..imagebase
DD $L$ssse3_body wrt ..imagebase,$L$ssse3_epilogue wrt ..imagebase
DD 0x20,0
$L$SEH_info_ChaCha20_128:
DB 9,0,0,0
DD simd_handler wrt ..imagebase
DD $L$128_body wrt ..imagebase,$L$128_epilogue wrt ..imagebase
DD 0x60,0
$L$SEH_info_ChaCha20_4x:
DB 9,0,0,0
DD simd_handler wrt ..imagebase
DD $L$4x_body wrt ..imagebase,$L$4x_epilogue wrt ..imagebase
DD 0xa0,0
$L$SEH_info_ChaCha20_4xop:
DB 9,0,0,0
DD simd_handler wrt ..imagebase
DD $L$4xop_body wrt ..imagebase,$L$4xop_epilogue wrt ..imagebase
DD 0xa0,0
$L$SEH_info_ChaCha20_8x:
DB 9,0,0,0
DD simd_handler wrt ..imagebase
DD $L$8x_body wrt ..imagebase,$L$8x_epilogue wrt ..imagebase
DD 0xa0,0
$L$SEH_info_ChaCha20_avx512:
DB 9,0,0,0
DD simd_handler wrt ..imagebase
DD $L$avx512_body wrt ..imagebase,$L$avx512_epilogue wrt ..imagebase
DD 0x20,0
$L$SEH_info_ChaCha20_avx512vl:
DB 9,0,0,0
DD simd_handler wrt ..imagebase
DD $L$avx512vl_body wrt ..imagebase,$L$avx512vl_epilogue wrt ..imagebase
DD 0x20,0
$L$SEH_info_ChaCha20_16x:
DB 9,0,0,0
DD simd_handler wrt ..imagebase
DD $L$16x_body wrt ..imagebase,$L$16x_epilogue wrt ..imagebase
DD 0xa0,0
$L$SEH_info_ChaCha20_8xvl:
DB 9,0,0,0
DD simd_handler wrt ..imagebase
DD $L$8xvl_body wrt ..imagebase,$L$8xvl_epilogue wrt ..imagebase
DD 0xa0,0
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r13
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_normal_ht+0x9054, %rsi
lea addresses_A_ht+0xa334, %rdi
clflush (%rsi)
nop
nop
nop
dec %r11
mov $14, %rcx
rep movsq
nop
nop
nop
nop
add $35589, %r13
lea addresses_UC_ht+0xd5d4, %r13
nop
nop
nop
cmp $139, %r12
vmovups (%r13), %ymm3
vextracti128 $1, %ymm3, %xmm3
vpextrq $1, %xmm3, %rdi
nop
nop
nop
nop
inc %rdi
lea addresses_D_ht+0x18941, %r11
nop
nop
nop
nop
nop
and $6132, %r9
mov $0x6162636465666768, %rcx
movq %rcx, %xmm1
and $0xffffffffffffffc0, %r11
movaps %xmm1, (%r11)
xor $16873, %rcx
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r13
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r13
push %r9
push %rbx
push %rcx
push %rdi
push %rsi
// REPMOV
mov $0xc38, %rsi
lea addresses_RW+0xbbd4, %rdi
clflush (%rdi)
nop
nop
nop
nop
cmp %r9, %r9
mov $17, %rcx
rep movsq
nop
nop
sub %r10, %r10
// Store
lea addresses_WC+0x4c70, %rsi
nop
nop
cmp %rbx, %rbx
mov $0x5152535455565758, %r13
movq %r13, (%rsi)
nop
nop
nop
dec %rdi
// Store
lea addresses_D+0x17196, %r10
nop
nop
nop
nop
add $21298, %rdi
mov $0x5152535455565758, %rsi
movq %rsi, (%r10)
nop
nop
nop
xor $53875, %r13
// Faulty Load
lea addresses_RW+0x13dd4, %rbx
nop
nop
nop
xor %r9, %r9
mov (%rbx), %r10d
lea oracles, %rbx
and $0xff, %r10
shlq $12, %r10
mov (%rbx,%r10,1), %r10
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r9
pop %r13
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_P', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_RW', 'congruent': 8, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 16, 'AVXalign': True, 'NT': False, 'congruent': 0, 'same': False}}
{'32': 20}
32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
*/
|
bits 64
start:
invlpga eax, ecx
invlpga rax, ecx
jecxz start
jrcxz start
loop start, ecx
loop start, rcx
loope start, ecx
loope start, rcx
loopz start, ecx
loopz start, rcx
loopne start, ecx
loopne start, rcx
loopnz start, ecx
loopnz start, rcx
clzero eax
clzero rax
movdir64b eax, [edi]
movdir64b rax, [rdi]
umonitor eax
umonitor rax
|
/* 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/core/grappler/costs/virtual_scheduler.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_replace.h"
#include "tensorflow/core/framework/allocation_description.pb.h"
#include "tensorflow/core/framework/attr_value.pb.h"
#include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/tensor.pb.h"
#include "tensorflow/core/framework/tensor_description.pb.h"
#include "tensorflow/core/framework/tensor_shape.pb.h"
#include "tensorflow/core/grappler/clusters/utils.h"
#include "tensorflow/core/grappler/costs/utils.h"
#include "tensorflow/core/grappler/op_types.h"
#include "tensorflow/core/grappler/utils.h"
#include "tensorflow/core/grappler/utils/transitive_fanin.h"
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/strings/numbers.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/util/device_name_utils.h"
namespace tensorflow {
namespace grappler {
namespace {
using ::tensorflow::strings::HumanReadableNumBytes;
constexpr char kAttrInputSrc[] = "input_source_";
constexpr char kAttrSrcDevice[] = "send_device";
constexpr char kAttrDstDevice[] = "recv_device";
constexpr char kAttrTensorName[] = "tensor_name";
constexpr char kChannelDevice[] = "Channel";
float Round2(const float x) {
// Not using std::round from <cmath> here because not all platforms seem to
// support that (specifically Android).
return ::round(100.0 * x) / 100.0;
}
Costs& FindOrCreateZero(const string& op_name,
std::map<string, Costs>* op_cost) {
auto it = op_cost->find(op_name);
if (it == op_cost->end()) {
// Note that default constructor of Costs sets some memory related fields
// to unknown values so we should explicitly initialize it with ZeroCosts.
it = op_cost->emplace(op_name, Costs::ZeroCosts()).first;
}
return it->second;
}
// Key to the cached _Recv ops map, and its hash and predicate structures.
struct RecvNodeDescriptor {
const NodeDef* node;
const int port_num;
const string device;
RecvNodeDescriptor(const NodeDef* node_, const int port_num_,
const string& device_)
: node(node_), port_num(port_num_), device(device_) {}
};
struct RecvNodeDescriptorHash {
std::size_t operator()(const RecvNodeDescriptor& recv_node) const {
return std::hash<const NodeDef*>()(recv_node.node) ^
std::hash<int>()(recv_node.port_num) ^
std::hash<string>()(recv_node.device);
}
};
struct RecvNodeDescriptorEqual {
bool operator()(const RecvNodeDescriptor& a,
const RecvNodeDescriptor& b) const {
return a.node == b.node && a.port_num == b.port_num && a.device == b.device;
}
};
void UpdateDeviceAnnotationState(const NodeDef* node,
const NodeState& node_state,
DeviceState* device) {
if (node->attr().count(kOutputShapes) == 0) return;
int64 execution_count = node->attr().count(kExecutionCount) == 0
? 1
: node->attr().at(kExecutionCount).i();
auto& shape_annotation_stats = device->shape_annotation_stats;
shape_annotation_stats.num_ops_annotated += 1;
shape_annotation_stats.num_ops_executed += execution_count;
shape_annotation_stats.num_ops_executed_more_than_once +=
execution_count > 1 ? 1 : 0;
shape_annotation_stats.num_ops_with_incompatible_shapes +=
node_state.shape_incompatible ? 1 : 0;
shape_annotation_stats.num_ops_with_dynamic_shapes +=
(execution_count > 1 && node->attr().count(kOutputSame) == 0) ? 1 : 0;
}
} // namespace
const NodeDef* LIFOManager::GetCurrNode() {
CHECK(!nodes_.empty()) << "GetCurrNode(), but there's no ready node";
if (curr_pos_ == nodes_.end()) {
curr_pos_ = --(nodes_.rbegin().base()); // Last one in the list.
}
// Once curr_pos_ is set to a valid entry in the list, we keep using the
// cached curr_pos_ until RemoveCurrNode() is called. AddNode() will not
// change the GetCurrNode() return value.
return *curr_pos_;
}
void LIFOManager::RemoveCurrNode() {
// Make sure we have curr_pos_ ready to be removed.
GetCurrNode();
// Note curr_pos_ may not be pointing the last element if some nodes are
// added.
nodes_.erase(curr_pos_);
curr_pos_ = nodes_.end(); // Reset curr_pos_.
}
HeapReadyManager::HeapReadyManager() : ReadyNodeManager() {
std::make_heap(nodes_.begin(), nodes_.end());
}
Status HeapReadyManager::Init(
const std::unordered_map<const NodeDef*, NodeState>* node_map) {
// Resets the node state since different instances of the scheduler can reuse
// the same node_manager.
node_map_ = node_map;
nodes_.clear();
waiting_queue_.clear();
// Sets up the comparator for the heap.
greater_ = Greater();
return Status::OK();
}
const NodeDef* HeapReadyManager::GetCurrNode() {
if (nodes_.empty()) {
// Nothing in the node_; probably, the very first call. Move waiting_queue_
// to node_.
DrainWaitingQueue();
CHECK(!nodes_.empty()) << "GetCurrNode(), but there's no ready node";
}
return nodes_.front();
}
void HeapReadyManager::RemoveCurrNode() {
if (nodes_.empty()) {
// Make sure that there is a node to be removed at the front of nodes_.
GetCurrNode();
}
std::pop_heap(nodes_.begin(), nodes_.end(), greater_);
nodes_.pop_back();
DrainWaitingQueue();
}
bool HeapReadyManager::Empty() const {
return nodes_.empty() && waiting_queue_.empty();
}
void HeapReadyManager::DrainWaitingQueue() {
for (const auto* node : waiting_queue_) {
// push_heap in AddNode() and pop_heap in RemoveCurrNode() guarantees that
// the first element is the node with minimum time_ready.
nodes_.push_back(node);
std::push_heap(nodes_.begin(), nodes_.end(), greater_);
}
waiting_queue_.clear();
}
bool FirstReadyCmp(
const std::unordered_map<const NodeDef*, NodeState>* node_map,
const NodeDef* a, const NodeDef* b) {
if (node_map->at(a).time_ready == node_map->at(b).time_ready) {
// Use Node name as tie-breaker for deterministic node scheduling.
return a->name().compare(b->name()) > 0;
} else {
// Note: we need a node with minimum time_ready, not maximum; hence, using
// a > b for comparison function.
return node_map->at(a).time_ready > node_map->at(b).time_ready;
}
}
std::function<bool(const NodeDef*, const NodeDef*)>
FirstReadyManager::Greater() {
auto greater = [this](const NodeDef* a, const NodeDef* b) -> bool {
return FirstReadyCmp(node_map_, a, b);
};
return greater;
}
std::function<bool(const NodeDef*, const NodeDef*)>
PriorityReadyManager::Greater() {
auto greater = [this](const NodeDef* a, const NodeDef* b) -> bool {
auto pri_a = node_priority_.at(a->name());
auto pri_b = node_priority_.at(b->name());
if (pri_a == pri_b) {
// Fallback to default (FirstReady) behaviour.
return FirstReadyCmp(node_map_, a, b);
}
return pri_a > pri_b;
};
return greater;
}
void PriorityReadyManager::AddNode(const NodeDef* node) {
if (node_priority_.count(node->name()) == 0) {
VLOG(3) << "Priority of node " << node->name() << " not found.";
node_priority_[node->name()] = 0;
}
HeapReadyManager::AddNode(node);
}
Status PriorityReadyManager::SetPriority(
const std::unordered_map<string, int>& node_priority) {
node_priority_ = node_priority;
return Status::OK();
}
CompositeNodeManager::CompositeNodeManager()
: ReadyNodeManager(), send_manager_(), recv_manager_() {}
Status CompositeNodeManager::Init(
const std::unordered_map<const NodeDef*, NodeState>* node_map) {
node_map_ = node_map;
TF_RETURN_IF_ERROR(send_manager_.Init(node_map));
TF_RETURN_IF_ERROR(recv_manager_.Init(node_map));
curr_node_ = nullptr;
return Status::OK();
}
void CompositeNodeManager::AddNode(const NodeDef* node) {
if (IsSend(*node)) {
send_manager_.AddNode(node);
} else if (IsRecv(*node)) {
recv_manager_.AddNode(node);
} else {
const auto& device = node_map_->at(node).device_name;
ops_lifo_map_[device].AddNode(node);
}
}
const NodeDef* CompositeNodeManager::GetCurrNode() {
if (curr_node_) return curr_node_;
// Per-device LIFO for normal ops (not _Send / _Recv),
// FirstReady for _Send and _Recv (separately),
// Globally (among the LIFO-selected ops from each device and _Send and
// _Recv) FirstReady,
// Priority order: _Send, _Recv, and then the rest, if time_ready is equal.
std::vector<std::pair<const NodeDef*, Costs::Duration>> candidates;
for (auto& ops_lifo : ops_lifo_map_) {
if (!ops_lifo.second.Empty()) {
const auto* op = ops_lifo.second.GetCurrNode();
candidates.emplace_back(op, node_map_->at(op).time_ready);
}
}
if (!send_manager_.Empty()) {
const auto* send = send_manager_.GetCurrNode();
candidates.emplace_back(send, node_map_->at(send).time_ready);
}
if (!recv_manager_.Empty()) {
const auto* recv = recv_manager_.GetCurrNode();
candidates.emplace_back(recv, node_map_->at(recv).time_ready);
}
CHECK(!candidates.empty());
auto first_ready = std::min_element(
candidates.begin(), candidates.end(),
[](const std::pair<const NodeDef*, Costs::Duration>& a,
const std::pair<const NodeDef*, Costs::Duration>& b) {
if (a.second == b.second) {
// Note that there can be only 1 Send and only 1 Recv in candidates,
// at most; hence, score is 2 for Send, 1 for Recv, and 0 for a
// normap op, and a_score and b_score are equal only if both are
// normal ops.
int a_score = 2 * IsSend(*a.first) + IsRecv(*a.first);
int b_score = 2 * IsSend(*b.first) + IsRecv(*b.first);
if (a_score == b_score) {
// Both are normal ops; use node name as tie breaker.
return a.first->name().compare(b.first->name()) < 0;
} else {
// Prioritize by op type: _Send, _Recv, and normap ops.
return a_score > b_score;
}
} else {
return a.second < b.second;
}
});
// Next time we call GetCurrNode(), it just returns the cached one,
// curr_node_ until we call RemovCurrNode().
curr_node_ = first_ready->first;
return curr_node_;
}
void CompositeNodeManager::RemoveCurrNode() {
const auto* node = GetCurrNode();
if (IsSend(*node)) {
send_manager_.RemoveCurrNode();
} else if (IsRecv(*node)) {
recv_manager_.RemoveCurrNode();
} else {
const auto device = node_map_->at(node).device_name;
ops_lifo_map_[device].RemoveCurrNode();
}
// Reset curr_node_ so that GetCurrNode() finds another node.
curr_node_ = nullptr;
}
bool CompositeNodeManager::Empty() const {
// Empty if all the ready managers are empty.
bool empty = true;
for (const auto& ops_lifo : ops_lifo_map_) {
empty &= ops_lifo.second.Empty();
}
return empty && send_manager_.Empty() && recv_manager_.Empty();
}
std::unique_ptr<ReadyNodeManager> ReadyNodeManagerFactory(
const string& ready_node_manager) {
if (ready_node_manager == "FIFO") {
return absl::make_unique<FIFOManager>();
} else if (ready_node_manager == "LIFO") {
return absl::make_unique<LIFOManager>();
} else if (ready_node_manager == "FirstReady") {
return absl::make_unique<FirstReadyManager>();
} else if (ready_node_manager == "Composite") {
return absl::make_unique<CompositeNodeManager>();
}
LOG(FATAL) << "Not a valid ready node manager: " << ready_node_manager;
return nullptr;
}
VirtualScheduler::VirtualScheduler(const bool use_static_shapes,
const bool use_aggressive_shape_inference,
Cluster* cluster,
ReadyNodeManager* ready_nodes,
std::unique_ptr<VirtualPlacer> placer)
: ready_nodes_(ready_nodes),
graph_costs_(Costs::ZeroCosts()),
cluster_(cluster),
use_static_shapes_(use_static_shapes),
use_aggressive_shape_inference_(use_aggressive_shape_inference),
placer_(std::move(placer)) {
DCHECK(placer_); // check if the pointer is valid.
graph_costs_.num_ops_total = 0;
initialized_ = false;
track_mem_usage_snapshot_ = VLOG_IS_ON(1);
}
Status VirtualScheduler::Init(const GrapplerItem* item) {
initialized_ = false;
// Clear all internal states so that the VirtualScheduler is reusable for
// different GrapplerItems
node_map_.clear();
device_.clear();
additional_nodes_.clear();
graph_costs_ = Costs::ZeroCosts();
graph_costs_.num_ops_total = 0;
op_to_cost_.clear();
op_counts_.clear();
op_costs_.clear();
// Init() preprocesses the input grappler_item and graph_properties to extract
// necessary information for emulating tensorflow op scheduling and
// construct internal data structures (NodeState and DeviceState) for virtual
// scheduling.
TF_RETURN_IF_ERROR(ready_nodes_->Init(GetNodeStates()));
// Constructs graph properties and performs shape inference.
graph_properties_ = absl::make_unique<GraphProperties>(*item);
if (use_static_shapes_) {
TF_RETURN_IF_ERROR(graph_properties_->InferStatically(
true, use_aggressive_shape_inference_, true));
} else {
TF_RETURN_IF_ERROR(graph_properties_->InferDynamically(cluster_));
}
grappler_item_ = item;
const auto& graph = grappler_item_->graph;
const auto& fetch_nodes = grappler_item_->fetch;
std::set<string> feed_nodes;
for (const auto& f : grappler_item_->feed) {
auto iter_and_inserted_flag = feed_nodes.insert(f.first);
QCHECK(iter_and_inserted_flag.second)
<< "Duplicate feed node found: " << f.first;
}
// Get the nodes that would run to output fetch_nodes.
std::unordered_map<string, const NodeDef*> name_to_node;
std::vector<const NodeDef*> fetch_fanin_nodes;
TF_RETURN_IF_ERROR(ComputeTransitiveFanin(graph, fetch_nodes, &name_to_node,
&fetch_fanin_nodes));
// Once ComputeTransitiveFanin is complete, only the nodes that can be reached
// from the fetch nodes are scheduled. So the scheduled nodes should be
// exactly the same as those executed for real. One possible discrepancy could
// be the control flow nodes, where tf only executes one path.
// Traverses the graph to record _Send nodes.
// TODO(dyoon): Instead of identifying _Send node here manually, add _Send
// to _Recv as control dependency when creating GrapplerItem.
std::unordered_map<string, const NodeDef*> name_to_send;
for (const auto& node : graph.node()) {
if (IsSend(node)) {
const auto& attr = node.attr();
name_to_send[attr.at("tensor_name").s()] = &node;
}
}
// To reuse _Recv ops.
std::unordered_map<RecvNodeDescriptor, const NodeDef*, RecvNodeDescriptorHash,
RecvNodeDescriptorEqual>
cached_recv_nodes;
// Build node_map; for each node, create its NodeState and connect its inputs
// and outputs.
for (const auto* curr_node : fetch_fanin_nodes) {
auto& curr_node_state = GetNodeStateOrCreateIt(curr_node);
const string curr_node_device = DeviceName(curr_node);
std::vector<string> inputs;
if (IsRecv(*curr_node)) {
const auto& attr = curr_node->attr();
if (attr.count("tensor_name")) {
const auto& send_node_name = attr.at("tensor_name").s();
auto it = name_to_send.find(send_node_name);
// If there is a _Send associated with the curr_node (_Recv), add it as
// input.
if (it != name_to_send.end()) {
const NodeDef* send = it->second;
inputs = {send->name()};
}
}
} else {
for (const string& input : curr_node->input()) {
inputs.push_back(input);
}
}
for (const string& input_node_name : inputs) {
// Note that input_node_name may be in <prefix><node_name>:<port_num>
// format, where <prefix> (e.g., "^" for control dependency) and
// ":<port_num>" may be omitted. NodeName() extracts only the node_name.
const NodeDef* input_node = name_to_node[NodeName(input_node_name)];
CHECK(input_node);
const string in_device = DeviceName(input_node);
const auto input_node_port_num = NodePosition(input_node_name);
if (curr_node_device == in_device) {
// Same device: connect input_node and curr_node directly.
curr_node_state.inputs.push_back(
std::make_pair(input_node, input_node_port_num));
auto& input_node_state = GetNodeStateOrCreateIt(input_node);
input_node_state.outputs[input_node_port_num].push_back(curr_node);
} else {
RecvNodeDescriptor recv_node(input_node, input_node_port_num,
curr_node_device);
auto it = cached_recv_nodes.find(recv_node);
if (it != cached_recv_nodes.end()) {
// Different device, but found an already-cached copy (a _Recv op);
// connect the _Recv to curr_node.
const NodeDef* recv_op = it->second;
// recv_op's output port is hard-coded to zero.
curr_node_state.inputs.push_back(std::make_pair(recv_op, 0));
auto& input_node_state = node_map_.at(recv_op);
input_node_state.outputs[0].push_back(curr_node);
} else {
// Different device, no cached copy; transfer input_node to the
// curr_node's device.
auto send_and_recv = CreateSendRecv(input_node, curr_node, input_node,
input_node_name);
// Note that CreateSendRecv() already connected input/output between
// _Send and _Recv ops.
const auto* send = send_and_recv.first;
const auto* recv = send_and_recv.second;
// recv_op's output port is hard-coded to zero.
curr_node_state.inputs.push_back(std::make_pair(recv, 0));
auto& input_node_state = GetNodeStateOrCreateIt(input_node);
input_node_state.outputs[input_node_port_num].push_back(send);
// Cache the _Recv op for future use.
cached_recv_nodes[recv_node] = recv;
}
}
}
// Special case: given feed nodes are ready at time 0.
const bool given_as_feed =
feed_nodes.find(curr_node->name()) != feed_nodes.end();
// Default case: node without inputs are ready at time 0.
// Note that we check inputs vector which may be different to
// curr_node->input(); e.g., we add Send as input to Recv.
const bool has_no_inputs = inputs.empty();
if (given_as_feed || has_no_inputs) {
curr_node_state.time_ready = Costs::Duration();
ready_nodes_->AddNode(curr_node);
VLOG(3) << "Added ready node: " << curr_node->name();
}
feed_nodes.erase(curr_node->name());
if (IsPersistent(*curr_node)) {
auto& device_state = device_[curr_node_device];
for (int port_num = 0;
port_num < curr_node_state.output_properties.size(); ++port_num) {
device_state.persistent_nodes.insert(
std::make_pair(curr_node, port_num));
}
}
}
if (ready_nodes_->Empty()) {
return errors::InvalidArgument("No ready nodes in the graph.");
}
if (!feed_nodes.empty()) {
// This isn't always a bug: when the caller hasn't specified the exact list
// of feed and fetch nodes, by default we consider all placeholders as feed
// nodes, but some of them may not be needed for the default fetch node.
VLOG(1) << "Some feed nodes were not consumed by the fetch fanin: "
<< absl::StrJoin(feed_nodes, ",");
}
initialized_ = true;
return Status::OK();
}
void VirtualScheduler::MaybeUpdateInputOutput(const NodeDef* node) {
CHECK(!initialized_) << "MaybeUpdateInputOutput is called after Init().";
// This method is called when NodeState is created and adds input and output
// properties for a few exceptional cases that GraphProperties cannot provide
// input/output properties.
if ((IsSend(*node) || IsRecv(*node)) && node->attr().count(kAttrInputSrc)) {
// _Send and _Recv ops created from VirtualScheduler have kAttrInputSrc
// attr; normal _Send and _Recv ops (from the input graph) do not have that
// attr.
auto& node_state = node_map_[node];
auto& inputs = node_state.input_properties;
auto& outputs = node_state.output_properties;
// _Send and _Recv ops are created from VirtualScheduler, so
// there should be no inputs TensorProperties.
CHECK(inputs.empty());
CHECK(outputs.empty());
const auto& attr = node->attr();
// This is the original input source to the _Send and _Recv, and this
// string includes "^" if it was control dependency, and output port
/// (e.g., ":2") if the input source had multiple outputs.
const auto& input_source_name = attr.at(kAttrInputSrc).s();
if (IsControlInput(input_source_name)) {
// Control dependency; regardless of the input source tensor size,
// send 4B.
OpInfo::TensorProperties control_message;
control_message.set_dtype(DT_FLOAT);
control_message.mutable_shape()->add_dim()->set_size(1);
auto* value = control_message.mutable_value();
value->add_float_val(1);
inputs.push_back(control_message);
outputs.push_back(control_message);
} else {
const auto& output_properties =
graph_properties_->GetOutputProperties(NodeName(input_source_name));
// Like with HasInputProperties, if a node does not have output
// properties, it's likely it was pruned during the shape inference run.
if (!output_properties.empty()) {
const auto input_node_port_num = NodePosition(input_source_name);
// Use the input source's output property as _Send and _Recv's input
// property.
CHECK_GT(output_properties.size(), input_node_port_num);
inputs.push_back(output_properties[input_node_port_num]);
outputs.push_back(output_properties[input_node_port_num]);
}
}
}
}
string VirtualScheduler::DeviceName(const NodeDef* node) const {
return placer_->get_canonical_device_name(*node);
}
string VirtualScheduler::SanitizedDeviceName(const NodeDef* node) const {
// Replace the ":" characters that may be present in the device name with "_".
// This makes it possible to then use the resulting string in a node name.
return absl::StrReplaceAll(placer_->get_canonical_device_name(*node),
{{":", "_"}});
}
string VirtualScheduler::ChannelDeviceName(const NodeDef* from,
const NodeDef* to) const {
CHECK(!initialized_) << "ChannelDeviceName is called after Init().";
return absl::StrCat(kChannelDevice, "_from_", SanitizedDeviceName(from),
"_to_", SanitizedDeviceName(to));
}
std::pair<const NodeDef*, const NodeDef*> VirtualScheduler::CreateSendRecv(
const NodeDef* from, const NodeDef* to, const NodeDef* input_node,
const string& input_name) {
CHECK(!initialized_) << "CreateSendRecv is called after Init().";
// Connect "from" node to "to" node with _Send and _Recv such that
// from -> _Send -> _Recv -> to.
// _Send is placed on "Channel" device, and _Recv is on the same device
// as "to" node.
// input_node_name is the string from the "to" node to identify which output
// we get from the "from" node.
// Note that we use NodeState for scheduling, so _Send and _Recv
// NodeDefs created here need not be correct: in terms of name,
// input names, attrs, etc.
auto input_node_port_num = NodePosition(input_name);
string src_name;
if (input_node_port_num >= 0) {
src_name = absl::StrCat(from->name(), "_", input_node_port_num);
} else {
src_name = absl::StrCat(from->name(), "_minus1");
}
// _Send op.
auto* send = new NodeDef();
send->set_name("Send_" + src_name + "_from_" + SanitizedDeviceName(from) +
"_to_" + SanitizedDeviceName(to));
send->set_op("_Send");
send->add_input(from->name());
send->set_device(ChannelDeviceName(from, to));
auto& send_attr = *(send->mutable_attr());
send_attr[kAttrInputSrc].set_s(input_name);
send_attr[kAttrSrcDevice].set_s(DeviceName(from));
send_attr[kAttrDstDevice].set_s(DeviceName(to));
// GraphDef generated by AutoGrappler has tensor_name field when removing
// _Send/_Recv nodes.
if (input_node->attr().count(kAttrTensorName)) {
send_attr[kAttrTensorName].set_s(
input_node->attr().at(kAttrTensorName).s());
}
// _Recv op.
auto* recv = new NodeDef();
recv->set_name("Recv_" + src_name + "_on_" + SanitizedDeviceName(to));
recv->set_op("_Recv");
recv->add_input(send->name());
recv->set_device(DeviceName(to));
auto& recv_attr = *(recv->mutable_attr());
recv_attr[kAttrInputSrc].set_s(input_name);
if (input_node->attr().count(kAttrTensorName)) {
recv_attr[kAttrTensorName].set_s(
input_node->attr().at(kAttrTensorName).s());
}
// NodeState for _Send op.
auto& send_node_state = GetNodeStateOrCreateIt(send);
send_node_state.device_name = send->device(); // Set Channel device.
send_node_state.inputs.push_back(std::make_pair(from, input_node_port_num));
send_node_state.outputs[0].push_back(recv);
// NodeState for _Recv op.
auto& recv_node_state = GetNodeStateOrCreateIt(recv);
recv_node_state.inputs.push_back(std::make_pair(send, 0));
recv_node_state.outputs[0].push_back(to);
// Keep the created nodes.
additional_nodes_.emplace_back(std::unique_ptr<NodeDef>(send));
additional_nodes_.emplace_back(std::unique_ptr<NodeDef>(recv));
// Return _Send and _Recv.
return std::make_pair(send, recv);
}
OpContext VirtualScheduler::GetCurrNode() const {
const NodeDef* node = ready_nodes_->GetCurrNode();
// Get the device from the placer.
DeviceProperties device;
device = placer_->get_device(*node);
// Special case for _Send op.
if (IsSend(*node)) {
device.set_type(kChannelDevice);
}
// Construct OpContext.
OpContext op_context;
const auto& node_state = node_map_.at(node);
op_context.name = node->name();
op_context.device_name = node_state.device_name;
auto& op_info = op_context.op_info;
op_info.set_op(node->op());
*op_info.mutable_attr() = node->attr();
for (auto& input : node_state.input_properties) {
*op_info.add_inputs() = input;
}
for (auto& output : node_state.output_properties) {
*op_info.add_outputs() = output;
}
op_info.mutable_device()->Swap(&device);
if (grappler_item_->graph.has_library()) {
op_context.function_library = &grappler_item_->graph.library();
}
return op_context;
}
NodeState& VirtualScheduler::GetNodeStateOrCreateIt(const NodeDef* node) {
CHECK(!initialized_) << "GetNodeStateOrCreateIt is called after Init().";
auto it = node_map_.find(node);
if (it != node_map_.end()) {
return it->second;
}
// Not found; create a NodeState for this node.
it = node_map_.emplace(node, NodeState()).first;
auto& node_state = it->second;
node_state.input_properties =
graph_properties_->GetInputProperties(node->name());
node_state.output_properties =
graph_properties_->GetOutputProperties(node->name());
node_state.shape_incompatible =
graph_properties_->CheckShapeIncompatible(node->name());
// Some ops may need further processing to the input / output properties:
// _Send and _Recv.
MaybeUpdateInputOutput(node);
if (!IsSend(*node)) {
node_state.device_name = DeviceName(node);
// For _Send op, device_name will be set to Channel in CreateSendRecv().
}
// Initialize output port related data:
// Assume the size of OutputProperties represents the number of output ports
// of this node.
for (size_t i = 0; i < node_state.output_properties.size(); ++i) {
node_state.time_no_references[i] = Costs::Duration::max();
node_state.num_outputs_executed[i] = 0;
// Populate an empty vector for each port. The caller will add nodes
// that use this port as input.
node_state.outputs[i] = {};
}
// Port_num -1 is for control dependency.
node_state.time_no_references[-1] = Costs::Duration::max();
node_state.num_outputs_executed[-1] = 0;
node_state.outputs[-1] = {};
return it->second;
}
void VirtualScheduler::AddOutputNodesToReadyQueue(
const NodeDef* node, const Costs::Duration& curr_time) {
// Checks whether the Switch's output slots change over iterations.
int slot = -1;
if (IsSwitch(*node) && node->attr().count(kOutputSlots) > 0 &&
node->attr().at(kOutputSlots).list().i_size() > 0) {
slot = node->attr().at(kOutputSlots).list().i(0);
for (int i = 1; i < node->attr().at(kOutputSlots).list().i_size(); ++i) {
if (slot != node->attr().at(kOutputSlots).list().i(i)) {
slot = -1;
break;
}
}
}
// Increment num_inputs_ready of the output nodes and maybe add to ready
// nodes.
auto& node_state = node_map_[node];
for (const auto& port_num_output_pair : node_state.outputs) {
// If Switch is annotated and its output slots are always the same, we only
// schedule the slot that was executed. Otherwise, scheduler both slots.
if (slot >= 0 && port_num_output_pair.first != slot) continue;
for (auto* output_node : port_num_output_pair.second) {
auto& output_state = node_map_[output_node];
output_state.num_inputs_ready++;
// Execute a node as soon as all its inputs are ready. Merge nodes are
// special since they run as soon as one of their inputs becomes
// available.
if (output_state.num_inputs_ready == output_state.inputs.size() ||
IsMerge(*output_node)) {
// This output node is now ready.
output_state.time_ready = curr_time;
ready_nodes_->AddNode(output_node);
VLOG(3) << " Add output: " << output_node->name();
}
}
}
}
bool VirtualScheduler::MarkCurrNodeExecuted(const Costs& node_costs) {
// Update graph_costs_ and per-op costs.
const NodeDef* node = ready_nodes_->GetCurrNode();
auto& node_state = node_map_[node];
// TODO(dyoon, andiryxu): Consider to revisit node execution w.r.t. Switch and
// Merge -- it can create a loop which may include loop-carried dependency,
// diverge-merge, and other complex execution patterns.
bool previously_executed_merge =
IsMerge(*node) && (node_state.time_finished != Costs::Duration::max());
// If there is annotation in the graph about execution times, we use that
// number, otherwise, we assume the node is executed once.
node_state.execution_count = node->attr().count(kExecutionCount) == 0
? 1
: node->attr().at(kExecutionCount).i();
node_state.node_costs = node_costs;
// TotalNodeCosts() Should be called after node_costs and execution_count.
Costs total_node_costs = node_state.TotalNodeCosts();
graph_costs_ = CombineCosts(graph_costs_, total_node_costs);
const string& op_name = node->op();
auto& op_cost = FindOrCreateZero(op_name, &op_to_cost_);
op_cost = CombineCosts(op_cost, total_node_costs);
if (VLOG_IS_ON(2)) {
// Also keep track of op counts and costs per op (with their shapes).
OpContext op_context = GetCurrNode();
string node_description = GetOpDescription(op_context.op_info);
op_counts_[node_description] += 1;
op_costs_[node_description] =
std::make_pair(total_node_costs.execution_time.asMicroSeconds().count(),
!node_costs.inaccurate);
}
// Update node and device states.
auto& device = device_[node_state.device_name];
device.nodes_executed.push_back(node);
// Node is scheduled when the device is available AND all the inputs are
// ready; hence, time_scheduled is time_ready if time_ready > device curr
// time.
node_state.time_scheduled =
std::max(device.GetCurrTime(), node_state.time_ready);
// Override device curr time with the time_scheduled.
device.device_costs.execution_time = node_state.time_scheduled;
device.device_costs = CombineCosts(device.device_costs, total_node_costs);
auto curr_time = device.GetCurrTime();
node_state.time_finished = curr_time;
// Update shape annotation states.
UpdateDeviceAnnotationState(node, node_state, &device);
// Update device memory usage.
if (!IsPersistent(*node)) {
for (const auto& port_num_output_pair : node_state.outputs) {
int port_num = port_num_output_pair.first;
// There's a chance that a specific output is not used at all.
if (node_state.outputs[port_num].empty()) {
node_state.time_no_references[port_num] = curr_time;
} else {
device.memory_usage +=
CalculateOutputSize(node_state.output_properties, port_num) *
node_state.execution_count;
device.nodes_in_memory.insert(std::make_pair(node, port_num));
}
}
}
// Update device's per-op cost.
auto& device_op_cost = FindOrCreateZero(op_name, &device.op_to_cost);
device_op_cost = CombineCosts(device_op_cost, total_node_costs);
VLOG(3) << "Op scheduled -- name: " << node->name() << ", op: " << node->op()
<< ", device: " << node->device()
<< ", execution_count: " << node_state.execution_count
<< ", ready: " << node_state.time_ready.count()
<< ", scheduled: " << node_state.time_scheduled.count()
<< ", finished: " << node_state.time_finished.count();
if (previously_executed_merge) {
// Skip AddOutputNodesToReadyQueue; this is due to Switch-Merge.
VLOG(1) << "node [ " << node->name() << ", " << node->op() << " ] "
<< "is executed more than once. "
<< "Skip scheduling its output nodes.";
} else {
// Checks outputs, and adds ready nodes to queue.
AddOutputNodesToReadyQueue(node, curr_time);
}
// Increment num_outputs_executed of the input nodes and maybe update memory.
for (const auto& input_port : node_state.inputs) {
auto* input = input_port.first;
auto port = input_port.second;
auto& input_state = node_map_[input];
input_state.num_outputs_executed[port]++;
if (input_state.num_outputs_executed[port] ==
input_state.outputs[port].size() &&
!IsPersistent(*input)) {
// All the outputs are executed; no reference to this output port of
// input node.
input_state.time_no_references[port] = curr_time;
auto& input_device = device_[input_state.device_name];
input_device.memory_usage -=
CalculateOutputSize(input_state.output_properties, port) *
node_state.execution_count;
input_device.nodes_in_memory.erase(std::make_pair(input, port));
}
}
if (!IsPersistent(*node)) {
// Now that output memory is added and used up nodes are deallocated,
// check max memory usage.
if (device.memory_usage > device.max_memory_usage) {
device.max_memory_usage = device.memory_usage;
if (track_mem_usage_snapshot_) {
device.mem_usage_snapshot_at_peak = device.nodes_in_memory;
}
}
}
ready_nodes_->RemoveCurrNode();
return !ready_nodes_->Empty();
}
Costs VirtualScheduler::Summary() const {
// Overall statement about accuracy
VLOG(1) << graph_costs_.num_ops_total << " ops processed in total, with "
<< graph_costs_.num_ops_with_unknown_shapes
<< " having unknown shapes";
// Print out basic execution summary.
VLOG(1) << "Expected execution time: " << graph_costs_.execution_time.count();
VLOG(1) << "Expected compute time: " << graph_costs_.compute_time.count();
VLOG(1) << "Expected memory time: " << graph_costs_.memory_time.count();
VLOG(1) << "Expected intermediate memory time: "
<< graph_costs_.intermediate_memory_time.count();
VLOG(1) << "Expected max memory: " << graph_costs_.max_memory;
VLOG(1) << "Expected max per-op buffers: " << graph_costs_.max_per_op_buffers;
VLOG(1) << "Expected max per-op streaming buffers: "
<< graph_costs_.max_per_op_streaming;
VLOG(1) << "Per-op execution time / compute time / memory time"
<< " / intermediate memory time:";
for (const auto& op_cost_pair : op_to_cost_) {
const auto& op = op_cost_pair.first;
const auto& cost = op_cost_pair.second.execution_time.count();
const auto& compute_cost = op_cost_pair.second.compute_time.count();
const auto& memory_cost = op_cost_pair.second.memory_time.count();
const auto& intermediate_memory_cost =
op_cost_pair.second.intermediate_memory_time.count();
const bool is_op_cost_accurate = !op_cost_pair.second.inaccurate;
if (cost) { // Skip printing out zero-cost ops.
VLOG(1) << absl::StrFormat(" + %30s : %c %10d / %10d / %10d / %10d", op,
(is_op_cost_accurate ? ' ' : '~'), cost,
compute_cost, memory_cost,
intermediate_memory_cost);
}
}
// Print per device summary
VLOG(1) << "Devices:";
Costs critical_path_costs = Costs::ZeroCosts();
std::vector<string> device_names;
device_names.reserve(device_.size());
for (auto& it : device_) {
device_names.push_back(it.first);
}
std::sort(device_names.begin(), device_names.end());
for (const auto& name : device_names) {
const auto& state = device_.at(name);
std::map<string, int64> op_to_memory;
// First profile only persistent memory usage.
int64 persistent_memory_usage = 0;
std::set<string> persistent_ops;
for (const auto& node_port : state.persistent_nodes) {
const auto* node = node_port.first;
const auto port = node_port.second;
const auto output_size =
CalculateOutputSize(node_map_.at(node).output_properties, port);
persistent_memory_usage += output_size;
op_to_memory[node->op()] += output_size;
persistent_ops.insert(node->op());
}
int64 max_memory_usage = persistent_memory_usage + state.max_memory_usage;
critical_path_costs.estimated_max_memory_per_device[name] =
max_memory_usage;
const Costs::NanoSeconds wall_time_ns = state.GetCurrTime();
VLOG(1) << "Device = " << name
<< ", num_nodes = " << state.nodes_executed.size()
<< ", wall_time_ns = " << wall_time_ns.count() << ", memory usage: "
<< "persistent = " << HumanReadableNumBytes(persistent_memory_usage)
<< ", peak = " << HumanReadableNumBytes(state.max_memory_usage)
<< ", total = " << HumanReadableNumBytes(max_memory_usage)
<< ", at the end: " << HumanReadableNumBytes(state.memory_usage);
// Overall statement about accuracy
VLOG(1) << state.device_costs.num_ops_total
<< " ops processed in total, with "
<< state.device_costs.num_ops_with_unknown_shapes
<< " having unknown shapes";
// Device shape annotation statistics.
const auto& device_annotation_stats = state.shape_annotation_stats;
if (device_annotation_stats.num_ops_annotated > 0) {
VLOG(1) << device_annotation_stats.num_ops_annotated
<< " ops with shape annotation, with "
<< device_annotation_stats.num_ops_executed_more_than_once
<< " executed more than once, "
<< device_annotation_stats.num_ops_with_dynamic_shapes
<< " with dynamic shapes, "
<< device_annotation_stats.num_ops_with_incompatible_shapes
<< " with incompatible shapes, "
<< device_annotation_stats.num_ops_executed
<< " ops executed in total.";
}
VLOG(1) << "Per-op execution time / compute time / memory time "
<< " / intermediate memory time"
<< " (and memory usage at peak memory usage):";
// Profile non-persistent op memory usage.
for (const auto& node_port : state.mem_usage_snapshot_at_peak) {
const auto* node = node_port.first;
const auto port = node_port.second;
op_to_memory[node->op()] +=
CalculateOutputSize(node_map_.at(node).output_properties, port);
}
Costs::NanoSeconds total_compute_time_ns;
bool is_total_cost_accurate = true;
for (const auto& op_cost_pair : state.op_to_cost) {
const auto& op = op_cost_pair.first;
const auto& cost = op_cost_pair.second.execution_time.count();
const auto& compute_cost = op_cost_pair.second.compute_time.count();
const auto& memory_cost = op_cost_pair.second.memory_time.count();
const auto& intermediate_memory_cost =
op_cost_pair.second.intermediate_memory_time.count();
total_compute_time_ns += op_cost_pair.second.execution_time;
const bool is_op_cost_accurate = !op_cost_pair.second.inaccurate;
if (!is_op_cost_accurate) {
is_total_cost_accurate = false;
}
int64 op_mem_usage = 0;
auto it = op_to_memory.find(op);
if (it != op_to_memory.end()) {
op_mem_usage = it->second;
}
const float mem_usage_percent =
max_memory_usage > 0 ? Round2(100.0 * op_mem_usage / max_memory_usage)
: 0.0;
if (cost || mem_usage_percent > 1.0) {
// Print out only non-zero cost ops or ops with > 1% memory usage.
VLOG(1) << absl::StrFormat(
" + %30s : %c %10d / %10d / %10d / %10d", op.c_str(),
(is_op_cost_accurate ? ' ' : '~'), cost, compute_cost,
memory_cost, intermediate_memory_cost)
<< " (" << HumanReadableNumBytes(op_mem_usage) << " ["
<< mem_usage_percent << "%] "
<< (persistent_ops.count(op) > 0 ? ": persistent op)" : ")");
}
}
int utilization = 0;
if (wall_time_ns.count() > 0) {
utilization = total_compute_time_ns.count() * 100 / wall_time_ns.count();
}
VLOG(1) << "Device = " << name << ", total_compute_time_ns = "
<< (is_total_cost_accurate ? "" : "~")
<< total_compute_time_ns.count()
<< ", utilization = " << utilization << "%";
if (critical_path_costs.execution_time <= state.GetCurrTime()) {
critical_path_costs = state.device_costs;
}
}
if (VLOG_IS_ON(2)) {
// Also log the op description and their corresponding counts.
VLOG(2) << "Node description, counts, cost:";
for (const auto& item : op_counts_) {
int cost;
bool is_cost_accurate;
std::tie(cost, is_cost_accurate) = op_costs_.at(item.first);
VLOG(2) << "Node: " << item.first << ", Count: " << item.second
<< ", Individual Cost: " << (is_cost_accurate ? "" : "~") << cost
<< " us";
}
}
VLOG(1) << "Critical path execution time: "
<< critical_path_costs.execution_time.count();
return critical_path_costs;
}
Costs VirtualScheduler::Summary(RunMetadata* metadata) {
if (metadata) GenerateRunMetadata(metadata);
return Summary();
}
void VirtualScheduler::GenerateRunMetadata(RunMetadata* metadata) {
// Fill RunMetadata's step_stats and partition_graphs fields.
StepStats* stepstats = metadata->mutable_step_stats();
for (const auto& device : device_) {
GraphDef* device_partition_graph = metadata->add_partition_graphs();
DeviceStepStats* device_stepstats = stepstats->add_dev_stats();
device_stepstats->set_device(device.first);
for (const auto& node_def : device.second.nodes_executed) {
const NodeState& nodestate = node_map_.at(node_def);
NodeExecStats* node_stats = device_stepstats->add_node_stats();
uint64 total_output_size = 0;
for (int slot = 0; slot < nodestate.output_properties.size(); slot++) {
const auto& properties = nodestate.output_properties[slot];
NodeOutput* no = node_stats->add_output();
no->set_slot(slot);
TensorDescription* tensor_descr = no->mutable_tensor_description();
tensor_descr->set_dtype(properties.dtype());
*tensor_descr->mutable_shape() = properties.shape();
// Optional allocation description.
const auto tensor_size =
CalculateOutputSize(nodestate.output_properties, slot);
total_output_size += tensor_size;
tensor_descr->mutable_allocation_description()->set_requested_bytes(
tensor_size);
tensor_descr->mutable_allocation_description()->set_allocated_bytes(
tensor_size);
}
if (node_def->op() != "HloGenericOp") {
node_stats->set_timeline_label(node_def->op());
} else {
// For HloGenericOp, display hlo_opcode as timeline label.
string timeline_label;
if (node_def->attr().count("hlo_opcode") > 0) {
absl::StrAppend(&timeline_label,
node_def->attr().at("hlo_opcode").s());
}
if (node_def->attr().count("_hlo_metadata_op_type") > 0) {
absl::StrAppend(&timeline_label, "/",
node_def->attr().at("_hlo_metadata_op_type").s());
}
node_stats->set_timeline_label(timeline_label);
}
node_stats->set_node_name(node_def->name());
// Timestamps in microseconds (can be used by timeline_server).
node_stats->set_op_start_rel_micros(0);
node_stats->set_all_start_micros(
nodestate.time_scheduled.asMicroSeconds().count());
node_stats->set_op_end_rel_micros(
nodestate.time_finished.asMicroSeconds().count() -
nodestate.time_scheduled.asMicroSeconds().count());
node_stats->set_all_end_rel_micros(
nodestate.time_finished.asMicroSeconds().count() -
nodestate.time_scheduled.asMicroSeconds().count());
// Timestamps in nanoseconds (can be used by xprof trace).
node_stats->set_op_start_rel_nanos(0);
node_stats->set_all_start_nanos(nodestate.time_scheduled.count());
node_stats->set_op_end_rel_nanos(nodestate.time_finished.count() -
nodestate.time_scheduled.count());
node_stats->set_all_end_rel_nanos(nodestate.time_finished.count() -
nodestate.time_scheduled.count());
auto* mem_stats = node_stats->mutable_memory_stats();
// VirtualScheduler does not specify scratch pad memory usage.
mem_stats->set_temp_memory_size(0);
int64 persistent_memory_size = 0;
if (IsPersistent(*node_def)) {
persistent_memory_size = total_output_size;
}
mem_stats->set_persistent_memory_size(persistent_memory_size);
*device_partition_graph->add_node() = *node_def;
}
}
}
const std::unordered_map<string, int64> VirtualScheduler::GetPeakMemoryUsage()
const {
std::unordered_map<string, int64> result;
for (const auto& device : device_) {
const string& name = device.first;
const DeviceState& state = device.second;
result[name] = state.max_memory_usage;
}
return result;
}
const std::unordered_map<string, int64>
VirtualScheduler::GetPersistentMemoryUsage() const {
std::unordered_map<string, int64> result;
for (const auto& device : device_) {
const string& name = device.first;
const DeviceState& state = device.second;
int64 persistent_memory_usage = 0;
for (const auto& node_port : state.persistent_nodes) {
const auto* node = node_port.first;
const auto port = node_port.second;
const auto output_size =
CalculateOutputSize(node_map_.at(node).output_properties, port);
persistent_memory_usage += output_size;
}
result[name] = persistent_memory_usage;
}
return result;
}
} // end namespace grappler
} // end namespace tensorflow
|
; A070350: a(n) = 2^n mod 45.
; 1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17,34,23,1,2,4,8,16,32,19,38,31,17
mov $1,1
mov $2,$0
lpb $2,1
mul $1,2
mod $1,45
sub $2,1
lpe
|
; A017181: (9n+1)^9.
; 1,1000000000,322687697779,10578455953408,129961739795077,922190162669056,4605366583984375,18014398509481984,58871586708267913,167619550409708032,427929800129788411,1000000000000000000
mul $0,9
add $0,1
pow $0,9
|
Route9WildMons:
def_grass_wildmons 15 ; encounter rate
db 22, MEOWTH
db 22, MACHOP
db 23, MEOWTH
db 21, EKANS
db 22, FARFETCHD
db 23, SPEAROW
db 22, MEOWTH
db 26, GLOOM
db 26, FEAROW
db 27, GROWLITHE
end_grass_wildmons
def_water_wildmons 0 ; encounter rate
end_water_wildmons
|
; A152548: Sum of squared terms in rows of triangle A152547: a(n) = Sum_{k=0..C(n,[n/2])-1} A152547(n,k)^2.
; Submitted by Jon Maiga
; 1,4,10,24,54,120,260,560,1190,2520,5292,11088,23100,48048,99528,205920,424710,875160,1798940,3695120,7574996,15519504,31744440,64899744,132503644,270415600,551231800,1123264800,2286646200,4653525600
mov $1,$0
mov $2,1
add $2,$0
mov $0,$2
div $0,2
bin $1,$0
add $2,$0
add $0,$2
mul $0,$1
|
; A234041: a(n) = binomial(n+2,2)*gcd(n,3)/3, n >= 0.
; 1,1,2,10,5,7,28,12,15,55,22,26,91,35,40,136,51,57,190,70,77,253,92,100,325,117,126,406,145,155,496,176,187,595,210,222,703,247,260,820,287,301,946,330,345,1081,376,392,1225,425,442,1378,477,495,1540,532,551,1711,590,610,1891,651,672,2080,715,737,2278,782,805,2485,852,876,2701,925,950,2926,1001,1027,3160,1080,1107,3403,1162,1190,3655,1247,1276,3916,1335,1365,4186,1426,1457,4465,1520,1552,4753,1617,1650,5050
add $0,2
bin $0,2
dif $0,3
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r13
push %r8
push %r9
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x1a09e, %rsi
dec %r8
movb (%rsi), %r10b
nop
nop
cmp $65410, %r11
lea addresses_normal_ht+0x75b, %r9
nop
nop
nop
nop
and %r13, %r13
movups (%r9), %xmm6
vpextrq $1, %xmm6, %rbx
nop
nop
nop
add %rsi, %rsi
lea addresses_normal_ht+0x162df, %r8
cmp $58954, %r10
mov $0x6162636465666768, %r9
movq %r9, %xmm6
vmovups %ymm6, (%r8)
nop
nop
nop
inc %r13
lea addresses_WC_ht+0xb09e, %r8
nop
and %rsi, %rsi
mov $0x6162636465666768, %r11
movq %r11, (%r8)
nop
nop
nop
nop
nop
sub $30259, %r8
lea addresses_D_ht+0x5f3e, %rsi
lea addresses_D_ht+0x18bd2, %rdi
nop
nop
and $26859, %r11
mov $90, %rcx
rep movsb
nop
nop
nop
nop
sub %r11, %r11
lea addresses_WC_ht+0x2124, %rsi
clflush (%rsi)
nop
nop
nop
nop
nop
and %r10, %r10
mov (%rsi), %ecx
nop
sub %r10, %r10
lea addresses_A_ht+0x12d3e, %rsi
lea addresses_UC_ht+0x14b1e, %rdi
nop
nop
nop
nop
add $59626, %rbx
mov $58, %rcx
rep movsb
nop
nop
nop
nop
nop
xor %r11, %r11
lea addresses_UC_ht+0x1ef3e, %rsi
lea addresses_UC_ht+0x10eb6, %rdi
and $558, %rbx
mov $111, %rcx
rep movsl
nop
nop
nop
nop
nop
xor %rsi, %rsi
lea addresses_WC_ht+0x17fde, %rsi
lea addresses_A_ht+0x1d4e6, %rdi
sub $23860, %r9
mov $101, %rcx
rep movsq
nop
nop
nop
nop
nop
cmp %rsi, %rsi
lea addresses_normal_ht+0x11f3e, %r13
nop
xor %r10, %r10
mov (%r13), %cx
add $29979, %r10
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r9
pop %r8
pop %r13
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r9
push %rax
push %rbx
push %rcx
push %rdi
push %rdx
// Load
lea addresses_A+0xf94e, %r9
nop
nop
sub %r13, %r13
movups (%r9), %xmm4
vpextrq $0, %xmm4, %rdi
nop
nop
nop
nop
cmp %rdi, %rdi
// Store
lea addresses_WC+0x1f7be, %rax
nop
cmp $52602, %rdi
mov $0x5152535455565758, %r13
movq %r13, %xmm7
vmovntdq %ymm7, (%rax)
nop
nop
nop
nop
xor $46892, %rdi
// Load
lea addresses_PSE+0x1e0de, %rax
nop
nop
nop
nop
and %rdx, %rdx
mov (%rax), %ebx
nop
nop
nop
nop
nop
and %rax, %rax
// Load
lea addresses_WC+0x1b356, %rdx
cmp $55115, %rcx
movb (%rdx), %r13b
nop
and %r13, %r13
// Faulty Load
lea addresses_A+0x1cf3e, %r13
nop
nop
nop
add $61951, %rdi
vmovntdqa (%r13), %ymm3
vextracti128 $1, %ymm3, %xmm3
vpextrq $0, %xmm3, %rdx
lea oracles, %rax
and $0xff, %rdx
shlq $12, %rdx
mov (%rax,%rdx,1), %rdx
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r9
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_A', 'same': False, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_A', 'same': False, 'size': 16, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_WC', 'same': False, 'size': 32, 'congruent': 6, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_PSE', 'same': False, 'size': 4, 'congruent': 4, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WC', 'same': False, 'size': 1, 'congruent': 3, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'type': 'addresses_A', 'same': True, 'size': 32, 'congruent': 0, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 1, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_normal_ht', 'same': False, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_normal_ht', 'same': True, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_WC_ht', 'same': True, 'size': 8, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_D_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 4, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_A_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 5, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WC_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_normal_ht', 'same': False, 'size': 2, 'congruent': 11, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'}
{'ec': 1, '16': 20, 'ef': 1, '35': 50, '48': 145, 'f4': 1, '00': 28, '06': 1}
06 35 48 35 48 48 00 48 48 48 48 48 00 48 00 00 48 48 48 48 48 48 48 48 16 48 48 00 48 48 00 00 48 16 48 48 48 48 35 48 35 48 48 48 35 16 48 16 ec 35 35 48 48 35 35 48 48 48 16 16 16 48 48 48 48 48 48 48 48 48 48 48 00 00 35 48 48 48 48 48 16 35 48 00 48 48 48 00 48 48 48 48 00 00 35 35 35 48 48 35 35 35 00 35 35 48 35 00 35 35 35 48 35 48 35 35 16 48 48 16 48 48 35 48 48 48 00 48 48 16 48 48 48 48 48 35 48 48 48 48 35 48 48 48 48 48 48 48 48 48 35 35 00 00 48 48 48 48 48 16 48 35 35 ef 16 35 48 35 48 35 35 35 f4 48 35 16 48 00 00 48 48 48 48 48 00 48 48 48 48 00 48 48 48 48 48 48 48 00 48 48 48 48 48 00 48 16 00 48 48 00 48 48 48 48 48 00 48 16 48 35 35 48 35 00 16 35 35 48 48 48 48 48 35 48 35 48 48 16 35 35 48 35 48 16 35 48 16
*/
|
; A147568: a(n) = 2*A000695(n)+3.
; 3,5,11,13,35,37,43,45,131,133,139,141,163,165,171,173,515,517,523,525,547,549,555,557,643,645,651,653,675,677,683,685,2051,2053,2059,2061,2083,2085,2091,2093,2179,2181,2187,2189,2211,2213,2219,2221,2563,2565,2571
seq $0,98871 ; Sums of distinct powers of 4 plus 1.
mul $0,2
add $0,1
|
;;
;; Copyright (c) 2020, Intel Corporation
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;;
;; * Redistributions of source code must retain the above copyright notice,
;; this list of conditions and the following disclaimer.
;; * Redistributions in binary form must reproduce the above copyright
;; notice, this list of conditions and the following disclaimer in the
;; documentation and/or other materials provided with the distribution.
;; * Neither the name of Intel Corporation nor the names of its contributors
;; may be used to endorse or promote products derived from this software
;; without specific prior written permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;
%include "include/os.asm"
%include "imb_job.asm"
%include "mb_mgr_datastruct.asm"
%include "constants.asm"
%include "include/reg_sizes.asm"
%include "include/const.inc"
%ifndef SUBMIT_JOB_ZUC128_EEA3
%define SUBMIT_JOB_ZUC128_EEA3 submit_job_zuc_eea3_no_gfni_avx512
%define SUBMIT_JOB_ZUC256_EEA3 submit_job_zuc256_eea3_no_gfni_avx512
%define FLUSH_JOB_ZUC128_EEA3 flush_job_zuc_eea3_no_gfni_avx512
%define FLUSH_JOB_ZUC256_EEA3 flush_job_zuc256_eea3_no_gfni_avx512
%define SUBMIT_JOB_ZUC128_EIA3 submit_job_zuc_eia3_no_gfni_avx512
%define FLUSH_JOB_ZUC128_EIA3 flush_job_zuc_eia3_no_gfni_avx512
%define SUBMIT_JOB_ZUC256_EIA3 submit_job_zuc256_eia3_no_gfni_avx512
%define FLUSH_JOB_ZUC256_EIA3 flush_job_zuc256_eia3_no_gfni_avx512
%define ZUC_EIA3_16_BUFFER zuc_eia3_16_buffer_job_no_gfni_avx512
%define ZUC256_EIA3_16_BUFFER zuc256_eia3_16_buffer_job_no_gfni_avx512
%define ZUC128_INIT_16 asm_ZucInitialization_16_avx512
%define ZUC256_INIT_16 asm_Zuc256Initialization_16_avx512
%define ZUC_KEYGEN4B_16 asm_ZucGenKeystream4B_16_avx512
%define ZUC_CIPHER asm_ZucCipher_16_avx512
%endif
section .data
default rel
index_to_mask:
dw 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080
dw 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
extern zuc_eia3_16_buffer_job_no_gfni_avx512
extern zuc_eia3_16_buffer_job_gfni_avx512
extern zuc256_eia3_16_buffer_job_no_gfni_avx512
extern zuc256_eia3_16_buffer_job_gfni_avx512
extern asm_ZucInitialization_16_avx512
extern asm_ZucInitialization_16_gfni_avx512
extern asm_ZucCipher_16_avx512
extern asm_ZucCipher_16_gfni_avx512
extern asm_Zuc256Initialization_16_avx512
extern asm_Zuc256Initialization_16_gfni_avx512
extern asm_ZucGenKeystream4B_16_avx512
extern asm_ZucGenKeystream4B_16_gfni_avx512
%ifdef LINUX
%define arg1 rdi
%define arg2 rsi
%define arg3 rdx
%define arg4 rcx
%define arg5 r8
%else
%define arg1 rcx
%define arg2 rdx
%define arg3 r8
%define arg4 r9
%define arg5 qword [rsp + 32]
%endif
%define state arg1
%define job arg2
%define job_rax rax
; This routine and its callee clobbers all GPRs
struc STACK
_gpr_save: resq 10
_rsp_save: resq 1
endstruc
%define OFS_R1 (16*(4*16))
%define OFS_R2 (OFS_R1 + (4*16))
section .text
%define APPEND(a,b) a %+ b
%macro SUBMIT_JOB_ZUC_EEA3 1
%define %%KEY_SIZE %1 ; [constant] Key size (128 or 256)
; idx needs to be in rbp
%define len rbp
%define idx rbp
%define lane r8
%define unused_lanes rbx
%define tmp r12
%define tmp2 r13
%define tmp3 r14
%define min_len r14
mov rax, rsp
sub rsp, STACK_size
and rsp, -16
mov [rsp + _gpr_save + 8*0], rbx
mov [rsp + _gpr_save + 8*1], rbp
mov [rsp + _gpr_save + 8*2], r12
mov [rsp + _gpr_save + 8*3], r13
mov [rsp + _gpr_save + 8*4], r14
mov [rsp + _gpr_save + 8*5], r15
%ifndef LINUX
mov [rsp + _gpr_save + 8*6], rsi
mov [rsp + _gpr_save + 8*7], rdi
%endif
mov [rsp + _gpr_save + 8*8], state
mov [rsp + _gpr_save + 8*9], job
mov [rsp + _rsp_save], rax ; original SP
mov unused_lanes, [state + _zuc_unused_lanes]
mov lane, unused_lanes
and lane, 0xF ;; just a nibble
shr unused_lanes, 4
mov tmp, [job + _iv]
mov [state + _zuc_args_IV + lane*8], tmp
mov [state + _zuc_unused_lanes], unused_lanes
add qword [state + _zuc_lanes_in_use], 1
mov [state + _zuc_job_in_lane + lane*8], job
; New job that needs init (update bit in zuc_init_not_done bitmask)
lea tmp2, [rel index_to_mask]
movzx DWORD(tmp), word [tmp2 + lane*2]
kmovw k1, DWORD(tmp)
or [state + _zuc_init_not_done], WORD(tmp)
not DWORD(tmp)
and [state + _zuc_unused_lane_bitmask], WORD(tmp)
mov tmp, [job + _src]
add tmp, [job + _cipher_start_src_offset_in_bytes]
mov [state + _zuc_args_in + lane*8], tmp
mov tmp, [job + _enc_keys]
mov [state + _zuc_args_keys + lane*8], tmp
mov tmp, [job + _dst]
mov [state + _zuc_args_out + lane*8], tmp
;; insert len into proper lane
mov len, [job + _msg_len_to_cipher_in_bytes]
;; Update lane len
vmovdqa64 ymm0, [state + _zuc_lens]
vpbroadcastw ymm1, WORD(len)
vmovdqu16 ymm0{k1}, ymm1
vmovdqa64 [state + _zuc_lens], ymm0
;; Find min length for lanes 0-7
vphminposuw xmm2, xmm0
cmp qword [state + _zuc_lanes_in_use], 16
jne %%return_null_submit_eea3
; Find min length for lanes 8-15
vpextrw DWORD(min_len), xmm2, 0 ; min value
vpextrw DWORD(idx), xmm2, 1 ; min index
vextracti128 xmm1, ymm0, 1
vphminposuw xmm2, xmm1
vpextrw DWORD(tmp), xmm2, 0 ; min value
cmp DWORD(min_len), DWORD(tmp)
jle %%use_min
vpextrw DWORD(idx), xmm2, 1 ; min index
add DWORD(idx), 8 ; but index +8
mov min_len, tmp ; min len
%%use_min:
or min_len, min_len
je %%len_is_0_submit_eea3
; Move state into r11, as register for state will be used
; to pass parameter to next function
mov r11, state
%if %%KEY_SIZE == 128
;; If Windows, reserve memory in stack for parameter transferring
%ifndef LINUX
;; 32 bytes for 4 parameters
sub rsp, 32
%endif
lea arg1, [r11 + _zuc_args_keys]
lea arg2, [r11 + _zuc_args_IV]
lea arg3, [r11 + _zuc_state]
movzx DWORD(arg4), word [r11 + _zuc_init_not_done]
call ZUC128_INIT_16
%ifndef LINUX
add rsp, 32
%endif
%else ;; %%KEY_SIZE == 256
;; If Windows, reserve memory in stack for parameter transferring
%ifndef LINUX
;; 40 bytes for 5 parameters
sub rsp, 40
%endif
lea arg1, [r11 + _zuc_args_keys]
lea arg2, [r11 + _zuc_args_IV]
lea arg3, [r11 + _zuc_state]
movzx DWORD(arg4), word [r11 + _zuc_init_not_done]
mov arg5, 2
call ZUC256_INIT_16
%ifndef LINUX
add rsp, 40
%endif
%endif ;; %%KEY_SIZE == 128
mov r11, [rsp + _gpr_save + 8*8]
mov word [r11 + _zuc_init_not_done], 0 ; Init done for all lanes
;; If Windows, reserve memory in stack for parameter transferring
%ifndef LINUX
;; 40 bytes for 5 parameters
sub rsp, 40
%endif
lea arg1, [r11 + _zuc_state]
lea arg2, [r11 + _zuc_args_in]
lea arg3, [r11 + _zuc_args_out]
lea arg4, [r11 + _zuc_lens]
mov arg5, min_len
call ZUC_CIPHER
%ifndef LINUX
add rsp, 40
%endif
mov state, [rsp + _gpr_save + 8*8]
mov job, [rsp + _gpr_save + 8*9]
%%len_is_0_submit_eea3:
; process completed job "idx"
;; - decrement number of jobs in use
sub qword [state + _zuc_lanes_in_use], 1
mov job_rax, [state + _zuc_job_in_lane + idx*8]
mov unused_lanes, [state + _zuc_unused_lanes]
mov qword [state + _zuc_job_in_lane + idx*8], 0
or dword [job_rax + _status], STS_COMPLETED_AES
shl unused_lanes, 4
or unused_lanes, idx
mov [state + _zuc_unused_lanes], unused_lanes
lea tmp2, [rel index_to_mask]
movzx DWORD(tmp), word [tmp2 + idx*2]
or [state + _zuc_unused_lane_bitmask], WORD(tmp)
; Clear ZUC state of lane that is returned
%ifdef SAFE_DATA
vpxorq zmm0, zmm0
kmovw k1, [tmp2 + idx*2]
%assign i 0
%rep (16 + 6)
vmovdqa32 [state + _zuc_state]{k1}, zmm0
%assign i (i + 1)
%endrep
%endif
%%return_submit_eea3:
vzeroupper
mov rbx, [rsp + _gpr_save + 8*0]
mov rbp, [rsp + _gpr_save + 8*1]
mov r12, [rsp + _gpr_save + 8*2]
mov r13, [rsp + _gpr_save + 8*3]
mov r14, [rsp + _gpr_save + 8*4]
mov r15, [rsp + _gpr_save + 8*5]
%ifndef LINUX
mov rsi, [rsp + _gpr_save + 8*6]
mov rdi, [rsp + _gpr_save + 8*7]
%endif
mov rsp, [rsp + _rsp_save] ; original SP
ret
%%return_null_submit_eea3:
xor job_rax, job_rax
jmp %%return_submit_eea3
%endmacro
%macro FLUSH_JOB_ZUC_EEA3 1
%define %%KEY_SIZE %1 ; [constant] Key size (128 or 256)
%define unused_lanes rbx
%define tmp1 rbx
%define tmp2 rax
; idx needs to be in rbp (will be maintained after function calls)
%define tmp rbp
%define idx rbp
%define tmp3 r8
%define tmp4 r9
%define tmp5 r10
%define null_jobs_mask r13 ; Will be maintained after function calls
%define min_len r14 ; Will be maintained after function calls
mov rax, rsp
sub rsp, STACK_size
and rsp, -16
mov [rsp + _gpr_save + 8*0], rbx
mov [rsp + _gpr_save + 8*1], rbp
mov [rsp + _gpr_save + 8*2], r12
mov [rsp + _gpr_save + 8*3], r13
mov [rsp + _gpr_save + 8*4], r14
mov [rsp + _gpr_save + 8*5], r15
%ifndef LINUX
mov [rsp + _gpr_save + 8*6], rsi
mov [rsp + _gpr_save + 8*7], rdi
%endif
mov [rsp + _gpr_save + 8*8], state
mov [rsp + _rsp_save], rax ; original SP
; check for empty
cmp qword [state + _zuc_lanes_in_use], 0
jz %%return_null_flush_eea3
; Find lanes with NULL jobs
vpxorq zmm0, zmm0
vmovdqu64 zmm1, [state + _zuc_job_in_lane]
vmovdqu64 zmm2, [state + _zuc_job_in_lane + (8*8)]
vpcmpq k1, zmm1, zmm0, 0 ; EQ ; mask of null jobs (L8)
vpcmpq k2, zmm2, zmm0, 0 ; EQ ; mask of null jobs (H8)
kshiftlw k3, k2, 8
korw k3, k3, k1 ; mask of NULL jobs for all lanes
kmovw DWORD(null_jobs_mask), k3
;; - Update lengths of NULL lanes to 0xFFFF, to find minimum
vmovdqa ymm0, [state + _zuc_lens]
mov WORD(tmp3), 0xffff
vpbroadcastw ymm1, WORD(tmp3)
vmovdqu16 ymm0{k3}, ymm1
vmovdqa64 [state + _zuc_lens], ymm0
; Find if a job has been finished (length is zero)
vpxor ymm1, ymm1
vpcmpw k4, ymm0, ymm1, 0
kmovw DWORD(tmp), k4
bsf DWORD(idx), DWORD(tmp)
jnz %%len_is_0_flush_eea3
;; Find min length for lanes 0-7
vphminposuw xmm2, xmm0
; extract min length of lanes 0-7
vpextrw DWORD(min_len), xmm2, 0 ; min value
vpextrw DWORD(idx), xmm2, 1 ; min index
;; Update lens and find min for lanes 8-15
vextracti128 xmm1, ymm0, 1
vphminposuw xmm2, xmm1
vpextrw DWORD(tmp3), xmm2, 0 ; min value
cmp DWORD(min_len), DWORD(tmp3)
jle %%use_min_flush
vpextrw DWORD(idx), xmm2, 1 ; min index
add DWORD(idx), 8 ; but index +8
mov min_len, tmp3 ; min len
%%use_min_flush:
; Move state into r12, as register for state will be used
; to pass parameter to next function
mov r12, state
;; copy good lane data (with minimum length) into NULL lanes
;; - k1(L8)/k2(H8)/k3 - masks of NULL jobs
;; - idx index of job with minimum length
;; - in pointer
mov tmp3, [state + _zuc_args_in + idx*8]
vpbroadcastq zmm1, tmp3
vmovdqu64 [state + _zuc_args_in + (0*PTR_SZ)]{k1}, zmm1
vmovdqu64 [state + _zuc_args_in + (8*PTR_SZ)]{k2}, zmm1
;; - out pointer
mov tmp3, [state + _zuc_args_out + idx*8]
vpbroadcastq zmm1, tmp3
vmovdqu64 [state + _zuc_args_out + (0*PTR_SZ)]{k1}, zmm1
vmovdqu64 [state + _zuc_args_out + (8*PTR_SZ)]{k2}, zmm1
;; - key pointer
mov tmp3, [state + _zuc_args_keys + idx*8]
vpbroadcastq zmm1, tmp3
vmovdqu64 [state + _zuc_args_keys + (0*PTR_SZ)]{k1}, zmm1
vmovdqu64 [state + _zuc_args_keys + (8*PTR_SZ)]{k2}, zmm1
;; - IV pointer
mov tmp3, [state + _zuc_args_IV + idx*8]
vpbroadcastq zmm1, tmp3
vmovdqu64 [state + _zuc_args_IV + (0*PTR_SZ)]{k1}, zmm1
vmovdqu64 [state + _zuc_args_IV + (8*PTR_SZ)]{k2}, zmm1
cmp word [r12 + _zuc_init_not_done], 0
je %%skip_init_flush
%if %%KEY_SIZE == 128
;; If Windows, reserve memory in stack for parameter transferring
%ifndef LINUX
;; 32 bytes for 4 parameters
sub rsp, 32
%endif
lea arg1, [r12 + _zuc_args_keys]
lea arg2, [r12 + _zuc_args_IV]
lea arg3, [r12 + _zuc_state]
movzx DWORD(arg4), word [r12 + _zuc_init_not_done]
call ZUC128_INIT_16
%ifndef LINUX
add rsp, 32
%endif
%else ;; %%KEY_SIZE == 256
;; If Windows, reserve memory in stack for parameter transferring
%ifndef LINUX
;; 40 bytes for 5 parameters
sub rsp, 40
%endif
lea arg1, [r12 + _zuc_args_keys]
lea arg2, [r12 + _zuc_args_IV]
lea arg3, [r12 + _zuc_state]
movzx DWORD(arg4), word [r12 + _zuc_init_not_done]
mov arg5, 2
call ZUC256_INIT_16
%ifndef LINUX
add rsp, 40
%endif
%endif ;; %%KEY_SIZE == 128
mov word [r12 + _zuc_init_not_done], 0
%%skip_init_flush:
;; Copy state from valid lane into NULL job masks
kmovq k1, null_jobs_mask
;; Copy LFSR registers
%assign off 0
%rep 16
mov DWORD(tmp4), [r12 + _zuc_state + off + idx*4]
vpbroadcastd zmm0, DWORD(tmp4)
vmovdqa32 [r12 + _zuc_state + off]{k1}, zmm0
%assign off (off + 64)
%endrep
;; Copy R1-2
mov DWORD(tmp4), [r12 + _zuc_state + OFS_R1 + idx*4]
vpbroadcastd zmm0, DWORD(tmp4)
vmovdqa32 [r12 + _zuc_state + OFS_R1]{k1}, zmm0
mov DWORD(tmp4), [r12 + _zuc_state + OFS_R2 + idx*4]
vpbroadcastd zmm0, DWORD(tmp4)
vmovdqa32 [r12 + _zuc_state + OFS_R2]{k1}, zmm0
;; If Windows, reserve memory in stack for parameter transferring
%ifndef LINUX
;; 40 bytes for 5 parameters
sub rsp, 40
%endif
lea arg1, [r12 + _zuc_state]
lea arg2, [r12 + _zuc_args_in]
lea arg3, [r12 + _zuc_args_out]
lea arg4, [r12 + _zuc_lens]
mov arg5, min_len
call ZUC_CIPHER
%ifndef LINUX
add rsp, 40
%endif
mov state, [rsp + _gpr_save + 8*8]
; Prepare bitmask to clear ZUC state with lane
; that is returned and NULL lanes
%ifdef SAFE_DATA
lea tmp2, [rel index_to_mask]
movzx DWORD(tmp1), word [tmp2 + idx*2]
movzx DWORD(tmp3), word [state + _zuc_unused_lane_bitmask]
or tmp3, tmp1 ;; bitmask with NULL lanes and job to return
kmovq k1, tmp3
jmp %%skip_flush_clear_state
%endif
%%len_is_0_flush_eea3:
%ifdef SAFE_DATA
; Prepare bitmask to clear ZUC state with lane that is returned
lea tmp3, [rel index_to_mask]
kmovw k1, [tmp3 + idx*2]
%%skip_flush_clear_state:
%endif
; process completed job "idx"
;; - decrement number of jobs in use
sub qword [state + _zuc_lanes_in_use], 1
mov job_rax, [state + _zuc_job_in_lane + idx*8]
mov unused_lanes, [state + _zuc_unused_lanes]
mov qword [state + _zuc_job_in_lane + idx*8], 0
or dword [job_rax + _status], STS_COMPLETED_AES
shl unused_lanes, 4
or unused_lanes, idx
mov [state + _zuc_unused_lanes], unused_lanes
lea tmp4, [rel index_to_mask]
movzx DWORD(tmp3), word [tmp4 + idx*2]
or [state + _zuc_unused_lane_bitmask], WORD(tmp3)
; Clear ZUC state using k1 bitmask set above
%ifdef SAFE_DATA
vpxorq zmm0, zmm0
%assign i 0
%rep (16 + 6)
vmovdqa32 [state + _zuc_state]{k1}, zmm0
%assign i (i + 1)
%endrep
%endif
vzeroupper
%%return_flush_eea3:
mov rbx, [rsp + _gpr_save + 8*0]
mov rbp, [rsp + _gpr_save + 8*1]
mov r12, [rsp + _gpr_save + 8*2]
mov r13, [rsp + _gpr_save + 8*3]
mov r14, [rsp + _gpr_save + 8*4]
mov r15, [rsp + _gpr_save + 8*5]
%ifndef LINUX
mov rsi, [rsp + _gpr_save + 8*6]
mov rdi, [rsp + _gpr_save + 8*7]
%endif
mov rsp, [rsp + _rsp_save] ; original SP
ret
%%return_null_flush_eea3:
xor job_rax, job_rax
jmp %%return_flush_eea3
%endmacro
; JOB* SUBMIT_JOB_ZUC128_EEA3(MB_MGR_ZUC_OOO *state, IMB_JOB *job)
; arg 1 : state
; arg 2 : job
MKGLOBAL(SUBMIT_JOB_ZUC128_EEA3,function,internal)
SUBMIT_JOB_ZUC128_EEA3:
SUBMIT_JOB_ZUC_EEA3 128
; JOB* SUBMIT_JOB_ZUC256_EEA3(MB_MGR_ZUC_OOO *state, IMB_JOB *job)
; arg 1 : state
; arg 2 : job
MKGLOBAL(SUBMIT_JOB_ZUC256_EEA3,function,internal)
SUBMIT_JOB_ZUC256_EEA3:
SUBMIT_JOB_ZUC_EEA3 256
; JOB* FLUSH_JOB_ZUC128_EEA3(MB_MGR_ZUC_OOO *state)
; arg 1 : state
MKGLOBAL(FLUSH_JOB_ZUC128_EEA3,function,internal)
FLUSH_JOB_ZUC128_EEA3:
FLUSH_JOB_ZUC_EEA3 128
; JOB* FLUSH_JOB_ZUC256_EEA3(MB_MGR_ZUC_OOO *state)
; arg 1 : state
MKGLOBAL(FLUSH_JOB_ZUC256_EEA3,function,internal)
FLUSH_JOB_ZUC256_EEA3:
FLUSH_JOB_ZUC_EEA3 256
%macro SUBMIT_JOB_ZUC_EIA3 1
%define %%KEY_SIZE %1 ; [constant] Key size (128 or 256)
; idx needs to be in rbp
%define len rbp
%define idx rbp
%define lane r8
%define unused_lanes rbx
%define tmp r12
%define tmp2 r13
%define tmp3 r14
%define min_len r14
mov rax, rsp
sub rsp, STACK_size
and rsp, -16
mov [rsp + _gpr_save + 8*0], rbx
mov [rsp + _gpr_save + 8*1], rbp
mov [rsp + _gpr_save + 8*2], r12
mov [rsp + _gpr_save + 8*3], r13
mov [rsp + _gpr_save + 8*4], r14
mov [rsp + _gpr_save + 8*5], r15
%ifndef LINUX
mov [rsp + _gpr_save + 8*6], rsi
mov [rsp + _gpr_save + 8*7], rdi
%endif
mov [rsp + _gpr_save + 8*8], state
mov [rsp + _gpr_save + 8*9], job
mov [rsp + _rsp_save], rax ; original SP
mov unused_lanes, [state + _zuc_unused_lanes]
mov lane, unused_lanes
and lane, 0xF ;; just a nibble
shr unused_lanes, 4
mov tmp, [job + _zuc_eia3_iv]
mov [state + _zuc_args_IV + lane*8], tmp
mov [state + _zuc_unused_lanes], unused_lanes
add qword [state + _zuc_lanes_in_use], 1
mov [state + _zuc_job_in_lane + lane*8], job
; New job that needs init (update bit in zuc_init_not_done bitmask)
lea tmp2, [rel index_to_mask]
movzx DWORD(tmp), word [tmp2 + lane*2]
or [state + _zuc_init_not_done], WORD(tmp)
kmovq k1, tmp
not tmp
and [state + _zuc_unused_lane_bitmask], WORD(tmp)
; Reset temporary digest for the lane
mov dword [state + _zuc_args_digest + lane*4], 0
mov tmp, [job + _src]
add tmp, [job + _hash_start_src_offset_in_bytes]
mov [state + _zuc_args_in + lane*8], tmp
mov tmp, [job + _zuc_eia3_key]
mov [state + _zuc_args_keys + lane*8], tmp
;; insert len into proper lane
mov len, [job + _msg_len_to_hash_in_bits]
;; Update lane len
vmovdqa64 ymm0, [state + _zuc_lens]
vpbroadcastw ymm1, WORD(len)
vmovdqu16 ymm0{k1}, ymm1
vmovdqa64 [state + _zuc_lens], ymm0
cmp qword [state + _zuc_lanes_in_use], 16
jne %%return_null_submit_eia3
;; Find min length for lanes 0-7
vphminposuw xmm2, xmm0
; Find min length for lanes 8-15
vpextrw DWORD(min_len), xmm2, 0 ; min value
vpextrw DWORD(idx), xmm2, 1 ; min index
vextracti128 xmm1, ymm0, 1
vphminposuw xmm2, xmm1
vpextrw DWORD(tmp), xmm2, 0 ; min value
cmp DWORD(min_len), DWORD(tmp)
jle %%use_min_eia3
vpextrw DWORD(idx), xmm2, 1 ; min index
add DWORD(idx), 8 ; but index +8
mov min_len, tmp ; min len
%%use_min_eia3:
or min_len, min_len
jz %%len_is_0_submit_eia3
; Move state into r12, as register for state will be used
; to pass parameter to next function
mov r12, state
%if %%KEY_SIZE == 128
;; If Windows, reserve memory in stack for parameter transferring
%ifndef LINUX
;; 32 bytes for 4 parameters
sub rsp, 32
%endif
lea arg1, [r12 + _zuc_args_keys]
lea arg2, [r12 + _zuc_args_IV]
lea arg3, [r12 + _zuc_state]
movzx DWORD(arg4), word [r12 + _zuc_init_not_done]
call ZUC128_INIT_16
%ifndef LINUX
add rsp, 32
%endif
%else ;; %%KEY_SIZE == 256
;; If Windows, reserve memory in stack for parameter transferring
%ifndef LINUX
;; 40 bytes for 5 parameters
sub rsp, 40
%endif
lea arg1, [r12 + _zuc_args_keys]
lea arg2, [r12 + _zuc_args_IV]
lea arg3, [r12 + _zuc_state]
movzx DWORD(arg4), word [r12 + _zuc_init_not_done]
mov arg5, 4
call ZUC256_INIT_16
%ifndef LINUX
;; 32 bytes for 4 parameters (RSP was 40 bytes down, so we need 4 bytes up)
add rsp, 8
%endif
lea arg1, [r12 + _zuc_state]
lea arg2, [r12 + _zuc_args_digest]
movzx DWORD(arg3), word [r12 + _zuc_init_not_done]
; Generate first 4 bytes of keystream, used as the initial value of digests
call ZUC_KEYGEN4B_16
%ifndef LINUX
add rsp, 32
%endif
%endif ;; %%KEY_SIZE == 128
%ifndef LINUX
sub rsp, 32
%endif
mov arg1, r12
%if %%KEY_SIZE == 128
call ZUC_EIA3_16_BUFFER
%else
call ZUC256_EIA3_16_BUFFER
%endif
%ifndef LINUX
add rsp, 32
%endif
mov state, [rsp + _gpr_save + 8*8]
mov job, [rsp + _gpr_save + 8*9]
%%len_is_0_submit_eia3:
; process completed job "idx"
;; - decrement number of jobs in use
sub qword [state + _zuc_lanes_in_use], 1
mov job_rax, [state + _zuc_job_in_lane + idx*8]
mov unused_lanes, [state + _zuc_unused_lanes]
mov qword [state + _zuc_job_in_lane + idx*8], 0
or dword [job_rax + _status], STS_COMPLETED_HMAC
; Copy digest to auth tag output
mov r10d, [state + _zuc_args_digest + idx*4]
mov r11, [job_rax + _auth_tag_output]
mov [r11], r10d
shl unused_lanes, 4
or unused_lanes, idx
mov [state + _zuc_unused_lanes], unused_lanes
lea tmp2, [rel index_to_mask]
movzx DWORD(tmp), word [tmp2 + idx*2]
or [state + _zuc_unused_lane_bitmask], WORD(tmp)
; Clear ZUC state of lane that is returned
%ifdef SAFE_DATA
vpxorq zmm0, zmm0
kmovw k1, [tmp2 + idx*2]
%assign i 0
%rep (16 + 6)
vmovdqa32 [state + _zuc_state]{k1}, zmm0
%assign i (i + 1)
%endrep
%endif
%%return_submit_eia3:
vzeroupper
mov rbx, [rsp + _gpr_save + 8*0]
mov rbp, [rsp + _gpr_save + 8*1]
mov r12, [rsp + _gpr_save + 8*2]
mov r13, [rsp + _gpr_save + 8*3]
mov r14, [rsp + _gpr_save + 8*4]
mov r15, [rsp + _gpr_save + 8*5]
%ifndef LINUX
mov rsi, [rsp + _gpr_save + 8*6]
mov rdi, [rsp + _gpr_save + 8*7]
%endif
mov rsp, [rsp + _rsp_save] ; original SP
ret
%%return_null_submit_eia3:
xor job_rax, job_rax
jmp %%return_submit_eia3
%endmacro
%macro FLUSH_JOB_ZUC_EIA3 1
%define %%KEY_SIZE %1 ; [constant] Key size (128 or 256)
%define unused_lanes rbx
%define tmp1 rbx
%define tmp2 rax
%define tmp rbp
%define tmp3 r8
%define tmp4 r9
%define idx r14 ; Will be maintained after function calls
%define min_len r15 ; Will be maintained after function calls
mov rax, rsp
sub rsp, STACK_size
and rsp, -16
mov [rsp + _gpr_save + 8*0], rbx
mov [rsp + _gpr_save + 8*1], rbp
mov [rsp + _gpr_save + 8*2], r12
mov [rsp + _gpr_save + 8*3], r13
mov [rsp + _gpr_save + 8*4], r14
mov [rsp + _gpr_save + 8*5], r15
%ifndef LINUX
mov [rsp + _gpr_save + 8*6], rsi
mov [rsp + _gpr_save + 8*7], rdi
%endif
mov [rsp + _gpr_save + 8*8], state
mov [rsp + _rsp_save], rax ; original SP
; check for empty
cmp qword [state + _zuc_lanes_in_use], 0
jz %%return_null_flush_eia3
; find a lane with a null job
vpxorq zmm0, zmm0
vmovdqu64 zmm1, [state + _zuc_job_in_lane]
vmovdqu64 zmm2, [state + _zuc_job_in_lane + (8*8)]
vpcmpq k1, zmm1, zmm0, 0 ; EQ ; mask of null jobs (L8)
vpcmpq k2, zmm2, zmm0, 0 ; EQ ; mask of null jobs (H8)
kshiftlw k3, k2, 8
korw k3, k3, k1 ; mask of NULL jobs for all lanes
;; - Update lengths of NULL lanes to 0xFFFF, to find minimum
vmovdqa ymm0, [state + _zuc_lens]
mov WORD(tmp3), 0xffff
vpbroadcastw ymm1, WORD(tmp3)
vmovdqu16 ymm0{k3}, ymm1
vmovdqa64 [state + _zuc_lens], ymm0
; Find if a job has been finished (length is zero)
vpxor ymm1, ymm1
vpcmpw k4, ymm0, ymm1, 0
kmovw DWORD(tmp), k4
bsf DWORD(idx), DWORD(tmp)
jnz %%len_is_0_flush_eia3
;; Find min length for lanes 0-7
vphminposuw xmm2, xmm0
; extract min length of lanes 0-7
vpextrw DWORD(min_len), xmm2, 0 ; min value
vpextrw DWORD(idx), xmm2, 1 ; min index
;; Update lens and find min for lanes 8-15
vextracti128 xmm1, ymm0, 1
vphminposuw xmm2, xmm1
vpextrw DWORD(tmp3), xmm2, 0 ; min value
cmp DWORD(min_len), DWORD(tmp3)
jle %%use_min_flush_eia3
vpextrw DWORD(idx), xmm2, 1 ; min index
add DWORD(idx), 8 ; but index +8
mov min_len, tmp3 ; min len
%%use_min_flush_eia3:
;; copy good lane data into NULL lanes
;; - k1(L8)/k2(H8)/k3 - masks of NULL jobs
;; - idx - index of 1st non-null job
;; - in pointer
mov tmp3, [state + _zuc_args_in + idx*8]
vpbroadcastq zmm1, tmp3
vmovdqu64 [state + _zuc_args_in + (0*PTR_SZ)]{k1}, zmm1
vmovdqu64 [state + _zuc_args_in + (8*PTR_SZ)]{k2}, zmm1
;; - key pointer
mov tmp3, [state + _zuc_args_keys + idx*8]
vpbroadcastq zmm1, tmp3
vmovdqu64 [state + _zuc_args_keys + (0*PTR_SZ)]{k1}, zmm1
vmovdqu64 [state + _zuc_args_keys + (8*PTR_SZ)]{k2}, zmm1
;; - IV pointer
mov tmp3, [state + _zuc_args_IV + idx*8]
vpbroadcastq zmm1, tmp3
vmovdqu64 [state + _zuc_args_IV + (0*PTR_SZ)]{k1}, zmm1
vmovdqu64 [state + _zuc_args_IV + (8*PTR_SZ)]{k2}, zmm1
; Move state into r12, as register for state will be used
; to pass parameter to next function
mov r12, state
cmp word [r12 + _zuc_init_not_done], 0
je %%skip_init_flush_eia3
%if %%KEY_SIZE == 128
;; If Windows, reserve memory in stack for parameter transferring
%ifndef LINUX
;; 32 bytes for 4 parameters
sub rsp, 32
%endif
lea arg1, [r12 + _zuc_args_keys]
lea arg2, [r12 + _zuc_args_IV]
lea arg3, [r12 + _zuc_state]
movzx DWORD(arg4), word [r12 + _zuc_init_not_done]
call ZUC128_INIT_16
%ifndef LINUX
add rsp, 32
%endif
%else ;; %%KEY_SIZE == 256
;; If Windows, reserve memory in stack for parameter transferring
%ifndef LINUX
;; 40 bytes for 4 parameters
sub rsp, 40
%endif
lea arg1, [r12 + _zuc_args_keys]
lea arg2, [r12 + _zuc_args_IV]
lea arg3, [r12 + _zuc_state]
movzx DWORD(arg4), word [r12 + _zuc_init_not_done]
mov arg5, 4
call ZUC256_INIT_16
%ifndef LINUX
;; 32 bytes for 4 parameters (RSP was 40 bytes down, so we need 4 bytes up)
add rsp, 8
%endif
lea arg1, [r12 + _zuc_state]
lea arg2, [r12 + _zuc_args_digest]
movzx DWORD(arg3), word [r12 + _zuc_init_not_done]
; Generate first 4 bytes of keystream, used as the initial value of digests
call ZUC_KEYGEN4B_16
%ifndef LINUX
add rsp, 32
%endif
%endif ;; %%KEY_SIZE == 128
%%skip_init_flush_eia3:
%ifndef LINUX
sub rsp, 32
%endif
mov arg1, r12
%if %%KEY_SIZE == 128
call ZUC_EIA3_16_BUFFER
%else
call ZUC256_EIA3_16_BUFFER
%endif
%ifndef LINUX
add rsp, 32
%endif
mov state, [rsp + _gpr_save + 8*8]
; Prepare bitmask to clear ZUC state with lane
; that is returned and NULL lanes
%ifdef SAFE_DATA
lea tmp2, [rel index_to_mask]
movzx DWORD(tmp1), word [tmp2 + idx*2]
movzx DWORD(tmp3), word [state + _zuc_unused_lane_bitmask]
or tmp3, tmp1 ;; bitmask with NULL lanes and job to return
kmovq k1, tmp3
jmp %%skip_flush_clear_state_eia3
%endif
%%len_is_0_flush_eia3:
%ifdef SAFE_DATA
; Prepare bitmask to clear ZUC state with lane that is returned
lea tmp3, [rel index_to_mask]
kmovw k1, [tmp3 + idx*2]
%%skip_flush_clear_state_eia3:
%endif
; process completed job "idx"
;; - decrement number of jobs in use
sub qword [state + _zuc_lanes_in_use], 1
mov job_rax, [state + _zuc_job_in_lane + idx*8]
mov unused_lanes, [state + _zuc_unused_lanes]
mov qword [state + _zuc_job_in_lane + idx*8], 0
or dword [job_rax + _status], STS_COMPLETED_HMAC
; Copy digest to auth tag output
mov r10d, [state + _zuc_args_digest + idx*4]
mov r11, [job_rax + _auth_tag_output]
mov [r11], r10d
shl unused_lanes, 4
or unused_lanes, idx
mov [state + _zuc_unused_lanes], unused_lanes
lea tmp4, [rel index_to_mask]
movzx DWORD(tmp3), word [tmp4 + idx*2]
or [state + _zuc_unused_lane_bitmask], WORD(tmp3)
; Clear ZUC state using k1 bitmask set above
%ifdef SAFE_DATA
vpxorq zmm0, zmm0
%assign i 0
%rep (16 + 6)
vmovdqa32 [state + _zuc_state]{k1}, zmm0
%assign i (i + 1)
%endrep
%endif
vzeroupper
%%return_flush_eia3:
mov rbx, [rsp + _gpr_save + 8*0]
mov rbp, [rsp + _gpr_save + 8*1]
mov r12, [rsp + _gpr_save + 8*2]
mov r13, [rsp + _gpr_save + 8*3]
mov r14, [rsp + _gpr_save + 8*4]
mov r15, [rsp + _gpr_save + 8*5]
%ifndef LINUX
mov rsi, [rsp + _gpr_save + 8*6]
mov rdi, [rsp + _gpr_save + 8*7]
%endif
mov rsp, [rsp + _rsp_save] ; original SP
ret
%%return_null_flush_eia3:
xor job_rax, job_rax
jmp %%return_flush_eia3
%endmacro
; JOB* SUBMIT_JOB_ZUC128_EIA3(MB_MGR_ZUC_OOO *state, IMB_JOB *job)
; arg 1 : state
; arg 2 : job
MKGLOBAL(SUBMIT_JOB_ZUC128_EIA3,function,internal)
SUBMIT_JOB_ZUC128_EIA3:
SUBMIT_JOB_ZUC_EIA3 128
; JOB* SUBMIT_JOB_ZUC256_EIA3(MB_MGR_ZUC_OOO *state, IMB_JOB *job)
; arg 1 : state
; arg 2 : job
MKGLOBAL(SUBMIT_JOB_ZUC256_EIA3,function,internal)
SUBMIT_JOB_ZUC256_EIA3:
SUBMIT_JOB_ZUC_EIA3 256
; JOB* FLUSH_JOB_ZUC128_EIA3(MB_MGR_ZUC_OOO *state)
; arg 1 : state
MKGLOBAL(FLUSH_JOB_ZUC128_EIA3,function,internal)
FLUSH_JOB_ZUC128_EIA3:
FLUSH_JOB_ZUC_EIA3 128
; JOB* FLUSH_JOB_ZUC256_EIA3(MB_MGR_ZUC_OOO *state)
; arg 1 : state
MKGLOBAL(FLUSH_JOB_ZUC256_EIA3,function,internal)
FLUSH_JOB_ZUC256_EIA3:
FLUSH_JOB_ZUC_EIA3 256
%ifdef LINUX
section .note.GNU-stack noalloc noexec nowrite progbits
%endif
|
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the BSD 3-Clause License (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of the
// License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// 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 "flare/net/internal/http_engine.h"
#include <fcntl.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/timerfd.h>
#include <algorithm>
#include <mutex>
#include <queue>
#include <vector>
#include "flare/base/internal/lazy_init.h"
#include "flare/base/object_pool.h"
#include "flare/base/thread/attribute.h"
#include "flare/fiber/detail/scheduling_group.h"
#include "flare/fiber/fiber.h"
#include "flare/fiber/runtime.h"
DEFINE_int32(flare_http_engine_workers_per_scheduling_group, 1,
"http engine background workers per scheduling group");
DEFINE_int32(flare_http_engine_max_connections_per_host_per_worker, 50,
"max connections per host per worker");
DEFINE_int32(flare_http_engine_max_total_connections_per_worker, 200,
"max total connections per worker");
DEFINE_bool(flare_http_engine_use_epoll, false,
"http client use epoll or poll");
DEFINE_bool(flare_http_engine_enable_debug, false,
"If set, debugging output from libcurl is logged.");
DEFINE_bool(flare_http_engine_enable_debug_body, false,
"If set, HTTP body is also logged.");
using namespace std::literals;
namespace flare {
namespace internal {
class Notifier {
public:
bool Init() {
fd_ = eventfd(0, 0);
if (fd_ < 0) return false;
return SetupFd(fd_);
}
bool SetupFd(int fd) {
int old_fl = fcntl(fd, F_GETFL, 0);
if (old_fl < 0) {
return false;
}
int f = fcntl(fd, F_SETFL, old_fl | O_NONBLOCK);
if (f == -1) {
return false;
}
int old_fd = fcntl(fd, F_GETFD, 0);
if (old_fd < 0) return false;
if (fcntl(fd, F_SETFD, old_fd | FD_CLOEXEC) == -1) return false;
return true;
}
void Read() {
eventfd_t u;
while (eventfd_read(fd_, &u) == 0) {
// Empty body
}
}
bool Notify() {
DCHECK_GE(fd_, 0);
eventfd_t u = 1;
return eventfd_write(fd_, u) == 0;
}
int Fd() { return fd_; }
private:
int fd_;
};
class CallContextQueue {
public:
void Push(PooledPtr<HttpTaskCallContext> ctx) {
std::unique_lock _(pending_call_ctx_mutex_);
pending_call_ctxs_.push(std::move(ctx));
}
// Out should ensure that the size is at least max_ctxs.
// Returns the actual pop number.
std::size_t Pop(PooledPtr<HttpTaskCallContext>* out, std::size_t max_ctxs) {
if (max_ctxs == 0) return 0;
std::unique_lock _(pending_call_ctx_mutex_);
std::size_t i = 0;
while (max_ctxs-- && !pending_call_ctxs_.empty()) {
out[i++] = std::move(pending_call_ctxs_.front());
pending_call_ctxs_.pop();
}
return i;
}
private:
std::mutex pending_call_ctx_mutex_;
std::queue<PooledPtr<HttpTaskCallContext>> pending_call_ctxs_;
};
int SockCallback(CURL* e, curl_socket_t s, int what, void* cbp, void* sockp);
int MultiTimerCallback(CURLM* multi, long timeout_ms, int* tfd) { // NOLINT
struct itimerspec its;
if (timeout_ms > 0) {
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
its.it_value.tv_sec = timeout_ms / 1000;
its.it_value.tv_nsec = (timeout_ms % 1000) * 1000 * 1000;
} else if (timeout_ms == 0) {
/* libcurl wants us to timeout now, however setting both fields of
* new_value.it_value to zero disarms the timer. The closest we can
* do is to schedule the timer to fire in 1 ns. */
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = 1;
} else {
memset(&its, 0, sizeof(struct itimerspec));
}
timerfd_settime(*tfd, /*flags=*/0, &its, nullptr);
return 0;
}
class CurlClient {
public:
CurlClient(std::size_t group, CallContextQueue* call_context_queue,
Notifier* notifier) {
multi_handle_ = curl_multi_init();
FLARE_CHECK(multi_handle_, "Curl multi init failed");
curl_multi_setopt(multi_handle_, CURLMOPT_MAXCONNECTS,
FLAGS_flare_http_engine_max_total_connections_per_worker);
curl_multi_setopt(
multi_handle_, CURLMOPT_MAX_HOST_CONNECTIONS,
FLAGS_flare_http_engine_max_connections_per_host_per_worker);
notifier_ = notifier;
group_ = group;
call_context_queue_ = call_context_queue;
worker_ = std::thread([this, group] {
flare::SetCurrentThreadAffinity(
fiber::detail::GetSchedulingGroup(group)->Affinity());
if (FLAGS_flare_http_engine_use_epoll) {
InitEpoll();
LoopEpoll();
} else {
LoopPoll();
}
});
}
void Stop() { exiting_.store(true, std::memory_order_relaxed); }
~CurlClient() {
worker_.join();
struct itimerspec its;
timerfd_settime(tfd_, 0, &its, nullptr);
curl_multi_cleanup(multi_handle_);
}
void InitEpoll() {
epfd_ = epoll_create1(EPOLL_CLOEXEC);
FLARE_CHECK(epfd_ != -1, "epoll_create1 failed");
tfd_ = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
FLARE_CHECK(tfd_ != -1, "timerfd_create failed");
struct itimerspec its;
memset(&its, 0, sizeof(struct itimerspec));
its.it_interval.tv_sec = 0;
its.it_value.tv_sec = 1;
timerfd_settime(tfd_, 0, &its, nullptr);
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = tfd_;
epoll_ctl(epfd_, EPOLL_CTL_ADD, tfd_, &ev);
curl_multi_setopt(multi_handle_, CURLMOPT_SOCKETFUNCTION, SockCallback);
curl_multi_setopt(multi_handle_, CURLMOPT_SOCKETDATA, this);
curl_multi_setopt(multi_handle_, CURLMOPT_TIMERFUNCTION,
MultiTimerCallback);
curl_multi_setopt(multi_handle_, CURLMOPT_TIMERDATA, &tfd_);
ev.events = EPOLLIN;
ev.data.fd = notifier_->Fd();
epoll_ctl(epfd_, EPOLL_CTL_ADD, notifier_->Fd(), &ev);
}
void TimerCallback(int revents) {
uint64_t count = 0;
ssize_t err = read(tfd_, &count, sizeof(uint64_t));
if (err == -1) {
/* Note that we may call the timer callback even if the timerfd isn't
* readable. It's possible that there are multiple events stored in the
* epoll buffer (i.e. the timer may have fired multiple times). The
* event count is cleared after the first call so future events in the
* epoll buffer will fail to read from the timer. */
if (errno == EAGAIN) {
FLARE_VLOG(100, "EAGAIN on tfd {}", tfd_);
return;
}
}
FLARE_CHECK(err == sizeof(uint64_t), "read(tfd) == {}", err);
curl_multi_socket_action(multi_handle_, CURL_SOCKET_TIMEOUT, 0,
&still_running_);
CheckMultiInfo();
}
void EventCallback(int fd, int revents) {
int action = ((revents & EPOLLIN) ? CURL_CSELECT_IN : 0) |
((revents & EPOLLOUT) ? CURL_CSELECT_OUT : 0);
curl_multi_socket_action(multi_handle_, fd, action, &still_running_);
CheckMultiInfo();
}
void CheckMultiInfo() {
CURLMsg* msg;
int msgs_left;
while ((msg = curl_multi_info_read(multi_handle_, &msgs_left))) {
if (msg->msg == CURLMSG_DONE) {
CURL* e = msg->easy_handle;
curl_multi_remove_handle(multi_handle_, e);
fiber::internal::StartFiberDetached(
Fiber::Attributes{.scheduling_group = group_},
[this, e, msg]() mutable {
void* pointer;
curl_easy_getinfo(e, CURLINFO_PRIVATE, &pointer);
EasyHandlerDone(e, msg->data.result,
reinterpret_cast<HttpTaskCallContext*>(pointer));
});
}
}
}
void AddHandlers() {
static constexpr std::size_t kMaxStilRunning = 50;
static constexpr std::size_t kLocalPopArraySize = 30;
PooledPtr<HttpTaskCallContext> local_pop_array[kLocalPopArraySize];
std::size_t max_to_pop = (still_running_ >= kMaxStilRunning)
? 1
: kMaxStilRunning - still_running_;
PooledPtr<HttpTaskCallContext>* out;
std::vector<PooledPtr<HttpTaskCallContext>> large_pop_array;
if (max_to_pop <= kLocalPopArraySize) {
out = local_pop_array;
} else {
large_pop_array.resize(max_to_pop);
out = large_pop_array.data();
}
auto n = call_context_queue_->Pop(out, max_to_pop);
for (std::size_t i = 0; i < n; ++i) {
curl_multi_add_handle(multi_handle_, out[i]->curl_handler);
HttpTaskCallContext* ctx = out[i].Leak();
FLARE_CHECK_EQ(CURLE_OK,
curl_easy_setopt(ctx->curl_handler, CURLOPT_PRIVATE, ctx));
}
}
void LoopEpoll() {
struct epoll_event events[128];
while (!exiting_.load(std::memory_order_relaxed)) {
AddHandlers();
int err = epoll_wait(epfd_, events,
sizeof(events) / sizeof(struct epoll_event), 1000);
if (err == -1) {
if (errno == EINTR) {
FLARE_LOG_INFO_EVERY_SECOND("Note: wait interrupted");
continue;
} else {
FLARE_CHECK(0, "Epoll wait error");
}
}
for (int idx = 0; idx < err; ++idx) {
if (events[idx].data.fd == tfd_) {
TimerCallback(events[idx].events);
} else if (events[idx].data.fd == notifier_->Fd()) {
notifier_->Read();
} else {
EventCallback(events[idx].data.fd, events[idx].events);
}
}
}
}
void LoopPoll() {
int numfds;
struct curl_waitfd extra_fds[1];
extra_fds[0].fd = notifier_->Fd();
extra_fds[0].events = CURL_WAIT_POLLIN;
while (!exiting_.load(std::memory_order_relaxed)) {
CURLMcode mc = curl_multi_perform(multi_handle_, &still_running_);
CheckMultiInfo();
AddHandlers();
long curl_timeo = -1; // NOLINT
curl_multi_timeout(multi_handle_, &curl_timeo);
if (curl_timeo < 0) {
curl_timeo = 5;
}
mc = curl_multi_poll(multi_handle_, extra_fds, 1, curl_timeo, &numfds);
notifier_->Read();
}
}
void EasyHandlerDone(CURL* easy_handler, CURLcode result_code,
HttpTaskCallContext* ctx) {
// `done` is kept alive until user's callback returns. This is necessary if
// the user frees `HttpTaskCompletion` in its callback. If we keep `done` in
// `HttpTaskCompletion`, user's callback might get freed even before it
// completes.
auto done = std::move(ctx->done);
if (result_code != CURLE_OK) {
done(Status(result_code, curl_easy_strerror(result_code)));
object_pool::Put<HttpTaskCallContext>(ctx);
} else {
done(HttpTaskCompletion(ctx));
}
}
CURLM* multi_handle_;
int epfd_;
private:
std::atomic<bool> exiting_{false};
std::thread worker_;
int tfd_;
Notifier* notifier_;
std::size_t group_;
CallContextQueue* call_context_queue_;
int still_running_ = 0;
};
class CurlClientGroup {
public:
CurlClientGroup(std::size_t sz, std::size_t group) {
FLARE_CHECK(notifier_.Init(), "Failed to init notifier");
for (std::size_t i = 0; i < sz; ++i) {
clients_.push_back(
std::make_unique<CurlClient>(group, &queue_, ¬ifier_));
}
}
void PushContext(PooledPtr<HttpTaskCallContext> ctx) {
queue_.Push(std::move(ctx));
notifier_.Notify();
}
void Stop() {
for (auto&& c : clients_) {
c->Stop();
}
}
private:
std::vector<std::unique_ptr<CurlClient>> clients_;
CallContextQueue queue_;
Notifier notifier_;
};
std::vector<std::unique_ptr<CurlClientGroup>> curl_client_groups;
struct SockInfo {
curl_socket_t sockfd;
CURL* easy;
int action;
long timeout; // NOLINT
};
void SetSock(SockInfo* f, curl_socket_t s, CURL* e, int act, CurlClient* g) {
struct epoll_event ev;
int kind = ((act & CURL_POLL_IN) ? static_cast<int>(EPOLLIN) : 0) |
((act & CURL_POLL_OUT) ? static_cast<int>(EPOLLOUT) : 0);
if (f->sockfd) {
if (epoll_ctl(g->epfd_, EPOLL_CTL_DEL, f->sockfd, nullptr))
FLARE_LOG_ERROR_EVERY_SECOND("EPOLL_CTL_DEL failed for fd: {} : {}\n",
f->sockfd, strerror(errno));
}
f->sockfd = s;
f->action = act;
f->easy = e;
ev.events = kind;
ev.data.fd = s;
if (epoll_ctl(g->epfd_, EPOLL_CTL_ADD, s, &ev))
FLARE_LOG_ERROR_EVERY_SECOND("EPOLL_CTL_ADD failed for fd: {} : {}\n", s,
strerror(errno));
}
void RemoveSock(SockInfo* f, CurlClient* g) {
if (f) {
if (f->sockfd) {
if (epoll_ctl(g->epfd_, EPOLL_CTL_DEL, f->sockfd, nullptr))
FLARE_LOG_ERROR_EVERY_SECOND("EPOLL_CTL_DEL failed for fd: %d : %s\n",
f->sockfd, strerror(errno));
}
delete f;
}
}
int SockCallback(CURL* e, curl_socket_t s, int what, void* cbp, void* sockp) {
CurlClient* g = reinterpret_cast<CurlClient*>(cbp);
SockInfo* fdp = reinterpret_cast<SockInfo*>(sockp);
const char* whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"};
FLARE_VLOG(100, "socket callback: s={} e={} what={} ", s, e, whatstr[what]);
if (what == CURL_POLL_REMOVE) {
RemoveSock(fdp, g);
} else {
if (!fdp) {
SockInfo* fdp = new SockInfo;
fdp->sockfd = 0;
SetSock(fdp, s, e, what, g);
curl_multi_assign(g->multi_handle_, s, fdp);
} else {
SetSock(fdp, s, e, what, g);
}
}
return 0;
}
size_t HttpWriteCallback(char* ptr, size_t size, size_t nmemb, void* pstr) {
auto bytes = size * nmemb;
static_cast<flare::NoncontiguousBufferBuilder*>(pstr)->Append(ptr, bytes);
return bytes;
}
// The header callback will be called once for each header and
// only complete header lines are passed on to the callback.
// Parsing headers is very easy using this.
size_t HttpHeaderCallback(char* ptr, size_t size, size_t nmemb, void* pstr) {
std::size_t bytes = size * nmemb;
std::string_view s(ptr, bytes);
if (s.find_first_of(':') == std::string_view::npos) { // Status-Line.
return bytes;
}
if (s.size() > 2 && s[bytes - 2] == '\r' && s[bytes - 1] == '\n') {
s.remove_suffix(2);
}
static_cast<std::vector<std::string>*>(pstr)->emplace_back(s);
return bytes;
}
int HttpDebugCallback(CURL* handle, curl_infotype type, char* data, size_t size,
void* userptr) {
std::string_view data_view(data, size);
if (type == CURLINFO_TEXT || type == CURLINFO_HEADER_IN ||
type == CURLINFO_HEADER_OUT) {
FLARE_LOG_INFO("[{}] {}", type, data_view);
} else if (type == CURLINFO_DATA_IN || type == CURLINFO_DATA_OUT) {
if (FLAGS_flare_http_engine_enable_debug_body) {
FLARE_LOG_INFO("[{}] {}", type, data_view);
} // Ignored otherwise.
} // Everything else is ignored.
return 0;
}
HttpEngine* HttpEngine::Instance() {
static NeverDestroyedSingleton<HttpEngine> engine;
return engine.Get();
}
void HttpEngine::StartTask(
HttpTask task, Function<void(Expected<HttpTaskCompletion, Status>)> done) {
auto ctx = task.ctx_.Get();
ctx->hdrs = std::move(task.hdrs_);
if (FLAGS_flare_http_engine_enable_debug) {
FLARE_CHECK_EQ(CURLE_OK,
curl_easy_setopt(ctx->curl_handler, CURLOPT_DEBUGFUNCTION,
HttpDebugCallback));
FLARE_CHECK_EQ(CURLE_OK,
curl_easy_setopt(ctx->curl_handler, CURLOPT_VERBOSE, 1));
}
FLARE_CHECK_EQ(CURLE_OK,
curl_easy_setopt(ctx->curl_handler, CURLOPT_NOSIGNAL, 1));
FLARE_CHECK_EQ(CURLE_OK,
curl_easy_setopt(ctx->curl_handler, CURLOPT_WRITEFUNCTION,
HttpWriteCallback));
ctx->body = std::make_unique<NoncontiguousBufferBuilder>();
FLARE_CHECK_EQ(
CURLE_OK,
curl_easy_setopt(ctx->curl_handler, CURLOPT_WRITEDATA, ctx->body.get()));
FLARE_CHECK_EQ(CURLE_OK,
curl_easy_setopt(ctx->curl_handler, CURLOPT_HEADERFUNCTION,
HttpHeaderCallback));
FLARE_CHECK_EQ(CURLE_OK, curl_easy_setopt(ctx->curl_handler,
CURLOPT_HEADERDATA, &ctx->headers));
FLARE_CHECK_EQ(
CURLE_OK,
curl_easy_setopt(ctx->curl_handler, CURLOPT_HTTPHEADER, ctx->hdrs.get()));
ctx->done = std::move(done);
auto c = curl_client_groups[fiber::GetCurrentSchedulingGroupIndex()].get();
c->PushContext(std::move(task.ctx_));
}
void HttpEngine::Stop() {
for (auto&& c : curl_client_groups) {
c->Stop();
}
}
void HttpEngine::Join() {
for (auto&& c : curl_client_groups) {
c.reset();
}
curl_global_cleanup();
}
HttpEngine::HttpEngine() {
auto ret = curl_global_init(CURL_GLOBAL_DEFAULT);
FLARE_CHECK(!ret, "Curl Init failed {}", ret);
for (auto i = 0; i < fiber::GetSchedulingGroupCount(); ++i) {
curl_client_groups.push_back(std::make_unique<CurlClientGroup>(
FLAGS_flare_http_engine_workers_per_scheduling_group, i));
}
}
} // namespace internal
} // namespace flare
|
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include "conanhelper.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
qmlRegisterType<ConanHelper>("ConanHelperBinding", 1, 0, "ConanHelperBinding");
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
|
; CRT0 stub for 64k adam
INCLUDE "target/coleco/def/eos.def"
EXTERN msx_set_mode
defc TAR__register_sp = 0xd390
defc TAR__clib_exit_stack_size = 32
defc TAR__fputc_cons_generic = 1
; No interrupts registered
defc TAR__crt_enable_rst = $0000
IFNDEF CRT_ENABLE_NMI
defc TAR__crt_enable_nmi = 1
defc _z80_nmi = nmi_handler
ENDIF
defc CRT_ORG_CODE = 0
EXTERN nmi_vectors
EXTERN asm_interrupt_handler
INCLUDE "crt/classic/crt_rules.inc"
org CRT_ORG_CODE
jp program
INCLUDE "crt/classic/crt_z80_rsts.asm"
program:
; Make room for the atexit() stack
INCLUDE "crt/classic/crt_init_sp.asm"
INCLUDE "crt/classic/crt_init_atexit.asm"
call crt0_init_bss
ld (exitsp),sp
ld hl,2
call msx_set_mode
IF DEFINED_USING_amalloc
INCLUDE "crt/classic/crt_init_amalloc.asm"
ENDIF
; Entry to the user code
call _main
cleanup:
call crt0_exit
endloop:
jr endloop
l_dcal:
jp (hl)
IF (__crt_enable_nmi <= 1)
nmi_handler:
push af
push hl
ld a,(__vdp_enable_status)
rlca
jr c,no_vbl
in a,(VDP_STATUS)
ld (__tms9918_status_register),a
no_vbl:
ld hl,nmi_vectors
call asm_interrupt_handler
pop hl
pop af
retn
ENDIF
; We're not using that much from EOS, so put these here
; until we've got more functionality that should go into
; a library
PUBLIC fgetc_cons
PUBLIC _fgetc_cons
fgetc_cons:
_fgetc_cons:
call ReadKeyboard
jr nz,fgetc_cons
ld l,a
ld h,0
cp 13
ret nz
ld l,10
ret
; msxbios is a noop
msxbios:
ret
INCLUDE "crt/classic/crt_runtime_selection.asm"
INCLUDE "crt/classic/crt_section.asm"
; Include the IPL bootstrap code
INCLUDE "target/coleco/classic/adam_bootstrap.asm"
|
#include "prog3.h"
#include <iostream>
#include <string.h>
// constructor
Student::Student(char *sn,char *cn) {
int n = strlen(sn);
school_name = new char[n+1];
strcpy(school_name,sn);
n = strlen(cn);
class_name = new char[n+1];
strcpy(class_name,cn);
}
// 顯示
void Student::show() {
std::cout << "\n學校名稱->" << school_name;
std::cout << "\n班級名稱->" << class_name;
}
// constructor:成員串列初設
Score::Score(char *s_n,char *c_n):Student(s_n,c_n) {
std::cout << "\n輸入...." ;
Student::show();
std::cout << "\n中文成績:";
std::cin >> Chinese;
std::cout << "數學成績:";
std::cin >> Math;
std::cout << "英文成績:";
std::cin >> English;
}
// constructor:成員串列初設
Score::Score(char *s_n,char *c_n,int c,int m,int e):Student(s_n,c_n) {
Chinese = c;
Math = m;
English = e;
}
// 顯示
void Score::show() {
std::cout << "\n顯示...." ;
Student::show();
std::cout << "\n中文成績:" << Chinese;
std::cout << "\n數學成績:" << Math;
std::cout << "\n英文成績:" << English;
}
|
object_const_def ; object_event constants
const PLAYERSHOUSE1F_MOM1
const PLAYERSHOUSE1F_MOM2
const PLAYERSHOUSE1F_MOM3
const PLAYERSHOUSE1F_MOM4
const PLAYERSHOUSE1F_POKEFAN_F
PlayersHouse1F_MapScripts:
db 2 ; scene scripts
scene_script .DummyScene0 ; SCENE_DEFAULT
scene_script .DummyScene1 ; SCENE_FINISHED
db 0 ; callbacks
.DummyScene0:
end
.DummyScene1:
end
MeetMomLeftScript:
setevent EVENT_TEMPORARY_UNTIL_MAP_RELOAD_1
MeetMomRightScript:
playmusic MUSIC_MOM
showemote EMOTE_SHOCK, PLAYERSHOUSE1F_MOM1, 15
turnobject PLAYER, LEFT
checkevent EVENT_TEMPORARY_UNTIL_MAP_RELOAD_1
iffalse .OnRight
applymovement PLAYERSHOUSE1F_MOM1, MomTurnsTowardPlayerMovement
sjump MeetMomScript
.OnRight:
applymovement PLAYERSHOUSE1F_MOM1, MomWalksToPlayerMovement
MeetMomScript:
opentext
writetext ElmsLookingForYouText
buttonsound
getstring STRING_BUFFER_4, GearName
scall PlayersHouse1FReceiveItemStd
setflag ENGINE_POKEGEAR
setflag ENGINE_PHONE_CARD
addcellnum PHONE_MOM
setscene SCENE_FINISHED
setevent EVENT_PLAYERS_HOUSE_MOM_1
clearevent EVENT_PLAYERS_HOUSE_MOM_2
writetext MomGivesPokegearText
buttonsound
special InitialSetDSTFlag
.SetDayOfWeek:
writetext IsItDSTText
yesorno
iffalse .WrongDay
special InitialSetDSTFlag
yesorno
iffalse .SetDayOfWeek
sjump .DayOfWeekDone
.WrongDay:
special InitialClearDSTFlag
yesorno
iffalse .SetDayOfWeek
.DayOfWeekDone:
writetext ComeHomeForDSTText
yesorno
iffalse .ExplainPhone
sjump .KnowPhone
.KnowPhone:
writetext KnowTheInstructionsText
buttonsound
sjump .FinishPhone
.ExplainPhone:
writetext DontKnowTheInstructionsText
buttonsound
sjump .FinishPhone
.FinishPhone:
writetext InstructionsNextText
waitbutton
closetext
checkevent EVENT_TEMPORARY_UNTIL_MAP_RELOAD_1
iftrue .FromRight
checkevent EVENT_TEMPORARY_UNTIL_MAP_RELOAD_2
iffalse .FromLeft
sjump .Finish
.FromRight:
applymovement PLAYERSHOUSE1F_MOM1, MomTurnsBackMovement
sjump .Finish
.FromLeft:
applymovement PLAYERSHOUSE1F_MOM1, MomWalksBackMovement
sjump .Finish
.Finish:
special RestartMapMusic
turnobject PLAYERSHOUSE1F_MOM1, LEFT
end
MeetMomTalkedScript:
playmusic MUSIC_MOM
sjump MeetMomScript
GearName:
db "#GEAR@"
PlayersHouse1FReceiveItemStd:
jumpstd receiveitem
end
MomScript:
faceplayer
setevent EVENT_TEMPORARY_UNTIL_MAP_RELOAD_2
checkscene
iffalse MeetMomTalkedScript ; SCENE_DEFAULT
opentext
checkevent EVENT_FIRST_TIME_BANKING_WITH_MOM
iftrue .FirstTimeBanking
checkevent EVENT_TALKED_TO_MOM_AFTER_MYSTERY_EGG_QUEST
iftrue .BankOfMom
checkevent EVENT_GAVE_MYSTERY_EGG_TO_ELM
iftrue .GaveMysteryEgg
checkevent EVENT_GOT_A_POKEMON_FROM_ELM
iftrue .GotAPokemon
writetext HurryUpElmIsWaitingText
waitbutton
closetext
end
.GotAPokemon:
writetext SoWhatWasProfElmsErrandText
waitbutton
closetext
end
.FirstTimeBanking:
writetext ImBehindYouText
waitbutton
closetext
end
.GaveMysteryEgg:
setevent EVENT_FIRST_TIME_BANKING_WITH_MOM
.BankOfMom:
setevent EVENT_TALKED_TO_MOM_AFTER_MYSTERY_EGG_QUEST
special BankOfMom
waitbutton
closetext
end
NeighborScript:
faceplayer
opentext
checktime MORN
iftrue .MornScript
checktime DAY
iftrue .DayScript
checktime NITE
iftrue .NiteScript
.MornScript:
writetext NeighborMornIntroText
buttonsound
sjump .Main
.DayScript:
writetext NeighborDayIntroText
buttonsound
sjump .Main
.NiteScript:
writetext NeighborNiteIntroText
buttonsound
sjump .Main
.Main:
writetext NeighborText
waitbutton
closetext
turnobject PLAYERSHOUSE1F_POKEFAN_F, RIGHT
end
TVScript:
jumptext TVText
StoveScript:
jumptext StoveText
SinkScript:
jumptext SinkText
FridgeScript:
jumptext FridgeText
MomTurnsTowardPlayerMovement:
turn_head RIGHT
step_end
MomWalksToPlayerMovement:
slow_step RIGHT
step_end
MomTurnsBackMovement:
turn_head LEFT
step_end
MomWalksBackMovement:
slow_step LEFT
step_end
ElmsLookingForYouText:
text "Oh, <PLAYER>…! Our"
line "neighbor, PROF."
para "ELM, was looking"
line "for you."
para "He said he wanted"
line "you to do some-"
cont "thing for him."
para "Oh! I almost for-"
line "got! Your #MON"
para "GEAR is back from"
line "the repair shop."
para "Here you go!"
done
MomGivesPokegearText:
text "#MON GEAR, or"
line "just #GEAR."
para "It's essential if"
line "you want to be a"
cont "good trainer."
para "Oh, there's one"
line "thing I forgot to"
para "ask you!"
para "Can you please set"
line "your #GEAR"
para "for Daylight"
line "Saving Time?"
done
IsItDSTText:
text "Is it Daylight"
line "Saving Time now?"
done
ComeHomeForDSTText:
text "Come home to"
line "adjust your clock"
para "for Daylight"
line "Saving Time."
para "By the way, do you"
line "know how to use"
cont "the PHONE?"
done
KnowTheInstructionsText:
text "Don't you just"
line "turn the #GEAR"
para "on and select the"
line "PHONE icon?"
done
DontKnowTheInstructionsText:
text "I'll read the"
line "instructions."
para "Turn the #GEAR"
line "on and select the"
cont "PHONE icon."
done
InstructionsNextText:
text "Phone numbers are"
line "stored in memory."
para "Just choose a name"
line "you want to call."
para "Gee, isn't that"
line "convenient?"
done
HurryUpElmIsWaitingText:
text "PROF.ELM is wait-"
line "ing for you."
para "Hurry up, baby!"
done
SoWhatWasProfElmsErrandText:
text "So, what was PROF."
line "ELM's errand?"
para "…"
para "That does sound"
line "challenging."
para "But, you should be"
line "proud that people"
cont "rely on you."
done
ImBehindYouText:
text "<PLAYER>, do it!"
para "I'm behind you all"
line "the way!"
done
NeighborMornIntroText:
text "Good morning,"
line "<PLAY_G>!"
para "I'm visiting!"
done
NeighborDayIntroText:
text "Hello, <PLAY_G>!"
line "I'm visiting!"
done
NeighborNiteIntroText:
text "Good evening,"
line "<PLAY_G>!"
para "I'm visiting!"
done
NeighborText:
text "<PLAY_G>, have you"
line "heard?"
para "My daughter is"
line "adamant about"
para "becoming PROF."
line "ELM's assistant."
para "She really loves"
line "#MON!"
done
StoveText:
text "Mom's specialty!"
para "CINNABAR VOLCANO"
line "BURGER!"
done
SinkText:
text "The sink is spot-"
line "less. Mom likes it"
cont "clean."
done
FridgeText:
text "Let's see what's"
line "in the fridge…"
para "FRESH WATER and"
line "tasty LEMONADE!"
done
TVText:
text "There's a movie on"
line "TV: Stars dot the"
para "sky as two boys"
line "ride on a train…"
para "I'd better get"
line "rolling too!"
done
PlayersHouse1F_MapEvents:
db 0, 0 ; filler
db 3 ; warp events
warp_event 6, 7, NEW_BARK_TOWN, 2
warp_event 7, 7, NEW_BARK_TOWN, 2
warp_event 9, 0, PLAYERS_HOUSE_2F, 1
db 2 ; coord events
coord_event 8, 4, SCENE_DEFAULT, MeetMomLeftScript
coord_event 9, 4, SCENE_DEFAULT, MeetMomRightScript
db 4 ; bg events
bg_event 0, 1, BGEVENT_READ, StoveScript
bg_event 1, 1, BGEVENT_READ, SinkScript
bg_event 2, 1, BGEVENT_READ, FridgeScript
bg_event 4, 1, BGEVENT_READ, TVScript
db 5 ; object events
object_event 7, 4, SPRITE_MOM, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, MomScript, EVENT_PLAYERS_HOUSE_MOM_1
object_event 2, 2, SPRITE_MOM, SPRITEMOVEDATA_STANDING_UP, 0, 0, -1, MORN, 0, OBJECTTYPE_SCRIPT, 0, MomScript, EVENT_PLAYERS_HOUSE_MOM_2
object_event 7, 4, SPRITE_MOM, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, DAY, 0, OBJECTTYPE_SCRIPT, 0, MomScript, EVENT_PLAYERS_HOUSE_MOM_2
object_event 0, 2, SPRITE_MOM, SPRITEMOVEDATA_STANDING_UP, 0, 0, -1, NITE, 0, OBJECTTYPE_SCRIPT, 0, MomScript, EVENT_PLAYERS_HOUSE_MOM_2
object_event 4, 4, SPRITE_POKEFAN_F, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, NeighborScript, EVENT_PLAYERS_HOUSE_1F_NEIGHBOR
|
#include <jawt_md.h>
#include <X11/Xresource.h>
#include <stdint.h>
#include "jni_helpers.h"
#include "SkSurface.h"
#include "src/core/SkAutoMalloc.h"
class SoftwareDevice
{
public:
Display* display;
Window window;
GC gc;
sk_sp<SkSurface> surface;
unsigned int depth = 0;
SkColorType colorSpace = kUnknown_SkColorType;
void initDevice() {
Window wnd;
int x, y;
unsigned int w, h, border;
XGetGeometry(display, window, &wnd, &x, &y, &w, &h, &border, &depth);
switch(depth) {
case 16:
colorSpace = kRGB_565_SkColorType;
break;
case 24: case 32:
colorSpace = kBGRA_8888_SkColorType;
break;
default:
colorSpace = kUnknown_SkColorType;
}
}
~SoftwareDevice() {
if (display != NULL && gc != NULL)
{
XFreeGC(display, gc);
}
}
};
extern "C"
{
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_LinuxSoftwareRedrawer_createDevice(
JNIEnv *env, jobject redrawer, jlong displayPtr, jlong windowPtr, jint width, jint height)
{
Display *display = fromJavaPointer<Display *>(displayPtr);
Window window = fromJavaPointer<Window>(windowPtr);
SoftwareDevice *device = new SoftwareDevice();
device->display = display;
device->window = window;
device->gc = XCreateGC(device->display, device->window, 0, nullptr);
device->initDevice();
if (device->colorSpace == kUnknown_SkColorType)
{
return 0L;
}
device->surface.reset();
SkImageInfo info = SkImageInfo::Make(
width, height, device->colorSpace, kPremul_SkAlphaType,
SkColorSpace::MakeSRGB());
device->surface = SkSurface::MakeRaster(info);
return toJavaPointer(device);
}
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_AbstractDirectSoftwareRedrawer_resize(
JNIEnv *env, jobject redrawer, jlong devicePtr, jint width, jint height)
{
SoftwareDevice *device = fromJavaPointer<SoftwareDevice *>(devicePtr);
device->surface.reset();
SkImageInfo info = SkImageInfo::Make(
width, height, device->colorSpace, kPremul_SkAlphaType,
SkColorSpace::MakeSRGB());
device->surface = SkSurface::MakeRaster(info);
}
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_AbstractDirectSoftwareRedrawer_acquireSurface(
JNIEnv *env, jobject redrawer, jlong devicePtr)
{
SoftwareDevice *device = fromJavaPointer<SoftwareDevice *>(devicePtr);
return toJavaPointer(device->surface.release());
}
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_AbstractDirectSoftwareRedrawer_finishFrame(
JNIEnv *env, jobject redrawer, jlong devicePtr, jlong surfacePtr)
{
SoftwareDevice *device = fromJavaPointer<SoftwareDevice *>(devicePtr);
SkSurface *surface = fromJavaPointer<SkSurface *>(surfacePtr);
SkPixmap pm;
if (!surface->peekPixels(&pm)) {
return;
}
int bitsPerPixel = pm.info().bytesPerPixel() * 8;
XImage image;
memset(&image, 0, sizeof(image));
image.width = pm.width();
image.height = pm.height();
image.format = ZPixmap;
image.data = (char*) pm.addr();
image.byte_order = LSBFirst;
image.bitmap_unit = bitsPerPixel;
image.bitmap_bit_order = LSBFirst;
image.bitmap_pad = bitsPerPixel;
image.depth = device->depth;
image.bytes_per_line = pm.rowBytes() - pm.width() * pm.info().bytesPerPixel();
image.bits_per_pixel = bitsPerPixel;
if (!XInitImage(&image)) {
return;
}
XPutImage(device->display, device->window, device->gc, &image, 0, 0, 0, 0, pm.width(), pm.height());
}
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_AbstractDirectSoftwareRedrawer_disposeDevice(
JNIEnv *env, jobject redrawer, jlong devicePtr)
{
SoftwareDevice *device = fromJavaPointer<SoftwareDevice *>(devicePtr);
delete device;
}
}
|
/* Copyright 2015 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 <functional>
#include <memory>
#include <vector>
#include "tensorflow/core/common_runtime/kernel_benchmark_testlib.h"
#include "tensorflow/core/framework/allocator.h"
#include "tensorflow/core/framework/fake_input.h"
#include "tensorflow/core/framework/node_def_builder.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/kernels/ops_testutil.h"
#include "tensorflow/core/kernels/ops_util.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/test_benchmark.h"
namespace tensorflow {
class QuantizedReshapeTest : public OpsTestBase {
protected:
QuantizedReshapeTest() {}
};
TEST_F(QuantizedReshapeTest, Reshape) {
TF_ASSERT_OK(NodeDefBuilder("quantized_reshape", "QuantizedReshape")
.Input(FakeInput(DT_QUINT8))
.Input(FakeInput(DT_INT32))
.Input(FakeInput(DT_FLOAT))
.Input(FakeInput(DT_FLOAT))
.Finalize(node_def()));
TF_ASSERT_OK(InitOp());
Tensor input(DT_QUINT8, {10, 20});
Tensor expected(DT_QUINT8, {5, 10, 4});
for (int i = 0; i < input.shape().num_elements(); ++i) {
input.flat<quint8>()(i) = quint8(i);
expected.flat<quint8>()(i) = quint8(i);
}
AddInputFromArray<quint8>(input.shape(), input.flat<quint8>());
AddInputFromList<int32>({3}, {5, 10, 4}); // shape
AddInputFromArray<float>(TensorShape({1}), {-10});
AddInputFromArray<float>(TensorShape({1}), {20});
TF_ASSERT_OK(RunOpKernel());
EXPECT_EQ(-10, GetOutput(1)->flat<float>()(0));
EXPECT_EQ(20, GetOutput(2)->flat<float>()(0));
test::ExpectTensorEqual<quint8>(expected, *GetOutput(0));
}
} // namespace tensorflow
|
; A101859: a(n) = 11 + (23*n)/2 + n^2/2.
; Submitted by Christian Krause
; 0,11,23,36,50,65,81,98,116,135,155,176,198,221,245,270,296,323,351,380,410,441,473,506,540,575,611,648,686,725,765,806,848,891,935,980,1026,1073,1121,1170,1220,1271,1323,1376,1430,1485,1541,1598,1656,1715,1775,1836
add $0,11
bin $0,2
sub $0,55
|
; A076565: Greatest prime divisor of 2n+1 (sum of two successive integers).
; 3,5,7,3,11,13,5,17,19,7,23,5,3,29,31,11,7,37,13,41,43,5,47,7,17,53,11,19,59,61,7,13,67,23,71,73,5,11,79,3,83,17,29,89,13,31,19,97,11,101,103,7,107,109,37,113,23,13,17,11,41,5,127,43,131,19,5,137,139,47,13,29,7,149,151,17,31,157,53,23,163,11,167,13,19,173,7,59,179,181,61,37,17,7,191,193,13,197,199,67
add $0,1
lpb $0
mov $1,$0
seq $1,90368 ; a(1) = 1; for n>1, smallest divisor > 1 of 2n-1.
div $0,$1
lpe
mov $0,$1
|
#pragma once
#define NOMINMAX
#include "Plan.hpp"
namespace operations_research {
class PackingPlan : public Plan
{
public:
PackingPlan() {};
PackingPlan(int ws_id, std::string order_guid, int unit_id, std::vector<int> component_ids) : Plan(ws_id), OrderGuid(order_guid), ComponentIds(component_ids), UnitId(unit_id) {
ProdType = ProductionType::PACKING;
Name = "Packing-Plan</br>O-" + order_guid + "</br>U-" + std::to_string(unit_id);
};
~PackingPlan() {};
int EstimateTime(PackingWorkstation ws);
friend std::ostream& operator<< (std::ostream& out, const PackingPlan& plan);
std::string PrintHtml(sat::CpSolverResponse result, int minute_pixel_rate);
json ToJson(sat::CpSolverResponse result, int wsh, int shift_num, int shift_len);
std::string GetOrderId() { return OrderGuid; }
int GetUnitId() { return UnitId; }
std::vector<int> GetComponentId() { return ComponentIds; }
private:
std::string OrderGuid;
int UnitId;
std::vector<int> ComponentIds;
};
} |
; Multiplication function for field elements (integers modulo 2^255 - 19)
;
; Author: Daan Sprenkels <hello@dsprenkels.com>
%include "bench.asm"
%include "fe12_mul.mac"
extern crypto_scalarmult_curve13318_ref12_fe12x4_mul,
extern crypto_scalarmult_curve13318_ref12_fe12x4_squeeze
extern crypto_scalarmult_curve13318_ref12_fe12x4_squeeze_noload
extern crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba
extern crypto_scalarmult_curve13318_ref12_fe12_square_karatsuba
extern crypto_scalarmult_curve13318_ref12_fe12_squeeze
section .rodata
_bench1_name: db `ge_double_asm\0`
_bench2_name: db `ge_double_gcc\0`
_bench3_name: db `ge_double_clang\0`
_bench4_name: db `ge_double_asm_v2\0`
_bench5_name: db `ge_double_asm_v3\0`
_bench6_name: db `ge_double_asm_v4\0`
_bench7_name: db `ge_double_asm_v5\0`
_bench8_name: db `ge_double_asm_v6\0`
align 8, db 0
_bench_fns_arr:
dq ge_double_asm, ge_double_gcc, ge_double_clang, ge_double_asm_v2, ge_double_asm_v3, ge_double_asm_v4, ge_double_asm_v5, ge_double_asm_v6
_bench_names_arr:
dq _bench1_name, _bench2_name, _bench3_name, _bench4_name, _bench5_name, _bench6_name, _bench7_name, _bench8_name
_bench_fns: dq _bench_fns_arr
_bench_names: dq _bench_names_arr
_bench_fns_n: dd 8
section .bss
align 32
scratch_space: resb 1536
section .text
ge_double_asm:
; The next chain of procedures is an adapted version of Algorithm 6
; from the Renes-Costello-Batina addition laws. [Renes2016]
;
; fe12_squeeze guarantees that every processed double is always divisible
; by 2^k and bounded by 1.01 * 2^21 * 2^k, with k the limb's offset
; (0, 22, 43, etc.). This theorem (3.2) is proven in [Hash127] by Daniel
; Bernstein, although it needs to be adapted to this instance.
; Precondition of the theorem is that the input to fe12_squeeze is divisible
; by 2^k and bounded by 0.98 * 2^53 * 2^k.
;
; In other words: Any product limbs produced by fe12_mul (uncarried), must be
; bounded by ±0.98 * 2^53. In fe12_mul, the lowest limb is multiplied by the
; largest value, namely ±(11*19 + 1)*x*y = ±210*x*y for x the largest possible
; 22-bit limbs. This means that the summed limb bits of the 2 multiplied
; operands cannot exceed ±0.98 * 2^53 / 210. Rounded down this computes to
; ~±2^45.2 > ±1.1*2^45. So if we restrict ourselves to a multiplied upper bound
; of ±1.1*2^45, we should be all right.
;
; We would manage this by multiplying 2^21 values with 2^24 values
; (because 21 + 24 ≤ 45), but for example 2^23 * 2^23 is *forbidden* as it
; may overflow (23 + 23 > 45).
;
bench_prologue
%push ge_double_ctx
%define x3 rel scratch_space
%define y3 rel scratch_space + 12*8
%define z3 rel scratch_space + 24*8
%define x rel scratch_space + 36*8
%define y rel scratch_space + 48*8
%define z rel scratch_space + 60*8
%define t0 rsp
%define t1 rsp + 1*384
%define t2 rsp + 2*384
%define t3 rsp + 3*384
%define t4 rsp + 4*384
%define t5 rsp + 5*384
%define v11 rsp + 6*384
%define v34 rsp + 6*384 + 1*96
%define v26v30 rsp + 6*384 + 2*96
%define old_rdi rsp + 7*384
%define stack_size 7*384 + 32
; build stack frame
push rbp
mov rbp, rsp
and rsp, -32
sub rsp, (stack_size)
mov qword [old_rdi], rdi ; we are going to overwrite this during function calls
%assign i 0
%rep 12
vbroadcastsd ymm0, qword [x + i*8] ; [x, x, x, x]
vbroadcastsd ymm1, qword [y + i*8] ; [y, y, y, y]
vbroadcastsd ymm2, qword [z + i*8] ; [z, z, z, z]
vblendpd ymm3, ymm0, ymm2, 0b1100 ; [x, x, z, z]
vblendpd ymm4, ymm0, ymm2, 0b0110 ; [x, z, z, x]
vblendpd ymm4, ymm4, ymm1, 0b1000 ; [x, z, z, y]
vmovapd yword [t0 + i*32], ymm3
vmovapd yword [t1 + i*32], ymm4
; prepare for second mul
vmovapd oword [t3 + i*32], xmm1 ; t3 = [y, y, ??, ??]
vmovsd qword [t4 + i*32], xmm1 ; t4 = [y, ??, ??, ??]
vmovsd qword [t4 + i*32 + 8],xmm0 ; t4 = [y, x, ??, ??]
%assign i i+1
%endrep
lea rdi, [t2]
lea rsi, [t0]
lea rdx, [t1]
call crypto_scalarmult_curve13318_ref12_fe12x4_mul wrt ..plt
call crypto_scalarmult_curve13318_ref12_fe12x4_squeeze wrt ..plt
vmovapd ymm0, [rel .const_mulsmall]
%assign i 0
%rep 12
vmovapd ymm1, [t2 + 32*i] ; [v1, v6, v3, v28]
vpermilpd ymm2, ymm1, 0b0010 ; [v1, v6, v3, v3]
vmulpd ymm2, ymm2, ymm0 ; computing [v24, v18, v8, v17]
vextractf128 xmm3, ymm2, 0b1 ; [v8, v17]
vpermilpd xmm4, xmm3, 0b1 ; [v17, v8]
vaddsd xmm5, xmm2, xmm4 ; computing v25
vpermilpd xmm2, xmm2, 0b1 ; [v18, v24]
vaddsd xmm6, xmm2, xmm4 ; computing v19
vsubsd xmm6, xmm1, xmm6 ; computing v20
vmulsd xmm6, xmm6, [rel .const_neg3] ; computing v22
vpermilpd xmm1, xmm1, 0b1 ; [v6, v1]
vaddsd xmm7, xmm3, xmm1 ; computing v9
vmulsd xmm7, xmm7, [rel .const_neg6] ; computing v11
vmovsd qword [v11 + 8*i], xmm7 ; spill v11
vmovsd qword [t3 + i*32 + 16], xmm6 ; t3 = [y, y, v22, ??]
vmovsd qword [t3 + i*32 + 24], xmm6 ; t3 = [y, y, v22, v22]
vmovsd qword [t4 + i*32 + 16], xmm5 ; t4 = [y, x, v25, ??]
; put r29 in t4
vmovsd xmm8, qword [t2 + i*32 + 24]
vmulsd xmm9, xmm8, qword [rel .const_2] ; computing v29a
vmovsd qword [t4 + i*32 + 24], xmm9 ; t4 = [y, x, v25, v29a]
vmulsd xmm10, xmm8, qword [rel .const_8]; computing v34
vmovsd qword [v34 + i*8], xmm10 ; spill v34
%assign i i+1
%endrep
lea rdi, [t3]
call crypto_scalarmult_curve13318_ref12_fe12x4_squeeze wrt ..plt
lea rdi, [t4]
call crypto_scalarmult_curve13318_ref12_fe12x4_squeeze wrt ..plt
lea rdi, [t5]
lea rsi, [t3]
lea rdx, [t4]
call crypto_scalarmult_curve13318_ref12_fe12x4_mul wrt ..plt
call crypto_scalarmult_curve13318_ref12_fe12x4_squeeze wrt ..plt
; for the third batched multiplication we'll reuse {t0,t1,t2}
%assign i 0
%rep 12
vmovapd ymm0, [t5 + i*32] ; [v2, v4, v26, v30]
vmovsd xmm2, qword [v11 + i*8] ; v11
vsubsd xmm3, xmm0, xmm2 ; computing v12
vaddsd xmm4, xmm0, xmm2 ; computing v13
vpermilpd xmm5, xmm0, 0b1 ; [v4, v2]
vmulsd xmm5, xmm5, qword [rel .const_2] ; computing v5
vmovsd qword [t0 + 32*i], xmm3 ; t0 = [v12, ??, ??, ??]
vmovsd qword [t0 + 32*i + 8], xmm3 ; t0 = [v12, v12, ??, ??]
vmovsd qword [t0 + 32*i + 16], xmm0 ; t0 = [v12, v12, v2, ??]
vmovsd qword [t1 + 32*i], xmm5 ; t1 = [v5, ??, ??, ??]
vmovsd qword [t1 + 32*i + 8], xmm4 ; t1 = [v5, v13, ??, ??]
vmovsd xmm6, qword [v34 + i*8] ; reload v34
vmovsd qword [t1 + 32*i + 16], xmm6 ; t1 = [v5, v13, v34, ??]
vextractf128 xmm7, ymm0, 0b1 ; [v26, v30]
movapd oword [v26v30 + 16*i], xmm7 ; spill [v26, v30]
%assign i i+1
%endrep
lea rdi, [t0]
call crypto_scalarmult_curve13318_ref12_fe12x4_squeeze wrt ..plt
lea rdi, [t1]
call crypto_scalarmult_curve13318_ref12_fe12x4_squeeze wrt ..plt
lea rdi, [t2]
lea rsi, [t0]
lea rdx, [t1]
call crypto_scalarmult_curve13318_ref12_fe12x4_mul wrt ..plt
call crypto_scalarmult_curve13318_ref12_fe12x4_squeeze wrt ..plt
mov rdi, qword [old_rdi]
%assign i 0
%rep 12
vmovapd ymm0, [t2 + i*32] ; [v15, v14, v32, ??]
vpermilpd xmm1, xmm0, 0b1 ; [v14, v15]
vsubsd xmm2, xmm0, qword [v26v30 + 16*i + 8] ; v31
vaddsd xmm3, xmm1, qword [v26v30 + 16*i]; v27
vextractf128 xmm4, ymm0, 0b1 ; [v32, ??]
; save doubled point
vmovsd qword [x3 + 8*i], xmm2 ; store x3
vmovsd qword [y3 + 8*i], xmm3 ; store y3
vmovsd qword [z3 + 8*i], xmm4 ; store z3
%assign i i+1
%endrep
%pop ge_double_ctx
; restore stack frame
mov rsp, rbp
pop rbp
bench_epilogue
ret
section .rodata
.const_neg3: dq -3.0
.const_neg6: dq -6.0
.const_2: dq 2.0
.const_8: dq 8.0
align 32, db 0
.const_mulsmall: dq 3.0, 26636.0, -6659.0, -3.0
ge_double_asm_v2:
; The next chain of procedures is an adapted version of Algorithm 6
; from the Renes-Costello-Batina addition laws. [Renes2016]
;
; fe12_squeeze guarantees that every processed double is always divisible
; by 2^k and bounded by 1.01 * 2^21 * 2^k, with k the limb's offset
; (0, 22, 43, etc.). This theorem (3.2) is proven in [Hash127] by Daniel
; Bernstein, although it needs to be adapted to this instance.
; Precondition of the theorem is that the input to fe12_squeeze is divisible
; by 2^k and bounded by 0.98 * 2^53 * 2^k.
;
; In other words: Any product limbs produced by fe12_mul (uncarried), must be
; bounded by ±0.98 * 2^53. In fe12_mul, the lowest limb is multiplied by the
; largest value, namely ±(11*19 + 1)*x*y = ±210*x*y for x the largest possible
; 22-bit limbs. This means that the summed limb bits of the 2 multiplied
; operands cannot exceed ±0.98 * 2^53 / 210. Rounded down this computes to
; ~±2^45.2 > ±1.1*2^45. So if we restrict ourselves to a multiplied upper bound
; of ±1.1*2^45, we should be all right.
;
; We would manage this by multiplying 2^21 values with 2^24 values
; (because 21 + 24 ≤ 45), but for example 2^23 * 2^23 is *forbidden* as it
; may overflow (23 + 23 > 45).
;
bench_prologue
%push ge_double_ctx
%xdefine x3 rel scratch_space
%xdefine y3 rel scratch_space + 12*8
%xdefine z3 rel scratch_space + 24*8
%xdefine x rel scratch_space + 36*8
%xdefine y rel scratch_space + 48*8
%xdefine z rel scratch_space + 60*8
%xdefine t0 rsp
%xdefine t1 rsp + 1*384
%xdefine t2 rsp + 2*384
%xdefine t3 rsp + 3*384
%xdefine t4 rsp + 4*384
%xdefine t5 rsp + 5*384
%xdefine v11 rsp + 6*384
%xdefine v34 rsp + 6*384 + 1*96
%xdefine v26v30 rsp + 6*384 + 2*96
%xdefine old_rdi rsp + 7*384
%xdefine scratch rsp + 7*384 + 32
%xdefine stack_size 7*384 + 32 + 768
; build stack frame
push rbp
mov rbp, rsp
and rsp, -32
sub rsp, stack_size
mov qword [old_rdi], rdi ; we are going to overwrite this during function calls
%assign i 0
%rep 12
vbroadcastsd ymm0, qword [x + i*8] ; [x, x, x, x]
vbroadcastsd ymm1, qword [y + i*8] ; [y, y, y, y]
vbroadcastsd ymm2, qword [z + i*8] ; [z, z, z, z]
vblendpd ymm3, ymm0, ymm2, 0b1100 ; [x, x, z, z]
vblendpd ymm4, ymm0, ymm2, 0b0110 ; [x, z, z, x]
vblendpd ymm4, ymm4, ymm1, 0b1000 ; [x, z, z, y]
vmovapd yword [t0 + i*32], ymm3
vmovapd yword [t1 + i*32], ymm4
; prepare for second mul
vmovapd oword [t3 + i*32], xmm1 ; t3 = [y, y, ??, ??]
vmovsd qword [t4 + i*32], xmm1 ; t4 = [y, ??, ??, ??]
vmovsd qword [t4 + i*32 + 8],xmm0 ; t4 = [y, x, ??, ??]
%assign i i+1
%endrep
fe12x4_mul t2, t0, t1, scratch
; t2 is now in ymm{0-11}
vmovapd ymm12, [rel .const_mulsmall]
%assign i 0
%rep 12
vpermilpd ymm13, ymm%[i], 0b0010 ; [v1, v6, v3, v3]
vmulpd ymm%[i], ymm13, ymm12 ; computing [v24, v18, v8, v17]
%assign i i+1
%endrep
fe12x4_squeeze_body
%assign i 0
%rep 12
vextractf128 xmm12, ymm%[i], 0b1 ; [v8, v17]
vpermilpd xmm13, xmm12, 0b1 ; [v17, v8]
vaddsd xmm14, xmm%[i], xmm13 ; computing v25
vmovsd qword [t4 + i*32 + 16], xmm14 ; t4 = [y, x, v25, ??]
vpermilpd xmm%[i], xmm%[i], 0b1 ; [v18, v24]
vaddsd xmm13, xmm%[i], xmm13 ; computing v19
vmovapd xmm14, oword [t2 + i*32] ; [v1, v6]
vsubsd xmm13, xmm14, xmm13 ; computing v20
vmulsd xmm13, xmm13, [rel .const_neg3] ; computing v22
vmovsd qword [t3 + i*32 + 16], xmm13 ; t3 = [y, y, v22, ??]
vmovsd qword [t3 + i*32 + 24], xmm13 ; t3 = [y, y, v22, v22]
vpermilpd xmm14, xmm14, 0b1 ; [v6, v1]
vaddsd xmm12, xmm12, xmm14 ; computing v9
vmulsd xmm12, xmm12, [rel .const_neg6] ; computing v11
vmovsd qword [v11 + 8*i], xmm12 ; spill v11
; put r29 in t4
vmovsd xmm12, qword [t2 + i*32 + 24] ; [v28]
vmulsd xmm13, xmm12, qword [rel .const_2] ; computing v29a
vmovsd qword [t4 + i*32 + 24], xmm13 ; t4 = [y, x, v25, v29a]
vmulsd xmm12, xmm12, qword [rel .const_8] ; computing v34
vmovsd qword [v34 + i*8], xmm12 ; spill v34
%assign i i+1
%endrep
fe12x4_squeeze t3
fe12x4_squeeze t4
fe12x4_mul t5, t3, t4, scratch
; for the third batched multiplication we'll reuse {t0,t1,t2}
%assign i 0
%rep 12
vmovapd ymm0, [t5 + i*32] ; [v2, v4, v26, v30]
vmovsd xmm2, qword [v11 + i*8] ; v11
vsubsd xmm3, xmm0, xmm2 ; computing v12
vaddsd xmm4, xmm0, xmm2 ; computing v13
vpermilpd xmm5, xmm0, 0b1 ; [v4, v2]
vmulsd xmm5, xmm5, qword [rel .const_2] ; computing v5
vmovsd qword [t0 + 32*i], xmm3 ; t0 = [v12, ??, ??, ??]
vmovsd qword [t0 + 32*i + 8], xmm3 ; t0 = [v12, v12, ??, ??]
vmovsd qword [t0 + 32*i + 16], xmm0 ; t0 = [v12, v12, v2, ??]
vmovsd qword [t1 + 32*i], xmm5 ; t1 = [v5, ??, ??, ??]
vmovsd qword [t1 + 32*i + 8], xmm4 ; t1 = [v5, v13, ??, ??]
vmovsd xmm6, qword [v34 + i*8] ; reload v34
vmovsd qword [t1 + 32*i + 16], xmm6 ; t1 = [v5, v13, v34, ??]
vextractf128 xmm7, ymm0, 0b1 ; [v26, v30]
vmovapd oword [v26v30 + 16*i], xmm7 ; spill [v26, v30]
%assign i i+1
%endrep
fe12x4_squeeze t0
fe12x4_squeeze t1
fe12x4_mul t2, t0, t1, scratch
mov rdi, qword [old_rdi]
%assign i 0
%rep 12
vmovapd ymm0, [t2 + i*32] ; [v15, v14, v32, ??]
vpermilpd xmm1, xmm0, 0b1 ; [v14, v15]
vsubsd xmm2, xmm0, qword [v26v30 + 16*i + 8] ; v31
vaddsd xmm3, xmm1, qword [v26v30 + 16*i]; v27
vextractf128 xmm4, ymm0, 0b1 ; [v32, ??]
; save doubled point
vmovsd qword [x3 + 8*i], xmm2 ; store x3
vmovsd qword [y3 + 8*i], xmm3 ; store y3
vmovsd qword [z3 + 8*i], xmm4 ; store z3
%assign i i+1
%endrep
%pop ge_double_ctx
; restore stack frame
mov rsp, rbp
pop rbp
bench_epilogue
ret
section .rodata
.const_neg3: dq -3.0
.const_neg6: dq -6.0
.const_2: dq 2.0
.const_8: dq 8.0
align 32, db 0
.const_mulsmall: dq 3.0, 26636.0, -6659.0, -3.0
fe12x4_mul_consts
fe12x4_squeeze_consts
ge_double_asm_v3:
bench_prologue
%push ge_double_ctx
%xdefine x3 rel scratch_space
%xdefine y3 rel scratch_space + 12*8
%xdefine z3 rel scratch_space + 24*8
%xdefine x rel scratch_space + 36*8
%xdefine y rel scratch_space + 48*8
%xdefine z rel scratch_space + 60*8
%xdefine t0 rsp
%xdefine t1 rsp + 1*384
%xdefine t2 rsp + 2*384
%xdefine t3 rsp + 3*384
%xdefine t4 rsp + 4*384
%xdefine t5 rsp + 5*384
%xdefine v11v34 rsp + 6*384
%xdefine old_rdi rsp + 6*384 + 192
%xdefine scratch rsp + 6*384 + 256
%xdefine stack_size 6*384 + 256 + 768
; build stack frame
push rbp
mov rbp, rsp
and rsp, -32
sub rsp, stack_size
mov qword [old_rdi], rdi ; we are going to overwrite this during function calls
; assume forall v in {x, y, z} : |v| ≤ 1.01 * 2^22
vxorpd xmm15, xmm15, xmm15 ; [0, 0]
%assign i 0
%rep 12
vbroadcastsd ymm0, qword [x + i*8] ; [x, x, x, x]
vbroadcastsd ymm1, qword [y + i*8] ; [y, y, y, y]
vbroadcastsd ymm2, qword [z + i*8] ; [z, z, z, z]
vblendpd ymm3, ymm0, ymm2, 0b1100 ; [x, x, z, z]
vblendpd ymm4, ymm0, ymm2, 0b0110 ; [x, z, z, x]
vblendpd ymm4, ymm4, ymm1, 0b1000 ; [x, z, z, y]
vmovapd yword [t0 + i*32], ymm3
vmovapd yword [t1 + i*32], ymm4
; prepare for second mul
vblendpd xmm5, xmm0, xmm1, 0b01 ; [y, x]
vblendpd xmm6, xmm15, xmm0, 0b10 ; [0, x]
vaddpd xmm5, xmm5, xmm6 ; [y, 2*x]
vmovapd oword [t3 + i*32 + 16], xmm1 ; t3 = [??, ??, y, y]
vmovapd oword [t4 + i*32 + 16], xmm5 ; t4 = [??, ??, y, 2*x]
%assign i i+1
%endrep
fe12x4_mul t2, t0, t1, scratch ; computing [v1, v6, v3, v28] ≤ 1.01 * 2^21
; t2 is now in ymm{0-11}
vmovapd ymm12, [rel .const_mulsmall]
%assign i 0
%rep 12
vpermilpd ymm13, ymm%[i], 0b0010 ; [v1, v6, v3, v3]
vmulpd ymm%[i], ymm13, ymm12 ; computing [v24, v18, v8, v17]
; |v24| ≤ 1.52 * 2^22
; |v18| ≤ 1.65 * 2^35
; |v8| ≤ 1.65 * 2^33
; |v17| ≤ 1.52 * 2^22
%assign i i+1
%endrep
%assign i 0
%rep 12
vextractf128 xmm12, ymm%[i], 0b1 ; [v8, v17]
vpermilpd xmm13, xmm12, 0b1 ; [v17, v8]
vaddsd xmm14, xmm%[i], xmm13 ; computing v25 : |v25| ≤ 1.52 * 2^23
vpermilpd xmm%[i], xmm%[i], 0b1 ; [v18, v24]
vaddsd xmm13, xmm%[i], xmm13 ; computing v19 : |v19| ≤ 1.66 * 2^35
vmovapd xmm15, oword [t2 + i*32] ; [v1, v6]
vsubsd xmm13, xmm15, xmm13 ; computing v20 : |v20| ≤ 1.67 * 2^35
vmulsd xmm13, xmm13, qword [rel .const_neg3]; computing v22 : |v20| ≤ 1.26 * 2^37
vunpcklpd xmm13, xmm13, xmm14 ; [v22, v25]
vpermilpd xmm15, xmm15, 0b1 ; [v6, v1]
vaddsd xmm14, xmm12, xmm15 ; computing v9 : |v9| ≤ 1.66 * 2^33
vmulsd xmm14, xmm14, qword [rel .const_neg6]; computing v11 : |v11| ≤ 1.25 * 2^36
vmovsd xmm12, qword [t2 + 32*i + 24] ; reload v28
; TODO(dsprenkels) Left here, was recomputing bounds; need graph sheet
vmulsd xmm12, xmm12, qword [rel .const_8] ; computing v34 : |v34| ≤ 1.01 * 2^24
vunpcklpd xmm12, xmm14, xmm12 ; [v11, v34]
vinsertf128 ymm%[i], ymm12, xmm13, 0b1 ; [v11, v34, v22, v25]
%assign i i+1
%endrep
fe12x4_squeeze_body ; squeezing [v11, v34, v22, v25] ≤ 1.01 * 2^21
%assign i 0
%rep 12
vmovapd oword [v11v34 + 16*i], xmm%[i] ; spill [v11, v34]
vextractf128 xmm12, ymm%[i], 0b1 ; [v22, v25]
vmovddup xmm13, xmm12 ; [v22, v22]
vmovapd oword [t3 + i*32], xmm13 ; t3 = [v22, v22, y, y]
vmovsd xmm14, qword [t2 + i*32 + 24] ; [v28]
; TODO(dsprenkels) We can maybe optimise the next op with a blend from 0,t2 and a vaddpd
vaddsd xmm14, xmm14, xmm14 ; computing v29a : |v29a| ≤ 1.01 * 2^22
vblendpd xmm12, xmm12, xmm14, 0b01 ; [v29a, v25]
vmovapd oword [t4 + i*32], xmm12 ; t4 = [v29a, v25, y, 2*x]
%assign i i+1
%endrep
fe12x4_mul t5, t3, t4, scratch ; computing [v30, v26, v2, v5] ≤ 1.01 * 2^21
; for the third batched multiplication we'll reuse {t0,t1,t2}
%assign i 0
%rep 12
; TODO(dsprenkels) Eliminate this load (?):
vmovapd xmm0, oword [t5 + i*32 + 16] ; [v2, v5]
vmovsd xmm1, qword [v11v34 + i*16] ; v11
vsubsd xmm2, xmm0, xmm1 ; computing v12 : |v12| ≤ 1.01 * 2^22
vaddsd xmm3, xmm0, xmm1 ; computing v13 : |v13| ≤ 1.01 * 2^22
vmovapd oword [t0 + 32*i], xmm0 ; t0 = [v2, v5, ??, ??]
vmovsd qword [t0 + 32*i + 16], xmm2 ; t0 = [v2, v5, v12, ??]
vmovsd xmm4, qword [v11v34 + i*16 + 8] ; reload v34
vmovsd qword [t1 + 32*i], xmm4 ; t1 = [v34, ??, ??, ??]
vmovsd qword [t1 + 32*i + 8], xmm2 ; t1 = [v34, v12, ??, ??]
vmovsd qword [t1 + 32*i + 16], xmm3 ; t1 = [v34, v12, v13, ??]
%assign i i+1
%endrep
fe12x4_mul t2, t0, t1, scratch ; computing [v32, v15, v14, ??]
mov rdi, qword [old_rdi]
%assign i 0
%rep 12
; TODO(dsprenkels) Eliminate these loads:
vmovsd xmm0, qword [t2 + 32*i] ; v32
vmovsd xmm1, qword [t2 + 32*i + 8] ; v15
vmovsd xmm2, qword [t2 + 32*i + 16] ; v14
vsubsd xmm1, xmm1, qword [t5 + 32*i] ; computing v31 : |v31| ≤ 1.01 * 2^22
vaddsd xmm2, xmm2, qword [t5 + 32*i + 8] ; computing v27 : |v27| ≤ 1.01 * 2^22
; save doubled point
vmovsd qword [x3 + 8*i], xmm1 ; store x3
vmovsd qword [y3 + 8*i], xmm2 ; store y3
vmovsd qword [z3 + 8*i], xmm0 ; store z3
%assign i i+1
%endrep
%pop ge_double_ctx
; restore stack frame
mov rsp, rbp
pop rbp
bench_epilogue
ret
section .rodata
fe12x4_mul_consts
fe12x4_squeeze_consts
align 32, db 0
.const_mulsmall: dq 3.0, 26636.0, -6659.0, -3.0
align 4, db 0
.const_neg3: dq -3.0
.const_neg6: dq -6.0
.const_8: dq 8.0
ge_double_asm_v4:
bench_prologue
%push ge_double_ctx
%xdefine x3 rel scratch_space
%xdefine y3 rel scratch_space + 12*8
%xdefine z3 rel scratch_space + 24*8
%xdefine x rel scratch_space + 36*8
%xdefine y rel scratch_space + 48*8
%xdefine z rel scratch_space + 60*8
%xdefine t0 rsp
%xdefine t1 rsp + 1*384
%xdefine t2 rsp + 2*384
%xdefine t3 rsp + 3*384
%xdefine t4 rsp + 4*384
%xdefine t5 rsp + 5*384
%xdefine v11v34 rsp + 6*384
%xdefine old_rdi rsp + 6*384 + 192
%xdefine scratch rsp + 6*384 + 256
%xdefine stack_size 6*384 + 256 + 768
; build stack frame
push rbp
mov rbp, rsp
and rsp, -32
sub rsp, stack_size
mov qword [old_rdi], rdi ; we are going to overwrite this during function calls
; assume forall v in {x, y, z} : |v| ≤ 1.01 * 2^22
vxorpd xmm15, xmm15, xmm15 ; [0, 0]
%assign i 0
%rep 12
vbroadcastsd ymm0, qword [x + i*8] ; [x, x, x, x]
vbroadcastsd ymm1, qword [y + i*8] ; [y, y, y, y]
vbroadcastsd ymm2, qword [z + i*8] ; [z, z, z, z]
vblendpd ymm3, ymm0, ymm2, 0b1100 ; [x, x, z, z]
vblendpd ymm4, ymm0, ymm2, 0b0110 ; [x, z, z, x]
vblendpd ymm4, ymm4, ymm1, 0b1000 ; [x, z, z, y]
vmovapd yword [t0 + i*32], ymm3
vmovapd yword [t1 + i*32], ymm4
; prepare for second mul
vblendpd xmm5, xmm0, xmm1, 0b01 ; [y, x]
vblendpd xmm6, xmm15, xmm0, 0b10 ; [0, x]
vaddpd xmm5, xmm5, xmm6 ; [y, 2*x]
vmovapd oword [t3 + i*32 + 16], xmm1 ; t3 = [??, ??, y, y]
vmovapd oword [t4 + i*32 + 16], xmm5 ; t4 = [??, ??, y, 2*x]
%assign i i+1
%endrep
fe12x4_mul t2, t0, t1, scratch ; computing [v1, v6, v3, v28] ≤ 1.01 * 2^21
; t2 is now in ymm{0-11}
vmovapd ymm12, [rel .const_mulsmall]
%assign i 0
%rep 12
vpermilpd ymm13, ymm%[i], 0b0010 ; [v1, v6, v3, v3]
vmulpd ymm%[i], ymm13, ymm12 ; computing [v24, v18, v8, v17]
; |v24| ≤ 1.52 * 2^22
; |v18| ≤ 1.65 * 2^35
; |v8| ≤ 1.65 * 2^33
; |v17| ≤ 1.52 * 2^22
%assign i i+1
%endrep
%assign i 0
%rep 12
vextractf128 xmm12, ymm%[i], 0b1 ; [v8, v17]
vpermilpd xmm13, xmm12, 0b1 ; [v17, v8]
vaddsd xmm14, xmm%[i], xmm13 ; computing v25 : |v25| ≤ 1.52 * 2^23
vpermilpd xmm%[i], xmm%[i], 0b1 ; [v18, v24]
vaddsd xmm13, xmm%[i], xmm13 ; computing v19 : |v19| ≤ 1.66 * 2^35
vmovapd xmm15, oword [t2 + i*32] ; [v1, v6]
vsubsd xmm13, xmm15, xmm13 ; computing v20 : |v20| ≤ 1.67 * 2^35
vmulsd xmm13, xmm13, qword [rel .const_neg3]; computing v22 : |v20| ≤ 1.26 * 2^37
vunpcklpd xmm13, xmm13, xmm14 ; [v22, v25]
vpermilpd xmm15, xmm15, 0b1 ; [v6, v1]
vaddsd xmm14, xmm12, xmm15 ; computing v9 : |v9| ≤ 1.66 * 2^33
vmulsd xmm14, xmm14, qword [rel .const_neg6]; computing v11 : |v11| ≤ 1.25 * 2^36
vmovsd xmm12, qword [t2 + 32*i + 24] ; reload v28
; TODO(dsprenkels) Left here, was recomputing bounds; need graph sheet
vmulsd xmm12, xmm12, qword [rel .const_8] ; computing v34 : |v34| ≤ 1.01 * 2^24
vunpcklpd xmm12, xmm14, xmm12 ; [v11, v34]
vinsertf128 ymm%[i], ymm12, xmm13, 0b1 ; [v11, v34, v22, v25]
%assign i i+1
%endrep
fe12x4_squeeze_body ; squeezing [v11, v34, v22, v25] ≤ 1.01 * 2^21
%assign i 0
%rep 12
vmovapd oword [v11v34 + 16*i], xmm%[i] ; spill [v11, v34]
vextractf128 xmm12, ymm%[i], 0b1 ; [v22, v25]
vmovddup xmm13, xmm12 ; [v22, v22]
vmovapd oword [t3 + i*32], xmm13 ; t3 = [v22, v22, y, y]
vmovsd xmm14, qword [t2 + i*32 + 24] ; [v28]
; TODO(dsprenkels) We can maybe optimise the next op with a blend from 0,t2 and a vaddpd
vaddsd xmm14, xmm14, xmm14 ; computing v29a : |v29a| ≤ 1.01 * 2^22
vblendpd xmm12, xmm12, xmm14, 0b01 ; [v29a, v25]
vmovapd oword [t4 + i*32], xmm12 ; t4 = [v29a, v25, y, 2*x]
%assign i i+1
%endrep
fe12x4_mul t5, t3, t4, scratch ; computing [v30, v26, v2, v5] ≤ 1.01 * 2^21
; for the third batched multiplication we'll reuse {t0,t1,t2}
%assign i 0
%rep 12
; TODO(dsprenkels) Eliminate this load (?):
vmovapd xmm0, oword [t5 + i*32 + 16] ; [v2, v5]
vmovsd xmm1, qword [v11v34 + i*16] ; v11
vsubsd xmm2, xmm0, xmm1 ; computing v12 : |v12| ≤ 1.01 * 2^22
vaddsd xmm3, xmm0, xmm1 ; computing v13 : |v13| ≤ 1.01 * 2^22
vmovapd oword [t0 + 32*i], xmm0 ; t0 = [v2, v5, ??, ??]
vmovsd qword [t0 + 32*i + 16], xmm2 ; t0 = [v2, v5, v12, ??]
vmovsd xmm4, qword [v11v34 + i*16 + 8] ; reload v34
vmovsd qword [t1 + 32*i], xmm4 ; t1 = [v34, ??, ??, ??]
vmovsd qword [t1 + 32*i + 8], xmm2 ; t1 = [v34, v12, ??, ??]
vmovsd qword [t1 + 32*i + 16], xmm3 ; t1 = [v34, v12, v13, ??]
%assign i i+1
%endrep
fe12x4_mul_nosave t2, t0, t1, scratch ; computing [v32, v15, v14, ??] ≤ 1.01 * 2^21
%assign i 0
%rep 12
vpermilpd xmm12, xmm%[i], 0b1 ; v15
vextractf128 xmm13, ymm%[i], 0b1 ; v14
; TODO(dsprenkels) Left here, was recomputing bounds; need graph sheet
vsubsd xmm12, xmm12, qword [t5 + 32*i] ; computing v31 : |v31| ≤ 1.01 * 2^22
vaddsd xmm13, xmm13, qword [t5 + 32*i + 8] ; computing v27 : |v27| ≤ 1.01 * 2^22
; save doubled point
vmovsd qword [x3 + 8*i], xmm12 ; store x3
vmovsd qword [y3 + 8*i], xmm13 ; store y3
vmovsd qword [z3 + 8*i], xmm%[i] ; store z3
%assign i i+1
%endrep
%pop ge_double_ctx
; restore stack frame
mov rsp, rbp
pop rbp
bench_epilogue
ret
section .rodata
fe12x4_mul_consts
fe12x4_squeeze_consts
align 32, db 0
.const_mulsmall: dq 3.0, 26636.0, -6659.0, -3.0
align 4, db 0
.const_neg3: dq -3.0
.const_neg6: dq -6.0
.const_8: dq 8.0
ge_double_asm_v5:
bench_prologue
%push ge_double_ctx
%xdefine x3 rel scratch_space
%xdefine y3 rel scratch_space + 12*8
%xdefine z3 rel scratch_space + 24*8
%xdefine x rel scratch_space + 36*8
%xdefine y rel scratch_space + 48*8
%xdefine z rel scratch_space + 60*8
%xdefine t0 rsp
%xdefine t1 rsp + 1*384
%xdefine t2 rsp + 2*384
%xdefine t3 rsp + 3*384
%xdefine t4 rsp + 4*384
%xdefine t5 rsp + 5*384
%xdefine v11v34 rsp + 6*384
%xdefine old_rdi rsp + 6*384 + 192
%xdefine scratch rsp + 6*384 + 256
%xdefine stack_size 6*384 + 256 + 768
; build stack frame
push rbp
mov rbp, rsp
and rsp, -32
sub rsp, stack_size
mov qword [old_rdi], rdi ; we are going to overwrite this during function calls
; assume forall v in {x, y, z} : |v| ≤ 1.01 * 2^22
vxorpd xmm15, xmm15, xmm15 ; [0, 0]
%assign i 0
%rep 12
vbroadcastsd ymm0, qword [x + i*8] ; [x, x, x, x]
vbroadcastsd ymm1, qword [y + i*8] ; [y, y, y, y]
vbroadcastsd ymm2, qword [z + i*8] ; [z, z, z, z]
vblendpd ymm3, ymm0, ymm2, 0b1100 ; [x, x, z, z]
vblendpd ymm4, ymm0, ymm2, 0b0110 ; [x, z, z, x]
vblendpd ymm4, ymm4, ymm1, 0b1000 ; [x, z, z, y]
vmovapd yword [t0 + i*32], ymm3
vmovapd yword [t1 + i*32], ymm4
; prepare for second mul
vblendpd xmm5, xmm0, xmm1, 0b01 ; [y, x]
vblendpd xmm6, xmm15, xmm0, 0b10 ; [0, x]
vaddpd xmm5, xmm5, xmm6 ; [y, 2*x]
vmovapd oword [t3 + i*32 + 16], xmm1 ; t3 = [??, ??, y, y]
vmovapd oword [t4 + i*32 + 16], xmm5 ; t4 = [??, ??, y, 2*x]
%assign i i+1
%endrep
fe12x4_mul t2, t0, t1, scratch ; computing [v1, v6, v3, v28] ≤ 1.01 * 2^21
; t2 is now in ymm{0-11}
%assign i 0
%rep 12
vpermilpd ymm13, ymm%[i], 0b0010 ; [v1, v6, v3, v3]
vmulpd ymm%[i], ymm13, [rel .const_mulsmall]; computing [v24, v18, v8, v17]
; |v24| ≤ 1.52 * 2^22
; |v18| ≤ 1.65 * 2^35
; |v8| ≤ 1.65 * 2^33
; |v17| ≤ 1.52 * 2^22
vextractf128 xmm12, ymm%[i], 0b1 ; [v8, v17]
vpermilpd xmm13, xmm12, 0b1 ; [v17, v8]
vaddsd xmm14, xmm%[i], xmm13 ; computing v25 : |v25| ≤ 1.52 * 2^23
vpermilpd xmm%[i], xmm%[i], 0b1 ; [v18, v24]
vaddsd xmm13, xmm%[i], xmm13 ; computing v19 : |v19| ≤ 1.66 * 2^35
vmovapd xmm15, oword [t2 + i*32] ; [v1, v6]
vsubsd xmm13, xmm15, xmm13 ; computing v20 : |v20| ≤ 1.67 * 2^35
vmulsd xmm13, xmm13, qword [rel .const_neg3]; computing v22 : |v20| ≤ 1.26 * 2^37
vunpcklpd xmm13, xmm13, xmm14 ; [v22, v25]
vpermilpd xmm15, xmm15, 0b1 ; [v6, v1]
vaddsd xmm14, xmm12, xmm15 ; computing v9 : |v9| ≤ 1.66 * 2^33
vmulsd xmm14, xmm14, qword [rel .const_neg6]; computing v11 : |v11| ≤ 1.25 * 2^36
vmovsd xmm12, qword [t2 + 32*i + 24] ; reload v28
; TODO(dsprenkels) Left here, was recomputing bounds; need graph sheet
vmulsd xmm12, xmm12, qword [rel .const_8] ; computing v34 : |v34| ≤ 1.01 * 2^24
vunpcklpd xmm12, xmm14, xmm12 ; [v11, v34]
vinsertf128 ymm%[i], ymm12, xmm13, 0b1 ; [v11, v34, v22, v25]
%assign i i+1
%endrep
fe12x4_squeeze_body ; squeezing [v11, v34, v22, v25] ≤ 1.01 * 2^21
%assign i 0
%rep 12
vmovapd oword [v11v34 + 16*i], xmm%[i] ; spill [v11, v34]
vextractf128 xmm12, ymm%[i], 0b1 ; [v22, v25]
vmovddup xmm13, xmm12 ; [v22, v22]
vmovapd oword [t3 + i*32], xmm13 ; t3 = [v22, v22, y, y]
vmovsd xmm14, qword [t2 + i*32 + 24] ; [v28]
; TODO(dsprenkels) We can maybe optimise the next op with a blend from 0,t2 and a vaddpd
vaddsd xmm14, xmm14, xmm14 ; computing v29a : |v29a| ≤ 1.01 * 2^22
vblendpd xmm12, xmm12, xmm14, 0b01 ; [v29a, v25]
vmovapd oword [t4 + i*32], xmm12 ; t4 = [v29a, v25, y, 2*x]
%assign i i+1
%endrep
fe12x4_mul t5, t3, t4, scratch ; computing [v30, v26, v2, v5] ≤ 1.01 * 2^21
; for the third batched multiplication we'll reuse {t0,t1,t2}
%assign i 0
%rep 12
; TODO(dsprenkels) Eliminate this load (?):
vmovapd xmm0, oword [t5 + i*32 + 16] ; [v2, v5]
vmovsd xmm1, qword [v11v34 + i*16] ; v11
vsubsd xmm2, xmm0, xmm1 ; computing v12 : |v12| ≤ 1.01 * 2^22
vaddsd xmm3, xmm0, xmm1 ; computing v13 : |v13| ≤ 1.01 * 2^22
vmovapd oword [t0 + 32*i], xmm0 ; t0 = [v2, v5, ??, ??]
vmovsd qword [t0 + 32*i + 16], xmm2 ; t0 = [v2, v5, v12, ??]
vmovsd xmm4, qword [v11v34 + i*16 + 8] ; reload v34
vmovsd qword [t1 + 32*i], xmm4 ; t1 = [v34, ??, ??, ??]
vmovsd qword [t1 + 32*i + 8], xmm2 ; t1 = [v34, v12, ??, ??]
vmovsd qword [t1 + 32*i + 16], xmm3 ; t1 = [v34, v12, v13, ??]
%assign i i+1
%endrep
fe12x4_mul_nosave t2, t0, t1, scratch ; computing [v32, v15, v14, ??] ≤ 1.01 * 2^21
%assign i 0
%rep 12
vpermilpd xmm12, xmm%[i], 0b1 ; v15
vextractf128 xmm13, ymm%[i], 0b1 ; v14
; TODO(dsprenkels) Left here, was recomputing bounds; need graph sheet
vsubsd xmm12, xmm12, qword [t5 + 32*i] ; computing v31 : |v31| ≤ 1.01 * 2^22
vaddsd xmm13, xmm13, qword [t5 + 32*i + 8] ; computing v27 : |v27| ≤ 1.01 * 2^22
; save doubled point
vmovsd qword [x3 + 8*i], xmm12 ; store x3
vmovsd qword [y3 + 8*i], xmm13 ; store y3
vmovsd qword [z3 + 8*i], xmm%[i] ; store z3
%assign i i+1
%endrep
%pop ge_double_ctx
; restore stack frame
mov rsp, rbp
pop rbp
bench_epilogue
ret
section .rodata
fe12x4_mul_consts
fe12x4_squeeze_consts
align 32, db 0
.const_mulsmall: dq 3.0, 26636.0, -6659.0, -3.0
align 4, db 0
.const_neg3: dq -3.0
.const_neg6: dq -6.0
.const_8: dq 8.0
ge_double_asm_v6:
bench_prologue
%push ge_double_ctx
%xdefine x3 rel scratch_space
%xdefine y3 rel scratch_space + 12*8
%xdefine z3 rel scratch_space + 24*8
%xdefine x rel scratch_space + 36*8
%xdefine y rel scratch_space + 48*8
%xdefine z rel scratch_space + 60*8
%xdefine t0 rsp
%xdefine t1 rsp + 1*384
%xdefine t2 rsp + 2*384
%xdefine t3 rsp + 3*384
%xdefine t4 rsp + 4*384
%xdefine t5 rsp + 5*384
%xdefine v11v34 rsp + 6*384
%xdefine old_rdi rsp + 6*384 + 192
%xdefine scratch rsp + 6*384 + 256
%xdefine stack_size 6*384 + 256 + 768
; build stack frame
push rbp
mov rbp, rsp
and rsp, -32
sub rsp, stack_size
mov qword [old_rdi], rdi ; we are going to overwrite this during function calls
; assume forall v in {x, y, z} : |v| ≤ 1.01 * 2^22
vxorpd xmm15, xmm15, xmm15 ; [0, 0]
%assign i 0
%rep 12
vbroadcastsd ymm0, qword [x + i*8] ; [x, x, x, x]
vbroadcastsd ymm1, qword [y + i*8] ; [y, y, y, y]
vbroadcastsd ymm2, qword [z + i*8] ; [z, z, z, z]
vblendpd ymm3, ymm0, ymm2, 0b1100 ; [x, x, z, z]
vblendpd ymm4, ymm0, ymm2, 0b0110 ; [x, z, z, x]
vblendpd ymm4, ymm4, ymm1, 0b1000 ; [x, z, z, y]
vmovapd yword [t0 + i*32], ymm3
vmovapd yword [t1 + i*32], ymm4
; prepare for second mul
vblendpd xmm5, xmm0, xmm1, 0b01 ; [y, x]
vblendpd xmm6, xmm15, xmm0, 0b10 ; [0, x]
vaddpd xmm5, xmm5, xmm6 ; [y, 2*x]
vmovapd oword [t3 + i*32 + 16], xmm1 ; t3 = [??, ??, y, y]
vmovapd oword [t4 + i*32 + 16], xmm5 ; t4 = [??, ??, y, 2*x]
%assign i i+1
%endrep
fe12x4_mul t2, t0, t1, scratch ; computing [v1, v6, v3, v28] ≤ 1.01 * 2^21
; t2 is now in ymm{0-11}
vmovapd ymm12, [rel .const_mulsmall]
%assign i 0
%rep 12
vpermilpd ymm13, ymm%[i], 0b0010 ; [v1, v6, v3, v3]
vmulpd ymm%[i], ymm13, ymm12 ; computing [v24, v18, v8, v17]
; |v24| ≤ 1.52 * 2^22
; |v18| ≤ 1.65 * 2^35
; |v8| ≤ 1.65 * 2^33
; |v17| ≤ 1.52 * 2^22
%assign i i+1
%endrep
; t2 is now in ymm{0-11}
%assign i 0
%rep 12
vextractf128 xmm12, ymm%[i], 0b01 ; [v8, v17]
vpermilpd xmm13, xmm12, 0b01 ; [v17, v8]
vaddsd xmm14, xmm%[i], xmm13 ; computing v25 : |v25| ≤ 1.52 * 2^23
vpermilpd xmm%[i], xmm%[i], 0b01 ; [v18, v24]
vaddsd xmm13, xmm%[i], xmm13 ; computing v19 : |v19| ≤ 1.66 * 2^35
vmovapd xmm15, oword [t2 + i*32] ; [v1, v6]
vsubsd xmm13, xmm15, xmm13 ; computing v20 : |v20| ≤ 1.67 * 2^35
vmulsd xmm13, xmm13, qword [rel .const_neg3]; computing v22 : |v20| ≤ 1.26 * 2^37
vunpcklpd xmm13, xmm13, xmm14 ; [v22, v25]
vmovsd xmm15, qword [t2 + 32*i + 8] ; v6
vaddsd xmm14, xmm12, xmm15 ; computing v9 : |v9| ≤ 1.66 * 2^33
vmovsd xmm12, qword [t2 + 32*i + 24] ; reload v28
vunpcklpd xmm12, xmm14, xmm12 ; [v9, v28]
vmulpd xmm12, xmm12, oword [rel .const_neg6_8] ; computing [v11, v34]
vinsertf128 ymm%[i], ymm12, xmm13, 0b1 ; [v11, v34, v22, v25]
%assign i i+1
%endrep
fe12x4_squeeze_body ; squeezing [v11, v34, v22, v25] ≤ 1.01 * 2^21
%assign i 0
%rep 12
vmovapd oword [v11v34 + 16*i], xmm%[i] ; spill [v11, v34]
vextractf128 xmm12, ymm%[i], 0b1 ; [v22, v25]
vmovddup xmm13, xmm12 ; [v22, v22]
vmovapd oword [t3 + i*32], xmm13 ; t3 = [v22, v22, y, y]
vmovsd xmm14, qword [t2 + i*32 + 24] ; [v28]
vaddsd xmm14, xmm14, xmm14 ; computing v29a : |v29a| ≤ 1.01 * 2^22
vblendpd xmm12, xmm12, xmm14, 0b01 ; [v29a, v25]
vmovapd oword [t4 + i*32], xmm12 ; t4 = [v29a, v25, y, 2*x]
%assign i i+1
%endrep
fe12x4_mul t5, t3, t4, scratch ; computing [v30, v26, v2, v5] ≤ 1.01 * 2^21
; for the third batched multiplication we'll reuse {t0,t1,t2}
%assign i 0
%rep 12
vextractf128 xmm15, ymm%[i], 0b1 ; [v2, v5]
vmovapd xmm14, oword [v11v34 + i*16] ; [v11, v34]
vsubsd xmm13, xmm15, xmm14 ; computing v12 : |v12| ≤ 1.01 * 2^22
vaddsd xmm12, xmm15, xmm14 ; computing v13 : |v13| ≤ 1.01 * 2^22
vinsertf128 ymm15, xmm13, 0b1 ; [v2, v5, v12, ??]
vmovapd yword [t0 + 32*i], ymm15 ; t0 = [v2, v5, v12, ??]
vblendpd xmm14, xmm14, xmm13, 0b01 ; [v12, v34]
vpermilpd xmm14, xmm14, 0b01 ; [v34, v12]
vmovapd oword [t1 + 32*i], xmm14 ;
vmovsd qword [t1 + 32*i + 16], xmm12 ; t1 = [v34, v12, v13, ??]
%assign i i+1
%endrep
fe12x4_mul_nosave t2, t0, t1, scratch ; computing [v32, v15, v14, ??] ≤ 1.01 * 2^21
%assign i 0
%rep 12
vpermilpd xmm12, xmm%[i], 0b1 ; v15
vextractf128 xmm13, ymm%[i], 0b1 ; v14
vsubsd xmm12, xmm12, qword [t5 + 32*i] ; computing v31 : |v31| ≤ 1.01 * 2^22
vaddsd xmm13, xmm13, qword [t5 + 32*i + 8] ; computing v27 : |v27| ≤ 1.01 * 2^22
; save doubled point
vmovsd qword [x3 + 8*i], xmm12 ; store x3
vmovsd qword [y3 + 8*i], xmm13 ; store y3
vmovsd qword [z3 + 8*i], xmm%[i] ; store z3
%assign i i+1
%endrep
%pop ge_double_ctx
; restore stack frame
mov rsp, rbp
pop rbp
bench_epilogue
ret
section .rodata
fe12x4_mul_consts
fe12x4_squeeze_consts
align 32, db 0
.const_mulsmall: dq 3.0, 26636.0, -6659.0, -3.0
align 16, db 0
.const_neg6_8: dq -6.0, 8.0
align 4, db 0
.const_neg3: dq -3.0
section .text
ge_double_gcc:
bench_prologue
push r12
xor eax, eax
lea r12, [rel scratch_space]
push rbp
push rbx
sub rsp, 960
.L2:
vmovsd xmm0, [r12+36*8+rax]
vmovsd [rsp+rax], xmm0
add rax, 8
cmp rax, 96
jne .L2
xor eax, eax
.L3:
vmovsd xmm0, [r12+36*8+96+rax]
vmovsd [rsp+96+rax], xmm0
add rax, 8
cmp rax, 96
jne .L3
xor eax, eax
.L4:
vmovsd xmm0, [r12+36*8+192+rax]
vmovsd [rsp+192+rax], xmm0
add rax, 8
cmp rax, 96
jne .L4
lea rdi, [rsp+576]
mov rsi, rsp
call crypto_scalarmult_curve13318_ref12_fe12_square_karatsuba wrt ..plt
lea rsi, [rsp+96]
lea rdi, [rsp+672]
call crypto_scalarmult_curve13318_ref12_fe12_square_karatsuba wrt ..plt
lea rsi, [rsp+192]
lea rdi, [rsp+768]
call crypto_scalarmult_curve13318_ref12_fe12_square_karatsuba wrt ..plt
lea rdx, [rsp+96]
mov rsi, rsp
lea rdi, [rsp+864]
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
lea rax, [rsp+864]
lea rdx, [rsp+960]
.L5:
vmovsd xmm0, [rax]
add rax, 8
vaddsd xmm0, xmm0, xmm0
vmovsd [rax-8], xmm0
cmp rdx, rax
jne .L5
lea rdi, [rsp+768]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdi, [rsp+864]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rbx, [rsp+480]
mov rsi, rsp
lea rdx, [rsp+192]
lea rdi, [rsp+480]
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
lea rbp, [rbx+96]
mov rax, rbx
.L6:
vmovsd xmm0, [rax]
add rax, 8
vaddsd xmm0, xmm0, xmm0
vmovsd [rax-8], xmm0
cmp rbp, rax
jne .L6
xor eax, eax
.L7:
vmovsd xmm0, [rsp+768+rax]
vmovsd [rsp+384+rax], xmm0
add rax, 8
cmp rax, 96
jne .L7
lea rax, [rsp+384]
vmovsd xmm1, [rel .LC0]
lea rdx, [rax+96]
.L8:
vmulsd xmm0, xmm1, [rax]
add rax, 8
vmovsd [rax-8], xmm0
cmp rdx, rax
jne .L8
xor eax, eax
.L9:
vmovsd xmm0, [rsp+384+rax]
vsubsd xmm0, xmm0, [rsp+480+rax]
vmovsd [rsp+384+rax], xmm0
add rax, 8
cmp rax, 96
jne .L9
xor eax, eax
.L10:
vmovsd xmm0, [rsp+384+rax]
vaddsd xmm0, xmm0, xmm0
vmovsd [rsp+288+rax], xmm0
add rax, 8
cmp rax, 96
jne .L10
xor eax, eax
.L11:
vmovsd xmm0, [rsp+288+rax]
vaddsd xmm0, xmm0, [rsp+384+rax]
vmovsd [rsp+384+rax], xmm0
add rax, 8
cmp rax, 96
jne .L11
xor eax, eax
.L12:
vmovsd xmm0, [rsp+672+rax]
vsubsd xmm0, xmm0, [rsp+384+rax]
vmovsd [rsp+288+rax], xmm0
add rax, 8
cmp rax, 96
jne .L12
xor eax, eax
.L13:
vmovsd xmm0, [rsp+672+rax]
vaddsd xmm0, xmm0, [rsp+384+rax]
vmovsd [rsp+384+rax], xmm0
add rax, 8
cmp rax, 96
jne .L13
lea rdi, [rsp+288]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdi, [rsp+384]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdi, [rsp+480]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdx, [rsp+384]
lea rsi, [rsp+288]
mov rdi, rdx
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
lea rsi, [rsp+288]
lea rdx, [rsp+864]
mov rdi, rsi
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
mov rcx, [rel .LC0]
xor eax, eax
vmovq xmm1, rcx
.L14:
vmovsd xmm0, [rsp+768+rax]
vaddsd xmm0, xmm0, xmm0
vmovsd [rsp+864+rax], xmm0
add rax, 8
cmp rax, 96
jne .L14
xor eax, eax
.L15:
vmovsd xmm0, [rsp+768+rax]
vaddsd xmm0, xmm0, [rsp+864+rax]
vmovsd [rsp+768+rax], xmm0
add rax, 8
cmp rax, 96
jne .L15
lea rax, [rsp+480]
.L16:
vmulsd xmm0, xmm1, [rax]
add rax, 8
vmovsd [rax-8], xmm0
cmp rbp, rax
jne .L16
xor eax, eax
.L17:
vmovsd xmm0, [rsp+480+rax]
vsubsd xmm0, xmm0, [rsp+768+rax]
vmovsd [rsp+480+rax], xmm0
add rax, 8
cmp rax, 96
jne .L17
xor eax, eax
.L18:
vmovsd xmm0, [rsp+480+rax]
vsubsd xmm0, xmm0, [rsp+576+rax]
vmovsd [rsp+480+rax], xmm0
add rax, 8
cmp rax, 96
jne .L18
xor eax, eax
.L19:
vmovsd xmm0, [rsp+480+rax]
vaddsd xmm0, xmm0, xmm0
vmovsd [rsp+864+rax], xmm0
add rax, 8
cmp rax, 96
jne .L19
xor eax, eax
.L20:
vmovsd xmm0, [rsp+480+rax]
vaddsd xmm0, xmm0, [rsp+864+rax]
vmovsd [rsp+480+rax], xmm0
add rax, 8
cmp rax, 96
jne .L20
xor eax, eax
.L21:
vmovsd xmm0, [rsp+576+rax]
vaddsd xmm0, xmm0, xmm0
vmovsd [rsp+864+rax], xmm0
add rax, 8
cmp rax, 96
jne .L21
xor eax, eax
.L22:
vmovsd xmm0, [rsp+864+rax]
vaddsd xmm0, xmm0, [rsp+576+rax]
vmovsd [rsp+576+rax], xmm0
add rax, 8
cmp rax, 96
jne .L22
xor eax, eax
.L23:
vmovsd xmm0, [rsp+576+rax]
vsubsd xmm0, xmm0, [rsp+768+rax]
vmovsd [rsp+576+rax], xmm0
add rax, 8
cmp rax, 96
jne .L23
lea rdi, [rsp+576]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdi, [rsp+480]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rsi, [rsp+576]
lea rdx, [rsp+480]
mov rdi, rsi
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
xor eax, eax
.L24:
vmovsd xmm0, [rsp+384+rax]
vaddsd xmm0, xmm0, [rsp+576+rax]
vmovsd [rsp+384+rax], xmm0
add rax, 8
cmp rax, 96
jne .L24
lea rdx, [rsp+192]
lea rsi, [rsp+96]
lea rdi, [rsp+576]
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
lea rax, [rsp+576]
lea rdx, [rax+96]
.L25:
vmovsd xmm0, [rax]
add rax, 8
vaddsd xmm0, xmm0, xmm0
vmovsd [rax-8], xmm0
cmp rdx, rax
jne .L25
lea rdi, [rsp+576]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdx, [rsp+480]
lea rsi, [rsp+576]
mov rdi, rdx
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
xor eax, eax
.L26:
vmovsd xmm0, [rsp+288+rax]
vsubsd xmm0, xmm0, [rsp+480+rax]
vmovsd [rsp+288+rax], xmm0
add rax, 8
cmp rax, 96
jne .L26
lea rdi, [rsp+576]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdi, [rsp+672]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdx, [rsp+672]
lea rsi, [rsp+576]
lea rdi, [rsp+480]
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
lea rax, [rsp+480]
.L27:
vmovsd xmm0, [rax]
add rax, 8
vaddsd xmm0, xmm0, xmm0
vmovsd [rax-8], xmm0
cmp rbp, rax
jne .L27
.L28:
vmovsd xmm0, [rbx]
add rbx, 8
vaddsd xmm0, xmm0, xmm0
vmovsd [rbx-8], xmm0
cmp rbp, rbx
jne .L28
lea rdi, [rsp+288]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdi, [rsp+384]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdi, [rsp+480]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
xor eax, eax
.L29:
vmovsd xmm0, [rsp+288+rax]
vmovsd [r12+rax], xmm0
add rax, 8
cmp rax, 96
jne .L29
xor eax, eax
.L30:
vmovsd xmm0, [rsp+384+rax]
vmovsd [r12+96+rax], xmm0
add rax, 8
cmp rax, 96
jne .L30
xor eax, eax
.L31:
vmovsd xmm0, [rsp+480+rax]
vmovsd [r12+192+rax], xmm0
add rax, 8
cmp rax, 96
jne .L31
add rsp, 960
pop rbx
pop rbp
pop r12
bench_epilogue
ret
section .rodata
.LC0:
dq 0
dq 1086980864
section .text
ge_double_clang:
bench_prologue
push rbp
push r15
push r14
push r13
push r12
push rbx
sub rsp, 968
lea rbx, [rel scratch_space]
vmovups xmm0, [rel scratch_space + 36*8]
vmovups xmm1, [rel scratch_space + 36*8 + 16]
vmovups [rsp + 880], xmm1
vmovups [rsp + 864], xmm0
vmovups xmm0, [rel scratch_space + 36*8 + 32]
vmovups xmm1, [rel scratch_space + 36*8 + 48]
vmovups [rsp + 912], xmm1
vmovups [rsp + 896], xmm0
vmovups xmm0, [rel scratch_space + 36*8 + 64]
vmovups xmm1, [rel scratch_space + 36*8 + 80]
vmovups [rsp + 944], xmm1
vmovups [rsp + 928], xmm0
vmovups xmm0, [rel scratch_space + 36*8 + 96]
vmovups xmm1, [rel scratch_space + 36*8 + 112]
vmovups [rsp + 784], xmm1
vmovups [rsp + 768], xmm0
vmovups xmm0, [rel scratch_space + 36*8 + 128]
vmovups xmm1, [rel scratch_space + 36*8 + 144]
vmovups [rsp + 816], xmm1
vmovups [rsp + 800], xmm0
vmovups xmm0, [rel scratch_space + 36*8 + 160]
vmovups xmm1, [rel scratch_space + 36*8 + 176]
vmovups [rsp + 848], xmm1
vmovups [rsp + 832], xmm0
vmovups xmm0, [rel scratch_space + 36*8 + 192]
vmovups xmm1, [rel scratch_space + 36*8 + 208]
vmovups [rsp + 688], xmm1
vmovups [rsp + 672], xmm0
vmovups xmm0, [rel scratch_space + 36*8 + 224]
vmovups xmm1, [rel scratch_space + 36*8 + 240]
vmovups [rsp + 720], xmm1
vmovups [rsp + 704], xmm0
vmovups xmm0, [rel scratch_space + 36*8 + 256]
vmovups xmm1, [rel scratch_space + 36*8 + 272]
vmovups [rsp + 752], xmm1
vmovups [rsp + 736], xmm0
lea rdi, [rsp + 96]
lea r15, [rsp + 864]
mov rsi, r15
call crypto_scalarmult_curve13318_ref12_fe12_square_karatsuba wrt ..plt
lea rdi, [rsp + 576]
lea rbp, [rsp + 768]
mov rsi, rbp
call crypto_scalarmult_curve13318_ref12_fe12_square_karatsuba wrt ..plt
lea r12, [rsp + 480]
lea r14, [rsp + 672]
mov rdi, r12
mov rsi, r14
call crypto_scalarmult_curve13318_ref12_fe12_square_karatsuba wrt ..plt
lea r13, [rsp + 192]
mov rdi, r13
mov rsi, r15
mov rdx, rbp
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
vmovups xmm0, [rsp + 192]
vmovups xmm1, [rsp + 224]
vmovups xmm2, [rsp + 256]
vinsertf128 ymm0, ymm0, [rsp + 208], 1
vaddpd ymm0, ymm0, ymm0
vextractf128 [rsp + 208], ymm0, 1
vmovupd [rsp + 192], xmm0
vinsertf128 ymm0, ymm1, [rsp + 240], 1
vaddpd ymm0, ymm0, ymm0
vextractf128 [rsp + 240], ymm0, 1
vmovupd [rsp + 224], xmm0
vinsertf128 ymm0, ymm2, [rsp + 272], 1
vaddpd ymm0, ymm0, ymm0
vextractf128 [rsp + 272], ymm0, 1
vmovupd [rsp + 256], xmm0
mov rdi, r12
vzeroupper
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
mov rdi, r13
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
mov r12, rsp
mov rdi, r12
mov rsi, r15
mov rdx, r14
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
vmovups xmm0, [rsp]
vmovups xmm1, [rsp + 32]
vmovups xmm2, [rsp + 64]
vinsertf128 ymm0, ymm0, [rsp + 16], 1
vaddpd ymm0, ymm0, ymm0
vextractf128 [rsp + 16], ymm0, 1
vmovupd [rsp], xmm0
vinsertf128 ymm1, ymm1, [rsp + 48], 1
vaddpd ymm1, ymm1, ymm1
vextractf128 [rsp + 48], ymm1, 1
vmovupd [rsp + 32], xmm1
vinsertf128 ymm2, ymm2, [rsp + 80], 1
vaddpd ymm2, ymm2, ymm2
vextractf128 [rsp + 80], ymm2, 1
vmovupd [rsp + 64], xmm2
vmovups xmm3, [rsp + 480]
vmovups xmm4, [rsp + 512]
vmovups xmm5, [rsp + 544]
vinsertf128 ymm3, ymm3, [rsp + 496], 1
vinsertf128 ymm4, ymm4, [rsp + 528], 1
vinsertf128 ymm5, ymm5, [rsp + 560], 1
vmovupd ymm6, yword [rel .LCPI0_0]
vmulpd ymm3, ymm3, ymm6
vmulpd ymm4, ymm4, ymm6
vmulpd ymm5, ymm5, ymm6
vsubpd ymm0, ymm3, ymm0
vsubpd ymm1, ymm4, ymm1
vsubpd ymm2, ymm5, ymm2
vaddpd ymm3, ymm0, ymm0
vaddpd ymm4, ymm1, ymm1
vaddpd ymm5, ymm2, ymm2
vaddpd ymm0, ymm0, ymm3
vaddpd ymm1, ymm1, ymm4
vaddpd ymm2, ymm2, ymm5
vmovups xmm3, [rsp + 576]
vmovups xmm4, [rsp + 608]
vmovups xmm5, [rsp + 640]
vinsertf128 ymm3, ymm3, [rsp + 592], 1
vsubpd ymm6, ymm3, ymm0
vextractf128 [rsp + 400], ymm6, 1
vmovupd [rsp + 384], xmm6
vinsertf128 ymm4, ymm4, [rsp + 624], 1
vsubpd ymm6, ymm4, ymm1
vextractf128 [rsp + 432], ymm6, 1
vmovupd [rsp + 416], xmm6
vinsertf128 ymm5, ymm5, [rsp + 656], 1
vsubpd ymm6, ymm5, ymm2
vextractf128 [rsp + 464], ymm6, 1
vmovupd [rsp + 448], xmm6
vaddpd ymm0, ymm0, ymm3
vextractf128 [rsp + 304], ymm0, 1
vmovupd [rsp + 288], xmm0
vaddpd ymm0, ymm1, ymm4
vextractf128 [rsp + 336], ymm0, 1
vmovupd [rsp + 320], xmm0
vaddpd ymm0, ymm2, ymm5
vextractf128 [rsp + 368], ymm0, 1
vmovupd [rsp + 352], xmm0
lea r15, [rsp + 384]
mov rdi, r15
vzeroupper
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rbp, [rsp + 288]
mov rdi, rbp
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
mov rdi, r12
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
mov rdi, rbp
mov rsi, r15
mov rdx, rbp
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
mov rdi, r15
mov rsi, r15
mov rdx, r13
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
vmovupd xmm0, [rsp + 480]
vmovupd xmm1, [rsp + 496]
vmovupd xmm10, [rsp + 512]
vmovupd xmm11, [rsp + 528]
vaddpd xmm4, xmm0, xmm0
vmovupd [rsp + 192], xmm4
vaddpd xmm5, xmm1, xmm1
vmovupd [rsp + 208], xmm5
vaddpd xmm6, xmm10, xmm10
vmovupd [rsp + 224], xmm6
vaddpd xmm7, xmm11, xmm11
vmovupd [rsp + 240], xmm7
vmovupd xmm8, [rsp + 544]
vaddpd xmm9, xmm8, xmm8
vmovupd [rsp + 256], xmm9
vmovupd xmm2, [rsp + 560]
vaddpd xmm3, xmm2, xmm2
vmovupd [rsp + 272], xmm3
vinsertf128 ymm0, ymm0, xmm1, 1
vinsertf128 ymm1, ymm4, xmm5, 1
vaddpd ymm12, ymm0, ymm1
vextractf128 [rsp + 496], ymm12, 1
vmovupd [rsp + 480], xmm12
vinsertf128 ymm1, ymm10, xmm11, 1
vinsertf128 ymm4, ymm6, xmm7, 1
vaddpd ymm1, ymm1, ymm4
vextractf128 [rsp + 528], ymm1, 1
vmovupd [rsp + 512], xmm1
vinsertf128 ymm2, ymm8, xmm2, 1
vinsertf128 ymm3, ymm9, xmm3, 1
vaddpd ymm2, ymm2, ymm3
vextractf128 [rsp + 560], ymm2, 1
vmovupd [rsp + 544], xmm2
vmovups xmm3, [rsp]
vmovups xmm4, [rsp + 32]
vmovups xmm5, [rsp + 64]
vinsertf128 ymm3, ymm3, [rsp + 16], 1
vinsertf128 ymm4, ymm4, [rsp + 48], 1
vinsertf128 ymm5, ymm5, [rsp + 80], 1
vmovupd ymm0, yword [rel .LCPI0_0]
vmulpd ymm3, ymm3, ymm0
vmulpd ymm4, ymm4, ymm0
vmulpd ymm5, ymm5, ymm0
vsubpd ymm7, ymm3, ymm12
vsubpd ymm8, ymm4, ymm1
vsubpd ymm9, ymm5, ymm2
vmovupd xmm10, [rsp + 96]
vmovupd xmm0, [rsp + 112]
vmovups xmm4, [rsp + 128]
vmovupd xmm6, [rsp + 160]
vinsertf128 ymm11, ymm10, xmm0, 1
vsubpd ymm7, ymm7, ymm11
vinsertf128 ymm4, ymm4, [rsp + 144], 1
vsubpd ymm8, ymm8, ymm4
vmovupd xmm3, [rsp + 176]
vinsertf128 ymm5, ymm6, xmm3, 1
vsubpd ymm9, ymm9, ymm5
vaddpd ymm13, ymm7, ymm7
vaddpd ymm14, ymm8, ymm8
vaddpd ymm15, ymm9, ymm9
vaddpd ymm7, ymm7, ymm13
vextractf128 [rsp + 16], ymm7, 1
vmovupd [rsp], xmm7
vaddpd ymm7, ymm8, ymm14
vextractf128 [rsp + 48], ymm7, 1
vmovupd [rsp + 32], xmm7
vaddpd ymm7, ymm9, ymm15
vextractf128 [rsp + 80], ymm7, 1
vmovupd [rsp + 64], xmm7
vaddpd xmm9, xmm10, xmm10
vmovupd [rsp + 192], xmm9
vaddpd xmm0, xmm0, xmm0
vmovupd [rsp + 208], xmm0
vaddpd ymm8, ymm4, ymm4
vmovlpd qword [rsp + 224], xmm8
vmovhpd qword [rsp + 232], xmm8
vextractf128 xmm7, ymm8, 1
vmovlpd qword [rsp + 240], xmm7
vmovhpd qword [rsp + 248], xmm7
vaddpd xmm6, xmm6, xmm6
vmovupd [rsp + 256], xmm6
vaddpd xmm3, xmm3, xmm3
vmovupd [rsp + 272], xmm3
vinsertf128 ymm0, ymm9, xmm0, 1
vaddpd ymm0, ymm11, ymm0
vaddpd ymm4, ymm4, ymm8
vinsertf128 ymm3, ymm6, xmm3, 1
vaddpd ymm3, ymm5, ymm3
vsubpd ymm0, ymm0, ymm12
vextractf128 [rsp + 112], ymm0, 1
vmovupd [rsp + 96], xmm0
vsubpd ymm0, ymm4, ymm1
vextractf128 [rsp + 144], ymm0, 1
vmovupd [rsp + 128], xmm0
vsubpd ymm0, ymm3, ymm2
vextractf128 [rsp + 176], ymm0, 1
vmovupd [rsp + 160], xmm0
lea r14, [rsp + 96]
mov rdi, r14
vzeroupper
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
mov rdi, r12
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
mov rdi, r14
mov rsi, r14
mov rdx, r12
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
vmovups xmm0, [rsp + 288]
vmovups xmm1, [rsp + 320]
vinsertf128 ymm0, ymm0, [rsp + 304], 1
vmovups xmm2, [rsp + 352]
vmovups xmm3, [rsp + 96]
vinsertf128 ymm3, ymm3, [rsp + 112], 1
vmovups xmm4, [rsp + 128]
vaddpd ymm0, ymm0, ymm3
vextractf128 [rsp + 304], ymm0, 1
vmovupd [rsp + 288], xmm0
vinsertf128 ymm0, ymm1, [rsp + 336], 1
vinsertf128 ymm1, ymm4, [rsp + 144], 1
vmovups xmm3, [rsp + 160]
vaddpd ymm0, ymm0, ymm1
vextractf128 [rsp + 336], ymm0, 1
vmovupd [rsp + 320], xmm0
vinsertf128 ymm0, ymm2, [rsp + 368], 1
vinsertf128 ymm1, ymm3, [rsp + 176], 1
vaddpd ymm0, ymm0, ymm1
vextractf128 [rsp + 368], ymm0, 1
vmovupd [rsp + 352], xmm0
mov rdi, r14
lea rsi, [rsp + 768]
lea rdx, [rsp + 672]
vzeroupper
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
vmovups xmm0, [rsp + 96]
vmovups xmm1, [rsp + 128]
vmovups xmm2, [rsp + 160]
vinsertf128 ymm0, ymm0, [rsp + 112], 1
vaddpd ymm0, ymm0, ymm0
vextractf128 [rsp + 112], ymm0, 1
vmovupd [rsp + 96], xmm0
vinsertf128 ymm0, ymm1, [rsp + 144], 1
vaddpd ymm0, ymm0, ymm0
vextractf128 [rsp + 144], ymm0, 1
vmovupd [rsp + 128], xmm0
vinsertf128 ymm0, ymm2, [rsp + 176], 1
vaddpd ymm0, ymm0, ymm0
vextractf128 [rsp + 176], ymm0, 1
vmovupd [rsp + 160], xmm0
mov rdi, r14
vzeroupper
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
mov rdi, r12
mov rsi, r14
mov rdx, r12
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
vmovups xmm0, [rsp + 384]
vmovups xmm1, [rsp + 416]
vinsertf128 ymm0, ymm0, [rsp + 400], 1
vmovups xmm2, [rsp + 448]
vmovups xmm3, [rsp]
vinsertf128 ymm3, ymm3, [rsp + 16], 1
vmovups xmm4, [rsp + 32]
vsubpd ymm0, ymm0, ymm3
vextractf128 [rsp + 400], ymm0, 1
vmovupd [rsp + 384], xmm0
vinsertf128 ymm0, ymm1, [rsp + 432], 1
vinsertf128 ymm1, ymm4, [rsp + 48], 1
vmovups xmm3, [rsp + 64]
vsubpd ymm0, ymm0, ymm1
vextractf128 [rsp + 432], ymm0, 1
vmovupd [rsp + 416], xmm0
vinsertf128 ymm0, ymm2, [rsp + 464], 1
vinsertf128 ymm1, ymm3, [rsp + 80], 1
vsubpd ymm0, ymm0, ymm1
vextractf128 [rsp + 464], ymm0, 1
vmovupd [rsp + 448], xmm0
mov rdi, r14
vzeroupper
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rbp, [rsp + 576]
mov rdi, rbp
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
mov rdi, r12
mov rsi, r14
mov rdx, rbp
call crypto_scalarmult_curve13318_ref12_fe12_mul_karatsuba wrt ..plt
vmovups xmm0, [rsp]
vinsertf128 ymm0, ymm0, [rsp + 16], 1
vaddpd ymm0, ymm0, ymm0
vmovsd xmm1, qword [rsp + 32]
vaddsd xmm1, xmm1, xmm1
vmovsd xmm2, qword [rsp + 40]
vaddsd xmm2, xmm2, xmm2
vmovsd xmm3, qword [rsp + 48]
vaddsd xmm3, xmm3, xmm3
vmovsd xmm4, qword [rsp + 56]
vmovups xmm5, [rsp + 64]
vinsertf128 ymm5, ymm5, [rsp + 80], 1
vaddsd xmm4, xmm4, xmm4
vaddpd ymm5, ymm5, ymm5
vaddpd ymm0, ymm0, ymm0
vextractf128 [rsp + 16], ymm0, 1
vmovupd [rsp], xmm0
vaddsd xmm0, xmm1, xmm1
vmovsd qword [rsp + 32], xmm0
vaddsd xmm0, xmm2, xmm2
vmovsd qword [rsp + 40], xmm0
vaddsd xmm0, xmm3, xmm3
vmovsd qword [rsp + 48], xmm0
vaddsd xmm0, xmm4, xmm4
vmovsd qword [rsp + 56], xmm0
vaddpd ymm0, ymm5, ymm5
vextractf128 [rsp + 80], ymm0, 1
vmovupd [rsp + 64], xmm0
mov rdi, r15
vzeroupper
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
lea rdi, [rsp + 288]
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
mov rdi, r12
call crypto_scalarmult_curve13318_ref12_fe12_squeeze wrt ..plt
vmovups xmm0, [rsp + 384]
vmovups xmm1, [rsp + 400]
vmovups [rbx + 16], xmm1
vmovups [rbx], xmm0
vmovups xmm0, [rsp + 416]
vmovups xmm1, [rsp + 432]
vmovups [rbx + 48], xmm1
vmovups [rbx + 32], xmm0
vmovups xmm0, [rsp + 448]
vmovups xmm1, [rsp + 464]
vmovups [rbx + 80], xmm1
vmovups [rbx + 64], xmm0
vmovups xmm0, [rsp + 288]
vmovups xmm1, [rsp + 304]
vmovups [rbx + 112], xmm1
vmovups [rbx + 96], xmm0
vmovups xmm0, [rsp + 320]
vmovups xmm1, [rsp + 336]
vmovups [rbx + 144], xmm1
vmovups [rbx + 128], xmm0
vmovups xmm0, [rsp + 352]
vmovups xmm1, [rsp + 368]
vmovups [rbx + 176], xmm1
vmovups [rbx + 160], xmm0
vmovups xmm0, [rsp]
vmovups xmm1, [rsp + 16]
vmovups [rbx + 208], xmm1
vmovups [rbx + 192], xmm0
vmovups xmm0, [rsp + 32]
vmovups xmm1, [rsp + 48]
vmovups [rbx + 240], xmm1
vmovups [rbx + 224], xmm0
vmovups xmm0, [rsp + 64]
vmovups xmm1, [rsp + 80]
vmovups [rbx + 272], xmm1
vmovups [rbx + 256], xmm0
add rsp, 968
pop rbx
pop r12
pop r13
pop r14
pop r15
pop rbp
bench_epilogue
ret
section .rodata
align 32, db 0
.LCPI0_0:
dq 4668547262257823744
dq 4668547262257823744
dq 4668547262257823744
dq 4668547262257823744
|
/* Copyright (c) 2010-2011 mbed.org, 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 "stdint.h"
#include "USBEndpoints.h"
#include "USBDevice.h"
#include "USBDescriptor.h"
//#define DEBUG
/* Device status */
#define DEVICE_STATUS_SELF_POWERED (1U<<0)
#define DEVICE_STATUS_REMOTE_WAKEUP (1U<<1)
/* Endpoint status */
#define ENDPOINT_STATUS_HALT (1U<<0)
/* Standard feature selectors */
#define DEVICE_REMOTE_WAKEUP (1)
#define ENDPOINT_HALT (0)
/* Macro to convert wIndex endpoint number to physical endpoint number */
#define WINDEX_TO_PHYSICAL(endpoint) (((endpoint & 0x0f) << 1) + \
((endpoint & 0x80) ? 1 : 0))
bool USBDevice::requestGetDescriptor(void)
{
bool success = false;
#ifdef DEBUG
printf("get descr: type: %d\r\n", DESCRIPTOR_TYPE(transfer.setup.wValue));
#endif
switch (DESCRIPTOR_TYPE(transfer.setup.wValue))
{
case DEVICE_DESCRIPTOR:
if (deviceDesc() != NULL)
{
if ((deviceDesc()[0] == DEVICE_DESCRIPTOR_LENGTH) \
&& (deviceDesc()[1] == DEVICE_DESCRIPTOR))
{
#ifdef DEBUG
printf("device descr\r\n");
#endif
transfer.remaining = DEVICE_DESCRIPTOR_LENGTH;
transfer.ptr = deviceDesc();
transfer.direction = DEVICE_TO_HOST;
success = true;
}
}
break;
case CONFIGURATION_DESCRIPTOR:
if (configurationDesc() != NULL)
{
if ((configurationDesc()[0] == CONFIGURATION_DESCRIPTOR_LENGTH) \
&& (configurationDesc()[1] == CONFIGURATION_DESCRIPTOR))
{
#ifdef DEBUG
printf("conf descr request\r\n");
#endif
/* Get wTotalLength */
transfer.remaining = configurationDesc()[2] \
| (configurationDesc()[3] << 8);
transfer.ptr = configurationDesc();
transfer.direction = DEVICE_TO_HOST;
success = true;
}
}
break;
case STRING_DESCRIPTOR:
#ifdef DEBUG
printf("str descriptor\r\n");
#endif
switch (DESCRIPTOR_INDEX(transfer.setup.wValue))
{
case STRING_OFFSET_LANGID:
#ifdef DEBUG
printf("1\r\n");
#endif
transfer.remaining = stringLangidDesc()[0];
transfer.ptr = stringLangidDesc();
transfer.direction = DEVICE_TO_HOST;
success = true;
break;
case STRING_OFFSET_IMANUFACTURER:
#ifdef DEBUG
printf("2\r\n");
#endif
transfer.remaining = stringImanufacturerDesc()[0];
transfer.ptr = stringImanufacturerDesc();
transfer.direction = DEVICE_TO_HOST;
success = true;
break;
case STRING_OFFSET_IPRODUCT:
#ifdef DEBUG
printf("3\r\n");
#endif
transfer.remaining = stringIproductDesc()[0];
transfer.ptr = stringIproductDesc();
transfer.direction = DEVICE_TO_HOST;
success = true;
break;
case STRING_OFFSET_ISERIAL:
#ifdef DEBUG
printf("4\r\n");
#endif
transfer.remaining = stringIserialDesc()[0];
transfer.ptr = stringIserialDesc();
transfer.direction = DEVICE_TO_HOST;
success = true;
break;
case STRING_OFFSET_ICONFIGURATION:
#ifdef DEBUG
printf("5\r\n");
#endif
transfer.remaining = stringIConfigurationDesc()[0];
transfer.ptr = stringIConfigurationDesc();
transfer.direction = DEVICE_TO_HOST;
success = true;
break;
case STRING_OFFSET_IINTERFACE:
#ifdef DEBUG
printf("6\r\n");
#endif
transfer.remaining = stringIinterfaceDesc()[0];
transfer.ptr = stringIinterfaceDesc();
transfer.direction = DEVICE_TO_HOST;
success = true;
break;
}
break;
case INTERFACE_DESCRIPTOR:
#ifdef DEBUG
printf("interface descr\r\n");
#endif
case ENDPOINT_DESCRIPTOR:
#ifdef DEBUG
printf("endpoint descr\r\n");
#endif
/* TODO: Support is optional, not implemented here */
break;
default:
#ifdef DEBUG
printf("ERROR\r\n");
#endif
break;
}
return success;
}
void USBDevice::decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet)
{
/* Fill in the elements of a SETUP_PACKET structure from raw data */
packet->bmRequestType.dataTransferDirection = (data[0] & 0x80) >> 7;
packet->bmRequestType.Type = (data[0] & 0x60) >> 5;
packet->bmRequestType.Recipient = data[0] & 0x1f;
packet->bRequest = data[1];
packet->wValue = (data[2] | (uint16_t)data[3] << 8);
packet->wIndex = (data[4] | (uint16_t)data[5] << 8);
packet->wLength = (data[6] | (uint16_t)data[7] << 8);
}
bool USBDevice::controlOut(void)
{
/* Control transfer data OUT stage */
uint8_t buffer[MAX_PACKET_SIZE_EP0];
uint32_t packetSize;
/* Check we should be transferring data OUT */
if (transfer.direction != HOST_TO_DEVICE)
{
return false;
}
/* Read from endpoint */
packetSize = EP0getReadResult(buffer);
/* Check if transfer size is valid */
if (packetSize > transfer.remaining)
{
/* Too big */
return false;
}
/* Update transfer */
transfer.ptr += packetSize;
transfer.remaining -= packetSize;
/* Check if transfer has completed */
if (transfer.remaining == 0)
{
/* Transfer completed */
if (transfer.notify)
{
/* Notify class layer. */
USBCallback_requestCompleted(buffer, packetSize);
transfer.notify = false;
}
/* Status stage */
EP0write(NULL, 0);
}
else
{
EP0read();
}
return true;
}
bool USBDevice::controlIn(void)
{
/* Control transfer data IN stage */
uint32_t packetSize;
/* Check if transfer has completed (status stage transactions */
/* also have transfer.remaining == 0) */
if (transfer.remaining == 0)
{
if (transfer.zlp)
{
/* Send zero length packet */
EP0write(NULL, 0);
transfer.zlp = false;
}
/* Transfer completed */
if (transfer.notify)
{
/* Notify class layer. */
USBCallback_requestCompleted(NULL, 0);
transfer.notify = false;
}
EP0read();
EP0readStage();
/* Completed */
return true;
}
/* Check we should be transferring data IN */
if (transfer.direction != DEVICE_TO_HOST)
{
return false;
}
packetSize = transfer.remaining;
if (packetSize > MAX_PACKET_SIZE_EP0)
{
packetSize = MAX_PACKET_SIZE_EP0;
}
/* Write to endpoint */
EP0write(transfer.ptr, packetSize);
/* Update transfer */
transfer.ptr += packetSize;
transfer.remaining -= packetSize;
return true;
}
bool USBDevice::requestSetAddress(void)
{
/* Set the device address */
setAddress(transfer.setup.wValue);
if (transfer.setup.wValue == 0)
{
device.state = DEFAULT;
}
else
{
device.state = ADDRESS;
}
return true;
}
bool USBDevice::requestSetConfiguration(void)
{
device.configuration = transfer.setup.wValue;
/* Set the device configuration */
if (device.configuration == 0)
{
/* Not configured */
unconfigureDevice();
device.state = ADDRESS;
}
else
{
if (USBCallback_setConfiguration(device.configuration))
{
/* Valid configuration */
configureDevice();
device.state = CONFIGURED;
}
else
{
return false;
}
}
return true;
}
bool USBDevice::requestGetConfiguration(void)
{
/* Send the device configuration */
transfer.ptr = &device.configuration;
transfer.remaining = sizeof(device.configuration);
transfer.direction = DEVICE_TO_HOST;
return true;
}
bool USBDevice::requestGetInterface(void)
{
/* Return the selected alternate setting for an interface */
if (device.state != CONFIGURED)
{
return false;
}
/* Send the alternate setting */
transfer.setup.wIndex = currentInterface;
transfer.ptr = ¤tAlternate;
transfer.remaining = sizeof(currentAlternate);
transfer.direction = DEVICE_TO_HOST;
return true;
}
bool USBDevice::requestSetInterface(void)
{
bool success = false;
if(USBCallback_setInterface(transfer.setup.wIndex, transfer.setup.wValue))
{
success = true;
currentInterface = transfer.setup.wIndex;
currentAlternate = transfer.setup.wValue;
}
return success;
}
bool USBDevice::requestSetFeature()
{
bool success = false;
if (device.state != CONFIGURED)
{
/* Endpoint or interface must be zero */
if (transfer.setup.wIndex != 0)
{
return false;
}
}
switch (transfer.setup.bmRequestType.Recipient)
{
case DEVICE_RECIPIENT:
/* TODO: Remote wakeup feature not supported */
break;
case ENDPOINT_RECIPIENT:
if (transfer.setup.wValue == ENDPOINT_HALT)
{
/* TODO: We should check that the endpoint number is valid */
stallEndpoint(
WINDEX_TO_PHYSICAL(transfer.setup.wIndex));
success = true;
}
break;
default:
break;
}
return success;
}
bool USBDevice::requestClearFeature()
{
bool success = false;
if (device.state != CONFIGURED)
{
/* Endpoint or interface must be zero */
if (transfer.setup.wIndex != 0)
{
return false;
}
}
switch (transfer.setup.bmRequestType.Recipient)
{
case DEVICE_RECIPIENT:
/* TODO: Remote wakeup feature not supported */
break;
case ENDPOINT_RECIPIENT:
/* TODO: We should check that the endpoint number is valid */
if (transfer.setup.wValue == ENDPOINT_HALT)
{
unstallEndpoint( WINDEX_TO_PHYSICAL(transfer.setup.wIndex));
success = true;
}
break;
default:
break;
}
return success;
}
bool USBDevice::requestGetStatus(void)
{
static uint16_t status;
bool success = false;
if (device.state != CONFIGURED)
{
/* Endpoint or interface must be zero */
if (transfer.setup.wIndex != 0)
{
return false;
}
}
switch (transfer.setup.bmRequestType.Recipient)
{
case DEVICE_RECIPIENT:
/* TODO: Currently only supports self powered devices */
status = DEVICE_STATUS_SELF_POWERED;
success = true;
break;
case INTERFACE_RECIPIENT:
status = 0;
success = true;
break;
case ENDPOINT_RECIPIENT:
/* TODO: We should check that the endpoint number is valid */
if (getEndpointStallState(
WINDEX_TO_PHYSICAL(transfer.setup.wIndex)))
{
status = ENDPOINT_STATUS_HALT;
}
else
{
status = 0;
}
success = true;
break;
default:
break;
}
if (success)
{
/* Send the status */
transfer.ptr = (uint8_t *)&status; /* Assumes little endian */
transfer.remaining = sizeof(status);
transfer.direction = DEVICE_TO_HOST;
}
return success;
}
bool USBDevice::requestSetup(void)
{
bool success = false;
/* Process standard requests */
if ((transfer.setup.bmRequestType.Type == STANDARD_TYPE))
{
switch (transfer.setup.bRequest)
{
case GET_STATUS:
success = requestGetStatus();
break;
case CLEAR_FEATURE:
success = requestClearFeature();
break;
case SET_FEATURE:
success = requestSetFeature();
break;
case SET_ADDRESS:
success = requestSetAddress();
break;
case GET_DESCRIPTOR:
success = requestGetDescriptor();
break;
case SET_DESCRIPTOR:
/* TODO: Support is optional, not implemented here */
success = false;
break;
case GET_CONFIGURATION:
success = requestGetConfiguration();
break;
case SET_CONFIGURATION:
success = requestSetConfiguration();
break;
case GET_INTERFACE:
success = requestGetInterface();
break;
case SET_INTERFACE:
success = requestSetInterface();
break;
default:
break;
}
}
return success;
}
bool USBDevice::controlSetup(void)
{
bool success = false;
/* Control transfer setup stage */
uint8_t buffer[MAX_PACKET_SIZE_EP0];
EP0setup(buffer);
/* Initialise control transfer state */
decodeSetupPacket(buffer, &transfer.setup);
transfer.ptr = NULL;
transfer.remaining = 0;
transfer.direction = 0;
transfer.zlp = false;
transfer.notify = false;
#ifdef DEBUG
printf("dataTransferDirection: %d\r\nType: %d\r\nRecipient: %d\r\nbRequest: %d\r\nwValue: %d\r\nwIndex: %d\r\nwLength: %d\r\n",transfer.setup.bmRequestType.dataTransferDirection,
transfer.setup.bmRequestType.Type,
transfer.setup.bmRequestType.Recipient,
transfer.setup.bRequest,
transfer.setup.wValue,
transfer.setup.wIndex,
transfer.setup.wLength);
#endif
/* Class / vendor specific */
success = USBCallback_request();
if (!success)
{
/* Standard requests */
if (!requestSetup())
{
#ifdef DEBUG
printf("fail!!!!\r\n");
#endif
return false;
}
}
/* Check transfer size and direction */
if (transfer.setup.wLength>0)
{
if (transfer.setup.bmRequestType.dataTransferDirection \
== DEVICE_TO_HOST)
{
/* IN data stage is required */
if (transfer.direction != DEVICE_TO_HOST)
{
return false;
}
/* Transfer must be less than or equal to the size */
/* requested by the host */
if (transfer.remaining > transfer.setup.wLength)
{
transfer.remaining = transfer.setup.wLength;
}
}
else
{
/* OUT data stage is required */
if (transfer.direction != HOST_TO_DEVICE)
{
return false;
}
/* Transfer must be equal to the size requested by the host */
if (transfer.remaining != transfer.setup.wLength)
{
return false;
}
}
}
else
{
/* No data stage; transfer size must be zero */
if (transfer.remaining != 0)
{
return false;
}
}
/* Data or status stage if applicable */
if (transfer.setup.wLength>0)
{
if (transfer.setup.bmRequestType.dataTransferDirection \
== DEVICE_TO_HOST)
{
/* Check if we'll need to send a zero length packet at */
/* the end of this transfer */
if (transfer.setup.wLength > transfer.remaining)
{
/* Device wishes to transfer less than host requested */
if ((transfer.remaining % MAX_PACKET_SIZE_EP0) == 0)
{
/* Transfer is a multiple of EP0 max packet size */
transfer.zlp = true;
}
}
/* IN stage */
controlIn();
}
else
{
/* OUT stage */
EP0read();
}
}
else
{
/* Status stage */
EP0write(NULL, 0);
}
return true;
}
void USBDevice::busReset(void)
{
device.state = DEFAULT;
device.configuration = 0;
device.suspended = false;
/* Call class / vendor specific busReset function */
USBCallback_busReset();
}
void USBDevice::EP0setupCallback(void)
{
/* Endpoint 0 setup event */
if (!controlSetup())
{
/* Protocol stall */
EP0stall();
}
/* Return true if an OUT data stage is expected */
}
void USBDevice::EP0out(void)
{
/* Endpoint 0 OUT data event */
if (!controlOut())
{
/* Protocol stall; this will stall both endpoints */
EP0stall();
}
}
void USBDevice::EP0in(void)
{
#ifdef DEBUG
printf("EP0IN\r\n");
#endif
/* Endpoint 0 IN data event */
if (!controlIn())
{
/* Protocol stall; this will stall both endpoints */
EP0stall();
}
}
bool USBDevice::configured(void)
{
/* Returns true if device is in the CONFIGURED state */
return (device.state == CONFIGURED);
}
void USBDevice::connect(bool blocking)
{
/* Connect device */
USBHAL::connect();
if (blocking) {
/* Block if not configured */
while (!configured());
}
}
void USBDevice::disconnect(void)
{
/* Disconnect device */
USBHAL::disconnect();
}
CONTROL_TRANSFER * USBDevice::getTransferPtr(void)
{
return &transfer;
}
bool USBDevice::addEndpoint(uint8_t endpoint, uint32_t maxPacket)
{
return realiseEndpoint(endpoint, maxPacket, 0);
}
bool USBDevice::addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket)
{
/* For interrupt endpoints only */
return realiseEndpoint(endpoint, maxPacket, RATE_FEEDBACK_MODE);
}
uint8_t * USBDevice::findDescriptor(uint8_t descriptorType)
{
/* Find a descriptor within the list of descriptors */
/* following a configuration descriptor. */
uint16_t wTotalLength;
uint8_t *ptr;
if (configurationDesc() == NULL)
{
return NULL;
}
/* Check this is a configuration descriptor */
if ((configurationDesc()[0] != CONFIGURATION_DESCRIPTOR_LENGTH) \
|| (configurationDesc()[1] != CONFIGURATION_DESCRIPTOR))
{
return NULL;
}
wTotalLength = configurationDesc()[2] | (configurationDesc()[3] << 8);
/* Check there are some more descriptors to follow */
if (wTotalLength <= (CONFIGURATION_DESCRIPTOR_LENGTH+2))
/* +2 is for bLength and bDescriptorType of next descriptor */
{
return NULL;
}
/* Start at first descriptor after the configuration descriptor */
ptr = &(configurationDesc()[CONFIGURATION_DESCRIPTOR_LENGTH]);
do {
if (ptr[1] /* bDescriptorType */ == descriptorType)
{
/* Found */
return ptr;
}
/* Skip to next descriptor */
ptr += ptr[0]; /* bLength */
} while (ptr < (configurationDesc() + wTotalLength));
/* Reached end of the descriptors - not found */
return NULL;
}
void USBDevice::connectStateChanged(unsigned int connected)
{
}
void USBDevice::suspendStateChanged(unsigned int suspended)
{
}
USBDevice::USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release){
VENDOR_ID = vendor_id;
PRODUCT_ID = product_id;
PRODUCT_RELEASE = product_release;
/* Set initial device state */
device.state = POWERED;
device.configuration = 0;
device.suspended = false;
};
bool USBDevice::readStart(uint8_t endpoint, uint32_t maxSize)
{
return endpointRead(endpoint, maxSize) == EP_PENDING;
}
bool USBDevice::write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize)
{
EP_STATUS result;
if (size > maxSize)
{
return false;
}
if(!configured()) {
return false;
}
/* Send report */
result = endpointWrite(endpoint, buffer, size);
if (result != EP_PENDING)
{
return false;
}
/* Wait for completion */
do {
result = endpointWriteResult(endpoint);
} while ((result == EP_PENDING) && configured());
return (result == EP_COMPLETED);
}
bool USBDevice::writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize)
{
EP_STATUS result;
if (size > maxSize)
{
return false;
}
if(!configured()) {
return false;
}
/* Send report */
result = endpointWrite(endpoint, buffer, size);
if (result != EP_PENDING)
{
return false;
}
result = endpointWriteResult(endpoint);
return (result == EP_COMPLETED);
}
bool USBDevice::readEP(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize)
{
EP_STATUS result;
if(!configured()) {
return false;
}
/* Wait for completion */
do {
result = endpointReadResult(endpoint, buffer, size);
} while ((result == EP_PENDING) && configured());
return (result == EP_COMPLETED);
}
bool USBDevice::readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize)
{
EP_STATUS result;
if(!configured()) {
return false;
}
result = endpointReadResult(endpoint, buffer, size);
return (result == EP_COMPLETED);
}
uint8_t * USBDevice::deviceDesc() {
static uint8_t deviceDescriptor[] = {
DEVICE_DESCRIPTOR_LENGTH, /* bLength */
DEVICE_DESCRIPTOR, /* bDescriptorType */
LSB(USB_VERSION_2_0), /* bcdUSB (LSB) */
MSB(USB_VERSION_2_0), /* bcdUSB (MSB) */
0x00, /* bDeviceClass */
0x00, /* bDeviceSubClass */
0x00, /* bDeviceprotocol */
MAX_PACKET_SIZE_EP0, /* bMaxPacketSize0 */
(uint8_t)(LSB(VENDOR_ID)), /* idVendor (LSB) */
(uint8_t)(MSB(VENDOR_ID)), /* idVendor (MSB) */
(uint8_t)(LSB(PRODUCT_ID)), /* idProduct (LSB) */
(uint8_t)(MSB(PRODUCT_ID)), /* idProduct (MSB) */
(uint8_t)(LSB(PRODUCT_RELEASE)), /* bcdDevice (LSB) */
(uint8_t)(MSB(PRODUCT_RELEASE)), /* bcdDevice (MSB) */
STRING_OFFSET_IMANUFACTURER, /* iManufacturer */
STRING_OFFSET_IPRODUCT, /* iProduct */
STRING_OFFSET_ISERIAL, /* iSerialNumber */
0x01 /* bNumConfigurations */
};
return deviceDescriptor;
}
uint8_t * USBDevice::stringLangidDesc() {
static uint8_t stringLangidDescriptor[] = {
0x04, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
0x09,0x04, /*bString Lang ID - 0x0409 - English*/
};
return stringLangidDescriptor;
}
uint8_t * USBDevice::stringImanufacturerDesc() {
static uint8_t stringImanufacturerDescriptor[] = {
0x12, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'm',0,'b',0,'e',0,'d',0,'.',0,'o',0,'r',0,'g',0, /*bString iManufacturer - mbed.org*/
};
return stringImanufacturerDescriptor;
}
uint8_t * USBDevice::stringIserialDesc() {
static uint8_t stringIserialDescriptor[] = {
0x16, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'0',0,'1',0,'2',0,'3',0,'4',0,'5',0,'6',0,'7',0,'8',0,'9',0, /*bString iSerial - 0123456789*/
};
return stringIserialDescriptor;
}
uint8_t * USBDevice::stringIConfigurationDesc() {
static uint8_t stringIconfigurationDescriptor[] = {
0x06, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'0',0,'1',0, /*bString iConfiguration - 01*/
};
return stringIconfigurationDescriptor;
}
uint8_t * USBDevice::stringIinterfaceDesc() {
static uint8_t stringIinterfaceDescriptor[] = {
0x08, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'U',0,'S',0,'B',0, /*bString iInterface - USB*/
};
return stringIinterfaceDescriptor;
}
uint8_t * USBDevice::stringIproductDesc() {
static uint8_t stringIproductDescriptor[] = {
0x16, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'U',0,'S',0,'B',0,' ',0,'D',0,'E',0,'V',0,'I',0,'C',0,'E',0 /*bString iProduct - USB DEVICE*/
};
return stringIproductDescriptor;
}
|
StanleyPhoneCalleeScript:
gettrainername STRING_BUFFER_3, BUG_CATCHER, STANLEY1
checkflag ENGINE_STANLEY
iftrue .WantsBattle
farscall PhoneScript_AnswerPhone_Male
checkflag ENGINE_STANLEY_TUESDAY_NIGHT
iftrue .NotTuesday
checkflag ENGINE_STANLEY_HAS_ITEM
iftrue .HasItem
readvar VAR_WEEKDAY
ifnotequal TUESDAY, .NotTuesday
checktime NITE
iftrue STANLEYTuesdayNight
.NotTuesday:
farscall PhoneScript_Random2
ifequal 0, .NoContest
checkflag ENGINE_DAILY_BUG_CONTEST
iftrue .NoContest
readvar VAR_WEEKDAY
ifequal TUESDAY, .ContestToday
ifequal THURSDAY, .ContestToday
ifequal SATURDAY, .ContestToday
.NoContest:
farsjump UnknownScript_0xa0938
.ContestToday:
farsjump PhoneScript_BugCatchingContest
.WantsBattle:
getlandmarkname STRING_BUFFER_5, ROUTE_31
farsjump UnknownScript_0xa0a50
.HasItem:
getlandmarkname STRING_BUFFER_5, ROUTE_31
farsjump UnknownScript_0xa0ab5
STANLEYPhoneCallerScript:
gettrainername STRING_BUFFER_3, BUG_CATCHER, STANLEY1
farscall PhoneScript_GreetPhone_Male
farscall PhoneScript_Random2
ifequal 0, .NoContest
checkflag ENGINE_DAILY_BUG_CONTEST
iftrue .NoContest
readvar VAR_WEEKDAY
ifequal TUESDAY, .ContestToday
ifequal THURSDAY, .ContestToday
ifequal SATURDAY, .ContestToday
.NoContest:
checkflag ENGINE_STANLEY
iftrue .next
checkflag ENGINE_STANLEY_TUESDAY_NIGHT
iftrue .next
checkflag ENGINE_STANLEY_HAS_ITEM
iftrue .next
farscall PhoneScript_Random2
ifequal 0, STANLEYHasItem2
checkflag ENGINE_FLYPOINT_GOLDENROD
iffalse .next
farscall PhoneScript_Random2
ifequal 0, STANLEYWantsBattle2
.next:
farscall PhoneScript_Random3
ifequal 0, STANLEYFoundRare
farsjump Phone_GenericCall_Male
.ContestToday:
farsjump PhoneScript_BugCatchingContest
STANLEYTuesdayNight:
setflag ENGINE_STANLEY_TUESDAY_NIGHT
STANLEYWantsBattle2:
getlandmarkname STRING_BUFFER_5, ROUTE_31
setflag ENGINE_STANLEY
farsjump PhoneScript_WantsToBattle_Male
STANLEYFoundRare:
farsjump Phone_CheckIfUnseenRare_Male
STANLEYHasItem2:
setflag ENGINE_STANLEY_HAS_ITEM
getlandmarkname STRING_BUFFER_5, ROUTE_31
clearevent EVENT_STANLEY_HAS_BERRY
clearevent EVENT_STANLEY_HAS_PSNCUREBERRY
clearevent EVENT_STANLEY_HAS_PRZCUREBERRY
clearevent EVENT_STANLEY_HAS_BITTER_BERRY
random 4
ifequal 0, .Berry
ifequal 1, .PsnCureBerry
ifequal 2, .PrzCureBerry
ifequal 3, .Bitterberry
.Berry:
setevent EVENT_STANLEY_HAS_BERRY
sjump .FoundBerry
.PsnCureBerry:
setevent EVENT_STANLEY_HAS_PSNCUREBERRY
sjump .FoundBerry
.PrzCureBerry:
setevent EVENT_STANLEY_HAS_PRZCUREBERRY
sjump .FoundBerry
.Bitterberry:
setevent EVENT_STANLEY_HAS_BITTER_BERRY
.FoundBerry:
farsjump PhoneScript_FoundItem_Male
|
MODULE kbhit
SECTION code_clib
PUBLIC kbhit
PUBLIC _kbhit
PUBLIC getch
PUBLIC _getch
EXTERN getk
EXTERN fgetc_cons
EXTERN CLIB_KBHIT_NOSTORE
kbhit:
_kbhit:
IF __CPU_GBZ80__
ld hl,kbhit_key
ld a,(hl+)
ld h,(hl)
ld l,a
or h
ret nz
call getk
ld a,CLIB_KBHIT_NOSTORE
and a
ret nz
ld de,kbhit_key
ld a,l
ld (de),a
inc de
ld a,h
ld (de),a
ld d,h
ld e,l
ret
ELSE
ld hl,(kbhit_key) ; check if we've got a keypress pending
ld a,h
or l
ret nz ; we've got something pending
call getk ; read the keyboard
ld a,CLIB_KBHIT_NOSTORE
and a
ret nz
ld (kbhit_key),hl
ret
ENDIF
getch:
_getch:
IF __CPU_GBZ80__
ld hl,kbhit_key
ld a,(hl+)
ld e,a
ld d,(hl)
xor a
ld (hl-),a
ld (hl),a
ld h,d
ld l,e
ELSE
ld hl,(kbhit_key)
ld de,0
IF __CPU_INTEL__
ex de,hl
ld (kbhit_key),hl
ex de,hl
ELSE
ld (kbhit_key),de
ENDIF
ENDIF
ld a,h
or l
ret nz ; consume that keypress
; We didn't have anything, lets just read the keyboard
call fgetc_cons
ret
SECTION bss_clib
kbhit_key: defw 0
|
; int w_array_empty_fastcall(b_array_t *a)
SECTION code_adt_w_array
PUBLIC _w_array_empty_fastcall
defc _w_array_empty_fastcall = asm_w_array_empty
INCLUDE "adt/w_array/z80/asm_w_array_empty.asm"
|
dnl ARM64 mpn_mod_34lsub1 -- remainder modulo 2^48-1.
dnl Copyright 2012-2014 Free Software Foundation, Inc.
dnl This file is part of the GNU MP Library.
dnl
dnl The GNU MP Library is free software; you can redistribute it and/or modify
dnl it under the terms of either:
dnl
dnl * the GNU Lesser General Public License as published by the Free
dnl Software Foundation; either version 3 of the License, or (at your
dnl option) any later version.
dnl
dnl or
dnl
dnl * the GNU General Public License as published by the Free Software
dnl Foundation; either version 2 of the License, or (at your option) any
dnl later version.
dnl
dnl or both in parallel, as here.
dnl
dnl The GNU MP Library is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
dnl for more details.
dnl
dnl You should have received copies of the GNU General Public License and the
dnl GNU Lesser General Public License along with the GNU MP Library. If not,
dnl see https://www.gnu.org/licenses/.
include(`../config.m4')
C cycles/limb
C Cortex-A53 2
C Cortex-A57 1
C X-Gene 1.45
define(`ap', x0)
define(`n', x1)
changecom(blah)
C mp_limb_t mpn_mod_34lsub1 (mp_srcptr up, mp_size_t n)
C TODO
C * An alternative inner loop which could run at 0.722 c/l on A57:
C adds x8, x8, x2
C adcs x9, x9, x3
C ldp x2, x3, [ap, #-32]
C adcs x10, x10, x4
C adc x12, x12, xzr
C adds x8, x8, x5
C ldp x4, x5, [ap, #-16]
C sub n, n, #6
C adcs x9, x9, x6
C adcs x10, x10, x7
C ldp x6, x7, [ap], #48
C adc x12, x12, xzr
C tbz n, #63, L(top)
ASM_START()
TEXT
ALIGN(32)
PROLOGUE(mpn_mod_34lsub1)
subs n, n, #3
mov x8, #0
b.lt L(le2) C n <= 2
ldp x2, x3, [ap, #0]
ldr x4, [ap, #16]
add ap, ap, #24
subs n, n, #3
b.lt L(sum) C n <= 5
cmn x0, #0 C clear carry
L(top): ldp x5, x6, [ap, #0]
ldr x7, [ap, #16]
add ap, ap, #24
sub n, n, #3
adcs x2, x2, x5
adcs x3, x3, x6
adcs x4, x4, x7
tbz n, #63, L(top)
adc x8, xzr, xzr C x8 <= 1
L(sum): cmn n, #2
mov x5, #0
b.lo 1f
ldr x5, [ap], #8
1: mov x6, #0
b.ls 1f
ldr x6, [ap], #8
1: adds x2, x2, x5
adcs x3, x3, x6
adcs x4, x4, xzr
adc x8, x8, xzr C x8 <= 2
L(sum2):
and x0, x2, #0xffffffffffff
add x0, x0, x2, lsr #48
add x0, x0, x8
lsl x8, x3, #16
and x1, x8, #0xffffffffffff
add x0, x0, x1
add x0, x0, x3, lsr #32
lsl x8, x4, #32
and x1, x8, #0xffffffffffff
add x0, x0, x1
add x0, x0, x4, lsr #16
ret
L(le2): cmn n, #1
b.ne L(1)
ldp x2, x3, [ap]
mov x4, #0
b L(sum2)
L(1): ldr x2, [ap]
and x0, x2, #0xffffffffffff
add x0, x0, x2, lsr #48
ret
EPILOGUE()
|
;*****************************************************************************
;* dct-64.asm: x86_64 transform and zigzag
;*****************************************************************************
;* Copyright (C) 2003-2020 x264 project
;*
;* Authors: Loren Merritt <lorenm@u.washington.edu>
;* Holger Lubitz <holger@lubitz.org>
;* Laurent Aimar <fenrir@via.ecp.fr>
;* Min Chen <chenm001.163.com>
;*
;* This program is free software; you can redistribute it and/or modify
;* it under the terms of the GNU General Public License as published by
;* the Free Software Foundation; either version 2 of the License, or
;* (at your option) any later version.
;*
;* This program is distributed in the hope that it will be useful,
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;* GNU General Public License for more details.
;*
;* You should have received a copy of the GNU General Public License
;* along with this program; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
;*
;* This program is also available under a commercial proprietary license.
;* For more information, contact us at licensing@x264.com.
;*****************************************************************************
%include "x86inc.asm"
%include "x86util.asm"
SECTION .text
cextern pd_32
cextern pw_pixel_max
cextern pw_2
cextern pw_m2
cextern pw_32
cextern hsub_mul
; in: size, m0..m7, temp, temp
; out: m0..m7
%macro DCT8_1D 11
SUMSUB_BA %1, %6, %5, %11 ; %6=s34, %5=d34
SUMSUB_BA %1, %7, %4, %11 ; %7=s25, %4=d25
SUMSUB_BA %1, %8, %3, %11 ; %8=s16, %3=d16
SUMSUB_BA %1, %9, %2, %11 ; %9=s07, %2=d07
SUMSUB_BA %1, %7, %8, %11 ; %7=a1, %8=a3
SUMSUB_BA %1, %6, %9, %11 ; %6=a0, %9=a2
psra%1 m%10, m%2, 1
padd%1 m%10, m%2
padd%1 m%10, m%3
padd%1 m%10, m%4 ; %10=a4
psra%1 m%11, m%5, 1
padd%1 m%11, m%5
padd%1 m%11, m%3
psub%1 m%11, m%4 ; %11=a7
SUMSUB_BA %1, %5, %2
psub%1 m%2, m%4
psub%1 m%5, m%3
psra%1 m%4, 1
psra%1 m%3, 1
psub%1 m%2, m%4 ; %2=a5
psub%1 m%5, m%3 ; %5=a6
psra%1 m%3, m%11, 2
padd%1 m%3, m%10 ; %3=b1
psra%1 m%10, 2
psub%1 m%10, m%11 ; %10=b7
SUMSUB_BA %1, %7, %6, %11 ; %7=b0, %6=b4
psra%1 m%4, m%8, 1
padd%1 m%4, m%9 ; %4=b2
psra%1 m%9, 1
psub%1 m%9, m%8 ; %9=b6
psra%1 m%8, m%5, 2
padd%1 m%8, m%2 ; %8=b3
psra%1 m%2, 2
psub%1 m%5, m%2 ; %5=b5
SWAP %2, %7, %5, %8, %9, %10
%endmacro
%macro IDCT8_1D 11
SUMSUB_BA %1, %6, %2, %10 ; %5=a0, %1=a2
psra%1 m%10, m%3, 1
padd%1 m%10, m%3
padd%1 m%10, m%5
padd%1 m%10, m%7 ; %9=a7
psra%1 m%11, m%4, 1
psub%1 m%11, m%8 ; %10=a4
psra%1 m%8, 1
padd%1 m%8, m%4 ; %7=a6
psra%1 m%4, m%7, 1
padd%1 m%4, m%7
padd%1 m%4, m%9
psub%1 m%4, m%3 ; %3=a5
psub%1 m%3, m%5
psub%1 m%7, m%5
padd%1 m%3, m%9
psub%1 m%7, m%9
psra%1 m%5, 1
psra%1 m%9, 1
psub%1 m%3, m%5 ; %2=a3
psub%1 m%7, m%9 ; %6=a1
psra%1 m%5, m%10, 2
padd%1 m%5, m%7 ; %4=b1
psra%1 m%7, 2
psub%1 m%10, m%7 ; %9=b7
SUMSUB_BA %1, %8, %6, %7 ; %7=b0, %5=b6
SUMSUB_BA %1, %11, %2, %7 ; %10=b2, %1=b4
psra%1 m%9, m%4, 2
padd%1 m%9, m%3 ; %8=b3
psra%1 m%3, 2
psub%1 m%3, m%4 ; %2=b5
SUMSUB_BA %1, %10, %8, %7 ; %9=c0, %7=c7
SUMSUB_BA %1, %3, %11, %7 ; %2=c1, %10=c6
SUMSUB_BA %1, %9, %2, %7 ; %8=c2, %1=c5
SUMSUB_BA %1, %5, %6, %7 ; %4=c3, %5=c4
SWAP %11, %4
SWAP %2, %10, %7
SWAP %4, %9, %8
%endmacro
%if HIGH_BIT_DEPTH
%macro SUB8x8_DCT8 0
cglobal sub8x8_dct8, 3,3,14
TAIL_CALL .skip_prologue, 0
cglobal_label .skip_prologue
LOAD_DIFF8x4 0,1,2,3, none,none, r1, r2
LOAD_DIFF8x4 4,5,6,7, none,none, r1, r2
DCT8_1D w, 0,1,2,3,4,5,6,7, 8,9
TRANSPOSE4x4W 0,1,2,3,8
WIDEN_SXWD 0,8
WIDEN_SXWD 1,9
WIDEN_SXWD 2,10
WIDEN_SXWD 3,11
DCT8_1D d, 0,8,1,9,2,10,3,11, 12,13
mova [r0+0x00], m0
mova [r0+0x20], m8
mova [r0+0x40], m1
mova [r0+0x60], m9
mova [r0+0x80], m2
mova [r0+0xA0], m10
mova [r0+0xC0], m3
mova [r0+0xE0], m11
TRANSPOSE4x4W 4,5,6,7,0
WIDEN_SXWD 4,0
WIDEN_SXWD 5,1
WIDEN_SXWD 6,2
WIDEN_SXWD 7,3
DCT8_1D d,4,0,5,1,6,2,7,3, 8,9
mova [r0+0x10], m4
mova [r0+0x30], m0
mova [r0+0x50], m5
mova [r0+0x70], m1
mova [r0+0x90], m6
mova [r0+0xB0], m2
mova [r0+0xD0], m7
mova [r0+0xF0], m3
ret
%endmacro ; SUB8x8_DCT8
INIT_XMM sse2
SUB8x8_DCT8
INIT_XMM sse4
SUB8x8_DCT8
INIT_XMM avx
SUB8x8_DCT8
%macro ADD8x8_IDCT8 0
cglobal add8x8_idct8, 2,2,16
add r1, 128
TAIL_CALL .skip_prologue, 0
cglobal_label .skip_prologue
mova m0, [r1-128]
mova m1, [r1-96]
mova m2, [r1-64]
mova m3, [r1-32]
mova m4, [r1+ 0]
mova m5, [r1+32]
mova m6, [r1+64]
mova m7, [r1+96]
IDCT8_1D d,0,1,2,3,4,5,6,7,8,9
TRANSPOSE4x4D 0,1,2,3,8
TRANSPOSE4x4D 4,5,6,7,8
paddd m0, [pd_32]
paddd m4, [pd_32]
mova [r1+64], m6
mova [r1+96], m7
mova m8, [r1-112]
mova m9, [r1-80]
mova m10, [r1-48]
mova m11, [r1-16]
mova m12, [r1+16]
mova m13, [r1+48]
mova m14, [r1+80]
mova m15, [r1+112]
IDCT8_1D d,8,9,10,11,12,13,14,15,6,7
TRANSPOSE4x4D 8,9,10,11,6
TRANSPOSE4x4D 12,13,14,15,6
IDCT8_1D d,0,1,2,3,8,9,10,11,6,7
mova [r1-112], m8
mova [r1-80], m9
mova m6, [r1+64]
mova m7, [r1+96]
IDCT8_1D d,4,5,6,7,12,13,14,15,8,9
pxor m8, m8
mova m9, [pw_pixel_max]
STORE_DIFF m0, m4, m8, m9, [r0+0*FDEC_STRIDEB]
STORE_DIFF m1, m5, m8, m9, [r0+1*FDEC_STRIDEB]
STORE_DIFF m2, m6, m8, m9, [r0+2*FDEC_STRIDEB]
STORE_DIFF m3, m7, m8, m9, [r0+3*FDEC_STRIDEB]
mova m0, [r1-112]
mova m1, [r1-80]
STORE_DIFF m0, m12, m8, m9, [r0+4*FDEC_STRIDEB]
STORE_DIFF m1, m13, m8, m9, [r0+5*FDEC_STRIDEB]
STORE_DIFF m10, m14, m8, m9, [r0+6*FDEC_STRIDEB]
STORE_DIFF m11, m15, m8, m9, [r0+7*FDEC_STRIDEB]
ret
%endmacro ; ADD8x8_IDCT8
INIT_XMM sse2
ADD8x8_IDCT8
INIT_XMM avx
ADD8x8_IDCT8
%else ; !HIGH_BIT_DEPTH
%macro DCT_SUB8 0
cglobal sub8x8_dct, 3,3,10
add r2, 4*FDEC_STRIDE
%if cpuflag(ssse3)
mova m7, [hsub_mul]
%endif
TAIL_CALL .skip_prologue, 0
cglobal_label .skip_prologue
SWAP 7, 9
LOAD_DIFF8x4 0, 1, 2, 3, 8, 9, r1, r2-4*FDEC_STRIDE
LOAD_DIFF8x4 4, 5, 6, 7, 8, 9, r1, r2-4*FDEC_STRIDE
DCT4_1D 0, 1, 2, 3, 8
TRANSPOSE2x4x4W 0, 1, 2, 3, 8
DCT4_1D 4, 5, 6, 7, 8
TRANSPOSE2x4x4W 4, 5, 6, 7, 8
DCT4_1D 0, 1, 2, 3, 8
STORE_DCT 0, 1, 2, 3, r0, 0
DCT4_1D 4, 5, 6, 7, 8
STORE_DCT 4, 5, 6, 7, r0, 64
ret
;-----------------------------------------------------------------------------
; void sub8x8_dct8( int16_t dct[8][8], uint8_t *pix1, uint8_t *pix2 )
;-----------------------------------------------------------------------------
cglobal sub8x8_dct8, 3,3,11
add r2, 4*FDEC_STRIDE
%if cpuflag(ssse3)
mova m7, [hsub_mul]
%endif
TAIL_CALL .skip_prologue, 0
cglobal_label .skip_prologue
SWAP 7, 10
LOAD_DIFF8x4 0, 1, 2, 3, 4, 10, r1, r2-4*FDEC_STRIDE
LOAD_DIFF8x4 4, 5, 6, 7, 8, 10, r1, r2-4*FDEC_STRIDE
DCT8_1D w, 0,1,2,3,4,5,6,7,8,9
TRANSPOSE8x8W 0,1,2,3,4,5,6,7,8
DCT8_1D w, 0,1,2,3,4,5,6,7,8,9
movdqa [r0+0x00], m0
movdqa [r0+0x10], m1
movdqa [r0+0x20], m2
movdqa [r0+0x30], m3
movdqa [r0+0x40], m4
movdqa [r0+0x50], m5
movdqa [r0+0x60], m6
movdqa [r0+0x70], m7
ret
%endmacro
INIT_XMM sse2
%define movdqa movaps
%define punpcklqdq movlhps
DCT_SUB8
%undef movdqa
%undef punpcklqdq
INIT_XMM ssse3
DCT_SUB8
INIT_XMM avx
DCT_SUB8
INIT_XMM xop
DCT_SUB8
INIT_YMM avx2
cglobal sub16x16_dct8, 3,3,10
add r0, 128
add r2, 4*FDEC_STRIDE
call .sub16x8_dct8
add r0, 256
add r1, FENC_STRIDE*8
add r2, FDEC_STRIDE*8
call .sub16x8_dct8
RET
.sub16x8_dct8:
LOAD_DIFF16x2_AVX2 0, 1, 2, 3, 0, 1
LOAD_DIFF16x2_AVX2 2, 3, 4, 5, 2, 3
LOAD_DIFF16x2_AVX2 4, 5, 6, 7, 4, 5
LOAD_DIFF16x2_AVX2 6, 7, 8, 9, 6, 7
DCT8_1D w, 0,1,2,3,4,5,6,7,8,9
TRANSPOSE8x8W 0,1,2,3,4,5,6,7,8
DCT8_1D w, 0,1,2,3,4,5,6,7,8,9
mova [r0-0x80+0x00], xm0
vextracti128 [r0+0x00], m0, 1
mova [r0-0x80+0x10], xm1
vextracti128 [r0+0x10], m1, 1
mova [r0-0x80+0x20], xm2
vextracti128 [r0+0x20], m2, 1
mova [r0-0x80+0x30], xm3
vextracti128 [r0+0x30], m3, 1
mova [r0-0x80+0x40], xm4
vextracti128 [r0+0x40], m4, 1
mova [r0-0x80+0x50], xm5
vextracti128 [r0+0x50], m5, 1
mova [r0-0x80+0x60], xm6
vextracti128 [r0+0x60], m6, 1
mova [r0-0x80+0x70], xm7
vextracti128 [r0+0x70], m7, 1
ret
;-----------------------------------------------------------------------------
; void add8x8_idct8( uint8_t *p_dst, int16_t dct[8][8] )
;-----------------------------------------------------------------------------
%macro ADD8x8_IDCT8 0
cglobal add8x8_idct8, 2,2,11
add r0, 4*FDEC_STRIDE
pxor m7, m7
TAIL_CALL .skip_prologue, 0
cglobal_label .skip_prologue
SWAP 7, 9
movdqa m0, [r1+0x00]
movdqa m1, [r1+0x10]
movdqa m2, [r1+0x20]
movdqa m3, [r1+0x30]
movdqa m4, [r1+0x40]
movdqa m5, [r1+0x50]
movdqa m6, [r1+0x60]
movdqa m7, [r1+0x70]
IDCT8_1D w,0,1,2,3,4,5,6,7,8,10
TRANSPOSE8x8W 0,1,2,3,4,5,6,7,8
paddw m0, [pw_32] ; rounding for the >>6 at the end
IDCT8_1D w,0,1,2,3,4,5,6,7,8,10
DIFFx2 m0, m1, m8, m9, [r0-4*FDEC_STRIDE], [r0-3*FDEC_STRIDE]
DIFFx2 m2, m3, m8, m9, [r0-2*FDEC_STRIDE], [r0-1*FDEC_STRIDE]
DIFFx2 m4, m5, m8, m9, [r0+0*FDEC_STRIDE], [r0+1*FDEC_STRIDE]
DIFFx2 m6, m7, m8, m9, [r0+2*FDEC_STRIDE], [r0+3*FDEC_STRIDE]
STORE_IDCT m1, m3, m5, m7
ret
%endmacro ; ADD8x8_IDCT8
INIT_XMM sse2
ADD8x8_IDCT8
INIT_XMM avx
ADD8x8_IDCT8
;-----------------------------------------------------------------------------
; void add8x8_idct( uint8_t *pix, int16_t dct[4][4][4] )
;-----------------------------------------------------------------------------
%macro ADD8x8 0
cglobal add8x8_idct, 2,2,11
add r0, 4*FDEC_STRIDE
pxor m7, m7
TAIL_CALL .skip_prologue, 0
cglobal_label .skip_prologue
SWAP 7, 9
mova m0, [r1+ 0]
mova m2, [r1+16]
mova m1, [r1+32]
mova m3, [r1+48]
SBUTTERFLY qdq, 0, 1, 4
SBUTTERFLY qdq, 2, 3, 4
mova m4, [r1+64]
mova m6, [r1+80]
mova m5, [r1+96]
mova m7, [r1+112]
SBUTTERFLY qdq, 4, 5, 8
SBUTTERFLY qdq, 6, 7, 8
IDCT4_1D w,0,1,2,3,8,10
TRANSPOSE2x4x4W 0,1,2,3,8
IDCT4_1D w,4,5,6,7,8,10
TRANSPOSE2x4x4W 4,5,6,7,8
paddw m0, [pw_32]
IDCT4_1D w,0,1,2,3,8,10
paddw m4, [pw_32]
IDCT4_1D w,4,5,6,7,8,10
DIFFx2 m0, m1, m8, m9, [r0-4*FDEC_STRIDE], [r0-3*FDEC_STRIDE]
DIFFx2 m2, m3, m8, m9, [r0-2*FDEC_STRIDE], [r0-1*FDEC_STRIDE]
DIFFx2 m4, m5, m8, m9, [r0+0*FDEC_STRIDE], [r0+1*FDEC_STRIDE]
DIFFx2 m6, m7, m8, m9, [r0+2*FDEC_STRIDE], [r0+3*FDEC_STRIDE]
STORE_IDCT m1, m3, m5, m7
ret
%endmacro ; ADD8x8
INIT_XMM sse2
ADD8x8
INIT_XMM avx
ADD8x8
%endif ; !HIGH_BIT_DEPTH
|
; A001024: Powers of 15.
; 1,15,225,3375,50625,759375,11390625,170859375,2562890625,38443359375,576650390625,8649755859375,129746337890625,1946195068359375,29192926025390625,437893890380859375,6568408355712890625,98526125335693359375,1477891880035400390625,22168378200531005859375,332525673007965087890625,4987885095119476318359375,74818276426792144775390625,1122274146401882171630859375,16834112196028232574462890625,252511682940423488616943359375,3787675244106352329254150390625,56815128661595284938812255859375
mov $1,15
pow $1,$0
mov $0,$1
|
;| This programm translate string of numbers (msg) into hex type
;|----------------------------------------------------------------------------------------------
.model tiny
.code
.386
org 100h
VIDEOSEG equ 0b800h
WFRAME equ 35 ;
HFRAME equ 6 ;
COUNTSPACE1 equ 43 ;
COUNTSPACE2 equ 35 ;
start:
mov ax, 0b800h ; | mov es, 0b800h
mov es, ax ; |
xor ax, ax
mov al, 80 ; | al = 80y
mov bl, y ; |
mul bl ; |
add al, x
adc ah, 0
push ax
xor dx, dx
mov dl, x
add ax, dx
pop ax
shl ax, 1
mov bx, ax
mov es:[bx], 0c9h ; print begin left
mov byte ptr es:[bx+1], 4eh
add bx, 2
mov ax, 0
mov dl, 0cdh ; print ------
UpFr:
mov es:[bx], dl
mov byte ptr es:[bx+1], 4eh
add bx, 2
inc ax
cmp ax, WFRAME
jne UpFr
mov es:[bx], 0bbh ; print begin right
mov byte ptr es:[bx+1], 4eh
add bx, 2
mov si, 0
MainCicle:
mov cx, 0
mov dl, 20h
MakeSpace1:
mov es:[bx], dl ; ¯¥à¥å®€š¬ ®¢ãî áâபã
mov byte ptr es:[bx+1], 07h
add bx, 2
inc cx
cmp cx, COUNTSPACE1
jne MakeSpace1
mov dl, 0bah ; § ªš€ë¢ ¥¬ || ¯¥à¥€ ¯à®¡¥« ¬š
mov es:[bx], dl
mov byte ptr es:[bx+1], 4eh
add bx, 2
mov cx, 0
mov dl, 20h
MakeSpace2: mov es:[bx], dl ; ¯šè¥¬ ¯à®¡¥«ë ¬¥Š€ã || ||
mov byte ptr es:[bx+1], 4eh
add bx, 2
inc cx
cmp cx, WFRAME
jne MakeSpace2
mov dl, 0bah ; § ªàë¢ ¥¬ áâபã á ¯à®¡¥« ¬š ||
mov es:[bx], dl
mov byte ptr es:[bx+1], 4eh
add bx, 2
inc si
cmp si, HFRAME
jne MainCicle
mov cx, 0
mov dl, 20h
MakeSpace3:
mov es:[bx], dl ; ¯¥à¥å®€š¬ ®¢ãî áâபã
mov byte ptr es:[bx+1], 07h
add bx, 2
inc cx
cmp cx, COUNTSPACE1
jne MakeSpace3
mov es:[bx], 0c8h ; print begin left
mov byte ptr es:[bx+1], 4eh
add bx, 2
mov ax, 0
mov dl, 0cdh ; print ------
UndFr:
mov es:[bx], dl
mov byte ptr es:[bx+1], 4eh
add bx, 2
inc ax
cmp ax, WFRAME
jne UndFr
mov es:[bx], 0bch ; print begin right
mov byte ptr es:[bx+1], 4eh
add bx, 2
;*****************************************************************************************
xor ax, ax
mov al, msglen ; cx = strlen
adc ah, 0
mov cx, ax
dec cx
mov di, 0
mov bx, 0
mov si, offset msg ; si = &msg
Remul: mov al, [si] ; ax = str[si]
inc si ; si++
inc di
sub al, '0' ; al -= '0'
push ax
xor ax, ax
mov ax, bx ; ax = bx
mov bx, 10
mul bx ; ax = ax * 10
mov bx, ax ;
pop ax
add bx, ax ; bx += al
cmp di, cx
jne Remul
mov ax, bx
push ax ; PPPPPUSSHSHHH
;*****************************************************************************************
mov ax, 0b800h ; | mov es, 0b800h
mov es, ax ; |
xor ax, ax
mov al, 80 ; | al = 80y
mov bl, Ypict ; |
mul bl ; |
add al, Xpict
adc ah, 0
push ax
xor dx, dx
mov dl, Xpict
add ax, dx
pop ax
shl ax, 1
mov bx, ax
;---------------------------------------------------------------------------------------------
pop ax ; PPPPPPOOPPP
;---------------------------------------------------------------------------------------------
std
mov di, bx
mov cx, 16 ; system of numbers
HexTran:
xor dx, dx ; dx = 0
div cx ; ax = ax / 16
cmp dx, 10
je Ten
cmp dx, 11
je Elev
cmp dx, 12
je Twel
cmp dx, 13
je Thir
cmp dx, 14
je Four
cmp dx, 15
je Fift
xchg ax, dx ; swap( ax, dx )
add ax, '0' ; al += byte code '0'
; xor ah, ah
stosb ; put al into videoseg
push ax ; put ax into stk
xor al, al ; al = 0
mov al, 4eh ; put param into al
stosb ; put param into videoseg
pop ax ; get ax from stk
xchg ax, dx ; swap( ax, dx )
or ax, ax ; cicle if ax
jne HexTran
je EndProg
Ten:
push ax
mov al, 'A'
stosb
mov al, 4eh
stosb
pop ax
cmp ax, 0
jne HexTran
je EndProg
Elev:
push ax
mov al, 'B'
stosb
mov al, 4eh
stosb
pop ax
cmp ax, 0
jne HexTran
je EndProg
Twel:
push ax
mov al, 'C'
stosb
mov al, 4eh
stosb
pop ax
cmp ax, 0
jne HexTran
je EndProg
Thir:
push ax
mov al, 'D'
stosb
mov al, 4eh
stosb
pop ax
cmp ax, 0
jne HexTran
je EndProg
Four:
push ax
mov al, 'E'
stosb
mov al, 4eh
stosb
pop ax
cmp ax, 0
jne HexTran
je EndProg
Fift:
push ax
mov al, 'F'
stosb
mov al, 4eh
stosb
pop ax
cmp ax, 0
jne HexTran
je EndProg
EndProg: mov ax, 4c00h
int 21h
.data
WX db 160
x db 80/2 - (WFRAME/2)
y db 25/2 - (HFRAME /2)
Xpict db (80/2)+1
Ypict db (25/2 )
msg db '75', '$'
msglen db ($ - msg)
end start
|
/*
* 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.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <arrow-glib/arrow-glib.hpp>
#include <parquet-glib/arrow-file-writer.hpp>
G_BEGIN_DECLS
/**
* SECTION: arrow-file-writer
* @short_description: Arrow file writer class
* @include: parquet-glib/parquet-glib.h
*
* #GParquetWriterProperties is a class for the writer properties.
*
* #GParquetArrowFileWriter is a class for writer Apache Arrow data to
* file as Apache Parquet format.
*/
typedef struct GParquetWriterPropertiesPrivate_ {
std::shared_ptr<parquet::WriterProperties> properties;
parquet::WriterProperties::Builder *builder;
gboolean changed;
} GParquetWriterPropertiesPrivate;
G_DEFINE_TYPE_WITH_PRIVATE(GParquetWriterProperties,
gparquet_writer_properties,
G_TYPE_OBJECT)
#define GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(object) \
static_cast<GParquetWriterPropertiesPrivate *>( \
gparquet_writer_properties_get_instance_private( \
GPARQUET_WRITER_PROPERTIES(object)))
static void
gparquet_writer_properties_finalize(GObject *object)
{
auto priv = GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(object);
priv->properties.~shared_ptr();
delete priv->builder;
G_OBJECT_CLASS(gparquet_writer_properties_parent_class)->finalize(object);
}
static void
gparquet_writer_properties_init(GParquetWriterProperties *object)
{
auto priv = GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(object);
new(&priv->properties) std::shared_ptr<parquet::WriterProperties>;
priv->builder = new parquet::WriterProperties::Builder();
priv->changed = TRUE;
}
static void
gparquet_writer_properties_class_init(GParquetWriterPropertiesClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = gparquet_writer_properties_finalize;
}
/**
* gparquet_writer_properties_new:
*
* Return: A newly created #GParquetWriterProperties.
*
* Since: 1.0.0
*/
GParquetWriterProperties *
gparquet_writer_properties_new(void)
{
auto writer_properties = g_object_new(GPARQUET_TYPE_WRITER_PROPERTIES,
NULL);
return GPARQUET_WRITER_PROPERTIES(writer_properties);
}
/**
* gparquet_writer_properties_set_compression:
* @properties: A #GParquetWriterProperties.
* @compression_type: A #GArrowCompressionType.
* @path: (nullable): The column path as dot string.
*
* Since: 1.0.0
*/
void
gparquet_writer_properties_set_compression(GParquetWriterProperties *properties,
GArrowCompressionType compression_type,
const gchar *path)
{
auto arrow_compression_type = garrow_compression_type_to_raw(compression_type);
auto priv = GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(properties);
if (path) {
priv->builder->compression(path, arrow_compression_type);
} else {
priv->builder->compression(arrow_compression_type);
}
priv->changed = TRUE;
}
/**
* gparquet_writer_properties_get_compression_path:
* @properties: A #GParquetWriterProperties.
* @path: The path as dot string.
*
* Returns: The compression type of #GParquetWriterProperties.
*
* Since: 1.0.0
*/
GArrowCompressionType
gparquet_writer_properties_get_compression_path(GParquetWriterProperties *properties,
const gchar *path)
{
auto parquet_properties = gparquet_writer_properties_get_raw(properties);
auto parquet_column_path = parquet::schema::ColumnPath::FromDotString(path);
auto arrow_compression = parquet_properties->compression(parquet_column_path);
return garrow_compression_type_from_raw(arrow_compression);
}
/**
* gparquet_writer_properties_enable_dictionary:
* @properties: A #GParquetWriterProperties.
* @path: (nullable): The column path as dot string.
*
* Since: 1.0.0
*/
void
gparquet_writer_properties_enable_dictionary(GParquetWriterProperties *properties,
const gchar *path)
{
auto priv = GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(properties);
if (path) {
priv->builder->enable_dictionary(path);
} else {
priv->builder->enable_dictionary();
}
priv->changed = TRUE;
}
/**
* gparquet_writer_properties_disable_dictionary:
* @properties: A #GParquetWriterProperties.
* @path: (nullable): The column path as dot string.
*
* Since: 1.0.0
*/
void
gparquet_writer_properties_disable_dictionary(GParquetWriterProperties *properties,
const gchar *path)
{
auto priv = GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(properties);
if (path) {
priv->builder->disable_dictionary(path);
} else {
priv->builder->disable_dictionary();
}
priv->changed = TRUE;
}
/**
* gparquet_writer_properties_is_dictionary_enabled:
* @properties: A #GParquetWriterProperties.
* @path: The path as dot string.
*
* Returns: %TRUE on dictionary enabled, %FALSE on dictionary disabled.
*
* Since: 1.0.0
*/
gboolean
gparquet_writer_properties_is_dictionary_enabled(GParquetWriterProperties *properties,
const gchar *path)
{
auto parquet_properties = gparquet_writer_properties_get_raw(properties);
auto parquet_column_path = parquet::schema::ColumnPath::FromDotString(path);
return parquet_properties->dictionary_enabled(parquet_column_path);
}
/**
* gparquet_writer_properties_set_dictionary_page_size_limit:
* @properties: A #GParquetWriterProperties.
* @limit: The dictionary page size limit.
*
* Since: 1.0.0
*/
void
gparquet_writer_properties_set_dictionary_page_size_limit(GParquetWriterProperties *properties,
gint64 limit)
{
auto priv = GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(properties);
priv->builder->dictionary_pagesize_limit(limit);
priv->changed = TRUE;
}
/**
* gparquet_writer_properties_get_dictionary_page_size_limit:
* @properties: A #GParquetWriterProperties.
*
* Returns: The dictionary page size limit.
*
* Since: 1.0.0
*/
gint64
gparquet_writer_properties_get_dictionary_page_size_limit(GParquetWriterProperties *properties)
{
auto parquet_properties = gparquet_writer_properties_get_raw(properties);
return parquet_properties->dictionary_pagesize_limit();
}
/**
* gparquet_writer_properties_set_batch_size:
* @properties: A #GParquetWriterProperties.
* @batch_size: The batch size.
*
* Since: 1.0.0
*/
void
gparquet_writer_properties_set_batch_size(GParquetWriterProperties *properties,
gint64 batch_size)
{
auto priv = GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(properties);
priv->builder->write_batch_size(batch_size);
priv->changed = TRUE;
}
/**
* gparquet_writer_properties_get_batch_size:
* @properties: A #GParquetWriterProperties.
*
* Returns: The batch size.
*
* Since: 1.0.0
*/
gint64
gparquet_writer_properties_get_batch_size(GParquetWriterProperties *properties)
{
auto parquet_properties = gparquet_writer_properties_get_raw(properties);
return parquet_properties->write_batch_size();
}
/**
* gparquet_writer_properties_set_max_row_group_length:
* @properties: A #GParquetWriterProperties.
* @length: The max row group length.
*
* Since: 1.0.0
*/
void
gparquet_writer_properties_set_max_row_group_length(GParquetWriterProperties *properties,
gint64 length)
{
auto priv = GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(properties);
priv->builder->max_row_group_length(length);
priv->changed = TRUE;
}
/**
* gparquet_writer_properties_get_max_row_group_length:
* @properties: A #GParquetWriterProperties.
*
* Returns: The max row group length.
*
* Since: 1.0.0
*/
gint64
gparquet_writer_properties_get_max_row_group_length(GParquetWriterProperties *properties)
{
auto parquet_properties = gparquet_writer_properties_get_raw(properties);
return parquet_properties->max_row_group_length();
}
/**
* gparquet_writer_properties_set_data_page_size:
* @properties: A #GParquetWriterProperties.
* @data_page_size: The data page size.
*
* Since: 1.0.0
*/
void
gparquet_writer_properties_set_data_page_size(GParquetWriterProperties *properties,
gint64 data_page_size)
{
auto priv = GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(properties);
priv->builder->data_pagesize(data_page_size);
priv->changed = TRUE;
}
/**
* gparquet_writer_properties_get_data_page_size:
* @properties: A #GParquetWriterProperties.
*
* Returns: The data page size.
*
* Since: 1.0.0
*/
gint64
gparquet_writer_properties_get_data_page_size(GParquetWriterProperties *properties)
{
auto parquet_properties = gparquet_writer_properties_get_raw(properties);
return parquet_properties->data_pagesize();
}
typedef struct GParquetArrowFileWriterPrivate_ {
parquet::arrow::FileWriter *arrow_file_writer;
} GParquetArrowFileWriterPrivate;
enum {
PROP_0,
PROP_ARROW_FILE_WRITER
};
G_DEFINE_TYPE_WITH_PRIVATE(GParquetArrowFileWriter,
gparquet_arrow_file_writer,
G_TYPE_OBJECT)
#define GPARQUET_ARROW_FILE_WRITER_GET_PRIVATE(obj) \
static_cast<GParquetArrowFileWriterPrivate *>( \
gparquet_arrow_file_writer_get_instance_private( \
GPARQUET_ARROW_FILE_WRITER(obj)))
static void
gparquet_arrow_file_writer_finalize(GObject *object)
{
auto priv = GPARQUET_ARROW_FILE_WRITER_GET_PRIVATE(object);
delete priv->arrow_file_writer;
G_OBJECT_CLASS(gparquet_arrow_file_writer_parent_class)->finalize(object);
}
static void
gparquet_arrow_file_writer_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GPARQUET_ARROW_FILE_WRITER_GET_PRIVATE(object);
switch (prop_id) {
case PROP_ARROW_FILE_WRITER:
priv->arrow_file_writer =
static_cast<parquet::arrow::FileWriter *>(g_value_get_pointer(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
gparquet_arrow_file_writer_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
gparquet_arrow_file_writer_init(GParquetArrowFileWriter *object)
{
}
static void
gparquet_arrow_file_writer_class_init(GParquetArrowFileWriterClass *klass)
{
GParamSpec *spec;
auto gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = gparquet_arrow_file_writer_finalize;
gobject_class->set_property = gparquet_arrow_file_writer_set_property;
gobject_class->get_property = gparquet_arrow_file_writer_get_property;
spec = g_param_spec_pointer("arrow-file-writer",
"ArrowFileWriter",
"The raw std::shared<parquet::arrow::FileWriter> *",
static_cast<GParamFlags>(G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property(gobject_class, PROP_ARROW_FILE_WRITER, spec);
}
/**
* gparquet_arrow_file_writer_new_arrow:
* @schema: Arrow schema for written data.
* @sink: Arrow output stream to be written.
* @writer_properties: (nullable): A #GParquetWriterProperties.
* @error: (nullable): Return locatipcn for a #GError or %NULL.
*
* Returns: (nullable): A newly created #GParquetArrowFileWriter.
*
* Since: 0.11.0
*/
GParquetArrowFileWriter *
gparquet_arrow_file_writer_new_arrow(GArrowSchema *schema,
GArrowOutputStream *sink,
GParquetWriterProperties *writer_properties,
GError **error)
{
auto arrow_schema = garrow_schema_get_raw(schema).get();
auto arrow_output_stream = garrow_output_stream_get_raw(sink);
auto arrow_memory_pool = arrow::default_memory_pool();
std::unique_ptr<parquet::arrow::FileWriter> parquet_arrow_file_writer;
arrow::Status status;
if (writer_properties) {
auto parquet_writer_properties = gparquet_writer_properties_get_raw(writer_properties);
status = parquet::arrow::FileWriter::Open(*arrow_schema,
arrow_memory_pool,
arrow_output_stream,
parquet_writer_properties,
&parquet_arrow_file_writer);
} else {
auto parquet_writer_properties = parquet::default_writer_properties();
status = parquet::arrow::FileWriter::Open(*arrow_schema,
arrow_memory_pool,
arrow_output_stream,
parquet_writer_properties,
&parquet_arrow_file_writer);
}
if (garrow_error_check(error,
status,
"[parquet][arrow][file-writer][new-arrow]")) {
return gparquet_arrow_file_writer_new_raw(parquet_arrow_file_writer.release());
} else {
return NULL;
}
}
/**
* gparquet_arrow_file_writer_new_path:
* @schema: Arrow schema for written data.
* @path: Path to be read.
* @writer_properties: (nullable): A #GParquetWriterProperties.
* @error: (nullable): Return locatipcn for a #GError or %NULL.
*
* Returns: (nullable): A newly created #GParquetArrowFileWriter.
*
* Since: 0.11.0
*/
GParquetArrowFileWriter *
gparquet_arrow_file_writer_new_path(GArrowSchema *schema,
const gchar *path,
GParquetWriterProperties *writer_properties,
GError **error)
{
auto arrow_file_output_stream =
arrow::io::FileOutputStream::Open(path, false);
if (!garrow::check(error,
arrow_file_output_stream,
"[parquet][arrow][file-writer][new-path]")) {
return NULL;
}
auto arrow_schema = garrow_schema_get_raw(schema).get();
std::shared_ptr<arrow::io::OutputStream> arrow_output_stream =
arrow_file_output_stream.ValueOrDie();
auto arrow_memory_pool = arrow::default_memory_pool();
std::unique_ptr<parquet::arrow::FileWriter> parquet_arrow_file_writer;
arrow::Status status;
if (writer_properties) {
auto parquet_writer_properties = gparquet_writer_properties_get_raw(writer_properties);
status = parquet::arrow::FileWriter::Open(*arrow_schema,
arrow_memory_pool,
arrow_output_stream,
parquet_writer_properties,
&parquet_arrow_file_writer);
} else {
auto parquet_writer_properties = parquet::default_writer_properties();
status = parquet::arrow::FileWriter::Open(*arrow_schema,
arrow_memory_pool,
arrow_output_stream,
parquet_writer_properties,
&parquet_arrow_file_writer);
}
if (garrow::check(error,
status,
"[parquet][arrow][file-writer][new-path]")) {
return gparquet_arrow_file_writer_new_raw(parquet_arrow_file_writer.release());
} else {
return NULL;
}
}
/**
* gparquet_arrow_file_writer_write_table:
* @writer: A #GParquetArrowFileWriter.
* @table: A table to be written.
* @chunk_size: The max number of rows in a row group.
* @error: (nullable): Return locatipcn for a #GError or %NULL.
*
* Returns: %TRUE on success, %FALSE if there was an error.
*
* Since: 0.11.0
*/
gboolean
gparquet_arrow_file_writer_write_table(GParquetArrowFileWriter *writer,
GArrowTable *table,
guint64 chunk_size,
GError **error)
{
auto parquet_arrow_file_writer = gparquet_arrow_file_writer_get_raw(writer);
auto arrow_table = garrow_table_get_raw(table).get();
auto status = parquet_arrow_file_writer->WriteTable(*arrow_table, chunk_size);
return garrow_error_check(error,
status,
"[parquet][arrow][file-writer][write-table]");
}
/**
* gparquet_arrow_file_writer_close:
* @writer: A #GParquetArrowFileWriter.
* @error: (nullable): Return locatipcn for a #GError or %NULL.
*
* Returns: %TRUE on success, %FALSE if there was an error.
*
* Since: 0.11.0
*/
gboolean
gparquet_arrow_file_writer_close(GParquetArrowFileWriter *writer,
GError **error)
{
auto parquet_arrow_file_writer = gparquet_arrow_file_writer_get_raw(writer);
auto status = parquet_arrow_file_writer->Close();
return garrow_error_check(error,
status,
"[parquet][arrow][file-writer][close]");
}
G_END_DECLS
GParquetArrowFileWriter *
gparquet_arrow_file_writer_new_raw(parquet::arrow::FileWriter *parquet_arrow_file_writer)
{
auto arrow_file_writer =
GPARQUET_ARROW_FILE_WRITER(g_object_new(GPARQUET_TYPE_ARROW_FILE_WRITER,
"arrow-file-writer", parquet_arrow_file_writer,
NULL));
return arrow_file_writer;
}
parquet::arrow::FileWriter *
gparquet_arrow_file_writer_get_raw(GParquetArrowFileWriter *arrow_file_writer)
{
auto priv = GPARQUET_ARROW_FILE_WRITER_GET_PRIVATE(arrow_file_writer);
return priv->arrow_file_writer;
}
std::shared_ptr<parquet::WriterProperties>
gparquet_writer_properties_get_raw(GParquetWriterProperties *properties)
{
auto priv = GPARQUET_WRITER_PROPERTIES_GET_PRIVATE(properties);
if (priv->changed) {
priv->properties = priv->builder->build();
priv->changed = FALSE;
}
return priv->properties;
}
|
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2011 Thomas Bernard
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(SPIRIT_KEYWORDS_OR_MARCH_13_2007_1145PM)
#define SPIRIT_KEYWORDS_OR_MARCH_13_2007_1145PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/detail/permute_function.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/detail/what_function.hpp>
#include <boost/spirit/home/support/info.hpp>
#include <boost/spirit/home/support/unused.hpp>
#include <boost/fusion/include/iter_fold.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/fusion/include/value_at.hpp>
#include <boost/optional.hpp>
#include <boost/foreach.hpp>
#include <boost/array.hpp>
#include <boost/spirit/home/qi/string/symbols.hpp>
#include <boost/spirit/home/qi/string/lit.hpp>
#include <boost/spirit/home/qi/action/action.hpp>
#include <boost/spirit/home/qi/directive/hold.hpp>
#include <boost/mpl/count_if.hpp>
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/copy.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/back_inserter.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/spirit/repository/home/qi/operator/detail/keywords.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::divides > // enables /
: mpl::true_ {};
template <>
struct flatten_tree<qi::domain, proto::tag::divides> // flattens /
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace repository { namespace qi
{
// kwd directive parser type identification
namespace detail
{
BOOST_MPL_HAS_XXX_TRAIT_DEF(kwd_parser_id)
}
// kwd directive type query
template <typename T>
struct is_kwd_parser : detail::has_kwd_parser_id<T> {};
template <typename Subject, typename Action>
struct is_kwd_parser<spirit::qi::action<Subject,Action> > : detail::has_kwd_parser_id<Subject> {};
template <typename Subject>
struct is_kwd_parser<spirit::qi::hold_directive<Subject> > : detail::has_kwd_parser_id<Subject> {};
// Keywords operator
template <typename Elements, typename Modifiers>
struct keywords : spirit::qi::nary_parser<keywords<Elements,Modifiers> >
{
template <typename Context, typename Iterator>
struct attribute
{
// Put all the element attributes in a tuple
typedef typename traits::build_attribute_sequence<
Elements, Context, traits::sequence_attribute_transform, Iterator, spirit::qi::domain >::type
all_attributes;
// Now, build a fusion vector over the attributes. Note
// that build_fusion_vector 1) removes all unused attributes
// and 2) may return unused_type if all elements have
// unused_type(s).
typedef typename
traits::build_fusion_vector<all_attributes>::type
type;
};
/// Make sure that all subjects are of the kwd type
typedef typename mpl::count_if<
Elements,
mpl::not_<
is_kwd_parser<
mpl::_1
>
>
> non_kwd_subject_count;
/// If the assertion fails here then you probably forgot to wrap a
/// subject of the / operator in a kwd directive
BOOST_MPL_ASSERT_RELATION( non_kwd_subject_count::value, ==, 0 );
///////////////////////////////////////////////////////////////////////////
// build_parser_tags
//
// Builds a boost::variant from an mpl::range_c in order to "mark" every
// parser of the fusion sequence. The integer constant is used in the parser
// dispatcher functor in order to use the parser corresponding to the recognised
// keyword.
///////////////////////////////////////////////////////////////////////////
template <typename Sequence>
struct build_parser_tags
{
// Get the sequence size
typedef typename mpl::size< Sequence >::type sequence_size;
// Create an integer_c constant for every parser in the sequence
typedef typename mpl::range_c<int, 0, sequence_size::value>::type int_range;
// Transform the range_c to an mpl vector in order to be able to transform it into a variant
typedef typename mpl::copy<int_range, mpl::back_inserter<mpl::vector<> > >::type int_vector;
// Build the variant type containing the indexes of the parsers
typedef typename
spirit::detail::as_variant<
int_vector >::type type;
};
// Create a variant type to be able to store parser indexes in the embedded symbols parser
typedef typename build_parser_tags< Elements >::type parser_index_type;
///////////////////////////////////////////////////////////////////////////
// build_char_type_sequence
//
// Build a fusion sequence from the kwd directive specified character type.
///////////////////////////////////////////////////////////////////////////
template <typename Sequence >
struct build_char_type_sequence
{
struct element_char_type
{
template <typename T>
struct result;
template <typename F, typename Element>
struct result<F(Element)>
{
typedef typename Element::char_type type;
};
template <typename F, typename Element,typename Action>
struct result<F(spirit::qi::action<Element,Action>) >
{
typedef typename Element::char_type type;
};
template <typename F, typename Element>
struct result<F(spirit::qi::hold_directive<Element>)>
{
typedef typename Element::char_type type;
};
// never called, but needed for decltype-based result_of (C++0x)
template <typename Element>
typename result<element_char_type(Element)>::type
operator()(Element&) const;
};
// Compute the list of character types of the child kwd directives
typedef typename
fusion::result_of::transform<Sequence, element_char_type>::type
type;
};
///////////////////////////////////////////////////////////////////////////
// get_keyword_char_type
//
// Collapses the character type comming from the subject kwd parsers and
// and checks that they are all identical (necessary in order to be able
// to build a tst parser to parse the keywords.
///////////////////////////////////////////////////////////////////////////
template <typename Sequence>
struct get_keyword_char_type
{
// Make sure each of the types occur only once in the type list
typedef typename
mpl::fold<
Sequence, mpl::vector<>,
mpl::if_<
mpl::contains<mpl::_1, mpl::_2>,
mpl::_1, mpl::push_back<mpl::_1, mpl::_2>
>
>::type
no_duplicate_char_types;
// If the compiler traps here this means you mixed
// character type for the keywords specified in the
// kwd directive sequence.
BOOST_MPL_ASSERT_RELATION( mpl::size<no_duplicate_char_types>::value, ==, 1 );
typedef typename mpl::front<no_duplicate_char_types>::type type;
};
/// Get the character type for the tst parser
typedef typename build_char_type_sequence< Elements >::type char_types;
typedef typename get_keyword_char_type< char_types >::type char_type;
/// Our symbols container
typedef spirit::qi::tst< char_type, parser_index_type> keywords_type;
// Filter functor used for case insensitive parsing
template <typename CharEncoding>
struct no_case_filter
{
char_type operator()(char_type ch) const
{
return static_cast<char_type>(CharEncoding::tolower(ch));
}
};
///////////////////////////////////////////////////////////////////////////
// build_case_type_sequence
//
// Build a fusion sequence from the kwd/ikwd directives
// in order to determine if case sensitive and case insensitive
// keywords have been mixed.
///////////////////////////////////////////////////////////////////////////
template <typename Sequence >
struct build_case_type_sequence
{
struct element_case_type
{
template <typename T>
struct result;
template <typename F, typename Element>
struct result<F(Element)>
{
typedef typename Element::no_case_keyword type;
};
template <typename F, typename Element,typename Action>
struct result<F(spirit::qi::action<Element,Action>) >
{
typedef typename Element::no_case_keyword type;
};
template <typename F, typename Element>
struct result<F(spirit::qi::hold_directive<Element>)>
{
typedef typename Element::no_case_keyword type;
};
// never called, but needed for decltype-based result_of (C++0x)
template <typename Element>
typename result<element_case_type(Element)>::type
operator()(Element&) const;
};
// Compute the list of character types of the child kwd directives
typedef typename
fusion::result_of::transform<Sequence, element_case_type>::type
type;
};
///////////////////////////////////////////////////////////////////////////
// get_nb_case_types
//
// Counts the number of entries in the case type sequence matching the
// CaseType parameter (mpl::true_ -> case insensitve
// , mpl::false_ -> case sensitive
///////////////////////////////////////////////////////////////////////////
template <typename Sequence,typename CaseType>
struct get_nb_case_types
{
// Make sure each of the types occur only once in the type list
typedef typename
mpl::count_if<
Sequence, mpl::equal_to<mpl::_,CaseType>
>::type type;
};
// Build the case type sequence
typedef typename build_case_type_sequence<Elements>::type case_type_sequence;
// Count the number of case sensitive entries and case insensitve entries
typedef typename get_nb_case_types<case_type_sequence,mpl::true_>::type ikwd_count;
typedef typename get_nb_case_types<case_type_sequence,mpl::false_>::type kwd_count;
// Get the size of the original sequence
typedef typename mpl::size<Elements>::type nb_elements;
// Determine if all the kwd directive are case sensitive/insensitive
typedef typename mpl::equal_to< ikwd_count, nb_elements>::type all_ikwd;
typedef typename mpl::equal_to< kwd_count, nb_elements>::type all_kwd;
typedef typename mpl::or_< all_kwd, all_ikwd >::type all_directives_of_same_type;
// Do we have a no case modifier
typedef has_modifier<Modifiers, spirit::tag::char_code_base<spirit::tag::no_case> > no_case_modifier;
// Should the no_case filter always be used ?
typedef typename mpl::or_<
no_case_modifier,
mpl::and_<
all_directives_of_same_type
,all_ikwd
>
>::type
no_case;
typedef no_case_filter<
typename spirit::detail::get_encoding_with_case<
Modifiers
, char_encoding::standard
, no_case::value>::type>
nc_filter;
// Determine the standard case filter type
typedef typename mpl::if_<
no_case
, nc_filter
, spirit::qi::tst_pass_through >::type
filter_type;
// build a bool array and an integer array which will be used to
// check that the repetition constraints of the kwd parsers are
// met and bail out a soon as possible
typedef boost::array<bool, fusion::result_of::size<Elements>::value> flags_type;
typedef boost::array<int, fusion::result_of::size<Elements>::value> counters_type;
// Functor which adds all the keywords/subject parser indexes
// collected from the subject kwd directives to the keyword tst parser
template< typename Sequence >
struct keyword_entry_adder
{
typedef int result_type;
keyword_entry_adder(shared_ptr<keywords_type> lookup,flags_type &flags) :
lookup(lookup)
,flags(flags)
{}
typedef typename fusion::result_of::begin< Sequence >::type sequence_begin;
template <typename T>
int operator()(const int i, const T &parser) const
{
// Determine the current position being handled
typedef typename fusion::result_of::distance< sequence_begin, T >::type position_raw;
// Transform the position to a parser index tag
typedef typename mpl::integral_c<int,position_raw::value> position;
return call(i,fusion::deref(parser),position());
}
template <typename T, typename Position, typename Action>
int call( const int i, const spirit::qi::action<T,Action> &parser, const Position position ) const
{
// Make the keyword/parse index entry in the tst parser
lookup->add(
traits::get_begin<char_type>(parser.subject.keyword.str),
traits::get_end<char_type>(parser.subject.keyword.str),
position
);
// Get the initial state of the flags array and store it in the flags initializer
flags[Position::value]=parser.subject.iter.flag_init();
return 0;
}
template <typename T, typename Position>
int call( const int i, const T & parser, const Position position) const
{
// Make the keyword/parse index entry in the tst parser
lookup->add(
traits::get_begin<char_type>(parser.keyword.str),
traits::get_end<char_type>(parser.keyword.str),
position
);
// Get the initial state of the flags array and store it in the flags initializer
flags[Position::value]=parser.iter.flag_init();
return 0;
}
template <typename T, typename Position>
int call( const int i, const spirit::qi::hold_directive<T> & parser, const Position position) const
{
// Make the keyword/parse index entry in the tst parser
lookup->add(
traits::get_begin<char_type>(parser.subject.keyword.str),
traits::get_end<char_type>(parser.subject.keyword.str),
position
);
// Get the initial state of the flags array and store it in the flags initializer
flags[Position::value]=parser.subject.iter.flag_init();
return 0;
}
shared_ptr<keywords_type> lookup;
flags_type & flags;
};
keywords(Elements const& elements) :
elements(elements)
, lookup(new keywords_type())
{
// Loop through all the subject parsers to build the keyword parser symbol parser
keyword_entry_adder<Elements> f1(lookup,flags_init);
fusion::iter_fold(this->elements,0,f1);
}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_) const
{
// Select which parse function to call
// We need to handle the case where kwd / ikwd directives have been mixed
// This is where we decide which function should be called.
return parse_impl(first, last, context, skipper, attr_,
typename mpl::or_<all_directives_of_same_type, no_case>::type()
);
}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse_impl(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_,mpl::true_ /* no ikwd */) const
{
// wrap the attribute in a tuple if it is not a tuple
typename traits::wrap_if_not_tuple<Attribute>::type attr(attr_);
flags_type flags(flags_init);
//flags.assign(false);
counters_type counters;
counters.assign(0);
typedef repository::qi::detail::parse_dispatcher<Elements,Iterator, Context, Skipper
, flags_type, counters_type
, typename traits::wrap_if_not_tuple<Attribute>::type
, mpl::false_ > parser_visitor_type;
parser_visitor_type parse_visitor(elements, first, last
, context, skipper, flags
, counters, attr);
// We have a bool array 'flags' with one flag for each parser as well as a 'counter'
// array.
// The kwd directive sets and increments the counter when a successeful parse occured
// as well as the slot of the corresponding parser to true in the flags array as soon
// the minimum repetition requirement is met and keeps that value to true as long as
// the maximum repetition requirement is met.
// The parsing takes place here in two steps:
// 1) parse a keyword and fetch the parser index associated with that keyword
// 2) call the associated parser and store the parsed value in the matching attribute.
Iterator save = first;
while(true)
{
spirit::qi::skip_over(first, last, skipper);
if (parser_index_type* val_ptr
= lookup->find(first, last, filter_type()))
{
spirit::qi::skip_over(first, last, skipper);
if(!apply_visitor(parse_visitor,*val_ptr)){
first = save;
return false;
}
save = first;
}
else
{
// Check that we are leaving the keywords parser in a successfull state
BOOST_FOREACH(bool &valid,flags)
{
if(!valid)
{
first = save;
return false;
}
}
return true;
}
}
return false;
}
// Handle the mixed kwd and ikwd case
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse_impl(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_,mpl::false_) const
{
// wrap the attribute in a tuple if it is not a tuple
typename traits::wrap_if_not_tuple<Attribute>::type attr(attr_);
flags_type flags(flags_init);
//flags.assign(false);
counters_type counters;
counters.assign(0);
typedef detail::parse_dispatcher<Elements, Iterator, Context, Skipper
, flags_type, counters_type
, typename traits::wrap_if_not_tuple<Attribute>::type
, mpl::false_> parser_visitor_type;
typedef detail::parse_dispatcher<Elements, Iterator, Context, Skipper
, flags_type, counters_type
, typename traits::wrap_if_not_tuple<Attribute>::type
, mpl::true_> no_case_parser_visitor_type;
parser_visitor_type parse_visitor(elements,first,last
,context,skipper,flags,counters,attr);
no_case_parser_visitor_type no_case_parse_visitor(elements,first,last
,context,skipper,flags,counters,attr);
// We have a bool array 'flags' with one flag for each parser as well as a 'counter'
// array.
// The kwd directive sets and increments the counter when a successeful parse occured
// as well as the slot of the corresponding parser to true in the flags array as soon
// the minimum repetition requirement is met and keeps that value to true as long as
// the maximum repetition requirement is met.
// The parsing takes place here in two steps:
// 1) parse a keyword and fetch the parser index associated with that keyword
// 2) call the associated parser and store the parsed value in the matching attribute.
Iterator save = first;
while(true)
{
spirit::qi::skip_over(first, last, skipper);
// First pass case sensitive
Iterator saved_first = first;
if (parser_index_type* val_ptr
= lookup->find(first, last, spirit::qi::tst_pass_through()))
{
spirit::qi::skip_over(first, last, skipper);
if(!apply_visitor(parse_visitor,*val_ptr)){
first = save;
return false;
}
save = first;
}
// Second pass case insensitive
else if(parser_index_type* val_ptr
= lookup->find(saved_first,last,nc_filter()))
{
first = saved_first;
spirit::qi::skip_over(first, last, skipper);
if(!apply_visitor(no_case_parse_visitor,*val_ptr)){
first = save;
return false;
}
save = first;
}
else
{
// Check that we are leaving the keywords parser in a successfull state
BOOST_FOREACH(bool &valid,flags)
{
if(!valid)
{
first = save;
return false;
}
}
return true;
}
}
return false;
}
template <typename Context>
info what(Context& context) const
{
info result("keywords");
fusion::for_each(elements,
spirit::detail::what_function<Context>(result, context));
return result;
}
flags_type flags_init;
Elements elements;
shared_ptr<keywords_type> lookup;
};
}}}}
namespace boost { namespace spirit { namespace qi {
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers >
struct make_composite<proto::tag::divides, Elements, Modifiers >
{
typedef repository::qi::keywords<Elements,Modifiers> result_type;
result_type operator()(Elements ref, unused_type) const
{
return result_type(ref);
}
};
}}}
namespace boost { namespace spirit { namespace traits
{
// We specialize this for keywords (see support/attributes.hpp).
// For keywords, we only wrap the attribute in a tuple IFF
// it is not already a fusion tuple.
template <typename Elements, typename Modifiers,typename Attribute>
struct pass_attribute<repository::qi::keywords<Elements,Modifiers>, Attribute>
: wrap_if_not_tuple<Attribute> {};
template <typename Elements, typename Modifiers>
struct has_semantic_action<repository::qi::keywords<Elements, Modifiers> >
: nary_has_semantic_action<Elements> {};
}}}
#endif
|
; ---------------------------------------------------------------------------
; Animation script - geyser of lava (MZ)
; ---------------------------------------------------------------------------
Ani_Geyser: dc.w @bubble1-Ani_Geyser
dc.w @bubble2-Ani_Geyser
dc.w @end-Ani_Geyser
dc.w @bubble3-Ani_Geyser
dc.w @blank-Ani_Geyser
dc.w @bubble4-Ani_Geyser
@bubble1: dc.b 2, 0, 1, 0, 1, 4, 5, 4, 5, afRoutine
@bubble2: dc.b 2, 2, 3, afEnd
@end: dc.b 2, 6, 7, afEnd
@bubble3: dc.b 2, 2, 3, 0, 1, 0, 1, afRoutine
@blank: dc.b $F, $13, afEnd
even
@bubble4: dc.b 2, $11, $12, afEnd
even |
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %rax
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_D_ht+0x1c68c, %rsi
lea addresses_D_ht+0xcf8c, %rdi
nop
nop
nop
add $58879, %rax
mov $115, %rcx
rep movsq
sub $48716, %rsi
lea addresses_WT_ht+0x3d8c, %rbp
inc %rax
vmovups (%rbp), %ymm3
vextracti128 $1, %ymm3, %xmm3
vpextrq $0, %xmm3, %r12
dec %rcx
lea addresses_WT_ht+0x125cc, %rsi
lea addresses_UC_ht+0x1d98c, %rdi
nop
nop
nop
add $2877, %rdx
mov $2, %rcx
rep movsq
nop
nop
nop
nop
add %rdx, %rdx
lea addresses_UC_ht+0x7b8c, %rcx
nop
nop
nop
nop
nop
sub %r12, %r12
mov (%rcx), %rax
nop
nop
nop
nop
add %rdx, %rdx
lea addresses_WC_ht+0x678c, %rdx
nop
nop
nop
nop
nop
xor $19600, %rcx
mov $0x6162636465666768, %rbp
movq %rbp, %xmm5
vmovups %ymm5, (%rdx)
nop
nop
nop
nop
nop
xor %rdi, %rdi
lea addresses_D_ht+0xb56c, %r12
mfence
mov $0x6162636465666768, %rdi
movq %rdi, %xmm2
vmovups %ymm2, (%r12)
nop
nop
nop
cmp %rcx, %rcx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r9
push %rbp
push %rbx
push %rsi
// Faulty Load
lea addresses_WC+0xd98c, %rsi
nop
nop
nop
nop
nop
and %r9, %r9
vmovups (%rsi), %ymm0
vextracti128 $0, %ymm0, %xmm0
vpextrq $0, %xmm0, %r10
lea oracles, %r11
and $0xff, %r10
shlq $12, %r10
mov (%r11,%r10,1), %r10
pop %rsi
pop %rbx
pop %rbp
pop %r9
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_WC', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_WC', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 8, 'same': False}}
{'src': {'same': True, 'congruent': 10, 'NT': False, 'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}}
{'src': {'same': False, 'congruent': 9, 'NT': False, 'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 3, 'NT': False, 'type': 'addresses_D_ht', 'size': 32, 'AVXalign': False}}
{'38': 21829}
38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38
*/
|
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE762_Mismatched_Memory_Management_Routines__delete_wchar_t_malloc_44.cpp
Label Definition File: CWE762_Mismatched_Memory_Management_Routines__delete.label.xml
Template File: sources-sinks-44.tmpl.cpp
*/
/*
* @description
* CWE: 762 Mismatched Memory Management Routines
* BadSource: malloc Allocate data using malloc()
* GoodSource: Allocate data using new
* Sinks:
* GoodSink: Deallocate data using free()
* BadSink : Deallocate data using delete
* Flow Variant: 44 Data/control flow: data passed as an argument from one function to a function in the same source file called via a function pointer
*
* */
#include "std_testcase.h"
namespace CWE762_Mismatched_Memory_Management_Routines__delete_wchar_t_malloc_44
{
#ifndef OMITBAD
static void bad_sink(wchar_t * data)
{
/* POTENTIAL FLAW: Deallocate memory using delete - the source memory allocation function may
* require a call to free() to deallocate the memory */
delete data;
}
void bad()
{
wchar_t * data;
/* define a function pointer */
void (*func_ptr) (wchar_t *) = bad_sink;
/* Initialize data*/
data = NULL;
/* POTENTIAL FLAW: Allocate memory with a function that requires free() to free the memory */
data = (wchar_t *)malloc(100*sizeof(wchar_t));
/* use the function pointer */
func_ptr(data);
}
#endif /* OMITBAD */
#ifndef OMITGOOD
/* goodG2B() uses the GoodSource with the BadSink */
static void goodG2B_sink(wchar_t * data)
{
/* POTENTIAL FLAW: Deallocate memory using delete - the source memory allocation function may
* require a call to free() to deallocate the memory */
delete data;
}
static void goodG2B()
{
wchar_t * data;
void (*func_ptr) (wchar_t *) = goodG2B_sink;
/* Initialize data*/
data = NULL;
/* FIX: Allocate memory from the heap using new */
data = new wchar_t;
func_ptr(data);
}
/* goodB2G() uses the BadSource with the GoodSink */
static void goodB2G_sink(wchar_t * data)
{
/* FIX: Deallocate the memory using free() */
free(data);
}
static void goodB2G()
{
wchar_t * data;
void (*func_ptr) (wchar_t *) = goodB2G_sink;
/* Initialize data*/
data = NULL;
/* POTENTIAL FLAW: Allocate memory with a function that requires free() to free the memory */
data = (wchar_t *)malloc(100*sizeof(wchar_t));
func_ptr(data);
}
void good()
{
goodG2B();
goodB2G();
}
#endif /* OMITGOOD */
} // close namespace
/* Below is the main(). It is only used when building this testcase on
its own for testing or for building a binary to use in testing binary
analysis tools. It is not used when compiling all the testcases as one
application, which is how source code analysis tools are tested. */
#ifdef INCLUDEMAIN
using namespace CWE762_Mismatched_Memory_Management_Routines__delete_wchar_t_malloc_44; // so that we can use good and bad easily
int main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine("Calling good()...");
good();
printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
printLine("Calling bad()...");
bad();
printLine("Finished bad()");
#endif /* OMITBAD */
return 0;
}
#endif
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.