text
stringlengths
1
1.05M
/** * Project Logi source code * Copyright (C) 2019 Primoz Lavric * * 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 3 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, see <http://www.gnu.org/licenses/>. */ #ifndef LOGI_MEMORY_MEMORY_ALLOCATOR_IMPL_HPP #define LOGI_MEMORY_MEMORY_ALLOCATOR_IMPL_HPP #include <optional> #include <vk_mem_alloc.h> #include "logi/base/common.hpp" #include "logi/base/vulkan_object.hpp" namespace logi { class VulkanInstanceImpl; class PhysicalDeviceImpl; class LogicalDeviceImpl; class VMABufferImpl; class VMAImageImpl; class VMAAccelerationStructureNVImpl; class MemoryAllocatorImpl : public VulkanObject, public std::enable_shared_from_this<MemoryAllocatorImpl>, public VulkanObjectComposite<VMABufferImpl>, public VulkanObjectComposite<VMAImageImpl>, public VulkanObjectComposite<VMAAccelerationStructureNVImpl> { public: explicit MemoryAllocatorImpl(LogicalDeviceImpl& logicalDevice, vk::DeviceSize preferredLargeHeapBlockSize = 0u, uint32_t frameInUseCount = 0u, const std::vector<vk::DeviceSize>& heapSizeLimits = {}, const std::optional<vk::AllocationCallbacks>& allocator = {}); // region Sub handles const std::shared_ptr<VMABufferImpl>& createBuffer(const vk::BufferCreateInfo& bufferCreateInfo, const VmaAllocationCreateInfo& allocationCreateInfo, const std::optional<vk::AllocationCallbacks>& allocator); void destroyBuffer(size_t id); const std::shared_ptr<VMAImageImpl>& createImage(const vk::ImageCreateInfo& imageCreateInfo, const VmaAllocationCreateInfo& allocationCreateInfo, const std::optional<vk::AllocationCallbacks>& allocator = {}); void destroyImage(size_t id); const std::shared_ptr<VMAAccelerationStructureNVImpl>& createAccelerationStructureNV(const vk::AccelerationStructureCreateInfoNV& accelerationStructureCreateInfo, const VmaAllocationCreateInfo& allocationCreateInfo, const std::optional<vk::AllocationCallbacks>& allocator = {}); void destroyAccelerationStructureNV(size_t id); // endregion // region Logi Declarations VulkanInstanceImpl& getInstance() const; PhysicalDeviceImpl& getPhysicalDevice() const; LogicalDeviceImpl& getLogicalDevice() const; const vk::DispatchLoaderDynamic& getDispatcher() const; operator const VmaAllocator&() const; void destroy() const; protected: void free() override; // endregion private: LogicalDeviceImpl& logicalDevice_; std::optional<vk::AllocationCallbacks> allocator_; VmaAllocator vma_; }; } // namespace logi #endif // LOGI_MEMORY_MEMORY_ALLOCATOR_IMPL_HPP
/* Given a Binary Tree, find vertical sum of the nodes that are in same vertical line. Print all sums through different vertical lines. */ #include<iostream> #include<map> using namespace std; struct node { node *left; int data; node *right; }; class BinaryTree { public: node *root; BinaryTree() { root = NULL; } node *create(); void insert(node *,node *); void vertical_sum(node *); }; node *BinaryTree::create() { node *temp = new node(); cout << "\nEnter data "; cin >> temp -> data; temp->left = NULL; temp->right = NULL; return temp; } void BinaryTree::insert(node *rt,node *temp) { char ch; cout << "where do you wnat to insert to left/right ? (l/r) "; cin >> ch; if(ch == 'r') { if(rt->right == NULL) { rt->right = temp; return ; } else insert(rt->right ,temp); } else { if(rt->left == NULL) { rt->left = temp; return ; } else insert(rt->left ,temp); } } void vertical_sum_cal(node *temp, int hd, auto &map) { if(temp != NULL) { vertical_sum_cal(temp -> left, hd - 1, map); map[hd] += temp -> data; vertical_sum_cal(temp -> right, hd + 1, map); } } void BinaryTree :: vertical_sum(node *root) { map <int, int> Map; vertical_sum_cal(root, 0, Map); for(auto it = Map.begin(); it != Map.end(); it++) { cout << it -> second << " "; } } int main() { int op; BinaryTree ob; cout << "1.insertion"; cout << "\n2.vertical sum"; cout << "\n3.exit"; while(1) { cout << "\nEnter operation "; cin >> op; if(op == 1) { node *node = ob.create(); if(ob.root == NULL) ob.root = node; else ob.insert(ob.root ,node); } else if(op == 2) { ob.vertical_sum(ob.root); } else if(op == 3) exit(0); else cout << "\nWrong option "; } }
/******************************************************************** * This file includes functions that outputs a configuration protocol to XML format *******************************************************************/ /* Headers from system goes first */ #include <string> #include <algorithm> /* Headers from vtr util library */ #include "vtr_assert.h" #include "vtr_log.h" #include "vtr_time.h" /* Headers from openfpga util library */ #include "openfpga_digest.h" /* Headers from arch openfpga library */ #include "write_xml_utils.h" /* Headers from fabrickey library */ #include "write_xml_fabric_key.h" /******************************************************************** * A writer to output a component key to XML format * * Return 0 if successful * Return 1 if there are more serious bugs in the architecture * Return 2 if fail when creating files *******************************************************************/ static int write_xml_fabric_component_key(std::fstream& fp, const FabricKey& fabric_key, const FabricKeyId& component_key) { /* Validate the file stream */ if (false == openfpga::valid_file_stream(fp)) { return 2; } openfpga::write_tab_to_file(fp, 2); fp << "<key"; if (false == fabric_key.valid_key_id(component_key)) { return 1; } write_xml_attribute(fp, "id", size_t(component_key)); if (!fabric_key.key_name(component_key).empty()) { write_xml_attribute(fp, "name", fabric_key.key_name(component_key).c_str()); } write_xml_attribute(fp, "value", fabric_key.key_value(component_key)); if (!fabric_key.key_alias(component_key).empty()) { write_xml_attribute(fp, "alias", fabric_key.key_alias(component_key).c_str()); } vtr::Point<int> coord = fabric_key.key_coordinate(component_key); if (fabric_key.valid_key_coordinate(coord)) { write_xml_attribute(fp, "column", coord.x()); write_xml_attribute(fp, "row", coord.y()); } fp << "/>" << "\n"; return 0; } /******************************************************************** * A writer to output a BL shift register bank description to XML format * * Return 0 if successful * Return 1 if there are more serious bugs in the architecture * Return 2 if fail when creating files *******************************************************************/ static int write_xml_fabric_bl_shift_register_banks(std::fstream& fp, const FabricKey& fabric_key, const FabricRegionId& region) { /* Validate the file stream */ if (false == openfpga::valid_file_stream(fp)) { return 2; } /* If we have an empty bank, we just skip it */ if (0 == fabric_key.bl_banks(region).size()) { return 0; } /* Write the root node */ openfpga::write_tab_to_file(fp, 2); fp << "<bl_shift_register_banks>" << "\n"; for (const auto& bank : fabric_key.bl_banks(region)) { openfpga::write_tab_to_file(fp, 3); fp << "<bank"; write_xml_attribute(fp, "id", size_t(bank)); std::string port_str; for (const auto& port : fabric_key.bl_bank_data_ports(region, bank)) { port_str += generate_xml_port_name(port) + ","; } /* Chop the last comma */ if (!port_str.empty()) { port_str.pop_back(); } write_xml_attribute(fp, "range", port_str.c_str()); fp << "/>" << "\n"; } openfpga::write_tab_to_file(fp, 2); fp << "</bl_shift_register_banks>" << "\n"; return 0; } /******************************************************************** * A writer to output a WL shift register bank description to XML format * * Return 0 if successful * Return 1 if there are more serious bugs in the architecture * Return 2 if fail when creating files *******************************************************************/ static int write_xml_fabric_wl_shift_register_banks(std::fstream& fp, const FabricKey& fabric_key, const FabricRegionId& region) { /* Validate the file stream */ if (false == openfpga::valid_file_stream(fp)) { return 2; } /* If we have an empty bank, we just skip it */ if (0 == fabric_key.wl_banks(region).size()) { return 0; } /* Write the root node */ openfpga::write_tab_to_file(fp, 2); fp << "<wl_shift_register_banks>" << "\n"; for (const auto& bank : fabric_key.wl_banks(region)) { openfpga::write_tab_to_file(fp, 3); fp << "<bank"; write_xml_attribute(fp, "id", size_t(bank)); std::string port_str; for (const auto& port : fabric_key.wl_bank_data_ports(region, bank)) { port_str += generate_xml_port_name(port) + ","; } /* Chop the last comma */ if (!port_str.empty()) { port_str.pop_back(); } write_xml_attribute(fp, "range", port_str.c_str()); fp << "/>" << "\n"; } openfpga::write_tab_to_file(fp, 2); fp << "</wl_shift_register_banks>" << "\n"; return 0; } /******************************************************************** * A writer to output a fabric key to XML format * * Return 0 if successful * Return 1 if there are more serious bugs in the architecture * Return 2 if fail when creating files *******************************************************************/ int write_xml_fabric_key(const char* fname, const FabricKey& fabric_key) { vtr::ScopedStartFinishTimer timer("Write Fabric Key"); /* Create a file handler */ std::fstream fp; /* Open the file stream */ fp.open(std::string(fname), std::fstream::out | std::fstream::trunc); /* Validate the file stream */ openfpga::check_file_stream(fname, fp); /* Write the root node */ fp << "<fabric_key>" << "\n"; int err_code = 0; /* Write region by region */ for (const FabricRegionId& region : fabric_key.regions()) { openfpga::write_tab_to_file(fp, 1); fp << "<region id=\"" << size_t(region) << "\"" << ">\n"; /* Write shift register banks */ write_xml_fabric_bl_shift_register_banks(fp, fabric_key, region); write_xml_fabric_wl_shift_register_banks(fp, fabric_key, region); /* Write component by component */ for (const FabricKeyId& key : fabric_key.region_keys(region)) { err_code = write_xml_fabric_component_key(fp, fabric_key, key); if (0 != err_code) { return err_code; } } openfpga::write_tab_to_file(fp, 1); fp << "</region>" << "\n"; } /* Finish writing the root node */ fp << "</fabric_key>" << "\n"; /* Close the file stream */ fp.close(); return err_code; }
; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$" message db "Please Enter Char : $" res1 db "Ahmad $" res2 db "Bahman $" res3 db "Computer $" res4 db "General $" inputstring label byte max db 1 len db ? string db 2 dup('$') ends stack segment dw 128 dup(0) ends code segment start: ; set segment registers: mov ax, data mov ds, ax mov es, ax ; add your code here lea dx, message mov ah, 9h int 21h mov ah, 1h int 21h cmp al, 'A' je if cmp al, 'B' je elseif1 cmp al, 'C' je elseif2 jmp else if: lea dx, res1 mov ah, 9h int 21h jmp endif elseif1: lea dx, res2 mov ah, 9h int 21h jmp endif elseif2: lea dx, res3 mov ah, 9h int 21h jmp endif else: lea dx, res4 mov ah, 9h int 21h endif: lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1 int 21h mov ax, 4c00h ; exit to operating system. int 21h ends end start ; set entry point and stop the assembler.
; A001716: Generalized Stirling numbers. ; Submitted by Jon Maiga ; 1,9,74,638,5944,60216,662640,7893840,101378880,1397759040,20606463360,323626665600,5395972377600,95218662067200,1773217155225600,34758188233574400,715437948072960000,15429680577561600000,347968129734973440000,8190600438533990400000,200883079981296599040000,5125485066487954882560000,135847813402575324610560000,3735106205390634703749120000,106397785326007497065103360000,3136350498556169724971581440000,95564141955641708741571379200000,3006697210593591480761430835200000 add $0,1 mov $1,3 mov $2,3 lpb $0 sub $0,1 add $2,1 mul $3,$2 add $3,$1 mul $1,$2 lpe mov $0,$3 div $0,3
#include "moab/Range.hpp" #include "moab/Core.hpp" #include "moab/Skinner.hpp" #include <iostream> #include <stdlib.h> using namespace moab; enum { NO_ERROR= 0, SYNTAX_ERROR = 1, FILE_IO_ERROR = 2, INTERNAL_ERROR = 3 }; const char* DEFAULT_TAG_NAME = "depth"; static void usage( const char* argv0 ) { std::cerr << "Usage: " << argv0 << "[-t <tag name] <input_file> <output_file>" << std::endl << argv0 << "-h" << std::endl; exit(SYNTAX_ERROR); } static void check( ErrorCode rval ) { if (MB_SUCCESS != rval) { std::cerr << "Internal error. Aborting." << std::endl; exit(INTERNAL_ERROR); } } static void tag_depth( Interface& moab, Tag tag ); int main( int argc, char* argv[] ) { const char *input = 0, *output = 0, *tagname = DEFAULT_TAG_NAME; bool expect_tag_name = false; for (int i = 1; i < argc; ++i) { if (expect_tag_name) { tagname = argv[i]; expect_tag_name = false; } else if (!strcmp("-t", argv[i])) expect_tag_name = true; else if (input == 0) input = argv[i]; else if (output == 0) output = argv[i]; else { std::cerr << "Unexpected argument: '" << argv[i] << "'" << std::endl; usage(argv[0]); } } if (expect_tag_name) { std::cerr << "Expected argument following '-t'" << std::endl; usage(argv[0]); } if (!input) { std::cerr << "No input file" << std::endl; usage(argv[0]); } if (!output) { std::cerr << "No output file" << std::endl; usage(argv[0]); } Core moab; Interface& mb = moab; EntityHandle file; ErrorCode rval; rval = mb.create_meshset( MESHSET_SET, file ); check(rval); rval = mb.load_file( input, &file ); if (MB_SUCCESS != rval) { std::cerr << "Failed to load file: " << input << std::endl; return FILE_IO_ERROR; } int init_val = -1; Tag tag; bool created; rval = mb.tag_get_handle( tagname, 1, MB_TYPE_INTEGER, tag, MB_TAG_DENSE|MB_TAG_CREAT, &init_val, &created ); if (!created) { rval = mb.tag_delete( tag ); check(rval); rval = mb.tag_get_handle( tagname, 1, MB_TYPE_INTEGER, tag, MB_TAG_DENSE|MB_TAG_CREAT, &init_val, &created ); check(rval); } tag_depth( mb, tag ); rval = mb.write_file( output, 0, 0, &file, 1 ); if (rval == MB_SUCCESS) std::cout << "Wrote file: " << output << std::endl; else { std::cerr << "Failed to write file: " << output << std::endl; return FILE_IO_ERROR; } return NO_ERROR; } static ErrorCode get_adjacent_elems( Interface& mb, const Range& verts, Range& elems ) { elems.clear(); ErrorCode rval; for (int dim = 3; dim > 0; --dim) { rval = mb.get_adjacencies( verts, dim, false, elems, Interface::UNION ); if (MB_SUCCESS != rval) break; } return rval; } void tag_depth( Interface& mb, Tag tag ) { ErrorCode rval; int dim; Skinner tool(&mb); Range verts, elems; dim = 3; while (elems.empty()) { rval = mb.get_entities_by_dimension( 0, dim, elems ); check(rval); if (--dim == 0) return; // no elements } rval = tool.find_skin( 0, elems, 0, verts ); check(rval); rval = get_adjacent_elems( mb, verts, elems ); check(rval); std::vector<int> data; int val, depth = 0; while (!elems.empty()) { data.clear(); data.resize( elems.size(), depth++ ); rval = mb.tag_set_data( tag, elems, &data[0] ); check(rval); verts.clear(); rval = mb.get_adjacencies( elems, 0, false, verts, Interface::UNION ); check(rval); Range tmp; rval = get_adjacent_elems( mb, verts, tmp ); check(rval); elems.clear(); for (Range::reverse_iterator i = tmp.rbegin(); i != tmp.rend(); ++i) { rval = mb.tag_get_data( tag, &*i, 1, &val ); check(rval); if (val == -1) elems.insert( *i ); } } std::cout << "Maximum depth: " << depth << std::endl; }
*= $0801 .byte $4c,$16,$08,$00,$97,$32 .byte $2c,$30,$3a,$9e,$32,$30 .byte $37,$30,$00,$00,$00,$a9 .byte $01,$85,$02 jsr print .byte 13 .text "(up)stya" .byte 0 lda #%00011011 sta db lda #%11000110 sta ab lda #%10110001 sta xb lda #%01101100 sta yb lda #0 sta pb tsx stx sb lda #0 sta yb next lda db lda ab sta ar lda xb sta xr lda yb sta yr sta dr lda pb ora #%00110000 sta pr lda sb sta sr ldx sb txs lda pb pha lda ab ldx xb ldy yb plp cmd sty da php cld sta aa stx xa sty ya pla sta pa tsx stx sa jsr check inc yb jmpnext bne next inc pb bne jmpnext jsr print .text " - ok" .byte 13,0 lda 2 beq load wait jsr $ffe4 beq wait jmp $8000 load jsr print name .text "taxn" namelen = *-name .byte 0 lda #0 sta $0a sta $b9 lda #namelen sta $b7 lda #<name sta $bb lda #>name sta $bc pla pla jmp $e16f db .byte 0 ab .byte 0 xb .byte 0 yb .byte 0 pb .byte 0 sb .byte 0 da .byte 0 aa .byte 0 xa .byte 0 ya .byte 0 pa .byte 0 sa .byte 0 dr .byte 0 ar .byte 0 xr .byte 0 yr .byte 0 pr .byte 0 sr .byte 0 check .block lda da cmp dr bne error lda aa cmp ar bne error lda xa cmp xr bne error lda ya cmp yr bne error lda pa cmp pr bne error lda sa cmp sr bne error rts error jsr print .byte 13 .null "before " ldx #<db ldy #>db jsr showregs jsr print .byte 13 .null "after " ldx #<da ldy #>da jsr showregs jsr print .byte 13 .null "right " ldx #<dr ldy #>dr jsr showregs lda #13 jsr $ffd2 wait jsr $ffe4 beq wait cmp #3 beq stop rts stop lda 2 beq basic jmp $8000 basic jmp ($a002) showregs stx 172 sty 173 ldy #0 lda (172),y jsr hexb lda #32 jsr $ffd2 lda #32 jsr $ffd2 iny lda (172),y jsr hexb lda #32 jsr $ffd2 iny lda (172),y jsr hexb lda #32 jsr $ffd2 iny lda (172),y jsr hexb lda #32 jsr $ffd2 iny lda (172),y ldx #"n" asl a bcc ok7 ldx #"N" ok7 pha txa jsr $ffd2 pla ldx #"v" asl a bcc ok6 ldx #"V" ok6 pha txa jsr $ffd2 pla ldx #"0" asl a bcc ok5 ldx #"1" ok5 pha txa jsr $ffd2 pla ldx #"b" asl a bcc ok4 ldx #"B" ok4 pha txa jsr $ffd2 pla ldx #"d" asl a bcc ok3 ldx #"D" ok3 pha txa jsr $ffd2 pla ldx #"i" asl a bcc ok2 ldx #"I" ok2 pha txa jsr $ffd2 pla ldx #"z" asl a bcc ok1 ldx #"Z" ok1 pha txa jsr $ffd2 pla ldx #"c" asl a bcc ok0 ldx #"C" ok0 pha txa jsr $ffd2 pla lda #32 jsr $ffd2 iny lda (172),y .bend hexb pha lsr a lsr a lsr a lsr a jsr hexn pla and #$0f hexn ora #$30 cmp #$3a bcc hexn0 adc #6 hexn0 jmp $ffd2 print pla .block sta print0+1 pla sta print0+2 ldx #1 print0 lda !*,x beq print1 jsr $ffd2 inx bne print0 print1 sec txa adc print0+1 sta print2+1 lda #0 adc print0+2 sta print2+2 print2 jmp !* .bend
; A176531: Decimal expansion of (10+sqrt(110))/2. ; Submitted by Christian Krause ; 1,0,2,4,4,0,4,4,2,4,0,8,5,0,7,5,7,7,3,4,9,5,7,2,6,7,5,6,8,3,9,9,6,8,7,9,9,2,3,7,6,3,5,9,2,8,8,4,0,7,5,1,9,9,2,4,3,7,8,7,7,8,8,1,7,9,0,0,0,2,9,6,2,7,5,0,5,5,0,3,4,5,7,0,9,6,9,2,6,4,4,4,6,6,5,9,7,2,0,8 mov $2,1 mov $3,$0 mul $3,4 lpb $3 add $1,$5 add $5,$2 add $5,$2 add $1,$5 mul $1,40 add $2,$1 mov $1,0 sub $3,1 lpe mov $1,1 add $1,$5 mov $4,10 pow $4,$0 div $2,$4 div $1,$2 mov $0,$1 mod $0,10
; void *tshc_saddr2aaddr(void *saddr) SECTION code_clib SECTION code_arch PUBLIC tshc_saddr2aaddr EXTERN asm_tshc_saddr2aaddr defc tshc_saddr2aaddr = asm_tshc_saddr2aaddr
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r14 push %rax push %rbx push %rcx push %rdi push %rdx push %rsi lea addresses_D_ht+0x19bc6, %rcx nop sub %rbx, %rbx mov $0x6162636465666768, %rdx movq %rdx, (%rcx) nop cmp %rsi, %rsi lea addresses_A_ht+0x249e, %rsi lea addresses_normal_ht+0x5ee, %rdi nop nop nop nop cmp $55560, %rax mov $34, %rcx rep movsq nop nop nop add %rdi, %rdi lea addresses_A_ht+0xf49e, %rsi clflush (%rsi) nop nop nop nop nop and $27990, %rbx movw $0x6162, (%rsi) nop nop inc %rdx lea addresses_UC_ht+0x6b4e, %rsi lea addresses_normal_ht+0x50b1, %rdi nop nop sub %rax, %rax mov $36, %rcx rep movsl nop nop nop cmp $57316, %rdx lea addresses_A_ht+0x219e, %rdx nop nop nop and $6668, %rdi mov $0x6162636465666768, %rax movq %rax, %xmm3 and $0xffffffffffffffc0, %rdx vmovntdq %ymm3, (%rdx) nop nop nop add %rdi, %rdi lea addresses_WT_ht+0xc9e, %rsi nop lfence mov $0x6162636465666768, %rbx movq %rbx, %xmm7 movups %xmm7, (%rsi) nop nop nop xor %rbx, %rbx lea addresses_WT_ht+0x1715e, %rsi nop sub $45079, %rcx mov (%rsi), %di nop nop nop nop add $14528, %rcx lea addresses_UC_ht+0x5e9e, %rsi lea addresses_WC_ht+0x1121e, %rdi nop nop nop xor $15951, %r14 mov $39, %rcx rep movsb nop nop cmp $13350, %rdx lea addresses_D_ht+0xe6ba, %rsi lea addresses_A_ht+0x18656, %rdi nop nop nop nop dec %r12 mov $91, %rcx rep movsw nop nop nop nop lfence lea addresses_normal_ht+0x1887e, %rcx nop nop add $49663, %rax movb (%rcx), %dl add $23537, %rax lea addresses_normal_ht+0xf85e, %rsi lea addresses_UC_ht+0x13896, %rdi clflush (%rsi) clflush (%rdi) nop nop and $9322, %rbx mov $95, %rcx rep movsq nop nop nop nop dec %rdi pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %rax pop %r14 pop %r12 ret .global s_faulty_load s_faulty_load: push %r15 push %rax push %rbx push %rcx push %rdi push %rdx // Store lea addresses_normal+0x1196e, %rax nop nop nop nop cmp %r15, %r15 mov $0x5152535455565758, %rdx movq %rdx, (%rax) nop nop nop sub %rcx, %rcx // Faulty Load lea addresses_RW+0x749e, %rcx clflush (%rcx) and %rdx, %rdx mov (%rcx), %ebx lea oracles, %rax and $0xff, %rbx shlq $12, %rbx mov (%rax,%rbx,1), %rbx pop %rdx pop %rdi pop %rcx pop %rbx pop %rax pop %r15 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 11, 'same': True}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 3, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 2, 'AVXalign': False, 'NT': True, 'congruent': 10, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 32, 'AVXalign': False, 'NT': True, 'congruent': 8, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': True, 'congruent': 6, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 7, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 2, 'same': False}} {'32': 498} 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 */
/** * @file /ecl_devices/include/ecl/devices/serial_w32.hpp * * @brief Win32 interface for serial (RS232) devices. * * @date May 2010 **/ /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_THREADS_SERIAL_W32_HPP_ #define ECL_THREADS_SERIAL_W32_HPP_ /***************************************************************************** ** Platform Check *****************************************************************************/ #include <ecl/config.hpp> #ifdef ECL_IS_WIN32 /***************************************************************************** ** Includes *****************************************************************************/ #include <windows.h> #include <string> #include <ecl/exceptions/standard_exception.hpp> #include <ecl/utilities/parameter.hpp> #include <ecl/threads/thread.hpp> #include "serial_parameters.hpp" #include "traits.hpp" #include "macros.hpp" /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { /***************************************************************************** ** Interface [Serial] *****************************************************************************/ /** * @brief Win32 implementation for a serial (RS232) device. * * This device is a c++ wrapper around the win32 api for serial (RS232 devices). It * configures the serial device as a non-seekable source-sink (read-write), * device. * * Just a quick note about the serial termios functions. They can * be configured in a variety of ways for a variety of * situations (modems, terminals, login consoles). Most of these are * redundant for control, so we just keep it simple here * and use a simple wrapper around a useful configuration for * control. This keeps * options and settings to a minimum and lets us get on with the job * of control. * * <b>Read Modes</b> * * In posix, there are several available read modes. As mentioned above, * some of these are for all intents and purposes, redundant for control. * One particular example is the message * buffering configuration that uses both a packet size limit as well * as an inter-byte timeout when reading. Unfortunately the minimum inter-byte * timeout is a massive 200ms, which makes it all but useless for * control. * * Subsequently, the default mode of operation is using * a timeout - as this one will automatically return you whenever any * new data comes in. Great for control! An alternative non-blocking option is * also provided. * * <b>Usage</b>: * * The serial device does both input and output, using the usual read/write * interface with your preference of RAII/non-RAII style interface. In either * case, the serial class does the cleanup for you in the destructor. * * Protocol configuration is done either in the constructor or the open() * command by passing a port name and a set of enumerated * protocol configuration parameters - @ref BaudRate "baud rate", * @ref DataBits "data bits", @ref StopBits "stop bits", * and @ref Parity "parity" are defined via enums. * * @code * Serial serial_raii("/dev/ttyS0",BaudRate_115200,DataBits_8,StopBits_1,NoParity); // RAII * Serial serial_nonraii; * serial_nonraii.open("/dev/ttyS0",BaudRate_115200,DataBits_8,StopBits_1,NoParity); // non-RAII * @endcode * * Reading with various timeouts. * * @code * int n; * char buffer[256]; * serial.block(500); // timeout of 500ms * n = serial.read(buffer,256); * serial.unblock(); * n = serial.read(buffer,256); // always returns, even if nothing is there. * @endcode * * Writing: * * @code * serial.write("Dude\n",5); * @endcode * * @todo Another option in future would be to utilise the asynchronous * configuration mode for serial ports (see * http://www.faqs.org/docs/Linux-HOWTO/Serial-Programming-HOWTO.html#AEN144). * This might get around some bottlenecking io performance problems. */ class ecl_devices_PUBLIC Serial { public: /********************* ** C&D **********************/ /** * @brief Non-RAII style constructor, doesn't make a connection. * * Sometimes its more convenient to open manually rather than inside * constructors. Use this with the open() command to do so. You can * check for open status with via the open accessor. */ Serial() : is_open(false), is_run(false), file_descriptor(INVALID_HANDLE_VALUE), error_handler(NoError) {}; /** * @brief Constructs and opens the connection, RAII style. * * Configures and opens the serial device (RAII style) with the specified * parameters. * * By default, the port is configured to read in blocking mode * (with no timeouts) - use the block(), block(timeout_ms) and unbock() * methods to alter its behaviour. * @param port_name : the device name. * @param baud_rate : baud rate. * @param data_bits : the number of bits in a single message byte. * @param stop_bits : the number of bits after the data used for error checking. * @param parity : the parity used for checksums. * @exception StandardException : throws if the connection failed to open. */ Serial(const std::string& port_name, const BaudRate &baud_rate = BaudRate_115200, const DataBits &data_bits = DataBits_8, const StopBits &stop_bits = StopBits_1, const Parity &parity = NoParity ) ecl_throw_decl(StandardException); /** * @brief Cleans up the file descriptor. * * Cleans up the file descriptor. */ virtual ~Serial(); /********************* ** Open/Close **********************/ /** * @brief Opens the connection. * * Configures and opens the serial device with the specified * parameters. You don't need to do this if you constructed this class with the RAII * style constructor. * * If the device is already open, it will first close and then reopen the device. * * @param port_name : the device name. * @param baud_rate : baud rate. * @param data_bits : the number of bits in a single message byte. * @param stop_bits : the number of bits after the data used for error checking. * @param parity : the parity used for checksums. * @exception StandardException : throws if the connection failed to open. */ void open(const std::string& port_name, const BaudRate &baud_rate = BaudRate_115200, const DataBits &data_bits = DataBits_8, const StopBits &stop_bits = StopBits_1, const Parity &parity = NoParity ) ecl_throw_decl(StandardException); /** * @brief Closes the port connection. * * The destructor automatically handles this, so in most cases its redundant. * However there are times when a serial port must be temporarily closed. * This enables you to do that. */ void close(); /** * @brief Status flag indicating if the serial port is open/closed. * * True if the serial port is open and connected, false otherwise. */ bool open() const { return is_open; } /********************* ** Writing **********************/ /** * @brief Write a character to the serial port. * * Write a character to the serial port. * * @param c : the character to write. * @exception StandardException : throws if writing returned an error [debug mode only]. **/ long write(const char &c) ecl_assert_throw_decl(StandardException); /** * @brief Write a character string to the serial port. * * Write a character string to the serial port. * @param s : points to the beginning of the character string. * @param n : the number of characters to write. * @exception StandardException : throws if writing returned an error [debug mode only]. **/ long write(const char *s, unsigned long n) ecl_assert_throw_decl(StandardException); /** * @brief A dummy flush function, not used, but needed by streams. * * This is unused - but is included so as to implement streaming functionality * on top of this device. */ void flush() {} /********************* ** Reading Modes **********************/ /** * @brief Switch to blocking mode with a timeout for reading. * * Switched to blocking mode with the specified timeout in milliseconds. * * @param timeout : timeout measured in ms. * * @exception StandardException : throws if a timeout < 0 is specified [debug mode only]. */ void block(const long &timeout = 500) ecl_assert_throw_decl(StandardException); /** * @brief Switch to unbocked mode for reading. * * This causes the serial port to automatically return from a read, even * if there is no data available. */ void unblock(); /********************* ** Reading **********************/ /** * @brief Get the number of bytes remaining in the buffer, but do not read. * * Check the serial port's buffer to determine how many bytes are left in the buffer for reading. * * @return int : the number of bytes in the buffer **/ long remaining(); /** * @brief Read a character from the port. * * Uses the current device configuration * for reading. The blocking policy is defined by the current parameters * of the port. * * @param c : character to read into from the serial port's buffer. * @exception StandardException : throws if reading returned an error [debug mode only]. **/ long read(char &c) ecl_assert_throw_decl(StandardException); /** * @brief Read a character string from the port. * * Uses the current device configuration * for reading. The blocking policy is defined by the current parameters * of the port. * * @param s : character string to read into from the serial port's buffer. * @param n : the number of bytes to read. * @exception StandardException : throws if reading returned an error [debug mode only]. **/ long read(char *s, const unsigned long &n) ecl_assert_throw_decl(StandardException); /********************* ** Serial Specific **********************/ /** * @brief Clear both input and output buffers. * * Serial input and output buffers are managed by the system. This clears * them both. */ void clear() { PurgeComm( file_descriptor, PURGE_RXCLEAR ); PurgeComm( file_descriptor, PURGE_TXCLEAR ); } /** * @brief Clear the input buffer. * * The serial input buffer are managed by the system. This clears it. */ void clearInputBuffer() { PurgeComm( file_descriptor, PURGE_RXCLEAR ); } /** * @brief Clear the output buffer. * * The serial output buffer are managed by the system. This clears it. */ void clearOutputBuffer() { PurgeComm( file_descriptor, PURGE_TXCLEAR ); } /** * @brief Return the latest error state for this serial object. * * Return the error result from the last used open/read/write * method in this class. */ const Error& error() const { return error_handler; } private: /********************* ** Variables **********************/ HANDLE file_descriptor; OVERLAPPED m_osRead, m_osWrite; // Offsets std::string port; bool is_open; ecl::Error error_handler; Thread event_receiver; bool is_run; private: /** * @brief Threading procedure for serial port. * * Receiving event generated by communication port. */ friend void event_proc(void* arg); }; /***************************************************************************** ** Traits [Serial] *****************************************************************************/ /** * @brief Serial sink (output device) trait. * * Specialisation for the serial sink (output device) trait. */ template <> class is_sink<Serial> : public True {}; /** * @brief Serial sink (input device) trait. * * Specialisation for the serial sink (input device) trait. */ template <> class is_source<Serial> : public True {}; /** * @brief Serial sourcesink (input-output device) trait. * * Specialisation for the serial sourcesink (input-output device) trait. */ template <> class is_sourcesink<Serial> : public True {}; } // namespace ecl #endif /* ECL_IS_WIN32 */ #endif /* ECL_THREADS_SERIAL_W32_HPP_ */
; A263511: Total number of ON (black) cells after n iterations of the "Rule 155" elementary cellular automaton starting with a single ON (black) cell. ; 1,3,6,12,19,29,40,54,69,87,106,128,151,177,204,234,265,299,334,372,411,453,496,542,589,639,690,744,799,857,916,978,1041,1107,1174,1244,1315,1389,1464,1542,1621,1703,1786,1872,1959,2049,2140,2234,2329,2427,2526,2628,2731,2837,2944,3054,3165,3279,3394,3512,3631,3753,3876,4002,4129,4259,4390,4524,4659,4797,4936,5078,5221,5367,5514,5664,5815,5969,6124,6282,6441,6603,6766,6932,7099,7269,7440,7614,7789,7967,8146,8328,8511,8697,8884,9074,9265,9459,9654,9852,10051,10253,10456,10662,10869,11079,11290,11504,11719,11937,12156,12378,12601,12827,13054,13284,13515,13749,13984,14222,14461,14703,14946,15192,15439,15689,15940,16194,16449,16707,16966,17228,17491,17757,18024,18294,18565,18839,19114,19392,19671,19953,20236,20522,20809,21099,21390,21684,21979,22277,22576,22878,23181,23487,23794,24104,24415,24729,25044,25362,25681,26003,26326,26652,26979,27309,27640,27974,28309,28647,28986,29328,29671,30017,30364,30714,31065,31419,31774,32132,32491,32853,33216,33582,33949,34319,34690,35064,35439,35817,36196,36578,36961,37347,37734,38124,38515,38909,39304,39702,40101,40503,40906,41312,41719,42129,42540,42954,43369,43787,44206,44628,45051,45477,45904,46334,46765,47199,47634,48072,48511,48953,49396,49842,50289,50739,51190,51644,52099,52557,53016,53478,53941,54407,54874,55344,55815,56289,56764,57242,57721,58203,58686,59172,59659,60149,60640,61134,61629,62127 mov $1,1 add $1,$0 pow $0,2 div $1,2 add $1,$0 add $1,1
; A242084: 5^p - 4^p - 1, where p is prime. ; Submitted by Jamie Morken(s3) ; 8,60,2100,61740,44633820,1153594260,745759583940,18798608421180,11850560210900460,185976284546943991380,4652001187058965190220,72740686675902780452348340,45469899385367953379053128420,1136791005963704961126617632860,710522928719471619786725881590540,11102149116613150797554620891903059060,173472015290681763212224222187425603741980,4336803373030034596366319588251525724324820,67762614002272544185404138398396481330945794940,42351641787528717320760339650052529940479203583020 seq $0,40 ; The prime numbers. seq $0,5060 ; a(n) = 5^n - 4^n. sub $0,1
.global s_prepare_buffers s_prepare_buffers: push %r13 push %rcx push %rdi push %rdx lea addresses_UC_ht+0x18250, %rdx cmp %rcx, %rcx mov $0x6162636465666768, %r13 movq %r13, %xmm4 and $0xffffffffffffffc0, %rdx vmovntdq %ymm4, (%rdx) nop sub %rdi, %rdi pop %rdx pop %rdi pop %rcx pop %r13 ret .global s_faulty_load s_faulty_load: push %r13 push %r8 push %rbp push %rbx push %rcx push %rdi push %rdx // Load mov $0x5ad77600000005b8, %r13 nop nop and $16996, %rcx movb (%r13), %bl nop dec %r13 // Load lea addresses_US+0x175b8, %rdi nop sub $19913, %rbp mov (%rdi), %bx nop nop nop nop nop cmp $21688, %rbx // Store lea addresses_WT+0x151b8, %r8 clflush (%r8) nop nop nop and %rdx, %rdx mov $0x5152535455565758, %rbx movq %rbx, %xmm2 vmovups %ymm2, (%r8) nop and %rbp, %rbp // Store lea addresses_A+0x191b8, %r13 nop nop nop and $36012, %rbp mov $0x5152535455565758, %rdx movq %rdx, %xmm5 vmovups %ymm5, (%r13) nop nop add %rcx, %rcx // Store mov $0x71ca530000000558, %rdi sub $2898, %rbp movb $0x51, (%rdi) nop nop nop nop nop add $38481, %r13 // Store lea addresses_WT+0x1ec98, %r13 nop nop sub $52302, %rbp mov $0x5152535455565758, %rcx movq %rcx, %xmm1 vmovups %ymm1, (%r13) nop nop nop sub $49342, %rbx // Load lea addresses_US+0x3db8, %rdi nop nop nop nop nop xor $29658, %rbp movups (%rdi), %xmm7 vpextrq $1, %xmm7, %r13 nop nop nop nop nop add %r13, %r13 // Faulty Load mov $0x54e00c0000000db8, %rbx nop nop nop nop add $6349, %rbp movups (%rbx), %xmm1 vpextrq $0, %xmm1, %r8 lea oracles, %rbx and $0xff, %r8 shlq $12, %r8 mov (%rbx,%r8,1), %r8 pop %rdx pop %rdi pop %rcx pop %rbx pop %rbp pop %r8 pop %r13 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_NC', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'} {'src': {'NT': False, 'same': False, 'congruent': 11, 'type': 'addresses_NC', 'AVXalign': True, 'size': 1}, 'OP': 'LOAD'} {'src': {'NT': False, 'same': False, 'congruent': 6, 'type': 'addresses_US', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 9, 'type': 'addresses_WT', 'AVXalign': False, 'size': 32}} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 9, 'type': 'addresses_A', 'AVXalign': False, 'size': 32}} {'OP': 'STOR', 'dst': {'NT': True, 'same': False, 'congruent': 2, 'type': 'addresses_NC', 'AVXalign': False, 'size': 1}} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 5, 'type': 'addresses_WT', 'AVXalign': False, 'size': 32}} {'src': {'NT': False, 'same': False, 'congruent': 10, 'type': 'addresses_US', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'} [Faulty Load] {'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_NC', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'NT': True, 'same': False, 'congruent': 2, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 32}} {'00': 6087} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r13 push %r8 push %r9 push %rbx push %rcx push %rdi push %rsi lea addresses_WC_ht+0x1513e, %r9 nop nop and %r8, %r8 mov $0x6162636465666768, %r11 movq %r11, (%r9) nop nop nop xor $59653, %r13 lea addresses_UC_ht+0x853e, %rsi lea addresses_normal_ht+0x198fe, %rdi nop nop cmp %rbx, %rbx mov $102, %rcx rep movsw add $9518, %rsi lea addresses_WT_ht+0x1951e, %r9 mfence mov $0x6162636465666768, %r11 movq %r11, %xmm0 movups %xmm0, (%r9) cmp %rsi, %rsi lea addresses_WC_ht+0x1d33e, %r8 nop nop sub $57549, %r13 mov (%r8), %ecx nop nop nop nop nop xor %rbx, %rbx lea addresses_WT_ht+0xf13e, %rsi lea addresses_UC_ht+0x1a3ee, %rdi nop nop nop add %r13, %r13 mov $31, %rcx rep movsq dec %r8 lea addresses_D_ht+0x1573e, %rsi lea addresses_normal_ht+0x1527e, %rdi nop nop nop sub $54120, %r9 mov $27, %rcx rep movsq nop nop dec %r8 pop %rsi pop %rdi pop %rcx pop %rbx pop %r9 pop %r8 pop %r13 pop %r11 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r14 push %r15 push %rax push %rdi push %rdx // Store lea addresses_UC+0x791e, %rax nop nop nop nop cmp $58963, %r12 mov $0x5152535455565758, %r11 movq %r11, %xmm1 vmovups %ymm1, (%rax) nop nop nop nop inc %r14 // Faulty Load lea addresses_PSE+0x713e, %r15 nop nop sub $31915, %rdi movb (%r15), %r12b lea oracles, %rax and $0xff, %r12 shlq $12, %r12 mov (%rax,%r12,1), %r12 pop %rdx pop %rdi pop %rax pop %r15 pop %r14 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_PSE', 'same': False, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_UC', 'same': False, 'size': 32, 'congruent': 4, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} [Faulty Load] {'src': {'type': 'addresses_PSE', 'same': True, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 8, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_UC_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 16, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 4, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 3, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_D_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': True}, 'OP': 'REPM'} {'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 */
SECTION code_fp_math48 PUBLIC _asin EXTERN cm48_sdccix_asin defc _asin = cm48_sdccix_asin
.size 8000 .text@48 jp lstatint .text@100 jp lbegin .text@150 lbegin: ld a, ff ldff(45), a ld b, 91 call lwaitly_b xor a, a ldff(40), a ld hl, fea0 lbegin_fill_oam: dec l ld(hl), a jrnz lbegin_fill_oam ld hl, fe9c ld d, 10 ld a, d ld(hl), a inc l ld a, 18 ld(hl), a ld a, 97 ldff(40), a call lwaitly_b ld a, 40 ldff(41), a ld a, 02 ldff(ff), a xor a, a ldff(0f), a ei ld a, 97 ldff(45), a ld c, 41 .text@1000 lstatint: nop .text@14f5 ld a, 95 ldff(40), a .text@151a ldff a, (c) and a, 03 jp lprint_a .text@7000 lprint_a: push af ld b, 91 call lwaitly_b xor a, a ldff(40), a pop af ld(9800), a ld bc, 7a00 ld hl, 8000 ld d, a0 lprint_copytiles: ld a, (bc) inc bc ld(hl++), a dec d jrnz lprint_copytiles ld a, c0 ldff(47), a ld a, 80 ldff(68), a ld a, ff ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a xor a, a ldff(69), a ldff(69), a ldff(43), a ld a, 91 ldff(40), a lprint_limbo: jr lprint_limbo .text@7400 lwaitly_b: ld c, 44 lwaitly_b_loop: ldff a, (c) cmp a, b jrnz lwaitly_b_loop ret .data@7a00 00 00 7f 7f 41 41 41 41 41 41 41 41 41 41 7f 7f 00 00 08 08 08 08 08 08 08 08 08 08 08 08 08 08 00 00 7f 7f 01 01 01 01 7f 7f 40 40 40 40 7f 7f 00 00 7f 7f 01 01 01 01 3f 3f 01 01 01 01 7f 7f 00 00 41 41 41 41 41 41 7f 7f 01 01 01 01 01 01 00 00 7f 7f 40 40 40 40 7e 7e 01 01 01 01 7e 7e 00 00 7f 7f 40 40 40 40 7f 7f 41 41 41 41 7f 7f 00 00 7f 7f 01 01 02 02 04 04 08 08 10 10 10 10 00 00 3e 3e 41 41 41 41 3e 3e 41 41 41 41 3e 3e 00 00 7f 7f 41 41 41 41 7f 7f 01 01 01 01 7f 7f
; A262389: Numbers whose last digit is composite. ; Submitted by Jon Maiga ; 4,6,8,9,14,16,18,19,24,26,28,29,34,36,38,39,44,46,48,49,54,56,58,59,64,66,68,69,74,76,78,79,84,86,88,89,94,96,98,99,104,106,108,109,114,116,118,119,124,126,128,129,134,136,138,139,144,146,148,149 mul $0,5 mov $1,$0 bin $0,3 mod $0,2 div $1,4 sub $0,$1 sub $1,$0 mov $0,$1 add $0,4
; ; Word: OVER ; Dictionary: (a b - a b a) ; Date: 1st February 2018 ; Macro: Yes ; Notes: ; pop ix pop hl ; 2nd on stack push hl ; push back push de ; push TOS ex de,hl ; 2nd to TOS jp (ix)
TITLE Program Template (RevStr.asm) ; This program reverses a string. ; Last update: 1/28/02 INCLUDE Irvine32.inc .data aName BYTE "Abraham Lincoln",0 nameSize = ($ - aName) - 1 .code main PROC ; Push the name on the stack. mov ecx,nameSize mov esi,0 L1: movzx eax,aName[esi] ; get character push eax ; push on stack inc esi Loop L1 ; Pop the name from the stack, in reverse, ; and store in the aName array. mov ecx,nameSize mov esi,0 L2: pop eax ; get character mov aName[esi],al ; store in string inc esi Loop L2 ; Display the name. mov edx,OFFSET aName call Writestring call Crlf exit main ENDP END main
############################################################################### # Copyright 2018 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .section .note.GNU-stack,"",%progbits .text .p2align 5, 0x90 .globl g9_EncryptOFB_RIJ128_AES_NI .type g9_EncryptOFB_RIJ128_AES_NI, @function g9_EncryptOFB_RIJ128_AES_NI: push %ebp mov %esp, %ebp push %ebx push %esi push %edi sub $(164), %esp movl (32)(%ebp), %eax movdqu (%eax), %xmm0 movdqu %xmm0, (%esp) movl (16)(%ebp), %eax movl (20)(%ebp), %ecx lea (,%eax,4), %eax lea (,%eax,4), %eax lea (%ecx,%eax), %ecx neg %eax movl %eax, (16)(%ebp) movl %ecx, (20)(%ebp) movl (8)(%ebp), %esi movl (12)(%ebp), %edi movl (28)(%ebp), %ebx .p2align 5, 0x90 .Lblks_loopgas_1: lea (,%ebx,4), %ebx cmpl %ebx, (24)(%ebp) cmovll (24)(%ebp), %ebx xor %ecx, %ecx .L__0000gas_1: movb (%esi,%ecx), %dl movb %dl, (96)(%esp,%ecx) add $(1), %ecx cmp %ebx, %ecx jl .L__0000gas_1 movl (20)(%ebp), %ecx movl (16)(%ebp), %eax movl %ebx, (160)(%esp) xor %edx, %edx .p2align 5, 0x90 .Lsingle_blkgas_1: movdqa (%ecx,%eax), %xmm3 add $(16), %eax movdqa (%ecx,%eax), %xmm4 pxor %xmm3, %xmm0 .p2align 5, 0x90 .Lcipher_loopgas_1: add $(16), %eax aesenc %xmm4, %xmm0 movdqa (%ecx,%eax), %xmm4 jnz .Lcipher_loopgas_1 aesenclast %xmm4, %xmm0 movdqu %xmm0, (16)(%esp) movl (28)(%ebp), %eax movdqu (96)(%esp,%edx), %xmm1 pxor %xmm0, %xmm1 movdqu %xmm1, (32)(%esp,%edx) movdqu (%esp,%eax), %xmm0 movdqu %xmm0, (%esp) add %eax, %edx movl (16)(%ebp), %eax cmp %ebx, %edx jl .Lsingle_blkgas_1 xor %ecx, %ecx .L__0001gas_1: movb (32)(%esp,%ecx), %bl movb %bl, (%edi,%ecx) add $(1), %ecx cmp %edx, %ecx jl .L__0001gas_1 movl (28)(%ebp), %ebx add %edx, %esi add %edx, %edi subl %edx, (24)(%ebp) jg .Lblks_loopgas_1 movl (32)(%ebp), %eax movdqu (%esp), %xmm0 movdqu %xmm0, (%eax) add $(164), %esp pop %edi pop %esi pop %ebx pop %ebp ret .Lfe1: .size g9_EncryptOFB_RIJ128_AES_NI, .Lfe1-(g9_EncryptOFB_RIJ128_AES_NI) .p2align 5, 0x90 .globl g9_EncryptOFB128_RIJ128_AES_NI .type g9_EncryptOFB128_RIJ128_AES_NI, @function g9_EncryptOFB128_RIJ128_AES_NI: push %ebp mov %esp, %ebp push %esi push %edi movl (28)(%ebp), %eax movdqu (%eax), %xmm0 movl (16)(%ebp), %eax movl (20)(%ebp), %ecx lea (,%eax,4), %eax lea (,%eax,4), %eax lea (%ecx,%eax), %ecx neg %eax movl %eax, (16)(%ebp) movl (8)(%ebp), %esi movl (12)(%ebp), %edi movl (24)(%ebp), %edx .p2align 5, 0x90 .Lblks_loopgas_2: movdqa (%ecx,%eax), %xmm3 add $(16), %eax .p2align 5, 0x90 .Lsingle_blkgas_2: movdqa (%ecx,%eax), %xmm4 pxor %xmm3, %xmm0 movdqu (%esi), %xmm1 .p2align 5, 0x90 .Lcipher_loopgas_2: add $(16), %eax aesenc %xmm4, %xmm0 movdqa (%ecx,%eax), %xmm4 jnz .Lcipher_loopgas_2 aesenclast %xmm4, %xmm0 pxor %xmm0, %xmm1 movdqu %xmm1, (%edi) movl (16)(%ebp), %eax add $(16), %esi add $(16), %edi sub $(16), %edx jg .Lblks_loopgas_2 movl (28)(%ebp), %eax movdqu %xmm0, (%eax) pop %edi pop %esi pop %ebp ret .Lfe2: .size g9_EncryptOFB128_RIJ128_AES_NI, .Lfe2-(g9_EncryptOFB128_RIJ128_AES_NI)
; A006308: Coefficients of period polynomials. ; 3,10,21,55,78,136,171,253,406,465,666,820,903,1081,1378,1711,1830,2211,2485,2628,3081,3403,3916,4656,5050 add $0,1 cal $0,72205 ; a(n) = (p^2 - p + 2)/2 for p = prime(n); number of squares modulo p^2. mov $1,$0 mul $1,17 sub $1,68 div $1,17 add $1,3
section .data var1: dq 0x_1234_5678_90ab_cdef var2: dq 0x_fedc_ba12_3456_7890 var3: dq 0x_1234_5678_09ab_cdef section .bss section .text global main main: ;; scab rax vs rdi cld ;; clear direction flag mov rax, 0x_1234_5678_90ab_cdef lea rdi, [var1] scasq ;; scan a register string qword to rdi(es:edi) ;; scab rax vs rdi cld ;; clear direction flag ;mov rax, 0x_1234_5678_90ab_cdef lea rdi, [var2] scasq ;; scan a register string qword to rdi(es:edi) ;; set CF ;; cmpsb compare memory(ds:si vs es:di) cld lea rsi, [var1] lea rdi, [var3] cmpsq ;; set ZF ;; exit mov rax, 60 mov rdi, 0 syscall
; ; jdmrgext.asm - merged upsampling/color conversion (64-bit SSE2) ; ; Copyright 2009, 2012 Pierre Ossman <ossman@cendio.se> for Cendio AB ; Copyright (C) 2009, 2012, 2016, D. R. Commander. ; ; Based on the x86 SIMD extension for IJG JPEG library ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; ; This file should be assembled with NASM (Netwide Assembler), ; can *not* be assembled with Microsoft's MASM or any compatible ; assembler (including Borland's Turbo Assembler). ; NASM is available from http://nasm.sourceforge.net/ or ; http://sourceforge.net/project/showfiles.php?group_id=6208 ; ; [TAB8] %include "jcolsamp.inc" ; -------------------------------------------------------------------------- ; ; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. ; ; GLOBAL(void) ; jsimd_h2v1_merged_upsample_sse2(JDIMENSION output_width, ; JSAMPIMAGE input_buf, ; JDIMENSION in_row_group_ctr, ; JSAMPARRAY output_buf); ; ; r10d = JDIMENSION output_width ; r11 = JSAMPIMAGE input_buf ; r12d = JDIMENSION in_row_group_ctr ; r13 = JSAMPARRAY output_buf %define wk(i) rbp - (WK_NUM - (i)) * SIZEOF_XMMWORD ; xmmword wk[WK_NUM] %define WK_NUM 3 align 32 GLOBAL_FUNCTION(jsimd_h2v1_merged_upsample_sse2) EXTN(jsimd_h2v1_merged_upsample_sse2): push rbp mov rax, rsp ; rax = original rbp sub rsp, byte 4 and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits mov [rsp], rax mov rbp, rsp ; rbp = aligned rbp lea rsp, [wk(0)] collect_args 4 push rbx mov ecx, r10d ; col test rcx, rcx jz near .return push rcx mov rdi, r11 mov ecx, r12d mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY] mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY] mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY] mov rdi, r13 mov rsi, JSAMPROW [rsi+rcx*SIZEOF_JSAMPROW] ; inptr0 mov rbx, JSAMPROW [rbx+rcx*SIZEOF_JSAMPROW] ; inptr1 mov rdx, JSAMPROW [rdx+rcx*SIZEOF_JSAMPROW] ; inptr2 mov rdi, JSAMPROW [rdi] ; outptr pop rcx ; col .columnloop: movdqa xmm6, XMMWORD [rbx] ; xmm6=Cb(0123456789ABCDEF) movdqa xmm7, XMMWORD [rdx] ; xmm7=Cr(0123456789ABCDEF) pxor xmm1, xmm1 ; xmm1=(all 0's) pcmpeqw xmm3, xmm3 psllw xmm3, 7 ; xmm3={0xFF80 0xFF80 0xFF80 0xFF80 ..} movdqa xmm4, xmm6 punpckhbw xmm6, xmm1 ; xmm6=Cb(89ABCDEF)=CbH punpcklbw xmm4, xmm1 ; xmm4=Cb(01234567)=CbL movdqa xmm0, xmm7 punpckhbw xmm7, xmm1 ; xmm7=Cr(89ABCDEF)=CrH punpcklbw xmm0, xmm1 ; xmm0=Cr(01234567)=CrL paddw xmm6, xmm3 paddw xmm4, xmm3 paddw xmm7, xmm3 paddw xmm0, xmm3 ; (Original) ; R = Y + 1.40200 * Cr ; G = Y - 0.34414 * Cb - 0.71414 * Cr ; B = Y + 1.77200 * Cb ; ; (This implementation) ; R = Y + 0.40200 * Cr + Cr ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr ; B = Y - 0.22800 * Cb + Cb + Cb movdqa xmm5, xmm6 ; xmm5=CbH movdqa xmm2, xmm4 ; xmm2=CbL paddw xmm6, xmm6 ; xmm6=2*CbH paddw xmm4, xmm4 ; xmm4=2*CbL movdqa xmm1, xmm7 ; xmm1=CrH movdqa xmm3, xmm0 ; xmm3=CrL paddw xmm7, xmm7 ; xmm7=2*CrH paddw xmm0, xmm0 ; xmm0=2*CrL pmulhw xmm6, [rel PW_MF0228] ; xmm6=(2*CbH * -FIX(0.22800)) pmulhw xmm4, [rel PW_MF0228] ; xmm4=(2*CbL * -FIX(0.22800)) pmulhw xmm7, [rel PW_F0402] ; xmm7=(2*CrH * FIX(0.40200)) pmulhw xmm0, [rel PW_F0402] ; xmm0=(2*CrL * FIX(0.40200)) paddw xmm6, [rel PW_ONE] paddw xmm4, [rel PW_ONE] psraw xmm6, 1 ; xmm6=(CbH * -FIX(0.22800)) psraw xmm4, 1 ; xmm4=(CbL * -FIX(0.22800)) paddw xmm7, [rel PW_ONE] paddw xmm0, [rel PW_ONE] psraw xmm7, 1 ; xmm7=(CrH * FIX(0.40200)) psraw xmm0, 1 ; xmm0=(CrL * FIX(0.40200)) paddw xmm6, xmm5 paddw xmm4, xmm2 paddw xmm6, xmm5 ; xmm6=(CbH * FIX(1.77200))=(B-Y)H paddw xmm4, xmm2 ; xmm4=(CbL * FIX(1.77200))=(B-Y)L paddw xmm7, xmm1 ; xmm7=(CrH * FIX(1.40200))=(R-Y)H paddw xmm0, xmm3 ; xmm0=(CrL * FIX(1.40200))=(R-Y)L movdqa XMMWORD [wk(0)], xmm6 ; wk(0)=(B-Y)H movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=(R-Y)H movdqa xmm6, xmm5 movdqa xmm7, xmm2 punpcklwd xmm5, xmm1 punpckhwd xmm6, xmm1 pmaddwd xmm5, [rel PW_MF0344_F0285] pmaddwd xmm6, [rel PW_MF0344_F0285] punpcklwd xmm2, xmm3 punpckhwd xmm7, xmm3 pmaddwd xmm2, [rel PW_MF0344_F0285] pmaddwd xmm7, [rel PW_MF0344_F0285] paddd xmm5, [rel PD_ONEHALF] paddd xmm6, [rel PD_ONEHALF] psrad xmm5, SCALEBITS psrad xmm6, SCALEBITS paddd xmm2, [rel PD_ONEHALF] paddd xmm7, [rel PD_ONEHALF] psrad xmm2, SCALEBITS psrad xmm7, SCALEBITS packssdw xmm5, xmm6 ; xmm5=CbH*-FIX(0.344)+CrH*FIX(0.285) packssdw xmm2, xmm7 ; xmm2=CbL*-FIX(0.344)+CrL*FIX(0.285) psubw xmm5, xmm1 ; xmm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H psubw xmm2, xmm3 ; xmm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L movdqa XMMWORD [wk(2)], xmm5 ; wk(2)=(G-Y)H mov al, 2 ; Yctr jmp short .Yloop_1st .Yloop_2nd: movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(R-Y)H movdqa xmm2, XMMWORD [wk(2)] ; xmm2=(G-Y)H movdqa xmm4, XMMWORD [wk(0)] ; xmm4=(B-Y)H .Yloop_1st: movdqa xmm7, XMMWORD [rsi] ; xmm7=Y(0123456789ABCDEF) pcmpeqw xmm6, xmm6 psrlw xmm6, BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} pand xmm6, xmm7 ; xmm6=Y(02468ACE)=YE psrlw xmm7, BYTE_BIT ; xmm7=Y(13579BDF)=YO movdqa xmm1, xmm0 ; xmm1=xmm0=(R-Y)(L/H) movdqa xmm3, xmm2 ; xmm3=xmm2=(G-Y)(L/H) movdqa xmm5, xmm4 ; xmm5=xmm4=(B-Y)(L/H) paddw xmm0, xmm6 ; xmm0=((R-Y)+YE)=RE=R(02468ACE) paddw xmm1, xmm7 ; xmm1=((R-Y)+YO)=RO=R(13579BDF) packuswb xmm0, xmm0 ; xmm0=R(02468ACE********) packuswb xmm1, xmm1 ; xmm1=R(13579BDF********) paddw xmm2, xmm6 ; xmm2=((G-Y)+YE)=GE=G(02468ACE) paddw xmm3, xmm7 ; xmm3=((G-Y)+YO)=GO=G(13579BDF) packuswb xmm2, xmm2 ; xmm2=G(02468ACE********) packuswb xmm3, xmm3 ; xmm3=G(13579BDF********) paddw xmm4, xmm6 ; xmm4=((B-Y)+YE)=BE=B(02468ACE) paddw xmm5, xmm7 ; xmm5=((B-Y)+YO)=BO=B(13579BDF) packuswb xmm4, xmm4 ; xmm4=B(02468ACE********) packuswb xmm5, xmm5 ; xmm5=B(13579BDF********) %if RGB_PIXELSIZE == 3 ; --------------- ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **) punpcklbw xmmA, xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) punpcklbw xmmE, xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F) punpcklbw xmmD, xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F) movdqa xmmG, xmmA movdqa xmmH, xmmA punpcklwd xmmA, xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07) punpckhwd xmmG, xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F) psrldq xmmH, 2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --) psrldq xmmE, 2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --) movdqa xmmC, xmmD movdqa xmmB, xmmD punpcklwd xmmD, xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18) punpckhwd xmmC, xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --) psrldq xmmB, 2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --) movdqa xmmF, xmmE punpcklwd xmmE, xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29) punpckhwd xmmF, xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --) pshufd xmmH, xmmA, 0x4E ; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03) movdqa xmmB, xmmE punpckldq xmmA, xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14) punpckldq xmmE, xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07) punpckhdq xmmD, xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29) pshufd xmmH, xmmG, 0x4E ; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B) movdqa xmmB, xmmF punpckldq xmmG, xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C) punpckldq xmmF, xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F) punpckhdq xmmC, xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --) punpcklqdq xmmA, xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) punpcklqdq xmmD, xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) punpcklqdq xmmF, xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) cmp rcx, byte SIZEOF_XMMWORD jb short .column_st32 test rdi, SIZEOF_XMMWORD-1 jnz short .out1 ; --(aligned)------------------- movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF jmp short .out0 .out1: ; --(unaligned)----------------- movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF .out0: add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr sub rcx, byte SIZEOF_XMMWORD jz near .endcolumn add rsi, byte SIZEOF_XMMWORD ; inptr0 dec al ; Yctr jnz near .Yloop_2nd add rbx, byte SIZEOF_XMMWORD ; inptr1 add rdx, byte SIZEOF_XMMWORD ; inptr2 jmp near .columnloop .column_st32: lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE cmp rcx, byte 2*SIZEOF_XMMWORD jb short .column_st16 movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD add rdi, byte 2*SIZEOF_XMMWORD ; outptr movdqa xmmA, xmmF sub rcx, byte 2*SIZEOF_XMMWORD jmp short .column_st15 .column_st16: cmp rcx, byte SIZEOF_XMMWORD jb short .column_st15 movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA add rdi, byte SIZEOF_XMMWORD ; outptr movdqa xmmA, xmmD sub rcx, byte SIZEOF_XMMWORD .column_st15: ; Store the lower 8 bytes of xmmA to the output when it has enough ; space. cmp rcx, byte SIZEOF_MMWORD jb short .column_st7 movq XMM_MMWORD [rdi], xmmA add rdi, byte SIZEOF_MMWORD sub rcx, byte SIZEOF_MMWORD psrldq xmmA, SIZEOF_MMWORD .column_st7: ; Store the lower 4 bytes of xmmA to the output when it has enough ; space. cmp rcx, byte SIZEOF_DWORD jb short .column_st3 movd XMM_DWORD [rdi], xmmA add rdi, byte SIZEOF_DWORD sub rcx, byte SIZEOF_DWORD psrldq xmmA, SIZEOF_DWORD .column_st3: ; Store the lower 2 bytes of rax to the output when it has enough ; space. movd eax, xmmA cmp rcx, byte SIZEOF_WORD jb short .column_st1 mov WORD [rdi], ax add rdi, byte SIZEOF_WORD sub rcx, byte SIZEOF_WORD shr rax, 16 .column_st1: ; Store the lower 1 byte of rax to the output when it has enough ; space. test rcx, rcx jz short .endcolumn mov BYTE [rdi], al %else ; RGB_PIXELSIZE == 4 ; ----------- %ifdef RGBX_FILLER_0XFF pcmpeqb xmm6, xmm6 ; xmm6=XE=X(02468ACE********) pcmpeqb xmm7, xmm7 ; xmm7=XO=X(13579BDF********) %else pxor xmm6, xmm6 ; xmm6=XE=X(02468ACE********) pxor xmm7, xmm7 ; xmm7=XO=X(13579BDF********) %endif ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **) punpcklbw xmmA, xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) punpcklbw xmmE, xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E) punpcklbw xmmB, xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F) punpcklbw xmmF, xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F) movdqa xmmC, xmmA punpcklwd xmmA, xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36) punpckhwd xmmC, xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E) movdqa xmmG, xmmB punpcklwd xmmB, xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37) punpckhwd xmmG, xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F) movdqa xmmD, xmmA punpckldq xmmA, xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) punpckhdq xmmD, xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) movdqa xmmH, xmmC punpckldq xmmC, xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) punpckhdq xmmH, xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) cmp rcx, byte SIZEOF_XMMWORD jb short .column_st32 test rdi, SIZEOF_XMMWORD-1 jnz short .out1 ; --(aligned)------------------- movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC movntdq XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH jmp short .out0 .out1: ; --(unaligned)----------------- movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC movdqu XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH .out0: add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr sub rcx, byte SIZEOF_XMMWORD jz near .endcolumn add rsi, byte SIZEOF_XMMWORD ; inptr0 dec al ; Yctr jnz near .Yloop_2nd add rbx, byte SIZEOF_XMMWORD ; inptr1 add rdx, byte SIZEOF_XMMWORD ; inptr2 jmp near .columnloop .column_st32: cmp rcx, byte SIZEOF_XMMWORD/2 jb short .column_st16 movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD add rdi, byte 2*SIZEOF_XMMWORD ; outptr movdqa xmmA, xmmC movdqa xmmD, xmmH sub rcx, byte SIZEOF_XMMWORD/2 .column_st16: cmp rcx, byte SIZEOF_XMMWORD/4 jb short .column_st15 movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA add rdi, byte SIZEOF_XMMWORD ; outptr movdqa xmmA, xmmD sub rcx, byte SIZEOF_XMMWORD/4 .column_st15: ; Store two pixels (8 bytes) of xmmA to the output when it has enough ; space. cmp rcx, byte SIZEOF_XMMWORD/8 jb short .column_st7 movq XMM_MMWORD [rdi], xmmA add rdi, byte SIZEOF_XMMWORD/8*4 sub rcx, byte SIZEOF_XMMWORD/8 psrldq xmmA, SIZEOF_XMMWORD/8*4 .column_st7: ; Store one pixel (4 bytes) of xmmA to the output when it has enough ; space. test rcx, rcx jz short .endcolumn movd XMM_DWORD [rdi], xmmA %endif ; RGB_PIXELSIZE ; --------------- .endcolumn: sfence ; flush the write buffer .return: pop rbx uncollect_args 4 mov rsp, rbp ; rsp <- aligned rbp pop rsp ; rsp <- original rbp pop rbp ret ; -------------------------------------------------------------------------- ; ; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. ; ; GLOBAL(void) ; jsimd_h2v2_merged_upsample_sse2(JDIMENSION output_width, ; JSAMPIMAGE input_buf, ; JDIMENSION in_row_group_ctr, ; JSAMPARRAY output_buf); ; ; r10d = JDIMENSION output_width ; r11 = JSAMPIMAGE input_buf ; r12d = JDIMENSION in_row_group_ctr ; r13 = JSAMPARRAY output_buf align 32 GLOBAL_FUNCTION(jsimd_h2v2_merged_upsample_sse2) EXTN(jsimd_h2v2_merged_upsample_sse2): push rbp mov rax, rsp mov rbp, rsp collect_args 4 push rbx mov eax, r10d mov rdi, r11 mov ecx, r12d mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY] mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY] mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY] mov rdi, r13 lea rsi, [rsi+rcx*SIZEOF_JSAMPROW] push rdx ; inptr2 push rbx ; inptr1 push rsi ; inptr00 mov rbx, rsp push rdi push rcx push rax %ifdef WIN64 mov r8, rcx mov r9, rdi mov rcx, rax mov rdx, rbx %else mov rdx, rcx mov rcx, rdi mov rdi, rax mov rsi, rbx %endif call EXTN(jsimd_h2v1_merged_upsample_sse2) pop rax pop rcx pop rdi pop rsi pop rbx pop rdx add rdi, byte SIZEOF_JSAMPROW ; outptr1 add rsi, byte SIZEOF_JSAMPROW ; inptr01 push rdx ; inptr2 push rbx ; inptr1 push rsi ; inptr00 mov rbx, rsp push rdi push rcx push rax %ifdef WIN64 mov r8, rcx mov r9, rdi mov rcx, rax mov rdx, rbx %else mov rdx, rcx mov rcx, rdi mov rdi, rax mov rsi, rbx %endif call EXTN(jsimd_h2v1_merged_upsample_sse2) pop rax pop rcx pop rdi pop rsi pop rbx pop rdx pop rbx uncollect_args 4 pop rbp ret ; For some reason, the OS X linker does not honor the request to align the ; segment unless we do this. align 32
mov r1, 2 mov r2, 6 pow r1, r2 out r1
; ; Copyright © 2015 Odzhan, Peter Ferrie. All Rights Reserved. ; ; Redistribution and use in source and binary forms, with or without ; modification, are permitted provided that the following conditions are ; met: ; ; 1. Redistributions of source code must retain the above copyright ; notice, this list of conditions and the following disclaimer. ; ; 2. Redistributions in binary form must reproduce the above copyright ; notice, this list of conditions and the following disclaimer in the ; documentation and/or other materials provided with the distribution. ; ; 3. The name of the author may not be used to endorse or promote products ; derived from this software without specific prior written permission. ; ; THIS SOFTWARE IS PROVIDED BY AUTHORS "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 AUTHOR 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. ; ----------------------------------------------- ; blake2s in x86 assembly ; ; size: 509 bytes ; ; global calls use cdecl convention ; ; ----------------------------------------------- bits 32 %ifndef BIN global _b2s_initx global _b2s_updatex global _b2s_finalx %endif struc pushad_t _edi resd 1 _esi resd 1 _ebp resd 1 _esp resd 1 _ebx resd 1 _edx resd 1 _ecx resd 1 _eax resd 1 .size: endstruc struc b2s_ctx state resb 32 buffer resb 64 len resd 2 index resd 1 outlen resd 1 endstruc %define a eax %define b edx %define c esi %define d edi %define x edi %define t0 ebp ; void b2s_g(blake2_blk *blk, uint16_t index, ; uint32_t x0, uint32_t x1) b2s_g: pushad push a xchg ah, al aam 16 movzx ebp, ah movzx c, al pop a aam 16 movzx b, ah movzx a, al lea a, [x+a*4] lea b, [x+b*4] lea c, [x+c*4] lea d, [x+ebp*4] ; load ecx with rotate values ; 16, 12, 8, 7 mov ecx, 07080C10h ; x[a] = PLUS(x[a],x[b]) + x0; mov t0, [esp+_ebx] ; x0 add t0, [b] q_l1: mov bl, 1 q_l2: ; also x[c] = PLUS(x[c],x[d]); add t0, [a] mov [a], t0 ; x[d] = ROTATE(XOR(x[d],x[a]),cl); ; also x[b] = ROTATE(XOR(x[b],x[c]),cl); xor t0, [d] ror t0, cl mov [d], t0 xchg cl, ch xchg c, a xchg d, b inc ebx jpo q_l2 ; x[a] = PLUS(x[a],x[b]) + x1; add t0, [esp+_ecx] ; x1 ; -------------------------------------------- shr ecx, 16 jnz q_l1 popad ret ; void b2s_compress (b2s_ctx *ctx, int last) _b2s_compressx: pushad mov esi, edi mov ebx, esi ; create space for v + m sub esp, 124 push eax ; initialize v with state and chaining variables mov edi, esp ; edi = v mov eax, b2s_iv b2t_l1: ; first is ctx->state push 32 ; move 32 bytes pop ecx ; then b2s_iv rep movsb cmc ; complement xchg esi, eax jc b2t_l1 ; continue if carry ; esi should now be ctx->buffer ; edi will be m ; copy buffer into m mov cl, 64 push edi rep movsb pop edi ; esi now points to ctx->len ; xor v with current length lodsd xor [edi+12*4-64], eax lodsd xor [edi+13*4-64], eax ; if this is last block, invert word 14 ; 1 becomes -1, 0 remains 0 neg edx xor [edi+14*4-64], edx ; do 10 rounds mov cl, 10 b2t_l2: xor esi, esi b2t_l3: cmp esi, 10 je b2t_l2 xor ebp, ebp mov edx, [b2s_sigma64+8*esi+4] mov eax, [b2s_sigma64+8*esi] b2t_l4: pushad aam 16 mov cl, ah movzx eax, al mov ebx, [edi+4*eax] ; m.v32[x0] mov ecx, [edi+4*ecx] ; m.v32[x1] mov eax, dword[ebp*2+b2s_idx16] ; b2s_idx16[j] mov edi, [edi+_esp-96] call b2s_g popad shrd eax, edx, 8 shr edx, 8 inc ebp cmp ebp, 8 jnz b2t_l4 ; check rnds inc esi loop b2t_l3 ; update state with work vector b2t_l5: mov eax, [edi+4*ebp-68] xor eax, [edi+4*ebp+32-68] xor [ebx+4*ebp-4], eax dec ebp jnz b2t_l5 add esp, 124 pop eax popad ret ; void b2s_init (b2s_ctx *ctx, uint32_t outlen, ; void *key, uint32_t keylen, uint32_t rnds) _b2s_initx: pushad mov ebp, esp mov edi, [ebp+32+ 4] ; ctx mov ebx, [ebp+32+ 8] ; outlen mov edx, [ebp+32+16] ; keylen ; initialize state mov esi, b2s_iv lodsd ; eax ^= outlen xor eax, ebx ; keylen << 8 shl edx, 8 ; eax ^= keylen xor eax, edx ; eax ^= 0x01010000 xor eax, 001010000h ; ctx->state.v32[0] = eax stosd push 7 pop ecx rep movsd ; edi now points to ctx->buffer ; zero initialize ; also ctx->len.v64 = 0 xor eax, eax mov cl, 19 push edi rep stosd ; edi now points to index mov ecx, [ebp+32+16] ; keylen jecxz b2_kl mov byte [edi-4], 64 b2_kl: ; ctx->outlen = outlen xchg eax, ebx stosd mov esi, [ebp+32+12] ; key pop edi rep movsb popad ret ; void b2s_update (b2s_ctx *ctx, ; void *input, uint32_t len) _b2s_updatex: pushad lea esi, [esp+32+4] lodsd xchg edi, eax ; ctx lodsd xchg ecx, eax lodsd xchg ecx, eax ; len jecxz ex_upd xchg esi, eax ; input mov edx, [edi+index] ; index b2_upd: cmp edx, 64 jnz b2_ab ; ctx->len.v64 += index add dword[edi+len+0], edx mov dl, 0 ; last=0 adc dword[edi+len+4], edx call _b2s_compressx b2_ab: lodsb mov [edi+edx+buffer], al inc edx loop b2_upd mov [edi+index], edx ex_upd: popad ret ; void b2s_final (void* out, b2s_ctx *ctx) _b2s_finalx: pushad mov esi, [esp+32+4] ; out mov edx, [esp+32+8] ; ctx mov ecx, [edx+index] ; index xor eax, eax add dword[edx+len+0], ecx adc dword[edx+len+4], eax lea edi, [edx+ecx+buffer] neg ecx add ecx, 64 rep stosb xchg edx, eax xchg edi, eax inc edx ; last=1 call _b2s_compressx mov ecx, [edi+outlen] ; outlen xchg esi, edi rep movsb popad ret b2s_iv: dd 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A dd 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 b2s_idx16: dw 0xC840, 0xD951, 0xEA62, 0xFB73 dw 0xFA50, 0xCB61, 0xD872, 0xE943 b2s_sigma64: dq 0xfedcba9876543210, 0x357b20c16df984ae dq 0x491763eadf250c8b, 0x8f04a562ebcd1397 dq 0xd386cb1efa427509, 0x91ef57d438b0a6c2 dq 0xb8293670a4def15c, 0xa2684f05931ce7bd dq 0x5a417d2c803b9ef6, 0x0dc3e9bf5167482a
0x0000 (0x000000) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0001 (0x000002) 0x291E- f:00024 d: 286 | OR[286] = A 0x0002 (0x000004) 0x1010- f:00010 d: 16 | A = 16 (0x0010) 0x0003 (0x000006) 0x291F- f:00024 d: 287 | OR[287] = A 0x0004 (0x000008) 0x1008- f:00010 d: 8 | A = 8 (0x0008) 0x0005 (0x00000A) 0x2B1A- f:00025 d: 282 | OR[282] = A + OR[282] 0x0006 (0x00000C) 0x2119- f:00020 d: 281 | A = OR[281] 0x0007 (0x00000E) 0x1408- f:00012 d: 8 | A = A + 8 (0x0008) 0x0008 (0x000010) 0x2921- f:00024 d: 289 | OR[289] = A 0x0009 (0x000012) 0x2102- f:00020 d: 258 | A = OR[258] 0x000A (0x000014) 0x141C- f:00012 d: 28 | A = A + 28 (0x001C) 0x000B (0x000016) 0x2923- f:00024 d: 291 | OR[291] = A 0x000C (0x000018) 0x211F- f:00020 d: 287 | A = OR[287] 0x000D (0x00001A) 0x845F- f:00102 d: 95 | P = P + 95 (0x006C), A = 0 0x000E (0x00001C) 0x211F- f:00020 d: 287 | A = OR[287] 0x000F (0x00001E) 0x1604- f:00013 d: 4 | A = A - 4 (0x0004) 0x0010 (0x000020) 0x291F- f:00024 d: 287 | OR[287] = A 0x0011 (0x000022) 0x5800- f:00054 d: 0 | B = A 0x0012 (0x000024) 0x2119- f:00020 d: 281 | A = OR[281] 0x0013 (0x000026) 0x2913- f:00024 d: 275 | OR[275] = A 0x0014 (0x000028) 0x74E1- f:00072 d: 225 | R = P + 225 (0x00F5) 0x0015 (0x00002A) 0x2120- f:00020 d: 288 | A = OR[288] 0x0016 (0x00002C) 0x2922- f:00024 d: 290 | OR[290] = A 0x0017 (0x00002E) 0x0804- f:00004 d: 4 | A = A > 4 (0x0004) 0x0018 (0x000030) 0x1A00-0x0FF0 f:00015 d: 0 | A = A & 4080 (0x0FF0) 0x001A (0x000034) 0x291D- f:00024 d: 285 | OR[285] = A 0x001B (0x000036) 0x74DA- f:00072 d: 218 | R = P + 218 (0x00F5) 0x001C (0x000038) 0x2122- f:00020 d: 290 | A = OR[290] 0x001D (0x00003A) 0x0A08- f:00005 d: 8 | A = A < 8 (0x0008) 0x001E (0x00003C) 0x2922- f:00024 d: 290 | OR[290] = A 0x001F (0x00003E) 0x2120- f:00020 d: 288 | A = OR[288] 0x0020 (0x000040) 0x0808- f:00004 d: 8 | A = A > 8 (0x0008) 0x0021 (0x000042) 0x12FF- f:00011 d: 255 | A = A & 255 (0x00FF) 0x0022 (0x000044) 0x2920- f:00024 d: 288 | OR[288] = A 0x0023 (0x000046) 0x2120- f:00020 d: 288 | A = OR[288] 0x0024 (0x000048) 0x2522- f:00022 d: 290 | A = A + OR[290] 0x0025 (0x00004A) 0x2920- f:00024 d: 288 | OR[288] = A 0x0026 (0x00004C) 0x2120- f:00020 d: 288 | A = OR[288] 0x0027 (0x00004E) 0x8602- f:00103 d: 2 | P = P + 2 (0x0029), A # 0 0x0028 (0x000050) 0x7012- f:00070 d: 18 | P = P + 18 (0x003A) 0x0029 (0x000052) 0x2120- f:00020 d: 288 | A = OR[288] 0x002A (0x000054) 0x1E00-0xFFFF f:00017 d: 0 | A = A - 65535 (0xFFFF) 0x002C (0x000058) 0x8602- f:00103 d: 2 | P = P + 2 (0x002E), A # 0 0x002D (0x00005A) 0x700D- f:00070 d: 13 | P = P + 13 (0x003A) 0x002E (0x00005C) 0x1800-0x2020 f:00014 d: 0 | A = 8224 (0x2020) 0x0030 (0x000060) 0x2720- f:00023 d: 288 | A = A - OR[288] 0x0031 (0x000062) 0x2920- f:00024 d: 288 | OR[288] = A 0x0032 (0x000064) 0x1203- f:00011 d: 3 | A = A & 3 (0x0003) 0x0033 (0x000066) 0x5800- f:00054 d: 0 | B = A 0x0034 (0x000068) 0x2120- f:00020 d: 288 | A = OR[288] 0x0035 (0x00006A) 0x0802- f:00004 d: 2 | A = A > 2 (0x0002) 0x0036 (0x00006C) 0x2920- f:00024 d: 288 | OR[288] = A 0x0037 (0x00006E) 0x211D- f:00020 d: 285 | A = OR[285] 0x0038 (0x000070) 0x4800- f:00044 d: 0 | A = A > B 0x0039 (0x000072) 0x291D- f:00024 d: 285 | OR[285] = A 0x003A (0x000074) 0x211D- f:00020 d: 285 | A = OR[285] 0x003B (0x000076) 0x3921- f:00034 d: 289 | (OR[289]) = A 0x003C (0x000078) 0x2121- f:00020 d: 289 | A = OR[289] 0x003D (0x00007A) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001) 0x003E (0x00007C) 0x2908- f:00024 d: 264 | OR[264] = A 0x003F (0x00007E) 0x2120- f:00020 d: 288 | A = OR[288] 0x0040 (0x000080) 0x3908- f:00034 d: 264 | (OR[264]) = A 0x0041 (0x000082) 0x211A- f:00020 d: 282 | A = OR[282] 0x0042 (0x000084) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001) 0x0043 (0x000086) 0x2908- f:00024 d: 264 | OR[264] = A 0x0044 (0x000088) 0x3108- f:00030 d: 264 | A = (OR[264]) 0x0045 (0x00008A) 0x2914- f:00024 d: 276 | OR[276] = A 0x0046 (0x00008C) 0x2114- f:00020 d: 276 | A = OR[276] 0x0047 (0x00008E) 0x2720- f:00023 d: 288 | A = A - OR[288] 0x0048 (0x000090) 0x2913- f:00024 d: 275 | OR[275] = A 0x0049 (0x000092) 0x8204- f:00101 d: 4 | P = P + 4 (0x004D), C = 1 0x004A (0x000094) 0x2120- f:00020 d: 288 | A = OR[288] 0x004B (0x000096) 0x2714- f:00023 d: 276 | A = A - OR[276] 0x004C (0x000098) 0x2913- f:00024 d: 275 | OR[275] = A 0x004D (0x00009A) 0x2113- f:00020 d: 275 | A = OR[275] 0x004E (0x00009C) 0x8602- f:00103 d: 2 | P = P + 2 (0x0050), A # 0 0x004F (0x00009E) 0x7009- f:00070 d: 9 | P = P + 9 (0x0058) 0x0050 (0x0000A0) 0x2113- f:00020 d: 275 | A = OR[275] 0x0051 (0x0000A2) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001) 0x0052 (0x0000A4) 0x8003- f:00100 d: 3 | P = P + 3 (0x0055), C = 0 0x0053 (0x0000A6) 0x8402- f:00102 d: 2 | P = P + 2 (0x0055), A = 0 0x0054 (0x0000A8) 0x7002- f:00070 d: 2 | P = P + 2 (0x0056) 0x0055 (0x0000AA) 0x7003- f:00070 d: 3 | P = P + 3 (0x0058) 0x0056 (0x0000AC) 0x1001- f:00010 d: 1 | A = 1 (0x0001) 0x0057 (0x0000AE) 0x291E- f:00024 d: 286 | OR[286] = A 0x0058 (0x0000B0) 0x211F- f:00020 d: 287 | A = OR[287] 0x0059 (0x0000B2) 0x5800- f:00054 d: 0 | B = A 0x005A (0x0000B4) 0x211C- f:00020 d: 284 | A = OR[284] 0x005B (0x0000B6) 0x2913- f:00024 d: 275 | OR[275] = A 0x005C (0x0000B8) 0x7499- f:00072 d: 153 | R = P + 153 (0x00F5) 0x005D (0x0000BA) 0x2120- f:00020 d: 288 | A = OR[288] 0x005E (0x0000BC) 0x3923- f:00034 d: 291 | (OR[291]) = A 0x005F (0x0000BE) 0x7496- f:00072 d: 150 | R = P + 150 (0x00F5) 0x0060 (0x0000C0) 0x2123- f:00020 d: 291 | A = OR[291] 0x0061 (0x0000C2) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001) 0x0062 (0x0000C4) 0x2908- f:00024 d: 264 | OR[264] = A 0x0063 (0x0000C6) 0x2120- f:00020 d: 288 | A = OR[288] 0x0064 (0x0000C8) 0x3908- f:00034 d: 264 | (OR[264]) = A 0x0065 (0x0000CA) 0x1002- f:00010 d: 2 | A = 2 (0x0002) 0x0066 (0x0000CC) 0x2B23- f:00025 d: 291 | OR[291] = A + OR[291] 0x0067 (0x0000CE) 0x1002- f:00010 d: 2 | A = 2 (0x0002) 0x0068 (0x0000D0) 0x2B21- f:00025 d: 289 | OR[289] = A + OR[289] 0x0069 (0x0000D2) 0x1002- f:00010 d: 2 | A = 2 (0x0002) 0x006A (0x0000D4) 0x2B1A- f:00025 d: 282 | OR[282] = A + OR[282] 0x006B (0x0000D6) 0x725F- f:00071 d: 95 | P = P - 95 (0x000C) 0x006C (0x0000D8) 0x2119- f:00020 d: 281 | A = OR[281] 0x006D (0x0000DA) 0x1408- f:00012 d: 8 | A = A + 8 (0x0008) 0x006E (0x0000DC) 0x290D- f:00024 d: 269 | OR[269] = A 0x006F (0x0000DE) 0x2102- f:00020 d: 258 | A = OR[258] 0x0070 (0x0000E0) 0x140C- f:00012 d: 12 | A = A + 12 (0x000C) 0x0071 (0x0000E2) 0x290E- f:00024 d: 270 | OR[270] = A 0x0072 (0x0000E4) 0x1008- f:00010 d: 8 | A = 8 (0x0008) 0x0073 (0x0000E6) 0x290F- f:00024 d: 271 | OR[271] = A 0x0074 (0x0000E8) 0x7006- f:00070 d: 6 | P = P + 6 (0x007A) 0x0075 (0x0000EA) 0x310D- f:00030 d: 269 | A = (OR[269]) 0x0076 (0x0000EC) 0x390E- f:00034 d: 270 | (OR[270]) = A 0x0077 (0x0000EE) 0x2D0D- f:00026 d: 269 | OR[269] = OR[269] + 1 0x0078 (0x0000F0) 0x2D0E- f:00026 d: 270 | OR[270] = OR[270] + 1 0x0079 (0x0000F2) 0x2F0F- f:00027 d: 271 | OR[271] = OR[271] - 1 0x007A (0x0000F4) 0x210F- f:00020 d: 271 | A = OR[271] 0x007B (0x0000F6) 0x8E06- f:00107 d: 6 | P = P - 6 (0x0075), A # 0 0x007C (0x0000F8) 0x211B- f:00020 d: 283 | A = OR[283] 0x007D (0x0000FA) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001) 0x007E (0x0000FC) 0x8474- f:00102 d: 116 | P = P + 116 (0x00F2), A = 0 0x007F (0x0000FE) 0x211E- f:00020 d: 286 | A = OR[286] 0x0080 (0x000100) 0x8667- f:00103 d: 103 | P = P + 103 (0x00E7), A # 0 0x0081 (0x000102) 0x2102- f:00020 d: 258 | A = OR[258] 0x0082 (0x000104) 0x140B- f:00012 d: 11 | A = A + 11 (0x000B) 0x0083 (0x000106) 0x2908- f:00024 d: 264 | OR[264] = A 0x0084 (0x000108) 0x3108- f:00030 d: 264 | A = (OR[264]) 0x0085 (0x00010A) 0x1A00-0xFFFE f:00015 d: 0 | A = A & 65534 (0xFFFE) 0x0087 (0x00010E) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001) 0x0088 (0x000110) 0x3908- f:00034 d: 264 | (OR[264]) = A 0x0089 (0x000112) 0x1010- f:00010 d: 16 | A = 16 (0x0010) 0x008A (0x000114) 0x291F- f:00024 d: 287 | OR[287] = A 0x008B (0x000116) 0x2119- f:00020 d: 281 | A = OR[281] 0x008C (0x000118) 0x1408- f:00012 d: 8 | A = A + 8 (0x0008) 0x008D (0x00011A) 0x2921- f:00024 d: 289 | OR[289] = A 0x008E (0x00011C) 0x211F- f:00020 d: 287 | A = OR[287] 0x008F (0x00011E) 0x8458- f:00102 d: 88 | P = P + 88 (0x00E7), A = 0 0x0090 (0x000120) 0x211F- f:00020 d: 287 | A = OR[287] 0x0091 (0x000122) 0x1604- f:00013 d: 4 | A = A - 4 (0x0004) 0x0092 (0x000124) 0x291F- f:00024 d: 287 | OR[287] = A 0x0093 (0x000126) 0x3121- f:00030 d: 289 | A = (OR[289]) 0x0094 (0x000128) 0x291D- f:00024 d: 285 | OR[285] = A 0x0095 (0x00012A) 0x2121- f:00020 d: 289 | A = OR[289] 0x0096 (0x00012C) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001) 0x0097 (0x00012E) 0x2908- f:00024 d: 264 | OR[264] = A 0x0098 (0x000130) 0x3108- f:00030 d: 264 | A = (OR[264]) 0x0099 (0x000132) 0x2920- f:00024 d: 288 | OR[288] = A 0x009A (0x000134) 0x2120- f:00020 d: 288 | A = OR[288] 0x009B (0x000136) 0x1E00-0xFFFF f:00017 d: 0 | A = A - 65535 (0xFFFF) 0x009D (0x00013A) 0x8455- f:00102 d: 85 | P = P + 85 (0x00F2), A = 0 0x009E (0x00013C) 0x211D- f:00020 d: 285 | A = OR[285] 0x009F (0x00013E) 0x8445- f:00102 d: 69 | P = P + 69 (0x00E4), A = 0 0x00A0 (0x000140) 0x211D- f:00020 d: 285 | A = OR[285] 0x00A1 (0x000142) 0x2913- f:00024 d: 275 | OR[275] = A 0x00A2 (0x000144) 0x2113- f:00020 d: 275 | A = OR[275] 0x00A3 (0x000146) 0x0C01- f:00006 d: 1 | A = A >> 1 (0x0001) 0x00A4 (0x000148) 0x2913- f:00024 d: 275 | OR[275] = A 0x00A5 (0x00014A) 0x8803- f:00104 d: 3 | P = P - 3 (0x00A2), C = 0 0x00A6 (0x00014C) 0x2113- f:00020 d: 275 | A = OR[275] 0x00A7 (0x00014E) 0x1680- f:00013 d: 128 | A = A - 128 (0x0080) 0x00A8 (0x000150) 0x824A- f:00101 d: 74 | P = P + 74 (0x00F2), C = 1 0x00A9 (0x000152) 0x2120- f:00020 d: 288 | A = OR[288] 0x00AA (0x000154) 0x1E00-0x0800 f:00017 d: 0 | A = A - 2048 (0x0800) 0x00AC (0x000158) 0x8002- f:00100 d: 2 | P = P + 2 (0x00AE), C = 0 0x00AD (0x00015A) 0x7031- f:00070 d: 49 | P = P + 49 (0x00DE) 0x00AE (0x00015C) 0x100C- f:00010 d: 12 | A = 12 (0x000C) 0x00AF (0x00015E) 0x2913- f:00024 d: 275 | OR[275] = A 0x00B0 (0x000160) 0x2118- f:00020 d: 280 | A = OR[280] 0x00B1 (0x000162) 0x2520- f:00022 d: 288 | A = A + OR[288] 0x00B2 (0x000164) 0x2914- f:00024 d: 276 | OR[276] = A 0x00B3 (0x000166) 0x2113- f:00020 d: 275 | A = OR[275] 0x00B4 (0x000168) 0x8429- f:00102 d: 41 | P = P + 41 (0x00DD), A = 0 0x00B5 (0x00016A) 0x2113- f:00020 d: 275 | A = OR[275] 0x00B6 (0x00016C) 0x1604- f:00013 d: 4 | A = A - 4 (0x0004) 0x00B7 (0x00016E) 0x2913- f:00024 d: 275 | OR[275] = A 0x00B8 (0x000170) 0x5800- f:00054 d: 0 | B = A 0x00B9 (0x000172) 0x211D- f:00020 d: 285 | A = OR[285] 0x00BA (0x000174) 0x4800- f:00044 d: 0 | A = A > B 0x00BB (0x000176) 0x120F- f:00011 d: 15 | A = A & 15 (0x000F) 0x00BC (0x000178) 0x2915- f:00024 d: 277 | OR[277] = A 0x00BD (0x00017A) 0x211F- f:00020 d: 287 | A = OR[287] 0x00BE (0x00017C) 0x5800- f:00054 d: 0 | B = A 0x00BF (0x00017E) 0x2115- f:00020 d: 277 | A = OR[277] 0x00C0 (0x000180) 0x4A00- f:00045 d: 0 | A = A < B 0x00C1 (0x000182) 0x2915- f:00024 d: 277 | OR[277] = A 0x00C2 (0x000184) 0x3114- f:00030 d: 276 | A = (OR[276]) 0x00C3 (0x000186) 0x2917- f:00024 d: 279 | OR[279] = A 0x00C4 (0x000188) 0x1800-0xFFFF f:00014 d: 0 | A = 65535 (0xFFFF) 0x00C6 (0x00018C) 0x2717- f:00023 d: 279 | A = A - OR[279] 0x00C7 (0x00018E) 0x2315- f:00021 d: 277 | A = A & OR[277] 0x00C8 (0x000190) 0x290D- f:00024 d: 269 | OR[269] = A 0x00C9 (0x000192) 0x1800-0xFFFF f:00014 d: 0 | A = 65535 (0xFFFF) 0x00CB (0x000196) 0x2715- f:00023 d: 277 | A = A - OR[277] 0x00CC (0x000198) 0x2317- f:00021 d: 279 | A = A & OR[279] 0x00CD (0x00019A) 0x250D- f:00022 d: 269 | A = A + OR[269] 0x00CE (0x00019C) 0x2917- f:00024 d: 279 | OR[279] = A 0x00CF (0x00019E) 0x2117- f:00020 d: 279 | A = OR[279] 0x00D0 (0x0001A0) 0x3914- f:00034 d: 276 | (OR[276]) = A 0x00D1 (0x0001A2) 0x2D14- f:00026 d: 276 | OR[276] = OR[276] + 1 0x00D2 (0x0001A4) 0x8412- f:00102 d: 18 | P = P + 18 (0x00E4), A = 0 0x00D3 (0x0001A6) 0x2118- f:00020 d: 280 | A = OR[280] 0x00D4 (0x0001A8) 0x1C00-0x07FF f:00016 d: 0 | A = A + 2047 (0x07FF) 0x00D6 (0x0001AC) 0x2908- f:00024 d: 264 | OR[264] = A 0x00D7 (0x0001AE) 0x2114- f:00020 d: 276 | A = OR[276] 0x00D8 (0x0001B0) 0x2708- f:00023 d: 264 | A = A - OR[264] 0x00D9 (0x0001B2) 0x8003- f:00100 d: 3 | P = P + 3 (0x00DC), C = 0 0x00DA (0x0001B4) 0x8402- f:00102 d: 2 | P = P + 2 (0x00DC), A = 0 0x00DB (0x0001B6) 0x7009- f:00070 d: 9 | P = P + 9 (0x00E4) 0x00DC (0x0001B8) 0x7229- f:00071 d: 41 | P = P - 41 (0x00B3) 0x00DD (0x0001BA) 0x7007- f:00070 d: 7 | P = P + 7 (0x00E4) 0x00DE (0x0001BC) 0x2120- f:00020 d: 288 | A = OR[288] 0x00DF (0x0001BE) 0x1E00-0x0806 f:00017 d: 0 | A = A - 2054 (0x0806) 0x00E1 (0x0001C2) 0x8202- f:00101 d: 2 | P = P + 2 (0x00E3), C = 1 0x00E2 (0x0001C4) 0x7002- f:00070 d: 2 | P = P + 2 (0x00E4) 0x00E3 (0x0001C6) 0x700F- f:00070 d: 15 | P = P + 15 (0x00F2) 0x00E4 (0x0001C8) 0x1002- f:00010 d: 2 | A = 2 (0x0002) 0x00E5 (0x0001CA) 0x2B21- f:00025 d: 289 | OR[289] = A + OR[289] 0x00E6 (0x0001CC) 0x7258- f:00071 d: 88 | P = P - 88 (0x008E) 0x00E7 (0x0001CE) 0x2005- f:00020 d: 5 | A = OR[5] 0x00E8 (0x0001D0) 0x1406- f:00012 d: 6 | A = A + 6 (0x0006) 0x00E9 (0x0001D2) 0x2908- f:00024 d: 264 | OR[264] = A 0x00EA (0x0001D4) 0x211E- f:00020 d: 286 | A = OR[286] 0x00EB (0x0001D6) 0x3908- f:00034 d: 264 | (OR[264]) = A 0x00EC (0x0001D8) 0x102A- f:00010 d: 42 | A = 42 (0x002A) 0x00ED (0x0001DA) 0x2924- f:00024 d: 292 | OR[292] = A 0x00EE (0x0001DC) 0x1124- f:00010 d: 292 | A = 292 (0x0124) 0x00EF (0x0001DE) 0x5800- f:00054 d: 0 | B = A 0x00F0 (0x0001E0) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00F1 (0x0001E2) 0x7C09- f:00076 d: 9 | R = OR[9] 0x00F2 (0x0001E4) 0x1001- f:00010 d: 1 | A = 1 (0x0001) 0x00F3 (0x0001E6) 0x291E- f:00024 d: 286 | OR[286] = A 0x00F4 (0x0001E8) 0x720D- f:00071 d: 13 | P = P - 13 (0x00E7) 0x00F5 (0x0001EA) 0x1004- f:00010 d: 4 | A = 4 (0x0004) 0x00F6 (0x0001EC) 0x2914- f:00024 d: 276 | OR[276] = A 0x00F7 (0x0001EE) 0x2114- f:00020 d: 276 | A = OR[276] 0x00F8 (0x0001F0) 0x840C- f:00102 d: 12 | P = P + 12 (0x0104), A = 0 0x00F9 (0x0001F2) 0x3113- f:00030 d: 275 | A = (OR[275]) 0x00FA (0x0001F4) 0x4800- f:00044 d: 0 | A = A > B 0x00FB (0x0001F6) 0x120F- f:00011 d: 15 | A = A & 15 (0x000F) 0x00FC (0x0001F8) 0x2915- f:00024 d: 277 | OR[277] = A 0x00FD (0x0001FA) 0x2120- f:00020 d: 288 | A = OR[288] 0x00FE (0x0001FC) 0x0A04- f:00005 d: 4 | A = A < 4 (0x0004) 0x00FF (0x0001FE) 0x2515- f:00022 d: 277 | A = A + OR[277] 0x0100 (0x000200) 0x2920- f:00024 d: 288 | OR[288] = A 0x0101 (0x000202) 0x2D13- f:00026 d: 275 | OR[275] = OR[275] + 1 0x0102 (0x000204) 0x2F14- f:00027 d: 276 | OR[276] = OR[276] - 1 0x0103 (0x000206) 0x720C- f:00071 d: 12 | P = P - 12 (0x00F7) 0x0104 (0x000208) 0x0200- f:00001 d: 0 | EXIT 0x0105 (0x00020A) 0x0000- f:00000 d: 0 | PASS 0x0106 (0x00020C) 0x0000- f:00000 d: 0 | PASS 0x0107 (0x00020E) 0x0000- f:00000 d: 0 | PASS
; A024038: a(n) = 4^n - n^2. ; 1,3,12,55,240,999,4060,16335,65472,262063,1048476,4194183,16777072,67108695,268435260,1073741599,4294967040,17179868895,68719476412,274877906583,1099511627376,4398046510663,17592186043932,70368744177135,281474976710080,1125899906841999,4503599627369820,18014398509481255,72057594037927152,288230376151710903,1152921504606846076,4611686018427386943,18446744073709550592,73786976294838205375,295147905179352824700,1180591620717411302199,4722366482869645212400,18889465931478580853415,75557863725914323417692,302231454903657293675023,1208925819614629174704576,4835703278458516698823023,19342813113834066795297052,77371252455336267181193415,309485009821345068724779120,1237940039285380274899122199,4951760157141521099596494780,19807040628566084398385985375,79228162514264337593543948032,316912650057057350374175798943,1267650600228229401496703202876,5070602400912917605986812818903,20282409603651670423947251283312,81129638414606681695789005141255,324518553658426726783156020573340,1298074214633706907132624082301999,5192296858534827628530496329216960,20769187434139310514121985316877135,83076749736557242056487941267518172,332306998946228968225951765070082663 mov $1,4 pow $1,$0 mov $2,$0 mul $2,$0 sub $1,$2 mov $0,$1
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) Berkeley Softworks 1994 -- All Rights Reserved PROJECT: PC GEOS MODULE: Brother NIKE 56-jet print driver FILE: nike56Stream.asm AUTHOR: Dave Durran REVISION HISTORY: Name Date Description ---- ---- ----------- Dave 10/94 Initial revision DESCRIPTION: $Id: nike56Stream.asm,v 1.1 97/04/18 11:55:38 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PrinterBIOSNoDMA %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: call a printer BIOS routine CALLED BY: PRINT ROUTINES PASS: ah - Function number of BIOS routine to execute others - specific to routine RETURN: ax = Printer status flags carry set if error DESTROYED: nothing PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Dave 10/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ PrinterBIOSNoDMA proc near int 17h ;actual printer BIOS call test ax,mask PER_ACK ;see if we were successful in our command clc ;assume OK jnz exit stc exit: ret PrinterBIOSNoDMA endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PrinterBIOS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Call a printer BIOS routine and check trying if DMA is busy CALLED BY: PRINT ROUTINES PASS: ah = Function number of BIOS routine to execute others = specific to routine RETURN: ax = Printer status flags carry set if error DESTROYED: ax SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- Joon 4/28/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DMA_BUSY_FLAG equ 02h PrinterBIOS proc near passedBP local word push bp function local word push ax dmaRetryCount local word .enter mov ss:[dmaRetryCount], 120 ;120 * 1/4 sec = 30 sec callBIOS: push bp mov bp, ss:[passedBP] int 17h ;actual printer BIOS call pop bp test ax,DMA_BUSY_FLAG jz dmaOK ;exit if DMA was not busy dec ss:[dmaRetryCount] stc ;assume not OK jz exit mov ax, 15 call TimerSleep ;wait 1/4 second and try again mov ax, ss:[function] jmp callBIOS dmaOK: test ax,mask PER_ACK ;see if we were successful jnz exit stc ;not OK exit: .leave ret PrinterBIOS endp
;cpuinit.asm ;AMD64 CPU setup ;Bryan E. Topp <betopp@betopp.com> 2021 ;How many CPUs we support %define CPU_MAX 256 ;Where the trampoline for SMP initialization gets copied %define SMP_STUB_ADDR 4096 extern hal_panic section .text bits 32 global cpuinit_entry cpuinit_entry: ;We should be in 32-bit protected mode without paging right now. ;We'll need to turn symbols into physical addresses to use them. ;Define a macro to help with this. %define PHYSADDR(symb) (symb - 0xFFFFFFFFC0000000) ;Make sure our macro lines up with the linker script extern _KSPACE_BASE mov EAX, PHYSADDR(_KSPACE_BASE) cmp EAX, 0 jne cpuinit_fail ;Make sure the kernel as-linked fits in a single identity-mapped page table (2MBytes of space). mov ECX, 4096 * 511 ;We need to save one page at the top of the table for mapping the Local APIC. mov EDX, 4096 * 2 ;We need to save two pages at the bottom for identity-mapping a spot to start-up secondary cores. extern _KERNEL_START ;From linker script mov EAX, PHYSADDR(_KERNEL_START) cmp EAX, ECX jae cpuinit_fail cmp EAX, EDX jb cpuinit_fail extern _KERNEL_END ;From linker script mov EAX, PHYSADDR(_KERNEL_END) cmp EAX, ECX jae cpuinit_fail cmp EAX, EDX jb cpuinit_fail ;Verify that the CPU supports the features that we need for this kernel. ;Todo - do something reasonable if we see the wrong CPU type. For now, just crash. ;Check that we have CPUID support. mov ESP, PHYSADDR(cpuinit_initstack.top) pushfd ;Save EFLAGS pop EAX ;Store EFLAGS in EAX mov EBX, EAX ;Save in EBX for later testing xor EAX, (1<<21) ;Toggle bit 21 push EAX ;Push modified flags to stack popfd ;Save changed flags to EFLAGS pushfd ;Push EFLAGS back onto stack pop EAX ;Get value in EAX cmp EAX, EBX ;See if we were able to successfully change the bit jz cpuinit_fail ;Jumps in failure case ;Use CPUID to check that we have Long Mode support mov EAX, 0x80000001 cpuid and EDX, 1<<29 ;Test Long Mode bit jz cpuinit_fail ;Jumps in failure case ;Use CPUID to check that we have APIC support mov EAX, 0x00000001 cpuid and EDX, 1<<9 ;Test APIC bit jz cpuinit_fail ;Jumps in failure case ;Use CPUID to check that we have RDMSR support mov EAX, 0x00000001 cpuid and EDX, 1<<5 ;Test MSR bit jz cpuinit_fail ;Jumps in failure case ;Use CPUID to check that we have [RD/WR][FS/GS]BASE mov EAX, 0x00000007 mov ECX, 0 cpuid and EBX, 1<<0 ;Test FSGSBASE bit jz cpuinit_fail ;Jumps in failure case ;Use CPUID to check that we support SYSCALL/SYSRET mov EAX, 0x80000001 cpuid and EDX, 1<<11;Test SysCallSysRet bit jz cpuinit_fail ;Jumps in failure case ;Using physical addresses, set up the kernel paging structures. ;Map both identity (as loaded at 1MByte) and virtual spaces (-1GByte+1MByte). ;Point PML4[0] and PML4[511] at PDPT mov EAX, PHYSADDR(cpuinit_pdpt) or EAX, 3 ;Present, writable mov [PHYSADDR(cpuinit_pml4) + (8 * 511)], EAX mov [PHYSADDR(cpuinit_pml4)], EAX ;Point PDPT[0] and PDPT[511] at PD mov EAX, PHYSADDR(cpuinit_pd) or EAX, 3 ;Present, writable mov [PHYSADDR(cpuinit_pdpt) + (8*511)], EAX mov [PHYSADDR(cpuinit_pdpt)], EAX ;Point PD[0] at PT mov EAX, PHYSADDR(cpuinit_pt) or EAX, 3 ;Present, writable mov [PHYSADDR(cpuinit_pd)], EAX ;Fill PT entries to cover kernel mov EAX, PHYSADDR(_KERNEL_START) shr EAX, 12 mov EBX, PHYSADDR(_KERNEL_END) shr EBX, 12 mov EDI, PHYSADDR(cpuinit_pt) .pt_loop: cmp EAX, EBX jae .pt_done mov ECX, EAX shl ECX, 12 ;Turn back into address or ECX, 3 ;Present, writable mov [EDI + (8 * EAX)], ECX inc EAX jmp .pt_loop .pt_done: ;Point the CPU at the PML4 now that it's ready mov EAX, PHYSADDR(cpuinit_pml4) mov CR3, EAX ;Turn on Physical Address Extension and Long Mode Enable to indicate 4-level paging for Long Mode mov EAX, CR4 or EAX, (1<<5) ;PAE mov CR4, EAX mov ECX, 0xC0000080 ;EFER rdmsr or EAX, (1<<8) ;LME wrmsr ;Enable paging, still 32-bit code, identity-mapped space for now. This should activate Long Mode, because LME was set. mov EAX, CR0 or EAX, (1<<31) ;PG mov CR0, EAX ;Now that we're in Long Mode we can jump to 64-bit code. ;Do so, using a temporary global descriptor table + 64-bit code descriptor. ;(We still can't refer to 64-bit addresses yet.) mov EDI, PHYSADDR(.gdtr) lgdt [EDI] jmp 8 : PHYSADDR(.target64) .gdt: dq 0 ;Null db 0, 0, 0, 0, 0, 0b10011000, 0b00100000, 0 ;64-bit r0 code .gdtr: dw 16 ;Two descriptors long dq PHYSADDR(.gdt) .target64: ;Alright, if we get here, we should be executing 64-bit Long Mode code. ;Now we can actually specify addresses using a full 64-bit pointer, and jump up to our virtual space. bits 64 mov RAX, .targetvm jmp RAX .targetvm: ;Ah, finally. Now we're in 64-bit long mode, in virtual space. ;Load the proper global descriptor table lgdt [cpuinit_gdtr] ;Activate the proper data segment descriptors mov AX, (cpuinit_gdt.r0data64 - cpuinit_gdt) mov SS, AX mov DS, AX mov ES, AX mov FS, AX mov GS, AX ;Build the Interrupt Descriptor Table using the interrupt vectors from link-time. mov RSI, cpuinit_isrptrs ;Read location of ISRs mov RDI, cpuinit_idt ;Write to interrupt descriptor table mov ECX, 256 ;Fill all 256 entries .idt_loop: mov RAX, [RSI] ;Load address of function to call mov [RDI + 0], AX ;Target offset 15..0 shr RAX, 16 mov [RDI + 6], AX ;Target offset 31..16 shr RAX, 16 mov [RDI + 8], EAX ;Target offset 64..32 mov AX, cpuinit_gdt.r0code64 - cpuinit_gdt mov [RDI + 2], AX ;Target selector (always kernel code segment) mov AL, 0 mov [RDI + 4], AL ;Interrupt Stack Table entry to use (don't) mov AL, 0b10001110 ;Present (1), DPL=0 (00), always 0, type = interrupt gate (1110) mov [RDI + 5], AL add RSI, 8 ;Advance to next 64-bit function pointer add RDI, 16 ;Advance to next 16-byte descriptor loop .idt_loop ;Counts down ECX .idt_done: ;Activate the interrupt descriptor table lidt [cpuinit_idtr] ;Use early-stack while setting up mov RSP, cpuinit_initstack.top ;Turn on WRGSBASE and friends mov RAX, CR4 or RAX, (1<<16) ;set FSGSBASE bit mov CR4, RAX ;Set up our frame allocator using the memory map information from multiboot extern frame_free_multiboot call frame_free_multiboot ;Set up keyboard support (todo - need a real driver model at some point) extern pic8259_init call pic8259_init extern ps2kbd_init call ps2kbd_init ;Initialize kernel while single-threaded extern kentry_boot call kentry_boot ;Now we need to release the other CPU cores. ;Turn on the APIC Enable flag in the APIC Base Address Register MSR mov ECX, 0x0000001B ;APIC Base Address Register MSR rdmsr or EAX, 1 << 11 ;Set AE (APIC Enable) bit wrmsr ;Read the base address returned from the MSR and EAX, 0xFFFFF000 and EDX, 0x000FFFFF shl RDX, 32 or RAX, RDX ;Map a page at the top of kernel space as-linked to access the LAPIC or RAX, 3 ;Present, writable mov [cpuinit_pt + (8*511)], RAX mov RAX, _KSPACE_BASE + (4096*511) mov [cpuinit_lapicaddr], RAX ;Identity-map the 2nd page of memory (0x1000-0x1FFF) for non-bootstrap cores to land in mov RAX, SMP_STUB_ADDR or RAX, 3 mov [cpuinit_pt + ((SMP_STUB_ADDR / 4096) * 8)], RAX ;Copy our trampoline into low memory for the secondary cores mov RCX, cpuinit_smpstub.end - cpuinit_smpstub mov RSI, cpuinit_smpstub mov RDI, SMP_STUB_ADDR rep movsb ;Get our LAPIC address, as mapped virtually earlier mov RBX, [cpuinit_lapicaddr] ;Clear APIC errors mov EAX, 0 mov [RBX + 0x280], EAX ;Send an INIT IPI to all remote cores mov EAX, 0xC4500 ;Init IPI, positive edge-trigger, to all-except-self mov [RBX + 0x300], EAX ;Wait for delivery .init_wait: pause mov EAX, [RBX + 0x300] and EAX, 1<<12 jnz .init_wait ;Send a STARTUP IPI to all remote cores. mov EAX, 0xC4600 ;Startup IPI, positive edge-trigger, to all-except-self or EAX, SMP_STUB_ADDR / 4096 ;Page number to start executing mov [RBX + 0x300], EAX ;Wait for delivery .sipi_wait: pause mov EAX, [RBX + 0x300] and EAX, 1<<12 jnz .sipi_wait ;Wait a moment before sending a second STARTUP IPI mov CX, 65535 .second_sipi_delay: loop .second_sipi_delay mov [RBX + 0x300], EAX ;Join the other cores in the common code path jmp cpuinit_all cpuinit_fail: .spin: jmp .spin ;Stub copied to low memory to set up non-bootstrap cores cpuinit_smpstub: ;This code gets copied to an arbitrary low address in conventional memory. ;Non-bootstrap cores will enter this code in Real Mode. ;The kernel pagetables are already set up and this region is identity-mapped. ;So we just need to kick the processor up into 64-bit mode. bits 16 cli ;Load a temporary GDT and enter protected mode lgdt [.tempgdtr32 + SMP_STUB_ADDR - cpuinit_smpstub] mov EAX, CR0 or EAX, 1 ;Set PE mov CR0, EAX ;Longjump to activate 32-bit code, using descriptors in the temporary GDT jmp (8) : (.target32 + SMP_STUB_ADDR - cpuinit_smpstub) .tempgdt32: dq 0 ;Null descriptor db 0xFF, 0xFF, 0x00, 0x00, 0x00, 0b10011010, 0b11001111, 0x00 ;Ring-0 32-bit code db 0xFF, 0xFF, 0x00, 0x00, 0x00, 0b10010010, 0b11001111, 0x00 ;Ring-0 32-bit data .tempgdtr32: dw 23 ;Limit dd .tempgdt32 + SMP_STUB_ADDR - cpuinit_smpstub ;Base .target32: bits 32 ;So now we're in 32-bit protected mode. ;Setup now looks similar to the bootstrap core, once it's come from Multiboot and set up the pagetables. ;Enable Physical Address Extension in CR4, required for long-mode mov EAX, CR4 or EAX, (1<<5) ;PAE mov CR4, EAX ;Load Page Directory Base Register with physical address of top-level paging structure (PML4) including identity-mapping mov EAX, PHYSADDR(cpuinit_pml4) mov CR3, EAX ;Set Long Mode Enabled in the Extended Feature Enable Register, so we get into Long Mode when activating paging mov ECX, 0xC0000080 ;EFER rdmsr or EAX, (1<<8) ;LME wrmsr ;Enable paging; Long Mode is activated in doing so because LME was set. mov EAX, CR0 or EAX, (1<<31) ;PG mov CR0, EAX ;We're down in conventional memory, still, in an identity-mapped page. ;Now we just need to jump up into the kernel's virtual space. ;Same problem as on the bootstrap core, though - we can't get there unless we're already in 64-bit mode. ;Set up another temporary GDT and use it to get into 64-bit code. lgdt [.tempgdtr64 + SMP_STUB_ADDR - cpuinit_smpstub] jmp (8) : .target64 + SMP_STUB_ADDR - cpuinit_smpstub .tempgdt64: dq 0 ;Null db 0, 0, 0, 0, 0, 0b10011000, 0b00100000, 0 ;64-bit code .tempgdtr64: dw 15 ;Limit dd .tempgdt64 + SMP_STUB_ADDR - cpuinit_smpstub ;Base .target64: bits 64 ;And now that we're in 64-bit mode, we can see the whole address space, and proceed into the kernel. mov RAX, cpuinit_all jmp RAX .end: bits 64 ;Entry code run on all cores align 16 cpuinit_all: ;Load the proper descriptor tables lgdt [cpuinit_gdtr] lidt [cpuinit_idtr] ;Activate the proper data segment descriptors mov AX, (cpuinit_gdt.r0data64 - cpuinit_gdt) mov SS, AX mov DS, AX mov ES, AX mov FS, AX mov GS, AX ;Turn on WRGSBASE and friends mov RAX, CR4 or RAX, (1<<16) ;set FSGSBASE bit mov CR4, RAX ;Find a core number for ourselves. mov RAX, 0 ;ID to try taking, if it's the next-ID mov RCX, 1 ;Next-ID then stored if we are successful .id_loop: lock cmpxchg qword [cpuinit_nextid], RCX jz .id_done mov RAX, RCX inc RCX jmp .id_loop .id_done: ;Got our unique ID in RAX. Set aside in RBX as well. mov RBX, RAX ;Wait for any processors ahead of us to finish init. .wait_loop: mov RCX, [cpuinit_coresdone] cmp RCX, RAX je .wait_done pause jmp .wait_loop .wait_done: ;Use the init-stack while initializing (one at a time!) mov RSP, cpuinit_initstack.top ;Allocate a page for our task state segment call cpuinit_bump_alloc mov RSI, RAX ;Set aside a pointer to it, for easier access later mov [cpuinit_tssptrs + (8 * RBX)], RAX ;Compute where we'll store our Task State Segment Descriptor mov RDI, cpuinit_gdt.ktss_array ;Start of per-CPU TSS descriptors mov ECX, EBX ;Index of our CPU shl ECX, 4 ;16 bytes per TSS descriptor add RDI, RCX ;Advance to position in TSS descriptor array ;Build the TSS descriptor mov AX, 0xFFF mov [RDI + 0], AX ;Segment limit 15..0 mov RAX, RSI mov [RDI + 2], AX ;Segment base 15..0 shr RAX, 16 mov [RDI + 4], AL ;Segment base 23..16 mov [RDI + 7], AH ;Segment base 31..24 shr RAX, 16 mov [RDI + 8], EAX ;Segment base 63..32 mov EAX, 0 mov [RDI + 12], EAX ;High dword all 0 mov AL, 0b10001001 ;Present (1), DPL=0 (00), always 0, available 64-bit TSS (1001) mov [RDI + 5], AL mov AL, 0b00000000 ;Granularity = x1B (0), unused (00), available for OS (0), segment limit 19..16 (0000) mov [RDI + 6], AL ;Activate it mov RAX, RDI sub RAX, cpuinit_gdt ltr AX ;Turn on SYSCALL/SYSRET mov ECX, 0xC0000080 ;EFER rdmsr or EAX, (1<<0) ;set SCE bit wrmsr ;Set up usage of SYSCALL/SYSRET mov ECX, 0xC0000081 ;STAR register mov EDX, (cpuinit_gdt.r3dummy - cpuinit_gdt) ;SYSRET CS and SS (+16 and +8 from this) shl EDX, 16 mov DX, (cpuinit_gdt.r0code64 - cpuinit_gdt) ;SYSCALL CS and SS (+0 and +8 from this) mov EAX, 0 ;32-bit SYSCALL target EIP wrmsr mov ECX, 0xC0000082 ;LSTAR register mov RAX, cpuinit_syscall mov RDX, RAX ;Need to put 64-bit address in EDX:EAX rather than RAX. shr RDX, 32 wrmsr mov ECX, 0xC0000083 ;CSTAR register mov RAX, 0 ;Don't support compatibility-mode. mov RDX, 0 wrmsr mov ECX, 0xC0000084 ;SFMASK mov EAX, 0xFFFFFFFF ;Mask all flags. mov EDX, 0 ;Reserved, RAZ wrmsr ;Allocate space for our rescheduling stack and use that, instead of the shared initial stack call cpuinit_bump_alloc mov RSP, RAX add RSP, 4096 ;Now we're done with shared init resources - allow other cores to go inc qword [cpuinit_coresdone] ;Enter the kernel extern kentry_sched call kentry_sched ;Kernel shouldn't return lidt [0] int 0 jmp 0 ;Simple bump-allocator, which allocates single pages of kernel space after the kernel as-linked. ;Used to allocate per-CPU stacks and task-state segments. cpuinit_bump_alloc: ;Get a frame from the frame allocator extern hal_frame_alloc call hal_frame_alloc ;Stick it after other allocations extern pt_set ;pt_set(uint64_t pml4, uint64_t addr, uint64_t frame, uint64_t flags) mov RDI, PHYSADDR(cpuinit_pml4) mov RSI, [cpuinit_bump_next] mov RDX, RAX mov RCX, 3 call pt_set ;Advance by two frames to leave a guard page before following allocations mov RAX, [cpuinit_bump_next] push RAX add RAX, 8192 mov [cpuinit_bump_next], RAX pop RAX ret ;Returns the location of the calling CPU's task-state segment in RAX. Only alters RAX. align 16 global cpuinit_gettss cpuinit_gettss: ;Find our CPU index based on our task register mov RAX, 0 str AX ;Find our current task-state selector sub AX, (cpuinit_gdt.ktss_array - cpuinit_gdt) ;Make relative to the first task-state selector shr AX, 4 ;Divide by 16 to find out which, in the array, it selects. That's our CPU number. ;Get our task-state segment location from the array of TSS pointers we set aside mov RAX, [cpuinit_tssptrs + (8 * RAX)] ret ;Called to exit the kernel initially to a nearly-undefined user state align 16 global hal_exit_fresh ;void hal_exit_fresh(uintptr_t u_pc, void *k_sp); hal_exit_fresh: ;Save k_sp parameter as RSP0 entry in task-state segment call cpuinit_gettss mov [RAX + 0x4], RSI ;Set up for dropping to usermode with a sysret mov RCX, RDI ;Will be RIP - user entry point mov R11, 0x202 ;Will be RFLAGS - initialize to just interrupts (and always-1 flag) enabled ;Zero all other registers mov RAX, 0 mov RDX, RAX mov RBX, RAX mov RBP, RAX mov RSI, RAX mov RDI, RAX mov R8, RAX mov R9, RAX mov R10, RAX mov R12, RAX mov R13, RAX mov R14, RAX mov R15, RAX ;Drop to user-mode cli ;Disable interrupts so we don't get caught with wrong GS-base swapgs ;Preserve kernel GS-base o64 a64 sysret ;Drop to usermode align 16 global hal_intr_wake ;void hal_intr_wake(void); hal_intr_wake: ;Send a broadcast IPI on our "wakeup" interrupt vector (255) mov RCX, [cpuinit_lapicaddr] mov EAX, 0xC45FF ;Fixed interrupt, positive edge-trigger, to all-except-self, vector 0xFF mov [RCX + 0x300], EAX ret ;Entry point for system calls bits 64 align 16 cpuinit_syscall: ;Interrupts should be disabled at this point - we clear all flags on syscall. ;Swap to kernel-mode GS. swapgs ;Load the RSP0 (kernel stack pointer) from the task state segment for this CPU. ;We can clobber RAX to do this, because it's neither saved nor involved in passing parameters. call cpuinit_gettss mov RAX, [RAX + 0x4] xchg RAX, RSP ;Set user's RSP aside in RAX and place kernel stack pointer in RSP. ;Build a system-call exit buffer on the stack. ;The kernel expects the first 4 entries to always be size, return address, return stack, return value. sub RSP, (8*11) mov qword [RSP + (8*0)], 8*11 ;Total size of the buffer mov [RSP + (8*1)], RCX ;User return address mov [RSP + (8*2)], RAX ;User stack pointer mov qword [RSP + (8*3)], -38 ;User return value (-ENOSYS) mov [RSP + (8*4)], RBP mov [RSP + (8*5)], RBX mov [RSP + (8*6)], R12 mov [RSP + (8*7)], R13 mov [RSP + (8*8)], R14 mov [RSP + (8*9)], R15 swapgs rdgsbase RAX swapgs mov [RSP + (8*10)], RAX ;User GS-base ;Pull RCX/4th parameter out of R10, where it was stashed before the SYSCALL instruction mov RCX, R10 ;Pass the exit buffer's location on the stack as the 7th parameter. push RSP ;Other parameters are already in registers. Handle the system call. ;Note that we just trash the saved flags (R11) as flags aren't preserved across calls in SysVABI. extern kentry_syscall call kentry_syscall ;The kernel should call a function to exit, rather than returning. .spin: mov RDI, .panicstr call hal_panic jmp .spin .panicstr: db "syscall botched exit\0" ;Called to exit the kernel from a system call or exception align 16 global hal_exit_resume ;void hal_exit_resume(hal_exit_t *e, void *k_sp); hal_exit_resume: ;Disable interrupts so we don't get caught with the wrong GS-base cli ;Swap to user GS swapgs ;Set aside desired kernel stack pointer in RSP0 field of TSS. call cpuinit_gettss mov [RAX + 0x4], RSI ;Check how long the exit-buffer is. ;Resume based on it. cmp qword [RDI], 8*20 je .from_exception cmp qword [RDI], 8*11 je .from_syscall ;Bad size in exit buffer mov RDX, RDI mov RDI, .badstr jmp hal_panic .badstr: db "bad exit-buffer size\0" ;Restoring an exit-buffer that was made on a system-call .from_syscall: ;Restore saved registers mov RCX, [RDI + (8*1)] ;User return address (restored to RIP by sysret) mov RSP, [RDI + (8*2)] ;User stack pointer mov RAX, [RDI + (8*3)] ;User return value mov RBP, [RDI + (8*4)] mov RBX, [RDI + (8*5)] mov R12, [RDI + (8*6)] mov R13, [RDI + (8*7)] mov R14, [RDI + (8*8)] mov R15, [RDI + (8*9)] mov R11, [RDI + (8*10)] ;User GS-base wrgsbase R11 ;Clobber flags because those don't get preserved mov R11, 0x202 ;User flags (restored to RFLAGS by sysret) o64 a64 sysret ;Restoring an exit-buffer that was made on an exception .from_exception: ;Restore GS-base mov R11, [RDI + (8* 4)] ;User GS-base wrgsbase R11 ;Restore general purpose registers, except RDI, which contains our exit-buffer location mov RCX, [RDI + (8* 6)] mov RDX, [RDI + (8* 7)] mov RBX, [RDI + (8* 8)] mov RBP, [RDI + (8* 9)] mov RSI, [RDI + (8*10)] mov R8 , [RDI + (8*12)] mov R9 , [RDI + (8*13)] mov R10, [RDI + (8*14)] mov R11, [RDI + (8*15)] mov R12, [RDI + (8*16)] mov R13, [RDI + (8*17)] mov R14, [RDI + (8*18)] mov R15, [RDI + (8*19)] ;Note that we're still on the old kernel-stack here, because we didn't restore RSP. ;Put RIP, CS, RFLAGS, RSP, SS on the kernel stack for later IRETQ push qword (cpuinit_gdt.r3data64 - cpuinit_gdt) | 3 ;SS push qword [RDI + (8* 2)] ;RSP push qword [RDI + (8* 5)] ;RFLAGS push qword (cpuinit_gdt.r3code64 - cpuinit_gdt) | 3 ;CS push qword [RDI + (8* 1)] ;RIP ;We've read everything but RDI out of the exit-buffer now. ;Clobber RDI, the location of the buffer, in restoring it mov RDI, [RDI + (8*11)] ;Restore the last few registers with an IRETQ from the kernel stack iretq ;Pops RIP, CS, RFLAGS, RSP, SS ;Exception handlers bits 64 ;Divide-by-zero exception (vector 0) cpuinit_isr_de: push qword 0 ;phony error-code push qword 0 ;vector jmp cpuinit_exception ;Debug exception (vector 1) cpuinit_isr_db: push qword 0 ;phony error-code push qword 1 ;vector jmp cpuinit_exception ;Nonmaskable interrupt (vector 2) cpuinit_isr_nmi: push qword 0 ;phony error-code push qword 2 ;vector jmp cpuinit_exception ;Breakpoint exception (vector 3) cpuinit_isr_bp: push qword 0 ;phony error-code push qword 3 ;vector jmp cpuinit_exception ;Overflow exception (vector 4) cpuinit_isr_of: push qword 0 ;phony error-code push qword 4 ;vector jmp cpuinit_exception ;Bound range exception (vector 5) cpuinit_isr_br: push qword 0 ;phony error-code push qword 5 ;vector jmp cpuinit_exception ;Invalid opcode exception (vector 6) cpuinit_isr_ud: push qword 0 ;phony error-code push qword 6 ;vector jmp cpuinit_exception ;Device not available exception (vector 7) cpuinit_isr_nm: push qword 0 ;phony error-code push qword 7 ;vector jmp cpuinit_exception ;Double fault (vector 8) cpuinit_isr_df: mov RDI, .str jmp hal_panic .str: db "cpuinit_isr_df", 0 ;Coprocessor segment overrun (vector 9) cpuinit_isr_cop: mov RDI, .str jmp hal_panic .str: db "cpuinit_isr_cop", 0 ;Invalid TSS (vector 10) cpuinit_isr_ts: ;CPU pushes error-code push qword 10 ;vector jmp cpuinit_exception ;Segment not present (vector 11) cpuinit_isr_np: ;CPU pushes error-code push qword 11 ;vector jmp cpuinit_exception ;Stack exception (vector 12) cpuinit_isr_ss: ;CPU pushes error-code push qword 12 ;vector jmp cpuinit_exception ;General protection exception (vector 13) cpuinit_isr_gp: ;CPU pushes error-code push qword 13 ;vector jmp cpuinit_exception ;Page fault exception (vector 14) cpuinit_isr_pf: ;CPU pushes error-code push qword 14 ;vector jmp cpuinit_exception ;x87 floating-point exception (vector 16) cpuinit_isr_mf: push qword 0 ;phony error-code push qword 16 ;vector jmp cpuinit_exception ;Alignment check exception (vector 17) cpuinit_isr_ac: ;CPU pushes error-code push qword 17 ;vector jmp cpuinit_exception ;Machine-check exception (vector 18) cpuinit_isr_mc: mov RDI, .str jmp hal_panic .str: db "cpuinit_isr_mc", 0 ;SIMD floating-point exception (vector 19) cpuinit_isr_xf: push qword 0 ;phony error-code push qword 19 ;vector jmp cpuinit_exception ;Hypervisor injection exception (vector 28) cpuinit_isr_hv: mov RDI, .str jmp hal_panic .str: db "cpuinit_isr_hv", 0 ;VMM communication exception (vector 29) cpuinit_isr_vc: mov RDI, .str jmp hal_panic .str: db "cpuinit_isr_vc", 0 ;Security exception (vector 30) cpuinit_isr_sx: mov RDI, .str jmp hal_panic .str: db "cpuinit_isr_sx", 0 ;Entry point for unused interrupt vectors cpuinit_isr_bad: mov RDI, .str jmp hal_panic .str: db "cpuinit_isr_bad", 0 ;Common handling for exceptions cpuinit_exception: ;CPU should have already switched us to the kernel stack, as we store it in the TSS when dropping to user-mode. ;Interrupts will already be disabled. ;The stack contains already: Vector number, error-code, RIP, CS, RFLAGS, RSP, SS ;Push the rest of the registers on the stack. push R15 push R14 push R13 push R12 push R11 push R10 push R9 push R8 push RDI push RSI push RBP push RBX push RDX push RCX mov R11, [RSP + (8*18)] ;Get RFLAGS that the CPU pushed push R11 rdgsbase R11 push R11 swapgs ;For now just assume that we were in usermode, and flip to the kernel GS-base ;Kernel expects the first 4 entries of the exit buffer to be size, RIP, RSP, RAX push RAX mov R11, [RSP + (8*22)] ;Get RSP that the CPU pushed push R11 mov R11, [RSP + (8*20)] ;Get RIP that the CPU pushed push R11 push qword 20*8 ;Size of exit buffer including this qword ;Alright, exit buffer is built on the stack. ;Figure out what signal number to tell the kernel. mov RDI, [RSP+(8*20)] ;Get vector number that we pushed before jumping to cpuinit_exception extern excsig call excsig mov RDI, RAX ;Return value from excsig mov RSI, [RSP+(8*22)] ;RIP that CPU pushed mov RDX, CR2 ;Fault address from CPU mov RCX, RSP ;Location of exit-buffer extern kentry_exception ;void kentry_exception(int signum, uint64_t pc_addr, uint64_t ref_addr, hal_exit_t *eptr) call kentry_exception ;Exception handling in kernel should wipe-out kernel stack. .spin: hlt jmp .spin ;Interrupt service routines for legacy interrupts cpuinit_isr_irq0: push qword 0 jmp cpuinit_irq cpuinit_isr_irq1: push qword 1 jmp cpuinit_irq cpuinit_isr_irq2: push qword 2 jmp cpuinit_irq cpuinit_isr_irq3: push qword 3 jmp cpuinit_irq cpuinit_isr_irq4: push qword 4 jmp cpuinit_irq cpuinit_isr_irq5: push qword 5 jmp cpuinit_irq cpuinit_isr_irq6: push qword 6 jmp cpuinit_irq cpuinit_isr_irq7: push qword 7 jmp cpuinit_irq cpuinit_isr_irq8: push qword 8 jmp cpuinit_irq cpuinit_isr_irq9: push qword 9 jmp cpuinit_irq cpuinit_isr_irq10: push qword 10 jmp cpuinit_irq cpuinit_isr_irq11: push qword 11 jmp cpuinit_irq cpuinit_isr_irq12: push qword 12 jmp cpuinit_irq cpuinit_isr_irq13: push qword 13 jmp cpuinit_irq cpuinit_isr_irq14: push qword 14 jmp cpuinit_irq cpuinit_isr_irq15: push qword 15 jmp cpuinit_irq ;Common handling for IRQs cpuinit_irq: ;This is simpler than exception handling because we'll never context-switch away. ;So we'll always finish this on the same CPU we started, and can be minimally invasive. ;Save all registers that the kernel might use but won't save when making function calls. push RAX push RDI push RSI push RDX push RCX push R8 push R9 push R10 push R11 rdgsbase RAX push RAX ;Clear the GS-base as interrupts don't execute "on a thread" mov RAX, 0 wrgsbase RAX ;Check interrupt number mov RAX, [RSP+(8*10)] cmp RAX, 1 jne .done ;IRQ 1 - keyboard extern ps2kbd_isr call ps2kbd_isr .done: ;Send EOI mov RDI, [RSP+(8*10)] extern pic8529_pre_iret call pic8529_pre_iret pop RAX wrgsbase RAX pop R11 pop R10 pop R9 pop R8 pop RCX pop RDX pop RSI pop RDI pop RAX add RSP, 8 ;Pop vector number iretq ;Interrupt service routine for "wakeup" interrupts bits 64 align 16 cpuinit_isr_woke: ;Do nothing - we've been brought out of a halt, and that's all we care about. iretq section .data bits 32 ;Global descriptor table align 16 cpuinit_gdt: ;Null descriptor dq 0 ;!!!QEMU DISCREPANCY!!! ;The AMD64 reference (24593 r3.35 p90) says that all fields except "P" are ignored in long-mode data segment descriptors. ;However, QEMU requires that the "writable" bit be set on a data segment descriptor if it is selected for SS. ;Note that a SYSCALL instruction will load CS and SS with a certain value +0 and +8. ;So the order of these two descriptors matters - r0data64 must follow r0code64. ;Kernel code segment (64-bit long mode, ring-0) .r0code64: db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0b10011000 ;Present (1), DPL=0 (00), code segment (11), non-conforming (0), ignored (00) db 0b00100000 ;Ignored (0), 64-bit (01), unused (0), ignored (0000) db 0 ;Ignored ;Kernel data segment (ring-0) .r0data64: db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0b10010010 ;Present (1), ignored (00), data segment (10), ignored (0), writable (1), ignored (0) db 0 ;Ignored db 0 ;Ignored ;Similarly, SYSRET loads CS and SS with a certain value +16 and +8. ;The descriptor that SYSRET points to, +0, is used for returning to 32-bit code. We don't support that. ;So we must have r3dummy, r3data64, and then r3code64. .r3dummy: dq 0 ;Don't support returning to 32-bit mode ;!!!QEMU DISCREPANCY!!! ;The AMD64 reference (24593 r3.35 p91) says privilege level on a data segment is ignored. ;It explicitly states "a data-segment-descriptor DPL field is ignored in 64-bit mode" (24593 r3.35 p92). ;QEMU seems to check the privilege level on this when we use it in an iretq though. ;User data segment (ring-3) .r3data64: db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0b11110010 ;Present (1), SHOULD BE IGNORED (11), data segment (10), ignored (0), writable (1), ignored (0) db 0 ;Ignored db 0 ;Ignored ;User code segment (64-bit long mode, ring-3) .r3code64: db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0 ;Ignored db 0b11111000 ;Present (1), DPL=3 (11), code segment (11), non-conforming (0), ignored (00) db 0b00100000 ;Ignored (0), 64-bit (01), unused (0), ignored (0000) db 0 ;Ignored ;Descriptors for task-state segments for each CPU ;Built at runtime, so we can swizzle the address bytes align 16 .ktss_array: times (16 * CPU_MAX) db 0 ;Each descriptor is 16 bytes, and we need one per CPU .end: ;Pointer to global descriptor table for LGDT instruction align 16 cpuinit_gdtr: dw (cpuinit_gdt.end - cpuinit_gdt) - 1 dq cpuinit_gdt ;Pointer to interrupt descriptor table for LIDT instruction align 16 cpuinit_idtr: dw (cpuinit_idt.end - cpuinit_idt) - 1 dq cpuinit_idt ;Function pointers we use for building the interrupt descriptor table align 16 cpuinit_isrptrs: ;First 32 vectors - CPU exceptions dq cpuinit_isr_de ;0 dq cpuinit_isr_db ;1 dq cpuinit_isr_nmi ;2 dq cpuinit_isr_bp ;3 dq cpuinit_isr_of ;4 dq cpuinit_isr_br ;5 dq cpuinit_isr_ud ;6 dq cpuinit_isr_nm ;7 dq cpuinit_isr_df ;8 dq cpuinit_isr_cop ;9 dq cpuinit_isr_ts ;10 dq cpuinit_isr_np ;11 dq cpuinit_isr_ss ;12 dq cpuinit_isr_gp ;13 dq cpuinit_isr_pf ;14 dq cpuinit_isr_bad ;15 dq cpuinit_isr_mf ;16 dq cpuinit_isr_ac ;17 dq cpuinit_isr_mc ;18 dq cpuinit_isr_xf ;19 dq cpuinit_isr_bad ;20 dq cpuinit_isr_bad ;21 dq cpuinit_isr_bad ;22 dq cpuinit_isr_bad ;23 dq cpuinit_isr_bad ;24 dq cpuinit_isr_bad ;25 dq cpuinit_isr_bad ;26 dq cpuinit_isr_bad ;27 dq cpuinit_isr_hv ;28 dq cpuinit_isr_vc ;29 dq cpuinit_isr_sx ;30 dq cpuinit_isr_bad ;31 ;Vectors 32-47 used for legacy IRQs dq cpuinit_isr_irq0 ;32 dq cpuinit_isr_irq1 ;33 dq cpuinit_isr_irq2 ;34 dq cpuinit_isr_irq3 ;35 dq cpuinit_isr_irq4 ;36 dq cpuinit_isr_irq5 ;37 dq cpuinit_isr_irq6 ;38 dq cpuinit_isr_irq7 ;39 dq cpuinit_isr_irq8 ;40 dq cpuinit_isr_irq9 ;41 dq cpuinit_isr_irq10 ;42 dq cpuinit_isr_irq11 ;43 dq cpuinit_isr_irq12 ;44 dq cpuinit_isr_irq13 ;45 dq cpuinit_isr_irq14 ;46 dq cpuinit_isr_irq15 ;47 ;Other vectors unused times 207 dq cpuinit_isr_bad ;48-254 ;Vector 255 is wakeup dq cpuinit_isr_woke ;255 ;Simple bump allocator for allocating per-core structures, virtually, after kernel as-linked align 8 cpuinit_bump_next: dq _KERNEL_END + 4096 section .bss bits 32 ;Stack for initial single-processor setup of kernel align 4096 cpuinit_initstack: resb 4096 .top: ;PML4 (top level paging structure) for kernel as linked align 4096 global cpuinit_pml4 cpuinit_pml4: resb 4096 ;Page directory pointer table for kernel as linked align 4096 global cpuinit_pdpt cpuinit_pdpt: resb 4096 ;Page directory for kernel as linked align 4096 global cpuinit_pd cpuinit_pd: resb 4096 ;Page table for kernel as linked align 4096 global cpuinit_pt cpuinit_pt: resb 4096 ;Space for interrupt descriptor table (IDT) ;We have to build this at runtime because of the crazy byte swizzling needed. align 4096 cpuinit_idt: resb 256 * 16 .end: ;Address where we mapped the Local APIC align 8 cpuinit_lapicaddr: resb 8 ;ID numbers claimed atomically by CPUs on startup align 8 cpuinit_nextid: resb 8 ;Number of CPUs that have completed startup successfully align 8 cpuinit_coresdone: resb 8 ;Pointers to task state segments for each CPU align 8 cpuinit_tssptrs: resb 8 * CPU_MAX
# Register use for syscall # syscall_num 1st arg 2nd 3rd 4th 5th 6th # x86_64 rax rdi rsi rdx r10 r8 r9 - mov %rdi,%rax mov %rsi,%rdi mov %rdx,%rsi mov %rcx,%rdx mov %r8,%r10 mov %r9,%r8 mov 0x8(%rsp),%r9 syscall cmp $0xfffffffffffff001,%rax jae 0x7ffff7b0f902 <syscall+34> retq mov 0x2c255f(%rip),%rcx # 0x7ffff7dd1e68 neg %eax mov %eax,%fs:(%rcx) or $0xffffffffffffffff,%rax retq
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/search_engines/template_url_service_factory.h" #include <string> #include "base/bind.h" #include "base/prefs/pref_service.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/google/google_url_tracker_factory.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/rlz/rlz.h" #include "chrome/browser/search_engines/chrome_template_url_service_client.h" #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" #include "chrome/browser/webdata/web_data_service_factory.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/pref_registry/pref_registry_syncable.h" #include "components/search_engines/default_search_manager.h" #include "components/search_engines/search_engines_pref_names.h" #include "components/search_engines/template_url_service.h" // static TemplateURLService* TemplateURLServiceFactory::GetForProfile(Profile* profile) { return static_cast<TemplateURLService*>( GetInstance()->GetServiceForBrowserContext(profile, true)); } // static TemplateURLServiceFactory* TemplateURLServiceFactory::GetInstance() { return Singleton<TemplateURLServiceFactory>::get(); } // static KeyedService* TemplateURLServiceFactory::BuildInstanceFor( content::BrowserContext* context) { base::Closure dsp_change_callback; #if defined(ENABLE_RLZ) dsp_change_callback = base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent), rlz_lib::CHROME, RLZTracker::ChromeOmnibox(), rlz_lib::SET_TO_GOOGLE); #endif Profile* profile = static_cast<Profile*>(context); return new TemplateURLService( profile->GetPrefs(), scoped_ptr<SearchTermsData>(new UIThreadSearchTermsData(profile)), WebDataServiceFactory::GetKeywordWebDataForProfile( profile, ServiceAccessType::EXPLICIT_ACCESS), scoped_ptr<TemplateURLServiceClient>(new ChromeTemplateURLServiceClient( HistoryServiceFactory::GetForProfile( profile, ServiceAccessType::EXPLICIT_ACCESS))), GoogleURLTrackerFactory::GetForProfile(profile), g_browser_process->rappor_service(), dsp_change_callback); } TemplateURLServiceFactory::TemplateURLServiceFactory() : BrowserContextKeyedServiceFactory( "TemplateURLServiceFactory", BrowserContextDependencyManager::GetInstance()) { DependsOn(GoogleURLTrackerFactory::GetInstance()); DependsOn(HistoryServiceFactory::GetInstance()); DependsOn(WebDataServiceFactory::GetInstance()); } TemplateURLServiceFactory::~TemplateURLServiceFactory() {} KeyedService* TemplateURLServiceFactory::BuildServiceInstanceFor( content::BrowserContext* profile) const { return BuildInstanceFor(static_cast<Profile*>(profile)); } void TemplateURLServiceFactory::RegisterProfilePrefs( user_prefs::PrefRegistrySyncable* registry) { DefaultSearchManager::RegisterProfilePrefs(registry); registry->RegisterStringPref(prefs::kSyncedDefaultSearchProviderGUID, std::string(), user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); registry->RegisterBooleanPref( prefs::kDefaultSearchProviderEnabled, true, user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderName, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderID, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderPrepopulateID, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderSuggestURL, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderSearchURL, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderInstantURL, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderImageURL, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderNewTabURL, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderSearchURLPostParams, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderSuggestURLPostParams, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderInstantURLPostParams, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderImageURLPostParams, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderKeyword, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderIconURL, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderEncodings, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterListPref(prefs::kDefaultSearchProviderAlternateURLs, user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( prefs::kDefaultSearchProviderSearchTermsReplacementKey, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); } content::BrowserContext* TemplateURLServiceFactory::GetBrowserContextToUse( content::BrowserContext* context) const { return chrome::GetBrowserContextRedirectedInIncognito(context); } bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const { return true; }
ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK EQU $01 ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK EQU $02 USING_EXTERNAL_CLOCK EQU $01 USING_INTERNAL_CLOCK EQU $02 CONNECTION_NOT_ESTABLISHED EQU $ff ; signals the start of an array of bytes transferred over the link cable SERIAL_PREAMBLE_BYTE EQU $FD ; this byte is used when there is no data to send SERIAL_NO_DATA_BYTE EQU $FE ; signals the end of one part of a patch list (there are two parts) for player/enemy party data SERIAL_PATCH_LIST_PART_TERMINATOR EQU $FF LINK_STATE_NONE EQU $00 ; not using link LINK_STATE_IN_CABLE_CLUB EQU $01 ; in a cable club room (Colosseum or Trade Centre) LINK_STATE_START_TRADE EQU $02 ; pre-trade selection screen initialisation LINK_STATE_START_BATTLE EQU $03 ; pre-battle initialisation LINK_STATE_BATTLING EQU $04 ; in a link battle LINK_STATE_RESET EQU $05 ; reset game (unused) LINK_STATE_TRADING EQU $32 ; in a link trade LINKBATTLE_RUN EQU $F LINKBATTLE_STRUGGLE EQU $E LINKBATTLE_NO_ACTION EQU $D
#include "cbase.h" #include "filesystem.h"
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r13 push %r14 push %r9 push %rax push %rcx push %rdi push %rsi lea addresses_WC_ht+0xbfcf, %rsi lea addresses_normal_ht+0x13acf, %rdi nop nop nop nop xor %r9, %r9 mov $16, %rcx rep movsl nop nop nop nop sub %rdi, %rdi lea addresses_UC_ht+0x5b4f, %rdi nop add %r10, %r10 vmovups (%rdi), %ymm2 vextracti128 $1, %ymm2, %xmm2 vpextrq $0, %xmm2, %r9 nop nop nop inc %r10 lea addresses_UC_ht+0x1e14f, %r13 clflush (%r13) nop nop nop nop nop and $24240, %rax mov (%r13), %r10 nop nop nop nop nop dec %rdi lea addresses_WT_ht+0x31af, %rsi nop dec %r13 movw $0x6162, (%rsi) nop nop add %r9, %r9 lea addresses_normal_ht+0xe34f, %rsi nop dec %rdi movw $0x6162, (%rsi) cmp $55013, %r10 lea addresses_normal_ht+0x8211, %rcx nop nop nop cmp %r9, %r9 mov (%rcx), %ax nop nop nop nop inc %rax lea addresses_D_ht+0x7fe3, %rcx nop nop xor $4365, %rdi movl $0x61626364, (%rcx) nop nop nop inc %r13 lea addresses_WT_ht+0x1713b, %rax nop sub $26531, %rdi mov (%rax), %r13w nop nop nop nop and $44120, %r9 lea addresses_A_ht+0xaacf, %rdi nop nop add %r9, %r9 vmovups (%rdi), %ymm1 vextracti128 $0, %ymm1, %xmm1 vpextrq $0, %xmm1, %rsi nop nop inc %rax lea addresses_normal_ht+0x414f, %rsi lea addresses_D_ht+0x1714f, %rdi clflush (%rdi) nop nop nop nop nop add %r14, %r14 mov $60, %rcx rep movsl nop nop and $39071, %rcx lea addresses_UC_ht+0x81f3, %r9 nop nop cmp $44384, %rax mov $0x6162636465666768, %rcx movq %rcx, (%r9) nop nop add $24917, %r13 lea addresses_WC_ht+0x18e4f, %rdi nop nop nop nop nop inc %r13 mov (%rdi), %si nop nop cmp %rsi, %rsi lea addresses_normal_ht+0x11d4f, %rsi lea addresses_UC_ht+0x1d8e2, %rdi nop nop nop add %r9, %r9 mov $7, %rcx rep movsb nop sub $39235, %r10 lea addresses_A_ht+0x1104f, %r14 nop and $11470, %rcx mov (%r14), %edi nop sub $40081, %rcx pop %rsi pop %rdi pop %rcx pop %rax pop %r9 pop %r14 pop %r13 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r13 push %rax push %rbp push %rdi push %rsi // Store lea addresses_US+0x334f, %r11 nop nop nop dec %rbp mov $0x5152535455565758, %rax movq %rax, %xmm1 movntdq %xmm1, (%r11) cmp %rbp, %rbp // Store lea addresses_RW+0x18f4f, %r12 nop nop nop nop nop add $19424, %rdi mov $0x5152535455565758, %rbp movq %rbp, %xmm0 vmovntdq %ymm0, (%r12) nop nop nop nop nop xor $44601, %rsi // Load lea addresses_normal+0x654f, %r13 nop nop nop nop add $14307, %r11 mov (%r13), %r12 nop nop and $64699, %rdi // Faulty Load lea addresses_US+0x1994f, %r12 nop nop nop nop add $14329, %r11 mov (%r12), %rsi lea oracles, %r13 and $0xff, %rsi shlq $12, %rsi mov (%r13,%rsi,1), %rsi pop %rsi pop %rdi pop %rbp pop %rax pop %r13 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_US'}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 16, 'NT': True, 'type': 'addresses_US'}} {'OP': 'STOR', 'dst': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 32, 'NT': True, 'type': 'addresses_RW'}} {'src': {'congruent': 7, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_normal'}, 'OP': 'LOAD'} [Faulty Load] {'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 8, 'NT': False, 'type': 'addresses_US'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'congruent': 7, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_normal_ht'}} {'src': {'congruent': 6, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 11, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'congruent': 5, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_WT_ht'}} {'OP': 'STOR', 'dst': {'congruent': 9, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_normal_ht'}} {'src': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_D_ht'}} {'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_WT_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 5, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 11, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_D_ht'}} {'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': True, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_UC_ht'}} {'src': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_WC_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 10, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'congruent': 0, 'same': False, 'type': 'addresses_UC_ht'}} {'src': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'} {'00': 21829} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
# JMH version: 1.19 # VM version: JDK 1.8.0_131, VM 25.131-b11 # VM invoker: /usr/lib/jvm/java-8-oracle/jre/bin/java # VM options: <none> # Warmup: 20 iterations, 1 s each # Measurement: 20 iterations, 1 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Average time, time/op # Benchmark: com.github.arnaudroger.Seq2ArrayAccess.testGet # Parameters: (size = 1000) # Run progress: 0.00% complete, ETA 00:00:40 # Fork: 1 of 1 # Preparing profilers: LinuxPerfAsmProfiler # Profilers consume stdout and stderr from target VM, use -v EXTRA to copy to console # Warmup Iteration 1: 334.349 ns/op # Warmup Iteration 2: 346.347 ns/op # Warmup Iteration 3: 318.022 ns/op # Warmup Iteration 4: 321.903 ns/op # Warmup Iteration 5: 317.772 ns/op # Warmup Iteration 6: 319.919 ns/op # Warmup Iteration 7: 318.490 ns/op # Warmup Iteration 8: 317.578 ns/op # Warmup Iteration 9: 317.263 ns/op # Warmup Iteration 10: 317.551 ns/op # Warmup Iteration 11: 320.836 ns/op # Warmup Iteration 12: 317.835 ns/op # Warmup Iteration 13: 319.652 ns/op # Warmup Iteration 14: 316.904 ns/op # Warmup Iteration 15: 317.256 ns/op # Warmup Iteration 16: 322.853 ns/op # Warmup Iteration 17: 320.175 ns/op # Warmup Iteration 18: 320.182 ns/op # Warmup Iteration 19: 318.752 ns/op # Warmup Iteration 20: 320.307 ns/op Iteration 1: 322.303 ns/op Iteration 2: 321.378 ns/op Iteration 3: 319.529 ns/op Iteration 4: 320.261 ns/op Iteration 5: 323.531 ns/op Iteration 6: 320.900 ns/op Iteration 7: 319.312 ns/op Iteration 8: 321.831 ns/op Iteration 9: 318.855 ns/op Iteration 10: 319.784 ns/op Iteration 11: 324.568 ns/op Iteration 12: 319.887 ns/op Iteration 13: 319.830 ns/op Iteration 14: 318.753 ns/op Iteration 15: 322.076 ns/op Iteration 16: 321.250 ns/op Iteration 17: 321.013 ns/op Iteration 18: 319.132 ns/op Iteration 19: 318.847 ns/op Iteration 20: 319.453 ns/op # Processing profiler results: LinuxPerfAsmProfiler Result "com.github.arnaudroger.Seq2ArrayAccess.testGet": 320.625 ±(99.9%) 1.407 ns/op [Average] (min, avg, max) = (318.753, 320.625, 324.568), stdev = 1.621 CI (99.9%): [319.217, 322.032] (assumes normal distribution) Secondary result "com.github.arnaudroger.Seq2ArrayAccess.testGet:·asm": PrintAssembly processed: 171949 total address lines. Perf output processed (skipped 23.316 seconds): Column 1: cycles (20704 events) Column 2: instructions (20706 events) Hottest code regions (>10.00% "cycles" events): ....[Hottest Region 1].............................................................................. C2, level 4, com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub, version 531 (226 bytes) ; implicit exception: dispatches to 0x00007f0870bf2ffd 0x00007f0870bf2df5: test %r11d,%r11d 0x00007f0870bf2df8: jne 0x00007f0870bf2ef9 ;*ifeq ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@33 (line 234) 0x00007f0870bf2dfe: mov $0x1,%ebx ╭ 0x00007f0870bf2e03: jmp 0x00007f0870bf2e3b │↗ 0x00007f0870bf2e05: xor %edx,%edx ;*if_icmpge ││ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@18 (line 57) ││ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) ││ ↗ 0x00007f0870bf2e07: mov %rbx,0x48(%rsp) 0.11% ││ │ 0x00007f0870bf2e0c: mov %r8,%rbp ││ │ 0x00007f0870bf2e0f: mov (%rsp),%rsi 0.14% 0.03% ││ │ 0x00007f0870bf2e13: callq 0x00007f0870a0d020 ; OopMap{rbp=Oop [64]=Oop [80]=Oop [0]=Oop off=312} ││ │ ;*invokevirtual consume ││ │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@20 (line 232) ││ │ ; {optimized virtual_call} 0.29% 0.09% ││ │ 0x00007f0870bf2e18: mov %rbp,%r8 ││ │ 0x00007f0870bf2e1b: movzbl 0x94(%r8),%r11d ;*getfield isDone ││ │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@30 (line 234) 0.02% ││ │ 0x00007f0870bf2e23: mov 0x48(%rsp),%rbx 0.06% 0.09% ││ │ 0x00007f0870bf2e28: add $0x1,%rbx ; OopMap{r8=Oop [64]=Oop [80]=Oop [0]=Oop off=332} ││ │ ;*ifeq ││ │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@33 (line 234) ││ │ 0x00007f0870bf2e2c: test %eax,0x15f731ce(%rip) # 0x00007f0886b66000 ││ │ ; {poll} 0.00% 0.00% ││ │ 0x00007f0870bf2e32: test %r11d,%r11d ││ │ 0x00007f0870bf2e35: jne 0x00007f0870bf2efe ;*aload ││ │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@13 (line 232) ↘│ │ 0x00007f0870bf2e3b: mov 0x50(%rsp),%r10 0.07% 0.04% │ │ 0x00007f0870bf2e40: mov 0x10(%r10),%ecx ;*getfield data │ │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@3 (line 57) │ │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 0.01% 0.01% │ │ 0x00007f0870bf2e44: mov 0xc(%r12,%rcx,8),%ebp ;*arraylength │ │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@8 (line 57) │ │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) │ │ ; implicit exception: dispatches to 0x00007f0870bf2fb9 0.18% 0.14% │ │ 0x00007f0870bf2e49: test %ebp,%ebp ╰ │ 0x00007f0870bf2e4b: jle 0x00007f0870bf2e05 ;*if_icmpge │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@18 (line 57) │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 0.09% 0.05% │ 0x00007f0870bf2e4d: test %ebp,%ebp │ 0x00007f0870bf2e4f: jbe 0x00007f0870bf2f2f 0.00% 0.00% │ 0x00007f0870bf2e55: mov %ebp,%r11d │ 0x00007f0870bf2e58: dec %r11d │ 0x00007f0870bf2e5b: cmp %ebp,%r11d │ 0x00007f0870bf2e5e: jae 0x00007f0870bf2f2f ;*aload_3 │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@21 (line 57) │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 0.08% 0.02% │ 0x00007f0870bf2e64: mov 0x10(%r12,%rcx,8),%r10d ;*aaload │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@24 (line 57) │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 0.00% │ 0x00007f0870bf2e69: mov 0x10(%r12,%r10,8),%rdx ;*getfield value │ ; - java.lang.Long::longValue@1 (line 1000) │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@30 (line 58) │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) │ ; implicit exception: dispatches to 0x00007f0870bf2f99 0.15% 0.05% │ 0x00007f0870bf2e6e: mov %ebp,%r9d │ 0x00007f0870bf2e71: add $0xfffffffd,%r9d │ 0x00007f0870bf2e75: cmp %r9d,%r11d │ 0x00007f0870bf2e78: mov $0x80000000,%r11d 0.08% 0.04% │ 0x00007f0870bf2e7e: cmovl %r11d,%r9d │ 0x00007f0870bf2e82: lea (%r12,%rcx,8),%rdi │ 0x00007f0870bf2e86: cmp $0x1,%r9d │ 0x00007f0870bf2e8a: jle 0x00007f0870bf2f4d 0.07% 0.01% │ 0x00007f0870bf2e90: mov $0x1,%ecx │ 0x00007f0870bf2e95: data16 data16 nopw 0x0(%rax,%rax,1) │ ;*aload_3 │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@21 (line 57) │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 0.01% 0.00% ↗│ 0x00007f0870bf2ea0: mov 0x10(%rdi,%rcx,4),%r11d 0.02% 0.00% ││ 0x00007f0870bf2ea5: add 0x10(%r12,%r11,8),%rdx ; implicit exception: dispatches to 0x00007f0870bf2f99 21.65% 20.79% ││ 0x00007f0870bf2eaa: movslq %ecx,%r11 0.01% 0.01% ││ 0x00007f0870bf2ead: mov 0x14(%rdi,%r11,4),%r10d ;*aaload ││ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@24 (line 57) ││ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 0.01% ││ 0x00007f0870bf2eb2: mov 0x10(%r12,%r10,8),%rsi ;*getfield value ││ ; - java.lang.Long::longValue@1 (line 1000) ││ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@30 (line 58) ││ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) ││ ; implicit exception: dispatches to 0x00007f0870bf2f99 1.23% 1.26% ││ 0x00007f0870bf2eb7: mov 0x18(%rdi,%r11,4),%r10d ;*aaload ││ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@24 (line 57) ││ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 19.36% 20.47% ││ 0x00007f0870bf2ebc: mov 0x10(%r12,%r10,8),%r10 ;*getfield value ││ ; - java.lang.Long::longValue@1 (line 1000) ││ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@30 (line 58) ││ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) ││ ; implicit exception: dispatches to 0x00007f0870bf2f99 2.08% 2.04% ││ 0x00007f0870bf2ec1: mov 0x1c(%rdi,%r11,4),%r11d ;*aaload ││ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@24 (line 57) ││ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) ││ 0x00007f0870bf2ec6: mov 0x10(%r12,%r11,8),%r11 ;*getfield value ││ ; - java.lang.Long::longValue@1 (line 1000) ││ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@30 (line 58) ││ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) ││ ; implicit exception: dispatches to 0x00007f0870bf2f99 4.89% 4.70% ││ 0x00007f0870bf2ecb: add %rsi,%rdx 16.44% 15.93% ││ 0x00007f0870bf2ece: add %r10,%rdx 4.50% 4.98% ││ 0x00007f0870bf2ed1: add %r11,%rdx ;*ladd ││ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@33 (line 58) ││ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 22.57% 24.03% ││ 0x00007f0870bf2ed4: add $0x4,%ecx ;*iinc ││ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@35 (line 57) ││ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) ││ 0x00007f0870bf2ed7: cmp %r9d,%ecx ╰│ 0x00007f0870bf2eda: jl 0x00007f0870bf2ea0 ;*if_icmpge │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@18 (line 57) │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 0.00% 0.01% │ 0x00007f0870bf2edc: cmp %ebp,%ecx ╰ 0x00007f0870bf2ede: jge 0x00007f0870bf2e07 ;*aload_3 ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@21 (line 57) ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 0.28% 0.26% ↗ 0x00007f0870bf2ee4: mov 0x10(%rdi,%rcx,4),%r11d ;*aaload │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@24 (line 57) │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 0.30% 0.28% │ 0x00007f0870bf2ee9: add 0x10(%r12,%r11,8),%rdx ;*ladd │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@33 (line 58) │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) │ ; implicit exception: dispatches to 0x00007f0870bf2f99 0.89% 0.86% │ 0x00007f0870bf2eee: inc %ecx ;*iinc │ ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@35 (line 57) │ ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) │ 0x00007f0870bf2ef0: cmp %ebp,%ecx ╰ 0x00007f0870bf2ef2: jl 0x00007f0870bf2ee4 ;*if_icmpge ; - com.github.arnaudroger.Seq2ArrayAccess::testGet@18 (line 57) ; - com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub@17 (line 232) 0x00007f0870bf2ef4: jmpq 0x00007f0870bf2e07 .................................................................................................... 95.64% 96.22% <total for region 1> ....[Hottest Regions]............................................................................... 95.64% 96.22% C2, level 4 com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub, version 531 (226 bytes) 2.15% 2.14% [kernel.kallsyms] [unknown] (0 bytes) 0.57% 0.05% C2, level 4 org.openjdk.jmh.infra.Blackhole::consume, version 512 (44 bytes) 0.09% 0.02% [kernel.kallsyms] [unknown] (30 bytes) 0.05% 0.02% [kernel.kallsyms] [unknown] (0 bytes) 0.04% 0.01% [kernel.kallsyms] [unknown] (1 bytes) 0.04% 0.04% [kernel.kallsyms] [unknown] (24 bytes) 0.04% 0.00% [kernel.kallsyms] [unknown] (8 bytes) 0.03% 0.00% [kernel.kallsyms] [unknown] (24 bytes) 0.03% 0.01% libjvm.so _ZN10fileStream5writeEPKcm (36 bytes) 0.02% 0.05% [kernel.kallsyms] [unknown] (83 bytes) 0.02% 0.02% [kernel.kallsyms] [unknown] (9 bytes) 0.02% 0.01% [kernel.kallsyms] [unknown] (0 bytes) 0.02% [kernel.kallsyms] [unknown] (49 bytes) 0.02% 0.00% [kernel.kallsyms] [unknown] (72 bytes) 0.02% 0.05% libjvm.so _ZN12outputStream15update_positionEPKcm (17 bytes) 0.02% 0.04% libjvm.so _ZN13RelocIterator10initializeEP7nmethodPhS2_ (90 bytes) 0.02% 0.00% libpthread-2.26.so __pthread_disable_asynccancel (0 bytes) 0.01% 0.01% [kernel.kallsyms] [unknown] (0 bytes) 0.01% 0.00% [kernel.kallsyms] [unknown] (20 bytes) 1.13% 1.28% <...other 329 warm regions...> .................................................................................................... 99.99% 100.00% <totals> ....[Hottest Methods (after inlining)].............................................................. 95.64% 96.22% C2, level 4 com.github.arnaudroger.generated.Seq2ArrayAccess_testGet_jmhTest::testGet_avgt_jmhStub, version 531 3.11% 3.01% [kernel.kallsyms] [unknown] 0.57% 0.05% C2, level 4 org.openjdk.jmh.infra.Blackhole::consume, version 512 0.07% 0.04% hsdis-amd64.so [unknown] 0.04% 0.08% libc-2.26.so vfprintf 0.04% 0.02% libjvm.so _ZN10fileStream5writeEPKcm 0.02% 0.04% libjvm.so _ZN13xmlTextStream5writeEPKcm 0.02% 0.05% libjvm.so _ZN13RelocIterator10initializeEP7nmethodPhS2_ 0.02% 0.01% libc-2.26.so __strlen_avx2 0.02% 0.00% libjvm.so _ZN13defaultStream5writeEPKcm 0.02% 0.00% libpthread-2.26.so __pthread_disable_asynccancel 0.02% 0.05% libjvm.so _ZN12outputStream15update_positionEPKcm 0.01% libjvm.so jio_print 0.01% 0.00% libc-2.26.so _IO_fflush 0.01% 0.04% libc-2.26.so _IO_fwrite 0.01% 0.00% libc-2.26.so _IO_vsnprintf 0.01% 0.01% libjvm.so _ZN7Monitor5ILockEP6Thread 0.01% 0.00% libc-2.26.so __memmove_avx_unaligned_erms 0.01% 0.00% libjvm.so _ZN12stringStream5writeEPKcm 0.01% 0.00% libjvm.so _ZN10decode_env12handle_eventEPKcPh 0.30% 0.14% <...other 57 warm methods...> .................................................................................................... 99.99% 99.80% <totals> ....[Distribution by Source]........................................................................ 96.20% 96.28% C2, level 4 3.11% 3.01% [kernel.kallsyms] 0.33% 0.33% libjvm.so 0.19% 0.25% libc-2.26.so 0.08% 0.04% hsdis-amd64.so 0.04% 0.06% libpthread-2.26.so 0.03% 0.02% interpreter 0.00% 0.00% perf-2686.map 0.00% C1, level 3 .................................................................................................... 99.99% 100.00% <totals> # Run complete. Total time: 00:00:45 Benchmark (size) Mode Cnt Score Error Units Seq2ArrayAccess.testGet 1000 avgt 20 320.625 ± 1.407 ns/op Seq2ArrayAccess.testGet:·asm 1000 avgt NaN --- Benchmark result is saved to jmh-result2.csv
;; ;; Copyright (c) 2020-2021, Intel Corporation ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions are met: ;; ;; * Redistributions of source code must retain the above copyright notice, ;; this list of conditions and the following disclaimer. ;; * Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; * Neither the name of Intel Corporation nor the names of its contributors ;; may be used to endorse or promote products derived from this software ;; without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;; %include "include/os.asm" [bits 64] default rel section .data ;; Ethernet FCS CRC32 0x04c11db7 ;; http://www.ietf.org/rfc/rfc1952.txt align 64 MKGLOBAL(crc32_ethernet_fcs_const,data,internal) crc32_ethernet_fcs_const: dq 0x00000000e95c1271, 0x00000000ce3371cb ; 2048-bits fold dq 0x00000000910eeec1, 0x0000000033fff533 ; 1024-bits fold dq 0x000000000cbec0ed, 0x0000000031f8303f ; 896-bits fold dq 0x0000000057c54819, 0x00000000df068dc2 ; 768-bits fold dq 0x00000000ae0b5394, 0x000000001c279815 ; 640-bits fold dq 0x000000001d9513d7, 0x000000008f352d95 ; 512-bits fold dq 0x00000000af449247, 0x000000003db1ecdc ; 384-bits fold dq 0x0000000081256527, 0x00000000f1da05aa ; 256-bits fold dq 0x00000000ccaa009e, 0x00000000ae689191 ; 128-bits fold dq 0x0000000000000000, 0x0000000000000000 ; padding dq 0x00000000ccaa009e, 0x00000000b8bc6765 ; 128-bits to 64-bits fold dq 0x00000001f7011640, 0x00000001db710640 ; 64-bits to 32-bits reduction ;; CRC16 X25 CCITT 0x1021 / initial value = 0xffff align 64 MKGLOBAL(crc16_x25_ccitt_const,data,internal) crc16_x25_ccitt_const: dq 0x0000000000009a19, 0x0000000000002df8 ; 2048-b fold dq 0x00000000000068af, 0x000000000000b6c9 ; 1024-b fold dq 0x000000000000c64f, 0x000000000000cd95 ; 896-b fold dq 0x000000000000d341, 0x000000000000b8f2 ; 768-b fold dq 0x0000000000000842, 0x000000000000b072 ; 640-b fold dq 0x00000000000047e3, 0x000000000000922d ; 512-b fold dq 0x0000000000000e3a, 0x0000000000004d7a ; 384-b fold dq 0x0000000000005b44, 0x0000000000007762 ; 256-b fold dq 0x00000000000081bf, 0x0000000000008e10 ; 128-b fold dq 0x0000000000000000, 0x0000000000000000 ; padding dq 0x00000000000081bf, 0x0000000000001cbb ; 128-bits to 64-bits fold dq 0x000000011c581910, 0x0000000000010810 ; 64-bits to 32-bits reduction %ifdef LINUX section .note.GNU-stack noalloc noexec nowrite progbits %endif
// Copyright (c) 2011-2014 The Bitcoin developers // Copyright (c) 2014-2015 The Dash developers // Copyright (c) 2015-2017 The PIVX developers // Copyright (c) 2018 The Specialcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #if defined(HAVE_CONFIG_H) #include "config/specialcoin-config.h" #endif #include "addressbookpage.h" #include "ui_addressbookpage.h" #include "addresstablemodel.h" #include "bitcoingui.h" #include "csvmodelwriter.h" #include "editaddressdialog.h" #include "guiutil.h" #include <QIcon> #include <QMenu> #include <QMessageBox> #include <QSortFilterProxyModel> AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget* parent) : QDialog(parent), ui(new Ui::AddressBookPage), model(0), mode(mode), tab(tab) { ui->setupUi(this); #ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac ui->newAddress->setIcon(QIcon()); ui->copyAddress->setIcon(QIcon()); ui->deleteAddress->setIcon(QIcon()); ui->exportButton->setIcon(QIcon()); #endif switch (mode) { case ForSelection: switch (tab) { case SendingTab: setWindowTitle(tr("Choose the address to send coins to")); break; case ReceivingTab: setWindowTitle(tr("Choose the address to receive coins with")); break; } connect(ui->tableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept())); ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); ui->tableView->setFocus(); ui->closeButton->setText(tr("C&hoose")); ui->exportButton->hide(); break; case ForEditing: switch (tab) { case SendingTab: setWindowTitle(tr("Sending addresses")); break; case ReceivingTab: setWindowTitle(tr("Receiving addresses")); break; } break; } switch (tab) { case SendingTab: ui->labelExplanation->setText(tr("These are your Specialcoin addresses for sending payments. Always check the amount and the receiving address before sending coins.")); ui->deleteAddress->setVisible(true); break; case ReceivingTab: ui->labelExplanation->setText(tr("These are your Specialcoin addresses for receiving payments. It is recommended to use a new receiving address for each transaction.")); ui->deleteAddress->setVisible(false); break; } // Context menu actions QAction* copyAddressAction = new QAction(tr("&Copy Address"), this); QAction* copyLabelAction = new QAction(tr("Copy &Label"), this); QAction* editAction = new QAction(tr("&Edit"), this); deleteAction = new QAction(ui->deleteAddress->text(), this); // Build context menu contextMenu = new QMenu(); contextMenu->addAction(copyAddressAction); contextMenu->addAction(copyLabelAction); contextMenu->addAction(editAction); if (tab == SendingTab) contextMenu->addAction(deleteAction); contextMenu->addSeparator(); // Connect signals for context menu actions connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(on_copyAddress_clicked())); connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(onCopyLabelAction())); connect(editAction, SIGNAL(triggered()), this, SLOT(onEditAction())); connect(deleteAction, SIGNAL(triggered()), this, SLOT(on_deleteAddress_clicked())); connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint))); connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(accept())); } AddressBookPage::~AddressBookPage() { delete ui; } void AddressBookPage::setModel(AddressTableModel* model) { this->model = model; if (!model) return; proxyModel = new QSortFilterProxyModel(this); proxyModel->setSourceModel(model); proxyModel->setDynamicSortFilter(true); proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); switch (tab) { case ReceivingTab: // Receive filter proxyModel->setFilterRole(AddressTableModel::TypeRole); proxyModel->setFilterFixedString(AddressTableModel::Receive); break; case SendingTab: // Send filter proxyModel->setFilterRole(AddressTableModel::TypeRole); proxyModel->setFilterFixedString(AddressTableModel::Send); break; } ui->tableView->setModel(proxyModel); ui->tableView->sortByColumn(0, Qt::AscendingOrder); // Set column widths #if QT_VERSION < 0x050000 ui->tableView->horizontalHeader()->setResizeMode(AddressTableModel::Label, QHeaderView::Stretch); ui->tableView->horizontalHeader()->setResizeMode(AddressTableModel::Address, QHeaderView::ResizeToContents); #else ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Label, QHeaderView::Stretch); ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Address, QHeaderView::ResizeToContents); #endif connect(ui->tableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged())); // Select row for newly created address connect(model, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(selectNewAddress(QModelIndex, int, int))); selectionChanged(); } void AddressBookPage::on_copyAddress_clicked() { GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Address); } void AddressBookPage::onCopyLabelAction() { GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Label); } void AddressBookPage::onEditAction() { if (!model) return; if (!ui->tableView->selectionModel()) return; QModelIndexList indexes = ui->tableView->selectionModel()->selectedRows(); if (indexes.isEmpty()) return; EditAddressDialog dlg( tab == SendingTab ? EditAddressDialog::EditSendingAddress : EditAddressDialog::EditReceivingAddress, this); dlg.setModel(model); QModelIndex origIndex = proxyModel->mapToSource(indexes.at(0)); dlg.loadRow(origIndex.row()); dlg.exec(); } void AddressBookPage::on_newAddress_clicked() { if (!model) return; EditAddressDialog dlg( tab == SendingTab ? EditAddressDialog::NewSendingAddress : EditAddressDialog::NewReceivingAddress, this); dlg.setModel(model); if (dlg.exec()) { newAddressToSelect = dlg.getAddress(); } } void AddressBookPage::on_deleteAddress_clicked() { QTableView* table = ui->tableView; if (!table->selectionModel()) return; QModelIndexList indexes = table->selectionModel()->selectedRows(); if (!indexes.isEmpty()) { table->model()->removeRow(indexes.at(0).row()); } } void AddressBookPage::selectionChanged() { // Set button states based on selected tab and selection QTableView* table = ui->tableView; if (!table->selectionModel()) return; if (table->selectionModel()->hasSelection()) { switch (tab) { case SendingTab: // In sending tab, allow deletion of selection ui->deleteAddress->setEnabled(true); ui->deleteAddress->setVisible(true); deleteAction->setEnabled(true); break; case ReceivingTab: // Deleting receiving addresses, however, is not allowed ui->deleteAddress->setEnabled(false); ui->deleteAddress->setVisible(false); deleteAction->setEnabled(false); break; } ui->copyAddress->setEnabled(true); } else { ui->deleteAddress->setEnabled(false); ui->copyAddress->setEnabled(false); } } void AddressBookPage::done(int retval) { QTableView* table = ui->tableView; if (!table->selectionModel() || !table->model()) return; // Figure out which address was selected, and return it QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address); foreach (QModelIndex index, indexes) { QVariant address = table->model()->data(index); returnValue = address.toString(); } if (returnValue.isEmpty()) { // If no address entry selected, return rejected retval = Rejected; } QDialog::done(retval); } void AddressBookPage::on_exportButton_clicked() { // CSV is currently the only supported format QString filename = GUIUtil::getSaveFileName(this, tr("Export Address List"), QString(), tr("Comma separated file (*.csv)"), NULL); if (filename.isNull()) return; CSVModelWriter writer(filename); // name, column, role writer.setModel(proxyModel); writer.addColumn("Label", AddressTableModel::Label, Qt::EditRole); writer.addColumn("Address", AddressTableModel::Address, Qt::EditRole); if (!writer.write()) { QMessageBox::critical(this, tr("Exporting Failed"), tr("There was an error trying to save the address list to %1. Please try again.").arg(filename)); } } void AddressBookPage::contextualMenu(const QPoint& point) { QModelIndex index = ui->tableView->indexAt(point); if (index.isValid()) { contextMenu->exec(QCursor::pos()); } } void AddressBookPage::selectNewAddress(const QModelIndex& parent, int begin, int /*end*/) { QModelIndex idx = proxyModel->mapFromSource(model->index(begin, AddressTableModel::Address, parent)); if (idx.isValid() && (idx.data(Qt::EditRole).toString() == newAddressToSelect)) { // Select row of newly created address, once ui->tableView->setFocus(); ui->tableView->selectRow(idx.row()); newAddressToSelect.clear(); } }
; A001585: a(n) = 3^n + n^3. ; 1,4,17,54,145,368,945,2530,7073,20412,60049,178478,533169,1596520,4785713,14352282,43050817,129145076,387426321,1162268326,3486792401,10460362464,31381070257,94143190994,282429550305,847288625068,2541865845905,7625597504670,22876792476913,68630377389272,205891132121649,617673396313738,1853020188884609,5559060566591460 mov $1,3 pow $1,$0 pow $0,3 add $1,$0
; A223443: 4-level binary fanout graph coloring a rectangular array: number of n X 2 0..14 arrays where 0..14 label nodes of a graph with edges 0,1 1,3 3,5 3,6 1,4 4,7 4,8 0,2 2,9 9,11 9,12 2,10 10,13 10,14 and every array movement to a horizontal or vertical neighbor moves along an edge of this graph. ; Submitted by Christian Krause ; 28,104,408,1616,6432,25664,102528,409856,1638912,6554624,26216448,104861696,419438592,1677737984,6710919168,26843611136,107374313472,429496991744,1717987442688,6871948722176,27487792791552,109951166971904,439804659499008,1759218621218816,7036874451320832,28147497738174464,112589990818480128,450359963005485056,1801439851485069312,7205759404866535424,28823037617318658048,115292150464979664896,461168601851328724992,1844674407388135030784,7378697629518180384768,29514790518004002062336 mov $1,2 pow $1,$0 mul $1,5 mov $0,$1 mul $1,5 add $1,3 div $1,2 mul $1,$0 mov $0,$1 div $0,10 mul $0,4
/* * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. 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. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file 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 <aws/core/client/AWSError.h> #include <aws/core/utils/HashingUtils.h> #include <aws/logs/CloudWatchLogsErrors.h> using namespace Aws::Client; using namespace Aws::CloudWatchLogs; using namespace Aws::Utils; namespace Aws { namespace CloudWatchLogs { namespace CloudWatchLogsErrorMapper { static const int INVALID_PARAMETER_HASH = HashingUtils::HashString("InvalidParameterException"); static const int OPERATION_ABORTED_HASH = HashingUtils::HashString("OperationAbortedException"); static const int INVALID_SEQUENCE_TOKEN_HASH = HashingUtils::HashString("InvalidSequenceTokenException"); static const int RESOURCE_ALREADY_EXISTS_HASH = HashingUtils::HashString("ResourceAlreadyExistsException"); static const int INVALID_OPERATION_HASH = HashingUtils::HashString("InvalidOperationException"); static const int DATA_ALREADY_ACCEPTED_HASH = HashingUtils::HashString("DataAlreadyAcceptedException"); static const int MALFORMED_QUERY_HASH = HashingUtils::HashString("MalformedQueryException"); static const int LIMIT_EXCEEDED_HASH = HashingUtils::HashString("LimitExceededException"); AWSError<CoreErrors> GetErrorForName(const char* errorName) { int hashCode = HashingUtils::HashString(errorName); if (hashCode == INVALID_PARAMETER_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(CloudWatchLogsErrors::INVALID_PARAMETER), false); } else if (hashCode == OPERATION_ABORTED_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(CloudWatchLogsErrors::OPERATION_ABORTED), false); } else if (hashCode == INVALID_SEQUENCE_TOKEN_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(CloudWatchLogsErrors::INVALID_SEQUENCE_TOKEN), false); } else if (hashCode == RESOURCE_ALREADY_EXISTS_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(CloudWatchLogsErrors::RESOURCE_ALREADY_EXISTS), false); } else if (hashCode == INVALID_OPERATION_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(CloudWatchLogsErrors::INVALID_OPERATION), false); } else if (hashCode == DATA_ALREADY_ACCEPTED_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(CloudWatchLogsErrors::DATA_ALREADY_ACCEPTED), false); } else if (hashCode == MALFORMED_QUERY_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(CloudWatchLogsErrors::MALFORMED_QUERY), false); } else if (hashCode == LIMIT_EXCEEDED_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(CloudWatchLogsErrors::LIMIT_EXCEEDED), false); } return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false); } } // namespace CloudWatchLogsErrorMapper } // namespace CloudWatchLogs } // namespace Aws
Palette_ArmorAndGloves: { ;DEDF9 LDA !RANDOM_SPRITE_FLAG : BNE .continue LDA.b #$10 : STA $BC ; Load Original Sprite Location REP #$21 LDA $7EF35B JSL $1BEDFF;Read Original Palette Code RTL .part_two SEP #$30 LDA !RANDOM_SPRITE_FLAG : BNE .continue REP #$30 LDA $7EF354 JSL $1BEE21;Read Original Palette Code RTL .continue PHX : PHY : PHA ; Load armor palette PHB : PHK : PLB REP #$20 ; Check what Link's armor value is. LDA $7EF35B : AND.w #$00FF : TAX ; (DEC06, X) LDA $1BEC06, X : AND.w #$00FF : ASL A : ADC.w #$F000 : STA $00 ;replace D308 by 7000 and search REP #$10 LDA.w #$01E2 ; Target SP-7 (sprite palette 6) LDX.w #$000E ; Palette has 15 colors TXY : TAX ;LDA $7EC178 : AND #$00FF : STA $02 LDA.b $BC : AND #$00FF : STA $02 .loop LDA [$00] : STA $7EC300, X : STA $7EC500, X INC $00 : INC $00 INX #2 DEY : BPL .loop SEP #$30 PLB INC $15 PLA : PLY : PLX RTL } change_sprite: { ;JSL $09C114 ; Restore the dungeon_resetsprites LDA !RANDOM_SPRITE_FLAG : BEQ .continue JSL GetRandomInt : AND #$1F : !ADD #$60 : STA $BC STA $7EC178 JSL Palette_ArmorAndGloves STZ $0710 .continue LDA $0E20, X : CMP.b #$61 ; Restored Code Bank06.asm(5967) ; LDA $0E20, X : CMP.b #$61 : BNE .not_beamos_laser RTL }
.global s_prepare_buffers s_prepare_buffers: push %r13 push %r15 push %r8 push %rax push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_WT_ht+0x906d, %rdx nop inc %rbp mov (%rdx), %r8d nop nop nop cmp $3779, %r13 lea addresses_normal_ht+0x48ed, %rsi nop nop nop nop inc %r8 mov (%rsi), %ebp nop nop cmp $5022, %r8 lea addresses_WT_ht+0xb8ed, %rax nop nop inc %r15 mov $0x6162636465666768, %r8 movq %r8, %xmm3 movups %xmm3, (%rax) nop nop nop cmp %rbp, %rbp lea addresses_D_ht+0xe0ed, %r13 nop add %rsi, %rsi movl $0x61626364, (%r13) nop nop nop xor $14235, %r8 lea addresses_WT_ht+0xfead, %rax nop nop inc %rsi vmovups (%rax), %ymm1 vextracti128 $1, %ymm1, %xmm1 vpextrq $0, %xmm1, %r13 sub %rbp, %rbp lea addresses_normal_ht+0x18dc9, %rdx xor $25719, %rbp mov $0x6162636465666768, %rsi movq %rsi, %xmm7 movups %xmm7, (%rdx) nop and $6955, %r13 lea addresses_WC_ht+0x1a345, %rsi lea addresses_A_ht+0xa85d, %rdi nop nop nop add %r13, %r13 mov $4, %rcx rep movsl nop nop nop nop cmp %rax, %rax pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %rax pop %r8 pop %r15 pop %r13 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %rax push %rbp push %rdi push %rdx // Faulty Load lea addresses_A+0x1c0ed, %rbp nop nop and %rax, %rax movb (%rbp), %r11b lea oracles, %rbp and $0xff, %r11 shlq $12, %r11 mov (%rbp,%r11,1), %r11 pop %rdx pop %rdi pop %rbp pop %rax pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_A', 'same': False, 'size': 4, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_A', 'same': True, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 4, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_normal_ht', 'same': False, 'size': 4, 'congruent': 11, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 16, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_D_ht', 'same': False, 'size': 4, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 32, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_normal_ht', 'same': False, 'size': 16, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM'} {'35': 21829} 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 */
; unsigned char *p3dos_copy_cstr_to_pstr(char *pdst, const char *csrc) SECTION code_esxdos PUBLIC p3dos_copy_cstr_to_pstr EXTERN asm_p3dos_copy_cstr_to_pstr p3dos_copy_cstr_to_pstr: pop af pop hl pop de push de push hl push af jp asm_p3dos_copy_cstr_to_pstr
;***************************************************************************** ;* x86util.asm ;***************************************************************************** ;* Copyright (C) 2008-2010 x264 project ;* ;* Authors: Loren Merritt <lorenm@u.washington.edu> ;* Holger Lubitz <holger@lubitz.org> ;* ;* This file is part of FFmpeg. ;* ;* FFmpeg is free software; you can redistribute it and/or ;* modify it under the terms of the GNU Lesser General Public ;* License as published by the Free Software Foundation; either ;* version 2.1 of the License, or (at your option) any later version. ;* ;* FFmpeg is distributed in the hope that it will be useful, ;* but WITHOUT ANY WARRANTY; without even the implied warranty of ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;* Lesser General Public License for more details. ;* ;* You should have received a copy of the GNU Lesser General Public ;* License along with FFmpeg; if not, write to the Free Software ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;****************************************************************************** %define private_prefix ff %define public_prefix avpriv %define cpuflags_mmxext cpuflags_mmx2 %include "libavutil/x86/x86inc.asm" ; expands to [base],...,[base+7*stride] %define PASS8ROWS(base, base3, stride, stride3) \ [base], [base + stride], [base + 2*stride], [base3], \ [base3 + stride], [base3 + 2*stride], [base3 + stride3], [base3 + stride*4] ; Interleave low src0 with low src1 and store in src0, ; interleave high src0 with high src1 and store in src1. ; %1 - types ; %2 - index of the register with src0 ; %3 - index of the register with src1 ; %4 - index of the register for intermediate results ; example for %1 - wd: input: src0: x0 x1 x2 x3 z0 z1 z2 z3 ; src1: y0 y1 y2 y3 q0 q1 q2 q3 ; output: src0: x0 y0 x1 y1 x2 y2 x3 y3 ; src1: z0 q0 z1 q1 z2 q2 z3 q3 %macro SBUTTERFLY 4 %ifidn %1, dqqq vperm2i128 m%4, m%2, m%3, q0301 vinserti128 m%2, m%2, xm%3, 1 %elif avx_enabled == 0 mova m%4, m%2 punpckl%1 m%2, m%3 punpckh%1 m%4, m%3 %else punpckh%1 m%4, m%2, m%3 punpckl%1 m%2, m%3 %endif SWAP %3, %4 %endmacro %macro SBUTTERFLY2 4 punpckl%1 m%4, m%2, m%3 punpckh%1 m%2, m%2, m%3 SWAP %2, %4, %3 %endmacro %macro SBUTTERFLYPS 3 unpcklps m%3, m%1, m%2 unpckhps m%1, m%1, m%2 SWAP %1, %3, %2 %endmacro %macro SBUTTERFLYPD 3 movlhps m%3, m%1, m%2 movhlps m%2, m%2, m%1 SWAP %1, %3 %endmacro %macro TRANSPOSE4x4B 5 SBUTTERFLY bw, %1, %2, %5 SBUTTERFLY bw, %3, %4, %5 SBUTTERFLY wd, %1, %3, %5 SBUTTERFLY wd, %2, %4, %5 SWAP %2, %3 %endmacro %macro TRANSPOSE4x4W 5 SBUTTERFLY wd, %1, %2, %5 SBUTTERFLY wd, %3, %4, %5 SBUTTERFLY dq, %1, %3, %5 SBUTTERFLY dq, %2, %4, %5 SWAP %2, %3 %endmacro %macro TRANSPOSE2x4x4B 5 SBUTTERFLY bw, %1, %2, %5 SBUTTERFLY bw, %3, %4, %5 SBUTTERFLY wd, %1, %3, %5 SBUTTERFLY wd, %2, %4, %5 SBUTTERFLY dq, %1, %2, %5 SBUTTERFLY dq, %3, %4, %5 %endmacro %macro TRANSPOSE2x4x4W 5 SBUTTERFLY wd, %1, %2, %5 SBUTTERFLY wd, %3, %4, %5 SBUTTERFLY dq, %1, %3, %5 SBUTTERFLY dq, %2, %4, %5 SBUTTERFLY qdq, %1, %2, %5 SBUTTERFLY qdq, %3, %4, %5 %endmacro %macro TRANSPOSE4x4D 5 SBUTTERFLY dq, %1, %2, %5 SBUTTERFLY dq, %3, %4, %5 SBUTTERFLY qdq, %1, %3, %5 SBUTTERFLY qdq, %2, %4, %5 SWAP %2, %3 %endmacro ; identical behavior to TRANSPOSE4x4D, but using SSE1 float ops %macro TRANSPOSE4x4PS 5 SBUTTERFLYPS %1, %2, %5 SBUTTERFLYPS %3, %4, %5 SBUTTERFLYPD %1, %3, %5 SBUTTERFLYPD %2, %4, %5 SWAP %2, %3 %endmacro %macro TRANSPOSE8x4D 9-11 %if ARCH_X86_64 SBUTTERFLY dq, %1, %2, %9 SBUTTERFLY dq, %3, %4, %9 SBUTTERFLY dq, %5, %6, %9 SBUTTERFLY dq, %7, %8, %9 SBUTTERFLY qdq, %1, %3, %9 SBUTTERFLY qdq, %2, %4, %9 SBUTTERFLY qdq, %5, %7, %9 SBUTTERFLY qdq, %6, %8, %9 SWAP %2, %5 SWAP %4, %7 %else ; in: m0..m7 ; out: m0..m7, unless %11 in which case m2 is in %9 ; spills into %9 and %10 movdqa %9, m%7 SBUTTERFLY dq, %1, %2, %7 movdqa %10, m%2 movdqa m%7, %9 SBUTTERFLY dq, %3, %4, %2 SBUTTERFLY dq, %5, %6, %2 SBUTTERFLY dq, %7, %8, %2 SBUTTERFLY qdq, %1, %3, %2 movdqa %9, m%3 movdqa m%2, %10 SBUTTERFLY qdq, %2, %4, %3 SBUTTERFLY qdq, %5, %7, %3 SBUTTERFLY qdq, %6, %8, %3 SWAP %2, %5 SWAP %4, %7 %if %0<11 movdqa m%3, %9 %endif %endif %endmacro %macro TRANSPOSE8x8W 9-11 %if ARCH_X86_64 SBUTTERFLY wd, %1, %2, %9 SBUTTERFLY wd, %3, %4, %9 SBUTTERFLY wd, %5, %6, %9 SBUTTERFLY wd, %7, %8, %9 SBUTTERFLY dq, %1, %3, %9 SBUTTERFLY dq, %2, %4, %9 SBUTTERFLY dq, %5, %7, %9 SBUTTERFLY dq, %6, %8, %9 SBUTTERFLY qdq, %1, %5, %9 SBUTTERFLY qdq, %2, %6, %9 SBUTTERFLY qdq, %3, %7, %9 SBUTTERFLY qdq, %4, %8, %9 SWAP %2, %5 SWAP %4, %7 %else ; in: m0..m7, unless %11 in which case m6 is in %9 ; out: m0..m7, unless %11 in which case m4 is in %10 ; spills into %9 and %10 %if %0<11 movdqa %9, m%7 %endif SBUTTERFLY wd, %1, %2, %7 movdqa %10, m%2 movdqa m%7, %9 SBUTTERFLY wd, %3, %4, %2 SBUTTERFLY wd, %5, %6, %2 SBUTTERFLY wd, %7, %8, %2 SBUTTERFLY dq, %1, %3, %2 movdqa %9, m%3 movdqa m%2, %10 SBUTTERFLY dq, %2, %4, %3 SBUTTERFLY dq, %5, %7, %3 SBUTTERFLY dq, %6, %8, %3 SBUTTERFLY qdq, %1, %5, %3 SBUTTERFLY qdq, %2, %6, %3 movdqa %10, m%2 movdqa m%3, %9 SBUTTERFLY qdq, %3, %7, %2 SBUTTERFLY qdq, %4, %8, %2 SWAP %2, %5 SWAP %4, %7 %if %0<11 movdqa m%5, %10 %endif %endif %endmacro %macro TRANSPOSE16x16W 18-19 ; in: m0..m15, unless %19 in which case m6 is in %17 ; out: m0..m15, unless %19 in which case m4 is in %18 ; spills into %17 and %18 %if %0 < 19 mova %17, m%7 %endif SBUTTERFLY dqqq, %1, %9, %7 SBUTTERFLY dqqq, %2, %10, %7 SBUTTERFLY dqqq, %3, %11, %7 SBUTTERFLY dqqq, %4, %12, %7 SBUTTERFLY dqqq, %5, %13, %7 SBUTTERFLY dqqq, %6, %14, %7 mova %18, m%14 mova m%7, %17 SBUTTERFLY dqqq, %7, %15, %14 SBUTTERFLY dqqq, %8, %16, %14 SBUTTERFLY wd, %1, %2, %14 SBUTTERFLY wd, %3, %4, %14 SBUTTERFLY wd, %5, %6, %14 SBUTTERFLY wd, %7, %8, %14 SBUTTERFLY wd, %9, %10, %14 SBUTTERFLY wd, %11, %12, %14 mova %17, m%12 mova m%14, %18 SBUTTERFLY wd, %13, %14, %12 SBUTTERFLY wd, %15, %16, %12 SBUTTERFLY dq, %1, %3, %12 SBUTTERFLY dq, %2, %4, %12 SBUTTERFLY dq, %5, %7, %12 SBUTTERFLY dq, %6, %8, %12 SBUTTERFLY dq, %9, %11, %12 mova %18, m%11 mova m%12, %17 SBUTTERFLY dq, %10, %12, %11 SBUTTERFLY dq, %13, %15, %11 SBUTTERFLY dq, %14, %16, %11 SBUTTERFLY qdq, %1, %5, %11 SBUTTERFLY qdq, %2, %6, %11 SBUTTERFLY qdq, %3, %7, %11 SBUTTERFLY qdq, %4, %8, %11 SWAP %2, %5 SWAP %4, %7 SBUTTERFLY qdq, %9, %13, %11 SBUTTERFLY qdq, %10, %14, %11 mova m%11, %18 mova %18, m%5 SBUTTERFLY qdq, %11, %15, %5 SBUTTERFLY qdq, %12, %16, %5 %if %0 < 19 mova m%5, %18 %endif SWAP %10, %13 SWAP %12, %15 %endmacro %macro TRANSPOSE_8X8B 8 %if mmsize == 8 %error "This macro does not support mmsize == 8" %endif punpcklbw m%1, m%2 punpcklbw m%3, m%4 punpcklbw m%5, m%6 punpcklbw m%7, m%8 TRANSPOSE4x4W %1, %3, %5, %7, %2 MOVHL m%2, m%1 MOVHL m%4, m%3 MOVHL m%6, m%5 MOVHL m%8, m%7 %endmacro ; PABSW macro assumes %1 != %2, while ABS1/2 macros work in-place %macro PABSW 2 %if cpuflag(ssse3) pabsw %1, %2 %elif cpuflag(mmxext) pxor %1, %1 psubw %1, %2 pmaxsw %1, %2 %else pxor %1, %1 pcmpgtw %1, %2 pxor %2, %1 psubw %2, %1 SWAP %1, %2 %endif %endmacro %macro PSIGNW 2 %if cpuflag(ssse3) psignw %1, %2 %else pxor %1, %2 psubw %1, %2 %endif %endmacro %macro ABS1 2 %if cpuflag(ssse3) pabsw %1, %1 %elif cpuflag(mmxext) ; a, tmp pxor %2, %2 psubw %2, %1 pmaxsw %1, %2 %else ; a, tmp pxor %2, %2 pcmpgtw %2, %1 pxor %1, %2 psubw %1, %2 %endif %endmacro %macro ABS2 4 %if cpuflag(ssse3) pabsw %1, %1 pabsw %2, %2 %elif cpuflag(mmxext) ; a, b, tmp0, tmp1 pxor %3, %3 pxor %4, %4 psubw %3, %1 psubw %4, %2 pmaxsw %1, %3 pmaxsw %2, %4 %else ; a, b, tmp0, tmp1 pxor %3, %3 pxor %4, %4 pcmpgtw %3, %1 pcmpgtw %4, %2 pxor %1, %3 pxor %2, %4 psubw %1, %3 psubw %2, %4 %endif %endmacro %macro ABSB 2 ; source mmreg, temp mmreg (unused for ssse3) %if cpuflag(ssse3) pabsb %1, %1 %else pxor %2, %2 psubb %2, %1 pminub %1, %2 %endif %endmacro %macro ABSB2 4 ; src1, src2, tmp1, tmp2 (tmp1/2 unused for SSSE3) %if cpuflag(ssse3) pabsb %1, %1 pabsb %2, %2 %else pxor %3, %3 pxor %4, %4 psubb %3, %1 psubb %4, %2 pminub %1, %3 pminub %2, %4 %endif %endmacro %macro ABSD2_MMX 4 pxor %3, %3 pxor %4, %4 pcmpgtd %3, %1 pcmpgtd %4, %2 pxor %1, %3 pxor %2, %4 psubd %1, %3 psubd %2, %4 %endmacro %macro ABS4 6 ABS2 %1, %2, %5, %6 ABS2 %3, %4, %5, %6 %endmacro %macro SPLATB_LOAD 3 %if cpuflag(ssse3) movd %1, [%2-3] pshufb %1, %3 %else movd %1, [%2-3] ;to avoid crossing a cacheline punpcklbw %1, %1 SPLATW %1, %1, 3 %endif %endmacro %macro SPLATB_REG 3 %if cpuflag(ssse3) movd %1, %2d pshufb %1, %3 %else movd %1, %2d punpcklbw %1, %1 SPLATW %1, %1, 0 %endif %endmacro %macro HADDD 2 ; sum junk %if sizeof%1 == 32 %define %2 xmm%2 vextracti128 %2, %1, 1 %define %1 xmm%1 paddd %1, %2 %endif %if mmsize >= 16 %if cpuflag(xop) && sizeof%1 == 16 vphadddq %1, %1 %endif movhlps %2, %1 paddd %1, %2 %endif %if notcpuflag(xop) || sizeof%1 != 16 %if cpuflag(mmxext) PSHUFLW %2, %1, q0032 %else ; mmx mova %2, %1 psrlq %2, 32 %endif paddd %1, %2 %endif %undef %1 %undef %2 %endmacro %macro HADDW 2 ; reg, tmp %if cpuflag(xop) && sizeof%1 == 16 vphaddwq %1, %1 movhlps %2, %1 paddd %1, %2 %else pmaddwd %1, [pw_1] HADDD %1, %2 %endif %endmacro %macro HADDPS 3 ; dst, src, tmp %if cpuflag(sse3) haddps %1, %1, %2 %else movaps %3, %1 shufps %1, %2, q2020 shufps %3, %2, q3131 addps %1, %3 %endif %endmacro %macro PALIGNR 4-5 %if cpuflag(ssse3) %if %0==5 palignr %1, %2, %3, %4 %else palignr %1, %2, %3 %endif %elif cpuflag(mmx) ; [dst,] src1, src2, imm, tmp %define %%dst %1 %if %0==5 %ifnidn %1, %2 mova %%dst, %2 %endif %rotate 1 %endif %ifnidn %4, %2 mova %4, %2 %endif %if mmsize==8 psllq %%dst, (8-%3)*8 psrlq %4, %3*8 %else pslldq %%dst, 16-%3 psrldq %4, %3 %endif por %%dst, %4 %endif %endmacro %macro PAVGB 2-4 %if cpuflag(mmxext) pavgb %1, %2 %elif cpuflag(3dnow) pavgusb %1, %2 %elif cpuflag(mmx) movu %3, %2 por %3, %1 pxor %1, %2 pand %1, %4 psrlq %1, 1 psubb %3, %1 SWAP %1, %3 %endif %endmacro %macro PSHUFLW 1+ %if mmsize == 8 pshufw %1 %else pshuflw %1 %endif %endmacro %macro PSWAPD 2 %if cpuflag(mmxext) pshufw %1, %2, q1032 %elif cpuflag(3dnowext) pswapd %1, %2 %elif cpuflag(3dnow) movq %1, %2 psrlq %1, 32 punpckldq %1, %2 %endif %endmacro %macro DEINTB 5 ; mask, reg1, mask, reg2, optional src to fill masks from %ifnum %5 pand m%3, m%5, m%4 ; src .. y6 .. y4 pand m%1, m%5, m%2 ; dst .. y6 .. y4 %else mova m%1, %5 pand m%3, m%1, m%4 ; src .. y6 .. y4 pand m%1, m%1, m%2 ; dst .. y6 .. y4 %endif psrlw m%2, 8 ; dst .. y7 .. y5 psrlw m%4, 8 ; src .. y7 .. y5 %endmacro %macro SUMSUB_BA 3-4 %if %0==3 padd%1 m%2, m%3 padd%1 m%3, m%3 psub%1 m%3, m%2 %else %if avx_enabled == 0 mova m%4, m%2 padd%1 m%2, m%3 psub%1 m%3, m%4 %else padd%1 m%4, m%2, m%3 psub%1 m%3, m%2 SWAP %2, %4 %endif %endif %endmacro %macro SUMSUB_BADC 5-6 %if %0==6 SUMSUB_BA %1, %2, %3, %6 SUMSUB_BA %1, %4, %5, %6 %else padd%1 m%2, m%3 padd%1 m%4, m%5 padd%1 m%3, m%3 padd%1 m%5, m%5 psub%1 m%3, m%2 psub%1 m%5, m%4 %endif %endmacro %macro SUMSUB2_AB 4 %ifnum %3 psub%1 m%4, m%2, m%3 psub%1 m%4, m%3 padd%1 m%2, m%2 padd%1 m%2, m%3 %else mova m%4, m%2 padd%1 m%2, m%2 padd%1 m%2, %3 psub%1 m%4, %3 psub%1 m%4, %3 %endif %endmacro %macro SUMSUB2_BA 4 %if avx_enabled == 0 mova m%4, m%2 padd%1 m%2, m%3 padd%1 m%2, m%3 psub%1 m%3, m%4 psub%1 m%3, m%4 %else padd%1 m%4, m%2, m%3 padd%1 m%4, m%3 psub%1 m%3, m%2 psub%1 m%3, m%2 SWAP %2, %4 %endif %endmacro %macro SUMSUBD2_AB 5 %ifnum %4 psra%1 m%5, m%2, 1 ; %3: %3>>1 psra%1 m%4, m%3, 1 ; %2: %2>>1 padd%1 m%4, m%2 ; %3: %3>>1+%2 psub%1 m%5, m%3 ; %2: %2>>1-%3 SWAP %2, %5 SWAP %3, %4 %else mova %5, m%2 mova %4, m%3 psra%1 m%3, 1 ; %3: %3>>1 psra%1 m%2, 1 ; %2: %2>>1 padd%1 m%3, %5 ; %3: %3>>1+%2 psub%1 m%2, %4 ; %2: %2>>1-%3 %endif %endmacro %macro DCT4_1D 5 %ifnum %5 SUMSUB_BADC w, %4, %1, %3, %2, %5 SUMSUB_BA w, %3, %4, %5 SUMSUB2_AB w, %1, %2, %5 SWAP %1, %3, %4, %5, %2 %else SUMSUB_BADC w, %4, %1, %3, %2 SUMSUB_BA w, %3, %4 mova [%5], m%2 SUMSUB2_AB w, %1, [%5], %2 SWAP %1, %3, %4, %2 %endif %endmacro %macro IDCT4_1D 6-7 %ifnum %6 SUMSUBD2_AB %1, %3, %5, %7, %6 ; %3: %3>>1-%5 %5: %3+%5>>1 SUMSUB_BA %1, %4, %2, %7 ; %4: %2+%4 %2: %2-%4 SUMSUB_BADC %1, %5, %4, %3, %2, %7 ; %5: %2+%4 + (%3+%5>>1) ; %4: %2+%4 - (%3+%5>>1) ; %3: %2-%4 + (%3>>1-%5) ; %2: %2-%4 - (%3>>1-%5) %else %ifidn %1, w SUMSUBD2_AB %1, %3, %5, [%6], [%6+16] %else SUMSUBD2_AB %1, %3, %5, [%6], [%6+32] %endif SUMSUB_BA %1, %4, %2 SUMSUB_BADC %1, %5, %4, %3, %2 %endif SWAP %2, %5, %4 ; %2: %2+%4 + (%3+%5>>1) row0 ; %3: %2-%4 + (%3>>1-%5) row1 ; %4: %2-%4 - (%3>>1-%5) row2 ; %5: %2+%4 - (%3+%5>>1) row3 %endmacro %macro LOAD_DIFF 5 %ifidn %3, none movh %1, %4 movh %2, %5 punpcklbw %1, %2 punpcklbw %2, %2 psubw %1, %2 %else movh %1, %4 punpcklbw %1, %3 movh %2, %5 punpcklbw %2, %3 psubw %1, %2 %endif %endmacro %macro STORE_DCT 6 movq [%5+%6+ 0], m%1 movq [%5+%6+ 8], m%2 movq [%5+%6+16], m%3 movq [%5+%6+24], m%4 movhps [%5+%6+32], m%1 movhps [%5+%6+40], m%2 movhps [%5+%6+48], m%3 movhps [%5+%6+56], m%4 %endmacro %macro LOAD_DIFF_8x4P 7-10 r0,r2,0 ; 4x dest, 2x temp, 2x pointer, increment? LOAD_DIFF m%1, m%5, m%7, [%8], [%9] LOAD_DIFF m%2, m%6, m%7, [%8+r1], [%9+r3] LOAD_DIFF m%3, m%5, m%7, [%8+2*r1], [%9+2*r3] LOAD_DIFF m%4, m%6, m%7, [%8+r4], [%9+r5] %if %10 lea %8, [%8+4*r1] lea %9, [%9+4*r3] %endif %endmacro %macro DIFFx2 6-7 movh %3, %5 punpcklbw %3, %4 psraw %1, 6 paddsw %1, %3 movh %3, %6 punpcklbw %3, %4 psraw %2, 6 paddsw %2, %3 packuswb %2, %1 %endmacro %macro STORE_DIFF 4 movh %2, %4 punpcklbw %2, %3 psraw %1, 6 paddsw %1, %2 packuswb %1, %1 movh %4, %1 %endmacro %macro STORE_DIFFx2 8 ; add1, add2, reg1, reg2, zero, shift, source, stride movh %3, [%7] movh %4, [%7+%8] psraw %1, %6 psraw %2, %6 punpcklbw %3, %5 punpcklbw %4, %5 paddw %3, %1 paddw %4, %2 packuswb %3, %5 packuswb %4, %5 movh [%7], %3 movh [%7+%8], %4 %endmacro %macro PMINUB 3 ; dst, src, ignored %if cpuflag(mmxext) pminub %1, %2 %else ; dst, src, tmp mova %3, %1 psubusb %3, %2 psubb %1, %3 %endif %endmacro %macro SPLATW 2-3 0 %if cpuflag(avx2) && %3 == 0 vpbroadcastw %1, %2 %elif mmsize == 16 pshuflw %1, %2, (%3)*0x55 punpcklqdq %1, %1 %elif cpuflag(mmxext) pshufw %1, %2, (%3)*0x55 %else %ifnidn %1, %2 mova %1, %2 %endif %if %3 & 2 punpckhwd %1, %1 %else punpcklwd %1, %1 %endif %if %3 & 1 punpckhwd %1, %1 %else punpcklwd %1, %1 %endif %endif %endmacro %macro SPLATD 1 %if mmsize == 8 punpckldq %1, %1 %elif cpuflag(sse2) pshufd %1, %1, 0 %elif cpuflag(sse) shufps %1, %1, 0 %endif %endmacro %macro CLIPUB 3 ;(dst, min, max) pmaxub %1, %2 pminub %1, %3 %endmacro %macro CLIPW 3 ;(dst, min, max) pmaxsw %1, %2 pminsw %1, %3 %endmacro %macro PMINSD_MMX 3 ; dst, src, tmp mova %3, %2 pcmpgtd %3, %1 pxor %1, %2 pand %1, %3 pxor %1, %2 %endmacro %macro PMAXSD_MMX 3 ; dst, src, tmp mova %3, %1 pcmpgtd %3, %2 pand %1, %3 pandn %3, %2 por %1, %3 %endmacro %macro CLIPD_MMX 3-4 ; src/dst, min, max, tmp PMINSD_MMX %1, %3, %4 PMAXSD_MMX %1, %2, %4 %endmacro %macro CLIPD_SSE2 3-4 ; src/dst, min (float), max (float), unused cvtdq2ps %1, %1 minps %1, %3 maxps %1, %2 cvtps2dq %1, %1 %endmacro %macro CLIPD_SSE41 3-4 ; src/dst, min, max, unused pminsd %1, %3 pmaxsd %1, %2 %endmacro %macro VBROADCASTSS 2 ; dst xmm/ymm, src m32/xmm %if cpuflag(avx2) vbroadcastss %1, %2 %elif cpuflag(avx) %ifnum sizeof%2 ; avx1 register shufps xmm%1, xmm%2, xmm%2, q0000 %if sizeof%1 >= 32 ; mmsize>=32 vinsertf128 %1, %1, xmm%1, 1 %endif %else ; avx1 memory vbroadcastss %1, %2 %endif %else %ifnum sizeof%2 ; sse register shufps %1, %2, %2, q0000 %else ; sse memory movss %1, %2 shufps %1, %1, 0 %endif %endif %endmacro %macro VBROADCASTSD 2 ; dst xmm/ymm, src m64 %if cpuflag(avx) && mmsize == 32 vbroadcastsd %1, %2 %elif cpuflag(sse3) movddup %1, %2 %else ; sse2 movsd %1, %2 movlhps %1, %1 %endif %endmacro %macro VPBROADCASTD 2 ; dst xmm/ymm, src m32/xmm %if cpuflag(avx2) vpbroadcastd %1, %2 %elif cpuflag(avx) && sizeof%1 >= 32 %error vpbroadcastd not possible with ymm on avx1. try vbroadcastss %else %ifnum sizeof%2 ; sse2 register pshufd %1, %2, q0000 %else ; sse memory movd %1, %2 pshufd %1, %1, 0 %endif %endif %endmacro %macro SHUFFLE_MASK_W 8 %rep 8 %if %1>=0x80 db %1, %1 %else db %1*2 db %1*2+1 %endif %rotate 1 %endrep %endmacro %macro PMOVSXWD 2; dst, src %if cpuflag(sse4) pmovsxwd %1, %2 %else %ifnidn %1, %2 mova %1, %2 %endif punpcklwd %1, %1 psrad %1, 16 %endif %endmacro ; Wrapper for non-FMA version of fmaddps %macro FMULADD_PS 5 %if cpuflag(fma3) || cpuflag(fma4) fmaddps %1, %2, %3, %4 %elifidn %1, %4 mulps %5, %2, %3 addps %1, %4, %5 %else mulps %1, %2, %3 addps %1, %4 %endif %endmacro %macro LSHIFT 2 %if mmsize > 8 pslldq %1, %2 %else psllq %1, 8*(%2) %endif %endmacro %macro RSHIFT 2 %if mmsize > 8 psrldq %1, %2 %else psrlq %1, 8*(%2) %endif %endmacro %macro MOVHL 2 ; dst, src %ifidn %1, %2 punpckhqdq %1, %2 %elif cpuflag(avx) punpckhqdq %1, %2, %2 %elif cpuflag(sse4) pshufd %1, %2, q3232 ; pshufd is slow on some older CPUs, so only use it on more modern ones %else movhlps %1, %2 ; may cause an int/float domain transition and has a dependency on dst %endif %endmacro ; Horizontal Sum of Packed Single precision floats ; The resulting sum is in all elements. %macro HSUMPS 2 ; dst/src, tmp %if cpuflag(avx) %if sizeof%1>=32 ; avx vperm2f128 %2, %1, %1, (0)*16+(1) addps %1, %2 %endif shufps %2, %1, %1, q1032 addps %1, %2 shufps %2, %1, %1, q0321 addps %1, %2 %else ; this form is a bit faster than the short avx-like emulation. movaps %2, %1 shufps %1, %1, q1032 addps %1, %2 movaps %2, %1 shufps %1, %1, q0321 addps %1, %2 ; all %1 members should be equal for as long as float a+b==b+a %endif %endmacro ; Emulate blendvps if not available ; ; src_b is destroyed when using emulation with logical operands ; SSE41 blendv instruction is hard coded to use xmm0 as mask %macro BLENDVPS 3 ; dst/src_a, src_b, mask %if cpuflag(avx) blendvps %1, %1, %2, %3 %elif cpuflag(sse4) %ifnidn %3,xmm0 %error sse41 blendvps uses xmm0 as default 3d operand, you used %3 %endif blendvps %1, %2, %3 %else xorps %2, %1 andps %2, %3 xorps %1, %2 %endif %endmacro ; Emulate pblendvb if not available ; ; src_b is destroyed when using emulation with logical operands ; SSE41 blendv instruction is hard coded to use xmm0 as mask %macro PBLENDVB 3 ; dst/src_a, src_b, mask %if cpuflag(avx) %if cpuflag(avx) && notcpuflag(avx2) && sizeof%1 >= 32 %error pblendb not possible with ymm on avx1, try blendvps. %endif pblendvb %1, %1, %2, %3 %elif cpuflag(sse4) %ifnidn %3,xmm0 %error sse41 pblendvd uses xmm0 as default 3d operand, you used %3 %endif pblendvb %1, %2, %3 %else pxor %2, %1 pand %2, %3 pxor %1, %2 %endif %endmacro
; A186302: ( A007522(n)-1 )/2. ; Submitted by Jon Maiga ; 3,11,15,23,35,39,51,63,75,83,95,99,111,119,131,135,155,179,183,191,215,219,231,239,243,251,299,303,315,323,359,363,371,375,411,419,431,443,455,459,483,491,495,515,519,531,543,551 mov $1,6 mov $2,$0 add $2,3 pow $2,2 lpb $2 sub $2,1 mov $3,$1 seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0. sub $0,$3 add $1,8 mov $4,$0 max $4,0 cmp $4,$0 mul $2,$4 lpe mov $0,$1 div $0,2 sub $0,4
; A001701: Generalized Stirling numbers. ; 1,6,26,71,155,295,511,826,1266,1860,2640,3641,4901,6461,8365,10660,13396,16626,20406,24795,29855,35651,42251,49726,58150,67600,78156,89901,102921,117305,133145,150536,169576,190366,213010,237615,264291,293151,324311,357890,394010,432796,474376,518881,566445,617205,671301,728876,790076,855050,923950,996931,1074151,1155771,1241955,1332870,1428686,1529576,1635716,1747285,1864465,1987441,2116401,2251536,2393040,2541110,2695946,2857751,3026731,3203095,3387055,3578826,3778626,3986676,4203200,4428425,4662581,4905901,5158621,5420980,5693220,5975586,6268326,6571691,6885935,7211315,7548091,7896526,8256886,8629440,9014460,9412221,9823001,10247081,10684745,11136280,11601976,12082126,12577026,13086975 mov $1,1 trn $1,$0 lpb $0 add $3,$0 sub $0,1 add $2,$3 add $2,5 add $1,$2 add $3,4 lpe mov $0,$1
; A017153: a(n) = (8*n + 7)^5. ; 16807,759375,6436343,28629151,90224199,229345007,503284375,992436543,1804229351,3077056399,4984209207,7737809375,11592740743,16850581551,23863536599,33038369407,44840334375,59797108943,78502725751,101621504799,129891985607,164130859375,205236901143,254194901951,312079600999,380059617807,459401384375,551473077343,657748550151,779811265199,919358226007,1078203909375,1258284197543,1461660310351,1690522737399,1947195170207,2234138434375,2553954421743,2909390022551,3303341057599,3738856210407 mul $0,8 add $0,7 pow $0,5
; A008580: Crystal ball sequence for planar net 3.6.3.6. ; 1,5,13,27,45,67,95,125,163,201,249,295,353,407,475,537,615,685,773,851,949,1035,1143,1237,1355,1457,1585,1695,1833,1951,2099,2225,2383,2517,2685,2827,3005,3155,3343,3501,3699,3865,4073,4247,4465,4647,4875,5065,5303,5501,5749,5955,6213,6427,6695,6917,7195,7425,7713,7951,8249,8495,8803,9057,9375,9637,9965,10235,10573,10851,11199,11485,11843,12137,12505,12807,13185,13495,13883,14201,14599,14925,15333,15667,16085,16427,16855,17205,17643,18001,18449,18815,19273,19647,20115,20497,20975,21365,21853,22251,22749,23155,23663,24077,24595,25017,25545,25975,26513,26951,27499,27945,28503,28957,29525,29987,30565,31035,31623,32101,32699,33185,33793,34287,34905,35407,36035,36545,37183,37701,38349,38875,39533,40067,40735,41277,41955,42505,43193,43751,44449,45015,45723,46297,47015,47597,48325,48915,49653,50251,50999,51605,52363,52977,53745,54367,55145,55775,56563,57201,57999,58645,59453,60107,60925,61587,62415,63085,63923,64601,65449,66135,66993,67687,68555,69257,70135,70845,71733,72451,73349,74075,74983,75717,76635,77377,78305,79055,79993,80751,81699,82465,83423,84197,85165,85947,86925,87715,88703,89501,90499,91305,92313,93127,94145,94967,95995,96825,97863,98701,99749,100595,101653,102507,103575,104437,105515,106385,107473,108351,109449,110335,111443,112337,113455,114357,115485,116395,117533,118451,119599,120525,121683,122617,123785,124727,125905,126855,128043,129001,130199,131165,132373,133347,134565,135547,136775,137765,139003,140001 mov $5,$0 lpb $0 add $0,1 add $1,3 add $3,1 mov $2,$3 mov $3,$1 trn $3,$0 sub $0,1 add $2,$0 add $3,$0 sub $0,1 mov $1,$2 lpe add $1,1 mov $6,$5 mov $8,$5 lpb $8 add $7,$6 sub $8,1 lpe mov $4,2 mov $6,$7 lpb $4 add $1,$6 sub $4,1 lpe
#include "selfdrive/ui/qt/offroad/networking.h" #include <QDebug> #include <QHBoxLayout> #include <QLabel> #include <QPainter> #include "selfdrive/ui/qt/widgets/scrollview.h" #include "selfdrive/ui/qt/util.h" void NetworkStrengthWidget::paintEvent(QPaintEvent* event) { QPainter p(this); p.setRenderHint(QPainter::Antialiasing); p.setPen(Qt::NoPen); const QColor gray(0x54, 0x54, 0x54); for (int i = 0, x = 0; i < 5; ++i) { p.setBrush(i < strength_ ? Qt::white : gray); p.drawEllipse(x, 0, 15, 15); x += 20; } } // Networking functions Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent), show_advanced(show_advanced){ s = new QStackedLayout; QLabel* warning = new QLabel("Network manager is inactive!"); warning->setAlignment(Qt::AlignCenter); warning->setStyleSheet(R"(font-size: 65px;)"); s->addWidget(warning); setLayout(s); QTimer* timer = new QTimer(this); QObject::connect(timer, &QTimer::timeout, this, &Networking::refresh); timer->start(5000); attemptInitialization(); } void Networking::attemptInitialization(){ // Checks if network manager is active try { wifi = new WifiManager(this); } catch (std::exception &e) { return; } connect(wifi, &WifiManager::wrongPassword, this, &Networking::wrongPassword); QVBoxLayout* vlayout = new QVBoxLayout; if (show_advanced) { QPushButton* advancedSettings = new QPushButton("Advanced"); advancedSettings->setStyleSheet("margin-right: 30px;"); advancedSettings->setFixedSize(350, 100); connect(advancedSettings, &QPushButton::released, [=](){ s->setCurrentWidget(an); }); vlayout->addSpacing(10); vlayout->addWidget(advancedSettings, 0, Qt::AlignRight); vlayout->addSpacing(10); } wifiWidget = new WifiUI(this, wifi); connect(wifiWidget, &WifiUI::connectToNetwork, this, &Networking::connectToNetwork); vlayout->addWidget(new ScrollView(wifiWidget, this), 1); QWidget* wifiScreen = new QWidget(this); wifiScreen->setLayout(vlayout); s->addWidget(wifiScreen); an = new AdvancedNetworking(this, wifi); connect(an, &AdvancedNetworking::backPress, [=](){s->setCurrentWidget(wifiScreen);}); s->addWidget(an); setStyleSheet(R"( QPushButton { font-size: 50px; margin: 0px; padding: 15px; border-width: 0; border-radius: 30px; color: #dddddd; background-color: #444444; } QPushButton:disabled { color: #777777; background-color: #222222; } )"); s->setCurrentWidget(wifiScreen); ui_setup_complete = true; } void Networking::refresh(){ if (!this->isVisible()) { return; } if (!ui_setup_complete) { attemptInitialization(); if (!ui_setup_complete) { return; } } wifiWidget->refresh(); an->refresh(); } void Networking::connectToNetwork(const Network &n) { if (n.security_type == SecurityType::OPEN) { wifi->connect(n); } else if (n.security_type == SecurityType::WPA) { QString pass = InputDialog::getText("Enter password for \"" + n.ssid + "\"", 8); wifi->connect(n, pass); } } void Networking::wrongPassword(const QString &ssid) { for (Network n : wifi->seen_networks) { if (n.ssid == ssid) { QString pass = InputDialog::getText("Wrong password for \"" + n.ssid +"\"", 8); wifi->connect(n, pass); return; } } } // AdvancedNetworking functions AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWidget(parent), wifi(wifi){ QVBoxLayout* vlayout = new QVBoxLayout; vlayout->setMargin(40); vlayout->setSpacing(20); // Back button QPushButton* back = new QPushButton("Back"); back->setFixedSize(500, 100); connect(back, &QPushButton::released, [=](){emit backPress();}); vlayout->addWidget(back, 0, Qt::AlignLeft); // Enable tethering layout ToggleControl *tetheringToggle = new ToggleControl("Enable Tethering", "", "", wifi->tetheringEnabled()); vlayout->addWidget(tetheringToggle); QObject::connect(tetheringToggle, &ToggleControl::toggleFlipped, this, &AdvancedNetworking::toggleTethering); vlayout->addWidget(horizontal_line(), 0); // Change tethering password editPasswordButton = new ButtonControl("Tethering Password", "EDIT", "", [=](){ QString pass = InputDialog::getText("Enter new tethering password", 8); if (pass.size()) { wifi->changeTetheringPassword(pass); } }); vlayout->addWidget(editPasswordButton, 0); vlayout->addWidget(horizontal_line(), 0); // IP address ipLabel = new LabelControl("IP Address", wifi->ipv4_address); vlayout->addWidget(ipLabel, 0); vlayout->addWidget(horizontal_line(), 0); // SSH keys vlayout->addWidget(new SshToggle()); vlayout->addWidget(horizontal_line(), 0); vlayout->addWidget(new SshControl()); vlayout->addStretch(1); setLayout(vlayout); } void AdvancedNetworking::refresh(){ ipLabel->setText(wifi->ipv4_address); update(); } void AdvancedNetworking::toggleTethering(bool enable) { if (enable) { wifi->enableTethering(); } else { wifi->disableTethering(); } editPasswordButton->setEnabled(!enable); } // WifiUI functions WifiUI::WifiUI(QWidget *parent, WifiManager* wifi) : QWidget(parent), wifi(wifi) { vlayout = new QVBoxLayout; // Scan on startup QLabel *scanning = new QLabel("Scanning for networks"); scanning->setStyleSheet(R"(font-size: 65px;)"); vlayout->addWidget(scanning, 0, Qt::AlignCenter); vlayout->setSpacing(25); setLayout(vlayout); } void WifiUI::refresh() { wifi->request_scan(); wifi->refreshNetworks(); clearLayout(vlayout); connectButtons = new QButtonGroup(this); // TODO check if this is a leak QObject::connect(connectButtons, qOverload<QAbstractButton*>(&QButtonGroup::buttonClicked), this, &WifiUI::handleButton); int i = 0; for (Network &network : wifi->seen_networks) { QHBoxLayout *hlayout = new QHBoxLayout; hlayout->addSpacing(50); QLabel *ssid_label = new QLabel(QString::fromUtf8(network.ssid)); ssid_label->setStyleSheet("font-size: 55px;"); hlayout->addWidget(ssid_label, 1, Qt::AlignLeft); // strength indicator unsigned int strength_scale = network.strength / 17; hlayout->addWidget(new NetworkStrengthWidget(strength_scale), 0, Qt::AlignRight); // connect button QPushButton* btn = new QPushButton(network.security_type == SecurityType::UNSUPPORTED ? "Unsupported" : (network.connected == ConnectedType::CONNECTED ? "Connected" : (network.connected == ConnectedType::CONNECTING ? "Connecting" : "Connect"))); btn->setDisabled(network.connected == ConnectedType::CONNECTED || network.connected == ConnectedType::CONNECTING || network.security_type == SecurityType::UNSUPPORTED); btn->setFixedWidth(350); hlayout->addWidget(btn, 0, Qt::AlignRight); connectButtons->addButton(btn, i); vlayout->addLayout(hlayout, 1); // Don't add the last horizontal line if (i+1 < wifi->seen_networks.size()) { vlayout->addWidget(horizontal_line(), 0); } i++; } vlayout->addStretch(3); } void WifiUI::handleButton(QAbstractButton* button) { QPushButton* btn = static_cast<QPushButton*>(button); Network n = wifi->seen_networks[connectButtons->id(btn)]; emit connectToNetwork(n); }
# Property of Mitchell Jonker .data pr0: .asciiz "Enter Value for A\n" pr1: .asciiz "Enter Value for B\n" pr2: .asciiz "Enter Value for C\n" pr3: .asciiz "Enter Value for D\n" result: .asciiz "F = " negative: .asciiz "A negative value was entered. Please restart the program." .text li $s0, 0 # a li $s1, 0 # b li $s2, 0 # c li $s3, 0 # d li $s4, 0 # 0 # Prompt and store A, if negative, err and exit li $v0, 4 la $a0, pr0 syscall li $v0, 5 syscall move $s0, $v0 bltz $s0, negative_error # Prompt and store B, if negative, err and exit li $v0, 4 la $a0, pr1 syscall li $v0, 5 syscall move $s1, $v0 bltz $s1, negative_error # Prompt and store C, if negative, err and exit li $v0, 4 la $a0, pr2 syscall li $v0, 5 syscall move $s2, $v0 bltz $s2, negative_error # Prompt and store D, if negative, err and exit li $v0, 4 la $a0, pr3 syscall li $v0, 5 syscall move $s3, $v0 bltz $s3, negative_error # Calculate F add $t0, $s0, $s1 # p1 add $t1, $s2, $s3 # p2 addi $t2, $s1, 3 # p3 sub $t3, $t0, $t1 add $t4, $t3, $t2 # Present user with answer F li $v0, 4 la $a0, result syscall li $v0, 1 move $a0, $t4 syscall li $v0, 10 syscall negative_error: li $v0, 4 la $a0, negative syscall li $v0, 10 syscall
//----------------------------------------------------------------------- // Copyright 2011 Ciaran McHale. // // 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. // //----------------------------------------------------------------------- // // BNF of config file // ------------------ // Note: "|" denotes choice // "{ ... }*" denotes repetition 0+ times // "[ ... ]" denotes 0 or 1 times // // configFile = StmtList // StmtList = { Stmt }* // // Stmt = ident_sym [ '=' | '?=' ] StringExpr ';' // | ident_sym [ '=' | '?=' ] ListExpr ';' // | ident_sym '{' StmtList '}' [ ';' ] // | '@include' StringExpr [ '@ifExists' ] ';' // | '@copyFrom' ident_sym [ '@ifExists' ] ';' // | '@remove' ident_sym ';' // | '@error' StringExpr ';' // | '@if' '(' Condition ')' '{' StmtList '}' // { '@elseIf' '(' Condition ')' '{' StmtList '}' }* // [ '@else' '{' StmtList '}' ] // [ ';' ] // // StringExpr = String { '+' String }* // // String = string_sym // | ident_sym // | 'osType(' ')' // | 'osDirSeparator(' ')' // | 'osPathSeparator(' ')' // | 'getenv(' StringExpr [ ',' StringExpr ] ')' // | 'exec(' StringExpr [ ',' StringExpr ] ')' // | 'join(' ListExpr ',' StringExpr ')' // | 'siblingScope(' StringExpr ')' // // // ListExpr = List { '+' List }* // List = '[' StringExprList [ ',' ] ']' // | ident_sym // | 'split(' StringExpr ',' StringExpr ')' // // StringExprList = empty // | StringExpr { ',' StringExpr }* // // Condition = OrCondition // OrCondition = AndCondition { '||' AndCondition }* // AndCondition = TermCondition { '&&' TermCondition }* // TermCondition = '(' Condition ')' // | '!' '(' Condition ')' // | 'isFileReadable(' StringExpr ')' // | StringExpr '==' StringExpr // | StringExpr '!=' StringExpr // | StringExpr '@in' ListExpr // | StringExpr '@matches' StringExpr //---------------------------------------------------------------------- //-------- // #include's //-------- #include "ConfigParser.h" #include "platform.h" #include "platform.h" #include <assert.h> #include <stdlib.h> #include <ctype.h> #include <errno.h> #include <string.h> namespace CONFIG4CPP_NAMESPACE { static bool startsWith(const char * str, const char * prefix) { return strncmp(str, prefix, strlen(prefix)) == 0; } //---------------------------------------------------------------------- // Function: Constructor // // Description: Initialise instance variables and do actual parsing. //---------------------------------------------------------------------- ConfigParser::ConfigParser( Configuration::SourceType sourceType, const char * source, const char * trustedCmdLine, const char * sourceDescription, ConfigurationImpl * config, bool ifExistsIsSpecified) throw(ConfigurationException) { StringBuffer msg; //-------- // Initialise instance variables //-------- m_config = config; m_errorInIncludedFile = false; switch (sourceType) { case Configuration::INPUT_FILE: m_fileName = source; break; case Configuration::INPUT_STRING: if (strcmp(sourceDescription, "") == 0) { m_fileName = "<string-based configuration>"; } else { m_fileName = sourceDescription; } break; case Configuration::INPUT_EXEC: if (strcmp(sourceDescription, "") == 0) { m_fileName.empty(); m_fileName << "exec#" << source; } else { m_fileName = sourceDescription; } source = trustedCmdLine; break; default: assert(0); // Bug! break; } //-------- // Initialise the lexical analyser. // The constructor of the lexical analyser throws an exception // if it cannot open the specified file or execute the specified // command. If such an exception is thrown and if // "ifExistsIsSpecified" is true then we return without doing // any work. //-------- try { m_lex = new ConfigLex(sourceType, source, &m_config->m_uidIdentifierProcessor); } catch (const ConfigurationException &) { m_lex = 0; if (ifExistsIsSpecified) { return; } else { throw; } } m_lex->nextToken(m_token); //-------- // Push our file onto the the stack of (include'd) files. //-------- m_config->pushIncludedFilename(m_fileName.c_str()); //-------- // Perform the actual work. Note that a config file // consists of a list of statements. //-------- try { parseStmtList(); accept(ConfigLex::LEX_EOF_SYM, "expecting identifier"); } catch(const ConfigurationException & ex) { delete m_lex; m_lex = 0; m_config->popIncludedFilename(m_fileName.c_str()); if (m_errorInIncludedFile) { throw; } else { msg << m_fileName << ", line " << m_token.lineNum() << ": " << ex.c_str(); throw ConfigurationException(msg.c_str()); } } //-------- // Pop our file from the the stack of (include'd) files. //-------- m_config->popIncludedFilename(m_fileName.c_str()); } //---------------------------------------------------------------------- // Function: Destructor // // Description: Reclaim memory. //---------------------------------------------------------------------- ConfigParser::~ConfigParser() { delete m_lex; } //---------------------------------------------------------------------- // Function: parseStmtList() // // Description: StmtList = { Stmt }* //---------------------------------------------------------------------- void ConfigParser::parseStmtList() { while ( m_token.type() == ConfigLex::LEX_IDENT_SYM || m_token.type() == ConfigLex::LEX_INCLUDE_SYM || m_token.type() == ConfigLex::LEX_IF_SYM || m_token.type() == ConfigLex::LEX_REMOVE_SYM || m_token.type() == ConfigLex::LEX_ERROR_SYM || m_token.type() == ConfigLex::LEX_COPY_FROM_SYM) { parseStmt(); } } //---------------------------------------------------------------------- // Function: parseStmt() // // Description: Stmt = ident [ '=' | '?=' ] RhsAssignStmt ';' // | ident Scope [ ';' ] // | '@include' StringExpr [ '@ifExists' ] ';' // | '@copyFrom' ident_sym [ '@ifExists' ] ';' //---------------------------------------------------------------------- void ConfigParser::parseStmt() { LexToken identName; short assignmentType; identName = m_token; // save it if (identName.type() == ConfigLex::LEX_INCLUDE_SYM) { parseIncludeStmt(); return; } else if (identName.type() == ConfigLex::LEX_IF_SYM) { parseIfStmt(); return; } else if (identName.type() == ConfigLex::LEX_REMOVE_SYM) { parseRemoveStmt(); return; } else if (identName.type() == ConfigLex::LEX_ERROR_SYM) { parseErrorStmt(); return; } else if (identName.type() == ConfigLex::LEX_COPY_FROM_SYM) { parseCopyStmt(); return; } if (identName.type() == ConfigLex::LEX_IDENT_SYM && identName.spelling()[0] == '.') { error("cannot use '.' at start of the declaration of a " "variable or scope,"); return; } accept(ConfigLex::LEX_IDENT_SYM, "expecting identifier or 'include'"); switch(m_token.type()) { case ConfigLex::LEX_EQUALS_SYM: case ConfigLex::LEX_QUESTION_EQUALS_SYM: assignmentType = m_token.type(); m_lex->nextToken(m_token); parseRhsAssignStmt(identName, assignmentType); accept(ConfigLex::LEX_SEMICOLON_SYM, "expecting ';' or '+'"); break; case ConfigLex::LEX_OPEN_BRACE_SYM: parseScope(identName); //-------- // Consume an optional ";" //-------- if (m_token.type() == ConfigLex::LEX_SEMICOLON_SYM) { m_lex->nextToken(m_token); } break; default: error("expecting '=', '?=' or '{'"); // matching '}' return; } } //---------------------------------------------------------------------- // Function: parseIncludeStmt() // // Description: IncludeStmt = 'include' StringExpr [ 'if' 'exists' ] ';' //---------------------------------------------------------------------- void ConfigParser::parseIncludeStmt() { StringBuffer source; StringBuffer msg; int includeLineNum; bool ifExistsIsSpecified; const char * execSource; StringBuffer trustedCmdLine; //-------- // Consume the '@include' keyword //-------- accept(ConfigLex::LEX_INCLUDE_SYM, "expecting 'include'"); if (m_config->getCurrScope() != m_config->rootScope()) { error("The '@include' command cannot be used inside a scope", false); return; } includeLineNum = m_token.lineNum(); //-------- // Consume the source //-------- parseStringExpr(source); //-------- // Check if this is a circular include. //-------- m_config->checkForCircularIncludes(source.c_str(), includeLineNum); //-------- // Consume "@ifExists" if specified //-------- if (m_token.type() == ConfigLex::LEX_IF_EXISTS_SYM) { ifExistsIsSpecified = true; m_lex->nextToken(m_token); } else { ifExistsIsSpecified = false; } //-------- // We get more intuitive error messages if we report a security // violation for include "exec#..." now instead of later from // inside a recursive call to the parser. //-------- execSource = 0; // prevent warning about it possibly being uninitialized if (startsWith(source.c_str(), "exec#")) { execSource = source.c_str() + strlen("exec#"); if (!m_config->isExecAllowed(execSource, trustedCmdLine)) { msg << "cannot include \"" << source << "\" due to security restrictions"; throw ConfigurationException(msg.c_str()); } } //-------- // The source is of one of the following forms: // "exec#<command>" // "file#<command>" // "<filename>" // // Parse the source. If there is an error then propagate it with // some additional text to indicate that the error was in an // included file. //-------- try { if (startsWith(source.c_str(), "exec#")) { ConfigParser tmp(Configuration::INPUT_EXEC, execSource, trustedCmdLine.c_str(), "", m_config, ifExistsIsSpecified); } else if (startsWith(source.c_str(), "file#")) { ConfigParser tmp(Configuration::INPUT_FILE, source.c_str() + strlen("file#"), trustedCmdLine.c_str(), "", m_config, ifExistsIsSpecified); } else { ConfigParser tmp(Configuration::INPUT_FILE, source.c_str(), trustedCmdLine.c_str(), "", m_config, ifExistsIsSpecified); } } catch(const ConfigurationException & ex) { m_errorInIncludedFile = true; msg << ex.c_str() << "\n(included from " << m_fileName << ", line " << includeLineNum << ")"; throw ConfigurationException(msg.c_str()); } //-------- // Consume the terminating ';' //-------- accept(ConfigLex::LEX_SEMICOLON_SYM, "expecting ';' or '@ifExists'"); } //---------------------------------------------------------------------- // Function: parseIfStmt() // // Description: //---------------------------------------------------------------------- void ConfigParser::parseIfStmt() { bool condition; bool condition2; //-------- // Parse the "if ( Condition ) { StmtList }" clause //-------- accept(ConfigLex::LEX_IF_SYM, "expecting 'if'"); accept(ConfigLex::LEX_OPEN_PAREN_SYM, "expecting '('"); condition = parseCondition(); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); accept(ConfigLex::LEX_OPEN_BRACE_SYM, "expecting '{'"); if (condition) { parseStmtList(); accept(ConfigLex::LEX_CLOSE_BRACE_SYM, "expecting '}'"); } else { skipToClosingBrace(); } //-------- // Parse 0+ "elseif ( Condition ) { StmtList }" clauses //-------- while (m_token.type() == ConfigLex::LEX_ELSE_IF_SYM) { m_lex->nextToken(m_token); accept(ConfigLex::LEX_OPEN_PAREN_SYM, "expecting '('"); condition2 = parseCondition(); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); accept(ConfigLex::LEX_OPEN_BRACE_SYM, "expecting '{'"); if (!condition && condition2) { parseStmtList(); accept(ConfigLex::LEX_CLOSE_BRACE_SYM, "expecting '}'"); } else { skipToClosingBrace(); } condition = condition || condition2; } //-------- // Parse the "else { StmtList }" clause, if any //-------- if (m_token.type() == ConfigLex::LEX_ELSE_SYM) { m_lex->nextToken(m_token); accept(ConfigLex::LEX_OPEN_BRACE_SYM, "expecting '{'"); if (!condition) { parseStmtList(); accept(ConfigLex::LEX_CLOSE_BRACE_SYM, "expecting '}'"); } else { skipToClosingBrace(); } } //-------- // Consume an optional ";" //-------- if (m_token.type() == ConfigLex::LEX_SEMICOLON_SYM) { m_lex->nextToken(m_token); } } void ConfigParser::skipToClosingBrace() { int countOpenBraces; countOpenBraces = 1; while (countOpenBraces > 0) { switch (m_token.type()) { case ConfigLex::LEX_OPEN_BRACE_SYM: countOpenBraces ++; break; case ConfigLex::LEX_CLOSE_BRACE_SYM: countOpenBraces --; break; case ConfigLex::LEX_EOF_SYM: error("expecting '}'"); break; default: break; } m_lex->nextToken(m_token); } } //---------------------------------------------------------------------- // Function: parseCondition() // // Description: //---------------------------------------------------------------------- bool ConfigParser::parseCondition() { return parseOrCondition(); } //---------------------------------------------------------------------- // Function: parseOrCondition() // // Description: //---------------------------------------------------------------------- bool ConfigParser::parseOrCondition() { bool result; bool result2; result = parseAndCondition(); while (m_token.type() == ConfigLex::LEX_OR_SYM) { m_lex->nextToken(m_token); result2 = parseAndCondition(); result = result || result2; } return result; } //---------------------------------------------------------------------- // Function: parseAndCondition() // // Description: //---------------------------------------------------------------------- bool ConfigParser::parseAndCondition() { bool result; bool result2; result = parseTerminalCondition(); while (m_token.type() == ConfigLex::LEX_AND_SYM) { m_lex->nextToken(m_token); result2 = parseTerminalCondition(); result = result && result2; } return result; } //---------------------------------------------------------------------- // Function: parseTerminalCondition() // // TermCondition = '(' Condition ')' // | '!' '(' Condition ')' // | 'isFileReadable(' StringExpr ')' // | StringExpr '==' StringExpr // | StringExpr '!=' StringExpr // | StringExpr 'in' ListExpr // | StringExpr 'matches' StringExpr //---------------------------------------------------------------------- bool ConfigParser::parseTerminalCondition() { FILE * file; StringBuffer str1; StringBuffer str2; StringVector list; bool result; int len; int i; result = false; if (m_token.type() == ConfigLex::LEX_NOT_SYM) { m_lex->nextToken(m_token); accept(ConfigLex::LEX_OPEN_PAREN_SYM, "expecting '('"); result = !parseCondition(); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); return result; } if (m_token.type() == ConfigLex::LEX_OPEN_PAREN_SYM) { m_lex->nextToken(m_token); result = parseCondition(); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); return result; } if (m_token.type() == ConfigLex::LEX_FUNC_IS_FILE_READABLE_SYM) { m_lex->nextToken(m_token); parseStringExpr(str1); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); file = fopen(str1.c_str(), "r"); if (file == 0) { return false; } else { fclose(file); return true; } } parseStringExpr(str1); switch (m_token.type()) { case ConfigLex::LEX_EQUALS_EQUALS_SYM: m_lex->nextToken(m_token); parseStringExpr(str2); result = (strcmp(str1.c_str(), str2.c_str()) == 0); break; case ConfigLex::LEX_NOT_EQUALS_SYM: m_lex->nextToken(m_token); parseStringExpr(str2); result = (strcmp(str1.c_str(), str2.c_str()) != 0); break; case ConfigLex::LEX_IN_SYM: m_lex->nextToken(m_token); parseListExpr(list); len = list.length(); result = false; for (i = 0; i < len; i++) { if (strcmp(str1.c_str(), list[i]) == 0) { result = true; break; } } break; case ConfigLex::LEX_MATCHES_SYM: m_lex->nextToken(m_token); parseStringExpr(str2); result = Configuration::patternMatch(str1.c_str(), str2.c_str()); break; default: error("expecting '(', or a string expression"); break; } return result; } //---------------------------------------------------------------------- // Function: parseCopyStmt() // // Description: CopyStmt = '@copyFrom' stringExpr [ '@ifExists' ] ';' //---------------------------------------------------------------------- void ConfigParser::parseCopyStmt() { StringBuffer fromScopeName; StringBuffer prefix; const char * toScopeName; StringBuffer msg; StringVector fromNamesVec; ConfigItem * item; ConfigScope * fromScope; ConfigScope * dummyScope; const char * newName; int i; int len; int fromScopeNameLen; bool ifExistsIsSpecified; accept(ConfigLex::LEX_COPY_FROM_SYM, "expecting '@copyFrom'"); parseStringExpr(fromScopeName); fromScopeNameLen = fromScopeName.length(); //-------- // Consume "@ifExists" if specified //-------- if (m_token.type() == ConfigLex::LEX_IF_EXISTS_SYM) { ifExistsIsSpecified = true; m_lex->nextToken(m_token); } else { ifExistsIsSpecified = false; } //-------- // Sanity check: cannot copy from a parent scope //-------- toScopeName = m_config->getCurrScope()->scopedName(); if (strcmp(toScopeName, fromScopeName.c_str()) == 0) { throw ConfigurationException( "copy statement: cannot copy from own scope"); } prefix << fromScopeName << "."; if (strncmp(toScopeName, prefix.c_str(), fromScopeNameLen+1) == 0) { throw ConfigurationException( "copy statement: cannot copy from a parent scope"); } //-------- // If the scope does not exist and if "@ifExists" was specified // then we short-circuit the rest of this function. //-------- item = m_config->lookup(fromScopeName.c_str(), fromScopeName.c_str(), true); if (item == 0 && ifExistsIsSpecified) { accept(ConfigLex::LEX_SEMICOLON_SYM, "expecting ';'"); return; } if (item == 0) { msg << "copy statement: scope '" << fromScopeName << "' does not exist"; throw ConfigurationException(msg.c_str()); } if (item->type() != Configuration::CFG_SCOPE) { msg << "copy statement: '" << fromScopeName << "' is not a scope"; throw ConfigurationException(msg.c_str()); } fromScope = item->scopeVal(); assert(fromScope != 0); //-------- // Get a recursive listing of all the items in fromScopeName //-------- fromScope->listFullyScopedNames(Configuration::CFG_SCOPE_AND_VARS, true, fromNamesVec); //-------- // Copy all the items into the current scope //-------- len = fromNamesVec.length(); for (i = 0; i < len; i++) { newName = &fromNamesVec[i][fromScopeNameLen + 1]; item = m_config->lookup(fromNamesVec[i], fromNamesVec[i], true); assert(item != 0); switch (item->type()) { case Configuration::CFG_STRING: m_config->insertString("", newName, item->stringVal()); break; case Configuration::CFG_LIST: m_config->insertList(newName, item->listVal()); break; case Configuration::CFG_SCOPE: m_config->ensureScopeExists(newName, dummyScope); break; default: assert(0); // Bug! break; } } //-------- // Consume the terminating ';' //-------- accept(ConfigLex::LEX_SEMICOLON_SYM, "expecting ';' or '@ifExists'"); } //---------------------------------------------------------------------- // Function: parseRemoveStmt() // // Description: removeStmt = 'remove' ident_sym ';' //---------------------------------------------------------------------- void ConfigParser::parseRemoveStmt() { ConfigScope * currScope; StringBuffer identName; StringBuffer msg; accept(ConfigLex::LEX_REMOVE_SYM, "expecting 'remove'"); identName = m_token.spelling(); accept(ConfigLex::LEX_IDENT_SYM, "expecting an identifier"); if (strchr(identName.c_str(), '.') != 0) { msg << m_fileName << ": can remove entries from only the " << "current scope"; throw ConfigurationException(msg.c_str()); } currScope = m_config->getCurrScope(); if (!currScope->removeItem(identName.c_str())) { msg << m_fileName << ": '" << identName << "' does not exist in the current scope"; throw ConfigurationException(msg.c_str()); } accept(ConfigLex::LEX_SEMICOLON_SYM, "expecting ';'"); } //---------------------------------------------------------------------- // Function: parseErrorStmt() // // Description: ErrorStmt = 'error' stringExpr ';' //---------------------------------------------------------------------- void ConfigParser::parseErrorStmt() { StringBuffer msg; accept(ConfigLex::LEX_ERROR_SYM, "expecting 'error'"); parseStringExpr(msg); accept(ConfigLex::LEX_SEMICOLON_SYM, "expecting ';'"); throw ConfigurationException(msg.c_str()); } //---------------------------------------------------------------------- // Function: parseScope() // // Description: Scope = '{' StmtList '}' //---------------------------------------------------------------------- void ConfigParser::parseScope(LexToken & scopeName) { ConfigScope * oldScope; ConfigScope * newScope; StringBuffer errMsg; //-------- // Create the new scope and put it onto the stack //-------- oldScope = m_config->getCurrScope(); m_config->ensureScopeExists(scopeName.spelling(), newScope); m_config->setCurrScope(newScope); //-------- // Do the actual parsing //-------- accept(ConfigLex::LEX_OPEN_BRACE_SYM, "expecting '{'"); parseStmtList(); accept(ConfigLex::LEX_CLOSE_BRACE_SYM, "expecting an identifier or '}'"); //-------- // Finally, pop the scope from the stack //-------- m_config->setCurrScope(oldScope); } //---------------------------------------------------------------------- // Function: parseRhsAssignStmt() // // Description: RhsAssignStmt = StringExpr // | ListExpr //---------------------------------------------------------------------- void ConfigParser::parseRhsAssignStmt( LexToken & varName, short assignmentType) { StringBuffer stringExpr; StringVector listExpr; Configuration::Type varType; StringBuffer msg; bool doAssign; switch(m_config->type(varName.spelling(), "")) { case Configuration::CFG_STRING: case Configuration::CFG_LIST: if (assignmentType == ConfigLex::LEX_QUESTION_EQUALS_SYM) { doAssign = false; } else { doAssign = true; } break; default: doAssign = true; break; } //-------- // Examine the current token to determine whether the expression // to be parsed is a stringExpr or an listExpr. //-------- switch(m_token.type()) { case ConfigLex::LEX_OPEN_BRACKET_SYM: case ConfigLex::LEX_FUNC_SPLIT_SYM: varType = Configuration::CFG_LIST; break; case ConfigLex::LEX_FUNC_SIBLING_SCOPE_SYM: case ConfigLex::LEX_FUNC_GETENV_SYM: case ConfigLex::LEX_FUNC_EXEC_SYM: case ConfigLex::LEX_FUNC_JOIN_SYM: case ConfigLex::LEX_FUNC_READ_FILE_SYM: case ConfigLex::LEX_FUNC_REPLACE_SYM: case ConfigLex::LEX_FUNC_OS_TYPE_SYM: case ConfigLex::LEX_FUNC_OS_DIR_SEP_SYM: case ConfigLex::LEX_FUNC_OS_PATH_SEP_SYM: case ConfigLex::LEX_FUNC_FILE_TO_DIR_SYM: case ConfigLex::LEX_FUNC_CONFIG_FILE_SYM: case ConfigLex::LEX_FUNC_CONFIG_TYPE_SYM: case ConfigLex::LEX_STRING_SYM: varType = Configuration::CFG_STRING; break; case ConfigLex::LEX_IDENT_SYM: //-------- // This identifier (hopefully) denotes an already // existing variable. We have to determine the type // of the variable (it is either a string or a list) // in order to proceed with the parsing. //-------- switch (m_config->type(m_token.spelling(), "")) { case Configuration::CFG_STRING: varType = Configuration::CFG_STRING; break; case Configuration::CFG_LIST: varType = Configuration::CFG_LIST; break; default: msg << "identifier '" << m_token.spelling() << "' not previously declared"; error(msg.c_str(), false); return; } break; default: error("expecting a string, identifier or '['"); // matching ']' return; } //-------- // Now that we know the type of the input expression, we // can parse it correctly. //-------- switch(varType) { case Configuration::CFG_STRING: parseStringExpr(stringExpr); if (doAssign) { m_config->insertString("", varName.spelling(), stringExpr.c_str()); } break; case Configuration::CFG_LIST: parseListExpr(listExpr); if (doAssign) { m_config->insertList(varName.spelling(), listExpr); } break; default: assert(0); // Bug break; } } //---------------------------------------------------------------------- // Function: parseStringExpr() // // Description: StringExpr = String { '+' String }* //---------------------------------------------------------------------- void ConfigParser::parseStringExpr(StringBuffer & expr) { StringBuffer expr2; parseString(expr); while (m_token.type() == ConfigLex::LEX_PLUS_SYM) { m_lex->nextToken(m_token); // consume the '+' parseString(expr2); expr << expr2; } } //---------------------------------------------------------------------- // Function: parseString() // // Description: string = string_sym // | ident_sym // | 'os.type(' ')' // | 'dir.sep(' ')' // | 'path.sep(' ')' // | Env // | Exec // | Join // | Split //---------------------------------------------------------------------- void ConfigParser::parseString(StringBuffer & str) { Configuration::Type type; StringBuffer msg; StringBuffer name; const char * constStr; ConfigItem * item; str.empty(); switch(m_token.type()) { case ConfigLex::LEX_FUNC_SIBLING_SCOPE_SYM: parseSiblingScope(str); break; case ConfigLex::LEX_FUNC_GETENV_SYM: parseEnv(str); break; case ConfigLex::LEX_FUNC_EXEC_SYM: parseExec(str); break; case ConfigLex::LEX_FUNC_JOIN_SYM: parseJoin(str); break; case ConfigLex::LEX_FUNC_READ_FILE_SYM: parseReadFile(str); break; case ConfigLex::LEX_FUNC_REPLACE_SYM: parseReplace(str); break; case ConfigLex::LEX_FUNC_OS_TYPE_SYM: str = CONFIG4CPP_OS_TYPE; m_lex->nextToken(m_token); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); break; case ConfigLex::LEX_FUNC_OS_DIR_SEP_SYM: str = CONFIG4CPP_DIR_SEP; m_lex->nextToken(m_token); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); break; case ConfigLex::LEX_FUNC_OS_PATH_SEP_SYM: str = CONFIG4CPP_PATH_SEP; m_lex->nextToken(m_token); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); break; case ConfigLex::LEX_FUNC_FILE_TO_DIR_SYM: m_lex->nextToken(m_token); parseStringExpr(name); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); getDirectoryOfFile(name.c_str(), str); break; case ConfigLex::LEX_FUNC_CONFIG_FILE_SYM: m_lex->nextToken(m_token); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); str = m_fileName; break; case ConfigLex::LEX_FUNC_CONFIG_TYPE_SYM: m_lex->nextToken(m_token); parseStringExpr(name); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); item = m_config->lookup(name.c_str(), name.c_str()); if (item == 0) { type = Configuration::CFG_NO_VALUE; } else { type = item->type(); } switch (type) { case Configuration::CFG_STRING: str = "string"; break; case Configuration::CFG_LIST: str = "list"; break; case Configuration::CFG_SCOPE: str = "scope"; break; case Configuration::CFG_NO_VALUE: str = "no_value"; break; default: assert(0); // Bug! break; } break; case ConfigLex::LEX_STRING_SYM: str = m_token.spelling(); m_lex->nextToken(m_token); break; case ConfigLex::LEX_IDENT_SYM: m_config->stringValue(m_token.spelling(), m_token.spelling(), constStr, type); switch (type) { case Configuration::CFG_STRING: str = constStr; break; case Configuration::CFG_NO_VALUE: msg << "identifier '" << m_token.spelling() << "' not previously declared"; error(msg.c_str(), false); return; case Configuration::CFG_SCOPE: msg << "identifier '" << m_token.spelling() << "' is a scope instead of a string"; error(msg.c_str(), false); return; case Configuration::CFG_LIST: msg << "identifier '" << m_token.spelling() << "' is a list instead of a string"; error(msg.c_str(), false); return; default: assert(0); // Bug return; } m_lex->nextToken(m_token); break; default: error("expecting a string or identifier"); return; } } //---------------------------------------------------------------------- // Function: parseEnv() // // Description: Env = 'getenv(' StringExpr ')' // | 'getenv(' StringExpr ',' StringExpr ')' //---------------------------------------------------------------------- void ConfigParser::parseEnv(StringBuffer & str) { StringBuffer msg; StringBuffer envVarName; bool hasDefaultStr; StringBuffer defaultStr; const char * val; accept(ConfigLex::LEX_FUNC_GETENV_SYM, "expecting 'getenv('"); parseStringExpr(envVarName); if (m_token.type() == ConfigLex::LEX_COMMA_SYM) { accept(ConfigLex::LEX_COMMA_SYM, "expecting ','"); parseStringExpr(defaultStr); hasDefaultStr = true; } else { hasDefaultStr = false; } accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); val = getenv(envVarName.c_str()); if (val == 0 && hasDefaultStr) { val = defaultStr.c_str(); } if (val == 0) { msg << "cannot access the '" << envVarName << "' environment variable"; throw ConfigurationException(msg.c_str()); } str = val; } void ConfigParser::parseSiblingScope(StringBuffer & str) { StringBuffer msg; ConfigScope * currScope; StringBuffer siblingName; const char * parentScopeName; const char * val; accept(ConfigLex::LEX_FUNC_SIBLING_SCOPE_SYM, "expecting 'siblingScope('"); currScope = m_config->getCurrScope(); if (currScope == m_config->rootScope()) { error("The siblingScope() function cannot be used in the " "root scope", false); return; } parentScopeName = currScope->parentScope()->scopedName(); parseStringExpr(siblingName); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); Configuration::mergeNames(parentScopeName, siblingName.c_str(), str); } //---------------------------------------------------------------------- // Function: parseReadFile() // // Description: //---------------------------------------------------------------------- void ConfigParser::parseReadFile(StringBuffer & str) { StringBuffer msg; StringBuffer fileName; int ch; BufferedFileReader file; accept(ConfigLex::LEX_FUNC_READ_FILE_SYM, "expecting 'read.file('"); parseStringExpr(fileName); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); str.empty(); if (!file.open(fileName.c_str())) { msg << "error reading " << fileName << ": " << strerror(errno); throw ConfigurationException(msg.c_str()); } while ((ch = file.getChar()) != EOF) { if (ch != '\r') { str.append((char)ch); } } } //---------------------------------------------------------------------- // Function: parseJoin() // // Description: Join = 'join(' ListExpr ',' StringExpr ')' //---------------------------------------------------------------------- void ConfigParser::parseJoin(StringBuffer & str) { StringVector list; StringBuffer separator; int len; int i; accept(ConfigLex::LEX_FUNC_JOIN_SYM, "expecting 'join('"); parseListExpr(list); accept(ConfigLex::LEX_COMMA_SYM, "expecting ','"); parseStringExpr(separator); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); str.empty(); len = list.length(); for (i = 0; i < len; i++) { str.append(list[i]); if (i < len - 1) { str.append(separator); } } } //---------------------------------------------------------------------- // Function: parseReplace() // // Description: Replace = 'replace(' StringExpr ',' StringExpr // ',' StringExpr ')' //---------------------------------------------------------------------- void ConfigParser::parseReplace(StringBuffer & result) { StringBuffer origStr; StringBuffer searchStr; StringBuffer replacementStr; const char * p; int origStrLen; int searchStrLen; int currStart; int currEnd; accept(ConfigLex::LEX_FUNC_REPLACE_SYM, "expecting 'replace('"); parseStringExpr(origStr); accept(ConfigLex::LEX_COMMA_SYM, "expecting ','"); parseStringExpr(searchStr); accept(ConfigLex::LEX_COMMA_SYM, "expecting ','"); parseStringExpr(replacementStr); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); result = ""; origStrLen = origStr.length(); searchStrLen = searchStr.length(); currStart = 0; p = strstr(origStr.c_str(), searchStr.c_str()); while (p != 0) { currEnd = p - origStr.c_str(); origStr[currEnd] = '\0'; result << (origStr.c_str() + currStart); result << replacementStr; currStart = currEnd + searchStrLen; p = strstr(origStr.c_str() + currStart, searchStr.c_str()); } result << (origStr.c_str() + currStart); } //---------------------------------------------------------------------- // Function: parseSplit() // // Description: Split = 'split(' StringExpr ',' StringExpr ')' //---------------------------------------------------------------------- void ConfigParser::parseSplit(StringVector & list) { StringBuffer str; StringBuffer delim; const char * p; int strLen; int delimLen; int currStart; int currEnd; accept(ConfigLex::LEX_FUNC_SPLIT_SYM, "expecting 'split('"); parseStringExpr(str); accept(ConfigLex::LEX_COMMA_SYM, "expecting ','"); parseStringExpr(delim); accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); list.empty(); strLen = str.length(); delimLen = delim.length(); currStart = 0; p = strstr(str.c_str(), delim.c_str()); while (p != 0) { currEnd = p - str.c_str(); str[currEnd] = '\0'; list.add(str.c_str() + currStart); currStart = currEnd + delimLen; p = strstr(str.c_str() + currStart, delim.c_str()); } list.add(str.c_str() + currStart); } //---------------------------------------------------------------------- // Function: parseExec() // // Description: Exec = 'os.exec(' StringExpr ')' // | 'os.exec(' StringExpr ',' StringExpr ')' //---------------------------------------------------------------------- void ConfigParser::parseExec(StringBuffer & str) { StringBuffer msg; StringBuffer cmd; bool hasDefaultStr; StringBuffer defaultStr; bool execStatus; StringBuffer trustedCmdLine; //-------- // Parse the command and default value, if any //-------- accept(ConfigLex::LEX_FUNC_EXEC_SYM, "expecting 'os.exec('"); parseStringExpr(cmd); if (m_token.type() == ConfigLex::LEX_COMMA_SYM) { accept(ConfigLex::LEX_COMMA_SYM, "expecting ','"); parseStringExpr(defaultStr); hasDefaultStr = true; } else { hasDefaultStr = false; } if (!m_config->isExecAllowed(cmd.c_str(), trustedCmdLine)) { msg << "cannot execute \"" << cmd.c_str() << "\" due to security restrictions"; throw ConfigurationException(msg.c_str()); } //-------- // Execute the command and decide if we throw an exception, // return the default value, if any, or return the output of // the successful execCmd(). //-------- execStatus = execCmd(trustedCmdLine.c_str(), str); if (!execStatus && !hasDefaultStr) { msg << "os.exec(\"" << cmd << "\") failed: " << str; throw ConfigurationException(msg.c_str()); } else if (!execStatus && hasDefaultStr) { str = defaultStr; } else { assert(execStatus == true); } accept(ConfigLex::LEX_CLOSE_PAREN_SYM, "expecting ')'"); } //---------------------------------------------------------------------- // Function: parseListExpr() // // Description: ListExpr = List { '+' List }* //---------------------------------------------------------------------- void ConfigParser::parseListExpr(StringVector & expr) { StringVector expr2; expr.empty(); parseList(expr); while (m_token.type() == ConfigLex::LEX_PLUS_SYM) { m_lex->nextToken(m_token); // consume the '+' parseList(expr2); expr.addWithOwnership(expr2); } } //---------------------------------------------------------------------- // Function: parseList() // // Description: List = 'split(' StringExpr ',' StringExpr ')' // | '[' StringExprList ']' // | ident_sym //---------------------------------------------------------------------- void ConfigParser::parseList(StringVector & expr) { Configuration::Type type; StringBuffer msg; switch (m_token.type()) { case ConfigLex::LEX_FUNC_SPLIT_SYM: parseSplit(expr); break; case ConfigLex::LEX_OPEN_BRACKET_SYM: //-------- // '[' StringExprList [ ',' ] ']' //-------- m_lex->nextToken(m_token); // consume the open bracket parseStringExprList(expr); accept(ConfigLex::LEX_CLOSE_BRACKET_SYM, "expecting ']'"); break; case ConfigLex::LEX_IDENT_SYM: //-------- // ident_sym: make sure the identifier is a list //-------- m_config->listValue(m_token.spelling(), m_token.spelling(), expr, type); if (type != Configuration::CFG_LIST) { msg << "identifier '" << m_token.spelling() << "' is not a list"; error(msg.c_str(), false); } m_lex->nextToken(m_token); // consume the identifier break; default: error("expecting an identifier or '['"); // matching ']' break; } } //---------------------------------------------------------------------- // Function: getDirectoryOfFile() // // Description: Returns the directory name of the specified file //---------------------------------------------------------------------- void ConfigParser::getDirectoryOfFile( const char * file, StringBuffer & result) { int len; int i; int j; bool found; len = strlen(file); found = false; for (i = len-1; i >=0; i--) { if (file[i] == '/' || file[i] == CONFIG4CPP_DIR_SEP[0]) { found = true; break; } } if (!found) { //-------- // Case 1. "foo.cfg" -> "." (UNIX and Windows) //-------- result = "."; } else if (i == 0) { //-------- // Case 2. "/foo.cfg" -> "/." (UNIX and Windows) // Or: "\foo.cfg" -> "\." (Windows only) //-------- result = ""; result << file[0] << "."; } else { //-------- // Case 3. "/tmp/foo.cfg" -> "/tmp" (UNIX and Windows) // Or: "C:\foo.cfg" -> "C:\." (Windows only) //-------- assert(i > 0); result = ""; for (j = 0; j < i; j++) { result << file[j]; } if (i == 2 && isalpha(file[0]) && file[1] == ':') { result << file[i] << "."; } } } //---------------------------------------------------------------------- // Function: parseStringExprList() // // Description: StringExprList = empty // | StringExpr { ',' StringExpr }* [ ',' ] //---------------------------------------------------------------------- void ConfigParser::parseStringExprList(StringVector & list) { StringBuffer str; short type; list.empty(); type = m_token.type(); if (type == ConfigLex::LEX_CLOSE_BRACKET_SYM) { return; // empty list } if (!m_token.isStringFunc() && type != ConfigLex::LEX_STRING_SYM && type != ConfigLex::LEX_IDENT_SYM ) { error("expecting a string or ']'"); } parseStringExpr(str); list.addWithOwnership(str); while (m_token.type() == ConfigLex::LEX_COMMA_SYM) { m_lex->nextToken(m_token); if (m_token.type() == ConfigLex::LEX_CLOSE_BRACKET_SYM) { return; } parseStringExpr(str); list.addWithOwnership(str); } } //---------------------------------------------------------------------- // Function: accept() // // Description: Consume the next token if it is the expected one. // Otherwise report an error. //---------------------------------------------------------------------- void ConfigParser::accept(short sym, const char *errMsg) { if (m_token.type() == sym) { m_lex->nextToken(m_token); } else { error(errMsg); } } //---------------------------------------------------------------------- // Function: error() // // Description: Report an error. //---------------------------------------------------------------------- void ConfigParser::error(const char * errMsg, bool printNear) { StringBuffer msg; //-------- // In order to provide good error messages, lexical errors // take precedence over parsing errors. For example, there is // no point in printing out "was expecting a string or identifier" // if the real problem is that the lexical analyser returned a // string_with_eol_sym symbol. //-------- // msg << "line " << m_token.lineNum() << ": "; switch (m_token.type()) { case ConfigLex::LEX_UNKNOWN_FUNC_SYM: msg << "'" << m_token.spelling() << "' " << "is not a built-in function"; throw ConfigurationException(msg.c_str()); case ConfigLex::LEX_SOLE_DOT_IDENT_SYM: msg << "'.' is not a valid identifier"; throw ConfigurationException(msg.c_str()); case ConfigLex::LEX_TWO_DOTS_IDENT_SYM: msg << "'..' appears in identified '" << m_token.spelling() << "'"; throw ConfigurationException(msg.c_str()); case ConfigLex::LEX_STRING_WITH_EOL_SYM: msg << "end-of-line not allowed in string '" << m_token.spelling() << "'"; throw ConfigurationException(msg.c_str()); case ConfigLex::LEX_BLOCK_STRING_WITH_EOF_SYM: msg << "end-of-file encountered in block string starting at " << "line " << m_token.lineNum(); throw ConfigurationException(msg.c_str()); case ConfigLex::LEX_ILLEGAL_IDENT_SYM: msg << "'" << m_token.spelling() << "' " << "is not a legal identifier"; throw ConfigurationException(msg.c_str()); default: // No lexical error. Handle the parsing error below. break; } //-------- // If we get this far then it means that we have to report // a parsing error (as opposed to a lexical error; they have // already been handled). //-------- if (printNear && m_token.type() == ConfigLex::LEX_STRING_SYM) { msg << errMsg << " near \"" << m_token.spelling() << "\""; throw ConfigurationException(msg.c_str()); } else if (printNear && m_token.type() != ConfigLex::LEX_STRING_SYM) { msg << errMsg << " near '" << m_token.spelling() << "'"; throw ConfigurationException(msg.c_str()); } else { msg << errMsg; throw ConfigurationException(msg.c_str()); } } }; // namespace CONFIG4CPP_NAMESPACE
; A142138: Primes congruent to 29 mod 37. ; Submitted by Jon Maiga ; 29,103,251,547,769,991,1213,1361,1583,1657,1879,2027,2693,2767,3137,3359,3433,3581,3803,3877,4099,4691,4987,5209,5431,5653,5801,6689,6763,6911,7207,7577,7873,8243,8317,8539,8761,9649,9871,10093,10463,11351,12239,12757,12979,13127,14533,15199,15569,15643,15791,16087,16901,17123,17419,17789,17863,18233,18307,18899,18973,19121,19417,19861,20231,20749,20897,21193,21341,21563,21859,22229,22303,23117,23339,23561,23857,24671,24967,25189,25411,25633,26003,26669,26891,27409,27631,27779,28001,28297,29333 mov $1,14 mov $2,$0 add $2,2 pow $2,2 lpb $2 sub $2,2 mov $3,$1 mul $3,2 seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0. sub $0,$3 add $1,37 mov $4,$0 max $4,0 cmp $4,$0 mul $2,$4 lpe mov $0,$1 mul $0,2 sub $0,73
; A101808: Number of primes between two consecutive even numbers. ; 1,2,1,1,0,1,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,0,0,1,0,0,0,1,0,1,1,0,1,1,0,1,0,0,0,0,0,0,1,0,1,0,0,1,1,0,0,0,0,1,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,1,0,0,0,0,1,1,0,1,1 mul $0,2 mov $1,$0 seq $1,20639 ; Lpf(n): least prime dividing n (when n > 1); a(1) = 1. Or, smallest prime factor of n, or smallest prime divisor of n. mov $2,$0 add $0,$1 add $0,1 mov $3,$2 cmp $3,0 add $2,$3 div $0,$2 sub $0,1
%ifdef CONFIG { "RegData": { "RAX": "0x1", "RBX": "0xFFFFFFFFFFFFFFFF" }, "MemoryRegions": { "0x100000000": "4096" } } %endif mov r15, 0xe0000000 mov rax, 0x0 mov [r15 + 8 * 0], rax mov rax, 0x1 mov [r15 + 8 * 1], rax mov rax, 0x2 mov [r15 + 8 * 2], rax mov r10, 0x1 mov r11, 0x0 mov r12, 0x2 cmp r10d, r12d mov rax, -1 mov rbx, -1 cmovs rax, [r15 + 8 * 1] cmovns rbx, [r15 + 8 * 0] hlt
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <GLES2/gl2.h> #include "gpu/demos/framework/demo.h" #include "gpu/demos/framework/demo_factory.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/instance.h" #include "ppapi/cpp/dev/graphics_3d_dev.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/rect.h" #include "ppapi/cpp/size.h" #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" namespace gpu { namespace demos { class PluginInstance : public pp::Instance { public: PluginInstance(PP_Instance instance, pp::Module* module) : pp::Instance(instance), module_(module), demo_(CreateDemo()) { // Set the callback object outside of the initializer list to avoid a // compiler warning about using "this" in an initializer list. callback_factory_.Initialize(this); } ~PluginInstance() { if (!graphics_.is_null()) { glSetCurrentContextPPAPI(graphics_.pp_resource()); delete demo_; glSetCurrentContextPPAPI(0); } } virtual void DidChangeView(const pp::Rect& position, const pp::Rect& /*clip*/) { if (size_ == position.size()) return; size_ = position.size(); demo_->InitWindowSize(size_.width(), size_.height()); if (graphics_.is_null()) { graphics_ = pp::Graphics3D_Dev(*this, 0, NULL, NULL); if (graphics_.is_null()) return; if (!pp::Instance::BindGraphics(graphics_)) return; glSetCurrentContextPPAPI(graphics_.pp_resource()); demo_->InitGL(); glSetCurrentContextPPAPI(0); } if (demo_->IsAnimated()) Animate(0); else Paint(); } void Paint() { glSetCurrentContextPPAPI(graphics_.pp_resource()); demo_->Draw(); graphics_.SwapBuffers(); glSetCurrentContextPPAPI(0); } private: void Animate(int delay) { Paint(); module_->core()->CallOnMainThread(delay, callback_factory_.NewCallback(&PluginInstance::Animate), delay); } pp::Module* module_; Demo* demo_; pp::Graphics3D_Dev graphics_; pp::Size size_; pp::CompletionCallbackFactory<PluginInstance> callback_factory_; }; class PluginModule : public pp::Module { public: PluginModule() {} ~PluginModule() { glTerminatePPAPI(); } virtual bool Init() { return glInitializePPAPI(get_browser_interface()) == GL_TRUE ? true : false; } virtual pp::Instance* CreateInstance(PP_Instance instance) { return new PluginInstance(instance, this); } }; } // namespace demos } // namespace gpu namespace pp { Module* CreateModule() { return new gpu::demos::PluginModule(); } } // namespace pp
dnl x86-32 mpn_mod_1s_4p, requiring cmov. dnl Contributed to the GNU project by Torbjorn Granlund. dnl Copyright 2009, 2010 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 P5 ? C P6 model 0-8,10-12 ? C P6 model 9 (Banias) ? C P6 model 13 (Dothan) 6 C P4 model 0 (Willamette) ? C P4 model 1 (?) ? C P4 model 2 (Northwood) 15.5 C P4 model 3 (Prescott) ? C P4 model 4 (Nocona) ? C AMD K6 ? C AMD K7 4.75 C AMD K8 ? ASM_START() TEXT ALIGN(16) PROLOGUE(mpn_mod_1s_4p) push %ebp push %edi push %esi push %ebx sub $28, %esp mov 60(%esp), %edi C cps[] mov 8(%edi), %eax mov 12(%edi), %edx mov 16(%edi), %ecx mov 20(%edi), %esi mov 24(%edi), %edi mov %eax, 4(%esp) mov %edx, 8(%esp) mov %ecx, 12(%esp) mov %esi, 16(%esp) mov %edi, 20(%esp) mov 52(%esp), %eax C n xor %edi, %edi mov 48(%esp), %esi C up lea -12(%esi,%eax,4), %esi and $3, %eax je L(b0) cmp $2, %eax jc L(b1) je L(b2) L(b3): mov 4(%esi), %eax mull 4(%esp) mov (%esi), %ebp add %eax, %ebp adc %edx, %edi mov 8(%esi), %eax mull 8(%esp) lea -12(%esi), %esi jmp L(m0) L(b0): mov (%esi), %eax mull 4(%esp) mov -4(%esi), %ebp add %eax, %ebp adc %edx, %edi mov 4(%esi), %eax mull 8(%esp) add %eax, %ebp adc %edx, %edi mov 8(%esi), %eax mull 12(%esp) lea -16(%esi), %esi jmp L(m0) L(b1): mov 8(%esi), %ebp lea -4(%esi), %esi jmp L(m1) L(b2): mov 8(%esi), %edi mov 4(%esi), %ebp lea -8(%esi), %esi jmp L(m1) ALIGN(16) L(top): mov (%esi), %eax mull 4(%esp) mov -4(%esi), %ebx xor %ecx, %ecx add %eax, %ebx adc %edx, %ecx mov 4(%esi), %eax mull 8(%esp) add %eax, %ebx adc %edx, %ecx mov 8(%esi), %eax mull 12(%esp) add %eax, %ebx adc %edx, %ecx lea -16(%esi), %esi mov 16(%esp), %eax mul %ebp add %eax, %ebx adc %edx, %ecx mov 20(%esp), %eax mul %edi mov %ebx, %ebp mov %ecx, %edi L(m0): add %eax, %ebp adc %edx, %edi L(m1): subl $4, 52(%esp) ja L(top) L(end): mov 4(%esp), %eax mul %edi mov 60(%esp), %edi add %eax, %ebp adc $0, %edx mov 4(%edi), %ecx mov %edx, %esi mov %ebp, %eax sal %cl, %esi mov %ecx, %ebx neg %ecx shr %cl, %eax or %esi, %eax lea 1(%eax), %esi mull (%edi) mov %ebx, %ecx mov %eax, %ebx mov %ebp, %eax mov 56(%esp), %ebp sal %cl, %eax add %eax, %ebx adc %esi, %edx imul %ebp, %edx sub %edx, %eax lea (%eax,%ebp), %edx cmp %eax, %ebx cmovc( %edx, %eax) mov %eax, %edx sub %ebp, %eax cmovc( %edx, %eax) add $28, %esp pop %ebx pop %esi pop %edi pop %ebp shr %cl, %eax ret EPILOGUE() ALIGN(16) PROLOGUE(mpn_mod_1s_4p_cps) C CAUTION: This is the same code as in pentium4/sse2/mod_1_4.asm push %ebp push %edi push %esi push %ebx mov 20(%esp), %ebp C FIXME: avoid bp for 0-idx mov 24(%esp), %ebx bsr %ebx, %ecx xor $31, %ecx sal %cl, %ebx C b << cnt mov %ebx, %edx not %edx mov $-1, %eax div %ebx xor %edi, %edi sub %ebx, %edi mov $1, %esi mov %eax, (%ebp) C store bi mov %ecx, 4(%ebp) C store cnt shld %cl, %eax, %esi imul %edi, %esi mov %eax, %edi mul %esi add %esi, %edx shr %cl, %esi mov %esi, 8(%ebp) C store B1modb not %edx imul %ebx, %edx lea (%edx,%ebx), %esi cmp %edx, %eax cmovnc( %edx, %esi) mov %edi, %eax mul %esi add %esi, %edx shr %cl, %esi mov %esi, 12(%ebp) C store B2modb not %edx imul %ebx, %edx lea (%edx,%ebx), %esi cmp %edx, %eax cmovnc( %edx, %esi) mov %edi, %eax mul %esi add %esi, %edx shr %cl, %esi mov %esi, 16(%ebp) C store B3modb not %edx imul %ebx, %edx lea (%edx,%ebx), %esi cmp %edx, %eax cmovnc( %edx, %esi) mov %edi, %eax mul %esi add %esi, %edx shr %cl, %esi mov %esi, 20(%ebp) C store B4modb not %edx imul %ebx, %edx add %edx, %ebx cmp %edx, %eax cmovnc( %edx, %ebx) shr %cl, %ebx mov %ebx, 24(%ebp) C store B5modb pop %ebx pop %esi pop %edi pop %ebp ret EPILOGUE()
dnl S/390-32 mpn_copyi dnl Copyright 2011 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 z900 0.75 C z990 0.375 C z9 ? C z10 ? C z196 ? C NOTE C * This is based on GNU libc memcpy which was written by Martin Schwidefsky. C INPUT PARAMETERS define(`rp', `%r2') define(`up', `%r3') define(`n', `%r4') ASM_START() PROLOGUE(mpn_copyi) ltr %r4, %r4 sll %r4, 2 je L(rtn) ahi %r4, -1 lr %r5, %r4 srl %r5, 8 ltr %r5, %r5 C < 256 bytes to copy? je L(1) L(top): mvc 0(256, rp), 0(up) la rp, 256(rp) la up, 256(up) brct %r5, L(top) L(1): bras %r5, L(2) C make r5 point to mvc insn mvc 0(1, rp), 0(up) L(2): ex %r4, 0(%r5) C execute mvc with length ((n-1) mod 256)+1 L(rtn): br %r14 EPILOGUE()
; A201476: Primes of the form 2n^2 + 9. ; Submitted by Jamie Morken(w4) ; 11,17,41,59,107,137,251,347,401,521,587,809,977,1259,1361,1931,2459,2897,3209,3371,3881,4241,5009,5417,6737,6971,7451,9257,10091,10667,11867,12491,12809,13457,15497,16937,17681,18059,20411,21227,22481,22907,25097,26459,26921,31259,33809,37547,38651,39209,42641,47441,49307,49937,53147,55787,57131,57809,61961,63377,64091,74507,84059,89051,89897,92459,100361,102161,103067,104891,108587,110459,122027,123017,126011,134171,135209,144731,146891,147977,157931,163601,167051,170537,171707,181211,182417 mov $1,2 mov $2,332203 mov $5,10 mov $6,2 lpb $2 mov $3,$6 seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0. sub $0,$3 add $1,4 mov $4,$0 max $4,0 cmp $4,$0 mul $2,$4 sub $2,18 add $5,$1 mov $6,$5 lpe mov $0,$5 add $0,1
;------------------------------------------------------------------------------ ; ; 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: ; ; ReadMm5.Asm ; ; Abstract: ; ; AsmReadMm5 function ; ; Notes: ; ;------------------------------------------------------------------------------ .code ;------------------------------------------------------------------------------ ; UINT64 ; EFIAPI ; AsmReadMm5 ( ; VOID ; ); ;------------------------------------------------------------------------------ AsmReadMm5 PROC ; ; 64-bit MASM doesn't support MMX instructions, so use opcode here ; DB 48h, 0fh, 7eh, 0e8h ret AsmReadMm5 ENDP END
; A049013: Duplicate of A020735. ; 5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51 mov $1,$0 add $1,$0 add $1,5
// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/common/media_galleries/picasa_types.h" #include <utility> #include "base/logging.h" #include "chrome/common/media_galleries/pmp_constants.h" namespace picasa { namespace { base::File OpenFile(const base::FilePath& directory_path, const std::string& suffix) { base::FilePath path = directory_path.Append(base::FilePath::FromUTF8Unsafe( std::string(kPicasaAlbumTableName) + "_" + suffix)); return base::File(path, base::File::FLAG_OPEN | base::File::FLAG_READ); } base::File OpenColumnFile(const base::FilePath& directory_path, const std::string& column_name) { return OpenFile(directory_path, column_name + "." + kPmpExtension); } } // namespace const char kPicasaDatabaseDirName[] = "db3"; const char kPicasaTempDirName[] = "tmp"; const char kPicasaAlbumTableName[] = "albumdata"; const char kAlbumTokenPrefix[] = "]album:"; const char kPicasaINIFilename[] = ".picasa.ini"; const uint32_t kAlbumCategoryAlbum = 0; const uint32_t kAlbumCategoryFolder = 2; const uint32_t kAlbumCategoryInvalid = 0xffff; // Sentinel value. AlbumInfo::AlbumInfo() { } AlbumInfo::AlbumInfo(const std::string& name, const base::Time& timestamp, const std::string& uid, const base::FilePath& path) : name(name), timestamp(timestamp), uid(uid), path(path) { } AlbumInfo::AlbumInfo(const AlbumInfo& other) = default; AlbumInfo::~AlbumInfo() { } AlbumTableFiles::AlbumTableFiles() { } AlbumTableFiles::AlbumTableFiles(const base::FilePath& directory_path) : indicator_file(OpenFile(directory_path, "0")), category_file(OpenColumnFile(directory_path, "category")), date_file(OpenColumnFile(directory_path, "date")), filename_file(OpenColumnFile(directory_path, "filename")), name_file(OpenColumnFile(directory_path, "name")), token_file(OpenColumnFile(directory_path, "token")), uid_file(OpenColumnFile(directory_path, "uid")) { } AlbumTableFiles::~AlbumTableFiles() { } AlbumTableFiles::AlbumTableFiles(AlbumTableFiles&& other) : indicator_file(std::move(other.indicator_file)), category_file(std::move(other.category_file)), date_file(std::move(other.date_file)), filename_file(std::move(other.filename_file)), name_file(std::move(other.name_file)), token_file(std::move(other.token_file)), uid_file(std::move(other.uid_file)) {} AlbumTableFiles& AlbumTableFiles::operator=(AlbumTableFiles&& other) { indicator_file = std::move(other.indicator_file); category_file = std::move(other.category_file); date_file = std::move(other.date_file); filename_file = std::move(other.filename_file); name_file = std::move(other.name_file); token_file = std::move(other.token_file); uid_file = std::move(other.uid_file); return *this; } AlbumTableFilesForTransit::AlbumTableFilesForTransit() : indicator_file(IPC::InvalidPlatformFileForTransit()), category_file(IPC::InvalidPlatformFileForTransit()), date_file(IPC::InvalidPlatformFileForTransit()), filename_file(IPC::InvalidPlatformFileForTransit()), name_file(IPC::InvalidPlatformFileForTransit()), token_file(IPC::InvalidPlatformFileForTransit()), uid_file(IPC::InvalidPlatformFileForTransit()) { } } // namespace picasa
.global s_prepare_buffers s_prepare_buffers: push %r14 push %r8 push %rax push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_UC_ht+0x11cfb, %r8 nop nop nop nop cmp $27202, %rdx movw $0x6162, (%r8) nop dec %rcx lea addresses_WT_ht+0xb81b, %rsi lea addresses_WT_ht+0x3a73, %rdi nop sub %rax, %rax mov $86, %rcx rep movsw nop nop nop nop and $52868, %rdi lea addresses_A_ht+0x13adb, %rsi lea addresses_A_ht+0x1011b, %rdi nop nop nop nop xor $46356, %r8 mov $114, %rcx rep movsl nop nop nop nop nop and %r8, %r8 lea addresses_UC_ht+0xefbb, %rsi lea addresses_A_ht+0x145ab, %rdi nop nop and $33925, %rbp mov $74, %rcx rep movsl nop nop nop xor $51318, %rbp pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %rax pop %r8 pop %r14 ret .global s_faulty_load s_faulty_load: push %r11 push %r14 push %r9 push %rbp push %rbx push %rdx push %rsi // Load lea addresses_PSE+0x1b69b, %rdx add $25082, %r11 mov (%rdx), %r9 nop nop nop add $35514, %rsi // Store lea addresses_PSE+0x1cd06, %r14 nop nop nop nop nop add %rbp, %rbp mov $0x5152535455565758, %r9 movq %r9, %xmm0 vmovups %ymm0, (%r14) nop and %rdx, %rdx // Store lea addresses_WC+0xa29b, %rsi nop nop nop sub $45034, %rbx movl $0x51525354, (%rsi) and %r14, %r14 // Store lea addresses_PSE+0x94ab, %r11 nop nop nop nop dec %rbx movl $0x51525354, (%r11) nop nop nop add %r11, %r11 // Store lea addresses_WC+0xea6b, %rbx nop nop nop nop inc %rdx mov $0x5152535455565758, %rsi movq %rsi, %xmm1 movntdq %xmm1, (%rbx) nop nop and %r11, %r11 // Store lea addresses_WT+0xfa9b, %r9 nop nop add $47852, %r14 movw $0x5152, (%r9) nop add $58083, %rsi // Faulty Load mov $0x5d4da1000000029b, %r11 nop cmp $48991, %r14 mov (%r11), %rbx lea oracles, %rbp and $0xff, %rbx shlq $12, %rbx mov (%rbp,%rbx,1), %rbx pop %rsi pop %rdx pop %rbx pop %rbp pop %r9 pop %r14 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_NC', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'} {'src': {'NT': True, 'same': False, 'congruent': 10, 'type': 'addresses_PSE', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_PSE', 'AVXalign': False, 'size': 32}} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 10, 'type': 'addresses_WC', 'AVXalign': False, 'size': 4}} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 3, 'type': 'addresses_PSE', 'AVXalign': True, 'size': 4}} {'OP': 'STOR', 'dst': {'NT': True, 'same': False, 'congruent': 4, 'type': 'addresses_WC', 'AVXalign': False, 'size': 16}} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_WT', 'AVXalign': False, 'size': 2}} [Faulty Load] {'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_NC', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 2}} {'src': {'same': False, 'congruent': 7, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_WT_ht'}} {'src': {'same': False, 'congruent': 4, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 7, 'type': 'addresses_A_ht'}} {'src': {'same': False, 'congruent': 5, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 4, 'type': 'addresses_A_ht'}} {'54': 21762, '00': 67} 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 */
; testing the multiplication ;------------------------------------ .org 1000 jp start #include "functions.inc" start: ld d,10 ld e,10 call multiply ; checks that the result is D * E and is stored in HL halt version: .db "V1.0",0
<% import collections import pwnlib.abi import pwnlib.constants import pwnlib.shellcraft %> <%docstring>newfstatat(vararg_0, vararg_1, vararg_2, vararg_3, vararg_4) -> str Invokes the syscall newfstatat. See 'man 2 newfstatat' for more information. Arguments: vararg(int): vararg Returns: long </%docstring> <%page args="vararg_0=None, vararg_1=None, vararg_2=None, vararg_3=None, vararg_4=None"/> <% abi = pwnlib.abi.ABI.syscall() stack = abi.stack regs = abi.register_arguments[1:] allregs = pwnlib.shellcraft.registers.current() can_pushstr = [] can_pushstr_array = [] argument_names = ['vararg_0', 'vararg_1', 'vararg_2', 'vararg_3', 'vararg_4'] argument_values = [vararg_0, vararg_1, vararg_2, vararg_3, vararg_4] # Load all of the arguments into their destination registers / stack slots. register_arguments = dict() stack_arguments = collections.OrderedDict() string_arguments = dict() dict_arguments = dict() array_arguments = dict() syscall_repr = [] for name, arg in zip(argument_names, argument_values): if arg is not None: syscall_repr.append('%s=%r' % (name, arg)) # If the argument itself (input) is a register... if arg in allregs: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[index] = arg # The argument is not a register. It is a string value, and we # are expecting a string value elif name in can_pushstr and isinstance(arg, str): string_arguments[name] = arg # The argument is not a register. It is a dictionary, and we are # expecting K:V paris. elif name in can_pushstr_array and isinstance(arg, dict): array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()] # The arguent is not a register. It is a list, and we are expecting # a list of arguments. elif name in can_pushstr_array and isinstance(arg, (list, tuple)): array_arguments[name] = arg # The argument is not a register, string, dict, or list. # It could be a constant string ('O_RDONLY') for an integer argument, # an actual integer value, or a constant. else: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[target] = arg # Some syscalls have different names on various architectures. # Determine which syscall number to use for the current architecture. for syscall in ['SYS_newfstatat']: if hasattr(pwnlib.constants, syscall): break else: raise Exception("Could not locate any syscalls: %r" % syscalls) %> /* newfstatat(${', '.join(syscall_repr)}) */ %for name, arg in string_arguments.items(): ${pwnlib.shellcraft.pushstr(arg, append_null=('\x00' not in arg))} ${pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)} %endfor %for name, arg in array_arguments.items(): ${pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)} %endfor %for name, arg in stack_arguments.items(): ${pwnlib.shellcraft.push(arg)} %endfor ${pwnlib.shellcraft.setregs(register_arguments)} ${pwnlib.shellcraft.syscall(syscall)}
/******************************************************************************* * Copyright (c) 2015-2018 Skymind, Inc. * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at * https://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. * * SPDX-License-Identifier: Apache-2.0 ******************************************************************************/ // // @author raver119@gmail.com // #include <op_boilerplate.h> #include <types/float16.h> #include <ops/declarable/helpers/batched_gemm.h> #include <helpers/BlasHelper.h> namespace nd4j { namespace ops { namespace helpers { template <typename T> void bgemm_(const std::vector<NDArray*>& vA, const std::vector<NDArray*>& vB, std::vector<NDArray*>& vC, const NDArray* alphas, const NDArray* betas, int transA, int transB, int M, int N, int K, const int lda, const int ldb, const int ldc) { int batchSize = vA.size(); if (BlasHelper::getInstance()->hasBatchedGEMM<T>()) { auto arr = vA.at(0); CBLAS_TRANSPOSE *tA, *tB; int *tM, *tN, *tK, *tldA, *tldB, *tldC, *tsize; // mkl requires mnk etc as arrays, cuda doesn't ALLOCATE(tA, arr->getContext()->getWorkspace(), batchSize, CBLAS_TRANSPOSE); ALLOCATE(tB, arr->getContext()->getWorkspace(), batchSize, CBLAS_TRANSPOSE); ALLOCATE(tM, arr->getContext()->getWorkspace(), batchSize, int); ALLOCATE(tN, arr->getContext()->getWorkspace(), batchSize, int); ALLOCATE(tK, arr->getContext()->getWorkspace(), batchSize, int); ALLOCATE(tldA, arr->getContext()->getWorkspace(), batchSize, int); ALLOCATE(tldB, arr->getContext()->getWorkspace(), batchSize, int); ALLOCATE(tldC, arr->getContext()->getWorkspace(), batchSize, int); ALLOCATE(tsize, arr->getContext()->getWorkspace(), batchSize, int); shape::fill(tA, (CBLAS_TRANSPOSE) transA, batchSize); shape::fill(tB, (CBLAS_TRANSPOSE) transB, batchSize); shape::fill(tM, M, batchSize); shape::fill(tN, N, batchSize); shape::fill(tK, K, batchSize); shape::fill(tldA, lda, batchSize); shape::fill(tldB, ldb, batchSize); shape::fill(tldC, ldc, batchSize); shape::fill(tsize, 1, batchSize); std::vector<T*> buffersA(batchSize); std::vector<T*> buffersB(batchSize); std::vector<T*> buffersC(batchSize); for (int e = 0; e < batchSize; e++) { buffersA[e] = reinterpret_cast<T *>(vA[e]->buffer()); buffersB[e] = reinterpret_cast<T *>(vB[e]->buffer()); buffersC[e] = reinterpret_cast<T *>(vC[e]->buffer()); } if (std::is_same<T, double>::value) { BlasHelper::getInstance()->dgemmBatched()(CblasColMajor, tA, tB, tM, tN, tK, (double *) alphas->getBuffer(), (double **) buffersA.data(), tldA, (double **) buffersB.data(), tldB, (double *) betas->getBuffer(),(double **) buffersC.data(), tldC, vA.size(), tsize); } else if (std::is_same<T, float >::value) { BlasHelper::getInstance()->sgemmBatched()(CblasColMajor, tA, tB, tM, tN, tK, (float *) alphas->getBuffer(), (float **) buffersA.data(), tldA, (float **) buffersB.data(), tldB, (float *) betas->getBuffer(), (float **) buffersC.data(), tldC, vA.size(), tsize); } // release temporary arrays RELEASE(tA, arr->getContext()->getWorkspace()); RELEASE(tB, arr->getContext()->getWorkspace()); RELEASE(tM, arr->getContext()->getWorkspace()); RELEASE(tN, arr->getContext()->getWorkspace()); RELEASE(tK, arr->getContext()->getWorkspace()); RELEASE(tldA, arr->getContext()->getWorkspace()); RELEASE(tldB, arr->getContext()->getWorkspace()); RELEASE(tldC, arr->getContext()->getWorkspace()); RELEASE(tsize, arr->getContext()->getWorkspace()); } else { CBLAS_TRANSPOSE tA = (CBLAS_TRANSPOSE) transA; CBLAS_TRANSPOSE tB = (CBLAS_TRANSPOSE) transB; int vaSize = vA.size(); PRAGMA_OMP_PARALLEL_FOR for (int p = 0; p < vaSize; ++p) { auto A = reinterpret_cast<T*>(vA.at(p)->buffer()); auto B = reinterpret_cast<T*>(vB.at(p)->buffer()); auto C = reinterpret_cast<T*>(vC.at(p)->buffer()); auto alpha = alphas->e<T>(p); auto beta = betas->e<T>(p); for (int m = 0; m < M; ++m) { for (int n = 0; n < N; ++n) { T c_mnp = 0; PRAGMA_OMP_SIMD for (int k = 0; k < K; ++k) c_mnp += A[tA == CblasNoTrans ? (m + k * lda) : (m * lda + k)] * B[tB == CblasNoTrans ? (k + n * ldb) : (k * ldb + n)]; C[m + n * ldc] = alpha * c_mnp + beta * C[m + n * ldc]; } } } } } void bgemm(const std::vector<NDArray*>& vA, const std::vector<NDArray*>& vB, std::vector<NDArray*>& vC, const NDArray* alphas, const NDArray* betas, int transA, int transB, int M, int N, int K, const int lda, const int ldb, const int ldc) { auto xType = vA.at(0)->dataType(); BUILD_SINGLE_SELECTOR(xType, bgemm_, (vA, vB, vC, alphas, betas, transA, transB, M, N, K, lda, ldb, ldc), FLOAT_TYPES); } BUILD_SINGLE_TEMPLATE(template void bgemm_, (const std::vector<NDArray*>& vA, const std::vector<NDArray*>& vB, std::vector<NDArray*>& vC, const NDArray* alphas, const NDArray* betas, int transA, int transB, int M, int N, int K, const int lda, const int ldb, const int ldc), FLOAT_TYPES); } } }
; A316457: Expansion of x*(31 + 326*x + 336*x^2 + 26*x^3 + x^4) / (1 - x)^6. ; 31,512,2943,10624,29375,68256,140287,263168,459999,760000,1199231,1821312,2678143,3830624,5349375,7315456,9821087,12970368,16879999,21680000,27514431,34542112,42937343,52890624,64609375,78318656,94261887,112701568,133919999,158220000,185925631,217382912,252960543,293050624,338069375,388457856,444682687,507236768,576639999,653440000,738212831,831563712,934127743,1046570624,1169589375,1303913056,1450303487,1609555968,1782499999,1970000000,2172956031,2392304512,2629018943,2884110624,3158629375,3453664256,3770344287,4109839168,4473359999,4862160000,5277535231,5720825312,6193414143,6696730624,7232249375,7801491456,8406025087,9047466368,9727479999,10447780000,11210130431,12016346112,12868293343,13767890624,14717109375,15717974656,16772565887,17883017568,19051519999,20280320000,21571721631,22928086912,24351836543,25845450624,27411469375,29052493856,30771186687,32570272768,34452539999,36420840000,38478088831,40627267712,42871423743,45213670624,47657189375,50205229056,52861107487,55628211968,58509999999,61510000000 mov $3,$0 sub $3,1 add $3,$0 mov $9,$0 lpb $3 sub $3,1 add $5,$0 lpe add $6,$5 lpb $5 sub $5,1 add $6,5 lpe mov $0,$6 add $0,3 mov $1,5 lpb $0 sub $0,1 add $1,5 lpe add $1,11 mov $2,150 mov $8,$9 lpb $2 add $1,$8 sub $2,1 lpe mov $4,$9 lpb $4 sub $4,1 add $7,$8 lpe mov $2,120 mov $8,$7 lpb $2 add $1,$8 sub $2,1 lpe mov $4,$9 mov $7,0 lpb $4 sub $4,1 add $7,$8 lpe mov $2,130 mov $8,$7 lpb $2 add $1,$8 sub $2,1 lpe mov $4,$9 mov $7,0 lpb $4 sub $4,1 add $7,$8 lpe mov $2,45 mov $8,$7 lpb $2 add $1,$8 sub $2,1 lpe mov $4,$9 mov $7,0 lpb $4 sub $4,1 add $7,$8 lpe mov $2,6 mov $8,$7 lpb $2 add $1,$8 sub $2,1 lpe mov $0,$1
; ; ANSI Video handling for the Commodore 128 (Z80 mode) ; By Stefano Bodrato - 22/08/2001 ; ; Scrollup ; ; ; $Id: f_ansi_scrollup.asm,v 1.6 2016/06/12 16:06:42 dom Exp $ ; SECTION code_clib PUBLIC ansi_SCROLLUP .ansi_SCROLLUP ld hl,$2000+40 ; Text ld de,$2000 ld bc,40*24 ldir ld h,d ld l,e ld b,40 .reslloop ld (hl),32 inc hl djnz reslloop ld hl,$1000+40 ; Color attributes ld de,$1000 ld bc,40*24 ldir ld h,d ld l,e ld b,40 .reslloop2 ld (hl),1 inc hl djnz reslloop2 ret
/* * sys_pitmgr_port.cpp * * Created on: 2019年12月5日 * Author: CkovMk */ #include "sys_pitmgr.hpp" #if defined(HITSIC_USE_PITMGR) && (HITSIC_USE_PITMGR > 0) #ifdef __cplusplus extern "C"{ #endif #if defined(HITSIC_PITMGR_DEFAULT_IRQ) && (HITSIC_PITMGR_DEFAULT_IRQ > 0) void LPTMR0_IRQHandler(void) { PIT_ClearStatusFlags(PIT, kPIT_Chnl_2, kPIT_TimerFlag); pitMgr_t::isr(); } #endif // ! HTISIC_PITMGR_USE_IRQHANDLER #ifdef __cplusplus } #endif #endif // ! HITSIC_USE_PITMGR
; A163180: a(n) = tau(n) + Sum_{k=1..n} (n mod k). ; 1,2,3,4,6,7,10,12,15,17,24,23,30,35,40,41,53,53,66,67,74,81,100,93,106,116,129,130,153,146,169,173,188,201,222,207,235,252,273,266,299,292,327,334,345,362,405,384,417,426,453,460,507,500,533,528,557,582,637,598,647 add $0,1 mov $2,$0 lpb $0 mov $3,$2 mov $4,$0 cmp $4,0 add $0,$4 mod $3,$0 sub $0,1 mov $4,$3 cmp $4,0 add $3,$4 add $5,$3 lpe mov $0,$5
; $Id: tstX86-FpuSaveRestoreA.asm $ ;; @file ; tstX86-FpuSaveRestore - Experimenting with saving and restoring FPU, assembly bits. ; ; ; Copyright (C) 2013-2017 Oracle Corporation ; ; This file is part of VirtualBox Open Source Edition (OSE), as ; available from http://www.virtualbox.org. This file is free software; ; you can redistribute it and/or modify it under the terms of the GNU ; General Public License (GPL) as published by the Free Software ; Foundation, in version 2 as it comes in the "COPYING" file of the ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. ; ;******************************************************************************* ;* Header Files * ;******************************************************************************* %include "iprt/asmdefs.mac" %include "iprt/x86.mac" ;******************************************************************************* ;* Global Variables * ;******************************************************************************* BEGINCODE g_r80_Zero: dt 0.0 g_r80_One: dt 1.0 BEGINCODE ;; Prepares a FPU exception. BEGINPROC MyFpuPrepXcpt fld tword [g_r80_One xWrtRIP] fld tword [g_r80_Zero xWrtRIP] fdiv st0 ret ENDPROC MyFpuPrepXcpt ;; Same as above, just different address. BEGINPROC MyFpuPrepXcpt2 fld tword [g_r80_One xWrtRIP] fld tword [g_r80_Zero xWrtRIP] fdiv st0 ret ENDPROC MyFpuPrepXcpt2 BEGINPROC MyFpuSave %ifdef ASM_CALL64_MSC o64 fxsave [rcx] %elifdef ASM_CALL64_GCC o64 fxsave [rdi] %elifdef RT_ARCH_X86 mov ecx, [esp + 4] fxsave [ecx] %else %error "Unsupported architecture." bad arch %endif ret ENDPROC MyFpuSave BEGINPROC MyFpuStoreEnv %ifdef ASM_CALL64_MSC fstenv [rcx] %elifdef ASM_CALL64_GCC fstenv [rdi] %elifdef RT_ARCH_X86 mov ecx, [esp + 4] fstenv [ecx] %else %error "Unsupported architecture." bad arch %endif ret ENDPROC MyFpuStoreEnv BEGINPROC MyFpuRestore %ifdef ASM_CALL64_MSC o64 fxrstor [rcx] %elifdef ASM_CALL64_GCC o64 fxrstor [rdi] %elifdef RT_ARCH_X86 mov ecx, [esp + 4] fxrstor [ecx] %else %error "Unsupported architecture." bad arch %endif ret ENDPROC MyFpuRestore BEGINPROC MyFpuLoadEnv %ifdef ASM_CALL64_MSC fldenv [rcx] %elifdef ASM_CALL64_GCC fldenv [rdi] %elifdef RT_ARCH_X86 mov ecx, [esp + 4] fldenv [ecx] %else %error "Unsupported architecture." bad arch %endif ret ENDPROC MyFpuLoadEnv
ORG 0H LJMP INIT ORG 000BH LJMP TO_ISR ORG 0030H INIT: MOV TMOD, #01H MOV TH0, #0H MOV TL0, #0H MOV IE, #82H //Initializes ENABLE and TIMER 1 SETB TR0 //start timer 0 CLR F0 MAIN: JB P3.7, BACKUP CLR C MOV A, P1 // Reads Sensor/ADC value CPL A MOV R5, A MOV P0, R5 // LED displays ADC value RRC A // PV/2 CLR C MOV R3, A // Loads PV/2 value into R3 MOV A, P2 // Reads switches RRC A // SP/2 CLR C MOV R7, A // Moves SP into scratch register SP = R7 SUBB A, R3// ERROR = (SP/2) - (PV/2) CLR C MOV R6, A // Moves ERROR into scratch register R6 ADD A, #127 //Manipulative Variable CLR C MOV R1, A // R1 <-- MV SETB P3.6 SETB P3.7 BACKUP: SJMP MAIN TO_ISR: CLR TR0 JB F0, LOW_P HIGH_P: //WANTS TO GO TO HIGH PULSE FROM LOW PULSE MOV A, #0FFH SETB P3.4 SETB F0 CLR C //CLEARS CARRY FLAG SUBB A, R1 // subtracts FF and A = A MOV TL0, A MOV TH0, #0FFH SETB TR0 CLR P3.7 CLR P3.6 RETI LOW_P: //WANTS TO GO LOW PULSE FROM HIGH PULSE CLR F0 //CLEARS FLAG FOR NEXT HIGH PULSE CLR P3.4 MOV TL0, R1 //TIMER = PWM_VALUE MOV TH0, #0FFH SETB TR0 RETI END
; A028859: a(n+2) = 2*a(n+1) + 2*a(n); a(0) = 1, a(1) = 3. ; Submitted by Christian Krause ; 1,3,8,22,60,164,448,1224,3344,9136,24960,68192,186304,508992,1390592,3799168,10379520,28357376,77473792,211662336,578272256,1579869184,4316282880,11792304128,32217174016,88018956288,240472260608,656982433792,1794909388800,4903783645184,13397386067968,36602339426304,99999450988544,273203580829696,746406063636480,2039219288932352,5571250705137664,15220939988140032,41584381386555392,113610642749390848,310390048271892480,848001382042566656,2316782860628918272,6329568485342969856 mov $2,1 mov $4,1 lpb $0 sub $0,1 mul $2,2 mov $3,$4 mov $4,$2 add $2,$3 lpe mov $0,$2
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.22.27905.0 TITLE D:\Project\VS\lab3\practice2.c .686P .XMM include listing.inc .model flat INCLUDELIB MSVCRTD INCLUDELIB OLDNAMES _DATA SEGMENT COMM _a:DWORD _DATA ENDS msvcjmc SEGMENT __F66CEB67_corecrt_stdio_config@h DB 01H __101834BA_corecrt_wstdio@h DB 01H __AD6A91B7_stdio@h DB 01H __A831ACCD_practice2@c DB 01H msvcjmc ENDS PUBLIC _main PUBLIC __JustMyCode_Default EXTRN @__CheckForDebuggerJustMyCode@4:PROC EXTRN __RTC_CheckEsp:PROC EXTRN __RTC_InitBase:PROC EXTRN __RTC_Shutdown:PROC ; COMDAT rtc$TMZ rtc$TMZ SEGMENT __RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown rtc$TMZ ENDS ; COMDAT rtc$IMZ rtc$IMZ SEGMENT __RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase rtc$IMZ ENDS ; Function compile flags: /Odt ; COMDAT __JustMyCode_Default _TEXT SEGMENT __JustMyCode_Default PROC ; COMDAT push ebp mov ebp, esp pop ebp ret 0 __JustMyCode_Default ENDP _TEXT ENDS ; Function compile flags: /Odtp /RTCsu /ZI /ZX ; File D:\Project\VS\lab3\practice2.c ; COMDAT _main _TEXT SEGMENT _argc$ = 8 ; size = 4 _argv$ = 12 ; size = 4 _main PROC ; COMDAT ; 15 : { push ebp mov ebp, esp sub esp, 204 ; 000000ccH push ebx push esi push edi lea edi, DWORD PTR [ebp-204] mov ecx, 51 ; 00000033H mov eax, -858993460 ; ccccccccH rep stosd mov ecx, OFFSET __A831ACCD_practice2@c call @__CheckForDebuggerJustMyCode@4 ; 16 : int i; ; 17 : ; 18 : a = 5; mov DWORD PTR _a, 5 ; 19 : ; 20 : return 0; xor eax, eax ; 21 : } pop edi pop esi pop ebx add esp, 204 ; 000000ccH cmp ebp, esp call __RTC_CheckEsp mov esp, ebp pop ebp ret 0 _main ENDP _TEXT ENDS END
.MODELSMALL .DATA PA EQU 0D800H PB EQU 0D801H PC EQU 0D802H CW EQU 0D803H .CODE MOV AX,@DATA MOV DS,AX MOV AL,82H ;port B as input, rest(Port A) are outputs MOV DX,CW OUT DX,AL MOV DX,PB ;reading input form LCI IN AL,DX ADD AL,00H JPE evenP ;jump parity equal MOV AL,00H ;display '00' as odd parity on PA MOV DX,PA OUT DX,AL JMP EXIT evenP: MOV AL,0FFH ;display 'ff' as even parity PA MOV DX,PA OUT DX,AL EXIT: MOV AH,4CH INT 21H END
[bits 32] [org 0x100] je label dd label dw label dd 3.14159 shl ax, 1 label: mov byte [label2+ebx], 1 resb 1 [section .data align=16] db 5 dd label2 [section .text] mov dword [label2], 5 call label je near label2 [section .bss] label2: resd 1 dd 1 mov cx, 5 [global label2] [extern label3] [section .data] times 65536 db 0
; A070538: a(n) = n^4 mod 19. ; 0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16,5,9,17,4,7,11,6,6,11,7,4,17,9,5,16,1,0,1,16 pow $0,4 mod $0,19 mov $1,$0
%ifdef CONFIG { "RegData": { "RAX": "0x4142434445464748", "RDX": "0x0", "RDI": "0xE0000018", "RSI": "0xE0000008" }, "MemoryRegions": { "0x100000000": "4096" } } %endif mov rdx, 0xe0000000 mov rax, 0x4142434445464748 mov [rdx + 8 * 0], rax mov rax, 0x5152535455565758 mov [rdx + 8 * 1], rax mov rax, 0x0 mov [rdx + 8 * 2], rax mov [rdx + 8 * 3], rax lea rdi, [rdx + 8 * 2] lea rsi, [rdx + 8 * 0] cld movsd ; rdi <- rsi movsd mov rax, [rdx + 8 * 2] mov rdx, [rdx + 8 * 3] hlt
; A022349: Fibonacci sequence beginning 0, 15. ; Submitted by Jon Maiga ; 0,15,15,30,45,75,120,195,315,510,825,1335,2160,3495,5655,9150,14805,23955,38760,62715,101475,164190,265665,429855,695520,1125375,1820895,2946270,4767165,7713435,12480600,20194035,32674635,52868670,85543305,138411975,223955280,362367255,586322535,948689790,1535012325,2483702115,4018714440,6502416555,10521130995,17023547550,27544678545,44568226095,72112904640,116681130735,188794035375,305475166110,494269201485,799744367595,1294013569080,2093757936675,3387771505755,5481529442430,8869300948185 mov $3,1 lpb $0 sub $0,1 mov $2,$3 add $3,$1 mov $1,$2 lpe mov $0,$1 mul $0,15
; A197879: Parity of floor(n*sqrt(8)). ; 0,1,0,1,0,0,1,0,1,0,1,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,1,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,0,1,0,0 mul $0,2 add $0,1 seq $0,87057 ; Smallest number whose square is larger than 2*n^2. sub $0,1 mod $0,2
/* ***** BEGIN LICENSE BLOCK ***** Version: MPL 1.1/LGPL 2.1/GPL 2.0 The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with ... for the specific language governing rights and limitations under the License. The Original Code is for LuminousForts. The Initial Developer of the Original Code is Hekar Khani. Portions created by the Hekar Khani are Copyright (C) 2010 Hekar Khani. All Rights Reserved. Contributor(s): Hekar Khani <hekark@gmail.com> Alternatively, the contents of this file may be used under the terms of either of the GNU General Public License Version 2 or later (the "GPL"), ... the terms of any one of the MPL, the GPL or the LGPL. ***** END LICENSE BLOCK ***** */ /*=============================================================== Client HUD Element Progress bar while freezing a block in "Combat Phase" Last Updated Dec 28, 2009 =================================================================*/ #include "cbase.h" #include <vgui/ISurface.h> #include "c_hl2mp_player.h" #include "Mod/Hud_FreezeProgress.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" DECLARE_HUDELEMENT( CHudFreezeProgress ); DECLARE_HUD_MESSAGE( CHudFreezeProgress, UpdateFreezeProgress ); CHudFreezeProgress::CHudFreezeProgress( const char* pElementName ) : CModHudElement( pElementName, HUDELEM_FREEZEPROGRESS ), BaseClass( NULL, "HudFreezeProgress" ) { SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD | HIDEHUD_NEEDSUIT | HIDEHUD_BUILDPHASE ); vgui::Panel *pParent = g_pClientMode->GetViewport(); SetParent( pParent ); SetVisible( false ); SetEnabled( true ); } CHudFreezeProgress::~CHudFreezeProgress() { } void CHudFreezeProgress::Init( void ) { HOOK_HUD_MESSAGE( CHudFreezeProgress, UpdateFreezeProgress ); } void CHudFreezeProgress::Reset( void ) { m_bShow = false; m_iProgressType = SFH_FREEZEPROGRESS_NONE; m_flProgress = 0; } bool CHudFreezeProgress::ShouldDraw (void) { C_HL2MP_Player *pPlayer = C_HL2MP_Player::GetLocalHL2MPPlayer(); if ( !pPlayer ) return false; return m_bShow & CModHudElement::ShouldDraw(); } void CHudFreezeProgress::Paint( void ) { if ( !m_bShow ) { return; } C_HL2MP_Player *pPlayer = C_HL2MP_Player::GetLocalHL2MPPlayer(); if ( !pPlayer ) return; int w, h; GetSize( w, h ); m_Foreground = LocalTeamColor(); // Draw the Background DrawBox( 0, 0, w, h, m_Background, 170, false ); // Draw the ProgressBar float progresslength = 0; if ( m_iProgressType == SFH_FREEZEPROGRESS_HEALING ) { progresslength = m_flProgress / 100.0f * m_flBarWidth; } else if ( m_iProgressType == SFH_FREEZEPROGRESS_FREEZING ) { progresslength = m_flProgress / 100.0f * m_flBarWidth; } else if ( m_iProgressType == SFH_FREEZEPROGRESS_UNFREEZING ) { progresslength = m_flBarWidth - m_flProgress / 100.0f * m_flBarWidth; } else if ( m_iProgressType == SFH_FREEZEPROGRESS_UNFREEZING_ENEMY ) { progresslength = m_flBarWidth - m_flProgress / 100.0f * m_flBarWidth; int otherteamnum = GetOtherTeamNumber( pPlayer->GetTeamNumber() ); if ( otherteamnum == TEAM_BLUE ) { m_Foreground = m_BlueProgressForeground; } else if ( otherteamnum == TEAM_RED ) { m_Foreground = m_RedProgressForeground; } } vgui::surface()->DrawSetColor( m_Background ); vgui::surface()->DrawFilledRect( 0, 0, w, h ); vgui::surface()->DrawSetColor( m_Foreground ); vgui::surface()->DrawFilledRect( m_flBarX, m_flBarY, m_flBarX + progresslength, m_flBarY + m_flBarHeight ); vgui::surface()->DrawSetColor( m_ProgressBackground ); vgui::surface()->DrawFilledRect(m_flBarX + progresslength, m_flBarY, m_flBarX + m_flBarWidth, m_flBarY + m_flBarHeight); #if 0 if ( pPlayer->GetTeamNumber() == TEAM_BLUE ) { DrawBrokenBorder( m_BlueBorder, 0, 0, w, h ); } else if ( pPlayer->GetTeamNumber() == TEAM_RED ) { DrawBrokenBorder( m_RedBorder, 0, 0, w, h ); } #endif // 0 } void CHudFreezeProgress::ApplySchemeSettings( vgui::IScheme* scheme ) { BaseClass::ApplySchemeSettings( scheme ); SetPaintBackgroundEnabled( false ); } /* * Freeze Progress Message * Updates the Progress of the freeze status (meant for combat phase) * Protocol: * Show/Hide - Byte * Type - Integer (FreezeProgressType_t) * Progress - Float (0 - 100) */ void CHudFreezeProgress::MsgFunc_UpdateFreezeProgress( bf_read& data ) { if ( data.ReadByte() ) { SetVisible( true ); m_bShow = true; } else { SetVisible( false ); m_bShow = false; } m_iProgressType = data.ReadLong(); m_flProgress = data.ReadFloat(); }
; ; ANSI Video handling for the the MicroBEE ; ; Stefano Bodrato - 2016 ; ; Handles colors referring to current PAPER/INK/etc. settings ; ; Scrollup ; ; ; $Id: f_ansi_scrollup.asm,v 1.2 2016-11-17 09:39:03 stefano Exp $ ; SECTION code_clib PUBLIC ansi_SCROLLUP EXTERN bee_attr EXTERN ansicolumns .ansi_SCROLLUP ld hl,$f000+ansicolumns ld de,$f000 ld bc,ansicolumns*24 ldir ld hl,$F000+ansicolumns*24 ld (hl),32 ;' ' ld d,h ld e,l inc de ld bc,ansicolumns-1 ldir ld a,64 out (8),a ld a,(bee_attr) ld hl,$f800+ansicolumns ld de,$f800 ld bc,ansicolumns*24 ldir ld hl,$F800+ansicolumns*24 ld (hl),a ld d,h ld e,l inc de ld bc,ansicolumns-1 ldir xor a out (8),a ret
; A239745: a(n) = (3*2^(n+2) + n*(n+5))/2 - 6. ; 0,9,25,54,108,211,411,804,1582,3129,6213,12370,24672,49263,98431,196752,393378,786613,1573065,3145950,6291700,12583179,25166115,50331964,100663638,201326961,402653581,805306794,1610613192,3221225959,6442451463,12884902440,25769804362,51539608173,103079215761,206158430902,412316861148,824633721603,1649267442475,3298534884180,6597069767550,13194139534249,26388279067605,52776558134274,105553116267568,211106232534111,422212465067151,844424930133184,1688849860265202,3377699720529189,6755399441057113,13510798882112910,27021597764224452,54043195528447483,108086391056893491,216172782113785452,432345564227569318,864691128455136993,1729382256910272285,3458764513820542810,6917529027641083800,13835058055282165719,27670116110564329495,55340232221128656984,110680464442257311898,221360928884514621661,442721857769029241121,885443715538058479974,1770887431076116957612,3541774862152233912819,7083549724304467823163,14167099448608935643780,28334198897217871284942,56668397794435742567193,113336795588871485131621,226673591177742970260402,453347182355485940517888,906694364710971881032783,1813388729421943762062495,3626777458843887524121840,7253554917687775048240450,14507109835375550096477589,29014219670751100192951785,58028439341502200385900094,116056878683004400771796628,232113757366008801543589611,464227514732017603087175491,928455029464035206174347164,1856910058928070412348690422,3713820117856140824697376849,7427640235712281649394749613,14855280471424563298789495050,29710560942849126597578985832,59421121885698253195157967303,118842243771396506390315930151,237684487542793012780631855752,475368975085586025561263706858,950737950171172051122527408973,1901475900342344102245054813105,3802951800684688204490109621270 lpb $0 add $1,$2 add $1,$0 sub $0,1 add $1,8 add $2,3 mul $2,2 lpe mov $0,$1
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r14 push %r15 push %r9 push %rcx push %rdi push %rdx push %rsi lea addresses_WC_ht+0x190f1, %r9 nop nop nop and %rcx, %rcx mov $0x6162636465666768, %rdx movq %rdx, %xmm3 movups %xmm3, (%r9) nop sub %r15, %r15 lea addresses_WT_ht+0x82f7, %rsi lea addresses_WT_ht+0xd71, %rdi nop nop nop nop nop add %r15, %r15 mov $75, %rcx rep movsl nop nop add %r9, %r9 lea addresses_A_ht+0x26f7, %r15 nop nop nop nop nop add $38455, %r12 movb $0x61, (%r15) nop nop nop xor %rdx, %rdx lea addresses_A_ht+0x11651, %rdx nop nop nop nop nop dec %rsi mov $0x6162636465666768, %r12 movq %r12, %xmm4 movups %xmm4, (%rdx) dec %rdx lea addresses_D_ht+0x3af7, %r15 clflush (%r15) xor $25259, %r9 movl $0x61626364, (%r15) nop nop xor $29556, %r9 lea addresses_WT_ht+0x14e92, %rcx nop xor $31471, %rdx vmovups (%rcx), %ymm0 vextracti128 $1, %ymm0, %xmm0 vpextrq $0, %xmm0, %r15 xor %rdi, %rdi lea addresses_WT_ht+0x3017, %rsi lea addresses_A_ht+0xbe5, %rdi nop nop cmp $36931, %r14 mov $46, %rcx rep movsq nop nop dec %rcx lea addresses_D_ht+0x3203, %rsi nop nop nop and %r12, %r12 vmovups (%rsi), %ymm3 vextracti128 $1, %ymm3, %xmm3 vpextrq $0, %xmm3, %r9 nop nop nop nop mfence lea addresses_D_ht+0x57f7, %r12 nop nop nop sub %r15, %r15 vmovups (%r12), %ymm6 vextracti128 $0, %ymm6, %xmm6 vpextrq $1, %xmm6, %r14 nop nop nop cmp %r15, %r15 lea addresses_normal_ht+0x1bf1, %rsi nop nop nop nop nop dec %rdx movb $0x61, (%rsi) nop nop nop nop nop dec %r14 pop %rsi pop %rdx pop %rdi pop %rcx pop %r9 pop %r15 pop %r14 pop %r12 ret .global s_faulty_load s_faulty_load: push %r13 push %r15 push %r9 push %rax push %rbx push %rcx push %rdx // Load lea addresses_WT+0x10687, %rbx nop nop xor $51307, %rdx mov (%rbx), %r15 nop nop nop nop dec %rax // Store lea addresses_US+0xa247, %rbx nop nop nop nop nop sub %rcx, %rcx movw $0x5152, (%rbx) // Exception!!! nop nop mov (0), %rbx nop nop sub %rdx, %rdx // Store mov $0x1b7, %rdx nop nop xor $57141, %r13 mov $0x5152535455565758, %r15 movq %r15, %xmm3 movaps %xmm3, (%rdx) nop nop nop cmp %rdx, %rdx // Store lea addresses_WT+0x1b7f7, %rdx nop nop nop nop nop cmp $58345, %rax movb $0x51, (%rdx) nop nop nop nop cmp $30313, %rcx // Load lea addresses_WT+0x12f7, %rcx add $53268, %r9 mov (%rcx), %r15w nop nop nop nop nop xor %rcx, %rcx // Faulty Load mov $0x1199130000000ef7, %r9 nop nop nop nop and %r13, %r13 vmovaps (%r9), %ymm4 vextracti128 $1, %ymm4, %xmm4 vpextrq $0, %xmm4, %rbx lea oracles, %rcx and $0xff, %rbx shlq $12, %rbx mov (%rcx,%rbx,1), %rbx pop %rdx pop %rcx pop %rbx pop %rax pop %r9 pop %r15 pop %r13 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_P', 'size': 16, 'AVXalign': True, 'NT': False, 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 32, 'AVXalign': True, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 3, 'same': True}, 'dst': {'type': 'addresses_A_ht', 'congruent': 1, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 1, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': False}} {'49': 6646, '46': 2013} 49 49 49 46 49 49 46 49 46 49 46 49 46 49 46 49 46 49 46 49 46 49 49 49 49 49 49 46 49 49 46 49 49 49 49 49 49 46 49 49 49 49 49 46 49 49 49 46 49 46 49 49 49 49 49 49 46 49 46 46 49 49 46 49 49 46 49 49 49 49 49 49 49 46 49 49 49 49 46 49 49 49 49 46 46 49 49 49 49 49 49 49 49 49 49 49 49 46 46 49 46 49 49 49 46 49 46 46 46 49 49 46 49 49 49 49 46 49 49 49 46 46 49 49 46 49 49 49 46 49 49 49 46 49 46 49 49 49 46 49 49 49 49 49 49 49 49 49 49 49 49 46 49 46 49 49 49 49 46 49 49 49 46 49 49 49 46 49 49 46 49 49 49 46 49 46 49 49 49 49 49 49 46 49 46 49 49 49 46 49 49 49 49 49 49 49 46 49 49 49 49 49 46 49 46 49 49 49 49 49 49 49 49 49 49 49 49 46 49 49 49 49 49 46 46 46 49 46 46 46 46 49 49 46 49 49 49 49 46 49 49 49 49 46 49 49 46 49 46 49 49 49 49 49 49 46 46 49 49 46 46 49 49 49 46 49 49 46 46 49 49 49 49 46 49 46 49 46 49 49 46 49 46 49 49 46 46 49 49 46 49 49 46 49 49 49 49 49 49 49 49 49 49 46 49 49 49 49 49 49 49 49 49 49 46 49 49 49 46 46 49 49 49 46 46 49 49 49 46 49 49 49 49 46 49 49 49 49 49 49 49 49 46 49 46 49 49 49 46 49 49 49 49 46 49 46 49 49 46 49 49 49 49 49 49 49 46 49 49 46 49 49 46 49 49 49 49 49 46 49 49 46 46 49 49 46 49 49 46 49 46 49 49 49 46 49 49 49 46 49 46 49 49 46 49 49 49 49 49 49 49 49 46 46 46 46 49 49 49 49 46 49 46 49 49 49 46 49 49 49 46 49 49 49 46 49 49 46 46 49 49 49 49 46 49 46 49 49 46 49 49 49 49 49 49 49 49 46 49 49 49 46 46 49 46 49 49 46 49 49 49 49 46 49 49 46 49 49 46 49 46 49 49 49 49 49 49 46 49 49 46 49 49 49 46 49 46 49 49 49 49 49 49 49 49 46 49 49 49 49 46 49 49 46 49 49 49 49 46 46 49 49 49 46 49 49 49 49 49 49 46 49 46 49 49 49 49 46 46 49 46 46 49 49 49 49 49 46 46 49 49 49 49 49 46 49 49 49 49 46 49 46 49 49 49 49 46 49 46 49 49 49 46 46 49 49 49 49 46 49 49 49 49 49 49 49 49 49 46 49 49 49 46 49 46 49 49 49 49 49 49 49 46 49 46 49 49 49 49 46 49 49 49 49 49 49 46 49 49 46 49 49 49 49 49 49 49 49 49 49 49 49 46 49 49 49 49 49 49 49 49 46 49 49 49 49 49 46 49 49 49 49 49 49 49 49 49 49 49 46 49 49 49 49 49 49 49 49 49 46 49 49 46 49 46 49 49 46 49 49 49 46 49 49 49 46 49 49 49 49 49 46 49 49 49 49 46 49 49 49 49 46 49 49 49 49 49 46 46 46 49 46 49 49 49 46 49 46 49 46 49 46 49 49 49 46 49 49 46 49 46 49 49 49 49 49 46 49 49 49 49 49 49 49 49 49 49 46 46 49 49 46 49 49 49 49 46 49 49 49 46 49 49 46 46 46 49 49 49 49 49 49 46 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 46 49 49 46 49 46 49 49 46 49 49 49 49 49 49 49 49 46 49 49 49 46 46 49 49 46 49 49 46 49 49 49 49 49 49 49 49 49 49 46 49 46 46 46 49 49 46 46 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 46 49 49 49 49 46 49 49 49 49 46 49 49 49 49 46 49 46 49 49 49 49 49 49 46 46 49 49 49 49 49 49 46 49 49 49 49 49 49 49 46 49 46 49 49 49 46 49 46 49 46 49 46 49 49 49 46 49 49 46 49 49 49 49 49 46 49 49 49 49 49 49 49 49 49 49 49 49 49 46 49 49 49 49 49 49 49 49 49 49 49 46 46 49 49 49 49 49 46 49 49 46 49 46 49 49 49 49 49 49 46 49 46 49 46 49 49 49 49 49 49 46 49 46 46 49 49 49 49 49 49 49 46 49 49 49 49 49 49 46 49 49 49 49 49 49 49 49 */
def main(c:bool, a:i128, b:i128) -> (y:i128) { t0:i8 = ext[0, 7](a); t1:i8 = ext[0, 7](b); t2:i8 = lmux_i8(c, t0, t1) @lut(??, ??); t3:i8 = ext[8, 15](a); t4:i8 = ext[8, 15](b); t5:i8 = lmux_i8(c, t3, t4) @lut(??, ??); t6:i8 = ext[16, 23](a); t7:i8 = ext[16, 23](b); t8:i8 = lmux_i8(c, t6, t7) @lut(??, ??); t9:i8 = ext[24, 31](a); t10:i8 = ext[24, 31](b); t11:i8 = lmux_i8(c, t9, t10) @lut(??, ??); t12:i8 = ext[32, 39](a); t13:i8 = ext[32, 39](b); t14:i8 = lmux_i8(c, t12, t13) @lut(??, ??); t15:i8 = ext[40, 47](a); t16:i8 = ext[40, 47](b); t17:i8 = lmux_i8(c, t15, t16) @lut(??, ??); t18:i8 = ext[48, 55](a); t19:i8 = ext[48, 55](b); t20:i8 = lmux_i8(c, t18, t19) @lut(??, ??); t21:i8 = ext[56, 63](a); t22:i8 = ext[56, 63](b); t23:i8 = lmux_i8(c, t21, t22) @lut(??, ??); t24:i8 = ext[64, 71](a); t25:i8 = ext[64, 71](b); t26:i8 = lmux_i8(c, t24, t25) @lut(??, ??); t27:i8 = ext[72, 79](a); t28:i8 = ext[72, 79](b); t29:i8 = lmux_i8(c, t27, t28) @lut(??, ??); t30:i8 = ext[80, 87](a); t31:i8 = ext[80, 87](b); t32:i8 = lmux_i8(c, t30, t31) @lut(??, ??); t33:i8 = ext[88, 95](a); t34:i8 = ext[88, 95](b); t35:i8 = lmux_i8(c, t33, t34) @lut(??, ??); t36:i8 = ext[96, 103](a); t37:i8 = ext[96, 103](b); t38:i8 = lmux_i8(c, t36, t37) @lut(??, ??); t39:i8 = ext[104, 111](a); t40:i8 = ext[104, 111](b); t41:i8 = lmux_i8(c, t39, t40) @lut(??, ??); t42:i8 = ext[112, 119](a); t43:i8 = ext[112, 119](b); t44:i8 = lmux_i8(c, t42, t43) @lut(??, ??); t45:i8 = ext[120, 127](a); t46:i8 = ext[120, 127](b); t47:i8 = lmux_i8(c, t45, t46) @lut(??, ??); y:i128 = cat(t2, t5, t8, t11, t14, t17, t20, t23, t26, t29, t32, t35, t38, t41, t44, t47); }
#include "../dbstore.h" #include "../print.h" #include "../story_item.h" #include "../userin.h" #include <iostream> #include <string> using namespace std; //your the captin now Database db_sS = Database(); void now_captin() { StoryItem* nowCaptinItem = new StoryItem(); nowCaptinItem->preText = ".\n You gather the crew around and you tell them about your home planet" ".\n About how its full of gold and riches beyond their wildest dreams" ".\n All the crew want to go with you however the captin disagrees" ".\n The captin shouts 'I will not have a mutiny aboard my ship, anybody who disagrees will go over board'"; nowCaptinItem->preTextColour = "magenta"; nowCaptinItem->prompt = "What do you do?"; nowCaptinItem->options = { "Shoot the capatin", //1 "Let him live", //2 "Throw him over board", //3 }; int choice = nowCaptinItem->run(); if (choice == 1) { print(".\n You shoot the captain and the crew cheer, you are the captin now", "green"); print(".\n Set sail for Earth", "green"); } else if (choice == 2) { print(".\n He shoots you to stop the mutiny", "red"); } else if (choice == 3) { print(".\n you throw hom oer board, you are the captin now", "green"); print(".\n Set sail for Earth", "green"); } } //winning the gun fight void the_gun() { StoryItem* theGunItem = new StoryItem(); theGunItem->preText = ".\n You get your self ready and start to say 'I am one witht he force, the force is with me'" ".\n You close your eyes and walk over and by some crazy miracle which would never happen you make it" ".\n You turn and fire it at the wall behind them, blowing a hole in the ship sucking their entire crew into space suffocating them"; theGunItem->preTextColour = "magenta"; theGunItem->prompt = "What do you do?"; theGunItem->options = { "Scream that your are the best", //1 "Be gracious and say it was nothing", //2 }; int choice = theGunItem->run(); if (choice == 1) { print(".\n While screaming you are the best you accidentlly say 'You guys all suck I love Trump'", "green"); print(".\n The crew were all strong Hillary supporters and just gun you down", "red"); } else if (choice == 2) { now_captin(); } } //gun fight void gun_crate() { StoryItem* gunCrateItem = new StoryItem(); gunCrateItem->preText = ".\n You spot a massive gun in a crate"; gunCrateItem->preTextColour = "magenta"; gunCrateItem->prompt = "What do you do?"; gunCrateItem->options = { "Run though the gun fire and pick it up", //1 "Stay and try to just use the gun you were given", //2 }; int choice = gunCrateItem->run(); if (choice == 1) { the_gun(); } else if (choice == 2) { print("The gun they gave you jams aand blows up in your face killing you", "red"); } } // start of the hunt void the_hunt() { StoryItem* theHuntItem = new StoryItem(); theHuntItem->preText = ".\n After chasing for what seems like hours it all comes down to this" ".\n Your captain rams their ship and you all jump aboard and you take cover behind some boxes" ".\n You get ready and pop your head up ready to fire"; theHuntItem->preTextColour = "magenta"; theHuntItem->prompt = "What do you do?"; theHuntItem->options = { "Shoot the frst thing you see", //1 "Duck back down", //2 "Evauluate the situation", //3 }; int choice = theHuntItem->run(); if (choice == 1) { print(".\n The first thing you saw was the captin and you shoot him unforunaly you dont kill him and he turn to face you and blows your head off", "red"); } else if (choice == 2) { print(".\n Your cower behind cover and try just wait the fight out", "green"); print(".\n They use a giant gun and vaporise you and the entire crew", "green"); } else if (choice == 3) { gun_crate(); } } // start of gun story line void the_ship_gun() { StoryItem* theShipGunItem = new StoryItem(); theShipGunItem->preText = ".\n The Captain comes up to you and pats you on the back and says 'welcome aboard, but you still have to proove your self'" ".\n The captain turns to the crew and shouts 'One with the ship, One with the crew!'" ".\n The crew start to chant 'One with the ship, One with the crew!' and you feel a bit out of place but you join in" ".\n After a few days sailing you spot another ship"; theShipGunItem->preTextColour = "magenta"; theShipGunItem->prompt = "What do you do?"; theShipGunItem->options = { "Shout for that you have seen it", //1 "Keep quite and hope they get away", //2 }; int choice = theShipGunItem->run(); if (choice == 1) { print(".\n All hands on deck, the hunt is on", "green"); the_hunt(); } else if (choice == 2) { print("The captain shouts up to you 'Are you blind, your not even wearing an eye patch yet, your useless!'"); print(".\n He looks up and just shoots you,your body falls limply of the edge and you just left floating as they sail away", "red"); } } //becoming captin void im_the_captain_now() { StoryItem* imTheCaptinNowItem = new StoryItem(); imTheCaptinNowItem->preText = ".\n Im the captain now" ".\n You win"; imTheCaptinNowItem->preTextColour = "magenta"; }; // sword fight 4 void sword_fight4() { StoryItem* swordFigh4Item = new StoryItem(); swordFigh4Item->preText = ".\n You take a step back" ".\n Hes still swinging wildly" ".\n What do you do:"; swordFigh4Item->preTextColour = "magenta"; swordFigh4Item->prompt = "What do you do?"; swordFigh4Item->options = { "Advance", //1 "Retreat", //2 }; int choice = swordFigh4Item->run(); if (choice == 1) { print("You have waited for just the right moment", "green"); print(".\n He swings and you trip him and then chop his head off while hes on the floor", "green"); im_the_captain_now(); } else if (choice == 2) { print(".\n You retreat too much"); print(".\n He backs you into the corner and chops you into lots of little pieces", "red"); } } // sword fight 3 void sword_fight3() { StoryItem* swordFigh3Item = new StoryItem(); swordFigh3Item->preText = ".\n You take a step back" ".\n He starts to get annoyed and starts to swing wildly" ".\n What do you do:"; swordFigh3Item->preTextColour = "magenta"; swordFigh3Item->prompt = "What do you do?"; swordFigh3Item->options = { "Advance", //1 "Retreat", //2 }; int choice = swordFigh3Item->run(); if (choice == 1) { print("Your too hasty"); print(".\n While he swings wildly he catches you and you scream in agony and he spears oyou through the heart", "red"); } else if (choice == 2) { sword_fight4(); } } // sword fight 2 void sword_fight2() { StoryItem* swordFigh2Item = new StoryItem(); swordFigh2Item->preText = ".\n You take a step back" ".\n He swings at you and misses" ".\n What do you do:"; swordFigh2Item->preTextColour = "magenta"; swordFigh2Item->prompt = "What do you do?"; swordFigh2Item->options = { "Advance", //1 "Retreat", //2 }; int choice = swordFigh2Item->run(); if (choice == 1) { print("Your too hasty"); print(".\n He chops of your leg and spins around to behind you and as you fall to one knee he beheads you", "red"); } else if (choice == 2) { sword_fight3(); } } // sword fight 1 void sword_fight() { StoryItem* swordFighItem = new StoryItem(); swordFighItem->preText = ".\n The bacics advance and attack, and retreat and defend"; swordFighItem->preTextColour = "magenta"; swordFighItem->prompt = "What do you do?"; swordFighItem->options = { "Advance", //1 "Retreat", //2 }; int choice = swordFighItem->run(); if (choice == 1) { print("Your too hasty"); print(".\n He chops of your leg and spins around to behiind you and as you fall to one knee he beheads you", "red"); } else if (choice == 2) { sword_fight2(); } } // start of sword story line void the_ship_sword() { StoryItem* theShipSwordItem = new StoryItem(); theShipSwordItem->preText = ".\n The Captain comes up to you and says 'Im the master swords man abord this ship do you think you can beat me?'"; theShipSwordItem->preTextColour = "magenta"; theShipSwordItem->prompt = "What do you do?"; theShipSwordItem->options = { "yes", //1 "no", //2 }; int choice = theShipSwordItem->run(); if (choice == 1) { print("Lets fight"); sword_fight(); } else if (choice == 2) { print("We dont take quiters abord this ship"); print(".\n In one fluid swoop he swings up and splits you though the middle", "red"); } } // joining the pirates void join_them() { StoryItem* joinThemItem = new StoryItem(); joinThemItem->preText = ".\n We are space pirates and we are destined to travel the 7 galaxys" ".\n You will come back with me to our ship the 'Floating Dutchman'"; joinThemItem->preTextColour = "magenta"; joinThemItem->prompt = "What do you do?"; joinThemItem->options = { "Light-saber fighting", //1 "Lazer guns", //2 "Cleaning the deck" //3 }; int choice = joinThemItem->run(); if (choice == 1) { db_sS.add_to_inventory("Light saber"); if (db_sS.do_i_have("Light saber")) { print("You now have a Light saber"); } else { print("You do not have a Light saber"); } print(".\n Good we will have to test you when we get back to the ship", "green"); the_ship_sword(); } else if (choice == 2) { db_sS.add_to_inventory("Lazer_gun"); if (db_sS.do_i_have("Lazer_gun")) { print("You now have a Lazer_gun"); } else { print("You do not have a Lazer_gun"); } print(".\n Welcome aboard", "green"); the_ship_gun(); } else if (choice == 3) { print(".\n We have no need for women", "red"); } } //meeting the pirate void mind_control() { StoryItem* mindControlItem = new StoryItem(); mindControlItem->preText = ".\n You black out" ".\n When you wake you can suddenly understand him" ".\n He says 'I have looked through your mind, im going to give you an ultimatum'"; mindControlItem->preTextColour = "magenta"; mindControlItem->prompt = "What do you do?"; mindControlItem->options = { "Join me in a life of piracy", //1 "I kill you", //2 }; int choice = mindControlItem->run(); if (choice == 1) { join_them(); } else if (choice == 2) { print("BLAST", "red"); } } //aboard the ship void aboard() { StoryItem* aboardItem = new StoryItem(); aboardItem->preText = ".\n This figure stands before you vaguely humanoid, he starts making noises getting more more agressive", "green" ".\n A tentacle shoots outa and ataches it to your head "; aboardItem->preTextColour = "magenta"; aboardItem->prompt = "What do you do?"; aboardItem->options = { "Try to fight", //1 "Let it happen", //2 "Use jedi mind powers to keep him out of your brain", //3 }; int choice = aboardItem->run(); if (choice == 1) { print(".\n The humanoid figure uses his tentacle and throws you into the air lock and blasts you back int space to suffocate", "red"); } else if (choice == 2) { mind_control(); } else if (choice == 3) { print(".\n Your no jedi", "green"); mind_control(); } } //pitate story start void start_story_S() { StoryItem* startStoryItem = new StoryItem(); startStoryItem->preText = ".\n You try to contact who ever is aboard", "green" ".\n You hear nothing but one of the docking bays open up"; startStoryItem->preTextColour = "magenta"; startStoryItem->prompt = "What do you do?"; startStoryItem->options = { "Dock and go aboard", //1 "Kep trying to contact them", //2 "Turn and run", //3 }; int choice = startStoryItem->run(); if (choice == 1) { aboard(); } else if (choice == 2) { print(".\n You annoy whoever is aboard and they use the space stations lazers to evaporate you from existance", "red"); } else if (choice == 3) { print(".\n You try to run and they use the space stations lazers to evaporate you from existance", "red"); } }
; A168587: Smallest digit sum of an n-digit prime with only digits 0 add 1 (or 0, if no such prime exists). ; 0,2,2,0,4,5,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 mov $2,$0 sub $0,2 mov $3,2 lpb $0 div $2,2 add $2,$0 mov $0,$2 div $0,2 sub $0,2 lpe mul $0,$2 sub $3,$0 add $3,$2 mov $0,$3 sub $0,2
// Copyright 2021 gRPC authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "src/core/lib/promise/detail/promise_factory.h" #include <gtest/gtest.h> #include "absl/functional/bind_front.h" #include "src/core/lib/gprpp/capture.h" #include "src/core/lib/promise/promise.h" namespace grpc_core { namespace promise_detail { namespace testing { template <typename Arg, typename F> PromiseFactory<Arg, F> MakeFactory(F f) { return PromiseFactory<Arg, F>(std::move(f)); } TEST(AdaptorTest, FactoryFromPromise) { EXPECT_EQ( MakeFactory<void>([]() { return Poll<int>(Poll<int>(42)); }).Once()(), Poll<int>(42)); EXPECT_EQ( MakeFactory<void>([]() { return Poll<int>(Poll<int>(42)); }).Repeated()(), Poll<int>(42)); EXPECT_EQ(MakeFactory<void>(Promise<int>([]() { return Poll<int>(Poll<int>(42)); })).Once()(), Poll<int>(42)); EXPECT_EQ(MakeFactory<void>(Promise<int>([]() { return Poll<int>(Poll<int>(42)); })).Repeated()(), Poll<int>(42)); } TEST(AdaptorTest, FactoryFromBindFrontPromise) { EXPECT_EQ(MakeFactory<void>( absl::bind_front([](int i) { return Poll<int>(i); }, 42)) .Once()(), Poll<int>(42)); } TEST(AdaptorTest, FactoryFromCapturePromise) { EXPECT_EQ(MakeFactory<void>(Capture([](int* i) { return Poll<int>(*i); }, 42)) .Once()(), Poll<int>(42)); } } // namespace testing } // namespace promise_detail } // namespace grpc_core int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r13 push %r8 push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_WC_ht+0xe83d, %rsi lea addresses_WC_ht+0x553d, %rdi nop nop xor %r11, %r11 mov $122, %rcx rep movsw nop add %rbp, %rbp lea addresses_UC_ht+0x19c3d, %r13 xor $11277, %rdx mov (%r13), %bp inc %rdi lea addresses_A_ht+0xf9cd, %rsi nop nop nop nop nop xor %rdx, %rdx movups (%rsi), %xmm3 vpextrq $0, %xmm3, %rcx nop nop nop nop nop cmp %rcx, %rcx lea addresses_A_ht+0xe03d, %rsi lea addresses_WT_ht+0xa9bd, %rdi clflush (%rsi) nop nop nop inc %r8 mov $14, %rcx rep movsq nop add %r13, %r13 lea addresses_D_ht+0x161e3, %rcx nop nop nop xor %r13, %r13 movl $0x61626364, (%rcx) xor $31505, %r11 lea addresses_WC_ht+0x263d, %rsi nop nop nop nop nop add $60077, %rcx movb $0x61, (%rsi) nop nop nop nop nop cmp $11880, %r8 pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %r8 pop %r13 pop %r11 ret .global s_faulty_load s_faulty_load: push %r12 push %r15 push %r9 push %rax push %rbp push %rdi push %rdx // Store lea addresses_US+0x1a43d, %r9 nop nop nop nop add %r12, %r12 movb $0x51, (%r9) nop nop nop nop nop add $22118, %r9 // Store lea addresses_D+0xf33d, %rbp clflush (%rbp) add %rdx, %rdx mov $0x5152535455565758, %r15 movq %r15, %xmm1 movups %xmm1, (%rbp) nop and $21845, %r15 // Faulty Load lea addresses_UC+0x7c3d, %r9 nop nop sub $54884, %rdi vmovups (%r9), %ymm6 vextracti128 $0, %ymm6, %xmm6 vpextrq $0, %xmm6, %rax lea oracles, %rdx and $0xff, %rax shlq $12, %rax mov (%rdx,%rax,1), %rax pop %rdx pop %rdi pop %rbp pop %rax pop %r9 pop %r15 pop %r12 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 10, 'size': 1, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 8, 'size': 16, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 5, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 8, 'size': 2, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 3, 'size': 16, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 9, 'size': 1, 'same': False, 'NT': False}} {'53': 419, 'f8': 1, '47': 142, 'e0': 1, '45': 144, '00': 3517, '01': 1539, 'a2': 1, '48': 1037, '64': 1, 'ff': 15027} 00 ff ff 48 ff ff ff ff ff ff ff ff 00 ff 01 ff ff 00 ff 01 ff 01 ff ff ff 53 47 ff 00 00 ff ff ff ff ff ff ff 00 ff ff ff ff ff ff ff 00 ff ff 00 ff 48 ff 00 ff ff ff ff ff ff 00 ff ff ff ff ff ff ff 00 00 48 ff ff ff ff ff 00 00 ff ff ff ff 00 ff ff ff 00 ff 01 48 ff ff ff 00 00 ff ff 00 00 48 00 ff ff ff 00 ff ff ff ff ff ff ff 01 00 ff ff 45 ff ff ff ff 00 ff ff 00 ff ff 01 00 ff 01 ff ff ff 00 53 ff 01 ff ff ff 00 ff ff 53 ff ff ff 00 ff ff 53 ff 00 45 00 00 00 ff ff ff ff ff 48 ff ff 00 ff 48 ff 00 00 ff ff ff 00 ff 01 ff ff ff ff 01 00 ff ff ff ff ff ff 53 ff ff ff 01 ff ff 01 00 ff ff ff 00 ff ff 48 48 ff 00 00 ff ff ff ff ff 48 ff ff ff ff ff 00 ff ff ff ff ff 01 ff ff 48 00 ff 48 ff ff ff ff 00 ff ff ff ff ff ff ff ff 00 ff ff ff ff 53 00 00 ff ff ff ff ff ff ff 00 ff ff ff 00 ff ff ff ff ff ff 48 48 ff ff ff ff ff ff ff 48 ff ff ff 00 ff ff ff ff 01 00 ff 01 ff ff 01 00 00 ff ff ff 48 ff 00 ff 45 ff 48 00 ff ff 01 ff 01 48 ff ff ff ff ff ff 00 ff ff ff 00 ff ff 01 ff 45 48 00 ff 01 ff ff 01 48 00 ff 00 ff ff 00 00 ff ff 00 00 ff ff ff ff 00 ff 01 ff 48 ff ff 01 48 ff ff 00 ff 00 ff 00 48 00 53 ff ff ff ff ff ff ff ff ff 01 ff ff ff 00 ff 00 ff ff ff 48 ff ff ff ff 53 00 ff ff 00 ff 53 ff 00 ff 00 ff ff ff 48 ff 00 ff ff 00 ff ff 53 00 ff ff ff ff ff 48 ff ff ff ff 53 ff 48 00 00 ff ff 00 ff 00 ff ff ff ff ff ff ff ff 01 45 ff 53 ff 53 00 ff ff 00 ff ff ff ff ff ff 01 ff ff 00 ff ff 01 ff ff ff 01 48 ff ff ff 01 00 ff ff ff 00 48 ff ff 01 ff 01 ff ff 00 ff ff 48 48 ff ff ff ff ff ff ff 48 ff ff 00 ff ff ff 53 ff ff 00 ff 00 ff ff 01 ff ff ff ff ff ff 01 ff ff ff ff ff 00 ff ff ff 01 00 ff ff ff 01 00 ff 00 ff 01 ff ff ff ff ff ff ff ff ff 01 ff ff 48 ff ff ff ff 01 48 ff ff 48 00 ff ff ff ff ff ff 00 00 ff 00 ff 00 ff ff ff 00 ff ff ff ff 00 45 ff ff ff 48 00 00 ff ff 00 ff ff ff ff ff ff 00 47 ff ff ff ff ff ff 47 ff ff ff 48 ff ff ff 00 ff ff ff ff ff ff ff ff ff 00 ff 00 ff ff ff ff ff ff 00 00 ff ff 01 00 ff ff ff 48 ff 00 00 ff ff ff 00 ff 01 00 ff ff ff 00 00 ff ff ff ff ff 00 48 00 53 ff 00 ff ff ff ff ff 01 ff 00 ff ff ff ff 53 ff ff ff 01 ff ff ff ff 00 ff ff 00 ff ff ff ff ff ff 00 ff ff ff ff ff ff 00 ff ff ff 00 ff ff 01 ff ff ff 01 ff ff ff ff 47 ff ff ff ff ff 01 ff ff 00 ff 48 ff 45 ff 01 ff ff ff 00 ff 01 53 00 48 ff 53 ff ff ff ff ff 00 ff ff 00 ff ff ff 01 00 ff ff ff ff ff ff ff 48 00 00 ff ff 00 00 ff ff 00 ff ff ff ff 00 48 ff 00 00 53 ff ff ff ff ff ff ff ff 00 ff 48 ff ff 01 ff 48 ff ff ff ff ff 00 00 ff ff ff ff ff ff 00 ff 53 ff ff ff ff 00 ff 48 ff ff 00 00 48 ff ff ff 01 ff 48 ff ff 00 ff 48 ff ff 00 ff ff ff ff 48 ff ff ff ff ff 48 ff ff ff ff ff ff ff ff ff ff ff 48 ff 01 ff ff ff ff ff ff ff ff ff ff ff 00 00 00 ff ff 47 ff 01 ff 48 ff ff 00 ff 48 ff ff ff ff ff ff 00 ff ff ff 00 ff 00 ff ff ff 01 ff 00 ff ff 01 ff 01 ff 00 ff ff 00 ff ff ff ff ff 00 ff ff ff ff 01 00 ff ff 01 ff ff ff ff ff 01 ff ff ff ff ff ff ff ff ff ff 01 ff 00 ff ff ff ff 00 ff 01 00 ff ff 01 ff ff ff ff ff ff ff ff ff ff ff ff ff ff */
;/* Builtins not (yet) implemented in Clang's compiler-rt. */ ;.global __mulhi3hw_noint ; .type __mulhi3hw_noint,@function .cdecls C, LIST, "builtins.h" .def __mulhi3hw_noint .global __mulhi3hw_noint __mulhi3hw_noint: ; these addresses are for MSP430FR5969 MOV R15, &0x04C0 MOV R14, &0x04C8 MOV &0x04CA, R15 RET
; A077552: Consider the following triangle in which the n-th row contains n distinct numbers whose product is the smallest and has the least possible number of divisors. 1 is a member of only the first row. Sequence contains the final term of the rows (the leading diagonal). ; 1,3,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648 mov $1,1 lpb $0 sub $0,1 add $2,$1 add $1,$2 add $1,1 mov $2,2 trn $2,$0 lpe
_start: cbz x0, return ret return: ret
/* ---------------------------------------------------------------------------- * GTSAM Copyright 2010, Georgia Tech Research Corporation, * Atlanta, Georgia 30332-0415 * All Rights Reserved * Authors: Frank Dellaert, et al. (see THANKS for the full author list) * See LICENSE for the license information * -------------------------------------------------------------------------- */ /** * @file testEssentialMatrixConstraint.cpp * @brief Unit tests for EssentialMatrixConstraint Class * @author Frank Dellaert * @author Pablo Alcantarilla * @date Jan 5, 2014 */ #include <gtsam/slam/EssentialMatrixConstraint.h> #include <gtsam/nonlinear/Symbol.h> #include <gtsam/geometry/Pose3.h> #include <gtsam/base/numericalDerivative.h> #include <gtsam/base/TestableAssertions.h> #include <CppUnitLite/TestHarness.h> using namespace std::placeholders; using namespace std; using namespace gtsam; /* ************************************************************************* */ TEST( EssentialMatrixConstraint, test ) { // Create a factor Key poseKey1(1); Key poseKey2(2); Rot3 trueRotation = Rot3::RzRyRx(0.15, 0.15, -0.20); Point3 trueTranslation(+0.5, -1.0, +1.0); Unit3 trueDirection(trueTranslation); EssentialMatrix measurement(trueRotation, trueDirection); SharedNoiseModel model = noiseModel::Isotropic::Sigma(5, 0.25); EssentialMatrixConstraint factor(poseKey1, poseKey2, measurement, model); // Create a linearization point at the zero-error point Pose3 pose1(Rot3::RzRyRx(0.00, -0.15, 0.30), Point3(-4.0, 7.0, -10.0)); Pose3 pose2( Rot3::RzRyRx(0.179693265735950, 0.002945368776519, 0.102274823253840), Point3(-3.37493895, 6.14660244, -8.93650986)); Vector expected = Z_5x1; Vector actual = factor.evaluateError(pose1,pose2); CHECK(assert_equal(expected, actual, 1e-8)); // Calculate numerical derivatives Matrix expectedH1 = numericalDerivative11<Vector5, Pose3>( std::bind(&EssentialMatrixConstraint::evaluateError, &factor, std::placeholders::_1, pose2, boost::none, boost::none), pose1); Matrix expectedH2 = numericalDerivative11<Vector5, Pose3>( std::bind(&EssentialMatrixConstraint::evaluateError, &factor, pose1, std::placeholders::_1, boost::none, boost::none), pose2); // Use the factor to calculate the derivative Matrix actualH1; Matrix actualH2; factor.evaluateError(pose1, pose2, actualH1, actualH2); // Verify we get the expected error CHECK(assert_equal(expectedH1, actualH1, 1e-5)); CHECK(assert_equal(expectedH2, actualH2, 1e-5)); } /* ************************************************************************* */ int main() { TestResult tr; return TestRegistry::runAllTests(tr); } /* ************************************************************************* */
#include "SettingForRendering.h" using namespace std; namespace FontGenerator { SettingForRendering::SettingForRendering() : m_fontSize(20) , m_fontColor(Color()) , m_border(nullptr) , m_bold(nullptr) { } #pragma region GetSet int SettingForRendering::GetFontSize() const { return m_fontSize; } void SettingForRendering::SetFontSize(int value) { m_fontSize = value; } Color SettingForRendering::GetFontColor() const { return m_fontColor; } void SettingForRendering::SetFontColor(Color value) { m_fontColor = value; } BorderSetting::Ptr SettingForRendering::GetBorder() const { return m_border; } void SettingForRendering::SetBorder(BorderSetting::Ptr value) { m_border = value; } BoldSetting::Ptr SettingForRendering::GetBold() const { return m_bold; } void SettingForRendering::SetBold(BoldSetting::Ptr value) { m_bold = value; } #pragma endregion }
;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX ;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS ;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE ;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. ; ; $Source: f:/miner/source/3d/rcs/points.asm $ ; $Revision: 1.13 $ ; $Author: matt $ ; $Date: 1995/02/09 22:00:05 $ ; ; Source for point definition, rotation, etc. ; ; $Log: points.asm $ ; Revision 1.13 1995/02/09 22:00:05 matt ; Removed dependence on divide overflow handler; we now check for overflow ; before dividing. This fixed problems on some TI chips. ; ; Revision 1.12 1994/11/11 19:22:06 matt ; Added new function, g3_calc_point_depth() ; ; Revision 1.11 1994/07/25 00:00:04 matt ; Made 3d no longer deal with point numbers, but only with pointers. ; ; Revision 1.10 1994/07/21 09:53:32 matt ; Made g3_point_2_vec() take 2d coords relative to upper left, not center ; ; Revision 1.9 1994/02/10 18:00:41 matt ; Changed 'if DEBUG_ON' to 'ifndef NDEBUG' ; ; Revision 1.8 1994/02/09 11:48:55 matt ; Added delta rotation functions ; ; Revision 1.7 1994/01/13 15:39:39 mike ; Change usage of Frame_count to _Frame_count. ; ; Revision 1.6 1993/12/21 20:35:35 matt ; Fixed bug that left register pushed if point was already projected in ; g3_project_list() ; ; Revision 1.5 1993/12/21 11:45:37 matt ; Fixed negative y bug in g3_point_2_vec() ; ; Revision 1.4 1993/12/20 20:21:51 matt ; Added g3_point_2_vec() ; ; Revision 1.3 1993/11/21 20:08:41 matt ; Added function g3_rotate_point() ; ; Revision 1.2 1993/11/04 18:49:17 matt ; Added system to only rotate points once per frame ; ; Revision 1.1 1993/10/29 22:20:27 matt ; Initial revision ; ; ; .386 option oldstructs .nolist include types.inc include psmacros.inc include gr.inc include 3d.inc .list assume cs:_TEXT, ds:_DATA _DATA segment dword public USE32 'DATA' rcsid db "$Id: points.asm 1.13 1995/02/09 22:00:05 matt Exp $" align 4 tempv vms_vector <> tempm vms_matrix <> _DATA ends _TEXT segment dword public USE32 'CODE' ;finds clipping codes for a point. takes eax=point. fills in p3_codes, ;and returns codes in bl. g3_code_point: code_point: push ecx xor bl,bl ;clear codes mov ecx,[eax].z ;get z cmp [eax].x,ecx ;x>z? jle not_right or bl,CC_OFF_RIGHT not_right: cmp [eax].y,ecx ;y>z? jle not_top or bl,CC_OFF_TOP not_top: neg ecx js not_behind or bl,CC_BEHIND not_behind: cmp [eax].x,ecx ;x<-z? jge not_left or bl,CC_OFF_LEFT not_left: cmp [eax].y,ecx ;y<-z jge not_bot or bl,CC_OFF_BOT not_bot: pop ecx mov [eax].p3_codes,bl ret ;rotate a point. don't look at rotated flags ;takes esi=dest point, esi=src vector ;returns bl=codes g3_rotate_point: pushm eax,ecx,esi,edi push edi ;save dest lea eax,tempv lea edi,View_position call vm_vec_sub mov esi,eax pop eax lea edi,View_matrix call vm_vec_rotate mov [eax].p3_flags,0 ;not projected ;;mov bx,_Frame_count ;curren frame ;;mov [eax].p3_frame,bx call code_point popm eax,ecx,esi,edi ret ;projects a point. takes esi=point g3_project_point: ;;ifndef NDEBUG ;; push eax ;; mov ax,[esi].p3_frame ;; cmp ax,_Frame_count ;; break_if ne,'Trying to project unrotated point!' ;; pop eax ;;endif test [esi].p3_flags,PF_PROJECTED jnz no_project test [esi].p3_codes,CC_BEHIND jnz no_project pushm eax,edx mov eax,[esi].x imul Canv_w2 proj_div0: divcheck [esi].z,div_overflow_handler idiv [esi].z add eax,Canv_w2 mov [esi].p3_sx,eax mov eax,[esi].y imul Canv_h2 proj_div1: divcheck [esi].z,div_overflow_handler idiv [esi].z neg eax add eax,Canv_h2 mov [esi].p3_sy,eax or [esi].p3_flags,PF_PROJECTED ;projected popm eax,edx no_project: ret div_overflow_handler: ;int 3 mov [esi].p3_flags,PF_OVERFLOW popm eax,edx ret ;from a 2d point on the screen, compute the vector in 3-space through that point ;takes eax,ebx = 2d point, esi=vector ;the 2d point is relative to the center of the canvas g3_point_2_vec: pushm ecx,edx,esi,edi push esi lea esi,tempv ;;mov edx,eax ;;xor eax,eax ;;idiv Canv_w2 sal eax,16 sub eax,Canv_w2 fixdiv Canv_w2 imul Matrix_scale.z idiv Matrix_scale.x mov [esi].x,eax ;;mov edx,ebx ;;xor eax,eax ;;sub Canv_h2 ;;idiv Canv_h2 mov eax,ebx sal eax,16 sub eax,Canv_h2 fixdiv Canv_h2 imul Matrix_scale.z idiv Matrix_scale.y neg eax mov [esi].y,eax mov [esi].z,f1_0 call vm_vec_normalize ;get normalized rotated vec lea edi,tempm lea esi,Unscaled_matrix call vm_copy_transpose_matrix pop eax ;get dest lea esi,tempv ;edi=matrix call vm_vec_rotate popm ecx,edx,esi,edi ret ;rotate a delta y vector. takes edi=dest vec, ebx=delta y g3_rotate_delta_y: pushm eax,edx mov eax,View_matrix.m4 fixmul ebx mov [edi].x,eax mov eax,View_matrix.m5 fixmul ebx mov [edi].y,eax mov eax,View_matrix.m6 fixmul ebx mov [edi].z,eax popm eax,edx ret ;rotate a delta x vector. takes edi=dest vec, ebx=delta x g3_rotate_delta_x: pushm eax,edx mov eax,View_matrix.m1 fixmul ebx mov [edi].x,eax mov eax,View_matrix.m2 fixmul ebx mov [edi].y,eax mov eax,View_matrix.m3 fixmul ebx mov [edi].z,eax popm eax,edx ret ;rotate a delta x vector. takes edi=dest vec, ebx=delta z g3_rotate_delta_z: pushm eax,edx mov eax,View_matrix.m7 fixmul ebx mov [edi].x,eax mov eax,View_matrix.m8 fixmul ebx mov [edi].y,eax mov eax,View_matrix.m9 fixmul ebx mov [edi].z,eax popm eax,edx ret ;rotate a delta vector. takes edi=dest vec, esi=src vec g3_rotate_delta_vec: pushm eax,edi mov eax,edi lea edi,View_matrix call vm_vec_rotate popm eax,edi ret ;adds a delta vector to a point. takes eax=dest point, esi=src pnt, edi=delta vec ;returns bl=codes. g3_add_delta_vec: ;;ifndef NDEBUG ;; push eax ;; mov ax,[esi].p3_frame ;; cmp ax,_Frame_count ;; break_if ne,'Trying to add delta to unrotated point!' ;; pop eax ;;endif call vm_vec_add ;;mov bx,_Frame_count ;;mov [eax].p3_frame,bx mov [eax].p3_flags,0 ;not projected call g3_code_point ret ;calculate the depth of a point - returns the z coord of the rotated point ;takes esi=vec, returns eax=depth g3_calc_point_depth: pushm edx,ebx,ecx mov eax,[esi].x sub eax,View_position.x imul View_matrix.fvec.x mov ebx,eax mov ecx,edx mov eax,[esi].y sub eax,View_position.y imul View_matrix.fvec.y add ebx,eax adc ecx,edx mov eax,[esi].z sub eax,View_position.z imul View_matrix.fvec.z add eax,ebx adc edx,ecx shrd eax,edx,16 popm edx,ebx,ecx ret _TEXT ends end
ORIGIN 0 SEGMENT CodeSegment1: START: LEA R0, DataSegment ADD R1, R1, 12 NOP NOP NOP ADD R1, R1, -5 NOP NOP NOP ADD R1, R1, 0 NOP NOP NOP STR R1, R0, aacus AND R2, R0, 4x0F NOP NOP NOP STR R2, R0, joiner NOP NOP NOP LDR R3, R0, DEEB NOP NOP NOP LDR R4, R0, LEAF NOP NOP NOP LDR R5, R0, D22D NOP NOP NOP LDR R6, R0, LIFE NOP NOP NOP ADD R3, R3, R4 NOP NOP NOP ADD R3, R3, R3 NOP NOP NOP STR R3, R0, calcx AND R4, R5, R3 NOP NOP NOP STR R4, R0, joiner NOT R5, R5 NOP NOP NOP STR R5, R0, duh LDR R6, R0, FOED NOP NOP NOP LDR R7, R0, FOED NOP NOP NOP LSHF R6, R6, 8 NOP NOP NOP RSHFL R7, R7, 3 NOP NOP NOP RSHFA R6, R6, 6 NOP NOP NOP STR R6, R0, fivespd NOP NOP NOP STR R7, R0, fivespd NOP NOP NOP LDR R1, R0, ZERO LDR R2, R0, ZERO LDR R3, R0, D22D LDR R4, R0, LIFE LDR R5, R0, FOED LDR R6, R0, DEEB LDR R7, R0, LEAF SEGMENT CodeSegment2: LDR R1, R0, BOMB NOP NOP NOP LEA R2, HOWHIGH NOP NOP NOP JMP R2 NOP NOP NOP LDR R1, R0, GOOF NOP NOP NOP HOWHIGH: STR R1, R0, dunk NOP NOP NOP LDR R2, R0, DEEB NOP NOP NOP STR R2, R0, SPOT1 LDR R3, R0, FOED LDR R4, R0, LEAF NOP NOP NOP STR R3, R0, SPOT2 STR R4, R0, SPOT3 LDR R5, R0, GOOD NOP NOP NOP STR R5, R0, SPOT4 NOP NOP NOP LDR R5, R0, SPOT1 LDR R4, R0, SPOT2 LDR R3, R0, SPOT3 LDR R2, R0, SPOT4 STR R5, R0, SPOT4 STR R4, R0, SPOT4 STR R3, R0, SPOT4 STR R2, R0, SPOT4 NOP NOP NOP ADD R2, R2, R3 NOP NOP NOP ADD R3, R4, R5 NOP NOP NOP ADD R2, R2, R3 NOP NOP NOP ADD R3, R0,1 NOP NOP NOP STB R6, R3, ZOOP LDR R4, R0, ZOOP STB R7, R0, BEAD LDR R3, R0, BEAD NOP NOP NOP STR R3, R0, chew STR R4, R0, chew ADD R3, R3, R4 LDR R4, R0, ZERO JSR MUDDLE STR R4, R0, MUDPIE LEA R5, MUDDLER NOP NOP NOP JSRR R5 STR R5, R0, MUDPIE ADD R6, R0, 1 NOP NOP NOP LDB R6, R6, COOKIE NOP LDB R7, R0, COOKIE NOP STR R6, R0, crumb NOP STR R7, R0, crumb NOP NOP NOP ADD R6, R6, R7 TRAP FUN STR R6, R0, FUN LDR R1,R0, ZERO LDR R2,R0, ZERO LDR R3,R0, ZERO LDR R4,R0, GOOD LDR R5,R0, GOOD LDR R6,R0, GOOD LDI R1, R0, TEST NOP NOP NOP STI R4, R0, DONE NOP NOP NOP LDR R2, R0, RESULT STR R1, R0, GOOF STR R2, R0, GOOF NOP AND R3, R3, 0 BRp DOH BRn DOH BRnp DOH BRz WOOHOO BRnz DOH BRnzp DOH DOH: ADD R3, R3, 4 WOOHOO: ADD R3, R3, 6 AND R4,R4,0 BRz SOFAR ADD R3, R3, 1 SOFAR: ADD R3, R3, 6 AND R4,R4,0 BRnp DOH2 NOP NOP NOP ADD R4, R4, 10 NOP BRp SOGOOD DOH2: ADD R3, R3, 6 BRnzp GetOverHere SOGOOD: ADD R3, R3, 3 NOP NOP NOP GetOverHere: ADD R3, R3, R4 NOP NOP NOP STR R3, R0, GOOF STR R1, R0, SPOT1 STR R2, R0, SPOT2 STR R3, R0, SPOT3 LEA R1, bouncer END_m: JMP R1 SEGMENT DataSegment: ZERO: DATA2 4x0000 ZOOP : DATA2 4x700F BEAD : DATA2 4xBEAD FUN : DATA2 HOPE DEEB: DATA2 4xDEEB LEAF: DATA2 4x1EAF D22D: DATA2 4xD22D LIFE: DATA2 4x0042 FOED: DATA2 4xF0ED BOMB: DATA2 4xB006 GOOF: DATA2 4x600F dunk: DATA2 4xdddd RESULT: DATA2 4x0000 GOOD: DATA2 4x600D COOKIE: DATA2 4xD0CA FOOB: DATA2 4xF00B aacus: DATA2 4xFFFF joiner: DATA2 4x1010 calcx: DATA2 4x1234 fivespd:DATA2 4x8921 duh: DATA2 4x9999 chew: DATA2 4xcccc crumb: DATA2 4x6969 GAME: DATA2 4xba11 SPOT1: DATA2 4x8888 SPOT2: DATA2 4xABCD SPOT3: DATA2 4x0110 SPOT4: DATA2 4xABBA TEST: DATA2 GAME DONE: DATA2 RESULT MUDPIE: DATA2 4x0000 BLUNDER: DATA2 bouncer MUDDLE: NOP NOP NOP ADD R4, R4,14 RET MUDDLER: LDR R5, R0, LIFE RET HOPE: LDR R1,R0, GOOD LDR R2,R0, GOOD LDR R3,R0, GOOD LDR R4,R0, GOOD LDR R5,R0, GOOD LDR R6,R0, GOOD RET SEGMENT bouncer: Beg1: LEA R0, ThisDataSeg AND R1, R1, 0 AND R2, R2, 0 AND R3, R3, 0 ADD R3, R3, 13 ADD R2, R2, 4xB ADD R1, R2, R3 ADD R4, R1, 3 LSHF R2, R2, 3 NOT R5, R3 AND R3, R2, 15 NOP NOP ADD R5, R3, R3 ADD R1, R4, 5 ADD R1, R4, 10 ADD R1, R4, 14 AND R2, R1, -1 STR R2, R0, BlackHole STR R5, R0, BlackHole ADD R0, R0, 2 STR R2, R0, BlackHole ADD R0, R0, -2 LDR R3, R0, Photostat LDR R3, R0, LdThis STR R3, R0, Photostat LDR R3, R0, nosedive ADD R4, R3, 11 LDR R3, R0, tailspin rshfl R4, R4, 1 ADD R5, R3, 7 LDI R1, R0, compass ADD R5, R5, 12 ADD R1, R4, 12 ADD R2, R3, 12 STR R1, R0, beancounter STR R2, R0, beancounter STR R3, R0, beancounter STR R4, R0, beancounter STR R5, R0, beancounter ADD R5, R1, 0 ADD R6, R3, 0 ADD R7, R4, 0 AND R1, R1, 0 AND R3, R3, 0 AND R4, R4, 0 ADD R1, R1, 8 ADD R3, R3, 2 ADD R4, R4, 2 BRp T1 ADD R3, R3, 1 T1: ADD R1, R1, 9 BRn T2 ADD R4, R4, 1 LDR R0, R0, beancounter LEA R0, DataSegment LDR R2, R0, SPOT1 LDR R6, R0, SPOT2 LDR R7, R0, SPOT3 LEA R0, ThisDataSeg AND R3, R3, 0 AND R4, R4, 0 NOP ADD R3, R3, 2 ADD R4, R4, 3 T2: LDR R1, R0, pessimist BRn T3 ADD R3, R3, 1 T3: LDR R1, R0, optimist BRz T4 ADD R4, R4, 1 T4: LDI R1, R0, gloomy BRnz T5 ADD R3, R3, 1 T5: LDI R1, R0, compass BRnz T6 ADD R4, R4, 1 T6: AND R1, R0, 0 LEA R1, ThisDataSeg BRp T7 ADD R3, R3, 1 T7: STR R3, R0, cc1 STR R4, R0, cc2 AND R1, R1, 0 AND R5, R5, 0 ADD R1, R1, -1 BRn T10 ADD R5, R5, 1 ADD R1, R1, -7 T10: ADD R5, R1, R5 NOP NOP NOP STR R5, R0, acorn ADD R0, R5, 0 SEGMENT GoofyCode: AND R5, R5, 0 LEA R1, GetHere JMP R1 ADD R5, R5, 1 GetHere: ADD R5, R0, R5 LEA R0, DataSegment nop nop nop LDR R1, R0, FUN LEA R0, ThisDataSeg STR R5, R0, BlackHole brnzp MoneyMoney SEGMENT ThisDataSeg: BlackHole: DATA2 0 WormHole: DATA2 0 LdThis: DATA2 4xabda Photostat: DATA2 0 nosedive: DATA2 4x9A4D tailspin: DATA2 4x3DAC compass: DATA2 quark beancounter: DATA2 4xfadd pessimist: DATA2 4xFB03 optimist: DATA2 4x0111 gloomy: DATA2 pessimist cc1: DATA2 4xf00f cc2: DATA2 4xf00f acorn: DATA2 4x0FEE quark: DATA2 4x276C payout: DATA2 MoneyMoney SEGMENT MoneyMoney: AND R7, R7, 0 AND R6, R6, 0 AND R5, R5, 0 AND R4, R4, 0 AND R3, R3, 0 AND R2, R2, 0 AND R1, R1, 0 AND R0, R0, 0 LEA R0, DataSegmentMtest LEA R1, Matrix1 LDR R2, R0, Counter2 LDR R3, R0, TWOFIVESIX FillM1: STR R2, R1, 0 ADD R2, R2, -7 ADD R1, R1, 2 ADD R3, R3, -1 BRp FillM1 LEA R4, Matrix1 LDR R2, R0, TWOFIVESIX ADD R4, R2, R4 LDR R3, R0, Counter2 AND R1, R1, 0 AND R2, R2, 0 FILLM2: JSR CalAddress ADD R6, R5, R4 STR R3, R6, 0 ADD R3, R3, -2 JSR CalNext2 ADD R5, R1, 0 BRzp FillM2 LEA R4, Matrix1 LDR R2, R0, TWOFIVESIX ADD R4, R2, R4 ADD R4, R2, R4 LDR R3, R0, Counter2 AND R1, R1, 0 AND R2, R2, 0 FILLM3: JSR CalAddress ADD R6, R5, R4 STR R3, R6, 0 ADD R3, R3, -5 JSR CalNext3 ADD R5, R1, 0 BRzp FillM3 LEA R3, Matrix1 LDR R4, R0, TWOFIVESIX ADD R4, R3, R4 AND R6, R6, 0 Continue1_2: LDR R1, R0, X2 LDR R2, R0, Y2 JSR CalAddress ADD R7, R5, R4 LDR R6, R7, 0 JSR CALNEXT3 STR R1, R0, X2 STR R2, R0, Y2 LDR R1, R0, X1 LDR R2, R0, Y1 JSR CalAddress ADD R5, R5, R3 LDR R7, R5, 0 ADD R6, R6, R7 STR R6, R5, 0 JSR CALNEXT2 ADD R7, R1, 0 BRn Done3 STR R1, R0, X1 STR R2, R0, Y1 BRnzp COntinue1_2 Done3: AND R1, R1, 0 STR R1, R0, X1 STR R1, R0, X2 STR R1, R0, Y1 STR R1, R0, Y2 LEA R3, Matrix1 LDR R4, R0, TWOFIVESIX ADD R4, R4, R4 ADD R4, R3, R4 AND R6, R6, 0 Continue1_3: LDR R1, R0, X2 LDR R2, R0, Y2 JSR CalAddress ADD R7, R5, R3 LDR R6, R7, 0 JSR CALNEXT1 STR R1, R0, X2 STR R2, R0, Y2 LDR R1, R0, X1 LDR R2, R0, Y1 JSR CalAddress ADD R5, R5, R4 LDR R7, R5, 0 ADD R6, R6, R7 STR R6, R5, 0 JSR CALNEXT3 ADD R7, R1, 0 BRn Done4 STR R1, R0, X1 STR R2, R0, Y1 BRnzp COntinue1_3 Done4: BRnzp CheckSUM CalNEXT1: ADD R5, R1, -15 BRz Ytest ADD R1, R1, 1 BRnzp SKIP YTEST: ADD R5, R2, -15 BRz DoneFor ADD R2, R2, 1 AND R1, R1, 0 BRnzp SKIP DoneFor: AND R1, R1, 0 ADD R1, R1, -1 SKip: RET CalNEXT2: ADD R5, R2, -15 BRz Xtest ADD R2, R2, 1 BRnzp SKIP1 XTEST: ADD R5, R1, -15 BRz Done1 ADD R1, R1, 1 AND R2, R2, 0 BRnzp SKIP1 Done1: AND R1, R1, 0 ADD R1, R1, -1 SKip1: RET CalNEXT3: STR R3, R0, TEMP3 ADD R3, R1, -15 BRz DRow ADD R3, R2, 0 BRz DRow1 LDR R3, R0, NEGONEFIVE ADD R3, R1, -15 BRz DRow ADD R1, R1, 1 ADD R2, R2, -1 BRnzp SKIP2 DRow1: ADD R2, R1, 1 AND R1, R1, 0 BRnzp SKIP2 DRow: ADD R3, R2, -15 BRz Done2 ADD R1, R2, 1 AND R2, R2, 0 ADD R2, R2, 15 BRnzp SKIP2 Done2: AND R1, R1, 0 ADD R1, R1, -1 SKIP2: LDR R3, R0, TEMP3 RET CalAddress: LSHF R5, R2, 4 ADD R5, R1, R5 LSHF R5, R5, 1 RET CHECKSUM: LEA R1, Matrix1 LDR R4, R0, TWOFIVESIX ADD R4, R4, R4 ADD R1, R4, R1 AND R7, R7, 0 AND R6, R6, 0 AND R5, R5, 0 AND R4, R4, 0 LDR R2, R0, ONEFOURTHREE LoopRowsA: LDR R3, R1, 0 ADD R4, R3, R4 ADD R1, R1, 2 ADD R2, R2, -1 BRzp LoopRowsA LSHF R4,R4,2 LDR R2, R0, ONEFOURTHREE LoopRowsB: LDR R3, R1, 0 ADD R5, R3, R5 ADD R1, R1, 2 ADD R2, R2, -1 BRzp LoopRowsB LSHF R5,R5,2 LDR R2, R0, ONEFOURTHREE LoopRowsC: LDR R3, R1, 0 ADD R6, R3, R6 ADD R1, R1, 2 ADD R2, R2, -1 BRzp LoopRowsC LSHF R6,R6,2 LDR R2, R0, ONEFOURTHREE LoopRowsD: LDR R3, R1, 0 ADD R7, R3, R7 ADD R1, R1, 2 ADD R2, R2, -1 BRzp LoopRowsD AND R3, R3,R7 NOT R7,R7 HALT: BRnzp HALT SEGMENT DataSegmentMtest: X1: DATA2 4x0000 Y1: DATA2 4x0000 X2: DATA2 4x0000 Y2: DATA2 4x0000 TEMP1: DATA2 4x0000 TEMP2: DATA2 4x0000 TEMP3: DATA2 4x0000 TEMP4: DATA2 4x0000 TWOFIVESIX: DATA2 256 UpperMemStart: DATA2 4xF000 Counter1: DATA2 4x0FFF Counter2: DATA2 4x4A3F ONEFOURTHREE: DATA2 63 NEGONEFIVE: DATA2 -15 Mask: Data2 4x00FF SEGMENT Matrix1: M00: DATA2 4x0000 M01: DATA2 4x0000 M02: DATA2 4x0000 M03: DATA2 4x0000 M04: DATA2 4x0000 M05: DATA2 4x0000 M06: DATA2 4x0000 M07: DATA2 4x0000 M08: DATA2 4x0000 M09: DATA2 4x0000 M0A: DATA2 4x0000 M0B: DATA2 4x0000 M0C: DATA2 4x0000 M0D: DATA2 4x0000 M0E: DATA2 4x0000 M0F: DATA2 4x0000 M10: DATA2 4x0000 M11: DATA2 4x0000 M12: DATA2 4x0000 M13: DATA2 4x0000 M14: DATA2 4x0000 M15: DATA2 4x0000 M16: DATA2 4x0000 M17: DATA2 4x0000 M18: DATA2 4x0000 M19: DATA2 4x0000 M1A: DATA2 4x0000 M1B: DATA2 4x0000 M1C: DATA2 4x0000 M1D: DATA2 4x0000 M1E: DATA2 4x0000 M1F: DATA2 4x0000 M20: DATA2 4x0000 M21: DATA2 4x0000 M22: DATA2 4x0000 M23: DATA2 4x0000 M24: DATA2 4x0000 M25: DATA2 4x0000 M26: DATA2 4x0000 M27: DATA2 4x0000 M28: DATA2 4x0000 M29: DATA2 4x0000 M2A: DATA2 4x0000 M2B: DATA2 4x0000 M2C: DATA2 4x0000 M2D: DATA2 4x0000 M2E: DATA2 4x0000 M2F: DATA2 4x0000 M30: DATA2 4x0000 M31: DATA2 4x0000 M32: DATA2 4x0000 M33: DATA2 4x0000 M34: DATA2 4x0000 M35: DATA2 4x0000 M36: DATA2 4x0000 M37: DATA2 4x0000 M38: DATA2 4x0000 M39: DATA2 4x0000 M3A: DATA2 4x0000 M3B: DATA2 4x0000 M3C: DATA2 4x0000 M3D: DATA2 4x0000 M3E: DATA2 4x0000 M3F: DATA2 4x0000 M40: DATA2 4x0000 M41: DATA2 4x0000 M42: DATA2 4x0000 M43: DATA2 4x0000 M44: DATA2 4x0000 M45: DATA2 4x0000 M46: DATA2 4x0000 M47: DATA2 4x0000 M48: DATA2 4x0000 M49: DATA2 4x0000 M4A: DATA2 4x0000 M4B: DATA2 4x0000 M4C: DATA2 4x0000 M4D: DATA2 4x0000 M4E: DATA2 4x0000 M4F: DATA2 4x0000 M50: DATA2 4x0000 M51: DATA2 4x0000 M52: DATA2 4x0000 M53: DATA2 4x0000 M54: DATA2 4x0000 M55: DATA2 4x0000 M56: DATA2 4x0000 M57: DATA2 4x0000 M58: DATA2 4x0000 M59: DATA2 4x0000 M5A: DATA2 4x0000 M5B: DATA2 4x0000 M5C: DATA2 4x0000 M5D: DATA2 4x0000 M5E: DATA2 4x0000 M5F: DATA2 4x0000 M60: DATA2 4x0000 M61: DATA2 4x0000 M62: DATA2 4x0000 M63: DATA2 4x0000 M64: DATA2 4x0000 M65: DATA2 4x0000 M66: DATA2 4x0000 M67: DATA2 4x0000 M68: DATA2 4x0000 M69: DATA2 4x0000 M6A: DATA2 4x0000 M6B: DATA2 4x0000 M6C: DATA2 4x0000 M6D: DATA2 4x0000 M6E: DATA2 4x0000 M6F: DATA2 4x0000 M70: DATA2 4x0000 M71: DATA2 4x0000 M72: DATA2 4x0000 M73: DATA2 4x0000 M74: DATA2 4x0000 M75: DATA2 4x0000 M76: DATA2 4x0000 M77: DATA2 4x0000 M78: DATA2 4x0000 M79: DATA2 4x0000 M7A: DATA2 4x0000 M7B: DATA2 4x0000 M7C: DATA2 4x0000 M7D: DATA2 4x0000 M7E: DATA2 4x0000 M7F: DATA2 4x0000 M80: DATA2 4x0000 M81: DATA2 4x0000 M82: DATA2 4x0000 M83: DATA2 4x0000 M84: DATA2 4x0000 M85: DATA2 4x0000 M86: DATA2 4x0000 M87: DATA2 4x0000 M88: DATA2 4x0000 M89: DATA2 4x0000 M8A: DATA2 4x0000 M8B: DATA2 4x0000 M8C: DATA2 4x0000 M8D: DATA2 4x0000 M8E: DATA2 4x0000 M8F: DATA2 4x0000 M90: DATA2 4x0000 M91: DATA2 4x0000 M92: DATA2 4x0000 M93: DATA2 4x0000 M94: DATA2 4x0000 M95: DATA2 4x0000 M96: DATA2 4x0000 M97: DATA2 4x0000 M98: DATA2 4x0000 M99: DATA2 4x0000 M9A: DATA2 4x0000 M9B: DATA2 4x0000 M9C: DATA2 4x0000 M9D: DATA2 4x0000 M9E: DATA2 4x0000 M9F: DATA2 4x0000 MA0: DATA2 4x0000 MA1: DATA2 4x0000 MA2: DATA2 4x0000 MA3: DATA2 4x0000 MA4: DATA2 4x0000 MA5: DATA2 4x0000 MA6: DATA2 4x0000 MA7: DATA2 4x0000 MA8: DATA2 4x0000 MA9: DATA2 4x0000 MAA: DATA2 4x0000 MAB: DATA2 4x0000 MAC: DATA2 4x0000 MAD: DATA2 4x0000 MAE: DATA2 4x0000 MAF: DATA2 4x0000 MB0: DATA2 4x0000 MB1: DATA2 4x0000 MB2: DATA2 4x0000 MB3: DATA2 4x0000 MB4: DATA2 4x0000 MB5: DATA2 4x0000 MB6: DATA2 4x0000 MB7: DATA2 4x0000 MB8: DATA2 4x0000 MB9: DATA2 4x0000 MBA: DATA2 4x0000 MBB: DATA2 4x0000 MBC: DATA2 4x0000 MBD: DATA2 4x0000 MBE: DATA2 4x0000 MBF: DATA2 4x0000 MC0: DATA2 4x0000 MC1: DATA2 4x0000 MC2: DATA2 4x0000 MC3: DATA2 4x0000 MC4: DATA2 4x0000 MC5: DATA2 4x0000 MC6: DATA2 4x0000 MC7: DATA2 4x0000 MC8: DATA2 4x0000 MC9: DATA2 4x0000 MCA: DATA2 4x0000 MCB: DATA2 4x0000 MCC: DATA2 4x0000 MCD: DATA2 4x0000 MCE: DATA2 4x0000 MCF: DATA2 4x0000 MD0: DATA2 4x0000 MD1: DATA2 4x0000 MD2: DATA2 4x0000 MD3: DATA2 4x0000 MD4: DATA2 4x0000 MD5: DATA2 4x0000 MD6: DATA2 4x0000 MD7: DATA2 4x0000 MD8: DATA2 4x0000 MD9: DATA2 4x0000 MDA: DATA2 4x0000 MDB: DATA2 4x0000 MDC: DATA2 4x0000 MDD: DATA2 4x0000 MDE: DATA2 4x0000 MDF: DATA2 4x0000 ME0: DATA2 4x0000 ME1: DATA2 4x0000 ME2: DATA2 4x0000 ME3: DATA2 4x0000 ME4: DATA2 4x0000 ME5: DATA2 4x0000 ME6: DATA2 4x0000 ME7: DATA2 4x0000 ME8: DATA2 4x0000 ME9: DATA2 4x0000 MEA: DATA2 4x0000 MEB: DATA2 4x0000 MEC: DATA2 4x0000 MED: DATA2 4x0000 MEE: DATA2 4x0000 MEF: DATA2 4x0000 MF0: DATA2 4x0000 MF1: DATA2 4x0000 MF2: DATA2 4x0000 MF3: DATA2 4x0000 MF4: DATA2 4x0000 MF5: DATA2 4x0000 MF6: DATA2 4x0000 MF7: DATA2 4x0000 MF8: DATA2 4x0000 MF9: DATA2 4x0000 MFA: DATA2 4x0000 MFB: DATA2 4x0000 MFC: DATA2 4x0000 MFD: DATA2 4x0000 MFE: DATA2 4x0000 MFF: DATA2 4x0000 SEGMENT Matrix2: N00: DATA2 4x0000 N01: DATA2 4x0000 N02: DATA2 4x0000 N03: DATA2 4x0000 N04: DATA2 4x0000 N05: DATA2 4x0000 N06: DATA2 4x0000 N07: DATA2 4x0000 N08: DATA2 4x0000 N09: DATA2 4x0000 N0A: DATA2 4x0000 N0B: DATA2 4x0000 N0C: DATA2 4x0000 N0D: DATA2 4x0000 N0E: DATA2 4x0000 N0F: DATA2 4x0000 N10: DATA2 4x0000 N11: DATA2 4x0000 N12: DATA2 4x0000 N13: DATA2 4x0000 N14: DATA2 4x0000 N15: DATA2 4x0000 N16: DATA2 4x0000 N17: DATA2 4x0000 N18: DATA2 4x0000 N19: DATA2 4x0000 N1A: DATA2 4x0000 N1B: DATA2 4x0000 N1C: DATA2 4x0000 N1D: DATA2 4x0000 N1E: DATA2 4x0000 N1F: DATA2 4x0000 N20: DATA2 4x0000 N21: DATA2 4x0000 N22: DATA2 4x0000 N23: DATA2 4x0000 N24: DATA2 4x0000 N25: DATA2 4x0000 N26: DATA2 4x0000 N27: DATA2 4x0000 N28: DATA2 4x0000 N29: DATA2 4x0000 N2A: DATA2 4x0000 N2B: DATA2 4x0000 N2C: DATA2 4x0000 N2D: DATA2 4x0000 N2E: DATA2 4x0000 N2F: DATA2 4x0000 N30: DATA2 4x0000 N31: DATA2 4x0000 N32: DATA2 4x0000 N33: DATA2 4x0000 N34: DATA2 4x0000 N35: DATA2 4x0000 N36: DATA2 4x0000 N37: DATA2 4x0000 N38: DATA2 4x0000 N39: DATA2 4x0000 N3A: DATA2 4x0000 N3B: DATA2 4x0000 N3C: DATA2 4x0000 N3D: DATA2 4x0000 N3E: DATA2 4x0000 N3F: DATA2 4x0000 N40: DATA2 4x0000 N41: DATA2 4x0000 N42: DATA2 4x0000 N43: DATA2 4x0000 N44: DATA2 4x0000 N45: DATA2 4x0000 N46: DATA2 4x0000 N47: DATA2 4x0000 N48: DATA2 4x0000 N49: DATA2 4x0000 N4A: DATA2 4x0000 N4B: DATA2 4x0000 N4C: DATA2 4x0000 N4D: DATA2 4x0000 N4E: DATA2 4x0000 N4F: DATA2 4x0000 N50: DATA2 4x0000 N51: DATA2 4x0000 N52: DATA2 4x0000 N53: DATA2 4x0000 N54: DATA2 4x0000 N55: DATA2 4x0000 N56: DATA2 4x0000 N57: DATA2 4x0000 N58: DATA2 4x0000 N59: DATA2 4x0000 N5A: DATA2 4x0000 N5B: DATA2 4x0000 N5C: DATA2 4x0000 N5D: DATA2 4x0000 N5E: DATA2 4x0000 N5F: DATA2 4x0000 N60: DATA2 4x0000 N61: DATA2 4x0000 N62: DATA2 4x0000 N63: DATA2 4x0000 N64: DATA2 4x0000 N65: DATA2 4x0000 N66: DATA2 4x0000 N67: DATA2 4x0000 N68: DATA2 4x0000 N69: DATA2 4x0000 N6A: DATA2 4x0000 N6B: DATA2 4x0000 N6C: DATA2 4x0000 N6D: DATA2 4x0000 N6E: DATA2 4x0000 N6F: DATA2 4x0000 N70: DATA2 4x0000 N71: DATA2 4x0000 N72: DATA2 4x0000 N73: DATA2 4x0000 N74: DATA2 4x0000 N75: DATA2 4x0000 N76: DATA2 4x0000 N77: DATA2 4x0000 N78: DATA2 4x0000 N79: DATA2 4x0000 N7A: DATA2 4x0000 N7B: DATA2 4x0000 N7C: DATA2 4x0000 N7D: DATA2 4x0000 N7E: DATA2 4x0000 N7F: DATA2 4x0000 N80: DATA2 4x0000 N81: DATA2 4x0000 N82: DATA2 4x0000 N83: DATA2 4x0000 N84: DATA2 4x0000 N85: DATA2 4x0000 N86: DATA2 4x0000 N87: DATA2 4x0000 N88: DATA2 4x0000 N89: DATA2 4x0000 N8A: DATA2 4x0000 N8B: DATA2 4x0000 N8C: DATA2 4x0000 N8D: DATA2 4x0000 N8E: DATA2 4x0000 N8F: DATA2 4x0000 N90: DATA2 4x0000 N91: DATA2 4x0000 N92: DATA2 4x0000 N93: DATA2 4x0000 N94: DATA2 4x0000 N95: DATA2 4x0000 N96: DATA2 4x0000 N97: DATA2 4x0000 N98: DATA2 4x0000 N99: DATA2 4x0000 N9A: DATA2 4x0000 N9B: DATA2 4x0000 N9C: DATA2 4x0000 N9D: DATA2 4x0000 N9E: DATA2 4x0000 N9F: DATA2 4x0000 NA0: DATA2 4x0000 NA1: DATA2 4x0000 NA2: DATA2 4x0000 NA3: DATA2 4x0000 NA4: DATA2 4x0000 NA5: DATA2 4x0000 NA6: DATA2 4x0000 NA7: DATA2 4x0000 NA8: DATA2 4x0000 NA9: DATA2 4x0000 NAA: DATA2 4x0000 NAB: DATA2 4x0000 NAC: DATA2 4x0000 NAD: DATA2 4x0000 NAE: DATA2 4x0000 NAF: DATA2 4x0000 NB0: DATA2 4x0000 NB1: DATA2 4x0000 NB2: DATA2 4x0000 NB3: DATA2 4x0000 NB4: DATA2 4x0000 NB5: DATA2 4x0000 NB6: DATA2 4x0000 NB7: DATA2 4x0000 NB8: DATA2 4x0000 NB9: DATA2 4x0000 NBA: DATA2 4x0000 NBB: DATA2 4x0000 NBC: DATA2 4x0000 NBD: DATA2 4x0000 NBE: DATA2 4x0000 NBF: DATA2 4x0000 NC0: DATA2 4x0000 NC1: DATA2 4x0000 NC2: DATA2 4x0000 NC3: DATA2 4x0000 NC4: DATA2 4x0000 NC5: DATA2 4x0000 NC6: DATA2 4x0000 NC7: DATA2 4x0000 NC8: DATA2 4x0000 NC9: DATA2 4x0000 NCA: DATA2 4x0000 NCB: DATA2 4x0000 NCC: DATA2 4x0000 NCD: DATA2 4x0000 NCE: DATA2 4x0000 NCF: DATA2 4x0000 ND0: DATA2 4x0000 ND1: DATA2 4x0000 ND2: DATA2 4x0000 ND3: DATA2 4x0000 ND4: DATA2 4x0000 ND5: DATA2 4x0000 ND6: DATA2 4x0000 ND7: DATA2 4x0000 ND8: DATA2 4x0000 ND9: DATA2 4x0000 NDA: DATA2 4x0000 NDB: DATA2 4x0000 NDC: DATA2 4x0000 NDD: DATA2 4x0000 NDE: DATA2 4x0000 NDF: DATA2 4x0000 NE0: DATA2 4x0000 NE1: DATA2 4x0000 NE2: DATA2 4x0000 NE3: DATA2 4x0000 NE4: DATA2 4x0000 NE5: DATA2 4x0000 NE6: DATA2 4x0000 NE7: DATA2 4x0000 NE8: DATA2 4x0000 NE9: DATA2 4x0000 NEA: DATA2 4x0000 NEB: DATA2 4x0000 NEC: DATA2 4x0000 NED: DATA2 4x0000 NEE: DATA2 4x0000 NEF: DATA2 4x0000 NF0: DATA2 4x0000 NF1: DATA2 4x0000 NF2: DATA2 4x0000 NF3: DATA2 4x0000 NF4: DATA2 4x0000 NF5: DATA2 4x0000 NF6: DATA2 4x0000 NF7: DATA2 4x0000 NF8: DATA2 4x0000 NF9: DATA2 4x0000 NFA: DATA2 4x0000 NFB: DATA2 4x0000 NFC: DATA2 4x0000 NFD: DATA2 4x0000 NFE: DATA2 4x0000 NFF: DATA2 4x0000 SEGMENT Matrix3: O00: DATA2 4x0000 O01: DATA2 4x0000 O02: DATA2 4x0000 O03: DATA2 4x0000 O04: DATA2 4x0000 O05: DATA2 4x0000 O06: DATA2 4x0000 O07: DATA2 4x0000 O08: DATA2 4x0000 O09: DATA2 4x0000 O0A: DATA2 4x0000 O0B: DATA2 4x0000 O0C: DATA2 4x0000 O0D: DATA2 4x0000 O0E: DATA2 4x0000 O0F: DATA2 4x0000 O10: DATA2 4x0000 O11: DATA2 4x0000 O12: DATA2 4x0000 O13: DATA2 4x0000 O14: DATA2 4x0000 O15: DATA2 4x0000 O16: DATA2 4x0000 O17: DATA2 4x0000 O18: DATA2 4x0000 O19: DATA2 4x0000 O1A: DATA2 4x0000 O1B: DATA2 4x0000 O1C: DATA2 4x0000 O1D: DATA2 4x0000 O1E: DATA2 4x0000 O1F: DATA2 4x0000 O20: DATA2 4x0000 O21: DATA2 4x0000 O22: DATA2 4x0000 O23: DATA2 4x0000 O24: DATA2 4x0000 O25: DATA2 4x0000 O26: DATA2 4x0000 O27: DATA2 4x0000 O28: DATA2 4x0000 O29: DATA2 4x0000 O2A: DATA2 4x0000 O2B: DATA2 4x0000 O2C: DATA2 4x0000 O2D: DATA2 4x0000 O2E: DATA2 4x0000 O2F: DATA2 4x0000 O30: DATA2 4x0000 O31: DATA2 4x0000 O32: DATA2 4x0000 O33: DATA2 4x0000 O34: DATA2 4x0000 O35: DATA2 4x0000 O36: DATA2 4x0000 O37: DATA2 4x0000 O38: DATA2 4x0000 O39: DATA2 4x0000 O3A: DATA2 4x0000 O3B: DATA2 4x0000 O3C: DATA2 4x0000 O3D: DATA2 4x0000 O3E: DATA2 4x0000 O3F: DATA2 4x0000 O40: DATA2 4x0000 O41: DATA2 4x0000 O42: DATA2 4x0000 O43: DATA2 4x0000 O44: DATA2 4x0000 O45: DATA2 4x0000 O46: DATA2 4x0000 O47: DATA2 4x0000 O48: DATA2 4x0000 O49: DATA2 4x0000 O4A: DATA2 4x0000 O4B: DATA2 4x0000 O4C: DATA2 4x0000 O4D: DATA2 4x0000 O4E: DATA2 4x0000 O4F: DATA2 4x0000 O50: DATA2 4x0000 O51: DATA2 4x0000 O52: DATA2 4x0000 O53: DATA2 4x0000 O54: DATA2 4x0000 O55: DATA2 4x0000 O56: DATA2 4x0000 O57: DATA2 4x0000 O58: DATA2 4x0000 O59: DATA2 4x0000 O5A: DATA2 4x0000 O5B: DATA2 4x0000 O5C: DATA2 4x0000 O5D: DATA2 4x0000 O5E: DATA2 4x0000 O5F: DATA2 4x0000 O60: DATA2 4x0000 O61: DATA2 4x0000 O62: DATA2 4x0000 O63: DATA2 4x0000 O64: DATA2 4x0000 O65: DATA2 4x0000 O66: DATA2 4x0000 O67: DATA2 4x0000 O68: DATA2 4x0000 O69: DATA2 4x0000 O6A: DATA2 4x0000 O6B: DATA2 4x0000 O6C: DATA2 4x0000 O6D: DATA2 4x0000 O6E: DATA2 4x0000 O6F: DATA2 4x0000 O70: DATA2 4x0000 O71: DATA2 4x0000 O72: DATA2 4x0000 O73: DATA2 4x0000 O74: DATA2 4x0000 O75: DATA2 4x0000 O76: DATA2 4x0000 O77: DATA2 4x0000 O78: DATA2 4x0000 O79: DATA2 4x0000 O7A: DATA2 4x0000 O7B: DATA2 4x0000 O7C: DATA2 4x0000 O7D: DATA2 4x0000 O7E: DATA2 4x0000 O7F: DATA2 4x0000 O80: DATA2 4x0000 O81: DATA2 4x0000 O82: DATA2 4x0000 O83: DATA2 4x0000 O84: DATA2 4x0000 O85: DATA2 4x0000 O86: DATA2 4x0000 O87: DATA2 4x0000 O88: DATA2 4x0000 O89: DATA2 4x0000 O8A: DATA2 4x0000 O8B: DATA2 4x0000 O8C: DATA2 4x0000 O8D: DATA2 4x0000 O8E: DATA2 4x0000 O8F: DATA2 4x0000 O90: DATA2 4x0000 O91: DATA2 4x0000 O92: DATA2 4x0000 O93: DATA2 4x0000 O94: DATA2 4x0000 O95: DATA2 4x0000 O96: DATA2 4x0000 O97: DATA2 4x0000 O98: DATA2 4x0000 O99: DATA2 4x0000 O9A: DATA2 4x0000 O9B: DATA2 4x0000 O9C: DATA2 4x0000 O9D: DATA2 4x0000 O9E: DATA2 4x0000 O9F: DATA2 4x0000 OA0: DATA2 4x0000 OA1: DATA2 4x0000 OA2: DATA2 4x0000 OA3: DATA2 4x0000 OA4: DATA2 4x0000 OA5: DATA2 4x0000 OA6: DATA2 4x0000 OA7: DATA2 4x0000 OA8: DATA2 4x0000 OA9: DATA2 4x0000 OAA: DATA2 4x0000 OAB: DATA2 4x0000 OAC: DATA2 4x0000 OAD: DATA2 4x0000 OAE: DATA2 4x0000 OAF: DATA2 4x0000 OB0: DATA2 4x0000 OB1: DATA2 4x0000 OB2: DATA2 4x0000 OB3: DATA2 4x0000 OB4: DATA2 4x0000 OB5: DATA2 4x0000 OB6: DATA2 4x0000 OB7: DATA2 4x0000 OB8: DATA2 4x0000 OB9: DATA2 4x0000 OBA: DATA2 4x0000 OBB: DATA2 4x0000 OBC: DATA2 4x0000 OBD: DATA2 4x0000 OBE: DATA2 4x0000 OBF: DATA2 4x0000 OC0: DATA2 4x0000 OC1: DATA2 4x0000 OC2: DATA2 4x0000 OC3: DATA2 4x0000 OC4: DATA2 4x0000 OC5: DATA2 4x0000 OC6: DATA2 4x0000 OC7: DATA2 4x0000 OC8: DATA2 4x0000 OC9: DATA2 4x0000 OCA: DATA2 4x0000 OCB: DATA2 4x0000 OCC: DATA2 4x0000 OCD: DATA2 4x0000 OCE: DATA2 4x0000 OCF: DATA2 4x0000 OD0: DATA2 4x0000 OD1: DATA2 4x0000 OD2: DATA2 4x0000 OD3: DATA2 4x0000 OD4: DATA2 4x0000 OD5: DATA2 4x0000 OD6: DATA2 4x0000 OD7: DATA2 4x0000 OD8: DATA2 4x0000 OD9: DATA2 4x0000 ODA: DATA2 4x0000 ODB: DATA2 4x0000 ODC: DATA2 4x0000 ODD: DATA2 4x0000 ODE: DATA2 4x0000 ODF: DATA2 4x0000 OE0: DATA2 4x0000 OE1: DATA2 4x0000 OE2: DATA2 4x0000 OE3: DATA2 4x0000 OE4: DATA2 4x0000 OE5: DATA2 4x0000 OE6: DATA2 4x0000 OE7: DATA2 4x0000 OE8: DATA2 4x0000 OE9: DATA2 4x0000 OEA: DATA2 4x0000 OEB: DATA2 4x0000 OEC: DATA2 4x0000 OED: DATA2 4x0000 OEE: DATA2 4x0000 OEF: DATA2 4x0000 OF0: DATA2 4x0000 OF1: DATA2 4x0000 OF2: DATA2 4x0000 OF3: DATA2 4x0000 OF4: DATA2 4x0000 OF5: DATA2 4x0000 OF6: DATA2 4x0000 OF7: DATA2 4x0000 OF8: DATA2 4x0000 OF9: DATA2 4x0000 OFA: DATA2 4x0000 OFB: DATA2 4x0000 OFC: DATA2 4x0000 OFD: DATA2 4x0000 OFE: DATA2 4x0000 OFF: DATA2 4x0000
#include "GameOverOverlay.h" GameOverOverlay::GameOverOverlay(void) { GameApp *app = GameApp::getInstance(); centerText = new TextItem(Vector2(POSITION_CENTERED, 60), 0, "Game Over", 100); centerText->setFont("resources/fonts/Honeycombed.ttf"); addInnerItem(centerText); this->texture = Texture::getOrCreate("0xAA000000", Colour(0xCC000000)); this->position = new Vector2(0, 0); this->size = new Vector2((float) app->getWindowWidth(), (float) app->getWindowHeight()); this->hidden = true; // Create the menu buttons restartButton = new ButtonItem(Vector2(InterfaceItem::POSITION_CENTERED, 450), 0, Vector2(800, 120), "MenuButton", "resources/images/MenuButton.png", "resources/images/MenuButtonHov.png", "resources/images/MenuButtonPress.png", "resources/images/MenuButtonPress.png"); addInnerItem(restartButton); leaderboardButton = new ButtonItem(Vector2(InterfaceItem::POSITION_CENTERED, 590), 0, Vector2(800, 120), "MenuButton", "resources/images/MenuButton.png", "resources/images/MenuButtonHov.png", "resources/images/MenuButtonPress.png", "resources/images/MenuButtonPress.png"); addInnerItem(leaderboardButton); menuButton = new ButtonItem(Vector2(InterfaceItem::POSITION_CENTERED, 730), 0, Vector2(800, 120), "MenuButton", "resources/images/MenuButton.png", "resources/images/MenuButtonHov.png", "resources/images/MenuButtonPress.png", "resources/images/MenuButtonPress.png"); addInnerItem(menuButton); quitButton = new ButtonItem(Vector2(InterfaceItem::POSITION_CENTERED, 870), 0, Vector2(800, 120), "MenuButton", "resources/images/MenuButton.png", "resources/images/MenuButtonHov.png", "resources/images/MenuButtonPress.png", "resources/images/MenuButtonPress.png"); addInnerItem(quitButton); // Draw some text over the buttons background TextItem *restartText = new TextItem(Vector2(InterfaceItem::POSITION_CENTERED, 470), 0, "Play Again", 72); restartText->setFont("resources/fonts/Neuropol.ttf"); addInnerItem(restartText); TextItem *leaderboardText = new TextItem(Vector2(InterfaceItem::POSITION_CENTERED, 610), 0, "Leaderboard", 72); leaderboardText->setFont("resources/fonts/Neuropol.ttf"); addInnerItem(leaderboardText); TextItem *menuText = new TextItem(Vector2(InterfaceItem::POSITION_CENTERED, 750), 0, "Quit to Menu", 72); menuText->setFont("resources/fonts/Neuropol.ttf"); addInnerItem(menuText); TextItem *quitText = new TextItem(Vector2(InterfaceItem::POSITION_CENTERED, 890), 0, "Quit to Desktop", 72); quitText->setFont("resources/fonts/Neuropol.ttf"); addInnerItem(quitText); // Draw the score of the player scoreText = new TextItem(Vector2(InterfaceItem::POSITION_CENTERED, 225), 0, "Total Distance: 00000m", 80); scoreText->setFont("resources/fonts/Neuropol.ttf"); addInnerItem(scoreText); } GameOverOverlay::~GameOverOverlay(void) { delete centerText; delete leaderboardButton; delete restartButton; delete menuButton; delete quitButton; } void GameOverOverlay::onKeyPress(SDL_Keysym key) { } void GameOverOverlay::update(unsigned millisElapsed) { if (restartButton->isPressed()) { GameMenu *menu = new GameMenu(); menu->setActionAfterFade(1); GameApp::getInstance()->setCurrentLevel(menu); } if (leaderboardButton->isPressed()) { LeaderboardScreen *leaderboard = new LeaderboardScreen(); GameApp::getInstance()->setCurrentLevel(leaderboard); } if (menuButton->isPressed()) { GameMenu *menu = new GameMenu(); GameApp::getInstance()->setCurrentLevel(menu); } if (quitButton->isPressed()) { GameApp::getInstance()->exitGame(); } InterfaceItem::update(millisElapsed); } void GameOverOverlay::setDistance(int distance) { this->distance = distance; char buffer[80]; sprintf(buffer, "Total Distance: %05dm", distance); scoreText->setText(buffer); } void GameOverOverlay::setLeaderboardPos(int pos) { if (pos > 0) { std::string text = ""; switch (pos) { case 1: text = "Congratulations! You've got FIRST place!"; break; case 2: text = "Congratulations! You've got 2nd place!"; break; case 3: text = "Congratulations! You've got 3rd place!"; break; case 4: text = "Congratulations! You've got 4th place!"; break; case 5: text = "Congratulations! You've got 5th place!"; break; } TextItem *leaderboardText = new TextItem(Vector2(InterfaceItem::POSITION_CENTERED, 325), 0, text, 80); leaderboardText->setFont("resources/fonts/Neuropol.ttf"); leaderboardText->setColour(Colour(0xFFFFDD00)); addInnerItem(leaderboardText); } }
#ifndef BOOST_METAPARSE_V1_FWD_NEXT_LINE_IMPL_HPP #define BOOST_METAPARSE_V1_FWD_NEXT_LINE_IMPL_HPP // Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. // 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) namespace boost { namespace metaparse { namespace v1 { template <class P> struct next_line_impl; template <class P, class Ch> struct next_line; } } } #endif
// Copyright (c) 2017 The DYOR developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "irc.h" #include "db.h" #include "net.h" #include "init.h" #include "strlcpy.h" #include "addrman.h" #include "ui_interface.h" #ifdef WIN32 #include <string.h> #endif #ifdef USE_UPNP #include <miniupnpc/miniwget.h> #include <miniupnpc/miniupnpc.h> #include <miniupnpc/upnpcommands.h> #include <miniupnpc/upnperrors.h> #endif using namespace std; using namespace boost; static const int MAX_OUTBOUND_CONNECTIONS = 16; void ThreadMessageHandler2(void* parg); void ThreadSocketHandler2(void* parg); void ThreadOpenConnections2(void* parg); void ThreadOpenAddedConnections2(void* parg); #ifdef USE_UPNP void ThreadMapPort2(void* parg); #endif void ThreadDNSAddressSeed2(void* parg); bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false); struct LocalServiceInfo { int nScore; int nPort; }; // // Global state variables // bool fDiscover = true; bool fUseUPnP = false; uint64_t nLocalServices = NODE_NETWORK; static CCriticalSection cs_mapLocalHost; static map<CNetAddr, LocalServiceInfo> mapLocalHost; static bool vfReachable[NET_MAX] = {}; static bool vfLimited[NET_MAX] = {}; static CNode* pnodeLocalHost = NULL; CAddress addrSeenByPeer(CService("0.0.0.0", 0), nLocalServices); uint64_t nLocalHostNonce = 0; boost::array<int, THREAD_MAX> vnThreadsRunning; static std::vector<SOCKET> vhListenSocket; CAddrMan addrman; vector<CNode*> vNodes; CCriticalSection cs_vNodes; map<CInv, CDataStream> mapRelay; deque<pair<int64_t, CInv> > vRelayExpiration; CCriticalSection cs_mapRelay; map<CInv, int64_t> mapAlreadyAskedFor; static deque<string> vOneShots; CCriticalSection cs_vOneShots; set<CNetAddr> setservAddNodeAddresses; CCriticalSection cs_setservAddNodeAddresses; static CSemaphore *semOutbound = NULL; void AddOneShot(string strDest) { LOCK(cs_vOneShots); vOneShots.push_back(strDest); } unsigned short GetListenPort() { return (unsigned short)(GetArg("-port", GetDefaultPort())); } void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd) { // Filter out duplicate requests if (pindexBegin == pindexLastGetBlocksBegin && hashEnd == hashLastGetBlocksEnd) return; pindexLastGetBlocksBegin = pindexBegin; hashLastGetBlocksEnd = hashEnd; PushMessage("getblocks", CBlockLocator(pindexBegin), hashEnd); } // find 'best' local address for a particular peer bool GetLocal(CService& addr, const CNetAddr *paddrPeer) { if (fNoListen) return false; int nBestScore = -1; int nBestReachability = -1; { LOCK(cs_mapLocalHost); for (map<CNetAddr, LocalServiceInfo>::iterator it = mapLocalHost.begin(); it != mapLocalHost.end(); it++) { int nScore = (*it).second.nScore; int nReachability = (*it).first.GetReachabilityFrom(paddrPeer); if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore)) { addr = CService((*it).first, (*it).second.nPort); nBestReachability = nReachability; nBestScore = nScore; } } } return nBestScore >= 0; } // get best local address for a particular peer as a CAddress CAddress GetLocalAddress(const CNetAddr *paddrPeer) { CAddress ret(CService("0.0.0.0",0),0); CService addr; if (GetLocal(addr, paddrPeer)) { ret = CAddress(addr); ret.nServices = nLocalServices; ret.nTime = GetAdjustedTime(); } return ret; } bool RecvLine(SOCKET hSocket, string& strLine) { strLine = ""; while (true) { char c; int nBytes = recv(hSocket, &c, 1, 0); if (nBytes > 0) { if (c == '\n') continue; if (c == '\r') return true; strLine += c; if (strLine.size() >= 9000) return true; } else if (nBytes <= 0) { if (fShutdown) return false; if (nBytes < 0) { int nErr = WSAGetLastError(); if (nErr == WSAEMSGSIZE) continue; if (nErr == WSAEWOULDBLOCK || nErr == WSAEINTR || nErr == WSAEINPROGRESS) { MilliSleep(10); continue; } } if (!strLine.empty()) return true; if (nBytes == 0) { // socket closed printf("socket closed\n"); return false; } else { // socket error int nErr = WSAGetLastError(); printf("recv failed: %d\n", nErr); return false; } } } } // used when scores of local addresses may have changed // pushes better local address to peers void static AdvertizeLocal() { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { if (pnode->fSuccessfullyConnected) { CAddress addrLocal = GetLocalAddress(&pnode->addr); if (addrLocal.IsRoutable() && (CService)addrLocal != (CService)pnode->addrLocal) { pnode->PushAddress(addrLocal); pnode->addrLocal = addrLocal; } } } } void SetReachable(enum Network net, bool fFlag) { LOCK(cs_mapLocalHost); vfReachable[net] = fFlag; if (net == NET_IPV6 && fFlag) vfReachable[NET_IPV4] = true; } // learn a new local address bool AddLocal(const CService& addr, int nScore) { if (!addr.IsRoutable()) return false; if (!fDiscover && nScore < LOCAL_MANUAL) return false; if (IsLimited(addr)) return false; printf("AddLocal(%s,%i)\n", addr.ToString().c_str(), nScore); { LOCK(cs_mapLocalHost); bool fAlready = mapLocalHost.count(addr) > 0; LocalServiceInfo &info = mapLocalHost[addr]; if (!fAlready || nScore >= info.nScore) { info.nScore = nScore + (fAlready ? 1 : 0); info.nPort = addr.GetPort(); } SetReachable(addr.GetNetwork()); } AdvertizeLocal(); return true; } bool AddLocal(const CNetAddr &addr, int nScore) { return AddLocal(CService(addr, GetListenPort()), nScore); } /** Make a particular network entirely off-limits (no automatic connects to it) */ void SetLimited(enum Network net, bool fLimited) { if (net == NET_UNROUTABLE) return; LOCK(cs_mapLocalHost); vfLimited[net] = fLimited; } bool IsLimited(enum Network net) { LOCK(cs_mapLocalHost); return vfLimited[net]; } bool IsLimited(const CNetAddr &addr) { return IsLimited(addr.GetNetwork()); } /** vote for a local address */ bool SeenLocal(const CService& addr) { { LOCK(cs_mapLocalHost); if (mapLocalHost.count(addr) == 0) return false; mapLocalHost[addr].nScore++; } AdvertizeLocal(); return true; } /** check whether a given address is potentially local */ bool IsLocal(const CService& addr) { LOCK(cs_mapLocalHost); return mapLocalHost.count(addr) > 0; } /** check whether a given address is in a network we can probably connect to */ bool IsReachable(const CNetAddr& addr) { LOCK(cs_mapLocalHost); enum Network net = addr.GetNetwork(); return vfReachable[net] && !vfLimited[net]; } bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const char* pszKeyword, CNetAddr& ipRet) { SOCKET hSocket; if (!ConnectSocket(addrConnect, hSocket)) return error("GetMyExternalIP() : connection to %s failed", addrConnect.ToString().c_str()); send(hSocket, pszGet, strlen(pszGet), MSG_NOSIGNAL); string strLine; while (RecvLine(hSocket, strLine)) { if (strLine.empty()) // HTTP response is separated from headers by blank line { while (true) { if (!RecvLine(hSocket, strLine)) { closesocket(hSocket); return false; } if (pszKeyword == NULL) break; if (strLine.find(pszKeyword) != string::npos) { strLine = strLine.substr(strLine.find(pszKeyword) + strlen(pszKeyword)); break; } } closesocket(hSocket); if (strLine.find("<") != string::npos) strLine = strLine.substr(0, strLine.find("<")); strLine = strLine.substr(strspn(strLine.c_str(), " \t\n\r")); while (strLine.size() > 0 && isspace(strLine[strLine.size()-1])) strLine.resize(strLine.size()-1); CService addr(strLine,0,true); printf("GetMyExternalIP() received [%s] %s\n", strLine.c_str(), addr.ToString().c_str()); if (!addr.IsValid() || !addr.IsRoutable()) return false; ipRet.SetIP(addr); return true; } } closesocket(hSocket); return error("GetMyExternalIP() : connection closed"); } // We now get our external IP from the IRC server first and only use this as a backup bool GetMyExternalIP(CNetAddr& ipRet) { CService addrConnect; const char* pszGet; const char* pszKeyword; for (int nLookup = 0; nLookup <= 1; nLookup++) for (int nHost = 1; nHost <= 2; nHost++) { // We should be phasing out our use of sites like these. If we need // replacements, we should ask for volunteers to put this simple // php file on their web server that prints the client IP: // <?php echo $_SERVER["REMOTE_ADDR"]; ?> if (nHost == 1) { addrConnect = CService("91.198.22.70",80); // checkip.dyndns.org if (nLookup == 1) { CService addrIP("checkip.dyndns.org", 80, true); if (addrIP.IsValid()) addrConnect = addrIP; } pszGet = "GET / HTTP/1.1\r\n" "Host: checkip.dyndns.org\r\n" "User-Agent: dyor\r\n" "Connection: close\r\n" "\r\n"; pszKeyword = "Address:"; } else if (nHost == 2) { addrConnect = CService("74.208.43.192", 80); // www.showmyip.com if (nLookup == 1) { CService addrIP("www.showmyip.com", 80, true); if (addrIP.IsValid()) addrConnect = addrIP; } pszGet = "GET /simple/ HTTP/1.1\r\n" "Host: www.showmyip.com\r\n" "User-Agent: dyor\r\n" "Connection: close\r\n" "\r\n"; pszKeyword = NULL; // Returns just IP address } if (GetMyExternalIP2(addrConnect, pszGet, pszKeyword, ipRet)) return true; } return false; } void ThreadGetMyExternalIP(void* parg) { // Make this thread recognisable as the external IP detection thread RenameThread("dyor-ext-ip"); CNetAddr addrLocalHost; if (GetMyExternalIP(addrLocalHost)) { printf("GetMyExternalIP() returned %s\n", addrLocalHost.ToStringIP().c_str()); AddLocal(addrLocalHost, LOCAL_HTTP); } } void AddressCurrentlyConnected(const CService& addr) { addrman.Connected(addr); } uint64_t CNode::nTotalBytesRecv = 0; uint64_t CNode::nTotalBytesSent = 0; CCriticalSection CNode::cs_totalBytesRecv; CCriticalSection CNode::cs_totalBytesSent; CNode* FindNode(const CNetAddr& ip) { { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) if ((CNetAddr)pnode->addr == ip) return (pnode); } return NULL; } CNode* FindNode(std::string addrName) { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) if (pnode->addrName == addrName) return (pnode); return NULL; } CNode* FindNode(const CService& addr) { { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) if ((CService)pnode->addr == addr) return (pnode); } return NULL; } CNode* ConnectNode(CAddress addrConnect, const char *pszDest) { if (pszDest == NULL) { if (IsLocal(addrConnect)) return NULL; // Look for an existing connection CNode* pnode = FindNode((CService)addrConnect); if (pnode) { pnode->AddRef(); return pnode; } } /// debug print printf("trying connection %s lastseen=%.1fhrs\n", pszDest ? pszDest : addrConnect.ToString().c_str(), pszDest ? 0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0); // Connect SOCKET hSocket; if (pszDest ? ConnectSocketByName(addrConnect, hSocket, pszDest, GetDefaultPort()) : ConnectSocket(addrConnect, hSocket)) { addrman.Attempt(addrConnect); /// debug print printf("connected %s\n", pszDest ? pszDest : addrConnect.ToString().c_str()); // Set to non-blocking #ifdef WIN32 u_long nOne = 1; if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) printf("ConnectSocket() : ioctlsocket non-blocking setting failed, error %d\n", WSAGetLastError()); #else if (fcntl(hSocket, F_SETFL, O_NONBLOCK) == SOCKET_ERROR) printf("ConnectSocket() : fcntl non-blocking setting failed, error %d\n", errno); #endif // Add node CNode* pnode = new CNode(hSocket, addrConnect, pszDest ? pszDest : "", false); pnode->AddRef(); { LOCK(cs_vNodes); vNodes.push_back(pnode); } pnode->nTimeConnected = GetTime(); return pnode; } else { return NULL; } } void CNode::CloseSocketDisconnect() { fDisconnect = true; if (hSocket != INVALID_SOCKET) { printf("disconnecting node %s\n", addrName.c_str()); closesocket(hSocket); hSocket = INVALID_SOCKET; // in case this fails, we'll empty the recv buffer when the CNode is deleted TRY_LOCK(cs_vRecvMsg, lockRecv); if (lockRecv) vRecvMsg.clear(); } } void CNode::Cleanup() { } void CNode::PushVersion() { /// when NTP implemented, change to just nTime = GetAdjustedTime() int64_t nTime = (fInbound ? GetAdjustedTime() : GetTime()); CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService("0.0.0.0",0))); CAddress addrMe = GetLocalAddress(&addr); RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); printf("send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString().c_str(), addrYou.ToString().c_str(), addr.ToString().c_str()); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()), nBestHeight); } std::map<CNetAddr, int64_t> CNode::setBanned; CCriticalSection CNode::cs_setBanned; void CNode::ClearBanned() { setBanned.clear(); } bool CNode::IsBanned(CNetAddr ip) { bool fResult = false; { LOCK(cs_setBanned); std::map<CNetAddr, int64_t>::iterator i = setBanned.find(ip); if (i != setBanned.end()) { int64_t t = (*i).second; if (GetTime() < t) fResult = true; } } return fResult; } bool CNode::Misbehaving(int howmuch) { if (addr.IsLocal()) { printf("Warning: Local node %s misbehaving (delta: %d)!\n", addrName.c_str(), howmuch); return false; } nMisbehavior += howmuch; if (nMisbehavior >= GetArg("-banscore", 100)) { int64_t banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban printf("Misbehaving: %s (%d -> %d) DISCONNECTING\n", addr.ToString().c_str(), nMisbehavior-howmuch, nMisbehavior); { LOCK(cs_setBanned); if (setBanned[addr] < banTime) setBanned[addr] = banTime; } CloseSocketDisconnect(); return true; } else printf("Misbehaving: %s (%d -> %d)\n", addr.ToString().c_str(), nMisbehavior-howmuch, nMisbehavior); return false; } #undef X #define X(name) stats.name = name void CNode::copyStats(CNodeStats &stats) { X(nServices); X(nLastSend); X(nLastRecv); X(nSendBytes); X(nRecvBytes); X(nTimeConnected); X(addrName); X(nVersion); X(strSubVer); X(fInbound); X(nStartingHeight); X(nMisbehavior); // It is common for nodes with good ping times to suddenly become lagged, // due to a new block arriving or other large transfer. // Merely reporting pingtime might fool the caller into thinking the node was still responsive, // since pingtime does not update until the ping is complete, which might take a while. // So, if a ping is taking an unusually long time in flight, // the caller can immediately detect that this is happening. int64_t nPingUsecWait = 0; if ((0 != nPingNonceSent) && (0 != nPingUsecStart)) { nPingUsecWait = GetTimeMicros() - nPingUsecStart; } // Raw ping time is in microseconds, but show it to user as whole seconds (Bitcoin users should be well used to small numbers with many decimal places by now :) stats.dPingTime = (((double)nPingUsecTime) / 1e6); stats.dPingWait = (((double)nPingUsecWait) / 1e6); } #undef X void CNode::RecordBytesRecv(uint64_t bytes) { LOCK(cs_totalBytesRecv); nTotalBytesRecv += bytes; } void CNode::RecordBytesSent(uint64_t bytes) { LOCK(cs_totalBytesSent); nTotalBytesSent += bytes; } uint64_t CNode::GetTotalBytesRecv() { LOCK(cs_totalBytesRecv); return nTotalBytesRecv; } uint64_t CNode::GetTotalBytesSent() { LOCK(cs_totalBytesSent); return nTotalBytesSent; } // requires LOCK(cs_vRecvMsg) bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes) { while (nBytes > 0) { // get current incomplete message, or create a new one if (vRecvMsg.empty() || vRecvMsg.back().complete()) vRecvMsg.push_back(CNetMessage(SER_NETWORK, nRecvVersion)); CNetMessage& msg = vRecvMsg.back(); // absorb network data int handled; if (!msg.in_data) handled = msg.readHeader(pch, nBytes); else handled = msg.readData(pch, nBytes); if (handled < 0) return false; pch += handled; nBytes -= handled; if (msg.complete()) msg.nTime = GetTimeMicros(); } return true; } int CNetMessage::readHeader(const char *pch, unsigned int nBytes) { // copy data to temporary parsing buffer unsigned int nRemaining = 24 - nHdrPos; unsigned int nCopy = std::min(nRemaining, nBytes); memcpy(&hdrbuf[nHdrPos], pch, nCopy); nHdrPos += nCopy; // if header incomplete, exit if (nHdrPos < 24) return nCopy; // deserialize to CMessageHeader try { hdrbuf >> hdr; } catch (std::exception &e) { return -1; } // reject messages larger than MAX_SIZE if (hdr.nMessageSize > MAX_SIZE) return -1; // switch state to reading message data in_data = true; vRecv.resize(hdr.nMessageSize); return nCopy; } int CNetMessage::readData(const char *pch, unsigned int nBytes) { unsigned int nRemaining = hdr.nMessageSize - nDataPos; unsigned int nCopy = std::min(nRemaining, nBytes); memcpy(&vRecv[nDataPos], pch, nCopy); nDataPos += nCopy; return nCopy; } // requires LOCK(cs_vSend) void SocketSendData(CNode *pnode) { std::deque<CSerializeData>::iterator it = pnode->vSendMsg.begin(); while (it != pnode->vSendMsg.end()) { const CSerializeData &data = *it; assert(data.size() > pnode->nSendOffset); int nBytes = send(pnode->hSocket, &data[pnode->nSendOffset], data.size() - pnode->nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT); if (nBytes > 0) { pnode->nLastSend = GetTime(); pnode->nSendOffset += nBytes; pnode->nSendBytes += nBytes; pnode->RecordBytesSent(nBytes); if (pnode->nSendOffset == data.size()) { pnode->nSendOffset = 0; pnode->nSendSize -= data.size(); it++; } else { // could not send full message; stop sending more break; } } else { if (nBytes < 0) { // error int nErr = WSAGetLastError(); if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS) { printf("socket send error %d\n", nErr); pnode->CloseSocketDisconnect(); } } // couldn't send anything at all break; } } if (it == pnode->vSendMsg.end()) { assert(pnode->nSendOffset == 0); assert(pnode->nSendSize == 0); } pnode->vSendMsg.erase(pnode->vSendMsg.begin(), it); } void ThreadSocketHandler(void* parg) { // Make this thread recognisable as the networking thread RenameThread("dyor-net"); try { vnThreadsRunning[THREAD_SOCKETHANDLER]++; ThreadSocketHandler2(parg); vnThreadsRunning[THREAD_SOCKETHANDLER]--; } catch (std::exception& e) { vnThreadsRunning[THREAD_SOCKETHANDLER]--; PrintException(&e, "ThreadSocketHandler()"); } catch (...) { vnThreadsRunning[THREAD_SOCKETHANDLER]--; throw; // support pthread_cancel() } printf("ThreadSocketHandler exited\n"); } void ThreadSocketHandler2(void* parg) { printf("ThreadSocketHandler started\n"); list<CNode*> vNodesDisconnected; unsigned int nPrevNodeCount = 0; while (true) { // // Disconnect nodes // { LOCK(cs_vNodes); // Disconnect unused nodes vector<CNode*> vNodesCopy = vNodes; BOOST_FOREACH(CNode* pnode, vNodesCopy) { if (pnode->fDisconnect || (pnode->GetRefCount() <= 0 && pnode->vRecvMsg.empty() && pnode->nSendSize == 0 && pnode->ssSend.empty())) { // remove from vNodes vNodes.erase(remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end()); // release outbound grant (if any) pnode->grantOutbound.Release(); // close socket and cleanup pnode->CloseSocketDisconnect(); pnode->Cleanup(); // hold in disconnected pool until all refs are released if (pnode->fNetworkNode || pnode->fInbound) pnode->Release(); vNodesDisconnected.push_back(pnode); } } // Delete disconnected nodes list<CNode*> vNodesDisconnectedCopy = vNodesDisconnected; BOOST_FOREACH(CNode* pnode, vNodesDisconnectedCopy) { // wait until threads are done using it if (pnode->GetRefCount() <= 0) { bool fDelete = false; { TRY_LOCK(pnode->cs_vSend, lockSend); if (lockSend) { TRY_LOCK(pnode->cs_vRecvMsg, lockRecv); if (lockRecv) { TRY_LOCK(pnode->cs_mapRequests, lockReq); if (lockReq) { TRY_LOCK(pnode->cs_inventory, lockInv); if (lockInv) fDelete = true; } } } } if (fDelete) { vNodesDisconnected.remove(pnode); delete pnode; } } } } if (vNodes.size() != nPrevNodeCount) { nPrevNodeCount = vNodes.size(); uiInterface.NotifyNumConnectionsChanged(vNodes.size()); } // // Find which sockets have data to receive // struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 50000; // frequency to poll pnode->vSend fd_set fdsetRecv; fd_set fdsetSend; fd_set fdsetError; FD_ZERO(&fdsetRecv); FD_ZERO(&fdsetSend); FD_ZERO(&fdsetError); SOCKET hSocketMax = 0; bool have_fds = false; BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket) { FD_SET(hListenSocket, &fdsetRecv); hSocketMax = max(hSocketMax, hListenSocket); have_fds = true; } { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { if (pnode->hSocket == INVALID_SOCKET) continue; { TRY_LOCK(pnode->cs_vSend, lockSend); if (lockSend) { // do not read, if draining write queue if (!pnode->vSendMsg.empty()) FD_SET(pnode->hSocket, &fdsetSend); else FD_SET(pnode->hSocket, &fdsetRecv); FD_SET(pnode->hSocket, &fdsetError); hSocketMax = max(hSocketMax, pnode->hSocket); have_fds = true; } } } } vnThreadsRunning[THREAD_SOCKETHANDLER]--; int nSelect = select(have_fds ? hSocketMax + 1 : 0, &fdsetRecv, &fdsetSend, &fdsetError, &timeout); vnThreadsRunning[THREAD_SOCKETHANDLER]++; if (fShutdown) return; if (nSelect == SOCKET_ERROR) { if (have_fds) { int nErr = WSAGetLastError(); printf("socket select error %d\n", nErr); for (unsigned int i = 0; i <= hSocketMax; i++) FD_SET(i, &fdsetRecv); } FD_ZERO(&fdsetSend); FD_ZERO(&fdsetError); MilliSleep(timeout.tv_usec/1000); } // // Accept new connections // BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket) if (hListenSocket != INVALID_SOCKET && FD_ISSET(hListenSocket, &fdsetRecv)) { struct sockaddr_storage sockaddr; socklen_t len = sizeof(sockaddr); SOCKET hSocket = accept(hListenSocket, (struct sockaddr*)&sockaddr, &len); CAddress addr; int nInbound = 0; if (hSocket != INVALID_SOCKET) if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr)) printf("Warning: Unknown socket family\n"); { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) if (pnode->fInbound) nInbound++; } if (hSocket == INVALID_SOCKET) { int nErr = WSAGetLastError(); if (nErr != WSAEWOULDBLOCK) printf("socket error accept failed: %d\n", nErr); } else if (nInbound >= GetArg("-maxconnections", 125) - MAX_OUTBOUND_CONNECTIONS) { closesocket(hSocket); } else if (CNode::IsBanned(addr)) { printf("connection from %s dropped (banned)\n", addr.ToString().c_str()); closesocket(hSocket); } else { printf("accepted connection %s\n", addr.ToString().c_str()); CNode* pnode = new CNode(hSocket, addr, "", true); pnode->AddRef(); { LOCK(cs_vNodes); vNodes.push_back(pnode); } } } // // Service each socket // vector<CNode*> vNodesCopy; { LOCK(cs_vNodes); vNodesCopy = vNodes; BOOST_FOREACH(CNode* pnode, vNodesCopy) pnode->AddRef(); } BOOST_FOREACH(CNode* pnode, vNodesCopy) { if (fShutdown) return; // // Receive // if (pnode->hSocket == INVALID_SOCKET) continue; if (FD_ISSET(pnode->hSocket, &fdsetRecv) || FD_ISSET(pnode->hSocket, &fdsetError)) { TRY_LOCK(pnode->cs_vRecvMsg, lockRecv); if (lockRecv) { if (pnode->GetTotalRecvSize() > ReceiveFloodSize()) { if (!pnode->fDisconnect) printf("socket recv flood control disconnect (%u bytes)\n", pnode->GetTotalRecvSize()); pnode->CloseSocketDisconnect(); } else { // typical socket buffer is 8K-64K char pchBuf[0x10000]; int nBytes = recv(pnode->hSocket, pchBuf, sizeof(pchBuf), MSG_DONTWAIT); if (nBytes > 0) { if (!pnode->ReceiveMsgBytes(pchBuf, nBytes)) pnode->CloseSocketDisconnect(); pnode->nLastRecv = GetTime(); pnode->nRecvBytes += nBytes; pnode->RecordBytesRecv(nBytes); } else if (nBytes == 0) { // socket closed gracefully if (!pnode->fDisconnect) printf("socket closed\n"); pnode->CloseSocketDisconnect(); } else if (nBytes < 0) { // error int nErr = WSAGetLastError(); if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS) { if (!pnode->fDisconnect) printf("socket recv error %d\n", nErr); pnode->CloseSocketDisconnect(); } } } } } // // Send // if (pnode->hSocket == INVALID_SOCKET) continue; if (FD_ISSET(pnode->hSocket, &fdsetSend)) { TRY_LOCK(pnode->cs_vSend, lockSend); if (lockSend) SocketSendData(pnode); } // // Inactivity checking // int64_t nTime = GetTime(); if (nTime - pnode->nTimeConnected > 60) { if (pnode->nLastRecv == 0 || pnode->nLastSend == 0) { printf("socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0); pnode->fDisconnect = true; } else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL) { printf("socket sending timeout: %"PRId64"s\n", nTime - pnode->nLastSend); pnode->fDisconnect = true; } else if (nTime - pnode->nLastRecv > (pnode->nVersion > BIP0031_VERSION ? TIMEOUT_INTERVAL : 90*60)) { printf("socket receive timeout: %"PRId64"s\n", nTime - pnode->nLastRecv); pnode->fDisconnect = true; } else if (pnode->nPingNonceSent && pnode->nPingUsecStart + TIMEOUT_INTERVAL * 1000000 < GetTimeMicros()) { printf("ping timeout: %fs\n", 0.000001 * (GetTimeMicros() - pnode->nPingUsecStart)); pnode->fDisconnect = true; } } } { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodesCopy) pnode->Release(); } MilliSleep(10); } } #ifdef USE_UPNP void ThreadMapPort(void* parg) { // Make this thread recognisable as the UPnP thread RenameThread("dyor-UPnP"); try { vnThreadsRunning[THREAD_UPNP]++; ThreadMapPort2(parg); vnThreadsRunning[THREAD_UPNP]--; } catch (std::exception& e) { vnThreadsRunning[THREAD_UPNP]--; PrintException(&e, "ThreadMapPort()"); } catch (...) { vnThreadsRunning[THREAD_UPNP]--; PrintException(NULL, "ThreadMapPort()"); } printf("ThreadMapPort exited\n"); } void ThreadMapPort2(void* parg) { printf("ThreadMapPort started\n"); std::string port = strprintf("%u", GetListenPort()); const char * multicastif = 0; const char * minissdpdpath = 0; struct UPNPDev * devlist = 0; char lanaddr[64]; #ifndef UPNPDISCOVER_SUCCESS /* miniupnpc 1.5 */ devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0); #elif MINIUPNPC_API_VERSION < 14 /* miniupnpc 1.6 */ int error = 0; devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &error); #else /* miniupnpc > 1.6 */ int error = 0; devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, 2, &error); #endif struct UPNPUrls urls; struct IGDdatas data; int r; r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr)); if (r == 1) { if (fDiscover) { char externalIPAddress[40]; r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress); if(r != UPNPCOMMAND_SUCCESS) printf("UPnP: GetExternalIPAddress() returned %d\n", r); else { if(externalIPAddress[0]) { printf("UPnP: ExternalIPAddress = %s\n", externalIPAddress); AddLocal(CNetAddr(externalIPAddress), LOCAL_UPNP); } else printf("UPnP: GetExternalIPAddress failed.\n"); } } string strDesc = "dyor " + FormatFullVersion(); #ifndef UPNPDISCOVER_SUCCESS /* miniupnpc 1.5 */ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0); #else /* miniupnpc 1.6 */ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0"); #endif if(r!=UPNPCOMMAND_SUCCESS) printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", port.c_str(), port.c_str(), lanaddr, r, strupnperror(r)); else printf("UPnP Port Mapping successful.\n"); int i = 1; while (true) { if (fShutdown || !fUseUPnP) { r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0); printf("UPNP_DeletePortMapping() returned : %d\n", r); freeUPNPDevlist(devlist); devlist = 0; FreeUPNPUrls(&urls); return; } if (i % 600 == 0) // Refresh every 20 minutes { #ifndef UPNPDISCOVER_SUCCESS /* miniupnpc 1.5 */ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0); #else /* miniupnpc 1.6 */ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0"); #endif if(r!=UPNPCOMMAND_SUCCESS) printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", port.c_str(), port.c_str(), lanaddr, r, strupnperror(r)); else printf("UPnP Port Mapping successful.\n");; } MilliSleep(2000); i++; } } else { printf("No valid UPnP IGDs found\n"); freeUPNPDevlist(devlist); devlist = 0; if (r != 0) FreeUPNPUrls(&urls); while (true) { if (fShutdown || !fUseUPnP) return; MilliSleep(2000); } } } void MapPort() { if (fUseUPnP && vnThreadsRunning[THREAD_UPNP] < 1) { if (!NewThread(ThreadMapPort, NULL)) printf("Error: ThreadMapPort(ThreadMapPort) failed\n"); } } #else void MapPort() { // Intentionally left blank. } #endif // DNS seeds // Each pair gives a source name and a seed name. // The first name is used as information source for addrman. // The second name should resolve to a list of seed addresses. static const char *strDNSSeed[][2] = { {"pok.cash1", "seed1.dyor.trade"}, {"pok.cash2", "seed2.dyor.trade"}, {"pok.cash3", "seed3.dyor.trade"}, {"pok.cash4", "seed4.dyor.trade"}, }; void ThreadDNSAddressSeed(void* parg) { // Make this thread recognisable as the DNS seeding thread RenameThread("dyor-dnsseed"); try { vnThreadsRunning[THREAD_DNSSEED]++; ThreadDNSAddressSeed2(parg); vnThreadsRunning[THREAD_DNSSEED]--; } catch (std::exception& e) { vnThreadsRunning[THREAD_DNSSEED]--; PrintException(&e, "ThreadDNSAddressSeed()"); } catch (...) { vnThreadsRunning[THREAD_DNSSEED]--; throw; // support pthread_cancel() } printf("ThreadDNSAddressSeed exited\n"); } void ThreadDNSAddressSeed2(void* parg) { printf("ThreadDNSAddressSeed started\n"); int found = 0; if (!fTestNet) { printf("Loading addresses from DNS seeds (could take a while)\n"); for (unsigned int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) { if (HaveNameProxy()) { AddOneShot(strDNSSeed[seed_idx][1]); } else { vector<CNetAddr> vaddr; vector<CAddress> vAdd; if (LookupHost(strDNSSeed[seed_idx][1], vaddr)) { BOOST_FOREACH(CNetAddr& ip, vaddr) { int nOneDay = 24*3600; CAddress addr = CAddress(CService(ip, GetDefaultPort())); addr.nTime = GetTime() - 3*nOneDay - GetRand(4*nOneDay); // use a random age between 3 and 7 days old vAdd.push_back(addr); found++; } } addrman.Add(vAdd, CNetAddr(strDNSSeed[seed_idx][0], true)); } } } printf("%d addresses found from DNS seeds\n", found); } unsigned int pnSeed[] = { 0x252E8038, 0xBC78F4C6 }; void DumpAddresses() { int64_t nStart = GetTimeMillis(); CAddrDB adb; adb.Write(addrman); printf("Flushed %d addresses to peers.dat %"PRId64"ms\n", addrman.size(), GetTimeMillis() - nStart); } void ThreadDumpAddress2(void* parg) { vnThreadsRunning[THREAD_DUMPADDRESS]++; while (!fShutdown) { DumpAddresses(); vnThreadsRunning[THREAD_DUMPADDRESS]--; MilliSleep(600000); vnThreadsRunning[THREAD_DUMPADDRESS]++; } vnThreadsRunning[THREAD_DUMPADDRESS]--; } void ThreadDumpAddress(void* parg) { // Make this thread recognisable as the address dumping thread RenameThread("dyor-adrdump"); try { ThreadDumpAddress2(parg); } catch (std::exception& e) { PrintException(&e, "ThreadDumpAddress()"); } printf("ThreadDumpAddress exited\n"); } void ThreadOpenConnections(void* parg) { // Make this thread recognisable as the connection opening thread RenameThread("dyor-opencon"); try { vnThreadsRunning[THREAD_OPENCONNECTIONS]++; ThreadOpenConnections2(parg); vnThreadsRunning[THREAD_OPENCONNECTIONS]--; } catch (std::exception& e) { vnThreadsRunning[THREAD_OPENCONNECTIONS]--; PrintException(&e, "ThreadOpenConnections()"); } catch (...) { vnThreadsRunning[THREAD_OPENCONNECTIONS]--; PrintException(NULL, "ThreadOpenConnections()"); } printf("ThreadOpenConnections exited\n"); } void static ProcessOneShot() { string strDest; { LOCK(cs_vOneShots); if (vOneShots.empty()) return; strDest = vOneShots.front(); vOneShots.pop_front(); } CAddress addr; CSemaphoreGrant grant(*semOutbound, true); if (grant) { if (!OpenNetworkConnection(addr, &grant, strDest.c_str(), true)) AddOneShot(strDest); } } void static ThreadStakeMiner(void* parg) { printf("ThreadStakeMiner started\n"); CWallet* pwallet = (CWallet*)parg; try { vnThreadsRunning[THREAD_STAKE_MINER]++; StakeMiner(pwallet); vnThreadsRunning[THREAD_STAKE_MINER]--; } catch (std::exception& e) { vnThreadsRunning[THREAD_STAKE_MINER]--; PrintException(&e, "ThreadStakeMiner()"); } catch (...) { vnThreadsRunning[THREAD_STAKE_MINER]--; PrintException(NULL, "ThreadStakeMiner()"); } printf("ThreadStakeMiner exiting, %d threads remaining\n", vnThreadsRunning[THREAD_STAKE_MINER]); } void ThreadOpenConnections2(void* parg) { printf("ThreadOpenConnections started\n"); // Connect to specific addresses if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) { for (int64_t nLoop = 0;; nLoop++) { ProcessOneShot(); BOOST_FOREACH(string strAddr, mapMultiArgs["-connect"]) { CAddress addr; OpenNetworkConnection(addr, NULL, strAddr.c_str()); for (int i = 0; i < 10 && i < nLoop; i++) { MilliSleep(500); if (fShutdown) return; } } MilliSleep(500); } } // Initiate network connections int64_t nStart = GetTime(); while (true) { ProcessOneShot(); vnThreadsRunning[THREAD_OPENCONNECTIONS]--; MilliSleep(500); vnThreadsRunning[THREAD_OPENCONNECTIONS]++; if (fShutdown) return; vnThreadsRunning[THREAD_OPENCONNECTIONS]--; CSemaphoreGrant grant(*semOutbound); vnThreadsRunning[THREAD_OPENCONNECTIONS]++; if (fShutdown) return; // Add seed nodes if IRC isn't working if (addrman.size()==0 && (GetTime() - nStart > 60) && !fTestNet) { std::vector<CAddress> vAdd; for (unsigned int i = 0; i < ARRAYLEN(pnSeed); i++) { // It'll only connect to one or two seed nodes because once it connects, // it'll get a pile of addresses with newer timestamps. // Seed nodes are given a random 'last seen time' of between one and two // weeks ago. const int64_t nOneWeek = 7*24*60*60; struct in_addr ip; memcpy(&ip, &pnSeed[i], sizeof(ip)); CAddress addr(CService(ip, GetDefaultPort())); addr.nTime = GetTime()-GetRand(nOneWeek)-nOneWeek; vAdd.push_back(addr); } addrman.Add(vAdd, CNetAddr("127.0.0.1")); } // // Choose an address to connect to based on most recently seen // CAddress addrConnect; // Only connect out to one peer per network group (/16 for IPv4). // Do this here so we don't have to critsect vNodes inside mapAddresses critsect. int nOutbound = 0; set<vector<unsigned char> > setConnected; { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { if (!pnode->fInbound) { setConnected.insert(pnode->addr.GetGroup()); nOutbound++; } } } int64_t nANow = GetAdjustedTime(); int nTries = 0; while (true) { // use an nUnkBias between 10 (no outgoing connections) and 90 (8 outgoing connections) CAddress addr = addrman.Select(10 + min(nOutbound,8)*10); // if we selected an invalid address, restart if (!addr.IsValid() || setConnected.count(addr.GetGroup()) || IsLocal(addr)) break; // If we didn't find an appropriate destination after trying 100 addresses fetched from addrman, // stop this loop, and let the outer loop run again (which sleeps, adds seed nodes, recalculates // already-connected network ranges, ...) before trying new addrman addresses. nTries++; if (nTries > 100) break; if (IsLimited(addr)) continue; // only consider very recently tried nodes after 30 failed attempts if (nANow - addr.nLastTry < 600 && nTries < 30) continue; // do not allow non-default ports, unless after 50 invalid addresses selected already if (addr.GetPort() != GetDefaultPort() && nTries < 50) continue; addrConnect = addr; break; } if (addrConnect.IsValid()) OpenNetworkConnection(addrConnect, &grant); } } void ThreadOpenAddedConnections(void* parg) { // Make this thread recognisable as the connection opening thread RenameThread("dyor-opencon"); try { vnThreadsRunning[THREAD_ADDEDCONNECTIONS]++; ThreadOpenAddedConnections2(parg); vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--; } catch (std::exception& e) { vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--; PrintException(&e, "ThreadOpenAddedConnections()"); } catch (...) { vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--; PrintException(NULL, "ThreadOpenAddedConnections()"); } printf("ThreadOpenAddedConnections exited\n"); } void ThreadOpenAddedConnections2(void* parg) { printf("ThreadOpenAddedConnections started\n"); if (mapArgs.count("-addnode") == 0) return; if (HaveNameProxy()) { while(!fShutdown) { BOOST_FOREACH(string& strAddNode, mapMultiArgs["-addnode"]) { CAddress addr; CSemaphoreGrant grant(*semOutbound); OpenNetworkConnection(addr, &grant, strAddNode.c_str()); MilliSleep(500); } vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--; MilliSleep(120000); // Retry every 2 minutes vnThreadsRunning[THREAD_ADDEDCONNECTIONS]++; } return; } vector<vector<CService> > vservAddressesToAdd(0); BOOST_FOREACH(string& strAddNode, mapMultiArgs["-addnode"]) { vector<CService> vservNode(0); if(Lookup(strAddNode.c_str(), vservNode, GetDefaultPort(), fNameLookup, 0)) { vservAddressesToAdd.push_back(vservNode); { LOCK(cs_setservAddNodeAddresses); BOOST_FOREACH(CService& serv, vservNode) setservAddNodeAddresses.insert(serv); } } } while (true) { vector<vector<CService> > vservConnectAddresses = vservAddressesToAdd; // Attempt to connect to each IP for each addnode entry until at least one is successful per addnode entry // (keeping in mind that addnode entries can have many IPs if fNameLookup) { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) for (vector<vector<CService> >::iterator it = vservConnectAddresses.begin(); it != vservConnectAddresses.end(); it++) BOOST_FOREACH(CService& addrNode, *(it)) if (pnode->addr == addrNode) { it = vservConnectAddresses.erase(it); it--; break; } } BOOST_FOREACH(vector<CService>& vserv, vservConnectAddresses) { CSemaphoreGrant grant(*semOutbound); OpenNetworkConnection(CAddress(*(vserv.begin())), &grant); MilliSleep(500); if (fShutdown) return; } if (fShutdown) return; vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--; MilliSleep(120000); // Retry every 2 minutes vnThreadsRunning[THREAD_ADDEDCONNECTIONS]++; if (fShutdown) return; } } // if successful, this moves the passed grant to the constructed node bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound, const char *strDest, bool fOneShot) { // // Initiate outbound network connection // if (fShutdown) return false; if (!strDest) if (IsLocal(addrConnect) || FindNode((CNetAddr)addrConnect) || CNode::IsBanned(addrConnect) || FindNode(addrConnect.ToStringIPPort().c_str())) return false; if (strDest && FindNode(strDest)) return false; vnThreadsRunning[THREAD_OPENCONNECTIONS]--; CNode* pnode = ConnectNode(addrConnect, strDest); vnThreadsRunning[THREAD_OPENCONNECTIONS]++; if (fShutdown) return false; if (!pnode) return false; if (grantOutbound) grantOutbound->MoveTo(pnode->grantOutbound); pnode->fNetworkNode = true; if (fOneShot) pnode->fOneShot = true; return true; } void ThreadMessageHandler(void* parg) { // Make this thread recognisable as the message handling thread RenameThread("dyor-msghand"); try { vnThreadsRunning[THREAD_MESSAGEHANDLER]++; ThreadMessageHandler2(parg); vnThreadsRunning[THREAD_MESSAGEHANDLER]--; } catch (std::exception& e) { vnThreadsRunning[THREAD_MESSAGEHANDLER]--; PrintException(&e, "ThreadMessageHandler()"); } catch (...) { vnThreadsRunning[THREAD_MESSAGEHANDLER]--; PrintException(NULL, "ThreadMessageHandler()"); } printf("ThreadMessageHandler exited\n"); } void ThreadMessageHandler2(void* parg) { printf("ThreadMessageHandler started\n"); SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL); while (!fShutdown) { vector<CNode*> vNodesCopy; { LOCK(cs_vNodes); vNodesCopy = vNodes; BOOST_FOREACH(CNode* pnode, vNodesCopy) pnode->AddRef(); } // Poll the connected nodes for messages CNode* pnodeTrickle = NULL; if (!vNodesCopy.empty()) pnodeTrickle = vNodesCopy[GetRand(vNodesCopy.size())]; BOOST_FOREACH(CNode* pnode, vNodesCopy) { if (pnode->fDisconnect) continue; // Receive messages { TRY_LOCK(pnode->cs_vRecvMsg, lockRecv); if (lockRecv) if (!ProcessMessages(pnode)) pnode->CloseSocketDisconnect(); } if (fShutdown) return; // Send messages { TRY_LOCK(pnode->cs_vSend, lockSend); if (lockSend) SendMessages(pnode, pnode == pnodeTrickle); } if (fShutdown) return; } { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodesCopy) pnode->Release(); } // Wait and allow messages to bunch up. // Reduce vnThreadsRunning so StopNode has permission to exit while // we're sleeping, but we must always check fShutdown after doing this. vnThreadsRunning[THREAD_MESSAGEHANDLER]--; MilliSleep(100); if (fRequestShutdown) StartShutdown(); vnThreadsRunning[THREAD_MESSAGEHANDLER]++; if (fShutdown) return; } } bool BindListenPort(const CService &addrBind, string& strError) { strError = ""; int nOne = 1; #ifdef WIN32 // Initialize Windows Sockets WSADATA wsadata; int ret = WSAStartup(MAKEWORD(2,2), &wsadata); if (ret != NO_ERROR) { strError = strprintf("Error: TCP/IP socket library failed to start (WSAStartup returned error %d)", ret); printf("%s\n", strError.c_str()); return false; } #endif // Create socket for listening for incoming connections struct sockaddr_storage sockaddr; socklen_t len = sizeof(sockaddr); if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len)) { strError = strprintf("Error: bind address family for %s not supported", addrBind.ToString().c_str()); printf("%s\n", strError.c_str()); return false; } SOCKET hListenSocket = socket(((struct sockaddr*)&sockaddr)->sa_family, SOCK_STREAM, IPPROTO_TCP); if (hListenSocket == INVALID_SOCKET) { strError = strprintf("Error: Couldn't open socket for incoming connections (socket returned error %d)", WSAGetLastError()); printf("%s\n", strError.c_str()); return false; } #ifdef SO_NOSIGPIPE // Different way of disabling SIGPIPE on BSD setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int)); #endif #ifndef WIN32 // Allow binding if the port is still in TIME_WAIT state after // the program was closed and restarted. Not an issue on windows. setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int)); #endif #ifdef WIN32 // Set to non-blocking, incoming connections will also inherit this if (ioctlsocket(hListenSocket, FIONBIO, (u_long*)&nOne) == SOCKET_ERROR) #else if (fcntl(hListenSocket, F_SETFL, O_NONBLOCK) == SOCKET_ERROR) #endif { strError = strprintf("Error: Couldn't set properties on socket for incoming connections (error %d)", WSAGetLastError()); printf("%s\n", strError.c_str()); return false; } // some systems don't have IPV6_V6ONLY but are always v6only; others do have the option // and enable it by default or not. Try to enable it, if possible. if (addrBind.IsIPv6()) { #ifdef IPV6_V6ONLY #ifdef WIN32 setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&nOne, sizeof(int)); #else setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&nOne, sizeof(int)); #endif #endif #ifdef WIN32 int nProtLevel = 10 /* PROTECTION_LEVEL_UNRESTRICTED */; int nParameterId = 23 /* IPV6_PROTECTION_LEVEl */; // this call is allowed to fail setsockopt(hListenSocket, IPPROTO_IPV6, nParameterId, (const char*)&nProtLevel, sizeof(int)); #endif } if (::bind(hListenSocket, (struct sockaddr*)&sockaddr, len) == SOCKET_ERROR) { int nErr = WSAGetLastError(); if (nErr == WSAEADDRINUSE) strError = strprintf(_("Unable to bind to %s on this computer. dyor is probably already running."), addrBind.ToString().c_str()); else strError = strprintf(_("Unable to bind to %s on this computer (bind returned error %d, %s)"), addrBind.ToString().c_str(), nErr, strerror(nErr)); printf("%s\n", strError.c_str()); return false; } printf("Bound to %s\n", addrBind.ToString().c_str()); // Listen for incoming connections if (listen(hListenSocket, SOMAXCONN) == SOCKET_ERROR) { strError = strprintf("Error: Listening for incoming connections failed (listen returned error %d)", WSAGetLastError()); printf("%s\n", strError.c_str()); return false; } vhListenSocket.push_back(hListenSocket); if (addrBind.IsRoutable() && fDiscover) AddLocal(addrBind, LOCAL_BIND); return true; } void static Discover() { if (!fDiscover) return; #ifdef WIN32 // Get local host IP char pszHostName[1000] = ""; if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR) { vector<CNetAddr> vaddr; if (LookupHost(pszHostName, vaddr)) { BOOST_FOREACH (const CNetAddr &addr, vaddr) { AddLocal(addr, LOCAL_IF); } } } #else // Get local host ip struct ifaddrs* myaddrs; if (getifaddrs(&myaddrs) == 0) { for (struct ifaddrs* ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL) continue; if ((ifa->ifa_flags & IFF_UP) == 0) continue; if (strcmp(ifa->ifa_name, "lo") == 0) continue; if (strcmp(ifa->ifa_name, "lo0") == 0) continue; if (ifa->ifa_addr->sa_family == AF_INET) { struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr); CNetAddr addr(s4->sin_addr); if (AddLocal(addr, LOCAL_IF)) printf("IPv4 %s: %s\n", ifa->ifa_name, addr.ToString().c_str()); } else if (ifa->ifa_addr->sa_family == AF_INET6) { struct sockaddr_in6* s6 = (struct sockaddr_in6*)(ifa->ifa_addr); CNetAddr addr(s6->sin6_addr); if (AddLocal(addr, LOCAL_IF)) printf("IPv6 %s: %s\n", ifa->ifa_name, addr.ToString().c_str()); } } freeifaddrs(myaddrs); } #endif // Don't use external IPv4 discovery, when -onlynet="IPv6" if (!IsLimited(NET_IPV4)) NewThread(ThreadGetMyExternalIP, NULL); } void StartNode(void* parg) { // Make this thread recognisable as the startup thread RenameThread("dyor-start"); if (semOutbound == NULL) { // initialize semaphore int nMaxOutbound = min(MAX_OUTBOUND_CONNECTIONS, (int)GetArg("-maxconnections", 125)); semOutbound = new CSemaphore(nMaxOutbound); } if (pnodeLocalHost == NULL) pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress(CService("127.0.0.1", 0), nLocalServices)); Discover(); // // Start threads // if (!GetBoolArg("-dnsseed", true)) printf("DNS seeding disabled\n"); else if (!NewThread(ThreadDNSAddressSeed, NULL)) printf("Error: NewThread(ThreadDNSAddressSeed) failed\n"); // Map ports with UPnP if (fUseUPnP) MapPort(); // Get addresses from IRC and advertise ours if (!NewThread(ThreadIRCSeed, NULL)) printf("Error: NewThread(ThreadIRCSeed) failed\n"); // Send and receive from sockets, accept connections if (!NewThread(ThreadSocketHandler, NULL)) printf("Error: NewThread(ThreadSocketHandler) failed\n"); // Initiate outbound connections from -addnode if (!NewThread(ThreadOpenAddedConnections, NULL)) printf("Error: NewThread(ThreadOpenAddedConnections) failed\n"); // Initiate outbound connections if (!NewThread(ThreadOpenConnections, NULL)) printf("Error: NewThread(ThreadOpenConnections) failed\n"); // Process messages if (!NewThread(ThreadMessageHandler, NULL)) printf("Error: NewThread(ThreadMessageHandler) failed\n"); // Dump network addresses if (!NewThread(ThreadDumpAddress, NULL)) printf("Error; NewThread(ThreadDumpAddress) failed\n"); // Mine proof-of-stake blocks in the background if (!GetBoolArg("-staking", true)) printf("Staking disabled\n"); else if (!NewThread(ThreadStakeMiner, pwalletMain)) printf("Error: NewThread(ThreadStakeMiner) failed\n"); } bool StopNode() { printf("StopNode()\n"); fShutdown = true; nTransactionsUpdated++; int64_t nStart = GetTime(); if (semOutbound) for (int i=0; i<MAX_OUTBOUND_CONNECTIONS; i++) semOutbound->post(); do { int nThreadsRunning = 0; for (int n = 0; n < THREAD_MAX; n++) nThreadsRunning += vnThreadsRunning[n]; if (nThreadsRunning == 0) break; if (GetTime() - nStart > 20) break; MilliSleep(20); } while(true); if (vnThreadsRunning[THREAD_SOCKETHANDLER] > 0) printf("ThreadSocketHandler still running\n"); if (vnThreadsRunning[THREAD_OPENCONNECTIONS] > 0) printf("ThreadOpenConnections still running\n"); if (vnThreadsRunning[THREAD_MESSAGEHANDLER] > 0) printf("ThreadMessageHandler still running\n"); if (vnThreadsRunning[THREAD_RPCLISTENER] > 0) printf("ThreadRPCListener still running\n"); if (vnThreadsRunning[THREAD_RPCHANDLER] > 0) printf("ThreadsRPCServer still running\n"); #ifdef USE_UPNP if (vnThreadsRunning[THREAD_UPNP] > 0) printf("ThreadMapPort still running\n"); #endif if (vnThreadsRunning[THREAD_DNSSEED] > 0) printf("ThreadDNSAddressSeed still running\n"); if (vnThreadsRunning[THREAD_ADDEDCONNECTIONS] > 0) printf("ThreadOpenAddedConnections still running\n"); if (vnThreadsRunning[THREAD_DUMPADDRESS] > 0) printf("ThreadDumpAddresses still running\n"); if (vnThreadsRunning[THREAD_STAKE_MINER] > 0) printf("ThreadStakeMiner still running\n"); while (vnThreadsRunning[THREAD_MESSAGEHANDLER] > 0 || vnThreadsRunning[THREAD_RPCHANDLER] > 0) MilliSleep(20); MilliSleep(50); DumpAddresses(); return true; } class CNetCleanup { public: CNetCleanup() { } ~CNetCleanup() { // Close sockets BOOST_FOREACH(CNode* pnode, vNodes) if (pnode->hSocket != INVALID_SOCKET) closesocket(pnode->hSocket); BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket) if (hListenSocket != INVALID_SOCKET) if (closesocket(hListenSocket) == SOCKET_ERROR) printf("closesocket(hListenSocket) failed with error %d\n", WSAGetLastError()); #ifdef WIN32 // Shutdown Windows Sockets WSACleanup(); #endif } } instance_of_cnetcleanup; void RelayTransaction(const CTransaction& tx, const uint256& hash) { CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss.reserve(10000); ss << tx; RelayTransaction(tx, hash, ss); } void RelayTransaction(const CTransaction& tx, const uint256& hash, const CDataStream& ss) { CInv inv(MSG_TX, hash); { LOCK(cs_mapRelay); // Expire old relay messages while (!vRelayExpiration.empty() && vRelayExpiration.front().first < GetTime()) { mapRelay.erase(vRelayExpiration.front().second); vRelayExpiration.pop_front(); } // Save original serialized message so newer versions are preserved mapRelay.insert(std::make_pair(inv, ss)); vRelayExpiration.push_back(std::make_pair(GetTime() + 15 * 60, inv)); } RelayInventory(inv); }
; A122249: Numerators of Hankel transform of 1/(2n+1). ; Submitted by Christian Krause ; 1,4,256,65536,1073741824,70368744177664,73786976294838206464,309485009821345068724781056,332306998946228968225951765070086144,1427247692705959881058285969449495136382746624 seq $0,77071 ; Row sums of A077070. mov $1,2 pow $1,$0 mov $0,$1