text
stringlengths
1
1.05M
; A158395: 729n - 1. ; 728,1457,2186,2915,3644,4373,5102,5831,6560,7289,8018,8747,9476,10205,10934,11663,12392,13121,13850,14579,15308,16037,16766,17495,18224,18953,19682,20411,21140,21869,22598,23327,24056,24785,25514,26243,26972,27701,28430,29159,29888,30617,31346,32075,32804,33533,34262,34991,35720,36449,37178,37907,38636,39365,40094,40823,41552,42281,43010,43739,44468,45197,45926,46655,47384,48113,48842,49571,50300,51029,51758,52487,53216,53945,54674,55403,56132,56861,57590,58319,59048,59777,60506,61235,61964 mul $0,729 add $0,728
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Copyright(c) 2011-2020 Intel Corporation All rights reserved. ; ; Redistribution and use in source and binary forms, with or without ; modification, are permitted provided that the following conditions ; are met: ; * Redistributions of source code must retain the above copyright ; notice, this list of conditions and the following disclaimer. ; * Redistributions in binary form must reproduce the above copyright ; notice, this list of conditions and the following disclaimer in ; the documentation and/or other materials provided with the ; distribution. ; * Neither the name of Intel Corporation nor the names of its ; contributors may be used to endorse or promote products derived ; from this software without specific prior written permission. ; ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Function API: ; UINT32 crc32_gzip_refl_by16_10( ; UINT32 init_crc, //initial CRC value, 32 bits ; const unsigned char *buf, //buffer pointer to calculate CRC on ; UINT64 len //buffer length in bytes (64-bit data) ; ); ; ; Authors: ; Erdinc Ozturk ; Vinodh Gopal ; James Guilford ; ; Reference paper titled "Fast CRC Computation for Generic Polynomials Using PCLMULQDQ Instruction" ; URL: http://download.intel.com/design/intarch/papers/323102.pdf ; ; ; sample yasm command line: ; yasm -f x64 -f elf64 -X gnu -g dwarf2 crc32_gzip_refl_by8 ; ; As explained here: ; http://docs.oracle.com/javase/7/docs/api/java/util/zip/package-summary.html ; CRC-32 checksum is described in RFC 1952 ; Implementing RFC 1952 CRC: ; http://www.ietf.org/rfc/rfc1952.txt %include "reg_sizes.asm" %ifndef FUNCTION_NAME %define FUNCTION_NAME crc32_gzip_refl_by16_10 %endif %if (AS_FEATURE_LEVEL) >= 10 %define fetch_dist 1024 [bits 64] default rel section .text %ifidn __OUTPUT_FORMAT__, win64 %xdefine arg1 rcx %xdefine arg2 rdx %xdefine arg3 r8 %xdefine arg1_low32 ecx %else %xdefine arg1 rdi %xdefine arg2 rsi %xdefine arg3 rdx %xdefine arg1_low32 edi %endif %define TMP 16*0 %ifidn __OUTPUT_FORMAT__, win64 %define XMM_SAVE 16*2 %define VARIABLE_OFFSET 16*12+8 %else %define VARIABLE_OFFSET 16*2+8 %endif align 16 mk_global FUNCTION_NAME, function FUNCTION_NAME: endbranch not arg1_low32 sub rsp, VARIABLE_OFFSET %ifidn __OUTPUT_FORMAT__, win64 ; push the xmm registers into the stack to maintain vmovdqa [rsp + XMM_SAVE + 16*0], xmm6 vmovdqa [rsp + XMM_SAVE + 16*1], xmm7 vmovdqa [rsp + XMM_SAVE + 16*2], xmm8 vmovdqa [rsp + XMM_SAVE + 16*3], xmm9 vmovdqa [rsp + XMM_SAVE + 16*4], xmm10 vmovdqa [rsp + XMM_SAVE + 16*5], xmm11 vmovdqa [rsp + XMM_SAVE + 16*6], xmm12 vmovdqa [rsp + XMM_SAVE + 16*7], xmm13 vmovdqa [rsp + XMM_SAVE + 16*8], xmm14 vmovdqa [rsp + XMM_SAVE + 16*9], xmm15 %endif ; check if smaller than 256B cmp arg3, 256 jl .less_than_256 ; load the initial crc value vmovd xmm10, arg1_low32 ; initial crc ; receive the initial 64B data, xor the initial crc value vmovdqu8 zmm0, [arg2+16*0] vmovdqu8 zmm4, [arg2+16*4] vpxorq zmm0, zmm10 vbroadcasti32x4 zmm10, [rk3] ;xmm10 has rk3 and rk4 ;imm value of pclmulqdq instruction will determine which constant to use sub arg3, 256 cmp arg3, 256 jl .fold_128_B_loop vmovdqu8 zmm7, [arg2+16*8] vmovdqu8 zmm8, [arg2+16*12] vbroadcasti32x4 zmm16, [rk_1] ;zmm16 has rk-1 and rk-2 sub arg3, 256 .fold_256_B_loop: add arg2, 256 vmovdqu8 zmm3, [arg2+16*0] vpclmulqdq zmm1, zmm0, zmm16, 0x10 vpclmulqdq zmm2, zmm0, zmm16, 0x01 vpxorq zmm0, zmm1, zmm2 vpxorq zmm0, zmm0, zmm3 vmovdqu8 zmm9, [arg2+16*4] vpclmulqdq zmm5, zmm4, zmm16, 0x10 vpclmulqdq zmm6, zmm4, zmm16, 0x01 vpxorq zmm4, zmm5, zmm6 vpxorq zmm4, zmm4, zmm9 vmovdqu8 zmm11, [arg2+16*8] vpclmulqdq zmm12, zmm7, zmm16, 0x10 vpclmulqdq zmm13, zmm7, zmm16, 0x01 vpxorq zmm7, zmm12, zmm13 vpxorq zmm7, zmm7, zmm11 vmovdqu8 zmm17, [arg2+16*12] vpclmulqdq zmm14, zmm8, zmm16, 0x10 vpclmulqdq zmm15, zmm8, zmm16, 0x01 vpxorq zmm8, zmm14, zmm15 vpxorq zmm8, zmm8, zmm17 sub arg3, 256 jge .fold_256_B_loop ;; Fold 256 into 128 add arg2, 256 vpclmulqdq zmm1, zmm0, zmm10, 0x01 vpclmulqdq zmm2, zmm0, zmm10, 0x10 vpternlogq zmm7, zmm1, zmm2, 0x96 ; xor ABC vpclmulqdq zmm5, zmm4, zmm10, 0x01 vpclmulqdq zmm6, zmm4, zmm10, 0x10 vpternlogq zmm8, zmm5, zmm6, 0x96 ; xor ABC vmovdqa32 zmm0, zmm7 vmovdqa32 zmm4, zmm8 add arg3, 128 jmp .fold_128_B_register ; at this section of the code, there is 128*x+y (0<=y<128) bytes of buffer. The fold_128_B_loop ; loop will fold 128B at a time until we have 128+y Bytes of buffer ; fold 128B at a time. This section of the code folds 8 xmm registers in parallel .fold_128_B_loop: add arg2, 128 vmovdqu8 zmm8, [arg2+16*0] vpclmulqdq zmm2, zmm0, zmm10, 0x10 vpclmulqdq zmm1, zmm0, zmm10, 0x01 vpxorq zmm0, zmm2, zmm1 vpxorq zmm0, zmm0, zmm8 vmovdqu8 zmm9, [arg2+16*4] vpclmulqdq zmm5, zmm4, zmm10, 0x10 vpclmulqdq zmm6, zmm4, zmm10, 0x01 vpxorq zmm4, zmm5, zmm6 vpxorq zmm4, zmm4, zmm9 sub arg3, 128 jge .fold_128_B_loop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; add arg2, 128 ; at this point, the buffer pointer is pointing at the last y Bytes of the buffer, where 0 <= y < 128 ; the 128B of folded data is in 8 of the xmm registers: xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7 .fold_128_B_register: ; fold the 8 128b parts into 1 xmm register with different constants vmovdqu8 zmm16, [rk9] ; multiply by rk9-rk16 vmovdqu8 zmm11, [rk17] ; multiply by rk17-rk20, rk1,rk2, 0,0 vpclmulqdq zmm1, zmm0, zmm16, 0x01 vpclmulqdq zmm2, zmm0, zmm16, 0x10 vextracti64x2 xmm7, zmm4, 3 ; save last that has no multiplicand vpclmulqdq zmm5, zmm4, zmm11, 0x01 vpclmulqdq zmm6, zmm4, zmm11, 0x10 vmovdqa xmm10, [rk1] ; Needed later in reduction loop vpternlogq zmm1, zmm2, zmm5, 0x96 ; xor ABC vpternlogq zmm1, zmm6, zmm7, 0x96 ; xor ABC vshufi64x2 zmm8, zmm1, zmm1, 0x4e ; Swap 1,0,3,2 - 01 00 11 10 vpxorq ymm8, ymm8, ymm1 vextracti64x2 xmm5, ymm8, 1 vpxorq xmm7, xmm5, xmm8 ; instead of 128, we add 128-16 to the loop counter to save 1 instruction from the loop ; instead of a cmp instruction, we use the negative flag with the jl instruction add arg3, 128-16 jl .final_reduction_for_128 ; now we have 16+y bytes left to reduce. 16 Bytes is in register xmm7 and the rest is in memory ; we can fold 16 bytes at a time if y>=16 ; continue folding 16B at a time .16B_reduction_loop: vpclmulqdq xmm8, xmm7, xmm10, 0x1 vpclmulqdq xmm7, xmm7, xmm10, 0x10 vpxor xmm7, xmm8 vmovdqu xmm0, [arg2] vpxor xmm7, xmm0 add arg2, 16 sub arg3, 16 ; instead of a cmp instruction, we utilize the flags with the jge instruction ; equivalent of: cmp arg3, 16-16 ; check if there is any more 16B in the buffer to be able to fold jge .16B_reduction_loop ;now we have 16+z bytes left to reduce, where 0<= z < 16. ;first, we reduce the data in the xmm7 register .final_reduction_for_128: add arg3, 16 je .128_done ; here we are getting data that is less than 16 bytes. ; since we know that there was data before the pointer, we can offset ; the input pointer before the actual point, to receive exactly 16 bytes. ; after that the registers need to be adjusted. .get_last_two_xmms: vmovdqa xmm2, xmm7 vmovdqu xmm1, [arg2 - 16 + arg3] ; get rid of the extra data that was loaded before ; load the shift constant lea rax, [pshufb_shf_table] add rax, arg3 vmovdqu xmm0, [rax] vpshufb xmm7, xmm0 vpxor xmm0, [mask3] vpshufb xmm2, xmm0 vpblendvb xmm2, xmm2, xmm1, xmm0 ;;;;;;;;;; vpclmulqdq xmm8, xmm7, xmm10, 0x1 vpclmulqdq xmm7, xmm7, xmm10, 0x10 vpxor xmm7, xmm8 vpxor xmm7, xmm2 .128_done: ; compute crc of a 128-bit value vmovdqa xmm10, [rk5] vmovdqa xmm0, xmm7 ;64b fold vpclmulqdq xmm7, xmm10, 0 vpsrldq xmm0, 8 vpxor xmm7, xmm0 ;32b fold vmovdqa xmm0, xmm7 vpslldq xmm7, 4 vpclmulqdq xmm7, xmm10, 0x10 vpxor xmm7, xmm0 ;barrett reduction .barrett: vpand xmm7, [mask2] vmovdqa xmm1, xmm7 vmovdqa xmm2, xmm7 vmovdqa xmm10, [rk7] vpclmulqdq xmm7, xmm10, 0 vpxor xmm7, xmm2 vpand xmm7, [mask] vmovdqa xmm2, xmm7 vpclmulqdq xmm7, xmm10, 0x10 vpxor xmm7, xmm2 vpxor xmm7, xmm1 vpextrd eax, xmm7, 2 .cleanup: not eax %ifidn __OUTPUT_FORMAT__, win64 vmovdqa xmm6, [rsp + XMM_SAVE + 16*0] vmovdqa xmm7, [rsp + XMM_SAVE + 16*1] vmovdqa xmm8, [rsp + XMM_SAVE + 16*2] vmovdqa xmm9, [rsp + XMM_SAVE + 16*3] vmovdqa xmm10, [rsp + XMM_SAVE + 16*4] vmovdqa xmm11, [rsp + XMM_SAVE + 16*5] vmovdqa xmm12, [rsp + XMM_SAVE + 16*6] vmovdqa xmm13, [rsp + XMM_SAVE + 16*7] vmovdqa xmm14, [rsp + XMM_SAVE + 16*8] vmovdqa xmm15, [rsp + XMM_SAVE + 16*9] %endif add rsp, VARIABLE_OFFSET ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; align 16 .less_than_256: ; check if there is enough buffer to be able to fold 16B at a time cmp arg3, 32 jl .less_than_32 ; if there is, load the constants vmovdqa xmm10, [rk1] ; rk1 and rk2 in xmm10 vmovd xmm0, arg1_low32 ; get the initial crc value vmovdqu xmm7, [arg2] ; load the plaintext vpxor xmm7, xmm0 ; update the buffer pointer add arg2, 16 ; update the counter. subtract 32 instead of 16 to save one instruction from the loop sub arg3, 32 jmp .16B_reduction_loop align 16 .less_than_32: ; mov initial crc to the return value. this is necessary for zero-length buffers. mov eax, arg1_low32 test arg3, arg3 je .cleanup vmovd xmm0, arg1_low32 ; get the initial crc value cmp arg3, 16 je .exact_16_left jl .less_than_16_left vmovdqu xmm7, [arg2] ; load the plaintext vpxor xmm7, xmm0 ; xor the initial crc value add arg2, 16 sub arg3, 16 vmovdqa xmm10, [rk1] ; rk1 and rk2 in xmm10 jmp .get_last_two_xmms align 16 .less_than_16_left: ; use stack space to load data less than 16 bytes, zero-out the 16B in memory first. vpxor xmm1, xmm1 mov r11, rsp vmovdqa [r11], xmm1 cmp arg3, 4 jl .only_less_than_4 ; backup the counter value mov r9, arg3 cmp arg3, 8 jl .less_than_8_left ; load 8 Bytes mov rax, [arg2] mov [r11], rax add r11, 8 sub arg3, 8 add arg2, 8 .less_than_8_left: cmp arg3, 4 jl .less_than_4_left ; load 4 Bytes mov eax, [arg2] mov [r11], eax add r11, 4 sub arg3, 4 add arg2, 4 .less_than_4_left: cmp arg3, 2 jl .less_than_2_left ; load 2 Bytes mov ax, [arg2] mov [r11], ax add r11, 2 sub arg3, 2 add arg2, 2 .less_than_2_left: cmp arg3, 1 jl .zero_left ; load 1 Byte mov al, [arg2] mov [r11], al .zero_left: vmovdqa xmm7, [rsp] vpxor xmm7, xmm0 ; xor the initial crc value lea rax,[pshufb_shf_table] vmovdqu xmm0, [rax + r9] vpshufb xmm7,xmm0 jmp .128_done align 16 .exact_16_left: vmovdqu xmm7, [arg2] vpxor xmm7, xmm0 ; xor the initial crc value jmp .128_done .only_less_than_4: cmp arg3, 3 jl .only_less_than_3 ; load 3 Bytes mov al, [arg2] mov [r11], al mov al, [arg2+1] mov [r11+1], al mov al, [arg2+2] mov [r11+2], al vmovdqa xmm7, [rsp] vpxor xmm7, xmm0 ; xor the initial crc value vpslldq xmm7, 5 jmp .barrett .only_less_than_3: cmp arg3, 2 jl .only_less_than_2 ; load 2 Bytes mov al, [arg2] mov [r11], al mov al, [arg2+1] mov [r11+1], al vmovdqa xmm7, [rsp] vpxor xmm7, xmm0 ; xor the initial crc value vpslldq xmm7, 6 jmp .barrett .only_less_than_2: ; load 1 Byte mov al, [arg2] mov [r11], al vmovdqa xmm7, [rsp] vpxor xmm7, xmm0 ; xor the initial crc value vpslldq xmm7, 7 jmp .barrett section .data align 32 %ifndef USE_CONSTS ; precomputed constants rk_1: dq 0x00000000e95c1271 rk_2: dq 0x00000000ce3371cb rk1: dq 0x00000000ccaa009e rk2: dq 0x00000001751997d0 rk3: dq 0x000000014a7fe880 rk4: dq 0x00000001e88ef372 rk5: dq 0x00000000ccaa009e rk6: dq 0x0000000163cd6124 rk7: dq 0x00000001f7011640 rk8: dq 0x00000001db710640 rk9: dq 0x00000001d7cfc6ac rk10: dq 0x00000001ea89367e rk11: dq 0x000000018cb44e58 rk12: dq 0x00000000df068dc2 rk13: dq 0x00000000ae0b5394 rk14: dq 0x00000001c7569e54 rk15: dq 0x00000001c6e41596 rk16: dq 0x0000000154442bd4 rk17: dq 0x0000000174359406 rk18: dq 0x000000003db1ecdc rk19: dq 0x000000015a546366 rk20: dq 0x00000000f1da05aa rk_1b: dq 0x00000000ccaa009e rk_2b: dq 0x00000001751997d0 dq 0x0000000000000000 dq 0x0000000000000000 %else INCLUDE_CONSTS %endif pshufb_shf_table: ; use these values for shift constants for the pshufb instruction ; different alignments result in values as shown: ; dq 0x8887868584838281, 0x008f8e8d8c8b8a89 ; shl 15 (16-1) / shr1 ; dq 0x8988878685848382, 0x01008f8e8d8c8b8a ; shl 14 (16-3) / shr2 ; dq 0x8a89888786858483, 0x0201008f8e8d8c8b ; shl 13 (16-4) / shr3 ; dq 0x8b8a898887868584, 0x030201008f8e8d8c ; shl 12 (16-4) / shr4 ; dq 0x8c8b8a8988878685, 0x04030201008f8e8d ; shl 11 (16-5) / shr5 ; dq 0x8d8c8b8a89888786, 0x0504030201008f8e ; shl 10 (16-6) / shr6 ; dq 0x8e8d8c8b8a898887, 0x060504030201008f ; shl 9 (16-7) / shr7 ; dq 0x8f8e8d8c8b8a8988, 0x0706050403020100 ; shl 8 (16-8) / shr8 ; dq 0x008f8e8d8c8b8a89, 0x0807060504030201 ; shl 7 (16-9) / shr9 ; dq 0x01008f8e8d8c8b8a, 0x0908070605040302 ; shl 6 (16-10) / shr10 ; dq 0x0201008f8e8d8c8b, 0x0a09080706050403 ; shl 5 (16-11) / shr11 ; dq 0x030201008f8e8d8c, 0x0b0a090807060504 ; shl 4 (16-12) / shr12 ; dq 0x04030201008f8e8d, 0x0c0b0a0908070605 ; shl 3 (16-13) / shr13 ; dq 0x0504030201008f8e, 0x0d0c0b0a09080706 ; shl 2 (16-14) / shr14 ; dq 0x060504030201008f, 0x0e0d0c0b0a090807 ; shl 1 (16-15) / shr15 dq 0x8786858483828100, 0x8f8e8d8c8b8a8988 dq 0x0706050403020100, 0x000e0d0c0b0a0908 mask: dq 0xFFFFFFFFFFFFFFFF, 0x0000000000000000 mask2: dq 0xFFFFFFFF00000000, 0xFFFFFFFFFFFFFFFF mask3: dq 0x8080808080808080, 0x8080808080808080 %else ; Assembler doesn't understand these opcodes. Add empty symbol for windows. %ifidn __OUTPUT_FORMAT__, win64 global no_ %+ FUNCTION_NAME no_ %+ FUNCTION_NAME %+ : %endif %endif ; (AS_FEATURE_LEVEL) >= 10
; A143984: a(0) = 0; thereafter, a(n+1) = (a(n) - 2)^2 - n. ; 0,3,-1,6,12,95,8643,74666874,5575141774264376,31082205803147712138788845611867,966103517589229313003894215813508352493573272034098666228778215 lpb $0 sub $0,1 sub $2,2 pow $2,2 sub $3,1 add $2,$3 lpe mov $0,$2
//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // This test fails on Windows because the underlying libc headers on Windows // are not modular // XFAIL: LIBCXX-WINDOWS-FIXME // Some headers are not available when these features are disabled, but they // still get built as part of the 'std' module, which breaks the build. // UNSUPPORTED: libcpp-has-no-threads // UNSUPPORTED: libcpp-has-no-localization // UNSUPPORTED: libcpp-has-no-filesystem-library // Test that intypes.h re-exports stdint.h // REQUIRES: modules-support // ADDITIONAL_COMPILE_FLAGS: -fmodules #include <inttypes.h> int main(int, char**) { int8_t x; (void)x; return 0; }
//------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled Copyright (c) 2012, 2013 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== #include <ripple/module/app/book/Quality.h> #include <beast/unit_test/suite.h> #include <beast/cxx14/type_traits.h> namespace ripple { namespace core { class Quality_test : public beast::unit_test::suite { public: // Create a raw, non-integral amount from mantissa and exponent Amount static raw (std::uint64_t mantissa, int exponent) { return Amount ({Currency(3), Account(3)}, mantissa, exponent); } template <class Integer> static Amount amount (Integer integer, std::enable_if_t <std::is_signed <Integer>::value>* = 0) { static_assert (std::is_integral <Integer>::value, ""); return Amount (integer, false); } template <class Integer> static Amount amount (Integer integer, std::enable_if_t <! std::is_signed <Integer>::value>* = 0) { static_assert (std::is_integral <Integer>::value, ""); if (integer < 0) return Amount (-integer, true); return Amount (integer, false); } template <class In, class Out> static Amounts amounts (In in, Out out) { return Amounts (amount(in), amount(out)); } template <class In1, class Out1, class Int, class In2, class Out2> void ceil_in (Quality const& q, In1 in, Out1 out, Int limit, In2 in_expected, Out2 out_expected) { auto expect_result (amounts (in_expected, out_expected)); auto actual_result (q.ceil_in (amounts(in, out), amount(limit))); expect (actual_result == expect_result); } template <class In1, class Out1, class Int, class In2, class Out2> void ceil_out (Quality const& q, In1 in, Out1 out, Int limit, In2 in_expected, Out2 out_expected) { auto const expect_result (amounts (in_expected, out_expected)); auto const actual_result (q.ceil_out (amounts(in, out), amount(limit))); expect (actual_result == expect_result); } void test_ceil_in () { testcase ("ceil_in"); { // 1 in, 1 out: Quality q (Amounts (amount(1), amount(1))); ceil_in (q, 1, 1, // 1 in, 1 out 1, // limit: 1 1, 1); // 1 in, 1 out ceil_in (q, 10, 10, // 10 in, 10 out 5, // limit: 5 5, 5); // 5 in, 5 out ceil_in (q, 5, 5, // 5 in, 5 out 10, // limit: 10 5, 5); // 5 in, 5 out } { // 1 in, 2 out: Quality q (Amounts (amount(1), amount(2))); ceil_in (q, 40, 80, // 40 in, 80 out 40, // limit: 40 40, 80); // 40 in, 20 out ceil_in (q, 40, 80, // 40 in, 80 out 20, // limit: 20 20, 40); // 20 in, 40 out ceil_in (q, 40, 80, // 40 in, 80 out 60, // limit: 60 40, 80); // 40 in, 80 out } { // 2 in, 1 out: Quality q (Amounts (amount(2), amount(1))); ceil_in (q, 40, 20, // 40 in, 20 out 20, // limit: 20 20, 10); // 20 in, 10 out ceil_in (q, 40, 20, // 40 in, 20 out 40, // limit: 40 40, 20); // 40 in, 20 out ceil_in (q, 40, 20, // 40 in, 20 out 50, // limit: 40 40, 20); // 40 in, 20 out } } void test_ceil_out () { testcase ("ceil_out"); { // 1 in, 1 out: Quality q (Amounts (amount(1),amount(1))); ceil_out (q, 1, 1, // 1 in, 1 out 1, // limit 1 1, 1); // 1 in, 1 out ceil_out (q, 10, 10, // 10 in, 10 out 5, // limit 5 5, 5); // 5 in, 5 out ceil_out (q, 10, 10, // 10 in, 10 out 20, // limit 20 10, 10); // 10 in, 10 out } { // 1 in, 2 out: Quality q (Amounts (amount(1),amount(2))); ceil_out (q, 40, 80, // 40 in, 80 out 40, // limit 40 20, 40); // 20 in, 40 out ceil_out (q, 40, 80, // 40 in, 80 out 80, // limit 80 40, 80); // 40 in, 80 out ceil_out (q, 40, 80, // 40 in, 80 out 100, // limit 100 40, 80); // 40 in, 80 out } { // 2 in, 1 out: Quality q (Amounts (amount(2),amount(1))); ceil_out (q, 40, 20, // 40 in, 20 out 20, // limit 20 40, 20); // 40 in, 20 out ceil_out (q, 40, 20, // 40 in, 20 out 40, // limit 40 40, 20); // 40 in, 20 out ceil_out (q, 40, 20, // 40 in, 20 out 10, // limit 10 20, 10); // 20 in, 10 out } } void test_raw() { testcase ("raw"); { Quality q (0x5d048191fb9130daull); // 126836389.7680090 Amounts const value ( amount(349469768), // 349.469768 XRP raw (2755280000000000ull, -15)); // 2.75528 Amount const limit ( raw (4131113916555555, -16)); // .4131113916555555 Amounts const result (q.ceil_out (value, limit)); expect (result.in != zero); } } void test_comparisons() { testcase ("comparisons"); Amount const amount1 (noIssue(), 231); Amount const amount2 (noIssue(), 462); Amount const amount3 (noIssue(), 924); Quality const q11 (core::Amounts (amount1, amount1)); Quality const q12 (core::Amounts (amount1, amount2)); Quality const q13 (core::Amounts (amount1, amount3)); Quality const q21 (core::Amounts (amount2, amount1)); Quality const q31 (core::Amounts (amount3, amount1)); expect (q11 == q11); expect (q11 < q12); expect (q12 < q13); expect (q31 < q21); expect (q21 < q11); expect (q31 != q21); } void test_composition () { testcase ("composition"); Amount const amount1 (noIssue(), 231); Amount const amount2 (noIssue(), 462); Amount const amount3 (noIssue(), 924); Quality const q11 (core::Amounts (amount1, amount1)); Quality const q12 (core::Amounts (amount1, amount2)); Quality const q13 (core::Amounts (amount1, amount3)); Quality const q21 (core::Amounts (amount2, amount1)); Quality const q31 (core::Amounts (amount3, amount1)); expect (composed_quality (q12, q21) == q11); Quality const q13_31 (composed_quality (q13, q31)); Quality const q31_13 (composed_quality (q31, q13)); expect (q13_31 == q31_13); expect (q13_31 == q11); } void test_operations () { testcase ("operations"); Quality const q11 (core::Amounts ( Amount (noIssue(), 731), Amount (noIssue(), 731))); Quality qa (q11); Quality qb (q11); expect (qa == qb); expect (++qa != q11); expect (qa != qb); expect (--qb != q11); expect (qa != qb); expect (qb < qa); expect (qb++ < qa); expect (qb++ < qa); expect (qb++ == qa); expect (qa < qb); } void run() { test_comparisons (); test_composition (); test_operations (); test_ceil_in (); test_ceil_out (); test_raw (); } }; BEAST_DEFINE_TESTSUITE(Quality,core,ripple); } }
; A118828: Numerators of the convergents of the 2-adic continued fraction of zero given by A118827. ; 1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1,-1,1,0,1,1,-1,0,-1 mul $0,10 bin $0,2 add $0,2 cal $0,46978 ; Numerators of Taylor series for exp(x)*sin(x). mov $1,$0
; A225530: Number of ordered pairs (i,j) with i,j >= 0, i + j = n and gcd(i,j) <= 1. ; 1,2,1,2,2,4,2,6,4,6,4,10,4,12,6,8,8,16,6,18,8,12,10,22,8,20,12,18,12,28,8,30,16,20,16,24,12,36,18,24,16,40,12,42,20,24,22,46,16,42,20,32,24,52,18,40,24,36,28,58,16,60,30,36,32,48,20,66,32,44,24,70,24,72,36,40,36,60,24,78,32,54,40,82,24,64,42,56,40,88,24,72,44,60,46,72,32,96,42,60 mov $1,$0 lpb $1 mov $0,$1 trn $0,1 seq $0,10 ; Euler totient function phi(n): count numbers <= n and prime to n. sub $0,1 mov $1,1 lpe add $0,1
# # Test for instructions ATX 0(0), XTA 0(0), ATI 0(0), ITA 0(0). # Address 0 and register m0 should always return 0. # org 1 ptr start 1 vtm -1,2 ita 2 atx 0 lbl a0left xta 0 # слева ati 2 vim fail,2 vtm -1,2 ita 2 lbl a0rght atx 0 xta 0 # справа ati 2 vim fail,2 # vtm -1,2 ita 2 ati 0 lbl m0left ita 0 # слева ati 2 vim fail,2 vtm -1,2 ita 2 lbl m0rght ati 0 ita 0 # справа ati 2 vim fail,2 # lbl pass stop 0o12345,6 lbl fail stop 0o76543,2
; 7 - Frase con offset ; López Garay Luis Felipe ; 15211312 ; 27 de Septiembre del 2018 .Model small .Stack 64 .Data frase db "Ensamblado con ensamblador!", 10, 13, "$" .Code mov ax,@Data mov ds,ax mov dx,offset frase mov ah,09h int 21h .Exit end
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r15 push %r8 push %rax push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_D_ht+0x46d8, %rbx nop nop and $43463, %rdi mov (%rbx), %r8d add %r10, %r10 lea addresses_D_ht+0x9628, %r15 nop add %rbp, %rbp mov (%r15), %eax nop add %r10, %r10 lea addresses_UC_ht+0x18d58, %rsi lea addresses_UC_ht+0xfd8, %rdi inc %rax mov $47, %rcx rep movsq inc %rax lea addresses_A_ht+0x187e8, %rcx nop nop nop nop nop xor $21665, %rdi mov (%rcx), %rsi nop nop lfence lea addresses_UC_ht+0x75d8, %rbp nop nop nop sub $23859, %r15 movb $0x61, (%rbp) nop nop nop nop add %rax, %rax lea addresses_D_ht+0x1e3ee, %rsi lea addresses_A_ht+0xbe18, %rdi nop nop dec %rax mov $46, %rcx rep movsl nop nop nop nop lfence lea addresses_UC_ht+0x4dd8, %rdi nop nop nop nop nop and %rcx, %rcx mov (%rdi), %si nop nop sub %r15, %r15 lea addresses_A_ht+0x110c0, %rax nop add %r10, %r10 mov $0x6162636465666768, %rbp movq %rbp, (%rax) nop nop nop nop nop and %rbx, %rbx lea addresses_WT_ht+0x119d8, %rbp nop sub $54853, %rdi movw $0x6162, (%rbp) nop lfence lea addresses_A_ht+0x162d8, %r10 nop nop nop nop nop add %rcx, %rcx movb (%r10), %bl nop and %rbx, %rbx lea addresses_UC_ht+0x5058, %rbx nop nop sub $49656, %rcx mov $0x6162636465666768, %r10 movq %r10, %xmm5 movups %xmm5, (%rbx) nop nop nop nop nop and $6596, %rbx lea addresses_WT_ht+0xf358, %rbp inc %rsi vmovups (%rbp), %ymm4 vextracti128 $0, %ymm4, %xmm4 vpextrq $0, %xmm4, %rdi xor %rdi, %rdi lea addresses_normal_ht+0x7416, %r8 dec %rbp mov (%r8), %rbx nop nop nop nop sub %rdi, %rdi pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %rax pop %r8 pop %r15 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %r15 push %r9 push %rbp push %rcx push %rdi push %rsi // Store lea addresses_WT+0x1c5b6, %r10 nop cmp %r13, %r13 mov $0x5152535455565758, %rdi movq %rdi, (%r10) nop nop nop xor $49493, %r13 // REPMOV lea addresses_normal+0xf2b8, %rsi lea addresses_WT+0x59d8, %rdi nop inc %r13 mov $111, %rcx rep movsw nop nop nop sub %r15, %r15 // Store mov $0x1d8, %rdi nop nop nop nop nop cmp %rsi, %rsi movl $0x51525354, (%rdi) nop and $556, %r9 // Store lea addresses_US+0x1734f, %r15 nop nop nop and $21672, %r13 movb $0x51, (%r15) and %rcx, %rcx // Store lea addresses_WC+0x149d8, %r10 nop nop nop nop nop add $27533, %r15 movw $0x5152, (%r10) add %rcx, %rcx // Faulty Load lea addresses_WT+0x59d8, %rsi nop nop nop nop xor %r15, %r15 mov (%rsi), %rbp lea oracles, %r9 and $0xff, %rbp shlq $12, %rbp mov (%r9,%rbp,1), %rbp pop %rsi pop %rdi pop %rcx pop %rbp pop %r9 pop %r15 pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WT', 'congruent': 0}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_WT', 'congruent': 1}, 'OP': 'STOR'} {'dst': {'same': True, 'congruent': 0, 'type': 'addresses_WT'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_normal'}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_P', 'congruent': 9}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_US', 'congruent': 0}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_WC', 'congruent': 11}, 'OP': 'STOR'} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': True, 'AVXalign': True, 'size': 8, 'type': 'addresses_WT', 'congruent': 0}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_D_ht', 'congruent': 6}} {'OP': 'LOAD', 'src': {'same': False, 'NT': True, 'AVXalign': False, 'size': 4, 'type': 'addresses_D_ht', 'congruent': 1}} {'dst': {'same': False, 'congruent': 9, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 6, 'type': 'addresses_UC_ht'}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_A_ht', 'congruent': 4}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_UC_ht', 'congruent': 10}, 'OP': 'STOR'} {'dst': {'same': False, 'congruent': 6, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'src': {'same': True, 'congruent': 1, 'type': 'addresses_D_ht'}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_UC_ht', 'congruent': 10}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_A_ht', 'congruent': 3}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': True, 'AVXalign': False, 'size': 2, 'type': 'addresses_WT_ht', 'congruent': 10}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_A_ht', 'congruent': 7}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_UC_ht', 'congruent': 7}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_WT_ht', 'congruent': 6}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_normal_ht', 'congruent': 1}} {'34': 1109} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
; A016206: Expansion of 1/((1-x)*(1-2x)*(1-11x)). ; 1,14,161,1786,19677,216510,2381737,26199362,288193493,3170129446,34871425953,383585689578,4219442593549,46413868545422,510552554032409,5616078094422034,61776859038773445,679545449426770038 lpb $0 mov $2,$0 sub $0,1 seq $2,16135 ; Expansion of 1/((1-2*x)*(1-11*x)). add $1,$2 lpe add $1,1 mov $0,$1
#pragma once #include <sstream> namespace kms { class addrinfo_t { struct addrinfo* m_pResult; int m_rc; public: addrinfo_t(const std::string& sAddress, int port, struct addrinfo& hints) : m_pResult(NULL) , m_rc(-1) { using std::stringstream; std::string sPort; stringstream ss; ss << port; sPort = ss.str(); m_rc = getaddrinfo(sAddress.c_str(), sPort.c_str(), &hints, &m_pResult); } ~addrinfo_t() { if (m_rc == 0) { freeaddrinfo(m_pResult); m_pResult = NULL; } } bool getIsValid() const { return m_rc == 0; } int getFamily() const { return m_pResult->ai_family; } int getSockType() const { return m_pResult->ai_socktype; } int getProtocol() const { return m_pResult->ai_protocol; } struct sockaddr * getAddr() const { return m_pResult->ai_addr; } auto getAddrLength() const -> auto { return m_pResult->ai_addrlen; } }; class socket_t { //provided by the platform.hpp kms_socket_t m_socket; public: socket_t() : m_socket(KMS_INVALID_SOCKET) { } ~socket_t() { close(); } void close() { if (getIsValid()) { ::closesocket(m_socket); m_socket = KMS_INVALID_SOCKET; } } void setNonBlockingMode() { unsigned long val = 1; ioctlsocket(m_socket, FIONBIO, &val); } bool getIsValid() const { return m_socket != KMS_INVALID_SOCKET; } bool connectTcp(const std::string& sAddress, int port) { //straight from MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/bb530741(v=vs.85).aspx struct addrinfo hints; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; addrinfo_t addr(sAddress, port, hints); if (!addr.getIsValid()) { //log_error("socket_t::Connect, getaddrinfo failed: %ld", rc); return false; } m_socket = socket(addr.getFamily(), addr.getSockType(), addr.getProtocol()); if (!getIsValid()) { return false; } int rc = connect(m_socket, addr.getAddr(), addr.getAddrLength()); if (rc == KMS_SOCKET_ERROR) { close(); } return getIsValid(); } auto recv(CCharVector& data, size_t index = 0) -> auto { memset(&data[index], 0, data.size() - index); return ::recv(m_socket, &data[index], data.size() - index, 0); } bool send(const std::string& buffer) { return KMS_SOCKET_ERROR != ::send(m_socket, buffer.c_str(), buffer.size(), 0); } int send(const CCharVector& buffer) { return static_cast<int>(::send(m_socket, &buffer[0], buffer.size(), 0)); } int checkForError() { fd_set hum; TIMEVAL wait = {0, 0}; FD_ZERO(&hum); FD_SET(m_socket, &hum); ::select(32, NULL, NULL, &hum, &wait); return FD_ISSET(m_socket, &hum); } int checkForRead() { fd_set hum; TIMEVAL wait = {0, 0}; FD_ZERO(&hum); FD_SET(m_socket, &hum); ::select(32, &hum, NULL, NULL, &wait); return FD_ISSET(m_socket, &hum); } int checkForWrite() { fd_set hum; TIMEVAL wait = {0, 0}; FD_ZERO(&hum); FD_SET(m_socket, &hum); ::select(32, NULL, &hum, NULL, &wait); return FD_ISSET(m_socket, &hum); } }; }
code: jmp start format: db 0x07 text: db 'c','h','a' ,'n','g' ,\ 'l','o','n' start: mov ax,0x07c0 mov ds,ax mov ax,0xb800 mov es,ax mov cx,(start - text ) mov di,0 mov si,text for: mov al,[si] mov byte [es:di], al add di,0x1 mov al,[format] mov byte [es:di],al add si,0x1 loop for ; 在调试的时候不会进行循环,直接跳转到下一个指令开始执行 end: times 510 - (end - code) db 0 db 0x55,0xaa
; A056738: Positions where 2's occur in A056731. ; 1,4,8,13,20,28,37,47,59,72,86,101,117,135,154,174,195,217,240,264,290,317,345,374,404,435,467,500,535,571,608,646,685,725,766,808,851,896,942,989,1037,1086,1136,1187,1239,1292,1346,1402,1459,1517,1576,1636 mov $21,$0 mov $23,$0 add $23,1 lpb $23 clr $0,21 mov $0,$21 sub $23,1 sub $0,$23 mov $18,$0 mov $20,$0 add $20,1 lpb $20 mov $0,$18 sub $20,1 sub $0,$20 mov $14,$0 mov $16,2 lpb $16 mov $0,$14 sub $16,1 add $0,$16 sub $0,1 mov $4,4 add $4,$0 mov $6,29 mov $11,$0 add $0,$4 mul $0,2 mov $4,1 lpb $0 add $4,3 sub $0,$4 add $4,2 add $5,$6 lpe mov $1,$5 sub $1,51 div $1,29 add $1,2 mov $5,$6 mov $13,$11 mul $13,2 add $1,$13 mov $17,$16 lpb $17 mov $15,$1 sub $17,1 lpe lpe lpb $14 mov $14,0 sub $15,$1 lpe mov $1,$15 sub $1,1 add $19,$1 lpe add $22,$19 lpe mov $1,$22
// Copyright (c) 2012-2015 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "util.h" #include "test/test_cryptodex.h" #include <string> #include <vector> #include <boost/algorithm/string.hpp> #include <boost/foreach.hpp> #include <boost/test/unit_test.hpp> BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup) static void ResetArgs(const std::string& strArg) { std::vector<std::string> vecArg; if (strArg.size()) boost::split(vecArg, strArg, boost::is_space(), boost::token_compress_on); // Insert dummy executable name: vecArg.insert(vecArg.begin(), "testcryptodex"); // Convert to char*: std::vector<const char*> vecChar; BOOST_FOREACH(std::string& s, vecArg) vecChar.push_back(s.c_str()); ParseParameters(vecChar.size(), &vecChar[0]); } BOOST_AUTO_TEST_CASE(boolarg) { ResetArgs("-foo"); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); BOOST_CHECK(!GetBoolArg("-fo", false)); BOOST_CHECK(GetBoolArg("-fo", true)); BOOST_CHECK(!GetBoolArg("-fooo", false)); BOOST_CHECK(GetBoolArg("-fooo", true)); ResetArgs("-foo=0"); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-foo=1"); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); // New 0.6 feature: auto-map -nosomething to !-something: ResetArgs("-nofoo"); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-nofoo=1"); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-foo -nofoo"); // -nofoo should win BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-foo=1 -nofoo=1"); // -nofoo should win BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-foo=0 -nofoo=0"); // -nofoo=0 should win BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); // New 0.6 feature: treat -- same as -: ResetArgs("--foo=1"); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); ResetArgs("--nofoo=1"); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); } BOOST_AUTO_TEST_CASE(stringarg) { ResetArgs(""); BOOST_CHECK_EQUAL(GetArg("-foo", ""), ""); BOOST_CHECK_EQUAL(GetArg("-foo", "eleven"), "eleven"); ResetArgs("-foo -bar"); BOOST_CHECK_EQUAL(GetArg("-foo", ""), ""); BOOST_CHECK_EQUAL(GetArg("-foo", "eleven"), ""); ResetArgs("-foo="); BOOST_CHECK_EQUAL(GetArg("-foo", ""), ""); BOOST_CHECK_EQUAL(GetArg("-foo", "eleven"), ""); ResetArgs("-foo=11"); BOOST_CHECK_EQUAL(GetArg("-foo", ""), "11"); BOOST_CHECK_EQUAL(GetArg("-foo", "eleven"), "11"); ResetArgs("-foo=eleven"); BOOST_CHECK_EQUAL(GetArg("-foo", ""), "eleven"); BOOST_CHECK_EQUAL(GetArg("-foo", "eleven"), "eleven"); } BOOST_AUTO_TEST_CASE(intarg) { ResetArgs(""); BOOST_CHECK_EQUAL(GetArg("-foo", 11), 11); BOOST_CHECK_EQUAL(GetArg("-foo", 0), 0); ResetArgs("-foo -bar"); BOOST_CHECK_EQUAL(GetArg("-foo", 11), 0); BOOST_CHECK_EQUAL(GetArg("-bar", 11), 0); ResetArgs("-foo=11 -bar=12"); BOOST_CHECK_EQUAL(GetArg("-foo", 0), 11); BOOST_CHECK_EQUAL(GetArg("-bar", 11), 12); ResetArgs("-foo=NaN -bar=NotANumber"); BOOST_CHECK_EQUAL(GetArg("-foo", 1), 0); BOOST_CHECK_EQUAL(GetArg("-bar", 11), 0); } BOOST_AUTO_TEST_CASE(doublecryptodex) { ResetArgs("--foo"); BOOST_CHECK_EQUAL(GetBoolArg("-foo", false), true); ResetArgs("--foo=verbose --bar=1"); BOOST_CHECK_EQUAL(GetArg("-foo", ""), "verbose"); BOOST_CHECK_EQUAL(GetArg("-bar", 0), 1); } BOOST_AUTO_TEST_CASE(boolargno) { ResetArgs("-nofoo"); BOOST_CHECK(!GetBoolArg("-foo", true)); BOOST_CHECK(!GetBoolArg("-foo", false)); ResetArgs("-nofoo=1"); BOOST_CHECK(!GetBoolArg("-foo", true)); BOOST_CHECK(!GetBoolArg("-foo", false)); ResetArgs("-nofoo=0"); BOOST_CHECK(GetBoolArg("-foo", true)); BOOST_CHECK(GetBoolArg("-foo", false)); ResetArgs("-foo --nofoo"); // --nofoo should win BOOST_CHECK(!GetBoolArg("-foo", true)); BOOST_CHECK(!GetBoolArg("-foo", false)); ResetArgs("-nofoo -foo"); // foo always wins: BOOST_CHECK(GetBoolArg("-foo", true)); BOOST_CHECK(GetBoolArg("-foo", false)); } BOOST_AUTO_TEST_SUITE_END()
;; ;; 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. ;; %define NUM_LANES 8 %define AES_CBC_ENC_X4 aes_cbc_enc_128_x8_sse %define SUBMIT_JOB_AES_ENC submit_job_aes128_enc_x8_sse %include "sse/mb_mgr_aes_submit_sse.asm"
;; ;; Copyright (c) 2012-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. ;; ; SHA1 code, hybrid, rolled, interleaved ; Uses SSE instructions %include "include/os.asm" %include "include/clear_regs.asm" section .data default rel align 16 PSHUFFLE_BYTE_FLIP_MASK: ;ddq 0x0c0d0e0f08090a0b0405060700010203 dq 0x0405060700010203, 0x0c0d0e0f08090a0b K00_19: ;ddq 0x5A8279995A8279995A8279995A827999 dq 0x5A8279995A827999, 0x5A8279995A827999 K20_39: ;ddq 0x6ED9EBA16ED9EBA16ED9EBA16ED9EBA1 dq 0x6ED9EBA16ED9EBA1, 0x6ED9EBA16ED9EBA1 K40_59: ;ddq 0x8F1BBCDC8F1BBCDC8F1BBCDC8F1BBCDC dq 0x8F1BBCDC8F1BBCDC, 0x8F1BBCDC8F1BBCDC K60_79: ;ddq 0xCA62C1D6CA62C1D6CA62C1D6CA62C1D6 dq 0xCA62C1D6CA62C1D6, 0xCA62C1D6CA62C1D6 section .text %define MOVDQ movdqu ;; assume buffers not aligned %ifdef LINUX %define INP rdi ; 1st arg %define CTX rsi ; 2nd arg %define REG3 edx %define REG4 ecx %else %define INP rcx ; 1st arg %define CTX rdx ; 2nd arg %define REG3 edi %define REG4 esi %endif %define FRAMESZ 3*16 + 1*8 %define _RSP FRAMESZ-1*8 + rsp %define a eax %define b ebx %define c REG3 %define d REG4 %define e r8d %define T1 r9d %define f r10d %define RND r11d %define g r12d %define h r13d %define XTMP0 xmm0 %define XTMP1 xmm1 %define XK xmm2 %xdefine X0 xmm3 %xdefine X1 xmm4 %xdefine X2 xmm5 %xdefine X3 xmm6 %xdefine X4 xmm7 %define XFER xmm8 %define SZ 4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Define Macros %macro rotate_Xs 0 %xdefine X_ X0 %xdefine X0 X1 %xdefine X1 X2 %xdefine X2 X3 %xdefine X3 X4 %xdefine X4 X_ %endmacro %macro ROTATE_ARGS 0 %xdefine TMP_ h %xdefine h g %xdefine g f %xdefine f e %xdefine e d %xdefine d c %xdefine c b %xdefine b a %xdefine a TMP_ %endm ;; Magic functions defined in FIPS 180-1 ;; ; macro MAGIC_F0 F,B,C,D,T ;; F = (D ^ (B & (C ^ D))) %macro MAGIC_F0 5 %define %%regF %1 %define %%regB %2 %define %%regC %3 %define %%regD %4 %define %%regT %5 mov %%regF,%%regC xor %%regF,%%regD and %%regF,%%regB xor %%regF,%%regD %endmacro ; macro MAGIC_F1 F,B,C,D,T ;; F = (B ^ C ^ D) %macro MAGIC_F1 5 %define %%regF %1 %define %%regB %2 %define %%regC %3 %define %%regD %4 %define %%regT %5 mov %%regF,%%regD xor %%regF,%%regC xor %%regF,%%regB %endmacro ; macro MAGIC_F2 F,B,C,D,T ;; F = ((B & C) | (B & D) | (C & D)) %macro MAGIC_F2 5 %define %%regF %1 %define %%regB %2 %define %%regC %3 %define %%regD %4 %define %%regT %5 mov %%regF,%%regB mov %%regT,%%regB or %%regF,%%regC and %%regT,%%regC and %%regF,%%regD or %%regF,%%regT %endmacro ; macro MAGIC_F3 F,B,C,D,T ;; F = (B ^ C ^ D) %macro MAGIC_F3 5 %define %%regF %1 %define %%regB %2 %define %%regC %3 %define %%regD %4 %define %%regT %5 MAGIC_F1 %%regF,%%regB,%%regC,%%regD,%%regT %endmacro ;; input is T1 %macro ROUND 1 %define %%MAGIC %1 add e,T1 mov T1,a rol T1,5 add e,T1 %%MAGIC h,b,c,d,T1 ;; FUN = MAGIC_Fi(B,C,D) rol b,30 add h,e ROTATE_ARGS %endmacro %macro do_4i 1 movdqa XFER, XK paddd XFER, X0 pextrd T1, XFER, 0 ;ROUND %1 add e,T1 ;SCHEDULE_4 movdqa XTMP0, X1 palignr XTMP0, X0, 8 ; XTMP0 = W[-14] mov T1,a movdqa XTMP1, X2 rol T1,5 pxor XTMP1, X0 ; XTMP1 = W[-8] ^ W[-16] add e,T1 pxor XTMP0, XTMP1 ; XTMP0 = W[-8] ^ W[-14] ^ W[-16] %1 h,b,c,d,T1 ;; FUN = MAGIC_Fi(B,C,D) ;; Finish low half movdqa X4, X3 rol b,30 psrldq X4, 4 ; X4 = W[-3] {xxBA} add h,e ROTATE_ARGS pextrd T1, XFER, 1 ;ROUND %1 add e,T1 pxor X4, XTMP0 ; mov T1,a movdqa XTMP1, X4 rol T1,5 ;; rotate X4 left 1 psrld XTMP1, (32-1) add e,T1 pslld X4, 1 %1 h,b,c,d,T1 ;; FUN = MAGIC_Fi(B,C,D) pxor X4, XTMP1 ; X4 = W[0] {xxBA} rol b,30 add h,e ROTATE_ARGS pextrd T1, XFER, 2 ;ROUND %1 add e,T1 movdqa XTMP1, X4 mov T1,a ;; Finish high half palignr XTMP1, X3, 4 ; XTMP1 = w[-3] {DCxx} rol T1,5 add e,T1 pxor XTMP0, XTMP1 %1 h,b,c,d,T1 ;; FUN = MAGIC_Fi(B,C,D) ;; rotate XTMP0 left 1 movdqa XTMP1, XTMP0 psrld XTMP1, (32-1) rol b,30 add h,e ROTATE_ARGS pextrd T1, XFER, 3 ;ROUND %1 add e,T1 mov T1,a pslld XTMP0, 1 rol T1,5 add e,T1 pxor XTMP0, XTMP1 ; XTMP0 = W[0] {DCxx} %1 h,b,c,d,T1 ;; FUN = MAGIC_Fi(B,C,D) ;; COMBINE HALVES shufps X4, XTMP0, 11100100b ; X4 = X[0] {DCBA} rol b,30 add h,e rotate_Xs ROTATE_ARGS %endmacro ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; void sha1_block_sse(void *input_data, UINT32 digest[5]) ;; arg 1 : (in) pointer to one block of data ;; arg 2 : (in/out) pointer to read/write digest MKGLOBAL(sha1_block_sse,function,internal) align 32 sha1_block_sse: push rbx push rsi push rdi push r12 push r13 movdqa XTMP0, [rel PSHUFFLE_BYTE_FLIP_MASK] %ifndef LINUX mov rax, rsp ; copy rsp sub rsp, FRAMESZ and rsp, -16 ; align stack frame mov [_RSP],rax ; save copy of rsp movdqa [rsp + 0 * 16], xmm6 movdqa [rsp + 1 * 16], xmm7 movdqa [rsp + 2 * 16], xmm8 %endif MOVDQ X0, [INP + 0*16] MOVDQ X1, [INP + 1*16] ;; load next message block MOVDQ X2, [INP + 2*16] MOVDQ X3, [INP + 3*16] ;; set up a-f based on h0-h4 ;; byte swap first 16 dwords mov a, [SZ*0 + CTX] pshufb X0, XTMP0 mov b, [SZ*1 + CTX] pshufb X1, XTMP0 mov c, [SZ*2 + CTX] pshufb X2, XTMP0 mov d, [SZ*3 + CTX] pshufb X3, XTMP0 mov e, [SZ*4 + CTX] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; do rounds 00-19 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; movdqa XK, [rel K00_19] mov RND, 3 ROTATE_ARGS ROTATE_ARGS ROTATE_ARGS ROTATE_ARGS rotate_Xs rotate_Xs rotate_Xs rotate_Xs jmp loop1_5 align 16 loop1: do_4i MAGIC_F0 loop1_5: do_4i MAGIC_F0 rotate_Xs rotate_Xs rotate_Xs rotate_Xs movdqa X0, X2 movdqa X2, X4 movdqa X4, X1 movdqa X1, X3 sub RND, 1 jne loop1 rotate_Xs rotate_Xs rotate_Xs rotate_Xs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; end rounds 00-19 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; do rounds 20-39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; movdqa XK, [rel K20_39] mov RND, 3 ROTATE_ARGS ROTATE_ARGS ROTATE_ARGS ROTATE_ARGS rotate_Xs rotate_Xs rotate_Xs rotate_Xs jmp loop2_5 align 16 loop2: do_4i MAGIC_F1 loop2_5: do_4i MAGIC_F1 rotate_Xs rotate_Xs rotate_Xs rotate_Xs movdqa X0, X2 movdqa X2, X4 movdqa X4, X1 movdqa X1, X3 sub RND, 1 jne loop2 rotate_Xs rotate_Xs rotate_Xs rotate_Xs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; end rounds 20-39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; do rounds 40-59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; movdqa XK, [rel K40_59] mov RND, 3 ROTATE_ARGS ROTATE_ARGS ROTATE_ARGS ROTATE_ARGS rotate_Xs rotate_Xs rotate_Xs rotate_Xs jmp loop3_5 align 16 loop3: do_4i MAGIC_F2 loop3_5: do_4i MAGIC_F2 rotate_Xs rotate_Xs rotate_Xs rotate_Xs movdqa X0, X2 movdqa X2, X4 movdqa X4, X1 movdqa X1, X3 sub RND, 1 jne loop3 rotate_Xs rotate_Xs rotate_Xs rotate_Xs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; end rounds 40-59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; do rounds 60-79 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; movdqa XK, [rel K60_79] do_4i MAGIC_F3 movdqa XFER, XK paddd XFER, X0 pextrd T1, XFER, 0 ROUND MAGIC_F3 pextrd T1, XFER, 1 ROUND MAGIC_F3 pextrd T1, XFER, 2 ROUND MAGIC_F3 pextrd T1, XFER, 3 ROUND MAGIC_F3 movdqa XFER, XK paddd XFER, X1 pextrd T1, XFER, 0 ROUND MAGIC_F3 pextrd T1, XFER, 1 ROUND MAGIC_F3 pextrd T1, XFER, 2 ROUND MAGIC_F3 pextrd T1, XFER, 3 ROUND MAGIC_F3 movdqa XFER, XK paddd XFER, X2 pextrd T1, XFER, 0 ROUND MAGIC_F3 pextrd T1, XFER, 1 ROUND MAGIC_F3 pextrd T1, XFER, 2 ROUND MAGIC_F3 pextrd T1, XFER, 3 ROUND MAGIC_F3 movdqa XFER, XK paddd XFER, X3 pextrd T1, XFER, 0 ROUND MAGIC_F3 pextrd T1, XFER, 1 ROUND MAGIC_F3 pextrd T1, XFER, 2 ROUND MAGIC_F3 pextrd T1, XFER, 3 ROUND MAGIC_F3 ;; update result digest h0-h4 add [SZ*0 + CTX], a add [SZ*1 + CTX], b add [SZ*2 + CTX], c add [SZ*3 + CTX], d add [SZ*4 + CTX], e %ifndef LINUX movdqa xmm8, [rsp + 2 * 16] movdqa xmm7, [rsp + 1 * 16] movdqa xmm6, [rsp + 0 * 16] %ifdef SAFE_DATA ;; Clear potential sensitive data stored in stack clear_xmms_sse xmm0, xmm1, xmm2, xmm3, xmm4, xmm5 movdqa [rsp + 0 * 16], xmm0 movdqa [rsp + 1 * 16], xmm0 movdqa [rsp + 2 * 16], xmm0 %endif mov rsp, [_RSP] %else ;; LINUX %ifdef SAFE_DATA clear_all_xmms_sse_asm %endif %endif ;; LINUX pop r13 pop r12 pop rdi pop rsi pop rbx ret %ifdef LINUX section .note.GNU-stack noalloc noexec nowrite progbits %endif
#include <libpmemobj.h> #include <iostream> #include <assert.h> #include <unistd.h> POBJ_LAYOUT_BEGIN(spmo_test); POBJ_LAYOUT_TOID(spmo_test, struct dummy); POBJ_LAYOUT_END(spmo_test); struct dummy { uint64_t x[1024]; }; int main() { unlink("spmo_test.pool"); PMEMobjpool* pool = pmemobj_create("spmo_test.pool", "spmo_test", 10*1024*1024, 0660); assert(pool != NULL); TOID(struct dummy) ptr; for (int i=0; i<1300; i++) { TX_BEGIN(pool) { ptr = TX_ZNEW(struct dummy); } TX_ONABORT { std::cerr << "Faild to allocate a dummy object" << std::endl; abort(); } TX_END TX_BEGIN(pool) { TX_FREE(ptr); } TX_ONABORT { std::cerr << "Failed to free the dummy object" << std::endl; abort(); } TX_END } for (int i=0; i<1300; i++) { TX_BEGIN(pool) { ptr = pmemobj_tx_xalloc(sizeof(struct dummy), TOID_TYPE_NUM(struct dummy), POBJ_XALLOC_ZERO); } TX_ONABORT { std::cerr << "Faild to allocate a dummy object" << std::endl; abort(); } TX_END TX_BEGIN(pool) { TX_FREE(ptr); } TX_ONABORT { std::cerr << "Failed to free the dummy object" << std::endl; abort(); } TX_END } pmemobj_close(pool); return 0; }
SECTION code_clib SECTION code_l PUBLIC l_small_ultoh EXTERN l_small_utoh l_small_ultoh: ; write unsigned hexadecimal long to ascii buffer in uppercase ; ; enter : dehl = unsigned long ; bc = char *buffer ; carry set to write leading zeroes ; ; exit : de = char *buffer (one byte past last char written) ; carry set if in write loop ; ; uses : af, de push hl ex de,hl ld e,c ld d,b call l_small_utoh jr c, was_writing dec de was_writing: pop hl jp l_small_utoh
SECTION code_fp_am9511 PUBLIC ceil EXTERN cam32_sccz80_ceil defc ceil = cam32_sccz80_ceil ; SDCC bridge for Classic IF __CLASSIC PUBLIC _ceil EXTERN cam32_sdcc_ceil defc _ceil = cam32_sdcc_ceil ENDIF
; A169296: Number of reduced words of length n in Coxeter group on 43 generators S_i with relations (S_i)^2 = (S_i S_j)^29 = I. ; 1,43,1806,75852,3185784,133802928,5619722976,236028364992,9913191329664,416354035845888,17486869505527296,734448519232146432,30846837807750150144,1295567187925506306048,54413821892871264854016 add $0,1 mov $3,1 lpb $0 sub $0,1 add $2,$3 div $3,$2 mul $2,42 lpe mov $0,$2 div $0,42
; /***************************************************************************** ; * ugBASIC - an isomorphic BASIC language compiler for retrocomputers * ; ***************************************************************************** ; * Copyright 2021 Marco Spedaletti (asimov@mclink.it) ; * ; * 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. ; *---------------------------------------------------------------------------- ; * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0 ; * (la "Licenza"); è proibito usare questo file se non in conformità alla ; * Licenza. Una copia della Licenza è disponibile all'indirizzo: ; * ; * http://www.apache.org/licenses/LICENSE-2.0 ; * ; * Se non richiesto dalla legislazione vigente o concordato per iscritto, ; * il software distribuito nei termini della Licenza è distribuito ; * "COSì COM'è", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o ; * implicite. Consultare la Licenza per il testo specifico che regola le ; * autorizzazioni e le limitazioni previste dalla medesima. ; ****************************************************************************/ ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ;* * ;* by Marco Spedaletti * ;* * ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * CPURANDOM_SEED: .BYTE $ff, $ff, $ff, $ff CPURANDOM_ENTROPY = MATHPTR3 CPURANDOM_INTERNALSEED: .BYTE $42, $45, $20, $21 CPURANDOM0: LDA CPURANDOM_INTERNALSEED STA CPURANDOM_SEED LDA CPURANDOM_INTERNALSEED+1 STA CPURANDOM_SEED+1 LDA CPURANDOM_INTERNALSEED+2 STA CPURANDOM_SEED+2 LDA CPURANDOM_INTERNALSEED+3 STA CPURANDOM_SEED+3 CPURANDOM: ASL CPURANDOM_SEED ROL CPURANDOM_SEED+1 ROL CPURANDOM_SEED+2 ROL CPURANDOM_SEED+3 BCC CPURANDOM2 LDA CPURANDOM_SEED EOR CPURANDOM_ENTROPY STA CPURANDOM_SEED LDA CPURANDOM_SEED+1 EOR #$1D STA CPURANDOM_SEED+1 LDA CPURANDOM_SEED+2 EOR #$C1 STA CPURANDOM_SEED+2 LDA CPURANDOM_SEED+3 EOR #$04 STA CPURANDOM_SEED+3 CPURANDOM2: LDA CPURANDOM_SEED STA CPURANDOM_INTERNALSEED LDA CPURANDOM_SEED+1 STA CPURANDOM_INTERNALSEED+1 LDA CPURANDOM_SEED+2 STA CPURANDOM_INTERNALSEED+2 LDA CPURANDOM_SEED+3 STA CPURANDOM_INTERNALSEED+3 RTS
; A098658: a(n) = 3^n*(2*n)!/(n!)^2. ; 1,6,54,540,5670,61236,673596,7505784,84440070,956987460,10909657044,124965162504,1437099368796,16581915793800,191876454185400,2225766868550640,25874539846901190,301362287628613860,3515893355667161700,41080438155689994600,480641126421572936820,5630367480938425831320,66028855003732448385480,775121341348163524525200,9107675760840921413171100,107106266947489235818892136,1260558372535834852330038216,14846576387644277149664894544,174977507425807552121050542840,2063527846194006304324113298320,24349628585089274391024536920176,287482711682021755713386468154336,3395889531743881989364377655073094,40133239920609514419760826832682020,474516542590736023433642717257005060 mul $0,2 seq $0,98662 ; E.g.f. BesselI(0,2*sqrt(3)*x) + BesselI(1,2*sqrt(3)*x)/sqrt(3).
; A132592: X-values of solutions to the equation X*(X + 1) - 8*Y^2 = 0. ; 0,8,288,9800,332928,11309768,384199200,13051463048,443365544448,15061377048200,511643454094368,17380816062160328,590436102659356800,20057446674355970888,681362750825443653408,23146276081390728245000,786292024016459316676608,26710782540478226038759688,907380314352243226001152800,30824219905435791458000435528,1047116096470464666346013655168,35571123060090362864306463840200,1208371067946601872720073756911648,41049045187124373309618201271155848,1394459165294282090654298769462387200 seq $0,3499 ; a(n) = 6*a(n-1) - a(n-2), with a(0) = 2, a(1) = 6. pow $0,2 sub $0,4 div $0,4
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r8 push %rcx push %rdi push %rsi lea addresses_WC_ht+0x10cab, %rsi lea addresses_WT_ht+0x72b, %rdi clflush (%rdi) nop nop nop nop nop add %r10, %r10 mov $23, %rcx rep movsw nop add $6574, %r8 pop %rsi pop %rdi pop %rcx pop %r8 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r14 push %r8 push %rbx push %rcx push %rdx // Store lea addresses_PSE+0xdfbb, %r14 nop xor %r12, %r12 movb $0x51, (%r14) sub %r14, %r14 // Store mov $0x44f5400000003ab, %rbx nop nop and %r10, %r10 mov $0x5152535455565758, %rcx movq %rcx, %xmm4 vmovups %ymm4, (%rbx) nop sub $30055, %r8 // Load lea addresses_WC+0x202b, %rdx and $52744, %r8 movups (%rdx), %xmm0 vpextrq $0, %xmm0, %rcx nop nop dec %r10 // Store lea addresses_RW+0x7d2b, %rdx nop nop add $51733, %rcx movw $0x5152, (%rdx) nop nop nop nop cmp %r8, %r8 // Store lea addresses_WC+0x1eb8c, %rcx nop nop nop inc %r8 movb $0x51, (%rcx) nop nop and $48031, %rcx // Faulty Load lea addresses_A+0xfb2b, %rbx nop add %r10, %r10 mov (%rbx), %r14 lea oracles, %r12 and $0xff, %r14 shlq $12, %r14 mov (%r12,%r14,1), %r14 pop %rdx pop %rcx pop %rbx pop %r8 pop %r14 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_A', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_PSE', 'size': 1, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 6, 'NT': False, 'type': 'addresses_NC', 'size': 32, 'AVXalign': False}} {'src': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_WC', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 7, 'NT': False, 'type': 'addresses_RW', 'size': 2, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_WC', 'size': 1, 'AVXalign': False}} [Faulty Load] {'src': {'same': True, 'congruent': 0, 'NT': True, 'type': 'addresses_A', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WC_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 10, 'same': False}} {'00': 51} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
; A305189: a(n) = 1*2 + 3 + 4*5 + 6 + 7*8 + 9 + 10*11 + 12 + ... + (up to n). ; 1,2,5,9,25,31,38,87,96,106,206,218,231,400,415,431,687,705,724,1085,1106,1128,1612,1636,1661,2286,2313,2341,3125,3155,3186,4147,4180,4214,5370,5406,5443,6812,6851,6891,8491,8533,8576,10425,10470,10516,12632,12680,12729,15130,15181,15233,17937,17991,18046,21071,21128,21186,24550,24610,24671,28392,28455,28519,32615,32681,32748,37237,37306,37376,42276,42348,42421,47750,47825,47901,53677,53755,53834,60075,60156,60238,66962,67046,67131,74356,74443,74531,82275,82365,82456,90737,90830,90924,99760,99856,99953,109362,109461,109561,119561,119663,119766,130375,130480,130586,141822,141930,142039,153920,154031,154143,166687,166801,166916,180141,180258,180376,194300,194420,194541,209182,209305,209429,224805,224931,225058,241187,241316,241446,258346,258478,258611,276300,276435,276571,295067,295205,295344,314665,314806,314948,335112,335256,335401,356426,356573,356721,378625,378775,378926,401727,401880,402034,425750,425906,426063,450712,450871,451031,476631,476793,476956,503525,503690,503856,531412,531580,531749,560310,560481,560653,590237,590411,590586,621211,621388,621566,653250,653430,653611,686372,686555,686739,720595,720781,720968,755937,756126,756316,792416,792608,792801,830050,830245,830441,868857,869055,869254,908855,909056,909258,950062,950266,950471,992496,992703,992911,1036175,1036385,1036596,1081117,1081330,1081544,1127340,1127556,1127773,1174862,1175081,1175301,1223701,1223923,1224146,1273875,1274100,1274326,1325402,1325630,1325859,1378300,1378531,1378763,1432587,1432821,1433056,1488281,1488518,1488756,1545400,1545640,1545881,1603962,1604205,1604449,1663985,1664231,1664478,1725487,1725736,1725986 mov $3,$0 add $3,1 mov $6,$0 lpb $3,1 mov $0,$6 sub $3,1 sub $0,$3 mov $2,$0 mul $0,2 mod $0,3 mov $4,0 add $4,$2 mov $5,$4 mul $5,2 lpb $0,1 mov $0,1 mul $5,$4 sub $5,2 lpe div $5,2 add $5,1 add $1,$5 lpe
; A161886: Number of nonzero elements in the n X n Redheffer matrix. ; 1,4,7,11,14,19,22,27,31,36,39,46,49,54,59,65,68,75,78,85,90,95,98,107,111,116,121,128,131,140,143,150,155,160,165,175,178,183,188,197,200,209,212,219,226,231,234,245,249,256,261,268,271,280,285,294,299,304 mov $1,5 mov $2,$0 mov $5,$0 mov $6,$0 lpb $2 add $3,1 mov $4,$2 sub $4,$5 lpb $4 add $1,1 trn $4,$3 lpe trn $5,$2 trn $2,2 lpe lpb $6 add $1,3 sub $6,1 lpe sub $1,4
; A144468: Final digit of multiples of 7. ; 0,7,4,1,8,5,2,9,6,3,0,7,4,1,8,5,2,9,6,3,0,7,4,1,8,5,2,9,6,3,0,7,4,1,8,5,2,9,6,3,0,7,4,1,8,5,2,9,6,3,0,7,4,1,8,5,2,9,6,3,0,7,4,1,8,5,2,9,6,3,0,7,4,1,8,5,2,9,6,3,0,7,4,1,8,5,2,9,6,3,0,7,4,1,8,5 mul $0,7 mod $0,10
#include "Platform.inc" #include "TailCalls.inc" #include "../ShiftRegister.inc" #include "../Adc.inc" #include "../Motor.inc" #include "Lcd.inc" #include "States.inc" radix decimal Lcd code global enableLcd global disableLcd global isLcdEnabled enableLcd: .safelySetBankFor enableLcdCount movf enableLcdCount btfss STATUS, Z goto enableLcdDone setLcdState LCD_STATE_ENABLE_WAITFORSHIFTREGISTER enableLcdDone: .setBankFor enableLcdCount incf enableLcdCount tcall enableShiftRegister disableLcd: .safelySetBankFor enableLcdCount decfsz enableLcdCount goto disableLcdDone setLcdState LCD_STATE_DISABLED .setBankFor lcdFlags bcf lcdFlags, LCD_FLAG_ENABLED .setBankFor LCD_CONTRAST_PORT bcf LCD_CONTRAST_PORT, LCD_CONTRAST_PIN fcall disableAdc fcall disableMotorVdd disableLcdDone: tcall disableShiftRegister isLcdEnabled: .safelySetBankFor lcdFlags btfsc lcdFlags, LCD_FLAG_ENABLED retlw 1 retlw 0 end
#include "pch.hpp" #include "Wallet.hpp" #include <chrono> #include <fstream> #include <iterator> #include <ranges> #include <thread> #include <unordered_set> #include "Base58.hpp" #include "Chain.hpp" #include "ECDSA.hpp" #include "GetActiveChainMsg.hpp" #include "GetMempoolMsg.hpp" #include "GetUTXOsMsg.hpp" #include "Log.hpp" #include "Mempool.hpp" #include "MsgCache.hpp" #include "MsgSerializer.hpp" #include "NetClient.hpp" #include "RIPEMD160.hpp" #include "SendActiveChainMsg.hpp" #include "SendMempoolMsg.hpp" #include "SendUTXOsMsg.hpp" #include "SHA256.hpp" #include "Tx.hpp" #include "TxInfoMsg.hpp" #include "UnspentTxOut.hpp" #include "Utils.hpp" std::string Wallet::WalletPath = DefaultWalletPath; std::string Wallet::PubKeyToAddress(const std::vector<uint8_t>& pubKey) { const auto sha256 = SHA256::HashBinary(pubKey); auto ripe = RIPEMD160::HashBinary(sha256); ripe.insert(ripe.begin(), 0x00); auto sha256d = SHA256::DoubleHashBinary(ripe); std::vector checksum(sha256d.begin(), sha256d.begin() + 4); ripe.insert(ripe.end(), checksum.begin(), checksum.end()); return PubKeyHashVersion + Base58::Encode(ripe); } std::tuple<std::vector<uint8_t>, std::vector<uint8_t>, std::string> Wallet::GetWallet(const std::string& walletPath) { std::vector<uint8_t> privKey; std::vector<uint8_t> pubKey; std::string address; std::ifstream wallet_in(walletPath, std::ios::binary); if (wallet_in.good()) { privKey = std::vector<uint8_t>(std::istreambuf_iterator(wallet_in), {}); pubKey = ECDSA::GetPubKeyFromPrivKey(privKey); address = PubKeyToAddress(pubKey); wallet_in.close(); } else { LOG_INFO("Generating new wallet {}", walletPath); auto [privKey, pubKey] = ECDSA::Generate(); address = PubKeyToAddress(pubKey); std::ofstream wallet_out(walletPath, std::ios::binary); wallet_out.write(reinterpret_cast<const char*>(privKey.data()), privKey.size()); wallet_out.flush(); wallet_out.close(); } return {privKey, pubKey, address}; } void Wallet::PrintWalletAddress(const std::string& walletPath) { const auto [privKey, pubKey, address] = GetWallet(walletPath); LOG_INFO("Wallet {} belongs to address {}", walletPath, address); } std::tuple<std::vector<uint8_t>, std::vector<uint8_t>, std::string> Wallet::InitWallet(const std::string& walletPath) { WalletPath = walletPath; const auto [privKey, pubKey, address] = GetWallet(WalletPath); static bool printedAddress = false; if (!printedAddress) { printedAddress = true; LOG_INFO("Your address is {}", address); } return {privKey, pubKey, address}; } std::tuple<std::vector<uint8_t>, std::vector<uint8_t>, std::string> Wallet::InitWallet() { return InitWallet(WalletPath); } std::shared_ptr<TxIn> Wallet::BuildTxIn(const std::vector<uint8_t>& privKey, const std::shared_ptr<TxOutPoint>& txOutPoint, const std::vector<std::shared_ptr<TxOut>>& txOuts) { int32_t sequence = -1; auto pubKey = ECDSA::GetPubKeyFromPrivKey(privKey); const auto spend_msg = MsgSerializer::BuildSpendMsg(txOutPoint, pubKey, sequence, txOuts); auto unlock_sig = ECDSA::SignMsg(spend_msg, privKey); return std::make_shared<TxIn>(txOutPoint, unlock_sig, pubKey, sequence); } std::shared_ptr<Tx> Wallet::SendValue_Miner(uint64_t value, uint64_t fee, const std::string& address, const std::vector<uint8_t>& privKey) { auto tx = BuildTx_Miner(value, fee, address, privKey); if (tx == nullptr) return nullptr; LOG_INFO("Built transaction {}, adding to mempool", tx->Id()); Mempool::AddTxToMempool(tx); NetClient::SendMsgRandom(TxInfoMsg(tx)); return tx; } std::shared_ptr<Tx> Wallet::SendValue(uint64_t value, uint64_t fee, const std::string& address, const std::vector<uint8_t>& privKey) { auto tx = BuildTx(value, fee, address, privKey); if (tx == nullptr) return nullptr; LOG_INFO("Built transaction {}, broadcasting", tx->Id()); if (!NetClient::SendMsgRandom(TxInfoMsg(tx))) { LOG_ERROR("No connection to send transaction"); } return tx; } Wallet::TxStatusResponse Wallet::GetTxStatus_Miner(const std::string& txId) { TxStatusResponse ret; { std::lock_guard lock(Mempool::Mutex); for (const auto& tx : Mempool::Map | std::views::keys) { if (tx == txId) { ret.Status = TxStatus::Mempool; return ret; } } } { std::lock_guard lock(Chain::Mutex); for (uint32_t height = 0; height < Chain::ActiveChain.size(); height++) { const auto& block = Chain::ActiveChain[height]; for (const auto& tx : block->Txs) { if (tx->Id() == txId) { ret.Status = TxStatus::Mined; ret.BlockId = block->Id(); ret.BlockHeight = height; return ret; } } } } ret.Status = TxStatus::NotFound; return ret; } Wallet::TxStatusResponse Wallet::GetTxStatus(const std::string& txId) { TxStatusResponse ret; if (MsgCache::SendMempoolMsg != nullptr) MsgCache::SendMempoolMsg = nullptr; if (!NetClient::SendMsgRandom(GetMempoolMsg())) { LOG_ERROR("No connection to ask mempool"); return ret; } auto start = Utils::GetUnixTimestamp(); while (MsgCache::SendMempoolMsg == nullptr) { if (Utils::GetUnixTimestamp() - start > MsgCache::MAX_MSG_AWAIT_TIME_IN_SECS) { LOG_ERROR("Timeout on GetMempoolMsg"); return ret; } std::this_thread::sleep_for(std::chrono::milliseconds(16)); } for (const auto& tx : MsgCache::SendMempoolMsg->Mempool) { if (tx == txId) { ret.Status = TxStatus::Mempool; return ret; } } if (MsgCache::SendActiveChainMsg != nullptr) MsgCache::SendActiveChainMsg = nullptr; if (!NetClient::SendMsgRandom(GetActiveChainMsg())) { LOG_ERROR("No connection to ask active chain"); return ret; } start = Utils::GetUnixTimestamp(); while (MsgCache::SendActiveChainMsg == nullptr) { if (Utils::GetUnixTimestamp() - start > MsgCache::MAX_MSG_AWAIT_TIME_IN_SECS) { LOG_ERROR("Timeout on GetActiveChainMsg"); return ret; } std::this_thread::sleep_for(std::chrono::milliseconds(16)); } for (uint32_t height = 0; height < MsgCache::SendActiveChainMsg->ActiveChain.size(); height++) { const auto& block = MsgCache::SendActiveChainMsg->ActiveChain[height]; for (const auto& tx : block->Txs) { if (tx->Id() == txId) { ret.Status = TxStatus::Mined; ret.BlockId = block->Id(); ret.BlockHeight = height; return ret; } } } ret.Status = TxStatus::NotFound; return ret; } void Wallet::PrintTxStatus(const std::string& txId) { auto response = GetTxStatus(txId); switch (response.Status) { case TxStatus::Mempool: { LOG_INFO("Transaction {} is in mempool", txId); break; } case TxStatus::Mined: { LOG_INFO("Transaction {} is mined in {} at height {}", txId, response.BlockId, response.BlockHeight); break; } case TxStatus::NotFound: { LOG_INFO("Transaction {} not found", txId); break; } } } uint64_t Wallet::GetBalance_Miner(const std::string& address) { auto utxos = FindUTXOsForAddress_Miner(address); uint64_t value = 0; for (const auto& utxo : utxos) value += utxo->TxOut->Value; return value; } uint64_t Wallet::GetBalance(const std::string& address) { auto utxos = FindUTXOsForAddress(address); uint64_t value = 0; for (const auto& utxo : utxos) value += utxo->TxOut->Value; return value; } void Wallet::PrintBalance(const std::string& address) { uint64_t balance = GetBalance(address); LOG_INFO("Address {} holds {} coins", address, balance); } std::shared_ptr<Tx> Wallet::BuildTxFromUTXOs(std::vector<std::shared_ptr<UTXO>>& utxos, uint64_t value, uint64_t fee, const std::string& address, const std::string& changeAddress, const std::vector<uint8_t>& privKey) { std::ranges::sort(utxos, [](const std::shared_ptr<UTXO>& a, const std::shared_ptr<UTXO>& b) -> bool { return a->TxOut->Value < b->TxOut->Value; }); std::ranges::sort(utxos, [](const std::shared_ptr<UTXO>& a, const std::shared_ptr<UTXO>& b) -> bool { return a->Height < b->Height; }); std::unordered_set<std::shared_ptr<UTXO>> selected_utxos; uint64_t in_sum = 0; const uint32_t total_size_est = 300; const uint64_t total_fee_est = total_size_est * fee; for (const auto& coin : utxos) { selected_utxos.insert(selected_utxos.end(), coin); for (const auto& selected_coin : selected_utxos) { in_sum += selected_coin->TxOut->Value; } if (in_sum <= value + total_fee_est) { in_sum = 0; } else { break; } } if (in_sum == 0) { LOG_ERROR("Not enough coins"); return nullptr; } const auto txOut = std::make_shared<TxOut>(value, address); uint64_t change = in_sum - value - total_fee_est; const auto txOut_change = std::make_shared<TxOut>(change, changeAddress); std::vector txOuts{txOut, txOut_change}; std::vector<std::shared_ptr<TxIn>> txIns; txIns.reserve(selected_utxos.size()); for (const auto& selected_coin : selected_utxos) { txIns.emplace_back(BuildTxIn(privKey, selected_coin->TxOutPoint, txOuts)); } auto tx = std::make_shared<Tx>(txIns, txOuts, 0); const uint32_t tx_size = tx->Serialize().GetBuffer().size(); const uint32_t real_fee = total_fee_est / tx_size; LOG_INFO("Built transaction {} with {} coins/byte fee", tx->Id(), real_fee); return tx; } std::shared_ptr<Tx> Wallet::BuildTx_Miner(uint64_t value, uint64_t fee, const std::string& address, const std::vector<uint8_t>& privKey) { const auto pubKey = ECDSA::GetPubKeyFromPrivKey(privKey); const auto myAddress = PubKeyToAddress(pubKey); auto my_coins = FindUTXOsForAddress_Miner(myAddress); if (my_coins.empty()) { LOG_ERROR("No coins found"); return nullptr; } return BuildTxFromUTXOs(my_coins, value, fee, address, myAddress, privKey); } std::shared_ptr<Tx> Wallet::BuildTx(uint64_t value, uint64_t fee, const std::string& address, const std::vector<uint8_t>& privKey) { const auto pubKey = ECDSA::GetPubKeyFromPrivKey(privKey); const auto myAddress = PubKeyToAddress(pubKey); auto my_coins = FindUTXOsForAddress(myAddress); if (my_coins.empty()) { LOG_ERROR("No coins found"); return nullptr; } return BuildTxFromUTXOs(my_coins, value, fee, address, myAddress, privKey); } std::vector<std::shared_ptr<UTXO>> Wallet::FindUTXOsForAddress_Miner(const std::string& address) { std::vector<std::shared_ptr<UTXO>> utxos; { std::lock_guard lock(UTXO::Mutex); for (const auto& v : UTXO::Map | std::views::values) { if (v->TxOut->ToAddress == address) { utxos.push_back(v); } } } return utxos; } std::vector<std::shared_ptr<UTXO>> Wallet::FindUTXOsForAddress(const std::string& address) { if (MsgCache::SendUTXOsMsg != nullptr) MsgCache::SendUTXOsMsg = nullptr; if (!NetClient::SendMsgRandom(GetUTXOsMsg())) { LOG_ERROR("No connection to ask UTXO set"); return {}; } const auto start = Utils::GetUnixTimestamp(); while (MsgCache::SendUTXOsMsg == nullptr) { if (Utils::GetUnixTimestamp() - start > MsgCache::MAX_MSG_AWAIT_TIME_IN_SECS) { LOG_ERROR("Timeout on GetUTXOsMsg"); return {}; } std::this_thread::sleep_for(std::chrono::milliseconds(16)); } std::vector<std::shared_ptr<UTXO>> utxos; for (const auto& v : MsgCache::SendUTXOsMsg->UTXO_Map | std::views::values) { if (v->TxOut->ToAddress == address) { utxos.push_back(v); } } return utxos; }
; A051683: Triangle read by rows: T(n,k) = n!*k. ; 1,2,4,6,12,18,24,48,72,96,120,240,360,480,600,720,1440,2160,2880,3600,4320,5040,10080,15120,20160,25200,30240,35280,40320,80640,120960,161280,201600,241920,282240,322560,362880,725760,1088640,1451520,1814400,2177280,2540160,2903040,3265920,3628800,7257600,10886400,14515200,18144000,21772800,25401600,29030400,32659200,36288000,39916800,79833600,119750400,159667200,199584000,239500800,279417600,319334400,359251200,399168000,439084800,479001600,958003200,1437004800,1916006400,2395008000,2874009600,3353011200,3832012800,4311014400,4790016000,5269017600,5748019200,6227020800,12454041600,18681062400,24908083200,31135104000,37362124800,43589145600,49816166400,56043187200,62270208000,68497228800,74724249600,80951270400,87178291200,174356582400,261534873600,348713164800,435891456000,523069747200,610248038400,697426329600,784604620800,871782912000,958961203200,1046139494400,1133317785600,1220496076800,1307674368000,2615348736000,3923023104000,5230697472000,6538371840000,7846046208000,9153720576000,10461394944000,11769069312000,13076743680000,14384418048000,15692092416000,16999766784000,18307441152000,19615115520000,20922789888000,41845579776000,62768369664000,83691159552000,104613949440000,125536739328000,146459529216000,167382319104000,188305108992000,209227898880000,230150688768000,251073478656000,271996268544000,292919058432000,313841848320000,334764638208000,355687428096000,711374856192000,1067062284288000,1422749712384000,1778437140480000,2134124568576000,2489811996672000,2845499424768000,3201186852864000,3556874280960000,3912561709056000,4268249137152000,4623936565248000,4979623993344000,5335311421440000,5690998849536000,6046686277632000,6402373705728000 mov $9,$0 mov $11,$0 add $11,1 lpb $11,1 clr $0,9 mov $0,$9 sub $11,1 sub $0,$11 mov $2,$0 lpb $2,1 sub $2,$7 add $7,1 mov $1,$7 trn $2,1 lpe fac $1 add $10,$1 lpe mov $1,$10
if TARGET == TARGET_SCD1 || TARGET == TARGET_SCD2 include blsload_sub.inc include cdbios.inc include bdp_sub.inc SP_INIT clr.b GA_COMMFLAGS_SUB set_wram_default_mode sync_main_sub rts SP_MAIN .1 bra.b .1 ; Endless loop SUB_INT_LEVEL2 blsload_check_main rts endif ; vim: ts=8 sw=8 sts=8 et
; A109119: a(n) = 2(5n^2 + 5n + 1)^3. ; 2,2662,59582,453962,2060602,6885902,18787862,44376082,94091762,183467702,334568302,577609562,952759082,1512116062,2321871302,3464647202,5042017762,7177208582,10017976862,13739671402,18548472602 lpb $0 sub $0,1 add $3,5 add $2,$3 lpe add $1,5 mul $2,2 add $2,1 pow $2,3 mul $1,$2 div $1,50 mul $1,20 add $1,2
; This file is INCLUDEd three times, once for each audio engine. dw .wave0 dw .wave1 dw .wave2 dw .wave3 dw .wave4 dw .wave5 ; used in the Lavender Town and Pokemon Tower themes dw .wave5 ; unused dw .wave5 ; unused dw .wave5 ; unused ; these are the definitions for the channel 3 instruments ; each instrument definition is made up of 32 points (nibbles) that form ; the graph of the wave ; the current instrument is copied to rWave_0--rWave_f .wave0 db $02,$46,$8A,$CE,$FF,$FE,$ED,$DC,$CB,$A9,$87,$65,$44,$33,$22,$11 .wave1 db $02,$46,$8A,$CE,$EF,$FF,$FE,$EE,$DD,$CB,$A9,$87,$65,$43,$22,$11 .wave2 db $13,$69,$BD,$EE,$EE,$FF,$FF,$ED,$DE,$FF,$FF,$EE,$EE,$DB,$96,$31 .wave3 db $02,$46,$8A,$CD,$EF,$FE,$DE,$FF,$EE,$DC,$BA,$98,$76,$54,$32,$10 .wave4 db $01,$23,$45,$67,$8A,$CD,$EE,$F7,$7F,$EE,$DC,$A8,$76,$54,$32,$10 ; duty 5 reads from sfx data .wave5
section .data msg1 : db 'debug here --',10 l1 : equ $-msg1 msg2 : db 'enter the size : ' l2 : equ $-msg2 msg3 : db 'enter the elements : ' l3 : equ $-msg3 msg4 : db 'msg 4 here',10 l4: equ $-msg4 msg5 : db 'msg 5 here',10 l5: equ $-msg5 space:db ' ' newline:db '',10 section .bss num: resw 1 counter: resw 1 n: resd 10 array: resw 50 counter_1: resw 1 dummy : resw 1 counter_2: resw 1 section .text global _start _start: mov eax, 4 mov ebx, 1 mov ecx, msg2 mov edx, l2 int 80h call read_num mov ax, word[num] mov word[n], ax mov word[counter_1],0 mov word[counter_2],0 loop_1: inc word[counter_1] inc word[counter_2] mov eax, 4 mov ebx, 1 mov ecx, msg4 mov edx, l4 int 80h mov eax,[counter_1] cmp eax,dword[n] jb loop_1 exit: mov eax,1 mov ebx,0 int 80h ; section for procedures ;---------------------------- print_num: ;usage ;------ ; 1: create a variable num(word) ; 2: move number to print to num (word) section .data nwl_for_printnum :db ' ',10 nwl_l_printnum : equ $-nwl_for_printnum section .bss count_printnum : resb 10 temp_printnum : resb 1 section .text push rax ; push all push rbx push rcx mov byte[count_printnum],0 ;call push_reg extract_no: cmp word[num], 0 je print_no inc byte[count_printnum] mov dx, 0 mov ax, word[num] mov bx, 10 div bx push dx ; recursion here mov word[num], ax jmp extract_no print_no: cmp byte[count_printnum], 0 je end_print dec byte[count_printnum] pop dx mov byte[temp_printnum], dl ; dx is further divided into dh and dl add byte[temp_printnum], 30h mov eax, 4 mov ebx, 1 mov ecx, temp_printnum mov edx, 1 int 80h jmp print_no end_print: mov eax,4 mov ebx,1 mov ecx,nwl_for_printnum mov edx,nwl_l_printnum int 80h ;;The memory location ’newline’ should be declared with the ASCII key for new popa ;call pop_reg pop rcx pop rbx pop rax ; pop all ret read_num: ;usage ;------ ; 1: create a variable num(word) ; 2: the input number is stored into num(word) section .bss temp_for_read: resb 1 section .text push rax ; push all push rbx push rcx mov word[num], 0 loop_read: ;; read a digit mov eax, 3 mov ebx, 0 mov ecx, temp_for_read mov edx, 1 int 80h ;;check if the read digit is the end of number, i.e, the enter-key whose ASCII cmp byte[temp], 10 cmp byte[temp_for_read], 10 je end_read mov ax, word[num] mov bx, 10 mul bx mov bl, byte[temp_for_read] sub bl, 30h mov bh, 0 add ax, bx mov word[num], ax jmp loop_read end_read: ;;pop all the used registers from the stack using popa ;call pop_reg pop rcx pop rbx pop rax ret
#include <gsl/gsl> #include <numeric> #include <iostream> #include <tuple> #include <vector> #include <iomanip> int gDebug = 0; void getDivider( int aNumber, std::vector<std::tuple<int,int>> & aDiveder ) { int i = 2; int sRemainder = 0; int sLimit = 0; auto sTuple = std::make_tuple( 1, aNumber ); aDiveder.push_back( sTuple ); sLimit = aNumber; while ( i < sLimit ) { sRemainder = aNumber % i; if ( sRemainder == 0 ) { sLimit = aNumber / i; sTuple = std::make_tuple( i, sLimit ); aDiveder.push_back( sTuple ); } else { /* do nothing */ } i++; } } void printDivider( std::vector<std::tuple<int,int>> & aDiveder ) { auto sPrintFunction = [](const std::tuple<int,int> & aTuple) { std::cout << "( " << std::get<0>(aTuple) << ", " << std::get<1>(aTuple) << " ) "; }; std::for_each( aDiveder.begin(), aDiveder.end(), sPrintFunction ); std::cout << "\n"; } int sumDivider( std::vector<std::tuple<int,int>> & aDiveder ) { int sSum = 0; for ( auto & sTuple : aDiveder ) { sSum += std::get<0>( sTuple ); if ( std::get<0>( sTuple ) != std::get<1>( sTuple ) ) { sSum += std::get<1>( sTuple ); } else { /* do nothing */ } } return sSum; } bool isAmicableNumber( int aNumber, int & aPairNumber ) { bool sIsAmicableNumber = false; std::vector<std::tuple<int,int>> sDivederOfNumber; int sPairNumber = 0; std::vector<std::tuple<int,int>> sDivederOfPairNumber; int sSum = 0; int sSumWithoutNumber = 0; getDivider( aNumber, sDivederOfNumber ); if ( gDebug == 1 ) printDivider( sDivederOfNumber ); sSum = sumDivider( sDivederOfNumber ); if ( gDebug == 1 ) std::cout << sSum << "\n"; sPairNumber = sSum - aNumber; if ( gDebug == 1 ) std::cout << sPairNumber << "\n"; if ( sPairNumber != aNumber ) { getDivider( sPairNumber, sDivederOfPairNumber ); sSum = sumDivider( sDivederOfPairNumber ); if ( gDebug == 1 ) std::cout << sSum << "\n"; if ( aNumber == ( sSum - sPairNumber ) ) { aPairNumber = sPairNumber; sIsAmicableNumber = true; } else { sIsAmicableNumber = false; } } else { sIsAmicableNumber = false; } if ( gDebug == 1 ) std::cout << sIsAmicableNumber << "\n"; return sIsAmicableNumber; } int main(int argc, char* argv[]) { int sNumber = 0; int sPairNumber = 0; sNumber = atoi( argv[1] ); if ( argc == 3 ) gDebug = atoi( argv[2] ); for ( int i = 2; i < sNumber; i++ ) { if ( isAmicableNumber( i, sPairNumber ) == true ) { std::cout << "( " << i << ", " << sPairNumber << " ) "; } } std::cout << "\n"; return 0; }
# PowerPC-64 mpn_sub_n -- Subtract two limb vectors of the same length > 0 # and store difference in a third limb vector. # Copyright (C) 1999, 2000 Free Software Foundation, Inc.b # This file is part of the GNU MP Library. # The GNU MP Library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or (at your # option) any later version. # The GNU MP Library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. # You should have received a copy of the GNU Lesser General Public License # along with the GNU MP Library; see the file COPYING.LIB. If not, write to # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, # MA 02111-1307, USA. # INPUT PARAMETERS # res_ptr r3 # s1_ptr r4 # s2_ptr r5 # size r6 include(`../config.m4') ASM_START() PROLOGUE(mpn_sub_n) mtctr r6 # copy size into CTR addic r0,r6,-1 # set cy ld r8,0(r4) # load least significant s1 limb ld r0,0(r5) # load least significant s2 limb addi r3,r3,-8 # offset res_ptr, it's updated before it's used bdz .Lend # If done, skip loop .Loop: ld r9,8(r4) # load s1 limb ld r10,8(r5) # load s2 limb subfe r7,r0,r8 # subtract limbs with cy, set cy std r7,8(r3) # store result limb bdz .Lexit # decrement CTR and exit if done ldu r8,16(r4) # load s1 limb and update s1_ptr ldu r0,16(r5) # load s2 limb and update s2_ptr subfe r7,r10,r9 # subtract limbs with cy, set cy stdu r7,16(r3) # store result limb and update res_ptr bdnz .Loop # decrement CTR and loop back .Lend: subfe r7,r0,r8 std r7,8(r3) # store ultimate result limb subfe r3,r0,r0 # load !cy into ... subfic r3,r3,0 # ... return value register blr .Lexit: subfe r7,r10,r9 std r7,16(r3) subfe r3,r0,r0 # load !cy into ... subfic r3,r3,0 # ... return value register blr EPILOGUE(mpn_sub_n)
; Pasecinic Nichita ; FAF - 192 ; 19.11.2021 [org 0x7c00] ; set origin offset at 0x7c00 ; First default text print mov bx, text ; save to bx the pointer to variable 'text' mov ah, 0Eh ; teletype output ; loop like while true loop: mov al, [bx] ; defer bx to al cmp al, 0 ; if al is termial (0) char : go to second procedure je second int 10h ; BIOS video service inc bx ; increment bx to point to next char in string jmp loop ; loop again ; Draw a rectangle from alphabet letters using different background and foreground colors ; A ..... Z ; . . ; . . ; N N ; A ..... Z ; prints a vertical line, starting from row - 3 and col - 3 ; red text on green background second: ; change cursor position mov ah, 02h ; FUNCTION: Set cursor position mov bh, 0 ; set page number mov dh, 3 ; set row mov dl, 3 ; set column int 10h ; BIOS video service mov al, 64 ; A in decimal is 65, so we need to start looping from 64 loop1: mov ah, 09h ; FUNCTION: Write Character and Attribute at Cursor inc al ; increment al (al++) cmp al, 'Z' + 1 ; if is last letter that we need, go to next procedure je third mov bl, 24H ; red text on green background mov cx, 1 ; Number of times to print character - 1 int 10h ; BIOS video service ; increment cursor position mov ah, 02h ; FUNCTION: Set cursor position mov bh, 0 ; page nr inc dl ; increment column for cursor position int 10h ; BIOS video service jmp loop1 ; loop again ; similar as previous just it is a vertical line from A to N (A - Z will form a rectangle) ; col 3, row 3 ; A - to N ; light cyan text on light red background third: mov ah, 02h mov bh, 0 mov dh, 3 mov dl, 3 int 10h mov al, 64 loop2: mov ah, 09h inc al cmp al, 'N' + 1 je fourth mov bl, 1100_1011b mov cx, 1 int 10h mov ah, 02h mov bh, 0 inc dh int 10h jmp loop2 ; vertical A - O ; white background and black text fourth: mov ah, 02h mov bh, 0 mov dh, 3 mov dl, 29 int 10h mov al, 64 loop3: mov ah, 09h inc al cmp al, 'O' + 1 je fifth mov bl, 1111_0000b mov cx, 1 int 10h mov ah, 02h mov bh, 0 inc dh int 10h jmp loop3 ; horizontal A - Z ; yellow text on blue background fifth: mov ah, 02h mov bh, 0 mov dh, 17 mov dl, 3 int 10h mov al, 64 loop4: mov ah, 09h inc al cmp al, 'Z' + 1 je exit mov bl, 1EH mov cx, 1 int 10h mov ah, 02h mov bh, 0 inc dl int 10h jmp loop4 exit: hlt ; halt execution until wake up text: db "real programmers can write assembly code in any language!", 0 ; define bytes, with 0 as terminal char ; Mark the device as bootable ; Add any additional zeroes to make 510 bytes in totals times 510-($-$$) db 0 ; repead instruction define bytes (db) 510-($-$$) times ; $$ - beginning of the current section ; $-$$ = length of the previous code = 3 ; 3 + (510 - 3) = 510 db 0x55, 0xaa ; Write the final 2 bytes as the magic number 0x55aa, remembering x86 little endian
/********** This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA **********/ // "mTunnel" multicast access service // Copyright (c) 1996-2017 Live Networks, Inc. All rights reserved. // Network Interfaces // C++ header #ifndef _NET_INTERFACE_HH #define _NET_INTERFACE_HH #ifndef _NET_ADDRESS_HH #include "NetAddress.hh" #endif class NetInterface { public: virtual ~NetInterface(); static UsageEnvironment* DefaultUsageEnvironment; // if non-NULL, used for each new interfaces protected: NetInterface(); // virtual base class }; class DirectedNetInterface: public NetInterface { public: virtual ~DirectedNetInterface(); virtual Boolean write(unsigned char* data, unsigned numBytes) = 0; virtual Boolean SourceAddrOKForRelaying(UsageEnvironment& env, unsigned addr) = 0; protected: DirectedNetInterface(); // virtual base class }; class DirectedNetInterfaceSet { public: DirectedNetInterfaceSet(); virtual ~DirectedNetInterfaceSet(); DirectedNetInterface* Add(DirectedNetInterface const* interf); // Returns the old value if different, otherwise 0 Boolean Remove(DirectedNetInterface const* interf); Boolean IsEmpty() { return fTable->IsEmpty(); } // Used to iterate through the interfaces in the set class Iterator { public: Iterator(DirectedNetInterfaceSet& interfaces); virtual ~Iterator(); DirectedNetInterface* next(); // NULL iff none private: HashTable::Iterator* fIter; }; private: friend class Iterator; HashTable* fTable; }; class Socket: public NetInterface { public: virtual ~Socket(); void reset(); // closes the socket, and sets "fSocketNum" to -1 virtual Boolean handleRead(unsigned char* buffer, unsigned bufferMaxSize, unsigned& bytesRead, struct sockaddr_in& fromAddress) = 0; // Returns False on error; resultData == NULL if data ignored int socketNum() const { return fSocketNum; } Port port() const { return fPort; } UsageEnvironment& env() const { return fEnv; } static int DebugLevel; protected: Socket(UsageEnvironment& env, Port port); // virtual base class Boolean changePort(Port newPort); // will also cause socketNum() to change private: int fSocketNum; UsageEnvironment& fEnv; Port fPort; }; UsageEnvironment& operator<<(UsageEnvironment& s, const Socket& sock); // A data structure for looking up a Socket by port: class SocketLookupTable { public: virtual ~SocketLookupTable(); Socket* Fetch(UsageEnvironment& env, Port port, Boolean& isNew); // Creates a new Socket if none already exists Boolean Remove(Socket const* sock); protected: SocketLookupTable(); // abstract base class virtual Socket* CreateNew(UsageEnvironment& env, Port port) = 0; private: HashTable* fTable; }; // A data structure for counting traffic: class NetInterfaceTrafficStats { public: NetInterfaceTrafficStats(); void countPacket(unsigned packetSize); float totNumPackets() const {return fTotNumPackets;} float totNumBytes() const {return fTotNumBytes;} Boolean haveSeenTraffic() const; private: float fTotNumPackets; float fTotNumBytes; }; #endif
; A109960: Number triangle binomial(n+3k,4k). ; Submitted by Jon Maiga ; 1,1,1,1,5,1,1,15,9,1,1,35,45,13,1,1,70,165,91,17,1,1,126,495,455,153,21,1,1,210,1287,1820,969,231,25,1,1,330,3003,6188,4845,1771,325,29,1,1,495,6435,18564,20349,10626,2925,435,33,1,1,715,12870,50388,74613,53130 lpb $0 mov $1,$0 mul $1,2 add $2,1 sub $0,$2 add $1,$0 sub $1,$2 lpe mul $0,4 bin $1,$0 mov $0,$1
DEVICE ZXSPECTRUMNEXT ;OPT reset --zxnext --syntax=abfw slot 3 org #6000 CHARS equ 15616-256 mystak equ 24575 ;ar bi trary value picked to be be low ;BFE0h and above 4000h staksto equ 24575 ;some where to put BA SIC's stack ;pointer bankm equ #5B5C ;sys tem vari able that holds the ;last value out put to 7FFDh port1 equ #7FFD ;ad dress of ROM/RAM switch ing port ;in I/O map catbuff equ #8000 ;some where for DOS to put its catalog dos_catalog equ #011E ;the DOS routine to call filename ds 15 typ equ $-4 pocetpolozek equ 231 virtmem defb 0 maxlen equ 128 maxline equ 37 save_allfiles defw 0 ReadNextReg: ; reads nextreg in A into A (does modify currently selected NextReg on I/O port) push bc ld bc,#243B out (c),a inc b ; bc = TBBLUE_REGISTER_ACCESS_P_253B in a,(c) ; read desired NextReg state pop bc ret INPUT ei ld (INPOS+1),hl ;ulož adresu začátku pro další použití ld hl,23296 ;do HL adresa editační oblasti ld b,hx ;do B délka editační oblasti IN1 ld (hl),32 ;a nyní celou editační inc hl ;zónu vyplníme mezerami djnz IN1 ;na konec editační zóny ld (hl),b ;přijde 0 res 5,(iy+1) ;signál není stisknuta klávesa xor a ;nastav kurzor ld (CURSOR+1),a ;na začátek editační zóny IN2 ld b,hx ;nyní celou editační zónu INPOS ld hl,0 ;vytiskneme, nastav ld (PPOS+1),hl ;tiskovou pozici ld hl,23296 ;začínáme od začátku CURSOR ld c,0 ;do C polohu kurzoru IN3 ld a,l ;testuj spodní byte adresy cp c ;v případe rovnosti ld a,">" ;dej do A kód kurzoru call z,CHAR ;a vytiskni ho ld a,(hl) ;vytiskni znak call CHAR ;z editační zóny inc hl ;a posun se pro další djnz IN3 ;opakuj se všemi znaky ld a,l ;kurzor také může cp c ;být až za posledním ld a,"<"+128 ;znakem, pak bude call z,CHAR ;na řádku vypadat jinak call INKEY ;přečti si kód klávesy cp 7 ;testuj EDIT (Caps Shift + 1) ret z ;a případně se vrať zpátky cp 13 ;testuj ENTER a případné odskoč ret z ;jp z,INPCLEAR ;na smazání řádku z obrazovky ld hl,IN2 ;na zásobník ulož adresu IN2, sem push hl ;se bude nyní program vracet ld hl,CURSOR+1 ;do HL vlož adresu pozice kurzoru cp 8 ;testuj kurzor doleva jr z,CURSLEFT ;odskoč cp 9 ;kurzor doprava jr z,CURSRGHT cp 12 ;delete (správně BACKSPACE) jr z,BCKSPACE cp 199 ;znak <= (funkce DELETE) jr z,DELETE cp 32 ;nyní zbývají ret c ;obyčejné znaky, cp 128 ;odfiltruj ret nc ;netisknutelné znaky ex af,af' ;a kód přesuň do A' ld a,(hl) ;testuj, zda není kurzor cp hx ;na konci řádku, ret nc ;když ano, tak se vrať inc (hl) ;posuň kurzor doprava ld l,(hl) ;do HL vlož adresu, dec l ;na kterou bude znak ld h,23296/256 ;uložen INS ld a,(hl) ;přečti původní znak or a ;a testuj konec řádku ret z ;případně se vrať ex af,af' ;přehoď původní a nový znak ld (hl),a ;a nový zapiš, pro další znak inc hl ;bude novým znakem předchozí jr INS ;znak, opakuj posun znaku až do konce CURSLEFT ld a,(hl) ;přečti polohu kurzoru or a ;a v případe, že je na levém okraji ret z ;tak se vrať a nic nedělej dec (hl) ;posuň kurzor doleva a vrať se na IN2 ret CURSRGHT ld a,(hl) ;přečti polohu kurzoru cp hx ;a když je na konci řádku ret nc ;tak se vrať inc (hl) ;jinak posuň kurzor doprava a vrať se ret ;vrať se na IN2 DELETE ld a,(hl) ;na konci cp hx ;editační zóny ret z ;DELETE nepracuje inc a ;jinak uprav polohu jr BCK2 ;a pokračuj společnou částí BCKSPACE ld a,(hl) ;BACKSPACE naopak or a ;nepracuje na začátku ret z ;editační zóny dec (hl) ;posuň kurzor vlevo BCK2 ld l,a ;společná část, ld h,23296/256 ;která zajišťuje ld e,l ;přesunutí následujících ld d,h ;znaků na uvolněné místo dec e ;po smazaném znaku DEL2 ld a,(hl) ;vlastní přesun ldi ;je prováděn instrukcí or a ;LDI dokud není přenesena 0, jr nz,DEL2 ;která signalizuje konec zóny ex de,hl ;na poslední pozici, dec hl ;která se nyní uvolnila, ld (hl)," " ;je zapsána mezera ret ;návrat na IN2 delka_souboru defw 0 INKEY halt xor a ld (aLAST_KEY+1),a ei halt ahl0 call KEYSCAN ld a,e inc a jr z,INKEY ld a,d ld hl,SYMTAB cp $18 jr z,aHLSM2 ld hl,CAPSTAB cp $27 jr z,aHLSM2 ld hl,NORMTAB aHLSM2 ld d,0 add hl,de ld a,(hl) or a jr z,INKEY aLAST_KEY ld b,0 cp b jr z,aSEDI_KEY ld b,3 aLOOP_LST halt djnz aLOOP_LST aSEDI_KEY ld (aLAST_KEY+1),a push af call beepk pop af ret INPCLEAR ld de,(INPOS+1) ;do DE pixelová pozice ld c,8 ;16 pixelových řádků na výšku INPC2 ld b,hx ;do B délka řádku inc b ;plus 1 za kurzor xor a ;vynuluj A push de ;ulož adresu začátku řádku INPC3 ld (de),a ;vymaž byty inc de ;v pixelovém djnz INPC3 ;řádku pop de ;obnov adresu počátku call DOWNDE ;a posuň se na další řádek dec c ;odečti jedničku jr nz,INPC2 ;a zbývají-li řádky, opakuj ret CHAR exx add a,a ld l,a sbc a,a ld c,a ld h,15 add hl,hl add hl,hl PPOS ld de,16384 push de ld b,8 CHAR2 ld a,(hl) ;rrca or (hl) xor c ld (de),a call DOWNDE inc hl djnz CHAR2 pop de inc e ld a,e and 31 jr nz,CHAR3 dec e ld a,e ; posun na další tiskovou pozici and %11100000 ld e,a ld b,16 CHAR4 call DOWNDE djnz CHAR4 CHAR3 ld (PPOS+1),de exx ret ; DE .... vstup hledaneho retezce ; HL .... vstup textu,kde budeme hledat ; Výstup: ; Z ... nalezeno ; C .. nenalezeno search ld (search0+1),de search1 ld a,(de) cp "a" jr c,search_next cp "z" jr nc,search_next or a sbc a,32 ld (de),a search_next ld a,(hl) cp "a" jr c,search_next2 cp "z" jr nc,search_next2 or a sbc a,32 ld (hl),a search_next2 ld a,(de) xor 32 ret z ;konec, nasli jsme retezec ld a,(hl) or a jr z,konec_textu ld a,(de) ; res 5,a ; res 5,(hl) xor (hl) jr z,search_jo search0 ld de,0 inc hl jr search1 search_jo inc hl inc de jr search1 konec_textu ld a,1 ;nastav nz - nic jsme nenasli or a ret SF searchfile ld (ssearch0+1),de ld a,(de) or a ret z ;konec, nasli jsme retezec ld a,(hl) or a jr z,skonec_textu ld a,(de) xor (hl) jr z,ssearch_jo ssearch0 ld de,0 inc hl jr searchfile ssearch_jo inc hl inc de jr searchfile skonec_textu ld a,1 ;nastav nz - nic jsme nenasli or a ret ; Porovnava dva reteze o delce 3 byty. ; Vstup: ; HL ... adresa prvniho retezce ; DE ... adresa druheho retezce ; Vystup: ; Z ... souhlasí ; NZ .. nesouhlasí compare ld a,(de) res 7,(hl) xor (hl) ret nz inc hl inc de ld a,(de) res 7,(hl) xor (hl) ret nz inc hl inc de ld a,(de) res 7,(hl) xor (hl) ret CountMemory ld de,13*(pocetpolozek-1) Count11 ld hl,catbuff add hl,de ld (Count11+1),hl ret savehl defw 0 saveix defw 0 ESXDOS MACRO service? : push hl : pop ix : rst $08 : db service? : ENDM ; copies HL into IX ; Read NextReg into A (does modify A, and NextReg selected on the I/O port) ; is not optimized for speed + restores BC MACRO NEXTREG2A register? ld a,register? call ReadNextReg ENDM txtWait defb "Please wait:",0 txtShrek defb "Main program: Shrek/MB Maniax",0 txtPress defb " Press any key to continue",0 txtBorik defb "AY play rutines: mborik/SinDiKat",0 txtThanks defb "Big thanks: ped7g, z00m, Logout",0 txtVersion defb "0.61",0 demo: di F_OPEN equ $9A FA_READ equ $01 F_READ equ $9D F_CLOSE equ $9B M_GETERR equ $93 next_register_select equ $243b nxr_peripheral2 equ $06 ld hl,22528 ld de,22529 ld a,7 ld (hl),a ld bc,767 ldir ld hl,screen ld de,16384 ld bc,2048 ldir ld de,18464+2 ld hl,txtWait call print ld hl, 18496+2 ld bc,4*256+28 ld a,%00000101 call RAMECEK ld de,18528+4 ld hl,txtStart call print ld de,20544+3 ld hl,txtShrek call print ld de,20576+3 ld hl,txtBorik call print ld de,20608+3 ld hl,txtThanks call print ld de,16480+28 ld hl,txtVersion call print ld hl,0 ld de,18528+24 ld (NUMPOS+1),de call DEC16 defw 20*256 ld hl,22528+13 + 32*18 ld b,15 podbarvi ld (hl),%01000111 inc hl djnz podbarvi ld hl,22528+15 + 32*19 ld b,15 podbarvi1 ld (hl),%01000111 inc hl djnz podbarvi1 ld hl,22528+11 + 32*20 ld b,15 podbarvi2 ld (hl),%01000111 inc hl djnz podbarvi2 ld hl,22528 ld b,32*4 podbarvi3 ld (hl),%01000111 inc hl djnz podbarvi3 ld bc,$123b ;nextreg #03,1 nextreg #07,3 ;28MHz - jen kvůli načítání (rychlost) call BUFF83 ld (staksto),sp ;save BASIC's stack pointer ld bc,port1 ;the horizontal ROM switch/RAM ;switch I/O ad dress ld a,(bankm) ;sys tem vari able that holds cur rent ;switch state res 4,a ;move right to left in hor i zon tal ;ROM switch (3 to 2) or 7 ;switch in RAM page 7 ld (bankm),a ;must keep sys tem vari able up to ;date (very im por tant) out (c),a ;make the switch ld sp,mystak ;make sure stack is above 4000h and ;be low BFE0h ei ;in ter rupts can now be en abled ld hl,catbuff ;some where for DOS to put the cata ;log ld de,catbuff+1 ; ld bc,1024 ;max i mum (for +3DOS) is ac tu ally ;64x13+13 = 845 ld (hl),0 ldir ;make sure at least first en try is ld de,catbuff ;the lo ca tion to be filled with the NextDirItem ld b,pocetpolozek ;the num ber of en tries in the ;buffer ld c,%100 ;include sys tem files in the cata ld hl,stardstar ;the file name ("*.*") call dos_catalog ;call the DOS en try ld (savehl),hl ld (saveix),ix ld a,b cp pocetpolozek push af ld hl,(ALLFILES) ld e,b ld d,0 add hl,de dec hl ld (ALLFILES),hl push hl push de push bc ld hl,(dirNum) add hl,de dec hl ld (dirNum),hl ld de,18528+24 ld (NUMPOS+1),de halt call DEC16 defw 20*256 pop bc pop de pop hl ld a,(FILES) add a,b dec a ld (FILES),a pop af jr c,cont nezapisuj ld a,b or a jr z,cont ld a,(virtmem) cp 4 jr z,cont call CountMemory ex de,hl ld hl,virtmem inc (hl) jr NextDirItem cont push af ;save flags and pos si ble er ror num ;ber re turned by DOS ld hl,(dirNum) ld de,18528+24 ld (NUMPOS+1),de halt call DEC16 defw 20*256 pop hl ld (dosret),hl ;put it where it can be seen from ; NextBASIC ld c,b ;move num ber of files in cat a log to ;low byte of BC ld b,0 ;this will be re turned in NextBASIC di ;about to ROM/RAM switch so be ;care ful push bc ;save num ber of files ld bc,port1 ;I/O ad dress of hor i zon tal ROM/RAM ;switch ld a,(bankm) ;get cur rent switch state set 4,a ;move left to right (ROM 2 to ROM ;3) and #F8 ;also want RAM page 0 ld (bankm),a ;up date the sys tem vari able (very ;im por tant) out (c),a ;make the switch pop bc ;get back the saved num ber of files dec bc ld sp,(staksto) ;put NextBASIC's stack back call BUFF83 ld hl,catbuff+13 ld de,(ALLFILES) testovani push de push hl pop ix push ix bit 7,(ix+7) jr nz,souhlasi ld de,8 add hl,de ;v HL je začátek přípony souboru push hl ld de,PT2 call compare pop hl jr z,souhlasi push hl ld de,PT3 call compare pop hl jr z,souhlasi ld de,SQT push hl call compare pop hl jr z,souhlasi ld de,STC push hl call compare pop hl jr z,souhlasi ld de,STP push hl call compare pop hl jr z,souhlasi pop de push de ;v de mame zacatek jmena souboru ld h,d ld l,e add hl,13 ;vynechana jedna polozka ld bc,1260*13 ldir ld hl,(ALLFILES) dec hl ld (ALLFILES),hl pop hl pop de dec de ld a,d or e jr nz,testovani jr skon souhlasi pop hl ld de,13 add hl,de pop de dec de ld a,d or e jr nz,testovani skon ld hl,(ALLFILES) ld (save_allfiles),hl ld de,18560+4 ld hl,txtLFNinfo call print call getAllLFN ld hl,(numLoop) ld de,18560+24 ;pozice ve VideoRam ld (NUMPOS+1),de call DEC16 ;vypiš číso HL - jaký soubor právě spracováváme defw 20*256 ld de,20544+3+32+32 + 32 +32 ld hl,txtPress call print cekej_na_klavesu ld hl,22528+(32*22) ld b,32 brv ld a,0 ld (hl),a inc hl djnz brv ld a,(brv+1) inc a cp 8 jr z,nuluj_barvu jr nenuluj_barvu nuluj_barvu xor a nenuluj_barvu ld (brv+1),a xor a in a,(254) cpl and 31 jr z,cekej_na_klavesu call GETDIR ld hl,16384 ld de,16385 ld bc,6143 xor a ld (hl),a ldir call NOBUFF83 call kresli call INIROLL ld hl,catbuff+#d call WRFILES ;vypis soubory ld de,18464+15 ld hl,txtcurrentfile call print ld de,18432+15 ld hl,txtallfiles call print call LFNWINDOW call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ld de,20544+15 ld hl,lfndir call print ld de,20544+15+3 ld hl,NAZEVADRESARE call print nextreg #07,0 ;3,5MHz nextreg $57,24 ;Nastrankuj od C000 player HLSMYC0 ld hl,(apos_all) inc hl ld de,18464+15+11 ld (NUMPOS+1),de call DEC16 defw 20*256 ld hl,(ALLFILES) ld de,18432+15+11 ld (NUMPOS+1),de call DEC16 defw 20*256 xor a ld (LAST_KEY+1),a ei halt ld a,(endsong) or a jr z,hl0 ld (LAST_KEY+1),a jr SEDI_KEY hl0 call KEYSCAN ld a,e inc a jr z,HLSMYC0 ld a,d ld hl,SYMTAB cp $18 jr z,HLSM2 ld hl,CAPSTAB cp $27 jr z,HLSM2 ld hl,NORMTAB HLSM2 ld d,0 add hl,de ld a,(hl) or a jr z,HLSMYC0 LAST_KEY ld b,0 cp b jr z,SEDI_KEY ld b,1 LOOP_LST halt djnz LOOP_LST SEDI_KEY ld (LAST_KEY+1),a ld (KEY),a call beepk call CH_FILE jr HLSMYC0 ei konec jr konec ret NUM ds 11 DEC16 ld c,' ' DEC16X ld iy,NUM ld de,-10000 call BN1 ld de,-1000 call BN1 DEC8_3 ld de,-100 call BN1 ld e,-10 call BN1 ld e,-1 ld c,'0' call BN1 DEC32SP ld (iy+0),0 ex (sp),hl ld e,(hl) inc hl ld d,(hl) inc hl ex (sp),hl ex de,hl ld hl,NUM NUMPOS ld de,18562+15 jp print BN1 ld a,'0'-1 BN4 add hl,de inc a jr c,BN4 BN2 sbc hl,de cp '0' jr z,BN3 db 1,'0' BN3 ld a,c or a ret z ld (iy+0),a inc iy ret dirNum defw 0 LFNWINDOW ld hl, 20640 ld bc,3*256+32 ld a,%00000111 call RAMECEK ret setspace ld (hl),32 ret ;Nastránkuj buffer s daty adresáře BUFF83 nextreg $54,20 nextreg $55,21 nextreg $56,22 nextreg $57,23 ret NOBUFF83 nextreg $54,04 nextreg $55,05 nextreg $56,00 nextreg $57,01 ret ; Input: HL = Dividend, C = Divisor, A = 0 ; Output: HL = Quotient, A = Remainder deleno xor a ld b,16 de add hl,hl rla cp c jr c,de1 sub c inc l de1 djnz de ret addrlfn dw 0 FINDLFN or a ld de,63 sbc hl,de add hl,de jr c,prvni ld c,63 xor a call deleno jr oddeleno prvni ld a,l ld l,0 oddeleno push af ld a,24 add a,l nextreg $57,a pop bc ld de,maxlen ld a,b or a ld hl,$e000 jr z,prvnizaznam lll add hl,de djnz lll prvnizaznam ld (addrlfn),hl ld de,LFNNAME ld b,maxlen popop ld a,(hl) cp 255 jr z,kon ld (de),a inc hl inc de djnz popop kon ld hl,LFNNAME ld b,40 F22222 ld a,(hl) cp 255 call z,setspace inc hl djnz F22222 lfnend ld hl,LFNNAME lfn_1 ld hl,28 + 20672+2 ld (maxpos),hl lfn_2 ld hl,63 + 20672+2 ld (maxpos2),hl lfnat ld de,20672+2 ld hl,LFNNAME ret LFNPRINT ld hl,LFNNAME ld de,LFNNAME + 1 ld a,32 ld (hl),a ld bc,164 ldir stop ld hl,(apos_all) call FINDLFN ;call p6b nextreg $57,01 ret by1 defb %00000000 defb %01111110 defb %01101010 defb %01010110 defb %01101010 defb %01010110 defb %01111110 defb %00000000 defb %00000000 defb %01111110 defb %01101010 defb %01010110 defb %01101010 defb %01010110 defb %01111110 defb %00000000 defb %00000000 defb %01111110 defb %01101010 defb %01010110 defb %01101010 defb %01010110 defb %01111110 defb %00000000 pozadi push de ld b,8 kr1 push bc push de ld bc,16 ld hl,byte16 ldir pop hl call downhl ex de,hl pop bc djnz kr1 pop de ld b,8 kr2 push bc push de ld bc,16 ld hl,abyte16 lddr pop hl call downhl ex de,hl pop bc djnz kr2 ret byte16 defb %11111111 byte15 defb %11111110 byte14 defb %11111100 byte13 defb %11111000 byte12 defb %11110000 byte11 defb %11100001 byte10 defb %11000011 byte9 defb %10000111 byte8 defb %00011111 byte7 defb %00001111 byte6 defb %00000111 byte5 defb %00000111 byte4 defb %00000011 byte3 defb %00000001 byte2 defb %00000001 byte1 defb %00000000 abyte1 defb %00000000 abyte2 defb %00000001 abyte3 defb %00000001 abyte4 defb %00000011 abyte5 defb %00000111 abyte6 defb %00000111 abyte7 defb %00001111 abyte8 defb %00011111 abyte9 defb %10000111 abyte10 defb %11000011 abyte11 defb %11100001 abyte12 defb %11110000 abyte13 defb %11111000 abyte14 defb %11111100 abyte15 defb %11111110 abyte16 defb %11111111 outputdir defb 0 stardstar: defb "*.???",#FF dosret: defw 0 KEY defb 0 CH_FILE ld a,(KEY) cp "q" jp z,UP cp 11 jp z,UP cp "s" jp z,hledej cp "r" jp z,reload cp "a" jp z,DOWN cp 10 jp z,DOWN cp 9 jp z,right cp 8 jp z,left cp 13 jp z,FIRE cp 32 jp z,nextsong ret txtFilter defb "Search: ",0 savepoc defw 0 actadr defw 0 h1 defw 0 txtFind defb "Search songs.",0 txtFind2 defb "Only chars, without spaces.",0 txtFinded defb "Found:",0 txtLeft defb "Left: ",0 hledej call savescr ld hl,0 ld (nalezeno+1),hl ld hl,0 ld (pozice+1),hl ld hl,(ALLFILES) ld (savepoc),hl ld hl,catbuff+#d ld (actadr),hl ld hl,18464 ld bc,8*256+32 ld a,%00000111 call RAMECEK ld de,18496+1 ld hl,txtFind call print ld de,18528+1 ld hl,txtFind2 call print ld hl,0 ld (pozice+1),hl ld (h1),hl ld hl,13*32+22528+1 ld b,29 po ld (hl),01101000b inc hl djnz po ld hx,28 ;délka vstupu ld hl,18592+1 ;adresa na obrazovce call INPUT ;volej vstupní podprogram cp 7 ;testuj EDIT jp z,end_hledej ld hl,23296 ld de,txtFilter + 8 ld bc,10 ldir ld de,20576+15 ld hl,txtFilter call print ld de,18624+1 ld hl,txtFinded call print ld de,18656+1 ld hl,txtLeft call print ssss nextreg #07,3 ;28MHz - jen kvůli načítání (rychlost) call BUFF83 ld hl,catbuff+13; + 26 ;vynechej první dvě položky ld de,(ALLFILES) htestovani push de push hl push hl push de nalezeno ld hl,0 ld de,18624+5 ;pozice ve VideoRam ld (NUMPOS+1),de call DEC16 ;vypiš číso HL - jaký soubor právě spracováváme defw 20*256 ld hl,(h1) inc hl ld (h1),hl ld hl,(ALLFILES) ld de,18656+5 ;pozice ve VideoRam ld (NUMPOS+1),de call DEC16 ;vypiš číso HL - jaký soubor právě spracováváme defw 20*256 ld hl,LFNNAME ld de,LFNNAME+1 xor a ld (hl),a ld bc,128 ldir pop de pop hl pozice ld hl,0 push hl call FINDLFN pop hl inc hl ld (pozice+1),hl ld de,23296 ld hl,LFNNAME call search jr z,hsouhlasi ; pop de ; push de ;v de mame zacatek jmena souboru ; ld h,d ; ld l,e ; add hl,13 ;vynechana jedna polozka ; ld hl,(actadr) ; ex de,hl ; ld bc,13 ;1260*13 ; ldir ld hl,(ALLFILES) dec hl ld (ALLFILES),hl pop hl ld de,13 add hl,de pop de dec de ld a,d or e jr nz,htestovani jr hkon hsouhlasi ld hl,(nalezeno+1) inc hl ld (nalezeno+1),hl ld hl,(actadr) ld de,vymenafile ld bc,13 ldir ;ulož soubor, co bude vymazany ld hl,(actadr) pop de push de ex de,hl ld bc,13 ldir ;nahrad pop de push de ld hl,vymenafile ld bc,13 ldir ld hl,(actadr) ld de,13 add hl,de ld (actadr),hl pop hl ld de,13 add hl,de pop de dec de ld a,d or e jp nz,htestovani hkon call GETDIR ld hl,(ALLFILES) ld a,h or l jp z,nula ld hl,18624+5 ld (lfnpos+1),hl call getAllLFN ld hl,18560+24 ld (lfnpos+1),hl ld hl,0 ld (apos_all),hl xor a ld (POS_F + 1),a ld hl,catbuff+#d ld (WRBUFF+1),hl call kresli ;call loadscr ld hl,16416 ld bc,20*256+14 ld a,%00001111 call RAMECEK call BUFF83 call WRFILES ld de,18464+15 ld hl,txtcurrentfile call print ld de,18432+15 ld hl,txtallfiles call print ld de,20576+15 ld hl,txtFilter call print TISK ld de,20544+15 ld hl,lfndir call print ld de,20544+15+3 ld hl,NAZEVADRESARE call print call LFNWINDOW call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print nextreg #07,0 ;3,5 MHz ret vymenafile ds 13 nula ld hl,18496 ld bc,6*256+32 ld a,%00000111 call RAMECEK ld de,18562+8-32 ld hl,nulatxt call print ; ld de,18560+7 ; ld hl,reloadtxt ; call print ld de,18624+6 ld hl,presstxt call print ld hl,(savepoc) ld (ALLFILES),hl nula1 halt XOR A ;test keyboard IN A,(#FE) CPL AND 15 JR Z,nula1 XOR A ;test keyboard IN A,(#FE) CPL AND 15 JR Z,nula1 call loadscr nextreg #07,0 ;3,5 MHz ret jp reload nulatxt defb "Nothing found!",0 reloadtxt defb "I must reload directory!",0 presstxt defb "Press any key to continue.",0 end_hledej call loadscr ;návrat pomocí klávesy EDIT ret templfn ds 129 ;Posunutí o stránku výše - šipka doleva left ld hl,(apos_all) ld a,h or l ret z ;skončí, pokud jsme na nultém souboru ld a,(POS_F+1) or a jr z,next_page_left ld a,(POS_F+1) ld c,%00001111 call KURZOR ;smaž kurzor ld a,(POS_F+1) ld e,a ld d,0 ld hl,(apos_all) or a sbc hl,de ld (apos_all),hl xor a ld (POS_F+1),a ld c,%00010111 call KURZOR call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret next_page_left ld hl,(apos_all) ld de,17 or a sbc hl,de jr c,next_left1 ;méně než 17 ld (apos_all),hl ld b,13 call mull ld de,catbuff+13 add hl,de ld (WRBUFF+1),hl call WRFILES call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret next_left1 ld hl,0 ld (apos_all),hl ld hl,catbuff+13 ld (WRBUFF+1),hl call WRFILES call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret ; Posunutí o stránku níž - šipka doprava right ld hl,(ALLFILES) dec hl ld e,17 ld d,0 or a sbc hl,de add hl,de jp c,posledni ld a,(POS_F+1) cp 17 jp z,next_page ld a,(POS_F+1) ;na konec stránky push af ld c,%00001111 call KURZOR ld a,17 ld (POS_F+1),a ld hl,(apos_all) pop bc push af ld a,17 or a sbc a,b ld e,a ld d,0 add hl,de ld (apos_all),hl ld c,%00010111 pop af call KURZOR call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret reload_dir di call BUFF83 ld hl,#8000 ld de,#8001 ld bc,1024 xor a ld (hl),a ldir ld bc,port1 ;the horizontal ROM switch/RAM ;switch I/O ad dress ld a,(bankm) ;sys tem vari able that holds cur rent ;switch state res 4,a ;move right to left in hor i zon tal ;ROM switch (3 to 2) or 7 ;switch in RAM page 7 ld (bankm),a ;must keep sys tem vari able up to ;date (very im por tant) out (c),a ;make the switch ;be low BFE0h ei ;in ter rupts can now be en abled ld hl,catbuff ;some where for DOS to put the cata ;log ld de,catbuff+1 ; ld bc,1024 ;max i mum (for +3DOS) is ac tu ally ;64x13+13 = 845 ld (hl),0 ldir ;make sure at least first en try is ld de,catbuff ;the lo ca tion to be filled with the aNextDirItem ld b,pocetpolozek ;the num ber of en tries in the ;buffer ld c,%100 ;include sys tem files in the cata ld hl,stardstar ;the file name ("*.*") call dos_catalog ;call the DOS en try NEXT0 ld (savehl),hl ld (saveix),ix ld a,b cp pocetpolozek push af ld hl,(ALLFILES) ld e,b ld d,0 add hl,de dec hl ld (ALLFILES),hl push hl push de push bc ld hl,(dirNum) add hl,de dec hl ld (dirNum),hl ld de,18528+24 ld (NUMPOS+1),de call DEC16 defw 20*256 pop bc pop de pop hl ld a,(FILES) add a,b dec a ld (FILES),a pop af jr c,acont ld a,b or a jr z,acont ld a,(virtmem) cp 4 jr z,acont call CountMemory ex de,hl ld hl,virtmem inc (hl) jr aNextDirItem acont push af ld hl,(dirNum) ld de,18528+24 ld (NUMPOS+1),de halt call DEC16 defw 20*256 pop hl ld (dosret),hl ;put it where it can be seen from ; NextBASIC ld c,b ;move num ber of files in cat a log to ;low byte of BC ld b,0 ;this will be re turned in NextBASIC di ;about to ROM/RAM switch so be ;care ful push bc ;save num ber of files ld bc,port1 ;I/O ad dress of hor i zon tal ROM/RAM ;switch ld a,(bankm) ;get cur rent switch state set 4,a ;move left to right (ROM 2 to ROM ;3) and #F8 ;also want RAM page 0 ld (bankm),a ;up date the sys tem vari able (very ;im por tant) out (c),a ;make the switch pop bc ;get back the saved num ber of files dec bc call BUFF83 JKJK ld hl,catbuff+13 ld de,(ALLFILES) ld (save_allfiles),de ; dec de atestovani push de push hl pop ix push ix bit 7,(ix+7) ; pop hl jr nz,asouhlasi ld de,8 add hl,de ;v HL je začátek přípony souboru push hl ld de,PT2 call compare pop hl jr z,asouhlasi push hl ld de,PT3 call compare pop hl jr z,asouhlasi ld de,SQT push hl call compare pop hl jr z,asouhlasi ld de,STC push hl call compare pop hl jr z,asouhlasi ld de,STP push hl call compare pop hl jr z,asouhlasi pop de push de ;v de mame zacatek jmena souboru ld h,d ld l,e add hl,13 ;vynechana jedna polozka ld bc,910*13 ldir ld hl,(ALLFILES) dec hl ld (ALLFILES),hl pop hl pop de dec de ld a,d or e jr nz,atestovani jr askon asouhlasi pop hl ld de,13 add hl,de pop de dec de ld a,d or e jr nz,atestovani askon ei ld de,18560+4 ld hl,txtLFNinfo call print call getAllLFN call GETDIR ld hl,16384 ld de,16385 ld bc,6143 xor a ld (hl),a ldir call NOBUFF83 call kresli ld hl,catbuff+#d ld (WRBUFF+1),hl call WRFILES ;vypis soubory ld de,18464+15 ld hl,txtcurrentfile call print ld de,18432+15 ld hl,txtallfiles call print ld de,20544+15 ld hl,lfndir call print ld de,20544+15+3 ld hl,NAZEVADRESARE call print call LFNWINDOW call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret next_page ld hl,(apos_all) inc hl ;test jestli už není víc souborů ex de,hl ;de ... aktualni pozice začátku výpisu ld hl,(ALLFILES) ;hl ... pocet souboru push de ld de,18 ;odečti počet na jednu stránku or a sbc hl,de ;hl ... počet souborů - 18 pop de ;de ... aktuální pozice or a sbc hl,de jr nc, next2 ld hl,(ALLFILES) or a ld de,17 sbc hl,de ld a,1 ld (maxfile),a jr next3 next2 ld hl,(apos_all) inc hl xor a ld (maxfile),a next3 ld b,13 call mull ld de,catbuff ;+13 add hl,de ld (WRBUFF+1),hl call WRFILES ld a,(maxfile) or a jr nz,next4 ld hl,(apos_all) ld de,17 add hl,de ld (apos_all),hl jr next5 next4 ld hl,(ALLFILES) dec hl ld (apos_all),hl next5 call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret maxfile db 0 posledni ;méně souborů než 17 ld a,(POS_F+1) ld c,%00001111 call KURZOR ld hl,(ALLFILES) dec hl ld a,l ld (POS_F+1),a ld (apos_all),hl ld c,%00010111 call KURZOR call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret right1 ret txtLFNinfo defb "Getting LFN information:",0 txtStart defb "Reading files in directory:",0 ;Nacte LFN vsech souboru nahranych v pameti numLoop defw 0 ; Násobení HL x B ; Vysledek HL mull ld d,l ;vynásob spodní byty ld e,b ; mul d,e ;vysledek je v de ex de,hl ;vysledek je v hl ld e,b ;násobitel do e mul d,e ;vynásob ld a,e ;do akumulátoru hoď výsledek (spodní byte) add a,h ld h,a ;konečný výsledek je v HL ret ; Tato rutina naplní banky ZX Next LFN jmény souborů, ; o délce 128bytů. getAllLFN ei ld hl,0 ld (numLoop),hl ld hl,#e000 ld (InBuff+1),hl ld a,24 ld (Page+1),a call savescr call BUFF83 ld hl,catbuff+#d ld de,bufftmp ld bc,13 ldir call NOBUFF83 ld hl,catbuff+#d ld (tmpname),hl ld bc,(ALLFILES) LFN1 push bc ei ld hl,(numLoop) inc hl ld (numLoop),hl lfnpos ld de,18560+24 ;pozice ve VideoRam ld (NUMPOS+1),de call DEC16 ;vypiš číso HL - jaký soubor právě spracováváme defw 20*256 di ;zakaž přerušení, jinak bude problém, nemáme nastránkovanou ZX Rom exx BFN BufferName ld de,bufftmp ;jmeno souboru ld hl,stardstar ld ix,(savehl) ld bc,LFNNAME exx ld c,7 ld de,$01b7 rst 8 ;služba EsxDosu, která volá službu +3Dosu (zjištění LFN konkrétního souboru) defb M_P3DOS Page ld a,24 nextreg $57,a ;nastrankuj stranku s volnymi daty InBuff ld de,#e000 ;ukazatel na pamet v bufferu ld hl,LFNNAME ;buffer pro LFN ld bc,maxlen ;ulož 64 bytů ldir call BUFF83 ld hl,(tmpname) ;přesuň se na další položku v adresáři ld de,13 add hl,de ld (tmpname),hl ;a ulož adresu, kde se nachází ld de,bufftmp ld bc,13 ldir call NOBUFF83 ld a,(Page+1) nextreg $57,a ld hl,(InBuff+1) ;vypočti další adresu v bance ZX Next, kam budu ukládat ld de,maxlen add hl,de ld (InBuff+1),hl ld de,#FFFF-128 or a sbc hl,de jr c,contin ld hl,Page+1 inc (hl) ld hl,#e000 ld (InBuff+1),hl contin pop bc ;zopakuj to pro všechny soubory, které máme načtené... dec bc ld a,b or c jr nz,LFN1 nextreg $57,1 ;vráť zpátky stránku, kde se nachází data pro player call loadscr ;obnov obrazovku ret tmpname ds 2 BFT bufftmp ds 15 M_P3DOS equ $94 reload nextreg #07,3 ;28MHz - jen kvůli načítání (rychlost) ld hl, 18496+2 ld bc,4*256+28 ld a,%00000101 call RAMECEK ld de,18528+4 ld hl,txtStart call print ld hl,0 ld (ALLFILES),hl ld (dirNum),hl ld (apos_all),hl xor a ld (POS_F+1),a ld (virtmem),a ld hl,catbuff ld (Count11+1),hl ; ld hl,(save_allfiles) ; ld (ALLFILES),hl call reload_dir ; ld de,18560+4 ; ld hl,txtLFNinfo ; call print ; call getAllLFN ; ld hl,16384 ; ld de,16385 ; ld bc,6143 ; xor a ; ld (hl),a ; ldir ; call NOBUFF83 ; call kresli ; ld hl,catbuff+#d ; ld (WRBUFF+1),hl ; call WRFILES ;vypis soubory ; ld de,18464+15 ; ld hl,txtcurrentfile ; call print ; ld de,18432+15 ; ld hl,txtallfiles ; call print ; call LFNWINDOW ; call LFNPRINT ; ld hl,LFNNAME + maxline ; ld (hl),0 ; ld hl,LFNNAME ; ld de,20672+2 ; call print nextreg #07,0 ;3,5 Mhz ret DIRNAME defs 13 defb 255 DIRTMP defb "C:",255 ds 10 NAZEVADRESARE ds 20 GETDIR ld hl,DIRTMP ld de,modstart ld bc,4 ldir ld bc,port1 ld a,(bankm) ;sys tem vari able that holds cur rent res 4,a ;move right to left in hor i zon tal or 7 ;switch in RAM page 7 ld (bankm),a ;must keep sys tem vari able up to out (c),a ;make the switch ld a,1 ;get path ld hl,modstart call $01b1 jr c,ok1 EEEE ld a,2 out (254),a ok1 ld bc,port1 ;I/O ad dress of hor i zon tal ROM/RAM ld a,(bankm) ;get cur rent switch state set 4,a ;move left to right (ROM 2 to ROM and #F8 ;also want RAM page 0 ld (bankm),a ;up date the sys tem vari able (very out (c),a ;make the switch ld hl,modstart ld bc,1024 ld a,#ff cpir AAA dec hl dec hl dec hl push hl ld hl,DIRBUFF ld de,DIRBUFF+1 ld bc,13 ld a,32 ld (hl),a ldir pop hl pr1 ld a,(hl) cp "/" jr z,pr0 cp ":" jp z,root dec hl jr pr1 pr0 inc hl ld de,DIRBUFF ld b,8 presun ld a,(hl) cp "/" jr z,prk ld (de),a inc de inc hl djnz presun prk ld hl,DIRBUFF ld bc,7 ld a,"." cpir jr nz,PRK2 push hl ld de,DIRBUFF+8 ld bc,4 ldir PRK0 pop hl ;adresa s teckou v HL dec hl push hl ex de,hl ;je v DE ld hl,DIRBUFF+7 ;az kam or a sbc hl,de push hl pop bc ;počet bytu pop hl ld d,h ld e,l inc de ld a,32 ld (hl),a ldir PRK2 xor a ld hl,DIRBUFF+11 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a ld hl,DIRBUFF+7 set 7,(hl) ld hl,parrent ld (goto+1),hl ;call gotodir ld bc,port1 ld a,(bankm) res 4,a or 7 ld (bankm),a out (c),a xor a ld hl,parrent call $01b1 ;skoc do nadrizeneho adresare nextreg $54,22 nextreg $55,23 ld hl,32768 ld (FF+1),hl xor a ld (virtmem),a FF ld de,32768 ld b,pocetpolozek ld hl,stardstar ld c,%100 call dos_catalog ld a,pocetpolozek xor b jr nz,PRK4 ld hl,(FF+1) ld de,pocetpolozek*13 add hl,de ld (FF+1),hl ld hl,virtmem inc (hl) ld a,(hl) xor 4 jr z,PRK4 jr FF PRK4 ld de,DIRBUFF ;jmeno souboru ld hl,stardstar ld ix,(savehl) ld bc,LFNNAME call $01b7 ;skoc zpatky do adresare ld hl,DIRBUFF+7 res 7,(hl) ld a,255 ld (DIRBUFF+11),a ld hl,DIRBUFF xor a call $01b1 ; ld hl,32768 ; ld (FF2+1),hl ;FF2 ld de,32768 ; ld b,pocetpolozek ; ld hl,stardstar ; ld c,%101 ; call dos_catalog ;call the DOS en try ; ld a,pocetpolozek ; xor b ; jr nz,PRK40 ; ld hl,(FF+1) ; ld de,pocetpolozek*13 ; add hl,de ; ld (FF2+1),hl ; jr FF2 ; PRK40 ld bc,port1 ld a,(bankm) set 4,a and #F8 ld (bankm),a out (c),a PRK5 ld hl,LFNNAME ld bc,128 ld a,#ff cpir dec hl ld (hl),0 xor a ld (LFNNAME+15),a ld de,20544+15 ld hl,lfndir call print ld a,32 ld (LFNNAME-1),a ld de,20544+15+3 ld hl,LFNNAME-1 ;call print ld hl,LFNNAME-1 ld de,NAZEVADRESARE ld bc,20 ldir ld hl,DIRBUFF ld (goto+1),hl ld a,255 ld (DIRBUFF+11),a ld hl,DIRBUFF+7 res 7,(hl) ; call gotodir ret GOTODIR gotodir ld bc,port1 ld a,(bankm) res 4,a or 7 ld (bankm),a out (c),a xor a goto ld hl,parrent call $01b1 jr c,gok ld a,2 out (254),a gok ld bc,port1 ld a,(bankm) set 4,a and #F8 ld (bankm),a out (c),a ret testpolozky defb "A~1 ",#a0,"POP",0,0 parrent defb "..",#ff lfndir defb "Dir:", 0 root ld a,32 ld (LFNNAME),a ld a,"/" ld (LFNNAME+1),a xor a ld (LFNNAME+2),a ld de,20544+15 ld hl,lfndir call print ld hl,LFNNAME ld de,NAZEVADRESARE ld bc,20 ldir ret DIRBUFF ds 15 CHANGEDIR nextreg #07,3 ;28MHz - jen kvůli načítání (rychlost) push hl ld hl, 18496+2 ld bc,4*256+28 ld a,%00000101 call RAMECEK ld de,18528+4 ld hl,txtStart call print ld hl,0 ld (ALLFILES),hl ld (dirNum),hl ld (apos_all),hl xor a ld (POS_F+1),a ld (virtmem),a ld hl,catbuff ld (Count11+1),hl ld hl,0 ld (ALLFILES),hl pop hl call BUFF83 ld ix,DIRNAME ld b,13 chngdir1 ld a,(hl) res 7,a or a jr nz,chng ld a,32 chng ld (ix+0),a inc hl inc ix djnz chngdir1 STOP ld hl,DIRNAME+11 chng2 ld a,(hl) cp 32 jr nz,zap dec hl jr chng2 zap ld a,255 inc hl ld (hl),a ld bc,port1 ld a,(bankm) ;sys tem vari able that holds cur rent res 4,a ;move right to left in hor i zon tal or 7 ;switch in RAM page 7 ld (bankm),a ;must keep sys tem vari able up to out (c),a ;make the switch xor a ;change path ld hl,DIRNAME AAAA call $01b1 jr c,ok ERROR ld a,2 out (254),a ok ld bc,port1 ;I/O ad dress of hor i zon tal ROM/RAM ld a,(bankm) ;get cur rent switch state set 4,a ;move left to right (ROM 2 to ROM and #F8 ;also want RAM page 0 ld (bankm),a ;up date the sys tem vari able (very out (c),a ;make the switch call reload_dir ; call GETDIR nextreg #07,0 ret txtsetup defb "Configuration",0 txtstereo defb "Stereo: ACB / ABC",0 txtchip defb "Sound chip: AY / YM",0 txthelp0 defb "Controls:",0 txthelp1 defb "Break: stop play | Space: next song",0 txthelp2 defb " A: AY | Y: YM | C: ACB | B: ABC ",0 vyrazni equ 01000111b showsetup NEXTREG2A 06 bit 0,a ;AY jr nz,sAY ld a,vyrazni ld hl,22528+32*4 + 21 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a ld a,%00000001 ld hl,22528+32*4 + 15 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a jr stereo sAY ld a,%00000001 ld hl,22528+32*4 + 21 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a ld a,vyrazni ld hl,22528+32*4 + 15 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a stereo NEXTREG2A 08 bit 5,a jr nz,sACB ld a,vyrazni ld hl,22528+32*3 + 21 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a ld a,%00000001 ld hl,22528+32*3 + 15 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a ret sACB ld a,%00000001 ld hl,22528+32*3 + 21 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a ld a,vyrazni ld hl,22528+32*3 + 15 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a ret ;Skok na další skladbu nextsong call DOWN ;Stisk klávesy ENTER. FIRE nextreg #07,3 call savescr ld a,(POS_F+1) ld e,a ld d,0 ld hl,(apos_all) add hl,de ld a,l or h ld hl,catbuff+#D jr z,F1 ld hl,(apos_all) ld b,h ld c,l ld de,13 ld hl,catbuff+#D F0 add hl,de dec bc ld a,c or b jr nz,F0 F1 push hl pop ix call BUFF83 bit 7,(ix+7) jp nz,CHANGEDIR push hl ld hl,18496 ld bc,7*256+32 ld a,%00000111 call RAMECEK ld hl,20480 ld bc,4*256+32 ld a,%00000101 call RAMECEK ld hl,16416+5 ld bc,5*256+22 ld a,%00000111 call RAMECEK ld hl,16576+1 ld bc,4*256+30 ld a,%00000101 call RAMECEK ; ld de,16576+3 ; ld hl,txthelp0 ; call print ld de,16608+3 ld hl,txthelp1 call print ld de,18432+3 ld hl,txthelp2 call print ld hl,22528 + 32*7 + 2 ld a,7 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a ld hl,22528 + 32*7 + 17 ld a,7 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a ld hl,22528 + 32*8 + 4 ld a,7 ld (hl),a inc hl ld (hl),a ld hl,22528 + 32*8 + 10 ld a,7 ld (hl),a inc hl ld (hl),a ld hl,22528 + 32*8 + 16 ld a,7 ld (hl),a inc hl ld (hl),a ld hl,22528 + 32*8 + 22 ld a,7 ld (hl),a inc hl ld (hl),a ld de,16448+6 ld hl,txtsetup call print ld hl,22528+32*2 + 6 ld a,101b ;ld a,255 ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a ld de,16480+6 ld hl,txtstereo call print ld de,16512+6 ld hl,txtchip call print call showsetup ld hl,22528+32*18+1 ld d,h ld e,l inc de ld a,7 ld (hl),a ld bc, 28 ldir ; ld hl,18592+2 ; ld (lfnat+1),hl ; ld hl,28 + 18592+2 ; ld (lfn_1 + 1),hl ; ld hl,28 + 18624+21 ; ld (lfn_2 + 1),hl ; ld hl,LFNNAME+128 ; ld (lfnend+1),hl ; ld hl,4 ; ld (odskok+1),hl call LFNPRINT ld hl,tmp ld de,tmp+1 xor a ld (hl),a ld bc,48 ldir ld hl,LFNNAME ld de,tmp ld bc,maxline ldir ld de,18560+2 ld hl,tmp call print ;************************** ld hl,tmp ld de,tmp+1 xor a ld (hl),a ld bc,48 ldir ld hl,LFNNAME+maxline ld de,tmp ld bc,maxline ldir ld de,18592+2 ld hl,tmp call print ;**************************** ld hl,tmp ld de,tmp+1 xor a ld (hl),a ld bc,48 ldir ld hl,LFNNAME+maxline+maxline ld de,tmp ld bc,maxline ldir ld de,18624+2 ld hl,tmp call print ld hl,12*32+22528+1 ld de,12*32+22528+2 ld bc,29 ld (hl),%01000111 ldir ld hl,13*32+22528+1 ld de,13*32+22528+2 ld bc,29 ld (hl),%01000111 ldir ld hl,14*32+22528+1 ld de,14*32+22528+2 ld bc,29 ld (hl),%01000111 ldir ld de,20672+2 ld (lfnat+1),de ld hl,28 + 20672+2 ld (lfn_1 + 1),hl ld hl,33 + 20672+2 ld (lfn_2 + 1),hl ld hl,LFNNAME+37 ld (lfnend+1),hl pop de ; v DE je nazev souboru call NOWRMOD ld de,18560+8-32+3 ld hl,text call print call LOADFile nextreg $57,1 ld hl,filename+9 ld de,PT2 call compare jp z,playmusic ld hl,filename+9 ld de,PT3 call compare jp z,playmusic ld hl,filename+9 ld de,SQT call compare jp z,SQTPLAY ld hl,filename+9 ld de,STC call compare jp z,STCPLAY ld hl,filename+9 ld de,STP call compare jp z,STPPLAY ld a,32 ld hl,endsong ld (hl),a ; jp playmusic navrat halt call loadscr ret tmp ds 49 PT2 defb "PT2" PT3 defb "PT3" SQT defb "SQT" STC defb "STC" STP defb "STP" endsong defb 0 Loading defb "Plase wait, loading file...",0 ; Nahrání souboru pomocí EsxDos služeb. Rutina nemá žádný vstup, ; vše si zjišťuje z proměnných (na adrese filename je již připravený název souboru) LOADFile nextreg #07,3 ;28MHz - jen kvůli načítání (rychlost) ld hl, 20640 ld bc,3*256+32 ld a,%00000010 call RAMECEK ld de,20672+2 ld hl,Loading call print ld b,FA_READ ld a,'*' ld hl,filename ESXDOS F_OPEN ld (fread+1),a ld hl,modstart ld de,modstart+1 ld bc,22048 ld a,255 ld (hl),a ldir ld hl,modstart ld bc,22048 call fread call fclose ld hl,modstart + 17000 hledej_konec_souboru ld a,(hl) cp 255 jr nz,nasel dec hl jr hledej_konec_souboru nasel ld (delka_souboru),hl nextreg #07,0 ;28MHz - jen kvůli načítání (rychlost) ret fclose ld a,(fread+1) ESXDOS F_CLOSE ret fread: ld a,1 ESXDOS F_READ ret nc fileError: push af and 7 out (254),a pop af ld b,1 ld de,esxError ESXDOS M_GETERR ld hl,esxError jp customErrorToBasic switchLayer2Off: ret ;Uloží obrazovku do banky 19 ZX Next. Ukládají se spodní dvě třetiny obrazovky, ;a celé atributy. Banka 19 se stránkuje od adresy $e000 savescr nextreg $57,19 ;Stránka na uložení VideoRam ld hl,16384 ld de,bufscr ld bc,6912 ldir nextreg $57,1 ;Nastránkuj zpátky ret ;Obnovení spodních dvou třetin obrazovky z 19 stárnky ZX Next. loadscr nextreg $57,19 ld hl,bufscr ld de,16384 ld bc,6912 ldir nextreg $57,1 ret customErrorToBasic: ; HL = message with |80 last char ld a,1 out (254),a ret keysound db 0 ;key sound 0= yes,1= no, klavesnicove echo ;KeyScan od Busyho z MRSu KEYSCAN ld l,47 ;testovani klavesnice ld de,65535 ld bc,65278 KEYLINE in a,(c) cpl and 31 jr z,KEYDONE ld h,a ld a,l KEY3KEYS inc d ret nz KEYBITS sub 8 srl h jr nc,KEYBITS ld d,e ld e,a jr nz,KEY3KEYS KEYDONE dec l rlc b jr c,KEYLINE ld a,d inc a ret z cp 40 ret z cp 25 ret z ld a,e ld e,d ld d,a cp 24 ret SYMTAB db "*^[&%>}/" db ",-]'$<{?" db ".+($" db 200 db '/',' ' db 0 db "=;)@" db 201 db "|:" db 32,13,34 db "_!" db 199 db "~",0 CAPSTAB db "BHY" db 10,8 db "TGV" db "NJU" db 11,5 db "RFC" db "MKI" db 9,4 db "EDX" db 2 db "LO" db 15,6 db "WSZ" db 1,13,"P" db 12,7 db "QA" NORMTAB db "bhy65tgv" db "nju74rfc" db "mki83edx" db 0 db "lo92wsz" db 32,13 db "p01qa" db 0 beepk ld a,(keysound) ;Busyho nahradni rutina,kratsi or a ret nz ld a,(BORDER) ld e,a ld b,$10 add a,b ; ld a,$10+border out ($fe),a ld b,$1c beepk1 djnz beepk1 ld a,$08 add a,e ; ld a,$08+border out ($fe),a ret BORDER db 0 ;okraj ;Pohyb nahoru - na pozici kurzoru se používa 16bitové číslo, ;takže maximální počet souboru je omezen, ale prakticky se k ;němu ani nepřiblížíme. ;Při scrolování se vypisuje jen spodní řádek, jinak se volá ;rutinka ROLLDOWN, která provede scroll o 8 pixelů dolů. Je to rychlejší, ;než vypisovat všechny soubory znova. UP POS_F ld a,0 or a jp z,UP1 ld hl,(apos_all) ld a,h or l jp z,UP1 ld c,%00001111 ld a,(POS_F+1) call KURZOR ld hl,(apos_all) dec hl ld (apos_all),hl dec a ld (POS_F+1),a ld c,%00010111 call KURZOR call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret UP1 POS_ALL ld a,0 ;or a ;ret z ;dec a ;ld (POS_ALL+1),a ld hl,(apos_all) ld a,l or h ret z dec hl ld (apos_all),hl push af call ROLLDOWN pop af ld hl,16448+1 call PRN_F call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret DOWN ld hl,(ALLFILES) dec hl ld e,17 ld d,0 or a sbc hl,de ld c,l jp c,D1 ld c,17 D1 ld a,(POS_F+1) cp c jp z,DOWN1 ld e,a ld d,0 ld hl,(ALLFILES) dec hl or a sbc hl,de ret z ld c,%00001111 call KURZOR inc a ld (POS_F+1),a ld hl,(apos_all) inc hl ld (apos_all),hl ld c,%00010111 call KURZOR call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret apos_all defw 0 DOWN1 ld hl,(apos_all) ;dec hl ex de,hl ld hl,(ALLFILES) dec hl ex de,hl or a sbc hl,de ret z ;maximum souboru ld hl,(apos_all) ;dec hl ex de,hl ld hl,(ALLFILES) dec hl ex de,hl or a sbc hl,de ex de,hl ld hl,(apos_all) or a sbc hl,de ret z ld a,(POS_ALL+1) inc a ld (POS_ALL+1),a ld hl,(apos_all) inc hl ld (apos_all),hl push af call ROLLUP pop af ld c,a ld a,(POS_F+1) add a,c ld hl,20576+1 call PRN_F call LFNPRINT ld hl,LFNNAME + maxline ld (hl),0 ld hl,LFNNAME ld de,20672+2 call print ret ;Font na vykreslování rámečků SPECFNT defw 32512 defw 30079 defw 28768 defw 28768 defw 65280 defw 22015 defw 0 defw 0 defw 65024 defw 22270 defw 1550 defw 1550 defw 28768 defw 28768 defw 28768 defw 28768 defw 0 defw 0 defw 0 defw 0 defw 1550 defw 1550 defw 1550 defw 1550 defw 28768 defw 32618 defw 30079 defw 28768 defw 0 defw 65450 defw 22015 defw 0 defw 1550 defw 65198 defw 22270 defw 1550 defw 28768 defw 28768 defw 32618 defw 127 defw 0 defw 0 defw 65450 defw 255 defw 1550 defw 1550 defw 65198 defw 254 defb 0,85,0,85,0,85,0 defb 0 DOWNHL inc h ld a,h and 7 ret nz ld a,l add a,32 ld l,a ld a,h ret c sub 8 ld h,a ret DOWNH ld a,l add a,32 ld l,a ld a,h ret nc add a,2048/256 ld h,a ret ;Rutinka na vypsání jednoho znaku 8bitovým fontem. ; Vstup: ; A ... znak ; Pozice se určuje návěstím P_AT PRINT exx ld l,a ld h,0 add hl,hl add hl,hl add hl,hl FNT ld bc,CHARS add hl,bc P_AT ld de,16384 push de ld a,(hl) ld (de),a inc hl inc d ld a,(hl) ld (de),a inc hl inc d ld a,(hl) ld (de),a inc hl inc d ld a,(hl) ld (de),a inc hl inc d ld a,(hl) ld (de),a inc hl inc d ld a,(hl) ld (de),a inc hl inc d ld a,(hl) ld (de),a inc hl inc d ld a,(hl) ld (de),a pop de inc e jr nz,CHAR1B ld a,d add a,8 ld d,a cp 88 jr c,CHAR1B ld d,64 CHAR1B ld (P_AT+1),de exx ret ; Vykreslení rámečku ; Vstup: ;hl=adrvrm ;bc,vyska * 256 + sirka ;a=barva RAMECEK push af push hl push bc ld (P_AT+1),hl dec c dec c push hl ld hl,SPECFNT ld (FNT+1),hl push bc ld a,0 call PRINT ld b,c RAM1 ld a,1 call PRINT djnz RAM1 ld a,2 call PRINT pop bc pop hl dec b dec b call DOWNH ld (P_AT+1),hl RAM3 push hl push bc ld a,3 call PRINT ld b,c RAM2 ld a,4 call PRINT djnz RAM2 ld a,5 call PRINT pop bc pop hl call DOWNH ld (P_AT+1),hl djnz RAM3 ld a,9 call PRINT ld b,c RAM4 ld a,10 call PRINT djnz RAM4 ld a,11 call PRINT ld hl,CHARS ld (FNT+1),hl pop bc pop hl ld a,h sub 64 rrca rrca rrca and 3 add a,88 ld h,a dec c pop af ATRR push bc push hl ld d,h ld e,l inc e ld b,0 ld (hl),a ldir pop hl ld de,32 add hl,de pop bc djnz ATRR ret tcursor defb "Cursors: move",0 tenter defb "Enter: play song",0 tspace defb "Space: play next",0 tsearch defb "S: search",0 treload defb "R: reload directory",0 ; Nakreslí všechny okna potřebné pro NextPlayer kresli: ld hl,16416 ld bc,20*256+14 ld a,%00001111 call RAMECEK ld hl,16608+14 ld bc,14*256+18 ld a,%00001111 call RAMECEK ld hl,16416+14 ld bc,6*256+18 ld a,%00000111 call RAMECEK ld hl,16384+1 ld de,TEXT1 call TEXT ld de,16384+ 14 ld hl,nnext call print ld hl,22528+14 ld a,5 ld b,17 kk ld (hl),a inc hl djnz kk ld hl,16448+15 ld de,Versionn ex de,hl call print ld hl,16480+15 ld de,Cursors ex de,hl call print ld hl,16512+15 ld de,Play ex de,hl call print ld hl,16544+15 ld de,NextPlay ex de,hl call print ld hl,18528+15 ld de,tcursor ex de,hl call print ld hl,18560+15 ld de,tenter ex de,hl call print ld hl,18592+15 ld de,tspace ex de,hl call print ld hl,18624+15 ld de,tsearch ex de,hl call print ld hl,18656+15 ld de,treload ex de,hl call print ld a,00001101b ld hl,11*32+22528 + 15 ld b,14 ld (hl),a inc hl djnz $-2 ld hl,12*32+22528 + 15 ld b,14 ld (hl),a inc hl djnz $-2 ld hl,13*32+22528 + 15 ld b,14 ld (hl),a inc hl djnz $-2 ld hl,14*32+22528 + 15 ld b,14 ld (hl),a inc hl djnz $-2 ld hl,15*32+22528 + 15 ld b,15 ld (hl),a inc hl djnz $-2 ret Versionn defb "Version: 0.61",0 Cursors defb " ",0 Play defb "Main program: Shrek",0 NextPlay defb "AY routines: mborik",0 TEXT1 defb "NextPlayer",0 nnext defb " for ZX Spectrum Next",0 WRFILES call BUFF83 ld hl,(ALLFILES) ld a,l ld de,18 or a sbc hl,de jr c,WRF4 ld a,18 WRF4 ld b,a ld hl,16448+1 WRBUFF ld de,catbuff+#D WRF2 push bc push hl ld (P_AT+1),hl ld a,(de) cp 32 jr z,ENDP call WRMOD ld hl,POC inc (hl) pop hl call DOWNH pop bc djnz WRF2 E2 ld a,(POS_F+1) ld c,%00010111 call KURZOR call NOBUFF83 ret ENDP pop hl pop bc ld hl,POC ld a,(hl) ld (FILES),a jr E2 dir defb 0 WRMOD ;původni WRMOD push de ld hl,7 add hl,de bit 7,(hl) jr z,neni_adr ld a,1 ld (dir),a jr je_dir neni_adr xor a ld (dir),a je_dir pop de ld ix,filename ld b,8 WRF1 ld a,(de) or a jr z,WWR ld (ix+0),a inc ix res 7,a call PRINT inc de djnz WRF1 ld a,(dir) or a jr nz,wwrdir ld a,"." ld (ix+0),a inc ix call PRINT ld b,3 wrf2 ld a,(de) res 7,a ld (ix+0),a inc ix call PRINT inc de djnz wrf2 inc de inc de ret WWR inc de ret wwrdir push de ld a,32 call PRINT ld a,"D" call PRINT ld a,"I" call PRINT ld a,"R" call PRINT pop de inc de inc de inc de inc de ;inc de inc de ret NOWRMOD call BUFF83 ld ix,filename ld b,8 aWRF1 ld a,(de) or a jr z,aWWR ld (ix+0),a inc ix ;call PRINT inc de djnz aWRF1 ld a,"." ld (ix+0),a inc ix ; call PRINT ld b,3 awrf2 ld a,(de) res 7,a ld (ix+0),a inc ix ; call PRINT inc de djnz awrf2 inc de inc de call NOBUFF83 ret aWWR inc de call NOBUFF83 ret S_TEXT ld bc,SPECFNT ld (FNT+1),bc call TEXT ld hl,CHARS ld (FNT+1),hl ret TEXT ld (P_AT+1),hl ex de,hl TEX1 ld a,(hl) or a ret z bit 7,a res 7,a jp nz,PRINT call PRINT inc hl jr TEX1 ret FILES defb 0 ALLFILES defb 0,0 POC defb 0 KURZOR push af add a,a add a,a add a,a ld l,a ld h,0 add hl,hl add hl,hl ld de,22528+64+1 add hl,de ld e,l ld d,h inc de ld (hl),c ld bc,11 ldir pop af ret PRN_F call BUFF83 ld (P_AT+1),hl ld hl,(apos_all) ld a,l or h ex de,hl ld hl,catbuff+#d jr z,F12 ld hl,catbuff ld b,d ld c,e ld de,13 F02 add hl,de ld a,b or c dec bc jr nz,F02 F12 ex de,hl call WRMOD call NOBUFF83 ret INIROLL nextreg $57,18 ld b,17*8 ld hl,UPDATA IR1 INI1 ld de,16480+1 ld (hl),e inc hl ld (hl),d inc hl call DOWNDE ld (INI1+1),de INI2 ld de,16448+1 ld (hl),e inc hl ld (hl),d inc hl call DOWNDE ld (INI2+1),de djnz IR1 ld b,17*8 ld hl,UPDATA-1 IR2 INI12 ld de,16480+1 ld (hl),d dec hl ld (hl),e dec hl call DOWNDE ld (INI12+1),de INI22 ld de,16448+1 ld (hl),d dec hl ld (hl),e dec hl call DOWNDE ld (INI22+1),de djnz IR2 ROLLUP ld hl,UPDATA jp ROLL ROLLDOWN ld hl,DOWNDATA ROLL nextreg $57,18 ld (SP_ST+1),sp ld sp,hl ld a,8*17 ROLL1 pop hl pop de ldi ldi ldi ldi ldi ldi ldi ldi ldi ldi ldi ldi dec a jr nz,ROLL1 SP_ST ld sp,0 nextreg $57,1 ;Stránka na uložení VideoRam ret DOWNDE inc d ld a,d and 7 ret nz ld a,e add a,32 ld e,a ld a,d ret c sub 8 ld d,a ret maxpos defw 0 maxpos2 defw 0 pp defb 0 pp_a defb 0 print: push hl push de ld hl,55 add hl,de ld (maxpos),hl ld de,33 add hl,de ld (maxpos2),hl pop de pop hl ; ld de,printpos p6b ld (pos),de xor a ld (roll),a print1: push hl ld hl,(maxpos) or a ld de,(pos) sbc hl,de jr nz,pophl odskok ld hl,8 add hl,de ld (pos),hl pophl ld hl,(pos) ld de,(maxpos2) or a sbc hl,de jr nz, pophl2 pop hl ret pophl2 pop hl push hl ld a,(hl) and 127 or a jr nz,ppp1 ld a,32 ppp1 call ascii ld a,(roll) inc a cp 1 call z,print2 cp 2 call z,print2 cp 4 jr nz,print3 ld a,0 call print2 print3: ld (roll),a pop hl push hl ld a,(hl) or a pop hl inc hl ret z jr print1 print2: ld hl,(pos) inc hl ld (pos),hl ret ascii: ld bc,font push bc sub 32 ld e,a ld d,0 ld b,8 ld hl,0 x8: add hl,de djnz x8 pop bc add hl,bc ld de,(pos) ex de,hl asci0: ld a,(roll) cp 3 jr z,roll3 cp 2 jr z,roll2 cp 1 jr z,roll1 roll0: call asci1 ret roll1: ld b,8 rol1_1: ld a,(de) sla a ld c,0 rl c sla a rl c push bc call asci2 pop bc inc de djnz rol1_1 ret roll2: ld b,8 rol2_1: ld a,(de) sla a ld c,0 rl c sla a rl c sla a rl c sla a rl c push bc call asci2 pop bc inc de djnz rol2_1 ret roll3: ld b,8 rol3_1: ld a,(de) srl a srl a push bc call asci3 pop bc inc de djnz rol3_1 ret asci1: ld b,8 asc1: ld a,(de) ld (hl),a inc de call downhl djnz asc1 ret asci2: ld (hl),a ld a,c dec hl or (hl) ld (hl),a inc hl call downhl ret asci3: or (hl) ld (hl),a downhl: inc h ld a,h and 7 ret nz ld a,l add a,32 ld l,a ld a,h jr c,down2 sub 8 ld h,a down2: cp 88 ret c ld hl,64 ret ;5-bit font font: db $00, $00, $00, $00, $00, $00, $00, $00 db $00, $20, $20, $20, $20, $00, $20, $00 db $00, $50, $50, $00, $00, $00, $00, $00 db $00, $50, $F8, $50, $50, $F8, $50, $00 db $00, $20, $F8, $A0, $F8, $28, $F8, $20 db $00, $40, $A8, $50, $20, $50, $A8, $10 db $00, $20, $50, $20, $68, $90, $68, $00 db $00, $10, $20, $00, $00, $00, $00, $00 db $00, $08, $10, $10, $10, $10, $08, $00 db $00, $40, $20, $20, $20, $20, $40, $00 db $00, $00, $50, $20, $F8, $20, $50, $00 db $00, $00, $20, $20, $F8, $20, $20, $00 db $00, $00, $00, $00, $00, $10, $10, $20 db $00, $00, $00, $00, $78, $00, $00, $00 db $00, $00, $00, $00, $00, $30, $30, $00 db $00, $00, $08, $10, $20, $40, $80, $00 db $00, $70, $98, $A8, $A8, $C8, $70, $00 db $00, $60, $A0, $20, $20, $20, $F8, $00 db $00, $70, $88, $08, $70, $80, $F8, $00 db $00, $70, $88, $30, $08, $88, $70, $00 db $00, $10, $30, $50, $90, $F8, $10, $00 db $00, $F8, $80, $F0, $08, $88, $70, $00 db $00, $70, $80, $F0, $88, $88, $70, $00 db $00, $F8, $08, $10, $20, $40, $40, $00 db $00, $70, $88, $70, $88, $88, $70, $00 db $00, $70, $88, $88, $78, $08, $70, $00 db $00, $00, $00, $20, $00, $00, $20, $00 db $00, $00, $20, $00, $00, $20, $20, $40 db $00, $00, $08, $10, $20, $10, $08, $00 db $00, $00, $00, $78, $00, $78, $00, $00 db $00, $00, $20, $10, $08, $10, $20, $00 db $00, $70, $88, $10, $20, $00, $20, $00 db $00, $70, $08, $68, $A8, $A8, $70, $00 db $00, $70, $88, $88, $F8, $88, $88, $00 db $00, $F0, $88, $F0, $88, $88, $F0, $00 db $00, $70, $88, $80, $80, $88, $70, $00 db $00, $E0, $90, $88, $88, $90, $E0, $00 db $00, $F8, $80, $F0, $80, $80, $F8, $00 db $00, $F8, $80, $F0, $80, $80, $80, $00 db $00, $70, $88, $80, $B8, $88, $70, $00 db $00, $88, $88, $F8, $88, $88, $88, $00 db $00, $F8, $20, $20, $20, $20, $F8, $00 db $00, $08, $08, $08, $88, $88, $70, $00 db $00, $90, $A0, $C0, $A0, $90, $88, $00 db $00, $80, $80, $80, $80, $80, $F8, $00 db $00, $88, $D8, $A8, $88, $88, $88, $00 db $00, $88, $C8, $A8, $98, $88, $88, $00 db $00, $70, $88, $88, $88, $88, $70, $00 db $00, $F0, $88, $88, $F0, $80, $80, $00 db $00, $70, $88, $88, $A8, $98, $70, $00 db $00, $F0, $88, $88, $F0, $90, $88, $00 db $00, $70, $80, $70, $08, $88, $70, $00 db $00, $F8, $20, $20, $20, $20, $20, $00 db $00, $88, $88, $88, $88, $88, $70, $00 db $00, $88, $88, $88, $88, $50, $20, $00 db $00, $88, $88, $88, $88, $A8, $50, $00 db $00, $88, $50, $20, $20, $50, $88, $00 db $00, $88, $50, $20, $20, $20, $20, $00 db $00, $F8, $08, $30, $40, $80, $F8, $00 db $00, $38, $20, $20, $20, $20, $38, $00 db $00, $00, $80, $40, $20, $10, $08, $00 db $00, $70, $10, $10, $10, $10, $70, $00 db $00, $20, $70, $A8, $20, $20, $20, $00 db $00, $00, $00, $00, $00, $00, $00, $FC db $00, $30, $48, $E0, $40, $40, $F8, $00 db $00, $00, $70, $08, $78, $88, $78, $00 db $00, $80, $80, $F0, $88, $88, $F0, $00 db $00, $00, $38, $40, $40, $40, $38, $00 db $00, $08, $08, $78, $88, $88, $78, $00 db $00, $00, $70, $88, $F0, $80, $78, $00 db $00, $30, $40, $60, $40, $40, $40, $00 db $00, $00, $78, $88, $88, $78, $08, $70 db $00, $80, $80, $F0, $88, $88, $88, $00 db $00, $20, $00, $60, $20, $20, $70, $00 db $00, $08, $00, $08, $08, $08, $48, $30 db $00, $40, $50, $60, $60, $50, $48, $00 db $00, $40, $40, $40, $40, $40, $30, $00 db $00, $00, $D0, $A8, $A8, $A8, $A8, $00 db $00, $00, $F0, $88, $88, $88, $88, $00 db $00, $00, $70, $88, $88, $88, $70, $00 db $00, $00, $F0, $88, $88, $F0, $80, $80 db $00, $00, $78, $88, $88, $78, $08, $08 db $00, $00, $38, $40, $40, $40, $40, $00 db $00, $00, $70, $80, $70, $08, $F0, $00 db $00, $20, $70, $20, $20, $20, $18, $00 db $00, $00, $88, $88, $88, $88, $70, $00 db $00, $00, $88, $88, $50, $50, $20, $00 db $00, $00, $88, $A8, $A8, $A8, $50, $00 db $00, $00, $88, $50, $20, $50, $88, $00 db $00, $00, $88, $88, $88, $78, $08, $70 db $00, $00, $F8, $10, $20, $40, $F8, $00 db $00, $38, $20, $C0, $20, $20, $38, $00 db $00, $10, $10, $10, $10, $10, $10, $00 db $00, $E0, $20, $18, $20, $20, $E0, $00 db $00, $28, $50, $00, $00, $00, $00, $00 db $00, $78, $84, $B4, $B4, $84, $78, $00 pos: dw 0 roll: db 0 txtbuf: ds 44 text: db "Now playing: ",0 txtallfiles db "All files:",0 txtcurrentfile db "Position:",0 DOWNDATA equ $e000 UPDATA equ DOWNDATA + 4*8*17 bufscr equ $e000 KKK org #9000 txtbuff ds 100 module key check ahl0 call KEYSCAN ld a,e inc a ret z ld a,d ld hl,SYMTAB cp $18 jr z,aHLSM2 ld hl,CAPSTAB cp $27 jr z,aHLSM2 ld hl,NORMTAB aHLSM2 ld d,0 add hl,de ld a,(hl) or a ret z aLAST_KEY ld b,0 cp b jr z,aSEDI_KEY aSEDI_KEY ld (aLAST_KEY+1),a push af ;call beepk pop af ret endmodule infosong push hl ld hl,txtbuff ld de,txtbuff+1 ld bc,99 ld a,32 ld (hl),a ldir pop hl ld de,txtbuff ld b,90 i1 ld a,(hl) cp 32 ret c cp 128 ret nc ld (de),a inc de inc hl djnz i1 ret pocitadlo defb 0 ACBhlas defb 0 STCPLAY di ld hl,20640 ld de,by1 ld b,8*3 sappp push de push bc push hl ld b,32 sappp0 ld a,(de) ld (hl),a inc hl djnz sappp0 pop hl pop bc pop de call downhl inc de djnz sappp ; ld de,18464+15 ; ld hl,txtcurrentfile ; call print ; ld de,18432+15 ; ld hl,txtallfiles ; call print ; ld hl,(apos_all) ; inc hl ; ld de,18464+15+11 ; ld (NUMPOS+1),de ; call DEC16 ; defw 20*256 ; ld hl,(ALLFILES) ; ld de,18432+15+11 ; ld (NUMPOS+1),de ; call DEC16 ; defw 20*256 ld a,0 ld hl,endsong ld (hl),a ld hl,modstart + 7 call infosong ld hl,txtbuff xor a ld (txtbuff+18),a ld de,20512+1 call print call stc.music_init .sloop ei halt push hl push de push bc ld hl,ACBhlas xor a ld (hl),a ld hl,23200;Vymazání ld de,23201;předešlého ld bc,96 ;zobrazení. ld (hl),b ldir ld a,8 ;A teď nové ld hl,23216;zobrazení. ld de,23215;Kanál A. call ATR ld a,10 ;Kanál C. ld hl,23248 ld de,23247 call ATR ld a,9 ;Kanál B. ld hl,23280 ld de,23279 call ATR ld a,(ACBhlas) or a jr z,.s1 ld hl,pocitadlo xor a ld (hl),a jr .s2 .s1 ld hl,pocitadlo inc (hl) .s2 call keysetup pop bc pop de pop hl call stc.music_play xor a ld a,(klavesa) cp 1 jr z,sakoneca cp 32 jr z,.s3 ld a,(pocitadlo) xor 100 jr z,.s3 ld a,(music_setup) bit 7,a jr z,.sloop .s3 ld a,32 ld hl,endsong ld (hl),a sakoneca push af call music_mute pop af jp navrat STPPLAY di ld hl,20640 ld de,by1 ld b,8*3 stappp push de push bc push hl ld b,32 stappp0 ld a,(de) ld (hl),a inc hl djnz stappp0 pop hl pop bc pop de call downhl inc de djnz stappp ; ld de,18464+15 ; ld hl,txtcurrentfile ; call print ; ld de,18432+15 ; ld hl,txtallfiles ; call print ; ld hl,(apos_all) ; inc hl ; ld de,18464+15+11 ; ld (NUMPOS+1),de ; call DEC16 ; defw 20*256 ; ld hl,(ALLFILES) ; ld de,18432+15+11 ; ld (NUMPOS+1),de ; call DEC16 ; defw 20*256 ld a,0 ld hl,endsong ld (hl),a ld hl,modstart + 11 + 27 call infosong ld hl,txtbuff xor a ld (txtbuff+80),a ld hl,tmp ld de,tmp+1 xor a ld (hl),a ld bc,48 ldir ld hl,txtbuff ld de,tmp ld bc,25 ldir ld hl,tmp ld de,20512+1 call print call stp.music_init .astloop ei halt push hl push de push bc ld hl,ACBhlas xor a ld (hl),a ld hl,23200;Vymazání ld de,23201;předešlého ld bc,96 ;zobrazení. ld (hl),b ldir ld a,8 ;A teď nové ld hl,23216;zobrazení. ld de,23215;Kanál A. call ATR ld a,10 ;Kanál C. ld hl,23248 ld de,23247 call ATR ld a,9 ;Kanál B. ld hl,23280 ld de,23279 call ATR call keysetup ld a,(ACBhlas) or a jr z,.st1 ld hl,pocitadlo xor a ld (hl),a jr .st2 .st1 ld hl,pocitadlo inc (hl) .st2 pop bc pop de pop hl call stp.music_play xor a ld a,(klavesa) cp 1 jr z,stakoneca cp 32 jr z,.st3 ld a,(pocitadlo) xor 100 jr z,.st3 ld a,(music_setup) bit 7,a jr z,.astloop .st3 ld a,32 ld hl,endsong ld (hl),a stakoneca push af call stc.music_mute pop af jp navrat sqt_txt defb "SQ Tracker", 0 SQTPLAY di ld hl,20640 ld de,by1 ld b,8*3 appp push de push bc push hl ld b,32 appp0 ld a,(de) ld (hl),a inc hl djnz appp0 pop hl pop bc pop de call downhl inc de djnz appp ; ld de,18464+15 ; ld hl,txtcurrentfile ; call print ; ld de,18432+15 ; ld hl,txtallfiles ; call print ; ld hl,(apos_all) ; inc hl ; ld de,18464+15+11 ; ld (NUMPOS+1),de ; call DEC16 ; defw 20*256 ; ld hl,(ALLFILES) ; ld de,18432+15+11 ; ld (NUMPOS+1),de ; call DEC16 ; defw 20*256 ld a,0 ld hl,endsong ld (hl),a ld hl,sqt_txt ld de,20512+1 call print call SQ_INIT .loop ei halt push hl push de push bc ld hl,23200;Vymazání ld de,23201;předešlého ld bc,96 ;zobrazení. ld (hl),b ldir xor a ld hl,ACBhlas ld (hl),a ld a,8 ;A teď nové ld hl,23216;zobrazení. ld de,23215;Kanál A. call ATR ld a,10 ;Kanál C. ld hl,23248 ld de,23247 call ATR ld a,9 ;Kanál B. ld hl,23280 ld de,23279 call ATR ld a,(ACBhlas) or a jr z,.as1 ld hl,pocitadlo xor a ld (hl),a jr .as2 .as1 ld hl,pocitadlo inc (hl) .as2 call keysetup pop bc pop de pop hl call SQ_PLAY xor a ld a,(klavesa) cp 1 jr z,akoneca cp 32 jr z,.as3 ld a,(pocitadlo) xor 100 jr z,.as3 ld a,(SQ_STATUS) bit 7,a jr z,.loop .as3 ld a,32 ld hl,endsong ld (hl),a akoneca push af call music_mute pop af jp navrat ;jr .loop ; Povodny player generovany SQ-Linkerom doplneny o GLOBVOL, ; tj. moznost globalneho utlmenia ~ © 2009 mborik/RM-TEAM. ; Upravene na prehravanie SQT suborov, ktorym je potrebne ; na zaciatku relokovat absolutne adresy, dalej bol doplneny ; stavovy bajt podobny aky ma moj PT3 player, cize je mozne ; song neopakovat, alebo fadeoutovat © 2020 mborik/SinDiKat. ; Stavovy bajt prehravaca: ; bit.0 nastav ak nechces ziaden looping ; bit.1 nastav ak chces, aby nastal postupny fadeout po par sekundach ; bit.7 sa nastavi vzdy, po odohrati vsetkych pozicii alebo po fadeoute ; ...v jednoduchosti: 2 - fadeout after loop ; 1 - no loop ; 0 - loop forever SQ_STATUS: db 2 SQ_INIT: ld de,(RELOC_BASE) ; nacitame prvy offset, z ktoreho ld hl,BUFFER+10 ; po odpocitani skutocnej adresy dat xor a ; bez 10 bajtov ziskavame offset, sbc hl,de ; ktorym musime relokovat vsetky push hl ; absolutne ukazovatele v datach muziky ld de,(RELOC_ENDPTR) add hl,de pop bc RELOCATOR: dec hl ld d,(hl) dec hl ld e,(hl) ex de,hl add hl,bc ex de,hl ld (hl),e inc hl ld (hl),d dec hl ld a,l sub RELOC_BASE % 256 jr nz,RELOCATOR ld (CHKFADEOUT+1),a ld (GLOBVOL+1),a dec a ld (SQ_REST+1),a ; resetujem detektor konca skladby ld a,2 ld (SQ_STATUS),a ld a,8 ; inicializacia prehravaca ld (CHNZ1),a ld (CHNZ2),a ld (CHNZ3),a ld bc,$0101 call SQ_REND1 CHN_INIT: ld hl,(I_POSITIONS) ld ix,CHNZ1 call SQ_I9 call SQ_I call SQ_I SQ_STOP: ld de,#073F ; AY registre 7-12 nastav na uplne ticho CHN_INILOOP: call OUT1 ld e,0 inc d ld a,d cp 12 jr nz,CHN_INILOOP ret SQ_DEADEND: inc (hl) ; prehravanie skoncilo, SQ_PLAY je mrtve jr SQ_STOP SQ_PLAY: ld hl,SQ_SYS dec (hl) jr nz,CHKFADEOUT SQ_PLAYSPEED: ld (hl),0 inc hl dec (hl) ld a,(hl) or a call z,SQ_REST cp 4 call c,SQ_I SQ_PP ld ix,CHNZ1 ld c,36 call SQ_P ld ix,CHNZ2 ld c,18 call SQ_P ld ix,CHNZ3 ld c,9 call SQ_P CHKFADEOUT: ld a,0 ; kontrola, ci fadeoutujeme or a jr z,SQ_C ld a,(SQ_STATUS) bit 7,a jr nz,SQ_DEADEND COUNTFADEOUT: ld a,0 dec a ld (COUNTFADEOUT+1),a jr nz,GLOBVOL ld a,(GLOBVOL+1) inc a cp 16 jr z,RESETFADEOUT ld (GLOBVOL+1),a DIVFADEOUT: ld a,0 srl a ld l,a srl l add a,l jr nz,DIVFADEOUT1 inc a DIVFADEOUT1: ld (COUNTFADEOUT+1),a ld (DIVFADEOUT+1),a GLOBVOL: ld a,0 ; global attenuation ld (CHNZ1+11),a ; pre vsetky kanaly ld (CHNZ2+11),a ld (CHNZ3+11),a bit 3,a ; dosiahla hodnota attenuation jr z,SQ_C ; cislo vacsie ako 8? ld hl,CHNZ1 ; tak je nutne upravit sq-flagy, ld de,CHZL ; aby sa prestali prehravat hw obalky ld c,3 ; vo vsetkych troch kanaloch GLOBVOL1: res 0,(hl) ; vynulovanim nulteho bytu add hl,de dec c jr nz,GLOBVOL1 SQ_C: xor a ; vynuluje mixer register ld l,a ld h,a ld (SQ_N+1),hl ld ix,CHNZ1 ; postupne prechadza kanalmi call SQ_R call SQ_R call SQ_R SQ_N: ld bc,0 ; nastavenie mixer registra ld a,b ; B = sumove generatory pre ABC rla ; C = tonove generatory pre ABC rla rla or c cpl ; potom sa bity komplementuju SQ_OFF: or 0 ld e,a ld d,7 ; a posielaju na register 7 AY OUT1: ld bc,$FFFD out (c),d ld b,$BF out (c),e ret RESETFADEOUT: ld hl,-1 ld (SQ_SYS),hl ld hl,SQ_STATUS set 7,(hl) xor a db 1 ; ld bc,NN namiesto ld a,N ENABLEFADE: ld a,48 FORCEFADE: ld hl,CHKFADEOUT+1 inc (hl) ld (COUNTFADEOUT+1),a ld (DIVFADEOUT+1),a cpl ld (SQ_REST+1),a ret SQ_I: ld hl,0 SQ_I1: ld ix,CHNZ1 SQ_I9: ld a,(hl) or a jr nz,SQ_I3 ld (SQ_REST+1),a ; oznac, ze pri najblizsom patterne ld hl,(I_REPEAT) ; budeme testovat fadeout alebo noloop SQ_I3: ld b,(hl) rl b res 5,(ix+0) jr nc,SQ_I4 set 5,(ix+0) SQ_I4: inc hl ld a,(hl) and 15 ld (ix+26),a ld a,(hl) and 240 rra rra rra rra cp 9 jr c,ZBR sub 9 cpl ZBR: ld (ix+24),a inc hl ld (SQ_I+1),hl ld l,b ld h,0 ld de,(I_PATTERNS) add hl,de ld e,(hl) inc hl ld d,(hl) inc de ld (ix+22),e ld (ix+23),d ld de,CHZL add ix,de ld (SQ_I1+2),ix ret SQ_NOFADE: call RESETFADEOUT pop af ret SQ_REST: ld a,-1 or a jr nz,SQ_REST0 ld a,(SQ_STATUS) rrca ; bit 0. nastaveny = koniec jr c,SQ_NOFADE rrca ; bit 1. nastaveny = fadeout jr nc,SQ_REST0 call ENABLEFADE SQ_REST0: ld a,(CHNZ1+26) ld (CHNZ1+11),a ld a,(CHNZ2+26) ld (CHNZ2+11),a ld a,(CHNZ3+26) ld (CHNZ3+11),a ld hl,(CHNZ1+22) dec hl ld b,(hl) inc hl ld (CHNZ1+18),hl ld hl,(CHNZ2+22) ld (CHNZ2+18),hl ld hl,(CHNZ3+22) ld (CHNZ3+18),hl ld hl,(CHNZ1+24) ld (CHNZ1+20),hl ld hl,(CHNZ2+24) ld (CHNZ2+20),hl ld hl,(CHNZ3+24) ld (CHNZ3+20),hl ld hl,(SQ_I+1) ld c,(hl) inc hl ld (SQ_I+1),hl ld hl,CHNZ1 ld (SQ_I1+2),hl ld a,3 ld d,0 SQ_REST1: res 4,(hl) bit 5,(hl) jr z,SQ_REST2 set 4,(hl) SQ_REST2: ld e,21 add hl,de ld (hl),d ld e,CHZL-21 add hl,de dec a jr nz,SQ_REST1 SQ_REND1: ld (SQ_SYS),bc ld a,c SQ_REND2: ld (SQ_PLAYSPEED+1),a ld a,b ret SQ_P: ld a,(ix+21) or a jr z,Y01 dec (ix+21) bit 7,(ix+0) jr nz,Y33 ret Y01: ld e,(ix+18) ld d,(ix+19) set 6,(ix+0) res 7,(ix+0) ld a,(de) inc de bit 7,a jr z,Y02 Y05: ld (ix+18),e ld (ix+19),d ld b,a bit 6,a jr z,Y60 dec de ld (ix+27),e ld (ix+28),d Y34: and 31 jp SQ_SMP Y60: bit 5,a jr nz,Y06 and 15 bit 4,b jr z,Y07 neg Y07: add a,(ix+12) ld (ix+12),a Y33: ld e,(ix+27) ld d,(ix+28) res 6,(ix+0) ld a,(de) bit 7,a jr nz,Y34 inc de jp SMP_ORN Y06: and 15 ld (ix+21),a bit 4,b ret z or a jr z,Y33 set 7,(ix+0) jr Y33 Y02: cp 96 jp c,Y03 sub 96 cp 15 jr c,Y04 ld hl,SQ_OFF+1 ld b,a ld a,(hl) or c ld (hl),a set 3,(ix+0) ld a,b sub 15 jp z,Z26 Y04: dec a ex de,hl ld c,(hl) inc hl bit 6,(ix+0) jr z,Y69 ld (ix+18),l ld (ix+19),h res 6,(ix+0) Y69: cp 8 jr c,Z38 set 0,(ix+0) ld l,c ld e,a ld d,13 call OUT1 ld d,11 ld e,l jp OUT1 Z38: cp 6 ; channel volume set jr nc,Z36 bit 4,(ix+0) ret z or a jr nz,Z31 ld a,c SQ_V: and 15 ld (ix+11),a ret Z31: dec a ; channel volume slide jr nz,Z32 ld a,c add a,(ix+11) jr SQ_V Z32: dec a ; global volume set jr nz,Z33 ld a,c ld (CHNZ1+11),a ld (CHNZ2+11),a ld (CHNZ3+11),a ret Z33: dec a ; global volume slide jr nz,Z34 ld b,3 ld de,CHZL ld hl,CHNZ1+11 Z33_2: ld a,(hl) add a,c and 15 ld (hl),a add hl,de djnz Z33_2 ret Z34: ld hl,SQ_SYS ; speed set dec a jr nz,Z35 ld a,c SQ_S: and 31 jr nz,SQ_Z ld a,32 SQ_Z: ld (hl),a jp SQ_REND2 Z35: ld a,(hl) ; speed slide add a,c jr SQ_S Z36: sub 6 ld b,0 ld a,c ld c,b jr nz,Z37 dec b neg Z37: set 2,(ix+0) ld (ix+13),c ld (ix+14),c ld (ix+15),a ld (ix+16),b ret Y03: ld (ix+12),a dec de ld (ix+27),e ld (ix+28),d inc de call SMP_ORN bit 6,(ix+0) ret z Z26: ld (ix+18),e ld (ix+19),d ret SMP_ORN: ld a,(de) inc de bit 7,a jr z,SMP_ORN9 ld b,a rra and 31 call nz,SQ_SMP bit 6,b ret z ld a,(de) and 240 rr b rra rra rra srl a call nz,SQ_ORN ld a,(de) inc de and 15 ret z SMP_ORN9: jp Y04 SQ_SMP: push bc add a,a ld c,a ld b,0 ld a,(ix+0) and %11110000 ld (ix+0),a ld hl,(I_SAMPLES) add hl,bc ld c,(hl) inc hl ld b,(hl) push ix pop hl inc hl ld (hl),c inc hl ld (hl),b inc bc inc bc inc hl ld (hl),c inc hl ld (hl),b inc hl ld (hl),32 inc hl ld (SQ_NXT+1),hl pop bc ld hl,SQ_OFF+1 ld a,(hl) or c xor c ld (hl),a ret SQ_ORN: add a,a ld c,a ld b,0 ld hl,(I_ORNAMENTS) add hl,bc ld c,(hl) inc hl ld b,(hl) SQ_NXT: ld hl,0 ld (hl),c inc hl ld (hl),b inc hl inc bc inc bc ld (hl),c inc hl ld (hl),b inc hl ld (hl),32 set 1,(ix+0) ret OUT2: ld hl,SQ_N+1 ; podla carry nastavi v SQ_N rl (hl) ; tonovy generator, sumovy off inc hl ; potom vytiahne cislo kanalu rl (hl) ld a,(ix+17) add a,8 ; pripocita k nemu 8 out (c),a ; tj. volume registre AY ld b,$BF out (c),e ; a posle hodnotu v E jp SQ_ZCH SQ_R: ld l,(ix+3) ld h,(ix+4) ld bc,$FFFD ld d,(ix+0) ld e,0 bit 3,d ; ak sa nema nic hrat, umlcat jr nz,OUT2 ld a,(hl) and 15 jp nz,SQ_R1 bit 0,d ; ak sa ma hrat obalka, nastav jr z,SQ_R2 ld e,16 jp SQ_R2 SQ_R1: sub (ix+11) ; od hlasitosti z sa odpocita jr c,SQ_R2 ; global volume nastavenie ld e,a SQ_R2: ld a,(ix+17) ; vytiahne sa cislo kanalu add a,8 ; pripocita sa 8 cim sa dostnem out (c),a ; na registre hlasitosi AY ld b,$BF out (c),e ld a,(hl) inc hl and 240 ; vytiahujem sumove data rra rra rra ld d,6 ld e,(hl) rl e bit 5,(hl) ; zistujem, ci budeme sumiet jr z,SQ_ZNN adc a,0 ld b,$FF out (c),d ld b,$BF out (c),a SQ_ZNN: ld a,e rla ex de,hl ld hl,SQ_N+1 ; nastavime v SQ_N stavy oboch rl (hl) ; generatorov (sum/ton) pre ch. inc hl rla rl (hl) ex de,hl ld a,(hl) ; vypocitavanie frekvencie... and 31 ld d,a inc hl ld e,(hl) inc hl push de ld d,0 dec (ix+5) jp nz,FQ_2 ld l,(ix+1) ld h,(ix+2) ld a,(hl) inc hl cp 32 ld c,(hl) inc hl jr nz,FQ_1 set 3,(ix+0) res 1,(ix+0) FQ_1: ld b,a add a,a add a,b ld e,a add hl,de ld (ix+5),c FQ_2: ld (ix+3),l ld (ix+4),h ld a,(ix+12) bit 1,(ix+0) jr z,FQ_5 ld l,(ix+8) ld h,(ix+9) add a,(hl) inc hl dec (ix+10) jp nz,FQ_4 ex af,af' ld l,(ix+6) ld h,(ix+7) ld a,(hl) inc hl cp 32 ld e,b jr z,FQ_3 ld c,(hl) ld e,a FQ_3: inc hl add hl,de ld (ix+10),c ex af,af' FQ_4: ld (ix+8),l ld (ix+9),h FQ_5: add a,(ix+20) cp 45 jr nc,FQ_6 add a,a ld e,a ld hl,FRQ2 add hl,de ld d,(hl) inc hl jp FQ_7 FQ_6: ld hl,FRQ1-45 ld e,a add hl,de FQ_7: ld e,(hl) ex de,hl pop de ; ...frekvenciu mame, bit 4,d ; bude este fine-tuning? res 4,d jr z,FQ_9 add hl,de db 1 ; ld bc,NN namiesto sbc hl,de FQ_9: sbc hl,de bit 2,(ix+0) jr z,OUT9 ld c,(ix+13) ld b,(ix+14) add hl,bc ex de,hl ld l,(ix+15) ld h,(ix+16) add hl,bc ld (ix+13),l ld (ix+14),h ex de,hl OUT9: ld a,(ix+17) ; vytiahi cislo kanalu add a,a ; vynasob dvoma ld bc,$FFFD ; a naprogramuj freq tonu out (c),a ld b,$BF out (c),l inc a ld b,$FF out (c),a ld b,$BF out (c),h SQ_ZCH: ld de,CHZL ; prejdi s IX na dalsi kanal add ix,de ret FRQ2: db 13,93,12,156 db 11,231,11,60 db 10,155,10,2,9,115 db 8,235,8,107,7,242 db 7,128,7,20,6,174 db 6,78,5,244,5,158 db 5,79,5,1,4,185 db 4,117,4,53,3,249 db 3,192,3,138,3,87 db 3,39,2,250,2,207 db 2,167,2,129,2,93 db 2,59,2,27,1,252 db 1,224,1,197,1,172 db 1,148,1,125,1,104 db 1,83,1,64 db 1,46,1,29,1,13 FRQ1: db 254,240,226,214 db 202,190,180,170 db 160,151,143,135 db 127,120,113,107 db 101,95,90,85,80 db 76,71,67,64,60,57 db 53,50,48,45,42,40 db 38,36,34,32,30,28 db 27,25,24,22,21,20 db 19,18,17,16,15,14 CHNZ1: db 0 dw 0,0,0,0,0,0,0,0 dw 2,0,0,0,0,0 CHNZ2: db 0 dw 0,0,0,0,0,0,0,0 dw 1,0,0,0,0,0 CHNZ3: db 0 dw 0,0,0,0,0,0,0,0 dw 0,0,0,0,0,0 SQ_SYS: dw #0101 CHZL: equ CHNZ2-CHNZ1 ; offset medzi kanalmi ;universal pt2 and pt3 player for zx spectrum and msx ;(c)2004-2005 s.v.bulba <vorobey@mail.khstu.ru> ;http://bulba.at.kz ;release number release equ "0" ;conditional assembly ;1) version of rout (zx or msx standards) zx equ 1 msx equ 0 ;2) current position counter at (start+11) curposcounter equ 1 ;3) allow channels allocation bits at (start+10) acbbac equ 1 ;4) allow loop checking and disabling loopchecker equ 1 ;5) insert official identificator id equ 1 ATR push de ld (atr_kan+1),a ld bc,AY ;Přečtení hlasitosti out (c),a ;z AY in a,(c) ld e,a ld a,254 ;přepnutí na druhou AY out (c),a atr_kan ld a,0 out (c),a in a,(c) ld d,a ld a,255 out (c),a ld a,d add a,e rra pop de push hl push af ld hl,ACBhlas or (hl) ld (hl),a pop af pop hl ; out (254),a cp 16 ;Test překročení jr c,ATR3 ;maximální hlast. ld a,15 ATR3 or a ret z ld b,a ;Uschování hlast. or a rra ;Výpočet barvy jr c,ATR2 ;atributu. set 6,a ;Nastavení jasu. ATR2 ld (hl),a ;Vykreslení ld (de),a ;atributové čáry. inc hl ;Opakuje se dec de ;tolikrát, kolik djnz ATR2 ;je hlasitost. ret AY equ 65533 keysetup call key.check ld (klavesa),a cp "a" call z,setAY cp "y" call z,setYM cp "b" call z,ABC cp "c" call z,ACB call showsetup ret playmusic ld hl,20640 ld de,by1 ld b,8*3 ppp push de push bc push hl ld b,32 ppp0 ld a,(de) ld (hl),a inc hl djnz ppp0 pop hl pop bc pop de call downhl inc de djnz ppp ; ld de,18464+15 ; ld hl,txtcurrentfile ; call print ; ld de,18432+15 ; ld hl,txtallfiles ; call print ; ld hl,(apos_all) ; inc hl ; ld de,18464+15+11 ; ld (NUMPOS+1),de ; call DEC16 ; defw 20*256 ; ld hl,(ALLFILES) ; ld de,18432+15+11 ; ld (NUMPOS+1),de ; call DEC16 ; defw 20*256 xor a ld (endsong),a ld a,(typ) cp "3" jr nz,pp0 ld a,%00000001 ld (VTPL.SETUP),a ld a,1 ;pt2,abc,looped jr pp1 pp0 ld a,%00000011 ld (VTPL.SETUP),a ld a,2 pp1 push af cp 2 jr nz,pt3 ld hl,modstart + 101 jr pt2 pt3 ld hl,modstart + 30 pt2 call infosong ld hl,txtbuff xor a ld (txtbuff+80),a ld hl,tmp ld de,tmp+1 xor a ld (hl),a ld bc,48 ldir ld hl,txtbuff ld de,tmp ld bc,maxline-4 ldir ld hl,tmp ld de,20512+1 call print ld hl,tmp ld de,tmp+1 xor a ld (hl),a ld bc,48 ldir ld hl,txtbuff + maxline-4 ld de,tmp ld bc,maxline ldir ld hl,tmp ld de,20512+1 + 32 call print pop af ld hl,(delka_souboru) DELKA push hl ld a,(hl) cp "S" jr nz,normalni_pt3 dec hl ld a,(hl) cp "T" jr nz,normalni_pt3 dec hl ld a,(hl) cp "2" jr nz,normalni_pt3 dec hl ld a,(hl) cp "0" jr nz,normalni_pt3 ld a,(VTPL.SETUP) or %00010000 ld (VTPL.SETUP),a jr pokrvdet normalni_pt3 ;ld (VTPL.SETUP),a jr pokrvdet pokrvdet pop hl or a ld de,11 sbc hl,de ld a,(hl) inc hl ld h,(hl) ld l,a ld de,songdata add hl,de ex de,hl ;v DE máme druhou skladbu ;CALL music_init ld hl,songdata call VTPL.INIT EI LOOP HALT push hl push de push bc ld hl,23200;Vymazání ld de,23201;předešlého ld bc,96 ;zobrazení. ld (hl),b ldir xor a ld hl,ACBhlas ld (hl),a ld a,8 ;A teď nové ld hl,23216;zobrazení. ld de,23215;Kanál A. call ATR ld a,10 ;Kanál C. ld hl,23248 ld de,23247 call ATR ld a,9 ;Kanál B. ld hl,23280 ld de,23279 call ATR ld a,(ACBhlas) or a jr z,.s1 ld hl,pocitadlo xor a ld (hl),a jr .s2 .s1 ld hl,pocitadlo inc (hl) .s2 call keysetup pop bc pop de pop hl CALL VTPL.PLAY ld a,(klavesa) cp 1 jr z,koneca cp 32 jr z,.s3 ld a,(pocitadlo) xor 100 jr z,.s3 ld a,(music_setup) bit 7,a JR z,LOOP .s3 ld a,32 ld hl,endsong ld (hl),a koneca push af call VTPL.MUTE pop af jp navrat ACB NEXTREG2A 08 or #20 nextreg 08,a ret ABC NEXTREG2A 08 and 0xDF nextreg 08,a ret setAY NEXTREG2A 06 and #FC or #1 nextreg 06,a ret setYM NEXTREG2A 06 and #FC nextreg 06,a ret KLAVESA klavesa defb 0 tona equ 0 tonb equ 2 tonc equ 4 noise equ 6 mixer equ 7 ampla equ 8 amplb equ 9 amplc equ 10 env equ 11 envtp equ 13 ; struct chp ;reset group chp_psinor equ 0 chp_psinsm equ 1 chp_cramsl equ 2 chp_crnssl equ 3 chp_crensl equ 4 chp_tslcnt equ 5 chp_crtnsl equ 6 chp_tnacc equ 8 chp_conoff equ 10 ;reset group chp_onoffd equ 11 ;ix for ptdecod here (+12) chp_offond equ 12 chp_ornptr equ 13 chp_samptr equ 15 chp_nntskp equ 17 chp_note equ 18 chp_sltont equ 19 chp_env_en equ 20 chp_flags equ 21 ;enabled - 0,simplegliss - 2 chp_tnsldl equ 22 chp_tslstp equ 23 chp_tndelt equ 25 chp_ntskcn equ 27 chp_volume equ 28 ; ends chp equ 29 ;entry and other points ;start initialize playing of module at mdladdr ;start+3 initialization with module address in hl ;start+5 play one quark ;start+8 mute ;start+10 setup and status flags ;start+11 current position value (byte) (optional) ;first 12 values of tone tables (packed) music_init: ld hl,MDLADDR music_init0: push hl ld bc,#40 ; look for "by" identifier add hl,bc ld a,(hl) cp 'y' dec hl ld a,(hl) pop hl jr z,pt3fmt_init cp 'b' jr z,pt3fmt_init ld a,(hl) ; and first byte of PT2 is delay cp c ; compared to PT3 text identifier jp c,pt2fmt_init pt3fmt_init call setmodaddr push hl ld de,100 add hl,de ld a,(hl) ld (delay),a push hl pop ix add hl,de ld (CrPsPtr+1),hl ld e,(ix+2) add hl,de inc hl ld (LPosPtr+1),hl pop de ld l,(ix+3) ld h,(ix+4) add hl,de ld (PatsPtr+1),hl ld hl,#A9 add hl,de ld (OrnPtrs+1),hl ld hl,#69 add hl,de ld (SamPtrs+1),hl ld a,(ix-87) ; extract version number sub '0' jr c,l20 cp 10 jr c,l21 l20: ld a,6 l21: ld (Version+1),a push af cp 4 ld a,(ix-1) ; tone table number rla and 7 push af ld hl,#18 + ((smp_-SamCnv-2) << 8) ; jr smp_ ld (SamCnv),hl ld a,#BA ; cp d ld (OrnCP),a ld (SamCP),a ld a,#7B ; ld a,e ld (OrnLD),a ld (SamLD),a ld a,#87 ; add a,a ld (SamClc2),a ld hl,0 ld de,PT3_EmptySmpOrn ld a,pt3pattdc-ptdecode-2 jr ptx_initcommon pt2fmt_init: ld (delay),a push hl push hl push hl inc hl inc hl ld a,(hl) inc hl ld (SamPtrs+1),hl ld e,(hl) inc hl ld d,(hl) pop hl and a sbc hl,de call setmodaddr pop hl ld de,67 add hl,de ld (OrnPtrs+1),hl ld e,32 add hl,de ld c,(hl) inc hl ld b,(hl) ld e,30 add hl,de ld (CrPsPtr+1),hl ld e,a inc hl add hl,de ld (LPosPtr+1),hl pop hl add hl,bc ld (PatsPtr+1),hl ld a,5 ld (Version+1),a push af ld a,2 push af ld hl,$51CB ; bit 2,c ld (SamCnv),hl ld a,$BB ; cp e ld (OrnCP),a ld (SamCP),a ld a,$7A ; ld a,d ld (OrnLD),a ld (SamLD),a ld a,$80 ; add a,b ld (SamClc2),a ld hl,$8687 ; add a,a,(hl) ld de,PT2_EmptySmpOrn ld a,pt2pattdc-ptdecode-2 ptx_initcommon: ld (PsCalc),hl ld (ptdecode+1),a push de ; note table data depacker ld de,T_PACK ld bc,T1_+(2*49)-1 tp_0: ld a,(de) inc de cp 15*2 jr nc,tp_1 ld h,a ld a,(de) ld l,a inc de jr tp_2 tp_1: push de ld d,0 ld e,a add hl,de add hl,de pop de tp_2: ld a,h ld (bc),a dec bc ld a,l ld (bc),a dec bc sub low (#F8*2) jr nz,tp_0 ld (GlobalAttn+1),a ld (chkfadeout+1),a ld hl,music_setup res 7,(hl) ld hl,VARS ld (hl),a ld de,VARS+1 ld bc,VAR0END-VARS-1 ldir inc hl ld (AdInPtA+1),hl ; ptr to zero inc a ld (DelyCnt),a ld hl,#F001 ; H - CHP.Volume, L - CHP.NtSkCn ld (ChanA+CHP.NtSkCn),hl ld (ChanB+CHP.NtSkCn),hl ld (ChanC+CHP.NtSkCn),hl pop hl ld (ChanA+CHP.OrnPtr),hl ; ornament 0 is "0,1,0" ld (ChanB+CHP.OrnPtr),hl ; in all versions from ld (ChanC+CHP.OrnPtr),hl ; 3.xx to 3.6x and VTII pop af ;NoteTableCreator (c) Ivan Roshin ;A - NoteTableNumber*2+VersionForNoteTable ; xx1b - 3.xx..3.4r ; xx0b - 3.4x..3.6x - VortexTracker II ld hl,nt_data push de ld d,b add a,a ld e,a add hl,de ld e,(hl) inc hl srl e sbc a,a and #A7 ; #00 (NOP) or #A7 (AND A) ld (l3),a ex de,hl pop bc ; bc = T1_ add hl,bc ld a,(de) add a,low T_ ld c,a adc a,high T_ sub c ld b,a push bc ld de,NT_ push de ld b,12 l1: push bc ld c,(hl) inc hl push hl ld b,(hl) push de ex de,hl ld de,#17 ld xh,8 l2: srl b rr c l3: add hl,de ; will be replaced by AND A or NOP apparently ld a,c adc a,d ld (hl),a inc hl ld a,b adc a,d ld (hl),a add hl,de dec xh jr nz,l2 pop de inc de inc de pop hl inc hl pop bc djnz l1 pop hl pop de ld a,e cp low TCOLD_1 jr nz,corr_1 ld a,#FD ld (NT_+#002E),a corr_1: ld a,(de) and a jr z,tc_exit rra push af add a,a ld c,a add hl,bc pop af jr nc,corr_2 dec (hl) dec (hl) corr_2: inc (hl) and a sbc hl,bc inc de jr corr_1 tc_exit: pop af ; VolTableCreator (c) Ivan Roshin ; A - VersionForVolumeTable ; (0..4 - v3.xx .. v3.4x ; (5.. - v2.x, v3.5x .. v3.6x (VT2) .. v3.7) cp 5 ld hl,17 ld d,h ld e,h ld a,#17 jr nc,m1 dec l ld e,l xor a m1: ld (m2),a ld ix,VT_+16 ld c,16 initloop2: push hl add hl,de ex de,hl sbc hl,hl initloop1: ld a,l m2: ld a,l ld a,h adc a,0 ld (ix+0),a inc ix add hl,de inc c ld a,c and 15 jr nz,initloop1 pop hl ld a,e cp #77 jr nz,m3 inc e m3: ld a,c and a jr nz,initloop2 jp rout_a0 setmodaddr: ld (modaddr+1),hl ld (mdaddr1+1),hl ld (mdaddr2+1),hl ret ; PT2 pattern decoder --------------------------------------------------------- pd2_sam call setsam jr pd2_loop pd2_eoff ld (ix-12+CHP.Env_En),a jr pd2_loop pd2_env ld (ix-12+CHP.Env_En),16 ld (AYREGS+AR_EnvTp),a ld a,(bc) inc bc ld l,a ld a,(bc) inc bc ld h,a ld (EnvBase),hl jr pd2_loop pd2_orn call setorn jr pd2_loop pd2_skip inc a ld (ix-12+CHP.NNtSkp),a jr pd2_loop pd2_vol rrca rrca rrca rrca ld (ix-12+CHP.Volume),a jr pd2_loop pd2_del call c_delay jr pd2_loop pd2_glis set 2,(ix-12+CHP.Flags) inc a ld (ix-12+CHP.TnSlDl),a ld (ix-12+CHP.TSlCnt),a ld a,(bc) inc bc ld (ix-12+CHP.TSlStp),a add a,a sbc a,a ld (ix-12+CHP.TSlStp+1),a scf jr pd2_loop2 pd2_port: res 2,(ix-12+CHP.Flags) ld a,(bc) inc bc inc bc ; ignoring precalc delta to right sound inc bc scf jr pd2_loop2 pd2_stop: ld (ix-12+CHP.TSlCnt),a jr pd2_loop pt2pattdc: and a pd2_loop2: ex af,af' pd2_loop: ld a,(bc) inc bc add a,$20 jr z,pd2_rel jr c,pd2_sam add a,96 jr c,pd2_note inc a jr z,pd2_eoff add a,15 jp z,pd_fin jr c,pd2_env add a,$10 jr c,pd2_orn add a,$40 jr c,pd2_skip add a,$10 jr c,pd2_vol inc a jr z,pd2_del inc a jr z,pd2_glis inc a jr z,pd2_port inc a jr z,pd2_stop ld a,(bc) inc bc ld (ix-12+CHP.CrNsSl),a jr pd2_loop pd2_rel: ld (ix-12+CHP.Flags),a jr pd2_exit pd2_note: ld l,a ld a,(ix-12+CHP.Note) ld (PrNote+1),a ld (ix-12+CHP.Note),l xor a ld (ix-12+CHP.TSlCnt),a set 0,(ix-12+CHP.Flags) ex af,af' jr nc,pd2_noglis bit 2,(ix-12+CHP.Flags) jr nz,pd2_noport ld (LoStep+1),a add a,a sbc a,a ex af,af' ld h,a ld l,a inc a call setport pd2_noport: ld (ix-12+CHP.TSlCnt),1 pd2_noglis: xor a pd2_exit: ld (ix-12+CHP.PsInSm),a ld (ix-12+CHP.PsInOr),a ld (ix-12+CHP.CrTnSl),a ld (ix-12+CHP.CrTnSl+1),a jp pd_fin ptdecode: jr pt3pattdc ; patter decoder fork ; PT3 pattern decoder --------------------------------------------------------- PD_OrSm: ld (ix-12+CHP.Env_En),0 call setorn pd_sam_: ld a,(bc) inc bc rrca pd_sam: call setsam jr pd_loop pd_vol: rrca rrca rrca rrca ld (ix-12+CHP.Volume),a jr pd_lp2 pd_eoff: ld (ix-12+CHP.Env_En),a ld (ix-12+CHP.PsInOr),a jr pd_lp2 pd_SorE: dec a jr nz,pd_env ld a,(bc) inc bc ld (ix-12+CHP.NNtSkp),a jr pd_lp2 pd_env: call setenv jr pd_lp2 pd_orn: call setorn jr pd_loop pd_esam: ld (ix-12+CHP.Env_En),a ld (ix-12+CHP.PsInOr),a call nz,setenv jr pd_sam_ pt3pattdc: ld a,(ix-12+CHP.Note) ld (PrNote+1),a ld l,(ix-12+CHP.CrTnSl) ld h,(ix-12+CHP.CrTnSl+1) ld (PrSlide+1),hl pd_loop: ld de,#2010 pd_lp2: ld a,(bc) inc bc add a,e jr c,PD_OrSm add a,d jr z,pd_fin jr c,pd_sam add a,e jr z,pd_rel jr c,pd_vol add a,e jr z,pd_eoff jr c,pd_SorE add a,#60 jr c,pd_note add a,e jr c,pd_orn add a,d jr c,pd_nois add a,e jr c,pd_esam add a,a ld e,a ld hl,spccoms-#20E0 add hl,de ld e,(hl) inc hl ld d,(hl) push de jr pd_loop pd_nois: ld (Ns_base),a jr pd_lp2 pd_rel: res 0,(ix-12+CHP.Flags) jr pd_res pd_note: ld (ix-12+CHP.Note),a set 0,(ix-12+CHP.Flags) xor a pd_res: ld (pdsp_+1),sp ld sp,ix ld h,a ld l,a push hl push hl push hl push hl push hl push hl pdsp_: ld sp,#3131 pd_fin: ld a,(ix-12+CHP.NNtSkp) ld (ix-12+CHP.NtSkCn),a ret c_portm: ld a,(bc) inc bc inc bc ; skip precalculated tone delta inc bc ; (because cannot be right after pt3 compilation) ex af,af' ld a,(bc) ; signed tone step inc bc ld (LoStep+1),a ld a,(bc) inc bc and a ex af,af' ld l,(ix-12+CHP.CrTnSl) ld h,(ix-12+CHP.CrTnSl+1) ; Set portamento variables ; A - Delay; A' - Hi(Step); ZF' - (A'=0); HL - CrTnSl setport res 2,(ix-12+CHP.Flags) ld (ix-12+CHP.TnSlDl),a ld (ix-12+CHP.TSlCnt),a push hl ld de,NT_ ld a,(ix-12+CHP.Note) ld (ix-12+CHP.SlToNt),a add a,a ld l,a ld h,0 add hl,de ld a,(hl) inc hl ld h,(hl) ld l,a push hl PrNote: ld a,#3E ld (ix-12+CHP.Note),a add a,a ld l,a ld h,0 add hl,de ld e,(hl) inc hl ld d,(hl) pop hl sbc hl,de ld (ix-12+CHP.TnDelt),l ld (ix-12+CHP.TnDelt+1),h pop de Version: ld a,#3E cp 6 jr c,LoStep ; old 3xxx for PT v3.5- PrSlide: ld de,#1111 ld (ix-12+CHP.CrTnSl),e ld (ix-12+CHP.CrTnSl+1),d LoStep: ld a,0 ; signed tone step ex af,af' jr z,nosig ex de,hl nosig: sbc hl,de jp p,set_stp cpl ex af,af' neg ex af,af' set_stp: ld (ix-12+CHP.TSlStp+1),a ex af,af' ld (ix-12+CHP.TSlStp),a ld (ix-12+CHP.COnOff),0 ret c_gliss: set 2,(ix-12+CHP.Flags) ld a,(bc) inc bc ld (ix-12+CHP.TnSlDl),a and a jr nz,gl36 ld a,(Version+1) ;AlCo PT3.7+ cp 7 sbc a,a inc a gl36: ld (ix-12+CHP.TSlCnt),a ld a,(bc) inc bc ex af,af' ld a,(bc) inc bc jr set_stp c_smpos: ld a,(bc) inc bc ld (ix-12+CHP.PsInSm),a ret c_orpos: ld a,(bc) inc bc ld (ix-12+CHP.PsInOr),a ret c_vibrt: ld a,(bc) inc bc ld (ix-12+CHP.OnOffD),a ld (ix-12+CHP.COnOff),a ld a,(bc) inc bc ld (ix-12+CHP.OffOnD),a xor a ld (ix-12+CHP.TSlCnt),a ld (ix-12+CHP.CrTnSl),a ld (ix-12+CHP.CrTnSl+1),a ret c_engls: ld a,(bc) inc bc ld (Env_Del+1),a ld (CurEDel),a ld a,(bc) inc bc ld l,a ld a,(bc) inc bc ld h,a ld (ESldAdd+1),hl ret c_delay: ld a,(bc) inc bc ld (delay),a ld (DelyCnt),a ; bugfix by Lee_dC ret setenv: ld (ix-12+CHP.Env_En),e ld (AYREGS+AR_EnvTp),a ld a,(bc) inc bc ld h,a ld a,(bc) inc bc ld l,a ld (EnvBase),hl xor a ld (ix-12+CHP.PsInOr),a ld (CurEDel),a ld h,a ld l,a ld (CurESld),hl c_nop: ret setorn: add a,a ld e,a ld d,0 ld (ix-12+CHP.PsInOr),d OrnPtrs: ld hl,#2121 add hl,de ld e,(hl) inc hl ld d,(hl) mdaddr2: ld hl,#2121 add hl,de ld (ix-12+CHP.OrnPtr),l ld (ix-12+CHP.OrnPtr+1),h ret setsam: add a,a ld e,a ld d,0 SamPtrs: ld hl,#2121 add hl,de ld e,(hl) inc hl ld d,(hl) mdaddr1: ld hl,#2121 add hl,de ld (ix-12+CHP.SamPtr),l ld (ix-12+CHP.SamPtr+1),h ret ; all 16 addresses filled to protect from broken pt3 modules spccoms: dw c_nop dw c_gliss dw c_portm dw c_smpos dw c_orpos dw c_vibrt dw c_nop dw c_nop dw c_engls dw c_delay dw c_nop dw c_nop dw c_nop dw c_nop dw c_nop dw c_nop chregs: xor a ld (Ampl),a bit 0,(ix+CHP.Flags) push hl jp z,ch_exit ld (csp_+1),sp ld l,(ix+CHP.OrnPtr) ld h,(ix+CHP.OrnPtr+1) ld sp,hl pop de ld h,a ld a,(ix+CHP.PsInOr) ld l,a add hl,sp inc a ; PT2 | PT3 OrnCP: cp d ; cp e | cp d jr c,ch_orps OrnLD: ld a,e ; a,d | a,e ch_orps: ld (ix+CHP.PsInOr),a ld a,(ix+CHP.Note) add a,(hl) jp p,ch_ntp xor a ch_ntp: cp 96 jr c,ch_nok ld a,95 ch_nok: add a,a ex af,af' ld l,(ix+CHP.SamPtr) ld h,(ix+CHP.SamPtr+1) ld sp,hl pop de ld h,0 ld a,(ix+CHP.PsInSm) ld b,a add a,a ; PT2 | PT3 SamClc2: add a,a ; a,b | a,a ld l,a add hl,sp ld sp,hl ld a,b inc a SamCP: cp d ; cp e | cp d jr c,ch_smps SamLD: ld a,e ; a,d | a,e ch_smps: ld (ix+CHP.PsInSm),a pop bc pop hl ; PT2 | PT3 SamCnv: jr smp_ ; bit 2,c | jr smp_ ld h,b ; Convert PT2 sample to PT3 jr nz,SamCnv1 ex de,hl and a sbc hl,hl sbc hl,de SamCnv1: ld d,c rr c sbc a,a cpl and #3E rr c rr b and c ld c,a ld a,b rra rra rr d rra and #9F ld b,a smp_: ld e,(ix+CHP.TnAcc) ld d,(ix+CHP.TnAcc+1) add hl,de bit 6,b jr z,ch_noac ld (ix+CHP.TnAcc),l ld (ix+CHP.TnAcc+1),h ch_noac: ex de,hl ex af,af' ld l,a ld h,0 ld sp,NT_ add hl,sp ld sp,hl pop hl add hl,de ld e,(ix+CHP.CrTnSl) ld d,(ix+CHP.CrTnSl+1) add hl,de csp_: ld sp,#3131 ex (sp),hl xor a or (ix+CHP.TSlCnt) jr z,ch_amp dec (ix+CHP.TSlCnt) jr nz,ch_amp ld a,(ix+CHP.TnSlDl) ld (ix+CHP.TSlCnt),a ld l,(ix+CHP.TSlStp) ld h,(ix+CHP.TSlStp+1) ld a,h add hl,de ld (ix+CHP.CrTnSl),l ld (ix+CHP.CrTnSl+1),h bit 2,(ix+CHP.Flags) jr nz,ch_amp ld e,(ix+CHP.TnDelt) ld d,(ix+CHP.TnDelt+1) and a jr z,ch_stpp ex de,hl ch_stpp: sbc hl,de jp m,ch_amp ld a,(ix+CHP.SlToNt) ld (ix+CHP.Note),a xor a ld (ix+CHP.TSlCnt),a ld (ix+CHP.CrTnSl),a ld (ix+CHP.CrTnSl+1),a ch_amp: ld a,(ix+CHP.CrAmSl) bit 7,c jr z,ch_noam bit 6,c jr z,ch_amin cp 15 jr z,ch_noam inc a jr ch_svam ch_amin: cp -15 jr z,ch_noam dec a ch_svam: ld (ix+CHP.CrAmSl),a ch_noam: ld l,a ld a,b and 15 add a,l jp p,ch_apos xor a ch_apos: cp 16 jr c,ch_vol ld a,15 ch_vol: or (ix+CHP.Volume) ld l,a ld h,0 ld de,VT_ add hl,de ld e,(hl) GlobalAttn: ld a,0 ; GLOBAL ATTENUATION cp 8 ; if value of attenuation is higher jr c,ch_globvol ; then this value we will stop set 0,c ; also envelopes (bit.0 in flags)... ch_globvol: sub e jr c,ch_env xor a ch_env: neg bit 0,c jr nz,ch_noen or (ix+CHP.Env_En) ch_noen: ld (Ampl),a bit 7,b ld a,c jr z,no_ensl rla rla sra a sra a sra a add a,(ix+CHP.CrEnSl) bit 5,b jr z,no_enac ld (ix+CHP.CrEnSl),a no_enac: ld hl,AddToEn+1 add a,(hl) ld (hl),a jr ch_mix no_ensl: rra add a,(ix+CHP.CrNsSl) ld (AddToNs),a bit 5,b jr z,ch_mix ld (ix+CHP.CrNsSl),a ch_mix: ld a,b rra and #48 ch_exit: ld hl,AYREGS+AR_Mixer or (hl) rrca ld (hl),a pop hl xor a or (ix+CHP.COnOff) ret z dec (ix+CHP.COnOff) ret nz xor (ix+CHP.Flags) ld (ix+CHP.Flags),a rra ld a,(ix+CHP.OnOffD) jr c,ch_ondl ld a,(ix+CHP.OffOnD) ch_ondl: ld (ix+CHP.COnOff),a ret ;------------------------------------------------------------------------------ music_play: xor a ld (AddToEn+1),a ld (AYREGS+AR_Mixer),a dec a ld (AYREGS+AR_EnvTp),a ld hl,DelyCnt dec (hl) jp nz,pl2 call chkfadeout ld hl,ChanA+CHP.NtSkCn dec (hl) jr nz,pl1b AdInPtA: ld bc,#0101 ld a,(bc) and a jr nz,pl1a ld d,a ld (Ns_base),a CrPsPtr: ld hl,#2121 inc hl ld a,(hl) inc a jr nz,plnlp call checklp LPosPtr: ld hl,#2121 ld a,(hl) inc a plnlp: ld (CrPsPtr+1),hl dec a ; PT2 PT3 PsCalc: nop ; add a,a nop nop ; add a,(hl) nop add a,a ld e,a rl d PatsPtr: ld hl,#2121 add hl,de modaddr: ld de,#1111 ld (psp_+1),sp ld sp,hl pop hl add hl,de ld b,h ld c,l pop hl add hl,de ld (AdInPtB+1),hl pop hl add hl,de ld (AdInPtC+1),hl psp_: ld sp,#3131 pl1a: ld ix,ChanA+12 call ptdecode ld (AdInPtA+1),bc pl1b: ld hl,ChanB+CHP.NtSkCn dec (hl) jr nz,pl1c ld ix,ChanB+12 AdInPtB: ld bc,#0101 call ptdecode ld (AdInPtB+1),bc pl1c: ld hl,ChanC+CHP.NtSkCn dec (hl) jr nz,pl1d ld ix,ChanC+12 AdInPtC: ld bc,#0101 call ptdecode ld (AdInPtC+1),bc delay: equ $+1 pl1d: ld a,#3E ld (DelyCnt),a pl2: ld ix,ChanA ld hl,(AYREGS+AR_TonA) call chregs ld (AYREGS+AR_TonA),hl ld a,(Ampl) ld (AYREGS+AR_AmplA),a ld ix,ChanB ld hl,(AYREGS+AR_TonB) call chregs ld (AYREGS+AR_TonB),hl ld a,(Ampl) ld (AYREGS+AR_AmplB),a ld ix,ChanC ld hl,(AYREGS+AR_TonC) call chregs ld (AYREGS+AR_TonC),hl ld hl,(Ns_base) ; read together with AddToNs ld a,h add a,l ld (AYREGS+AR_Noise),a AddToEn: ld a,#3E ld e,a add a,a sbc a,a ld d,a ld hl,(EnvBase) add hl,de ld de,(CurESld) add hl,de ld (AYREGS+AR_Env),hl xor a ld hl,CurEDel or (hl) jr z,rout_a0 dec (hl) jr nz,rout Env_Del: ld a,#3E ld (hl),a ESldAdd: ld hl,#2121 add hl,de ld (CurESld),hl rout: xor a rout_a0: ld de,#FFBF ld bc,#FFFD ld hl,AYREGS lout: out (c),a ld b,e outi ld b,d inc a cp #0D jr nz,lout out (c),a ld a,(hl) and a ret m ld b,e out (c),a ret checklp: ld hl,music_setup bit 1,(hl) jr nz,enablefade bit 0,(hl) ret z noloop: set 7,(hl) deadend: pop hl ld hl,DelyCnt inc (hl) ld hl,ChanA+CHP.NtSkCn inc (hl) music_mute: xor a ld h,a ld l,a ld (AYREGS+AR_AmplA),a ld (AYREGS+AR_AmplB),hl jr rout_a0 enablefade: ld a,48 forcefade: ld hl,chkfadeout+1 inc (hl) ld hl,(CrPsPtr+1) ld (resetfadeout+1),hl ld (resetfadeout1+1),bc ld (countfadeout+1),a ld (divfadeout+1),a chkfadeout: ld a,0 or a ret z ld a,(music_setup) rlca jr c,deadend countfadeout: ld a,#3E dec a ld (countfadeout+1),a ret nz ld a,(GlobalAttn+1) inc a cp 16 jr z,resetfadeout ld (GlobalAttn+1),a divfadeout: ld a,#3E srl a ld l,a srl l add a,l jr nz,divfadeout1 inc a divfadeout1: ld (countfadeout+1),a ld (divfadeout+1),a ret resetfadeout: ld hl,#2121 ld (CrPsPtr+1),hl resetfadeout1: ld hl,#2121 ld (AdInPtA+1),hl xor a ld (ChanA+CHP.NtSkCn),a ld hl,music_setup jr noloop ; bit.0 if you want to play without looping ; bit.1 if you play looped but fadeout after few seconds ; bit.7 is set each time when loop is passed ; ...or simplified: 2 - fadeout after loop ; 1 - no loop ; 0 - loop forever music_setup: db 2 ;------------------------------------------------------------------------------ ; note table data nt_data: db (T_NEW_0-T1_)*2 db TCNEW_0-T_ db (T_OLD_0-T1_)*2+1 db TCOLD_0-T_ db (T_NEW_1-T1_)*2+1 db TCNEW_1-T_ db (T_OLD_1-T1_)*2+1 db TCOLD_1-T_ db (T_NEW_2-T1_)*2 db TCNEW_2-T_ db (T_OLD_2-T1_)*2 db TCOLD_2-T_ db (T_NEW_3-T1_)*2 db TCNEW_3-T_ db (T_OLD_3-T1_)*2 db TCOLD_3-T_ T_ TCOLD_0 db #00+1,#04+1,#08+1,#0A+1,#0C+1,#0E+1,#12+1,#14+1 db #18+1,#24+1,#3C+1,0 TCOLD_1 db #5C+1,0 TCOLD_2 db #30+1,#36+1,#4C+1,#52+1,#5E+1,#70+1,#82,#8C,#9C db #9E,#A0,#A6,#A8,#AA,#AC,#AE,#AE,0 TCNEW_3 db #56+1 TCOLD_3 db #1E+1,#22+1,#24+1,#28+1,#2C+1,#2E+1,#32+1,#BE+1,0 TCNEW_0 db #1C+1,#20+1,#22+1,#26+1,#2A+1,#2C+1,#30+1,#54+1 db #BC+1,#BE+1,0 TCNEW_1 equ TCOLD_1 TCNEW_2 db #1A+1,#20+1,#24+1,#28+1,#2A+1,#3A+1,#4C+1,#5E+1 db #BA+1,#BC+1,#BE+1,0 PT3_EmptySmpOrn equ $-1 db 1,0 ;#90 ; delete #90 if you don't need default sample PT2_EmptySmpOrn equ VT_+31 ; 1,0,0 sequence ; first 12 values of tone tables (packed) T_PACK db high (#06EC*2), low (#06EC*2) db #0755-#06EC db #07C5-#0755 db #083B-#07C5 db #08B8-#083B db #093D-#08B8 db #09CA-#093D db #0A5F-#09CA db #0AFC-#0A5F db #0BA4-#0AFC db #0C55-#0BA4 db #0D10-#0C55 db high (#066D*2), low (#066D*2) db #06CF-#066D db #0737-#06CF db #07A4-#0737 db #0819-#07A4 db #0894-#0819 db #0917-#0894 db #09A1-#0917 db #0A33-#09A1 db #0ACF-#0A33 db #0B73-#0ACF db #0C22-#0B73 db #0CDA-#0C22 db high (#0704*2), low (#0704*2) db #076E-#0704 db #07E0-#076E db #0858-#07E0 db #08D6-#0858 db #095C-#08D6 db #09EC-#095C db #0A82-#09EC db #0B22-#0A82 db #0BCC-#0B22 db #0C80-#0BCC db #0D3E-#0C80 db high (#07E0*2), low (#07E0*2) db #0858-#07E0 db #08E0-#0858 db #0960-#08E0 db #09F0-#0960 db #0A88-#09F0 db #0B28-#0A88 db #0BD8-#0B28 db #0C80-#0BD8 db #0D60-#0C80 db #0E10-#0D60 db #0EF8-#0E10 ; channel data offsets struct CHP PsInOr byte PsInSm byte CrAmSl byte CrNsSl byte CrEnSl byte TSlCnt byte CrTnSl word TnAcc word COnOff byte OnOffD byte OffOnD byte ; IX for PTDECOD here (+12) OrnPtr word SamPtr word NNtSkp byte Note byte SlToNt byte Env_En byte Flags byte TnSlDl byte ; Enabled - 0, SimpleGliss - 2 TSlStp word TnDelt word NtSkCn byte Volume byte ends AR_TonA equ 0 ; word 1 AR_TonB equ 2 ; word 1 AR_TonC equ 4 ; word 1 AR_Noise equ 6 ; byte 1 AR_Mixer equ 7 ; byte 1 AR_AmplA equ 8 ; byte 1 AR_AmplB equ 9 ; byte 1 AR_AmplC equ 10 ; byte 1 AR_Env equ 11 ; word 1 AR_EnvTp equ 13 ; byte 1 AR_Size equ 14 ;------------------------------------------------------------------------------ ; variables are 541 bytes long VARS ChanA ds 29 ChanB ds 29 ChanC ds 29 ; GlobalVars DelyCnt db 0 CurESld dw 0 CurEDel db 0 Ns_base db 0 AddToNs db 0 AYREGS equ $ Ampl equ AYREGS+AR_AmplC VT_ ds 256 ; Volume Table NT_ ds 192 ; Note Table EnvBase equ VT_+14 T1_ equ VT_+16 ; Tone tables data depacked here T_OLD_1 equ T1_ T_OLD_2 equ T_OLD_1+24 T_OLD_3 equ T_OLD_2+24 T_OLD_0 equ T_OLD_3+2 T_NEW_0 equ T_OLD_0 T_NEW_1 equ T_OLD_1 T_NEW_2 equ T_NEW_0+24 T_NEW_3 equ T_OLD_3 VAR0END equ T1_ ; init zeroes from VARS to VAR0END-1 VARSEND equ $ module stc music_init: ld hl,songdata music_init0: ld a,(hl) ld (speed),a ld (module_addr+1),hl inc hl call add_offset ld a,(de) inc de inc a ld (song_length),a ld (positions),de call add_offset ld (ornaments),de push de call add_offset ld (patterns),de ld hl,HEADLEN call module_addr ex de,hl ld (samples),hl ld hl,empty_pattern ld (chn1_pattptr),hl inc hl ld de,CHN1+1 ld bc,VARSLEN ld (hl),b ldir pop hl ld bc,ORNALEN xor a call scan_until ld (apply_volenv+1),a ld (chkfadeout+1),a dec a ld (CHN1+CHP.SmpCnt),a ld (CHN2+CHP.SmpCnt),a ld (CHN3+CHP.SmpCnt),a ld a,1 ld (tempo_cnt),a inc hl ld (CHN1+CHP.OrnPtr),hl ld (CHN2+CHP.OrnPtr),hl ld (CHN3+CHP.OrnPtr),hl ld hl,music_setup res 7,(hl) jp music_mute scan_until: cp (hl) ret z add hl,bc jr scan_until add_offset: ld e,(hl) inc hl ld d,(hl) inc hl ex de,hl module_addr: ld bc,0 add hl,bc ex de,hl ret new_position: ld a,(current_pos) ld c,a ld hl,song_length cp (hl) jr c,.continue ld hl,music_setup bit 1,(hl) call nz,enablefade bit 0,(hl) jp nz,noloop xor a ld c,a .continue: inc a ld (current_pos),a ld l,c ld h,0 add hl,hl ld de,(positions) add hl,de ld c,(hl) inc hl ld a,(hl) ld (get_frequency+1),a ld a,c ld hl,(patterns) ld bc,PATTLEN call scan_until inc hl call add_offset ld (chn1_pattptr),de call add_offset ld (chn2_pattptr),de call add_offset ld (chn3_pattptr),de ret adv_patt_step: dec (ix+CHP.PatStpCnt) ret p ld a,(ix+CHP.PatStep) ld (ix+CHP.PatStpCnt),a ret ;------------------------------------------------------------------------------ music_play: ld a,(tempo_cnt) dec a ld (tempo_cnt),a jr nz,playback ld a,(speed) ld (tempo_cnt),a .chn1: ld ix,CHN1 call adv_patt_step jp p,.chn2 ld hl,(chn1_pattptr) ld a,(hl) inc a call z,new_position ld hl,(chn1_pattptr) call read_pattern ld (chn1_pattptr),hl .chn2: ld ix,CHN2 call adv_patt_step jp p,.chn3 ld hl,(chn2_pattptr) call read_pattern ld (chn2_pattptr),hl .chn3: ld ix,CHN3 call adv_patt_step jp p,playback ld hl,(chn3_pattptr) call read_pattern ld (chn3_pattptr),hl ;------------------------------------------------------------------------------ playback: call chkfadeout ld ix,CHN1 call adv_sample ld a,c ld (sample_index+1),a call read_sample ld a,c or b rrca ld (AYREGS+AR.Mixer),a ld a,(ix+CHP.SmpCnt) inc a jr z,.chn2 call set_noise call get_tone ld (AYREGS+AR.TonA),hl .chn2: ld hl,AYREGS+AR.AmplA call apply_volenv ld ix,CHN2 call adv_sample ld a,(ix+CHP.SmpCnt) inc a jr z,.chn3 ld a,c ld (sample_index+1),a call read_sample ld a,(AYREGS+AR.Mixer) or c or b ld (AYREGS+AR.Mixer),a call set_noise call get_tone ld (AYREGS+AR.TonB),hl .chn3: ld hl,AYREGS+AR.AmplB call apply_volenv ld ix,CHN3 call adv_sample ld a,(ix+CHP.SmpCnt) inc a jr z,.finish ld a,c ld (sample_index+1),a call read_sample ld a,(AYREGS+AR.Mixer) rlc c rlc b or b or c ld (AYREGS+AR.Mixer),a call set_noise call get_tone ld (AYREGS+AR.TonC),hl .finish: ld hl,AYREGS+AR.AmplC call apply_volenv outay: ld hl,AYREGS+AR.EnvSh xor a or (hl) ld a,AR.EnvSh jr nz,.fillregs sub 3 dec hl dec hl dec hl .fillregs: ld bc,#FFFD .loop: out (c),a res 6,b outd set 6,b dec a ret m jr .loop music_mute: ld hl,AYREGS ld de,AYREGS+1 ld bc,AR.Mixer ld (hl),b ldir dec (hl) ld l,low AYREGS ld c,AR.EnvSh-AR.Mixer-1 ldir ex hl,de ld a,AR.EnvSh jr outay.fillregs c_note: ld (ix+CHP.Note),a ld (ix+CHP.SmpIndex),0 ld (ix+CHP.SmpCnt),#20 c_empty: inc hl ret c_sample: sub #60 push hl ld bc,SAMPLEN ld hl,(samples) call scan_until inc hl ld (ix+CHP.SmpPtr),l ld (ix+CHP.SmpPtr+1),h pop hl inc hl jr read_pattern c_rest: inc hl c_norept: ld (ix+CHP.SmpCnt),-1 ret read_pattern: ld a,(hl) cp #60 ; note jr c,c_note cp #70 ; sample jr c,c_sample cp #80 ; ornament jr c,c_ornament jr z,c_rest ; rest cp #81 ; empty jr z,c_empty cp #82 ; ornament off jr z,c_ornoff cp #8F ; envelope jr c,c_envelope sub #A1 ; speed ld (ix+CHP.PatStpCnt),a ld (ix+CHP.PatStep),a inc hl jr read_pattern c_ornoff: xor a db 1 ; ld bc,* (skip next instruction) c_ornament: sub #70 c_ornament0: push hl ld bc,ORNALEN ld hl,(ornaments) call scan_until inc hl ld (ix+CHP.OrnPtr),l ld (ix+CHP.OrnPtr+1),h ld (ix+CHP.EnvState),0 pop hl inc hl jr read_pattern c_envelope: sub #80 ld (AYREGS+AR.EnvSh),a inc hl ld a,(hl) inc hl ld (AYREGS+AR.Env),a ld (ix+CHP.EnvState),1 push hl xor a ld bc,ORNALEN ld hl,(ornaments) call scan_until inc hl ld (ix+CHP.OrnPtr),l ld (ix+CHP.OrnPtr+1),h pop hl jr read_pattern adv_sample: ld a,(ix+CHP.SmpCnt) inc a ret z dec a dec a ld (ix+CHP.SmpCnt),a push af ld a,(ix+CHP.SmpIndex) ld c,a inc a and #1F ld (ix+CHP.SmpIndex),a pop af ret nz ld e,(ix+CHP.SmpPtr) ld d,(ix+CHP.SmpPtr+1) ld hl,#60 ; offset to sample metadata add hl,de ld a,(hl) dec a jp m,c_norept ld c,a ; repeat sample inc a and #1F ld (ix+CHP.SmpIndex),a inc hl ld a,(hl) inc a ld (ix+CHP.SmpCnt),a ret read_sample: ld d,0 ld e,a add a,a add a,e ld e,a ld l,(ix+CHP.SmpPtr) ld h,(ix+CHP.SmpPtr+1) add hl,de inc hl ld a,(hl) bit 7,a ld c,#10 jr nz,.no_noise ld c,d .no_noise: bit 6,a ld b,2 jr nz,.no_tone ld b,d .no_tone: inc hl ld e,(hl) dec hl dec hl ld d,(hl) ld l,a and #1F ld h,a ld a,d push af and #F0 rrca rrca rrca rrca ld d,a pop af and #0F bit 5,l ld l,a ret z set 4,d ret set_noise: ld a,c or a ret nz ld a,h ld (AYREGS+AR.Noise),a ret apply_volenv: ld e,0 ; GLOBAL ATTENUATION sub e jr nc,.set xor a .set ld (hl),a ; if value of attenuation is higher bit 3,a ; then 8 we will stop also envelopes... ret z ld a,(ix+CHP.SmpCnt) inc a ret z ld a,(ix+CHP.EnvState) or a ret z dec a jr nz,.resetshape ld (ix+CHP.EnvState),2 jr .setenv .resetshape: xor a ld (AYREGS+AR.EnvSh),a .setenv: set 4,(hl) ret get_tone: ld a,l push af push de ld l,(ix+CHP.OrnPtr) ld h,(ix+CHP.OrnPtr+1) sample_index: ld de,0 add hl,de ld a,(ix+CHP.Note) add a,(hl) get_frequency: add a,0 add a,a ld e,a ld d,0 ld hl,freqtable add hl,de ld e,(hl) inc hl ld d,(hl) ex de,hl pop de pop af bit 4,d jr z,.negative res 4,d add hl,de ret .negative: and a sbc hl,de ret ;------------------------------------------------------------------------------ resetfadeout: ld hl,music_setup noloop: set 7,(hl) call music_mute deadend: pop hl xor a ld (tempo_cnt),a dec a ld (CHN1+CHP.SmpCnt),a ld (CHN2+CHP.SmpCnt),a ld (CHN3+CHP.SmpCnt),a ld (chkfadeout+1),a ret enablefade: ld a,48 forcefade: ld (chkfadeout+1),a ld (countfadeout+1),a ld (divfadeout+1),a chkfadeout: ld a,0 or a ret z ld a,(music_setup) rlca jr c,deadend countfadeout: ld a,0 dec a ld (countfadeout+1),a ret nz ld a,(apply_volenv+1) inc a cp 16 jr z,resetfadeout ld (apply_volenv+1),a divfadeout: ld a,0 srl a ld e,a srl e add a,e jr nz,divfadeout1 inc a divfadeout1: ld (countfadeout+1),a ld (divfadeout+1),a ret ;------------------------------------------------------------------------------ positions: dw 0 ornaments: dw 0 patterns: dw 0 samples: dw 0 speed: db 0 tempo_cnt: db 0 song_length: db 0 chn1_pattptr: dw empty_pattern chn2_pattptr: dw empty_pattern chn3_pattptr: dw empty_pattern empty_pattern: db #FF VARS CHN1: ds 10 CHN2: ds 10 CHN3: ds 10 current_pos: db 0 @VARSLEN = $ - VARS AYREGS: ds 14 ;------------------------------------------------------------------------------ freqtable: dw #0EF8, #0E10, #0D60, #0C80, #0BD8, #0B28, #0A88, #09F0 dw #0960, #08E0, #0858, #07E0, #077C, #0708, #06B0, #0640 dw #05EC, #0594, #0544, #04F8, #04B0, #0470, #042C, #03F0 dw #03BE, #0384, #0358, #0320, #02F6, #02CA, #02A2, #027C dw #0258, #0238, #0216, #01F8, #01DF, #01C2, #01AC, #0190 dw #017B, #0165, #0151, #013E, #012C, #011C, #010B, #00FC dw #00EF, #00E1, #00D6, #00C8, #00BD, #00B2, #00A8, #009F dw #0096, #008E, #0085, #007E, #0077, #0070, #006B, #0064 dw #005E, #0059, #0054, #004F, #004B, #0047, #0042, #003F dw #003B, #0038, #0035, #0032, #002F, #002C, #002A, #0027 dw #0025, #0023, #0021, #001F, #001D, #001C, #001A, #0019 dw #0017, #0016, #0015, #0013, #0012, #0011, #0010, #000F ;------------------------------------------------------------------------------ struct AR ; AY Registers structure TonA word ; 0 TonB word ; 2 TonC word ; 4 Noise byte ; 6 Mixer byte ; 7 AmplA byte ; 8 AmplB byte ; 9 AmplC byte ; 10 Env word ; 11 EnvSh byte ; 13 ends struct CHP ; channel parameters structure EnvState byte PatStep byte SmpIndex byte Note byte PatStpCnt byte SmpPtr word OrnPtr word SmpCnt byte ends @HEADLEN = 27 ; file header length @SAMPLEN = 99 ; single sample length @ORNALEN = 33 ; single ornament length @PATTLEN = 7 ; single pattern record length endmodule ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;Universal PT2'n'PT3 Turbo Sound player for ZX Spectrum ;(c)2004-2007 S.V.Bulba <vorobey@mail.khstu.ru> ;Specially for AlCo ;http://bulba.untergrund.net/ (http://bulba.at.kz/) MODULE VTPL ;Release number Release EQU "0" ;Conditional assembly ;1) Current position counters at (Vars1+0) and (Vars2+0) CurPosCounter=0 ;2) Allow channels allocation bits at (START+10) ACBBAC=0 ;3) Allow loop checking and disabling LoopChecker=1 ;4) Insert official identificator Id=0 ;5) Set IY for correct return to ZX Basic Basic=1 ;Features ;-------- ;-Can be compiled at any address (i.e. no need rounding ORG ; address). ;-Variables (VARS) can be located at any address (not only after ; code block). ;-INIT subprogram checks PT3-module version and rightly ; generates both note and volume tables outside of code block ; (in VARS). ;-Two portamento (spc. command 3xxx) algorithms (depending of ; PT3 module version). ;-New 1.XX and 2.XX special command behaviour (only for PT v3.7 ; and higher). ;-Any Tempo value are accepted (including Tempo=1 and Tempo=2). ;-TS modes: 2xPT3, 2xPT2 and PT v3.7 TS standard. ;-Fully compatible with Ay_Emul PT3 and PT2 players codes. ;-See also notes at the end of this source code. ;Limitations ;----------- ;-Can run in RAM only (self-modified code is used). ;-PT2 position list must be end by #FF marker only. ;Warning!!! PLAY subprogram can crash if no module are loaded ;into RAM or INIT subprogram was not called before. ;Call MUTE or INIT one more time to mute sound after stopping ;playing ;Test codes (commented) ; LD A,32 ;SinglePT3(TS if TSPT3.7),ABC,Looped ; LD (START+10),A ; LD HL,#8000 ;Mod1 ; LD DE,#A000 ;Mod2 (optional) ; CALL START+3 ; EI ;_LP HALT ; CALL START+5 ; XOR A ; IN A,(#FE) ; CPL ; AND 15 ; JR Z,_LP ; JR START+8 TonA EQU 0 TonB EQU 2 TonC EQU 4 Noise EQU 6 Mixer EQU 7 AmplA EQU 8 AmplB EQU 9 AmplC EQU 10 Env EQU 11 EnvTp EQU 13 ;Entry and other points ;START initialize playing of modules at MDLADDR (single module) ;START+3 initialization with module address in HL and DE (TS) ;START+5 play one quark ;START+8 mute ;START+10 setup and status flags START: LD HL,songdata ;DE - address of 2nd module for TS JR INIT JP PLAY JR MUTE SETUP DB %00010000 ;set bit0, if you want to play without looping ;(optional); ;set bit1 for PT2 and reset for PT3 before ;calling INIT; ;bits2-3: %00-ABC, %01-ACB, %10-BAC (optional); ;bits4-5: %00-no TS, %01-2 modules TS, %10- ;autodetect PT3 TS-format by AlCo (PT 3.7+); ;Remark: old PT3 TS-format by AlCo (PT 3.6) is not ;documented and must be converted to new standard. ;bit6 is set each time, when loop point of 2nd TS ;module is passed (optional). ;bit7 is set each time, when loop point of 1st TS ;or of single module is passed (optional). ;Identifier IF Id DB "=UniPT2/PT3/TS-Player r.",Release,"=" ENDIF IF LoopChecker CHECKLP LD HL,SETUP BIT 0,(IY-100+VRS.ModNum) JR Z,CHL1 SET 6,(HL) JR CHL2 CHL1 SET 7,(HL) CHL2 BIT 0,(HL) RET Z POP HL INC (IY-100+VRS.DelyCnt) INC (IY-100+VRS.ChanA+CHP.NtSkCn) XOR A LD (IY-100+VRS.AYREGS+AmplA),A LD (IY-100+VRS.AYREGS+AmplB),A LD (IY-100+VRS.AYREGS+AmplC),A RET ENDIF MUTE: XOR A LD H,A LD L,A LD (VARS1+VRS.AYREGS+AmplA),A LD (VARS1+VRS.AYREGS+AmplB),HL LD (VARS2+VRS.AYREGS+AmplA),A LD (VARS2+VRS.AYREGS+AmplB),HL JP ROUT INIT: ;HL - AddressOfModule ;DE - AddresOf2ndModule PUSH DE PUSH HL LD HL,VARS LD (HL),0 LD DE,VARS+1 LD BC,VAR0END-VARS-1 LDIR INC HL LD (VARS1+VRS.AdInPtA),HL ;ptr to zero LD (VARS2+VRS.AdInPtA),HL POP HL LD IY,VARS1+100 LD A,(START+10) AND 2 JP NZ,I_PT2 CALL INITPT3 LD HL,(e_-SamCnv-2)*256+#18 LD (SamCnv),HL LD A,#BA LD (OrnCP),A LD (SamCP),A LD A,#7B LD (OrnLD),A LD (SamLD),A LD A,#87 LD (SamClc2),A POP HL ;Use version and ton table of 1st module LD A,(IX+13-100) ;EXTRACT VERSION NUMBER SUB #30 JR C,L20 CP 10 JR C,L21 L20 LD A,6 L21 LD (Version),A PUSH AF ;VolTable version CP 4 LD A,(IX+99-100) ;TONE TABLE NUMBER RLA AND 7 PUSH AF ;NoteTable number LD IY,VARS2+100 LD A,(START+10) AND 48 JR Z,NOTS CP 16 JR Z,TwoPT3s LD A,(Version) CP 7 JR C,NOTS LD A,(IX+98-100) ;ALCO TS MARKER CP #20 JR Z,NOTS LD HL,VARS1 LD DE,VARS2 LD BC,VRS LDIR SET 1,(IY-100+VRS.ModNum) LD C,A ADD A,A ADD A,C SUB 2 LD (TSSub),A JR AlCoTS_ TwoPT3s CALL INITPT3 AlCoTS_ LD A,1 LD (is_ts),A SET 0,(IY-100+VRS.ModNum) NOTS LD BC,PT3PD LD HL,0 LD DE,PT3EMPTYORN JR INITCOMMON I_PT2 CALL INITPT2 LD HL,#51CB LD (SamCnv),HL LD A,#BB LD (OrnCP),A LD (SamCP),A LD A,#7A LD (OrnLD),A LD (SamLD),A LD A,#80 LD (SamClc2),A POP HL LD A,5 LD (Version),A PUSH AF LD A,2 PUSH AF LD A,(START+10) AND 48 JR Z,NOTS2 LD IY,VARS2+100 LD A,1 LD (is_ts),A SET 0,(IY-100+VRS.ModNum) CALL INITPT2 NOTS2 LD BC,PT2PD LD HL,#8687 LD DE,PT2EMPTYORN INITCOMMON IF Basic LD IY,#5C3A ENDIF LD (PTDEC),BC LD (PsCalc),HL PUSH DE ;note table data depacker ;(c) Ivan Roshin LD DE,T_PACK LD BC,T1_+(2*49)-1 TP_0 LD A,(DE) INC DE CP 15*2 JR NC,TP_1 LD H,A LD A,(DE) LD L,A INC DE JR TP_2 TP_1 PUSH DE LD D,0 LD E,A ADD HL,DE ADD HL,DE POP DE TP_2 LD A,H LD (BC),A DEC BC LD A,L LD (BC),A DEC BC SUB #F8*2 JR NZ,TP_0 INC A LD (VARS1+VRS.DelyCnt),A LD (VARS2+VRS.DelyCnt),A LD HL,#F001 ;H - CHP.Volume, L - CHP.NtSkCn LD (VARS1+VRS.ChanA+CHP.NtSkCn),HL LD (VARS1+VRS.ChanB+CHP.NtSkCn),HL LD (VARS1+VRS.ChanC+CHP.NtSkCn),HL LD (VARS2+VRS.ChanA+CHP.NtSkCn),HL LD (VARS2+VRS.ChanB+CHP.NtSkCn),HL LD (VARS2+VRS.ChanC+CHP.NtSkCn),HL POP HL LD (VARS1+VRS.ChanA+CHP.OrnPtr),HL LD (VARS1+VRS.ChanB+CHP.OrnPtr),HL LD (VARS1+VRS.ChanC+CHP.OrnPtr),HL LD (VARS2+VRS.ChanA+CHP.OrnPtr),HL LD (VARS2+VRS.ChanB+CHP.OrnPtr),HL LD (VARS2+VRS.ChanC+CHP.OrnPtr),HL POP AF ;NoteTableCreator (c) Ivan Roshin ;A - NoteTableNumber*2+VersionForNoteTable ;(xx1b - 3.xx..3.4r, xx0b - 3.4x..3.6x..VTII1.0) LD HL,NT_DATA LD D,0 ADD A,A LD E,A ADD HL,DE LD E,(HL) INC HL SRL E SBC A,A AND #A7 ;#00 (NOP) or #A7 (AND A) LD (L3),A EX DE,HL LD BC,T1_ ADD HL,BC LD A,(DE) ADD A,T_ LD C,A ADC A,T_/256 SUB C LD B,A PUSH BC LD DE,NT_ PUSH DE LD B,12 L1 PUSH BC LD C,(HL) INC HL PUSH HL LD B,(HL) PUSH DE EX DE,HL LD DE,23 LD IXH,8 L2 SRL B RR C L3 DB #19 ;AND A or NOP LD A,C ADC A,D ;=ADC 0 LD (HL),A INC HL LD A,B ADC A,D LD (HL),A ADD HL,DE DEC IXH JR NZ,L2 POP DE INC DE INC DE POP HL INC HL POP BC DJNZ L1 POP HL POP DE LD A,E CP TCOLD_1 JR NZ,CORR_1 LD A,#FD LD (NT_+#2E),A CORR_1 LD A,(DE) AND A JR Z,TC_EXIT RRA PUSH AF ADD A,A LD C,A ADD HL,BC POP AF JR NC,CORR_2 DEC (HL) DEC (HL) CORR_2 INC (HL) AND A SBC HL,BC INC DE JR CORR_1 TC_EXIT POP AF ;VolTableCreator (c) Ivan Roshin ;A - VersionForVolumeTable (0..4 - 3.xx..3.4x; ;5.. - 2.x,3.5x..3.6x..VTII1.0) CP 5 LD HL,#11 LD D,H LD E,H LD A,#17 JR NC,M1 DEC L LD E,L XOR A M1 LD (M2),A LD IX,VT_+16 LD C,#F INITV2 PUSH HL ADD HL,DE EX DE,HL SBC HL,HL LD B,#10 INITV1 LD A,L M2 DB #7D LD A,H ADC A,0 LD (IX),A INC IX ADD HL,DE DJNZ INITV1 POP HL LD A,E CP #77 JR NZ,M3 INC E M3 DEC C JR NZ,INITV2 JP ROUT INITPT3 CALL SETMDAD PUSH HL LD DE,100 ADD HL,DE LD A,(HL) LD (IY-100+VRS.Delay),A PUSH HL POP IX ADD HL,DE CALL SETCPPT LD E,(IX+102-100) INC HL IF CurPosCounter LD (IY-100+VRS.PosSub),L ENDIF ADD HL,DE CALL SETLPPT POP DE LD L,(IX+103-100) LD H,(IX+104-100) ADD HL,DE CALL SETPTPT LD HL,169 ADD HL,DE CALL SETORPT LD HL,105 ADD HL,DE SETSMPT LD (IY-100+VRS.SamPtrs),L LD (IY-100+VRS.SamPtrs+1),H RET INITPT2 LD A,(HL) LD (IY-100+VRS.Delay),A PUSH HL PUSH HL PUSH HL INC HL INC HL LD A,(HL) INC HL CALL SETSMPT LD E,(HL) INC HL LD D,(HL) POP HL AND A SBC HL,DE CALL SETMDAD POP HL LD DE,67 ADD HL,DE CALL SETORPT LD E,32 ADD HL,DE LD C,(HL) INC HL LD B,(HL) LD E,30 ADD HL,DE CALL SETCPPT LD E,A INC HL IF CurPosCounter LD (IY-100+VRS.PosSub),L ENDIF ADD HL,DE CALL SETLPPT POP HL ADD HL,BC SETPTPT LD (IY-100+VRS.PatsPtr),L LD (IY-100+VRS.PatsPtr+1),H RET SETMDAD LD (IY-100+VRS.MODADDR),L LD (IY-100+VRS.MODADDR+1),H RET SETORPT LD (IY-100+VRS.OrnPtrs),L LD (IY-100+VRS.OrnPtrs+1),H RET SETCPPT LD (IY-100+VRS.CrPsPtr),L LD (IY-100+VRS.CrPsPtr+1),H RET SETLPPT LD (IY-100+VRS.LPosPtr),L LD (IY-100+VRS.LPosPtr+1),H RET SETENBS LD (IY-100+VRS.EnvBase),L LD (IY-100+VRS.EnvBase+1),H RET SETESLD LD (IY-100+VRS.CurESld),L LD (IY-100+VRS.CurESld+1),H RET GETIX PUSH IY POP IX ADD IX,DE RET PTDECOD CALL GETIX PTDEC EQU $+1 JP #C3C3 ;PT2 pattern decoder PD2_SAM CALL SETSAM JR PD2_LOOP PD2_EOff LD (IX-12+CHP.Env_En),A JR PD2_LOOP PD2_ENV LD (IX-12+CHP.Env_En),16 LD (IY-100+VRS.AYREGS+EnvTp),A LD A,(BC) INC BC LD L,A LD A,(BC) INC BC LD H,A CALL SETENBS JR PD2_LOOP PD2_ORN CALL SETORN JR PD2_LOOP PD2_SKIP INC A LD (IX-12+CHP.NNtSkp),A JR PD2_LOOP PD2_VOL RRCA RRCA RRCA RRCA LD (IX-12+CHP.Volume),A JR PD2_LOOP PD2_DEL CALL C_DELAY JR PD2_LOOP PD2_GLIS SET 2,(IX-12+CHP.Flags) INC A LD (IX-12+CHP.TnSlDl),A LD (IX-12+CHP.TSlCnt),A LD A,(BC) INC BC LD (IX-12+CHP.TSlStp),A ADD A,A SBC A,A LD (IX-12+CHP.TSlStp+1),A SCF JR PD2_LP2 PT2PD AND A PD2_LP2 EX AF,AF' PD2_LOOP LD A,(BC) INC BC ADD A,#20 JR Z,PD2_REL JR C,PD2_SAM ADD A,96 JR C,PD2_NOTE INC A JR Z,PD2_EOff ADD A,15 JP Z,PD_FIN JR C,PD2_ENV ADD A,#10 JR C,PD2_ORN ADD A,#40 JR C,PD2_SKIP ADD A,#10 JR C,PD2_VOL INC A JR Z,PD2_DEL INC A JR Z,PD2_GLIS INC A JR Z,PD2_PORT INC A JR Z,PD2_STOP LD A,(BC) INC BC LD (IX-12+CHP.CrNsSl),A JR PD2_LOOP PD2_PORT RES 2,(IX-12+CHP.Flags) LD A,(BC) INC BC INC BC ;ignoring precalc delta to right sound INC BC SCF JR PD2_LP2 PD2_STOP LD (IX-12+CHP.TSlCnt),A JR PD2_LOOP PD2_REL LD (IX-12+CHP.Flags),A JR PD2_EXIT PD2_NOTE LD L,A LD A,(IX-12+CHP.Note) LD (PrNote+1),A LD (IX-12+CHP.Note),L XOR A LD (IX-12+CHP.TSlCnt),A SET 0,(IX-12+CHP.Flags) EX AF,AF' JR NC,NOGLIS2 BIT 2,(IX-12+CHP.Flags) JR NZ,NOPORT2 LD (LoStep),A ADD A,A SBC A,A EX AF,AF' LD H,A LD L,A INC A CALL SETPORT NOPORT2 LD (IX-12+CHP.TSlCnt),1 NOGLIS2 XOR A PD2_EXIT LD (IX-12+CHP.PsInSm),A LD (IX-12+CHP.PsInOr),A LD (IX-12+CHP.CrTnSl),A LD (IX-12+CHP.CrTnSl+1),A JP PD_FIN ;PT3 pattern decoder PD_OrSm LD (IX-12+CHP.Env_En),0 CALL SETORN PD_SAM_ LD A,(BC) INC BC RRCA PD_SAM CALL SETSAM JR PD_LOOP PD_VOL RRCA RRCA RRCA RRCA LD (IX-12+CHP.Volume),A JR PD_LP2 PD_EOff LD (IX-12+CHP.Env_En),A LD (IX-12+CHP.PsInOr),A JR PD_LP2 PD_SorE DEC A JR NZ,PD_ENV LD A,(BC) INC BC LD (IX-12+CHP.NNtSkp),A JR PD_LP2 PD_ENV CALL SETENV JR PD_LP2 PD_ORN CALL SETORN JR PD_LOOP PD_ESAM LD (IX-12+CHP.Env_En),A LD (IX-12+CHP.PsInOr),A CALL NZ,SETENV JR PD_SAM_ PT3PD LD A,(IX-12+CHP.Note) LD (PrNote+1),A LD L,(IX-12+CHP.CrTnSl) LD H,(IX-12+CHP.CrTnSl+1) LD (PrSlide+1),HL PD_LOOP LD DE,#2010 PD_LP2 LD A,(BC) INC BC ADD A,E JR C,PD_OrSm ADD A,D JR Z,PD_FIN JR C,PD_SAM ADD A,E JR Z,PD_REL JR C,PD_VOL ADD A,E JR Z,PD_EOff JR C,PD_SorE ADD A,96 JR C,PD_NOTE ADD A,E JR C,PD_ORN ADD A,D JR C,PD_NOIS ADD A,E JR C,PD_ESAM ADD A,A LD E,A LD HL,SPCCOMS+#FF20-#2000 ADD HL,DE LD E,(HL) INC HL LD D,(HL) PUSH DE JR PD_LOOP PD_NOIS LD (IY-100+VRS.Ns_Base),A JR PD_LP2 PD_REL RES 0,(IX-12+CHP.Flags) JR PD_RES PD_NOTE LD (IX-12+CHP.Note),A SET 0,(IX-12+CHP.Flags) XOR A PD_RES LD (PDSP_+1),SP LD SP,IX LD H,A LD L,A PUSH HL PUSH HL PUSH HL PUSH HL PUSH HL PUSH HL PDSP_ LD SP,#3131 PD_FIN LD A,(IX-12+CHP.NNtSkp) LD (IX-12+CHP.NtSkCn),A RET C_PORTM LD A,(BC) INC BC ;SKIP PRECALCULATED TONE DELTA (BECAUSE ;CANNOT BE RIGHT AFTER PT3 COMPILATION) INC BC INC BC EX AF,AF' LD A,(BC) ;SIGNED TONE STEP INC BC LD (LoStep),A LD A,(BC) INC BC AND A EX AF,AF' LD L,(IX-12+CHP.CrTnSl) LD H,(IX-12+CHP.CrTnSl+1) ;Set portamento variables ;A - Delay; A' - Hi(Step); ZF' - (A'=0); HL - CrTnSl SETPORT RES 2,(IX-12+CHP.Flags) LD (IX-12+CHP.TnSlDl),A LD (IX-12+CHP.TSlCnt),A PUSH HL LD DE,NT_ LD A,(IX-12+CHP.Note) LD (IX-12+CHP.SlToNt),A ADD A,A LD L,A LD H,0 ADD HL,DE LD A,(HL) INC HL LD H,(HL) LD L,A PUSH HL PrNote LD A,#3E LD (IX-12+CHP.Note),A ADD A,A LD L,A LD H,0 ADD HL,DE LD E,(HL) INC HL LD D,(HL) POP HL SBC HL,DE LD (IX-12+CHP.TnDelt),L LD (IX-12+CHP.TnDelt+1),H POP DE Version EQU $+1 LD A,#3E CP 6 JR C,OLDPRTM ;Old 3xxx for PT v3.5- PrSlide LD DE,#1111 LD (IX-12+CHP.CrTnSl),E LD (IX-12+CHP.CrTnSl+1),D LoStep EQU $+1 OLDPRTM LD A,#3E EX AF,AF' JR Z,NOSIG EX DE,HL NOSIG SBC HL,DE JP P,SET_STP CPL EX AF,AF' NEG EX AF,AF' SET_STP LD (IX-12+CHP.TSlStp+1),A EX AF,AF' LD (IX-12+CHP.TSlStp),A LD (IX-12+CHP.COnOff),0 RET C_GLISS SET 2,(IX-12+CHP.Flags) LD A,(BC) INC BC LD (IX-12+CHP.TnSlDl),A AND A JR NZ,GL36 LD A,(Version) ;AlCo PT3.7+ CP 7 SBC A,A INC A GL36 LD (IX-12+CHP.TSlCnt),A LD A,(BC) INC BC EX AF,AF' LD A,(BC) INC BC JR SET_STP C_SMPOS LD A,(BC) INC BC LD (IX-12+CHP.PsInSm),A RET C_ORPOS LD A,(BC) INC BC LD (IX-12+CHP.PsInOr),A RET C_VIBRT LD A,(BC) INC BC LD (IX-12+CHP.OnOffD),A LD (IX-12+CHP.COnOff),A LD A,(BC) INC BC LD (IX-12+CHP.OffOnD),A XOR A LD (IX-12+CHP.TSlCnt),A LD (IX-12+CHP.CrTnSl),A LD (IX-12+CHP.CrTnSl+1),A RET C_ENGLS LD A,(BC) INC BC LD (IY-100+VRS.Env_Del),A LD (IY-100+VRS.CurEDel),A LD A,(BC) INC BC LD L,A LD A,(BC) INC BC LD H,A LD (IY-100+VRS.ESldAdd),L LD (IY-100+VRS.ESldAdd+1),H RET C_DELAY LD A,(BC) INC BC LD (IY-100+VRS.Delay),A LD HL,VARS2+VRS.ModNum ;if AlCo_TS BIT 1,(HL) RET Z LD (VARS1+VRS.Delay),A LD (VARS1+VRS.DelyCnt),A LD (VARS2+VRS.Delay),A RET SETENV LD (IX-12+CHP.Env_En),E LD (IY-100+VRS.AYREGS+EnvTp),A LD A,(BC) INC BC LD H,A LD A,(BC) INC BC LD L,A CALL SETENBS XOR A LD (IX-12+CHP.PsInOr),A LD (IY-100+VRS.CurEDel),A LD H,A LD L,A JP SETESLD SETORN ADD A,A LD E,A LD D,0 LD (IX-12+CHP.PsInOr),D LD L,(IY-100+VRS.OrnPtrs) LD H,(IY-100+VRS.OrnPtrs+1) ADD HL,DE LD E,(HL) INC HL LD D,(HL) LD L,(IY-100+VRS.MODADDR) LD H,(IY-100+VRS.MODADDR+1) ADD HL,DE LD (IX-12+CHP.OrnPtr),L LD (IX-12+CHP.OrnPtr+1),H C_NOP RET SETSAM ADD A,A LD E,A LD D,0 LD L,(IY-100+VRS.SamPtrs); LD H,(IY-100+VRS.SamPtrs+1); ADD HL,DE LD E,(HL) INC HL LD D,(HL) LD L,(IY-100+VRS.MODADDR) LD H,(IY-100+VRS.MODADDR+1) ADD HL,DE LD (IX-12+CHP.SamPtr),L LD (IX-12+CHP.SamPtr+1),H RET ;ALL 16 ADDRESSES TO PROTECT FROM BROKEN PT3 MODULES SPCCOMS DW C_NOP DW C_GLISS DW C_PORTM DW C_SMPOS DW C_ORPOS DW C_VIBRT DW C_NOP DW C_NOP DW C_ENGLS DW C_DELAY DW C_NOP DW C_NOP DW C_NOP DW C_NOP DW C_NOP DW C_NOP CHREGS CALL GETIX XOR A LD (Ampl),A BIT 0,(IX+CHP.Flags) PUSH HL JP Z,CH_EXIT LD (CSP_+1),SP LD L,(IX+CHP.OrnPtr) LD H,(IX+CHP.OrnPtr+1) LD SP,HL POP DE LD H,A LD A,(IX+CHP.PsInOr) LD L,A ADD HL,SP INC A ;PT2 PT3 OrnCP INC A ;CP E CP D JR C,CH_ORPS OrnLD DB 1 ;LD A,D LD A,E CH_ORPS LD (IX+CHP.PsInOr),A LD A,(IX+CHP.Note) ADD A,(HL) JP P,CH_NTP XOR A CH_NTP CP 96 JR C,CH_NOK LD A,95 CH_NOK ADD A,A EX AF,AF' LD L,(IX+CHP.SamPtr) LD H,(IX+CHP.SamPtr+1) LD SP,HL POP DE LD H,0 LD A,(IX+CHP.PsInSm) LD B,A ADD A,A SamClc2 ADD A,A ;or ADD A,B for PT2 LD L,A ADD HL,SP LD SP,HL LD A,B INC A ;PT2 PT3 SamCP INC A ;CP E CP D JR C,CH_SMPS SamLD DB 1 ;LD A,D LD A,E CH_SMPS LD (IX+CHP.PsInSm),A POP BC POP HL ;Convert PT2 sample to PT3 ;PT2 PT3 SamCnv POP HL ;BIT 2,C JR e_ POP HL LD H,B JR NZ,$+8 EX DE,HL AND A SBC HL,HL SBC HL,DE LD D,C RR C SBC A,A CPL AND #3E RR C RR B AND C LD C,A LD A,B RRA RRA RR D RRA AND #9F LD B,A e_ LD E,(IX+CHP.TnAcc) LD D,(IX+CHP.TnAcc+1) ADD HL,DE BIT 6,B JR Z,CH_NOAC LD (IX+CHP.TnAcc),L LD (IX+CHP.TnAcc+1),H CH_NOAC EX DE,HL EX AF,AF' ADD A,NT_ LD L,A ADC A,NT_/256 SUB L LD H,A LD SP,HL POP HL ADD HL,DE LD E,(IX+CHP.CrTnSl) LD D,(IX+CHP.CrTnSl+1) ADD HL,DE CSP_ LD SP,#3131 EX (SP),HL XOR A OR (IX+CHP.TSlCnt) JR Z,CH_AMP DEC (IX+CHP.TSlCnt) JR NZ,CH_AMP LD A,(IX+CHP.TnSlDl) LD (IX+CHP.TSlCnt),A LD L,(IX+CHP.TSlStp) LD H,(IX+CHP.TSlStp+1) LD A,H ADD HL,DE LD (IX+CHP.CrTnSl),L LD (IX+CHP.CrTnSl+1),H BIT 2,(IX+CHP.Flags) JR NZ,CH_AMP LD E,(IX+CHP.TnDelt) LD D,(IX+CHP.TnDelt+1) AND A JR Z,CH_STPP EX DE,HL CH_STPP SBC HL,DE JP M,CH_AMP LD A,(IX+CHP.SlToNt) LD (IX+CHP.Note),A XOR A LD (IX+CHP.TSlCnt),A LD (IX+CHP.CrTnSl),A LD (IX+CHP.CrTnSl+1),A CH_AMP LD A,(IX+CHP.CrAmSl) BIT 7,C JR Z,CH_NOAM BIT 6,C JR Z,CH_AMIN CP 15 JR Z,CH_NOAM INC A JR CH_SVAM CH_AMIN CP -15 JR Z,CH_NOAM DEC A CH_SVAM LD (IX+CHP.CrAmSl),A CH_NOAM LD L,A LD A,B AND 15 ADD A,L JP P,CH_APOS XOR A CH_APOS CP 16 JR C,CH_VOL LD A,15 CH_VOL OR (IX+CHP.Volume) ADD A,VT_ LD L,A ADC A,VT_/256 SUB L LD H,A LD A,(HL) CH_ENV BIT 0,C JR NZ,CH_NOEN OR (IX+CHP.Env_En) CH_NOEN LD (Ampl),A BIT 7,B LD A,C JR Z,NO_ENSL RLA RLA SRA A SRA A SRA A ADD A,(IX+CHP.CrEnSl) ;SEE COMMENT BELOW BIT 5,B JR Z,NO_ENAC LD (IX+CHP.CrEnSl),A NO_ENAC ADD A,(IY-100+VRS.AddToEn) ;BUG IN PT3 - NEED WORD HERE LD (IY-100+VRS.AddToEn),A JR CH_MIX NO_ENSL RRA ADD A,(IX+CHP.CrNsSl) LD (IY-100+VRS.AddToNs),A BIT 5,B JR Z,CH_MIX LD (IX+CHP.CrNsSl),A CH_MIX LD A,B RRA AND #48 CH_EXIT OR (IY-100+VRS.AYREGS+Mixer) RRCA LD (IY-100+VRS.AYREGS+Mixer),A POP HL XOR A OR (IX+CHP.COnOff) RET Z DEC (IX+CHP.COnOff) RET NZ XOR (IX+CHP.Flags) LD (IX+CHP.Flags),A RRA LD A,(IX+CHP.OnOffD) JR C,CH_ONDL LD A,(IX+CHP.OffOnD) CH_ONDL LD (IX+CHP.COnOff),A RET PLAY_ XOR A LD (IY-100+VRS.AddToEn),A LD (IY-100+VRS.AYREGS+Mixer),A DEC A LD (IY-100+VRS.AYREGS+EnvTp),A DEC (IY-100+VRS.DelyCnt) JP NZ,PL2 DEC (IY-100+VRS.ChanA+CHP.NtSkCn) JR NZ,PL1B LD C,(IY-100+VRS.AdInPtA) LD B,(IY-100+VRS.AdInPtA+1) LD A,(BC) AND A JR NZ,PL1A LD D,A LD (IY-100+VRS.Ns_Base),A LD L,(IY-100+VRS.CrPsPtr) LD H,(IY-100+VRS.CrPsPtr+1) INC HL LD A,(HL) INC A JR NZ,PLNLP IF LoopChecker CALL CHECKLP ENDIF LD L,(IY-100+VRS.LPosPtr) LD H,(IY-100+VRS.LPosPtr+1) LD A,(HL) INC A PLNLP CALL SETCPPT DEC A BIT 1,(IY-100+VRS.ModNum) JR Z,NoAlCo TSSub EQU $+1 SUB #D6 CPL NoAlCo ;PT2 PT3 PsCalc DEC A ;ADD A,A NOP DEC A ;ADD A,(HL) NOP ADD A,A LD E,A RL D IF CurPosCounter LD A,L SUB (IY-100+VRS.PosSub) LD (IY-100+VRS.CurPos),A ENDIF LD L,(IY-100+VRS.PatsPtr) LD H,(IY-100+VRS.PatsPtr+1) ADD HL,DE LD E,(IY-100+VRS.MODADDR) LD D,(IY-100+VRS.MODADDR+1) LD (PSP_+1),SP LD SP,HL POP HL ADD HL,DE LD B,H LD C,L POP HL ADD HL,DE LD (IY-100+VRS.AdInPtB),L LD (IY-100+VRS.AdInPtB+1),H POP HL ADD HL,DE LD (IY-100+VRS.AdInPtC),L LD (IY-100+VRS.AdInPtC+1),H PSP_ LD SP,#3131 PL1A LD DE,VRS.ChanA+12-100 CALL PTDECOD LD (IY-100+VRS.AdInPtA),C LD (IY-100+VRS.AdInPtA+1),B PL1B DEC (IY-100+VRS.ChanB+CHP.NtSkCn) JR NZ,PL1C LD DE,VRS.ChanB+12-100 LD C,(IY-100+VRS.AdInPtB) LD B,(IY-100+VRS.AdInPtB+1) CALL PTDECOD LD (IY-100+VRS.AdInPtB),C LD (IY-100+VRS.AdInPtB+1),B PL1C DEC (IY-100+VRS.ChanC+CHP.NtSkCn) JR NZ,PL1D LD DE,VRS.ChanC+12-100 LD C,(IY-100+VRS.AdInPtC) LD B,(IY-100+VRS.AdInPtC+1) CALL PTDECOD LD (IY-100+VRS.AdInPtC),C LD (IY-100+VRS.AdInPtC+1),B PL1D LD A,(IY-100+VRS.Delay) LD (IY-100+VRS.DelyCnt),A PL2 LD DE,VRS.ChanA-100 LD L,(IY-100+VRS.AYREGS+TonA) LD H,(IY-100+VRS.AYREGS+TonA+1) CALL CHREGS LD (IY-100+VRS.AYREGS+TonA),L LD (IY-100+VRS.AYREGS+TonA+1),H Ampl EQU $+1 LD A,#3E LD (IY-100+VRS.AYREGS+AmplA),A LD DE,VRS.ChanB-100 LD L,(IY-100+VRS.AYREGS+TonB) LD H,(IY-100+VRS.AYREGS+TonB+1) CALL CHREGS LD (IY-100+VRS.AYREGS+TonB),L LD (IY-100+VRS.AYREGS+TonB+1),H LD A,(Ampl) LD (IY-100+VRS.AYREGS+AmplB),A LD DE,VRS.ChanC-100 LD L,(IY-100+VRS.AYREGS+TonC) LD H,(IY-100+VRS.AYREGS+TonC+1) CALL CHREGS LD (IY-100+VRS.AYREGS+TonC),L LD (IY-100+VRS.AYREGS+TonC+1),H LD A,(Ampl) LD (IY-100+VRS.AYREGS+AmplC),A LD A,(IY-100+VRS.Ns_Base) ADD (IY-100+VRS.AddToNs) LD (IY-100+VRS.AYREGS+Noise),A LD A,(IY-100+VRS.AddToEn) LD E,A ADD A,A SBC A,A LD D,A LD L,(IY-100+VRS.EnvBase) LD H,(IY-100+VRS.EnvBase+1) ADD HL,DE LD E,(IY-100+VRS.CurESld) LD D,(IY-100+VRS.CurESld+1) ADD HL,DE LD (IY-100+VRS.AYREGS+Env),L LD (IY-100+VRS.AYREGS+Env+1),H XOR A OR (IY-100+VRS.CurEDel) RET Z DEC (IY-100+VRS.CurEDel) RET NZ LD A,(IY-100+VRS.Env_Del) LD (IY-100+VRS.CurEDel),A LD L,(IY-100+VRS.ESldAdd) LD H,(IY-100+VRS.ESldAdd+1) ADD HL,DE JP SETESLD PLAY LD IY,VARS1+100 CALL PLAY_ LD A,(is_ts) AND A JR Z,PL_nts LD IY,VARS2+100 CALL PLAY_ PL_nts IF Basic LD IY,#5C3A ENDIF ROUT LD BC,#FFFD LD A,(is_ts) AND A JR Z,r_nts ;keep old standard OUT (C),B r_nts EX AF,AF' IF ACBBAC LD IX,VARS1+VRS.AYREGS ELSE LD HL,VARS1+VRS.AYREGS ENDIF CALL ROUT_ EX AF,AF' RET Z LD B,D CPL OUT (C),A IF ACBBAC LD IX,VARS2+VRS.AYREGS ELSE LD HL,VARS2+VRS.AYREGS ENDIF ROUT_ IF ACBBAC LD A,(SETUP) AND 12 JR Z,ABC ADD A,CHTABLE LD E,A ADC A,CHTABLE/256 SUB E LD D,A LD B,0 PUSH IX POP HL LD A,(DE) INC DE LD C,A ADD HL,BC LD A,(IX+TonB) LD C,(HL) LD (IX+TonB),C LD (HL),A INC HL LD A,(IX+TonB+1) LD C,(HL) LD (IX+TonB+1),C LD (HL),A LD A,(DE) INC DE LD C,A ADD HL,BC LD A,(IX+AmplB) LD C,(HL) LD (IX+AmplB),C LD (HL),A LD A,(DE) INC DE LD (RxCA1),A XOR 8 LD (RxCA2),A LD A,(DE) AND (IX+Mixer) LD E,A LD A,(IX+Mixer) RxCA1 DB #E6 AND %010010 OR E LD E,A LD A,(IX+Mixer) AND %010010 RxCA2 OR E OR E LD (IX+Mixer),A ABC ENDIF XOR A LD DE,#FFBF IF ACBBAC LD BC,#FFFD PUSH IX POP HL ENDIF LOUT OUT (C),A LD B,E OUTI LD B,D INC A CP 13 JR NZ,LOUT OUT (C),A LD A,(HL) AND A RET M LD B,E OUT (C),A RET IF ACBBAC CHTABLE EQU $-4 DB 4,5,15,%001001,0,7,7,%100100 ENDIF NT_DATA DB (T_NEW_0-T1_)*2 DB TCNEW_0-T_ DB (T_OLD_0-T1_)*2+1 DB TCOLD_0-T_ DB (T_NEW_1-T1_)*2+1 DB TCNEW_1-T_ DB (T_OLD_1-T1_)*2+1 DB TCOLD_1-T_ DB (T_NEW_2-T1_)*2 DB TCNEW_2-T_ DB (T_OLD_2-T1_)*2 DB TCOLD_2-T_ DB (T_NEW_3-T1_)*2 DB TCNEW_3-T_ DB (T_OLD_3-T1_)*2 DB TCOLD_3-T_ T_ TCOLD_0 DB #00+1,#04+1,#08+1,#0A+1,#0C+1,#0E+1,#12+1,#14+1 DB #18+1,#24+1,#3C+1,0 TCOLD_1 DB #5C+1,0 TCOLD_2 DB #30+1,#36+1,#4C+1,#52+1,#5E+1,#70+1,#82,#8C,#9C DB #9E,#A0,#A6,#A8,#AA,#AC,#AE,#AE,0 TCNEW_3 DB #56+1 TCOLD_3 DB #1E+1,#22+1,#24+1,#28+1,#2C+1,#2E+1,#32+1,#BE+1,0 TCNEW_0 DB #1C+1,#20+1,#22+1,#26+1,#2A+1,#2C+1,#30+1,#54+1 DB #BC+1,#BE+1,0 TCNEW_1 EQU TCOLD_1 TCNEW_2 DB #1A+1,#20+1,#24+1,#28+1,#2A+1,#3A+1,#4C+1,#5E+1 DB #BA+1,#BC+1,#BE+1,0 PT3EMPTYORN EQU $-1 DB 1,0 ;first 12 values of tone tables (packed) T_PACK DB #06EC*2/256,#06EC*2 DB #0755-#06EC DB #07C5-#0755 DB #083B-#07C5 DB #08B8-#083B DB #093D-#08B8 DB #09CA-#093D DB #0A5F-#09CA DB #0AFC-#0A5F DB #0BA4-#0AFC DB #0C55-#0BA4 DB #0D10-#0C55 DB #066D*2/256,#066D*2 DB #06CF-#066D DB #0737-#06CF DB #07A4-#0737 DB #0819-#07A4 DB #0894-#0819 DB #0917-#0894 DB #09A1-#0917 DB #0A33-#09A1 DB #0ACF-#0A33 DB #0B73-#0ACF DB #0C22-#0B73 DB #0CDA-#0C22 DB #0704*2/256,#0704*2 DB #076E-#0704 DB #07E0-#076E DB #0858-#07E0 DB #08D6-#0858 DB #095C-#08D6 DB #09EC-#095C DB #0A82-#09EC DB #0B22-#0A82 DB #0BCC-#0B22 DB #0C80-#0BCC DB #0D3E-#0C80 DB #07E0*2/256,#07E0*2 DB #0858-#07E0 DB #08E0-#0858 DB #0960-#08E0 DB #09F0-#0960 DB #0A88-#09F0 DB #0B28-#0A88 DB #0BD8-#0B28 DB #0C80-#0BD8 DB #0D60-#0C80 DB #0E10-#0D60 DB #0EF8-#0E10 ;vars from here can be stripped ;you can move VARS to any other address VARS is_ts DB 0 ;ChannelsVars STRUCT CHP ;reset group PsInOr DB 0 PsInSm DB 0 CrAmSl DB 0 CrNsSl DB 0 CrEnSl DB 0 TSlCnt DB 0 CrTnSl DW 0 TnAcc DW 0 COnOff DB 0 ;reset group OnOffD DB 0 ;IX for PTDECOD here (+12) OffOnD DB 0 OrnPtr DW 0 SamPtr DW 0 NNtSkp DB 0 Note DB 0 SlToNt DB 0 Env_En DB 0 Flags DB 0 ;Enabled - 0, SimpleGliss - 2 TnSlDl DB 0 TSlStp DW 0 TnDelt DW 0 NtSkCn DB 0 Volume DB 0 ENDS STRUCT VRS ;IF not works in STRUCT in SjASM :( ; IF CurPosCounter CurPos DB 0 PosSub DB 0 ; ENDIF ModNum DB 0 ;bit0: ChipNum ;bit1: 1-reversed patterns order (AlCo TS) ChanA DS CHP ChanB DS CHP ChanC DS CHP ;GlobalVars MODADDR DW 0 OrnPtrs DW 0 SamPtrs DW 0 PatsPtr DW 0 AdInPtA DW 0 AdInPtB DW 0 AdInPtC DW 0 CrPsPtr DW 0 LPosPtr DW 0 Delay DB 0 DelyCnt DB 0 ESldAdd DW 0 CurESld DW 0 Env_Del DB 0 CurEDel DB 0 Ns_Base DB 0 AddToNs DB 0 AddToEn DB 0 EnvBase DW 0 AYREGS DS 14 ENDS VARS1 DS VRS VARS2 DS VRS VT_ EQU $-16 DS 256-16 ;CreatedVolumeTableAddress T1_ EQU VT_+16 ;Tone tables data depacked here T_OLD_1 EQU T1_ T_OLD_2 EQU T_OLD_1+24 T_OLD_3 EQU T_OLD_2+24 T_OLD_0 EQU T_OLD_3+2 T_NEW_0 EQU T_OLD_0 T_NEW_1 EQU T_OLD_1 T_NEW_2 EQU T_NEW_0+24 T_NEW_3 EQU T_OLD_3 PT2EMPTYORN EQU VT_+31 ;1,0,0 sequence NT_ DS 192 ;CreatedNoteTableAddress VAR0END EQU VT_+16 ;INIT zeroes from VARS to VAR0END-1 VARSEND EQU $ MDLADDR EQU songdata ;Release 0 steps: ;04/21/2007 ;Works start (PTxPlay adaptation); first beta. ;04/22/2007 ;Job finished; beta-testing. ;04/23/2007 ;PT v3.7 TS mode corrected (after AlCo remarks). ;04/29/2007 ;Added 1.XX and 2.XX special commands interpretation for PT3 ;modules of v3.7+. ;Size (minimal build for ZX Spectrum): ;Code block #908 bytes ;Variables #2BF bytes (can be stripped) ;Total size #908+#2BF=#BC7 (3015) bytes ENDMODULE ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** ;*************************** module stp @NULL = 0 ;------------------------------------------------------------------------------ music_init: ld hl,songdata music_init0: ld (module_addr+1),hl ld a,#FC ld (ChA.smppos+1),a ld (ChB.smppos+1),a ld (ChC.smppos+1),a ld a,(hl) inc hl ld (speed+1),a call add_offset.de ld a,(hl) ld (song_length+1),a inc hl ld a,(hl) ld (loop_position+1),a inc hl ld (positions+1),hl call add_offset ld (patterns+1),hl push hl call add_offset ld (ChA.ornoffs+1),hl ld (ChB.ornoffs+1),hl ld (ChC.ornoffs+1),hl call add_offset ld (ChA.smpoffs+1),hl ld (ChB.smpoffs+1),hl ld (ChC.smpoffs+1),hl ex de,hl ld a,(hl) ld (hl),0 pop hl or a jr z,.noreloc .relocator: call add_offset.de ex de,hl dec hl ld (hl),d dec hl ld (hl),e inc hl inc hl dec a jr nz,.relocator .noreloc: ld hl,empty_pattern ld c,3 ld (ChA.datptr+1),hl ld (ChB.datptr+1),hl ld (ChC.datptr+1),hl ld h,a ld l,a ld (ChA.Xportamnt+1),hl ld (ChB.Xportamnt+1),hl ld (ChA.Xpitch+1),hl ld (ChB.Xpitch+1),hl ld (ChC.playback+2),a ld (chkfadeout+1),a ld (apply_volume+1),a ld (ChA.attn+1),a ld (ChB.attn+1),a ld (ChC.attn+1),a dec a ld (current_pos+1),a ld hl,music_setup res 7,(hl) music_mute: xor a ld (AYREG_EnvSh+1),a ld hl,AYREG_TonA ld b,#0D .loopregs: ld (hl),a inc hl djnz .loopregs ld a,c ld (tempocnt_0),a ld bc,#FFFD ld a,#0C out (c),a xor a ld b,#BF out (c),a jp outay add_offset ex de,hl .de ld e,(hl) inc hl ld d,(hl) inc hl ex de,hl module_addr: ld bc,0 add hl,bc ret ; --------------------------------------------------------------------------- resetfadeout: ld hl,music_setup noloop: set 7,(hl) xor a ld (AYREG_AmplA),a ld (AYREG_AmplB),a ld (AYREG_AmplC),a ld (AYREG_EnvSh+1),a dec a ld (tempocnt_0),a ld (chkfadeout+1),a ld xl,#3F jp retsp enablefade: ld a,48 forcefade: ld (chkfadeout+1),a ld (countfadeout+1),a ld (divfadeout+1),a xor a ld (apply_volume+1),a jr loop_position ; --------------------------------------------------------------------------- new_position: ld hl,(ChB.datptr+1) or (hl) jp nz,chkfadeout ld hl,(ChC.datptr+1) or (hl) jp nz,chkfadeout ld b,a current_pos: ld a,0 inc a song_length: cp 0 jr nz,song_continue ld hl,music_setup bit 1,(hl) jr nz,enablefade bit 0,(hl) jr nz,noloop loop_position: ld a,0 song_continue: ld (current_pos+1),a ld c,a positions: ld hl,NULL add hl,bc add hl,bc ld c,(hl) inc hl ld a,(hl) patterns: ld hl,NULL add hl,bc ld sp,hl pop hl ld (ChA.datptr+1),hl pop hl ld (ChB.datptr+1),hl pop hl ld (ChC.datptr+1),hl add a,#60 ld (ChC.playback+2),a ld b,a ld c,#F0 jp ChA.datptr ; ---------------------------------------------------------------------------- music_play: di ld (retsp+1),sp ld d,0 exx ChC.playback: ld bc,#60F0 ld hl,tempocnt_0 dec (hl) jp nz,ChB.playback @speed: ld (hl),0 inc hl dec (hl) jp p,ChB.Xsmpptr ChC.datptr: ld hl,NULL or (hl) jp z,ChB.Xsmpptr ChC.readpatt: ld a,(hl) inc hl cp #C0 jr c,ChC.nocmd sub c jr nc,ChC.setvol sub c jp nc,ChC.nop sub c jr nc,ChC.setrst sub c jp ChC.setenv ChC.nocmd: sub #80 jr nc,ChC.setspd sub c jp nc,ChC.setorn sbc a,c jr nc,ChC.setsmp add a,b ld (ChC.note+1),a ld (ChC.datptr+1),hl xor a ld (ChC.smppos+1),a ld (ChC.ornpos+1),a ld l,a ld h,a ld (ChC.pitch+1),hl jp ChC.exit ChC.setport: ld a,(hl) inc hl ld (ChC.portamnt+1),a rla sbc a,a ld (ChC.portamnt+2),a jr ChC.readpatt ChC.setvol: jr z,ChC.setport dec a ld (ChC.volume+1),a jr ChC.readpatt ChC.setrst: ld a,#FC ld (ChC.smppos+1),a ld (ChC.datptr+1),hl jp ChC.exit ChC.setsmp: add a,a exx ld e,a ChC.smpoffs: ld hl,NULL add hl,de ld sp,hl pop hl ld a,(hl) add a,a add a,a ld (ChC.smploop+1),a inc hl ld a,(hl) add a,a add a,a ld (ChC.smplen+1),a ld (ChC.smpptr+1),hl exx jp ChC.readpatt ChC.setspd: ld (ChC.exit+1),a jp ChC.readpatt ChC.setenv: ld (env.shape+1),a ld a,#1F ld (ChC.ampl+1),a ld a,(hl) inc hl ld (env.period+1),a ld de,empty_orn ld (ChC.ornptr+1),de xor a ld (ChC.ornloop+1),a ld (ChC.portamnt+1),a ld (ChC.portamnt+2),a inc a ld (ChC.ornlen+1),a jp ChC.readpatt ChC.setorn: add a,a exx ld e,a ld a,#0F ld (ChC.ampl+1),a ChC.ornoffs: ld hl,NULL add hl,de ld sp,hl pop hl ld a,(hl) ld (ChC.ornloop+1),a inc hl ld a,(hl) ld (ChC.ornlen+1),a inc hl ld (ChC.ornptr+1),hl ld l,d ld h,d ld (ChC.portamnt+1),hl exx jp ChC.readpatt ; --------------------------------------------------------------------------- ChB.playback: ld a,(hl) dec a jp nz,ChA.playback ld hl,tempocnt_2 dec (hl) jp p,chkfadeout ChB.datptr: ld hl,NULL or (hl) jp z,chkfadeout ChB.readpatt: ld a,(hl) inc hl cp #C0 jr c,ChB.nocmd sub c jr nc,ChB.setvol sub c jr nc,ChB.nop sub c jr nc,ChB.setrst sub c jr ChB.setenv ChB.nocmd: sub #80 jr nc,ChB.setspd sub c jp nc,ChB.setorn sbc a,c jr nc,ChB.setsmp add a,b ld (ChB.Xnote+1),a ld (ChB.datptr+1),hl xor a ld (ChB.Xsmppos+1),a ld l,a ld h,a ld (ChB.Xpitch+1),hl ld a,#22 ld (ChB.Xinst1),a ld a,#32 ld (ChB.Xinst2),a jr ChB.exit ChB.setvol: jr z,ChB.setport dec a ld (ChB.Xvolume+1),a jr ChB.readpatt ChB.nop: ld (ChB.datptr+1),hl ChB.exit: ld a,0 ld (tempocnt_2),a jp chkfadeout ChB.setrst: ld a,#FC ld (ChB.Xsmppos+1),a ld (ChB.datptr+1),hl jr ChB.exit ChB.setsmp: add a,a exx ld e,a ChB.smpoffs: ld hl,NULL add hl,de ld sp,hl pop hl ld a,(hl) add a,a add a,a ld (ChB.Xsmploop+1),a inc hl ld a,(hl) add a,a add a,a ld (ChB.Xsmplen+1),a ld (ChB.Xsmpptr+1),hl exx jr ChB.readpatt ChB.setspd: ld (ChB.exit+1),a jr ChB.readpatt ChB.setenv: ld (env.shape+1),a ld a,#1F ld (ChB.Xampl+1),a ld a,(hl) inc hl ld (env.period+1),a ld de,empty_orn ld (ChB.Xornptr+1),de ld a,#22 ld (ChB.Xinst3),a xor a ld (ChB.Xornloop+1),a ld (ChB.Xportamnt+1),a ld (ChB.Xportamnt+2),a inc a ld (ChB.Xornlen+1),a jp ChB.readpatt ChB.setport: ld a,(hl) inc hl ld (ChB.Xportamnt+1),a rla sbc a,a ld (ChB.Xportamnt+2),a jp ChB.readpatt ChB.setorn: add a,a exx ld e,a ld a,#0F ld (ChB.Xampl+1),a ChB.ornoffs: ld hl,NULL add hl,de ld sp,hl pop hl ld a,(hl) ld (ChB.Xornloop+1),a inc hl ld a,(hl) ld (ChB.Xornlen+1),a inc hl ld (ChB.Xornptr+1),hl ld l,d ld h,d ld (ChB.Xportamnt+1),hl ld a,#22 ld (ChB.Xinst3),a exx jp ChB.readpatt ; --------------------------------------------------------------------------- ChA.playback: dec a jp nz,chkfadeout dec hl dec (hl) jp p,chkfadeout ChA.datptr: ld hl,NULL or (hl) jp z,new_position ChA.readpatt: ld a,(hl) inc hl cp #C0 jr c,ChA.nocmd sub c jr nc,ChA.setvol sub c jr nc,ChA.nop sub c jr nc,ChA.setrst sub c jr ChA.setenv ChA.nocmd: sub #80 jr nc,ChA.setspd sub c jp nc,ChA.setorn sbc a,c jr nc,ChA.setsmp add a,b ld (ChA.Xnote+1),a ld (ChA.datptr+1),hl xor a ld (ChA.Xsmppos+1),a ld l,a ld h,a ld (ChA.Xpitch+1),hl ld a,#22 ld (ChA.Xinst1),a ld a,#32 ld (ChA.Xinst2),a jr ChA.exit ChA.setvol: jr z,ChA.setport dec a ld (ChA.Xvolume+1),a jr ChA.readpatt ChA.nop: ld (ChA.datptr+1),hl ChA.exit: ld a,0 ld (tempocnt_1),a jp chkfadeout ChA.setrst: ld a,#FC ld (ChA.Xsmppos+1),a ld (ChA.datptr+1),hl jr ChA.exit ChA.setsmp: add a,a exx ld e,a ChA.smpoffs: ld hl,NULL add hl,de ld sp,hl pop hl ld a,(hl) add a,a add a,a ld (ChA.Xsmploop+1),a inc hl ld a,(hl) add a,a add a,a ld (ChA.Xsmplen+1),a ld (ChA.Xsmpptr+1),hl exx jr ChA.readpatt ChA.setspd: ld (ChA.exit+1),a jr ChA.readpatt ChA.setenv: ld (env.shape+1),a ld a,#1F ld (ChA.Xampl+1),a ld a,(hl) inc hl ld (env.period+1),a ld de,empty_orn ld (ChA.Xornptr+1),de ld a,#22 ld (ChA.Xinst3),a xor a ld (ChA.Xornloop+1),a ld (ChA.Xportamnt+1),a ld (ChA.Xportamnt+2),a inc a ld (ChA.Xornlen+1),a jp ChA.readpatt ChA.setport: ld a,(hl) inc hl ld (ChA.Xportamnt+1),a rla sbc a,a ld (ChA.Xportamnt+2),a jp ChA.readpatt ChA.setorn: add a,a exx ld e,a ld a,#0F ld (ChA.Xampl+1),a ChA.ornoffs: ld hl,NULL add hl,de ld sp,hl pop hl ld a,(hl) ld (ChA.Xornloop+1),a inc hl ld a,(hl) ld (ChA.Xornlen+1),a inc hl ld (ChA.Xornptr+1),hl ld l,d ld h,d ld (ChA.Xportamnt+1),hl ld a,#22 ld (ChA.Xinst3),a exx jp ChA.readpatt ; --------------------------------------------------------------------------- ChA.mute: xor a ld (AYREG_AmplA),a ld xl,9 jp ChB.ornpos ChB.mute: xor a ld (AYREG_AmplB),a ld a,xl or #12 ld xl,a jp ChC.ornpos ChC.mute: xor a ld (AYREG_AmplC),a ld a,xl or #24 ld xl,a jp retsp ; --------------------------------------------------------------------------- ChC.nop: ld (ChC.datptr+1),hl ChC.exit: ld a,0 ld (pattstep_cnt),a ChB.Xsmpptr: ld hl,NULL ld (ChB.smpptr+1),hl ChB.Xornptr: ld hl,NULL ld (ChB.ornptr+1),hl ChB.Xpitch: ld hl,NULL ChB.Xinst1: ld (ChB.pitch+1),hl ChB.Xportamnt: ld hl,NULL ChB.Xinst3: ld (ChB.portamnt+1),hl ChB.Xornlen: ld a,0 ld (ChB.ornlen+1),a ChB.Xsmplen: ld a,0 ld (ChB.smplen+1),a ChB.Xornloop: ld a,0 ld (ChB.ornloop+1),a ChB.Xsmploop: ld a,0 ld (ChB.smploop+1),a ChB.Xvolume: ld a,0 ld (ChB.volume+1),a ChB.Xampl: ld a,#0F ld (ChB.ampl+1),a ChB.Xnote: ld a,0 ld (ChB.note+1),a ChB.Xsmppos: ld a,0 cp 1 jr z,ChA.Xsmpptr ld (ChB.smppos+1),a ChA.Xsmpptr: ld hl,NULL ld (ChA.smpptr+1),hl ChA.Xornptr: ld hl,NULL ld (ChA.ornptr+1),hl ChA.Xpitch: ld hl,NULL ChA.Xinst1: ld (ChA.pitch+1),hl ChA.Xportamnt: ld hl,NULL ChA.Xinst3: ld (ChA.portamnt+1),hl ChA.Xornlen: ld a,0 ld (ChA.ornlen+1),a ChA.Xsmplen: ld a,0 ld (ChA.smplen+1),a ChA.Xornloop: ld a,0 ld (ChA.ornloop+1),a ChA.Xsmploop: ld a,0 ld (ChA.smploop+1),a ChA.Xvolume: ld a,0 ld (ChA.volume+1),a ChA.Xampl: ld a,#0F ld (ChA.ampl+1),a ChA.Xnote: ld a,0 ld (ChA.note+1),a ChA.Xsmppos: ld a,0 cp 1 jr z,env.shape ld (ChA.smppos+1),a env.shape: ld a,0 ld (AYREG_EnvSh+1),a env.period: ld a,0 ld (AYREG_Env+1),a xor a ld (env.shape+1),a ChA.Xinst2: ld (ChA.ornpos+1),a ChB.Xinst2: ld (ChB.ornpos+1),a inc a ld (ChA.Xsmppos+1),a ld (ChA.Xinst2),a ld (ChB.Xsmppos+1),a ld (ChB.Xinst2),a ld (ChA.Xinst1),a ld (ChB.Xinst1),a ; --------------------------------------------------------------------------- chkfadeout: ld a,0 or a jr z,ChA.ornpos ld a,(music_setup) rlca jp c,retsp countfadeout: ld a,0 dec a ld (countfadeout+1),a jr nz,ChA.ornpos ld e,16 apply_volume: ld a,0 inc a cp e jp z,resetfadeout ld (apply_volume+1),a ld (ChA.attn+1),a ld (ChB.attn+1),a ld (ChC.attn+1),a bit 3,a ; if value of attenuation jr z,divfadeout ; hits the 8 we turn off xor a ; also hw envelopes ld (env.shape+1),a ld (AYREG_EnvSh+1),a ld a,e dec a ld (ChA.ampl+1),a ld (ChB.ampl+1),a ld (ChC.ampl+1),a divfadeout: ld a,0 srl a ld e,a srl e add a,e jr nz,divfadeout1 inc a divfadeout1: ld (divfadeout+1),a add a,a ld (countfadeout+1),a ChA.ornpos: ld de,0 ChA.ornptr: ld hl,NULL add hl,de inc e ld a,e ChA.ornlen: cp 0 jr nz,ChA.readorn ChA.ornloop: ld a,0 ChA.readorn: ld (ChA.ornpos+1),a ChA.note: ld a,0 add a,(hl) add a,a ld e,a ld hl,freqtable add hl,de ld sp,hl ChA.smppos: ld a,0 ChA.smpptr: ld hl,NULL inc a jp m,ChA.mute ld e,a add hl,de add a,3 ChA.smplen: cp 0 jr nz,ChA.readsmp ChA.smploop: ld a,0 ChA.readsmp: ld (ChA.smppos+1),a pop bc ld sp,hl pop de ld h,0 ld a,e and #0F ChA.volume: sub 0 ld l,a ccf sbc a,a and l srl d jr nc,ChA.attn set 4,h ChA.attn: sub 0 jr nc,ChA.attnn xor a ChA.attnn: or h ChA.ampl: and 0 ld (AYREG_AmplA),a ld a,e rlca jr c,ChA.pitch ld xh,d ChA.pitch: ld hl,NULL ChA.portamnt: ld de,0 add hl,de ld (ChA.pitch+1),hl add hl,bc pop bc add hl,bc rlca rlca rlca and #0F ld xl,a ld a,h and #0F ld h,a ld (AYREG_TonA),hl ChB.ornpos: ld de,0 ChB.ornptr: ld hl,NULL add hl,de inc e ld a,e ChB.ornlen: cp 0 jr nz,ChB.readorn ChB.ornloop: ld a,0 ChB.readorn: ld (ChB.ornpos+1),a ChB.note: ld a,0 add a,(hl) add a,a ld e,a ld hl,freqtable add hl,de ld sp,hl ChB.smppos: ld a,NULL ChB.smpptr: ld hl,NULL inc a jp m,ChB.mute ld e,a add hl,de add a,3 ChB.smplen: cp 0 jr nz,ChB.readsmp ChB.smploop: ld a,0 ChB.readsmp: ld (ChB.smppos+1),a pop bc ld sp,hl pop de ld h,0 ld a,e and #0F ChB.volume: sub 0 ld l,a ccf sbc a,a and l srl d jr nc,ChB.attn set 4,h ChB.attn: sub 0 jr nc,ChB.attnn xor a ChB.attnn: or h ChB.ampl: and 0 ld (AYREG_AmplB),a ld a,e rrca rrca rrca and #1E or xl ld xl,a and #10 jr nz,ChB.pitch ld xh,d ChB.pitch: ld hl,NULL ChB.portamnt: ld de,0 add hl,de ld (ChB.pitch+1),hl add hl,bc pop bc add hl,bc ld a,h and #0F ld h,a ld (AYREG_TonB),hl ChC.ornpos: ld de,0 ChC.ornptr: ld hl,NULL add hl,de inc e ld a,e ChC.ornlen: cp 0 jr nz,ChC.readorn ChC.ornloop: ld a,0 ChC.readorn: ld (ChC.ornpos+1),a ChC.note: ld a,0 add a,(hl) add a,a ld e,a ld hl,freqtable add hl,de ld sp,hl ChC.smppos: ld a,0 ChC.smpptr: ld hl,NULL inc a jp m,ChC.mute ld e,a add hl,de add a,3 ChC.smplen: cp 0 jr nz,ChC.readsmp ChC.smploop: ld a,0 ChC.readsmp: ld (ChC.smppos+1),a pop bc ld sp,hl pop de ld h,0 ld a,e and #0F ChC.volume: sub 0 ld l,a ccf sbc a,a and l srl d jr nc,ChC.attn set 4,h ChC.attn: sub 0 jr nc,ChC.attnn xor a ChC.attnn: or h ChC.ampl: and 0 ld (AYREG_AmplC),a ld a,e rrca rrca and #3C or xl ld xl,a and #20 jr nz,ChC.pitch ld xh,d ChC.pitch: ld hl,NULL ChC.portamnt: ld de,0 add hl,de ld (ChC.pitch+1),hl add hl,bc pop bc add hl,bc ld a,h and #0F ld h,a ld (AYREG_TonC),hl @retsp: ld sp,0 outay: ld hl,AYREG_AmplC ld de,#FFBF ld bc,#FFFD ld a,#0D out (c),a AYREG_EnvSh: ld a,0 or a jr z,noenvelopes ld b,e out (c),a ld a,#0B ld b,d out (c),a ld b,e AYREG_Env: ld a,0 out (c),a ld b,d noenvelopes: ld a,#0A out (c),a ld b,e outd dec a ld b,d out (c),a ld b,e outd dec a ld b,d out (c),a ld b,e outd dec a ld b,d out (c),a ld b,e ld a,xl out (c),a ld a,6 ld b,d out (c),a ld b,e ld a,xh out (c),a ld a,5 ld b,d out (c),a ld b,e outd dec a ld b,d out (c),a ld b,e outd dec a ld b,d out (c),a ld b,e outd dec a ld b,d out (c),a ld b,e outd dec a ld b,d out (c),a ld b,e outd dec a ld b,d out (c),a ld b,e outd ld (AYREG_EnvSh+1),a ei ret ;------------------------------------------------------------------------------ freqtable dw #0EF8, #0E10, #0D60, #0C80, #0BD8, #0B28, #0A88, #09F0 dw #0960, #08E0, #0858, #07E0, #077C, #0708, #06B0, #0640 dw #05EC, #0594, #0544, #04F8, #04B0, #0470, #042C, #03F0 dw #03BE, #0384, #0358, #0320, #02F6, #02CA, #02A2, #027C dw #0258, #0238, #0216, #01F8, #01DF, #01C2, #01AC, #0190 dw #017B, #0165, #0151, #013E, #012C, #011C, #010B, #00FC dw #00EF, #00E1, #00D6, #00C8, #00BD, #00B2, #00A8, #009F dw #0096, #008E, #0085, #007E, #0077, #0070, #006B, #0064 dw #005E, #0059, #0054, #004F, #004B, #0047, #0042, #003F dw #003B, #0038, #0035, #0032, #002F, #002C, #002A, #0027 dw #0025, #0023, #0021, #001F, #001D, #001C, #001A, #0019 dw #0017, #0016, #0015, #0013, #0012, #0011, #0010, #000F empty_orn: db #00, #00, #00 empty_pattern: db #70, #80, #F1, #D0, #00 AYREG_TonA: dw 0 AYREG_TonB: dw 0 AYREG_TonC: dw 0 AYREG_AmplA: db 0 AYREG_AmplB: db 0 AYREG_AmplC: db 0 tempocnt_2: db 0 tempocnt_1: db 0 tempocnt_0: db 0 pattstep_cnt: db 0 ;----------------------------------------------------------------------------- endmodule songdata MDLADDR modstart BUFFER: ds 2 ; dlzka songu RELOC_BASE: I_SAMPLES: ds 2 ; adresa lookup tabulky samplov I_ORNAMENTS: ds 2 ; adresa lookup tabulky ornamentov I_PATTERNS: ds 2 ; adresa lookup tabulky patternov I_POSITIONS: ds 2 ; adresa definicii pozicii I_REPEAT: ds 2 ; ukazovatel na repeat poziciu RELOC_ENDPTR: ds 2 ; tu je uz ukazovat na prvy sampel LFNNAME ds 262 screen incbin logo.bin esxError ds 34 CSPECTMAP player.map savenex open "NextPlayer.nex",demo,24575 savenex core 2,0,0 ;SAVENEX SCREEN BMP "screen2.bmp" savenex auto savenex close
;ifdef NEC98 /* #endif position = EOF */ ;/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ ;/*:::::::::::::::: NEC98 GGDC Graphic Draw Emulation :::::::::::::::*/ ;/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ ;/* add making start NEC NEC98 930623 KBNES 1OA */ .386p include ks386.inc include callconv.inc _TEXT SEGMENT DWORD USE32 PUBLIC 'CODE' ASSUME DS:NOTHING, ES:NOTHING, SS:FLAT, FS:NOTHING, GS:NOTHING _TEXT ENDS _DATA SEGMENT DWORD USE32 PUBLIC 'DATA' ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: write_one_word label dword dd offset draw_mov ; replace draw_one_pixel label dword dd offset draw_and ; replace dd offset draw_or ; replace draw_one_word label dword dd offset draw_mov ; replace dd offset draw_xor ; complement dd offset draw_and ; clear dd offset draw_or ; set draw_0_pixel label dword dd offset draw_and ; replace dd offset draw_nop ; complement dd offset draw_nop ; clear dd offset draw_nop ; set draw_1_pixel label dword dd offset draw_or ; replace dd offset draw_xor ; complement dd offset draw_and ; clear dd offset draw_or ; set ggdc_dir_func_pixel label dword dd offset pixel_dir_0 dd offset pixel_dir_1 dd offset pixel_dir_2 dd offset pixel_dir_3 dd offset pixel_dir_4 dd offset pixel_dir_5 dd offset pixel_dir_6 dd offset pixel_dir_7 ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ggdc_dir_func_word label dword dd offset word_dir_0 dd offset word_dir_1 dd offset word_dir_2 dd offset word_dir_3 dd offset word_dir_4 dd offset word_dir_5 dd offset word_dir_6 dd offset word_dir_7 ggdc_VRAM dd 00000000H ggdc_EAD dd 00000000H ggdc_PITCH dd 00000000H ggdc_DIR dd 00000000H ggdc_DC dw 0000H ggdc_D dw 0000H ggdc_D2 dw 0000H ggdc_D1 dw 0000H ggdc_DM dw 0000H ggdc_PTN dw 0000H ggdc_ZOOM dw 0000H ggdc_SL dw 0000H ggdc_WG dw 0000H ggdc_MASKGDC dw 0000H ggdc_TXT label byte db 00H db 00H db 00H db 00H db 00H db 00H db 00H db 00H ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ggdc_MASKCPU dw 0000H ggdc_READ dw 0000H ZOOM1 dw 0000H ZOOM2 dw 0000H ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ggdc_read_back_EAD dd 00000000H ggdc_read_back_DAD dw 0000H ggdc_CSRR_1 db 00H ggdc_CSRR_2 db 00H ggdc_CSRR_3 db 00H ggdc_CSRR_4 db 00H ggdc_CSRR_5 db 00H ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: _DATA ENDS _TEXT SEGMENT ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;:::::::::::::::: NEC98 GGDC Graphic DATA SET :::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: cPublicProc _ggdc_mod_select,1 push ebp ; save ebp mov ebp,esp ; set up stack frame ; ebp - n = local data area ; ebp + 0 = save ebp ; ebp + 4 = return address pushad ; push eax ; save eax reg ; push ebx ; save ebx reg xor ebx,ebx ; ebx = 0 mov eax,[ebp+8] ; parameter 1 = mod data address mov bl,byte ptr[eax] ; set mode mov eax,draw_0_pixel[ebx*4] ; select logic mov [draw_one_pixel][0],eax ; save 1dot 0bit mov eax,draw_1_pixel[ebx*4] ; select logic mov [draw_one_pixel][4],eax ; save 1dot 1bit mov eax,draw_one_word[ebx*4]; select logic mov [write_one_word],eax ; save 1dot 1bit ; pop ebx ; restore ebx ; pop eax ; restore eax popad mov esp,ebp ; restore stack frame pop ebp ; restore ebp stdRET _ggdc_mod_select stdENDP _ggdc_mod_select ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: cPublicProc _ggdc_send_c_asm,1 push ebp mov ebp,esp pushad mov esi,[ebp+8] ; c data area mov edi,offset ggdc_VRAM ; asm data area mov ecx,11 ; move count rep movsd ; 44 bytes data move mov ecx,16 ; mov dx,[ggdc_MASKGDC] ; GGDC mask data @@: rcr dx,1 ; reverse right <-> left rcl ax,1 ; loop short @b ; mov [ggdc_MASKCPU],ax ; use CPU drawing popad pop ebp stdRET _ggdc_send_c_asm stdENDP _ggdc_send_c_asm ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: cPublicProc _ggdc_read_back,1 push ebp mov ebp,esp pushad mov esi,offset ggdc_read_back_EAD ; copy back data mov edi,[ebp+8] ; asm data area mov ecx,11 ; move count rep movsb ; 11 bytes data move popad pop ebp stdRET _ggdc_read_back stdENDP _ggdc_read_back ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;:::::::::::::::::: NEC98 GGDC Graphic Draw LINE ::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: cPublicProc _ggdc_drawing_line,0 pushad ; save all reg mov esi,[ggdc_EAD] ; esi = ggdc start address mov ebp,[ggdc_VRAM] ; ebp = vram start address mov ebx,[ggdc_DIR] ; ebx = direction next mov cx ,[ggdc_PTN] ; cx = line pattern mov dx ,[ggdc_D] ; dx = vectw param D draw_line_loop: movzx eax,cx ; line pattern set and eax,1 ; select logic ror cx,1 ; next pattern mov eax,draw_one_pixel[eax*4] ; address set call eax ; drawing 1 dot test dx, 2000h ; D >= 0 ? check bit 13 jz short draw_line_pos ; Yes jump! add dx,[ggdc_D1] ; D = D + D1 movzx eax,bx ; ax = DIR test al,1 ; DIR LSB = 0 ? jnz short draw_line_inc ; No! DIR = DIR + 1 jmp short draw_line_dir ; Yes DIR = DIR draw_line_pos: add dx,[ggdc_D2] ; D = D + D2 movzx eax,bx ; ax = DIR test al,1 ; DIR LSB = 0 ? jnz short draw_line_dir ; No! DIR = DIR draw_line_inc: inc ax ; DIR = DIR + 1 and ax,7 ; bound dir 0-->7 draw_line_dir: mov eax,ggdc_dir_func_pixel[eax*4] ; select dir function call eax ; next pixel position dec word ptr[ggdc_DC] ; loop-1 jnz draw_line_loop ; 0 ?? next pixel call save_ead_dad ; last position save popad ; restore all reg stdRET _ggdc_drawing_line stdENDP _ggdc_drawing_line ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;:::::::::::::::::: NEC98 GGDC Graphic Draw ARC ::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: cPublicProc _ggdc_drawing_arc,0 pushad ; save all reg mov esi,[ggdc_EAD] ; esi = ggdc start address mov ebp,[ggdc_VRAM] ; ebp = vram start address mov ebx,[ggdc_DIR] ; bx = direction next mov cx ,[ggdc_PTN] ; cx = mask pattern mov dx ,[ggdc_D] ; dx = vectw param D inc word ptr [ggdc_DM] ; DM = DM + 1 draw_arc_loop: dec word ptr [ggdc_DM] ; DM = DM - 1 jnz short @f ; DM = 0 ? No! jump inc word ptr [ggdc_DM] movzx eax,cx ; ax is PTN and ax,1 ; pattern set mov eax,draw_one_pixel[eax*4] ; address set call eax ; drawing 1 dot @@: ror cx,1 ; next pattern add dx,[ggdc_D1] ; D = D + D1 test dx,2000h ; D >= 0 ? jz short draw_arc_pos ; Yes! jump add dx,[ggdc_D2] ; D = D + D2 sub word ptr [ggdc_D2],2 ; D2 = D2 - 2 mov eax,ebx ; ax = DIR test al,1 ; DIR LSB = 0 ? jz short draw_arc_inc ; yes ! jmp short draw_arc_dir ; no ! draw_arc_pos: mov eax,ebx ; ax = DIR test al,1 ; DIR LSB = 0 ? jz short draw_arc_dir ; Yes! draw_arc_inc: inc ax ; DIR = DIR + 1 and ax,7 ; bound 7 draw_arc_dir: sub word ptr[ggdc_D1],2 ; D1 = D1 - 2 mov eax,ggdc_dir_func_pixel[eax*4] ; select dir function call eax ; next position dec [ggdc_DC] ; loop - 1 jnz draw_arc_loop ; 0 ?? next pixel call save_ead_dad ; last position save popad ; restore all reg stdRET _ggdc_drawing_arc stdENDP _ggdc_drawing_arc ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;:::::::::::::::::: NEC98 GGDC Graphic Draw RECT ::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: cPublicProc _ggdc_drawing_rect,0 pushad mov esi,[ggdc_EAD] ; esi = ggdc start address mov ebp,[ggdc_VRAM] ; ebp = vram start address mov ebx,[ggdc_DIR] ; bx = direction next mov cx ,[ggdc_PTN] ; cx = mask pattern mov dx ,[ggdc_D] ; dx = vectw param D draw_rect_loop: movzx eax,cx ; ax is PTN and eax,1 ; set pattern mov eax,draw_one_pixel[eax*4] ; address set call eax ; drawing 1 dot ror cx,1 ; next pattern movzx ebx,bx ; ax = DIR mov eax,ggdc_dir_func_pixel[ebx*4] ; select dir function call eax ; next position add dx,[ggdc_D1] ; D = D+1 test dx,3fffh ; D=0 ? jnz draw_rect_loop ; no! next test word ptr[ggdc_DC],1 ; DC LSB = 0 jnz short @f ; No ! jump add dx,[ggdc_D2] ; D = D + D2 jmp short draw_rect_dec ; @@: add dx,[ggdc_DM] ; draw_rect_dec: add bx,2 ; DIR = DIR + 2 and bx,7 ; bound 7 dec [ggdc_DC] ; DC = DC - 1 jnz draw_rect_loop ; if DC!=0 loop call save_ead_dad ; last position save popad ; restore all reg stdRET _ggdc_drawing_rect stdENDP _ggdc_drawing_rect ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;:::::::::::::::::: NEC98 GGDC Graphic Draw PIXEL ::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: cPublicProc _ggdc_drawing_pixel pushad mov esi,[ggdc_EAD] ; esi = ggdc start address mov ebp,[ggdc_VRAM] ; ebp = vram start address mov ebx,[ggdc_DIR] ; bx = direction next mov cx ,[ggdc_PTN] ; cx = line pattern movzx eax,cx ; set line pattern and eax, 1 ; pattern ? mov eax,draw_one_pixel[eax*4] ; select function call eax ; draw pixel mov eax,ggdc_dir_func_pixel[ebx*4] ; select dir function call eax ; next position call save_ead_dad ; last position save popad ; restore all reg stdRET _ggdc_drawing_pixel stdENDP _ggdc_drawing_pixel ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;:::::::::::::::::: NEC98 GGDC Graphic Draw TEXT ::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: cPublicProc _ggdc_drawing_text,0 pushad mov esi,[ggdc_EAD] ; esi = ggdc start address mov ebp,[ggdc_VRAM] ; ebp = vram start address mov dx, [ggdc_D] ; edx = D mov ax, [ggdc_ZOOM] ; copy zoom mov [ZOOM1],ax ; ZW1 xor ebx,ebx ; TXT start data mov ch,01h ; reset PS text_2nd_dir_loop: mov cl,ggdc_TXT[ebx] ; get TXn inc ebx ; point to next TX and bl,7 ; bound 7 mov ax,[ggdc_ZOOM] ; eax = zoom mov [ZOOM2],ax ; ZW2 = ZW + 1 text_2nd_dir_zoom: ; D times (D2 times) text_1st_dir_loop: mov al,cl ; copy TXn test al,ch ; get PS bit mov eax,0 ; PS bit 1 or 0 ? jz short @f ; 0 : EAX = 0 inc eax ; 1 : EAX = 1 @@: mov eax,draw_one_pixel[eax*4] ; select function call eax ; drawing 1 dot dec word ptr[ZOOM1] ; ZW1 = ZW1 - 1 jnz short text_1st_zoom_skip ; ZW1 = 0 ? No! mov ax,[ggdc_ZOOM] ; ax = ZW + 1 mov [ZOOM1],ax ; ZW1 = ZW + 1 add dx,[ggdc_D1] ; D = D + D1 test dx,3fffh ; D = 0 ? jz short text_1st_dir_loop_exit ; Yes! rol ch, 1 ; ROL(PS) test word ptr[ggdc_DM],1 ; if LSB(DM) jnz short text_1st_zoom_skip ; 1 : ROL(PS) ror ch, 2 ; 0 : ROR(PS) text_1st_zoom_skip: mov eax,[ggdc_DIR] ; get DIR mov eax,ggdc_dir_func_pixel[eax*4] ; select dir function call eax ; calculate next dot address jmp short text_1st_dir_loop ; while D != 0 text_1st_dir_loop_exit: mov eax,[ggdc_DIR] ; get DIR' = DIR inc ax ; DIR' = DIR' + 1 test word ptr[ggdc_SL],1 ; SL bit check ? jnz short @f ; 1 : DIR' = DIR' + 0 inc ax ; 0 : DIR' = DIR' + 1 @@: test word ptr[ggdc_DM],1 ; if LSB(DM) jnz short @f ; 1 : DIR' = DIR' + 0 add ax, 4 ; 0 : DIR' = DIR' + 4 @@: and eax, 7 ; normalize DIR' mov eax,ggdc_dir_func_pixel[eax*4] ; select dir function call eax ; calculate next scanline address add [ggdc_DIR],4 ; DIR = DIR + 4 and [ggdc_DIR],7 ; normalize DIR mov dx,[ggdc_D2] ; dec word ptr[ggdc_DM] ; DM = DM - 1 dec word ptr[ZOOM2] ; ZOOM2 - 1 jnz text_2nd_dir_zoom ; ZOOM2 != 0 dec word ptr[ggdc_DC] ; DC = DC - 1 jnz text_2nd_dir_loop ; DC != 0 call save_ead_dad ; last position save popad ; restore all reg stdRET _ggdc_drawing_text stdENDP _ggdc_drawing_text ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;:::::::::::::::::: NEC98 GGDC Graphic Draw WRITE ::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: cPublicProc _ggdc_writing,1 push ebp mov ebp,esp pushad mov ebx,[ebp+8] ; output data address mov bx,word ptr[ebx] ; output data mov esi,[ggdc_EAD] ; esi = ggdc start address mov ebp,[ggdc_VRAM] ; ebp = vram start address mov edx,[ggdc_DIR] ; dx = direction test [ggdc_WG],1 ; WG bit on ? jnz short write_text_mode ; 1: TEXT mode ; 0: GRAPH mode write_graph_mode: test bx,1 ; check LSB of output data jz short @f ; mov eax,[write_one_word] ; call eax ; drawing 1 pixel @@: mov eax,ggdc_dir_func_pixel[edx*4] ; select dir function call eax ; calculate next dot address jmp short write_end ; write_text_mode: mov ecx,16 ; change out data @@: rcr bx,1 ; rcl ax,1 ; left bit <-> right bit loop @b ; mov bx,[ggdc_MASKCPU] ; save mask data and ax,bx ; mask & out data mov [ggdc_MASKCPU],ax ; ax = mask data mov eax,[write_one_word] ; call eax ; drawing 1 word mov eax,ggdc_dir_func_word[edx*4] ; select dir function call eax ; calculate next dot address mov [ggdc_MASKCPU],bx ; resrtore dAD/MASK write_end: call save_ead_dad ; last position save popad ; pop ebp ; stdRET _ggdc_writing stdENDP _ggdc_writing ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;:::::::::::::::::: NEC98 GGDC Graphic Draw READ ::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: cPublicProc _ggdc_reading,1 push ebp mov ebp,esp pushad mov ebx,[ebp+8] ; return data address push ebx ; save it mov esi,[ggdc_EAD] ; esi = ggdc start address mov ebp,[ggdc_VRAM] ; ebp = vram start address mov edx,[ggdc_DIR] ; dx = direction mov edi,esi ; copy ggdc address and edi,0000ffffH ; recalc NEC98 vram address bound mov ax,[ebp+edi*2] ; read data xchg ah,al ; high <-> low mov ecx, 16 @@: rcr ax, 1 ; reverse bits rcl bx, 1 ; left to right loop short @b ; do 16 times mov [ggdc_READ],bx ; save data test [ggdc_WG],1 ; WG check jnz short read_text_mode ; 1: TEXT mode ; 0: GRAPHIC mode read_graph_mode: mov eax,ggdc_dir_func_pixel[edx*4] ; select dir function call eax ; calculate next dot address jmp short read_end read_text_mode: mov eax,ggdc_dir_func_word[edx*4] ; select dir function call eax ; calculate next dot address read_end: mov ax,[ggdc_READ] ; copy back from tmp pop ebx ; data address mov word ptr[ebx],ax ; return call save_ead_dad ; last position save popad pop ebp stdRET _ggdc_reading stdENDP _ggdc_reading ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; save_ead_dad: mov eax,esi ; Last Ead address and eax,0003FFFFH ; bound GGDC memory area mov [ggdc_read_back_EAD],eax; mov [ggdc_CSRR_1],al ; return data1 shr eax,8 ; mov [ggdc_CSRR_2],al ; return data2 shr eax,8 ; mov [ggdc_CSRR_3],al ; return data3 mov ecx,16 ; mov dx,[ggdc_MASKCPU] ; GGDC mask data @@: rcr dx,1 ; reverse right <-> left rcl ax,1 ; loop short @b ; mov [ggdc_read_back_DAD],ax ; use GDC drawing mov [ggdc_CSRR_4],al ; return data4 mov [ggdc_CSRR_5],ah ; return data5 ret ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; ; draw_and ; ; input: ; ; esi = ggdc address ; ; ebp = virtual vram start address ; ; destory: ; ; eax,edi,flag ; ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; draw_and: public draw_and mov ax,[ggdc_MASKCPU] ; set xchg ah,al ; change High <-> Low not ax ; not mov edi,esi ; copy ggdc address and edi,0000ffffH ; recalc NEC98 vram address bound and [ebp+edi*2],ax ; draw pixel ret ; return ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; ; draw_or ; ; input: ; ; esi = ggdc address ; ; ebp = virtual vram start address ; ; destory: ; ; eax,edi,flag ; ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; draw_or: public draw_or mov ax,[ggdc_MASKCPU] ; set xchg ah,al ; change High <-> Low mov edi,esi ; copy ggdc address and edi,0000ffffH ; recalc NEC98 vram address bound or [ebp+edi*2],ax ; draw pixel ret ; return ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; ; draw_xor ; ; input: ; ; esi = ggdc address ; ; ebp = virtual vram start address ; ; destory: ; ; eax,edi,flag ; ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; draw_xor: public draw_xor mov ax,[ggdc_MASKCPU] ; set xchg ah,al ; change High <-> Low mov edi,esi ; copy ggdc address and edi,0000ffffH ; recalc NEC98 vram address bound xor [ebp+edi*2],ax ; draw pixel ret ; return ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; ; draw_mov ; ; input: ; ; esi = ggdc address ; ; ebp = virtual vram start address ; ; destory: ; ; eax,edi,flag ; ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; draw_mov: public draw_mov mov ax,[ggdc_MASKCPU] ; set xchg ah,al ; change High <-> Low mov edi,esi ; copy ggdc address and edi,0000ffffH ; recalc NEC98 vram address bound mov [ebp+edi*2],ax ; draw pixel ret ; return ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; ; draw_mov ; ; input : none ; ; destory: none ; ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; draw_nop: public draw_nop ret ; do nothing ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; ; ggdc_dir_func_pixel ; ; input : none ; ; update : esi ; ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; pixel_dir_0: public pixel_dir_0 add esi,[ggdc_PITCH] ; move down ret ; return ;-----------------------------------------------------------------------; pixel_dir_1: public pixel_dir_1 add esi,[ggdc_PITCH] ; move down ror word ptr [ggdc_MASKCPU],1 ; move right adc esi,0 ; over word? ret ; return ;-----------------------------------------------------------------------; pixel_dir_2: public pixel_dir_2 ror word ptr [ggdc_MASKCPU],1 ; move right adc esi,0 ; over word? ret ; return ;-----------------------------------------------------------------------; pixel_dir_3: public pixel_dir_3 sub esi,[ggdc_PITCH] ; move up ror word ptr[ggdc_MASKCPU],1 ; move right adc esi,0 ; over word? ret ; return ;-----------------------------------------------------------------------; pixel_dir_4: public pixel_dir_4 sub esi,[ggdc_PITCH] ; move up ret ; return ;-----------------------------------------------------------------------; pixel_dir_5: public pixel_dir_5 sub esi,[ggdc_PITCH] ; move up rol word ptr [ggdc_MASKCPU],1 ; move left sbb esi,0 ; over word? ret ; return ;-----------------------------------------------------------------------; pixel_dir_6: public pixel_dir_6 rol word ptr [ggdc_MASKCPU],1 ; move left sbb esi,0 ; over word? ret ; return ;-----------------------------------------------------------------------; pixel_dir_7: public pixel_dir_7 add esi,[ggdc_PITCH] ; move down rol word ptr [ggdc_MASKCPU],1 ; move left sbb esi,0 ; over word? ret ; return ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; ; ggdc_dir_func_short ; ; input : none ; ; destory: esi , dx , flag ; ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; word_dir_0: public word_dir_0 add esi,[ggdc_PITCH] ; move down ret ; return ;-----------------------------------------------------------------------; word_dir_1: public word_dir_1 add esi,[ggdc_PITCH] ; move down inc esi ; move right ret ; return ;-----------------------------------------------------------------------; word_dir_2: public word_dir_2 inc esi ; move right ret ; return ;-----------------------------------------------------------------------; word_dir_3: public word_dir_3 sub esi,[ggdc_PITCH] ; move up inc esi ; move right ret ; return ;-----------------------------------------------------------------------; word_dir_4: public word_dir_4 sub esi,[ggdc_PITCH] ; move up ret ; return ;-----------------------------------------------------------------------; word_dir_5: public word_dir_5 sub esi,[ggdc_PITCH] ; move up dec esi ; move left ret ; return ;-----------------------------------------------------------------------; word_dir_6: public word_dir_6 dec esi ; move left ret ; return ;-----------------------------------------------------------------------; word_dir_7: public word_dir_7 add esi,[ggdc_PITCH] ; move down dec esi ; move left ret ; return _TEXT ENDS END ;endif
; A019429: Continued fraction for tan(1/6). ; 0,5,1,16,1,28,1,40,1,52,1,64,1,76,1,88,1,100,1,112,1,124,1,136,1,148,1,160,1,172,1,184,1,196,1,208,1,220,1,232,1,244,1,256,1,268,1,280,1,292,1,304,1,316,1,328,1,340,1,352,1,364,1,376,1,388,1,400,1,412,1,424,1,436,1,448,1,460,1,472,1,484,1,496,1,508,1,520,1,532,1,544,1,556,1,568,1,580,1,592 seq $0,19428 ; Continued fraction for tan(1/5). sub $0,9 mov $2,8 add $2,$0 add $1,$2 add $2,4 div $2,5 add $1,$2 add $1,1 mov $0,$1
; unsigned char esx_f_seekdir(unsigned char handle,uint32_t pos) SECTION code_esxdos PUBLIC _esx_f_seekdir_callee EXTERN asm_esx_f_seekdir _esx_f_seekdir_callee: pop hl dec sp pop af pop de pop bc push hl jp asm_esx_f_seekdir
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r12 push %rax push %rbp push %rcx push %rdi push %rsi lea addresses_WT_ht+0x1b921, %rax nop cmp $28080, %r11 mov $0x6162636465666768, %rdi movq %rdi, (%rax) nop nop nop and $54756, %r10 lea addresses_WC_ht+0x465f, %r12 add %rbp, %rbp mov $0x6162636465666768, %rsi movq %rsi, %xmm0 and $0xffffffffffffffc0, %r12 movntdq %xmm0, (%r12) xor %r12, %r12 lea addresses_WC_ht+0x3561, %rax clflush (%rax) nop nop sub %rsi, %rsi mov (%rax), %r12 nop sub $39831, %rsi lea addresses_WT_ht+0xb1e1, %rax nop nop nop nop nop xor $62349, %r11 movb $0x61, (%rax) nop dec %rax lea addresses_D_ht+0xaa19, %rsi lea addresses_normal_ht+0xaf21, %rdi clflush (%rsi) nop nop nop nop cmp $17973, %r10 mov $88, %rcx rep movsb nop dec %rsi pop %rsi pop %rdi pop %rcx pop %rbp pop %rax pop %r12 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r15 push %r9 push %rbp push %rdi push %rdx // Store lea addresses_normal+0x1dea1, %rdx nop nop nop nop nop and %r11, %r11 movb $0x51, (%rdx) sub %r11, %r11 // Load mov $0x4c7e620000000f21, %r11 nop nop nop nop cmp %rdi, %rdi movb (%r11), %r10b nop nop nop nop nop add $62141, %rdi // Faulty Load mov $0x4c7e620000000f21, %r15 nop nop and $45547, %rdx mov (%r15), %r10 lea oracles, %rdx and $0xff, %r10 shlq $12, %r10 mov (%rdx,%r10,1), %r10 pop %rdx pop %rdi pop %rbp pop %r9 pop %r15 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 8, 'AVXalign': True, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False, 'NT': True, 'congruent': 9, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 1, 'same': True}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': True, 'NT': True, 'congruent': 2, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 11, 'same': False}} {'00': 189} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
.686P .model flat,stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc .data ClassName db "life",0 AppName db "life",0 .data? hwnd LPVOID ? hInstance HINSTANCE ? msg MSG <> wndClassEx WNDCLASSEX <> .code WndProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM .IF uMsg==WM_CLOSE invoke DestroyWindow,hwnd invoke PostQuitMessage,0 .ELSE invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .ENDIF xor eax,eax ret WndProc ENDP life: invoke GetModuleHandle,NULL mov hInstance, eax mov wndClassEx.hInstance, eax mov wndClassEx.cbSize,SIZEOF WNDCLASSEX mov wndClassEx.style,CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNCLIENT mov wndClassEx.lpfnWndProc,OFFSET WndProc mov wndClassEx.cbClsExtra,NULL mov wndClassEx.cbWndExtra,NULL mov wndClassEx.hbrBackground,COLOR_MENUTEXT mov wndClassEx.lpszMenuName,NULL mov wndClassEx.lpszClassName,OFFSET ClassName invoke LoadCursor,NULL,IDC_ARROW mov wndClassEx.hCursor,eax invoke LoadIcon,hInstance,500 mov wndClassEx.hIcon,eax mov wndClassEx.hIconSm,eax invoke RegisterClassEx,ADDR wndClassEx invoke CreateWindowEx,0,ADDR ClassName,ADDR AppName,\ WS_POPUP,0,0,1366,768,NULL,NULL,\ hInstance,NULL mov hwnd,eax invoke ShowWindow,hwnd,SW_SHOWNORMAL invoke UpdateWindow,hwnd MsgLoop: invoke GetMessage,ADDR msg,0,0,0 test eax,eax jz EndLoop invoke TranslateMessage,ADDR msg invoke DispatchMessage,ADDR msg jmp MsgLoop EndLoop: invoke ExitProcess,eax end life
// TecplotLiteSorter.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <fstream> #include <sstream> #include <vector> #include <algorithm> //#define TECPLOT_DEBUG #define dims 2 #define output_precision 10 #define num_grids 1 #define max_time 1000 #define time_step 1000 #define num_ranks 8 void sortrows(std::vector<std::vector<double>>& matrix, int col) { // Loop over rows with sort std::stable_sort( matrix.begin(), matrix.end(), // Lambda expression to decide whether line goes before another [col](const std::vector<double>& row1, const std::vector<double>& row2) { return row1[col] < row2[col]; } ); } void unitTest() { // Container std::vector< std::vector<double> > data; // Random data data.resize(4); data[0].push_back(4); data[0].push_back(5); data[0].push_back(6); data[1].push_back(0); data[1].push_back(2); data[1].push_back(8); data[2].push_back(1); data[2].push_back(2); data[2].push_back(3); data[3].push_back(6); data[3].push_back(7); data[3].push_back(9); // Sort sortrows(data,3); sortrows(data,2); sortrows(data,1); // Output for (int i = 0; i < 4; i++) { std::cout << std::endl; for (int j = 0 ; j < 3; j++) { std::cout << data[i][j] << "\t"; } } } int main(int argc, char* argv) { #if (dims == 3 && defined TECPLOT_DEBUG) int num_vars = 47; #elif (dims == 2 && defined TECPLOT_DEBUG) int num_vars = 27; #else int num_vars = 19; #endif // Files std::ofstream tecfile; std::ifstream srcfile; std::string filename; std::string line_in; // String to store line std::istringstream iss; // Buffer stream int line_counter; #ifdef TECPLOT_DEBUG std::string filetype = "tecplotdebug"; #else std::string filetype = "io_lite"; #endif // Text variables std::string time_string; std::string variables; variables.resize(num_vars); double tmp; double type; double rank; // Variable containers std::vector< std::vector<double> > data; std::vector<double> row; row.resize(num_vars); // Item counter unsigned int item_number = 0; // Loop over time for (int time = 0; time <= max_time; time += time_step) { // Reset item numbers and flush stores item_number = 0; data.clear(); row.clear(); row.resize(num_vars-1); // Do not store the rank // Loop over levels for (int level = 0; level < num_grids; level++) { #ifndef TECPLOT_DEBUG // Loop over ranks for (int rank = 0; rank < num_ranks; rank++) #endif { // Reset line counter line_counter = 0; iss.clear(); // Flush the string stream so eofbit is reset // Try to open file #ifdef TECPLOT_DEBUG filename = "./process/" + filetype + ".Lev" + std::to_string(level) + ".Reg0." + std::to_string(time) + ".dat"; #else filename = "./process/" + filetype + ".Lev" + std::to_string(level) + ".Reg0.Rnk" + std::to_string(rank) + "." + std::to_string(time) + ".dat"; #endif srcfile.open(filename, std::ios::in); if (!srcfile.is_open()) continue; #ifdef TECPLOT_DEBUG std::cout << "Reading in Grid Level " << level << " of " << num_grids-1 << ", Time " << time << " of " << max_time << std::endl; #else std::cout << "Reading in Rank " << rank << " of " << num_ranks-1 << ", Grid Level " << level << " of " << num_grids-1 << ", Time " << time << " of " << max_time << std::endl; #endif // Read in one line at a time while( !srcfile.eof() ) { // Get line and put in buffer std::getline(srcfile, line_in, '\n'); iss.str(line_in); iss.seekg(0); // Reset buffer position to start of buffer if (line_counter < 2) { // Ignore header line line_counter++; continue; } else if (line_counter == 1) { // Read in time time_string = line_in; line_counter++; continue; } else if (line_counter == 2) { // Read in variable titles variables = line_in; line_counter++; continue; } // Else continue... // Increment line counter line_counter++; // Read in rank (omit from data store as it messes up diff comprisons) iss >> rank; // Read in type iss >> type; // Don't read in certain site types if (type == 2 || type == 3 || type == 5) continue; // Increment item number store item_number++; // Store type row[0] = type; // Read in rest of data for (int item = 1; item < num_vars-1; item++) { iss >> tmp; row[item] = tmp; } // Assign to data store data.push_back(row); } // Reached end of file so close file srcfile.close(); // Delete erroneous space at end of file data.erase(data.end()-1,data.end()); item_number--; } } // Break if the time step doesn't exist if (item_number == 0) continue; // Sort items std::cout << "Sorting data..." << std::endl; // X Y Z variables are in columns 1 2 3 sortrows(data,3); sortrows(data,2); sortrows(data,1); // Write Data // std::cout << "Writing data..." << std::endl; // Open file tecfile.open("./out/tecplot." + std::to_string(time) + ".dat"); tecfile.precision(output_precision); tecfile.setf(std::ios::fixed); tecfile.setf(std::ios::showpoint); // Write out tecplot header tecfile << "TITLE = All grid quantities excluding refined regions" << std::endl; tecfile << "FILETYPE = FULL" << std::endl; #ifdef TECPLOT_DEBUG tecfile << "VARIABLES = \"TYPE\" \"X\" \"Y\" \"Z\" \"F\" \"FEQ\" \"RHO\" \"UX\" \"UY\" \"UZ\"" << std::endl; #else tecfile << "VARIABLES = \"TYPE\" \"X\" \"Y\" \"Z\" \"RHO\" \"UX\" \"UY\" \"UZ\" \"TA_RHO\" \"TA_UX\" \"TA_UY\" \"TA_UZ\" "<< "\"TA_UXUX\" \"TA_UXUY\" \"TA_UXUZ\" \"TA_UYUY\" \"TA_UYUZ\" \"TA_UZUZ\"" << std::endl; #endif tecfile << "ZONE" << std::endl; tecfile << "I = " << item_number << std::endl; tecfile << "DATAPACKING = POINT" << std::endl; tecfile << "SOLUTIONTIME = " << std::to_string(time) << std::endl; // Write out items (rank not included) for (size_t i = 0; i < data.size(); i++) { for (int j = 0; j < num_vars-1; j++) { tecfile << data[i][j] << "\t"; } tecfile << std::endl; } // Time step complete tecfile.close(); } return 0; }
;================================================================================================== ; Benchmark BQ4845P RTC Driver ;================================================================================================== ; Register Addresses (HEX / BCD): ; +---+-----+--------------+-------------------+------------------+----------------+ ; |ADR| D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | RANGE | REGISTER | ; +---+-----+--------------+-------------------+------------------+----------------+ ; | 0 | 0 | 10-Second | 1-Second | 00-59 | Seconds | ; +---+-----+----+---------+-------------------+------------------+----------------+ ; | | ALM1|ALM2| | | | | ; | 1 | | 10-Second | 1-Second | 00-59 | Seconds Alarm | ; +---+-----+--------------+-------------------+------------------+----------------+ ; | 2 | 0 | 10-Minute | 1-Minute | 00-59 | Minutes | ; +---+-----+----+---------+-------------------+------------------+----------------+ ; | | ALM1|ARM0| | | | | ; | 3 | | 10-Minute | 1-Minute | 00-59 | Minutes Alarm | ; +---+-----+----+---------+-------------------+------------------+----------------+ ; | 4 |PM/AM| 0 | 10-Hour | 1-Hour |01-12 AM/81-92 PM | Hours | ; +---+-----+----+----+----+-------------------+------------------+----------------+ ; | | ALM1| | | | | | ; | 5 |PM/AM|ALM0| 10-Hour | 1-Hour |01-12 AM/81-92 PM | Hours Alarm | ; +---+-----+----+----+----+-------------------+------------------+----------------+ ; | 6 | 0 | 0 | 10-Day | 1-Day | 01-31 | Day | ; +---+-----+----+----+----+-------------------+------------------+----------------+ ; | 7 | ALM1|ALM0| 10-day | 1-Day | 01-31 | Day Alarm | ; +---+-----+----+----+----+----+--------------+------------------+----------------+ ; | 8 | 0 | 0 | 0 | 0 | 0 | Day Of Week | 01-07 | Day Of Week | ; +---+-----+----+----+----+----+--------------+------------------+----------------+ ; | 9 | 0 | 0 | 0 |10Mo| 1-Month | 01-12 | Month | ; +---+-----+----+----+----+-------------------+------------------+----------------+ ; | A | 10-Year | 1-Year | 00-99 | Year | ; +---+-----+----+----+----+----+----+----+----+------------------+----------------+ ; | B | * | WD2| WD1| WD0| RS3| RS2| RS1| RS0| | Rates | ; +---+-----+----+----+----+----+----+----+----+------------------+----------------+ ; | C | * | * | * | * | AIE| PIE|PWRE| ABE| | Interrupt | ; +---+-----+----+----+----+----+----+----+----+------------------+----------------+ ; | D | * | * | * | * | AF | PF |PWRF| BVF| | Flags | ; +---+-----+----+----+----+----+----+----+----+------------------+----------------+ ; | E | * | * | * | * | UTI|STOP|2412| DSE| | Control | ; +---+-----+----+----+----+----+----+----+----+------------------+----------------+ ; | F | * | * | * | * | * | * | * | * | | Unused | ; +---+-----+----+----+----+----+----+----+----+------------------+----------------+ ; * = Unused bits; unwritable and read as 0. ; 0 = should be set to 0 for valid time/calendar range. ; Clock calendar data is BCD. Automatic leap year adjustment. ; PM/AM = 1 for PM; PM/AM = 0 for AM. ; DSE = 1 enable daylight savings adjustment. ; 24/12 = 1 enable 24-hour data representation; 24/12 = 0 enables 12-hour data representation. ; Day-Of-Week coded as Sunday = 1 through Saturday = 7. ; BVF = 1 for valid battery. ; STOP = 1 turns the RTC on; STOP = 0 stops the RTC in back-up mode. ; Constants BQRTC_SEC .EQU BQRTC_BASE + $00 BQRTC_SEC_ALM .EQU BQRTC_BASE + $01 BQRTC_MIN .EQU BQRTC_BASE + $02 BQRTC_MIN_ALM .EQU BQRTC_BASE + $03 BQRTC_HOUR .EQU BQRTC_BASE + $04 BQRTC_HOUR_ALM .EQU BQRTC_BASE + $05 BQRTC_DAY .EQU BQRTC_BASE + $06 BQRTC_DAY_ALM .EQU BQRTC_BASE + $07 BQRTC_WEEK_DAY .EQU BQRTC_BASE + $08 BQRTC_MONTH .EQU BQRTC_BASE + $09 BQRTC_YEAR .EQU BQRTC_BASE + $0A BQRTC_RATE .EQU BQRTC_BASE + $0B BQRTC_INTERRUPT .EQU BQRTC_BASE + $0C BQRTC_FLAGS .EQU BQRTC_BASE + $0D BQRTC_CONTROL .EQU BQRTC_BASE + $0E BQRTC_UNUSED .EQU BQRTC_BASE + $0F BQRTC_HIGH .EQU %11110000 BQRTC_LOW .EQU %00001111 BQRTC_WD .EQU %01110000 BQRTC_RS .EQU %00001111 BQRTC_BVF .EQU %00000001 BQRTC_PWRF .EQU %00000010 BQRTC_PF .EQU %00000100 BQRTC_AF .EQU %00001000 BQRTC_DSE .EQU %00000001 BQRTC_2412 .EQU %00000010 BQRTC_STOP .EQU %00000100 BQRTC_UTI .EQU %00001000 BQRTC_BUFSIZE .EQU 6 ; 6 BYTE BUFFER (YYMMDDHHMMSS) ; RTC Device Initialization Entry BQRTC_INIT: CALL NEWLINE ; Formatting PRTS("BQRTC: IO=0x$") LD A, BQRTC_BASE CALL PRTHEXBYTE LD A, BQRTC_DSE | BQRTC_2412 | BQRTC_STOP | BQRTC_UTI OUT0 (BQRTC_CONTROL), A ; Enable Daylight Savings and 24 Hour XOR A ; Zero A OUT0 (BQRTC_RATE), A ; Disable Periodic Interrupt Rate OUT0 (BQRTC_INTERRUPT), A ; Disable Interrupts CALL BQRTC_LOAD ; DISPLAY CURRENT TIME PRTS(" $") LD A, (BQRTC_BUF_MON) CALL PRTHEXBYTE PRTS("/$") LD A, (BQRTC_BUF_DAY) CALL PRTHEXBYTE PRTS("/$") LD A, (BQRTC_BUF_YEAR) CALL PRTHEXBYTE PRTS(" $") LD A, (BQRTC_BUF_HOUR) CALL PRTHEXBYTE PRTS(":$") LD A, (BQRTC_BUF_MIN) CALL PRTHEXBYTE PRTS(":$") LD A, (BQRTC_BUF_SEC) CALL PRTHEXBYTE XOR A ; Signal success RET ; RTC Device Function Dispatch Entry ; A: Result (OUT), 0=OK, Z=OK, NZ=Error ; B: Function (IN) BQRTC_DISPATCH: LD A, B ; Get requested function AND $0F ; Isolate Sub-Function JP Z, BQRTC_GETTIM ; Get Time DEC A JP Z, BQRTC_SETTIM ; Set Time DEC A JP Z, BQRTC_GETBYT ; Get NVRAM Byte Value DEC A JP Z, BQRTC_SETBYT ; Set NVRAM Byte Value DEC A JP Z, BQRTC_GETBLK ; Get NVRAM Data Block Value DEC A JP Z, BQRTC_SETBLK ; Set NVRAM Data Block Value DEC A JP Z, BQRTC_GETALM ; Get Alarm DEC A JP Z, BQRTC_SETALM ; Set Alarm ; ; NVRAM FUNCTIONS ARE NOT AVAILABLE ; BQRTC_GETBYT: BQRTC_SETBYT: BQRTC_GETBLK: BQRTC_SETBLK: CALL PANIC ; RTC Get Time ; A: Result (OUT), 0=OK, Z=OK, NZ=Error ; HL: Date/Time Buffer (OUT) ; Buffer format is BCD: YYMMDDHHMMSS ; 24 hour time format is assumed ; BQRTC_GETTIM: EX DE, HL CALL BQRTC_LOAD ; Now copy to read destination (Interbank Save) LD A, BID_BIOS ; Copy from BIOS bank LD (HB_SRCBNK), A ; Set it LD A, (HB_INVBNK) ; Copy to current user bank LD (HB_DSTBNK), A ; Set it LD BC, BQRTC_BUFSIZE ; Length is 6 bytes #IF (INTMODE == 1) DI #ENDIF CALL HB_BNKCPY ; Copy the clock data #IF (INTMODE == 1) EI #ENDIF ; ; CLEAN UP AND RETURN XOR A ; SIGNAL SUCCESS RET ; AND RETURN ; ; RTC Set Time ; A: Result (OUT), 0=OK, Z=OK, NZ=Error ; HL: Date/Time Buffer (IN) ; Buffer Format is BCD: YYMMDDHHMMSS ; 24 hour time format is assumed ; BQRTC_SETTIM: ; ; Copy incoming time data to our time buffer LD A, (HB_INVBNK) ; Copy from current user bank LD (HB_SRCBNK), A ; Set it LD A, BID_BIOS ; Copy to BIOS bank LD (HB_DSTBNK), A ; Set it LD DE, BQRTC_BUF ; Destination Address LD BC, BQRTC_BUFSIZE ; Length is 6 bytes #IF (INTMODE == 1) DI #ENDIF CALL HB_BNKCPY ; Copy the clock data #IF (INTMODE == 1) EI #ENDIF ; Write to clock LD HL, BQRTC_BUF CALL BQRTC_SUSPEND LD A, (HL) OUT0 (BQRTC_YEAR), A ; Write Year INC HL LD A, (HL) OUT0 (BQRTC_MONTH), A ; Write Month INC HL LD A, (HL) OUT0 (BQRTC_DAY), A ; Write Day INC HL LD A, (HL) OUT0 (BQRTC_HOUR), A ; Write Hour INC HL LD A, (HL) OUT0 (BQRTC_MIN), A ; Write Minute INC HL LD A, (HL) OUT0 (BQRTC_SEC), A ; Write Second CALL BQRTC_RESUME ; clean up and return XOR A ; Signal success RET ; And return ; RTC Get Alarm ; A: Result (OUT), 0=OK, Z=OK, NZ=Error ; HL: Date/Time Buffer (OUT) ; Buffer format is BCD: YYMMDDHHMMSS ; 24 hour time format is assumed ; BQRTC_GETALM: EX DE, HL LD HL, BQRTC_BUF PUSH HL ; Save address of source buffer CALL BQRTC_SUSPEND XOR A LD (HL), A ; Read Year INC HL LD (HL), A ; Read Month INC HL IN0 A, (BQRTC_DAY_ALM) ; Read Day LD (HL), A INC HL IN0 A, (BQRTC_HOUR_ALM) ; Read Hour LD (HL), A INC HL IN0 A, (BQRTC_MIN_ALM) ; Read Minute LD (HL), A INC HL IN0 A, (BQRTC_SEC_ALM) ; Read Second LD (HL), A CALL BQRTC_RESUME POP HL ; Restore address of source buffer ; Now copy to read destination (Interbank Save) LD A, BID_BIOS ; Copy from BIOS bank LD (HB_SRCBNK), A ; Set it LD A, (HB_INVBNK) ; Copy to current user bank LD (HB_DSTBNK), A ; Set it LD BC, BQRTC_BUFSIZE ; Length is 6 bytes #IF (INTMODE == 1) DI #ENDIF CALL HB_BNKCPY ; Copy the clock data #IF (INTMODE == 1) EI #ENDIF ; ; CLEAN UP AND RETURN XOR A ; SIGNAL SUCCESS RET ; AND RETURN ; ; RTC Set Alarm ; A: Result (OUT), 0=OK, Z=OK, NZ=Error ; HL: Date/Time Buffer (IN) ; Buffer Format is BCD: YYMMDDHHMMSS ; 24 hour time format is assumed ; BQRTC_SETALM: ; Copy incoming time data to our time buffer LD A, (HB_INVBNK) ; Copy from current user bank LD (HB_SRCBNK), A ; Set it LD A, BID_BIOS ; Copy to BIOS bank LD (HB_DSTBNK), A ; Set it LD DE, BQRTC_BUF ; Destination Address LD BC, BQRTC_BUFSIZE ; Length is 6 bytes #IF (INTMODE == 1) DI #ENDIF CALL HB_BNKCPY ; Copy the clock data #IF (INTMODE == 1) EI #ENDIF ; Write to clock LD HL, BQRTC_BUF_DAY CALL BQRTC_SUSPEND LD A, (HL) OUT0 (BQRTC_DAY_ALM), A ; Write Day INC HL LD A, (HL) OUT0 (BQRTC_HOUR_ALM), A ; Write Hour INC HL LD A, (HL) OUT0 (BQRTC_MIN_ALM), A ; Write Minute INC HL LD A, (HL) OUT0 (BQRTC_SEC_ALM), A ; Write Second CALL BQRTC_RESUME ; clean up and return XOR A ; Signal success RET ; And return BQRTC_SUSPEND: IN0 A, (BQRTC_CONTROL) ; Suspend Clock OR BQRTC_UTI OUT0 (BQRTC_CONTROL), A RET BQRTC_RESUME: IN0 A, (BQRTC_CONTROL) ; Resume Clock AND ~BQRTC_UTI OUT0 (BQRTC_CONTROL), A RET BQRTC_LOAD: LD HL, BQRTC_BUF PUSH HL ; Save address of source buffer CALL BQRTC_SUSPEND IN0 A, (BQRTC_YEAR) ; Read Year LD (HL), A INC HL IN0 A, (BQRTC_MONTH) ; Read Month LD (HL), A INC HL IN0 A, (BQRTC_DAY) ; Read Day LD (HL), A INC HL IN0 A, (BQRTC_HOUR) ; Read Hour LD (HL), A INC HL IN0 A, (BQRTC_MIN) ; Read Minute LD (HL), A INC HL IN0 A, (BQRTC_SEC) ; Read Second LD (HL), A CALL BQRTC_RESUME POP HL ; Restore address of source buffer RET ; Working Variables BQRTC_BUF: BQRTC_BUF_YEAR: .DB 0 ; Year BQRTC_BUF_MON: .DB 0 ; Month BQRTC_BUF_DAY: .DB 0 ; Day BQRTC_BUF_HOUR: .DB 0 ; Hour BQRTC_BUF_MIN: .DB 0 ; Minute BQRTC_BUF_SEC: .DB 0 ; Second
#include "ModuleDebugDraw.h" #include "Application.h" #include "ModuleRender.h" #include "ModuleEditor.h" #include "Camera.h" #include "Math/float4x4.h" #define DEBUG_DRAW_IMPLEMENTATION 1 #include "debugdraw.h" // Debug Draw API. Notice that we need the DEBUG_DRAW_IMPLEMENTATION macro here! #include <glad/glad.h> #include <assert.h> class DDRenderInterfaceCoreGL final : public dd::RenderInterface { public: // // dd::RenderInterface overrides: // void drawPointList(const dd::DrawVertex * points, int count, bool depthEnabled) override { assert(points != nullptr); assert(count > 0 && count <= DEBUG_DRAW_VERTEX_BUFFER_SIZE); glBindVertexArray(linePointVAO); glUseProgram(linePointProgram); glUniformMatrix4fv(linePointProgram_MvpMatrixLocation, 1, GL_TRUE, reinterpret_cast<float*>(&mvpMatrix)); bool already = glIsEnabled(GL_DEPTH_TEST); if (depthEnabled) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); } // NOTE: Could also use glBufferData to take advantage of the buffer orphaning trick... glBindBuffer(GL_ARRAY_BUFFER, linePointVBO); glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(dd::DrawVertex), points); // Issue the draw call: glDrawArrays(GL_POINTS, 0, count); glUseProgram(0); glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); checkGLError(__FILE__, __LINE__); if (already) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); } } void drawLineList(const dd::DrawVertex * lines, int count, bool depthEnabled) override { assert(lines != nullptr); assert(count > 0 && count <= DEBUG_DRAW_VERTEX_BUFFER_SIZE); glBindVertexArray(linePointVAO); glUseProgram(linePointProgram); glUniformMatrix4fv(linePointProgram_MvpMatrixLocation, 1, GL_TRUE, reinterpret_cast<const float*>(&mvpMatrix)); bool already = glIsEnabled(GL_DEPTH_TEST); if (depthEnabled) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); } // NOTE: Could also use glBufferData to take advantage of the buffer orphaning trick... glBindBuffer(GL_ARRAY_BUFFER, linePointVBO); glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(dd::DrawVertex), lines); // Issue the draw call: glDrawArrays(GL_LINES, 0, count); glUseProgram(0); glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); checkGLError(__FILE__, __LINE__); if (already) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); } } void drawGlyphList(const dd::DrawVertex * glyphs, int count, dd::GlyphTextureHandle glyphTex) override { assert(glyphs != nullptr); assert(count > 0 && count <= DEBUG_DRAW_VERTEX_BUFFER_SIZE); glBindVertexArray(textVAO); glUseProgram(textProgram); // These doesn't have to be reset every draw call, I'm just being lazy ;) glUniform1i(textProgram_GlyphTextureLocation, 0); glUniform2f(textProgram_ScreenDimensions, static_cast<GLfloat>(width), static_cast<GLfloat>(height)); if (glyphTex != nullptr) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, handleToGL(glyphTex)); } glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); bool already = glIsEnabled(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST); glBindBuffer(GL_ARRAY_BUFFER, textVBO); glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(dd::DrawVertex), glyphs); glDrawArrays(GL_TRIANGLES, 0, count); // Issue the draw call glDisable(GL_BLEND); glUseProgram(0); glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); checkGLError(__FILE__, __LINE__); if (already) { glEnable(GL_DEPTH_TEST); } } dd::GlyphTextureHandle createGlyphTexture(int width, int height, const void * pixels) override { assert(width > 0 && height > 0); assert(pixels != nullptr); GLuint textureId = 0; glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); checkGLError(__FILE__, __LINE__); return GLToHandle(textureId); } void destroyGlyphTexture(dd::GlyphTextureHandle glyphTex) override { if (glyphTex == nullptr) { return; } const GLuint textureId = handleToGL(glyphTex); glBindTexture(GL_TEXTURE_2D, 0); glDeleteTextures(1, &textureId); } // These two can also be implemented to perform GL render // state setup/cleanup, but we don't use them in this sample. //void beginDraw() override { } //void endDraw() override { } // // Local methods: // DDRenderInterfaceCoreGL() : mvpMatrix() , width(0) , height(0) , linePointProgram(0) , linePointProgram_MvpMatrixLocation(-1) , textProgram(0) , textProgram_GlyphTextureLocation(-1) , textProgram_ScreenDimensions(-1) , linePointVAO(0) , linePointVBO(0) , textVAO(0) , textVBO(0) { //std::printf("\n"); //std::printf("GL_VENDOR : %s\n", glGetString(GL_VENDOR)); //std::printf("GL_RENDERER : %s\n", glGetString(GL_RENDERER)); //std::printf("GL_VERSION : %s\n", glGetString(GL_VERSION)); //std::printf("GLSL_VERSION : %s\n\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); //std::printf("DDRenderInterfaceCoreGL initializing ...\n"); // Default OpenGL states: glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); // This has to be enabled since the point drawing shader will use gl_PointSize. glEnable(GL_PROGRAM_POINT_SIZE); setupShaderPrograms(); setupVertexBuffers(); //std::printf("DDRenderInterfaceCoreGL ready!\n\n"); } ~DDRenderInterfaceCoreGL() { glDeleteProgram(linePointProgram); glDeleteProgram(textProgram); glDeleteVertexArrays(1, &linePointVAO); glDeleteBuffers(1, &linePointVBO); glDeleteVertexArrays(1, &textVAO); glDeleteBuffers(1, &textVBO); } void setupShaderPrograms() { //std::printf("> DDRenderInterfaceCoreGL::setupShaderPrograms()\n"); // // Line/point drawing shader: // { GLuint linePointVS = glCreateShader(GL_VERTEX_SHADER); glShaderSource(linePointVS, 1, &linePointVertShaderSrc, nullptr); compileShader(linePointVS); GLint linePointFS = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(linePointFS, 1, &linePointFragShaderSrc, nullptr); compileShader(linePointFS); linePointProgram = glCreateProgram(); glAttachShader(linePointProgram, linePointVS); glAttachShader(linePointProgram, linePointFS); glBindAttribLocation(linePointProgram, 0, "in_Position"); glBindAttribLocation(linePointProgram, 1, "in_ColorPointSize"); linkProgram(linePointProgram); linePointProgram_MvpMatrixLocation = glGetUniformLocation(linePointProgram, "u_MvpMatrix"); if (linePointProgram_MvpMatrixLocation < 0) { //errorF("Unable to get u_MvpMatrix uniform location!"); } checkGLError(__FILE__, __LINE__); } // // Text rendering shader: // { GLuint textVS = glCreateShader(GL_VERTEX_SHADER); glShaderSource(textVS, 1, &textVertShaderSrc, nullptr); compileShader(textVS); GLint textFS = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(textFS, 1, &textFragShaderSrc, nullptr); compileShader(textFS); textProgram = glCreateProgram(); glAttachShader(textProgram, textVS); glAttachShader(textProgram, textFS); glBindAttribLocation(textProgram, 0, "in_Position"); glBindAttribLocation(textProgram, 1, "in_TexCoords"); glBindAttribLocation(textProgram, 2, "in_Color"); linkProgram(textProgram); textProgram_GlyphTextureLocation = glGetUniformLocation(textProgram, "u_glyphTexture"); if (textProgram_GlyphTextureLocation < 0) { //errorF("Unable to get u_glyphTexture uniform location!"); } textProgram_ScreenDimensions = glGetUniformLocation(textProgram, "u_screenDimensions"); if (textProgram_ScreenDimensions < 0) { //errorF("Unable to get u_screenDimensions uniform location!"); } checkGLError(__FILE__, __LINE__); } } void setupVertexBuffers() { //std::printf("> DDRenderInterfaceCoreGL::setupVertexBuffers()\n"); // // Lines/points vertex buffer: // { glGenVertexArrays(1, &linePointVAO); glGenBuffers(1, &linePointVBO); checkGLError(__FILE__, __LINE__); glBindVertexArray(linePointVAO); glBindBuffer(GL_ARRAY_BUFFER, linePointVBO); // RenderInterface will never be called with a batch larger than // DEBUG_DRAW_VERTEX_BUFFER_SIZE vertexes, so we can allocate the same amount here. glBufferData(GL_ARRAY_BUFFER, DEBUG_DRAW_VERTEX_BUFFER_SIZE * sizeof(dd::DrawVertex), nullptr, GL_STREAM_DRAW); checkGLError(__FILE__, __LINE__); // Set the vertex format expected by 3D points and lines: std::size_t offset = 0; glEnableVertexAttribArray(0); // in_Position (vec3) glVertexAttribPointer( /* index = */ 0, /* size = */ 3, /* type = */ GL_FLOAT, /* normalize = */ GL_FALSE, /* stride = */ sizeof(dd::DrawVertex), /* offset = */ reinterpret_cast<void *>(offset)); offset += sizeof(float) * 3; glEnableVertexAttribArray(1); // in_ColorPointSize (vec4) glVertexAttribPointer( /* index = */ 1, /* size = */ 4, /* type = */ GL_FLOAT, /* normalize = */ GL_FALSE, /* stride = */ sizeof(dd::DrawVertex), /* offset = */ reinterpret_cast<void *>(offset)); checkGLError(__FILE__, __LINE__); // VAOs can be a pain in the neck if left enabled... glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); } // // Text rendering vertex buffer: // { glGenVertexArrays(1, &textVAO); glGenBuffers(1, &textVBO); checkGLError(__FILE__, __LINE__); glBindVertexArray(textVAO); glBindBuffer(GL_ARRAY_BUFFER, textVBO); // NOTE: A more optimized implementation might consider combining // both the lines/points and text buffers to save some memory! glBufferData(GL_ARRAY_BUFFER, DEBUG_DRAW_VERTEX_BUFFER_SIZE * sizeof(dd::DrawVertex), nullptr, GL_STREAM_DRAW); checkGLError(__FILE__, __LINE__); // Set the vertex format expected by the 2D text: std::size_t offset = 0; glEnableVertexAttribArray(0); // in_Position (vec2) glVertexAttribPointer( /* index = */ 0, /* size = */ 2, /* type = */ GL_FLOAT, /* normalize = */ GL_FALSE, /* stride = */ sizeof(dd::DrawVertex), /* offset = */ reinterpret_cast<void *>(offset)); offset += sizeof(float) * 2; glEnableVertexAttribArray(1); // in_TexCoords (vec2) glVertexAttribPointer( /* index = */ 1, /* size = */ 2, /* type = */ GL_FLOAT, /* normalize = */ GL_FALSE, /* stride = */ sizeof(dd::DrawVertex), /* offset = */ reinterpret_cast<void *>(offset)); offset += sizeof(float) * 2; glEnableVertexAttribArray(2); // in_Color (vec4) glVertexAttribPointer( /* index = */ 2, /* size = */ 4, /* type = */ GL_FLOAT, /* normalize = */ GL_FALSE, /* stride = */ sizeof(dd::DrawVertex), /* offset = */ reinterpret_cast<void *>(offset)); checkGLError(__FILE__, __LINE__); // Ditto. glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); } } static GLuint handleToGL(dd::GlyphTextureHandle handle) { const std::size_t temp = reinterpret_cast<std::size_t>(handle); return static_cast<GLuint>(temp); } static dd::GlyphTextureHandle GLToHandle(const GLuint id) { const std::size_t temp = static_cast<std::size_t>(id); return reinterpret_cast<dd::GlyphTextureHandle>(temp); } static void checkGLError(const char * file, const int line) { GLenum err; while ((err = glGetError()) != GL_NO_ERROR) { //errorF("%s(%d) : GL_CORE_ERROR=0x%X - %s", file, line, err, errorToString(err)); } } static void compileShader(const GLuint shader) { glCompileShader(shader); checkGLError(__FILE__, __LINE__); GLint status; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); checkGLError(__FILE__, __LINE__); if (status == GL_FALSE) { GLchar strInfoLog[1024] = {0}; glGetShaderInfoLog(shader, sizeof(strInfoLog) - 1, nullptr, strInfoLog); //errorF("\n>>> Shader compiler errors:\n%s", strInfoLog); } } static void linkProgram(const GLuint program) { glLinkProgram(program); checkGLError(__FILE__, __LINE__); GLint status; glGetProgramiv(program, GL_LINK_STATUS, &status); checkGLError(__FILE__, __LINE__); if (status == GL_FALSE) { GLchar strInfoLog[1024] = {0}; glGetProgramInfoLog(program, sizeof(strInfoLog) - 1, nullptr, strInfoLog); //errorF("\n>>> Program linker errors:\n%s", strInfoLog); } } // The "model-view-projection" matrix for the scene. // In this demo, it consists of the camera's view and projection matrices only. math::float4x4 mvpMatrix; unsigned width, height; private: GLuint linePointProgram; GLint linePointProgram_MvpMatrixLocation; GLuint textProgram; GLint textProgram_GlyphTextureLocation; GLint textProgram_ScreenDimensions; GLuint linePointVAO; GLuint linePointVBO; GLuint textVAO; GLuint textVBO; static const char * linePointVertShaderSrc; static const char * linePointFragShaderSrc; static const char * textVertShaderSrc; static const char * textFragShaderSrc; }; // class DDRenderInterfaceCoreGL // ======================================================== // Minimal shaders we need for the debug primitives: // ======================================================== const char * DDRenderInterfaceCoreGL::linePointVertShaderSrc = "\n" "#version 150\n" "\n" "in vec3 in_Position;\n" "in vec4 in_ColorPointSize;\n" "\n" "out vec4 v_Color;\n" "uniform mat4 u_MvpMatrix;\n" "\n" "void main()\n" "{\n" " gl_Position = u_MvpMatrix * vec4(in_Position, 1.0);\n" " gl_PointSize = in_ColorPointSize.w;\n" " v_Color = vec4(in_ColorPointSize.xyz, 1.0);\n" "}\n"; const char * DDRenderInterfaceCoreGL::linePointFragShaderSrc = "\n" "#version 150\n" "\n" "in vec4 v_Color;\n" "out vec4 out_FragColor;\n" "\n" "void main()\n" "{\n" " out_FragColor = v_Color;\n" "}\n"; const char * DDRenderInterfaceCoreGL::textVertShaderSrc = "\n" "#version 150\n" "\n" "in vec2 in_Position;\n" "in vec2 in_TexCoords;\n" "in vec3 in_Color;\n" "\n" "uniform vec2 u_screenDimensions;\n" "\n" "out vec2 v_TexCoords;\n" "out vec4 v_Color;\n" "\n" "void main()\n" "{\n" " // Map to normalized clip coordinates:\n" " float x = ((2.0 * (in_Position.x - 0.5)) / u_screenDimensions.x) - 1.0;\n" " float y = 1.0 - ((2.0 * (in_Position.y - 0.5)) / u_screenDimensions.y);\n" "\n" " gl_Position = vec4(x, y, 0.0, 1.0);\n" " v_TexCoords = in_TexCoords;\n" " v_Color = vec4(in_Color, 1.0);\n" "}\n"; const char * DDRenderInterfaceCoreGL::textFragShaderSrc = "\n" "#version 150\n" "\n" "in vec2 v_TexCoords;\n" "in vec4 v_Color;\n" "\n" "uniform sampler2D u_glyphTexture;\n" "out vec4 out_FragColor;\n" "\n" "void main()\n" "{\n" " out_FragColor = v_Color;\n" " out_FragColor.a = texture(u_glyphTexture, v_TexCoords).r;\n" "}\n"; DDRenderInterfaceCoreGL* ModuleDebugDraw::implementation = 0; bool ModuleDebugDraw::Init() { implementation = new DDRenderInterfaceCoreGL; dd::initialize(implementation); return true; } bool ModuleDebugDraw::Clean() { dd::shutdown(); delete implementation; implementation = 0; return true; } bool ModuleDebugDraw::Update() { assert(implementation); implementation->width = ModuleRender::ms_width; implementation->height = ModuleRender::ms_height; implementation->mvpMatrix = App->m_Editor->m_Camera->m_Frustum.ComputeViewProjMatrix(); dd::flush(); return true; }
// Copyright (c) 2017-2018 Hartmut Kaiser // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #if !defined(PHYLANX_PRIMITIVES_PARALLEL_BLOCK_OPERATION_OCT_08_2017_0807PM) #define PHYLANX_PRIMITIVES_PARALLEL_BLOCK_OPERATION_OCT_08_2017_0807PM #include <phylanx/config.hpp> #include <phylanx/execution_tree/primitives/base_primitive.hpp> #include <phylanx/execution_tree/primitives/primitive_component_base.hpp> #include <phylanx/ir/node_data.hpp> #include <hpx/lcos/future.hpp> #include <memory> #include <string> #include <utility> #include <vector> namespace phylanx { namespace execution_tree { namespace primitives { class parallel_block_operation : public primitive_component_base , public std::enable_shared_from_this<parallel_block_operation> { protected: hpx::future<primitive_argument_type> eval( primitive_arguments_type const& operands, primitive_arguments_type const& args) const; public: static match_pattern_type const match_data; parallel_block_operation() = default; parallel_block_operation( primitive_arguments_type&& operands, std::string const& name, std::string const& codename); hpx::future<primitive_argument_type> eval( primitive_arguments_type const& args) const override; }; inline primitive create_parallel_block_operation( hpx::id_type const& locality, primitive_arguments_type&& operands, std::string const& name = "", std::string const& codename = "") { return create_primitive_component( locality, "parallel_block", std::move(operands), name, codename); } }}} #endif
{ Game : RainbowSix.exe Version: 1.0 Date : 11-22-16 Author : Brian Coffey Script for No Recoil. Status: Working 11/22 } [ENABLE] aobscanmodule(INJECT_No_Recoil,RainbowSixGame.exe+755239,F3 0F 10 4B 70 44) alloc(newmem_no_recoil,2048,RainbowSixGame.exe+755239) stealtheditex(stealth,INJECT_No_Recoil,1) label(originalcode_No_Recoil) label(returnhere) label(No_Recoil) registersymbol(No_Recoil) alloc(_recoilValue,8) registersymbol(_recoilValue) //====================================================== newmem_no_recoil: movss xmm0, [_recoilValue] movss xmm2,xmm0 movss xmm1,xmm0 movss [rbx+48],xmm0 movss [rbx+70],xmm0 movss [rbx+40],xmm0 movss [rbx+4C],xmm0 movss [rbx+44],xmm0 movss [rbx+5C],xmm0 // make our Recoil Value = 0 movss [rbx+54],xmm0 // make rbx+54 = 0 movss [rbx+58],xmm0 movss [rbx+50],xmm0 originalcode_No_Recoil: jmp returnhere _recoilValue: dd (float)0.0 //enable: //db 0 //====================================================== stealth: No_Recoil: jmp newmem_no_recoil returnhere: [DISABLE] No_Recoil: movss xmm1,[rbx+70] unregistersymbol(No_Recoil) dealloc(newmem_no_recoil) { Recoil Notes / Scratch Buffer rbx+28 = "RainbowSix.exe"+02E2AF48 + 18 + D0 + 488 + 98 + 158 //RECOIL_BASE = rbx = "RainbowSix.exe"+02E2AF48 + 18 + D0 + 488 + 98 + 130 //Known Recoil VALUE address = rbx+28 -- moved into xmm0 //{current recoil amount? = rbx+74 -- moved into xmm1 xmm0 - movss xmm0,[rbx+58] // --- Injection Here --- \\ subss xmm0,[rbx+50] mulss xmm0,xmm2 -- find out where xmm2 is calculated. adds xmm0,[rbx+50] movss [rbx+10],xmm0 -- moves current value of xmm0 into rbx+10 // possible current recoil amount = [rbx+10] // possible_current_recoil = "RainbowSix.exe"+02E2AF48 + 18 + D0 + 488 + 98 + 140 // Recoil 1 (same as above, just copied for reference) RainbowSix.RDcGroupCondition::IsActive+4CBC2 - movss xmm0,[rbx+58] RainbowSix.RDcGroupCondition::IsActive+4CBC7 - subss xmm0,[rbx+50] RainbowSix.RDcGroupCondition::IsActive+4CBCC - mulss xmm0,xmm2 RainbowSix.RDcGroupCondition::IsActive+4CBD0 - addss xmm0,[rbx+50] RainbowSix.RDcGroupCondition::IsActive+4CBD5 - movss [rbx+10],xmm0 // Recoil 2 RainbowSix.RDcGroupCondition::IsActive+4CBA7 - movss xmm0,[rbx+4C] RainbowSix.RDcGroupCondition::IsActive+4CBAC - subss xmm0,[rbx+44] RainbowSix.RDcGroupCondition::IsActive+4CBB1 - mulss xmm0,xmm2 RainbowSix.RDcGroupCondition::IsActive+4CBB5 - addss xmm0,[rbx+44] RainbowSix.RDcGroupCondition::IsActive+4CBBA - movss [rbx+00000098],xmm0 // rbx+18 also gets effected by xmm0-> // Recoil 3 RainbowSix.RDcGroupCondition::IsActive+4CBDA - movss xmm0,[rbx+5C] RainbowSix.RDcGroupCondition::IsActive+4CBDF - subss xmm0,[rbx+54] RainbowSix.RDcGroupCondition::IsActive+4CBE4 - mulss xmm0,xmm2 RainbowSix.RDcGroupCondition::IsActive+4CBE8 - addss xmm0,[rbx+54] RainbowSix.RDcGroupCondition::IsActive+4CBED - movss [rbx+18],xmm0 // current possible effective injection: alloc(_recoilValue,8) registersymbol(_recoilValue) newmem: movss xmm0, [_recoilValue] movss [rbx+48],xmm0 movss [rbx+70],xmm0 movss [rbx+40],xmm0 movss [rbx+4C],xmm0 movss [rbx+44],xmm0 movss xmm2,xmm0 movss [rbx+5C],xmm0 // make our Recoil Value = 0 movss [rbx+54],xmm0 // make rbx+54 = 0 movss xmm2,xmm0 // make xmm2 = 0 // repeated, for good measure. movss [rbx+58],xmm0 movss [rbx+50],xmm0 originalcode: _recoilValue dd (float)0.0 { // ORIGINAL CODE - INJECTION POINT: RainbowSix.RDcGroupCondition::IsActive+4CB83 RainbowSix.RDcGroupCondition::IsActive+4CB5A: F3 0F10 43 3C - movss xmm0,[rbx+3C] RainbowSix.RDcGroupCondition::IsActive+4CB5F: F3 0F5E C3 - divss xmm0,xmm3 RainbowSix.RDcGroupCondition::IsActive+4CB63: 41 0F2F C1 - comiss xmm0,xmm9 RainbowSix.RDcGroupCondition::IsActive+4CB67: 76 11 - jna 7FF76052EC1A RainbowSix.RDcGroupCondition::IsActive+4CB69: F3 0F10 15 D7B35701 - movss xmm2,[7FF761AA9FE8] RainbowSix.RDcGroupCondition::IsActive+4CB71: 44 0F28 C8 - movaps xmm9,xmm0 RainbowSix.RDcGroupCondition::IsActive+4CB75: 0F2F C2 - comiss xmm0,xmm2 RainbowSix.RDcGroupCondition::IsActive+4CB78: 73 04 - jae 7FF76052EC1E RainbowSix.RDcGroupCondition::IsActive+4CB7A: 41 0F28 D1 - movaps xmm2,xmm9 RainbowSix.RDcGroupCondition::IsActive+4CB7E: F3 0F10 43 48 - movss xmm0,[rbx+48] // ---------- INJECTING HERE ---------- RainbowSix.RDcGroupCondition::IsActive+4CB83: F3 0F10 4B 70 - movss xmm1,[rbx+70] // ---------- DONE INJECTING ---------- RainbowSix.RDcGroupCondition::IsActive+4CB88: 44 0F28 4C 24 40 - movaps xmm9,[rsp+40] RainbowSix.RDcGroupCondition::IsActive+4CB8E: 0F2F F9 - comiss xmm7,xmm1 RainbowSix.RDcGroupCondition::IsActive+4CB91: F3 0F5C 43 40 - subss xmm0,[rbx+40] RainbowSix.RDcGroupCondition::IsActive+4CB96: F3 0F59 C2 - mulss xmm0,xmm2 RainbowSix.RDcGroupCondition::IsActive+4CB9A: F3 0F58 43 40 - addss xmm0,[rbx+40] RainbowSix.RDcGroupCondition::IsActive+4CB9F: F3 0F11 83 94000000 - movss [rbx+00000094],xmm0 RainbowSix.RDcGroupCondition::IsActive+4CBA7: F3 0F10 43 4C - movss xmm0,[rbx+4C] RainbowSix.RDcGroupCondition::IsActive+4CBAC: F3 0F5C 43 44 - subss xmm0,[rbx+44] RainbowSix.RDcGroupCondition::IsActive+4CBB1: F3 0F59 C2 - mulss xmm0,xmm2 RainbowSix.RDcGroupCondition::IsActive+4CBB5: F3 0F58 43 44 - addss xmm0,[rbx+44] }
; A037585: Base 6 digits are, in order, the first n terms of the periodic sequence with initial period 3,1. ; 3,19,117,703,4221,25327,151965,911791,5470749,32824495,196946973,1181681839,7090091037,42540546223,255243277341,1531459664047,9188757984285,55132547905711,330795287434269,1984771724605615 seq $0,33116 ; Base-6 digits are, in order, the first n terms of the periodic sequence with initial period 1,0. seq $0,63204 ; Dimension of the space of weight 2n cuspidal newforms for Gamma_0( 25 ).
############################################################################### # Copyright 2019 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .text .p2align 6, 0x90 _mla_1x1: movq (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mov %rbx, %r8 ret .p2align 6, 0x90 _mul_1x1: movq (%rcx), %rdx mulxq (%rsi), %rax, %rdx movq %rax, (%rdi) movq %rdx, (8)(%rdi) ret .p2align 6, 0x90 _mla_2x2: movq (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mov %rbp, %r9 movq (8)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (8)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mov %rbp, %r9 ret .p2align 6, 0x90 _mul_2x2: call _mla_2x2 movq %r8, (16)(%rdi) movq %r9, (24)(%rdi) ret .p2align 6, 0x90 _mla_3x3: movq (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mov %rbx, %r10 movq (8)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (8)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mov %rbx, %r10 movq (16)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (16)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mov %rbx, %r10 ret .p2align 6, 0x90 _mul_3x3: call _mla_3x3 movq %r8, (24)(%rdi) movq %r9, (32)(%rdi) movq %r10, (40)(%rdi) ret .p2align 6, 0x90 _mla_4x2: movq (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mov %rbp, %r11 movq (8)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (8)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mov %rbp, %r11 ret .p2align 6, 0x90 _mla_4x4: call _mla_4x2 add $(16), %rdi add $(16), %rcx call _mla_4x2 sub $(16), %rdi sub $(16), %rcx ret .p2align 6, 0x90 _mul_4x4: call _mla_4x4 movq %r8, (32)(%rdi) movq %r9, (40)(%rdi) movq %r10, (48)(%rdi) movq %r11, (56)(%rdi) ret .p2align 6, 0x90 _mla_5x2: mov (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mov %rbx, %r12 mov (8)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (8)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mov %rbx, %r12 ret .p2align 6, 0x90 _mla_5x5: mov (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mov %rbx, %r12 add $(8), %rdi add $(8), %rcx call _mla_5x2 add $(16), %rdi add $(16), %rcx call _mla_5x2 sub $(24), %rdi sub $(24), %rcx ret .p2align 6, 0x90 _mul_5x5: call _mla_5x5 movq %r8, (40)(%rdi) movq %r9, (48)(%rdi) movq %r10, (56)(%rdi) movq %r11, (64)(%rdi) movq %r12, (72)(%rdi) ret .p2align 6, 0x90 _mla_6x2: mov (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mov %rbp, %r13 mov (8)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (8)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mov %rbp, %r13 ret .p2align 6, 0x90 _mla_6x6: call _mla_6x2 add $(16), %rdi add $(16), %rcx call _mla_6x2 add $(16), %rdi add $(16), %rcx call _mla_6x2 sub $(32), %rdi sub $(32), %rcx ret .p2align 6, 0x90 _mul_6x6: call _mla_6x6 movq %r8, (48)(%rdi) movq %r9, (56)(%rdi) movq %r10, (64)(%rdi) movq %r11, (72)(%rdi) movq %r12, (80)(%rdi) movq %r13, (88)(%rdi) ret .p2align 6, 0x90 _mla_7x2: mov (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mulx (48)(%rsi), %r13, %rbx add %r14, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mov %rbx, %r14 mov (8)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (8)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mulx (48)(%rsi), %r13, %rbx add %r14, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mov %rbx, %r14 ret .p2align 6, 0x90 _mla_7x7: mov (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mulx (48)(%rsi), %r13, %rbx add %r14, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mov %rbx, %r14 add $(8), %rdi add $(8), %rcx call _mla_7x2 add $(16), %rdi add $(16), %rcx call _mla_7x2 add $(16), %rdi add $(16), %rcx call _mla_7x2 sub $(40), %rdi sub $(40), %rcx ret .p2align 6, 0x90 _mul_7x7: call _mla_7x7 movq %r8, (56)(%rdi) movq %r9, (64)(%rdi) movq %r10, (72)(%rdi) movq %r11, (80)(%rdi) movq %r12, (88)(%rdi) movq %r13, (96)(%rdi) movq %r14, (104)(%rdi) ret .p2align 6, 0x90 _mla_8x1: mov (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mulx (48)(%rsi), %r13, %rbx add %r14, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mulx (56)(%rsi), %r14, %rbp add %r15, %r14 adc $(0), %rbp add %rbx, %r14 adc $(0), %rbp mov %rbp, %r15 ret .p2align 6, 0x90 _mla_8x2: mov (%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mulx (48)(%rsi), %r13, %rbx add %r14, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mulx (56)(%rsi), %r14, %rbp add %r15, %r14 adc $(0), %rbp add %rbx, %r14 adc $(0), %rbp mov %rbp, %r15 mov (8)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (8)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mulx (48)(%rsi), %r13, %rbx add %r14, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mulx (56)(%rsi), %r14, %rbp add %r15, %r14 adc $(0), %rbp add %rbx, %r14 adc $(0), %rbp mov %rbp, %r15 ret .p2align 6, 0x90 _mla_8x3: call _mla_8x1 add $(8), %rdi add $(8), %rcx call _mla_8x2 sub $(8), %rdi sub $(8), %rcx ret .p2align 6, 0x90 _mla_8x4: call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 sub $(16), %rdi sub $(16), %rcx ret .p2align 6, 0x90 _mla_8x5: call _mla_8x1 add $(8), %rdi add $(8), %rcx call _mla_8x4 sub $(8), %rdi sub $(8), %rcx ret .p2align 6, 0x90 _mla_8x6: call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x4 sub $(16), %rdi sub $(16), %rcx ret .p2align 6, 0x90 _mla_8x7: call _mla_8x1 add $(8), %rdi add $(8), %rcx call _mla_8x6 sub $(8), %rdi sub $(8), %rcx ret .p2align 6, 0x90 _mla_8x8: call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 sub $(48), %rdi sub $(48), %rcx ret .p2align 6, 0x90 _mul_8x8: call _mla_8x8 movq %r8, (64)(%rdi) movq %r9, (72)(%rdi) movq %r10, (80)(%rdi) movq %r11, (88)(%rdi) movq %r12, (96)(%rdi) movq %r13, (104)(%rdi) movq %r14, (112)(%rdi) movq %r15, (120)(%rdi) ret .p2align 6, 0x90 _mul_9x9: call _mla_8x8 mov (64)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (64)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mulx (48)(%rsi), %r13, %rbx add %r14, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mulx (56)(%rsi), %r14, %rbp add %r15, %r14 adc $(0), %rbp add %rbx, %r14 adc $(0), %rbp mov %rbp, %r15 push %r15 mov (64)(%rsi), %rdx mov (64)(%rdi), %r15 mulx (%rcx), %rax, %rbx add %r15, %rax adc $(0), %rbx mov %rax, (64)(%rdi) mulx (8)(%rcx), %r15, %rbp add %r8, %r15 adc $(0), %rbp add %rbx, %r15 adc $(0), %rbp mulx (16)(%rcx), %r8, %rbx add %r9, %r8 adc $(0), %rbx add %rbp, %r8 adc $(0), %rbx mulx (24)(%rcx), %r9, %rbp add %r10, %r9 adc $(0), %rbp add %rbx, %r9 adc $(0), %rbp mulx (32)(%rcx), %r10, %rbx add %r11, %r10 adc $(0), %rbx add %rbp, %r10 adc $(0), %rbx mulx (40)(%rcx), %r11, %rbp add %r12, %r11 adc $(0), %rbp add %rbx, %r11 adc $(0), %rbp mulx (48)(%rcx), %r12, %rbx add %r13, %r12 adc $(0), %rbx add %rbp, %r12 adc $(0), %rbx mulx (56)(%rcx), %r13, %rbp add %r14, %r13 adc $(0), %rbp add %rbx, %r13 adc $(0), %rbp mov %rbp, %r14 movq %r15, (72)(%rdi) mulx (64)(%rcx), %rbp, %r15 pop %rax add %rax, %r14 adc $(0), %r15 add %rbp, %r14 adc $(0), %r15 movq %r8, (80)(%rdi) movq %r9, (88)(%rdi) movq %r10, (96)(%rdi) movq %r11, (104)(%rdi) movq %r12, (112)(%rdi) movq %r13, (120)(%rdi) movq %r14, (128)(%rdi) movq %r15, (136)(%rdi) ret .p2align 6, 0x90 _mul_10x10: call _mla_8x8 add $(64), %rdi add $(64), %rcx call _mla_8x2 push %r15 push %r14 add $(64), %rsi sub $(64), %rcx xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx mov %r13, %r15 mov %r12, %r14 mov %r11, %r13 mov %r10, %r12 mov %r9, %r11 mov %r8, %r10 movq (8)(%rdi), %r9 movq (%rdi), %r8 call _mla_8x2 movq %r8, (16)(%rdi) movq %r9, (24)(%rdi) movq %r10, (32)(%rdi) movq %r11, (40)(%rdi) movq %r12, (48)(%rdi) movq %r13, (56)(%rdi) add $(64), %rdi xor %r10, %r10 pop %r8 pop %r9 add %r14, %r8 adc %r15, %r9 adc $(0), %r10 xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx add $(64), %rcx call _mla_2x2 add $(16), %rdi add %r10, %r8 adc $(0), %r9 movq %r8, (%rdi) movq %r9, (8)(%rdi) ret .p2align 6, 0x90 _mul_11x11: call _mla_8x8 add $(64), %rdi add $(64), %rcx call _mla_8x3 push %r15 push %r14 push %r13 add $(64), %rsi sub $(64), %rcx xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx mov %r12, %r15 mov %r11, %r14 mov %r10, %r13 mov %r9, %r12 mov %r8, %r11 movq (16)(%rdi), %r10 movq (8)(%rdi), %r9 movq (%rdi), %r8 call _mla_8x3 movq %r8, (24)(%rdi) movq %r9, (32)(%rdi) movq %r10, (40)(%rdi) movq %r11, (48)(%rdi) movq %r12, (56)(%rdi) add $(64), %rdi xor %r11, %r11 pop %r8 pop %r9 pop %r10 add %r13, %r8 adc %r14, %r9 adc %r15, %r10 adc $(0), %r11 xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx add $(64), %rcx call _mla_3x3 add $(24), %rdi add %r11, %r8 adc $(0), %r9 adc $(0), %r10 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) ret .p2align 6, 0x90 _mul_12x12: call _mla_8x8 add $(64), %rdi add $(64), %rcx call _mla_8x4 push %r15 push %r14 push %r13 push %r12 add $(64), %rsi sub $(64), %rcx xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx mov %r11, %r15 mov %r10, %r14 mov %r9, %r13 mov %r8, %r12 movq (24)(%rdi), %r11 movq (16)(%rdi), %r10 movq (8)(%rdi), %r9 movq (%rdi), %r8 call _mla_8x4 movq %r8, (32)(%rdi) movq %r9, (40)(%rdi) movq %r10, (48)(%rdi) movq %r11, (56)(%rdi) add $(64), %rdi xor %rax, %rax pop %r8 pop %r9 pop %r10 pop %r11 add %r12, %r8 adc %r13, %r9 adc %r14, %r10 adc %r15, %r11 adc $(0), %rax push %rax xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx add $(64), %rcx call _mla_4x4 add $(32), %rdi pop %rax add %rax, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) ret .p2align 6, 0x90 _mul_13x13: call _mla_8x8 add $(64), %rdi add $(64), %rcx call _mla_8x5 push %r15 push %r14 push %r13 push %r12 push %r11 add $(64), %rsi sub $(64), %rcx xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx mov %r10, %r15 mov %r9, %r14 mov %r8, %r13 movq (32)(%rdi), %r12 movq (24)(%rdi), %r11 movq (16)(%rdi), %r10 movq (8)(%rdi), %r9 movq (%rdi), %r8 call _mla_8x5 movq %r8, (40)(%rdi) movq %r9, (48)(%rdi) movq %r10, (56)(%rdi) add $(64), %rdi xor %rax, %rax pop %r8 pop %r9 pop %r10 pop %rbx pop %rbp add %r11, %r8 adc %r12, %r9 adc %r13, %r10 adc %r14, %rbx adc %r15, %rbp adc $(0), %rax push %rax mov %rbx, %r11 mov %rbp, %r12 xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx add $(64), %rcx call _mla_5x5 add $(40), %rdi pop %rax add %rax, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) ret .p2align 6, 0x90 _mul_14x14: call _mla_7x7 add $(56), %rdi add $(56), %rsi call _mla_7x7 movq %r8, (56)(%rdi) movq %r9, (64)(%rdi) movq %r10, (72)(%rdi) movq %r11, (80)(%rdi) movq %r12, (88)(%rdi) movq %r13, (96)(%rdi) movq %r14, (104)(%rdi) movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 add $(56), %rcx sub $(56), %rsi call _mla_7x7 xor %rdx, %rdx movq (56)(%rdi), %rax add %rax, %r8 movq (64)(%rdi), %rax adc %rax, %r9 movq (72)(%rdi), %rax adc %rax, %r10 movq (80)(%rdi), %rax adc %rax, %r11 movq (88)(%rdi), %rax adc %rax, %r12 movq (96)(%rdi), %rax adc %rax, %r13 movq (104)(%rdi), %rax adc %rax, %r14 adc $(0), %rdx push %rdx add $(56), %rdi add $(56), %rsi call _mla_7x7 sub $(112), %rdi sub $(56), %rsi sub $(56), %rcx pop %rdx add %rdx, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 adc $(0), %r14 movq %r8, (168)(%rdi) movq %r9, (176)(%rdi) movq %r10, (184)(%rdi) movq %r11, (192)(%rdi) movq %r12, (200)(%rdi) movq %r13, (208)(%rdi) movq %r14, (216)(%rdi) ret .p2align 6, 0x90 _mul_15x15: call _mla_8x8 add $(64), %rdi add $(64), %rcx call _mla_8x7 movq %r8, (56)(%rdi) movq %r9, (64)(%rdi) movq %r10, (72)(%rdi) movq %r11, (80)(%rdi) movq %r12, (88)(%rdi) movq %r13, (96)(%rdi) movq %r14, (104)(%rdi) movq %r15, (112)(%rdi) add $(64), %rsi sub $(64), %rcx xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mla_8x7 movq %r8, (56)(%rdi) add $(64), %rdi xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx add $(64), %rcx mov %r9, %r8 mov %r10, %r9 mov %r11, %r10 mov %r12, %r11 mov %r13, %r12 mov %r14, %r13 mov %r15, %r14 xor %rdx, %rdx movq (%rdi), %rax add %rax, %r8 movq (8)(%rdi), %rax adc %rax, %r9 movq (16)(%rdi), %rax adc %rax, %r10 movq (24)(%rdi), %rax adc %rax, %r11 movq (32)(%rdi), %rax adc %rax, %r12 movq (40)(%rdi), %rax adc %rax, %r13 movq (48)(%rdi), %rax adc %rax, %r14 adc $(0), %rdx push %rdx call _mla_7x7 add $(56), %rdi pop %rax add %rax, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 adc $(0), %r14 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) movq %r14, (48)(%rdi) ret .p2align 6, 0x90 _mul_16x16: call _mla_8x8 add $(64), %rdi add $(64), %rsi call _mla_8x8 movq %r8, (64)(%rdi) movq %r9, (72)(%rdi) movq %r10, (80)(%rdi) movq %r11, (88)(%rdi) movq %r12, (96)(%rdi) movq %r13, (104)(%rdi) movq %r14, (112)(%rdi) movq %r15, (120)(%rdi) movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 add $(64), %rcx sub $(64), %rsi call _mla_8x8 xor %rdx, %rdx movq (64)(%rdi), %rax add %rax, %r8 movq (72)(%rdi), %rax adc %rax, %r9 movq (80)(%rdi), %rax adc %rax, %r10 movq (88)(%rdi), %rax adc %rax, %r11 movq (96)(%rdi), %rax adc %rax, %r12 movq (104)(%rdi), %rax adc %rax, %r13 movq (112)(%rdi), %rax adc %rax, %r14 movq (120)(%rdi), %rax adc %rax, %r15 adc $(0), %rdx push %rdx add $(64), %rdi add $(64), %rsi call _mla_8x8 sub $(128), %rdi sub $(64), %rsi sub $(64), %rcx pop %rdx add %rdx, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 adc $(0), %r14 adc $(0), %r15 movq %r8, (192)(%rdi) movq %r9, (200)(%rdi) movq %r10, (208)(%rdi) movq %r11, (216)(%rdi) movq %r12, (224)(%rdi) movq %r13, (232)(%rdi) movq %r14, (240)(%rdi) movq %r15, (248)(%rdi) ret mul_lxl_basic: .quad _mul_1x1 - mul_lxl_basic .quad _mul_2x2 - mul_lxl_basic .quad _mul_3x3 - mul_lxl_basic .quad _mul_4x4 - mul_lxl_basic .quad _mul_5x5 - mul_lxl_basic .quad _mul_6x6 - mul_lxl_basic .quad _mul_7x7 - mul_lxl_basic .quad _mul_8x8 - mul_lxl_basic .quad _mul_9x9 - mul_lxl_basic .quad _mul_10x10-mul_lxl_basic .quad _mul_11x11-mul_lxl_basic .quad _mul_12x12-mul_lxl_basic .quad _mul_13x13-mul_lxl_basic .quad _mul_14x14-mul_lxl_basic .quad _mul_15x15-mul_lxl_basic .quad _mul_16x16-mul_lxl_basic mla_lxl_short: .quad _mla_1x1 - mla_lxl_short .quad _mla_2x2 - mla_lxl_short .quad _mla_3x3 - mla_lxl_short .quad _mla_4x4 - mla_lxl_short .quad _mla_5x5 - mla_lxl_short .quad _mla_6x6 - mla_lxl_short .quad _mla_7x7 - mla_lxl_short mla_8xl_tail: .quad _mla_8x1 - mla_8xl_tail .quad _mla_8x2 - mla_8xl_tail .quad _mla_8x3 - mla_8xl_tail .quad _mla_8x4 - mla_8xl_tail .quad _mla_8x5 - mla_8xl_tail .quad _mla_8x6 - mla_8xl_tail .quad _mla_8x7 - mla_8xl_tail .p2align 6, 0x90 _mul_8Nx8M: push %rbx push %rdi push %rsi push %rdx .Lmul_loopAgas_36: push %rdx call _mla_8x8 add $(64), %rdi add $(64), %rsi pop %rdx sub $(8), %rdx jnz .Lmul_loopAgas_36 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) movq %r14, (48)(%rdi) movq %r15, (56)(%rdi) jmp .Lmla_enrtygas_36 .Lmla_loopBgas_36: push %rbx push %rdi push %rsi push %rdx xor %rax, %rax push %rax movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 .LloopAgas_36: push %rdx call _mla_8x8 add $(64), %rdi add $(64), %rsi pop %rdx sub $(8), %rdx jz .Lexit_loopAgas_36 pop %rax neg %rax movq (%rdi), %rax adc %rax, %r8 movq (8)(%rdi), %rax adc %rax, %r9 movq (16)(%rdi), %rax adc %rax, %r10 movq (24)(%rdi), %rax adc %rax, %r11 movq (32)(%rdi), %rax adc %rax, %r12 movq (40)(%rdi), %rax adc %rax, %r13 movq (48)(%rdi), %rax adc %rax, %r14 movq (56)(%rdi), %rax adc %rax, %r15 sbb %rax, %rax push %rax jmp .LloopAgas_36 .Lexit_loopAgas_36: pop %rax neg %rax adc $(0), %r8 movq %r8, (%rdi) adc $(0), %r9 movq %r9, (8)(%rdi) adc $(0), %r10 movq %r10, (16)(%rdi) adc $(0), %r11 movq %r11, (24)(%rdi) adc $(0), %r12 movq %r12, (32)(%rdi) adc $(0), %r13 movq %r13, (40)(%rdi) adc $(0), %r14 movq %r14, (48)(%rdi) adc $(0), %r15 movq %r15, (56)(%rdi) .Lmla_enrtygas_36: pop %rdx pop %rsi pop %rdi add $(64), %rdi add $(64), %rcx pop %rbx sub $(8), %rbx jnz .Lmla_loopBgas_36 ret .p2align 6, 0x90 _mla_simple: xor %rax, %rax mov %rdx, %r11 cmp %rbx, %r11 jge .Lms_mla_entrygas_37 xor %rbx, %r11 xor %r11, %rbx xor %rbx, %r11 xor %rcx, %rsi xor %rsi, %rcx xor %rcx, %rsi jmp .Lms_mla_entrygas_37 .Lms_loopBgas_37: push %rbx push %rdi push %rsi push %r11 push %rax movq (%rcx), %rdx xor %r10, %r10 .Lms_loopAgas_37: mulxq (%rsi), %r8, %r9 add $(8), %rdi add $(8), %rsi add %r10, %r8 adc $(0), %r9 addq (-8)(%rdi), %r8 adc $(0), %r9 movq %r8, (-8)(%rdi) mov %r9, %r10 sub $(1), %r11 jnz .Lms_loopAgas_37 pop %rax shr $(1), %rax adcq (%rdi), %r10 movq %r10, (%rdi) adc $(0), %rax pop %r11 pop %rsi pop %rdi pop %rbx add $(8), %rdi add $(8), %rcx .Lms_mla_entrygas_37: sub $(1), %rbx jnc .Lms_loopBgas_37 ret .p2align 6, 0x90 _mul_NxM: sub $(56), %rsp cmp $(8), %rbx jge .Lregular_entrygas_38 cmp $(8), %rdx jge .Lirregular_entrygas_38 mov %rdx, %r8 add %rbx, %r8 mov %rdi, %rbp xor %rax, %rax .L__0000gas_38: movq %rax, (%rbp) add $(8), %rbp sub $(1), %r8 jnz .L__0000gas_38 call _mla_simple jmp .Lquitgas_38 .Lirregular_entrygas_38: mov %rbx, (%rsp) mov %rdx, (24)(%rsp) mov %rdx, (32)(%rsp) lea mla_8xl_tail(%rip), %rax mov (-8)(%rax,%rbx,8), %rbp add %rbp, %rax mov %rax, (48)(%rsp) jmp .Lirr_init_entrygas_38 .Lirr_init_loopgas_38: mov %rdx, (32)(%rsp) call *%rax mov (%rsp), %rbx movq %r8, (%rdi,%rbx,8) movq %r9, (8)(%rdi,%rbx,8) movq %r10, (16)(%rdi,%rbx,8) movq %r11, (24)(%rdi,%rbx,8) movq %r12, (32)(%rdi,%rbx,8) movq %r13, (40)(%rdi,%rbx,8) movq %r14, (48)(%rdi,%rbx,8) movq %r15, (56)(%rdi,%rbx,8) add $(64), %rsi add $(64), %rdi xor %r8, %r8 xor %r9, %r9 xor %r10, %r10 xor %r11, %r11 xor %r12, %r12 xor %r13, %r13 xor %r14, %r14 xor %r15, %r15 movq (%rdi), %r8 cmp $(1), %rbx jz .Lcontinuegas_38 movq (8)(%rdi), %r9 cmp $(2), %rbx jz .Lcontinuegas_38 movq (16)(%rdi), %r10 cmp $(3), %rbx jz .Lcontinuegas_38 movq (24)(%rdi), %r11 cmp $(4), %rbx jz .Lcontinuegas_38 movq (32)(%rdi), %r12 cmp $(5), %rbx jz .Lcontinuegas_38 movq (40)(%rdi), %r13 cmp $(6), %rbx jz .Lcontinuegas_38 movq (48)(%rdi), %r14 .Lcontinuegas_38: mov (32)(%rsp), %rdx .Lirr_init_entrygas_38: sub $(8), %rdx mov (48)(%rsp), %rax jnc .Lirr_init_loopgas_38 add $(8), %rdx jz .Lquitgas_38 lea (%rdi,%rbx,8), %rbp xor %rax, %rax .L__0001gas_38: movq %rax, (%rbp) add $(8), %rbp sub $(1), %rdx jnz .L__0001gas_38 mov (32)(%rsp), %rdx call _mla_simple jmp .Lquitgas_38 .Lregular_entrygas_38: sub $(8), %rbx xor %rax, %rax mov %rbx, (%rsp) mov %rdi, (8)(%rsp) mov %rsi, (16)(%rsp) mov %rdx, (24)(%rsp) mov %rdx, (32)(%rsp) mov %rax, (40)(%rsp) mov %rdx, %rbp and $(7), %rbp lea mla_8xl_tail(%rip), %rax mov (-8)(%rax,%rbp,8), %rbp add %rbp, %rax mov %rax, (48)(%rsp) sub $(8), %rdx .Linit_loopAgas_38: mov %rdx, (32)(%rsp) call _mla_8x8 mov (32)(%rsp), %rdx add $(64), %rdi add $(64), %rsi sub $(8), %rdx jnc .Linit_loopAgas_38 add $(8), %rdx jz .Linit_completegas_38 mov %rdx, (32)(%rsp) mov (48)(%rsp), %rax xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx call *%rax xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx mov (32)(%rsp), %rdx lea (%rdi,%rdx,8), %rdi .Linit_completegas_38: movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) movq %r14, (48)(%rdi) movq %r15, (56)(%rdi) jmp .Lmla_enrtygas_38 .Lmla_loopBgas_38: mov %rbx, (%rsp) mov %rdi, (8)(%rsp) xor %rax, %rax mov %rax, (40)(%rsp) movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 sub $(8), %rdx .LloopAgas_38: mov %rdx, (32)(%rsp) call _mla_8x8 mov (32)(%rsp), %rdx add $(64), %rdi add $(64), %rsi sub $(8), %rdx jc .Lexit_loopAgas_38 mov (40)(%rsp), %rax shr $(1), %rax movq (%rdi), %rbx adc %rbx, %r8 movq (8)(%rdi), %rbx adc %rbx, %r9 movq (16)(%rdi), %rbx adc %rbx, %r10 movq (24)(%rdi), %rbx adc %rbx, %r11 movq (32)(%rdi), %rbx adc %rbx, %r12 movq (40)(%rdi), %rbx adc %rbx, %r13 movq (48)(%rdi), %rbx adc %rbx, %r14 movq (56)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax mov %rax, (40)(%rsp) jmp .LloopAgas_38 .Lexit_loopAgas_38: add $(8), %rdx jz .Lcomplete_reg_loopBgas_38 mov %rdx, (32)(%rsp) xor %rax, %rax .Lput_zerogas_38: movq %rax, (%rdi,%rdx,8) add $(1), %rdx cmp $(8), %rdx jl .Lput_zerogas_38 mov (40)(%rsp), %rax shr $(1), %rax mov (%rdi), %rbx adc %rbx, %r8 mov (8)(%rdi), %rbx adc %rbx, %r9 mov (16)(%rdi), %rbx adc %rbx, %r10 mov (24)(%rdi), %rbx adc %rbx, %r11 mov (32)(%rdi), %rbx adc %rbx, %r12 mov (40)(%rdi), %rbx adc %rbx, %r13 mov (48)(%rdi), %rbx adc %rbx, %r14 mov (56)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax mov %rax, (40)(%rsp) mov (48)(%rsp), %rax xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx call *%rax xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx mov (32)(%rsp), %rdx lea (%rdi,%rdx,8), %rdi mov (40)(%rsp), %rax shr $(1), %rax dec %rdx jz .Lmt_1gas_38 dec %rdx jz .Lmt_2gas_38 dec %rdx jz .Lmt_3gas_38 dec %rdx jz .Lmt_4gas_38 dec %rdx jz .Lmt_5gas_38 dec %rdx jz .Lmt_6gas_38 .Lmt_7gas_38: adc $(0), %r9 .Lmt_6gas_38: adc $(0), %r10 .Lmt_5gas_38: adc $(0), %r11 .Lmt_4gas_38: adc $(0), %r12 .Lmt_3gas_38: adc $(0), %r13 .Lmt_2gas_38: adc $(0), %r14 .Lmt_1gas_38: adc $(0), %r15 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) movq %r14, (48)(%rdi) movq %r15, (56)(%rdi) jmp .Lmla_enrtygas_38 .Lcomplete_reg_loopBgas_38: mov (40)(%rsp), %rax add %rax, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 adc $(0), %r14 adc $(0), %r15 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) movq %r14, (48)(%rdi) movq %r15, (56)(%rdi) .Lmla_enrtygas_38: mov (%rsp), %rbx mov (8)(%rsp), %rdi mov (24)(%rsp), %rdx mov (16)(%rsp), %rsi add $(64), %rcx add $(64), %rdi sub $(8), %rbx jnc .Lmla_loopBgas_38 add $(8), %rbx jz .Lquitgas_38 mov %rbx, (%rsp) lea mla_8xl_tail(%rip), %rax mov (-8)(%rax,%rbx,8), %rbp add %rbp, %rax mov %rax, (48)(%rsp) lea (%rdi,%rdx,8), %rbp xor %rax, %rax .L__0002gas_38: movq %rax, (%rbp) add $(8), %rbp sub $(1), %rbx jnz .L__0002gas_38 xor %rax, %rax mov %rax, (40)(%rsp) sub $(8), %rdx .Ltail_loopAgas_38: movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 mov %rdx, (32)(%rsp) mov (48)(%rsp), %rax call *%rax .Lenrty_tail_loopAgas_38: mov (40)(%rsp), %rax shr $(1), %rax adc $(0), %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 adc $(0), %r14 adc $(0), %r15 adc $(0), %rax mov (%rsp), %rbx mov %rbx, %rbp dec %rbp jz .Ltt_1gas_38 dec %rbp jz .Ltt_2gas_38 dec %rbp jz .Ltt_3gas_38 dec %rbp jz .Ltt_4gas_38 dec %rbp jz .Ltt_5gas_38 dec %rbp jz .Ltt_6gas_38 .Ltt_7gas_38: mov (8)(%rdi,%rbx,8), %rbp adc %rbp, %r9 .Ltt_6gas_38: mov (16)(%rdi,%rbx,8), %rbp adc %rbp, %r10 .Ltt_5gas_38: mov (24)(%rdi,%rbx,8), %rbp adc %rbp, %r11 .Ltt_4gas_38: mov (32)(%rdi,%rbx,8), %rbp adc %rbp, %r12 .Ltt_3gas_38: mov (40)(%rdi,%rbx,8), %rbp adc %rbp, %r13 .Ltt_2gas_38: mov (48)(%rdi,%rbx,8), %rbp adc %rbp, %r14 .Ltt_1gas_38: mov (56)(%rdi,%rbx,8), %rbp adc %rbp, %r15 adc $(0), %rax mov %rax, (40)(%rsp) movq %r8, (%rdi,%rbx,8) movq %r9, (8)(%rdi,%rbx,8) movq %r10, (16)(%rdi,%rbx,8) movq %r11, (24)(%rdi,%rbx,8) movq %r12, (32)(%rdi,%rbx,8) movq %r13, (40)(%rdi,%rbx,8) movq %r14, (48)(%rdi,%rbx,8) movq %r15, (56)(%rdi,%rbx,8) mov (32)(%rsp), %rdx add $(64), %rsi add $(64), %rdi sub $(8), %rdx jnc .Ltail_loopAgas_38 add $(8), %rdx jz .Lquitgas_38 mov (40)(%rsp), %rax mov %rbx, %rbp dec %rbp movq (%rdi,%rbx,8), %r8 add %rax, %r8 movq %r8, (%rdi,%rbx,8) jz .Lsimplegas_38 dec %rbp movq (8)(%rdi,%rbx,8), %r9 adc $(0), %r9 movq %r9, (8)(%rdi,%rbx,8) jz .Lsimplegas_38 dec %rbp movq (16)(%rdi,%rbx,8), %r10 adc $(0), %r10 movq %r10, (16)(%rdi,%rbx,8) jz .Lsimplegas_38 dec %rbp movq (24)(%rdi,%rbx,8), %r11 adc $(0), %r11 movq %r11, (24)(%rdi,%rbx,8) jz .Lsimplegas_38 dec %rbp movq (32)(%rdi,%rbx,8), %r12 adc $(0), %r12 movq %r12, (32)(%rdi,%rbx,8) jz .Lsimplegas_38 dec %rbp movq (40)(%rdi,%rbx,8), %r13 adc $(0), %r13 movq %r13, (40)(%rdi,%rbx,8) jz .Lsimplegas_38 dec %rbp movq (48)(%rdi,%rbx,8), %r14 adc $(0), %r14 movq %r14, (48)(%rdi,%rbx,8) .Lsimplegas_38: call _mla_simple .Lquitgas_38: add $(56), %rsp ret .p2align 6, 0x90 _sqr_1: movq (%rsi), %rdx mulx %rdx, %rax, %rdx movq %rax, (%rdi) movq %rdx, (8)(%rdi) ret .p2align 6, 0x90 _sqr_2: movq (%rsi), %rdx mulxq (8)(%rsi), %r8, %r9 mulx %rdx, %r10, %r11 movq (8)(%rsi), %rdx mulx %rdx, %rax, %rdx xor %rcx, %rcx add %r8, %r8 adc %r9, %r9 adc $(0), %rcx movq %r10, (%rdi) add %r8, %r11 movq %r11, (8)(%rdi) adc %r9, %rax movq %rax, (16)(%rdi) adc %rcx, %rdx movq %rdx, (24)(%rdi) ret .p2align 6, 0x90 _sqr_3: mov (%rsi), %rdx mulx (8)(%rsi), %r8, %r9 mulx (16)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 movq (8)(%rsi), %rdx mulxq (16)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 movq (%rsi), %rdx xor %rcx, %rcx add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc %rcx, %rcx mulx %rdx, %rdx, %rax mov %rdx, (%rdi) mov (8)(%rsi), %rdx add %rax, %r8 mov %r8, (8)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r9 mov %r9, (16)(%rdi) mov (16)(%rsi), %rdx adc %rax, %r10 mov %r10, (24)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r11 mov %r11, (32)(%rdi) adc %rax, %rcx mov %rcx, (40)(%rdi) ret .p2align 6, 0x90 _sqr_4: mov (%rsi), %rdx mulx (8)(%rsi), %r8, %r9 mulx (16)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 mulx (24)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 movq (8)(%rsi), %rdx mulxq (16)(%rsi), %rax, %rcx xor %r12, %r12 add %rax, %r10 adc %rcx, %r11 adc $(0), %r12 mulxq (24)(%rsi), %rax, %rcx add %rax, %r11 adc %rcx, %r12 movq (16)(%rsi), %rdx mulxq (24)(%rsi), %rax, %r13 add %rax, %r12 adc $(0), %r13 mov (%rsi), %rdx xor %rcx, %rcx add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc %r12, %r12 adc %r13, %r13 adc $(0), %rcx mulx %rdx, %rdx, %rax mov %rdx, (%rdi) mov (8)(%rsi), %rdx add %rax, %r8 mov %r8, (8)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r9 mov %r9, (16)(%rdi) mov (16)(%rsi), %rdx adc %rax, %r10 mov %r10, (24)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r11 mov %r11, (32)(%rdi) mov (24)(%rsi), %rdx adc %rax, %r12 mov %r12, (40)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r13 mov %r13, (48)(%rdi) adc %rax, %rcx mov %rcx, (56)(%rdi) ret .p2align 6, 0x90 _sqr_5: mov (%rsi), %rdx mulx (8)(%rsi), %r8, %r9 mulx (16)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 mulx (24)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 mulx (32)(%rsi), %rax, %r12 add %rax, %r11 adc $(0), %r12 mov (8)(%rsi), %rdx mulx (16)(%rsi), %rax, %rbp add %rax, %r10 adc $(0), %rbp mulx (24)(%rsi), %rax, %rcx add %rax, %r11 adc $(0), %rcx add %rbp, %r11 adc $(0), %rcx mov %rcx, %rbp mulx (32)(%rsi), %rax, %rcx add %rax, %r12 adc $(0), %rcx add %rbp, %r12 adc $(0), %rcx mov %rcx, %rbp mov %rbp, %r13 movq (16)(%rsi), %rdx mulxq (24)(%rsi), %rax, %rcx xor %r14, %r14 add %rax, %r12 adc %rcx, %r13 adc $(0), %r14 mulxq (32)(%rsi), %rax, %rcx add %rax, %r13 adc %rcx, %r14 movq (24)(%rsi), %rdx mulxq (32)(%rsi), %rax, %r15 add %rax, %r14 adc $(0), %r15 mov (%rsi), %rdx xor %rcx, %rcx add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc %r12, %r12 adc %r13, %r13 adc %r14, %r14 adc %r15, %r15 adc $(0), %rcx mulx %rdx, %rdx, %rax mov %rdx, (%rdi) mov (8)(%rsi), %rdx add %rax, %r8 mov %r8, (8)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r9 mov %r9, (16)(%rdi) mov (16)(%rsi), %rdx adc %rax, %r10 mov %r10, (24)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r11 mov %r11, (32)(%rdi) mov (24)(%rsi), %rdx adc %rax, %r12 mov %r12, (40)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r13 mov %r13, (48)(%rdi) mov (32)(%rsi), %rdx adc %rax, %r14 mov %r14, (56)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r15 mov %r15, (64)(%rdi) mov (40)(%rsi), %rdx adc %rax, %rcx mov %rcx, (72)(%rdi) ret .p2align 6, 0x90 _sqr_6: mov (%rsi), %rdx mulx (8)(%rsi), %r8, %r9 mulx (16)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 mulx (24)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 mulx (32)(%rsi), %rax, %r12 add %rax, %r11 adc $(0), %r12 mulx (40)(%rsi), %rax, %r13 add %rax, %r12 adc $(0), %r13 mov (8)(%rsi), %rdx mulx (16)(%rsi), %rax, %rbp add %rax, %r10 adc $(0), %rbp mulx (24)(%rsi), %rax, %rcx add %rax, %r11 adc $(0), %rcx add %rbp, %r11 adc $(0), %rcx mov %rcx, %rbp mulx (32)(%rsi), %rax, %rcx add %rax, %r12 adc $(0), %rcx add %rbp, %r12 adc $(0), %rcx mov %rcx, %rbp mulx (40)(%rsi), %rax, %rcx add %rax, %r13 adc $(0), %rcx add %rbp, %r13 adc $(0), %rcx mov %rcx, %rbp mov %rbp, %r14 mov (16)(%rsi), %rdx mulx (24)(%rsi), %rax, %rbp add %rax, %r12 adc $(0), %rbp mulx (32)(%rsi), %rax, %rcx add %rax, %r13 adc $(0), %rcx add %rbp, %r13 adc $(0), %rcx mov %rcx, %rbp mulx (40)(%rsi), %rax, %rcx add %rax, %r14 adc $(0), %rcx add %rbp, %r14 adc $(0), %rcx mov %rcx, %rbp mov %rbp, %r15 movq (24)(%rsi), %rdx mulxq (32)(%rsi), %rax, %rcx xor %rbx, %rbx add %rax, %r14 adc %rcx, %r15 adc $(0), %rbx mulxq (40)(%rsi), %rax, %rcx add %rax, %r15 adc %rcx, %rbx movq (32)(%rsi), %rdx mulxq (40)(%rsi), %rax, %rbp add %rax, %rbx adc $(0), %rbp mov (%rsi), %rdx xor %rcx, %rcx add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc %r12, %r12 adc %r13, %r13 adc %r14, %r14 adc %r15, %r15 adc %rbx, %rbx adc %rbp, %rbp adc $(0), %rcx mulx %rdx, %rdx, %rax mov %rdx, (%rdi) mov (8)(%rsi), %rdx add %rax, %r8 mov %r8, (8)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r9 mov %r9, (16)(%rdi) mov (16)(%rsi), %rdx adc %rax, %r10 mov %r10, (24)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r11 mov %r11, (32)(%rdi) mov (24)(%rsi), %rdx adc %rax, %r12 mov %r12, (40)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r13 mov %r13, (48)(%rdi) mov (32)(%rsi), %rdx adc %rax, %r14 mov %r14, (56)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r15 mov %r15, (64)(%rdi) mov (40)(%rsi), %rdx adc %rax, %rbx mov %rbx, (72)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %rbp mov %rbp, (80)(%rdi) adc %rax, %rcx mov %rcx, (88)(%rdi) ret .p2align 6, 0x90 _sqr_7: mov (%rsi), %rdx mulx (8)(%rsi), %r8, %r9 mulx (16)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 mulx (24)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 mulx (32)(%rsi), %rax, %r12 add %rax, %r11 adc $(0), %r12 mulx (40)(%rsi), %rax, %r13 add %rax, %r12 adc $(0), %r13 mulx (48)(%rsi), %rax, %r14 add %rax, %r13 adc $(0), %r14 mov (8)(%rsi), %rdx mulx (16)(%rsi), %rax, %rbp add %rax, %r10 adc $(0), %rbp mulx (24)(%rsi), %rax, %rcx add %rax, %r11 adc $(0), %rcx add %rbp, %r11 adc $(0), %rcx mov %rcx, %rbp mulx (32)(%rsi), %rax, %rcx add %rax, %r12 adc $(0), %rcx add %rbp, %r12 adc $(0), %rcx mov %rcx, %rbp mulx (40)(%rsi), %rax, %rcx add %rax, %r13 adc $(0), %rcx add %rbp, %r13 adc $(0), %rcx mov %rcx, %rbp mulx (48)(%rsi), %rax, %rcx add %rax, %r14 adc $(0), %rcx add %rbp, %r14 adc $(0), %rcx mov %rcx, %rbp mov %rbp, %r15 mov (16)(%rsi), %rdx mulx (24)(%rsi), %rax, %rbp add %rax, %r12 adc $(0), %rbp xor %rbx, %rbx mulx (32)(%rsi), %rax, %rcx add %rax, %r13 adc $(0), %rcx add %rbp, %r13 adc $(0), %rcx mov %rcx, %rbp mulx (40)(%rsi), %rax, %rcx add %rax, %r14 adc $(0), %rcx add %rbp, %r14 adc $(0), %rcx mov %rcx, %rbp add %rbp, %r15 adc $(0), %rbx mov (24)(%rsi), %rax mulq (32)(%rsi) add %rax, %r14 adc $(0), %rdx add %rdx, %r15 adc $(0), %rbx mov (%rsi), %rdx xor %rcx, %rcx add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc %r12, %r12 adc %r13, %r13 adc %r14, %r14 adc $(0), %rcx mulx %rdx, %rdx, %rax mov %rdx, (%rdi) mov (8)(%rsi), %rdx add %rax, %r8 mov %r8, (8)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r9 mov %r9, (16)(%rdi) mov (16)(%rsi), %rdx adc %rax, %r10 mov %r10, (24)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r11 mov %r11, (32)(%rdi) mov (24)(%rsi), %rdx adc %rax, %r12 mov %r12, (40)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r13 mov %r13, (48)(%rdi) adc %rax, %r14 mov %r14, (56)(%rdi) adc $(0), %rcx mov (16)(%rsi), %rax xor %r8, %r8 mulq (48)(%rsi) add %rax, %r15 adc $(0), %rdx add %rdx, %rbx adc $(0), %r8 mov (24)(%rsi), %rdx mulx (40)(%rsi), %rax, %r14 add %rax, %r15 adc %r14, %rbx adc $(0), %r8 mulx (48)(%rsi), %rax, %r14 add %rax, %rbx adc %r14, %r8 mov (32)(%rsi), %rdx mulx (40)(%rsi), %rax, %r14 xor %r9, %r9 add %rax, %rbx adc %r14, %r8 adc $(0), %r9 mulx (48)(%rsi), %rax, %r14 add %rax, %r8 adc %r14, %r9 mov (40)(%rsi), %rax xor %r10, %r10 mulq (48)(%rsi) add %rax, %r9 adc %rdx, %r10 mov (32)(%rsi), %rdx xor %r11, %r11 add %r15, %r15 adc %rbx, %rbx adc %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc $(0), %r11 mulx %rdx, %rdx, %rax add %rcx, %rdx adc $(0), %rax add %rdx, %r15 mov (40)(%rsi), %rdx mov %r15, (64)(%rdi) adc %rax, %rbx mov %rbx, (72)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r8 mov %r8, (80)(%rdi) mov (48)(%rsi), %rdx adc %rax, %r9 mov %r9, (88)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r10 mov %r10, (96)(%rdi) adc %rax, %r11 mov %r11, (104)(%rdi) ret .p2align 6, 0x90 _sqr_8: mov (%rsi), %rdx mulx (8)(%rsi), %r8, %r9 mulx (16)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 mulx (24)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 mulx (32)(%rsi), %rax, %r12 add %rax, %r11 adc $(0), %r12 mulx (40)(%rsi), %rax, %r13 add %rax, %r12 adc $(0), %r13 mulx (48)(%rsi), %rax, %r14 add %rax, %r13 adc $(0), %r14 mulx (56)(%rsi), %rax, %r15 add %rax, %r14 adc $(0), %r15 mov (8)(%rsi), %rdx mulx (16)(%rsi), %rax, %rbp add %rax, %r10 adc $(0), %rbp xor %rbx, %rbx mulx (24)(%rsi), %rax, %rcx add %rax, %r11 adc $(0), %rcx add %rbp, %r11 adc $(0), %rcx mov %rcx, %rbp mulx (32)(%rsi), %rax, %rcx add %rax, %r12 adc $(0), %rcx add %rbp, %r12 adc $(0), %rcx mov %rcx, %rbp mulx (40)(%rsi), %rax, %rcx add %rax, %r13 adc $(0), %rcx add %rbp, %r13 adc $(0), %rcx mov %rcx, %rbp mulx (48)(%rsi), %rax, %rcx add %rax, %r14 adc $(0), %rcx add %rbp, %r14 adc $(0), %rcx mov %rcx, %rbp add %rbp, %r15 adc $(0), %rbx mov (16)(%rsi), %rdx mulx (24)(%rsi), %rax, %rbp add %rax, %r12 adc $(0), %rbp mulx (32)(%rsi), %rax, %rcx add %rax, %r13 adc $(0), %rcx add %rbp, %r13 adc $(0), %rcx mov %rcx, %rbp mulx (40)(%rsi), %rax, %rcx add %rax, %r14 adc $(0), %rcx add %rbp, %r14 adc $(0), %rcx mov %rcx, %rbp add %rbp, %r15 adc $(0), %rbx mov (24)(%rsi), %rax mulq (32)(%rsi) add %rax, %r14 adc $(0), %rdx add %rdx, %r15 adc $(0), %rbx mov (%rsi), %rdx xor %rcx, %rcx add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc %r12, %r12 adc %r13, %r13 adc %r14, %r14 adc $(0), %rcx mulx %rdx, %rdx, %rax mov %rdx, (%rdi) mov (8)(%rsi), %rdx add %rax, %r8 mov %r8, (8)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r9 mov %r9, (16)(%rdi) mov (16)(%rsi), %rdx adc %rax, %r10 mov %r10, (24)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r11 mov %r11, (32)(%rdi) mov (24)(%rsi), %rdx adc %rax, %r12 mov %r12, (40)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r13 mov %r13, (48)(%rdi) adc %rax, %r14 mov %r14, (56)(%rdi) adc $(0), %rcx mov (8)(%rsi), %rax xor %r8, %r8 mulq (56)(%rsi) add %rax, %r15 adc $(0), %rdx add %rdx, %rbx adc $(0), %r8 mov (16)(%rsi), %rdx mulx (48)(%rsi), %rax, %r14 add %rax, %r15 adc %r14, %rbx adc $(0), %r8 mulx (56)(%rsi), %rax, %r14 xor %r9, %r9 add %rax, %rbx adc %r14, %r8 adc $(0), %r9 mov (24)(%rsi), %rdx mulx (40)(%rsi), %rax, %r14 add %rax, %r15 adc $(0), %r14 add %r14, %rbx adc $(0), %r8 adc $(0), %r9 mulx (48)(%rsi), %rax, %r14 add %rax, %rbx adc $(0), %r14 add %r14, %r8 adc $(0), %r9 mulx (56)(%rsi), %rax, %r14 add %rax, %r8 adc $(0), %r14 add %r14, %r9 mov (32)(%rsi), %rdx mulx (40)(%rsi), %rax, %r10 add %rax, %rbx adc $(0), %r10 mulx (48)(%rsi), %rax, %r14 add %rax, %r8 adc $(0), %r14 add %r10, %r8 adc $(0), %r14 mov %r14, %r10 mulx (56)(%rsi), %rax, %r14 add %rax, %r9 adc $(0), %r14 add %r10, %r9 adc $(0), %r14 mov %r14, %r10 mov (40)(%rsi), %rdx mulx (48)(%rsi), %rax, %r11 add %rax, %r9 adc $(0), %r11 mulx (56)(%rsi), %rax, %r14 add %rax, %r10 adc $(0), %r14 add %r11, %r10 adc $(0), %r14 mov %r14, %r11 mov (48)(%rsi), %rax mulq (56)(%rsi) add %rax, %r11 adc $(0), %rdx mov %rdx, %r12 mov (32)(%rsi), %rdx xor %r13, %r13 add %r15, %r15 adc %rbx, %rbx adc %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc %r12, %r12 adc $(0), %r13 mulx %rdx, %rdx, %rax add %rcx, %rdx adc $(0), %rax add %rdx, %r15 mov (40)(%rsi), %rdx mov %r15, (64)(%rdi) adc %rax, %rbx mov %rbx, (72)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r8 mov %r8, (80)(%rdi) mov (48)(%rsi), %rdx adc %rax, %r9 mov %r9, (88)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r10 mov %r10, (96)(%rdi) mov (56)(%rsi), %rdx adc %rax, %r11 mov %r11, (104)(%rdi) mulx %rdx, %rdx, %rax adc %rdx, %r12 mov %r12, (112)(%rdi) adc %rax, %r13 mov %r13, (120)(%rdi) ret .p2align 6, 0x90 _add_diag_4: movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 xor %rbp, %rbp add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc %r12, %r12 adc %r13, %r13 adc %r14, %r14 adc %r15, %r15 adc $(0), %rbp mov (%rsi), %rdx mulx %rdx, %rax, %rdx add %rbx, %rax adc $(0), %rdx add %rax, %r8 mov %rbp, %rbx adc %rdx, %r9 mov (8)(%rsi), %rdx mulx %rdx, %rax, %rdx adc %rax, %r10 adc %rdx, %r11 mov (16)(%rsi), %rdx mulx %rdx, %rax, %rdx adc %rax, %r12 adc %rdx, %r13 mov (24)(%rsi), %rdx mulx %rdx, %rax, %rdx adc %rax, %r14 adc %rdx, %r15 adc $(0), %rbx movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) movq %r14, (48)(%rdi) movq %r15, (56)(%rdi) ret .p2align 6, 0x90 _sqr8_triangle: mov (%rsi), %rdx mov %r8, (%rdi) mulx (8)(%rsi), %rax, %rbp add %rax, %r9 adc $(0), %rbp mulx (16)(%rsi), %rax, %rbx add %rax, %r10 adc $(0), %rbx add %rbp, %r10 adc $(0), %rbx mulx (24)(%rsi), %rax, %rbp add %rax, %r11 adc $(0), %rbp add %rbx, %r11 adc $(0), %rbp mulx (32)(%rsi), %rax, %rbx add %rax, %r12 adc $(0), %rbx add %rbp, %r12 adc $(0), %rbx mulx (40)(%rsi), %rax, %rbp add %rax, %r13 adc $(0), %rbp add %rbx, %r13 adc $(0), %rbp mulx (48)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx add %rbp, %r14 adc $(0), %rbx mulx (56)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 mov (8)(%rsi), %rdx mov %r9, (8)(%rdi) mulx (16)(%rsi), %rax, %rbx add %rax, %r11 adc $(0), %rbx mulx (24)(%rsi), %rax, %rbp add %rax, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mulx (32)(%rsi), %rax, %rbx add %rax, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mulx (40)(%rsi), %rax, %rbp add %rax, %r14 adc $(0), %rbp add %rbx, %r14 adc $(0), %rbp mulx (48)(%rsi), %rax, %rbx add %rax, %r15 adc $(0), %rbx add %rbp, %r15 adc $(0), %rbx mulx (56)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 add %rbx, %r8 adc $(0), %r9 mov (16)(%rsi), %rdx mov %r10, (16)(%rdi) mulx (24)(%rsi), %rax, %rbp add %rax, %r13 adc $(0), %rbp mulx (32)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx add %rbp, %r14 adc $(0), %rbx mulx (40)(%rsi), %rax, %rbp add %rax, %r15 adc $(0), %rbp add %rbx, %r15 adc $(0), %rbp mulx (48)(%rsi), %rax, %rbx add %rax, %r8 adc $(0), %rbx add %rbp, %r8 adc $(0), %rbx mulx (56)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 add %rbx, %r9 adc $(0), %r10 mov (24)(%rsi), %rdx mov %r11, (24)(%rdi) mulx (32)(%rsi), %rax, %rbx add %rax, %r15 adc $(0), %rbx mulx (40)(%rsi), %rax, %rbp add %rax, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (48)(%rsi), %rax, %rbx add %rax, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (56)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 add %rbx, %r10 adc $(0), %r11 mov (32)(%rsi), %rdx mov %r12, (32)(%rdi) mulx (40)(%rsi), %rax, %rbp add %rax, %r9 adc $(0), %rbp mulx (48)(%rsi), %rax, %rbx add %rax, %r10 adc $(0), %rbx add %rbp, %r10 adc $(0), %rbx mulx (56)(%rsi), %rax, %r12 add %rax, %r11 adc $(0), %r12 add %rbx, %r11 adc $(0), %r12 mov (40)(%rsi), %rdx mov %r13, (40)(%rdi) mulx (48)(%rsi), %rax, %rbx add %rax, %r11 adc $(0), %rbx mulx (56)(%rsi), %rax, %r13 add %rax, %r12 adc $(0), %r13 add %rbx, %r12 adc $(0), %r13 mov (48)(%rsi), %rdx mov %r14, (48)(%rdi) mulx (56)(%rsi), %rax, %r14 add %rax, %r13 adc $(0), %r14 ret .p2align 6, 0x90 _sqr_9: call _sqr8_triangle movq %r15, (56)(%rdi) lea (64)(%rsi), %rcx add $(64), %rdi xor %r15, %r15 call _mla_8x1 movq %r8, (8)(%rdi) movq %r9, (16)(%rdi) movq %r10, (24)(%rdi) movq %r11, (32)(%rdi) movq %r12, (40)(%rdi) movq %r13, (48)(%rdi) movq %r14, (56)(%rdi) movq %r15, (64)(%rdi) xor %rbx, %rbx movq %rbx, (72)(%rdi) sub $(64), %rdi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 xor %rbp, %rbp add %r8, %r8 adc %r9, %r9 adc $(0), %rbp mov (%rsi), %rdx mulx %rdx, %rax, %rdx add %rbx, %rax adc $(0), %rdx add %rax, %r8 mov %rbp, %rbx adc %rdx, %r9 adc $(0), %rbx movq %r8, (%rdi) movq %r9, (8)(%rdi) sub $(64), %rsi sub $(128), %rdi ret .p2align 6, 0x90 _sqr_10: call _sqr8_triangle movq %r15, (56)(%rdi) lea (64)(%rsi), %rcx add $(64), %rdi xor %r15, %r15 call _mla_8x2 movq %r8, (16)(%rdi) movq %r9, (24)(%rdi) movq %r10, (32)(%rdi) movq %r11, (40)(%rdi) movq %r12, (48)(%rdi) movq %r13, (56)(%rdi) movq %r14, (64)(%rdi) movq (64)(%rsi), %rdx mulx (72)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 xor %rbx, %rbx movq %r15, (72)(%rdi) movq %r8, (80)(%rdi) movq %rbx, (88)(%rdi) sub $(64), %rdi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 xor %rbp, %rbp add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc $(0), %rbp mov (%rsi), %rdx mulx %rdx, %rax, %rdx add %rbx, %rax adc $(0), %rdx add %rax, %r8 mov %rbp, %rbx adc %rdx, %r9 mov (8)(%rsi), %rdx mulx %rdx, %rax, %rdx adc %rax, %r10 adc %rdx, %r11 adc $(0), %rbx movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) sub $(64), %rsi sub $(128), %rdi ret .p2align 6, 0x90 _sqr_11: call _sqr8_triangle movq %r15, (56)(%rdi) lea (64)(%rsi), %rcx add $(64), %rdi xor %r15, %r15 call _mla_8x1 add $(8), %rdi add $(8), %rcx call _mla_8x2 sub $(8), %rdi sub $(8), %rcx movq %r8, (24)(%rdi) movq %r9, (32)(%rdi) movq %r10, (40)(%rdi) movq %r11, (48)(%rdi) movq %r12, (56)(%rdi) movq (64)(%rsi), %rdx mov %r13, (64)(%rdi) mulx (72)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx mulx (80)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 movq (72)(%rsi), %rdx mov %r14, (72)(%rdi) mulx (80)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 xor %rbx, %rbx movq %r15, (80)(%rdi) movq %r8, (88)(%rdi) movq %r9, (96)(%rdi) movq %rbx, (104)(%rdi) sub $(64), %rdi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 xor %rbp, %rbp add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc %r12, %r12 adc %r13, %r13 adc $(0), %rbp mov (%rsi), %rdx mulx %rdx, %rax, %rdx add %rbx, %rax adc $(0), %rdx add %rax, %r8 mov %rbp, %rbx adc %rdx, %r9 mov (8)(%rsi), %rdx mulx %rdx, %rax, %rdx adc %rax, %r10 adc %rdx, %r11 mov (16)(%rsi), %rdx mulx %rdx, %rax, %rdx adc %rax, %r12 adc %rdx, %r13 adc $(0), %rbx movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) sub $(64), %rsi sub $(128), %rdi ret .p2align 6, 0x90 _sqr_12: call _sqr8_triangle movq %r15, (56)(%rdi) lea (64)(%rsi), %rcx add $(64), %rdi xor %r15, %r15 call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 sub $(16), %rdi sub $(16), %rcx movq %r8, (32)(%rdi) movq %r9, (40)(%rdi) movq %r10, (48)(%rdi) movq %r11, (56)(%rdi) movq (64)(%rsi), %rdx mov %r12, (64)(%rdi) mulx (72)(%rsi), %rax, %rbp add %rax, %r13 adc $(0), %rbp mulx (80)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx add %rbp, %r14 adc $(0), %rbx mulx (88)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 movq (72)(%rsi), %rdx mov %r13, (72)(%rdi) mulx (80)(%rsi), %rax, %rbx add %rax, %r15 adc $(0), %rbx mulx (88)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 add %rbx, %r8 adc $(0), %r9 movq (80)(%rsi), %rdx mov %r14, (80)(%rdi) mulx (88)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 xor %rbx, %rbx movq %r15, (88)(%rdi) movq %r8, (96)(%rdi) movq %r9, (104)(%rdi) movq %r10, (112)(%rdi) movq %rbx, (120)(%rdi) sub $(64), %rdi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 sub $(64), %rsi sub $(128), %rdi ret .p2align 6, 0x90 _sqr_13: call _sqr8_triangle movq %r15, (56)(%rdi) lea (64)(%rsi), %rcx add $(64), %rdi xor %r15, %r15 call _mla_8x1 add $(8), %rdi add $(8), %rcx call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 sub $(24), %rdi sub $(24), %rcx movq %r8, (40)(%rdi) movq %r9, (48)(%rdi) movq %r10, (56)(%rdi) movq (64)(%rsi), %rdx mov %r11, (64)(%rdi) mulx (72)(%rsi), %rax, %rbx add %rax, %r12 adc $(0), %rbx mulx (80)(%rsi), %rax, %rbp add %rax, %r13 adc $(0), %rbp add %rbx, %r13 adc $(0), %rbp mulx (88)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx add %rbp, %r14 adc $(0), %rbx mulx (96)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 movq (72)(%rsi), %rdx mov %r12, (72)(%rdi) mulx (80)(%rsi), %rax, %rbp add %rax, %r14 adc $(0), %rbp mulx (88)(%rsi), %rax, %rbx add %rax, %r15 adc $(0), %rbx add %rbp, %r15 adc $(0), %rbx mulx (96)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 add %rbx, %r8 adc $(0), %r9 movq (80)(%rsi), %rdx mov %r13, (80)(%rdi) mulx (88)(%rsi), %rax, %rbx add %rax, %r8 adc $(0), %rbx mulx (96)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 add %rbx, %r9 adc $(0), %r10 movq (88)(%rsi), %rdx mov %r14, (88)(%rdi) mulx (96)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 xor %rbx, %rbx movq %r15, (96)(%rdi) movq %r8, (104)(%rdi) movq %r9, (112)(%rdi) movq %r10, (120)(%rdi) movq %r11, (128)(%rdi) movq %rbx, (136)(%rdi) sub $(64), %rdi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 xor %rbp, %rbp add %r8, %r8 adc %r9, %r9 adc $(0), %rbp mov (%rsi), %rdx mulx %rdx, %rax, %rdx add %rbx, %rax adc $(0), %rdx add %rax, %r8 mov %rbp, %rbx adc %rdx, %r9 adc $(0), %rbx movq %r8, (%rdi) movq %r9, (8)(%rdi) sub $(96), %rsi sub $(192), %rdi ret .p2align 6, 0x90 _sqr_14: call _sqr8_triangle movq %r15, (56)(%rdi) lea (64)(%rsi), %rcx add $(64), %rdi xor %r15, %r15 call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 sub $(32), %rdi sub $(32), %rcx movq %r8, (48)(%rdi) movq %r9, (56)(%rdi) movq (64)(%rsi), %rdx mov %r10, (64)(%rdi) mulx (72)(%rsi), %rax, %rbp add %rax, %r11 adc $(0), %rbp mulx (80)(%rsi), %rax, %rbx add %rax, %r12 adc $(0), %rbx add %rbp, %r12 adc $(0), %rbx mulx (88)(%rsi), %rax, %rbp add %rax, %r13 adc $(0), %rbp add %rbx, %r13 adc $(0), %rbp mulx (96)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx add %rbp, %r14 adc $(0), %rbx mulx (104)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 movq (72)(%rsi), %rdx mov %r11, (72)(%rdi) mulx (80)(%rsi), %rax, %rbx add %rax, %r13 adc $(0), %rbx mulx (88)(%rsi), %rax, %rbp add %rax, %r14 adc $(0), %rbp add %rbx, %r14 adc $(0), %rbp mulx (96)(%rsi), %rax, %rbx add %rax, %r15 adc $(0), %rbx add %rbp, %r15 adc $(0), %rbx mulx (104)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 add %rbx, %r8 adc $(0), %r9 movq (80)(%rsi), %rdx mov %r12, (80)(%rdi) mulx (88)(%rsi), %rax, %rbp add %rax, %r15 adc $(0), %rbp mulx (96)(%rsi), %rax, %rbx add %rax, %r8 adc $(0), %rbx add %rbp, %r8 adc $(0), %rbx mulx (104)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 add %rbx, %r9 adc $(0), %r10 movq (88)(%rsi), %rdx mov %r13, (88)(%rdi) mulx (96)(%rsi), %rax, %rbx add %rax, %r9 adc $(0), %rbx mulx (104)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 add %rbx, %r10 adc $(0), %r11 movq (96)(%rsi), %rdx mov %r14, (96)(%rdi) mulx (104)(%rsi), %rax, %r12 add %rax, %r11 adc $(0), %r12 xor %rbx, %rbx movq %r15, (104)(%rdi) movq %r8, (112)(%rdi) movq %r9, (120)(%rdi) movq %r10, (128)(%rdi) movq %r11, (136)(%rdi) movq %r12, (144)(%rdi) movq %rbx, (152)(%rdi) sub $(64), %rdi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 xor %rbp, %rbp add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc $(0), %rbp mov (%rsi), %rdx mulx %rdx, %rax, %rdx add %rbx, %rax adc $(0), %rdx add %rax, %r8 mov %rbp, %rbx adc %rdx, %r9 mov (8)(%rsi), %rdx mulx %rdx, %rax, %rdx adc %rax, %r10 adc %rdx, %r11 adc $(0), %rbx movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) sub $(96), %rsi sub $(192), %rdi ret .p2align 6, 0x90 _sqr_15: call _sqr8_triangle movq %r15, (56)(%rdi) lea (64)(%rsi), %rcx add $(64), %rdi xor %r15, %r15 call _mla_8x1 add $(8), %rdi add $(8), %rcx call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 sub $(40), %rdi sub $(40), %rcx movq %r8, (56)(%rdi) movq (64)(%rsi), %rdx mov %r9, (64)(%rdi) mulx (72)(%rsi), %rax, %rbx add %rax, %r10 adc $(0), %rbx mulx (80)(%rsi), %rax, %rbp add %rax, %r11 adc $(0), %rbp add %rbx, %r11 adc $(0), %rbp mulx (88)(%rsi), %rax, %rbx add %rax, %r12 adc $(0), %rbx add %rbp, %r12 adc $(0), %rbx mulx (96)(%rsi), %rax, %rbp add %rax, %r13 adc $(0), %rbp add %rbx, %r13 adc $(0), %rbp mulx (104)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx add %rbp, %r14 adc $(0), %rbx mulx (112)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 movq (72)(%rsi), %rdx mov %r10, (72)(%rdi) mulx (80)(%rsi), %rax, %rbp add %rax, %r12 adc $(0), %rbp mulx (88)(%rsi), %rax, %rbx add %rax, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mulx (96)(%rsi), %rax, %rbp add %rax, %r14 adc $(0), %rbp add %rbx, %r14 adc $(0), %rbp mulx (104)(%rsi), %rax, %rbx add %rax, %r15 adc $(0), %rbx add %rbp, %r15 adc $(0), %rbx mulx (112)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 add %rbx, %r8 adc $(0), %r9 movq (80)(%rsi), %rdx mov %r11, (80)(%rdi) mulx (88)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx mulx (96)(%rsi), %rax, %rbp add %rax, %r15 adc $(0), %rbp add %rbx, %r15 adc $(0), %rbp mulx (104)(%rsi), %rax, %rbx add %rax, %r8 adc $(0), %rbx add %rbp, %r8 adc $(0), %rbx mulx (112)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 add %rbx, %r9 adc $(0), %r10 movq (88)(%rsi), %rdx mov %r12, (88)(%rdi) mulx (96)(%rsi), %rax, %rbp add %rax, %r8 adc $(0), %rbp mulx (104)(%rsi), %rax, %rbx add %rax, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (112)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 add %rbx, %r10 adc $(0), %r11 movq (96)(%rsi), %rdx mov %r13, (96)(%rdi) mulx (104)(%rsi), %rax, %rbx add %rax, %r10 adc $(0), %rbx mulx (112)(%rsi), %rax, %r12 add %rax, %r11 adc $(0), %r12 add %rbx, %r11 adc $(0), %r12 movq (104)(%rsi), %rdx mov %r14, (104)(%rdi) mulx (112)(%rsi), %rax, %r13 add %rax, %r12 adc $(0), %r13 xor %rbx, %rbx movq %r15, (112)(%rdi) movq %r8, (120)(%rdi) movq %r9, (128)(%rdi) movq %r10, (136)(%rdi) movq %r11, (144)(%rdi) movq %r12, (152)(%rdi) movq %r13, (160)(%rdi) movq %rbx, (168)(%rdi) sub $(64), %rdi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 xor %rbp, %rbp add %r8, %r8 adc %r9, %r9 adc %r10, %r10 adc %r11, %r11 adc %r12, %r12 adc %r13, %r13 adc $(0), %rbp mov (%rsi), %rdx mulx %rdx, %rax, %rdx add %rbx, %rax adc $(0), %rdx add %rax, %r8 mov %rbp, %rbx adc %rdx, %r9 mov (8)(%rsi), %rdx mulx %rdx, %rax, %rdx adc %rax, %r10 adc %rdx, %r11 mov (16)(%rsi), %rdx mulx %rdx, %rax, %rdx adc %rax, %r12 adc %rdx, %r13 adc $(0), %rbx movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) sub $(96), %rsi sub $(192), %rdi ret .p2align 6, 0x90 _sqr_16: call _sqr8_triangle movq %r15, (56)(%rdi) mov %rsi, %rcx add $(64), %rsi add $(64), %rdi xor %r15, %r15 call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 add $(16), %rdi add $(16), %rcx call _mla_8x2 sub $(48), %rdi sub $(48), %rcx add $(64), %rdi call _sqr8_triangle xor %rbx, %rbx movq %r15, (56)(%rdi) movq %r8, (64)(%rdi) movq %r9, (72)(%rdi) movq %r10, (80)(%rdi) movq %r11, (88)(%rdi) movq %r12, (96)(%rdi) movq %r13, (104)(%rdi) movq %r14, (112)(%rdi) movq %rbx, (120)(%rdi) sub $(64), %rsi sub $(128), %rdi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 add $(64), %rdi add $(32), %rsi call _add_diag_4 sub $(96), %rsi sub $(192), %rdi ret .p2align 6, 0x90 _sqr9_triangle: call _sqr8_triangle movq %r15, (56)(%rdi) xor %r15, %r15 lea (64)(%rsi), %rcx add $(64), %rdi call _mla_8x1 xor %rax, %rax movq %r8, (8)(%rdi) movq %r9, (16)(%rdi) movq %r10, (24)(%rdi) movq %r11, (32)(%rdi) movq %r12, (40)(%rdi) movq %r13, (48)(%rdi) movq %r14, (56)(%rdi) movq %r15, (64)(%rdi) movq %rax, (72)(%rdi) sub $(64), %rdi ret .p2align 6, 0x90 _sqr10_triangle: call _sqr8_triangle movq %r15, (56)(%rdi) xor %r15, %r15 lea (64)(%rsi), %rcx add $(64), %rdi call _mla_8x2 movq %r8, (16)(%rdi) movq %r9, (24)(%rdi) movq %r10, (32)(%rdi) movq %r11, (40)(%rdi) movq %r12, (48)(%rdi) movq %r13, (56)(%rdi) movq %r14, (64)(%rdi) movq (64)(%rsi), %rdx mulx (72)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 xor %rax, %rax movq %r15, (72)(%rdi) movq %r8, (80)(%rdi) movq %rax, (88)(%rdi) sub $(64), %rdi ret .p2align 6, 0x90 _sqr11_triangle: call _sqr8_triangle movq %r15, (56)(%rdi) xor %r15, %r15 lea (64)(%rsi), %rcx add $(64), %rdi call _mla_8x3 movq %r8, (24)(%rdi) movq %r9, (32)(%rdi) movq %r10, (40)(%rdi) movq %r11, (48)(%rdi) movq %r12, (56)(%rdi) movq (64)(%rsi), %rdx mov %r13, (64)(%rdi) mulx (72)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx mulx (80)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 movq (72)(%rsi), %rdx mov %r14, (72)(%rdi) mulx (80)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 xor %rax, %rax movq %r15, (80)(%rdi) movq %r8, (88)(%rdi) movq %r9, (96)(%rdi) movq %rax, (104)(%rdi) sub $(64), %rdi ret .p2align 6, 0x90 _sqr12_triangle: call _sqr8_triangle movq %r15, (56)(%rdi) xor %r15, %r15 lea (64)(%rsi), %rcx add $(64), %rdi call _mla_8x4 movq %r8, (32)(%rdi) movq %r9, (40)(%rdi) movq %r10, (48)(%rdi) movq %r11, (56)(%rdi) movq (64)(%rsi), %rdx mov %r12, (64)(%rdi) mulx (72)(%rsi), %rax, %rbp add %rax, %r13 adc $(0), %rbp mulx (80)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx add %rbp, %r14 adc $(0), %rbx mulx (88)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 movq (72)(%rsi), %rdx mov %r13, (72)(%rdi) mulx (80)(%rsi), %rax, %rbx add %rax, %r15 adc $(0), %rbx mulx (88)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 add %rbx, %r8 adc $(0), %r9 movq (80)(%rsi), %rdx mov %r14, (80)(%rdi) mulx (88)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 xor %rax, %rax movq %r15, (88)(%rdi) movq %r8, (96)(%rdi) movq %r9, (104)(%rdi) movq %r10, (112)(%rdi) movq %rax, (120)(%rdi) sub $(64), %rdi ret .p2align 6, 0x90 _sqr13_triangle: call _sqr8_triangle movq %r15, (56)(%rdi) xor %r15, %r15 lea (64)(%rsi), %rcx add $(64), %rdi call _mla_8x5 movq %r8, (40)(%rdi) movq %r9, (48)(%rdi) movq %r10, (56)(%rdi) movq (64)(%rsi), %rdx mov %r11, (64)(%rdi) mulx (72)(%rsi), %rax, %rbx add %rax, %r12 adc $(0), %rbx mulx (80)(%rsi), %rax, %rbp add %rax, %r13 adc $(0), %rbp add %rbx, %r13 adc $(0), %rbp mulx (88)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx add %rbp, %r14 adc $(0), %rbx mulx (96)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 movq (72)(%rsi), %rdx mov %r12, (72)(%rdi) mulx (80)(%rsi), %rax, %rbp add %rax, %r14 adc $(0), %rbp mulx (88)(%rsi), %rax, %rbx add %rax, %r15 adc $(0), %rbx add %rbp, %r15 adc $(0), %rbx mulx (96)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 add %rbx, %r8 adc $(0), %r9 movq (80)(%rsi), %rdx mov %r13, (80)(%rdi) mulx (88)(%rsi), %rax, %rbx add %rax, %r8 adc $(0), %rbx mulx (96)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 add %rbx, %r9 adc $(0), %r10 movq (88)(%rsi), %rdx mov %r14, (88)(%rdi) mulx (96)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 xor %rax, %rax movq %r15, (96)(%rdi) movq %r8, (104)(%rdi) movq %r9, (112)(%rdi) movq %r10, (120)(%rdi) movq %r11, (128)(%rdi) movq %rax, (136)(%rdi) sub $(64), %rdi ret .p2align 6, 0x90 _sqr14_triangle: call _sqr8_triangle movq %r15, (56)(%rdi) xor %r15, %r15 lea (64)(%rsi), %rcx add $(64), %rdi call _mla_8x6 movq %r8, (48)(%rdi) movq %r9, (56)(%rdi) movq (64)(%rsi), %rdx mov %r10, (64)(%rdi) mulx (72)(%rsi), %rax, %rbp add %rax, %r11 adc $(0), %rbp mulx (80)(%rsi), %rax, %rbx add %rax, %r12 adc $(0), %rbx add %rbp, %r12 adc $(0), %rbx mulx (88)(%rsi), %rax, %rbp add %rax, %r13 adc $(0), %rbp add %rbx, %r13 adc $(0), %rbp mulx (96)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx add %rbp, %r14 adc $(0), %rbx mulx (104)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 movq (72)(%rsi), %rdx mov %r11, (72)(%rdi) mulx (80)(%rsi), %rax, %rbx add %rax, %r13 adc $(0), %rbx mulx (88)(%rsi), %rax, %rbp add %rax, %r14 adc $(0), %rbp add %rbx, %r14 adc $(0), %rbp mulx (96)(%rsi), %rax, %rbx add %rax, %r15 adc $(0), %rbx add %rbp, %r15 adc $(0), %rbx mulx (104)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 add %rbx, %r8 adc $(0), %r9 movq (80)(%rsi), %rdx mov %r12, (80)(%rdi) mulx (88)(%rsi), %rax, %rbp add %rax, %r15 adc $(0), %rbp mulx (96)(%rsi), %rax, %rbx add %rax, %r8 adc $(0), %rbx add %rbp, %r8 adc $(0), %rbx mulx (104)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 add %rbx, %r9 adc $(0), %r10 movq (88)(%rsi), %rdx mov %r13, (88)(%rdi) mulx (96)(%rsi), %rax, %rbx add %rax, %r9 adc $(0), %rbx mulx (104)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 add %rbx, %r10 adc $(0), %r11 movq (96)(%rsi), %rdx mov %r14, (96)(%rdi) mulx (104)(%rsi), %rax, %r12 add %rax, %r11 adc $(0), %r12 xor %rax, %rax movq %r15, (104)(%rdi) movq %r8, (112)(%rdi) movq %r9, (120)(%rdi) movq %r10, (128)(%rdi) movq %r11, (136)(%rdi) movq %r12, (144)(%rdi) movq %rax, (152)(%rdi) sub $(64), %rdi ret .p2align 6, 0x90 _sqr15_triangle: call _sqr8_triangle movq %r15, (56)(%rdi) xor %r15, %r15 lea (64)(%rsi), %rcx add $(64), %rdi call _mla_8x7 movq %r8, (56)(%rdi) movq (64)(%rsi), %rdx mov %r9, (64)(%rdi) mulx (72)(%rsi), %rax, %rbx add %rax, %r10 adc $(0), %rbx mulx (80)(%rsi), %rax, %rbp add %rax, %r11 adc $(0), %rbp add %rbx, %r11 adc $(0), %rbp mulx (88)(%rsi), %rax, %rbx add %rax, %r12 adc $(0), %rbx add %rbp, %r12 adc $(0), %rbx mulx (96)(%rsi), %rax, %rbp add %rax, %r13 adc $(0), %rbp add %rbx, %r13 adc $(0), %rbp mulx (104)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx add %rbp, %r14 adc $(0), %rbx mulx (112)(%rsi), %rax, %r8 add %rax, %r15 adc $(0), %r8 add %rbx, %r15 adc $(0), %r8 movq (72)(%rsi), %rdx mov %r10, (72)(%rdi) mulx (80)(%rsi), %rax, %rbp add %rax, %r12 adc $(0), %rbp mulx (88)(%rsi), %rax, %rbx add %rax, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mulx (96)(%rsi), %rax, %rbp add %rax, %r14 adc $(0), %rbp add %rbx, %r14 adc $(0), %rbp mulx (104)(%rsi), %rax, %rbx add %rax, %r15 adc $(0), %rbx add %rbp, %r15 adc $(0), %rbx mulx (112)(%rsi), %rax, %r9 add %rax, %r8 adc $(0), %r9 add %rbx, %r8 adc $(0), %r9 movq (80)(%rsi), %rdx mov %r11, (80)(%rdi) mulx (88)(%rsi), %rax, %rbx add %rax, %r14 adc $(0), %rbx mulx (96)(%rsi), %rax, %rbp add %rax, %r15 adc $(0), %rbp add %rbx, %r15 adc $(0), %rbp mulx (104)(%rsi), %rax, %rbx add %rax, %r8 adc $(0), %rbx add %rbp, %r8 adc $(0), %rbx mulx (112)(%rsi), %rax, %r10 add %rax, %r9 adc $(0), %r10 add %rbx, %r9 adc $(0), %r10 movq (88)(%rsi), %rdx mov %r12, (88)(%rdi) mulx (96)(%rsi), %rax, %rbp add %rax, %r8 adc $(0), %rbp mulx (104)(%rsi), %rax, %rbx add %rax, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (112)(%rsi), %rax, %r11 add %rax, %r10 adc $(0), %r11 add %rbx, %r10 adc $(0), %r11 movq (96)(%rsi), %rdx mov %r13, (96)(%rdi) mulx (104)(%rsi), %rax, %rbx add %rax, %r10 adc $(0), %rbx mulx (112)(%rsi), %rax, %r12 add %rax, %r11 adc $(0), %r12 add %rbx, %r11 adc $(0), %r12 movq (104)(%rsi), %rdx mov %r14, (104)(%rdi) mulx (112)(%rsi), %rax, %r13 add %rax, %r12 adc $(0), %r13 xor %rax, %rax movq %r15, (112)(%rdi) movq %r8, (120)(%rdi) movq %r9, (128)(%rdi) movq %r10, (136)(%rdi) movq %r11, (144)(%rdi) movq %r12, (152)(%rdi) movq %r13, (160)(%rdi) movq %rax, (168)(%rdi) sub $(64), %rdi ret .p2align 6, 0x90 _sqr16_triangle: call _sqr8_triangle movq %r15, (56)(%rdi) xor %r15, %r15 mov %rsi, %rcx add $(64), %rsi add $(64), %rdi call _mla_8x8 add $(64), %rdi call _sqr8_triangle xor %rax, %rax movq %r15, (56)(%rdi) movq %r8, (64)(%rdi) movq %r9, (72)(%rdi) movq %r10, (80)(%rdi) movq %r11, (88)(%rdi) movq %r12, (96)(%rdi) movq %r13, (104)(%rdi) movq %r14, (112)(%rdi) movq %rax, (120)(%rdi) sub $(64), %rsi sub $(128), %rdi ret sqr_l_basic: .quad _sqr_1 - sqr_l_basic .quad _sqr_2 - sqr_l_basic .quad _sqr_3 - sqr_l_basic .quad _sqr_4 - sqr_l_basic .quad _sqr_5 - sqr_l_basic .quad _sqr_6 - sqr_l_basic .quad _sqr_7 - sqr_l_basic .quad _sqr_8 - sqr_l_basic .quad _sqr_9 - sqr_l_basic .quad _sqr_10- sqr_l_basic .quad _sqr_11- sqr_l_basic .quad _sqr_12- sqr_l_basic .quad _sqr_13- sqr_l_basic .quad _sqr_14- sqr_l_basic .quad _sqr_15- sqr_l_basic .quad _sqr_16- sqr_l_basic sqrN_triangle: .quad _sqr9_triangle - sqrN_triangle .quad _sqr10_triangle - sqrN_triangle .quad _sqr11_triangle - sqrN_triangle .quad _sqr12_triangle - sqrN_triangle .quad _sqr13_triangle - sqrN_triangle .quad _sqr14_triangle - sqrN_triangle .quad _sqr15_triangle - sqrN_triangle .quad _sqr16_triangle - sqrN_triangle .p2align 6, 0x90 _sqr_8N: push %rdi push %rsi push %rdx push %rdi push %rsi push %rdx push %rdx call _sqr8_triangle pop %rdx movq %r15, (56)(%rdi) xor %r15, %r15 add $(64), %rdi sub $(8), %rdx mov %rsi, %rcx add $(64), %rsi .LinitLoopgas_65: push %rdx call _mla_8x8 pop %rdx add $(64), %rsi add $(64), %rdi sub $(8), %rdx jnz .LinitLoopgas_65 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) movq %r14, (48)(%rdi) movq %r15, (56)(%rdi) jmp .Lupdate_Trianglegas_65 .LouterLoopgas_65: push %rdi push %rsi push %rdx xor %rax, %rax push %rax movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 .LinnerLoop_entrygas_65: push %rdx call _sqr8_triangle pop %rdx movq %r15, (56)(%rdi) xor %r15, %r15 add $(64), %rdi sub $(8), %rdx jz .LskipInnerLoopgas_65 mov %rsi, %rcx add $(64), %rsi .LinnerLoopgas_65: pop %rax neg %rax movq (%rdi), %rax adc %rax, %r8 movq (8)(%rdi), %rax adc %rax, %r9 movq (16)(%rdi), %rax adc %rax, %r10 movq (24)(%rdi), %rax adc %rax, %r11 movq (32)(%rdi), %rax adc %rax, %r12 movq (40)(%rdi), %rax adc %rax, %r13 movq (48)(%rdi), %rax adc %rax, %r14 movq (56)(%rdi), %rax adc %rax, %r15 sbb %rax, %rax push %rax push %rdx call _mla_8x8 pop %rdx add $(64), %rsi add $(64), %rdi sub $(8), %rdx jnz .LinnerLoopgas_65 .LskipInnerLoopgas_65: pop %rax neg %rax adc $(0), %r8 movq %r8, (%rdi) adc $(0), %r9 movq %r9, (8)(%rdi) adc $(0), %r10 movq %r10, (16)(%rdi) adc $(0), %r11 movq %r11, (24)(%rdi) adc $(0), %r12 movq %r12, (32)(%rdi) adc $(0), %r13 movq %r13, (40)(%rdi) adc $(0), %r14 movq %r14, (48)(%rdi) adc $(0), %r15 movq %r15, (56)(%rdi) .Lupdate_Trianglegas_65: pop %rdx pop %rsi pop %rdi add $(64), %rsi add $(128), %rdi sub $(8), %rdx jnz .LouterLoopgas_65 pop %rcx pop %rsi pop %rdi xor %rbx, %rbx .Lupdate_loopgas_65: call _add_diag_4 add $(64), %rdi add $(32), %rsi sub $(4), %rcx jnz .Lupdate_loopgas_65 ret .p2align 6, 0x90 _sqr_N: push %rdi push %rsi push %rdx push %rdi push %rsi push %rdx mov %rdx, %rbp and $(7), %rbp lea mla_8xl_tail(%rip), %rax mov (-8)(%rax,%rbp,8), %rbp add %rbp, %rax push %rax sub $(8), %rdx push %rdx call _sqr8_triangle pop %rdx movq %r15, (56)(%rdi) add $(64), %rdi xor %r15, %r15 mov %rsi, %rcx add $(64), %rsi sub $(8), %rdx .LinitLoopgas_66: push %rdx call _mla_8x8 pop %rdx add $(64), %rsi add $(64), %rdi sub $(8), %rdx jnc .LinitLoopgas_66 add $(8), %rdx xor %rcx, %rsi xor %rsi, %rcx xor %rcx, %rsi mov (%rsp), %rax push %rdx call *%rax pop %rdx lea (%rdi,%rdx,8), %rdi movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) movq %r14, (48)(%rdi) movq %r15, (56)(%rdi) jmp .Lupdate_Trianglegas_66 .LouterLoopgas_66: push %rdi push %rsi push %rdx push %rax xor %rax, %rax push %rax movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 sub $(8), %rdx push %rdx call _sqr8_triangle pop %rdx movq %r15, (56)(%rdi) add $(64), %rdi xor %r15, %r15 mov %rsi, %rcx add $(64), %rsi sub $(8), %rdx .LinnerLoopgas_66: pop %rax neg %rax movq (%rdi), %rax adc %rax, %r8 movq (8)(%rdi), %rax adc %rax, %r9 movq (16)(%rdi), %rax adc %rax, %r10 movq (24)(%rdi), %rax adc %rax, %r11 movq (32)(%rdi), %rax adc %rax, %r12 movq (40)(%rdi), %rax adc %rax, %r13 movq (48)(%rdi), %rax adc %rax, %r14 movq (56)(%rdi), %rax adc %rax, %r15 sbb %rax, %rax push %rax push %rdx call _mla_8x8 pop %rdx add $(64), %rsi add $(64), %rdi sub $(8), %rdx jnc .LinnerLoopgas_66 add $(8), %rdx pxor %xmm0, %xmm0 movdqu %xmm0, (%rdi,%rdx,8) movdqu %xmm0, (16)(%rdi,%rdx,8) movdqu %xmm0, (32)(%rdi,%rdx,8) movdqu %xmm0, (48)(%rdi,%rdx,8) pop %rax neg %rax movq (%rdi), %rax adc %rax, %r8 movq (8)(%rdi), %rax adc %rax, %r9 movq (16)(%rdi), %rax adc %rax, %r10 movq (24)(%rdi), %rax adc %rax, %r11 movq (32)(%rdi), %rax adc %rax, %r12 movq (40)(%rdi), %rax adc %rax, %r13 movq (48)(%rdi), %rax adc %rax, %r14 movq (56)(%rdi), %rax adc %rax, %r15 sbb %rax, %rax neg %rax movq %rax, (64)(%rdi) xor %rcx, %rsi xor %rsi, %rcx xor %rcx, %rsi mov (%rsp), %rax push %rdx call *%rax pop %rdx lea (%rdi,%rdx,8), %rdi xor %rax, %rax movq (%rdi), %rax add %rax, %r8 movq %r8, (%rdi) movq (8)(%rdi), %rax adc %rax, %r9 movq %r9, (8)(%rdi) movq (16)(%rdi), %rax adc %rax, %r10 movq %r10, (16)(%rdi) movq (24)(%rdi), %rax adc %rax, %r11 movq %r11, (24)(%rdi) movq (32)(%rdi), %rax adc %rax, %r12 movq %r12, (32)(%rdi) movq (40)(%rdi), %rax adc %rax, %r13 movq %r13, (40)(%rdi) movq (48)(%rdi), %rax adc %rax, %r14 movq %r14, (48)(%rdi) movq (56)(%rdi), %rax adc %rax, %r15 movq %r15, (56)(%rdi) .Lupdate_Trianglegas_66: pop %rax pop %rdx pop %rsi pop %rdi add $(64), %rsi add $(128), %rdi sub $(8), %rdx cmp $(16), %rdx jg .LouterLoopgas_66 mov %rdx, %rbp sub $(8), %rbp lea sqrN_triangle(%rip), %rax mov (-8)(%rax,%rbp,8), %rbp add %rbp, %rax sub $(256), %rsp push %rdi push %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 lea (16)(%rsp), %rdi call *%rax mov %rdi, %rsi pop %rdx pop %rdi movdqu (%rsi), %xmm0 movdqu (16)(%rsi), %xmm1 movdqu (32)(%rsi), %xmm2 movdqu (48)(%rsi), %xmm3 add $(64), %rsi movdqu %xmm0, (%rdi) movdqu %xmm1, (16)(%rdi) movdqu %xmm2, (32)(%rdi) movdqu %xmm3, (48)(%rdi) add $(64), %rdi lea (-8)(%rdx), %rax xor %rbx, %rbx .Lupdate1gas_66: movq (%rsi), %r8 movq (%rdi), %r9 add $(8), %rsi neg %rbx adc %r9, %r8 sbb %rbx, %rbx movq %r8, (%rdi) add $(8), %rdi sub $(1), %rax jg .Lupdate1gas_66 .Lupdate2gas_66: movq (%rsi), %r8 add $(8), %rsi neg %rbx adc $(0), %r8 sbb %rbx, %rbx movq %r8, (%rdi) add $(8), %rdi sub $(1), %rdx jg .Lupdate2gas_66 add $(256), %rsp .Ladd_diagonalsgas_66: pop %rcx pop %rsi pop %rdi sub $(4), %rcx xor %rbx, %rbx .Ladd_diagonal_loopgas_66: call _add_diag_4 add $(64), %rdi add $(32), %rsi sub $(4), %rcx jnc .Ladd_diagonal_loopgas_66 add $(4), %rcx jz .Lquitgas_66 .Ladd_diagonal_restgas_66: movq (%rdi), %r8 movq (8)(%rdi), %r9 xor %rbp, %rbp add %r8, %r8 adc %r9, %r9 adc $(0), %rbp mov (%rsi), %rdx mulx %rdx, %rax, %rdx add %rbx, %rax adc $(0), %rdx add %rax, %r8 mov %rbp, %rbx adc %rdx, %r9 adc $(0), %rbx movq %r8, (%rdi) movq %r9, (8)(%rdi) add $(16), %rdi add $(8), %rsi sub $(1), %rcx jnz .Ladd_diagonal_restgas_66 .Lquitgas_66: ret .p2align 6, 0x90 _sub_N: xor %rax, %rax .Lsub_nextgas_67: lea (8)(%rdi), %rdi movq (%rsi), %r8 movq (%rcx), %r9 lea (8)(%rsi), %rsi lea (8)(%rcx), %rcx sbb %r9, %r8 movq %r8, (-8)(%rdi) dec %rdx jnz .Lsub_nextgas_67 adc $(0), %rax ret .p2align 6, 0x90 _copy_ae_N: lea (8)(%rdi), %rdi movq (%rsi), %r8 movq (%rcx), %r9 lea (8)(%rsi), %rsi lea (8)(%rcx), %rcx cmovae %r9, %r8 movq %r8, (-8)(%rdi) dec %rdx jnz _copy_ae_N ret .p2align 6, 0x90 _mred1_start: mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rbx, %r8 ret .p2align 6, 0x90 _mred2_start: mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mov %rbp, %r9 ret .p2align 6, 0x90 _mred3_start: mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mov %rbx, %r10 ret .p2align 6, 0x90 _mred4_start: mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mov %rbp, %r11 ret .p2align 6, 0x90 _mred5_start: mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mov %rbx, %r12 ret .p2align 6, 0x90 _mred6_start: mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mov %rbp, %r13 ret .p2align 6, 0x90 _mred7_start: mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mulx (48)(%rsi), %r13, %rbx add %r14, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mov %rbx, %r14 ret .p2align 6, 0x90 _mred8_start: mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (32)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mulx (40)(%rsi), %r12, %rbp add %r13, %r12 adc $(0), %rbp add %rbx, %r12 adc $(0), %rbp mulx (48)(%rsi), %r13, %rbx add %r14, %r13 adc $(0), %rbx add %rbp, %r13 adc $(0), %rbx mulx (56)(%rsi), %r14, %rbp add %r15, %r14 adc $(0), %rbp add %rbx, %r14 adc $(0), %rbp mov %rbp, %r15 ret .p2align 6, 0x90 _mred8x1_start: push %rdx mulx %r8, %rdx, %rbx movq %rdx, (%rcx) call _mred8_start mov %rax, (%rdi) pop %rdx ret .p2align 6, 0x90 _mred8x2_start: push %rdx mulx %r8, %rdx, %rbx movq %rdx, (%rcx) call _mred8_start mov %rax, (%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (8)(%rcx) call _mred8_start mov %rax, (8)(%rdi) pop %rdx ret .p2align 6, 0x90 _mred8x3_start: push %rdx mulx %r8, %rdx, %rbx movq %rdx, (%rcx) call _mred8_start mov %rax, (%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (8)(%rcx) call _mred8_start mov %rax, (8)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (16)(%rcx) call _mred8_start mov %rax, (16)(%rdi) pop %rdx ret .p2align 6, 0x90 _mred8x4_start: push %rdx mulx %r8, %rdx, %rbx movq %rdx, (%rcx) call _mred8_start mov %rax, (%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (8)(%rcx) call _mred8_start mov %rax, (8)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (16)(%rcx) call _mred8_start mov %rax, (16)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (24)(%rcx) call _mred8_start mov %rax, (24)(%rdi) pop %rdx ret .p2align 6, 0x90 _mred8x5_start: push %rdx mulx %r8, %rdx, %rbx movq %rdx, (%rcx) call _mred8_start mov %rax, (%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (8)(%rcx) call _mred8_start mov %rax, (8)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (16)(%rcx) call _mred8_start mov %rax, (16)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (24)(%rcx) call _mred8_start mov %rax, (24)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (32)(%rcx) call _mred8_start mov %rax, (32)(%rdi) pop %rdx ret .p2align 6, 0x90 _mred8x6_start: push %rdx mulx %r8, %rdx, %rbx movq %rdx, (%rcx) call _mred8_start mov %rax, (%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (8)(%rcx) call _mred8_start mov %rax, (8)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (16)(%rcx) call _mred8_start mov %rax, (16)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (24)(%rcx) call _mred8_start mov %rax, (24)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (32)(%rcx) call _mred8_start mov %rax, (32)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (40)(%rcx) call _mred8_start mov %rax, (40)(%rdi) pop %rdx ret .p2align 6, 0x90 _mred8x7_start: push %rdx mulx %r8, %rdx, %rbx movq %rdx, (%rcx) call _mred8_start mov %rax, (%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (8)(%rcx) call _mred8_start mov %rax, (8)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (16)(%rcx) call _mred8_start mov %rax, (16)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (24)(%rcx) call _mred8_start mov %rax, (24)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (32)(%rcx) call _mred8_start mov %rax, (32)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (40)(%rcx) call _mred8_start mov %rax, (40)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (48)(%rcx) call _mred8_start mov %rax, (48)(%rdi) pop %rdx ret .p2align 6, 0x90 _mred8x8_start: push %rdx mulx %r8, %rdx, %rbx movq %rdx, (%rcx) call _mred8_start mov %rax, (%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (8)(%rcx) call _mred8_start mov %rax, (8)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (16)(%rcx) call _mred8_start mov %rax, (16)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (24)(%rcx) call _mred8_start mov %rax, (24)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (32)(%rcx) call _mred8_start mov %rax, (32)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (40)(%rcx) call _mred8_start mov %rax, (40)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (48)(%rcx) call _mred8_start mov %rax, (48)(%rdi) mov (%rsp), %rdx mulx %r8, %rdx, %rbx movq %rdx, (56)(%rcx) call _mred8_start mov %rax, (56)(%rdi) pop %rdx ret .p2align 6, 0x90 _mred_5: push %r8 movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred5_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred5_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred5_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred5_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred5_start pop %rax xor %rax, %rax mov (40)(%rdi), %rbx add %rbx, %r8 movq %r8, (40)(%rdi) mov (48)(%rdi), %rbx adc %rbx, %r9 movq %r9, (48)(%rdi) mov (56)(%rdi), %rbx adc %rbx, %r10 movq %r10, (56)(%rdi) mov (64)(%rdi), %rbx adc %rbx, %r11 movq %r11, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r12 movq %r12, (72)(%rdi) adc $(0), %rax mov (%rsi), %rbx sub %rbx, %r8 mov (8)(%rsi), %rbx sbb %rbx, %r9 mov (16)(%rsi), %rbx sbb %rbx, %r10 mov (24)(%rsi), %rbx sbb %rbx, %r11 mov (32)(%rsi), %rbx sbb %rbx, %r12 sbb $(0), %rax movq (40)(%rdi), %rax movq (48)(%rdi), %rbx movq (56)(%rdi), %rcx movq (64)(%rdi), %rdx movq (72)(%rdi), %rbp cmovae %r8, %rax cmovae %r9, %rbx cmovae %r10, %rcx cmovae %r11, %rdx cmovae %r12, %rbp movq %rax, (%r15) movq %rbx, (8)(%r15) movq %rcx, (16)(%r15) movq %rdx, (24)(%r15) movq %rbp, (32)(%r15) ret .p2align 6, 0x90 _mred_6: push %r8 movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred6_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred6_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred6_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred6_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred6_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred6_start pop %rax xor %rax, %rax mov (48)(%rdi), %rbx add %rbx, %r8 movq %r8, (48)(%rdi) mov (56)(%rdi), %rbx adc %rbx, %r9 movq %r9, (56)(%rdi) mov (64)(%rdi), %rbx adc %rbx, %r10 movq %r10, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r11 movq %r11, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r12 movq %r12, (80)(%rdi) mov (88)(%rdi), %rbx adc %rbx, %r13 movq %r13, (88)(%rdi) adc $(0), %rax mov (%rsi), %rbx sub %rbx, %r8 mov (8)(%rsi), %rbx sbb %rbx, %r9 mov (16)(%rsi), %rbx sbb %rbx, %r10 mov (24)(%rsi), %rbx sbb %rbx, %r11 mov (32)(%rsi), %rbx sbb %rbx, %r12 mov (40)(%rsi), %rbx sbb %rbx, %r13 sbb $(0), %rax movq (48)(%rdi), %rax movq (56)(%rdi), %rbx movq (64)(%rdi), %rcx movq (72)(%rdi), %rdx movq (80)(%rdi), %rbp movq (88)(%rdi), %rsi cmovae %r8, %rax cmovae %r9, %rbx cmovae %r10, %rcx cmovae %r11, %rdx cmovae %r12, %rbp cmovae %r13, %rsi movq %rax, (%r15) movq %rbx, (8)(%r15) movq %rcx, (16)(%r15) movq %rdx, (24)(%r15) movq %rbp, (32)(%r15) movq %rsi, (40)(%r15) ret .p2align 6, 0x90 _mred_7: push %r8 movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred7_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred7_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred7_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred7_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred7_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred7_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred7_start pop %rax xor %rax, %rax mov (56)(%rdi), %rbx add %rbx, %r8 movq %r8, (56)(%rdi) mov (64)(%rdi), %rbx adc %rbx, %r9 movq %r9, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r10 movq %r10, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r11 movq %r11, (80)(%rdi) mov (88)(%rdi), %rbx adc %rbx, %r12 movq %r12, (88)(%rdi) mov (96)(%rdi), %rbx adc %rbx, %r13 movq %r13, (96)(%rdi) mov (104)(%rdi), %rbx adc %rbx, %r14 movq %r14, (104)(%rdi) adc $(0), %rax mov (%rsi), %rbx sub %rbx, %r8 mov (8)(%rsi), %rbx sbb %rbx, %r9 mov (16)(%rsi), %rbx sbb %rbx, %r10 mov (24)(%rsi), %rbx sbb %rbx, %r11 mov (32)(%rsi), %rbx sbb %rbx, %r12 mov (40)(%rsi), %rbx sbb %rbx, %r13 mov (48)(%rsi), %rbx sbb %rbx, %r14 sbb $(0), %rax movq (56)(%rdi), %rax movq (64)(%rdi), %rbx movq (72)(%rdi), %rcx movq (80)(%rdi), %rdx movq (88)(%rdi), %rbp movq (96)(%rdi), %rsi movq (104)(%rdi), %rdi cmovae %r8, %rax cmovae %r9, %rbx cmovae %r10, %rcx cmovae %r11, %rdx cmovae %r12, %rbp cmovae %r13, %rsi cmovae %r14, %rdi movq %rax, (%r15) movq %rbx, (8)(%r15) movq %rcx, (16)(%r15) movq %rdx, (24)(%r15) movq %rbp, (32)(%r15) movq %rsi, (40)(%r15) movq %rdi, (48)(%r15) ret .p2align 6, 0x90 _mred_8: push %r15 push %r8 movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred8_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred8_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred8_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred8_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred8_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred8_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred8_start mov (%rsp), %rdx mulx %r8, %rdx, %rbx call _mred8_start pop %rax xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 movq %r8, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r9 movq %r9, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r10 movq %r10, (80)(%rdi) mov (88)(%rdi), %rbx adc %rbx, %r11 movq %r11, (88)(%rdi) mov (96)(%rdi), %rbx adc %rbx, %r12 movq %r12, (96)(%rdi) mov (104)(%rdi), %rbx adc %rbx, %r13 movq %r13, (104)(%rdi) mov (112)(%rdi), %rbx adc %rbx, %r14 movq %r14, (112)(%rdi) mov (120)(%rdi), %rbx adc %rbx, %r15 movq %r15, (120)(%rdi) adc $(0), %rax mov (%rsi), %rbx sub %rbx, %r8 mov (8)(%rsi), %rbx sbb %rbx, %r9 mov (16)(%rsi), %rbx sbb %rbx, %r10 mov (24)(%rsi), %rbx sbb %rbx, %r11 mov (32)(%rsi), %rbx sbb %rbx, %r12 mov (40)(%rsi), %rbx sbb %rbx, %r13 mov (48)(%rsi), %rbx sbb %rbx, %r14 mov (56)(%rsi), %rbx sbb %rbx, %r15 sbb $(0), %rax pop %rsi movq (64)(%rdi), %rax movq (72)(%rdi), %rbx movq (80)(%rdi), %rcx movq (88)(%rdi), %rdx cmovae %r8, %rax cmovae %r9, %rbx cmovae %r10, %rcx cmovae %r11, %rdx movq %rax, (%rsi) movq %rbx, (8)(%rsi) movq %rcx, (16)(%rsi) movq %rdx, (24)(%rsi) movq (96)(%rdi), %rax movq (104)(%rdi), %rbx movq (112)(%rdi), %rcx movq (120)(%rdi), %rdx cmovae %r12, %rax cmovae %r13, %rbx cmovae %r14, %rcx cmovae %r15, %rdx movq %rax, (32)(%rsi) movq %rbx, (40)(%rsi) movq %rcx, (48)(%rsi) movq %rdx, (56)(%rsi) ret .p2align 6, 0x90 _mred_9: push %r15 sub $(64), %rsp mov %rsp, %rcx push %r8 mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx call _mla_8x1 xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx pop %rax shr $(1), %rax movq %r8, (8)(%rdi) movq %r9, (16)(%rdi) movq %r10, (24)(%rdi) movq %r11, (32)(%rdi) movq %r12, (40)(%rdi) movq %r13, (48)(%rdi) movq %r14, (56)(%rdi) mov (64)(%rdi), %rbx adc %rbx, %r15 mov %r15, (64)(%rdi) adc $(0), %rax push %rax sub $(64), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 mov (8)(%rsp), %rdx call _mred8x1_start xor %rax, %rax movq %r8, (8)(%rdi) movq %r9, (16)(%rdi) movq %r10, (24)(%rdi) movq %r11, (32)(%rdi) movq %r12, (40)(%rdi) movq %r13, (48)(%rdi) movq %r14, (56)(%rdi) mov %r15, %r8 addq (64)(%rdi), %r8 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi call _mla_1x1 pop %rax shr $(1), %rax mov (8)(%rdi), %rbx adc %rbx, %r8 adc $(0), %rax pop %rbx add %rbx, %r8 movq %r8, (8)(%rdi) adc $(0), %rax pop %rcx add $(64), %rsp lea (-64)(%rsi), %rcx lea (-56)(%rdi), %rsi pop %rdi mov %rax, %rbx mov $(9), %rdx call _sub_N sub %rax, %rbx sub $(72), %rdi sub $(72), %rsi mov %rdi, %rcx mov $(9), %rdx shr $(1), %rbx call _copy_ae_N ret .p2align 6, 0x90 _mred_10: push %r15 sub $(64), %rsp mov %rsp, %rcx push %r8 mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx call _mla_8x2 xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx pop %rax shr $(1), %rax movq %r8, (16)(%rdi) movq %r9, (24)(%rdi) movq %r10, (32)(%rdi) movq %r11, (40)(%rdi) movq %r12, (48)(%rdi) movq %r13, (56)(%rdi) mov (64)(%rdi), %rbx adc %rbx, %r14 mov %r14, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r15 mov %r15, (72)(%rdi) adc $(0), %rax push %rax sub $(64), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 mov (8)(%rsp), %rdx call _mred8x2_start xor %rax, %rax movq %r8, (16)(%rdi) movq %r9, (24)(%rdi) movq %r10, (32)(%rdi) movq %r11, (40)(%rdi) movq %r12, (48)(%rdi) movq %r13, (56)(%rdi) mov %r14, %r8 mov %r15, %r9 addq (64)(%rdi), %r8 adcq (72)(%rdi), %r9 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi call _mla_2x2 pop %rax shr $(1), %rax mov (16)(%rdi), %rbx adc %rbx, %r8 mov (24)(%rdi), %rbx adc %rbx, %r9 adc $(0), %rax pop %rbx add %rbx, %r8 adc $(0), %r9 movq %r8, (16)(%rdi) movq %r9, (24)(%rdi) adc $(0), %rax pop %rcx add $(64), %rsp lea (-64)(%rsi), %rcx lea (-48)(%rdi), %rsi pop %rdi mov %rax, %rbx mov $(10), %rdx call _sub_N sub %rax, %rbx sub $(80), %rdi sub $(80), %rsi mov %rdi, %rcx mov $(10), %rdx shr $(1), %rbx call _copy_ae_N ret .p2align 6, 0x90 _mred_11: push %r15 sub $(64), %rsp mov %rsp, %rcx push %r8 mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx call _mla_8x3 xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx pop %rax shr $(1), %rax movq %r8, (24)(%rdi) movq %r9, (32)(%rdi) movq %r10, (40)(%rdi) movq %r11, (48)(%rdi) movq %r12, (56)(%rdi) mov (64)(%rdi), %rbx adc %rbx, %r13 mov %r13, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r14 mov %r14, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r15 mov %r15, (80)(%rdi) adc $(0), %rax push %rax sub $(64), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 mov (8)(%rsp), %rdx call _mred8x3_start xor %rax, %rax movq %r8, (24)(%rdi) movq %r9, (32)(%rdi) movq %r10, (40)(%rdi) movq %r11, (48)(%rdi) movq %r12, (56)(%rdi) mov %r13, %r8 mov %r14, %r9 mov %r15, %r10 addq (64)(%rdi), %r8 adcq (72)(%rdi), %r9 adcq (80)(%rdi), %r10 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi call _mla_3x3 pop %rax shr $(1), %rax mov (24)(%rdi), %rbx adc %rbx, %r8 mov (32)(%rdi), %rbx adc %rbx, %r9 mov (40)(%rdi), %rbx adc %rbx, %r10 adc $(0), %rax pop %rbx add %rbx, %r8 adc $(0), %r9 adc $(0), %r10 movq %r8, (24)(%rdi) movq %r9, (32)(%rdi) movq %r10, (40)(%rdi) adc $(0), %rax pop %rcx add $(64), %rsp lea (-64)(%rsi), %rcx lea (-40)(%rdi), %rsi pop %rdi mov %rax, %rbx mov $(11), %rdx call _sub_N sub %rax, %rbx sub $(88), %rdi sub $(88), %rsi mov %rdi, %rcx mov $(11), %rdx shr $(1), %rbx call _copy_ae_N ret .p2align 6, 0x90 _mred_12: push %r15 sub $(64), %rsp mov %rsp, %rcx push %r8 mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx call _mla_8x4 xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx pop %rax shr $(1), %rax movq %r8, (32)(%rdi) movq %r9, (40)(%rdi) movq %r10, (48)(%rdi) movq %r11, (56)(%rdi) mov (64)(%rdi), %rbx adc %rbx, %r12 mov %r12, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r13 mov %r13, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r14 mov %r14, (80)(%rdi) mov (88)(%rdi), %rbx adc %rbx, %r15 mov %r15, (88)(%rdi) adc $(0), %rax push %rax sub $(64), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 mov (8)(%rsp), %rdx call _mred8x4_start xor %rax, %rax movq %r8, (32)(%rdi) movq %r9, (40)(%rdi) movq %r10, (48)(%rdi) movq %r11, (56)(%rdi) mov %r12, %r8 mov %r13, %r9 mov %r14, %r10 mov %r15, %r11 addq (64)(%rdi), %r8 adcq (72)(%rdi), %r9 adcq (80)(%rdi), %r10 adcq (88)(%rdi), %r11 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi call _mla_4x4 pop %rax shr $(1), %rax mov (32)(%rdi), %rbx adc %rbx, %r8 mov (40)(%rdi), %rbx adc %rbx, %r9 mov (48)(%rdi), %rbx adc %rbx, %r10 mov (56)(%rdi), %rbx adc %rbx, %r11 adc $(0), %rax pop %rbx add %rbx, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 movq %r8, (32)(%rdi) movq %r9, (40)(%rdi) movq %r10, (48)(%rdi) movq %r11, (56)(%rdi) adc $(0), %rax pop %rcx add $(64), %rsp lea (-64)(%rsi), %rcx lea (-32)(%rdi), %rsi pop %rdi mov %rax, %rbx mov $(12), %rdx call _sub_N sub %rax, %rbx sub $(96), %rdi sub $(96), %rsi mov %rdi, %rcx mov $(12), %rdx shr $(1), %rbx call _copy_ae_N ret .p2align 6, 0x90 _mred_13: push %r15 sub $(64), %rsp mov %rsp, %rcx push %r8 mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx call _mla_8x5 xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx pop %rax shr $(1), %rax movq %r8, (40)(%rdi) movq %r9, (48)(%rdi) movq %r10, (56)(%rdi) mov (64)(%rdi), %rbx adc %rbx, %r11 mov %r11, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r12 mov %r12, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r13 mov %r13, (80)(%rdi) mov (88)(%rdi), %rbx adc %rbx, %r14 mov %r14, (88)(%rdi) mov (96)(%rdi), %rbx adc %rbx, %r15 mov %r15, (96)(%rdi) adc $(0), %rax push %rax sub $(64), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 mov (8)(%rsp), %rdx call _mred8x5_start xor %rax, %rax movq %r8, (40)(%rdi) movq %r9, (48)(%rdi) movq %r10, (56)(%rdi) mov %r11, %r8 mov %r12, %r9 mov %r13, %r10 mov %r14, %r11 mov %r15, %r12 addq (64)(%rdi), %r8 adcq (72)(%rdi), %r9 adcq (80)(%rdi), %r10 adcq (88)(%rdi), %r11 adcq (96)(%rdi), %r12 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi call _mla_5x5 pop %rax shr $(1), %rax mov (40)(%rdi), %rbx adc %rbx, %r8 mov (48)(%rdi), %rbx adc %rbx, %r9 mov (56)(%rdi), %rbx adc %rbx, %r10 mov (64)(%rdi), %rbx adc %rbx, %r11 mov (72)(%rdi), %rbx adc %rbx, %r12 adc $(0), %rax pop %rbx add %rbx, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 movq %r8, (40)(%rdi) movq %r9, (48)(%rdi) movq %r10, (56)(%rdi) movq %r11, (64)(%rdi) movq %r12, (72)(%rdi) adc $(0), %rax pop %rcx add $(64), %rsp lea (-64)(%rsi), %rcx lea (-24)(%rdi), %rsi pop %rdi mov %rax, %rbx mov $(13), %rdx call _sub_N sub %rax, %rbx sub $(104), %rdi sub $(104), %rsi mov %rdi, %rcx mov $(13), %rdx shr $(1), %rbx call _copy_ae_N ret .p2align 6, 0x90 _mred_14: push %r15 sub $(64), %rsp mov %rsp, %rcx push %r8 mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx call _mla_8x6 xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx pop %rax shr $(1), %rax movq %r8, (48)(%rdi) movq %r9, (56)(%rdi) mov (64)(%rdi), %rbx adc %rbx, %r10 mov %r10, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r11 mov %r11, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r12 mov %r12, (80)(%rdi) mov (88)(%rdi), %rbx adc %rbx, %r13 mov %r13, (88)(%rdi) mov (96)(%rdi), %rbx adc %rbx, %r14 mov %r14, (96)(%rdi) mov (104)(%rdi), %rbx adc %rbx, %r15 mov %r15, (104)(%rdi) adc $(0), %rax push %rax sub $(64), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 mov (8)(%rsp), %rdx call _mred8x6_start xor %rax, %rax movq %r8, (48)(%rdi) movq %r9, (56)(%rdi) mov %r10, %r8 mov %r11, %r9 mov %r12, %r10 mov %r13, %r11 mov %r14, %r12 mov %r15, %r13 addq (64)(%rdi), %r8 adcq (72)(%rdi), %r9 adcq (80)(%rdi), %r10 adcq (88)(%rdi), %r11 adcq (96)(%rdi), %r12 adcq (104)(%rdi), %r13 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi call _mla_6x6 pop %rax shr $(1), %rax mov (48)(%rdi), %rbx adc %rbx, %r8 mov (56)(%rdi), %rbx adc %rbx, %r9 mov (64)(%rdi), %rbx adc %rbx, %r10 mov (72)(%rdi), %rbx adc %rbx, %r11 mov (80)(%rdi), %rbx adc %rbx, %r12 mov (88)(%rdi), %rbx adc %rbx, %r13 adc $(0), %rax pop %rbx add %rbx, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 movq %r8, (48)(%rdi) movq %r9, (56)(%rdi) movq %r10, (64)(%rdi) movq %r11, (72)(%rdi) movq %r12, (80)(%rdi) movq %r13, (88)(%rdi) adc $(0), %rax pop %rcx add $(64), %rsp lea (-64)(%rsi), %rcx lea (-16)(%rdi), %rsi pop %rdi mov %rax, %rbx mov $(14), %rdx call _sub_N sub %rax, %rbx sub $(112), %rdi sub $(112), %rsi mov %rdi, %rcx mov $(14), %rdx shr $(1), %rbx call _copy_ae_N ret .p2align 6, 0x90 _mred_15: push %r15 sub $(64), %rsp mov %rsp, %rcx push %r8 mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx call _mla_8x7 xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx pop %rax shr $(1), %rax movq %r8, (56)(%rdi) mov (64)(%rdi), %rbx adc %rbx, %r9 mov %r9, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r10 mov %r10, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r11 mov %r11, (80)(%rdi) mov (88)(%rdi), %rbx adc %rbx, %r12 mov %r12, (88)(%rdi) mov (96)(%rdi), %rbx adc %rbx, %r13 mov %r13, (96)(%rdi) mov (104)(%rdi), %rbx adc %rbx, %r14 mov %r14, (104)(%rdi) mov (112)(%rdi), %rbx adc %rbx, %r15 mov %r15, (112)(%rdi) adc $(0), %rax push %rax sub $(64), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 mov (8)(%rsp), %rdx call _mred8x7_start xor %rax, %rax movq %r8, (56)(%rdi) mov %r9, %r8 mov %r10, %r9 mov %r11, %r10 mov %r12, %r11 mov %r13, %r12 mov %r14, %r13 mov %r15, %r14 addq (64)(%rdi), %r8 adcq (72)(%rdi), %r9 adcq (80)(%rdi), %r10 adcq (88)(%rdi), %r11 adcq (96)(%rdi), %r12 adcq (104)(%rdi), %r13 adcq (112)(%rdi), %r14 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi call _mla_7x7 pop %rax shr $(1), %rax mov (56)(%rdi), %rbx adc %rbx, %r8 mov (64)(%rdi), %rbx adc %rbx, %r9 mov (72)(%rdi), %rbx adc %rbx, %r10 mov (80)(%rdi), %rbx adc %rbx, %r11 mov (88)(%rdi), %rbx adc %rbx, %r12 mov (96)(%rdi), %rbx adc %rbx, %r13 mov (104)(%rdi), %rbx adc %rbx, %r14 adc $(0), %rax pop %rbx add %rbx, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 adc $(0), %r14 movq %r8, (56)(%rdi) movq %r9, (64)(%rdi) movq %r10, (72)(%rdi) movq %r11, (80)(%rdi) movq %r12, (88)(%rdi) movq %r13, (96)(%rdi) movq %r14, (104)(%rdi) adc $(0), %rax pop %rcx add $(64), %rsp lea (-64)(%rsi), %rcx lea (-8)(%rdi), %rsi pop %rdi mov %rax, %rbx mov $(15), %rdx call _sub_N sub %rax, %rbx sub $(120), %rdi sub $(120), %rsi mov %rdi, %rcx mov $(15), %rdx shr $(1), %rbx call _copy_ae_N ret .p2align 6, 0x90 _mred_16: push %r15 sub $(64), %rsp mov %rsp, %rcx mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax add $(64), %rsi add $(64), %rdi push %rdx call _mla_8x8 pop %rdx pop %rax shr $(1), %rax mov (64)(%rdi), %rbx adc %rbx, %r8 mov %r8, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r9 mov %r9, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r10 mov %r10, (80)(%rdi) mov (88)(%rdi), %rbx adc %rbx, %r11 mov %r11, (88)(%rdi) mov (96)(%rdi), %rbx adc %rbx, %r12 mov %r12, (96)(%rdi) mov (104)(%rdi), %rbx adc %rbx, %r13 mov %r13, (104)(%rdi) mov (112)(%rdi), %rbx adc %rbx, %r14 mov %r14, (112)(%rdi) mov (120)(%rdi), %rbx adc %rbx, %r15 mov %r15, (120)(%rdi) adc $(0), %rax push %rax sub $(64), %rsi movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi call _mla_8x8 sub $(64), %rsi pop %rax shr $(1), %rax mov (64)(%rdi), %rbx adc %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax pop %rbx add %rbx, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 adc $(0), %r14 adc $(0), %r15 adc $(0), %rax movq %r8, (64)(%rdi) movq %r9, (72)(%rdi) movq %r10, (80)(%rdi) movq %r11, (88)(%rdi) movq %r12, (96)(%rdi) movq %r13, (104)(%rdi) movq %r14, (112)(%rdi) movq %r15, (120)(%rdi) add $(64), %rsp pop %rbp mov (%rdi), %rbx sub (%rsi), %rbx mov %rbx, (%rbp) mov (8)(%rdi), %rbx sbb (8)(%rsi), %rbx mov %rbx, (8)(%rbp) mov (16)(%rdi), %rbx sbb (16)(%rsi), %rbx mov %rbx, (16)(%rbp) mov (24)(%rdi), %rbx sbb (24)(%rsi), %rbx mov %rbx, (24)(%rbp) mov (32)(%rdi), %rbx sbb (32)(%rsi), %rbx mov %rbx, (32)(%rbp) mov (40)(%rdi), %rbx sbb (40)(%rsi), %rbx mov %rbx, (40)(%rbp) mov (48)(%rdi), %rbx sbb (48)(%rsi), %rbx mov %rbx, (48)(%rbp) mov (56)(%rdi), %rbx sbb (56)(%rsi), %rbx mov %rbx, (56)(%rbp) mov (64)(%rsi), %rbx sbb %rbx, %r8 mov (72)(%rsi), %rbx sbb %rbx, %r9 mov (80)(%rsi), %rbx sbb %rbx, %r10 mov (88)(%rsi), %rbx sbb %rbx, %r11 mov (96)(%rsi), %rbx sbb %rbx, %r12 mov (104)(%rsi), %rbx sbb %rbx, %r13 mov (112)(%rsi), %rbx sbb %rbx, %r14 mov (120)(%rsi), %rbx sbb %rbx, %r15 sbb $(0), %rax movq (64)(%rdi), %rax movq (72)(%rdi), %rbx movq (80)(%rdi), %rcx movq (88)(%rdi), %rdx cmovae %r8, %rax cmovae %r9, %rbx cmovae %r10, %rcx cmovae %r11, %rdx movq %rax, (64)(%rbp) movq %rbx, (72)(%rbp) movq %rcx, (80)(%rbp) movq %rdx, (88)(%rbp) movq (96)(%rdi), %rax movq (104)(%rdi), %rbx movq (112)(%rdi), %rcx movq (120)(%rdi), %rdx cmovae %r12, %rax cmovae %r13, %rbx cmovae %r14, %rcx cmovae %r15, %rdx movq %rax, (96)(%rbp) movq %rbx, (104)(%rbp) movq %rcx, (112)(%rbp) movq %rdx, (120)(%rbp) movq (%rbp), %r8 movq (8)(%rbp), %r9 movq (16)(%rbp), %r10 movq (24)(%rbp), %r11 movq (32)(%rbp), %r12 movq (40)(%rbp), %r13 movq (48)(%rbp), %r14 movq (56)(%rbp), %r15 movq (%rdi), %rax movq (8)(%rdi), %rbx movq (16)(%rdi), %rcx movq (24)(%rdi), %rdx cmovae %r8, %rax cmovae %r9, %rbx cmovae %r10, %rcx cmovae %r11, %rdx movq %rax, (%rbp) movq %rbx, (8)(%rbp) movq %rcx, (16)(%rbp) movq %rdx, (24)(%rbp) movq (32)(%rdi), %rax movq (40)(%rdi), %rbx movq (48)(%rdi), %rcx movq (56)(%rdi), %rdx cmovae %r12, %rax cmovae %r13, %rbx cmovae %r14, %rcx cmovae %r15, %rdx movq %rax, (32)(%rbp) movq %rbx, (40)(%rbp) movq %rcx, (48)(%rbp) movq %rdx, (56)(%rbp) ret mred_short: .quad _mred_5 - mred_short .quad _mred_6 - mred_short .quad _mred_7 - mred_short .quad _mred_8 - mred_short .quad _mred_9 - mred_short .quad _mred_10 - mred_short .quad _mred_11 - mred_short .quad _mred_12 - mred_short .quad _mred_13 - mred_short .quad _mred_14 - mred_short .quad _mred_15 - mred_short .quad _mred_16 - mred_short mred8x_start: .quad _mred8x1_start - mred8x_start .quad _mred8x2_start - mred8x_start .quad _mred8x3_start - mred8x_start .quad _mred8x4_start - mred8x_start .quad _mred8x5_start - mred8x_start .quad _mred8x6_start - mred8x_start .quad _mred8x7_start - mred8x_start .p2align 6, 0x90 _mred_8N: push %r15 sub $(64), %rsp mov %rsp, %rcx mov %rdx, %rbx xor %rax, %rax .LpassLoopgas_97: push %rdi push %rsi push %rdx push %r8 push %rbx push %rax push %rdx mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start pop %rdx xor %rax, %rax mov (64)(%rdi), %rbx add %rbx, %r8 mov (72)(%rdi), %rbx adc %rbx, %r9 mov (80)(%rdi), %rbx adc %rbx, %r10 mov (88)(%rdi), %rbx adc %rbx, %r11 mov (96)(%rdi), %rbx adc %rbx, %r12 mov (104)(%rdi), %rbx adc %rbx, %r13 mov (112)(%rdi), %rbx adc %rbx, %r14 mov (120)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax jmp .LentryInnerLoopgas_97 .LinnerLoopgas_97: push %rdx call _mla_8x8 pop %rdx pop %rax shr $(1), %rax mov (64)(%rdi), %rbx adc %rbx, %r8 mov %r8, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r9 mov %r9, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r10 mov %r10, (80)(%rdi) mov (88)(%rdi), %rbx adc %rbx, %r11 mov %r11, (88)(%rdi) mov (96)(%rdi), %rbx adc %rbx, %r12 mov %r12, (96)(%rdi) mov (104)(%rdi), %rbx adc %rbx, %r13 mov %r13, (104)(%rdi) mov (112)(%rdi), %rbx adc %rbx, %r14 mov %r14, (112)(%rdi) mov (120)(%rdi), %rbx adc %rbx, %r15 mov %r15, (120)(%rdi) adc $(0), %rax push %rax .LentryInnerLoopgas_97: add $(64), %rdi add $(64), %rsi sub $(8), %rdx jg .LinnerLoopgas_97 pop %rax pop %rbx add %rbx, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 adc $(0), %r14 adc $(0), %r15 adc $(0), %rax movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) movq %r14, (48)(%rdi) movq %r15, (56)(%rdi) pop %rbx pop %r8 pop %rdx pop %rsi pop %rdi add $(64), %rdi sub $(8), %rbx jg .LpassLoopgas_97 add $(64), %rsp mov %rdx, %r14 lea (,%rdx,8), %r15 mov %rax, %rbx mov %rsi, %rcx mov %rdi, %rsi pop %rdi call _sub_N sub %rax, %rbx mov %r14, %rdx sub %r15, %rdi sub %r15, %rsi mov %rdi, %rcx shr $(1), %rbx call _copy_ae_N ret .p2align 6, 0x90 _mred_N: push %r15 sub $(64), %rsp mov %rsp, %rcx mov %rdx, %rbx sub $(8), %rbx xor %rax, %rax mov $(7), %r15 and %rdx, %r15 lea mla_8xl_tail(%rip), %rbp mov (-8)(%rbp,%r15,8), %r15 add %r15, %rbp .LpassLoopgas_98: push %rdi push %rsi push %rdx push %r8 push %rbx push %rax push %rbp sub $(8), %rdx push %rdx mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 call _mred8x8_start pop %rdx xor %rax, %rax push %rax jmp .LentryInnerLoopgas_98 .LinnerLoopgas_98: push %rdx call _mla_8x8 pop %rdx .LentryInnerLoopgas_98: pop %rax shr $(1), %rax mov (64)(%rdi), %rbx adc %rbx, %r8 mov %r8, (64)(%rdi) mov (72)(%rdi), %rbx adc %rbx, %r9 mov %r9, (72)(%rdi) mov (80)(%rdi), %rbx adc %rbx, %r10 mov %r10, (80)(%rdi) mov (88)(%rdi), %rbx adc %rbx, %r11 mov %r11, (88)(%rdi) mov (96)(%rdi), %rbx adc %rbx, %r12 mov %r12, (96)(%rdi) mov (104)(%rdi), %rbx adc %rbx, %r13 mov %r13, (104)(%rdi) mov (112)(%rdi), %rbx adc %rbx, %r14 mov %r14, (112)(%rdi) mov (120)(%rdi), %rbx adc %rbx, %r15 mov %r15, (120)(%rdi) adc $(0), %rax push %rax add $(64), %rdi add $(64), %rsi sub $(8), %rdx jnc .LinnerLoopgas_98 add $(8), %rdx jz .Lcomplete_regular_passgas_98 mov (8)(%rsp), %rax xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx push %rdx call *%rax pop %rdx xor %rsi, %rcx xor %rcx, %rsi xor %rsi, %rcx lea (%rdi,%rdx,8), %rdi pop %rax shr $(1), %rax mov %rdx, %rbx dec %rbx jz .Lmt_1gas_98 dec %rbx jz .Lmt_2gas_98 dec %rbx jz .Lmt_3gas_98 dec %rbx jz .Lmt_4gas_98 dec %rbx jz .Lmt_5gas_98 dec %rbx jz .Lmt_6gas_98 .Lmt_7gas_98: mov (8)(%rdi), %rbx adc %rbx, %r9 .Lmt_6gas_98: mov (16)(%rdi), %rbx adc %rbx, %r10 .Lmt_5gas_98: mov (24)(%rdi), %rbx adc %rbx, %r11 .Lmt_4gas_98: mov (32)(%rdi), %rbx adc %rbx, %r12 .Lmt_3gas_98: mov (40)(%rdi), %rbx adc %rbx, %r13 .Lmt_2gas_98: mov (48)(%rdi), %rbx adc %rbx, %r14 .Lmt_1gas_98: mov (56)(%rdi), %rbx adc %rbx, %r15 adc $(0), %rax push %rax .Lcomplete_regular_passgas_98: pop %rax pop %rbp pop %rbx add %rbx, %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 adc $(0), %r14 adc $(0), %r15 adc $(0), %rax movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %r12, (32)(%rdi) movq %r13, (40)(%rdi) movq %r14, (48)(%rdi) movq %r15, (56)(%rdi) pop %rbx pop %r8 pop %rdx pop %rsi pop %rdi add $(64), %rdi sub $(8), %rbx jnc .LpassLoopgas_98 add $(8), %rbx jz .Lcomplete_reductiongas_98 push %rdi push %rsi push %rdx push %r8 push %rbx push %rax push %rbp sub $(8), %rdx push %rdx mov %r8, %rdx movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 lea mred8x_start(%rip), %rax mov (-8)(%rax,%rbx,8), %rbp add %rbp, %rax call *%rax pop %rdx xor %rax, %rax push %rax jmp .LentryTailLoopgas_98 .LtailLoopgas_98: movq (%rdi), %r8 movq (8)(%rdi), %r9 movq (16)(%rdi), %r10 movq (24)(%rdi), %r11 movq (32)(%rdi), %r12 movq (40)(%rdi), %r13 movq (48)(%rdi), %r14 movq (56)(%rdi), %r15 mov (8)(%rsp), %rax push %rdx call *%rax pop %rdx .LentryTailLoopgas_98: pop %rax shr $(1), %rax adc $(0), %r8 adc $(0), %r9 adc $(0), %r10 adc $(0), %r11 adc $(0), %r12 adc $(0), %r13 adc $(0), %r14 adc $(0), %r15 adc $(0), %rax mov (16)(%rsp), %rbx cmp $(1), %rbx jz .Ltt_1gas_98 cmp $(2), %rbx jz .Ltt_2gas_98 cmp $(3), %rbx jz .Ltt_3gas_98 cmp $(4), %rbx jz .Ltt_4gas_98 cmp $(5), %rbx jz .Ltt_5gas_98 cmp $(6), %rbx jz .Ltt_6gas_98 .Ltt_7gas_98: mov (8)(%rdi,%rbx,8), %rbp adc %rbp, %r9 .Ltt_6gas_98: mov (16)(%rdi,%rbx,8), %rbp adc %rbp, %r10 .Ltt_5gas_98: mov (24)(%rdi,%rbx,8), %rbp adc %rbp, %r11 .Ltt_4gas_98: mov (32)(%rdi,%rbx,8), %rbp adc %rbp, %r12 .Ltt_3gas_98: mov (40)(%rdi,%rbx,8), %rbp adc %rbp, %r13 .Ltt_2gas_98: mov (48)(%rdi,%rbx,8), %rbp adc %rbp, %r14 .Ltt_1gas_98: mov (56)(%rdi,%rbx,8), %rbp adc %rbp, %r15 adc $(0), %rax push %rax movq %r8, (%rdi,%rbx,8) movq %r9, (8)(%rdi,%rbx,8) movq %r10, (16)(%rdi,%rbx,8) movq %r11, (24)(%rdi,%rbx,8) movq %r12, (32)(%rdi,%rbx,8) movq %r13, (40)(%rdi,%rbx,8) movq %r14, (48)(%rdi,%rbx,8) movq %r15, (56)(%rdi,%rbx,8) add $(64), %rsi add $(64), %rdi sub $(8), %rdx jnc .LtailLoopgas_98 add $(8), %rdx mov %rdx, %rbx movq (%rdi), %r8 dec %rbx jz .Lget_tail_procgas_98 movq (8)(%rdi), %r9 dec %rbx jz .Lget_tail_procgas_98 movq (16)(%rdi), %r10 dec %rbx jz .Lget_tail_procgas_98 movq (24)(%rdi), %r11 dec %rbx jz .Lget_tail_procgas_98 movq (32)(%rdi), %r12 dec %rbx jz .Lget_tail_procgas_98 movq (40)(%rdi), %r13 dec %rbx jz .Lget_tail_procgas_98 movq (48)(%rdi), %r14 .Lget_tail_procgas_98: lea mla_lxl_short(%rip), %rax mov (-8)(%rax,%rdx,8), %rbp add %rbp, %rax push %rdx call *%rax pop %rdx lea (%rdi,%rdx,8), %rdi pop %rax shr $(1), %rax mov %rdx, %rbx mov (%rdi), %rbp adc %rbp, %r8 dec %rbx jz .Ladd_carry1gas_98 mov (8)(%rdi), %rbp adc %rbp, %r9 dec %rbx jz .Ladd_carry1gas_98 mov (16)(%rdi), %rbp adc %rbp, %r10 dec %rbx jz .Ladd_carry1gas_98 mov (24)(%rdi), %rbp adc %rbp, %r11 dec %rbx jz .Ladd_carry1gas_98 mov (32)(%rdi), %rbp adc %rbp, %r12 dec %rbx jz .Ladd_carry1gas_98 mov (40)(%rdi), %rbp adc %rbp, %r13 dec %rbx jz .Ladd_carry1gas_98 mov (48)(%rdi), %rbp adc %rbp, %r14 .Ladd_carry1gas_98: adc $(0), %rax pop %rbp pop %rbx add %rbx, %r8 movq %r8, (%rdi) dec %rdx jz .Ladd_carry2gas_98 adc $(0), %r9 movq %r9, (8)(%rdi) dec %rdx jz .Ladd_carry2gas_98 adc $(0), %r10 movq %r10, (16)(%rdi) dec %rdx jz .Ladd_carry2gas_98 adc $(0), %r11 movq %r11, (24)(%rdi) dec %rdx jz .Ladd_carry2gas_98 adc $(0), %r12 movq %r12, (32)(%rdi) dec %rdx jz .Ladd_carry2gas_98 adc $(0), %r13 movq %r13, (40)(%rdi) dec %rdx jz .Ladd_carry2gas_98 adc $(0), %r14 movq %r14, (48)(%rdi) .Ladd_carry2gas_98: adc $(0), %rax pop %rbx pop %r8 pop %rdx pop %rsi pop %rdi lea (%rdi,%rbx,8), %rdi .Lcomplete_reductiongas_98: add $(64), %rsp mov %rdx, %r14 lea (,%rdx,8), %r15 mov %rax, %rbx mov %rsi, %rcx mov %rdi, %rsi pop %rdi call _sub_N sub %rax, %rbx mov %r14, %rdx sub %r15, %rdi sub %r15, %rsi mov %rdi, %rcx shr $(1), %rbx call _copy_ae_N ret .p2align 6, 0x90 .globl _cpMulAdc_BNU_school _cpMulAdc_BNU_school: push %rbx push %rbp push %r12 push %r13 push %r14 push %r15 movslq %edx, %rdx movslq %r8d, %rbx xor %r8, %r8 xor %r9, %r9 xor %r10, %r10 xor %r11, %r11 xor %r12, %r12 xor %r13, %r13 xor %r14, %r14 xor %r15, %r15 cmp %rbx, %rdx jl .Lswap_operansgas_99 jg .Ltest_8N_casegas_99 cmp $(16), %rdx jg .Ltest_8N_casegas_99 cmp $(4), %rdx jg .Lmore_then_4gas_99 cmp $(3), %edx ja .Lmul_4_4gas_99 jz .Lmul_3_3gas_99 jp .Lmul_2_2gas_99 .Lmul_1_1gas_99: mov (%rcx), %rdx mulx (%rsi), %rbp, %r8 mov %rbp, (%rdi) movq %r8, (8)(%rdi) jmp .Lquitgas_99 .Lmul_2_2gas_99: mov (%rcx), %rdx mulx (%rsi), %rbp, %r8 mov %rbp, (%rdi) mulx (8)(%rsi), %rbx, %r9 add %rbx, %r8 adc $(0), %r9 mov (8)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (8)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mov %rbp, %r9 movq %r8, (16)(%rdi) movq %r9, (24)(%rdi) jmp .Lquitgas_99 .Lmul_3_3gas_99: mov (%rcx), %rdx mulx (%rsi), %rbp, %r8 mov %rbp, (%rdi) mulx (8)(%rsi), %rbx, %r9 add %rbx, %r8 mulx (16)(%rsi), %rbp, %r10 adc %rbp, %r9 adc $(0), %r10 mov (8)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (8)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mov %rbx, %r10 mov (16)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (16)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mov %rbx, %r10 movq %r8, (24)(%rdi) movq %r9, (32)(%rdi) movq %r10, (40)(%rdi) jmp .Lquitgas_99 .Lmul_4_4gas_99: mov (%rcx), %rdx mulx (%rsi), %rbp, %r8 mov %rbp, (%rdi) mulx (8)(%rsi), %rbx, %r9 add %rbx, %r8 mulx (16)(%rsi), %rbp, %r10 adc %rbp, %r9 mulx (24)(%rsi), %rbx, %r11 adc %rbx, %r10 adc $(0), %r11 mov (8)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (8)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mov %rbp, %r11 mov (16)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (16)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mov %rbp, %r11 mov (24)(%rcx), %rdx mulx (%rsi), %rax, %rbx add %r8, %rax adc $(0), %rbx mov %rax, (24)(%rdi) mulx (8)(%rsi), %r8, %rbp add %r9, %r8 adc $(0), %rbp add %rbx, %r8 adc $(0), %rbp mulx (16)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (24)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mov %rbp, %r11 movq %r8, (32)(%rdi) movq %r9, (40)(%rdi) movq %r10, (48)(%rdi) movq %r11, (56)(%rdi) jmp .Lquitgas_99 .Lmore_then_4gas_99: lea mul_lxl_basic(%rip), %rax mov (-8)(%rax,%rdx,8), %rbp add %rbp, %rax call *%rax jmp .Lquitgas_99 .Lswap_operansgas_99: xor %rcx, %rsi xor %rsi, %rcx xor %rcx, %rsi xor %rbx, %rdx xor %rdx, %rbx xor %rbx, %rdx .Ltest_8N_casegas_99: mov %rdx, %rax or %rbx, %rax and $(7), %rax jnz .Lgeneral_mulgas_99 call _mul_8Nx8M jmp .Lquitgas_99 .Lgeneral_mulgas_99: call _mul_NxM jmp .Lquitgas_99 .Lquitgas_99: vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp pop %rbx ret .p2align 6, 0x90 .globl _cpSqrAdc_BNU_school _cpSqrAdc_BNU_school: push %rbx push %rbp push %r12 push %r13 push %r14 push %r15 movslq %edx, %rdx xor %r8, %r8 xor %r9, %r9 xor %r10, %r10 xor %r11, %r11 xor %r12, %r12 xor %r13, %r13 xor %r14, %r14 xor %r15, %r15 cmp $(16), %rdx jg .Ltest_8N_casegas_100 lea sqr_l_basic(%rip), %rax mov (-8)(%rax,%rdx,8), %rbp add %rbp, %rax call *%rax jmp .Lquitgas_100 .Ltest_8N_casegas_100: test $(7), %rdx jnz .Lgeneral_sqrgas_100 call _sqr_8N jmp .Lquitgas_100 .Lgeneral_sqrgas_100: call _sqr_N .Lquitgas_100: vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp pop %rbx ret .p2align 6, 0x90 .globl _cpMontRedAdc_BNU _cpMontRedAdc_BNU: push %rbx push %rbp push %r12 push %r13 push %r14 push %r15 mov %rdi, %r15 mov %rsi, %rdi mov %rdx, %rsi movslq %ecx, %rdx cmp $(16), %rdx ja .Ltest_8N_casegas_101 cmp $(4), %rdx ja .Labove4gas_101 cmp $(3), %rdx ja .Lred_4gas_101 jz .Lred_3gas_101 jp .Lred_2gas_101 .Lred_1gas_101: movq (%rdi), %r9 mov %r8, %rdx imul %r9, %rdx mulx (%rsi), %rax, %rbp add %r9, %rax adc $(0), %rbp mov %rbp, %r9 xor %rbx, %rbx addq (8)(%rdi), %r9 movq %r9, (8)(%rdi) adc $(0), %rbx subq (%rsi), %r9 sbb $(0), %rbx movq (8)(%rdi), %rax cmovae %r9, %rax movq %rax, (%r15) jmp .Lquitgas_101 .Lred_2gas_101: movq (%rdi), %r9 movq (8)(%rdi), %r10 mov %r8, %rdx imul %r9, %rdx mulx (%rsi), %rax, %rbp add %r9, %rax adc $(0), %rbp mulx (8)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mov %rbx, %r10 mov %r8, %rdx imul %r9, %rdx mulx (%rsi), %rax, %rbp add %r9, %rax adc $(0), %rbp mulx (8)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mov %rbx, %r10 xor %rbx, %rbx addq (16)(%rdi), %r9 movq %r9, (16)(%rdi) adcq (24)(%rdi), %r10 movq %r10, (24)(%rdi) adc $(0), %rbx subq (%rsi), %r9 sbbq (8)(%rsi), %r10 sbb $(0), %rbx movq (16)(%rdi), %rax cmovae %r9, %rax movq %rax, (%r15) movq (24)(%rdi), %rax cmovae %r10, %rax movq %rax, (8)(%r15) jmp .Lquitgas_101 .Lred_3gas_101: movq (%rdi), %r9 movq (8)(%rdi), %r10 movq (16)(%rdi), %r11 mov %r8, %rdx imul %r9, %rdx mulx (%rsi), %rax, %rbp add %r9, %rax adc $(0), %rbp mulx (8)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (16)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mov %rbp, %r11 mov %r8, %rdx imul %r9, %rdx mulx (%rsi), %rax, %rbp add %r9, %rax adc $(0), %rbp mulx (8)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (16)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mov %rbp, %r11 mov %r8, %rdx imul %r9, %rdx mulx (%rsi), %rax, %rbp add %r9, %rax adc $(0), %rbp mulx (8)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (16)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mov %rbp, %r11 xor %rbx, %rbx addq (24)(%rdi), %r9 movq %r9, (24)(%rdi) adcq (32)(%rdi), %r10 movq %r10, (32)(%rdi) adcq (40)(%rdi), %r11 movq %r11, (40)(%rdi) adc $(0), %rbx subq (%rsi), %r9 sbbq (8)(%rsi), %r10 sbbq (16)(%rsi), %r11 sbb $(0), %rbx movq (24)(%rdi), %rax cmovae %r9, %rax movq %rax, (%r15) movq (32)(%rdi), %rax cmovae %r10, %rax movq %rax, (8)(%r15) movq (40)(%rdi), %rax cmovae %r11, %rax movq %rax, (16)(%r15) jmp .Lquitgas_101 .Lred_4gas_101: movq (%rdi), %r9 movq (8)(%rdi), %r10 movq (16)(%rdi), %r11 movq (24)(%rdi), %r12 mov %r8, %rdx imul %r9, %rdx mulx (%rsi), %rax, %rbp add %r9, %rax adc $(0), %rbp mulx (8)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (16)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (24)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mov %rbx, %r12 mov %r8, %rdx imul %r9, %rdx mulx (%rsi), %rax, %rbp add %r9, %rax adc $(0), %rbp mulx (8)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (16)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (24)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mov %rbx, %r12 mov %r8, %rdx imul %r9, %rdx mulx (%rsi), %rax, %rbp add %r9, %rax adc $(0), %rbp mulx (8)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (16)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (24)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mov %rbx, %r12 mov %r8, %rdx imul %r9, %rdx mulx (%rsi), %rax, %rbp add %r9, %rax adc $(0), %rbp mulx (8)(%rsi), %r9, %rbx add %r10, %r9 adc $(0), %rbx add %rbp, %r9 adc $(0), %rbx mulx (16)(%rsi), %r10, %rbp add %r11, %r10 adc $(0), %rbp add %rbx, %r10 adc $(0), %rbp mulx (24)(%rsi), %r11, %rbx add %r12, %r11 adc $(0), %rbx add %rbp, %r11 adc $(0), %rbx mov %rbx, %r12 xor %rbx, %rbx addq (32)(%rdi), %r9 movq %r9, (32)(%rdi) adcq (40)(%rdi), %r10 movq %r10, (40)(%rdi) adcq (48)(%rdi), %r11 movq %r11, (48)(%rdi) adcq (56)(%rdi), %r12 movq %r12, (56)(%rdi) adc $(0), %rbx subq (%rsi), %r9 sbbq (8)(%rsi), %r10 sbbq (16)(%rsi), %r11 sbbq (24)(%rsi), %r12 sbb $(0), %rbx movq (32)(%rdi), %rax cmovae %r9, %rax movq %rax, (%r15) movq (40)(%rdi), %rax cmovae %r10, %rax movq %rax, (8)(%r15) movq (48)(%rdi), %rax cmovae %r11, %rax movq %rax, (16)(%r15) movq (56)(%rdi), %rax cmovae %r12, %rax movq %rax, (24)(%r15) jmp .Lquitgas_101 .Labove4gas_101: mov %rdx, %rbp sub $(4), %rbp lea mred_short(%rip), %rax mov (-8)(%rax,%rbp,8), %rbp add %rbp, %rax call *%rax jmp .Lquitgas_101 .Ltest_8N_casegas_101: test $(7), %rdx jnz .Lgeneral_casegas_101 call _mred_8N jmp .Lquitgas_101 .Lgeneral_casegas_101: call _mred_N .Lquitgas_101: vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp pop %rbx ret
//----------------------------------*-C++-*----------------------------------// // Copyright 2021 UT-Battelle, LLC, and other Celeritas developers. // See the top-level COPYRIGHT file for details. // SPDX-License-Identifier: (Apache-2.0 OR MIT) //---------------------------------------------------------------------------// //! \file CutoffView.hh //---------------------------------------------------------------------------// #pragma once #include "CutoffInterface.hh" namespace celeritas { //---------------------------------------------------------------------------// /*! * Access invariant material- and particle-dependent cutoff values. * * \c CutoffParamsData is defined in \c CutoffInterface and constructed by * \c CutoffParams . * * \code * CutoffParams cutoffs(input); * CutoffView cutoff_view(cutoffs.host_pointers(), material_id); * cutoff_view.energy(particle_id); * cutoff_view.range(particle_id); * \endcode */ class CutoffView { public: //!@{ //! Type aliases using CutoffId = OpaqueId<ParticleCutoff>; using CutoffPointers = CutoffParamsData<Ownership::const_reference, MemSpace::native>; using Energy = units::MevEnergy; //!@} public: // Construct for the given particle and material ids inline CELER_FUNCTION CutoffView(const CutoffPointers& params, MaterialId material); //! Return energy cutoff value inline CELER_FUNCTION Energy energy(ParticleId particle) const; //! Return range cutoff value inline CELER_FUNCTION real_type range(ParticleId particle) const; private: const CutoffPointers& params_; MaterialId material_; }; //---------------------------------------------------------------------------// } // namespace celeritas #include "CutoffView.i.hh"
; A270788: Unique fixed point of the 3-symbol Fibonacci morphism phi-hat_2. ; 1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,3,1,2,1,2,3,1 add $0,2 cal $0,242082 ; Nim sequence of game on n counters whose legal moves are removing some number of counters in A027941. mov $1,$0 add $1,1
; A051336: Number of arithmetic progressions in {1,2,3,...,n}, including trivial arithmetic progressions of lengths 1 and 2. ; 1,3,7,13,22,33,48,65,86,110,138,168,204,242,284,330,381,434,493,554,621,692,767,844,929,1017,1109,1205,1307,1411,1523,1637,1757,1881,2009,2141,2282,2425,2572,2723,2882,3043,3212,3383,3560,3743,3930,4119,4318,4520,4728,4940,5158,5378,5606,5838,6078,6322,6570,6820,7082,7346,7614,7888,8169,8454,8747,9042,9343,9648,9961,10276,10603,10932,11265,11604,11949,12298,12655,13014,13383,13757,14135,14515,14907,15303,15703,16107,16519,16933,17359,17789,18225,18665,19109,19557,20017,20479,20947,21421 mov $1,1 mov $2,$0 lpb $2 add $3,1 mov $4,$2 lpb $4 add $1,$4 trn $4,$3 lpe add $1,1 sub $2,1 lpe mov $0,$1
; A208283: Number of n X 4 0..1 arrays avoiding 0 0 0 and 0 0 1 horizontally and 0 0 1 and 1 1 0 vertically. ; 10,100,378,984,2090,3900,6650,10608,16074,23380,32890,45000,60138,78764,101370,128480,160650,198468,242554,293560,352170,419100,495098,580944,677450,785460,905850,1039528,1187434,1350540,1529850,1726400,1941258 mov $2,$0 mov $3,$0 add $0,4 bin $0,3 sub $0,1 mul $2,$0 mov $4,$0 sub $4,1 mov $5,2 add $5,$2 mov $8,$2 add $8,$5 lpb $0 mov $0,1 mov $1,$8 add $8,$4 add $1,$8 mul $1,2 lpe sub $1,2 mov $6,$3 mul $6,2 add $1,$6 mov $7,$3 mul $7,$3 add $1,$7 mul $7,$3 mov $6,$7 mul $6,3 add $1,$6
lda {m2} sta $fe lda {m2}+1 sta $ff lda ($fe),y sta {m1} lda #0 sta {m1}+1
; Copyright (c) 2015, Thierry Tremblay ; All rights reserved. ; ; Redistribution and use in source and binary forms, with or without ; modification, are permitted provided that the following conditions are met: ; ; * Redistributions of source code must retain the above copyright notice, this ; list of conditions and the following disclaimer. ; ; * Redistributions in binary form must reproduce the above copyright notice, ; this list of conditions and the following disclaimer in the documentation ; and/or other materials provided with the distribution. ; ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE ; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. global _start_kernel global _BootPageDirectory global _BootPageTable global cpu_halt extern kernel_early extern kernel_main extern _BootStackTop PAGE_WRITE equ 0x02 PAGE_PRESENT equ 0x01 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Start the kernel ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; [bits 32] section .boot _start_kernel: ; Initialize the page directory (4 MB per entry) mov edi, _BootPageDirectory - KERNEL_VIRTUAL_BASE mov eax, (_BootPageTable - KERNEL_VIRTUAL_BASE) + PAGE_WRITE + PAGE_PRESENT mov [edi], eax ; Identity map the first 4 MB mov [edi + (KERNEL_VIRTUAL_BASE >> 22) * 4], eax ; Map the same 4 MB to high memory ; Initialize the page table mov edi, _BootPageTable - KERNEL_VIRTUAL_BASE mov eax, 0x00000000 | PAGE_WRITE | PAGE_PRESENT ; Start at physical address 0 mov ecx, 1024 ; 1024 entries .fill_page_table: mov [edi], eax add eax, 0x1000 add edi, 4 loop .fill_page_table ; Load Page Directory Base Register. mov eax, _BootPageDirectory - KERNEL_VIRTUAL_BASE mov cr3, eax ; Enable paging mov eax, cr0 bts eax, 31 mov cr0, eax ; Jump to high memory using an absolute jump mov ecx, enter_higher_half jmp ecx ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; High Memory Entry Point ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; section .text align 4 enter_higher_half: ; Initialize stack mov esp, _BootStackTop ; Kernel early initialization call kernel_early or eax,eax jnz cpu_halt ; Transfer control to kernel call kernel_main ; Hang if kernel unexpectedly returns. cpu_halt: cli .hangloop: hlt jmp .hangloop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Page Mapping Tables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; section .bss nobits align 0x1000 _BootPageDirectory: resb 0x1000 _BootPageTable: resb 0x1000
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #include "tensorflow/core/common_runtime/function.h" #include <deque> #include <vector> #include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/executor.h" #include "tensorflow/core/common_runtime/executor_factory.h" #include "tensorflow/core/common_runtime/graph_optimizer.h" #include "tensorflow/core/common_runtime/memory_types.h" #include "tensorflow/core/common_runtime/rendezvous_mgr.h" #include "tensorflow/core/framework/collective.h" #include "tensorflow/core/framework/function.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/versions.pb.h" #include "tensorflow/core/graph/algorithm.h" #include "tensorflow/core/graph/control_flow.h" #include "tensorflow/core/graph/gradients.h" #include "tensorflow/core/graph/graph_constructor.h" #include "tensorflow/core/graph/node_builder.h" #include "tensorflow/core/graph/optimizer_cse.h" #include "tensorflow/core/lib/core/threadpool.h" #include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/platform/macros.h" // See core/kernels/function_ops.cc for related kernels. namespace tensorflow { // A few string constant used throughout this module. static constexpr const char* const kArgOp = FunctionLibraryDefinition::kArgOp; static constexpr const char* const kDeviceArgOp = FunctionLibraryDefinition::kDeviceArgOp; static constexpr const char* const kRetOp = FunctionLibraryDefinition::kRetOp; static constexpr const char* const kDeviceRetOp = FunctionLibraryDefinition::kDeviceRetOp; static constexpr const char* const kGradientOp = FunctionLibraryDefinition::kGradientOp; static constexpr const char* const kNodeLabel = "Func"; static constexpr const char* const kFuncAttr = FunctionLibraryDefinition::kFuncAttr; // Represents the index-th output of a node. struct Endpoint { Node* node; int index; // Returns the string name represents this endpoint. string name() const { if (index == 0) { return node->name(); } else { return strings::StrCat(node->name(), ":", index); } } DataType dtype() const { return node->output_type(index); } }; struct EndpointHash { uint64 operator()(const Endpoint& x) const { return Hash64(reinterpret_cast<const char*>(&x.node), sizeof(Node*), x.index); } }; struct EndpointEq { bool operator()(const Endpoint& x, const Endpoint& y) const { return (x.node == y.node) && (x.index == y.index); } }; // The following Add* routines are used to add a few graph nodes while // functions are transformed. static Node* AddNoOp(StringPiece name, Graph* g) { NodeDef ndef; ndef.set_name(g->NewName(absl::StrCat(kNodeLabel, "/", name))); ndef.set_op("NoOp"); Status s; Node* ret = g->AddNode(ndef, &s); TF_CHECK_OK(s); return ret; } static Node* AddIdentity(StringPiece name, Graph* g, Endpoint input) { DCHECK_LT(0, input.dtype()); NodeDef ndef; ndef.set_name(g->NewName(absl::StrCat(kNodeLabel, "/", name))); ndef.set_op("Identity"); // NOTE(skyewm): we explicitly set the device here to address a multi-GPU // performance issue where this Identity would be placed alone on a GPU, // causing unnecessary device traffic. See b/122483225 for details. ndef.set_device(input.node->def().device()); ndef.add_input(input.name()); AddNodeAttr("T", BaseType(input.dtype()), &ndef); Status s; Node* ret = g->AddNode(ndef, &s); TF_CHECK_OK(s); g->AddEdge(input.node, input.index, ret, 0); return ret; } static Node* AddArg(Graph* g, DataType dtype, int index) { DCHECK_LT(0, dtype); DCHECK_LT(dtype, DT_FLOAT_REF); NodeDef ndef; ndef.set_name(g->NewName(kNodeLabel)); ndef.set_op(kArgOp); AddNodeAttr("T", dtype, &ndef); AddNodeAttr("index", index, &ndef); Status s; Node* ret = g->AddNode(ndef, &s); TF_CHECK_OK(s); return ret; } static Node* AddRet(Graph* g, Endpoint input, int index) { DCHECK_LT(0, input.dtype()); DCHECK_LT(input.dtype(), DT_FLOAT_REF); NodeDef ndef; ndef.set_name(g->NewName(kNodeLabel)); ndef.set_op(kRetOp); ndef.add_input(input.name()); AddNodeAttr("T", input.dtype(), &ndef); AddNodeAttr("index", index, &ndef); Status s; Node* ret = g->AddNode(ndef, &s); TF_CHECK_OK(s); g->AddEdge(input.node, input.index, ret, 0); return ret; } // FunctionLibraryRuntime implementation that forwards all the function calls to // the base runtime implementation, and only overrides FunctionLibraryDefinition // in calls to Instantiate (if caller doesn't provide the // InstantiateOptions::lib_def option). // // When the function library runtime (FunctionLibraryRuntimeImpl specifically) // instantiates a function into a Graph object, it also creates an Executor for // it. That executor has a pointer to the function library runtime instance, // that is used to instantiate all nested function calls. // // The function library definition used to instantiate the function must be // preserved in the Executor's function library runtime. // // IMPORTANT: This runtime is intended for use only in executors created for // functions instantiated into a graph in FunctionLibraryRuntimeImpl. class FunctionLibraryRuntimeOverlay : public FunctionLibraryRuntime { public: FunctionLibraryRuntimeOverlay(FunctionLibraryRuntime* base_flr, const FunctionLibraryDefinition* lib_def) : base_flr_(base_flr), lib_def_(lib_def) {} ~FunctionLibraryRuntimeOverlay() override; Status Instantiate(const string& function_name, AttrSlice attrs, const InstantiateOptions& options, Handle* handle) override; Status ReleaseHandle(Handle handle) override; const FunctionBody* GetFunctionBody(Handle h) override; Status GetRetTypes(Handle h, DataTypeVector* ret_types) override; void Run(const Options& opts, Handle handle, gtl::ArraySlice<Tensor> args, std::vector<Tensor>* rets, DoneCallback done) override; void Run(const Options& opts, Handle handle, CallFrameInterface* call_frame, DoneCallback done) override; Status CreateKernel(const NodeDef& ndef, OpKernel** kernel) override; bool IsStateful(const string& function_name) override; const FunctionLibraryDefinition* GetFunctionLibraryDefinition() const override; Env* env() override; Device* device() override; std::function<void(std::function<void()>)>* runner() override; const DeviceMgr* device_mgr() const override; string DebugString(Handle handle) override; int graph_def_version() override; Status Clone(std::unique_ptr<FunctionLibraryDefinition>* out_lib_def, std::unique_ptr<ProcessFunctionLibraryRuntime>* out_pflr, FunctionLibraryRuntime** out_flr) override; private: FunctionLibraryRuntime* base_flr_; // not owned const FunctionLibraryDefinition* lib_def_; // not owned }; FunctionLibraryRuntimeOverlay::~FunctionLibraryRuntimeOverlay() = default; Status FunctionLibraryRuntimeOverlay::Instantiate( const string& function_name, AttrSlice attrs, const InstantiateOptions& options, Handle* handle) { // We automatically set the `lib_def` option for all instantiations, if the // caller doesn't set this option explicitly. if (!options.lib_def && lib_def_) { InstantiateOptions options_copy = options; options_copy.lib_def = lib_def_; return base_flr_->Instantiate(function_name, attrs, options_copy, handle); } else { return base_flr_->Instantiate(function_name, attrs, options, handle); } } Status FunctionLibraryRuntimeOverlay::ReleaseHandle(Handle handle) { return base_flr_->ReleaseHandle(handle); } const FunctionBody* FunctionLibraryRuntimeOverlay::GetFunctionBody(Handle h) { return base_flr_->GetFunctionBody(h); } Status FunctionLibraryRuntimeOverlay::GetRetTypes(Handle h, DataTypeVector* ret_types) { return base_flr_->GetRetTypes(h, ret_types); } void FunctionLibraryRuntimeOverlay::Run(const Options& opts, Handle handle, gtl::ArraySlice<Tensor> args, std::vector<Tensor>* rets, DoneCallback done) { base_flr_->Run(opts, handle, args, rets, std::move(done)); } void FunctionLibraryRuntimeOverlay::Run(const Options& opts, Handle handle, CallFrameInterface* call_frame, DoneCallback done) { base_flr_->Run(opts, handle, call_frame, std::move(done)); } Status FunctionLibraryRuntimeOverlay::CreateKernel(const NodeDef&, OpKernel**) { // We don't have access to base_lib_def_ in base function library runtime (aka // FunctionLibraryRuntimeImpl), so to make sure we do not create a kernel with // the wrong lib_def we just disable creation of new kernels through overlays. // // When we call Instantiate from the base runtime with the lib_def option, // the base runtime implementation is responsible for correctly passing it // through to all kernel constructions. return errors::Internal( "Overlay function library runtime doesn't support kernel creation."); } bool FunctionLibraryRuntimeOverlay::IsStateful(const string& function_name) { // Important: we do not forward lookup to the base FLR. const OpDef* op_def; const Status s = lib_def_->LookUpOpDef(function_name, &op_def); return s.ok() && op_def->is_stateful(); } Env* FunctionLibraryRuntimeOverlay::env() { return base_flr_->env(); } Device* FunctionLibraryRuntimeOverlay::device() { return base_flr_->device(); } std::function<void(std::function<void()>)>* FunctionLibraryRuntimeOverlay::runner() { return base_flr_->runner(); } const DeviceMgr* FunctionLibraryRuntimeOverlay::device_mgr() const { return base_flr_->device_mgr(); } const FunctionLibraryDefinition* FunctionLibraryRuntimeOverlay::GetFunctionLibraryDefinition() const { return lib_def_ ? lib_def_ : base_flr_->GetFunctionLibraryDefinition(); } string FunctionLibraryRuntimeOverlay::DebugString(Handle handle) { return base_flr_->DebugString(handle); } int FunctionLibraryRuntimeOverlay::graph_def_version() { return base_flr_->graph_def_version(); } Status FunctionLibraryRuntimeOverlay::Clone( std::unique_ptr<FunctionLibraryDefinition>* out_lib_def, std::unique_ptr<ProcessFunctionLibraryRuntime>* out_pflr, FunctionLibraryRuntime** out_flr) { // NOTE(ezhulenev): The cloned FunctionLibraryRuntime will be missing the // FunctionLibraryDefinition override, but that's ok because we anyway do not // copy / clone instantiated items from the base FLR. return base_flr_->Clone(out_lib_def, out_pflr, out_flr); } class FunctionLibraryRuntimeImpl : public FunctionLibraryRuntime { public: FunctionLibraryRuntimeImpl(const DeviceMgr* dmgr, Env* env, Device* device, int graph_def_version, const FunctionLibraryDefinition* lib_def, thread::ThreadPool* default_thread_pool, const OptimizerOptions& optimizer_options, CustomKernelCreator custom_kernel_creator, ProcessFunctionLibraryRuntime* parent); ~FunctionLibraryRuntimeImpl() override; Status Instantiate(const string& function_name, AttrSlice attrs, const InstantiateOptions& options, Handle* handle) override; Status ReleaseHandle(Handle handle) override; const FunctionBody* GetFunctionBody(Handle handle) override; Status GetRetTypes(Handle handle, DataTypeVector* ret_types) override; Status CreateKernel(const NodeDef& ndef, OpKernel** kernel) override; void Run(const Options& opts, Handle handle, gtl::ArraySlice<Tensor> args, std::vector<Tensor>* rets, DoneCallback done) override; // NOTE(mrry): This overload is currently only implemented for local function // execution. // TODO(b/70346412): Implement support for remote function execution when // passing a call frame. void Run(const Options& opts, Handle handle, CallFrameInterface* frame, DoneCallback done) override; bool IsStateful(const string& function) override; const FunctionLibraryDefinition* GetFunctionLibraryDefinition() const override { return base_lib_def_; } Device* device() override { return device_; } std::function<void(std::function<void()>)>* runner() override { return &default_runner_; } const DeviceMgr* device_mgr() const override { return device_mgr_; } Env* env() override { return env_; } int graph_def_version() override { return graph_def_version_; } string DebugString(Handle h) override; Status Clone(std::unique_ptr<FunctionLibraryDefinition>* out_lib_def, std::unique_ptr<ProcessFunctionLibraryRuntime>* out_pflr, FunctionLibraryRuntime** out_flr) override; private: typedef FunctionLibraryRuntimeImpl ME; const DeviceMgr* const device_mgr_; Device* const device_; Env* const env_; const int graph_def_version_; const FunctionLibraryDefinition* const base_lib_def_; GraphOptimizer optimizer_; const CustomKernelCreator custom_kernel_creator_; Executor::Args::Runner default_runner_; const string device_name_; std::function<Status(const string&, const OpDef**)> get_func_sig_; std::function<Status(const NodeDef&, OpKernel**)> create_kernel_; mutable mutex mu_; int next_handle_ GUARDED_BY(mu_); // The instantiated and transformed function is encoded as a Graph // object, and an executor is created for the graph. struct Item { uint64 instantiation_counter = 0; const Graph* graph = nullptr; // Owned by exec. const FunctionLibraryDefinition* lib_def = nullptr; // Not owned. FunctionBody* func_graph = nullptr; Executor* exec = nullptr; FunctionLibraryRuntimeOverlay* overlay_flr = nullptr; string executor_type; ~Item() { delete this->func_graph; delete this->exec; delete this->overlay_flr; } }; std::unordered_map<Handle, std::unique_ptr<Item>> items_ GUARDED_BY(mu_); ProcessFunctionLibraryRuntime* parent_ = nullptr; // not owned. Status CreateKernel(const NodeDef& ndef, const FunctionLibraryDefinition* lib_def, OpKernel** kernel); Status FunctionDefToBody(const FunctionDef& fdef, AttrSlice attrs, const FunctionLibraryDefinition* lib_def, std::unique_ptr<FunctionBody>* fbody); Status CreateItem(Item** item); Status GetOrCreateItem(LocalHandle local_handle, Item** item); Status InstantiateSymbolicGradient(const NameAttrList& func, const FunctionLibraryDefinition* lib_def, std::unique_ptr<FunctionBody>* g_body); bool IsLocalTarget(const InstantiateOptions& options); AttrValueMap FixAttrs(const AttrSlice& attrs); void RunRemote(const Options& opts, Handle handle, gtl::ArraySlice<Tensor> args, std::vector<Tensor>* rets, Item* item, DoneCallback done); void ExecutorArgsFromOptions(const FunctionLibraryRuntime::Options& run_opts, CallFrameInterface* frame, Executor::Args* exec_args); TF_DISALLOW_COPY_AND_ASSIGN(FunctionLibraryRuntimeImpl); }; FunctionLibraryRuntimeImpl::FunctionLibraryRuntimeImpl( const DeviceMgr* dmgr, Env* env, Device* device, int graph_def_version, const FunctionLibraryDefinition* lib_def, thread::ThreadPool* default_thread_pool, const OptimizerOptions& optimizer_options, CustomKernelCreator custom_kernel_creator, ProcessFunctionLibraryRuntime* parent) : device_mgr_(dmgr), device_(device), env_(env), graph_def_version_(graph_def_version), base_lib_def_(lib_def), optimizer_(optimizer_options), custom_kernel_creator_(std::move(custom_kernel_creator)), default_runner_(nullptr), device_name_(device_ == nullptr ? ProcessFunctionLibraryRuntime::kDefaultFLRDevice : device_->name()), next_handle_(0), parent_(parent) { get_func_sig_ = [this](const string& op, const OpDef** sig) { return base_lib_def_->LookUpOpDef(op, sig); }; create_kernel_ = [this](const NodeDef& ndef, OpKernel** kernel) { return CreateKernel(ndef, kernel); }; thread::ThreadPool* pool = nullptr; if (device_ != nullptr) { pool = device_->tensorflow_device_thread_pool(); } if (pool == nullptr) { pool = default_thread_pool; } if (pool != nullptr) { default_runner_ = [pool](Executor::Args::Closure c) { pool->Schedule(std::move(c)); }; } } FunctionLibraryRuntimeImpl::~FunctionLibraryRuntimeImpl() {} // An asynchronous op kernel which executes an instantiated function // defined in a library. class CallOp : public AsyncOpKernel { public: CallOp(FunctionLibraryRuntime::Handle handle, OpKernelConstruction* ctx) : AsyncOpKernel(ctx), handle_(handle) {} ~CallOp() override { // TODO(iga): Release the cached handle_ } void ComputeAsync(OpKernelContext* ctx, DoneCallback done) override { FunctionLibraryRuntime* lib = ctx->function_library(); OP_REQUIRES_ASYNC(ctx, lib != nullptr, errors::Internal("No function library is provided."), done); FunctionLibraryRuntime::Options opts; opts.step_id = ctx->step_id(); opts.rendezvous = ctx->rendezvous(); opts.cancellation_manager = ctx->cancellation_manager(); opts.step_container = ctx->step_container(); opts.stats_collector = ctx->stats_collector(); opts.runner = ctx->runner(); opts.collective_executor = ctx->collective_executor(); std::vector<Tensor> args; args.reserve(ctx->num_inputs()); for (int i = 0; i < ctx->num_inputs(); ++i) { args.push_back(ctx->input(i)); } std::vector<Tensor>* rets = new std::vector<Tensor>; lib->Run(opts, handle_, args, rets, [ctx, done, rets](const Status& status) { if (!status.ok()) { ctx->SetStatus(status); } else { const int ret_size = static_cast<int>(rets->size()); CHECK_EQ(ret_size, ctx->num_outputs()); for (int i = 0; i < ret_size; ++i) { ctx->set_output(i, (*rets)[i]); } } delete rets; done(); }); } private: FunctionLibraryRuntime::Handle handle_; TF_DISALLOW_COPY_AND_ASSIGN(CallOp); }; const FunctionBody* FunctionLibraryRuntimeImpl::GetFunctionBody(Handle h) { LocalHandle local_handle = parent_->GetHandleOnDevice(device_name_, h); if (local_handle == kInvalidLocalHandle) { LOG(ERROR) << "Could not find Handle: " << h << " on device: " << device_name_; return nullptr; } tf_shared_lock l(mu_); auto iter = items_.find(local_handle); CHECK(iter != items_.end()); return iter->second->func_graph; } Status FunctionLibraryRuntimeImpl::GetRetTypes(Handle h, DataTypeVector* ret_types) { if (parent_->IsMultiDevice(h)) { return parent_->GetRetTypes(h, ret_types); } LocalHandle local_handle = parent_->GetHandleOnDevice(device_name_, h); if (local_handle == kInvalidLocalHandle) { return errors::InvalidArgument("Handle ", h, " not found."); } const FunctionBody* fbody = GetFunctionBody(h); *ret_types = fbody->ret_types; return Status::OK(); } Status FunctionLibraryRuntimeImpl::CreateKernel(const NodeDef& ndef, OpKernel** kernel) { return CreateKernel(ndef, base_lib_def_, kernel); } Status FunctionLibraryRuntimeImpl::CreateKernel( const NodeDef& ndef, const FunctionLibraryDefinition* lib_def, OpKernel** kernel) { // If a custom kernel creator is given, try that. Status s; if (custom_kernel_creator_) { std::unique_ptr<OpKernel> ret; s = custom_kernel_creator_(this, ndef, &ret); if (s.ok()) { *kernel = ret.release(); return s; } else { VLOG(2) << "Custom creator error: " << s; // Falls through. s = Status::OK(); } } if (lib_def->Find(ndef.op()) == nullptr) { // A primitive operation. Creates the registered kernel. return CreateNonCachedKernel(device_, this, ndef, graph_def_version_, kernel); } // Try to instantiate this function for the func/attr. Maybe it's // cached already. InstantiateOptions options; if (lib_def != base_lib_def_) { options.lib_def = lib_def; } Handle handle; TF_RETURN_IF_ERROR( Instantiate(ndef.op(), AttrSlice(&ndef.attr()), options, &handle)); const FunctionBody* fbody = GetFunctionBody(handle); CHECK_NOTNULL(fbody); // TODO(zhifengc): For now, we assume int32 and resources are always on host // memory and other types are always on device memory. We should do type // inference over function body to derive the correct input/output memory // types. MemoryTypeVector input_memory_types; for (const auto& t : fbody->arg_types) { input_memory_types.push_back(MTypeFromDType(t)); } MemoryTypeVector output_memory_types; for (const auto& t : fbody->ret_types) { output_memory_types.push_back(MTypeFromDType(t)); } // Constructs a CallOp kernel for running the instantiated function. auto device_type = DeviceType(device_->attributes().device_type()); OpKernelConstruction construction( device_type, device_, device_->GetAllocator(AllocatorAttributes()), &ndef, &fbody->fdef.signature(), this, fbody->arg_types, input_memory_types, fbody->ret_types, output_memory_types, graph_def_version_, &s); if (s.ok()) { *kernel = new CallOp(handle, &construction); } return s; } Status FunctionLibraryRuntimeImpl::FunctionDefToBody( const FunctionDef& fdef, AttrSlice attrs, const FunctionLibraryDefinition* lib_def, std::unique_ptr<FunctionBody>* fbody) { if (lib_def == base_lib_def_) { return FunctionDefToBodyHelper(fdef, attrs, lib_def, get_func_sig_, fbody); } else { auto get_func_sig = [lib_def](const string& op, const OpDef** sig) { return lib_def->LookUpOpDef(op, sig); }; return FunctionDefToBodyHelper(fdef, attrs, lib_def, get_func_sig, fbody); } } Status FunctionLibraryRuntimeImpl::InstantiateSymbolicGradient( const NameAttrList& func, const FunctionLibraryDefinition* lib_def, std::unique_ptr<FunctionBody>* g_body) { const FunctionDef* fdef = lib_def->Find(func.name()); if (fdef == nullptr) { // f is a primitive op. gradient::Creator creator; TF_RETURN_IF_ERROR(gradient::GetOpGradientCreator(func.name(), &creator)); if (creator == nullptr) { return errors::InvalidArgument("No gradient is defined for ", func.name()); } FunctionDef grad_fdef; // TODO(josh11b): Should filter out the attrs from func that aren't used // by the gradient function. TF_RETURN_IF_ERROR(creator(AttrSlice(&func.attr()), &grad_fdef)); TF_RETURN_IF_ERROR( FunctionDefToBody(grad_fdef, AttrSlice(&func.attr()), lib_def, g_body)); } else { // f is a user-defined function. InstantiateOptions options; if (lib_def != base_lib_def_) { options.lib_def = lib_def; } Handle f_handle; TF_RETURN_IF_ERROR( Instantiate(func.name(), AttrSlice(&func.attr()), options, &f_handle)); const FunctionBody* f_body = GetFunctionBody(f_handle); CHECK_NOTNULL(f_body); *g_body = SymbolicGradient(*f_body); } return Status::OK(); } bool FunctionLibraryRuntimeImpl::IsLocalTarget( const InstantiateOptions& options) { if (device_ == nullptr) return true; if (options.target.empty()) return true; if (options.is_multi_device_function) return false; Device* target_device; if (!device_mgr_->LookupDevice(options.target, &target_device).ok()) { VLOG(1) << "Not instantiating function in FLR because failed to " << "find device " << options.target << " in device manager"; return false; } if (target_device != device_) { VLOG(1) << "Not instantiating function in FLR because target device " << options.target << " is different from FLR's device: " << device_->DebugString(); return false; } return true; } Status FunctionLibraryRuntimeImpl::Instantiate( const string& function_name, AttrSlice attrs, const InstantiateOptions& options, Handle* handle) { if (!IsLocalTarget(options)) { return parent_->Instantiate(function_name, attrs, options, handle); } // Since this is a local target, ensure that the local `device_name_` appears // in the canonical key. InstantiateOptions options_copy(options); options_copy.target = device_name_; const string key = Canonicalize(function_name, attrs, options_copy); { mutex_lock l(mu_); *handle = parent_->GetHandle(key); if (*handle != kInvalidHandle) { FunctionLibraryRuntime::LocalHandle handle_on_device = parent_->GetHandleOnDevice(device_name_, *handle); if (handle_on_device == kInvalidLocalHandle) { return errors::Internal("LocalHandle not found for handle ", *handle, "."); } auto item_handle = items_.find(handle_on_device); if (item_handle == items_.end()) { return errors::Internal("LocalHandle ", handle_on_device, " for handle ", *handle, " not found in items."); } ++item_handle->second->instantiation_counter; return Status::OK(); } } const FunctionLibraryDefinition* lib_def = options.lib_def ? options.lib_def : base_lib_def_; std::unique_ptr<FunctionBody> fbody; if (function_name == kGradientOp) { const AttrValue* f = attrs.Find(kFuncAttr); if (f == nullptr) { return errors::InvalidArgument("SymbolicGradient is missing attr: f"); } const auto& func = f->func(); if (func.name() == kGradientOp) { return errors::InvalidArgument("Can't take gradient of SymbolicGradient"); } const string grad = lib_def->FindGradient(func.name()); if (!grad.empty()) { return Instantiate(grad, AttrSlice(&func.attr()), options, handle); } TF_RETURN_IF_ERROR(InstantiateSymbolicGradient(func, lib_def, &fbody)); } else { const FunctionDef* fdef = lib_def->Find(function_name); if (fdef == nullptr) { return errors::NotFound("Function ", function_name, " is not defined."); } TF_RETURN_IF_ERROR(FunctionDefToBody(*fdef, attrs, lib_def, &fbody)); } LocalHandle local_handle; { mutex_lock l(mu_); *handle = parent_->GetHandle(key); if (*handle != kInvalidHandle) { local_handle = parent_->GetHandleOnDevice(device_name_, *handle); ++items_[local_handle]->instantiation_counter; } else { *handle = parent_->AddHandle(key, device_name_, next_handle_); Item* item = new Item; item->func_graph = fbody.release(); item->lib_def = options.lib_def; item->instantiation_counter = 1; item->executor_type = ExecutorType(options, attrs); if (options.lib_def) { item->overlay_flr = new FunctionLibraryRuntimeOverlay(this, options.lib_def); } local_handle = next_handle_++; items_.emplace(local_handle, std::unique_ptr<Item>(item)); } } if (options.create_kernels_eagerly) { Item* item; TF_RETURN_IF_ERROR(GetOrCreateItem(local_handle, &item)); } return Status::OK(); } Status FunctionLibraryRuntimeImpl::ReleaseHandle(Handle handle) { LocalHandle h = parent_->GetHandleOnDevice(device_name_, handle); if (h == kInvalidLocalHandle) { return parent_->ReleaseHandle(handle); } std::unique_ptr<Item> item_to_delete; Status parent_status; { mutex_lock l(mu_); auto it = items_.find(h); if (it == items_.end()) { return errors::Internal( "Inconsistent FunctionLibraryRuntime. Expected to find an item for " "handle ", h, " but found none"); } std::unique_ptr<Item>& item = it->second; --item->instantiation_counter; if (item->instantiation_counter == 0) { // We don't simply erase h's item because that would trigger // item destruction while holding mu_. Item destruction can // trigger graph destruction. If the graph contains kernels like // CallOp or PartitionCallOp, their destructors will release cached // function handles, resulting in deadlock here. item_to_delete = std::move(item); items_.erase(h); parent_status = parent_->RemoveHandle(handle); } } return parent_status; } void DumpGraph(StringPiece label, const Graph* g) { // TODO(zhifengc): Change Graph to record #nodes. VLOG(1) << "Graph " << label << " #nodes " << g->num_nodes() << " #edges " << g->num_edges(); if (VLOG_IS_ON(2)) { for (const auto& line : str_util::Split(DebugString(g), '\n')) { VLOG(2) << "|| " << line; } } } void OptimizeGraph(FunctionLibraryRuntime* lib, std::unique_ptr<Graph>* g, const GraphOptimizer::Options& graph_optimizer_options) { OptimizerOptions opts; opts.set_do_common_subexpression_elimination(true); opts.set_do_function_inlining(true); opts.set_do_constant_folding(true); GraphOptimizer optimizer(opts); optimizer.Optimize(lib, lib->env(), lib->device(), g, graph_optimizer_options); } void OptimizeGraph(FunctionLibraryRuntime* lib, std::unique_ptr<Graph>* g) { OptimizeGraph(lib, g, GraphOptimizer::Options()); } namespace { // Removes all stateless nodes that do not contribute to a return // value from the function body. Unlike `RemoveDeadNodes()`, which is // triggered by `OptimizerOptions.do_function_inlining`, this pass // ignores the SINK node, from which (by definition) all nodes are // reverse reachable, and preserves all nodes that are reachable from // control output nodes. // // TODO(ezhulenev, skyewm): Function body should not have special treatment of // stateful ops, graph should encode nodes that must execute with `control_ret` // and `control_output`. void PruneFunctionBody(const FunctionDef& fdef, Graph* g) { VLOG(2) << "Pruning function body: function_name=" << fdef.signature().name(); // `control_ret` nodes must be always executed. std::unordered_set<StringPiece, StringPieceHasher> control_ret_nodes; for (const auto& control_ret : fdef.control_ret()) { control_ret_nodes.insert(control_ret.second); } std::unordered_set<const Node*> nodes; for (auto n : g->nodes()) { // NOTE(mrry): "_Retval" nodes are stateful, and so will be added // to the seed set of `nodes`. "_Arg" nodes are also stateful, but we // specifically exclude them as seeds, to avoid unconditionally executing // unused argument nodes (e.g. in a function like `lambda x, y: y`). // TODO(mrry): Investigate whether the `n->IsControlFlow()` test is // still needed. It would be preferable to prune entire loops and/or // conditionals if they are not used in the graph. if (n->IsControlFlow() || (n->op_def().is_stateful() && n->type_string() != kArgOp) || (control_ret_nodes.find(n->name()) != control_ret_nodes.end())) { nodes.insert(n); } } bool changed = PruneForReverseReachability(g, std::move(nodes)); if (changed) { FixupSourceAndSinkEdges(g); } } } // namespace Status FunctionLibraryRuntimeImpl::CreateItem(Item** item) { const FunctionBody* fbody; const FunctionLibraryDefinition* lib_def; string executor_type; { tf_shared_lock l(mu_); fbody = (*item)->func_graph; lib_def = (*item)->lib_def; executor_type = (*item)->executor_type; } if (!lib_def) { lib_def = base_lib_def_; } std::unique_ptr<Graph> g(new Graph(lib_def)); CopyGraph(*fbody->graph, g.get()); PruneFunctionBody(fbody->fdef, g.get()); optimizer_.Optimize(this, env(), device(), &g, /*shape_map=*/nullptr); TF_RETURN_IF_ERROR(EnsureMemoryTypes(DeviceType(device()->device_type()), device()->name(), g.get())); // Creates an executor based on the g. This must be done without // holding mu_ because create_kernel_ calls back into the library. LocalExecutorParams params; params.device = device_; params.function_library = (*item)->overlay_flr ? static_cast<FunctionLibraryRuntime*>((*item)->overlay_flr) : static_cast<FunctionLibraryRuntime*>(this); if (lib_def == base_lib_def_) { params.create_kernel = create_kernel_; } else { params.create_kernel = [this, lib_def](const NodeDef& ndef, OpKernel** kernel) { return CreateKernel(ndef, lib_def, kernel); }; } params.delete_kernel = [](OpKernel* kernel) { DeleteNonCachedKernel(kernel); }; Graph* graph = g.get(); std::unique_ptr<Executor> exec; TF_RETURN_IF_ERROR(NewExecutor(executor_type, params, std::move(g), &exec)); { // Guard item since it is already inserted in items_. mutex_lock l(mu_); if ((*item)->exec == nullptr) { (*item)->graph = graph; (*item)->exec = exec.release(); } } return Status::OK(); } Status FunctionLibraryRuntimeImpl::GetOrCreateItem(LocalHandle local_handle, Item** item) { { tf_shared_lock l(mu_); auto iter = items_.find(local_handle); if (iter == items_.end()) { return errors::Internal("Local function handle ", local_handle, " is not valid. Likely an internal error."); } *item = iter->second.get(); if ((*item)->exec != nullptr) { return Status::OK(); } } // NOTE: We need to call CreateItem out of mu_ because creating an // executor needs to call CreateKernel. return CreateItem(item); } void FunctionLibraryRuntimeImpl::ExecutorArgsFromOptions( const FunctionLibraryRuntime::Options& run_opts, CallFrameInterface* frame, Executor::Args* exec_args) { // Inherit the step_id from the caller. exec_args->step_id = run_opts.step_id; exec_args->rendezvous = run_opts.rendezvous; exec_args->stats_collector = run_opts.stats_collector; exec_args->cancellation_manager = run_opts.cancellation_manager; exec_args->step_container = run_opts.step_container; if (run_opts.runner) { exec_args->runner = *run_opts.runner; } else { exec_args->runner = default_runner_; } exec_args->collective_executor = run_opts.collective_executor; exec_args->call_frame = frame; } void FunctionLibraryRuntimeImpl::RunRemote(const Options& opts, Handle handle, gtl::ArraySlice<Tensor> args, std::vector<Tensor>* rets, Item* item, DoneCallback done) { string target_device = parent_->GetDeviceName(handle); string source_device = opts.source_device; Rendezvous* rendezvous = opts.rendezvous; DeviceContext* device_context; Status s = parent_->GetDeviceContext(target_device, &device_context); if (!s.ok()) { done(s); return; } int64 src_incarnation, target_incarnation; s = parent_->GetDeviceIncarnation(source_device, &src_incarnation); s.Update(parent_->GetDeviceIncarnation(target_device, &target_incarnation)); if (!s.ok()) { done(s); return; } const FunctionBody* fbody = GetFunctionBody(handle); FunctionCallFrame* frame = new FunctionCallFrame(fbody->arg_types, fbody->ret_types); Executor::Args* exec_args = new Executor::Args; ExecutorArgsFromOptions(opts, frame, exec_args); std::vector<AllocatorAttributes> args_alloc_attrs, rets_alloc_attrs; args_alloc_attrs.reserve(fbody->arg_types.size()); rets_alloc_attrs.reserve(fbody->ret_types.size()); // Note: Functions assume that int32's are always on host memory. for (const auto& arg_type : fbody->arg_types) { AllocatorAttributes arg_alloc_attrs; if (MTypeFromDType(arg_type) == HOST_MEMORY) { arg_alloc_attrs.set_on_host(true); } args_alloc_attrs.push_back(arg_alloc_attrs); } for (const auto& ret_type : fbody->ret_types) { AllocatorAttributes ret_alloc_attrs; if (MTypeFromDType(ret_type) == HOST_MEMORY) { ret_alloc_attrs.set_on_host(true); } rets_alloc_attrs.push_back(ret_alloc_attrs); } bool allow_dead_tensors = opts.allow_dead_tensors; // The ProcFLR sends the arguments to the function from the source_device to // the target_device. So here we receive those arguments. Similarly, when the // computation is done and stored in *rets, we send the return values back // to the source_device (caller) so that the ProcFLR can receive them later. std::vector<Tensor>* remote_args = new std::vector<Tensor>; ProcessFunctionLibraryRuntime::ReceiveTensorsAsync( source_device, target_device, "arg_", src_incarnation, args.size(), device_context, args_alloc_attrs, rendezvous, remote_args, [frame, remote_args, item, source_device, target_device, target_incarnation, rendezvous, device_context, rets, done, exec_args, rets_alloc_attrs, allow_dead_tensors](const Status& status) { Status s = status; if (s.ok()) { s = frame->SetArgs(*remote_args); } if (!s.ok()) { delete frame; delete remote_args; delete exec_args; done(s); return; } item->exec->RunAsync( *exec_args, [frame, rets, done, source_device, target_device, target_incarnation, rendezvous, device_context, remote_args, rets_alloc_attrs, allow_dead_tensors](const Status& status) { Status s = status; if (s.ok()) { s = frame->ConsumeRetvals(rets, allow_dead_tensors); } delete frame; if (!s.ok()) { delete remote_args; done(s); return; } s = ProcessFunctionLibraryRuntime::SendTensors( target_device, source_device, "ret_", target_incarnation, *rets, device_context, rets_alloc_attrs, rendezvous); delete remote_args; done(s); }); delete exec_args; }); } void FunctionLibraryRuntimeImpl::Run(const Options& opts, Handle handle, gtl::ArraySlice<Tensor> args, std::vector<Tensor>* rets, DoneCallback done) { if (opts.cancellation_manager && opts.cancellation_manager->IsCancelled()) { done(errors::Cancelled("")); return; } Options run_opts = opts; if (opts.create_rendezvous) { Rendezvous* rendezvous = new IntraProcessRendezvous(device_mgr_); run_opts.rendezvous = rendezvous; run_opts.create_rendezvous = false; done = [done, rendezvous](const Status& status) { rendezvous->Unref(); done(status); }; } LocalHandle local_handle = parent_->GetHandleOnDevice(device_name_, handle); if (local_handle == kInvalidLocalHandle) { parent_->Run(run_opts, handle, args, rets, done); return; } if (run_opts.runner == nullptr) { run_opts.runner = &default_runner_; } DCHECK(run_opts.runner != nullptr); Item* item = nullptr; Status s = GetOrCreateItem(local_handle, &item); if (!s.ok()) { done(s); return; } if (run_opts.remote_execution) { // NOTE(mrry): `RunRemote()` will set `exec_args->call_frame` for us. RunRemote(run_opts, handle, args, rets, item, done); return; } const FunctionBody* fbody = GetFunctionBody(handle); FunctionCallFrame* frame = new FunctionCallFrame(fbody->arg_types, fbody->ret_types); s = frame->SetArgs(args); if (!s.ok()) { delete frame; done(s); return; } Executor::Args exec_args; ExecutorArgsFromOptions(run_opts, frame, &exec_args); bool allow_dead_tensors = run_opts.allow_dead_tensors; item->exec->RunAsync( // Executor args exec_args, // Done callback. [frame, rets, done, allow_dead_tensors](const Status& status) { Status s = status; if (s.ok()) { s = frame->ConsumeRetvals(rets, allow_dead_tensors); } delete frame; done(s); }); } void FunctionLibraryRuntimeImpl::Run(const Options& opts, Handle handle, CallFrameInterface* frame, DoneCallback done) { if (opts.cancellation_manager && opts.cancellation_manager->IsCancelled()) { done(errors::Cancelled("")); return; } LocalHandle local_handle = parent_->GetHandleOnDevice(device_name_, handle); if (local_handle == kInvalidLocalHandle || opts.remote_execution) { done(errors::Unimplemented("Remote calling with CallFrameInterface")); return; } Options run_opts = opts; if (opts.create_rendezvous) { Rendezvous* rendezvous = new IntraProcessRendezvous(device_mgr_); run_opts.rendezvous = rendezvous; run_opts.create_rendezvous = false; done = std::bind( [rendezvous](DoneCallback done, // Begin unbound arguments. const Status& status) { rendezvous->Unref(); done(status); }, std::move(done), std::placeholders::_1); } Item* item = nullptr; Status s = GetOrCreateItem(local_handle, &item); if (!s.ok()) { done(s); return; } if (run_opts.runner == nullptr) { run_opts.runner = &default_runner_; } DCHECK(run_opts.runner != nullptr); Executor::Args exec_args; ExecutorArgsFromOptions(run_opts, frame, &exec_args); item->exec->RunAsync(exec_args, std::move(done)); } bool FunctionLibraryRuntimeImpl::IsStateful(const string& func) { const OpDef* op_def; const Status s = base_lib_def_->LookUpOpDef(func, &op_def); return s.ok() && op_def->is_stateful(); } string FunctionLibraryRuntimeImpl::DebugString(Handle handle) { Item* item = nullptr; LocalHandle local_handle = parent_->GetHandleOnDevice(device_name_, handle); Status s = GetOrCreateItem(local_handle, &item); if (s.ok()) { return tensorflow::DebugString(item->graph); } else { return s.ToString(); } } Status FunctionLibraryRuntimeImpl::Clone( std::unique_ptr<FunctionLibraryDefinition>* out_lib_def, std::unique_ptr<ProcessFunctionLibraryRuntime>* out_pflr, FunctionLibraryRuntime** out_flr) { TF_RETURN_IF_ERROR( parent_->Clone(env_, graph_def_version_, optimizer_.options(), custom_kernel_creator_, out_lib_def, out_pflr)); *out_flr = (*out_pflr)->GetFLR(device_->name()); if (out_flr != nullptr) { return Status::OK(); } else { return errors::Internal("Cloning FunctionLibraryRuntime failed."); } } namespace { struct CustomCreatorSingleton { mutex mu; CustomKernelCreator custom_creator = nullptr; void Set(CustomKernelCreator cb) { mutex_lock l(mu); custom_creator = std::move(cb); } CustomKernelCreator Get() { mutex_lock l(mu); return custom_creator; } }; CustomCreatorSingleton* GetCustomCreatorSingleton() { static CustomCreatorSingleton* ccs = new CustomCreatorSingleton; return ccs; } } // namespace void RegisterDefaultCustomKernelCreator(CustomKernelCreator cb) { GetCustomCreatorSingleton()->Set(std::move(cb)); } std::unique_ptr<FunctionLibraryRuntime> NewFunctionLibraryRuntime( const DeviceMgr* device_mgr, Env* env, Device* device, int graph_def_version, const FunctionLibraryDefinition* lib_def, thread::ThreadPool* thread_pool, const OptimizerOptions& optimizer_options, CustomKernelCreator custom_kernel_creator, ProcessFunctionLibraryRuntime* parent) { return std::unique_ptr<FunctionLibraryRuntime>(new FunctionLibraryRuntimeImpl( device_mgr, env, device, graph_def_version, lib_def, thread_pool, optimizer_options, std::move(custom_kernel_creator), parent)); } std::unique_ptr<FunctionLibraryRuntime> NewFunctionLibraryRuntime( const DeviceMgr* device_mgr, Env* env, Device* device, int graph_def_version, const FunctionLibraryDefinition* lib_def, thread::ThreadPool* thread_pool, const OptimizerOptions& optimizer_options, ProcessFunctionLibraryRuntime* parent) { return NewFunctionLibraryRuntime(device_mgr, env, device, graph_def_version, lib_def, thread_pool, optimizer_options, GetCustomCreatorSingleton()->Get(), parent); } bool RemoveDeadNodes(Graph* g) { VLOG(2) << "Removing dead nodes"; std::unordered_set<const Node*> nodes; for (auto n : g->nodes()) { if (n->IsSource() || n->IsSink() || n->IsControlFlow() || n->op_def().is_stateful()) { nodes.insert(n); } } return PruneForReverseReachability(g, std::move(nodes)); } namespace { // If 'edges' contains only 1 non-control edge, returns it. Otherwise, // returns a nullptr. const Edge* GetTheOnlyDataEdge(const EdgeSet& edges) { const Edge* ret = nullptr; for (const Edge* e : edges) { if (e->IsControlEdge() || ret) { // Don't touch it if there is a control edge. return nullptr; } if (IsRefType(e->src()->output_type(e->src_output()))) { // Don't touch it if the identity node is effectively de-reffing // a ref. return nullptr; } if (IsRecv(e->src()) || IsSwitch(e->src())) { // Don't touch it if the identity is introduced for control flow. // Recv disables all its successors if it receives a dead signal. // When Recv has an outgoing control edge, the current executor // would not disable the destination. The current solution (see // graph_partition.cc) is to add an identity after Recv and change // the control edge to be from this identity node. So the identity // can't be removed. return nullptr; } ret = e; } return ret; } } // end namespace bool RemoveIdentityNodes(Graph* g) { VLOG(2) << "Removing identity nodes"; bool removed_any = false; gtl::InlinedVector<Node*, 8> matches; for (Node* n : g->nodes()) { if (!n->IsIdentity()) continue; if (!GetTheOnlyDataEdge(n->in_edges())) continue; // Some identity nodes are used as sink nodes to give names to output // tensors. These nodes are not going to be executed unless they are in the // fetch set. But if they are in the fetch set we don't want to remove them. if (n->out_edges().empty()) continue; matches.push_back(n); } if (!matches.empty()) { for (Node* n : matches) { const Edge* in = GetTheOnlyDataEdge(n->in_edges()); for (const Edge* out : n->out_edges()) { if (out->IsControlEdge()) { g->AddControlEdge(in->src(), out->dst()); } else { g->AddEdge(in->src(), in->src_output(), out->dst(), out->dst_input()); } } VLOG(2) << "Remove Identity: " << n->DebugString(); g->RemoveNode(n); removed_any = true; } } return removed_any; } bool RemoveListArrayConverter(Graph* g) { VLOG(2) << "Removing list array converter"; gtl::InlinedVector<Node*, 8> matches; for (Node* n : g->nodes()) { if ((n->type_string() == "_ListToArray") || (n->type_string() == "_ArrayToList")) { matches.push_back(n); } } bool removed_any = false; if (!matches.empty()) { for (Node* n : matches) { if (n->num_inputs() != n->num_outputs()) { continue; // Not expected. Skip. } gtl::InlinedVector<Node*, 8> identity_nodes(n->num_inputs(), nullptr); const auto no_op = [&](StringPiece name) { return AddNoOp(absl::StrCat(n->name(), "/", name), g); }; const auto identity = [&](StringPiece name, Endpoint input) { return AddIdentity(absl::StrCat(n->name(), "/", name), g, input); }; // Process input edges first. Node* input_control_node = nullptr; for (const Edge* e : n->in_edges()) { if (e->IsControlEdge()) { if (input_control_node == nullptr) { // If node "n" has any control dependencies, adds a no-op // node (input_control_node) which the additional Identity // nodes depends on and the input_control_node depends on // the node "n"s control dependencies. input_control_node = no_op("input_control_node"); } g->AddControlEdge(e->src(), input_control_node); } else { const int index = e->dst_input(); Node** id_node = &identity_nodes[index]; if (*id_node != nullptr) { LOG(ERROR) << "RemoveListArrayConverter unexpected duplicated input: " << e->dst_input(); return removed_any; } *id_node = identity("input", {e->src(), e->src_output()}); } } // If node "n" has any control dependencies, the added identity // nodes should have control dependencies on input_control_node. if (input_control_node != nullptr) { for (Node* id : identity_nodes) { g->AddControlEdge(input_control_node, id); } } Node* output_control_node = nullptr; for (const Edge* e : n->out_edges()) { if (e->IsControlEdge()) { if (output_control_node == nullptr) { // If node "n" is control-depended upon by other nodes, // adds a no-op node (output_control_node) which those // nodes will depend on and output_control_node depends on // all Identity nodes. output_control_node = no_op("output_control_node"); } g->AddControlEdge(output_control_node, e->dst()); } else { Node* id_node = identity_nodes[e->src_output()]; if (id_node == nullptr) { LOG(ERROR) << "RemoveListArrayConverter unexpected missing input: " << e->src_output(); return removed_any; } CHECK(id_node); g->AddEdge(id_node, 0, e->dst(), e->dst_input()); } } // If any nodes have control dependencies on node "n", those // nodes should have control dependencies on // output_control_node. if (output_control_node != nullptr) { for (Node* id : identity_nodes) { g->AddControlEdge(id, output_control_node); } } g->RemoveNode(n); removed_any = true; } } return removed_any; } Status NameAndAttrsFromFunctionCall(const NodeDef& call_def, NameAttrList* function) { if (call_def.op() == "PartitionedCall" || call_def.op() == "StatefulPartitionedCall") { TF_RETURN_IF_ERROR(GetNodeAttr(call_def, "f", function)); } else { function->set_name(call_def.op()); *function->mutable_attr() = call_def.attr(); } return Status::OK(); } Status InstantiateFunctionCall(const NodeDef& call_def, FunctionLibraryRuntime* flr, FunctionLibraryRuntime::Handle* handle) { NameAttrList function; TF_RETURN_IF_ERROR(NameAndAttrsFromFunctionCall(call_def, &function)); return flr->Instantiate(function.name(), AttrSlice(&function.attr()), handle); } namespace { Status ValidateNoInline(const FunctionBody* fbody) { const auto attr = AttrSlice(&fbody->fdef.attr()); bool noinline = false; if (GetNodeAttr(attr, kNoInlineAttr, &noinline).ok() && noinline) { return errors::InvalidArgument( "Can't inline function marked with '_noinline'"); } return Status::OK(); } using OutputControlSrc = InlineFunctionBodyOptions::OutputControlSource; } // namespace string InlineFunctionBodyOptions::DebugString() const { const auto true_false = [](bool b) { return b ? "true" : "false"; }; return absl::StrCat("disable_inlining=", true_false(disable_inlining), ", ignore_noinline=", true_false(ignore_noinline), ", override_device=", true_false(ignore_noinline), ", output_control_src=", output_control_src == OutputControlSrc::kDataOutputs ? "DataOutputs" : "ControlOutputs"); } Status ValidateInlining(const Node* node, const FunctionBody* fbody, const InlineFunctionBodyOptions& options) { // TODO(ezhulenev): Currently common_runtime function inlining can't guarantee // that all side-effectful ops will be executed after inlining. See Grappler // function_optimizer for details. Unify all function inlining mechanism. // Do not inline if `!fbody->control_ret_nodes.empty()`. const auto num_node_inputs = static_cast<size_t>(node->num_inputs()); const auto num_node_outputs = static_cast<size_t>(node->num_outputs()); if (num_node_inputs != fbody->arg_types.size() || num_node_inputs != fbody->arg_nodes.size()) { return errors::InvalidArgument( "Node inputs do not match function arguments: inputs=", num_node_inputs, " arg_types=", fbody->arg_types.size(), " arg_nodes=", fbody->arg_nodes.size()); } if (num_node_outputs != fbody->ret_types.size() || num_node_outputs != fbody->ret_nodes.size()) { return errors::InvalidArgument( "Node outputs do not match function returns: outputs=", num_node_outputs, " ret_types=", fbody->ret_types.size(), " ret_nodes=", fbody->ret_nodes.size()); } for (int i = 0; i < node->num_inputs(); ++i) { if (node->input_type(i) != fbody->arg_types[i]) { return errors::InvalidArgument( "Node input type doesn't match function argument type: ", node->input_type(i), " != ", fbody->arg_types[i], " @ index=", i); } } for (int i = 0; i < node->num_outputs(); ++i) { if (node->output_type(i) != fbody->ret_types[i]) { return errors::InvalidArgument( "Node output type doesn't match function return type: ", node->output_type(i), " != ", fbody->ret_types[i], " @ index=", i); } } if (options.disable_inlining) { return errors::InvalidArgument( "Function inlining explicitly disabled by 'options.disable_inlining'"); } if (!options.ignore_noinline) { TF_RETURN_IF_ERROR(ValidateNoInline(fbody)); } return Status::OK(); } // Function inlining must preserve function execution semantics with regards to // side-effects visibility. Tensorflow in Eager mode has an automatic control // dependencies tracking mechanism, which enforces well-defined execution order // of all side-effects. Any other frontend (e.g. Swift) must produce graphs // following the same rules, to ensure that function inlining works correctly. // // IMPORTANT: Currently we do not have a true notion of "side-effectful" node, // we assume that all stateful nodes might have side-effects, though it's not // true in practice, e.g. `ReadVariableOp` doesn't have an observable // side-effect. // // Automatic control dependency rules in Tensorflow 2.0 (python in eager mode): // // 1) When a function has a resource (DT_RESOURCE data type) input argument it // "captures" the mutable resource. This is implemented by automatically // adding a incoming control edge from the previous side-effectful op // touching that resource, and an outgoing control edge to the next // side-effectful op using the same resource. This serializes the mutations // of the resource to make graph execution deterministic. // // 2) All stateful ops inside a function body are guaranteed to execute in // program order, this is achieved by adding control edges between stateful // ops at graph construction time. Stateful ops (or ops that must execute) // should be in the function control return set. Having a data edge to the // regular function output might be not enough, because after function // inlining it might happen that data output is unused. // // 3) Furthermore, all ops accepting the same resource as an input are // guaranteed to run in program order. This is also done by adding control // edges at graph construction time. The last op touching the resource // must be in a control return set, which will guarantee that all side // effects to the resource will happen before function completion. // // Function inlining must preserve side-effect visibility: // // 1) All side-effects to the captured resources, that happened before function // call must be visible to the function body nodes using that resources. // // 2) All side-effects to the captured resources, that happened inside function // body, must be visible to every op/function using that resource after the // function call completed. // // To guarantee that these properties are preserved after inlining we: // // 1) Create "input_control_node" NoOp. Function call node incoming control // edges will be forwarded *to* this node. Function inputs (Identity nodes) // will have a control edge *from* this node. If function body has nodes // without inputs, they will have a control edge *from* this node. // // 2) Create "output_control_node" NoOp. All nodes that have incoming control // edge *from* the function call node, will be forwarded to this node. // // We have two options for choosing which nodes will have a control edge *to* // the "output control node": // a) control returns (`control_ret` field in FunctionDef) // b) data returns (`ret` field in FunctionDef) // // We do a) for multi-device function calls in Tensorflow v2 and b) // for the rest for compatibility with Tensorflow v1. // // Following the automatic control dependencies tracking rules, a node that // has an incoming control edge from the function call node is dependent on // the side-effects happening inside the function body. The output control // node will guarantee side-effects execution order. // // If function call node doesn't have an outgoing control edge, it means that // no one is interested in observing side-effects that might have happened. // // Function inlining might leave the graph in partially-placed state. Function // inlining caller must call Placer to guarantee that all nodes are placed. // // Function inlining with `options.override_device=true` will leave graph in // fully placed state, by overriding all inlined nodes devices with the caller // node device, but it will make functions always single-device. These functions // after inlining will not be able to handle resources on multiple devices. This // is currently acceptable for XLA use cases (XLA cluster is always executed on // a single device). // // TODO(ezhulenev): Documentation above is ahead of implementation below. Status InlineFunctionBody(const FunctionLibraryDefinition& flib_def, Graph* g, Node* caller, const FunctionBody* fbody, const InlineFunctionBodyOptions& options) { VLOG(3) << "Inline function call: " << SummarizeNode(*caller) << " [" << options.DebugString() << "]"; VLOG(4) << "Inlined function definition: " << DebugString(fbody->fdef); Status validation = ValidateInlining(caller, fbody, options); if (!validation.ok()) { LOG(WARNING) << "Inlining mismatch: " << SummarizeNode(*caller) << " vs. " << DebugString(fbody->graph); return errors::Internal("Inlining mismatch: ", validation.error_message()); } // We can't possibly introduce a duplicate control edge during function // inlining, so we skip this check in calls to the 'g->AddControlEdge(...)'. static constexpr bool kDoNotCheckDuplicates = true; // ------------------------------------------------------------------------ // // Helper functions to create `NoOp` and `Identity` nodes for auxiliary // control nodes and inlined function inputs and outputs. // Add a NoOp node for function control inputs/outputs. const auto no_op = [&](StringPiece name) { Node* node = AddNoOp(absl::StrCat(caller->name(), "/", name), g); node->set_requested_device(caller->def().device()); return node; }; // Add an Identity node for function data inputs/outputs. const auto identity = [&](StringPiece name, Endpoint input) { return AddIdentity(absl::StrCat(caller->name(), "/", name), g, input); }; // ------------------------------------------------------------------------ // // Input edges. For data edges coming into "caller", we first compute the // <src>:<src_output> for the i-th input in "inputs". // If "caller" has any input control dependencies, we add a NoOp // node "input_control_node", which depends on "caller"'s control inputs. std::vector<Endpoint> inputs(caller->num_inputs()); Node* input_control_node = nullptr; for (const Edge* e : caller->in_edges()) { if (e->IsControlEdge()) { if (input_control_node == nullptr) { input_control_node = no_op("input_control_node"); } g->AddControlEdge(e->src(), input_control_node, kDoNotCheckDuplicates); } else { inputs[e->dst_input()] = {e->src(), e->src_output()}; } } // ------------------------------------------------------------------------ // // Duplicate fbody->graph into 'g'. First, we copy the nodes of // fbody->graph into 'g' except the source and sink nodes. We copy // edges among nodes in 'fbody->graph'. // // If 'x' is a node in fbody->graph and its copy in 'g' is 'y', we // remember 'y' in node_map[x->id()]. std::vector<Node*> node_map(fbody->graph->num_node_ids()); for (Node* n : fbody->graph->op_nodes()) { NodeDef ndef = n->def(); ndef.set_name(strings::StrCat(caller->name(), "/", ndef.name())); if (options.override_device || ndef.device().empty()) { ndef.set_device(caller->def().device()); } for (auto& attr : *ndef.mutable_attr()) { if (attr.first == "_class") { attr.second.set_s( strings::StrCat(caller->name(), "/", attr.second.s())); } } Status added_node; Node* clone = g->AddNode(ndef, &added_node); if (options.override_device && !caller->assigned_device_name().empty()) { clone->set_assigned_device_name(caller->assigned_device_name()); } TF_CHECK_OK(added_node); node_map[n->id()] = clone; // If there is an input control node, and one of: // a) the node has no data or control inputs, or // b) the node is a function call (including SymbolicGradient), // then add a control edge from the input control node to the clone. // // We must not execute any nodes if the original function call would not // have executed. This is especially critical when the function call is // inside a control-flow construct like tf.cond(). Case (a) ensures that // such nodes do not run. // // The purpose of case (b) is to ensure that instances of case (a) created // by further inlining steps also receive the control dependency. // // This edge is required to transfer execution frame down to all function // body nodes of inlined nested function calls. if (input_control_node) { bool has_inputs = absl::c_any_of( n->in_edges(), [](const Edge* e) { return !e->src()->IsSource(); }); if (!has_inputs || IsFunctionCall(flib_def, *n)) { g->AddControlEdge(input_control_node, clone, kDoNotCheckDuplicates); } } } for (const Edge* e : fbody->graph->edges()) { if (e->src()->IsSource() || e->src()->IsSink() || e->dst()->IsSource() || e->dst()->IsSink()) { continue; } Node* src_copy = node_map[e->src()->id()]; Node* dst_copy = node_map[e->dst()->id()]; g->AddEdge(src_copy, e->src_output(), dst_copy, e->dst_input()); } // ------------------------------------------------------------------------ // // Connect input edges. // // We create one Identity node for each input. Then, we connect inputs[i] to // the i-th identity node added. The nodes that previously connected // to the j-th output of i-th arg node are reconnected to the i-th // identity node. // // The added identity nodes depend on "input_control_node". for (std::size_t i = 0; i < fbody->arg_nodes.size(); ++i) { Node* arg = node_map[fbody->arg_nodes[i]->id()]; Node* n = identity("input", inputs[i]); if (input_control_node) { g->AddControlEdge(input_control_node, n, kDoNotCheckDuplicates); } for (const Edge* e : arg->out_edges()) { if (e->IsControlEdge()) { g->AddControlEdge(n, e->dst(), kDoNotCheckDuplicates); } else { g->AddEdge(n, 0, e->dst(), e->dst_input()); } } node_map[fbody->arg_nodes[i]->id()] = n; g->RemoveNode(arg); // 'arg' is disconnected. } // ------------------------------------------------------------------------ // // Connect output edges. // // For i-th return node in fbody->graph, we add in "g" an identity node // (outputs[i-th]). We then reconnect every incoming edge into the i-th return // node to the added identity node. // // For every data edge coming out of "callee"s i-th output, we reconnect it to // the i-th identity added above. // // If "callee" is control-depended upon by any other nodes, we add a NoOp node // "output_control_node". "output_control_node" depends on all identity nodes // added above or on all control return nodes (controlled by // `options.output_control_src` value). And nodes previously depend on // "callee" is changed to depend on "output_control_node". // // If `keep_node_fetchable` is `true` we always add an output control node, to // guarantee that executing a fetchable node will execute all side-effects. std::vector<Node*> outputs(caller->num_outputs()); for (std::size_t i = 0; i < fbody->ret_nodes.size(); ++i) { Node* ret = node_map[fbody->ret_nodes[i]->id()]; Endpoint data; // Data input for the ret node. for (const Edge* e : ret->in_edges()) { if (!e->IsControlEdge()) { data = {e->src(), e->src_output()}; break; } } CHECK(data.node != nullptr); Node* n = identity("output", data); outputs[i] = n; for (const Edge* e : ret->in_edges()) { if (e->IsControlEdge()) { g->AddControlEdge(e->src(), n, kDoNotCheckDuplicates); } } g->RemoveNode(ret); // 'ret' is disconnected. } Node* output_control_node = nullptr; bool has_control_outputs = absl::c_any_of( caller->out_edges(), [](const Edge* e) { return e->IsControlEdge(); }); if (has_control_outputs || options.keep_caller_fetchable) { output_control_node = no_op("output_control_node"); if (options.output_control_src == OutputControlSrc::kDataOutputs) { for (Node* n : outputs) { g->AddControlEdge(n, output_control_node, kDoNotCheckDuplicates); } } else { for (Node* fbody_node : fbody->control_ret_nodes) { Node* n = node_map[fbody_node->id()]; g->AddControlEdge(n, output_control_node, kDoNotCheckDuplicates); } } } // We can't leave output control node without incoming control edges, because // in this case outgoing control edge will loose execution frame information. // We connect input_control_node and output_control_node with a control edge // to forward execution frame to the controlled nodes. Above we add a control // edge to all function calls inside function body, to guarantee that we will // always have input_control_node when we need it. if (output_control_node && output_control_node->in_edges().empty()) { if (input_control_node) { g->AddControlEdge(input_control_node, output_control_node, kDoNotCheckDuplicates); } else { VLOG(3) << "Function inlining potentially dropped execution frame " "information from outgoing control edges."; } } for (const Edge* e : caller->out_edges()) { if (e->IsControlEdge()) { g->AddControlEdge(output_control_node, e->dst(), kDoNotCheckDuplicates); } else { g->AddEdge(outputs[e->src_output()], 0, e->dst(), e->dst_input()); } } // ------------------------------------------------------------------------ // // Add an IdentityN or NoOp node in-place of caller node to keep `caller` // fetchable. if (options.keep_caller_fetchable) { std::vector<NodeBuilder::NodeOut> output_tensors; absl::c_transform(outputs, std::back_inserter(output_tensors), [](Node* n) { return NodeBuilder::NodeOut(n, 0); }); Node* fetchable_node; if (output_tensors.empty()) { // IdentityN node must have at least one data input. If function has no // data outputs, it still could be used as a callable target. TF_CHECK_OK(NodeBuilder(caller->name(), "NoOp") .Device(caller->requested_device()) .ControlInput(output_control_node) .Finalize(g, &fetchable_node)); } else { TF_CHECK_OK(NodeBuilder(caller->name(), "IdentityN") .Device(caller->requested_device()) .Input(output_tensors) .ControlInput(output_control_node) .Finalize(g, &fetchable_node)); } } // ------------------------------------------------------------------------ // // 'caller' is replaced with inlined function body nodes and maybe IdentityN // to keep it fetchable. g->RemoveNode(caller); return Status::OK(); } bool IsFunctionCall(const FunctionLibraryDefinition& lib_def, const Node& node) { return node.IsPartitionedCall() || node.type_string() == FunctionLibraryDefinition::kGradientOp || lib_def.Find(node.def().op()) != nullptr; } bool ExpandInlineFunctions(FunctionLibraryRuntime* lib, Graph* graph, const ExpandInlineFunctionsOptions& options) { std::vector<std::pair<Node*, const FunctionBody*>> candidates; const FunctionLibraryDefinition* fld = lib->GetFunctionLibraryDefinition(); for (Node* node : graph->nodes()) { // Skip nodes that are not function calls or SymbolicGradient calls. if (!IsFunctionCall(*lib->GetFunctionLibraryDefinition(), *node)) { continue; } // Skip function calls that marked noinline. bool noinline; if (fld->GetAttr(*node, kNoInlineAttr, &noinline).ok() && noinline) { VLOG(3) << "noinline: " << SummarizeNode(*node); continue; } FunctionLibraryRuntime::Handle handle; Status s = InstantiateFunctionCall(node->def(), lib, &handle); if (!s.ok()) { LOG(ERROR) << "Failed to instantiate a function: " << s.error_message(); continue; } const FunctionBody* fbody = lib->GetFunctionBody(handle); CHECK_NOTNULL(fbody); candidates.emplace_back(node, fbody); } bool inlined_any = false; for (const auto& p : candidates) { Status inlined = InlineFunctionBody(*fld, graph, p.first, p.second, p.first->IsPartitionedCall() ? options.multi_device_options : options.native_options); if (inlined.ok()) { inlined_any = true; } else { VLOG(1) << "Failed to inline function call: node=" << p.first->name() << " error=" << inlined.error_message(); } } // TODO(ezhulenev): Release handles for inlined function calls. return inlined_any; } string NewName(const Node* n, bool pretty) { if (pretty) { return strings::StrCat(n->type_string(), n->id()); } else { return strings::StrCat("n", n->id()); } } // TODO(zhifengc): Maybe this should be the default Graph::AsGraphDef. // and stash the original NodeDef name as an attr for documentation // purpose. void ToGraphDef(const Graph* g, GraphDef* gdef, bool pretty) { // We visit nodes in forward topological sort order, which is a // possible execution order of the graph. gtl::InlinedVector<const Edge*, 4> inputs; gdef->Clear(); *gdef->mutable_versions() = g->versions(); std::vector<Node*> start_nodes; for (Node* n : g->nodes()) { if (n->out_edges().empty()) { start_nodes.push_back(n); } } ReverseDFSFrom(*g, start_nodes, nullptr, [gdef, pretty, &inputs](Node* n) { if (!n->IsOp()) return; NodeDef* ndef = gdef->add_node(); ndef->set_name(NewName(n, pretty)); ndef->set_op(n->type_string()); for (const auto& attr : n->attrs()) { (*ndef->mutable_attr())[attr.first] = attr.second; } if (!n->assigned_device_name().empty()) { ndef->set_device(n->assigned_device_name()); } else { ndef->set_device(n->requested_device()); } inputs.clear(); inputs.resize(n->num_inputs()); for (const Edge* e : n->in_edges()) { if (e->IsControlEdge()) { inputs.push_back(e); } else { if (inputs[e->dst_input()] == nullptr) { inputs[e->dst_input()] = e; } else { LOG(WARNING) << "Malformed graph node. multiple input edges: " << n->DebugString(); } } } // node->name() is merely NodeDef::name, which are not guaranteed // to be unique and stable after optimization rewrites. Therefore, // we use "n<node id>" instead. for (const Edge* e : inputs) { if (e == nullptr) { ndef->add_input("unknown"); continue; } const string srcname = NewName(e->src(), pretty); if (!e->src()->IsOp()) { } else if (e->IsControlEdge()) { ndef->add_input(strings::StrCat("^", srcname)); } else if (e->src_output() == 0) { ndef->add_input(srcname); } else { ndef->add_input(strings::StrCat(srcname, ":", e->src_output())); } } }); } string DebugString(const Graph* g) { GraphDef gdef; ToGraphDef(g, &gdef); return DebugString(gdef); } FunctionBody::FunctionBody(const FunctionDef& f, DataTypeSlice arg_t, DataTypeSlice ret_t, Graph* g) : fdef(f), graph(g), arg_types(arg_t.begin(), arg_t.end()), ret_types(ret_t.begin(), ret_t.end()) { // 1. Find regular Arg/Ret nodes. this->arg_nodes.resize(arg_types.size()); this->ret_nodes.resize(ret_types.size()); for (Node* n : this->graph->op_nodes()) { gtl::InlinedVector<Node*, 4>* node_vec; if (n->type_string() == kRetOp || n->type_string() == kDeviceRetOp) { node_vec = &this->ret_nodes; } else if (n->type_string() == kArgOp || n->type_string() == kDeviceArgOp) { node_vec = &this->arg_nodes; } else { continue; } int index; TF_CHECK_OK(GetNodeAttr(n->attrs(), "index", &index)); CHECK_LE(0, index); CHECK_LT(index, node_vec->size()); (*node_vec)[index] = n; } // 2. Find ControlRet nodes that must be always executed. std::unordered_set<StringPiece, StringPieceHasher> control_ret_node_names; for (const auto& control_ret : fdef.control_ret()) { control_ret_node_names.insert(control_ret.second); } this->control_ret_nodes.reserve(control_ret_node_names.size()); for (Node* n : this->graph->op_nodes()) { if (control_ret_node_names.count(n->name()) > 0) { this->control_ret_nodes.push_back(n); } } } FunctionBody::~FunctionBody() { delete this->graph; } class SymbolicGradientHelper { public: explicit SymbolicGradientHelper(const FunctionBody& f) : fbody_(&f) {} ~SymbolicGradientHelper() = default; std::unique_ptr<FunctionBody> Compute(); private: const FunctionBody* fbody_; // Makes a copy of fbody_ in gbody. void Copy(FunctionBody* gbody); TF_DISALLOW_COPY_AND_ASSIGN(SymbolicGradientHelper); }; void SymbolicGradientHelper::Copy(FunctionBody* gbody) { const Graph& src = *(fbody_->graph); gbody->graph = new Graph(src.op_registry()); Graph* dst = gbody->graph; std::vector<Node*> node_map(src.num_node_ids()); // Copy the nodes. node_map[src.source_node()->id()] = dst->source_node(); node_map[src.sink_node()->id()] = dst->sink_node(); for (Node* n : src.op_nodes()) { node_map[n->id()] = dst->CopyNode(n); } // Copy the edges. for (const Edge* e : src.edges()) { Node* src_copy = node_map[e->src()->id()]; Node* dst_copy = node_map[e->dst()->id()]; dst->AddEdge(src_copy, e->src_output(), dst_copy, e->dst_input()); } // Save inputs in copied graph. CHECK_EQ(fbody_->arg_types.size(), fbody_->arg_nodes.size()); gbody->arg_types = fbody_->arg_types; for (std::size_t i = 0; i < fbody_->arg_nodes.size(); ++i) { gbody->arg_nodes.push_back(node_map[fbody_->arg_nodes[i]->id()]); } // Save outputs in copied graph. CHECK_EQ(fbody_->ret_types.size(), fbody_->ret_nodes.size()); gbody->ret_types = fbody_->ret_types; for (std::size_t i = 0; i < fbody_->ret_nodes.size(); ++i) { gbody->ret_nodes.push_back(node_map[fbody_->ret_nodes[i]->id()]); } } std::unique_ptr<FunctionBody> SymbolicGradientHelper::Compute() { FunctionBody* gbody = new FunctionBody; Copy(gbody); // copy fbody_ into gbody. Graph* g = gbody->graph; const int num_y = static_cast<int>(gbody->ret_nodes.size()); // Populate 'y_node_outputs_' with node function body outputs. // Populate 'y_grad_nodes' with initial gradient nodes for each return node // of the original function body (these will be 'arg' nodes in the function // gradient body). std::vector<NodeOut> y_node_outputs; y_node_outputs.reserve(num_y); std::vector<NodeOut> y_grad_node_outputs; y_grad_node_outputs.reserve(num_y); for (int i = 0; i < num_y; ++i) { Node* y = gbody->ret_nodes[i]; y_node_outputs.push_back({y, 0}); DCHECK_EQ(y->type_string(), kRetOp); const DataType dtype = y->input_type(0); const int index = static_cast<int>(gbody->arg_nodes.size()); Node* dy = AddArg(g, dtype, index); gbody->arg_types.push_back(dtype); gbody->arg_nodes.push_back(dy); y_grad_node_outputs.push_back({dy, 0}); } // Populate 'x_nodes' with function args (excluding 'y_grad_node_outputs'). const size_t num_x = fbody_->arg_nodes.size(); std::vector<NodeOut> x_node_outputs; x_node_outputs.reserve(num_x); for (size_t i = 0; i < fbody_->arg_nodes.size(); ++i) { x_node_outputs.push_back({gbody->arg_nodes[i], 0}); } // Call AddSymbolicGradients which will add nodes to graph 'g' that // compute the function gradient (adding an entry in 'x_grad_node_outputs' // for each node in 'x_node_outputs'). std::vector<NodeOut> x_grad_node_outputs; TF_CHECK_OK(AddSymbolicGradients(y_node_outputs, x_node_outputs, y_grad_node_outputs, &x_grad_node_outputs, g)); // Remove the old return nodes from the function body. for (Node* n : gbody->ret_nodes) { g->RemoveNode(n); } gbody->ret_types = fbody_->arg_types; // TODO(apassos): use the right dtype for gradients of resource variables for (int i = 0; i < gbody->ret_types.size(); ++i) { if (gbody->ret_types[i] == DT_RESOURCE) { gbody->ret_types[i] = DT_FLOAT; } } gbody->ret_nodes.clear(); // Add new return nodes to the function gradient body for each node // in 'x_grad_nodes'. const int arg_types_size = static_cast<int>(fbody_->arg_types.size()); for (int i = 0; i < arg_types_size; ++i) { Endpoint grad = {x_grad_node_outputs[i].node, x_grad_node_outputs[i].index}; Node* ret = AddRet(g, grad, i); gbody->ret_nodes.push_back(ret); } return std::unique_ptr<FunctionBody>(gbody); } std::unique_ptr<FunctionBody> SymbolicGradient(const FunctionBody& f) { return SymbolicGradientHelper(f).Compute(); } Status FunctionDefToBodyHelper( const FunctionDef& fdef, const AttrSlice& attrs, const FunctionLibraryDefinition* const lib_def, const std::function<Status(const string&, const OpDef**)>& get_func_sig, std::unique_ptr<FunctionBody>* fbody) { // Instantiates the function template into a graph def. InstantiationResult result; TF_RETURN_IF_ERROR(InstantiateFunction(fdef, attrs, get_func_sig, &result)); std::unique_ptr<Graph> graph(new Graph(lib_def)); GraphConstructorOptions opts; opts.allow_internal_ops = true; opts.expect_device_spec = false; TF_RETURN_IF_ERROR(ConvertNodeDefsToGraph(opts, result.nodes, graph.get())); // Call BuildControlFlowInfo to validate that this function body has // well-formed control flow. std::vector<ControlFlowInfo> dummy; TF_RETURN_IF_ERROR(BuildControlFlowInfo(graph.get(), &dummy)); *fbody = absl::make_unique<FunctionBody>(fdef, result.arg_types, result.ret_types, graph.release()); return Status::OK(); } Status FunctionDefToBodyHelper(const FunctionDef& fdef, const AttrSlice& attrs, const FunctionLibraryDefinition* lib_def, std::unique_ptr<FunctionBody>* fbody) { const auto get_func_sig = [&lib_def](const string& op, const OpDef** sig) { return lib_def->LookUpOpDef(op, sig); }; return FunctionDefToBodyHelper(fdef, attrs, lib_def, get_func_sig, fbody); } } // end namespace tensorflow
SECTION code_clib SECTION code_l PUBLIC l_setmem_de ; write byte to buffer pointed at by de ; invoke with "call l_setmem_de - (n*2)" to write n bytes to memory ; ; enter : de = char *buffer ; a = fill byte ; ; exit : de = char *buffer (one byte past last byte written) ; ; uses : de ld (de),a inc de ld (de),a inc de ld (de),a inc de ld (de),a inc de ld (de),a inc de ld (de),a inc de ld (de),a inc de ld (de),a inc de l_setmem_de: ret
/* * Author: Jon Trulson <jtrulson@ics.com> * Copyright (c) 2015 Intel Corporation. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include <iostream> #include <signal.h> #include <stdint.h> #include "gas.hpp" #include "mq7.hpp" bool shouldRun = true; using namespace std; void sig_handler(int signo) { if (signo == SIGINT) { shouldRun = false; } } //! [Interesting] int main(int argc, char** argv) { // Attach gas sensor to Analog A0 upm::MQ7 sensor(0); signal(SIGINT, sig_handler); uint16_t buffer[128]; thresholdContext ctx; ctx.averageReading = 0; ctx.runningAverage = 0; ctx.averagedOver = 2; // Infinite loop, ends when script is cancelled // Repeatedly, take a sample every 2 microseconds; // find the average of 128 samples; and // print a running graph of asteriskss as averages while (shouldRun) { int len = sensor.getSampledWindow(2, 128, buffer); if (len) { int thresh = sensor.findThreshold(&ctx, 30, buffer, len); sensor.printGraph(&ctx, 5); if (thresh) { // do something .... } } } cout << "Exiting" << endl; return 0; } //! [Interesting]
; A164485: Number of binary strings of length n with no substrings equal to 0001, 1000 or 1001. ; 13,21,33,53,85,137,221,357,577,933,1509,2441,3949,6389,10337,16725,27061,43785,70845,114629,185473,300101,485573,785673,1271245,2056917,3328161,5385077,8713237,14098313,22811549,36909861,59721409,96631269,156352677,252983945,409336621,662320565,1071657185,1733977749,2805634933,4539612681,7345247613,11884860293,19230107905,31114968197,50345076101,81460044297,131805120397,213265164693,345070285089,558335449781,903405734869,1461741184649,2365146919517,3826888104165,6192035023681,10018923127845,16210958151525,26229881279369,42440839430893,68670720710261,111111560141153,179782280851413,290893840992565,470676121843977,761569962836541,1232246084680517,1993816047517057,3226062132197573,5219878179714629,8445940311912201 mov $1,6 mov $2,4 lpb $0 sub $0,1 mov $3,$2 mov $2,$1 add $1,$3 lpe mul $1,2 add $1,1
; int ba_priority_queue_push(ba_priority_queue_t *q, int c) SECTION code_adt_ba_priority_queue PUBLIC ba_priority_queue_push EXTERN asm_ba_priority_queue_push ba_priority_queue_push: pop af pop bc pop hl push hl push bc push af jp asm_ba_priority_queue_push
/* file: cor_dist_dense_batch.cpp */ /******************************************************************************* * Copyright 2014 Intel Corporation * * 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. *******************************************************************************/ /* ! Content: ! C++ example of computing a correlation distance matrix !******************************************************************************/ /** * <a name="DAAL-EXAMPLE-CPP-CORRELATION_DISTANCE_BATCH"></a> * \example cor_dist_dense_batch.cpp */ #include "daal.h" #include "service.h" using namespace std; using namespace daal; using namespace daal::algorithms; using namespace daal::data_management; /* Input data set parameters */ const string datasetFileName = "../data/batch/distance.csv"; int main(int argc, char * argv[]) { checkArguments(argc, argv, 1, &datasetFileName); /* Initialize FileDataSource<CSVFeatureManager> to retrieve the input data from a .csv file */ FileDataSource<CSVFeatureManager> dataSource(datasetFileName, DataSource::doAllocateNumericTable, DataSource::doDictionaryFromContext); /* Retrieve the data from the input file */ dataSource.loadDataBlock(); /* Create an algorithm to compute a correlation distance matrix using the default method */ correlation_distance::Batch<> algorithm; /* Set input objects for the algorithm */ algorithm.input.set(correlation_distance::data, dataSource.getNumericTable()); /* Compute a correlation distance matrix */ algorithm.compute(); /* Get the computed correlation distance matrix */ correlation_distance::ResultPtr res = algorithm.getResult(); printNumericTable(res->get(correlation_distance::correlationDistance), "Correlation distance", 15); return 0; }
/* * Copyright (C) 2009 Matt Oswald * Copyright (c) 2009-2010 Ricardo Quesada * Copyright (c) 2010-2012 cocos2d-x.org * Copyright (c) 2011 Zynga Inc. * Copyright (c) 2011 Marco Tillemans * Copyright (c) 2013-2014 Chukong Technologies Inc. * * http://www.cocos2d-x.org * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ #include "2d/CCParticleBatchNode.h" #include "renderer/CCTextureAtlas.h" #include "2d/CCGrid.h" #include "2d/CCParticleSystem.h" #include "platform/CCFileUtils.h" #include "base/CCProfiling.h" #include "base/ccConfig.h" #include "base/ccMacros.h" #include "base/base64.h" #include "base/ZipUtils.h" #include "renderer/CCTextureCache.h" #include "renderer/CCGLProgramState.h" #include "renderer/CCGLProgram.h" #include "renderer/ccGLStateCache.h" #include "renderer/CCQuadCommand.h" #include "renderer/CCRenderer.h" NS_CC_BEGIN ParticleBatchNode::ParticleBatchNode() : _textureAtlas(nullptr) { } ParticleBatchNode::~ParticleBatchNode() { CC_SAFE_RELEASE(_textureAtlas); } /* * creation with Texture2D */ ParticleBatchNode* ParticleBatchNode::createWithTexture(Texture2D *tex, int capacity/* = kParticleDefaultCapacity*/) { ParticleBatchNode * p = new ParticleBatchNode(); if( p && p->initWithTexture(tex, capacity)) { p->autorelease(); return p; } CC_SAFE_DELETE(p); return nullptr; } /* * creation with File Image */ ParticleBatchNode* ParticleBatchNode::create(const std::string& imageFile, int capacity/* = kParticleDefaultCapacity*/) { ParticleBatchNode * p = new ParticleBatchNode(); if( p && p->initWithFile(imageFile, capacity)) { p->autorelease(); return p; } CC_SAFE_DELETE(p); return nullptr; } /* * init with Texture2D */ bool ParticleBatchNode::initWithTexture(Texture2D *tex, int capacity) { _textureAtlas = new TextureAtlas(); _textureAtlas->initWithTexture(tex, capacity); _children.reserve(capacity); _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return true; } /* * init with FileImage */ bool ParticleBatchNode::initWithFile(const std::string& fileImage, int capacity) { Texture2D *tex = Director::getInstance()->getTextureCache()->addImage(fileImage); return initWithTexture(tex, capacity); } // ParticleBatchNode - composition // override visit. // Don't call visit on it's children void ParticleBatchNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // CAREFUL: // This visit is almost identical to Node#visit // with the exception that it doesn't call visit on it's children // // The alternative is to have a void Sprite#visit, but // although this is less maintainable, is faster // if (!_visible) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); draw(renderer, _modelViewTransform, flags); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } // override addChild: void ParticleBatchNode::addChild(Node * aChild, int zOrder, int tag) { CCASSERT( aChild != nullptr, "Argument must be non-nullptr"); CCASSERT( dynamic_cast<ParticleSystem*>(aChild) != nullptr, "CCParticleBatchNode only supports QuadParticleSystems as children"); ParticleSystem* child = static_cast<ParticleSystem*>(aChild); CCASSERT( child->getTexture()->getName() == _textureAtlas->getTexture()->getName(), "CCParticleSystem is not using the same texture id"); // If this is the 1st children, then copy blending function if (_children.empty()) { setBlendFunc(child->getBlendFunc()); } CCASSERT( _blendFunc.src == child->getBlendFunc().src && _blendFunc.dst == child->getBlendFunc().dst, "Can't add a ParticleSystem that uses a different blending function"); //no lazy sorting, so don't call super addChild, call helper instead auto pos = addChildHelper(child,zOrder,tag); //get new atlasIndex int atlasIndex = 0; if (pos != 0) { ParticleSystem* p = static_cast<ParticleSystem*>(_children.at(pos-1)); atlasIndex = p->getAtlasIndex() + p->getTotalParticles(); } else { atlasIndex = 0; } insertChild(child, atlasIndex); // update quad info child->setBatchNode(this); } // don't use lazy sorting, reordering the particle systems quads afterwards would be too complex // XXX research whether lazy sorting + freeing current quads and calloc a new block with size of capacity would be faster // XXX or possibly using vertexZ for reordering, that would be fastest // this helper is almost equivalent to Node's addChild, but doesn't make use of the lazy sorting int ParticleBatchNode::addChildHelper(ParticleSystem* child, int z, int aTag) { CCASSERT( child != nullptr, "Argument must be non-nil"); CCASSERT( child->getParent() == nullptr, "child already added. It can't be added again"); _children.reserve(4); //don't use a lazy insert auto pos = searchNewPositionInChildrenForZ(z); _children.insert(pos, child); child->setTag(aTag); child->_setLocalZOrder(z); child->setParent(this); if( _running ) { child->onEnter(); child->onEnterTransitionDidFinish(); } return pos; } // Reorder will be done in this function, no "lazy" reorder to particles void ParticleBatchNode::reorderChild(Node * aChild, int zOrder) { CCASSERT( aChild != nullptr, "Child must be non-nullptr"); CCASSERT( dynamic_cast<ParticleSystem*>(aChild) != nullptr, "CCParticleBatchNode only supports QuadParticleSystems as children"); CCASSERT( _children.contains(aChild), "Child doesn't belong to batch" ); ParticleSystem* child = static_cast<ParticleSystem*>(aChild); if( zOrder == child->getLocalZOrder() ) { return; } // no reordering if only 1 child if (!_children.empty()) { int newIndex = 0, oldIndex = 0; getCurrentIndex(&oldIndex, &newIndex, child, zOrder); if( oldIndex != newIndex ) { // reorder _children->array child->retain(); _children.erase(oldIndex); _children.insert(newIndex, child); child->release(); // save old altasIndex int oldAtlasIndex = child->getAtlasIndex(); // update atlas index updateAllAtlasIndexes(); // Find new AtlasIndex int newAtlasIndex = 0; for( int i=0;i < _children.size();i++) { ParticleSystem* node = static_cast<ParticleSystem*>(_children.at(i)); if( node == child ) { newAtlasIndex = child->getAtlasIndex(); break; } } // reorder textureAtlas quads _textureAtlas->moveQuadsFromIndex(oldAtlasIndex, child->getTotalParticles(), newAtlasIndex); child->updateWithNoTime(); } } child->_setLocalZOrder(zOrder); } void ParticleBatchNode::getCurrentIndex(int* oldIndex, int* newIndex, Node* child, int z) { bool foundCurrentIdx = false; bool foundNewIdx = false; int minusOne = 0; auto count = _children.size(); for( int i=0; i < count; i++ ) { Node* pNode = _children.at(i); // new index if( pNode->getLocalZOrder() > z && ! foundNewIdx ) { *newIndex = i; foundNewIdx = true; if( foundCurrentIdx && foundNewIdx ) { break; } } // current index if( child == pNode ) { *oldIndex = i; foundCurrentIdx = true; if( ! foundNewIdx ) { minusOne = -1; } if( foundCurrentIdx && foundNewIdx ) { break; } } } if( ! foundNewIdx ) { *newIndex = static_cast<int>(count); } *newIndex += minusOne; } int ParticleBatchNode::searchNewPositionInChildrenForZ(int z) { auto count = _children.size(); for( int i=0; i < count; i++ ) { Node *child = _children.at(i); if (child->getLocalZOrder() > z) { return i; } } return static_cast<int>(count); } // override removeChild: void ParticleBatchNode::removeChild(Node* aChild, bool cleanup) { // explicit nil handling if (aChild == nullptr) return; CCASSERT( dynamic_cast<ParticleSystem*>(aChild) != nullptr, "CCParticleBatchNode only supports QuadParticleSystems as children"); CCASSERT(_children.contains(aChild), "CCParticleBatchNode doesn't contain the sprite. Can't remove it"); ParticleSystem* child = static_cast<ParticleSystem*>(aChild); // remove child helper _textureAtlas->removeQuadsAtIndex(child->getAtlasIndex(), child->getTotalParticles()); // after memmove of data, empty the quads at the end of array _textureAtlas->fillWithEmptyQuadsFromIndex(_textureAtlas->getTotalQuads(), child->getTotalParticles()); // particle could be reused for self rendering child->setBatchNode(nullptr); Node::removeChild(child, cleanup); updateAllAtlasIndexes(); } void ParticleBatchNode::removeChildAtIndex(int index, bool doCleanup) { removeChild(_children.at(index), doCleanup); } void ParticleBatchNode::removeAllChildrenWithCleanup(bool doCleanup) { for(const auto &child : _children) static_cast<ParticleSystem*>(child)->setBatchNode(nullptr); Node::removeAllChildrenWithCleanup(doCleanup); _textureAtlas->removeAllQuads(); } void ParticleBatchNode::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { CC_PROFILER_START("CCParticleBatchNode - draw"); if( _textureAtlas->getTotalQuads() == 0 ) { return; } _batchCommand.init( _globalZOrder, getGLProgram(), _blendFunc, _textureAtlas, _modelViewTransform); renderer->addCommand(&_batchCommand); CC_PROFILER_STOP("CCParticleBatchNode - draw"); } void ParticleBatchNode::increaseAtlasCapacityTo(ssize_t quantity) { CCLOG("cocos2d: ParticleBatchNode: resizing TextureAtlas capacity from [%lu] to [%lu].", (long)_textureAtlas->getCapacity(), (long)quantity); if( ! _textureAtlas->resizeCapacity(quantity) ) { // serious problems CCLOGWARN("cocos2d: WARNING: Not enough memory to resize the atlas"); CCASSERT(false,"XXX: ParticleBatchNode #increaseAtlasCapacity SHALL handle this assert"); } } //sets a 0'd quad into the quads array void ParticleBatchNode::disableParticle(int particleIndex) { V3F_C4B_T2F_Quad* quad = &((_textureAtlas->getQuads())[particleIndex]); quad->br.vertices.x = quad->br.vertices.y = quad->tr.vertices.x = quad->tr.vertices.y = quad->tl.vertices.x = quad->tl.vertices.y = quad->bl.vertices.x = quad->bl.vertices.y = 0.0f; } // ParticleBatchNode - add / remove / reorder helper methods // add child helper void ParticleBatchNode::insertChild(ParticleSystem* system, int index) { system->setAtlasIndex(index); if(_textureAtlas->getTotalQuads() + system->getTotalParticles() > _textureAtlas->getCapacity()) { increaseAtlasCapacityTo(_textureAtlas->getTotalQuads() + system->getTotalParticles()); // after a realloc empty quads of textureAtlas can be filled with gibberish (realloc doesn't perform calloc), insert empty quads to prevent it _textureAtlas->fillWithEmptyQuadsFromIndex(_textureAtlas->getCapacity() - system->getTotalParticles(), system->getTotalParticles()); } // make room for quads, not necessary for last child if (system->getAtlasIndex() + system->getTotalParticles() != _textureAtlas->getTotalQuads()) { _textureAtlas->moveQuadsFromIndex(index, index+system->getTotalParticles()); } // increase totalParticles here for new particles, update method of particle-system will fill the quads _textureAtlas->increaseTotalQuadsWith(system->getTotalParticles()); updateAllAtlasIndexes(); } //rebuild atlas indexes void ParticleBatchNode::updateAllAtlasIndexes() { int index = 0; for(const auto &child : _children) { ParticleSystem* partiSys = static_cast<ParticleSystem*>(child); partiSys->setAtlasIndex(index); index += partiSys->getTotalParticles(); } } // ParticleBatchNode - CocosNodeTexture protocol void ParticleBatchNode::updateBlendFunc() { if( ! _textureAtlas->getTexture()->hasPremultipliedAlpha()) _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; } void ParticleBatchNode::setTexture(Texture2D* texture) { _textureAtlas->setTexture(texture); // If the new texture has No premultiplied alpha, AND the blendFunc hasn't been changed, then update it if( texture && ! texture->hasPremultipliedAlpha() && ( _blendFunc.src == CC_BLEND_SRC && _blendFunc.dst == CC_BLEND_DST ) ) { _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; } } Texture2D* ParticleBatchNode::getTexture() const { return _textureAtlas->getTexture(); } void ParticleBatchNode::setBlendFunc(const BlendFunc &blendFunc) { _blendFunc = blendFunc; } // returns the blending function used for the texture const BlendFunc& ParticleBatchNode::getBlendFunc() const { return _blendFunc; } NS_CC_END
ItemFinder: farcall CheckForHiddenItems jr c, .found_something ld hl, .Script_FoundNothing jr .resume .found_something ld hl, .Script_FoundSomething .resume call QueueScript ld a, $1 ld [wItemEffectSucceeded], a ret .ItemfinderSound: ld c, 4 .sfx_loop push bc ld de, SFX_SECOND_PART_OF_ITEMFINDER call WaitPlaySFX ld de, SFX_TRANSACTION call WaitPlaySFX pop bc dec c jr nz, .sfx_loop ret .Script_FoundSomething: reloadmappart special UpdateTimePals callasm .ItemfinderSound writetext .Text_FoundSomething closetext end .Script_FoundNothing: reloadmappart special UpdateTimePals writetext .Text_FoundNothing closetext end .Text_FoundSomething: ; Yes! ITEMFINDER indicates there's an item nearby. text_far UnknownText_0x1c0a77 text_end .Text_FoundNothing: ; Nope! ITEMFINDER isn't responding. text_far UnknownText_0x1c0aa9 text_end
// http://turtle.sourceforge.net // // Copyright Mathieu Champlon 2011 // // 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) #include <turtle/mock.hpp> namespace { struct my_base { virtual ~my_base() {} virtual void my_method() = 0; virtual void my_method( int ) = 0; }; MOCK_BASE_CLASS( my_class, my_base ) { MOCK_METHOD( my_method, 0 ) }; }
####### # STORE GAME POSITION IN ARRAY # ------------ # inputs: a1 - Array start address # a2 - Array position starting from 0 # a3 - Value to store 1 = X 2 = O ####### store_in_array: slli a2, a2, 2 # shift by 2 -> multiply by 4 because every int is of size 4 add a1, a1, a2 # add position to start address sw a3, 0(a1) # save value ret
#include "Drone.hpp" #include "Scene.hpp" extern bool DISPLAY; Drone::Drone(const Vector3 &position, const Vector3 &scale) : SceneObject("point.dat", position, scale, nullptr) { /* ============[Shake]=========== */ // banan // 200ml mleka // milkyway // jagody 100g // lyzka masla orzechowego /* =========[Naleśniczki]======== */ // 4jajka // 180ml mleka // 200g mąki // 1 łyżeczka proszku do pieczenia // 2 łyżki cukru lub miodu // 1 banan // 1/2 łyżeczki cynamonu this->directionVec = {cos(0), sin(0), 0}; this->animation.goalOrientation = 0; this->anglesRPY[2] = this->animation.goalOrientation; Vector3 rotorScale = scale * 10; this->body = std::make_shared<Cuboid>(scale*0.5 + VectorZ*0.5, Vector3(), this); this->route = std::make_shared<Route>(Vector3(), Vector3(), 0, nullptr); auto tmpPtr1 = std::make_shared<Rotor>(SpinDirection_t::Clockwise, (*(this->body->vertexes[0])) + VectorZ * this->body->dimentions[2], rotorScale, this); this->rotors.push_back(std::move(tmpPtr1)); auto tmpPtr2 = std::make_shared<Rotor>(SpinDirection_t::Clockwise, (*(this->body->vertexes[1])) + VectorZ * this->body->dimentions[2], rotorScale, this); this->rotors.push_back(std::move(tmpPtr2)); auto tmpPtr3 = std::make_shared<Rotor>(SpinDirection_t::CounterClockwise, (*(this->body->vertexes[6])) + VectorZ * this->body->dimentions[2], rotorScale, this); this->rotors.push_back(std::move(tmpPtr3)); auto tmpPtr4 = std::make_shared<Rotor>(SpinDirection_t::CounterClockwise, (*(this->body->vertexes[7])) + VectorZ * this->body->dimentions[2], rotorScale, this); this->rotors.push_back(std::move(tmpPtr4)); // if(tmpPtr1 == nullptr) // exit(-1); if (DISPLAY){ Scene::AddToDrawable(this->route.get()); Scene::AddToDrawable(this->body.get()); } for (auto &rotor : this->rotors) { rotor->Update(); if (DISPLAY) { Scene::AddToDrawable(rotor.get()); } } this->Left(0); this->body->UpdatePoints(); this->animation.SetGoalPosition(this->position); this->animation.SetGoalOrientation(this->anglesRPY[2]); } Drone::~Drone() {} void Drone::Forward(const double &length) { // std::cout << "KAT: " << this->anglesRPY[2] << std::endl; // Vector3 direction = {cos(this->anglesRPY[2] * M_PI / 180), sin(this->anglesRPY[2] * M_PI / 180 ), 0}; this->animation.SetGoalPosition(this->position + this->directionVec * length); // rotors[0]->Rotate(15, VectorY); // rotors[2]->Rotate(15, VectorX); // rotors[1]->Rotate(-15, VectorX); // rotors[3]->Rotate(-15, VectorY); // this->body->Rotate(15, VectorY); } void Drone::GoVerdical(const double &length) { this->animation.SetGoalPosition(this->position + VectorZ * length); // rotors[0]->Rotate(0, VectorY); // rotors[1]->Rotate(0, VectorX); // rotors[2]->Rotate(0, VectorX); // rotors[3]->Rotate(0, VectorY); // this->body->Rotate(0, VectorY); } void Drone::Draw() { for (auto &rotor : this->rotors) if (DISPLAY) Scene::Draw(rotor.get()); Scene::Draw(this); } void Drone::Left(const double &angle) { this->animation.SetGoalOrientation(angle); } void Drone::Right(const double &angle) { this->animation.SetGoalOrientation(-angle); } bool Drone::Translated(){ auto translateDiff = this->animation.goalPosition - this->position; // std::cout << this->position.Length() << " " << translateDiff.Length() << std::endl; if (translateDiff.Length() > this->animation.translateStep.Length()){ this->Translate(this->animation.translateStep); } else if (translateDiff.Length() <= this->animation.translateStep.Length()) { this->Translate((translateDiff - this->animation.translateStep)); this->Translate(this->animation.translateStep); // std::cout << this->position << " " << translateDiff << std::endl; return true; } return false; } bool Drone::Rotated(){ auto angleDiff = this->anglesRPY[2] - this->animation.goalOrientation; // std::cout << anglesRPY[2] << " "<<this->animation.goalOrientation << std::endl; if (std::fabs(angleDiff) >= this->animation.rotateStep) { if (angleDiff < 0) this->Rotate(this->animation.rotateStep, VectorZ); else if (angleDiff > 0) this->Rotate(-this->animation.rotateStep, VectorZ); } else if (anglesRPY[2] == this->animation.goalOrientation) { return true; } else if (std::fabs(this->anglesRPY[2] - this->animation.goalOrientation) <= this->animation.rotateStep) { this->Rotate(-angleDiff, VectorZ); } this->directionVec = {cos(this->anglesRPY[2] * M_PI / 180), sin(this->anglesRPY[2] * M_PI / 180), 0}; return false; } // TO DO PID void Drone::FlyTo(const Vector3 &position, const double &height) { Vector3 moving = this->position*(-1) + position; double inAcos = (this->directionVec[0] * moving[0] + this->directionVec[1] * moving[1]) / moving.Length(); if(inAcos <= -1) inAcos += 1; else if (inAcos >= 1) inAcos -= 1; double angle = acos(inAcos) * 180 / M_PI; // this->MakeRoute(position, height); this->moves.push([height, this]() { this->GoVerdical(height);}); this->moves.push([angle, this]() { this->Right(angle); }); this->moves.push([moving, this]() { this->Forward(moving.Length()); }); this->moves.push([height, this]() { this->GoVerdical(-height); }); } void Drone::MakeRoute(const double &height, const double &angle, const double &length) { double angleRad = (this->anglesRPY[2] - angle) * M_PI / 180; this->route->startPoint = this->position; this->route->finishPoint = Vector3({cos(angleRad), sin(angleRad), 0}) * length + this->position; this->route->height = height; this->route->Update(); } void Drone::Update() { // std::cout << "Chce latać" << std::endl; if (this->Translated() && this->Rotated()) { if (!this->moves.empty()){ this->moves.front()(); this->moves.pop(); } } this->UpdatePoints(); this->body->UpdatePoints(); for (auto &rotor : this->rotors) { rotor->Update(); } } void Drone::ChangeColor(const int &x){ Scene::api.UsunNazwePliku(this->body->Name()); PzG::InfoPlikuDoRysowania *wInfoPliku1 = &Scene::api.DodajNazwePliku((std::string(TMP_FOLDER) + this->body->Name()).c_str()); wInfoPliku1->ZmienKolor(x); for(auto &rotor: this->rotors){ Scene::api.UsunNazwePliku(rotor->Name()); wInfoPliku1 = &Scene::api.DodajNazwePliku((std::string(TMP_FOLDER) + rotor->Name()).c_str()); wInfoPliku1->ZmienKolor(x); } }
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* * Copyright 2011-2020 Couchbase, Inc. * * 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 "config.h" #include <gtest/gtest.h> #include <libcouchbase/couchbase.h> #include "jsparse/parser.h" #include "contrib/lcb-jsoncpp/lcb-jsoncpp.h" #include "t_jsparse.h" class JsonParseTest : public ::testing::Test { }; using namespace lcb::jsparse; static std::string iov2s(const lcb_IOV &iov) { return std::string(reinterpret_cast<const char *>(iov.iov_base), iov.iov_len); } struct Context : Parser::Actions { lcb_STATUS rc; bool received_done; std::string meta; std::vector<std::string> rows; Context() { reset(); } void reset() { rc = LCB_SUCCESS; received_done = false; meta.clear(); rows.clear(); } void JSPARSE_on_row(const Row &row) { rows.push_back(iov2s(row.row)); } void JSPARSE_on_complete(const std::string &s) { meta.assign(s); received_done = true; } void JSPARSE_on_error(const std::string &) { rc = LCB_ERR_PROTOCOL_ERROR; received_done = true; } }; static bool validateJsonRows(const char *txt, size_t ntxt, Parser::Mode mode) { Context cx; Parser parser(mode, &cx); for (size_t ii = 0; ii < ntxt; ii++) { parser.feed(txt + ii, 1); } EXPECT_EQ(LCB_SUCCESS, cx.rc); lcb_IOV out; parser.get_postmortem(out); EXPECT_EQ(cx.meta, iov2s(out)); Json::Value root; EXPECT_TRUE(Json::Reader().parse(cx.meta, root)); return true; } static bool validateBadParse(const char *txt, size_t ntxt, Parser::Mode mode) { Context cx; Parser p(mode, &cx); p.feed(txt, ntxt); EXPECT_EQ(LCB_ERR_PROTOCOL_ERROR, cx.rc); return true; } TEST_F(JsonParseTest, testFTS) { ASSERT_TRUE(validateJsonRows(JSON_fts_good, sizeof(JSON_fts_good), Parser::MODE_FTS)); ASSERT_TRUE(validateBadParse(JSON_fts_bad, sizeof(JSON_fts_bad), Parser::MODE_FTS)); ASSERT_TRUE(validateBadParse(JSON_fts_bad2, sizeof(JSON_fts_bad2), Parser::MODE_FTS)); } TEST_F(JsonParseTest, testN1QL) { ASSERT_TRUE(validateJsonRows(JSON_n1ql_nonempty, sizeof(JSON_n1ql_nonempty), Parser::MODE_N1QL)); ASSERT_TRUE(validateJsonRows(JSON_n1ql_empty, sizeof(JSON_n1ql_empty), Parser::MODE_N1QL)); ASSERT_TRUE(validateBadParse(JSON_n1ql_bad, sizeof(JSON_n1ql_bad), Parser::MODE_N1QL)); } TEST_F(JsonParseTest, testInvalidJSON) { std::string input = "503 Service Unavailable"; Json::Value meta; ASSERT_TRUE(Json::Reader().parse(input.c_str(), input.c_str() + input.size(), meta)); ASSERT_FALSE(Json::Reader(Json::Features::strictMode()).parse(input.c_str(), input.c_str() + input.size(), meta)); }
; size_t dtog(double x, char *buf, uint16_t prec, uint16_t flag) __z88dk_callee SECTION code_clib SECTION code_stdlib PUBLIC _dtog_callee EXTERN dcallee1, asm_dtog _dtog_callee: call dcallee1 ; AC' = x pop af pop hl pop de pop bc push af jp asm_dtog
.public _start .extern nesto123 .data a: .word 0x12345678 t: .long 0x12343 r: .char 34 .align .skip 1 .text _start: callt r1, 0xffff call r2, 6 .data.ert b: .char 3 .text.ert add r1, r2 label1: ldch r2, 0x567
; A157508: a(n) = 1458*n - 18. ; 1440,2898,4356,5814,7272,8730,10188,11646,13104,14562,16020,17478,18936,20394,21852,23310,24768,26226,27684,29142,30600,32058,33516,34974,36432,37890,39348,40806,42264,43722,45180,46638,48096,49554,51012,52470,53928,55386,56844,58302,59760,61218,62676,64134,65592,67050,68508,69966,71424,72882,74340,75798,77256,78714,80172,81630,83088,84546,86004,87462,88920,90378,91836,93294,94752,96210,97668,99126,100584,102042,103500,104958,106416,107874,109332,110790,112248,113706,115164,116622,118080,119538 mul $0,1458 add $0,1440
// --------------------------------------------------------------------------- // // This file is part of the <kortex> library suite // // Copyright (C) 2013 Engin Tola // // See LICENSE file for license information. // // author: Engin Tola // e-mail: engintola@gmail.com // web : http://www.engintola.com // // --------------------------------------------------------------------------- #include <algorithm> #include <climits> #include <kortex/rect2.h> #include <kortex/check.h> namespace kortex { bool Rect2f::is_inside(float x, float y) const { if( y>=ly && y<uy && x>=lx && x<ux ) return true; else return false; } bool Rect2f::is_inside_y(float y) const { if( y>=ly && y<uy ) return true; else return false; } bool Rect2f::is_inside_x(float x) const { if( x>=lx && x<ux ) return true; else return false; } bool Rect2f::is_inside(int x, int y) const { if( y>=ly && y<uy && x>=lx && x<ux ) return true; else return false; } bool Rect2f::is_inside_y(int y) const { if( y>=ly && y<uy ) return true; else return false; } bool Rect2f::is_inside_x(int x) const { if( x>=lx && x<ux ) return true; else return false; } void Rect2f::print() const { printf( "Boundary: [x %f %f ] [y %f %f] [sz %f %f]\n", lx, ux, ly, uy, dx, dy ); } // // // void Rect2i::reset_max_region() { logman_warning( "there is a possible bug here - below min/max should be flipped" ); init( INT_MIN, INT_MAX, INT_MIN, INT_MAX ); id = 0; } bool Rect2i::is_inside(int x, int y) const { if( x>=lx && x<ux && y>=ly && y<uy ) return true; else return false; } bool Rect2i::is_inside_x(int x) const { if( x>=lx && x<ux ) return true; else return false; } bool Rect2i::is_inside_y(int y) const { if( y>=ly && y<uy ) return true; else return false; } // void rect_move( const Rect2i& irect, int mx, int my, Rect2i& orect ) { orect.init( mx+irect.lx, mx+irect.ux, my+irect.ly, my+irect.uy ); orect.id = irect.id; } void rect_union( const Rect2i& r0, const Rect2i& r1, Rect2i& out ) { out = r0; out.update( r1.lx, r1.ly ); out.update( r1.ux, r1.uy ); } bool rect_intersect( const Rect2i& r0, const Rect2i& r1, Rect2i& out ) { if( r1.lx > r0.ux ) return false; if( r0.lx > r1.ux ) return false; if( r1.ly > r0.uy ) return false; if( r0.ly > r1.uy ) return false; int olx = std::max( r0.lx, r1.lx ); int oux = std::min( r0.ux, r1.ux ); int oly = std::max( r0.ly, r1.ly ); int ouy = std::min( r0.uy, r1.uy ); out.init(olx, oux, oly, ouy); return true; } }
/*********************************************************************** * File : postgisrasterdataset.cpp * Project: PostGIS Raster driver * Purpose: GDAL Dataset implementation for PostGIS Raster driver * Author: Jorge Arevalo, jorge.arevalo@deimos-space.com * jorgearevalo@libregis.org * * Author: David Zwarg, dzwarg@azavea.com * * Last changes: $Id$ * *********************************************************************** * Copyright (c) 2009 - 2013, Jorge Arevalo, David Zwarg * Copyright (c) 2013, Even Rouault <even dot rouault at mines-paris dot org> * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. **********************************************************************/ #include "gdal_frmts.h" #include "postgisraster.h" #include <math.h> #include <algorithm> CPL_CVSID("$Id$") #ifdef _WIN32 #define rint(x) floor((x) + 0.5) #endif /* PostgreSQL defaults */ #define DEFAULT_SCHEMA "public" #define DEFAULT_COLUMN "rast" /** Note on read performance on mode=2: There are different situations: 1) the table is registered in the raster_columns table and number of bands, minx,miny,maxx,maxy are available a) no where clause, the table has a primary key and a GIST index on the raster column. If the raster_columns advertize a scale_x and scale_y, use it. Otherwise take the metadata of 10 rasters and compute and average scale_x, scale_y With above information, we can build the dataset definition. (Following logic is implemented in LoadSources()) During a IRasterIO() query, i) we will do a SQL query to retrieve the PKID of tiles that intersect the query window. ii) If some tiles are not registered as sources, then do a SQL query to fetch their metadata and instantiate them and register them. iii) If some tiles are not cached, then determine if the query window is not too big (w.r.t. GDAL cache), and if not, then do a SQL query to fetch their raster column. Note: if raster_columns show that all tiles have same dimensions, we can merge the query ii) and iii) in the same one. b) otherwise, do a full scan of metadata to build the sources 2) otherwise, throw a warning to the user and do a full scan of metadata is needed to build the sources For 1b) and 2), during a IRasterIO() query, determine which sources are needed and not cached. (Following logic is implemented in IRasterIO()) If the query window is not too big, If there's a primary key, then do a SQL query on the IDs of uncached sources to fetch their raster column and cache them. Otherwise if there's a GIST index, do a SQL spatial query on the window to fetch their raster column, and cache them (identification with registered sources is done with the top-left coordinates) Otherwise do a SQL query based on the range of top-left coordinates of tiles that intersect the query window. Conclusion: best performance is achieved with: no where clause, a primary key, a GIST index, known table extent and, with moderate performance advantage : - same scale_x, scale_y to save an initial SQL query, - same blocksize_x, blocksize_y to save one SQL query per IRasterIO() */ /************************ * \brief Constructor ************************/ PostGISRasterDataset::PostGISRasterDataset() : VRTDataset(0, 0), papszSubdatasets(nullptr), nSrid(-1), nOverviewFactor(1), nBandsToCreate(0), poConn(nullptr), bRegularBlocking(false), bAllTilesSnapToSameGrid(false), bCheckAllTiles(CPLTestBool( CPLGetConfigOption("PR_ALLOW_WHOLE_TABLE_SCAN", "YES"))), pszSchema(nullptr), pszTable(nullptr), pszColumn(nullptr), pszWhere(nullptr), pszPrimaryKeyName(nullptr), bIsFastPK(false), bHasTriedFetchingPrimaryKeyName(false), pszProjection(nullptr), // Default resolutionStrategy(AVERAGE_APPROX_RESOLUTION), nMode(NO_MODE), m_nTiles(0), xmin(0.0), ymin(0.0), xmax(0.0), ymax(0.0), papoSourcesHolders(nullptr), hQuadTree(nullptr), bHasBuiltOverviews(false), nOverviewCount(0), poParentDS(nullptr), papoOverviewDS(nullptr), bAssumeMultiBandReadPattern(true), nNextExpectedBand(1), nXOffPrev(0), nYOffPrev(0), nXSizePrev(0), nYSizePrev(0), bHasTriedHasSpatialIndex(false), bHasSpatialIndex(false), bBuildQuadTreeDynamically(false), bTilesSameDimension(false), nTileWidth(0), nTileHeight(0) { adfGeoTransform[GEOTRSFRM_TOPLEFT_X] = 0.0; adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1] = 0.0; adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] = 0.0; adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] = 0.0; adfGeoTransform[GEOTRSFRM_WE_RES] = CPLAtof(CPLGetConfigOption("PR_WE_RES", NO_VALID_RES)); adfGeoTransform[GEOTRSFRM_NS_RES] = CPLAtof(CPLGetConfigOption("PR_NS_RES", NO_VALID_RES)); const char * pszTmp = nullptr; // We ignore this option if we provided the desired resolution if (CPLIsEqual(adfGeoTransform[GEOTRSFRM_WE_RES], CPLAtof(NO_VALID_RES)) || CPLIsEqual(adfGeoTransform[GEOTRSFRM_NS_RES], CPLAtof(NO_VALID_RES))) { // Resolution didn't have a valid value, so, we initiate it adfGeoTransform[GEOTRSFRM_WE_RES] = 0.0; adfGeoTransform[GEOTRSFRM_NS_RES] = 0.0; pszTmp = CPLGetConfigOption("PR_RESOLUTION_STRATEGY", "AVERAGE_APPROX"); if (EQUAL(pszTmp, "LOWEST")) resolutionStrategy = LOWEST_RESOLUTION; else if (EQUAL(pszTmp, "HIGHEST")) resolutionStrategy = HIGHEST_RESOLUTION; else if (EQUAL(pszTmp, "USER")) resolutionStrategy = USER_RESOLUTION; else if (EQUAL(pszTmp, "AVERAGE")) resolutionStrategy = AVERAGE_RESOLUTION; } else { resolutionStrategy = USER_RESOLUTION; #ifdef DEBUG_VERBOSE pszTmp = "USER"; #endif } #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::Constructor:" "STRATEGY = %s", pszTmp); #endif poDriver = nullptr; nRasterXSize = 0; nRasterYSize = 0; SetWritable(false); // TODO: Parametrize bAllTilesSnapToSameGrid. It controls if all the // raster rows, in ONE_RASTER_PER_TABLE mode, must be checked to // test if they snap to the same grid and have the same SRID. It can // be the user decision, if he/she's sure all the rows pass the // test and want more speed. } /************************ * \brief Constructor ************************/ PostGISRasterDataset::~PostGISRasterDataset() { if (pszSchema) { CPLFree(pszSchema); pszSchema = nullptr; } if (pszTable) { CPLFree(pszTable); pszTable = nullptr; } if (pszColumn) { CPLFree(pszColumn); pszColumn = nullptr; } if (pszWhere) { CPLFree(pszWhere); pszWhere = nullptr; } if (pszProjection) { CPLFree(pszProjection); pszProjection = nullptr; } if (pszPrimaryKeyName) { CPLFree(pszPrimaryKeyName); pszPrimaryKeyName = nullptr; } if (papszSubdatasets) { CSLDestroy(papszSubdatasets); papszSubdatasets = nullptr; } if (hQuadTree) { CPLQuadTreeDestroy(hQuadTree); hQuadTree = nullptr; } // Call it now so that the VRT sources // are deleted and that there is no longer any code // referencing the bands of the source holders. // Otherwise this would go wrong because // of the deleting the source holders just below. CloseDependentDatasets(); if (papoSourcesHolders) { int i; for(i = 0; i < m_nTiles; i++) { if (papoSourcesHolders[i]) delete papoSourcesHolders[i]; } VSIFree(papoSourcesHolders); papoSourcesHolders = nullptr; } } /************************************************************************/ /* CloseDependentDatasets() */ /************************************************************************/ int PostGISRasterDataset::CloseDependentDatasets() { int bHasDroppedRef = VRTDataset::CloseDependentDatasets(); if( nOverviewCount > 0 ) { int i; for(i = 0; i < nOverviewCount; i++) { delete papoOverviewDS[i]; } CPLFree(papoOverviewDS); papoOverviewDS = nullptr; nOverviewCount = 0; bHasDroppedRef = TRUE; } return bHasDroppedRef; } /************************************************************************/ /* HasSpatialIndex() */ /************************************************************************/ GBool PostGISRasterDataset::HasSpatialIndex() { CPLString osCommand; PGresult* poResult = nullptr; // If exists, return it if (bHasTriedHasSpatialIndex) { return bHasSpatialIndex; } bHasTriedHasSpatialIndex = true; /* For debugging purposes only */ if( CPLTestBool(CPLGetConfigOption("PR_DISABLE_GIST", "FALSE") ) ) return false; // Copyright dustymugs !!! osCommand.Printf( "SELECT n.nspname AS schema_name, c2.relname AS table_name, att.attname AS column_name, " " c.relname AS index_name, am.amname AS index_type " "FROM pg_catalog.pg_class c " "JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid " "JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid " "JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace " "JOIN pg_am am ON c.relam = am.oid " "JOIN pg_attribute att ON att.attrelid = c2.oid " "AND pg_catalog.format_type(att.atttypid, att.atttypmod) = 'raster' " "WHERE c.relkind IN ('i') " "AND am.amname = 'gist' " "AND strpos(split_part(pg_catalog.pg_get_indexdef(i.indexrelid, 0, true), ' gist ', 2), att.attname) > 0 " "AND n.nspname = '%s' " "AND c2.relname = '%s' " "AND att.attname = '%s' ", pszSchema, pszTable, pszColumn); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::HasSpatialIndex(): Query: %s", osCommand.c_str()); #endif poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) <= 0 ) { bHasSpatialIndex = false; CPLDebug("PostGIS_Raster", "For better performance, creating a spatial index " "with 'CREATE INDEX %s_%s_%s_gist_idx ON %s.%s USING GIST (ST_ConvexHull(%s))' is advised", pszSchema, pszTable, pszColumn, pszSchema, pszTable, pszColumn); } else { bHasSpatialIndex = true; } if( poResult ) PQclear(poResult); return bHasSpatialIndex; } /*********************************************************************** * \brief Look for a primary key in the table selected by the user * * If the table does not have a primary key, it returns NULL **********************************************************************/ const char * PostGISRasterDataset::GetPrimaryKeyRef() { CPLString osCommand; PGresult* poResult = nullptr; // If exists, return it if (bHasTriedFetchingPrimaryKeyName) { return pszPrimaryKeyName; } bHasTriedFetchingPrimaryKeyName = true; /* For debugging purposes only */ if( CPLTestBool(CPLGetConfigOption("PR_DISABLE_PK", "FALSE") ) ) return nullptr; /* Determine the primary key/unique column on the table */ osCommand.Printf("select d.attname from pg_catalog.pg_constraint " "as a join pg_catalog.pg_indexes as b on a.conname = " "b.indexname join pg_catalog.pg_class as c on c.relname = " "b.tablename join pg_catalog.pg_attribute as d on " "c.relfilenode = d.attrelid where b.schemaname = '%s' and " "b.tablename = '%s' and d.attnum = a.conkey[1] and a.contype " "in ('p', 'u')", pszSchema, pszTable); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::GetPrimaryKeyRef(): Query: %s", osCommand.c_str()); #endif poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) <= 0 ) { PQclear(poResult); /** * Maybe there is no primary key or unique constraint; a * sequence will also suffice; get the first one **/ osCommand.Printf("select cols.column_name from " "information_schema.columns as cols join " "information_schema.sequences as seqs on " "cols.column_default like '%%'||seqs.sequence_name||'%%' " "where cols.table_schema = '%s' and cols.table_name = '%s'", pszSchema, pszTable); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::GetPrimaryKeyRef(): Query: %s", osCommand.c_str()); #endif poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) <= 0) { CPLDebug("PostGIS_Raster", "PostGISRasterDataset::GetPrimaryKeyRef(): Could not " "find a primary key or unique column on the specified " "table %s.%s. For better performance, creating a primary key on the table is advised.", pszSchema, pszTable); pszPrimaryKeyName = nullptr; // Just in case } else { pszPrimaryKeyName = CPLStrdup(PQgetvalue(poResult, 0, 0)); } } // Ok, get the primary key else { pszPrimaryKeyName = CPLStrdup(PQgetvalue(poResult, 0, 0)); bIsFastPK = true; } PQclear(poResult); return pszPrimaryKeyName; } /*********************************************************************** * \brief Look for raster tables in database and store them as * subdatasets * * If no table is provided in connection string, the driver looks for * the existent raster tables in the schema given as argument. This * argument, however, is optional. If a NULL value is provided, the * driver looks for all raster tables in all schemas of the * user-provided database. * * NOTE: Permissions are managed by libpq. The driver only returns an * error if an error is returned when trying to access to tables not * allowed to the current user. **********************************************************************/ GBool PostGISRasterDataset::BrowseDatabase(const char* pszCurrentSchema, const char* pszValidConnectionString) { char* l_pszSchema = nullptr; char* l_pszTable = nullptr; char* l_pszColumn = nullptr; int i = 0; int nTuples = 0; PGresult * poResult = nullptr; CPLString osCommand; /************************************************************* * Fetch all the raster tables and store them as subdatasets *************************************************************/ if (pszCurrentSchema == nullptr) { osCommand.Printf("select pg_namespace.nspname as schema, " "pg_class.relname as table, pg_attribute.attname as column " "from pg_class, pg_namespace,pg_attribute, pg_type where " "pg_class.relnamespace = pg_namespace.oid and " "pg_class.oid = pg_attribute.attrelid and " "pg_attribute.atttypid = pg_type.oid and " "pg_type.typname = 'raster'"); poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) <= 0) { ReportError(CE_Failure, CPLE_AppDefined, "Error browsing database for PostGIS Raster tables: %s", PQerrorMessage(poConn)); if (poResult != nullptr) PQclear(poResult); return false; } nTuples = PQntuples(poResult); for (i = 0; i < nTuples; i++) { l_pszSchema = PQgetvalue(poResult, i, 0); l_pszTable = PQgetvalue(poResult, i, 1); l_pszColumn = PQgetvalue(poResult, i, 2); papszSubdatasets = CSLSetNameValue(papszSubdatasets, CPLSPrintf("SUBDATASET_%d_NAME", (i + 1)), CPLSPrintf("PG:%s schema=%s table=%s column=%s", pszValidConnectionString, l_pszSchema, l_pszTable, l_pszColumn)); papszSubdatasets = CSLSetNameValue(papszSubdatasets, CPLSPrintf("SUBDATASET_%d_DESC", (i + 1)), CPLSPrintf("PostGIS Raster table at %s.%s (%s)", l_pszSchema, l_pszTable, l_pszColumn)); } PQclear(poResult); } /*************************************************************** * Fetch all the schema's raster tables and store them as * subdatasets **************************************************************/ else { osCommand.Printf("select pg_class.relname as table, " "pg_attribute.attname as column from pg_class, " "pg_namespace,pg_attribute, pg_type where " "pg_class.relnamespace = pg_namespace.oid and " "pg_class.oid = pg_attribute.attrelid and " "pg_attribute.atttypid = pg_type.oid and " "pg_type.typname = 'raster' and " "pg_namespace.nspname = '%s'", pszCurrentSchema); poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) <= 0) { ReportError(CE_Failure, CPLE_AppDefined, "Error browsing database for PostGIS Raster tables: %s", PQerrorMessage(poConn)); if (poResult != nullptr) PQclear(poResult); return false; } nTuples = PQntuples(poResult); for (i = 0; i < nTuples; i++) { l_pszTable = PQgetvalue(poResult, i, 0); l_pszColumn = PQgetvalue(poResult, i, 1); papszSubdatasets = CSLSetNameValue(papszSubdatasets, CPLSPrintf("SUBDATASET_%d_NAME", (i + 1)), CPLSPrintf("PG:%s schema=%s table=%s column=%s", pszValidConnectionString, pszCurrentSchema, l_pszTable, l_pszColumn)); papszSubdatasets = CSLSetNameValue(papszSubdatasets, CPLSPrintf("SUBDATASET_%d_DESC", (i + 1)), CPLSPrintf("PostGIS Raster table at %s.%s (%s)", pszCurrentSchema, l_pszTable, l_pszColumn)); } PQclear(poResult); } return true; } /*********************************************************************** * \brief Look for overview tables for the bands of the current dataset **********************************************************************/ PROverview * PostGISRasterDataset::GetOverviewTables(int * pnOverviews) { PROverview * poOV = nullptr; CPLString osCommand; osCommand.Printf("SELECT o_table_name, overview_factor, " "o_raster_column, o_table_schema FROM raster_overviews " "WHERE r_table_schema = '%s' AND r_table_name = '%s' AND " "r_raster_column = '%s' ORDER BY overview_factor", this->pszSchema, this->pszTable, this->pszColumn); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::GetOverviewTables(): Query: %s", osCommand.c_str()); #endif PGresult* poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) < 0) { ReportError(CE_Failure, CPLE_AppDefined, "Error looking for overview tables: %s", PQerrorMessage(poConn)); if (poResult) PQclear(poResult); return nullptr; } else if (PQntuples(poResult) == 0) { CPLDebug("PostGIS_Raster", "PostGISRasterDataset::GetOverviewTables(): No overviews " "for table %s.%s", pszTable, pszSchema); if (poResult) PQclear(poResult); return nullptr; } int nTuples = PQntuples(poResult); poOV = (PROverview *)VSIMalloc2(nTuples, sizeof(PROverview)); if (poOV == nullptr) { ReportError(CE_Failure, CPLE_AppDefined, "Error looking for overview tables"); PQclear(poResult); return nullptr; } int iOVerview = 0; for(iOVerview = 0; iOVerview < nTuples; iOVerview++) { poOV[iOVerview].pszSchema = CPLStrdup(PQgetvalue(poResult, iOVerview, 3)); poOV[iOVerview].pszTable = CPLStrdup(PQgetvalue(poResult, iOVerview, 0)); poOV[iOVerview].pszColumn = CPLStrdup(PQgetvalue(poResult, iOVerview, 2)); poOV[iOVerview].nFactor = atoi(PQgetvalue(poResult, iOVerview, 1)); } if (pnOverviews) *pnOverviews = nTuples; PQclear(poResult); return poOV; } /*********************************************************************** * \brief Build overview datasets ***********************************************************************/ void PostGISRasterDataset::BuildOverviews() { if( bHasBuiltOverviews || poParentDS != nullptr ) return; bHasBuiltOverviews = true; /******************************************************************* * We also get the names of the overview tables, if they exist. So, * we'll can use them to create the overview datasets. ******************************************************************/ int nOV = 0; PROverview * poOV = GetOverviewTables(&nOV); if (poOV) { papoOverviewDS = (PostGISRasterDataset**) CPLCalloc(nOV, sizeof(PostGISRasterDataset*)); nOverviewCount = 0; int iOV; for(iOV = 0; iOV < nOV; iOV++) { PostGISRasterDataset* poOvrDS = new PostGISRasterDataset(); poOvrDS->nOverviewFactor = poOV[iOV].nFactor; poOvrDS->poConn = poConn; poOvrDS->eAccess = eAccess; poOvrDS->nMode = nMode; poOvrDS->pszSchema = poOV[iOV].pszSchema; // takes ownership poOvrDS->pszTable = poOV[iOV].pszTable; // takes ownership poOvrDS->pszColumn = poOV[iOV].pszColumn; // takes ownership poOvrDS->pszWhere = pszWhere ? CPLStrdup(pszWhere) : nullptr; poOvrDS->poParentDS = this; if (!CPLTestBool(CPLGetConfigOption("PG_DEFERRED_OVERVIEWS", "YES")) && (!poOvrDS->SetRasterProperties(nullptr) || poOvrDS->GetRasterCount() != GetRasterCount())) { delete poOvrDS; } else { papoOverviewDS[nOverviewCount ++] = poOvrDS; } } VSIFree(poOV); } } /*********************************************************************** * \brief Returns overview count ***********************************************************************/ int PostGISRasterDataset::GetOverviewCount() { BuildOverviews(); return nOverviewCount; } /*********************************************************************** * \brief Returns overview dataset ***********************************************************************/ PostGISRasterDataset* PostGISRasterDataset::GetOverviewDS(int iOvr) { if( iOvr < 0 || iOvr > GetOverviewCount() ) return nullptr; return papoOverviewDS[iOvr]; } /*********************************************************************** * \brief Calculates the destination window for a VRT source, taking * into account that the source is a PostGIS Raster tile and the * destination is the general dataset itself * * This method is adapted from gdalbuildvrt as is in GDAL 1.10.0 ***********************************************************************/ GBool PostGISRasterDataset::GetDstWin( PostGISRasterTileDataset * psDP, int* pnDstXOff, int* pnDstYOff, int* pnDstXSize, int* pnDstYSize) { double we_res = this->adfGeoTransform[GEOTRSFRM_WE_RES]; double ns_res = this->adfGeoTransform[GEOTRSFRM_NS_RES]; double adfTileGeoTransform[6]; psDP->GetGeoTransform(adfTileGeoTransform); *pnDstXOff = (int) (0.5 + (adfTileGeoTransform[GEOTRSFRM_TOPLEFT_X] - xmin) / we_res); if( ns_res < 0 ) *pnDstYOff = (int) (0.5 + (ymax - adfTileGeoTransform[GEOTRSFRM_TOPLEFT_Y]) / -ns_res); else *pnDstYOff = (int) (0.5 + (adfTileGeoTransform[GEOTRSFRM_TOPLEFT_Y] - ymin) / ns_res); *pnDstXSize = (int) (0.5 + psDP->GetRasterXSize() * adfTileGeoTransform[GEOTRSFRM_WE_RES] / we_res); *pnDstYSize = (int) (0.5 + psDP->GetRasterYSize() * adfTileGeoTransform[GEOTRSFRM_NS_RES] / ns_res); return true; } /*********************************************************************** * \brief Add tiles bands as complex source for raster bands. **********************************************************************/ GBool PostGISRasterDataset::AddComplexSource(PostGISRasterTileDataset* poRTDS) { // Parameters to add the tile bands as sources int nDstXOff = 0; int nDstYOff = 0; int nDstXSize = 0; int nDstYSize = 0; // Get src and dst parameters GBool bValidTile = GetDstWin(poRTDS, &nDstXOff, &nDstYOff, &nDstXSize, &nDstYSize); if (!bValidTile) return false; #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::AddComplexSource: " "Tile bounding box from (%d, %d) of size (%d, %d) will " "cover raster bounding box from (%d, %d) of size " "(%d, %d)", 0, 0, poRTDS->GetRasterXSize(), poRTDS->GetRasterYSize(), nDstXOff, nDstYOff, nDstXSize, nDstYSize); #endif // Add tiles bands as sources for the raster bands for(int iBand = 0; iBand < nBandsToCreate; iBand++) { PostGISRasterRasterBand * prb = (PostGISRasterRasterBand *)GetRasterBand(iBand + 1); int bHasNoData = FALSE; double dfBandNoDataValue = prb->GetNoDataValue(&bHasNoData); PostGISRasterTileRasterBand * prtb = (PostGISRasterTileRasterBand *) poRTDS->GetRasterBand(iBand + 1); prb->AddComplexSource(prtb, 0, 0, poRTDS->GetRasterXSize(), poRTDS->GetRasterYSize(), nDstXOff, nDstYOff, nDstXSize, nDstYSize, 0.0, 1.0, (bHasNoData) ? dfBandNoDataValue : VRT_NODATA_UNSET); prtb->poSource = prb->papoSources[prb->nSources-1]; } return true; } /************************************************************************/ /* GetMatchingSourceRef() */ /************************************************************************/ /** * \brief Get the tile dataset that matches the given upper left pixel **/ PostGISRasterTileDataset * PostGISRasterDataset::GetMatchingSourceRef(double dfUpperLeftX, double dfUpperLeftY) { int i; PostGISRasterTileDataset * poRTDS = nullptr; for(i = 0; i < m_nTiles; i++) { poRTDS = papoSourcesHolders[i]; if (CPLIsEqual(poRTDS->adfGeoTransform[GEOTRSFRM_TOPLEFT_X], dfUpperLeftX) && CPLIsEqual(poRTDS->adfGeoTransform[GEOTRSFRM_TOPLEFT_Y], dfUpperLeftY)) { return poRTDS; } } return nullptr; } /************************************************************************/ /* CacheTile() */ /************************************************************************/ void PostGISRasterDataset::CacheTile(const char* pszMetadata, const char* pszRaster, const char *pszPKID, int nBand, int bAllBandCaching) { /** * Get metadata record and unpack it **/ char* pszRes = CPLStrdup(pszMetadata); // Skip first "(" char* pszFilteredRes = pszRes + 1; // Skip last ")" pszFilteredRes[strlen(pszFilteredRes)-1] = '\0'; // Tokenize char** papszParams = CSLTokenizeString2(pszFilteredRes, ",", CSLT_HONOURSTRINGS | CSLT_ALLOWEMPTYTOKENS); CPLAssert(CSLCount(papszParams) >= ELEMENTS_OF_METADATA_RECORD); CPLFree(pszRes); double dfTilePixelSizeX = CPLAtof(papszParams[POS_UPPERLEFTX]); double dfTilePixelSizeY = CPLAtof(papszParams[POS_UPPERLEFTY]); int nTileXSize = atoi(papszParams[POS_WIDTH]); int nTileYSize = atoi(papszParams[POS_HEIGHT]); CSLDestroy(papszParams); papszParams = nullptr; /** * Get actual raster band data **/ int nBandDataTypeSize = GDALGetDataTypeSize(GetRasterBand(nBand)->GetRasterDataType()) / 8; int nExpectedBandDataSize = nTileXSize * nTileYSize * nBandDataTypeSize; int nWKBLength = 0; GByte* pbyData = CPLHexToBinary(pszRaster, &nWKBLength); int nExpectedBands = bAllBandCaching ? GetRasterCount() : 1; int nExpectedWKBLength = RASTER_HEADER_SIZE + BAND_SIZE(nBandDataTypeSize, nExpectedBandDataSize) * nExpectedBands; if( nWKBLength != nExpectedWKBLength ) { CPLDebug("PostGIS_Raster", "nWKBLength=%d, nExpectedWKBLength=%d", nWKBLength, nExpectedWKBLength ); CPLFree(pbyData); return; } // Do byte-swapping if necessary */ int bIsLittleEndian = (pbyData[0] == 1); #ifdef CPL_LSB int bSwap = !bIsLittleEndian; #else int bSwap = bIsLittleEndian; #endif PostGISRasterTileDataset* poRTDS = nullptr; if( GetPrimaryKeyRef() != nullptr ) poRTDS = GetMatchingSourceRef(pszPKID); else poRTDS = GetMatchingSourceRef(dfTilePixelSizeX, dfTilePixelSizeY); if( poRTDS == nullptr ) { CPLFree(pbyData); return; } for(int k=1; k <= nExpectedBands; k++) { GByte* pbyDataToRead = (GByte*)GET_BAND_DATA(pbyData, k, nBandDataTypeSize, nExpectedBandDataSize); if( bSwap && nBandDataTypeSize > 1 ) { GDALSwapWords( pbyDataToRead, nBandDataTypeSize, nTileXSize * nTileYSize, nBandDataTypeSize ); } /** * Get the right PostGISRasterRasterBand **/ int nCurBand = ( nExpectedBands > 1 ) ? k : nBand; /** * Get the right tileband **/ GDALRasterBand * poRTB = poRTDS->GetRasterBand(nCurBand); /** * Manually add each tile data to the cache of the * matching PostGISRasterTileRasterBand. **/ if (poRTB) { GDALRasterBlock* poBlock = poRTB->GetLockedBlockRef(0, 0, TRUE); if( poBlock != nullptr ) { // Point block data ref to fetched data memcpy(poBlock->GetDataRef(), (void *)pbyDataToRead, nExpectedBandDataSize); poBlock->DropLock(); } } } CPLFree(pbyData); } /************************************************************************/ /* LoadSources() */ /************************************************************************/ GBool PostGISRasterDataset::LoadSources(int nXOff, int nYOff, int nXSize, int nYSize, int nBand) { if( !bBuildQuadTreeDynamically ) return false; CPLString osCommand; CPLString osSpatialFilter; CPLString osIDsToFetch; int bFetchAll = FALSE; if( nXOff == 0 && nYOff == 0 && nXSize == nRasterXSize && nYSize == nRasterYSize ) { bFetchAll = TRUE; } else { double adfProjWin[8]; PolygonFromCoords(nXOff, nYOff, nXOff + nXSize, nYOff + nYSize, adfProjWin); osSpatialFilter.Printf("%s && " "ST_GeomFromText('POLYGON((%.18f %.18f,%.18f %.18f,%.18f %.18f,%.18f %.18f,%.18f %.18f))') ", //"AND ST_Intersects(%s, ST_GeomFromEWKT('SRID=%d;POLYGON((%.18f %.18f,%.18f %.18f,%.18f %.18f,%.18f %.18f,%.18f %.18f))'))", pszColumn, adfProjWin[0], adfProjWin[1], adfProjWin[2], adfProjWin[3], adfProjWin[4], adfProjWin[5], adfProjWin[6], adfProjWin[7], adfProjWin[0], adfProjWin[1] /*,pszColumn, nSrid, adfProjWin[0], adfProjWin[1], adfProjWin[2], adfProjWin[3], adfProjWin[4], adfProjWin[5], adfProjWin[6], adfProjWin[7], adfProjWin[0], adfProjWin[1]*/); } int bLoadRasters = FALSE; int bAllBandCaching = FALSE; PGresult *poResult = nullptr; if( m_nTiles > 0 && !bFetchAll ) { osCommand.Printf("SELECT %s FROM %s.%s", pszPrimaryKeyName, pszSchema, pszTable); osCommand += " WHERE "; osCommand += osSpatialFilter; osSpatialFilter = ""; poResult = PQexec(poConn, osCommand.c_str()); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::LoadSources(): Query = \"%s\" --> number of rows = %d", osCommand.c_str(), poResult ? PQntuples(poResult) : 0 ); #endif if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) < 0) { if (poResult) PQclear(poResult); CPLError(CE_Failure, CPLE_AppDefined, "PostGISRasterDataset::LoadSources(): %s", PQerrorMessage(poConn)); return false; } if( bTilesSameDimension && nBand > 0 ) { GIntBig nMemoryRequiredForTiles = static_cast<GIntBig>(PQntuples(poResult)) * nTileWidth * nTileHeight * (GDALGetDataTypeSize(GetRasterBand(nBand)->GetRasterDataType()) / 8); GIntBig nCacheMax = (GIntBig) GDALGetCacheMax64(); if( nBands * nMemoryRequiredForTiles <= nCacheMax ) { bLoadRasters = TRUE; bAllBandCaching = TRUE; } else if( nMemoryRequiredForTiles <= nCacheMax ) { bLoadRasters = TRUE; } } int i; for(i=0;i<PQntuples(poResult);i++) { const char* pszPKID = PQgetvalue(poResult, i, 0); PostGISRasterTileDataset *poTile = GetMatchingSourceRef(pszPKID); int bFetchTile = FALSE; if( poTile == nullptr ) bFetchTile = TRUE; else if( bLoadRasters ) { PostGISRasterTileRasterBand* poTileBand = (PostGISRasterTileRasterBand *)poTile->GetRasterBand(nBand); if( !poTileBand->IsCached() ) bFetchTile = TRUE; } if( bFetchTile ) { if( !osIDsToFetch.empty() ) osIDsToFetch += ","; osIDsToFetch += "'"; osIDsToFetch += pszPKID; osIDsToFetch += "'"; } } PQclear(poResult); } if( bFetchAll || !osIDsToFetch.empty() || !osSpatialFilter.empty() ) { osCommand.Printf("SELECT %s, ST_Metadata(%s)", pszPrimaryKeyName, pszColumn); if( bLoadRasters ) { if( bAllBandCaching ) osCommand += CPLSPrintf(", %s", pszColumn); else osCommand += CPLSPrintf(", ST_Band(%s, %d)", pszColumn, nBand); } osCommand += CPLSPrintf(" FROM %s.%s", pszSchema, pszTable); if( !osIDsToFetch.empty() ) { osCommand += " WHERE "; osCommand += pszPrimaryKeyName; osCommand += " IN ("; osCommand += osIDsToFetch; osCommand += ")"; } else if ( !osSpatialFilter.empty() ) { osCommand += " WHERE "; osCommand += osSpatialFilter; } poResult = PQexec(poConn, osCommand.c_str()); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::LoadSources(): Query = \"%s\" --> number of rows = %d", osCommand.c_str(), poResult ? PQntuples(poResult) : 0 ); #endif if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) < 0) { if (poResult) PQclear(poResult); CPLError(CE_Failure, CPLE_AppDefined, "PostGISRasterDataset::LoadSources(): %s", PQerrorMessage(poConn)); return false; } for(int i=0;i<PQntuples(poResult);i++) { const char* pszPKID = PQgetvalue(poResult, i, 0); const char* pszMetadata = PQgetvalue(poResult, i, 1); PostGISRasterTileDataset* poRTDS = GetMatchingSourceRef(pszPKID); if( poRTDS == nullptr ) { poRTDS = BuildRasterTileDataset( pszMetadata, pszPKID, GetRasterCount(), nullptr); if( poRTDS != nullptr ) { if( AddComplexSource(poRTDS) ) { oMapPKIDToRTDS[poRTDS->pszPKID] = poRTDS; papoSourcesHolders = (PostGISRasterTileDataset**) CPLRealloc(papoSourcesHolders, sizeof(PostGISRasterTileDataset*) * (m_nTiles + 1)); papoSourcesHolders[m_nTiles ++] = poRTDS; CPLQuadTreeInsert(hQuadTree, poRTDS); } else { delete poRTDS; poRTDS = nullptr; } } } if( bLoadRasters && poRTDS != nullptr ) { const char* pszRaster = PQgetvalue(poResult, i, 2); CacheTile(pszMetadata, pszRaster, pszPKID, nBand, bAllBandCaching); } } PQclear(poResult); } // If we have fetched the surface of all the dataset, then all sources have // been built, and we don't need to do a spatial query on following IRasterIO() calls if( bFetchAll ) bBuildQuadTreeDynamically = false; return true; } /*********************************************************************** * \brief Get some useful metadata for all bands * * The allocated memory is responsibility of the caller **********************************************************************/ BandMetadata * PostGISRasterDataset::GetBandsMetadata(int * pnBands) { BandMetadata * poBMD = nullptr; PGresult * poResult = nullptr; CPLString osCommand; char * pszRes = nullptr; char * pszFilteredRes = nullptr; char ** papszParams = nullptr; osCommand.Printf("select st_bandmetadata(%s, band) from " "(select %s, generate_series(1, %d) band from " "(select %s from %s.%s where (%s) AND st_numbands(%s)=%d limit 1) bar) foo", pszColumn, pszColumn, nBandsToCreate, pszColumn, pszSchema, pszTable, pszWhere ? pszWhere : "true", pszColumn, nBandsToCreate); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::GetBandsMetadata(): Query: %s", osCommand.c_str()); #endif poResult = PQexec(poConn, osCommand.c_str()); /* Error getting info from database */ if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) <= 0) { ReportError(CE_Failure, CPLE_AppDefined, "Error getting band metadata while creating raster " "bands"); CPLDebug("PostGIS_Raster", "PostGISRasterDataset::GetBandsMetadata(): %s", PQerrorMessage(poConn)); if (poResult) PQclear(poResult); return nullptr; } // Matches nBands int nTuples = PQntuples(poResult); poBMD = (BandMetadata *)VSI_MALLOC2_VERBOSE(nTuples, sizeof(BandMetadata)); if (poBMD == nullptr) { PQclear(poResult); return nullptr; } int iBand = 0; for(iBand = 0; iBand < nTuples; iBand++) { // Get metadata record pszRes = CPLStrdup(PQgetvalue(poResult, iBand, 0)); // Skip first "(" pszFilteredRes = pszRes + 1; // Skip last ")" pszFilteredRes[strlen(pszFilteredRes)-1] = '\0'; // Tokenize papszParams = CSLTokenizeString2(pszFilteredRes, ",", CSLT_HONOURSTRINGS | CSLT_ALLOWEMPTYTOKENS); CPLAssert(CSLCount(papszParams) >= ELEMENTS_OF_BAND_METADATA_RECORD); CPLFree(pszRes); // If the band doesn't have nodata, NULL is returned as nodata TranslateDataType(papszParams[POS_PIXELTYPE], &(poBMD[iBand].eDataType), &(poBMD[iBand].nBitsDepth), &(poBMD[iBand].bSignedByte)); if (papszParams[POS_NODATAVALUE] == nullptr || EQUAL(papszParams[POS_NODATAVALUE], "NULL") || EQUAL(papszParams[POS_NODATAVALUE], "f") || EQUAL(papszParams[POS_NODATAVALUE], "")) { poBMD[iBand].bHasNoDataValue = false; poBMD[iBand].dfNoDataValue = CPLAtof(NO_VALID_RES); } else { poBMD[iBand].bHasNoDataValue = true; poBMD[iBand].dfNoDataValue = CPLAtof(papszParams[POS_NODATAVALUE]); } // TODO: Manage outdb and get path poBMD[iBand].bIsOffline = (papszParams[POS_ISOUTDB] != nullptr) ? EQUAL(papszParams[POS_ISOUTDB], "t") : false; CSLDestroy(papszParams); } if (pnBands) *pnBands = nTuples; PQclear(poResult); return poBMD; } /*********************************************************************** * \brief Function to get the bounding box of each element inserted in * the QuadTree index **********************************************************************/ static void GetTileBoundingBox(const void *hFeature, CPLRectObj * pBounds) { PostGISRasterTileDataset * poRTD = (PostGISRasterTileDataset *)hFeature; double adfTileGeoTransform[6]; poRTD->GetGeoTransform(adfTileGeoTransform); int nTileWidth = poRTD->GetRasterXSize(); int nTileHeight = poRTD->GetRasterYSize(); pBounds->minx = adfTileGeoTransform[GEOTRSFRM_TOPLEFT_X]; pBounds->maxx = adfTileGeoTransform[GEOTRSFRM_TOPLEFT_X] + nTileWidth * adfTileGeoTransform[GEOTRSFRM_WE_RES]; if (adfTileGeoTransform[GEOTRSFRM_NS_RES] >= 0.0) { pBounds->miny = adfTileGeoTransform[GEOTRSFRM_TOPLEFT_Y]; pBounds->maxy = adfTileGeoTransform[GEOTRSFRM_TOPLEFT_Y] + nTileHeight * adfTileGeoTransform[GEOTRSFRM_NS_RES]; } else { pBounds->maxy = adfTileGeoTransform[GEOTRSFRM_TOPLEFT_Y]; pBounds->miny = adfTileGeoTransform[GEOTRSFRM_TOPLEFT_Y] + nTileHeight * adfTileGeoTransform[GEOTRSFRM_NS_RES]; } #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "TileBoundingBox minx=%f miny=%f maxx=%f maxy=%f adfTileGeoTransform[GEOTRSFRM_NS_RES]=%f", pBounds->minx, pBounds->miny, pBounds->maxx, pBounds->maxy, adfTileGeoTransform[GEOTRSFRM_NS_RES]); #endif return; } /******************************************************** * \brief Builds a PostGISRasterTileDataset* object from the ST_Metadata ********************************************************/ PostGISRasterTileDataset* PostGISRasterDataset::BuildRasterTileDataset(const char* pszMetadata, const char* pszPKID, int nBandsFetched, BandMetadata * poBandMetaData) { // Get metadata record char* pszRes = CPLStrdup(pszMetadata); // Skip first "(" char* pszFilteredRes = pszRes + 1; // Skip last ")" pszFilteredRes[strlen(pszFilteredRes)-1] = '\0'; // Tokenize char** papszParams = CSLTokenizeString2(pszFilteredRes, ",", CSLT_HONOURSTRINGS | CSLT_ALLOWEMPTYTOKENS); CPLAssert(CSLCount(papszParams) >= ELEMENTS_OF_METADATA_RECORD); CPLFree(pszRes); double tileSkewX = CPLAtof(papszParams[POS_SKEWX]); double tileSkewY = CPLAtof(papszParams[POS_SKEWY]); // Rotated rasters are not allowed, so far // TODO: allow them if (!CPLIsEqual(tileSkewX, 0.0) || !CPLIsEqual(tileSkewY, 0.0)) { ReportError(CE_Failure, CPLE_AppDefined, "GDAL PostGIS Raster driver can not work with " "rotated rasters yet."); CSLDestroy(papszParams); return nullptr; } int l_nTileWidth = atoi(papszParams[POS_WIDTH]); int l_nTileHeight = atoi(papszParams[POS_HEIGHT]); /** * Now, construct a PostGISRasterTileDataset, and add * its bands as sources for the general raster bands **/ int nTileBands = atoi(papszParams[POS_NBANDS]); /** * If the source doesn't have the same number of bands than * the raster band, is discarded **/ if (nTileBands != nBandsFetched) { CPLDebug("PostGIS_Raster", "PostGISRasterDataset::" "BuildRasterTileDataset(): Tile has %d " "bands, and the raster has %d bands. Discarding " "this tile", nTileBands, nBandsFetched); CSLDestroy(papszParams); return nullptr; } PostGISRasterTileDataset* poRTDS = new PostGISRasterTileDataset(this, l_nTileWidth, l_nTileHeight); if (GetPrimaryKeyRef() != nullptr) { poRTDS->pszPKID = CPLStrdup(pszPKID); } poRTDS->adfGeoTransform[GEOTRSFRM_TOPLEFT_X]= CPLAtof(papszParams[POS_UPPERLEFTX]); poRTDS->adfGeoTransform[GEOTRSFRM_TOPLEFT_Y]= CPLAtof(papszParams[POS_UPPERLEFTY]); poRTDS->adfGeoTransform[GEOTRSFRM_WE_RES]= CPLAtof(papszParams[POS_SCALEX]); poRTDS->adfGeoTransform[GEOTRSFRM_NS_RES]= CPLAtof(papszParams[POS_SCALEY]); // TODO: outdb bands should be handled. Not a priority. for(int j = 0; j < nTileBands; j++) { // Create band poRTDS->SetBand(j + 1, new PostGISRasterTileRasterBand( poRTDS, j + 1, (poBandMetaData ) ? poBandMetaData[j].eDataType : GetRasterBand(j+1)->GetRasterDataType(), (poBandMetaData ) ? poBandMetaData[j].bIsOffline : FALSE)); } CSLDestroy(papszParams); return poRTDS; } /******************************************************** * \brief Updates components GEOTRSFRM_WE_RES and GEOTRSFRM_NS_RES * of dataset adfGeoTransform ********************************************************/ void PostGISRasterDataset::UpdateGlobalResolutionWithTileResolution( double tilePixelSizeX, double tilePixelSizeY) { // Calculate pixel size if (resolutionStrategy == AVERAGE_RESOLUTION || resolutionStrategy == AVERAGE_APPROX_RESOLUTION) { adfGeoTransform[GEOTRSFRM_WE_RES] += tilePixelSizeX; adfGeoTransform[GEOTRSFRM_NS_RES] += tilePixelSizeY; } else if (resolutionStrategy == HIGHEST_RESOLUTION) { adfGeoTransform[GEOTRSFRM_WE_RES] = std::min(adfGeoTransform[GEOTRSFRM_WE_RES], tilePixelSizeX); /** * Yes : as ns_res is negative, the highest resolution * is the max value. * * Negative tilePixelSizeY means that the coords origin * is in top left corner. This is not the common * situation. Most image files store data from top to * bottom, while the projected coordinate systems * utilize traditional Cartesian coordinates with the * origin in the conventional lower-left corner (bottom * to top). For that reason, this parameter is normally * negative. **/ if (tilePixelSizeY < 0.0) adfGeoTransform[GEOTRSFRM_NS_RES] = std::max(adfGeoTransform[GEOTRSFRM_NS_RES], tilePixelSizeY); else adfGeoTransform[GEOTRSFRM_NS_RES] = std::min(adfGeoTransform[GEOTRSFRM_NS_RES], tilePixelSizeY); } else if (resolutionStrategy == LOWEST_RESOLUTION) { adfGeoTransform[GEOTRSFRM_WE_RES] = std::max(adfGeoTransform[GEOTRSFRM_WE_RES], tilePixelSizeX); if (tilePixelSizeY < 0.0) adfGeoTransform[GEOTRSFRM_NS_RES] = std::min(adfGeoTransform[GEOTRSFRM_NS_RES], tilePixelSizeY); else adfGeoTransform[GEOTRSFRM_NS_RES] = std::max(adfGeoTransform[GEOTRSFRM_NS_RES], tilePixelSizeY); } } /*********************************************************************** * \brief Build bands ***********************************************************************/ void PostGISRasterDataset::BuildBands(BandMetadata * poBandMetaData, int nBandsFetched) { #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::ConstructOneDatasetFromTiles: " "Now constructing the raster dataset bands"); #endif int iBand; for (iBand = 0; iBand < nBandsFetched; iBand++) { SetBand(iBand + 1, new PostGISRasterRasterBand(this, iBand + 1, poBandMetaData[iBand].eDataType, poBandMetaData[iBand].bHasNoDataValue, poBandMetaData[iBand].dfNoDataValue, poBandMetaData[iBand].bIsOffline)); // Set some band metadata items GDALRasterBand * b = GetRasterBand(iBand + 1); if (poBandMetaData[iBand].bSignedByte) { b->SetMetadataItem( "PIXELTYPE", "SIGNEDBYTE", "IMAGE_STRUCTURE" ); } if (poBandMetaData[iBand].nBitsDepth < 8) { b->SetMetadataItem( "NBITS", CPLString().Printf( "%d", poBandMetaData[iBand].nBitsDepth ), "IMAGE_STRUCTURE" ); } #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::ConstructOneDatasetFromTiles: " "Band %d built", iBand + 1); #endif } } /*********************************************************************** * \brief Construct just one dataset from all the results fetched. * * This method is not very elegant. It's strongly attached to * SetRasterProperties (it assumes poResult is not NULL, and the actual * results are stored at fixed positions). I just did it to avoid a * huge SetRasterProperties method. * * I know, this could be avoided in a better way. Like implementing a * wrapper to raise queries and get results without all the checking * overhead. I'd like to do it, someday... **********************************************************************/ GBool PostGISRasterDataset::ConstructOneDatasetFromTiles( PGresult * poResult) { /******************************************************************* * We first get the band metadata. So we'll can use it as metadata * for all the sources. * * We just fetch the band metadata from 1 tile. So, we assume that: * - All the bands have the same data type * - All the bands have the same NODATA value * * It's user's responsibility to ensure the requested table fit in * this schema. He/she may use the 'where' clause to ensure this ******************************************************************/ int nBandsFetched = 0; BandMetadata * poBandMetaData = GetBandsMetadata(&nBandsFetched); /******************************************************************* * Now, we can iterate over the input query's results (metadata * from all the database tiles). * * In this iteration, we will construct the dataset GeoTransform * array and we will add each tile's band as source for each of our * rasterbands. ******************************************************************/ int l_nTiles = PQntuples(poResult); adfGeoTransform[GEOTRSFRM_TOPLEFT_X] = xmin; int nField = (GetPrimaryKeyRef() != nullptr) ? 1 : 0; /** * Optimization - Just one tile: The dataset's geotransform is the * tile's geotransform. And we don't need to construct sources for * the raster bands. We just read from the unique tile we have. So, * we avoid all the VRT stuff. * * TODO: For some reason, the implementation of IRasterIO in * PostGISRasterRasterBand class causes a segmentation fault when * tries to call GDALRasterBand::IRasterIO. This call intends to * delegate the I/O in the parent class, that will call * PostGISRasterRasterBand::IReadBlock. * * If you avoid PostGISRasterRasterBand::IRasterIO method, the * IReadBlock method is directly call and it works fine. * * Right now, we avoid this optimization by making the next boolean * variable always true. **/ //GBool bNeedToConstructSourcesHolders = (l_nTiles > 1); // As the optimization is not working, we avoid it GBool bNeedToConstructSourcesHolders = true; #ifdef notdef // This won't be called if the optimization is disabled if (!bNeedToConstructSourcesHolders) { // Get metadata record char* pszRes = CPLStrdup(PQgetvalue(poResult, 0, nField)); // Skip first "(" char* pszFilteredRes = pszRes + 1; // Skip last ")" pszFilteredRes[strlen(pszFilteredRes)-1] = '\0'; // Tokenize char** papszParams = CSLTokenizeString2(pszFilteredRes, ",", CSLT_HONOURSTRINGS | CSLT_ALLOWEMPTYTOKENS); CPLAssert(CSLCount(papszParams) >= ELEMENTS_OF_METADATA_RECORD); CPLFree(pszRes); adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1] = CPLAtof(papszParams[POS_SKEWX]); adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] = CPLAtof(papszParams[POS_SKEWY]); // Rotated rasters are not allowed, so far // TODO: allow them if (!CPLIsEqual(adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1], 0.0) || !CPLIsEqual(adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2], 0.0)) { ReportError(CE_Failure, CPLE_AppDefined, "GDAL PostGIS Raster driver can not work with " "rotated rasters yet."); VSIFree(poBandMetaData); CSLDestroy(papszParams); return false; } /** * We override user resolution. It only makes sense in case we * have several tiles with different resolutions **/ adfGeoTransform[GEOTRSFRM_WE_RES] = CPLAtof(papszParams[POS_SCALEX]); adfGeoTransform[GEOTRSFRM_NS_RES] = CPLAtof(papszParams[POS_SCALEY]); CSLDestroy(papszParams); } /** * Several tiles: construct the dataset from metadata of all tiles, * and create PostGISRasterTileDataset objects, to hold the * PostGISRasterTileRasterBands objects that will be used as sources **/ else #endif { int i; #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::ConstructOneDatasetFromTiles: " "Constructing one dataset from %d tiles", l_nTiles); #endif papoSourcesHolders = (PostGISRasterTileDataset **) VSI_CALLOC_VERBOSE(l_nTiles, sizeof(PostGISRasterTileDataset *)); if (papoSourcesHolders == nullptr) { VSIFree(poBandMetaData); return false; } int nValidTiles = 0; for(i = 0; i < l_nTiles; i++) { PostGISRasterTileDataset* poRTDS = BuildRasterTileDataset(PQgetvalue(poResult, i, nField), (GetPrimaryKeyRef() != nullptr) ? PQgetvalue(poResult, i, 0) : nullptr, nBandsFetched, poBandMetaData); if( poRTDS == nullptr ) continue; if( nOverviewFactor == 1 && resolutionStrategy != USER_RESOLUTION ) { double tilePixelSizeX = poRTDS->adfGeoTransform[GEOTRSFRM_WE_RES]; double tilePixelSizeY = poRTDS->adfGeoTransform[GEOTRSFRM_NS_RES]; if( nValidTiles == 0 ) { adfGeoTransform[GEOTRSFRM_WE_RES] = tilePixelSizeX; adfGeoTransform[GEOTRSFRM_NS_RES] = tilePixelSizeY; } else { UpdateGlobalResolutionWithTileResolution(tilePixelSizeX, tilePixelSizeY); } } papoSourcesHolders[nValidTiles++] = poRTDS; } // end for l_nTiles = nValidTiles; if( nOverviewFactor > 1 ) { adfGeoTransform[GEOTRSFRM_WE_RES] = poParentDS->adfGeoTransform[GEOTRSFRM_WE_RES] * nOverviewFactor; adfGeoTransform[GEOTRSFRM_NS_RES] = poParentDS->adfGeoTransform[GEOTRSFRM_NS_RES] * nOverviewFactor; } else if ((resolutionStrategy == AVERAGE_RESOLUTION || resolutionStrategy == AVERAGE_APPROX_RESOLUTION) && l_nTiles > 0) { adfGeoTransform[GEOTRSFRM_WE_RES] /= l_nTiles; adfGeoTransform[GEOTRSFRM_NS_RES] /= l_nTiles; } } // end else /** * Complete the rest of geotransform parameters **/ if (adfGeoTransform[GEOTRSFRM_NS_RES] >= 0.0) adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] = ymin; else adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] = ymax; #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::ConstructOneDatasetFromTiles: " "GeoTransform array = (%f, %f, %f, %f, %f, %f)", adfGeoTransform[GEOTRSFRM_TOPLEFT_X], adfGeoTransform[GEOTRSFRM_WE_RES], adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1], adfGeoTransform[GEOTRSFRM_TOPLEFT_Y], adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2], adfGeoTransform[GEOTRSFRM_NS_RES]); #endif // Calculate the raster size from the geotransform array nRasterXSize = (int) fabs(rint((xmax - xmin) / adfGeoTransform[GEOTRSFRM_WE_RES])); nRasterYSize = (int) fabs(rint((ymax - ymin) / adfGeoTransform[GEOTRSFRM_NS_RES])); #ifdef DEBUG_VERBOSE CPLDebug( "PostGIS_Raster", "PostGISRasterDataset::ConstructOneDatasetFromTiles: " "Raster size: (%d, %d), ",nRasterXSize, nRasterYSize); #endif if (nRasterXSize <= 0 || nRasterYSize <= 0) { ReportError(CE_Failure, CPLE_AppDefined, "Computed PostGIS Raster dimension is invalid. You've " "probably specified inappropriate resolution." ); VSIFree(poBandMetaData); return false; } /******************************************************************* * Now construct the dataset bands ******************************************************************/ BuildBands(poBandMetaData, nBandsFetched); // And free bandmetadata VSIFree(poBandMetaData); /******************************************************************* * Finally, add complex sources and create a quadtree index for them ******************************************************************/ // cppcheck-suppress knownConditionTrueFalse if (bNeedToConstructSourcesHolders) { #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::ConstructOneDatasetFromTiles: " "Finally, adding sources for bands"); #endif for(int iSource = 0; iSource < l_nTiles; iSource++) { PostGISRasterTileDataset* poRTDS =papoSourcesHolders[iSource]; if (!AddComplexSource(poRTDS)) { CPLDebug("PostGIS_Raster", "PostGISRasterDataset::ConstructOneDatasetFromTiles:" "Bounding box of tile %d does not intersect the " "bounding box of dataset ", iSource); continue; } if( poRTDS->pszPKID != nullptr ) oMapPKIDToRTDS[poRTDS->pszPKID] = poRTDS; CPLQuadTreeInsert(hQuadTree, poRTDS); } } return true; } /*********************************************************************** * \brief Construct subdatasets and show them. * * This method is not very elegant. It's strongly attached to * SetRasterProperties (it assumes poResult is not NULL, and the actual * results are stored at fixed positions). I just did it to avoid a * huge SetRasterProperties method. * * I know, this could be avoided in a better way. Like implementing a * wrapper to raise queries and get results without all the checking * overhead. I'd like to do it, someday... **********************************************************************/ GBool PostGISRasterDataset::YieldSubdatasets(PGresult * poResult, const char * pszValidConnectionString) { int l_nTiles = PQntuples(poResult); int i = 0; double dfTileUpperLeftX = 0; double dfTileUpperLeftY = 0; papszSubdatasets = (char**)VSICalloc(2 * l_nTiles + 1, sizeof(char*)); if( papszSubdatasets == nullptr ) return false; // Subdatasets identified by primary key if (GetPrimaryKeyRef() != nullptr) { for(i = 0; i < l_nTiles; i++) { const char* pszId = PQgetvalue(poResult, i, 0); papszSubdatasets[2 * i] = CPLStrdup(CPLSPrintf("SUBDATASET_%d_NAME=PG:%s schema=%s table=%s column=%s " "where='%s = %s'", i+ 1, pszValidConnectionString, pszSchema, pszTable, pszColumn, pszPrimaryKeyName, pszId)); papszSubdatasets[2 * i + 1] = CPLStrdup(CPLSPrintf("SUBDATASET_%d_DESC=PostGIS Raster at %s.%s (%s), with %s = %s", i + 1, pszSchema, pszTable, pszColumn, pszPrimaryKeyName, pszId)); } } // Subdatasets identified by upper left pixel else { for(i = 0; i < l_nTiles; i++) { char * pszRes = CPLStrdup(PQgetvalue(poResult, i, 0)); // Skip first "(" char * pszFilteredRes = pszRes + 1; // Skip last ")" pszFilteredRes[strlen(pszFilteredRes)-1] = '\0'; // Tokenize char ** papszParams = CSLTokenizeString2(pszFilteredRes, ",", CSLT_HONOURSTRINGS); CPLFree(pszRes); dfTileUpperLeftX = CPLAtof(papszParams[POS_UPPERLEFTX]); dfTileUpperLeftY = CPLAtof(papszParams[POS_UPPERLEFTY]); papszSubdatasets[2 * i] = CPLStrdup(CPLSPrintf("SUBDATASET_%d_NAME=PG:%s schema=%s table=%s column=%s " "where='abs(ST_UpperLeftX(%s) - %.8f) < 1e-8 AND " "abs(ST_UpperLeftY(%s) - %.8f) < 1e-8'", i + 1, pszValidConnectionString, pszSchema, pszTable, pszColumn, pszColumn, dfTileUpperLeftX, pszColumn, dfTileUpperLeftY)); papszSubdatasets[2 * i + 1] = CPLStrdup(CPLSPrintf("SUBDATASET_%d_DESC=PostGIS Raster at %s.%s (%s), " "UpperLeft = %.8f, %.8f", i + 1, pszSchema, pszTable, pszColumn, dfTileUpperLeftX, dfTileUpperLeftY)); CSLDestroy(papszParams); } } /** * Not a single raster fetched. Not really needed. Just to keep code clean **/ nRasterXSize = 0; nRasterYSize = 0; adfGeoTransform[GEOTRSFRM_TOPLEFT_X] = 0.0; adfGeoTransform[GEOTRSFRM_WE_RES] = 1.0; adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1] = 0.0; adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] = 0.0; adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] = 0.0; adfGeoTransform[GEOTRSFRM_NS_RES] = -1.0; return true; } /*********************************************************************** * \brief Set the general raster properties. * * This method is called when the driver working mode is * ONE_RASTER_PER_ROW or ONE_RASTER_PER_TABLE. * * We must distinguish between tiled and untiled raster coverages. In * PostGIS Raster, there's no real difference between 'tile' and * 'raster'. There's only 'raster objects'. Each record of a raster * table is a raster object, and has its own georeference information, * whether if the record is a tile of a bigger raster coverage or is a * complete raster. So, <b>there's no a way of knowing if the rows of a * raster table are related or not</b>. It's user's responsibility, and * it's managed by 'mode' parameter in connection string, which * determines the driver working mode. * * The user is responsible to ensure that the raster layer meets the * minimum topological requirements for analysis. The ideal case is when * all the raster tiles of a continuous layer are the same size, snap to * the same grid and do not overlap. * **********************************************************************/ GBool PostGISRasterDataset::SetRasterProperties (const char * pszValidConnectionString) { PGresult* poResult = nullptr; CPLString osCommand; GBool bDataFoundInRasterColumns = false; GBool bNeedToCheckWholeTable = false; /******************************************************************* * Get the extent and the maximum number of bands of the requested * raster- * * TODO: The extent of rotated rasters could be a problem. We will * need a ST_RotatedExtent function in PostGIS. Without that * function, we should not allow rotated rasters. ******************************************************************/ if (pszWhere != nullptr) { osCommand.Printf( "select srid, nbband, ST_XMin(geom) as xmin, " "ST_XMax(geom) as xmax, ST_YMin(geom) as ymin, " "ST_YMax(geom) as ymax, scale_x, scale_y from (select ST_SRID(%s) srid, " "ST_Extent(%s::geometry) geom, max(ST_NumBands(%s)) " "nbband, avg(ST_ScaleX(%s)) scale_x, avg(ST_ScaleY(%s)) scale_y from %s.%s where %s group by ST_SRID(%s)) foo", pszColumn, pszColumn, pszColumn, pszColumn, pszColumn, pszSchema, pszTable, pszWhere, pszColumn); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties(): First query: %s", osCommand.c_str()); #endif poResult = PQexec(poConn, osCommand.c_str()); } else { /** * Optimization: First, check raster_columns view (it makes * things faster. See ticket #5046) * * This can only be applied if we don't have a 'where' clause, * because raster_columns view stores statistics about the whole * table. If the user specified 'where' clause is because is * just interested in a subset of the table rows. **/ osCommand.Printf( "select srid, nbband, ST_XMin(geom) as xmin, ST_XMax(geom) " "as xmax, ST_YMin(geom) as ymin, ST_YMax(geom) as ymax, " "scale_x, scale_y, blocksize_x, blocksize_y, same_alignment, regular_blocking " "from (select srid, extent geom, num_bands nbband, " "scale_x, scale_y, blocksize_x, blocksize_y, same_alignment, regular_blocking from " "raster_columns where r_table_schema = '%s' and " "r_table_name = '%s' and r_raster_column = '%s' ) foo", pszSchema, pszTable, pszColumn); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties(): First query: %s", osCommand.c_str()); #endif poResult = PQexec(poConn, osCommand.c_str()); // Query execution error if(poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) < 0) { bNeedToCheckWholeTable = true; if (poResult) PQclear(poResult); } /** * We didn't find anything in raster_columns view. Need to check * the whole table for metadata **/ else if (PQntuples(poResult) == 0) { ReportError(CE_Warning, CPLE_AppDefined, "Cannot find " "information about %s.%s table in raster_columns view. The " "raster table load would take a lot of time. Please, " "execute AddRasterConstraints PostGIS function to register " "this table as raster table in raster_columns view. This " "will save a lot of time.", pszSchema, pszTable); PQclear(poResult); bNeedToCheckWholeTable = true; } /* There's a result but the row has empty values */ else if (PQntuples(poResult) == 1 && (PQgetvalue(poResult, 0, 1)[0] == '\0' || (poParentDS == nullptr && (PQgetvalue(poResult, 0, 2)[0] == '\0' || PQgetvalue(poResult, 0, 3)[0] == '\0' || PQgetvalue(poResult, 0, 4)[0] == '\0' || PQgetvalue(poResult, 0, 5)[0] == '\0'))) ) { ReportError(CE_Warning, CPLE_AppDefined, "Cannot find (valid) " "information about %s.%s table in raster_columns view. The " "raster table load would take a lot of time. Please, " "execute AddRasterConstraints PostGIS function to register " "this table as raster table in raster_columns view. This " "will save a lot of time.", pszSchema, pszTable); PQclear(poResult); bNeedToCheckWholeTable = true; } // We should check whole table but we can't if (bNeedToCheckWholeTable && !bCheckAllTiles) { ReportError(CE_Failure, CPLE_AppDefined, "Cannot find " "information about %s.%s table in raster_columns view. " "Please, execute AddRasterConstraints PostGIS function to " "register this table as raster table in raster_columns " "view. This will save a lot of time. As alternative, " "provide configuration option " "PR_ALLOW_WHOLE_TABLE_SCAN=YES. With this option, the " "driver will work even without the table information " "stored in raster_columns view, but it could perform " "really slow.", pszSchema, pszTable); PQclear(poResult); return false; } // We should check the whole table and we can else if (bNeedToCheckWholeTable) { osCommand.Printf( "select srid, nbband, st_xmin(geom) as xmin, " "st_xmax(geom) as xmax, st_ymin(geom) as ymin, " "st_ymax(geom) as ymax, scale_x, scale_y from (select st_srid(%s) srid, " "st_extent(%s::geometry) geom, max(ST_NumBands(%s)) " "nbband, avg(ST_ScaleX(%s)) scale_x, avg(ST_ScaleY(%s)) scale_y from %s.%s group by st_srid(%s)) foo", pszColumn, pszColumn, pszColumn, pszColumn, pszColumn, pszSchema, pszTable, pszColumn); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties(): " "First query: %s", osCommand.c_str()); #endif poResult = PQexec(poConn, osCommand.c_str()); } // We already found the data in raster_columns else { bDataFoundInRasterColumns = true; } } // Query execution error if(poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) < 0) { ReportError(CE_Failure, CPLE_AppDefined, "Error browsing database for PostGIS Raster " "properties : %s", PQerrorMessage(poConn)); if (poResult != nullptr) PQclear(poResult); return false; } else if (PQntuples(poResult) == 0) { ReportError(CE_Failure, CPLE_AppDefined, "No results found in %s.%s. Did you specify a 'where' " "clause too restrictive?", pszSchema, pszTable); PQclear(poResult); return false; } /** * Found more than one SRID value in the table. Not allowed. * * TODO: We could provide an extra parameter, to transform all the * tiles to the same SRID **/ else if (PQntuples(poResult) > 1) { ReportError(CE_Failure, CPLE_AppDefined, "Error, the table %s.%s contains tiles with different " "srid. This feature is not yet supported by the PostGIS " "Raster driver. Please, specify a table that contains only " "tiles with the same srid or provide a 'where' constraint " "to select just the tiles with the same value for srid", pszSchema, pszTable); PQclear(poResult); return false; } // Get some information we will probably need further nSrid = atoi(PQgetvalue(poResult, 0, 0)); nBandsToCreate = atoi(PQgetvalue(poResult, 0, 1)); if( poParentDS != nullptr ) { /* If we are an overview of a parent dataset, we need to adjust */ /* to its extent, otherwise IRasterIO() will not work properly */ xmin = poParentDS->xmin; xmax = poParentDS->xmax; ymin = poParentDS->ymin; ymax = poParentDS->ymax; } else { xmin = CPLAtof(PQgetvalue(poResult, 0, 2)); xmax = CPLAtof(PQgetvalue(poResult, 0, 3)); ymin = CPLAtof(PQgetvalue(poResult, 0, 4)); ymax = CPLAtof(PQgetvalue(poResult, 0, 5)); } // Create the QuadTree object CPLRectObj sRect; sRect.minx = xmin; sRect.miny = ymin; sRect.maxx = xmax; sRect.maxy = ymax; hQuadTree = CPLQuadTreeCreate(&sRect, GetTileBoundingBox); double scale_x = CPLAtof(PQgetvalue(poResult, 0, 6)); double scale_y = CPLAtof(PQgetvalue(poResult, 0, 7)); if( nOverviewFactor > 1 && poParentDS != nullptr ) { scale_x = poParentDS->adfGeoTransform[GEOTRSFRM_WE_RES] * nOverviewFactor; scale_y = poParentDS->adfGeoTransform[GEOTRSFRM_NS_RES] * nOverviewFactor; } else if( resolutionStrategy == USER_RESOLUTION) { scale_x = adfGeoTransform[GEOTRSFRM_WE_RES]; scale_y = adfGeoTransform[GEOTRSFRM_NS_RES]; } // These fields can only be fetched from raster_columns view if (bDataFoundInRasterColumns) { nTileWidth = atoi(PQgetvalue(poResult, 0, 8)); nTileHeight = atoi(PQgetvalue(poResult, 0, 9)); if( nTileWidth != 0 && nTileHeight != 0 ) bTilesSameDimension = true; bAllTilesSnapToSameGrid = EQUAL(PQgetvalue(poResult, 0, 10), "t"); bRegularBlocking = EQUAL(PQgetvalue(poResult, 0, 11), "t"); } #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties: xmin = %f, " "xmax = %f, ymin = %f, ymax = %f, scale_x = %f, scale_y = %f", xmin, xmax, ymin, ymax, scale_x, scale_y); #endif PQclear(poResult); /******************************************************************* * Now, we fetch the metadata of all the raster tiles in the * database, that will allow us to construct VRT sources to the * PostGIS Raster bands. * * TODO: Improve this. If we have a big amount of tiles, it can be * a problem. ******************************************************************/ // We'll identify each tile for its primary key/unique id (ideal) if (GetPrimaryKeyRef() != nullptr) { if (pszWhere == nullptr) { /* If we don't know the pixel size, then guess it from averaging the metadata */ /* of a maximum 10 rasters */ if( bIsFastPK && nMode == ONE_RASTER_PER_TABLE && HasSpatialIndex() && (scale_x == 0 || scale_y == 0) && resolutionStrategy == AVERAGE_APPROX_RESOLUTION ) { osCommand.Printf("SELECT avg(scale_x) avg_scale_x, avg(scale_y) avg_scale_y FROM " "(SELECT ST_ScaleX(%s) scale_x, ST_ScaleY(%s) scale_y FROM %s.%s LIMIT 10) foo", pszColumn, pszColumn, pszSchema, pszTable); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties(): Query: %s", osCommand.c_str()); #endif poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) <= 0) { ReportError(CE_Failure, CPLE_AppDefined, "Error retrieving raster metadata"); CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties(): %s", PQerrorMessage(poConn)); if (poResult != nullptr) PQclear(poResult); return false; } scale_x = CPLAtof(PQgetvalue(poResult, 0, 0)); scale_y = CPLAtof(PQgetvalue(poResult, 0, 1)); CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties: guessed: scale_x = %f, scale_y = %f", scale_x, scale_y); PQclear(poResult); } /* If we build a raster for the whole table, than we have a spatial index, and a primary key, and we know the pixel size, we can build the dataset immediately, and IRasterIO() queries will be able to retrieve quickly the PKID of the tiles to fetch, so we don't need to scan the whole table */ if( bIsFastPK && nMode == ONE_RASTER_PER_TABLE && HasSpatialIndex() && scale_x != 0 && scale_y != 0 ) { adfGeoTransform[GEOTRSFRM_TOPLEFT_X] = xmin; adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1] = 0.0; adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] = (scale_y < 0) ? ymax : ymin; adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] = 0.0; adfGeoTransform[GEOTRSFRM_WE_RES] = scale_x; adfGeoTransform[GEOTRSFRM_NS_RES] = scale_y; // Calculate the raster size from the geotransform array nRasterXSize = (int) fabs(rint((xmax - xmin) / adfGeoTransform[GEOTRSFRM_WE_RES])); nRasterYSize = (int) fabs(rint((ymax - ymin) / adfGeoTransform[GEOTRSFRM_NS_RES])); #ifdef DEBUG_VERBOSE CPLDebug( "PostGIS_Raster", "PostGISRasterDataset::ConstructOneDatasetFromTiles: " "Raster size: (%d, %d), ",nRasterXSize, nRasterYSize); #endif if (nRasterXSize <= 0 || nRasterYSize <= 0) { ReportError( CE_Failure, CPLE_AppDefined, "Computed PostGIS Raster dimension is invalid. You " "have probably specified an inappropriate " "resolution." ); return false; } bBuildQuadTreeDynamically = true; /************************************************************** * Now construct the dataset bands ***************************************************************/ int nBandsFetched = 0; BandMetadata * poBandMetaData = GetBandsMetadata(&nBandsFetched); BuildBands(poBandMetaData, nBandsFetched); // And free bandmetadata VSIFree(poBandMetaData); return true; } osCommand.Printf("select %s, st_metadata(%s) from %s.%s", pszPrimaryKeyName, pszColumn, pszSchema, pszTable); // srid should not be necessary. It was previously checked } else { osCommand.Printf("select %s, st_metadata(%s) from %s.%s " "where %s", pszPrimaryKeyName, pszColumn, pszSchema, pszTable, pszWhere); } } // No primary key/unique id found. We rely on upper left pixel else { if (pszWhere == nullptr) { osCommand.Printf("select st_metadata(%s) from %s.%s", pszColumn, pszSchema, pszTable); } else { osCommand.Printf("select st_metadata(%s) from %s.%s " "where %s", pszColumn, pszSchema, pszTable, pszWhere); } } #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties(): Query: %s", osCommand.c_str()); #endif poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_TUPLES_OK || PQntuples(poResult) <= 0) { ReportError(CE_Failure, CPLE_AppDefined, "Error retrieving raster metadata"); CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties(): %s", PQerrorMessage(poConn)); if (poResult != nullptr) PQclear(poResult); return false; } // Now we know the number of tiles that form our dataset m_nTiles = PQntuples(poResult); /******************************************************************* * We are going to create a whole dataset as a mosaic with all the * tiles. We'll consider each tile as a VRT source for * PostGISRasterRasterBand. The data will be actually read by each * of these sources, and it will be cached in the sources' caches, * not in the PostGISRasterRasterBand cache ******************************************************************/ if (m_nTiles == 1 || nMode == ONE_RASTER_PER_TABLE) { #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties(): " "Constructing one dataset from %d tiles", m_nTiles); #endif GBool res = ConstructOneDatasetFromTiles(poResult); PQclear(poResult); return res; } /*************************************************************** * One raster per row: collect subdatasets **************************************************************/ else if (nMode == ONE_RASTER_PER_ROW) { #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::SetRasterProperties(): " "Reporting %d datasets", m_nTiles); #endif GBool res = YieldSubdatasets(poResult, pszValidConnectionString); PQclear(poResult); return res; } /*************************************************************** * Wrong mode: error **************************************************************/ else { ReportError(CE_Failure, CPLE_AppDefined, "Wrong driver working mode. You must specify mode = 1 or " "mode = 2 in the connection string. Check PostGIS Raster " "documentation at " "http://trac.osgeo.org/gdal/wiki/frmts_wtkraster.html " "for further information about working modes."); PQclear(poResult); return false; } } /*********************************************************************** * \brief Get the connection information for a filename. * * This method extracts these dataset parameters from the connection * string, if present: * - pszSchema: The schema where the table belongs * - pszTable: The table's name * - pszColumn: The raster column's name * - pszWhere: A where constraint to apply to the table's rows * - pszHost: The PostgreSQL host * - pszPort: The PostgreSQL port * - pszUser: The PostgreSQL user * - pszPassword: The PostgreSQL password * - nMode: The connection mode * * If any of there parameters is not present in the connection string, * default values are taken. nMode is deducted from the rest of * parameters if not provided. * * Apart from that, bBrowseDatabase is set to TRUE if the mode is * BROWSE_SCHEMA or BROWSE_DATABASE **********************************************************************/ static GBool GetConnectionInfo(const char * pszFilename, char ** ppszConnectionString, char ** ppszDbname, char ** ppszSchema, char ** ppszTable, char ** ppszColumn, char ** ppszWhere, char ** ppszHost, char ** ppszPort, char ** ppszUser, char ** ppszPassword, WorkingMode * nMode, GBool * bBrowseDatabase) { int nPos = -1, i; char * pszTmp = nullptr; char **papszParams = ParseConnectionString(pszFilename); if (papszParams == nullptr) { return false; } /******************************************************************* * Get mode: * - 1. ONE_RASTER_PER_ROW: Each row is considered as a separate * raster * - 2. ONE_RASTER_PER_TABLE: All the table rows are considered as * a whole raster coverage ******************************************************************/ nPos = CSLFindName(papszParams, "mode"); if (nPos != -1) { int tmp; tmp = atoi(CPLParseNameValue(papszParams[nPos], nullptr)); // default value *nMode = ONE_RASTER_PER_ROW; if (tmp == 2) { *nMode = ONE_RASTER_PER_TABLE; } /* Remove the mode from connection string */ papszParams = CSLRemoveStrings(papszParams, nPos, 1, nullptr); } /* Default mode */ else *nMode = ONE_RASTER_PER_ROW; /** * Case 1: There's no database name: Error, you need, at least, * specify a database name (NOTE: insensitive search) **/ nPos = CSLFindName(papszParams, "dbname"); if (nPos == -1) { CPLError(CE_Failure, CPLE_AppDefined, "You must specify at least a db name"); CSLDestroy(papszParams); return false; } *ppszDbname = CPLStrdup(CPLParseNameValue(papszParams[nPos], nullptr)); /** * Case 2: There's database name, but no table name: activate a flag * for browsing the database, fetching all the schemas that contain * raster tables **/ nPos = CSLFindName(papszParams, "table"); if (nPos == -1) { *bBrowseDatabase = true; /* Get schema name, if exist */ nPos = CSLFindName(papszParams, "schema"); if (nPos != -1) { *ppszSchema = CPLStrdup(CPLParseNameValue(papszParams[nPos], nullptr)); /* Delete this pair from params array */ papszParams = CSLRemoveStrings(papszParams, nPos, 1, nullptr); } /** * Remove the rest of the parameters, if exist (they must not be * present if we want a valid PQ connection string) **/ nPos = CSLFindName(papszParams, "column"); if (nPos != -1) { /* Delete this pair from params array */ papszParams = CSLRemoveStrings(papszParams, nPos, 1, nullptr); } nPos = CSLFindName(papszParams, "where"); if (nPos != -1) { /* Delete this pair from params array */ papszParams = CSLRemoveStrings(papszParams, nPos, 1, nullptr); } } else { *ppszTable = CPLStrdup(CPLParseNameValue(papszParams[nPos], nullptr)); /* Delete this pair from params array */ papszParams = CSLRemoveStrings(papszParams, nPos, 1, nullptr); /** * Case 3: There's database and table name, but no column * name: Use a default column name and use the table to create * the dataset **/ nPos = CSLFindName(papszParams, "column"); if (nPos == -1) { *ppszColumn = CPLStrdup(DEFAULT_COLUMN); } /** * Case 4: There's database, table and column name: Use the * table to create a dataset **/ else { *ppszColumn = CPLStrdup(CPLParseNameValue(papszParams[nPos], nullptr)); /* Delete this pair from params array */ papszParams = CSLRemoveStrings(papszParams, nPos, 1, nullptr); } /* Get the rest of the parameters, if exist */ nPos = CSLFindName(papszParams, "schema"); if (nPos == -1) { *ppszSchema = CPLStrdup(DEFAULT_SCHEMA); } else { *ppszSchema = CPLStrdup(CPLParseNameValue(papszParams[nPos], nullptr)); /* Delete this pair from params array */ papszParams = CSLRemoveStrings(papszParams, nPos, 1, nullptr); } nPos = CSLFindName(papszParams, "where"); if (nPos != -1) { *ppszWhere = CPLStrdup(CPLParseNameValue(papszParams[nPos], nullptr)); /* Delete this pair from params array */ papszParams = CSLRemoveStrings(papszParams, nPos, 1, nullptr); } } /* Parse ppszWhere, if needed */ if (*ppszWhere) { pszTmp = ReplaceQuotes(*ppszWhere, static_cast<int>(strlen(*ppszWhere))); CPLFree(*ppszWhere); *ppszWhere = pszTmp; } /*************************************** * Construct a valid connection string ***************************************/ CPLString osConnectionString; for (i = 0; i < CSLCount(papszParams); i++) { osConnectionString += papszParams[i]; osConnectionString += " "; } *ppszConnectionString = CPLStrdup(osConnectionString); nPos = CSLFindName(papszParams, "host"); if (nPos != -1) { *ppszHost = CPLStrdup(CPLParseNameValue(papszParams[nPos], nullptr)); } else if (CPLGetConfigOption("PGHOST", nullptr) != nullptr) { *ppszHost = CPLStrdup(CPLGetConfigOption("PGHOST", nullptr)); } else *ppszHost = nullptr; /*else { CPLError(CE_Failure, CPLE_AppDefined, "Host parameter must be provided, or PGHOST environment " "variable must be set. Please set the host and try again."); CSLDestroy(papszParams); return false; }*/ nPos = CSLFindName(papszParams, "port"); if (nPos != -1) { *ppszPort = CPLStrdup(CPLParseNameValue(papszParams[nPos], nullptr)); } else if (CPLGetConfigOption("PGPORT", nullptr) != nullptr ) { *ppszPort = CPLStrdup(CPLGetConfigOption("PGPORT", nullptr)); } else *ppszPort = nullptr; /*else { CPLError(CE_Failure, CPLE_AppDefined, "Port parameter must be provided, or PGPORT environment " "variable must be set. Please set the port and try again."); CSLDestroy(papszParams); return false; }*/ nPos = CSLFindName(papszParams, "user"); if (nPos != -1) { *ppszUser = CPLStrdup(CPLParseNameValue(papszParams[nPos], nullptr)); } else if (CPLGetConfigOption("PGUSER", nullptr) != nullptr ) { *ppszUser = CPLStrdup(CPLGetConfigOption("PGUSER", nullptr)); } else *ppszUser = nullptr; /*else { CPLError(CE_Failure, CPLE_AppDefined, "User parameter must be provided, or PGUSER environment " "variable must be set. Please set the user and try again."); CSLDestroy(papszParams); return false; }*/ nPos = CSLFindName(papszParams, "password"); if (nPos != -1) { *ppszPassword = CPLStrdup(CPLParseNameValue(papszParams[nPos], nullptr)); } else if (CPLGetConfigOption("PGPASSWORD", nullptr) != nullptr ) { *ppszPassword = CPLStrdup(CPLGetConfigOption("PGPASSWORD", nullptr)); } else *ppszPassword = nullptr; CSLDestroy(papszParams); #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::GetConnectionInfo(): " "Mode: %d\nDbname: %s\nSchema: %s\nTable: %s\nColumn: %s\nWhere: %s\n" "Host: %s\nPort: %s\nUser: %s\nPassword: %s\n" "Connection String: %s\n", *nMode, *ppszDbname, *ppszSchema ? *ppszSchema : "(null)", *ppszTable ? *ppszTable : "(null)", *ppszColumn ? *ppszColumn : "(null)", *ppszWhere ? *ppszWhere : "(null)", *ppszHost ? *ppszHost : "(null)", *ppszPort ? *ppszPort : "(null)", *ppszUser ? *ppszUser : "(null)", *ppszPassword ? *ppszPassword : "(null)", *ppszConnectionString); #endif return true; } /*********************************************************************** * \brief Create a connection to a postgres database **********************************************************************/ static PGconn * GetConnection(const char * pszFilename, char ** ppszConnectionString, char ** ppszSchema, char ** ppszTable, char ** ppszColumn, char ** ppszWhere, WorkingMode * nMode, GBool * bBrowseDatabase) { PGconn * poConn = nullptr; char * pszDbname = nullptr; char * pszHost = nullptr; char * pszPort = nullptr; char * pszUser = nullptr; char * pszPassword = nullptr; if (GetConnectionInfo(pszFilename, ppszConnectionString, &pszDbname, ppszSchema, ppszTable, ppszColumn, ppszWhere, &pszHost, &pszPort, &pszUser, &pszPassword, nMode, bBrowseDatabase)) { /************************************************************** * Open a new database connection **************************************************************/ PostGISRasterDriver * poDriver = (PostGISRasterDriver *)GDALGetDriverByName("PostGISRaster"); poConn = poDriver->GetConnection(*ppszConnectionString, pszDbname, pszHost, pszPort, pszUser); if (poConn == nullptr) { CPLError(CE_Failure, CPLE_AppDefined, "Couldn't establish a database connection"); } } CPLFree(pszDbname); CPLFree(pszHost); CPLFree(pszPort); CPLFree(pszUser); CPLFree(pszPassword); return poConn; } /************************************************************************/ /* Identify() */ /************************************************************************/ int PostGISRasterDataset::Identify(GDALOpenInfo* poOpenInfo) { if (poOpenInfo->pszFilename == nullptr || poOpenInfo->fpL != nullptr || !STARTS_WITH_CI(poOpenInfo->pszFilename, "PG:")) { return FALSE; } // Will avoid a OGR PostgreSQL connection string to be recognized as a // PostgisRaster one and later fail (#6034) if( strstr(poOpenInfo->pszFilename, " schemas=") || strstr(poOpenInfo->pszFilename, " SCHEMAS=") ) { return FALSE; } return TRUE; } /*********************************************************************** * \brief Open a connection with PostgreSQL. The connection string will * have the PostgreSQL accepted format, plus the next key=value pairs: * schema = &lt;schema_name&gt; * table = &lt;table_name&gt; * column = &lt;column_name&gt; * where = &lt;SQL where&gt; * mode = &lt;working mode&gt; (1 or 2) * * These pairs are used for selecting the right raster table. **********************************************************************/ GDALDataset* PostGISRasterDataset::Open(GDALOpenInfo* poOpenInfo) { char* pszConnectionString = nullptr; char* pszSchema = nullptr; char* pszTable = nullptr; char* pszColumn = nullptr; char* pszWhere = nullptr; WorkingMode nMode = NO_MODE; PGconn * poConn = nullptr; PostGISRasterDataset* poDS = nullptr; GBool bBrowseDatabase = false; CPLString osCommand; /************************** * Check input parameter **************************/ if (!Identify(poOpenInfo)) return nullptr; poConn = GetConnection(poOpenInfo->pszFilename, &pszConnectionString, &pszSchema, &pszTable, &pszColumn, &pszWhere, &nMode, &bBrowseDatabase); if (poConn == nullptr) { CPLFree(pszConnectionString); CPLFree(pszSchema); CPLFree(pszTable); CPLFree(pszColumn); CPLFree(pszWhere); return nullptr; } /******************************************************************* * No table will be read. Only shows information about the existent * raster tables ******************************************************************/ if (bBrowseDatabase) { /** * Creates empty dataset object, only for subdatasets **/ poDS = new PostGISRasterDataset(); poDS->poConn = poConn; poDS->eAccess = GA_ReadOnly; //poDS->poDriver = poDriver; poDS->nMode = (pszSchema) ? BROWSE_SCHEMA : BROWSE_DATABASE; /** * Look for raster tables at database and * store them as subdatasets **/ if (!poDS->BrowseDatabase(pszSchema, pszConnectionString)) { CPLFree(pszConnectionString); delete poDS; if (pszSchema) CPLFree(pszSchema); if (pszTable) CPLFree(pszTable); if (pszColumn) CPLFree(pszColumn); if (pszWhere) CPLFree(pszWhere); return nullptr; } if (pszSchema) CPLFree(pszSchema); if (pszTable) CPLFree(pszTable); if (pszColumn) CPLFree(pszColumn); if (pszWhere) CPLFree(pszWhere); } /******************************************************************* * A table will be read as dataset: Fetch raster properties from db. ******************************************************************/ else { poDS = new PostGISRasterDataset(); poDS->poConn = poConn; poDS->eAccess = poOpenInfo->eAccess; poDS->nMode = nMode; //poDS->poDriver = poDriver; poDS->pszSchema = pszSchema; poDS->pszTable = pszTable; poDS->pszColumn = pszColumn; poDS->pszWhere = pszWhere; /** * Fetch basic raster metadata from db **/ #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "Open:: connection string = %s", pszConnectionString); #endif if (!poDS->SetRasterProperties(pszConnectionString)) { CPLFree(pszConnectionString); delete poDS; return nullptr; } } CPLFree(pszConnectionString); return poDS; } /************************************************************************/ /* GetMetadataDomainList() */ /************************************************************************/ char **PostGISRasterDataset::GetMetadataDomainList() { return BuildMetadataDomainList(GDALDataset::GetMetadataDomainList(), TRUE, "SUBDATASETS", NULL); } /***************************************** * \brief Get Metadata from raster * TODO: Add more options (the result of * calling ST_Metadata, for example) *****************************************/ char** PostGISRasterDataset::GetMetadata(const char *pszDomain) { if (pszDomain != nullptr && STARTS_WITH_CI(pszDomain, "SUBDATASETS")) return papszSubdatasets; else return GDALDataset::GetMetadata(pszDomain); } /***************************************************** * \brief Fetch the projection definition string * for this dataset in OpenGIS WKT format. It should * be suitable for use with the OGRSpatialReference * class. *****************************************************/ const char* PostGISRasterDataset::GetProjectionRef() { CPLString osCommand; if (nSrid == -1) return ""; if (pszProjection) return pszProjection; /******************************************************** * Reading proj from database ********************************************************/ osCommand.Printf("SELECT srtext FROM spatial_ref_sys where SRID=%d", nSrid); PGresult* poResult = PQexec(this->poConn, osCommand.c_str()); if (poResult && PQresultStatus(poResult) == PGRES_TUPLES_OK && PQntuples(poResult) > 0) { pszProjection = CPLStrdup(PQgetvalue(poResult, 0, 0)); } if (poResult) PQclear(poResult); return pszProjection; } /********************************************************** * \brief Set projection definition. The input string must * be in OGC WKT or PROJ.4 format **********************************************************/ CPLErr PostGISRasterDataset::SetProjection(const char * pszProjectionRef) { VALIDATE_POINTER1(pszProjectionRef, "SetProjection", CE_Failure); CPLString osCommand; int nFetchedSrid = -1; /***************************************************************** * Check if the dataset allows updating *****************************************************************/ if (GetAccess() != GA_Update) { ReportError(CE_Failure, CPLE_NoWriteAccess, "This driver doesn't allow write access"); return CE_Failure; } /***************************************************************** * Look for projection with this text *****************************************************************/ // First, WKT text osCommand.Printf("SELECT srid FROM spatial_ref_sys where srtext='%s'", pszProjectionRef); PGresult * poResult = PQexec(poConn, osCommand.c_str()); if (poResult && PQresultStatus(poResult) == PGRES_TUPLES_OK && PQntuples(poResult) > 0) { nFetchedSrid = atoi(PQgetvalue(poResult, 0, 0)); // update class attribute nSrid = nFetchedSrid; // update raster_columns table osCommand.Printf("UPDATE raster_columns SET srid=%d WHERE \ r_table_name = '%s' AND r_column = '%s'", nSrid, pszTable, pszColumn); poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { ReportError(CE_Failure, CPLE_AppDefined, "Couldn't update raster_columns table: %s", PQerrorMessage(poConn)); return CE_Failure; } // TODO: Update ALL blocks with the new srid... return CE_None; } // If not, proj4 text else { osCommand.Printf( "SELECT srid FROM spatial_ref_sys where proj4text='%s'", pszProjectionRef); poResult = PQexec(poConn, osCommand.c_str()); if (poResult && PQresultStatus(poResult) == PGRES_TUPLES_OK && PQntuples(poResult) > 0) { nFetchedSrid = atoi(PQgetvalue(poResult, 0, 0)); // update class attribute nSrid = nFetchedSrid; // update raster_columns table osCommand.Printf("UPDATE raster_columns SET srid=%d WHERE \ r_table_name = '%s' AND r_column = '%s'", nSrid, pszTable, pszColumn); poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { ReportError(CE_Failure, CPLE_AppDefined, "Couldn't update raster_columns table: %s", PQerrorMessage(poConn)); return CE_Failure; } // TODO: Update ALL blocks with the new srid... return CE_None; } else { ReportError(CE_Failure, CPLE_WrongFormat, "Couldn't find WKT neither proj4 definition"); return CE_Failure; } } } /******************************************************** * \brief Set the affine transformation coefficients ********************************************************/ CPLErr PostGISRasterDataset::SetGeoTransform(double* padfGeoTransform) { if (!padfGeoTransform) return CE_Failure; memcpy(adfGeoTransform, padfGeoTransform, 6 * sizeof(double)); return CE_None; } /******************************************************** * \brief Get the affine transformation coefficients ********************************************************/ CPLErr PostGISRasterDataset::GetGeoTransform(double * padfGeoTransform) { // copy necessary values in supplied buffer memcpy(padfGeoTransform, adfGeoTransform, 6 * sizeof(double)); if( nRasterXSize == 0 && nRasterYSize == 0 ) return CE_Failure; /* To avoid QGIS trying to create a warped VRT for what is really */ /* an ungeoreferenced dataset */ if( CPLIsEqual(padfGeoTransform[0], 0.0) && CPLIsEqual(padfGeoTransform[1], 1.0) && CPLIsEqual(padfGeoTransform[2], 0.0) && CPLIsEqual(padfGeoTransform[3], 0.0) && CPLIsEqual(padfGeoTransform[4], 0.0) && CPLIsEqual(padfGeoTransform[5], 1.0) ) { return CE_Failure; } return CE_None; } /********************************************************* * \brief Fetch files forming dataset. * * We need to define this method because the VRTDataset * method doesn't check for NULL FileList before trying * to collect the names of all sources' file list. *********************************************************/ char **PostGISRasterDataset::GetFileList() { return nullptr; } /******************************************************** * \brief Create a copy of a PostGIS Raster dataset. ********************************************************/ GDALDataset * PostGISRasterDataset::CreateCopy( CPL_UNUSED const char * pszFilename, GDALDataset *poGSrcDS, CPL_UNUSED int bStrict, CPL_UNUSED char ** papszOptions, CPL_UNUSED GDALProgressFunc pfnProgress, CPL_UNUSED void * pProgressData ) { char* pszSchema = nullptr; char* pszTable = nullptr; char* pszColumn = nullptr; char* pszWhere = nullptr; GBool bBrowseDatabase = false; WorkingMode nMode; char* pszConnectionString = nullptr; PGconn * poConn = nullptr; PGresult * poResult = nullptr; CPLString osCommand; GBool bInsertSuccess; if( poGSrcDS->GetDriver() != GDALGetDriverByName("PostGISRaster") ) { CPLError( CE_Failure, CPLE_NotSupported, "PostGISRasterDataset::CreateCopy() only works on source " "datasets that are PostGISRaster" ); return nullptr; } // Now we can do the cast PostGISRasterDataset *poSrcDS = (PostGISRasterDataset *)poGSrcDS; // Check connection string if (pszFilename == nullptr || !STARTS_WITH_CI(pszFilename, "PG:")) { /** * The connection string provided is not a valid connection * string. */ CPLError( CE_Failure, CPLE_NotSupported, "PostGIS Raster driver was unable to parse the provided " "connection string." ); return nullptr; } poConn = GetConnection(pszFilename, &pszConnectionString, &pszSchema, &pszTable, &pszColumn, &pszWhere, &nMode, &bBrowseDatabase); if (poConn == nullptr || bBrowseDatabase || pszTable == nullptr) { CPLFree(pszConnectionString); CPLFree(pszSchema); CPLFree(pszTable); CPLFree(pszColumn); CPLFree(pszWhere); // if connection info fails, browsing mode, or no table set return nullptr; } // begin transaction poResult = PQexec(poConn, "begin"); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Error beginning database transaction: %s", PQerrorMessage(poConn)); if (poResult != nullptr) PQclear(poResult); if (pszSchema) CPLFree(pszSchema); if (pszTable) CPLFree(pszTable); if (pszColumn) CPLFree(pszColumn); if (pszWhere) CPLFree(pszWhere); CPLFree(pszConnectionString); return nullptr; } PQclear(poResult); // create table for raster (if not exists because a // dataset will not be reported for an empty table) // TODO: is 'rid' necessary? osCommand.Printf("create table if not exists %s.%s (rid serial, %s " "public.raster, constraint %s_pkey primary key (rid));", pszSchema, pszTable, pszColumn, pszTable); poResult = PQexec(poConn, osCommand.c_str()); if ( poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Error creating needed tables: %s", PQerrorMessage(poConn)); if (poResult != nullptr) PQclear(poResult); // rollback poResult = PQexec(poConn, "rollback"); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Error rolling back transaction: %s", PQerrorMessage(poConn)); } if (poResult != nullptr) PQclear(poResult); if (pszSchema) CPLFree(pszSchema); if (pszTable) CPLFree(pszTable); if (pszColumn) CPLFree(pszColumn); if (pszWhere) CPLFree(pszWhere); CPLFree(pszConnectionString); return nullptr; } PQclear(poResult); osCommand.Printf("create index %s_%s_gist ON %s.%s USING gist " "(public.st_convexhull(%s));", pszTable, pszColumn, pszSchema, pszTable, pszColumn); poResult = PQexec(poConn, osCommand.c_str()); if ( poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Error creating needed index: %s", PQerrorMessage(poConn)); if (poResult != nullptr) PQclear(poResult); // rollback poResult = PQexec(poConn, "rollback"); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Error rolling back transaction: %s", PQerrorMessage(poConn)); } if (poResult != nullptr) PQclear(poResult); if (pszSchema) CPLFree(pszSchema); if (pszTable) CPLFree(pszTable); if (pszColumn) CPLFree(pszColumn); if (pszWhere) CPLFree(pszWhere); CPLFree(pszConnectionString); return nullptr; } PQclear(poResult); const char* pszSubdatasetName = nullptr; PostGISRasterDataset *poSubDS = nullptr; if (poSrcDS->nMode == ONE_RASTER_PER_TABLE) { // one raster per table // insert one raster bInsertSuccess = InsertRaster(poConn, poSrcDS, pszSchema, pszTable, pszColumn); if (!bInsertSuccess) { // rollback poResult = PQexec(poConn, "rollback"); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Error rolling back transaction: %s", PQerrorMessage(poConn)); } if (poResult != nullptr) PQclear(poResult); if (pszSchema) CPLFree(pszSchema); if (pszTable) CPLFree(pszTable); if (pszColumn) CPLFree(pszColumn); if (pszWhere) CPLFree(pszWhere); CPLFree(pszConnectionString); return nullptr; } } else if (poSrcDS->nMode == ONE_RASTER_PER_ROW) { // one raster per row // papszSubdatasets contains name/desc for each subdataset for (int i = 0; i < CSLCount(poSrcDS->papszSubdatasets); i += 2) { pszSubdatasetName = CPLParseNameValue( poSrcDS->papszSubdatasets[i], nullptr); if (pszSubdatasetName == nullptr) { CPLDebug("PostGIS_Raster", "PostGISRasterDataset::CreateCopy(): " "Could not parse name/value out of subdataset list: " "%s", poSrcDS->papszSubdatasets[i]); continue; } // for each subdataset GDALOpenInfo poOpenInfo( pszSubdatasetName, GA_ReadOnly ); // open the subdataset poSubDS = (PostGISRasterDataset *)Open(&poOpenInfo); if (poSubDS == nullptr) { // notify! CPLDebug("PostGIS_Raster", "PostGISRasterDataset::CreateCopy(): " "Could not open a subdataset: %s", pszSubdatasetName); continue; } // insert one raster bInsertSuccess = InsertRaster(poConn, poSubDS, pszSchema, pszTable, pszColumn); if (!bInsertSuccess) { CPLDebug("PostGIS_Raster", "PostGISRasterDataset::CreateCopy(): " "Could not copy raster subdataset to new dataset." ); // keep trying ... } // close this dataset GDALClose((GDALDatasetH)poSubDS); } } // commit transaction poResult = PQexec(poConn, "commit"); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Error committing database transaction: %s", PQerrorMessage(poConn)); if (poResult != nullptr) PQclear(poResult); if (pszSchema) CPLFree(pszSchema); if (pszTable) CPLFree(pszTable); if (pszColumn) CPLFree(pszColumn); if (pszWhere) CPLFree(pszWhere); CPLFree(pszConnectionString); return nullptr; } PQclear(poResult); if (pszSchema) CPLFree(pszSchema); if (pszTable) CPLFree(pszTable); if (pszColumn) CPLFree(pszColumn); if (pszWhere) CPLFree(pszWhere); CPLFree(pszConnectionString); CPLDebug("PostGIS_Raster", "PostGISRasterDataset::CreateCopy(): " "Opening new dataset: %s", pszFilename); // connect to the new dataset GDALOpenInfo poOpenInfo( pszFilename, GA_Update ); // open the newdataset poSubDS = (PostGISRasterDataset *)Open(&poOpenInfo); if (poSubDS == nullptr) { CPLDebug("PostGIS_Raster", "PostGISRasterDataset::CreateCopy(): " "New dataset could not be opened."); } return poSubDS; } /******************************************************** * \brief Helper method to insert a new raster. ********************************************************/ GBool PostGISRasterDataset::InsertRaster(PGconn * poConn, PostGISRasterDataset * poSrcDS, const char *pszSchema, const char * pszTable, const char * pszColumn) { CPLString osCommand; PGresult * poResult = nullptr; if (poSrcDS->pszWhere == nullptr) { osCommand.Printf("insert into %s.%s (%s) (select %s from %s.%s)", pszSchema, pszTable, pszColumn, poSrcDS->pszColumn, poSrcDS->pszSchema, poSrcDS->pszTable); } else { osCommand.Printf("insert into %s.%s (%s) (select %s from %s.%s where %s)", pszSchema, pszTable, pszColumn, poSrcDS->pszColumn, poSrcDS->pszSchema, poSrcDS->pszTable, poSrcDS->pszWhere); } #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterDataset::InsertRaster(): Query = %s", osCommand.c_str()); #endif poResult = PQexec(poConn, osCommand.c_str()); if ( poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Error inserting raster: %s", PQerrorMessage(poConn)); if (poResult != nullptr) PQclear(poResult); return false; } PQclear(poResult); return true; } /********************************************************* * \brief Delete a PostGIS Raster dataset. *********************************************************/ CPLErr PostGISRasterDataset::Delete(const char* pszFilename) { char* pszSchema = nullptr; char* pszTable = nullptr; char* pszColumn = nullptr; char* pszWhere = nullptr; GBool bBrowseDatabase; char* pszConnectionString = nullptr; WorkingMode nMode; PGconn * poConn = nullptr; PGresult * poResult = nullptr; CPLString osCommand; CPLErr nError = CE_Failure; // Check connection string if (pszFilename == nullptr || !STARTS_WITH_CI(pszFilename, "PG:")) { /** * The connection string provided is not a valid connection * string. */ CPLError( CE_Failure, CPLE_NotSupported, "PostGIS Raster driver was unable to parse the provided " "connection string. Nothing was deleted." ); return CE_Failure; } poConn = GetConnection(pszFilename, &pszConnectionString, &pszSchema, &pszTable, &pszColumn, &pszWhere, &nMode, &bBrowseDatabase); if (poConn == nullptr || pszSchema == nullptr || pszTable == nullptr) { CPLFree(pszConnectionString); CPLFree(pszSchema); CPLFree(pszTable); CPLFree(pszColumn); CPLFree(pszWhere); return CE_Failure; } // begin transaction poResult = PQexec(poConn, "begin"); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Error beginning database transaction: %s", PQerrorMessage(poConn)); // set nMode to NO_MODE to avoid any further processing nMode = NO_MODE; } PQclear(poResult); if ( nMode == ONE_RASTER_PER_TABLE || (nMode == ONE_RASTER_PER_ROW && pszWhere == nullptr)) { // without a where clause, this delete command shall delete // all subdatasets, even if the mode is ONE_RASTER_PER_ROW // drop table <schema>.<table>; osCommand.Printf("drop table %s.%s", pszSchema, pszTable); poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Couldn't drop the table %s.%s: %s", pszSchema, pszTable, PQerrorMessage(poConn)); } else { PQclear(poResult); nError = CE_None; } } else if (nMode == ONE_RASTER_PER_ROW) { // delete from <schema>.<table> where <where> osCommand.Printf("delete from %s.%s where %s", pszSchema, pszTable, pszWhere); poResult = PQexec(poConn, osCommand.c_str()); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Couldn't delete records from the table %s.%s: %s", pszSchema, pszTable, PQerrorMessage(poConn)); } else { PQclear(poResult); nError = CE_None; } } // if mode == NO_MODE, the begin transaction above did not complete, // so no commit is necessary if (nMode != NO_MODE) { poResult = PQexec(poConn, "commit"); if (poResult == nullptr || PQresultStatus(poResult) != PGRES_COMMAND_OK) { CPLError(CE_Failure, CPLE_AppDefined, "Error committing database transaction: %s", PQerrorMessage(poConn)); nError = CE_Failure; } } if (poResult) PQclear(poResult); if (pszSchema) CPLFree(pszSchema); if (pszTable) CPLFree(pszTable); if (pszColumn) CPLFree(pszColumn); if (pszWhere) CPLFree(pszWhere); // clean up connection string CPLFree(pszConnectionString); return nError; } /*********************************************************************** * \brief Create an array with all the coordinates needed to construct * a polygon using ST_PolygonFromText. **********************************************************************/ GBool PostGISRasterDataset::PolygonFromCoords( int nXOff, int nYOff, int nXEndOff, int nYEndOff, double adfProjWin[8]) { // We first construct a polygon to intersect with int ulx = nXOff; int uly = nYOff; int lrx = nXEndOff; int lry = nYEndOff; double xRes = adfGeoTransform[GEOTRSFRM_WE_RES]; double yRes = adfGeoTransform[GEOTRSFRM_NS_RES]; adfProjWin[0] = adfGeoTransform[GEOTRSFRM_TOPLEFT_X] + ulx * xRes + uly * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1]; adfProjWin[1] = adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] + ulx * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] + uly * yRes; adfProjWin[2] = adfGeoTransform[GEOTRSFRM_TOPLEFT_X] + lrx * xRes + uly * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1]; adfProjWin[3] = adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] + lrx * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] + uly * yRes; adfProjWin[4] = adfGeoTransform[GEOTRSFRM_TOPLEFT_X] + lrx * xRes + lry * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1]; adfProjWin[5] = adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] + lrx * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] + lry * yRes; adfProjWin[6] = adfGeoTransform[GEOTRSFRM_TOPLEFT_X] + ulx * xRes + lry * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1]; adfProjWin[7] = adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] + ulx * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] + lry * yRes; #ifdef DEBUG_VERBOSE CPLDebug("PostGIS_Raster", "PostGISRasterDataset::PolygonFromCoords: constructed " "polygon: POLYGON((%.17f %.17f, %.17f %.17f, %.17f %.17f, " "%.17f %.17f, %.17f %.17f))", adfProjWin[0], adfProjWin[1], adfProjWin[2], adfProjWin[3], adfProjWin[4], adfProjWin[5], adfProjWin[6], adfProjWin[7], adfProjWin[0], adfProjWin[1]); #endif return true; } /*********************************************************************** * GDALRegister_PostGISRaster() **********************************************************************/ void GDALRegister_PostGISRaster() { if( !GDAL_CHECK_VERSION( "PostGISRaster driver" ) ) return; if( GDALGetDriverByName( "PostGISRaster" ) != nullptr ) return; GDALDriver *poDriver = new PostGISRasterDriver(); poDriver->SetDescription("PostGISRaster"); poDriver->SetMetadataItem( GDAL_DCAP_RASTER, "YES" ); poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "PostGIS Raster driver"); poDriver->SetMetadataItem( GDAL_DMD_SUBDATASETS, "YES" ); poDriver->pfnOpen = PostGISRasterDataset::Open; poDriver->pfnIdentify = PostGISRasterDataset::Identify; poDriver->pfnCreateCopy = PostGISRasterDataset::CreateCopy; poDriver->pfnDelete = PostGISRasterDataset::Delete; GetGDALDriverManager()->RegisterDriver(poDriver); }
; size_t w_array_size(w_array_t *a) PUBLIC _w_array_size EXTERN asm_w_array_size _w_array_size: pop af pop hl push hl push af jp asm_w_array_size
#include <stdlib.h> #include <string.h> #include <limits> #include <redisclient/redisvalue.h> #define BOOST_TEST_MAIN #define BOOST_TEST_MODULE test_RedisParser #include <boost/test/unit_test.hpp> using namespace redisclient; BOOST_AUTO_TEST_CASE(test_integer) { RedisValue v(100); BOOST_CHECK_EQUAL(v.toInt(), 100); BOOST_CHECK_EQUAL(v.isInt(), true); BOOST_CHECK_EQUAL(v.isOk(), true); } BOOST_AUTO_TEST_CASE(test_integer_pisitive) { RedisValue v(std::numeric_limits<int64_t>::max()); BOOST_CHECK_EQUAL(v.toInt(), std::numeric_limits<int64_t>::max()); BOOST_CHECK_EQUAL(v.isInt(), true); BOOST_CHECK_EQUAL(v.isOk(), true); } BOOST_AUTO_TEST_CASE(test_integer_negative) { RedisValue v(std::numeric_limits<int64_t>::min()); BOOST_CHECK_EQUAL(v.toInt(), std::numeric_limits<int64_t>::min()); BOOST_CHECK_EQUAL(v.isInt(), true); BOOST_CHECK_EQUAL(v.isOk(), true); } BOOST_AUTO_TEST_CASE(test_const_char) { RedisValue v("test string"); BOOST_CHECK_EQUAL(v.toString(), "test string"); BOOST_CHECK_EQUAL(v.isString(), true); BOOST_CHECK_EQUAL(v.isOk(), true); } BOOST_AUTO_TEST_CASE(test_std_string) { RedisValue v(std::string("test string")); BOOST_CHECK_EQUAL(v.toString(), "test string"); BOOST_CHECK_EQUAL(v.isString(), true); BOOST_CHECK_EQUAL(v.isOk(), true); } BOOST_AUTO_TEST_CASE(test_byte_array) { std::vector<char> byteArray{'t', 'e', 's', 't'}; RedisValue v(byteArray); BOOST_CHECK(v.toByteArray() == byteArray); BOOST_CHECK_EQUAL(v.isByteArray(), true); BOOST_CHECK_EQUAL(v.isOk(), true); } BOOST_AUTO_TEST_CASE(test_error) { std::vector<char> byteArray{'t', 'e', 's', 't'}; RedisValue v(byteArray, RedisValue::ErrorTag{}); BOOST_CHECK(v.toByteArray() == byteArray); BOOST_CHECK_EQUAL(v.isByteArray(), true); BOOST_CHECK_EQUAL(v.isOk(), false); BOOST_CHECK_EQUAL(v.isError(), true); }
\ -*- mode:beebasm -*- \ ****************************************************************** \ * FRAK ZOOMER FX \ ****************************************************************** FRAK_SPRITE_WIDTH=32 FRAK_SPRITE_HEIGHT=43 ; TODO: Need to make this a multiple of 2. FRAK_MAX_ZOOM=55 \\ TODO: Describe the FX and requirements. \\ Describe the track values used: \ ****************************************************************** \ Update FX \ \ The update function is used to update / tick any variables used \ in the FX. It may also prepare part of the screen buffer before \ drawing commenses but note the strict timing constraints! \ \ This function will be called during vblank, after any system \ modules have been polled. \ \ The function MUST COMPLETE BEFORE TIMER 1 REACHES 0, i.e. before \ raster line 0 begins. If you are late then the draw function will \ be late and your raster timings will be wrong! \ ****************************************************************** ;When you start, one 16-bit number will be in product+0-product+1, low byte first as usual for 6502 ;and the other 16-bit number will be in product+2-product+3, same way. When you're done, ;the 32-bit answer will take all four bytes, with the high cell first. ;IOW, $12345678 will be in the order 34 12 78 56. ;Addresses temp+0 and temp+1 will be used as a scratchpad. .multiply_16_by_16 { LDA product+2 ; Get the multiplicand and STA temp+0 ; put it in the scratchpad. LDA product+3 STA temp+1 STZ product+2 ; Zero-out the original multiplicand area. STZ product+3 LDY #16 ; We'll loop 16 times. .loop1 ASL product+2 ; Shift the entire 32 bits over one bit position. ROL product+3 ROL product+0 ROL product+1 BCC loop2 ; Skip the adding-in to the result if ; the high bit shifted out was 0. CLC ; Else, add multiplier to intermediate result. LDA temp+0 ADC product+2 STA product+2 LDA temp+1 ADC product+3 STA product+3 LDA #0 ; If C=1, incr lo byte of hi cell. ADC product+0 STA product+0 .loop2 DEY ; If we haven't done 16 iterations yet, BNE loop1 ; then go around again. RTS } .fx_frak_zoomer_update { \\ Scanline 0,2,4,6 from zoom. lda rocket_track_zoom+1 ; 3c cmp #FRAK_MAX_ZOOM bcc zoom_ok lda #FRAK_MAX_ZOOM-1 .zoom_ok sta zoom tax lda fx_zoom_scanlines, X sta next_scanline \\ Set dv. txa:asl a:tax lda fx_zoom_dv_table+0, X sta fx_zoom_add_dv_LO+1 lda fx_zoom_dv_table+1, X sta fx_zoom_add_dv_HI+1 \\ top_pos = (y_pos - 60*dv) MOD sprite_height sec lda rocket_track_y_pos+0 sbc fx_zoom_viewport_height+0,X sta v+0 lda rocket_track_y_pos+1 sbc fx_zoom_viewport_height+1,X tay lda frak_mod_sprite_height, Y sta v+1 \\ Hi byte of V * 16 clc lda #0:sta temp lda v+1 asl a:rol temp asl a:rol temp asl a:rol temp asl a:rol temp clc adc #LO(frak_data) sta pal_loop+1 lda temp adc #HI(frak_data) sta pal_loop+2 \\ Set palette for first line. \\ Should really be in draw function. ldy #15 ; 2c .pal_loop lda frak_data, y ; 4c sta &fe21 ; 4c dey ; 2c bpl pal_loop ; 3c \\ 2+16*13-1=234c !! \\ ALT: lda (frakptr), Y:sta &fe21:iny ; 11c \\ 16*11=176c hmmmm. \\ Need char offset for left edge of viewport that is 80 units wide, centre is 40. \\ So subtract distance to left edge of viewport before calculating. \\ left_pos = (x_pos - 40*dv) MOD sprite_width \\ char_off = (sprite_width_in_chars_for_zoom * left_pos) / sprite_width. \\ sprite_width_in_chars_for_zoom and x_pos both 12-bits. sec lda rocket_track_x_pos+0 sbc fx_zoom_viewport_width+0,X sta product+0 lda rocket_track_x_pos+1 sbc fx_zoom_viewport_width+1,X and #15 ;MOD FRAK_SPRITE_WIDTH_IN_CHARS sta product+1 lda fx_zoom_max_char_width+0,X:sta product+2 lda fx_zoom_max_char_width+1,X:sta product+3 jsr multiply_16_by_16 ;IOW, $12345678 will be in the order 34 12 78 56. ;We want 345 as a 12-bit number so shift by 4: lsr product+0:ror product+3 lsr product+0:ror product+3 lsr product+0:ror product+3 lsr product+0:ror product+3 lda product+0:sta char_off+1 lda product+3:sta char_off+0 lda #6:sta &fe00 ; 8c lda #1:sta &fe01 ; 8c lda #119:sta row_count ; 5c rts } \ ****************************************************************** \ Draw FX \ \ The draw function is the main body of the FX. \ \ This function will be exactly at the start* of raster line 0 with \ a stablised raster. VC=0 HC=0|1 SC=0 \ \ This means that a new CRTC cycle has just started! If you didn't \ specify the registers from the previous frame then they will be \ the default MODE 0,1,2 values as per initialisation. \ \ If messing with CRTC registers, THIS FUNCTION MUST ALWAYS PRODUCE \ A FULL AND VALID 312 line PAL signal before exiting! \ ****************************************************************** \\ Double-line RVI with no LHS blanking. \\ Display 0,2,4,6 scanline as first row from any other. \\ NB. Can't hide LHS garbage but will only be visible on scanline 0. :\ \\ Set R9 before final scanline to 13 + current - next. eg. R9 = 13 + 6 - 0 = 13 \\ \\ cycles --> 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 0 \\ lda..sta............WAIT_CYCLES 18 ..............................lda..sta ...........| \\ #1 &fe01 #127 &fe01 \\ scanline 1 ^ 2 3 4 5 6 7 8 9 10 11 12 13 xx 0 \\ hpos | \\ --> missed due to end of CRTC cycle + \\ NB. There is no additional scanline if this is not the end of the CRTC cycle. \\ Repeated double-line RVI with LHS blanking. \\ Display 0,2,4,6 scanline as repeated row. \\ Set R9 before final scanline to 9 + current - next = 9 constant. \\ \\ cycles --> 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 0 \\ lda..sta............WAIT_CYCLES 10 ..........lda..stz ...........sta ...........| \\ #1 &fe01 #127 &fe01 &fe01 \\ scanline 7 ^ 8 9 x 0 1 2 3 4 5 ? ? ? 6 \\ hpos | | \\ --> missed due to end of CRTC cycle + + scanline counter prevented from updating whilst R0=0! CODE_ALIGN 32 .fx_frak_zoomer_draw { \\ <=== HCC=0 (scanline=-2) \\ R9 must be set before final scanline of the row. lda #9:sta &fe00 ; 8c \\ Set R9=13+current-next. lda #13 ; 2c clc ; 2c adc prev_scanline ; 3c sec ; 2c sbc next_scanline ; 3c sta &fe01 ; 6c ldx next_scanline ; 3c stx prev_scanline ; 3c \\ 24c \\ Set screen address for zoom. lda zoom ; 3c asl a:tax ; 4c lda #13:sta &fe00 ; 8c <= 7c lda fx_zoom_crtc_addresses+0, X ; 4c clc ; 2c adc char_off ; 3c sta &fe01 ; 6c <= 5c lda #12:sta &fe00 ; 8c lda fx_zoom_crtc_addresses+1, X ; 4c adc char_off+1 ; 3c sta &fe01 ; 6c <= 5c \\ 48c \\ This FX always uses screen in MAIN RAM. \\ TODO: Add a data byte to specify MAIN or SHADOW. ; clear bit 0 to display MAIN. lda &fe34:and #&fe:sta &fe34 ; 10c WAIT_CYCLES 38 \\ <=== HCC=0 (scanline=-1) \\ Set R0=101 (102c) lda #0:sta &fe00 ; 8c lda #101:sta &fe01 ; 8c WAIT_CYCLES 78 \\ <=== HCC=94 (scanline=-1) lda #1:sta &fe01 ; 8c \\ <=== HCC=102 (scanline=-1) \\ Burn R0=1 scanlines. WAIT_CYCLES 14 ldx #4 ; 2c ldy #9 ; 2c \\ At HCC=0 set R0=127. lda #127:sta &fe01 ; 8c \\ <=== HCC=0 (scanline=0) \\ Set R4=0 (one row per cycle). stx &fe00 ; 6c stz &fe01 ; 6c \\ 2x scanlines per row. .scanline_loop { \\ <=== HCC=12 (scanline=even) \\ Update texture v. clc ; 2c lda v ; 3c .*fx_zoom_add_dv_LO adc #128 ; 2c sta v ; 3c lda v+1 ; 3c .*fx_zoom_add_dv_HI adc #0 ; 2c cmp #FRAK_SPRITE_HEIGHT ; 2c bcc ok ; 2c sbc #FRAK_SPRITE_HEIGHT ; 2c jmp store ; 3c .ok ; 3c WAIT_CYCLES 4 .store sta v+1 ; 3c \\ 27c tax ; 2c lda frak_lines_LO, X ; 4c sta set_palette+1 ; 4c lda frak_lines_HI, X ; 4c sta set_palette+2 ; 4c \\ 18c \\ Set R9=9 constant. sty &fe00 ; 6c <= 5c sty &fe01 ; 6c \\ <=== HCC=68 (scanline=even) .set_palette jsr frak_line0 ; 60c \\ <=== HCC=0 (scanline=odd) lda #0:sta &fe00 ; 8c lda #103:sta &fe01 ; 8c WAIT_CYCLES 80 lda #1:sta &fe01 ; 8c \\ <=== HCC=104 WAIT_CYCLES 10 lda #127 ; 2c stz &fe01 ; 6c sta &fe01 ; 6c \\ <=== HCC=0 (scanline=even) WAIT_CYCLES 4 dec row_count ; 5c bne scanline_loop ; 3c } CHECK_SAME_PAGE_AS scanline_loop, TRUE .scanline_last \\ Currently at scanline 2+118*2=238, need 312 lines total. \\ Remaining scanlines = 74 = 37 rows * 2 scanlines. lda #4: sta &FE00 lda #36: sta &FE01 \\ R7 vsync at scanline 272 = 238 + 17*2 lda #7:sta &fe00 lda #17:sta &fe01 \\ Need to recover back to correct scanline count. lda #9:sta &fe00 clc lda prev_scanline adc #1 sta &fe01 \\ Wait for scanline 240. WAIT_SCANLINES_ZERO_X 2 \\ R9=1 lda #9:sta &fe00 lda #1:sta &fe01 lda #0:sta prev_scanline \\ FX responsible for resetting lower palette. ldx #LO(fx_static_image_default_palette) ldy #HI(fx_static_image_default_palette) jmp fx_static_image_set_palette } \\ Generated code for palette swaps each line. include "build/frak-lines.asm" \ ****************************************************************** \ * FX DATA \ ****************************************************************** ; TODO: Should really be 2x bytes LO & HI for dv=1.0 at zoom=0. PAGE_ALIGN_FOR_SIZE 2*FRAK_MAX_ZOOM .fx_zoom_dv_table incbin "data/raw/zoom-dv-table.bin" PAGE_ALIGN_FOR_SIZE 2*FRAK_MAX_ZOOM .fx_zoom_crtc_addresses incbin "data/raw/zoom-to-crtc-addr.bin" PAGE_ALIGN_FOR_SIZE 2*FRAK_MAX_ZOOM .fx_zoom_max_char_width incbin "data/raw/zoom-sprite-width-in-chars.bin" PAGE_ALIGN_FOR_SIZE FRAK_MAX_ZOOM .fx_zoom_scanlines incbin "data/raw/zoom-to-scanline.bin" PAGE_ALIGN_FOR_SIZE 2*FRAK_MAX_ZOOM .fx_zoom_viewport_width incbin "data/raw/zoom-viewport-width.bin" PAGE_ALIGN_FOR_SIZE 2*FRAK_MAX_ZOOM .fx_zoom_viewport_height incbin "data/raw/zoom-viewport-height.bin" .frak_data INCBIN "build/frak-sprite.bin" .frak_mod_sprite_height FOR n,0,255,1 EQUB n MOD FRAK_SPRITE_HEIGHT NEXT
; A047925: 3rd column of array in A038150. ; 8,16,29,37,50,63,71,84,92,105,118,126,139,152,160,173,181,194,207,215,228,236,249,262,270,283,296,304,317,325,338,351,359,372,385,393,406,414,427,440,448,461,469,482,495,503,516,529,537,550,558,571,584,592 mov $4,$0 add $4,1 mov $8,$0 lpb $4,1 mov $0,$8 sub $4,1 sub $0,$4 mov $7,2 mov $9,$0 lpb $7,1 sub $7,1 add $0,$7 sub $0,1 mov $2,$7 mov $10,$0 mul $10,16 mov $3,$10 mul $3,10 div $3,259 mov $6,$3 lpb $2,1 sub $2,1 mov $5,$6 lpe lpe lpb $9,1 sub $5,$6 mov $9,0 lpe mov $6,$5 mul $6,5 add $6,8 add $1,$6 lpe
BITS 64 ;TEST_FILE_META_BEGIN ;TEST_TYPE=TEST_F ;TEST_IGNOREFLAGS= ;TEST_FILE_META_END ; CMOVB16rr mov ax, 0x2 mov bx, 0x4 ;TEST_BEGIN_RECORDING cmovb ax, bx ;TEST_END_RECORDING
; ; Enterprise 64/128 clock() ; ; stefano 5/4/2007 ; ; ------ ; $Id: clock.asm,v 1.4 2016/06/12 17:02:26 dom Exp $ ; SECTION code_clib PUBLIC clock PUBLIC _clock .clock ._clock rst 30h defb 32 ; C hours 0 .. 23 (BCD) ; D minutes 0 .. 59 (BCD) ; E seconds 0 .. 59 (BCD) ; let's copy the result in dehl ; in a quick but wrong way.. ex de,hl ld d,0 ld e,c ret
#include "WebClient.h" #include "Url.h" #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/event_groups.h" #include "HttpResponseParser.h" #include "lwip/err.h" #include "lwip/sockets.h" #include "lwip/sys.h" #include "lwip/netdb.h" #include "lwip/dns.h" // TODO**************************** Port to ESP_TLS APIs #include "mbedtls/platform.h" #include "mbedtls/net.h" #include "mbedtls/ssl.h" #include "mbedtls/entropy.h" #include "mbedtls/ctr_drbg.h" #include "mbedtls/error.h" #include "mbedtls/certs.h" #define DEFAULT_MAXRESPONSEDATASIZE 16*1024 #define RECEIVE_BUFFER_SIZE 2*1024 static const char LOGTAG[] = "WebClient"; WebClient::WebClient() { muMaxResponseDataSize = DEFAULT_MAXRESPONSEDATASIZE; } WebClient::~WebClient() { } bool WebClient::Prepare(Url* pUrl) { mlRequestHeaders.clear(); if (!pUrl) return false; mpUrl = pUrl; return true; } void WebClient::Clear(){ mlRequestHeaders.clear(); mHttpResponseParser.Clear(); } bool WebClient::AddHttpHeader(String& sHeader) { mlRequestHeaders.push_back(sHeader); return true; } bool WebClient::AddHttpHeaderCStr(const char* header) { mlRequestHeaders.push_back(header); return true; } void WebClient::SetDownloadHandler(DownAndUploadHandler* pDownloadHandler) { mpDownloadHandler = pDownloadHandler; } unsigned short WebClient::HttpPost(const char* data, unsigned int size) { if (!data) return 0; mpPostData = data; muPostDataSize = size; return HttpExecute(); } unsigned short WebClient::HttpPost(String& sData) { return HttpPost(sData.c_str(), sData.length()); } void WebClient::PrepareRequest(String& sRequest) { sRequest.reserve(512); sRequest = mpPostData ? "POST " : "GET "; sRequest += mpUrl->GetPath(); if (mpUrl->GetQueryParams().size()) { sRequest += '?'; sRequest += mpUrl->GetQuery(); } sRequest += " HTTP/1.0\r\nHost: "; sRequest += mpUrl->GetHost(); sRequest += "\r\n"; for (std::list<String>::iterator it = mlRequestHeaders.begin(); it != mlRequestHeaders.end(); ++it) { sRequest += *it; //TODO *it or it???? sRequest += "\r\n"; } if (mpPostData) { ESP_LOGD(LOGTAG, "SETTING Content-Length to %u", muPostDataSize); char contentLength[64]; sprintf(contentLength, "Content-Length: %u\r\n", muPostDataSize); sRequest += contentLength; } sRequest += "User-Agent: esp32webclient/1.0 esp32\r\n\r\n"; } unsigned short WebClient::HttpGet() { mpPostData = NULL; muPostDataSize = 0; unsigned short statuscode; if (!mpUrl) return 1001; for (short redirects = 0; redirects < 5; redirects++) { statuscode = HttpExecute(); if (statuscode != 302 && statuscode != 301) { ESP_LOGD(LOGTAG, "HttpExecute* finished with %u", mHttpResponseParser.GetStatusCode()); return statuscode; } mpUrl->Parse(mHttpResponseParser.GetRedirectLocation()); ESP_LOGD(LOGTAG, "Redirecting to: %s", mHttpResponseParser.GetRedirectLocation().c_str()); } return 399; // max redirects exceeded } unsigned short WebClient::HttpExecute() { if (!mpUrl) return 1001; if (mpUrl->GetHost().length() == 0) { return 1002; } if (mpUrl->GetSecure()) { return HttpExecuteSecure(); } struct addrinfo *res; char service[6]; sprintf(service, "%i", mpUrl->GetPort()); struct addrinfo hints; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; int err = getaddrinfo(mpUrl->GetHost().c_str(), service, &hints, &res); if (err != 0 || res == NULL) { ESP_LOGE(LOGTAG, "DNS lookup failed err=%d res=%p", err, res); return 1003; } // Code to print the resolved IP. // Note: inet_ntoa is non-reentrant, look at ipaddr_ntoa_r for "real" code struct in_addr *addr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; ESP_LOGD(LOGTAG, "DNS lookup succeeded. IP=%s", inet_ntoa(*addr)); // Socket int clientSocket = socket(res->ai_family, res->ai_socktype, 0); if (clientSocket < 0) { ESP_LOGE(LOGTAG, "... Failed to allocate socket."); freeaddrinfo(res); return 1004; } ESP_LOGD(LOGTAG, "... allocated socket\r\n"); // CONNECT if (connect(clientSocket, res->ai_addr, res->ai_addrlen) != 0) { ESP_LOGE(LOGTAG, "... socket connect failed errno=%d", errno); close(clientSocket); freeaddrinfo(res); return 1005; } ESP_LOGD(LOGTAG, "... connected"); freeaddrinfo(res); // Build HTTP Request String sRequest; PrepareRequest(sRequest); // send HTTP request ESP_LOGD(LOGTAG, "sRequest: %s", sRequest.c_str()); if (write(clientSocket, sRequest.c_str(), sRequest.length()) < 0) { ESP_LOGE(LOGTAG, "... socket send failed"); close(clientSocket); return 1006; } sRequest.clear(); // free memory if (mpPostData) { if (write(clientSocket, mpPostData, muPostDataSize) < 0) { ESP_LOGE(LOGTAG, "... socket send post data failed"); close(clientSocket); return 1007; } } ESP_LOGD(LOGTAG, "... socket send success"); // Read HTTP response mHttpResponseParser.Init(mpDownloadHandler, muMaxResponseDataSize); //char recv_buf[1024]; String sReceiveBuf; sReceiveBuf.resize(RECEIVE_BUFFER_SIZE); while (!mHttpResponseParser.ResponseFinished()) { size_t sizeRead = read(clientSocket, (char*)sReceiveBuf.c_str(), sReceiveBuf.length()); if (!mHttpResponseParser.ParseResponse((char*)sReceiveBuf.c_str(), sizeRead)) { ESP_LOGE(LOGTAG, "HTTP Response error: %d", mHttpResponseParser.GetError()); close(clientSocket); return 1008; } } //ESP_LOGI(LOGTAG, "data %i bytes: %s", mHttpResponseParser.GetContentLength(), mHttpResponseParser.GetBody().c_str()); close(clientSocket); return mHttpResponseParser.GetStatusCode(); } unsigned short WebClient::HttpExecuteSecure() { String sRequest; char buf[512]; //TODO REMOVE EXTRA LARGE BUFFER AFTER TESTING String sReceiveBuf; int ret, flags, len; mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; mbedtls_ssl_context ssl; mbedtls_x509_crt cacert; mbedtls_ssl_config conf; mbedtls_net_context server_fd; bool netInitDone = false; mbedtls_ssl_init(&ssl); mbedtls_x509_crt_init(&cacert); mbedtls_ctr_drbg_init(&ctr_drbg); ESP_LOGD(LOGTAG, "Seeding the random number generator"); mbedtls_ssl_config_init(&conf); mbedtls_entropy_init(&entropy); if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, NULL, 0)) != 0) { ESP_LOGE(LOGTAG, "mbedtls_ctr_drbg_seed returned %d", ret); goto exit; } /* ESP_LOGI(LOGTAG, "Loading the CA root certificate..."); ret = mbedtls_x509_crt_parse(&cacert, server_root_cert_pem_start, server_root_cert_pem_end-server_root_cert_pem_start); if(ret < 0) { ESP_LOGE(LOGTAG, "mbedtls_x509_crt_parse returned -0x%x\n\n", -ret); abort(); } */ ESP_LOGD(LOGTAG, "Setting hostname for TLS session..."); /* Hostname set here should match CN in server certificate */ if ((ret = mbedtls_ssl_set_hostname(&ssl, mpUrl->GetPortAsString().c_str())) != 0) { ESP_LOGE(LOGTAG, "mbedtls_ssl_set_hostname returned -0x%x", -ret); goto exit; } ESP_LOGD(LOGTAG, "Setting up the SSL/TLS structure..."); if ((ret = mbedtls_ssl_config_defaults(&conf, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT)) != 0) { ESP_LOGE(LOGTAG, "mbedtls_ssl_config_defaults returned %d", ret); goto exit; } /* MBEDTLS_SSL_VERIFY_OPTIONAL is bad for security, in this example it will print a warning if CA verification fails but it will continue to connect. You should consider using MBEDTLS_SSL_VERIFY_REQUIRED in your own code. */ mbedtls_ssl_conf_authmode(&conf, MBEDTLS_SSL_VERIFY_OPTIONAL); mbedtls_ssl_conf_ca_chain(&conf, &cacert, NULL); mbedtls_ssl_conf_rng(&conf, mbedtls_ctr_drbg_random, &ctr_drbg); #ifdef CONFIG_MBEDTLS_DEBUG //mbedtls_esp_enable_debug_log(&conf, 4); #endif if ((ret = mbedtls_ssl_setup(&ssl, &conf)) != 0) { ESP_LOGE(LOGTAG, "mbedtls_ssl_setup returned -0x%x\n\n", -ret); goto exit; } // the following onwards needs working WIFI and IP address mbedtls_net_init(&server_fd); netInitDone = true; ESP_LOGD(LOGTAG, "Connecting to %s:%hu...", mpUrl->GetHost().c_str(), mpUrl->GetPort()); ESP_LOGD(LOGTAG, "Port as string '%s'", mpUrl->GetPortAsString().c_str()); if ((ret = mbedtls_net_connect(&server_fd, mpUrl->GetHost().c_str(), mpUrl->GetPortAsString().c_str(), MBEDTLS_NET_PROTO_TCP)) != 0) { ESP_LOGE(LOGTAG, "mbedtls_net_connect returned -%x", -ret); goto exit; } ESP_LOGD(LOGTAG, "Connected."); mbedtls_ssl_set_bio(&ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL); ESP_LOGD(LOGTAG, "Performing the SSL/TLS handshake..."); while ((ret = mbedtls_ssl_handshake(&ssl)) != 0) { if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { ESP_LOGE(LOGTAG, "mbedtls_ssl_handshake returned -0x%x", -ret); goto exit; } } ESP_LOGD(LOGTAG, "Verifying peer X.509 certificate..."); if ((flags = mbedtls_ssl_get_verify_result(&ssl)) != 0) { /* In real life, we probably want to close connection if ret != 0 */ ESP_LOGW(LOGTAG, "Failed to verify peer certificate!"); bzero(buf, sizeof(buf)); mbedtls_x509_crt_verify_info(buf, sizeof(buf), " ! ", flags); ESP_LOGW(LOGTAG, "verification info: %s", buf); } else { ESP_LOGD(LOGTAG, "Certificate verified."); } // Build HTTP Request PrepareRequest(sRequest); ESP_LOGD(LOGTAG, "Writing HTTP request... <%s>", sRequest.c_str()); while ((ret = mbedtls_ssl_write(&ssl, (const unsigned char*)sRequest.c_str(), sRequest.length())) <= 0) { if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { ESP_LOGE(LOGTAG, "mbedtls_ssl_write returned -0x%x", -ret); goto exit; } } if (mpPostData) { while ((ret = mbedtls_ssl_write(&ssl, (const unsigned char*)mpPostData, muPostDataSize)) <= 0) { if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { ESP_LOGE(LOGTAG, "mbedtls_ssl_write returned -0x%x during POST", -ret); goto exit; } } } //ESP_LOGI(LOGTAG, "%d bytes written", ret); ESP_LOGD(LOGTAG, "Reading HTTP response..."); sRequest.clear(); // free memory //ESP_LOGI(LOGTAG, "... socket send success"); // Read HTTP response mHttpResponseParser.Init(mpDownloadHandler, muMaxResponseDataSize); if (!sReceiveBuf.resize(RECEIVE_BUFFER_SIZE)) ESP_LOGE(LOGTAG, "memory allocation failed (%d)", RECEIVE_BUFFER_SIZE); //ESP_LOGI(LOGTAG, "sReceiveBuf.length(%d)", sReceiveBuf.length()); while (!mHttpResponseParser.ResponseFinished()) { //ESP_LOGI(LOGTAG, "before ssl_read"); //ESP_LOGI(LOGTAG, "sReceiveBuf.length(%d), pointer=%p", sReceiveBuf.length(), sReceiveBuf.c_str()); ret = mbedtls_ssl_read(&ssl, (unsigned char*)sReceiveBuf.c_str(), sReceiveBuf.length()); //ESP_LOGI(LOGTAG, "after ssl_read ret=%d", ret); if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) continue; if (ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) { ret = 0; break; } if (ret < 0) { //ESP_LOGE(LOGTAG, "Connection closed during parsing"); ESP_LOGE(LOGTAG, "mbedtls_ssl_read returned -0x%x", -ret); break; } len = ret; //ESP_LOGI(LOGTAG, "invoking responseparse(buflen=%d)", len); if (!mHttpResponseParser.ParseResponse((char*)sReceiveBuf.c_str(), len)) { ESP_LOGE(LOGTAG, "HTTP Error Code: %d", mHttpResponseParser.GetError()); goto exit; } //ESP_LOGI(LOGTAG, "responseparser actual length %d", mHttpResponseParser.GetContentLength()); } mbedtls_ssl_close_notify(&ssl); exit: mbedtls_ssl_session_reset(&ssl); if (netInitDone) mbedtls_net_free(&server_fd); mbedtls_x509_crt_free(&cacert); mbedtls_ssl_free(&ssl); mbedtls_ssl_config_free(&conf); mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_entropy_free(&entropy); if (!mHttpResponseParser.ResponseFinished() && ret != 0) { mbedtls_strerror(ret, buf, 100); ESP_LOGE(LOGTAG, "Last MBEDTLS error was: -0x%x - %s", -ret, buf); return 1010; } return mHttpResponseParser.GetStatusCode(); }
; A049610: a(n) = Sum_{k=0..floor(n/2)} k*binomial(n,2*k) = floor(n*2^(n-3)). ; 0,0,1,3,8,20,48,112,256,576,1280,2816,6144,13312,28672,61440,131072,278528,589824,1245184,2621440,5505024,11534336,24117248,50331648,104857600,218103808,452984832,939524096,1946157056,4026531840,8321499136,17179869184,35433480192,73014444032,150323855360,309237645312,635655159808,1305670057984,2680059592704,5497558138880,11269994184704,23089744183296,47278999994368,96757023244288,197912092999680,404620279021568,826832744087552,1688849860263936,3448068464705536,7036874417766400 mov $1,2 pow $1,$0 mul $1,$0 div $1,8
/* Copyright (c) 2006-2018, Universities Space Research Association (USRA). * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Universities Space Research Association 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 USRA ``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 USRA 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 "AdapterExecInterface.hh" #include "Debug.hh" #include "Expression.hh" #include "State.hh" #include "Value.hh" #include <cstring> #include <iomanip> #include <sstream> namespace PLEXIL { /** * @brief Default constructor method. */ AdapterExecInterface::AdapterExecInterface() { } /** * @brief Destructor method. */ AdapterExecInterface::~AdapterExecInterface() { } // // Static utility functions // std::string AdapterExecInterface::getText(const State& c) { std::ostringstream retval; retval << c.name() << "("; std::vector<Value>::const_iterator it = c.parameters().begin(); if(it != c.parameters().end()) { retval << *it; for (++it; it != c.parameters().end(); ++it) retval << ", " << *it; } retval << ")"; return retval.str(); } }
#pragma once /** @file @brief wrap openssl Copyright (C) 2012 Cybozu Labs, Inc., all rights reserved. */ #include <cybozu/exception.hpp> #ifdef __APPLE__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif #if 0 //#ifdef __APPLE__ #define COMMON_DIGEST_FOR_OPENSSL #include <CommonCrypto/CommonDigest.h> #include <CommonCrypto/CommonHMAC.h> #define SHA1 CC_SHA1 #define SHA224 CC_SHA224 #define SHA256 CC_SHA256 #define SHA384 CC_SHA384 #define SHA512 CC_SHA512 #else #include <openssl/hmac.h> #include <openssl/evp.h> #include <openssl/sha.h> #endif #ifdef _MSC_VER #include <cybozu/link_libeay32.hpp> #endif namespace cybozu { namespace crypto { class Hash { public: enum Name { N_SHA1, N_SHA224, N_SHA256, N_SHA384, N_SHA512 }; private: Name name_; size_t hashSize_; union { SHA_CTX sha1; SHA256_CTX sha256; SHA512_CTX sha512; } ctx_; public: static inline size_t getSize(Name name) { switch (name) { case N_SHA1: return SHA_DIGEST_LENGTH; case N_SHA224: return SHA224_DIGEST_LENGTH; case N_SHA256: return SHA256_DIGEST_LENGTH; case N_SHA384: return SHA384_DIGEST_LENGTH; case N_SHA512: return SHA512_DIGEST_LENGTH; default: throw cybozu::Exception("crypto:Hash:getSize") << name; } } static inline const char *getName(Name name) { switch (name) { case N_SHA1: return "sha1"; case N_SHA224: return "sha224"; case N_SHA256: return "sha256"; case N_SHA384: return "sha384"; case N_SHA512: return "sha512"; default: throw cybozu::Exception("crypto:Hash:getName") << name; } } static inline Name getName(const std::string& nameStr) { static const struct { const char *nameStr; Name name; } tbl[] = { { "sha1", N_SHA1 }, { "sha224", N_SHA224 }, { "sha256", N_SHA256 }, { "sha384", N_SHA384 }, { "sha512", N_SHA512 }, }; for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { if (nameStr == tbl[i].nameStr) return tbl[i].name; } throw cybozu::Exception("crypto:Hash:getName") << nameStr; } explicit Hash(Name name = N_SHA1) : name_(name) , hashSize_(getSize(name)) { reset(); } void update(const char *buf, size_t bufSize) { switch (name_) { case N_SHA1: SHA1_Update(&ctx_.sha1, buf, bufSize); break; case N_SHA224: SHA224_Update(&ctx_.sha256, buf, bufSize); break; case N_SHA256: SHA256_Update(&ctx_.sha256, buf, bufSize); break; case N_SHA384: SHA384_Update(&ctx_.sha512, buf, bufSize); break; case N_SHA512: SHA512_Update(&ctx_.sha512, buf, bufSize); break; } } void update(const std::string& buf) { update(buf.c_str(), buf.size()); } void reset() { switch (name_) { case N_SHA1: SHA1_Init(&ctx_.sha1); break; case N_SHA224: SHA224_Init(&ctx_.sha256); break; case N_SHA256: SHA256_Init(&ctx_.sha256); break; case N_SHA384: SHA384_Init(&ctx_.sha512); break; case N_SHA512: SHA512_Init(&ctx_.sha512); break; default: throw cybozu::Exception("crypto:Hash:rset") << name_; } } /* md must have hashSize byte @note clear inner buffer after calling digest */ void digest(char *out, const char *buf, size_t bufSize) { update(buf, bufSize); unsigned char *md = reinterpret_cast<unsigned char*>(out); switch (name_) { case N_SHA1: SHA1_Final(md, &ctx_.sha1); break; case N_SHA224: SHA224_Final(md, &ctx_.sha256); break; case N_SHA256: SHA256_Final(md, &ctx_.sha256); break; case N_SHA384: SHA384_Final(md, &ctx_.sha512); break; case N_SHA512: SHA512_Final(md, &ctx_.sha512); break; default: throw cybozu::Exception("crypto:Hash:digest") << name_; } reset(); } std::string digest(const char *buf, size_t bufSize) { std::string ret; ret.resize(hashSize_); digest(&ret[0], buf, bufSize); return ret; } std::string digest(const std::string& buf = "") { return digest(buf.c_str(), buf.size()); } static inline std::string digest(Name name, const char *buf, size_t bufSize) { unsigned char md[128]; const unsigned char *src = cybozu::cast<const unsigned char *>(buf); switch (name) { case N_SHA1: SHA1(src, bufSize, md); break; case N_SHA224: SHA224(src, bufSize, md); break; case N_SHA256: SHA256(src, bufSize, md); break; case N_SHA384: SHA384(src, bufSize, md); break; case N_SHA512: SHA512(src, bufSize, md); break; default: throw cybozu::Exception("crypt:Hash:digest") << name; } return std::string(cybozu::cast<const char*>(md), getSize(name)); } static inline std::string digest(Name name, const std::string& buf) { return digest(name, buf.c_str(), buf.size()); } }; class Hmac { const EVP_MD *evp_; public: explicit Hmac(Hash::Name name = Hash::N_SHA1) { switch (name) { case Hash::N_SHA1: evp_ = EVP_sha1(); break; case Hash::N_SHA224: evp_ = EVP_sha224(); break; case Hash::N_SHA256: evp_ = EVP_sha256(); break; case Hash::N_SHA384: evp_ = EVP_sha384(); break; case Hash::N_SHA512: evp_ = EVP_sha512(); break; default: throw cybozu::Exception("crypto:Hmac:") << name; } } std::string eval(const std::string& key, const std::string& data) { std::string out(EVP_MD_size(evp_) + 1, 0); unsigned int outLen = 0; if (HMAC(evp_, key.c_str(), static_cast<int>(key.size()), cybozu::cast<const uint8_t *>(data.c_str()), data.size(), cybozu::cast<uint8_t *>(&out[0]), &outLen)) { out.resize(outLen); return out; } throw cybozu::Exception("crypto::Hamc::eval"); } }; class Cipher { const EVP_CIPHER *cipher_; EVP_CIPHER_CTX *ctx_; public: enum Name { N_AES128_CBC, N_AES192_CBC, N_AES256_CBC, N_AES128_ECB, // be carefull to use N_AES192_ECB, // be carefull to use N_AES256_ECB, // be carefull to use }; static inline size_t getSize(Name name) { switch (name) { case N_AES128_CBC: return 128; case N_AES192_CBC: return 192; case N_AES256_CBC: return 256; case N_AES128_ECB: return 128; case N_AES192_ECB: return 192; case N_AES256_ECB: return 256; default: throw cybozu::Exception("crypto:Cipher:getSize") << name; } } enum Mode { Decoding, Encoding }; explicit Cipher(Name name = N_AES128_CBC) : cipher_(0) , ctx_(0) { ctx_ = EVP_CIPHER_CTX_new(); if (ctx_ == 0) throw cybozu::Exception("crypto:Cipher:EVP_CIPHER_CTX_new"); switch (name) { case N_AES128_CBC: cipher_ = EVP_aes_128_cbc(); break; case N_AES192_CBC: cipher_ = EVP_aes_192_cbc(); break; case N_AES256_CBC: cipher_ = EVP_aes_256_cbc(); break; case N_AES128_ECB: cipher_ = EVP_aes_128_ecb(); break; case N_AES192_ECB: cipher_ = EVP_aes_192_ecb(); break; case N_AES256_ECB: cipher_ = EVP_aes_256_ecb(); break; default: throw cybozu::Exception("crypto:Cipher:Cipher:name") << (int)name; } } ~Cipher() { if (ctx_) EVP_CIPHER_CTX_free(ctx_); } /* @note don't use padding = true */ void setup(Mode mode, const std::string& key, const std::string& iv, bool padding = false) { const int keyLen = static_cast<int>(key.size()); const int expectedKeyLen = EVP_CIPHER_key_length(cipher_); if (keyLen != expectedKeyLen) { throw cybozu::Exception("crypto:Cipher:setup:keyLen") << keyLen << expectedKeyLen; } int ret = EVP_CipherInit_ex(ctx_, cipher_, NULL, cybozu::cast<const uint8_t*>(key.c_str()), cybozu::cast<const uint8_t*>(iv.c_str()), mode == Encoding ? 1 : 0); if (ret != 1) { throw cybozu::Exception("crypto:Cipher:setup:EVP_CipherInit_ex") << ret; } ret = EVP_CIPHER_CTX_set_padding(ctx_, padding ? 1 : 0); if (ret != 1) { throw cybozu::Exception("crypto:Cipher:setup:EVP_CIPHER_CTX_set_padding") << ret; } /* const int ivLen = static_cast<int>(iv.size()); const int expectedIvLen = EVP_CIPHER_CTX_iv_length(&ctx_); if (ivLen != expectedIvLen) { throw cybozu::Exception("crypto:Cipher:setup:ivLen") << ivLen << expectedIvLen; } */ } /* the size of outBuf must be larger than inBufSize + blockSize @retval positive or 0 : writeSize(+blockSize) @retval -1 : error */ int update(char *outBuf, const char *inBuf, int inBufSize) { int outLen = 0; int ret = EVP_CipherUpdate(ctx_, cybozu::cast<uint8_t*>(outBuf), &outLen, cybozu::cast<const uint8_t*>(inBuf), inBufSize); if (ret != 1) return -1; return outLen; } /* return -1 if padding @note don't use */ int finalize(char *outBuf) { int outLen = 0; int ret = EVP_CipherFinal_ex(ctx_, cybozu::cast<uint8_t*>(outBuf), &outLen); if (ret != 1) return -1; return outLen; } }; } } // cybozu::crypto #ifdef __APPLE__ #pragma GCC diagnostic pop #endif
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1992 -- All Rights Reserved PROJECT: GeoDex MODULE: Misc FILE: miscLettersDraw.asm AUTHOR: Ted H. Kim, March 9, 1992 ROUTINES: Name Description ---- ----------- LettersCompDraw Draw method for composite gadget LettersColorDraw Draws bitmaps for GeoDex in color display LettersBWDraw Draws bitmaps for GeoDex in B&W display LettersCGADraw Draws bitmaps for GeoDex in CGA display LettersDraw Draw method for letter class gadget DrawRecycleTab Draw the recycle tab DrawLetterTabs Draws new letters onto letter tabs bitmap DrawLetters Routine called by both DrawLetterTabs DrawMultChar Draw letter tabs w/ multiple characters REVISION HISTORY: Name Date Description ---- ---- ----------- ted 3/92 Initial revision DESCRIPTION: Contains message handlers for MSG_VIS_DRAW. $Id: miscLettersDraw.asm,v 1.1 97/04/04 15:50:41 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ LettersCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LettersCompDraw %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draw routine for composite gadget. CALLED BY: UI (= MSG_VIS_DRAW) PASS: ds:si - instance data bp - gState handle cx - draw flags RETURN: nothing DESTROYED: ax, bx, cx, dx, di PSEUDO CODE/STRATEGY: Set the attributes Get the bounds of gadget Draw the framed rectangle Draw its children KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 10/3/89 Initial version Ted 2/6/90 Uses bitmaps %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ LettersCompDraw method LettersCompClass, MSG_VIS_DRAW push cx, bp mov di, bp ; di - gstate handle ; check to see if we are running under color mode cmp es:[colorFlag], FALSE ; B&W? je bw ; jump if B&W call LettersColorDraw ; draw color bitmaps jmp exit bw: call LettersBWDraw ; draw B&W bitmaps exit: pop cx, bp ; call its super class mov ax, MSG_VIS_DRAW mov di, offset LettersCompClass call ObjCallSuperNoLock ret LettersCompDraw endm LettersCode ends ColorCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LettersColorDraw %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draws all the bitmaps for color GeoDex except the letter tabs. CALLED BY: LettersColorDraw PASS: *ds:si - instance data of LettersCompClass RETURN: nothing DESTROYED: ax, bx, cx, dx, bp PSEUDO CODE/STRATEGY: Draw the rectangle for record entry area Fill this area with white color Draw the bitmap to the right of record entry area that shows the thickness of record entries Draw the bottom part of the bitmap Change the background color of phone related icons to light grey KNOWN BUGS/SIDE EFFECTS/IDEAS: This routine is too big. REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 10/16/90 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ LettersColorDraw proc far class LettersCompClass push ds, si ; *ds:si - ptr to instance data call VisGetBounds ; get the bounds of gadget ; first draw the background for the card entry area. push bx ; save top boundary push ax ; save left boundary mov al, SDM_100 ; SOLID pattern call GrSetLineMask ; set the line pattern to solid mov ax, (CF_INDEX shl 8) or C_BLACK call GrSetLineColor ; set the line color to black pop ax ; restore left position push ax ; save left boundary inc ax ; ax - adjust left position ifdef GPC ; ; if no bottom/side, no adjust ; push si mov si, ds:[si] add si, ds:[si].LettersComp_offset tst ds:[si].LCC_colBottom jz checkAdjust tst ds:[si].LCC_colMidsect checkAdjust: pop si jz noAdjust endif add bx, COLOR_TOP_POS_ADJUST_BACKGRND_RECT ; bx - adjust top pos sub cx, COLOR_RIGHT_POS_ADJUST_BACKGRND_RECT ; cx - adjust right pos noAdjust:: ifndef GPC ; GPC - draw at bottom mov dx, bx add dx, COLOR_BOTTOM_POS_ADJUST_BACKGRND_RECT ; dx - adjust bottom endif call GrDrawRect ; draw background rectangle push ax ; save left position mov al, SDM_100 ; SOLID pattern call GrSetAreaMask ; set the area attributes mov ax, (CF_INDEX shl 8) or C_WHITE call GrSetAreaColor ; set the color to white pop ax ; restore left position inc ax ; ax - left ;dec cx ; cx - right ifdef GPC push bx inc bx ; don't clobber top of outline call GrFillRect ; fill the rectangle w/ white pop bx else call GrFillRect ; fill the rectangle w/ white endif ; draw the right side of card view that shows the thickness of ; record entries ifdef GPC pop si, si ; dump top left pop ds, si ; *ds:si = object push si mov si, ds:[si] add si, ds:[si].LettersComp_offset tst ds:[si].LCC_colMidsect jz noSideBot tst ds:[si].LCC_colBottom jz noSideBot push cx, dx ; save lower right add cx, 4 mov ax, cx sub dx, 5 call GrDrawLine add cx, 4 mov ax, cx sub dx, 5 call GrDrawLine add cx, 4 mov ax, cx sub dx, 5 call GrDrawLine pop ax, bx ; restore lower right call GrDrawLine noSideBot: pop si else ; GPC mov si, ds:[si] add si, ds:[si].LettersComp_offset ; si - offset to instance data mov bx, ds:[si].LCC_colMidsect ; bx - handle of bitmap mov si, offset ColorMidsectResource: StartmidsecIcon ; si - offset pop ax ; ax - left pos. of bitmap inc ax ; adjust it for color version push ax ; save it call MemLock ; load in the bitmap mov bp, bx ; bp - resource handle mov ds, ax ; ds - seg addr of bitmap pop ax ; restore left position pop bx ; restore top position add ax, COLOR_LEFT_POS_ADJUST_MIDDLE_BITMAP ; adjust left position add bx, COLOR_TOP_POS_ADJUST_MIDDLE_BITMAP ; adjust top position clr dx ; no call back routine call GrDrawBitmap ; draw the middle section pop ds, si ; ds:si - ptr to instance data push ds, si call VisGetBounds ; get the bounds of gadget push bx ; save top position push ax ; save left position mov bx, bp ; bx - resource handle call MemUnlock ; unlock the bitmap resource ; now draw the bottom part of card view mov si, ds:[si] add si, ds:[si].LettersComp_offset ; si - offset to instance data mov bx, ds:[si].LCC_colBottom ; bx - handle of color bitmap mov si, offset ColorBottomResource: StartbottomIcon ; si - offset call MemLock ; load in the bitmap mov bp, bx ; bp - resource handle mov ds, ax ; ds - seg addr of bitmap pop ax ; restore left position pop bx ; restore top position inc ax ; adjust left position add bx, COLOR_TOP_POS_ADJUST_BOTTOM_BITMAP ; adjust top position clr dx ; no call back routine call GrDrawBitmap ; draw the bitmap mov bx, bp ; bx - resource handle call MemUnlock ; unlock the bitmap resource pop ds, si ; ds:si - ptr to instance data endif ; GPC ifndef GPC ; the buttons draw their own backgrounds push ds, si ; for color version, change the background color of phone icon ; and phone number scroll up & down icons to light grey mov ax, (CF_INDEX shl 8) or C_LIGHT_GREY call GrSetAreaColor ; set the color to light grey mov si, offset ScrollUpTrigger ; ds:si - instance data of obj mov ax, MSG_VIS_GET_BOUNDS ; ax - method number call ObjCallInstanceNoLock ; get bounds of up arrow button mov bx, bp ; bx - left position call GrFillRect ; fill this area with lt. grey mov si, offset ScrollDownTrigger ; ds:si - instance data of obj mov ax, MSG_VIS_GET_BOUNDS ; ax - method number call ObjCallInstanceNoLock ; get bounds of down button mov bx, bp ; bx - left position call GrFillRect ; fill this area with lt. grey if _PHONE_ICON mov si, offset AutoDialTrigger ; ds:si - instance data of obj mov ax, MSG_VIS_GET_BOUNDS ; ax - method number call ObjCallInstanceNoLock ; get bounds of phone button mov bx, bp ; bx - left position call GrFillRect ; fill this area with lt. grey endif pop ds, si ; ds:si - ptr to instance data endif ; GPC ret LettersColorDraw endp ColorCode ends LettersCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LettersBWDraw %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draws all the bitmaps for B&W GeoDex except the letter tabs. CALLED BY: LettersCompDraw PASS: cga - flag that tells you which video card is being used *ds:si - instance data of LettersCompDraw RETURN: nothing DESTROYED: ax, bx, cx, dx, bp PSEUDO CODE/STRATEGY: Draw a vertical line on the left edge of data entry area Draw the bitmap to the right of record entry area that shows the thickness of record entries Draw the bottom part of the bitmap KNOWN BUGS/SIDE EFFECTS/IDEAS: This routine is too big. REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 10/16/90 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ LettersBWDraw proc near class LettersCompClass if not PZ_PCGEOS tst es:[cga] ; running under CGA card? LONG js doCGA ; if so, skip to handle it endif push ds, si ; *ds:si - instance data call VisGetBounds ; get the bounds of gadget push bx ; save top boundary push ax ; save left boundary mov al, SDM_100 ; SOLID pattern call GrSetLineMask ; set the line pattern mov ax, (CF_INDEX shl 8) or C_BLACK call GrSetLineColor ; set the line color to black pop ax ; restore left position push ax ; save left boundary inc ax ; ax - left add bx, BW_TOP_POS_ADJUST_BACKGRND_RECT ; bx - adjust top mov cx, ax ; cx - right mov dx, bx add dx, BW_BOTTOM_POS_ADJUST_BACKGRND_RECT ; dx - adjust bottom call GrDrawLine ; draw a line ; draw the bitmap that shows the thickness of rolodex cards mov ax, C_BLACK or (CF_INDEX shl 8) call GrSetAreaColor mov si, ds:[si] add si, ds:[si].LettersComp_offset ; si - offset to instance data mov bx, ds:[si].LCC_bwMidsect ; bx - handle of bitmap data mov si, offset BWMidsectResource: StartbwmidsecIcon ; si - offset call MemLock ; load in the bitmap mov bp, bx ; bp - resource handle mov ds, ax ; ds - seg addr of bitmap pop ax ; restore left position pop bx ; restore top position add ax, BW_LEFT_POS_ADJUST_MIDDLE_BITMAP ; adjust left position add bx, BW_TOP_POS_ADJUST_MIDDLE_BITMAP ; adjust top position clr dx ; no call back routine call GrFillBitmap ; draw the mid section pop ds, si ; ds:si - ptr to instance data push ds, si call VisGetBounds ; get the bounds of gadget push bx ; save top position push ax ; save left position mov bx, bp ; bx - resource handle call MemUnlock ; unlock the bitmap resource ; draw the bitmap that shows the punched holes at the bottom of a card mov si, ds:[si] add si, ds:[si].LettersComp_offset ; si - offset to instance data mov bx, ds:[si].LCC_bwBottom ; bx - handle of B&W bitmap mov si, offset BWBottomResource: StartbwbottomIcon ; si - offset call MemLock ; load in the bitmap mov bp, bx ; bp - resource handle mov ds, ax ; ds - seg addr of bitmap pop ax ; restore left position pop bx ; restore top position inc ax ; adjust left position add bx, BW_TOP_POS_ADJUST_BOTTOM_BITMAP ; adjust top position clr dx ; no call back routine call GrFillBitmap ; draw the bitmap mov bx, bp ; bx - resource handle call MemUnlock ; unlock the bitmap resource pop ds, si ; ds:si - ptr to instance data ret if not PZ_PCGEOS doCGA: call LettersCGADraw ; draw diff'rnt bitmap for CGA ret endif LettersBWDraw endp LettersCode ends if not PZ_PCGEOS CGACode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LettersCGADraw %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draws all of the bitmaps for CGA GeoDex except letter tabs. CALLED BY: LettersBWDraw PASS: *ds:si - instance data of LettersCompDraw RETURN: nothing DESTROYED: ax, bx, cx, dx, bp PSEUDO CODE/STRATEGY: Draw a vertical line on the left edge of data entry area Draw the bitmap to the right of record entry area that shows the thickness of record entries Draw the bottom part of the bitmap KNOWN BUGS/SIDE EFFECTS/IDEAS: This routine is too big. REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 10/16/90 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ LettersCGADraw proc far class LettersCompClass push ds, si ; *ds:si - instance data call VisGetBounds ; get the bounds of gadget push bx ; save top boundary push ax ; save left boundary mov al, SDM_100 ; SOLID pattern call GrSetLineMask ; set the line pattern mov ax, (CF_INDEX shl 8) or C_BLACK call GrSetLineColor ; set the line color to black pop ax ; restore left position push ax ; save left boundary inc ax ; ax - left add bx, CGA_TOP_POS_ADJUST_BACKGRND_RECT ; bx - adjust top mov cx, ax ; cx - right mov dx, bx add dx, CGA_BOTTOM_POS_ADJUST_BACKGRND_RECT ; dx - adjust bottom call GrDrawLine ; vertical line on left edge ; draw the bitmap that shows the thickness of the GeoDex cards mov si, ds:[si] add si, ds:[si].LettersComp_offset ; si - offset to instance data mov bx, ds:[si].LCC_cgaMidsect ; bx - handle of bitmap data mov si, offset CGABWMidsectResource: StartcgabwmidsecIcon call MemLock ; load in the bitmap mov bp, bx ; bp - resource handle mov ds, ax ; ds - seg addr of bitmap pop ax ; restore left position pop bx ; restore top position add ax, CGA_LEFT_POS_ADJUST_MIDDLE_BITMAP ; adjust left position add bx, CGA_TOP_POS_ADJUST_MIDDLE_BITMAP ; adjust top position clr dx ; no call back routine call GrFillBitmap ; draw the mid section pop ds, si ; ds:si - ptr to instance data push ds, si call VisGetBounds ; get the bounds of gadget push bx ; save top position push ax ; save left position mov bx, bp ; bx - resource handle call MemUnlock ; unlock the bitmap resource ; draw the bitmap that shows the punched holes at the bottom of a card mov si, ds:[si] add si, ds:[si].LettersComp_offset ; si - offset to instance data mov bx, ds:[si].LCC_bwBottom ; bx - handle of B&W bitmap mov si, offset BWBottomResource: StartbwbottomIcon ; si - offset call MemLock ; load in the bitmap mov bp, bx ; bp - resource handle mov ds, ax ; ds - seg addr of bitmap pop ax ; restore left position pop bx ; restore top position inc ax ; adjust left position add bx, CGA_TOP_POS_ADJUST_BOTTOM_BITMAP ; adjust top position clr dx ; no call back routine call GrFillBitmap ; draw the bitmap mov bx, bp ; bx - resource handle call MemUnlock ; unlock the bitmap resource pop ds, si ; ds:si - ptr to instance data ret LettersCGADraw endp CGACode ends endif LettersCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LettersDraw %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draw routine for letters class. CALLED BY: UI (= MSG_VIS_DRAW) PASS: ds:si - instance data es - segment of LettersClass ax - The method cx - DrawFlag (with DF_EXPOSED) bp - gstate to use RETURN: nothing DESTROYED: ax, bx, cx, dx, bp, si, di, ds, es PSEUDO CODE/STRATEGY: Draw the bounding boxes for letter buttons Display characters for letter buttons KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 10/3/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ LettersDraw method LettersClass, MSG_VIS_DRAW call VisGetBounds ; get bounds of letter boxes mov di, bp ; di - handle graphics state push ds, si ; ds:si - instance data push ax ; save left boundary push bx ; save top boundary tst es:[colorFlag] ; is color flag set? js colorBitmap ; if so, skip ; draw the black and white letter tab bitmap mov si, ds:[si] add si, ds:[si].Letters_offset ; access the instance data mov bx, ds:[si].LI_bwLetters ; bx - handle of bitmap resource mov si, offset BWLettersResource: StartstarbwIcon ; si - offset jmp short draw ; skip to draw it colorBitmap: ; draw the color bitmap for letter tabs mov si, ds:[si] add si, ds:[si].Letters_offset ; access the instance data mov bx, ds:[si].LI_colLetters ; bx - handle of color bitmap mov si, offset ColorLettersResource: StartstarcolIcon ; si - offset draw: call MemLock ; load in the bitmap resource mov bp, bx ; save resource handle mov ds, ax ; ds - seg address of bitmap resource pop bx ; restore top boundary pop ax ; restore left boundary inc ax ; adjust left boundary clr dx ; no call back routine call GrDrawBitmap ; draw the damn thing mov bx, bp ; bx - resource handle call MemUnlock ; unlock the resource block pop ds, si ; ds:si - instance data ; write the letters into the letter tabs push si mov cx, 1 ; gstate handle is passed mov dl, es:[curCharSet] ; dl - current character set index mov dh, C_RED ; dl - ColorIndex call DrawLetterTabs ; draw letters into tabs mov si, ds:[si] add si, ds:[si].Letters_offset ; access instance data test ds:[si].LI_flag, mask LIF_INVERTED ; is there an inverted char? mov dx, ds:[si].LI_letter ; dx - letter tab ID pop si je exit ; if not, exit ; invert the letter tab mov cx, es:[gmb.GMB_numMainTab] push es mov bp, di ; bp - gState handle call LettersButtonInvert pop es exit: cmp es:[numCharSet], 1 ; one set of characters? je done ; if so, exit call DrawRecycleTab ; otherwise, draw recycle tab done: ret LettersDraw endm if 0 COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CheckBounds %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Check the VisBounds of this object to see if it is being exposed. CALLED BY: (INTERNAL) LettersDraw PASS: ax - left bx - top cx - right dx - bottom RETURN: carry set if not exposed carry clear if it is being exposed DESTROYED: nothing SIDE EFFECTS: none PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- THK 11/19/92 Initial revision %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CheckBounds proc near uses ax, bx, cx, dx left local word top local word right local word bottom local word .enter ; set up the local stack frame mov left, ax mov top, bx mov right, cx mov bottom, dx ; now get the bounds of clipped region call GrGetMaskBounds cmp ax, right ; too far right? jg notExposed ; if so, not exposed cmp bx, bottom ; too far above? jg notExposed ; if so, not exposed cmp cx, left ; too far left? jl notExposed ; if so, not exposed cmp dx, top ; too far below? jl notExposed ; if so, not exposed clc ; exposed flag set jmp exit notExposed: stc ; not exposed flag set exit: .leave ret CheckBounds endp endif COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawRecycleTab %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draws the recycle tab CALLED BY: (INTERNAL) LettersDraw PASS: es - seg addr of core block ds:si - instance data RETURN: nothing DESTROYED: ax, bx, si, bp SIDE EFFECTS: none PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- THK 10/92 Initial revision %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawRecycleTab proc near class LettersClass left local word top local word right local word bottom local word memHandle local hptr .enter ; check to see if color mode call VisGetBounds ; get the bounds of gadget mov left, ax ; save the bounds mov top, bx mov right, cx mov bottom, dx tst es:[colorFlag] js colorBitmap ; if so, skip ; locate bitmap for B&W arrow mov si, ds:[si] add si, ds:[si].Letters_offset mov bx, ds:[si].LI_bwLetters ; bx - handle of BW bitmap block mov si, offset BWLettersResource: StartBWArrow jmp common colorBitmap: ; locate bitmap for color arrow mov si, ds:[si] add si, ds:[si].Letters_offset mov bx, ds:[si].LI_colLetters ; bx - handle of color bitmap block mov si, offset ColorLettersResource: StartColorArrow common: call MemLock ; lock the bitmap resource block mov memHandle, bx mov ds, ax ; ds:si - bitmap mov ax, left add ax, LEFT_POS_RECYCLE_TAB ; ax - x position mov bx, top add bx, TOP_POS_RECYCLE_TAB ; bx - y position call GrDrawBitmap mov bx, memHandle call MemUnlock ; unlock the resource block .leave ret DrawRecycleTab endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawLetterTabs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draw new set of characters onto the letter tab bitmap. CALLED BY: UI(=MSG_DRAW_LETTER_TABS), LettersButtonCalc PASS: dl - curCharSet dh - ColorIndex cx - flag for GState if cx = 0, create a new GState if cx = 1, di is the handle of GState di - handle of GState if cx is not zero es - dgroup RETURN: nothing DESTROYED: nothing KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- ted 7/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawLetterTabs method LettersClass, MSG_DRAW_LETTER_TABS uses ax, bx, cx, dx, ds, es, si, di, bp gState local hptr ; gstate handle colorIndex local word ; current ColorIndex .enter mov ax, es:[numCharSet] ; ax - number of char set cmp dl, al ; is this char set exant? jl ok ; if so, skip clr dl ; if not, draw the 1st set ok: mov es:[curCharSet], dl ; update curCharSet push cx ; save gstate flag tst cx ; gstate handle passed? jne skip ; if so, skip ; if not, we need to create a new gstate push bp, dx mov ax, MSG_VIS_VUP_CREATE_GSTATE call ObjCallInstanceNoLock ; create gState mov di, bp ; di - gState handle pop bp, dx skip: ; change the text color mov gState, di ; save gState handle call GrGetTextColor ; get current color index mov colorIndex, ax ; save it mov ah, CF_INDEX mov al, dh ; al - ColorIndex call GrSetTextColor ; change text color to red call DrawLetters ; draw new set of characters mov di, gState ; di - handle of gState mov ax, colorIndex mov ah, CF_INDEX call GrSetTextColor ; restore the text color pop cx ; save gstate flag tst cx ; did we create a new gstate? jne exit ; if not, exit call GrDestroyState ; if so, destroy it exit: .leave ret DrawLetterTabs endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawLetters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draw all the characters in the given character set. CALLED BY: DrawLetterTabs, ClearLetterTabs PASS: di - gstate handle dl - curCharSet es - dgroup RETURN: nothing DESTROYED: ax, bx, cx, dx, ds, si KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- ted 7/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawLetters proc near xColumnOne local word ; left boundary of letter tabs xPosition local word ; x position for GrDrawChar yPosition local word ; y position for GrDrawChar gState local hptr ; gstate handle charSet local byte ; current character set index leftSpace local word ; space b/w left edge and char .enter mov leftSpace, LEFT_SPACE_IN_TAB mov charSet, dl ; save cur char set number mov gState, di ; save gState handle call VisGetBounds ; get bounds of letter tabs sub dx, FIRST_ROW_Y_POSITION_ADJUST ; adjust y position mov yPosition, dx ; bx - y position PZ < sub yPosition, 1 > mov xColumnOne, ax ; save left pos. of boundary add ax, FIRST_ROW_X_POSITION_ADJUST ; adjust x position mov xPosition, ax ; ax - x position PZ < sub xPosition, 3 > ; now change the font and point size ifdef GPC call GrSaveState endif mov dx, LETTER_TAB_FONT_SIZE ; dx - integer part of WBFixed mov cx, GEODEX_DISPLAY_FONT clr ah ; dx.ah - point size call GrSetFont ; change the font GetResourceHandleNS TextResource, bx call MemLock ; lock the block with char set mov ds, ax ; set up the segment ;; (why?) mov es, ax ; set up the segment ;; (why?) mov di, offset LetterTabCharSetTable; handle of error messages mov si, offset LetterTabCharSetTable mov si, ds:[si] ; dereference the handle clr dh mov dl, charSet ; dx - current char set index shl dx, 1 ; multiply it by two add si, dx ; go to the correct char set mov si, ds:[si] ; text handle => si mov si, ds:[si] ; dereference the handle clr cx ; index into character set charLoop: push si, cx shl cx, 1 ; array of 'nptr's add si, cx ; go to the correct character mov si, ds:[si] ; text handle => si mov si, ds:[si] ; character is in DS:SI ChunkSizePtr ds, si, cx DBCS < shr cx, 1 ; cx - string length > dec cx ; cx - length w/out NULL cmp cx, 1 ; just one character in string? jg notOne ; if not, skip to handle it SBCS < clr dh > LocalGetChar dx, dssi, noAdvance ; dx - char to draw mov ax, xPosition ; ax - x position mov bx, yPosition ; bx - y position mov di, gState ; di - gState handle call GrDrawChar ; draw the character jmp common2 notOne: call DrawMultChar ; draw multiple character common2: pop si, cx ; cx - # of chars drawn so far inc cx ; increment it cmp cx, MAX_NUM_OF_LETTER_TABS ; are we done? je done ; if so, exit cmp cx, DLTI_ROW_TWO ; if not, at the beg. of row 2? jne three ; if not, skip ; this is the 1st character of row two, adjust x, y position values mov leftSpace, LEFT_SPACE_IN_TAB mov ax, xColumnOne add ax, SECOND_ROW_X_POSITION_ADJUST mov xPosition, ax ; ax - new X position for row 2 sub yPosition, SECOND_ROW_Y_POSITION_ADJUST ; y position jmp charLoop ; draw the next character three: cmp cx, DLTI_ROW_THREE ; is this 1st char of row 3? jne updateX ; if not, skip ; this is the 1st character of row three, adjust x, y position values mov leftSpace, LEFT_SPACE_IN_TAB mov ax, xColumnOne add ax, THIRD_ROW_X_POSITION_ADJUST mov xPosition, ax ; ax - new x position of row 3 sub yPosition, THIRD_ROW_Y_POSITION_ADJUST ; y position jmp charLoop ; draw the next character updateX: mov leftSpace, LEFT_SPACE_IN_TAB-3 add xPosition, NEXT_COLUMN_INCREMENT; update x position jmp charLoop done: ifdef GPC mov di, gState call GrRestoreState endif GetResourceHandleNS TextResource, bx call MemUnlock ; unlock the block .leave ret DrawLetters endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawMultChar %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draw letter tabs with multiple characters CALLED BY: (INTERNAL) DrawLetters PASS: ds:si - character string to draw cx - length of string (w//out C_NULL) RETURN: none DESTROYED: ax, bx, cx, dx, si, di SIDE EFFECTS: none PSEUDO CODE/STRATEGY: Calculate string width in points. If more than 2 chars, move left margin to left edge of letter tab. Print the string. REVISION HISTORY: Name Date Description ---- ---- ----------- THK 10/92 Initial revision %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawMultChar proc near xColumnOne local word ; left boundary of letter tabs xPosition local word ; x position for GrDrawChar yPosition local word ; y position for GrDrawChar gState local hptr ; gstate handle charSet local byte ; current character set index leftSpace local word ; space b/w left edge and char .enter inherit near push cx ; save char length clr cx ; cx - point width of string clr ah push si mainLoop: LocalGetChar ax, dssi ; ax - char to draw LocalIsNull ax ; end of string? je done ; exit if so mov di, gState ; di - gState handle call GrCharWidth ; dx - width of this character add cx, dx ; cx - width of string jmp mainLoop ; check the next character done: pop si ; retrive string ptr ;;(why??) cmp cx, NEXT_COLUMN_INCREMENT ; is string too wide? ;;(why??) jle draw ; if so, exit ;;(why??) draw: mov ax, xPosition pop bx ; retrieve char length cmp bx, 2 ; more that 2 chars? je charLoop sub ax, leftSpace ; ax - "moved left" x position charLoop: LocalGetChar dx, dssi ; dx - char to draw LocalIsNull dx ; end of string? je exit ; exit if so mov bx, yPosition ; bx - y position mov di, gState ; di - gState handle push ax call GrDrawChar ; draw the character mov ax, dx ; ax - char to draw call GrCharWidth ; dx - width of this character pop ax add ax, dx ; ax - x position jmp charLoop exit: .leave ret DrawMultChar endp LettersCode ends
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r13 push %r15 push %r9 push %rax push %rbp lea addresses_WC_ht+0xee23, %r15 nop nop nop nop cmp $48245, %rbp mov (%r15), %r11d nop nop sub $51725, %r13 lea addresses_D_ht+0xc23, %r9 nop nop and $3662, %r11 movb $0x61, (%r9) nop nop nop nop cmp $32803, %r15 pop %rbp pop %rax pop %r9 pop %r15 pop %r13 pop %r11 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r12 push %rax push %rbp push %rbx // Faulty Load lea addresses_WC+0x96a3, %rbx add %rbp, %rbp movups (%rbx), %xmm3 vpextrq $1, %xmm3, %r10 lea oracles, %rbp and $0xff, %r10 shlq $12, %r10 mov (%rbp,%r10,1), %r10 pop %rbx pop %rbp pop %rax pop %r12 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 7, 'size': 4, 'same': False, 'NT': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 5, 'size': 1, 'same': False, 'NT': False}} {'00': 21829} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
;; ;; Copyright (c) Microsoft. All rights reserved. ;; Licensed under the MIT license. See LICENSE file in the project root for full license information. ;; #include "AsmMacros.h" TEXTAREA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; RhpThrowHwEx ;; ;; INPUT: R0: exception code of fault ;; R1: faulting IP ;; ;; OUTPUT: ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; NESTED_ENTRY RhpThrowHwEx #define STACKSIZEOF_ExInfo ((SIZEOF__ExInfo + 7)&(~7)) #define rsp_offsetof_ExInfo 0 #define rsp_offsetof_Context STACKSIZEOF_ExInfo PROLOG_NOP mov r2, r0 ;; save exception code into r2 PROLOG_NOP mov r0, sp ;; get SP of fault site PROLOG_NOP add lr, r1, #2 ;; 'faulting IP' += 2, we do this because everywhere else we treat the ;; faulting IP as a return-address and optionally subtract one when doing ;; EH-related things (but not subtracting 2 when doing GC-related things). ;; The fault IP here will be the start of the faulting instruction, so +2 ;; will point to either the next instruction or the middle of this ;; instruction. Either way, when the dispatch / stackwalk code deals with ;; this address it'll apply a -2 for EH range checks and the GC-related ;; operations don't need to be precise here because the fault location ;; isn't a GC safe point ;; Setup a PAL_LIMITED_CONTEXT on the stack { PROLOG_NOP vpush {d8-d15} PROLOG_NOP push {r0,lr} ;; push {sp, pc} of fault site PROLOG_PUSH_MACHINE_FRAME ;; unwind code only PROLOG_PUSH {r0,r4-r11,lr} ;; } end PAL_LIMITED_CONTEXT PROLOG_STACK_ALLOC STACKSIZEOF_ExInfo ; r0: SP of fault site ; r1: IP of fault site ; r2: exception code of fault ; lr: IP of fault site (as a 'return address') mov r0, r2 ;; r0 <- exception code of fault ;; r2 = GetThread(), TRASHES r1 INLINE_GETTHREAD r2, r1 add r1, sp, #rsp_offsetof_ExInfo ;; r1 <- ExInfo* mov r3, #0 str r3, [r1, #OFFSETOF__ExInfo__m_exception] ;; pExInfo->m_exception = null mov r3, #1 strb r3, [r1, #OFFSETOF__ExInfo__m_passNumber] ;; pExInfo->m_passNumber = 1 mov r3, #0xFFFFFFFF str r3, [r1, #OFFSETOF__ExInfo__m_idxCurClause] ;; pExInfo->m_idxCurClause = MaxTryRegionIdx mov r3, #2 strb r3, [r1, #OFFSETOF__ExInfo__m_kind] ;; pExInfo->m_kind = ExKind.HardwareFault ;; link the ExInfo into the thread's ExInfo chain ldr r3, [r2, #OFFSETOF__Thread__m_pExInfoStackHead] str r3, [r1, #OFFSETOF__ExInfo__m_pPrevExInfo] ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead str r1, [r2, #OFFSETOF__Thread__m_pExInfoStackHead] ;; m_pExInfoStackHead = pExInfo ;; set the exception context field on the ExInfo add r2, sp, #rsp_offsetof_Context ;; r2 <- PAL_LIMITED_CONTEXT* str r2, [r1, #OFFSETOF__ExInfo__m_pExContext] ;; pExInfo->m_pExContext = pContext ;; r0: exception code ;; r1: ExInfo* bl RhThrowHwEx LABELED_RETURN_ADDRESS RhpThrowHwEx2 ;; no return __debugbreak NESTED_END RhpThrowHwEx ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; RhpThrowEx ;; ;; INPUT: R0: exception object ;; ;; OUTPUT: ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; NESTED_ENTRY RhpThrowEx ;; Setup a PAL_LIMITED_CONTEXT on the stack { PROLOG_VPUSH {d8-d15} PROLOG_PUSH {r0,lr} ;; Reserve space for SP and store LR PROLOG_PUSH {r0,r4-r11,lr} ;; } end PAL_LIMITED_CONTEXT PROLOG_STACK_ALLOC STACKSIZEOF_ExInfo ;; Compute and save SP at callsite. add r1, sp, #(STACKSIZEOF_ExInfo + SIZEOF__PAL_LIMITED_CONTEXT) str r1, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__SP)] ;; r2 = GetThread(), TRASHES r1 INLINE_GETTHREAD r2, r1 ;; There is runtime C# code that can tail call to RhpThrowEx using a binder intrinsic. So the return ;; address could have been hijacked when we were in that C# code and we must remove the hijack and ;; reflect the correct return address in our exception context record. The other throw helpers don't ;; need this because they cannot be tail-called from C#. ;; NOTE: we cannot use INLINE_THREAD_UNHIJACK because it will write into the stack at the location ;; where the tail-calling thread had saved LR, which may not match where we have saved LR. ldr r1, [r2, #OFFSETOF__Thread__m_pvHijackedReturnAddress] cbz r1, NotHijacked ldr r3, [r2, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation] ;; r0: exception object ;; r1: hijacked return address ;; r2: pThread ;; r3: hijacked return address location add r12, sp, #(STACKSIZEOF_ExInfo + SIZEOF__PAL_LIMITED_CONTEXT) ;; re-compute SP at callsite cmp r3, r12 ;; if (m_ppvHijackedReturnAddressLocation < SP at callsite) blo TailCallWasHijacked ;; normal case where a valid return address location is hijacked str r1, [r3] b ClearThreadState TailCallWasHijacked ;; Abnormal case where the return address location is now invalid because we ended up here via a tail ;; call. In this case, our hijacked return address should be the correct caller of this method. ;; ;; stick the previous return address in LR as well as in the right spots in our PAL_LIMITED_CONTEXT. mov lr, r1 str lr, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__LR)] str lr, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__IP)] ClearThreadState ;; clear the Thread's hijack state mov r3, #0 str r3, [r2, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation] str r3, [r2, #OFFSETOF__Thread__m_pvHijackedReturnAddress] NotHijacked add r1, sp, #rsp_offsetof_ExInfo ;; r1 <- ExInfo* mov r3, #0 str r3, [r1, #OFFSETOF__ExInfo__m_exception] ;; pExInfo->m_exception = null mov r3, #1 strb r3, [r1, #OFFSETOF__ExInfo__m_passNumber] ;; pExInfo->m_passNumber = 1 mov r3, #0xFFFFFFFF str r3, [r1, #OFFSETOF__ExInfo__m_idxCurClause] ;; pExInfo->m_idxCurClause = MaxTryRegionIdx mov r3, #1 strb r3, [r1, #OFFSETOF__ExInfo__m_kind] ;; pExInfo->m_kind = ExKind.Throw ;; link the ExInfo into the thread's ExInfo chain ldr r3, [r2, #OFFSETOF__Thread__m_pExInfoStackHead] str r3, [r1, #OFFSETOF__ExInfo__m_pPrevExInfo] ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead str r1, [r2, #OFFSETOF__Thread__m_pExInfoStackHead] ;; m_pExInfoStackHead = pExInfo ;; set the exception context field on the ExInfo add r2, sp, #rsp_offsetof_Context ;; r2 <- PAL_LIMITED_CONTEXT* str r2, [r1, #OFFSETOF__ExInfo__m_pExContext] ;; pExInfo->m_pExContext = pContext ;; r0: exception object ;; r1: ExInfo* bl RhThrowEx LABELED_RETURN_ADDRESS RhpThrowEx2 ;; no return __debugbreak NESTED_END RhpThrowEx ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; void FASTCALL RhpRethrow() ;; ;; SUMMARY: Similar to RhpThrowEx, except that it passes along the currently active ExInfo ;; ;; INPUT: ;; ;; OUTPUT: ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; NESTED_ENTRY RhpRethrow ;; Setup a PAL_LIMITED_CONTEXT on the stack { PROLOG_VPUSH {d8-d15} PROLOG_PUSH {r0,lr} ;; Reserve space for SP and store LR PROLOG_PUSH {r0,r4-r11,lr} ;; } end PAL_LIMITED_CONTEXT PROLOG_STACK_ALLOC STACKSIZEOF_ExInfo ;; Compute and save SP at callsite. add r1, sp, #(STACKSIZEOF_ExInfo + SIZEOF__PAL_LIMITED_CONTEXT) str r1, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__SP)] ;; r2 = GetThread(), TRASHES r1 INLINE_GETTHREAD r2, r1 add r1, sp, #rsp_offsetof_ExInfo ;; r1 <- ExInfo* mov r3, #0 str r3, [r1, #OFFSETOF__ExInfo__m_exception] ;; pExInfo->m_exception = null mov r3, #1 strb r3, [r1, #OFFSETOF__ExInfo__m_passNumber] ;; pExInfo->m_passNumber = 1 mov r3, #0xFFFFFFFF str r3, [r1, #OFFSETOF__ExInfo__m_idxCurClause] ;; pExInfo->m_idxCurClause = MaxTryRegionIdx ;; link the ExInfo into the thread's ExInfo chain ldr r3, [r2, #OFFSETOF__Thread__m_pExInfoStackHead] mov r0, r3 ;; r0 <- current ExInfo str r3, [r1, #OFFSETOF__ExInfo__m_pPrevExInfo] ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead str r1, [r2, #OFFSETOF__Thread__m_pExInfoStackHead] ;; m_pExInfoStackHead = pExInfo ;; set the exception context field on the ExInfo add r2, sp, #rsp_offsetof_Context ;; r2 <- PAL_LIMITED_CONTEXT* str r2, [r1, #OFFSETOF__ExInfo__m_pExContext] ;; pExInfo->m_pExContext = pContext ;; r0 contains the currently active ExInfo ;; r1 contains the address of the new ExInfo bl RhRethrow LABELED_RETURN_ADDRESS RhpRethrow2 ;; no return __debugbreak NESTED_END RhpRethrow ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; void* FASTCALL RhpCallCatchFunclet(RtuObjectRef exceptionObj, void* pHandlerIP, REGDISPLAY* pRegDisplay, ;; ExInfo* pExInfo) ;; ;; INPUT: R0: exception object ;; R1: handler funclet address ;; R2: REGDISPLAY* ;; R3: ExInfo* ;; ;; OUTPUT: ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; NESTED_ENTRY RhpCallCatchFunclet PROLOG_PUSH {r1-r11,lr} ;; r2 & r3 are saved so we have the REGDISPLAY and ExInfo later, r1 is ;; alignment padding, and we save the preserved regs #define rsp_offset_r2 4 #define rsp_offset_r3 8 ;; ;; clear the DoNotTriggerGc flag, trashes r4-r6 ;; INLINE_GETTHREAD r5, r6 ;; r5 <- Thread*, r6 <- trashed ClearRetry_Catch ldrex r4, [r5, #OFFSETOF__Thread__m_ThreadStateFlags] bic r4, #TSF_DoNotTriggerGc strex r6, r4, [r5, #OFFSETOF__Thread__m_ThreadStateFlags] cbz r6, ClearSuccess_Catch b ClearRetry_Catch ClearSuccess_Catch ;; ;; set preserved regs to the values expected by the funclet ;; ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR4] ldr r4, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR5] ldr r5, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR6] ldr r6, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR7] ldr r7, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR8] ldr r8, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR9] ldr r9, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR10] ldr r10, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR11] ldr r11, [r12] #if 0 // def _DEBUG ;; @TODO: temporarily removed because trashing the frame pointer breaks the debugger ;; trash the values at the old homes to make sure nobody uses them movw r3, #0xdeed movt r3, #0xbaad ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR4] str r3, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR5] str r3, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR6] str r3, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR7] str r3, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR8] str r3, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR9] str r3, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR10] str r3, [r12] ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR11] str r3, [r12] #endif // _DEBUG ;; ;; load vfp preserved regs ;; add r12, r2, #OFFSETOF__REGDISPLAY__D vldm r12!, {d8-d15} ;; ;; call the funclet ;; ;; r0 still contains the exception object blx r1 LABELED_RETURN_ADDRESS RhpCallCatchFunclet2 ;; r0 contains resume IP ldr r2, [sp, #rsp_offset_r2] ;; r2 <- REGDISPLAY* ;; @TODO: add DBG-only validation code for ExInfo pop INLINE_GETTHREAD r1, r3 ;; r1 <- Thread*, r3 <- trashed ;; We must unhijack the thread at this point because the section of stack where the hijack is applied ;; may go dead. If it does, then the next time we try to unhijack the thread, it will corrupt the stack. INLINE_THREAD_UNHIJACK r1, r3, r12 ;; Thread in r1, trashes r3 and r12 ldr r3, [sp, #rsp_offset_r3] ;; r3 <- current ExInfo* ldr r2, [r2, #OFFSETOF__REGDISPLAY__SP] ;; r2 <- resume SP value PopExInfoLoop ldr r3, [r3, #OFFSETOF__ExInfo__m_pPrevExInfo] ;; r3 <- next ExInfo cbz r3, DonePopping ;; if (pExInfo == null) { we're done } cmp r3, r2 blt PopExInfoLoop ;; if (pExInfo < resume SP} { keep going } DonePopping str r3, [r1, #OFFSETOF__Thread__m_pExInfoStackHead] ;; store the new head on the Thread ;; reset SP and jump to continuation address mov sp, r2 bx r0 NESTED_END RhpCallCatchFunclet ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; void FASTCALL RhpCallFinallyFunclet(void* pHandlerIP, REGDISPLAY* pRegDisplay) ;; ;; INPUT: R0: handler funclet address ;; R1: REGDISPLAY* ;; ;; OUTPUT: ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; NESTED_ENTRY RhpCallFinallyFunclet PROLOG_PUSH {r1,r4-r11,lr} ;; r1 is saved so we have the REGDISPLAY later #define rsp_offset_r1 0 ;; ;; We want to suppress hijacking between invocations of subsequent finallys. We do this because we ;; cannot tolerate a GC after one finally has run (and possibly side-effected the GC state of the ;; method) and then been popped off the stack, leaving behind no trace of its effect. ;; ;; So we clear the state before and set it after invocation of the handler. ;; ;; ;; clear the DoNotTriggerGc flag, trashes r1-r3 ;; INLINE_GETTHREAD r2, r3 ;; r2 <- Thread*, r3 <- trashed ClearRetry ldrex r1, [r2, #OFFSETOF__Thread__m_ThreadStateFlags] bic r1, #TSF_DoNotTriggerGc strex r3, r1, [r2, #OFFSETOF__Thread__m_ThreadStateFlags] cbz r3, ClearSuccess b ClearRetry ClearSuccess ldr r1, [sp, #rsp_offset_r1] ;; reload REGDISPLAY pointer ;; ;; set preserved regs to the values expected by the funclet ;; ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR4] ldr r4, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR5] ldr r5, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR6] ldr r6, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR7] ldr r7, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR8] ldr r8, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR9] ldr r9, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR10] ldr r10, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR11] ldr r11, [r12] #if 0 // def _DEBUG ;; @TODO: temporarily removed because trashing the frame pointer breaks the debugger ;; trash the values at the old homes to make sure nobody uses them movw r3, #0xdeed movt r3, #0xbaad ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR4] str r3, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR5] str r3, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR6] str r3, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR7] str r3, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR8] str r3, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR9] str r3, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR10] str r3, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR11] str r3, [r12] #endif // _DEBUG ;; ;; load vfp preserved regs ;; add r12, r1, #OFFSETOF__REGDISPLAY__D vldm r12!, {d8-d15} ;; ;; call the funclet ;; blx r0 LABELED_RETURN_ADDRESS RhpCallFinallyFunclet2 ldr r1, [sp, #rsp_offset_r1] ;; reload REGDISPLAY pointer ;; ;; save new values of preserved regs into REGDISPLAY ;; ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR4] str r4, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR5] str r5, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR6] str r6, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR7] str r7, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR8] str r8, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR9] str r9, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR10] str r10, [r12] ldr r12, [r1, #OFFSETOF__REGDISPLAY__pR11] str r11, [r12] ;; ;; store vfp preserved regs ;; add r12, r1, #OFFSETOF__REGDISPLAY__D vstm r12!, {d8-d15} ;; ;; set the DoNotTriggerGc flag, trashes r1-r3 ;; INLINE_GETTHREAD r2, r3 ;; r2 <- Thread*, r3 <- trashed SetRetry ldrex r1, [r2, #OFFSETOF__Thread__m_ThreadStateFlags] orr r1, #TSF_DoNotTriggerGc strex r3, r1, [r2, #OFFSETOF__Thread__m_ThreadStateFlags] cbz r3, SetSuccess b SetRetry SetSuccess EPILOG_POP {r1,r4-r11,pc} NESTED_END RhpCallFinallyFunclet ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; void* FASTCALL RhpCallFilterFunclet(RtuObjectRef exceptionObj, void* pFilterIP, REGDISPLAY* pRegDisplay) ;; ;; INPUT: R0: exception object ;; R1: filter funclet address ;; R2: REGDISPLAY* ;; ;; OUTPUT: ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; NESTED_ENTRY RhpCallFilterFunclet PROLOG_PUSH {r2,r7,r11,lr} ;; r2 is saved so we have the REGDISPLAY later #undef rsp_offset_r2 #define rsp_offset_r2 0 ldr r12, [r2, #OFFSETOF__REGDISPLAY__pR7] ldr r7, [r12] ;; ;; call the funclet ;; ;; r0 still contains the exception object blx r1 LABELED_RETURN_ADDRESS RhpCallFilterFunclet2 EPILOG_POP {r1,r7,r11,pc} NESTED_END RhpCallFilterFunclet end
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r13 push %r15 push %r9 push %rcx push %rdx lea addresses_normal_ht+0x12849, %r13 nop nop nop nop nop add $49400, %rcx mov $0x6162636465666768, %rdx movq %rdx, %xmm2 vmovups %ymm2, (%r13) nop cmp %r10, %r10 lea addresses_UC_ht+0x86c9, %rdx nop nop nop add $45324, %r9 movups (%rdx), %xmm0 vpextrq $1, %xmm0, %r11 nop and %rcx, %rcx lea addresses_WT_ht+0x116c9, %rcx nop nop add $27170, %r15 movw $0x6162, (%rcx) dec %rdx lea addresses_UC_ht+0xaa9, %r9 nop nop xor $50302, %r10 mov (%r9), %cx nop nop nop nop nop sub %rdx, %rdx lea addresses_WT_ht+0x15545, %r11 nop nop nop nop nop add $8494, %rcx mov (%r11), %r9d add $52255, %r11 lea addresses_normal_ht+0x168a9, %r13 cmp $54152, %r11 mov $0x6162636465666768, %r10 movq %r10, (%r13) nop nop sub $7106, %r10 lea addresses_WC_ht+0x1b8e1, %r13 nop inc %rdx mov (%r13), %r9d nop xor $62258, %r15 lea addresses_WC_ht+0x88af, %rcx nop sub %r10, %r10 movw $0x6162, (%rcx) and $24071, %rcx pop %rdx pop %rcx pop %r9 pop %r15 pop %r13 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r12 push %r13 push %rbp push %rcx push %rdi push %rsi // Store lea addresses_UC+0x40d9, %rdi sub $51310, %r13 movw $0x5152, (%rdi) nop nop nop nop dec %rdi // Store lea addresses_A+0xf449, %rdi nop and $22303, %rsi mov $0x5152535455565758, %r12 movq %r12, %xmm1 movntdq %xmm1, (%rdi) nop nop nop inc %r12 // Faulty Load lea addresses_normal+0xeec9, %r12 nop nop nop nop nop add %rsi, %rsi movb (%r12), %cl lea oracles, %rsi and $0xff, %rcx shlq $12, %rcx mov (%rsi,%rcx,1), %rcx pop %rsi pop %rdi pop %rcx pop %rbp pop %r13 pop %r12 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} {'34': 34} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
// Copyright (c) 2009-2014 The Drivercoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "uritests.h" #include "guiutil.h" #include "walletmodel.h" #include <QUrl> void URITests::uriTests() { SendCoinsRecipient rv; QUrl uri; uri.setUrl(QString("drivercoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-dontexist=")); QVERIFY(!GUIUtil::parseDrivercoinURI(uri, &rv)); uri.setUrl(QString("drivercoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?dontexist=")); QVERIFY(GUIUtil::parseDrivercoinURI(uri, &rv)); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.label == QString()); QVERIFY(rv.amount == 0); uri.setUrl(QString("drivercoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Wikipedia Example Address")); QVERIFY(GUIUtil::parseDrivercoinURI(uri, &rv)); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.label == QString("Wikipedia Example Address")); QVERIFY(rv.amount == 0); uri.setUrl(QString("drivercoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=0.001")); QVERIFY(GUIUtil::parseDrivercoinURI(uri, &rv)); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.label == QString()); QVERIFY(rv.amount == 100000); uri.setUrl(QString("drivercoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1.001")); QVERIFY(GUIUtil::parseDrivercoinURI(uri, &rv)); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.label == QString()); QVERIFY(rv.amount == 100100000); uri.setUrl(QString("drivercoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=Wikipedia Example")); QVERIFY(GUIUtil::parseDrivercoinURI(uri, &rv)); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.amount == 10000000000LL); QVERIFY(rv.label == QString("Wikipedia Example")); uri.setUrl(QString("drivercoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address")); QVERIFY(GUIUtil::parseDrivercoinURI(uri, &rv)); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.label == QString()); QVERIFY(GUIUtil::parseDrivercoinURI("drivercoin://175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address", &rv)); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.label == QString()); uri.setUrl(QString("drivercoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address")); QVERIFY(GUIUtil::parseDrivercoinURI(uri, &rv)); uri.setUrl(QString("drivercoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example")); QVERIFY(!GUIUtil::parseDrivercoinURI(uri, &rv)); uri.setUrl(QString("drivercoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example")); QVERIFY(!GUIUtil::parseDrivercoinURI(uri, &rv)); }
; A038232: Triangle whose (i,j)-th entry is binomial(i,j)*4^(i-j)*2^j. ; Submitted by Christian Krause ; 1,4,2,16,16,4,64,96,48,8,256,512,384,128,16,1024,2560,2560,1280,320,32,4096,12288,15360,10240,3840,768,64,16384,57344,86016,71680,35840,10752,1792,128,65536,262144,458752,458752,286720,114688 lpb $0 add $1,1 sub $0,$1 mov $2,$1 sub $2,$0 lpe add $2,$1 bin $1,$0 mov $0,2 pow $0,$2 mul $0,2 mul $1,$0 mov $0,$1 div $0,2
;; ;; Copyright (c) 2012-2018, Intel Corporation ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions are met: ;; ;; * Redistributions of source code must retain the above copyright notice, ;; this list of conditions and the following disclaimer. ;; * Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; * Neither the name of Intel Corporation nor the names of its contributors ;; may be used to endorse or promote products derived from this software ;; without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;; %include "include/os.asm" %include "job_aes_hmac.asm" %include "mb_mgr_datastruct.asm" %include "include/reg_sizes.asm" extern sha512_x2_sse section .data default rel align 16 byteswap: ;ddq 0x08090a0b0c0d0e0f0001020304050607 dq 0x0001020304050607, 0x08090a0b0c0d0e0f len_masks: ;ddq 0x0000000000000000000000000000FFFF dq 0x000000000000FFFF, 0x0000000000000000 ;ddq 0x000000000000000000000000FFFF0000 dq 0x00000000FFFF0000, 0x0000000000000000 one: dq 1 section .text %ifndef FUNC %define FUNC flush_job_hmac_sha_512_sse %define SHA_X_DIGEST_SIZE 512 %endif %if 1 %ifdef LINUX %define arg1 rdi %define arg2 rsi %else %define arg1 rcx %define arg2 rdx %endif %define state arg1 %define job arg2 %define len2 arg2 ; idx needs to be in rbx, rbp, r12-r15 %define idx rbp %define unused_lanes rbx %define lane_data rbx %define tmp2 rbx %define job_rax rax %define tmp1 rax %define size_offset rax %define tmp rax %define start_offset rax %define tmp3 arg1 %define extra_blocks arg2 %define p arg2 %define tmp4 r8 %define tmp5 r9 %define tmp6 r10 %endif ; This routine clobbers rbx, rbp struc STACK _gpr_save: resq 2 _rsp_save: resq 1 endstruc %define APPEND(a,b) a %+ b ; JOB* FUNC(MB_MGR_HMAC_SHA_512_OOO *state) ; arg 1 : rcx : state MKGLOBAL(FUNC,function,internal) FUNC: mov rax, rsp sub rsp, STACK_size and rsp, -16 mov [rsp + _gpr_save + 8*0], rbx mov [rsp + _gpr_save + 8*1], rbp mov [rsp + _rsp_save], rax ; original SP mov unused_lanes, [state + _unused_lanes_sha512] bt unused_lanes, 16+7 jc return_null ; find a lane with a non-null job xor idx, idx cmp qword [state + _ldata_sha512 + 1 * _SHA512_LANE_DATA_size + _job_in_lane_sha512], 0 cmovne idx, [rel one] copy_lane_data: ; copy good lane (idx) to empty lanes movdqa xmm0, [state + _lens_sha512] mov tmp, [state + _args_sha512 + _data_ptr_sha512 + PTR_SZ*idx] %assign I 0 %rep 2 cmp qword [state + _ldata_sha512 + I * _SHA512_LANE_DATA_size + _job_in_lane_sha512], 0 jne APPEND(skip_,I) mov [state + _args_sha512 + _data_ptr_sha512 + PTR_SZ*I], tmp por xmm0, [rel len_masks + 16*I] APPEND(skip_,I): %assign I (I+1) %endrep movdqa [state + _lens_sha512], xmm0 phminposuw xmm1, xmm0 pextrw len2, xmm1, 0 ; min value pextrw idx, xmm1, 1 ; min index (0...3) cmp len2, 0 je len_is_0 pshuflw xmm1, xmm1, 0xA0 psubw xmm0, xmm1 movdqa [state + _lens_sha512], xmm0 ; "state" and "args" are the same address, arg1 ; len is arg2 call sha512_x2_sse ; state and idx are intact len_is_0: ; process completed job "idx" imul lane_data, idx, _SHA512_LANE_DATA_size lea lane_data, [state + _ldata_sha512 + lane_data] mov DWORD(extra_blocks), [lane_data + _extra_blocks_sha512] cmp extra_blocks, 0 jne proc_extra_blocks cmp dword [lane_data + _outer_done_sha512], 0 jne end_loop proc_outer: mov dword [lane_data + _outer_done_sha512], 1 mov DWORD(size_offset), [lane_data + _size_offset_sha512] mov qword [lane_data + _extra_block_sha512 + size_offset], 0 mov word [state + _lens_sha512 + 2*idx], 1 lea tmp, [lane_data + _outer_block_sha512] mov job, [lane_data + _job_in_lane_sha512] mov [state + _args_data_ptr_sha512 + PTR_SZ*idx], tmp %assign I 0 %rep (SHA_X_DIGEST_SIZE / (8*16)) movq xmm0, [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + (2*I)*SHA512_DIGEST_ROW_SIZE] pinsrq xmm0, [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + (2*I + 1) *SHA512_DIGEST_ROW_SIZE], 1 pshufb xmm0, [rel byteswap] movdqa [lane_data + _outer_block_sha512 + I*16], xmm0 %assign I (I+1) %endrep mov tmp, [job + _auth_key_xor_opad] %assign I 0 %rep 4 movdqu xmm0, [tmp + I * 16] movq [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 2*I*SHA512_DIGEST_ROW_SIZE], xmm0 pextrq [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + (2*I + 1)*SHA512_DIGEST_ROW_SIZE], xmm0, 1 %assign I (I+1) %endrep jmp copy_lane_data align 16 proc_extra_blocks: mov DWORD(start_offset), [lane_data + _start_offset_sha512] mov [state + _lens_sha512 + 2*idx], WORD(extra_blocks) lea tmp, [lane_data + _extra_block_sha512 + start_offset] mov [state + _args_data_ptr_sha512 + PTR_SZ*idx], tmp mov dword [lane_data + _extra_blocks_sha512], 0 jmp copy_lane_data return_null: xor job_rax, job_rax jmp return align 16 end_loop: mov job_rax, [lane_data + _job_in_lane_sha512] mov qword [lane_data + _job_in_lane_sha512], 0 or dword [job_rax + _status], STS_COMPLETED_HMAC mov unused_lanes, [state + _unused_lanes_sha512] shl unused_lanes, 8 or unused_lanes, idx mov [state + _unused_lanes_sha512], unused_lanes mov p, [job_rax + _auth_tag_output] %if (SHA_X_DIGEST_SIZE != 384) cmp qword [job_rax + _auth_tag_output_len_in_bytes], 32 jne copy_full_digest %else cmp qword [job_rax + _auth_tag_output_len_in_bytes], 24 jne copy_full_digest %endif ;; copy 32 bytes for SHA512 // 24 bytes for SHA384 mov QWORD(tmp2), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 0*SHA512_DIGEST_ROW_SIZE] mov QWORD(tmp4), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 1*SHA512_DIGEST_ROW_SIZE] mov QWORD(tmp6), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 2*SHA512_DIGEST_ROW_SIZE] %if (SHA_X_DIGEST_SIZE != 384) mov QWORD(tmp5), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 3*SHA512_DIGEST_ROW_SIZE] %endif bswap QWORD(tmp2) bswap QWORD(tmp4) bswap QWORD(tmp6) %if (SHA_X_DIGEST_SIZE != 384) bswap QWORD(tmp5) %endif mov [p + 0*8], QWORD(tmp2) mov [p + 1*8], QWORD(tmp4) mov [p + 2*8], QWORD(tmp6) %if (SHA_X_DIGEST_SIZE != 384) mov [p + 3*8], QWORD(tmp5) %endif jmp return copy_full_digest: ;; copy 32 bytes for SHA512 // 24 bytes for SHA384 mov QWORD(tmp2), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 0*SHA512_DIGEST_ROW_SIZE] mov QWORD(tmp4), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 1*SHA512_DIGEST_ROW_SIZE] mov QWORD(tmp6), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 2*SHA512_DIGEST_ROW_SIZE] mov QWORD(tmp5), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 3*SHA512_DIGEST_ROW_SIZE] bswap QWORD(tmp2) bswap QWORD(tmp4) bswap QWORD(tmp6) bswap QWORD(tmp5) mov [p + 0*8], QWORD(tmp2) mov [p + 1*8], QWORD(tmp4) mov [p + 2*8], QWORD(tmp6) mov [p + 3*8], QWORD(tmp5) mov QWORD(tmp2), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 4*SHA512_DIGEST_ROW_SIZE] mov QWORD(tmp4), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 5*SHA512_DIGEST_ROW_SIZE] %if (SHA_X_DIGEST_SIZE != 384) mov QWORD(tmp6), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 6*SHA512_DIGEST_ROW_SIZE] mov QWORD(tmp5), [state + _args_digest_sha512 + SHA512_DIGEST_WORD_SIZE*idx + 7*SHA512_DIGEST_ROW_SIZE] %endif bswap QWORD(tmp2) bswap QWORD(tmp4) %if (SHA_X_DIGEST_SIZE != 384) bswap QWORD(tmp6) bswap QWORD(tmp5) %endif mov [p + 4*8], QWORD(tmp2) mov [p + 5*8], QWORD(tmp4) %if (SHA_X_DIGEST_SIZE != 384) mov [p + 6*8], QWORD(tmp6) mov [p + 7*8], QWORD(tmp5) %endif return: mov rbx, [rsp + _gpr_save + 8*0] mov rbp, [rsp + _gpr_save + 8*1] mov rsp, [rsp + _rsp_save] ; original SP ret %ifdef LINUX section .note.GNU-stack noalloc noexec nowrite progbits %endif
// ============================================================== // RTL generated by Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC // Version: 2019.1 // Copyright (C) 1986-2019 Xilinx, Inc. All Rights Reserved. // // =========================================================== #include "aes_main.h" #include "AESL_pkg.h" using namespace std; namespace ap_rtl { const sc_logic aes_main::ap_const_logic_1 = sc_dt::Log_1; const sc_logic aes_main::ap_const_logic_0 = sc_dt::Log_0; const sc_lv<12> aes_main::ap_ST_fsm_state1 = "1"; const sc_lv<12> aes_main::ap_ST_fsm_state2 = "10"; const sc_lv<12> aes_main::ap_ST_fsm_state3 = "100"; const sc_lv<12> aes_main::ap_ST_fsm_state4 = "1000"; const sc_lv<12> aes_main::ap_ST_fsm_state5 = "10000"; const sc_lv<12> aes_main::ap_ST_fsm_state6 = "100000"; const sc_lv<12> aes_main::ap_ST_fsm_state7 = "1000000"; const sc_lv<12> aes_main::ap_ST_fsm_state8 = "10000000"; const sc_lv<12> aes_main::ap_ST_fsm_state9 = "100000000"; const sc_lv<12> aes_main::ap_ST_fsm_state10 = "1000000000"; const sc_lv<12> aes_main::ap_ST_fsm_state11 = "10000000000"; const sc_lv<12> aes_main::ap_ST_fsm_state12 = "100000000000"; const sc_lv<32> aes_main::ap_const_lv32_0 = "00000000000000000000000000000000"; const sc_lv<32> aes_main::ap_const_lv32_A = "1010"; const sc_lv<32> aes_main::ap_const_lv32_B = "1011"; const sc_lv<32> aes_main::ap_const_lv32_8 = "1000"; const sc_lv<32> aes_main::ap_const_lv32_9 = "1001"; const sc_lv<32> aes_main::ap_const_lv32_2B = "101011"; const sc_lv<4> aes_main::ap_const_lv4_0 = "0000"; const sc_lv<32> aes_main::ap_const_lv32_7E = "1111110"; const sc_lv<4> aes_main::ap_const_lv4_1 = "1"; const sc_lv<32> aes_main::ap_const_lv32_1 = "1"; const sc_lv<32> aes_main::ap_const_lv32_15 = "10101"; const sc_lv<4> aes_main::ap_const_lv4_2 = "10"; const sc_lv<32> aes_main::ap_const_lv32_16 = "10110"; const sc_lv<4> aes_main::ap_const_lv4_3 = "11"; const sc_lv<32> aes_main::ap_const_lv32_2 = "10"; const sc_lv<32> aes_main::ap_const_lv32_28 = "101000"; const sc_lv<4> aes_main::ap_const_lv4_4 = "100"; const sc_lv<32> aes_main::ap_const_lv32_AE = "10101110"; const sc_lv<4> aes_main::ap_const_lv4_5 = "101"; const sc_lv<32> aes_main::ap_const_lv32_3 = "11"; const sc_lv<32> aes_main::ap_const_lv32_D2 = "11010010"; const sc_lv<4> aes_main::ap_const_lv4_6 = "110"; const sc_lv<32> aes_main::ap_const_lv32_A6 = "10100110"; const sc_lv<4> aes_main::ap_const_lv4_7 = "111"; const sc_lv<32> aes_main::ap_const_lv32_4 = "100"; const sc_lv<32> aes_main::ap_const_lv32_AB = "10101011"; const sc_lv<4> aes_main::ap_const_lv4_8 = "1000"; const sc_lv<32> aes_main::ap_const_lv32_F7 = "11110111"; const sc_lv<4> aes_main::ap_const_lv4_9 = "1001"; const sc_lv<32> aes_main::ap_const_lv32_5 = "101"; const sc_lv<4> aes_main::ap_const_lv4_A = "1010"; const sc_lv<32> aes_main::ap_const_lv32_88 = "10001000"; const sc_lv<4> aes_main::ap_const_lv4_B = "1011"; const sc_lv<32> aes_main::ap_const_lv32_6 = "110"; const sc_lv<4> aes_main::ap_const_lv4_C = "1100"; const sc_lv<32> aes_main::ap_const_lv32_CF = "11001111"; const sc_lv<4> aes_main::ap_const_lv4_D = "1101"; const sc_lv<32> aes_main::ap_const_lv32_7 = "111"; const sc_lv<32> aes_main::ap_const_lv32_4F = "1001111"; const sc_lv<4> aes_main::ap_const_lv4_E = "1110"; const sc_lv<32> aes_main::ap_const_lv32_3C = "111100"; const sc_lv<4> aes_main::ap_const_lv4_F = "1111"; const sc_lv<32> aes_main::ap_const_lv32_32 = "110010"; const sc_lv<32> aes_main::ap_const_lv32_F6 = "11110110"; const sc_lv<32> aes_main::ap_const_lv32_30 = "110000"; const sc_lv<32> aes_main::ap_const_lv32_31 = "110001"; const sc_lv<32> aes_main::ap_const_lv32_98 = "10011000"; const sc_lv<32> aes_main::ap_const_lv32_E0 = "11100000"; const sc_lv<32> aes_main::ap_const_lv32_43 = "1000011"; const sc_lv<32> aes_main::ap_const_lv32_A8 = "10101000"; const sc_lv<32> aes_main::ap_const_lv32_5A = "1011010"; const sc_lv<32> aes_main::ap_const_lv32_8D = "10001101"; const sc_lv<32> aes_main::ap_const_lv32_A2 = "10100010"; const sc_lv<32> aes_main::ap_const_lv32_37 = "110111"; const sc_lv<32> aes_main::ap_const_lv32_34 = "110100"; const bool aes_main::ap_const_boolean_1 = true; aes_main::aes_main(sc_module_name name) : sc_module(name), mVcdFile(0) { word_0_U = new aes_main_word_0("word_0_U"); word_0_U->clk(ap_clk); word_0_U->reset(ap_rst); word_0_U->address0(word_0_address0); word_0_U->ce0(word_0_ce0); word_0_U->we0(word_0_we0); word_0_U->d0(word_0_d0); word_0_U->q0(word_0_q0); word_0_U->address1(word_0_address1); word_0_U->ce1(word_0_ce1); word_0_U->we1(word_0_we1); word_0_U->d1(word_0_d1); word_0_U->q1(word_0_q1); word_1_U = new aes_main_word_0("word_1_U"); word_1_U->clk(ap_clk); word_1_U->reset(ap_rst); word_1_U->address0(word_1_address0); word_1_U->ce0(word_1_ce0); word_1_U->we0(word_1_we0); word_1_U->d0(word_1_d0); word_1_U->q0(word_1_q0); word_1_U->address1(word_1_address1); word_1_U->ce1(word_1_ce1); word_1_U->we1(word_1_we1); word_1_U->d1(word_1_d1); word_1_U->q1(word_1_q1); statemt_0_U = new aes_main_statemt_0("statemt_0_U"); statemt_0_U->clk(ap_clk); statemt_0_U->reset(ap_rst); statemt_0_U->address0(statemt_0_address0); statemt_0_U->ce0(statemt_0_ce0); statemt_0_U->we0(statemt_0_we0); statemt_0_U->d0(statemt_0_d0); statemt_0_U->q0(statemt_0_q0); statemt_0_U->address1(statemt_0_address1); statemt_0_U->ce1(statemt_0_ce1); statemt_0_U->we1(statemt_0_we1); statemt_0_U->d1(statemt_0_d1); statemt_0_U->q1(statemt_0_q1); statemt_1_U = new aes_main_statemt_0("statemt_1_U"); statemt_1_U->clk(ap_clk); statemt_1_U->reset(ap_rst); statemt_1_U->address0(statemt_1_address0); statemt_1_U->ce0(statemt_1_ce0); statemt_1_U->we0(statemt_1_we0); statemt_1_U->d0(statemt_1_d0); statemt_1_U->q0(statemt_1_q0); statemt_1_U->address1(statemt_1_address1); statemt_1_U->ce1(statemt_1_ce1); statemt_1_U->we1(statemt_1_we1); statemt_1_U->d1(statemt_1_d1); statemt_1_U->q1(statemt_1_q1); key_0_U = new aes_main_statemt_0("key_0_U"); key_0_U->clk(ap_clk); key_0_U->reset(ap_rst); key_0_U->address0(key_0_address0); key_0_U->ce0(key_0_ce0); key_0_U->we0(key_0_we0); key_0_U->d0(key_0_d0); key_0_U->q0(key_0_q0); key_0_U->address1(key_0_address1); key_0_U->ce1(key_0_ce1); key_0_U->we1(key_0_we1); key_0_U->d1(key_0_d1); key_0_U->q1(key_0_q1); grp_decrypt_fu_242 = new decrypt("grp_decrypt_fu_242"); grp_decrypt_fu_242->ap_clk(ap_clk); grp_decrypt_fu_242->ap_rst(ap_rst); grp_decrypt_fu_242->ap_start(grp_decrypt_fu_242_ap_start); grp_decrypt_fu_242->ap_done(grp_decrypt_fu_242_ap_done); grp_decrypt_fu_242->ap_idle(grp_decrypt_fu_242_ap_idle); grp_decrypt_fu_242->ap_ready(grp_decrypt_fu_242_ap_ready); grp_decrypt_fu_242->statemt_0_address0(grp_decrypt_fu_242_statemt_0_address0); grp_decrypt_fu_242->statemt_0_ce0(grp_decrypt_fu_242_statemt_0_ce0); grp_decrypt_fu_242->statemt_0_we0(grp_decrypt_fu_242_statemt_0_we0); grp_decrypt_fu_242->statemt_0_d0(grp_decrypt_fu_242_statemt_0_d0); grp_decrypt_fu_242->statemt_0_q0(statemt_0_q0); grp_decrypt_fu_242->statemt_0_address1(grp_decrypt_fu_242_statemt_0_address1); grp_decrypt_fu_242->statemt_0_ce1(grp_decrypt_fu_242_statemt_0_ce1); grp_decrypt_fu_242->statemt_0_we1(grp_decrypt_fu_242_statemt_0_we1); grp_decrypt_fu_242->statemt_0_d1(grp_decrypt_fu_242_statemt_0_d1); grp_decrypt_fu_242->statemt_0_q1(statemt_0_q1); grp_decrypt_fu_242->statemt_1_address0(grp_decrypt_fu_242_statemt_1_address0); grp_decrypt_fu_242->statemt_1_ce0(grp_decrypt_fu_242_statemt_1_ce0); grp_decrypt_fu_242->statemt_1_we0(grp_decrypt_fu_242_statemt_1_we0); grp_decrypt_fu_242->statemt_1_d0(grp_decrypt_fu_242_statemt_1_d0); grp_decrypt_fu_242->statemt_1_q0(statemt_1_q0); grp_decrypt_fu_242->statemt_1_address1(grp_decrypt_fu_242_statemt_1_address1); grp_decrypt_fu_242->statemt_1_ce1(grp_decrypt_fu_242_statemt_1_ce1); grp_decrypt_fu_242->statemt_1_we1(grp_decrypt_fu_242_statemt_1_we1); grp_decrypt_fu_242->statemt_1_d1(grp_decrypt_fu_242_statemt_1_d1); grp_decrypt_fu_242->statemt_1_q1(statemt_1_q1); grp_decrypt_fu_242->key_0_address0(grp_decrypt_fu_242_key_0_address0); grp_decrypt_fu_242->key_0_ce0(grp_decrypt_fu_242_key_0_ce0); grp_decrypt_fu_242->key_0_q0(key_0_q0); grp_decrypt_fu_242->key_0_address1(grp_decrypt_fu_242_key_0_address1); grp_decrypt_fu_242->key_0_ce1(grp_decrypt_fu_242_key_0_ce1); grp_decrypt_fu_242->key_0_q1(key_0_q1); grp_decrypt_fu_242->round_val(grp_decrypt_fu_242_round_val); grp_decrypt_fu_242->round_val_ap_vld(grp_decrypt_fu_242_round_val_ap_vld); grp_decrypt_fu_242->word_0_address0(grp_decrypt_fu_242_word_0_address0); grp_decrypt_fu_242->word_0_ce0(grp_decrypt_fu_242_word_0_ce0); grp_decrypt_fu_242->word_0_we0(grp_decrypt_fu_242_word_0_we0); grp_decrypt_fu_242->word_0_d0(grp_decrypt_fu_242_word_0_d0); grp_decrypt_fu_242->word_0_q0(word_0_q0); grp_decrypt_fu_242->word_0_address1(grp_decrypt_fu_242_word_0_address1); grp_decrypt_fu_242->word_0_ce1(grp_decrypt_fu_242_word_0_ce1); grp_decrypt_fu_242->word_0_we1(grp_decrypt_fu_242_word_0_we1); grp_decrypt_fu_242->word_0_d1(grp_decrypt_fu_242_word_0_d1); grp_decrypt_fu_242->word_0_q1(word_0_q1); grp_decrypt_fu_242->word_1_address0(grp_decrypt_fu_242_word_1_address0); grp_decrypt_fu_242->word_1_ce0(grp_decrypt_fu_242_word_1_ce0); grp_decrypt_fu_242->word_1_we0(grp_decrypt_fu_242_word_1_we0); grp_decrypt_fu_242->word_1_d0(grp_decrypt_fu_242_word_1_d0); grp_decrypt_fu_242->word_1_q0(word_1_q0); grp_decrypt_fu_242->word_1_address1(grp_decrypt_fu_242_word_1_address1); grp_decrypt_fu_242->word_1_ce1(grp_decrypt_fu_242_word_1_ce1); grp_decrypt_fu_242->word_1_we1(grp_decrypt_fu_242_word_1_we1); grp_decrypt_fu_242->word_1_d1(grp_decrypt_fu_242_word_1_d1); grp_decrypt_fu_242->word_1_q1(word_1_q1); grp_decrypt_fu_242->main_result_i(main_result); grp_decrypt_fu_242->main_result_o(grp_decrypt_fu_242_main_result_o); grp_decrypt_fu_242->main_result_o_ap_vld(grp_decrypt_fu_242_main_result_o_ap_vld); grp_encrypt_fu_264 = new encrypt("grp_encrypt_fu_264"); grp_encrypt_fu_264->ap_clk(ap_clk); grp_encrypt_fu_264->ap_rst(ap_rst); grp_encrypt_fu_264->ap_start(grp_encrypt_fu_264_ap_start); grp_encrypt_fu_264->ap_done(grp_encrypt_fu_264_ap_done); grp_encrypt_fu_264->ap_idle(grp_encrypt_fu_264_ap_idle); grp_encrypt_fu_264->ap_ready(grp_encrypt_fu_264_ap_ready); grp_encrypt_fu_264->statemt_0_address0(grp_encrypt_fu_264_statemt_0_address0); grp_encrypt_fu_264->statemt_0_ce0(grp_encrypt_fu_264_statemt_0_ce0); grp_encrypt_fu_264->statemt_0_we0(grp_encrypt_fu_264_statemt_0_we0); grp_encrypt_fu_264->statemt_0_d0(grp_encrypt_fu_264_statemt_0_d0); grp_encrypt_fu_264->statemt_0_q0(statemt_0_q0); grp_encrypt_fu_264->statemt_0_address1(grp_encrypt_fu_264_statemt_0_address1); grp_encrypt_fu_264->statemt_0_ce1(grp_encrypt_fu_264_statemt_0_ce1); grp_encrypt_fu_264->statemt_0_we1(grp_encrypt_fu_264_statemt_0_we1); grp_encrypt_fu_264->statemt_0_d1(grp_encrypt_fu_264_statemt_0_d1); grp_encrypt_fu_264->statemt_0_q1(statemt_0_q1); grp_encrypt_fu_264->statemt_1_address0(grp_encrypt_fu_264_statemt_1_address0); grp_encrypt_fu_264->statemt_1_ce0(grp_encrypt_fu_264_statemt_1_ce0); grp_encrypt_fu_264->statemt_1_we0(grp_encrypt_fu_264_statemt_1_we0); grp_encrypt_fu_264->statemt_1_d0(grp_encrypt_fu_264_statemt_1_d0); grp_encrypt_fu_264->statemt_1_q0(statemt_1_q0); grp_encrypt_fu_264->statemt_1_address1(grp_encrypt_fu_264_statemt_1_address1); grp_encrypt_fu_264->statemt_1_ce1(grp_encrypt_fu_264_statemt_1_ce1); grp_encrypt_fu_264->statemt_1_we1(grp_encrypt_fu_264_statemt_1_we1); grp_encrypt_fu_264->statemt_1_d1(grp_encrypt_fu_264_statemt_1_d1); grp_encrypt_fu_264->statemt_1_q1(statemt_1_q1); grp_encrypt_fu_264->key_0_address0(grp_encrypt_fu_264_key_0_address0); grp_encrypt_fu_264->key_0_ce0(grp_encrypt_fu_264_key_0_ce0); grp_encrypt_fu_264->key_0_q0(key_0_q0); grp_encrypt_fu_264->key_0_address1(grp_encrypt_fu_264_key_0_address1); grp_encrypt_fu_264->key_0_ce1(grp_encrypt_fu_264_key_0_ce1); grp_encrypt_fu_264->key_0_q1(key_0_q1); grp_encrypt_fu_264->round_val(grp_encrypt_fu_264_round_val); grp_encrypt_fu_264->round_val_ap_vld(grp_encrypt_fu_264_round_val_ap_vld); grp_encrypt_fu_264->word_0_address0(grp_encrypt_fu_264_word_0_address0); grp_encrypt_fu_264->word_0_ce0(grp_encrypt_fu_264_word_0_ce0); grp_encrypt_fu_264->word_0_we0(grp_encrypt_fu_264_word_0_we0); grp_encrypt_fu_264->word_0_d0(grp_encrypt_fu_264_word_0_d0); grp_encrypt_fu_264->word_0_q0(word_0_q0); grp_encrypt_fu_264->word_0_address1(grp_encrypt_fu_264_word_0_address1); grp_encrypt_fu_264->word_0_ce1(grp_encrypt_fu_264_word_0_ce1); grp_encrypt_fu_264->word_0_we1(grp_encrypt_fu_264_word_0_we1); grp_encrypt_fu_264->word_0_d1(grp_encrypt_fu_264_word_0_d1); grp_encrypt_fu_264->word_0_q1(word_0_q1); grp_encrypt_fu_264->word_1_address0(grp_encrypt_fu_264_word_1_address0); grp_encrypt_fu_264->word_1_ce0(grp_encrypt_fu_264_word_1_ce0); grp_encrypt_fu_264->word_1_we0(grp_encrypt_fu_264_word_1_we0); grp_encrypt_fu_264->word_1_d0(grp_encrypt_fu_264_word_1_d0); grp_encrypt_fu_264->word_1_q0(word_1_q0); grp_encrypt_fu_264->word_1_address1(grp_encrypt_fu_264_word_1_address1); grp_encrypt_fu_264->word_1_ce1(grp_encrypt_fu_264_word_1_ce1); grp_encrypt_fu_264->word_1_we1(grp_encrypt_fu_264_word_1_we1); grp_encrypt_fu_264->word_1_d1(grp_encrypt_fu_264_word_1_d1); grp_encrypt_fu_264->word_1_q1(word_1_q1); grp_encrypt_fu_264->main_result_i(main_result); grp_encrypt_fu_264->main_result_o(grp_encrypt_fu_264_main_result_o); grp_encrypt_fu_264->main_result_o_ap_vld(grp_encrypt_fu_264_main_result_o_ap_vld); SC_METHOD(thread_ap_clk_no_reset_); dont_initialize(); sensitive << ( ap_clk.pos() ); SC_METHOD(thread_ap_CS_fsm_state1); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state10); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state11); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state12); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state2); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state3); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state4); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state5); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state6); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state7); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state8); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_CS_fsm_state9); sensitive << ( ap_CS_fsm ); SC_METHOD(thread_ap_done); sensitive << ( grp_decrypt_fu_242_ap_done ); sensitive << ( ap_CS_fsm_state12 ); SC_METHOD(thread_ap_idle); sensitive << ( ap_start ); sensitive << ( ap_CS_fsm_state1 ); SC_METHOD(thread_ap_ready); sensitive << ( grp_decrypt_fu_242_ap_done ); sensitive << ( ap_CS_fsm_state12 ); SC_METHOD(thread_ap_return); sensitive << ( grp_decrypt_fu_242_ap_done ); sensitive << ( ap_CS_fsm_state12 ); SC_METHOD(thread_grp_decrypt_fu_242_ap_start); sensitive << ( grp_decrypt_fu_242_ap_start_reg ); SC_METHOD(thread_grp_encrypt_fu_264_ap_start); sensitive << ( grp_encrypt_fu_264_ap_start_reg ); SC_METHOD(thread_key_0_address0); sensitive << ( ap_CS_fsm_state1 ); sensitive << ( grp_decrypt_fu_242_key_0_address0 ); sensitive << ( grp_encrypt_fu_264_key_0_address0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state2 ); sensitive << ( ap_CS_fsm_state3 ); sensitive << ( ap_CS_fsm_state4 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_key_0_address1); sensitive << ( ap_CS_fsm_state1 ); sensitive << ( grp_decrypt_fu_242_key_0_address1 ); sensitive << ( grp_encrypt_fu_264_key_0_address1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state2 ); sensitive << ( ap_CS_fsm_state3 ); sensitive << ( ap_CS_fsm_state4 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_key_0_ce0); sensitive << ( ap_start ); sensitive << ( ap_CS_fsm_state1 ); sensitive << ( grp_decrypt_fu_242_key_0_ce0 ); sensitive << ( grp_encrypt_fu_264_key_0_ce0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state2 ); sensitive << ( ap_CS_fsm_state3 ); sensitive << ( ap_CS_fsm_state4 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_key_0_ce1); sensitive << ( ap_start ); sensitive << ( ap_CS_fsm_state1 ); sensitive << ( grp_decrypt_fu_242_key_0_ce1 ); sensitive << ( grp_encrypt_fu_264_key_0_ce1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state2 ); sensitive << ( ap_CS_fsm_state3 ); sensitive << ( ap_CS_fsm_state4 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_key_0_d0); sensitive << ( ap_CS_fsm_state1 ); sensitive << ( ap_CS_fsm_state2 ); sensitive << ( ap_CS_fsm_state3 ); sensitive << ( ap_CS_fsm_state4 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_key_0_d1); sensitive << ( ap_CS_fsm_state1 ); sensitive << ( ap_CS_fsm_state2 ); sensitive << ( ap_CS_fsm_state3 ); sensitive << ( ap_CS_fsm_state4 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_key_0_we0); sensitive << ( ap_start ); sensitive << ( ap_CS_fsm_state1 ); sensitive << ( ap_CS_fsm_state2 ); sensitive << ( ap_CS_fsm_state3 ); sensitive << ( ap_CS_fsm_state4 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_key_0_we1); sensitive << ( ap_start ); sensitive << ( ap_CS_fsm_state1 ); sensitive << ( ap_CS_fsm_state2 ); sensitive << ( ap_CS_fsm_state3 ); sensitive << ( ap_CS_fsm_state4 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_0_address0); sensitive << ( grp_decrypt_fu_242_statemt_0_address0 ); sensitive << ( grp_encrypt_fu_264_statemt_0_address0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_0_address1); sensitive << ( grp_decrypt_fu_242_statemt_0_address1 ); sensitive << ( grp_encrypt_fu_264_statemt_0_address1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_0_ce0); sensitive << ( grp_decrypt_fu_242_statemt_0_ce0 ); sensitive << ( grp_encrypt_fu_264_statemt_0_ce0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_0_ce1); sensitive << ( grp_decrypt_fu_242_statemt_0_ce1 ); sensitive << ( grp_encrypt_fu_264_statemt_0_ce1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_0_d0); sensitive << ( grp_decrypt_fu_242_statemt_0_d0 ); sensitive << ( grp_encrypt_fu_264_statemt_0_d0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_0_d1); sensitive << ( grp_decrypt_fu_242_statemt_0_d1 ); sensitive << ( grp_encrypt_fu_264_statemt_0_d1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_0_we0); sensitive << ( grp_decrypt_fu_242_statemt_0_we0 ); sensitive << ( grp_encrypt_fu_264_statemt_0_we0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_0_we1); sensitive << ( grp_decrypt_fu_242_statemt_0_we1 ); sensitive << ( grp_encrypt_fu_264_statemt_0_we1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_1_address0); sensitive << ( grp_decrypt_fu_242_statemt_1_address0 ); sensitive << ( grp_encrypt_fu_264_statemt_1_address0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_1_address1); sensitive << ( grp_decrypt_fu_242_statemt_1_address1 ); sensitive << ( grp_encrypt_fu_264_statemt_1_address1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_1_ce0); sensitive << ( grp_decrypt_fu_242_statemt_1_ce0 ); sensitive << ( grp_encrypt_fu_264_statemt_1_ce0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_1_ce1); sensitive << ( grp_decrypt_fu_242_statemt_1_ce1 ); sensitive << ( grp_encrypt_fu_264_statemt_1_ce1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_1_d0); sensitive << ( grp_decrypt_fu_242_statemt_1_d0 ); sensitive << ( grp_encrypt_fu_264_statemt_1_d0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_1_d1); sensitive << ( grp_decrypt_fu_242_statemt_1_d1 ); sensitive << ( grp_encrypt_fu_264_statemt_1_d1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_1_we0); sensitive << ( grp_decrypt_fu_242_statemt_1_we0 ); sensitive << ( grp_encrypt_fu_264_statemt_1_we0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_statemt_1_we1); sensitive << ( grp_decrypt_fu_242_statemt_1_we1 ); sensitive << ( grp_encrypt_fu_264_statemt_1_we1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); sensitive << ( ap_CS_fsm_state5 ); sensitive << ( ap_CS_fsm_state6 ); sensitive << ( ap_CS_fsm_state7 ); sensitive << ( ap_CS_fsm_state8 ); SC_METHOD(thread_word_0_address0); sensitive << ( grp_decrypt_fu_242_word_0_address0 ); sensitive << ( grp_encrypt_fu_264_word_0_address0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_0_address1); sensitive << ( grp_decrypt_fu_242_word_0_address1 ); sensitive << ( grp_encrypt_fu_264_word_0_address1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_0_ce0); sensitive << ( grp_decrypt_fu_242_word_0_ce0 ); sensitive << ( grp_encrypt_fu_264_word_0_ce0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_0_ce1); sensitive << ( grp_decrypt_fu_242_word_0_ce1 ); sensitive << ( grp_encrypt_fu_264_word_0_ce1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_0_d0); sensitive << ( grp_decrypt_fu_242_word_0_d0 ); sensitive << ( grp_encrypt_fu_264_word_0_d0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_0_d1); sensitive << ( grp_decrypt_fu_242_word_0_d1 ); sensitive << ( grp_encrypt_fu_264_word_0_d1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_0_we0); sensitive << ( grp_decrypt_fu_242_word_0_we0 ); sensitive << ( grp_encrypt_fu_264_word_0_we0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_0_we1); sensitive << ( grp_decrypt_fu_242_word_0_we1 ); sensitive << ( grp_encrypt_fu_264_word_0_we1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_1_address0); sensitive << ( grp_decrypt_fu_242_word_1_address0 ); sensitive << ( grp_encrypt_fu_264_word_1_address0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_1_address1); sensitive << ( grp_decrypt_fu_242_word_1_address1 ); sensitive << ( grp_encrypt_fu_264_word_1_address1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_1_ce0); sensitive << ( grp_decrypt_fu_242_word_1_ce0 ); sensitive << ( grp_encrypt_fu_264_word_1_ce0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_1_ce1); sensitive << ( grp_decrypt_fu_242_word_1_ce1 ); sensitive << ( grp_encrypt_fu_264_word_1_ce1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_1_d0); sensitive << ( grp_decrypt_fu_242_word_1_d0 ); sensitive << ( grp_encrypt_fu_264_word_1_d0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_1_d1); sensitive << ( grp_decrypt_fu_242_word_1_d1 ); sensitive << ( grp_encrypt_fu_264_word_1_d1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_1_we0); sensitive << ( grp_decrypt_fu_242_word_1_we0 ); sensitive << ( grp_encrypt_fu_264_word_1_we0 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_word_1_we1); sensitive << ( grp_decrypt_fu_242_word_1_we1 ); sensitive << ( grp_encrypt_fu_264_word_1_we1 ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_METHOD(thread_ap_NS_fsm); sensitive << ( ap_start ); sensitive << ( ap_CS_fsm ); sensitive << ( ap_CS_fsm_state1 ); sensitive << ( grp_decrypt_fu_242_ap_done ); sensitive << ( grp_encrypt_fu_264_ap_done ); sensitive << ( ap_CS_fsm_state12 ); sensitive << ( ap_CS_fsm_state10 ); SC_THREAD(thread_hdltv_gen); sensitive << ( ap_clk.pos() ); ap_CS_fsm = "000000000001"; main_result = "00000000000000000000000000000000"; grp_decrypt_fu_242_ap_start_reg = SC_LOGIC_0; grp_encrypt_fu_264_ap_start_reg = SC_LOGIC_0; static int apTFileNum = 0; stringstream apTFilenSS; apTFilenSS << "aes_main_sc_trace_" << apTFileNum ++; string apTFn = apTFilenSS.str(); mVcdFile = sc_create_vcd_trace_file(apTFn.c_str()); mVcdFile->set_time_unit(1, SC_PS); if (1) { #ifdef __HLS_TRACE_LEVEL_PORT__ sc_trace(mVcdFile, ap_clk, "(port)ap_clk"); sc_trace(mVcdFile, ap_rst, "(port)ap_rst"); sc_trace(mVcdFile, ap_start, "(port)ap_start"); sc_trace(mVcdFile, ap_done, "(port)ap_done"); sc_trace(mVcdFile, ap_idle, "(port)ap_idle"); sc_trace(mVcdFile, ap_ready, "(port)ap_ready"); sc_trace(mVcdFile, ap_return, "(port)ap_return"); #endif #ifdef __HLS_TRACE_LEVEL_INT__ sc_trace(mVcdFile, ap_CS_fsm, "ap_CS_fsm"); sc_trace(mVcdFile, ap_CS_fsm_state1, "ap_CS_fsm_state1"); sc_trace(mVcdFile, word_0_address0, "word_0_address0"); sc_trace(mVcdFile, word_0_ce0, "word_0_ce0"); sc_trace(mVcdFile, word_0_we0, "word_0_we0"); sc_trace(mVcdFile, word_0_d0, "word_0_d0"); sc_trace(mVcdFile, word_0_q0, "word_0_q0"); sc_trace(mVcdFile, word_0_address1, "word_0_address1"); sc_trace(mVcdFile, word_0_ce1, "word_0_ce1"); sc_trace(mVcdFile, word_0_we1, "word_0_we1"); sc_trace(mVcdFile, word_0_d1, "word_0_d1"); sc_trace(mVcdFile, word_0_q1, "word_0_q1"); sc_trace(mVcdFile, word_1_address0, "word_1_address0"); sc_trace(mVcdFile, word_1_ce0, "word_1_ce0"); sc_trace(mVcdFile, word_1_we0, "word_1_we0"); sc_trace(mVcdFile, word_1_d0, "word_1_d0"); sc_trace(mVcdFile, word_1_q0, "word_1_q0"); sc_trace(mVcdFile, word_1_address1, "word_1_address1"); sc_trace(mVcdFile, word_1_ce1, "word_1_ce1"); sc_trace(mVcdFile, word_1_we1, "word_1_we1"); sc_trace(mVcdFile, word_1_d1, "word_1_d1"); sc_trace(mVcdFile, word_1_q1, "word_1_q1"); sc_trace(mVcdFile, main_result, "main_result"); sc_trace(mVcdFile, statemt_0_address0, "statemt_0_address0"); sc_trace(mVcdFile, statemt_0_ce0, "statemt_0_ce0"); sc_trace(mVcdFile, statemt_0_we0, "statemt_0_we0"); sc_trace(mVcdFile, statemt_0_d0, "statemt_0_d0"); sc_trace(mVcdFile, statemt_0_q0, "statemt_0_q0"); sc_trace(mVcdFile, statemt_0_address1, "statemt_0_address1"); sc_trace(mVcdFile, statemt_0_ce1, "statemt_0_ce1"); sc_trace(mVcdFile, statemt_0_we1, "statemt_0_we1"); sc_trace(mVcdFile, statemt_0_d1, "statemt_0_d1"); sc_trace(mVcdFile, statemt_0_q1, "statemt_0_q1"); sc_trace(mVcdFile, statemt_1_address0, "statemt_1_address0"); sc_trace(mVcdFile, statemt_1_ce0, "statemt_1_ce0"); sc_trace(mVcdFile, statemt_1_we0, "statemt_1_we0"); sc_trace(mVcdFile, statemt_1_d0, "statemt_1_d0"); sc_trace(mVcdFile, statemt_1_q0, "statemt_1_q0"); sc_trace(mVcdFile, statemt_1_address1, "statemt_1_address1"); sc_trace(mVcdFile, statemt_1_ce1, "statemt_1_ce1"); sc_trace(mVcdFile, statemt_1_we1, "statemt_1_we1"); sc_trace(mVcdFile, statemt_1_d1, "statemt_1_d1"); sc_trace(mVcdFile, statemt_1_q1, "statemt_1_q1"); sc_trace(mVcdFile, key_0_address0, "key_0_address0"); sc_trace(mVcdFile, key_0_ce0, "key_0_ce0"); sc_trace(mVcdFile, key_0_we0, "key_0_we0"); sc_trace(mVcdFile, key_0_d0, "key_0_d0"); sc_trace(mVcdFile, key_0_q0, "key_0_q0"); sc_trace(mVcdFile, key_0_address1, "key_0_address1"); sc_trace(mVcdFile, key_0_ce1, "key_0_ce1"); sc_trace(mVcdFile, key_0_we1, "key_0_we1"); sc_trace(mVcdFile, key_0_d1, "key_0_d1"); sc_trace(mVcdFile, key_0_q1, "key_0_q1"); sc_trace(mVcdFile, grp_decrypt_fu_242_ap_start, "grp_decrypt_fu_242_ap_start"); sc_trace(mVcdFile, grp_decrypt_fu_242_ap_done, "grp_decrypt_fu_242_ap_done"); sc_trace(mVcdFile, grp_decrypt_fu_242_ap_idle, "grp_decrypt_fu_242_ap_idle"); sc_trace(mVcdFile, grp_decrypt_fu_242_ap_ready, "grp_decrypt_fu_242_ap_ready"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_0_address0, "grp_decrypt_fu_242_statemt_0_address0"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_0_ce0, "grp_decrypt_fu_242_statemt_0_ce0"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_0_we0, "grp_decrypt_fu_242_statemt_0_we0"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_0_d0, "grp_decrypt_fu_242_statemt_0_d0"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_0_address1, "grp_decrypt_fu_242_statemt_0_address1"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_0_ce1, "grp_decrypt_fu_242_statemt_0_ce1"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_0_we1, "grp_decrypt_fu_242_statemt_0_we1"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_0_d1, "grp_decrypt_fu_242_statemt_0_d1"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_1_address0, "grp_decrypt_fu_242_statemt_1_address0"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_1_ce0, "grp_decrypt_fu_242_statemt_1_ce0"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_1_we0, "grp_decrypt_fu_242_statemt_1_we0"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_1_d0, "grp_decrypt_fu_242_statemt_1_d0"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_1_address1, "grp_decrypt_fu_242_statemt_1_address1"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_1_ce1, "grp_decrypt_fu_242_statemt_1_ce1"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_1_we1, "grp_decrypt_fu_242_statemt_1_we1"); sc_trace(mVcdFile, grp_decrypt_fu_242_statemt_1_d1, "grp_decrypt_fu_242_statemt_1_d1"); sc_trace(mVcdFile, grp_decrypt_fu_242_key_0_address0, "grp_decrypt_fu_242_key_0_address0"); sc_trace(mVcdFile, grp_decrypt_fu_242_key_0_ce0, "grp_decrypt_fu_242_key_0_ce0"); sc_trace(mVcdFile, grp_decrypt_fu_242_key_0_address1, "grp_decrypt_fu_242_key_0_address1"); sc_trace(mVcdFile, grp_decrypt_fu_242_key_0_ce1, "grp_decrypt_fu_242_key_0_ce1"); sc_trace(mVcdFile, grp_decrypt_fu_242_round_val, "grp_decrypt_fu_242_round_val"); sc_trace(mVcdFile, grp_decrypt_fu_242_round_val_ap_vld, "grp_decrypt_fu_242_round_val_ap_vld"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_0_address0, "grp_decrypt_fu_242_word_0_address0"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_0_ce0, "grp_decrypt_fu_242_word_0_ce0"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_0_we0, "grp_decrypt_fu_242_word_0_we0"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_0_d0, "grp_decrypt_fu_242_word_0_d0"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_0_address1, "grp_decrypt_fu_242_word_0_address1"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_0_ce1, "grp_decrypt_fu_242_word_0_ce1"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_0_we1, "grp_decrypt_fu_242_word_0_we1"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_0_d1, "grp_decrypt_fu_242_word_0_d1"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_1_address0, "grp_decrypt_fu_242_word_1_address0"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_1_ce0, "grp_decrypt_fu_242_word_1_ce0"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_1_we0, "grp_decrypt_fu_242_word_1_we0"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_1_d0, "grp_decrypt_fu_242_word_1_d0"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_1_address1, "grp_decrypt_fu_242_word_1_address1"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_1_ce1, "grp_decrypt_fu_242_word_1_ce1"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_1_we1, "grp_decrypt_fu_242_word_1_we1"); sc_trace(mVcdFile, grp_decrypt_fu_242_word_1_d1, "grp_decrypt_fu_242_word_1_d1"); sc_trace(mVcdFile, grp_decrypt_fu_242_main_result_o, "grp_decrypt_fu_242_main_result_o"); sc_trace(mVcdFile, grp_decrypt_fu_242_main_result_o_ap_vld, "grp_decrypt_fu_242_main_result_o_ap_vld"); sc_trace(mVcdFile, grp_encrypt_fu_264_ap_start, "grp_encrypt_fu_264_ap_start"); sc_trace(mVcdFile, grp_encrypt_fu_264_ap_done, "grp_encrypt_fu_264_ap_done"); sc_trace(mVcdFile, grp_encrypt_fu_264_ap_idle, "grp_encrypt_fu_264_ap_idle"); sc_trace(mVcdFile, grp_encrypt_fu_264_ap_ready, "grp_encrypt_fu_264_ap_ready"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_0_address0, "grp_encrypt_fu_264_statemt_0_address0"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_0_ce0, "grp_encrypt_fu_264_statemt_0_ce0"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_0_we0, "grp_encrypt_fu_264_statemt_0_we0"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_0_d0, "grp_encrypt_fu_264_statemt_0_d0"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_0_address1, "grp_encrypt_fu_264_statemt_0_address1"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_0_ce1, "grp_encrypt_fu_264_statemt_0_ce1"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_0_we1, "grp_encrypt_fu_264_statemt_0_we1"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_0_d1, "grp_encrypt_fu_264_statemt_0_d1"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_1_address0, "grp_encrypt_fu_264_statemt_1_address0"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_1_ce0, "grp_encrypt_fu_264_statemt_1_ce0"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_1_we0, "grp_encrypt_fu_264_statemt_1_we0"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_1_d0, "grp_encrypt_fu_264_statemt_1_d0"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_1_address1, "grp_encrypt_fu_264_statemt_1_address1"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_1_ce1, "grp_encrypt_fu_264_statemt_1_ce1"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_1_we1, "grp_encrypt_fu_264_statemt_1_we1"); sc_trace(mVcdFile, grp_encrypt_fu_264_statemt_1_d1, "grp_encrypt_fu_264_statemt_1_d1"); sc_trace(mVcdFile, grp_encrypt_fu_264_key_0_address0, "grp_encrypt_fu_264_key_0_address0"); sc_trace(mVcdFile, grp_encrypt_fu_264_key_0_ce0, "grp_encrypt_fu_264_key_0_ce0"); sc_trace(mVcdFile, grp_encrypt_fu_264_key_0_address1, "grp_encrypt_fu_264_key_0_address1"); sc_trace(mVcdFile, grp_encrypt_fu_264_key_0_ce1, "grp_encrypt_fu_264_key_0_ce1"); sc_trace(mVcdFile, grp_encrypt_fu_264_round_val, "grp_encrypt_fu_264_round_val"); sc_trace(mVcdFile, grp_encrypt_fu_264_round_val_ap_vld, "grp_encrypt_fu_264_round_val_ap_vld"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_0_address0, "grp_encrypt_fu_264_word_0_address0"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_0_ce0, "grp_encrypt_fu_264_word_0_ce0"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_0_we0, "grp_encrypt_fu_264_word_0_we0"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_0_d0, "grp_encrypt_fu_264_word_0_d0"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_0_address1, "grp_encrypt_fu_264_word_0_address1"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_0_ce1, "grp_encrypt_fu_264_word_0_ce1"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_0_we1, "grp_encrypt_fu_264_word_0_we1"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_0_d1, "grp_encrypt_fu_264_word_0_d1"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_1_address0, "grp_encrypt_fu_264_word_1_address0"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_1_ce0, "grp_encrypt_fu_264_word_1_ce0"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_1_we0, "grp_encrypt_fu_264_word_1_we0"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_1_d0, "grp_encrypt_fu_264_word_1_d0"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_1_address1, "grp_encrypt_fu_264_word_1_address1"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_1_ce1, "grp_encrypt_fu_264_word_1_ce1"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_1_we1, "grp_encrypt_fu_264_word_1_we1"); sc_trace(mVcdFile, grp_encrypt_fu_264_word_1_d1, "grp_encrypt_fu_264_word_1_d1"); sc_trace(mVcdFile, grp_encrypt_fu_264_main_result_o, "grp_encrypt_fu_264_main_result_o"); sc_trace(mVcdFile, grp_encrypt_fu_264_main_result_o_ap_vld, "grp_encrypt_fu_264_main_result_o_ap_vld"); sc_trace(mVcdFile, grp_decrypt_fu_242_ap_start_reg, "grp_decrypt_fu_242_ap_start_reg"); sc_trace(mVcdFile, ap_CS_fsm_state11, "ap_CS_fsm_state11"); sc_trace(mVcdFile, ap_CS_fsm_state12, "ap_CS_fsm_state12"); sc_trace(mVcdFile, grp_encrypt_fu_264_ap_start_reg, "grp_encrypt_fu_264_ap_start_reg"); sc_trace(mVcdFile, ap_CS_fsm_state9, "ap_CS_fsm_state9"); sc_trace(mVcdFile, ap_CS_fsm_state10, "ap_CS_fsm_state10"); sc_trace(mVcdFile, ap_CS_fsm_state2, "ap_CS_fsm_state2"); sc_trace(mVcdFile, ap_CS_fsm_state3, "ap_CS_fsm_state3"); sc_trace(mVcdFile, ap_CS_fsm_state4, "ap_CS_fsm_state4"); sc_trace(mVcdFile, ap_CS_fsm_state5, "ap_CS_fsm_state5"); sc_trace(mVcdFile, ap_CS_fsm_state6, "ap_CS_fsm_state6"); sc_trace(mVcdFile, ap_CS_fsm_state7, "ap_CS_fsm_state7"); sc_trace(mVcdFile, ap_CS_fsm_state8, "ap_CS_fsm_state8"); sc_trace(mVcdFile, ap_NS_fsm, "ap_NS_fsm"); #endif } mHdltvinHandle.open("aes_main.hdltvin.dat"); mHdltvoutHandle.open("aes_main.hdltvout.dat"); } aes_main::~aes_main() { if (mVcdFile) sc_close_vcd_trace_file(mVcdFile); mHdltvinHandle << "] " << endl; mHdltvoutHandle << "] " << endl; mHdltvinHandle.close(); mHdltvoutHandle.close(); delete word_0_U; delete word_1_U; delete statemt_0_U; delete statemt_1_U; delete key_0_U; delete grp_decrypt_fu_242; delete grp_encrypt_fu_264; } void aes_main::thread_ap_clk_no_reset_() { if ( ap_rst.read() == ap_const_logic_1) { ap_CS_fsm = ap_ST_fsm_state1; } else { ap_CS_fsm = ap_NS_fsm.read(); } if ( ap_rst.read() == ap_const_logic_1) { grp_decrypt_fu_242_ap_start_reg = ap_const_logic_0; } else { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state11.read())) { grp_decrypt_fu_242_ap_start_reg = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, grp_decrypt_fu_242_ap_ready.read())) { grp_decrypt_fu_242_ap_start_reg = ap_const_logic_0; } } if ( ap_rst.read() == ap_const_logic_1) { grp_encrypt_fu_264_ap_start_reg = ap_const_logic_0; } else { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state9.read())) { grp_encrypt_fu_264_ap_start_reg = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, grp_encrypt_fu_264_ap_ready.read())) { grp_encrypt_fu_264_ap_start_reg = ap_const_logic_0; } } if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read()) && esl_seteq<1,1,1>(ap_const_logic_1, grp_encrypt_fu_264_main_result_o_ap_vld.read()))) { main_result = grp_encrypt_fu_264_main_result_o.read(); } else if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read()) && esl_seteq<1,1,1>(ap_const_logic_1, grp_decrypt_fu_242_main_result_o_ap_vld.read()))) { main_result = grp_decrypt_fu_242_main_result_o.read(); } } void aes_main::thread_ap_CS_fsm_state1() { ap_CS_fsm_state1 = ap_CS_fsm.read()[0]; } void aes_main::thread_ap_CS_fsm_state10() { ap_CS_fsm_state10 = ap_CS_fsm.read()[9]; } void aes_main::thread_ap_CS_fsm_state11() { ap_CS_fsm_state11 = ap_CS_fsm.read()[10]; } void aes_main::thread_ap_CS_fsm_state12() { ap_CS_fsm_state12 = ap_CS_fsm.read()[11]; } void aes_main::thread_ap_CS_fsm_state2() { ap_CS_fsm_state2 = ap_CS_fsm.read()[1]; } void aes_main::thread_ap_CS_fsm_state3() { ap_CS_fsm_state3 = ap_CS_fsm.read()[2]; } void aes_main::thread_ap_CS_fsm_state4() { ap_CS_fsm_state4 = ap_CS_fsm.read()[3]; } void aes_main::thread_ap_CS_fsm_state5() { ap_CS_fsm_state5 = ap_CS_fsm.read()[4]; } void aes_main::thread_ap_CS_fsm_state6() { ap_CS_fsm_state6 = ap_CS_fsm.read()[5]; } void aes_main::thread_ap_CS_fsm_state7() { ap_CS_fsm_state7 = ap_CS_fsm.read()[6]; } void aes_main::thread_ap_CS_fsm_state8() { ap_CS_fsm_state8 = ap_CS_fsm.read()[7]; } void aes_main::thread_ap_CS_fsm_state9() { ap_CS_fsm_state9 = ap_CS_fsm.read()[8]; } void aes_main::thread_ap_done() { if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read()) && esl_seteq<1,1,1>(grp_decrypt_fu_242_ap_done.read(), ap_const_logic_1))) { ap_done = ap_const_logic_1; } else { ap_done = ap_const_logic_0; } } void aes_main::thread_ap_idle() { if ((esl_seteq<1,1,1>(ap_const_logic_0, ap_start.read()) && esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state1.read()))) { ap_idle = ap_const_logic_1; } else { ap_idle = ap_const_logic_0; } } void aes_main::thread_ap_ready() { if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read()) && esl_seteq<1,1,1>(grp_decrypt_fu_242_ap_done.read(), ap_const_logic_1))) { ap_ready = ap_const_logic_1; } else { ap_ready = ap_const_logic_0; } } void aes_main::thread_ap_return() { ap_return = ap_const_lv32_0; } void aes_main::thread_grp_decrypt_fu_242_ap_start() { grp_decrypt_fu_242_ap_start = grp_decrypt_fu_242_ap_start_reg.read(); } void aes_main::thread_grp_encrypt_fu_264_ap_start() { grp_encrypt_fu_264_ap_start = grp_encrypt_fu_264_ap_start_reg.read(); } void aes_main::thread_key_0_address0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { key_0_address0 = ap_const_lv4_E; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { key_0_address0 = ap_const_lv4_C; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { key_0_address0 = ap_const_lv4_A; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { key_0_address0 = ap_const_lv4_8; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state4.read())) { key_0_address0 = ap_const_lv4_6; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state3.read())) { key_0_address0 = ap_const_lv4_4; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state2.read())) { key_0_address0 = ap_const_lv4_2; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state1.read())) { key_0_address0 = ap_const_lv4_0; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { key_0_address0 = grp_encrypt_fu_264_key_0_address0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { key_0_address0 = grp_decrypt_fu_242_key_0_address0.read(); } else { key_0_address0 = (sc_lv<4>) ("XXXX"); } } void aes_main::thread_key_0_address1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { key_0_address1 = ap_const_lv4_F; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { key_0_address1 = ap_const_lv4_D; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { key_0_address1 = ap_const_lv4_B; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { key_0_address1 = ap_const_lv4_9; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state4.read())) { key_0_address1 = ap_const_lv4_7; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state3.read())) { key_0_address1 = ap_const_lv4_5; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state2.read())) { key_0_address1 = ap_const_lv4_3; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state1.read())) { key_0_address1 = ap_const_lv4_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { key_0_address1 = grp_encrypt_fu_264_key_0_address1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { key_0_address1 = grp_decrypt_fu_242_key_0_address1.read(); } else { key_0_address1 = (sc_lv<4>) ("XXXX"); } } void aes_main::thread_key_0_ce0() { if (((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state1.read()) && esl_seteq<1,1,1>(ap_start.read(), ap_const_logic_1)) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state2.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state3.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state4.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { key_0_ce0 = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { key_0_ce0 = grp_encrypt_fu_264_key_0_ce0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { key_0_ce0 = grp_decrypt_fu_242_key_0_ce0.read(); } else { key_0_ce0 = ap_const_logic_0; } } void aes_main::thread_key_0_ce1() { if (((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state1.read()) && esl_seteq<1,1,1>(ap_start.read(), ap_const_logic_1)) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state2.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state3.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state4.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { key_0_ce1 = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { key_0_ce1 = grp_encrypt_fu_264_key_0_ce1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { key_0_ce1 = grp_decrypt_fu_242_key_0_ce1.read(); } else { key_0_ce1 = ap_const_logic_0; } } void aes_main::thread_key_0_d0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { key_0_d0 = ap_const_lv32_4F; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { key_0_d0 = ap_const_lv32_9; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { key_0_d0 = ap_const_lv32_AB; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state4.read())) { key_0_d0 = ap_const_lv32_D2; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state3.read())) { key_0_d0 = ap_const_lv32_28; } else if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state2.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()))) { key_0_d0 = ap_const_lv32_15; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state1.read())) { key_0_d0 = ap_const_lv32_2B; } else { key_0_d0 = (sc_lv<32>) ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } } void aes_main::thread_key_0_d1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { key_0_d1 = ap_const_lv32_3C; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { key_0_d1 = ap_const_lv32_CF; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { key_0_d1 = ap_const_lv32_88; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { key_0_d1 = ap_const_lv32_F7; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state4.read())) { key_0_d1 = ap_const_lv32_A6; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state3.read())) { key_0_d1 = ap_const_lv32_AE; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state2.read())) { key_0_d1 = ap_const_lv32_16; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state1.read())) { key_0_d1 = ap_const_lv32_7E; } else { key_0_d1 = (sc_lv<32>) ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } } void aes_main::thread_key_0_we0() { if (((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state1.read()) && esl_seteq<1,1,1>(ap_start.read(), ap_const_logic_1)) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state2.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state3.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state4.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { key_0_we0 = ap_const_logic_1; } else { key_0_we0 = ap_const_logic_0; } } void aes_main::thread_key_0_we1() { if (((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state1.read()) && esl_seteq<1,1,1>(ap_start.read(), ap_const_logic_1)) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state2.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state3.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state4.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { key_0_we1 = ap_const_logic_1; } else { key_0_we1 = ap_const_logic_0; } } void aes_main::thread_statemt_0_address0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { statemt_0_address0 = ap_const_lv4_6; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { statemt_0_address0 = ap_const_lv4_4; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { statemt_0_address0 = ap_const_lv4_2; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { statemt_0_address0 = ap_const_lv4_0; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_0_address0 = grp_encrypt_fu_264_statemt_0_address0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_0_address0 = grp_decrypt_fu_242_statemt_0_address0.read(); } else { statemt_0_address0 = (sc_lv<4>) ("XXXX"); } } void aes_main::thread_statemt_0_address1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { statemt_0_address1 = ap_const_lv4_7; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { statemt_0_address1 = ap_const_lv4_5; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { statemt_0_address1 = ap_const_lv4_3; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { statemt_0_address1 = ap_const_lv4_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_0_address1 = grp_encrypt_fu_264_statemt_0_address1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_0_address1 = grp_decrypt_fu_242_statemt_0_address1.read(); } else { statemt_0_address1 = (sc_lv<4>) ("XXXX"); } } void aes_main::thread_statemt_0_ce0() { if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { statemt_0_ce0 = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_0_ce0 = grp_encrypt_fu_264_statemt_0_ce0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_0_ce0 = grp_decrypt_fu_242_statemt_0_ce0.read(); } else { statemt_0_ce0 = ap_const_logic_0; } } void aes_main::thread_statemt_0_ce1() { if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { statemt_0_ce1 = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_0_ce1 = grp_encrypt_fu_264_statemt_0_ce1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_0_ce1 = grp_decrypt_fu_242_statemt_0_ce1.read(); } else { statemt_0_ce1 = ap_const_logic_0; } } void aes_main::thread_statemt_0_d0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { statemt_0_d0 = ap_const_lv32_E0; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { statemt_0_d0 = ap_const_lv32_31; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { statemt_0_d0 = ap_const_lv32_88; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { statemt_0_d0 = ap_const_lv32_32; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_0_d0 = grp_encrypt_fu_264_statemt_0_d0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_0_d0 = grp_decrypt_fu_242_statemt_0_d0.read(); } else { statemt_0_d0 = (sc_lv<32>) ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } } void aes_main::thread_statemt_0_d1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { statemt_0_d1 = ap_const_lv32_7; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { statemt_0_d1 = ap_const_lv32_98; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { statemt_0_d1 = ap_const_lv32_30; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { statemt_0_d1 = ap_const_lv32_F6; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_0_d1 = grp_encrypt_fu_264_statemt_0_d1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_0_d1 = grp_decrypt_fu_242_statemt_0_d1.read(); } else { statemt_0_d1 = (sc_lv<32>) ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } } void aes_main::thread_statemt_0_we0() { if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { statemt_0_we0 = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_0_we0 = grp_encrypt_fu_264_statemt_0_we0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_0_we0 = grp_decrypt_fu_242_statemt_0_we0.read(); } else { statemt_0_we0 = ap_const_logic_0; } } void aes_main::thread_statemt_0_we1() { if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { statemt_0_we1 = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_0_we1 = grp_encrypt_fu_264_statemt_0_we1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_0_we1 = grp_decrypt_fu_242_statemt_0_we1.read(); } else { statemt_0_we1 = ap_const_logic_0; } } void aes_main::thread_statemt_1_address0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { statemt_1_address0 = ap_const_lv4_6; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { statemt_1_address0 = ap_const_lv4_4; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { statemt_1_address0 = ap_const_lv4_2; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { statemt_1_address0 = ap_const_lv4_0; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_1_address0 = grp_encrypt_fu_264_statemt_1_address0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_1_address0 = grp_decrypt_fu_242_statemt_1_address0.read(); } else { statemt_1_address0 = (sc_lv<4>) ("XXXX"); } } void aes_main::thread_statemt_1_address1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { statemt_1_address1 = ap_const_lv4_7; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { statemt_1_address1 = ap_const_lv4_5; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { statemt_1_address1 = ap_const_lv4_3; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { statemt_1_address1 = ap_const_lv4_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_1_address1 = grp_encrypt_fu_264_statemt_1_address1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_1_address1 = grp_decrypt_fu_242_statemt_1_address1.read(); } else { statemt_1_address1 = (sc_lv<4>) ("XXXX"); } } void aes_main::thread_statemt_1_ce0() { if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { statemt_1_ce0 = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_1_ce0 = grp_encrypt_fu_264_statemt_1_ce0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_1_ce0 = grp_decrypt_fu_242_statemt_1_ce0.read(); } else { statemt_1_ce0 = ap_const_logic_0; } } void aes_main::thread_statemt_1_ce1() { if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { statemt_1_ce1 = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_1_ce1 = grp_encrypt_fu_264_statemt_1_ce1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_1_ce1 = grp_decrypt_fu_242_statemt_1_ce1.read(); } else { statemt_1_ce1 = ap_const_logic_0; } } void aes_main::thread_statemt_1_d0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { statemt_1_d0 = ap_const_lv32_37; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { statemt_1_d0 = ap_const_lv32_31; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { statemt_1_d0 = ap_const_lv32_5A; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { statemt_1_d0 = ap_const_lv32_43; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_1_d0 = grp_encrypt_fu_264_statemt_1_d0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_1_d0 = grp_decrypt_fu_242_statemt_1_d0.read(); } else { statemt_1_d0 = (sc_lv<32>) ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } } void aes_main::thread_statemt_1_d1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read())) { statemt_1_d1 = ap_const_lv32_34; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read())) { statemt_1_d1 = ap_const_lv32_A2; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read())) { statemt_1_d1 = ap_const_lv32_8D; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read())) { statemt_1_d1 = ap_const_lv32_A8; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_1_d1 = grp_encrypt_fu_264_statemt_1_d1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_1_d1 = grp_decrypt_fu_242_statemt_1_d1.read(); } else { statemt_1_d1 = (sc_lv<32>) ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } } void aes_main::thread_statemt_1_we0() { if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { statemt_1_we0 = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_1_we0 = grp_encrypt_fu_264_statemt_1_we0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_1_we0 = grp_decrypt_fu_242_statemt_1_we0.read(); } else { statemt_1_we0 = ap_const_logic_0; } } void aes_main::thread_statemt_1_we1() { if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state5.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state6.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state7.read()) || esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state8.read()))) { statemt_1_we1 = ap_const_logic_1; } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { statemt_1_we1 = grp_encrypt_fu_264_statemt_1_we1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { statemt_1_we1 = grp_decrypt_fu_242_statemt_1_we1.read(); } else { statemt_1_we1 = ap_const_logic_0; } } void aes_main::thread_word_0_address0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_0_address0 = grp_encrypt_fu_264_word_0_address0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_0_address0 = grp_decrypt_fu_242_word_0_address0.read(); } else { word_0_address0 = "XXXXXXXX"; } } void aes_main::thread_word_0_address1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_0_address1 = grp_encrypt_fu_264_word_0_address1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_0_address1 = grp_decrypt_fu_242_word_0_address1.read(); } else { word_0_address1 = "XXXXXXXX"; } } void aes_main::thread_word_0_ce0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_0_ce0 = grp_encrypt_fu_264_word_0_ce0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_0_ce0 = grp_decrypt_fu_242_word_0_ce0.read(); } else { word_0_ce0 = ap_const_logic_0; } } void aes_main::thread_word_0_ce1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_0_ce1 = grp_encrypt_fu_264_word_0_ce1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_0_ce1 = grp_decrypt_fu_242_word_0_ce1.read(); } else { word_0_ce1 = ap_const_logic_0; } } void aes_main::thread_word_0_d0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_0_d0 = grp_encrypt_fu_264_word_0_d0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_0_d0 = grp_decrypt_fu_242_word_0_d0.read(); } else { word_0_d0 = (sc_lv<32>) ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } } void aes_main::thread_word_0_d1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_0_d1 = grp_encrypt_fu_264_word_0_d1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_0_d1 = grp_decrypt_fu_242_word_0_d1.read(); } else { word_0_d1 = (sc_lv<32>) ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } } void aes_main::thread_word_0_we0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_0_we0 = grp_encrypt_fu_264_word_0_we0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_0_we0 = grp_decrypt_fu_242_word_0_we0.read(); } else { word_0_we0 = ap_const_logic_0; } } void aes_main::thread_word_0_we1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_0_we1 = grp_encrypt_fu_264_word_0_we1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_0_we1 = grp_decrypt_fu_242_word_0_we1.read(); } else { word_0_we1 = ap_const_logic_0; } } void aes_main::thread_word_1_address0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_1_address0 = grp_encrypt_fu_264_word_1_address0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_1_address0 = grp_decrypt_fu_242_word_1_address0.read(); } else { word_1_address0 = "XXXXXXXX"; } } void aes_main::thread_word_1_address1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_1_address1 = grp_encrypt_fu_264_word_1_address1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_1_address1 = grp_decrypt_fu_242_word_1_address1.read(); } else { word_1_address1 = "XXXXXXXX"; } } void aes_main::thread_word_1_ce0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_1_ce0 = grp_encrypt_fu_264_word_1_ce0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_1_ce0 = grp_decrypt_fu_242_word_1_ce0.read(); } else { word_1_ce0 = ap_const_logic_0; } } void aes_main::thread_word_1_ce1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_1_ce1 = grp_encrypt_fu_264_word_1_ce1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_1_ce1 = grp_decrypt_fu_242_word_1_ce1.read(); } else { word_1_ce1 = ap_const_logic_0; } } void aes_main::thread_word_1_d0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_1_d0 = grp_encrypt_fu_264_word_1_d0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_1_d0 = grp_decrypt_fu_242_word_1_d0.read(); } else { word_1_d0 = (sc_lv<32>) ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } } void aes_main::thread_word_1_d1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_1_d1 = grp_encrypt_fu_264_word_1_d1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_1_d1 = grp_decrypt_fu_242_word_1_d1.read(); } else { word_1_d1 = (sc_lv<32>) ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } } void aes_main::thread_word_1_we0() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_1_we0 = grp_encrypt_fu_264_word_1_we0.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_1_we0 = grp_decrypt_fu_242_word_1_we0.read(); } else { word_1_we0 = ap_const_logic_0; } } void aes_main::thread_word_1_we1() { if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read())) { word_1_we1 = grp_encrypt_fu_264_word_1_we1.read(); } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read())) { word_1_we1 = grp_decrypt_fu_242_word_1_we1.read(); } else { word_1_we1 = ap_const_logic_0; } } void aes_main::thread_ap_NS_fsm() { switch (ap_CS_fsm.read().to_uint64()) { case 1 : if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state1.read()) && esl_seteq<1,1,1>(ap_start.read(), ap_const_logic_1))) { ap_NS_fsm = ap_ST_fsm_state2; } else { ap_NS_fsm = ap_ST_fsm_state1; } break; case 2 : ap_NS_fsm = ap_ST_fsm_state3; break; case 4 : ap_NS_fsm = ap_ST_fsm_state4; break; case 8 : ap_NS_fsm = ap_ST_fsm_state5; break; case 16 : ap_NS_fsm = ap_ST_fsm_state6; break; case 32 : ap_NS_fsm = ap_ST_fsm_state7; break; case 64 : ap_NS_fsm = ap_ST_fsm_state8; break; case 128 : ap_NS_fsm = ap_ST_fsm_state9; break; case 256 : ap_NS_fsm = ap_ST_fsm_state10; break; case 512 : if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state10.read()) && esl_seteq<1,1,1>(grp_encrypt_fu_264_ap_done.read(), ap_const_logic_1))) { ap_NS_fsm = ap_ST_fsm_state11; } else { ap_NS_fsm = ap_ST_fsm_state10; } break; case 1024 : ap_NS_fsm = ap_ST_fsm_state12; break; case 2048 : if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_CS_fsm_state12.read()) && esl_seteq<1,1,1>(grp_decrypt_fu_242_ap_done.read(), ap_const_logic_1))) { ap_NS_fsm = ap_ST_fsm_state1; } else { ap_NS_fsm = ap_ST_fsm_state12; } break; default : ap_NS_fsm = (sc_lv<12>) ("XXXXXXXXXXXX"); break; } } void aes_main::thread_hdltv_gen() { const char* dump_tv = std::getenv("AP_WRITE_TV"); if (!(dump_tv && string(dump_tv) == "on")) return; wait(); mHdltvinHandle << "[ " << endl; mHdltvoutHandle << "[ " << endl; int ap_cycleNo = 0; while (1) { wait(); const char* mComma = ap_cycleNo == 0 ? " " : ", " ; mHdltvinHandle << mComma << "{" << " \"ap_rst\" : \"" << ap_rst.read() << "\" "; mHdltvinHandle << " , " << " \"ap_start\" : \"" << ap_start.read() << "\" "; mHdltvoutHandle << mComma << "{" << " \"ap_done\" : \"" << ap_done.read() << "\" "; mHdltvoutHandle << " , " << " \"ap_idle\" : \"" << ap_idle.read() << "\" "; mHdltvoutHandle << " , " << " \"ap_ready\" : \"" << ap_ready.read() << "\" "; mHdltvoutHandle << " , " << " \"ap_return\" : \"" << ap_return.read() << "\" "; mHdltvinHandle << "}" << std::endl; mHdltvoutHandle << "}" << std::endl; ap_cycleNo++; } } }
/* * Copyright 2015 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #include "webrtc/base/filerotatingstream.h" #include <algorithm> #include <iostream> #include <string> #include "webrtc/base/checks.h" #include "webrtc/base/fileutils.h" #include "webrtc/base/pathutils.h" // Note: We use std::cerr for logging in the write paths of this stream to avoid // infinite loops when logging. namespace rtc { FileRotatingStream::FileRotatingStream(const std::string& dir_path, const std::string& file_prefix) : FileRotatingStream(dir_path, file_prefix, 0, 0, kRead) { } FileRotatingStream::FileRotatingStream(const std::string& dir_path, const std::string& file_prefix, size_t max_file_size, size_t num_files) : FileRotatingStream(dir_path, file_prefix, max_file_size, num_files, kWrite) { RTC_DCHECK_GT(max_file_size, 0u); RTC_DCHECK_GT(num_files, 1u); } FileRotatingStream::FileRotatingStream(const std::string& dir_path, const std::string& file_prefix, size_t max_file_size, size_t num_files, Mode mode) : dir_path_(dir_path), file_prefix_(file_prefix), mode_(mode), file_stream_(nullptr), max_file_size_(max_file_size), current_file_index_(0), rotation_index_(0), current_bytes_written_(0), disable_buffering_(false) { RTC_DCHECK(Filesystem::IsFolder(dir_path)); switch (mode) { case kWrite: { file_names_.clear(); for (size_t i = 0; i < num_files; ++i) { file_names_.push_back(GetFilePath(i, num_files)); } rotation_index_ = num_files - 1; break; } case kRead: { file_names_ = GetFilesWithPrefix(); std::sort(file_names_.begin(), file_names_.end()); if (file_names_.size() > 0) { // |file_names_| is sorted newest first, so read from the end. current_file_index_ = file_names_.size() - 1; } break; } } } FileRotatingStream::~FileRotatingStream() { } StreamState FileRotatingStream::GetState() const { if (mode_ == kRead && current_file_index_ < file_names_.size()) { return SS_OPEN; } if (!file_stream_) { return SS_CLOSED; } return file_stream_->GetState(); } StreamResult FileRotatingStream::Read(void* buffer, size_t buffer_len, size_t* read, int* error) { RTC_DCHECK(buffer); if (mode_ != kRead) { return SR_EOS; } if (current_file_index_ >= file_names_.size()) { return SR_EOS; } // We will have no file stream initially, and when we are finished with the // previous file. if (!file_stream_) { if (!OpenCurrentFile()) { return SR_ERROR; } } int local_error = 0; if (!error) { error = &local_error; } StreamResult result = file_stream_->Read(buffer, buffer_len, read, error); if (result == SR_EOS || result == SR_ERROR) { if (result == SR_ERROR) { LOG(LS_ERROR) << "Failed to read from: " << file_names_[current_file_index_] << "Error: " << error; } // Reached the end of the file, read next file. If there is an error return // the error status but allow for a next read by reading next file. CloseCurrentFile(); if (current_file_index_ == 0) { // Just finished reading the last file, signal EOS by setting index. current_file_index_ = file_names_.size(); } else { --current_file_index_; } if (read) { *read = 0; } return result == SR_EOS ? SR_SUCCESS : result; } else if (result == SR_SUCCESS) { // Succeeded, continue reading from this file. return SR_SUCCESS; } else { RTC_NOTREACHED(); } return result; } StreamResult FileRotatingStream::Write(const void* data, size_t data_len, size_t* written, int* error) { if (mode_ != kWrite) { return SR_EOS; } if (!file_stream_) { std::cerr << "Open() must be called before Write." << std::endl; return SR_ERROR; } // Write as much as will fit in to the current file. RTC_DCHECK_LT(current_bytes_written_, max_file_size_); size_t remaining_bytes = max_file_size_ - current_bytes_written_; size_t write_length = std::min(data_len, remaining_bytes); size_t local_written = 0; if (!written) { written = &local_written; } StreamResult result = file_stream_->Write(data, write_length, written, error); current_bytes_written_ += *written; // If we're done with this file, rotate it out. if (current_bytes_written_ >= max_file_size_) { RTC_DCHECK_EQ(current_bytes_written_, max_file_size_); RotateFiles(); } return result; } bool FileRotatingStream::Flush() { if (!file_stream_) { return false; } return file_stream_->Flush(); } bool FileRotatingStream::GetSize(size_t* size) const { if (mode_ != kRead) { // Not possible to get accurate size on disk when writing because of // potential buffering. return false; } RTC_DCHECK(size); *size = 0; size_t total_size = 0; for (auto file_name : file_names_) { Pathname pathname(file_name); size_t file_size = 0; if (Filesystem::GetFileSize(file_name, &file_size)) { total_size += file_size; } } *size = total_size; return true; } void FileRotatingStream::Close() { CloseCurrentFile(); } bool FileRotatingStream::Open() { switch (mode_) { case kRead: // Defer opening to when we first read since we want to return read error // if we fail to open next file. return true; case kWrite: { // Delete existing files when opening for write. std::vector<std::string> matching_files = GetFilesWithPrefix(); for (auto matching_file : matching_files) { if (!Filesystem::DeleteFile(matching_file)) { std::cerr << "Failed to delete: " << matching_file << std::endl; } } return OpenCurrentFile(); } } return false; } bool FileRotatingStream::DisableBuffering() { disable_buffering_ = true; if (!file_stream_) { std::cerr << "Open() must be called before DisableBuffering()." << std::endl; return false; } return file_stream_->DisableBuffering(); } std::string FileRotatingStream::GetFilePath(size_t index) const { RTC_DCHECK_LT(index, file_names_.size()); return file_names_[index]; } bool FileRotatingStream::OpenCurrentFile() { CloseCurrentFile(); // Opens the appropriate file in the appropriate mode. RTC_DCHECK_LT(current_file_index_, file_names_.size()); std::string file_path = file_names_[current_file_index_]; file_stream_.reset(new FileStream()); const char* mode = nullptr; switch (mode_) { case kWrite: mode = "w+"; // We should always we writing to the zero-th file. RTC_DCHECK_EQ(current_file_index_, 0u); break; case kRead: mode = "r"; break; } int error = 0; if (!file_stream_->Open(file_path, mode, &error)) { std::cerr << "Failed to open: " << file_path << "Error: " << error << std::endl; file_stream_.reset(); return false; } if (disable_buffering_) { file_stream_->DisableBuffering(); } return true; } void FileRotatingStream::CloseCurrentFile() { if (!file_stream_) { return; } current_bytes_written_ = 0; file_stream_.reset(); } void FileRotatingStream::RotateFiles() { RTC_DCHECK_EQ(mode_, kWrite); CloseCurrentFile(); // Rotates the files by deleting the file at |rotation_index_|, which is the // oldest file and then renaming the newer files to have an incremented index. // See header file comments for example. RTC_DCHECK_LT(rotation_index_, file_names_.size()); std::string file_to_delete = file_names_[rotation_index_]; if (Filesystem::IsFile(file_to_delete)) { if (!Filesystem::DeleteFile(file_to_delete)) { std::cerr << "Failed to delete: " << file_to_delete << std::endl; } } for (auto i = rotation_index_; i > 0; --i) { std::string rotated_name = file_names_[i]; std::string unrotated_name = file_names_[i - 1]; if (Filesystem::IsFile(unrotated_name)) { if (!Filesystem::MoveFile(unrotated_name, rotated_name)) { std::cerr << "Failed to move: " << unrotated_name << " to " << rotated_name << std::endl; } } } // Create a new file for 0th index. OpenCurrentFile(); OnRotation(); } std::vector<std::string> FileRotatingStream::GetFilesWithPrefix() const { std::vector<std::string> files; // Iterate over the files in the directory. DirectoryIterator it; Pathname dir_path; dir_path.SetFolder(dir_path_); if (!it.Iterate(dir_path)) { return files; } do { std::string current_name = it.Name(); if (current_name.size() && !it.IsDirectory() && current_name.compare(0, file_prefix_.size(), file_prefix_) == 0) { Pathname path(dir_path_, current_name); files.push_back(path.pathname()); } } while (it.Next()); return files; } std::string FileRotatingStream::GetFilePath(size_t index, size_t num_files) const { RTC_DCHECK_LT(index, num_files); std::ostringstream file_name; // The format will be "_%<num_digits>zu". We want to zero pad the index so // that it will sort nicely. size_t max_digits = ((num_files - 1) / 10) + 1; size_t num_digits = (index / 10) + 1; RTC_DCHECK_LE(num_digits, max_digits); size_t padding = max_digits - num_digits; file_name << file_prefix_ << "_"; for (size_t i = 0; i < padding; ++i) { file_name << "0"; } file_name << index; Pathname file_path(dir_path_, file_name.str()); return file_path.pathname(); } CallSessionFileRotatingStream::CallSessionFileRotatingStream( const std::string& dir_path) : FileRotatingStream(dir_path, kLogPrefix), max_total_log_size_(0), num_rotations_(0) { } CallSessionFileRotatingStream::CallSessionFileRotatingStream( const std::string& dir_path, size_t max_total_log_size) : FileRotatingStream(dir_path, kLogPrefix, max_total_log_size / 2, GetNumRotatingLogFiles(max_total_log_size) + 1), max_total_log_size_(max_total_log_size), num_rotations_(0) { RTC_DCHECK_GE(max_total_log_size, 4u); } const char* CallSessionFileRotatingStream::kLogPrefix = "webrtc_log"; const size_t CallSessionFileRotatingStream::kRotatingLogFileDefaultSize = 1024 * 1024; void CallSessionFileRotatingStream::OnRotation() { ++num_rotations_; if (num_rotations_ == 1) { // On the first rotation adjust the max file size so subsequent files after // the first are smaller. SetMaxFileSize(GetRotatingLogSize(max_total_log_size_)); } else if (num_rotations_ == (GetNumFiles() - 1)) { // On the next rotation the very first file is going to be deleted. Change // the rotation index so this doesn't happen. SetRotationIndex(GetRotationIndex() - 1); } } size_t CallSessionFileRotatingStream::GetRotatingLogSize( size_t max_total_log_size) { size_t num_rotating_log_files = GetNumRotatingLogFiles(max_total_log_size); size_t rotating_log_size = num_rotating_log_files > 2 ? kRotatingLogFileDefaultSize : max_total_log_size / 4; return rotating_log_size; } size_t CallSessionFileRotatingStream::GetNumRotatingLogFiles( size_t max_total_log_size) { // At minimum have two rotating files. Otherwise split the available log size // evenly across 1MB files. return std::max((size_t)2, (max_total_log_size / 2) / kRotatingLogFileDefaultSize); } } // namespace rtc
; A315019: Coordination sequence Gal.6.320.5 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings. ; 1,5,9,15,19,23,29,33,37,43,47,52,57,61,67,71,75,81,85,89,95,99,104,109,113,119,123,127,133,137,141,147,151,156,161,165,171,175,179,185,189,193,199,203,208,213,217,223,227,231 mov $5,$0 mul $0,4 mov $4,$0 sub $0,1 div $0,11 add $0,1 mov $2,$4 mul $2,2 div $2,22 add $2,$0 mov $1,$2 mov $3,$5 mul $3,4 add $1,$3 mov $0,$1
// Manuel Monforte // TAIS62 #include <iostream> #include <iomanip> #include <fstream> #include "PriorityQueue.h" #include <string> /* Coste de la solucion-->Operaciones top() y pop() sobre cola de prioridad O(NlogN) siendo n el numerod e pacientes a tratar */ struct tPaciente{ std::string nombre; int gravedad; tPaciente(){}; tPaciente(std::string n, int g) : nombre(n), gravedad(g){}; }; bool operator < (const tPaciente & a, const tPaciente & b){ return a.gravedad > b.gravedad; } // Resuelve un caso de prueba, leyendo de la entrada la // configuración, y escribiendo la respuesta bool resuelveCaso() { // leer los datos de la entrada int N,g; char type; std::string n; std::cin >> N; if (N==0) return false; PriorityQueue<tPaciente>listaEspera; for (int i = 0; i < N; i++){ std::cin >> type; if (type == 'I'){ std::cin >> n >> g; listaEspera.push({ n, g }); } else if (type == 'A'){ std::cout << listaEspera.top().nombre << "\n"; if(listaEspera.size()>1)listaEspera.pop(); } } std::cout << "----\n"; return true; } int main() { // Para la entrada por fichero. // Comentar para acepta el reto #ifndef DOMJUDGE std::ifstream in("datos.txt"); auto cinbuf = std::cin.rdbuf(in.rdbuf()); //save old buf and redirect std::cin to casos.txt #endif while (resuelveCaso()) ; // Para restablecer entrada. Comentar para acepta el reto #ifndef DOMJUDGE // para dejar todo como estaba al principio std::cin.rdbuf(cinbuf); system("PAUSE"); #endif return 0; }
// Copyright 2018 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/browser_switcher/browser_switcher_sitelist.h" #include <algorithm> #include <memory> #include <string> #include <utility> #include <vector> #include "base/values.h" #include "chrome/browser/browser_switcher/browser_switcher_prefs.h" #include "chrome/browser/browser_switcher/ieem_sitelist_parser.h" #include "components/prefs/pref_registry_simple.h" #include "components/sync_preferences/testing_pref_service_syncable.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" namespace browser_switcher { namespace { class TestBrowserSwitcherPrefs : public BrowserSwitcherPrefs { public: explicit TestBrowserSwitcherPrefs(PrefService* prefs) : BrowserSwitcherPrefs(prefs, nullptr) {} }; std::unique_ptr<base::Value> StringArrayToValue( const std::vector<const char*>& strings) { std::vector<base::Value> values(strings.size()); std::transform(strings.begin(), strings.end(), values.begin(), [](const char* s) { return base::Value(s); }); return std::make_unique<base::Value>(values); } } // namespace class BrowserSwitcherSitelistTest : public testing::Test { public: void Initialize(const std::vector<const char*>& url_list, const std::vector<const char*>& url_greylist, bool enabled = true) { BrowserSwitcherPrefs::RegisterProfilePrefs(prefs_backend_.registry()); prefs_backend_.SetManagedPref(prefs::kEnabled, std::make_unique<base::Value>(enabled)); prefs_backend_.SetManagedPref(prefs::kUrlList, StringArrayToValue(url_list)); prefs_backend_.SetManagedPref(prefs::kUrlGreylist, StringArrayToValue(url_greylist)); prefs_ = std::make_unique<TestBrowserSwitcherPrefs>(&prefs_backend_); sitelist_ = std::make_unique<BrowserSwitcherSitelistImpl>(prefs_.get()); } bool ShouldSwitch(const GURL& url) { return sitelist_->ShouldSwitch(url); } Decision GetDecision(const GURL& url) { return sitelist_->GetDecision(url); } sync_preferences::TestingPrefServiceSyncable* prefs_backend() { return &prefs_backend_; } BrowserSwitcherSitelist* sitelist() { return sitelist_.get(); } private: sync_preferences::TestingPrefServiceSyncable prefs_backend_; std::unique_ptr<BrowserSwitcherPrefs> prefs_; std::unique_ptr<BrowserSwitcherSitelist> sitelist_; }; TEST_F(BrowserSwitcherSitelistTest, CanonicalizeRule) { std::string rule = "Example.Com"; CanonicalizeRule(&rule); EXPECT_EQ("example.com", rule); rule = "Example.Com/"; CanonicalizeRule(&rule); EXPECT_EQ("//example.com/", rule); rule = "!Example.Com/Abc"; CanonicalizeRule(&rule); EXPECT_EQ("!//example.com/Abc", rule); rule = "/Example.Com"; CanonicalizeRule(&rule); EXPECT_EQ("/Example.Com", rule); rule = "//Example.Com"; CanonicalizeRule(&rule); EXPECT_EQ("//example.com/", rule); rule = "!//Example.Com"; CanonicalizeRule(&rule); EXPECT_EQ("!//example.com/", rule); rule = "HTTP://EXAMPLE.COM"; CanonicalizeRule(&rule); EXPECT_EQ("http://example.com/", rule); rule = "HTTP://EXAMPLE.COM/ABC"; CanonicalizeRule(&rule); EXPECT_EQ("http://example.com/ABC", rule); rule = "User@Example.Com:8080/Test"; CanonicalizeRule(&rule); EXPECT_EQ("//User@example.com:8080/Test", rule); } TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectWildcard) { // A "*" by itself means everything matches. Initialize({"*"}, {}); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("https://example.com/foobar/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/foobar/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://google.com/"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectHost) { // A string without slashes means compare the URL's host (case-insensitive). Initialize({"example.com"}, {}); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("https://example.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://subdomain.example.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/foobar/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://google.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://example.ca/"))); // For backwards compatibility, this should also match, even if it's not the // same host. EXPECT_TRUE(ShouldSwitch(GURL("https://notexample.com/"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectHostNotLowerCase) { // Host is not in lowercase form, but we compare ignoring case. Initialize({"eXaMpLe.CoM"}, {}); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectWrongScheme) { Initialize({"example.com"}, {}); // Scheme is not one of 'http', 'https' or 'file'. EXPECT_FALSE(ShouldSwitch(GURL("ftp://example.com/"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectPrefix) { // A string with slashes means check if it's a prefix (case-sensitive). Initialize({"http://example.com/foobar"}, {}); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/foobar"))); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/foobar/subroute/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/foobar#fragment"))); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/foobar?query=param"))); EXPECT_FALSE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("https://example.com/foobar"))); EXPECT_FALSE(ShouldSwitch(GURL("HTTP://EXAMPLE.COM/FOOBAR"))); EXPECT_FALSE(ShouldSwitch(GURL("http://subdomain.example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://google.com/"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectInvertedMatch) { // The most specific (i.e., longest string) rule should have priority. Initialize({"!subdomain.example.com", "example.com"}, {}); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://subdomain.example.com/"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectGreylist) { // The most specific (i.e., longest string) rule should have priority. Initialize({"example.com"}, {"http://example.com/login/"}); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://example.com/login/"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectGreylistWildcard) { Initialize({"*"}, {"*"}); // If both are wildcards, prefer the greylist. EXPECT_FALSE(ShouldSwitch(GURL("http://example.com/"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldMatchAnySchema) { // URLs formatted like these don't include a schema, so should match both HTTP // and HTTPS. Initialize({"//example.com", "reddit.com/r/funny"}, {}); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/something"))); EXPECT_TRUE(ShouldSwitch(GURL("https://example.com/something"))); EXPECT_TRUE(ShouldSwitch(GURL("file://example.com/foobar/"))); EXPECT_FALSE(ShouldSwitch(GURL("https://foo.example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("mailto://example.com"))); EXPECT_FALSE(ShouldSwitch(GURL("http://bad.com/example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://bad.com//example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://bad.com/hackme.html?example.com"))); EXPECT_TRUE(ShouldSwitch(GURL("http://reddit.com/r/funny"))); EXPECT_TRUE(ShouldSwitch(GURL("https://reddit.com/r/funny"))); EXPECT_FALSE(ShouldSwitch(GURL("http://reddit.com/r/pics"))); EXPECT_FALSE(ShouldSwitch(GURL("https://reddit.com/r/pics"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldRedirectPort) { Initialize( {"//example.com", "//test.com:3000", "lol.com:3000", "trololo.com"}, {}); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com:2000/something"))); EXPECT_TRUE(ShouldSwitch(GURL("http://test.com:3000/something"))); EXPECT_TRUE(ShouldSwitch(GURL("http://lol.com:3000/something"))); EXPECT_TRUE(ShouldSwitch(GURL("http://trololo.com/something"))); EXPECT_TRUE(ShouldSwitch(GURL("http://trololo.com:3000/something"))); EXPECT_FALSE(ShouldSwitch(GURL("http://test.com:2000/something"))); EXPECT_FALSE(ShouldSwitch(GURL("http://test.com:2000/something:3000"))); EXPECT_FALSE(ShouldSwitch(GURL("http://test.com/something:3000"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldPickUpPrefChanges) { Initialize({}, {}); prefs_backend()->SetManagedPref(prefs::kUrlList, StringArrayToValue({"example.com"})); prefs_backend()->SetManagedPref(prefs::kUrlGreylist, StringArrayToValue({"foo.example.com"})); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://bar.example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://foo.example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://google.com/"))); } TEST_F(BrowserSwitcherSitelistTest, ShouldIgnoreNonManagedPrefs) { Initialize({}, {}); prefs_backend()->Set(prefs::kUrlList, *StringArrayToValue({"example.com"})); EXPECT_FALSE(ShouldSwitch(GURL("http://example.com/"))); prefs_backend()->SetManagedPref(prefs::kUrlList, StringArrayToValue({"example.com"})); prefs_backend()->Set(prefs::kUrlGreylist, *StringArrayToValue({"morespecific.example.com"})); EXPECT_TRUE(ShouldSwitch(GURL("http://morespecific.example.com/"))); } TEST_F(BrowserSwitcherSitelistTest, SetIeemSitelist) { Initialize({}, {}); ParsedXml ieem; ieem.rules = {"example.com"}; sitelist()->SetIeemSitelist(std::move(ieem)); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://bar.example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://google.com/"))); } TEST_F(BrowserSwitcherSitelistTest, SetExternalSitelist) { Initialize({}, {}); ParsedXml external; external.rules = {"example.com"}; sitelist()->SetExternalSitelist(std::move(external)); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://bar.example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://google.com/"))); } TEST_F(BrowserSwitcherSitelistTest, SetExternalGreylist) { Initialize({"example.com"}, {}); ParsedXml external; external.rules = {"foo.example.com"}; sitelist()->SetExternalGreylist(std::move(external)); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://bar.example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://foo.example.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://google.com/"))); } TEST_F(BrowserSwitcherSitelistTest, All3Sources) { Initialize({"google.com"}, {"mail.google.com"}); ParsedXml ieem; ieem.rules = {"example.com"}; sitelist()->SetIeemSitelist(std::move(ieem)); ParsedXml external; external.rules = {"yahoo.com"}; sitelist()->SetExternalSitelist(std::move(external)); EXPECT_TRUE(ShouldSwitch(GURL("http://google.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://drive.google.com/"))); EXPECT_FALSE(ShouldSwitch(GURL("http://mail.google.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://bar.example.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://yahoo.com/"))); EXPECT_TRUE(ShouldSwitch(GURL("http://news.yahoo.com/"))); } TEST_F(BrowserSwitcherSitelistTest, BrowserSwitcherDisabled) { Initialize({"example.com"}, {}, false); EXPECT_FALSE(ShouldSwitch(GURL("http://example.com/"))); EXPECT_EQ(Decision(kStay, kDisabled, ""), GetDecision(GURL("http://example.com/"))); } TEST_F(BrowserSwitcherSitelistTest, CheckReason) { Initialize({"foo.invalid.com", "!example.com"}, {"//foo.invalid.com/foobar", "invalid.com"}); EXPECT_EQ(Decision(kStay, kProtocol, ""), GetDecision(GURL("ftp://example.com/"))); EXPECT_EQ(Decision(kStay, kDefault, ""), GetDecision(GURL("http://google.com/"))); EXPECT_EQ(Decision(kStay, kDefault, ""), GetDecision(GURL("http://bar.invalid.com/"))); EXPECT_EQ(Decision(kStay, kSitelist, "!example.com"), GetDecision(GURL("http://example.com/"))); EXPECT_EQ(Decision(kGo, kSitelist, "foo.invalid.com"), GetDecision(GURL("http://foo.invalid.com/"))); EXPECT_EQ(Decision(kStay, kGreylist, "//foo.invalid.com/foobar"), GetDecision(GURL("http://foo.invalid.com/foobar"))); } } // namespace browser_switcher
// Copyright 2015 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 "ui/ozone/platform/caca/client_native_pixmap_factory_caca.h" #include "ui/ozone/common/stub_client_native_pixmap_factory.h" namespace ui { ClientNativePixmapFactory* CreateClientNativePixmapFactoryCaca() { return CreateStubClientNativePixmapFactory(); } } // namespace ui
dnl AMD64 mpn_lshsub_n. R = 2^k(U - V). dnl Copyright 2006, 2011, 2012 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 AMD K8,K9 3.15 (mpn_sub_n + mpn_lshift costs about 4 c/l) C AMD K10 3.15 (mpn_sub_n + mpn_lshift costs about 4 c/l) C Intel P4 16.5 C Intel core2 4.35 C Intel corei ? C Intel atom ? C VIA nano ? C This was written quickly and not optimized at all, but it runs very well on C K8. But perhaps one could get under 3 c/l. Ideas: C 1) Use indexing to save the 3 LEA C 2) Write reasonable feed-in code C 3) Be more clever about register usage C 4) Unroll more, handling CL negation, carry save/restore cost much now C 5) Reschedule C INPUT PARAMETERS define(`rp', `%rdi') define(`up', `%rsi') define(`vp', `%rdx') define(`n', `%rcx') define(`cnt', `%r8') ABI_SUPPORT(DOS64) ABI_SUPPORT(STD64) ASM_START() TEXT ALIGN(16) PROLOGUE(mpn_lshsub_n) FUNC_ENTRY(4) IFDOS(` mov 56(%rsp), %r8d ') push %r12 push %r13 push %r14 push %r15 push %rbx mov n, %rax xor R32(%rbx), R32(%rbx) C clear carry save register mov R32(%r8), R32(%rcx) C shift count xor R32(%r15), R32(%r15) C limb carry mov R32(%rax), R32(%r11) and $3, R32(%r11) je L(4) sub $1, R32(%r11) L(oopette): add R32(%rbx), R32(%rbx) C restore carry flag mov 0(up), %r8 lea 8(up), up sbb 0(vp), %r8 mov %r8, %r12 sbb R32(%rbx), R32(%rbx) C save carry flag shl R8(%rcx), %r8 or %r15, %r8 mov %r12, %r15 lea 8(vp), vp neg R8(%rcx) shr R8(%rcx), %r15 neg R8(%rcx) mov %r8, 0(rp) lea 8(rp), rp sub $1, R32(%r11) jnc L(oopette) L(4): sub $4, %rax jc L(end) ALIGN(16) L(oop): add R32(%rbx), R32(%rbx) C restore carry flag mov 0(up), %r8 mov 8(up), %r9 mov 16(up), %r10 mov 24(up), %r11 lea 32(up), up sbb 0(vp), %r8 mov %r8, %r12 sbb 8(vp), %r9 mov %r9, %r13 sbb 16(vp), %r10 mov %r10, %r14 sbb 24(vp), %r11 sbb R32(%rbx), R32(%rbx) C save carry flag shl R8(%rcx), %r8 shl R8(%rcx), %r9 shl R8(%rcx), %r10 or %r15, %r8 mov %r11, %r15 shl R8(%rcx), %r11 lea 32(vp), vp neg R8(%rcx) shr R8(%rcx), %r12 shr R8(%rcx), %r13 shr R8(%rcx), %r14 shr R8(%rcx), %r15 C used next loop or %r12, %r9 or %r13, %r10 or %r14, %r11 neg R8(%rcx) mov %r8, 0(rp) mov %r9, 8(rp) mov %r10, 16(rp) mov %r11, 24(rp) lea 32(rp), rp sub $4, %rax jnc L(oop) L(end): neg R32(%rbx) shl R8(%rcx), %rbx adc %r15, %rbx mov %rbx, %rax pop %rbx pop %r15 pop %r14 pop %r13 pop %r12 FUNC_EXIT() ret EPILOGUE()